tarsk 0.5.49 → 0.5.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/index.js +10644 -8487
  2. package/dist/public/assets/{account-view-DxHV7OtO.js → account-view-orctnHTc.js} +1 -1
  3. package/dist/public/assets/{api-Dhzdgb40.js → api-_tZksLaY.js} +1 -1
  4. package/dist/public/assets/{browser-tab-qhf-xKwZ.js → browser-tab-bfjSH9LH.js} +1 -1
  5. package/dist/public/assets/commit-dialog-BAFsxiuw.js +1 -0
  6. package/dist/public/assets/{context-menu-PIC-g8wy.js → context-menu-CeBh_Q21.js} +1 -1
  7. package/dist/public/assets/{create-repo-dialog-CsjpTBPU.js → create-repo-dialog-D6cKAxMh.js} +1 -1
  8. package/dist/public/assets/{dialogs-config-BEazgV7k.js → dialogs-config-COzptu1b.js} +14 -14
  9. package/dist/public/assets/diff-view-CFu5DBIy.js +3 -0
  10. package/dist/public/assets/{explorer-tab-view--ib_BjId.js → explorer-tab-view-yR_3TyF7.js} +2 -2
  11. package/dist/public/assets/explorer-tree-DKrWFiee.js +1 -0
  12. package/dist/public/assets/explorer-view-DYbdTXTm.js +1 -0
  13. package/dist/public/assets/git-history-dialog-CTJwMGDA.js +1 -0
  14. package/dist/public/assets/git-ops-button-DM9h9L8O.js +2 -0
  15. package/dist/public/assets/history-view-BJ65FVAN.js +9 -0
  16. package/dist/public/assets/index-BMgOr4si.js +73 -0
  17. package/dist/public/assets/index-DzUALYN4.css +1 -0
  18. package/dist/public/assets/{mcp-server-card-ChdAZekt.js → mcp-server-card-7DWtYR7B.js} +1 -1
  19. package/dist/public/assets/{merged-pr-dialog-DAXqT4Xe.js → merged-pr-dialog-D6ReZlV4.js} +1 -1
  20. package/dist/public/assets/model-star-rating-DmWIerry.js +1 -0
  21. package/dist/public/assets/onboarding-pVfMmu_a.js +1 -0
  22. package/dist/public/assets/project-settings-view-CvPC_OvN.js +1 -0
  23. package/dist/public/assets/providers-list-view-BEBGDXvF.js +1 -0
  24. package/dist/public/assets/pull-request-dialog-DD9Yxl2t.js +1 -0
  25. package/dist/public/assets/pull-with-changes-dialog-yEIyN-rw.js +1 -0
  26. package/dist/public/assets/push-before-pr-dialog-09SWB4nh.js +1 -0
  27. package/dist/public/assets/{radio-group-n9qyUxmu.js → radio-group-DAndqwXy.js} +1 -1
  28. package/dist/public/assets/react-vendor-CEpXTE2b.js +16 -0
  29. package/dist/public/assets/settings-general-view-Crc9BTRv.js +1 -0
  30. package/dist/public/assets/settings-instructions-view-CB-cGPIr.js +1 -0
  31. package/dist/public/assets/settings-list-C5XuK_4u.js +1 -0
  32. package/dist/public/assets/settings-mcp-servers-view-CZR7I1h2.js +5 -0
  33. package/dist/public/assets/{settings-models-skeleton-Cse6L-Nd.js → settings-models-skeleton-ZtGznNlV.js} +1 -1
  34. package/dist/public/assets/settings-models-view-CB0rRPNa.js +1 -0
  35. package/dist/public/assets/settings-rules-view-BnoxoZfX.js +8 -0
  36. package/dist/public/assets/settings-skills-view-DKXDiK3e.js +3 -0
  37. package/dist/public/assets/settings-slash-commands-view-DtTuDEFe.js +1 -0
  38. package/dist/public/assets/settings-subagents-view-DNcPuqd5.js +2 -0
  39. package/dist/public/assets/{settings-system-prompt-view-B1vc2cgC.js → settings-system-prompt-view-BLkM6rN5.js} +1 -1
  40. package/dist/public/assets/{settings-view-DLBIkYoA.js → settings-view-BX2dUb7a.js} +2 -2
  41. package/dist/public/assets/{skeleton-6mGMglV0.js → skeleton-CxK1dTki.js} +1 -1
  42. package/dist/public/assets/slug-utils-D3-onmIf.js +1 -0
  43. package/dist/public/assets/{tabs-iUSYYupj.js → tabs-Tmfp1NOE.js} +1 -1
  44. package/dist/public/assets/{terminal-panel-DIpnKR-N.js → terminal-panel-DKkr68gm.js} +1 -1
  45. package/dist/public/assets/todos-view-_rD_cv7x.js +17 -0
  46. package/dist/public/assets/{ui-components-kSaUEA_X.js → ui-components-BhYSDqpD.js} +1 -1
  47. package/dist/public/assets/{use-deferred-search-DGJskNBr.js → use-deferred-search-DXiiWEeH.js} +1 -1
  48. package/dist/public/assets/{utils-CECQ_-6N.js → utils-DDUhUTLy.js} +1 -1
  49. package/dist/public/assets/{vosk-speech-CgILeNJR.js → vosk-speech-BHa2mKnm.js} +2 -2
  50. package/dist/public/assets/{web-BWAZk7ug.js → web-3Ems3Koj.js} +1 -1
  51. package/dist/public/assets/{web-BD1sqxMq.js → web-6JeYEnKU.js} +1 -1
  52. package/dist/public/assets/{web-DGalafxk.js → web-BYoghlKk.js} +1 -1
  53. package/dist/public/assets/{web-Dt5YgbhM.js → web-Dgmyivst.js} +1 -1
  54. package/dist/public/index.html +8 -8
  55. package/package.json +1 -1
  56. package/dist/public/assets/commit-dialog-DcVXFOBP.js +0 -1
  57. package/dist/public/assets/diff-view-CGEl0YbC.js +0 -3
  58. package/dist/public/assets/explorer-tree-CiPMm5ck.js +0 -1
  59. package/dist/public/assets/explorer-view-odyQutTO.js +0 -1
  60. package/dist/public/assets/git-history-dialog-qUZ7Qsp4.js +0 -1
  61. package/dist/public/assets/git-ops-button-Bced-_39.js +0 -2
  62. package/dist/public/assets/history-view-BMVTxWTg.js +0 -9
  63. package/dist/public/assets/index-C7FLshNp.css +0 -1
  64. package/dist/public/assets/index-_SOdLUMq.js +0 -73
  65. package/dist/public/assets/model-star-rating-BzpXBjSo.js +0 -1
  66. package/dist/public/assets/onboarding-Bi5MieW-.js +0 -1
  67. package/dist/public/assets/project-settings-view-CHV6lJG4.js +0 -1
  68. package/dist/public/assets/providers-list-view-Dgid2Wui.js +0 -1
  69. package/dist/public/assets/pull-request-dialog-BFgRF5AH.js +0 -1
  70. package/dist/public/assets/pull-with-changes-dialog-oGP-j8Yw.js +0 -1
  71. package/dist/public/assets/push-before-pr-dialog-BQ0QC6Qu.js +0 -1
  72. package/dist/public/assets/react-vendor-iDwBzcYF.js +0 -16
  73. package/dist/public/assets/settings-general-view-Vwi9J6Tn.js +0 -1
  74. package/dist/public/assets/settings-instructions-view-8YIr0PO3.js +0 -1
  75. package/dist/public/assets/settings-list-owWkHWxE.js +0 -1
  76. package/dist/public/assets/settings-mcp-servers-view-CCXW_uet.js +0 -5
  77. package/dist/public/assets/settings-models-view-BAxf3eJq.js +0 -1
  78. package/dist/public/assets/settings-rules-view-D3KLTKVZ.js +0 -8
  79. package/dist/public/assets/settings-skills-view-DaqOna-w.js +0 -3
  80. package/dist/public/assets/settings-slash-commands-view-CN8_DTYX.js +0 -1
  81. package/dist/public/assets/settings-subagents-view-BIejA-ck.js +0 -2
  82. package/dist/public/assets/slug-utils-BT1eqWhW.js +0 -1
  83. package/dist/public/assets/todos-view-BK6i_oPT.js +0 -17
@@ -0,0 +1,73 @@
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-D6ReZlV4.js","assets/dialogs-config-COzptu1b.js","assets/onboarding-pVfMmu_a.js","assets/history-view-BJ65FVAN.js","assets/git-ops-button-DM9h9L8O.js","assets/monaco-CZnIWXyV.js","assets/monaco-Br_kD0ds.css","assets/diff-view-CFu5DBIy.js","assets/context-menu-CeBh_Q21.js","assets/react-vendor-CEpXTE2b.js","assets/utils-DDUhUTLy.js","assets/terminal-panel-DKkr68gm.js","assets/terminal-panel-kHJ-D0s7.css","assets/explorer-tab-view-yR_3TyF7.js","assets/browser-tab-bfjSH9LH.js","assets/settings-view-BX2dUb7a.js","assets/settings-models-skeleton-ZtGznNlV.js","assets/skeleton-CxK1dTki.js","assets/todos-view-_rD_cv7x.js","assets/tabs-Tmfp1NOE.js"])))=>i.map(i=>d[i]);
2
+ import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$i as r,$o as i,$r as a,A as o,Aa as s,An as c,Ar as l,At as u,Bn as d,Bt as f,Cn as p,D as m,Da as h,Dn as g,Do as _,Dr as v,Dt as y,En as b,Eo as x,Er as S,Fi as C,Fo as w,Fr as T,Ft as E,Gn as D,Go as O,Ha as k,Hi as A,Ho as j,Ht as M,Ii as N,Ir as P,It as F,J as I,Jo as L,Jr as R,Ka as ee,Kr as z,L as te,La as ne,Li as re,Ln as ie,Lr as B,Mn as ae,Mo as oe,Mr as se,N as ce,Ni as V,Nn as le,No as ue,Oa as de,On as fe,Oo as H,Or as pe,Pa as me,Pi as he,Po as ge,Pr as U,Q as _e,Qa as ve,Qn as ye,Qr as be,Ra as xe,S as Se,Sa as Ce,Sr as W,T as we,Tn as Te,Tr as Ee,Tt as De,Ua as Oe,Un as ke,Uo as Ae,Va as je,Vi as Me,Vt as Ne,Wi as Pe,Wo as Fe,Wt as Ie,Xa as Le,Xi as Re,Xo as ze,Xr as Be,Xt as Ve,Ya as He,Yi as Ue,Yn as We,Yr as Ge,Za as Ke,Zi as qe,Zo as Je,Zr as Ye,_n as Xe,_o as Ze,_r as Qe,aa as $e,an as et,ar as tt,as as nt,b as rt,ba as it,bo as at,br as ot,c as st,ca as G,cn as ct,co as lt,cr as ut,cs as dt,d as ft,dn as pt,do as mt,ds as ht,ea as gt,ei as _t,eo as vt,er as yt,es as bt,et as xt,fn as St,fo as Ct,fr as wt,fs as Tt,g as Et,gn as K,gr as q,hn as Dt,ho as Ot,ht as kt,ia as At,in as jt,io as Mt,ir as Nt,is as Pt,it as Ft,j as It,ja as Lt,ji as Rt,jn as zt,ka as Bt,kn as Vt,ko as Ht,kr as Ut,kt as Wt,ln as Gt,lo as Kt,lr as qt,ls as Jt,m as Yt,mn as Xt,mo as Zt,mr as Qt,na as $t,nn as en,no as tn,nr as nn,oa as rn,on as an,or as on,p as sn,po as cn,pr as ln,pt as un,qa as dn,qo as fn,qt as pn,ra as mn,rn as hn,ro as gn,rr as _n,rt as J,sa as vn,sn as yn,so as bn,sr as xn,ta as Sn,ti as Cn,to as wn,tr as Tn,ts as En,uo as Dn,us as On,ut as kn,v as An,vr as jn,w as Mn,wn as Nn,wo as Pn,wr as Fn,x as In,xo as Ln,xt as Rn,yo 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-COzptu1b.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-CEpXTE2b.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-BJ65FVAN.js";import{d as fi,l as pi,o as mi,u as hi}from"./onboarding-pVfMmu_a.js";import{a as gi,i as _i,n as vi,o as yi,r as bi,t as xi}from"./vosk-speech-BHa2mKnm.js";import{n as Si,t as Ci}from"./utils-DDUhUTLy.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(Tt(),1),Ai=sr(),X=On(),Z=function(e){return e.SetProjects=`SET_PROJECTS`,e.SetProjectsLoading=`SET_PROJECTS_LOADING`,e.SelectThread=`SELECT_THREAD`,e.SetMessages=`SET_MESSAGES`,e.AddMessage=`ADD_MESSAGE`,e.EnqueueChatMessage=`ENQUEUE_CHAT_MESSAGE`,e.RemoveQueuedChatMessage=`REMOVE_QUEUED_CHAT_MESSAGE`,e.SetStreaming=`SET_STREAMING`,e.AppendStreamContent=`APPEND_STREAM_CONTENT`,e.SetStreamContent=`SET_STREAM_CONTENT`,e.AppendStreamThinking=`APPEND_STREAM_THINKING`,e.AppendStreamChunk=`APPEND_STREAM_CHUNK`,e.SetStreamModel=`SET_STREAM_MODEL`,e.SetProjectModel=`SET_PROJECT_MODEL`,e.ResetStream=`RESET_STREAM`,e.StopStream=`STOP_STREAM`,e.ToggleSidebar=`TOGGLE_SIDEBAR`,e.CloseSidebar=`CLOSE_SIDEBAR`,e.SetCreatingProject=`SET_CREATING_PROJECT`,e.ConfigUpdated=`CONFIG_UPDATED`,e.SetProcessingThreads=`SET_PROCESSING_THREADS`,e.AddProcessingThread=`ADD_PROCESSING_THREAD`,e.RemoveProcessingThread=`REMOVE_PROCESSING_THREAD`,e.AddCreatingProject=`ADD_CREATING_PROJECT`,e.AddCreatingThread=`ADD_CREATING_THREAD`,e.RemoveCreatingProject=`REMOVE_CREATING_PROJECT`,e.RemoveCreatingThread=`REMOVE_CREATING_THREAD`,e.MarkThreadCompleted=`MARK_THREAD_COMPLETED`,e.ClearThreadCompleted=`CLEAR_THREAD_COMPLETED`,e.AddDeletingThread=`ADD_DELETING_THREAD`,e.RemoveDeletingThread=`REMOVE_DELETING_THREAD`,e.AddDeletingProject=`ADD_DELETING_PROJECT`,e.RemoveDeletingProject=`REMOVE_DELETING_PROJECT`,e.AppendCommandOutput=`APPEND_COMMAND_OUTPUT`,e.SetRunningCommand=`SET_RUNNING_COMMAND`,e.ClearCommandOutput=`CLEAR_COMMAND_OUTPUT`,e.ToggleTerminal=`TOGGLE_TERMINAL`,e.SetTerminalOpen=`SET_TERMINAL_OPEN`,e.QueueTerminalCommand=`QUEUE_TERMINAL_COMMAND`,e.ClearQueuedTerminalCommand=`CLEAR_QUEUED_TERMINAL_COMMAND`,e.AppendTerminalLine=`APPEND_TERMINAL_LINE`,e.ClearTerminalOutput=`CLEAR_TERMINAL_OUTPUT`,e.SetTerminalHeight=`SET_TERMINAL_HEIGHT`,e.SetTerminalCwd=`SET_TERMINAL_CWD`,e.SetTerminalRunning=`SET_TERMINAL_RUNNING`,e.SetTerminalHistory=`SET_TERMINAL_HISTORY`,e.SetTerminalHistoryIndex=`SET_TERMINAL_HISTORY_INDEX`,e.UpdateThreadTitle=`UPDATE_THREAD_TITLE`,e.ClearFocusChatInput=`CLEAR_FOCUS_CHAT_INPUT`,e.ClearMessages=`CLEAR_MESSAGES`,e.UpdateToolCallProgress=`UPDATE_TOOL_CALL_PROGRESS`,e.UpdateToolExecutionOutput=`UPDATE_TOOL_EXECUTION_OUTPUT`,e.AppendToolExecutionOutput=`APPEND_TOOL_EXECUTION_OUTPUT`,e.ClearToolCallProgress=`CLEAR_TOOL_CALL_PROGRESS`,e.SetPendingChatMessage=`SET_PENDING_CHAT_MESSAGE`,e.ClearPendingChatMessage=`CLEAR_PENDING_CHAT_MESSAGE`,e.IncrementStreamEventCount=`INCREMENT_STREAM_EVENT_COUNT`,e.SetDiffComments=`SET_DIFF_COMMENTS`,e.ClearSelection=`CLEAR_SELECTION`,e.SetChatInputDraft=`SET_CHAT_INPUT_DRAFT`,e.ClearChatInputDraft=`CLEAR_CHAT_INPUT_DRAFT`,e.EnableDualChat=`ENABLE_DUAL_CHAT`,e.DisableDualChat=`DISABLE_DUAL_CHAT`,e.SetFocusedPane=`SET_FOCUSED_PANE`,e.SetSecondaryMessages=`SET_SECONDARY_MESSAGES`,e.AddSecondaryMessage=`ADD_SECONDARY_MESSAGE`,e.SetActiveStreamPane=`SET_ACTIVE_STREAM_PANE`,e}({}),ji={projects:[],projectsLoading:!0,selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,queuedChatMessages:[],isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0,threadStreamingStates:{},threadDualChatStates:{},projectModelSelections:{},sidebarOpen:!0,isCreatingProject:!1,configUpdatedAt:0,processingThreadIds:[],completedThreadIds:[],deletingThreadIds:[],deletingProjectIds:[],commandOutput:``,isRunningCommand:!1,terminalStates:{},focusChatInput:!1,toolCallProgress:{},pendingChatMessage:null,diffComments:{},chatInputDrafts:{},dualChatEnabled:!1,focusedPane:`primary`,secondaryConversationId:null,secondaryMessages:[],secondaryMessagesLoaded:!1,activeStreamPane:null},Mi={open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};function Ni(e,t,n,r){return t.includes(e)||Ri(n,e,`primary`).isStreaming||Ri(n,e,`secondary`).isStreaming?!0:r?.threadId===e}var Pi={isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0},Fi=Pi;function Ii(){return{...Pi,streamingSegments:[]}}function Li(e,t=`primary`){return`${e}:${t}`}function Ri(e,t,n=`primary`){return t?e[Li(t,n)]??Fi:Fi}function zi(e,t){return t.threadId??e.selectedThreadId}function Bi(e,t){return t.paneId??e.activeStreamPane??`primary`}function Vi(e,t,n){return t===e.selectedThreadId?e.activeStreamPane===null?n===`primary`:e.activeStreamPane===n:!1}function Hi(e,t,n,r,i=!1){if(!t)return{...e,...r,toolCallProgress:i?{}:e.toolCallProgress};let a=Li(t,n),o={...e.threadStreamingStates,[a]:r};return Vi(e,t,n)?{...e,...r,threadStreamingStates:o,toolCallProgress:i?{}:e.toolCallProgress}:{...e,threadStreamingStates:o}}function Ui(){return{open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1}}var Wi={dualChatEnabled:!1,focusedPane:`primary`,secondaryConversationId:null,secondaryMessages:[],secondaryMessagesLoaded:!1,activeStreamPane:null};function Gi(){return{...Wi}}function Ki(e){return{dualChatEnabled:e.dualChatEnabled,focusedPane:e.focusedPane,secondaryConversationId:e.secondaryConversationId,secondaryMessages:e.secondaryMessages,secondaryMessagesLoaded:e.secondaryMessagesLoaded,activeStreamPane:e.activeStreamPane}}function qi(e,t){return t?e[t]??Wi:Wi}function Ji(e){return{...e,secondaryMessages:[...e.secondaryMessages]}}function Yi(e,t,n){let r=Ji(n),i=t===null?e.threadDualChatStates:{...e.threadDualChatStates,[t]:r};return t===e.selectedThreadId?{...e,...r,threadDualChatStates:i}:{...e,threadDualChatStates:i}}function Xi(e,t,n){let r=e.threadDualChatStates;return t&&(r={...r,[t]:Ji(Ki(e))}),{...Ji(qi(r,n)),threadDualChatStates:r}}function Zi(e,t){return Yi(e,e.selectedThreadId,{...Ki(e),...t})}function Qi(e,t){switch(t.type){case Z.EnableDualChat:{let n=e.selectedThreadId?qi(e.threadDualChatStates,e.selectedThreadId):Wi,r=n.secondaryConversationId!==null;return Zi(e,{dualChatEnabled:!0,focusedPane:`primary`,secondaryConversationId:r?n.secondaryConversationId:t.conversationId,secondaryMessages:r?n.secondaryMessages:[],secondaryMessagesLoaded:r?n.secondaryMessagesLoaded:!0})}case Z.DisableDualChat:return Zi(e,{dualChatEnabled:!1,focusedPane:`primary`,activeStreamPane:null});case Z.SetFocusedPane:return Zi(e,{focusedPane:t.paneId});case Z.SetSecondaryMessages:return Zi(e,{secondaryMessages:t.messages,secondaryMessagesLoaded:!0});case Z.AddSecondaryMessage:return Zi(e,{secondaryMessages:[...e.secondaryMessages,t.message]});case Z.SetActiveStreamPane:{if(!e.selectedThreadId||t.paneId===null)return Zi(e,{activeStreamPane:null});let n=Ri(e.threadStreamingStates,e.selectedThreadId,t.paneId);return{...Zi(e,{activeStreamPane:t.paneId}),...n}}default:return null}}function $i(e,t){switch(t.type){case Z.SetMessages:return{...e,messages:t.messages,messagesLoaded:!0};case Z.AddMessage:return t.threadId&&t.threadId!==e.selectedThreadId?e:t.paneId===`secondary`?Yi(e,e.selectedThreadId,{...Ki(e),secondaryMessages:[...e.secondaryMessages,t.message]}):{...e,messages:[...e.messages,t.message]};case Z.EnqueueChatMessage:return{...e,queuedChatMessages:[...e.queuedChatMessages,t.message]};case Z.RemoveQueuedChatMessage:return{...e,queuedChatMessages:e.queuedChatMessages.filter(e=>e.id!==t.queuedMessageId)};case Z.ClearMessages:return{...e,messages:[]};case Z.UpdateToolCallProgress:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{...n,...t.progress}}}}case Z.UpdateToolExecutionOutput:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{toolCallId:t.toolCallId,toolName:t.toolName??n?.toolName??``,delta:n?.delta??``,partial:n?.partial??{role:`tool`,content:[]},executionOutput:t.executionOutput}}}}case Z.AppendToolExecutionOutput:{let n=e.toolCallProgress[t.toolCallId],r=n?.executionOutput??``;return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{toolCallId:t.toolCallId,toolName:t.toolName??n?.toolName??`agent`,delta:n?.delta??``,partial:n?.partial??{role:`tool`,content:[]},executionOutput:r+t.delta}}}}case Z.ClearToolCallProgress:{if(!t.toolCallId)return{...e,toolCallProgress:{}};let{[t.toolCallId]:n,...r}=e.toolCallProgress;return{...e,toolCallProgress:r}}case Z.SetPendingChatMessage:return{...e,pendingChatMessage:t.message};case Z.ClearPendingChatMessage:return{...e,pendingChatMessage:null};case Z.SetChatInputDraft:return{...e,chatInputDrafts:{...e.chatInputDrafts,[t.threadId]:t.draft}};case Z.ClearChatInputDraft:{let{[t.threadId]:n,...r}=e.chatInputDrafts;return{...e,chatInputDrafts:r}}case Z.SelectThread:{let n=Xi(e,e.selectedThreadId,t.threadId),r=Ri(e.threadStreamingStates,t.threadId,`primary`);return{...e,...r,...n,selectedThreadId:t.threadId,selectedProjectId:t.projectId,messages:t.initialMessages??[],messagesLoaded:!1,focusChatInput:t.focusInput??!1}}case Z.ClearSelection:return{...e,...Ii(),selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,...Gi()};default:return null}}function ea(e,t){switch(t.type){case Z.SetProjects:{let n={...e.projectModelSelections};for(let e of t.projects)for(let t of e.threads){if(!t.model)continue;let e=n[t.threadId];n[t.threadId]={id:t.model,provider:t.modelProvider,name:e?.name??t.model,description:e?.description??``,context_length:e?.context_length,contextWindow:e?.contextWindow,features:e?.features,input_modalities:e?.input_modalities,max_output:e?.max_output,pricing:e?.pricing,tarsk_use:e?.tarsk_use,coding_index:e?.coding_index,supportsImages:e?.supportsImages}}return{...e,projects:t.projects,projectModelSelections:n}}case Z.SetProjectsLoading:return{...e,projectsLoading:t.projectsLoading};case Z.SetProjectModel:return console.log(`[Store] SetProjectModel action:`,{threadId:t.threadId,model:{id:t.model.id,provider:t.model.provider}}),{...e,projects:e.projects.map(e=>({...e,threads:e.threads.map(e=>e.threadId===t.threadId?{...e,model:t.model.id,modelProvider:t.model.provider}:e)})),projectModelSelections:{...e.projectModelSelections,[t.threadId]:t.model}};case Z.SetProcessingThreads:return{...e,processingThreadIds:t.threadIds,completedThreadIds:e.completedThreadIds.filter(e=>!t.threadIds.includes(e))};case Z.AddProcessingThread:return{...e,processingThreadIds:e.processingThreadIds.includes(t.threadId)?e.processingThreadIds:[...e.processingThreadIds,t.threadId],completedThreadIds:e.completedThreadIds.filter(e=>e!==t.threadId)};case Z.RemoveProcessingThread:return{...e,processingThreadIds:e.processingThreadIds.filter(e=>e!==t.threadId)};case Z.AddCreatingProject:return{...e,projects:[...e.projects,{projectId:t.projectId,name:t.projectName,gitUrl:t.gitUrl,threads:[{threadId:t.threadId,title:`thread-1`,path:``,currentBranch:``}]}]};case Z.AddCreatingThread:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:[...e.threads,{threadId:t.threadId,title:t.title,path:``,currentBranch:``}]}:e)};case Z.RemoveCreatingProject:return{...e,projects:e.projects.filter(e=>e.projectId!==t.projectId)};case Z.RemoveCreatingThread:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.filter(e=>e.threadId!==t.threadId)}:e)};case Z.MarkThreadCompleted:return{...e,completedThreadIds:e.completedThreadIds.includes(t.threadId)?e.completedThreadIds:[...e.completedThreadIds,t.threadId]};case Z.ClearThreadCompleted:return{...e,completedThreadIds:e.completedThreadIds.filter(e=>e!==t.threadId)};case Z.AddDeletingThread:return{...e,deletingThreadIds:e.deletingThreadIds.includes(t.threadId)?e.deletingThreadIds:[...e.deletingThreadIds,t.threadId]};case Z.RemoveDeletingThread:return{...e,deletingThreadIds:e.deletingThreadIds.filter(e=>e!==t.threadId)};case Z.AddDeletingProject:return{...e,deletingProjectIds:e.deletingProjectIds.includes(t.projectId)?e.deletingProjectIds:[...e.deletingProjectIds,t.projectId]};case Z.RemoveDeletingProject:return{...e,deletingProjectIds:e.deletingProjectIds.filter(e=>e!==t.projectId)};case Z.UpdateThreadTitle:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.map(e=>e.threadId===t.threadId?{...e,title:t.title}:e)}:e)};default:return null}}function ta(e){return e.type===`tool_use`}function na(e){return e.type===`tool-result`}function ra(e){return typeof e==`string`?e.replace(/\\n/g,`
3
+ `).replace(/✅/g,`✓`):``}function ia(e){if(!e||typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=/\[([A-Za-z]+)\]\s*/g,r,i=0;for(let e of t.matchAll(n))r=e[1],i=e.index+e[0].length;let a=r,o=a?t.slice(i):t;if(a&&o)return[{type:`reasoning`,text:o,label:a}];let s=[],c=0;for(;c<t.length;){let e=t.indexOf(`[`,c);if(e===-1){let e=t.slice(c).trim();e&&s.push({type:`reasoning`,text:e});break}let n=t.slice(c,e).trim();n&&s.push({type:`reasoning`,text:n});let r=0,i=-1;for(let n=e;n<t.length;n++)if(t[n]===`[`)r++;else if(t[n]===`]`&&(r--,r===0)){i=n;break}if(i===-1){let n=t.slice(e).trim();n&&s.push({type:`reasoning`,text:n});break}try{let n=JSON.parse(t.slice(e,i+1));if(Array.isArray(n)){for(let e of n)if(e&&typeof e==`object`&&`type`in e){let t=e.type;(t===`tool-result`||t===`tool_use`)&&s.push(e)}}}catch{let n=t.slice(e,i+1).trim();n&&s.push({type:`reasoning`,text:n})}c=i+1}return s.length>0?s:null}function aa(e,t){let n=0;for(let r=t;r<e.length;r++){let t=e[r];if(t===`[`)n++;else if(t===`]`&&(n--,n===0))return r}return-1}function oa(e,t=0){let n=[],r=t;for(;r<e.length;){for(;r<e.length&&/\s/.test(e.charAt(r));)r++;if(r>=e.length||e.charAt(r)!==`[`)break;let t=aa(e,r);if(t===-1)break;try{let i=JSON.parse(e.slice(r,t+1));if(!Array.isArray(i))break;n.push(...ca(i))}catch{break}r=t+1}return n.length===0?null:{blocks:n,nextIndex:r}}function sa(e,t){let n=[...e];for(let e of t){if(e.type===`tool_use`){let t=n.findIndex(t=>t.type===`tool_use`&&t.id===e.id);t>=0?n[t]=e:n.push(e);continue}if(e.type===`tool-result`){let t=n.findIndex(t=>t.type===`tool-result`&&t.toolCallId===e.toolCallId);t>=0?n[t]=e:n.push(e);continue}n.push(e)}return n}function ca(e){return e.map(e=>{if(typeof e==`object`&&e&&!(`type`in e)){let t=e;if(t.reasoning)return{type:`reasoning`,text:typeof t.reasoning==`string`?t.reasoning:JSON.stringify(t.reasoning)};let n=t.text??t.content??t.answer;if(n)return{type:`text`,text:typeof n==`string`?n:JSON.stringify(n)}}return e})}function la(e){let t=[];if(e.type===`long_running_confirmation`&&typeof e.prompt==`object`&&e.prompt!==null&&typeof e.prompt.question==`string`&&Array.isArray(e.prompt.options)){let n=e.prompt;return t.push({type:`long_running_confirmation`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:void 0,question:n.question,options:n.options.filter(e=>typeof e==`string`),context:typeof n.context==`string`?n.context:void 0}}),t}if(e.type===`shell_permission`&&typeof e.shellPermission==`object`&&e.shellPermission!==null&&typeof e.shellPermission.command==`string`){let n=e.shellPermission;return t.push({type:`shell_permission`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:`shell-permission`,command:n.command,source:n.source===`bash`||n.source===`skill_script`||n.source===`browser_js`?n.source:`bash`,wildcardOptions:Array.isArray(n.wildcardOptions)?n.wildcardOptions.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`&&typeof e.pattern==`string`&&(e.scope===`session`||e.scope===`project`)):[]}}),t}if(e.type===`web_fetch_permission`&&typeof e.webFetchPermission==`object`&&e.webFetchPermission!==null&&typeof e.webFetchPermission.hostname==`string`){let n=e.webFetchPermission;return t.push({type:`web_fetch_permission`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:`web-fetch-permission`,hostname:n.hostname,url:typeof n.url==`string`?n.url:``,wildcardOptions:Array.isArray(n.wildcardOptions)?n.wildcardOptions.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`&&typeof e.pattern==`string`&&(e.scope===`session`||e.scope===`project`)):[]}}),t}e.reasoning&&typeof e.reasoning==`string`&&t.push({type:`reasoning`,text:e.reasoning});let n=(typeof e.text==`string`?e.text:null)??(typeof e.content==`string`?e.content:null)??(typeof e.answer==`string`?e.answer:null);return n&&t.push({type:`text`,text:n}),t.length===0&&Object.keys(e).length>0&&t.push({type:`text`,text:JSON.stringify(e,null,2)}),t}function ua(e){return da(e)?.some(e=>e.type===`tool_use`||e.type===`tool-result`)??!1}function da(e){if(!e)return null;let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return ca(e);if(typeof e==`object`&&e)return la(e)}catch{if(t.startsWith(`[`)){let e=oa(t);if(e){let n=t.slice(e.nextIndex).trim();return n?[...e.blocks,{type:`text`,text:n}]:e.blocks}}}let n=[],r=e.indexOf(`{`),i=e.indexOf(`[`),a=r===-1?i:i===-1?r:Math.min(r,i);if(a!==-1){let t=e.slice(0,a).trim();t&&n.push({type:`text`,text:t});let r=e.slice(a),i=oa(r);if(i){n.push(...i.blocks);let e=r.slice(i.nextIndex).trim();return e&&n.push({type:`text`,text:e}),n}let o=Math.max(r.lastIndexOf(`]`),r.lastIndexOf(`}`));if(o!==-1){let e=r.substring(0,o+1);try{let t=JSON.parse(e);Array.isArray(t)?n.push(...ca(t)):n.push(...la(t));let i=r.substring(o+1).trim();return i&&n.push({type:`text`,text:i}),n}catch{}}}return n.length>0?n:null}function fa(e,t,n){let r=e[e.length-1];return r?.type===t?[...e.slice(0,-1),{type:t,chunks:[...r.chunks,n]}]:[...e,{type:t,chunks:[n]}]}function pa(e,t){return e[e.length-1]?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[t]}]:[...e,{type:`content`,chunks:[t]}]}function ma(e,t){let n=da(t);if(!n?.some(e=>e.type===`tool_use`||e.type===`tool-result`))return fa(e,`content`,t);let r=e[e.length-1],i=n;if(r?.type===`content`){let e=r.chunks.join(``);i=sa(da(e)??(e.trim()?[{type:`text`,text:e}]:[]),n)}let a=JSON.stringify(i);return r?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[a]}]:[...e,{type:`content`,chunks:[a]}]}function ha(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`content`)return n.chunks.join(``)}return``}function ga(e,t){return[...e,{type:`long_running_confirmation`,prompt:t}]}function _a(e,t){return[...e,{type:`shell_permission`,prompt:t}]}function va(e,t){return[...e,{type:`web_fetch_permission`,prompt:t}]}function ya(e){let t=[];for(let n of e){if(n.type===`long_running_confirmation`){t.push({type:`long_running_confirmation`,prompt:n.prompt});continue}if(n.type===`shell_permission`){t.push({type:`shell_permission`,prompt:n.prompt});continue}if(n.type===`web_fetch_permission`){t.push({type:`web_fetch_permission`,prompt:n.prompt});continue}let e=n.chunks.join(``);if(n.type===`thinking`){let n=ia(e)??[];t.push(...n)}else{let n=da(e)??(e.trim()?[{type:`text`,text:e}]:[]);t.push(...n)}}return t}function ba(e){return e.type===`thinking-group`}function xa(e,t=!1){let n=[],r=[],i,a=()=>{r.length>0&&(n.push({type:`thinking-group`,text:r.join(`
4
+
5
+ `),label:i,isCurrentlyStreaming:!1}),r=[],i=void 0)};for(let t of e)if(t.type===`reasoning`&&`text`in t){let e=t;r.push(e.text),e.label&&(i=e.label)}else a(),n.push(t);if(a(),t&&n.length>0){let e=n[n.length-1];if(e.type===`thinking-group`){let t=e;t.label!==`Validated`&&(t.isCurrentlyStreaming=!0)}}return n}function Sa(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`long_running_confirmation`||n.type===`shell_permission`||n.type===`web_fetch_permission`)return t}return-1}function Ca(e){return e.type===`content`||e.type===`thinking`?e.chunks.some(e=>e.trim().length>0):!1}function wa(e){let t=ya(e),n=t.some(e=>ta(e)&&e.name===`ask_user`),r=t.some(e=>na(e)&&e.toolName===`ask_user`);if(n&&!r)return!0;let i=Sa(e);return i===-1?!1:!e.slice(i+1).some(Ca)}function Ta(e){let t=ya(e);return t.length===0?`...`:t.length===1&&t[0]?.type===`text`&&`text`in t[0]?t[0].text:JSON.stringify(t)}function Ea(e,t){switch(t.type){case Z.SetStreaming:{let n=zi(e,t),r=Bi(e,t);return Hi(e,n,r,{...Ri(e.threadStreamingStates,n,r),isStreaming:t.isStreaming})}case Z.AppendStreamContent:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingContent:i.streamingContent+t.content})}case Z.SetStreamContent:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r),a=pa(i.streamingSegments,t.content);return Hi(e,n,r,{...i,streamingContent:t.content,streamingSegments:a})}case Z.AppendStreamThinking:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingThinking:i.streamingThinking+t.content})}case Z.IncrementStreamEventCount:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingEventCount:i.streamingEventCount+1})}case Z.AppendStreamChunk:{let n=zi(e,t),r=Bi(e,t),i=Ri(e.threadStreamingStates,n,r);return Hi(e,n,r,{...i,streamingSegments:t.segments,streamingContent:t.chunkType===`content`?i.streamingContent+t.content:i.streamingContent,streamingThinking:t.chunkType===`thinking`?i.streamingThinking+t.content:i.streamingThinking})}case Z.SetStreamModel:{let n=zi(e,t),r=Bi(e,t);return Hi(e,n,r,{...Ri(e.threadStreamingStates,n,r),streamingModel:t.model})}case Z.ResetStream:return Hi(e,zi(e,t),Bi(e,t),Ii(),!0);case Z.StopStream:{let n=zi(e,t),r=Bi(e,t);return Hi(e,n,r,{...Ri(e.threadStreamingStates,n,r),isStreaming:!1})}default:return null}}function Da(e,t){return e.terminalStates[t]??Ui()}function Oa(e,t){switch(t.type){case Z.AppendCommandOutput:return{...e,commandOutput:e.commandOutput+t.content};case Z.SetRunningCommand:return{...e,isRunningCommand:t.isRunning};case Z.ClearCommandOutput:return{...e,commandOutput:``};case Z.ToggleTerminal:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,open:!n.open}}}}case Z.SetTerminalOpen:{let n=t.threadId??`default`,r=Da(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:t.open}}}}case Z.QueueTerminalCommand:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,queuedCommand:t.command,queuedRelativeFolder:t.relativeFolder??null,open:!0}}}}case Z.ClearQueuedTerminalCommand:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,queuedCommand:null}}}}case Z.AppendTerminalLine:{let n=t.threadId??`default`,r=Da(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[...r.outputLines,t.line]}}}}case Z.ClearTerminalOutput:{let n=t.threadId??`default`,r=Da(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[]}}}}case Z.SetTerminalHeight:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,height:t.height}}}}case Z.SetTerminalCwd:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,cwd:t.cwd}}}}case Z.SetTerminalRunning:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,isRunning:t.isRunning}}}}case Z.SetTerminalHistory:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,history:t.history}}}}case Z.SetTerminalHistoryIndex:{let n=Da(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,historyIndex:t.index}}}}default:return null}}function ka(e,t){switch(t.type){case Z.ToggleSidebar:return{...e,sidebarOpen:!e.sidebarOpen};case Z.CloseSidebar:return e.sidebarOpen?{...e,sidebarOpen:!1}:e;case Z.SetCreatingProject:return{...e,isCreatingProject:t.isCreating};case Z.ConfigUpdated:return{...e,configUpdatedAt:Date.now()};case Z.ClearFocusChatInput:return{...e,focusChatInput:!1};case Z.SetDiffComments:return{...e,diffComments:{...e.diffComments,[t.threadId]:t.comments}};default:return null}}var Aa=[Ea,$i,Qi,ea,Oa,ka];function ja(e,t){for(let n of Aa){let r=n(e,t);if(r!==null)return r}return e}var Ma=new Set([Z.AppendStreamChunk,Z.IncrementStreamEventCount,Z.SetStreamModel,Z.AppendStreamContent,Z.AppendStreamThinking,Z.SetStreamContent]);function Na(e=ji){let t=e,n=new Set,r=0,i=[];function a(){return t}function o(){for(let e of n)e()}function s(e){let n=ja(t,e);n!==t&&(t=n)}function c(){if(r=0,i.length!==0){for(let e of i)s(e);i.length=0,o()}}function l(e){if(Ma.has(e.type)){i.push(e),r===0&&(r=requestAnimationFrame(c));return}s(e),o()}function u(e){return n.add(e),function(){n.delete(e)}}return{getState:a,dispatch:l,subscribe:u}}var Pa=(0,Y.createContext)(null);function Fa(){let e=(0,Y.useContext)(Pa);if(!e)throw Error(`useAppStore must be used within an AppStoreContext.Provider`);return e}function Q(e){let t=(0,X.c)(3),n=Fa(),r;t[0]!==e||t[1]!==n?(r=function(){return e(n.getState())},t[0]=e,t[1]=n,t[2]=r):r=t[2];let i=r;return(0,Y.useSyncExternalStore)(n.subscribe,i,i)}function Ia(){return Fa().dispatch}function La(e){let t=(0,X.c)(8),n=Ia(),r;t[0]===e?r=t[1]:(r=t=>(e?t.terminalStates[e]:void 0)??Mi,t[0]=e,t[1]=r);let i=Q(r),a;t[2]!==n||t[3]!==e?(a=t=>{e&&n({...t,threadId:e})},t[2]=n,t[3]=e,t[4]=a):a=t[4];let o=a,s;return t[5]!==o||t[6]!==i?(s={terminalState:i,dispatch:o},t[5]=o,t[6]=i,t[7]=s):s=t[7],s}var $=Jt(),Ra=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=V(`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(`textarea`,{className:a,ref:t,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ra.displayName=`Textarea`;function za(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:o,feedbackEmail:s,onFeedbackEmailChange:c,feedbackText:l,onFeedbackTextChange:u,loadingFeedbackUser:d,submittingFeedback:f,onSubmit:p}=e,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsxs)(_t,{children:[(0,$.jsx)(Cn,{children:`Send Feedback`}),(0,$.jsx)(be,{children:`Share feedback about Tarsk.`})]}),t[0]=m):m=t[0];let h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(z,{htmlFor:`feedback-name`,children:`Name`}),t[1]=h):h=t[1];let g;t[2]===o?g=t[3]:(g=e=>o(e.target.value),t[2]=o,t[3]=g);let _=f||d,v;t[4]!==i||t[5]!==g||t[6]!==_?(v=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[h,(0,$.jsx)(R,{id:`feedback-name`,value:i,onChange:g,placeholder:`Your name`,disabled:_})]}),t[4]=i,t[5]=g,t[6]=_,t[7]=v):v=t[7];let y;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(z,{htmlFor:`feedback-email`,children:`Email`}),t[8]=y):y=t[8];let b;t[9]===c?b=t[10]:(b=e=>c(e.target.value),t[9]=c,t[10]=b);let x=f||d,S;t[11]!==s||t[12]!==b||t[13]!==x?(S=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[y,(0,$.jsx)(R,{id:`feedback-email`,type:`email`,value:s,onChange:b,placeholder:`you@example.com`,disabled:x})]}),t[11]=s,t[12]=b,t[13]=x,t[14]=S):S=t[14];let C;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(z,{htmlFor:`feedback-text`,children:`Feedback`}),t[15]=C):C=t[15];let w;t[16]===u?w=t[17]:(w=e=>u(e.target.value),t[16]=u,t[17]=w);let T;t[18]!==l||t[19]!==f||t[20]!==w?(T=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[C,(0,$.jsx)(Ra,{id:`feedback-text`,value:l,onChange:w,placeholder:`Tell us what you think...`,className:`min-h-32`,disabled:f})]}),t[18]=l,t[19]=f,t[20]=w,t[21]=T):T=t[21];let E;t[22]!==T||t[23]!==v||t[24]!==S?(E=(0,$.jsxs)(`div`,{className:`grid gap-4 py-2`,children:[v,S,T]}),t[22]=T,t[23]=v,t[24]=S,t[25]=E):E=t[25];let D;t[26]===r?D=t[27]:(D=()=>r(!1),t[26]=r,t[27]=D);let O;t[28]!==f||t[29]!==D?(O=(0,$.jsx)(Rt,{variant:`outline`,onClick:D,disabled:f,children:`Cancel`}),t[28]=f,t[29]=D,t[30]=O):O=t[30];let k;t[31]===f?k=t[32]:(k=f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cn,{className:`mr-2 h-4 w-4 animate-spin`}),`Sending...`]}):`Send`,t[31]=f,t[32]=k);let A;t[33]!==p||t[34]!==f||t[35]!==k?(A=(0,$.jsx)(Rt,{onClick:p,disabled:f,children:k}),t[33]=p,t[34]=f,t[35]=k,t[36]=A):A=t[36];let j;t[37]!==O||t[38]!==A?(j=(0,$.jsxs)(a,{children:[O,A]}),t[37]=O,t[38]=A,t[39]=j):j=t[39];let M;t[40]!==E||t[41]!==j?(M=(0,$.jsxs)(Ye,{className:`max-w-xl max-md:top-[max(1rem,env(safe-area-inset-top,0px))] max-md:max-h-[calc(100dvh-2rem)] max-md:translate-y-0 max-md:overflow-y-auto max-md:data-[state=closed]:slide-out-to-top max-md:data-[state=open]:slide-in-from-top max-md:data-[state=closed]:slide-out-to-left-0 max-md:data-[state=open]:slide-in-from-left-0 max-md:data-[state=closed]:zoom-out-100 max-md:data-[state=open]:zoom-in-100`,children:[m,E,j]}),t[40]=E,t[41]=j,t[42]=M):M=t[42];let N;return t[43]!==r||t[44]!==n||t[45]!==M?(N=(0,$.jsx)(Ge,{open:n,onOpenChange:r,children:M}),t[43]=r,t[44]=n,t[45]=M,t[46]=N):N=t[46],N}function Ba(e){let t=(0,X.c)(30),{node:n,level:r,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l,forceOpenIds:u}=e,d=!!(n.children&&n.children.length>0),f,p,m;if(t[0]!==a||t[1]!==u||t[2]!==d||t[3]!==r||t[4]!==n||t[5]!==l||t[6]!==c||t[7]!==i){f=u?.has(n.id)||(c[n.id]??a);let e;t[11]!==n.id||t[12]!==l?(e=()=>l(n.id),t[11]=n.id,t[12]=l,t[13]=e):e=t[13];let o=e;p=`min-w-0`,m=i(n,{isOpen:f,level:r,toggle:o,hasChildren:d}),t[0]=a,t[1]=u,t[2]=d,t[3]=r,t[4]=n,t[5]=l,t[6]=c,t[7]=i,t[8]=f,t[9]=p,t[10]=m}else f=t[8],p=t[9],m=t[10];let h;t[14]!==s||t[15]!==a||t[16]!==u||t[17]!==d||t[18]!==o||t[19]!==f||t[20]!==r||t[21]!==n.children||t[22]!==l||t[23]!==c||t[24]!==i?(h=d&&f&&(0,$.jsx)(`div`,{style:{paddingLeft:o},className:s,children:n.children.map(e=>(0,$.jsx)(Ba,{node:e,level:r+1,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l,forceOpenIds:u},e.id))}),t[14]=s,t[15]=a,t[16]=u,t[17]=d,t[18]=o,t[19]=f,t[20]=r,t[21]=n.children,t[22]=l,t[23]=c,t[24]=i,t[25]=h):h=t[25];let g;return t[26]!==p||t[27]!==m||t[28]!==h?(g=(0,$.jsxs)(`div`,{className:p,children:[m,h]}),t[26]=p,t[27]=m,t[28]=h,t[29]=g):g=t[29],g}function Va(e){let t=(0,X.c)(28),{nodes:n,renderNode:r,resetKey:i,defaultOpen:a,forceOpenIds:o,initialOpenIds:s,indent:c,childContainerClassName:l,className:u}=e,d=a===void 0?!1:a,f=c===void 0?16:c,p;t[0]===s?p=t[1]:(p=()=>{let e={};if(s)for(let t of s)e[t]=!0;return e},t[0]=s,t[1]=p);let[m,h]=(0,Y.useState)(p),[g,_]=(0,Y.useState)(i);if(i!==g){_(i);let e={};if(s)for(let t of s)e[t]=!0;h(e)}let v;t[2]===o?v=t[3]:(v=o?new Set(o):void 0,t[2]=o,t[3]=v);let y=v,b;t[4]===d?b=t[5]:(b=e=>{h(t=>({...t,[e]:!(t[e]??d)}))},t[4]=d,t[5]=b);let x=b,S;t[6]===u?S=t[7]:(S=V(`min-w-0`,u),t[6]=u,t[7]=S);let C;if(t[8]!==l||t[9]!==d||t[10]!==y||t[11]!==x||t[12]!==f||t[13]!==n||t[14]!==m||t[15]!==r){let e;t[17]!==l||t[18]!==d||t[19]!==y||t[20]!==x||t[21]!==f||t[22]!==m||t[23]!==r?(e=e=>(0,$.jsx)(Ba,{node:e,level:0,renderNode:r,defaultOpen:d,indent:f,childContainerClassName:l,openState:m,onToggle:x,forceOpenIds:y},e.id),t[17]=l,t[18]=d,t[19]=y,t[20]=x,t[21]=f,t[22]=m,t[23]=r,t[24]=e):e=t[24],C=n.map(e),t[8]=l,t[9]=d,t[10]=y,t[11]=x,t[12]=f,t[13]=n,t[14]=m,t[15]=r,t[16]=C}else C=t[16];let w;return t[25]!==S||t[26]!==C?(w=(0,$.jsx)(`div`,{className:S,children:C}),t[25]=S,t[26]=C,t[27]=w):w=t[27],w}var Ha=1,Ua=1e3,Wa=0;function Ga(){return Wa=(Wa+1)%(2**53-1),Wa.toString()}var Ka=new Map,qa=e=>{if(Ka.has(e))return;let t=setTimeout(()=>{Ka.delete(e),Za({type:`REMOVE_TOAST`,toastId:e})},Ua);Ka.set(e,t)},Ja=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,Ha)};case`UPDATE_TOAST`:return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case`DISMISS_TOAST`:{let{toastId:n}=t;return n?qa(n):e.toasts.forEach(e=>{qa(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===n||n===void 0?{...e,open:!1}:e)}}case`REMOVE_TOAST`:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},Ya=[],Xa={toasts:[]};function Za(e){Xa=Ja(Xa,e),Ya.forEach(e=>{e(Xa)})}function Qa({...e}){let t=Ga(),n=e=>Za({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>Za({type:`DISMISS_TOAST`,toastId:t});return Za({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function $a(){let e=(0,X.c)(4),[t,n]=Y.useState(Xa),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(Ya.push(n),()=>{let e=Ya.indexOf(n);e>-1&&Ya.splice(e,1)}),i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i);let a;return e[2]===t?a=e[3]:(a={...t,toast:Qa,dismiss:eo},e[2]=t,e[3]=a),a}function eo(e){return Za({type:`DISMISS_TOAST`,toastId:e})}function to(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!0;return l(!0),kn().then(e=>{t&&(r(t=>t||e.name),a(t=>t||e.email))}).catch(()=>{t&&Qa({title:`Could not load git details`,description:`You can still submit feedback by entering your name and email manually.`,variant:`destructive`})}).finally(()=>{t&&l(!1)}),()=>{t=!1}},[e]),{showFeedback:e,feedbackName:n,setFeedbackName:r,feedbackEmail:i,setFeedbackEmail:a,feedbackText:o,setFeedbackText:s,loadingFeedbackUser:c,submittingFeedback:u,handleFeedbackDialogChange:e=>{t(e),e||s(``)},handleSubmitFeedback:async()=>{let e=o.trim();if(!e){Qa({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}d(!0);try{await ye(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),Qa({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),s(``),t(!1)}catch(e){Qa({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{d(!1)}}}}var no=ei(e=>(0,$.jsxs)(`div`,{className:e.v0,style:e.v1,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-sidebar-border px-4 py-3 h-[61px]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e.v2,className:`flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm cursor-pointer`,children:(0,$.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:`h-full w-full`})}),e.v3]}),e.v4]}),e.v5,e.v6]}),{name:`SidePanelContainer_1`,portals:[`v3`,`v4`,`v5`,`v6`]}),ro=function(e){let t=(0,X.c)(23),{children:n,collapsed:i,title:a,onTitleClose:o,subtitle:s,headerAction:c,footer:l,isDevMode:u}=e,d,f,p,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=yt(),p=function(){et(`https://tarsk.io/`)},d=no,m=V(`flex flex-col select-none bg-sidebar text-sidebar-foreground mx-2.5 md:mr-10 rounded-3xl shadow-2xl overflow-hidden`,f&&`mt-8`),t[0]=d,t[1]=f,t[2]=p,t[3]=m):(d=t[0],f=t[1],p=t[2],m=t[3]);let h;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(h={containerType:`inline-size`,height:f?`calc(100% - 42px)`:`calc(100% - 12px)`},t[4]=h):h=t[4];let g;t[5]!==i||t[6]!==u||t[7]!==s?(g=!i&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:p,className:V(r.sectionTitle,u&&`text-destructive dark:text-red-400`,`cursor-pointer hover:underline`),children:u?`Dev Mode`:`tarsk`}),s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Je,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,$.jsx)(`span`,{className:V(r.label,`text-sidebar-foreground/80`),children:s})]})]}),t[5]=i,t[6]=u,t[7]=s,t[8]=g):g=t[8];let _;t[9]!==i||t[10]!==c||t[11]!==o||t[12]!==a?(_=(a??o??c)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[c&&!i&&c,a&&(0,$.jsx)(`span`,{className:V(r.compact,`font-medium text-sidebar-foreground/80`),children:a}),o&&(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:o,children:[(0,$.jsx)(Ce,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]}),t[9]=i,t[10]=c,t[11]=o,t[12]=a,t[13]=_):_=t[13];let v;t[14]===n?v=t[15]:(v=(0,$.jsx)(st,{className:`flex-1`,children:n}),t[14]=n,t[15]=v);let y;t[16]===l?y=t[17]:(y=l&&(0,$.jsx)(`div`,{className:`border-t border-sidebar-border`,children:l}),t[16]=l,t[17]=y);let b;return t[18]!==g||t[19]!==_||t[20]!==v||t[21]!==y?(b=(0,$.jsx)(d,{v0:m,v1:h,v2:p,v3:g,v4:_,v5:v,v6:y}),t[18]=g,t[19]=_,t[20]=v,t[21]=y,t[22]=b):b=t[22],b},io=ei(e=>(0,$.jsx)(`svg`,{className:e.v0,viewBox:`0 0 12 12`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})}),{name:`ThreadStatusDot_1`,svg:!0}),ao=ei(e=>(0,$.jsx)(`svg`,{className:e.v0,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.0`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`4.5`})}),{name:`ThreadStatusDot_2`,svg:!0}),oo=function(e){let t=(0,X.c)(9),{gitStatusDot:n,animate:r}=e,i=!!n,a=r&&`animate-thread-dot-pulse`,o=n===`changes`&&`text-brand`,s;t[0]!==i||t[1]!==n||t[2]!==a||t[3]!==o?(s=V(`h-3 w-3 shrink-0 origin-center`,a,o,Me(n)&&`text-orange-500`,!i&&`text-muted-foreground`),t[0]=i,t[1]=n,t[2]=a,t[3]=o,t[4]=s):s=t[4];let c=s;if(i){let e;return t[5]===c?e=t[6]:(e=(0,$.jsx)(io,{v0:c}),t[5]=c,t[6]=e),e}let l;return t[7]===c?l=t[8]:(l=(0,$.jsx)(ao,{v0:c}),t[7]=c,t[8]=l),l};function so(e){let t=(0,X.c)(87),{projects:n,selectedThreadId:i,selectedProjectId:a,processingThreadIds:o,completedThreadIds:s,deletingThreadIds:c,deletingProjectIds:l,onSelectThread:u,onCreateProject:d,onCreateThread:f,onDeleteThread:p,onDeleteProject:m,collapsed:h,updateAvailable:g,updatingApp:_,onUpdateApp:v,isDevMode:y,expandProjectId:b}=e,x=er(),S=Q(fo),w=Q(uo),{showFeedback:E,feedbackName:D,setFeedbackName:O,feedbackEmail:k,setFeedbackEmail:A,feedbackText:j,setFeedbackText:M,loadingFeedbackUser:N,submittingFeedback:F,handleFeedbackDialogChange:I,handleSubmitFeedback:L}=to(),R;t[0]===n?R=t[1]:(R=[...n].sort(lo),t[0]=n,t[1]=R);let ee=R,z;t[2]===ee?z=t[3]:(z=ee.map(co),t[2]=ee,t[3]=z);let te=z,ne;bb0:{if(!a){ne=void 0;break bb0}if(n.find(e=>e.projectId===a)?.threads.length===1){ne=void 0;break bb0}let e;t[4]===a?e=t[5]:(e=[a],t[4]=a,t[5]=e),ne=e}let re=ne,ie;t[6]===b?ie=t[7]:(ie=b?[b]:void 0,t[6]=b,t[7]=ie);let ae=ie,oe;t[8]!==h||t[9]!==d?(oe=!h&&(0,$.jsxs)(Rt,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:d,children:[(0,$.jsx)(Le,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[8]=h,t[9]=d,t[10]=oe):oe=t[10];let se;t[11]!==h||t[12]!==v||t[13]!==g||t[14]!==_?(se=g&&(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:v,disabled:_,children:[_?(0,$.jsx)(cn,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Gn,{className:`h-4 w-4`}),!h&&(0,$.jsx)(`span`,{className:`truncate`,children:_?`Updating...`:`Update to Latest`})]}),t[11]=h,t[12]=v,t[13]=g,t[14]=_,t[15]=se):se=t[15];let ce;t[16]===x?ce=t[17]:(ce=()=>void x(`/settings/general`),t[16]=x,t[17]=ce);let le;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(xe,{className:`h-4 w-4`}),t[18]=le):le=t[18];let ue;t[19]===h?ue=t[20]:(ue=!h&&(0,$.jsx)(`span`,{className:`truncate`,children:`Settings`}),t[19]=h,t[20]=ue);let de;t[21]!==ce||t[22]!==ue?(de=(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:ce,children:[le,ue]}),t[21]=ce,t[22]=ue,t[23]=de):de=t[23];let fe;t[24]===I?fe=t[25]:(fe=()=>I(!0),t[24]=I,t[25]=fe);let H,pe;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(Dn,{className:`h-4 w-4`}),pe=(0,$.jsx)(`span`,{className:`sr-only`,children:`Feedback`}),t[26]=H,t[27]=pe):(H=t[26],pe=t[27]);let me;t[28]===fe?me=t[29]:(me=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:fe,children:[H,pe]})}),t[28]=fe,t[29]=me);let he;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(T,{children:`Send feedback to the Tarsk team`}),t[30]=he):he=t[30];let ge;t[31]===me?ge=t[32]:(ge=(0,$.jsx)(P,{children:(0,$.jsxs)(U,{children:[me,he]})}),t[31]=me,t[32]=ge);let _e;t[33]!==de||t[34]!==ge?(_e=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[de,ge]}),t[33]=de,t[34]=ge,t[35]=_e):_e=t[35];let ve;t[36]!==_e||t[37]!==se?(ve=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[se,_e]}),t[36]=_e,t[37]=se,t[38]=ve):ve=t[38];let ye;t[39]===n.length?ye=t[40]:(ye=n.length===0&&(0,$.jsx)(`p`,{className:V(r.compact,`px-3 py-6 text-center text-muted-foreground`),children:`No projects yet. Clone a repository to get started.`}),t[39]=n.length,t[40]=ye);let be;t[41]!==s||t[42]!==l||t[43]!==c||t[44]!==x||t[45]!==f||t[46]!==m||t[47]!==p||t[48]!==u||t[49]!==w||t[50]!==o||t[51]!==n||t[52]!==a||t[53]!==i||t[54]!==S?(be=(e,t)=>{let{isOpen:r,toggle:d}=t;return e.kind===`project`?(0,$.jsx)(po,{project:e.project,isOpen:r,onToggle:d,isDeletingProject:l.includes(e.project.projectId),isSelected:a?e.project.projectId===a:!1,onCreateThread:f,onDeleteProject:m,onProjectSettings:e=>void x(`/settings/project/${e}`),hasSelectedThread:e.project.threads.some(e=>e.threadId===i),onSelectThread:u}):(0,$.jsx)(mo,{thread:e.thread,projectId:e.projectId,selectedThreadId:i,isProcessing:Ni(e.thread.threadId,o,S,w),isDeleting:c.includes(e.thread.threadId),isCompleted:s.includes(e.thread.threadId),projectTitlePrefix:`${C(n.find(t=>t.projectId===e.projectId))} - `,onSelectThread:u,onDeleteThread:p})},t[41]=s,t[42]=l,t[43]=c,t[44]=x,t[45]=f,t[46]=m,t[47]=p,t[48]=u,t[49]=w,t[50]=o,t[51]=n,t[52]=a,t[53]=i,t[54]=S,t[55]=be):be=t[55];let Se;t[56]!==ae||t[57]!==re||t[58]!==te||t[59]!==be?(Se=(0,$.jsx)(Va,{nodes:te,defaultOpen:!1,initialOpenIds:re,forceOpenIds:ae,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:be}),t[56]=ae,t[57]=re,t[58]=te,t[59]=be,t[60]=Se):Se=t[60];let Ce;t[61]!==ye||t[62]!==Se?(Ce=(0,$.jsx)(`div`,{className:`flex-1 w-full`,children:(0,$.jsxs)(`div`,{className:`px-2 py-2 w-full max-w-full overflow-hidden`,children:[ye,Se]})}),t[61]=ye,t[62]=Se,t[63]=Ce):Ce=t[63];let W;t[64]!==h||t[65]!==y||t[66]!==ve||t[67]!==Ce||t[68]!==oe?(W=(0,$.jsx)(ro,{collapsed:h,isDevMode:y,headerAction:oe,footer:ve,children:Ce}),t[64]=h,t[65]=y,t[66]=ve,t[67]=Ce,t[68]=oe,t[69]=W):W=t[69];let we;t[70]===L?we=t[71]:(we=()=>void L(),t[70]=L,t[71]=we);let Te;t[72]!==k||t[73]!==D||t[74]!==j||t[75]!==I||t[76]!==N||t[77]!==A||t[78]!==O||t[79]!==M||t[80]!==E||t[81]!==F||t[82]!==we?(Te=(0,$.jsx)(za,{open:E,onOpenChange:I,feedbackName:D,onFeedbackNameChange:O,feedbackEmail:k,onFeedbackEmailChange:A,feedbackText:j,onFeedbackTextChange:M,loadingFeedbackUser:N,submittingFeedback:F,onSubmit:we}),t[72]=k,t[73]=D,t[74]=j,t[75]=I,t[76]=N,t[77]=A,t[78]=O,t[79]=M,t[80]=E,t[81]=F,t[82]=we,t[83]=Te):Te=t[83];let Ee;return t[84]!==W||t[85]!==Te?(Ee=(0,$.jsxs)($.Fragment,{children:[W,Te]}),t[84]=W,t[85]=Te,t[86]=Ee):Ee=t[86],Ee}function co(e,t){return{id:e.projectId||e.gitUrl||`project-${t}`,kind:`project`,project:e,children:e.threads.map((t,n)=>({id:t.threadId||`${e.projectId}-${t.title||n}`,kind:`thread`,thread:t,projectId:e.projectId}))}}function lo(e,t){return C(e).localeCompare(C(t))}function uo(e){return e.pendingChatMessage}function fo(e){return e.threadStreamingStates}function po(e){let t=(0,X.c)(39),{project:n,isOpen:r,onToggle:i,isDeletingProject:a,hasSelectedThread:o,isSelected:s,onCreateThread:c,onDeleteProject:l,onProjectSettings:u,onSelectThread:d}=e,f;t[0]===n?f=t[1]:(f=C(n),t[0]=n,t[1]=f);let p=f,m=o||s,h=n.threads.length===1?n.threads[0]:null,g;t[2]!==d||t[3]!==i||t[4]!==n.projectId||t[5]!==h||t[6]!==m?(g=function(){if(!m&&h){d(n.projectId,h.threadId);return}i()},t[2]=d,t[3]=i,t[4]=n.projectId,t[5]=h,t[6]=m,t[7]=g):g=t[7];let v=g,y=o||s,b=r&&`rotate-90`,x;t[8]===b?x=t[9]:(x=V(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,b),t[8]=b,t[9]=x);let S;t[10]===x?S=t[11]:(S=(0,$.jsx)(Je,{className:x}),t[10]=x,t[11]=S);let w;t[12]===n.gitUrl?w=t[13]:(w=n.gitUrl?(0,$.jsx)(Ht,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,$.jsx)(_,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[12]=n.gitUrl,t[13]=w);let E=(o||s)&&`font-bold text-foreground`,D;t[14]===E?D=t[15]:(D=V(`min-w-0 truncate transition-all block`,E),t[14]=E,t[15]=D);let O;t[16]!==p||t[17]!==D?(O=(0,$.jsx)(`span`,{className:D,children:p}),t[16]=p,t[17]=D,t[18]=O):O=t[18];let k;t[19]!==O||t[20]!==S||t[21]!==w?(k=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[S,w,O]}),t[19]=O,t[20]=S,t[21]=w,t[22]=k):k=t[22];let A;t[23]!==v||t[24]!==k?(A=(0,$.jsx)(`button`,{type:`button`,className:`min-w-0`,onClick:v,children:k}),t[23]=v,t[24]=k,t[25]=A):A=t[25];let j;t[26]!==A||t[27]!==y?(j=(0,$.jsx)(fi,{selected:y,noBackground:!0,className:`h-9 min-w-0 flex-1`,asChild:!0,children:A}),t[26]=A,t[27]=y,t[28]=j):j=t[28];let M;t[29]!==a||t[30]!==c||t[31]!==l||t[32]!==u||t[33]!==n.projectId||t[34]!==n.threads.length?(M=(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:a?(0,$.jsx)(cn,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,$.jsxs)(P,{children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>u(n.projectId),children:[(0,$.jsx)(xe,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,$.jsx)(T,{side:`right`,children:`Project settings`})]}),(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`action`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>c(n.projectId),children:[(0,$.jsx)(Le,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,$.jsx)(T,{side:`right`,children:`Add thread`})]}),n.threads.length===0&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:()=>l(n.projectId),children:[(0,$.jsx)(Bt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(T,{side:`right`,children:`Delete project`})]})]})}),t[29]=a,t[30]=c,t[31]=l,t[32]=u,t[33]=n.projectId,t[34]=n.threads.length,t[35]=M):M=t[35];let N;return t[36]!==j||t[37]!==M?(N=(0,$.jsxs)(`div`,{className:`group mb-1 flex min-w-0 items-center`,children:[j,M]}),t[36]=j,t[37]=M,t[38]=N):N=t[38],N}function mo(e){let t=(0,X.c)(57),{thread:n,projectId:i,selectedThreadId:a,isProcessing:o,isDeleting:s,isCompleted:c,projectTitlePrefix:l,onSelectThread:u,onDeleteThread:d}=e,[f,p]=(0,Y.useState)(!1),m=(0,Y.useRef)(null),h=n.threadId===a,g,_;t[0]===o?(g=t[1],_=t[2]):(g=()=>{o&&m.current&&m.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},_=[o],t[0]=o,t[1]=g,t[2]=_),(0,Y.useEffect)(g,_);let v;t[3]!==d||t[4]!==i||t[5]!==n.gitStatusDot||t[6]!==n.threadId?(v=e=>{e.stopPropagation(),n.gitStatusDot?p(!0):d(i,n.threadId)},t[3]=d,t[4]=i,t[5]=n.gitStatusDot,t[6]=n.threadId,t[7]=v):v=t[7];let y=v,b;t[8]!==l||t[9]!==n.threadId||t[10]!==n.title?(b=n.title?.startsWith(l)?n.title.slice(l.length):n.title??n.threadId,t[8]=l,t[9]=n.threadId,t[10]=n.title,t[11]=b):b=t[11];let x=b,S;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)($r,{children:`Delete Thread`}),t[12]=S):S=t[12];let C;t[13]===x?C=t[14]:(C=(0,$.jsxs)(ti,{children:[`Are you sure you want to delete "`,x,`" and all its files? This action cannot be undone.`]}),t[13]=x,t[14]=C);let w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(Zr,{children:`Cancel`}),t[15]=w):w=t[15];let E;t[16]!==d||t[17]!==i||t[18]!==n.threadId?(E=(0,$.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[w,(0,$.jsx)(si,{onClick:()=>{p(!1),d(i,n.threadId)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[16]=d,t[17]=i,t[18]=n.threadId,t[19]=E):E=t[19];let D;t[20]!==C||t[21]!==E?(D=(0,$.jsxs)(oi,{children:[S,C,E]}),t[20]=C,t[21]=E,t[22]=D):D=t[22];let O;t[23]!==f||t[24]!==D?(O=(0,$.jsx)(ri,{open:f,onOpenChange:p,children:D}),t[23]=f,t[24]=D,t[25]=O):O=t[25];let k;t[26]!==u||t[27]!==i||t[28]!==n.threadId?(k=()=>u(i,n.threadId),t[26]=u,t[27]=i,t[28]=n.threadId,t[29]=k):k=t[29];let A=o||s,j;t[30]!==A||t[31]!==n.gitStatusDot?(j=(0,$.jsx)(oo,{gitStatusDot:n.gitStatusDot,animate:A}),t[30]=A,t[31]=n.gitStatusDot,t[32]=j):j=t[32];let M;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(M=V(r.body,`truncate block`),t[33]=M):M=t[33];let N;t[34]===x?N=t[35]:(N=(0,$.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,$.jsx)(`span`,{className:M,children:x})}),t[34]=x,t[35]=N);let P;t[36]===c?P=t[37]:(P=c?(0,$.jsx)(bt,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):null,t[36]=c,t[37]=P);let F;t[38]!==k||t[39]!==j||t[40]!==N||t[41]!==P?(F=(0,$.jsxs)(`button`,{type:`button`,className:`min-w-0 w-full`,onClick:k,children:[j,N,P]}),t[38]=k,t[39]=j,t[40]=N,t[41]=P,t[42]=F):F=t[42];let I;t[43]!==h||t[44]!==F?(I=(0,$.jsx)(fi,{selected:h,className:`min-w-0 flex-1`,asChild:!0,children:F}),t[43]=h,t[44]=F,t[45]=I):I=t[45];let L;t[46]!==y||t[47]!==c||t[48]!==s||t[49]!==o?(L=!o&&!s&&!c&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-sm`,className:`hidden can-hover:group-hover:flex shrink-0 items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:y,children:[(0,$.jsx)(Bt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,$.jsx)(T,{side:`right`,children:`Delete thread and files from the repo`})]}),t[46]=y,t[47]=c,t[48]=s,t[49]=o,t[50]=L):L=t[50];let R;t[51]!==I||t[52]!==L?(R=(0,$.jsxs)(`div`,{ref:m,className:`group flex min-w-0 items-center`,children:[I,L]}),t[51]=I,t[52]=L,t[53]=R):R=t[53];let ee;return t[54]!==O||t[55]!==R?(ee=(0,$.jsxs)($.Fragment,{children:[O,R]}),t[54]=O,t[55]=R,t[56]=ee):ee=t[56],ee}var ho=e(ht(),1),go=.1,_o=10,vo=1.25,yo=.001;function bo(){let e=(0,X.c)(15),[t,n]=(0,Y.useState)(1),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={x:0,y:0},e[0]=r):r=e[0];let[i,a]=(0,Y.useState)(r),[o,s]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),l=xo,u;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>n(e=>l(e*vo)),e[1]=u):u=e[1];let d=u,f;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>n(e=>l(e/vo)),e[2]=f):f=e[2];let p=f,m;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{n(1),a({x:0,y:0})},e[3]=m):m=e[3];let h=m,g;e[4]===i?g=e[5]:(g=e=>{e.preventDefault(),s(!0),c.current={x:e.clientX,y:e.clientY,ox:i.x,oy:i.y}},e[4]=i,e[5]=g);let _=g,v;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=e=>{c.current&&a({x:c.current.ox+(e.clientX-c.current.x),y:c.current.oy+(e.clientY-c.current.y)})},e[6]=v):v=e[6];let y=v,b;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{s(!1),c.current=null},e[7]=b):b=e[7];let x=b,S=(0,Y.useRef)(null),C,w;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{let e=S.current;if(!e)return;let t=function(e){e.preventDefault();let t=-e.deltaY*yo;n(e=>l(e*(1+t)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},w=[],e[8]=C,e[9]=w):(C=e[8],w=e[9]),(0,Y.useEffect)(C,w);let T;return e[10]!==o||e[11]!==i||e[12]!==_||e[13]!==t?(T={scale:t,offset:i,isDragging:o,containerRef:S,zoomIn:d,zoomOut:p,reset:h,onMouseDown:_,onMouseMove:y,onMouseUp:x},e[10]=o,e[11]=i,e[12]=_,e[13]=t,e[14]=T):T=e[14],T}function xo(e){return Math.min(Math.max(e,go),_o)}var So=ei(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[(0,$.jsx)(`span`,{className:e.v0,children:e.v1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.v2,e.v3]})]}),{name:`JSX_header_1`,portals:[`v1`,`v2`,`v3`]}),Co=ei(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`pre`,{className:`overflow-x-auto p-4 max-w-full`,children:(0,$.jsx)(`code`,{className:e.v2,children:e.v3})})]}),{name:`MermaidRenderer_1`,portals:[`v1`,`v3`]}),wo=ei(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`div`,{className:e.v2,children:`Rendering diagram…`})]}),{name:`MermaidRenderer_2`,portals:[`v1`]}),To=ei(e=>e.v0,{name:`MermaidRenderer_3`,portals:[`v0`]}),Eo=function(e){let t=(0,X.c)(47),{content:n,className:i}=e,[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),{svgOutput:l,renderError:u}=Oo(n,Do()),d;t[0]===n?d=t[1]:(d=async function(){await navigator.clipboard.writeText(n),o(!0),setTimeout(()=>o(!1),2e3)},t[0]=n,t[1]=d);let f=d,p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(p=V(r.compact,`font-mono text-muted-foreground`),t[2]=p):p=t[2];let m=u?`mermaid (render error)`:`mermaid diagram`,h;t[3]!==u||t[4]!==l?(h=l&&!u&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`action`,size:`icon-xs`,onClick:()=>c(!0),children:[(0,$.jsx)(Ct,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View fullscreen`})]})}),(0,$.jsx)(T,{children:`View fullscreen`})]}),t[3]=u,t[4]=l,t[5]=h):h=t[5];let g;t[6]===a?g=t[7]:(g=a?(0,$.jsx)(bt,{}):(0,$.jsx)(Ae,{}),t[6]=a,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy mermaid code`}),t[8]=_):_=t[8];let v;t[9]!==f||t[10]!==g?(v=(0,$.jsxs)(Rt,{variant:`action`,size:`icon-xs`,onClick:f,children:[g,_]}),t[9]=f,t[10]=g,t[11]=v):v=t[11];let y;t[12]!==m||t[13]!==h||t[14]!==v?(y=(0,$.jsx)(So,{v0:p,v1:m,v2:h,v3:v}),t[12]=m,t[13]=h,t[14]=v,t[15]=y):y=t[15];let b=y;if(u){let e;t[16]===i?e=t[17]:(e=V(`group relative overflow-hidden rounded-lg border border-border bg-muted`,i),t[16]=i,t[17]=e);let a;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(a=V(r.compact,`font-mono text-foreground leading-relaxed`),t[18]=a):a=t[18];let o;return t[19]!==n||t[20]!==b||t[21]!==e?(o=(0,$.jsx)(Co,{v0:e,v1:b,v2:a,v3:n}),t[19]=n,t[20]=b,t[21]=e,t[22]=o):o=t[22],o}if(!l){let e;t[23]===i?e=t[24]:(e=V(`group relative overflow-hidden rounded-lg border border-border bg-muted`,i),t[23]=i,t[24]=e);let n;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(n=V(r.compact,`p-4 text-muted-foreground`),t[25]=n):n=t[25];let a;return t[26]!==b||t[27]!==e?(a=(0,$.jsx)(wo,{v0:e,v1:b,v2:n}),t[26]=b,t[27]=e,t[28]=a):a=t[28],a}let x;t[29]===i?x=t[30]:(x=V(`group relative overflow-hidden rounded-lg border border-border bg-muted`,i),t[29]=i,t[30]=x);let S;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>c(!0),t[31]=S):S=t[31];let C;t[32]===l?C=t[33]:(C=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`block w-full text-left cursor-zoom-in p-4 max-w-full overflow-hidden [&_svg]:max-w-full [&_svg]:h-auto hover:bg-muted/70 transition-colors`,onClick:S,dangerouslySetInnerHTML:{__html:l}})}),t[32]=l,t[33]=C);let w;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(T,{children:`Click to view fullscreen`}),t[34]=w):w=t[34];let E;t[35]===C?E=t[36]:(E=(0,$.jsxs)(U,{children:[C,w]}),t[35]=C,t[36]=E);let D;t[37]!==b||t[38]!==E||t[39]!==x?(D=(0,$.jsxs)(`div`,{className:x,children:[b,E]}),t[37]=b,t[38]=E,t[39]=x,t[40]=D):D=t[40];let O;t[41]!==s||t[42]!==l?(O=s&&(0,$.jsx)(ko,{svgOutput:l,onClose:()=>c(!1)}),t[41]=s,t[42]=l,t[43]=O):O=t[43];let k;return t[44]!==D||t[45]!==O?(k=(0,$.jsx)(To,{v0:(0,$.jsxs)(P,{children:[D,O]})}),t[44]=D,t[45]=O,t[46]=k):k=t[46],k};function Do(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(!1),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=function(){n(document.documentElement.classList.contains(`dark`))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Y.useEffect)(r,i),t}function Oo(e,t){let[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let n=!1;async function i(){try{let{renderMermaidSVG:i}=await Xr(async()=>{let{renderMermaidSVG:e}=await import(`./dist-oojFghRi.js`);return{renderMermaidSVG:e}},__vite__mapDeps([0,1])),o=i(e,{bg:t?`#18181B`:`#FFFFFF`,fg:t?`#FAFAFA`:`#27272A`,transparent:!1,padding:32});n||(r(o),a(!1))}catch(e){console.error(`Mermaid render error:`,e),n||a(!0)}}return i(),()=>{n=!0}},[e,t]),{svgOutput:n,renderError:i}}function ko(e){let t=(0,X.c)(70),{svgOutput:n,onClose:i}=e,{scale:a,offset:o,isDragging:s,containerRef:c,zoomIn:l,zoomOut:u,reset:d,onMouseDown:f,onMouseMove:p,onMouseUp:m}=bo(),h,g;t[0]===i?(h=t[1],g=t[2]):(h=()=>{let e=function(e){e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},g=[i],t[0]=i,t[1]=h,t[2]=g),(0,Y.useEffect)(h,g);let _;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(_=[],t[3]=_):_=t[3],(0,Y.useEffect)(Ao,_);let v;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:V(r.compact,`font-mono text-muted-foreground`),children:`mermaid diagram`}),t[4]=v):v=t[4];let y,b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(bn,{className:`h-3.5 w-3.5`}),b=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom out`}),t[5]=y,t[6]=b):(y=t[5],b=t[6]);let x;t[7]===u?x=t[8]:(x=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-xs`,onClick:u,children:[y,b]})}),t[7]=u,t[8]=x);let S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(T,{children:`Zoom out`}),t[9]=S):S=t[9];let C;t[10]===x?C=t[11]:(C=(0,$.jsxs)(U,{children:[x,S]}),t[10]=x,t[11]=C);let w;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(w=V(r.compact,`min-w-[3rem] px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`),t[12]=w):w=t[12];let E;t[13]===a?E=t[14]:(E=Math.round(a*100),t[13]=a,t[14]=E);let D;t[15]!==d||t[16]!==E?(D=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:d,className:w,children:[E,`%`]})}),t[15]=d,t[16]=E,t[17]=D):D=t[17];let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(T,{children:`Reset zoom`}),t[18]=O):O=t[18];let k;t[19]===D?k=t[20]:(k=(0,$.jsxs)(U,{children:[D,O]}),t[19]=D,t[20]=k);let A,j;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(Le,{className:`h-3.5 w-3.5`}),j=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom in`}),t[21]=A,t[22]=j):(A=t[21],j=t[22]);let M;t[23]===l?M=t[24]:(M=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-xs`,onClick:l,children:[A,j]})}),t[23]=l,t[24]=M);let N;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(T,{children:`Zoom in`}),t[25]=N):N=t[25];let F;t[26]===M?F=t[27]:(F=(0,$.jsxs)(U,{children:[M,N]}),t[26]=M,t[27]=F);let I,L;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(ee,{className:`h-3.5 w-3.5`}),L=(0,$.jsx)(`span`,{className:`sr-only`,children:`Reset view`}),t[28]=I,t[29]=L):(I=t[28],L=t[29]);let R;t[30]===d?R=t[31]:(R=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-xs`,onClick:d,children:[I,L]})}),t[30]=d,t[31]=R);let z;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(T,{children:`Reset view`}),t[32]=z):z=t[32];let te;t[33]===R?te=t[34]:(te=(0,$.jsxs)(U,{children:[R,z]}),t[33]=R,t[34]=te);let ne;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),t[35]=ne):ne=t[35];let re,ie;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,$.jsx)(Ce,{className:`h-3.5 w-3.5`}),ie=(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`}),t[36]=re,t[37]=ie):(re=t[36],ie=t[37]);let ae;t[38]===i?ae=t[39]:(ae=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-xs`,onClick:i,children:[re,ie]})}),t[38]=i,t[39]=ae);let oe;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(oe=(0,$.jsx)(T,{children:`Close (Esc)`}),t[40]=oe):oe=t[40];let se;t[41]===ae?se=t[42]:(se=(0,$.jsxs)(U,{children:[ae,oe]}),t[41]=ae,t[42]=se);let ce;t[43]!==k||t[44]!==F||t[45]!==te||t[46]!==se||t[47]!==C?(ce=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-background/90 border-b border-border shrink-0`,children:[v,(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[C,k,F,te,ne,se]})]}),t[43]=k,t[44]=F,t[45]=te,t[46]=se,t[47]=C,t[48]=ce):ce=t[48];let le=s?`cursor-grabbing`:`cursor-grab`,ue;t[49]===le?ue=t[50]:(ue=V(`flex-1 overflow-hidden select-none`,le),t[49]=le,t[50]=ue);let de=`translate(${o.x}px, ${o.y}px) scale(${a})`,fe=s?`none`:`transform 0.1s ease-out`,H;t[51]!==de||t[52]!==fe?(H={transform:de,transformOrigin:`center center`,transition:fe},t[51]=de,t[52]=fe,t[53]=H):H=t[53];let pe;t[54]===n?pe=t[55]:(pe={__html:n},t[54]=n,t[55]=pe);let me;t[56]!==H||t[57]!==pe?(me=(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,style:H,dangerouslySetInnerHTML:pe}),t[56]=H,t[57]=pe,t[58]=me):me=t[58];let he;t[59]!==c||t[60]!==f||t[61]!==p||t[62]!==m||t[63]!==ue||t[64]!==me?(he=(0,$.jsx)(`div`,{ref:c,className:ue,onMouseDown:f,onMouseMove:p,onMouseUp:m,onMouseLeave:m,children:me}),t[59]=c,t[60]=f,t[61]=p,t[62]=m,t[63]=ue,t[64]=me,t[65]=he):he=t[65];let ge;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,$.jsx)(`div`,{className:V(r.compact,`shrink-0 px-4 py-2 text-center text-muted-foreground/60 bg-background/60 border-t border-border`),children:`Scroll to zoom · Drag to pan · Esc to close`}),t[66]=ge):ge=t[66];let _e;return t[67]!==ce||t[68]!==he?(_e=(0,ho.createPortal)((0,$.jsx)(P,{children:(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-black/85 backdrop-blur-sm`,role:`dialog`,"aria-modal":`true`,"aria-label":`Diagram fullscreen view`,children:[ce,he,ge]})}),document.body),t[67]=ce,t[68]=he,t[69]=_e):_e=t[69],_e}function Ao(){return document.body.style.overflow=`hidden`,jo}function jo(){document.body.style.overflow=``}function Mo(e){let t=e.trim();if(t.startsWith(`/`)){let e=We().replace(/\/$/,``);return $t(`${e}${t}`,e)}return $t(t,We())}function No(e){let t=e.trim();if(t.startsWith(`/api/`))return!0;if(!/^https?:\/\//i.test(t))return!1;try{let e=new URL(t);if(Sn(e.hostname))return!0;let n=new URL(We());return e.origin===n.origin&&e.pathname.startsWith(`/api/`)}catch{return!1}}function Po(e){let t=e.trim();return!t||t.startsWith(`mailto:`)||t.startsWith(`tel:`)?!1:yt()?/^https?:\/\//i.test(t)||t.startsWith(`/api/`):No(t)}function Fo(e){let t=Mo(e);return on()&&!yt()?(window.open(t,`_blank`,`noopener,noreferrer`),Promise.resolve()):et(t)}function Io(e){return!!(Sn(e.hostname)||typeof window<`u`&&e.origin===window.location.origin)}function Lo(e){return decodeURIComponent(e.replace(/^\/+/,``))}function Ro(e){let t=e.trim();if(!t||t.includes(`
6
+ `))return null;let n=Pe(t);if(!n)return null;let r=t.toLowerCase();return r.startsWith(`http://`)||r.startsWith(`https://`)||r.startsWith(`/`)||r.includes(`/explorer/media`)||t.includes(`/`)||t.includes(`\\`)?{kind:n,src:t}:null}function zo(e,t){let n=e.trim();if(!n||n.startsWith(`data:`)||n.includes(`/explorer/media`))return null;let r;if(/^https?:\/\//i.test(n)){let e;try{e=new URL(n)}catch{return null}if(!Io(e))return null;r=Lo(e.pathname)}else r=Lo(n);let i=Pe(r);return!i||t&&i!==t?null:{path:r,kind:i}}function Bo(e,t){return Mo(`/api/threads/${encodeURIComponent(e)}/explorer/media?path=${encodeURIComponent(t)}`)}function Vo(e){if(!e.startsWith(`/`))return!1;let t=e.split(`/`)[1]??``;return[`Users`,`tmp`,`var`,`private`,`Volumes`,`home`].includes(t)}function Ho(e,t){if(!e||e.startsWith(`data:`))return e;if(t){if(Vo(e)&&Pe(e))return Bo(t,e);let n=zo(e);if(n)return Bo(t,n.path)}return e.startsWith(`/`)?Mo(e):$t(e,We())}function Uo(e,t){return Ho(e,t)}var Wo=ei(e=>(0,$.jsxs)(`div`,{className:`mb-3 relative group/img inline-block max-w-full`,children:[(0,$.jsx)(`img`,{src:e.v0,alt:e.v1,className:`max-w-full rounded-lg block`,style:e.v2}),(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:e.v3})]}),{name:`GeneratedImageResult_1`,portals:[`v3`]}),Go=function(e){let t=(0,X.c)(32),{imageUrl:n,imageData:r,alt:i,threadId:a}=e,o=i===void 0?`Generated image`:i,[s,c]=(0,Y.useState)(!1),l;t[0]!==r||t[1]!==n||t[2]!==a?(l=r?`data:image/png;base64,${r}`:Uo(n??``,a),t[0]=r,t[1]=n,t[2]=a,t[3]=l):l=t[3];let u=l,d;t[4]===u?d=t[5]:(d=async()=>{let e=gt(u)??`generated-image-${Date.now()}.png`,{path:t}=await Xe(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:u,filename:e});Qa({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[4]=u,t[5]=d);let f=d,p;t[6]===u?p=t[7]:(p=async()=>{await rt(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:u}),c(!0),setTimeout(()=>c(!1),2e3)},t[6]=u,t[7]=p);let m=p;if(!u)return null;let h;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h={maxHeight:`512px`},t[8]=h):h=t[8];let g;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(Gn,{className:`h-3.5 w-3.5`}),t[9]=g):g=t[9];let _;t[10]===f?_=t[11]:(_=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:f,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:g})}),t[10]=f,t[11]=_);let v;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(T,{children:`Save image`}),t[12]=v):v=t[12];let y;t[13]===_?y=t[14]:(y=(0,$.jsxs)(U,{children:[_,v]}),t[13]=_,t[14]=y);let b;t[15]===s?b=t[16]:(b=s?(0,$.jsx)(bt,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(Ae,{className:`h-3.5 w-3.5`}),t[15]=s,t[16]=b);let x;t[17]!==m||t[18]!==b?(x=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:m,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:b})}),t[17]=m,t[18]=b,t[19]=x):x=t[19];let S=s?`Copied!`:`Copy to clipboard`,C;t[20]===S?C=t[21]:(C=(0,$.jsx)(T,{children:S}),t[20]=S,t[21]=C);let w;t[22]!==x||t[23]!==C?(w=(0,$.jsxs)(U,{children:[x,C]}),t[22]=x,t[23]=C,t[24]=w):w=t[24];let E;t[25]!==w||t[26]!==y?(E=(0,$.jsxs)(P,{children:[y,w]}),t[25]=w,t[26]=y,t[27]=E):E=t[27];let D;return t[28]!==o||t[29]!==u||t[30]!==E?(D=(0,$.jsx)(Wo,{v0:u,v1:o,v2:h,v3:E}),t[28]=o,t[29]=u,t[30]=E,t[31]=D):D=t[31],D};function Ko(e){let t=mn(e);if(!t?.imageUrl&&!t?.imageData)return null;let n;if(typeof e==`object`&&e){let t=e;if(typeof t.model==`string`)n=t.model;else if(typeof t.content==`string`)try{let e=JSON.parse(t.content);typeof e.model==`string`&&(n=e.model)}catch{}}else if(typeof e==`string`)try{let t=JSON.parse(e.trim());typeof t.model==`string`&&(n=t.model)}catch{}return{imageUrl:t.imageUrl,imageData:t.imageData,model:n}}function qo(e,t){let n=Ko(e)??Ko(t);if(!n?.imageUrl&&!n?.imageData)return null;let r,i=[e,t.content,t];for(let e of i)if(typeof e==`string`&&e.trim().startsWith(`{`))try{let t=JSON.parse(e);if(typeof t.savedPath==`string`){r=t.savedPath;break}}catch{}else if(e&&typeof e==`object`){let t=e;if(typeof t.savedPath==`string`){r=t.savedPath;break}if(typeof t.content==`string`)try{let e=JSON.parse(t.content);if(typeof e.savedPath==`string`){r=e.savedPath;break}}catch{}}return{...n,savedPath:r}}var Jo=Un(`chat.media`);function Yo(e){if(!e)return`Unknown media error`;switch(e.code){case MediaError.MEDIA_ERR_ABORTED:return`Playback aborted`;case MediaError.MEDIA_ERR_NETWORK:return`Network error while fetching media`;case MediaError.MEDIA_ERR_DECODE:return`Media decode error`;case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:return`Unsupported media format or inaccessible source`;default:return`Media error (code ${e.code})`}}async function Xo(e){try{let t=await fetch(e,{method:`GET`,headers:{Range:`bytes=0-0`}}),n=t.headers.get(`content-type`)??`unknown`,r=t.headers.get(`accept-ranges`)??`none`,i=t.headers.get(`content-range`),a=i?`, content-range=${i}`:``;return`HTTP ${t.status} ${t.statusText}, content-type=${n}, accept-ranges=${r}${a}`}catch(e){return e instanceof Error?e.message:`Fetch failed`}}function Zo(e){Jo.error(`Failed to load media`,{kind:e.kind,src:e.src,label:e.label,mediaError:e.mediaError?{code:e.mediaError.code,message:e.mediaError.message,label:Yo(e.mediaError)}:void 0,probeResult:e.probeResult})}function Qo(e,t,n,r){let[i,a]=(0,Y.useState)({objectUrl:null,loadError:null,loading:!1});return(0,Y.useEffect)(()=>{if(!t){a(e=>(e.objectUrl&&URL.revokeObjectURL(e.objectUrl),{objectUrl:null,loadError:null,loading:!1}));return}let i=!1;a(e=>(e.objectUrl&&URL.revokeObjectURL(e.objectUrl),{objectUrl:null,loadError:null,loading:!0}));async function o(){try{let t=await fetch(e);if(!t.ok){let t=await Xo(e);throw Error(t)}let n=await t.blob();if(i)return;let r=URL.createObjectURL(n);if(i){URL.revokeObjectURL(r);return}a({objectUrl:r,loadError:null,loading:!1})}catch(t){if(i)return;let o=t instanceof Error?t.message:await Xo(e);Zo({kind:n,src:e,label:r,probeResult:o}),a({objectUrl:null,loadError:o,loading:!1})}}return o(),()=>{i=!0,a(e=>(e.objectUrl&&URL.revokeObjectURL(e.objectUrl),{objectUrl:null,loadError:null,loading:!1}))}},[e,t,n,r]),i}function $o(e){let t=(0,X.c)(44),{src:n,label:i}=e,[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l=(0,Y.useRef)(null),{objectUrl:u,loadError:d,loading:f}=Qo(n,a,`video`,i),p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=function(e){o(e),e||(c(!1),l.current&&l.current.pause())},t[0]=p):p=t[0];let m=p,h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=function(){c(es)},t[1]=h):h=t[1];let g=h,_;t[2]!==i||t[3]!==n?(_=async function(e){let t=e.currentTarget.error;Zo({kind:`video`,src:n,label:i,mediaError:t,probeResult:await Xo(n)})},t[2]=i,t[3]=n,t[4]=_):_=t[4];let v=_,y=i??`Video`,b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>o(!0),t[5]=b):b=t[5];let x=i?`Play ${i}`:`Play video`,S;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(`span`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-background/90 text-foreground shadow-sm`,children:(0,$.jsx)(Ke,{className:`h-7 w-7 fill-current`})}),t[6]=S):S=t[6];let C;t[7]===x?C=t[8]:(C=(0,$.jsx)(`button`,{type:`button`,onClick:b,"aria-label":x,className:`flex min-h-32 w-full items-center justify-center rounded-md bg-muted/30 transition-colors hover:bg-muted/50`,children:S}),t[7]=x,t[8]=C);let w=s?`h-dvh w-dvw max-w-none rounded-none`:`max-w-[min(92vw,960px)]`,T;t[9]===w?T=t[10]:(T=V(`gap-0 overflow-hidden border-none bg-black p-0 sm:rounded-lg`,w),t[9]=w,t[10]=T);let E;t[11]===y?E=t[12]:(E=(0,$.jsx)(Cn,{className:`sr-only`,children:y}),t[11]=y,t[12]=E);let D;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(be,{className:`sr-only`,children:`Video player`}),t[13]=D):D=t[13];let O=s?`Shrink video`:`Expand video`,k;t[14]===s?k=t[15]:(k=s?(0,$.jsx)(lt,{className:`h-4 w-4`}):(0,$.jsx)(Ct,{className:`h-4 w-4`}),t[14]=s,t[15]=k);let A;t[16]!==O||t[17]!==k?(A=(0,$.jsx)(`button`,{type:`button`,onClick:g,"aria-label":O,className:`flex h-7 w-7 items-center justify-center rounded-full text-white/90 transition-colors hover:bg-white/15 hover:text-white`,children:k}),t[16]=O,t[17]=k,t[18]=A):A=t[18];let j;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsxs)(Be,{className:`flex h-7 w-7 items-center justify-center rounded-full text-white/90 transition-colors hover:bg-white/15 hover:text-white`,children:[(0,$.jsx)(Ce,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[19]=j):j=t[19];let M;t[20]===A?M=t[21]:(M=(0,$.jsxs)(`div`,{className:`absolute right-4 top-4 z-10 flex items-center gap-1`,children:[A,j]}),t[20]=A,t[21]=M);let N=s?`h-full`:`min-h-[240px]`,P;t[22]===N?P=t[23]:(P=V(`flex items-center justify-center p-3 pt-12 sm:p-4`,N),t[22]=N,t[23]=P);let F;t[24]!==s||t[25]!==v||t[26]!==d||t[27]!==f||t[28]!==u?(F=f?(0,$.jsx)(`p`,{className:V(r.compact,`text-white/80`),children:`Loading video...`}):d?(0,$.jsxs)(`p`,{className:V(r.compact,`px-4 text-center text-destructive`),children:[`Could not load video: `,d]}):u?(0,$.jsx)(`video`,{ref:l,src:u,controls:!0,autoPlay:!0,playsInline:!0,className:V(`max-w-full rounded`,s?`max-h-full`:`max-h-[80vh]`),onError:v}):null,t[24]=s,t[25]=v,t[26]=d,t[27]=f,t[28]=u,t[29]=F):F=t[29];let I;t[30]!==P||t[31]!==F?(I=(0,$.jsx)(`div`,{className:P,children:F}),t[30]=P,t[31]=F,t[32]=I):I=t[32];let L;t[33]!==E||t[34]!==M||t[35]!==I||t[36]!==T?(L=(0,$.jsxs)(Ye,{hideClose:!0,className:T,children:[E,D,M,I]}),t[33]=E,t[34]=M,t[35]=I,t[36]=T,t[37]=L):L=t[37];let R;t[38]!==a||t[39]!==L?(R=(0,$.jsx)(Ge,{open:a,onOpenChange:m,children:L}),t[38]=a,t[39]=L,t[40]=R):R=t[40];let ee;return t[41]!==R||t[42]!==C?(ee=(0,$.jsxs)($.Fragment,{children:[C,R]}),t[41]=R,t[42]=C,t[43]=ee):ee=t[43],ee}function es(e){return!e}function ts(e){let t=(0,X.c)(12),{src:n,label:i}=e,{objectUrl:a,loadError:o,loading:s}=Qo(n,!0,`audio`,i),c;t[0]!==i||t[1]!==n?(c=async function(e){let t=e.currentTarget.error;Zo({kind:`audio`,src:n,label:i,mediaError:t,probeResult:await Xo(n)})},t[0]=i,t[1]=n,t[2]=c):c=t[2];let l=c,u;t[3]!==l||t[4]!==s||t[5]!==a?(u=s?(0,$.jsx)(`p`,{className:V(r.compact,`text-muted-foreground`),children:`Loading audio...`}):a?(0,$.jsx)(`audio`,{src:a,controls:!0,preload:`metadata`,className:`w-full`,onError:l}):null,t[3]=l,t[4]=s,t[5]=a,t[6]=u):u=t[6];let d;t[7]===o?d=t[8]:(d=o?(0,$.jsxs)(`p`,{className:V(r.compact,`mt-2 text-destructive`),children:[`Could not load audio: `,o]}):null,t[7]=o,t[8]=d);let f;return t[9]!==u||t[10]!==d?(f=(0,$.jsxs)($.Fragment,{children:[u,d]}),t[9]=u,t[10]=d,t[11]=f):f=t[11],f}function ns(e){let t=(0,X.c)(13),{src:n,kind:i,label:a}=e;if(!n)return null;let o=i===`video`?ue:ge,s=i===`video`?`p-2`:`p-3`,c;t[0]===s?c=t[1]:(c=V(`mt-2 max-w-full overflow-hidden rounded-lg border border-border bg-background`,s),t[0]=s,t[1]=c);let l;t[2]!==o||t[3]!==a?(l=a?(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(o,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:V(r.compact,`truncate`),children:a})]}):null,t[2]=o,t[3]=a,t[4]=l):l=t[4];let u;t[5]!==i||t[6]!==a||t[7]!==n?(u=i===`video`?(0,$.jsx)($o,{src:n,label:a}):(0,$.jsx)(ts,{src:n,label:a}),t[5]=i,t[6]=a,t[7]=n,t[8]=u):u=t[8];let d;return t[9]!==c||t[10]!==l||t[11]!==u?(d=(0,$.jsxs)(`div`,{className:c,children:[l,u]}),t[9]=c,t[10]=l,t[11]=u,t[12]=d):d=t[12],d}var rs=`graph.flowchart.sequenceDiagram.classDiagram.stateDiagram.erDiagram.journey.gantt.pie.quadrantChart.requirementDiagram.gitgraph.mindmap.timeline.zenuml.sankey.block.architecture.c4.packet.circuit.flowchart LR.flowchart TD.flowchart BT.flowchart RL.graph LR.graph TD.graph BT.graph RL`.split(`.`),is=[/-->/,/--\./,/-\./,/==>/,/--\|/,/\w+\[\w+\]/,/\w+\(\w+\)/,/\w+\{\w+\}/,/\w+>\w+\]/,/\w+\(\w+\)/,/\w+\[\(\w+\)\]/,/participant\s+\w+/,/actor\s+\w+/,/Note over \w+/,/loop\s+/,/alt\s+/,/opt\s+/,/class\s+\w+/,/interface\s+\w+/,/enum\s+\w+/,/\[\*\]/,/\[\*\]/,/title\s+/,/direction\s+/,/subgraph\s+/];function as(e){if(!e||typeof e!=`string`)return!1;let t=e.split(`
7
+ `).map(e=>e.trim()).filter(e=>e.length>0);if(t.length===0)return!1;if(/```mermaid\s*\n([\s\S]*?)\n```/.test(e))return!0;let n=t[0].toLowerCase();if(rs.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `)))return!0;let r=0;for(let t of is)t.test(e)&&r++;return r>=2}function os(e){if(!as(e))return null;let t=/```mermaid\s*\n([\s\S]*?)\n```/.exec(e);if(t)return t[1].trim();let n=e.split(`
8
+ `).map(e=>e.trim()).filter(e=>e.length>0)[0].toLowerCase();return rs.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `))?e.trim():null}function ss(e){let t=(0,X.c)(14),{href:n,children:r}=e,i;t[0]===n?i=t[1]:(i=Mo(n),t[0]=n,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=Po(n),t[2]=n,t[3]=o);let s=o,c;t[4]!==n||t[5]!==s?(c=function(e){s&&(e.preventDefault(),Fo(n))},t[4]=n,t[5]=s,t[6]=c):c=t[6];let l=c,u;t[7]===s?u=t[8]:(u=s?{}:{target:`_blank`,rel:`noopener noreferrer`},t[7]=s,t[8]=u);let d;return t[9]!==r||t[10]!==l||t[11]!==a||t[12]!==u?(d=(0,$.jsx)(`a`,{href:a,onClick:l,className:`text-primary underline underline-offset-2 hover:text-primary/80`,...u,children:r}),t[9]=r,t[10]=l,t[11]=a,t[12]=u,t[13]=d):d=t[13],d}var cs=ei(e=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden rounded-lg border border-border bg-muted`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[(0,$.jsx)(`span`,{className:e.v0,children:e.v1}),e.v2]}),(0,$.jsx)(`pre`,{className:e.v3,children:(0,$.jsx)(`code`,{className:e.v4,children:e.v5})})]}),{name:`CodeBlock_1`,portals:[`v1`,`v2`,`v5`]}),ls=function(e){let t=(0,X.c)(19),{language:n,code:i,compact:a}=e,o=a===void 0?!1:a,[s,c]=(0,Y.useState)(!1),l;t[0]===i?l=t[1]:(l=async()=>{await navigator.clipboard.writeText(i),c(!0),setTimeout(()=>c(!1),2e3)},t[0]=i,t[1]=l);let u=l,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=V(r.compact,`text-muted-foreground font-mono`),t[2]=d):d=t[2];let f=n||`text`,p;t[3]===s?p=t[4]:(p=s?(0,$.jsx)(bt,{}):(0,$.jsx)(Ae,{}),t[3]=s,t[4]=p);let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[5]=m):m=t[5];let h;t[6]!==u||t[7]!==p?(h=(0,$.jsxs)(Rt,{variant:`action`,size:`icon-xs`,onClick:u,children:[p,m]}),t[6]=u,t[7]=p,t[8]=h):h=t[8];let g=o?`p-2`:`p-4`,_;t[9]===g?_=t[10]:(_=V(`overflow-x-auto max-w-full`,g),t[9]=g,t[10]=_);let v;t[11]===o?v=t[12]:(v=V(o?V(r.compact,`font-mono`):r.mono,`text-foreground leading-relaxed`),t[11]=o,t[12]=v);let y;return t[13]!==i||t[14]!==v||t[15]!==f||t[16]!==h||t[17]!==_?(y=(0,$.jsx)(cs,{v0:d,v1:f,v2:h,v3:_,v4:v,v5:i}),t[13]=i,t[14]=v,t[15]=f,t[16]=h,t[17]=_,t[18]=y):y=t[18],y},us=(0,Y.memo)(function({content:e,className:t,enableMermaid:n=!1,threadId:r,compact:i=!1}){let a=(0,Y.useMemo)(()=>!e||typeof e!=`string`?[]:hs(e,n),[e,n]),o=(0,Y.useMemo)(()=>{let e=0;return a.map(t=>{if(t.type===`list`&&t.ordered){let n=e+1;return e+=t.items.length,n}else if(t.type===`list`&&!t.ordered)return 1;else return e=0,1})},[a]);return a.length===0?null:(0,$.jsx)(`div`,{className:V(`prose-custom min-w-0 break-words`,t),children:a.map((e,t)=>(0,$.jsx)(`div`,{className:ms(t,a,i),children:(0,$.jsx)(Os,{block:e,start:o[t],threadId:r,compact:i})},t))})}),ds=/^!\[([^\]]*)\]\(([^)]+)\)\s*$/;function fs(e){let t=e.match(ds);return t?{alt:t[1],src:t[2]}:null}function ps(e,t){let n=e?`mt-0 space-y-0.5`:`mt-0 space-y-1`;return t?V(n,`pl-6`):V(n,`ml-[3.8rem]`,`list-outside overflow-visible list-disc`)}function ms(e,t,n=!1){if(e===0)return``;let r=t[e-1],i=t[e];return r.type===`list`||i.type===`list`?``:n?`mt-2`:`mt-3`}function hs(e,t=!1){let n=e.split(`
9
+ `),r=[],i=0;for(;i<n.length;){let e=n[i];if(e.trimStart().startsWith("```")){let a=e.trimStart().slice(3).trim(),o=[];for(i++;i<n.length&&!n[i].trimStart().startsWith("```");)o.push(n[i]),i++;t&&(a===`mermaid`||as(o.join(`
10
+ `)))?r.push({type:`mermaid`,code:o.join(`
11
+ `)}):r.push({type:`code`,language:a,code:o.join(`
12
+ `)}),i++;continue}let a=e.match(/^(#{1,6})(\s.*)?$/);if(a){r.push({type:`heading`,level:a[1].length,text:a[2]?a[2].trim():``}),i++;continue}if(/^(---|\*\*\*|___)/.test(e.trim())){r.push({type:`hr`}),i++;continue}if(e.includes(`|`)&&i+1<n.length&&n[i+1].match(/^\|?\s*[-:]+/)){let t=e.split(`|`).map(e=>e.trim()).filter(Boolean);i+=2;let a=[];for(;i<n.length&&n[i].includes(`|`);)a.push(n[i].split(`|`).map(e=>e.trim()).filter(Boolean)),i++;r.push({type:`table`,headers:t,rows:a});continue}if(e.startsWith(`> `)){let e=[];for(;i<n.length&&n[i].startsWith(`> `);)e.push(n[i].slice(2)),i++;r.push({type:`blockquote`,text:e.join(`
13
+ `)});continue}if(/^\s*[-*+]\s/.test(e)){let e=[];for(;i<n.length&&/^\s*[-*+]\s/.test(n[i]);)e.push(n[i].replace(/^\s*[-*+]\s/,``)),i++;r.push({type:`list`,ordered:!1,items:e});continue}if(/^\s*\d+\.\s/.test(e)){let e=[];for(;i<n.length&&/^\s*\d+\.\s/.test(n[i]);)e.push(n[i].replace(/^\s*\d+\.\s/,``)),i++;r.push({type:`list`,ordered:!0,items:e});continue}if(e.trim()===``){i++;continue}let o=fs(e);if(o){r.push({type:`image`,...o}),i++;continue}let s=Ro(e);if(s){r.push({type:`media`,kind:s.kind,src:s.src}),i++;continue}let c=[];for(;i<n.length&&n[i].trim()!==``&&!n[i].startsWith(`#`)&&!n[i].startsWith("```")&&!n[i].startsWith(`> `)&&!/^\s*[-*+]\s/.test(n[i])&&!/^\s*\d+\.\s/.test(n[i]);)c.push(n[i]),i++;if(c.length>0){let e=c.join(`
14
+ `);if(t&&as(e)){let t=os(e);t?r.push({type:`mermaid`,code:t}):r.push({type:`paragraph`,text:e})}else r.push({type:`paragraph`,text:e})}}return r}var gs=ei(e=>e.v0,{name:`MarkdownBlock_2`,portals:[`v0`]}),_s=ei(e=>e.v0,{name:`MarkdownBlock_3`,portals:[`v0`]}),vs=ei(e=>(0,$.jsx)(`blockquote`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_4`,portals:[`v1`]}),ys=ei(e=>(0,$.jsx)(`ol`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_5`,portals:[`v1`]}),bs=ei(e=>(0,$.jsx)(`ul`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_6`,portals:[`v1`]}),xs=ei(e=>(0,$.jsx)(`p`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_7`,portals:[`v1`]}),Ss=ei(()=>(0,$.jsx)(`hr`,{className:`border-border`}),{name:`MarkdownBlock_8`}),Cs=ei(e=>(0,$.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border max-w-full`,children:(0,$.jsxs)(`table`,{className:e.v0,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{className:`border-b border-border bg-muted/50`,children:e.v1})}),(0,$.jsx)(`tbody`,{children:e.v2})]})}),{name:`MarkdownBlock_9`,portals:[`v1`,`v2`]}),ws=ei(e=>e.v0,{name:`MarkdownBlock_10`,portals:[`v0`]}),Ts=ei(e=>e.v0,{name:`MarkdownBlock_11`,portals:[`v0`]}),Es=ei(e=>e.v0,{name:`MarkdownBlock_12`,portals:[`v0`]}),Ds=ei(e=>e.v0,{name:`MarkdownBlock_13`,portals:[`v0`]}),Os=(0,Y.memo)(function(e){let t=(0,X.c)(111),{block:n,start:i,threadId:a,compact:o}=e,s=i===void 0?1:i,c=o===void 0?!1:o,l=c?r.caption:r.body,u;t[0]===c?u=t[1]:(u=c?V(r.compact,`font-mono`):r.mono,t[0]=c,t[1]=u);let d=u;switch(n.type){case`heading`:{let e=`h${n.level}`,i,o,s;if(t[2]!==e||t[3]!==n.level||t[4]!==c){let a=c?{1:V(r.caption,`font-semibold`),2:V(r.caption,`font-semibold`),3:V(r.body,`font-semibold`),4:V(r.body,`font-semibold`),5:V(r.compact,`font-semibold`),6:V(r.compact,`font-semibold`)}:{1:r.sectionTitle,2:r.subSectionTitle,3:r.subSectionTitle,4:r.subSectionTitle,5:r.sectionSubtitle,6:r.sectionSubtitle};o=gs,i=e,s=V(a[n.level]),t[2]=e,t[3]=n.level,t[4]=c,t[5]=i,t[6]=o,t[7]=s}else i=t[5],o=t[6],s=t[7];let l;t[8]!==n.text||t[9]!==d||t[10]!==a?(l=(0,$.jsx)(ks,{text:n.text,threadId:a,inlineCodeClass:d}),t[8]=n.text,t[9]=d,t[10]=a,t[11]=l):l=t[11];let u;t[12]!==i||t[13]!==s||t[14]!==l?(u=(0,$.jsx)(i,{className:s,children:l}),t[12]=i,t[13]=s,t[14]=l,t[15]=u):u=t[15];let f;return t[16]!==o||t[17]!==u?(f=(0,$.jsx)(o,{v0:u}),t[16]=o,t[17]=u,t[18]=f):f=t[18],f}case`code`:{let e;return t[19]!==n.code||t[20]!==n.language||t[21]!==c?(e=(0,$.jsx)(_s,{v0:(0,$.jsx)(ls,{language:n.language,code:n.code,compact:c})}),t[19]=n.code,t[20]=n.language,t[21]=c,t[22]=e):e=t[22],e}case`blockquote`:{let e;t[23]===l?e=t[24]:(e=V(l,`border-l-2 border-border pl-4 text-muted-foreground italic`),t[23]=l,t[24]=e);let r;t[25]!==n.text||t[26]!==d||t[27]!==a?(r=(0,$.jsx)(ks,{text:n.text,threadId:a,inlineCodeClass:d}),t[25]=n.text,t[26]=d,t[27]=a,t[28]=r):r=t[28];let i;return t[29]!==e||t[30]!==r?(i=(0,$.jsx)(vs,{v0:e,v1:r}),t[29]=e,t[30]=r,t[31]=i):i=t[31],i}case`list`:{let e,r,i;if(t[32]!==n.items||t[33]!==n.ordered||t[34]!==l||t[35]!==c||t[36]!==d||t[37]!==s||t[38]!==a){i=Symbol.for(`react.early_return_sentinel`);bb0:{let o=ps(c,n.ordered);if(n.ordered){let e=V(l,o),r;if(t[42]!==n.items||t[43]!==d||t[44]!==s||t[45]!==a){let e;t[47]!==d||t[48]!==s||t[49]!==a?(e=(e,t)=>(0,$.jsxs)(`li`,{className:`flex gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`shrink-0 select-none tabular-nums`,children:[s+t,`.`]}),(0,$.jsx)(`span`,{children:(0,$.jsx)(ks,{text:e,threadId:a,inlineCodeClass:d})})]},t),t[47]=d,t[48]=s,t[49]=a,t[50]=e):e=t[50],r=n.items.map(e),t[42]=n.items,t[43]=d,t[44]=s,t[45]=a,t[46]=r}else r=t[46];i=(0,$.jsx)(ys,{v0:e,v1:r});break bb0}e=bs,r=V(l,o)}t[32]=n.items,t[33]=n.ordered,t[34]=l,t[35]=c,t[36]=d,t[37]=s,t[38]=a,t[39]=e,t[40]=r,t[41]=i}else e=t[39],r=t[40],i=t[41];if(i!==Symbol.for(`react.early_return_sentinel`))return i;let o;if(t[51]!==n.items||t[52]!==d||t[53]!==a){let e;t[55]!==d||t[56]!==a?(e=(e,t)=>(0,$.jsx)(`li`,{children:(0,$.jsx)(ks,{text:e,threadId:a,inlineCodeClass:d})},t),t[55]=d,t[56]=a,t[57]=e):e=t[57],o=n.items.map(e),t[51]=n.items,t[52]=d,t[53]=a,t[54]=o}else o=t[54];let u;return t[58]!==e||t[59]!==r||t[60]!==o?(u=(0,$.jsx)(e,{v0:r,v1:o}),t[58]=e,t[59]=r,t[60]=o,t[61]=u):u=t[61],u}case`paragraph`:{let e;t[62]===l?e=t[63]:(e=V(l,`mt-0 leading-relaxed whitespace-pre-wrap break-words`),t[62]=l,t[63]=e);let r;t[64]!==n.text||t[65]!==d||t[66]!==a?(r=(0,$.jsx)(ks,{text:n.text,threadId:a,inlineCodeClass:d}),t[64]=n.text,t[65]=d,t[66]=a,t[67]=r):r=t[67];let i;return t[68]!==e||t[69]!==r?(i=(0,$.jsx)(xs,{v0:e,v1:r}),t[68]=e,t[69]=r,t[70]=i):i=t[70],i}case`hr`:{let e;return t[71]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ss,{}),t[71]=e):e=t[71],e}case`table`:{let e;t[72]===l?e=t[73]:(e=V(l,`w-full`),t[72]=l,t[73]=e);let r;if(t[74]!==n.headers||t[75]!==d||t[76]!==a){let e;t[78]!==d||t[79]!==a?(e=(e,t)=>(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:(0,$.jsx)(ks,{text:e,threadId:a,inlineCodeClass:d})},t),t[78]=d,t[79]=a,t[80]=e):e=t[80],r=n.headers.map(e),t[74]=n.headers,t[75]=d,t[76]=a,t[77]=r}else r=t[77];let i;if(t[81]!==n.rows||t[82]!==d||t[83]!==a){let e;t[85]!==d||t[86]!==a?(e=(e,t)=>(0,$.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map((e,t)=>(0,$.jsx)(`td`,{className:`px-3 py-2`,children:(0,$.jsx)(ks,{text:e,threadId:a,inlineCodeClass:d})},t))},t),t[85]=d,t[86]=a,t[87]=e):e=t[87],i=n.rows.map(e),t[81]=n.rows,t[82]=d,t[83]=a,t[84]=i}else i=t[84];let o;return t[88]!==e||t[89]!==r||t[90]!==i?(o=(0,$.jsx)(Cs,{v0:e,v1:r,v2:i}),t[88]=e,t[89]=r,t[90]=i,t[91]=o):o=t[91],o}case`mermaid`:{let e;return t[92]===n.code?e=t[93]:(e=(0,$.jsx)(ws,{v0:(0,$.jsx)(Eo,{content:n.code})}),t[92]=n.code,t[93]=e),e}case`image`:{let e;t[94]!==n.src||t[95]!==a?(e=Uo(n.src,a),t[94]=n.src,t[95]=a,t[96]=e):e=t[96];let r=n.alt||`Image`,i;return t[97]!==e||t[98]!==r?(i=(0,$.jsx)(Ts,{v0:(0,$.jsx)(Go,{imageUrl:e,alt:r})}),t[97]=e,t[98]=r,t[99]=i):i=t[99],i}case`media`:{let e;t[100]!==n.src||t[101]!==a?(e=Ho(n.src,a),t[100]=n.src,t[101]=a,t[102]=e):e=t[102];let r=e;if(n.kind===`image`){let e;return t[103]===r?e=t[104]:(e=(0,$.jsx)(Es,{v0:(0,$.jsx)(Go,{imageUrl:r,alt:`Image`})}),t[103]=r,t[104]=e),e}let i;t[105]===n.src?i=t[106]:(i=n.src.split(/[/\\]/).pop(),t[105]=n.src,t[106]=i);let o=i,s;return t[107]!==n.kind||t[108]!==o||t[109]!==r?(s=(0,$.jsx)(Ds,{v0:(0,$.jsx)(ns,{src:r,kind:n.kind,label:o})}),t[107]=n.kind,t[108]=o,t[109]=r,t[110]=s):s=t[110],s}default:return null}}),ks=(0,Y.memo)(function(e){let t=(0,X.c)(11),{text:n,threadId:i,inlineCodeClass:a}=e,o=a===void 0?r.mono:a,s;t[0]===n?s=t[1]:(s=As(n),t[0]=n,t[1]=s);let c=s,l;if(t[2]!==o||t[3]!==c||t[4]!==i){let e;t[6]!==o||t[7]!==i?(e=(e,t)=>{switch(e.type){case`bold`:return(0,$.jsx)(`strong`,{className:`font-semibold`,children:e.text},t);case`italic`:return(0,$.jsx)(`em`,{children:e.text},t);case`strikethrough`:return(0,$.jsx)(`del`,{className:`text-muted-foreground`,children:e.text},t);case`code`:return(0,$.jsx)(`code`,{className:V(o,`rounded bg-muted/20 py-0.5`),children:e.text},t);case`link`:return(0,$.jsx)(ss,{href:e.href,children:e.text},t);case`image`:return(0,$.jsx)(Go,{imageUrl:Uo(e.src,i),alt:e.alt||`Image`},t);default:return(0,$.jsx)(`span`,{children:e.text},t)}},t[6]=o,t[7]=i,t[8]=e):e=t[8],l=c.map(e),t[2]=o,t[3]=c,t[4]=i,t[5]=l}else l=t[5];let u;return t[9]===l?u=t[10]:(u=(0,$.jsx)($.Fragment,{children:l}),t[9]=l,t[10]=u),u});function As(e){let t=[],n=/(`[^`]+`)|(!\[[^\]]*\]\([^)]+\))|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(__[^_]+__)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)]+\))/g,r=0,i;for(;(i=n.exec(e))!==null;){i.index>r&&t.push({type:`text`,text:e.slice(r,i.index)});let n=i[0];if(n.startsWith("`"))t.push({type:`code`,text:n.slice(1,-1)});else if(n.startsWith(`![`)){let e=n.match(/!\[([^\]]*)\]\(([^)]+)\)/);e&&t.push({type:`image`,alt:e[1],src:e[2]})}else if(n.startsWith(`**`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`__`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`~~`))t.push({type:`strikethrough`,text:n.slice(2,-2)});else if(n.startsWith(`*`)||n.startsWith(`_`))t.push({type:`italic`,text:n.slice(1,-1)});else if(n.startsWith(`[`)){let e=n.match(/\[([^\]]+)\]\(([^)]+)\)/);e&&t.push({type:`link`,text:e[1],href:e[2]})}r=i.index+n.length}return r<e.length&&t.push({type:`text`,text:e.slice(r)}),t.length>0?t:[{type:`text`,text:e}]}function js(e){return e.split(/[/\\]/).pop()||void 0}var Ms=(0,Y.memo)(function(e){let t=(0,X.c)(20),{content:n,threadId:i,className:a,enableMermaid:o}=e,s=o===void 0?!0:o,c;t[0]===n?c=t[1]:(c=Ro(n),t[0]=n,t[1]=c);let l=c;if(l){let e;t[2]!==l.src||t[3]!==i?(e=Ho(l.src,i),t[2]=l.src,t[3]=i,t[4]=e):e=t[4];let n=e;if(l.kind===`image`){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Go,{imageUrl:n,alt:`Image`}),t[5]=n,t[6]=e),e}let r=l.kind,a;t[7]===l.src?a=t[8]:(a=js(l.src),t[7]=l.src,t[8]=a);let o;return t[9]!==l.kind||t[10]!==n||t[11]!==a?(o=(0,$.jsx)(ns,{src:n,kind:r,label:a}),t[9]=l.kind,t[10]=n,t[11]=a,t[12]=o):o=t[12],o}let u;t[13]===n?u=t[14]:(u=ra(n),t[13]=n,t[14]=u);let d=a??r.body,f;return t[15]!==s||t[16]!==u||t[17]!==d||t[18]!==i?(f=(0,$.jsx)(us,{content:u,enableMermaid:s,className:d,threadId:i}),t[15]=s,t[16]=u,t[17]=d,t[18]=i,t[19]=f):f=t[19],f});function Ns(e){return`data:${e.mimeType};base64,${e.content}`}function Ps(e){return e.mimeType.startsWith(`image/`)?`image`:e.mimeType.startsWith(`video/`)?`video`:e.mimeType.startsWith(`audio/`)?`audio`:Pe(e.fileName)||`file`}function Fs(e){let t=(0,X.c)(6),{icon:n,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=V(r.compact,`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-muted-foreground`),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{className:`truncate`,children:i}),t[1]=i,t[2]=o);let s;return t[3]!==n||t[4]!==o?(s=(0,$.jsxs)(`div`,{className:a,children:[n,o]}),t[3]=n,t[4]=o,t[5]=s):s=t[5],s}function Is(e){let t=(0,X.c)(14),{attachment:n}=e,r=Ps(n),i;t[0]===n?i=t[1]:(i=Ns(n),t[0]=n,t[1]=i);let a=i;if(r===`image`){let e;return t[2]!==n.fileName||t[3]!==a?(e=(0,$.jsx)(`div`,{className:`mt-1 max-w-full overflow-hidden rounded-lg border border-border bg-background`,children:(0,$.jsx)(`img`,{src:a,alt:n.fileName,className:`block max-h-80 max-w-full object-contain`})}),t[2]=n.fileName,t[3]=a,t[4]=e):e=t[4],e}if(r===`video`){let e;return t[5]!==n.fileName||t[6]!==a?(e=(0,$.jsx)(ns,{src:a,kind:`video`,label:n.fileName}),t[5]=n.fileName,t[6]=a,t[7]=e):e=t[7],e}if(r===`audio`){let e;return t[8]!==n.fileName||t[9]!==a?(e=(0,$.jsx)(ns,{src:a,kind:`audio`,label:n.fileName}),t[8]=n.fileName,t[9]=a,t[10]=e):e=t[10],e}let o;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(tn,{className:`h-2.5 w-2.5`}),t[11]=o):o=t[11];let s;return t[12]===n.fileName?s=t[13]:(s=(0,$.jsx)(Fs,{icon:o,label:n.fileName}),t[12]=n.fileName,t[13]=s),s}function Ls(e){let t=(0,X.c)(4),{attachments:n}=e,r;t[0]===n?r=t[1]:(r=n.map(Rs),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)(`div`,{className:`mt-1 space-y-2`,children:r}),t[2]=r,t[3]=i),i}function Rs(e){let t=Ps(e),n=`${e.fileName}:${e.mimeType}`;return t===`file`?(0,$.jsx)(Is,{attachment:e},n):(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(Fs,{icon:t===`audio`?(0,$.jsx)(ge,{className:`h-2.5 w-2.5`}):t===`video`?(0,$.jsx)(ue,{className:`h-2.5 w-2.5`}):(0,$.jsx)(tn,{className:`h-2.5 w-2.5`}),label:e.fileName}),(0,$.jsx)(Is,{attachment:e})]},n)}function zs(e){let[t,n]=(0,Y.useState)(!1);async function r(r){if(!(!e||t)){n(!0);try{let t=await Xt(e,r);t.success?Qa({title:`Checkpoint restored`,description:`Working tree restored to before this agent run.`}):Qa({title:`Restore failed`,description:t.error??`Could not restore checkpoint.`,variant:`destructive`})}catch(e){Qa({title:`Restore failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{n(!1)}}}return{isRestoring:t,restore:r}}function Bs(e){let t=(0,X.c)(7),n=e===void 0?2e3:e,[r,i]=(0,Y.useState)(!1),a,o;t[0]!==r||t[1]!==n?(a=()=>{if(!r)return;let e=setTimeout(()=>i(!1),n);return()=>clearTimeout(e)},o=[r,n],t[0]=r,t[1]=n,t[2]=a,t[3]=o):(a=t[2],o=t[3]),(0,Y.useEffect)(a,o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=function(){i(!0)},t[4]=s):s=t[4];let c=s,l;return t[5]===r?l=t[6]:(l={copied:r,markCopied:c},t[5]=r,t[6]=l),l}function Vs(e){return e.length<=32?e:`${e.slice(0,32)}...`}function Hs(e){let t=(0,X.c)(60),{message:n,threadId:i,showCheckpointRestore:a,checkpointRestoreTooltip:o}=e,c=a===void 0?!1:a,[l,u]=(0,Y.useState)(!1),d=n.sender===`user`,{isRestoring:f,restore:p}=zs(i),{copied:m,markCopied:h}=Bs(),g=d&&(c||!!o),_;t[0]===n.timestamp?_=t[1]:(_=n.timestamp?new Date(n.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,t[0]=n.timestamp,t[1]=_);let v=_,y;t[2]===n.content?y=t[3]:(y=Vs(n.content),t[2]=n.content,t[3]=y);let b=y,x;t[4]!==f||t[5]!==n.checkpointRef||t[6]!==c?(x=function(){!n.checkpointRef||!c||f||u(!0)},t[4]=f,t[5]=n.checkpointRef,t[6]=c,t[7]=x):x=t[7];let S=x,C;t[8]!==n.checkpointRef||t[9]!==p||t[10]!==c?(C=async function(){!n.checkpointRef||!c||(await p(n.checkpointRef),u(!1))},t[8]=n.checkpointRef,t[9]=p,t[10]=c,t[11]=C):C=t[11];let w=C,E;t[12]!==h||t[13]!==n.content?(E=async function(){try{await navigator.clipboard.writeText(n.content),h()}catch(e){let t=e;Qa({title:`Copy failed`,description:t instanceof Error?t.message:`Could not copy prompt.`,variant:`destructive`})}},t[12]=h,t[13]=n.content,t[14]=E):E=t[14];let D=E,O=d&&`flex-row-reverse`,k;t[15]===O?k=t[16]:(k=V(`flex items-center gap-2`,O),t[15]=O,t[16]=k);let A;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(A=V(r.compact,`font-medium text-foreground`),t[17]=A):A=t[17];let M=d?`You`:`Agent`,N;t[18]===M?N=t[19]:(N=(0,$.jsx)(`span`,{className:A,children:M}),t[18]=M,t[19]=N);let F;t[20]!==o||t[21]!==D||t[22]!==S||t[23]!==m||t[24]!==f||t[25]!==d||t[26]!==g||t[27]!==c?(F=d&&(0,$.jsx)(P,{children:(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:D,"aria-label":m?`Prompt copied`:`Copy prompt`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted`,children:m?(0,$.jsx)(bt,{className:`h-3 w-3 text-green-500`}):(0,$.jsx)(Ae,{className:`h-3 w-3`})})})}),(0,$.jsx)(T,{side:`left`,children:m?`Copied prompt`:`Copy prompt`})]}),g&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:c?S:void 0,disabled:!c||f,"aria-label":o??`Restore checkpoint`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted disabled:opacity-50 disabled:hover:text-muted-foreground disabled:hover:bg-transparent`,children:(0,$.jsx)(ee,{className:V(`h-3 w-3`,f&&`animate-spin`)})})})}),(0,$.jsx)(T,{side:`left`,children:o??`Restore checkpoint`})]})]})}),t[20]=o,t[21]=D,t[22]=S,t[23]=m,t[24]=f,t[25]=d,t[26]=g,t[27]=c,t[28]=F):F=t[28];let I;t[29]===v?I=t[30]:(I=v&&(0,$.jsxs)(`span`,{className:V(r.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Fe,{className:`h-2.5 w-2.5`}),v]}),t[29]=v,t[30]=I);let L;t[31]===n.model?L=t[32]:(L=n.model&&(0,$.jsxs)(`span`,{className:V(r.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(j,{className:`h-2.5 w-2.5`}),hi(n.model)]}),t[31]=n.model,t[32]=L);let R;t[33]===n.metadata?R=t[34]:(R=n.metadata?.processingTimeMs&&(0,$.jsxs)(`span`,{className:V(r.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(s,{className:`h-2.5 w-2.5`}),n.metadata.processingTimeMs>=6e4?`${Math.floor(n.metadata.processingTimeMs/6e4)}m ${Math.round(n.metadata.processingTimeMs%6e4/1e3)}s`:`${Math.round(n.metadata.processingTimeMs/1e3)}s`]}),t[33]=n.metadata,t[34]=R);let z;t[35]===n.metadata?z=t[36]:(z=(n.metadata?.tokenCount||n.metadata?.estimatedCost)&&(0,$.jsxs)(`span`,{className:V(r.compact,`text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[n.metadata.tokenCount?`${n.metadata.tokenCount.toLocaleString()} tokens`:null,n.metadata.tokenCount&&n.metadata.estimatedCost?` · `:null,n.metadata.estimatedCost?G(n.metadata.estimatedCost):null]}),t[35]=n.metadata,t[36]=z);let te;t[37]!==N||t[38]!==F||t[39]!==I||t[40]!==L||t[41]!==R||t[42]!==z||t[43]!==k?(te=(0,$.jsxs)(`div`,{className:k,children:[N,F,I,L,R,z]}),t[37]=N,t[38]=F,t[39]=I,t[40]=L,t[41]=R,t[42]=z,t[43]=k,t[44]=te):te=t[44];let ne;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)($r,{children:`Restore Checkpoint`}),t[45]=ne):ne=t[45];let re;t[46]===b?re=t[47]:(re=(0,$.jsxs)(ii,{children:[ne,(0,$.jsxs)(ti,{children:[`Restore to the checkpoint before “`,b,`” was started?`]})]}),t[46]=b,t[47]=re);let ie;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,$.jsx)(Zr,{children:`Cancel`}),t[48]=ie):ie=t[48];let ae;t[49]===w?ae=t[50]:(ae=(0,$.jsxs)(ni,{children:[ie,(0,$.jsx)(si,{onClick:w,children:`Restore checkpoint`})]}),t[49]=w,t[50]=ae);let oe;t[51]!==re||t[52]!==ae?(oe=(0,$.jsxs)(oi,{children:[re,ae]}),t[51]=re,t[52]=ae,t[53]=oe):oe=t[53];let se;t[54]!==l||t[55]!==oe?(se=(0,$.jsx)(ri,{open:l,onOpenChange:u,children:oe}),t[54]=l,t[55]=oe,t[56]=se):se=t[56];let ce;return t[57]!==te||t[58]!==se?(ce=(0,$.jsxs)($.Fragment,{children:[te,se]}),t[57]=te,t[58]=se,t[59]=ce):ce=t[59],ce}function Us(e){let t=(0,X.c)(32),{src:n,threadId:r}=e,{copied:i,markCopied:a}=Bs(),o;t[0]!==n||t[1]!==r?(o=n.startsWith(`data:`)?n:Uo(n,r),t[0]=n,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===s?c=t[4]:(c=async function(){let e=`generated-image-${Date.now()}.png`,{path:t}=await Xe(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:s,filename:e});Qa({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[3]=s,t[4]=c);let l=c,u;t[5]!==s||t[6]!==a?(u=async function(){await rt(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:s}),a()},t[5]=s,t[6]=a,t[7]=u):u=t[7];let d=u,f;t[8]===s?f=t[9]:(f=(0,$.jsx)(`img`,{src:s,alt:`Generated image`,className:`max-w-full rounded-lg border border-border block max-h-[512px]`}),t[8]=s,t[9]=f);let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Gn,{className:`h-3.5 w-3.5`}),t[10]=p):p=t[10];let m;t[11]===l?m=t[12]:(m=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:l,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:p})}),t[11]=l,t[12]=m);let h;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(T,{children:`Save image`}),t[13]=h):h=t[13];let g;t[14]===m?g=t[15]:(g=(0,$.jsxs)(U,{children:[m,h]}),t[14]=m,t[15]=g);let _;t[16]===i?_=t[17]:(_=i?(0,$.jsx)(bt,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(Ae,{className:`h-3.5 w-3.5`}),t[16]=i,t[17]=_);let v;t[18]!==d||t[19]!==_?(v=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:d,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:_})}),t[18]=d,t[19]=_,t[20]=v):v=t[20];let y=i?`Copied!`:`Copy to clipboard`,b;t[21]===y?b=t[22]:(b=(0,$.jsx)(T,{children:y}),t[21]=y,t[22]=b);let x;t[23]!==v||t[24]!==b?(x=(0,$.jsxs)(U,{children:[v,b]}),t[23]=v,t[24]=b,t[25]=x):x=t[25];let S;t[26]!==x||t[27]!==g?(S=(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:(0,$.jsxs)(P,{children:[g,x]})}),t[26]=x,t[27]=g,t[28]=S):S=t[28];let C;return t[29]!==S||t[30]!==f?(C=(0,$.jsxs)(`div`,{className:`mt-2 relative group/img inline-block max-w-full`,children:[f,S]}),t[29]=S,t[30]=f,t[31]=C):C=t[31],C}var Ws=(0,Y.createContext)(null);function Gs(e){let t=(0,X.c)(10),{children:n}=e,[r,i]=(0,Y.useState)(`chat`),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(0),[l,u]=(0,Y.useState)(0),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>{c(qs)},t[0]=d):d=t[0];let f=d,p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{u(Ks)},t[1]=p):p=t[1];let m=p,h;t[2]!==r||t[3]!==s||t[4]!==l||t[5]!==a?(h={activeMainTab:r,setActiveMainTab:i,terminalNotification:a,setTerminalNotification:o,reviewRefreshTick:s,triggerReviewRefresh:f,tasksRefreshTick:l,triggerTasksRefresh:m},t[2]=r,t[3]=s,t[4]=l,t[5]=a,t[6]=h):h=t[6];let g=h,_;return t[7]!==n||t[8]!==g?(_=(0,$.jsx)(Ws.Provider,{value:g,children:n}),t[7]=n,t[8]=g,t[9]=_):_=t[9],_}function Ks(e){return e+1}function qs(e){return e+1}function Js(){let e=(0,Y.useContext)(Ws);if(!e)throw Error(`useMainTab must be used within a MainTabProvider`);return e}var Ys=(0,Y.createContext)(null);function Xs(e){let t=(0,X.c)(8),{children:n}=e,[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(0),[s,c]=(0,Y.useState)(null),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{o(Zs)},t[0]=l):l=t[0];let u=l,d;t[1]!==s||t[2]!==a||t[3]!==r?(d={pendingExplorerPath:r,setPendingExplorerPath:i,explorerRefreshTick:a,triggerExplorerRefresh:u,explorerClearPath:s,setExplorerClearPath:c},t[1]=s,t[2]=a,t[3]=r,t[4]=d):d=t[4];let f=d,p;return t[5]!==n||t[6]!==f?(p=(0,$.jsx)(Ys.Provider,{value:f,children:n}),t[5]=n,t[6]=f,t[7]=p):p=t[7],p}function Zs(e){return e+1}function Qs(){let e=(0,Y.useContext)(Ys);if(!e)throw Error(`useExplorerTab must be used within an ExplorerTabProvider`);return e}var $s=new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`,`g`),ec=new RegExp(String.raw`\x1B\].*?(?:\x07|\x1B\\)`,`g`),tc=new RegExp(String.raw`\x1B[@-_]`,`g`),nc=/\r(?!\n)/g,rc=/\\n/g;function ic(e){return e.replace(ec,``).replace($s,``).replace(tc,``)}function ac(e){return ic(e).replace(rc,`
15
+ `).replace(nc,`
16
+ `)}function oc(e){return Re(e)}function sc(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t)}...`}function cc(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:sc(t,50)}}function lc(e,t){if(!t||!e||typeof e!=`string`)return e;try{let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(new RegExp(n,`g`),`.`)}catch{return e}}function uc(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}var dc=32;function fc(e,t){if(e===void 0)return null;let n;return n=typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):e===null?`null`:JSON.stringify(e),n.length>t?`${n.slice(0,t)}...`:n}function pc(e,t=dc,n=[]){if(!e)return null;let r=new Set(n),i=[];for(let[n,a]of Object.entries(e)){if(r.has(n))continue;let e=fc(a,t);e&&i.push(`${n}: ${e}`)}return i.length>0?i.join(`, `):null}function mc(e){if(!e)return`browser`;let t=typeof e.action==`string`?e.action:`browser`;if(typeof e.url==`string`&&e.url.trim())return`${t} · ${e.url.trim()}`;if(typeof e.ref==`string`&&e.ref.trim())return`${t} · ${e.ref.trim()}`;if(typeof e.text==`string`&&e.text.trim())return`${t} · ${e.text.trim()}`;if(typeof e.selector==`string`&&e.selector.trim())return`${t} · ${e.selector.trim()}`;if(typeof e.preset==`string`&&e.preset.trim())return`${t} · ${e.preset.trim()}`;if(typeof e.script==`string`&&e.script.trim()){let n=e.script.trim();return n.length>40?`${t} · ${n.slice(0,40)}…`:`${t} · ${n}`}return t}function hc(e){return typeof e!=`object`||!e||Array.isArray(e)?e:At(e)}function gc(e){try{return bc(hc(JSON.parse(e)))}catch{return bc(e)}}function _c(e){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function vc(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(vc);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=_c(r);t[n]=typeof e==`object`?vc(e):r}else t[n]=vc(r);return t}function yc(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
17
+ `),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
18
+ `),t=t.replace(/\\"/g,`"`),t}function bc(e){if(e==null)return``;let t=typeof e==`object`&&e?vc(e):e;return ac(yc(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2)))}function xc(e,t){let n=e.name??`Unknown Tool`,r=e.id??`unknown`,i=e.input,a=i&&typeof i==`object`?i:null,o=i&&typeof i==`object`&&`description`in i,s=o?i.subagent_type:void 0,c=s==null?null:JSON.stringify(s),l=n===`agent`&&a&&typeof a.agentName==`string`?a.agentName:null,u=o?null:lc(uc(i),t),d=lc(o?String(i.prompt):null,t),f=lc(a&&typeof a.command==`string`?a.command:null,t),p=n===`fetch`&&a&&typeof a.url==`string`?a.url:null,m=a&&typeof a.pattern==`string`?a.pattern:null,h=n===`web_search`&&a&&typeof a.query==`string`?a.query:null,g=a&&typeof a.lang==`string`?a.lang:null,_=n===`code_search`,v=_&&a&&typeof a.query==`string`?a.query:null,y=_&&a&&typeof a.filePath==`string`?a.filePath:null,b=_&&a&&typeof a.fileGlob==`string`?a.fileGlob:null,x=lc(a&&typeof a.path==`string`?a.path:null,t),S=a&&typeof a.offset==`number`?a.offset:null,C=a&&typeof a.limit==`number`?a.limit:null,w=n.toLowerCase(),T=w.includes(`read`)||w.includes(`write`)||w.includes(`edit`),E=w.includes(`edit`),D=T&&a&&typeof a.path==`string`?a.path:null,O=D?D.split(`/`).pop()??D:null,k=E&&a&&typeof a.oldText==`string`?a.oldText:null,A=E&&a&&typeof a.newText==`string`?a.newText:null,j=k===null?null:k.split(`
19
+ `).length,M=A===null?null:A.split(`
20
+ `).length,N=k!==null&&A!==null,P=n===`generate_image`&&a&&typeof a.prompt==`string`?a.prompt:null,F=n===`find_images`&&a&&typeof a.query==`string`?a.query:null,I=n===`todo`&&a?a.status:void 0,L=e.displayName??Re(n),R=e.activeDisplayName??Ue(n),ee=`default`;return w===`bash`||w.includes(`terminal`)||w.includes(`shell`)?ee=`bash`:w===`fetch`?ee=`fetch`:T?ee=`file`:_||w===`find`||w===`web_search`||w.includes(`search`)||w.includes(`grep`)?ee=`search`:w===`agent`||w.includes(`subagent`)||o?ee=`agent`:w===`todo`?ee=`todo`:w===`generate_image`?ee=`imageGen`:w===`find_images`?ee=`findImages`:w===`browser`&&(ee=`browser`),{toolType:ee,toolName:n,toolId:r,displayName:L,activeDisplayName:R,inputObj:a,toolInput:u,command:f,fetchUrl:p,pattern:m,webSearchQuery:h,codeSearchQuery:v,codeSearchFilePath:y,codeSearchFileGlob:b,isFileTool:T,isEditTool:E,filePath:D,fileDisplayName:O,editOldText:k,editNewText:A,editDeletedLineCount:j,editAddedLineCount:M,hasEditDiff:N,path:x,offset:S,limit:C,prompt:d,agentName:l,subagentType:c,lang:g,imageGenPrompt:P,findImagesQuery:F,todoStatus:I}}var Sc=new Map;function Cc(e){return e.trim()}function wc(){let e=W(ut.BASH_COMMAND_DURATIONS);if(!e)return{};try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`number`&&Number.isFinite(r)&&r>0&&(n[Cc(e)]=r);return n}catch{return{}}}function Tc(e){se(ut.BASH_COMMAND_DURATIONS,JSON.stringify(e))}function Ec(e){return wc()[Cc(e)]??null}function Dc(e,t){let n=Cc(e);if(!n||!Number.isFinite(t)||t<=0)return;let r=wc();r[n]=Math.round(t),Tc(r)}function Oc(e,t){!t?.trim()||Sc.has(e)||Sc.set(e,{command:Cc(t),startedAt:Date.now()})}function kc(e){let t=Sc.get(e);if(!t)return;let n=Date.now()-t.startedAt;Dc(t.command,n),Sc.delete(e)}function Ac(e){let t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function jc(e,t){return t!==null&&t>0?`${Math.min(99,Math.round(e/t*100))}% complete`:Ac(e)}var Mc=1e3;function Nc(e,t,n){let[r,i]=(0,Y.useState)(0),[a,o]=(0,Y.useState)(null),s=(0,Y.useRef)(null),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(n);return l.current=n,(0,Y.useEffect)(()=>{if(n&&!c.current){let n=e?.trim()??``;o(n?Ec(n):null),Oc(t,e),s.current=Date.now(),i(0)}else !n&&c.current&&(kc(t),s.current=null,i(0),o(null));c.current=n},[n,e,t]),(0,Y.useEffect)(()=>()=>{l.current&&kc(t)},[t]),(0,Y.useEffect)(()=>{if(!n)return;let e=()=>{s.current===null&&(s.current=Date.now()),i(Date.now()-s.current)};e();let t=setInterval(e,Mc);return()=>clearInterval(t)},[n]),n?jc(r,a):null}function Pc(e){let{maxHeight:t=`48`,padding:n=`2`,leading:i=!1,className:a}=e??{};return V(r.mono,n===`3`?`p-3`:`p-2`,`bg-muted rounded whitespace-pre-wrap overflow-auto text-foreground`,t===`64`?`max-h-64`:`max-h-48`,i&&`leading-relaxed`,a)}function Fc(e){let t=(0,X.c)(13),{open:n,onOpenChange:i,title:a,content:o,markdown:s,threadId:c}=e,l=s===void 0?!1:s,u;t[0]===a?u=t[1]:(u=(0,$.jsx)(_t,{children:(0,$.jsx)(Cn,{children:(0,$.jsx)(`code`,{className:r.mono,children:a})})}),t[0]=a,t[1]=u);let d;t[2]!==o||t[3]!==l||t[4]!==c?(d=l?(0,$.jsx)(`div`,{className:V(`flex-1 overflow-auto min-h-0`,r.body),children:(0,$.jsx)(us,{content:ra(o),threadId:c})}):(0,$.jsx)(`pre`,{className:Pc({padding:`3`,className:`flex-1 max-h-none`}),children:o}),t[2]=o,t[3]=l,t[4]=c,t[5]=d):d=t[5];let f;t[6]!==u||t[7]!==d?(f=(0,$.jsxs)(Ye,{className:`max-w-3xl h-[80vh] flex flex-col`,children:[u,d]}),t[6]=u,t[7]=d,t[8]=f):f=t[8];let p;return t[9]!==i||t[10]!==n||t[11]!==f?(p=(0,$.jsx)(Ge,{open:n,onOpenChange:i,children:f}),t[9]=i,t[10]=n,t[11]=f,t[12]=p):p=t[12],p}function Ic(e){let t=(0,X.c)(20),{open:n,onOpenChange:i,title:a,requestContent:o,responseContent:s}=e,c;t[0]===a?c=t[1]:(c=(0,$.jsx)(_t,{children:(0,$.jsx)(Cn,{children:(0,$.jsx)(`code`,{className:r.mono,children:a})})}),t[0]=a,t[1]=c);let l,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`div`,{className:V(r.compact,`mb-1 text-muted-foreground`),children:`Request`}),u=Pc({padding:`3`,className:`max-h-48`}),t[2]=l,t[3]=u):(l=t[2],u=t[3]);let d;t[4]===o?d=t[5]:(d=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[l,(0,$.jsx)(`pre`,{className:u,children:o})]}),t[4]=o,t[5]=d);let f,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(`div`,{className:V(r.compact,`mb-1 text-muted-foreground`),children:`Response`}),p=Pc({padding:`3`,className:`flex-1 max-h-none`}),t[6]=f,t[7]=p):(f=t[6],p=t[7]);let m;t[8]===s?m=t[9]:(m=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[f,(0,$.jsx)(`pre`,{className:p,children:s})]}),t[8]=s,t[9]=m);let h;t[10]!==d||t[11]!==m?(h=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[d,m]}),t[10]=d,t[11]=m,t[12]=h):h=t[12];let g;t[13]!==c||t[14]!==h?(g=(0,$.jsxs)(Ye,{className:`max-w-3xl h-[80vh] flex flex-col gap-4`,children:[c,h]}),t[13]=c,t[14]=h,t[15]=g):g=t[15];let _;return t[16]!==i||t[17]!==n||t[18]!==g?(_=(0,$.jsx)(Ge,{open:n,onOpenChange:i,children:g}),t[16]=i,t[17]=n,t[18]=g,t[19]=_):_=t[19],_}function Lc(e){let t=(0,X.c)(10),{oldText:n,newText:i}=e,a,o,s;if(t[0]!==i||t[1]!==n){let e=n.split(`
21
+ `),c=i.split(`
22
+ `);t[5]===Symbol.for(`react.memo_cache_sentinel`)?(a=V(r.caption,`font-mono whitespace-pre-wrap overflow-auto`),t[5]=a):a=t[5],o=e.map(zc),s=c.map(Rc),t[0]=i,t[1]=n,t[2]=a,t[3]=o,t[4]=s}else a=t[2],o=t[3],s=t[4];let c;return t[6]!==a||t[7]!==o||t[8]!==s?(c=(0,$.jsxs)(`pre`,{className:a,children:[o,s]}),t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function Rc(e,t){return(0,$.jsxs)(`div`,{className:`bg-green-500/10 text-green-600 dark:text-green-400`,children:[(0,$.jsx)(`span`,{className:`select-none opacity-50 mr-2`,children:`+`}),e]},`new-${t}`)}function zc(e,t){return(0,$.jsxs)(`div`,{className:`bg-red-500/10 text-red-600 dark:text-red-400`,children:[(0,$.jsx)(`span`,{className:`select-none opacity-50 mr-2`,children:`-`}),e]},`old-${t}`)}function Bc(e){let t=(0,X.c)(3),{name:n}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=V(r.caption,`px-1.5 py-0.5 rounded bg-muted font-mono`),t[0]=i):i=t[0];let a;return t[1]===n?a=t[2]:(a=(0,$.jsx)(`span`,{className:i,children:n}),t[1]=n,t[2]=a),a}function Vc(e){let t=(0,X.c)(3),{type:n}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=V(r.caption,`px-2 py-0.5 rounded bg-muted`),t[0]=i):i=t[0];let a;return t[1]===n?a=t[2]:(a=(0,$.jsx)(`span`,{className:i,children:n}),t[1]=n,t[2]=a),a}function Hc(e){let t=(0,X.c)(3),{children:n}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=V(r.caption,`font-mono truncate whitespace-nowrap min-w-0 max-w-full rounded bg-muted/60 px-1 py-0.5`),t[0]=i):i=t[0];let a;return t[1]===n?a=t[2]:(a=(0,$.jsx)(`code`,{className:i,children:n}),t[1]=n,t[2]=a),a}function Uc(e){let t=(0,X.c)(5),{className:n,size:r}=e,i=(r===void 0?`sm`:r)===`sm`?`h-7 w-7`:`h-8 w-8`,a;t[0]!==n||t[1]!==i?(a=V(`shrink-0`,i,n),t[0]=n,t[1]=i,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`img`,{src:`/busy.svg`,alt:``,className:a,"aria-hidden":!0}),t[3]=a,t[4]=o),o}function Wc(e){let t=(0,X.c)(15),{toolName:n,displayName:i,muted:a,size:o,className:s}=e,c=a===void 0?!0:a,l;t[0]===s?l=t[1]:(l=V(`inline-flex items-center gap-1`,s),t[0]=s,t[1]=l);let u=!c&&`text-foreground`,d;t[2]===u?d=t[3]:(d=V(r.caption,u),t[2]=u,t[3]=d);let f;t[4]!==i||t[5]!==d?(f=(0,$.jsx)(`span`,{className:d,children:i}),t[4]=i,t[5]=d,t[6]=f):f=t[6];let p;t[7]!==l||t[8]!==f?(p=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:l,children:f})}),t[7]=l,t[8]=f,t[9]=p):p=t[9];let m;t[10]===n?m=t[11]:(m=(0,$.jsx)(T,{children:n}),t[10]=n,t[11]=m);let h;return t[12]!==p||t[13]!==m?(h=(0,$.jsxs)(U,{children:[p,m]}),t[12]=p,t[13]=m,t[14]=h):h=t[14],h}function Gc(e){let t=(0,X.c)(106),{data:n,inline:a,resultContent:o,isActive:s}=e,c=(0,Y.useRef)(null),[l,u]=(0,Y.useState)(!!s),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(!!s),m;t[0]===n.toolId?m=t[1]:(m=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=m);let h=Q(m),g=s?h??o??``:o??``,_;t[2]===g?_=t[3]:(_=g?ac(g):``,t[2]=g,t[3]=_);let v=_,y=s?v:``,b=Nc(n.command,n.toolId,!!s),x;t[4]===n.command?x=t[5]:(x=n.command===null?null:cc(n.command),t[4]=n.command,t[5]=x);let S=x,C,w;t[6]===s?(C=t[7],w=t[8]):(C=()=>{s&&!p.current?u(!0):!s&&p.current&&u(!1),p.current=!!s},w=[s],t[6]=s,t[7]=C,t[8]=w),(0,Y.useEffect)(C,w);let E;t[9]!==s||t[10]!==l?(E=()=>{l&&s&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},t[9]=s,t[10]=l,t[11]=E):E=t[11];let D;if(t[12]!==s||t[13]!==l||t[14]!==y?(D=[l,s,y],t[12]=s,t[13]=l,t[14]=y,t[15]=D):D=t[15],(0,Y.useEffect)(E,D),a){if(s){let e;t[16]===l?e=t[17]:(e=()=>u(!l),t[16]=l,t[17]=e);let a;t[18]!==n.activeDisplayName||t[19]!==n.toolName?(a=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!1,className:`shrink-0`}),t[18]=n.activeDisplayName,t[19]=n.toolName,t[20]=a):a=t[20];let o;t[21]===S?o=t[22]:(o=S!==null&&(0,$.jsx)(`span`,{className:V(r.caption,`min-w-0 flex-1 truncate whitespace-nowrap`),children:S.label}),t[21]=S,t[22]=o);let s;t[23]===b?s=t[24]:(s=b&&(0,$.jsx)(`span`,{className:V(r.caption,`tabular-nums shrink-0`),children:b}),t[23]=b,t[24]=s);let d;t[25]===l?d=t[26]:(d=l?(0,$.jsx)(i,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Je,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[25]=l,t[26]=d);let f;t[27]!==l||t[28]!==o||t[29]!==s||t[30]!==d||t[31]!==e||t[32]!==a?(f=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full min-w-0`,onClick:e,"aria-expanded":l,children:[a,o,s,d]}),t[27]=l,t[28]=o,t[29]=s,t[30]=d,t[31]=e,t[32]=a,t[33]=f):f=t[33];let p=l?`grid-rows-[1fr]`:`grid-rows-[0fr]`,m;t[34]===p?m=t[35]:(m=V(`grid transition-[grid-template-rows] duration-200 ease-in-out`,p),t[34]=p,t[35]=m);let h,g;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(h=V(r.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),g={maxHeight:`7.5em`},t[36]=h,t[37]=g):(h=t[36],g=t[37]);let _;t[38]===y?_=t[39]:(_=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:c,className:h,style:g,children:y})}),t[38]=y,t[39]=_);let v;t[40]!==m||t[41]!==_?(v=(0,$.jsx)(`div`,{className:m,children:_}),t[40]=m,t[41]=_,t[42]=v):v=t[42];let x;return t[43]!==f||t[44]!==v?(x=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[f,v]}),t[43]=f,t[44]=v,t[45]=x):x=t[45],x}if(S!==null&&v){let e=S.label!==S.fullText,i;t[46]!==n.displayName||t[47]!==n.toolName?(i=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[46]=n.displayName,t[47]=n.toolName,t[48]=i):i=t[48];let a,o;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>f(!0),a=V(r.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 cursor-pointer`),t[49]=a,t[50]=o):(a=t[49],o=t[50]);let s;t[51]===S.label?s=t[52]:(s=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:o,className:a,children:S.label})}),t[51]=S.label,t[52]=s);let c=e?S.fullText:`View output`,l;t[53]===c?l=t[54]:(l=(0,$.jsx)(T,{className:`max-w-md break-all font-mono`,children:c}),t[53]=c,t[54]=l);let u;t[55]!==s||t[56]!==l?(u=(0,$.jsxs)(U,{children:[s,l]}),t[55]=s,t[56]=l,t[57]=u):u=t[57];let p;t[58]!==u||t[59]!==i?(p=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[i,u]}),t[58]=u,t[59]=i,t[60]=p):p=t[60];let m;t[61]!==S.fullText||t[62]!==d||t[63]!==v?(m=(0,$.jsx)(Fc,{open:d,onOpenChange:f,title:S.fullText,content:v}),t[61]=S.fullText,t[62]=d,t[63]=v,t[64]=m):m=t[64];let h;return t[65]!==p||t[66]!==m?(h=(0,$.jsxs)($.Fragment,{children:[p,m]}),t[65]=p,t[66]=m,t[67]=h):h=t[67],h}let e;t[68]!==n.displayName||t[69]!==n.toolName?(e=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[68]=n.displayName,t[69]=n.toolName,t[70]=e):e=t[70];let a;t[71]===S?a=t[72]:(a=S!==null&&(0,$.jsx)(`code`,{className:V(r.caption,`font-mono truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:S.label}),t[71]=S,t[72]=a);let o;return t[73]!==e||t[74]!==a?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,a]}),t[73]=e,t[74]=a,t[75]=o):o=t[75],o}let O;t[76]===l?O=t[77]:(O=()=>u(!l),t[76]=l,t[77]=O);let k;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(k=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[78]=k):k=t[78];let A;t[79]!==n.activeDisplayName||t[80]!==n.displayName||t[81]!==s||t[82]!==b?(A=s?(0,$.jsxs)($.Fragment,{children:[n.activeDisplayName,b&&(0,$.jsx)(`span`,{className:`ml-2 text-muted-foreground tabular-nums`,children:b})]}):n.displayName,t[79]=n.activeDisplayName,t[80]=n.displayName,t[81]=s,t[82]=b,t[83]=A):A=t[83];let j;t[84]===A?j=t[85]:(j=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:A}),t[84]=A,t[85]=j);let M;t[86]===l?M=t[87]:(M=l?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[86]=l,t[87]=M);let N;t[88]!==j||t[89]!==M||t[90]!==O?(N=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:O,className:k,children:[j,M]})}),t[88]=j,t[89]=M,t[90]=O,t[91]=N):N=t[91];let P;t[92]===n.toolName?P=t[93]:(P=(0,$.jsx)(T,{children:n.toolName}),t[92]=n.toolName,t[93]=P);let F;t[94]!==N||t[95]!==P?(F=(0,$.jsxs)(U,{children:[N,P]}),t[94]=N,t[95]=P,t[96]=F):F=t[96];let I;t[97]!==n.toolId||t[98]!==n.toolInput||t[99]!==s||t[100]!==l||t[101]!==y?(I=l&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),s?(0,$.jsx)(`div`,{ref:c,className:V(r.caption,`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),style:{maxHeight:`7.5em`},children:y}):n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null]}),t[97]=n.toolId,t[98]=n.toolInput,t[99]=s,t[100]=l,t[101]=y,t[102]=I):I=t[102];let L;return t[103]!==F||t[104]!==I?(L=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[F,I]}),t[103]=F,t[104]=I,t[105]=L):L=t[105],L}function Kc(e){let t=(0,X.c)(50),{data:n,inline:a,resultContent:o,isActive:s}=e,[c,l]=(0,Y.useState)(!!s),[u,d]=(0,Y.useState)(!1),f=n.fetchUrl,p;t[0]===o?p=t[1]:(p=o?qc(o):null,t[0]=o,t[1]=p);let m=p;if(a){let e;t[2]===c?e=t[3]:(e=()=>l(!c),t[2]=c,t[3]=e);let a=n.toolName,u=n.activeDisplayName,d=!!s,p;t[4]!==n.activeDisplayName||t[5]!==n.toolName||t[6]!==d?(p=(0,$.jsx)(Wc,{toolName:a,displayName:u,isActive:d}),t[4]=n.activeDisplayName,t[5]=n.toolName,t[6]=d,t[7]=p):p=t[7];let h;t[8]===f?h=t[9]:(h=f!==null&&(0,$.jsx)(`span`,{className:V(r.caption,`break-all`),children:f}),t[8]=f,t[9]=h);let g;t[10]===m?g=t[11]:(g=m&&(0,$.jsxs)(`span`,{className:V(r.caption,`text-muted-foreground shrink-0`),children:[m.bytes,` bytes · HTTP `,m.code]}),t[10]=m,t[11]=g);let _;t[12]===c?_=t[13]:(_=c?(0,$.jsx)(i,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Je,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[12]=c,t[13]=_);let v;t[14]!==c||t[15]!==e||t[16]!==p||t[17]!==h||t[18]!==g||t[19]!==_?(v=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":c,children:[p,h,g,_]}),t[14]=c,t[15]=e,t[16]=p,t[17]=h,t[18]=g,t[19]=_,t[20]=v):v=t[20];let y;t[21]!==c||t[22]!==o?(y=c&&o&&(0,$.jsx)(`pre`,{className:V(r.mono,r.caption,`whitespace-pre-wrap break-all rounded bg-muted/40 p-2 max-h-48 overflow-auto`),children:Jc(o)}),t[21]=c,t[22]=o,t[23]=y):y=t[23];let b;return t[24]!==v||t[25]!==y?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[v,y]}),t[24]=v,t[25]=y,t[26]=b):b=t[26],b}let h=n.toolName,g=n.displayName,_=!!s,v;t[27]!==n.displayName||t[28]!==n.toolName||t[29]!==_?(v=(0,$.jsx)(Wc,{toolName:h,displayName:g,isActive:_}),t[27]=n.displayName,t[28]=n.toolName,t[29]=_,t[30]=v):v=t[30];let y;t[31]===f?y=t[32]:(y=f!==null&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`code`,{className:V(r.mono,r.caption,`break-all`),children:f})}),(0,$.jsx)(T,{children:f})]}),t[31]=f,t[32]=y);let b;t[33]===m?b=t[34]:(b=m&&(0,$.jsxs)(`span`,{className:V(r.caption,`text-muted-foreground`),children:[m.bytes,` bytes · HTTP `,m.code,` · `,m.durationMs,`ms`]}),t[33]=m,t[34]=b);let x;t[35]===o?x=t[36]:(x=o&&(0,$.jsx)(`button`,{type:`button`,className:V(r.caption,`text-brand hover:underline ml-auto`),onClick:()=>d(!0),children:`View result`}),t[35]=o,t[36]=x);let S;t[37]!==v||t[38]!==y||t[39]!==b||t[40]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[v,y,b,x]}),t[37]=v,t[38]=y,t[39]=b,t[40]=x,t[41]=S):S=t[41];let C;t[42]===o?C=t[43]:(C=o?Jc(o):``,t[42]=o,t[43]=C);let w;t[44]!==u||t[45]!==C?(w=(0,$.jsx)(Fc,{open:u,onOpenChange:d,title:`Fetch result`,content:C}),t[44]=u,t[45]=C,t[46]=w):w=t[46];let E;return t[47]!==w||t[48]!==S?(E=(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-3 my-1`,children:[S,w]}),t[47]=w,t[48]=S,t[49]=E):E=t[49],E}function qc(e){try{let t=JSON.parse(e);if(typeof t.bytes==`number`&&typeof t.code==`number`)return{bytes:t.bytes,code:t.code,durationMs:typeof t.durationMs==`number`?t.durationMs:0}}catch{}return null}function Jc(e){try{let t=JSON.parse(e);if(typeof t.result==`string`)return t.result}catch{}return e}var Yc=Hr,Xc=Er,Zc=Y.forwardRef((e,t)=>{let n=(0,X.c)(13),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:r,align:a,sideOffset:o,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a===void 0?`center`:a,c=o===void 0?4:o,l;n[5]===r?l=n[6]:(l=V(`z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[5]=r,n[6]=l);let u;return n[7]!==s||n[8]!==i||n[9]!==t||n[10]!==c||n[11]!==l?(u=(0,$.jsx)(Rr,{children:(0,$.jsx)(wr,{ref:t,align:s,sideOffset:c,className:l,...i})}),n[7]=s,n[8]=i,n[9]=t,n[10]=c,n[11]=l,n[12]=u):u=n[12],u});Zc.displayName=wr.displayName;function Qc(e){let t=(0,X.c)(6),{type:n,count:i}=e,a=n===`added`?`text-green-600 dark:text-green-400`:`text-red-600 dark:text-red-400`,o;t[0]===a?o=t[1]:(o=V(r.compact,`font-mono tabular-nums`,a),t[0]=a,t[1]=o);let s=n===`added`?`+`:`-`,c;return t[2]!==i||t[3]!==o||t[4]!==s?(c=(0,$.jsxs)(`span`,{className:o,children:[s,i]}),t[2]=i,t[3]=o,t[4]=s,t[5]=c):c=t[5],c}function $c(e){let t=(0,X.c)(3),{offset:n,limit:i}=e;if(n===null&&i===null)return null;let a;a=n!==null&&i!==null?`${n}-${n+i}`:n===null?`${i}`:`${n}-`;let o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=V(r.compact,`font-mono tabular-nums text-muted-foreground`),t[0]=o):o=t[0];let s;return t[1]===a?s=t[2]:(s=(0,$.jsx)(`span`,{className:o,children:a}),t[1]=a,t[2]=s),s}function el(e){let t=(0,X.c)(51),{data:n,inline:a,rootPath:o,onOpenFile:s}=e,[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f;t[0]!==n.filePath||t[1]!==s||t[2]!==o?(f=function(){!n.filePath||!s||s(o&&n.filePath.startsWith(o)?n.filePath.slice(o.length+1):n.filePath)},t[0]=n.filePath,t[1]=s,t[2]=o,t[3]=f):f=t[3];let p=f;if(a){let e=!!(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName),i;t[4]!==n.displayName||t[5]!==n.toolId||t[6]!==n.toolInput||t[7]!==n.toolName||t[8]!==e?(i=e?(0,$.jsxs)(Yc,{children:[(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),(0,$.jsx)(Zc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:V(r.caption,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput})]})})]}):(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[4]=n.displayName,t[5]=n.toolId,t[6]=n.toolInput,t[7]=n.toolName,t[8]=e,t[9]=i):i=t[9];let a;t[10]!==n.editAddedLineCount||t[11]!==n.editDeletedLineCount||t[12]!==n.editNewText||t[13]!==n.editOldText||t[14]!==n.fileDisplayName||t[15]!==n.filePath||t[16]!==n.hasEditDiff||t[17]!==n.limit||t[18]!==n.offset||t[19]!==n.path||t[20]!==n.toolName||t[21]!==u||t[22]!==p||t[23]!==o?(a=n.fileDisplayName?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:n.hasEditDiff?()=>d(!0):p,className:V(`inline-flex max-w-full items-center gap-2 cursor-pointer`,r.caption,`font-mono hover:underline`),children:[(0,$.jsx)(`span`,{className:`truncate max-w-[200px] sm:max-w-[320px]`,children:n.fileDisplayName}),n.toolName===`read`?(0,$.jsx)($c,{offset:n.offset,limit:n.limit}):null,n.hasEditDiff?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 shrink-0`,children:[n.editAddedLineCount===null?null:(0,$.jsx)(Qc,{type:`added`,count:n.editAddedLineCount}),n.editDeletedLineCount===null?null:(0,$.jsx)(Qc,{type:`deleted`,count:n.editDeletedLineCount})]}):null]})}),(0,$.jsx)(T,{children:n.hasEditDiff?`View diff`:n.filePath?lc(n.filePath,o)??n.filePath:n.fileDisplayName})]}),n.hasEditDiff&&(0,$.jsx)(Ge,{open:u,onOpenChange:d,children:(0,$.jsxs)(Ye,{className:`max-w-2xl h-[80vh] flex flex-col`,children:[(0,$.jsx)(_t,{children:(0,$.jsx)(Cn,{children:(0,$.jsx)(`code`,{className:V(r.caption,`font-mono`),children:lc(n.filePath,o)??n.filePath})})}),(0,$.jsx)(`div`,{className:`overflow-auto flex-1 rounded border border-border bg-muted/30 p-3`,children:(0,$.jsx)(Lc,{oldText:n.editOldText,newText:n.editNewText})})]})})]}):n.path===null?null:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:V(r.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(T,{children:n.path})]}),t[10]=n.editAddedLineCount,t[11]=n.editDeletedLineCount,t[12]=n.editNewText,t[13]=n.editOldText,t[14]=n.fileDisplayName,t[15]=n.filePath,t[16]=n.hasEditDiff,t[17]=n.limit,t[18]=n.offset,t[19]=n.path,t[20]=n.toolName,t[21]=u,t[22]=p,t[23]=o,t[24]=a):a=t[24];let s;return t[25]!==i||t[26]!==a?(s=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[i,a]}),t[25]=i,t[26]=a,t[27]=s):s=t[27],s}let m;t[28]===c?m=t[29]:(m=()=>l(!c),t[28]=c,t[29]=m);let h;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(h=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[30]=h):h=t[30];let g;t[31]===n.displayName?g=t[32]:(g=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[31]=n.displayName,t[32]=g);let _;t[33]===c?_=t[34]:(_=c?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[33]=c,t[34]=_);let v;t[35]!==m||t[36]!==g||t[37]!==_?(v=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:m,className:h,children:[g,_]})}),t[35]=m,t[36]=g,t[37]=_,t[38]=v):v=t[38];let y;t[39]===n.toolName?y=t[40]:(y=(0,$.jsx)(T,{children:n.toolName}),t[39]=n.toolName,t[40]=y);let b;t[41]!==v||t[42]!==y?(b=(0,$.jsxs)(U,{children:[v,y]}),t[41]=v,t[42]=y,t[43]=b):b=t[43];let x;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==c?(x=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=c,t[47]=x):x=t[47];let S;return t[48]!==b||t[49]!==x?(S=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[b,x]}),t[48]=b,t[49]=x,t[50]=S):S=t[50],S}function tl(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:sc(t,50)}}function nl(e){let t=(0,X.c)(11),{text:n}=e,r;t[0]===n?r=t[1]:(r=tl(n),t[0]=n,t[1]=r);let{label:i,fullText:a}=r,o;t[2]===i?o=t[3]:(o=(0,$.jsx)(Hc,{children:i}),t[2]=i,t[3]=o);let s=o;if(i===a)return s;let c;t[4]===s?c=t[5]:(c=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:`min-w-0`,children:s})}),t[4]=s,t[5]=c);let l;t[6]===a?l=t[7]:(l=(0,$.jsx)(T,{className:`max-w-md break-all font-mono`,children:a}),t[6]=a,t[7]=l);let u;return t[8]!==c||t[9]!==l?(u=(0,$.jsxs)(U,{children:[c,l]}),t[8]=c,t[9]=l,t[10]=u):u=t[10],u}function rl(e){let t=(0,X.c)(7),{data:n}=e,r=n.toolName===`code_search`,i;return t[0]!==n.codeSearchFileGlob||t[1]!==n.codeSearchFilePath||t[2]!==n.codeSearchQuery||t[3]!==n.pattern||t[4]!==n.webSearchQuery||t[5]!==r?(i=(0,$.jsx)($.Fragment,{children:r?(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(nl,{text:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsx)(nl,{text:`/${n.pattern}/`}),n.codeSearchFilePath!==null&&(0,$.jsx)(nl,{text:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(nl,{text:n.codeSearchFileGlob})]}):(0,$.jsxs)($.Fragment,{children:[n.webSearchQuery!==null&&(0,$.jsx)(nl,{text:n.webSearchQuery}),n.pattern!==null&&(0,$.jsx)(nl,{text:n.pattern})]})}),t[0]=n.codeSearchFileGlob,t[1]=n.codeSearchFilePath,t[2]=n.codeSearchQuery,t[3]=n.pattern,t[4]=n.webSearchQuery,t[5]=r,t[6]=i):i=t[6],i}function il(e){let t=(0,X.c)(72),{data:n,inline:a,resultContent:o,isActive:s}=e,[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=n.toolName===`code_search`,p=n.webSearchQuery??n.codeSearchQuery??n.pattern??n.codeSearchFilePath??n.codeSearchFileGlob??`search`,m;t[0]===p?m=t[1]:(m=tl(p),t[0]=p,t[1]=m);let{label:h,fullText:g}=m,_=h!==g;if(a){if(o&&(f||n.toolName===`find`||n.webSearchQuery!==null||n.pattern!==null)){let e;t[2]!==n.displayName||t[3]!==n.toolName||t[4]!==s?(e=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:s,className:`shrink-0`}),t[2]=n.displayName,t[3]=n.toolName,t[4]=s,t[5]=e):e=t[5];let i,a;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>d(!0),a=V(r.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 cursor-pointer text-left`),t[6]=i,t[7]=a):(i=t[6],a=t[7]);let c;t[8]===h?c=t[9]:(c=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,className:a,children:h})}),t[8]=h,t[9]=c);let l=_?g:`View results`,f;t[10]===l?f=t[11]:(f=(0,$.jsx)(T,{className:`max-w-md break-all font-mono`,children:l}),t[10]=l,t[11]=f);let p;t[12]!==c||t[13]!==f?(p=(0,$.jsxs)(U,{children:[c,f]}),t[12]=c,t[13]=f,t[14]=p):p=t[14];let m;t[15]!==e||t[16]!==p?(m=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,p]}),t[15]=e,t[16]=p,t[17]=m):m=t[17];let v;t[18]!==u||t[19]!==o||t[20]!==g?(v=(0,$.jsx)(Fc,{open:u,onOpenChange:d,title:g,content:o}),t[18]=u,t[19]=o,t[20]=g,t[21]=v):v=t[21];let y;return t[22]!==v||t[23]!==m?(y=(0,$.jsxs)($.Fragment,{children:[m,v]}),t[22]=v,t[23]=m,t[24]=y):y=t[24],y}let e;t[25]!==n.displayName||t[26]!==n.toolName||t[27]!==s?(e=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:s,className:`shrink-0`}),t[25]=n.displayName,t[26]=n.toolName,t[27]=s,t[28]=e):e=t[28];let i;t[29]===n?i=t[30]:(i=(0,$.jsx)(rl,{data:n}),t[29]=n,t[30]=i);let a;t[31]===n.lang?a=t[32]:(a=n.lang!==null&&(0,$.jsx)(`span`,{className:V(r.caption,`px-1.5 py-0.5 rounded bg-muted`),children:n.lang}),t[31]=n.lang,t[32]=a);let c;return t[33]!==e||t[34]!==i||t[35]!==a?(c=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,i,a]}),t[33]=e,t[34]=i,t[35]=a,t[36]=c):c=t[36],c}let v;t[37]===c?v=t[38]:(v=()=>l(!c),t[37]=c,t[38]=v);let y;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(y=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[39]=y):y=t[39];let b;t[40]===s?b=t[41]:(b=s&&(0,$.jsx)(Uc,{size:`md`}),t[40]=s,t[41]=b);let x;t[42]===n.displayName?x=t[43]:(x=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[42]=n.displayName,t[43]=x);let S;t[44]!==n.codeSearchFileGlob||t[45]!==n.codeSearchFilePath||t[46]!==n.codeSearchQuery||t[47]!==n.pattern||t[48]!==f?(S=f&&(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(`code`,{className:V(r.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsxs)(`code`,{className:V(r.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:[`/`,n.pattern,`/`]}),n.codeSearchFilePath!==null&&(0,$.jsx)(`code`,{className:V(r.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(`code`,{className:V(r.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFileGlob})]}),t[44]=n.codeSearchFileGlob,t[45]=n.codeSearchFilePath,t[46]=n.codeSearchQuery,t[47]=n.pattern,t[48]=f,t[49]=S):S=t[49];let C;t[50]===c?C=t[51]:(C=c?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[50]=c,t[51]=C);let w;t[52]!==v||t[53]!==b||t[54]!==x||t[55]!==S||t[56]!==C?(w=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:v,className:y,children:[b,x,S,C]})}),t[52]=v,t[53]=b,t[54]=x,t[55]=S,t[56]=C,t[57]=w):w=t[57];let E;t[58]===n.toolName?E=t[59]:(E=(0,$.jsx)(T,{children:n.toolName}),t[58]=n.toolName,t[59]=E);let D;t[60]!==w||t[61]!==E?(D=(0,$.jsxs)(U,{children:[w,E]}),t[60]=w,t[61]=E,t[62]=D):D=t[62];let O;t[63]!==n.toolId||t[64]!==n.toolInput||t[65]!==c||t[66]!==f||t[67]!==o?(O=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null,f&&o&&(0,$.jsx)(`pre`,{className:Pc({maxHeight:`64`,className:`mt-2`}),children:o})]}),t[63]=n.toolId,t[64]=n.toolInput,t[65]=c,t[66]=f,t[67]=o,t[68]=O):O=t[68];let k;return t[69]!==D||t[70]!==O?(k=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[D,O]}),t[69]=D,t[70]=O,t[71]=k):k=t[71],k}function al(e){let t=(0,X.c)(13),{output:n,scrollRef:i,placeholder:a,threadId:o,className:s,style:c}=e,l;t[0]===n?l=t[1]:(l=n?ra(ac(n)):``,t[0]=n,t[1]=l);let u=l,d;t[2]===s?d=t[3]:(d=V(r.caption,`text-muted-foreground/60 overflow-y-auto scrollbar-hide`,s),t[2]=s,t[3]=d);let f;t[4]!==u||t[5]!==a||t[6]!==o?(f=u?(0,$.jsx)(us,{content:u,compact:!0,threadId:o}):a,t[4]=u,t[5]=a,t[6]=o,t[7]=f):f=t[7];let p;return t[8]!==i||t[9]!==c||t[10]!==d||t[11]!==f?(p=(0,$.jsx)(`div`,{ref:i,className:d,style:c,children:f}),t[8]=i,t[9]=c,t[10]=d,t[11]=f,t[12]=p):p=t[12],p}function ol(e){let t=(0,X.c)(136),{data:n,inline:a,resultContent:o,isActive:s}=e,c=(0,Y.useRef)(null),[l,u]=(0,Y.useState)(!!s),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(!!s),m;t[0]===n.toolId?m=t[1]:(m=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=m);let h=Q(m),g=Q(sl),_=s?h??o??``:o??h??``,v;t[2]===_?v=t[3]:(v=_?ac(_):``,t[2]=_,t[3]=v);let y=v,b=s?y:``,x,S;t[4]===s?(x=t[5],S=t[6]):(x=()=>{s&&!p.current?u(!0):!s&&p.current&&u(!1),p.current=!!s},S=[s],t[4]=s,t[5]=x,t[6]=S),(0,Y.useEffect)(x,S);let C;t[7]!==l||t[8]!==s?(C=()=>{l&&s&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},t[7]=l,t[8]=s,t[9]=C):C=t[9];let w;if(t[10]!==l||t[11]!==s||t[12]!==b?(w=[l,s,b],t[10]=l,t[11]=s,t[12]=b,t[13]=w):w=t[13],(0,Y.useEffect)(C,w),a){if(s){let e;t[14]===l?e=t[15]:(e=()=>u(!l),t[14]=l,t[15]=e);let r;t[16]!==n.activeDisplayName||t[17]!==n.toolName?(r=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!0}),t[16]=n.activeDisplayName,t[17]=n.toolName,t[18]=r):r=t[18];let a;t[19]===n.agentName?a=t[20]:(a=n.agentName&&(0,$.jsx)(Bc,{name:n.agentName}),t[19]=n.agentName,t[20]=a);let o;t[21]===n.subagentType?o=t[22]:(o=n.subagentType&&(0,$.jsx)(Vc,{type:n.subagentType}),t[21]=n.subagentType,t[22]=o);let s;t[23]===l?s=t[24]:(s=l?(0,$.jsx)(i,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(Je,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[23]=l,t[24]=s);let d;t[25]!==l||t[26]!==o||t[27]!==s||t[28]!==e||t[29]!==r||t[30]!==a?(d=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":l,children:[r,a,o,s]}),t[25]=l,t[26]=o,t[27]=s,t[28]=e,t[29]=r,t[30]=a,t[31]=d):d=t[31];let f=l?`grid-rows-[1fr]`:`grid-rows-[0fr]`,p;t[32]===f?p=t[33]:(p=V(`grid transition-[grid-template-rows] duration-200 ease-in-out`,f),t[32]=f,t[33]=p);let m;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(m={maxHeight:`7.5em`},t[34]=m):m=t[34];let h;t[35]!==b||t[36]!==g?(h=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(al,{scrollRef:c,output:b,placeholder:`Running subagent...`,threadId:g,className:`ml-5`,style:m})}),t[35]=b,t[36]=g,t[37]=h):h=t[37];let _;t[38]!==p||t[39]!==h?(_=(0,$.jsx)(`div`,{className:p,children:h}),t[38]=p,t[39]=h,t[40]=_):_=t[40];let v;return t[41]!==d||t[42]!==_?(v=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[d,_]}),t[41]=d,t[42]=_,t[43]=v):v=t[43],v}if(y){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:!1})})})}),t[44]=n.displayName,t[45]=n.toolName,t[46]=e):e=t[46];let i;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(i=V(r.caption,`space-y-2`),t[47]=i):i=t[47];let a;t[48]===n.toolId?a=t[49]:(a=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[48]=n.toolId,t[49]=a);let o;t[50]!==n.prompt||t[51]!==n.toolInput?(o=n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null,t[50]=n.prompt,t[51]=n.toolInput,t[52]=o):o=t[52];let s;t[53]!==o||t[54]!==a?(s=(0,$.jsx)(Zc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:i,children:[a,o]})}),t[53]=o,t[54]=a,t[55]=s):s=t[55];let c;t[56]!==s||t[57]!==e?(c=(0,$.jsxs)(Yc,{children:[e,s]}),t[56]=s,t[57]=e,t[58]=c):c=t[58];let l;t[59]===n.agentName?l=t[60]:(l=n.agentName&&(0,$.jsx)(Bc,{name:n.agentName}),t[59]=n.agentName,t[60]=l);let u;t[61]===n.subagentType?u=t[62]:(u=n.subagentType&&(0,$.jsx)(Vc,{type:n.subagentType}),t[61]=n.subagentType,t[62]=u);let p;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(!0),className:V(r.caption,`text-muted-foreground hover:underline`),children:`View output`})}),(0,$.jsx)(T,{children:`View subagent output`})]}),t[63]=p):p=t[63];let m;t[64]!==c||t[65]!==l||t[66]!==u?(m=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[c,l,u,p]}),t[64]=c,t[65]=l,t[66]=u,t[67]=m):m=t[67];let h;t[68]!==n.displayName||t[69]!==d||t[70]!==y||t[71]!==g?(h=(0,$.jsx)(Fc,{open:d,onOpenChange:f,title:n.displayName,content:y,markdown:!0,threadId:g}),t[68]=n.displayName,t[69]=d,t[70]=y,t[71]=g,t[72]=h):h=t[72];let _;return t[73]!==m||t[74]!==h?(_=(0,$.jsxs)($.Fragment,{children:[m,h]}),t[73]=m,t[74]=h,t[75]=_):_=t[75],_}let e;t[76]!==n.displayName||t[77]!==n.toolName?(e=(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),t[76]=n.displayName,t[77]=n.toolName,t[78]=e):e=t[78];let a;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(a=V(r.caption,`space-y-2`),t[79]=a):a=t[79];let o;t[80]===n.toolId?o=t[81]:(o=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[80]=n.toolId,t[81]=o);let p;t[82]!==n.prompt||t[83]!==n.toolInput?(p=n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null,t[82]=n.prompt,t[83]=n.toolInput,t[84]=p):p=t[84];let m;t[85]!==p||t[86]!==o?(m=(0,$.jsx)(Zc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:a,children:[o,p]})}),t[85]=p,t[86]=o,t[87]=m):m=t[87];let h;t[88]!==m||t[89]!==e?(h=(0,$.jsxs)(Yc,{children:[e,m]}),t[88]=m,t[89]=e,t[90]=h):h=t[90];let _;t[91]===n.agentName?_=t[92]:(_=n.agentName&&(0,$.jsx)(Bc,{name:n.agentName}),t[91]=n.agentName,t[92]=_);let v;t[93]===n.subagentType?v=t[94]:(v=n.subagentType&&(0,$.jsx)(Vc,{type:n.subagentType}),t[93]=n.subagentType,t[94]=v);let x;return t[95]!==h||t[96]!==_||t[97]!==v?(x=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[h,_,v]}),t[95]=h,t[96]=_,t[97]=v,t[98]=x):x=t[98],x}let E;t[99]===l?E=t[100]:(E=()=>u(!l),t[99]=l,t[100]=E);let D;t[101]===Symbol.for(`react.memo_cache_sentinel`)?(D=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[101]=D):D=t[101];let O;t[102]===s?O=t[103]:(O=s&&(0,$.jsx)(Uc,{size:`md`}),t[102]=s,t[103]=O);let k=s?n.activeDisplayName:n.displayName,A;t[104]===k?A=t[105]:(A=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:k}),t[104]=k,t[105]=A);let j;t[106]===n.agentName?j=t[107]:(j=n.agentName&&(0,$.jsx)(Bc,{name:n.agentName}),t[106]=n.agentName,t[107]=j);let M;t[108]===n.subagentType?M=t[109]:(M=n.subagentType&&(0,$.jsx)(Vc,{type:n.subagentType}),t[108]=n.subagentType,t[109]=M);let N;t[110]===l?N=t[111]:(N=l?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[110]=l,t[111]=N);let P;t[112]!==A||t[113]!==j||t[114]!==M||t[115]!==N||t[116]!==E||t[117]!==O?(P=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:E,className:D,children:[O,A,j,M,N]})}),t[112]=A,t[113]=j,t[114]=M,t[115]=N,t[116]=E,t[117]=O,t[118]=P):P=t[118];let F;t[119]===n.toolName?F=t[120]:(F=(0,$.jsx)(T,{children:n.toolName}),t[119]=n.toolName,t[120]=F);let I;t[121]!==P||t[122]!==F?(I=(0,$.jsxs)(U,{children:[P,F]}),t[121]=P,t[122]=F,t[123]=I):I=t[123];let L;t[124]!==n.prompt||t[125]!==n.toolId||t[126]!==n.toolInput||t[127]!==y||t[128]!==l||t[129]!==s||t[130]!==b||t[131]!==g?(L=l&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),s?(0,$.jsx)(al,{scrollRef:c,output:b,placeholder:`Running subagent...`,threadId:g,style:{maxHeight:`7.5em`}}):n.prompt?(0,$.jsx)(`div`,{className:Pc({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):y?(0,$.jsx)(al,{output:y,threadId:g,className:`max-h-64`}):null]}),t[124]=n.prompt,t[125]=n.toolId,t[126]=n.toolInput,t[127]=y,t[128]=l,t[129]=s,t[130]=b,t[131]=g,t[132]=L):L=t[132];let R;return t[133]!==I||t[134]!==L?(R=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[I,L]}),t[133]=I,t[134]=L,t[135]=R):R=t[135],R}function sl(e){return e.selectedThreadId}function cl(e){let t=(0,X.c)(26),{data:n,inline:a,isActive:o}=e,[s,c]=(0,Y.useState)(!1);if(a)return null;let l;t[0]===s?l=t[1]:(l=()=>c(!s),t[0]=s,t[1]=l);let u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=V(r.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[2]=u):u=t[2];let d;t[3]===o?d=t[4]:(d=o&&(0,$.jsx)(Uc,{size:`md`}),t[3]=o,t[4]=d);let f;t[5]===n.displayName?f=t[6]:(f=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[5]=n.displayName,t[6]=f);let p;t[7]===s?p=t[8]:(p=s?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[7]=s,t[8]=p);let m;t[9]!==l||t[10]!==d||t[11]!==f||t[12]!==p?(m=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:l,className:u,children:[d,f,p]})}),t[9]=l,t[10]=d,t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;t[14]===n.toolName?h=t[15]:(h=(0,$.jsx)(T,{children:n.toolName}),t[14]=n.toolName,t[15]=h);let g;t[16]!==m||t[17]!==h?(g=(0,$.jsxs)(U,{children:[m,h]}),t[16]=m,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==n.toolId||t[20]!==n.toolInput||t[21]!==s?(_=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null]}),t[19]=n.toolId,t[20]=n.toolInput,t[21]=s,t[22]=_):_=t[22];let v;return t[23]!==g||t[24]!==_?(v=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[g,_]}),t[23]=g,t[24]=_,t[25]=v):v=t[25],v}function ll(e){let t=(0,X.c)(35),{data:n,inline:a,isActive:o}=e,[s,c]=(0,Y.useState)(!1);if(a){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==o?(e=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:o}),t[0]=n.displayName,t[1]=n.toolName,t[2]=o,t[3]=e):e=t[3];let i;t[4]===n.imageGenPrompt?i=t[5]:(i=n.imageGenPrompt!==null&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:V(r.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.imageGenPrompt})}),(0,$.jsx)(T,{children:n.imageGenPrompt})]}),t[4]=n.imageGenPrompt,t[5]=i);let a;return t[6]!==e||t[7]!==i?(a=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,i]}),t[6]=e,t[7]=i,t[8]=a):a=t[8],a}let l;t[9]===s?l=t[10]:(l=()=>c(!s),t[9]=s,t[10]=l);let u;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=V(r.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[11]=u):u=t[11];let d;t[12]===o?d=t[13]:(d=o&&(0,$.jsx)(Uc,{size:`md`}),t[12]=o,t[13]=d);let f;t[14]===n.displayName?f=t[15]:(f=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[14]=n.displayName,t[15]=f);let p;t[16]===s?p=t[17]:(p=s?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[16]=s,t[17]=p);let m;t[18]!==l||t[19]!==d||t[20]!==f||t[21]!==p?(m=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:l,className:u,children:[d,f,p]})}),t[18]=l,t[19]=d,t[20]=f,t[21]=p,t[22]=m):m=t[22];let h;t[23]===n.toolName?h=t[24]:(h=(0,$.jsx)(T,{children:n.toolName}),t[23]=n.toolName,t[24]=h);let g;t[25]!==m||t[26]!==h?(g=(0,$.jsxs)(U,{children:[m,h]}),t[25]=m,t[26]=h,t[27]=g):g=t[27];let _;t[28]!==n.toolId||t[29]!==n.toolInput||t[30]!==s?(_=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null]}),t[28]=n.toolId,t[29]=n.toolInput,t[30]=s,t[31]=_):_=t[31];let v;return t[32]!==g||t[33]!==_?(v=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[g,_]}),t[32]=g,t[33]=_,t[34]=v):v=t[34],v}function ul(e){if(!e)return null;try{let t=JSON.parse(e);return qo(t,{content:e,...t})}catch{return qo(e,{content:e})}}function dl(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`image`}function fl(e){let t=(0,X.c)(54),{data:n,inline:a,resultContent:o,isActive:s}=e,[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=Q(pl),p,m;t[0]===o?(p=t[1],m=t[2]):(p=ul(o),m=p?dl(p):null,t[0]=o,t[1]=p,t[2]=m);let h=m;if(a){let e;t[3]!==n.displayName||t[4]!==n.toolName||t[5]!==s?(e=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:s}),t[3]=n.displayName,t[4]=n.toolName,t[5]=s,t[6]=e):e=t[6];let i;t[7]!==n.findImagesQuery||t[8]!==p?(i=n.findImagesQuery!==null&&!p&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:V(r.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.findImagesQuery})}),(0,$.jsx)(T,{children:n.findImagesQuery})]}),t[7]=n.findImagesQuery,t[8]=p,t[9]=i):i=t[9];let a;t[10]!==p||t[11]!==h?(a=p&&h&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),className:V(r.caption,`hover:underline`),children:[`Found `,h]})}),(0,$.jsx)(T,{children:`View image`})]}),t[10]=p,t[11]=h,t[12]=a):a=t[12];let o;t[13]!==e||t[14]!==i||t[15]!==a?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,i,a]}),t[13]=e,t[14]=i,t[15]=a,t[16]=o):o=t[16];let c;t[17]!==u||t[18]!==p||t[19]!==h||t[20]!==f?(c=p&&(0,$.jsx)(Ge,{open:u,onOpenChange:d,children:(0,$.jsxs)(Ye,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(_t,{children:(0,$.jsxs)(Cn,{children:[`Found `,h]})}),(0,$.jsx)(Go,{imageUrl:p.imageUrl,imageData:p.imageData,threadId:f,alt:h??`Found image`})]})}),t[17]=u,t[18]=p,t[19]=h,t[20]=f,t[21]=c):c=t[21];let l;return t[22]!==o||t[23]!==c?(l=(0,$.jsxs)($.Fragment,{children:[o,c]}),t[22]=o,t[23]=c,t[24]=l):l=t[24],l}let g;t[25]===c?g=t[26]:(g=()=>l(!c),t[25]=c,t[26]=g);let _;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(_=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[27]=_):_=t[27];let v;t[28]===s?v=t[29]:(v=s&&(0,$.jsx)(Uc,{size:`md`}),t[28]=s,t[29]=v);let y=p?`Found ${h}`:n.displayName,b;t[30]===y?b=t[31]:(b=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:y}),t[30]=y,t[31]=b);let x;t[32]===c?x=t[33]:(x=c?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[32]=c,t[33]=x);let S;t[34]!==g||t[35]!==v||t[36]!==b||t[37]!==x?(S=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:g,className:_,children:[v,b,x]})}),t[34]=g,t[35]=v,t[36]=b,t[37]=x,t[38]=S):S=t[38];let C;t[39]===n.toolName?C=t[40]:(C=(0,$.jsx)(T,{children:n.toolName}),t[39]=n.toolName,t[40]=C);let w;t[41]!==S||t[42]!==C?(w=(0,$.jsxs)(U,{children:[S,C]}),t[41]=S,t[42]=C,t[43]=w):w=t[43];let E;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==c||t[47]!==p||t[48]!==h||t[49]!==f?(E=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null,p&&(0,$.jsx)(Go,{imageUrl:p.imageUrl,imageData:p.imageData,threadId:f,alt:h??`Found image`})]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=c,t[47]=p,t[48]=h,t[49]=f,t[50]=E):E=t[50];let D;return t[51]!==w||t[52]!==E?(D=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[w,E]}),t[51]=w,t[52]=E,t[53]=D):D=t[53],D}function pl(e){return e.selectedThreadId}function ml(e){if(!e)return null;try{let t=JSON.parse(e);return t.action===`screenshot`?qo(t,{content:e,...t}):null}catch{return null}}function hl(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`screenshot`}function gl(e){let t=(0,X.c)(85),{data:n,inline:a,resultContent:o,isActive:s}=e,[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=Q(_l),p;t[0]===n.inputObj?p=t[1]:(p=mc(n.inputObj),t[0]=n.inputObj,t[1]=p);let m=p,h;t[2]===n.inputObj?h=t[3]:(h=uc(n.inputObj),t[2]=n.inputObj,t[3]=h);let g=h,_;t[4]===o?_=t[5]:(_=o?gc(o):``,t[4]=o,t[5]=_);let v=_,y,b;t[6]===o?(y=t[7],b=t[8]):(y=ml(o),b=y?hl(y):null,t[6]=o,t[7]=y,t[8]=b);let x=b;if(a){let e;t[9]!==n.displayName||t[10]!==n.toolName||t[11]!==s?(e=(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:s}),t[9]=n.displayName,t[10]=n.toolName,t[11]=s,t[12]=e):e=t[12];let i;t[13]!==m||t[14]!==o||t[15]!==x||t[16]!==y?(i=y&&x?(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),className:V(r.caption,`hover:underline`),children:[`Screenshot `,x]})}),(0,$.jsx)(T,{children:`View screenshot`})]}):o?(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:V(r.caption,`font-mono hover:underline break-all cursor-pointer`),children:m})}),(0,$.jsx)(T,{children:`View results`})]}):(0,$.jsx)(`span`,{className:V(r.caption,`font-mono break-all text-muted-foreground`),children:m}),t[13]=m,t[14]=o,t[15]=x,t[16]=y,t[17]=i):i=t[17];let a;t[18]!==e||t[19]!==i?(a=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,i]}),t[18]=e,t[19]=i,t[20]=a):a=t[20];let c;t[21]!==u||t[22]!==g||t[23]!==m||t[24]!==v||t[25]!==o||t[26]!==x||t[27]!==y||t[28]!==f?(c=y?(0,$.jsx)(Ge,{open:u,onOpenChange:d,children:(0,$.jsxs)(Ye,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(_t,{children:(0,$.jsxs)(Cn,{children:[`Screenshot `,x]})}),(0,$.jsx)(Go,{imageUrl:y.imageUrl,imageData:y.imageData,threadId:f,alt:x??`Browser screenshot`})]})}):o&&(0,$.jsx)(Ic,{open:u,onOpenChange:d,title:m,requestContent:g,responseContent:v}),t[21]=u,t[22]=g,t[23]=m,t[24]=v,t[25]=o,t[26]=x,t[27]=y,t[28]=f,t[29]=c):c=t[29];let l;return t[30]!==a||t[31]!==c?(l=(0,$.jsxs)($.Fragment,{children:[a,c]}),t[30]=a,t[31]=c,t[32]=l):l=t[32],l}let S;t[33]===c?S=t[34]:(S=()=>l(!c),t[33]=c,t[34]=S);let C;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(C=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[35]=C):C=t[35];let w;t[36]===s?w=t[37]:(w=s&&(0,$.jsx)(Uc,{size:`md`}),t[36]=s,t[37]=w);let E=y&&x?`Screenshot ${x}`:n.displayName,D;t[38]===E?D=t[39]:(D=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:E}),t[38]=E,t[39]=D);let O;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(O=V(r.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[40]=O):O=t[40];let k;t[41]===m?k=t[42]:(k=(0,$.jsx)(`span`,{className:O,children:m}),t[41]=m,t[42]=k);let A;t[43]!==o||t[44]!==y?(A=o&&!y&&(0,$.jsx)(`button`,{type:`button`,className:V(r.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),d(!0)},children:`View results`}),t[43]=o,t[44]=y,t[45]=A):A=t[45];let j;t[46]===y?j=t[47]:(j=y&&(0,$.jsx)(`button`,{type:`button`,className:V(r.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),d(!0)},children:`View screenshot`}),t[46]=y,t[47]=j);let M;t[48]===c?M=t[49]:(M=c?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[48]=c,t[49]=M);let N;t[50]!==k||t[51]!==A||t[52]!==j||t[53]!==M||t[54]!==S||t[55]!==w||t[56]!==D?(N=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:S,className:C,children:[w,D,k,A,j,M]})}),t[50]=k,t[51]=A,t[52]=j,t[53]=M,t[54]=S,t[55]=w,t[56]=D,t[57]=N):N=t[57];let P;t[58]===n.toolName?P=t[59]:(P=(0,$.jsx)(T,{children:n.toolName}),t[58]=n.toolName,t[59]=P);let F;t[60]!==N||t[61]!==P?(F=(0,$.jsxs)(U,{children:[N,P]}),t[60]=N,t[61]=P,t[62]=F):F=t[62];let I;t[63]!==n.toolId||t[64]!==c||t[65]!==g||t[66]!==v||t[67]!==o||t[68]!==x||t[69]!==y||t[70]!==f?(I=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border space-y-2`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground font-mono`),children:[`ID: `,n.toolId]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:V(r.compact,`text-muted-foreground mb-1`),children:`Request`}),(0,$.jsx)(`pre`,{className:Pc(),children:g})]}),y?(0,$.jsx)(Go,{imageUrl:y.imageUrl,imageData:y.imageData,threadId:f,alt:x??`Browser screenshot`}):o&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:V(r.compact,`text-muted-foreground mb-1`),children:`Response`}),(0,$.jsx)(`pre`,{className:Pc({maxHeight:`64`}),children:v})]})]}),t[63]=n.toolId,t[64]=c,t[65]=g,t[66]=v,t[67]=o,t[68]=x,t[69]=y,t[70]=f,t[71]=I):I=t[71];let L;t[72]!==u||t[73]!==g||t[74]!==m||t[75]!==v||t[76]!==o||t[77]!==x||t[78]!==y||t[79]!==f?(L=y?(0,$.jsx)(Ge,{open:u,onOpenChange:d,children:(0,$.jsxs)(Ye,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(_t,{children:(0,$.jsxs)(Cn,{children:[`Screenshot `,x]})}),(0,$.jsx)(Go,{imageUrl:y.imageUrl,imageData:y.imageData,threadId:f,alt:x??`Browser screenshot`})]})}):o&&(0,$.jsx)(Ic,{open:u,onOpenChange:d,title:m,requestContent:g,responseContent:v}),t[72]=u,t[73]=g,t[74]=m,t[75]=v,t[76]=o,t[77]=x,t[78]=y,t[79]=f,t[80]=L):L=t[80];let R;return t[81]!==F||t[82]!==I||t[83]!==L?(R=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[F,I,L]}),t[81]=F,t[82]=I,t[83]=L,t[84]=R):R=t[84],R}function _l(e){return e.selectedThreadId}function vl(e){let t=(0,X.c)(10),{summary:n,fullSummary:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=V(r.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[0]=a):a=t[0];let o;t[1]===n?o=t[2]:(o=(0,$.jsx)(`span`,{className:a,children:n}),t[1]=n,t[2]=o);let s=o;if(n===i)return s;let c;t[3]===s?c=t[4]:(c=(0,$.jsx)(B,{asChild:!0,children:s}),t[3]=s,t[4]=c);let l;t[5]===i?l=t[6]:(l=(0,$.jsx)(T,{className:`max-w-md break-all font-mono`,children:i}),t[5]=i,t[6]=l);let u;return t[7]!==c||t[8]!==l?(u=(0,$.jsxs)(U,{children:[c,l]}),t[7]=c,t[8]=l,t[9]=u):u=t[9],u}function yl(e){let t=(0,X.c)(52),{data:n,inline:a,isActive:o}=e,[s,c]=(0,Y.useState)(!1),l,u;if(t[0]!==n.inputObj||t[1]!==n.path||t[2]!==n.prompt){let e=n.path===null?[]:[`path`];l=n.prompt===null?pc(n.inputObj,32,e):null,u=n.prompt===null?pc(n.inputObj,1/0,e):null,t[0]=n.inputObj,t[1]=n.path,t[2]=n.prompt,t[3]=l,t[4]=u}else l=t[3],u=t[4];let d=u;if(a){let e=!!(n.prompt??(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName)),i;t[5]!==n.displayName||t[6]!==n.prompt||t[7]!==n.toolId||t[8]!==n.toolInput||t[9]!==n.toolName||t[10]!==e||t[11]!==o?(i=e?(0,$.jsxs)(Yc,{children:[(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:o,muted:!1})})})}),(0,$.jsx)(Zc,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:V(r.bodyMuted,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null]})})]}):(0,$.jsx)(Wc,{toolName:n.toolName,displayName:n.displayName,isActive:o}),t[5]=n.displayName,t[6]=n.prompt,t[7]=n.toolId,t[8]=n.toolInput,t[9]=n.toolName,t[10]=e,t[11]=o,t[12]=i):i=t[12];let a;t[13]!==d||t[14]!==l?(a=l&&d&&(0,$.jsx)(vl,{summary:l,fullSummary:d}),t[13]=d,t[14]=l,t[15]=a):a=t[15];let s;t[16]===n.path?s=t[17]:(s=n.path!==null&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:V(r.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(T,{children:n.path})]}),t[16]=n.path,t[17]=s);let c;return t[18]!==i||t[19]!==a||t[20]!==s?(c=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[i,a,s]}),t[18]=i,t[19]=a,t[20]=s,t[21]=c):c=t[21],c}let f;t[22]===s?f=t[23]:(f=()=>c(!s),t[22]=s,t[23]=f);let p;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(p=V(r.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[24]=p):p=t[24];let m;t[25]===o?m=t[26]:(m=o&&(0,$.jsx)(Uc,{size:`md`}),t[25]=o,t[26]=m);let h;t[27]===n.displayName?h=t[28]:(h=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[27]=n.displayName,t[28]=h);let g;t[29]===l?g=t[30]:(g=l&&(0,$.jsx)(`span`,{className:V(r.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),children:l}),t[29]=l,t[30]=g);let _;t[31]===s?_=t[32]:(_=s?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[31]=s,t[32]=_);let v;t[33]!==f||t[34]!==m||t[35]!==h||t[36]!==g||t[37]!==_?(v=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:f,className:p,children:[m,h,g,_]})}),t[33]=f,t[34]=m,t[35]=h,t[36]=g,t[37]=_,t[38]=v):v=t[38];let y;t[39]===n.toolName?y=t[40]:(y=(0,$.jsx)(T,{children:n.toolName}),t[39]=n.toolName,t[40]=y);let b;t[41]!==v||t[42]!==y?(b=(0,$.jsxs)(U,{children:[v,y]}),t[41]=v,t[42]=y,t[43]=b):b=t[43];let x;t[44]!==n.prompt||t[45]!==n.toolId||t[46]!==n.toolInput||t[47]!==s?(x=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:Pc({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:Pc(),children:n.toolInput}):null]}),t[44]=n.prompt,t[45]=n.toolId,t[46]=n.toolInput,t[47]=s,t[48]=x):x=t[48];let S;return t[49]!==b||t[50]!==x?(S=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[b,x]}),t[49]=b,t[50]=x,t[51]=S):S=t[51],S}function bl(e){let t=(0,X.c)(51),{block:n,inline:r,resultContent:i,isActive:a}=e,{setActiveMainTab:o}=Js(),{setPendingExplorerPath:s}=Qs(),c=Q(xl),l=xc(n,c),u=!!a,d;t[0]!==o||t[1]!==s?(d=function(e){s(e),o(`explorer`)},t[0]=o,t[1]=s,t[2]=d):d=t[2];let f=d;switch(l.toolType){case`bash`:{let e;return t[3]!==l||t[4]!==r||t[5]!==u||t[6]!==i?(e=(0,$.jsx)(Gc,{data:l,inline:r,resultContent:i,isActive:u}),t[3]=l,t[4]=r,t[5]=u,t[6]=i,t[7]=e):e=t[7],e}case`fetch`:{let e;return t[8]!==l||t[9]!==r||t[10]!==u||t[11]!==i?(e=(0,$.jsx)(Kc,{data:l,inline:r,resultContent:i,isActive:u}),t[8]=l,t[9]=r,t[10]=u,t[11]=i,t[12]=e):e=t[12],e}case`file`:{let e;return t[13]!==l||t[14]!==f||t[15]!==r||t[16]!==u||t[17]!==c?(e=(0,$.jsx)(el,{data:l,inline:r,rootPath:c,onOpenFile:f,isActive:u}),t[13]=l,t[14]=f,t[15]=r,t[16]=u,t[17]=c,t[18]=e):e=t[18],e}case`search`:{let e;return t[19]!==l||t[20]!==r||t[21]!==u||t[22]!==i?(e=(0,$.jsx)(il,{data:l,inline:r,resultContent:i,isActive:u}),t[19]=l,t[20]=r,t[21]=u,t[22]=i,t[23]=e):e=t[23],e}case`agent`:{let e;return t[24]!==l||t[25]!==r||t[26]!==u||t[27]!==i?(e=(0,$.jsx)(ol,{data:l,inline:r,resultContent:i,isActive:u}),t[24]=l,t[25]=r,t[26]=u,t[27]=i,t[28]=e):e=t[28],e}case`todo`:{let e;return t[29]!==l||t[30]!==r||t[31]!==u?(e=(0,$.jsx)(cl,{data:l,inline:r,isActive:u}),t[29]=l,t[30]=r,t[31]=u,t[32]=e):e=t[32],e}case`imageGen`:{let e;return t[33]!==l||t[34]!==r||t[35]!==u?(e=(0,$.jsx)(ll,{data:l,inline:r,isActive:u}),t[33]=l,t[34]=r,t[35]=u,t[36]=e):e=t[36],e}case`findImages`:{let e;return t[37]!==l||t[38]!==r||t[39]!==u||t[40]!==i?(e=(0,$.jsx)(fl,{data:l,inline:r,resultContent:i,isActive:u}),t[37]=l,t[38]=r,t[39]=u,t[40]=i,t[41]=e):e=t[41],e}case`browser`:{let e;return t[42]!==l||t[43]!==r||t[44]!==u||t[45]!==i?(e=(0,$.jsx)(gl,{data:l,inline:r,resultContent:i,isActive:u}),t[42]=l,t[43]=r,t[44]=u,t[45]=i,t[46]=e):e=t[46],e}default:{let e;return t[47]!==l||t[48]!==r||t[49]!==u?(e=(0,$.jsx)(yl,{data:l,inline:r,isActive:u}),t[47]=l,t[48]=r,t[49]=u,t[50]=e):e=t[50],e}}}function xl(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Sl=(0,Y.createContext)({todos:[],setTodos:()=>{}});function Cl(e){let t=(0,X.c)(10),{children:n,threadId:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=[],t[0]=i):i=t[0];let[a,o]=(0,Y.useState)(i),s=(0,Y.useRef)(-1),c;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=(e,t)=>{t>=s.current&&(s.current=t,o(e))},t[1]=c):c=t[1];let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{s.current=-1,o([])},t[2]=u):u=t[2];let d;t[3]===r?d=t[4]:(d=[r],t[3]=r,t[4]=d),(0,Y.useEffect)(u,d);let f;t[5]===a?f=t[6]:(f={todos:a,setTodos:l},t[5]=a,t[6]=f);let p;return t[7]!==n||t[8]!==f?(p=(0,$.jsx)(Sl.Provider,{value:f,children:n}),t[7]=n,t[8]=f,t[9]=p):p=t[9],p}function wl(e){let t=[e.result,e.content],n=[];for(let e of t)if(typeof e==`string`)n.push(e);else if(Array.isArray(e))for(let t of e)typeof t==`object`&&t&&`text`in t&&typeof t.text==`string`&&n.push(t.text);for(let e of n){let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&Array.isArray(e.todos))return e.todos}catch(e){console.error(`Failed to parse todo JSON:`,e)}}return null}function Tl(e){let t=(0,X.c)(5),{todos:n,sequence:r}=e,{setTodos:i}=(0,Y.useContext)(Sl),a,o;return t[0]!==r||t[1]!==i||t[2]!==n?(a=()=>{i(n,r)},o=[n,i,r],t[0]=r,t[1]=i,t[2]=n,t[3]=a,t[4]=o):(a=t[3],o=t[4]),(0,Y.useEffect)(a,o),null}function El(e){let t=(0,X.c)(79),{block:n,inline:a,sequence:o}=e,s=o===void 0?0:o,[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=Q(Ol),p=Q(Dl),m=n.toolName??`Unknown Tool`,h=n.toolCallId??`unknown`,g=n,_=n.result??g.content,v;t[0]!==g||t[1]!==m?(v=m===`todo`?wl(g):null,t[0]=g,t[1]=m,t[2]=v):v=t[2];let y=v,b,x,S,C,w,E,D;if(t[3]!==g||t[4]!==a||t[5]!==_||t[6]!==f||t[7]!==s||t[8]!==p||t[9]!==y||t[10]!==m){D=Symbol.for(`react.early_return_sentinel`);bb0:{if(x=m===`find_images`?qo(_,g):null,C=lc(bc(_),f),!(C.length>0)&&y===null&&!x){D=null;break bb0}if(b=oc(m),typeof _==`object`&&_){let e=_,n=e.returnDisplay??e.return_display;if(typeof n==`string`&&n.trim()){let e;t[18]===n?e=t[19]:(e=n.trim(),t[18]=n,t[19]=e),b=e}else if(m===`read`||m===`file_read`){let n=e.filePath??e.file_path??e.path??``;if(n){let e;t[20]===n?e=t[21]:(e=n.split(`/`).pop()??n,t[20]=n,t[21]=e),b=`Completed ${e}`}}}else if(_==null){let e;t[22]===m?e=t[23]:(e=oc(m),t[22]=m,t[23]=e),b=`${e} (no result)`}if(x){let e=x.savedPath?lc(x.savedPath.split(`/`).pop()??x.savedPath,f):null;b=e?`Found ${e}`:`Found image`}if(b=lc(b,f),y!==null){let e;t[24]!==s||t[25]!==y?(e=(0,$.jsx)(Tl,{todos:y,sequence:s}),t[24]=s,t[25]=y,t[26]=e):e=t[26],D=e;break bb0}if(a&&(x||m===`browser`)){D=null;break bb0}if(m===`generate_image`){let e;t[27]!==g||t[28]!==_?(e=Ko(_)??Ko(g),t[27]=g,t[28]=_,t[29]=e):e=t[29];let n=e;if(n&&(n.imageUrl||n.imageData)){let e;t[30]!==n.imageData||t[31]!==n.imageUrl||t[32]!==p?(e=(0,$.jsx)(Go,{imageUrl:n.imageUrl,imageData:n.imageData,threadId:p}),t[30]=n.imageData,t[31]=n.imageUrl,t[32]=p,t[33]=e):e=t[33],D=e;break bb0}}if(a){D=null;break bb0}let e;t[34]===m?e=t[35]:(e=m.toLowerCase().includes(`bash`),t[34]=m,t[35]=e),S=e,w=C?C.split(`
23
+ `):[],E=S?w.slice(0,3).join(`
24
+ `):C}t[3]=g,t[4]=a,t[5]=_,t[6]=f,t[7]=s,t[8]=p,t[9]=y,t[10]=m,t[11]=b,t[12]=x,t[13]=S,t[14]=C,t[15]=w,t[16]=E,t[17]=D}else b=t[11],x=t[12],S=t[13],C=t[14],w=t[15],E=t[16],D=t[17];if(D!==Symbol.for(`react.early_return_sentinel`))return D;let O=E,k=S&&w.length>3;if(S){let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=V(r.body,`px-3 py-2 flex items-center gap-2 font-medium text-foreground`),t[36]=e):e=t[36];let n;t[37]===b?n=t[38]:(n=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:b})}),t[37]=b,t[38]=n);let i;t[39]!==k||t[40]!==O||t[41]!==C||t[42]!==w?(i=C&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[k?(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`pre`,{className:V(r.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2 cursor-pointer hover:bg-muted/80`),onClick:()=>d(!0),children:[O,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
25
+ `,`...`]})]})}),(0,$.jsx)(T,{children:`Click to see full output`})]}):(0,$.jsx)(`pre`,{className:V(r.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2`),children:O}),k&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),className:V(r.caption,`mt-1 text-brand hover:underline`),children:[`Show full output (`,w.length,` lines)`]})]}),t[39]=k,t[40]=O,t[41]=C,t[42]=w,t[43]=i):i=t[43];let a;t[44]!==n||t[45]!==i?(a=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[n,i]}),t[44]=n,t[45]=i,t[46]=a):a=t[46];let o;t[47]!==u||t[48]!==k||t[49]!==C?(o=k&&(0,$.jsx)(Ge,{open:u,onOpenChange:d,children:(0,$.jsxs)(Ye,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(_t,{children:(0,$.jsx)(Cn,{children:`Full Output`})}),(0,$.jsx)(`pre`,{className:V(r.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`),children:C})]})}),t[47]=u,t[48]=k,t[49]=C,t[50]=o):o=t[50];let s;return t[51]!==a||t[52]!==o?(s=(0,$.jsxs)($.Fragment,{children:[a,o]}),t[51]=a,t[52]=o,t[53]=s):s=t[53],s}let A;t[54]===c?A=t[55]:(A=()=>l(!c),t[54]=c,t[55]=A);let j;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(j=V(r.body,`w-full px-3 py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted transition-colors text-left`),t[56]=j):j=t[56];let M;t[57]===b?M=t[58]:(M=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:b}),t[57]=b,t[58]=M);let N;t[59]===c?N=t[60]:(N=c?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[59]=c,t[60]=N);let P;t[61]!==A||t[62]!==M||t[63]!==N?(P=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:A,className:j,children:[M,N]})}),t[61]=A,t[62]=M,t[63]=N,t[64]=P):P=t[64];let F=`${m} result`,I;t[65]===F?I=t[66]:(I=(0,$.jsx)(T,{children:F}),t[65]=F,t[66]=I);let L;t[67]!==I||t[68]!==P?(L=(0,$.jsxs)(U,{children:[P,I]}),t[67]=I,t[68]=P,t[69]=L):L=t[69];let R;t[70]!==c||t[71]!==x||t[72]!==C||t[73]!==p||t[74]!==h?(R=c&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,`text-muted-foreground mb-2 font-mono`),children:[`Call ID: `,h]}),x&&(0,$.jsx)(Go,{imageUrl:x.imageUrl,imageData:x.imageData,threadId:p}),C&&!x&&(0,$.jsx)(`pre`,{className:V(r.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`),children:C})]}),t[70]=c,t[71]=x,t[72]=C,t[73]=p,t[74]=h,t[75]=R):R=t[75];let ee;return t[76]!==L||t[77]!==R?(ee=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[L,R]}),t[76]=L,t[77]=R,t[78]=ee):ee=t[78],ee}function Dl(e){return e.selectedThreadId}function Ol(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var kl=ei(e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e.v0,"aria-expanded":e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:e.v3,children:e.v4})]}),(0,$.jsx)(`div`,{className:e.v5,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v6})})]}),{name:`ThinkingBlock_1`,portals:[`v2`,`v4`,`v6`]}),Al=function(e){let t=(0,X.c)(38),{text:n,isStreaming:i,label:a,threadId:o}=e,s=n===void 0?``:n,c=i===void 0?!1:i,l=(0,Y.useRef)(null),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=Date.now(),t[0]=u):u=t[0];let d=(0,Y.useRef)(u),[f,p]=(0,Y.useState)(0),[m,h]=(0,Y.useState)(!1),g=(0,Y.useRef)(c),_,v;t[1]===c?(_=t[2],v=t[3]):(_=()=>{c&&!g.current?(d.current=Date.now(),p(0)):g.current&&!c&&(p(Date.now()-d.current),h(!1)),g.current=c},v=[c],t[1]=c,t[2]=_,t[3]=v),(0,Y.useEffect)(_,v);let y;t[4]!==m||t[5]!==c?(y=()=>{m&&c&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},t[4]=m,t[5]=c,t[6]=y):y=t[6];let b;if(t[7]!==m||t[8]!==c||t[9]!==s?(b=[s,m,c],t[7]=m,t[8]=c,t[9]=s,t[10]=b):b=t[10],(0,Y.useEffect)(y,b),!s&&!c||!c&&f<=0&&a!==`MCP`&&a!==`Validated`)return null;let x=!c&&a===`Validated`,S;t[11]!==f||t[12]!==c||t[13]!==a||t[14]!==s?(S=Nl(c,a,f,vn(s)),t[11]=f,t[12]=c,t[13]=a,t[14]=s,t[15]=S):S=t[15];let C=S,w;t[16]===s?w=t[17]:(w=s?ra(ac(s)):``,t[16]=s,t[17]=w);let T=w,E;t[18]===m?E=t[19]:(E=()=>h(!m),t[18]=m,t[19]=E);let D;t[20]===x?D=t[21]:(D=x?(0,$.jsx)(L,{className:`h-3.5 w-3.5 shrink-0 text-green-600`}):null,t[20]=x,t[21]=D);let O=m?`grid-rows-[1fr]`:`grid-rows-[0fr]`,k;t[22]===O?k=t[23]:(k=[`grid transition-[grid-template-rows] duration-200 ease-in-out`,O],t[22]=O,t[23]=k);let A=k.join(` `),j,M;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(j=V(r.caption,`ml-5 text-muted-foreground/60 overflow-y-auto scrollbar-hide`),M={maxHeight:`7.5em`},t[24]=j,t[25]=M):(j=t[24],M=t[25]);let N;t[26]!==T||t[27]!==o?(N=T?(0,$.jsx)(us,{content:T,compact:!0,threadId:o}):null,t[26]=T,t[27]=o,t[28]=N):N=t[28];let P;t[29]===N?P=t[30]:(P=(0,$.jsx)(`div`,{ref:l,className:j,style:M,children:N}),t[29]=N,t[30]=P);let F;return t[31]!==m||t[32]!==C||t[33]!==E||t[34]!==D||t[35]!==A||t[36]!==P?(F=(0,$.jsx)(kl,{v0:E,v1:m,v2:D,v3:r.caption,v4:C,v5:A,v6:P}),t[31]=m,t[32]=C,t[33]=E,t[34]=D,t[35]=A,t[36]=P,t[37]=F):F=t[37],F};function jl(e){if(e<1e3){let t=Math.max(1,Math.round(e));return`${t} millisecond${t===1?``:`s`}`}let t=Math.max(1,Math.round(e/1e3));if(t<60)return`${t} second${t===1?``:`s`}`;let n=Math.floor(t/60),r=t%60;return r===0?`${n} minute${n===1?``:`s`}`:`${n} minute${n===1?``:`s`} ${r} second${r===1?``:`s`}`}function Ml(e){return` (${e.toLocaleString()} token${e===1?``:`s`})`}function Nl(e,t,n,r){let i=e&&r>0?Ml(r):``;return e?t===`MCP`?`Connecting MCP servers...${i}`:t===`Validating`?`Validating...${i}`:`Thinking...${i}`:t===`MCP`?`MCP setup complete.`:t===`Validated`?`Validated`:n<=0?`Thought complete.`:`Thought for ${jl(n)}.`}function Pl(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`${t}-${e.length}`}function Fl(e){if(typeof e.executionOutput==`string`)return e.executionOutput;let t=e.partial?.content?.[0]?.arguments;if(!(!t||typeof t!=`object`)&&`content`in t&&typeof t.content==`string`)return t.content}function Il(e,t){let n=e.find(e=>na(e)&&e.toolCallId===t);if(!n)return;let r=n,i=r.result??r.content;if(i!=null){if(typeof i==`string`){if(r.imageUrl&&i.trim().startsWith(`{`))try{let e=JSON.parse(i);if(!e.imageUrl)return JSON.stringify({...e,imageUrl:r.imageUrl})}catch{}return i}return JSON.stringify(i,null,2)}}function Ll(e,t){return e.some(e=>na(e)&&e.toolCallId===t)}function Rl(e,t){if(t)return Il(e,t)}var zl=ei(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsxs)(`div`,{className:e.v4,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[e.v5,`:`]}),` `,(0,$.jsx)(`span`,{children:e.v6})]})]}),{name:`AskUserBlock_1`,portals:[`v0`,`v2`,`v3`,`v5`,`v6`]}),Bl=ei(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),e.v4,(0,$.jsxs)(`div`,{className:`flex flex-col rounded-2xl border border-border focus-within:ring-2 focus-within:ring-brand`,children:[(0,$.jsx)(`input`,{type:`text`,value:e.v5,onChange:e.v6,onKeyDown:e.v7,placeholder:e.v8,disabled:e.v9,className:`w-full bg-transparent px-4 pt-3 pb-1 text-base text-foreground placeholder:text-muted-foreground focus:outline-none disabled:opacity-50`}),(0,$.jsx)(`div`,{className:`flex items-center justify-end px-3 pb-2`,children:(0,$.jsx)(`button`,{type:`button`,onClick:e.v10,disabled:e.v11,className:`h-7 w-7 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50 flex items-center justify-center shrink-0`,children:e.v12})})]})]}),{name:`AskUserBlock_2`,portals:[`v0`,`v2`,`v3`,`v4`,`v12`]}),Vl=function(e){let t=(0,X.c)(54),{toolCallId:n,question:i,options:a,context:o,answeredText:s,answeredLabel:c}=e,[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(!!s),[p,m]=(0,Y.useState)(s??``),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(null),y,b;t[0]===s?(y=t[1],b=t[2]):(y=()=>{let e=s?.trim();if(e){f(!0),m(e),g(!1),v(null);return}f(!1),m(``)},b=[s],t[0]=s,t[1]=y,t[2]=b),(0,Y.useEffect)(y,b);let x;t[3]!==h||t[4]!==n?(x=async e=>{if(!(!e.trim()||h)){g(!0);try{await Vt(n,e.trim()),m(e.trim()),f(!0)}catch(e){console.error(`Failed to submit answer:`,e),g(!1),v(null)}}},t[3]=h,t[4]=n,t[5]=x):x=t[5];let S=x,C;t[6]!==S||t[7]!==h||t[8]!==d?(C=e=>{d||h||(v(e),S(e))},t[6]=S,t[7]=h,t[8]=d,t[9]=C):C=t[9];let w=C,T;t[10]!==l||t[11]!==S||t[12]!==h||t[13]!==d?(T=()=>{if(d||h)return;let e=l.trim();e&&S(e)},t[10]=l,t[11]=S,t[12]=h,t[13]=d,t[14]=T):T=t[14];let E=T,D;t[15]===E?D=t[16]:(D=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),E())},t[15]=E,t[16]=D);let O=D;if(d){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(bt,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=V(r.label,`text-foreground`),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let a;t[19]===i?a=t[20]:(a=(0,$.jsx)(us,{content:i}),t[19]=i,t[20]=a);let s;t[21]===o?s=t[22]:(s=o&&(0,$.jsx)(`p`,{className:V(r.bodyMuted,`mt-1`),children:o}),t[21]=o,t[22]=s);let l=c??`You answered`,u;return t[23]!==p||t[24]!==s||t[25]!==l||t[26]!==a?(u=(0,$.jsx)(zl,{v0:e,v1:n,v2:a,v3:s,v4:r.bodyMuted,v5:l,v6:p}),t[23]=p,t[24]=s,t[25]=l,t[26]=a,t[27]=u):u=t[27],u}let k,A;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(fn,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),A=V(r.label,`text-foreground`),t[28]=k,t[29]=A):(k=t[28],A=t[29]);let j;t[30]===i?j=t[31]:(j=(0,$.jsx)(us,{content:i}),t[30]=i,t[31]=j);let M;t[32]===o?M=t[33]:(M=o&&(0,$.jsx)(`p`,{className:V(r.bodyMuted,`mt-1`),children:o}),t[32]=o,t[33]=M);let N;t[34]!==w||t[35]!==h||t[36]!==a||t[37]!==_?(N=a&&a.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:a.map(e=>{let t=_===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>w(e),disabled:h,className:V(`rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50 flex items-center gap-1.5`,r.label,t?`border-foreground/20 bg-accent text-accent-foreground`:`border-foreground/20 bg-background text-foreground hover:bg-accent hover:text-accent-foreground`),children:[t&&(0,$.jsx)(bt,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[34]=w,t[35]=h,t[36]=a,t[37]=_,t[38]=N):N=t[38];let P;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(P=e=>u(e.target.value),t[39]=P):P=t[39];let F=a?.length?`Or type a custom answer...`:`Type your answer...`,I;t[40]!==l||t[41]!==h?(I=h||!l.trim(),t[40]=l,t[41]=h,t[42]=I):I=t[42];let L;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(nt,{className:`h-3 w-3`}),t[43]=L):L=t[43];let R;return t[44]!==l||t[45]!==E||t[46]!==O||t[47]!==h||t[48]!==M||t[49]!==N||t[50]!==F||t[51]!==I||t[52]!==j?(R=(0,$.jsx)(Bl,{v0:k,v1:A,v2:j,v3:M,v4:N,v5:l,v6:P,v7:O,v8:F,v9:h,v10:E,v11:I,v12:L}),t[44]=l,t[45]=E,t[46]=O,t[47]=h,t[48]=M,t[49]=N,t[50]=F,t[51]=I,t[52]=j,t[53]=R):R=t[53],R},Hl=qn,Ul=Mr,Wl=Ur,Gl=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),i,a,o,s;n[0]===e?(i=n[1],a=n[2],o=n[3],s=n[4]):({className:a,inset:o,children:i,...s}=e,n[0]=e,n[1]=i,n[2]=a,n[3]=o,n[4]=s);let c;n[5]!==a||n[6]!==o?(c=V(V(r.body,`flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),o&&`pl-8`,a),n[5]=a,n[6]=o,n[7]=c):c=n[7];let l;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Je,{className:`ml-auto`}),n[8]=l):l=n[8];let u;return n[9]!==i||n[10]!==s||n[11]!==t||n[12]!==c?(u=(0,$.jsxs)(Vr,{ref:t,className:c,...s,children:[i,l]}),n[9]=i,n[10]=s,n[11]=t,n[12]=c,n[13]=u):u=n[13],u});Gl.displayName=Vr.displayName;var Kl=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=V(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Lr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Kl.displayName=Lr.displayName;var ql=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,sideOffset:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?4:a,s;n[4]===r?s=n[5]:(s=V(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[4]=r,n[5]=s);let c;return n[6]!==i||n[7]!==t||n[8]!==o||n[9]!==s?(c=(0,$.jsx)(Sr,{children:(0,$.jsx)(Br,{ref:t,sideOffset:o,className:s,...i})}),n[6]=i,n[7]=t,n[8]=o,n[9]=s,n[10]=c):c=n[10],c});ql.displayName=Br.displayName;var Jl=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),i,a,o;n[0]===e?(i=n[1],a=n[2],o=n[3]):({className:i,inset:a,...o}=e,n[0]=e,n[1]=i,n[2]=a,n[3]=o);let s;n[4]!==i||n[5]!==a?(s=V(V(r.body,`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),a&&`pl-8`,i),n[4]=i,n[5]=a,n[6]=s):s=n[6];let c;return n[7]!==o||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(ir,{ref:t,className:s,...o}),n[7]=o,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});Jl.displayName=ir.displayName;var Yl=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),i,a,o,s;n[0]===e?(i=n[1],a=n[2],o=n[3],s=n[4]):({className:o,children:a,checked:i,...s}=e,n[0]=e,n[1]=i,n[2]=a,n[3]=o,n[4]=s);let c;n[5]===o?c=n[6]:(c=V(V(r.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),o),n[5]=o,n[6]=c);let l;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(xr,{children:(0,$.jsx)(bt,{className:`h-4 w-4`})})}),n[7]=l):l=n[7];let u;return n[8]!==i||n[9]!==a||n[10]!==s||n[11]!==t||n[12]!==c?(u=(0,$.jsxs)(ar,{ref:t,className:c,checked:i,...s,children:[l,a]}),n[8]=i,n[9]=a,n[10]=s,n[11]=t,n[12]=c,n[13]=u):u=n[13],u});Yl.displayName=ar.displayName;var Xl=Y.forwardRef((e,t)=>{let n=(0,X.c)(12),i,a,o;n[0]===e?(i=n[1],a=n[2],o=n[3]):({className:a,children:i,...o}=e,n[0]=e,n[1]=i,n[2]=a,n[3]=o);let s;n[4]===a?s=n[5]:(s=V(V(r.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),a),n[4]=a,n[5]=s);let c;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(xr,{children:(0,$.jsx)(O,{className:`h-2 w-2 fill-current`})})}),n[6]=c):c=n[6];let l;return n[7]!==i||n[8]!==o||n[9]!==t||n[10]!==s?(l=(0,$.jsxs)(pr,{ref:t,className:s,...o,children:[c,i]}),n[7]=i,n[8]=o,n[9]=t,n[10]=s,n[11]=l):l=n[11],l});Xl.displayName=pr.displayName;var Zl=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),i,a,o;n[0]===e?(i=n[1],a=n[2],o=n[3]):({className:i,inset:a,...o}=e,n[0]=e,n[1]=i,n[2]=a,n[3]=o);let s=a&&`pl-8`,c;n[4]!==i||n[5]!==s?(c=V(r.body,`px-2 py-1.5 font-semibold`,s,i),n[4]=i,n[5]=s,n[6]=c):c=n[6];let l;return n[7]!==o||n[8]!==t||n[9]!==c?(l=(0,$.jsx)(br,{ref:t,className:c,...o}),n[7]=o,n[8]=t,n[9]=c,n[10]=l):l=n[10],l});Zl.displayName=br.displayName;var Ql=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=V(`-mx-1 my-1 h-px bg-muted`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Or,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ql.displayName=Or.displayName;var $l=e=>{let t=(0,X.c)(8),n,i;t[0]===e?(n=t[1],i=t[2]):({className:n,...i}=e,t[0]=e,t[1]=n,t[2]=i);let a;t[3]===n?a=t[4]:(a=V(r.compact,`ml-auto tracking-widest opacity-60`,n),t[3]=n,t[4]=a);let o;return t[5]!==i||t[6]!==a?(o=(0,$.jsx)(`span`,{className:a,...i}),t[5]=i,t[6]=a,t[7]=o):o=t[7],o};$l.displayName=`DropdownMenuShortcut`;var eu=ei(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsx)(`div`,{className:e.v4,children:`Skipped`})]}),{name:`PermissionPromptBlock_1`,portals:[`v0`,`v2`,`v3`]}),tu=ei(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex rounded-md shadow-sm`,children:[e.v4,e.v5]}),e.v6]})]}),{name:`PermissionPromptBlock_2`,portals:[`v0`,`v2`,`v3`,`v4`,`v5`,`v6`]}),nu=function(e){let t=(0,X.c)(41),{icon:n,promptTitle:a,skippedTitle:o,detail:s,wildcardOptions:c,secondaryButtonLabel:l,resolvedDecision:u,onAllowOnce:d,onAllowWildcard:f,onSecondary:p}=e,[m,h]=(0,Y.useState)(!!u),[g,_]=(0,Y.useState)(u??null),[v,y]=(0,Y.useState)(!1),b,x;t[0]===u?(b=t[1],x=t[2]):(b=()=>{u&&(h(!0),_(u),y(!1))},x=[u],t[0]=u,t[1]=b,t[2]=x),(0,Y.useEffect)(b,x);let S;t[3]!==v||t[4]!==d||t[5]!==m?(S=async function(){if(!(v||m)){y(!0);try{await d(),h(!0),_(`allowed`)}catch(e){console.error(`Failed to submit permission response:`,e),y(!1)}}},t[3]=v,t[4]=d,t[5]=m,t[6]=S):S=t[6];let C=S,w;t[7]!==v||t[8]!==f||t[9]!==m?(w=async function(e){if(!(v||m)){y(!0);try{await f(e),h(!0),_(`allowed`)}catch(e){console.error(`Failed to submit permission response:`,e),y(!1)}}},t[7]=v,t[8]=f,t[9]=m,t[10]=w):w=t[10];let T=w,E;t[11]!==v||t[12]!==p||t[13]!==m?(E=async function(){if(!(v||m)){y(!0);try{await p(),h(!0),_(`skipped`)}catch(e){console.error(`Failed to submit permission response:`,e),y(!1)}}},t[11]=v,t[12]=p,t[13]=m,t[14]=E):E=t[14];let D=E;if(m&&g!==`skipped`)return null;if(m){let e;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(bt,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[15]=e):e=t[15];let n;return t[16]!==s||t[17]!==o?(n=(0,$.jsx)(eu,{v0:e,v1:r.label,v2:o,v3:s,v4:r.bodyMuted}),t[16]=s,t[17]=o,t[18]=n):n=t[18],n}let O;t[19]===C?O=t[20]:(O=()=>void C(),t[19]=C,t[20]=O);let k;t[21]!==v||t[22]!==O?(k=(0,$.jsx)(Rt,{type:`button`,size:`sm`,disabled:v,onClick:O,className:`rounded-r-none`,children:`Allow`}),t[21]=v,t[22]=O,t[23]=k):k=t[23];let A;t[24]!==T||t[25]!==v||t[26]!==c?(A=c.length>0&&(0,$.jsxs)(Hl,{children:[(0,$.jsx)(Ul,{asChild:!0,children:(0,$.jsx)(Rt,{type:`button`,size:`sm`,disabled:v,className:V(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(i,{className:`h-4 w-4`})})}),(0,$.jsx)(ql,{align:`end`,className:`max-w-md`,children:c.map(e=>(0,$.jsx)(Jl,{onClick:()=>void T(e),children:e.label},`${e.scope}-${e.pattern}`))})]}),t[24]=T,t[25]=v,t[26]=c,t[27]=A):A=t[27];let j;t[28]===D?j=t[29]:(j=()=>void D(),t[28]=D,t[29]=j);let M;t[30]!==v||t[31]!==l||t[32]!==j?(M=(0,$.jsx)(Rt,{type:`button`,size:`sm`,variant:`outline`,disabled:v,onClick:j,children:l}),t[30]=v,t[31]=l,t[32]=j,t[33]=M):M=t[33];let N;return t[34]!==s||t[35]!==n||t[36]!==a||t[37]!==M||t[38]!==k||t[39]!==A?(N=(0,$.jsx)(tu,{v0:n,v1:r.label,v2:a,v3:s,v4:k,v5:A,v6:M}),t[34]=s,t[35]=n,t[36]=a,t[37]=M,t[38]=k,t[39]=A,t[40]=N):N=t[40],N};function ru(e){let t=(0,X.c)(3),{command:n}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=V(r.mono,r.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),t[0]=i):i=t[0];let a;return t[1]===n?a=t[2]:(a=(0,$.jsx)(`code`,{className:i,children:n}),t[1]=n,t[2]=a),a}function iu(e){let t=(0,X.c)(16),{toolCallId:n,command:r,projectId:i,wildcardOptions:a,resolvedDecision:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(ne,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[0]=s):s=t[0];let c;t[1]===r?c=t[2]:(c=(0,$.jsx)(ru,{command:r}),t[1]=r,t[2]=c);let l,u;t[3]!==i||t[4]!==n?(l=()=>zt(n,`allow_once`,{projectId:i??void 0}),u=e=>zt(n,e.scope===`project`?`allow_pattern_project`:`allow_pattern_session`,{pattern:e.pattern,projectId:i??void 0}),t[3]=i,t[4]=n,t[5]=l,t[6]=u):(l=t[5],u=t[6]);let d;t[7]===n?d=t[8]:(d=()=>zt(n,`skip`),t[7]=n,t[8]=d);let f;return t[9]!==o||t[10]!==c||t[11]!==l||t[12]!==u||t[13]!==d||t[14]!==a?(f=(0,$.jsx)(nu,{icon:s,promptTitle:`Allow the agent to run this command?`,skippedTitle:`Shell command permission`,detail:c,wildcardOptions:a,secondaryButtonLabel:`Skip`,resolvedDecision:o,onAllowOnce:l,onAllowWildcard:u,onSecondary:d}),t[9]=o,t[10]=c,t[11]=l,t[12]=u,t[13]=d,t[14]=a,t[15]=f):f=t[15],f}function au(e){let t=(0,X.c)(9),{hostname:n,url:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=V(r.mono,r.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),t[0]=a):a=t[0];let o;t[1]===n?o=t[2]:(o=(0,$.jsx)(`code`,{className:a,children:n}),t[1]=n,t[2]=o);let s;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(s=V(r.caption,r.bodyMuted,`mt-1 break-all`),t[3]=s):s=t[3];let c;t[4]===i?c=t[5]:(c=(0,$.jsx)(`div`,{className:s,children:i}),t[4]=i,t[5]=c);let l;return t[6]!==o||t[7]!==c?(l=(0,$.jsxs)($.Fragment,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8],l}function ou(e){let t=(0,X.c)(15),{toolCallId:n,hostname:r,url:i,wildcardOptions:a,resolvedDecision:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(Ln,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[0]=s):s=t[0];let c;t[1]!==r||t[2]!==i?(c=(0,$.jsx)(au,{hostname:r,url:i}),t[1]=r,t[2]=i,t[3]=c):c=t[3];let l,u,d;t[4]===n?(l=t[5],u=t[6],d=t[7]):(l=()=>ae(n,`allow_once`),u=e=>ae(n,e.scope===`project`?`allow_domain_project`:`allow_domain_session`),d=()=>ae(n,`skip`),t[4]=n,t[5]=l,t[6]=u,t[7]=d);let f;return t[8]!==o||t[9]!==c||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==a?(f=(0,$.jsx)(nu,{icon:s,promptTitle:`Allow the agent to fetch from this domain?`,skippedTitle:`Web fetch permission`,detail:c,wildcardOptions:a,secondaryButtonLabel:`Deny`,resolvedDecision:o,onAllowOnce:l,onAllowWildcard:u,onSecondary:d}),t[8]=o,t[9]=c,t[10]=l,t[11]=u,t[12]=d,t[13]=a,t[14]=f):f=t[14],f}var su=new Map,cu=new Map;function lu(e){return su.get(e)}function uu(e,t){let n=cu.get(e);return n||(n=new Set,cu.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&cu.delete(e)}}function du(e){let t=cu.get(e);if(t)for(let e of t)e()}function fu(e,t){return async function(n,r){let i=await fetch(e+`/api/browser-js/execute-tool`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threadId:t,toolName:n,params:r})});if(!i.ok){let e=await i.text();try{let t=JSON.parse(e).error||{};e=t.details||t.message||e}catch{}return{text:null,error:`Tool `+n+` failed: `+e}}let a=await i.json();return{text:a.content&&a.content[0]?a.content[0].text:null,error:null}}}function pu(e,t,n){if(su.has(e))return;su.set(e,{status:`running`}),du(e);let r=We();(async()=>{try{let i=fu(r,n),a=Object.getPrototypeOf(async function(){}).constructor,o=await new a(`callTool`,t)(i),s=o===void 0?null:o;su.set(e,{status:`success`,result:s}),du(e),await c(e,s)}catch(t){let n=t instanceof Error?t.stack||t.message:String(t);su.set(e,{status:`error`,error:n}),du(e);try{await c(e,{error:n})}catch(e){console.error(`[browser-js-executor] failed to submit error result`,e)}}})()}var mu=ei(e=>(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v2})]})}),{name:`RunWebWorkerBlock_1`,portals:[`v1`,`v2`]}),hu=ei(e=>(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[(0,$.jsxs)(`button`,{onClick:e.v0,className:e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v3}),e.v4]}),e.v5]}),{name:`RunWebWorkerBlock_2`,portals:[`v2`,`v3`,`v4`,`v5`]}),gu=ei(e=>(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[(0,$.jsxs)(`button`,{onClick:e.v0,className:e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v3}),e.v4]}),e.v5]}),{name:`RunWebWorkerBlock_3`,portals:[`v2`,`v3`,`v4`,`v5`]}),_u=function(e){let t=(0,X.c)(41),{toolCallId:n,intention:a,code:o}=e,s=Q(vu),c;t[0]===n?c=t[1]:(c=lu(n),t[0]=n,t[1]=c);let l=c,[u,d]=(0,Y.useState)(l?.status??`running`),f;t[2]===l?f=t[3]:(f=()=>{if(!l||l.status!==`success`)return null;let e=l.result;return e==null?null:typeof e==`string`?e:JSON.stringify(e,null,2)},t[2]=l,t[3]=f);let[p,m]=(0,Y.useState)(f),[h,g]=(0,Y.useState)(l?.error??null),_,v;t[4]===n?(_=t[5],v=t[6]):(_=()=>uu(n,()=>{let e=lu(n);if(e)if(d(e.status),e.status===`success`){let t=e.result;m(t==null?null:typeof t==`string`?t:JSON.stringify(t,null,2))}else e.status===`error`&&g(e.error??null)}),v=[n],t[4]=n,t[5]=_,t[6]=v),(0,Y.useEffect)(_,v);let y,b;t[7]!==o||t[8]!==s||t[9]!==n?(y=()=>{s&&pu(n,o,s)},b=[n,o,s],t[7]=o,t[8]=s,t[9]=n,t[10]=y,t[11]=b):(y=t[10],b=t[11]),(0,Y.useEffect)(y,b);let[x,S]=(0,Y.useState)(!1),C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>S(yu),t[12]=C):C=t[12];let w=C;if(u===`running`){let e,n;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=V(r.label,`w-full py-2 flex items-center gap-2`),n=(0,$.jsx)(j,{className:`h-4 w-4 shrink-0 text-brand animate-pulse`}),t[13]=e,t[14]=n):(e=t[13],n=t[14]);let i=a||`Executing Browser JS...`,o;return t[15]===i?o=t[16]:(o=(0,$.jsx)(mu,{v0:e,v1:n,v2:i}),t[15]=i,t[16]=o),o}if(u===`success`){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=V(r.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),n=(0,$.jsx)(j,{className:`h-4 w-4 shrink-0 text-brand`}),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let s=a||`Browser JS Executed Successfully`,c;t[19]===x?c=t[20]:(c=x?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[19]=x,t[20]=c);let l;t[21]!==o||t[22]!==x||t[23]!==p?(l=x&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:V(r.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:o}),p!=null&&(0,$.jsx)(`pre`,{className:V(r.body,`leading-relaxed whitespace-pre-wrap border-t border-border pt-2`),children:p})]}),t[21]=o,t[22]=x,t[23]=p,t[24]=l):l=t[24];let u;return t[25]!==s||t[26]!==c||t[27]!==l?(u=(0,$.jsx)(hu,{v0:w,v1:e,v2:n,v3:s,v4:c,v5:l}),t[25]=s,t[26]=c,t[27]=l,t[28]=u):u=t[28],u}let T,E;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(T=V(r.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),E=(0,$.jsx)(j,{className:`h-4 w-4 shrink-0 text-destructive`}),t[29]=T,t[30]=E):(T=t[29],E=t[30]);let D=a||`Browser JS Execution Failed`,O;t[31]===x?O=t[32]:(O=x?(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(Je,{className:`h-4 w-4 shrink-0`}),t[31]=x,t[32]=O);let k;t[33]!==o||t[34]!==h||t[35]!==x?(k=x&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:V(r.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:h}),(0,$.jsx)(`pre`,{className:V(r.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:o})]}),t[33]=o,t[34]=h,t[35]=x,t[36]=k):k=t[36];let A;return t[37]!==D||t[38]!==O||t[39]!==k?(A=(0,$.jsx)(gu,{v0:w,v1:T,v2:E,v3:D,v4:O,v5:k}),t[37]=D,t[38]=O,t[39]=k,t[40]=A):A=t[40],A};function vu(e){return e.selectedThreadId}function yu(e){return!e}function bu(e){let t=(0,X.c)(69),{toolCall:n,className:a}=e,o=Ia(),[s,c]=(0,Y.useState)(!1),l;t[0]===n.id?l=t[1]:(l=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=l);let u=Q(l),d=Q(wu),f=Q(Cu),p;t[2]!==n.activeDisplayName||t[3]!==n.name?(p=n.activeDisplayName??Ue(n.name),t[2]=n.activeDisplayName,t[3]=n.name,t[4]=p):p=t[4];let m=p;if(!d)return null;let h;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{c(Su)},t[5]=h):h=t[5];let g=h,_;t[6]!==o||t[7]!==f||t[8]!==n.id||t[9]!==n.name?(_=()=>{o({type:Z.StopStream});let e={type:`tool-result`,toolCallId:n.id,toolName:n.name,result:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`,isError:!0,content:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`};o({type:Z.AppendStreamChunk,chunkType:`content`,content:JSON.stringify([e]),segments:f})},t[6]=o,t[7]=f,t[8]=n.id,t[9]=n.name,t[10]=_):_=t[10];let v=_,y=xu,b=n.name===`bash`&&typeof n.input?.command==`string`?n.input.command:null,x;t[11]===b?x=t[12]:(x=b===null?null:cc(b),t[11]=b,t[12]=x);let S=x,C=n.name===`fetch`&&typeof n.input?.url==`string`?n.input.url:null,w=n.name===`web_search`&&typeof n.input?.query==`string`?n.input.query:null,E=!b&&typeof n.input?.description==`string`?n.input.description:null,D;t[13]===a?D=t[14]:(D=V(`overflow-hidden mb-2`,a),t[13]=a,t[14]=D);let O;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(Uc,{}),t[15]=O):O=t[15];let k;t[16]===m?k=t[17]:(k=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[O,(0,$.jsx)(`span`,{className:r.bodyMuted,children:m})]})}),t[16]=m,t[17]=k);let A;t[18]===n.name?A=t[19]:(A=(0,$.jsx)(T,{children:n.name}),t[18]=n.name,t[19]=A);let j;t[20]!==k||t[21]!==A?(j=(0,$.jsxs)(U,{children:[k,A]}),t[20]=k,t[21]=A,t[22]=j):j=t[22];let M;t[23]===S?M=t[24]:(M=S!==null&&(0,$.jsx)(`code`,{className:V(r.mono,r.bodyMuted,`truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:S.label}),t[23]=S,t[24]=M);let N;t[25]===C?N=t[26]:(N=C!==null&&(0,$.jsx)(`code`,{className:V(r.mono,r.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:C.length>60?`${C.slice(0,59)}…`:C}),t[25]=C,t[26]=N);let P;t[27]===w?P=t[28]:(P=w!==null&&(0,$.jsx)(`code`,{className:V(r.mono,r.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:w.length>60?`${w.slice(0,59)}…`:w}),t[27]=w,t[28]=P);let F;t[29]===E?F=t[30]:(F=E!==null&&(0,$.jsx)(`span`,{className:r.bodyMuted,children:E}),t[29]=E,t[30]=F);let I;t[31]!==b||t[32]!==E||t[33]!==C||t[34]!==w?(I=!b&&!C&&!w&&!E&&(0,$.jsx)(`span`,{className:r.bodyMuted,children:`running`}),t[31]=b,t[32]=E,t[33]=C,t[34]=w,t[35]=I):I=t[35];let L;t[36]===s?L=t[37]:(L=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:g,className:`p-1 hover:bg-muted/50 rounded transition-colors`,children:s?(0,$.jsx)(ze,{className:`h-3 w-3`}):(0,$.jsx)(i,{className:`h-3 w-3`})})}),t[36]=s,t[37]=L);let R=s?`Collapse`:`Expand`,ee;t[38]===R?ee=t[39]:(ee=(0,$.jsx)(T,{children:R}),t[38]=R,t[39]=ee);let z;t[40]!==L||t[41]!==ee?(z=(0,$.jsxs)(U,{children:[L,ee]}),t[40]=L,t[41]=ee,t[42]=z):z=t[42];let te;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(Ce,{className:`h-3 w-3`}),t[43]=te):te=t[43];let ne;t[44]===v?ne=t[45]:(ne=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:v,className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,children:te})}),t[44]=v,t[45]=ne);let re;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,$.jsx)(T,{className:`bg-red-600 text-white border-red-600`,children:`Stop this process`}),t[46]=re):re=t[46];let ie;t[47]===ne?ie=t[48]:(ie=(0,$.jsxs)(U,{children:[ne,re]}),t[47]=ne,t[48]=ie);let ae;t[49]!==z||t[50]!==ie?(ae=(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[z,ie]}),t[49]=z,t[50]=ie,t[51]=ae):ae=t[51];let oe;t[52]!==j||t[53]!==M||t[54]!==N||t[55]!==P||t[56]!==F||t[57]!==I||t[58]!==ae?(oe=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[j,M,N,P,F,I,ae]}),t[52]=j,t[53]=M,t[54]=N,t[55]=P,t[56]=F,t[57]=I,t[58]=ae,t[59]=oe):oe=t[59];let se;t[60]!==s||t[61]!==n.id||t[62]!==n.input||t[63]!==u?(se=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border min-h-[8rem] overflow-auto`,children:[(0,$.jsxs)(`div`,{className:V(r.compact,r.bodyMuted,`mb-2 font-mono`),children:[`ID: `,n.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:V(r.compact,r.label,`text-muted-foreground mb-1`),children:`Input:`}),(0,$.jsx)(`pre`,{className:Pc({className:`border border-border`}),children:y(n.input)})]}),u&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:V(r.compact,r.label,`text-muted-foreground mb-1`),children:`Progress:`}),(0,$.jsxs)(`div`,{className:V(r.body,`bg-green-50 dark:bg-green-900/20 p-2 rounded border border-green-200 dark:border-green-800`),children:[(0,$.jsx)(`div`,{className:V(r.mono,`text-green-700 dark:text-green-300`),children:u.delta}),u.partial?.content?.[0]?.arguments&&typeof u.partial.content[0].arguments==`object`&&`content`in u.partial.content[0].arguments&&typeof u.partial.content[0].arguments.content==`string`&&(0,$.jsxs)(`div`,{className:V(r.mono,`mt-1 text-green-600 dark:text-green-400`),children:[`Building: `,u.partial.content[0].arguments.content.slice(-50),u.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,$.jsxs)(`div`,{className:V(r.compact,`flex items-center gap-1.5 text-muted-foreground`),children:[(0,$.jsx)(Uc,{}),`Executing`,u&&` with progress`,`...`]})]}),t[60]=s,t[61]=n.id,t[62]=n.input,t[63]=u,t[64]=se):se=t[64];let ce;return t[65]!==oe||t[66]!==se||t[67]!==D?(ce=(0,$.jsxs)(`div`,{className:D,children:[oe,se]}),t[65]=oe,t[66]=se,t[67]=D,t[68]=ce):ce=t[68],ce}function xu(e){return JSON.stringify(e,null,2)}function Su(e){return!e}function Cu(e){return e.streamingSegments}function wu(e){return e.isStreaming}function Tu(e,t){let n=e.toLowerCase();return n===`agent`||n.includes(`subagent`)?!0:!!(t&&typeof t==`object`&&`description`in t&&(`prompt`in t||`agentName`in t))}function Eu(e){return e.type!==`subagent_event`||!e.subagentEvent?null:Du(e.subagentEvent)}function Du(e){switch(e.type){case`message`:return e.content&&e.isThinking||e.content&&!e.isThinking&&e.role!==`tool`?e.content:e.role===`tool`&&e.content?Ou(e.content):null;case`shell_permission`:{let t=e.shellPermission?.command?.trim();return t?`\n⏳ Waiting for shell approval: ${t}\n`:`
26
+ ⏳ Waiting for shell approval…
27
+ `}case`web_fetch_permission`:{let t=e.webFetchPermission?.hostname?.trim();return t?`\n⏳ Waiting for approval to fetch ${t}\n`:`
28
+ ⏳ Waiting for web fetch approval…
29
+ `}case`error`:return e.content?`\n${e.content}`:null;default:return null}}function Ou(e){try{let t=JSON.parse(e);if(!Array.isArray(t))return null;let n=[];for(let e of t)if(e.type===`tool_use`&&e.name)n.push(`\n→ ${e.name}\n`);else if(e.type===`tool-result`&&e.content){let t=typeof e.content==`string`?e.content.trim():JSON.stringify(e.content),r=t.slice(0,120);if(r){let e=t.length>120?`…`:``;n.push(`✓\n\n\`\`\`\n${r}${e}\n\`\`\`\n`)}}return n.length>0?n.join(``):null}catch{return null}}function ku(e){return{question:typeof e.question==`string`?e.question:``,options:Array.isArray(e.options)?e.options.filter(e=>typeof e==`string`):void 0,context:typeof e.context==`string`?e.context:void 0}}function Au(e){return{intention:typeof e.intention==`string`?e.intention:``,code:typeof e.code==`string`?e.code:``}}function ju(e){let t=(0,X.c)(6),{prompt:n,answeredText:r}=e,i=n.toolCallId??`long-running-confirmation`,a;return t[0]!==r||t[1]!==n.context||t[2]!==n.options||t[3]!==n.question||t[4]!==i?(a=(0,$.jsx)(Vl,{toolCallId:i,question:n.question,options:n.options,context:n.context,answeredText:r,answeredLabel:`You answered`}),t[0]=r,t[1]=n.context,t[2]=n.options,t[3]=n.question,t[4]=i,t[5]=a):a=t[5],a}function Mu(e){let t=(0,X.c)(5),{prompt:n,projectId:r}=e,i;return t[0]!==r||t[1]!==n.command||t[2]!==n.toolCallId||t[3]!==n.wildcardOptions?(i=(0,$.jsx)(iu,{toolCallId:n.toolCallId,command:n.command,projectId:r,wildcardOptions:n.wildcardOptions}),t[0]=r,t[1]=n.command,t[2]=n.toolCallId,t[3]=n.wildcardOptions,t[4]=i):i=t[4],i}function Nu(e){let t=(0,X.c)(6),{prompt:n,projectId:r}=e,i;return t[0]!==r||t[1]!==n.hostname||t[2]!==n.toolCallId||t[3]!==n.url||t[4]!==n.wildcardOptions?(i=(0,$.jsx)(ou,{toolCallId:n.toolCallId,hostname:n.hostname,url:n.url,projectId:r,wildcardOptions:n.wildcardOptions}),t[0]=r,t[1]=n.hostname,t[2]=n.toolCallId,t[3]=n.url,t[4]=n.wildcardOptions,t[5]=i):i=t[5],i}function Pu(e,t){if(e.name!==`ask_user`)return null;let n=ku(e.input);return(0,$.jsx)(Vl,{toolCallId:e.id,question:n.question,options:n.options,context:n.context,answeredText:t})}function Fu(e){if(e.name!==`run_js`&&e.name!==`run_web_worker`)return null;let t=Au(e.input);return(0,$.jsx)(_u,{toolCallId:e.id,intention:t.intention,code:t.code})}function Iu(e){let t=(0,X.c)(12),{block:n,resultContent:r}=e,i;t[0]===n.id?i=t[1]:(i=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=i);let a=Q(i),o;t[2]===a?o=t[3]:(o=a??{},t[2]=a,t[3]=o);let s;t[4]===o?s=t[5]:(s=Fl(o),t[4]=o,t[5]=s);let c=s,l=r===void 0,u=n.name===`bash`||n.name===`read`||n.name===`file_read`||Tu(n.name,n.input);if(l&&!u){let e;return t[6]===n?e=t[7]:(e=(0,$.jsx)(bu,{toolCall:n}),t[6]=n,t[7]=e),e}let d=l?c:r,f;return t[8]!==n||t[9]!==l||t[10]!==d?(f=(0,$.jsx)(bl,{inline:!0,block:n,resultContent:d,isActive:l}),t[8]=n,t[9]=l,t[10]=d,t[11]=f):f=t[11],f}function Lu(e){let t=(0,X.c)(11),{block:n,showActive:r,resultContent:i}=e,a;t[0]!==n||t[1]!==i?(a=Pu(n,i),t[0]=n,t[1]=i,t[2]=a):a=t[2];let o=a;if(o)return o;let s;t[3]===n?s=t[4]:(s=Fu(n),t[3]=n,t[4]=s);let c=s;if(c)return c;if(r){let e;return t[5]!==n||t[6]!==i?(e=(0,$.jsx)(Iu,{block:n,resultContent:i}),t[5]=n,t[6]=i,t[7]=e):e=t[7],e}let l;return t[8]!==n||t[9]!==i?(l=(0,$.jsx)(bl,{inline:!0,block:n,resultContent:i,isActive:!1}),t[8]=n,t[9]=i,t[10]=l):l=t[10],l}function Ru(e){let t=(0,X.c)(3),{block:n,sequence:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(El,{inline:!0,sequence:r,block:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function zu(e){if(ba(e)){let t=e.text.slice(0,128);return`thinking-${e.label??`none`}-${Pl(t)}`}switch(e.type){case`tool_use`:return`tool-${e.id}`;case`tool-result`:return`result-${e.toolCallId}`;case`long_running_confirmation`:return`lrc-${e.prompt.toolCallId??Pl(e.prompt.question)}`;case`shell_permission`:return`shell-${e.prompt.toolCallId}`;case`web_fetch_permission`:return`fetch-${e.prompt.toolCallId}`;case`text`:return`text-${Pl(e.text.slice(0,128))}`}}function Bu(e,t,n){let{lookupBlocks:r,isStreaming:i,threadId:a,projectId:o,messageIndex:s}=n;if(ta(e)&&e.name===`todo`)return null;if(na(e)){if(e.toolName===`todo`)return(0,$.jsx)(Ru,{sequence:s,block:e},t);if(e.toolName===`ask_user`)return null}switch(e.type){case`long_running_confirmation`:return(0,$.jsx)(ju,{prompt:e.prompt,answeredText:Rl(r,e.prompt.toolCallId)},t);case`shell_permission`:return(0,$.jsx)(Mu,{prompt:e.prompt,projectId:o},t);case`web_fetch_permission`:return(0,$.jsx)(Nu,{prompt:e.prompt,projectId:o},t);case`text`:return(0,$.jsx)(Ms,{content:e.text,threadId:a},t);case`tool_use`:{let n=Il(r,e.id);return(0,$.jsx)(Lu,{block:e,showActive:i&&!Ll(r,e.id),resultContent:n},t)}case`tool-result`:return(0,$.jsx)(Ru,{block:e},t)}}function Vu(e){let t=(0,X.c)(8),{blocks:n,isStreaming:r,threadId:i,projectId:a,messageIndex:o}=e,s=r===void 0?!1:r,c=o===void 0?0:o,l;t[0]!==n||t[1]!==s||t[2]!==c||t[3]!==a||t[4]!==i?(l=xa(n,s).map(e=>{let t=zu(e);return ba(e)?(0,$.jsx)(Al,{text:e.text,label:e.label,isStreaming:e.isCurrentlyStreaming,threadId:i},t):Bu(e,t,{lookupBlocks:n,isStreaming:s,threadId:i,projectId:a,messageIndex:c})}),t[0]=n,t[1]=s,t[2]=c,t[3]=a,t[4]=i,t[5]=l):l=t[5];let u;return t[6]===l?u=t[7]:(u=(0,$.jsx)($.Fragment,{children:l}),t[6]=l,t[7]=u),u}var Hu=ei(e=>(0,$.jsx)(`div`,{className:e.v0,children:(0,$.jsxs)(`div`,{className:e.v1,children:[e.v2,(0,$.jsx)(`div`,{className:e.v3,children:e.v4}),e.v5,e.v6]})}),{name:`ChatMessage_1`,portals:[`v2`,`v4`,`v5`,`v6`]}),Uu=function(e){let t=(0,X.c)(37),{message:n,threadId:r,messageIndex:i,showCheckpointRestore:a,checkpointRestoreTooltip:o}=e,s=i===void 0?0:i,c=a===void 0?!1:a,l=n.sender===`user`,u;t[0]!==l||t[1]!==n.content?(u=l?null:da(n.content),t[0]=l,t[1]=n.content,t[2]=u):u=t[2];let d=u,f;t[3]!==n.content||t[4]!==n.isThinking?(f=n.isThinking?ia(n.content):null,t[3]=n.content,t[4]=n.isThinking,t[5]=f):f=t[5];let p=f,m=l&&`flex justify-end`,h;t[6]===m?h=t[7]:(h=V(`group px-4 py-4`,m),t[6]=m,t[7]=h);let g=l&&`items-end`,_;t[8]===g?_=t[9]:(_=V(`flex flex-col gap-1 min-w-0 max-w-full`,g),t[8]=g,t[9]=_);let v;t[10]!==o||t[11]!==n||t[12]!==c||t[13]!==r?(v=(0,$.jsx)(Hs,{message:n,threadId:r,showCheckpointRestore:c,checkpointRestoreTooltip:o}),t[10]=o,t[11]=n,t[12]=c,t[13]=r,t[14]=v):v=t[14];let y=l&&`rounded-xl px-4 py-3 bg-foreground text-background`,b;t[15]===y?b=t[16]:(b=V(`flex flex-col gap-0.5 min-w-0 text-base`,y),t[15]=y,t[16]=b);let x;t[17]!==n||t[18]!==s||t[19]!==d||t[20]!==p||t[21]!==r?(x=(0,$.jsx)(Wu,{message:n,threadId:r,messageIndex:s,structuredContent:d,thinkingBlocks:p}),t[17]=n,t[18]=s,t[19]=d,t[20]=p,t[21]=r,t[22]=x):x=t[22];let S;t[23]!==n.generatedImageData||t[24]!==n.generatedImageUrl||t[25]!==r?(S=(n.generatedImageUrl||n.generatedImageData)&&(0,$.jsx)(Us,{src:n.generatedImageData?`data:image/png;base64,${n.generatedImageData}`:n.generatedImageUrl,threadId:r}),t[23]=n.generatedImageData,t[24]=n.generatedImageUrl,t[25]=r,t[26]=S):S=t[26];let C;t[27]===n.attachments?C=t[28]:(C=n.attachments&&n.attachments.length>0&&(0,$.jsx)(Ls,{attachments:n.attachments}),t[27]=n.attachments,t[28]=C);let w;return t[29]!==b||t[30]!==x||t[31]!==S||t[32]!==C||t[33]!==h||t[34]!==_||t[35]!==v?(w=(0,$.jsx)(Hu,{v0:h,v1:_,v2:v,v3:b,v4:x,v5:S,v6:C}),t[29]=b,t[30]=x,t[31]=S,t[32]=C,t[33]=h,t[34]=_,t[35]=v,t[36]=w):w=t[36],w};function Wu(e){let t=(0,X.c)(14),{message:n,threadId:i,messageIndex:a,structuredContent:o,thinkingBlocks:s}=e;if(n.isThinking){if(s?.length){let e;return t[0]!==s||t[1]!==i?(e=(0,$.jsx)(Vu,{blocks:s,threadId:i}),t[0]=s,t[1]=i,t[2]=e):e=t[2],e}let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=V(r.bodyMuted,`leading-relaxed whitespace-pre-wrap`),t[3]=e):e=t[3];let a;return t[4]!==n.content||t[5]!==i?(a=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(Ms,{content:n.content,threadId:i})}),t[4]=n.content,t[5]=i,t[6]=a):a=t[6],a}if(o){let e;return t[7]!==a||t[8]!==o||t[9]!==i?(e=(0,$.jsx)(Vu,{blocks:o,threadId:i,messageIndex:a}),t[7]=a,t[8]=o,t[9]=i,t[10]=e):e=t[10],e}let c;return t[11]!==n.content||t[12]!==i?(c=(0,$.jsx)(Ms,{content:n.content,threadId:i,className:r.body}),t[11]=n.content,t[12]=i,t[13]=c):c=t[13],c}function Gu(e){let t=(0,Y.useRef)(new Map);return(0,Y.useMemo)(()=>{let n=t.current,r=[],i=new Set;for(let t of e){if(i.add(t),t.type===`long_running_confirmation`){r.push({type:`long_running_confirmation`,prompt:t.prompt});continue}if(t.type===`shell_permission`){r.push({type:`shell_permission`,prompt:t.prompt});continue}if(t.type===`web_fetch_permission`){r.push({type:`web_fetch_permission`,prompt:t.prompt});continue}let e=n.get(t);if(e&&e.chunks===t.chunks){r.push(...e.blocks);continue}let a=t.chunks.join(``),o;o=t.type===`thinking`?ia(a)??[]:da(a)??(a.trim()?[{type:`text`,text:a}]:[]),n.set(t,{chunks:t.chunks,blocks:o}),r.push(...o)}for(let e of n.keys())i.has(e)||n.delete(e);return r},[e])}var Ku=ei(e=>(0,$.jsx)(`div`,{className:e.v0,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:e.v1,children:`Agent`}),e.v2]}),e.v3]})}),{name:`StreamingMessage_1`,portals:[`v2`,`v3`]}),qu=function(e){let t=(0,X.c)(16),{segments:n,model:i,threadId:a,projectId:o,isCreatingProject:s,isProcessingThread:c,totalMessages:l,showProcessingLine:u}=e,d=l===void 0?0:l,f=u===void 0?!1:u,p=Gu(n),m=f?`pb-0`:`pb-4`,h;t[0]===m?h=t[1]:(h=V(`group px-4 pt-4`,m),t[0]=m,t[1]=h);let g;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(g=V(r.compact,`font-medium text-foreground`),t[2]=g):g=t[2];let _;t[3]===i?_=t[4]:(_=i&&(0,$.jsxs)(`span`,{className:V(r.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(j,{className:`h-2.5 w-2.5`}),hi(i)]}),t[3]=i,t[4]=_);let v;t[5]!==s||t[6]!==c||t[7]!==p||t[8]!==o||t[9]!==a||t[10]!==d?(v=p.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 min-w-0 text-base`,children:(0,$.jsx)(Vu,{blocks:p,isStreaming:!0,threadId:a,projectId:o,messageIndex:d})}):s||c?(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(Al,{isStreaming:!0})}):null,t[5]=s,t[6]=c,t[7]=p,t[8]=o,t[9]=a,t[10]=d,t[11]=v):v=t[11];let y;return t[12]!==h||t[13]!==_||t[14]!==v?(y=(0,$.jsx)(Ku,{v0:h,v1:g,v2:_,v3:v}),t[12]=h,t[13]=_,t[14]=v,t[15]=y):y=t[15],y},Ju=3e3;function Yu(e){let t=[...rn],n=e?t.filter(t=>t!==e):t;return n[Math.floor(Math.random()*n.length)]}function Xu(e){let t=(0,X.c)(3),[n,r]=(0,Y.useState)($e),i=(0,Y.useRef)($e),a,o;return t[0]===e?(a=t[1],o=t[2]):(a=()=>{if(!e){r($e),i.current=$e;return}let t=setInterval(()=>{let e=i.current===`Processing...`?Yu():Yu(i.current);i.current=e,r(e)},Ju);return()=>clearInterval(t)},o=[e],t[0]=e,t[1]=a,t[2]=o),(0,Y.useEffect)(a,o),n}function Zu(e){let t=(0,X.c)(8),{active:n,className:i}=e,a=n===void 0?!0:n,o=Xu(a),s=a?`animate-shimmer`:void 0,c;t[0]===s?c=t[1]:(c=V(r.caption,s),t[0]=s,t[1]=c);let l;t[2]!==o||t[3]!==c?(l=(0,$.jsx)(`span`,{className:c,children:o}),t[2]=o,t[3]=c,t[4]=l):l=t[4];let u;return t[5]!==i||t[6]!==l?(u=(0,$.jsx)(`div`,{className:i,"aria-live":`polite`,"aria-busy":`true`,children:l}),t[5]=i,t[6]=l,t[7]=u):u=t[7],u}var Qu=ei(e=>(0,$.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-1 flex-col items-center gap-8 overflow-y-auto px-4 py-8`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`h1`,{className:e.v0,children:`Let's build it!`}),(0,$.jsx)(`p`,{className:e.v1,children:e.v2})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[e.v3,(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v4,children:[e.v5,(0,$.jsx)(`span`,{className:e.v6,children:`Connect a repo`}),(0,$.jsx)(`span`,{className:e.v7,children:`Clone an existing repository`})]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v8,children:[e.v9,(0,$.jsx)(`span`,{className:e.v10,children:`New App`}),(0,$.jsx)(`span`,{className:e.v11,children:`Create a new project from template`})]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v12,children:[e.v13,(0,$.jsx)(`span`,{className:e.v14,children:`Open Folder`}),(0,$.jsx)(`span`,{className:e.v15,children:`Use an existing local folder`})]})]})]}),{name:`WelcomeScreen_1`,portals:[`v2`,`v3`,`v5`,`v9`,`v13`]}),$u=function(e){let t=(0,X.c)(17),{projects:n,onSelectProject:i,onCreateThread:a,onConnectRepo:o,onNewApp:s,onOpenFolder:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=V(r.pageTitle,`tracking-tight text-balance`),t[0]=l):l=t[0];let u=n.length===0?`Start or connect your first project`:`Select a project to start coding`,d;if(t[1]!==a||t[2]!==i||t[3]!==n){let e;t[5]!==a||t[6]!==i?(e=e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:()=>{e.threads.length===0?a(e.projectId):i(e.projectId,e.threads[0].threadId)},children:[(0,$.jsx)(Ht,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`${r.body} text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:r.caption,children:[e.threads.length,` thread`,e.threads.length===1?``:`s`]})]},e.projectId),t[5]=a,t[6]=i,t[7]=e):e=t[7],d=n.map(e),t[1]=a,t[2]=i,t[3]=n,t[4]=d}else d=t[4];let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(x,{className:`h-5 w-5 text-muted-foreground`}),t[8]=f):f=t[8];let p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(wn,{className:`h-5 w-5 text-muted-foreground`}),t[9]=p):p=t[9];let m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(H,{className:`h-5 w-5 text-muted-foreground`}),t[10]=m):m=t[10];let h;return t[11]!==o||t[12]!==s||t[13]!==c||t[14]!==u||t[15]!==d?(h=(0,$.jsx)(Qu,{v0:l,v1:`mt-1 ${r.pageSubtitle}`,v2:u,v3:d,v4:o,v5:f,v6:`${r.body} text-foreground leading-snug font-medium`,v7:r.caption,v8:s,v9:p,v10:`${r.body} text-foreground leading-snug font-medium`,v11:r.caption,v12:c,v13:m,v14:`${r.body} text-foreground leading-snug font-medium`,v15:r.caption}),t[11]=o,t[12]=s,t[13]=c,t[14]=u,t[15]=d,t[16]=h):h=t[16],h},ed=(0,Y.createContext)(null);function td(e){let t=(0,X.c)(7),{children:n}=e,[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l;t[0]!==s||t[1]!==a||t[2]!==r?(l={devServerUrl:r,setDevServerUrl:i,devServerRunning:a,setDevServerRunning:o,devServerLoading:s,setDevServerLoading:c},t[0]=s,t[1]=a,t[2]=r,t[3]=l):l=t[3];let u=l,d;return t[4]!==n||t[5]!==u?(d=(0,$.jsx)(ed.Provider,{value:u,children:n}),t[4]=n,t[5]=u,t[6]=d):d=t[6],d}function nd(){let e=(0,Y.useContext)(ed);if(!e)throw Error(`useDevServer must be used within a DevServerProvider`);return e}function rd(e){e.onTerminalMessage?.(`✓ Server running at: ${e.url}`),e.setDevServerUrl(e.url),e.setActiveMainTab(`browser`)}function id(e){return typeof e==`object`&&!!e&&e.type===`url`&&typeof e.url==`string`}function ad(){let e=Q(e=>e.selectedThreadId),{dispatch:t}=La(e),{setActiveMainTab:n}=Js(),{setDevServerUrl:r,setDevServerRunning:i,setDevServerLoading:a}=nd();return{startServer:async o=>{if(!o?.runCommand||!o?.projectId)return;a(!0),t({type:Z.ClearTerminalOutput}),t({type:Z.SetTerminalOpen,open:!1}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Starting dev server: ${o.runCommand}`}});let s=!1,c=setTimeout(()=>{s=!0,t({type:Z.SetTerminalOpen,open:!0})},3e3);try{let l=await Te(o.projectId,e??void 0);if(!l){clearTimeout(c),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}}),a(!1);return}let u=l.getReader(),d=new TextDecoder;i(!0),a(!1);let f=!1,p=!1;for(;;){let{done:e,value:i}=await u.read();if(e)break;let o=d.decode(i,{stream:!0});try{let e=o.split(`
30
+ `).filter(e=>e.trim());for(let i of e)try{let e=JSON.parse(i);p||(p=!0,a(!1)),id(e)&&e.url&&(clearTimeout(c),rd({url:e.url,setDevServerUrl:r,setActiveMainTab:n,onTerminalMessage:e=>{t({type:Z.AppendTerminalLine,line:{type:`system`,content:e}})}}),s&&setTimeout(()=>{t({type:Z.SetTerminalOpen,open:!1})},100),f=!0)}catch{}}catch{}}f||t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server is running but URL could not be detected`}})}catch(e){console.error(`Failed to start dev server:`,e),a(!1),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}})}},setServerUrl:r}}var od=3e4,sd=2e3;function cd(e){let{devServerRunning:t,setDevServerRunning:n,devServerLoading:r}=nd(),i=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{e&&(i.current=!1,(async()=>{try{n((await hn(e)).isRunning)}catch{n(!1)}finally{i.current=!0}})())},[e,n]),(0,Y.useEffect)(()=>{if(!e||!r)return;let t=Date.now(),i=setInterval(()=>{if(Date.now()-t>od){clearInterval(i);return}hn(e).then(e=>{e.isRunning&&(n(!0),clearInterval(i))}).catch(()=>{})},sd);return()=>clearInterval(i)},[e,r,n]),{isRunning:t,isLoading:r,recheck:(0,Y.useCallback)(async()=>{if(e)try{n((await hn(e)).isRunning)}catch{n(!1)}},[e,n])}}var ld=ei(e=>(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 px-4`,children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`h1`,{className:e.v0,children:e.v1}),(0,$.jsx)(`p`,{className:e.v2,children:e.v3})]}),e.v4]})}),{name:`ChatMessagesPlaceholder_1`,portals:[`v1`,`v3`,`v4`]}),ud=function(e){let t=(0,X.c)(14),{project:n}=e,{isRunning:i}=cd(n?.projectId),{startServer:a}=ad();n?.name;let o=n?.name??`your project`,s;t[0]===o?s=t[1]:(s=dd(o),t[0]=o,t[1]=s);let c=s,l=!i&&n?.runCommand,u;t[2]!==n||t[3]!==a?(u=()=>{n&&a(n)},t[2]=n,t[3]=a,t[4]=u):u=t[4];let d=u,f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=V(r.pageTitle,`tracking-tight text-foreground text-balance`),t[5]=f):f=t[5];let p=n?.name??`Project`,m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=V(r.pageSubtitle,`mt-2`),t[6]=m):m=t[6];let h;t[7]!==d||t[8]!==l?(h=l&&(0,$.jsx)(`button`,{type:`button`,onClick:d,className:V(r.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground hover:bg-primary/90 transition-colors`),children:`Start App`}),t[7]=d,t[8]=l,t[9]=h):h=t[9];let g;return t[10]!==c||t[11]!==p||t[12]!==h?(g=(0,$.jsx)(ld,{v0:f,v1:p,v2:m,v3:c,v4:h}),t[10]=c,t[11]=p,t[12]=h,t[13]=g):g=t[13],g};function dd(e){let t=[`What would you like to add to ${e}?`,`What should we build in ${e}?`,`What changes do you want to make to ${e}?`,`What feature should we add to ${e}?`,`What would you like to fix in ${e}?`,`What are we working on in ${e}?`,`What's next for ${e}?`,`What should we improve in ${e}?`,`How can we make ${e} better?`,`What would you like to change in ${e}?`,`What should we ship in ${e} next?`];return t[Math.floor(Math.random()*t.length)]}function fd({virtuosoRef:e,selectedThreadId:t,messagesLoaded:n,messageCount:r,isStreaming:i,hasPendingMessage:a,streamingSegmentCount:o}){let s=(0,Y.useRef)(0),c=(0,Y.useRef)(!1),u=(0,Y.useRef)(!1),d=(0,Y.useRef)(!1),f=(0,Y.useRef)(0),p=(0,Y.useRef)(null),m=(0,Y.useCallback)(()=>{t&&e.current?.getState(e=>{l(t,e.scrollTop)})},[t,e]),h=(0,Y.useRef)(m);h.current=m;function g(){d.current&&h.current()}(0,Y.useEffect)(()=>{function e(){g()}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[t]),(0,Y.useEffect)(()=>{let e=setInterval(()=>{g()},5e3);return()=>clearInterval(e)},[t]),(0,Y.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,Y.useEffect)(()=>{u.current=!1,d.current=!1,s.current=0},[t]),(0,Y.useEffect)(()=>{if(!t||!n||r===0||u.current)return;u.current=!0,s.current=r;let i=ot(t);if(i!==null&&i>0){requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.current?.scrollTo({top:i,behavior:`auto`}),d.current=!0})});return}d.current=!0},[t,n,r,e]),(0,Y.useEffect)(()=>{if(!u.current)return;let t=r>s.current,n=c.current&&!i;if(i||a||t||n){f.current&&cancelAnimationFrame(f.current);let t=n?`smooth`:`auto`;f.current=requestAnimationFrame(()=>{e.current?.scrollTo({top:2**53-1,behavior:t}),f.current=0})}return s.current=r,c.current=i,()=>{f.current&&=(cancelAnimationFrame(f.current),0)}},[i,a,r,o,e]);function _(){p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{g(),p.current=null},150)}function v(e){e||g()}return{onRangeChanged:_,onScrollingStateChange:v}}var pd=(0,Y.createContext)(void 0);function md(e){let t=(0,X.c)(12),{paneId:n,conversationId:r,fillPane:i,children:a}=e,o=i===void 0?!1:i,s=Ia(),c=Q(hd),l;t[0]!==s||t[1]!==n?(l=()=>{s({type:Z.SetFocusedPane,paneId:n})},t[0]=s,t[1]=n,t[2]=l):l=t[2];let u=l,d=c===n,f;t[3]!==r||t[4]!==o||t[5]!==n||t[6]!==u||t[7]!==d?(f={paneId:n,conversationId:r,isFocused:d,fillPane:o,setFocused:u},t[3]=r,t[4]=o,t[5]=n,t[6]=u,t[7]=d,t[8]=f):f=t[8];let p=f,m;return t[9]!==a||t[10]!==p?(m=(0,$.jsx)(pd.Provider,{value:p,children:a}),t[9]=a,t[10]=p,t[11]=m):m=t[11],m}function hd(e){return e.focusedPane}function gd(){let e=(0,X.c)(1),t=(0,Y.useContext)(pd);if(t===void 0){let t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={paneId:`primary`,conversationId:void 0,isFocused:!0,fillPane:!1,setFocused:_d},e[0]=t):t=e[0],t}return t}function _d(){}var vd=`md:mr-4`;function yd(e){return e?`w-full min-w-0 px-4`:`mx-auto max-w-3xl w-full min-w-0`}function bd(e,t){return e?V(`relative w-full min-w-0 pl-4`,vd):V(`relative mx-auto max-w-3xl`,t?`w-full min-w-0`:`w-[90vw] min-w-[400px]`)}function xd(e,t){return t?`absolute inset-x-0 bottom-0 mx-auto w-full max-w-3xl max-md:px-2 px-4 pb-4 pointer-events-none`:e?`relative w-full min-w-0 pb-2 md:pb-4`:V(`relative mx-auto w-full max-w-3xl max-md:px-0 pb-2 md:pl-4 md:pb-4 md:-ml-[6px]`,vd)}function Sd(e){return e.isCreatingProject||e.streamingSegmentCount>0?!0:e.lastMessageSender===`user`}function Cd(e){if(e.isUser)return e.hasCheckpointRef?e.isStreaming||e.hasPendingMessage||e.isCreatingProject||e.isProcessingThread?`Restore unavailable while this thread is still processing.`:`Restore checkpoint`:`Restore unavailable: no checkpoint was created for this prompt.`}function wd(e){return{bottomInset:e.bottomInset,columnClassName:e.columnClassName,isStreaming:e.isStreaming,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread,hasPendingMessage:e.hasPendingMessage,hasActiveBlockingPrompt:wa(e.streamingSegments),selectedProjectId:e.selectedProjectId,selectedThreadId:e.selectedThreadId,streamingSegments:e.streamingSegments,streamingModel:e.streamingModel,totalMessages:e.totalMessages,lastMessageSender:e.lastMessageSender,error:e.error,onClearError:e.onClearError,showCheckpointRestore:t=>t.sender===`user`&&!!t.checkpointRef&&!e.isStreaming&&!e.hasPendingMessage&&!e.isCreatingProject&&!e.isProcessingThread,getCheckpointTooltip:t=>Cd({isUser:t.sender===`user`,hasCheckpointRef:!!t.checkpointRef,isStreaming:e.isStreaming,hasPendingMessage:e.hasPendingMessage,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread})}}function Td(e){let t=(0,Y.forwardRef)((t,n)=>{let r=(0,X.c)(9),i,a,o;r[0]===t?(i=r[1],a=r[2],o=r[3]):({style:o,children:i,...a}=t,r[0]=t,r[1]=i,r[2]=a,r[3]=o);let s;return r[4]!==i||r[5]!==a||r[6]!==n||r[7]!==o?(s=(0,$.jsx)(`div`,{ref:n,style:o,...a,className:e,children:i}),r[4]=i,r[5]=a,r[6]=n,r[7]=o,r[8]=s):s=r[8],s});return t.displayName=`MessageList`,t}function Ed(e){let t=(0,X.c)(28),{context:n}=e;if(!n)return null;let{bottomInset:i,isStreaming:a,isCreatingProject:o,isProcessingThread:s,hasPendingMessage:c,hasActiveBlockingPrompt:l,selectedProjectId:u,selectedThreadId:d,streamingSegments:f,streamingModel:p,totalMessages:m,lastMessageSender:h,error:g,onClearError:_}=n,v=f.length>0||o||s&&(a||c),y;t[0]!==o||t[1]!==h||t[2]!==f.length?(y=Sd({isCreatingProject:o,streamingSegmentCount:f.length,lastMessageSender:h}),t[0]=o,t[1]=h,t[2]=f.length,t[3]=y):y=t[3];let b=y,x=v&&(a||o||s)&&b,S=(a||c)&&!l&&b,C;t[4]===i?C=t[5]:(C={paddingBottom:i},t[4]=i,t[5]=C);let w;t[6]!==o||t[7]!==s||t[8]!==u||t[9]!==d||t[10]!==x||t[11]!==S||t[12]!==p||t[13]!==f||t[14]!==m?(w=x&&(0,$.jsx)(qu,{segments:f,model:p,threadId:d,projectId:u,isCreatingProject:o,isProcessingThread:s,totalMessages:m,showProcessingLine:S}),t[6]=o,t[7]=s,t[8]=u,t[9]=d,t[10]=x,t[11]=S,t[12]=p,t[13]=f,t[14]=m,t[15]=w):w=t[15];let T;t[16]!==x||t[17]!==S?(T=S&&(0,$.jsx)(`div`,{className:V(`px-4 pb-4`,x?`pt-0`:`pt-2`),children:(0,$.jsx)(Zu,{active:S})}),t[16]=x,t[17]=S,t[18]=T):T=t[18];let E;t[19]!==g||t[20]!==_?(E=g&&(0,$.jsxs)(`div`,{className:`mx-4 my-2`,children:[(0,$.jsx)(di,{variant:`error`,className:`mb-0`,children:g}),(0,$.jsx)(`button`,{type:`button`,className:V(r.compact,`mt-1 text-destructive underline underline-offset-2 hover:text-destructive/80`),onClick:_,children:`Dismiss`})]}),t[19]=g,t[20]=_,t[21]=E):E=t[21];let D;return t[22]!==n.columnClassName||t[23]!==C||t[24]!==w||t[25]!==T||t[26]!==E?(D=(0,$.jsxs)(`div`,{className:n.columnClassName,style:C,children:[w,T,E]}),t[22]=n.columnClassName,t[23]=C,t[24]=w,t[25]=T,t[26]=E,t[27]=D):D=t[27],D}function Dd(e,t,n){return(0,$.jsx)(Uu,{message:t,threadId:n.selectedThreadId,messageIndex:e,showCheckpointRestore:n.showCheckpointRestore(t),checkpointRestoreTooltip:n.getCheckpointTooltip(t)})}var Od=(0,Y.forwardRef)(function(e,t){let n=(0,X.c)(56),{bottomInset:r,messages:i,isStreaming:a,streamingSegments:o,streamingModel:s,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,selectedThreadId:d,selectedProjectId:f,projects:p,projectsLoading:m,messagesLoaded:h,onSelectThread:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b,error:x,onClearError:S,onAtBottomChange:C,hideEmptyState:w}=e,T=r===void 0?0:r,E=w===void 0?!1:w,{fillPane:D}=gd(),O;n[0]===D?O=n[1]:(O=yd(D),n[0]=D,n[1]=O);let k=O,A=(0,Y.useRef)(null),j;n[2]===k?j=n[3]:(j=Td(k),n[2]=k,n[3]=j);let M;n[4]===j?M=n[5]:(M={List:j,Footer:Ed},n[4]=j,n[5]=M);let N=M,P;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(P=()=>({scrollToBottom:()=>{A.current?.scrollTo({top:2**53-1,behavior:`smooth`})}}),n[6]=P):P=n[6],(0,Y.useImperativeHandle)(t,P);let F;n[7]!==u||n[8]!==a||n[9]!==i.length||n[10]!==h||n[11]!==d||n[12]!==o.length?(F={virtuosoRef:A,selectedThreadId:d,messagesLoaded:h,messageCount:i.length,isStreaming:a,hasPendingMessage:u,streamingSegmentCount:o.length},n[7]=u,n[8]=a,n[9]=i.length,n[10]=h,n[11]=d,n[12]=o.length,n[13]=F):F=n[13];let{onRangeChanged:I,onScrollingStateChange:L}=fd(F),R=!E&&i.length===0&&!a&&!c&&!d,ee=!E&&h&&i.length===0&&!a&&!c&&!l&&!u&&d,z;if(n[14]!==p||n[15]!==f){let e;n[17]===f?e=n[18]:(e=e=>e.projectId===f,n[17]=f,n[18]=e),z=p.find(e),n[14]=p,n[15]=f,n[16]=z}else z=n[16];let te=z,ne=i.length>0?i[i.length-1].sender:null,re;n[19]!==T||n[20]!==k||n[21]!==x||n[22]!==u||n[23]!==c||n[24]!==l||n[25]!==a||n[26]!==ne||n[27]!==i.length||n[28]!==S||n[29]!==f||n[30]!==d||n[31]!==s||n[32]!==o?(re=wd({bottomInset:T,columnClassName:k,isStreaming:a,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,streamingSegments:o,selectedProjectId:f,selectedThreadId:d,streamingModel:s,totalMessages:i.length,lastMessageSender:ne,error:x,onClearError:S}),n[19]=T,n[20]=k,n[21]=x,n[22]=u,n[23]=c,n[24]=l,n[25]=a,n[26]=ne,n[27]=i.length,n[28]=S,n[29]=f,n[30]=d,n[31]=s,n[32]=o,n[33]=re):re=n[33];let ie=re;if(R){let e=`flex-1 transition-opacity duration-500 ease-in-out ${m?`opacity-0`:`opacity-100`}`,t;n[34]!==v||n[35]!==_||n[36]!==y||n[37]!==b||n[38]!==g||n[39]!==p?(t=(0,$.jsx)($u,{projects:p,onSelectProject:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b}),n[34]=v,n[35]=_,n[36]=y,n[37]=b,n[38]=g,n[39]=p,n[40]=t):t=n[40];let r;return n[41]!==e||n[42]!==t?(r=(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center overflow-hidden`,children:(0,$.jsx)(`div`,{className:e,children:t})}),n[41]=e,n[42]=t,n[43]=r):r=n[43],r}if(ee){let e;return n[44]===te?e=n[45]:(e=(0,$.jsx)(ud,{project:te}),n[44]=te,n[45]=e),e}let B;n[46]===Symbol.for(`react.memo_cache_sentinel`)?(B=V(`h-full overflow-hidden`),n[46]=B):B=n[46];let ae=d??void 0,oe;n[47]===Symbol.for(`react.memo_cache_sentinel`)?(oe={height:`100%`},n[47]=oe):oe=n[47];let se;return n[48]!==i||n[49]!==C||n[50]!==I||n[51]!==L||n[52]!==ae||n[53]!==N||n[54]!==ie?(se=(0,$.jsx)(`div`,{className:B,children:(0,$.jsx)(Fr,{ref:A,style:oe,data:i,computeItemKey:kd,context:ie,itemContent:Dd,overscan:500,components:N,atBottomStateChange:C,rangeChanged:I,isScrolling:L},ae)}),n[48]=i,n[49]=C,n[50]=I,n[51]=L,n[52]=ae,n[53]=N,n[54]=ie,n[55]=se):se=n[55],se});function kd(e,t){return t.messageId}var Ad={onboarding:{status:()=>[`onboarding`,`status`]},app:{update:()=>[`app`,`update`]},models:{enabled:e=>[`models`,`enabled`,e]},userTasks:e=>[`user-tasks`,e]};function jd(e){let t=(0,X.c)(10),r;t[0]===e?r=t[1]:(r=Ad.models.enabled(e),t[0]=e,t[1]=r);let i;t[2]===r?i=t[3]:(i={queryKey:r,queryFn:n,placeholderData:qr},t[2]=r,t[3]=i);let a=Wr(i),o;bb0:{if(!a.data){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],o=e;break bb0}let e;t[5]===a.data?e=t[6]:(e=Object.values(a.data).flat(),t[5]=a.data,t[6]=e),o=e}let s=o,c;return t[7]!==s||t[8]!==a?(c={...a,models:s},t[7]=s,t[8]=a,t[9]=c):c=t[9],c}function Md(e,t){return t===`secondary`?`${e}:secondary`:e}function Nd(e){let t=(0,X.c)(117),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{initialValue:r}=n,i=Ia(),{paneId:a}=gd(),o=Q(Ud),s=Q(Hd),c=Q(Vd),l=Q(Bd),u=Q(zd),d=Q(Rd),f=Q(Ld),p=Q(Id),{models:m,isFetched:h}=jd(d),g;t[2]!==u||t[3]!==r||t[4]!==a||t[5]!==o?(g=()=>{if(o){let e=Md(o,a);if(u[e])return u[e]}return r??``},t[2]=u,t[3]=r,t[4]=a,t[5]=o,t[6]=g):g=t[6];let[_,v]=(0,Y.useState)(g),[y,b]=(0,Y.useState)(-1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)(0),T=(0,Y.useRef)(_),D,O;t[7]===_?(D=t[8],O=t[9]):(D=()=>{T.current=_},O=[_],t[7]=_,t[8]=D,t[9]=O),(0,Y.useEffect)(D,O);let k=(0,Y.useRef)(u),A,j;t[10]===u?(A=t[11],j=t[12]):(A=()=>{k.current=u},j=[u],t[10]=u,t[11]=A,t[12]=j),(0,Y.useEffect)(A,j);let M=(0,Y.useRef)(!0),N,P;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(N=()=>(M.current=!0,()=>{M.current=!1}),P=[],t[13]=N,t[14]=P):(N=t[13],P=t[14]),(0,Y.useEffect)(N,P);let F;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(F=[],t[15]=F):F=t[15];let[I,L]=(0,Y.useState)(F),R;t[16]!==l||t[17]!==o?(R=()=>(o?l[o]:void 0)??null,t[16]=l,t[17]=o,t[18]=R):R=t[18];let[ee,z]=(0,Y.useState)(R),te=(0,Y.useRef)(ee?.id??``),ne=(0,Y.useRef)(ee?.provider??``),re=(0,Y.useRef)(null),[ie,B]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(!1),se;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(se=[],t[19]=se):se=t[19];let[ce,V]=(0,Y.useState)(se),[le,ue]=(0,Y.useState)(!1),[de,fe]=(0,Y.useState)(!1),[H,pe]=(0,Y.useState)(!1),me;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(me=[],t[20]=me):me=t[20];let[he,ge]=(0,Y.useState)(me),[U,ve]=(0,Y.useState)(null),ye;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(ye=[],t[21]=ye):ye=t[21];let[be,xe]=(0,Y.useState)(ye),[Se,Ce]=(0,Y.useState)(!1),[W,we]=(0,Y.useState)(``),[Te,Ee]=(0,Y.useState)(0),De;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(De=[],t[22]=De):De=t[22];let[Oe,Ae]=(0,Y.useState)(De),je;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(je=[],t[23]=je):je=t[23];let[Me,Ne]=(0,Y.useState)(je),Pe;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(Pe=[],t[24]=Pe):Pe=t[24];let[Fe,Ie]=(0,Y.useState)(Pe),[Le,Re]=(0,Y.useState)(!1),[ze,Be]=(0,Y.useState)(!1),[Ve,He]=(0,Y.useState)(``),Ue=(0,Y.useRef)(null),We=(0,Y.useRef)(null),Ge=(0,Y.useRef)(null),Ke=(0,Y.useRef)(null),qe=(0,Y.useRef)(null),Je=(0,Y.useRef)(null),Ye;t[25]!==ee?.id||t[26]!==ee?.provider?(Ye=()=>{te.current=ee?.id??``,ne.current=ee?.provider??``},t[25]=ee?.id,t[26]=ee?.provider,t[27]=Ye):Ye=t[27];let Xe=ee?.id,Ze=ee?.provider,Qe;t[28]!==Xe||t[29]!==Ze?(Qe=[Xe,Ze],t[28]=Xe,t[29]=Ze,t[30]=Qe):Qe=t[30],(0,Y.useEffect)(Ye,Qe);let $e;t[31]!==i||t[32]!==o?($e=(e,t)=>{z(e);let n=o;if(!n||(i({type:Z.SetProjectModel,threadId:n,model:e}),t?.persist===!1))return;let r=`${n}:${e.provider??``}:${e.id}`;re.current!==r&&(re.current=r,console.log(`[useChatInputState] Persisting model to thread:`,{threadId:n,model:{id:e.id,provider:e.provider}}),ke(n,{model:e.id,modelProvider:e.provider}).then(()=>{re.current===r&&(re.current=null),console.log(`[useChatInputState] Model persisted successfully`)}).catch(e=>{re.current===r&&(re.current=null),console.error(`Failed to save model to thread:`,e)}))},t[31]=i,t[32]=o,t[33]=$e):$e=t[33];let et=$e,tt,nt;t[34]!==m||t[35]!==h||t[36]!==l||t[37]!==c||t[38]!==et||t[39]!==s||t[40]!==o?(tt=()=>{let e=s?c.find(e=>e.projectId===s)?.threads.find(e=>e.threadId===o):void 0,t=o?l[o]:void 0,n=e?.model??t?.id??null,r=e?.modelProvider??t?.provider??null;if(m.length===0){h&&(L([]),z(null));return}L(m);let i=n&&r?m.find(e=>e.id===n&&e.provider===r)??null:null,a=m[0],u=i??a,d=!i&&!!(n||r),f=te.current===u.id&&ne.current===u.provider;if(!m.some(e=>e.id===te.current&&e.provider===ne.current)&&te.current){et(a,{persist:!0});return}f||et(u,{persist:d})},nt=[o,s,c,l,m,h,et],t[34]=m,t[35]=h,t[36]=l,t[37]=c,t[38]=et,t[39]=s,t[40]=o,t[41]=tt,t[42]=nt):(tt=t[41],nt=t[42]),(0,Y.useEffect)(tt,nt);let rt,it;t[43]!==he.length||t[44]!==H?(rt=()=>{!H||he.length>0||(async()=>{try{let e=await _e(),t=Object.values(e).flat();t.length>0&&(ge(t),ve(e=>e??t[0]))}catch(e){console.error(`Failed to load image models:`,e)}})()},it=[H,he.length],t[43]=he.length,t[44]=H,t[45]=rt,t[46]=it):(rt=t[45],it=t[46]),(0,Y.useEffect)(rt,it);let[at,ot]=(0,Y.useState)(o),st,G;t[47]!==i||t[48]!==a||t[49]!==at||t[50]!==o?(st=()=>{if(o!==at){at&&T.current.trim()&&k.current[Md(at,a)]!==T.current&&i({type:Z.SetChatInputDraft,threadId:Md(at,a),draft:T.current});let e=!1;return queueMicrotask(()=>{e||!M.current||(ot(o),v(o?k.current[Md(o,a)]??``:``),xe([]),Ce(!1),Ae([]),Ne([]),Ie([]),Re(!1),Be(!1),ue(!1),pe(!1),fe(!1))}),()=>{e=!0}}},G=[o,at,a,i],t[47]=i,t[48]=a,t[49]=at,t[50]=o,t[51]=st,t[52]=G):(st=t[51],G=t[52]),(0,Y.useEffect)(st,G);let ct,lt;t[53]===o?(ct=t[54],lt=t[55]):(ct=()=>{o&&E(o).then(e=>{let{commands:t,skills:n,bundledSkills:r}=e;console.log(`Loaded slash commands:`,t,`skills:`,n,`bundled:`,r),Ae(t),Ne(n),Ie(r)}).catch(Fd)},lt=[o],t[53]=o,t[54]=ct,t[55]=lt),(0,Y.useEffect)(ct,lt);let ut=(0,Y.useRef)(!1),dt,ft;t[56]!==o||t[57]!==ze?(dt=()=>{ze&&!ut.current&&o&&E(o).then(e=>{let{commands:t,skills:n,bundledSkills:r}=e;Ae(t),Ne(n),Ie(r)}).catch(Pd),ut.current=ze},ft=[ze,o],t[56]=o,t[57]=ze,t[58]=dt,t[59]=ft):(dt=t[58],ft=t[59]),(0,Y.useEffect)(dt,ft);let pt;t[60]!==u||t[61]!==a||t[62]!==o?(pt=o?u[Md(o,a)]??``:``,t[60]=u,t[61]=a,t[62]=o,t[63]=pt):pt=t[63];let mt=pt,ht;t[64]!==o||t[65]!==mt?(ht=()=>{o&&v(mt)},t[64]=o,t[65]=mt,t[66]=ht):ht=t[66];let gt;t[67]!==a||t[68]!==o||t[69]!==mt?(gt=[o,mt,a],t[67]=a,t[68]=o,t[69]=mt,t[70]=gt):gt=t[70],(0,Y.useEffect)(ht,gt);let _t;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(_t=()=>{let e=We.current;if(!e)return;e.style.height=`auto`;let t=Math.max(e.scrollHeight,e.offsetHeight);e.style.height=`${Math.min(t,160)}px`},t[71]=_t):_t=t[71];let vt;t[72]===_?vt=t[73]:(vt=[_],t[72]=_,t[73]=vt),(0,Y.useLayoutEffect)(_t,vt);let yt,bt;t[74]!==i||t[75]!==f||t[76]!==p||t[77]!==o?(yt=()=>{f&&o&&!p&&(We.current?.focus(),i({type:Z.ClearFocusChatInput}))},bt=[f,o,p,i],t[74]=i,t[75]=f,t[76]=p,t[77]=o,t[78]=yt,t[79]=bt):(yt=t[78],bt=t[79]),(0,Y.useEffect)(yt,bt);let xt,St;t[80]!==i||t[81]!==a||t[82]!==o?(xt=()=>{let e=o,t=e?Md(e,a):null;return()=>{t&&T.current.trim()&&k.current[t]!==T.current&&i({type:Z.SetChatInputDraft,threadId:t,draft:T.current})}},St=[o,a,i],t[80]=i,t[81]=a,t[82]=o,t[83]=xt,t[84]=St):(xt=t[83],St=t[84]),(0,Y.useEffect)(xt,St);let Ct,wt;t[85]!==ie||t[86]!==ae?(Ct=()=>{let e=e=>{Ge.current&&!Ge.current.contains(e.target)&&B(!1),Ke.current&&!Ke.current.contains(e.target)&&oe(!1)};if(ie||ae)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},wt=[ie,ae],t[85]=ie,t[86]=ae,t[87]=Ct,t[88]=wt):(Ct=t[87],wt=t[88]),(0,Y.useEffect)(Ct,wt);let Tt;return t[89]!==be||t[90]!==ce||t[91]!==he||t[92]!==I||t[93]!==Le||t[94]!==Fe||t[95]!==Ve||t[96]!==C||t[97]!==i||t[98]!==x||t[99]!==y||t[100]!==H||t[101]!==_||t[102]!==le||t[103]!==de||t[104]!==et||t[105]!==U||t[106]!==Te||t[107]!==ee||t[108]!==o||t[109]!==ze||t[110]!==ie||t[111]!==ae||t[112]!==Se||t[113]!==Me||t[114]!==Oe||t[115]!==W?(Tt={message:_,setMessage:v,historyIndex:y,setHistoryIndex:b,draftMessage:x,setDraftMessage:S,cursorPosition:C,setCursorPosition:w,availableModels:I,setAvailableModels:L,selectedModel:ee,setSelectedModel:et,selectedModelIdRef:te,showModelMenu:ie,setShowModelMenu:B,showPlusMenu:ae,setShowPlusMenu:oe,attachments:ce,setAttachments:V,planMode:le,setPlanMode:ue,ralphMode:de,setRalphMode:fe,imageMode:H,setImageMode:pe,availableImageModels:he,setAvailableImageModels:ge,selectedImageModel:U,setSelectedImageModel:ve,allFiles:be,setAllFiles:xe,showSuggestions:Se,setShowSuggestions:Ce,suggestionQuery:W,setSuggestionQuery:we,selectedIndex:Te,setSelectedIndex:Ee,slashCommands:Oe,setSlashCommands:Ae,skills:Me,setSkills:Ne,bundledSkills:Fe,setBundledSkills:Ie,bundledSkillMode:Le,setBundledSkillMode:Re,showCommandSuggestions:ze,setShowCommandSuggestions:Be,commandQuery:Ve,setCommandQuery:He,fileInputRef:Ue,textareaRef:We,modelMenuRef:Ge,plusMenuRef:Ke,suggestionsRef:qe,commandSuggestionsRef:Je,selectedThreadId:o,dispatch:i},t[89]=be,t[90]=ce,t[91]=he,t[92]=I,t[93]=Le,t[94]=Fe,t[95]=Ve,t[96]=C,t[97]=i,t[98]=x,t[99]=y,t[100]=H,t[101]=_,t[102]=le,t[103]=de,t[104]=et,t[105]=U,t[106]=Te,t[107]=ee,t[108]=o,t[109]=ze,t[110]=ie,t[111]=ae,t[112]=Se,t[113]=Me,t[114]=Oe,t[115]=W,t[116]=Tt):Tt=t[116],Tt}function Pd(e){return console.error(`Failed to refresh slash commands and skills:`,e)}function Fd(e){return console.error(`Failed to load slash commands and skills:`,e)}function Id(e){return e.isStreaming}function Ld(e){return e.focusChatInput}function Rd(e){return e.configUpdatedAt}function zd(e){return e.chatInputDrafts}function Bd(e){return e.projectModelSelections}function Vd(e){return e.projects}function Hd(e){return e.selectedProjectId}function Ud(e){return e.selectedThreadId}var Wd=e=>{qt(e)};function Gd(e,t){return t===`secondary`?`${e}:secondary`:e}function Kd(e){let t=(0,X.c)(116),{message:n,setMessage:r,userTasks:i,onMatchedUserTaskSend:a,attachments:o,selectedModel:s,onSend:c,isStreaming:l,selectedThreadId:u,isListening:d,stopListening:f,resetTranscript:p,dispatch:m,historyIndex:h,setHistoryIndex:g,draftMessage:_,setDraftMessage:v,cursorPosition:y,setCursorPosition:b,showSuggestions:x,setShowSuggestions:S,suggestionQuery:C,setSuggestionQuery:w,allFiles:T,setAllFiles:E,selectedIndex:D,setSelectedIndex:O,showCommandSuggestions:k,setShowCommandSuggestions:A,commandQuery:j,setCommandQuery:M,slashCommands:N,skills:P,bundledSkills:F,bundledSkillMode:I,setBundledSkillMode:L,textareaRef:R,setAttachments:ee,planMode:z,setPlanMode:te,ralphMode:ne,setRalphMode:re,imageMode:ie,setImageMode:B,selectedImageModel:ae,hasConversationMessages:oe}=e,{paneId:se}=gd(),ce;t[0]!==o||t[1]!==m||t[2]!==ie||t[3]!==d||t[4]!==l||t[5]!==n||t[6]!==a||t[7]!==c||t[8]!==se||t[9]!==z||t[10]!==ne||t[11]!==p||t[12]!==ae||t[13]!==s||t[14]!==u||t[15]!==ee||t[16]!==v||t[17]!==g||t[18]!==r||t[19]!==f||t[20]!==R||t[21]!==i?(ce=()=>{if(!n.trim()&&o.length===0||!u)return;let e=ie?ae:s;if(!e)return;d&&(f(),p()),l?m({type:Z.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:u,paneId:se,message:n,model:e.id,attachments:o,provider:e.provider,planMode:z,imageMode:ie,ralphMode:ne}}):c(n,e.id,o,e.provider,z,ie,ne);let t=n,h=i.find(e=>e.content===t);Wd(n),r(``),ee([]),h&&a?.(h),g(-1),v(``),u&&m({type:Z.ClearChatInputDraft,threadId:Gd(u,se)}),R.current&&(R.current.style.height=`auto`)},t[0]=o,t[1]=m,t[2]=ie,t[3]=d,t[4]=l,t[5]=n,t[6]=a,t[7]=c,t[8]=se,t[9]=z,t[10]=ne,t[11]=p,t[12]=ae,t[13]=s,t[14]=u,t[15]=ee,t[16]=v,t[17]=g,t[18]=r,t[19]=f,t[20]=R,t[21]=i,t[22]=ce):ce=t[22];let V=ce,le;t[23]!==y||t[24]!==n||t[25]!==r||t[26]!==S||t[27]!==C||t[28]!==R?(le=e=>{let t=n.substring(0,y-C.length-1);r(`${t}${e} ${n.substring(y)}`),S(!1),setTimeout(()=>{if(R.current){R.current.focus();let n=t.length+e.length+1;R.current.setSelectionRange(n,n)}},0)},t[23]=y,t[24]=n,t[25]=r,t[26]=S,t[27]=C,t[28]=R,t[29]=le):le=t[29];let ue=le,de;t[30]!==j||t[31]!==y||t[32]!==n||t[33]!==B||t[34]!==r||t[35]!==te||t[36]!==re||t[37]!==A||t[38]!==R?(de=e=>{let t=e.metadata.action===`compact`?`/compact`:e.content,i=n.substring(0,y-j.length-1);r(`${i}${t}${n.substring(y)}`),A(!1),setTimeout(()=>{if(R.current){R.current.focus();let e=i.length+t.length;R.current.setSelectionRange(e,e)}},0),e.metadata.mode===`plan`?(te(!0),re(!1),B(!1)):e.metadata.mode===`ralph`&&(re(!0),te(!1),B(!1))},t[30]=j,t[31]=y,t[32]=n,t[33]=B,t[34]=r,t[35]=te,t[36]=re,t[37]=A,t[38]=R,t[39]=de):de=t[39];let fe=de,H;t[40]!==I||t[41]!==j||t[42]!==y||t[43]!==n||t[44]!==L||t[45]!==r||t[46]!==A||t[47]!==R?(H=e=>{let t=I?j.length+2:j.length+1,i=n.substring(0,y-t),a=n.substring(y),o=e.scope===`bundled`?`//${e.name}`:e.name.includes(` `)?`/"${e.name}"`:`/${e.name}`;r(`${i}${o}${a}`),A(!1),L(!1),setTimeout(()=>{if(R.current){R.current.focus();let e=i.length+o.length;R.current.setSelectionRange(e,e)}},0)},t[40]=I,t[41]=j,t[42]=y,t[43]=n,t[44]=L,t[45]=r,t[46]=A,t[47]=R,t[48]=H):H=t[48];let pe=H,me,he,ge,U;if(t[49]!==T||t[50]!==I||t[51]!==F||t[52]!==j||t[53]!==_||t[54]!==V||t[55]!==oe||t[56]!==h||t[57]!==fe||t[58]!==ue||t[59]!==pe||t[60]!==n||t[61]!==D||t[62]!==u||t[63]!==E||t[64]!==L||t[65]!==M||t[66]!==b||t[67]!==v||t[68]!==g||t[69]!==r||t[70]!==O||t[71]!==A||t[72]!==S||t[73]!==w||t[74]!==k||t[75]!==x||t[76]!==P||t[77]!==N||t[78]!==C){ge=e=>{if(k){if(e.key===`ArrowDown`){e.preventDefault(),O((D+1)%me.length);return}if(e.key===`ArrowUp`){e.preventDefault(),O((D-1+me.length)%me.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=me[D];t&&(t.type===`command`?fe(t.data):pe(t.data));return}if(e.key===`Escape`){A(!1);return}}if(x){let t=he.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),O((D+1)%he.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),O((D-1+he.length)%he.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),he[D]&&ue(he[D]);return}if(e.key===`Escape`){S(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),V();return}let t=q();t.length!==0&&(e.key===`ArrowUp`?(e.preventDefault(),h===-1?(v(n),g(t.length-1),r(t[t.length-1])):h>0&&(g(h-1),r(t[h-1]))):e.key===`ArrowDown`&&(e.preventDefault(),h>0?(g(h-1),r(t[h-1])):h===0&&(g(-1),r(_))))};let e;t[83]!==T||t[84]!==u||t[85]!==E||t[86]!==L||t[87]!==M||t[88]!==b||t[89]!==r||t[90]!==O||t[91]!==A||t[92]!==S||t[93]!==w?(e=e=>{let t=e.target.value,n=e.target.selectionStart;r(t),b(n);let i=t.substring(0,n),a=i.lastIndexOf(`//`);if(a!==-1){let t=a>0?i[a-1]:``;if(a===0||/\s/.test(t)){let t=i.substring(a+2);if(!t.includes(` `)){M(t),L(!0),A(!0),S(!1),O(0);let n=e.target;n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,160)}px`;return}}}L(!1);let o=i.lastIndexOf(`/`);if(o!==-1){let e=o>0?i[o-1]:``;if(o===0||/\s/.test(e)){let e=i.substring(o+1);e.includes(` `)?A(!1):(M(e),A(!0),S(!1),O(0))}else A(!1)}else{A(!1);let e=i.lastIndexOf(`#`);if(e!==-1){let t=e>0?i[e-1]:``;if(e===0||/\s/.test(t)){let t=i.substring(e+1);t.includes(` `)?S(!1):(w(t),S(!0),O(0),T.length===0&&u&&Kn(u).then(e=>{E(e)}).catch(Yd))}else S(!1)}else S(!1)}let s=e.target;s.style.height=`auto`,s.style.height=`${Math.min(s.scrollHeight,160)}px`},t[83]=T,t[84]=u,t[85]=E,t[86]=L,t[87]=M,t[88]=b,t[89]=r,t[90]=O,t[91]=A,t[92]=S,t[93]=w,t[94]=e):e=t[94],U=e;let i;if(t[95]!==I||t[96]!==F||t[97]!==j||t[98]!==oe||t[99]!==P||t[100]!==N){let e;t[102]!==j||t[103]!==oe?(e=e=>e.metadata.action===`compact`&&!oe?!1:e.name.toLowerCase().includes(j.toLowerCase()),t[102]=j,t[103]=oe,t[104]=e):e=t[104];let n=N.filter(e),r=I?F:P,a;t[105]===j?a=t[106]:(a=e=>e.name.toLowerCase().includes(j.toLowerCase()),t[105]=j,t[106]=a);let o=r.filter(a);i=[...I?[]:n.map(Jd),...o.map(qd)],t[95]=I,t[96]=F,t[97]=j,t[98]=oe,t[99]=P,t[100]=N,t[101]=i}else i=t[101];me=i.slice(0,10),he=x?T.filter(e=>e.toLowerCase().includes(C.toLowerCase())).slice(0,10):[],t[49]=T,t[50]=I,t[51]=F,t[52]=j,t[53]=_,t[54]=V,t[55]=oe,t[56]=h,t[57]=fe,t[58]=ue,t[59]=pe,t[60]=n,t[61]=D,t[62]=u,t[63]=E,t[64]=L,t[65]=M,t[66]=b,t[67]=v,t[68]=g,t[69]=r,t[70]=O,t[71]=A,t[72]=S,t[73]=w,t[74]=k,t[75]=x,t[76]=P,t[77]=N,t[78]=C,t[79]=me,t[80]=he,t[81]=ge,t[82]=U}else me=t[79],he=t[80],ge=t[81],U=t[82];let _e;return t[107]!==me||t[108]!==he||t[109]!==ge||t[110]!==V||t[111]!==U||t[112]!==fe||t[113]!==ue||t[114]!==pe?(_e={handleSend:V,handleKeyDown:ge,handleTextareaInput:U,insertFileReference:ue,insertCommand:fe,insertSkill:pe,allSuggestions:me,fileSuggestions:he},t[107]=me,t[108]=he,t[109]=ge,t[110]=V,t[111]=U,t[112]=fe,t[113]=ue,t[114]=pe,t[115]=_e):_e=t[115],_e}function qd(e){return{type:`skill`,data:e}}function Jd(e){return{type:`command`,data:e}}function Yd(e){return console.error(`Failed to fetch files:`,e)}var Xd=768;function Zd(){let e=(0,X.c)(2),[t,n]=Y.useState(Qd),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${Xd-1}px)`),t=()=>{n(window.innerWidth<Xd)};return e.addEventListener(`change`,t),n(window.innerWidth<Xd),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),t}function Qd(){return typeof window>`u`?!1:window.innerWidth<Xd}function $d(){let e=(0,X.c)(18),t=Ia(),n=Q(nf),r=Q(tf),i=Q(ef),a=Zd(),o,s;e[0]!==t||e[1]!==n||e[2]!==a?(o=()=>{a&&n&&t({type:Z.DisableDualChat})},s=[t,n,a],e[0]=t,e[1]=n,e[2]=a,e[3]=o,e[4]=s):(o=e[3],s=e[4]),(0,Y.useEffect)(o,s);let c;e[5]!==t||e[6]!==a||e[7]!==i?(c=()=>{if(!i||a)return;let e=crypto.randomUUID();t({type:Z.EnableDualChat,conversationId:e})},e[5]=t,e[6]=a,e[7]=i,e[8]=c):c=e[8];let l=c,u;e[9]===t?u=e[10]:(u=()=>{t({type:Z.DisableDualChat})},e[9]=t,e[10]=u);let d=u,f=!a&&!!i,p=n&&f,m=r!==`secondary`,h;return e[11]!==d||e[12]!==l||e[13]!==r||e[14]!==p||e[15]!==f||e[16]!==m?(h={isDualChatActive:p,showDualChatControls:f,focusedPane:r,canCloseSecondary:m,enableDualChat:l,disableDualChat:d},e[11]=d,e[12]=l,e[13]=r,e[14]=p,e[15]=f,e[16]=m,e[17]=h):h=e[17],h}function ef(e){return e.selectedThreadId}function tf(e){return e.focusedPane}function nf(e){return e.dualChatEnabled}function rf(e){let t=(0,X.c)(20),{visible:n,commands:i,skills:a,skillReferencePrefix:o,query:s,selectedIndex:c,onSelectCommand:l,onSelectSkill:u,onMouseEnterSuggestion:d,containerRef:f}=e,p=o===void 0?`/`:o;if(!n)return null;let m=p===`//`,h;if(t[0]!==i||t[1]!==f||t[2]!==m||t[3]!==d||t[4]!==l||t[5]!==u||t[6]!==s||t[7]!==c||t[8]!==p||t[9]!==a){let e;t[11]===s?e=t[12]:(e=e=>e.name.toLowerCase().includes(s.toLowerCase()),t[11]=s,t[12]=e);let n=i.filter(e),o;t[13]===s?o=t[14]:(o=e=>e.name.toLowerCase().includes(s.toLowerCase()),t[13]=s,t[14]=o);let g=[...a.filter(o).map(of),...m?[]:n.map(af)].slice(0,10),_,v;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(_=V(r.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),v=(0,$.jsx)(Lt,{className:`h-3 w-3`}),t[15]=_,t[16]=v):(_=t[15],v=t[16]);let y=m?`Bundled Skills`:`Skills & Commands`,b=s&&` matching "${s}"`,x;t[17]!==y||t[18]!==b?(x=(0,$.jsxs)(`div`,{className:_,children:[v,y,b]}),t[17]=y,t[18]=b,t[19]=x):x=t[19],h=(0,$.jsxs)(`div`,{ref:f,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[x,g.length>0?(()=>{let e=[],t=!1,n=!1;return g.forEach((i,a)=>{let o=a===c;if(i.type===`skill`&&!t&&(t=!0,e.push((0,$.jsx)(`div`,{className:V(r.dropdownGroupHeading,`px-2 py-1.5 pt-2`),children:`Skills`},`group-skills`))),i.type===`command`&&!n&&(n=!0,e.push((0,$.jsx)(`div`,{className:V(r.dropdownGroupHeading,`px-2 py-1.5 pt-2`),children:`Commands`},`group-commands`))),i.type===`command`){let t=i.data;e.push((0,$.jsxs)(`button`,{type:`button`,className:V(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,o?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>l(t),onMouseEnter:()=>d(a),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,t.name]}),t.metadata.argumentHint&&(0,$.jsx)(`span`,{className:r.compact,children:t.metadata.argumentHint})]}),t.metadata.description&&(0,$.jsx)(`span`,{className:r.compact,children:t.metadata.description})]},`cmd-${t.name}`))}else{let t=i.data;e.push((0,$.jsxs)(`button`,{type:`button`,className:V(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,o?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>u(t),onMouseEnter:()=>d(a),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(`span`,{className:`font-medium`,children:[p,t.name]})}),(0,$.jsx)(`span`,{className:r.compact,children:t.description})]},`skill-${t.name}`))}}),e})():(0,$.jsxs)(`div`,{className:V(r.compact,`px-3 py-4 text-center text-muted-foreground`),children:[m?`No bundled skills found.`:`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:r.compact,children:[m?(0,$.jsx)($.Fragment,{children:`Use bundled skills with syntax like `}):(0,$.jsx)($.Fragment,{children:`Create commands in `}),m?(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`//skill-name`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/commands/`}),` or skills in`,` `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/skills/`})]})]})]})]}),t[0]=i,t[1]=f,t[2]=m,t[3]=d,t[4]=l,t[5]=u,t[6]=s,t[7]=c,t[8]=p,t[9]=a,t[10]=h}else h=t[10];return h}function af(e){return{type:`command`,data:e}}function of(e){return{type:`skill`,data:e}}function sf(e){return e.startsWith(`image/`)}function cf(e){return e.startsWith(`video/`)}function lf(e){return e.startsWith(`audio/`)}function uf(e){let t=(0,X.c)(7),{attachments:n,onRemove:i}=e;if(n.length===0)return null;let a;if(t[0]!==n||t[1]!==i){let e;t[3]===i?e=t[4]:(e=(e,t)=>(0,$.jsx)(`div`,{className:V(r.compact,`group relative flex items-center gap-1 rounded-md bg-muted text-muted-foreground`),children:sf(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.content}`,alt:e.fileName,className:`h-16 w-16 rounded-md object-cover`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-foreground text-background opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,$.jsx)(Ce,{className:`h-2.5 w-2.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):cf(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(ue,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(Ce,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):lf(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(ge,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(Ce,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(tn,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(Ce,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]})},t),t[3]=i,t[4]=e),a=n.map(e),t[0]=n,t[1]=i,t[2]=a}else a=t[2];let o;return t[5]===a?o=t[6]:(o=(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:a}),t[5]=a,t[6]=o),o}var df=ei(e=>(0,$.jsxs)(`div`,{className:`w-72 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:e.v0,children:`Context`}),e.v1]}),(0,$.jsxs)(`div`,{className:e.v2,children:[(0,$.jsxs)(`span`,{children:[e.v3,`% Full`]}),(0,$.jsxs)(`span`,{children:[`~`,e.v4,` / `,e.v5,` Tokens`]})]}),(0,$.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted/60`,children:(0,$.jsx)(`div`,{className:`flex h-full w-full`,children:e.v6})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.v7})]}),{name:`ContextUsagePanel_1`,portals:[`v1`,`v3`,`v4`,`v5`,`v6`,`v7`]}),ff=function(e){let t=(0,X.c)(37),{breakdown:n,onClose:i}=e,{categories:a,totalTokens:o,contextWindow:s,percentageFull:c}=n,l,u,d,f,p,m,h,g;if(t[0]!==a||t[1]!==s||t[2]!==i||t[3]!==c||t[4]!==o){let e;t[13]===a?e=t[14]:(e=e=>a[e.key]>0,t[13]=a,t[14]=e);let n=pf.filter(e);l=df,u=r.label,t[15]===i?d=t[16]:(d=i&&(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:i,children:[(0,$.jsx)(Ce,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[15]=i,t[16]=d),t[17]===Symbol.for(`react.memo_cache_sentinel`)?(f=V(r.compact,`flex items-center justify-between text-muted-foreground`),t[17]=f):f=t[17],p=c,t[18]===o?m=t[19]:(m=mf(o),t[18]=o,t[19]=m),t[20]===s?h=t[21]:(h=hf(s),t[20]=s,t[21]=h);let _;t[22]!==a||t[23]!==s?(_=e=>{let t=a[e.key],n=s>0?t/s*100:0;return(0,$.jsx)(`div`,{style:{width:`${Math.max(n,t>0?.5:0)}%`,backgroundColor:e.color}},e.key)},t[22]=a,t[23]=s,t[24]=_):_=t[24],g=n.map(_),t[0]=a,t[1]=s,t[2]=i,t[3]=c,t[4]=o,t[5]=l,t[6]=u,t[7]=d,t[8]=f,t[9]=p,t[10]=m,t[11]=h,t[12]=g}else l=t[5],u=t[6],d=t[7],f=t[8],p=t[9],m=t[10],h=t[11],g=t[12];let _;t[25]===a?_=t[26]:(_=pf.map(e=>(0,$.jsxs)(`div`,{className:V(r.compact,`flex items-center justify-between text-muted-foreground`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{children:e.label})]}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:mf(a[e.key])})]},e.key)),t[25]=a,t[26]=_);let v;return t[27]!==l||t[28]!==u||t[29]!==d||t[30]!==f||t[31]!==p||t[32]!==m||t[33]!==h||t[34]!==g||t[35]!==_?(v=(0,$.jsx)(l,{v0:u,v1:d,v2:f,v3:p,v4:m,v5:h,v6:g,v7:_}),t[27]=l,t[28]=u,t[29]=d,t[30]=f,t[31]=p,t[32]=m,t[33]=h,t[34]=g,t[35]=_,t[36]=v):v=t[36],v},pf=[{key:`systemPrompt`,label:`System prompt`,color:`#9CA3AF`},{key:`toolDefinitions`,label:`Tool definitions`,color:`#B088F0`},{key:`rules`,label:`Rules`,color:`#88D088`},{key:`skills`,label:`Skills`,color:`#D0A000`},{key:`subagentDefinitions`,label:`Subagent definitions`,color:`#2080D0`},{key:`conversation`,label:`Conversation`,color:`#E09030`}];function mf(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function hf(e){return e>=1e6?`${Math.round(e/1e6)}M`:e>=1e3?`${Math.round(e/1e3)}K`:e.toString()}function gf({threadId:e,currentConversationId:t,initialBreakdown:n,refreshKey:i,children:a}){let[o,s]=(0,Y.useState)(n??null),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(n?t:void 0);return(0,Y.useEffect)(()=>{if(n){s(n),h(t),d(null);return}t!==m&&(s(null),h(void 0),d(null))},[n,t,m,i]),(0,Y.useEffect)(()=>{if(!f||!e||!t||m===t)return;let n=!1;async function r(){let r=t;if(r){l(!0),d(null);try{let t=await Ft(e,r);if(n)return;s(t),h(r)}catch(e){if(console.error(`[TokenUsageTooltip] Failed to load context data:`,e),n)return;s(e=>(e||d(`Failed to load context data`),e))}finally{n||l(!1)}}}return r(),()=>{n=!0}},[f,e,t,m]),!e||e===``?(0,$.jsx)($.Fragment,{children:a}):(0,$.jsxs)(Yc,{open:f,onOpenChange:p,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Xc,{asChild:!0,children:a})}),(0,$.jsx)(T,{side:`top`,className:`bg-popover text-popover-foreground`,children:`Show context usage`})]}),(0,$.jsxs)(Zc,{side:`top`,align:`end`,className:`w-auto p-4`,children:[c&&(0,$.jsxs)(`div`,{className:V(r.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(En,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading context...`})]}),u&&!c&&(0,$.jsxs)(`div`,{className:V(r.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(En,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u})]}),!c&&!u&&o&&(0,$.jsx)(ff,{breakdown:o,onClose:()=>p(!1)})]})]})}var _f=ei(e=>(0,$.jsxs)(`svg`,{className:e.v0,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,$.jsx)(`circle`,{className:`text-muted-foreground/25`,cx:`10`,cy:`10`,r:e.v1,fill:`none`,stroke:`currentColor`,strokeWidth:`3`}),(0,$.jsx)(`circle`,{cx:`10`,cy:`10`,r:e.v2,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:e.v3,strokeDashoffset:e.v4,transform:`rotate(-90 10 10)`})]}),{name:`ContextUsageRing_1`,svg:!0}),vf=function(e){let t=(0,X.c)(5),{percentage:n}=e,r=2*Math.PI*7,i=r*(1-Math.min(n,100)/100),a;t[0]===n?a=t[1]:(a=bf(n),t[0]=n,t[1]=a);let o=`h-4 w-4 ${a}`,s;return t[2]!==i||t[3]!==o?(s=(0,$.jsx)(_f,{v0:o,v1:7,v2:7,v3:r,v4:i}),t[2]=i,t[3]=o,t[4]=s):s=t[4],s};function yf(e){return e.filter(e=>e.sender===`agent`).length}function bf(e){return e>75?`text-red-500`:e>50?`text-orange-500`:`text-muted-foreground`}var xf=500;function Sf(e){let t=(0,X.c)(39),{threadId:n,conversationId:r,messages:i}=e,a;t[0]===i?a=t[1]:(a=i===void 0?[]:i,t[0]=i,t[1]=a);let o=a,[s,c]=(0,Y.useState)(r),[l,u]=(0,Y.useState)(),d;t[2]===o?d=t[3]:(d=yf(o),t[2]=o,t[3]=d);let f=d,[p,m]=(0,Y.useState)(f),h=(0,Y.useRef)(null),g=(0,Y.useRef)(n),_,v;t[4]===f?(_=t[5],v=t[6]):(_=()=>(h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{m(f)},xf),()=>{h.current&&clearTimeout(h.current)}),v=[f],t[4]=f,t[5]=_,t[6]=v),(0,Y.useEffect)(_,v);let y,b;t[7]===n?(y=t[8],b=t[9]):(y=()=>{g.current!==n&&(g.current&&(D.invalidate(`thread-${g.current}`),D.invalidatePattern(RegExp(`^context-breakdown-${g.current}-`))),g.current=n,c(void 0),u(void 0))},b=[n],t[7]=n,t[8]=y,t[9]=b),(0,Y.useEffect)(y,b);let x,S;t[10]===r?(x=t[11],S=t[12]):(x=()=>{if(r){c(r);return}},S=[r],t[10]=r,t[11]=x,t[12]=S),(0,Y.useEffect)(x,S);let C;t[13]!==r||t[14]!==n?(C=()=>{let e=!1;return(async function(){if(!n){c(void 0),u(void 0);return}if(r){c(r);return}try{let t=await F(n);if(e)return;c(t.currentConversationId)}catch(e){console.error(`Failed to fetch thread data:`,e)}})(),()=>{e=!0}},t[13]=r,t[14]=n,t[15]=C):C=t[15];let w;t[16]!==r||t[17]!==p||t[18]!==n?(w=[r,n,p],t[16]=r,t[17]=p,t[18]=n,t[19]=w):w=t[19],(0,Y.useEffect)(C,w);let T;t[20]!==s||t[21]!==n?(T=()=>{let e=!1;return(async function(){if(!n||!s){u(void 0);return}try{let t=await Ft(n,s);if(e)return;u(t)}catch(e){let t=e;if(t instanceof Error&&t.message===`Conversation not found`){u(void 0);return}console.error(`Failed to fetch context breakdown:`,t)}})(),()=>{e=!0}},t[20]=s,t[21]=n,t[22]=T):T=t[22];let E;if(t[23]!==p||t[24]!==s||t[25]!==n?(E=[n,s,p],t[23]=p,t[24]=s,t[25]=n,t[26]=E):E=t[26],(0,Y.useEffect)(T,E),!n||n===``)return null;let O=l?.percentageFull,k=typeof O==`number`&&O>25,A=String(p),j;t[27]!==O||t[28]!==k?(j=k?(0,$.jsx)(vf,{percentage:O}):(0,$.jsx)(de,{className:`h-4 w-4`}),t[27]=O,t[28]=k,t[29]=j):j=t[29];let M;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(`span`,{className:`sr-only`,children:`Show context usage`}),t[30]=M):M=t[30];let N;t[31]===j?N=t[32]:(N=(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[j,M]}),t[31]=j,t[32]=N);let P;return t[33]!==l||t[34]!==s||t[35]!==A||t[36]!==N||t[37]!==n?(P=(0,$.jsx)(gf,{threadId:n,currentConversationId:s,initialBreakdown:l,refreshKey:A,children:N}),t[33]=l,t[34]=s,t[35]=A,t[36]=N,t[37]=n,t[38]=P):P=t[38],P}function Cf(e,t){let n=e.target.files;if(!n||n.length===0)return;let r=Array.from(n),i=r.length,a=Array.from({length:i}),o=0;e.target.value=``,r.forEach((e,n)=>{let r=new FileReader;r.onload=()=>{let s=r.result.split(`,`)[1];a[n]={fileName:e.name,content:s,mimeType:e.type||`application/octet-stream`},o+=1,o===i&&t(a)},r.readAsDataURL(e)})}function wf(e){let t=(0,X.c)(17),{showSuggestions:n,fileSuggestions:i,suggestionQuery:a,selectedIndex:o,onSelectFile:s,onMouseEnterSuggestion:c,containerRef:l}=e;if(!n||i.length===0)return null;let u,d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=V(r.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),d=(0,$.jsx)(k,{className:`h-3 w-3`}),t[0]=u,t[1]=d):(u=t[0],d=t[1]);let f;t[2]===a?f=t[3]:(f=(0,$.jsxs)(`div`,{className:u,children:[d,`Files matching "`,a,`"`]}),t[2]=a,t[3]=f);let p;if(t[4]!==i||t[5]!==c||t[6]!==s||t[7]!==o){let e;t[9]!==c||t[10]!==s||t[11]!==o?(e=(e,t)=>{let n=e.split(`/`).pop()??e,i=t===o;return(0,$.jsxs)(`button`,{type:`button`,className:V(r.body,`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left transition-colors`,i?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>s(e),onMouseEnter:()=>c(t),children:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,$.jsx)(w,{className:`h-4 w-4 text-blue-500`}):(0,$.jsx)(oe,{className:`h-4 w-4 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium`,children:n}),(0,$.jsx)(`span`,{className:V(r.compact,`truncate text-muted-foreground opacity-70`),children:e})]})]},e)},t[9]=c,t[10]=s,t[11]=o,t[12]=e):e=t[12],p=i.map(e),t[4]=i,t[5]=c,t[6]=s,t[7]=o,t[8]=p}else p=t[8];let m;return t[13]!==l||t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(`div`,{ref:l,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[f,p]}),t[13]=l,t[14]=f,t[15]=p,t[16]=m):m=t[16],m}function Tf(e){let t=(0,X.c)(5),{providerSlug:n}=e;if(!n)return null;let r;t[0]===n?r=t[1]:(r=Wt(n),t[0]=n,t[1]=r);let i=`${n} logo`,a;return t[2]!==r||t[3]!==i?(a=(0,$.jsx)(`img`,{src:r,alt:i,className:`h-3.5 w-3.5 flex-shrink-0 dark:invert`,onError:Ef}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a}function Ef(e){e.currentTarget.style.visibility=`hidden`}function Df(e){let t=(0,X.c)(9),{providerSlug:n,providerData:i}=e,a=i?.name??n,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=V(r.dropdownGroupHeading,`flex items-center gap-1.5 px-3 py-1.5 uppercase tracking-wide`),t[0]=o):o=t[0];let s;t[1]===n?s=t[2]:(s=(0,$.jsx)(Tf,{providerSlug:n}),t[1]=n,t[2]=s);let c;t[3]!==a||t[4]!==i?(c=i?.url?(0,$.jsx)(mi,{url:i.url,showIcon:!1,variant:`inline`,children:a}):a,t[3]=a,t[4]=i,t[5]=c):c=t[5];let l;return t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:o,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8],l}function Of(e){let t=e.pricing?.prompt;return t==null?null:Math.ceil(t*3)}function kf(e){return`$${he(e)}`}function Af(e,t){return e.pricing?(0,$.jsxs)(`div`,{className:`max-w-64 whitespace-normal break-words text-left leading-relaxed`,children:[(0,$.jsx)(`div`,{children:`${kf(e.pricing.prompt??0)} input per million tokens`}),(0,$.jsx)(`div`,{children:`${kf(e.pricing.completion??0)} output per million tokens`}),(0,$.jsx)(`div`,{children:`Displayed value of ${t} is a relative price.`})]}):null}function jf(e,t){return[...e].sort((e,n)=>{let r=(e.provider??`Other`).localeCompare(n.provider??`Other`);if(r!==0)return r;if(t===`relative-price`){let t=(Of(e)??2**53-1)-(Of(n)??2**53-1);if(t!==0)return t}return hi(e.id).localeCompare(hi(n.id))})}function Mf(e){let t=(0,X.c)(34),{availableModels:n,selectedModel:i,onModelSelect:a}=e,[o,s]=Y.useState(!1),[c,l]=Y.useState(`relative-price`),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=new Map,t[0]=d):d=t[0];let[f,p]=Y.useState(d),m=Y.useRef(null),h,g;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{u().then(function(e){p(new Map(e.map(Pf)))})},g=[],t[1]=h,t[2]=g):(h=t[1],g=t[2]),Y.useEffect(h,g);let _,v;t[3]===o?(_=t[4],v=t[5]):(_=()=>{let e=e=>{m.current&&!m.current.contains(e.target)&&s(!1)};if(o)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},v=[o],t[3]=o,t[4]=_,t[5]=v),Y.useEffect(_,v);let y;t[6]===a?y=t[7]:(y=e=>{a(e),s(!1)},t[6]=a,t[7]=y);let b=y,x;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>{l(function(e){return e===`relative-price`?`alphabetical`:`relative-price`})},t[8]=x):x=t[8];let S=x,C;t[9]!==n||t[10]!==c?(C=jf(n,c),t[9]=n,t[10]=c,t[11]=C):C=t[11];let w=C,E=c===`relative-price`?Pt:dt,D=c===`relative-price`?`Sort by relative price`:`Sort alphabetically`,O;t[12]===o?O=t[13]:(O=()=>s(!o),t[12]=o,t[13]=O);let k;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(k=V(r.body,`font-normal`),t[14]=k):k=t[14];let A;t[15]===i?A=t[16]:(A=i?hi(i.id):`No model`,t[15]=i,t[16]=A);let j;t[17]===A?j=t[18]:(j=(0,$.jsx)(`span`,{className:k,children:A}),t[17]=A,t[18]=j);let M;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(ze,{className:`h-3 w-3`}),t[19]=M):M=t[19];let N;t[20]!==j||t[21]!==O?(N=(0,$.jsxs)(Rt,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:O,children:[j,M]}),t[20]=j,t[21]=O,t[22]=N):N=t[22];let F;t[23]!==E||t[24]!==b||t[25]!==f||t[26]!==i?.id||t[27]!==o||t[28]!==D||t[29]!==w?(F=o&&(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 w-80 max-h-80 overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:(0,$.jsxs)(P,{children:[(0,$.jsx)(`div`,{className:`-mb-3 flex justify-end px-1 pb-1`,children:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":D,className:`rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground`,onClick:S,children:(0,$.jsx)(E,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(T,{side:`left`,align:`start`,sideOffset:8,children:D})]})}),Object.entries(w.reduce(Nf,{})).map((e,t)=>{let[n,a]=e;return(0,$.jsxs)(`div`,{children:[t>0&&(0,$.jsx)(pi,{className:`my-1`}),(0,$.jsx)(Df,{providerSlug:n,providerData:f.get(n)}),a.map(e=>{let t=Of(e),n=t==null?null:Af(e,t);return(0,$.jsx)(`div`,{children:(0,$.jsx)(`div`,{children:(0,$.jsxs)(`button`,{type:`button`,className:V(r.body,`flex w-full items-center justify-between gap-3 whitespace-nowrap rounded-md px-3 py-1.5 pl-8 text-popover-foreground hover:bg-accent`,e.id===i?.id&&`bg-accent font-medium`),onClick:()=>b(e),children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:hi(e.id)}),t!=null&&n&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:t})}),(0,$.jsx)(T,{side:`left`,align:`end`,sideOffset:8,className:`max-w-64`,children:n})]})]})})},e.id)})]},n)})]})}),t[23]=E,t[24]=b,t[25]=f,t[26]=i?.id,t[27]=o,t[28]=D,t[29]=w,t[30]=F):F=t[30];let I;return t[31]!==N||t[32]!==F?(I=(0,$.jsxs)(`div`,{className:`relative`,ref:m,children:[N,F]}),t[31]=N,t[32]=F,t[33]=I):I=t[33],I}function Nf(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function Pf(e){return[e.slug,e]}var Ff=[{value:`build`,label:`Build`,icon:zn,description:`Executes code changes and implements features`},{value:`plan`,label:`Plan`,icon:Ot,description:`Creates implementation plans without making changes`},{value:`image`,label:`Image`,icon:Ze,description:`Generates and edits images`},{value:`ralph`,label:`Ralph`,icon:dn,description:`Runs rapid iterative test-fix cycles`}];function If(e,t,n){return n?`ralph`:e?`plan`:t?`image`:`build`}function Lf({planMode:e,imageMode:t,ralphMode:n,setPlanMode:r,setImageMode:i,setRalphMode:a,projectId:o}){let s=Ia(),c=Q(function(e){if(o)return e.projects.find(e=>e.projectId===o)}),[l,u]=Y.useState(!0),[d,f]=Y.useState(!1),p=If(e,t,n),m=Ff.find(e=>e.value===p);Y.useEffect(()=>{c&&u(c.allowAllCommands===!1)},[c]);async function h(){if(!o||d)return;let e=!l;u(e),f(!0);try{await ie(o,{allowAllCommands:!e}),en(o);let t=await y();s({type:Z.SetProjects,projects:t.projects})}catch(t){u(!e),console.error(`Failed to update command confirmation setting:`,t)}finally{f(!1)}}function g(e){r(e===`plan`),i(e===`image`),a(e===`ralph`)}return{chatModes:Ff,confirmCommands:l,currentConfig:m,currentMode:p,isUpdatingConfirmCommands:d,selectMode:g,toggleConfirmCommands:h}}function Rf(e){let t=(0,X.c)(38),{planMode:n,imageMode:i,ralphMode:a,setPlanMode:o,setImageMode:s,setRalphMode:c,projectId:l}=e,[u,d]=Y.useState(!1),f=Y.useRef(null),p;t[0]!==i||t[1]!==n||t[2]!==l||t[3]!==a||t[4]!==s||t[5]!==o||t[6]!==c?(p={planMode:n,imageMode:i,ralphMode:a,setPlanMode:o,setImageMode:s,setRalphMode:c,projectId:l},t[0]=i,t[1]=n,t[2]=l,t[3]=a,t[4]=s,t[5]=o,t[6]=c,t[7]=p):p=t[7];let{chatModes:m,confirmCommands:h,currentConfig:g,currentMode:_,isUpdatingConfirmCommands:v,selectMode:y,toggleConfirmCommands:b}=Lf(p),x,S;t[8]===u?(x=t[9],S=t[10]):(x=()=>{let e=function(e){f.current&&!f.current.contains(e.target)&&d(!1)};if(u)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},S=[u],t[8]=u,t[9]=x,t[10]=S),Y.useEffect(x,S);let C;t[11]===y?C=t[12]:(C=function(e){y(e),d(!1)},t[11]=y,t[12]=C);let w=C,E;t[13]===u?E=t[14]:(E=()=>d(!u),t[13]=u,t[14]=E);let D;t[15]===g.icon?D=t[16]:(D=(0,$.jsx)(g.icon,{className:`h-4 w-4`}),t[15]=g.icon,t[16]=D);let O;t[17]!==E||t[18]!==D?(O=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`action`,size:`icon-sm`,onClick:E,children:D})}),t[17]=E,t[18]=D,t[19]=O):O=t[19];let k;t[20]!==g.description||t[21]!==g.label?(k=(0,$.jsx)(T,{children:(0,$.jsxs)(`p`,{children:[g.label,` - `,g.description]})}),t[20]=g.description,t[21]=g.label,t[22]=k):k=t[22];let A;t[23]!==O||t[24]!==k?(A=(0,$.jsx)(P,{children:(0,$.jsxs)(U,{children:[O,k]})}),t[23]=O,t[24]=k,t[25]=A):A=t[25];let j;t[26]!==m||t[27]!==h||t[28]!==_||t[29]!==w||t[30]!==v||t[31]!==u||t[32]!==l||t[33]!==b?(j=u&&(0,$.jsxs)(`div`,{className:`absolute bottom-full right-0 z-50 mb-1 w-56 rounded-lg border border-border bg-popover p-1 shadow-md`,children:[l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:V(r.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent disabled:opacity-50`),onClick:()=>{b()},disabled:v,children:[`Confirm Commands`,h&&(0,$.jsx)(bt,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border`})]}),m.map(e=>{let t=e.icon,n=e.value===_;return(0,$.jsxs)(`button`,{type:`button`,className:V(r.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent`),onClick:()=>w(e.value),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(bt,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[26]=m,t[27]=h,t[28]=_,t[29]=w,t[30]=v,t[31]=u,t[32]=l,t[33]=b,t[34]=j):j=t[34];let M;return t[35]!==j||t[36]!==A?(M=(0,$.jsxs)(`div`,{className:`relative hidden md:block`,ref:f,children:[A,j]}),t[35]=j,t[36]=A,t[37]=M):M=t[37],M}function zf(e){let t=(0,X.c)(32),{disabled:n,canAddTask:r,onFileAttach:i,onAddTask:a,showModes:o,planMode:s,imageMode:c,ralphMode:l,setPlanMode:u,setImageMode:d,setRalphMode:f,projectId:p}=e,m=n===void 0?!1:n,h=o===void 0?!1:o,g=s===void 0?!1:s,_=c===void 0?!1:c,v=l===void 0?!1:l,y=u??Hf,b=d??Vf,x=f??Bf,S;t[0]!==_||t[1]!==g||t[2]!==p||t[3]!==v||t[4]!==y||t[5]!==b||t[6]!==x?(S={planMode:g,imageMode:_,ralphMode:v,setPlanMode:y,setImageMode:b,setRalphMode:x,projectId:p},t[0]=_,t[1]=g,t[2]=p,t[3]=v,t[4]=y,t[5]=b,t[6]=x,t[7]=S):S=t[7];let C=Lf(S),w;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(w=function(e){e()},t[8]=w):w=t[8];let T=w,E,D;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(Le,{}),D=(0,$.jsx)(`span`,{className:`sr-only`,children:`More options`}),t[9]=E,t[10]=D):(E=t[9],D=t[10]);let O;t[11]===m?O=t[12]:(O=(0,$.jsx)(Ul,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`action`,size:`icon-sm`,disabled:m,children:[E,D]})}),t[11]=m,t[12]=O);let k;t[13]===i?k=t[14]:(k=()=>T(i),t[13]=i,t[14]=k);let A;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(tn,{className:`mr-2 h-3.5 w-3.5`}),t[15]=A):A=t[15];let j;t[16]===k?j=t[17]:(j=(0,$.jsxs)(Jl,{onClick:k,children:[A,`Attach File`]}),t[16]=k,t[17]=j);let M;t[18]!==r||t[19]!==a?(M=r&&(0,$.jsxs)(Jl,{onClick:()=>T(a),children:[(0,$.jsx)(Zt,{className:`mr-2 h-3.5 w-3.5`}),`Add Task`]}),t[18]=r,t[19]=a,t[20]=M):M=t[20];let N;t[21]!==C||t[22]!==p||t[23]!==h?(N=h&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ql,{}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Jl,{onClick:()=>{C.toggleConfirmCommands()},disabled:C.isUpdatingConfirmCommands,children:[`Confirm Commands`,C.confirmCommands&&(0,$.jsx)(bt,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(Ql,{})]}),C.chatModes.map(e=>{let t=e.icon,n=e.value===C.currentMode;return(0,$.jsxs)(Jl,{onClick:()=>C.selectMode(e.value),className:V(n&&`bg-accent`),children:[(0,$.jsx)(t,{className:`mr-2 h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(bt,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[21]=C,t[22]=p,t[23]=h,t[24]=N):N=t[24];let P;t[25]!==j||t[26]!==M||t[27]!==N?(P=(0,$.jsxs)(ql,{align:`start`,side:`top`,className:`w-56`,children:[j,M,N]}),t[25]=j,t[26]=M,t[27]=N,t[28]=P):P=t[28];let F;return t[29]!==O||t[30]!==P?(F=(0,$.jsxs)(Hl,{children:[O,P]}),t[29]=O,t[30]=P,t[31]=F):F=t[31],F}function Bf(){}function Vf(){}function Hf(){}var Uf=_i(`voice.stt.web`);function Wf(e){switch(e){case`not-allowed`:return`Microphone access was denied. Please allow microphone access to use voice input.`;case`service-not-allowed`:return`Speech recognition is not allowed in this environment.`;case`audio-capture`:return`No microphone was found. Please connect a microphone to use voice input.`;case`network`:return`Speech recognition requires a network connection.`;case`no-speech`:case`aborted`:return null;default:return`Speech recognition error: ${e}`}}function Gf(e){let t=``;for(let n=0;n<e.results.length;n+=1)t+=e.results[n][0]?.transcript??``;return t}function Kf(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>()=>{l.current=!1,c.current?.abort(),c.current=null},[]);let u=(0,Y.useCallback)(()=>{let e=gi();if(!e){l.current=!1,t(`error`),r(!1),s(`Speech recognition is not supported in this environment.`);return}e.continuous=!0,e.interimResults=!0,e.lang=`en-US`,e.onresult=e=>{let t=Gf(e).trim();t&&a(t)},e.onerror=e=>{let t=Wf(e.error);Uf.error(`Web Speech recognition error`,{error:e.error,message:e.message}),t&&s(t)},e.onend=()=>{if(c.current=null,!l.current){t(`ready`);return}Uf.info(`Web Speech recognition ended — restarting`),u()},c.current=e;try{e.start(),t(`recording`),Uf.info(`Web Speech recognition started`)}catch(e){c.current=null,l.current=!1;let n=e instanceof Error?e.message:`Unknown error`;Uf.error(`Failed to start Web Speech recognition`,{error:n}),t(`ready`),s(`Failed to start speech recognition: ${n}`)}},[]),d=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`error`)return e;t(`checking-support`),s(null),Uf.info(`Checking Web Speech API support`,{userAgent:navigator.userAgent,platform:navigator.platform});let n=yi();return r(n),n?(Uf.info(`Web Speech API available — ready`),t(`ready`),`ready`):(Uf.error(`Web Speech API not available`),t(`error`),s(`Speech recognition is not supported in this environment.`),`error`)},[e]);return{state:e,isSupported:n,transcript:i,error:o,downloadProgress:0,startListening:(0,Y.useCallback)(async()=>{l.current=!0,s(null),a(``),Uf.info(`Starting Web Speech recognition`),u()},[u]),stopListening:(0,Y.useCallback)(async()=>{l.current=!1,c.current?.stop(),c.current=null,t(`ready`),Uf.info(`Web Speech recognition stopped`)},[]),requestModelDownload:(0,Y.useCallback)(async()=>{},[]),ensureReady:d,resetTranscript:(0,Y.useCallback)(()=>{a(``),s(null)},[])}}var qf=_i(`voice.stt.vosk-hook`);function Jf(e,t){let n=e.trim(),r=t.trim();return n&&r?`${n} ${r}`:n||r}function Yf(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(0),u=(0,Y.useRef)(null),d=(0,Y.useRef)(null),f=(0,Y.useRef)(null),p=(0,Y.useRef)(null),m=(0,Y.useRef)(!1),h=(0,Y.useRef)(``),g=(0,Y.useRef)(``),_=(0,Y.useCallback)(e=>{m.current=e},[]);(0,Y.useEffect)(()=>()=>{f.current?.stop(),f.current=null,u.current?.terminate(),u.current=null},[]);let v=(0,Y.useCallback)(()=>{a(Jf(h.current,g.current))},[]),y=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`needs-model`||e===`error`)return e;if(p.current)return p.current;let n=xi();async function i(){t(`checking-support`),_(!1),l(0),s(null),qf.separator(`VOICE SESSION START`),qf.info(`Checking Vosk support`,{userAgent:navigator.userAgent,platform:navigator.platform,url:n});try{let e=new vi;u.current=e;let i=e.checkSupport();if(r(i),!i)return qf.error(`Vosk not supported in this environment`),t(`error`),s(`Local speech recognition is not supported in this environment.`),`error`;let a=new bi;d.current=a,qf.info(`Checking IndexedDB model cache`,{url:n});let o=await a.getCachedModelByUrl(n);return o?(qf.info(`Cached model found — initializing Vosk`,{sizeBytes:o.byteLength,sizeMB:(o.byteLength/1024/1024).toFixed(2)}),_(!0),t(`initializing`),await e.initModelFromBytes(o),qf.info(`Vosk model initialized from cache — ready`),t(`ready`),`ready`):(qf.info(`Model not in cache — download required`),t(`needs-model`),`needs-model`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;return qf.error(`Failed to check speech recognition support`,{error:n}),t(`error`),s(`Failed to check speech recognition support: ${n}`),`error`}}let a=i();p.current=a;try{return await a}finally{p.current=null}},[e,_]),b=(0,Y.useCallback)(async()=>{if(!u.current||!d.current)return;let e=xi();t(`downloading-model`),l(0),s(null),qf.info(`Model download requested`,{url:e});try{let n=await d.current.loadModelByUrl(e,e=>{l(e),e%10==0&&qf.debug(`Model download progress`,{progress:e})});qf.info(`Model download complete — initializing Vosk`,{sizeBytes:n.byteLength,sizeMB:(n.byteLength/1024/1024).toFixed(2)}),t(`initializing`),await u.current.initModelFromBytes(n),qf.info(`Vosk model initialized after download — ready`),_(!0),t(`ready`)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred.`;qf.error(`Model download or initialization failed`,{error:n}),t(`needs-model`),s(n)}},[_]);return{state:e,isSupported:n,transcript:i,error:o,downloadProgress:c,startListening:(0,Y.useCallback)(async()=>{if(!(!u.current||!m.current)){if(t(`requesting-mic`),s(null),h.current=``,g.current=``,a(``),qf.separator(`RECORDING START`),!navigator.mediaDevices?.getUserMedia){qf.error(`navigator.mediaDevices.getUserMedia not available`),t(`ready`),s(`Microphone is not available in this environment.`);return}try{f.current=await u.current.startMicPipeline({onPartial:e=>{g.current=e,v()},onResult:e=>{let t=h.current.trim();h.current=t?`${t} ${e}`:e,g.current=``,v()}}),t(`recording`),qf.info(`Recording started`)}catch(e){t(`ready`),e instanceof DOMException&&e.name===`NotAllowedError`?s(`Microphone access was denied. Please allow microphone access to use voice input.`):e instanceof DOMException&&e.name===`NotFoundError`?s(`No microphone was found. Please connect a microphone to use voice input.`):s(`Microphone error: ${e instanceof Error?e.message:`Unknown error`}`)}}},[v]),stopListening:(0,Y.useCallback)(async()=>{if(!f.current){qf.info(`stopListening called but no active recording`),m.current&&t(`ready`);return}t(`transcribing`),qf.info(`Stopping recording`);try{await f.current.stop(),g.current=``,v(),t(`ready`),qf.info(`Recording stopped`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;qf.error(`Failed to stop recording`,{error:n}),t(`ready`),s(`Failed to stop recording: ${n}`)}finally{f.current=null}},[v]),requestModelDownload:b,ensureReady:y,resetTranscript:(0,Y.useCallback)(()=>{h.current=``,g.current=``,a(``),s(null)},[])}}function Xf(){let e=(0,X.c)(22),t=Yf(),n=Kf();if(yt()){let n;return e[0]!==t.downloadProgress||e[1]!==t.ensureReady||e[2]!==t.error||e[3]!==t.isSupported||e[4]!==t.requestModelDownload||e[5]!==t.resetTranscript||e[6]!==t.startListening||e[7]!==t.state||e[8]!==t.stopListening||e[9]!==t.transcript?(n={state:t.state,isSupported:t.isSupported,usesLocalModel:!0,transcript:t.transcript,error:t.error,downloadProgress:t.downloadProgress,startListening:t.startListening,stopListening:t.stopListening,requestModelDownload:t.requestModelDownload,ensureReady:t.ensureReady,resetTranscript:t.resetTranscript},e[0]=t.downloadProgress,e[1]=t.ensureReady,e[2]=t.error,e[3]=t.isSupported,e[4]=t.requestModelDownload,e[5]=t.resetTranscript,e[6]=t.startListening,e[7]=t.state,e[8]=t.stopListening,e[9]=t.transcript,e[10]=n):n=e[10],n}let r;return e[11]!==n.downloadProgress||e[12]!==n.ensureReady||e[13]!==n.error||e[14]!==n.isSupported||e[15]!==n.requestModelDownload||e[16]!==n.resetTranscript||e[17]!==n.startListening||e[18]!==n.state||e[19]!==n.stopListening||e[20]!==n.transcript?(r={state:n.state,isSupported:n.isSupported,usesLocalModel:!1,transcript:n.transcript,error:n.error,downloadProgress:n.downloadProgress,startListening:n.startListening,stopListening:n.stopListening,requestModelDownload:n.requestModelDownload,ensureReady:n.ensureReady,resetTranscript:n.resetTranscript},e[11]=n.downloadProgress,e[12]=n.ensureReady,e[13]=n.error,e[14]=n.isSupported,e[15]=n.requestModelDownload,e[16]=n.resetTranscript,e[17]=n.startListening,e[18]=n.state,e[19]=n.stopListening,e[20]=n.transcript,e[21]=r):r=e[21],r}var Zf=Y.forwardRef((e,t)=>{let n=(0,X.c)(13),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,value:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===r?o=n[5]:(o=V(`relative h-4 w-full overflow-hidden rounded-full bg-secondary`,r),n[4]=r,n[5]=o);let s=`translateX(-${100-(a||0)}%)`,c;n[6]===s?c=n[7]:(c=(0,$.jsx)(yr,{className:`h-full w-full flex-1 bg-primary transition-all`,style:{transform:s}}),n[6]=s,n[7]=c);let l;return n[8]!==i||n[9]!==t||n[10]!==o||n[11]!==c?(l=(0,$.jsx)(tr,{ref:t,className:o,...i,children:c}),n[8]=i,n[9]=t,n[10]=o,n[11]=c,n[12]=l):l=n[12],l});Zf.displayName=tr.displayName;function Qf(e,t,n){return t?`Preparing voice input…`:n<100?`Downloading voice model… ${n}%`:e?`Finishing download…`:`Downloading voice model…`}function $f(e){let t=(0,X.c)(24),{open:n,onOpenChange:i,onRetry:o,isDownloading:s,isInitializing:c,progress:l,error:u}=e,d=s||c,f;t[0]!==d||t[1]!==i?(f=function(e){d&&!e||i(e)},t[0]=d,t[1]=i,t[2]=f):f=t[2];let p=f,m=u?`Voice model download failed`:`Setting up voice input`,h;t[3]===m?h=t[4]:(h=(0,$.jsx)(Cn,{children:m}),t[3]=m,t[4]=h);let g=u?`The English voice model could not be downloaded or prepared.`:`First-time setup downloads a ~40 MB English speech model to your device.`,_;t[5]===g?_=t[6]:(_=(0,$.jsx)(be,{children:g}),t[5]=g,t[6]=_);let v;t[7]!==h||t[8]!==_?(v=(0,$.jsxs)(_t,{children:[h,_]}),t[7]=h,t[8]=_,t[9]=v):v=t[9];let y;t[10]!==u||t[11]!==s||t[12]!==c||t[13]!==i||t[14]!==o||t[15]!==l?(y=u?(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(di,{variant:`error`,className:`mb-0`,children:u}),(0,$.jsxs)(a,{children:[(0,$.jsx)(Rt,{variant:`outline`,onClick:()=>i(!1),children:`Cancel`}),(0,$.jsx)(Rt,{onClick:o,children:`Try again`})]})]}):(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(di,{variant:`info`,className:`mb-0`,children:`One-time download. After this finishes, voice input works offline and you will not need to download the model again.`}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Qr,{title:Qf(s,c,l)}),(0,$.jsx)(Zf,{value:c?100:l,className:`w-full`}),(0,$.jsx)(`p`,{className:V(r.bodyMuted,`text-center`),children:c?`Loading the model into memory. This usually takes a few seconds.`:l<100?`About 40 MB — kept on this device for future use.`:`Saving the model locally…`})]})]}),t[10]=u,t[11]=s,t[12]=c,t[13]=i,t[14]=o,t[15]=l,t[16]=y):y=t[16];let b;t[17]!==v||t[18]!==y?(b=(0,$.jsxs)(Ye,{children:[v,y]}),t[17]=v,t[18]=y,t[19]=b):b=t[19];let x;return t[20]!==p||t[21]!==n||t[22]!==b?(x=(0,$.jsx)(Ge,{open:n,onOpenChange:p,children:b}),t[20]=p,t[21]=n,t[22]=b,t[23]=x):x=t[23],x}var ep=ei(e=>(0,$.jsxs)(`slot`,{children:[(0,$.jsx)(`style`,{children:`
31
+ .recording-waveform {
32
+ display: flex;
33
+ align-items: center;
34
+ gap: 2px;
35
+ height: 16px;
36
+ }
37
+ .recording-waveform-bar {
38
+ display: block;
39
+ width: 3px;
40
+ height: 4px;
41
+ border-radius: 2px;
42
+ background: currentColor;
43
+ animation: waveform-bounce 0.7s ease-in-out infinite alternate;
44
+ }
45
+ @keyframes waveform-bounce {
46
+ from { height: 3px; }
47
+ to { height: 14px; }
48
+ }
49
+ `}),e.v0,e.v1]}),{name:`SpeechInput_1`,portals:[`v0`,`v1`]}),tp=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}=Xf(),{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,E=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 D(){h(!0),u()}let O=(0,Y.useCallback)(async()=>{if(b){l();return}if(x){D();return}if(n===`ready`){f(),c();return}if(n===`idle`){let e=await d();e===`needs-model`?D():e===`ready`&&(f(),c())}},[x,b,n,d,l,c,f,u]),k=(0,Y.useCallback)(()=>{u()},[u]);(0,Y.useEffect)(()=>{n===`ready`&&m&&h(!1)},[n,m]);let A=(0,Y.useCallback)(()=>E?`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,E,w,v,y,r,x]),j=(0,Y.useCallback)(()=>w||y?(0,$.jsx)(cn,{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)(Kt,{className:`h-3 w-3`}),[w,v,y]),M=A(),N=b?M:`Voice input`;return(0,$.jsx)(ep,{v0:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:t({onClick:O,disabled:E||w||y||r===!1,icon:j(),label:M,isRecording:v,isTranscribing:y,isDownloading:w,needsModel:x,isSupported:r!==!1})}),(0,$.jsx)(T,{side:`top`,className:`bg-popover text-popover-foreground max-w-64`,children:N})]}),v1:i?(0,$.jsx)($f,{open:m,onOpenChange:h,onRetry:k,isDownloading:S,isInitializing:C,progress:s,error:m?o:null}):null})};function np(e){let t=(0,X.c)(8),{queuedMessages:n,onRemoveQueuedMessage:i}=e;if(n.length===0)return null;let a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`div`,{className:V(r.compact,r.label,`text-muted-foreground`),children:`Queued messages`}),t[0]=a):a=t[0];let o;if(t[1]!==i||t[2]!==n){let e;t[4]===i?e=t[5]:(e=e=>(0,$.jsxs)(`div`,{className:V(r.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:()=>i(e.id),"aria-label":`Remove queued message`,children:(0,$.jsx)(Ce,{className:`h-3.5 w-3.5`})})]},e.id),t[4]=i,t[5]=e),o=n.map(e),t[1]=i,t[2]=n,t[3]=o}else o=t[3];let s;return t[6]===o?s=t[7]:(s=(0,$.jsxs)(di,{className:`mb-3 border border-border/60 bg-muted/30 px-4 py-3`,children:[a,(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:o})]}),t[6]=o,t[7]=s),s}function rp(e){let t=(0,X.c)(27),{onSpeechClick:n,speechDisabled:r,icon:i,label:a,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:l,hasMessageText:u,setIsVoiceActive:d,isStreaming:f,disabled:p,canSubmitMessage:m,attachmentsLength:h,effectiveModel:g,onStop:_,onSend:v}=e,y=o||s||c,b,x;t[0]!==y||t[1]!==d?(b=()=>{d(y)},x=[y,d],t[0]=y,t[1]=d,t[2]=b,t[3]=x):(b=t[2],x=t[3]),(0,Y.useEffect)(b,x);let S=!f&&!y&&((p??!1)||!m&&r||!u&&h>0&&!g||u&&!g),C;t[4]!==m||t[5]!==f||t[6]!==y||t[7]!==v||t[8]!==n||t[9]!==_?(C=function(){if(f){_?.();return}if(y){n();return}if(m){v();return}n()},t[4]=m,t[5]=f,t[6]=y,t[7]=v,t[8]=n,t[9]=_,t[10]=C):C=t[10];let w=C,T=f?`Stop generation`:y?a:m?`Send message`:a,E=`relative h-7 w-7 rounded-full ${o?`bg-primary text-primary-foreground hover:bg-primary/90`:``} ${f?`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`:``}`,D;t[11]!==m||t[12]!==i||t[13]!==f||t[14]!==y?(D=f?(0,$.jsx)(`span`,{className:`block h-3 w-3 shrink-0 rounded-[2px] bg-current`,"aria-hidden":`true`}):y||!m?i:(0,$.jsx)(nt,{className:`h-3 w-3`}),t[11]=m,t[12]=i,t[13]=f,t[14]=y,t[15]=D):D=t[15];let O;t[16]===T?O=t[17]:(O=(0,$.jsx)(`span`,{className:`sr-only`,children:T}),t[16]=T,t[17]=O);let k;t[18]===l?k=t[19]:(k=!l&&(0,$.jsx)(`span`,{className:`sr-only`,children:`Voice input not supported`}),t[18]=l,t[19]=k);let A;return t[20]!==w||t[21]!==S||t[22]!==E||t[23]!==D||t[24]!==O||t[25]!==k?(A=(0,$.jsxs)(Rt,{size:`icon`,className:E,onClick:w,disabled:S,children:[D,O,k]}),t[20]=w,t[21]=S,t[22]=E,t[23]=D,t[24]=O,t[25]=k,t[26]=A):A=t[26],A}function ip(e){let t=(0,X.c)(197),{planMode:n,setPlanMode:i,onSend:a,onStop:s,isStreaming:c,disabled:l,initialValue:u,queuedMessages:d,onRemoveQueuedMessage:f,isOverlay:p,userTasks:m,onMatchedUserTaskSend:g,onUserTaskCreated:_}=e,v=c===void 0?!1:c,y=p===void 0?!1:p,b;t[0]===m?b=t[1]:(b=m===void 0?[]:m,t[0]=m,t[1]=b);let x=b,S;t[2]===u?S=t[3]:(S={initialValue:u},t[2]=u,t[3]=S);let{message:C,setMessage:w,historyIndex:E,setHistoryIndex:D,draftMessage:O,setDraftMessage:k,cursorPosition:A,setCursorPosition:j,availableModels:M,selectedModel:N,setSelectedModel:P,attachments:F,setAttachments:I,planMode:L,setPlanMode:R,ralphMode:ee,setRalphMode:z,imageMode:te,setImageMode:ne,availableImageModels:re,selectedImageModel:ie,setSelectedImageModel:ae,allFiles:oe,setAllFiles:se,showSuggestions:ce,setShowSuggestions:le,suggestionQuery:ue,setSuggestionQuery:de,selectedIndex:fe,setSelectedIndex:H,slashCommands:pe,skills:me,bundledSkills:he,bundledSkillMode:ge,setBundledSkillMode:_e,showCommandSuggestions:ve,setShowCommandSuggestions:ye,commandQuery:be,setCommandQuery:xe,fileInputRef:Se,textareaRef:W,suggestionsRef:we,commandSuggestionsRef:Te,selectedThreadId:Ee,dispatch:De}=Nd(S),{paneId:Oe,conversationId:ke,setFocused:Ae,fillPane:je}=gd(),Me=Q(pp),Ne=Q(fp),Pe=Oe===`secondary`?Ne:Me,Fe=Q(dp),{isDualChatActive:Ie,showDualChatControls:Le,canCloseSecondary:Re,enableDualChat:ze,disableDualChat:Be}=$d(),Ve;t[4]===Pe?Ve=t[5]:(Ve=Pe.some(up),t[4]=Pe,t[5]=Ve);let He=Ve,Ue=te?ie:N,We=te?re:M,Ge;t[6]===C?Ge=t[7]:(Ge=C.trim(),t[6]=C,t[7]=Ge);let Ke=Ge.length>0,qe=Ke||F.length>0,[Ye,Xe]=Y.useState(!1),Ze=Zd(),Qe=n??L,$e=i??R,et=Ee??void 0,tt;t[8]!==oe||t[9]!==F||t[10]!==ge||t[11]!==he||t[12]!==be||t[13]!==A||t[14]!==De||t[15]!==O||t[16]!==Qe||t[17]!==$e||t[18]!==He||t[19]!==E||t[20]!==te||t[21]!==v||t[22]!==C||t[23]!==g||t[24]!==a||t[25]!==ee||t[26]!==ie||t[27]!==fe||t[28]!==N||t[29]!==se||t[30]!==I||t[31]!==_e||t[32]!==xe||t[33]!==j||t[34]!==k||t[35]!==D||t[36]!==ne||t[37]!==w||t[38]!==z||t[39]!==H||t[40]!==ye||t[41]!==le||t[42]!==de||t[43]!==ve||t[44]!==ce||t[45]!==me||t[46]!==pe||t[47]!==ue||t[48]!==et||t[49]!==W||t[50]!==x?(tt={message:C,setMessage:w,userTasks:x,onMatchedUserTaskSend:g,attachments:F,selectedModel:N,onSend:a,isStreaming:v,selectedThreadId:et,isListening:!1,stopListening:lp,resetTranscript:cp,dispatch:De,historyIndex:E,setHistoryIndex:D,draftMessage:O,setDraftMessage:k,cursorPosition:A,setCursorPosition:j,showSuggestions:ce,setShowSuggestions:le,suggestionQuery:ue,setSuggestionQuery:de,allFiles:oe,setAllFiles:se,selectedIndex:fe,setSelectedIndex:H,showCommandSuggestions:ve,setShowCommandSuggestions:ye,commandQuery:be,setCommandQuery:xe,slashCommands:pe,skills:me,bundledSkills:he,bundledSkillMode:ge,setBundledSkillMode:_e,textareaRef:W,setAttachments:I,planMode:Qe,setPlanMode:$e,ralphMode:ee,setRalphMode:z,imageMode:te,setImageMode:ne,selectedImageModel:ie,hasConversationMessages:He},t[8]=oe,t[9]=F,t[10]=ge,t[11]=he,t[12]=be,t[13]=A,t[14]=De,t[15]=O,t[16]=Qe,t[17]=$e,t[18]=He,t[19]=E,t[20]=te,t[21]=v,t[22]=C,t[23]=g,t[24]=a,t[25]=ee,t[26]=ie,t[27]=fe,t[28]=N,t[29]=se,t[30]=I,t[31]=_e,t[32]=xe,t[33]=j,t[34]=k,t[35]=D,t[36]=ne,t[37]=w,t[38]=z,t[39]=H,t[40]=ye,t[41]=le,t[42]=de,t[43]=ve,t[44]=ce,t[45]=me,t[46]=pe,t[47]=ue,t[48]=et,t[49]=W,t[50]=x,t[51]=tt):tt=t[51];let{handleSend:nt,handleKeyDown:rt,handleTextareaInput:it,insertFileReference:at,insertCommand:ot,insertSkill:st,fileSuggestions:G}=Kd(tt),ct;t[52]===w?ct=t[53]:(ct=e=>{w(t=>(t.endsWith(` `),t+e))},t[52]=w,t[53]=ct);let lt=ct,ut;t[54]===I?ut=t[55]:(ut=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(sp);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];I(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[54]=I,t[55]=ut);let dt=ut,ft;t[56]!==je||t[57]!==y?(ft=xd(je,y),t[56]=je,t[57]=y,t[58]=ft):ft=t[58];let pt=y?`border-border/50 bg-background/80 shadow-lg backdrop-blur-sm`:`border-border bg-background shadow-2xl`,mt;t[59]===pt?mt=t[60]:(mt=V(`relative flex min-w-0 flex-1 flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto`,pt),t[59]=pt,t[60]=mt);let ht;t[61]!==Re||t[62]!==Be||t[63]!==l||t[64]!==Ie||t[65]!==Oe||t[66]!==Le?(ht=Le&&Oe===`secondary`&&Ie&&(0,$.jsx)(`div`,{className:`absolute top-2 right-2 z-10 hidden md:block`,children:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{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)(Ce,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close dual chat`})]})}),(0,$.jsx)(T,{children:`Close dual chat`})]})}),t[61]=Re,t[62]=Be,t[63]=l,t[64]=Ie,t[65]=Oe,t[66]=Le,t[67]=ht):ht=t[67];let gt;t[68]!==f||t[69]!==d?(gt=(0,$.jsx)(np,{queuedMessages:d,onRemoveQueuedMessage:f}),t[68]=f,t[69]=d,t[70]=gt):gt=t[70];let _t=ee?`Describe stories for Ralph to implement autonomously...`:Qe?`Describe what you want Tarsk to plan...`:te?`Describe the image you want to generate...`:Ye?`Dictate your message...`:`Ask Tarsk anything, # for files, / for commands & skills`,vt=Le&&Oe===`secondary`&&Ie&&`md:pr-12`,yt;t[71]===vt?yt=t[72]:(yt=V(r.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`,vt),t[71]=vt,t[72]=yt);let bt;t[73]!==l||t[74]!==rt||t[75]!==dt||t[76]!==it||t[77]!==C||t[78]!==Ae||t[79]!==_t||t[80]!==yt||t[81]!==W?(bt=(0,$.jsx)(`textarea`,{ref:W,value:C,onChange:it,onKeyDown:rt,onPaste:dt,onFocus:Ae,placeholder:_t,rows:1,className:yt,disabled:l}),t[73]=l,t[74]=rt,t[75]=dt,t[76]=it,t[77]=C,t[78]=Ae,t[79]=_t,t[80]=yt,t[81]=W,t[82]=bt):bt=t[82];let xt=ge?he:me,St=ge?`//`:`/`,Ct;t[83]!==be||t[84]!==Te||t[85]!==ot||t[86]!==st||t[87]!==fe||t[88]!==H||t[89]!==ve||t[90]!==pe||t[91]!==xt||t[92]!==St?(Ct=(0,$.jsx)(rf,{visible:ve,commands:pe,skills:xt,skillReferencePrefix:St,query:be,selectedIndex:fe,onSelectCommand:ot,onSelectSkill:st,onMouseEnterSuggestion:H,containerRef:Te}),t[83]=be,t[84]=Te,t[85]=ot,t[86]=st,t[87]=fe,t[88]=H,t[89]=ve,t[90]=pe,t[91]=xt,t[92]=St,t[93]=Ct):Ct=t[93];let wt;t[94]!==G||t[95]!==at||t[96]!==fe||t[97]!==H||t[98]!==ce||t[99]!==ue||t[100]!==we?(wt=(0,$.jsx)(wf,{showSuggestions:ce,fileSuggestions:G,suggestionQuery:ue,selectedIndex:fe,onSelectFile:at,onMouseEnterSuggestion:H,containerRef:we}),t[94]=G,t[95]=at,t[96]=fe,t[97]=H,t[98]=ce,t[99]=ue,t[100]=we,t[101]=wt):wt=t[101];let Tt;t[102]!==F||t[103]!==N?.id||t[104]!==N?.name||t[105]!==N?.supportsImages||t[106]!==I?(Tt=F.length>0&&(0,$.jsxs)(`div`,{className:`px-4`,children:[(0,$.jsx)(uf,{attachments:F,onRemove:e=>I(t=>t.filter((t,n)=>n!==e))}),F.some(op)&&N?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:V(r.compact,`mb-2 flex items-center gap-1.5 text-amber-500`),children:[(0,$.jsx)(h,{className:`h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[`Images are not supported by `,N?.name||N?.id]})]})]}),t[102]=F,t[103]=N?.id,t[104]=N?.name,t[105]=N?.supportsImages,t[106]=I,t[107]=Tt):Tt=t[107];let Et;t[108]===Se?Et=t[109]:(Et=()=>Se.current?.click(),t[108]=Se,t[109]=Et);let K;t[110]!==De||t[111]!==C||t[112]!==_||t[113]!==Oe||t[114]!==I||t[115]!==w||t[116]!==Ee||t[117]!==W?(K=()=>{let e=Ee;if(!e)return;let t=C.trim();t&&o(e,t).then(t=>{_?.(t),w(``),I([]),De({type:Z.ClearChatInputDraft,threadId:Oe===`secondary`?`${e}:secondary`:e}),W.current&&(W.current.style.height=`auto`)}).catch(ap)},t[110]=De,t[111]=C,t[112]=_,t[113]=Oe,t[114]=I,t[115]=w,t[116]=Ee,t[117]=W,t[118]=K):K=t[118];let q;t[119]!==l||t[120]!==Qe||t[121]!==$e||t[122]!==Ke||t[123]!==te||t[124]!==Ze||t[125]!==ee||t[126]!==Fe||t[127]!==ne||t[128]!==z||t[129]!==Et||t[130]!==K?(q=(0,$.jsx)(zf,{disabled:l,canAddTask:Ke,showModes:Ze,planMode:Qe,imageMode:te,ralphMode:ee,setPlanMode:$e,setImageMode:ne,setRalphMode:z,projectId:Fe,onFileAttach:Et,onAddTask:K}),t[119]=l,t[120]=Qe,t[121]=$e,t[122]=Ke,t[123]=te,t[124]=Ze,t[125]=ee,t[126]=Fe,t[127]=ne,t[128]=z,t[129]=Et,t[130]=K,t[131]=q):q=t[131];let Dt=te?ae:P,Ot;t[132]!==We||t[133]!==Ue||t[134]!==Dt?(Ot=(0,$.jsx)(Mf,{availableModels:We,selectedModel:Ue,onModelSelect:Dt}),t[132]=We,t[133]=Ue,t[134]=Dt,t[135]=Ot):Ot=t[135];let kt;t[136]!==q||t[137]!==Ot?(kt=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[q,Ot]}),t[136]=q,t[137]=Ot,t[138]=kt):kt=t[138];let At;t[139]!==Qe||t[140]!==$e||t[141]!==te||t[142]!==ee||t[143]!==Fe||t[144]!==ne||t[145]!==z?(At=(0,$.jsx)(Rf,{planMode:Qe,imageMode:te,ralphMode:ee,setPlanMode:$e,setImageMode:ne,setRalphMode:z,projectId:Fe}),t[139]=Qe,t[140]=$e,t[141]=te,t[142]=ee,t[143]=Fe,t[144]=ne,t[145]=z,t[146]=At):At=t[146];let jt=Ee??void 0,Mt;t[147]!==ke||t[148]!==Pe||t[149]!==jt?(Mt=(0,$.jsx)(Sf,{threadId:jt,conversationId:ke,messages:Pe}),t[147]=ke,t[148]=Pe,t[149]=jt,t[150]=Mt):Mt=t[150];let Nt;t[151]!==F.length||t[152]!==qe||t[153]!==l||t[154]!==Ue||t[155]!==nt||t[156]!==Ke||t[157]!==v||t[158]!==s?(Nt=e=>{let{onClick:t,disabled:n,icon:r,label:i,isRecording:a,isTranscribing:o,isDownloading:c,isSupported:u}=e;return(0,$.jsx)(rp,{onSpeechClick:t,speechDisabled:n,icon:r,label:i,isRecording:a,isTranscribing:o,isDownloading:c,isSupported:u,hasMessageText:Ke,setIsVoiceActive:Xe,isStreaming:v,disabled:l,canSubmitMessage:qe,attachmentsLength:F.length,effectiveModel:Ue,onStop:s,onSend:nt})},t[151]=F.length,t[152]=qe,t[153]=l,t[154]=Ue,t[155]=nt,t[156]=Ke,t[157]=v,t[158]=s,t[159]=Nt):Nt=t[159];let Pt;t[160]!==lt||t[161]!==Nt?(Pt=(0,$.jsx)(tp,{onTranscript:lt,children:Nt}),t[160]=lt,t[161]=Nt,t[162]=Pt):Pt=t[162];let Ft;t[163]!==At||t[164]!==Mt||t[165]!==Pt?(Ft=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[At,Mt,Pt]}),t[163]=At,t[164]=Mt,t[165]=Pt,t[166]=Ft):Ft=t[166];let It;t[167]!==kt||t[168]!==Ft?(It=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[kt,Ft]}),t[167]=kt,t[168]=Ft,t[169]=It):It=t[169];let Lt;t[170]!==mt||t[171]!==ht||t[172]!==gt||t[173]!==bt||t[174]!==Ct||t[175]!==wt||t[176]!==Tt||t[177]!==It?(Lt=(0,$.jsxs)(`div`,{className:mt,children:[ht,gt,bt,Ct,wt,Tt,It]}),t[170]=mt,t[171]=ht,t[172]=gt,t[173]=bt,t[174]=Ct,t[175]=wt,t[176]=Tt,t[177]=It,t[178]=Lt):Lt=t[178];let zt;t[179]!==l||t[180]!==ze||t[181]!==Ie||t[182]!==Oe||t[183]!==Le?(zt=Le&&Oe===`primary`&&!Ie&&(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{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)(Je,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Open dual chat`})]})}),(0,$.jsx)(T,{children:`Open dual chat`})]}),t[179]=l,t[180]=ze,t[181]=Ie,t[182]=Oe,t[183]=Le,t[184]=zt):zt=t[184];let Bt;t[185]!==Lt||t[186]!==zt?(Bt=(0,$.jsxs)(`div`,{className:`relative flex min-w-0 items-center gap-1`,children:[Lt,zt]}),t[185]=Lt,t[186]=zt,t[187]=Bt):Bt=t[187];let Vt;t[188]===I?Vt=t[189]:(Vt=e=>Cf(e,e=>I(t=>[...t,...e])),t[188]=I,t[189]=Vt);let Ht;t[190]!==Se||t[191]!==Vt?(Ht=(0,$.jsx)(`input`,{ref:Se,type:`file`,multiple:!0,className:`hidden`,onChange:Vt}),t[190]=Se,t[191]=Vt,t[192]=Ht):Ht=t[192];let Ut;return t[193]!==ft||t[194]!==Bt||t[195]!==Ht?(Ut=(0,$.jsxs)(`div`,{className:ft,children:[Bt,Ht]}),t[193]=ft,t[194]=Bt,t[195]=Ht,t[196]=Ut):Ut=t[196],Ut}function ap(e){console.error(`Failed to create user task:`,e)}function op(e){return e.mimeType.startsWith(`image/`)}function sp(e){return e.type.startsWith(`image/`)}function cp(){}function lp(){}function up(e){return e.sender===`agent`}function dp(e){return e.selectedProjectId}function fp(e){return e.secondaryMessages}function pp(e){return e.messages}var mp=Un(`gitops.timing`);function hp(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}),mp.debug(`${e} step=${n} ${r}ms`)}}function i(n,r,i){t.push({step:n,ms:r}),mp.debug(`${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(` `);mp.debug(`${e} summary total=${i}ms slowest=${a.step}@${a.ms}ms breakdown=[${o}]${r?` ${r}`:``}`)}return{step:r,record:i,summary:a}}var gp=3e4,_p={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},vp=new Map,yp=new Map;function bp(e,t){let n=vp.get(e);if(n)for(let e of n)e(t)}function xp(e,t){let n=vp.get(e);return n||(n=new Set,vp.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&vp.delete(e)}}function Sp(e){return`unified-git-status-${e}`}function Cp(e){return D.getSync(Sp(e))}function wp(e){let[t,n]=(0,Y.useState)(_p),[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=hp(`hook fetch thread=${e} force=${t}`),a=setTimeout(()=>{o.current===n&&i(!0)},100);try{let i=Sp(e),a=performance.now(),c=Cp(e);r.record(`local-cache-check`,Math.round(performance.now()-a),`result=${c?`hit`:`miss`}`),t&&(D.invalidate(i),r.record(`invalidate-local-cache`,0));let l=await r.step(`ttl-cache-get`,()=>D.get(i,()=>f(e,t,!1),gp));if(o.current!==n){r.summary(`stale-request`);return}await r.step(`update-state`,async()=>{s(l),bp(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 xp(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(_p)});return}let t=a.current!==e,r=Cp(e);t&&(console.log(`[gitops-timing] hook thread changed ${a.current??`none`} -> ${e}`),a.current=e),(0,Y.startTransition)(()=>{n(r??_p)}),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=yp.get(s);if(e){console.log(`[gitops-timing] hook initial fetch already in flight thread=${s}`),e.then(()=>{if(l)return;let e=Cp(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}`),yp.delete(s)});yp.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 Tp=(0,Y.createContext)(void 0);function Ep(e){let t=(0,X.c)(7),{threadId:n,fetchUnifiedStatus:r}=e,i=Q(kp),a=Q(Op),o=Q(Dp),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 Dp(e){return e.selectedThreadId}function Op(e){return e.completedThreadIds}function kp(e){return e.isStreaming}function Ap(e){let t=(0,X.c)(7),{threadId:n,children:r}=e,i=wp(n),a;t[0]!==n||t[1]!==i.fetchUnifiedStatus?(a=(0,$.jsx)(Ep,{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)(Tp.Provider,{value:i,children:[a,r]}),t[3]=r,t[4]=a,t[5]=i,t[6]=o):o=t[6],o}function jp(){let e=(0,Y.useContext)(Tp);if(e===void 0)throw Error(`useGitStatus must be used within a GitStatusProvider`);return e}var Mp=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}),Np=function(e){let t=(0,X.c)(2),{completedCount:n,totalCount:r}=e,i=Lp*(1-(r>0?n/r:0)),a=Pp/2,o;return t[0]===i?o=t[1]:(o=(0,$.jsx)(Mp,{v0:Pp,v1:Pp,v2:`0 0 ${Pp} ${Pp}`,v3:a,v4:a,v5:Ip,v6:Fp,v7:a,v8:a,v9:Ip,v10:Fp,v11:Lp,v12:i,v13:`rotate(-90 ${a} ${a})`}),t[0]=i,t[1]=o),o},Pp=40,Fp=4,Ip=10,Lp=2*Math.PI*Ip;function Rp(e){let t=(0,X.c)(13),{todos:n}=e,i;t[0]===n?i=t[1]:(i=n.filter(Bp),t[0]=n,t[1]=i);let a=i.length,o;t[2]===n.length?o=t[3]:(o=n.length===0&&(0,$.jsx)(`p`,{className:r.compact,children:`No todo items.`}),t[2]=n.length,t[3]=o);let s;t[4]===n?s=t[5]:(s=n.map(zp),t[4]=n,t[5]=s);let c;t[6]!==a||t[7]!==n.length?(c=n.length>0&&(0,$.jsxs)(`p`,{className:V(r.compact,`pt-1`),children:[a,`/`,n.length,` completed`]}),t[6]=a,t[7]=n.length,t[8]=c):c=t[8];let l;return t[9]!==o||t[10]!==s||t[11]!==c?(l=(0,$.jsxs)(`div`,{className:`space-y-1`,children:[o,s,c]}),t[9]=o,t[10]=s,t[11]=c,t[12]=l):l=t[12],l}function zp(e){return(0,$.jsxs)(`div`,{className:V(r.caption,`flex items-start gap-2`),children:[e.status===`done`?(0,$.jsx)(L,{className:`h-4 w-4 shrink-0 mt-0.5 text-brand`}):e.status===`working`?(0,$.jsx)(Fe,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(O,{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 Bp(e){return e.status===`done`}function Vp(e){let t=(0,X.c)(43),{layout:n}=e,r=n===void 0?`bar`:n,{todos:i}=(0,Y.useContext)(Sl),[a,o]=(0,Y.useState)(!1),s;t[0]===i?s=t[1]:(s=i.filter(Hp),t[0]=i,t[1]=s);let c=s.length,l=i.length-c,u=`${c} of ${i.length} complete`;if(l<=0)return null;if(r===`menu`){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>o(!0),t[2]=e):e=t[2];let n;t[3]!==c||t[4]!==i.length?(n=(0,$.jsx)(Np,{completedCount:c,totalCount:i.length}),t[3]=c,t[4]=i.length,t[5]=n):n=t[5];let r;t[6]===u?r=t[7]:(r=(0,$.jsx)(`span`,{children:u}),t[6]=u,t[7]=r);let s;t[8]!==n||t[9]!==r?(s=(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:e,children:[n,r]}),t[8]=n,t[9]=r,t[10]=s):s=t[10];let l;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(_t,{children:(0,$.jsx)(Cn,{children:`Agent Todos`})}),t[11]=l):l=t[11];let d;t[12]===i?d=t[13]:(d=(0,$.jsxs)(Ye,{className:`max-w-md`,children:[l,(0,$.jsx)(Rp,{todos:i})]}),t[12]=i,t[13]=d);let f;t[14]!==a||t[15]!==d?(f=(0,$.jsx)(Ge,{open:a,onOpenChange:o,children:d}),t[14]=a,t[15]=d,t[16]=f):f=t[16];let p;return t[17]!==s||t[18]!==f?(p=(0,$.jsxs)($.Fragment,{children:[s,f]}),t[17]=s,t[18]=f,t[19]=p):p=t[19],p}let d;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>o(!0),t[20]=d):d=t[20];let f;t[21]!==c||t[22]!==i.length?(f=(0,$.jsx)(Np,{completedCount:c,totalCount:i.length}),t[21]=c,t[22]=i.length,t[23]=f):f=t[23];let p;t[24]===u?p=t[25]:(p=(0,$.jsx)(`span`,{className:`sr-only`,children:u}),t[24]=u,t[25]=p);let m;t[26]!==f||t[27]!==p?(m=(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon`,className:`ml-2 rounded-full [&_svg]:!size-10`,onClick:d,children:[f,p]})}),t[26]=f,t[27]=p,t[28]=m):m=t[28];let h;t[29]===u?h=t[30]:(h=(0,$.jsx)(T,{children:u}),t[29]=u,t[30]=h);let g;t[31]!==m||t[32]!==h?(g=(0,$.jsx)(P,{children:(0,$.jsxs)(U,{children:[m,h]})}),t[31]=m,t[32]=h,t[33]=g):g=t[33];let _;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(_t,{children:(0,$.jsx)(Cn,{children:`Agent Todos`})}),t[34]=_):_=t[34];let v;t[35]===i?v=t[36]:(v=(0,$.jsxs)(Ye,{className:`max-w-md`,children:[_,(0,$.jsx)(Rp,{todos:i})]}),t[35]=i,t[36]=v);let y;t[37]!==a||t[38]!==v?(y=(0,$.jsx)(Ge,{open:a,onOpenChange:o,children:v}),t[37]=a,t[38]=v,t[39]=y):y=t[39];let b;return t[40]!==y||t[41]!==g?(b=(0,$.jsxs)($.Fragment,{children:[g,y]}),t[40]=y,t[41]=g,t[42]=b):b=t[42],b}function Hp(e){return e.status===`done`}function Up(e){let t=(0,X.c)(34),{tasks:n,disabled:i,onSelectTask:a,onTogglePinned:o,onRemoveTask:s,layout:c}=e,l=i===void 0?!1:i,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]===a?h=t[1]:(h=function(e){a(e),f(!1)},t[0]=a,t[1]=h);let g=h,_;t[2]!==s||t[3]!==p?(_=function(e){s(e),p===1&&f(!1)},t[2]=s,t[3]=p,t[4]=_):_=t[4];let v=_,y;t[5]===o?y=t[6]:(y=function(e){o(e)},t[5]=o,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=V(`gap-2`,S,C),t[7]=S,t[8]=C,t[9]=w):w=t[9];let E;t[10]===m?E=t[11]:(E=(0,$.jsx)(`span`,{children:m}),t[10]=m,t[11]=E);let D;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(ze,{className:`h-4 w-4 shrink-0`}),t[12]=D):D=t[12];let O;t[13]!==l||t[14]!==E||t[15]!==x||t[16]!==w?(O=(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:x,size:`sm`,className:w,disabled:l,children:[E,D]})}),t[13]=l,t[14]=E,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:V(r.compact,r.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)(je,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:V(r.body,`line-clamp-3 text-foreground`),children:e.content})]}),(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{type:`button`,variant:`ghost`,size:`icon`,className:V(`h-7 w-7 shrink-0`,e.pinned&&`text-primary hover:text-primary`),onClick:()=>b(e.id),children:[(0,$.jsx)(ve,{className:V(`h-4 w-4`,e.pinned&&`fill-current`)}),(0,$.jsx)(`span`,{className:`sr-only`,children:e.pinned?`Unpin task`:`Pin task`})]})}),(0,$.jsx)(T,{children:e.pinned?`Unpin task`:`Pin task`})]}),(0,$.jsxs)(Rt,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:()=>v(e.id),children:[(0,$.jsx)(Ce,{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)(Zc,{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)(P,{children:(0,$.jsxs)(Yc,{open:d,onOpenChange:f,children:[O,j]})}),t[30]=d,t[31]=O,t[32]=j,t[33]=M):M=t[33],M}function Wp(e){let t=(0,X.c)(23),n=kr(),r;t[0]===e?r=t[1]:(r=Ad.userTasks(e),t[0]=e,t[1]=r);let i;t[2]===e?i=t[3]:(i=()=>Ne(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(Ad.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:Ad.userTasks(e)}),t[13]=n,t[14]=e,t[15]=d):d=t[15];let f;return t[16]!==s.error||t[17]!==s.isError||t[18]!==s.isLoading||t[19]!==l||t[20]!==u||t[21]!==d?(f={userTasks:u,isLoading:s.isLoading,isError:s.isError,error:s.error,setUserTasks:l,invalidate:d},t[16]=s.error,t[17]=s.isError,t[18]=s.isLoading,t[19]=l,t[20]=u,t[21]=d,t[22]=f):f=t[22],f}function Gp(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 Kp=(0,Y.createContext)(void 0);function qp(e){let t=(0,X.c)(33),{children:n}=e,r=Ia(),{paneId:i}=gd(),a=Q(Zp),o=Q(Xp),s=Q(Yp),c=Q(Jp),{toast:l}=$a(),{userTasks:u,setUserTasks:d,isError:f}=Wp(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=Gp(o,a);await ke(a,{title:e}),s&&r({type:Z.UpdateThreadTitle,projectId:s,threadId:a,title:e});let t=await Et(a);r({type:Z.ClearMessages}),console.log(`New conversation started:`,t),setTimeout(()=>{(async()=>{try{let e=await J(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)(Kp.Provider,{value:E,children:n}),t[30]=n,t[31]=E,t[32]=D):D=t[32],D}function Jp(e){return e.isCreatingProject}function Yp(e){return e.selectedProjectId}function Xp(e){return e.projects}function Zp(e){return e.selectedThreadId}function Qp(){let e=(0,Y.useContext)(Kp);if(e===void 0)throw Error(`useChatInputToolbar must be used within a ChatInputToolbarProvider`);return e}var $p=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)(cn,{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)(cn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))};function em({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){return t?e.map(([e,t])=>(0,$.jsxs)(Wl,{children:[(0,$.jsx)(Gl,{children:e}),(0,$.jsx)(Kl,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,$.jsxs)(Jl,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(cn,{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)(Jl,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(cn,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))}function tm({threadId:e,layout:t=`bar`}){let n=Ia(),{setTerminalNotification:r,setActiveMainTab:i}=Js(),{setDevServerUrl:a}=nd(),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(new Set),u=(0,Y.useRef)(new Map);(0,Y.useEffect)(()=>((async()=>{try{let t=await De(e);if(t.length===0){s(null);return}s(t),l(new Set(t.filter(e=>e.isRunning).map(e=>e.name)))}catch{s(null)}})(),()=>{for(let e of u.current.values())e.abort();u.current.clear()}),[e]);function d(t){if(typeof t==`string`){n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}});return}if(!(!t||typeof t!=`object`)){if(id(t)){rd({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 f=async t=>{if(c.has(t.name)){let r=u.current.get(t.name);r&&(r.abort(),u.current.delete(t.name));try{await fe(e,t.name)}catch{}n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`■ ${t.friendlyName} stopped`}}),l(e=>{let n=new Set(e);return n.delete(t.name),n})}else{let i=new AbortController;u.current.set(t.name,i),l(e=>new Set([...e,t.name])),r(!0),n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`▶ ${t.friendlyName}`}});try{let r=await Dt(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{d(JSON.parse(t))}catch{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}})}}if(a.trim())try{d(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{u.current.delete(t.name),l(e=>{let n=new Set(e);return n.delete(t.name),n})}}};if(!o)return null;let p=o.reduce((e,t)=>(e[t.workspace]||(e[t.workspace]=[]),e[t.workspace].push(t),e),{}),m=Object.entries(p).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort((e,t)=>e.friendlyName.localeCompare(t.friendlyName))]),h=m.length>1;function g(e){f(e)}return t===`menu`?(0,$.jsxs)(Yc,{children:[(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(Oe,{className:`h-4 w-4 shrink-0`}),`Project Scripts`]})}),(0,$.jsx)(Zc,{align:`start`,className:`w-56 p-1`,children:(0,$.jsx)($p,{workspaceEntries:m,hasMultipleWorkspaces:h,runningScripts:c,onScriptClick:g})})]}):(0,$.jsxs)(Hl,{children:[(0,$.jsx)(P,{children:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Ul,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`action`,size:`icon-md`,children:(0,$.jsx)(Oe,{})})})}),(0,$.jsx)(T,{children:`Project Scripts`})]})}),(0,$.jsx)(ql,{align:`end`,className:`min-w-[180px]`,children:(0,$.jsx)(em,{workspaceEntries:m,hasMultipleWorkspaces:h,runningScripts:c,onScriptClick:g})})]})}var nm=`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 rm({open:e,onOpenChange:t,projectId:n,commands:a,onRefresh:o}){let[s,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),b=(0,Y.useRef)(null),x=()=>{c({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),f(!1),m([])},S=e=>{c({...e}),f(!1),m([])},C=async()=>{try{v(!0);let e=await kt(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)}},w=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&&w(p[h])):e.key===`Escape`&&(e.preventDefault(),f(!1),m([])))};(0,Y.useEffect)(()=>{let e=e=>{b.current&&!b.current.contains(e.target)&&(f(!1),m([]))};return d&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[d]);let D=async e=>{try{await It(n,e),Qa({title:`Success`,description:`Command deleted`}),o()}catch{Qa({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(Ge,{open:e,onOpenChange:t,children:(0,$.jsxs)(Ye,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(_t,{children:[(0,$.jsx)(Cn,{children:`Project Commands`}),(0,$.jsx)(be,{children:`Manage custom commands for this project.`})]}),(0,$.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:s?(0,$.jsxs)(`div`,{className:`p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(R,{id:`name`,value:s.name,onChange:e=>c({...s,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,$.jsx)(z,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ra,{ref:y,id:`commandLine`,value:s.commandLine,onChange:e=>c({...s,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)(P,{children:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void C(),disabled:_,children:(0,$.jsx)(i,{className:`h-4 w-4`})})}),(0,$.jsx)(T,{children:(0,$.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),d&&(0,$.jsx)(`div`,{ref:b,className:`absolute bottom-full left-0 right-0 mb-2 max-h-60 overflow-y-auto rounded-lg border border-border bg-popover shadow-lg z-50`,children:(0,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.jsxs)(`div`,{className:V(r.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),children:[(0,$.jsx)(i,{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 i=e[t].sort((e,t)=>e.name.localeCompare(t.name));return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:V(r.dropdownGroupHeading,`px-3 py-1.5 text-muted-foreground/70 bg-muted/30`),children:t}),i.map(e=>{let t=n===h;return n++,(0,$.jsxs)(`button`,{type:`button`,className:V(`flex w-full flex-col gap-1 rounded-lg mx-1 px-3 py-2 text-left transition-colors`,t?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>w(e),onMouseEnter:()=>g(n-1),children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:V(r.caption,`font-mono`),children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:V(r.caption,`px-3 py-4 text-center`),children:_?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(R,{id:`relativeFolder`,value:s.relativeFolder??``,onChange:e=>c({...s,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,$.jsx)(`p`,{className:r.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)(z,{children:`Icon`}),(0,$.jsx)(P,{children:(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:nm.map(e=>{let t=it[e]||fn;return(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{variant:s.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>c({...s,icon:e}),children:(0,$.jsx)(t,{className:`h-4 w-4`})})}),(0,$.jsx)(T,{children:e})]},e)})})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:[(0,$.jsx)(Ce,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsxs)(Rt,{size:`sm`,onClick:async()=>{if(!s?.name||!s?.commandLine){Qa({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{u(!0),await K(n,s),Qa({title:`Success`,description:`Command saved`}),c(null),o()}catch{Qa({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{u(!1)}},disabled:l,children:[(0,$.jsx)(bt,{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:[a.length===0&&(0,$.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No commands defined yet.`}),a.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-md border border-border bg-card hover:bg-muted/50 cursor-pointer group transition-colors`,onClick:()=>S(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,$.jsx)(it[e.icon]||Ke,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:r.label,children:e.name}),(0,$.jsx)(`span`,{className:V(r.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)(Rt,{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(),D(e.id)},children:(0,$.jsx)(Bt,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(Rt,{variant:`outline`,className:`w-full border-dashed`,onClick:x,children:[(0,$.jsx)(Le,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function im(e){let t=(0,X.c)(37),{layout:n}=e,r=n===void 0?`bar`:n,i=Q(sm),a=Q(om),o=Q(am),s=Ia(),{terminalState:c,dispatch:l}=La(a),[u,d]=(0,Y.useState)(!1),f=c.isRunning||c.queuedCommand!==null,p,m,h,g,_;if(t[0]!==s||t[1]!==l||t[2]!==f||t[3]!==r||t[4]!==o||t[5]!==i||t[6]!==a||t[7]!==u){_=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),p=o.find(e)?.commands??[];let n;t[15]!==l||t[16]!==i||t[17]!==a?(n=e=>{!i||!a||l({type:Z.QueueTerminalCommand,command:e.commandLine,relativeFolder:e.relativeFolder})},t[15]=l,t[16]=i,t[17]=a,t[18]=n):n=t[18];let c=n,v;if(t[19]===s?v=t[20]:(v=async()=>{s({type:Z.ConfigUpdated})},t[19]=s,t[20]=v),m=v,!i){_=null;break bb0}if(r===`menu`){let e;t[21]!==c||t[22]!==f?(e=e=>{let t=it[e.icon]||Ke;return(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:V(`relative w-full justify-start gap-2`,f&&`text-primary`,f&&`before:absolute before:inset-[-1px] before:rounded-md before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`),onClick:()=>c({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:f,children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0`}),e.name]},e.id)},t[21]=c,t[22]=f,t[23]=e):e=t[23];let n,r;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>d(!0),n=(0,$.jsx)(Hn,{className:`h-4 w-4 shrink-0`}),t[24]=n,t[25]=r):(n=t[24],r=t[25]);let a=p.length===0?`Project Commands`:`Manage commands`,o;t[26]===a?o=t[27]:(o=(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:r,children:[n,a]}),t[26]=a,t[27]=o),_=(0,$.jsxs)($.Fragment,{children:[p.map(e),o,(0,$.jsx)(rm,{open:u,onOpenChange:d,projectId:i,commands:p,onRefresh:m})]});break bb0}h=`flex items-center gap-1`,g=p.length===0?(0,$.jsx)(P,{children:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`action`,size:`icon-md`,onClick:()=>d(!0),children:(0,$.jsx)(Hn,{})})}),(0,$.jsx)(T,{children:`Manage commands`})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(P,{children:[p.map(e=>{let t=it[e.icon]||Ke;return(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`action`,size:`icon-md`,className:V(`relative`,f&&`bg-primary/10 text-primary`,f&&`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`),onClick:()=>c({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:f,children:(0,$.jsx)(t,{})})}),(0,$.jsx)(T,{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)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>d(!0),children:(0,$.jsx)(Hn,{})})}),(0,$.jsx)(T,{children:`Manage commands`})]})]})})}t[0]=s,t[1]=l,t[2]=f,t[3]=r,t[4]=o,t[5]=i,t[6]=a,t[7]=u,t[8]=p,t[9]=m,t[10]=h,t[11]=g,t[12]=_}else p=t[8],m=t[9],h=t[10],g=t[11],_=t[12];if(_!==Symbol.for(`react.early_return_sentinel`))return _;let v;t[28]!==p||t[29]!==m||t[30]!==i||t[31]!==u?(v=(0,$.jsx)(rm,{open:u,onOpenChange:d,projectId:i,commands:p,onRefresh:m}),t[28]=p,t[29]=m,t[30]=i,t[31]=u,t[32]=v):v=t[32];let y;return t[33]!==h||t[34]!==g||t[35]!==v?(y=(0,$.jsxs)(`div`,{className:h,children:[g,v]}),t[33]=h,t[34]=g,t[35]=v,t[36]=y):y=t[36],y}function am(e){return e.projects}function om(e){return e.selectedThreadId}function sm(e){return e.selectedProjectId}var cm=`VS Code`;function lm(e){return e||jn(cm)}var um={"VS Code":`vscode`,Antigravity:`antigravity`,Cursor:`cursor`,"Devin Desktop":`devin`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function dm({projectId:e,threadId:t,openWith:n,layout:r=`bar`}){let[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(()=>lm(n)),[d,f]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{let e=await xt();c(e);let t=lm(n);e.includes(t)?u(t):e.length>0&&u(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),c([cm])}finally{f(!1)}})()},[]),(0,Y.useEffect)(()=>{if(n&&s.includes(n)){u(n);return}let e=jn(cm);!n&&s.includes(e)&&u(e)},[n,s]);async function p(t){u(t),pe(t),await Wn(e,t)}let m=async n=>{try{o(!0),await p(n),t?await ct(t,n):await yn(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{o(!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)(Rt,{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)(Rt,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,disabled:a,onClick:()=>{g()},children:[(0,$.jsx)(`img`,{src:`/ide/${um[l]||um[cm]}.svg`,alt:l,className:`h-4 w-4 shrink-0`}),`Open in `,l]}),(0,$.jsxs)(Yc,{children:[(0,$.jsx)(Xc,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(i,{className:`h-4 w-4 shrink-0`}),`Change IDE`]})}),(0,$.jsx)(Zc,{align:`start`,className:`w-56 p-1`,children:s.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>{h(e)},disabled:a,children:[(0,$.jsx)(`img`,{src:`/ide/${um[e]||um[cm]}.svg`,alt:e,className:`h-4 w-4 shrink-0`}),e]},e))})]})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:a,onClick:g,children:(0,$.jsx)(`img`,{src:`/ide/${um[l]||um[cm]}.svg`,alt:l,className:`h-4 w-4`})})}),(0,$.jsx)(T,{children:`Open in ${l}`})]}),(0,$.jsxs)(Hl,{children:[(0,$.jsx)(Ul,{asChild:!0,children:(0,$.jsx)(Rt,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:a,children:(0,$.jsx)(i,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(ql,{align:`end`,children:s.map(e=>(0,$.jsxs)(Jl,{onClick:()=>void h(e),disabled:a,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${um[e]||um[cm]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}var fm=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`]}),pm=ei(e=>e.v0,{name:`RunStopButton_2`,portals:[`v0`]}),mm=ei(e=>(0,$.jsx)(`slot`,{children:e.v0}),{name:`RunStopButton_3`,portals:[`v0`]}),hm=function({projectId:e,runCommand:t,large:n,layout:i=`bar`}){let{dispatch:a}=La(Q(e=>e.selectedThreadId)),{setDevServerUrl:o,setDevServerRunning:s,setDevServerLoading:c}=nd(),{startServer:l}=ad(),{isRunning:u,isLoading:d}=cd(e),f=(0,Y.useRef)(!1),p=()=>{l({projectId:e,runCommand:t||``})},m=async()=>{f.current=!0,c(!0);try{await g(e),s(!1),o(null),a({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server stopped`}})}catch(e){let t=e instanceof Error?e.message:`Failed to stop dev server`;a({type:Z.AppendTerminalLine,line:{type:`error`,content:t}}),Qa({title:`Error`,description:t,variant:`destructive`})}finally{c(!1)}},h=!!t,_=d?`Starting...`:u?`Stop dev server`:`Start dev server`;return n?(0,$.jsx)(fm,{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)(cn,{className:`h-10 w-10 animate-spin`}):u?(0,$.jsx)(me,{className:`h-10 w-10 fill-current`}):(0,$.jsx)(Ke,{className:`h-10 w-10 fill-current group-hover:text-foreground transition-colors`}),v4:V(r.body,`group-hover:text-foreground transition-colors`),v5:_}):i===`menu`?(0,$.jsx)(pm,{v0:(0,$.jsxs)(Rt,{variant:`ghost`,size:`sm`,className:V(`w-full justify-start gap-2`,u&&`text-orange-500`),onClick:u?m:p,disabled:d||!u&&!h,children:[d?(0,$.jsx)(cn,{className:`h-4 w-4 shrink-0 animate-spin`}):u?(0,$.jsx)(me,{className:`h-4 w-4 shrink-0 fill-current`}):(0,$.jsx)(Ke,{className:`h-4 w-4 shrink-0`}),_]})}):(0,$.jsx)(mm,{v0:(0,$.jsx)(P,{children:(0,$.jsxs)(U,{children:[(0,$.jsx)(B,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`ghost`,size:`icon`,className:V(`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)(cn,{className:`h-4 w-4 animate-spin`}):u?(0,$.jsx)(me,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(Ke,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:u?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(T,{children:u?`Stop dev server`:h?`Start dev server: ${t}`:`Set run command in project settings`})]})})})};function gm(e){let t=(0,X.c)(31),{currentBranch:n,availableBranches:i,isLoadingBranches:a,isCheckingOut:o,onLoadBranches:s,onCheckoutBranch:c,onCreateBranch:l,onRenameBranch:u}=e,d;t[0]===s?d=t[1]:(d=e=>{e&&s()},t[0]=s,t[1]=d);let f,p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=V(r.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)(x,{className:`h-3.5 w-3.5 shrink-0`}),t[2]=f,t[3]=p):(f=t[2],p=t[3]);let m=n||`Unknown`,h;t[4]===m?h=t[5]:(h=(0,$.jsx)(Ul,{asChild:!0,children:(0,$.jsxs)(Rt,{variant:`outline`,size:`sm`,className:f,children:[p,m]})}),t[4]=m,t[5]=h);let g,_;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(Le,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),_=(0,$.jsx)(`span`,{children:`Create branch`}),t[6]=g,t[7]=_):(g=t[6],_=t[7]);let v;t[8]!==o||t[9]!==l?(v=(0,$.jsxs)(Jl,{onClick:l,disabled:o,children:[g,_]}),t[8]=o,t[9]=l,t[10]=v):v=t[10];let y,b;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(vt,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),y=(0,$.jsx)(`span`,{children:`Rename branch`}),t[11]=y,t[12]=b):(y=t[11],b=t[12]);let S;t[13]!==o||t[14]!==u?(S=(0,$.jsxs)(Jl,{onClick:u,disabled:o,children:[b,y]}),t[13]=o,t[14]=u,t[15]=S):S=t[15];let C;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Ql,{}),t[16]=C):C=t[16];let w;t[17]!==i||t[18]!==n||t[19]!==o||t[20]!==a||t[21]!==c?(w=a?(0,$.jsxs)(`div`,{className:V(r.compact,`px-2 py-1.5 text-muted-foreground flex items-center gap-2`),children:[(0,$.jsx)(cn,{className:`h-3 w-3 animate-spin`}),`Loading branches...`]}):i.length===0?(0,$.jsx)(`div`,{className:V(r.compact,`px-2 py-1.5 text-muted-foreground`),children:`No branches found`}):(0,$.jsx)(`div`,{className:`max-h-[300px] overflow-y-auto`,children:i.map(e=>(0,$.jsxs)(Jl,{disabled:e===n||o,onClick:()=>c(e),children:[(0,$.jsx)(x,{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:V(r.compact,`ml-auto text-muted-foreground`),children:`current`})]},e))}),t[17]=i,t[18]=n,t[19]=o,t[20]=a,t[21]=c,t[22]=w):w=t[22];let T;t[23]!==S||t[24]!==w||t[25]!==v?(T=(0,$.jsxs)(ql,{align:`start`,children:[v,S,C,w]}),t[23]=S,t[24]=w,t[25]=v,t[26]=T):T=t[26];let E;return t[27]!==d||t[28]!==T||t[29]!==h?(E=(0,$.jsxs)(Hl,{onOpenChange:d,children:[h,T]}),t[27]=d,t[28]=T,t[29]=h,t[30]=E):E=t[30],E}function _m(){return{autoGenerateCommitMessage:wt(),autoGeneratePRInfo:ln(),privateRepositoryDefault:Bn(),newChatOnNewBranch:Qe()}}function vm(e){e.autoGenerateCommitMessage!==void 0&&Fn(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&Ee(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&Ut(e.privateRepositoryDefault),e.newChatOnNewBranch!==void 0&&v(e.newChatOnNewBranch)}var ym=(0,Y.lazy)(()=>Xr(()=>import(`./merged-pr-dialog-D6ReZlV4.js`).then(e=>({default:e.MergedPRDialog})),__vite__mapDeps([2,3,1,4,5])));function bm({threadId:e,projectId:t}){let n=Ia(),r=Q(e=>e.projects.find(e=>e.projectId===t)),i=jp(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(()=>_m());(0,Y.useEffect)(()=>{vm(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 ke(e,{title:r}),n({type:Z.UpdateThreadTitle,projectId:t,threadId:e,title:r}),await Et(e),n({type:Z.ClearMessages}),setTimeout(()=>{(async()=>{try{let t=await J(e);n({type:Z.SetMessages,messages:t.messages})}catch(e){console.error(`Failed to refresh chat history after starting new chat:`,e)}})()},0)}en();let a=await y();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)(ym,{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 xm(e){let t=(0,X.c)(35),{open:n,onOpenChange:r,branchName:i,onBranchNameChange:o,isLoading:s,onCreateBranch:c}=e,l;t[0]!==i||t[1]!==s||t[2]!==c?(l=e=>{e.key===`Enter`&&i.trim()&&!s&&c()},t[0]=i,t[1]=s,t[2]=c,t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsxs)(_t,{children:[(0,$.jsx)(Cn,{children:`New Branch`}),(0,$.jsx)(be,{children:`Enter a name for the new branch. It will be created from the default branch.`})]}),t[4]=d):d=t[4];let f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(z,{htmlFor:`branch-name`,children:`Branch Name`}),t[5]=f):f=t[5];let p;t[6]===o?p=t[7]:(p=e=>o(e.target.value),t[6]=o,t[7]=p);let m;t[8]!==i||t[9]!==u||t[10]!==s||t[11]!==p?(m=(0,$.jsx)(`div`,{className:`grid gap-4 py-4`,children:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[f,(0,$.jsx)(R,{id:`branch-name`,placeholder:`e.g. feature/my-feature`,value:i,onChange:p,onKeyDown:u,disabled:s,autoFocus:!0})]})}),t[8]=i,t[9]=u,t[10]=s,t[11]=p,t[12]=m):m=t[12];let h;t[13]===r?h=t[14]:(h=()=>r(!1),t[13]=r,t[14]=h);let g;t[15]!==s||t[16]!==h?(g=(0,$.jsx)(Rt,{variant:`outline`,onClick:h,disabled:s,children:`Cancel`}),t[15]=s,t[16]=h,t[17]=g):g=t[17];let _;t[18]!==i||t[19]!==s?(_=s||!i.trim(),t[18]=i,t[19]=s,t[20]=_):_=t[20];let v=s?`Creating...`:`Create Branch`,y;t[21]!==c||t[22]!==_||t[23]!==v?(y=(0,$.jsx)(Rt,{onClick:c,disabled:_,children:v}),t[21]=c,t[22]=_,t[23]=v,t[24]=y):y=t[24];let b;t[25]!==y||t[26]!==g?(b=(0,$.jsxs)(a,{children:[g,y]}),t[25]=y,t[26]=g,t[27]=b):b=t[27];let x;t[28]!==b||t[29]!==m?(x=(0,$.jsxs)(Ye,{children:[d,m,b]}),t[28]=b,t[29]=m,t[30]=x):x=t[30];let S;return t[31]!==r||t[32]!==n||t[33]!==x?(S=(0,$.jsx)(Ge,{open:n,onOpenChange:r,children:x}),t[31]=r,t[32]=n,t[33]=x,t[34]=S):S=t[34],S}function Sm(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 Cm(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,currentBranch:i,availableBranches:o,branchName:s,onBranchNameChange:c,isLoading:l,onRenameBranch:u}=e,d;t[0]===o?d=t[1]:(d=new Set(o),t[0]=o,t[1]=d);let f=d,p,m;t[2]!==s||t[3]!==i||t[4]!==f?(m=s.trim(),p=Sm(m,i,f),t[2]=s,t[3]=i,t[4]=f,t[5]=p,t[6]=m):(p=t[5],m=t[6]);let h=p,g=l||h!==null,_;t[7]!==g||t[8]!==u?(_=e=>{e.key===`Enter`&&!g&&u()},t[7]=g,t[8]=u,t[9]=_):_=t[9];let v=_,y;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(Cn,{children:`Rename Branch`}),t[10]=y):y=t[10];let b;t[11]===i?b=t[12]:(b=(0,$.jsxs)(_t,{children:[y,(0,$.jsxs)(be,{children:[`Rename the current branch `,(0,$.jsx)(`span`,{className:`font-semibold`,children:i}),` to a new name.`]})]}),t[11]=i,t[12]=b);let x;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(z,{htmlFor:`rename-branch-name`,children:`New Branch Name`}),t[13]=x):x=t[13];let S;t[14]===c?S=t[15]:(S=e=>c(e.target.value),t[14]=c,t[15]=S);let C;t[16]!==s||t[17]!==v||t[18]!==l||t[19]!==S?(C=(0,$.jsx)(R,{id:`rename-branch-name`,placeholder:`e.g. feature/my-feature`,value:s,onChange:S,onKeyDown:v,disabled:l,autoFocus:!0,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1}),t[16]=s,t[17]=v,t[18]=l,t[19]=S,t[20]=C):C=t[20];let w;t[21]!==m||t[22]!==h?(w=h&&m.length>0&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:h}),t[21]=m,t[22]=h,t[23]=w):w=t[23];let T;t[24]!==C||t[25]!==w?(T=(0,$.jsx)(`div`,{className:`grid gap-4 py-4`,children:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[x,C,w]})}),t[24]=C,t[25]=w,t[26]=T):T=t[26];let E;t[27]===r?E=t[28]:(E=()=>r(!1),t[27]=r,t[28]=E);let D;t[29]!==l||t[30]!==E?(D=(0,$.jsx)(Rt,{variant:`outline`,onClick:E,disabled:l,children:`Cancel`}),t[29]=l,t[30]=E,t[31]=D):D=t[31];let O=l?`Renaming...`:`Rename Branch`,k;t[32]!==g||t[33]!==u||t[34]!==O?(k=(0,$.jsx)(Rt,{onClick:u,disabled:g,children:O}),t[32]=g,t[33]=u,t[34]=O,t[35]=k):k=t[35];let A;t[36]!==D||t[37]!==k?(A=(0,$.jsxs)(a,{children:[D,k]}),t[36]=D,t[37]=k,t[38]=A):A=t[38];let j;t[39]!==T||t[40]!==A||t[41]!==b?(j=(0,$.jsxs)(Ye,{children:[b,T,A]}),t[39]=T,t[40]=A,t[41]=b,t[42]=j):j=t[42];let M;return t[43]!==r||t[44]!==n||t[45]!==j?(M=(0,$.jsx)(Ge,{open:n,onOpenChange:r,children:j}),t[43]=r,t[44]=n,t[45]=j,t[46]=M):M=t[46],M}var wm=`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 Tm(){return wm[Math.floor(Math.random()*wm.length)]??`branch`}function Em(){let e=Tm(),t=Tm();for(;t===e;)t=Tm();return`${e}-${t}`}function Dm(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=jp();(0,Y.useEffect)(()=>{if(!s){u(``);return}u(Em())},[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 pn(e)).branches)}catch{n([])}finally{i(!1)}}}async function C(t){if(!(!e||t===x.currentBranch)){o(!0);try{await M(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 Ve(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 Om=(0,Y.lazy)(()=>Xr(()=>import(`./git-ops-button-DM9h9L8O.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([6,1,7,8,3])));function km(e){return e===`menu`?`w-full justify-start gap-2`:`gap-2`}function Am(e){let t=(0,X.c)(4),{threadId:n,projectId:r,messages:i,userTasks:a}=e,{hasChanges:o}=jp(),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 jm(e){let t=(0,X.c)(3),{hasMessages:n,onNewChat:r}=e;if(!n)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Le,{className:`h-4 w-4 shrink-0`}),t[0]=i):i=t[0];let a;return t[1]===r?a=t[2]:(a=(0,$.jsx)(`div`,{className:`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,"data-chat-toolbar":!0,children:(0,$.jsxs)(Rt,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:r,children:[i,`New Chat`]})}),t[1]=r,t[2]=a),a}function Mm(e){let t=(0,X.c)(92),{threadId:n,projectId:r,messages:i,userTasks:a,effectiveIsStreaming:o,isCreatingProject:s,onNewChat:c,onSelectUserTask:l,onToggleUserTaskPinned:u,onRemoveUserTask:d,layout:f}=e,p=f===void 0?`bar`:f,{setActiveMainTab:m}=Js(),h;t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a?(h={threadId:n,projectId:r,messages:i,userTasks:a},t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=h):h=t[4];let{hasMessages:g,hasChanges:_,isVisible:v}=Am(h),{changedFilesCount:y}=jp(),b;t[5]===p?b=t[6]:(b=km(p),t[5]=p,t[6]=b);let x=b,{currentBranch:S,availableBranches:C,isLoadingBranches:w,isCheckingOut:T,loadBranches:E,checkoutBranch:D,isRenameDialogOpen:O,setIsRenameDialogOpen:k,renameBranchName:A,setRenameBranchName:j,isRenamingBranch:M,renameBranch:N,openRenameBranchDialog:P,isCreateDialogOpen:F,setIsCreateDialogOpen:I,newBranchName:L,setNewBranchName:R,isCreatingBranch:ee,createBranch:z}=Dm(n),te=Q(Nm),ne;if(t[7]!==r||t[8]!==te){let e;t[10]===r?e=t[11]:(e=e=>e.projectId===r,t[10]=r,t[11]=e),ne=te.find(e),t[7]=r,t[8]=te,t[9]=ne}else ne=t[9];let re=ne,ie=p===`menu`&&!!n&&!!r,B=g||_||a.length>0||!!(n&&r);if(!v)return null;let ae=p===`bar`&&`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,oe=p===`menu`&&`flex flex-col items-stretch gap-1 p-1 min-w-[220px]`,se;t[12]!==ae||t[13]!==oe?(se=V(ae,oe),t[12]=ae,t[13]=oe,t[14]=se):se=t[14];let ce=p===`bar`?!0:void 0,le;t[15]!==g||t[16]!==p||t[17]!==c||t[18]!==x?(le=g&&(0,$.jsxs)(Rt,{variant:p===`menu`?`ghost`:`outline`,size:`sm`,className:x,onClick:c,children:[(0,$.jsx)(Le,{className:`h-4 w-4 shrink-0`}),`New Chat`]}),t[15]=g,t[16]=p,t[17]=c,t[18]=x,t[19]=le):le=t[19];let ue;t[20]!==y||t[21]!==_||t[22]!==p||t[23]!==m||t[24]!==x?(ue=_&&(0,$.jsxs)(Rt,{variant:p===`menu`?`ghost`:`outline`,size:`sm`,className:x,onClick:()=>m(`review`),children:[(0,$.jsx)(Pn,{className:`h-4 w-4 shrink-0`}),y,` `,y===1?`Change`:`Changes`]}),t[20]=y,t[21]=_,t[22]=p,t[23]=m,t[24]=x,t[25]=ue):ue=t[25];let de;t[26]!==o||t[27]!==s||t[28]!==p||t[29]!==d||t[30]!==l||t[31]!==u||t[32]!==n||t[33]!==a?(de=a.length>0&&(0,$.jsx)(Up,{tasks:a,disabled:o||!n&&!s,onSelectTask:l,onTogglePinned:u,onRemoveTask:d,layout:p}),t[26]=o,t[27]=s,t[28]=p,t[29]=d,t[30]=l,t[31]=u,t[32]=n,t[33]=a,t[34]=de):de=t[34];let fe;t[35]!==p||t[36]!==r||t[37]!==n?(fe=n&&r&&(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Om,{projectId:r,threadId:n,layout:p},n)}),t[35]=p,t[36]=r,t[37]=n,t[38]=fe):fe=t[38];let H;t[39]!==g||t[40]!==p?(H=g&&(0,$.jsx)(Vp,{layout:p}),t[39]=g,t[40]=p,t[41]=H):H=t[41];let pe;t[42]!==C||t[43]!==D||t[44]!==S||t[45]!==T||t[46]!==w||t[47]!==p||t[48]!==E||t[49]!==P||t[50]!==I?(pe=p===`bar`&&(0,$.jsx)(gm,{currentBranch:S,availableBranches:C,isLoadingBranches:w,isCheckingOut:T,onLoadBranches:E,onCheckoutBranch:D,onCreateBranch:()=>I(!0),onRenameBranch:P}),t[42]=C,t[43]=D,t[44]=S,t[45]=T,t[46]=w,t[47]=p,t[48]=E,t[49]=P,t[50]=I,t[51]=pe):pe=t[51];let me;t[52]!==B||t[53]!==ie?(me=ie&&B&&(0,$.jsx)(Ql,{className:`my-1`}),t[52]=B,t[53]=ie,t[54]=me):me=t[54];let he;t[55]!==r||t[56]!==re?.openWith||t[57]!==re?.runCommand||t[58]!==ie||t[59]!==n?(he=ie&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(hm,{projectId:r,runCommand:re?.runCommand,layout:`menu`}),(0,$.jsx)(tm,{threadId:n,layout:`menu`}),(0,$.jsx)(im,{layout:`menu`}),(0,$.jsx)(dm,{projectId:r,threadId:n,openWith:re?.openWith,layout:`menu`})]}),t[55]=r,t[56]=re?.openWith,t[57]=re?.runCommand,t[58]=ie,t[59]=n,t[60]=he):he=t[60];let ge;t[61]!==ue||t[62]!==de||t[63]!==fe||t[64]!==H||t[65]!==pe||t[66]!==me||t[67]!==he||t[68]!==se||t[69]!==ce||t[70]!==le?(ge=(0,$.jsxs)(`div`,{className:se,"data-chat-toolbar":ce,children:[le,ue,de,fe,H,pe,me,he]}),t[61]=ue,t[62]=de,t[63]=fe,t[64]=H,t[65]=pe,t[66]=me,t[67]=he,t[68]=se,t[69]=ce,t[70]=le,t[71]=ge):ge=t[71];let U;t[72]!==z||t[73]!==F||t[74]!==ee||t[75]!==L||t[76]!==I||t[77]!==R?(U=(0,$.jsx)(xm,{open:F,onOpenChange:I,branchName:L,onBranchNameChange:R,isLoading:ee,onCreateBranch:z}),t[72]=z,t[73]=F,t[74]=ee,t[75]=L,t[76]=I,t[77]=R,t[78]=U):U=t[78];let _e;t[79]!==C||t[80]!==S||t[81]!==O||t[82]!==M||t[83]!==N||t[84]!==A||t[85]!==k||t[86]!==j?(_e=(0,$.jsx)(Cm,{open:O,onOpenChange:k,currentBranch:S,availableBranches:C,branchName:A,onBranchNameChange:j,isLoading:M,onRenameBranch:N}),t[79]=C,t[80]=S,t[81]=O,t[82]=M,t[83]=N,t[84]=A,t[85]=k,t[86]=j,t[87]=_e):_e=t[87];let ve;return t[88]!==ge||t[89]!==U||t[90]!==_e?(ve=(0,$.jsxs)($.Fragment,{children:[ge,U,_e]}),t[88]=ge,t[89]=U,t[90]=_e,t[91]=ve):ve=t[91],ve}function Nm(e){return e.projects}function Pm(e){let t=(0,X.c)(10),{mode:n,messages:r,onNewChat:i}=e,a=n===void 0?`full`:n,o;t[0]!==r||t[1]!==e.projectId||t[2]!==e.threadId||t[3]!==e.userTasks?(o={threadId:e.threadId,projectId:e.projectId,messages:r,userTasks:e.userTasks},t[0]=r,t[1]=e.projectId,t[2]=e.threadId,t[3]=e.userTasks,t[4]=o):o=t[4];let{hasMessages:s}=Am(o);if(a===`newChatOnly`){let e;return t[5]!==s||t[6]!==i?(e=(0,$.jsx)(jm,{hasMessages:s,onNewChat:i}),t[5]=s,t[6]=i,t[7]=e):e=t[7],e}let c;return t[8]===e?c=t[9]:(c=(0,$.jsx)(Mm,{...e}),t[8]=e,t[9]=c),c}function Fm(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(Pm,{...e}),t[0]=e,t[1]=n),n}function Im(){let e=(0,X.c)(21),t=Q(zm),n=Q(Rm),r=Q(Lm),{userTasks:i,handleNewChat:a,handleSelectUserTask:o,handleRemoveUserTask:s,toggleUserTaskPinned:c,effectiveIsStreaming:l,isCreatingProject:u}=Qp(),d;e[0]!==r||e[1]!==n||e[2]!==t||e[3]!==i?(d={threadId:t,projectId:n,messages:r,userTasks:i},e[0]=r,e[1]=n,e[2]=t,e[3]=i,e[4]=d):d=e[4];let{isVisible:f}=Am(d);if(!t||!f)return null;let p;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Ul,{asChild:!0,children:(0,$.jsxs)(Rt,{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)(mt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Chat actions`})]})}),e[5]=p):p=e[5];let m=n??``,h;e[6]===a?h=e[7]:(h=()=>{a()},e[6]=a,e[7]=h);let g;e[8]===s?g=e[9]:(g=e=>{s(e)},e[8]=s,e[9]=g);let _;return e[10]!==l||e[11]!==o||e[12]!==u||e[13]!==r||e[14]!==t||e[15]!==m||e[16]!==h||e[17]!==g||e[18]!==c||e[19]!==i?(_=(0,$.jsxs)(Hl,{children:[p,(0,$.jsx)(ql,{align:`end`,className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(Mm,{threadId:t,projectId:m,messages:r,userTasks:i,effectiveIsStreaming:l,isCreatingProject:u,onNewChat:h,onSelectUserTask:o,onToggleUserTaskPinned:c,onRemoveUserTask:g,layout:`menu`})})]}),e[10]=l,e[11]=o,e[12]=u,e[13]=r,e[14]=t,e[15]=m,e[16]=h,e[17]=g,e[18]=c,e[19]=i,e[20]=_):_=e[20],_}function Lm(e){return e.messages}function Rm(e){return e.selectedProjectId}function zm(e){return e.selectedThreadId}function Bm(e){let t=(0,X.c)(6),{threadId:n,children:r}=e,i=Q(Vm),a;t[0]!==i||t[1]!==n?(a=n&&i?(0,$.jsx)(bm,{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 Vm(e){return e.selectedProjectId}function Hm(e){let t=(0,X.c)(6),{threadId:n,children:r}=e,i;t[0]!==r||t[1]!==n?(i=(0,$.jsx)(Bm,{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)(Ap,{threadId:n,children:i}),t[3]=i,t[4]=n,t[5]=a):a=t[5],a}function Um(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 s;t[3]!==i||t[4]!==r?(s=(0,$.jsxs)(oi,{children:[o,(0,$.jsx)(ni,{children:(0,$.jsx)(Rt,{onClick:()=>{r(),i(`/settings/account`)},children:`Go to Account`})})]}),t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==n||t[7]!==a||t[8]!==s?(c=(0,$.jsx)(ri,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}var Wm=`tarsk-browser-tool-request`,Gm=`tarsk-ask-user-prompt`,Km=new Set,qm=new Set;function Jm(e){yt()&&window.dispatchEvent(new CustomEvent(Wm,{detail:e}))}function Ym(e,t,n){!yt()||Km.has(e)||t.action&&(Km.add(e),Jm({toolCallId:e,input:t,threadId:n}))}function Xm(e,t){qm.has(e)||(qm.add(e),window.dispatchEvent(new CustomEvent(Gm,{detail:{toolCallId:e,threadId:t}})))}function Zm(){return yt()?`views://public/browser-preview-rpc.js`:`${We()}/browser-preview-rpc.js`}async function Qm(e,t){await St(e,t)}async function $m(e,t){await pt(e,t)}var eh=new Set,th=new Map,nh=5e3;function rh(e){eh.add(e);let t=th.get(e);t&&clearTimeout(t),th.set(e,setTimeout(()=>{eh.delete(e),th.delete(e)},nh))}function ih(e){return eh.has(e)}function ah(e){return e.filter(e=>!eh.has(e))}var oh;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})(oh||={});var sh=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},ch=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,lh=e=>{let t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},i=()=>t===null?ch(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 sh(`"${e}" plugin is not implemented on ${c}`,oh.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 sh(`"${e}.${t}()" is not implemented on ${c}`,oh.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=sh,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},uh=(e=>e.Capacitor=lh(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),dh=uh.registerPlugin,fh=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 uh.Exception(e,oh.Unimplemented)}unavailable(e=`not available`){return new uh.Exception(e,oh.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)}))}},ph=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),mh=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),hh=class extends fh{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=mh(n).trim(),r=mh(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=ph(e.key),n=ph(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)}}};dh(`CapacitorCookies`,{web:()=>new hh});var gh=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)}),_h=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},vh=(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,yh=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=_h(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},bh=class extends fh{async request(e){let t=yh(e,e.webFetchExtra),n=vh(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 gh(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`}))}};dh(`CapacitorHttp`,{web:()=>new bh});var xh;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(xh||={});var Sh;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(Sh||={});var Ch=class extends fh{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`)}};dh(`SystemBars`,{web:()=>new Ch});var wh=dh(`KeepAwake`,{web:()=>Xr(()=>import(`./web-6JeYEnKU.js`).then(e=>new e.KeepAwakeWeb),[])}),Th=0;function Eh(){return typeof window<`u`&&on()}async function Dh(){if(Eh()&&(Th+=1,!(Th>1)))try{await wh.keepAwake()}catch{Th=0}}async function Oh(){if(Eh()&&Th!==0&&(--Th,!(Th>0)))try{await wh.allowSleep()}catch{Th=0}}async function kh(){if(Th=0,Eh())try{await wh.allowSleep()}catch{}}function Ah(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&&pu(e.id,e.input.code,t)}catch{}}function jh(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&&Ym(e.id,e.input,t)}catch{}}function Mh(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&&Xm(e.id,t)}catch{}}function Nh(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`&&Oc(e.id,e.input.command)}catch{}}function Ph(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`&&kc(e.toolCallId)}catch{}}async function Fh(e,t,n,r,i){let a=await J(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 Ih=/^\/compact(?:\s+(.*))?$/i,Lh=`[Compact] Compaction in progress...`;function Rh(e,t,n){return{...e,threadId:t,paneId:n}}function zh(e,t,n){let r={type:`thinking`,content:Lh,model:n};e(Rh({type:Z.SetStreaming,isStreaming:!0},t,`primary`)),e(Rh({type:Z.SetStreamModel,model:n},t,`primary`)),e(Rh({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r.content??``,segments:fa([],`thinking`,r.content??``)},t,`primary`))}function Bh(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),p=(0,Y.useRef)({primary:!1,secondary:!1}),m=Q(e=>e.selectedThreadId),h=Q(e=>e.selectedProjectId),g=Q(e=>e.queuedChatMessages),_=Q(e=>e.pendingChatMessage),v=Q(e=>e.processingThreadIds);u.current=m;function y(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=>m?g.filter(t=>t.threadId===m&&t.paneId===e):[],[g,m]),w=(0,Y.useCallback)((e,n,r)=>{let i=Li(e,r.paneId);if(r.pendingTransientRecovery){r.pendingTransientRecovery=!1,(async()=>{try{if((await Rn()).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)||(rh(e),t(Rh({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,Oh()),r.stopHandled)return;if(rh(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(Rh({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 Fh(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(Rh({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(!m)return;l(m);let n=Li(m,e),r=d.current.get(n);r&&(r.stopHandled=!0,r.controller.abort(),r.cancel?.(),d.current.delete(n),r.keepsDeviceAwake&&(r.keepsDeviceAwake=!1,Oh())),b(m);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(m,e),isThinking:!1};t({type:Z.AddMessage,message:i,threadId:m,paneId:e}),t({type:Z.ClearToolCallProgress}),t(Rh({type:Z.ResetStream},m,e)),t({type:Z.SetActiveStreamPane,paneId:null}),t({type:Z.MarkThreadCompleted,threadId:m}),t({type:Z.RemoveProcessingThread,threadId:m}),rh(m)},[m,t,r]);(0,Y.useEffect)(()=>()=>{for(let[e,n]of d.current.entries()){n.controller.abort(),n.cancel?.(),n.keepsDeviceAwake&&(n.keepsDeviceAwake=!1,Oh());let[r,i]=e.split(`:`);t(Rh({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(Rh({type:Z.ResetStream},e,i)),t({type:Z.AddProcessingThread,threadId:e}),t(Rh({type:Z.SetStreaming,isStreaming:!0},e,i)),t({type:Z.SetActiveStreamPane,paneId:i}),Dh().then(()=>{p.keepsDeviceAwake=!0}),n(f.signal).then(n=>{if(!n||f.signal.aborted){w(e,r,p);return}p.cancel=Gt(n,n=>{if(t(Rh({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(Rh({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(Rh({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(Rh({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=Eu(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(Rh({type:Z.SetStreamModel,model:n.model},e,i)),n.type===`thinking`||n.isThinking){let r=n.content??``;Ah(r,e),jh(r,e),Mh(r,e),p.assistantThinking+=r,p.segments=fa(p.segments,`thinking`,r),t(Rh({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(Rh({type:Z.SetStreamContent,content:r},e,i)),typeof r==`string`&&(Ah(r,e),jh(r,e),Mh(r,e))}else{if(p.hasStructuredContent)return;let r=n.content??``;p.assistantMessage+=r,p.segments=fa(p.segments,`content`,r),t(Rh({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(jt(t)){p.pendingTransientRecovery=!0;return}p.error=t,e===u.current&&a(t)},n=>{if(t(Rh({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(Rh({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(Rh({type:Z.SetStreamContent,content:a},e,i)),Ah(a,e),jh(a,e),Mh(a,e)):(p.assistantMessage+=a,p.segments=fa(p.segments,`content`,a),t(Rh({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&&(Nh(a),Ph(a),ua(a)?(p.hasStructuredContent=!0,p.segments=ma(p.segments,a),p.assistantMessage=ha(p.segments),t(Rh({type:Z.SetStreamContent,content:p.assistantMessage},e,i))):a.trim().startsWith(`[`)||(p.assistantMessage+=a,p.segments=fa(p.segments,`content`,a),t(Rh({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(Rh({type:Z.ResetStream},e,i));return}if(n instanceof ft){d.current.delete(c),t(Rh({type:Z.ResetStream},e,i)),s(!0);return}if(n instanceof Error&&n.message.includes(`not currently processing`)){d.current.delete(c),t(Rh({type:Z.ResetStream},e,i));return}if(n instanceof Error&&jt(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(Rh({type:Z.ResetStream},e,i))}),f},[t,w]);f.current=E,(0,Y.useEffect)(()=>{for(let e of v){let t=Li(e,`primary`);d.current.has(t)||r.getState().threadStreamingStates[t]?.isStreaming||ih(e)||E(e,t=>le(e,t),`default`,`primary`)}},[E,v,r]);let D=(0,Y.useCallback)(async(r,i,o,s,c,u,d,f,p)=>{if(!m)return;let g=m,_=y(r);a(null),l(null);let b=o.trim().match(Ih);if(b){if(r!==`primary`)return;if(_.filter(e=>e.sender===`agent`).length<2){n({title:`Nothing to compact`,description:`Start a conversation with at least two exchanges first.`});return}if(v.includes(g)||x(g,r)){n({title:`Agent is busy`,description:`Wait for the agent to finish before compacting.`});return}let e=b[1]?.trim();zh(t,g,s);try{let i=await An(g,{model:s,provider:u,instructions:e});t({type:Z.SetMessages,messages:i.messages}),t(Rh({type:Z.ResetStream},g,r)),n({title:`Conversation compacted`,description:`${i.messagesBefore} messages → ${i.messagesAfter} summary`})}catch(e){t(Rh({type:Z.ResetStream},g,r)),n({title:`Compaction failed`,description:e instanceof Error?e.message:`Failed to compact conversation`,variant:`destructive`})}return}let S=`msg-${Date.now()}`,C={messageId:S,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:C,threadId:g,paneId:r});let w;try{let e=await Se(g,S);e.success&&e.stashed&&e.checkpointRef&&(w=e.checkpointRef)}catch{}if(r===`primary`){let e=o.trim().replace(/\n/g,` `).slice(0,100);h&&(ke(g,{title:e}).catch(e=>{console.error(`Failed to update thread title:`,e)}),t({type:Z.UpdateThreadTitle,projectId:h,threadId:g,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:g,paneId:r}),t(Rh({type:Z.ResetStream},g,r)),t({type:Z.SetActiveStreamPane,paneId:null});return}t(Rh({type:Z.SetStreaming,isStreaming:!0},g,r)),t({type:Z.SetActiveStreamPane,paneId:r});try{let n=await I(o,s,e,g),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:g,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:g,paneId:r})}finally{t(Rh({type:Z.ResetStream},g,r)),t({type:Z.SetActiveStreamPane,paneId:null})}return}E(g,e=>Nn(g,o,s,c,e,u,d,p,w,i),s,r,i),d&&e?.()},[m,h,t,E,v,n,e,r]);return(0,Y.useEffect)(()=>{let e=_;if(!e||e.threadId!==m||x(m??``,`primary`))return;let n=setTimeout(()=>{t({type:Z.ClearPendingChatMessage}),D(`primary`,void 0,e.message,e.model,[],e.provider)},100);return()=>clearTimeout(n)},[_,m,t,D,r]),(0,Y.useEffect)(()=>{if(!m)return;let e,n=null;for(let i of[`primary`,`secondary`]){let a=C(i);if(a.length===0||x(m,i)||p.current[i])continue;let[o]=a;p.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),p.current[i]=!1},0);break}return()=>{e&&clearTimeout(e),n&&(p.current[n]=!1)}},[t,C,D,g,m,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(m??``,e)||y(e).length>0||!m)&&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,m,r]),showEmptyBalanceDialog:o,setShowEmptyBalanceDialog:s}}var Vh=(0,Y.createContext)(void 0);function Hh(e){let t=(0,X.c)(3),{children:n}=e,r=Bh(),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Vh.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function Uh(){let e=(0,Y.useContext)(Vh);if(e===void 0)throw Error(`useChatHandlersContext must be used within a ChatHandlersProvider`);return e}function Wh(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)(Gh,{messages:i}),t[2]=i,t[3]=a),a}function Gh(e){let t=(0,X.c)(61),{messages:n}=e,{paneId:r,conversationId:i,fillPane:a}=gd(),o=Q(Jh),s=Q(qh),c=Q(Kh),[l,u]=Y.useState(!1),{handleSend:d,handleStop:f,getQueuedMessagesForPane:p,handleRemoveQueuedMessage:m,showEmptyBalanceDialog:h,setShowEmptyBalanceDialog:g}=Uh(),{userTasks:_,setUserTasks:v,handleNewChat:y,handleSelectUserTask:b,handleRemoveUserTask:x,toggleUserTaskPinned:S,effectiveIsStreaming:C}=Qp(),w=Zd(),T;t[0]===w?T=t[1]:(T=w||on(),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=r===`primary`&&s&&(c||n.length>0||_.length>0),P=r===`secondary`&&s&&n.length>0,F;t[12]===g?F=t[13]:(F=()=>g(!1),t[12]=g,t[13]=F);let I;t[14]!==h||t[15]!==F?(I=(0,$.jsx)(Um,{open:h,onClose:F}),t[14]=h,t[15]=F,t[16]=I):I=t[16];let L;t[17]!==a||t[18]!==E?(L=bd(a,E),t[17]=a,t[18]=E,t[19]=L):L=t[19];let R;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]!==N||t[30]!==P||t[31]!==S||t[32]!==_?(R=(N||P)&&(0,$.jsx)(`div`,{className:`max-md:hidden`,children:(0,$.jsx)(Fm,{threadId:s,projectId:c??``,messages:n,userTasks:r===`primary`?_:[],effectiveIsStreaming:C,isCreatingProject:o,mode:r===`secondary`?`newChatOnly`:`full`,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]=N,t[30]=P,t[31]=S,t[32]=_,t[33]=R):R=t[33];let ee=!s&&!o,z;t[34]!==p||t[35]!==r?(z=p(r),t[34]=p,t[35]=r,t[36]=z):z=t[36];let te;t[37]===x?te=t[38]:(te=e=>{e.pinned||x(e.id)},t[37]=x,t[38]=te);let ne;t[39]===v?ne=t[40]:(ne=e=>{v(t=>[...t,e])},t[39]=v,t[40]=ne);let re;t[41]!==C||t[42]!==M||t[43]!==O||t[44]!==A||t[45]!==l||t[46]!==z||t[47]!==te||t[48]!==ne||t[49]!==ee||t[50]!==_?(re=(0,$.jsx)(ip,{planMode:l,setPlanMode:u,onSend:O,onStop:A,isStreaming:C,disabled:ee,initialValue:``,queuedMessages:z,onRemoveQueuedMessage:M,isOverlay:!1,userTasks:_,onMatchedUserTaskSend:te,onUserTaskCreated:ne}),t[41]=C,t[42]=M,t[43]=O,t[44]=A,t[45]=l,t[46]=z,t[47]=te,t[48]=ne,t[49]=ee,t[50]=_,t[51]=re):re=t[51];let ie;t[52]!==re||t[53]!==R?(ie=(0,$.jsxs)(`div`,{className:`relative`,children:[R,re]}),t[52]=re,t[53]=R,t[54]=ie):ie=t[54];let B;t[55]!==ie||t[56]!==L?(B=(0,$.jsx)(`div`,{className:L,children:ie}),t[55]=ie,t[56]=L,t[57]=B):B=t[57];let ae;return t[58]!==B||t[59]!==I?(ae=(0,$.jsxs)($.Fragment,{children:[I,B]}),t[58]=B,t[59]=I,t[60]=ae):ae=t[60],ae}function Kh(e){return e.selectedProjectId}function qh(e){return e.selectedThreadId}function Jh(e){return e.isCreatingProject}var Yh=768;function Xh(){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: ${Yh-1}px)`),t=()=>{n(window.innerWidth<Yh)};return e.addEventListener(`change`,t),n(window.innerWidth<Yh),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),!!t}function Zh(e){let t=(0,X.c)(7),{paneId:n,conversationId:r}=e,i=Ia(),a=Q($h),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 J(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 $h(e){return e.selectedThreadId}var eg=4,tg=8,ng=`(max-width: 767px)`;function rg(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(ng).matches?eg:0,s=window.matchMedia(ng).matches?0:tg;return a+o+s}function ig(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(rg(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 ag;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(ag||={});var og;(function(e){e.Body=`body`,e.Ionic=`ionic`,e.Native=`native`,e.None=`none`})(og||={});var sg=dh(`Keyboard`);function cg(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 lg(e,t){return tt()?t:e>0?e:t}function ug(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(cg(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 on()&&a.push(sg.addListener(`keyboardWillShow`,e=>{o(e.keyboardHeight)}),sg.addListener(`keyboardDidShow`,e=>{o(e.keyboardHeight)}),sg.addListener(`keyboardWillHide`,()=>{o(0)}),sg.addListener(`keyboardDidHide`,()=>{o(0)})),()=>{r?.removeEventListener(`resize`,n),r?.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n);for(let e of a)e.then(dg)}},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=lg(r,a),n[3]=r,n[4]=a,n[5]=u):u=n[5],u}function dg(e){e.remove()}function fg({paneId:e,conversationId:t,onCreateThread:n,showEmptyState:r=e===`primary`,fillPane:a=!1,onConnectRepo:o=()=>{},onNewApp:s=()=>{},onOpenFolder:c=()=>{}}){let l=Ia(),u=Q(e=>e.selectedThreadId),d=Q(e=>e.selectedProjectId),f=Q(e=>e.projects),p=Q(e=>e.projectsLoading),m=Q(e=>e.isCreatingProject),h=Q(e=>e.processingThreadIds),g=Q(e=>e.pendingChatMessage),_=Q(t=>u?Ri(t.threadStreamingStates,u,e):null),v=Q(e=>e.messages),y=Q(e=>e.secondaryMessages),b=Q(e=>e.messagesLoaded),x=Q(e=>e.secondaryMessagesLoaded),S=e===`primary`?v:y,C=e===`primary`?b:x,w=!!(u&&h.includes(u)),T=e===`primary`&&g?.threadId===u,E=_?.isStreaming??!1;Zh({paneId:e,conversationId:t});let D=(0,Y.useRef)(null),O=(0,Y.useRef)(null),k=(0,Y.useRef)(null),A=Xh(),[j,M]=(0,Y.useState)(!0),N=!!u,P=A&&N&&!j,F=ig(D,O,N),I=ug(O);function L(){l({type:Z.CloseSidebar})}return(0,$.jsx)(md,{paneId:e,conversationId:t,fillPane:a,children:(0,$.jsx)(qp,{children:(0,$.jsxs)(`div`,{ref:D,className:`relative flex h-full min-w-0 flex-col`,children:[(0,$.jsx)(Od,{ref:k,bottomInset:F,messages:S,isStreaming:E,streamingSegments:E?_?.streamingSegments??[]:[],streamingModel:E?_?.streamingModel??``:``,isCreatingProject:r?m:!1,isProcessingThread:w,hasPendingMessage:T,selectedThreadId:u,selectedProjectId:d,projects:f,projectsLoading:p,messagesLoaded:C,onSelectThread:(e,t)=>{L(),l({type:Z.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:o,onNewApp:s,onOpenFolder:c,error:null,onClearError:()=>{},onAtBottomChange:M,hideEmptyState:!r}),N&&(0,$.jsxs)(`div`,{ref:O,className:`absolute inset-x-0 z-20 max-md:px-2`,style:{bottom:I},children:[(0,$.jsx)(`div`,{className:V(`h-0 bg-gradient-to-t from-background to-transparent md:h-6`,`md:mr-4`)}),(0,$.jsx)(`div`,{className:V(`h-0 bg-background md:h-8`,`md:mr-4`)}),P&&(0,$.jsx)(`div`,{className:`mb-1 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>k.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)(i,{className:`h-4 w-4`})})}),(0,$.jsx)(`div`,{className:V(`bg-background`,`md:mr-4`),children:(0,$.jsx)(Wh,{messages:S})})]})]})})})}function pg(){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 J(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 mg=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=V(`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},hg=vr,gg=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=V(`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)(at,{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},_g=(0,Y.lazy)(()=>Xr(()=>import(`./diff-view-CFu5DBIy.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),vg=(0,Y.lazy)(()=>Xr(()=>import(`./dialogs-config-COzptu1b.js`).then(e=>e.t),__vite__mapDeps([3,1])));function yg(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(xg),d=Q(bg),{isDualChatActive:f}=$d(),p=Xh(),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 Mn(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 we(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 an(),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;pg();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)(_g,{threadId:u,onExit:A})}):j&&f&&!p?(0,$.jsxs)(mg,{direction:`horizontal`,className:`h-full`,children:[(0,$.jsx)(hg,{defaultSize:50,minSize:30,children:(0,$.jsx)(fg,{paneId:`primary`,fillPane:!0,onCreateThread:n,showEmptyState:!0,onConnectRepo:_,onNewApp:y,onOpenFolder:T})}),(0,$.jsx)(gg,{withHandle:!0}),(0,$.jsx)(hg,{defaultSize:50,minSize:30,className:`border-l border-border`,children:(0,$.jsx)(fg,{paneId:`secondary`,fillPane:!0,conversationId:d??void 0,onCreateThread:n,showEmptyState:!1})})]}):j?(0,$.jsx)(fg,{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)(vg,{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)(Hh,{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)(Cl,{threadId:u,children:F}),t[32]=u,t[33]=F,t[34]=I):I=t[34],I}function bg(e){return e.secondaryConversationId}function xg(e){return e.selectedThreadId}function Sg(e){let t=(0,X.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=V(`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 Cg(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 wg;(function(e){e.Heavy=`HEAVY`,e.Medium=`MEDIUM`,e.Light=`LIGHT`})(wg||={});var Tg;(function(e){e.Success=`SUCCESS`,e.Warning=`WARNING`,e.Error=`ERROR`})(Tg||={});var Eg=dh(`Haptics`,{web:()=>Xr(()=>import(`./web-Dgmyivst.js`).then(e=>new e.HapticsWeb),[])});function Dg(){return typeof window<`u`&&on()}function Og(e=wg.Medium){Dg()&&Eg.impact({style:e}).catch(()=>{})}function kg(){let e=(0,X.c)(49),t=Ia(),n=Q(Pg),i=Q(Ng),a=Q(Mg),o=Q(jg),s=Q(Ag),{handleNewChat:c}=Qp(),l=s.length>0,u;if(e[0]!==a||e[1]!==i){let t;e[3]===i?t=e[4]:(t=e=>e.projectId===i,e[3]=i,e[4]=t),u=a.find(t),e[0]=a,e[1]=i,e[2]=u}else u=e[2];let d=u,f=!o,p,m;if(e[5]!==f){let t=yt();p=Sg,m=V(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]===o?g=e[11]:(g=o?(0,$.jsx)(Mt,{className:`h-4 w-4`}):(0,$.jsx)(gn,{className:`h-4 w-4`}),e[10]=o,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)(Rt,{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]!==a||e[17]!==i||e[18]!==n?(y=n&&(0,$.jsx)(`span`,{className:V(r.sectionTitle,`text-foreground truncate min-w-0`),children:N(a,i)}),e[16]=a,e[17]=i,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)(Rt,{size:`icon`,className:`h-7 w-7 rounded-full md:hidden electrobun-webkit-app-region-no-drag`,onClick:()=>{Og(),c()},children:[(0,$.jsx)(Le,{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)(Im,{}),e[27]=n,e[28]=S);let C;e[29]!==d?.runCommand||e[30]!==i||e[31]!==n?(C=i&&(0,$.jsxs)(Cg,{className:`electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(hm,{projectId:i,runCommand:d?.runCommand}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(tm,{threadId:n}),(0,$.jsx)(im,{})]})]}),e[29]=d?.runCommand,e[30]=i,e[31]=n,e[32]=C):C=e[32];let w;e[33]!==d?.openWith||e[34]!==i||e[35]!==n?(w=n&&i&&(0,$.jsx)(Cg,{className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(dm,{projectId:i,threadId:n,openWith:d?.openWith})}),e[33]=d?.openWith,e[34]=i,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 E;e[40]!==T||e[41]!==x||e[42]!==S?(E=(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]=E):E=e[43];let D;return e[44]!==p||e[45]!==m||e[46]!==E||e[47]!==b?(D=(0,$.jsxs)(p,{className:m,children:[b,E]}),e[44]=p,e[45]=m,e[46]=E,e[47]=b,e[48]=D):D=e[48],D}function Ag(e){return e.messages}function jg(e){return e.sidebarOpen}function Mg(e){return e.projects}function Ng(e){return e.selectedProjectId}function Pg(e){return e.selectedThreadId}function Fg(){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 Ig=[`Chat`,`Explorer`,`Review`,`Browser`,`Terminal`,`Tasks`];function Lg(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}=Js(),{triggerExplorerRefresh:f}=Qs(),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=Ig.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 Rg=(0,Y.lazy)(()=>Xr(()=>import(`./terminal-panel-DKkr68gm.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([13,1,3,14]))),zg=(0,Y.lazy)(()=>Xr(()=>import(`./diff-view-CFu5DBIy.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),Bg=(0,Y.lazy)(()=>Xr(()=>import(`./explorer-tab-view-yR_3TyF7.js`),__vite__mapDeps([15,1,7,8,5,3]))),Vg=(0,Y.lazy)(()=>Xr(()=>import(`./browser-tab-bfjSH9LH.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([16,1,3]))),Hg=(0,Y.lazy)(()=>Xr(()=>import(`./settings-view-BX2dUb7a.js`),__vite__mapDeps([17,1,7,8,5,3,4,18,19,11]))),Ug=(0,Y.lazy)(()=>Xr(()=>import(`./todos-view-_rD_cv7x.js`).then(e=>({default:e.TodosView})),__vite__mapDeps([20,1,7,8,5,3,21,11])));function Wg(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}=Js(),h=!i&&!a,g;t[0]===h?g=t[1]:(g=h&&(0,$.jsx)(kg,{}),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)(Lg,{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)(Fg,{}),children:(0,$.jsx)(Hg,{})})}),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)(Fg,{}),children:(0,$.jsx)(Hg,{})})}),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)(Fg,{}),children:(0,$.jsx)(Hg,{})})}),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)(yg,{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)(Rg,{})}),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)(Vg,{})}),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)(Bg,{})})}),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)(Ug,{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)(zg,{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 Gg(e){let t=(0,X.c)(14),{open:n,projectName:i,onOpenChange:a,onConfirm:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)($r,{children:`Delete Project`}),t[0]=s):s=t[0];let c;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=V(r.body,`font-semibold text-foreground`),t[1]=c):c=t[1];let l;t[2]===i?l=t[3]:(l=(0,$.jsxs)(ii,{children:[s,(0,$.jsxs)(ti,{children:[`Are you sure you want to delete`,` `,(0,$.jsxs)(`span`,{className:c,children:[`"`,i,`"`]}),`? This will remove the project and all its data. This action cannot be undone.`]})]}),t[2]=i,t[3]=l);let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Zr,{children:`Cancel`}),t[4]=u):u=t[4];let d;t[5]===o?d=t[6]:(d=(0,$.jsxs)(ni,{children:[u,(0,$.jsx)(si,{onClick:o,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[5]=o,t[6]=d);let f;t[7]!==l||t[8]!==d?(f=(0,$.jsxs)(oi,{children:[l,d]}),t[7]=l,t[8]=d,t[9]=f):f=t[9];let p;return t[10]!==a||t[11]!==n||t[12]!==f?(p=(0,$.jsx)(ri,{open:n,onOpenChange:a,children:f}),t[10]=a,t[11]=n,t[12]=f,t[13]=p):p=t[13],p}function Kg(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(qg),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 qg(e,t){let n=e.match(/^cd "([^"]+)" && (.+)$/),i=n?n[1]:`root`,a=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:r.label,children:i||`root`}),(0,$.jsx)(`div`,{className:r.bodyMuted,children:a})]})]})},t)}var Jg;(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`})(Jg||={});var Yg=new Map([[Jg.QR_CODE,`QR_CODE`],[Jg.AZTEC,`AZTEC`],[Jg.CODABAR,`CODABAR`],[Jg.CODE_39,`CODE_39`],[Jg.CODE_93,`CODE_93`],[Jg.CODE_128,`CODE_128`],[Jg.DATA_MATRIX,`DATA_MATRIX`],[Jg.MAXICODE,`MAXICODE`],[Jg.ITF,`ITF`],[Jg.EAN_13,`EAN_13`],[Jg.EAN_8,`EAN_8`],[Jg.PDF_417,`PDF_417`],[Jg.RSS_14,`RSS_14`],[Jg.RSS_EXPANDED,`RSS_EXPANDED`],[Jg.UPC_A,`UPC_A`],[Jg.UPC_E,`UPC_E`],[Jg.UPC_EAN_EXTENSION,`UPC_EAN_EXTENSION`]]),Xg;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.URL=1]=`URL`})(Xg||={});function Zg(e){return Object.values(Jg).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 $g=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}(),e_=function(){function e(e,t){this.format=e,this.formatName=t}return e.prototype.toString=function(){return this.formatName},e.create=function(t){if(!Yg.has(t))throw`${t} not in html5QrcodeSupportedFormatsTextMap`;return new e(t,Yg.get(t))},e}(),t_=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}(),n_;(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`})(n_||={});var r_=function(){function e(){}return e.createFrom=function(e){return{errorMessage:e,type:n_.UNKWOWN_ERROR}},e}(),i_=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 a_(e){return e==null}function o_(e,t,n){return e>n?n:e<t?t:e}var s_=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}(),c_=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}(),l_=function(){function e(){}return e.poweredBy=function(){return`Powered by `},e.reportIssues=function(){return`Report issues`},e}(),u_=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}(),d_=e(t(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?r(e):typeof define==`function`&&define.amd?define([`exports`],r):(n=typeof globalThis<`u`?globalThis:n||self,r(n.ZXing={}))})(e,(function(e){function t(e){return e==null}var n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};function r(e,t){n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t){var n=Object.setPrototypeOf;n?n(e,t):e.__proto__=t}function a(e,t){t===void 0&&(t=e.constructor);var n=Error.captureStackTrace;n&&n(e,t)}var o=(function(e){r(t,e);function t(t){var n=this.constructor,r=e.call(this,t)||this;return Object.defineProperty(r,"name",{value:n.name,enumerable:!1}),i(r,n.prototype),a(r),r}return t})(Error);class s extends o{constructor(e=void 0){super(e),this.message=e}getKind(){return this.constructor.kind}}s.kind=`Exception`;class c extends s{}c.kind=`ArgumentException`;class l extends s{}l.kind=`IllegalArgumentException`;class u{constructor(e){if(this.binarizer=e,e===null)throw new l(`Binarizer must be non-null.`)}getWidth(){return this.binarizer.getWidth()}getHeight(){return this.binarizer.getHeight()}getBlackRow(e,t){return this.binarizer.getBlackRow(e,t)}getBlackMatrix(){return(this.matrix===null||this.matrix===void 0)&&(this.matrix=this.binarizer.getBlackMatrix()),this.matrix}isCropSupported(){return this.binarizer.getLuminanceSource().isCropSupported()}crop(e,t,n,r){let i=this.binarizer.getLuminanceSource().crop(e,t,n,r);return new u(this.binarizer.createBinarizer(i))}isRotateSupported(){return this.binarizer.getLuminanceSource().isRotateSupported()}rotateCounterClockwise(){let e=this.binarizer.getLuminanceSource().rotateCounterClockwise();return new u(this.binarizer.createBinarizer(e))}rotateCounterClockwise45(){let e=this.binarizer.getLuminanceSource().rotateCounterClockwise45();return new u(this.binarizer.createBinarizer(e))}toString(){try{return this.getBlackMatrix().toString()}catch{return``}}}class d extends s{static getChecksumInstance(){return new d}}d.kind=`ChecksumException`;class f{constructor(e){this.source=e}getLuminanceSource(){return this.source}getWidth(){return this.source.getWidth()}getHeight(){return this.source.getHeight()}}class p{static arraycopy(e,t,n,r,i){for(;i--;)n[r++]=e[t++]}static currentTimeMillis(){return Date.now()}}class m extends s{}m.kind=`IndexOutOfBoundsException`;class h extends m{constructor(e=void 0,t=void 0){super(t),this.index=e,this.message=t}}h.kind=`ArrayIndexOutOfBoundsException`;class g{static fill(e,t){for(let n=0,r=e.length;n<r;n++)e[n]=t}static fillWithin(e,t,n,r){g.rangeCheck(e.length,t,n);for(let i=t;i<n;i++)e[i]=r}static rangeCheck(e,t,n){if(t>n)throw new l(`fromIndex(`+t+`) > toIndex(`+n+`)`);if(t<0)throw new h(t);if(n>e)throw new h(n)}static asList(...e){return e}static create(e,t,n){return Array.from({length:e}).map(e=>Array.from({length:t}).fill(n))}static createInt32Array(e,t,n){return Array.from({length:e}).map(e=>Int32Array.from({length:t}).fill(n))}static equals(e,t){if(!e||!t||!e.length||!t.length||e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}static hashCode(e){if(e===null)return 0;let t=1;for(let n of e)t=31*t+n;return t}static fillUint8Array(e,t){for(let n=0;n!==e.length;n++)e[n]=t}static copyOf(e,t){return e.slice(0,t)}static copyOfUint8Array(e,t){if(e.length<=t){let n=new Uint8Array(t);return n.set(e),n}return e.slice(0,t)}static copyOfRange(e,t,n){let r=n-t,i=new Int32Array(r);return p.arraycopy(e,t,i,0,r),i}static binarySearch(e,t,n){n===void 0&&(n=g.numberComparator);let r=0,i=e.length-1;for(;r<=i;){let a=i+r>>1,o=n(t,e[a]);if(o>0)r=a+1;else if(o<0)i=a-1;else return a}return-r-1}static numberComparator(e,t){return e-t}}class _{static numberOfTrailingZeros(e){let t;if(e===0)return 32;let n=31;return t=e<<16,t!==0&&(n-=16,e=t),t=e<<8,t!==0&&(n-=8,e=t),t=e<<4,t!==0&&(n-=4,e=t),t=e<<2,t!==0&&(n-=2,e=t),n-(e<<1>>>31)}static numberOfLeadingZeros(e){if(e===0)return 32;let t=1;return e>>>16||(t+=16,e<<=16),e>>>24||(t+=8,e<<=8),e>>>28||(t+=4,e<<=4),e>>>30||(t+=2,e<<=2),t-=e>>>31,t}static toHexString(e){return e.toString(16)}static toBinaryString(e){return String(parseInt(String(e),2))}static bitCount(e){return e-=e>>>1&1431655765,e=(e&858993459)+(e>>>2&858993459),e=e+(e>>>4)&252645135,e+=e>>>8,e+=e>>>16,e&63}static truncDivision(e,t){return Math.trunc(e/t)}static parseInt(e,t=void 0){return parseInt(e,t)}}_.MIN_VALUE_32_BITS=-2147483648,_.MAX_VALUE=2**53-1;class v{constructor(e,t){e===void 0?(this.size=0,this.bits=new Int32Array(1)):(this.size=e,t==null?this.bits=v.makeArray(e):this.bits=t)}getSize(){return this.size}getSizeInBytes(){return Math.floor((this.size+7)/8)}ensureCapacity(e){if(e>this.bits.length*32){let t=v.makeArray(e);p.arraycopy(this.bits,0,t,0,this.bits.length),this.bits=t}}get(e){return(this.bits[Math.floor(e/32)]&1<<(e&31))!=0}set(e){this.bits[Math.floor(e/32)]|=1<<(e&31)}flip(e){this.bits[Math.floor(e/32)]^=1<<(e&31)}getNextSet(e){let t=this.size;if(e>=t)return t;let n=this.bits,r=Math.floor(e/32),i=n[r];i&=~((1<<(e&31))-1);let a=n.length;for(;i===0;){if(++r===a)return t;i=n[r]}let o=r*32+_.numberOfTrailingZeros(i);return o>t?t:o}getNextUnset(e){let t=this.size;if(e>=t)return t;let n=this.bits,r=Math.floor(e/32),i=~n[r];i&=~((1<<(e&31))-1);let a=n.length;for(;i===0;){if(++r===a)return t;i=~n[r]}let o=r*32+_.numberOfTrailingZeros(i);return o>t?t:o}setBulk(e,t){this.bits[Math.floor(e/32)]=t}setRange(e,t){if(t<e||e<0||t>this.size)throw new l;if(t===e)return;t--;let n=Math.floor(e/32),r=Math.floor(t/32),i=this.bits;for(let a=n;a<=r;a++){let o=a>n?0:e&31,s=(2<<(a<r?31:t&31))-(1<<o);i[a]|=s}}clear(){let e=this.bits.length,t=this.bits;for(let n=0;n<e;n++)t[n]=0}isRange(e,t,n){if(t<e||e<0||t>this.size)throw new l;if(t===e)return!0;t--;let r=Math.floor(e/32),i=Math.floor(t/32),a=this.bits;for(let o=r;o<=i;o++){let s=o>r?0:e&31,c=(2<<(o<i?31:t&31))-(1<<s)&4294967295;if((a[o]&c)!==(n?c:0))return!1}return!0}appendBit(e){this.ensureCapacity(this.size+1),e&&(this.bits[Math.floor(this.size/32)]|=1<<(this.size&31)),this.size++}appendBits(e,t){if(t<0||t>32)throw new l(`Num bits must be between 0 and 32`);this.ensureCapacity(this.size+t);for(let n=t;n>0;n--)this.appendBit((e>>n-1&1)==1)}appendBitArray(e){let t=e.size;this.ensureCapacity(this.size+t);for(let n=0;n<t;n++)this.appendBit(e.get(n))}xor(e){if(this.size!==e.size)throw new l(`Sizes don't match`);let t=this.bits;for(let n=0,r=t.length;n<r;n++)t[n]^=e.bits[n]}toBytes(e,t,n,r){for(let i=0;i<r;i++){let r=0;for(let t=0;t<8;t++)this.get(e)&&(r|=1<<7-t),e++;t[n+i]=r}}getBitArray(){return this.bits}reverse(){let e=new Int32Array(this.bits.length),t=Math.floor((this.size-1)/32),n=t+1,r=this.bits;for(let i=0;i<n;i++){let n=r[i];n=n>>1&1431655765|(n&1431655765)<<1,n=n>>2&858993459|(n&858993459)<<2,n=n>>4&252645135|(n&252645135)<<4,n=n>>8&16711935|(n&16711935)<<8,n=n>>16&65535|(n&65535)<<16,e[t-i]=n}if(this.size!==n*32){let t=n*32-this.size,r=e[0]>>>t;for(let i=1;i<n;i++){let n=e[i];r|=n<<32-t,e[i-1]=r,r=n>>>t}e[n-1]=r}this.bits=e}static makeArray(e){return new Int32Array(Math.floor((e+31)/32))}equals(e){if(!(e instanceof v))return!1;let t=e;return this.size===t.size&&g.equals(this.bits,t.bits)}hashCode(){return 31*this.size+g.hashCode(this.bits)}toString(){let e=``;for(let t=0,n=this.size;t<n;t++)t&7||(e+=` `),e+=this.get(t)?`X`:`.`;return e}clone(){return new v(this.size,this.bits.slice())}}var y;(function(e){e[e.OTHER=0]=`OTHER`,e[e.PURE_BARCODE=1]=`PURE_BARCODE`,e[e.POSSIBLE_FORMATS=2]=`POSSIBLE_FORMATS`,e[e.TRY_HARDER=3]=`TRY_HARDER`,e[e.CHARACTER_SET=4]=`CHARACTER_SET`,e[e.ALLOWED_LENGTHS=5]=`ALLOWED_LENGTHS`,e[e.ASSUME_CODE_39_CHECK_DIGIT=6]=`ASSUME_CODE_39_CHECK_DIGIT`,e[e.ASSUME_GS1=7]=`ASSUME_GS1`,e[e.RETURN_CODABAR_START_END=8]=`RETURN_CODABAR_START_END`,e[e.NEED_RESULT_POINT_CALLBACK=9]=`NEED_RESULT_POINT_CALLBACK`,e[e.ALLOWED_EAN_EXTENSIONS=10]=`ALLOWED_EAN_EXTENSIONS`})(y||={});var b=y;class x extends s{static getFormatInstance(){return new x}}x.kind=`FormatException`;var S;(function(e){e[e.Cp437=0]=`Cp437`,e[e.ISO8859_1=1]=`ISO8859_1`,e[e.ISO8859_2=2]=`ISO8859_2`,e[e.ISO8859_3=3]=`ISO8859_3`,e[e.ISO8859_4=4]=`ISO8859_4`,e[e.ISO8859_5=5]=`ISO8859_5`,e[e.ISO8859_6=6]=`ISO8859_6`,e[e.ISO8859_7=7]=`ISO8859_7`,e[e.ISO8859_8=8]=`ISO8859_8`,e[e.ISO8859_9=9]=`ISO8859_9`,e[e.ISO8859_10=10]=`ISO8859_10`,e[e.ISO8859_11=11]=`ISO8859_11`,e[e.ISO8859_13=12]=`ISO8859_13`,e[e.ISO8859_14=13]=`ISO8859_14`,e[e.ISO8859_15=14]=`ISO8859_15`,e[e.ISO8859_16=15]=`ISO8859_16`,e[e.SJIS=16]=`SJIS`,e[e.Cp1250=17]=`Cp1250`,e[e.Cp1251=18]=`Cp1251`,e[e.Cp1252=19]=`Cp1252`,e[e.Cp1256=20]=`Cp1256`,e[e.UnicodeBigUnmarked=21]=`UnicodeBigUnmarked`,e[e.UTF8=22]=`UTF8`,e[e.ASCII=23]=`ASCII`,e[e.Big5=24]=`Big5`,e[e.GB18030=25]=`GB18030`,e[e.EUC_KR=26]=`EUC_KR`})(S||={});class C{constructor(e,t,n,...r){this.valueIdentifier=e,this.name=n,typeof t==`number`?this.values=Int32Array.from([t]):this.values=t,this.otherEncodingNames=r,C.VALUE_IDENTIFIER_TO_ECI.set(e,this),C.NAME_TO_ECI.set(n,this);let i=this.values;for(let e=0,t=i.length;e!==t;e++){let t=i[e];C.VALUES_TO_ECI.set(t,this)}for(let e of r)C.NAME_TO_ECI.set(e,this)}getValueIdentifier(){return this.valueIdentifier}getName(){return this.name}getValue(){return this.values[0]}static getCharacterSetECIByValue(e){if(e<0||e>=900)throw new x(`incorect value`);let t=C.VALUES_TO_ECI.get(e);if(t===void 0)throw new x(`incorect value`);return t}static getCharacterSetECIByName(e){let t=C.NAME_TO_ECI.get(e);if(t===void 0)throw new x(`incorect value`);return t}equals(e){if(!(e instanceof C))return!1;let t=e;return this.getName()===t.getName()}}C.VALUE_IDENTIFIER_TO_ECI=new Map,C.VALUES_TO_ECI=new Map,C.NAME_TO_ECI=new Map,C.Cp437=new C(S.Cp437,Int32Array.from([0,2]),`Cp437`),C.ISO8859_1=new C(S.ISO8859_1,Int32Array.from([1,3]),`ISO-8859-1`,`ISO88591`,`ISO8859_1`),C.ISO8859_2=new C(S.ISO8859_2,4,`ISO-8859-2`,`ISO88592`,`ISO8859_2`),C.ISO8859_3=new C(S.ISO8859_3,5,`ISO-8859-3`,`ISO88593`,`ISO8859_3`),C.ISO8859_4=new C(S.ISO8859_4,6,`ISO-8859-4`,`ISO88594`,`ISO8859_4`),C.ISO8859_5=new C(S.ISO8859_5,7,`ISO-8859-5`,`ISO88595`,`ISO8859_5`),C.ISO8859_6=new C(S.ISO8859_6,8,`ISO-8859-6`,`ISO88596`,`ISO8859_6`),C.ISO8859_7=new C(S.ISO8859_7,9,`ISO-8859-7`,`ISO88597`,`ISO8859_7`),C.ISO8859_8=new C(S.ISO8859_8,10,`ISO-8859-8`,`ISO88598`,`ISO8859_8`),C.ISO8859_9=new C(S.ISO8859_9,11,`ISO-8859-9`,`ISO88599`,`ISO8859_9`),C.ISO8859_10=new C(S.ISO8859_10,12,`ISO-8859-10`,`ISO885910`,`ISO8859_10`),C.ISO8859_11=new C(S.ISO8859_11,13,`ISO-8859-11`,`ISO885911`,`ISO8859_11`),C.ISO8859_13=new C(S.ISO8859_13,15,`ISO-8859-13`,`ISO885913`,`ISO8859_13`),C.ISO8859_14=new C(S.ISO8859_14,16,`ISO-8859-14`,`ISO885914`,`ISO8859_14`),C.ISO8859_15=new C(S.ISO8859_15,17,`ISO-8859-15`,`ISO885915`,`ISO8859_15`),C.ISO8859_16=new C(S.ISO8859_16,18,`ISO-8859-16`,`ISO885916`,`ISO8859_16`),C.SJIS=new C(S.SJIS,20,`SJIS`,`Shift_JIS`),C.Cp1250=new C(S.Cp1250,21,`Cp1250`,`windows-1250`),C.Cp1251=new C(S.Cp1251,22,`Cp1251`,`windows-1251`),C.Cp1252=new C(S.Cp1252,23,`Cp1252`,`windows-1252`),C.Cp1256=new C(S.Cp1256,24,`Cp1256`,`windows-1256`),C.UnicodeBigUnmarked=new C(S.UnicodeBigUnmarked,25,`UnicodeBigUnmarked`,`UTF-16BE`,`UnicodeBig`),C.UTF8=new C(S.UTF8,26,`UTF8`,`UTF-8`),C.ASCII=new C(S.ASCII,Int32Array.from([27,170]),`ASCII`,`US-ASCII`),C.Big5=new C(S.Big5,28,`Big5`),C.GB18030=new C(S.GB18030,29,`GB18030`,`GB2312`,`EUC_CN`,`GBK`),C.EUC_KR=new C(S.EUC_KR,30,`EUC_KR`,`EUC-KR`);class w extends s{}w.kind=`UnsupportedOperationException`;class T{static decode(e,t){let n=this.encodingName(t);return this.customDecoder?this.customDecoder(e,n):typeof TextDecoder>`u`||this.shouldDecodeOnFallback(n)?this.decodeFallback(e,n):new TextDecoder(n).decode(e)}static shouldDecodeOnFallback(e){return!T.isBrowser()&&e===`ISO-8859-1`}static encode(e,t){let n=this.encodingName(t);return this.customEncoder?this.customEncoder(e,n):typeof TextEncoder>`u`?this.encodeFallback(e):new TextEncoder().encode(e)}static isBrowser(){return typeof window<`u`&&{}.toString.call(window)===`[object Window]`}static encodingName(e){return typeof e==`string`?e:e.getName()}static encodingCharacterSet(e){return e instanceof C?e:C.getCharacterSetECIByName(e)}static decodeFallback(e,t){let n=this.encodingCharacterSet(t);if(T.isDecodeFallbackSupported(n)){let t=``;for(let n=0,r=e.length;n<r;n++){let r=e[n].toString(16);r.length<2&&(r=`0`+r),t+=`%`+r}return decodeURIComponent(t)}if(n.equals(C.UnicodeBigUnmarked))return String.fromCharCode.apply(null,new Uint16Array(e.buffer));throw new w(`Encoding ${this.encodingName(t)} not supported by fallback.`)}static isDecodeFallbackSupported(e){return e.equals(C.UTF8)||e.equals(C.ISO8859_1)||e.equals(C.ASCII)}static encodeFallback(e){let t=btoa(unescape(encodeURIComponent(e))).split(``),n=[];for(let e=0;e<t.length;e++)n.push(t[e].charCodeAt(0));return new Uint8Array(n)}}class E{static castAsNonUtf8Char(e,t=null){let n=t?t.getName():this.ISO88591;return T.decode(new Uint8Array([e]),n)}static guessEncoding(e,t){if(t!=null&&t.get(b.CHARACTER_SET)!==void 0)return t.get(b.CHARACTER_SET).toString();let n=e.length,r=!0,i=!0,a=!0,o=0,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=e.length>3&&e[0]===239&&e[1]===187&&e[2]===191;for(let t=0;t<n&&(r||i||a);t++){let n=e[t]&255;a&&(o>0?n&128?o--:a=!1:n&128&&(n&64?(o++,n&32?(o++,n&16?(o++,n&8?a=!1:l++):c++):s++):a=!1)),r&&(n>127&&n<160?r=!1:n>159&&(n<192||n===215||n===247)&&g++),i&&(u>0?n<64||n===127||n>252?i=!1:u--:n===128||n===160||n>239?i=!1:n>160&&n<224?(d++,p=0,f++,f>m&&(m=f)):n>127?(u++,f=0,p++,p>h&&(h=p)):(f=0,p=0))}return a&&o>0&&(a=!1),i&&u>0&&(i=!1),a&&(_||s+c+l>0)?E.UTF8:i&&(E.ASSUME_SHIFT_JIS||m>=3||h>=3)?E.SHIFT_JIS:r&&i?m===2&&d===2||g*10>=n?E.SHIFT_JIS:E.ISO88591:r?E.ISO88591:i?E.SHIFT_JIS:a?E.UTF8:E.PLATFORM_DEFAULT_ENCODING}static format(e,...t){let n=-1;function r(e,r,i,a,o,s){if(e===`%%`)return`%`;if(t[++n]===void 0)return;e=a?parseInt(a.substr(1)):void 0;let c=o?parseInt(o.substr(1)):void 0,l;switch(s){case`s`:l=t[n];break;case`c`:l=t[n][0];break;case`f`:l=parseFloat(t[n]).toFixed(e);break;case`p`:l=parseFloat(t[n]).toPrecision(e);break;case`e`:l=parseFloat(t[n]).toExponential(e);break;case`x`:l=parseInt(t[n]).toString(c||16);break;case`d`:l=parseFloat(parseInt(t[n],c||10).toPrecision(e)).toFixed(0);break}l=typeof l==`object`?JSON.stringify(l):(+l).toString(c);let u=parseInt(i),d=i&&i[0]+``==`0`?`0`:` `;for(;l.length<u;)l=r===void 0?d+l:l+d;return l}return e.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,r)}static getBytes(e,t){return T.encode(e,t)}static getCharCode(e,t=0){return e.charCodeAt(t)}static getCharAt(e){return String.fromCharCode(e)}}E.SHIFT_JIS=C.SJIS.getName(),E.GB2312=`GB2312`,E.ISO88591=C.ISO8859_1.getName(),E.EUC_JP=`EUC_JP`,E.UTF8=C.UTF8.getName(),E.PLATFORM_DEFAULT_ENCODING=E.UTF8,E.ASSUME_SHIFT_JIS=!1;class D{constructor(e=``){this.value=e}enableDecoding(e){return this.encoding=e,this}append(e){return typeof e==`string`?this.value+=e.toString():this.encoding?this.value+=E.castAsNonUtf8Char(e,this.encoding):this.value+=String.fromCharCode(e),this}appendChars(e,t,n){for(let r=t;t<t+n;r++)this.append(e[r]);return this}length(){return this.value.length}charAt(e){return this.value.charAt(e)}deleteCharAt(e){this.value=this.value.substr(0,e)+this.value.substring(e+1)}setCharAt(e,t){this.value=this.value.substr(0,e)+t+this.value.substr(e+1)}substring(e,t){return this.value.substring(e,t)}setLengthToZero(){this.value=``}toString(){return this.value}insert(e,t){this.value=this.value.substr(0,e)+t+this.value.substr(e+t.length)}}class O{constructor(e,t,n,r){if(this.width=e,this.height=t,this.rowSize=n,this.bits=r,t??=e,this.height=t,e<1||t<1)throw new l(`Both dimensions must be greater than 0`);n??=Math.floor((e+31)/32),this.rowSize=n,r??(this.bits=new Int32Array(this.rowSize*this.height))}static parseFromBooleanArray(e){let t=e.length,n=e[0].length,r=new O(n,t);for(let i=0;i<t;i++){let t=e[i];for(let e=0;e<n;e++)t[e]&&r.set(e,i)}return r}static parseFromString(e,t,n){if(e===null)throw new l(`stringRepresentation cannot be null`);let r=Array(e.length),i=0,a=0,o=-1,s=0,c=0;for(;c<e.length;)if(e.charAt(c)===`
52
+ `||e.charAt(c)===`\r`){if(i>a){if(o===-1)o=i-a;else if(i-a!==o)throw new l(`row lengths do not match`);a=i,s++}c++}else if(e.substring(c,c+t.length)===t)c+=t.length,r[i]=!0,i++;else if(e.substring(c,c+n.length)===n)c+=n.length,r[i]=!1,i++;else throw new l(`illegal character encountered: `+e.substring(c));if(i>a){if(o===-1)o=i-a;else if(i-a!==o)throw new l(`row lengths do not match`);s++}let u=new O(o,s);for(let e=0;e<i;e++)r[e]&&u.set(Math.floor(e%o),Math.floor(e/o));return u}get(e,t){let n=t*this.rowSize+Math.floor(e/32);return(this.bits[n]>>>(e&31)&1)!=0}set(e,t){let n=t*this.rowSize+Math.floor(e/32);this.bits[n]|=1<<(e&31)&4294967295}unset(e,t){let n=t*this.rowSize+Math.floor(e/32);this.bits[n]&=~(1<<(e&31)&4294967295)}flip(e,t){let n=t*this.rowSize+Math.floor(e/32);this.bits[n]^=1<<(e&31)&4294967295}xor(e){if(this.width!==e.getWidth()||this.height!==e.getHeight()||this.rowSize!==e.getRowSize())throw new l(`input matrix dimensions do not match`);let t=new v(Math.floor(this.width/32)+1),n=this.rowSize,r=this.bits;for(let i=0,a=this.height;i<a;i++){let a=i*n,o=e.getRow(i,t).getBitArray();for(let e=0;e<n;e++)r[a+e]^=o[e]}}clear(){let e=this.bits,t=e.length;for(let n=0;n<t;n++)e[n]=0}setRegion(e,t,n,r){if(t<0||e<0)throw new l(`Left and top must be nonnegative`);if(r<1||n<1)throw new l(`Height and width must be at least 1`);let i=e+n,a=t+r;if(a>this.height||i>this.width)throw new l(`The region must fit inside the matrix`);let o=this.rowSize,s=this.bits;for(let n=t;n<a;n++){let t=n*o;for(let n=e;n<i;n++)s[t+Math.floor(n/32)]|=1<<(n&31)&4294967295}}getRow(e,t){t==null||t.getSize()<this.width?t=new v(this.width):t.clear();let n=this.rowSize,r=this.bits,i=e*n;for(let e=0;e<n;e++)t.setBulk(e*32,r[i+e]);return t}setRow(e,t){p.arraycopy(t.getBitArray(),0,this.bits,e*this.rowSize,this.rowSize)}rotate180(){let e=this.getWidth(),t=this.getHeight(),n=new v(e),r=new v(e);for(let e=0,i=Math.floor((t+1)/2);e<i;e++)n=this.getRow(e,n),r=this.getRow(t-1-e,r),n.reverse(),r.reverse(),this.setRow(e,r),this.setRow(t-1-e,n)}getEnclosingRectangle(){let e=this.width,t=this.height,n=this.rowSize,r=this.bits,i=e,a=t,o=-1,s=-1;for(let e=0;e<t;e++)for(let t=0;t<n;t++){let c=r[e*n+t];if(c!==0){if(e<a&&(a=e),e>s&&(s=e),t*32<i){let e=0;for(;!(c<<31-e&4294967295);)e++;t*32+e<i&&(i=t*32+e)}if(t*32+31>o){let e=31;for(;!(c>>>e);)e--;t*32+e>o&&(o=t*32+e)}}}return o<i||s<a?null:Int32Array.from([i,a,o-i+1,s-a+1])}getTopLeftOnBit(){let e=this.rowSize,t=this.bits,n=0;for(;n<t.length&&t[n]===0;)n++;if(n===t.length)return null;let r=n/e,i=n%e*32,a=t[n],o=0;for(;!(a<<31-o&4294967295);)o++;return i+=o,Int32Array.from([i,r])}getBottomRightOnBit(){let e=this.rowSize,t=this.bits,n=t.length-1;for(;n>=0&&t[n]===0;)n--;if(n<0)return null;let r=Math.floor(n/e),i=Math.floor(n%e)*32,a=t[n],o=31;for(;!(a>>>o);)o--;return i+=o,Int32Array.from([i,r])}getWidth(){return this.width}getHeight(){return this.height}getRowSize(){return this.rowSize}equals(e){if(!(e instanceof O))return!1;let t=e;return this.width===t.width&&this.height===t.height&&this.rowSize===t.rowSize&&g.equals(this.bits,t.bits)}hashCode(){let e=this.width;return e=31*e+this.width,e=31*e+this.height,e=31*e+this.rowSize,e=31*e+g.hashCode(this.bits),e}toString(e=`X `,t=` `,n=`
53
+ `){return this.buildToString(e,t,n)}buildToString(e,t,n){let r=new D;for(let i=0,a=this.height;i<a;i++){for(let n=0,a=this.width;n<a;n++)r.append(this.get(n,i)?e:t);r.append(n)}return r.toString()}clone(){return new O(this.width,this.height,this.rowSize,this.bits.slice())}}class k extends s{static getNotFoundInstance(){return new k}}k.kind=`NotFoundException`;class A extends f{constructor(e){super(e),this.luminances=A.EMPTY,this.buckets=new Int32Array(A.LUMINANCE_BUCKETS)}getBlackRow(e,t){let n=this.getLuminanceSource(),r=n.getWidth();t==null||t.getSize()<r?t=new v(r):t.clear(),this.initArrays(r);let i=n.getRow(e,this.luminances),a=this.buckets;for(let e=0;e<r;e++)a[(i[e]&255)>>A.LUMINANCE_SHIFT]++;let o=A.estimateBlackPoint(a);if(r<3)for(let e=0;e<r;e++)(i[e]&255)<o&&t.set(e);else{let e=i[0]&255,n=i[1]&255;for(let a=1;a<r-1;a++){let r=i[a+1]&255;(n*4-e-r)/2<o&&t.set(a),e=n,n=r}}return t}getBlackMatrix(){let e=this.getLuminanceSource(),t=e.getWidth(),n=e.getHeight(),r=new O(t,n);this.initArrays(t);let i=this.buckets;for(let r=1;r<5;r++){let a=Math.floor(n*r/5),o=e.getRow(a,this.luminances),s=Math.floor(t*4/5);for(let e=Math.floor(t/5);e<s;e++){let t=o[e]&255;i[t>>A.LUMINANCE_SHIFT]++}}let a=A.estimateBlackPoint(i),o=e.getMatrix();for(let e=0;e<n;e++){let n=e*t;for(let i=0;i<t;i++)(o[n+i]&255)<a&&r.set(i,e)}return r}createBinarizer(e){return new A(e)}initArrays(e){this.luminances.length<e&&(this.luminances=new Uint8ClampedArray(e));let t=this.buckets;for(let e=0;e<A.LUMINANCE_BUCKETS;e++)t[e]=0}static estimateBlackPoint(e){let t=e.length,n=0,r=0,i=0;for(let a=0;a<t;a++)e[a]>i&&(r=a,i=e[a]),e[a]>n&&(n=e[a]);let a=0,o=0;for(let n=0;n<t;n++){let t=n-r,i=e[n]*t*t;i>o&&(a=n,o=i)}if(r>a){let e=r;r=a,a=e}if(a-r<=t/16)throw new k;let s=a-1,c=-1;for(let t=a-1;t>r;t--){let i=t-r,o=i*i*(a-t)*(n-e[t]);o>c&&(s=t,c=o)}return s<<A.LUMINANCE_SHIFT}}A.LUMINANCE_BITS=5,A.LUMINANCE_SHIFT=8-A.LUMINANCE_BITS,A.LUMINANCE_BUCKETS=1<<A.LUMINANCE_BITS,A.EMPTY=Uint8ClampedArray.from([0]);class j extends A{constructor(e){super(e),this.matrix=null}getBlackMatrix(){if(this.matrix!==null)return this.matrix;let e=this.getLuminanceSource(),t=e.getWidth(),n=e.getHeight();if(t>=j.MINIMUM_DIMENSION&&n>=j.MINIMUM_DIMENSION){let r=e.getMatrix(),i=t>>j.BLOCK_SIZE_POWER;(t&j.BLOCK_SIZE_MASK)!==0&&i++;let a=n>>j.BLOCK_SIZE_POWER;(n&j.BLOCK_SIZE_MASK)!==0&&a++;let o=j.calculateBlackPoints(r,i,a,t,n),s=new O(t,n);j.calculateThresholdForBlock(r,i,a,t,n,o,s),this.matrix=s}else this.matrix=super.getBlackMatrix();return this.matrix}createBinarizer(e){return new j(e)}static calculateThresholdForBlock(e,t,n,r,i,a,o){let s=i-j.BLOCK_SIZE,c=r-j.BLOCK_SIZE;for(let i=0;i<n;i++){let l=i<<j.BLOCK_SIZE_POWER;l>s&&(l=s);let u=j.cap(i,2,n-3);for(let n=0;n<t;n++){let i=n<<j.BLOCK_SIZE_POWER;i>c&&(i=c);let s=j.cap(n,2,t-3),d=0;for(let e=-2;e<=2;e++){let t=a[u+e];d+=t[s-2]+t[s-1]+t[s]+t[s+1]+t[s+2]}let f=d/25;j.thresholdBlock(e,i,l,f,r,o)}}}static cap(e,t,n){return e<t?t:e>n?n:e}static thresholdBlock(e,t,n,r,i,a){for(let o=0,s=n*i+t;o<j.BLOCK_SIZE;o++,s+=i)for(let i=0;i<j.BLOCK_SIZE;i++)(e[s+i]&255)<=r&&a.set(t+i,n+o)}static calculateBlackPoints(e,t,n,r,i){let a=i-j.BLOCK_SIZE,o=r-j.BLOCK_SIZE,s=Array(n);for(let i=0;i<n;i++){s[i]=new Int32Array(t);let n=i<<j.BLOCK_SIZE_POWER;n>a&&(n=a);for(let a=0;a<t;a++){let t=a<<j.BLOCK_SIZE_POWER;t>o&&(t=o);let c=0,l=255,u=0;for(let i=0,a=n*r+t;i<j.BLOCK_SIZE;i++,a+=r){for(let t=0;t<j.BLOCK_SIZE;t++){let n=e[a+t]&255;c+=n,n<l&&(l=n),n>u&&(u=n)}if(u-l>j.MIN_DYNAMIC_RANGE)for(i++,a+=r;i<j.BLOCK_SIZE;i++,a+=r)for(let t=0;t<j.BLOCK_SIZE;t++)c+=e[a+t]&255}let d=c>>j.BLOCK_SIZE_POWER*2;if(u-l<=j.MIN_DYNAMIC_RANGE&&(d=l/2,i>0&&a>0)){let e=(s[i-1][a]+2*s[i][a-1]+s[i-1][a-1])/4;l<e&&(d=e)}s[i][a]=d}}return s}}j.BLOCK_SIZE_POWER=3,j.BLOCK_SIZE=1<<j.BLOCK_SIZE_POWER,j.BLOCK_SIZE_MASK=j.BLOCK_SIZE-1,j.MINIMUM_DIMENSION=j.BLOCK_SIZE*5,j.MIN_DYNAMIC_RANGE=24;class M{constructor(e,t){this.width=e,this.height=t}getWidth(){return this.width}getHeight(){return this.height}isCropSupported(){return!1}crop(e,t,n,r){throw new w(`This luminance source does not support cropping.`)}isRotateSupported(){return!1}rotateCounterClockwise(){throw new w(`This luminance source does not support rotation by 90 degrees.`)}rotateCounterClockwise45(){throw new w(`This luminance source does not support rotation by 45 degrees.`)}toString(){let e=new Uint8ClampedArray(this.width),t=new D;for(let n=0;n<this.height;n++){let r=this.getRow(n,e);for(let e=0;e<this.width;e++){let n=r[e]&255,i;i=n<64?`#`:n<128?`+`:n<192?`.`:` `,t.append(i)}t.append(`
54
+ `)}return t.toString()}}class N extends M{constructor(e){super(e.getWidth(),e.getHeight()),this.delegate=e}getRow(e,t){let n=this.delegate.getRow(e,t),r=this.getWidth();for(let e=0;e<r;e++)n[e]=255-(n[e]&255);return n}getMatrix(){let e=this.delegate.getMatrix(),t=this.getWidth()*this.getHeight(),n=new Uint8ClampedArray(t);for(let r=0;r<t;r++)n[r]=255-(e[r]&255);return n}isCropSupported(){return this.delegate.isCropSupported()}crop(e,t,n,r){return new N(this.delegate.crop(e,t,n,r))}isRotateSupported(){return this.delegate.isRotateSupported()}invert(){return this.delegate}rotateCounterClockwise(){return new N(this.delegate.rotateCounterClockwise())}rotateCounterClockwise45(){return new N(this.delegate.rotateCounterClockwise45())}}class P extends M{constructor(e){super(e.width,e.height),this.canvas=e,this.tempCanvasElement=null,this.buffer=P.makeBufferFromCanvasImageData(e)}static makeBufferFromCanvasImageData(e){let t=e.getContext(`2d`).getImageData(0,0,e.width,e.height);return P.toGrayscaleBuffer(t.data,e.width,e.height)}static toGrayscaleBuffer(e,t,n){let r=new Uint8ClampedArray(t*n);for(let t=0,n=0,i=e.length;t<i;t+=4,n++){let i;if(e[t+3]===0)i=255;else{let n=e[t],r=e[t+1],a=e[t+2];i=306*n+601*r+117*a+512>>10}r[n]=i}return r}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth(),r=e*n;return t===null?t=this.buffer.slice(r,r+n):(t.length<n&&(t=new Uint8ClampedArray(n)),t.set(this.buffer.slice(r,r+n))),t}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(e,t,n,r){return super.crop(e,t,n,r),this}isRotateSupported(){return!0}rotateCounterClockwise(){return this.rotate(-90),this}rotateCounterClockwise45(){return this.rotate(-45),this}getTempCanvasElement(){if(this.tempCanvasElement===null){let e=this.canvas.ownerDocument.createElement(`canvas`);e.width=this.canvas.width,e.height=this.canvas.height,this.tempCanvasElement=e}return this.tempCanvasElement}rotate(e){let t=this.getTempCanvasElement(),n=t.getContext(`2d`),r=e*P.DEGREE_TO_RADIANS,i=this.canvas.width,a=this.canvas.height,o=Math.ceil(Math.abs(Math.cos(r))*i+Math.abs(Math.sin(r))*a),s=Math.ceil(Math.abs(Math.sin(r))*i+Math.abs(Math.cos(r))*a);return t.width=o,t.height=s,n.translate(o/2,s/2),n.rotate(r),n.drawImage(this.canvas,i/-2,a/-2),this.buffer=P.makeBufferFromCanvasImageData(t),this}invert(){return new N(this)}}P.DEGREE_TO_RADIANS=Math.PI/180;class F{constructor(e,t,n){this.deviceId=e,this.label=t,this.kind=`videoinput`,this.groupId=n||void 0}toJSON(){return{kind:this.kind,groupId:this.groupId,deviceId:this.deviceId,label:this.label}}}var I=(globalThis||global||self||window||void 0)&&(globalThis||global||self||window||void 0).__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})};class L{constructor(e,t=500,n){this.reader=e,this.timeBetweenScansMillis=t,this._hints=n,this._stopContinuousDecode=!1,this._stopAsyncDecode=!1,this._timeBetweenDecodingAttempts=0}get hasNavigator(){return typeof navigator<`u`}get isMediaDevicesSuported(){return this.hasNavigator&&!!navigator.mediaDevices}get canEnumerateDevices(){return!!(this.isMediaDevicesSuported&&navigator.mediaDevices.enumerateDevices)}get timeBetweenDecodingAttempts(){return this._timeBetweenDecodingAttempts}set timeBetweenDecodingAttempts(e){this._timeBetweenDecodingAttempts=e<0?0:e}set hints(e){this._hints=e||null}get hints(){return this._hints}listVideoInputDevices(){return I(this,void 0,void 0,function*(){if(!this.hasNavigator)throw Error(`Can't enumerate devices, navigator is not present.`);if(!this.canEnumerateDevices)throw Error(`Can't enumerate devices, method not supported.`);let e=yield navigator.mediaDevices.enumerateDevices(),t=[];for(let n of e){let e=n.kind===`video`?`videoinput`:n.kind;if(e!==`videoinput`)continue;let r={deviceId:n.deviceId||n.id,label:n.label||`Video device ${t.length+1}`,kind:e,groupId:n.groupId};t.push(r)}return t})}getVideoInputDevices(){return I(this,void 0,void 0,function*(){return(yield this.listVideoInputDevices()).map(e=>new F(e.deviceId,e.label))})}findDeviceById(e){return I(this,void 0,void 0,function*(){let t=yield this.listVideoInputDevices();return t?t.find(t=>t.deviceId===e):null})}decodeFromInputVideoDevice(e,t){return I(this,void 0,void 0,function*(){return yield this.decodeOnceFromVideoDevice(e,t)})}decodeOnceFromVideoDevice(e,t){return I(this,void 0,void 0,function*(){this.reset();let n;n=e?{deviceId:{exact:e}}:{facingMode:`environment`};let r={video:n};return yield this.decodeOnceFromConstraints(r,t)})}decodeOnceFromConstraints(e,t){return I(this,void 0,void 0,function*(){let n=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeOnceFromStream(n,t)})}decodeOnceFromStream(e,t){return I(this,void 0,void 0,function*(){this.reset();let n=yield this.attachStreamToVideo(e,t);return yield this.decodeOnce(n)})}decodeFromInputVideoDeviceContinuously(e,t,n){return I(this,void 0,void 0,function*(){return yield this.decodeFromVideoDevice(e,t,n)})}decodeFromVideoDevice(e,t,n){return I(this,void 0,void 0,function*(){let r;r=e?{deviceId:{exact:e}}:{facingMode:`environment`};let i={video:r};return yield this.decodeFromConstraints(i,t,n)})}decodeFromConstraints(e,t,n){return I(this,void 0,void 0,function*(){let r=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeFromStream(r,t,n)})}decodeFromStream(e,t,n){return I(this,void 0,void 0,function*(){this.reset();let r=yield this.attachStreamToVideo(e,t);return yield this.decodeContinuously(r,n)})}stopAsyncDecode(){this._stopAsyncDecode=!0}stopContinuousDecode(){this._stopContinuousDecode=!0}attachStreamToVideo(e,t){return I(this,void 0,void 0,function*(){let n=this.prepareVideoElement(t);return this.addVideoSource(n,e),this.videoElement=n,this.stream=e,yield this.playVideoOnLoadAsync(n),n})}playVideoOnLoadAsync(e){return new Promise((t,n)=>this.playVideoOnLoad(e,()=>t()))}playVideoOnLoad(e,t){this.videoEndedListener=()=>this.stopStreams(),this.videoCanPlayListener=()=>this.tryPlayVideo(e),e.addEventListener(`ended`,this.videoEndedListener),e.addEventListener(`canplay`,this.videoCanPlayListener),e.addEventListener(`playing`,t),this.tryPlayVideo(e)}isVideoPlaying(e){return e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2}tryPlayVideo(e){return I(this,void 0,void 0,function*(){if(this.isVideoPlaying(e)){console.warn(`Trying to play video that is already playing.`);return}try{yield e.play()}catch{console.warn(`It was not possible to play the video.`)}})}getMediaElement(e,t){let n=document.getElementById(e);if(!n)throw new c(`element with id '${e}' not found`);if(n.nodeName.toLowerCase()!==t.toLowerCase())throw new c(`element with id '${e}' must be an ${t} element`);return n}decodeFromImage(e,t){if(!e&&!t)throw new c(`either imageElement with a src set or an url must be provided`);return t&&!e?this.decodeFromImageUrl(t):this.decodeFromImageElement(e)}decodeFromVideo(e,t){if(!e&&!t)throw new c(`Either an element with a src set or an URL must be provided`);return t&&!e?this.decodeFromVideoUrl(t):this.decodeFromVideoElement(e)}decodeFromVideoContinuously(e,t,n){if(e===void 0&&t===void 0)throw new c(`Either an element with a src set or an URL must be provided`);return t&&!e?this.decodeFromVideoUrlContinuously(t,n):this.decodeFromVideoElementContinuously(e,n)}decodeFromImageElement(e){if(!e)throw new c(`An image element must be provided.`);this.reset();let t=this.prepareImageElement(e);this.imageElement=t;let n;return n=this.isImageLoaded(t)?this.decodeOnce(t,!1,!0):this._decodeOnLoadImage(t),n}decodeFromVideoElement(e){let t=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideo(t)}decodeFromVideoElementContinuously(e,t){let n=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideoContinuously(n,t)}_decodeFromVideoElementSetup(e){if(!e)throw new c(`A video element must be provided.`);this.reset();let t=this.prepareVideoElement(e);return this.videoElement=t,t}decodeFromImageUrl(e){if(!e)throw new c(`An URL must be provided.`);this.reset();let t=this.prepareImageElement();this.imageElement=t;let n=this._decodeOnLoadImage(t);return t.src=e,n}decodeFromVideoUrl(e){if(!e)throw new c(`An URL must be provided.`);this.reset();let t=this.prepareVideoElement(),n=this.decodeFromVideoElement(t);return t.src=e,n}decodeFromVideoUrlContinuously(e,t){if(!e)throw new c(`An URL must be provided.`);this.reset();let n=this.prepareVideoElement(),r=this.decodeFromVideoElementContinuously(n,t);return n.src=e,r}_decodeOnLoadImage(e){return new Promise((t,n)=>{this.imageLoadedListener=()=>this.decodeOnce(e,!1,!0).then(t,n),e.addEventListener(`load`,this.imageLoadedListener)})}_decodeOnLoadVideo(e){return I(this,void 0,void 0,function*(){return yield this.playVideoOnLoadAsync(e),yield this.decodeOnce(e)})}_decodeOnLoadVideoContinuously(e,t){return I(this,void 0,void 0,function*(){yield this.playVideoOnLoadAsync(e),this.decodeContinuously(e,t)})}isImageLoaded(e){return!(!e.complete||e.naturalWidth===0)}prepareImageElement(e){let t;return e===void 0&&(t=document.createElement(`img`),t.width=200,t.height=200),typeof e==`string`&&(t=this.getMediaElement(e,`img`)),e instanceof HTMLImageElement&&(t=e),t}prepareVideoElement(e){let t;return!e&&typeof document<`u`&&(t=document.createElement(`video`),t.width=200,t.height=200),typeof e==`string`&&(t=this.getMediaElement(e,`video`)),e instanceof HTMLVideoElement&&(t=e),t.setAttribute(`autoplay`,`true`),t.setAttribute(`muted`,`true`),t.setAttribute(`playsinline`,`true`),t}decodeOnce(e,t=!0,n=!0){this._stopAsyncDecode=!1;let r=(i,a)=>{if(this._stopAsyncDecode){a(new k(`Video stream has ended before any code could be detected.`)),this._stopAsyncDecode=void 0;return}try{i(this.decode(e))}catch(e){let o=t&&e instanceof k,s=(e instanceof d||e instanceof x)&&n;if(o||s)return setTimeout(r,this._timeBetweenDecodingAttempts,i,a);a(e)}};return new Promise((e,t)=>r(e,t))}decodeContinuously(e,t){this._stopContinuousDecode=!1;let n=()=>{if(this._stopContinuousDecode){this._stopContinuousDecode=void 0;return}try{t(this.decode(e),null),setTimeout(n,this.timeBetweenScansMillis)}catch(e){t(null,e);let r=e instanceof d||e instanceof x,i=e instanceof k;(r||i)&&setTimeout(n,this._timeBetweenDecodingAttempts)}};n()}decode(e){let t=this.createBinaryBitmap(e);return this.decodeBitmap(t)}_isHTMLVideoElement(e){return e.videoWidth!==0}drawFrameOnCanvas(e,t,n){t||={sx:0,sy:0,sWidth:e.videoWidth,sHeight:e.videoHeight,dx:0,dy:0,dWidth:e.videoWidth,dHeight:e.videoHeight},n||=this.captureCanvasContext,n.drawImage(e,t.sx,t.sy,t.sWidth,t.sHeight,t.dx,t.dy,t.dWidth,t.dHeight)}drawImageOnCanvas(e,t,n=this.captureCanvasContext){t||={sx:0,sy:0,sWidth:e.naturalWidth,sHeight:e.naturalHeight,dx:0,dy:0,dWidth:e.naturalWidth,dHeight:e.naturalHeight},n||=this.captureCanvasContext,n.drawImage(e,t.sx,t.sy,t.sWidth,t.sHeight,t.dx,t.dy,t.dWidth,t.dHeight)}createBinaryBitmap(e){return this.getCaptureCanvasContext(e),this._isHTMLVideoElement(e)?this.drawFrameOnCanvas(e):this.drawImageOnCanvas(e),new u(new j(new P(this.getCaptureCanvas(e))))}getCaptureCanvasContext(e){if(!this.captureCanvasContext){let t=this.getCaptureCanvas(e).getContext(`2d`);this.captureCanvasContext=t}return this.captureCanvasContext}getCaptureCanvas(e){if(!this.captureCanvas){let t=this.createCaptureCanvas(e);this.captureCanvas=t}return this.captureCanvas}decodeBitmap(e){return this.reader.decode(e,this._hints)}createCaptureCanvas(e){if(typeof document>`u`)return this._destroyCaptureCanvas(),null;let t=document.createElement(`canvas`),n,r;return e!==void 0&&(e instanceof HTMLVideoElement?(n=e.videoWidth,r=e.videoHeight):e instanceof HTMLImageElement&&(n=e.naturalWidth||e.width,r=e.naturalHeight||e.height)),t.style.width=n+`px`,t.style.height=r+`px`,t.width=n,t.height=r,t}stopStreams(){this.stream&&=(this.stream.getVideoTracks().forEach(e=>e.stop()),void 0),this._stopAsyncDecode===!1&&this.stopAsyncDecode(),this._stopContinuousDecode===!1&&this.stopContinuousDecode()}reset(){this.stopStreams(),this._destroyVideoElement(),this._destroyImageElement(),this._destroyCaptureCanvas()}_destroyVideoElement(){this.videoElement&&=(this.videoEndedListener!==void 0&&this.videoElement.removeEventListener(`ended`,this.videoEndedListener),this.videoPlayingEventListener!==void 0&&this.videoElement.removeEventListener(`playing`,this.videoPlayingEventListener),this.videoCanPlayListener!==void 0&&this.videoElement.removeEventListener(`loadedmetadata`,this.videoCanPlayListener),this.cleanVideoSource(this.videoElement),void 0)}_destroyImageElement(){this.imageElement&&=(this.imageLoadedListener!==void 0&&this.imageElement.removeEventListener(`load`,this.imageLoadedListener),this.imageElement.src=void 0,this.imageElement.removeAttribute(`src`),void 0)}_destroyCaptureCanvas(){this.captureCanvasContext=void 0,this.captureCanvas=void 0}addVideoSource(e,t){try{e.srcObject=t}catch{e.src=URL.createObjectURL(t)}}cleanVideoSource(e){try{e.srcObject=null}catch{e.src=``}this.videoElement.removeAttribute(`src`)}}class R{constructor(e,t,n=t==null?0:8*t.length,r,i,a=p.currentTimeMillis()){this.text=e,this.rawBytes=t,this.numBits=n,this.resultPoints=r,this.format=i,this.timestamp=a,this.text=e,this.rawBytes=t,n==null?this.numBits=t==null?0:8*t.length:this.numBits=n,this.resultPoints=r,this.format=i,this.resultMetadata=null,a==null?this.timestamp=p.currentTimeMillis():this.timestamp=a}getText(){return this.text}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}getResultPoints(){return this.resultPoints}getBarcodeFormat(){return this.format}getResultMetadata(){return this.resultMetadata}putMetadata(e,t){this.resultMetadata===null&&(this.resultMetadata=new Map),this.resultMetadata.set(e,t)}putAllMetadata(e){e!==null&&(this.resultMetadata===null?this.resultMetadata=e:this.resultMetadata=new Map(e))}addResultPoints(e){let t=this.resultPoints;if(t===null)this.resultPoints=e;else if(e!==null&&e.length>0){let n=Array(t.length+e.length);p.arraycopy(t,0,n,0,t.length),p.arraycopy(e,0,n,t.length,e.length),this.resultPoints=n}}getTimestamp(){return this.timestamp}toString(){return this.text}}var ee;(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`})(ee||={});var z=ee,te;(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`})(te||={});var ne=te;class re{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 ie{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 B{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=ie.addOrSubtract(n,r)}return n}n=t[0];let r=t.length,i=this.field;for(let a=1;a<r;a++)n=ie.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]=ie.addOrSubtract(t[e-i],n[e]);return new B(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]=ie.addOrSubtract(a[e+t],o.multiply(n,r[t]))}return new B(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 B(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 B(a,i)}divide(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(e.isZero())throw new l(`Divide by 0`);let t=this.field,n=t.getZero(),r=this,i=e.getCoefficient(e.getDegree()),a=t.inverse(i);for(;r.getDegree()>=e.getDegree()&&!r.isZero();){let i=r.getDegree()-e.getDegree(),o=t.multiply(r.getCoefficient(r.getDegree()),a),s=e.multiplyByMonomial(i,o),c=t.buildMonomial(i,o);n=n.addOrSubtract(c),r=r.addOrSubtract(s)}return[n,r]}toString(){let e=``;for(let t=this.getDegree();t>=0;t--){let n=this.getCoefficient(t);if(n!==0){if(n<0?(e+=` - `,n=-n):e.length>0&&(e+=` + `),t===0||n!==1){let t=this.field.log(n);t===0?e+=`1`:t===1?e+=`a`:(e+=`a^`,e+=t)}t!==0&&(t===1?e+=`x`:(e+=`x^`,e+=t))}}return e}}class ae extends s{}ae.kind=`ArithmeticException`;class oe extends ie{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 B(this,Int32Array.from([0])),this.one=new B(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 B(this,n)}inverse(e){if(e===0)throw new ae;return this.expTable[this.size-this.logTable[e]-1]}multiply(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.size-1)]}getSize(){return this.size}getGeneratorBase(){return this.generatorBase}toString(){return`GF(0x`+_.toHexString(this.primitive)+`,`+this.size+`)`}equals(e){return e===this}}oe.AZTEC_DATA_12=new oe(4201,4096,1),oe.AZTEC_DATA_10=new oe(1033,1024,1),oe.AZTEC_DATA_6=new oe(67,64,1),oe.AZTEC_PARAM=new oe(19,16,1),oe.QR_CODE_FIELD_256=new oe(285,256,0),oe.DATA_MATRIX_FIELD_256=new oe(301,256,1),oe.AZTEC_DATA_8=oe.DATA_MATRIX_FIELD_256,oe.MAXICODE_FIELD_64=oe.AZTEC_DATA_6;class se extends s{}se.kind=`ReedSolomonException`;class ce extends s{}ce.kind=`IllegalStateException`;class V{constructor(e){this.field=e}decode(e,t){let n=this.field,r=new B(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 B(n,i),s=this.runEuclideanAlgorithm(n.buildMonomial(t,1),o,t),c=s[0],l=s[1],u=this.findErrorLocations(c),d=this.findErrorMagnitudes(l,u);for(let t=0;t<u.length;t++){let r=e.length-1-n.log(u[t]);if(r<0)throw new se(`Bad error location`);e[r]=oe.addOrSubtract(e[r],d[t])}}runEuclideanAlgorithm(e,t,n){if(e.getDegree()<t.getDegree()){let n=e;e=t,t=n}let r=this.field,i=e,a=t,o=r.getZero(),s=r.getOne();for(;a.getDegree()>=(n/2|0);){let e=i,t=o;if(i=a,o=s,i.isZero())throw new se(`r_{i-1} was zero`);a=e;let n=r.getZero(),c=i.getCoefficient(i.getDegree()),l=r.inverse(c);for(;a.getDegree()>=i.getDegree()&&!a.isZero();){let e=a.getDegree()-i.getDegree(),t=r.multiply(a.getCoefficient(a.getDegree()),l);n=n.addOrSubtract(r.buildMonomial(e,t)),a=a.addOrSubtract(i.multiplyByMonomial(e,t))}if(s=n.multiply(o).addOrSubtract(t),a.getDegree()>=i.getDegree())throw new ce(`Division algorithm failed to reduce polynomial?`)}let c=s.getCoefficient(0);if(c===0)throw new se(`sigmaTilde(0) was zero`);let l=r.inverse(c);return[s.multiplyScalar(l),a.multiplyScalar(l)]}findErrorLocations(e){let t=e.getDegree();if(t===1)return Int32Array.from([e.getCoefficient(1)]);let n=new Int32Array(t),r=0,i=this.field;for(let a=1;a<i.getSize()&&r<t;a++)e.evaluateAt(a)===0&&(n[r]=i.inverse(a),r++);if(r!==t)throw new se(`Error locator degree does not match number of roots`);return n}findErrorMagnitudes(e,t){let n=t.length,r=new Int32Array(n),i=this.field;for(let a=0;a<n;a++){let o=i.inverse(t[a]),s=1;for(let e=0;e<n;e++)if(a!==e){let n=i.multiply(t[e],o),r=n&1?n&-2:n|1;s=i.multiply(s,r)}r[a]=i.multiply(e.evaluateAt(o),i.inverse(s)),i.getGeneratorBase()!==0&&(r[a]=i.multiply(r[a],o))}return r}}var le;(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`})(le||={});class ue{decode(e){this.ddata=e;let t=e.getBits(),n=this.extractBits(t),r=this.correctBits(n),i=new re(ue.convertBoolArrayToByteArray(r),ue.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=le.UPPER,r=le.UPPER,i=``,a=0;for(;a<t;)if(r===le.BINARY){if(t-a<5)break;let o=ue.readCode(e,a,5);if(a+=5,o===0){if(t-a<11)break;o=ue.readCode(e,a,11)+31,a+=11}for(let n=0;n<o;n++){if(t-a<8){a=t;break}let n=ue.readCode(e,a,8);i+=E.castAsNonUtf8Char(n),a+=8}r=n}else{let o=r===le.DIGIT?4:5;if(t-a<o)break;let s=ue.readCode(e,a,o);a+=o;let c=ue.getCharacter(r,s);c.startsWith(`CTRL_`)?(n=r,r=ue.getTable(c.charAt(5)),c.charAt(6)===`L`&&(n=r)):(i+=c,r=n)}return i}static getTable(e){switch(e){case`L`:return le.LOWER;case`P`:return le.PUNCT;case`M`:return le.MIXED;case`D`:return le.DIGIT;case`B`:return le.BINARY;default:return le.UPPER}}static getCharacter(e,t){switch(e){case le.UPPER:return ue.UPPER_TABLE[t];case le.LOWER:return ue.LOWER_TABLE[t];case le.MIXED:return ue.MIXED_TABLE[t];case le.PUNCT:return ue.PUNCT_TABLE[t];case le.DIGIT:return ue.DIGIT_TABLE[t];default:throw new ce(`Bad table`)}}correctBits(e){let t,n;this.ddata.getNbLayers()<=2?(n=6,t=oe.AZTEC_DATA_6):this.ddata.getNbLayers()<=8?(n=8,t=oe.AZTEC_DATA_8):this.ddata.getNbLayers()<=22?(n=10,t=oe.AZTEC_DATA_10):(n=12,t=oe.AZTEC_DATA_12);let r=this.ddata.getNbDatablocks(),i=e.length/n;if(i<r)throw new x;let a=e.length%n,o=new Int32Array(i);for(let t=0;t<i;t++,a+=n)o[t]=ue.readCode(e,a,n);try{new V(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?ue.readCode(e,t,8):ue.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]=ue.readByte(e,8*n);return t}totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}ue.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(`.`),ue.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(`.`),ue.MIXED_TABLE=`CTRL_PS. .\\1.\\2.\\3.\\4.\\5.\\6.\\7.\b. .
55
+ .\\13.\f.\r.\\33.\\34.\\35.\\36.\\37.@.\\.^._.\`.|.~.\\177.CTRL_LL.CTRL_UL.CTRL_PL.CTRL_BS`.split(`.`),ue.PUNCT_TABLE=[``,`\r`,`\r
56
+ `,`. `,`, `,`: `,`!`,`"`,`#`,`$`,`%`,`&`,`'`,`(`,`)`,`*`,`+`,`,`,`-`,`.`,`/`,`:`,`;`,`<`,`=`,`>`,`?`,`[`,`]`,`{`,`}`,`CTRL_UL`],ue.DIGIT_TABLE=[`CTRL_PS`,` `,`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`,`,`.`,`CTRL_UL`,`CTRL_US`];class de{constructor(){}static round(e){return e===NaN?0:e<=-(2**53-1)?-(2**53-1):e>=2**53-1?2**53-1:e+(e<0?-.5:.5)|0}static distance(e,t,n,r){let i=e-n,a=t-r;return Math.sqrt(i*i+a*a)}static sum(e){let t=0;for(let n=0,r=e.length;n!==r;n++){let r=e[n];t+=r}return t}}class fe{static floatToIntBits(e){return e}}fe.MAX_VALUE=2**53-1;class H{constructor(e,t){this.x=e,this.y=t}getX(){return this.x}getY(){return this.y}equals(e){if(e instanceof H){let t=e;return this.x===t.x&&this.y===t.y}return!1}hashCode(){return 31*fe.floatToIntBits(this.x)+fe.floatToIntBits(this.y)}toString(){return`(`+this.x+`,`+this.y+`)`}static orderBestPatterns(e){let t=this.distance(e[0],e[1]),n=this.distance(e[1],e[2]),r=this.distance(e[0],e[2]),i,a,o;if(n>=t&&n>=r?(a=e[0],i=e[1],o=e[2]):r>=n&&r>=t?(a=e[1],i=e[0],o=e[2]):(a=e[2],i=e[0],o=e[1]),this.crossProductZ(i,a,o)<0){let e=i;i=o,o=e}e[0]=i,e[1]=a,e[2]=o}static distance(e,t){return de.distance(e.x,e.y,t.x,t.y)}static crossProductZ(e,t,n){let r=t.x,i=t.y;return(n.x-r)*(e.y-i)-(n.y-i)*(e.x-r)}}class pe{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class me extends pe{constructor(e,t,n,r,i){super(e,t),this.compact=n,this.nbDatablocks=r,this.nbLayers=i}getNbLayers(){return this.nbLayers}getNbDatablocks(){return this.nbDatablocks}isCompact(){return this.compact}}class he{constructor(e,t,n,r){this.image=e,this.height=e.getHeight(),this.width=e.getWidth(),t??=he.INIT_SIZE,n??=e.getWidth()/2|0,r??=e.getHeight()/2|0;let i=t/2|0;if(this.leftInit=n-i,this.rightInit=n+i,this.upInit=r-i,this.downInit=r+i,this.upInit<0||this.leftInit<0||this.downInit>=this.height||this.rightInit>=this.width)throw new k}detect(){let e=this.leftInit,t=this.rightInit,n=this.upInit,r=this.downInit,i=!1,a=!0,o=!1,s=!1,c=!1,l=!1,u=!1,d=this.width,f=this.height;for(;a;){a=!1;let p=!0;for(;(p||!s)&&t<d;)p=this.containsBlackPoint(n,r,t,!1),p?(t++,a=!0,s=!0):s||t++;if(t>=d){i=!0;break}let m=!0;for(;(m||!c)&&r<f;)m=this.containsBlackPoint(e,t,r,!0),m?(r++,a=!0,c=!0):c||r++;if(r>=f){i=!0;break}let h=!0;for(;(h||!l)&&e>=0;)h=this.containsBlackPoint(n,r,e,!1),h?(e--,a=!0,l=!0):l||e--;if(e<0){i=!0;break}let g=!0;for(;(g||!u)&&n>=0;)g=this.containsBlackPoint(e,t,n,!0),g?(n--,a=!0,u=!0):u||n--;if(n<0){i=!0;break}a&&(o=!0)}if(!i&&o){let i=t-e,a=null;for(let t=1;a===null&&t<i;t++)a=this.getBlackPointOnSegment(e,r-t,e+t,r);if(a==null)throw new k;let o=null;for(let t=1;o===null&&t<i;t++)o=this.getBlackPointOnSegment(e,n+t,e+t,n);if(o==null)throw new k;let s=null;for(let e=1;s===null&&e<i;e++)s=this.getBlackPointOnSegment(t,n+e,t-e,n);if(s==null)throw new k;let c=null;for(let e=1;c===null&&e<i;e++)c=this.getBlackPointOnSegment(t,r-e,t-e,r);if(c==null)throw new k;return this.centerEdges(c,a,s,o)}else throw new k}getBlackPointOnSegment(e,t,n,r){let i=de.round(de.distance(e,t,n,r)),a=(n-e)/i,o=(r-t)/i,s=this.image;for(let n=0;n<i;n++){let r=de.round(e+n*a),i=de.round(t+n*o);if(s.get(r,i))return new H(r,i)}return null}centerEdges(e,t,n,r){let i=e.getX(),a=e.getY(),o=t.getX(),s=t.getY(),c=n.getX(),l=n.getY(),u=r.getX(),d=r.getY(),f=he.CORR;return i<this.width/2?[new H(u-f,d+f),new H(o+f,s+f),new H(c-f,l-f),new H(i+f,a-f)]:[new H(u+f,d+f),new H(o+f,s-f),new H(c-f,l+f),new H(i-f,a-f)]}containsBlackPoint(e,t,n,r){let i=this.image;if(r){for(let r=e;r<=t;r++)if(i.get(r,n))return!0}else for(let r=e;r<=t;r++)if(i.get(n,r))return!0;return!1}}he.INIT_SIZE=10,he.CORR=1;class ge{static checkAndNudgePoints(e,t){let n=e.getWidth(),r=e.getHeight(),i=!0;for(let e=0;e<t.length&&i;e+=2){let a=Math.floor(t[e]),o=Math.floor(t[e+1]);if(a<-1||a>n||o<-1||o>r)throw new k;i=!1,a===-1?(t[e]=0,i=!0):a===n&&(t[e]=n-1,i=!0),o===-1?(t[e+1]=0,i=!0):o===r&&(t[e+1]=r-1,i=!0)}i=!0;for(let e=t.length-2;e>=0&&i;e-=2){let a=Math.floor(t[e]),o=Math.floor(t[e+1]);if(a<-1||a>n||o<-1||o>r)throw new k;i=!1,a===-1?(t[e]=0,i=!0):a===n&&(t[e]=n-1,i=!0),o===-1?(t[e+1]=0,i=!0):o===r&&(t[e+1]=r-1,i=!0)}}}class U{constructor(e,t,n,r,i,a,o,s,c){this.a11=e,this.a21=t,this.a31=n,this.a12=r,this.a22=i,this.a32=a,this.a13=o,this.a23=s,this.a33=c}static quadrilateralToQuadrilateral(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=U.quadrilateralToSquare(e,t,n,r,i,a,o,s);return U.squareToQuadrilateral(c,l,u,d,f,p,m,h).times(g)}transformPoints(e){let t=e.length,n=this.a11,r=this.a12,i=this.a13,a=this.a21,o=this.a22,s=this.a23,c=this.a31,l=this.a32,u=this.a33;for(let d=0;d<t;d+=2){let t=e[d],f=e[d+1],p=i*t+s*f+u;e[d]=(n*t+a*f+c)/p,e[d+1]=(r*t+o*f+l)/p}}transformPointsWithValues(e,t){let n=this.a11,r=this.a12,i=this.a13,a=this.a21,o=this.a22,s=this.a23,c=this.a31,l=this.a32,u=this.a33,d=e.length;for(let f=0;f<d;f++){let d=e[f],p=t[f],m=i*d+s*p+u;e[f]=(n*d+a*p+c)/m,t[f]=(r*d+o*p+l)/m}}static squareToQuadrilateral(e,t,n,r,i,a,o,s){let c=e-n+i-o,l=t-r+a-s;if(c===0&&l===0)return new U(n-e,i-n,e,r-t,a-r,t,0,0,1);{let u=n-i,d=o-i,f=r-a,p=s-a,m=u*p-d*f,h=(c*p-d*l)/m,g=(u*l-c*f)/m;return new U(n-e+h*n,o-e+g*o,e,r-t+h*r,s-t+g*s,t,h,g,1)}}static quadrilateralToSquare(e,t,n,r,i,a,o,s){return U.squareToQuadrilateral(e,t,n,r,i,a,o,s).buildAdjoint()}buildAdjoint(){return new U(this.a22*this.a33-this.a23*this.a32,this.a23*this.a31-this.a21*this.a33,this.a21*this.a32-this.a22*this.a31,this.a13*this.a32-this.a12*this.a33,this.a11*this.a33-this.a13*this.a31,this.a12*this.a31-this.a11*this.a32,this.a12*this.a23-this.a13*this.a22,this.a13*this.a21-this.a11*this.a23,this.a11*this.a22-this.a12*this.a21)}times(e){return new U(this.a11*e.a11+this.a21*e.a12+this.a31*e.a13,this.a11*e.a21+this.a21*e.a22+this.a31*e.a23,this.a11*e.a31+this.a21*e.a32+this.a31*e.a33,this.a12*e.a11+this.a22*e.a12+this.a32*e.a13,this.a12*e.a21+this.a22*e.a22+this.a32*e.a23,this.a12*e.a31+this.a22*e.a32+this.a32*e.a33,this.a13*e.a11+this.a23*e.a12+this.a33*e.a13,this.a13*e.a21+this.a23*e.a22+this.a33*e.a23,this.a13*e.a31+this.a23*e.a32+this.a33*e.a33)}}class _e extends ge{sampleGrid(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v){let y=U.quadrilateralToQuadrilateral(r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v);return this.sampleGridWithTransform(e,t,n,y)}sampleGridWithTransform(e,t,n,r){if(t<=0||n<=0)throw new k;let i=new O(t,n),a=new Float32Array(2*t);for(let t=0;t<n;t++){let n=a.length,o=t+.5;for(let e=0;e<n;e+=2)a[e]=e/2+.5,a[e+1]=o;r.transformPoints(a),ge.checkAndNudgePoints(e,a);try{for(let r=0;r<n;r+=2)e.get(Math.floor(a[r]),Math.floor(a[r+1]))&&i.set(r/2,t)}catch{throw new k}}return i}}class ve{static setGridSampler(e){ve.gridSampler=e}static getInstance(){return ve.gridSampler}}ve.gridSampler=new _e;class ye{constructor(e,t){this.x=e,this.y=t}toResultPoint(){return new H(this.getX(),this.getY())}getX(){return this.x}getY(){return this.y}}class be{constructor(e){this.EXPECTED_CORNER_BITS=new Int32Array([3808,476,2107,1799]),this.image=e}detect(){return this.detectMirror(!1)}detectMirror(e){let t=this.getMatrixCenter(),n=this.getBullsEyeCorners(t);if(e){let e=n[0];n[0]=n[2],n[2]=e}return this.extractParameters(n),new me(this.sampleGrid(this.image,n[this.shift%4],n[(this.shift+1)%4],n[(this.shift+2)%4],n[(this.shift+3)%4]),this.getMatrixCornerPoints(n),this.compact,this.nbDataBlocks,this.nbLayers)}extractParameters(e){if(!this.isValidPoint(e[0])||!this.isValidPoint(e[1])||!this.isValidPoint(e[2])||!this.isValidPoint(e[3]))throw new k;let t=2*this.nbCenterLayers,n=new Int32Array([this.sampleLine(e[0],e[1],t),this.sampleLine(e[1],e[2],t),this.sampleLine(e[2],e[3],t),this.sampleLine(e[3],e[0],t)]);this.shift=this.getRotation(n,t);let r=0;for(let e=0;e<4;e++){let t=n[(this.shift+e)%4];this.compact?(r<<=7,r+=t>>1&127):(r<<=10,r+=(t>>2&992)+(t>>1&31))}let i=this.getCorrectedParameterData(r,this.compact);this.compact?(this.nbLayers=(i>>6)+1,this.nbDataBlocks=(i&63)+1):(this.nbLayers=(i>>11)+1,this.nbDataBlocks=(i&2047)+1)}getRotation(e,t){let n=0;e.forEach((e,r,i)=>{let a=(e>>t-2<<1)+(e&1);n=(n<<3)+a}),n=((n&1)<<11)+(n>>1);for(let e=0;e<4;e++)if(_.bitCount(n^this.EXPECTED_CORNER_BITS[e])<=2)return e;throw new k}getCorrectedParameterData(e,t){let n,r;t?(n=7,r=2):(n=10,r=4);let i=n-r,a=new Int32Array(n);for(let t=n-1;t>=0;--t)a[t]=e&15,e>>=4;try{new V(oe.AZTEC_PARAM).decode(a,i)}catch{throw new k}let o=0;for(let e=0;e<r;e++)o=(o<<4)+a[e];return o}getBullsEyeCorners(e){let t=e,n=e,r=e,i=e,a=!0;for(this.nbCenterLayers=1;this.nbCenterLayers<9;this.nbCenterLayers++){let e=this.getFirstDifferent(t,a,1,-1),o=this.getFirstDifferent(n,a,1,1),s=this.getFirstDifferent(r,a,-1,1),c=this.getFirstDifferent(i,a,-1,-1);if(this.nbCenterLayers>2){let n=this.distancePoint(c,e)*this.nbCenterLayers/(this.distancePoint(i,t)*(this.nbCenterLayers+2));if(n<.75||n>1.25||!this.isWhiteOrBlackRectangle(e,o,s,c))break}t=e,n=o,r=s,i=c,a=!a}if(this.nbCenterLayers!==5&&this.nbCenterLayers!==7)throw new k;this.compact=this.nbCenterLayers===5;let o=new H(t.getX()+.5,t.getY()-.5),s=new H(n.getX()+.5,n.getY()+.5),c=new H(r.getX()-.5,r.getY()+.5),l=new H(i.getX()-.5,i.getY()-.5);return this.expandSquare([o,s,c,l],2*this.nbCenterLayers-3,2*this.nbCenterLayers)}getMatrixCenter(){let e,t,n,r;try{let i=new he(this.image).detect();e=i[0],t=i[1],n=i[2],r=i[3]}catch{let i=this.image.getWidth()/2,a=this.image.getHeight()/2;e=this.getFirstDifferent(new ye(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new ye(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new ye(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new ye(i-7,a-7),!1,-1,-1).toResultPoint()}let i=de.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=de.round((e.getY()+r.getY()+t.getY()+n.getY())/4);try{let o=new he(this.image,15,i,a).detect();e=o[0],t=o[1],n=o[2],r=o[3]}catch{e=this.getFirstDifferent(new ye(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new ye(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new ye(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new ye(i-7,a-7),!1,-1,-1).toResultPoint()}return i=de.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=de.round((e.getY()+r.getY()+t.getY()+n.getY())/4),new ye(i,a)}getMatrixCornerPoints(e){return this.expandSquare(e,2*this.nbCenterLayers,this.getDimension())}sampleGrid(e,t,n,r,i){let a=ve.getInstance(),o=this.getDimension(),s=o/2-this.nbCenterLayers,c=o/2+this.nbCenterLayers;return a.sampleGrid(e,o,o,s,s,c,s,c,c,s,c,t.getX(),t.getY(),n.getX(),n.getY(),r.getX(),r.getY(),i.getX(),i.getY())}sampleLine(e,t,n){let r=0,i=this.distanceResultPoint(e,t),a=i/n,o=e.getX(),s=e.getY(),c=a*(t.getX()-e.getX())/i,l=a*(t.getY()-e.getY())/i;for(let e=0;e<n;e++)this.image.get(de.round(o+e*c),de.round(s+e*l))&&(r|=1<<n-e-1);return r}isWhiteOrBlackRectangle(e,t,n,r){e=new ye(e.getX()-3,e.getY()+3),t=new ye(t.getX()-3,t.getY()-3),n=new ye(n.getX()+3,n.getY()-3),r=new ye(r.getX()+3,r.getY()+3);let i=this.getColor(r,e);if(i===0)return!1;let a=this.getColor(e,t);return a!==i||(a=this.getColor(t,n),a!==i)?!1:(a=this.getColor(n,r),a===i)}getColor(e,t){let n=this.distancePoint(e,t),r=(t.getX()-e.getX())/n,i=(t.getY()-e.getY())/n,a=0,o=e.getX(),s=e.getY(),c=this.image.get(e.getX(),e.getY()),l=Math.ceil(n);for(let e=0;e<l;e++)o+=r,s+=i,this.image.get(de.round(o),de.round(s))!==c&&a++;let u=a/n;return u>.1&&u<.9?0:u<=.1===c?1:-1}getFirstDifferent(e,t,n,r){let i=e.getX()+n,a=e.getY()+r;for(;this.isValid(i,a)&&this.image.get(i,a)===t;)i+=n,a+=r;for(i-=n,a-=r;this.isValid(i,a)&&this.image.get(i,a)===t;)i+=n;for(i-=n;this.isValid(i,a)&&this.image.get(i,a)===t;)a+=r;return a-=r,new ye(i,a)}expandSquare(e,t,n){let r=n/(2*t),i=e[0].getX()-e[2].getX(),a=e[0].getY()-e[2].getY(),o=(e[0].getX()+e[2].getX())/2,s=(e[0].getY()+e[2].getY())/2,c=new H(o+r*i,s+r*a),l=new H(o-r*i,s-r*a);return i=e[1].getX()-e[3].getX(),a=e[1].getY()-e[3].getY(),o=(e[1].getX()+e[3].getX())/2,s=(e[1].getY()+e[3].getY())/2,[c,new H(o+r*i,s+r*a),l,new H(o-r*i,s-r*a)]}isValid(e,t){return e>=0&&e<this.image.getWidth()&&t>0&&t<this.image.getHeight()}isValidPoint(e){let t=de.round(e.getX()),n=de.round(e.getY());return this.isValid(t,n)}distancePoint(e,t){return de.distance(e.getX(),e.getY(),t.getX(),t.getY())}distanceResultPoint(e,t){return de.distance(e.getX(),e.getY(),t.getX(),t.getY())}getDimension(){return this.compact?4*this.nbLayers+11:this.nbLayers<=4?4*this.nbLayers+15:4*this.nbLayers+2*(_.truncDivision(this.nbLayers-4,8)+1)+15}}class xe{decode(e,t=null){let n=null,r=new be(e.getBlackMatrix()),i=null,a=null;try{let e=r.detectMirror(!1);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new ue().decode(e)}catch(e){n=e}if(a==null)try{let e=r.detectMirror(!0);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new ue().decode(e)}catch(e){throw n??e}let o=new R(a.getText(),a.getRawBytes(),a.getNumBits(),i,z.AZTEC,p.currentTimeMillis()),s=a.getByteSegments();s!=null&&o.putMetadata(ne.BYTE_SEGMENTS,s);let c=a.getECLevel();return c!=null&&o.putMetadata(ne.ERROR_CORRECTION_LEVEL,c),o}reportFoundResultPoints(e,t){if(e!=null){let n=e.get(b.NEED_RESULT_POINT_CALLBACK);n!=null&&t.forEach((e,t,r)=>{n.foundPossibleResultPoint(e)})}}reset(){}}class Se extends L{constructor(e=500){super(new xe,e)}}class Ce{decode(e,t){try{return this.doDecode(e,t)}catch{if(t&&t.get(b.TRY_HARDER)===!0&&e.isRotateSupported()){let n=e.rotateCounterClockwise(),r=this.doDecode(n,t),i=r.getResultMetadata(),a=270;i!==null&&i.get(ne.ORIENTATION)===!0&&(a+=i.get(ne.ORIENTATION)%360),r.putMetadata(ne.ORIENTATION,a);let o=r.getResultPoints();if(o!==null){let e=n.getHeight();for(let t=0;t<o.length;t++)o[t]=new H(e-o[t].getY()-1,o[t].getX())}return r}else throw new k}}reset(){}doDecode(e,t){let n=e.getWidth(),r=e.getHeight(),i=new v(n),a=t&&t.get(b.TRY_HARDER)===!0,o=Math.max(1,r>>(a?8:5)),s;s=a?r:15;let c=Math.trunc(r/2);for(let a=0;a<s;a++){let s=Math.trunc((a+1)/2),l=c+o*(a&1?-s:s);if(l<0||l>=r)break;try{i=e.getBlackRow(l,i)}catch{continue}for(let e=0;e<2;e++){if(e===1&&(i.reverse(),t&&t.get(b.NEED_RESULT_POINT_CALLBACK)===!0)){let e=new Map;t.forEach((t,n)=>e.set(n,t)),e.delete(b.NEED_RESULT_POINT_CALLBACK),t=e}try{let r=this.decodeRow(l,i,t);if(e===1){r.putMetadata(ne.ORIENTATION,180);let e=r.getResultPoints();e!==null&&(e[0]=new H(n-e[0].getX()-1,e[0].getY()),e[1]=new H(n-e[1].getX()-1,e[1].getY()))}return r}catch{}}}throw new k}static recordPattern(e,t,n){let r=n.length;for(let e=0;e<r;e++)n[e]=0;let i=e.getSize();if(t>=i)throw new k;let a=!e.get(t),o=0,s=t;for(;s<i;){if(e.get(s)!==a)n[o]++;else if(++o===r)break;else n[o]=1,a=!a;s++}if(!(o===r||o===r-1&&s===i))throw new k}static recordPatternInReverse(e,t,n){let r=n.length,i=e.get(t);for(;t>0&&r>=0;)e.get(--t)!==i&&(r--,i=!i);if(r>=0)throw new k;Ce.recordPattern(e,t+1,n)}static patternMatchVariance(e,t,n){let r=e.length,i=0,a=0;for(let n=0;n<r;n++)i+=e[n],a+=t[n];if(i<a)return 1/0;let o=i/a;n*=o;let s=0;for(let i=0;i<r;i++){let r=e[i],a=t[i]*o,c=r>a?r-a:a-r;if(c>n)return 1/0;s+=c}return s/i}}class W extends Ce{static findStartPattern(e){let t=e.getSize(),n=e.getNextSet(0),r=0,i=Int32Array.from([0,0,0,0,0,0]),a=n,o=!1;for(let s=n;s<t;s++)if(e.get(s)!==o)i[r]++;else{if(r===5){let t=W.MAX_AVG_VARIANCE,n=-1;for(let e=W.CODE_START_A;e<=W.CODE_START_C;e++){let r=Ce.patternMatchVariance(i,W.CODE_PATTERNS[e],W.MAX_INDIVIDUAL_VARIANCE);r<t&&(t=r,n=e)}if(n>=0&&e.isRange(Math.max(0,a-(s-a)/2),a,!1))return Int32Array.from([a,s,n]);a+=i[0]+i[1],i=i.slice(2,i.length-1),i[r-1]=0,i[r]=0,r--}else r++;i[r]=1,o=!o}throw new k}static decodeCode(e,t,n){Ce.recordPattern(e,n,t);let r=W.MAX_AVG_VARIANCE,i=-1;for(let e=0;e<W.CODE_PATTERNS.length;e++){let n=W.CODE_PATTERNS[e],a=this.patternMatchVariance(t,n,W.MAX_INDIVIDUAL_VARIANCE);a<r&&(r=a,i=e)}if(i>=0)return i;throw new k}decodeRow(e,t,n){let r=n&&n.get(b.ASSUME_GS1)===!0,i=W.findStartPattern(t),a=i[2],o=0,s=new Uint8Array(20);s[o++]=a;let c;switch(a){case W.CODE_START_A:c=W.CODE_CODE_A;break;case W.CODE_START_B:c=W.CODE_CODE_B;break;case W.CODE_START_C:c=W.CODE_CODE_C;break;default:throw new x}let l=!1,u=!1,f=``,p=i[0],m=i[1],h=Int32Array.from([0,0,0,0,0,0]),g=0,_=0,v=a,y=0,S=!0,C=!1,w=!1;for(;!l;){let e=u;switch(u=!1,g=_,_=W.decodeCode(t,h,m),s[o++]=_,_!==W.CODE_STOP&&(S=!0),_!==W.CODE_STOP&&(y++,v+=y*_),p=m,m+=h.reduce((e,t)=>e+t,0),_){case W.CODE_START_A:case W.CODE_START_B:case W.CODE_START_C:throw new x}switch(c){case W.CODE_CODE_A:if(_<64)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else if(_<96)w===C?f+=String.fromCharCode(_-64):f+=String.fromCharCode(_+64),w=!1;else switch(_!==W.CODE_STOP&&(S=!1),_){case W.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case W.CODE_FNC_2:case W.CODE_FNC_3:break;case W.CODE_FNC_4_A:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case W.CODE_SHIFT:u=!0,c=W.CODE_CODE_B;break;case W.CODE_CODE_B:c=W.CODE_CODE_B;break;case W.CODE_CODE_C:c=W.CODE_CODE_C;break;case W.CODE_STOP:l=!0;break}break;case W.CODE_CODE_B:if(_<96)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else switch(_!==W.CODE_STOP&&(S=!1),_){case W.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case W.CODE_FNC_2:case W.CODE_FNC_3:break;case W.CODE_FNC_4_B:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case W.CODE_SHIFT:u=!0,c=W.CODE_CODE_A;break;case W.CODE_CODE_A:c=W.CODE_CODE_A;break;case W.CODE_CODE_C:c=W.CODE_CODE_C;break;case W.CODE_STOP:l=!0;break}break;case W.CODE_CODE_C:if(_<100)_<10&&(f+=`0`),f+=_;else switch(_!==W.CODE_STOP&&(S=!1),_){case W.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case W.CODE_CODE_A:c=W.CODE_CODE_A;break;case W.CODE_CODE_B:c=W.CODE_CODE_B;break;case W.CODE_STOP:l=!0;break}break}e&&(c=c===W.CODE_CODE_A?W.CODE_CODE_B:W.CODE_CODE_A)}let T=m-p;if(m=t.getNextUnset(m),!t.isRange(m,Math.min(t.getSize(),m+(m-p)/2),!1))throw new k;if(v-=y*g,v%103!==g)throw new d;let E=f.length;if(E===0)throw new k;E>0&&S&&(f=c===W.CODE_CODE_C?f.substring(0,E-2):f.substring(0,E-1));let D=(i[1]+i[0])/2,O=p+T/2,A=s.length,j=new Uint8Array(A);for(let e=0;e<A;e++)j[e]=s[e];let M=[new H(D,e),new H(O,e)];return new R(f,j,0,M,z.CODE_128,new Date().getTime())}}W.CODE_PATTERNS=[Int32Array.from([2,1,2,2,2,2]),Int32Array.from([2,2,2,1,2,2]),Int32Array.from([2,2,2,2,2,1]),Int32Array.from([1,2,1,2,2,3]),Int32Array.from([1,2,1,3,2,2]),Int32Array.from([1,3,1,2,2,2]),Int32Array.from([1,2,2,2,1,3]),Int32Array.from([1,2,2,3,1,2]),Int32Array.from([1,3,2,2,1,2]),Int32Array.from([2,2,1,2,1,3]),Int32Array.from([2,2,1,3,1,2]),Int32Array.from([2,3,1,2,1,2]),Int32Array.from([1,1,2,2,3,2]),Int32Array.from([1,2,2,1,3,2]),Int32Array.from([1,2,2,2,3,1]),Int32Array.from([1,1,3,2,2,2]),Int32Array.from([1,2,3,1,2,2]),Int32Array.from([1,2,3,2,2,1]),Int32Array.from([2,2,3,2,1,1]),Int32Array.from([2,2,1,1,3,2]),Int32Array.from([2,2,1,2,3,1]),Int32Array.from([2,1,3,2,1,2]),Int32Array.from([2,2,3,1,1,2]),Int32Array.from([3,1,2,1,3,1]),Int32Array.from([3,1,1,2,2,2]),Int32Array.from([3,2,1,1,2,2]),Int32Array.from([3,2,1,2,2,1]),Int32Array.from([3,1,2,2,1,2]),Int32Array.from([3,2,2,1,1,2]),Int32Array.from([3,2,2,2,1,1]),Int32Array.from([2,1,2,1,2,3]),Int32Array.from([2,1,2,3,2,1]),Int32Array.from([2,3,2,1,2,1]),Int32Array.from([1,1,1,3,2,3]),Int32Array.from([1,3,1,1,2,3]),Int32Array.from([1,3,1,3,2,1]),Int32Array.from([1,1,2,3,1,3]),Int32Array.from([1,3,2,1,1,3]),Int32Array.from([1,3,2,3,1,1]),Int32Array.from([2,1,1,3,1,3]),Int32Array.from([2,3,1,1,1,3]),Int32Array.from([2,3,1,3,1,1]),Int32Array.from([1,1,2,1,3,3]),Int32Array.from([1,1,2,3,3,1]),Int32Array.from([1,3,2,1,3,1]),Int32Array.from([1,1,3,1,2,3]),Int32Array.from([1,1,3,3,2,1]),Int32Array.from([1,3,3,1,2,1]),Int32Array.from([3,1,3,1,2,1]),Int32Array.from([2,1,1,3,3,1]),Int32Array.from([2,3,1,1,3,1]),Int32Array.from([2,1,3,1,1,3]),Int32Array.from([2,1,3,3,1,1]),Int32Array.from([2,1,3,1,3,1]),Int32Array.from([3,1,1,1,2,3]),Int32Array.from([3,1,1,3,2,1]),Int32Array.from([3,3,1,1,2,1]),Int32Array.from([3,1,2,1,1,3]),Int32Array.from([3,1,2,3,1,1]),Int32Array.from([3,3,2,1,1,1]),Int32Array.from([3,1,4,1,1,1]),Int32Array.from([2,2,1,4,1,1]),Int32Array.from([4,3,1,1,1,1]),Int32Array.from([1,1,1,2,2,4]),Int32Array.from([1,1,1,4,2,2]),Int32Array.from([1,2,1,1,2,4]),Int32Array.from([1,2,1,4,2,1]),Int32Array.from([1,4,1,1,2,2]),Int32Array.from([1,4,1,2,2,1]),Int32Array.from([1,1,2,2,1,4]),Int32Array.from([1,1,2,4,1,2]),Int32Array.from([1,2,2,1,1,4]),Int32Array.from([1,2,2,4,1,1]),Int32Array.from([1,4,2,1,1,2]),Int32Array.from([1,4,2,2,1,1]),Int32Array.from([2,4,1,2,1,1]),Int32Array.from([2,2,1,1,1,4]),Int32Array.from([4,1,3,1,1,1]),Int32Array.from([2,4,1,1,1,2]),Int32Array.from([1,3,4,1,1,1]),Int32Array.from([1,1,1,2,4,2]),Int32Array.from([1,2,1,1,4,2]),Int32Array.from([1,2,1,2,4,1]),Int32Array.from([1,1,4,2,1,2]),Int32Array.from([1,2,4,1,1,2]),Int32Array.from([1,2,4,2,1,1]),Int32Array.from([4,1,1,2,1,2]),Int32Array.from([4,2,1,1,1,2]),Int32Array.from([4,2,1,2,1,1]),Int32Array.from([2,1,2,1,4,1]),Int32Array.from([2,1,4,1,2,1]),Int32Array.from([4,1,2,1,2,1]),Int32Array.from([1,1,1,1,4,3]),Int32Array.from([1,1,1,3,4,1]),Int32Array.from([1,3,1,1,4,1]),Int32Array.from([1,1,4,1,1,3]),Int32Array.from([1,1,4,3,1,1]),Int32Array.from([4,1,1,1,1,3]),Int32Array.from([4,1,1,3,1,1]),Int32Array.from([1,1,3,1,4,1]),Int32Array.from([1,1,4,1,3,1]),Int32Array.from([3,1,1,1,4,1]),Int32Array.from([4,1,1,1,3,1]),Int32Array.from([2,1,1,4,1,2]),Int32Array.from([2,1,1,2,1,4]),Int32Array.from([2,1,1,2,3,2]),Int32Array.from([2,3,3,1,1,1,2])],W.MAX_AVG_VARIANCE=.25,W.MAX_INDIVIDUAL_VARIANCE=.7,W.CODE_SHIFT=98,W.CODE_CODE_C=99,W.CODE_CODE_B=100,W.CODE_CODE_A=101,W.CODE_FNC_1=102,W.CODE_FNC_2=97,W.CODE_FNC_3=96,W.CODE_FNC_4_A=101,W.CODE_FNC_4_B=100,W.CODE_START_A=103,W.CODE_START_B=104,W.CODE_START_C=105,W.CODE_STOP=106;class we extends Ce{constructor(e=!1,t=!1){super(),this.usingCheckDigit=e,this.extendedMode=t,this.decodeRowResult=``,this.counters=new Int32Array(9)}decodeRow(e,t,n){let r=this.counters;r.fill(0),this.decodeRowResult=``;let i=we.findAsteriskPattern(t,r),a=t.getNextSet(i[1]),o=t.getSize(),s,c;do{we.recordPattern(t,a,r);let e=we.toNarrowWidePattern(r);if(e<0)throw new k;s=we.patternToChar(e),this.decodeRowResult+=s,c=a;for(let e of r)a+=e;a=t.getNextSet(a)}while(s!==`*`);this.decodeRowResult=this.decodeRowResult.substring(0,this.decodeRowResult.length-1);let l=0;for(let e of r)l+=e;let u=a-c-l;if(a!==o&&u*2<l)throw new k;if(this.usingCheckDigit){let e=this.decodeRowResult.length-1,t=0;for(let n=0;n<e;n++)t+=we.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(n));if(this.decodeRowResult.charAt(e)!==we.ALPHABET_STRING.charAt(t%43))throw new d;this.decodeRowResult=this.decodeRowResult.substring(0,e)}if(this.decodeRowResult.length===0)throw new k;let f;f=this.extendedMode?we.decodeExtended(this.decodeRowResult):this.decodeRowResult;let p=(i[1]+i[0])/2,m=c+l/2;return new R(f,null,0,[new H(p,e),new H(m,e)],z.CODE_39,new Date().getTime())}static findAsteriskPattern(e,t){let n=e.getSize(),r=e.getNextSet(0),i=0,a=r,o=!1,s=t.length;for(let c=r;c<n;c++)if(e.get(c)!==o)t[i]++;else{if(i===s-1){if(this.toNarrowWidePattern(t)===we.ASTERISK_ENCODING&&e.isRange(Math.max(0,a-Math.floor((c-a)/2)),a,!1))return[a,c];a+=t[0]+t[1],t.copyWithin(0,2,2+i-1),t[i-1]=0,t[i]=0,i--}else i++;t[i]=1,o=!o}throw new k}static toNarrowWidePattern(e){let t=e.length,n=0,r;do{let i=2147483647;for(let t of e)t<i&&t>n&&(i=t);n=i,r=0;let a=0,o=0;for(let i=0;i<t;i++){let s=e[i];s>n&&(o|=1<<t-1-i,r++,a+=s)}if(r===3){for(let i=0;i<t&&r>0;i++){let t=e[i];if(t>n&&(r--,t*2>=a))return-1}return o}}while(r>3);return-1}static patternToChar(e){for(let t=0;t<we.CHARACTER_ENCODINGS.length;t++)if(we.CHARACTER_ENCODINGS[t]===e)return we.ALPHABET_STRING.charAt(t);if(e===we.ASTERISK_ENCODING)return`*`;throw new k}static decodeExtended(e){let t=e.length,n=``;for(let r=0;r<t;r++){let t=e.charAt(r);if(t===`+`||t===`$`||t===`%`||t===`/`){let i=e.charAt(r+1),a=`\0`;switch(t){case`+`:if(i>=`A`&&i<=`Z`)a=String.fromCharCode(i.charCodeAt(0)+32);else throw new x;break;case`$`:if(i>=`A`&&i<=`Z`)a=String.fromCharCode(i.charCodeAt(0)-64);else throw new x;break;case`%`:if(i>=`A`&&i<=`E`)a=String.fromCharCode(i.charCodeAt(0)-38);else if(i>=`F`&&i<=`J`)a=String.fromCharCode(i.charCodeAt(0)-11);else if(i>=`K`&&i<=`O`)a=String.fromCharCode(i.charCodeAt(0)+16);else if(i>=`P`&&i<=`T`)a=String.fromCharCode(i.charCodeAt(0)+43);else if(i===`U`)a=`\0`;else if(i===`V`)a=`@`;else if(i===`W`)a="`";else if(i===`X`||i===`Y`||i===`Z`)a=``;else throw new x;break;case`/`:if(i>=`A`&&i<=`O`)a=String.fromCharCode(i.charCodeAt(0)-32);else if(i===`Z`)a=`:`;else throw new x;break}n+=a,r++}else n+=t}return n}}we.ALPHABET_STRING=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%`,we.CHARACTER_ENCODINGS=[52,289,97,352,49,304,112,37,292,100,265,73,328,25,280,88,13,268,76,28,259,67,322,19,274,82,7,262,70,22,385,193,448,145,400,208,133,388,196,168,162,138,42],we.ASTERISK_ENCODING=148;class Te extends Ce{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,t,n){let r=this.decodeStart(t),i=this.decodeEnd(t),a=new D;Te.decodeMiddle(t,r[1],i[0],a);let o=a.toString(),s=null;n!=null&&(s=n.get(b.ALLOWED_LENGTHS)),s??=Te.DEFAULT_ALLOWED_LENGTHS;let c=o.length,l=!1,u=0;for(let e of s){if(c===e){l=!0;break}e>u&&(u=e)}if(!l&&c>u&&(l=!0),!l)throw new x;return new R(o,null,0,[new H(r[1],e),new H(i[0],e)],z.ITF,new Date().getTime())}static decodeMiddle(e,t,n,r){let i=new Int32Array(10),a=new Int32Array(5),o=new Int32Array(5);for(i.fill(0),a.fill(0),o.fill(0);t<n;){Ce.recordPattern(e,t,i);for(let e=0;e<5;e++){let t=2*e;a[e]=i[t],o[e]=i[t+1]}let n=Te.decodeDigit(a);r.append(n.toString()),n=this.decodeDigit(o),r.append(n.toString()),i.forEach(function(e){t+=e})}}decodeStart(e){let t=Te.skipWhiteSpace(e),n=Te.findGuardPattern(e,t,Te.START_PATTERN);return this.narrowLineWidth=(n[1]-n[0])/4,this.validateQuietZone(e,n[0]),n}validateQuietZone(e,t){let n=this.narrowLineWidth*10;n=n<t?n:t;for(let r=t-1;n>0&&r>=0&&!e.get(r);r--)n--;if(n!==0)throw new k}static skipWhiteSpace(e){let t=e.getSize(),n=e.getNextSet(0);if(n===t)throw new k;return n}decodeEnd(e){e.reverse();try{let t=Te.skipWhiteSpace(e),n;try{n=Te.findGuardPattern(e,t,Te.END_PATTERN_REVERSED[0])}catch(r){r instanceof k&&(n=Te.findGuardPattern(e,t,Te.END_PATTERN_REVERSED[1]))}this.validateQuietZone(e,n[0]);let r=n[0];return n[0]=e.getSize()-n[1],n[1]=e.getSize()-r,n}finally{e.reverse()}}static findGuardPattern(e,t,n){let r=n.length,i=new Int32Array(r),a=e.getSize(),o=!1,s=0,c=t;i.fill(0);for(let l=t;l<a;l++)if(e.get(l)!==o)i[s]++;else{if(s===r-1){if(Ce.patternMatchVariance(i,n,Te.MAX_INDIVIDUAL_VARIANCE)<Te.MAX_AVG_VARIANCE)return[c,l];c+=i[0]+i[1],p.arraycopy(i,2,i,0,s-1),i[s-1]=0,i[s]=0,s--}else s++;i[s]=1,o=!o}throw new k}static decodeDigit(e){let t=Te.MAX_AVG_VARIANCE,n=-1,r=Te.PATTERNS.length;for(let i=0;i<r;i++){let r=Te.PATTERNS[i],a=Ce.patternMatchVariance(e,r,Te.MAX_INDIVIDUAL_VARIANCE);a<t?(t=a,n=i):a===t&&(n=-1)}if(n>=0)return n%10;throw new k}}Te.PATTERNS=[Int32Array.from([1,1,2,2,1]),Int32Array.from([2,1,1,1,2]),Int32Array.from([1,2,1,1,2]),Int32Array.from([2,2,1,1,1]),Int32Array.from([1,1,2,1,2]),Int32Array.from([2,1,2,1,1]),Int32Array.from([1,2,2,1,1]),Int32Array.from([1,1,1,2,2]),Int32Array.from([2,1,1,2,1]),Int32Array.from([1,2,1,2,1]),Int32Array.from([1,1,3,3,1]),Int32Array.from([3,1,1,1,3]),Int32Array.from([1,3,1,1,3]),Int32Array.from([3,3,1,1,1]),Int32Array.from([1,1,3,1,3]),Int32Array.from([3,1,3,1,1]),Int32Array.from([1,3,3,1,1]),Int32Array.from([1,1,1,3,3]),Int32Array.from([3,1,1,3,1]),Int32Array.from([1,3,1,3,1])],Te.MAX_AVG_VARIANCE=.38,Te.MAX_INDIVIDUAL_VARIANCE=.5,Te.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],Te.START_PATTERN=Int32Array.from([1,1,1,1]),Te.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class Ee extends Ce{constructor(){super(...arguments),this.decodeRowStringBuffer=``}static findStartGuardPattern(e){let t=!1,n,r=0,i=Int32Array.from([0,0,0]);for(;!t;){i=Int32Array.from([0,0,0]),n=Ee.findGuardPattern(e,r,!1,this.START_END_PATTERN,i);let a=n[0];r=n[1];let o=a-(r-a);o>=0&&(t=e.isRange(o,a,!1))}return n}static checkChecksum(e){return Ee.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return Ee.getStandardUPCEANChecksum(e.substring(0,t-1))===n}static getStandardUPCEANChecksum(e){let t=e.length,n=0;for(let r=t-1;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}n*=3;for(let r=t-2;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}return(1e3-n)%10}static decodeEnd(e,t){return Ee.findGuardPattern(e,t,!1,Ee.START_END_PATTERN,new Int32Array(Ee.START_END_PATTERN.length).fill(0))}static findGuardPatternWithoutCounters(e,t,n,r){return this.findGuardPattern(e,t,n,r,new Int32Array(r.length))}static findGuardPattern(e,t,n,r,i){let a=e.getSize();t=n?e.getNextUnset(t):e.getNextSet(t);let o=0,s=t,c=r.length,l=n;for(let n=t;n<a;n++)if(e.get(n)!==l)i[o]++;else{if(o===c-1){if(Ce.patternMatchVariance(i,r,Ee.MAX_INDIVIDUAL_VARIANCE)<Ee.MAX_AVG_VARIANCE)return Int32Array.from([s,n]);s+=i[0]+i[1];let e=i.slice(2,i.length-1);for(let t=0;t<o-1;t++)i[t]=e[t];i[o-1]=0,i[o]=0,o--}else o++;i[o]=1,l=!l}throw new k}static decodeDigit(e,t,n,r){this.recordPattern(e,n,t);let i=this.MAX_AVG_VARIANCE,a=-1,o=r.length;for(let e=0;e<o;e++){let n=r[e],o=Ce.patternMatchVariance(t,n,Ee.MAX_INDIVIDUAL_VARIANCE);o<i&&(i=o,a=e)}if(a>=0)return a;throw new k}}Ee.MAX_AVG_VARIANCE=.48,Ee.MAX_INDIVIDUAL_VARIANCE=.7,Ee.START_END_PATTERN=Int32Array.from([1,1,1]),Ee.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),Ee.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Ee.L_PATTERNS=[Int32Array.from([3,2,1,1]),Int32Array.from([2,2,2,1]),Int32Array.from([2,1,2,2]),Int32Array.from([1,4,1,1]),Int32Array.from([1,1,3,2]),Int32Array.from([1,2,3,1]),Int32Array.from([1,1,1,4]),Int32Array.from([1,3,1,2]),Int32Array.from([1,2,1,3]),Int32Array.from([3,1,1,2])];class De{constructor(){this.CHECK_DIGIT_ENCODINGS=[24,20,18,17,12,6,3,10,9,5],this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=``}decodeRow(e,t,n){let r=this.decodeRowStringBuffer,i=this.decodeMiddle(t,n,r),a=r.toString(),o=De.parseExtensionString(a),s=new R(a,null,0,[new H((n[0]+n[1])/2,e),new H(i,e)],z.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<5&&a<i;t++){let i=Ee.decodeDigit(e,r,a,Ee.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<4-t),t!==4&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==5)throw new k;let s=this.determineCheckDigit(o);if(De.extensionChecksum(n.toString())!==s)throw new k;return a}static extensionChecksum(e){let t=e.length,n=0;for(let r=t-2;r>=0;r-=2)n+=e.charAt(r).charCodeAt(0)-48;n*=3;for(let r=t-1;r>=0;r-=2)n+=e.charAt(r).charCodeAt(0)-48;return n*=3,n%10}determineCheckDigit(e){for(let t=0;t<10;t++)if(e===this.CHECK_DIGIT_ENCODINGS[t])return t;throw new k}static parseExtensionString(e){if(e.length!==5)return null;let t=De.parseExtension5String(e);return t==null?null:new Map([[ne.SUGGESTED_PRICE,t]])}static parseExtension5String(e){let t;switch(e.charAt(0)){case`0`:t=`£`;break;case`5`:t=`$`;break;case`9`:switch(e){case`90000`:return null;case`99991`:return`0.00`;case`99990`:return`Used`}t=``;break;default:t=``;break}let n=parseInt(e.substring(1)),r=(n/100).toString(),i=n%100,a=i<10?`0`+i:i.toString();return t+r+`.`+a}}class Oe{constructor(){this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=``}decodeRow(e,t,n){let r=this.decodeRowStringBuffer,i=this.decodeMiddle(t,n,r),a=r.toString(),o=Oe.parseExtensionString(a),s=new R(a,null,0,[new H((n[0]+n[1])/2,e),new H(i,e)],z.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<2&&a<i;t++){let i=Ee.decodeDigit(e,r,a,Ee.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<1-t),t!==1&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==2||parseInt(n.toString())%4!==o)throw new k;return a}static parseExtensionString(e){return e.length===2?new Map([[ne.ISSUE_NUMBER,parseInt(e)]]):null}}class ke{static decodeRow(e,t,n){let r=Ee.findGuardPattern(t,n,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new De().decodeRow(e,t,r)}catch{return new Oe().decodeRow(e,t,r)}}}ke.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class Ae extends Ee{constructor(){super(),this.decodeRowStringBuffer=``,Ae.L_AND_G_PATTERNS=Ae.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let t=Ae.L_PATTERNS[e-10],n=new Int32Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[t.length-e-1];Ae.L_AND_G_PATTERNS[e]=n}}decodeRow(e,t,n){let r=Ae.findStartGuardPattern(t),i=n==null?null:n.get(b.NEED_RESULT_POINT_CALLBACK);if(i!=null){let t=new H((r[0]+r[1])/2,e);i.foundPossibleResultPoint(t)}let a=this.decodeMiddle(t,r,this.decodeRowStringBuffer),o=a.rowOffset,s=a.resultString;if(i!=null){let t=new H(o,e);i.foundPossibleResultPoint(t)}let c=this.decodeEnd(t,o);if(i!=null){let t=new H((c[0]+c[1])/2,e);i.foundPossibleResultPoint(t)}let l=c[1],u=l+(l-c[0]);if(u>=t.getSize()||!t.isRange(l,u,!1))throw new k;let f=s.toString();if(f.length<8)throw new x;if(!Ae.checkChecksum(f))throw new d;let p=(r[1]+r[0])/2,m=(c[1]+c[0])/2,h=this.getBarcodeFormat(),g=new R(f,null,0,[new H(p,e),new H(m,e)],h,new Date().getTime()),_=0;try{let n=ke.decodeRow(e,t,c[1]);g.putMetadata(ne.UPC_EAN_EXTENSION,n.getText()),g.putAllMetadata(n.getResultMetadata()),g.addResultPoints(n.getResultPoints()),_=n.getText().length}catch{}let v=n==null?null:n.get(b.ALLOWED_EAN_EXTENSIONS);if(v!=null){let e=!1;for(let t in v)if(_.toString()===t){e=!0;break}if(!e)throw new k}return g}decodeEnd(e,t){return Ae.findGuardPattern(e,t,!1,Ae.START_END_PATTERN,new Int32Array(Ae.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return Ae.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return Ae.getStandardUPCEANChecksum(e.substring(0,t-1))===n}static getStandardUPCEANChecksum(e){let t=e.length,n=0;for(let r=t-1;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}n*=3;for(let r=t-2;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}return(1e3-n)%10}}class je extends Ae{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<6&&a<i;t++){let i=Ae.decodeDigit(e,r,a,Ae.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}n=je.determineFirstDigit(n,o),a=Ae.findGuardPattern(e,a,!0,Ae.MIDDLE_PATTERN,new Int32Array(Ae.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<6&&a<i;t++){let t=Ae.decodeDigit(e,r,a,Ae.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return z.EAN_13}static determineFirstDigit(e,t){for(let n=0;n<10;n++)if(t===this.FIRST_DIGIT_ENCODINGS[n])return e=String.fromCharCode(48+n)+e,e;throw new k}}je.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class Me extends Ae{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1];for(let t=0;t<4&&a<i;t++){let t=Ae.decodeDigit(e,r,a,Ae.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}a=Ae.findGuardPattern(e,a,!0,Ae.MIDDLE_PATTERN,new Int32Array(Ae.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<4&&a<i;t++){let t=Ae.decodeDigit(e,r,a,Ae.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return z.EAN_8}}class Ne extends Ae{constructor(){super(...arguments),this.ean13Reader=new je}getBarcodeFormat(){return z.UPC_A}decode(e,t){return this.maybeReturnResult(this.ean13Reader.decode(e))}decodeRow(e,t,n){return this.maybeReturnResult(this.ean13Reader.decodeRow(e,t,n))}decodeMiddle(e,t,n){return this.ean13Reader.decodeMiddle(e,t,n)}maybeReturnResult(e){let t=e.getText();if(t.charAt(0)===`0`){let n=new R(t.substring(1),null,null,e.getResultPoints(),z.UPC_A);return e.getResultMetadata()!=null&&n.putAllMetadata(e.getResultMetadata()),n}else throw new k}reset(){this.ean13Reader.reset()}}class Pe extends Ae{constructor(){super(),this.decodeMiddleCounters=new Int32Array(4)}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters.map(e=>e);r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<6&&a<i;t++){let i=Pe.decodeDigit(e,r,a,Pe.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}let s=Pe.determineNumSysAndCheckDigit(n,o);return{rowOffset:a,resultString:s}}decodeEnd(e,t){return Pe.findGuardPatternWithoutCounters(e,t,!0,Pe.MIDDLE_END_PATTERN)}checkChecksum(e){return Ae.checkChecksum(Pe.convertUPCEtoUPCA(e))}static determineNumSysAndCheckDigit(e,t){for(let n=0;n<=1;n++)for(let r=0;r<10;r++)if(t===this.NUMSYS_AND_CHECK_DIGIT_PATTERNS[n][r]){let t=String.fromCharCode(48+n),i=String.fromCharCode(48+r);return t+e+i}throw k.getNotFoundInstance()}getBarcodeFormat(){return z.UPC_E}static convertUPCEtoUPCA(e){let t=e.slice(1,7).split(``).map(e=>e.charCodeAt(0)),n=new D;n.append(e.charAt(0));let r=t[5];switch(r){case 0:case 1:case 2:n.appendChars(t,0,2),n.append(r),n.append(`0000`),n.appendChars(t,2,3);break;case 3:n.appendChars(t,0,3),n.append(`00000`),n.appendChars(t,3,2);break;case 4:n.appendChars(t,0,4),n.append(`00000`),n.append(t[4]);break;default:n.appendChars(t,0,5),n.append(`0000`),n.append(r);break}return e.length>=8&&n.append(e.charAt(7)),n.toString()}}Pe.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Pe.NUMSYS_AND_CHECK_DIGIT_PATTERNS=[Int32Array.from([56,52,50,49,44,38,35,42,41,37]),Int32Array.from([7,11,13,14,19,25,28,21,22,26])];class Fe extends Ce{constructor(e){super();let n=e==null?null:e.get(b.POSSIBLE_FORMATS),r=[];t(n)?(r.push(new je),r.push(new Ne),r.push(new Me),r.push(new Pe)):(n.indexOf(z.EAN_13)>-1&&r.push(new je),n.indexOf(z.UPC_A)>-1&&r.push(new Ne),n.indexOf(z.EAN_8)>-1&&r.push(new Me),n.indexOf(z.UPC_E)>-1&&r.push(new Pe)),this.readers=r}decodeRow(e,t,n){for(let r of this.readers)try{let i=r.decodeRow(e,t,n),a=i.getBarcodeFormat()===z.EAN_13&&i.getText().charAt(0)===`0`,o=n==null?null:n.get(b.POSSIBLE_FORMATS),s=o==null||o.includes(z.UPC_A);if(a&&s){let e=i.getRawBytes(),t=new R(i.getText().substring(1),e,e?e.length:null,i.getResultPoints(),z.UPC_A);return t.putAllMetadata(i.getResultMetadata()),t}return i}catch{}throw new k}reset(){for(let e of this.readers)e.reset()}}class Ie extends Ce{constructor(){super(),this.decodeFinderCounters=new Int32Array(4),this.dataCharacterCounters=new Int32Array(8),this.oddRoundingErrors=[,,,,],this.evenRoundingErrors=[,,,,],this.oddCounts=Array(this.dataCharacterCounters.length/2),this.evenCounts=Array(this.dataCharacterCounters.length/2)}getDecodeFinderCounters(){return this.decodeFinderCounters}getDataCharacterCounters(){return this.dataCharacterCounters}getOddRoundingErrors(){return this.oddRoundingErrors}getEvenRoundingErrors(){return this.evenRoundingErrors}getOddCounts(){return this.oddCounts}getEvenCounts(){return this.evenCounts}parseFinderValue(e,t){for(let n=0;n<t.length;n++)if(Ce.patternMatchVariance(e,t[n],Ie.MAX_INDIVIDUAL_VARIANCE)<Ie.MAX_AVG_VARIANCE)return n;throw new k}static count(e){return de.sum(new Int32Array(e))}static increment(e,t){let n=0,r=t[0];for(let i=1;i<e.length;i++)t[i]>r&&(r=t[i],n=i);e[n]++}static decrement(e,t){let n=0,r=t[0];for(let i=1;i<e.length;i++)t[i]<r&&(r=t[i],n=i);e[n]--}static isFinderPattern(e){let t=e[0]+e[1],n=t/(t+e[2]+e[3]);if(n>=Ie.MIN_FINDER_PATTERN_RATIO&&n<=Ie.MAX_FINDER_PATTERN_RATIO){let t=2**53-1,n=-(2**53-1);for(let r of e)r>n&&(n=r),r<t&&(t=r);return n<10*t}return!1}}Ie.MAX_AVG_VARIANCE=.2,Ie.MAX_INDIVIDUAL_VARIANCE=.45,Ie.MIN_FINDER_PATTERN_RATIO=9.5/12,Ie.MAX_FINDER_PATTERN_RATIO=12.5/14;class Le{constructor(e,t){this.value=e,this.checksumPortion=t}getValue(){return this.value}getChecksumPortion(){return this.checksumPortion}toString(){return this.value+`(`+this.checksumPortion+`)`}equals(e){if(!(e instanceof Le))return!1;let t=e;return this.value===t.value&&this.checksumPortion===t.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class Re{constructor(e,t,n,r,i){this.value=e,this.startEnd=t,this.value=e,this.startEnd=t,this.resultPoints=[],this.resultPoints.push(new H(n,i)),this.resultPoints.push(new H(r,i))}getValue(){return this.value}getStartEnd(){return this.startEnd}getResultPoints(){return this.resultPoints}equals(e){if(!(e instanceof Re))return!1;let t=e;return this.value===t.value}hashCode(){return this.value}}class ze{constructor(){}static getRSSvalue(e,t,n){let r=0;for(let t of e)r+=t;let i=0,a=0,o=e.length;for(let s=0;s<o-1;s++){let c;for(c=1,a|=1<<s;c<e[s];c++,a&=~(1<<s)){let e=ze.combins(r-c-1,o-s-2);if(n&&a===0&&r-c-(o-s-1)>=o-s-1&&(e-=ze.combins(r-c-(o-s),o-s-2)),o-s-1>1){let n=0;for(let e=r-c-(o-s-2);e>t;e--)n+=ze.combins(r-c-e-1,o-s-3);e-=n*(o-1-s)}else r-c>t&&e--;i+=e}r-=c}return i}static combins(e,t){let n,r;e-t>t?(r=t,n=e-t):(r=e-t,n=t);let i=1,a=1;for(let t=e;t>n;t--)i*=t,a<=r&&(i/=a,a++);for(;a<=r;)i/=a,a++;return i}}class Be{static buildBitArray(e){let t=e.length*2-1;e[e.length-1].getRightChar()??--t;let n=new v(12*t),r=0,i=e[0].getRightChar().getValue();for(let e=11;e>=0;--e)i&1<<e&&n.set(r),r++;for(let t=1;t<e.length;++t){let i=e[t],a=i.getLeftChar().getValue();for(let e=11;e>=0;--e)a&1<<e&&n.set(r),r++;if(i.getRightChar()!=null){let e=i.getRightChar().getValue();for(let t=11;t>=0;--t)e&1<<t&&n.set(r),r++}}return n}}class Ve{constructor(e,t){t?this.decodedInformation=null:(this.finished=e,this.decodedInformation=t)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class He{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class Ue extends He{constructor(e,t){super(e),this.value=t}getValue(){return this.value}isFNC1(){return this.value===Ue.FNC1}}Ue.FNC1=`$`;class We extends He{constructor(e,t,n){super(e),n?(this.remaining=!0,this.remainingValue=this.remainingValue):(this.remaining=!1,this.remainingValue=0),this.newString=t}getNewString(){return this.newString}isRemaining(){return this.remaining}getRemainingValue(){return this.remainingValue}}class Ge extends He{constructor(e,t,n){if(super(e),t<0||t>10||n<0||n>10)throw new x;this.firstDigit=t,this.secondDigit=n}getFirstDigit(){return this.firstDigit}getSecondDigit(){return this.secondDigit}getValue(){return this.firstDigit*10+this.secondDigit}isFirstDigitFNC1(){return this.firstDigit===Ge.FNC1}isSecondDigitFNC1(){return this.secondDigit===Ge.FNC1}isAnyFNC1(){return this.firstDigit===Ge.FNC1||this.secondDigit===Ge.FNC1}}Ge.FNC1=10;class Ke{constructor(){}static parseFieldsInGeneralPurpose(e){if(!e)return null;if(e.length<2)throw new k;let t=e.substring(0,2);for(let n of Ke.TWO_DIGIT_DATA_LENGTH)if(n[0]===t)return n[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(2,n[2],e):Ke.processFixedAI(2,n[1],e);if(e.length<3)throw new k;let n=e.substring(0,3);for(let t of Ke.THREE_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(3,t[2],e):Ke.processFixedAI(3,t[1],e);for(let t of Ke.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(4,t[2],e):Ke.processFixedAI(4,t[1],e);if(e.length<4)throw new k;let r=e.substring(0,4);for(let t of Ke.FOUR_DIGIT_DATA_LENGTH)if(t[0]===r)return t[1]===Ke.VARIABLE_LENGTH?Ke.processVariableAI(4,t[2],e):Ke.processFixedAI(4,t[1],e);throw new k}static processFixedAI(e,t,n){if(n.length<e)throw new k;let r=n.substring(0,e);if(n.length<e+t)throw new k;let i=n.substring(e,e+t),a=n.substring(e+t),o=`(`+r+`)`+i,s=Ke.parseFieldsInGeneralPurpose(a);return s==null?o:o+s}static processVariableAI(e,t,n){let r=n.substring(0,e),i;i=n.length<e+t?n.length:e+t;let a=n.substring(e,i),o=n.substring(i),s=`(`+r+`)`+a,c=Ke.parseFieldsInGeneralPurpose(o);return c==null?s:s+c}}Ke.VARIABLE_LENGTH=[],Ke.TWO_DIGIT_DATA_LENGTH=[[`00`,18],[`01`,14],[`02`,14],[`10`,Ke.VARIABLE_LENGTH,20],[`11`,6],[`12`,6],[`13`,6],[`15`,6],[`17`,6],[`20`,2],[`21`,Ke.VARIABLE_LENGTH,20],[`22`,Ke.VARIABLE_LENGTH,29],[`30`,Ke.VARIABLE_LENGTH,8],[`37`,Ke.VARIABLE_LENGTH,8],[`90`,Ke.VARIABLE_LENGTH,30],[`91`,Ke.VARIABLE_LENGTH,30],[`92`,Ke.VARIABLE_LENGTH,30],[`93`,Ke.VARIABLE_LENGTH,30],[`94`,Ke.VARIABLE_LENGTH,30],[`95`,Ke.VARIABLE_LENGTH,30],[`96`,Ke.VARIABLE_LENGTH,30],[`97`,Ke.VARIABLE_LENGTH,3],[`98`,Ke.VARIABLE_LENGTH,30],[`99`,Ke.VARIABLE_LENGTH,30]],Ke.THREE_DIGIT_DATA_LENGTH=[[`240`,Ke.VARIABLE_LENGTH,30],[`241`,Ke.VARIABLE_LENGTH,30],[`242`,Ke.VARIABLE_LENGTH,6],[`250`,Ke.VARIABLE_LENGTH,30],[`251`,Ke.VARIABLE_LENGTH,30],[`253`,Ke.VARIABLE_LENGTH,17],[`254`,Ke.VARIABLE_LENGTH,20],[`400`,Ke.VARIABLE_LENGTH,30],[`401`,Ke.VARIABLE_LENGTH,30],[`402`,17],[`403`,Ke.VARIABLE_LENGTH,30],[`410`,13],[`411`,13],[`412`,13],[`413`,13],[`414`,13],[`420`,Ke.VARIABLE_LENGTH,20],[`421`,Ke.VARIABLE_LENGTH,15],[`422`,3],[`423`,Ke.VARIABLE_LENGTH,15],[`424`,3],[`425`,3],[`426`,3]],Ke.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH=[[`310`,6],[`311`,6],[`312`,6],[`313`,6],[`314`,6],[`315`,6],[`316`,6],[`320`,6],[`321`,6],[`322`,6],[`323`,6],[`324`,6],[`325`,6],[`326`,6],[`327`,6],[`328`,6],[`329`,6],[`330`,6],[`331`,6],[`332`,6],[`333`,6],[`334`,6],[`335`,6],[`336`,6],[`340`,6],[`341`,6],[`342`,6],[`343`,6],[`344`,6],[`345`,6],[`346`,6],[`347`,6],[`348`,6],[`349`,6],[`350`,6],[`351`,6],[`352`,6],[`353`,6],[`354`,6],[`355`,6],[`356`,6],[`357`,6],[`360`,6],[`361`,6],[`362`,6],[`363`,6],[`364`,6],[`365`,6],[`366`,6],[`367`,6],[`368`,6],[`369`,6],[`390`,Ke.VARIABLE_LENGTH,15],[`391`,Ke.VARIABLE_LENGTH,18],[`392`,Ke.VARIABLE_LENGTH,15],[`393`,Ke.VARIABLE_LENGTH,18],[`703`,Ke.VARIABLE_LENGTH,30]],Ke.FOUR_DIGIT_DATA_LENGTH=[[`7001`,13],[`7002`,Ke.VARIABLE_LENGTH,30],[`7003`,10],[`8001`,14],[`8002`,Ke.VARIABLE_LENGTH,20],[`8003`,Ke.VARIABLE_LENGTH,30],[`8004`,Ke.VARIABLE_LENGTH,30],[`8005`,6],[`8006`,18],[`8007`,Ke.VARIABLE_LENGTH,30],[`8008`,Ke.VARIABLE_LENGTH,12],[`8018`,18],[`8020`,Ke.VARIABLE_LENGTH,25],[`8100`,6],[`8101`,10],[`8102`,2],[`8110`,Ke.VARIABLE_LENGTH,70],[`8200`,Ke.VARIABLE_LENGTH,70]];class qe{constructor(e){this.buffer=new D,this.information=e}decodeAllCodes(e,t){let n=t,r=null;do{let t=this.decodeGeneralPurposeField(n,r),i=Ke.parseFieldsInGeneralPurpose(t.getNewString());if(i!=null&&e.append(i),r=t.isRemaining()?``+t.getRemainingValue():null,n===t.getNewPosition())break;n=t.getNewPosition()}while(!0);return e.toString()}isStillNumeric(e){if(e+7>this.information.getSize())return e+4<=this.information.getSize();for(let t=e;t<e+3;++t)if(this.information.get(t))return!0;return this.information.get(e+3)}decodeNumeric(e){if(e+7>this.information.getSize()){let t=this.extractNumericValueFromBitArray(e,4);return t===0?new Ge(this.information.getSize(),Ge.FNC1,Ge.FNC1):new Ge(this.information.getSize(),t-1,Ge.FNC1)}let t=this.extractNumericValueFromBitArray(e,7),n=(t-8)/11,r=(t-8)%11;return new Ge(e+7,n,r)}extractNumericValueFromBitArray(e,t){return qe.extractNumericValueFromBitArray(this.information,e,t)}static extractNumericValueFromBitArray(e,t,n){let r=0;for(let i=0;i<n;++i)e.get(t+i)&&(r|=1<<n-i-1);return r}decodeGeneralPurposeField(e,t){this.buffer.setLengthToZero(),t!=null&&this.buffer.append(t),this.current.setPosition(e);let n=this.parseBlocks();return n!=null&&n.isRemaining()?new We(this.current.getPosition(),this.buffer.toString(),n.getRemainingValue()):new We(this.current.getPosition(),this.buffer.toString())}parseBlocks(){let e,t;do{let n=this.current.getPosition();if(this.current.isAlpha()?(t=this.parseAlphaBlock(),e=t.isFinished()):this.current.isIsoIec646()?(t=this.parseIsoIec646Block(),e=t.isFinished()):(t=this.parseNumericBlock(),e=t.isFinished()),n===this.current.getPosition()&&!e)break}while(!e);return t.getDecodedInformation()}parseNumericBlock(){for(;this.isStillNumeric(this.current.getPosition());){let e=this.decodeNumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFirstDigitFNC1()){let t;return t=e.isSecondDigitFNC1()?new We(this.current.getPosition(),this.buffer.toString()):new We(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new Ve(!0,t)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1())return new Ve(!0,new We(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getSecondDigit())}return this.isNumericToAlphaNumericLatch(this.current.getPosition())&&(this.current.setAlpha(),this.current.incrementPosition(4)),new Ve(!1)}parseIsoIec646Block(){for(;this.isStillIsoIec646(this.current.getPosition());){let e=this.decodeIsoIec646(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1())return new Ve(!0,new We(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setAlpha()),new Ve(!1)}parseAlphaBlock(){for(;this.isStillAlpha(this.current.getPosition());){let e=this.decodeAlphanumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1())return new Ve(!0,new We(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setIsoIec646()),new Ve(!1)}isStillIsoIec646(e){if(e+5>this.information.getSize())return!1;let t=this.extractNumericValueFromBitArray(e,5);if(t>=5&&t<16)return!0;if(e+7>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<116)return!0;if(e+8>this.information.getSize())return!1;let r=this.extractNumericValueFromBitArray(e,8);return r>=232&&r<253}decodeIsoIec646(e){let t=this.extractNumericValueFromBitArray(e,5);if(t===15)return new Ue(e+5,Ue.FNC1);if(t>=5&&t<15)return new Ue(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<90)return new Ue(e+7,``+(n+1));if(n>=90&&n<116)return new Ue(e+7,``+(n+7));let r=this.extractNumericValueFromBitArray(e,8),i;switch(r){case 232:i=`!`;break;case 233:i=`"`;break;case 234:i=`%`;break;case 235:i=`&`;break;case 236:i=`'`;break;case 237:i=`(`;break;case 238:i=`)`;break;case 239:i=`*`;break;case 240:i=`+`;break;case 241:i=`,`;break;case 242:i=`-`;break;case 243:i=`.`;break;case 244:i=`/`;break;case 245:i=`:`;break;case 246:i=`;`;break;case 247:i=`<`;break;case 248:i=`=`;break;case 249:i=`>`;break;case 250:i=`?`;break;case 251:i=`_`;break;case 252:i=` `;break;default:throw new x}return new Ue(e+8,i)}isStillAlpha(e){if(e+5>this.information.getSize())return!1;let t=this.extractNumericValueFromBitArray(e,5);if(t>=5&&t<16)return!0;if(e+6>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,6);return n>=16&&n<63}decodeAlphanumeric(e){let t=this.extractNumericValueFromBitArray(e,5);if(t===15)return new Ue(e+5,Ue.FNC1);if(t>=5&&t<15)return new Ue(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,6);if(n>=32&&n<58)return new Ue(e+6,``+(n+33));let r;switch(n){case 58:r=`*`;break;case 59:r=`,`;break;case 60:r=`-`;break;case 61:r=`.`;break;case 62:r=`/`;break;default:throw new ce(`Decoding invalid alphanumeric value: `+n)}return new Ue(e+6,r)}isAlphaTo646ToAlphaLatch(e){if(e+1>this.information.getSize())return!1;for(let t=0;t<5&&t+e<this.information.getSize();++t)if(t===2){if(!this.information.get(e+2))return!1}else if(this.information.get(e+t))return!1;return!0}isAlphaOr646ToNumericLatch(e){if(e+3>this.information.getSize())return!1;for(let t=e;t<e+3;++t)if(this.information.get(t))return!1;return!0}isNumericToAlphaNumericLatch(e){if(e+1>this.information.getSize())return!1;for(let t=0;t<4&&t+e<this.information.getSize();++t)if(this.information.get(e+t))return!1;return!0}}class Je{constructor(e){this.information=e,this.generalDecoder=new qe(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class Ye extends Je{constructor(e){super(e)}encodeCompressedGtin(e,t){e.append(`(01)`);let n=e.length();e.append(`9`),this.encodeCompressedGtinWithoutAI(e,t,n)}encodeCompressedGtinWithoutAI(e,t,n){for(let n=0;n<4;++n){let r=this.getGeneralDecoder().extractNumericValueFromBitArray(t+10*n,10);r/100==0&&e.append(`0`),r/10==0&&e.append(`0`),e.append(r)}Ye.appendCheckDigit(e,n)}static appendCheckDigit(e,t){let n=0;for(let r=0;r<13;r++){let i=e.charAt(r+t).charCodeAt(0)-48;n+=r&1?i:3*i}n=10-n%10,n===10&&(n=0),e.append(n)}}Ye.GTIN_SIZE=40;class Xe extends Ye{constructor(e){super(e)}parseInformation(){let e=new D;e.append(`(01)`);let t=e.length(),n=this.getGeneralDecoder().extractNumericValueFromBitArray(Xe.HEADER_SIZE,4);return e.append(n),this.encodeCompressedGtinWithoutAI(e,Xe.HEADER_SIZE+4,t),this.getGeneralDecoder().decodeAllCodes(e,Xe.HEADER_SIZE+44)}}Xe.HEADER_SIZE=4;class Ze extends Je{constructor(e){super(e)}parseInformation(){let e=new D;return this.getGeneralDecoder().decodeAllCodes(e,Ze.HEADER_SIZE)}}Ze.HEADER_SIZE=5;class Qe extends Ye{constructor(e){super(e)}encodeCompressedWeight(e,t,n){let r=this.getGeneralDecoder().extractNumericValueFromBitArray(t,n);this.addWeightCode(e,r);let i=this.checkWeight(r),a=1e5;for(let t=0;t<5;++t)i/a===0&&e.append(`0`),a/=10;e.append(i)}}class $e extends Qe{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=$e.HEADER_SIZE+Qe.GTIN_SIZE+$e.WEIGHT_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,$e.HEADER_SIZE),this.encodeCompressedWeight(e,$e.HEADER_SIZE+Qe.GTIN_SIZE,$e.WEIGHT_SIZE),e.toString()}}$e.HEADER_SIZE=5,$e.WEIGHT_SIZE=15;class et extends $e{constructor(e){super(e)}addWeightCode(e,t){e.append(`(3103)`)}checkWeight(e){return e}}class tt extends $e{constructor(e){super(e)}addWeightCode(e,t){t<1e4?e.append(`(3202)`):e.append(`(3203)`)}checkWeight(e){return e<1e4?e:e-1e4}}class nt extends Ye{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<nt.HEADER_SIZE+Ye.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,nt.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(nt.HEADER_SIZE+Ye.GTIN_SIZE,nt.LAST_DIGIT_SIZE);e.append(`(392`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().decodeGeneralPurposeField(nt.HEADER_SIZE+Ye.GTIN_SIZE+nt.LAST_DIGIT_SIZE,null);return e.append(n.getNewString()),e.toString()}}nt.HEADER_SIZE=8,nt.LAST_DIGIT_SIZE=2;class rt extends Ye{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<rt.HEADER_SIZE+Ye.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,rt.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(rt.HEADER_SIZE+Ye.GTIN_SIZE,rt.LAST_DIGIT_SIZE);e.append(`(393`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(rt.HEADER_SIZE+Ye.GTIN_SIZE+rt.LAST_DIGIT_SIZE,rt.FIRST_THREE_DIGITS_SIZE);n/100==0&&e.append(`0`),n/10==0&&e.append(`0`),e.append(n);let r=this.getGeneralDecoder().decodeGeneralPurposeField(rt.HEADER_SIZE+Ye.GTIN_SIZE+rt.LAST_DIGIT_SIZE+rt.FIRST_THREE_DIGITS_SIZE,null);return e.append(r.getNewString()),e.toString()}}rt.HEADER_SIZE=8,rt.LAST_DIGIT_SIZE=2,rt.FIRST_THREE_DIGITS_SIZE=10;class it extends Qe{constructor(e,t,n){super(e),this.dateCode=n,this.firstAIdigits=t}parseInformation(){if(this.getInformation().getSize()!=it.HEADER_SIZE+it.GTIN_SIZE+it.WEIGHT_SIZE+it.DATE_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,it.HEADER_SIZE),this.encodeCompressedWeight(e,it.HEADER_SIZE+it.GTIN_SIZE,it.WEIGHT_SIZE),this.encodeCompressedDate(e,it.HEADER_SIZE+it.GTIN_SIZE+it.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,t){let n=this.getGeneralDecoder().extractNumericValueFromBitArray(t,it.DATE_SIZE);if(n==38400)return;e.append(`(`),e.append(this.dateCode),e.append(`)`);let r=n%32;n/=32;let i=n%12+1;n/=12;let a=n;a/10==0&&e.append(`0`),e.append(a),i/10==0&&e.append(`0`),e.append(i),r/10==0&&e.append(`0`),e.append(r)}addWeightCode(e,t){e.append(`(`),e.append(this.firstAIdigits),e.append(t/1e5),e.append(`)`)}checkWeight(e){return e%1e5}}it.HEADER_SIZE=8,it.WEIGHT_SIZE=20,it.DATE_SIZE=16;function at(e){try{if(e.get(1))return new Xe(e);if(!e.get(2))return new Ze(e);switch(qe.extractNumericValueFromBitArray(e,1,4)){case 4:return new et(e);case 5:return new tt(e)}switch(qe.extractNumericValueFromBitArray(e,1,5)){case 12:return new nt(e);case 13:return new rt(e)}switch(qe.extractNumericValueFromBitArray(e,1,7)){case 56:return new it(e,`310`,`11`);case 57:return new it(e,`320`,`11`);case 58:return new it(e,`310`,`13`);case 59:return new it(e,`320`,`13`);case 60:return new it(e,`310`,`15`);case 61:return new it(e,`320`,`15`);case 62:return new it(e,`310`,`17`);case 63:return new it(e,`320`,`17`)}}catch(t){throw console.log(t),new ce(`unknown decoder: `+e)}}class ot{constructor(e,t,n,r){this.leftchar=e,this.rightchar=t,this.finderpattern=n,this.maybeLast=r}mayBeLast(){return this.maybeLast}getLeftChar(){return this.leftchar}getRightChar(){return this.rightchar}getFinderPattern(){return this.finderpattern}mustBeLast(){return this.rightchar==null}toString(){return`[ `+this.leftchar+`, `+this.rightchar+` : `+(this.finderpattern==null?`null`:this.finderpattern.getValue())+` ]`}static equals(e,t){return e instanceof ot?ot.equalsOrNull(e.leftchar,t.leftchar)&&ot.equalsOrNull(e.rightchar,t.rightchar)&&ot.equalsOrNull(e.finderpattern,t.finderpattern):!1}static equalsOrNull(e,t){return e===null?t===null:ot.equals(e,t)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class st{constructor(e,t,n){this.pairs=e,this.rowNumber=t,this.wasReversed=n}getPairs(){return this.pairs}getRowNumber(){return this.rowNumber}isReversed(){return this.wasReversed}isEquivalent(e){return this.checkEqualitity(this,e)}toString(){return`{ `+this.pairs+` }`}equals(e,t){return e instanceof st?this.checkEqualitity(e,t)&&e.wasReversed===t.wasReversed:!1}checkEqualitity(e,t){if(!e||!t)return;let n;return e.forEach((e,r)=>{t.forEach(t=>{e.getLeftChar().getValue()===t.getLeftChar().getValue()&&e.getRightChar().getValue()===t.getRightChar().getValue()&&e.getFinderPatter().getValue()===t.getFinderPatter().getValue()&&(n=!0)})}),n}}class G extends Ie{constructor(e){super(...arguments),this.pairs=Array(G.MAX_PAIRS),this.rows=[],this.startEnd=[2],this.verbose=e===!0}decodeRow(e,t,n){this.pairs.length=0,this.startFromEven=!1;try{return G.constructResult(this.decodeRow2pairs(e,t))}catch(e){this.verbose&&console.log(e)}return this.pairs.length=0,this.startFromEven=!0,G.constructResult(this.decodeRow2pairs(e,t))}reset(){this.pairs.length=0,this.rows.length=0}decodeRow2pairs(e,t){let n=!1;for(;!n;)try{this.pairs.push(this.retrieveNextPair(t,this.pairs,e))}catch(e){if(e instanceof k){if(!this.pairs.length)throw new k;n=!0}}if(this.checkChecksum())return this.pairs;let r;if(r=!!this.rows.length,this.storeRow(e,!1),r){let e=this.checkRowsBoolean(!1);if(e!=null||(e=this.checkRowsBoolean(!0),e!=null))return e}throw new k}checkRowsBoolean(e){if(this.rows.length>25)return this.rows.length=0,null;this.pairs.length=0,e&&(this.rows=this.rows.reverse());let t=null;try{t=this.checkRows([],0)}catch(e){this.verbose&&console.log(e)}return e&&(this.rows=this.rows.reverse()),t}checkRows(e,t){for(let n=t;n<this.rows.length;n++){let t=this.rows[n];this.pairs.length=0;for(let t of e)this.pairs.push(t.getPairs());if(this.pairs.push(t.getPairs()),!G.isValidSequence(this.pairs))continue;if(this.checkChecksum())return this.pairs;let r=Array(e);r.push(t);try{return this.checkRows(r,n+1)}catch(e){this.verbose&&console.log(e)}}throw new k}static isValidSequence(e){for(let t of G.FINDER_PATTERN_SEQUENCES){if(e.length>t.length)continue;let n=!0;for(let r=0;r<e.length;r++)if(e[r].getFinderPattern().getValue()!=t[r]){n=!1;break}if(n)return!0}return!1}storeRow(e,t){let n=0,r=!1,i=!1;for(;n<this.rows.length;){let t=this.rows[n];if(t.getRowNumber()>e){i=t.isEquivalent(this.pairs);break}r=t.isEquivalent(this.pairs),n++}i||r||G.isPartialRow(this.pairs,this.rows)||(this.rows.push(n,new st(this.pairs,e,t)),this.removePartialRows(this.pairs,this.rows))}removePartialRows(e,t){for(let n of t)if(n.getPairs().length!==e.length){for(let t of n.getPairs())for(let n of e)if(ot.equals(t,n))break}}static isPartialRow(e,t){for(let n of t){let t=!0;for(let r of e){let e=!1;for(let t of n.getPairs())if(r.equals(t)){e=!0;break}if(!e){t=!1;break}}if(t)return!0}return!1}getRows(){return this.rows}static constructResult(e){let t=at(Be.buildBitArray(e)).parseInformation(),n=e[0].getFinderPattern().getResultPoints(),r=e[e.length-1].getFinderPattern().getResultPoints();return new R(t,null,null,[n[0],n[1],r[0],r[1]],z.RSS_EXPANDED,null)}checkChecksum(){let e=this.pairs.get(0),t=e.getLeftChar(),n=e.getRightChar();if(n==null)return!1;let r=n.getChecksumPortion(),i=2;for(let e=1;e<this.pairs.size();++e){let t=this.pairs.get(e);r+=t.getLeftChar().getChecksumPortion(),i++;let n=t.getRightChar();n!=null&&(r+=n.getChecksumPortion(),i++)}return r%=211,211*(i-4)+r==t.getValue()}static getNextSecondBar(e,t){let n;return e.get(t)?(n=e.getNextUnset(t),n=e.getNextSet(n)):(n=e.getNextSet(t),n=e.getNextUnset(n)),n}retrieveNextPair(e,t,n){let r=t.length%2==0;this.startFromEven&&(r=!r);let i,a=!0,o=-1;do this.findNextPair(e,t,o),i=this.parseFoundFinderPattern(e,n,r),i==null?o=G.getNextSecondBar(e,this.startEnd[0]):a=!1;while(a);let s=this.decodeDataCharacter(e,i,r,!0);if(!this.isEmptyPair(t)&&t[t.length-1].mustBeLast())throw new k;let c;try{c=this.decodeDataCharacter(e,i,r,!1)}catch(e){c=null,this.verbose&&console.log(e)}return new ot(s,c,i,!0)}isEmptyPair(e){return e.length===0}findNextPair(e,t,n){let r=this.getDecodeFinderCounters();r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a;a=n>=0?n:this.isEmptyPair(t)?0:t[t.length-1].getFinderPattern().getStartEnd()[1];let o=t.length%2!=0;this.startFromEven&&(o=!o);let s=!1;for(;a<i&&(s=!e.get(a),s);)a++;let c=0,l=a;for(let t=a;t<i;t++)if(e.get(t)!=s)r[c]++;else{if(c==3){if(o&&G.reverseCounters(r),G.isFinderPattern(r)){this.startEnd[0]=l,this.startEnd[1]=t;return}o&&G.reverseCounters(r),l+=r[0]+r[1],r[0]=r[2],r[1]=r[3],r[2]=0,r[3]=0,c--}else c++;r[c]=1,s=!s}throw new k}static reverseCounters(e){let t=e.length;for(let n=0;n<t/2;++n){let r=e[n];e[n]=e[t-n-1],e[t-n-1]=r}}parseFoundFinderPattern(e,t,n){let r,i,a;if(n){let t=this.startEnd[0]-1;for(;t>=0&&!e.get(t);)t--;t++,r=this.startEnd[0]-t,i=t,a=this.startEnd[1]}else i=this.startEnd[0],a=e.getNextUnset(this.startEnd[1]+1),r=a-this.startEnd[1];let o=this.getDecodeFinderCounters();p.arraycopy(o,0,o,1,o.length-1),o[0]=r;let s;try{s=this.parseFinderValue(o,G.FINDER_PATTERNS)}catch{return null}return new Re(s,[i,a],i,a,t)}decodeDataCharacter(e,t,n,r){let i=this.getDataCharacterCounters();for(let e=0;e<i.length;e++)i[e]=0;if(r)G.recordPatternInReverse(e,t.getStartEnd()[0],i);else{G.recordPattern(e,t.getStartEnd()[1],i);for(let e=0,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}let a=de.sum(new Int32Array(i))/17,o=(t.getStartEnd()[1]-t.getStartEnd()[0])/15;if(Math.abs(a-o)/o>.3)throw new k;let s=this.getOddCounts(),c=this.getEvenCounts(),l=this.getOddRoundingErrors(),u=this.getEvenRoundingErrors();for(let e=0;e<i.length;e++){let t=1*i[e]/a,n=t+.5;if(n<1){if(t<.3)throw new k;n=1}else if(n>8){if(t>8.7)throw new k;n=8}let r=e/2;e&1?(c[r]=n,u[r]=t-n):(s[r]=n,l[r]=t-n)}this.adjustOddEvenCounts(17);let d=4*t.getValue()+(n?0:2)+ +!r-1,f=0,p=0;for(let e=s.length-1;e>=0;e--){if(G.isNotA1left(t,n,r)){let t=G.WEIGHTS[d][2*e];p+=s[e]*t}f+=s[e]}let m=0;for(let e=c.length-1;e>=0;e--)if(G.isNotA1left(t,n,r)){let t=G.WEIGHTS[d][2*e+1];m+=c[e]*t}let h=p+m;if(f&1||f>13||f<4)throw new k;let g=(13-f)/2,_=G.SYMBOL_WIDEST[g],v=9-_,y=ze.getRSSvalue(s,_,!0),b=ze.getRSSvalue(c,v,!1),x=G.EVEN_TOTAL_SUBSET[g],S=G.GSUM[g];return new Le(y*x+b+S,h)}static isNotA1left(e,t,n){return!(e.getValue()==0&&t&&n)}adjustOddEvenCounts(e){let t=de.sum(new Int32Array(this.getOddCounts())),n=de.sum(new Int32Array(this.getEvenCounts())),r=!1,i=!1;t>13?i=!0:t<4&&(r=!0);let a=!1,o=!1;n>13?o=!0:n<4&&(a=!0);let s=t+n-e,c=(t&1)==1,l=(n&1)==0;if(s==1)if(c){if(l)throw new k;i=!0}else{if(!l)throw new k;o=!0}else if(s==-1)if(c){if(l)throw new k;r=!0}else{if(!l)throw new k;a=!0}else if(s==0){if(c){if(!l)throw new k;t<n?(r=!0,o=!0):(i=!0,a=!0)}else if(l)throw new k}else throw new k;if(r){if(i)throw new k;G.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(i&&G.decrement(this.getOddCounts(),this.getOddRoundingErrors()),a){if(o)throw new k;G.increment(this.getEvenCounts(),this.getOddRoundingErrors())}o&&G.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}G.SYMBOL_WIDEST=[7,5,4,3,1],G.EVEN_TOTAL_SUBSET=[4,20,52,104,204],G.GSUM=[0,348,1388,2948,3988],G.FINDER_PATTERNS=[Int32Array.from([1,8,4,1]),Int32Array.from([3,6,4,1]),Int32Array.from([3,4,6,1]),Int32Array.from([3,2,8,1]),Int32Array.from([2,6,5,1]),Int32Array.from([2,2,9,1])],G.WEIGHTS=[[1,3,9,27,81,32,96,77],[20,60,180,118,143,7,21,63],[189,145,13,39,117,140,209,205],[193,157,49,147,19,57,171,91],[62,186,136,197,169,85,44,132],[185,133,188,142,4,12,36,108],[113,128,173,97,80,29,87,50],[150,28,84,41,123,158,52,156],[46,138,203,187,139,206,196,166],[76,17,51,153,37,111,122,155],[43,129,176,106,107,110,119,146],[16,48,144,10,30,90,59,177],[109,116,137,200,178,112,125,164],[70,210,208,202,184,130,179,115],[134,191,151,31,93,68,204,190],[148,22,66,198,172,94,71,2],[6,18,54,162,64,192,154,40],[120,149,25,75,14,42,126,167],[79,26,78,23,69,207,199,175],[103,98,83,38,114,131,182,124],[161,61,183,127,170,88,53,159],[55,165,73,8,24,72,5,15],[45,135,194,160,58,174,100,89]],G.FINDER_PAT_A=0,G.FINDER_PAT_B=1,G.FINDER_PAT_C=2,G.FINDER_PAT_D=3,G.FINDER_PAT_E=4,G.FINDER_PAT_F=5,G.FINDER_PATTERN_SEQUENCES=[[G.FINDER_PAT_A,G.FINDER_PAT_A],[G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B],[G.FINDER_PAT_A,G.FINDER_PAT_C,G.FINDER_PAT_B,G.FINDER_PAT_D],[G.FINDER_PAT_A,G.FINDER_PAT_E,G.FINDER_PAT_B,G.FINDER_PAT_D,G.FINDER_PAT_C],[G.FINDER_PAT_A,G.FINDER_PAT_E,G.FINDER_PAT_B,G.FINDER_PAT_D,G.FINDER_PAT_D,G.FINDER_PAT_F],[G.FINDER_PAT_A,G.FINDER_PAT_E,G.FINDER_PAT_B,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_F,G.FINDER_PAT_F],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_D],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_E],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_F,G.FINDER_PAT_F],[G.FINDER_PAT_A,G.FINDER_PAT_A,G.FINDER_PAT_B,G.FINDER_PAT_B,G.FINDER_PAT_C,G.FINDER_PAT_D,G.FINDER_PAT_D,G.FINDER_PAT_E,G.FINDER_PAT_E,G.FINDER_PAT_F,G.FINDER_PAT_F]],G.MAX_PAIRS=11;class ct extends Le{constructor(e,t,n){super(e,t),this.count=0,this.finderPattern=n}getFinderPattern(){return this.finderPattern}getCount(){return this.count}incrementCount(){this.count++}}class lt extends Ie{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,t,n){let r=this.decodePair(t,!1,e,n);lt.addOrTally(this.possibleLeftPairs,r),t.reverse();let i=this.decodePair(t,!0,e,n);lt.addOrTally(this.possibleRightPairs,i),t.reverse();for(let e of this.possibleLeftPairs)if(e.getCount()>1){for(let t of this.possibleRightPairs)if(t.getCount()>1&&lt.checkChecksum(e,t))return lt.constructResult(e,t)}throw new k}static addOrTally(e,t){if(t==null)return;let n=!1;for(let r of e)if(r.getValue()===t.getValue()){r.incrementCount(),n=!0;break}n||e.push(t)}reset(){this.possibleLeftPairs.length=0,this.possibleRightPairs.length=0}static constructResult(e,t){let n=4537077*e.getValue()+t.getValue(),r=new String(n).toString(),i=new D;for(let e=13-r.length;e>0;e--)i.append(`0`);i.append(r);let a=0;for(let e=0;e<13;e++){let t=i.charAt(e).charCodeAt(0)-48;a+=e&1?t:3*t}a=10-a%10,a===10&&(a=0),i.append(a.toString());let o=e.getFinderPattern().getResultPoints(),s=t.getFinderPattern().getResultPoints();return new R(i.toString(),null,0,[o[0],o[1],s[0],s[1]],z.RSS_14,new Date().getTime())}static checkChecksum(e,t){let n=(e.getChecksumPortion()+16*t.getChecksumPortion())%79,r=9*e.getFinderPattern().getValue()+t.getFinderPattern().getValue();return r>72&&r--,r>8&&r--,n===r}decodePair(e,t,n,r){try{let i=this.findFinderPattern(e,t),a=this.parseFoundFinderPattern(e,n,t,i),o=r==null?null:r.get(b.NEED_RESULT_POINT_CALLBACK);if(o!=null){let r=(i[0]+i[1])/2;t&&(r=e.getSize()-1-r),o.foundPossibleResultPoint(new H(r,n))}let s=this.decodeDataCharacter(e,a,!0),c=this.decodeDataCharacter(e,a,!1);return new ct(1597*s.getValue()+c.getValue(),s.getChecksumPortion()+4*c.getChecksumPortion(),a)}catch{return null}}decodeDataCharacter(e,t,n){let r=this.getDataCharacterCounters();for(let e=0;e<r.length;e++)r[e]=0;if(n)Ce.recordPatternInReverse(e,t.getStartEnd()[0],r);else{Ce.recordPattern(e,t.getStartEnd()[1]+1,r);for(let e=0,t=r.length-1;e<t;e++,t--){let n=r[e];r[e]=r[t],r[t]=n}}let i=n?16:15,a=de.sum(new Int32Array(r))/i,o=this.getOddCounts(),s=this.getEvenCounts(),c=this.getOddRoundingErrors(),l=this.getEvenRoundingErrors();for(let e=0;e<r.length;e++){let t=r[e]/a,n=Math.floor(t+.5);n<1?n=1:n>8&&(n=8);let i=Math.floor(e/2);e&1?(s[i]=n,l[i]=t-n):(o[i]=n,c[i]=t-n)}this.adjustOddEvenCounts(n,i);let u=0,d=0;for(let e=o.length-1;e>=0;e--)d*=9,d+=o[e],u+=o[e];let f=0,p=0;for(let e=s.length-1;e>=0;e--)f*=9,f+=s[e],p+=s[e];let m=d+3*f;if(n){if(u&1||u>12||u<4)throw new k;let e=(12-u)/2,t=lt.OUTSIDE_ODD_WIDEST[e],n=9-t,r=ze.getRSSvalue(o,t,!1),i=ze.getRSSvalue(s,n,!0),a=lt.OUTSIDE_EVEN_TOTAL_SUBSET[e],c=lt.OUTSIDE_GSUM[e];return new Le(r*a+i+c,m)}else{if(p&1||p>10||p<4)throw new k;let e=(10-p)/2,t=lt.INSIDE_ODD_WIDEST[e],n=9-t,r=ze.getRSSvalue(o,t,!0),i=ze.getRSSvalue(s,n,!1),a=lt.INSIDE_ODD_TOTAL_SUBSET[e],c=lt.INSIDE_GSUM[e];return new Le(i*a+r+c,m)}}findFinderPattern(e,t){let n=this.getDecodeFinderCounters();n[0]=0,n[1]=0,n[2]=0,n[3]=0;let r=e.getSize(),i=!1,a=0;for(;a<r&&(i=!e.get(a),t!==i);)a++;let o=0,s=a;for(let t=a;t<r;t++)if(e.get(t)!==i)n[o]++;else{if(o===3){if(Ie.isFinderPattern(n))return[s,t];s+=n[0]+n[1],n[0]=n[2],n[1]=n[3],n[2]=0,n[3]=0,o--}else o++;n[o]=1,i=!i}throw new k}parseFoundFinderPattern(e,t,n,r){let i=e.get(r[0]),a=r[0]-1;for(;a>=0&&i!==e.get(a);)a--;a++;let o=r[0]-a,s=this.getDecodeFinderCounters(),c=new Int32Array(s.length);p.arraycopy(s,0,c,1,s.length-1),c[0]=o;let l=this.parseFinderValue(c,lt.FINDER_PATTERNS),u=a,d=r[1];return n&&(u=e.getSize()-1-u,d=e.getSize()-1-d),new Re(l,[a,r[1]],u,d,t)}adjustOddEvenCounts(e,t){let n=de.sum(new Int32Array(this.getOddCounts())),r=de.sum(new Int32Array(this.getEvenCounts())),i=!1,a=!1,o=!1,s=!1;e?(n>12?a=!0:n<4&&(i=!0),r>12?s=!0:r<4&&(o=!0)):(n>11?a=!0:n<5&&(i=!0),r>10?s=!0:r<4&&(o=!0));let c=n+r-t,l=(n&1)==+!!e,u=(r&1)==1;if(c===1)if(l){if(u)throw new k;a=!0}else{if(!u)throw new k;s=!0}else if(c===-1)if(l){if(u)throw new k;i=!0}else{if(!u)throw new k;o=!0}else if(c===0){if(l){if(!u)throw new k;n<r?(i=!0,s=!0):(a=!0,o=!0)}else if(u)throw new k}else throw new k;if(i){if(a)throw new k;Ie.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&Ie.decrement(this.getOddCounts(),this.getOddRoundingErrors()),o){if(s)throw new k;Ie.increment(this.getEvenCounts(),this.getOddRoundingErrors())}s&&Ie.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}lt.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],lt.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],lt.OUTSIDE_GSUM=[0,161,961,2015,2715],lt.INSIDE_GSUM=[0,336,1036,1516],lt.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],lt.INSIDE_ODD_WIDEST=[2,4,6,8],lt.FINDER_PATTERNS=[Int32Array.from([3,8,2,1]),Int32Array.from([3,5,5,1]),Int32Array.from([3,3,7,1]),Int32Array.from([3,1,9,1]),Int32Array.from([2,7,4,1]),Int32Array.from([2,5,6,1]),Int32Array.from([2,3,8,1]),Int32Array.from([1,5,7,1]),Int32Array.from([1,3,9,1])];class ut extends Ce{constructor(e,t){super(),this.readers=[],this.verbose=t===!0;let n=e?e.get(b.POSSIBLE_FORMATS):null,r=e&&e.get(b.ASSUME_CODE_39_CHECK_DIGIT)!==void 0;n?((n.includes(z.EAN_13)||n.includes(z.UPC_A)||n.includes(z.EAN_8)||n.includes(z.UPC_E))&&this.readers.push(new Fe(e)),n.includes(z.CODE_39)&&this.readers.push(new we(r)),n.includes(z.CODE_128)&&this.readers.push(new W),n.includes(z.ITF)&&this.readers.push(new Te),n.includes(z.RSS_14)&&this.readers.push(new lt),n.includes(z.RSS_EXPANDED)&&this.readers.push(new G(this.verbose))):(this.readers.push(new Fe(e)),this.readers.push(new we),this.readers.push(new Fe(e)),this.readers.push(new W),this.readers.push(new Te),this.readers.push(new lt),this.readers.push(new G(this.verbose)))}decodeRow(e,t,n){for(let r=0;r<this.readers.length;r++)try{return this.readers[r].decodeRow(e,t,n)}catch{}throw new k}reset(){this.readers.forEach(e=>e.reset())}}class dt extends L{constructor(e=500,t){super(new ut(t),e,t)}}class ft{constructor(e,t,n){this.ecCodewords=e,this.ecBlocks=[t],n&&this.ecBlocks.push(n)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class pt{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class mt{constructor(e,t,n,r,i,a){this.versionNumber=e,this.symbolSizeRows=t,this.symbolSizeColumns=n,this.dataRegionSizeRows=r,this.dataRegionSizeColumns=i,this.ecBlocks=a;let o=0,s=a.getECCodewords(),c=a.getECBlocks();for(let e of c)o+=e.getCount()*(e.getDataCodewords()+s);this.totalCodewords=o}getVersionNumber(){return this.versionNumber}getSymbolSizeRows(){return this.symbolSizeRows}getSymbolSizeColumns(){return this.symbolSizeColumns}getDataRegionSizeRows(){return this.dataRegionSizeRows}getDataRegionSizeColumns(){return this.dataRegionSizeColumns}getTotalCodewords(){return this.totalCodewords}getECBlocks(){return this.ecBlocks}static getVersionForDimensions(e,t){if(e&1||t&1)throw new x;for(let n of mt.VERSIONS)if(n.symbolSizeRows===e&&n.symbolSizeColumns===t)return n;throw new x}toString(){return``+this.versionNumber}static buildVersions(){return[new mt(1,10,10,8,8,new ft(5,new pt(1,3))),new mt(2,12,12,10,10,new ft(7,new pt(1,5))),new mt(3,14,14,12,12,new ft(10,new pt(1,8))),new mt(4,16,16,14,14,new ft(12,new pt(1,12))),new mt(5,18,18,16,16,new ft(14,new pt(1,18))),new mt(6,20,20,18,18,new ft(18,new pt(1,22))),new mt(7,22,22,20,20,new ft(20,new pt(1,30))),new mt(8,24,24,22,22,new ft(24,new pt(1,36))),new mt(9,26,26,24,24,new ft(28,new pt(1,44))),new mt(10,32,32,14,14,new ft(36,new pt(1,62))),new mt(11,36,36,16,16,new ft(42,new pt(1,86))),new mt(12,40,40,18,18,new ft(48,new pt(1,114))),new mt(13,44,44,20,20,new ft(56,new pt(1,144))),new mt(14,48,48,22,22,new ft(68,new pt(1,174))),new mt(15,52,52,24,24,new ft(42,new pt(2,102))),new mt(16,64,64,14,14,new ft(56,new pt(2,140))),new mt(17,72,72,16,16,new ft(36,new pt(4,92))),new mt(18,80,80,18,18,new ft(48,new pt(4,114))),new mt(19,88,88,20,20,new ft(56,new pt(4,144))),new mt(20,96,96,22,22,new ft(68,new pt(4,174))),new mt(21,104,104,24,24,new ft(56,new pt(6,136))),new mt(22,120,120,18,18,new ft(68,new pt(6,175))),new mt(23,132,132,20,20,new ft(62,new pt(8,163))),new mt(24,144,144,22,22,new ft(62,new pt(8,156),new pt(2,155))),new mt(25,8,18,6,16,new ft(7,new pt(1,5))),new mt(26,8,32,6,14,new ft(11,new pt(1,10))),new mt(27,12,26,10,24,new ft(14,new pt(1,16))),new mt(28,12,36,10,16,new ft(18,new pt(1,22))),new mt(29,16,36,14,16,new ft(24,new pt(1,32))),new mt(30,16,48,14,22,new ft(28,new pt(1,49)))]}}mt.VERSIONS=mt.buildVersions();class ht{constructor(e){let t=e.getHeight();if(t<8||t>144||t&1)throw new x;this.version=ht.readVersion(e),this.mappingBitMatrix=this.extractDataRegion(e),this.readMappingMatrix=new O(this.mappingBitMatrix.getWidth(),this.mappingBitMatrix.getHeight())}getVersion(){return this.version}static readVersion(e){let t=e.getHeight(),n=e.getWidth();return mt.getVersionForDimensions(t,n)}readCodewords(){let e=new Int8Array(this.version.getTotalCodewords()),t=0,n=4,r=0,i=this.mappingBitMatrix.getHeight(),a=this.mappingBitMatrix.getWidth(),o=!1,s=!1,c=!1,l=!1;do if(n===i&&r===0&&!o)e[t++]=this.readCorner1(i,a)&255,n-=2,r+=2,o=!0;else if(n===i-2&&r===0&&a&3&&!s)e[t++]=this.readCorner2(i,a)&255,n-=2,r+=2,s=!0;else if(n===i+4&&r===2&&!(a&7)&&!c)e[t++]=this.readCorner3(i,a)&255,n-=2,r+=2,c=!0;else if(n===i-2&&r===0&&(a&7)==4&&!l)e[t++]=this.readCorner4(i,a)&255,n-=2,r+=2,l=!0;else{do n<i&&r>=0&&!this.readMappingMatrix.get(r,n)&&(e[t++]=this.readUtah(n,r,i,a)&255),n-=2,r+=2;while(n>=0&&r<a);n+=1,r+=3;do n>=0&&r<a&&!this.readMappingMatrix.get(r,n)&&(e[t++]=this.readUtah(n,r,i,a)&255),n+=2,r-=2;while(n<i&&r>=0);n+=3,r+=1}while(n<i||r<a);if(t!==this.version.getTotalCodewords())throw new x;return e}readModule(e,t,n,r){return e<0&&(e+=n,t+=4-(n+4&7)),t<0&&(t+=r,e+=4-(r+4&7)),this.readMappingMatrix.set(t,e),this.mappingBitMatrix.get(t,e)}readUtah(e,t,n,r){let i=0;return this.readModule(e-2,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e-2,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t,n,r)&&(i|=1),i<<=1,this.readModule(e,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e,t,n,r)&&(i|=1),i}readCorner1(e,t){let n=0;return this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,1,e,t)&&(n|=1),n<<=1,this.readModule(e-1,2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(2,t-1,e,t)&&(n|=1),n<<=1,this.readModule(3,t-1,e,t)&&(n|=1),n}readCorner2(e,t){let n=0;return this.readModule(e-3,0,e,t)&&(n|=1),n<<=1,this.readModule(e-2,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(0,t-4,e,t)&&(n|=1),n<<=1,this.readModule(0,t-3,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n}readCorner3(e,t){let n=0;return this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(0,t-3,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-3,e,t)&&(n|=1),n<<=1,this.readModule(1,t-2,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n}readCorner4(e,t){let n=0;return this.readModule(e-3,0,e,t)&&(n|=1),n<<=1,this.readModule(e-2,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(2,t-1,e,t)&&(n|=1),n<<=1,this.readModule(3,t-1,e,t)&&(n|=1),n}extractDataRegion(e){let t=this.version.getSymbolSizeRows(),n=this.version.getSymbolSizeColumns();if(e.getHeight()!==t)throw new l(`Dimension of bitMatrix must match the version size`);let r=this.version.getDataRegionSizeRows(),i=this.version.getDataRegionSizeColumns(),a=t/r|0,o=n/i|0,s=a*r,c=new O(o*i,s);for(let t=0;t<a;++t){let n=t*r;for(let a=0;a<o;++a){let o=a*i;for(let s=0;s<r;++s){let l=t*(r+2)+1+s,u=n+s;for(let t=0;t<i;++t){let n=a*(i+2)+1+t;if(e.get(n,l)){let e=o+t;c.set(e,u)}}}}}return c}}class gt{constructor(e,t){this.numDataCodewords=e,this.codewords=t}static getDataBlocks(e,t){let n=t.getECBlocks(),r=0,i=n.getECBlocks();for(let e of i)r+=e.getCount();let a=Array(r),o=0;for(let e of i)for(let t=0;t<e.getCount();t++){let t=e.getDataCodewords(),r=n.getECCodewords()+t;a[o++]=new gt(t,new Uint8Array(r))}let s=a[0].codewords.length-n.getECCodewords(),c=s-1,u=0;for(let t=0;t<c;t++)for(let n=0;n<o;n++)a[n].codewords[t]=e[u++];let d=t.getVersionNumber()===24,f=d?8:o;for(let t=0;t<f;t++)a[t].codewords[s-1]=e[u++];let p=a[0].codewords.length;for(let t=s;t<p;t++)for(let n=0;n<o;n++){let r=d?(n+8)%o:n,i=d&&r>7?t-1:t;a[r].codewords[i]=e[u++]}if(u!==e.length)throw new l;return a}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}class _t{constructor(e){this.bytes=e,this.byteOffset=0,this.bitOffset=0}getBitOffset(){return this.bitOffset}getByteOffset(){return this.byteOffset}readBits(e){if(e<1||e>32||e>this.available())throw new l(``+e);let t=0,n=this.bitOffset,r=this.byteOffset,i=this.bytes;if(n>0){let a=8-n,o=e<a?e:a,s=a-o,c=255>>8-o<<s;t=(i[r]&c)>>s,e-=o,n+=o,n===8&&(n=0,r++)}if(e>0){for(;e>=8;)t=t<<8|i[r]&255,r++,e-=8;if(e>0){let a=8-e,o=255>>a<<a;t=t<<e|(i[r]&o)>>a,n+=e}}return this.bitOffset=n,this.byteOffset=r,t}available(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset}}var vt;(function(e){e[e.PAD_ENCODE=0]=`PAD_ENCODE`,e[e.ASCII_ENCODE=1]=`ASCII_ENCODE`,e[e.C40_ENCODE=2]=`C40_ENCODE`,e[e.TEXT_ENCODE=3]=`TEXT_ENCODE`,e[e.ANSIX12_ENCODE=4]=`ANSIX12_ENCODE`,e[e.EDIFACT_ENCODE=5]=`EDIFACT_ENCODE`,e[e.BASE256_ENCODE=6]=`BASE256_ENCODE`})(vt||={});class yt{static decode(e){let t=new _t(e),n=new D,r=new D,i=[],a=vt.ASCII_ENCODE;do if(a===vt.ASCII_ENCODE)a=this.decodeAsciiSegment(t,n,r);else{switch(a){case vt.C40_ENCODE:this.decodeC40Segment(t,n);break;case vt.TEXT_ENCODE:this.decodeTextSegment(t,n);break;case vt.ANSIX12_ENCODE:this.decodeAnsiX12Segment(t,n);break;case vt.EDIFACT_ENCODE:this.decodeEdifactSegment(t,n);break;case vt.BASE256_ENCODE:this.decodeBase256Segment(t,n,i);break;default:throw new x}a=vt.ASCII_ENCODE}while(a!==vt.PAD_ENCODE&&t.available()>0);return r.length()>0&&n.append(r.toString()),new re(e,n.toString(),i.length===0?null:i,null)}static decodeAsciiSegment(e,t,n){let r=!1;do{let i=e.readBits(8);if(i===0)throw new x;if(i<=128)return r&&(i+=128),t.append(String.fromCharCode(i-1)),vt.ASCII_ENCODE;if(i===129)return vt.PAD_ENCODE;if(i<=229){let e=i-130;e<10&&t.append(`0`),t.append(``+e)}else switch(i){case 230:return vt.C40_ENCODE;case 231:return vt.BASE256_ENCODE;case 232:t.append(``);break;case 233:case 234:break;case 235:r=!0;break;case 236:t.append(`[)>05`),n.insert(0,``);break;case 237:t.append(`[)>06`),n.insert(0,``);break;case 238:return vt.ANSIX12_ENCODE;case 239:return vt.TEXT_ENCODE;case 240:return vt.EDIFACT_ENCODE;case 241:break;default:if(i!==254||e.available()!==0)throw new x;break}}while(e.available()>0);return vt.ASCII_ENCODE}static decodeC40Segment(e,t){let n=!1,r=[],i=0;do{if(e.available()===8)return;let a=e.readBits(8);if(a===254)return;this.parseTwoBytes(a,e.readBits(8),r);for(let e=0;e<3;e++){let a=r[e];switch(i){case 0:if(a<3)i=a+1;else if(a<this.C40_BASIC_SET_CHARS.length){let e=this.C40_BASIC_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else throw new x;break;case 1:n?(t.append(String.fromCharCode(a+128)),n=!1):t.append(String.fromCharCode(a)),i=0;break;case 2:if(a<this.C40_SHIFT2_SET_CHARS.length){let e=this.C40_SHIFT2_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else switch(a){case 27:t.append(``);break;case 30:n=!0;break;default:throw new x}i=0;break;case 3:n?(t.append(String.fromCharCode(a+224)),n=!1):t.append(String.fromCharCode(a+96)),i=0;break;default:throw new x}}}while(e.available()>0)}static decodeTextSegment(e,t){let n=!1,r=[],i=0;do{if(e.available()===8)return;let a=e.readBits(8);if(a===254)return;this.parseTwoBytes(a,e.readBits(8),r);for(let e=0;e<3;e++){let a=r[e];switch(i){case 0:if(a<3)i=a+1;else if(a<this.TEXT_BASIC_SET_CHARS.length){let e=this.TEXT_BASIC_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else throw new x;break;case 1:n?(t.append(String.fromCharCode(a+128)),n=!1):t.append(String.fromCharCode(a)),i=0;break;case 2:if(a<this.TEXT_SHIFT2_SET_CHARS.length){let e=this.TEXT_SHIFT2_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else switch(a){case 27:t.append(``);break;case 30:n=!0;break;default:throw new x}i=0;break;case 3:if(a<this.TEXT_SHIFT3_SET_CHARS.length){let e=this.TEXT_SHIFT3_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e),i=0}else throw new x;break;default:throw new x}}}while(e.available()>0)}static decodeAnsiX12Segment(e,t){let n=[];do{if(e.available()===8)return;let r=e.readBits(8);if(r===254)return;this.parseTwoBytes(r,e.readBits(8),n);for(let e=0;e<3;e++){let r=n[e];switch(r){case 0:t.append(`\r`);break;case 1:t.append(`*`);break;case 2:t.append(`>`);break;case 3:t.append(` `);break;default:if(r<14)t.append(String.fromCharCode(r+44));else if(r<40)t.append(String.fromCharCode(r+51));else throw new x;break}}}while(e.available()>0)}static parseTwoBytes(e,t,n){let r=(e<<8)+t-1,i=Math.floor(r/1600);n[0]=i,r-=i*1600,i=Math.floor(r/40),n[1]=i,n[2]=r-i*40}static decodeEdifactSegment(e,t){do{if(e.available()<=16)return;for(let n=0;n<4;n++){let n=e.readBits(6);if(n===31){let t=8-e.getBitOffset();t!==8&&e.readBits(t);return}n&32||(n|=64),t.append(String.fromCharCode(n))}}while(e.available()>0)}static decodeBase256Segment(e,t,n){let r=1+e.getByteOffset(),i=this.unrandomize255State(e.readBits(8),r++),a;if(a=i===0?e.available()/8|0:i<250?i:250*(i-249)+this.unrandomize255State(e.readBits(8),r++),a<0)throw new x;let o=new Uint8Array(a);for(let t=0;t<a;t++){if(e.available()<8)throw new x;o[t]=this.unrandomize255State(e.readBits(8),r++)}n.push(o);try{t.append(T.decode(o,E.ISO88591))}catch(e){throw new ce(`Platform does not support required encoding: `+e.message)}}static unrandomize255State(e,t){let n=e-(149*t%255+1);return n>=0?n:n+256}}yt.C40_BASIC_SET_CHARS=`*** 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``),yt.C40_SHIFT2_SET_CHARS=`!"#$%&'()*+,-./:;<=>?@[\\]^_`.split(``),yt.TEXT_BASIC_SET_CHARS=`*** 0123456789abcdefghijklmnopqrstuvwxyz`.split(``),yt.TEXT_SHIFT2_SET_CHARS=yt.C40_SHIFT2_SET_CHARS,yt.TEXT_SHIFT3_SET_CHARS="`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~".split(``);class bt{constructor(){this.rsDecoder=new V(oe.DATA_MATRIX_FIELD_256)}decode(e){let t=new ht(e),n=t.getVersion(),r=t.readCodewords(),i=gt.getDataBlocks(r,n),a=0;for(let e of i)a+=e.getNumDataCodewords();let o=new Uint8Array(a),s=i.length;for(let e=0;e<s;e++){let t=i[e],n=t.getCodewords(),r=t.getNumDataCodewords();this.correctErrors(n,r);for(let t=0;t<r;t++)o[t*s+e]=n[t]}return yt.decode(o)}correctErrors(e,t){let n=new Int32Array(e);try{this.rsDecoder.decode(n,e.length-t)}catch{throw new d}for(let r=0;r<t;r++)e[r]=n[r]}}class xt{constructor(e){this.image=e,this.rectangleDetector=new he(this.image)}detect(){let e=this.rectangleDetector.detect(),t=this.detectSolid1(e);if(t=this.detectSolid2(t),t[3]=this.correctTopRight(t),!t[3])throw new k;t=this.shiftToModuleCenter(t);let n=t[0],r=t[1],i=t[2],a=t[3],o=this.transitionsBetween(n,a)+1,s=this.transitionsBetween(i,a)+1;return(o&1)==1&&(o+=1),(s&1)==1&&(s+=1),4*o<7*s&&4*s<7*o&&(o=s=Math.max(o,s)),new pe(xt.sampleGrid(this.image,n,r,i,a,o,s),[n,r,i,a])}static shiftPoint(e,t,n){let r=(t.getX()-e.getX())/(n+1),i=(t.getY()-e.getY())/(n+1);return new H(e.getX()+r,e.getY()+i)}static moveAway(e,t,n){let r=e.getX(),i=e.getY();return r<t?--r:r+=1,i<n?--i:i+=1,new H(r,i)}detectSolid1(e){let t=e[0],n=e[1],r=e[3],i=e[2],a=this.transitionsBetween(t,n),o=this.transitionsBetween(n,r),s=this.transitionsBetween(r,i),c=this.transitionsBetween(i,t),l=a,u=[i,t,n,r];return l>o&&(l=o,u[0]=t,u[1]=n,u[2]=r,u[3]=i),l>s&&(l=s,u[0]=n,u[1]=r,u[2]=i,u[3]=t),l>c&&(u[0]=r,u[1]=i,u[2]=t,u[3]=n),u}detectSolid2(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i),o=xt.shiftPoint(n,r,(a+1)*4),s=xt.shiftPoint(r,n,(a+1)*4);return this.transitionsBetween(o,t)<this.transitionsBetween(s,i)?(e[0]=t,e[1]=n,e[2]=r,e[3]=i):(e[0]=n,e[1]=r,e[2]=i,e[3]=t),e}correctTopRight(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i),o=this.transitionsBetween(n,i),s=xt.shiftPoint(t,n,(o+1)*4),c=xt.shiftPoint(r,n,(a+1)*4);a=this.transitionsBetween(s,i),o=this.transitionsBetween(c,i);let l=new H(i.getX()+(r.getX()-n.getX())/(a+1),i.getY()+(r.getY()-n.getY())/(a+1)),u=new H(i.getX()+(t.getX()-n.getX())/(o+1),i.getY()+(t.getY()-n.getY())/(o+1));return this.isValid(l)?!this.isValid(u)||this.transitionsBetween(s,l)+this.transitionsBetween(c,l)>this.transitionsBetween(s,u)+this.transitionsBetween(c,u)?l:u:this.isValid(u)?u:null}shiftToModuleCenter(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i)+1,o=this.transitionsBetween(r,i)+1,s=xt.shiftPoint(t,n,o*4),c=xt.shiftPoint(r,n,a*4);a=this.transitionsBetween(s,i)+1,o=this.transitionsBetween(c,i)+1,(a&1)==1&&(a+=1),(o&1)==1&&(o+=1);let l=(t.getX()+n.getX()+r.getX()+i.getX())/4,u=(t.getY()+n.getY()+r.getY()+i.getY())/4;t=xt.moveAway(t,l,u),n=xt.moveAway(n,l,u),r=xt.moveAway(r,l,u),i=xt.moveAway(i,l,u);let d,f;return s=xt.shiftPoint(t,n,o*4),s=xt.shiftPoint(s,i,a*4),d=xt.shiftPoint(n,t,o*4),d=xt.shiftPoint(d,r,a*4),c=xt.shiftPoint(r,i,o*4),c=xt.shiftPoint(c,n,a*4),f=xt.shiftPoint(i,r,o*4),f=xt.shiftPoint(f,t,a*4),[s,d,c,f]}isValid(e){return e.getX()>=0&&e.getX()<this.image.getWidth()&&e.getY()>0&&e.getY()<this.image.getHeight()}static sampleGrid(e,t,n,r,i,a,o){return ve.getInstance().sampleGrid(e,a,o,.5,.5,a-.5,.5,a-.5,o-.5,.5,o-.5,t.getX(),t.getY(),i.getX(),i.getY(),r.getX(),r.getY(),n.getX(),n.getY())}transitionsBetween(e,t){let n=Math.trunc(e.getX()),r=Math.trunc(e.getY()),i=Math.trunc(t.getX()),a=Math.trunc(t.getY()),o=Math.abs(a-r)>Math.abs(i-n);if(o){let e=n;n=r,r=e,e=i,i=a,a=e}let s=Math.abs(i-n),c=Math.abs(a-r),l=-s/2,u=r<a?1:-1,d=n<i?1:-1,f=0,p=this.image.get(o?r:n,o?n:r);for(let e=n,t=r;e!==i;e+=d){let n=this.image.get(o?t:e,o?e:t);if(n!==p&&(f++,p=n),l+=c,l>0){if(t===a)break;t+=u,l-=s}}return f}}class St{constructor(){this.decoder=new bt}decode(e,t=null){let n,r;if(t!=null&&t.has(b.PURE_BARCODE)){let t=St.extractPureBits(e.getBlackMatrix());n=this.decoder.decode(t),r=St.NO_POINTS}else{let t=new xt(e.getBlackMatrix()).detect();n=this.decoder.decode(t.getBits()),r=t.getPoints()}let i=n.getRawBytes(),a=new R(n.getText(),i,8*i.length,r,z.DATA_MATRIX,p.currentTimeMillis()),o=n.getByteSegments();o!=null&&a.putMetadata(ne.BYTE_SEGMENTS,o);let s=n.getECLevel();return s!=null&&a.putMetadata(ne.ERROR_CORRECTION_LEVEL,s),a}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t==null||n==null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=(n[0]-o+1)/r,c=(a-i+1)/r;if(s<=0||c<=0)throw new k;let l=r/2;i+=l,o+=l;let u=new O(s,c);for(let t=0;t<c;t++){let n=i+t*r;for(let i=0;i<s;i++)e.get(o+i*r,n)&&u.set(i,t)}return u}static moduleSize(e,t){let n=t.getWidth(),r=e[0],i=e[1];for(;r<n&&t.get(r,i);)r++;if(r===n)throw new k;let a=r-e[0];if(a===0)throw new k;return a}}St.NO_POINTS=[];class Ct extends L{constructor(e=500){super(new St,e)}}var wt;(function(e){e[e.L=0]=`L`,e[e.M=1]=`M`,e[e.Q=2]=`Q`,e[e.H=3]=`H`})(wt||={});class Tt{constructor(e,t,n){this.value=e,this.stringValue=t,this.bits=n,Tt.FOR_BITS.set(n,this),Tt.FOR_VALUE.set(e,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(e){switch(e){case`L`:return Tt.L;case`M`:return Tt.M;case`Q`:return Tt.Q;case`H`:return Tt.H;default:throw new c(e+`not available`)}}toString(){return this.stringValue}equals(e){if(!(e instanceof Tt))return!1;let t=e;return this.value===t.value}static forBits(e){if(e<0||e>=Tt.FOR_BITS.size)throw new l;return Tt.FOR_BITS.get(e)}}Tt.FOR_BITS=new Map,Tt.FOR_VALUE=new Map,Tt.L=new Tt(wt.L,`L`,1),Tt.M=new Tt(wt.M,`M`,0),Tt.Q=new Tt(wt.Q,`Q`,3),Tt.H=new Tt(wt.H,`H`,2);class Et{constructor(e){this.errorCorrectionLevel=Tt.forBits(e>>3&3),this.dataMask=e&7}static numBitsDiffering(e,t){return _.bitCount(e^t)}static decodeFormatInformation(e,t){let n=Et.doDecodeFormatInformation(e,t);return n===null?Et.doDecodeFormatInformation(e^Et.FORMAT_INFO_MASK_QR,t^Et.FORMAT_INFO_MASK_QR):n}static doDecodeFormatInformation(e,t){let n=2**53-1,r=0;for(let i of Et.FORMAT_INFO_DECODE_LOOKUP){let a=i[0];if(a===e||a===t)return new Et(i[1]);let o=Et.numBitsDiffering(e,a);o<n&&(r=i[1],n=o),e!==t&&(o=Et.numBitsDiffering(t,a),o<n&&(r=i[1],n=o))}return n<=3?new Et(r):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(e){if(!(e instanceof Et))return!1;let t=e;return this.errorCorrectionLevel===t.errorCorrectionLevel&&this.dataMask===t.dataMask}}Et.FORMAT_INFO_MASK_QR=21522,Et.FORMAT_INFO_DECODE_LOOKUP=[Int32Array.from([21522,0]),Int32Array.from([20773,1]),Int32Array.from([24188,2]),Int32Array.from([23371,3]),Int32Array.from([17913,4]),Int32Array.from([16590,5]),Int32Array.from([20375,6]),Int32Array.from([19104,7]),Int32Array.from([30660,8]),Int32Array.from([29427,9]),Int32Array.from([32170,10]),Int32Array.from([30877,11]),Int32Array.from([26159,12]),Int32Array.from([25368,13]),Int32Array.from([27713,14]),Int32Array.from([26998,15]),Int32Array.from([5769,16]),Int32Array.from([5054,17]),Int32Array.from([7399,18]),Int32Array.from([6608,19]),Int32Array.from([1890,20]),Int32Array.from([597,21]),Int32Array.from([3340,22]),Int32Array.from([2107,23]),Int32Array.from([13663,24]),Int32Array.from([12392,25]),Int32Array.from([16177,26]),Int32Array.from([14854,27]),Int32Array.from([9396,28]),Int32Array.from([8579,29]),Int32Array.from([11994,30]),Int32Array.from([11245,31])];class K{constructor(e,...t){this.ecCodewordsPerBlock=e,this.ecBlocks=t}getECCodewordsPerBlock(){return this.ecCodewordsPerBlock}getNumBlocks(){let e=0,t=this.ecBlocks;for(let n of t)e+=n.getCount();return e}getTotalECCodewords(){return this.ecCodewordsPerBlock*this.getNumBlocks()}getECBlocks(){return this.ecBlocks}}class q{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class Dt{constructor(e,t,...n){this.versionNumber=e,this.alignmentPatternCenters=t,this.ecBlocks=n;let r=0,i=n[0].getECCodewordsPerBlock(),a=n[0].getECBlocks();for(let e of a)r+=e.getCount()*(e.getDataCodewords()+i);this.totalCodewords=r}getVersionNumber(){return this.versionNumber}getAlignmentPatternCenters(){return this.alignmentPatternCenters}getTotalCodewords(){return this.totalCodewords}getDimensionForVersion(){return 17+4*this.versionNumber}getECBlocksForLevel(e){return this.ecBlocks[e.getValue()]}static getProvisionalVersionForDimension(e){if(e%4!=1)throw new x;try{return this.getVersionForNumber((e-17)/4)}catch{throw new x}}static getVersionForNumber(e){if(e<1||e>40)throw new l;return Dt.VERSIONS[e-1]}static decodeVersionInformation(e){let t=2**53-1,n=0;for(let r=0;r<Dt.VERSION_DECODE_INFO.length;r++){let i=Dt.VERSION_DECODE_INFO[r];if(i===e)return Dt.getVersionForNumber(r+7);let a=Et.numBitsDiffering(e,i);a<t&&(n=r+7,t=a)}return t<=3?Dt.getVersionForNumber(n):null}buildFunctionPattern(){let e=this.getDimensionForVersion(),t=new O(e);t.setRegion(0,0,9,9),t.setRegion(e-8,0,8,9),t.setRegion(0,e-8,9,8);let n=this.alignmentPatternCenters.length;for(let e=0;e<n;e++){let r=this.alignmentPatternCenters[e]-2;for(let i=0;i<n;i++)e===0&&(i===0||i===n-1)||e===n-1&&i===0||t.setRegion(this.alignmentPatternCenters[i]-2,r,5,5)}return t.setRegion(6,9,1,e-17),t.setRegion(9,6,e-17,1),this.versionNumber>6&&(t.setRegion(e-11,0,3,6),t.setRegion(0,e-11,6,3)),t}toString(){return``+this.versionNumber}}Dt.VERSION_DECODE_INFO=Int32Array.from([31892,34236,39577,42195,48118,51042,55367,58893,63784,68472,70749,76311,79154,84390,87683,92361,96236,102084,102881,110507,110734,117786,119615,126325,127568,133589,136944,141498,145311,150283,152622,158308,161089,167017]),Dt.VERSIONS=[new Dt(1,new Int32Array,new K(7,new q(1,19)),new K(10,new q(1,16)),new K(13,new q(1,13)),new K(17,new q(1,9))),new Dt(2,Int32Array.from([6,18]),new K(10,new q(1,34)),new K(16,new q(1,28)),new K(22,new q(1,22)),new K(28,new q(1,16))),new Dt(3,Int32Array.from([6,22]),new K(15,new q(1,55)),new K(26,new q(1,44)),new K(18,new q(2,17)),new K(22,new q(2,13))),new Dt(4,Int32Array.from([6,26]),new K(20,new q(1,80)),new K(18,new q(2,32)),new K(26,new q(2,24)),new K(16,new q(4,9))),new Dt(5,Int32Array.from([6,30]),new K(26,new q(1,108)),new K(24,new q(2,43)),new K(18,new q(2,15),new q(2,16)),new K(22,new q(2,11),new q(2,12))),new Dt(6,Int32Array.from([6,34]),new K(18,new q(2,68)),new K(16,new q(4,27)),new K(24,new q(4,19)),new K(28,new q(4,15))),new Dt(7,Int32Array.from([6,22,38]),new K(20,new q(2,78)),new K(18,new q(4,31)),new K(18,new q(2,14),new q(4,15)),new K(26,new q(4,13),new q(1,14))),new Dt(8,Int32Array.from([6,24,42]),new K(24,new q(2,97)),new K(22,new q(2,38),new q(2,39)),new K(22,new q(4,18),new q(2,19)),new K(26,new q(4,14),new q(2,15))),new Dt(9,Int32Array.from([6,26,46]),new K(30,new q(2,116)),new K(22,new q(3,36),new q(2,37)),new K(20,new q(4,16),new q(4,17)),new K(24,new q(4,12),new q(4,13))),new Dt(10,Int32Array.from([6,28,50]),new K(18,new q(2,68),new q(2,69)),new K(26,new q(4,43),new q(1,44)),new K(24,new q(6,19),new q(2,20)),new K(28,new q(6,15),new q(2,16))),new Dt(11,Int32Array.from([6,30,54]),new K(20,new q(4,81)),new K(30,new q(1,50),new q(4,51)),new K(28,new q(4,22),new q(4,23)),new K(24,new q(3,12),new q(8,13))),new Dt(12,Int32Array.from([6,32,58]),new K(24,new q(2,92),new q(2,93)),new K(22,new q(6,36),new q(2,37)),new K(26,new q(4,20),new q(6,21)),new K(28,new q(7,14),new q(4,15))),new Dt(13,Int32Array.from([6,34,62]),new K(26,new q(4,107)),new K(22,new q(8,37),new q(1,38)),new K(24,new q(8,20),new q(4,21)),new K(22,new q(12,11),new q(4,12))),new Dt(14,Int32Array.from([6,26,46,66]),new K(30,new q(3,115),new q(1,116)),new K(24,new q(4,40),new q(5,41)),new K(20,new q(11,16),new q(5,17)),new K(24,new q(11,12),new q(5,13))),new Dt(15,Int32Array.from([6,26,48,70]),new K(22,new q(5,87),new q(1,88)),new K(24,new q(5,41),new q(5,42)),new K(30,new q(5,24),new q(7,25)),new K(24,new q(11,12),new q(7,13))),new Dt(16,Int32Array.from([6,26,50,74]),new K(24,new q(5,98),new q(1,99)),new K(28,new q(7,45),new q(3,46)),new K(24,new q(15,19),new q(2,20)),new K(30,new q(3,15),new q(13,16))),new Dt(17,Int32Array.from([6,30,54,78]),new K(28,new q(1,107),new q(5,108)),new K(28,new q(10,46),new q(1,47)),new K(28,new q(1,22),new q(15,23)),new K(28,new q(2,14),new q(17,15))),new Dt(18,Int32Array.from([6,30,56,82]),new K(30,new q(5,120),new q(1,121)),new K(26,new q(9,43),new q(4,44)),new K(28,new q(17,22),new q(1,23)),new K(28,new q(2,14),new q(19,15))),new Dt(19,Int32Array.from([6,30,58,86]),new K(28,new q(3,113),new q(4,114)),new K(26,new q(3,44),new q(11,45)),new K(26,new q(17,21),new q(4,22)),new K(26,new q(9,13),new q(16,14))),new Dt(20,Int32Array.from([6,34,62,90]),new K(28,new q(3,107),new q(5,108)),new K(26,new q(3,41),new q(13,42)),new K(30,new q(15,24),new q(5,25)),new K(28,new q(15,15),new q(10,16))),new Dt(21,Int32Array.from([6,28,50,72,94]),new K(28,new q(4,116),new q(4,117)),new K(26,new q(17,42)),new K(28,new q(17,22),new q(6,23)),new K(30,new q(19,16),new q(6,17))),new Dt(22,Int32Array.from([6,26,50,74,98]),new K(28,new q(2,111),new q(7,112)),new K(28,new q(17,46)),new K(30,new q(7,24),new q(16,25)),new K(24,new q(34,13))),new Dt(23,Int32Array.from([6,30,54,78,102]),new K(30,new q(4,121),new q(5,122)),new K(28,new q(4,47),new q(14,48)),new K(30,new q(11,24),new q(14,25)),new K(30,new q(16,15),new q(14,16))),new Dt(24,Int32Array.from([6,28,54,80,106]),new K(30,new q(6,117),new q(4,118)),new K(28,new q(6,45),new q(14,46)),new K(30,new q(11,24),new q(16,25)),new K(30,new q(30,16),new q(2,17))),new Dt(25,Int32Array.from([6,32,58,84,110]),new K(26,new q(8,106),new q(4,107)),new K(28,new q(8,47),new q(13,48)),new K(30,new q(7,24),new q(22,25)),new K(30,new q(22,15),new q(13,16))),new Dt(26,Int32Array.from([6,30,58,86,114]),new K(28,new q(10,114),new q(2,115)),new K(28,new q(19,46),new q(4,47)),new K(28,new q(28,22),new q(6,23)),new K(30,new q(33,16),new q(4,17))),new Dt(27,Int32Array.from([6,34,62,90,118]),new K(30,new q(8,122),new q(4,123)),new K(28,new q(22,45),new q(3,46)),new K(30,new q(8,23),new q(26,24)),new K(30,new q(12,15),new q(28,16))),new Dt(28,Int32Array.from([6,26,50,74,98,122]),new K(30,new q(3,117),new q(10,118)),new K(28,new q(3,45),new q(23,46)),new K(30,new q(4,24),new q(31,25)),new K(30,new q(11,15),new q(31,16))),new Dt(29,Int32Array.from([6,30,54,78,102,126]),new K(30,new q(7,116),new q(7,117)),new K(28,new q(21,45),new q(7,46)),new K(30,new q(1,23),new q(37,24)),new K(30,new q(19,15),new q(26,16))),new Dt(30,Int32Array.from([6,26,52,78,104,130]),new K(30,new q(5,115),new q(10,116)),new K(28,new q(19,47),new q(10,48)),new K(30,new q(15,24),new q(25,25)),new K(30,new q(23,15),new q(25,16))),new Dt(31,Int32Array.from([6,30,56,82,108,134]),new K(30,new q(13,115),new q(3,116)),new K(28,new q(2,46),new q(29,47)),new K(30,new q(42,24),new q(1,25)),new K(30,new q(23,15),new q(28,16))),new Dt(32,Int32Array.from([6,34,60,86,112,138]),new K(30,new q(17,115)),new K(28,new q(10,46),new q(23,47)),new K(30,new q(10,24),new q(35,25)),new K(30,new q(19,15),new q(35,16))),new Dt(33,Int32Array.from([6,30,58,86,114,142]),new K(30,new q(17,115),new q(1,116)),new K(28,new q(14,46),new q(21,47)),new K(30,new q(29,24),new q(19,25)),new K(30,new q(11,15),new q(46,16))),new Dt(34,Int32Array.from([6,34,62,90,118,146]),new K(30,new q(13,115),new q(6,116)),new K(28,new q(14,46),new q(23,47)),new K(30,new q(44,24),new q(7,25)),new K(30,new q(59,16),new q(1,17))),new Dt(35,Int32Array.from([6,30,54,78,102,126,150]),new K(30,new q(12,121),new q(7,122)),new K(28,new q(12,47),new q(26,48)),new K(30,new q(39,24),new q(14,25)),new K(30,new q(22,15),new q(41,16))),new Dt(36,Int32Array.from([6,24,50,76,102,128,154]),new K(30,new q(6,121),new q(14,122)),new K(28,new q(6,47),new q(34,48)),new K(30,new q(46,24),new q(10,25)),new K(30,new q(2,15),new q(64,16))),new Dt(37,Int32Array.from([6,28,54,80,106,132,158]),new K(30,new q(17,122),new q(4,123)),new K(28,new q(29,46),new q(14,47)),new K(30,new q(49,24),new q(10,25)),new K(30,new q(24,15),new q(46,16))),new Dt(38,Int32Array.from([6,32,58,84,110,136,162]),new K(30,new q(4,122),new q(18,123)),new K(28,new q(13,46),new q(32,47)),new K(30,new q(48,24),new q(14,25)),new K(30,new q(42,15),new q(32,16))),new Dt(39,Int32Array.from([6,26,54,82,110,138,166]),new K(30,new q(20,117),new q(4,118)),new K(28,new q(40,47),new q(7,48)),new K(30,new q(43,24),new q(22,25)),new K(30,new q(10,15),new q(67,16))),new Dt(40,Int32Array.from([6,30,58,86,114,142,170]),new K(30,new q(19,118),new q(6,119)),new K(28,new q(18,47),new q(31,48)),new K(30,new q(34,24),new q(34,25)),new K(30,new q(20,15),new q(61,16)))];var Ot;(function(e){e[e.DATA_MASK_000=0]=`DATA_MASK_000`,e[e.DATA_MASK_001=1]=`DATA_MASK_001`,e[e.DATA_MASK_010=2]=`DATA_MASK_010`,e[e.DATA_MASK_011=3]=`DATA_MASK_011`,e[e.DATA_MASK_100=4]=`DATA_MASK_100`,e[e.DATA_MASK_101=5]=`DATA_MASK_101`,e[e.DATA_MASK_110=6]=`DATA_MASK_110`,e[e.DATA_MASK_111=7]=`DATA_MASK_111`})(Ot||={});class kt{constructor(e,t){this.value=e,this.isMasked=t}unmaskBitMatrix(e,t){for(let n=0;n<t;n++)for(let r=0;r<t;r++)this.isMasked(n,r)&&e.flip(r,n)}}kt.values=new Map([[Ot.DATA_MASK_000,new kt(Ot.DATA_MASK_000,(e,t)=>(e+t&1)==0)],[Ot.DATA_MASK_001,new kt(Ot.DATA_MASK_001,(e,t)=>(e&1)==0)],[Ot.DATA_MASK_010,new kt(Ot.DATA_MASK_010,(e,t)=>t%3==0)],[Ot.DATA_MASK_011,new kt(Ot.DATA_MASK_011,(e,t)=>(e+t)%3==0)],[Ot.DATA_MASK_100,new kt(Ot.DATA_MASK_100,(e,t)=>(Math.floor(e/2)+Math.floor(t/3)&1)==0)],[Ot.DATA_MASK_101,new kt(Ot.DATA_MASK_101,(e,t)=>e*t%6==0)],[Ot.DATA_MASK_110,new kt(Ot.DATA_MASK_110,(e,t)=>e*t%6<3)],[Ot.DATA_MASK_111,new kt(Ot.DATA_MASK_111,(e,t)=>(e+t+e*t%3&1)==0)]]);class At{constructor(e){let t=e.getHeight();if(t<21||(t&3)!=1)throw new x;this.bitMatrix=e}readFormatInformation(){if(this.parsedFormatInfo!==null&&this.parsedFormatInfo!==void 0)return this.parsedFormatInfo;let e=0;for(let t=0;t<6;t++)e=this.copyBit(t,8,e);e=this.copyBit(7,8,e),e=this.copyBit(8,8,e),e=this.copyBit(8,7,e);for(let t=5;t>=0;t--)e=this.copyBit(8,t,e);let t=this.bitMatrix.getHeight(),n=0,r=t-7;for(let e=t-1;e>=r;e--)n=this.copyBit(8,e,n);for(let e=t-8;e<t;e++)n=this.copyBit(e,8,n);if(this.parsedFormatInfo=Et.decodeFormatInformation(e,n),this.parsedFormatInfo!==null)return this.parsedFormatInfo;throw new x}readVersion(){if(this.parsedVersion!==null&&this.parsedVersion!==void 0)return this.parsedVersion;let e=this.bitMatrix.getHeight(),t=Math.floor((e-17)/4);if(t<=6)return Dt.getVersionForNumber(t);let n=0,r=e-11;for(let t=5;t>=0;t--)for(let i=e-9;i>=r;i--)n=this.copyBit(i,t,n);let i=Dt.decodeVersionInformation(n);if(i!==null&&i.getDimensionForVersion()===e)return this.parsedVersion=i,i;n=0;for(let t=5;t>=0;t--)for(let i=e-9;i>=r;i--)n=this.copyBit(t,i,n);if(i=Dt.decodeVersionInformation(n),i!==null&&i.getDimensionForVersion()===e)return this.parsedVersion=i,i;throw new x}copyBit(e,t,n){return(this.isMirror?this.bitMatrix.get(t,e):this.bitMatrix.get(e,t))?n<<1|1:n<<1}readCodewords(){let e=this.readFormatInformation(),t=this.readVersion(),n=kt.values.get(e.getDataMask()),r=this.bitMatrix.getHeight();n.unmaskBitMatrix(this.bitMatrix,r);let i=t.buildFunctionPattern(),a=!0,o=new Uint8Array(t.getTotalCodewords()),s=0,c=0,l=0;for(let e=r-1;e>0;e-=2){e===6&&e--;for(let t=0;t<r;t++){let n=a?r-1-t:t;for(let t=0;t<2;t++)i.get(e-t,n)||(l++,c<<=1,this.bitMatrix.get(e-t,n)&&(c|=1),l===8&&(o[s++]=c,l=0,c=0))}a=!a}if(s!==t.getTotalCodewords())throw new x;return o}remask(){if(this.parsedFormatInfo===null)return;let e=kt.values[this.parsedFormatInfo.getDataMask()],t=this.bitMatrix.getHeight();e.unmaskBitMatrix(this.bitMatrix,t)}setMirror(e){this.parsedVersion=null,this.parsedFormatInfo=null,this.isMirror=e}mirror(){let e=this.bitMatrix;for(let t=0,n=e.getWidth();t<n;t++)for(let n=t+1,r=e.getHeight();n<r;n++)e.get(t,n)!==e.get(n,t)&&(e.flip(n,t),e.flip(t,n))}}class jt{constructor(e,t){this.numDataCodewords=e,this.codewords=t}static getDataBlocks(e,t,n){if(e.length!==t.getTotalCodewords())throw new l;let r=t.getECBlocksForLevel(n),i=0,a=r.getECBlocks();for(let e of a)i+=e.getCount();let o=Array(i),s=0;for(let e of a)for(let t=0;t<e.getCount();t++){let t=e.getDataCodewords(),n=r.getECCodewordsPerBlock()+t;o[s++]=new jt(t,new Uint8Array(n))}let c=o[0].codewords.length,u=o.length-1;for(;u>=0&&o[u].codewords.length!==c;)u--;u++;let d=c-r.getECCodewordsPerBlock(),f=0;for(let t=0;t<d;t++)for(let n=0;n<s;n++)o[n].codewords[t]=e[f++];for(let t=u;t<s;t++)o[t].codewords[d]=e[f++];let p=o[0].codewords.length;for(let t=d;t<p;t++)for(let n=0;n<s;n++){let r=n<u?t:t+1;o[n].codewords[r]=e[f++]}return o}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}var Mt;(function(e){e[e.TERMINATOR=0]=`TERMINATOR`,e[e.NUMERIC=1]=`NUMERIC`,e[e.ALPHANUMERIC=2]=`ALPHANUMERIC`,e[e.STRUCTURED_APPEND=3]=`STRUCTURED_APPEND`,e[e.BYTE=4]=`BYTE`,e[e.ECI=5]=`ECI`,e[e.KANJI=6]=`KANJI`,e[e.FNC1_FIRST_POSITION=7]=`FNC1_FIRST_POSITION`,e[e.FNC1_SECOND_POSITION=8]=`FNC1_SECOND_POSITION`,e[e.HANZI=9]=`HANZI`})(Mt||={});class Nt{constructor(e,t,n,r){this.value=e,this.stringValue=t,this.characterCountBitsForVersions=n,this.bits=r,Nt.FOR_BITS.set(r,this),Nt.FOR_VALUE.set(e,this)}static forBits(e){let t=Nt.FOR_BITS.get(e);if(t===void 0)throw new l;return t}getCharacterCountBits(e){let t=e.getVersionNumber(),n;return n=t<=9?0:t<=26?1:2,this.characterCountBitsForVersions[n]}getValue(){return this.value}getBits(){return this.bits}equals(e){if(!(e instanceof Nt))return!1;let t=e;return this.value===t.value}toString(){return this.stringValue}}Nt.FOR_BITS=new Map,Nt.FOR_VALUE=new Map,Nt.TERMINATOR=new Nt(Mt.TERMINATOR,`TERMINATOR`,Int32Array.from([0,0,0]),0),Nt.NUMERIC=new Nt(Mt.NUMERIC,`NUMERIC`,Int32Array.from([10,12,14]),1),Nt.ALPHANUMERIC=new Nt(Mt.ALPHANUMERIC,`ALPHANUMERIC`,Int32Array.from([9,11,13]),2),Nt.STRUCTURED_APPEND=new Nt(Mt.STRUCTURED_APPEND,`STRUCTURED_APPEND`,Int32Array.from([0,0,0]),3),Nt.BYTE=new Nt(Mt.BYTE,`BYTE`,Int32Array.from([8,16,16]),4),Nt.ECI=new Nt(Mt.ECI,`ECI`,Int32Array.from([0,0,0]),7),Nt.KANJI=new Nt(Mt.KANJI,`KANJI`,Int32Array.from([8,10,12]),8),Nt.FNC1_FIRST_POSITION=new Nt(Mt.FNC1_FIRST_POSITION,`FNC1_FIRST_POSITION`,Int32Array.from([0,0,0]),5),Nt.FNC1_SECOND_POSITION=new Nt(Mt.FNC1_SECOND_POSITION,`FNC1_SECOND_POSITION`,Int32Array.from([0,0,0]),9),Nt.HANZI=new Nt(Mt.HANZI,`HANZI`,Int32Array.from([8,10,12]),13);class Pt{static decode(e,t,n,r){let i=new _t(e),a=new D,o=[],s=-1,c=-1;try{let e=null,n=!1,l;do{if(i.available()<4)l=Nt.TERMINATOR;else{let e=i.readBits(4);l=Nt.forBits(e)}switch(l){case Nt.TERMINATOR:break;case Nt.FNC1_FIRST_POSITION:case Nt.FNC1_SECOND_POSITION:n=!0;break;case Nt.STRUCTURED_APPEND:if(i.available()<16)throw new x;s=i.readBits(8),c=i.readBits(8);break;case Nt.ECI:let u=Pt.parseECIValue(i);if(e=C.getCharacterSetECIByValue(u),e===null)throw new x;break;case Nt.HANZI:let d=i.readBits(4),f=i.readBits(l.getCharacterCountBits(t));d===Pt.GB2312_SUBSET&&Pt.decodeHanziSegment(i,a,f);break;default:let p=i.readBits(l.getCharacterCountBits(t));switch(l){case Nt.NUMERIC:Pt.decodeNumericSegment(i,a,p);break;case Nt.ALPHANUMERIC:Pt.decodeAlphanumericSegment(i,a,p,n);break;case Nt.BYTE:Pt.decodeByteSegment(i,a,p,e,o,r);break;case Nt.KANJI:Pt.decodeKanjiSegment(i,a,p);break;default:throw new x}break}}while(l!==Nt.TERMINATOR)}catch{throw new x}return new re(e,a.toString(),o.length===0?null:o,n===null?null:n.toString(),s,c)}static decodeHanziSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/96<<8&4294967295|t%96;a<959?a+=41377:a+=42657,r[i]=a>>8&255,r[i+1]=a&255,i+=2,n--}try{t.append(T.decode(r,E.GB2312))}catch(e){throw new x(e)}}static decodeKanjiSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/192<<8&4294967295|t%192;a<7936?a+=33088:a+=49472,r[i]=a>>8,r[i+1]=a,i+=2,n--}try{t.append(T.decode(r,E.SHIFT_JIS))}catch(e){throw new x(e)}}static decodeByteSegment(e,t,n,r,i,a){if(8*n>e.available())throw new x;let o=new Uint8Array(n);for(let t=0;t<n;t++)o[t]=e.readBits(8);let s;s=r===null?E.guessEncoding(o,a):r.getName();try{t.append(T.decode(o,s))}catch(e){throw new x(e)}i.push(o)}static toAlphaNumericChar(e){if(e>=Pt.ALPHANUMERIC_CHARS.length)throw new x;return Pt.ALPHANUMERIC_CHARS[e]}static decodeAlphanumericSegment(e,t,n,r){let i=t.length();for(;n>1;){if(e.available()<11)throw new x;let r=e.readBits(11);t.append(Pt.toAlphaNumericChar(Math.floor(r/45))),t.append(Pt.toAlphaNumericChar(r%45)),n-=2}if(n===1){if(e.available()<6)throw new x;t.append(Pt.toAlphaNumericChar(e.readBits(6)))}if(r)for(let e=i;e<t.length();e++)t.charAt(e)===`%`&&(e<t.length()-1&&t.charAt(e+1)===`%`?t.deleteCharAt(e+1):t.setCharAt(e,``))}static decodeNumericSegment(e,t,n){for(;n>=3;){if(e.available()<10)throw new x;let r=e.readBits(10);if(r>=1e3)throw new x;t.append(Pt.toAlphaNumericChar(Math.floor(r/100))),t.append(Pt.toAlphaNumericChar(Math.floor(r/10)%10)),t.append(Pt.toAlphaNumericChar(r%10)),n-=3}if(n===2){if(e.available()<7)throw new x;let n=e.readBits(7);if(n>=100)throw new x;t.append(Pt.toAlphaNumericChar(Math.floor(n/10))),t.append(Pt.toAlphaNumericChar(n%10))}else if(n===1){if(e.available()<4)throw new x;let n=e.readBits(4);if(n>=10)throw new x;t.append(Pt.toAlphaNumericChar(n))}}static parseECIValue(e){let t=e.readBits(8);if(!(t&128))return t&127;if((t&192)==128){let n=e.readBits(8);return(t&63)<<8&4294967295|n}if((t&224)==192){let n=e.readBits(16);return(t&31)<<16&4294967295|n}throw new x}}Pt.ALPHANUMERIC_CHARS=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Pt.GB2312_SUBSET=1;class Ft{constructor(e){this.mirrored=e}isMirrored(){return this.mirrored}applyMirroredCorrection(e){if(!this.mirrored||e===null||e.length<3)return;let t=e[0];e[0]=e[2],e[2]=t}}class It{constructor(){this.rsDecoder=new V(oe.QR_CODE_FIELD_256)}decodeBooleanArray(e,t){return this.decodeBitMatrix(O.parseFromBooleanArray(e),t)}decodeBitMatrix(e,t){let n=new At(e),r=null;try{return this.decodeBitMatrixParser(n,t)}catch(e){r=e}try{n.remask(),n.setMirror(!0),n.readVersion(),n.readFormatInformation(),n.mirror();let e=this.decodeBitMatrixParser(n,t);return e.setOther(new Ft(!0)),e}catch(e){throw r===null?e:r}}decodeBitMatrixParser(e,t){let n=e.readVersion(),r=e.readFormatInformation().getErrorCorrectionLevel(),i=e.readCodewords(),a=jt.getDataBlocks(i,n,r),o=0;for(let e of a)o+=e.getNumDataCodewords();let s=new Uint8Array(o),c=0;for(let e of a){let t=e.getCodewords(),n=e.getNumDataCodewords();this.correctErrors(t,n);for(let e=0;e<n;e++)s[c++]=t[e]}return Pt.decode(s,n,r,t)}correctErrors(e,t){let n=new Int32Array(e);try{this.rsDecoder.decode(n,e.length-t)}catch{throw new d}for(let r=0;r<t;r++)e[r]=n[r]}}class Lt extends H{constructor(e,t,n){super(e,t),this.estimatedModuleSize=n}aboutEquals(e,t,n){if(Math.abs(t-this.getY())<=e&&Math.abs(n-this.getX())<=e){let t=Math.abs(e-this.estimatedModuleSize);return t<=1||t<=this.estimatedModuleSize}return!1}combineEstimate(e,t,n){return new Lt((this.getX()+t)/2,(this.getY()+e)/2,(this.estimatedModuleSize+n)/2)}}class Rt{constructor(e,t,n,r,i,a,o){this.image=e,this.startX=t,this.startY=n,this.width=r,this.height=i,this.moduleSize=a,this.resultPointCallback=o,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(3)}find(){let e=this.startX,t=this.height,n=e+this.width,r=this.startY+t/2,i=new Int32Array(3),a=this.image;for(let o=0;o<t;o++){let t=r+(o&1?-Math.floor((o+1)/2):Math.floor((o+1)/2));i[0]=0,i[1]=0,i[2]=0;let s=e;for(;s<n&&!a.get(s,t);)s++;let c=0;for(;s<n;){if(a.get(s,t))if(c===1)i[1]++;else if(c===2){if(this.foundPatternCross(i)){let e=this.handlePossibleCenter(i,t,s);if(e!==null)return e}i[0]=i[2],i[1]=1,i[2]=0,c=1}else i[++c]++;else c===1&&c++,i[c]++;s++}if(this.foundPatternCross(i)){let e=this.handlePossibleCenter(i,t,n);if(e!==null)return e}}if(this.possibleCenters.length!==0)return this.possibleCenters[0];throw new k}static centerFromEnd(e,t){return t-e[2]-e[1]/2}foundPatternCross(e){let t=this.moduleSize,n=t/2;for(let r=0;r<3;r++)if(Math.abs(t-e[r])>=n)return!1;return!0}crossCheckVertical(e,t,n,r){let i=this.image,a=i.getHeight(),o=this.crossCheckStateCount;o[0]=0,o[1]=0,o[2]=0;let s=e;for(;s>=0&&i.get(t,s)&&o[1]<=n;)o[1]++,s--;if(s<0||o[1]>n)return NaN;for(;s>=0&&!i.get(t,s)&&o[0]<=n;)o[0]++,s--;if(o[0]>n)return NaN;for(s=e+1;s<a&&i.get(t,s)&&o[1]<=n;)o[1]++,s++;if(s===a||o[1]>n)return NaN;for(;s<a&&!i.get(t,s)&&o[2]<=n;)o[2]++,s++;if(o[2]>n)return NaN;let c=o[0]+o[1]+o[2];return 5*Math.abs(c-r)>=2*r?NaN:this.foundPatternCross(o)?Rt.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n){let r=e[0]+e[1]+e[2],i=Rt.centerFromEnd(e,n),a=this.crossCheckVertical(t,i,2*e[1],r);if(!isNaN(a)){let t=(e[0]+e[1]+e[2])/3;for(let e of this.possibleCenters)if(e.aboutEquals(t,a,i))return e.combineEstimate(a,i,t);let n=new Lt(i,a,t);this.possibleCenters.push(n),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(n)}return null}}class zt extends H{constructor(e,t,n,r){super(e,t),this.estimatedModuleSize=n,this.count=r,r===void 0&&(this.count=1)}getEstimatedModuleSize(){return this.estimatedModuleSize}getCount(){return this.count}aboutEquals(e,t,n){if(Math.abs(t-this.getY())<=e&&Math.abs(n-this.getX())<=e){let t=Math.abs(e-this.estimatedModuleSize);return t<=1||t<=this.estimatedModuleSize}return!1}combineEstimate(e,t,n){let r=this.count+1;return new zt((this.count*this.getX()+t)/r,(this.count*this.getY()+e)/r,(this.count*this.estimatedModuleSize+n)/r,r)}}class Bt{constructor(e){this.bottomLeft=e[0],this.topLeft=e[1],this.topRight=e[2]}getBottomLeft(){return this.bottomLeft}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}}class Vt{constructor(e,t){this.image=e,this.resultPointCallback=t,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(5),this.resultPointCallback=t}getImage(){return this.image}getPossibleCenters(){return this.possibleCenters}find(e){let t=e!=null&&e.get(b.TRY_HARDER)!==void 0,n=e!=null&&e.get(b.PURE_BARCODE)!==void 0,r=this.image,i=r.getHeight(),a=r.getWidth(),o=Math.floor(3*i/(4*Vt.MAX_MODULES));(o<Vt.MIN_SKIP||t)&&(o=Vt.MIN_SKIP);let s=!1,c=new Int32Array(5);for(let e=o-1;e<i&&!s;e+=o){c[0]=0,c[1]=0,c[2]=0,c[3]=0,c[4]=0;let t=0;for(let i=0;i<a;i++)if(r.get(i,e))(t&1)==1&&t++,c[t]++;else if(t&1)c[t]++;else if(t===4)if(Vt.foundPatternCross(c)){if(this.handlePossibleCenter(c,e,i,n)===!0)if(o=2,this.hasSkipped===!0)s=this.haveMultiplyConfirmedCenters();else{let t=this.findRowSkip();t>c[2]&&(e+=t-c[2]-o,i=a-1)}else{c[0]=c[2],c[1]=c[3],c[2]=c[4],c[3]=1,c[4]=0,t=3;continue}t=0,c[0]=0,c[1]=0,c[2]=0,c[3]=0,c[4]=0}else c[0]=c[2],c[1]=c[3],c[2]=c[4],c[3]=1,c[4]=0,t=3;else c[++t]++;Vt.foundPatternCross(c)&&this.handlePossibleCenter(c,e,a,n)===!0&&(o=c[0],this.hasSkipped&&(s=this.haveMultiplyConfirmedCenters()))}let l=this.selectBestPatterns();return H.orderBestPatterns(l),new Bt(l)}static centerFromEnd(e,t){return t-e[4]-e[3]-e[2]/2}static foundPatternCross(e){let t=0;for(let n=0;n<5;n++){let r=e[n];if(r===0)return!1;t+=r}if(t<7)return!1;let n=t/7,r=n/2;return Math.abs(n-e[0])<r&&Math.abs(n-e[1])<r&&Math.abs(3*n-e[2])<3*r&&Math.abs(n-e[3])<r&&Math.abs(n-e[4])<r}getCrossCheckStateCount(){let e=this.crossCheckStateCount;return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e}crossCheckDiagonal(e,t,n,r){let i=this.getCrossCheckStateCount(),a=0,o=this.image;for(;e>=a&&t>=a&&o.get(t-a,e-a);)i[2]++,a++;if(e<a||t<a)return!1;for(;e>=a&&t>=a&&!o.get(t-a,e-a)&&i[1]<=n;)i[1]++,a++;if(e<a||t<a||i[1]>n)return!1;for(;e>=a&&t>=a&&o.get(t-a,e-a)&&i[0]<=n;)i[0]++,a++;if(i[0]>n)return!1;let s=o.getHeight(),c=o.getWidth();for(a=1;e+a<s&&t+a<c&&o.get(t+a,e+a);)i[2]++,a++;if(e+a>=s||t+a>=c)return!1;for(;e+a<s&&t+a<c&&!o.get(t+a,e+a)&&i[3]<n;)i[3]++,a++;if(e+a>=s||t+a>=c||i[3]>=n)return!1;for(;e+a<s&&t+a<c&&o.get(t+a,e+a)&&i[4]<n;)i[4]++,a++;if(i[4]>=n)return!1;let l=i[0]+i[1]+i[2]+i[3]+i[4];return Math.abs(l-r)<2*r&&Vt.foundPatternCross(i)}crossCheckVertical(e,t,n,r){let i=this.image,a=i.getHeight(),o=this.getCrossCheckStateCount(),s=e;for(;s>=0&&i.get(t,s);)o[2]++,s--;if(s<0)return NaN;for(;s>=0&&!i.get(t,s)&&o[1]<=n;)o[1]++,s--;if(s<0||o[1]>n)return NaN;for(;s>=0&&i.get(t,s)&&o[0]<=n;)o[0]++,s--;if(o[0]>n)return NaN;for(s=e+1;s<a&&i.get(t,s);)o[2]++,s++;if(s===a)return NaN;for(;s<a&&!i.get(t,s)&&o[3]<n;)o[3]++,s++;if(s===a||o[3]>=n)return NaN;for(;s<a&&i.get(t,s)&&o[4]<n;)o[4]++,s++;if(o[4]>=n)return NaN;let c=o[0]+o[1]+o[2]+o[3]+o[4];return 5*Math.abs(c-r)>=2*r?NaN:Vt.foundPatternCross(o)?Vt.centerFromEnd(o,s):NaN}crossCheckHorizontal(e,t,n,r){let i=this.image,a=i.getWidth(),o=this.getCrossCheckStateCount(),s=e;for(;s>=0&&i.get(s,t);)o[2]++,s--;if(s<0)return NaN;for(;s>=0&&!i.get(s,t)&&o[1]<=n;)o[1]++,s--;if(s<0||o[1]>n)return NaN;for(;s>=0&&i.get(s,t)&&o[0]<=n;)o[0]++,s--;if(o[0]>n)return NaN;for(s=e+1;s<a&&i.get(s,t);)o[2]++,s++;if(s===a)return NaN;for(;s<a&&!i.get(s,t)&&o[3]<n;)o[3]++,s++;if(s===a||o[3]>=n)return NaN;for(;s<a&&i.get(s,t)&&o[4]<n;)o[4]++,s++;if(o[4]>=n)return NaN;let c=o[0]+o[1]+o[2]+o[3]+o[4];return 5*Math.abs(c-r)>=r?NaN:Vt.foundPatternCross(o)?Vt.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n,r){let i=e[0]+e[1]+e[2]+e[3]+e[4],a=Vt.centerFromEnd(e,n),o=this.crossCheckVertical(t,Math.floor(a),e[2],i);if(!isNaN(o)&&(a=this.crossCheckHorizontal(Math.floor(a),Math.floor(o),e[2],i),!isNaN(a)&&(!r||this.crossCheckDiagonal(Math.floor(o),Math.floor(a),e[2],i)))){let e=i/7,t=!1,n=this.possibleCenters;for(let r=0,i=n.length;r<i;r++){let i=n[r];if(i.aboutEquals(e,o,a)){n[r]=i.combineEstimate(o,a,e),t=!0;break}}if(!t){let t=new zt(a,o,e);n.push(t),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(t)}return!0}return!1}findRowSkip(){if(this.possibleCenters.length<=1)return 0;let e=null;for(let t of this.possibleCenters)if(t.getCount()>=Vt.CENTER_QUORUM)if(e==null)e=t;else return this.hasSkipped=!0,Math.floor((Math.abs(e.getX()-t.getX())-Math.abs(e.getY()-t.getY()))/2);return 0}haveMultiplyConfirmedCenters(){let e=0,t=0,n=this.possibleCenters.length;for(let n of this.possibleCenters)n.getCount()>=Vt.CENTER_QUORUM&&(e++,t+=n.getEstimatedModuleSize());if(e<3)return!1;let r=t/n,i=0;for(let e of this.possibleCenters)i+=Math.abs(e.getEstimatedModuleSize()-r);return i<=.05*t}selectBestPatterns(){let e=this.possibleCenters.length;if(e<3)throw new k;let t=this.possibleCenters,n;if(e>3){let r=0,i=0;for(let e of this.possibleCenters){let t=e.getEstimatedModuleSize();r+=t,i+=t*t}n=r/e;let a=Math.sqrt(i/e-n*n);t.sort((e,t)=>{let r=Math.abs(t.getEstimatedModuleSize()-n),i=Math.abs(e.getEstimatedModuleSize()-n);return r<i?-1:+(r>i)});let o=Math.max(.2*n,a);for(let e=0;e<t.length&&t.length>3;e++){let r=t[e];Math.abs(r.getEstimatedModuleSize()-n)>o&&(t.splice(e,1),e--)}}if(t.length>3){let e=0;for(let n of t)e+=n.getEstimatedModuleSize();n=e/t.length,t.sort((e,t)=>{if(t.getCount()===e.getCount()){let r=Math.abs(t.getEstimatedModuleSize()-n),i=Math.abs(e.getEstimatedModuleSize()-n);return r<i?1:r>i?-1:0}else return t.getCount()-e.getCount()}),t.splice(3)}return[t[0],t[1],t[2]]}}Vt.CENTER_QUORUM=2,Vt.MIN_SKIP=3,Vt.MAX_MODULES=57;class Ht{constructor(e){this.image=e}getImage(){return this.image}getResultPointCallback(){return this.resultPointCallback}detect(e){this.resultPointCallback=e==null?null:e.get(b.NEED_RESULT_POINT_CALLBACK);let t=new Vt(this.image,this.resultPointCallback).find(e);return this.processFinderPatternInfo(t)}processFinderPatternInfo(e){let t=e.getTopLeft(),n=e.getTopRight(),r=e.getBottomLeft(),i=this.calculateModuleSize(t,n,r);if(i<1)throw new k(`No pattern found in proccess finder.`);let a=Ht.computeDimension(t,n,r,i),o=Dt.getProvisionalVersionForDimension(a),s=o.getDimensionForVersion()-7,c=null;if(o.getAlignmentPatternCenters().length>0){let e=n.getX()-t.getX()+r.getX(),a=n.getY()-t.getY()+r.getY(),o=1-3/s,l=Math.floor(t.getX()+o*(e-t.getX())),u=Math.floor(t.getY()+o*(a-t.getY()));for(let e=4;e<=16;e<<=1)try{c=this.findAlignmentInRegion(i,l,u,e);break}catch(e){if(!(e instanceof k))throw e}}let l=Ht.createTransform(t,n,r,c,a),u=Ht.sampleGrid(this.image,l,a),d;return d=c===null?[r,t,n]:[r,t,n,c],new pe(u,d)}static createTransform(e,t,n,r,i){let a=i-3.5,o,s,c,l;return r===null?(o=t.getX()-e.getX()+n.getX(),s=t.getY()-e.getY()+n.getY(),c=a,l=a):(o=r.getX(),s=r.getY(),c=a-3,l=c),U.quadrilateralToQuadrilateral(3.5,3.5,a,3.5,c,l,3.5,a,e.getX(),e.getY(),t.getX(),t.getY(),o,s,n.getX(),n.getY())}static sampleGrid(e,t,n){return ve.getInstance().sampleGridWithTransform(e,n,n,t)}static computeDimension(e,t,n,r){let i=de.round(H.distance(e,t)/r),a=de.round(H.distance(e,n)/r),o=Math.floor((i+a)/2)+7;switch(o&3){case 0:o++;break;case 2:o--;break;case 3:throw new k(`Dimensions could be not found.`)}return o}calculateModuleSize(e,t,n){return(this.calculateModuleSizeOneWay(e,t)+this.calculateModuleSizeOneWay(e,n))/2}calculateModuleSizeOneWay(e,t){let n=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.getX()),Math.floor(e.getY()),Math.floor(t.getX()),Math.floor(t.getY())),r=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(t.getX()),Math.floor(t.getY()),Math.floor(e.getX()),Math.floor(e.getY()));return isNaN(n)?r/7:isNaN(r)?n/7:(n+r)/14}sizeOfBlackWhiteBlackRunBothWays(e,t,n,r){let i=this.sizeOfBlackWhiteBlackRun(e,t,n,r),a=1,o=e-(n-e);o<0?(a=e/(e-o),o=0):o>=this.image.getWidth()&&(a=(this.image.getWidth()-1-e)/(o-e),o=this.image.getWidth()-1);let s=Math.floor(t-(r-t)*a);return a=1,s<0?(a=t/(t-s),s=0):s>=this.image.getHeight()&&(a=(this.image.getHeight()-1-t)/(s-t),s=this.image.getHeight()-1),o=Math.floor(e+(o-e)*a),i+=this.sizeOfBlackWhiteBlackRun(e,t,o,s),i-1}sizeOfBlackWhiteBlackRun(e,t,n,r){let i=Math.abs(r-t)>Math.abs(n-e);if(i){let i=e;e=t,t=i,i=n,n=r,r=i}let a=Math.abs(n-e),o=Math.abs(r-t),s=-a/2,c=e<n?1:-1,l=t<r?1:-1,u=0,d=n+c;for(let n=e,f=t;n!==d;n+=c){let c=i?f:n,d=i?n:f;if(u===1===this.image.get(c,d)){if(u===2)return de.distance(n,f,e,t);u++}if(s+=o,s>0){if(f===r)break;f+=l,s-=a}}return u===2?de.distance(n+c,r,e,t):NaN}findAlignmentInRegion(e,t,n,r){let i=Math.floor(r*e),a=Math.max(0,t-i),o=Math.min(this.image.getWidth()-1,t+i);if(o-a<e*3)throw new k(`Alignment top exceeds estimated module size.`);let s=Math.max(0,n-i),c=Math.min(this.image.getHeight()-1,n+i);if(c-s<e*3)throw new k(`Alignment bottom exceeds estimated module size.`);return new Rt(this.image,a,s,o-a,c-s,e,this.resultPointCallback).find()}}class Ut{constructor(){this.decoder=new It}getDecoder(){return this.decoder}decode(e,t){let n,r;if(t!=null&&t.get(b.PURE_BARCODE)!==void 0){let i=Ut.extractPureBits(e.getBlackMatrix());n=this.decoder.decodeBitMatrix(i,t),r=Ut.NO_POINTS}else{let i=new Ht(e.getBlackMatrix()).detect(t);n=this.decoder.decodeBitMatrix(i.getBits(),t),r=i.getPoints()}n.getOther()instanceof Ft&&n.getOther().applyMirroredCorrection(r);let i=new R(n.getText(),n.getRawBytes(),void 0,r,z.QR_CODE,void 0),a=n.getByteSegments();a!==null&&i.putMetadata(ne.BYTE_SEGMENTS,a);let o=n.getECLevel();return o!==null&&i.putMetadata(ne.ERROR_CORRECTION_LEVEL,o),n.hasStructuredAppend()&&(i.putMetadata(ne.STRUCTURED_APPEND_SEQUENCE,n.getStructuredAppendSequenceNumber()),i.putMetadata(ne.STRUCTURED_APPEND_PARITY,n.getStructuredAppendParity())),i}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t===null||n===null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=n[0];if(o>=s||i>=a||a-i!==s-o&&(s=o+(a-i),s>=e.getWidth()))throw new k;let c=Math.round((s-o+1)/r),l=Math.round((a-i+1)/r);if(c<=0||l<=0||l!==c)throw new k;let u=Math.floor(r/2);i+=u,o+=u;let d=o+Math.floor((c-1)*r)-s;if(d>0){if(d>u)throw new k;o-=d}let f=i+Math.floor((l-1)*r)-a;if(f>0){if(f>u)throw new k;i-=f}let p=new O(c,l);for(let t=0;t<l;t++){let n=i+Math.floor(t*r);for(let i=0;i<c;i++)e.get(o+Math.floor(i*r),n)&&p.set(i,t)}return p}static moduleSize(e,t){let n=t.getHeight(),r=t.getWidth(),i=e[0],a=e[1],o=!0,s=0;for(;i<r&&a<n;){if(o!==t.get(i,a)){if(++s===5)break;o=!o}i++,a++}if(i===r||a===n)throw new k;return(i-e[0])/7}}Ut.NO_POINTS=[];class Wt{PDF417Common(){}static getBitCountSum(e){return de.sum(e)}static toIntArray(e){if(e==null||!e.length)return Wt.EMPTY_INT_ARRAY;let t=new Int32Array(e.length),n=0;for(let r of e)t[n++]=r;return t}static getCodeword(e){let t=g.binarySearch(Wt.SYMBOL_TABLE,e&262143);return t<0?-1:(Wt.CODEWORD_TABLE[t]-1)%Wt.NUMBER_OF_CODEWORDS}}Wt.NUMBER_OF_CODEWORDS=929,Wt.MAX_CODEWORDS_IN_BARCODE=Wt.NUMBER_OF_CODEWORDS-1,Wt.MIN_ROWS_IN_BARCODE=3,Wt.MAX_ROWS_IN_BARCODE=90,Wt.MODULES_IN_CODEWORD=17,Wt.MODULES_IN_STOP_PATTERN=18,Wt.BARS_IN_MODULE=8,Wt.EMPTY_INT_ARRAY=new Int32Array([]),Wt.SYMBOL_TABLE=Int32Array.from([66142,66170,66206,66236,66290,66292,66350,66382,66396,66454,66470,66476,66594,66600,66614,66626,66628,66632,66640,66654,66662,66668,66682,66690,66718,66720,66748,66758,66776,66798,66802,66804,66820,66824,66832,66846,66848,66876,66880,66936,66950,66956,66968,66992,67006,67022,67036,67042,67044,67048,67062,67118,67150,67164,67214,67228,67256,67294,67322,67350,67366,67372,67398,67404,67416,67438,67474,67476,67490,67492,67496,67510,67618,67624,67650,67656,67664,67678,67686,67692,67706,67714,67716,67728,67742,67744,67772,67782,67788,67800,67822,67826,67828,67842,67848,67870,67872,67900,67904,67960,67974,67992,68016,68030,68046,68060,68066,68068,68072,68086,68104,68112,68126,68128,68156,68160,68216,68336,68358,68364,68376,68400,68414,68448,68476,68494,68508,68536,68546,68548,68552,68560,68574,68582,68588,68654,68686,68700,68706,68708,68712,68726,68750,68764,68792,68802,68804,68808,68816,68830,68838,68844,68858,68878,68892,68920,68976,68990,68994,68996,69e3,69008,69022,69024,69052,69062,69068,69080,69102,69106,69108,69142,69158,69164,69190,69208,69230,69254,69260,69272,69296,69310,69326,69340,69386,69394,69396,69410,69416,69430,69442,69444,69448,69456,69470,69478,69484,69554,69556,69666,69672,69698,69704,69712,69726,69754,69762,69764,69776,69790,69792,69820,69830,69836,69848,69870,69874,69876,69890,69918,69920,69948,69952,70008,70022,70040,70064,70078,70094,70108,70114,70116,70120,70134,70152,70174,70176,70264,70384,70412,70448,70462,70496,70524,70542,70556,70584,70594,70600,70608,70622,70630,70636,70664,70672,70686,70688,70716,70720,70776,70896,71136,71180,71192,71216,71230,71264,71292,71360,71416,71452,71480,71536,71550,71554,71556,71560,71568,71582,71584,71612,71622,71628,71640,71662,71726,71732,71758,71772,71778,71780,71784,71798,71822,71836,71864,71874,71880,71888,71902,71910,71916,71930,71950,71964,71992,72048,72062,72066,72068,72080,72094,72096,72124,72134,72140,72152,72174,72178,72180,72206,72220,72248,72304,72318,72416,72444,72456,72464,72478,72480,72508,72512,72568,72588,72600,72624,72638,72654,72668,72674,72676,72680,72694,72726,72742,72748,72774,72780,72792,72814,72838,72856,72880,72894,72910,72924,72930,72932,72936,72950,72966,72972,72984,73008,73022,73056,73084,73102,73116,73144,73156,73160,73168,73182,73190,73196,73210,73226,73234,73236,73250,73252,73256,73270,73282,73284,73296,73310,73318,73324,73346,73348,73352,73360,73374,73376,73404,73414,73420,73432,73454,73498,73518,73522,73524,73550,73564,73570,73572,73576,73590,73800,73822,73858,73860,73872,73886,73888,73916,73944,73970,73972,73992,74014,74016,74044,74048,74104,74118,74136,74160,74174,74210,74212,74216,74230,74244,74256,74270,74272,74360,74480,74502,74508,74544,74558,74592,74620,74638,74652,74680,74690,74696,74704,74726,74732,74782,74784,74812,74992,75232,75288,75326,75360,75388,75456,75512,75576,75632,75646,75650,75652,75664,75678,75680,75708,75718,75724,75736,75758,75808,75836,75840,75896,76016,76256,76736,76824,76848,76862,76896,76924,76992,77048,77296,77340,77368,77424,77438,77536,77564,77572,77576,77584,77600,77628,77632,77688,77702,77708,77720,77744,77758,77774,77788,77870,77902,77916,77922,77928,77966,77980,78008,78018,78024,78032,78046,78060,78074,78094,78136,78192,78206,78210,78212,78224,78238,78240,78268,78278,78284,78296,78322,78324,78350,78364,78448,78462,78560,78588,78600,78622,78624,78652,78656,78712,78726,78744,78768,78782,78798,78812,78818,78820,78824,78838,78862,78876,78904,78960,78974,79072,79100,79296,79352,79368,79376,79390,79392,79420,79424,79480,79600,79628,79640,79664,79678,79712,79740,79772,79800,79810,79812,79816,79824,79838,79846,79852,79894,79910,79916,79942,79948,79960,79982,79988,80006,80024,80048,80062,80078,80092,80098,80100,80104,80134,80140,80176,80190,80224,80252,80270,80284,80312,80328,80336,80350,80358,80364,80378,80390,80396,80408,80432,80446,80480,80508,80576,80632,80654,80668,80696,80752,80766,80776,80784,80798,80800,80828,80844,80856,80878,80882,80884,80914,80916,80930,80932,80936,80950,80962,80968,80976,80990,80998,81004,81026,81028,81040,81054,81056,81084,81094,81100,81112,81134,81154,81156,81160,81168,81182,81184,81212,81216,81272,81286,81292,81304,81328,81342,81358,81372,81380,81384,81398,81434,81454,81458,81460,81486,81500,81506,81508,81512,81526,81550,81564,81592,81602,81604,81608,81616,81630,81638,81644,81702,81708,81722,81734,81740,81752,81774,81778,81780,82050,82078,82080,82108,82180,82184,82192,82206,82208,82236,82240,82296,82316,82328,82352,82366,82402,82404,82408,82440,82448,82462,82464,82492,82496,82552,82672,82694,82700,82712,82736,82750,82784,82812,82830,82882,82884,82888,82896,82918,82924,82952,82960,82974,82976,83004,83008,83064,83184,83424,83468,83480,83504,83518,83552,83580,83648,83704,83740,83768,83824,83838,83842,83844,83848,83856,83872,83900,83910,83916,83928,83950,83984,84e3,84028,84032,84088,84208,84448,84928,85040,85054,85088,85116,85184,85240,85488,85560,85616,85630,85728,85756,85764,85768,85776,85790,85792,85820,85824,85880,85894,85900,85912,85936,85966,85980,86048,86080,86136,86256,86496,86976,88160,88188,88256,88312,88560,89056,89200,89214,89312,89340,89536,89592,89608,89616,89632,89664,89720,89840,89868,89880,89904,89952,89980,89998,90012,90040,90190,90204,90254,90268,90296,90306,90308,90312,90334,90382,90396,90424,90480,90494,90500,90504,90512,90526,90528,90556,90566,90572,90584,90610,90612,90638,90652,90680,90736,90750,90848,90876,90884,90888,90896,90910,90912,90940,90944,91e3,91014,91020,91032,91056,91070,91086,91100,91106,91108,91112,91126,91150,91164,91192,91248,91262,91360,91388,91584,91640,91664,91678,91680,91708,91712,91768,91888,91928,91952,91966,92e3,92028,92046,92060,92088,92098,92100,92104,92112,92126,92134,92140,92188,92216,92272,92384,92412,92608,92664,93168,93200,93214,93216,93244,93248,93304,93424,93664,93720,93744,93758,93792,93820,93888,93944,93980,94008,94064,94078,94084,94088,94096,94110,94112,94140,94150,94156,94168,94246,94252,94278,94284,94296,94318,94342,94348,94360,94384,94398,94414,94428,94440,94470,94476,94488,94512,94526,94560,94588,94606,94620,94648,94658,94660,94664,94672,94686,94694,94700,94714,94726,94732,94744,94768,94782,94816,94844,94912,94968,94990,95004,95032,95088,95102,95112,95120,95134,95136,95164,95180,95192,95214,95218,95220,95244,95256,95280,95294,95328,95356,95424,95480,95728,95758,95772,95800,95856,95870,95968,95996,96008,96016,96030,96032,96060,96064,96120,96152,96176,96190,96220,96226,96228,96232,96290,96292,96296,96310,96322,96324,96328,96336,96350,96358,96364,96386,96388,96392,96400,96414,96416,96444,96454,96460,96472,96494,96498,96500,96514,96516,96520,96528,96542,96544,96572,96576,96632,96646,96652,96664,96688,96702,96718,96732,96738,96740,96744,96758,96772,96776,96784,96798,96800,96828,96832,96888,97008,97030,97036,97048,97072,97086,97120,97148,97166,97180,97208,97220,97224,97232,97246,97254,97260,97326,97330,97332,97358,97372,97378,97380,97384,97398,97422,97436,97464,97474,97476,97480,97488,97502,97510,97516,97550,97564,97592,97648,97666,97668,97672,97680,97694,97696,97724,97734,97740,97752,97774,97830,97836,97850,97862,97868,97880,97902,97906,97908,97926,97932,97944,97968,97998,98012,98018,98020,98024,98038,98618,98674,98676,98838,98854,98874,98892,98904,98926,98930,98932,98968,99006,99042,99044,99048,99062,99166,99194,99246,99286,99350,99366,99372,99386,99398,99416,99438,99442,99444,99462,99504,99518,99534,99548,99554,99556,99560,99574,99590,99596,99608,99632,99646,99680,99708,99726,99740,99768,99778,99780,99784,99792,99806,99814,99820,99834,99858,99860,99874,99880,99894,99906,99920,99934,99962,99970,99972,99976,99984,99998,1e5,100028,100038,100044,100056,100078,100082,100084,100142,100174,100188,100246,100262,100268,100306,100308,100390,100396,100410,100422,100428,100440,100462,100466,100468,100486,100504,100528,100542,100558,100572,100578,100580,100584,100598,100620,100656,100670,100704,100732,100750,100792,100802,100808,100816,100830,100838,100844,100858,100888,100912,100926,100960,100988,101056,101112,101148,101176,101232,101246,101250,101252,101256,101264,101278,101280,101308,101318,101324,101336,101358,101362,101364,101410,101412,101416,101430,101442,101448,101456,101470,101478,101498,101506,101508,101520,101534,101536,101564,101580,101618,101620,101636,101640,101648,101662,101664,101692,101696,101752,101766,101784,101838,101858,101860,101864,101934,101938,101940,101966,101980,101986,101988,101992,102030,102044,102072,102082,102084,102088,102096,102138,102166,102182,102188,102214,102220,102232,102254,102282,102290,102292,102306,102308,102312,102326,102444,102458,102470,102476,102488,102514,102516,102534,102552,102576,102590,102606,102620,102626,102632,102646,102662,102668,102704,102718,102752,102780,102798,102812,102840,102850,102856,102864,102878,102886,102892,102906,102936,102974,103008,103036,103104,103160,103224,103280,103294,103298,103300,103312,103326,103328,103356,103366,103372,103384,103406,103410,103412,103472,103486,103520,103548,103616,103672,103920,103992,104048,104062,104160,104188,104194,104196,104200,104208,104224,104252,104256,104312,104326,104332,104344,104368,104382,104398,104412,104418,104420,104424,104482,104484,104514,104520,104528,104542,104550,104570,104578,104580,104592,104606,104608,104636,104652,104690,104692,104706,104712,104734,104736,104764,104768,104824,104838,104856,104910,104930,104932,104936,104968,104976,104990,104992,105020,105024,105080,105200,105240,105278,105312,105372,105410,105412,105416,105424,105446,105518,105524,105550,105564,105570,105572,105576,105614,105628,105656,105666,105672,105680,105702,105722,105742,105756,105784,105840,105854,105858,105860,105864,105872,105888,105932,105970,105972,106006,106022,106028,106054,106060,106072,106100,106118,106124,106136,106160,106174,106190,106210,106212,106216,106250,106258,106260,106274,106276,106280,106306,106308,106312,106320,106334,106348,106394,106414,106418,106420,106566,106572,106610,106612,106630,106636,106648,106672,106686,106722,106724,106728,106742,106758,106764,106776,106800,106814,106848,106876,106894,106908,106936,106946,106948,106952,106960,106974,106982,106988,107032,107056,107070,107104,107132,107200,107256,107292,107320,107376,107390,107394,107396,107400,107408,107422,107424,107452,107462,107468,107480,107502,107506,107508,107544,107568,107582,107616,107644,107712,107768,108016,108060,108088,108144,108158,108256,108284,108290,108292,108296,108304,108318,108320,108348,108352,108408,108422,108428,108440,108464,108478,108494,108508,108514,108516,108520,108592,108640,108668,108736,108792,109040,109536,109680,109694,109792,109820,110016,110072,110084,110088,110096,110112,110140,110144,110200,110320,110342,110348,110360,110384,110398,110432,110460,110478,110492,110520,110532,110536,110544,110558,110658,110686,110714,110722,110724,110728,110736,110750,110752,110780,110796,110834,110836,110850,110852,110856,110864,110878,110880,110908,110912,110968,110982,111e3,111054,111074,111076,111080,111108,111112,111120,111134,111136,111164,111168,111224,111344,111372,111422,111456,111516,111554,111556,111560,111568,111590,111632,111646,111648,111676,111680,111736,111856,112096,112152,112224,112252,112320,112440,112514,112516,112520,112528,112542,112544,112588,112686,112718,112732,112782,112796,112824,112834,112836,112840,112848,112870,112890,112910,112924,112952,113008,113022,113026,113028,113032,113040,113054,113056,113100,113138,113140,113166,113180,113208,113264,113278,113376,113404,113416,113424,113440,113468,113472,113560,113614,113634,113636,113640,113686,113702,113708,113734,113740,113752,113778,113780,113798,113804,113816,113840,113854,113870,113890,113892,113896,113926,113932,113944,113968,113982,114016,114044,114076,114114,114116,114120,114128,114150,114170,114194,114196,114210,114212,114216,114242,114244,114248,114256,114270,114278,114306,114308,114312,114320,114334,114336,114364,114380,114420,114458,114478,114482,114484,114510,114524,114530,114532,114536,114842,114866,114868,114970,114994,114996,115042,115044,115048,115062,115130,115226,115250,115252,115278,115292,115298,115300,115304,115318,115342,115394,115396,115400,115408,115422,115430,115436,115450,115478,115494,115514,115526,115532,115570,115572,115738,115758,115762,115764,115790,115804,115810,115812,115816,115830,115854,115868,115896,115906,115912,115920,115934,115942,115948,115962,115996,116024,116080,116094,116098,116100,116104,116112,116126,116128,116156,116166,116172,116184,116206,116210,116212,116246,116262,116268,116282,116294,116300,116312,116334,116338,116340,116358,116364,116376,116400,116414,116430,116444,116450,116452,116456,116498,116500,116514,116520,116534,116546,116548,116552,116560,116574,116582,116588,116602,116654,116694,116714,116762,116782,116786,116788,116814,116828,116834,116836,116840,116854,116878,116892,116920,116930,116936,116944,116958,116966,116972,116986,117006,117048,117104,117118,117122,117124,117136,117150,117152,117180,117190,117196,117208,117230,117234,117236,117304,117360,117374,117472,117500,117506,117508,117512,117520,117536,117564,117568,117624,117638,117644,117656,117680,117694,117710,117724,117730,117732,117736,117750,117782,117798,117804,117818,117830,117848,117874,117876,117894,117936,117950,117966,117986,117988,117992,118022,118028,118040,118064,118078,118112,118140,118172,118210,118212,118216,118224,118238,118246,118266,118306,118312,118338,118352,118366,118374,118394,118402,118404,118408,118416,118430,118432,118460,118476,118514,118516,118574,118578,118580,118606,118620,118626,118628,118632,118678,118694,118700,118730,118738,118740,118830,118834,118836,118862,118876,118882,118884,118888,118902,118926,118940,118968,118978,118980,118984,118992,119006,119014,119020,119034,119068,119096,119152,119166,119170,119172,119176,119184,119198,119200,119228,119238,119244,119256,119278,119282,119284,119324,119352,119408,119422,119520,119548,119554,119556,119560,119568,119582,119584,119612,119616,119672,119686,119692,119704,119728,119742,119758,119772,119778,119780,119784,119798,119920,119934,120032,120060,120256,120312,120324,120328,120336,120352,120384,120440,120560,120582,120588,120600,120624,120638,120672,120700,120718,120732,120760,120770,120772,120776,120784,120798,120806,120812,120870,120876,120890,120902,120908,120920,120946,120948,120966,120972,120984,121008,121022,121038,121058,121060,121064,121078,121100,121112,121136,121150,121184,121212,121244,121282,121284,121288,121296,121318,121338,121356,121368,121392,121406,121440,121468,121536,121592,121656,121730,121732,121736,121744,121758,121760,121804,121842,121844,121890,121922,121924,121928,121936,121950,121958,121978,121986,121988,121992,122e3,122014,122016,122044,122060,122098,122100,122116,122120,122128,122142,122144,122172,122176,122232,122246,122264,122318,122338,122340,122344,122414,122418,122420,122446,122460,122466,122468,122472,122510,122524,122552,122562,122564,122568,122576,122598,122618,122646,122662,122668,122694,122700,122712,122738,122740,122762,122770,122772,122786,122788,122792,123018,123026,123028,123042,123044,123048,123062,123098,123146,123154,123156,123170,123172,123176,123190,123202,123204,123208,123216,123238,123244,123258,123290,123314,123316,123402,123410,123412,123426,123428,123432,123446,123458,123464,123472,123486,123494,123500,123514,123522,123524,123528,123536,123552,123580,123590,123596,123608,123630,123634,123636,123674,123698,123700,123740,123746,123748,123752,123834,123914,123922,123924,123938,123944,123958,123970,123976,123984,123998,124006,124012,124026,124034,124036,124048,124062,124064,124092,124102,124108,124120,124142,124146,124148,124162,124164,124168,124176,124190,124192,124220,124224,124280,124294,124300,124312,124336,124350,124366,124380,124386,124388,124392,124406,124442,124462,124466,124468,124494,124508,124514,124520,124558,124572,124600,124610,124612,124616,124624,124646,124666,124694,124710,124716,124730,124742,124748,124760,124786,124788,124818,124820,124834,124836,124840,124854,124946,124948,124962,124964,124968,124982,124994,124996,125e3,125008,125022,125030,125036,125050,125058,125060,125064,125072,125086,125088,125116,125126,125132,125144,125166,125170,125172,125186,125188,125192,125200,125216,125244,125248,125304,125318,125324,125336,125360,125374,125390,125404,125410,125412,125416,125430,125444,125448,125456,125472,125504,125560,125680,125702,125708,125720,125744,125758,125792,125820,125838,125852,125880,125890,125892,125896,125904,125918,125926,125932,125978,125998,126002,126004,126030,126044,126050,126052,126056,126094,126108,126136,126146,126148,126152,126160,126182,126202,126222,126236,126264,126320,126334,126338,126340,126344,126352,126366,126368,126412,126450,126452,126486,126502,126508,126522,126534,126540,126552,126574,126578,126580,126598,126604,126616,126640,126654,126670,126684,126690,126692,126696,126738,126754,126756,126760,126774,126786,126788,126792,126800,126814,126822,126828,126842,126894,126898,126900,126934,127126,127142,127148,127162,127178,127186,127188,127254,127270,127276,127290,127302,127308,127320,127342,127346,127348,127370,127378,127380,127394,127396,127400,127450,127510,127526,127532,127546,127558,127576,127598,127602,127604,127622,127628,127640,127664,127678,127694,127708,127714,127716,127720,127734,127754,127762,127764,127778,127784,127810,127812,127816,127824,127838,127846,127866,127898,127918,127922,127924,128022,128038,128044,128058,128070,128076,128088,128110,128114,128116,128134,128140,128152,128176,128190,128206,128220,128226,128228,128232,128246,128262,128268,128280,128304,128318,128352,128380,128398,128412,128440,128450,128452,128456,128464,128478,128486,128492,128506,128522,128530,128532,128546,128548,128552,128566,128578,128580,128584,128592,128606,128614,128634,128642,128644,128648,128656,128670,128672,128700,128716,128754,128756,128794,128814,128818,128820,128846,128860,128866,128868,128872,128886,128918,128934,128940,128954,128978,128980,129178,129198,129202,129204,129238,129258,129306,129326,129330,129332,129358,129372,129378,129380,129384,129398,129430,129446,129452,129466,129482,129490,129492,129562,129582,129586,129588,129614,129628,129634,129636,129640,129654,129678,129692,129720,129730,129732,129736,129744,129758,129766,129772,129814,129830,129836,129850,129862,129868,129880,129902,129906,129908,129930,129938,129940,129954,129956,129960,129974,130010]),Wt.CODEWORD_TABLE=Int32Array.from([2627,1819,2622,2621,1813,1812,2729,2724,2723,2779,2774,2773,902,896,908,868,865,861,859,2511,873,871,1780,835,2493,825,2491,842,837,844,1764,1762,811,810,809,2483,807,2482,806,2480,815,814,813,812,2484,817,816,1745,1744,1742,1746,2655,2637,2635,2626,2625,2623,2628,1820,2752,2739,2737,2728,2727,2725,2730,2785,2783,2778,2777,2775,2780,787,781,747,739,736,2413,754,752,1719,692,689,681,2371,678,2369,700,697,694,703,1688,1686,642,638,2343,631,2341,627,2338,651,646,643,2345,654,652,1652,1650,1647,1654,601,599,2322,596,2321,594,2319,2317,611,610,608,606,2324,603,2323,615,614,612,1617,1616,1614,1612,616,1619,1618,2575,2538,2536,905,901,898,909,2509,2507,2504,870,867,864,860,2512,875,872,1781,2490,2489,2487,2485,1748,836,834,832,830,2494,827,2492,843,841,839,845,1765,1763,2701,2676,2674,2653,2648,2656,2634,2633,2631,2629,1821,2638,2636,2770,2763,2761,2750,2745,2753,2736,2735,2733,2731,1848,2740,2738,2786,2784,591,588,576,569,566,2296,1590,537,534,526,2276,522,2274,545,542,539,548,1572,1570,481,2245,466,2242,462,2239,492,485,482,2249,496,494,1534,1531,1528,1538,413,2196,406,2191,2188,425,419,2202,415,2199,432,430,427,1472,1467,1464,433,1476,1474,368,367,2160,365,2159,362,2157,2155,2152,378,377,375,2166,372,2165,369,2162,383,381,379,2168,1419,1418,1416,1414,385,1411,384,1423,1422,1420,1424,2461,802,2441,2439,790,786,783,794,2409,2406,2403,750,742,738,2414,756,753,1720,2367,2365,2362,2359,1663,693,691,684,2373,680,2370,702,699,696,704,1690,1687,2337,2336,2334,2332,1624,2329,1622,640,637,2344,634,2342,630,2340,650,648,645,2346,655,653,1653,1651,1649,1655,2612,2597,2595,2571,2568,2565,2576,2534,2529,2526,1787,2540,2537,907,904,900,910,2503,2502,2500,2498,1768,2495,1767,2510,2508,2506,869,866,863,2513,876,874,1782,2720,2713,2711,2697,2694,2691,2702,2672,2670,2664,1828,2678,2675,2647,2646,2644,2642,1823,2639,1822,2654,2652,2650,2657,2771,1855,2765,2762,1850,1849,2751,2749,2747,2754,353,2148,344,342,336,2142,332,2140,345,1375,1373,306,2130,299,2128,295,2125,319,314,311,2132,1354,1352,1349,1356,262,257,2101,253,2096,2093,274,273,267,2107,263,2104,280,278,275,1316,1311,1308,1320,1318,2052,202,2050,2044,2040,219,2063,212,2060,208,2055,224,221,2066,1260,1258,1252,231,1248,229,1266,1264,1261,1268,155,1998,153,1996,1994,1991,1988,165,164,2007,162,2006,159,2003,2e3,172,171,169,2012,166,2010,1186,1184,1182,1179,175,1176,173,1192,1191,1189,1187,176,1194,1193,2313,2307,2305,592,589,2294,2292,2289,578,572,568,2297,580,1591,2272,2267,2264,1547,538,536,529,2278,525,2275,547,544,541,1574,1571,2237,2235,2229,1493,2225,1489,478,2247,470,2244,465,2241,493,488,484,2250,498,495,1536,1533,1530,1539,2187,2186,2184,2182,1432,2179,1430,2176,1427,414,412,2197,409,2195,405,2193,2190,426,424,421,2203,418,2201,431,429,1473,1471,1469,1466,434,1477,1475,2478,2472,2470,2459,2457,2454,2462,803,2437,2432,2429,1726,2443,2440,792,789,785,2401,2399,2393,1702,2389,1699,2411,2408,2405,745,741,2415,758,755,1721,2358,2357,2355,2353,1661,2350,1660,2347,1657,2368,2366,2364,2361,1666,690,687,2374,683,2372,701,698,705,1691,1689,2619,2617,2610,2608,2605,2613,2593,2588,2585,1803,2599,2596,2563,2561,2555,1797,2551,1795,2573,2570,2567,2577,2525,2524,2522,2520,1786,2517,1785,2514,1783,2535,2533,2531,2528,1788,2541,2539,906,903,911,2721,1844,2715,2712,1838,1836,2699,2696,2693,2703,1827,1826,1824,2673,2671,2669,2666,1829,2679,2677,1858,1857,2772,1854,1853,1851,1856,2766,2764,143,1987,139,1986,135,133,131,1984,128,1983,125,1981,138,137,136,1985,1133,1132,1130,112,110,1974,107,1973,104,1971,1969,122,121,119,117,1977,114,1976,124,1115,1114,1112,1110,1117,1116,84,83,1953,81,1952,78,1950,1948,1945,94,93,91,1959,88,1958,85,1955,99,97,95,1961,1086,1085,1083,1081,1078,100,1090,1089,1087,1091,49,47,1917,44,1915,1913,1910,1907,59,1926,56,1925,53,1922,1919,66,64,1931,61,1929,1042,1040,1038,71,1035,70,1032,68,1048,1047,1045,1043,1050,1049,12,10,1869,1867,1864,1861,21,1880,19,1877,1874,1871,28,1888,25,1886,22,1883,982,980,977,974,32,30,991,989,987,984,34,995,994,992,2151,2150,2147,2146,2144,356,355,354,2149,2139,2138,2136,2134,1359,343,341,338,2143,335,2141,348,347,346,1376,1374,2124,2123,2121,2119,1326,2116,1324,310,308,305,2131,302,2129,298,2127,320,318,316,313,2133,322,321,1355,1353,1351,1357,2092,2091,2089,2087,1276,2084,1274,2081,1271,259,2102,256,2100,252,2098,2095,272,269,2108,266,2106,281,279,277,1317,1315,1313,1310,282,1321,1319,2039,2037,2035,2032,1203,2029,1200,1197,207,2053,205,2051,201,2049,2046,2043,220,218,2064,215,2062,211,2059,228,226,223,2069,1259,1257,1254,232,1251,230,1267,1265,1263,2316,2315,2312,2311,2309,2314,2304,2303,2301,2299,1593,2308,2306,590,2288,2287,2285,2283,1578,2280,1577,2295,2293,2291,579,577,574,571,2298,582,581,1592,2263,2262,2260,2258,1545,2255,1544,2252,1541,2273,2271,2269,2266,1550,535,532,2279,528,2277,546,543,549,1575,1573,2224,2222,2220,1486,2217,1485,2214,1482,1479,2238,2236,2234,2231,1496,2228,1492,480,477,2248,473,2246,469,2243,490,487,2251,497,1537,1535,1532,2477,2476,2474,2479,2469,2468,2466,2464,1730,2473,2471,2453,2452,2450,2448,1729,2445,1728,2460,2458,2456,2463,805,804,2428,2427,2425,2423,1725,2420,1724,2417,1722,2438,2436,2434,2431,1727,2444,2442,793,791,788,795,2388,2386,2384,1697,2381,1696,2378,1694,1692,2402,2400,2398,2395,1703,2392,1701,2412,2410,2407,751,748,744,2416,759,757,1807,2620,2618,1806,1805,2611,2609,2607,2614,1802,1801,1799,2594,2592,2590,2587,1804,2600,2598,1794,1793,1791,1789,2564,2562,2560,2557,1798,2554,1796,2574,2572,2569,2578,1847,1846,2722,1843,1842,1840,1845,2716,2714,1835,1834,1832,1830,1839,1837,2700,2698,2695,2704,1817,1811,1810,897,862,1777,829,826,838,1760,1758,808,2481,1741,1740,1738,1743,2624,1818,2726,2776,782,740,737,1715,686,679,695,1682,1680,639,628,2339,647,644,1645,1643,1640,1648,602,600,597,595,2320,593,2318,609,607,604,1611,1610,1608,1606,613,1615,1613,2328,926,924,892,886,899,857,850,2505,1778,824,823,821,819,2488,818,2486,833,831,828,840,1761,1759,2649,2632,2630,2746,2734,2732,2782,2781,570,567,1587,531,527,523,540,1566,1564,476,467,463,2240,486,483,1524,1521,1518,1529,411,403,2192,399,2189,423,416,1462,1457,1454,428,1468,1465,2210,366,363,2158,360,2156,357,2153,376,373,370,2163,1410,1409,1407,1405,382,1402,380,1417,1415,1412,1421,2175,2174,777,774,771,784,732,725,722,2404,743,1716,676,674,668,2363,665,2360,685,1684,1681,626,624,622,2335,620,2333,617,2330,641,635,649,1646,1644,1642,2566,928,925,2530,2527,894,891,888,2501,2499,2496,858,856,854,851,1779,2692,2668,2665,2645,2643,2640,2651,2768,2759,2757,2744,2743,2741,2748,352,1382,340,337,333,1371,1369,307,300,296,2126,315,312,1347,1342,1350,261,258,250,2097,246,2094,271,268,264,1306,1301,1298,276,1312,1309,2115,203,2048,195,2045,191,2041,213,209,2056,1246,1244,1238,225,1234,222,1256,1253,1249,1262,2080,2079,154,1997,150,1995,147,1992,1989,163,160,2004,156,2001,1175,1174,1172,1170,1167,170,1164,167,1185,1183,1180,1177,174,1190,1188,2025,2024,2022,587,586,564,559,556,2290,573,1588,520,518,512,2268,508,2265,530,1568,1565,461,457,2233,450,2230,446,2226,479,471,489,1526,1523,1520,397,395,2185,392,2183,389,2180,2177,410,2194,402,422,1463,1461,1459,1456,1470,2455,799,2433,2430,779,776,773,2397,2394,2390,734,728,724,746,1717,2356,2354,2351,2348,1658,677,675,673,670,667,688,1685,1683,2606,2589,2586,2559,2556,2552,927,2523,2521,2518,2515,1784,2532,895,893,890,2718,2709,2707,2689,2687,2684,2663,2662,2660,2658,1825,2667,2769,1852,2760,2758,142,141,1139,1138,134,132,129,126,1982,1129,1128,1126,1131,113,111,108,105,1972,101,1970,120,118,115,1109,1108,1106,1104,123,1113,1111,82,79,1951,75,1949,72,1946,92,89,86,1956,1077,1076,1074,1072,98,1069,96,1084,1082,1079,1088,1968,1967,48,45,1916,42,1914,39,1911,1908,60,57,54,1923,50,1920,1031,1030,1028,1026,67,1023,65,1020,62,1041,1039,1036,1033,69,1046,1044,1944,1943,1941,11,9,1868,7,1865,1862,1859,20,1878,16,1875,13,1872,970,968,966,963,29,960,26,23,983,981,978,975,33,971,31,990,988,985,1906,1904,1902,993,351,2145,1383,331,330,328,326,2137,323,2135,339,1372,1370,294,293,291,289,2122,286,2120,283,2117,309,303,317,1348,1346,1344,245,244,242,2090,239,2088,236,2085,2082,260,2099,249,270,1307,1305,1303,1300,1314,189,2038,186,2036,183,2033,2030,2026,206,198,2047,194,216,1247,1245,1243,1240,227,1237,1255,2310,2302,2300,2286,2284,2281,565,563,561,558,575,1589,2261,2259,2256,2253,1542,521,519,517,514,2270,511,533,1569,1567,2223,2221,2218,2215,1483,2211,1480,459,456,453,2232,449,474,491,1527,1525,1522,2475,2467,2465,2451,2449,2446,801,800,2426,2424,2421,2418,1723,2435,780,778,775,2387,2385,2382,2379,1695,2375,1693,2396,735,733,730,727,749,1718,2616,2615,2604,2603,2601,2584,2583,2581,2579,1800,2591,2550,2549,2547,2545,1792,2542,1790,2558,929,2719,1841,2710,2708,1833,1831,2690,2688,2686,1815,1809,1808,1774,1756,1754,1737,1736,1734,1739,1816,1711,1676,1674,633,629,1638,1636,1633,1641,598,1605,1604,1602,1600,605,1609,1607,2327,887,853,1775,822,820,1757,1755,1584,524,1560,1558,468,464,1514,1511,1508,1519,408,404,400,1452,1447,1444,417,1458,1455,2208,364,361,358,2154,1401,1400,1398,1396,374,1393,371,1408,1406,1403,1413,2173,2172,772,726,723,1712,672,669,666,682,1678,1675,625,623,621,618,2331,636,632,1639,1637,1635,920,918,884,880,889,849,848,847,846,2497,855,852,1776,2641,2742,2787,1380,334,1367,1365,301,297,1340,1338,1335,1343,255,251,247,1296,1291,1288,265,1302,1299,2113,204,196,192,2042,1232,1230,1224,214,1220,210,1242,1239,1235,1250,2077,2075,151,148,1993,144,1990,1163,1162,1160,1158,1155,161,1152,157,1173,1171,1168,1165,168,1181,1178,2021,2020,2018,2023,585,560,557,1585,516,509,1562,1559,458,447,2227,472,1516,1513,1510,398,396,393,390,2181,386,2178,407,1453,1451,1449,1446,420,1460,2209,769,764,720,712,2391,729,1713,664,663,661,659,2352,656,2349,671,1679,1677,2553,922,919,2519,2516,885,883,881,2685,2661,2659,2767,2756,2755,140,1137,1136,130,127,1125,1124,1122,1127,109,106,102,1103,1102,1100,1098,116,1107,1105,1980,80,76,73,1947,1068,1067,1065,1063,90,1060,87,1075,1073,1070,1080,1966,1965,46,43,40,1912,36,1909,1019,1018,1016,1014,58,1011,55,1008,51,1029,1027,1024,1021,63,1037,1034,1940,1939,1937,1942,8,1866,4,1863,1,1860,956,954,952,949,946,17,14,969,967,964,961,27,957,24,979,976,972,1901,1900,1898,1896,986,1905,1903,350,349,1381,329,327,324,1368,1366,292,290,287,284,2118,304,1341,1339,1337,1345,243,240,237,2086,233,2083,254,1297,1295,1293,1290,1304,2114,190,187,184,2034,180,2031,177,2027,199,1233,1231,1229,1226,217,1223,1241,2078,2076,584,555,554,552,550,2282,562,1586,507,506,504,502,2257,499,2254,515,1563,1561,445,443,441,2219,438,2216,435,2212,460,454,475,1517,1515,1512,2447,798,797,2422,2419,770,768,766,2383,2380,2376,721,719,717,714,731,1714,2602,2582,2580,2548,2546,2543,923,921,2717,2706,2705,2683,2682,2680,1771,1752,1750,1733,1732,1731,1735,1814,1707,1670,1668,1631,1629,1626,1634,1599,1598,1596,1594,1603,1601,2326,1772,1753,1751,1581,1554,1552,1504,1501,1498,1509,1442,1437,1434,401,1448,1445,2206,1392,1391,1389,1387,1384,359,1399,1397,1394,1404,2171,2170,1708,1672,1669,619,1632,1630,1628,1773,1378,1363,1361,1333,1328,1336,1286,1281,1278,248,1292,1289,2111,1218,1216,1210,197,1206,193,1228,1225,1221,1236,2073,2071,1151,1150,1148,1146,152,1143,149,1140,145,1161,1159,1156,1153,158,1169,1166,2017,2016,2014,2019,1582,510,1556,1553,452,448,1506,1500,394,391,387,1443,1441,1439,1436,1450,2207,765,716,713,1709,662,660,657,1673,1671,916,914,879,878,877,882,1135,1134,1121,1120,1118,1123,1097,1096,1094,1092,103,1101,1099,1979,1059,1058,1056,1054,77,1051,74,1066,1064,1061,1071,1964,1963,1007,1006,1004,1002,999,41,996,37,1017,1015,1012,1009,52,1025,1022,1936,1935,1933,1938,942,940,938,935,932,5,2,955,953,950,947,18,943,15,965,962,958,1895,1894,1892,1890,973,1899,1897,1379,325,1364,1362,288,285,1334,1332,1330,241,238,234,1287,1285,1283,1280,1294,2112,188,185,181,178,2028,1219,1217,1215,1212,200,1209,1227,2074,2072,583,553,551,1583,505,503,500,513,1557,1555,444,442,439,436,2213,455,451,1507,1505,1502,796,763,762,760,767,711,710,708,706,2377,718,715,1710,2544,917,915,2681,1627,1597,1595,2325,1769,1749,1747,1499,1438,1435,2204,1390,1388,1385,1395,2169,2167,1704,1665,1662,1625,1623,1620,1770,1329,1282,1279,2109,1214,1207,1222,2068,2065,1149,1147,1144,1141,146,1157,1154,2013,2011,2008,2015,1579,1549,1546,1495,1487,1433,1431,1428,1425,388,1440,2205,1705,658,1667,1664,1119,1095,1093,1978,1057,1055,1052,1062,1962,1960,1005,1003,1e3,997,38,1013,1010,1932,1930,1927,1934,941,939,936,933,6,930,3,951,948,944,1889,1887,1884,1881,959,1893,1891,35,1377,1360,1358,1327,1325,1322,1331,1277,1275,1272,1269,235,1284,2110,1205,1204,1201,1198,182,1195,179,1213,2070,2067,1580,501,1551,1548,440,437,1497,1494,1490,1503,761,709,707,1706,913,912,2198,1386,2164,2161,1621,1766,2103,1208,2058,2054,1145,1142,2005,2002,1999,2009,1488,1429,1426,2200,1698,1659,1656,1975,1053,1957,1954,1001,998,1924,1921,1918,1928,937,934,931,1879,1876,1873,1870,945,1885,1882,1323,1273,1270,2105,1202,1199,1196,1211,2061,2057,1576,1543,1540,1484,1481,1478,1491,1700]);class Gt{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class Kt{static detectMultiple(e,t,n){let r=e.getBlackMatrix(),i=Kt.detect(n,r);return i.length||(r=r.clone(),r.rotate180(),i=Kt.detect(n,r)),new Gt(r,i)}static detect(e,t){let n=[],r=0,i=0,a=!1;for(;r<t.getHeight();){let o=Kt.findVertices(t,r,i);if(o[0]==null&&o[3]==null){if(!a)break;a=!1,i=0;for(let e of n)e[1]!=null&&(r=Math.trunc(Math.max(r,e[1].getY()))),e[3]!=null&&(r=Math.max(r,Math.trunc(e[3].getY())));r+=Kt.ROW_STEP;continue}if(a=!0,n.push(o),!e)break;o[2]==null?(i=Math.trunc(o[4].getX()),r=Math.trunc(o[4].getY())):(i=Math.trunc(o[2].getX()),r=Math.trunc(o[2].getY()))}return n}static findVertices(e,t,n){let r=e.getHeight(),i=e.getWidth(),a=Array(8);return Kt.copyToResult(a,Kt.findRowsWithPattern(e,r,i,t,n,Kt.START_PATTERN),Kt.INDEXES_START_PATTERN),a[4]!=null&&(n=Math.trunc(a[4].getX()),t=Math.trunc(a[4].getY())),Kt.copyToResult(a,Kt.findRowsWithPattern(e,r,i,t,n,Kt.STOP_PATTERN),Kt.INDEXES_STOP_PATTERN),a}static copyToResult(e,t,n){for(let r=0;r<n.length;r++)e[n[r]]=t[r]}static findRowsWithPattern(e,t,n,r,i,a){let o=[,,,,],s=!1,c=new Int32Array(a.length);for(;r<t;r+=Kt.ROW_STEP){let t=Kt.findGuardPattern(e,i,r,n,!1,a,c);if(t!=null){for(;r>0;){let o=Kt.findGuardPattern(e,i,--r,n,!1,a,c);if(o!=null)t=o;else{r++;break}}o[0]=new H(t[0],r),o[1]=new H(t[1],r),s=!0;break}}let l=r+1;if(s){let r=0,i=Int32Array.from([Math.trunc(o[0].getX()),Math.trunc(o[1].getX())]);for(;l<t;l++){let t=Kt.findGuardPattern(e,i[0],l,n,!1,a,c);if(t!=null&&Math.abs(i[0]-t[0])<Kt.MAX_PATTERN_DRIFT&&Math.abs(i[1]-t[1])<Kt.MAX_PATTERN_DRIFT)i=t,r=0;else if(r>Kt.SKIPPED_ROW_COUNT_MAX)break;else r++}l-=r+1,o[2]=new H(i[0],l),o[3]=new H(i[1],l)}return l-r<Kt.BARCODE_MIN_HEIGHT&&g.fill(o,null),o}static findGuardPattern(e,t,n,r,i,a,o){g.fillWithin(o,0,o.length,0);let s=t,c=0;for(;e.get(s,n)&&s>0&&c++<Kt.MAX_PIXEL_DRIFT;)s--;let l=s,u=0,d=a.length;for(let t=i;l<r;l++)if(e.get(l,n)!==t)o[u]++;else{if(u===d-1){if(Kt.patternMatchVariance(o,a,Kt.MAX_INDIVIDUAL_VARIANCE)<Kt.MAX_AVG_VARIANCE)return new Int32Array([s,l]);s+=o[0]+o[1],p.arraycopy(o,2,o,0,u-1),o[u-1]=0,o[u]=0,u--}else u++;o[u]=1,t=!t}return u===d-1&&Kt.patternMatchVariance(o,a,Kt.MAX_INDIVIDUAL_VARIANCE)<Kt.MAX_AVG_VARIANCE?new Int32Array([s,l-1]):null}static patternMatchVariance(e,t,n){let r=e.length,i=0,a=0;for(let n=0;n<r;n++)i+=e[n],a+=t[n];if(i<a)return 1/0;let o=i/a;n*=o;let s=0;for(let i=0;i<r;i++){let r=e[i],a=t[i]*o,c=r>a?r-a:a-r;if(c>n)return 1/0;s+=c}return s/i}}Kt.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),Kt.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),Kt.MAX_AVG_VARIANCE=.42,Kt.MAX_INDIVIDUAL_VARIANCE=.8,Kt.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),Kt.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),Kt.MAX_PIXEL_DRIFT=3,Kt.MAX_PATTERN_DRIFT=5,Kt.SKIPPED_ROW_COUNT_MAX=25,Kt.ROW_STEP=5,Kt.BARCODE_MIN_HEIGHT=10;class qt{constructor(e,t){if(t.length===0)throw new l;this.field=e;let n=t.length;if(n>1&&t[0]===0){let e=1;for(;e<n&&t[e]===0;)e++;e===n?this.coefficients=new Int32Array([0]):(this.coefficients=new Int32Array(n-e),p.arraycopy(t,e,this.coefficients,0,this.coefficients.length))}else this.coefficients=t}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);if(e===1){let e=0;for(let t of this.coefficients)e=this.field.add(e,t);return e}let t=this.coefficients[0],n=this.coefficients.length;for(let r=1;r<n;r++)t=this.field.add(this.field.multiply(e,t),this.coefficients[r]);return t}add(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);if(this.isZero())return e;if(e.isZero())return this;let t=this.coefficients,n=e.coefficients;if(t.length>n.length){let e=t;t=n,n=e}let r=new Int32Array(n.length),i=n.length-t.length;p.arraycopy(n,0,r,0,i);for(let e=i;e<n.length;e++)r[e]=this.field.add(t[e-i],n[e]);return new qt(this.field,r)}subtract(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);return e.isZero()?this:this.add(e.negative())}multiply(e){return e instanceof qt?this.multiplyOther(e):this.multiplyScalar(e)}multiplyOther(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);if(this.isZero()||e.isZero())return new qt(this.field,new Int32Array([0]));let t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,a=new Int32Array(n+i-1);for(let e=0;e<n;e++){let n=t[e];for(let t=0;t<i;t++)a[e+t]=this.field.add(a[e+t],this.field.multiply(n,r[t]))}return new qt(this.field,a)}negative(){let e=this.coefficients.length,t=new Int32Array(e);for(let n=0;n<e;n++)t[n]=this.field.subtract(0,this.coefficients[n]);return new qt(this.field,t)}multiplyScalar(e){if(e===0)return new qt(this.field,new Int32Array([0]));if(e===1)return this;let t=this.coefficients.length,n=new Int32Array(t);for(let r=0;r<t;r++)n[r]=this.field.multiply(this.coefficients[r],e);return new qt(this.field,n)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return new qt(this.field,new Int32Array([0]));let n=this.coefficients.length,r=new Int32Array(n+e);for(let e=0;e<n;e++)r[e]=this.field.multiply(this.coefficients[e],t);return new qt(this.field,r)}toString(){let e=new D;for(let t=this.getDegree();t>=0;t--){let n=this.getCoefficient(t);n!==0&&(n<0?(e.append(` - `),n=-n):e.length()>0&&e.append(` + `),(t===0||n!==1)&&e.append(n),t!==0&&(t===1?e.append(`x`):(e.append(`x^`),e.append(t))))}return e.toString()}}class Jt{add(e,t){return(e+t)%this.modulus}subtract(e,t){return(this.modulus+e-t)%this.modulus}exp(e){return this.expTable[e]}log(e){if(e===0)throw new l;return this.logTable[e]}inverse(e){if(e===0)throw new ae;return this.expTable[this.modulus-this.logTable[e]-1]}multiply(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.modulus-1)]}getSize(){return this.modulus}equals(e){return e===this}}class Yt extends Jt{constructor(e,t){super(),this.modulus=e,this.expTable=new Int32Array(e),this.logTable=new Int32Array(e);let n=1;for(let r=0;r<e;r++)this.expTable[r]=n,n=n*t%e;for(let t=0;t<e-1;t++)this.logTable[this.expTable[t]]=t;this.zero=new qt(this,new Int32Array([0])),this.one=new qt(this,new Int32Array([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,t){if(e<0)throw new l;if(t===0)return this.zero;let n=new Int32Array(e+1);return n[0]=t,new qt(this,n)}}Yt.PDF417_GF=new Yt(Wt.NUMBER_OF_CODEWORDS,3);class Xt{constructor(){this.field=Yt.PDF417_GF}decode(e,t,n){let r=new qt(this.field,e),i=new Int32Array(t),a=!1;for(let e=t;e>0;e--){let n=r.evaluateAt(this.field.exp(e));i[t-e]=n,n!==0&&(a=!0)}if(!a)return 0;let o=this.field.getOne();if(n!=null)for(let t of n){let n=this.field.exp(e.length-1-t),r=new qt(this.field,new Int32Array([this.field.subtract(0,n),1]));o=o.multiply(r)}let s=new qt(this.field,i),c=this.runEuclideanAlgorithm(this.field.buildMonomial(t,1),s,t),l=c[0],u=c[1],f=this.findErrorLocations(l),p=this.findErrorMagnitudes(u,l,f);for(let t=0;t<f.length;t++){let n=e.length-1-this.field.log(f[t]);if(n<0)throw d.getChecksumInstance();e[n]=this.field.subtract(e[n],p[t])}return f.length}runEuclideanAlgorithm(e,t,n){if(e.getDegree()<t.getDegree()){let n=e;e=t,t=n}let r=e,i=t,a=this.field.getZero(),o=this.field.getOne();for(;i.getDegree()>=Math.round(n/2);){let e=r,t=a;if(r=i,a=o,r.isZero())throw d.getChecksumInstance();i=e;let n=this.field.getZero(),s=r.getCoefficient(r.getDegree()),c=this.field.inverse(s);for(;i.getDegree()>=r.getDegree()&&!i.isZero();){let e=i.getDegree()-r.getDegree(),t=this.field.multiply(i.getCoefficient(i.getDegree()),c);n=n.add(this.field.buildMonomial(e,t)),i=i.subtract(r.multiplyByMonomial(e,t))}o=n.multiply(a).subtract(t).negative()}let s=o.getCoefficient(0);if(s===0)throw d.getChecksumInstance();let c=this.field.inverse(s);return[o.multiply(c),i.multiply(c)]}findErrorLocations(e){let t=e.getDegree(),n=new Int32Array(t),r=0;for(let i=1;i<this.field.getSize()&&r<t;i++)e.evaluateAt(i)===0&&(n[r]=this.field.inverse(i),r++);if(r!==t)throw d.getChecksumInstance();return n}findErrorMagnitudes(e,t,n){let r=t.getDegree(),i=new Int32Array(r);for(let e=1;e<=r;e++)i[r-e]=this.field.multiply(e,t.getCoefficient(e));let a=new qt(this.field,i),o=n.length,s=new Int32Array(o);for(let t=0;t<o;t++){let r=this.field.inverse(n[t]),i=this.field.subtract(0,e.evaluateAt(r)),o=this.field.inverse(a.evaluateAt(r));s[t]=this.field.multiply(i,o)}return s}}class Zt{constructor(e,t,n,r,i){e instanceof Zt?this.constructor_2(e):this.constructor_1(e,t,n,r,i)}constructor_1(e,t,n,r,i){let a=t==null||n==null,o=r==null||i==null;if(a&&o)throw new k;a?(t=new H(0,r.getY()),n=new H(0,i.getY())):o&&(r=new H(e.getWidth()-1,t.getY()),i=new H(e.getWidth()-1,n.getY())),this.image=e,this.topLeft=t,this.bottomLeft=n,this.topRight=r,this.bottomRight=i,this.minX=Math.trunc(Math.min(t.getX(),n.getX())),this.maxX=Math.trunc(Math.max(r.getX(),i.getX())),this.minY=Math.trunc(Math.min(t.getY(),r.getY())),this.maxY=Math.trunc(Math.max(n.getY(),i.getY()))}constructor_2(e){this.image=e.image,this.topLeft=e.getTopLeft(),this.bottomLeft=e.getBottomLeft(),this.topRight=e.getTopRight(),this.bottomRight=e.getBottomRight(),this.minX=e.getMinX(),this.maxX=e.getMaxX(),this.minY=e.getMinY(),this.maxY=e.getMaxY()}static merge(e,t){return e==null?t:t==null?e:new Zt(e.image,e.topLeft,e.bottomLeft,t.topRight,t.bottomRight)}addMissingRows(e,t,n){let r=this.topLeft,i=this.bottomLeft,a=this.topRight,o=this.bottomRight;if(e>0){let t=n?this.topLeft:this.topRight,i=Math.trunc(t.getY()-e);i<0&&(i=0);let o=new H(t.getX(),i);n?r=o:a=o}if(t>0){let e=n?this.bottomLeft:this.bottomRight,r=Math.trunc(e.getY()+t);r>=this.image.getHeight()&&(r=this.image.getHeight()-1);let a=new H(e.getX(),r);n?i=a:o=a}return new Zt(this.image,r,i,a,o)}getMinX(){return this.minX}getMaxX(){return this.maxX}getMinY(){return this.minY}getMaxY(){return this.maxY}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}getBottomLeft(){return this.bottomLeft}getBottomRight(){return this.bottomRight}}class Qt{constructor(e,t,n,r){this.columnCount=e,this.errorCorrectionLevel=r,this.rowCountUpperPart=t,this.rowCountLowerPart=n,this.rowCount=t+n}getColumnCount(){return this.columnCount}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getRowCount(){return this.rowCount}getRowCountUpperPart(){return this.rowCountUpperPart}getRowCountLowerPart(){return this.rowCountLowerPart}}class $t{constructor(){this.buffer=``}static form(e,t){let n=-1;function r(e,r,i,a,o,s){if(e===`%%`)return`%`;if(t[++n]===void 0)return;e=a?parseInt(a.substr(1)):void 0;let c=o?parseInt(o.substr(1)):void 0,l;switch(s){case`s`:l=t[n];break;case`c`:l=t[n][0];break;case`f`:l=parseFloat(t[n]).toFixed(e);break;case`p`:l=parseFloat(t[n]).toPrecision(e);break;case`e`:l=parseFloat(t[n]).toExponential(e);break;case`x`:l=parseInt(t[n]).toString(c||16);break;case`d`:l=parseFloat(parseInt(t[n],c||10).toPrecision(e)).toFixed(0);break}l=typeof l==`object`?JSON.stringify(l):(+l).toString(c);let u=parseInt(i),d=i&&i[0]+``==`0`?`0`:` `;for(;l.length<u;)l=r===void 0?d+l:l+d;return l}return e.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,r)}format(e,...t){this.buffer+=$t.form(e,t)}toString(){return this.buffer}}class en{constructor(e){this.boundingBox=new Zt(e),this.codewords=Array(e.getMaxY()-e.getMinY()+1)}getCodewordNearby(e){let t=this.getCodeword(e);if(t!=null)return t;for(let n=1;n<en.MAX_NEARBY_DISTANCE;n++){let r=this.imageRowToCodewordIndex(e)-n;if(r>=0&&(t=this.codewords[r],t!=null)||(r=this.imageRowToCodewordIndex(e)+n,r<this.codewords.length&&(t=this.codewords[r],t!=null)))return t}return null}imageRowToCodewordIndex(e){return e-this.boundingBox.getMinY()}setCodeword(e,t){this.codewords[this.imageRowToCodewordIndex(e)]=t}getCodeword(e){return this.codewords[this.imageRowToCodewordIndex(e)]}getBoundingBox(){return this.boundingBox}getCodewords(){return this.codewords}toString(){let e=new $t,t=0;for(let n of this.codewords){if(n==null){e.format(`%3d: | %n`,t++);continue}e.format(`%3d: %3d|%3d%n`,t++,n.getRowNumber(),n.getValue())}return e.toString()}}en.MAX_NEARBY_DISTANCE=5;class tn{constructor(){this.values=new Map}setValue(e){e=Math.trunc(e);let t=this.values.get(e);t??=0,t++,this.values.set(e,t)}getValue(){let e=-1,t=[];for(let[n,r]of this.values.entries()){let i={getKey:()=>n,getValue:()=>r};i.getValue()>e?(e=i.getValue(),t=[],t.push(i.getKey())):i.getValue()===e&&t.push(i.getKey())}return Wt.toIntArray(t)}getConfidence(e){return this.values.get(e)}}class nn extends en{constructor(e,t){super(e),this._isLeft=t}setRowNumbers(){for(let e of this.getCodewords())e?.setRowNumberAsRowIndicatorColumn()}adjustCompleteIndicatorColumnRowNumbers(e){let t=this.getCodewords();this.setRowNumbers(),this.removeIncorrectCodewords(t,e);let n=this.getBoundingBox(),r=this._isLeft?n.getTopLeft():n.getTopRight(),i=this._isLeft?n.getBottomLeft():n.getBottomRight(),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.imageRowToCodewordIndex(Math.trunc(i.getY())),s=-1,c=1,l=0;for(let n=a;n<o;n++){if(t[n]==null)continue;let r=t[n],i=r.getRowNumber()-s;if(i===0)l++;else if(i===1)c=Math.max(c,l),l=1,s=r.getRowNumber();else if(i<0||r.getRowNumber()>=e.getRowCount()||i>n)t[n]=null;else{let e;e=c>2?(c-2)*i:i;let a=e>=n;for(let r=1;r<=e&&!a;r++)a=t[n-r]!=null;a?t[n]=null:(s=r.getRowNumber(),l=1)}}}getRowHeights(){let e=this.getBarcodeMetadata();if(e==null)return null;this.adjustIncompleteIndicatorColumnRowNumbers(e);let t=new Int32Array(e.getRowCount());for(let e of this.getCodewords())if(e!=null){let n=e.getRowNumber();if(n>=t.length)continue;t[n]++}return t}adjustIncompleteIndicatorColumnRowNumbers(e){let t=this.getBoundingBox(),n=this._isLeft?t.getTopLeft():t.getTopRight(),r=this._isLeft?t.getBottomLeft():t.getBottomRight(),i=this.imageRowToCodewordIndex(Math.trunc(n.getY())),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.getCodewords(),s=-1;for(let t=i;t<a;t++){if(o[t]==null)continue;let n=o[t];n.setRowNumberAsRowIndicatorColumn();let r=n.getRowNumber()-s;r===0||(r===1?s=n.getRowNumber():n.getRowNumber()>=e.getRowCount()?o[t]=null:s=n.getRowNumber())}}getBarcodeMetadata(){let e=this.getCodewords(),t=new tn,n=new tn,r=new tn,i=new tn;for(let a of e){if(a==null)continue;a.setRowNumberAsRowIndicatorColumn();let e=a.getValue()%30,o=a.getRowNumber();switch(this._isLeft||(o+=2),o%3){case 0:n.setValue(e*3+1);break;case 1:i.setValue(e/3),r.setValue(e%3);break;case 2:t.setValue(e+1);break}}if(t.getValue().length===0||n.getValue().length===0||r.getValue().length===0||i.getValue().length===0||t.getValue()[0]<1||n.getValue()[0]+r.getValue()[0]<Wt.MIN_ROWS_IN_BARCODE||n.getValue()[0]+r.getValue()[0]>Wt.MAX_ROWS_IN_BARCODE)return null;let a=new Qt(t.getValue()[0],n.getValue()[0],r.getValue()[0],i.getValue()[0]);return this.removeIncorrectCodewords(e,a),a}removeIncorrectCodewords(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(e[n]==null)continue;let i=r.getValue()%30,a=r.getRowNumber();if(a>t.getRowCount()){e[n]=null;continue}switch(this._isLeft||(a+=2),a%3){case 0:i*3+1!==t.getRowCountUpperPart()&&(e[n]=null);break;case 1:(Math.trunc(i/3)!==t.getErrorCorrectionLevel()||i%3!==t.getRowCountLowerPart())&&(e[n]=null);break;case 2:i+1!==t.getColumnCount()&&(e[n]=null);break}}}isLeft(){return this._isLeft}toString(){return`IsLeft: `+this._isLeft+`
57
+ `+super.toString()}}class rn{constructor(e,t){this.ADJUST_ROW_NUMBER_SKIP=2,this.barcodeMetadata=e,this.barcodeColumnCount=e.getColumnCount(),this.boundingBox=t,this.detectionResultColumns=Array(this.barcodeColumnCount+2)}getDetectionResultColumns(){this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[0]),this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[this.barcodeColumnCount+1]);let e=Wt.MAX_CODEWORDS_IN_BARCODE,t;do t=e,e=this.adjustRowNumbersAndGetCount();while(e>0&&e<t);return this.detectionResultColumns}adjustIndicatorColumnRowNumbers(e){e?.adjustCompleteIndicatorColumnRowNumbers(this.barcodeMetadata)}adjustRowNumbersAndGetCount(){let e=this.adjustRowNumbersByRow();if(e===0)return 0;for(let e=1;e<this.barcodeColumnCount+1;e++){let t=this.detectionResultColumns[e].getCodewords();for(let n=0;n<t.length;n++)t[n]!=null&&(t[n].hasValidRowNumber()||this.adjustRowNumbers(e,n,t))}return e}adjustRowNumbersByRow(){return this.adjustRowNumbersFromBothRI(),this.adjustRowNumbersFromLRI()+this.adjustRowNumbersFromRRI()}adjustRowNumbersFromBothRI(){if(this.detectionResultColumns[0]==null||this.detectionResultColumns[this.barcodeColumnCount+1]==null)return;let e=this.detectionResultColumns[0].getCodewords(),t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<e.length;n++)if(e[n]!=null&&t[n]!=null&&e[n].getRowNumber()===t[n].getRowNumber())for(let t=1;t<=this.barcodeColumnCount;t++){let r=this.detectionResultColumns[t].getCodewords()[n];r!=null&&(r.setRowNumber(e[n].getRowNumber()),r.hasValidRowNumber()||(this.detectionResultColumns[t].getCodewords()[n]=null))}}adjustRowNumbersFromRRI(){if(this.detectionResultColumns[this.barcodeColumnCount+1]==null)return 0;let e=0,t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=this.barcodeColumnCount+1;t>0&&i<this.ADJUST_ROW_NUMBER_SKIP;t--){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=rn.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}adjustRowNumbersFromLRI(){if(this.detectionResultColumns[0]==null)return 0;let e=0,t=this.detectionResultColumns[0].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=1;t<this.barcodeColumnCount+1&&i<this.ADJUST_ROW_NUMBER_SKIP;t++){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=rn.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}static adjustRowNumberIfValid(e,t,n){return n==null||n.hasValidRowNumber()||(n.isValidRowNumber(e)?(n.setRowNumber(e),t=0):++t),t}adjustRowNumbers(e,t,n){if(!this.detectionResultColumns[e-1])return;let r=n[t],i=this.detectionResultColumns[e-1].getCodewords(),a=i;this.detectionResultColumns[e+1]!=null&&(a=this.detectionResultColumns[e+1].getCodewords());let o=Array(14);o[2]=i[t],o[3]=a[t],t>0&&(o[0]=n[t-1],o[4]=i[t-1],o[5]=a[t-1]),t>1&&(o[8]=n[t-2],o[10]=i[t-2],o[11]=a[t-2]),t<n.length-1&&(o[1]=n[t+1],o[6]=i[t+1],o[7]=a[t+1]),t<n.length-2&&(o[9]=n[t+2],o[12]=i[t+2],o[13]=a[t+2]);for(let e of o)if(rn.adjustRowNumber(r,e))return}static adjustRowNumber(e,t){return t==null?!1:t.hasValidRowNumber()&&t.getBucket()===e.getBucket()?(e.setRowNumber(t.getRowNumber()),!0):!1}getBarcodeColumnCount(){return this.barcodeColumnCount}getBarcodeRowCount(){return this.barcodeMetadata.getRowCount()}getBarcodeECLevel(){return this.barcodeMetadata.getErrorCorrectionLevel()}setBoundingBox(e){this.boundingBox=e}getBoundingBox(){return this.boundingBox}setDetectionResultColumn(e,t){this.detectionResultColumns[e]=t}getDetectionResultColumn(e){return this.detectionResultColumns[e]}toString(){let e=this.detectionResultColumns[0];e??=this.detectionResultColumns[this.barcodeColumnCount+1];let t=new $t;for(let n=0;n<e.getCodewords().length;n++){t.format(`CW %3d:`,n);for(let e=0;e<this.barcodeColumnCount+2;e++){if(this.detectionResultColumns[e]==null){t.format(` | `);continue}let r=this.detectionResultColumns[e].getCodewords()[n];if(r==null){t.format(` | `);continue}t.format(` %3d|%3d`,r.getRowNumber(),r.getValue())}t.format(`%n`)}return t.toString()}}class an{constructor(e,t,n,r){this.rowNumber=an.BARCODE_ROW_UNKNOWN,this.startX=Math.trunc(e),this.endX=Math.trunc(t),this.bucket=Math.trunc(n),this.value=Math.trunc(r)}hasValidRowNumber(){return this.isValidRowNumber(this.rowNumber)}isValidRowNumber(e){return e!==an.BARCODE_ROW_UNKNOWN&&this.bucket===e%3*3}setRowNumberAsRowIndicatorColumn(){this.rowNumber=Math.trunc(Math.trunc(this.value/30)*3+Math.trunc(this.bucket/3))}getWidth(){return this.endX-this.startX}getStartX(){return this.startX}getEndX(){return this.endX}getBucket(){return this.bucket}getValue(){return this.value}getRowNumber(){return this.rowNumber}setRowNumber(e){this.rowNumber=e}toString(){return this.rowNumber+`|`+this.value}}an.BARCODE_ROW_UNKNOWN=-1;class on{static initialize(){for(let e=0;e<Wt.SYMBOL_TABLE.length;e++){let t=Wt.SYMBOL_TABLE[e],n=t&1;for(let r=0;r<Wt.BARS_IN_MODULE;r++){let i=0;for(;(t&1)===n;)i+=1,t>>=1;n=t&1,on.RATIOS_TABLE[e]||(on.RATIOS_TABLE[e]=Array(Wt.BARS_IN_MODULE)),on.RATIOS_TABLE[e][Wt.BARS_IN_MODULE-r-1]=Math.fround(i/Wt.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let t=on.getDecodedCodewordValue(on.sampleBitCounts(e));return t===-1?on.getClosestDecodedValue(e):t}static sampleBitCounts(e){let t=de.sum(e),n=new Int32Array(Wt.BARS_IN_MODULE),r=0,i=0;for(let a=0;a<Wt.MODULES_IN_CODEWORD;a++){let o=t/(2*Wt.MODULES_IN_CODEWORD)+a*t/Wt.MODULES_IN_CODEWORD;i+e[r]<=o&&(i+=e[r],r++),n[r]++}return n}static getDecodedCodewordValue(e){let t=on.getBitValue(e);return Wt.getCodeword(t)===-1?-1:t}static getBitValue(e){let t=0;for(let n=0;n<e.length;n++)for(let r=0;r<e[n];r++)t=t<<1|n%2==0;return Math.trunc(t)}static getClosestDecodedValue(e){let t=de.sum(e),n=Array(Wt.BARS_IN_MODULE);if(t>1)for(let r=0;r<n.length;r++)n[r]=Math.fround(e[r]/t);let r=fe.MAX_VALUE,i=-1;this.bSymbolTableReady||on.initialize();for(let e=0;e<on.RATIOS_TABLE.length;e++){let t=0,a=on.RATIOS_TABLE[e];for(let e=0;e<Wt.BARS_IN_MODULE;e++){let i=Math.fround(a[e]-n[e]);if(t+=Math.fround(i*i),t>=r)break}t<r&&(r=t,i=Wt.SYMBOL_TABLE[e])}return i}}on.bSymbolTableReady=!1,on.RATIOS_TABLE=Array(Wt.SYMBOL_TABLE.length).map(e=>e=Array(Wt.BARS_IN_MODULE));class sn{constructor(){this.segmentCount=-1,this.fileSize=-1,this.timestamp=-1,this.checksum=-1}getSegmentIndex(){return this.segmentIndex}setSegmentIndex(e){this.segmentIndex=e}getFileId(){return this.fileId}setFileId(e){this.fileId=e}getOptionalData(){return this.optionalData}setOptionalData(e){this.optionalData=e}isLastSegment(){return this.lastSegment}setLastSegment(e){this.lastSegment=e}getSegmentCount(){return this.segmentCount}setSegmentCount(e){this.segmentCount=e}getSender(){return this.sender||null}setSender(e){this.sender=e}getAddressee(){return this.addressee||null}setAddressee(e){this.addressee=e}getFileName(){return this.fileName}setFileName(e){this.fileName=e}getFileSize(){return this.fileSize}setFileSize(e){this.fileSize=e}getChecksum(){return this.checksum}setChecksum(e){this.checksum=e}getTimestamp(){return this.timestamp}setTimestamp(e){this.timestamp=e}}class cn{static parseLong(e,t=void 0){return parseInt(e,t)}}class ln extends s{}ln.kind=`NullPointerException`;class un{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,t,n){if(e==null)throw new ln;if(t<0||t>e.length||n<0||t+n>e.length||t+n<0)throw new m;if(n!==0)for(let r=0;r<n;r++)this.write(e[t+r])}flush(){}close(){}}class dn extends s{}class fn extends un{constructor(e=32){if(super(),this.count=0,e<0)throw new l(`Negative initial size: `+e);this.buf=new Uint8Array(e)}ensureCapacity(e){e-this.buf.length>0&&this.grow(e)}grow(e){let t=this.buf.length<<1;if(t-e<0&&(t=e),t<0){if(e<0)throw new dn;t=_.MAX_VALUE}this.buf=g.copyOfUint8Array(this.buf,t)}write(e){this.ensureCapacity(this.count+1),this.buf[this.count]=e,this.count+=1}writeBytesOffset(e,t,n){if(t<0||t>e.length||n<0||t+n-e.length>0)throw new m;this.ensureCapacity(this.count+n),p.arraycopy(e,t,this.buf,this.count,n),this.count+=n}writeTo(e){e.writeBytesOffset(this.buf,0,this.count)}reset(){this.count=0}toByteArray(){return g.copyOfUint8Array(this.buf,this.count)}size(){return this.count}toString(e){return e?typeof e==`string`?this.toString_string(e):this.toString_number(e):this.toString_void()}toString_void(){return new String(this.buf).toString()}toString_string(e){return new String(this.buf).toString()}toString_number(e){return new String(this.buf).toString()}close(){}}var pn;(function(e){e[e.ALPHA=0]=`ALPHA`,e[e.LOWER=1]=`LOWER`,e[e.MIXED=2]=`MIXED`,e[e.PUNCT=3]=`PUNCT`,e[e.ALPHA_SHIFT=4]=`ALPHA_SHIFT`,e[e.PUNCT_SHIFT=5]=`PUNCT_SHIFT`})(pn||={});function mn(){if(typeof window<`u`)return window.BigInt||null;if(typeof global<`u`)return global.BigInt||null;if(typeof self<`u`)return self.BigInt||null;throw Error(`Can't search globals for BigInt!`)}let hn;function gn(e){if(hn===void 0&&(hn=mn()),hn===null)throw Error(`BigInt is not supported!`);return hn(e)}function _n(){let e=[];e[0]=gn(1);let t=gn(900);e[1]=t;for(let n=2;n<16;n++)e[n]=e[n-1]*t;return e}class J{static decode(e,t){let n=new D(``),r=C.ISO8859_1;n.enableDecoding(r);let i=1,a=e[i++],o=new sn;for(;i<e[0];){switch(a){case J.TEXT_COMPACTION_MODE_LATCH:i=J.textCompaction(e,i,n);break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:i=J.byteCompaction(a,e,r,i,n);break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:n.append(e[i++]);break;case J.NUMERIC_COMPACTION_MODE_LATCH:i=J.numericCompaction(e,i,n);break;case J.ECI_CHARSET:C.getCharacterSetECIByValue(e[i++]);break;case J.ECI_GENERAL_PURPOSE:i+=2;break;case J.ECI_USER_DEFINED:i++;break;case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:i=J.decodeMacroBlock(e,i,o);break;case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:throw new x;default:i--,i=J.textCompaction(e,i,n);break}if(i<e.length)a=e[i++];else throw x.getFormatInstance()}if(n.length()===0)throw x.getFormatInstance();let s=new re(null,n.toString(),null,t);return s.setOther(o),s}static decodeMacroBlock(e,t,n){if(t+J.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw x.getFormatInstance();let r=new Int32Array(J.NUMBER_OF_SEQUENCE_CODEWORDS);for(let n=0;n<J.NUMBER_OF_SEQUENCE_CODEWORDS;n++,t++)r[n]=e[t];n.setSegmentIndex(_.parseInt(J.decodeBase900toBase10(r,J.NUMBER_OF_SEQUENCE_CODEWORDS)));let i=new D;t=J.textCompaction(e,t,i),n.setFileId(i.toString());let a=-1;for(e[t]===J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(a=t+1);t<e[0];)switch(e[t]){case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(t++,e[t]){case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let r=new D;t=J.textCompaction(e,t+1,r),n.setFileName(r.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let i=new D;t=J.textCompaction(e,t+1,i),n.setSender(i.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let a=new D;t=J.textCompaction(e,t+1,a),n.setAddressee(a.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let o=new D;t=J.numericCompaction(e,t+1,o),n.setSegmentCount(_.parseInt(o.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let s=new D;t=J.numericCompaction(e,t+1,s),n.setTimestamp(cn.parseLong(s.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let c=new D;t=J.numericCompaction(e,t+1,c),n.setChecksum(_.parseInt(c.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let l=new D;t=J.numericCompaction(e,t+1,l),n.setFileSize(cn.parseLong(l.toString()));break;default:throw x.getFormatInstance()}break;case J.MACRO_PDF417_TERMINATOR:t++,n.setLastSegment(!0);break;default:throw x.getFormatInstance()}if(a!==-1){let r=t-a;n.isLastSegment()&&r--,n.setOptionalData(g.copyOfRange(e,a,a+r))}return t}static textCompaction(e,t,n){let r=new Int32Array((e[0]-t)*2),i=new Int32Array((e[0]-t)*2),a=0,o=!1;for(;t<e[0]&&!o;){let n=e[t++];if(n<J.TEXT_COMPACTION_MODE_LATCH)r[a]=n/30,r[a+1]=n%30,a+=2;else switch(n){case J.TEXT_COMPACTION_MODE_LATCH:r[a++]=J.TEXT_COMPACTION_MODE_LATCH;break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:t--,o=!0;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r[a]=J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,n=e[t++],i[a]=n,a++;break}}return J.decodeTextCompaction(r,i,a,n),t}static decodeTextCompaction(e,t,n,r){let i=pn.ALPHA,a=pn.ALPHA,o=0;for(;o<n;){let n=e[o],s=``;switch(i){case pn.ALPHA:if(n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case J.LL:i=pn.LOWER;break;case J.ML:i=pn.MIXED;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.LOWER:if(n<26)s=String.fromCharCode(97+n);else switch(n){case 26:s=` `;break;case J.AS:a=i,i=pn.ALPHA_SHIFT;break;case J.ML:i=pn.MIXED;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.MIXED:if(n<J.PL)s=J.MIXED_CHARS[n];else switch(n){case J.PL:i=pn.PUNCT;break;case 26:s=` `;break;case J.LL:i=pn.LOWER;break;case J.AL:i=pn.ALPHA;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.PUNCT:if(n<J.PAL)s=J.PUNCT_CHARS[n];else switch(n){case J.PAL:i=pn.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.ALPHA_SHIFT:if(i=a,n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.PUNCT_SHIFT:if(i=a,n<J.PAL)s=J.PUNCT_CHARS[n];else switch(n){case J.PAL:i=pn.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break}s!==``&&r.append(s),o++}}static byteCompaction(e,t,n,r,i){let a=new fn,o=0,s=0,c=!1;switch(e){case J.BYTE_COMPACTION_MODE_LATCH:let e=new Int32Array(6),n=t[r++];for(;r<t[0]&&!c;)switch(e[o++]=n,s=900*s+n,n=t[r++],n){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:r--,c=!0;break;default:if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(gn(s)>>gn(8*(5-e))));s=0,o=0}break}r===t[0]&&n<J.TEXT_COMPACTION_MODE_LATCH&&(e[o++]=n);for(let t=0;t<o;t++)a.write(e[t]);break;case J.BYTE_COMPACTION_MODE_LATCH_6:for(;r<t[0]&&!c;){let e=t[r++];if(e<J.TEXT_COMPACTION_MODE_LATCH)o++,s=900*s+e;else switch(e){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:r--,c=!0;break}if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(gn(s)>>gn(8*(5-e))));s=0,o=0}}break}return i.append(T.decode(a.toByteArray(),n)),r}static numericCompaction(e,t,n){let r=0,i=!1,a=new Int32Array(J.MAX_NUMERIC_CODEWORDS);for(;t<e[0]&&!i;){let o=e[t++];if(t===e[0]&&(i=!0),o<J.TEXT_COMPACTION_MODE_LATCH)a[r]=o,r++;else switch(o){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:t--,i=!0;break}(r%J.MAX_NUMERIC_CODEWORDS===0||o===J.NUMERIC_COMPACTION_MODE_LATCH||i)&&r>0&&(n.append(J.decodeBase900toBase10(a,r)),r=0)}return t}static decodeBase900toBase10(e,t){let n=gn(0);for(let r=0;r<t;r++)n+=J.EXP900[t-r-1]*gn(e[r]);let r=n.toString();if(r.charAt(0)!==`1`)throw new x;return r.substring(1)}}J.TEXT_COMPACTION_MODE_LATCH=900,J.BYTE_COMPACTION_MODE_LATCH=901,J.NUMERIC_COMPACTION_MODE_LATCH=902,J.BYTE_COMPACTION_MODE_LATCH_6=924,J.ECI_USER_DEFINED=925,J.ECI_GENERAL_PURPOSE=926,J.ECI_CHARSET=927,J.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,J.MACRO_PDF417_TERMINATOR=922,J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,J.MAX_NUMERIC_CODEWORDS=15,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,J.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,J.PL=25,J.LL=27,J.AS=27,J.ML=28,J.AL=28,J.PS=29,J.PAL=29,J.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
58
+ -.$/"|*()?{}'`,J.MIXED_CHARS=`0123456789&\r ,:#-.$/+%*=^`,J.EXP900=mn()?_n():[],J.NUMBER_OF_SEQUENCE_CODEWORDS=2;class vn{constructor(){}static decode(e,t,n,r,i,a,o){let s=new Zt(e,t,n,r,i),c=null,l=null,u;for(let n=!0;;n=!1){if(t!=null&&(c=vn.getRowIndicatorColumn(e,s,t,!0,a,o)),r!=null&&(l=vn.getRowIndicatorColumn(e,s,r,!1,a,o)),u=vn.merge(c,l),u==null)throw k.getNotFoundInstance();let i=u.getBoundingBox();if(n&&i!=null&&(i.getMinY()<s.getMinY()||i.getMaxY()>s.getMaxY()))s=i;else break}u.setBoundingBox(s);let d=u.getBarcodeColumnCount()+1;u.setDetectionResultColumn(0,c),u.setDetectionResultColumn(d,l);let f=c!=null;for(let t=1;t<=d;t++){let n=f?t:d-t;if(u.getDetectionResultColumn(n)!==void 0)continue;let r;r=n===0||n===d?new nn(s,n===0):new en(s),u.setDetectionResultColumn(n,r);let i=-1,c=i;for(let t=s.getMinY();t<=s.getMaxY();t++){if(i=vn.getStartColumn(u,n,t,f),i<0||i>s.getMaxX()){if(c===-1)continue;i=c}let l=vn.detectCodeword(e,s.getMinX(),s.getMaxX(),f,i,t,a,o);l!=null&&(r.setCodeword(t,l),c=i,a=Math.min(a,l.getWidth()),o=Math.max(o,l.getWidth()))}}return vn.createDecoderResult(u)}static merge(e,t){if(e==null&&t==null)return null;let n=vn.getBarcodeMetadata(e,t);return n==null?null:new rn(n,Zt.merge(vn.adjustBoundingBox(e),vn.adjustBoundingBox(t)))}static adjustBoundingBox(e){if(e==null)return null;let t=e.getRowHeights();if(t==null)return null;let n=vn.getMax(t),r=0;for(let e of t)if(r+=n-e,e>0)break;let i=e.getCodewords();for(let e=0;r>0&&i[e]==null;e++)r--;let a=0;for(let e=t.length-1;e>=0&&(a+=n-t[e],!(t[e]>0));e--);for(let e=i.length-1;a>0&&i[e]==null;e--)a--;return e.getBoundingBox().addMissingRows(r,a,e.isLeft())}static getMax(e){let t=-1;for(let n of e)t=Math.max(t,n);return t}static getBarcodeMetadata(e,t){let n;if(e==null||(n=e.getBarcodeMetadata())==null)return t==null?null:t.getBarcodeMetadata();let r;return t==null||(r=t.getBarcodeMetadata())==null?n:n.getColumnCount()!==r.getColumnCount()&&n.getErrorCorrectionLevel()!==r.getErrorCorrectionLevel()&&n.getRowCount()!==r.getRowCount()?null:n}static getRowIndicatorColumn(e,t,n,r,i,a){let o=new nn(t,r);for(let s=0;s<2;s++){let c=s===0?1:-1,l=Math.trunc(Math.trunc(n.getX()));for(let s=Math.trunc(Math.trunc(n.getY()));s<=t.getMaxY()&&s>=t.getMinY();s+=c){let t=vn.detectCodeword(e,0,e.getWidth(),r,l,s,i,a);t!=null&&(o.setCodeword(s,t),l=r?t.getStartX():t.getEndX())}}return o}static adjustCodewordCount(e,t){let n=t[0][1],r=n.getValue(),i=e.getBarcodeColumnCount()*e.getBarcodeRowCount()-vn.getNumberOfECCodeWords(e.getBarcodeECLevel());if(r.length===0){if(i<1||i>Wt.MAX_CODEWORDS_IN_BARCODE)throw k.getNotFoundInstance();n.setValue(i)}else r[0]!==i&&n.setValue(i)}static createDecoderResult(e){let t=vn.createBarcodeMatrix(e);vn.adjustCodewordCount(e,t);let n=[],r=new Int32Array(e.getBarcodeRowCount()*e.getBarcodeColumnCount()),i=[],a=[];for(let o=0;o<e.getBarcodeRowCount();o++)for(let s=0;s<e.getBarcodeColumnCount();s++){let c=t[o][s+1].getValue(),l=o*e.getBarcodeColumnCount()+s;c.length===0?n.push(l):c.length===1?r[l]=c[0]:(a.push(l),i.push(c))}let o=Array(i.length);for(let e=0;e<o.length;e++)o[e]=i[e];return vn.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),r,Wt.toIntArray(n),Wt.toIntArray(a),o)}static createDecoderResultFromAmbiguousValues(e,t,n,r,i){let a=new Int32Array(r.length),o=100;for(;o-- >0;){for(let e=0;e<a.length;e++)t[r[e]]=i[e][a[e]];try{return vn.decodeCodewords(t,e,n)}catch(e){if(!(e instanceof d))throw e}if(a.length===0)throw d.getChecksumInstance();for(let e=0;e<a.length;e++)if(a[e]<i[e].length-1){a[e]++;break}else if(a[e]=0,e===a.length-1)throw d.getChecksumInstance()}throw d.getChecksumInstance()}static createBarcodeMatrix(e){let t=Array.from({length:e.getBarcodeRowCount()},()=>Array(e.getBarcodeColumnCount()+2));for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length;n++)t[e][n]=new tn;let n=0;for(let r of e.getDetectionResultColumns()){if(r!=null){for(let e of r.getCodewords())if(e!=null){let r=e.getRowNumber();if(r>=0){if(r>=t.length)continue;t[r][n].setValue(e.getValue())}}}n++}return t}static isValidBarcodeColumn(e,t){return t>=0&&t<=e.getBarcodeColumnCount()+1}static getStartColumn(e,t,n,r){let i=r?1:-1,a=null;if(vn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodeword(n)),a!=null)return r?a.getEndX():a.getStartX();if(a=e.getDetectionResultColumn(t).getCodewordNearby(n),a!=null)return r?a.getStartX():a.getEndX();if(vn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodewordNearby(n)),a!=null)return r?a.getEndX():a.getStartX();let o=0;for(;vn.isValidBarcodeColumn(e,t-i);){t-=i;for(let n of e.getDetectionResultColumn(t).getCodewords())if(n!=null)return(r?n.getEndX():n.getStartX())+i*o*(n.getEndX()-n.getStartX());o++}return r?e.getBoundingBox().getMinX():e.getBoundingBox().getMaxX()}static detectCodeword(e,t,n,r,i,a,o,s){i=vn.adjustCodewordStartColumn(e,t,n,r,i,a);let c=vn.getModuleBitCount(e,t,n,r,i,a);if(c==null)return null;let l,u=de.sum(c);if(r)l=i+u;else{for(let e=0;e<c.length/2;e++){let t=c[e];c[e]=c[c.length-1-e],c[c.length-1-e]=t}l=i,i=l-u}if(!vn.checkCodewordSkew(u,o,s))return null;let d=on.getDecodedValue(c),f=Wt.getCodeword(d);return f===-1?null:new an(i,l,vn.getCodewordBucketNumber(d),f)}static getModuleBitCount(e,t,n,r,i,a){let o=i,s=new Int32Array(8),c=0,l=r?1:-1,u=r;for(;(r?o<n:o>=t)&&c<s.length;)e.get(o,a)===u?(s[c]++,o+=l):(c++,u=!u);return c===s.length||o===(r?n:t)&&c===s.length-1?s:null}static getNumberOfECCodeWords(e){return 2<<e}static adjustCodewordStartColumn(e,t,n,r,i,a){let o=i,s=r?-1:1;for(let c=0;c<2;c++){for(;(r?o>=t:o<n)&&r===e.get(o,a);){if(Math.abs(i-o)>vn.CODEWORD_SKEW_SIZE)return i;o+=s}s=-s,r=!r}return o}static checkCodewordSkew(e,t,n){return t-vn.CODEWORD_SKEW_SIZE<=e&&e<=n+vn.CODEWORD_SKEW_SIZE}static decodeCodewords(e,t,n){if(e.length===0)throw x.getFormatInstance();let r=1<<t+1,i=vn.correctErrors(e,n,r);vn.verifyCodewordCount(e,r);let a=J.decode(e,``+t);return a.setErrorsCorrected(i),a.setErasures(n.length),a}static correctErrors(e,t,n){if(t!=null&&t.length>n/2+vn.MAX_ERRORS||n<0||n>vn.MAX_EC_CODEWORDS)throw d.getChecksumInstance();return vn.errorCorrection.decode(e,n,t)}static verifyCodewordCount(e,t){if(e.length<4)throw x.getFormatInstance();let n=e[0];if(n>e.length)throw x.getFormatInstance();if(n===0)if(t<e.length)e[0]=e.length-t;else throw x.getFormatInstance()}static getBitCountForCodeword(e){let t=new Int32Array(8),n=0,r=t.length-1;for(;!((e&1)!==n&&(n=e&1,r--,r<0));)t[r]++,e>>=1;return t}static getCodewordBucketNumber(e){return e instanceof Int32Array?this.getCodewordBucketNumber_Int32Array(e):this.getCodewordBucketNumber_number(e)}static getCodewordBucketNumber_number(e){return vn.getCodewordBucketNumber(vn.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let t=new $t;for(let n=0;n<e.length;n++){t.format(`Row %2d: `,n);for(let r=0;r<e[n].length;r++){let i=e[n][r];i.getValue().length===0?t.format(` `,null):t.format(`%4d(%2d)`,i.getValue()[0],i.getConfidence(i.getValue()[0]))}t.format(`%n`)}return t.toString()}}vn.CODEWORD_SKEW_SIZE=2,vn.MAX_ERRORS=3,vn.MAX_EC_CODEWORDS=512,vn.errorCorrection=new Xt;class yn{decode(e,t=null){let n=yn.decode(e,t,!1);if(n==null||n.length===0||n[0]==null)throw k.getNotFoundInstance();return n[0]}decodeMultiple(e,t=null){try{return yn.decode(e,t,!0)}catch(e){throw e instanceof x||e instanceof d?k.getNotFoundInstance():e}}static decode(e,t,n){let r=[],i=Kt.detectMultiple(e,t,n);for(let e of i.getPoints()){let t=vn.decode(i.getBits(),e[4],e[5],e[6],e[7],yn.getMinCodewordWidth(e),yn.getMaxCodewordWidth(e)),n=new R(t.getText(),t.getRawBytes(),void 0,e,z.PDF_417);n.putMetadata(ne.ERROR_CORRECTION_LEVEL,t.getECLevel());let a=t.getOther();a!=null&&n.putMetadata(ne.PDF417_EXTRA_METADATA,a),r.push(n)}return r.map(e=>e)}static getMaxWidth(e,t){return e==null||t==null?0:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMinWidth(e,t){return e==null||t==null?_.MAX_VALUE:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMaxCodewordWidth(e){return Math.floor(Math.max(Math.max(yn.getMaxWidth(e[0],e[4]),yn.getMaxWidth(e[6],e[2])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN),Math.max(yn.getMaxWidth(e[1],e[5]),yn.getMaxWidth(e[7],e[3])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(yn.getMinWidth(e[0],e[4]),yn.getMinWidth(e[6],e[2])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN),Math.min(yn.getMinWidth(e[1],e[5]),yn.getMinWidth(e[7],e[3])*Wt.MODULES_IN_CODEWORD/Wt.MODULES_IN_STOP_PATTERN)))}reset(){}}class bn extends s{}bn.kind=`ReaderException`;class xn{constructor(e,t){this.verbose=e===!0,t&&this.setHints(t)}decode(e,t){return t&&this.setHints(t),this.decodeInternal(e)}decodeWithState(e){return(this.readers===null||this.readers===void 0)&&this.setHints(null),this.decodeInternal(e)}setHints(e){this.hints=e;let n=!t(e)&&e.get(b.TRY_HARDER)===!0,r=t(e)?null:e.get(b.POSSIBLE_FORMATS),i=[];if(!t(r)){let t=r.some(e=>e===z.UPC_A||e===z.UPC_E||e===z.EAN_13||e===z.EAN_8||e===z.CODABAR||e===z.CODE_39||e===z.CODE_93||e===z.CODE_128||e===z.ITF||e===z.RSS_14||e===z.RSS_EXPANDED);t&&!n&&i.push(new ut(e,this.verbose)),r.includes(z.QR_CODE)&&i.push(new Ut),r.includes(z.DATA_MATRIX)&&i.push(new St),r.includes(z.AZTEC)&&i.push(new xe),r.includes(z.PDF_417)&&i.push(new yn),t&&n&&i.push(new ut(e,this.verbose))}i.length===0&&(n||i.push(new ut(e,this.verbose)),i.push(new Ut),i.push(new St),i.push(new xe),i.push(new yn),n&&i.push(new ut(e,this.verbose))),this.readers=i}reset(){if(this.readers!==null)for(let e of this.readers)e.reset()}decodeInternal(e){if(this.readers===null)throw new bn(`No readers where selected, nothing can be read.`);for(let t of this.readers)try{return t.decode(e,this.hints)}catch(e){if(e instanceof bn)continue}throw new k(`No MultiFormat Readers were able to detect the code.`)}}class Sn extends L{constructor(e=null,t=500){let n=new xn;n.setHints(e),super(n,t)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class Cn extends L{constructor(e=500){super(new yn,e)}}class wn extends L{constructor(e=500){super(new Ut,e)}}var Tn;(function(e){e[e.ERROR_CORRECTION=0]=`ERROR_CORRECTION`,e[e.CHARACTER_SET=1]=`CHARACTER_SET`,e[e.DATA_MATRIX_SHAPE=2]=`DATA_MATRIX_SHAPE`,e[e.MIN_SIZE=3]=`MIN_SIZE`,e[e.MAX_SIZE=4]=`MAX_SIZE`,e[e.MARGIN=5]=`MARGIN`,e[e.PDF417_COMPACT=6]=`PDF417_COMPACT`,e[e.PDF417_COMPACTION=7]=`PDF417_COMPACTION`,e[e.PDF417_DIMENSIONS=8]=`PDF417_DIMENSIONS`,e[e.AZTEC_LAYERS=9]=`AZTEC_LAYERS`,e[e.QR_VERSION=10]=`QR_VERSION`})(Tn||={});var En=Tn;class Dn{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new B(e,Int32Array.from([1])))}buildGenerator(e){let t=this.cachedGenerators;if(e>=t.length){let n=t[t.length-1],r=this.field;for(let i=t.length;i<=e;i++){let e=n.multiply(new B(r,Int32Array.from([1,r.exp(i-1+r.getGeneratorBase())])));t.push(e),n=e}}return t[e]}encode(e,t){if(t===0)throw new l(`No error correction bytes`);let n=e.length-t;if(n<=0)throw new l(`No data bytes provided`);let r=this.buildGenerator(t),i=new Int32Array(n);p.arraycopy(e,0,i,0,n);let a=new B(this.field,i);a=a.multiplyByMonomial(t,1);let o=a.divide(r)[1].getCoefficients(),s=t-o.length;for(let t=0;t<s;t++)e[n+t]=0;p.arraycopy(o,0,e,n+s,o.length)}}class On{constructor(){}static applyMaskPenaltyRule1(e){return On.applyMaskPenaltyRule1Internal(e,!0)+On.applyMaskPenaltyRule1Internal(e,!1)}static applyMaskPenaltyRule2(e){let t=0,n=e.getArray(),r=e.getWidth(),i=e.getHeight();for(let e=0;e<i-1;e++){let i=n[e];for(let a=0;a<r-1;a++){let r=i[a];r===i[a+1]&&r===n[e+1][a]&&r===n[e+1][a+1]&&t++}}return On.N2*t}static applyMaskPenaltyRule3(e){let t=0,n=e.getArray(),r=e.getWidth(),i=e.getHeight();for(let e=0;e<i;e++)for(let a=0;a<r;a++){let o=n[e];a+6<r&&o[a]===1&&o[a+1]===0&&o[a+2]===1&&o[a+3]===1&&o[a+4]===1&&o[a+5]===0&&o[a+6]===1&&(On.isWhiteHorizontal(o,a-4,a)||On.isWhiteHorizontal(o,a+7,a+11))&&t++,e+6<i&&n[e][a]===1&&n[e+1][a]===0&&n[e+2][a]===1&&n[e+3][a]===1&&n[e+4][a]===1&&n[e+5][a]===0&&n[e+6][a]===1&&(On.isWhiteVertical(n,a,e-4,e)||On.isWhiteVertical(n,a,e+7,e+11))&&t++}return t*On.N3}static isWhiteHorizontal(e,t,n){t=Math.max(t,0),n=Math.min(n,e.length);for(let r=t;r<n;r++)if(e[r]===1)return!1;return!0}static isWhiteVertical(e,t,n,r){n=Math.max(n,0),r=Math.min(r,e.length);for(let i=n;i<r;i++)if(e[i][t]===1)return!1;return!0}static applyMaskPenaltyRule4(e){let t=0,n=e.getArray(),r=e.getWidth(),i=e.getHeight();for(let e=0;e<i;e++){let i=n[e];for(let e=0;e<r;e++)i[e]===1&&t++}let a=e.getHeight()*e.getWidth();return Math.floor(Math.abs(t*2-a)*10/a)*On.N4}static getDataMaskBit(e,t,n){let r,i;switch(e){case 0:r=n+t&1;break;case 1:r=n&1;break;case 2:r=t%3;break;case 3:r=(n+t)%3;break;case 4:r=Math.floor(n/2)+Math.floor(t/3)&1;break;case 5:i=n*t,r=(i&1)+i%3;break;case 6:i=n*t,r=(i&1)+i%3&1;break;case 7:i=n*t,r=i%3+(n+t&1)&1;break;default:throw new l(`Invalid mask pattern: `+e)}return r===0}static applyMaskPenaltyRule1Internal(e,t){let n=0,r=t?e.getHeight():e.getWidth(),i=t?e.getWidth():e.getHeight(),a=e.getArray();for(let e=0;e<r;e++){let r=0,o=-1;for(let s=0;s<i;s++){let i=t?a[e][s]:a[s][e];i===o?r++:(r>=5&&(n+=On.N1+(r-5)),r=1,o=i)}r>=5&&(n+=On.N1+(r-5))}return n}}On.N1=3,On.N2=3,On.N3=40,On.N4=10;class kn{constructor(e,t){this.width=e,this.height=t;let n=Array(t);for(let r=0;r!==t;r++)n[r]=new Uint8Array(e);this.bytes=n}getHeight(){return this.height}getWidth(){return this.width}get(e,t){return this.bytes[t][e]}getArray(){return this.bytes}setNumber(e,t,n){this.bytes[t][e]=n}setBoolean(e,t,n){this.bytes[t][e]=+!!n}clear(e){for(let t of this.bytes)g.fill(t,e)}equals(e){if(!(e instanceof kn))return!1;let t=e;if(this.width!==t.width||this.height!==t.height)return!1;for(let e=0,n=this.height;e<n;++e){let n=this.bytes[e],r=t.bytes[e];for(let e=0,t=this.width;e<t;++e)if(n[e]!==r[e])return!1}return!0}toString(){let e=new D;for(let t=0,n=this.height;t<n;++t){let n=this.bytes[t];for(let t=0,r=this.width;t<r;++t)switch(n[t]){case 0:e.append(` 0`);break;case 1:e.append(` 1`);break;default:e.append(` `);break}e.append(`
59
+ `)}return e.toString()}}class An{constructor(){this.maskPattern=-1}getMode(){return this.mode}getECLevel(){return this.ecLevel}getVersion(){return this.version}getMaskPattern(){return this.maskPattern}getMatrix(){return this.matrix}toString(){let e=new D;return e.append(`<<
60
+ `),e.append(` mode: `),e.append(this.mode?this.mode.toString():`null`),e.append(`
61
+ ecLevel: `),e.append(this.ecLevel?this.ecLevel.toString():`null`),e.append(`
62
+ version: `),e.append(this.version?this.version.toString():`null`),e.append(`
63
+ maskPattern: `),e.append(this.maskPattern.toString()),this.matrix?(e.append(`
64
+ matrix:
65
+ `),e.append(this.matrix.toString())):e.append(`
66
+ matrix: null
67
+ `),e.append(`>>
68
+ `),e.toString()}setMode(e){this.mode=e}setECLevel(e){this.ecLevel=e}setVersion(e){this.version=e}setMaskPattern(e){this.maskPattern=e}setMatrix(e){this.matrix=e}static isValidMaskPattern(e){return e>=0&&e<An.NUM_MASK_PATTERNS}}An.NUM_MASK_PATTERNS=8;class jn extends s{}jn.kind=`WriterException`;class Mn{constructor(){}static clearMatrix(e){e.clear(255)}static buildMatrix(e,t,n,r,i){Mn.clearMatrix(i),Mn.embedBasicPatterns(n,i),Mn.embedTypeInfo(t,r,i),Mn.maybeEmbedVersionInfo(n,i),Mn.embedDataBits(e,r,i)}static embedBasicPatterns(e,t){Mn.embedPositionDetectionPatternsAndSeparators(t),Mn.embedDarkDotAtLeftBottomCorner(t),Mn.maybeEmbedPositionAdjustmentPatterns(e,t),Mn.embedTimingPatterns(t)}static embedTypeInfo(e,t,n){let r=new v;Mn.makeTypeInfoBits(e,t,r);for(let e=0,t=r.getSize();e<t;++e){let t=r.get(r.getSize()-1-e),i=Mn.TYPE_INFO_COORDINATES[e],a=i[0],o=i[1];if(n.setBoolean(a,o,t),e<8){let r=n.getWidth()-e-1;n.setBoolean(r,8,t)}else{let r=n.getHeight()-7+(e-8);n.setBoolean(8,r,t)}}}static maybeEmbedVersionInfo(e,t){if(e.getVersionNumber()<7)return;let n=new v;Mn.makeVersionInfoBits(e,n);let r=17;for(let e=0;e<6;++e)for(let i=0;i<3;++i){let a=n.get(r);r--,t.setBoolean(e,t.getHeight()-11+i,a),t.setBoolean(t.getHeight()-11+i,e,a)}}static embedDataBits(e,t,n){let r=0,i=-1,a=n.getWidth()-1,o=n.getHeight()-1;for(;a>0;){for(a===6&&--a;o>=0&&o<n.getHeight();){for(let i=0;i<2;++i){let s=a-i;if(!Mn.isEmpty(n.get(s,o)))continue;let c;r<e.getSize()?(c=e.get(r),++r):c=!1,t!==255&&On.getDataMaskBit(t,s,o)&&(c=!c),n.setBoolean(s,o,c)}o+=i}i=-i,o+=i,a-=2}if(r!==e.getSize())throw new jn(`Not all bits consumed: `+r+`/`+e.getSize())}static findMSBSet(e){return 32-_.numberOfLeadingZeros(e)}static calculateBCHCode(e,t){if(t===0)throw new l(`0 polynomial`);let n=Mn.findMSBSet(t);for(e<<=n-1;Mn.findMSBSet(e)>=n;)e^=t<<Mn.findMSBSet(e)-n;return e}static makeTypeInfoBits(e,t,n){if(!An.isValidMaskPattern(t))throw new jn(`Invalid mask pattern`);let r=e.getBits()<<3|t;n.appendBits(r,5);let i=Mn.calculateBCHCode(r,Mn.TYPE_INFO_POLY);n.appendBits(i,10);let a=new v;if(a.appendBits(Mn.TYPE_INFO_MASK_PATTERN,15),n.xor(a),n.getSize()!==15)throw new jn(`should not happen but we got: `+n.getSize())}static makeVersionInfoBits(e,t){t.appendBits(e.getVersionNumber(),6);let n=Mn.calculateBCHCode(e.getVersionNumber(),Mn.VERSION_INFO_POLY);if(t.appendBits(n,12),t.getSize()!==18)throw new jn(`should not happen but we got: `+t.getSize())}static isEmpty(e){return e===255}static embedTimingPatterns(e){for(let t=8;t<e.getWidth()-8;++t){let n=(t+1)%2;Mn.isEmpty(e.get(t,6))&&e.setNumber(t,6,n),Mn.isEmpty(e.get(6,t))&&e.setNumber(6,t,n)}}static embedDarkDotAtLeftBottomCorner(e){if(e.get(8,e.getHeight()-8)===0)throw new jn;e.setNumber(8,e.getHeight()-8,1)}static embedHorizontalSeparationPattern(e,t,n){for(let r=0;r<8;++r){if(!Mn.isEmpty(n.get(e+r,t)))throw new jn;n.setNumber(e+r,t,0)}}static embedVerticalSeparationPattern(e,t,n){for(let r=0;r<7;++r){if(!Mn.isEmpty(n.get(e,t+r)))throw new jn;n.setNumber(e,t+r,0)}}static embedPositionAdjustmentPattern(e,t,n){for(let r=0;r<5;++r){let i=Mn.POSITION_ADJUSTMENT_PATTERN[r];for(let a=0;a<5;++a)n.setNumber(e+a,t+r,i[a])}}static embedPositionDetectionPattern(e,t,n){for(let r=0;r<7;++r){let i=Mn.POSITION_DETECTION_PATTERN[r];for(let a=0;a<7;++a)n.setNumber(e+a,t+r,i[a])}}static embedPositionDetectionPatternsAndSeparators(e){let t=Mn.POSITION_DETECTION_PATTERN[0].length;Mn.embedPositionDetectionPattern(0,0,e),Mn.embedPositionDetectionPattern(e.getWidth()-t,0,e),Mn.embedPositionDetectionPattern(0,e.getWidth()-t,e),Mn.embedHorizontalSeparationPattern(0,7,e),Mn.embedHorizontalSeparationPattern(e.getWidth()-8,7,e),Mn.embedHorizontalSeparationPattern(0,e.getWidth()-8,e),Mn.embedVerticalSeparationPattern(7,0,e),Mn.embedVerticalSeparationPattern(e.getHeight()-7-1,0,e),Mn.embedVerticalSeparationPattern(7,e.getHeight()-7,e)}static maybeEmbedPositionAdjustmentPatterns(e,t){if(e.getVersionNumber()<2)return;let n=e.getVersionNumber()-1,r=Mn.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[n];for(let e=0,n=r.length;e!==n;e++){let i=r[e];if(i>=0)for(let e=0;e!==n;e++){let n=r[e];n>=0&&Mn.isEmpty(t.get(n,i))&&Mn.embedPositionAdjustmentPattern(n-2,i-2,t)}}}}Mn.POSITION_DETECTION_PATTERN=Array.from([Int32Array.from([1,1,1,1,1,1,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,1,1,1,1,1,1])]),Mn.POSITION_ADJUSTMENT_PATTERN=Array.from([Int32Array.from([1,1,1,1,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,0,1,0,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,1,1,1,1])]),Mn.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE=Array.from([Int32Array.from([-1,-1,-1,-1,-1,-1,-1]),Int32Array.from([6,18,-1,-1,-1,-1,-1]),Int32Array.from([6,22,-1,-1,-1,-1,-1]),Int32Array.from([6,26,-1,-1,-1,-1,-1]),Int32Array.from([6,30,-1,-1,-1,-1,-1]),Int32Array.from([6,34,-1,-1,-1,-1,-1]),Int32Array.from([6,22,38,-1,-1,-1,-1]),Int32Array.from([6,24,42,-1,-1,-1,-1]),Int32Array.from([6,26,46,-1,-1,-1,-1]),Int32Array.from([6,28,50,-1,-1,-1,-1]),Int32Array.from([6,30,54,-1,-1,-1,-1]),Int32Array.from([6,32,58,-1,-1,-1,-1]),Int32Array.from([6,34,62,-1,-1,-1,-1]),Int32Array.from([6,26,46,66,-1,-1,-1]),Int32Array.from([6,26,48,70,-1,-1,-1]),Int32Array.from([6,26,50,74,-1,-1,-1]),Int32Array.from([6,30,54,78,-1,-1,-1]),Int32Array.from([6,30,56,82,-1,-1,-1]),Int32Array.from([6,30,58,86,-1,-1,-1]),Int32Array.from([6,34,62,90,-1,-1,-1]),Int32Array.from([6,28,50,72,94,-1,-1]),Int32Array.from([6,26,50,74,98,-1,-1]),Int32Array.from([6,30,54,78,102,-1,-1]),Int32Array.from([6,28,54,80,106,-1,-1]),Int32Array.from([6,32,58,84,110,-1,-1]),Int32Array.from([6,30,58,86,114,-1,-1]),Int32Array.from([6,34,62,90,118,-1,-1]),Int32Array.from([6,26,50,74,98,122,-1]),Int32Array.from([6,30,54,78,102,126,-1]),Int32Array.from([6,26,52,78,104,130,-1]),Int32Array.from([6,30,56,82,108,134,-1]),Int32Array.from([6,34,60,86,112,138,-1]),Int32Array.from([6,30,58,86,114,142,-1]),Int32Array.from([6,34,62,90,118,146,-1]),Int32Array.from([6,30,54,78,102,126,150]),Int32Array.from([6,24,50,76,102,128,154]),Int32Array.from([6,28,54,80,106,132,158]),Int32Array.from([6,32,58,84,110,136,162]),Int32Array.from([6,26,54,82,110,138,166]),Int32Array.from([6,30,58,86,114,142,170])]),Mn.TYPE_INFO_COORDINATES=Array.from([Int32Array.from([8,0]),Int32Array.from([8,1]),Int32Array.from([8,2]),Int32Array.from([8,3]),Int32Array.from([8,4]),Int32Array.from([8,5]),Int32Array.from([8,7]),Int32Array.from([8,8]),Int32Array.from([7,8]),Int32Array.from([5,8]),Int32Array.from([4,8]),Int32Array.from([3,8]),Int32Array.from([2,8]),Int32Array.from([1,8]),Int32Array.from([0,8])]),Mn.VERSION_INFO_POLY=7973,Mn.TYPE_INFO_POLY=1335,Mn.TYPE_INFO_MASK_PATTERN=21522;class Nn{constructor(e,t){this.dataBytes=e,this.errorCorrectionBytes=t}getDataBytes(){return this.dataBytes}getErrorCorrectionBytes(){return this.errorCorrectionBytes}}class Pn{constructor(){}static calculateMaskPenalty(e){return On.applyMaskPenaltyRule1(e)+On.applyMaskPenaltyRule2(e)+On.applyMaskPenaltyRule3(e)+On.applyMaskPenaltyRule4(e)}static encode(e,t,n=null){let r=Pn.DEFAULT_BYTE_MODE_ENCODING,i=n!==null&&n.get(En.CHARACTER_SET)!==void 0;i&&(r=n.get(En.CHARACTER_SET).toString());let a=this.chooseMode(e,r),o=new v;if(a===Nt.BYTE&&(i||Pn.DEFAULT_BYTE_MODE_ENCODING!==r)){let e=C.getCharacterSetECIByName(r);e!==void 0&&this.appendECI(e,o)}this.appendModeInfo(a,o);let s=new v;this.appendBytes(e,a,s,r);let c;if(n!==null&&n.get(En.QR_VERSION)!==void 0){let e=Number.parseInt(n.get(En.QR_VERSION).toString(),10);c=Dt.getVersionForNumber(e);let r=this.calculateBitsNeeded(a,o,s,c);if(!this.willFit(r,c,t))throw new jn(`Data too big for requested version`)}else c=this.recommendVersion(t,a,o,s);let l=new v;l.appendBitArray(o);let u=a===Nt.BYTE?s.getSizeInBytes():e.length;this.appendLengthInfo(u,c,a,l),l.appendBitArray(s);let d=c.getECBlocksForLevel(t),f=c.getTotalCodewords()-d.getTotalECCodewords();this.terminateBits(f,l);let p=this.interleaveWithECBytes(l,c.getTotalCodewords(),f,d.getNumBlocks()),m=new An;m.setECLevel(t),m.setMode(a),m.setVersion(c);let h=c.getDimensionForVersion(),g=new kn(h,h),_=this.chooseMaskPattern(p,t,c,g);return m.setMaskPattern(_),Mn.buildMatrix(p,t,c,_,g),m.setMatrix(g),m}static recommendVersion(e,t,n,r){let i=this.calculateBitsNeeded(t,n,r,Dt.getVersionForNumber(1)),a=this.chooseVersion(i,e),o=this.calculateBitsNeeded(t,n,r,a);return this.chooseVersion(o,e)}static calculateBitsNeeded(e,t,n,r){return t.getSize()+e.getCharacterCountBits(r)+n.getSize()}static getAlphanumericCode(e){return e<Pn.ALPHANUMERIC_TABLE.length?Pn.ALPHANUMERIC_TABLE[e]:-1}static chooseMode(e,t=null){if(C.SJIS.getName()===t&&this.isOnlyDoubleByteKanji(e))return Nt.KANJI;let n=!1,r=!1;for(let t=0,i=e.length;t<i;++t){let i=e.charAt(t);if(Pn.isDigit(i))n=!0;else if(this.getAlphanumericCode(i.charCodeAt(0))!==-1)r=!0;else return Nt.BYTE}return r?Nt.ALPHANUMERIC:n?Nt.NUMERIC:Nt.BYTE}static isOnlyDoubleByteKanji(e){let t;try{t=T.encode(e,C.SJIS)}catch{return!1}let n=t.length;if(n%2!=0)return!1;for(let e=0;e<n;e+=2){let n=t[e]&255;if((n<129||n>159)&&(n<224||n>235))return!1}return!0}static chooseMaskPattern(e,t,n,r){let i=2**53-1,a=-1;for(let o=0;o<An.NUM_MASK_PATTERNS;o++){Mn.buildMatrix(e,t,n,o,r);let s=this.calculateMaskPenalty(r);s<i&&(i=s,a=o)}return a}static chooseVersion(e,t){for(let n=1;n<=40;n++){let r=Dt.getVersionForNumber(n);if(Pn.willFit(e,r,t))return r}throw new jn(`Data too big`)}static willFit(e,t,n){return t.getTotalCodewords()-t.getECBlocksForLevel(n).getTotalECCodewords()>=(e+7)/8}static terminateBits(e,t){let n=e*8;if(t.getSize()>n)throw new jn(`data bits cannot fit in the QR Code`+t.getSize()+` > `+n);for(let e=0;e<4&&t.getSize()<n;++e)t.appendBit(!1);let r=t.getSize()&7;if(r>0)for(let e=r;e<8;e++)t.appendBit(!1);let i=e-t.getSizeInBytes();for(let e=0;e<i;++e)t.appendBits(e&1?17:236,8);if(t.getSize()!==n)throw new jn(`Bits size does not equal capacity`)}static getNumDataBytesAndNumECBytesForBlockID(e,t,n,r,i,a){if(r>=n)throw new jn(`Block ID too large`);let o=e%n,s=n-o,c=Math.floor(e/n),l=c+1,u=Math.floor(t/n),d=u+1,f=c-u,p=l-d;if(f!==p)throw new jn(`EC bytes mismatch`);if(n!==s+o)throw new jn(`RS blocks mismatch`);if(e!==(u+f)*s+(d+p)*o)throw new jn(`Total bytes mismatch`);r<s?(i[0]=u,a[0]=f):(i[0]=d,a[0]=p)}static interleaveWithECBytes(e,t,n,r){if(e.getSizeInBytes()!==n)throw new jn(`Number of bits and data bytes does not match`);let i=0,a=0,o=0,s=[];for(let c=0;c<r;++c){let l=new Int32Array(1),u=new Int32Array(1);Pn.getNumDataBytesAndNumECBytesForBlockID(t,n,r,c,l,u);let d=l[0],f=new Uint8Array(d);e.toBytes(8*i,f,0,d);let p=Pn.generateECBytes(f,u[0]);s.push(new Nn(f,p)),a=Math.max(a,d),o=Math.max(o,p.length),i+=l[0]}if(n!==i)throw new jn(`Data bytes does not match offset`);let c=new v;for(let e=0;e<a;++e)for(let t of s){let n=t.getDataBytes();e<n.length&&c.appendBits(n[e],8)}for(let e=0;e<o;++e)for(let t of s){let n=t.getErrorCorrectionBytes();e<n.length&&c.appendBits(n[e],8)}if(t!==c.getSizeInBytes())throw new jn(`Interleaving error: `+t+` and `+c.getSizeInBytes()+` differ.`);return c}static generateECBytes(e,t){let n=e.length,r=new Int32Array(n+t);for(let t=0;t<n;t++)r[t]=e[t]&255;new Dn(oe.QR_CODE_FIELD_256).encode(r,t);let i=new Uint8Array(t);for(let e=0;e<t;e++)i[e]=r[n+e];return i}static appendModeInfo(e,t){t.appendBits(e.getBits(),4)}static appendLengthInfo(e,t,n,r){let i=n.getCharacterCountBits(t);if(e>=1<<i)throw new 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 ce;let a=i.getWidth(),o=i.getHeight(),s=a+r*2,c=o+r*2,l=Math.max(t,s),u=Math.max(n,c),d=Math.min(Math.floor(l/s),Math.floor(u/c)),f=Math.floor((l-a*d)/2),p=Math.floor((u-o*d)/2),m=this.createSVGElement(l,u);for(let e=0,t=p;e<o;e++,t+=d)for(let n=0,r=f;n<a;n++,r+=d)if(i.get(n,e)===1){let e=this.createSvgRectElement(r,t,d,d);m.appendChild(e)}return m}createSVGElement(e,t){let n=document.createElementNS(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!==z.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 ce;let a=i.getWidth(),o=i.getHeight(),s=a+r*2,c=o+r*2,l=Math.max(t,s),u=Math.max(n,c),d=Math.min(Math.floor(l/s),Math.floor(u/c)),f=Math.floor((l-a*d)/2),p=Math.floor((u-o*d)/2),m=new O(l,u);for(let e=0,t=p;e<o;e++,t+=d)for(let n=0,r=f;n<a;n++,r+=d)i.get(n,e)===1&&m.setRegion(r,t,d,d);return m}}In.QUIET_ZONE_SIZE=4;class Ln{encode(e,t,n,r,i){let a;switch(t){case z.QR_CODE:a=new In;break;default:throw new l(`No encoder available for format `+t)}return a.encode(e,t,n,r,i)}}class Rn extends M{constructor(e,t,n,r,i,a,o,s){if(super(a,o),this.yuvData=e,this.dataWidth=t,this.dataHeight=n,this.left=r,this.top=i,r+a>t||i+o>n)throw new l(`Crop rectangle does not fit within image data.`);s&&this.reverseHorizontal(a,o)}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth();(t==null||t.length<n)&&(t=new Uint8ClampedArray(n));let r=(e+this.top)*this.dataWidth+this.left;return p.arraycopy(this.yuvData,r,t,0,n),t}getMatrix(){let e=this.getWidth(),t=this.getHeight();if(e===this.dataWidth&&t===this.dataHeight)return this.yuvData;let n=e*t,r=new Uint8ClampedArray(n),i=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return p.arraycopy(this.yuvData,i,r,0,n),r;for(let n=0;n<t;n++){let t=n*e;p.arraycopy(this.yuvData,i,r,t,e),i+=this.dataWidth}return r}isCropSupported(){return!0}crop(e,t,n,r){return new Rn(this.yuvData,this.dataWidth,this.dataHeight,this.left+e,this.top+t,n,r,!1)}renderThumbnail(){let e=this.getWidth()/Rn.THUMBNAIL_SCALE_FACTOR,t=this.getHeight()/Rn.THUMBNAIL_SCALE_FACTOR,n=new Int32Array(e*t),r=this.yuvData,i=this.top*this.dataWidth+this.left;for(let a=0;a<t;a++){let t=a*e;for(let a=0;a<e;a++){let e=r[i+a*Rn.THUMBNAIL_SCALE_FACTOR]&255;n[t+a]=4278190080|e*65793}i+=this.dataWidth*Rn.THUMBNAIL_SCALE_FACTOR}return n}getThumbnailWidth(){return this.getWidth()/Rn.THUMBNAIL_SCALE_FACTOR}getThumbnailHeight(){return this.getHeight()/Rn.THUMBNAIL_SCALE_FACTOR}reverseHorizontal(e,t){let n=this.yuvData;for(let r=0,i=this.top*this.dataWidth+this.left;r<t;r++,i+=this.dataWidth){let t=i+e/2;for(let r=i,a=i+e-1;r<t;r++,a--){let e=n[r];n[r]=n[a],n[a]=e}}}invert(){return new N(this)}}Rn.THUMBNAIL_SCALE_FACTOR=2;class zn extends M{constructor(e,t,n,r,i,a,o){if(super(t,n),this.dataWidth=r,this.dataHeight=i,this.left=a,this.top=o,e.BYTES_PER_ELEMENT===4){let r=t*n,i=new Uint8ClampedArray(r);for(let t=0;t<r;t++){let n=e[t],r=n>>16&255,a=n>>7&510,o=n&255;i[t]=(r+a+o)/4&255}this.luminances=i}else this.luminances=e;if(r===void 0&&(this.dataWidth=t),i===void 0&&(this.dataHeight=n),a===void 0&&(this.left=0),o===void 0&&(this.top=0),this.left+t>this.dataWidth||this.top+n>this.dataHeight)throw new l(`Crop rectangle does not fit within image data.`)}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth();(t==null||t.length<n)&&(t=new Uint8ClampedArray(n));let r=(e+this.top)*this.dataWidth+this.left;return p.arraycopy(this.luminances,r,t,0,n),t}getMatrix(){let e=this.getWidth(),t=this.getHeight();if(e===this.dataWidth&&t===this.dataHeight)return this.luminances;let n=e*t,r=new Uint8ClampedArray(n),i=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return p.arraycopy(this.luminances,i,r,0,n),r;for(let n=0;n<t;n++){let t=n*e;p.arraycopy(this.luminances,i,r,t,e),i+=this.dataWidth}return r}isCropSupported(){return!0}crop(e,t,n,r){return new zn(this.luminances,n,r,this.dataWidth,this.dataHeight,this.left+e,this.top+t)}invert(){return new N(this)}}class Bn extends C{static forName(e){return this.getCharacterSetECIByName(e)}}class Vn{}Vn.ISO_8859_1=C.ISO8859_1;class Hn{isCompact(){return this.compact}setCompact(e){this.compact=e}getSize(){return this.size}setSize(e){this.size=e}getLayers(){return this.layers}setLayers(e){this.layers=e}getCodeWords(){return this.codeWords}setCodeWords(e){this.codeWords=e}getMatrix(){return this.matrix}setMatrix(e){this.matrix=e}}class Un{static singletonList(e){return[e]}static min(e,t){return e.sort(t)[0]}}class Wn{constructor(e){this.previous=e}getPrevious(){return this.previous}}class Gn extends Wn{constructor(e,t,n){super(e),this.value=t,this.bitCount=n}appendTo(e,t){e.appendBits(this.value,this.bitCount)}add(e,t){return new Gn(this,e,t)}addBinaryShift(e,t){return console.warn(`addBinaryShift on SimpleToken, this simply returns a copy of this token`),new Gn(this,e,t)}toString(){let e=this.value&(1<<this.bitCount)-1;return e|=1<<this.bitCount,`<`+_.toBinaryString(e|1<<this.bitCount).substring(1)+`>`}}class Kn extends Gn{constructor(e,t,n){super(e,0,0),this.binaryShiftStart=t,this.binaryShiftByteCount=n}appendTo(e,t){for(let n=0;n<this.binaryShiftByteCount;n++)(n===0||n===31&&this.binaryShiftByteCount<=62)&&(e.appendBits(31,5),this.binaryShiftByteCount>62?e.appendBits(this.binaryShiftByteCount-31,16):n===0?e.appendBits(Math.min(this.binaryShiftByteCount,31),5):e.appendBits(this.binaryShiftByteCount-31,5)),e.appendBits(t[this.binaryShiftStart+n],8)}addBinaryShift(e,t){return new Kn(this,e,t)}toString(){return`<`+this.binaryShiftStart+`::`+(this.binaryShiftStart+this.binaryShiftByteCount-1)+`>`}}function qn(e,t,n){return new Kn(e,t,n)}function Jn(e,t,n){return new Gn(e,t,n)}let Yn=[`UPPER`,`LOWER`,`DIGIT`,`MIXED`,`PUNCT`],Xn=new Gn(null,0,0),Zn=[Int32Array.from([0,327708,327710,327709,656318]),Int32Array.from([590318,0,327710,327709,656318]),Int32Array.from([262158,590300,0,590301,932798]),Int32Array.from([327709,327708,656318,0,327710]),Int32Array.from([327711,656380,656382,656381,0])];function Qn(e){for(let t of e)g.fill(t,-1);return e[0][4]=0,e[1][4]=0,e[1][0]=28,e[3][4]=0,e[2][4]=0,e[2][0]=15,e}let $n=Qn(g.createInt32Array(6,6));class er{constructor(e,t,n,r){this.token=e,this.mode=t,this.binaryShiftByteCount=n,this.bitCount=r}getMode(){return this.mode}getToken(){return this.token}getBinaryShiftByteCount(){return this.binaryShiftByteCount}getBitCount(){return this.bitCount}latchAndAppend(e,t){let n=this.bitCount,r=this.token;if(e!==this.mode){let t=Zn[this.mode][e];r=Jn(r,t&65535,t>>16),n+=t>>16}let i=e===2?4:5;return r=Jn(r,t,i),new er(r,e,0,n+i)}shiftAndAppend(e,t){let n=this.token,r=this.mode===2?4:5;return n=Jn(n,$n[this.mode][e],r),n=Jn(n,t,5),new er(n,this.mode,0,this.bitCount+r+5)}addBinaryShiftChar(e){let t=this.token,n=this.mode,r=this.bitCount;if(this.mode===4||this.mode===2){let e=Zn[n][0];t=Jn(t,e&65535,e>>16),r+=e>>16,n=0}let i=this.binaryShiftByteCount===0||this.binaryShiftByteCount===31?18:this.binaryShiftByteCount===62?9:8,a=new er(t,n,this.binaryShiftByteCount+1,r+i);return a.binaryShiftByteCount===2078&&(a=a.endBinaryShift(e+1)),a}endBinaryShift(e){if(this.binaryShiftByteCount===0)return this;let t=this.token;return t=qn(t,e-this.binaryShiftByteCount,this.binaryShiftByteCount),new er(t,this.mode,0,this.bitCount)}isBetterThanOrEqualTo(e){let t=this.bitCount+(Zn[this.mode][e.mode]>>16);return this.binaryShiftByteCount<e.binaryShiftByteCount?t+=er.calculateBinaryShiftCost(e)-er.calculateBinaryShiftCost(this):this.binaryShiftByteCount>e.binaryShiftByteCount&&e.binaryShiftByteCount>0&&(t+=10),t<=e.bitCount}toBitArray(e){let t=[];for(let n=this.endBinaryShift(e.length).token;n!==null;n=n.getPrevious())t.unshift(n);let n=new v;for(let r of t)r.appendTo(n,e);return n}toString(){return E.format(`%s bits=%d bytes=%d`,Yn[this.mode],this.bitCount,this.binaryShiftByteCount)}static calculateBinaryShiftCost(e){return e.binaryShiftByteCount>62?21:e.binaryShiftByteCount>31?20:e.binaryShiftByteCount>0?10:0}}er.INITIAL_STATE=new er(Xn,0,0,0);function tr(e){let t=E.getCharCode(` `),n=E.getCharCode(`.`),r=E.getCharCode(`,`);e[0][t]=1;let i=E.getCharCode(`Z`),a=E.getCharCode(`A`);for(let t=a;t<=i;t++)e[0][t]=t-a+2;e[1][t]=1;let o=E.getCharCode(`z`),s=E.getCharCode(`a`);for(let t=s;t<=o;t++)e[1][t]=t-s+2;e[2][t]=1;let c=E.getCharCode(`9`),l=E.getCharCode(`0`);for(let t=l;t<=c;t++)e[2][t]=t-l+2;e[2][r]=12,e[2][n]=13;let u=`\0 \x07\b
69
+ \v\f\r\x1B@\\^_\`|~`.split(``);for(let t=0;t<u.length;t++)e[3][E.getCharCode(u[t])]=t;let d=`\0\r\0\0\0\0!'#$%&'()*+,-./:;<=>?[]{}`.split(``);for(let t=0;t<d.length;t++)E.getCharCode(d[t])>0&&(e[4][E.getCharCode(d[t])]=t);return e}let nr=tr(g.createInt32Array(5,256));class rr{constructor(e){this.text=e}encode(){let e=E.getCharCode(` `),t=E.getCharCode(`
70
+ `),n=Un.singletonList(er.INITIAL_STATE);for(let r=0;r<this.text.length;r++){let i,a=r+1<this.text.length?this.text[r+1]:0;switch(this.text[r]){case E.getCharCode(`\r`):i=a===t?2:0;break;case E.getCharCode(`.`):i=a===e?3:0;break;case E.getCharCode(`,`):i=a===e?4:0;break;case E.getCharCode(`:`):i=a===e?5:0;break;default:i=0}i>0?(n=rr.updateStateListForPair(n,r,i),r++):n=this.updateStateListForChar(n,r)}return Un.min(n,(e,t)=>e.getBitCount()-t.getBitCount()).toBitArray(this.text)}updateStateListForChar(e,t){let n=[];for(let r of e)this.updateStateForChar(r,t,n);return rr.simplifyStates(n)}updateStateForChar(e,t,n){let r=this.text[t]&255,i=nr[e.getMode()][r]>0,a=null;for(let o=0;o<=4;o++){let s=nr[o][r];if(s>0){if(a??=e.endBinaryShift(t),!i||o===e.getMode()||o===2){let e=a.latchAndAppend(o,s);n.push(e)}if(!i&&$n[e.getMode()][o]>=0){let e=a.shiftAndAppend(o,s);n.push(e)}}}if(e.getBinaryShiftByteCount()>0||nr[e.getMode()][r]===0){let r=e.addBinaryShiftChar(t);n.push(r)}}static updateStateListForPair(e,t,n){let r=[];for(let i of e)this.updateStateForPair(i,t,n,r);return this.simplifyStates(r)}static updateStateForPair(e,t,n,r){let i=e.endBinaryShift(t);if(r.push(i.latchAndAppend(4,n)),e.getMode()!==4&&r.push(i.shiftAndAppend(4,n)),n===3||n===4){let e=i.latchAndAppend(2,16-n).latchAndAppend(2,1);r.push(e)}if(e.getBinaryShiftByteCount()>0){let n=e.addBinaryShiftChar(t).addBinaryShiftChar(t+1);r.push(n)}}static simplifyStates(e){let t=[];for(let n of e){let e=!0;for(let r of t){if(r.isBetterThanOrEqualTo(n)){e=!1;break}n.isBetterThanOrEqualTo(r)&&(t=t.filter(e=>e!==r))}e&&t.push(n)}return t}}class ir{constructor(){}static encodeBytes(e){return ir.encode(e,ir.DEFAULT_EC_PERCENT,ir.DEFAULT_AZTEC_LAYERS)}static encode(e,t,n){let r=new rr(e).encode(),i=_.truncDivision(r.getSize()*t,100)+11,a=r.getSize()+i,o,s,c,u,d;if(n!==ir.DEFAULT_AZTEC_LAYERS){if(o=n<0,s=Math.abs(n),s>(o?ir.MAX_NB_BITS_COMPACT:ir.MAX_NB_BITS))throw new l(E.format(`Illegal value %s for layers`,n));c=ir.totalBitsInLayer(s,o),u=ir.WORD_SIZE[s];let e=c-c%u;if(d=ir.stuffBits(r,u),d.getSize()+i>e||o&&d.getSize()>u*64)throw new l(`Data to large for user specified layer`)}else{u=0,d=null;for(let e=0;;e++){if(e>ir.MAX_NB_BITS)throw new l(`Data too large for an Aztec code`);if(o=e<=3,s=o?e+1:e,c=ir.totalBitsInLayer(s,o),a>c)continue;(d==null||u!==ir.WORD_SIZE[s])&&(u=ir.WORD_SIZE[s],d=ir.stuffBits(r,u));let t=c-c%u;if(!(o&&d.getSize()>u*64)&&d.getSize()+i<=t)break}}let f=ir.generateCheckWords(d,c,u),p=d.getSize()/u,m=ir.generateModeMessage(o,s,p),h=(o?11:14)+s*4,g=new Int32Array(h),v;if(o){v=h;for(let e=0;e<g.length;e++)g[e]=e}else{v=h+1+2*_.truncDivision(_.truncDivision(h,2)-1,15);let e=_.truncDivision(h,2),t=_.truncDivision(v,2);for(let n=0;n<e;n++){let r=n+_.truncDivision(n,15);g[e-n-1]=t-r-1,g[e+n]=t+r+1}}let y=new O(v);for(let e=0,t=0;e<s;e++){let n=(s-e)*4+(o?9:12);for(let r=0;r<n;r++){let i=r*2;for(let a=0;a<2;a++)f.get(t+i+a)&&y.set(g[e*2+a],g[e*2+r]),f.get(t+n*2+i+a)&&y.set(g[e*2+r],g[h-1-e*2-a]),f.get(t+n*4+i+a)&&y.set(g[h-1-e*2-a],g[h-1-e*2-r]),f.get(t+n*6+i+a)&&y.set(g[h-1-e*2-r],g[e*2+a])}t+=n*8}if(ir.drawModeMessage(y,o,v,m),o)ir.drawBullsEye(y,_.truncDivision(v,2),5);else{ir.drawBullsEye(y,_.truncDivision(v,2),7);for(let e=0,t=0;e<_.truncDivision(h,2)-1;e+=15,t+=16)for(let e=_.truncDivision(v,2)&1;e<v;e+=2)y.set(_.truncDivision(v,2)-t,e),y.set(_.truncDivision(v,2)+t,e),y.set(e,_.truncDivision(v,2)-t),y.set(e,_.truncDivision(v,2)+t)}let b=new Hn;return b.setCompact(o),b.setSize(v),b.setLayers(s),b.setCodeWords(p),b.setMatrix(y),b}static drawBullsEye(e,t,n){for(let r=0;r<n;r+=2)for(let n=t-r;n<=t+r;n++)e.set(n,t-r),e.set(n,t+r),e.set(t-r,n),e.set(t+r,n);e.set(t-n,t-n),e.set(t-n+1,t-n),e.set(t-n,t-n+1),e.set(t+n,t-n),e.set(t+n,t-n+1),e.set(t+n,t+n-1)}static generateModeMessage(e,t,n){let r=new v;return e?(r.appendBits(t-1,2),r.appendBits(n-1,6),r=ir.generateCheckWords(r,28,4)):(r.appendBits(t-1,5),r.appendBits(n-1,11),r=ir.generateCheckWords(r,40,4)),r}static drawModeMessage(e,t,n,r){let i=_.truncDivision(n,2);if(t)for(let t=0;t<7;t++){let n=i-3+t;r.get(t)&&e.set(n,i-5),r.get(t+7)&&e.set(i+5,n),r.get(20-t)&&e.set(n,i+5),r.get(27-t)&&e.set(i-5,n)}else for(let t=0;t<10;t++){let n=i-5+t+_.truncDivision(t,5);r.get(t)&&e.set(n,i-7),r.get(t+10)&&e.set(i+7,n),r.get(29-t)&&e.set(n,i+7),r.get(39-t)&&e.set(i-7,n)}}static generateCheckWords(e,t,n){let r=e.getSize()/n,i=new Dn(ir.getGF(n)),a=_.truncDivision(t,n),o=ir.bitsToWords(e,n,a);i.encode(o,a-r);let s=t%n,c=new v;c.appendBits(0,s);for(let e of Array.from(o))c.appendBits(e,n);return c}static bitsToWords(e,t,n){let r=new Int32Array(n),i,a;for(i=0,a=e.getSize()/t;i<a;i++){let n=0;for(let r=0;r<t;r++)n|=e.get(i*t+r)?1<<t-r-1:0;r[i]=n}return r}static getGF(e){switch(e){case 4:return oe.AZTEC_PARAM;case 6:return oe.AZTEC_DATA_6;case 8:return oe.AZTEC_DATA_8;case 10:return oe.AZTEC_DATA_10;case 12:return oe.AZTEC_DATA_12;default:throw new l(`Unsupported word size `+e)}}static stuffBits(e,t){let n=new v,r=e.getSize(),i=(1<<t)-2;for(let a=0;a<r;a+=t){let o=0;for(let n=0;n<t;n++)(a+n>=r||e.get(a+n))&&(o|=1<<t-1-n);(o&i)===i?(n.appendBits(o&i,t),a--):(o&i)===0?(n.appendBits(o|1,t),a--):n.appendBits(o,t)}return n}static totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}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!==z.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 ce;let i=r.getWidth(),a=r.getHeight(),o=Math.max(t,i),s=Math.max(n,a),c=Math.min(o/i,s/a),l=(o-i*c)/2,u=(s-a*c)/2,d=new O(o,s);for(let e=0,t=u;e<a;e++,t+=c)for(let n=0,a=l;n<i;n++,a+=c)r.get(n,e)&&d.setRegion(a,t,c,c);return d}}e.AbstractExpandedDecoder=Je,e.ArgumentException=c,e.ArithmeticException=ae,e.AztecCode=Hn,e.AztecCodeReader=xe,e.AztecCodeWriter=ar,e.AztecDecoder=ue,e.AztecDetector=be,e.AztecDetectorResult=me,e.AztecEncoder=ir,e.AztecHighLevelEncoder=rr,e.AztecPoint=ye,e.BarcodeFormat=z,e.Binarizer=f,e.BinaryBitmap=u,e.BitArray=v,e.BitMatrix=O,e.BitSource=_t,e.BrowserAztecCodeReader=Se,e.BrowserBarcodeReader=dt,e.BrowserCodeReader=L,e.BrowserDatamatrixCodeReader=Ct,e.BrowserMultiFormatReader=Sn,e.BrowserPDF417Reader=Cn,e.BrowserQRCodeReader=wn,e.BrowserQRCodeSvgWriter=Fn,e.CharacterSetECI=C,e.ChecksumException=d,e.Code128Reader=W,e.Code39Reader=we,e.DataMatrixDecodedBitStreamParser=yt,e.DataMatrixReader=St,e.DecodeHintType=b,e.DecoderResult=re,e.DefaultGridSampler=_e,e.DetectorResult=pe,e.EAN13Reader=je,e.EncodeHintType=En,e.Exception=s,e.FormatException=x,e.GenericGF=oe,e.GenericGFPoly=B,e.GlobalHistogramBinarizer=A,e.GridSampler=ge,e.GridSamplerInstance=ve,e.HTMLCanvasElementLuminanceSource=P,e.HybridBinarizer=j,e.ITFReader=Te,e.IllegalArgumentException=l,e.IllegalStateException=ce,e.InvertedLuminanceSource=N,e.LuminanceSource=M,e.MathUtils=de,e.MultiFormatOneDReader=ut,e.MultiFormatReader=xn,e.MultiFormatWriter=Ln,e.NotFoundException=k,e.OneDReader=Ce,e.PDF417DecodedBitStreamParser=J,e.PDF417DecoderErrorCorrection=Xt,e.PDF417Reader=yn,e.PDF417ResultMetadata=sn,e.PerspectiveTransform=U,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=V,e.ReedSolomonEncoder=Dn,e.ReedSolomonException=se,e.Result=R,e.ResultMetadataType=ne,e.ResultPoint=H,e.StringUtils=E,e.UnsupportedOperationException=w,e.VideoInputDevice=F,e.WhiteRectangleDetector=he,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})}))}))()),f_=function(){function e(e,t,n){if(this.formatMap=new Map([[Jg.QR_CODE,d_.BarcodeFormat.QR_CODE],[Jg.AZTEC,d_.BarcodeFormat.AZTEC],[Jg.CODABAR,d_.BarcodeFormat.CODABAR],[Jg.CODE_39,d_.BarcodeFormat.CODE_39],[Jg.CODE_93,d_.BarcodeFormat.CODE_93],[Jg.CODE_128,d_.BarcodeFormat.CODE_128],[Jg.DATA_MATRIX,d_.BarcodeFormat.DATA_MATRIX],[Jg.MAXICODE,d_.BarcodeFormat.MAXICODE],[Jg.ITF,d_.BarcodeFormat.ITF],[Jg.EAN_13,d_.BarcodeFormat.EAN_13],[Jg.EAN_8,d_.BarcodeFormat.EAN_8],[Jg.PDF_417,d_.BarcodeFormat.PDF_417],[Jg.RSS_14,d_.BarcodeFormat.RSS_14],[Jg.RSS_EXPANDED,d_.BarcodeFormat.RSS_EXPANDED],[Jg.UPC_A,d_.BarcodeFormat.UPC_A],[Jg.UPC_E,d_.BarcodeFormat.UPC_E],[Jg.UPC_EAN_EXTENSION,d_.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!d_)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(d_.DecodeHintType.POSSIBLE_FORMATS,r),i.set(d_.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 d_.MultiFormatReader(this.verbose,this.hints),n=new d_.HTMLCanvasElementLuminanceSource(e),r=new d_.BinaryBitmap(new d_.HybridBinarizer(n)),i=t.decode(r);return{text:i.text,format:e_.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}(),p_=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())})},m_=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}}},h_=function(){function e(t,n,r){if(this.formatMap=new Map([[Jg.QR_CODE,`qr_code`],[Jg.AZTEC,`aztec`],[Jg.CODABAR,`codabar`],[Jg.CODE_39,`code_39`],[Jg.CODE_93,`code_93`],[Jg.CODE_128,`code_128`],[Jg.DATA_MATRIX,`data_matrix`],[Jg.ITF,`itf`],[Jg.EAN_13,`ean_13`],[Jg.EAN_8,`ean_8`],[Jg.PDF_417,`pdf417`],[Jg.UPC_A,`upc_a`],[Jg.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 p_(this,void 0,void 0,function(){var t,n;return m_(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:e_.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}(),g_=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())})},__=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}}},v_=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&&h_.isSupported()?(this.primaryDecoder=new h_(e,n,r),this.secondaryDecoder=new f_(e,n,r)):this.primaryDecoder=new f_(e,n,r)}return e.prototype.decodeAsync=function(e){return g_(this,void 0,void 0,function(){var t;return __(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 g_(this,void 0,void 0,function(){var t,n;return __(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}(),y_=(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)}})(),b_=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())})},x_=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}}},S_=function(){function e(e,t){this.name=e,this.track=t}return e.prototype.isSupported=function(){return this.track.getCapabilities?this.name in this.track.getCapabilities():!1},e.prototype.apply=function(e){var t={};t[this.name]=e;var n={advanced:[t]};return this.track.applyConstraints(n)},e.prototype.value=function(){var e=this.track.getSettings();return this.name in e?e[this.name]:null},e}(),C_=function(e){y_(t,e);function t(t){return e.call(this,`zoom`,t)||this}return t}(function(e){y_(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}(S_)),w_=function(e){y_(t,e);function t(t){return e.call(this,`torch`,t)||this}return t}(S_),T_=function(){function e(e){this.track=e}return e.prototype.zoomFeature=function(){return new C_(this.track)},e.prototype.torchFeature=function(){return new w_(this.track)},e}(),E_=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 b_(this,void 0,void 0,function(){var a,o;return x_(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 b_(this,void 0,void 0,function(){return x_(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 T_(this.getFirstTrackOrFail())},e}(),D_=function(){function e(e){this.mediaStream=e}return e.prototype.render=function(e,t,n){return b_(this,void 0,void 0,function(){return x_(this,function(r){return[2,E_.create(e,this.mediaStream,t,n)]})})},e.create=function(t){return b_(this,void 0,void 0,function(){var n,r;return x_(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}(),O_=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())})},k_=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}}},A_=function(){function e(){}return e.failIfNotSupported=function(){return O_(this,void 0,void 0,function(){return k_(this,function(t){if(!navigator.mediaDevices)throw`navigator.mediaDevices not supported`;return[2,new e]})})},e.prototype.create=function(e){return O_(this,void 0,void 0,function(){return k_(this,function(t){return[2,D_.create(e)]})})},e}(),j_=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())})},M_=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}}},N_=function(){function e(){}return e.retrieve=function(){return navigator.mediaDevices?e.getCamerasFromMediaDevices():MediaStreamTrack&&MediaStreamTrack.getSources?e.getCamerasFromMediaStreamTrack():e.rejectWithError()},e.rejectWithError=function(){var t=s_.unableToQuerySupportedDevices();return e.isHttpsOrLocalhost()||(t=s_.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 j_(this,void 0,void 0,function(){var e,t,n,r,i,a,o;return M_(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}(),P_;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.NOT_STARTED=1]=`NOT_STARTED`,e[e.SCANNING=2]=`SCANNING`,e[e.PAUSED=3]=`PAUSED`})(P_||={});var F_=function(){function e(){this.state=P_.NOT_STARTED,this.onGoingTransactionNewState=P_.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===P_.UNKNOWN)throw`Transaction is already cancelled, cannot execute().`;var e=this.onGoingTransactionNewState;this.onGoingTransactionNewState=P_.UNKNOWN,this.directTransition(e)},e.prototype.cancel=function(){if(this.onGoingTransactionNewState===P_.UNKNOWN)throw`Transaction is already cancelled, cannot cancel().`;this.onGoingTransactionNewState=P_.UNKNOWN},e.prototype.getState=function(){return this.state},e.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==P_.UNKNOWN)throw`Cannot transition to a new state, already under transition`},e.prototype.validateTransition=function(e){switch(this.state){case P_.UNKNOWN:throw`Transition from unknown is not allowed`;case P_.NOT_STARTED:this.failIfNewStateIs(e,[P_.PAUSED]);break;case P_.SCANNING:break;case P_.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}(),I_=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()===P_.NOT_STARTED},e.prototype.isScanning=function(){return this.stateManager.getState()!==P_.NOT_STARTED},e.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===P_.SCANNING},e.prototype.isPaused=function(){return this.stateManager.getState()===P_.PAUSED},e}(),L_=function(){function e(){}return e.create=function(){return new I_(new F_)},e}(),R_=(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)}})(),z_=function(e){R_(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}($g),B_=function(){function e(e,t){this.logger=t,this.fps=z_.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=z_.DEFAULT_DISABLE_FLIP}return e.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?u_.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError(`Empty videoConstraints`,!0),!1)},e.prototype.isShadedBoxEnabled=function(){return!a_(this.qrbox)},e.create=function(t,n){return new e(t,n)},e}(),V_=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 i_(this.verbose),this.qrcode=new v_(this.getSupportedFormats(t),this.getUseBarCodeDetectorIfSupported(n),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=L_.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=B_.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:z_.DEFAULT_WIDTH,l.style.position=`relative`,this.shouldScan=!0,this.element=l;var u=this,d=this.stateManagerProxy.startTransition(P_.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)}};A_.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(s_.errorGettingUserMedia(e))})}).catch(function(e){d.cancel(),r(s_.cameraStreamingNotSupported())})})},e.prototype.pause=function(e){if(!this.stateManagerProxy.isStrictlyScanning())throw`Cannot pause, scanner is not scanning.`;this.stateManagerProxy.directTransition(P_.PAUSED),this.showPausedState(),(a_(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(P_.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(P_.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var n=function(){if(e.element){var t=document.getElementById(z_.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(a_(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:z_.DEFAULT_WIDTH,l=Math.max(s.clientHeight?s.clientHeight:o,z_.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=z_.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(t_.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 N_.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(!u_.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=[Jg.QR_CODE,Jg.AZTEC,Jg.CODABAR,Jg.CODE_39,Jg.CODE_93,Jg.CODE_128,Jg.DATA_MATRIX,Jg.MAXICODE,Jg.ITF,Jg.EAN_13,Jg.EAN_8,Jg.PDF_417,Jg.RSS_14,Jg.RSS_EXPANDED,Jg.UPC_A,Jg.UPC_E,Jg.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];Zg(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(a_(e))return!0;if(!a_(e.useBarCodeDetectorIfSupported))return e.useBarCodeDetectorIfSupported!==!1;if(a_(e.experimentalFeatures))return!0;var t=e.experimentalFeatures;return a_(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<z_.MIN_QR_BOX_SIZE)throw`minimum size of 'config.qrbox' dimension value is ${z_.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=a_(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=s_.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,t_.createFromQrcodeResult(t)),n.possiblyUpdateShaders(!0),!0}).catch(function(e){n.possiblyUpdateShaders(!1);var r=s_.codeParseError(e);return t(r,r_.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?z_.BORDER_SHADER_MATCH_COLOR:z_.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=a_(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=`${z_.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=z_.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}(),H_=`data:image/svg+xml;base64,`,U_=H_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNzEuNjQzIDM3MS42NDMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDM3MS42NDMgMzcxLjY0MyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZD0iTTEwNS4wODQgMzguMjcxaDE2My43Njh2MjBIMTA1LjA4NHoiLz48cGF0aCBkPSJNMzExLjU5NiAxOTAuMTg5Yy03LjQ0MS05LjM0Ny0xOC40MDMtMTYuMjA2LTMyLjc0My0yMC41MjJWMzBjMC0xNi41NDItMTMuNDU4LTMwLTMwLTMwSDEyNS4wODRjLTE2LjU0MiAwLTMwIDEzLjQ1OC0zMCAzMHYxMjAuMTQzaC04LjI5NmMtMTYuNTQyIDAtMzAgMTMuNDU4LTMwIDMwdjEuMzMzYTI5LjgwNCAyOS44MDQgMCAwIDAgNC42MDMgMTUuOTM5Yy03LjM0IDUuNDc0LTEyLjEwMyAxNC4yMjEtMTIuMTAzIDI0LjA2MXYxLjMzM2MwIDkuODQgNC43NjMgMTguNTg3IDEyLjEwMyAyNC4wNjJhMjkuODEgMjkuODEgMCAwIDAtNC42MDMgMTUuOTM4djEuMzMzYzAgMTYuNTQyIDEzLjQ1OCAzMCAzMCAzMGg4LjMyNGMuNDI3IDExLjYzMSA3LjUwMyAyMS41ODcgMTcuNTM0IDI2LjE3Ny45MzEgMTAuNTAzIDQuMDg0IDMwLjE4NyAxNC43NjggNDUuNTM3YTkuOTg4IDkuOTg4IDAgMCAwIDguMjE2IDQuMjg4IDkuOTU4IDkuOTU4IDAgMCAwIDUuNzA0LTEuNzkzYzQuNTMzLTMuMTU1IDUuNjUtOS4zODggMi40OTUtMTMuOTIxLTYuNzk4LTkuNzY3LTkuNjAyLTIyLjYwOC0xMC43Ni0zMS40aDgyLjY4NWMuMjcyLjQxNC41NDUuODE4LjgxNSAxLjIxIDMuMTQyIDQuNTQxIDkuMzcyIDUuNjc5IDEzLjkxMyAyLjUzNCA0LjU0Mi0zLjE0MiA1LjY3Ny05LjM3MSAyLjUzNS0xMy45MTMtMTEuOTE5LTE3LjIyOS04Ljc4Ny0zNS44ODQgOS41ODEtNTcuMDEyIDMuMDY3LTIuNjUyIDEyLjMwNy0xMS43MzIgMTEuMjE3LTI0LjAzMy0uODI4LTkuMzQzLTcuMTA5LTE3LjE5NC0xOC42NjktMjMuMzM3YTkuODU3IDkuODU3IDAgMCAwLTEuMDYxLS40ODZjLS40NjYtLjE4Mi0xMS40MDMtNC41NzktOS43NDEtMTUuNzA2IDEuMDA3LTYuNzM3IDE0Ljc2OC04LjI3MyAyMy43NjYtNy42NjYgMjMuMTU2IDEuNTY5IDM5LjY5OCA3LjgwMyA0Ny44MzYgMTguMDI2IDUuNzUyIDcuMjI1IDcuNjA3IDE2LjYyMyA1LjY3MyAyOC43MzMtLjQxMyAyLjU4NS0uODI0IDUuMjQxLTEuMjQ1IDcuOTU5LTUuNzU2IDM3LjE5NC0xMi45MTkgODMuNDgzLTQ5Ljg3IDExNC42NjEtNC4yMjEgMy41NjEtNC43NTYgOS44Ny0xLjE5NCAxNC4wOTJhOS45OCA5Ljk4IDAgMCAwIDcuNjQ4IDMuNTUxIDkuOTU1IDkuOTU1IDAgMCAwIDYuNDQ0LTIuMzU4YzQyLjY3Mi0zNi4wMDUgNTAuODAyLTg4LjUzMyA1Ni43MzctMTI2Ljg4OC40MTUtMi42ODQuODIxLTUuMzA5IDEuMjI5LTcuODYzIDIuODM0LTE3LjcyMS0uNDU1LTMyLjY0MS05Ljc3Mi00NC4zNDV6bS0yMzIuMzA4IDQyLjYyYy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM2MwLTUuNTE0IDQuNDg2LTEwIDEwLTEwaDE1djIxLjMzM2gtMTV6bS0yLjUtNTIuNjY2YzAtNS41MTQgNC40ODYtMTAgMTAtMTBoNy41djIxLjMzM2gtNy41Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM3ptMTcuNSA5My45OTloLTcuNWMtNS41MTQgMC0xMC00LjQ4Ni0xMC0xMHYtMS4zMzNjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGg3LjV2MjEuMzMzem0zMC43OTYgMjguODg3Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi04LjI3MWg5MS40NTdjLS44NTEgNi42NjgtLjQzNyAxMi43ODcuNzMxIDE4LjI3MWgtODIuMTg4em03OS40ODItMTEzLjY5OGMtMy4xMjQgMjAuOTA2IDEyLjQyNyAzMy4xODQgMjEuNjI1IDM3LjA0IDUuNDQxIDIuOTY4IDcuNTUxIDUuNjQ3IDcuNzAxIDcuMTg4LjIxIDIuMTUtMi41NTMgNS42ODQtNC40NzcgNy4yNTEtLjQ4Mi4zNzgtLjkyOS44LTEuMzM1IDEuMjYxLTYuOTg3IDcuOTM2LTExLjk4MiAxNS41Mi0xNS40MzIgMjIuNjg4aC05Ny41NjRWMzBjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGgxMjMuNzY5YzUuNTE0IDAgMTAgNC40ODYgMTAgMTB2MTM1LjU3OWMtMy4wMzItLjM4MS02LjE1LS42OTQtOS4zODktLjkxNC0yNS4xNTktMS42OTQtNDIuMzcgNy43NDgtNDQuODk4IDI0LjY2NnoiLz48cGF0aCBkPSJNMTc5LjEyOSA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXpNMTcyLjYyOSAxNDIuODZoLTEyLjU2VjEzMC44YTUgNSAwIDEgMC0xMCAwdjE3LjA2MWE1IDUgMCAwIDAgNSA1aDE3LjU2YTUgNSAwIDEgMCAwLTEwLjAwMXpNMjE2LjU2OCA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXptLTUgMjQuMDYxaC0xNC4wNlY5My4xNjdoMTQuMDZ2MTQuMDYxek0yMTEuNjY5IDEyNS45MzZIMTk3LjQxYTUgNSAwIDAgMC01IDV2MTQuMjU3YTUgNSAwIDAgMCA1IDVoMTQuMjU5YTUgNSAwIDAgMCA1LTV2LTE0LjI1N2E1IDUgMCAwIDAtNS01eiIvPjwvc3ZnPg==`,W_=H_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1OS4wMTggNTkuMDE4IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1OS4wMTggNTkuMDE4IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJtNTguNzQxIDU0LjgwOS01Ljk2OS02LjI0NGExMC43NCAxMC43NCAwIDAgMCAyLjgyLTcuMjVjMC01Ljk1My00Ljg0My0xMC43OTYtMTAuNzk2LTEwLjc5NlMzNCAzNS4zNjEgMzQgNDEuMzE0IDM4Ljg0MyA1Mi4xMSA0NC43OTYgNTIuMTFjMi40NDEgMCA0LjY4OC0uODI0IDYuNDk5LTIuMTk2bDYuMDAxIDYuMjc3YS45OTguOTk4IDAgMCAwIDEuNDE0LjAzMiAxIDEgMCAwIDAgLjAzMS0xLjQxNHpNMzYgNDEuMzE0YzAtNC44NSAzLjk0Ni04Ljc5NiA4Ljc5Ni04Ljc5NnM4Ljc5NiAzLjk0NiA4Ljc5NiA4Ljc5Ni0zLjk0NiA4Ljc5Ni04Ljc5NiA4Ljc5NlMzNiA0Ni4xNjQgMzYgNDEuMzE0ek0xMC40MzEgMTYuMDg4YzAgMy4wNyAyLjQ5OCA1LjU2OCA1LjU2OSA1LjU2OHM1LjU2OS0yLjQ5OCA1LjU2OS01LjU2OGMwLTMuMDcxLTIuNDk4LTUuNTY5LTUuNTY5LTUuNTY5cy01LjU2OSAyLjQ5OC01LjU2OSA1LjU2OXptOS4xMzggMGMwIDEuOTY4LTEuNjAyIDMuNTY4LTMuNTY5IDMuNTY4cy0zLjU2OS0xLjYwMS0zLjU2OS0zLjU2OCAxLjYwMi0zLjU2OSAzLjU2OS0zLjU2OSAzLjU2OSAxLjYwMSAzLjU2OSAzLjU2OXoiLz48cGF0aCBkPSJtMzAuODgyIDI4Ljk4NyA5LjE4LTEwLjA1NCAxMS4yNjIgMTAuMzIzYTEgMSAwIDAgMCAxLjM1MS0xLjQ3NWwtMTItMTFhMSAxIDAgMCAwLTEuNDE0LjA2M2wtOS43OTQgMTAuNzI3LTQuNzQzLTQuNzQzYTEuMDAzIDEuMDAzIDAgMCAwLTEuMzY4LS4wNDRMNi4zMzkgMzcuNzY4YTEgMSAwIDEgMCAxLjMyMiAxLjUwMWwxNi4zMTMtMTQuMzYyIDcuMzE5IDcuMzE4YS45OTkuOTk5IDAgMSAwIDEuNDE0LTEuNDE0bC0xLjgyNS0xLjgyNHoiLz48cGF0aCBkPSJNMzAgNDYuNTE4SDJ2LTQyaDU0djI4YTEgMSAwIDEgMCAyIDB2LTI5YTEgMSAwIDAgMC0xLTFIMWExIDEgMCAwIDAtMSAxdjQ0YTEgMSAwIDAgMCAxIDFoMjlhMSAxIDAgMSAwIDAtMnoiLz48L3N2Zz4=`,G_=H_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NjAgNDYwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0NjAgNDYwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNMjMwIDBDMTAyLjk3NSAwIDAgMTAyLjk3NSAwIDIzMHMxMDIuOTc1IDIzMCAyMzAgMjMwIDIzMC0xMDIuOTc0IDIzMC0yMzBTMzU3LjAyNSAwIDIzMCAwem0zOC4zMzMgMzc3LjM2YzAgOC42NzYtNy4wMzQgMTUuNzEtMTUuNzEgMTUuNzFoLTQzLjEwMWMtOC42NzYgMC0xNS43MS03LjAzNC0xNS43MS0xNS43MVYyMDIuNDc3YzAtOC42NzYgNy4wMzMtMTUuNzEgMTUuNzEtMTUuNzFoNDMuMTAxYzguNjc2IDAgMTUuNzEgNy4wMzMgMTUuNzEgMTUuNzFWMzc3LjM2ek0yMzAgMTU3Yy0yMS41MzkgMC0zOS0xNy40NjEtMzktMzlzMTcuNDYxLTM5IDM5LTM5IDM5IDE3LjQ2MSAzOSAzOS0xNy40NjEgMzktMzkgMzl6Ii8+PC9zdmc+`,K_=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAQgAAAEIBarqQRAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAE1SURBVDiNfdI7S0NBEAXgLya1otFgpbYSbISAgpXYi6CmiH9KCAiChaVga6OiWPgfRDQ+0itaGVNosXtluWwcuMzePfM4M3sq8lbHBubwg1dc4m1E/J/N4ghDPOIsfk/4xiEao5KX0McFljN4C9d4QTPXuY99jP3DsIoDPGM6BY5i5yI5R7O4q+ImFkJY2DCh3cAH2klyB+9J1xUMMAG7eCh1a+Mr+k48b5diXrFVwwLuS+BJ9MfR7+G0FHOHhTHhnXNWS87VDF4pcnfQK4Ep7XScNLmPTZgURNKKYENYWDpzW1BhscS1WHS8CDgURFJQrWcoF3c13KKbgg1BYQfy8xZWEzTTw1QZbAoKu8FqJnktdu5hcVSHmchiILzzuaDQvjBzV2m8yohCE1jHfPx/xhU+y4G/D75ELlRJsSYAAAAASUVORK5CYII=`,q_=function(){function e(){}return e.createDefault=function(){return{hasPermission:!1,lastUsedCameraId:null}},e}(),J_=function(){function e(){this.data=q_.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=q_.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}(),Y_=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=l_.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=l_.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}(),X_=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=G_,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=K_,this.infoIcon.style.opacity=`1`):(this.isShowingInfoIcon=!0,this.onTapOut(),this.infoIcon.src=G_,this.infoIcon.style.opacity=`0.6`)},e}(),Z_=function(){function e(){var e=this;this.infoDiv=new Y_,this.infoIcon=new X_(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())})},$_=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}}},ev=function(){function e(){}return e.hasPermissions=function(){return Q_(this,void 0,void 0,function(){var e,t,n,r;return $_(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}(),tv=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 $g.DEFAULT_SUPPORTED_SCAN_TYPE;var t=$g.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(!$g.DEFAULT_SUPPORTED_SCAN_TYPE.includes(i))throw`Unsupported scan type ${i}`}return e},e}(),nv=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}(),rv=function(){function e(){}return e.createElement=function(e,t){var n=document.createElement(e);return n.id=t,n.classList.add(nv.ALL_ELEMENT_CLASS),e===`button`&&n.setAttribute(`type`,`button`),n},e}(),iv=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())})},av=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}}},ov=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 iv(this,void 0,void 0,function(){var e,t;return av(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?c_.torchOffButton():c_.torchOnButton()),this.isTorchOn=t):this.propagateFailure(t),this.buttonController.enable()},e.prototype.propagateFailure=function(e,t){var n=e?c_.torchOnFailedMessage():c_.torchOffFailedMessage();t&&(n+=`; Error = `+t),this.onTorchActionFailureCallback(n)},e.prototype.reset=function(){this.isTorchOn=!1},e}(),sv=function(){function e(e,t){this.onTorchActionFailureCallback=t,this.torchButton=rv.createElement(`button`,nv.TORCH_BUTTON_ID),this.torchController=new ov(e,this,t)}return e.prototype.render=function(e,t){var n=this;this.torchButton.innerText=c_.torchOnButton(),this.torchButton.style.display=t.display,this.torchButton.style.marginLeft=t.marginLeft;var r=this;this.torchButton.addEventListener(`click`,function(e){return iv(n,void 0,void 0,function(){return av(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(nv.TORCH_BUTTON_CLASS_TORCH_OFF),r.torchButton.classList.add(nv.TORCH_BUTTON_CLASS_TORCH_ON)):(r.torchButton.classList.remove(nv.TORCH_BUTTON_CLASS_TORCH_ON),r.torchButton.classList.add(nv.TORCH_BUTTON_CLASS_TORCH_OFF)),[2]}})})}),e.appendChild(this.torchButton)},e.prototype.updateTorchCapability=function(e){this.torchController=new ov(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=c_.torchOnButton(),this.torchController.reset()},e.create=function(t,n,r,i){var a=new e(n,i);return a.render(t,r),a},e}(),cv=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=rv.createElement(`button`,nv.FILE_SELECTION_BUTTON_ID),this.setInitialValueToButton(),this.fileSelectionButton.addEventListener(`click`,function(e){r.click()}),r.append(this.fileSelectionButton),this.fileScanInput=rv.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=c_.dragAndDropMessage();break}}o||(a.innerText=c_.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=c_.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=c_.fileSelectionChooseAnother()+` - `+e;this.fileSelectionButton.innerText=r},e.prototype.setInitialValueToButton=function(){var e=c_.fileSelectionChooseImage()+` - `+c_.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}(),lv=function(){function e(e){this.selectElement=rv.createElement(`select`,nv.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=`${c_.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=[c_.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}(),uv=function(){function e(){this.onChangeCallback=null,this.zoomElementContainer=document.createElement(`div`),this.rangeInput=rv.createElement(`input`,nv.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=c_.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=c_.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}(),dv;(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`})(dv||={});function fv(e){return{fps:e.fps,qrbox:e.qrbox,aspectRatio:e.aspectRatio,disableFlip:e.disableFlip,videoConstraints:e.videoConstraints}}function pv(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 tv(this.config.supportedScanTypes),this.currentScanType=this.scanTypeSelector.getDefaultScanType(),this.sectionSwapAllowed=!0,this.logger=new i_(this.verbose),this.persistedDataManager=new J_,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(c_.lastMatch(t),dv.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 V_(this.getScanRegionId(),pv(this.config,this.verbose))},e.prototype.pause=function(e){(a_(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||=$g.SCAN_DEFAULT_FPS,e.rememberLastUsedCamera!==!$g.DEFAULT_REMEMBER_LAST_CAMERA_USED&&(e.rememberLastUsedCamera=$g.DEFAULT_REMEMBER_LAST_CAMERA_USED),e.supportedScanTypes||=$g.DEFAULT_SUPPORTED_SCAN_TYPE,e):{fps:$g.SCAN_DEFAULT_FPS,rememberLastUsedCamera:$g.DEFAULT_REMEMBER_LAST_CAMERA_USED,supportedScanTypes:$g.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),tv.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 Z_().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(c_.cameraPermissionRequesting());var i=function(){n||r.createPermissionButton(e,t)};V_.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(c_.noCameraFound(),dv.STATUS_WARNING),i())}).catch(function(e){r.persistedDataManager.setHasPermission(!1),n?n.disabled=!1:i(),r.setHeaderMessage(e,dv.STATUS_WARNING),r.showHideScanTypeSwapLink(!0)})},e.prototype.createPermissionButton=function(e,t){var n=this,r=rv.createElement(`button`,this.getCameraPermissionButtonId());r.innerText=c_.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(tv.isCameraScanType(this.currentScanType)&&this.persistedDataManager.hasCameraPermissions()){ev.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=tv.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=tv.isFileScanType(this.currentScanType),n=this,r=function(e){if(!n.html5Qrcode)throw`html5Qrcode not defined`;tv.isFileScanType(n.currentScanType)&&(n.setHeaderMessage(c_.loadingImage()),n.html5Qrcode.scanFileV2(e,!0).then(function(e){n.resetHeaderMessage(),n.qrCodeSuccessCallback(e.decodedText,e)}).catch(function(e){n.setHeaderMessage(e,dv.STATUS_WARNING),n.qrCodeErrorCallback(e,r_.createFrom(e))}))};this.fileSelectionUi=cv.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=uv.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=o_(r,n.min(),n.max()),i.setValues(n.min(),n.max(),r,n.step()),i.show()}},o=lv.create(r,e),s=document.createElement(`span`),c=rv.createElement(`button`,nv.CAMERA_START_BUTTON_ID);c.innerText=c_.scanButtonStartScanningText(),s.appendChild(c);var l=rv.createElement(`button`,nv.CAMERA_STOP_BUTTON_ID);l.innerText=c_.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=sv.create(s,e.torchFeature(),{display:`none`,marginLeft:`5px`},function(e){n.setHeaderMessage(e,dv.STATUS_WARNING)}),u.show()};r.appendChild(s);var f=function(e){e||(c.style.display=`none`),c.innerText=c_.scanButtonStartScanningText(),c.style.opacity=`1`,c.disabled=!1,e&&(c.style.display=`inline-block`)};if(c.addEventListener(`click`,function(e){c.innerText=c_.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,fv(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,dv.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,dv.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=c_.textIfCameraScanSelected(),n=c_.textIfFileScanSelected(),r=document.getElementById(this.getDashboardSectionId()),i=document.createElement(`div`);i.style.textAlign=`center`;var a=rv.createElement(`span`,this.getDashboardSectionSwapLinkId());a.style.textDecoration=`underline`,a.style.cursor=`pointer`,a.innerText=tv.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,tv.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()){ev.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||=dv.STATUS_DEFAULT;var n=this.getHeaderMessageDiv();switch(n.innerText=e,n.style.display=`block`,t){case dv.STATUS_SUCCESS:n.style.background=`rgba(106, 175, 80, 0.26)`,n.style.color=`#477735`;break;case dv.STATUS_WARNING:n.style.background=`rgba(203, 36, 49, 0.14)`,n.style.color=`#cb2431`;break;case dv.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=U_,this.cameraScanImage.alt=c_.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=W_,this.fileScanImage.alt=c_.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 nv.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 nv.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 mv;(function(e){e[e.BACK=1]=`BACK`,e[e.FRONT=2]=`FRONT`})(mv||={});var hv;(function(e){e[e.PORTRAIT=1]=`PORTRAIT`,e[e.LANDSCAPE=2]=`LANDSCAPE`,e[e.ADAPTIVE=3]=`ADAPTIVE`})(hv||={});var gv;(function(e){e[e.ALL=17]=`ALL`})(gv||={});var _v=Object.assign(Object.assign({},Jg),gv),vv;(function(e){e.ZXING=`zxing`,e.MLKIT=`mlkit`})(vv||={});var yv=[{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 bv(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 xv=dh(`CapacitorBarcodeScanner`,{web:()=>(bv(yv),Xr(()=>import(`./web-3Ems3Koj.js`).then(e=>new e.CapacitorBarcodeScannerWeb),[]))}),Sv=class{static async scanBarcode(e){return e.scanInstructions=e.scanInstructions||` `,e.scanButton=e.scanButton||!1,e.scanText=e.scanText||` `,e.cameraDirection=e.cameraDirection||mv.BACK,e.scanOrientation=e.scanOrientation||hv.ADAPTIVE,xv.scanBarcode(e)}};function Cv(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 wv(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 Tv(){let[e,t]=(0,Y.useState)(!1);return{scan:(0,Y.useCallback)(async()=>{if(!on())return{value:null,error:null};t(!0);try{let e=await Sv.scanBarcode({hint:_v.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 wv(e)?{value:null,error:null}:Cv(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:on()}}function Ev(){let[e,t]=(0,Y.useState)(!0),[n,i]=(0,Y.useState)(_n),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),d=Tv();(0,Y.useEffect)(()=>{let e=!0;return(async()=>{try{let n=await fetch(`${We()}/health`,{method:`GET`});e&&t(n.ok)}catch{e&&t(!1)}})(),()=>{e=!1}},[]);let f=(0,Y.useCallback)(async()=>{let e=Tn(n);if(e){o(null),u(!0);try{if(!await xn(e)){o(e);return}nn(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){i(e.value),o(null);let t=Tn(e.value);if(!t){c(`The scanned QR code did not contain a valid server address.`);return}u(!0);try{if(!await xn(t)){o(t);return}nn(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)(R,{value:n,onChange:e=>{i(e.target.value),o(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)(Rt,{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)(cn,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(He,{className:`h-4 w-4`})})]}),s&&(0,$.jsxs)(di,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsx)(`p`,{className:`flex-1`,children:s}),(0,$.jsx)(Rt,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>c(null),children:(0,$.jsx)(Ce,{className:`h-4 w-4`})})]}),a&&(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 `,a,`. Please check that you are on the same network and that the Tarsk server is running and accessible on the network.`]}),(0,$.jsx)(Rt,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>o(null),children:(0,$.jsx)(Ce,{className:`h-4 w-4`})})]}),(0,$.jsx)(ni,{children:(0,$.jsx)(Rt,{onClick:()=>void f(),disabled:!n.trim()||l,children:l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cn,{className:`mr-2 h-4 w-4 animate-spin`}),`Connecting...`]}):`Connect`})}),(0,$.jsxs)(di,{variant:`hint`,className:`mb-0`,children:[(0,$.jsx)(`p`,{className:r.bodyMuted,children:`Start the Tarsk server on your local machine by running:`}),(0,$.jsx)(`code`,{className:V(r.mono,`mt-2 block rounded bg-background/60 px-2 py-1 text-foreground`),children:`npx tarsk --server`})]})]})})}var Dv=(0,Y.lazy)(()=>Xr(()=>import(`./dialogs-config-COzptu1b.js`).then(e=>e.t),__vite__mapDeps([3,1]))),Ov=(0,Y.lazy)(()=>Xr(()=>import(`./onboarding-pVfMmu_a.js`).then(e=>e.t),__vite__mapDeps([4,1,5,3])));function kv(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)(Dv,{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)(Gg,{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)(Kg,{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)(Ov,{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)(Ev,{}),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 Av=(0,Y.createContext)(null);function jv(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(Mv)},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)(Av.Provider,{value:u,children:n}),t[4]=n,t[5]=u,t[6]=d):d=t[6],d}function Mv(e){return e+1}function Nv(){let e=(0,Y.useContext)(Av);if(!e)throw Error(`useBrowserTab must be used within a BrowserTabProvider`);return e}function Pv(e){let t=e.trim();return t?t.startsWith(`http://`)||t.startsWith(`https://`)?t:`http://${t}`:``}function Fv(){return document.querySelector(`electrobun-webview`)}function Iv(e=2e4){return new Promise((t,n)=>{let r=Date.now();function i(){let a=Fv();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 Lv(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 Rv(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=Fv();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 zv(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 Iv();t.syncDimensions(!0),await $m(r,{action:`set_viewport`,preset:e,webview_id:t.webviewId})}catch(t){console.error(`[browser-tool] failed to set viewport`,t),await $m(r,{action:`set_viewport`,preset:e,error:t instanceof Error?t.message:String(t)})}return}if(A(i.action)){try{await $m(r,await Lv(await Iv(),i,t))}catch(e){console.error(`[browser-tool] failed to execute host browser action`,e),await $m(r,{action:i.action,error:e instanceof Error?e.message:String(e)})}return}Rv(r)}}function Bv(){let{activeMainTab:e,setActiveMainTab:t}=Js(),{setDevServerUrl:n,devServerUrl:r}=nd(),{setBrowserDeviceMode:i}=Nv(),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(Gm,e),function(){window.removeEventListener(Gm,e)}},[]),(0,Y.useEffect)(()=>{if(!yt())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=Pv(n);e&&u.current(e)}zv(t,s.current||``,d.current)}return window.addEventListener(Wm,e),function(){window.removeEventListener(Wm,e)}},[])}var Vv=or,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=V(`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});Hv.displayName=Yn.displayName;var Uv=re(`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`}}),Wv=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=V(Uv({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});Wv.displayName=mr.displayName;var Gv=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),i,a;n[0]===e?(i=n[1],a=n[2]):({className:i,...a}=e,n[0]=e,n[1]=i,n[2]=a);let o;n[3]===i?o=n[4]:(o=V(`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`,r.body,i),n[3]=i,n[4]=o);let s;return n[5]!==a||n[6]!==t||n[7]!==o?(s=(0,$.jsx)(dr,{ref:t,className:o,...a}),n[5]=a,n[6]=t,n[7]=o,n[8]=s):s=n[8],s});Gv.displayName=dr.displayName;var Kv=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=V(`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)(Ce,{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});Kv.displayName=$n.displayName;var qv=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),i,a;n[0]===e?(i=n[1],a=n[2]):({className:i,...a}=e,n[0]=e,n[1]=i,n[2]=a);let o;n[3]===i?o=n[4]:(o=V(r.dialogTitle,i),n[3]=i,n[4]=o);let s;return n[5]!==a||n[6]!==t||n[7]!==o?(s=(0,$.jsx)(Yr,{ref:t,className:o,...a}),n[5]=a,n[6]=t,n[7]=o,n[8]=s):s=n[8],s});qv.displayName=Yr.displayName;var Jv=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),i,a;n[0]===e?(i=n[1],a=n[2]):({className:i,...a}=e,n[0]=e,n[1]=i,n[2]=a);let o;n[3]===i?o=n[4]:(o=V(r.body,`opacity-90 text-muted-foreground group-[.destructive]:text-destructive-foreground`,i),n[3]=i,n[4]=o);let s;return n[5]!==a||n[6]!==t||n[7]!==o?(s=(0,$.jsx)(rr,{ref:t,className:o,...a}),n[5]=a,n[6]=t,n[7]=o,n[8]=s):s=n[8],s});Jv.displayName=rr.displayName;function Yv(){let e=(0,X.c)(5),{toasts:t}=$a(),n;e[0]===t?n=e[1]:(n=t.map(Xv),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(Hv,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(Vv,{duration:1e4,children:[n,r]}),e[3]=n,e[4]=i),i}function Xv(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,$.jsxs)(Wv,{...a,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(qv,{children:n}),r&&(0,$.jsx)(Jv,{children:r})]}),i,(0,$.jsx)(Kv,{})]},t)}function Zv(){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)(Zv),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 $v(){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 ey(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)($v,{}),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 ty(e,t){let n=e.getReader(),r=new TextDecoder,i=``;try{for(;;){let{done:e,value:a}=await n.read();if(e)break;i+=r.decode(a,{stream:!0});let o=i.split(`
71
+ `);i=o.pop()??``;for(let e of o){let n=e.trim();if(n)try{await t(JSON.parse(n),n)}catch{await t(n,n)}}}if(i.trim())try{await t(JSON.parse(i),i)}catch{await t(i,i)}}finally{n.releaseLock()}}async function ny(e,t){await ty(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 ry(){let e=(0,X.c)(14),t=Ia(),n=Q(oy),r=ai(`projects:bootstrap:${Q(ay)}`,y),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(iy);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 iy(e){return e.isSelected}function ay(e){return e.configUpdatedAt}function oy(e){return e.selectedThreadId}function sy(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}),en(),li(`projects:bootstrap:`);let e=await y();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}),p(e,n).catch(e=>{console.error(`Failed to select thread:`,e)})},[t,i,r]),f=(0,Y.useCallback)(async n=>{t({type:Z.SetCreatingProject,isCreating:!0});try{let r=await n.apiCall();if(!r){t({type:Z.SetCreatingProject,isCreating:!1}),await l();return}let i=n.useTerminalDispatch?o:t;i({type:Z.ClearTerminalOutput}),i({type:Z.SetTerminalOpen,open:!0}),i({type:Z.AppendTerminalLine,line:{type:`system`,content:n.initialMessage}});let a=r.getReader(),s=new TextDecoder,u=``,d=null,f=!1,p=null,m=null;for(;;){let{done:e,value:r}=await a.read();if(e)break;u+=s.decode(r,{stream:!0});let o=u.split(`
72
+ `);u=o.pop()??``;for(let e of o){let r=e.trim();if(r)try{let e=JSON.parse(r);if(e.type===`progress`)!f&&e.threadId&&e.projectId&&(f=!0,p=e.projectId,m=e.threadId,t({type:Z.AddCreatingProject,projectId:e.projectId,threadId:e.threadId,projectName:n.optimisticProjectName,gitUrl:n.gitUrl??``}),t({type:Z.AddProcessingThread,threadId:e.threadId})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`output`,content:e.message}});else if(e.type===`complete`){if(e.project){d=e.project.id;let r=n.includeThreadPath&&e.project.threads?.length>0?`${e.project.path}/${e.project.threads[0]}`:e.project.path;i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Project created successfully at: ${r}`}}),t({type:Z.SetTerminalOpen,open:!1}),n.handleSetupScript&&e.suggestedSetupScript&&c({projectId:e.project.id,command:e.suggestedSetupScript,remainingScripts:e.project.pendingSetupScripts??[]})}}else e.type===`error`&&(f&&p&&(t({type:Z.RemoveCreatingProject,projectId:p}),m&&t({type:Z.RemoveProcessingThread,threadId:m})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`error`,content:`Error: ${e.message}`}}))}catch(e){console.error(`Failed to parse ${n.logTag} event`,e)}}}t({type:Z.SetCreatingProject,isCreating:!1}),f&&m&&t({type:Z.RemoveProcessingThread,threadId:m}),en();let h=await y();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]),h=(0,Y.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await f({apiCall:()=>Mn(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[f]),g=(0,Y.useCallback)(async(e,t,n)=>{await f({apiCall:()=>we(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[f]),_=(0,Y.useCallback)(async e=>{await f({apiCall:()=>In(e),initialMessage:`Creating folder "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create folder`,catchErrorPrefix:`Failed to create folder`})},[f]),v=(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 m(e,r);if(!o){await l();return}let s=o.getReader(),c=new TextDecoder,u=``,d=!1,f=null,p=!0,h=[{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 h)t({type:Z.AppendTerminalLine,threadId:f,line:e});h.length=0}let r={type:`output`,content:n.message};f?t({type:Z.AppendTerminalLine,threadId:f,line:r}):h.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}):h.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}),en(),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]),b=(0,Y.useCallback)(async(e,n)=>{t({type:Z.AddDeletingThread,threadId:n}),t({type:Z.ClearChatInputDraft,threadId:n});try{await te(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]),x=(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 ce(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]),S=(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 d(r,n,!0);s&&await ny(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:h,handleCreateWebApp:g,handleCreateFolder:_,handleOpenFolder:(0,Y.useCallback)(async()=>{await f({apiCall:an,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[f]),handleCreateThread:v,handleDeleteThread:b,confirmDeleteProject:x,pendingSetupScriptConfirmation:s,resolveSetupScriptConfirmation:S}}function cy(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(ly),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 ly(){return document.hasFocus()}var uy=null;function dy(){uy??=new Audio(`/pop.wav`),uy.currentTime=0,uy.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function fy(){let e=Ia(),t=Fa(),n=Q(e=>e.processingThreadIds),r=Q(e=>e.completedThreadIds),i=cy(),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=ah(await Rn()),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&&dy(),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 py(){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:Ad.onboarding.status(),queryFn:un,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:Ad.app.update(),queryFn:Yt,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 sn()}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 my(e){return e.startsWith(`/settings`)||e===`/review`}function hy(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}=Js(),{triggerExplorerRefresh:f}=Qs(),{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&&!my(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 L,R;t[30]!==c||t[31]!==n||t[32]!==u?(L=()=>{let e=S.current===`review`;S.current=c,c===`review`&&!e&&!C.current&&n&&u(),C.current=!1},R=[c,n,u],t[30]=c,t[31]=n,t[32]=u,t[33]=L,t[34]=R):(L=t[33],R=t[34]),(0,Y.useEffect)(L,R);let ee,z;t[35]!==c||t[36]!==g||t[37]!==h||t[38]!==r||t[39]!==d?(ee=()=>{let e=w.current===`tasks`;w.current=c,c===`tasks`&&!e&&!T.current&&r&&!g&&!h&&d(),T.current=!1},z=[c,r,g,h,d],t[35]=c,t[36]=g,t[37]=h,t[38]=r,t[39]=d,t[40]=ee,t[41]=z):(ee=t[40],z=t[41]),(0,Y.useEffect)(ee,z);let te;return t[42]!==g||t[43]!==h?(te={isSettingsRoute:h,isReviewRoute:g,explorerTabClickedRef:x,reviewTabClickedRef:C,tasksTabClickedRef:T},t[42]=g,t[43]=h,t[44]=te):te=t[44],te}function gy(e,t){let n=(0,X.c)(8),r=Ia(),i=Q(_y),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 _y(e){return e.sidebarOpen}var vy=dh(`App`,{web:()=>Xr(()=>import(`./web-BYoghlKk.js`).then(e=>new e.AppWeb),[])}),yy=1e10,by=1e3;function xy(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 Sy(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=by}=e;e.transport&&i(e.transport),e.requestHandler&&a(e.requestHandler),e._debugHooks&&(t=e._debugHooks);let s=0;function c(){return s<=yy?++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 xy([`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 xy([`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 xy([`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 xy([`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 Cy(e,t){let n=Sy({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 wy=window.__electrobunWebviewId,Ty=window.__electrobunRpcSocketPort,Ey=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:${Ty}/socket?webviewId=${wy}`);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 Cy(`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 Dy(){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)(jy,t);let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=[],e[1]=n):n=e[1],(0,Y.useEffect)(Oy,n)}function Oy(){if(!on())return;let e=vy.addListener(`backButton`,Ay);return()=>{e.then(ky)}}function ky(e){return e.remove()}function Ay(e){let{canGoBack:t}=e;t?window.history.back():vy.exitApp()}function jy(){window.__electrobunWebviewId&&new Ey({})}function My(e){let t=(0,X.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(Gs,{children:(0,$.jsx)(td,{children:(0,$.jsx)(Xs,{children:(0,$.jsx)(jv,{children:n})})})}),t[0]=n,t[1]=r),r}function Ny(){return Bv(),null}function Py(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={queryKey:[`health-status`,We()],queryFn:Fy,refetchInterval:3e4,retry:!1},e[0]=t):t=e[0],Wr(t)}async function Fy(){let e=await fetch(`${We()}/health`,{method:`GET`});if(!e.ok)throw Error(`Failed to load health status`);return e.json()}function Iy(){let e=(0,X.c)(105),t=Ia(),n=er(),r=fr(),i=Q(Vy),a=Q(By),o=Q(zy),s=Q(Ry),c=Q(Ly);Dy();let l=Zd(),u;e[0]===l?u=e[1]:(u=l||on(),e[0]=l,e[1]=u);let d=u,{data:f}=Py(),[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:w,handleCreateProject:T,handleCreateWebApp:E,handleCreateFolder:D,handleOpenFolder:O,handleCreateThread:k,handleDeleteThread:A,confirmDeleteProject:j,refreshProjects:M,pendingSetupScriptConfirmation:N,resolveSetupScriptConfirmation:F}=sy(x),{processingThreadIds:I,completedThreadIds:L,clearCompleted:R}=fy(),{setActiveMainTab:ee}=Js(),{triggerBrowserReset:z}=Nv(),{showOnboarding:te,setShowOnboarding:ne,updateAvailable:re,updatingApp:ie,handleUpdateApp:B}=py(),ae;e[3]!==l||e[4]!==a||e[5]!==i?(ae={selectedThreadId:i,selectedProjectId:a,isMobile:l,mainTabBarRef:b},e[3]=l,e[4]=a,e[5]=i,e[6]=ae):ae=e[6];let{isSettingsRoute:oe,isReviewRoute:se,explorerTabClickedRef:ce,reviewTabClickedRef:le,tasksTabClickedRef:ue}=hy(ae);gy(oe,se);let de;e[7]===S?de=e[8]:(de=e=>{let t=S.find(t=>t.projectId===e);t&&v({id:t.projectId,name:C(t)})},e[7]=S,e[8]=de);let fe=de,H;e[9]===k?H=e[10]:(H=e=>{m(e),k(e,void 0)},e[9]=k,e[10]=H);let pe=H,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]!==R||e[17]!==t||e[18]!==w||e[19]!==r.pathname||e[20]!==n||e[21]!==i||e[22]!==ee||e[23]!==z||e[24]!==d?(ge=(e,a)=>{m(null),R(a),r.pathname!==`/`&&n(`/`),ee(`chat`),i!==a&&z(),w(e,a),d&&t({type:Z.CloseSidebar})},e[16]=R,e[17]=t,e[18]=w,e[19]=r.pathname,e[20]=n,e[21]=i,e[22]=ee,e[23]=z,e[24]=d,e[25]=ge):ge=e[25];let U=ge,_e,ve;e[26]===o?(_e=e[27],ve=e[28]):(_e=()=>{o?y.current?.expand():y.current?.collapse()},ve=[o],e[26]=o,e[27]=_e,e[28]=ve),(0,Y.useEffect)(_e,ve);let ye;e[29]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,$.jsx)(Ny,{}),e[29]=ye):ye=e[29];let be;e[30]===Symbol.for(`react.memo_cache_sentinel`)?(be=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(ry,{})}),e[30]=be):be=e[30];let xe=d?100:25,Se=d?50:12,Ce=d?100:32,W=d&&!o&&`hidden`,we;e[31]===W?we=e[32]:(we=V(`border-r border-transparent`,W),e[31]=W,e[32]=we);let Te;e[33]===Symbol.for(`react.memo_cache_sentinel`)?(Te=()=>g(!0),e[33]=Te):Te=e[33];let Ee=!o,De=f?.isDevMode===!0,Oe;e[34]!==L||e[35]!==c||e[36]!==s||e[37]!==p||e[38]!==pe||e[39]!==fe||e[40]!==A||e[41]!==U||e[42]!==B||e[43]!==I||e[44]!==S||e[45]!==a||e[46]!==i||e[47]!==Ee||e[48]!==De||e[49]!==re||e[50]!==ie?(Oe=(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(so,{projects:S,selectedThreadId:i,selectedProjectId:a,processingThreadIds:I,completedThreadIds:L,deletingThreadIds:s,deletingProjectIds:c,onSelectThread:U,onCreateProject:Te,onCreateThread:pe,onDeleteThread:A,onDeleteProject:fe,collapsed:Ee,updateAvailable:re,updatingApp:ie,onUpdateApp:B,isDevMode:De,expandProjectId:p})}),e[34]=L,e[35]=c,e[36]=s,e[37]=p,e[38]=pe,e[39]=fe,e[40]=A,e[41]=U,e[42]=B,e[43]=I,e[44]=S,e[45]=a,e[46]=i,e[47]=Ee,e[48]=De,e[49]=re,e[50]=ie,e[51]=Oe):Oe=e[51];let ke;e[52]!==xe||e[53]!==Se||e[54]!==Ce||e[55]!==we||e[56]!==Oe?(ke=(0,$.jsx)(hg,{ref:y,defaultSize:xe,minSize:Se,maxSize:Ce,collapsible:!0,collapsedSize:0,className:we,children:Oe}),e[52]=xe,e[53]=Se,e[54]=Ce,e[55]=we,e[56]=Oe,e[57]=ke):ke=e[57];let Ae;e[58]!==o||e[59]!==d?(Ae=!d&&(0,$.jsx)(gg,{withHandle:!0,className:o?`ml-[-40px]`:``}),e[58]=o,e[59]=d,e[60]=Ae):Ae=e[60];let je=d&&o&&`hidden`,Me;e[61]===je?Me=e[62]:(Me=V(`overflow-hidden`,je),e[61]=je,e[62]=Me);let Ne=i??void 0,Pe;e[63]!==ce||e[64]!==pe||e[65]!==se||e[66]!==oe||e[67]!==le||e[68]!==a||e[69]!==i||e[70]!==ue?(Pe=(0,$.jsx)(qp,{children:(0,$.jsx)(Wg,{selectedThreadId:i,selectedProjectId:a,isReviewRoute:se,isSettingsRoute:oe,onCreateThread:pe,mainTabBarRef:b,explorerTabClickedRef:ce,reviewTabClickedRef:le,tasksTabClickedRef:ue})}),e[63]=ce,e[64]=pe,e[65]=se,e[66]=oe,e[67]=le,e[68]=a,e[69]=i,e[70]=ue,e[71]=Pe):Pe=e[71];let Fe;e[72]!==Ne||e[73]!==Pe?(Fe=(0,$.jsx)(Hm,{threadId:Ne,children:Pe}),e[72]=Ne,e[73]=Pe,e[74]=Fe):Fe=e[74];let Ie;e[75]!==Me||e[76]!==Fe?(Ie=(0,$.jsx)(hg,{minSize:40,className:Me,children:Fe}),e[75]=Me,e[76]=Fe,e[77]=Ie):Ie=e[77];let Le;e[78]===Symbol.for(`react.memo_cache_sentinel`)?(Le=e=>!e&&v(null),e[78]=Le):Le=e[78];let Re;e[79]!==j||e[80]!==_?(Re=()=>{_&&(j(_.id),v(null))},e[79]=j,e[80]=_,e[81]=Re):Re=e[81];let ze;e[82]===M?ze=e[83]:(ze=()=>{M()},e[82]=M,e[83]=ze);let Be;e[84]!==_||e[85]!==D||e[86]!==T||e[87]!==E||e[88]!==O||e[89]!==N||e[90]!==F||e[91]!==ne||e[92]!==h||e[93]!==te||e[94]!==Re||e[95]!==ze?(Be=(0,$.jsx)(kv,{showCreateProject:h,onCreateProjectOpenChange:g,onSubmitClone:T,onSubmitWebApp:E,onSubmitFolder:D,onOpenFolder:O,deleteProject:_,onDeleteProjectOpenChange:Le,onConfirmDeleteProject:Re,pendingSetupScriptConfirmation:N,onResolveSetupScriptConfirmation:F,showOnboarding:te,onOnboardingOpenChange:ne,onOnboardingComplete:ze}),e[84]=_,e[85]=D,e[86]=T,e[87]=E,e[88]=O,e[89]=N,e[90]=F,e[91]=ne,e[92]=h,e[93]=te,e[94]=Re,e[95]=ze,e[96]=Be):Be=e[96];let Ve;e[97]!==ke||e[98]!==Ae||e[99]!==Ie||e[100]!==Be?(Ve=(0,$.jsxs)(mg,{direction:`horizontal`,className:`h-screen bg-background`,children:[ke,Ae,Ie,Be]}),e[97]=ke,e[98]=Ae,e[99]=Ie,e[100]=Be,e[101]=Ve):Ve=e[101];let He;e[102]===Symbol.for(`react.memo_cache_sentinel`)?(He=(0,$.jsx)(Yv,{}),e[102]=He):He=e[102];let Ue;return e[103]===Ve?Ue=e[104]:(Ue=(0,$.jsxs)($.Fragment,{children:[ye,be,(0,$.jsxs)(P,{delayDuration:200,children:[Ve,He]})]}),e[103]=Ve,e[104]=Ue),Ue}function Ly(e){return e.deletingProjectIds}function Ry(e){return e.deletingThreadIds}function zy(e){return e.sidebarOpen}function By(e){return e.selectedProjectId}function Vy(e){return e.selectedThreadId}function Hy(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(My,{children:(0,$.jsx)(Iy,{})}),e[0]=t):t=e[0],t}function Uy(){let e=(0,X.c)(3),[t]=(0,Y.useState)(Na),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(Hy,{}),e[0]=n):n=e[0];let r;return e[1]===t?r=e[2]:(r=(0,$.jsx)(ey,{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 Wy=75,Gy=125,Ky=100;function qy(){return window.matchMedia(`(max-width: 767px)`).matches}function Jy(e){let t=qe(e,qy());document.documentElement.style.fontSize=`${t}%`}var Yy=!1;function Xy(){Yy||(Yy=!0,window.matchMedia(`(max-width: 767px)`).addEventListener(`change`,()=>{Jy(Qt(Ky))}))}function Zy(){let[e,t]=(0,Y.useState)(()=>Qt(Ky));(0,Y.useEffect)(()=>{Xy(),Jy(e)},[e]);function n(e){let n=Math.max(Wy,Math.min(Gy,Math.round(e)));t(n),S(n)}return{scale:e,updateScale:n,resetScale:(0,Y.useCallback)(()=>{n(Ky)},[]),min:Wy,max:Gy,default:Ky}}function Qy(){Xy(),Jy(Qt(Ky))}var $y;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})($y||={});var eb;(function(e){e.None=`NONE`,e.Slide=`SLIDE`,e.Fade=`FADE`})(eb||={});var tb=dh(`StatusBar`),nb=`--app-viewport-height`;function rb(){let e=window.visualViewport,t=Math.round(Nt()===`ios`?window.innerHeight:e?.height??window.innerHeight);document.documentElement.style.setProperty(nb,`${t}px`)}function ib(){rb(),requestAnimationFrame(rb)}function ab(){document.documentElement.dataset.nativeShell=`true`,ib(),window.addEventListener(`resize`,rb),window.addEventListener(`orientationchange`,ib);let e=window.visualViewport;e?.addEventListener(`resize`,rb),e?.addEventListener(`scroll`,rb)}async function ob(){try{await tb.setOverlaysWebView({overlay:!0}),await tb.show(),ib()}catch{}}async function sb(){try{let e=Nt()===`ios`?og.None:og.Body;await sg.setResizeMode({mode:e})}catch{}}function cb(){on()&&(ab(),ob(),sb(),document.addEventListener(`visibilitychange`,()=>{if(document.visibilityState===`visible`){ib(),ob();return}kh()}))}Qy(),cb();var lb=`tarsk-chunk-reload`;function ub(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 db(){sessionStorage.getItem(lb)||(sessionStorage.setItem(lb,`1`),window.location.reload())}window.addEventListener(`unhandledrejection`,e=>{ub(e.reason)&&(e.preventDefault(),db())}),window.addEventListener(`vite:preloadError`,e=>{e.preventDefault(),db()}),sessionStorage.removeItem(lb);var fb=!1;window.addEventListener(`resize`,()=>{fb||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100%)`),!0)});var pb=on()?Jn:Nr;(0,Ai.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Y.StrictMode,{children:(0,$.jsx)(pb,{children:(0,$.jsx)(Uy,{})})}));export{Qs as A,Z as B,Jl as C,Yc as D,Ul as E,Va as F,Ra as I,Ia as L,us as M,ro as N,Zc as O,Qa as P,Q as R,ql as S,$l as T,hm as _,V_ as a,nd as b,Sg as c,mg as d,Wh as f,vm as g,_m as h,_v as i,Js as j,Xc as k,gg as l,Zm as m,Nv as n,wg as o,fh as p,hv as r,Tg as s,Zy as t,hg as u,jp as v,Ql as w,Hl as x,Zd as y,La as z};