tarsk 0.5.49 → 0.5.51

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 (90) hide show
  1. package/README.md +85 -3
  2. package/dist/index.js +10869 -8554
  3. package/dist/public/assets/{account-view-DxHV7OtO.js → account-view-CGokQA1o.js} +1 -1
  4. package/dist/public/assets/api-BRrGio-B.js +1 -0
  5. package/dist/public/assets/browser-tab-B3BybVD0.js +1 -0
  6. package/dist/public/assets/commit-dialog-BLzHl6oN.js +1 -0
  7. package/dist/public/assets/context-menu-yKNgVtVk.js +1 -0
  8. package/dist/public/assets/create-repo-dialog-DHFloJc3.js +1 -0
  9. package/dist/public/assets/{dialogs-config-BEazgV7k.js → dialogs-config-BF_RyK5j.js} +14 -14
  10. package/dist/public/assets/diff-view-DONeogdk.js +3 -0
  11. package/dist/public/assets/explorer-tab-view-C1Dex751.js +2 -0
  12. package/dist/public/assets/{explorer-tree-CiPMm5ck.js → explorer-tree-BmsrsMXJ.js} +1 -1
  13. package/dist/public/assets/explorer-view-1fAca9It.js +1 -0
  14. package/dist/public/assets/git-history-dialog-DXsSt3e0.js +1 -0
  15. package/dist/public/assets/git-ops-button-Cj3j4bvy.js +2 -0
  16. package/dist/public/assets/history-view-COEFPP2U.js +9 -0
  17. package/dist/public/assets/index-Dsj5zHdU.js +73 -0
  18. package/dist/public/assets/index-DzUALYN4.css +1 -0
  19. package/dist/public/assets/mcp-server-card-3bFOnHFO.js +1 -0
  20. package/dist/public/assets/merged-pr-dialog-C5vgSXwq.js +1 -0
  21. package/dist/public/assets/model-star-rating-GWRgO9pY.js +1 -0
  22. package/dist/public/assets/onboarding-B_n7I3ri.js +1 -0
  23. package/dist/public/assets/project-settings-view-DsVEiQM_.js +1 -0
  24. package/dist/public/assets/providers-list-view-BT5XZP-F.js +1 -0
  25. package/dist/public/assets/pull-request-dialog-BO_7fALs.js +1 -0
  26. package/dist/public/assets/pull-with-changes-dialog-DQSC-HUH.js +1 -0
  27. package/dist/public/assets/push-before-pr-dialog-B9evx_c7.js +1 -0
  28. package/dist/public/assets/radio-group-CNuRXtN5.js +1 -0
  29. package/dist/public/assets/react-vendor-D-z0br-z.js +16 -0
  30. package/dist/public/assets/settings-general-view-BaTUBgdM.js +1 -0
  31. package/dist/public/assets/settings-instructions-view-Bit7tYRh.js +1 -0
  32. package/dist/public/assets/settings-list-Cc_0YmxB.js +1 -0
  33. package/dist/public/assets/settings-mcp-servers-view-BcuuyWhI.js +5 -0
  34. package/dist/public/assets/{settings-models-skeleton-Cse6L-Nd.js → settings-models-skeleton-BfIx9XDs.js} +1 -1
  35. package/dist/public/assets/{settings-models-view-BAxf3eJq.js → settings-models-view-CNFB1Iqn.js} +1 -1
  36. package/dist/public/assets/settings-rules-view-BvelCH4j.js +8 -0
  37. package/dist/public/assets/settings-skills-view-DV-cA6cj.js +3 -0
  38. package/dist/public/assets/settings-slash-commands-view-CKxQnzse.js +1 -0
  39. package/dist/public/assets/settings-subagents-view-DAl5Db-p.js +2 -0
  40. package/dist/public/assets/{settings-system-prompt-view-B1vc2cgC.js → settings-system-prompt-view-BdwsxqMo.js} +1 -1
  41. package/dist/public/assets/settings-view-BxiazdKG.js +2 -0
  42. package/dist/public/assets/{skeleton-6mGMglV0.js → skeleton-DJZ5x6e0.js} +1 -1
  43. package/dist/public/assets/{slug-utils-BT1eqWhW.js → slug-utils-D4uxO5qv.js} +1 -1
  44. package/dist/public/assets/{tabs-iUSYYupj.js → tabs-TGCt-ze0.js} +1 -1
  45. package/dist/public/assets/{terminal-panel-DIpnKR-N.js → terminal-panel-Bh_CKydu.js} +2 -2
  46. package/dist/public/assets/todos-view-DDSSplmi.js +17 -0
  47. package/dist/public/assets/{ui-components-kSaUEA_X.js → ui-components-JEH8JAJ7.js} +1 -1
  48. package/dist/public/assets/{use-deferred-search-DGJskNBr.js → use-deferred-search-BZg7Bt7W.js} +1 -1
  49. package/dist/public/assets/{utils-CECQ_-6N.js → utils-H-1x3dmp.js} +1 -1
  50. package/dist/public/assets/{vosk-speech-CgILeNJR.js → vosk-speech-FJiKHPe4.js} +2 -2
  51. package/dist/public/assets/{web-DGalafxk.js → web-B4cuelyi.js} +1 -1
  52. package/dist/public/assets/{web-BD1sqxMq.js → web-CQpWcSn8.js} +1 -1
  53. package/dist/public/assets/{web-BWAZk7ug.js → web-Cq4yC7dg.js} +1 -1
  54. package/dist/public/assets/{web-Dt5YgbhM.js → web-DOZOaJlj.js} +1 -1
  55. package/dist/public/index.html +8 -8
  56. package/package.json +1 -1
  57. package/dist/public/assets/api-Dhzdgb40.js +0 -1
  58. package/dist/public/assets/browser-tab-qhf-xKwZ.js +0 -1
  59. package/dist/public/assets/commit-dialog-DcVXFOBP.js +0 -1
  60. package/dist/public/assets/context-menu-PIC-g8wy.js +0 -1
  61. package/dist/public/assets/create-repo-dialog-CsjpTBPU.js +0 -1
  62. package/dist/public/assets/diff-view-CGEl0YbC.js +0 -3
  63. package/dist/public/assets/explorer-tab-view--ib_BjId.js +0 -2
  64. package/dist/public/assets/explorer-view-odyQutTO.js +0 -1
  65. package/dist/public/assets/git-history-dialog-qUZ7Qsp4.js +0 -1
  66. package/dist/public/assets/git-ops-button-Bced-_39.js +0 -2
  67. package/dist/public/assets/history-view-BMVTxWTg.js +0 -9
  68. package/dist/public/assets/index-C7FLshNp.css +0 -1
  69. package/dist/public/assets/index-_SOdLUMq.js +0 -73
  70. package/dist/public/assets/mcp-server-card-ChdAZekt.js +0 -1
  71. package/dist/public/assets/merged-pr-dialog-DAXqT4Xe.js +0 -1
  72. package/dist/public/assets/model-star-rating-BzpXBjSo.js +0 -1
  73. package/dist/public/assets/onboarding-Bi5MieW-.js +0 -1
  74. package/dist/public/assets/project-settings-view-CHV6lJG4.js +0 -1
  75. package/dist/public/assets/providers-list-view-Dgid2Wui.js +0 -1
  76. package/dist/public/assets/pull-request-dialog-BFgRF5AH.js +0 -1
  77. package/dist/public/assets/pull-with-changes-dialog-oGP-j8Yw.js +0 -1
  78. package/dist/public/assets/push-before-pr-dialog-BQ0QC6Qu.js +0 -1
  79. package/dist/public/assets/radio-group-n9qyUxmu.js +0 -1
  80. package/dist/public/assets/react-vendor-iDwBzcYF.js +0 -16
  81. package/dist/public/assets/settings-general-view-Vwi9J6Tn.js +0 -1
  82. package/dist/public/assets/settings-instructions-view-8YIr0PO3.js +0 -1
  83. package/dist/public/assets/settings-list-owWkHWxE.js +0 -1
  84. package/dist/public/assets/settings-mcp-servers-view-CCXW_uet.js +0 -5
  85. package/dist/public/assets/settings-rules-view-D3KLTKVZ.js +0 -8
  86. package/dist/public/assets/settings-skills-view-DaqOna-w.js +0 -3
  87. package/dist/public/assets/settings-slash-commands-view-CN8_DTYX.js +0 -1
  88. package/dist/public/assets/settings-subagents-view-BIejA-ck.js +0 -2
  89. package/dist/public/assets/settings-view-DLBIkYoA.js +0 -2
  90. 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-C5vgSXwq.js","assets/dialogs-config-BF_RyK5j.js","assets/onboarding-B_n7I3ri.js","assets/history-view-COEFPP2U.js","assets/git-ops-button-Cj3j4bvy.js","assets/monaco-CZnIWXyV.js","assets/monaco-Br_kD0ds.css","assets/diff-view-DONeogdk.js","assets/context-menu-yKNgVtVk.js","assets/react-vendor-D-z0br-z.js","assets/utils-H-1x3dmp.js","assets/terminal-panel-Bh_CKydu.js","assets/terminal-panel-kHJ-D0s7.css","assets/explorer-tab-view-C1Dex751.js","assets/browser-tab-B3BybVD0.js","assets/settings-view-BxiazdKG.js","assets/settings-models-skeleton-BfIx9XDs.js","assets/skeleton-DJZ5x6e0.js","assets/todos-view-DDSSplmi.js","assets/tabs-TGCt-ze0.js"])))=>i.map(i=>d[i]);
2
+ import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$a as r,$i as i,$n as a,$o as o,$r as s,A as c,Aa as l,An as u,Ao as d,Ar as f,At as p,Ba as m,Bi as h,Bn as g,Bt as _,Co as v,Cr as y,D as b,Dn as x,Dr as S,Dt as C,En as w,Eo as T,Er as E,Fi as D,Fo as O,Fr as k,Ft as A,Ga as j,Gi as M,Go as N,Hi as P,Ht as F,Ia as I,Ii as L,Io as R,Ir as z,It as B,J as ee,Ja as te,Kn as ne,Ko as re,L as ie,Li as ae,Ln as oe,Lo as se,Lr as ce,Ma as le,Mi as V,Mn as ue,N as de,Na as fe,Nn as H,Nr as pe,On as me,Oo as he,Or as ge,Pi as U,Pn as _e,Po as ve,Q as ye,Qa as be,Qi as xe,Qo as Se,Qr as Ce,Ri as we,Rn as Te,Rr as Ee,S as De,Sa as Oe,So as ke,T as Ae,Tn as je,Tr as Me,Tt as Ne,Ua as Pe,Ui as Fe,Va as Ie,Vn as Le,Vo as Re,Vt as ze,Wa as Be,Wn as Ve,Wo as He,Wt as Ue,Xn as We,Xo as Ge,Xr as Ke,Xt as qe,Ya as Je,Yo as Ye,Yr as Xe,Z as Ze,Za as Qe,Zi as $e,Zr as et,_n as tt,_o as nt,_r as rt,aa as it,an as at,ao as ot,ar as st,b as ct,br as W,c as lt,ca as ut,cn as dt,cr as ft,d as pt,do as mt,ds as ht,ei as gt,eo as _t,et as vt,fn as yt,fo as bt,fs as xt,g as St,gn as Ct,go as wt,hn as Tt,ho as Et,hr as Dt,ht as G,ia as K,in as Ot,io as kt,ir as At,it as jt,j as Mt,ja as Nt,jn as Pt,jo as Ft,jr as It,ka as Lt,kn as Rt,ko as zt,kr as Bt,kt as Vt,la as Ht,ln as Ut,lo as Wt,lr as Gt,m as Kt,mo as qt,mr as Jt,ms as Yt,na as Xt,ni as Zt,nn as Qt,no as $t,nr as en,ns as tn,oa as nn,on as rn,oo as an,or as on,os as sn,p as cn,pn as ln,po as un,pr as dn,ps as fn,pt as pn,qo as mn,qr as hn,qt as gn,ra as _n,rn as vn,ro as q,rr as yn,rs as bn,rt as xn,sa as Sn,sn as Cn,sr as wn,ss as Tn,ta as J,ti as En,tr as Dn,ts as On,ua as kn,un as An,uo as jn,ur as Mn,us as Nn,ut as Pn,v as Fn,vn as In,vr as Ln,w as Rn,wa as zn,wn as Bn,x as Vn,xo as Hn,xr as Un,xt as Wn,yo as Gn,yr as Kn,z as qn,za as Jn,zt as Yn}from"./dialogs-config-BF_RyK5j.js";import{$ as Xn,At as Zn,B as Qn,Ct as $n,Dt as er,Et as tr,F as nr,Ft as rr,G as ir,H as ar,I as or,J as sr,K as cr,L as lr,Lt as ur,Mt as dr,Nt as fr,Ot as pr,P as mr,Pt as hr,Q as gr,R as _r,St as vr,Tt as yr,U as br,V as xr,W as Sr,X as Cr,Y as wr,Z as Tr,_t as Er,at as Dr,bt as Or,ct as kr,dt as Ar,et as jr,ft as Mr,gt as Nr,ht as Pr,it as Fr,jt as Ir,kt as Lr,lt as Rr,mt as zr,nt as Br,ot as Vr,pt as Hr,q as Ur,rt as Wr,st as Gr,tt as Kr,ut as qr,vt as Jr,wt as Yr,xt as Xr,yt as Zr,z as Qr}from"./react-vendor-D-z0br-z.js";import{r as $r}from"./monaco-CZnIWXyV.js";import{A as ei,C as ti,F as ni,I as ri,M as ii,N as ai,O as oi,P as si,a as ci,j as li,k as ui,l as di,s as fi,u as pi,x as mi}from"./history-view-COEFPP2U.js";import{d as hi,l as gi,o as _i,u as vi}from"./onboarding-B_n7I3ri.js";import{a as yi,i as bi,n as xi,o as Si,r as Ci,t as wi}from"./vosk-speech-FJiKHPe4.js";import{n as Ti,t as Ei}from"./utils-H-1x3dmp.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 Di=class extends zr{#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||Oi(),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=Pr({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),Er.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function Oi(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var ki=class extends Lr{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 Di({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=Ai(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=Ai(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=Ai(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=Ai(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){Er.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=>vr(t,e))}findAll(e={}){return this.getAll().filter(t=>vr(e,t))}notify(e){Er.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return Er.batch(()=>Promise.all(e.map(e=>e.continue().catch(Yr))))}};function Ai(e){return e.options.scope?.id}var ji=class extends Lr{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??Or(r,t),a=this.get(i);return a||(a=new Hr({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(){Er.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=>$n(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>$n(e,t)):t}notify(e){Er.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Er.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Er.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},Mi=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new ji,this.#t=e.mutationCache||new ki,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=pr.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Nr.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(tr(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=Jr(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return Er.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;Er.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return Er.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=Er.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Yr).catch(Yr)}invalidateQueries(e,t={}){return Er.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=Er.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(Yr)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Yr)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(tr(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Yr).catch(Yr)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Yr).catch(Yr)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Nr.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(Zr(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{yr(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Zr(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{yr(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||=Or(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===er&&(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(Yt(),1),Ni=ur(),X=xt(),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}({}),Pi={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},Fi={open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};function Ii(e,t,n,r){return t.includes(e)||Vi(n,e,`primary`).isStreaming||Vi(n,e,`secondary`).isStreaming?!0:r?.threadId===e}var Li={isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0},Ri=Li;function zi(){return{...Li,streamingSegments:[]}}function Bi(e,t=`primary`){return`${e}:${t}`}function Vi(e,t,n=`primary`){return t?e[Bi(t,n)]??Ri:Ri}function Hi(e,t){return t.threadId??e.selectedThreadId}function Ui(e,t){return t.paneId??e.activeStreamPane??`primary`}function Wi(e,t,n){return t===e.selectedThreadId?e.activeStreamPane===null?n===`primary`:e.activeStreamPane===n:!1}function Gi(e,t,n,r,i=!1){if(!t)return{...e,...r,toolCallProgress:i?{}:e.toolCallProgress};let a=Bi(t,n),o={...e.threadStreamingStates,[a]:r};return Wi(e,t,n)?{...e,...r,threadStreamingStates:o,toolCallProgress:i?{}:e.toolCallProgress}:{...e,threadStreamingStates:o}}function Ki(){return{open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1}}var qi={dualChatEnabled:!1,focusedPane:`primary`,secondaryConversationId:null,secondaryMessages:[],secondaryMessagesLoaded:!1,activeStreamPane:null};function Ji(){return{...qi}}function Yi(e){return{dualChatEnabled:e.dualChatEnabled,focusedPane:e.focusedPane,secondaryConversationId:e.secondaryConversationId,secondaryMessages:e.secondaryMessages,secondaryMessagesLoaded:e.secondaryMessagesLoaded,activeStreamPane:e.activeStreamPane}}function Xi(e,t){return t?e[t]??qi:qi}function Zi(e){return{...e,secondaryMessages:[...e.secondaryMessages]}}function Qi(e,t,n){let r=Zi(n),i=t===null?e.threadDualChatStates:{...e.threadDualChatStates,[t]:r};return t===e.selectedThreadId?{...e,...r,threadDualChatStates:i}:{...e,threadDualChatStates:i}}function $i(e,t,n){let r=e.threadDualChatStates;return t&&(r={...r,[t]:Zi(Yi(e))}),{...Zi(Xi(r,n)),threadDualChatStates:r}}function ea(e,t){return Qi(e,e.selectedThreadId,{...Yi(e),...t})}function ta(e,t){switch(t.type){case Z.EnableDualChat:{let n=e.selectedThreadId?Xi(e.threadDualChatStates,e.selectedThreadId):qi,r=n.secondaryConversationId!==null;return ea(e,{dualChatEnabled:!0,focusedPane:`primary`,secondaryConversationId:r?n.secondaryConversationId:t.conversationId,secondaryMessages:r?n.secondaryMessages:[],secondaryMessagesLoaded:r?n.secondaryMessagesLoaded:!0})}case Z.DisableDualChat:return ea(e,{dualChatEnabled:!1,focusedPane:`primary`,activeStreamPane:null});case Z.SetFocusedPane:return ea(e,{focusedPane:t.paneId});case Z.SetSecondaryMessages:return ea(e,{secondaryMessages:t.messages,secondaryMessagesLoaded:!0});case Z.AddSecondaryMessage:return ea(e,{secondaryMessages:[...e.secondaryMessages,t.message]});case Z.SetActiveStreamPane:{if(!e.selectedThreadId||t.paneId===null)return ea(e,{activeStreamPane:null});let n=Vi(e.threadStreamingStates,e.selectedThreadId,t.paneId);return{...ea(e,{activeStreamPane:t.paneId}),...n}}default:return null}}function na(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`?Qi(e,e.selectedThreadId,{...Yi(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=$i(e,e.selectedThreadId,t.threadId),r=Vi(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,...zi(),selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,...Ji()};default:return null}}function ra(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 ia(e){return e.type===`tool_use`}function aa(e){return e.type===`tool-result`}function oa(e){return typeof e==`string`?e.replace(/\\n/g,`
3
+ `).replace(/✅/g,`✓`):``}function sa(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 ca(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 la(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=ca(e,r);if(t===-1)break;try{let i=JSON.parse(e.slice(r,t+1));if(!Array.isArray(i))break;n.push(...da(i))}catch{break}r=t+1}return n.length===0?null:{blocks:n,nextIndex:r}}function ua(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 da(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 fa(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 pa(e){return ma(e)?.some(e=>e.type===`tool_use`||e.type===`tool-result`)??!1}function ma(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 da(e);if(typeof e==`object`&&e)return fa(e)}catch{if(t.startsWith(`[`)){let e=la(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=la(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(...da(t)):n.push(...fa(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 ha(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 ga(e,t){return e[e.length-1]?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[t]}]:[...e,{type:`content`,chunks:[t]}]}function _a(e,t){let n=ma(t);if(!n?.some(e=>e.type===`tool_use`||e.type===`tool-result`))return ha(e,`content`,t);let r=e[e.length-1],i=n;if(r?.type===`content`){let e=r.chunks.join(``);i=ua(ma(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 va(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`content`)return n.chunks.join(``)}return``}function ya(e,t){return[...e,{type:`long_running_confirmation`,prompt:t}]}function ba(e,t){return[...e,{type:`shell_permission`,prompt:t}]}function xa(e,t){return[...e,{type:`web_fetch_permission`,prompt:t}]}function Sa(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=sa(e)??[];t.push(...n)}else{let n=ma(e)??(e.trim()?[{type:`text`,text:e}]:[]);t.push(...n)}}return t}function Ca(e){return e.type===`thinking-group`}function wa(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 Ta(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 Ea(e){return e.type===`content`||e.type===`thinking`?e.chunks.some(e=>e.trim().length>0):!1}function Da(e){let t=Sa(e),n=t.some(e=>ia(e)&&e.name===`ask_user`),r=t.some(e=>aa(e)&&e.toolName===`ask_user`);if(n&&!r)return!0;let i=Ta(e);return i===-1?!1:!e.slice(i+1).some(Ea)}function Oa(e){let t=Sa(e);return t.length===0?`...`:t.length===1&&t[0]?.type===`text`&&`text`in t[0]?t[0].text:JSON.stringify(t)}function ka(e,t){switch(t.type){case Z.SetStreaming:{let n=Hi(e,t),r=Ui(e,t);return Gi(e,n,r,{...Vi(e.threadStreamingStates,n,r),isStreaming:t.isStreaming})}case Z.AppendStreamContent:{let n=Hi(e,t),r=Ui(e,t),i=Vi(e.threadStreamingStates,n,r);return Gi(e,n,r,{...i,streamingContent:i.streamingContent+t.content})}case Z.SetStreamContent:{let n=Hi(e,t),r=Ui(e,t),i=Vi(e.threadStreamingStates,n,r),a=ga(i.streamingSegments,t.content);return Gi(e,n,r,{...i,streamingContent:t.content,streamingSegments:a})}case Z.AppendStreamThinking:{let n=Hi(e,t),r=Ui(e,t),i=Vi(e.threadStreamingStates,n,r);return Gi(e,n,r,{...i,streamingThinking:i.streamingThinking+t.content})}case Z.IncrementStreamEventCount:{let n=Hi(e,t),r=Ui(e,t),i=Vi(e.threadStreamingStates,n,r);return Gi(e,n,r,{...i,streamingEventCount:i.streamingEventCount+1})}case Z.AppendStreamChunk:{let n=Hi(e,t),r=Ui(e,t),i=Vi(e.threadStreamingStates,n,r);return Gi(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=Hi(e,t),r=Ui(e,t);return Gi(e,n,r,{...Vi(e.threadStreamingStates,n,r),streamingModel:t.model})}case Z.ResetStream:return Gi(e,Hi(e,t),Ui(e,t),zi(),!0);case Z.StopStream:{let n=Hi(e,t),r=Ui(e,t);return Gi(e,n,r,{...Vi(e.threadStreamingStates,n,r),isStreaming:!1})}default:return null}}function Aa(e,t){return e.terminalStates[t]??Ki()}function ja(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=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,open:!n.open}}}}case Z.SetTerminalOpen:{let n=t.threadId??`default`,r=Aa(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:t.open}}}}case Z.QueueTerminalCommand:{let n=Aa(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=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,queuedCommand:null}}}}case Z.AppendTerminalLine:{let n=t.threadId??`default`,r=Aa(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[...r.outputLines,t.line]}}}}case Z.ClearTerminalOutput:{let n=t.threadId??`default`,r=Aa(e,n);return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[]}}}}case Z.SetTerminalHeight:{let n=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,height:t.height}}}}case Z.SetTerminalCwd:{let n=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,cwd:t.cwd}}}}case Z.SetTerminalRunning:{let n=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,isRunning:t.isRunning}}}}case Z.SetTerminalHistory:{let n=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,history:t.history}}}}case Z.SetTerminalHistoryIndex:{let n=Aa(e,t.threadId);return{...e,terminalStates:{...e.terminalStates,[t.threadId]:{...n,historyIndex:t.index}}}}default:return null}}function Ma(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 Na=[ka,na,ta,ra,ja,Ma];function Pa(e,t){for(let n of Na){let r=n(e,t);if(r!==null)return r}return e}var Fa=new Set([Z.AppendStreamChunk,Z.IncrementStreamEventCount,Z.SetStreamModel,Z.AppendStreamContent,Z.AppendStreamThinking,Z.SetStreamContent]);function Ia(e=Pi){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=Pa(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(Fa.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 La=(0,Y.createContext)(null);function Ra(){let e=(0,Y.useContext)(La);if(!e)throw Error(`useAppStore must be used within an AppStoreContext.Provider`);return e}function Q(e){let t=(0,X.c)(3),n=Ra(),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 za(){return Ra().dispatch}function Ba(e){let t=(0,X.c)(8),n=za(),r;t[0]===e?r=t[1]:(r=t=>(e?t.terminalStates[e]:void 0)??Fi,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 $=ht(),Va=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=U(`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});Va.displayName=`Textarea`;function Ha(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:a,feedbackEmail:o,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)(En,{children:[(0,$.jsx)(Zt,{children:`Send Feedback`}),(0,$.jsx)(s,{children:`Share feedback about Tarsk.`})]}),t[0]=m):m=t[0];let h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(hn,{htmlFor:`feedback-name`,children:`Name`}),t[1]=h):h=t[1];let g;t[2]===a?g=t[3]:(g=e=>a(e.target.value),t[2]=a,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)(Xe,{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)(hn,{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]!==o||t[12]!==b||t[13]!==x?(S=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[y,(0,$.jsx)(Xe,{id:`feedback-email`,type:`email`,value:o,onChange:b,placeholder:`you@example.com`,disabled:x})]}),t[11]=o,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)(hn,{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)(Va,{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)(V,{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)(Et,{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)(V,{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)(gt,{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)(Ce,{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)(Ke,{open:n,onOpenChange:r,children:M}),t[43]=r,t[44]=n,t[45]=M,t[46]=N):N=t[46],N}function Ua(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)(Ua,{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 Wa(e){let t=(0,X.c)(31),{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,x;t[4]===o?(b=t[5],x=t[6]):(b=()=>{o?.length&&h(e=>{let t={...e},n=!1;for(let e of o)t[e]!==!0&&(t[e]=!0,n=!0);return n?t:e})},x=[o],t[4]=o,t[5]=b,t[6]=x),(0,Y.useEffect)(b,x);let S;t[7]===d?S=t[8]:(S=e=>{h(t=>({...t,[e]:!(t[e]??d)}))},t[7]=d,t[8]=S);let C=S,w;t[9]===u?w=t[10]:(w=U(`min-w-0`,u),t[9]=u,t[10]=w);let T;if(t[11]!==l||t[12]!==d||t[13]!==y||t[14]!==C||t[15]!==f||t[16]!==n||t[17]!==m||t[18]!==r){let e;t[20]!==l||t[21]!==d||t[22]!==y||t[23]!==C||t[24]!==f||t[25]!==m||t[26]!==r?(e=e=>(0,$.jsx)(Ua,{node:e,level:0,renderNode:r,defaultOpen:d,indent:f,childContainerClassName:l,openState:m,onToggle:C,forceOpenIds:y},e.id),t[20]=l,t[21]=d,t[22]=y,t[23]=C,t[24]=f,t[25]=m,t[26]=r,t[27]=e):e=t[27],T=n.map(e),t[11]=l,t[12]=d,t[13]=y,t[14]=C,t[15]=f,t[16]=n,t[17]=m,t[18]=r,t[19]=T}else T=t[19];let E;return t[28]!==w||t[29]!==T?(E=(0,$.jsx)(`div`,{className:w,children:T}),t[28]=w,t[29]=T,t[30]=E):E=t[30],E}var Ga=1,Ka=1e3,qa=0;function Ja(){return qa=(qa+1)%(2**53-1),qa.toString()}var Ya=new Map,Xa=e=>{if(Ya.has(e))return;let t=setTimeout(()=>{Ya.delete(e),eo({type:`REMOVE_TOAST`,toastId:e})},Ka);Ya.set(e,t)},Za=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,Ga)};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?Xa(n):e.toasts.forEach(e=>{Xa(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)}}},Qa=[],$a={toasts:[]};function eo(e){$a=Za($a,e),Qa.forEach(e=>{e($a)})}function to({...e}){let t=Ja(),n=e=>eo({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>eo({type:`DISMISS_TOAST`,toastId:t});return eo({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function no(){let e=(0,X.c)(4),[t,n]=Y.useState($a),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(Qa.push(n),()=>{let e=Qa.indexOf(n);e>-1&&Qa.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:to,dismiss:ro},e[2]=t,e[3]=a),a}function ro(e){return eo({type:`DISMISS_TOAST`,toastId:e})}function io(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!0;return u(!0),Pn().then(e=>{t&&(r(t=>t||e.name),o(t=>t||e.email))}).catch(()=>{t&&to({title:`Could not load git details`,description:`You can still submit feedback by entering your name and email manually.`,variant:`destructive`})}).finally(()=>{t&&u(!1)}),()=>{t=!1}},[e]),{showFeedback:e,feedbackName:n,setFeedbackName:r,feedbackEmail:i,setFeedbackEmail:o,feedbackText:s,setFeedbackText:c,loadingFeedbackUser:l,submittingFeedback:d,handleFeedbackDialogChange:e=>{t(e),e||c(``)},handleSubmitFeedback:async()=>{let e=s.trim();if(!e){to({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}f(!0);try{await a(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),to({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),c(``),t(!1)}catch(e){to({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{f(!1)}}}}var ao=ri(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`]}),oo=function(e){let t=(0,X.c)(23),{children:n,collapsed:r,title:i,onTitleClose:a,subtitle:s,headerAction:c,footer:l,isDevMode:u}=e,d,f,p,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=Dn(),p=function(){at(`https://tarsk.io/`)},d=ao,m=U(`flex flex-col select-none bg-sidebar text-sidebar-foreground mx-2.5 md:mr-10 rounded-3xl shadow-2xl overflow-hidden`,f&&`mt-8`),t[0]=d,t[1]=f,t[2]=p,t[3]=m):(d=t[0],f=t[1],p=t[2],m=t[3]);let h;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(h={containerType:`inline-size`,height:f?`calc(100% - 42px)`:`calc(100% - 12px)`},t[4]=h):h=t[4];let g;t[5]!==r||t[6]!==u||t[7]!==s?(g=!r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:p,className:U(J.sectionTitle,u&&`text-destructive dark:text-red-400`,`cursor-pointer hover:underline`),children:u?`Dev Mode`:`tarsk`}),s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(o,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,$.jsx)(`span`,{className:U(J.label,`text-sidebar-foreground/80`),children:s})]})]}),t[5]=r,t[6]=u,t[7]=s,t[8]=g):g=t[8];let _;t[9]!==r||t[10]!==c||t[11]!==a||t[12]!==i?(_=(i??a??c)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[c&&!r&&c,i&&(0,$.jsx)(`span`,{className:U(J.compact,`font-medium text-sidebar-foreground/80`),children:i}),a&&(0,$.jsxs)(V,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:a,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]}),t[9]=r,t[10]=c,t[11]=a,t[12]=i,t[13]=_):_=t[13];let v;t[14]===n?v=t[15]:(v=(0,$.jsx)(lt,{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},so=ri(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}),co=ri(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}),lo=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=U(`h-3 w-3 shrink-0 origin-center`,a,o,P(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)(so,{v0:c}),t[5]=c,t[6]=e),e}let l;return t[7]===c?l=t[8]:(l=(0,$.jsx)(co,{v0:c}),t[7]=c,t[8]=l),l};function uo(e){let t=(0,X.c)(87),{projects:n,selectedThreadId:r,selectedProjectId:i,processingThreadIds:a,completedThreadIds:o,deletingThreadIds:s,deletingProjectIds:c,onSelectThread:l,onCreateProject:u,onCreateThread:d,onDeleteThread:f,onDeleteProject:p,collapsed:h,updateAvailable:g,updatingApp:_,onUpdateApp:v,isDevMode:y,expandProjectId:b}=e,x=rr(),S=Q(ho),C=Q(mo),{showFeedback:w,feedbackName:T,setFeedbackName:E,feedbackEmail:D,setFeedbackEmail:O,feedbackText:A,setFeedbackText:j,loadingFeedbackUser:M,submittingFeedback:N,handleFeedbackDialogChange:P,handleSubmitFeedback:F}=io(),I;t[0]===n?I=t[1]:(I=[...n].sort(po),t[0]=n,t[1]=I);let R=I,B;t[2]===R?B=t[3]:(B=R.map(fo),t[2]=R,t[3]=B);let ee=B,te;bb0:{if(!i){te=void 0;break bb0}if(n.find(e=>e.projectId===i)?.threads.length===1){te=void 0;break bb0}let e;t[4]===i?e=t[5]:(e=[i],t[4]=i,t[5]=e),te=e}let ne=te,re;t[6]===b?re=t[7]:(re=b?[b]:void 0,t[6]=b,t[7]=re);let ie=re,ae;t[8]!==h||t[9]!==u?(ae=!h&&(0,$.jsxs)(V,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:u,children:[(0,$.jsx)(be,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[8]=h,t[9]=u,t[10]=ae):ae=t[10];let oe;t[11]!==h||t[12]!==v||t[13]!==g||t[14]!==_?(oe=g&&(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:v,disabled:_,children:[_?(0,$.jsx)(Et,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Re,{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]=oe):oe=t[15];let se;t[16]===x?se=t[17]:(se=()=>void x(`/settings/general`),t[16]=x,t[17]=se);let le;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(m,{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]!==se||t[22]!==ue?(de=(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:se,children:[le,ue]}),t[21]=se,t[22]=ue,t[23]=de):de=t[23];let fe;t[24]===P?fe=t[25]:(fe=()=>P(!0),t[24]=P,t[25]=fe);let H,pe;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(H=(0,$.jsx)(bt,{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)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{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)(z,{children:`Send feedback to the Tarsk team`}),t[30]=he):he=t[30];let ge;t[31]===me?ge=t[32]:(ge=(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{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]!==oe?(ve=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[oe,_e]}),t[36]=_e,t[37]=oe,t[38]=ve):ve=t[38];let ye;t[39]===n.length?ye=t[40]:(ye=n.length===0&&(0,$.jsx)(`p`,{className:U(J.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 xe;t[41]!==o||t[42]!==c||t[43]!==s||t[44]!==x||t[45]!==d||t[46]!==p||t[47]!==f||t[48]!==l||t[49]!==C||t[50]!==a||t[51]!==n||t[52]!==i||t[53]!==r||t[54]!==S?(xe=(e,t)=>{let{isOpen:u,toggle:m}=t;return e.kind===`project`?(0,$.jsx)(go,{project:e.project,isOpen:u,onToggle:m,isDeletingProject:c.includes(e.project.projectId),isSelected:i?e.project.projectId===i:!1,onCreateThread:d,onDeleteProject:p,onProjectSettings:e=>void x(`/settings/project/${e}`),hasSelectedThread:e.project.threads.some(e=>e.threadId===r),onSelectThread:l}):(0,$.jsx)(_o,{thread:e.thread,projectId:e.projectId,selectedThreadId:r,isProcessing:Ii(e.thread.threadId,a,S,C),isDeleting:s.includes(e.thread.threadId),isCompleted:o.includes(e.thread.threadId),projectTitlePrefix:`${L(n.find(t=>t.projectId===e.projectId))} - `,onSelectThread:l,onDeleteThread:f})},t[41]=o,t[42]=c,t[43]=s,t[44]=x,t[45]=d,t[46]=p,t[47]=f,t[48]=l,t[49]=C,t[50]=a,t[51]=n,t[52]=i,t[53]=r,t[54]=S,t[55]=xe):xe=t[55];let Se;t[56]!==ie||t[57]!==ne||t[58]!==ee||t[59]!==xe?(Se=(0,$.jsx)(Wa,{nodes:ee,defaultOpen:!1,initialOpenIds:ne,forceOpenIds:ie,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:xe}),t[56]=ie,t[57]=ne,t[58]=ee,t[59]=xe,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 we;t[64]!==h||t[65]!==y||t[66]!==ve||t[67]!==Ce||t[68]!==ae?(we=(0,$.jsx)(oo,{collapsed:h,isDevMode:y,headerAction:ae,footer:ve,children:Ce}),t[64]=h,t[65]=y,t[66]=ve,t[67]=Ce,t[68]=ae,t[69]=we):we=t[69];let Te;t[70]===F?Te=t[71]:(Te=()=>void F(),t[70]=F,t[71]=Te);let De;t[72]!==D||t[73]!==T||t[74]!==A||t[75]!==P||t[76]!==M||t[77]!==O||t[78]!==E||t[79]!==j||t[80]!==w||t[81]!==N||t[82]!==Te?(De=(0,$.jsx)(Ha,{open:w,onOpenChange:P,feedbackName:T,onFeedbackNameChange:E,feedbackEmail:D,onFeedbackEmailChange:O,feedbackText:A,onFeedbackTextChange:j,loadingFeedbackUser:M,submittingFeedback:N,onSubmit:Te}),t[72]=D,t[73]=T,t[74]=A,t[75]=P,t[76]=M,t[77]=O,t[78]=E,t[79]=j,t[80]=w,t[81]=N,t[82]=Te,t[83]=De):De=t[83];let Oe;return t[84]!==we||t[85]!==De?(Oe=(0,$.jsxs)($.Fragment,{children:[we,De]}),t[84]=we,t[85]=De,t[86]=Oe):Oe=t[86],Oe}function fo(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 po(e,t){return L(e).localeCompare(L(t))}function mo(e){return e.pendingChatMessage}function ho(e){return e.threadStreamingStates}function go(e){let t=(0,X.c)(39),{project:n,isOpen:r,onToggle:i,isDeletingProject:a,hasSelectedThread:s,isSelected:c,onCreateThread:l,onDeleteProject:u,onProjectSettings:d,onSelectThread:f}=e,p;t[0]===n?p=t[1]:(p=L(n),t[0]=n,t[1]=p);let h=p,g=s||c,_=n.threads.length===1?n.threads[0]:null,v;t[2]!==f||t[3]!==i||t[4]!==n.projectId||t[5]!==_||t[6]!==g?(v=function(){if(!g&&_){f(n.projectId,_.threadId);return}i()},t[2]=f,t[3]=i,t[4]=n.projectId,t[5]=_,t[6]=g,t[7]=v):v=t[7];let y=v,b=s||c,x=r&&`rotate-90`,S;t[8]===x?S=t[9]:(S=U(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,x),t[8]=x,t[9]=S);let C;t[10]===S?C=t[11]:(C=(0,$.jsx)(o,{className:S}),t[10]=S,t[11]=C);let w;t[12]===n.gitUrl?w=t[13]:(w=n.gitUrl?(0,$.jsx)(Ft,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,$.jsx)(zt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[12]=n.gitUrl,t[13]=w);let T=(s||c)&&`font-bold text-foreground`,E;t[14]===T?E=t[15]:(E=U(`min-w-0 truncate transition-all block`,T),t[14]=T,t[15]=E);let D;t[16]!==h||t[17]!==E?(D=(0,$.jsx)(`span`,{className:E,children:h}),t[16]=h,t[17]=E,t[18]=D):D=t[18];let O;t[19]!==D||t[20]!==C||t[21]!==w?(O=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[C,w,D]}),t[19]=D,t[20]=C,t[21]=w,t[22]=O):O=t[22];let A;t[23]!==y||t[24]!==O?(A=(0,$.jsx)(`button`,{type:`button`,className:`min-w-0`,onClick:y,children:O}),t[23]=y,t[24]=O,t[25]=A):A=t[25];let j;t[26]!==A||t[27]!==b?(j=(0,$.jsx)(hi,{selected:b,noBackground:!0,className:`h-9 min-w-0 flex-1`,asChild:!0,children:A}),t[26]=A,t[27]=b,t[28]=j):j=t[28];let M;t[29]!==a||t[30]!==l||t[31]!==u||t[32]!==d||t[33]!==n.projectId||t[34]!==n.threads.length?(M=(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:a?(0,$.jsx)(Et,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,$.jsxs)(ce,{children:[(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>d(n.projectId),children:[(0,$.jsx)(m,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,$.jsx)(z,{side:`right`,children:`Project settings`})]}),(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`action`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>l(n.projectId),children:[(0,$.jsx)(be,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,$.jsx)(z,{side:`right`,children:`Add thread (⌘⇧T)`})]}),n.threads.length===0&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:()=>u(n.projectId),children:[(0,$.jsx)(Nt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(z,{side:`right`,children:`Delete project`})]})]})}),t[29]=a,t[30]=l,t[31]=u,t[32]=d,t[33]=n.projectId,t[34]=n.threads.length,t[35]=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 _o(e){let t=(0,X.c)(57),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:s,projectTitlePrefix:c,onSelectThread:l,onDeleteThread:u}=e,[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null),m=n.threadId===i,h,g;t[0]===a?(h=t[1],g=t[2]):(h=()=>{a&&p.current&&p.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},g=[a],t[0]=a,t[1]=h,t[2]=g),(0,Y.useEffect)(h,g);let _;t[3]!==u||t[4]!==r||t[5]!==n.gitStatusDot||t[6]!==n.threadId?(_=e=>{e.stopPropagation(),n.gitStatusDot?f(!0):u(r,n.threadId)},t[3]=u,t[4]=r,t[5]=n.gitStatusDot,t[6]=n.threadId,t[7]=_):_=t[7];let v=_,y;t[8]!==c||t[9]!==n.threadId||t[10]!==n.title?(y=n.title?.startsWith(c)?n.title.slice(c.length):n.title??n.threadId,t[8]=c,t[9]=n.threadId,t[10]=n.title,t[11]=y):y=t[11];let b=y,x;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(ni,{children:`Delete Thread`}),t[12]=x):x=t[12];let S;t[13]===b?S=t[14]:(S=(0,$.jsxs)(ii,{children:[`Are you sure you want to delete "`,b,`" and all its files? This action cannot be undone.`]}),t[13]=b,t[14]=S);let C;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(ei,{children:`Cancel`}),t[15]=C):C=t[15];let w;t[16]!==u||t[17]!==r||t[18]!==n.threadId?(w=(0,$.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[C,(0,$.jsx)(ui,{onClick:()=>{f(!1),u(r,n.threadId)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[16]=u,t[17]=r,t[18]=n.threadId,t[19]=w):w=t[19];let T;t[20]!==S||t[21]!==w?(T=(0,$.jsxs)(li,{children:[x,S,w]}),t[20]=S,t[21]=w,t[22]=T):T=t[22];let E;t[23]!==d||t[24]!==T?(E=(0,$.jsx)(oi,{open:d,onOpenChange:f,children:T}),t[23]=d,t[24]=T,t[25]=E):E=t[25];let D;t[26]!==l||t[27]!==r||t[28]!==n.threadId?(D=()=>l(r,n.threadId),t[26]=l,t[27]=r,t[28]=n.threadId,t[29]=D):D=t[29];let O=a||o,A;t[30]!==O||t[31]!==n.gitStatusDot?(A=(0,$.jsx)(lo,{gitStatusDot:n.gitStatusDot,animate:O}),t[30]=O,t[31]=n.gitStatusDot,t[32]=A):A=t[32];let j;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(j=U(J.body,`truncate block`),t[33]=j):j=t[33];let M;t[34]===b?M=t[35]:(M=(0,$.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,$.jsx)(`span`,{className:j,children:b})}),t[34]=b,t[35]=M);let N;t[36]===s?N=t[37]:(N=s?(0,$.jsx)(tn,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):null,t[36]=s,t[37]=N);let P;t[38]!==D||t[39]!==A||t[40]!==M||t[41]!==N?(P=(0,$.jsxs)(`button`,{type:`button`,className:`min-w-0 w-full`,onClick:D,children:[A,M,N]}),t[38]=D,t[39]=A,t[40]=M,t[41]=N,t[42]=P):P=t[42];let F;t[43]!==m||t[44]!==P?(F=(0,$.jsx)(hi,{selected:m,className:`min-w-0 flex-1`,asChild:!0,children:P}),t[43]=m,t[44]=P,t[45]=F):F=t[45];let I;t[46]!==v||t[47]!==s||t[48]!==o||t[49]!==a?(I=!a&&!o&&!s&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{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:v,children:[(0,$.jsx)(Nt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,$.jsx)(z,{side:`right`,children:`Delete thread and files from the repo`})]}),t[46]=v,t[47]=s,t[48]=o,t[49]=a,t[50]=I):I=t[50];let L;t[51]!==F||t[52]!==I?(L=(0,$.jsxs)(`div`,{ref:p,className:`group flex min-w-0 items-center`,children:[F,I]}),t[51]=F,t[52]=I,t[53]=L):L=t[53];let R;return t[54]!==E||t[55]!==L?(R=(0,$.jsxs)($.Fragment,{children:[E,L]}),t[54]=E,t[55]=L,t[56]=R):R=t[56],R}var vo=e(fn(),1),yo=.1,bo=10,xo=1.25,So=.001;function Co(){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=wo,u;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>n(e=>l(e*xo)),e[1]=u):u=e[1];let d=u,f;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>n(e=>l(e/xo)),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*So;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 wo(e){return Math.min(Math.max(e,yo),bo)}var To=ri(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`]}),Eo=ri(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`]}),Do=ri(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`div`,{className:e.v2,children:`Rendering diagram…`})]}),{name:`MermaidRenderer_2`,portals:[`v1`]}),Oo=ri(e=>e.v0,{name:`MermaidRenderer_3`,portals:[`v0`]}),ko=function(e){let t=(0,X.c)(47),{content:n,className:r}=e,[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(!1),{svgOutput:c,renderError:l}=jo(n,Ao()),u;t[0]===n?u=t[1]:(u=async function(){await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=n,t[1]=u);let d=u,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=U(J.compact,`font-mono text-muted-foreground`),t[2]=f):f=t[2];let p=l?`mermaid (render error)`:`mermaid diagram`,m;t[3]!==l||t[4]!==c?(m=c&&!l&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`action`,size:`icon-xs`,onClick:()=>s(!0),children:[(0,$.jsx)(qt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View fullscreen`})]})}),(0,$.jsx)(z,{children:`View fullscreen`})]}),t[3]=l,t[4]=c,t[5]=m):m=t[5];let h;t[6]===i?h=t[7]:(h=i?(0,$.jsx)(tn,{}):(0,$.jsx)(N,{}),t[6]=i,t[7]=h);let g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy mermaid code`}),t[8]=g):g=t[8];let _;t[9]!==d||t[10]!==h?(_=(0,$.jsxs)(V,{variant:`action`,size:`icon-xs`,onClick:d,children:[h,g]}),t[9]=d,t[10]=h,t[11]=_):_=t[11];let v;t[12]!==p||t[13]!==m||t[14]!==_?(v=(0,$.jsx)(To,{v0:f,v1:p,v2:m,v3:_}),t[12]=p,t[13]=m,t[14]=_,t[15]=v):v=t[15];let y=v;if(l){let e;t[16]===r?e=t[17]:(e=U(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[16]=r,t[17]=e);let i;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(i=U(J.compact,`font-mono text-foreground leading-relaxed`),t[18]=i):i=t[18];let a;return t[19]!==n||t[20]!==y||t[21]!==e?(a=(0,$.jsx)(Eo,{v0:e,v1:y,v2:i,v3:n}),t[19]=n,t[20]=y,t[21]=e,t[22]=a):a=t[22],a}if(!c){let e;t[23]===r?e=t[24]:(e=U(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[23]=r,t[24]=e);let n;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(n=U(J.compact,`p-4 text-muted-foreground`),t[25]=n):n=t[25];let i;return t[26]!==y||t[27]!==e?(i=(0,$.jsx)(Do,{v0:e,v1:y,v2:n}),t[26]=y,t[27]=e,t[28]=i):i=t[28],i}let b;t[29]===r?b=t[30]:(b=U(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[29]=r,t[30]=b);let x;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>s(!0),t[31]=x):x=t[31];let S;t[32]===c?S=t[33]:(S=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`block w-full text-left cursor-zoom-in p-4 max-w-full overflow-hidden [&_svg]:max-w-full [&_svg]:h-auto hover:bg-muted/70 transition-colors`,onClick:x,dangerouslySetInnerHTML:{__html:c}})}),t[32]=c,t[33]=S);let C;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(z,{children:`Click to view fullscreen`}),t[34]=C):C=t[34];let w;t[35]===S?w=t[36]:(w=(0,$.jsxs)(k,{children:[S,C]}),t[35]=S,t[36]=w);let T;t[37]!==y||t[38]!==w||t[39]!==b?(T=(0,$.jsxs)(`div`,{className:b,children:[y,w]}),t[37]=y,t[38]=w,t[39]=b,t[40]=T):T=t[40];let E;t[41]!==o||t[42]!==c?(E=o&&(0,$.jsx)(Mo,{svgOutput:c,onClose:()=>s(!1)}),t[41]=o,t[42]=c,t[43]=E):E=t[43];let D;return t[44]!==T||t[45]!==E?(D=(0,$.jsx)(Oo,{v0:(0,$.jsxs)(ce,{children:[T,E]})}),t[44]=T,t[45]=E,t[46]=D):D=t[46],D};function Ao(){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 jo(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 $r(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 Mo(e){let t=(0,X.c)(70),{svgOutput:n,onClose:r}=e,{scale:i,offset:a,isDragging:o,containerRef:s,zoomIn:c,zoomOut:l,reset:u,onMouseDown:d,onMouseMove:f,onMouseUp:p}=Co(),m,h;t[0]===r?(m=t[1],h=t[2]):(m=()=>{let e=function(e){e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},h=[r],t[0]=r,t[1]=m,t[2]=h),(0,Y.useEffect)(m,h);let g;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],t[3]=g):g=t[3],(0,Y.useEffect)(No,g);let _;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:U(J.compact,`font-mono text-muted-foreground`),children:`mermaid diagram`}),t[4]=_):_=t[4];let v,y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Wt,{className:`h-3.5 w-3.5`}),y=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom out`}),t[5]=v,t[6]=y):(v=t[5],y=t[6]);let b;t[7]===l?b=t[8]:(b=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon-xs`,onClick:l,children:[v,y]})}),t[7]=l,t[8]=b);let x;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(z,{children:`Zoom out`}),t[9]=x):x=t[9];let S;t[10]===b?S=t[11]:(S=(0,$.jsxs)(k,{children:[b,x]}),t[10]=b,t[11]=S);let C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=U(J.compact,`min-w-[3rem] px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`),t[12]=C):C=t[12];let w;t[13]===i?w=t[14]:(w=Math.round(i*100),t[13]=i,t[14]=w);let T;t[15]!==u||t[16]!==w?(T=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:u,className:C,children:[w,`%`]})}),t[15]=u,t[16]=w,t[17]=T):T=t[17];let E;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(z,{children:`Reset zoom`}),t[18]=E):E=t[18];let D;t[19]===T?D=t[20]:(D=(0,$.jsxs)(k,{children:[T,E]}),t[19]=T,t[20]=D);let O,A;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(be,{className:`h-3.5 w-3.5`}),A=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom in`}),t[21]=O,t[22]=A):(O=t[21],A=t[22]);let j;t[23]===c?j=t[24]:(j=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon-xs`,onClick:c,children:[O,A]})}),t[23]=c,t[24]=j);let M;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(z,{children:`Zoom in`}),t[25]=M):M=t[25];let N;t[26]===j?N=t[27]:(N=(0,$.jsxs)(k,{children:[j,M]}),t[26]=j,t[27]=N);let P,F;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(te,{className:`h-3.5 w-3.5`}),F=(0,$.jsx)(`span`,{className:`sr-only`,children:`Reset view`}),t[28]=P,t[29]=F):(P=t[28],F=t[29]);let I;t[30]===u?I=t[31]:(I=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon-xs`,onClick:u,children:[P,F]})}),t[30]=u,t[31]=I);let L;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(z,{children:`Reset view`}),t[32]=L):L=t[32];let R;t[33]===I?R=t[34]:(R=(0,$.jsxs)(k,{children:[I,L]}),t[33]=I,t[34]=R);let B;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),t[35]=B):B=t[35];let ee,ne;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(zn,{className:`h-3.5 w-3.5`}),ne=(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`}),t[36]=ee,t[37]=ne):(ee=t[36],ne=t[37]);let re;t[38]===r?re=t[39]:(re=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon-xs`,onClick:r,children:[ee,ne]})}),t[38]=r,t[39]=re);let ie;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,$.jsx)(z,{children:`Close (Esc)`}),t[40]=ie):ie=t[40];let ae;t[41]===re?ae=t[42]:(ae=(0,$.jsxs)(k,{children:[re,ie]}),t[41]=re,t[42]=ae);let oe;t[43]!==D||t[44]!==N||t[45]!==R||t[46]!==ae||t[47]!==S?(oe=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-background/90 border-b border-border shrink-0`,children:[_,(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[S,D,N,R,B,ae]})]}),t[43]=D,t[44]=N,t[45]=R,t[46]=ae,t[47]=S,t[48]=oe):oe=t[48];let se=o?`cursor-grabbing`:`cursor-grab`,le;t[49]===se?le=t[50]:(le=U(`flex-1 overflow-hidden select-none`,se),t[49]=se,t[50]=le);let ue=`translate(${a.x}px, ${a.y}px) scale(${i})`,de=o?`none`:`transform 0.1s ease-out`,fe;t[51]!==ue||t[52]!==de?(fe={transform:ue,transformOrigin:`center center`,transition:de},t[51]=ue,t[52]=de,t[53]=fe):fe=t[53];let H;t[54]===n?H=t[55]:(H={__html:n},t[54]=n,t[55]=H);let pe;t[56]!==fe||t[57]!==H?(pe=(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,style:fe,dangerouslySetInnerHTML:H}),t[56]=fe,t[57]=H,t[58]=pe):pe=t[58];let me;t[59]!==s||t[60]!==d||t[61]!==f||t[62]!==p||t[63]!==le||t[64]!==pe?(me=(0,$.jsx)(`div`,{ref:s,className:le,onMouseDown:d,onMouseMove:f,onMouseUp:p,onMouseLeave:p,children:pe}),t[59]=s,t[60]=d,t[61]=f,t[62]=p,t[63]=le,t[64]=pe,t[65]=me):me=t[65];let he;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(`div`,{className:U(J.compact,`shrink-0 px-4 py-2 text-center text-muted-foreground/60 bg-background/60 border-t border-border`),children:`Scroll to zoom · Drag to pan · Esc to close`}),t[66]=he):he=t[66];let ge;return t[67]!==oe||t[68]!==me?(ge=(0,vo.createPortal)((0,$.jsx)(ce,{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:[oe,me,he]})}),document.body),t[67]=oe,t[68]=me,t[69]=ge):ge=t[69],ge}function No(){return document.body.style.overflow=`hidden`,Po}function Po(){document.body.style.overflow=``}function Fo(e){let t=e.trim();if(t.startsWith(`/`)){let e=We().replace(/\/$/,``);return K(`${e}${t}`,e)}return K(t,We())}function Io(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(_n(e.hostname))return!0;let n=new URL(We());return e.origin===n.origin&&e.pathname.startsWith(`/api/`)}catch{return!1}}function Lo(e){let t=e.trim();return!t||t.startsWith(`mailto:`)||t.startsWith(`tel:`)?!1:Dn()?/^https?:\/\//i.test(t)||t.startsWith(`/api/`):Io(t)}function Ro(e){let t=Fo(e);return wn()&&!Dn()?(window.open(t,`_blank`,`noopener,noreferrer`),Promise.resolve()):at(t)}function zo(e){return!!(_n(e.hostname)||typeof window<`u`&&e.origin===window.location.origin)}function Bo(e){return decodeURIComponent(e.replace(/^\/+/,``))}function Vo(e){let t=e.trim();if(!t||t.includes(`
6
+ `))return null;let n=M(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 Ho(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(!zo(e))return null;r=Bo(e.pathname)}else r=Bo(n);let i=M(r);return!i||t&&i!==t?null:{path:r,kind:i}}function Uo(e,t){return Fo(`/api/threads/${encodeURIComponent(e)}/explorer/media?path=${encodeURIComponent(t)}`)}function Wo(e){if(!e.startsWith(`/`))return!1;let t=e.split(`/`)[1]??``;return[`Users`,`tmp`,`var`,`private`,`Volumes`,`home`].includes(t)}function Go(e,t){if(!e||e.startsWith(`data:`))return e;if(t){if(Wo(e)&&M(e))return Uo(t,e);let n=Ho(e);if(n)return Uo(t,n.path)}return e.startsWith(`/`)?Fo(e):K(e,We())}function Ko(e,t){return Go(e,t)}var qo=ri(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`]}),Jo=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}`:Ko(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=Xt(u)??`generated-image-${Date.now()}.png`,{path:t}=await In(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:u,filename:e});to({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 ct(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)(Re,{className:`h-3.5 w-3.5`}),t[9]=g):g=t[9];let _;t[10]===f?_=t[11]:(_=(0,$.jsx)(Ee,{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)(z,{children:`Save image`}),t[12]=v):v=t[12];let y;t[13]===_?y=t[14]:(y=(0,$.jsxs)(k,{children:[_,v]}),t[13]=_,t[14]=y);let b;t[15]===s?b=t[16]:(b=s?(0,$.jsx)(tn,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(N,{className:`h-3.5 w-3.5`}),t[15]=s,t[16]=b);let x;t[17]!==m||t[18]!==b?(x=(0,$.jsx)(Ee,{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)(z,{children:S}),t[20]=S,t[21]=C);let w;t[22]!==x||t[23]!==C?(w=(0,$.jsxs)(k,{children:[x,C]}),t[22]=x,t[23]=C,t[24]=w):w=t[24];let T;t[25]!==w||t[26]!==y?(T=(0,$.jsxs)(ce,{children:[y,w]}),t[25]=w,t[26]=y,t[27]=T):T=t[27];let E;return t[28]!==o||t[29]!==u||t[30]!==T?(E=(0,$.jsx)(qo,{v0:u,v1:o,v2:h,v3:T}),t[28]=o,t[29]=u,t[30]=T,t[31]=E):E=t[31],E};function Yo(e){let t=it(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 Xo(e,t){let n=Yo(e)??Yo(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 Zo=h(`chat.media`);function Qo(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 $o(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 es(e){Zo.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:Qo(e.mediaError)}:void 0,probeResult:e.probeResult})}function ts(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 $o(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 $o(e);es({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 ns(e){let t=(0,X.c)(44),{src:n,label:i}=e,[a,o]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u=(0,Y.useRef)(null),{objectUrl:d,loadError:f,loading:p}=ts(n,a,`video`,i),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=function(e){o(e),e||(l(!1),u.current&&u.current.pause())},t[0]=m):m=t[0];let h=m,g;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(g=function(){l(rs)},t[1]=g):g=t[1];let _=g,v;t[2]!==i||t[3]!==n?(v=async function(e){let t=e.currentTarget.error;es({kind:`video`,src:n,label:i,mediaError:t,probeResult:await $o(n)})},t[2]=i,t[3]=n,t[4]=v):v=t[4];let y=v,b=i??`Video`,x;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>o(!0),t[5]=x):x=t[5];let S=i?`Play ${i}`:`Play video`,C;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(`span`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-background/90 text-foreground shadow-sm`,children:(0,$.jsx)(r,{className:`h-7 w-7 fill-current`})}),t[6]=C):C=t[6];let w;t[7]===S?w=t[8]:(w=(0,$.jsx)(`button`,{type:`button`,onClick:x,"aria-label":S,className:`flex min-h-32 w-full items-center justify-center rounded-md bg-muted/30 transition-colors hover:bg-muted/50`,children:C}),t[7]=S,t[8]=w);let T=c?`h-dvh w-dvw max-w-none rounded-none`:`max-w-[min(92vw,960px)]`,E;t[9]===T?E=t[10]:(E=U(`gap-0 overflow-hidden border-none bg-black p-0 sm:rounded-lg`,T),t[9]=T,t[10]=E);let D;t[11]===b?D=t[12]:(D=(0,$.jsx)(Zt,{className:`sr-only`,children:b}),t[11]=b,t[12]=D);let O;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(s,{className:`sr-only`,children:`Video player`}),t[13]=O):O=t[13];let k=c?`Shrink video`:`Expand video`,A;t[14]===c?A=t[15]:(A=c?(0,$.jsx)(jn,{className:`h-4 w-4`}):(0,$.jsx)(qt,{className:`h-4 w-4`}),t[14]=c,t[15]=A);let j;t[16]!==k||t[17]!==A?(j=(0,$.jsx)(`button`,{type:`button`,onClick:_,"aria-label":k,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:A}),t[16]=k,t[17]=A,t[18]=j):j=t[18];let M;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsxs)(et,{className:`flex h-7 w-7 items-center justify-center rounded-full text-white/90 transition-colors hover:bg-white/15 hover:text-white`,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[19]=M):M=t[19];let N;t[20]===j?N=t[21]:(N=(0,$.jsxs)(`div`,{className:`absolute right-4 top-4 z-10 flex items-center gap-1`,children:[j,M]}),t[20]=j,t[21]=N);let P=c?`h-full`:`min-h-[240px]`,F;t[22]===P?F=t[23]:(F=U(`flex items-center justify-center p-3 pt-12 sm:p-4`,P),t[22]=P,t[23]=F);let I;t[24]!==c||t[25]!==y||t[26]!==f||t[27]!==p||t[28]!==d?(I=p?(0,$.jsx)(`p`,{className:U(J.compact,`text-white/80`),children:`Loading video...`}):f?(0,$.jsxs)(`p`,{className:U(J.compact,`px-4 text-center text-destructive`),children:[`Could not load video: `,f]}):d?(0,$.jsx)(`video`,{ref:u,src:d,controls:!0,autoPlay:!0,playsInline:!0,className:U(`max-w-full rounded`,c?`max-h-full`:`max-h-[80vh]`),onError:y}):null,t[24]=c,t[25]=y,t[26]=f,t[27]=p,t[28]=d,t[29]=I):I=t[29];let L;t[30]!==F||t[31]!==I?(L=(0,$.jsx)(`div`,{className:F,children:I}),t[30]=F,t[31]=I,t[32]=L):L=t[32];let R;t[33]!==D||t[34]!==N||t[35]!==L||t[36]!==E?(R=(0,$.jsxs)(Ce,{hideClose:!0,className:E,children:[D,O,N,L]}),t[33]=D,t[34]=N,t[35]=L,t[36]=E,t[37]=R):R=t[37];let z;t[38]!==a||t[39]!==R?(z=(0,$.jsx)(Ke,{open:a,onOpenChange:h,children:R}),t[38]=a,t[39]=R,t[40]=z):z=t[40];let B;return t[41]!==z||t[42]!==w?(B=(0,$.jsxs)($.Fragment,{children:[w,z]}),t[41]=z,t[42]=w,t[43]=B):B=t[43],B}function rs(e){return!e}function is(e){let t=(0,X.c)(12),{src:n,label:r}=e,{objectUrl:i,loadError:a,loading:o}=ts(n,!0,`audio`,r),s;t[0]!==r||t[1]!==n?(s=async function(e){let t=e.currentTarget.error;es({kind:`audio`,src:n,label:r,mediaError:t,probeResult:await $o(n)})},t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=s,l;t[3]!==c||t[4]!==o||t[5]!==i?(l=o?(0,$.jsx)(`p`,{className:U(J.compact,`text-muted-foreground`),children:`Loading audio...`}):i?(0,$.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`,onError:c}):null,t[3]=c,t[4]=o,t[5]=i,t[6]=l):l=t[6];let u;t[7]===a?u=t[8]:(u=a?(0,$.jsxs)(`p`,{className:U(J.compact,`mt-2 text-destructive`),children:[`Could not load audio: `,a]}):null,t[7]=a,t[8]=u);let d;return t[9]!==l||t[10]!==u?(d=(0,$.jsxs)($.Fragment,{children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11],d}function as(e){let t=(0,X.c)(13),{src:n,kind:r,label:i}=e;if(!n)return null;let a=r===`video`?O:R,o=r===`video`?`p-2`:`p-3`,s;t[0]===o?s=t[1]:(s=U(`mt-2 max-w-full overflow-hidden rounded-lg border border-border bg-background`,o),t[0]=o,t[1]=s);let c;t[2]!==a||t[3]!==i?(c=i?(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(a,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:U(J.compact,`truncate`),children:i})]}):null,t[2]=a,t[3]=i,t[4]=c):c=t[4];let l;t[5]!==r||t[6]!==i||t[7]!==n?(l=r===`video`?(0,$.jsx)(ns,{src:n,label:i}):(0,$.jsx)(is,{src:n,label:i}),t[5]=r,t[6]=i,t[7]=n,t[8]=l):l=t[8];let u;return t[9]!==s||t[10]!==c||t[11]!==l?(u=(0,$.jsxs)(`div`,{className:s,children:[c,l]}),t[9]=s,t[10]=c,t[11]=l,t[12]=u):u=t[12],u}var os=`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(`.`),ss=[/-->/,/--\./,/-\./,/==>/,/--\|/,/\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 cs(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(os.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `)))return!0;let r=0;for(let t of ss)t.test(e)&&r++;return r>=2}function ls(e){if(!cs(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 os.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `))?e.trim():null}function us(e){let t=(0,X.c)(14),{href:n,children:r}=e,i;t[0]===n?i=t[1]:(i=Fo(n),t[0]=n,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=Lo(n),t[2]=n,t[3]=o);let s=o,c;t[4]!==n||t[5]!==s?(c=function(e){s&&(e.preventDefault(),Ro(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 ds=ri(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`]}),fs=function(e){let t=(0,X.c)(19),{language:n,code:r,compact:i}=e,a=i===void 0?!1:i,[o,s]=(0,Y.useState)(!1),c;t[0]===r?c=t[1]:(c=async()=>{await navigator.clipboard.writeText(r),s(!0),setTimeout(()=>s(!1),2e3)},t[0]=r,t[1]=c);let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=U(J.compact,`text-muted-foreground font-mono`),t[2]=u):u=t[2];let d=n||`text`,f;t[3]===o?f=t[4]:(f=o?(0,$.jsx)(tn,{}):(0,$.jsx)(N,{}),t[3]=o,t[4]=f);let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[5]=p):p=t[5];let m;t[6]!==l||t[7]!==f?(m=(0,$.jsxs)(V,{variant:`action`,size:`icon-xs`,onClick:l,children:[f,p]}),t[6]=l,t[7]=f,t[8]=m):m=t[8];let h=a?`p-2`:`p-4`,g;t[9]===h?g=t[10]:(g=U(`overflow-x-auto max-w-full`,h),t[9]=h,t[10]=g);let _;t[11]===a?_=t[12]:(_=U(a?U(J.compact,`font-mono`):J.mono,`text-foreground leading-relaxed`),t[11]=a,t[12]=_);let v;return t[13]!==r||t[14]!==_||t[15]!==d||t[16]!==m||t[17]!==g?(v=(0,$.jsx)(ds,{v0:u,v1:d,v2:m,v3:g,v4:_,v5:r}),t[13]=r,t[14]=_,t[15]=d,t[16]=m,t[17]=g,t[18]=v):v=t[18],v},ps=(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`?[]:vs(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:U(`prose-custom min-w-0 break-words`,t),children:a.map((e,t)=>(0,$.jsx)(`div`,{className:_s(t,a,i),children:(0,$.jsx)(js,{block:e,start:o[t],threadId:r,compact:i})},t))})}),ms=/^!\[([^\]]*)\]\(([^)]+)\)\s*$/;function hs(e){let t=e.match(ms);return t?{alt:t[1],src:t[2]}:null}function gs(e,t){let n=e?`mt-0 space-y-0.5`:`mt-0 space-y-1`;return t?U(n,`pl-6`):U(n,`ml-[3.8rem]`,`list-outside overflow-visible list-disc`)}function _s(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 vs(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`||cs(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=hs(e);if(o){r.push({type:`image`,...o}),i++;continue}let s=Vo(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&&cs(e)){let t=ls(e);t?r.push({type:`mermaid`,code:t}):r.push({type:`paragraph`,text:e})}else r.push({type:`paragraph`,text:e})}}return r}var ys=ri(e=>e.v0,{name:`MarkdownBlock_2`,portals:[`v0`]}),bs=ri(e=>e.v0,{name:`MarkdownBlock_3`,portals:[`v0`]}),xs=ri(e=>(0,$.jsx)(`blockquote`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_4`,portals:[`v1`]}),Ss=ri(e=>(0,$.jsx)(`ol`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_5`,portals:[`v1`]}),Cs=ri(e=>(0,$.jsx)(`ul`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_6`,portals:[`v1`]}),ws=ri(e=>(0,$.jsx)(`p`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_7`,portals:[`v1`]}),Ts=ri(()=>(0,$.jsx)(`hr`,{className:`border-border`}),{name:`MarkdownBlock_8`}),Es=ri(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`]}),Ds=ri(e=>e.v0,{name:`MarkdownBlock_10`,portals:[`v0`]}),Os=ri(e=>e.v0,{name:`MarkdownBlock_11`,portals:[`v0`]}),ks=ri(e=>e.v0,{name:`MarkdownBlock_12`,portals:[`v0`]}),As=ri(e=>e.v0,{name:`MarkdownBlock_13`,portals:[`v0`]}),js=(0,Y.memo)(function(e){let t=(0,X.c)(111),{block:n,start:r,threadId:i,compact:a}=e,o=r===void 0?1:r,s=a===void 0?!1:a,c=s?J.caption:J.body,l;t[0]===s?l=t[1]:(l=s?U(J.compact,`font-mono`):J.mono,t[0]=s,t[1]=l);let u=l;switch(n.type){case`heading`:{let e=`h${n.level}`,r,a,o;if(t[2]!==e||t[3]!==n.level||t[4]!==s){let i=s?{1:U(J.caption,`font-semibold`),2:U(J.caption,`font-semibold`),3:U(J.body,`font-semibold`),4:U(J.body,`font-semibold`),5:U(J.compact,`font-semibold`),6:U(J.compact,`font-semibold`)}:{1:J.sectionTitle,2:J.subSectionTitle,3:J.subSectionTitle,4:J.subSectionTitle,5:J.sectionSubtitle,6:J.sectionSubtitle};a=ys,r=e,o=U(i[n.level]),t[2]=e,t[3]=n.level,t[4]=s,t[5]=r,t[6]=a,t[7]=o}else r=t[5],a=t[6],o=t[7];let c;t[8]!==n.text||t[9]!==u||t[10]!==i?(c=(0,$.jsx)(Ms,{text:n.text,threadId:i,inlineCodeClass:u}),t[8]=n.text,t[9]=u,t[10]=i,t[11]=c):c=t[11];let l;t[12]!==r||t[13]!==o||t[14]!==c?(l=(0,$.jsx)(r,{className:o,children:c}),t[12]=r,t[13]=o,t[14]=c,t[15]=l):l=t[15];let d;return t[16]!==a||t[17]!==l?(d=(0,$.jsx)(a,{v0:l}),t[16]=a,t[17]=l,t[18]=d):d=t[18],d}case`code`:{let e;return t[19]!==n.code||t[20]!==n.language||t[21]!==s?(e=(0,$.jsx)(bs,{v0:(0,$.jsx)(fs,{language:n.language,code:n.code,compact:s})}),t[19]=n.code,t[20]=n.language,t[21]=s,t[22]=e):e=t[22],e}case`blockquote`:{let e;t[23]===c?e=t[24]:(e=U(c,`border-l-2 border-border pl-4 text-muted-foreground italic`),t[23]=c,t[24]=e);let r;t[25]!==n.text||t[26]!==u||t[27]!==i?(r=(0,$.jsx)(Ms,{text:n.text,threadId:i,inlineCodeClass:u}),t[25]=n.text,t[26]=u,t[27]=i,t[28]=r):r=t[28];let a;return t[29]!==e||t[30]!==r?(a=(0,$.jsx)(xs,{v0:e,v1:r}),t[29]=e,t[30]=r,t[31]=a):a=t[31],a}case`list`:{let e,r,a;if(t[32]!==n.items||t[33]!==n.ordered||t[34]!==c||t[35]!==s||t[36]!==u||t[37]!==o||t[38]!==i){a=Symbol.for(`react.early_return_sentinel`);bb0:{let l=gs(s,n.ordered);if(n.ordered){let e=U(c,l),r;if(t[42]!==n.items||t[43]!==u||t[44]!==o||t[45]!==i){let e;t[47]!==u||t[48]!==o||t[49]!==i?(e=(e,t)=>(0,$.jsxs)(`li`,{className:`flex gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`shrink-0 select-none tabular-nums`,children:[o+t,`.`]}),(0,$.jsx)(`span`,{children:(0,$.jsx)(Ms,{text:e,threadId:i,inlineCodeClass:u})})]},t),t[47]=u,t[48]=o,t[49]=i,t[50]=e):e=t[50],r=n.items.map(e),t[42]=n.items,t[43]=u,t[44]=o,t[45]=i,t[46]=r}else r=t[46];a=(0,$.jsx)(Ss,{v0:e,v1:r});break bb0}e=Cs,r=U(c,l)}t[32]=n.items,t[33]=n.ordered,t[34]=c,t[35]=s,t[36]=u,t[37]=o,t[38]=i,t[39]=e,t[40]=r,t[41]=a}else e=t[39],r=t[40],a=t[41];if(a!==Symbol.for(`react.early_return_sentinel`))return a;let l;if(t[51]!==n.items||t[52]!==u||t[53]!==i){let e;t[55]!==u||t[56]!==i?(e=(e,t)=>(0,$.jsx)(`li`,{children:(0,$.jsx)(Ms,{text:e,threadId:i,inlineCodeClass:u})},t),t[55]=u,t[56]=i,t[57]=e):e=t[57],l=n.items.map(e),t[51]=n.items,t[52]=u,t[53]=i,t[54]=l}else l=t[54];let d;return t[58]!==e||t[59]!==r||t[60]!==l?(d=(0,$.jsx)(e,{v0:r,v1:l}),t[58]=e,t[59]=r,t[60]=l,t[61]=d):d=t[61],d}case`paragraph`:{let e;t[62]===c?e=t[63]:(e=U(c,`mt-0 leading-relaxed whitespace-pre-wrap break-words`),t[62]=c,t[63]=e);let r;t[64]!==n.text||t[65]!==u||t[66]!==i?(r=(0,$.jsx)(Ms,{text:n.text,threadId:i,inlineCodeClass:u}),t[64]=n.text,t[65]=u,t[66]=i,t[67]=r):r=t[67];let a;return t[68]!==e||t[69]!==r?(a=(0,$.jsx)(ws,{v0:e,v1:r}),t[68]=e,t[69]=r,t[70]=a):a=t[70],a}case`hr`:{let e;return t[71]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ts,{}),t[71]=e):e=t[71],e}case`table`:{let e;t[72]===c?e=t[73]:(e=U(c,`w-full`),t[72]=c,t[73]=e);let r;if(t[74]!==n.headers||t[75]!==u||t[76]!==i){let e;t[78]!==u||t[79]!==i?(e=(e,t)=>(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:(0,$.jsx)(Ms,{text:e,threadId:i,inlineCodeClass:u})},t),t[78]=u,t[79]=i,t[80]=e):e=t[80],r=n.headers.map(e),t[74]=n.headers,t[75]=u,t[76]=i,t[77]=r}else r=t[77];let a;if(t[81]!==n.rows||t[82]!==u||t[83]!==i){let e;t[85]!==u||t[86]!==i?(e=(e,t)=>(0,$.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map((e,t)=>(0,$.jsx)(`td`,{className:`px-3 py-2`,children:(0,$.jsx)(Ms,{text:e,threadId:i,inlineCodeClass:u})},t))},t),t[85]=u,t[86]=i,t[87]=e):e=t[87],a=n.rows.map(e),t[81]=n.rows,t[82]=u,t[83]=i,t[84]=a}else a=t[84];let o;return t[88]!==e||t[89]!==r||t[90]!==a?(o=(0,$.jsx)(Es,{v0:e,v1:r,v2:a}),t[88]=e,t[89]=r,t[90]=a,t[91]=o):o=t[91],o}case`mermaid`:{let e;return t[92]===n.code?e=t[93]:(e=(0,$.jsx)(Ds,{v0:(0,$.jsx)(ko,{content:n.code})}),t[92]=n.code,t[93]=e),e}case`image`:{let e;t[94]!==n.src||t[95]!==i?(e=Ko(n.src,i),t[94]=n.src,t[95]=i,t[96]=e):e=t[96];let r=n.alt||`Image`,a;return t[97]!==e||t[98]!==r?(a=(0,$.jsx)(Os,{v0:(0,$.jsx)(Jo,{imageUrl:e,alt:r})}),t[97]=e,t[98]=r,t[99]=a):a=t[99],a}case`media`:{let e;t[100]!==n.src||t[101]!==i?(e=Go(n.src,i),t[100]=n.src,t[101]=i,t[102]=e):e=t[102];let r=e;if(n.kind===`image`){let e;return t[103]===r?e=t[104]:(e=(0,$.jsx)(ks,{v0:(0,$.jsx)(Jo,{imageUrl:r,alt:`Image`})}),t[103]=r,t[104]=e),e}let a;t[105]===n.src?a=t[106]:(a=n.src.split(/[/\\]/).pop(),t[105]=n.src,t[106]=a);let o=a,s;return t[107]!==n.kind||t[108]!==o||t[109]!==r?(s=(0,$.jsx)(As,{v0:(0,$.jsx)(as,{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}}),Ms=(0,Y.memo)(function(e){let t=(0,X.c)(11),{text:n,threadId:r,inlineCodeClass:i}=e,a=i===void 0?J.mono:i,o;t[0]===n?o=t[1]:(o=Ns(n),t[0]=n,t[1]=o);let s=o,c;if(t[2]!==a||t[3]!==s||t[4]!==r){let e;t[6]!==a||t[7]!==r?(e=(e,t)=>{switch(e.type){case`bold`:return(0,$.jsx)(`strong`,{className:`font-semibold`,children:e.text},t);case`italic`:return(0,$.jsx)(`em`,{children:e.text},t);case`strikethrough`:return(0,$.jsx)(`del`,{className:`text-muted-foreground`,children:e.text},t);case`code`:return(0,$.jsx)(`code`,{className:U(a,`rounded bg-muted/20 py-0.5`),children:e.text},t);case`link`:return(0,$.jsx)(us,{href:e.href,children:e.text},t);case`image`:return(0,$.jsx)(Jo,{imageUrl:Ko(e.src,r),alt:e.alt||`Image`},t);default:return(0,$.jsx)(`span`,{children:e.text},t)}},t[6]=a,t[7]=r,t[8]=e):e=t[8],c=s.map(e),t[2]=a,t[3]=s,t[4]=r,t[5]=c}else c=t[5];let l;return t[9]===c?l=t[10]:(l=(0,$.jsx)($.Fragment,{children:c}),t[9]=c,t[10]=l),l});function Ns(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 Ps(e){return e.split(/[/\\]/).pop()||void 0}var Fs=(0,Y.memo)(function(e){let t=(0,X.c)(20),{content:n,threadId:r,className:i,enableMermaid:a}=e,o=a===void 0?!0:a,s;t[0]===n?s=t[1]:(s=Vo(n),t[0]=n,t[1]=s);let c=s;if(c){let e;t[2]!==c.src||t[3]!==r?(e=Go(c.src,r),t[2]=c.src,t[3]=r,t[4]=e):e=t[4];let n=e;if(c.kind===`image`){let e;return t[5]===n?e=t[6]:(e=(0,$.jsx)(Jo,{imageUrl:n,alt:`Image`}),t[5]=n,t[6]=e),e}let i=c.kind,a;t[7]===c.src?a=t[8]:(a=Ps(c.src),t[7]=c.src,t[8]=a);let o;return t[9]!==c.kind||t[10]!==n||t[11]!==a?(o=(0,$.jsx)(as,{src:n,kind:i,label:a}),t[9]=c.kind,t[10]=n,t[11]=a,t[12]=o):o=t[12],o}let l;t[13]===n?l=t[14]:(l=oa(n),t[13]=n,t[14]=l);let u=i??J.body,d;return t[15]!==o||t[16]!==l||t[17]!==u||t[18]!==r?(d=(0,$.jsx)(ps,{content:l,enableMermaid:o,className:u,threadId:r}),t[15]=o,t[16]=l,t[17]=u,t[18]=r,t[19]=d):d=t[19],d});function Is(e){return`data:${e.mimeType};base64,${e.content}`}function Ls(e){return e.mimeType.startsWith(`image/`)?`image`:e.mimeType.startsWith(`video/`)?`video`:e.mimeType.startsWith(`audio/`)?`audio`:M(e.fileName)||`file`}function Rs(e){let t=(0,X.c)(6),{icon:n,label:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=U(J.compact,`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-muted-foreground`),t[0]=i):i=t[0];let a;t[1]===r?a=t[2]:(a=(0,$.jsx)(`span`,{className:`truncate`,children:r}),t[1]=r,t[2]=a);let o;return t[3]!==n||t[4]!==a?(o=(0,$.jsxs)(`div`,{className:i,children:[n,a]}),t[3]=n,t[4]=a,t[5]=o):o=t[5],o}function zs(e){let t=(0,X.c)(14),{attachment:n}=e,r=Ls(n),i;t[0]===n?i=t[1]:(i=Is(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)(as,{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)(as,{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)(kt,{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)(Rs,{icon:o,label:n.fileName}),t[12]=n.fileName,t[13]=s),s}function Bs(e){let t=(0,X.c)(4),{attachments:n}=e,r;t[0]===n?r=t[1]:(r=n.map(Vs),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 Vs(e){let t=Ls(e),n=`${e.fileName}:${e.mimeType}`;return t===`file`?(0,$.jsx)(zs,{attachment:e},n):(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(Rs,{icon:t===`audio`?(0,$.jsx)(R,{className:`h-2.5 w-2.5`}):t===`video`?(0,$.jsx)(O,{className:`h-2.5 w-2.5`}):(0,$.jsx)(kt,{className:`h-2.5 w-2.5`}),label:e.fileName}),(0,$.jsx)(zs,{attachment:e})]},n)}var Hs=h(`gitops.timing`);function Us(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}),Hs.debug(`${e} step=${n} ${r}ms`)}}function i(n,r,i){t.push({step:n,ms:r}),Hs.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(` `);Hs.debug(`${e} summary total=${i}ms slowest=${a.step}@${a.ms}ms breakdown=[${o}]${r?` ${r}`:``}`)}return{step:r,record:i,summary:a}}var Ws=3e4,Gs={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},Ks=new Map,qs=new Map;function Js(e,t){let n=Ks.get(e);if(n)for(let e of n)e(t)}function Ys(e,t){let n=Ks.get(e);return n||(n=new Set,Ks.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Ks.delete(e)}}function Xs(e){return`unified-git-status-${e}`}function Zs(e){return ne.getSync(Xs(e))}function Qs(e){let[t,n]=(0,Y.useState)(Gs),[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=Us(`hook fetch thread=${e} force=${t}`),a=setTimeout(()=>{o.current===n&&i(!0)},100);try{let i=Xs(e),a=performance.now(),c=Zs(e);r.record(`local-cache-check`,Math.round(performance.now()-a),`result=${c?`hit`:`miss`}`),t&&(ne.invalidate(i),r.record(`invalidate-local-cache`,0));let l=await r.step(`ttl-cache-get`,()=>ne.get(i,()=>_(e,t,!1),Ws));if(o.current!==n){r.summary(`stale-request`);return}await r.step(`update-state`,async()=>{s(l),Js(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 Ys(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(Gs)});return}let t=a.current!==e,r=Zs(e);t&&(console.log(`[gitops-timing] hook thread changed ${a.current??`none`} -> ${e}`),a.current=e),(0,Y.startTransition)(()=>{n(r??Gs)}),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=qs.get(s);if(e){console.log(`[gitops-timing] hook initial fetch already in flight thread=${s}`),e.then(()=>{if(l)return;let e=Zs(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}`),qs.delete(s)});qs.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 $s=(0,Y.createContext)(void 0);function ec(e){let t=(0,X.c)(7),{threadId:n,fetchUnifiedStatus:r}=e,i=Q(rc),a=Q(nc),o=Q(tc),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 tc(e){return e.selectedThreadId}function nc(e){return e.completedThreadIds}function rc(e){return e.isStreaming}function ic(e){let t=(0,X.c)(7),{threadId:n,children:r}=e,i=Qs(n),a;t[0]!==n||t[1]!==i.fetchUnifiedStatus?(a=(0,$.jsx)(ec,{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)($s.Provider,{value:i,children:[a,r]}),t[3]=r,t[4]=a,t[5]=i,t[6]=o):o=t[6],o}function ac(){let e=(0,Y.useContext)($s);if(e===void 0)throw Error(`useGitStatus must be used within a GitStatusProvider`);return e}function oc(e){let[t,n]=(0,Y.useState)(!1),{fetchUnifiedStatus:r}=ac();async function i(i){if(!(!e||t)){n(!0);try{let t=await Tt(e,i);t.success?(to({title:`Checkpoint restored`,description:`Working tree restored to before this agent run.`}),r(!0)):to({title:`Restore failed`,description:t.error??`Could not restore checkpoint.`,variant:`destructive`})}catch(e){to({title:`Restore failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{n(!1)}}}return{isRestoring:t,restore:i}}function sc(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 cc(e){return e.length<=32?e:`${e.slice(0,32)}...`}function lc(e){let t=(0,X.c)(60),{message:n,threadId:r,showCheckpointRestore:i,checkpointRestoreTooltip:a}=e,o=i===void 0?!1:i,[s,c]=(0,Y.useState)(!1),l=n.sender===`user`,{isRestoring:u,restore:d}=oc(r),{copied:f,markCopied:p}=sc(),m=l&&(o||!!a),h;t[0]===n.timestamp?h=t[1]:(h=n.timestamp?new Date(n.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,t[0]=n.timestamp,t[1]=h);let g=h,_;t[2]===n.content?_=t[3]:(_=cc(n.content),t[2]=n.content,t[3]=_);let v=_,y;t[4]!==u||t[5]!==n.checkpointRef||t[6]!==o?(y=function(){!n.checkpointRef||!o||u||c(!0)},t[4]=u,t[5]=n.checkpointRef,t[6]=o,t[7]=y):y=t[7];let b=y,x;t[8]!==n.checkpointRef||t[9]!==d||t[10]!==o?(x=async function(){!n.checkpointRef||!o||(await d(n.checkpointRef),c(!1))},t[8]=n.checkpointRef,t[9]=d,t[10]=o,t[11]=x):x=t[11];let S=x,C;t[12]!==p||t[13]!==n.content?(C=async function(){try{await navigator.clipboard.writeText(n.content),p()}catch(e){let t=e;to({title:`Copy failed`,description:t instanceof Error?t.message:`Could not copy prompt.`,variant:`destructive`})}},t[12]=p,t[13]=n.content,t[14]=C):C=t[14];let w=C,T=l&&`flex-row-reverse`,E;t[15]===T?E=t[16]:(E=U(`flex items-center gap-2`,T),t[15]=T,t[16]=E);let D;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(D=U(J.compact,`font-medium text-foreground`),t[17]=D):D=t[17];let O=l?`You`:`Agent`,A;t[18]===O?A=t[19]:(A=(0,$.jsx)(`span`,{className:D,children:O}),t[18]=O,t[19]=A);let j;t[20]!==a||t[21]!==w||t[22]!==b||t[23]!==f||t[24]!==u||t[25]!==l||t[26]!==m||t[27]!==o?(j=l&&(0,$.jsx)(ce,{children:(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:w,"aria-label":f?`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:f?(0,$.jsx)(tn,{className:`h-3 w-3 text-green-500`}):(0,$.jsx)(N,{className:`h-3 w-3`})})})}),(0,$.jsx)(z,{side:`left`,children:f?`Copied prompt`:`Copy prompt`})]}),m&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:o?b:void 0,disabled:!o||u,"aria-label":a??`Restore checkpoint`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted disabled:opacity-50 disabled:hover:text-muted-foreground disabled:hover:bg-transparent`,children:(0,$.jsx)(te,{className:U(`h-3 w-3`,u&&`animate-spin`)})})})}),(0,$.jsx)(z,{side:`left`,children:a??`Restore checkpoint`})]})]})}),t[20]=a,t[21]=w,t[22]=b,t[23]=f,t[24]=u,t[25]=l,t[26]=m,t[27]=o,t[28]=j):j=t[28];let M;t[29]===g?M=t[30]:(M=g&&(0,$.jsxs)(`span`,{className:U(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(re,{className:`h-2.5 w-2.5`}),g]}),t[29]=g,t[30]=M);let P;t[31]===n.model?P=t[32]:(P=n.model&&(0,$.jsxs)(`span`,{className:U(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(He,{className:`h-2.5 w-2.5`}),vi(n.model)]}),t[31]=n.model,t[32]=P);let F;t[33]===n.metadata?F=t[34]:(F=n.metadata?.processingTimeMs&&(0,$.jsxs)(`span`,{className:U(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(le,{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]=F);let I;t[35]===n.metadata?I=t[36]:(I=(n.metadata?.tokenCount||n.metadata?.estimatedCost)&&(0,$.jsxs)(`span`,{className:U(J.compact,`text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[n.metadata.tokenCount?`${n.metadata.tokenCount.toLocaleString()} tokens`:null,n.metadata.tokenCount&&n.metadata.estimatedCost?` · `:null,n.metadata.estimatedCost?kn(n.metadata.estimatedCost):null]}),t[35]=n.metadata,t[36]=I);let L;t[37]!==A||t[38]!==j||t[39]!==M||t[40]!==P||t[41]!==F||t[42]!==I||t[43]!==E?(L=(0,$.jsxs)(`div`,{className:E,children:[A,j,M,P,F,I]}),t[37]=A,t[38]=j,t[39]=M,t[40]=P,t[41]=F,t[42]=I,t[43]=E,t[44]=L):L=t[44];let R;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(ni,{children:`Restore Checkpoint`}),t[45]=R):R=t[45];let B;t[46]===v?B=t[47]:(B=(0,$.jsxs)(si,{children:[R,(0,$.jsxs)(ii,{children:[`Restore to the checkpoint before “`,v,`” was started?`]})]}),t[46]=v,t[47]=B);let ee;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(ei,{children:`Cancel`}),t[48]=ee):ee=t[48];let ne;t[49]===S?ne=t[50]:(ne=(0,$.jsxs)(ai,{children:[ee,(0,$.jsx)(ui,{onClick:S,children:`Restore checkpoint`})]}),t[49]=S,t[50]=ne);let ie;t[51]!==B||t[52]!==ne?(ie=(0,$.jsxs)(li,{children:[B,ne]}),t[51]=B,t[52]=ne,t[53]=ie):ie=t[53];let ae;t[54]!==s||t[55]!==ie?(ae=(0,$.jsx)(oi,{open:s,onOpenChange:c,children:ie}),t[54]=s,t[55]=ie,t[56]=ae):ae=t[56];let oe;return t[57]!==L||t[58]!==ae?(oe=(0,$.jsxs)($.Fragment,{children:[L,ae]}),t[57]=L,t[58]=ae,t[59]=oe):oe=t[59],oe}function uc(e){let t=(0,X.c)(32),{src:n,threadId:r}=e,{copied:i,markCopied:a}=sc(),o;t[0]!==n||t[1]!==r?(o=n.startsWith(`data:`)?n:Ko(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 In(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:s,filename:e});to({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 ct(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)(Re,{className:`h-3.5 w-3.5`}),t[10]=p):p=t[10];let m;t[11]===l?m=t[12]:(m=(0,$.jsx)(Ee,{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)(z,{children:`Save image`}),t[13]=h):h=t[13];let g;t[14]===m?g=t[15]:(g=(0,$.jsxs)(k,{children:[m,h]}),t[14]=m,t[15]=g);let _;t[16]===i?_=t[17]:(_=i?(0,$.jsx)(tn,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(N,{className:`h-3.5 w-3.5`}),t[16]=i,t[17]=_);let v;t[18]!==d||t[19]!==_?(v=(0,$.jsx)(Ee,{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)(z,{children:y}),t[21]=y,t[22]=b);let x;t[23]!==v||t[24]!==b?(x=(0,$.jsxs)(k,{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)(ce,{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 dc=(0,Y.createContext)(null);function fc(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(mc)},t[0]=d):d=t[0];let f=d,p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{u(pc)},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)(dc.Provider,{value:g,children:n}),t[7]=n,t[8]=g,t[9]=_):_=t[9],_}function pc(e){return e+1}function mc(e){return e+1}function hc(){let e=(0,Y.useContext)(dc);if(!e)throw Error(`useMainTab must be used within a MainTabProvider`);return e}var gc=(0,Y.createContext)(null);function _c(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(vc)},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)(gc.Provider,{value:f,children:n}),t[5]=n,t[6]=f,t[7]=p):p=t[7],p}function vc(e){return e+1}function yc(){let e=(0,Y.useContext)(gc);if(!e)throw Error(`useExplorerTab must be used within an ExplorerTabProvider`);return e}var bc=new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`,`g`),xc=new RegExp(String.raw`\x1B\].*?(?:\x07|\x1B\\)`,`g`),Sc=new RegExp(String.raw`\x1B[@-_]`,`g`),Cc=/\r(?!\n)/g,wc=/\\n/g;function Tc(e){return e.replace(xc,``).replace(bc,``).replace(Sc,``)}function Ec(e){return Tc(e).replace(wc,`
15
+ `).replace(Cc,`
16
+ `)}function Dc(e){return xe(e)}function Oc(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t)}...`}function kc(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:Oc(t,50)}}function Ac(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 jc(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}var Mc=32;function Nc(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=Mc,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=Nc(a,t);e&&i.push(`${n}: ${e}`)}return i.length>0?i.join(`, `):null}function Fc(e){if(!e)return`browser`;let t=typeof e.action==`string`?e.action:`browser`;if(typeof e.url==`string`&&e.url.trim())return`${t} · ${e.url.trim()}`;if(typeof e.ref==`string`&&e.ref.trim())return`${t} · ${e.ref.trim()}`;if(typeof e.text==`string`&&e.text.trim())return`${t} · ${e.text.trim()}`;if(typeof e.selector==`string`&&e.selector.trim())return`${t} · ${e.selector.trim()}`;if(typeof e.preset==`string`&&e.preset.trim())return`${t} · ${e.preset.trim()}`;if(typeof e.script==`string`&&e.script.trim()){let n=e.script.trim();return n.length>40?`${t} · ${n.slice(0,40)}…`:`${t} · ${n}`}return t}function Ic(e){return typeof e!=`object`||!e||Array.isArray(e)?e:nn(e)}function Lc(e){try{return Vc(Ic(JSON.parse(e)))}catch{return Vc(e)}}function Rc(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 zc(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(zc);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=Rc(r);t[n]=typeof e==`object`?zc(e):r}else t[n]=zc(r);return t}function Bc(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
17
+ `),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
18
+ `),t=t.replace(/\\"/g,`"`),t}function Vc(e){if(e==null)return``;let t=typeof e==`object`&&e?zc(e):e;return Ec(Bc(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2)))}function Hc(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:Ac(jc(i),t),d=Ac(o?String(i.prompt):null,t),f=Ac(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=Ac(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??xe(n),R=e.activeDisplayName??$e(n),z=`default`;return w===`bash`||w.includes(`terminal`)||w.includes(`shell`)?z=`bash`:w===`fetch`?z=`fetch`:T?z=`file`:_||w===`find`||w===`web_search`||w.includes(`search`)||w.includes(`grep`)?z=`search`:w===`agent`||w.includes(`subagent`)||o?z=`agent`:w===`todo`?z=`todo`:w===`generate_image`?z=`imageGen`:w===`find_images`?z=`findImages`:w===`browser`&&(z=`browser`),{toolType:z,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 Uc=new Map;function Wc(e){return e.trim()}function Gc(){let e=y(Gt.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[Wc(e)]=r);return n}catch{return{}}}function Kc(e){pe(Gt.BASH_COMMAND_DURATIONS,JSON.stringify(e))}function qc(e){return Gc()[Wc(e)]??null}function Jc(e,t){let n=Wc(e);if(!n||!Number.isFinite(t)||t<=0)return;let r=Gc();r[n]=Math.round(t),Kc(r)}function Yc(e,t){!t?.trim()||Uc.has(e)||Uc.set(e,{command:Wc(t),startedAt:Date.now()})}function Xc(e){let t=Uc.get(e);if(!t)return;let n=Date.now()-t.startedAt;Jc(t.command,n),Uc.delete(e)}function Zc(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 Qc(e,t){return t!==null&&t>0?`${Math.min(99,Math.round(e/t*100))}% complete`:Zc(e)}var $c=1e3;function el(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?qc(n):null),Yc(t,e),s.current=Date.now(),i(0)}else !n&&c.current&&(Xc(t),s.current=null,i(0),o(null));c.current=n},[n,e,t]),(0,Y.useEffect)(()=>()=>{l.current&&Xc(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,$c);return()=>clearInterval(t)},[n]),n?Qc(r,a):null}function tl(e){let{maxHeight:t=`48`,padding:n=`2`,leading:r=!1,className:i}=e??{};return U(J.mono,n===`3`?`p-3`:`p-2`,`bg-muted rounded whitespace-pre-wrap overflow-auto text-foreground`,t===`64`?`max-h-64`:`max-h-48`,r&&`leading-relaxed`,i)}function nl(e){let t=(0,X.c)(13),{open:n,onOpenChange:r,title:i,content:a,markdown:o,threadId:s}=e,c=o===void 0?!1:o,l;t[0]===i?l=t[1]:(l=(0,$.jsx)(En,{children:(0,$.jsx)(Zt,{children:(0,$.jsx)(`code`,{className:J.mono,children:i})})}),t[0]=i,t[1]=l);let u;t[2]!==a||t[3]!==c||t[4]!==s?(u=c?(0,$.jsx)(`div`,{className:U(`flex-1 overflow-auto min-h-0`,J.body),children:(0,$.jsx)(ps,{content:oa(a),threadId:s})}):(0,$.jsx)(`pre`,{className:tl({padding:`3`,className:`flex-1 max-h-none`}),children:a}),t[2]=a,t[3]=c,t[4]=s,t[5]=u):u=t[5];let d;t[6]!==l||t[7]!==u?(d=(0,$.jsxs)(Ce,{className:`max-w-3xl h-[80vh] flex flex-col`,children:[l,u]}),t[6]=l,t[7]=u,t[8]=d):d=t[8];let f;return t[9]!==r||t[10]!==n||t[11]!==d?(f=(0,$.jsx)(Ke,{open:n,onOpenChange:r,children:d}),t[9]=r,t[10]=n,t[11]=d,t[12]=f):f=t[12],f}function rl(e){let t=(0,X.c)(20),{open:n,onOpenChange:r,title:i,requestContent:a,responseContent:o}=e,s;t[0]===i?s=t[1]:(s=(0,$.jsx)(En,{children:(0,$.jsx)(Zt,{children:(0,$.jsx)(`code`,{className:J.mono,children:i})})}),t[0]=i,t[1]=s);let c,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`div`,{className:U(J.compact,`mb-1 text-muted-foreground`),children:`Request`}),l=tl({padding:`3`,className:`max-h-48`}),t[2]=c,t[3]=l):(c=t[2],l=t[3]);let u;t[4]===a?u=t[5]:(u=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[c,(0,$.jsx)(`pre`,{className:l,children:a})]}),t[4]=a,t[5]=u);let d,f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`div`,{className:U(J.compact,`mb-1 text-muted-foreground`),children:`Response`}),f=tl({padding:`3`,className:`flex-1 max-h-none`}),t[6]=d,t[7]=f):(d=t[6],f=t[7]);let p;t[8]===o?p=t[9]:(p=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[d,(0,$.jsx)(`pre`,{className:f,children:o})]}),t[8]=o,t[9]=p);let m;t[10]!==u||t[11]!==p?(m=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[u,p]}),t[10]=u,t[11]=p,t[12]=m):m=t[12];let h;t[13]!==s||t[14]!==m?(h=(0,$.jsxs)(Ce,{className:`max-w-3xl h-[80vh] flex flex-col gap-4`,children:[s,m]}),t[13]=s,t[14]=m,t[15]=h):h=t[15];let g;return t[16]!==r||t[17]!==n||t[18]!==h?(g=(0,$.jsx)(Ke,{open:n,onOpenChange:r,children:h}),t[16]=r,t[17]=n,t[18]=h,t[19]=g):g=t[19],g}function il(e){let t=(0,X.c)(10),{oldText:n,newText:r}=e,i,a,o;if(t[0]!==r||t[1]!==n){let e=n.split(`
21
+ `),s=r.split(`
22
+ `);t[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=U(J.caption,`font-mono whitespace-pre-wrap overflow-auto`),t[5]=i):i=t[5],a=e.map(ol),o=s.map(al),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o}else i=t[2],a=t[3],o=t[4];let s;return t[6]!==i||t[7]!==a||t[8]!==o?(s=(0,$.jsxs)(`pre`,{className:i,children:[a,o]}),t[6]=i,t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function al(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 ol(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 sl(e){let t=(0,X.c)(3),{name:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=U(J.caption,`px-1.5 py-0.5 rounded bg-muted font-mono`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`span`,{className:r,children:n}),t[1]=n,t[2]=i),i}function cl(e){let t=(0,X.c)(3),{type:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=U(J.caption,`px-2 py-0.5 rounded bg-muted`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`span`,{className:r,children:n}),t[1]=n,t[2]=i),i}function ll(e){let t=(0,X.c)(3),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=U(J.caption,`font-mono truncate whitespace-nowrap min-w-0 max-w-full rounded bg-muted/60 px-1 py-0.5`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`code`,{className:r,children:n}),t[1]=n,t[2]=i),i}function ul(e){let t=(0,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=U(`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 dl(e){let t=(0,X.c)(15),{toolName:n,displayName:r,muted:i,size:a,className:o}=e,s=i===void 0?!0:i,c;t[0]===o?c=t[1]:(c=U(`inline-flex items-center gap-1`,o),t[0]=o,t[1]=c);let l=!s&&`text-foreground`,u;t[2]===l?u=t[3]:(u=U(J.caption,l),t[2]=l,t[3]=u);let d;t[4]!==r||t[5]!==u?(d=(0,$.jsx)(`span`,{className:u,children:r}),t[4]=r,t[5]=u,t[6]=d):d=t[6];let f;t[7]!==c||t[8]!==d?(f=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{className:c,children:d})}),t[7]=c,t[8]=d,t[9]=f):f=t[9];let p;t[10]===n?p=t[11]:(p=(0,$.jsx)(z,{children:n}),t[10]=n,t[11]=p);let m;return t[12]!==f||t[13]!==p?(m=(0,$.jsxs)(k,{children:[f,p]}),t[12]=f,t[13]=p,t[14]=m):m=t[14],m}function fl(e){let t=(0,X.c)(106),{data:n,inline:r,resultContent:i,isActive:a}=e,s=(0,Y.useRef)(null),[c,l]=(0,Y.useState)(!!a),[u,d]=(0,Y.useState)(!1),f=(0,Y.useRef)(!!a),p;t[0]===n.toolId?p=t[1]:(p=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=p);let m=Q(p),h=a?m??i??``:i??``,g;t[2]===h?g=t[3]:(g=h?Ec(h):``,t[2]=h,t[3]=g);let _=g,v=a?_:``,y=el(n.command,n.toolId,!!a),b;t[4]===n.command?b=t[5]:(b=n.command===null?null:kc(n.command),t[4]=n.command,t[5]=b);let x=b,S,C;t[6]===a?(S=t[7],C=t[8]):(S=()=>{a&&!f.current?l(!0):!a&&f.current&&l(!1),f.current=!!a},C=[a],t[6]=a,t[7]=S,t[8]=C),(0,Y.useEffect)(S,C);let w;t[9]!==a||t[10]!==c?(w=()=>{c&&a&&s.current&&(s.current.scrollTop=s.current.scrollHeight)},t[9]=a,t[10]=c,t[11]=w):w=t[11];let T;if(t[12]!==a||t[13]!==c||t[14]!==v?(T=[c,a,v],t[12]=a,t[13]=c,t[14]=v,t[15]=T):T=t[15],(0,Y.useEffect)(w,T),r){if(a){let e;t[16]===c?e=t[17]:(e=()=>l(!c),t[16]=c,t[17]=e);let r;t[18]!==n.activeDisplayName||t[19]!==n.toolName?(r=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!1,className:`shrink-0`}),t[18]=n.activeDisplayName,t[19]=n.toolName,t[20]=r):r=t[20];let i;t[21]===x?i=t[22]:(i=x!==null&&(0,$.jsx)(`span`,{className:U(J.caption,`min-w-0 flex-1 truncate whitespace-nowrap`),children:x.label}),t[21]=x,t[22]=i);let a;t[23]===y?a=t[24]:(a=y&&(0,$.jsx)(`span`,{className:U(J.caption,`tabular-nums shrink-0`),children:y}),t[23]=y,t[24]=a);let u;t[25]===c?u=t[26]:(u=c?(0,$.jsx)(On,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(o,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[25]=c,t[26]=u);let d;t[27]!==c||t[28]!==i||t[29]!==a||t[30]!==u||t[31]!==e||t[32]!==r?(d=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full min-w-0`,onClick:e,"aria-expanded":c,children:[r,i,a,u]}),t[27]=c,t[28]=i,t[29]=a,t[30]=u,t[31]=e,t[32]=r,t[33]=d):d=t[33];let f=c?`grid-rows-[1fr]`:`grid-rows-[0fr]`,p;t[34]===f?p=t[35]:(p=U(`grid transition-[grid-template-rows] duration-200 ease-in-out`,f),t[34]=f,t[35]=p);let m,h;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(m=U(J.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),h={maxHeight:`7.5em`},t[36]=m,t[37]=h):(m=t[36],h=t[37]);let g;t[38]===v?g=t[39]:(g=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:s,className:m,style:h,children:v})}),t[38]=v,t[39]=g);let _;t[40]!==p||t[41]!==g?(_=(0,$.jsx)(`div`,{className:p,children:g}),t[40]=p,t[41]=g,t[42]=_):_=t[42];let b;return t[43]!==d||t[44]!==_?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[d,_]}),t[43]=d,t[44]=_,t[45]=b):b=t[45],b}if(x!==null&&_){let e=x.label!==x.fullText,r;t[46]!==n.displayName||t[47]!==n.toolName?(r=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[46]=n.displayName,t[47]=n.toolName,t[48]=r):r=t[48];let i,a;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>d(!0),i=U(J.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 cursor-pointer`),t[49]=i,t[50]=a):(i=t[49],a=t[50]);let o;t[51]===x.label?o=t[52]:(o=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:a,className:i,children:x.label})}),t[51]=x.label,t[52]=o);let s=e?x.fullText:`View output`,c;t[53]===s?c=t[54]:(c=(0,$.jsx)(z,{className:`max-w-md break-all font-mono`,children:s}),t[53]=s,t[54]=c);let l;t[55]!==o||t[56]!==c?(l=(0,$.jsxs)(k,{children:[o,c]}),t[55]=o,t[56]=c,t[57]=l):l=t[57];let f;t[58]!==l||t[59]!==r?(f=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,l]}),t[58]=l,t[59]=r,t[60]=f):f=t[60];let p;t[61]!==x.fullText||t[62]!==u||t[63]!==_?(p=(0,$.jsx)(nl,{open:u,onOpenChange:d,title:x.fullText,content:_}),t[61]=x.fullText,t[62]=u,t[63]=_,t[64]=p):p=t[64];let m;return t[65]!==f||t[66]!==p?(m=(0,$.jsxs)($.Fragment,{children:[f,p]}),t[65]=f,t[66]=p,t[67]=m):m=t[67],m}let e;t[68]!==n.displayName||t[69]!==n.toolName?(e=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[68]=n.displayName,t[69]=n.toolName,t[70]=e):e=t[70];let r;t[71]===x?r=t[72]:(r=x!==null&&(0,$.jsx)(`code`,{className:U(J.caption,`font-mono truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:x.label}),t[71]=x,t[72]=r);let i;return t[73]!==e||t[74]!==r?(i=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[73]=e,t[74]=r,t[75]=i):i=t[75],i}let E;t[76]===c?E=t[77]:(E=()=>l(!c),t[76]=c,t[77]=E);let D;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(D=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[78]=D):D=t[78];let O;t[79]!==n.activeDisplayName||t[80]!==n.displayName||t[81]!==a||t[82]!==y?(O=a?(0,$.jsxs)($.Fragment,{children:[n.activeDisplayName,y&&(0,$.jsx)(`span`,{className:`ml-2 text-muted-foreground tabular-nums`,children:y})]}):n.displayName,t[79]=n.activeDisplayName,t[80]=n.displayName,t[81]=a,t[82]=y,t[83]=O):O=t[83];let A;t[84]===O?A=t[85]:(A=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:O}),t[84]=O,t[85]=A);let j;t[86]===c?j=t[87]:(j=c?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[86]=c,t[87]=j);let M;t[88]!==A||t[89]!==j||t[90]!==E?(M=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:E,className:D,children:[A,j]})}),t[88]=A,t[89]=j,t[90]=E,t[91]=M):M=t[91];let N;t[92]===n.toolName?N=t[93]:(N=(0,$.jsx)(z,{children:n.toolName}),t[92]=n.toolName,t[93]=N);let P;t[94]!==M||t[95]!==N?(P=(0,$.jsxs)(k,{children:[M,N]}),t[94]=M,t[95]=N,t[96]=P):P=t[96];let F;t[97]!==n.toolId||t[98]!==n.toolInput||t[99]!==a||t[100]!==c||t[101]!==v?(F=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(`div`,{ref:s,className:U(J.caption,`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),style:{maxHeight:`7.5em`},children:v}):n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null]}),t[97]=n.toolId,t[98]=n.toolInput,t[99]=a,t[100]=c,t[101]=v,t[102]=F):F=t[102];let I;return t[103]!==P||t[104]!==F?(I=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[P,F]}),t[103]=P,t[104]=F,t[105]=I):I=t[105],I}function pl(e){let t=(0,X.c)(50),{data:n,inline:r,resultContent:i,isActive:a}=e,[s,c]=(0,Y.useState)(!!a),[l,u]=(0,Y.useState)(!1),d=n.fetchUrl,f;t[0]===i?f=t[1]:(f=i?ml(i):null,t[0]=i,t[1]=f);let p=f;if(r){let e;t[2]===s?e=t[3]:(e=()=>c(!s),t[2]=s,t[3]=e);let r=n.toolName,l=n.activeDisplayName,u=!!a,f;t[4]!==n.activeDisplayName||t[5]!==n.toolName||t[6]!==u?(f=(0,$.jsx)(dl,{toolName:r,displayName:l,isActive:u}),t[4]=n.activeDisplayName,t[5]=n.toolName,t[6]=u,t[7]=f):f=t[7];let m;t[8]===d?m=t[9]:(m=d!==null&&(0,$.jsx)(`span`,{className:U(J.caption,`break-all`),children:d}),t[8]=d,t[9]=m);let h;t[10]===p?h=t[11]:(h=p&&(0,$.jsxs)(`span`,{className:U(J.caption,`text-muted-foreground shrink-0`),children:[p.bytes,` bytes · HTTP `,p.code]}),t[10]=p,t[11]=h);let g;t[12]===s?g=t[13]:(g=s?(0,$.jsx)(On,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(o,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[12]=s,t[13]=g);let _;t[14]!==s||t[15]!==e||t[16]!==f||t[17]!==m||t[18]!==h||t[19]!==g?(_=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":s,children:[f,m,h,g]}),t[14]=s,t[15]=e,t[16]=f,t[17]=m,t[18]=h,t[19]=g,t[20]=_):_=t[20];let v;t[21]!==s||t[22]!==i?(v=s&&i&&(0,$.jsx)(`pre`,{className:U(J.mono,J.caption,`whitespace-pre-wrap break-all rounded bg-muted/40 p-2 max-h-48 overflow-auto`),children:hl(i)}),t[21]=s,t[22]=i,t[23]=v):v=t[23];let y;return t[24]!==_||t[25]!==v?(y=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[_,v]}),t[24]=_,t[25]=v,t[26]=y):y=t[26],y}let m=n.toolName,h=n.displayName,g=!!a,_;t[27]!==n.displayName||t[28]!==n.toolName||t[29]!==g?(_=(0,$.jsx)(dl,{toolName:m,displayName:h,isActive:g}),t[27]=n.displayName,t[28]=n.toolName,t[29]=g,t[30]=_):_=t[30];let v;t[31]===d?v=t[32]:(v=d!==null&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`code`,{className:U(J.mono,J.caption,`break-all`),children:d})}),(0,$.jsx)(z,{children:d})]}),t[31]=d,t[32]=v);let y;t[33]===p?y=t[34]:(y=p&&(0,$.jsxs)(`span`,{className:U(J.caption,`text-muted-foreground`),children:[p.bytes,` bytes · HTTP `,p.code,` · `,p.durationMs,`ms`]}),t[33]=p,t[34]=y);let b;t[35]===i?b=t[36]:(b=i&&(0,$.jsx)(`button`,{type:`button`,className:U(J.caption,`text-brand hover:underline ml-auto`),onClick:()=>u(!0),children:`View result`}),t[35]=i,t[36]=b);let x;t[37]!==_||t[38]!==v||t[39]!==y||t[40]!==b?(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[_,v,y,b]}),t[37]=_,t[38]=v,t[39]=y,t[40]=b,t[41]=x):x=t[41];let S;t[42]===i?S=t[43]:(S=i?hl(i):``,t[42]=i,t[43]=S);let C;t[44]!==l||t[45]!==S?(C=(0,$.jsx)(nl,{open:l,onOpenChange:u,title:`Fetch result`,content:S}),t[44]=l,t[45]=S,t[46]=C):C=t[46];let w;return t[47]!==C||t[48]!==x?(w=(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-3 my-1`,children:[x,C]}),t[47]=C,t[48]=x,t[49]=w):w=t[49],w}function ml(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 hl(e){try{let t=JSON.parse(e);if(typeof t.result==`string`)return t.result}catch{}return e}var gl=Gr,_l=kr,vl=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=U(`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)(Vr,{children:(0,$.jsx)(Dr,{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});vl.displayName=Dr.displayName;function yl(e){let t=(0,X.c)(6),{type:n,count:r}=e,i=n===`added`?`text-green-600 dark:text-green-400`:`text-red-600 dark:text-red-400`,a;t[0]===i?a=t[1]:(a=U(J.compact,`font-mono tabular-nums`,i),t[0]=i,t[1]=a);let o=n===`added`?`+`:`-`,s;return t[2]!==r||t[3]!==a||t[4]!==o?(s=(0,$.jsxs)(`span`,{className:a,children:[o,r]}),t[2]=r,t[3]=a,t[4]=o,t[5]=s):s=t[5],s}function bl(e){let t=(0,X.c)(3),{offset:n,limit:r}=e;if(n===null&&r===null)return null;let i;i=n!==null&&r!==null?`${n}-${n+r}`:n===null?`${r}`:`${n}-`;let a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=U(J.compact,`font-mono tabular-nums text-muted-foreground`),t[0]=a):a=t[0];let o;return t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{className:a,children:i}),t[1]=i,t[2]=o),o}function xl(e){let t=(0,X.c)(51),{data:n,inline:r,rootPath:i,onOpenFile:a}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d;t[0]!==n.filePath||t[1]!==a||t[2]!==i?(d=function(){!n.filePath||!a||a(i&&n.filePath.startsWith(i)?n.filePath.slice(i.length+1):n.filePath)},t[0]=n.filePath,t[1]=a,t[2]=i,t[3]=d):d=t[3];let f=d;if(r){let e=!!(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName),r;t[4]!==n.displayName||t[5]!==n.toolId||t[6]!==n.toolInput||t[7]!==n.toolName||t[8]!==e?(r=e?(0,$.jsxs)(gl,{children:[(0,$.jsx)(_l,{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)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),(0,$.jsx)(vl,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:U(J.caption,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput})]})})]}):(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[4]=n.displayName,t[5]=n.toolId,t[6]=n.toolInput,t[7]=n.toolName,t[8]=e,t[9]=r):r=t[9];let a;t[10]!==n.editAddedLineCount||t[11]!==n.editDeletedLineCount||t[12]!==n.editNewText||t[13]!==n.editOldText||t[14]!==n.fileDisplayName||t[15]!==n.filePath||t[16]!==n.hasEditDiff||t[17]!==n.limit||t[18]!==n.offset||t[19]!==n.path||t[20]!==n.toolName||t[21]!==l||t[22]!==f||t[23]!==i?(a=n.fileDisplayName?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:n.hasEditDiff?()=>u(!0):f,className:U(`inline-flex max-w-full items-center gap-2 cursor-pointer`,J.caption,`font-mono hover:underline`),children:[(0,$.jsx)(`span`,{className:`truncate max-w-[200px] sm:max-w-[320px]`,children:n.fileDisplayName}),n.toolName===`read`?(0,$.jsx)(bl,{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)(yl,{type:`added`,count:n.editAddedLineCount}),n.editDeletedLineCount===null?null:(0,$.jsx)(yl,{type:`deleted`,count:n.editDeletedLineCount})]}):null]})}),(0,$.jsx)(z,{children:n.hasEditDiff?`View diff`:n.filePath?Ac(n.filePath,i)??n.filePath:n.fileDisplayName})]}),n.hasEditDiff&&(0,$.jsx)(Ke,{open:l,onOpenChange:u,children:(0,$.jsxs)(Ce,{className:`max-w-2xl h-[80vh] flex flex-col`,children:[(0,$.jsx)(En,{children:(0,$.jsx)(Zt,{children:(0,$.jsx)(`code`,{className:U(J.caption,`font-mono`),children:Ac(n.filePath,i)??n.filePath})})}),(0,$.jsx)(`div`,{className:`overflow-auto flex-1 rounded border border-border bg-muted/30 p-3`,children:(0,$.jsx)(il,{oldText:n.editOldText,newText:n.editNewText})})]})})]}):n.path===null?null:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{className:U(J.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(z,{children:n.path})]}),t[10]=n.editAddedLineCount,t[11]=n.editDeletedLineCount,t[12]=n.editNewText,t[13]=n.editOldText,t[14]=n.fileDisplayName,t[15]=n.filePath,t[16]=n.hasEditDiff,t[17]=n.limit,t[18]=n.offset,t[19]=n.path,t[20]=n.toolName,t[21]=l,t[22]=f,t[23]=i,t[24]=a):a=t[24];let o;return t[25]!==r||t[26]!==a?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,a]}),t[25]=r,t[26]=a,t[27]=o):o=t[27],o}let p;t[28]===s?p=t[29]:(p=()=>c(!s),t[28]=s,t[29]=p);let m;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(m=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[30]=m):m=t[30];let h;t[31]===n.displayName?h=t[32]:(h=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[31]=n.displayName,t[32]=h);let g;t[33]===s?g=t[34]:(g=s?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[33]=s,t[34]=g);let _;t[35]!==p||t[36]!==h||t[37]!==g?(_=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:p,className:m,children:[h,g]})}),t[35]=p,t[36]=h,t[37]=g,t[38]=_):_=t[38];let v;t[39]===n.toolName?v=t[40]:(v=(0,$.jsx)(z,{children:n.toolName}),t[39]=n.toolName,t[40]=v);let y;t[41]!==_||t[42]!==v?(y=(0,$.jsxs)(k,{children:[_,v]}),t[41]=_,t[42]=v,t[43]=y):y=t[43];let b;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==s?(b=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=s,t[47]=b):b=t[47];let x;return t[48]!==y||t[49]!==b?(x=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[y,b]}),t[48]=y,t[49]=b,t[50]=x):x=t[50],x}function Sl(e){let t=e.replace(/\s+/g,` `).trim();return{fullText:t,label:Oc(t,50)}}function Cl(e){let t=(0,X.c)(11),{text:n}=e,r;t[0]===n?r=t[1]:(r=Sl(n),t[0]=n,t[1]=r);let{label:i,fullText:a}=r,o;t[2]===i?o=t[3]:(o=(0,$.jsx)(ll,{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)(Ee,{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)(z,{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)(k,{children:[c,l]}),t[8]=c,t[9]=l,t[10]=u):u=t[10],u}function wl(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)(Cl,{text:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsx)(Cl,{text:`/${n.pattern}/`}),n.codeSearchFilePath!==null&&(0,$.jsx)(Cl,{text:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(Cl,{text:n.codeSearchFileGlob})]}):(0,$.jsxs)($.Fragment,{children:[n.webSearchQuery!==null&&(0,$.jsx)(Cl,{text:n.webSearchQuery}),n.pattern!==null&&(0,$.jsx)(Cl,{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 Tl(e){let t=(0,X.c)(72),{data:n,inline:r,resultContent:i,isActive:a}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=n.toolName===`code_search`,f=n.webSearchQuery??n.codeSearchQuery??n.pattern??n.codeSearchFilePath??n.codeSearchFileGlob??`search`,p;t[0]===f?p=t[1]:(p=Sl(f),t[0]=f,t[1]=p);let{label:m,fullText:h}=p,g=m!==h;if(r){if(i&&(d||n.toolName===`find`||n.webSearchQuery!==null||n.pattern!==null)){let e;t[2]!==n.displayName||t[3]!==n.toolName||t[4]!==a?(e=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:a,className:`shrink-0`}),t[2]=n.displayName,t[3]=n.toolName,t[4]=a,t[5]=e):e=t[5];let r,o;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>u(!0),o=U(J.caption,`font-mono hover:underline truncate whitespace-nowrap min-w-0 cursor-pointer text-left`),t[6]=r,t[7]=o):(r=t[6],o=t[7]);let s;t[8]===m?s=t[9]:(s=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:o,children:m})}),t[8]=m,t[9]=s);let c=g?h:`View results`,d;t[10]===c?d=t[11]:(d=(0,$.jsx)(z,{className:`max-w-md break-all font-mono`,children:c}),t[10]=c,t[11]=d);let f;t[12]!==s||t[13]!==d?(f=(0,$.jsxs)(k,{children:[s,d]}),t[12]=s,t[13]=d,t[14]=f):f=t[14];let p;t[15]!==e||t[16]!==f?(p=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,f]}),t[15]=e,t[16]=f,t[17]=p):p=t[17];let _;t[18]!==l||t[19]!==i||t[20]!==h?(_=(0,$.jsx)(nl,{open:l,onOpenChange:u,title:h,content:i}),t[18]=l,t[19]=i,t[20]=h,t[21]=_):_=t[21];let v;return t[22]!==_||t[23]!==p?(v=(0,$.jsxs)($.Fragment,{children:[p,_]}),t[22]=_,t[23]=p,t[24]=v):v=t[24],v}let e;t[25]!==n.displayName||t[26]!==n.toolName||t[27]!==a?(e=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:a,className:`shrink-0`}),t[25]=n.displayName,t[26]=n.toolName,t[27]=a,t[28]=e):e=t[28];let r;t[29]===n?r=t[30]:(r=(0,$.jsx)(wl,{data:n}),t[29]=n,t[30]=r);let o;t[31]===n.lang?o=t[32]:(o=n.lang!==null&&(0,$.jsx)(`span`,{className:U(J.caption,`px-1.5 py-0.5 rounded bg-muted`),children:n.lang}),t[31]=n.lang,t[32]=o);let s;return t[33]!==e||t[34]!==r||t[35]!==o?(s=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 min-w-0`,children:[e,r,o]}),t[33]=e,t[34]=r,t[35]=o,t[36]=s):s=t[36],s}let _;t[37]===s?_=t[38]:(_=()=>c(!s),t[37]=s,t[38]=_);let v;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(v=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[39]=v):v=t[39];let y;t[40]===a?y=t[41]:(y=a&&(0,$.jsx)(ul,{size:`md`}),t[40]=a,t[41]=y);let b;t[42]===n.displayName?b=t[43]:(b=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[42]=n.displayName,t[43]=b);let x;t[44]!==n.codeSearchFileGlob||t[45]!==n.codeSearchFilePath||t[46]!==n.codeSearchQuery||t[47]!==n.pattern||t[48]!==d?(x=d&&(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(`code`,{className:U(J.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:U(J.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:U(J.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:U(J.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]=d,t[49]=x):x=t[49];let S;t[50]===s?S=t[51]:(S=s?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[50]=s,t[51]=S);let C;t[52]!==_||t[53]!==y||t[54]!==b||t[55]!==x||t[56]!==S?(C=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:_,className:v,children:[y,b,x,S]})}),t[52]=_,t[53]=y,t[54]=b,t[55]=x,t[56]=S,t[57]=C):C=t[57];let w;t[58]===n.toolName?w=t[59]:(w=(0,$.jsx)(z,{children:n.toolName}),t[58]=n.toolName,t[59]=w);let T;t[60]!==C||t[61]!==w?(T=(0,$.jsxs)(k,{children:[C,w]}),t[60]=C,t[61]=w,t[62]=T):T=t[62];let E;t[63]!==n.toolId||t[64]!==n.toolInput||t[65]!==s||t[66]!==d||t[67]!==i?(E=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null,d&&i&&(0,$.jsx)(`pre`,{className:tl({maxHeight:`64`,className:`mt-2`}),children:i})]}),t[63]=n.toolId,t[64]=n.toolInput,t[65]=s,t[66]=d,t[67]=i,t[68]=E):E=t[68];let D;return t[69]!==T||t[70]!==E?(D=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[T,E]}),t[69]=T,t[70]=E,t[71]=D):D=t[71],D}function El(e){let t=(0,X.c)(13),{output:n,scrollRef:r,placeholder:i,threadId:a,className:o,style:s}=e,c;t[0]===n?c=t[1]:(c=n?oa(Ec(n)):``,t[0]=n,t[1]=c);let l=c,u;t[2]===o?u=t[3]:(u=U(J.caption,`text-muted-foreground/60 overflow-y-auto scrollbar-hide`,o),t[2]=o,t[3]=u);let d;t[4]!==l||t[5]!==i||t[6]!==a?(d=l?(0,$.jsx)(ps,{content:l,compact:!0,threadId:a}):i,t[4]=l,t[5]=i,t[6]=a,t[7]=d):d=t[7];let f;return t[8]!==r||t[9]!==s||t[10]!==u||t[11]!==d?(f=(0,$.jsx)(`div`,{ref:r,className:u,style:s,children:d}),t[8]=r,t[9]=s,t[10]=u,t[11]=d,t[12]=f):f=t[12],f}function Dl(e){let t=(0,X.c)(136),{data:n,inline:r,resultContent:i,isActive:a}=e,s=(0,Y.useRef)(null),[c,l]=(0,Y.useState)(!!a),[u,d]=(0,Y.useState)(!1),f=(0,Y.useRef)(!!a),p;t[0]===n.toolId?p=t[1]:(p=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=p);let m=Q(p),h=Q(Ol),g=a?m??i??``:i??m??``,_;t[2]===g?_=t[3]:(_=g?Ec(g):``,t[2]=g,t[3]=_);let v=_,y=a?v:``,b,x;t[4]===a?(b=t[5],x=t[6]):(b=()=>{a&&!f.current?l(!0):!a&&f.current&&l(!1),f.current=!!a},x=[a],t[4]=a,t[5]=b,t[6]=x),(0,Y.useEffect)(b,x);let S;t[7]!==c||t[8]!==a?(S=()=>{c&&a&&s.current&&(s.current.scrollTop=s.current.scrollHeight)},t[7]=c,t[8]=a,t[9]=S):S=t[9];let C;if(t[10]!==c||t[11]!==a||t[12]!==y?(C=[c,a,y],t[10]=c,t[11]=a,t[12]=y,t[13]=C):C=t[13],(0,Y.useEffect)(S,C),r){if(a){let e;t[14]===c?e=t[15]:(e=()=>l(!c),t[14]=c,t[15]=e);let r;t[16]!==n.activeDisplayName||t[17]!==n.toolName?(r=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!0}),t[16]=n.activeDisplayName,t[17]=n.toolName,t[18]=r):r=t[18];let i;t[19]===n.agentName?i=t[20]:(i=n.agentName&&(0,$.jsx)(sl,{name:n.agentName}),t[19]=n.agentName,t[20]=i);let a;t[21]===n.subagentType?a=t[22]:(a=n.subagentType&&(0,$.jsx)(cl,{type:n.subagentType}),t[21]=n.subagentType,t[22]=a);let u;t[23]===c?u=t[24]:(u=c?(0,$.jsx)(On,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(o,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[23]=c,t[24]=u);let d;t[25]!==c||t[26]!==a||t[27]!==u||t[28]!==e||t[29]!==r||t[30]!==i?(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":c,children:[r,i,a,u]}),t[25]=c,t[26]=a,t[27]=u,t[28]=e,t[29]=r,t[30]=i,t[31]=d):d=t[31];let f=c?`grid-rows-[1fr]`:`grid-rows-[0fr]`,p;t[32]===f?p=t[33]:(p=U(`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 g;t[35]!==y||t[36]!==h?(g=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(El,{scrollRef:s,output:y,placeholder:`Running subagent...`,threadId:h,className:`ml-5`,style:m})}),t[35]=y,t[36]=h,t[37]=g):g=t[37];let _;t[38]!==p||t[39]!==g?(_=(0,$.jsx)(`div`,{className:p,children:g}),t[38]=p,t[39]=g,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(v){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(_l,{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)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:!1})})})}),t[44]=n.displayName,t[45]=n.toolName,t[46]=e):e=t[46];let r;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(r=U(J.caption,`space-y-2`),t[47]=r):r=t[47];let i;t[48]===n.toolId?i=t[49]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[48]=n.toolId,t[49]=i);let a;t[50]!==n.prompt||t[51]!==n.toolInput?(a=n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null,t[50]=n.prompt,t[51]=n.toolInput,t[52]=a):a=t[52];let o;t[53]!==a||t[54]!==i?(o=(0,$.jsx)(vl,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,a]})}),t[53]=a,t[54]=i,t[55]=o):o=t[55];let s;t[56]!==o||t[57]!==e?(s=(0,$.jsxs)(gl,{children:[e,o]}),t[56]=o,t[57]=e,t[58]=s):s=t[58];let c;t[59]===n.agentName?c=t[60]:(c=n.agentName&&(0,$.jsx)(sl,{name:n.agentName}),t[59]=n.agentName,t[60]=c);let l;t[61]===n.subagentType?l=t[62]:(l=n.subagentType&&(0,$.jsx)(cl,{type:n.subagentType}),t[61]=n.subagentType,t[62]=l);let f;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:U(J.caption,`text-muted-foreground hover:underline`),children:`View output`})}),(0,$.jsx)(z,{children:`View subagent output`})]}),t[63]=f):f=t[63];let p;t[64]!==s||t[65]!==c||t[66]!==l?(p=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[s,c,l,f]}),t[64]=s,t[65]=c,t[66]=l,t[67]=p):p=t[67];let m;t[68]!==n.displayName||t[69]!==u||t[70]!==v||t[71]!==h?(m=(0,$.jsx)(nl,{open:u,onOpenChange:d,title:n.displayName,content:v,markdown:!0,threadId:h}),t[68]=n.displayName,t[69]=u,t[70]=v,t[71]=h,t[72]=m):m=t[72];let g;return t[73]!==p||t[74]!==m?(g=(0,$.jsxs)($.Fragment,{children:[p,m]}),t[73]=p,t[74]=m,t[75]=g):g=t[75],g}let e;t[76]!==n.displayName||t[77]!==n.toolName?(e=(0,$.jsx)(_l,{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)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),t[76]=n.displayName,t[77]=n.toolName,t[78]=e):e=t[78];let r;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(r=U(J.caption,`space-y-2`),t[79]=r):r=t[79];let i;t[80]===n.toolId?i=t[81]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[80]=n.toolId,t[81]=i);let f;t[82]!==n.prompt||t[83]!==n.toolInput?(f=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]=f):f=t[84];let p;t[85]!==f||t[86]!==i?(p=(0,$.jsx)(vl,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,f]})}),t[85]=f,t[86]=i,t[87]=p):p=t[87];let m;t[88]!==p||t[89]!==e?(m=(0,$.jsxs)(gl,{children:[e,p]}),t[88]=p,t[89]=e,t[90]=m):m=t[90];let g;t[91]===n.agentName?g=t[92]:(g=n.agentName&&(0,$.jsx)(sl,{name:n.agentName}),t[91]=n.agentName,t[92]=g);let _;t[93]===n.subagentType?_=t[94]:(_=n.subagentType&&(0,$.jsx)(cl,{type:n.subagentType}),t[93]=n.subagentType,t[94]=_);let b;return t[95]!==m||t[96]!==g||t[97]!==_?(b=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[m,g,_]}),t[95]=m,t[96]=g,t[97]=_,t[98]=b):b=t[98],b}let w;t[99]===c?w=t[100]:(w=()=>l(!c),t[99]=c,t[100]=w);let T;t[101]===Symbol.for(`react.memo_cache_sentinel`)?(T=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[101]=T):T=t[101];let E;t[102]===a?E=t[103]:(E=a&&(0,$.jsx)(ul,{size:`md`}),t[102]=a,t[103]=E);let D=a?n.activeDisplayName:n.displayName,O;t[104]===D?O=t[105]:(O=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:D}),t[104]=D,t[105]=O);let A;t[106]===n.agentName?A=t[107]:(A=n.agentName&&(0,$.jsx)(sl,{name:n.agentName}),t[106]=n.agentName,t[107]=A);let j;t[108]===n.subagentType?j=t[109]:(j=n.subagentType&&(0,$.jsx)(cl,{type:n.subagentType}),t[108]=n.subagentType,t[109]=j);let M;t[110]===c?M=t[111]:(M=c?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[110]=c,t[111]=M);let N;t[112]!==O||t[113]!==A||t[114]!==j||t[115]!==M||t[116]!==w||t[117]!==E?(N=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:w,className:T,children:[E,O,A,j,M]})}),t[112]=O,t[113]=A,t[114]=j,t[115]=M,t[116]=w,t[117]=E,t[118]=N):N=t[118];let P;t[119]===n.toolName?P=t[120]:(P=(0,$.jsx)(z,{children:n.toolName}),t[119]=n.toolName,t[120]=P);let F;t[121]!==N||t[122]!==P?(F=(0,$.jsxs)(k,{children:[N,P]}),t[121]=N,t[122]=P,t[123]=F):F=t[123];let I;t[124]!==n.prompt||t[125]!==n.toolId||t[126]!==n.toolInput||t[127]!==v||t[128]!==c||t[129]!==a||t[130]!==y||t[131]!==h?(I=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(El,{scrollRef:s,output:y,placeholder:`Running subagent...`,threadId:h,style:{maxHeight:`7.5em`}}):n.prompt?(0,$.jsx)(`div`,{className:tl({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):v?(0,$.jsx)(El,{output:v,threadId:h,className:`max-h-64`}):null]}),t[124]=n.prompt,t[125]=n.toolId,t[126]=n.toolInput,t[127]=v,t[128]=c,t[129]=a,t[130]=y,t[131]=h,t[132]=I):I=t[132];let L;return t[133]!==F||t[134]!==I?(L=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[F,I]}),t[133]=F,t[134]=I,t[135]=L):L=t[135],L}function Ol(e){return e.selectedThreadId}function kl(e){let t=(0,X.c)(26),{data:n,inline:r,isActive:i}=e,[a,s]=(0,Y.useState)(!1);if(r)return null;let c;t[0]===a?c=t[1]:(c=()=>s(!a),t[0]=a,t[1]=c);let l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=U(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[2]=l):l=t[2];let u;t[3]===i?u=t[4]:(u=i&&(0,$.jsx)(ul,{size:`md`}),t[3]=i,t[4]=u);let d;t[5]===n.displayName?d=t[6]:(d=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[5]=n.displayName,t[6]=d);let f;t[7]===a?f=t[8]:(f=a?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[7]=a,t[8]=f);let p;t[9]!==c||t[10]!==u||t[11]!==d||t[12]!==f?(p=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:c,className:l,children:[u,d,f]})}),t[9]=c,t[10]=u,t[11]=d,t[12]=f,t[13]=p):p=t[13];let m;t[14]===n.toolName?m=t[15]:(m=(0,$.jsx)(z,{children:n.toolName}),t[14]=n.toolName,t[15]=m);let h;t[16]!==p||t[17]!==m?(h=(0,$.jsxs)(k,{children:[p,m]}),t[16]=p,t[17]=m,t[18]=h):h=t[18];let g;t[19]!==n.toolId||t[20]!==n.toolInput||t[21]!==a?(g=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null]}),t[19]=n.toolId,t[20]=n.toolInput,t[21]=a,t[22]=g):g=t[22];let _;return t[23]!==h||t[24]!==g?(_=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[h,g]}),t[23]=h,t[24]=g,t[25]=_):_=t[25],_}function Al(e){let t=(0,X.c)(35),{data:n,inline:r,isActive:i}=e,[a,s]=(0,Y.useState)(!1);if(r){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==i?(e=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:i}),t[0]=n.displayName,t[1]=n.toolName,t[2]=i,t[3]=e):e=t[3];let r;t[4]===n.imageGenPrompt?r=t[5]:(r=n.imageGenPrompt!==null&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{className:U(J.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.imageGenPrompt})}),(0,$.jsx)(z,{children:n.imageGenPrompt})]}),t[4]=n.imageGenPrompt,t[5]=r);let a;return t[6]!==e||t[7]!==r?(a=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[6]=e,t[7]=r,t[8]=a):a=t[8],a}let c;t[9]===a?c=t[10]:(c=()=>s(!a),t[9]=a,t[10]=c);let l;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(l=U(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[11]=l):l=t[11];let u;t[12]===i?u=t[13]:(u=i&&(0,$.jsx)(ul,{size:`md`}),t[12]=i,t[13]=u);let d;t[14]===n.displayName?d=t[15]:(d=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[14]=n.displayName,t[15]=d);let f;t[16]===a?f=t[17]:(f=a?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[16]=a,t[17]=f);let p;t[18]!==c||t[19]!==u||t[20]!==d||t[21]!==f?(p=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:c,className:l,children:[u,d,f]})}),t[18]=c,t[19]=u,t[20]=d,t[21]=f,t[22]=p):p=t[22];let m;t[23]===n.toolName?m=t[24]:(m=(0,$.jsx)(z,{children:n.toolName}),t[23]=n.toolName,t[24]=m);let h;t[25]!==p||t[26]!==m?(h=(0,$.jsxs)(k,{children:[p,m]}),t[25]=p,t[26]=m,t[27]=h):h=t[27];let g;t[28]!==n.toolId||t[29]!==n.toolInput||t[30]!==a?(g=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null]}),t[28]=n.toolId,t[29]=n.toolInput,t[30]=a,t[31]=g):g=t[31];let _;return t[32]!==h||t[33]!==g?(_=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[h,g]}),t[32]=h,t[33]=g,t[34]=_):_=t[34],_}function jl(e){if(!e)return null;try{let t=JSON.parse(e);return Xo(t,{content:e,...t})}catch{return Xo(e,{content:e})}}function Ml(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`image`}function Nl(e){let t=(0,X.c)(54),{data:n,inline:r,resultContent:i,isActive:a}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(Pl),f,p;t[0]===i?(f=t[1],p=t[2]):(f=jl(i),p=f?Ml(f):null,t[0]=i,t[1]=f,t[2]=p);let m=p;if(r){let e;t[3]!==n.displayName||t[4]!==n.toolName||t[5]!==a?(e=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[3]=n.displayName,t[4]=n.toolName,t[5]=a,t[6]=e):e=t[6];let r;t[7]!==n.findImagesQuery||t[8]!==f?(r=n.findImagesQuery!==null&&!f&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{className:U(J.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.findImagesQuery})}),(0,$.jsx)(z,{children:n.findImagesQuery})]}),t[7]=n.findImagesQuery,t[8]=f,t[9]=r):r=t[9];let i;t[10]!==f||t[11]!==m?(i=f&&m&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:U(J.caption,`hover:underline`),children:[`Found `,m]})}),(0,$.jsx)(z,{children:`View image`})]}),t[10]=f,t[11]=m,t[12]=i):i=t[12];let o;t[13]!==e||t[14]!==r||t[15]!==i?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r,i]}),t[13]=e,t[14]=r,t[15]=i,t[16]=o):o=t[16];let s;t[17]!==l||t[18]!==f||t[19]!==m||t[20]!==d?(s=f&&(0,$.jsx)(Ke,{open:l,onOpenChange:u,children:(0,$.jsxs)(Ce,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(En,{children:(0,$.jsxs)(Zt,{children:[`Found `,m]})}),(0,$.jsx)(Jo,{imageUrl:f.imageUrl,imageData:f.imageData,threadId:d,alt:m??`Found image`})]})}),t[17]=l,t[18]=f,t[19]=m,t[20]=d,t[21]=s):s=t[21];let c;return t[22]!==o||t[23]!==s?(c=(0,$.jsxs)($.Fragment,{children:[o,s]}),t[22]=o,t[23]=s,t[24]=c):c=t[24],c}let h;t[25]===s?h=t[26]:(h=()=>c(!s),t[25]=s,t[26]=h);let g;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(g=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[27]=g):g=t[27];let _;t[28]===a?_=t[29]:(_=a&&(0,$.jsx)(ul,{size:`md`}),t[28]=a,t[29]=_);let v=f?`Found ${m}`:n.displayName,y;t[30]===v?y=t[31]:(y=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:v}),t[30]=v,t[31]=y);let b;t[32]===s?b=t[33]:(b=s?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[32]=s,t[33]=b);let x;t[34]!==h||t[35]!==_||t[36]!==y||t[37]!==b?(x=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:h,className:g,children:[_,y,b]})}),t[34]=h,t[35]=_,t[36]=y,t[37]=b,t[38]=x):x=t[38];let S;t[39]===n.toolName?S=t[40]:(S=(0,$.jsx)(z,{children:n.toolName}),t[39]=n.toolName,t[40]=S);let C;t[41]!==x||t[42]!==S?(C=(0,$.jsxs)(k,{children:[x,S]}),t[41]=x,t[42]=S,t[43]=C):C=t[43];let w;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==s||t[47]!==f||t[48]!==m||t[49]!==d?(w=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null,f&&(0,$.jsx)(Jo,{imageUrl:f.imageUrl,imageData:f.imageData,threadId:d,alt:m??`Found image`})]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=s,t[47]=f,t[48]=m,t[49]=d,t[50]=w):w=t[50];let T;return t[51]!==C||t[52]!==w?(T=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[C,w]}),t[51]=C,t[52]=w,t[53]=T):T=t[53],T}function Pl(e){return e.selectedThreadId}function Fl(e){if(!e)return null;try{let t=JSON.parse(e);return t.action===`screenshot`?Xo(t,{content:e,...t}):null}catch{return null}}function Il(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`screenshot`}function Ll(e){let t=(0,X.c)(85),{data:n,inline:r,resultContent:i,isActive:a}=e,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(Rl),f;t[0]===n.inputObj?f=t[1]:(f=Fc(n.inputObj),t[0]=n.inputObj,t[1]=f);let p=f,m;t[2]===n.inputObj?m=t[3]:(m=jc(n.inputObj),t[2]=n.inputObj,t[3]=m);let h=m,g;t[4]===i?g=t[5]:(g=i?Lc(i):``,t[4]=i,t[5]=g);let _=g,v,y;t[6]===i?(v=t[7],y=t[8]):(v=Fl(i),y=v?Il(v):null,t[6]=i,t[7]=v,t[8]=y);let b=y;if(r){let e;t[9]!==n.displayName||t[10]!==n.toolName||t[11]!==a?(e=(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[9]=n.displayName,t[10]=n.toolName,t[11]=a,t[12]=e):e=t[12];let r;t[13]!==p||t[14]!==i||t[15]!==b||t[16]!==v?(r=v&&b?(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:U(J.caption,`hover:underline`),children:[`Screenshot `,b]})}),(0,$.jsx)(z,{children:`View screenshot`})]}):i?(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:U(J.caption,`font-mono hover:underline break-all cursor-pointer`),children:p})}),(0,$.jsx)(z,{children:`View results`})]}):(0,$.jsx)(`span`,{className:U(J.caption,`font-mono break-all text-muted-foreground`),children:p}),t[13]=p,t[14]=i,t[15]=b,t[16]=v,t[17]=r):r=t[17];let o;t[18]!==e||t[19]!==r?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[18]=e,t[19]=r,t[20]=o):o=t[20];let s;t[21]!==l||t[22]!==h||t[23]!==p||t[24]!==_||t[25]!==i||t[26]!==b||t[27]!==v||t[28]!==d?(s=v?(0,$.jsx)(Ke,{open:l,onOpenChange:u,children:(0,$.jsxs)(Ce,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(En,{children:(0,$.jsxs)(Zt,{children:[`Screenshot `,b]})}),(0,$.jsx)(Jo,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`})]})}):i&&(0,$.jsx)(rl,{open:l,onOpenChange:u,title:p,requestContent:h,responseContent:_}),t[21]=l,t[22]=h,t[23]=p,t[24]=_,t[25]=i,t[26]=b,t[27]=v,t[28]=d,t[29]=s):s=t[29];let c;return t[30]!==o||t[31]!==s?(c=(0,$.jsxs)($.Fragment,{children:[o,s]}),t[30]=o,t[31]=s,t[32]=c):c=t[32],c}let x;t[33]===s?x=t[34]:(x=()=>c(!s),t[33]=s,t[34]=x);let S;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(S=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[35]=S):S=t[35];let C;t[36]===a?C=t[37]:(C=a&&(0,$.jsx)(ul,{size:`md`}),t[36]=a,t[37]=C);let w=v&&b?`Screenshot ${b}`:n.displayName,T;t[38]===w?T=t[39]:(T=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:w}),t[38]=w,t[39]=T);let E;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(E=U(J.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[40]=E):E=t[40];let D;t[41]===p?D=t[42]:(D=(0,$.jsx)(`span`,{className:E,children:p}),t[41]=p,t[42]=D);let O;t[43]!==i||t[44]!==v?(O=i&&!v&&(0,$.jsx)(`button`,{type:`button`,className:U(J.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),u(!0)},children:`View results`}),t[43]=i,t[44]=v,t[45]=O):O=t[45];let A;t[46]===v?A=t[47]:(A=v&&(0,$.jsx)(`button`,{type:`button`,className:U(J.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),u(!0)},children:`View screenshot`}),t[46]=v,t[47]=A);let j;t[48]===s?j=t[49]:(j=s?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[48]=s,t[49]=j);let M;t[50]!==D||t[51]!==O||t[52]!==A||t[53]!==j||t[54]!==x||t[55]!==C||t[56]!==T?(M=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:x,className:S,children:[C,T,D,O,A,j]})}),t[50]=D,t[51]=O,t[52]=A,t[53]=j,t[54]=x,t[55]=C,t[56]=T,t[57]=M):M=t[57];let N;t[58]===n.toolName?N=t[59]:(N=(0,$.jsx)(z,{children:n.toolName}),t[58]=n.toolName,t[59]=N);let P;t[60]!==M||t[61]!==N?(P=(0,$.jsxs)(k,{children:[M,N]}),t[60]=M,t[61]=N,t[62]=P):P=t[62];let F;t[63]!==n.toolId||t[64]!==s||t[65]!==h||t[66]!==_||t[67]!==i||t[68]!==b||t[69]!==v||t[70]!==d?(F=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border space-y-2`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground font-mono`),children:[`ID: `,n.toolId]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:U(J.compact,`text-muted-foreground mb-1`),children:`Request`}),(0,$.jsx)(`pre`,{className:tl(),children:h})]}),v?(0,$.jsx)(Jo,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`}):i&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:U(J.compact,`text-muted-foreground mb-1`),children:`Response`}),(0,$.jsx)(`pre`,{className:tl({maxHeight:`64`}),children:_})]})]}),t[63]=n.toolId,t[64]=s,t[65]=h,t[66]=_,t[67]=i,t[68]=b,t[69]=v,t[70]=d,t[71]=F):F=t[71];let I;t[72]!==l||t[73]!==h||t[74]!==p||t[75]!==_||t[76]!==i||t[77]!==b||t[78]!==v||t[79]!==d?(I=v?(0,$.jsx)(Ke,{open:l,onOpenChange:u,children:(0,$.jsxs)(Ce,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(En,{children:(0,$.jsxs)(Zt,{children:[`Screenshot `,b]})}),(0,$.jsx)(Jo,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`})]})}):i&&(0,$.jsx)(rl,{open:l,onOpenChange:u,title:p,requestContent:h,responseContent:_}),t[72]=l,t[73]=h,t[74]=p,t[75]=_,t[76]=i,t[77]=b,t[78]=v,t[79]=d,t[80]=I):I=t[80];let L;return t[81]!==P||t[82]!==F||t[83]!==I?(L=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[P,F,I]}),t[81]=P,t[82]=F,t[83]=I,t[84]=L):L=t[84],L}function Rl(e){return e.selectedThreadId}function zl(e){let t=(0,X.c)(10),{summary:n,fullSummary:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=U(J.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsx)(`span`,{className:i,children:n}),t[1]=n,t[2]=a);let o=a;if(n===r)return o;let s;t[3]===o?s=t[4]:(s=(0,$.jsx)(Ee,{asChild:!0,children:o}),t[3]=o,t[4]=s);let c;t[5]===r?c=t[6]:(c=(0,$.jsx)(z,{className:`max-w-md break-all font-mono`,children:r}),t[5]=r,t[6]=c);let l;return t[7]!==s||t[8]!==c?(l=(0,$.jsxs)(k,{children:[s,c]}),t[7]=s,t[8]=c,t[9]=l):l=t[9],l}function Bl(e){let t=(0,X.c)(52),{data:n,inline:r,isActive:i}=e,[a,s]=(0,Y.useState)(!1),c,l;if(t[0]!==n.inputObj||t[1]!==n.path||t[2]!==n.prompt){let e=n.path===null?[]:[`path`];c=n.prompt===null?Pc(n.inputObj,32,e):null,l=n.prompt===null?Pc(n.inputObj,1/0,e):null,t[0]=n.inputObj,t[1]=n.path,t[2]=n.prompt,t[3]=c,t[4]=l}else c=t[3],l=t[4];let u=l;if(r){let e=!!(n.prompt??(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName)),r;t[5]!==n.displayName||t[6]!==n.prompt||t[7]!==n.toolId||t[8]!==n.toolInput||t[9]!==n.toolName||t[10]!==e||t[11]!==i?(r=e?(0,$.jsxs)(gl,{children:[(0,$.jsx)(_l,{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)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:i,muted:!1})})})}),(0,$.jsx)(vl,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:U(J.bodyMuted,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null]})})]}):(0,$.jsx)(dl,{toolName:n.toolName,displayName:n.displayName,isActive:i}),t[5]=n.displayName,t[6]=n.prompt,t[7]=n.toolId,t[8]=n.toolInput,t[9]=n.toolName,t[10]=e,t[11]=i,t[12]=r):r=t[12];let a;t[13]!==u||t[14]!==c?(a=c&&u&&(0,$.jsx)(zl,{summary:c,fullSummary:u}),t[13]=u,t[14]=c,t[15]=a):a=t[15];let o;t[16]===n.path?o=t[17]:(o=n.path!==null&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{className:U(J.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(z,{children:n.path})]}),t[16]=n.path,t[17]=o);let s;return t[18]!==r||t[19]!==a||t[20]!==o?(s=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,a,o]}),t[18]=r,t[19]=a,t[20]=o,t[21]=s):s=t[21],s}let d;t[22]===a?d=t[23]:(d=()=>s(!a),t[22]=a,t[23]=d);let f;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(f=U(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[24]=f):f=t[24];let p;t[25]===i?p=t[26]:(p=i&&(0,$.jsx)(ul,{size:`md`}),t[25]=i,t[26]=p);let m;t[27]===n.displayName?m=t[28]:(m=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[27]=n.displayName,t[28]=m);let h;t[29]===c?h=t[30]:(h=c&&(0,$.jsx)(`span`,{className:U(J.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),children:c}),t[29]=c,t[30]=h);let g;t[31]===a?g=t[32]:(g=a?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[31]=a,t[32]=g);let _;t[33]!==d||t[34]!==p||t[35]!==m||t[36]!==h||t[37]!==g?(_=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:d,className:f,children:[p,m,h,g]})}),t[33]=d,t[34]=p,t[35]=m,t[36]=h,t[37]=g,t[38]=_):_=t[38];let v;t[39]===n.toolName?v=t[40]:(v=(0,$.jsx)(z,{children:n.toolName}),t[39]=n.toolName,t[40]=v);let y;t[41]!==_||t[42]!==v?(y=(0,$.jsxs)(k,{children:[_,v]}),t[41]=_,t[42]=v,t[43]=y):y=t[43];let b;t[44]!==n.prompt||t[45]!==n.toolId||t[46]!==n.toolInput||t[47]!==a?(b=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:tl({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:tl(),children:n.toolInput}):null]}),t[44]=n.prompt,t[45]=n.toolId,t[46]=n.toolInput,t[47]=a,t[48]=b):b=t[48];let x;return t[49]!==y||t[50]!==b?(x=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[y,b]}),t[49]=y,t[50]=b,t[51]=x):x=t[51],x}function Vl(e){let t=(0,X.c)(51),{block:n,inline:r,resultContent:i,isActive:a}=e,{setActiveMainTab:o}=hc(),{setPendingExplorerPath:s}=yc(),c=Q(Hl),l=Hc(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)(fl,{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)(pl,{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)(xl,{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)(Tl,{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)(Dl,{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)(kl,{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)(Al,{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)(Nl,{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)(Ll,{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)(Bl,{data:l,inline:r,isActive:u}),t[47]=l,t[48]=r,t[49]=u,t[50]=e):e=t[50],e}}}function Hl(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Ul=(0,Y.createContext)({todos:[],setTodos:()=>{}});function Wl(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)(Ul.Provider,{value:f,children:n}),t[7]=n,t[8]=f,t[9]=p):p=t[9],p}function Gl(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 Kl(e){let t=(0,X.c)(5),{todos:n,sequence:r}=e,{setTodos:i}=(0,Y.useContext)(Ul),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 ql(e){let t=(0,X.c)(79),{block:n,inline:r,sequence:i}=e,a=i===void 0?0:i,[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(Yl),f=Q(Jl),p=n.toolName??`Unknown Tool`,m=n.toolCallId??`unknown`,h=n,g=n.result??h.content,_;t[0]!==h||t[1]!==p?(_=p===`todo`?Gl(h):null,t[0]=h,t[1]=p,t[2]=_):_=t[2];let v=_,y,b,x,S,C,w,T;if(t[3]!==h||t[4]!==r||t[5]!==g||t[6]!==d||t[7]!==a||t[8]!==f||t[9]!==v||t[10]!==p){T=Symbol.for(`react.early_return_sentinel`);bb0:{if(b=p===`find_images`?Xo(g,h):null,S=Ac(Vc(g),d),!(S.length>0)&&v===null&&!b){T=null;break bb0}if(y=Dc(p),typeof g==`object`&&g){let e=g,n=e.returnDisplay??e.return_display;if(typeof n==`string`&&n.trim()){let e;t[18]===n?e=t[19]:(e=n.trim(),t[18]=n,t[19]=e),y=e}else if(p===`read`||p===`file_read`){let n=e.filePath??e.file_path??e.path??``;if(n){let e;t[20]===n?e=t[21]:(e=n.split(`/`).pop()??n,t[20]=n,t[21]=e),y=`Completed ${e}`}}}else if(g==null){let e;t[22]===p?e=t[23]:(e=Dc(p),t[22]=p,t[23]=e),y=`${e} (no result)`}if(b){let e=b.savedPath?Ac(b.savedPath.split(`/`).pop()??b.savedPath,d):null;y=e?`Found ${e}`:`Found image`}if(y=Ac(y,d),v!==null){let e;t[24]!==a||t[25]!==v?(e=(0,$.jsx)(Kl,{todos:v,sequence:a}),t[24]=a,t[25]=v,t[26]=e):e=t[26],T=e;break bb0}if(r&&(b||p===`browser`)){T=null;break bb0}if(p===`generate_image`){let e;t[27]!==h||t[28]!==g?(e=Yo(g)??Yo(h),t[27]=h,t[28]=g,t[29]=e):e=t[29];let n=e;if(n&&(n.imageUrl||n.imageData)){let e;t[30]!==n.imageData||t[31]!==n.imageUrl||t[32]!==f?(e=(0,$.jsx)(Jo,{imageUrl:n.imageUrl,imageData:n.imageData,threadId:f}),t[30]=n.imageData,t[31]=n.imageUrl,t[32]=f,t[33]=e):e=t[33],T=e;break bb0}}if(r){T=null;break bb0}let e;t[34]===p?e=t[35]:(e=p.toLowerCase().includes(`bash`),t[34]=p,t[35]=e),x=e,C=S?S.split(`
23
+ `):[],w=x?C.slice(0,3).join(`
24
+ `):S}t[3]=h,t[4]=r,t[5]=g,t[6]=d,t[7]=a,t[8]=f,t[9]=v,t[10]=p,t[11]=y,t[12]=b,t[13]=x,t[14]=S,t[15]=C,t[16]=w,t[17]=T}else y=t[11],b=t[12],x=t[13],S=t[14],C=t[15],w=t[16],T=t[17];if(T!==Symbol.for(`react.early_return_sentinel`))return T;let E=w,D=x&&C.length>3;if(x){let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=U(J.body,`px-3 py-2 flex items-center gap-2 font-medium text-foreground`),t[36]=e):e=t[36];let n;t[37]===y?n=t[38]:(n=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:y})}),t[37]=y,t[38]=n);let r;t[39]!==D||t[40]!==E||t[41]!==S||t[42]!==C?(r=S&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[D?(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`pre`,{className:U(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2 cursor-pointer hover:bg-muted/80`),onClick:()=>u(!0),children:[E,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
25
+ `,`...`]})]})}),(0,$.jsx)(z,{children:`Click to see full output`})]}):(0,$.jsx)(`pre`,{className:U(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2`),children:E}),D&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:U(J.caption,`mt-1 text-brand hover:underline`),children:[`Show full output (`,C.length,` lines)`]})]}),t[39]=D,t[40]=E,t[41]=S,t[42]=C,t[43]=r):r=t[43];let i;t[44]!==n||t[45]!==r?(i=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[n,r]}),t[44]=n,t[45]=r,t[46]=i):i=t[46];let a;t[47]!==l||t[48]!==D||t[49]!==S?(a=D&&(0,$.jsx)(Ke,{open:l,onOpenChange:u,children:(0,$.jsxs)(Ce,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(En,{children:(0,$.jsx)(Zt,{children:`Full Output`})}),(0,$.jsx)(`pre`,{className:U(J.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`),children:S})]})}),t[47]=l,t[48]=D,t[49]=S,t[50]=a):a=t[50];let o;return t[51]!==i||t[52]!==a?(o=(0,$.jsxs)($.Fragment,{children:[i,a]}),t[51]=i,t[52]=a,t[53]=o):o=t[53],o}let O;t[54]===s?O=t[55]:(O=()=>c(!s),t[54]=s,t[55]=O);let A;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(A=U(J.body,`w-full px-3 py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted transition-colors text-left`),t[56]=A):A=t[56];let j;t[57]===y?j=t[58]:(j=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:y}),t[57]=y,t[58]=j);let M;t[59]===s?M=t[60]:(M=s?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[59]=s,t[60]=M);let N;t[61]!==O||t[62]!==j||t[63]!==M?(N=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:O,className:A,children:[j,M]})}),t[61]=O,t[62]=j,t[63]=M,t[64]=N):N=t[64];let P=`${p} result`,F;t[65]===P?F=t[66]:(F=(0,$.jsx)(z,{children:P}),t[65]=P,t[66]=F);let I;t[67]!==F||t[68]!==N?(I=(0,$.jsxs)(k,{children:[N,F]}),t[67]=F,t[68]=N,t[69]=I):I=t[69];let L;t[70]!==s||t[71]!==b||t[72]!==S||t[73]!==f||t[74]!==m?(L=s&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`Call ID: `,m]}),b&&(0,$.jsx)(Jo,{imageUrl:b.imageUrl,imageData:b.imageData,threadId:f}),S&&!b&&(0,$.jsx)(`pre`,{className:U(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`),children:S})]}),t[70]=s,t[71]=b,t[72]=S,t[73]=f,t[74]=m,t[75]=L):L=t[75];let R;return t[76]!==I||t[77]!==L?(R=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[I,L]}),t[76]=I,t[77]=L,t[78]=R):R=t[78],R}function Jl(e){return e.selectedThreadId}function Yl(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Xl=ri(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`]}),Zl=function(e){let t=(0,X.c)(38),{text:n,isStreaming:r,label:i,threadId:a}=e,o=n===void 0?``:n,s=r===void 0?!1:r,c=(0,Y.useRef)(null),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=Date.now(),t[0]=l):l=t[0];let u=(0,Y.useRef)(l),[d,f]=(0,Y.useState)(0),[p,m]=(0,Y.useState)(!1),h=(0,Y.useRef)(s),g,_;t[1]===s?(g=t[2],_=t[3]):(g=()=>{s&&!h.current?(u.current=Date.now(),f(0)):h.current&&!s&&(f(Date.now()-u.current),m(!1)),h.current=s},_=[s],t[1]=s,t[2]=g,t[3]=_),(0,Y.useEffect)(g,_);let v;t[4]!==p||t[5]!==s?(v=()=>{p&&s&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},t[4]=p,t[5]=s,t[6]=v):v=t[6];let y;if(t[7]!==p||t[8]!==s||t[9]!==o?(y=[o,p,s],t[7]=p,t[8]=s,t[9]=o,t[10]=y):y=t[10],(0,Y.useEffect)(v,y),!o&&!s||!s&&d<=0&&i!==`MCP`&&i!==`Validated`)return null;let b=!s&&i===`Validated`,x;t[11]!==d||t[12]!==s||t[13]!==i||t[14]!==o?(x=eu(s,i,d,Ht(o)),t[11]=d,t[12]=s,t[13]=i,t[14]=o,t[15]=x):x=t[15];let S=x,C;t[16]===o?C=t[17]:(C=o?oa(Ec(o)):``,t[16]=o,t[17]=C);let w=C,T;t[18]===p?T=t[19]:(T=()=>m(!p),t[18]=p,t[19]=T);let E;t[20]===b?E=t[21]:(E=b?(0,$.jsx)(Ge,{className:`h-3.5 w-3.5 shrink-0 text-green-600`}):null,t[20]=b,t[21]=E);let D=p?`grid-rows-[1fr]`:`grid-rows-[0fr]`,O;t[22]===D?O=t[23]:(O=[`grid transition-[grid-template-rows] duration-200 ease-in-out`,D],t[22]=D,t[23]=O);let k=O.join(` `),A,j;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(A=U(J.caption,`ml-5 text-muted-foreground/60 overflow-y-auto scrollbar-hide`),j={maxHeight:`7.5em`},t[24]=A,t[25]=j):(A=t[24],j=t[25]);let M;t[26]!==w||t[27]!==a?(M=w?(0,$.jsx)(ps,{content:w,compact:!0,threadId:a}):null,t[26]=w,t[27]=a,t[28]=M):M=t[28];let N;t[29]===M?N=t[30]:(N=(0,$.jsx)(`div`,{ref:c,className:A,style:j,children:M}),t[29]=M,t[30]=N);let P;return t[31]!==p||t[32]!==S||t[33]!==T||t[34]!==E||t[35]!==k||t[36]!==N?(P=(0,$.jsx)(Xl,{v0:T,v1:p,v2:E,v3:J.caption,v4:S,v5:k,v6:N}),t[31]=p,t[32]=S,t[33]=T,t[34]=E,t[35]=k,t[36]=N,t[37]=P):P=t[37],P};function Ql(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 $l(e){return` (${e.toLocaleString()} token${e===1?``:`s`})`}function eu(e,t,n,r){let i=e&&r>0?$l(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 ${Ql(n)}.`}function tu(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 nu(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 ru(e,t){let n=e.find(e=>aa(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 iu(e,t){return e.some(e=>aa(e)&&e.toolCallId===t)}function au(e,t){if(t)return ru(e,t)}var ou=ri(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`]}),su=ri(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`]}),cu=function(e){let t=(0,X.c)(54),{toolCallId:n,question:r,options:i,context:a,answeredText:o,answeredLabel:s}=e,[c,l]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(!!o),[p,m]=(0,Y.useState)(o??``),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(null),y,b;t[0]===o?(y=t[1],b=t[2]):(y=()=>{let e=o?.trim();if(e){f(!0),m(e),g(!1),v(null);return}f(!1),m(``)},b=[o],t[0]=o,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 u(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]!==c||t[11]!==S||t[12]!==h||t[13]!==d?(T=()=>{if(d||h)return;let e=c.trim();e&&S(e)},t[10]=c,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)(tn,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=U(J.label,`text-foreground`),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let i;t[19]===r?i=t[20]:(i=(0,$.jsx)(ps,{content:r}),t[19]=r,t[20]=i);let o;t[21]===a?o=t[22]:(o=a&&(0,$.jsx)(`p`,{className:U(J.bodyMuted,`mt-1`),children:a}),t[21]=a,t[22]=o);let c=s??`You answered`,l;return t[23]!==p||t[24]!==o||t[25]!==c||t[26]!==i?(l=(0,$.jsx)(ou,{v0:e,v1:n,v2:i,v3:o,v4:J.bodyMuted,v5:c,v6:p}),t[23]=p,t[24]=o,t[25]=c,t[26]=i,t[27]=l):l=t[27],l}let k,A;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(Ye,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),A=U(J.label,`text-foreground`),t[28]=k,t[29]=A):(k=t[28],A=t[29]);let j;t[30]===r?j=t[31]:(j=(0,$.jsx)(ps,{content:r}),t[30]=r,t[31]=j);let M;t[32]===a?M=t[33]:(M=a&&(0,$.jsx)(`p`,{className:U(J.bodyMuted,`mt-1`),children:a}),t[32]=a,t[33]=M);let N;t[34]!==w||t[35]!==h||t[36]!==i||t[37]!==_?(N=i&&i.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=_===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>w(e),disabled:h,className:U(`rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50 flex items-center gap-1.5`,J.label,t?`border-foreground/20 bg-accent text-accent-foreground`:`border-foreground/20 bg-background text-foreground hover:bg-accent hover:text-accent-foreground`),children:[t&&(0,$.jsx)(tn,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[34]=w,t[35]=h,t[36]=i,t[37]=_,t[38]=N):N=t[38];let P;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(P=e=>l(e.target.value),t[39]=P):P=t[39];let F=i?.length?`Or type a custom answer...`:`Type your answer...`,I;t[40]!==c||t[41]!==h?(I=h||!c.trim(),t[40]=c,t[41]=h,t[42]=I):I=t[42];let L;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(Tn,{className:`h-3 w-3`}),t[43]=L):L=t[43];let R;return t[44]!==c||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)(su,{v0:k,v1:A,v2:j,v3:M,v4:N,v5:c,v6:P,v7:O,v8:F,v9:h,v10:E,v11:I,v12:L}),t[44]=c,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},lu=Xn,uu=Fr,du=Kr,fu=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,s;n[0]===e?(r=n[1],i=n[2],a=n[3],s=n[4]):({className:i,inset:a,children:r,...s}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=s);let c;n[5]!==i||n[6]!==a?(c=U(U(J.body,`flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),a&&`pl-8`,i),n[5]=i,n[6]=a,n[7]=c):c=n[7];let l;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(o,{className:`ml-auto`}),n[8]=l):l=n[8];let u;return n[9]!==r||n[10]!==s||n[11]!==t||n[12]!==c?(u=(0,$.jsxs)(Wr,{ref:t,className:c,...s,children:[r,l]}),n[9]=r,n[10]=s,n[11]=t,n[12]=c,n[13]=u):u=n[13],u});fu.displayName=Wr.displayName;var pu=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=U(`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)(Br,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});pu.displayName=Br.displayName;var mu=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=U(`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)(Tr,{children:(0,$.jsx)(Ur,{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});mu.displayName=Ur.displayName;var hu=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==i?(o=U(U(J.body,`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),i&&`pl-8`,r),n[4]=r,n[5]=i,n[6]=o):o=n[6];let s;return n[7]!==a||n[8]!==t||n[9]!==o?(s=(0,$.jsx)(sr,{ref:t,className:o,...a}),n[7]=a,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});hu.displayName=sr.displayName;var gu=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:a,children:i,checked:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]===a?s=n[6]:(s=U(U(J.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),a),n[5]=a,n[6]=s);let c;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(wr,{children:(0,$.jsx)(tn,{className:`h-4 w-4`})})}),n[7]=c):c=n[7];let l;return n[8]!==r||n[9]!==i||n[10]!==o||n[11]!==t||n[12]!==s?(l=(0,$.jsxs)(cr,{ref:t,className:s,checked:r,...o,children:[c,i]}),n[8]=r,n[9]=i,n[10]=o,n[11]=t,n[12]=s,n[13]=l):l=n[13],l});gu.displayName=cr.displayName;var _u=Y.forwardRef((e,t)=>{let n=(0,X.c)(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=U(U(J.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),i),n[4]=i,n[5]=o);let s;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(wr,{children:(0,$.jsx)(mn,{className:`h-2 w-2 fill-current`})})}),n[6]=s):s=n[6];let c;return n[7]!==r||n[8]!==a||n[9]!==t||n[10]!==o?(c=(0,$.jsxs)(gr,{ref:t,className:o,...a,children:[s,r]}),n[7]=r,n[8]=a,n[9]=t,n[10]=o,n[11]=c):c=n[11],c});_u.displayName=gr.displayName;var vu=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=U(J.body,`px-2 py-1.5 font-semibold`,o,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==a||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(Cr,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});vu.displayName=Cr.displayName;var yu=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=U(`-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)(jr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});yu.displayName=jr.displayName;var bu=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=U(J.compact,`ml-auto tracking-widest opacity-60`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`span`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};bu.displayName=`DropdownMenuShortcut`;var xu=ri(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`]}),Su=ri(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`]}),Cu=function(e){let t=(0,X.c)(41),{icon:n,promptTitle:r,skippedTitle:i,detail:a,wildcardOptions:o,secondaryButtonLabel:s,resolvedDecision:c,onAllowOnce:l,onAllowWildcard:u,onSecondary:d}=e,[f,p]=(0,Y.useState)(!!c),[m,h]=(0,Y.useState)(c??null),[g,_]=(0,Y.useState)(!1),v,y;t[0]===c?(v=t[1],y=t[2]):(v=()=>{c&&(p(!0),h(c),_(!1))},y=[c],t[0]=c,t[1]=v,t[2]=y),(0,Y.useEffect)(v,y);let b;t[3]!==g||t[4]!==l||t[5]!==f?(b=async function(){if(!(g||f)){_(!0);try{await l(),p(!0),h(`allowed`)}catch(e){console.error(`Failed to submit permission response:`,e),_(!1)}}},t[3]=g,t[4]=l,t[5]=f,t[6]=b):b=t[6];let x=b,S;t[7]!==g||t[8]!==u||t[9]!==f?(S=async function(e){if(!(g||f)){_(!0);try{await u(e),p(!0),h(`allowed`)}catch(e){console.error(`Failed to submit permission response:`,e),_(!1)}}},t[7]=g,t[8]=u,t[9]=f,t[10]=S):S=t[10];let C=S,w;t[11]!==g||t[12]!==d||t[13]!==f?(w=async function(){if(!(g||f)){_(!0);try{await d(),p(!0),h(`skipped`)}catch(e){console.error(`Failed to submit permission response:`,e),_(!1)}}},t[11]=g,t[12]=d,t[13]=f,t[14]=w):w=t[14];let T=w;if(f&&m!==`skipped`)return null;if(f){let e;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(tn,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),t[15]=e):e=t[15];let n;return t[16]!==a||t[17]!==i?(n=(0,$.jsx)(xu,{v0:e,v1:J.label,v2:i,v3:a,v4:J.bodyMuted}),t[16]=a,t[17]=i,t[18]=n):n=t[18],n}let E;t[19]===x?E=t[20]:(E=()=>void x(),t[19]=x,t[20]=E);let D;t[21]!==g||t[22]!==E?(D=(0,$.jsx)(V,{type:`button`,size:`sm`,disabled:g,onClick:E,className:`rounded-r-none`,children:`Allow`}),t[21]=g,t[22]=E,t[23]=D):D=t[23];let O;t[24]!==C||t[25]!==g||t[26]!==o?(O=o.length>0&&(0,$.jsxs)(lu,{children:[(0,$.jsx)(uu,{asChild:!0,children:(0,$.jsx)(V,{type:`button`,size:`sm`,disabled:g,className:U(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(On,{className:`h-4 w-4`})})}),(0,$.jsx)(mu,{align:`end`,className:`max-w-md`,children:o.map(e=>(0,$.jsx)(hu,{onClick:()=>void C(e),children:e.label},`${e.scope}-${e.pattern}`))})]}),t[24]=C,t[25]=g,t[26]=o,t[27]=O):O=t[27];let k;t[28]===T?k=t[29]:(k=()=>void T(),t[28]=T,t[29]=k);let A;t[30]!==g||t[31]!==s||t[32]!==k?(A=(0,$.jsx)(V,{type:`button`,size:`sm`,variant:`outline`,disabled:g,onClick:k,children:s}),t[30]=g,t[31]=s,t[32]=k,t[33]=A):A=t[33];let j;return t[34]!==a||t[35]!==n||t[36]!==r||t[37]!==A||t[38]!==D||t[39]!==O?(j=(0,$.jsx)(Su,{v0:n,v1:J.label,v2:r,v3:a,v4:D,v5:O,v6:A}),t[34]=a,t[35]=n,t[36]=r,t[37]=A,t[38]=D,t[39]=O,t[40]=j):j=t[40],j};function wu(e){let t=(0,X.c)(3),{command:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=U(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`code`,{className:r,children:n}),t[1]=n,t[2]=i),i}function Tu(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)(Jn,{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)(wu,{command:r}),t[1]=r,t[2]=c);let l,u;t[3]!==i||t[4]!==n?(l=()=>ue(n,`allow_once`,{projectId:i??void 0}),u=e=>ue(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=()=>ue(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)(Cu,{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 Eu(e){let t=(0,X.c)(9),{hostname:n,url:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=U(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=(0,$.jsx)(`code`,{className:i,children:n}),t[1]=n,t[2]=a);let o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=U(J.caption,J.bodyMuted,`mt-1 break-all`),t[3]=o):o=t[3];let s;t[4]===r?s=t[5]:(s=(0,$.jsx)(`div`,{className:o,children:r}),t[4]=r,t[5]=s);let c;return t[6]!==a||t[7]!==s?(c=(0,$.jsxs)($.Fragment,{children:[a,s]}),t[6]=a,t[7]=s,t[8]=c):c=t[8],c}function Du(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)(v,{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)(Eu,{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=()=>H(n,`allow_once`),u=e=>H(n,e.scope===`project`?`allow_domain_project`:`allow_domain_session`),d=()=>H(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)(Cu,{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 Ou=new Map,ku=new Map;function Au(e){return Ou.get(e)}function ju(e,t){let n=ku.get(e);return n||(n=new Set,ku.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ku.delete(e)}}function Mu(e){let t=ku.get(e);if(t)for(let e of t)e()}function Nu(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(Ou.has(e))return;Ou.set(e,{status:`running`}),Mu(e);let r=We();(async()=>{try{let i=Nu(r,n),a=Object.getPrototypeOf(async function(){}).constructor,o=await new a(`callTool`,t)(i),s=o===void 0?null:o;Ou.set(e,{status:`success`,result:s}),Mu(e),await Pt(e,s)}catch(t){let n=t instanceof Error?t.stack||t.message:String(t);Ou.set(e,{status:`error`,error:n}),Mu(e);try{await Pt(e,{error:n})}catch(e){console.error(`[browser-js-executor] failed to submit error result`,e)}}})()}var Fu=ri(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`]}),Iu=ri(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`]}),Lu=ri(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`]}),Ru=function(e){let t=(0,X.c)(41),{toolCallId:n,intention:r,code:i}=e,a=Q(zu),s;t[0]===n?s=t[1]:(s=Au(n),t[0]=n,t[1]=s);let c=s,[l,u]=(0,Y.useState)(c?.status??`running`),d;t[2]===c?d=t[3]:(d=()=>{if(!c||c.status!==`success`)return null;let e=c.result;return e==null?null:typeof e==`string`?e:JSON.stringify(e,null,2)},t[2]=c,t[3]=d);let[f,p]=(0,Y.useState)(d),[m,h]=(0,Y.useState)(c?.error??null),g,_;t[4]===n?(g=t[5],_=t[6]):(g=()=>ju(n,()=>{let e=Au(n);if(e)if(u(e.status),e.status===`success`){let t=e.result;p(t==null?null:typeof t==`string`?t:JSON.stringify(t,null,2))}else e.status===`error`&&h(e.error??null)}),_=[n],t[4]=n,t[5]=g,t[6]=_),(0,Y.useEffect)(g,_);let v,y;t[7]!==i||t[8]!==a||t[9]!==n?(v=()=>{a&&Pu(n,i,a)},y=[n,i,a],t[7]=i,t[8]=a,t[9]=n,t[10]=v,t[11]=y):(v=t[10],y=t[11]),(0,Y.useEffect)(v,y);let[b,x]=(0,Y.useState)(!1),S;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>x(Bu),t[12]=S):S=t[12];let C=S;if(l===`running`){let e,n;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=U(J.label,`w-full py-2 flex items-center gap-2`),n=(0,$.jsx)(He,{className:`h-4 w-4 shrink-0 text-brand animate-pulse`}),t[13]=e,t[14]=n):(e=t[13],n=t[14]);let i=r||`Executing Browser JS...`,a;return t[15]===i?a=t[16]:(a=(0,$.jsx)(Fu,{v0:e,v1:n,v2:i}),t[15]=i,t[16]=a),a}if(l===`success`){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=U(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),n=(0,$.jsx)(He,{className:`h-4 w-4 shrink-0 text-brand`}),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let a=r||`Browser JS Executed Successfully`,s;t[19]===b?s=t[20]:(s=b?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[19]=b,t[20]=s);let c;t[21]!==i||t[22]!==b||t[23]!==f?(c=b&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:U(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i}),f!=null&&(0,$.jsx)(`pre`,{className:U(J.body,`leading-relaxed whitespace-pre-wrap border-t border-border pt-2`),children:f})]}),t[21]=i,t[22]=b,t[23]=f,t[24]=c):c=t[24];let l;return t[25]!==a||t[26]!==s||t[27]!==c?(l=(0,$.jsx)(Iu,{v0:C,v1:e,v2:n,v3:a,v4:s,v5:c}),t[25]=a,t[26]=s,t[27]=c,t[28]=l):l=t[28],l}let w,T;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(w=U(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),T=(0,$.jsx)(He,{className:`h-4 w-4 shrink-0 text-destructive`}),t[29]=w,t[30]=T):(w=t[29],T=t[30]);let E=r||`Browser JS Execution Failed`,D;t[31]===b?D=t[32]:(D=b?(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(o,{className:`h-4 w-4 shrink-0`}),t[31]=b,t[32]=D);let O;t[33]!==i||t[34]!==m||t[35]!==b?(O=b&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:U(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:m}),(0,$.jsx)(`pre`,{className:U(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i})]}),t[33]=i,t[34]=m,t[35]=b,t[36]=O):O=t[36];let k;return t[37]!==E||t[38]!==D||t[39]!==O?(k=(0,$.jsx)(Lu,{v0:C,v1:w,v2:T,v3:E,v4:D,v5:O}),t[37]=E,t[38]=D,t[39]=O,t[40]=k):k=t[40],k};function zu(e){return e.selectedThreadId}function Bu(e){return!e}function Vu(e){let t=(0,X.c)(69),{toolCall:n,className:r}=e,i=za(),[a,o]=(0,Y.useState)(!1),s;t[0]===n.id?s=t[1]:(s=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=s);let c=Q(s),l=Q(Gu),u=Q(Wu),d;t[2]!==n.activeDisplayName||t[3]!==n.name?(d=n.activeDisplayName??$e(n.name),t[2]=n.activeDisplayName,t[3]=n.name,t[4]=d):d=t[4];let f=d;if(!l)return null;let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{o(Uu)},t[5]=p):p=t[5];let m=p,h;t[6]!==i||t[7]!==u||t[8]!==n.id||t[9]!==n.name?(h=()=>{i({type:Z.StopStream});let e={type:`tool-result`,toolCallId:n.id,toolName:n.name,result:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`,isError:!0,content:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`};i({type:Z.AppendStreamChunk,chunkType:`content`,content:JSON.stringify([e]),segments:u})},t[6]=i,t[7]=u,t[8]=n.id,t[9]=n.name,t[10]=h):h=t[10];let g=h,_=Hu,v=n.name===`bash`&&typeof n.input?.command==`string`?n.input.command:null,y;t[11]===v?y=t[12]:(y=v===null?null:kc(v),t[11]=v,t[12]=y);let b=y,x=n.name===`fetch`&&typeof n.input?.url==`string`?n.input.url:null,S=n.name===`web_search`&&typeof n.input?.query==`string`?n.input.query:null,C=!v&&typeof n.input?.description==`string`?n.input.description:null,w;t[13]===r?w=t[14]:(w=U(`overflow-hidden mb-2`,r),t[13]=r,t[14]=w);let T;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(ul,{}),t[15]=T):T=t[15];let E;t[16]===f?E=t[17]:(E=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[T,(0,$.jsx)(`span`,{className:J.bodyMuted,children:f})]})}),t[16]=f,t[17]=E);let D;t[18]===n.name?D=t[19]:(D=(0,$.jsx)(z,{children:n.name}),t[18]=n.name,t[19]=D);let O;t[20]!==E||t[21]!==D?(O=(0,$.jsxs)(k,{children:[E,D]}),t[20]=E,t[21]=D,t[22]=O):O=t[22];let A;t[23]===b?A=t[24]:(A=b!==null&&(0,$.jsx)(`code`,{className:U(J.mono,J.bodyMuted,`truncate whitespace-nowrap rounded bg-muted/60 px-1 py-0.5 max-w-full`),children:b.label}),t[23]=b,t[24]=A);let j;t[25]===x?j=t[26]:(j=x!==null&&(0,$.jsx)(`code`,{className:U(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:x.length>60?`${x.slice(0,59)}…`:x}),t[25]=x,t[26]=j);let M;t[27]===S?M=t[28]:(M=S!==null&&(0,$.jsx)(`code`,{className:U(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:S.length>60?`${S.slice(0,59)}…`:S}),t[27]=S,t[28]=M);let N;t[29]===C?N=t[30]:(N=C!==null&&(0,$.jsx)(`span`,{className:J.bodyMuted,children:C}),t[29]=C,t[30]=N);let P;t[31]!==v||t[32]!==C||t[33]!==x||t[34]!==S?(P=!v&&!x&&!S&&!C&&(0,$.jsx)(`span`,{className:J.bodyMuted,children:`running`}),t[31]=v,t[32]=C,t[33]=x,t[34]=S,t[35]=P):P=t[35];let F;t[36]===a?F=t[37]:(F=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:m,className:`p-1 hover:bg-muted/50 rounded transition-colors`,children:a?(0,$.jsx)(Se,{className:`h-3 w-3`}):(0,$.jsx)(On,{className:`h-3 w-3`})})}),t[36]=a,t[37]=F);let I=a?`Collapse`:`Expand`,L;t[38]===I?L=t[39]:(L=(0,$.jsx)(z,{children:I}),t[38]=I,t[39]=L);let R;t[40]!==F||t[41]!==L?(R=(0,$.jsxs)(k,{children:[F,L]}),t[40]=F,t[41]=L,t[42]=R):R=t[42];let B;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(zn,{className:`h-3 w-3`}),t[43]=B):B=t[43];let ee;t[44]===g?ee=t[45]:(ee=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:g,className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,children:B})}),t[44]=g,t[45]=ee);let te;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(z,{className:`bg-red-600 text-white border-red-600`,children:`Stop this process`}),t[46]=te):te=t[46];let ne;t[47]===ee?ne=t[48]:(ne=(0,$.jsxs)(k,{children:[ee,te]}),t[47]=ee,t[48]=ne);let re;t[49]!==R||t[50]!==ne?(re=(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[R,ne]}),t[49]=R,t[50]=ne,t[51]=re):re=t[51];let ie;t[52]!==O||t[53]!==A||t[54]!==j||t[55]!==M||t[56]!==N||t[57]!==P||t[58]!==re?(ie=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[O,A,j,M,N,P,re]}),t[52]=O,t[53]=A,t[54]=j,t[55]=M,t[56]=N,t[57]=P,t[58]=re,t[59]=ie):ie=t[59];let ae;t[60]!==a||t[61]!==n.id||t[62]!==n.input||t[63]!==c?(ae=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border min-h-[8rem] overflow-auto`,children:[(0,$.jsxs)(`div`,{className:U(J.compact,J.bodyMuted,`mb-2 font-mono`),children:[`ID: `,n.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:U(J.compact,J.label,`text-muted-foreground mb-1`),children:`Input:`}),(0,$.jsx)(`pre`,{className:tl({className:`border border-border`}),children:_(n.input)})]}),c&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:U(J.compact,J.label,`text-muted-foreground mb-1`),children:`Progress:`}),(0,$.jsxs)(`div`,{className:U(J.body,`bg-green-50 dark:bg-green-900/20 p-2 rounded border border-green-200 dark:border-green-800`),children:[(0,$.jsx)(`div`,{className:U(J.mono,`text-green-700 dark:text-green-300`),children:c.delta}),c.partial?.content?.[0]?.arguments&&typeof c.partial.content[0].arguments==`object`&&`content`in c.partial.content[0].arguments&&typeof c.partial.content[0].arguments.content==`string`&&(0,$.jsxs)(`div`,{className:U(J.mono,`mt-1 text-green-600 dark:text-green-400`),children:[`Building: `,c.partial.content[0].arguments.content.slice(-50),c.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,$.jsxs)(`div`,{className:U(J.compact,`flex items-center gap-1.5 text-muted-foreground`),children:[(0,$.jsx)(ul,{}),`Executing`,c&&` with progress`,`...`]})]}),t[60]=a,t[61]=n.id,t[62]=n.input,t[63]=c,t[64]=ae):ae=t[64];let oe;return t[65]!==ie||t[66]!==ae||t[67]!==w?(oe=(0,$.jsxs)(`div`,{className:w,children:[ie,ae]}),t[65]=ie,t[66]=ae,t[67]=w,t[68]=oe):oe=t[68],oe}function Hu(e){return JSON.stringify(e,null,2)}function Uu(e){return!e}function Wu(e){return e.streamingSegments}function Gu(e){return e.isStreaming}function Ku(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 qu(e){return e.type!==`subagent_event`||!e.subagentEvent?null:Ju(e.subagentEvent)}function Ju(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?Yu(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 Yu(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 Xu(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 Zu(e){return{intention:typeof e.intention==`string`?e.intention:``,code:typeof e.code==`string`?e.code:``}}function Qu(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)(cu,{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 $u(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)(Tu,{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 ed(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)(Du,{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 td(e,t){if(e.name!==`ask_user`)return null;let n=Xu(e.input);return(0,$.jsx)(cu,{toolCallId:e.id,question:n.question,options:n.options,context:n.context,answeredText:t})}function nd(e){if(e.name!==`run_js`&&e.name!==`run_web_worker`)return null;let t=Zu(e.input);return(0,$.jsx)(Ru,{toolCallId:e.id,intention:t.intention,code:t.code})}function rd(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=nu(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`||Ku(n.name,n.input);if(l&&!u){let e;return t[6]===n?e=t[7]:(e=(0,$.jsx)(Vu,{toolCall:n}),t[6]=n,t[7]=e),e}let d=l?c:r,f;return t[8]!==n||t[9]!==l||t[10]!==d?(f=(0,$.jsx)(Vl,{inline:!0,block:n,resultContent:d,isActive:l}),t[8]=n,t[9]=l,t[10]=d,t[11]=f):f=t[11],f}function id(e){let t=(0,X.c)(11),{block:n,showActive:r,resultContent:i}=e,a;t[0]!==n||t[1]!==i?(a=td(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=nd(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)(rd,{block:n,resultContent:i}),t[5]=n,t[6]=i,t[7]=e):e=t[7],e}let l;return t[8]!==n||t[9]!==i?(l=(0,$.jsx)(Vl,{inline:!0,block:n,resultContent:i,isActive:!1}),t[8]=n,t[9]=i,t[10]=l):l=t[10],l}function ad(e){let t=(0,X.c)(3),{block:n,sequence:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(ql,{inline:!0,sequence:r,block:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function od(e){if(Ca(e)){let t=e.text.slice(0,128);return`thinking-${e.label??`none`}-${tu(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??tu(e.prompt.question)}`;case`shell_permission`:return`shell-${e.prompt.toolCallId}`;case`web_fetch_permission`:return`fetch-${e.prompt.toolCallId}`;case`text`:return`text-${tu(e.text.slice(0,128))}`}}function sd(e,t,n){let{lookupBlocks:r,isStreaming:i,threadId:a,projectId:o,messageIndex:s}=n;if(ia(e)&&e.name===`todo`)return null;if(aa(e)){if(e.toolName===`todo`)return(0,$.jsx)(ad,{sequence:s,block:e},t);if(e.toolName===`ask_user`)return null}switch(e.type){case`long_running_confirmation`:return(0,$.jsx)(Qu,{prompt:e.prompt,answeredText:au(r,e.prompt.toolCallId)},t);case`shell_permission`:return(0,$.jsx)($u,{prompt:e.prompt,projectId:o},t);case`web_fetch_permission`:return(0,$.jsx)(ed,{prompt:e.prompt,projectId:o},t);case`text`:return(0,$.jsx)(Fs,{content:e.text,threadId:a},t);case`tool_use`:{let n=ru(r,e.id);return(0,$.jsx)(id,{block:e,showActive:i&&!iu(r,e.id),resultContent:n},t)}case`tool-result`:return(0,$.jsx)(ad,{block:e},t)}}function cd(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=wa(n,s).map(e=>{let t=od(e);return Ca(e)?(0,$.jsx)(Zl,{text:e.text,label:e.label,isStreaming:e.isCurrentlyStreaming,threadId:i},t):sd(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 ld=ri(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`]}),ud=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:ma(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?sa(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=U(`group px-4 py-4`,m),t[6]=m,t[7]=h);let g=l&&`items-end`,_;t[8]===g?_=t[9]:(_=U(`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)(lc,{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=U(`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)(dd,{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)(uc,{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)(Bs,{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)(ld,{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 dd(e){let t=(0,X.c)(14),{message:n,threadId:r,messageIndex:i,structuredContent:a,thinkingBlocks:o}=e;if(n.isThinking){if(o?.length){let e;return t[0]!==o||t[1]!==r?(e=(0,$.jsx)(cd,{blocks:o,threadId:r}),t[0]=o,t[1]=r,t[2]=e):e=t[2],e}let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=U(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),t[3]=e):e=t[3];let i;return t[4]!==n.content||t[5]!==r?(i=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(Fs,{content:n.content,threadId:r})}),t[4]=n.content,t[5]=r,t[6]=i):i=t[6],i}if(a){let e;return t[7]!==i||t[8]!==a||t[9]!==r?(e=(0,$.jsx)(cd,{blocks:a,threadId:r,messageIndex:i}),t[7]=i,t[8]=a,t[9]=r,t[10]=e):e=t[10],e}let s;return t[11]!==n.content||t[12]!==r?(s=(0,$.jsx)(Fs,{content:n.content,threadId:r,className:J.body}),t[11]=n.content,t[12]=r,t[13]=s):s=t[13],s}function fd(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`?sa(a)??[]:ma(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 pd=ri(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`]}),md=function(e){let t=(0,X.c)(16),{segments:n,model:r,threadId:i,projectId:a,isCreatingProject:o,isProcessingThread:s,totalMessages:c,showProcessingLine:l}=e,u=c===void 0?0:c,d=l===void 0?!1:l,f=fd(n),p=d?`pb-0`:`pb-4`,m;t[0]===p?m=t[1]:(m=U(`group px-4 pt-4`,p),t[0]=p,t[1]=m);let h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=U(J.compact,`font-medium text-foreground`),t[2]=h):h=t[2];let g;t[3]===r?g=t[4]:(g=r&&(0,$.jsxs)(`span`,{className:U(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(He,{className:`h-2.5 w-2.5`}),vi(r)]}),t[3]=r,t[4]=g);let _;t[5]!==o||t[6]!==s||t[7]!==f||t[8]!==a||t[9]!==i||t[10]!==u?(_=f.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 min-w-0 text-base`,children:(0,$.jsx)(cd,{blocks:f,isStreaming:!0,threadId:i,projectId:a,messageIndex:u})}):o||s?(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(Zl,{isStreaming:!0})}):null,t[5]=o,t[6]=s,t[7]=f,t[8]=a,t[9]=i,t[10]=u,t[11]=_):_=t[11];let v;return t[12]!==m||t[13]!==g||t[14]!==_?(v=(0,$.jsx)(pd,{v0:m,v1:h,v2:g,v3:_}),t[12]=m,t[13]=g,t[14]=_,t[15]=v):v=t[15],v},hd=3e3;function gd(e){let t=[...ut],n=e?t.filter(t=>t!==e):t;return n[Math.floor(Math.random()*n.length)]}function _d(e){let t=(0,X.c)(3),[n,r]=(0,Y.useState)(Sn),i=(0,Y.useRef)(Sn),a,o;return t[0]===e?(a=t[1],o=t[2]):(a=()=>{if(!e){r(Sn),i.current=Sn;return}let t=setInterval(()=>{let e=i.current===`Processing...`?gd():gd(i.current);i.current=e,r(e)},hd);return()=>clearInterval(t)},o=[e],t[0]=e,t[1]=a,t[2]=o),(0,Y.useEffect)(a,o),n}function vd(e){let t=(0,X.c)(8),{active:n,className:r}=e,i=n===void 0?!0:n,a=_d(i),o=i?`animate-shimmer`:void 0,s;t[0]===o?s=t[1]:(s=U(J.caption,o),t[0]=o,t[1]=s);let c;t[2]!==a||t[3]!==s?(c=(0,$.jsx)(`span`,{className:s,children:a}),t[2]=a,t[3]=s,t[4]=c):c=t[4];let l;return t[5]!==r||t[6]!==c?(l=(0,$.jsx)(`div`,{className:r,"aria-live":`polite`,"aria-busy":`true`,children:c}),t[5]=r,t[6]=c,t[7]=l):l=t[7],l}var yd=ri(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`]}),bd=function(e){let t=(0,X.c)(17),{projects:n,onSelectProject:r,onCreateThread:i,onConnectRepo:a,onNewApp:o,onOpenFolder:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=U(J.pageTitle,`tracking-tight text-balance`),t[0]=c):c=t[0];let l=n.length===0?`Start or connect your first project`:`Select a project to start coding`,u;if(t[1]!==i||t[2]!==r||t[3]!==n){let e;t[5]!==i||t[6]!==r?(e=e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:()=>{e.threads.length===0?i(e.projectId):r(e.projectId,e.threads[0].threadId)},children:[(0,$.jsx)(Ft,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`${J.body} text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:J.caption,children:[e.threads.length,` thread`,e.threads.length===1?``:`s`]})]},e.projectId),t[5]=i,t[6]=r,t[7]=e):e=t[7],u=n.map(e),t[1]=i,t[2]=r,t[3]=n,t[4]=u}else u=t[4];let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(he,{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)(q,{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)(d,{className:`h-5 w-5 text-muted-foreground`}),t[10]=m):m=t[10];let h;return t[11]!==a||t[12]!==o||t[13]!==s||t[14]!==l||t[15]!==u?(h=(0,$.jsx)(yd,{v0:c,v1:`mt-1 ${J.pageSubtitle}`,v2:l,v3:u,v4:a,v5:f,v6:`${J.body} text-foreground leading-snug font-medium`,v7:J.caption,v8:o,v9:p,v10:`${J.body} text-foreground leading-snug font-medium`,v11:J.caption,v12:s,v13:m,v14:`${J.body} text-foreground leading-snug font-medium`,v15:J.caption}),t[11]=a,t[12]=o,t[13]=s,t[14]=l,t[15]=u,t[16]=h):h=t[16],h},xd=(0,Y.createContext)(null);function Sd(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)(xd.Provider,{value:u,children:n}),t[4]=n,t[5]=u,t[6]=d):d=t[6],d}function Cd(){let e=(0,Y.useContext)(xd);if(!e)throw Error(`useDevServer must be used within a DevServerProvider`);return e}function wd(e){e.onTerminalMessage?.(`✓ Server running at: ${e.url}`),e.setDevServerUrl(e.url),e.setActiveMainTab(`browser`)}function Td(e){return typeof e==`object`&&!!e&&e.type===`url`&&typeof e.url==`string`}function Ed(){let e=Q(e=>e.selectedThreadId),{dispatch:t}=Ba(e),{setActiveMainTab:n}=hc(),{setDevServerUrl:r,setDevServerRunning:i,setDevServerLoading:a}=Cd();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 w(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)),Td(e)&&e.url&&(clearTimeout(c),wd({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 Dd=3e4,Od=2e3;function kd(e){let{devServerRunning:t,setDevServerRunning:n,devServerLoading:r}=Cd(),i=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{e&&(i.current=!1,(async()=>{try{n((await vn(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>Dd){clearInterval(i);return}vn(e).then(e=>{e.isRunning&&(n(!0),clearInterval(i))}).catch(()=>{})},Od);return()=>clearInterval(i)},[e,r,n]),{isRunning:t,isLoading:r,recheck:(0,Y.useCallback)(async()=>{if(e)try{n((await vn(e)).isRunning)}catch{n(!1)}},[e,n])}}var Ad=ri(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`]}),jd=function(e){let t=(0,X.c)(14),{project:n}=e,{isRunning:r}=kd(n?.projectId),{startServer:i}=Ed();n?.name;let a=n?.name??`your project`,o;t[0]===a?o=t[1]:(o=Md(a),t[0]=a,t[1]=o);let s=o,c=!r&&n?.runCommand,l;t[2]!==n||t[3]!==i?(l=()=>{n&&i(n)},t[2]=n,t[3]=i,t[4]=l):l=t[4];let u=l,d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=U(J.pageTitle,`tracking-tight text-foreground text-balance`),t[5]=d):d=t[5];let f=n?.name??`Project`,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(p=U(J.pageSubtitle,`mt-2`),t[6]=p):p=t[6];let m;t[7]!==u||t[8]!==c?(m=c&&(0,$.jsx)(`button`,{type:`button`,onClick:u,className:U(J.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground hover:bg-primary/90 transition-colors`),children:`Start App`}),t[7]=u,t[8]=c,t[9]=m):m=t[9];let h;return t[10]!==s||t[11]!==f||t[12]!==m?(h=(0,$.jsx)(Ad,{v0:d,v1:f,v2:p,v3:s,v4:m}),t[10]=s,t[11]=f,t[12]=m,t[13]=h):h=t[13],h};function Md(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 Nd({virtuosoRef:e,selectedThreadId:t,messagesLoaded:n,messageCount:r,isStreaming:i,hasPendingMessage:a,streamingSegmentCount:o}){let s=(0,Y.useRef)(0),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(!1),u=(0,Y.useRef)(!1),d=(0,Y.useRef)(0),f=(0,Y.useRef)(null),p=(0,Y.useCallback)(()=>{t&&e.current?.getState(e=>{It(t,e.scrollTop)})},[t,e]),m=(0,Y.useRef)(p);m.current=p;function h(){u.current&&m.current()}(0,Y.useEffect)(()=>{function e(){h()}return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e)}},[t]),(0,Y.useEffect)(()=>{let e=setInterval(()=>{h()},5e3);return()=>clearInterval(e)},[t]),(0,Y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),(0,Y.useEffect)(()=>{l.current=!1,u.current=!1,s.current=0},[t]),(0,Y.useEffect)(()=>{if(!t||!n||r===0||l.current)return;l.current=!0,s.current=r;let i=Un(t);if(i!==null&&i>0){requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.current?.scrollTo({top:i,behavior:`auto`}),u.current=!0})});return}u.current=!0},[t,n,r,e]),(0,Y.useEffect)(()=>{if(!l.current)return;let t=r>s.current,n=c.current&&!i;if(i||a||t||n){d.current&&cancelAnimationFrame(d.current);let t=n?`smooth`:`auto`;d.current=requestAnimationFrame(()=>{e.current?.scrollTo({top:2**53-1,behavior:t}),d.current=0})}return s.current=r,c.current=i,()=>{d.current&&=(cancelAnimationFrame(d.current),0)}},[i,a,r,o,e]);function g(){f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{h(),f.current=null},150)}function _(e){e||h()}return{onRangeChanged:g,onScrollingStateChange:_}}var Pd=(0,Y.createContext)(void 0);function Fd(e){let t=(0,X.c)(12),{paneId:n,conversationId:r,fillPane:i,children:a}=e,o=i===void 0?!1:i,s=za(),c=Q(Id),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 Id(e){return e.focusedPane}function Ld(){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:Rd},e[0]=t):t=e[0],t}return t}function Rd(){}var zd=`md:mr-4`;function Bd(e){return e?`w-full min-w-0 px-4`:`mx-auto max-w-3xl w-full min-w-0`}function Vd(e,t){return e?U(`relative w-full min-w-0 pl-4`,zd):U(`relative mx-auto max-w-3xl`,t?`w-full min-w-0`:`w-[90vw] min-w-[400px]`)}function Hd(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`:U(`relative mx-auto w-full max-w-3xl max-md:px-0 pb-2 md:pl-4 md:pb-4 md:-ml-[6px]`,zd)}function Ud(e){return e.isCreatingProject||e.streamingSegmentCount>0?!0:e.lastMessageSender===`user`}function Wd(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 Gd(e){return{bottomInset:e.bottomInset,columnClassName:e.columnClassName,isStreaming:e.isStreaming,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread,hasPendingMessage:e.hasPendingMessage,hasActiveBlockingPrompt:Da(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=>Wd({isUser:t.sender===`user`,hasCheckpointRef:!!t.checkpointRef,isStreaming:e.isStreaming,hasPendingMessage:e.hasPendingMessage,isCreatingProject:e.isCreatingProject,isProcessingThread:e.isProcessingThread})}}function Kd(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 qd(e){let t=(0,X.c)(28),{context:n}=e;if(!n)return null;let{bottomInset:r,isStreaming:i,isCreatingProject:a,isProcessingThread:o,hasPendingMessage:s,hasActiveBlockingPrompt:c,selectedProjectId:l,selectedThreadId:u,streamingSegments:d,streamingModel:f,totalMessages:p,lastMessageSender:m,error:h,onClearError:g}=n,_=d.length>0||a||o&&(i||s),v;t[0]!==a||t[1]!==m||t[2]!==d.length?(v=Ud({isCreatingProject:a,streamingSegmentCount:d.length,lastMessageSender:m}),t[0]=a,t[1]=m,t[2]=d.length,t[3]=v):v=t[3];let y=v,b=_&&(i||a||o)&&y,x=(i||s)&&!c&&y,S;t[4]===r?S=t[5]:(S={paddingBottom:r},t[4]=r,t[5]=S);let C;t[6]!==a||t[7]!==o||t[8]!==l||t[9]!==u||t[10]!==b||t[11]!==x||t[12]!==f||t[13]!==d||t[14]!==p?(C=b&&(0,$.jsx)(md,{segments:d,model:f,threadId:u,projectId:l,isCreatingProject:a,isProcessingThread:o,totalMessages:p,showProcessingLine:x}),t[6]=a,t[7]=o,t[8]=l,t[9]=u,t[10]=b,t[11]=x,t[12]=f,t[13]=d,t[14]=p,t[15]=C):C=t[15];let w;t[16]!==b||t[17]!==x?(w=x&&(0,$.jsx)(`div`,{className:U(`px-4 pb-4`,b?`pt-0`:`pt-2`),children:(0,$.jsx)(vd,{active:x})}),t[16]=b,t[17]=x,t[18]=w):w=t[18];let T;t[19]!==h||t[20]!==g?(T=h&&(0,$.jsxs)(`div`,{className:`mx-4 my-2`,children:[(0,$.jsx)(mi,{variant:`error`,className:`mb-0`,children:h}),(0,$.jsx)(`button`,{type:`button`,className:U(J.compact,`mt-1 text-destructive underline underline-offset-2 hover:text-destructive/80`),onClick:g,children:`Dismiss`})]}),t[19]=h,t[20]=g,t[21]=T):T=t[21];let E;return t[22]!==n.columnClassName||t[23]!==S||t[24]!==C||t[25]!==w||t[26]!==T?(E=(0,$.jsxs)(`div`,{className:n.columnClassName,style:S,children:[C,w,T]}),t[22]=n.columnClassName,t[23]=S,t[24]=C,t[25]=w,t[26]=T,t[27]=E):E=t[27],E}function Jd(e,t,n){return(0,$.jsx)(ud,{message:t,threadId:n.selectedThreadId,messageIndex:e,showCheckpointRestore:n.showCheckpointRestore(t),checkpointRestoreTooltip:n.getCheckpointTooltip(t)})}var Yd=(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}=Ld(),O;n[0]===D?O=n[1]:(O=Bd(D),n[0]=D,n[1]=O);let k=O,A=(0,Y.useRef)(null),j;n[2]===k?j=n[3]:(j=Kd(k),n[2]=k,n[3]=j);let M;n[4]===j?M=n[5]:(M={List:j,Footer:qd},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}=Nd(F),R=!E&&i.length===0&&!a&&!c&&!d,z=!E&&h&&i.length===0&&!a&&!c&&!l&&!u&&d,B;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),B=p.find(e),n[14]=p,n[15]=f,n[16]=B}else B=n[16];let ee=B,te=i.length>0?i[i.length-1].sender:null,ne;n[19]!==T||n[20]!==k||n[21]!==x||n[22]!==u||n[23]!==c||n[24]!==l||n[25]!==a||n[26]!==te||n[27]!==i.length||n[28]!==S||n[29]!==f||n[30]!==d||n[31]!==s||n[32]!==o?(ne=Gd({bottomInset:T,columnClassName:k,isStreaming:a,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,streamingSegments:o,selectedProjectId:f,selectedThreadId:d,streamingModel:s,totalMessages:i.length,lastMessageSender:te,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]=te,n[27]=i.length,n[28]=S,n[29]=f,n[30]=d,n[31]=s,n[32]=o,n[33]=ne):ne=n[33];let re=ne;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)(bd,{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(z){let e;return n[44]===ee?e=n[45]:(e=(0,$.jsx)(jd,{project:ee}),n[44]=ee,n[45]=e),e}let ie;n[46]===Symbol.for(`react.memo_cache_sentinel`)?(ie=U(`h-full overflow-hidden`),n[46]=ie):ie=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]!==re?(se=(0,$.jsx)(`div`,{className:ie,children:(0,$.jsx)(Rr,{ref:A,style:oe,data:i,computeItemKey:Xd,context:re,itemContent:Jd,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]=re,n[55]=se):se=n[55],se});function Xd(e,t){return t.messageId}var Zd={onboarding:{status:()=>[`onboarding`,`status`]},app:{update:()=>[`app`,`update`]},models:{enabled:e=>[`models`,`enabled`,e]},userTasks:e=>[`user-tasks`,e]};function Qd(e){let t=(0,X.c)(10),r;t[0]===e?r=t[1]:(r=Zd.models.enabled(e),t[0]=e,t[1]=r);let i;t[2]===r?i=t[3]:(i={queryKey:r,queryFn:n,placeholderData:Xr},t[2]=r,t[3]=i);let a=qr(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 $d(e,t){return t===`secondary`?`${e}:secondary`:e}function ef(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=za(),{paneId:a}=Ld(),o=Q(df),s=Q(uf),c=Q(lf),l=Q(cf),u=Q(sf),d=Q(of),f=Q(af),p=Q(rf),{models:m,isFetched:h}=Qd(d),g;t[2]!==u||t[3]!==r||t[4]!==a||t[5]!==o?(g=()=>{if(o){let e=$d(o,a);if(u[e])return u[e]}return r??``},t[2]=u,t[3]=r,t[4]=a,t[5]=o,t[6]=g):g=t[6];let[_,v]=(0,Y.useState)(g),[y,b]=(0,Y.useState)(-1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)(0),T=(0,Y.useRef)(_),E,D;t[7]===_?(E=t[8],D=t[9]):(E=()=>{T.current=_},D=[_],t[7]=_,t[8]=E,t[9]=D),(0,Y.useEffect)(E,D);let O=(0,Y.useRef)(u),k,j;t[10]===u?(k=t[11],j=t[12]):(k=()=>{O.current=u},j=[u],t[10]=u,t[11]=k,t[12]=j),(0,Y.useEffect)(k,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[z,B]=(0,Y.useState)(R),ee=(0,Y.useRef)(z?.id??``),te=(0,Y.useRef)(z?.provider??``),ne=(0,Y.useRef)(null),[re,ie]=(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,le]=(0,Y.useState)(se),[V,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,_e]=(0,Y.useState)(null),ve;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(ve=[],t[21]=ve):ve=t[21];let[be,xe]=(0,Y.useState)(ve),[Se,Ce]=(0,Y.useState)(!1),[we,Te]=(0,Y.useState)(``),[Ee,De]=(0,Y.useState)(0),Oe;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=[],t[22]=Oe):Oe=t[22];let[ke,Ae]=(0,Y.useState)(Oe),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),[He,Ue]=(0,Y.useState)(``),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=(0,Y.useRef)(null),Xe;t[25]!==z?.id||t[26]!==z?.provider?(Xe=()=>{ee.current=z?.id??``,te.current=z?.provider??``},t[25]=z?.id,t[26]=z?.provider,t[27]=Xe):Xe=t[27];let Ze=z?.id,Qe=z?.provider,$e;t[28]!==Ze||t[29]!==Qe?($e=[Ze,Qe],t[28]=Ze,t[29]=Qe,t[30]=$e):$e=t[30],(0,Y.useEffect)(Xe,$e);let et;t[31]!==i||t[32]!==o?(et=(e,t)=>{B(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}`;ne.current!==r&&(ne.current=r,console.log(`[useChatInputState] Persisting model to thread:`,{threadId:n,model:{id:e.id,provider:e.provider}}),Ve(n,{model:e.id,modelProvider:e.provider}).then(()=>{ne.current===r&&(ne.current=null),console.log(`[useChatInputState] Model persisted successfully`)}).catch(e=>{ne.current===r&&(ne.current=null),console.error(`Failed to save model to thread:`,e)}))},t[31]=i,t[32]=o,t[33]=et):et=t[33];let tt=et,nt,rt;t[34]!==m||t[35]!==h||t[36]!==l||t[37]!==c||t[38]!==tt||t[39]!==s||t[40]!==o?(nt=()=>{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([]),B(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=ee.current===u.id&&te.current===u.provider;if(!m.some(e=>e.id===ee.current&&e.provider===te.current)&&ee.current){tt(a,{persist:!0});return}f||tt(u,{persist:d})},rt=[o,s,c,l,m,h,tt],t[34]=m,t[35]=h,t[36]=l,t[37]=c,t[38]=tt,t[39]=s,t[40]=o,t[41]=nt,t[42]=rt):(nt=t[41],rt=t[42]),(0,Y.useEffect)(nt,rt);let it,at;t[43]!==he.length||t[44]!==H?(it=()=>{!H||he.length>0||(async()=>{try{let e=await ye(),t=Object.values(e).flat();t.length>0&&(ge(t),_e(e=>e??t[0]))}catch(e){console.error(`Failed to load image models:`,e)}})()},at=[H,he.length],t[43]=he.length,t[44]=H,t[45]=it,t[46]=at):(it=t[45],at=t[46]),(0,Y.useEffect)(it,at);let[ot,st]=(0,Y.useState)(o),ct,W;t[47]!==i||t[48]!==a||t[49]!==ot||t[50]!==o?(ct=()=>{if(o!==ot){ot&&T.current.trim()&&O.current[$d(ot,a)]!==T.current&&i({type:Z.SetChatInputDraft,threadId:$d(ot,a),draft:T.current});let e=!1;return queueMicrotask(()=>{e||!M.current||(st(o),v(o?O.current[$d(o,a)]??``:``),xe([]),Ce(!1),Ae([]),Ne([]),Ie([]),Re(!1),Be(!1),ue(!1),pe(!1),fe(!1))}),()=>{e=!0}}},W=[o,ot,a,i],t[47]=i,t[48]=a,t[49]=ot,t[50]=o,t[51]=ct,t[52]=W):(ct=t[51],W=t[52]),(0,Y.useEffect)(ct,W);let lt,ut;t[53]===o?(lt=t[54],ut=t[55]):(lt=()=>{o&&A(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(nf)},ut=[o],t[53]=o,t[54]=lt,t[55]=ut),(0,Y.useEffect)(lt,ut);let dt=(0,Y.useRef)(!1),ft,pt;t[56]!==o||t[57]!==ze?(ft=()=>{ze&&!dt.current&&o&&A(o).then(e=>{let{commands:t,skills:n,bundledSkills:r}=e;Ae(t),Ne(n),Ie(r)}).catch(tf),dt.current=ze},pt=[ze,o],t[56]=o,t[57]=ze,t[58]=ft,t[59]=pt):(ft=t[58],pt=t[59]),(0,Y.useEffect)(ft,pt);let mt;t[60]!==u||t[61]!==a||t[62]!==o?(mt=o?u[$d(o,a)]??``:``,t[60]=u,t[61]=a,t[62]=o,t[63]=mt):mt=t[63];let ht=mt,gt;t[64]!==o||t[65]!==ht?(gt=()=>{o&&v(ht)},t[64]=o,t[65]=ht,t[66]=gt):gt=t[66];let _t;t[67]!==a||t[68]!==o||t[69]!==ht?(_t=[o,ht,a],t[67]=a,t[68]=o,t[69]=ht,t[70]=_t):_t=t[70],(0,Y.useEffect)(gt,_t);let vt;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(vt=()=>{let e=Ge.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]=vt):vt=t[71];let yt;t[72]===_?yt=t[73]:(yt=[_],t[72]=_,t[73]=yt),(0,Y.useLayoutEffect)(vt,yt);let bt,xt;t[74]!==i||t[75]!==f||t[76]!==p||t[77]!==o?(bt=()=>{f&&o&&!p&&(Ge.current?.focus(),i({type:Z.ClearFocusChatInput}))},xt=[f,o,p,i],t[74]=i,t[75]=f,t[76]=p,t[77]=o,t[78]=bt,t[79]=xt):(bt=t[78],xt=t[79]),(0,Y.useEffect)(bt,xt);let St,Ct;t[80]!==i||t[81]!==a||t[82]!==o?(St=()=>{let e=o,t=e?$d(e,a):null;return()=>{t&&T.current.trim()&&O.current[t]!==T.current&&i({type:Z.SetChatInputDraft,threadId:t,draft:T.current})}},Ct=[o,a,i],t[80]=i,t[81]=a,t[82]=o,t[83]=St,t[84]=Ct):(St=t[83],Ct=t[84]),(0,Y.useEffect)(St,Ct);let wt,Tt;t[85]!==re||t[86]!==ae?(wt=()=>{let e=e=>{Ke.current&&!Ke.current.contains(e.target)&&ie(!1),qe.current&&!qe.current.contains(e.target)&&oe(!1)};if(re||ae)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},Tt=[re,ae],t[85]=re,t[86]=ae,t[87]=wt,t[88]=Tt):(wt=t[87],Tt=t[88]),(0,Y.useEffect)(wt,Tt);let Et;return t[89]!==be||t[90]!==ce||t[91]!==he||t[92]!==I||t[93]!==Le||t[94]!==Fe||t[95]!==He||t[96]!==C||t[97]!==i||t[98]!==x||t[99]!==y||t[100]!==H||t[101]!==_||t[102]!==V||t[103]!==de||t[104]!==tt||t[105]!==U||t[106]!==Ee||t[107]!==z||t[108]!==o||t[109]!==ze||t[110]!==re||t[111]!==ae||t[112]!==Se||t[113]!==Me||t[114]!==ke||t[115]!==we?(Et={message:_,setMessage:v,historyIndex:y,setHistoryIndex:b,draftMessage:x,setDraftMessage:S,cursorPosition:C,setCursorPosition:w,availableModels:I,setAvailableModels:L,selectedModel:z,setSelectedModel:tt,selectedModelIdRef:ee,showModelMenu:re,setShowModelMenu:ie,showPlusMenu:ae,setShowPlusMenu:oe,attachments:ce,setAttachments:le,planMode:V,setPlanMode:ue,ralphMode:de,setRalphMode:fe,imageMode:H,setImageMode:pe,availableImageModels:he,setAvailableImageModels:ge,selectedImageModel:U,setSelectedImageModel:_e,allFiles:be,setAllFiles:xe,showSuggestions:Se,setShowSuggestions:Ce,suggestionQuery:we,setSuggestionQuery:Te,selectedIndex:Ee,setSelectedIndex:De,slashCommands:ke,setSlashCommands:Ae,skills:Me,setSkills:Ne,bundledSkills:Fe,setBundledSkills:Ie,bundledSkillMode:Le,setBundledSkillMode:Re,showCommandSuggestions:ze,setShowCommandSuggestions:Be,commandQuery:He,setCommandQuery:Ue,fileInputRef:We,textareaRef:Ge,modelMenuRef:Ke,plusMenuRef:qe,suggestionsRef:Je,commandSuggestionsRef:Ye,selectedThreadId:o,dispatch:i},t[89]=be,t[90]=ce,t[91]=he,t[92]=I,t[93]=Le,t[94]=Fe,t[95]=He,t[96]=C,t[97]=i,t[98]=x,t[99]=y,t[100]=H,t[101]=_,t[102]=V,t[103]=de,t[104]=tt,t[105]=U,t[106]=Ee,t[107]=z,t[108]=o,t[109]=ze,t[110]=re,t[111]=ae,t[112]=Se,t[113]=Me,t[114]=ke,t[115]=we,t[116]=Et):Et=t[116],Et}function tf(e){return console.error(`Failed to refresh slash commands and skills:`,e)}function nf(e){return console.error(`Failed to load slash commands and skills:`,e)}function rf(e){return e.isStreaming}function af(e){return e.focusChatInput}function of(e){return e.configUpdatedAt}function sf(e){return e.chatInputDrafts}function cf(e){return e.projectModelSelections}function lf(e){return e.projects}function uf(e){return e.selectedProjectId}function df(e){return e.selectedThreadId}var ff=e=>{Mn(e)};function pf(e,t){return t===`secondary`?`${e}:secondary`:e}function mf(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:z,planMode:B,setPlanMode:ee,ralphMode:te,setRalphMode:ne,imageMode:re,setImageMode:ie,selectedImageModel:ae,hasConversationMessages:oe}=e,{paneId:se}=Ld(),ce;t[0]!==o||t[1]!==m||t[2]!==re||t[3]!==d||t[4]!==l||t[5]!==n||t[6]!==a||t[7]!==c||t[8]!==se||t[9]!==B||t[10]!==te||t[11]!==p||t[12]!==ae||t[13]!==s||t[14]!==u||t[15]!==z||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=re?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:B,imageMode:re,ralphMode:te}}):c(n,e.id,o,e.provider,B,re,te);let t=n,h=i.find(e=>e.content===t);ff(n),r(``),z([]),h&&a?.(h),g(-1),v(``),u&&m({type:Z.ClearChatInputDraft,threadId:pf(u,se)}),R.current&&(R.current.style.height=`auto`)},t[0]=o,t[1]=m,t[2]=re,t[3]=d,t[4]=l,t[5]=n,t[6]=a,t[7]=c,t[8]=se,t[9]=B,t[10]=te,t[11]=p,t[12]=ae,t[13]=s,t[14]=u,t[15]=z,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 le=ce,V;t[23]!==y||t[24]!==n||t[25]!==r||t[26]!==S||t[27]!==C||t[28]!==R?(V=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]=V):V=t[29];let ue=V,de;t[30]!==j||t[31]!==y||t[32]!==n||t[33]!==ie||t[34]!==r||t[35]!==ee||t[36]!==ne||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`?(ee(!0),ne(!1),ie(!1)):e.metadata.mode===`ralph`&&(ne(!0),ee(!1),ie(!1))},t[30]=j,t[31]=y,t[32]=n,t[33]=ie,t[34]=r,t[35]=ee,t[36]=ne,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]!==le||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(),le();return}let t=rt();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&&Yn(u).then(e=>{E(e)}).catch(_f))}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(gf),...o.map(hf)],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]=le,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]!==le||t[111]!==U||t[112]!==fe||t[113]!==ue||t[114]!==pe?(_e={handleSend:le,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]=le,t[111]=U,t[112]=fe,t[113]=ue,t[114]=pe,t[115]=_e):_e=t[115],_e}function hf(e){return{type:`skill`,data:e}}function gf(e){return{type:`command`,data:e}}function _f(e){return console.error(`Failed to fetch files:`,e)}var vf=768;function yf(){let e=(0,X.c)(2),[t,n]=Y.useState(bf),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${vf-1}px)`),t=()=>{n(window.innerWidth<vf)};return e.addEventListener(`change`,t),n(window.innerWidth<vf),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),t}function bf(){return typeof window>`u`?!1:window.innerWidth<vf}function xf(){let e=(0,X.c)(18),t=za(),n=Q(wf),r=Q(Cf),i=Q(Sf),a=yf(),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 Sf(e){return e.selectedThreadId}function Cf(e){return e.focusedPane}function wf(e){return e.dualChatEnabled}function Tf(e){let t=(0,X.c)(20),{visible:n,commands:r,skills:i,skillReferencePrefix:a,query:o,selectedIndex:s,onSelectCommand:c,onSelectSkill:l,onMouseEnterSuggestion:u,containerRef:d}=e,f=a===void 0?`/`:a;if(!n)return null;let p=f===`//`,m;if(t[0]!==r||t[1]!==d||t[2]!==p||t[3]!==u||t[4]!==c||t[5]!==l||t[6]!==o||t[7]!==s||t[8]!==f||t[9]!==i){let e;t[11]===o?e=t[12]:(e=e=>e.name.toLowerCase().includes(o.toLowerCase()),t[11]=o,t[12]=e);let n=r.filter(e),a;t[13]===o?a=t[14]:(a=e=>e.name.toLowerCase().includes(o.toLowerCase()),t[13]=o,t[14]=a);let h=[...i.filter(a).map(Df),...p?[]:n.map(Ef)].slice(0,10),g,_;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(g=U(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),_=(0,$.jsx)(fe,{className:`h-3 w-3`}),t[15]=g,t[16]=_):(g=t[15],_=t[16]);let v=p?`Bundled Skills`:`Skills & Commands`,y=o&&` matching "${o}"`,b;t[17]!==v||t[18]!==y?(b=(0,$.jsxs)(`div`,{className:g,children:[_,v,y]}),t[17]=v,t[18]=y,t[19]=b):b=t[19],m=(0,$.jsxs)(`div`,{ref:d,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[b,h.length>0?(()=>{let e=[],t=!1,n=!1;return h.forEach((r,i)=>{let a=i===s;if(r.type===`skill`&&!t&&(t=!0,e.push((0,$.jsx)(`div`,{className:U(J.dropdownGroupHeading,`px-2 py-1.5 pt-2`),children:`Skills`},`group-skills`))),r.type===`command`&&!n&&(n=!0,e.push((0,$.jsx)(`div`,{className:U(J.dropdownGroupHeading,`px-2 py-1.5 pt-2`),children:`Commands`},`group-commands`))),r.type===`command`){let t=r.data;e.push((0,$.jsxs)(`button`,{type:`button`,className:U(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,a?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>c(t),onMouseEnter:()=>u(i),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,t.name]}),t.metadata.argumentHint&&(0,$.jsx)(`span`,{className:J.compact,children:t.metadata.argumentHint})]}),t.metadata.description&&(0,$.jsx)(`span`,{className:J.compact,children:t.metadata.description})]},`cmd-${t.name}`))}else{let t=r.data;e.push((0,$.jsxs)(`button`,{type:`button`,className:U(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,a?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>l(t),onMouseEnter:()=>u(i),children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(`span`,{className:`font-medium`,children:[f,t.name]})}),(0,$.jsx)(`span`,{className:J.compact,children:t.description})]},`skill-${t.name}`))}}),e})():(0,$.jsxs)(`div`,{className:U(J.compact,`px-3 py-4 text-center text-muted-foreground`),children:[p?`No bundled skills found.`:`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:J.compact,children:[p?(0,$.jsx)($.Fragment,{children:`Use bundled skills with syntax like `}):(0,$.jsx)($.Fragment,{children:`Create commands in `}),p?(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`//skill-name`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/commands/`}),` or skills in`,` `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/skills/`})]})]})]})]}),t[0]=r,t[1]=d,t[2]=p,t[3]=u,t[4]=c,t[5]=l,t[6]=o,t[7]=s,t[8]=f,t[9]=i,t[10]=m}else m=t[10];return m}function Ef(e){return{type:`command`,data:e}}function Df(e){return{type:`skill`,data:e}}function Of(e){return e.startsWith(`image/`)}function kf(e){return e.startsWith(`video/`)}function Af(e){return e.startsWith(`audio/`)}function jf(e){let t=(0,X.c)(7),{attachments:n,onRemove:r}=e;if(n.length===0)return null;let i;if(t[0]!==n||t[1]!==r){let e;t[3]===r?e=t[4]:(e=(e,t)=>(0,$.jsx)(`div`,{className:U(J.compact,`group relative flex items-center gap-1 rounded-md bg-muted text-muted-foreground`),children:Of(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.content}`,alt:e.fileName,className:`h-16 w-16 rounded-md object-cover`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-foreground text-background opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,$.jsx)(zn,{className:`h-2.5 w-2.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):kf(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(O,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(zn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):Af(e.mimeType)?(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(R,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(zn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(kt,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(zn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]})},t),t[3]=r,t[4]=e),i=n.map(e),t[0]=n,t[1]=r,t[2]=i}else i=t[2];let a;return t[5]===i?a=t[6]:(a=(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:i}),t[5]=i,t[6]=a),a}var Mf=ri(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`]}),Nf=function(e){let t=(0,X.c)(37),{breakdown:n,onClose:r}=e,{categories:i,totalTokens:a,contextWindow:o,percentageFull:s}=n,c,l,u,d,f,p,m,h;if(t[0]!==i||t[1]!==o||t[2]!==r||t[3]!==s||t[4]!==a){let e;t[13]===i?e=t[14]:(e=e=>i[e.key]>0,t[13]=i,t[14]=e);let n=Pf.filter(e);c=Mf,l=J.label,t[15]===r?u=t[16]:(u=r&&(0,$.jsxs)(V,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:r,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[15]=r,t[16]=u),t[17]===Symbol.for(`react.memo_cache_sentinel`)?(d=U(J.compact,`flex items-center justify-between text-muted-foreground`),t[17]=d):d=t[17],f=s,t[18]===a?p=t[19]:(p=Ff(a),t[18]=a,t[19]=p),t[20]===o?m=t[21]:(m=If(o),t[20]=o,t[21]=m);let g;t[22]!==i||t[23]!==o?(g=e=>{let t=i[e.key],n=o>0?t/o*100:0;return(0,$.jsx)(`div`,{style:{width:`${Math.max(n,t>0?.5:0)}%`,backgroundColor:e.color}},e.key)},t[22]=i,t[23]=o,t[24]=g):g=t[24],h=n.map(g),t[0]=i,t[1]=o,t[2]=r,t[3]=s,t[4]=a,t[5]=c,t[6]=l,t[7]=u,t[8]=d,t[9]=f,t[10]=p,t[11]=m,t[12]=h}else c=t[5],l=t[6],u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12];let g;t[25]===i?g=t[26]:(g=Pf.map(e=>(0,$.jsxs)(`div`,{className:U(J.compact,`flex items-center justify-between text-muted-foreground`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{children:e.label})]}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:Ff(i[e.key])})]},e.key)),t[25]=i,t[26]=g);let _;return t[27]!==c||t[28]!==l||t[29]!==u||t[30]!==d||t[31]!==f||t[32]!==p||t[33]!==m||t[34]!==h||t[35]!==g?(_=(0,$.jsx)(c,{v0:l,v1:u,v2:d,v3:f,v4:p,v5:m,v6:h,v7:g}),t[27]=c,t[28]=l,t[29]=u,t[30]=d,t[31]=f,t[32]=p,t[33]=m,t[34]=h,t[35]=g,t[36]=_):_=t[36],_},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 Ff(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function If(e){return e>=1e6?`${Math.round(e/1e6)}M`:e>=1e3?`${Math.round(e/1e3)}K`:e.toString()}function Lf({threadId:e,currentConversationId:t,initialBreakdown:n,refreshKey:r,children:i}){let[a,o]=(0,Y.useState)(n??null),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(n?t:void 0);return(0,Y.useEffect)(()=>{if(n){o(n),m(t),u(null);return}t!==p&&(o(null),m(void 0),u(null))},[n,t,p,r]),(0,Y.useEffect)(()=>{if(!d||!e||!t||p===t)return;let n=!1;async function r(){let r=t;if(r){c(!0),u(null);try{let t=await jt(e,r);if(n)return;o(t),m(r)}catch(e){if(console.error(`[TokenUsageTooltip] Failed to load context data:`,e),n)return;o(e=>(e||u(`Failed to load context data`),e))}finally{n||c(!1)}}}return r(),()=>{n=!0}},[d,e,t,p]),!e||e===``?(0,$.jsx)($.Fragment,{children:i}):(0,$.jsxs)(gl,{open:d,onOpenChange:f,children:[(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(_l,{asChild:!0,children:i})}),(0,$.jsx)(z,{side:`top`,className:`bg-popover text-popover-foreground`,children:`Show context usage`})]}),(0,$.jsxs)(vl,{side:`top`,align:`end`,className:`w-auto p-4`,children:[s&&(0,$.jsxs)(`div`,{className:U(J.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(bn,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading context...`})]}),l&&!s&&(0,$.jsxs)(`div`,{className:U(J.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(bn,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:l})]}),!s&&!l&&a&&(0,$.jsx)(Nf,{breakdown:a,onClose:()=>f(!1)})]})]})}var Rf=ri(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}),zf=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=Vf(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)(Rf,{v0:o,v1:7,v2:7,v3:r,v4:i}),t[2]=i,t[3]=o,t[4]=s):s=t[4],s};function Bf(e){return e.filter(e=>e.sender===`agent`).length}function Vf(e){return e>75?`text-red-500`:e>50?`text-orange-500`:`text-muted-foreground`}var Hf=500;function Uf(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),[u,d]=(0,Y.useState)(),f;t[2]===o?f=t[3]:(f=Bf(o),t[2]=o,t[3]=f);let p=f,[m,h]=(0,Y.useState)(p),g=(0,Y.useRef)(null),_=(0,Y.useRef)(n),v,y;t[4]===p?(v=t[5],y=t[6]):(v=()=>(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{h(p)},Hf),()=>{g.current&&clearTimeout(g.current)}),y=[p],t[4]=p,t[5]=v,t[6]=y),(0,Y.useEffect)(v,y);let b,x;t[7]===n?(b=t[8],x=t[9]):(b=()=>{_.current!==n&&(_.current&&(ne.invalidate(`thread-${_.current}`),ne.invalidatePattern(RegExp(`^context-breakdown-${_.current}-`))),_.current=n,c(void 0),d(void 0))},x=[n],t[7]=n,t[8]=b,t[9]=x),(0,Y.useEffect)(b,x);let S,C;t[10]===r?(S=t[11],C=t[12]):(S=()=>{if(r){c(r);return}},C=[r],t[10]=r,t[11]=S,t[12]=C),(0,Y.useEffect)(S,C);let w;t[13]!==r||t[14]!==n?(w=()=>{let e=!1;return(async function(){if(!n){c(void 0),d(void 0);return}if(r){c(r);return}try{let t=await B(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]=w):w=t[15];let T;t[16]!==r||t[17]!==m||t[18]!==n?(T=[r,n,m],t[16]=r,t[17]=m,t[18]=n,t[19]=T):T=t[19],(0,Y.useEffect)(w,T);let E;t[20]!==s||t[21]!==n?(E=()=>{let e=!1;return(async function(){if(!n||!s){d(void 0);return}try{let t=await jt(n,s);if(e)return;d(t)}catch(e){let t=e;if(t instanceof Error&&t.message===`Conversation not found`){d(void 0);return}console.error(`Failed to fetch context breakdown:`,t)}})(),()=>{e=!0}},t[20]=s,t[21]=n,t[22]=E):E=t[22];let D;if(t[23]!==m||t[24]!==s||t[25]!==n?(D=[n,s,m],t[23]=m,t[24]=s,t[25]=n,t[26]=D):D=t[26],(0,Y.useEffect)(E,D),!n||n===``)return null;let O=u?.percentageFull,k=typeof O==`number`&&O>25,A=String(m),j;t[27]!==O||t[28]!==k?(j=k?(0,$.jsx)(zf,{percentage:O}):(0,$.jsx)(l,{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)(V,{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]!==u||t[34]!==s||t[35]!==A||t[36]!==N||t[37]!==n?(P=(0,$.jsx)(Lf,{threadId:n,currentConversationId:s,initialBreakdown:u,refreshKey:A,children:N}),t[33]=u,t[34]=s,t[35]=A,t[36]=N,t[37]=n,t[38]=P):P=t[38],P}function Wf(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 Gf(e){let t=(0,X.c)(17),{showSuggestions:n,fileSuggestions:r,suggestionQuery:i,selectedIndex:a,onSelectFile:o,onMouseEnterSuggestion:s,containerRef:c}=e;if(!n||r.length===0)return null;let l,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=U(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),u=(0,$.jsx)(Be,{className:`h-3 w-3`}),t[0]=l,t[1]=u):(l=t[0],u=t[1]);let d;t[2]===i?d=t[3]:(d=(0,$.jsxs)(`div`,{className:l,children:[u,`Files matching "`,i,`"`]}),t[2]=i,t[3]=d);let f;if(t[4]!==r||t[5]!==s||t[6]!==o||t[7]!==a){let e;t[9]!==s||t[10]!==o||t[11]!==a?(e=(e,t)=>{let n=e.split(`/`).pop()??e,r=t===a;return(0,$.jsxs)(`button`,{type:`button`,className:U(J.body,`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left transition-colors`,r?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>o(e),onMouseEnter:()=>s(t),children:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,$.jsx)(se,{className:`h-4 w-4 text-blue-500`}):(0,$.jsx)(ve,{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:U(J.compact,`truncate text-muted-foreground opacity-70`),children:e})]})]},e)},t[9]=s,t[10]=o,t[11]=a,t[12]=e):e=t[12],f=r.map(e),t[4]=r,t[5]=s,t[6]=o,t[7]=a,t[8]=f}else f=t[8];let p;return t[13]!==c||t[14]!==d||t[15]!==f?(p=(0,$.jsxs)(`div`,{ref:c,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[d,f]}),t[13]=c,t[14]=d,t[15]=f,t[16]=p):p=t[16],p}function Kf(e){let t=(0,X.c)(5),{providerSlug:n}=e;if(!n)return null;let r;t[0]===n?r=t[1]:(r=Vt(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:qf}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a}function qf(e){e.currentTarget.style.visibility=`hidden`}function Jf(e){let t=(0,X.c)(9),{providerSlug:n,providerData:r}=e,i=r?.name??n,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=U(J.dropdownGroupHeading,`flex items-center gap-1.5 px-3 py-1.5 uppercase tracking-wide`),t[0]=a):a=t[0];let o;t[1]===n?o=t[2]:(o=(0,$.jsx)(Kf,{providerSlug:n}),t[1]=n,t[2]=o);let s;t[3]!==i||t[4]!==r?(s=r?.url?(0,$.jsx)(_i,{url:r.url,showIcon:!1,variant:`inline`,children:i}):i,t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:a,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8],c}function Yf(e){let t=e.pricing?.prompt;return t==null?null:Math.ceil(t*3)}function Xf(e){return`$${D(e)}`}function Zf(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:`${Xf(e.pricing.prompt??0)} input per million tokens`}),(0,$.jsx)(`div`,{children:`${Xf(e.pricing.completion??0)} output per million tokens`}),(0,$.jsx)(`div`,{children:`Displayed value of ${t} is a relative price.`})]}):null}function Qf(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=(Yf(e)??2**53-1)-(Yf(n)??2**53-1);if(t!==0)return t}return vi(e.id).localeCompare(vi(n.id))})}function $f(e){let t=(0,X.c)(40),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Y.useState(!1),[s,c]=Y.useState(`relative-price`),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=new Map,t[0]=l):l=t[0];let[u,d]=Y.useState(l),f=Y.useRef(null),m,h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{p().then(function(e){d(new Map(e.map(np)))})},h=[],t[1]=m,t[2]=h):(m=t[1],h=t[2]),Y.useEffect(m,h);let g,_;t[3]===a?(g=t[4],_=t[5]):(g=()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&o(!1)};if(a)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},_=[a],t[3]=a,t[4]=g,t[5]=_),Y.useEffect(g,_);let v;t[6]===i?v=t[7]:(v=e=>{i(e),o(!1)},t[6]=i,t[7]=v);let y=v,b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{c(function(e){return e===`relative-price`?`alphabetical`:`relative-price`})},t[8]=b):b=t[8];let x=b,S;t[9]!==n||t[10]!==s?(S=Qf(n,s),t[9]=n,t[10]=s,t[11]=S):S=t[11];let C=S,w=s===`relative-price`?sn:Nn,T=s===`relative-price`?`Sort by relative price`:`Sort alphabetically`,E,D;t[12]===n.length?(E=t[13],D=t[14]):(D=()=>{let e=function(e){let t=e.key.toLowerCase();!((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey)||t!==`m`||n.length===0||(e.preventDefault(),o(tp))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},E=[n.length],t[12]=n.length,t[13]=E,t[14]=D),Y.useEffect(D,E);let O;t[15]===a?O=t[16]:(O=()=>o(!a),t[15]=a,t[16]=O);let A;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(A=U(J.body,`font-normal`),t[17]=A):A=t[17];let j;t[18]===r?j=t[19]:(j=r?vi(r.id):`No model`,t[18]=r,t[19]=j);let M;t[20]===j?M=t[21]:(M=(0,$.jsx)(`span`,{className:A,children:j}),t[20]=j,t[21]=M);let N;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(Se,{className:`h-3 w-3`}),t[22]=N):N=t[22];let P;t[23]!==O||t[24]!==M?(P=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:O,children:[M,N]})}),t[23]=O,t[24]=M,t[25]=P):P=t[25];let F;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,$.jsx)(z,{children:`Select Model`}),t[26]=F):F=t[26];let I;t[27]===P?I=t[28]:(I=(0,$.jsxs)(k,{children:[P,F]}),t[27]=P,t[28]=I);let L;t[29]!==w||t[30]!==y||t[31]!==u||t[32]!==r?.id||t[33]!==a||t[34]!==T||t[35]!==C?(L=a&&(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 w-80 max-h-80 overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:(0,$.jsxs)(ce,{children:[(0,$.jsx)(`div`,{className:`-mb-3 flex justify-end px-1 pb-1`,children:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":T,className:`rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground`,onClick:x,children:(0,$.jsx)(w,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(z,{side:`left`,align:`start`,sideOffset:8,children:T})]})}),Object.entries(C.reduce(ep,{})).map((e,t)=>{let[n,i]=e;return(0,$.jsxs)(`div`,{children:[t>0&&(0,$.jsx)(gi,{className:`my-1`}),(0,$.jsx)(Jf,{providerSlug:n,providerData:u.get(n)}),i.map(e=>{let t=Yf(e),n=t==null?null:Zf(e,t);return(0,$.jsx)(`div`,{children:(0,$.jsx)(`div`,{children:(0,$.jsxs)(`button`,{type:`button`,className:U(J.body,`flex w-full items-center justify-between gap-3 whitespace-nowrap rounded-md px-3 py-1.5 pl-8 text-popover-foreground hover:bg-accent`,e.id===r?.id&&`bg-accent font-medium`),onClick:()=>y(e),children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:vi(e.id)}),t!=null&&n&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:t})}),(0,$.jsx)(z,{side:`left`,align:`end`,sideOffset:8,className:`max-w-64`,children:n})]})]})})},e.id)})]},n)})]})}),t[29]=w,t[30]=y,t[31]=u,t[32]=r?.id,t[33]=a,t[34]=T,t[35]=C,t[36]=L):L=t[36];let R;return t[37]!==I||t[38]!==L?(R=(0,$.jsxs)(`div`,{className:`relative`,ref:f,children:[I,L]}),t[37]=I,t[38]=L,t[39]=R):R=t[39],R}function ep(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function tp(e){return!e}function np(e){return[e.slug,e]}var rp=[{value:`build`,label:`Build`,icon:Hn,description:`Executes code changes and implements features`},{value:`plan`,label:`Plan`,icon:nt,description:`Creates implementation plans without making changes`},{value:`image`,label:`Image`,icon:Gn,description:`Generates and edits images`},{value:`ralph`,label:`Ralph`,icon:Je,description:`Runs rapid iterative test-fix cycles`}];function ip(e,t,n){return n?`ralph`:e?`plan`:t?`image`:`build`}function ap({planMode:e,imageMode:t,ralphMode:n,setPlanMode:r,setImageMode:i,setRalphMode:a,projectId:o}){let s=za(),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=ip(e,t,n),m=rp.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 Te(o,{allowAllCommands:!e}),Qt(o);let t=await C();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:rp,confirmCommands:l,currentConfig:m,currentMode:p,isUpdatingConfirmCommands:d,selectMode:g,toggleConfirmCommands:h}}function op(e){let t=(0,X.c)(38),{planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:s,projectId:c}=e,[l,u]=Y.useState(!1),d=Y.useRef(null),f;t[0]!==r||t[1]!==n||t[2]!==c||t[3]!==i||t[4]!==o||t[5]!==a||t[6]!==s?(f={planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:s,projectId:c},t[0]=r,t[1]=n,t[2]=c,t[3]=i,t[4]=o,t[5]=a,t[6]=s,t[7]=f):f=t[7];let{chatModes:p,confirmCommands:m,currentConfig:h,currentMode:g,isUpdatingConfirmCommands:_,selectMode:v,toggleConfirmCommands:y}=ap(f),b,x;t[8]===l?(b=t[9],x=t[10]):(b=()=>{let e=function(e){d.current&&!d.current.contains(e.target)&&u(!1)};if(l)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},x=[l],t[8]=l,t[9]=b,t[10]=x),Y.useEffect(b,x);let S;t[11]===v?S=t[12]:(S=function(e){v(e),u(!1)},t[11]=v,t[12]=S);let C=S,w;t[13]===l?w=t[14]:(w=()=>u(!l),t[13]=l,t[14]=w);let T;t[15]===h.icon?T=t[16]:(T=(0,$.jsx)(h.icon,{className:`h-4 w-4`}),t[15]=h.icon,t[16]=T);let E;t[17]!==w||t[18]!==T?(E=(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{variant:`action`,size:`icon-sm`,onClick:w,children:T})}),t[17]=w,t[18]=T,t[19]=E):E=t[19];let D;t[20]!==h.description||t[21]!==h.label?(D=(0,$.jsx)(z,{children:(0,$.jsxs)(`p`,{children:[h.label,` - `,h.description]})}),t[20]=h.description,t[21]=h.label,t[22]=D):D=t[22];let O;t[23]!==E||t[24]!==D?(O=(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{children:[E,D]})}),t[23]=E,t[24]=D,t[25]=O):O=t[25];let A;t[26]!==p||t[27]!==m||t[28]!==g||t[29]!==C||t[30]!==_||t[31]!==l||t[32]!==c||t[33]!==y?(A=l&&(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:[c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:U(J.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent disabled:opacity-50`),onClick:()=>{y()},disabled:_,children:[`Confirm Commands`,m&&(0,$.jsx)(tn,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border`})]}),p.map(e=>{let t=e.icon,n=e.value===g;return(0,$.jsxs)(`button`,{type:`button`,className:U(J.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent`),onClick:()=>C(e.value),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(tn,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[26]=p,t[27]=m,t[28]=g,t[29]=C,t[30]=_,t[31]=l,t[32]=c,t[33]=y,t[34]=A):A=t[34];let j;return t[35]!==A||t[36]!==O?(j=(0,$.jsxs)(`div`,{className:`relative hidden md:block`,ref:d,children:[O,A]}),t[35]=A,t[36]=O,t[37]=j):j=t[37],j}function sp(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??up,b=d??lp,x=f??cp,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=ap(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)(be,{}),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)(uu,{asChild:!0,children:(0,$.jsxs)(V,{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)(kt,{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)(hu,{onClick:k,children:[A,`Attach File`]}),t[16]=k,t[17]=j);let M;t[18]!==r||t[19]!==a?(M=r&&(0,$.jsxs)(hu,{onClick:()=>T(a),children:[(0,$.jsx)(wt,{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)(yu,{}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(hu,{onClick:()=>{C.toggleConfirmCommands()},disabled:C.isUpdatingConfirmCommands,children:[`Confirm Commands`,C.confirmCommands&&(0,$.jsx)(tn,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(yu,{})]}),C.chatModes.map(e=>{let t=e.icon,n=e.value===C.currentMode;return(0,$.jsxs)(hu,{onClick:()=>C.selectMode(e.value),className:U(n&&`bg-accent`),children:[(0,$.jsx)(t,{className:`mr-2 h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(tn,{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)(mu,{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)(lu,{children:[O,P]}),t[29]=O,t[30]=P,t[31]=F):F=t[31],F}function cp(){}function lp(){}function up(){}var dp=bi(`voice.stt.web`);function fp(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 pp(e){let t=``;for(let n=0;n<e.results.length;n+=1)t+=e.results[n][0]?.transcript??``;return t}function mp(){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=yi();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=pp(e).trim();t&&a(t)},e.onerror=e=>{let t=fp(e.error);dp.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}dp.info(`Web Speech recognition ended — restarting`),u()},c.current=e;try{e.start(),t(`recording`),dp.info(`Web Speech recognition started`)}catch(e){c.current=null,l.current=!1;let n=e instanceof Error?e.message:`Unknown error`;dp.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),dp.info(`Checking Web Speech API support`,{userAgent:navigator.userAgent,platform:navigator.platform});let n=Si();return r(n),n?(dp.info(`Web Speech API available — ready`),t(`ready`),`ready`):(dp.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(``),dp.info(`Starting Web Speech recognition`),u()},[u]),stopListening:(0,Y.useCallback)(async()=>{l.current=!1,c.current?.stop(),c.current=null,t(`ready`),dp.info(`Web Speech recognition stopped`)},[]),requestModelDownload:(0,Y.useCallback)(async()=>{},[]),ensureReady:d,resetTranscript:(0,Y.useCallback)(()=>{a(``),s(null)},[])}}var hp=bi(`voice.stt.vosk-hook`);function gp(e,t){let n=e.trim(),r=t.trim();return n&&r?`${n} ${r}`:n||r}function _p(){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(gp(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=wi();async function i(){t(`checking-support`),_(!1),l(0),s(null),hp.separator(`VOICE SESSION START`),hp.info(`Checking Vosk support`,{userAgent:navigator.userAgent,platform:navigator.platform,url:n});try{let e=new xi;u.current=e;let i=e.checkSupport();if(r(i),!i)return hp.error(`Vosk not supported in this environment`),t(`error`),s(`Local speech recognition is not supported in this environment.`),`error`;let a=new Ci;d.current=a,hp.info(`Checking IndexedDB model cache`,{url:n});let o=await a.getCachedModelByUrl(n);return o?(hp.info(`Cached model found — initializing Vosk`,{sizeBytes:o.byteLength,sizeMB:(o.byteLength/1024/1024).toFixed(2)}),_(!0),t(`initializing`),await e.initModelFromBytes(o),hp.info(`Vosk model initialized from cache — ready`),t(`ready`),`ready`):(hp.info(`Model not in cache — download required`),t(`needs-model`),`needs-model`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;return hp.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=wi();t(`downloading-model`),l(0),s(null),hp.info(`Model download requested`,{url:e});try{let n=await d.current.loadModelByUrl(e,e=>{l(e),e%10==0&&hp.debug(`Model download progress`,{progress:e})});hp.info(`Model download complete — initializing Vosk`,{sizeBytes:n.byteLength,sizeMB:(n.byteLength/1024/1024).toFixed(2)}),t(`initializing`),await u.current.initModelFromBytes(n),hp.info(`Vosk model initialized after download — ready`),_(!0),t(`ready`)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred.`;hp.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(``),hp.separator(`RECORDING START`),!navigator.mediaDevices?.getUserMedia){hp.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`),hp.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){hp.info(`stopListening called but no active recording`),m.current&&t(`ready`);return}t(`transcribing`),hp.info(`Stopping recording`);try{await f.current.stop(),g.current=``,v(),t(`ready`),hp.info(`Recording stopped`)}catch(e){let n=e instanceof Error?e.message:`Unknown error`;hp.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 vp(){let e=(0,X.c)(22),t=_p(),n=mp();if(Dn()){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}function yp(){let[e,t]=(0,Y.useState)(!0),[n,r]=(0,Y.useState)(!0),[i,a]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{let e=!1;async function n(){try{let n=await Ze();e||t(n.voiceAiProcessing)}catch(e){console.error(`Failed to load voice AI processing setting:`,e)}finally{e||r(!1)}}return n(),()=>{e=!0}},[]);async function o(e){a(!0);try{t((await oe({voiceAiProcessing:e})).voiceAiProcessing)}catch(e){throw console.error(`Failed to update voice AI processing setting:`,e),e}finally{a(!1)}}return{isEnabled:e,isLoading:n,isSaving:i,updateIsEnabled:o}}var bp=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=U(`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)(Sr,{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)(ir,{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});bp.displayName=ir.displayName;function xp(e,t,n){return t?`Preparing voice input…`:n<100?`Downloading voice model… ${n}%`:e?`Finishing download…`:`Downloading voice model…`}function Sp(e){let t=(0,X.c)(24),{open:n,onOpenChange:r,onRetry:i,isDownloading:a,isInitializing:o,progress:c,error:l}=e,u=a||o,d;t[0]!==u||t[1]!==r?(d=function(e){u&&!e||r(e)},t[0]=u,t[1]=r,t[2]=d):d=t[2];let f=d,p=l?`Voice model download failed`:`Setting up voice input`,m;t[3]===p?m=t[4]:(m=(0,$.jsx)(Zt,{children:p}),t[3]=p,t[4]=m);let h=l?`The English voice model could not be downloaded or prepared.`:`First-time setup downloads a ~40 MB English speech model to your device.`,g;t[5]===h?g=t[6]:(g=(0,$.jsx)(s,{children:h}),t[5]=h,t[6]=g);let _;t[7]!==m||t[8]!==g?(_=(0,$.jsxs)(En,{children:[m,g]}),t[7]=m,t[8]=g,t[9]=_):_=t[9];let v;t[10]!==l||t[11]!==a||t[12]!==o||t[13]!==r||t[14]!==i||t[15]!==c?(v=l?(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(mi,{variant:`error`,className:`mb-0`,children:l}),(0,$.jsxs)(gt,{children:[(0,$.jsx)(V,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(V,{onClick:i,children:`Try again`})]})]}):(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(mi,{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)(ti,{title:xp(a,o,c)}),(0,$.jsx)(bp,{value:o?100:c,className:`w-full`}),(0,$.jsx)(`p`,{className:U(J.bodyMuted,`text-center`),children:o?`Loading the model into memory. This usually takes a few seconds.`:c<100?`About 40 MB — kept on this device for future use.`:`Saving the model locally…`})]})]}),t[10]=l,t[11]=a,t[12]=o,t[13]=r,t[14]=i,t[15]=c,t[16]=v):v=t[16];let y;t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(Ce,{children:[_,v]}),t[17]=_,t[18]=v,t[19]=y):y=t[19];let b;return t[20]!==f||t[21]!==n||t[22]!==y?(b=(0,$.jsx)(Ke,{open:n,onOpenChange:f,children:y}),t[20]=f,t[21]=n,t[22]=y,t[23]=b):b=t[23],b}var Cp=ri(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`]}),wp=function({onTranscript:e,onVoiceSessionStart:t,children:n}){let{state:r,isSupported:i,usesLocalModel:a,transcript:o,error:s,downloadProgress:c,startListening:l,stopListening:u,requestModelDownload:d,ensureReady:f,resetTranscript:p}=vp(),{isEnabled:m}=yp(),{toast:h}=no(),[g,_]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(!1),b=(0,Y.useRef)(``),x=(0,Y.useRef)(null),S=(0,Y.useRef)(`idle`),C=r===`recording`,w=r===`transcribing`,T=C||w,E=r===`needs-model`,D=r===`downloading-model`,O=r===`initializing`,A=D||O,j=r===`checking-support`;(0,Y.useEffect)(()=>{s&&s!==x.current&&!g&&h({title:`Voice Input Error`,description:s,variant:`destructive`}),x.current=s},[s,g,h]),(0,Y.useEffect)(()=>{if(o&&o!==b.current){let t=o.substring(b.current.length);b.current=o,e(t)}},[o,e]),(0,Y.useEffect)(()=>{o||(b.current=``)},[o]),(0,Y.useEffect)(()=>{let t=S.current;if(S.current=r,(t===`recording`||t===`transcribing`)&&r===`ready`&&m&&b.current){let t=b.current;y(!0),An(t).then(t=>{e(t,{replace:!0})}).catch(()=>{e(t,{replace:!0})}).finally(()=>{y(!1)})}},[r,m,e]);function M(){_(!0),d()}let N=(0,Y.useCallback)(async()=>{if(T){u();return}if(E){M();return}if(r===`ready`){p(),t?.(),l();return}if(r===`idle`){let e=await f();e===`needs-model`?M():e===`ready`&&(p(),t?.(),l())}},[E,T,r,f,u,l,p,d,t]),P=(0,Y.useCallback)(()=>{d()},[d]);(0,Y.useEffect)(()=>{r===`ready`&&g&&_(!1)},[r,g]);let F=(0,Y.useCallback)(()=>j?`Checking voice input support...`:i===!1?`Voice input not supported in this browser`:s||(A?`Downloading speech model...`:v?`Processing transcription`:w?`Transcribing...`:C?`Stop listening`:E?`Click to download speech model`:`Start listening`),[s,v,j,A,C,w,i,E]),I=(0,Y.useCallback)(()=>A||w||v?(0,$.jsx)(Et,{className:`h-3 w-3 animate-spin`}):C?(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)(mt,{className:`h-3 w-3`}),[v,A,C,w]),L=F(),R=T||v?L:`Voice input`;return(0,$.jsx)(Cp,{v0:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:n({onClick:N,disabled:j||A||w||v||i===!1,icon:I(),label:L,isRecording:C,isTranscribing:w||v,isDownloading:A,needsModel:E,isSupported:i!==!1})}),(0,$.jsx)(z,{side:`top`,className:`bg-popover text-popover-foreground max-w-64`,children:R})]}),v1:a?(0,$.jsx)(Sp,{open:g,onOpenChange:_,onRetry:P,isDownloading:D,isInitializing:O,progress:c,error:g?s:null}):null})};function Tp(e){let t=(0,X.c)(8),{queuedMessages:n,onRemoveQueuedMessage:r}=e;if(n.length===0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`div`,{className:U(J.compact,J.label,`text-muted-foreground`),children:`Queued messages`}),t[0]=i):i=t[0];let a;if(t[1]!==r||t[2]!==n){let e;t[4]===r?e=t[5]:(e=e=>(0,$.jsxs)(`div`,{className:U(J.body,`flex items-start justify-between gap-3 rounded-md border border-border/60 bg-background px-3 py-2`),children:[(0,$.jsx)(`p`,{className:`flex-1 whitespace-pre-wrap text-foreground`,children:e.message}),(0,$.jsx)(`button`,{type:`button`,className:`rounded-full p-1 text-muted-foreground transition-colors hover:bg-foreground hover:text-background`,onClick:()=>r(e.id),"aria-label":`Remove queued message`,children:(0,$.jsx)(zn,{className:`h-3.5 w-3.5`})})]},e.id),t[4]=r,t[5]=e),a=n.map(e),t[1]=r,t[2]=n,t[3]=a}else a=t[3];let o;return t[6]===a?o=t[7]:(o=(0,$.jsxs)(mi,{className:`mb-3 border border-border/60 bg-muted/30 px-4 py-3`,children:[i,(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:a})]}),t[6]=a,t[7]=o),o}function Ep(e){let t=(0,X.c)(27),{onSpeechClick:n,speechDisabled:r,icon:i,label:a,isRecording:o,isTranscribing: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)(Tn,{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)(V,{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 Dp(e){let t=(0,X.c)(200),{planMode:n,setPlanMode:r,onSend:i,onStop:a,isStreaming:s,disabled:l,initialValue:u,queuedMessages:d,onRemoveQueuedMessage:f,isOverlay:p,userTasks:m,onMatchedUserTaskSend:h,onUserTaskCreated:g}=e,_=s===void 0?!1:s,v=p===void 0?!1:p,y;t[0]===m?y=t[1]:(y=m===void 0?[]:m,t[0]=m,t[1]=y);let b=y,x;t[2]===u?x=t[3]:(x={initialValue:u},t[2]=u,t[3]=x);let{message:S,setMessage:C,historyIndex:w,setHistoryIndex:T,draftMessage:E,setDraftMessage:D,cursorPosition:O,setCursorPosition:A,availableModels:j,selectedModel:M,setSelectedModel:N,attachments:P,setAttachments:F,planMode:I,setPlanMode:L,ralphMode:R,setRalphMode:B,imageMode:ee,setImageMode:te,availableImageModels:ne,selectedImageModel:re,setSelectedImageModel:ie,allFiles:ae,setAllFiles:oe,showSuggestions:se,setShowSuggestions:ce,suggestionQuery:le,setSuggestionQuery:ue,selectedIndex:de,setSelectedIndex:fe,slashCommands:H,skills:pe,bundledSkills:me,bundledSkillMode:he,setBundledSkillMode:ge,showCommandSuggestions:_e,setShowCommandSuggestions:ve,commandQuery:ye,setCommandQuery:be,fileInputRef:xe,textareaRef:Se,suggestionsRef:Ce,commandSuggestionsRef:we,selectedThreadId:Te,dispatch:De}=ef(x),{paneId:Oe,conversationId:ke,setFocused:Ae,fillPane:je}=Ld(),Me=Q(Ip),Ne=Q(Fp),Pe=Oe===`secondary`?Ne:Me,Fe=Q(Pp),{isDualChatActive:Ie,showDualChatControls:Le,canCloseSecondary:Re,enableDualChat:ze,disableDualChat:Be}=xf(),Ve;t[4]===Pe?Ve=t[5]:(Ve=Pe.some(Np),t[4]=Pe,t[5]=Ve);let He=Ve,Ue=ee?re:M,We=ee?ne:j,Ge;t[6]===S?Ge=t[7]:(Ge=S.trim(),t[6]=S,t[7]=Ge);let Ke=Ge.length>0,qe=Ke||P.length>0,[Je,Ye]=Y.useState(!1),Xe=yf(),Ze=n??I,Qe=r??L,$e=Te??void 0,et;t[8]!==ae||t[9]!==P||t[10]!==he||t[11]!==me||t[12]!==ye||t[13]!==O||t[14]!==De||t[15]!==E||t[16]!==Ze||t[17]!==Qe||t[18]!==He||t[19]!==w||t[20]!==ee||t[21]!==_||t[22]!==S||t[23]!==h||t[24]!==i||t[25]!==R||t[26]!==re||t[27]!==de||t[28]!==M||t[29]!==oe||t[30]!==F||t[31]!==ge||t[32]!==be||t[33]!==A||t[34]!==D||t[35]!==T||t[36]!==te||t[37]!==C||t[38]!==B||t[39]!==fe||t[40]!==ve||t[41]!==ce||t[42]!==ue||t[43]!==_e||t[44]!==se||t[45]!==pe||t[46]!==H||t[47]!==le||t[48]!==$e||t[49]!==Se||t[50]!==b?(et={message:S,setMessage:C,userTasks:b,onMatchedUserTaskSend:h,attachments:P,selectedModel:M,onSend:i,isStreaming:_,selectedThreadId:$e,isListening:!1,stopListening:Mp,resetTranscript:jp,dispatch:De,historyIndex:w,setHistoryIndex:T,draftMessage:E,setDraftMessage:D,cursorPosition:O,setCursorPosition:A,showSuggestions:se,setShowSuggestions:ce,suggestionQuery:le,setSuggestionQuery:ue,allFiles:ae,setAllFiles:oe,selectedIndex:de,setSelectedIndex:fe,showCommandSuggestions:_e,setShowCommandSuggestions:ve,commandQuery:ye,setCommandQuery:be,slashCommands:H,skills:pe,bundledSkills:me,bundledSkillMode:he,setBundledSkillMode:ge,textareaRef:Se,setAttachments:F,planMode:Ze,setPlanMode:Qe,ralphMode:R,setRalphMode:B,imageMode:ee,setImageMode:te,selectedImageModel:re,hasConversationMessages:He},t[8]=ae,t[9]=P,t[10]=he,t[11]=me,t[12]=ye,t[13]=O,t[14]=De,t[15]=E,t[16]=Ze,t[17]=Qe,t[18]=He,t[19]=w,t[20]=ee,t[21]=_,t[22]=S,t[23]=h,t[24]=i,t[25]=R,t[26]=re,t[27]=de,t[28]=M,t[29]=oe,t[30]=F,t[31]=ge,t[32]=be,t[33]=A,t[34]=D,t[35]=T,t[36]=te,t[37]=C,t[38]=B,t[39]=fe,t[40]=ve,t[41]=ce,t[42]=ue,t[43]=_e,t[44]=se,t[45]=pe,t[46]=H,t[47]=le,t[48]=$e,t[49]=Se,t[50]=b,t[51]=et):et=t[51];let{handleSend:tt,handleKeyDown:nt,handleTextareaInput:rt,insertFileReference:it,insertCommand:at,insertSkill:ot,fileSuggestions:st}=mf(et),ct=Y.useRef(``),W;t[52]===C?W=t[53]:(W=()=>{C(e=>(ct.current=e,e))},t[52]=C,t[53]=W);let lt=W,ut;t[54]===C?ut=t[55]:(ut=(e,t)=>{if(t?.replace){C(ct.current+e);return}C(t=>(t.endsWith(` `),t+e))},t[54]=C,t[55]=ut);let dt=ut,ft;t[56]===F?ft=t[57]:(ft=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(Ap);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];F(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[56]=F,t[57]=ft);let pt=ft,mt;t[58]!==je||t[59]!==v?(mt=Hd(je,v),t[58]=je,t[59]=v,t[60]=mt):mt=t[60];let ht=v?`border-border/50 bg-background/80 shadow-lg backdrop-blur-sm`:`border-border bg-background shadow-2xl`,gt;t[61]===ht?gt=t[62]:(gt=U(`relative flex min-w-0 flex-1 flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto`,ht),t[61]=ht,t[62]=gt);let _t;t[63]!==Re||t[64]!==Be||t[65]!==l||t[66]!==Ie||t[67]!==Oe||t[68]!==Le?(_t=Le&&Oe===`secondary`&&Ie&&(0,$.jsx)(`div`,{className:`absolute top-2 right-2 z-10 hidden md:block`,children:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:Be,disabled:!Re||l,children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close dual chat`})]})}),(0,$.jsx)(z,{children:`Close dual chat`})]})}),t[63]=Re,t[64]=Be,t[65]=l,t[66]=Ie,t[67]=Oe,t[68]=Le,t[69]=_t):_t=t[69];let vt;t[70]!==f||t[71]!==d?(vt=(0,$.jsx)(Tp,{queuedMessages:d,onRemoveQueuedMessage:f}),t[70]=f,t[71]=d,t[72]=vt):vt=t[72];let yt=R?`Describe stories for Ralph to implement autonomously...`:Ze?`Describe what you want Tarsk to plan...`:ee?`Describe the image you want to generate...`:Je?`Dictate your message...`:`Ask Tarsk anything, # for files, / for commands & skills`,bt=Le&&Oe===`secondary`&&Ie&&`md:pr-12`,xt;t[73]===bt?xt=t[74]:(xt=U(J.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`,bt),t[73]=bt,t[74]=xt);let St;t[75]!==l||t[76]!==nt||t[77]!==pt||t[78]!==rt||t[79]!==S||t[80]!==Ae||t[81]!==yt||t[82]!==xt||t[83]!==Se?(St=(0,$.jsx)(`textarea`,{ref:Se,value:S,onChange:rt,onKeyDown:nt,onPaste:pt,onFocus:Ae,placeholder:yt,rows:1,className:xt,disabled:l}),t[75]=l,t[76]=nt,t[77]=pt,t[78]=rt,t[79]=S,t[80]=Ae,t[81]=yt,t[82]=xt,t[83]=Se,t[84]=St):St=t[84];let Ct=he?me:pe,wt=he?`//`:`/`,Tt;t[85]!==ye||t[86]!==we||t[87]!==at||t[88]!==ot||t[89]!==de||t[90]!==fe||t[91]!==_e||t[92]!==H||t[93]!==Ct||t[94]!==wt?(Tt=(0,$.jsx)(Tf,{visible:_e,commands:H,skills:Ct,skillReferencePrefix:wt,query:ye,selectedIndex:de,onSelectCommand:at,onSelectSkill:ot,onMouseEnterSuggestion:fe,containerRef:we}),t[85]=ye,t[86]=we,t[87]=at,t[88]=ot,t[89]=de,t[90]=fe,t[91]=_e,t[92]=H,t[93]=Ct,t[94]=wt,t[95]=Tt):Tt=t[95];let Et;t[96]!==st||t[97]!==it||t[98]!==de||t[99]!==fe||t[100]!==se||t[101]!==le||t[102]!==Ce?(Et=(0,$.jsx)(Gf,{showSuggestions:se,fileSuggestions:st,suggestionQuery:le,selectedIndex:de,onSelectFile:it,onMouseEnterSuggestion:fe,containerRef:Ce}),t[96]=st,t[97]=it,t[98]=de,t[99]=fe,t[100]=se,t[101]=le,t[102]=Ce,t[103]=Et):Et=t[103];let Dt;t[104]!==P||t[105]!==M?.id||t[106]!==M?.name||t[107]!==M?.supportsImages||t[108]!==F?(Dt=P.length>0&&(0,$.jsxs)(`div`,{className:`px-4`,children:[(0,$.jsx)(jf,{attachments:P,onRemove:e=>F(t=>t.filter((t,n)=>n!==e))}),P.some(kp)&&M?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:U(J.compact,`mb-2 flex items-center gap-1.5 text-amber-500`),children:[(0,$.jsx)(Lt,{className:`h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[`Images are not supported by `,M?.name||M?.id]})]})]}),t[104]=P,t[105]=M?.id,t[106]=M?.name,t[107]=M?.supportsImages,t[108]=F,t[109]=Dt):Dt=t[109];let G;t[110]===xe?G=t[111]:(G=()=>xe.current?.click(),t[110]=xe,t[111]=G);let K;t[112]!==De||t[113]!==S||t[114]!==g||t[115]!==Oe||t[116]!==F||t[117]!==C||t[118]!==Te||t[119]!==Se?(K=()=>{let e=Te;if(!e)return;let t=S.trim();t&&c(e,t).then(t=>{g?.(t),C(``),F([]),De({type:Z.ClearChatInputDraft,threadId:Oe===`secondary`?`${e}:secondary`:e}),Se.current&&(Se.current.style.height=`auto`)}).catch(Op)},t[112]=De,t[113]=S,t[114]=g,t[115]=Oe,t[116]=F,t[117]=C,t[118]=Te,t[119]=Se,t[120]=K):K=t[120];let Ot;t[121]!==l||t[122]!==Ze||t[123]!==Qe||t[124]!==Ke||t[125]!==ee||t[126]!==Xe||t[127]!==R||t[128]!==Fe||t[129]!==te||t[130]!==B||t[131]!==G||t[132]!==K?(Ot=(0,$.jsx)(sp,{disabled:l,canAddTask:Ke,showModes:Xe,planMode:Ze,imageMode:ee,ralphMode:R,setPlanMode:Qe,setImageMode:te,setRalphMode:B,projectId:Fe,onFileAttach:G,onAddTask:K}),t[121]=l,t[122]=Ze,t[123]=Qe,t[124]=Ke,t[125]=ee,t[126]=Xe,t[127]=R,t[128]=Fe,t[129]=te,t[130]=B,t[131]=G,t[132]=K,t[133]=Ot):Ot=t[133];let kt=ee?ie:N,At;t[134]!==We||t[135]!==Ue||t[136]!==kt?(At=(0,$.jsx)($f,{availableModels:We,selectedModel:Ue,onModelSelect:kt}),t[134]=We,t[135]=Ue,t[136]=kt,t[137]=At):At=t[137];let jt;t[138]!==Ot||t[139]!==At?(jt=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Ot,At]}),t[138]=Ot,t[139]=At,t[140]=jt):jt=t[140];let Mt;t[141]!==Ze||t[142]!==Qe||t[143]!==ee||t[144]!==R||t[145]!==Fe||t[146]!==te||t[147]!==B?(Mt=(0,$.jsx)(op,{planMode:Ze,imageMode:ee,ralphMode:R,setPlanMode:Qe,setImageMode:te,setRalphMode:B,projectId:Fe}),t[141]=Ze,t[142]=Qe,t[143]=ee,t[144]=R,t[145]=Fe,t[146]=te,t[147]=B,t[148]=Mt):Mt=t[148];let Nt=Te??void 0,Pt;t[149]!==ke||t[150]!==Pe||t[151]!==Nt?(Pt=(0,$.jsx)(Uf,{threadId:Nt,conversationId:ke,messages:Pe}),t[149]=ke,t[150]=Pe,t[151]=Nt,t[152]=Pt):Pt=t[152];let Ft;t[153]!==P.length||t[154]!==qe||t[155]!==l||t[156]!==Ue||t[157]!==tt||t[158]!==Ke||t[159]!==_||t[160]!==a?(Ft=e=>{let{onClick:t,disabled:n,icon:r,label:i,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:u}=e;return(0,$.jsx)(Ep,{onSpeechClick:t,speechDisabled:n,icon:r,label:i,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:u,hasMessageText:Ke,setIsVoiceActive:Ye,isStreaming:_,disabled:l,canSubmitMessage:qe,attachmentsLength:P.length,effectiveModel:Ue,onStop:a,onSend:tt})},t[153]=P.length,t[154]=qe,t[155]=l,t[156]=Ue,t[157]=tt,t[158]=Ke,t[159]=_,t[160]=a,t[161]=Ft):Ft=t[161];let It;t[162]!==dt||t[163]!==lt||t[164]!==Ft?(It=(0,$.jsx)(wp,{onTranscript:dt,onVoiceSessionStart:lt,children:Ft}),t[162]=dt,t[163]=lt,t[164]=Ft,t[165]=It):It=t[165];let Rt;t[166]!==Mt||t[167]!==Pt||t[168]!==It?(Rt=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[Mt,Pt,It]}),t[166]=Mt,t[167]=Pt,t[168]=It,t[169]=Rt):Rt=t[169];let zt;t[170]!==jt||t[171]!==Rt?(zt=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[jt,Rt]}),t[170]=jt,t[171]=Rt,t[172]=zt):zt=t[172];let Bt;t[173]!==gt||t[174]!==_t||t[175]!==vt||t[176]!==St||t[177]!==Tt||t[178]!==Et||t[179]!==Dt||t[180]!==zt?(Bt=(0,$.jsxs)(`div`,{className:gt,children:[_t,vt,St,Tt,Et,Dt,zt]}),t[173]=gt,t[174]=_t,t[175]=vt,t[176]=St,t[177]=Tt,t[178]=Et,t[179]=Dt,t[180]=zt,t[181]=Bt):Bt=t[181];let Vt;t[182]!==l||t[183]!==ze||t[184]!==Ie||t[185]!==Oe||t[186]!==Le?(Vt=Le&&Oe===`primary`&&!Ie&&(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{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)(o,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Open dual chat`})]})}),(0,$.jsx)(z,{children:`Open dual chat`})]}),t[182]=l,t[183]=ze,t[184]=Ie,t[185]=Oe,t[186]=Le,t[187]=Vt):Vt=t[187];let Ht;t[188]!==Bt||t[189]!==Vt?(Ht=(0,$.jsxs)(`div`,{className:`relative flex min-w-0 items-center gap-1`,children:[Bt,Vt]}),t[188]=Bt,t[189]=Vt,t[190]=Ht):Ht=t[190];let Ut;t[191]===F?Ut=t[192]:(Ut=e=>Wf(e,e=>F(t=>[...t,...e])),t[191]=F,t[192]=Ut);let Wt;t[193]!==xe||t[194]!==Ut?(Wt=(0,$.jsx)(`input`,{ref:xe,type:`file`,multiple:!0,className:`hidden`,onChange:Ut}),t[193]=xe,t[194]=Ut,t[195]=Wt):Wt=t[195];let Gt;return t[196]!==mt||t[197]!==Ht||t[198]!==Wt?(Gt=(0,$.jsxs)(`div`,{className:mt,children:[Ht,Wt]}),t[196]=mt,t[197]=Ht,t[198]=Wt,t[199]=Gt):Gt=t[199],Gt}function Op(e){console.error(`Failed to create user task:`,e)}function kp(e){return e.mimeType.startsWith(`image/`)}function Ap(e){return e.type.startsWith(`image/`)}function jp(){}function Mp(){}function Np(e){return e.sender===`agent`}function Pp(e){return e.selectedProjectId}function Fp(e){return e.secondaryMessages}function Ip(e){return e.messages}var Lp=ri(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}),Rp=function(e){let t=(0,X.c)(2),{completedCount:n,totalCount:r}=e,i=Hp*(1-(r>0?n/r:0)),a=zp/2,o;return t[0]===i?o=t[1]:(o=(0,$.jsx)(Lp,{v0:zp,v1:zp,v2:`0 0 ${zp} ${zp}`,v3:a,v4:a,v5:Vp,v6:Bp,v7:a,v8:a,v9:Vp,v10:Bp,v11:Hp,v12:i,v13:`rotate(-90 ${a} ${a})`}),t[0]=i,t[1]=o),o},zp=40,Bp=4,Vp=10,Hp=2*Math.PI*Vp;function Up(e){let t=(0,X.c)(13),{todos:n}=e,r;t[0]===n?r=t[1]:(r=n.filter(Gp),t[0]=n,t[1]=r);let i=r.length,a;t[2]===n.length?a=t[3]:(a=n.length===0&&(0,$.jsx)(`p`,{className:J.compact,children:`No todo items.`}),t[2]=n.length,t[3]=a);let o;t[4]===n?o=t[5]:(o=n.map(Wp),t[4]=n,t[5]=o);let s;t[6]!==i||t[7]!==n.length?(s=n.length>0&&(0,$.jsxs)(`p`,{className:U(J.compact,`pt-1`),children:[i,`/`,n.length,` completed`]}),t[6]=i,t[7]=n.length,t[8]=s):s=t[8];let c;return t[9]!==a||t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`space-y-1`,children:[a,o,s]}),t[9]=a,t[10]=o,t[11]=s,t[12]=c):c=t[12],c}function Wp(e){return(0,$.jsxs)(`div`,{className:U(J.caption,`flex items-start gap-2`),children:[e.status===`done`?(0,$.jsx)(Ge,{className:`h-4 w-4 shrink-0 mt-0.5 text-brand`}):e.status===`working`?(0,$.jsx)(re,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(mn,{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 Gp(e){return e.status===`done`}function Kp(e){let t=(0,X.c)(43),{layout:n}=e,r=n===void 0?`bar`:n,{todos:i}=(0,Y.useContext)(Ul),[a,o]=(0,Y.useState)(!1),s;t[0]===i?s=t[1]:(s=i.filter(qp),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)(Rp,{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)(V,{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)(En,{children:(0,$.jsx)(Zt,{children:`Agent Todos`})}),t[11]=l):l=t[11];let d;t[12]===i?d=t[13]:(d=(0,$.jsxs)(Ce,{className:`max-w-md`,children:[l,(0,$.jsx)(Up,{todos:i})]}),t[12]=i,t[13]=d);let f;t[14]!==a||t[15]!==d?(f=(0,$.jsx)(Ke,{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)(Rp,{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)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{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)(z,{children:u}),t[29]=u,t[30]=h);let g;t[31]!==m||t[32]!==h?(g=(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{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)(En,{children:(0,$.jsx)(Zt,{children:`Agent Todos`})}),t[34]=_):_=t[34];let v;t[35]===i?v=t[36]:(v=(0,$.jsxs)(Ce,{className:`max-w-md`,children:[_,(0,$.jsx)(Up,{todos:i})]}),t[35]=i,t[36]=v);let y;t[37]!==a||t[38]!==v?(y=(0,$.jsx)(Ke,{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 qp(e){return e.status===`done`}function Jp(e){let t=(0,X.c)(34),{tasks:n,disabled:r,onSelectTask:i,onTogglePinned:a,onRemoveTask:o,layout:s}=e,c=r===void 0?!1:r,l=s===void 0?`bar`:s,[u,d]=(0,Y.useState)(!1),f=n.length,p=`${f} ${f===1?`Task`:`Tasks`}`;if(f===0)return null;let m;t[0]===i?m=t[1]:(m=function(e){i(e),d(!1)},t[0]=i,t[1]=m);let h=m,g;t[2]!==o||t[3]!==f?(g=function(e){o(e),f===1&&d(!1)},t[2]=o,t[3]=f,t[4]=g):g=t[4];let _=g,v;t[5]===a?v=t[6]:(v=function(e){a(e)},t[5]=a,t[6]=v);let y=v,b=l===`menu`?`ghost`:`outline`,x=l===`bar`&&`bg-background`,S=l===`menu`&&`w-full justify-start`,C;t[7]!==x||t[8]!==S?(C=U(`gap-2`,x,S),t[7]=x,t[8]=S,t[9]=C):C=t[9];let w;t[10]===p?w=t[11]:(w=(0,$.jsx)(`span`,{children:p}),t[10]=p,t[11]=w);let T;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Se,{className:`h-4 w-4 shrink-0`}),t[12]=T):T=t[12];let E;t[13]!==c||t[14]!==w||t[15]!==b||t[16]!==C?(E=(0,$.jsx)(_l,{asChild:!0,children:(0,$.jsxs)(V,{variant:b,size:`sm`,className:C,disabled:c,children:[w,T]})}),t[13]=c,t[14]=w,t[15]=b,t[16]=C,t[17]=E):E=t[17];let D;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(`div`,{className:U(J.compact,J.label,`px-2 pb-1 pt-1 text-muted-foreground`),children:`Tasks`}),t[18]=D):D=t[18];let O;if(t[19]!==_||t[20]!==h||t[21]!==y||t[22]!==n){let e;t[24]!==_||t[25]!==h||t[26]!==y?(e=e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-transparent px-2 py-2 hover:bg-accent`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-start gap-2 text-left`,onClick:()=>h(e),children:[(0,$.jsx)(Pe,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:U(J.body,`line-clamp-3 text-foreground`),children:e.content})]}),(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{type:`button`,variant:`ghost`,size:`icon`,className:U(`h-7 w-7 shrink-0`,e.pinned&&`text-primary hover:text-primary`),onClick:()=>y(e.id),children:[(0,$.jsx)(_t,{className:U(`h-4 w-4`,e.pinned&&`fill-current`)}),(0,$.jsx)(`span`,{className:`sr-only`,children:e.pinned?`Unpin task`:`Pin task`})]})}),(0,$.jsx)(z,{children:e.pinned?`Unpin task`:`Pin task`})]}),(0,$.jsxs)(V,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:()=>_(e.id),children:[(0,$.jsx)(zn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove task`})]})]},e.id),t[24]=_,t[25]=h,t[26]=y,t[27]=e):e=t[27],O=n.map(e),t[19]=_,t[20]=h,t[21]=y,t[22]=n,t[23]=O}else O=t[23];let A;t[28]===O?A=t[29]:(A=(0,$.jsx)(vl,{align:`start`,className:`w-96 p-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[D,O]})}),t[28]=O,t[29]=A);let j;return t[30]!==u||t[31]!==E||t[32]!==A?(j=(0,$.jsx)(ce,{children:(0,$.jsxs)(gl,{open:u,onOpenChange:d,children:[E,A]})}),t[30]=u,t[31]=E,t[32]=A,t[33]=j):j=t[33],j}function Yp(e){let t=(0,X.c)(23),n=Mr(),r;t[0]===e?r=t[1]:(r=Zd.userTasks(e),t[0]=e,t[1]=r);let i;t[2]===e?i=t[3]:(i=()=>ze(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=qr(o),c;t[8]!==n||t[9]!==e?(c=t=>{e&&n.setQueryData(Zd.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:Zd.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 Xp(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 Zp=(0,Y.createContext)(void 0);function Qp(e){let t=(0,X.c)(33),{children:n}=e,r=za(),{paneId:i}=Ld(),a=Q(nm),o=Q(tm),s=Q(em),c=Q($p),{toast:l}=no(),{userTasks:u,setUserTasks:d,isError:f}=Yp(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?Vi(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=Xp(o,a);await Ve(a,{title:e}),s&&r({type:Z.UpdateThreadTitle,projectId:s,threadId:a,title:e});let t=await St(a);r({type:Z.ClearMessages}),console.log(`New conversation started:`,t),setTimeout(()=>{(async()=>{try{let e=await xn(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 qn(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)(Zp.Provider,{value:E,children:n}),t[30]=n,t[31]=E,t[32]=D):D=t[32],D}function $p(e){return e.isCreatingProject}function em(e){return e.selectedProjectId}function tm(e){return e.projects}function nm(e){return e.selectedThreadId}function rm(){let e=(0,Y.useContext)(Zp);if(e===void 0)throw Error(`useChatInputToolbar must be used within a ChatInputToolbarProvider`);return e}var im=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)(Et,{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)(Et,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))};function am({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){return t?e.map(([e,t])=>(0,$.jsxs)(du,{children:[(0,$.jsx)(fu,{children:e}),(0,$.jsx)(pu,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,$.jsxs)(hu,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(Et,{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)(hu,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(Et,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))}function om({threadId:e,layout:t=`bar`}){let n=za(),{setTerminalNotification:r,setActiveMainTab:i}=hc(),{setDevServerUrl:a}=Cd(),[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 Ne(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(Td(t)){wd({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 Rt(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 Ct(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)(gl,{children:[(0,$.jsx)(_l,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(j,{className:`h-4 w-4 shrink-0`}),`Project Scripts`]})}),(0,$.jsx)(vl,{align:`start`,className:`w-56 p-1`,children:(0,$.jsx)(im,{workspaceEntries:m,hasMultipleWorkspaces:h,runningScripts:c,onScriptClick:g})})]}):(0,$.jsxs)(lu,{children:[(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(uu,{asChild:!0,children:(0,$.jsx)(V,{variant:`action`,size:`icon-md`,children:(0,$.jsx)(j,{})})})}),(0,$.jsx)(z,{children:`Project Scripts`})]})}),(0,$.jsx)(mu,{align:`end`,className:`min-w-[180px]`,children:(0,$.jsx)(am,{workspaceEntries:m,hasMultipleWorkspaces:h,runningScripts:c,onScriptClick:g})})]})}var sm=`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 cm({open:e,onOpenChange:t,projectId:n,commands:i,onRefresh:a}){let[o,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)([]),[h,g]=(0,Y.useState)(0),[_,v]=(0,Y.useState)(!1),y=(0,Y.useRef)(null),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 G(n);m(e.scripts),g(0),f(e.scripts.length>0)}catch(e){console.error(`Failed to load package scripts:`,e),to({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{v(!1)}},w=e=>{c(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),f(!1),m([]),y.current?.focus()},T=e=>{d&&(e.key===`ArrowDown`?(e.preventDefault(),g(e=>e<p.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),g(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),h<p.length&&w(p[h])):e.key===`Escape`&&(e.preventDefault(),f(!1),m([])))};(0,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 E=async e=>{try{await Mt(n,e),to({title:`Success`,description:`Command deleted`}),a()}catch{to({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(Ke,{open:e,onOpenChange:t,children:(0,$.jsxs)(Ce,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(En,{children:[(0,$.jsx)(Zt,{children:`Project Commands`}),(0,$.jsx)(s,{children:`Manage custom commands for this project.`})]}),(0,$.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:o?(0,$.jsxs)(`div`,{className:`p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(hn,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(Xe,{id:`name`,value:o.name,onChange:e=>c({...o,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,$.jsx)(hn,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Va,{ref:y,id:`commandLine`,value:o.commandLine,onChange:e=>c({...o,commandLine:e.target.value}),onKeyDown:T,placeholder:`e.g. npm test`,className:`font-mono text-base min-h-[100px] resize-none pr-10`}),(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{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)(On,{className:`h-4 w-4`})})}),(0,$.jsx)(z,{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:U(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),children:[(0,$.jsx)(On,{className:`h-3 w-3`}),`Available Scripts `,_&&`(loading...)`]}),p.length>0?(()=>{let e={};p.forEach(t=>{e[t.relativePath]||(e[t.relativePath]=[]),e[t.relativePath].push(t)});let t=Object.keys(e).sort(),n=0;return t.map(t=>{let r=e[t].sort((e,t)=>e.name.localeCompare(t.name));return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:U(J.dropdownGroupHeading,`px-3 py-1.5 text-muted-foreground/70 bg-muted/30`),children:t}),r.map(e=>{let t=n===h;return n++,(0,$.jsxs)(`button`,{type:`button`,className:U(`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:U(J.caption,`font-mono`),children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:U(J.caption,`px-3 py-4 text-center`),children:_?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(hn,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(Xe,{id:`relativeFolder`,value:o.relativeFolder??``,onChange:e=>c({...o,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,$.jsx)(`p`,{className:J.bodyMuted,children:`Folder path relative to project root where the command will be executed. Leave empty to run from project root.`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(hn,{children:`Icon`}),(0,$.jsx)(ce,{children:(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:sm.map(e=>{let t=Oe[e]||Ye;return(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{variant:o.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>c({...o,icon:e}),children:(0,$.jsx)(t,{className:`h-4 w-4`})})}),(0,$.jsx)(z,{children:e})]},e)})})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:[(0,$.jsx)(zn,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsxs)(V,{size:`sm`,onClick:async()=>{if(!o?.name||!o?.commandLine){to({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{u(!0),await tt(n,o),to({title:`Success`,description:`Command saved`}),c(null),a()}catch{to({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{u(!1)}},disabled:l,children:[(0,$.jsx)(tn,{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:[i.length===0&&(0,$.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No commands defined yet.`}),i.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)(Oe[e.icon]||r,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:J.label,children:e.name}),(0,$.jsx)(`span`,{className:U(J.caption,`line-clamp-1 font-mono`),children:e.commandLine})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(V,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors`,onClick:t=>{t.stopPropagation(),E(e.id)},children:(0,$.jsx)(Nt,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(V,{variant:`outline`,className:`w-full border-dashed`,onClick:x,children:[(0,$.jsx)(be,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function lm(e){let t=(0,X.c)(37),{layout:n}=e,i=n===void 0?`bar`:n,a=Q(fm),o=Q(dm),s=Q(um),c=za(),{terminalState:l,dispatch:u}=Ba(o),[d,f]=(0,Y.useState)(!1),p=l.isRunning||l.queuedCommand!==null,m,h,g,_,v;if(t[0]!==c||t[1]!==u||t[2]!==p||t[3]!==i||t[4]!==s||t[5]!==a||t[6]!==o||t[7]!==d){v=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[13]===a?e=t[14]:(e=e=>e.projectId===a,t[13]=a,t[14]=e),m=s.find(e)?.commands??[];let n;t[15]!==u||t[16]!==a||t[17]!==o?(n=e=>{!a||!o||u({type:Z.QueueTerminalCommand,command:e.commandLine,relativeFolder:e.relativeFolder})},t[15]=u,t[16]=a,t[17]=o,t[18]=n):n=t[18];let l=n,y;if(t[19]===c?y=t[20]:(y=async()=>{c({type:Z.ConfigUpdated})},t[19]=c,t[20]=y),h=y,!a){v=null;break bb0}if(i===`menu`){let e;t[21]!==l||t[22]!==p?(e=e=>{let t=Oe[e.icon]||r;return(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:U(`relative w-full justify-start gap-2`,p&&`text-primary`,p&&`before:absolute before:inset-[-1px] before:rounded-md before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`),onClick:()=>l({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:p,children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0`}),e.name]},e.id)},t[21]=l,t[22]=p,t[23]=e):e=t[23];let n,i;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>f(!0),n=(0,$.jsx)(Ie,{className:`h-4 w-4 shrink-0`}),t[24]=n,t[25]=i):(n=t[24],i=t[25]);let o=m.length===0?`Project Commands`:`Manage commands`,s;t[26]===o?s=t[27]:(s=(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:i,children:[n,o]}),t[26]=o,t[27]=s),v=(0,$.jsxs)($.Fragment,{children:[m.map(e),s,(0,$.jsx)(cm,{open:d,onOpenChange:f,projectId:a,commands:m,onRefresh:h})]});break bb0}g=`flex items-center gap-1`,_=m.length===0?(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{variant:`action`,size:`icon-md`,onClick:()=>f(!0),children:(0,$.jsx)(Ie,{})})}),(0,$.jsx)(z,{children:`Manage commands`})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(ce,{children:[m.map(e=>{let t=Oe[e.icon]||r;return(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{variant:`action`,size:`icon-md`,className:U(`relative`,p&&`bg-primary/10 text-primary`,p&&`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`),onClick:()=>l({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:p,children:(0,$.jsx)(t,{})})}),(0,$.jsx)(z,{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)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>f(!0),children:(0,$.jsx)(Ie,{})})}),(0,$.jsx)(z,{children:`Manage commands`})]})]})})}t[0]=c,t[1]=u,t[2]=p,t[3]=i,t[4]=s,t[5]=a,t[6]=o,t[7]=d,t[8]=m,t[9]=h,t[10]=g,t[11]=_,t[12]=v}else m=t[8],h=t[9],g=t[10],_=t[11],v=t[12];if(v!==Symbol.for(`react.early_return_sentinel`))return v;let y;t[28]!==m||t[29]!==h||t[30]!==a||t[31]!==d?(y=(0,$.jsx)(cm,{open:d,onOpenChange:f,projectId:a,commands:m,onRefresh:h}),t[28]=m,t[29]=h,t[30]=a,t[31]=d,t[32]=y):y=t[32];let b;return t[33]!==g||t[34]!==_||t[35]!==y?(b=(0,$.jsxs)(`div`,{className:g,children:[_,y]}),t[33]=g,t[34]=_,t[35]=y,t[36]=b):b=t[36],b}function um(e){return e.projects}function dm(e){return e.selectedThreadId}function fm(e){return e.selectedProjectId}var pm=`VS Code`;function mm(e){return e||Kn(pm)}var hm={"VS Code":`vscode`,Antigravity:`antigravity`,Cursor:`cursor`,"Devin Desktop":`devin`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function gm({projectId:e,threadId:t,openWith:n,layout:r=`bar`}){let[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)([]),[c,l]=(0,Y.useState)(()=>mm(n)),[u,d]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{let e=await vt();s(e);let t=mm(n);e.includes(t)?l(t):e.length>0&&l(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),s([pm])}finally{d(!1)}})()},[]),(0,Y.useEffect)(()=>{if(n&&o.includes(n)){l(n);return}let e=Kn(pm);!n&&o.includes(e)&&l(e)},[n,o]);async function f(t){l(t),Bt(t),await g(e,t)}let p=async n=>{try{a(!0),await f(n),t?await dt(t,n):await Cn(e,n),to({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}to({title:`Error`,description:t,variant:`destructive`})}finally{a(!1)}};async function m(e){try{await f(e)}catch(t){console.error(`Failed to save preferred IDE (${e}):`,t),to({title:`Error`,description:`Failed to save IDE preference`,variant:`destructive`})}}let h=async()=>{await p(c)};return u?(0,$.jsx)(V,{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)(V,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,disabled:i,onClick:()=>{h()},children:[(0,$.jsx)(`img`,{src:`/ide/${hm[c]||hm[pm]}.svg`,alt:c,className:`h-4 w-4 shrink-0`}),`Open in `,c]}),(0,$.jsxs)(gl,{children:[(0,$.jsx)(_l,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(On,{className:`h-4 w-4 shrink-0`}),`Change IDE`]})}),(0,$.jsx)(vl,{align:`start`,className:`w-56 p-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>{m(e)},disabled:i,children:[(0,$.jsx)(`img`,{src:`/ide/${hm[e]||hm[pm]}.svg`,alt:e,className:`h-4 w-4 shrink-0`}),e]},e))})]})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsx)(V,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:i,onClick:h,children:(0,$.jsx)(`img`,{src:`/ide/${hm[c]||hm[pm]}.svg`,alt:c,className:`h-4 w-4`})})}),(0,$.jsx)(z,{children:`Open in ${c}`})]}),(0,$.jsxs)(lu,{children:[(0,$.jsx)(uu,{asChild:!0,children:(0,$.jsx)(V,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:i,children:(0,$.jsx)(On,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(mu,{align:`end`,children:o.map(e=>(0,$.jsxs)(hu,{onClick:()=>void m(e),disabled:i,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${hm[e]||hm[pm]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}var _m=ri(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`]}),vm=ri(e=>e.v0,{name:`RunStopButton_2`,portals:[`v0`]}),ym=ri(e=>(0,$.jsx)(`slot`,{children:e.v0}),{name:`RunStopButton_3`,portals:[`v0`]}),bm=function({projectId:e,runCommand:t,large:n,layout:i=`bar`}){let{dispatch:a}=Ba(Q(e=>e.selectedThreadId)),{setDevServerUrl:o,setDevServerRunning:s,setDevServerLoading:c}=Cd(),{startServer:l}=Ed(),{isRunning:u,isLoading:d}=kd(e),f=(0,Y.useRef)(!1),p=()=>{l({projectId:e,runCommand:t||``})},m=async()=>{f.current=!0,c(!0);try{await me(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}}),to({title:`Error`,description:t,variant:`destructive`})}finally{c(!1)}},h=!!t,g=d?`Starting...`:u?`Stop dev server`:`Start dev server`;return n?(0,$.jsx)(_m,{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)(Et,{className:`h-10 w-10 animate-spin`}):u?(0,$.jsx)(I,{className:`h-10 w-10 fill-current`}):(0,$.jsx)(r,{className:`h-10 w-10 fill-current group-hover:text-foreground transition-colors`}),v4:U(J.body,`group-hover:text-foreground transition-colors`),v5:g}):i===`menu`?(0,$.jsx)(vm,{v0:(0,$.jsxs)(V,{variant:`ghost`,size:`sm`,className:U(`w-full justify-start gap-2`,u&&`text-orange-500`),onClick:u?m:p,disabled:d||!u&&!h,children:[d?(0,$.jsx)(Et,{className:`h-4 w-4 shrink-0 animate-spin`}):u?(0,$.jsx)(I,{className:`h-4 w-4 shrink-0 fill-current`}):(0,$.jsx)(r,{className:`h-4 w-4 shrink-0`}),g]})}):(0,$.jsx)(ym,{v0:(0,$.jsx)(ce,{children:(0,$.jsxs)(k,{children:[(0,$.jsx)(Ee,{asChild:!0,children:(0,$.jsxs)(V,{variant:`ghost`,size:`icon`,className:U(`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)(Et,{className:`h-4 w-4 animate-spin`}):u?(0,$.jsx)(I,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(r,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:u?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(z,{children:u?`Stop dev server`:h?`Start dev server: ${t}`:`Set run command in project settings`})]})})})};function xm(e){let t=(0,X.c)(31),{currentBranch:n,availableBranches:r,isLoadingBranches:i,isCheckingOut:a,onLoadBranches:o,onCheckoutBranch:s,onCreateBranch:c,onRenameBranch:l}=e,u;t[0]===o?u=t[1]:(u=e=>{e&&o()},t[0]=o,t[1]=u);let d,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=U(J.compact,`h-7 px-2 bg-background gap-1.5 border-none text-muted-foreground hover:bg-accent hover:text-accent-foreground`),f=(0,$.jsx)(he,{className:`h-3.5 w-3.5 shrink-0`}),t[2]=d,t[3]=f):(d=t[2],f=t[3]);let p=n||`Unknown`,m;t[4]===p?m=t[5]:(m=(0,$.jsx)(uu,{asChild:!0,children:(0,$.jsxs)(V,{variant:`outline`,size:`sm`,className:d,children:[f,p]})}),t[4]=p,t[5]=m);let h,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(be,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),g=(0,$.jsx)(`span`,{children:`Create branch`}),t[6]=h,t[7]=g):(h=t[6],g=t[7]);let _;t[8]!==a||t[9]!==c?(_=(0,$.jsxs)(hu,{onClick:c,disabled:a,children:[h,g]}),t[8]=a,t[9]=c,t[10]=_):_=t[10];let v,y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)($t,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),v=(0,$.jsx)(`span`,{children:`Rename branch`}),t[11]=v,t[12]=y):(v=t[11],y=t[12]);let b;t[13]!==a||t[14]!==l?(b=(0,$.jsxs)(hu,{onClick:l,disabled:a,children:[y,v]}),t[13]=a,t[14]=l,t[15]=b):b=t[15];let x;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(yu,{}),t[16]=x):x=t[16];let S;t[17]!==r||t[18]!==n||t[19]!==a||t[20]!==i||t[21]!==s?(S=i?(0,$.jsxs)(`div`,{className:U(J.compact,`px-2 py-1.5 text-muted-foreground flex items-center gap-2`),children:[(0,$.jsx)(Et,{className:`h-3 w-3 animate-spin`}),`Loading branches...`]}):r.length===0?(0,$.jsx)(`div`,{className:U(J.compact,`px-2 py-1.5 text-muted-foreground`),children:`No branches found`}):(0,$.jsx)(`div`,{className:`max-h-[300px] overflow-y-auto`,children:r.map(e=>(0,$.jsxs)(hu,{disabled:e===n||a,onClick:()=>s(e),children:[(0,$.jsx)(he,{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:U(J.compact,`ml-auto text-muted-foreground`),children:`current`})]},e))}),t[17]=r,t[18]=n,t[19]=a,t[20]=i,t[21]=s,t[22]=S):S=t[22];let C;t[23]!==b||t[24]!==S||t[25]!==_?(C=(0,$.jsxs)(mu,{align:`start`,children:[_,b,x,S]}),t[23]=b,t[24]=S,t[25]=_,t[26]=C):C=t[26];let w;return t[27]!==u||t[28]!==C||t[29]!==m?(w=(0,$.jsxs)(lu,{onOpenChange:u,children:[m,C]}),t[27]=u,t[28]=C,t[29]=m,t[30]=w):w=t[30],w}function Sm(){return{autoGenerateCommitMessage:dn(),autoGeneratePRInfo:Jt(),privateRepositoryDefault:W(),newChatOnNewBranch:Ln()}}function Cm(e){e.autoGenerateCommitMessage!==void 0&&Me(e.autoGenerateCommitMessage),e.autoGeneratePRInfo!==void 0&&E(e.autoGeneratePRInfo),e.privateRepositoryDefault!==void 0&&f(e.privateRepositoryDefault),e.newChatOnNewBranch!==void 0&&ge(e.newChatOnNewBranch)}var wm=(0,Y.lazy)(()=>$r(()=>import(`./merged-pr-dialog-C5vgSXwq.js`).then(e=>({default:e.MergedPRDialog})),__vite__mapDeps([2,3,1,4,5])));function Tm({threadId:e,projectId:t}){let n=za(),r=Q(e=>e.projects.find(e=>e.projectId===t)),i=ac(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(()=>Sm());(0,Y.useEffect)(()=>{Cm(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 Ue(e);if(u.newChatOnNewBranch){let r=`New Chat`;await Ve(e,{title:r}),n({type:Z.UpdateThreadTitle,projectId:t,threadId:e,title:r}),await St(e),n({type:Z.ClearMessages}),setTimeout(()=>{(async()=>{try{let t=await xn(e);n({type:Z.SetMessages,messages:t.messages})}catch(e){console.error(`Failed to refresh chat history after starting new chat:`,e)}})()},0)}Qt();let a=await C();n({type:Z.SetProjects,projects:a.projects}),to({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),to({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)(wm,{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 Em(e){let t=(0,X.c)(35),{open:n,onOpenChange:r,branchName:i,onBranchNameChange:a,isLoading:o,onCreateBranch:c}=e,l;t[0]!==i||t[1]!==o||t[2]!==c?(l=e=>{e.key===`Enter`&&i.trim()&&!o&&c()},t[0]=i,t[1]=o,t[2]=c,t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsxs)(En,{children:[(0,$.jsx)(Zt,{children:`New Branch`}),(0,$.jsx)(s,{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)(hn,{htmlFor:`branch-name`,children:`Branch Name`}),t[5]=f):f=t[5];let p;t[6]===a?p=t[7]:(p=e=>a(e.target.value),t[6]=a,t[7]=p);let m;t[8]!==i||t[9]!==u||t[10]!==o||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)(Xe,{id:`branch-name`,placeholder:`e.g. feature/my-feature`,value:i,onChange:p,onKeyDown:u,disabled:o,autoFocus:!0})]})}),t[8]=i,t[9]=u,t[10]=o,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]!==o||t[16]!==h?(g=(0,$.jsx)(V,{variant:`outline`,onClick:h,disabled:o,children:`Cancel`}),t[15]=o,t[16]=h,t[17]=g):g=t[17];let _;t[18]!==i||t[19]!==o?(_=o||!i.trim(),t[18]=i,t[19]=o,t[20]=_):_=t[20];let v=o?`Creating...`:`Create Branch`,y;t[21]!==c||t[22]!==_||t[23]!==v?(y=(0,$.jsx)(V,{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)(gt,{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)(Ce,{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)(Ke,{open:n,onOpenChange:r,children:x}),t[31]=r,t[32]=n,t[33]=x,t[34]=S):S=t[34],S}function Dm(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 Om(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,currentBranch:i,availableBranches:a,branchName:o,onBranchNameChange:c,isLoading:l,onRenameBranch:u}=e,d;t[0]===a?d=t[1]:(d=new Set(a),t[0]=a,t[1]=d);let f=d,p,m;t[2]!==o||t[3]!==i||t[4]!==f?(m=o.trim(),p=Dm(m,i,f),t[2]=o,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)(Zt,{children:`Rename Branch`}),t[10]=y):y=t[10];let b;t[11]===i?b=t[12]:(b=(0,$.jsxs)(En,{children:[y,(0,$.jsxs)(s,{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)(hn,{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]!==o||t[17]!==v||t[18]!==l||t[19]!==S?(C=(0,$.jsx)(Xe,{id:`rename-branch-name`,placeholder:`e.g. feature/my-feature`,value:o,onChange:S,onKeyDown:v,disabled:l,autoFocus:!0,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1}),t[16]=o,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)(V,{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)(V,{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)(gt,{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)(Ce,{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)(Ke,{open:n,onOpenChange:r,children:j}),t[43]=r,t[44]=n,t[45]=j,t[46]=M):M=t[46],M}var km=`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 Am(){return km[Math.floor(Math.random()*km.length)]??`branch`}function jm(){let e=Am(),t=Am();for(;t===e;)t=Am();return`${e}-${t}`}function Mm(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=ac();(0,Y.useEffect)(()=>{if(!s){u(``);return}u(jm())},[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 gn(e)).branches)}catch{n([])}finally{i(!1)}}}async function C(t){if(!(!e||t===x.currentBranch)){o(!0);try{await F(e,t),await x.fetchUnifiedStatus(!0),to({title:`Switched to branch "${t}"`})}catch(e){to({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 Ue(e,y,l);c(!1),await S(),await x.fetchUnifiedStatus(!0),to({title:`Branch created`,description:`Created branch "${t.branchName}" from ${y}`})}catch(e){to({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 qe(e,h);m(!1),await S(),await x.fetchUnifiedStatus(!0),to({title:`Branch renamed`,description:`Renamed branch to "${t.branchName}"`})}catch(e){to({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 Nm=(0,Y.lazy)(()=>$r(()=>import(`./git-ops-button-Cj3j4bvy.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([6,1,7,8,3])));function Pm(e){return e===`menu`?`w-full justify-start gap-2`:`gap-2`}function Fm(e){let t=(0,X.c)(4),{threadId:n,projectId:r,messages:i,userTasks:a}=e,{hasChanges:o}=ac(),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 Im(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)(be,{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)(V,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:r,children:[i,`New Chat`]})}),t[1]=r,t[2]=a),a}function Lm(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}=hc(),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}=Fm(h),{changedFilesCount:y}=ac(),b;t[5]===p?b=t[6]:(b=Pm(p),t[5]=p,t[6]=b);let x=b,{currentBranch:S,availableBranches:C,isLoadingBranches:w,isCheckingOut:E,loadBranches:D,checkoutBranch:O,isRenameDialogOpen:k,setIsRenameDialogOpen:A,renameBranchName:j,setRenameBranchName:M,isRenamingBranch:N,renameBranch:P,openRenameBranchDialog:F,isCreateDialogOpen:I,setIsCreateDialogOpen:L,newBranchName:R,setNewBranchName:z,isCreatingBranch:B,createBranch:ee}=Mm(n),te=Q(Rm),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,ae=g||_||a.length>0||!!(n&&r);if(!v)return null;let oe=p===`bar`&&`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,se=p===`menu`&&`flex flex-col items-stretch gap-1 p-1 min-w-[220px]`,ce;t[12]!==oe||t[13]!==se?(ce=U(oe,se),t[12]=oe,t[13]=se,t[14]=ce):ce=t[14];let le=p===`bar`?!0:void 0,ue;t[15]!==g||t[16]!==p||t[17]!==c||t[18]!==x?(ue=g&&(0,$.jsxs)(V,{variant:p===`menu`?`ghost`:`outline`,size:`sm`,className:x,onClick:c,children:[(0,$.jsx)(be,{className:`h-4 w-4 shrink-0`}),`New Chat`]}),t[15]=g,t[16]=p,t[17]=c,t[18]=x,t[19]=ue):ue=t[19];let de;t[20]!==y||t[21]!==_||t[22]!==p||t[23]!==m||t[24]!==x?(de=_&&(0,$.jsxs)(V,{variant:p===`menu`?`ghost`:`outline`,size:`sm`,className:x,onClick:()=>m(`review`),children:[(0,$.jsx)(T,{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]=de):de=t[25];let fe;t[26]!==o||t[27]!==s||t[28]!==p||t[29]!==d||t[30]!==l||t[31]!==u||t[32]!==n||t[33]!==a?(fe=a.length>0&&(0,$.jsx)(Jp,{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]=fe):fe=t[34];let H;t[35]!==p||t[36]!==r||t[37]!==n?(H=n&&r&&(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Nm,{projectId:r,threadId:n,layout:p},n)}),t[35]=p,t[36]=r,t[37]=n,t[38]=H):H=t[38];let pe;t[39]!==g||t[40]!==p?(pe=g&&(0,$.jsx)(Kp,{layout:p}),t[39]=g,t[40]=p,t[41]=pe):pe=t[41];let me;t[42]!==C||t[43]!==O||t[44]!==S||t[45]!==E||t[46]!==w||t[47]!==p||t[48]!==D||t[49]!==F||t[50]!==L?(me=p===`bar`&&(0,$.jsx)(xm,{currentBranch:S,availableBranches:C,isLoadingBranches:w,isCheckingOut:E,onLoadBranches:D,onCheckoutBranch:O,onCreateBranch:()=>L(!0),onRenameBranch:F}),t[42]=C,t[43]=O,t[44]=S,t[45]=E,t[46]=w,t[47]=p,t[48]=D,t[49]=F,t[50]=L,t[51]=me):me=t[51];let he;t[52]!==ae||t[53]!==ie?(he=ie&&ae&&(0,$.jsx)(yu,{className:`my-1`}),t[52]=ae,t[53]=ie,t[54]=he):he=t[54];let ge;t[55]!==r||t[56]!==re?.openWith||t[57]!==re?.runCommand||t[58]!==ie||t[59]!==n?(ge=ie&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(bm,{projectId:r,runCommand:re?.runCommand,layout:`menu`}),(0,$.jsx)(om,{threadId:n,layout:`menu`}),(0,$.jsx)(lm,{layout:`menu`}),(0,$.jsx)(gm,{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]=ge):ge=t[60];let _e;t[61]!==de||t[62]!==fe||t[63]!==H||t[64]!==pe||t[65]!==me||t[66]!==he||t[67]!==ge||t[68]!==ce||t[69]!==le||t[70]!==ue?(_e=(0,$.jsxs)(`div`,{className:ce,"data-chat-toolbar":le,children:[ue,de,fe,H,pe,me,he,ge]}),t[61]=de,t[62]=fe,t[63]=H,t[64]=pe,t[65]=me,t[66]=he,t[67]=ge,t[68]=ce,t[69]=le,t[70]=ue,t[71]=_e):_e=t[71];let ve;t[72]!==ee||t[73]!==I||t[74]!==B||t[75]!==R||t[76]!==L||t[77]!==z?(ve=(0,$.jsx)(Em,{open:I,onOpenChange:L,branchName:R,onBranchNameChange:z,isLoading:B,onCreateBranch:ee}),t[72]=ee,t[73]=I,t[74]=B,t[75]=R,t[76]=L,t[77]=z,t[78]=ve):ve=t[78];let ye;t[79]!==C||t[80]!==S||t[81]!==k||t[82]!==N||t[83]!==P||t[84]!==j||t[85]!==A||t[86]!==M?(ye=(0,$.jsx)(Om,{open:k,onOpenChange:A,currentBranch:S,availableBranches:C,branchName:j,onBranchNameChange:M,isLoading:N,onRenameBranch:P}),t[79]=C,t[80]=S,t[81]=k,t[82]=N,t[83]=P,t[84]=j,t[85]=A,t[86]=M,t[87]=ye):ye=t[87];let xe;return t[88]!==_e||t[89]!==ve||t[90]!==ye?(xe=(0,$.jsxs)($.Fragment,{children:[_e,ve,ye]}),t[88]=_e,t[89]=ve,t[90]=ye,t[91]=xe):xe=t[91],xe}function Rm(e){return e.projects}function zm(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}=Fm(o);if(a===`newChatOnly`){let e;return t[5]!==s||t[6]!==i?(e=(0,$.jsx)(Im,{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)(Lm,{...e}),t[8]=e,t[9]=c),c}function Bm(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(zm,{...e}),t[0]=e,t[1]=n),n}function Vm(){let e=(0,X.c)(21),t=Q(Wm),n=Q(Um),r=Q(Hm),{userTasks:i,handleNewChat:a,handleSelectUserTask:o,handleRemoveUserTask:s,toggleUserTaskPinned:c,effectiveIsStreaming:l,isCreatingProject:u}=rm(),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}=Fm(d);if(!t||!f)return null;let p;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(uu,{asChild:!0,children:(0,$.jsxs)(V,{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)(un,{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)(lu,{children:[p,(0,$.jsx)(mu,{align:`end`,className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(Lm,{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 Hm(e){return e.messages}function Um(e){return e.selectedProjectId}function Wm(e){return e.selectedThreadId}function Gm(e){let t=(0,X.c)(6),{threadId:n,children:r}=e,i=Q(Km),a;t[0]!==i||t[1]!==n?(a=n&&i?(0,$.jsx)(Tm,{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 Km(e){return e.selectedProjectId}function qm(e){let t=(0,X.c)(6),{threadId:n,children:r}=e,i;t[0]!==r||t[1]!==n?(i=(0,$.jsx)(Gm,{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)(ic,{threadId:n,children:i}),t[3]=i,t[4]=n,t[5]=a):a=t[5],a}function Jm(e){let t=(0,X.c)(10),{open:n,onClose:r}=e,i=rr(),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)(si,{children:[(0,$.jsx)(ni,{children:`Balance empty`}),(0,$.jsx)(ii,{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)(li,{children:[o,(0,$.jsx)(ai,{children:(0,$.jsx)(V,{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)(oi,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}var Ym=`tarsk-browser-tool-request`,Xm=`tarsk-ask-user-prompt`,Zm=new Set,Qm=new Set;function $m(e){Dn()&&window.dispatchEvent(new CustomEvent(Ym,{detail:e}))}function eh(e,t,n){!Dn()||Zm.has(e)||t.action&&(Zm.add(e),$m({toolCallId:e,input:t,threadId:n}))}function th(e,t){Qm.has(e)||(Qm.add(e),window.dispatchEvent(new CustomEvent(Xm,{detail:{toolCallId:e,threadId:t}})))}function nh(){return Dn()?`views://public/browser-preview-rpc.js`:`${We()}/browser-preview-rpc.js`}async function rh(e,t){await ln(e,t)}async function ih(e,t){await yt(e,t)}var ah=new Set,oh=new Map,sh=5e3;function ch(e){ah.add(e);let t=oh.get(e);t&&clearTimeout(t),oh.set(e,setTimeout(()=>{ah.delete(e),oh.delete(e)},sh))}function lh(e){return ah.has(e)}function uh(e){return e.filter(e=>!ah.has(e))}var dh;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})(dh||={});var fh=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},ph=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,mh=e=>{let t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},i=()=>t===null?ph(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 fh(`"${e}" plugin is not implemented on ${c}`,dh.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 fh(`"${e}.${t}()" is not implemented on ${c}`,dh.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=fh,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},hh=(e=>e.Capacitor=mh(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),gh=hh.registerPlugin,_h=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 hh.Exception(e,dh.Unimplemented)}unavailable(e=`not available`){return new hh.Exception(e,dh.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)}))}},vh=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),yh=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),bh=class extends _h{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=yh(n).trim(),r=yh(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=vh(e.key),n=vh(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)}}};gh(`CapacitorCookies`,{web:()=>new bh});var xh=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)}),Sh=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},Ch=(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,wh=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=Sh(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},Th=class extends _h{async request(e){let t=wh(e,e.webFetchExtra),n=Ch(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 xh(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`}))}};gh(`CapacitorHttp`,{web:()=>new Th});var Eh;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(Eh||={});var Dh;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(Dh||={});var Oh=class extends _h{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`)}};gh(`SystemBars`,{web:()=>new Oh});var kh=gh(`KeepAwake`,{web:()=>$r(()=>import(`./web-CQpWcSn8.js`).then(e=>new e.KeepAwakeWeb),[])}),Ah=0;function jh(){return typeof window<`u`&&wn()}async function Mh(){if(jh()&&(Ah+=1,!(Ah>1)))try{await kh.keepAwake()}catch{Ah=0}}async function Nh(){if(jh()&&Ah!==0&&(--Ah,!(Ah>0)))try{await kh.allowSleep()}catch{Ah=0}}async function Ph(){if(Ah=0,jh())try{await kh.allowSleep()}catch{}}function Fh(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 Ih(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&&eh(e.id,e.input,t)}catch{}}function Lh(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&&th(e.id,t)}catch{}}function Rh(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`&&Yc(e.id,e.input.command)}catch{}}function zh(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`&&Xc(e.toolCallId)}catch{}}async function Bh(e,t,n,r,i){let a=await xn(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 Vh=/^\/compact(?:\s+(.*))?$/i,Hh=`[Compact] Compaction in progress...`;function Uh(e,t,n){return{...e,threadId:t,paneId:n}}function Wh(e,t,n){let r={type:`thinking`,content:Hh,model:n};e(Uh({type:Z.SetStreaming,isStreaming:!0},t,`primary`)),e(Uh({type:Z.SetStreamModel,model:n},t,`primary`)),e(Uh({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r.content??``,segments:ha([],`thinking`,r.content??``)},t,`primary`))}function Gh(e){let t=za(),{toast:n}=no(),r=Ra(),[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 b(e,t){return Vi(r.getState().threadStreamingStates,e,t).isStreaming}function S(e,t){return Vi(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=Bi(e,r.paneId);if(r.pendingTransientRecovery){r.pendingTransientRecovery=!1,(async()=>{try{if((await Wn()).includes(e)){f.current?.(e,t=>_e(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)||(ch(e),t(Uh({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,Nh()),r.stopHandled)return;if(ch(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(Uh({type:Z.ResetStream},e,r.paneId)),t({type:Z.RemoveProcessingThread,threadId:e});return}let a=Oa(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 Bh(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(Uh({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=Bi(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,Nh())),x(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(Uh({type:Z.ResetStream},m,e)),t({type:Z.SetActiveStreamPane,paneId:null}),t({type:Z.MarkThreadCompleted,threadId:m}),t({type:Z.RemoveProcessingThread,threadId:m}),ch(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,Nh());let[r,i]=e.split(`:`);t(Uh({type:Z.ResetStream},r,i))}d.current.clear()},[t]);let E=(0,Y.useCallback)((e,n,r,i,o)=>{let c=Bi(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(Uh({type:Z.ResetStream},e,i)),t({type:Z.AddProcessingThread,threadId:e}),t(Uh({type:Z.SetStreaming,isStreaming:!0},e,i)),t({type:Z.SetActiveStreamPane,paneId:i}),Mh().then(()=>{p.keepsDeviceAwake=!0}),n(f.signal).then(n=>{if(!n||f.signal.aborted){w(e,r,p);return}p.cancel=Ut(n,n=>{if(t(Uh({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=ya(p.segments,r),t(Uh({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=ba(p.segments,r),t(Uh({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=xa(p.segments,r),t(Uh({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=qu(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(Uh({type:Z.SetStreamModel,model:n.model},e,i)),n.type===`thinking`||n.isThinking){let r=n.content??``;Fh(r,e),Ih(r,e),Lh(r,e),p.assistantThinking+=r,p.segments=ha(p.segments,`thinking`,r),t(Uh({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=ga(p.segments,r),t(Uh({type:Z.SetStreamContent,content:r},e,i)),typeof r==`string`&&(Fh(r,e),Ih(r,e),Lh(r,e))}else{if(p.hasStructuredContent)return;let r=n.content??``;p.assistantMessage+=r,p.segments=ha(p.segments,`content`,r),t(Uh({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(Ot(t)){p.pendingTransientRecovery=!0;return}p.error=t,e===u.current&&a(t)},n=>{if(t(Uh({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=ha(p.segments,`thinking`,a),t(Uh({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=ga(p.segments,a),t(Uh({type:Z.SetStreamContent,content:a},e,i)),Fh(a,e),Ih(a,e),Lh(a,e)):(p.assistantMessage+=a,p.segments=ha(p.segments,`content`,a),t(Uh({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&&(Rh(a),zh(a),pa(a)?(p.hasStructuredContent=!0,p.segments=_a(p.segments,a),p.assistantMessage=va(p.segments),t(Uh({type:Z.SetStreamContent,content:p.assistantMessage},e,i))):a.trim().startsWith(`[`)||(p.assistantMessage+=a,p.segments=ha(p.segments,`content`,a),t(Uh({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(Uh({type:Z.ResetStream},e,i));return}if(n instanceof pt){d.current.delete(c),t(Uh({type:Z.ResetStream},e,i)),s(!0);return}if(n instanceof Error&&n.message.includes(`not currently processing`)){d.current.delete(c),t(Uh({type:Z.ResetStream},e,i));return}if(n instanceof Error&&Ot(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(Uh({type:Z.ResetStream},e,i))}),f},[t,w]);f.current=E,(0,Y.useEffect)(()=>{for(let e of v){let t=Bi(e,`primary`);d.current.has(t)||r.getState().threadStreamingStates[t]?.isStreaming||lh(e)||E(e,t=>_e(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 x=o.trim().match(Vh);if(x){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)||b(g,r)){n({title:`Agent is busy`,description:`Wait for the agent to finish before compacting.`});return}let e=x[1]?.trim();Wh(t,g,s);try{let i=await Fn(g,{model:s,provider:u,instructions:e});t({type:Z.SetMessages,messages:i.messages}),t(Uh({type:Z.ResetStream},g,r)),n({title:`Conversation compacted`,description:`${i.messagesBefore} messages → ${i.messagesAfter} summary`})}catch(e){t(Uh({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 De(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&&(Ve(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(Uh({type:Z.ResetStream},g,r)),t({type:Z.SetActiveStreamPane,paneId:null});return}t(Uh({type:Z.SetStreaming,isStreaming:!0},g,r)),t({type:Z.SetActiveStreamPane,paneId:r});try{let n=await ee(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(Uh({type:Z.ResetStream},g,r)),t({type:Z.SetActiveStreamPane,paneId:null})}return}E(g,e=>je(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||b(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||b(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||b(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 Kh=(0,Y.createContext)(void 0);function qh(e){let t=(0,X.c)(3),{children:n}=e,r=Gh(),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Kh.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function Jh(){let e=(0,Y.useContext)(Kh);if(e===void 0)throw Error(`useChatHandlersContext must be used within a ChatHandlersProvider`);return e}function Yh(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)(Xh,{messages:i}),t[2]=i,t[3]=a),a}function Xh(e){let t=(0,X.c)(61),{messages:n}=e,{paneId:r,conversationId:i,fillPane:a}=Ld(),o=Q($h),s=Q(Qh),c=Q(Zh),[l,u]=Y.useState(!1),{handleSend:d,handleStop:f,getQueuedMessagesForPane:p,handleRemoveQueuedMessage:m,showEmptyBalanceDialog:h,setShowEmptyBalanceDialog:g}=Jh(),{userTasks:_,setUserTasks:v,handleNewChat:y,handleSelectUserTask:b,handleRemoveUserTask:x,toggleUserTaskPinned:S,effectiveIsStreaming:C}=rm(),w=yf(),T;t[0]===w?T=t[1]:(T=w||wn(),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)(Jm,{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=Vd(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)(Bm,{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 z=!s&&!o,B;t[34]!==p||t[35]!==r?(B=p(r),t[34]=p,t[35]=r,t[36]=B):B=t[36];let ee;t[37]===x?ee=t[38]:(ee=e=>{e.pinned||x(e.id)},t[37]=x,t[38]=ee);let te;t[39]===v?te=t[40]:(te=e=>{v(t=>[...t,e])},t[39]=v,t[40]=te);let ne;t[41]!==C||t[42]!==M||t[43]!==O||t[44]!==A||t[45]!==l||t[46]!==B||t[47]!==ee||t[48]!==te||t[49]!==z||t[50]!==_?(ne=(0,$.jsx)(Dp,{planMode:l,setPlanMode:u,onSend:O,onStop:A,isStreaming:C,disabled:z,initialValue:``,queuedMessages:B,onRemoveQueuedMessage:M,isOverlay:!1,userTasks:_,onMatchedUserTaskSend:ee,onUserTaskCreated:te}),t[41]=C,t[42]=M,t[43]=O,t[44]=A,t[45]=l,t[46]=B,t[47]=ee,t[48]=te,t[49]=z,t[50]=_,t[51]=ne):ne=t[51];let re;t[52]!==ne||t[53]!==R?(re=(0,$.jsxs)(`div`,{className:`relative`,children:[R,ne]}),t[52]=ne,t[53]=R,t[54]=re):re=t[54];let ie;t[55]!==re||t[56]!==L?(ie=(0,$.jsx)(`div`,{className:L,children:re}),t[55]=re,t[56]=L,t[57]=ie):ie=t[57];let ae;return t[58]!==ie||t[59]!==I?(ae=(0,$.jsxs)($.Fragment,{children:[I,ie]}),t[58]=ie,t[59]=I,t[60]=ae):ae=t[60],ae}function Zh(e){return e.selectedProjectId}function Qh(e){return e.selectedThreadId}function $h(e){return e.isCreatingProject}var eg=768;function tg(){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: ${eg-1}px)`),t=()=>{n(window.innerWidth<eg)};return e.addEventListener(`change`,t),n(window.innerWidth<eg),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),!!t}function ng(e){let t=(0,X.c)(7),{paneId:n,conversationId:r}=e,i=za(),a=Q(ig),o=Q(rg),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 xn(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 rg(e){return e.dualChatEnabled}function ig(e){return e.selectedThreadId}var ag=4,og=8,sg=`(max-width: 767px)`;function cg(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(sg).matches?ag:0,s=window.matchMedia(sg).matches?0:og;return a+o+s}function lg(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(cg(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 ug;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(ug||={});var dg;(function(e){e.Body=`body`,e.Ionic=`ionic`,e.Native=`native`,e.None=`none`})(dg||={});var fg=gh(`Keyboard`);function pg(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 mg(e,t){return on()?t:e>0?e:t}function hg(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(pg(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 wn()&&a.push(fg.addListener(`keyboardWillShow`,e=>{o(e.keyboardHeight)}),fg.addListener(`keyboardDidShow`,e=>{o(e.keyboardHeight)}),fg.addListener(`keyboardWillHide`,()=>{o(0)}),fg.addListener(`keyboardDidHide`,()=>{o(0)})),()=>{r?.removeEventListener(`resize`,n),r?.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n);for(let e of a)e.then(gg)}},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=mg(r,a),n[3]=r,n[4]=a,n[5]=u):u=n[5],u}function gg(e){e.remove()}function _g({paneId:e,conversationId:t,onCreateThread:n,showEmptyState:r=e===`primary`,fillPane:i=!1,onConnectRepo:a=()=>{},onNewApp:o=()=>{},onOpenFolder:s=()=>{}}){let c=za(),l=Q(e=>e.selectedThreadId),u=Q(e=>e.selectedProjectId),d=Q(e=>e.projects),f=Q(e=>e.projectsLoading),p=Q(e=>e.isCreatingProject),m=Q(e=>e.processingThreadIds),h=Q(e=>e.pendingChatMessage),g=Q(t=>l?Vi(t.threadStreamingStates,l,e):null),_=Q(e=>e.messages),v=Q(e=>e.secondaryMessages),y=Q(e=>e.messagesLoaded),b=Q(e=>e.secondaryMessagesLoaded),x=e===`primary`?_:v,S=e===`primary`?y:b,C=!!(l&&m.includes(l)),w=e===`primary`&&h?.threadId===l,T=g?.isStreaming??!1;ng({paneId:e,conversationId:t});let E=(0,Y.useRef)(null),D=(0,Y.useRef)(null),O=(0,Y.useRef)(null),k=tg(),[A,j]=(0,Y.useState)(!0),M=!!l,N=k&&M&&!A,P=lg(E,D,M),F=hg(D);function I(){c({type:Z.CloseSidebar})}return(0,$.jsx)(Fd,{paneId:e,conversationId:t,fillPane:i,children:(0,$.jsx)(Qp,{children:(0,$.jsxs)(`div`,{ref:E,className:`relative flex h-full min-w-0 flex-col`,children:[(0,$.jsx)(Yd,{ref:O,bottomInset:P,messages:x,isStreaming:T,streamingSegments:T?g?.streamingSegments??[]:[],streamingModel:T?g?.streamingModel??``:``,isCreatingProject:r?p:!1,isProcessingThread:C,hasPendingMessage:w,selectedThreadId:l,selectedProjectId:u,projects:d,projectsLoading:f,messagesLoaded:S,onSelectThread:(e,t)=>{I(),c({type:Z.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:a,onNewApp:o,onOpenFolder:s,error:null,onClearError:()=>{},onAtBottomChange:j,hideEmptyState:!r}),M&&(0,$.jsxs)(`div`,{ref:D,className:`absolute inset-x-0 z-20 max-md:px-2`,style:{bottom:F},children:[(0,$.jsx)(`div`,{className:U(`h-0 bg-gradient-to-t from-background to-transparent md:h-6`,`md:mr-4`)}),(0,$.jsx)(`div`,{className:U(`h-0 bg-background md:h-8`,`md:mr-4`)}),N&&(0,$.jsx)(`div`,{className:`mb-1 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>O.current?.scrollToBottom(),className:`flex h-8 w-8 items-center justify-center rounded-full border border-border bg-background shadow-md transition-colors hover:bg-accent active:bg-accent`,"aria-label":`Scroll to bottom`,children:(0,$.jsx)(On,{className:`h-4 w-4`})})}),(0,$.jsx)(`div`,{className:U(`bg-background`,`md:mr-4`),children:(0,$.jsx)(Yh,{messages:x})})]})]})})})}function vg(){let e=za(),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[Bi(n,`primary`)],s=!1;async function c(){try{let t=await xn(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 _e(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 yg=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=U(`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)(ar,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},bg=xr,xg=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=U(`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)(ke,{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)(br,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},Sg=(0,Y.lazy)(()=>$r(()=>import(`./diff-view-DONeogdk.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),Cg=(0,Y.lazy)(()=>$r(()=>import(`./dialogs-config-BF_RyK5j.js`).then(e=>e.t),__vite__mapDeps([3,1])));function wg(e){let t=(0,X.c)(35),{onCreateThread:n}=e,r=za(),i=rr(),a=hr(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=Q(Eg),d=Q(Tg),{isDualChatActive:f}=xf(),p=tg(),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 Rn(e,t),s(!1),l(null)}catch(e){console.error(`Failed to clone repository:`,e)}},t[6]=b):b=t[6];let x=b,S;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(S=async(e,t,n)=>{try{await Ae(e,t,n),s(!1),l(null)}catch(e){console.error(`Failed to create project:`,e)}},t[7]=S):S=t[7];let C=S,w;t[8]===h?w=t[9]:(w=async()=>{h();try{await rn(),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 Vn(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;vg();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)(di,{}),children:(0,$.jsx)(Sg,{threadId:u,onExit:A})}):j&&f&&!p?(0,$.jsxs)(yg,{direction:`horizontal`,className:`h-full`,children:[(0,$.jsx)(bg,{defaultSize:50,minSize:30,children:(0,$.jsx)(_g,{paneId:`primary`,fillPane:!0,onCreateThread:n,showEmptyState:!0,onConnectRepo:_,onNewApp:y,onOpenFolder:T})}),(0,$.jsx)(xg,{withHandle:!0}),(0,$.jsx)(bg,{defaultSize:50,minSize:30,className:`border-l border-border`,children:(0,$.jsx)(_g,{paneId:`secondary`,fillPane:!0,conversationId:d??void 0,onCreateThread:n,showEmptyState:!1})})]}):j?(0,$.jsx)(_g,{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)(Cg,{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)(qh,{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)(Wl,{threadId:u,children:F}),t[32]=u,t[33]=F,t[34]=I):I=t[34],I}function Tg(e){return e.secondaryConversationId}function Eg(e){return e.selectedThreadId}function Dg(e){let t=(0,X.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=U(`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 Og(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 kg;(function(e){e.Heavy=`HEAVY`,e.Medium=`MEDIUM`,e.Light=`LIGHT`})(kg||={});var Ag;(function(e){e.Success=`SUCCESS`,e.Warning=`WARNING`,e.Error=`ERROR`})(Ag||={});var jg=gh(`Haptics`,{web:()=>$r(()=>import(`./web-DOZOaJlj.js`).then(e=>new e.HapticsWeb),[])});function Mg(){return typeof window<`u`&&wn()}function Ng(e=kg.Medium){Mg()&&jg.impact({style:e}).catch(()=>{})}function Pg(){let e=(0,X.c)(49),t=za(),n=Q(zg),r=Q(Rg),i=Q(Lg),a=Q(Ig),o=Q(Fg),{handleNewChat:s}=rm(),c=o.length>0,l;if(e[0]!==i||e[1]!==r){let t;e[3]===r?t=e[4]:(t=e=>e.projectId===r,e[3]=r,e[4]=t),l=i.find(t),e[0]=i,e[1]=r,e[2]=l}else l=e[2];let u=l,d=!a,f,p;if(e[5]!==d){let t=Dn();f=Dg,p=U(t&&`pt-8 md:min-h-[103px]`,d&&t&&`max-md:pb-2 md:h-auto md:pb-3 md:h-[103px] md:pb-0`),e[5]=d,e[6]=f,e[7]=p}else f=e[6],p=e[7];let m;e[8]===t?m=e[9]:(m=()=>t({type:Z.ToggleSidebar}),e[8]=t,e[9]=m);let h;e[10]===a?h=e[11]:(h=a?(0,$.jsx)(an,{className:`h-4 w-4`}):(0,$.jsx)(ot,{className:`h-4 w-4`}),e[10]=a,e[11]=h);let g;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle sidebar`}),e[12]=g):g=e[12];let _;e[13]!==m||e[14]!==h?(_=(0,$.jsxs)(V,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0 electrobun-webkit-app-region-no-drag`,onClick:m,children:[h,g]}),e[13]=m,e[14]=h,e[15]=_):_=e[15];let v;e[16]!==i||e[17]!==r||e[18]!==n?(v=n&&(0,$.jsx)(`span`,{className:U(J.sectionTitle,`text-foreground truncate min-w-0`),children:ae(i,r)}),e[16]=i,e[17]=r,e[18]=n,e[19]=v):v=e[19];let y;e[20]!==_||e[21]!==v?(y=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[_,v]}),e[20]=_,e[21]=v,e[22]=y):y=e[22];let b;e[23]!==s||e[24]!==c||e[25]!==n?(b=n&&c&&(0,$.jsxs)(V,{size:`icon`,className:`h-7 w-7 rounded-full md:hidden electrobun-webkit-app-region-no-drag`,onClick:()=>{Ng(),s()},children:[(0,$.jsx)(be,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`New Chat`})]}),e[23]=s,e[24]=c,e[25]=n,e[26]=b):b=e[26];let x;e[27]===n?x=e[28]:(x=n&&(0,$.jsx)(Vm,{}),e[27]=n,e[28]=x);let S;e[29]!==u?.runCommand||e[30]!==r||e[31]!==n?(S=r&&(0,$.jsxs)(Og,{className:`electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(bm,{projectId:r,runCommand:u?.runCommand}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(om,{threadId:n}),(0,$.jsx)(lm,{})]})]}),e[29]=u?.runCommand,e[30]=r,e[31]=n,e[32]=S):S=e[32];let C;e[33]!==u?.openWith||e[34]!==r||e[35]!==n?(C=n&&r&&(0,$.jsx)(Og,{className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(gm,{projectId:r,threadId:n,openWith:u?.openWith})}),e[33]=u?.openWith,e[34]=r,e[35]=n,e[36]=C):C=e[36];let w;e[37]!==S||e[38]!==C?(w=(0,$.jsxs)(`div`,{className:`hidden md:flex flex-wrap items-center justify-end gap-2`,children:[S,C]}),e[37]=S,e[38]=C,e[39]=w):w=e[39];let T;e[40]!==w||e[41]!==b||e[42]!==x?(T=(0,$.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[b,x,w]}),e[40]=w,e[41]=b,e[42]=x,e[43]=T):T=e[43];let E;return e[44]!==f||e[45]!==p||e[46]!==T||e[47]!==y?(E=(0,$.jsxs)(f,{className:p,children:[y,T]}),e[44]=f,e[45]=p,e[46]=T,e[47]=y,e[48]=E):E=e[48],E}function Fg(e){return e.messages}function Ig(e){return e.sidebarOpen}function Lg(e){return e.projects}function Rg(e){return e.selectedProjectId}function zg(e){return e.selectedThreadId}function Bg(){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 Vg=[`Chat`,`Explorer`,`Review`,`Browser`,`Terminal`,`Tasks`];function Hg(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}=hc(),{triggerExplorerRefresh:f}=yc(),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=Vg.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 Ug=(0,Y.lazy)(()=>$r(()=>import(`./terminal-panel-Bh_CKydu.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([13,1,3,14]))),Wg=(0,Y.lazy)(()=>$r(()=>import(`./diff-view-DONeogdk.js`),__vite__mapDeps([9,1,7,8,5,3,4,10,11,12]))),Gg=(0,Y.lazy)(()=>$r(()=>import(`./explorer-tab-view-C1Dex751.js`),__vite__mapDeps([15,1,7,8,5,3]))),Kg=(0,Y.lazy)(()=>$r(()=>import(`./browser-tab-B3BybVD0.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([16,1,3]))),qg=(0,Y.lazy)(()=>$r(()=>import(`./settings-view-BxiazdKG.js`),__vite__mapDeps([17,1,7,8,5,3,4,18,19,11]))),Jg=(0,Y.lazy)(()=>$r(()=>import(`./todos-view-DDSSplmi.js`).then(e=>({default:e.TodosView})),__vite__mapDeps([20,1,7,8,5,3,21,11])));function Yg(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}=hc(),h=!i&&!a,g;t[0]===h?g=t[1]:(g=h&&(0,$.jsx)(Pg,{}),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)(Hg,{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)(dr,{path:`/settings/providers/:providerSlug`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Bg,{}),children:(0,$.jsx)(qg,{})})}),t[9]=y):y=t[9];let b;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(dr,{path:`/settings/project/:projectId`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Bg,{}),children:(0,$.jsx)(qg,{})})}),t[10]=b):b=t[10];let x;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(dr,{path:`/settings/:tab?`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Bg,{}),children:(0,$.jsx)(qg,{})})}),t[11]=x):x=t[11];let S;t[12]===o?S=t[13]:(S=(0,$.jsxs)(fr,{children:[y,b,x,(0,$.jsx)(dr,{path:`*`,element:(0,$.jsx)(wg,{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)(Ug,{})}),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)(Kg,{})}),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)(pi,{}),children:(0,$.jsx)(Gg,{})})}),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)(pi,{}),children:(0,$.jsx)(Jg,{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)(Wg,{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 Xg(e){let t=(0,X.c)(14),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(ni,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=U(J.body,`font-semibold text-foreground`),t[1]=s):s=t[1];let c;t[2]===r?c=t[3]:(c=(0,$.jsxs)(si,{children:[o,(0,$.jsxs)(ii,{children:[`Are you sure you want to delete`,` `,(0,$.jsxs)(`span`,{className:s,children:[`"`,r,`"`]}),`? This will remove the project and all its data. This action cannot be undone.`]})]}),t[2]=r,t[3]=c);let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(ei,{children:`Cancel`}),t[4]=l):l=t[4];let u;t[5]===a?u=t[6]:(u=(0,$.jsxs)(ai,{children:[l,(0,$.jsx)(ui,{onClick:a,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[5]=a,t[6]=u);let d;t[7]!==c||t[8]!==u?(d=(0,$.jsxs)(li,{children:[c,u]}),t[7]=c,t[8]=u,t[9]=d):d=t[9];let f;return t[10]!==i||t[11]!==n||t[12]!==d?(f=(0,$.jsx)(oi,{open:n,onOpenChange:i,children:d}),t[10]=i,t[11]=n,t[12]=d,t[13]=f):f=t[13],f}function Zg(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)(ni,{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)(si,{children:[o,(0,$.jsxs)(ii,{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)(ei,{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)(ui,{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)(ai,{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)(li,{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)(oi,{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 "([^"]+)" && (.+)$/),r=n?n[1]:`root`,i=n?n[2]:e;return(0,$.jsx)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/50`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:J.label,children:r||`root`}),(0,$.jsx)(`div`,{className:J.bodyMuted,children:i})]})]})},t)}var $g;(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`})($g||={});var e_=new Map([[$g.QR_CODE,`QR_CODE`],[$g.AZTEC,`AZTEC`],[$g.CODABAR,`CODABAR`],[$g.CODE_39,`CODE_39`],[$g.CODE_93,`CODE_93`],[$g.CODE_128,`CODE_128`],[$g.DATA_MATRIX,`DATA_MATRIX`],[$g.MAXICODE,`MAXICODE`],[$g.ITF,`ITF`],[$g.EAN_13,`EAN_13`],[$g.EAN_8,`EAN_8`],[$g.PDF_417,`PDF_417`],[$g.RSS_14,`RSS_14`],[$g.RSS_EXPANDED,`RSS_EXPANDED`],[$g.UPC_A,`UPC_A`],[$g.UPC_E,`UPC_E`],[$g.UPC_EAN_EXTENSION,`UPC_EAN_EXTENSION`]]),t_;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.URL=1]=`URL`})(t_||={});function n_(e){return Object.values($g).includes(e)}var r_;(function(e){e[e.SCAN_TYPE_CAMERA=0]=`SCAN_TYPE_CAMERA`,e[e.SCAN_TYPE_FILE=1]=`SCAN_TYPE_FILE`})(r_||={});var i_=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=[r_.SCAN_TYPE_CAMERA,r_.SCAN_TYPE_FILE],e}(),a_=function(){function e(e,t){this.format=e,this.formatName=t}return e.prototype.toString=function(){return this.formatName},e.create=function(t){if(!e_.has(t))throw`${t} not in html5QrcodeSupportedFormatsTextMap`;return new e(t,e_.get(t))},e}(),o_=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}(),s_;(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`})(s_||={});var c_=function(){function e(){}return e.createFrom=function(e){return{errorMessage:e,type:s_.UNKWOWN_ERROR}},e}(),l_=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 u_(e){return e==null}function d_(e,t,n){return e>n?n:e<t?t:e}var f_=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}(),p_=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}(),m_=function(){function e(){}return e.poweredBy=function(){return`Powered by `},e.reportIssues=function(){return`Report issues`},e}(),h_=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}(),g_=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 z;(function(e){e[e.AZTEC=0]=`AZTEC`,e[e.CODABAR=1]=`CODABAR`,e[e.CODE_39=2]=`CODE_39`,e[e.CODE_93=3]=`CODE_93`,e[e.CODE_128=4]=`CODE_128`,e[e.DATA_MATRIX=5]=`DATA_MATRIX`,e[e.EAN_8=6]=`EAN_8`,e[e.EAN_13=7]=`EAN_13`,e[e.ITF=8]=`ITF`,e[e.MAXICODE=9]=`MAXICODE`,e[e.PDF_417=10]=`PDF_417`,e[e.QR_CODE=11]=`QR_CODE`,e[e.RSS_14=12]=`RSS_14`,e[e.RSS_EXPANDED=13]=`RSS_EXPANDED`,e[e.UPC_A=14]=`UPC_A`,e[e.UPC_E=15]=`UPC_E`,e[e.UPC_EAN_EXTENSION=16]=`UPC_EAN_EXTENSION`})(z||={});var B=z,ee;(function(e){e[e.OTHER=0]=`OTHER`,e[e.ORIENTATION=1]=`ORIENTATION`,e[e.BYTE_SEGMENTS=2]=`BYTE_SEGMENTS`,e[e.ERROR_CORRECTION_LEVEL=3]=`ERROR_CORRECTION_LEVEL`,e[e.ISSUE_NUMBER=4]=`ISSUE_NUMBER`,e[e.SUGGESTED_PRICE=5]=`SUGGESTED_PRICE`,e[e.POSSIBLE_COUNTRY=6]=`POSSIBLE_COUNTRY`,e[e.UPC_EAN_EXTENSION=7]=`UPC_EAN_EXTENSION`,e[e.PDF417_EXTRA_METADATA=8]=`PDF417_EXTRA_METADATA`,e[e.STRUCTURED_APPEND_SEQUENCE=9]=`STRUCTURED_APPEND_SEQUENCE`,e[e.STRUCTURED_APPEND_PARITY=10]=`STRUCTURED_APPEND_PARITY`})(ee||={});var te=ee;class ne{constructor(e,t,n,r,i=-1,a=-1){this.rawBytes=e,this.text=t,this.byteSegments=n,this.ecLevel=r,this.structuredAppendSequenceNumber=i,this.structuredAppendParity=a,this.numBits=e==null?0:8*e.length}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}setNumBits(e){this.numBits=e}getText(){return this.text}getByteSegments(){return this.byteSegments}getECLevel(){return this.ecLevel}getErrorsCorrected(){return this.errorsCorrected}setErrorsCorrected(e){this.errorsCorrected=e}getErasures(){return this.erasures}setErasures(e){this.erasures=e}getOther(){return this.other}setOther(e){this.other=e}hasStructuredAppend(){return this.structuredAppendParity>=0&&this.structuredAppendSequenceNumber>=0}getStructuredAppendParity(){return this.structuredAppendParity}getStructuredAppendSequenceNumber(){return this.structuredAppendSequenceNumber}}class re{exp(e){return this.expTable[e]}log(e){if(e===0)throw new l;return this.logTable[e]}static addOrSubtract(e,t){return e^t}}class ie{constructor(e,t){if(t.length===0)throw new l;this.field=e;let n=t.length;if(n>1&&t[0]===0){let e=1;for(;e<n&&t[e]===0;)e++;e===n?this.coefficients=Int32Array.from([0]):(this.coefficients=new Int32Array(n-e),p.arraycopy(t,e,this.coefficients,0,this.coefficients.length))}else this.coefficients=t}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);let t=this.coefficients,n;if(e===1){n=0;for(let e=0,r=t.length;e!==r;e++){let r=t[e];n=re.addOrSubtract(n,r)}return n}n=t[0];let r=t.length,i=this.field;for(let a=1;a<r;a++)n=re.addOrSubtract(i.multiply(e,n),t[a]);return n}addOrSubtract(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(this.isZero())return e;if(e.isZero())return this;let t=this.coefficients,n=e.coefficients;if(t.length>n.length){let e=t;t=n,n=e}let r=new Int32Array(n.length),i=n.length-t.length;p.arraycopy(n,0,r,0,i);for(let e=i;e<n.length;e++)r[e]=re.addOrSubtract(t[e-i],n[e]);return new ie(this.field,r)}multiply(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(this.isZero()||e.isZero())return this.field.getZero();let t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,a=new Int32Array(n+i-1),o=this.field;for(let e=0;e<n;e++){let n=t[e];for(let t=0;t<i;t++)a[e+t]=re.addOrSubtract(a[e+t],o.multiply(n,r[t]))}return new ie(o,a)}multiplyScalar(e){if(e===0)return this.field.getZero();if(e===1)return this;let t=this.coefficients.length,n=this.field,r=new Int32Array(t),i=this.coefficients;for(let a=0;a<t;a++)r[a]=n.multiply(i[a],e);return new ie(n,r)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return this.field.getZero();let n=this.coefficients,r=n.length,i=new Int32Array(r+e),a=this.field;for(let e=0;e<r;e++)i[e]=a.multiply(n[e],t);return new ie(a,i)}divide(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(e.isZero())throw new l(`Divide by 0`);let t=this.field,n=t.getZero(),r=this,i=e.getCoefficient(e.getDegree()),a=t.inverse(i);for(;r.getDegree()>=e.getDegree()&&!r.isZero();){let i=r.getDegree()-e.getDegree(),o=t.multiply(r.getCoefficient(r.getDegree()),a),s=e.multiplyByMonomial(i,o),c=t.buildMonomial(i,o);n=n.addOrSubtract(c),r=r.addOrSubtract(s)}return[n,r]}toString(){let e=``;for(let t=this.getDegree();t>=0;t--){let n=this.getCoefficient(t);if(n!==0){if(n<0?(e+=` - `,n=-n):e.length>0&&(e+=` + `),t===0||n!==1){let t=this.field.log(n);t===0?e+=`1`:t===1?e+=`a`:(e+=`a^`,e+=t)}t!==0&&(t===1?e+=`x`:(e+=`x^`,e+=t))}}return e}}class ae extends s{}ae.kind=`ArithmeticException`;class oe extends re{constructor(e,t,n){super(),this.primitive=e,this.size=t,this.generatorBase=n;let r=new Int32Array(t),i=1;for(let n=0;n<t;n++)r[n]=i,i*=2,i>=t&&(i^=e,i&=t-1);this.expTable=r;let a=new Int32Array(t);for(let e=0;e<t-1;e++)a[r[e]]=e;this.logTable=a,this.zero=new ie(this,Int32Array.from([0])),this.one=new ie(this,Int32Array.from([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,t){if(e<0)throw new l;if(t===0)return this.zero;let n=new Int32Array(e+1);return n[0]=t,new ie(this,n)}inverse(e){if(e===0)throw new ae;return this.expTable[this.size-this.logTable[e]-1]}multiply(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.size-1)]}getSize(){return this.size}getGeneratorBase(){return this.generatorBase}toString(){return`GF(0x`+_.toHexString(this.primitive)+`,`+this.size+`)`}equals(e){return e===this}}oe.AZTEC_DATA_12=new oe(4201,4096,1),oe.AZTEC_DATA_10=new oe(1033,1024,1),oe.AZTEC_DATA_6=new oe(67,64,1),oe.AZTEC_PARAM=new oe(19,16,1),oe.QR_CODE_FIELD_256=new oe(285,256,0),oe.DATA_MATRIX_FIELD_256=new oe(301,256,1),oe.AZTEC_DATA_8=oe.DATA_MATRIX_FIELD_256,oe.MAXICODE_FIELD_64=oe.AZTEC_DATA_6;class se extends s{}se.kind=`ReedSolomonException`;class ce extends s{}ce.kind=`IllegalStateException`;class le{constructor(e){this.field=e}decode(e,t){let n=this.field,r=new ie(n,e),i=new Int32Array(t),a=!0;for(let e=0;e<t;e++){let t=r.evaluateAt(n.exp(e+n.getGeneratorBase()));i[i.length-1-e]=t,t!==0&&(a=!1)}if(a)return;let o=new ie(n,i),s=this.runEuclideanAlgorithm(n.buildMonomial(t,1),o,t),c=s[0],l=s[1],u=this.findErrorLocations(c),d=this.findErrorMagnitudes(l,u);for(let t=0;t<u.length;t++){let r=e.length-1-n.log(u[t]);if(r<0)throw new se(`Bad error location`);e[r]=oe.addOrSubtract(e[r],d[t])}}runEuclideanAlgorithm(e,t,n){if(e.getDegree()<t.getDegree()){let n=e;e=t,t=n}let r=this.field,i=e,a=t,o=r.getZero(),s=r.getOne();for(;a.getDegree()>=(n/2|0);){let e=i,t=o;if(i=a,o=s,i.isZero())throw new se(`r_{i-1} was zero`);a=e;let n=r.getZero(),c=i.getCoefficient(i.getDegree()),l=r.inverse(c);for(;a.getDegree()>=i.getDegree()&&!a.isZero();){let e=a.getDegree()-i.getDegree(),t=r.multiply(a.getCoefficient(a.getDegree()),l);n=n.addOrSubtract(r.buildMonomial(e,t)),a=a.addOrSubtract(i.multiplyByMonomial(e,t))}if(s=n.multiply(o).addOrSubtract(t),a.getDegree()>=i.getDegree())throw new ce(`Division algorithm failed to reduce polynomial?`)}let c=s.getCoefficient(0);if(c===0)throw new se(`sigmaTilde(0) was zero`);let l=r.inverse(c);return[s.multiplyScalar(l),a.multiplyScalar(l)]}findErrorLocations(e){let t=e.getDegree();if(t===1)return Int32Array.from([e.getCoefficient(1)]);let n=new Int32Array(t),r=0,i=this.field;for(let a=1;a<i.getSize()&&r<t;a++)e.evaluateAt(a)===0&&(n[r]=i.inverse(a),r++);if(r!==t)throw new se(`Error locator degree does not match number of roots`);return n}findErrorMagnitudes(e,t){let n=t.length,r=new Int32Array(n),i=this.field;for(let a=0;a<n;a++){let o=i.inverse(t[a]),s=1;for(let e=0;e<n;e++)if(a!==e){let n=i.multiply(t[e],o),r=n&1?n&-2:n|1;s=i.multiply(s,r)}r[a]=i.multiply(e.evaluateAt(o),i.inverse(s)),i.getGeneratorBase()!==0&&(r[a]=i.multiply(r[a],o))}return r}}var V;(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`})(V||={});class ue{decode(e){this.ddata=e;let t=e.getBits(),n=this.extractBits(t),r=this.correctBits(n),i=new ne(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=V.UPPER,r=V.UPPER,i=``,a=0;for(;a<t;)if(r===V.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===V.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 V.LOWER;case`P`:return V.PUNCT;case`M`:return V.MIXED;case`D`:return V.DIGIT;case`B`:return V.BINARY;default:return V.UPPER}}static getCharacter(e,t){switch(e){case V.UPPER:return ue.UPPER_TABLE[t];case V.LOWER:return ue.LOWER_TABLE[t];case V.MIXED:return ue.MIXED_TABLE[t];case V.PUNCT:return ue.PUNCT_TABLE[t];case V.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 le(t).decode(o,i-r)}catch(e){throw new x(e)}let s=(1<<n)-1,c=0;for(let e=0;e<r;e++){let t=o[e];if(t===0||t===s)throw new x;(t===1||t===s-1)&&c++}let l=Array(r*n-c),u=0;for(let e=0;e<r;e++){let t=o[e];if(t===1||t===s-1)l.fill(t>1,u,u+n-1),u+=n-1;else for(let e=n-1;e>=0;--e)l[u++]=(t&1<<e)!=0}return l}extractBits(e){let t=this.ddata.isCompact(),n=this.ddata.getNbLayers(),r=(t?11:14)+n*4,i=new Int32Array(r),a=Array(this.totalBitsInLayer(n,t));if(t)for(let e=0;e<i.length;e++)i[e]=e;else{let e=r+1+2*_.truncDivision(_.truncDivision(r,2)-1,15),t=r/2,n=_.truncDivision(e,2);for(let e=0;e<t;e++){let r=e+_.truncDivision(e,15);i[t-e-1]=n-r-1,i[t+e]=n+r+1}}for(let o=0,s=0;o<n;o++){let c=(n-o)*4+(t?9:12),l=o*2,u=r-1-l;for(let t=0;t<c;t++){let n=t*2;for(let r=0;r<2;r++)a[s+n+r]=e.get(i[l+r],i[l+t]),a[s+2*c+n+r]=e.get(i[l+t],i[u-r]),a[s+4*c+n+r]=e.get(i[u-r],i[u-t]),a[s+6*c+n+r]=e.get(i[u-t],i[l+r])}s+=c*8}return a}static readCode(e,t,n){let r=0;for(let i=t;i<t+n;i++)r<<=1,e[i]&&(r|=1);return r}static readByte(e,t){let n=e.length-t;return n>=8?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 le(oe.AZTEC_PARAM).decode(a,i)}catch{throw new k}let o=0;for(let e=0;e<r;e++)o=(o<<4)+a[e];return o}getBullsEyeCorners(e){let t=e,n=e,r=e,i=e,a=!0;for(this.nbCenterLayers=1;this.nbCenterLayers<9;this.nbCenterLayers++){let e=this.getFirstDifferent(t,a,1,-1),o=this.getFirstDifferent(n,a,1,1),s=this.getFirstDifferent(r,a,-1,1),c=this.getFirstDifferent(i,a,-1,-1);if(this.nbCenterLayers>2){let n=this.distancePoint(c,e)*this.nbCenterLayers/(this.distancePoint(i,t)*(this.nbCenterLayers+2));if(n<.75||n>1.25||!this.isWhiteOrBlackRectangle(e,o,s,c))break}t=e,n=o,r=s,i=c,a=!a}if(this.nbCenterLayers!==5&&this.nbCenterLayers!==7)throw new k;this.compact=this.nbCenterLayers===5;let o=new 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,B.AZTEC,p.currentTimeMillis()),s=a.getByteSegments();s!=null&&o.putMetadata(te.BYTE_SEGMENTS,s);let c=a.getECLevel();return c!=null&&o.putMetadata(te.ERROR_CORRECTION_LEVEL,c),o}reportFoundResultPoints(e,t){if(e!=null){let n=e.get(b.NEED_RESULT_POINT_CALLBACK);n!=null&&t.forEach((e,t,r)=>{n.foundPossibleResultPoint(e)})}}reset(){}}class 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(te.ORIENTATION)===!0&&(a+=i.get(te.ORIENTATION)%360),r.putMetadata(te.ORIENTATION,a);let o=r.getResultPoints();if(o!==null){let e=n.getHeight();for(let t=0;t<o.length;t++)o[t]=new 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(te.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 we 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=we.MAX_AVG_VARIANCE,n=-1;for(let e=we.CODE_START_A;e<=we.CODE_START_C;e++){let r=Ce.patternMatchVariance(i,we.CODE_PATTERNS[e],we.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=we.MAX_AVG_VARIANCE,i=-1;for(let e=0;e<we.CODE_PATTERNS.length;e++){let n=we.CODE_PATTERNS[e],a=this.patternMatchVariance(t,n,we.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=we.findStartPattern(t),a=i[2],o=0,s=new Uint8Array(20);s[o++]=a;let c;switch(a){case we.CODE_START_A:c=we.CODE_CODE_A;break;case we.CODE_START_B:c=we.CODE_CODE_B;break;case we.CODE_START_C:c=we.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=_,_=we.decodeCode(t,h,m),s[o++]=_,_!==we.CODE_STOP&&(S=!0),_!==we.CODE_STOP&&(y++,v+=y*_),p=m,m+=h.reduce((e,t)=>e+t,0),_){case we.CODE_START_A:case we.CODE_START_B:case we.CODE_START_C:throw new x}switch(c){case we.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(_!==we.CODE_STOP&&(S=!1),_){case we.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case we.CODE_FNC_2:case we.CODE_FNC_3:break;case we.CODE_FNC_4_A:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case we.CODE_SHIFT:u=!0,c=we.CODE_CODE_B;break;case we.CODE_CODE_B:c=we.CODE_CODE_B;break;case we.CODE_CODE_C:c=we.CODE_CODE_C;break;case we.CODE_STOP:l=!0;break}break;case we.CODE_CODE_B:if(_<96)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else switch(_!==we.CODE_STOP&&(S=!1),_){case we.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case we.CODE_FNC_2:case we.CODE_FNC_3:break;case we.CODE_FNC_4_B:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case we.CODE_SHIFT:u=!0,c=we.CODE_CODE_A;break;case we.CODE_CODE_A:c=we.CODE_CODE_A;break;case we.CODE_CODE_C:c=we.CODE_CODE_C;break;case we.CODE_STOP:l=!0;break}break;case we.CODE_CODE_C:if(_<100)_<10&&(f+=`0`),f+=_;else switch(_!==we.CODE_STOP&&(S=!1),_){case we.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case we.CODE_CODE_A:c=we.CODE_CODE_A;break;case we.CODE_CODE_B:c=we.CODE_CODE_B;break;case we.CODE_STOP:l=!0;break}break}e&&(c=c===we.CODE_CODE_A?we.CODE_CODE_B:we.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===we.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,B.CODE_128,new Date().getTime())}}we.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])],we.MAX_AVG_VARIANCE=.25,we.MAX_INDIVIDUAL_VARIANCE=.7,we.CODE_SHIFT=98,we.CODE_CODE_C=99,we.CODE_CODE_B=100,we.CODE_CODE_A=101,we.CODE_FNC_1=102,we.CODE_FNC_2=97,we.CODE_FNC_3=96,we.CODE_FNC_4_A=101,we.CODE_FNC_4_B=100,we.CODE_START_A=103,we.CODE_START_B=104,we.CODE_START_C=105,we.CODE_STOP=106;class Te 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=Te.findAsteriskPattern(t,r),a=t.getNextSet(i[1]),o=t.getSize(),s,c;do{Te.recordPattern(t,a,r);let e=Te.toNarrowWidePattern(r);if(e<0)throw new k;s=Te.patternToChar(e),this.decodeRowResult+=s,c=a;for(let e of r)a+=e;a=t.getNextSet(a)}while(s!==`*`);this.decodeRowResult=this.decodeRowResult.substring(0,this.decodeRowResult.length-1);let l=0;for(let e of r)l+=e;let u=a-c-l;if(a!==o&&u*2<l)throw new k;if(this.usingCheckDigit){let e=this.decodeRowResult.length-1,t=0;for(let n=0;n<e;n++)t+=Te.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(n));if(this.decodeRowResult.charAt(e)!==Te.ALPHABET_STRING.charAt(t%43))throw new d;this.decodeRowResult=this.decodeRowResult.substring(0,e)}if(this.decodeRowResult.length===0)throw new k;let f;f=this.extendedMode?Te.decodeExtended(this.decodeRowResult):this.decodeRowResult;let p=(i[1]+i[0])/2,m=c+l/2;return new R(f,null,0,[new H(p,e),new H(m,e)],B.CODE_39,new Date().getTime())}static findAsteriskPattern(e,t){let n=e.getSize(),r=e.getNextSet(0),i=0,a=r,o=!1,s=t.length;for(let c=r;c<n;c++)if(e.get(c)!==o)t[i]++;else{if(i===s-1){if(this.toNarrowWidePattern(t)===Te.ASTERISK_ENCODING&&e.isRange(Math.max(0,a-Math.floor((c-a)/2)),a,!1))return[a,c];a+=t[0]+t[1],t.copyWithin(0,2,2+i-1),t[i-1]=0,t[i]=0,i--}else i++;t[i]=1,o=!o}throw new k}static toNarrowWidePattern(e){let t=e.length,n=0,r;do{let i=2147483647;for(let t of e)t<i&&t>n&&(i=t);n=i,r=0;let a=0,o=0;for(let i=0;i<t;i++){let s=e[i];s>n&&(o|=1<<t-1-i,r++,a+=s)}if(r===3){for(let i=0;i<t&&r>0;i++){let t=e[i];if(t>n&&(r--,t*2>=a))return-1}return o}}while(r>3);return-1}static patternToChar(e){for(let t=0;t<Te.CHARACTER_ENCODINGS.length;t++)if(Te.CHARACTER_ENCODINGS[t]===e)return Te.ALPHABET_STRING.charAt(t);if(e===Te.ASTERISK_ENCODING)return`*`;throw new k}static decodeExtended(e){let t=e.length,n=``;for(let r=0;r<t;r++){let t=e.charAt(r);if(t===`+`||t===`$`||t===`%`||t===`/`){let i=e.charAt(r+1),a=`\0`;switch(t){case`+`:if(i>=`A`&&i<=`Z`)a=String.fromCharCode(i.charCodeAt(0)+32);else throw new x;break;case`$`:if(i>=`A`&&i<=`Z`)a=String.fromCharCode(i.charCodeAt(0)-64);else throw new x;break;case`%`:if(i>=`A`&&i<=`E`)a=String.fromCharCode(i.charCodeAt(0)-38);else if(i>=`F`&&i<=`J`)a=String.fromCharCode(i.charCodeAt(0)-11);else if(i>=`K`&&i<=`O`)a=String.fromCharCode(i.charCodeAt(0)+16);else if(i>=`P`&&i<=`T`)a=String.fromCharCode(i.charCodeAt(0)+43);else if(i===`U`)a=`\0`;else if(i===`V`)a=`@`;else if(i===`W`)a="`";else if(i===`X`||i===`Y`||i===`Z`)a=``;else throw new x;break;case`/`:if(i>=`A`&&i<=`O`)a=String.fromCharCode(i.charCodeAt(0)-32);else if(i===`Z`)a=`:`;else throw new x;break}n+=a,r++}else n+=t}return n}}Te.ALPHABET_STRING=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%`,Te.CHARACTER_ENCODINGS=[52,289,97,352,49,304,112,37,292,100,265,73,328,25,280,88,13,268,76,28,259,67,322,19,274,82,7,262,70,22,385,193,448,145,400,208,133,388,196,168,162,138,42],Te.ASTERISK_ENCODING=148;class Ee extends Ce{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,t,n){let r=this.decodeStart(t),i=this.decodeEnd(t),a=new D;Ee.decodeMiddle(t,r[1],i[0],a);let o=a.toString(),s=null;n!=null&&(s=n.get(b.ALLOWED_LENGTHS)),s??=Ee.DEFAULT_ALLOWED_LENGTHS;let c=o.length,l=!1,u=0;for(let e of s){if(c===e){l=!0;break}e>u&&(u=e)}if(!l&&c>u&&(l=!0),!l)throw new x;return new R(o,null,0,[new H(r[1],e),new H(i[0],e)],B.ITF,new Date().getTime())}static decodeMiddle(e,t,n,r){let i=new Int32Array(10),a=new Int32Array(5),o=new Int32Array(5);for(i.fill(0),a.fill(0),o.fill(0);t<n;){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=Ee.decodeDigit(a);r.append(n.toString()),n=this.decodeDigit(o),r.append(n.toString()),i.forEach(function(e){t+=e})}}decodeStart(e){let t=Ee.skipWhiteSpace(e),n=Ee.findGuardPattern(e,t,Ee.START_PATTERN);return this.narrowLineWidth=(n[1]-n[0])/4,this.validateQuietZone(e,n[0]),n}validateQuietZone(e,t){let n=this.narrowLineWidth*10;n=n<t?n:t;for(let r=t-1;n>0&&r>=0&&!e.get(r);r--)n--;if(n!==0)throw new k}static skipWhiteSpace(e){let t=e.getSize(),n=e.getNextSet(0);if(n===t)throw new k;return n}decodeEnd(e){e.reverse();try{let t=Ee.skipWhiteSpace(e),n;try{n=Ee.findGuardPattern(e,t,Ee.END_PATTERN_REVERSED[0])}catch(r){r instanceof k&&(n=Ee.findGuardPattern(e,t,Ee.END_PATTERN_REVERSED[1]))}this.validateQuietZone(e,n[0]);let r=n[0];return n[0]=e.getSize()-n[1],n[1]=e.getSize()-r,n}finally{e.reverse()}}static findGuardPattern(e,t,n){let r=n.length,i=new Int32Array(r),a=e.getSize(),o=!1,s=0,c=t;i.fill(0);for(let l=t;l<a;l++)if(e.get(l)!==o)i[s]++;else{if(s===r-1){if(Ce.patternMatchVariance(i,n,Ee.MAX_INDIVIDUAL_VARIANCE)<Ee.MAX_AVG_VARIANCE)return[c,l];c+=i[0]+i[1],p.arraycopy(i,2,i,0,s-1),i[s-1]=0,i[s]=0,s--}else s++;i[s]=1,o=!o}throw new k}static decodeDigit(e){let t=Ee.MAX_AVG_VARIANCE,n=-1,r=Ee.PATTERNS.length;for(let i=0;i<r;i++){let r=Ee.PATTERNS[i],a=Ce.patternMatchVariance(e,r,Ee.MAX_INDIVIDUAL_VARIANCE);a<t?(t=a,n=i):a===t&&(n=-1)}if(n>=0)return n%10;throw new k}}Ee.PATTERNS=[Int32Array.from([1,1,2,2,1]),Int32Array.from([2,1,1,1,2]),Int32Array.from([1,2,1,1,2]),Int32Array.from([2,2,1,1,1]),Int32Array.from([1,1,2,1,2]),Int32Array.from([2,1,2,1,1]),Int32Array.from([1,2,2,1,1]),Int32Array.from([1,1,1,2,2]),Int32Array.from([2,1,1,2,1]),Int32Array.from([1,2,1,2,1]),Int32Array.from([1,1,3,3,1]),Int32Array.from([3,1,1,1,3]),Int32Array.from([1,3,1,1,3]),Int32Array.from([3,3,1,1,1]),Int32Array.from([1,1,3,1,3]),Int32Array.from([3,1,3,1,1]),Int32Array.from([1,3,3,1,1]),Int32Array.from([1,1,1,3,3]),Int32Array.from([3,1,1,3,1]),Int32Array.from([1,3,1,3,1])],Ee.MAX_AVG_VARIANCE=.38,Ee.MAX_INDIVIDUAL_VARIANCE=.5,Ee.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],Ee.START_PATTERN=Int32Array.from([1,1,1,1]),Ee.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class De extends 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=De.findGuardPattern(e,r,!1,this.START_END_PATTERN,i);let a=n[0];r=n[1];let o=a-(r-a);o>=0&&(t=e.isRange(o,a,!1))}return n}static checkChecksum(e){return De.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return De.getStandardUPCEANChecksum(e.substring(0,t-1))===n}static getStandardUPCEANChecksum(e){let t=e.length,n=0;for(let r=t-1;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}n*=3;for(let r=t-2;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}return(1e3-n)%10}static decodeEnd(e,t){return De.findGuardPattern(e,t,!1,De.START_END_PATTERN,new Int32Array(De.START_END_PATTERN.length).fill(0))}static findGuardPatternWithoutCounters(e,t,n,r){return this.findGuardPattern(e,t,n,r,new Int32Array(r.length))}static findGuardPattern(e,t,n,r,i){let a=e.getSize();t=n?e.getNextUnset(t):e.getNextSet(t);let o=0,s=t,c=r.length,l=n;for(let n=t;n<a;n++)if(e.get(n)!==l)i[o]++;else{if(o===c-1){if(Ce.patternMatchVariance(i,r,De.MAX_INDIVIDUAL_VARIANCE)<De.MAX_AVG_VARIANCE)return Int32Array.from([s,n]);s+=i[0]+i[1];let e=i.slice(2,i.length-1);for(let t=0;t<o-1;t++)i[t]=e[t];i[o-1]=0,i[o]=0,o--}else o++;i[o]=1,l=!l}throw new k}static decodeDigit(e,t,n,r){this.recordPattern(e,n,t);let i=this.MAX_AVG_VARIANCE,a=-1,o=r.length;for(let e=0;e<o;e++){let n=r[e],o=Ce.patternMatchVariance(t,n,De.MAX_INDIVIDUAL_VARIANCE);o<i&&(i=o,a=e)}if(a>=0)return a;throw new k}}De.MAX_AVG_VARIANCE=.48,De.MAX_INDIVIDUAL_VARIANCE=.7,De.START_END_PATTERN=Int32Array.from([1,1,1]),De.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),De.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),De.L_PATTERNS=[Int32Array.from([3,2,1,1]),Int32Array.from([2,2,2,1]),Int32Array.from([2,1,2,2]),Int32Array.from([1,4,1,1]),Int32Array.from([1,1,3,2]),Int32Array.from([1,2,3,1]),Int32Array.from([1,1,1,4]),Int32Array.from([1,3,1,2]),Int32Array.from([1,2,1,3]),Int32Array.from([3,1,1,2])];class Oe{constructor(){this.CHECK_DIGIT_ENCODINGS=[24,20,18,17,12,6,3,10,9,5],this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=``}decodeRow(e,t,n){let r=this.decodeRowStringBuffer,i=this.decodeMiddle(t,n,r),a=r.toString(),o=Oe.parseExtensionString(a),s=new R(a,null,0,[new H((n[0]+n[1])/2,e),new H(i,e)],B.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<5&&a<i;t++){let i=De.decodeDigit(e,r,a,De.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<4-t),t!==4&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==5)throw new k;let s=this.determineCheckDigit(o);if(Oe.extensionChecksum(n.toString())!==s)throw new k;return a}static extensionChecksum(e){let t=e.length,n=0;for(let r=t-2;r>=0;r-=2)n+=e.charAt(r).charCodeAt(0)-48;n*=3;for(let r=t-1;r>=0;r-=2)n+=e.charAt(r).charCodeAt(0)-48;return n*=3,n%10}determineCheckDigit(e){for(let t=0;t<10;t++)if(e===this.CHECK_DIGIT_ENCODINGS[t])return t;throw new k}static parseExtensionString(e){if(e.length!==5)return null;let t=Oe.parseExtension5String(e);return t==null?null:new Map([[te.SUGGESTED_PRICE,t]])}static parseExtension5String(e){let t;switch(e.charAt(0)){case`0`:t=`£`;break;case`5`:t=`$`;break;case`9`:switch(e){case`90000`:return null;case`99991`:return`0.00`;case`99990`:return`Used`}t=``;break;default:t=``;break}let n=parseInt(e.substring(1)),r=(n/100).toString(),i=n%100,a=i<10?`0`+i:i.toString();return t+r+`.`+a}}class ke{constructor(){this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=``}decodeRow(e,t,n){let r=this.decodeRowStringBuffer,i=this.decodeMiddle(t,n,r),a=r.toString(),o=ke.parseExtensionString(a),s=new R(a,null,0,[new H((n[0]+n[1])/2,e),new H(i,e)],B.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<2&&a<i;t++){let i=De.decodeDigit(e,r,a,De.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<1-t),t!==1&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==2||parseInt(n.toString())%4!==o)throw new k;return a}static parseExtensionString(e){return e.length===2?new Map([[te.ISSUE_NUMBER,parseInt(e)]]):null}}class Ae{static decodeRow(e,t,n){let r=De.findGuardPattern(t,n,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new Oe().decodeRow(e,t,r)}catch{return new ke().decodeRow(e,t,r)}}}Ae.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class je extends De{constructor(){super(),this.decodeRowStringBuffer=``,je.L_AND_G_PATTERNS=je.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let t=je.L_PATTERNS[e-10],n=new Int32Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[t.length-e-1];je.L_AND_G_PATTERNS[e]=n}}decodeRow(e,t,n){let r=je.findStartGuardPattern(t),i=n==null?null:n.get(b.NEED_RESULT_POINT_CALLBACK);if(i!=null){let t=new 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(!je.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=Ae.decodeRow(e,t,c[1]);g.putMetadata(te.UPC_EAN_EXTENSION,n.getText()),g.putAllMetadata(n.getResultMetadata()),g.addResultPoints(n.getResultPoints()),_=n.getText().length}catch{}let v=n==null?null:n.get(b.ALLOWED_EAN_EXTENSIONS);if(v!=null){let e=!1;for(let t in v)if(_.toString()===t){e=!0;break}if(!e)throw new k}return g}decodeEnd(e,t){return je.findGuardPattern(e,t,!1,je.START_END_PATTERN,new Int32Array(je.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return je.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return je.getStandardUPCEANChecksum(e.substring(0,t-1))===n}static getStandardUPCEANChecksum(e){let t=e.length,n=0;for(let r=t-1;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}n*=3;for(let r=t-2;r>=0;r-=2){let t=e.charAt(r).charCodeAt(0)-48;if(t<0||t>9)throw new x;n+=t}return(1e3-n)%10}}class Me extends je{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<6&&a<i;t++){let i=je.decodeDigit(e,r,a,je.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}n=Me.determineFirstDigit(n,o),a=je.findGuardPattern(e,a,!0,je.MIDDLE_PATTERN,new Int32Array(je.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<6&&a<i;t++){let t=je.decodeDigit(e,r,a,je.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return B.EAN_13}static determineFirstDigit(e,t){for(let n=0;n<10;n++)if(t===this.FIRST_DIGIT_ENCODINGS[n])return e=String.fromCharCode(48+n)+e,e;throw new k}}Me.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class Ne extends je{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1];for(let t=0;t<4&&a<i;t++){let t=je.decodeDigit(e,r,a,je.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}a=je.findGuardPattern(e,a,!0,je.MIDDLE_PATTERN,new Int32Array(je.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<4&&a<i;t++){let t=je.decodeDigit(e,r,a,je.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return B.EAN_8}}class Pe extends je{constructor(){super(...arguments),this.ean13Reader=new Me}getBarcodeFormat(){return B.UPC_A}decode(e,t){return this.maybeReturnResult(this.ean13Reader.decode(e))}decodeRow(e,t,n){return this.maybeReturnResult(this.ean13Reader.decodeRow(e,t,n))}decodeMiddle(e,t,n){return this.ean13Reader.decodeMiddle(e,t,n)}maybeReturnResult(e){let t=e.getText();if(t.charAt(0)===`0`){let n=new R(t.substring(1),null,null,e.getResultPoints(),B.UPC_A);return e.getResultMetadata()!=null&&n.putAllMetadata(e.getResultMetadata()),n}else throw new k}reset(){this.ean13Reader.reset()}}class Fe extends je{constructor(){super(),this.decodeMiddleCounters=new Int32Array(4)}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters.map(e=>e);r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<6&&a<i;t++){let i=Fe.decodeDigit(e,r,a,Fe.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}let s=Fe.determineNumSysAndCheckDigit(n,o);return{rowOffset:a,resultString:s}}decodeEnd(e,t){return Fe.findGuardPatternWithoutCounters(e,t,!0,Fe.MIDDLE_END_PATTERN)}checkChecksum(e){return je.checkChecksum(Fe.convertUPCEtoUPCA(e))}static determineNumSysAndCheckDigit(e,t){for(let n=0;n<=1;n++)for(let r=0;r<10;r++)if(t===this.NUMSYS_AND_CHECK_DIGIT_PATTERNS[n][r]){let t=String.fromCharCode(48+n),i=String.fromCharCode(48+r);return t+e+i}throw k.getNotFoundInstance()}getBarcodeFormat(){return B.UPC_E}static convertUPCEtoUPCA(e){let t=e.slice(1,7).split(``).map(e=>e.charCodeAt(0)),n=new D;n.append(e.charAt(0));let r=t[5];switch(r){case 0:case 1:case 2:n.appendChars(t,0,2),n.append(r),n.append(`0000`),n.appendChars(t,2,3);break;case 3:n.appendChars(t,0,3),n.append(`00000`),n.appendChars(t,3,2);break;case 4:n.appendChars(t,0,4),n.append(`00000`),n.append(t[4]);break;default:n.appendChars(t,0,5),n.append(`0000`),n.append(r);break}return e.length>=8&&n.append(e.charAt(7)),n.toString()}}Fe.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Fe.NUMSYS_AND_CHECK_DIGIT_PATTERNS=[Int32Array.from([56,52,50,49,44,38,35,42,41,37]),Int32Array.from([7,11,13,14,19,25,28,21,22,26])];class Ie extends Ce{constructor(e){super();let n=e==null?null:e.get(b.POSSIBLE_FORMATS),r=[];t(n)?(r.push(new Me),r.push(new Pe),r.push(new Ne),r.push(new Fe)):(n.indexOf(B.EAN_13)>-1&&r.push(new Me),n.indexOf(B.UPC_A)>-1&&r.push(new Pe),n.indexOf(B.EAN_8)>-1&&r.push(new Ne),n.indexOf(B.UPC_E)>-1&&r.push(new Fe)),this.readers=r}decodeRow(e,t,n){for(let r of this.readers)try{let i=r.decodeRow(e,t,n),a=i.getBarcodeFormat()===B.EAN_13&&i.getText().charAt(0)===`0`,o=n==null?null:n.get(b.POSSIBLE_FORMATS),s=o==null||o.includes(B.UPC_A);if(a&&s){let e=i.getRawBytes(),t=new R(i.getText().substring(1),e,e?e.length:null,i.getResultPoints(),B.UPC_A);return t.putAllMetadata(i.getResultMetadata()),t}return i}catch{}throw new k}reset(){for(let e of this.readers)e.reset()}}class Le 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],Le.MAX_INDIVIDUAL_VARIANCE)<Le.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>=Le.MIN_FINDER_PATTERN_RATIO&&n<=Le.MAX_FINDER_PATTERN_RATIO){let t=2**53-1,n=-(2**53-1);for(let r of e)r>n&&(n=r),r<t&&(t=r);return n<10*t}return!1}}Le.MAX_AVG_VARIANCE=.2,Le.MAX_INDIVIDUAL_VARIANCE=.45,Le.MIN_FINDER_PATTERN_RATIO=9.5/12,Le.MAX_FINDER_PATTERN_RATIO=12.5/14;class Re{constructor(e,t){this.value=e,this.checksumPortion=t}getValue(){return this.value}getChecksumPortion(){return this.checksumPortion}toString(){return this.value+`(`+this.checksumPortion+`)`}equals(e){if(!(e instanceof Re))return!1;let t=e;return this.value===t.value&&this.checksumPortion===t.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class ze{constructor(e,t,n,r,i){this.value=e,this.startEnd=t,this.value=e,this.startEnd=t,this.resultPoints=[],this.resultPoints.push(new 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 ze))return!1;let t=e;return this.value===t.value}hashCode(){return this.value}}class Be{constructor(){}static getRSSvalue(e,t,n){let r=0;for(let t of e)r+=t;let i=0,a=0,o=e.length;for(let s=0;s<o-1;s++){let c;for(c=1,a|=1<<s;c<e[s];c++,a&=~(1<<s)){let e=Be.combins(r-c-1,o-s-2);if(n&&a===0&&r-c-(o-s-1)>=o-s-1&&(e-=Be.combins(r-c-(o-s),o-s-2)),o-s-1>1){let n=0;for(let e=r-c-(o-s-2);e>t;e--)n+=Be.combins(r-c-e-1,o-s-3);e-=n*(o-1-s)}else r-c>t&&e--;i+=e}r-=c}return i}static combins(e,t){let n,r;e-t>t?(r=t,n=e-t):(r=e-t,n=t);let i=1,a=1;for(let t=e;t>n;t--)i*=t,a<=r&&(i/=a,a++);for(;a<=r;)i/=a,a++;return i}}class Ve{static buildBitArray(e){let t=e.length*2-1;e[e.length-1].getRightChar()??--t;let n=new v(12*t),r=0,i=e[0].getRightChar().getValue();for(let e=11;e>=0;--e)i&1<<e&&n.set(r),r++;for(let t=1;t<e.length;++t){let i=e[t],a=i.getLeftChar().getValue();for(let e=11;e>=0;--e)a&1<<e&&n.set(r),r++;if(i.getRightChar()!=null){let e=i.getRightChar().getValue();for(let t=11;t>=0;--t)e&1<<t&&n.set(r),r++}}return n}}class He{constructor(e,t){t?this.decodedInformation=null:(this.finished=e,this.decodedInformation=t)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class Ue{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class We extends Ue{constructor(e,t){super(e),this.value=t}getValue(){return this.value}isFNC1(){return this.value===We.FNC1}}We.FNC1=`$`;class Ge extends Ue{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 Ke extends Ue{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===Ke.FNC1}isSecondDigitFNC1(){return this.secondDigit===Ke.FNC1}isAnyFNC1(){return this.firstDigit===Ke.FNC1||this.secondDigit===Ke.FNC1}}Ke.FNC1=10;class qe{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 qe.TWO_DIGIT_DATA_LENGTH)if(n[0]===t)return n[1]===qe.VARIABLE_LENGTH?qe.processVariableAI(2,n[2],e):qe.processFixedAI(2,n[1],e);if(e.length<3)throw new k;let n=e.substring(0,3);for(let t of qe.THREE_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===qe.VARIABLE_LENGTH?qe.processVariableAI(3,t[2],e):qe.processFixedAI(3,t[1],e);for(let t of qe.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===qe.VARIABLE_LENGTH?qe.processVariableAI(4,t[2],e):qe.processFixedAI(4,t[1],e);if(e.length<4)throw new k;let r=e.substring(0,4);for(let t of qe.FOUR_DIGIT_DATA_LENGTH)if(t[0]===r)return t[1]===qe.VARIABLE_LENGTH?qe.processVariableAI(4,t[2],e):qe.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=qe.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=qe.parseFieldsInGeneralPurpose(o);return c==null?s:s+c}}qe.VARIABLE_LENGTH=[],qe.TWO_DIGIT_DATA_LENGTH=[[`00`,18],[`01`,14],[`02`,14],[`10`,qe.VARIABLE_LENGTH,20],[`11`,6],[`12`,6],[`13`,6],[`15`,6],[`17`,6],[`20`,2],[`21`,qe.VARIABLE_LENGTH,20],[`22`,qe.VARIABLE_LENGTH,29],[`30`,qe.VARIABLE_LENGTH,8],[`37`,qe.VARIABLE_LENGTH,8],[`90`,qe.VARIABLE_LENGTH,30],[`91`,qe.VARIABLE_LENGTH,30],[`92`,qe.VARIABLE_LENGTH,30],[`93`,qe.VARIABLE_LENGTH,30],[`94`,qe.VARIABLE_LENGTH,30],[`95`,qe.VARIABLE_LENGTH,30],[`96`,qe.VARIABLE_LENGTH,30],[`97`,qe.VARIABLE_LENGTH,3],[`98`,qe.VARIABLE_LENGTH,30],[`99`,qe.VARIABLE_LENGTH,30]],qe.THREE_DIGIT_DATA_LENGTH=[[`240`,qe.VARIABLE_LENGTH,30],[`241`,qe.VARIABLE_LENGTH,30],[`242`,qe.VARIABLE_LENGTH,6],[`250`,qe.VARIABLE_LENGTH,30],[`251`,qe.VARIABLE_LENGTH,30],[`253`,qe.VARIABLE_LENGTH,17],[`254`,qe.VARIABLE_LENGTH,20],[`400`,qe.VARIABLE_LENGTH,30],[`401`,qe.VARIABLE_LENGTH,30],[`402`,17],[`403`,qe.VARIABLE_LENGTH,30],[`410`,13],[`411`,13],[`412`,13],[`413`,13],[`414`,13],[`420`,qe.VARIABLE_LENGTH,20],[`421`,qe.VARIABLE_LENGTH,15],[`422`,3],[`423`,qe.VARIABLE_LENGTH,15],[`424`,3],[`425`,3],[`426`,3]],qe.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`,qe.VARIABLE_LENGTH,15],[`391`,qe.VARIABLE_LENGTH,18],[`392`,qe.VARIABLE_LENGTH,15],[`393`,qe.VARIABLE_LENGTH,18],[`703`,qe.VARIABLE_LENGTH,30]],qe.FOUR_DIGIT_DATA_LENGTH=[[`7001`,13],[`7002`,qe.VARIABLE_LENGTH,30],[`7003`,10],[`8001`,14],[`8002`,qe.VARIABLE_LENGTH,20],[`8003`,qe.VARIABLE_LENGTH,30],[`8004`,qe.VARIABLE_LENGTH,30],[`8005`,6],[`8006`,18],[`8007`,qe.VARIABLE_LENGTH,30],[`8008`,qe.VARIABLE_LENGTH,12],[`8018`,18],[`8020`,qe.VARIABLE_LENGTH,25],[`8100`,6],[`8101`,10],[`8102`,2],[`8110`,qe.VARIABLE_LENGTH,70],[`8200`,qe.VARIABLE_LENGTH,70]];class Je{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=qe.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 Ke(this.information.getSize(),Ke.FNC1,Ke.FNC1):new Ke(this.information.getSize(),t-1,Ke.FNC1)}let t=this.extractNumericValueFromBitArray(e,7),n=(t-8)/11,r=(t-8)%11;return new Ke(e+7,n,r)}extractNumericValueFromBitArray(e,t){return Je.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 Ge(this.current.getPosition(),this.buffer.toString(),n.getRemainingValue()):new Ge(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 Ge(this.current.getPosition(),this.buffer.toString()):new Ge(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new He(!0,t)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1())return new He(!0,new Ge(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getSecondDigit())}return this.isNumericToAlphaNumericLatch(this.current.getPosition())&&(this.current.setAlpha(),this.current.incrementPosition(4)),new He(!1)}parseIsoIec646Block(){for(;this.isStillIsoIec646(this.current.getPosition());){let e=this.decodeIsoIec646(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1())return new He(!0,new Ge(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setAlpha()),new He(!1)}parseAlphaBlock(){for(;this.isStillAlpha(this.current.getPosition());){let e=this.decodeAlphanumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1())return new He(!0,new Ge(this.current.getPosition(),this.buffer.toString()));this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setIsoIec646()),new He(!1)}isStillIsoIec646(e){if(e+5>this.information.getSize())return!1;let t=this.extractNumericValueFromBitArray(e,5);if(t>=5&&t<16)return!0;if(e+7>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<116)return!0;if(e+8>this.information.getSize())return!1;let r=this.extractNumericValueFromBitArray(e,8);return r>=232&&r<253}decodeIsoIec646(e){let t=this.extractNumericValueFromBitArray(e,5);if(t===15)return new We(e+5,We.FNC1);if(t>=5&&t<15)return new We(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<90)return new We(e+7,``+(n+1));if(n>=90&&n<116)return new We(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 We(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 We(e+5,We.FNC1);if(t>=5&&t<15)return new We(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,6);if(n>=32&&n<58)return new We(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 We(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 Ye{constructor(e){this.information=e,this.generalDecoder=new Je(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class Xe extends Ye{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)}Xe.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)}}Xe.GTIN_SIZE=40;class Ze extends Xe{constructor(e){super(e)}parseInformation(){let e=new D;e.append(`(01)`);let t=e.length(),n=this.getGeneralDecoder().extractNumericValueFromBitArray(Ze.HEADER_SIZE,4);return e.append(n),this.encodeCompressedGtinWithoutAI(e,Ze.HEADER_SIZE+4,t),this.getGeneralDecoder().decodeAllCodes(e,Ze.HEADER_SIZE+44)}}Ze.HEADER_SIZE=4;class Qe extends Ye{constructor(e){super(e)}parseInformation(){let e=new D;return this.getGeneralDecoder().decodeAllCodes(e,Qe.HEADER_SIZE)}}Qe.HEADER_SIZE=5;class $e extends Xe{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 et extends $e{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=et.HEADER_SIZE+$e.GTIN_SIZE+et.WEIGHT_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,et.HEADER_SIZE),this.encodeCompressedWeight(e,et.HEADER_SIZE+$e.GTIN_SIZE,et.WEIGHT_SIZE),e.toString()}}et.HEADER_SIZE=5,et.WEIGHT_SIZE=15;class tt extends et{constructor(e){super(e)}addWeightCode(e,t){e.append(`(3103)`)}checkWeight(e){return e}}class nt extends et{constructor(e){super(e)}addWeightCode(e,t){t<1e4?e.append(`(3202)`):e.append(`(3203)`)}checkWeight(e){return e<1e4?e:e-1e4}}class rt extends Xe{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<rt.HEADER_SIZE+Xe.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,rt.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(rt.HEADER_SIZE+Xe.GTIN_SIZE,rt.LAST_DIGIT_SIZE);e.append(`(392`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().decodeGeneralPurposeField(rt.HEADER_SIZE+Xe.GTIN_SIZE+rt.LAST_DIGIT_SIZE,null);return e.append(n.getNewString()),e.toString()}}rt.HEADER_SIZE=8,rt.LAST_DIGIT_SIZE=2;class it extends Xe{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<it.HEADER_SIZE+Xe.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,it.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(it.HEADER_SIZE+Xe.GTIN_SIZE,it.LAST_DIGIT_SIZE);e.append(`(393`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(it.HEADER_SIZE+Xe.GTIN_SIZE+it.LAST_DIGIT_SIZE,it.FIRST_THREE_DIGITS_SIZE);n/100==0&&e.append(`0`),n/10==0&&e.append(`0`),e.append(n);let r=this.getGeneralDecoder().decodeGeneralPurposeField(it.HEADER_SIZE+Xe.GTIN_SIZE+it.LAST_DIGIT_SIZE+it.FIRST_THREE_DIGITS_SIZE,null);return e.append(r.getNewString()),e.toString()}}it.HEADER_SIZE=8,it.LAST_DIGIT_SIZE=2,it.FIRST_THREE_DIGITS_SIZE=10;class at extends $e{constructor(e,t,n){super(e),this.dateCode=n,this.firstAIdigits=t}parseInformation(){if(this.getInformation().getSize()!=at.HEADER_SIZE+at.GTIN_SIZE+at.WEIGHT_SIZE+at.DATE_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,at.HEADER_SIZE),this.encodeCompressedWeight(e,at.HEADER_SIZE+at.GTIN_SIZE,at.WEIGHT_SIZE),this.encodeCompressedDate(e,at.HEADER_SIZE+at.GTIN_SIZE+at.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,t){let n=this.getGeneralDecoder().extractNumericValueFromBitArray(t,at.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}}at.HEADER_SIZE=8,at.WEIGHT_SIZE=20,at.DATE_SIZE=16;function ot(e){try{if(e.get(1))return new Ze(e);if(!e.get(2))return new Qe(e);switch(Je.extractNumericValueFromBitArray(e,1,4)){case 4:return new tt(e);case 5:return new nt(e)}switch(Je.extractNumericValueFromBitArray(e,1,5)){case 12:return new rt(e);case 13:return new it(e)}switch(Je.extractNumericValueFromBitArray(e,1,7)){case 56:return new at(e,`310`,`11`);case 57:return new at(e,`320`,`11`);case 58:return new at(e,`310`,`13`);case 59:return new at(e,`320`,`13`);case 60:return new at(e,`310`,`15`);case 61:return new at(e,`320`,`15`);case 62:return new at(e,`310`,`17`);case 63:return new at(e,`320`,`17`)}}catch(t){throw console.log(t),new ce(`unknown decoder: `+e)}}class st{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 st?st.equalsOrNull(e.leftchar,t.leftchar)&&st.equalsOrNull(e.rightchar,t.rightchar)&&st.equalsOrNull(e.finderpattern,t.finderpattern):!1}static equalsOrNull(e,t){return e===null?t===null:st.equals(e,t)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class ct{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 ct?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 W extends Le{constructor(e){super(...arguments),this.pairs=Array(W.MAX_PAIRS),this.rows=[],this.startEnd=[2],this.verbose=e===!0}decodeRow(e,t,n){this.pairs.length=0,this.startFromEven=!1;try{return W.constructResult(this.decodeRow2pairs(e,t))}catch(e){this.verbose&&console.log(e)}return this.pairs.length=0,this.startFromEven=!0,W.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()),!W.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 W.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||W.isPartialRow(this.pairs,this.rows)||(this.rows.push(n,new ct(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(st.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=ot(Ve.buildBitArray(e)).parseInformation(),n=e[0].getFinderPattern().getResultPoints(),r=e[e.length-1].getFinderPattern().getResultPoints();return new R(t,null,null,[n[0],n[1],r[0],r[1]],B.RSS_EXPANDED,null)}checkChecksum(){let e=this.pairs.get(0),t=e.getLeftChar(),n=e.getRightChar();if(n==null)return!1;let r=n.getChecksumPortion(),i=2;for(let e=1;e<this.pairs.size();++e){let t=this.pairs.get(e);r+=t.getLeftChar().getChecksumPortion(),i++;let n=t.getRightChar();n!=null&&(r+=n.getChecksumPortion(),i++)}return r%=211,211*(i-4)+r==t.getValue()}static getNextSecondBar(e,t){let n;return e.get(t)?(n=e.getNextUnset(t),n=e.getNextSet(n)):(n=e.getNextSet(t),n=e.getNextUnset(n)),n}retrieveNextPair(e,t,n){let r=t.length%2==0;this.startFromEven&&(r=!r);let i,a=!0,o=-1;do this.findNextPair(e,t,o),i=this.parseFoundFinderPattern(e,n,r),i==null?o=W.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 st(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&&W.reverseCounters(r),W.isFinderPattern(r)){this.startEnd[0]=l,this.startEnd[1]=t;return}o&&W.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,W.FINDER_PATTERNS)}catch{return null}return new ze(s,[i,a],i,a,t)}decodeDataCharacter(e,t,n,r){let i=this.getDataCharacterCounters();for(let e=0;e<i.length;e++)i[e]=0;if(r)W.recordPatternInReverse(e,t.getStartEnd()[0],i);else{W.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(W.isNotA1left(t,n,r)){let t=W.WEIGHTS[d][2*e];p+=s[e]*t}f+=s[e]}let m=0;for(let e=c.length-1;e>=0;e--)if(W.isNotA1left(t,n,r)){let t=W.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,_=W.SYMBOL_WIDEST[g],v=9-_,y=Be.getRSSvalue(s,_,!0),b=Be.getRSSvalue(c,v,!1),x=W.EVEN_TOTAL_SUBSET[g],S=W.GSUM[g];return new Re(y*x+b+S,h)}static isNotA1left(e,t,n){return!(e.getValue()==0&&t&&n)}adjustOddEvenCounts(e){let t=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;W.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(i&&W.decrement(this.getOddCounts(),this.getOddRoundingErrors()),a){if(o)throw new k;W.increment(this.getEvenCounts(),this.getOddRoundingErrors())}o&&W.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}W.SYMBOL_WIDEST=[7,5,4,3,1],W.EVEN_TOTAL_SUBSET=[4,20,52,104,204],W.GSUM=[0,348,1388,2948,3988],W.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])],W.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]],W.FINDER_PAT_A=0,W.FINDER_PAT_B=1,W.FINDER_PAT_C=2,W.FINDER_PAT_D=3,W.FINDER_PAT_E=4,W.FINDER_PAT_F=5,W.FINDER_PATTERN_SEQUENCES=[[W.FINDER_PAT_A,W.FINDER_PAT_A],[W.FINDER_PAT_A,W.FINDER_PAT_B,W.FINDER_PAT_B],[W.FINDER_PAT_A,W.FINDER_PAT_C,W.FINDER_PAT_B,W.FINDER_PAT_D],[W.FINDER_PAT_A,W.FINDER_PAT_E,W.FINDER_PAT_B,W.FINDER_PAT_D,W.FINDER_PAT_C],[W.FINDER_PAT_A,W.FINDER_PAT_E,W.FINDER_PAT_B,W.FINDER_PAT_D,W.FINDER_PAT_D,W.FINDER_PAT_F],[W.FINDER_PAT_A,W.FINDER_PAT_E,W.FINDER_PAT_B,W.FINDER_PAT_D,W.FINDER_PAT_E,W.FINDER_PAT_F,W.FINDER_PAT_F],[W.FINDER_PAT_A,W.FINDER_PAT_A,W.FINDER_PAT_B,W.FINDER_PAT_B,W.FINDER_PAT_C,W.FINDER_PAT_C,W.FINDER_PAT_D,W.FINDER_PAT_D],[W.FINDER_PAT_A,W.FINDER_PAT_A,W.FINDER_PAT_B,W.FINDER_PAT_B,W.FINDER_PAT_C,W.FINDER_PAT_C,W.FINDER_PAT_D,W.FINDER_PAT_E,W.FINDER_PAT_E],[W.FINDER_PAT_A,W.FINDER_PAT_A,W.FINDER_PAT_B,W.FINDER_PAT_B,W.FINDER_PAT_C,W.FINDER_PAT_C,W.FINDER_PAT_D,W.FINDER_PAT_E,W.FINDER_PAT_F,W.FINDER_PAT_F],[W.FINDER_PAT_A,W.FINDER_PAT_A,W.FINDER_PAT_B,W.FINDER_PAT_B,W.FINDER_PAT_C,W.FINDER_PAT_D,W.FINDER_PAT_D,W.FINDER_PAT_E,W.FINDER_PAT_E,W.FINDER_PAT_F,W.FINDER_PAT_F]],W.MAX_PAIRS=11;class lt extends Re{constructor(e,t,n){super(e,t),this.count=0,this.finderPattern=n}getFinderPattern(){return this.finderPattern}getCount(){return this.count}incrementCount(){this.count++}}class ut extends Le{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,t,n){let r=this.decodePair(t,!1,e,n);ut.addOrTally(this.possibleLeftPairs,r),t.reverse();let i=this.decodePair(t,!0,e,n);ut.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&&ut.checkChecksum(e,t))return ut.constructResult(e,t)}throw new k}static addOrTally(e,t){if(t==null)return;let n=!1;for(let r of e)if(r.getValue()===t.getValue()){r.incrementCount(),n=!0;break}n||e.push(t)}reset(){this.possibleLeftPairs.length=0,this.possibleRightPairs.length=0}static constructResult(e,t){let n=4537077*e.getValue()+t.getValue(),r=new String(n).toString(),i=new D;for(let e=13-r.length;e>0;e--)i.append(`0`);i.append(r);let a=0;for(let e=0;e<13;e++){let t=i.charAt(e).charCodeAt(0)-48;a+=e&1?t:3*t}a=10-a%10,a===10&&(a=0),i.append(a.toString());let o=e.getFinderPattern().getResultPoints(),s=t.getFinderPattern().getResultPoints();return new R(i.toString(),null,0,[o[0],o[1],s[0],s[1]],B.RSS_14,new Date().getTime())}static checkChecksum(e,t){let n=(e.getChecksumPortion()+16*t.getChecksumPortion())%79,r=9*e.getFinderPattern().getValue()+t.getFinderPattern().getValue();return r>72&&r--,r>8&&r--,n===r}decodePair(e,t,n,r){try{let i=this.findFinderPattern(e,t),a=this.parseFoundFinderPattern(e,n,t,i),o=r==null?null:r.get(b.NEED_RESULT_POINT_CALLBACK);if(o!=null){let r=(i[0]+i[1])/2;t&&(r=e.getSize()-1-r),o.foundPossibleResultPoint(new H(r,n))}let s=this.decodeDataCharacter(e,a,!0),c=this.decodeDataCharacter(e,a,!1);return new lt(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=ut.OUTSIDE_ODD_WIDEST[e],n=9-t,r=Be.getRSSvalue(o,t,!1),i=Be.getRSSvalue(s,n,!0),a=ut.OUTSIDE_EVEN_TOTAL_SUBSET[e],c=ut.OUTSIDE_GSUM[e];return new Re(r*a+i+c,m)}else{if(p&1||p>10||p<4)throw new k;let e=(10-p)/2,t=ut.INSIDE_ODD_WIDEST[e],n=9-t,r=Be.getRSSvalue(o,t,!0),i=Be.getRSSvalue(s,n,!1),a=ut.INSIDE_ODD_TOTAL_SUBSET[e],c=ut.INSIDE_GSUM[e];return new Re(i*a+r+c,m)}}findFinderPattern(e,t){let n=this.getDecodeFinderCounters();n[0]=0,n[1]=0,n[2]=0,n[3]=0;let r=e.getSize(),i=!1,a=0;for(;a<r&&(i=!e.get(a),t!==i);)a++;let o=0,s=a;for(let t=a;t<r;t++)if(e.get(t)!==i)n[o]++;else{if(o===3){if(Le.isFinderPattern(n))return[s,t];s+=n[0]+n[1],n[0]=n[2],n[1]=n[3],n[2]=0,n[3]=0,o--}else o++;n[o]=1,i=!i}throw new k}parseFoundFinderPattern(e,t,n,r){let i=e.get(r[0]),a=r[0]-1;for(;a>=0&&i!==e.get(a);)a--;a++;let o=r[0]-a,s=this.getDecodeFinderCounters(),c=new Int32Array(s.length);p.arraycopy(s,0,c,1,s.length-1),c[0]=o;let l=this.parseFinderValue(c,ut.FINDER_PATTERNS),u=a,d=r[1];return n&&(u=e.getSize()-1-u,d=e.getSize()-1-d),new ze(l,[a,r[1]],u,d,t)}adjustOddEvenCounts(e,t){let n=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;Le.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&Le.decrement(this.getOddCounts(),this.getOddRoundingErrors()),o){if(s)throw new k;Le.increment(this.getEvenCounts(),this.getOddRoundingErrors())}s&&Le.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}ut.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],ut.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],ut.OUTSIDE_GSUM=[0,161,961,2015,2715],ut.INSIDE_GSUM=[0,336,1036,1516],ut.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],ut.INSIDE_ODD_WIDEST=[2,4,6,8],ut.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 dt 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(B.EAN_13)||n.includes(B.UPC_A)||n.includes(B.EAN_8)||n.includes(B.UPC_E))&&this.readers.push(new Ie(e)),n.includes(B.CODE_39)&&this.readers.push(new Te(r)),n.includes(B.CODE_128)&&this.readers.push(new we),n.includes(B.ITF)&&this.readers.push(new Ee),n.includes(B.RSS_14)&&this.readers.push(new ut),n.includes(B.RSS_EXPANDED)&&this.readers.push(new W(this.verbose))):(this.readers.push(new Ie(e)),this.readers.push(new Te),this.readers.push(new Ie(e)),this.readers.push(new we),this.readers.push(new Ee),this.readers.push(new ut),this.readers.push(new W(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 ft extends L{constructor(e=500,t){super(new dt(t),e,t)}}class pt{constructor(e,t,n){this.ecCodewords=e,this.ecBlocks=[t],n&&this.ecBlocks.push(n)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class mt{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class ht{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 ht.VERSIONS)if(n.symbolSizeRows===e&&n.symbolSizeColumns===t)return n;throw new x}toString(){return``+this.versionNumber}static buildVersions(){return[new ht(1,10,10,8,8,new pt(5,new mt(1,3))),new ht(2,12,12,10,10,new pt(7,new mt(1,5))),new ht(3,14,14,12,12,new pt(10,new mt(1,8))),new ht(4,16,16,14,14,new pt(12,new mt(1,12))),new ht(5,18,18,16,16,new pt(14,new mt(1,18))),new ht(6,20,20,18,18,new pt(18,new mt(1,22))),new ht(7,22,22,20,20,new pt(20,new mt(1,30))),new ht(8,24,24,22,22,new pt(24,new mt(1,36))),new ht(9,26,26,24,24,new pt(28,new mt(1,44))),new ht(10,32,32,14,14,new pt(36,new mt(1,62))),new ht(11,36,36,16,16,new pt(42,new mt(1,86))),new ht(12,40,40,18,18,new pt(48,new mt(1,114))),new ht(13,44,44,20,20,new pt(56,new mt(1,144))),new ht(14,48,48,22,22,new pt(68,new mt(1,174))),new ht(15,52,52,24,24,new pt(42,new mt(2,102))),new ht(16,64,64,14,14,new pt(56,new mt(2,140))),new ht(17,72,72,16,16,new pt(36,new mt(4,92))),new ht(18,80,80,18,18,new pt(48,new mt(4,114))),new ht(19,88,88,20,20,new pt(56,new mt(4,144))),new ht(20,96,96,22,22,new pt(68,new mt(4,174))),new ht(21,104,104,24,24,new pt(56,new mt(6,136))),new ht(22,120,120,18,18,new pt(68,new mt(6,175))),new ht(23,132,132,20,20,new pt(62,new mt(8,163))),new ht(24,144,144,22,22,new pt(62,new mt(8,156),new mt(2,155))),new ht(25,8,18,6,16,new pt(7,new mt(1,5))),new ht(26,8,32,6,14,new pt(11,new mt(1,10))),new ht(27,12,26,10,24,new pt(14,new mt(1,16))),new ht(28,12,36,10,16,new pt(18,new mt(1,22))),new ht(29,16,36,14,16,new pt(24,new mt(1,32))),new ht(30,16,48,14,22,new pt(28,new mt(1,49)))]}}ht.VERSIONS=ht.buildVersions();class gt{constructor(e){let t=e.getHeight();if(t<8||t>144||t&1)throw new x;this.version=gt.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 ht.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 _t{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 _t(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 vt{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 yt;(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`})(yt||={});class bt{static decode(e){let t=new vt(e),n=new D,r=new D,i=[],a=yt.ASCII_ENCODE;do if(a===yt.ASCII_ENCODE)a=this.decodeAsciiSegment(t,n,r);else{switch(a){case yt.C40_ENCODE:this.decodeC40Segment(t,n);break;case yt.TEXT_ENCODE:this.decodeTextSegment(t,n);break;case yt.ANSIX12_ENCODE:this.decodeAnsiX12Segment(t,n);break;case yt.EDIFACT_ENCODE:this.decodeEdifactSegment(t,n);break;case yt.BASE256_ENCODE:this.decodeBase256Segment(t,n,i);break;default:throw new x}a=yt.ASCII_ENCODE}while(a!==yt.PAD_ENCODE&&t.available()>0);return r.length()>0&&n.append(r.toString()),new ne(e,n.toString(),i.length===0?null:i,null)}static decodeAsciiSegment(e,t,n){let r=!1;do{let i=e.readBits(8);if(i===0)throw new x;if(i<=128)return r&&(i+=128),t.append(String.fromCharCode(i-1)),yt.ASCII_ENCODE;if(i===129)return yt.PAD_ENCODE;if(i<=229){let e=i-130;e<10&&t.append(`0`),t.append(``+e)}else switch(i){case 230:return yt.C40_ENCODE;case 231:return yt.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 yt.ANSIX12_ENCODE;case 239:return yt.TEXT_ENCODE;case 240:return yt.EDIFACT_ENCODE;case 241:break;default:if(i!==254||e.available()!==0)throw new x;break}}while(e.available()>0);return yt.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}}bt.C40_BASIC_SET_CHARS=`*** 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``),bt.C40_SHIFT2_SET_CHARS=`!"#$%&'()*+,-./:;<=>?@[\\]^_`.split(``),bt.TEXT_BASIC_SET_CHARS=`*** 0123456789abcdefghijklmnopqrstuvwxyz`.split(``),bt.TEXT_SHIFT2_SET_CHARS=bt.C40_SHIFT2_SET_CHARS,bt.TEXT_SHIFT3_SET_CHARS="`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~".split(``);class xt{constructor(){this.rsDecoder=new le(oe.DATA_MATRIX_FIELD_256)}decode(e){let t=new gt(e),n=t.getVersion(),r=t.readCodewords(),i=_t.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 bt.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 St{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(St.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=St.shiftPoint(n,r,(a+1)*4),s=St.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=St.shiftPoint(t,n,(o+1)*4),c=St.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=St.shiftPoint(t,n,o*4),c=St.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=St.moveAway(t,l,u),n=St.moveAway(n,l,u),r=St.moveAway(r,l,u),i=St.moveAway(i,l,u);let d,f;return s=St.shiftPoint(t,n,o*4),s=St.shiftPoint(s,i,a*4),d=St.shiftPoint(n,t,o*4),d=St.shiftPoint(d,r,a*4),c=St.shiftPoint(r,i,o*4),c=St.shiftPoint(c,n,a*4),f=St.shiftPoint(i,r,o*4),f=St.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 Ct{constructor(){this.decoder=new xt}decode(e,t=null){let n,r;if(t!=null&&t.has(b.PURE_BARCODE)){let t=Ct.extractPureBits(e.getBlackMatrix());n=this.decoder.decode(t),r=Ct.NO_POINTS}else{let t=new St(e.getBlackMatrix()).detect();n=this.decoder.decode(t.getBits()),r=t.getPoints()}let i=n.getRawBytes(),a=new R(n.getText(),i,8*i.length,r,B.DATA_MATRIX,p.currentTimeMillis()),o=n.getByteSegments();o!=null&&a.putMetadata(te.BYTE_SEGMENTS,o);let s=n.getECLevel();return s!=null&&a.putMetadata(te.ERROR_CORRECTION_LEVEL,s),a}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t==null||n==null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=(n[0]-o+1)/r,c=(a-i+1)/r;if(s<=0||c<=0)throw new k;let l=r/2;i+=l,o+=l;let u=new O(s,c);for(let t=0;t<c;t++){let n=i+t*r;for(let i=0;i<s;i++)e.get(o+i*r,n)&&u.set(i,t)}return u}static moduleSize(e,t){let n=t.getWidth(),r=e[0],i=e[1];for(;r<n&&t.get(r,i);)r++;if(r===n)throw new k;let a=r-e[0];if(a===0)throw new k;return a}}Ct.NO_POINTS=[];class wt extends L{constructor(e=500){super(new Ct,e)}}var Tt;(function(e){e[e.L=0]=`L`,e[e.M=1]=`M`,e[e.Q=2]=`Q`,e[e.H=3]=`H`})(Tt||={});class Et{constructor(e,t,n){this.value=e,this.stringValue=t,this.bits=n,Et.FOR_BITS.set(n,this),Et.FOR_VALUE.set(e,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(e){switch(e){case`L`:return Et.L;case`M`:return Et.M;case`Q`:return Et.Q;case`H`:return Et.H;default:throw new c(e+`not available`)}}toString(){return this.stringValue}equals(e){if(!(e instanceof Et))return!1;let t=e;return this.value===t.value}static forBits(e){if(e<0||e>=Et.FOR_BITS.size)throw new l;return Et.FOR_BITS.get(e)}}Et.FOR_BITS=new Map,Et.FOR_VALUE=new Map,Et.L=new Et(Tt.L,`L`,1),Et.M=new Et(Tt.M,`M`,0),Et.Q=new Et(Tt.Q,`Q`,3),Et.H=new Et(Tt.H,`H`,2);class Dt{constructor(e){this.errorCorrectionLevel=Et.forBits(e>>3&3),this.dataMask=e&7}static numBitsDiffering(e,t){return _.bitCount(e^t)}static decodeFormatInformation(e,t){let n=Dt.doDecodeFormatInformation(e,t);return n===null?Dt.doDecodeFormatInformation(e^Dt.FORMAT_INFO_MASK_QR,t^Dt.FORMAT_INFO_MASK_QR):n}static doDecodeFormatInformation(e,t){let n=2**53-1,r=0;for(let i of Dt.FORMAT_INFO_DECODE_LOOKUP){let a=i[0];if(a===e||a===t)return new Dt(i[1]);let o=Dt.numBitsDiffering(e,a);o<n&&(r=i[1],n=o),e!==t&&(o=Dt.numBitsDiffering(t,a),o<n&&(r=i[1],n=o))}return n<=3?new Dt(r):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(e){if(!(e instanceof Dt))return!1;let t=e;return this.errorCorrectionLevel===t.errorCorrectionLevel&&this.dataMask===t.dataMask}}Dt.FORMAT_INFO_MASK_QR=21522,Dt.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 G{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 K{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class Ot{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 Ot.VERSIONS[e-1]}static decodeVersionInformation(e){let t=2**53-1,n=0;for(let r=0;r<Ot.VERSION_DECODE_INFO.length;r++){let i=Ot.VERSION_DECODE_INFO[r];if(i===e)return Ot.getVersionForNumber(r+7);let a=Dt.numBitsDiffering(e,i);a<t&&(n=r+7,t=a)}return t<=3?Ot.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}}Ot.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]),Ot.VERSIONS=[new Ot(1,new Int32Array,new G(7,new K(1,19)),new G(10,new K(1,16)),new G(13,new K(1,13)),new G(17,new K(1,9))),new Ot(2,Int32Array.from([6,18]),new G(10,new K(1,34)),new G(16,new K(1,28)),new G(22,new K(1,22)),new G(28,new K(1,16))),new Ot(3,Int32Array.from([6,22]),new G(15,new K(1,55)),new G(26,new K(1,44)),new G(18,new K(2,17)),new G(22,new K(2,13))),new Ot(4,Int32Array.from([6,26]),new G(20,new K(1,80)),new G(18,new K(2,32)),new G(26,new K(2,24)),new G(16,new K(4,9))),new Ot(5,Int32Array.from([6,30]),new G(26,new K(1,108)),new G(24,new K(2,43)),new G(18,new K(2,15),new K(2,16)),new G(22,new K(2,11),new K(2,12))),new Ot(6,Int32Array.from([6,34]),new G(18,new K(2,68)),new G(16,new K(4,27)),new G(24,new K(4,19)),new G(28,new K(4,15))),new Ot(7,Int32Array.from([6,22,38]),new G(20,new K(2,78)),new G(18,new K(4,31)),new G(18,new K(2,14),new K(4,15)),new G(26,new K(4,13),new K(1,14))),new Ot(8,Int32Array.from([6,24,42]),new G(24,new K(2,97)),new G(22,new K(2,38),new K(2,39)),new G(22,new K(4,18),new K(2,19)),new G(26,new K(4,14),new K(2,15))),new Ot(9,Int32Array.from([6,26,46]),new G(30,new K(2,116)),new G(22,new K(3,36),new K(2,37)),new G(20,new K(4,16),new K(4,17)),new G(24,new K(4,12),new K(4,13))),new Ot(10,Int32Array.from([6,28,50]),new G(18,new K(2,68),new K(2,69)),new G(26,new K(4,43),new K(1,44)),new G(24,new K(6,19),new K(2,20)),new G(28,new K(6,15),new K(2,16))),new Ot(11,Int32Array.from([6,30,54]),new G(20,new K(4,81)),new G(30,new K(1,50),new K(4,51)),new G(28,new K(4,22),new K(4,23)),new G(24,new K(3,12),new K(8,13))),new Ot(12,Int32Array.from([6,32,58]),new G(24,new K(2,92),new K(2,93)),new G(22,new K(6,36),new K(2,37)),new G(26,new K(4,20),new K(6,21)),new G(28,new K(7,14),new K(4,15))),new Ot(13,Int32Array.from([6,34,62]),new G(26,new K(4,107)),new G(22,new K(8,37),new K(1,38)),new G(24,new K(8,20),new K(4,21)),new G(22,new K(12,11),new K(4,12))),new Ot(14,Int32Array.from([6,26,46,66]),new G(30,new K(3,115),new K(1,116)),new G(24,new K(4,40),new K(5,41)),new G(20,new K(11,16),new K(5,17)),new G(24,new K(11,12),new K(5,13))),new Ot(15,Int32Array.from([6,26,48,70]),new G(22,new K(5,87),new K(1,88)),new G(24,new K(5,41),new K(5,42)),new G(30,new K(5,24),new K(7,25)),new G(24,new K(11,12),new K(7,13))),new Ot(16,Int32Array.from([6,26,50,74]),new G(24,new K(5,98),new K(1,99)),new G(28,new K(7,45),new K(3,46)),new G(24,new K(15,19),new K(2,20)),new G(30,new K(3,15),new K(13,16))),new Ot(17,Int32Array.from([6,30,54,78]),new G(28,new K(1,107),new K(5,108)),new G(28,new K(10,46),new K(1,47)),new G(28,new K(1,22),new K(15,23)),new G(28,new K(2,14),new K(17,15))),new Ot(18,Int32Array.from([6,30,56,82]),new G(30,new K(5,120),new K(1,121)),new G(26,new K(9,43),new K(4,44)),new G(28,new K(17,22),new K(1,23)),new G(28,new K(2,14),new K(19,15))),new Ot(19,Int32Array.from([6,30,58,86]),new G(28,new K(3,113),new K(4,114)),new G(26,new K(3,44),new K(11,45)),new G(26,new K(17,21),new K(4,22)),new G(26,new K(9,13),new K(16,14))),new Ot(20,Int32Array.from([6,34,62,90]),new G(28,new K(3,107),new K(5,108)),new G(26,new K(3,41),new K(13,42)),new G(30,new K(15,24),new K(5,25)),new G(28,new K(15,15),new K(10,16))),new Ot(21,Int32Array.from([6,28,50,72,94]),new G(28,new K(4,116),new K(4,117)),new G(26,new K(17,42)),new G(28,new K(17,22),new K(6,23)),new G(30,new K(19,16),new K(6,17))),new Ot(22,Int32Array.from([6,26,50,74,98]),new G(28,new K(2,111),new K(7,112)),new G(28,new K(17,46)),new G(30,new K(7,24),new K(16,25)),new G(24,new K(34,13))),new Ot(23,Int32Array.from([6,30,54,78,102]),new G(30,new K(4,121),new K(5,122)),new G(28,new K(4,47),new K(14,48)),new G(30,new K(11,24),new K(14,25)),new G(30,new K(16,15),new K(14,16))),new Ot(24,Int32Array.from([6,28,54,80,106]),new G(30,new K(6,117),new K(4,118)),new G(28,new K(6,45),new K(14,46)),new G(30,new K(11,24),new K(16,25)),new G(30,new K(30,16),new K(2,17))),new Ot(25,Int32Array.from([6,32,58,84,110]),new G(26,new K(8,106),new K(4,107)),new G(28,new K(8,47),new K(13,48)),new G(30,new K(7,24),new K(22,25)),new G(30,new K(22,15),new K(13,16))),new Ot(26,Int32Array.from([6,30,58,86,114]),new G(28,new K(10,114),new K(2,115)),new G(28,new K(19,46),new K(4,47)),new G(28,new K(28,22),new K(6,23)),new G(30,new K(33,16),new K(4,17))),new Ot(27,Int32Array.from([6,34,62,90,118]),new G(30,new K(8,122),new K(4,123)),new G(28,new K(22,45),new K(3,46)),new G(30,new K(8,23),new K(26,24)),new G(30,new K(12,15),new K(28,16))),new Ot(28,Int32Array.from([6,26,50,74,98,122]),new G(30,new K(3,117),new K(10,118)),new G(28,new K(3,45),new K(23,46)),new G(30,new K(4,24),new K(31,25)),new G(30,new K(11,15),new K(31,16))),new Ot(29,Int32Array.from([6,30,54,78,102,126]),new G(30,new K(7,116),new K(7,117)),new G(28,new K(21,45),new K(7,46)),new G(30,new K(1,23),new K(37,24)),new G(30,new K(19,15),new K(26,16))),new Ot(30,Int32Array.from([6,26,52,78,104,130]),new G(30,new K(5,115),new K(10,116)),new G(28,new K(19,47),new K(10,48)),new G(30,new K(15,24),new K(25,25)),new G(30,new K(23,15),new K(25,16))),new Ot(31,Int32Array.from([6,30,56,82,108,134]),new G(30,new K(13,115),new K(3,116)),new G(28,new K(2,46),new K(29,47)),new G(30,new K(42,24),new K(1,25)),new G(30,new K(23,15),new K(28,16))),new Ot(32,Int32Array.from([6,34,60,86,112,138]),new G(30,new K(17,115)),new G(28,new K(10,46),new K(23,47)),new G(30,new K(10,24),new K(35,25)),new G(30,new K(19,15),new K(35,16))),new Ot(33,Int32Array.from([6,30,58,86,114,142]),new G(30,new K(17,115),new K(1,116)),new G(28,new K(14,46),new K(21,47)),new G(30,new K(29,24),new K(19,25)),new G(30,new K(11,15),new K(46,16))),new Ot(34,Int32Array.from([6,34,62,90,118,146]),new G(30,new K(13,115),new K(6,116)),new G(28,new K(14,46),new K(23,47)),new G(30,new K(44,24),new K(7,25)),new G(30,new K(59,16),new K(1,17))),new Ot(35,Int32Array.from([6,30,54,78,102,126,150]),new G(30,new K(12,121),new K(7,122)),new G(28,new K(12,47),new K(26,48)),new G(30,new K(39,24),new K(14,25)),new G(30,new K(22,15),new K(41,16))),new Ot(36,Int32Array.from([6,24,50,76,102,128,154]),new G(30,new K(6,121),new K(14,122)),new G(28,new K(6,47),new K(34,48)),new G(30,new K(46,24),new K(10,25)),new G(30,new K(2,15),new K(64,16))),new Ot(37,Int32Array.from([6,28,54,80,106,132,158]),new G(30,new K(17,122),new K(4,123)),new G(28,new K(29,46),new K(14,47)),new G(30,new K(49,24),new K(10,25)),new G(30,new K(24,15),new K(46,16))),new Ot(38,Int32Array.from([6,32,58,84,110,136,162]),new G(30,new K(4,122),new K(18,123)),new G(28,new K(13,46),new K(32,47)),new G(30,new K(48,24),new K(14,25)),new G(30,new K(42,15),new K(32,16))),new Ot(39,Int32Array.from([6,26,54,82,110,138,166]),new G(30,new K(20,117),new K(4,118)),new G(28,new K(40,47),new K(7,48)),new G(30,new K(43,24),new K(22,25)),new G(30,new K(10,15),new K(67,16))),new Ot(40,Int32Array.from([6,30,58,86,114,142,170]),new G(30,new K(19,118),new K(6,119)),new G(28,new K(18,47),new K(31,48)),new G(30,new K(34,24),new K(34,25)),new G(30,new K(20,15),new K(61,16)))];var kt;(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`})(kt||={});class At{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)}}At.values=new Map([[kt.DATA_MASK_000,new At(kt.DATA_MASK_000,(e,t)=>(e+t&1)==0)],[kt.DATA_MASK_001,new At(kt.DATA_MASK_001,(e,t)=>(e&1)==0)],[kt.DATA_MASK_010,new At(kt.DATA_MASK_010,(e,t)=>t%3==0)],[kt.DATA_MASK_011,new At(kt.DATA_MASK_011,(e,t)=>(e+t)%3==0)],[kt.DATA_MASK_100,new At(kt.DATA_MASK_100,(e,t)=>(Math.floor(e/2)+Math.floor(t/3)&1)==0)],[kt.DATA_MASK_101,new At(kt.DATA_MASK_101,(e,t)=>e*t%6==0)],[kt.DATA_MASK_110,new At(kt.DATA_MASK_110,(e,t)=>e*t%6<3)],[kt.DATA_MASK_111,new At(kt.DATA_MASK_111,(e,t)=>(e+t+e*t%3&1)==0)]]);class jt{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=Dt.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 Ot.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=Ot.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=Ot.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=At.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=At.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 Mt{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 Mt(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 Nt;(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`})(Nt||={});class Pt{constructor(e,t,n,r){this.value=e,this.stringValue=t,this.characterCountBitsForVersions=n,this.bits=r,Pt.FOR_BITS.set(r,this),Pt.FOR_VALUE.set(e,this)}static forBits(e){let t=Pt.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 Pt))return!1;let t=e;return this.value===t.value}toString(){return this.stringValue}}Pt.FOR_BITS=new Map,Pt.FOR_VALUE=new Map,Pt.TERMINATOR=new Pt(Nt.TERMINATOR,`TERMINATOR`,Int32Array.from([0,0,0]),0),Pt.NUMERIC=new Pt(Nt.NUMERIC,`NUMERIC`,Int32Array.from([10,12,14]),1),Pt.ALPHANUMERIC=new Pt(Nt.ALPHANUMERIC,`ALPHANUMERIC`,Int32Array.from([9,11,13]),2),Pt.STRUCTURED_APPEND=new Pt(Nt.STRUCTURED_APPEND,`STRUCTURED_APPEND`,Int32Array.from([0,0,0]),3),Pt.BYTE=new Pt(Nt.BYTE,`BYTE`,Int32Array.from([8,16,16]),4),Pt.ECI=new Pt(Nt.ECI,`ECI`,Int32Array.from([0,0,0]),7),Pt.KANJI=new Pt(Nt.KANJI,`KANJI`,Int32Array.from([8,10,12]),8),Pt.FNC1_FIRST_POSITION=new Pt(Nt.FNC1_FIRST_POSITION,`FNC1_FIRST_POSITION`,Int32Array.from([0,0,0]),5),Pt.FNC1_SECOND_POSITION=new Pt(Nt.FNC1_SECOND_POSITION,`FNC1_SECOND_POSITION`,Int32Array.from([0,0,0]),9),Pt.HANZI=new Pt(Nt.HANZI,`HANZI`,Int32Array.from([8,10,12]),13);class Ft{static decode(e,t,n,r){let i=new vt(e),a=new D,o=[],s=-1,c=-1;try{let e=null,n=!1,l;do{if(i.available()<4)l=Pt.TERMINATOR;else{let e=i.readBits(4);l=Pt.forBits(e)}switch(l){case Pt.TERMINATOR:break;case Pt.FNC1_FIRST_POSITION:case Pt.FNC1_SECOND_POSITION:n=!0;break;case Pt.STRUCTURED_APPEND:if(i.available()<16)throw new x;s=i.readBits(8),c=i.readBits(8);break;case Pt.ECI:let u=Ft.parseECIValue(i);if(e=C.getCharacterSetECIByValue(u),e===null)throw new x;break;case Pt.HANZI:let d=i.readBits(4),f=i.readBits(l.getCharacterCountBits(t));d===Ft.GB2312_SUBSET&&Ft.decodeHanziSegment(i,a,f);break;default:let p=i.readBits(l.getCharacterCountBits(t));switch(l){case Pt.NUMERIC:Ft.decodeNumericSegment(i,a,p);break;case Pt.ALPHANUMERIC:Ft.decodeAlphanumericSegment(i,a,p,n);break;case Pt.BYTE:Ft.decodeByteSegment(i,a,p,e,o,r);break;case Pt.KANJI:Ft.decodeKanjiSegment(i,a,p);break;default:throw new x}break}}while(l!==Pt.TERMINATOR)}catch{throw new x}return new ne(e,a.toString(),o.length===0?null:o,n===null?null:n.toString(),s,c)}static decodeHanziSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/96<<8&4294967295|t%96;a<959?a+=41377:a+=42657,r[i]=a>>8&255,r[i+1]=a&255,i+=2,n--}try{t.append(T.decode(r,E.GB2312))}catch(e){throw new x(e)}}static decodeKanjiSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/192<<8&4294967295|t%192;a<7936?a+=33088:a+=49472,r[i]=a>>8,r[i+1]=a,i+=2,n--}try{t.append(T.decode(r,E.SHIFT_JIS))}catch(e){throw new x(e)}}static decodeByteSegment(e,t,n,r,i,a){if(8*n>e.available())throw new x;let o=new Uint8Array(n);for(let t=0;t<n;t++)o[t]=e.readBits(8);let s;s=r===null?E.guessEncoding(o,a):r.getName();try{t.append(T.decode(o,s))}catch(e){throw new x(e)}i.push(o)}static toAlphaNumericChar(e){if(e>=Ft.ALPHANUMERIC_CHARS.length)throw new x;return Ft.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(Ft.toAlphaNumericChar(Math.floor(r/45))),t.append(Ft.toAlphaNumericChar(r%45)),n-=2}if(n===1){if(e.available()<6)throw new x;t.append(Ft.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(Ft.toAlphaNumericChar(Math.floor(r/100))),t.append(Ft.toAlphaNumericChar(Math.floor(r/10)%10)),t.append(Ft.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(Ft.toAlphaNumericChar(Math.floor(n/10))),t.append(Ft.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(Ft.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}}Ft.ALPHANUMERIC_CHARS=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Ft.GB2312_SUBSET=1;class It{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 Lt{constructor(){this.rsDecoder=new le(oe.QR_CODE_FIELD_256)}decodeBooleanArray(e,t){return this.decodeBitMatrix(O.parseFromBooleanArray(e),t)}decodeBitMatrix(e,t){let n=new jt(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 It(!0)),e}catch(e){throw r===null?e:r}}decodeBitMatrixParser(e,t){let n=e.readVersion(),r=e.readFormatInformation().getErrorCorrectionLevel(),i=e.readCodewords(),a=Mt.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 Ft.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 Rt 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 Rt((this.getX()+t)/2,(this.getY()+e)/2,(this.estimatedModuleSize+n)/2)}}class zt{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)?zt.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n){let r=e[0]+e[1]+e[2],i=zt.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 Rt(i,a,t);this.possibleCenters.push(n),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(n)}return null}}class Bt 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 Bt((this.count*this.getX()+t)/r,(this.count*this.getY()+e)/r,(this.count*this.estimatedModuleSize+n)/r,r)}}class Vt{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 Ht{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*Ht.MAX_MODULES));(o<Ht.MIN_SKIP||t)&&(o=Ht.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(Ht.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]++;Ht.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 Vt(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&&Ht.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:Ht.foundPatternCross(o)?Ht.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:Ht.foundPatternCross(o)?Ht.centerFromEnd(o,s):NaN}handlePossibleCenter(e,t,n,r){let i=e[0]+e[1]+e[2]+e[3]+e[4],a=Ht.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 Bt(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()>=Ht.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()>=Ht.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]]}}Ht.CENTER_QUORUM=2,Ht.MIN_SKIP=3,Ht.MAX_MODULES=57;class Ut{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 Ht(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=Ut.computeDimension(t,n,r,i),o=Ot.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=Ut.createTransform(t,n,r,c,a),u=Ut.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 zt(this.image,a,s,o-a,c-s,e,this.resultPointCallback).find()}}class Wt{constructor(){this.decoder=new Lt}getDecoder(){return this.decoder}decode(e,t){let n,r;if(t!=null&&t.get(b.PURE_BARCODE)!==void 0){let i=Wt.extractPureBits(e.getBlackMatrix());n=this.decoder.decodeBitMatrix(i,t),r=Wt.NO_POINTS}else{let i=new Ut(e.getBlackMatrix()).detect(t);n=this.decoder.decodeBitMatrix(i.getBits(),t),r=i.getPoints()}n.getOther()instanceof It&&n.getOther().applyMirroredCorrection(r);let i=new R(n.getText(),n.getRawBytes(),void 0,r,B.QR_CODE,void 0),a=n.getByteSegments();a!==null&&i.putMetadata(te.BYTE_SEGMENTS,a);let o=n.getECLevel();return o!==null&&i.putMetadata(te.ERROR_CORRECTION_LEVEL,o),n.hasStructuredAppend()&&(i.putMetadata(te.STRUCTURED_APPEND_SEQUENCE,n.getStructuredAppendSequenceNumber()),i.putMetadata(te.STRUCTURED_APPEND_PARITY,n.getStructuredAppendParity())),i}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t===null||n===null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=n[0];if(o>=s||i>=a||a-i!==s-o&&(s=o+(a-i),s>=e.getWidth()))throw new k;let c=Math.round((s-o+1)/r),l=Math.round((a-i+1)/r);if(c<=0||l<=0||l!==c)throw new k;let u=Math.floor(r/2);i+=u,o+=u;let d=o+Math.floor((c-1)*r)-s;if(d>0){if(d>u)throw new k;o-=d}let f=i+Math.floor((l-1)*r)-a;if(f>0){if(f>u)throw new k;i-=f}let p=new O(c,l);for(let t=0;t<l;t++){let n=i+Math.floor(t*r);for(let i=0;i<c;i++)e.get(o+Math.floor(i*r),n)&&p.set(i,t)}return p}static moduleSize(e,t){let n=t.getHeight(),r=t.getWidth(),i=e[0],a=e[1],o=!0,s=0;for(;i<r&&a<n;){if(o!==t.get(i,a)){if(++s===5)break;o=!o}i++,a++}if(i===r||a===n)throw new k;return(i-e[0])/7}}Wt.NO_POINTS=[];class Gt{PDF417Common(){}static getBitCountSum(e){return de.sum(e)}static toIntArray(e){if(e==null||!e.length)return Gt.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(Gt.SYMBOL_TABLE,e&262143);return t<0?-1:(Gt.CODEWORD_TABLE[t]-1)%Gt.NUMBER_OF_CODEWORDS}}Gt.NUMBER_OF_CODEWORDS=929,Gt.MAX_CODEWORDS_IN_BARCODE=Gt.NUMBER_OF_CODEWORDS-1,Gt.MIN_ROWS_IN_BARCODE=3,Gt.MAX_ROWS_IN_BARCODE=90,Gt.MODULES_IN_CODEWORD=17,Gt.MODULES_IN_STOP_PATTERN=18,Gt.BARS_IN_MODULE=8,Gt.EMPTY_INT_ARRAY=new Int32Array([]),Gt.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]),Gt.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 Kt{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class qt{static detectMultiple(e,t,n){let r=e.getBlackMatrix(),i=qt.detect(n,r);return i.length||(r=r.clone(),r.rotate180(),i=qt.detect(n,r)),new Kt(r,i)}static detect(e,t){let n=[],r=0,i=0,a=!1;for(;r<t.getHeight();){let o=qt.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+=qt.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 qt.copyToResult(a,qt.findRowsWithPattern(e,r,i,t,n,qt.START_PATTERN),qt.INDEXES_START_PATTERN),a[4]!=null&&(n=Math.trunc(a[4].getX()),t=Math.trunc(a[4].getY())),qt.copyToResult(a,qt.findRowsWithPattern(e,r,i,t,n,qt.STOP_PATTERN),qt.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+=qt.ROW_STEP){let t=qt.findGuardPattern(e,i,r,n,!1,a,c);if(t!=null){for(;r>0;){let o=qt.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=qt.findGuardPattern(e,i[0],l,n,!1,a,c);if(t!=null&&Math.abs(i[0]-t[0])<qt.MAX_PATTERN_DRIFT&&Math.abs(i[1]-t[1])<qt.MAX_PATTERN_DRIFT)i=t,r=0;else if(r>qt.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<qt.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++<qt.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(qt.patternMatchVariance(o,a,qt.MAX_INDIVIDUAL_VARIANCE)<qt.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&&qt.patternMatchVariance(o,a,qt.MAX_INDIVIDUAL_VARIANCE)<qt.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}}qt.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),qt.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),qt.MAX_AVG_VARIANCE=.42,qt.MAX_INDIVIDUAL_VARIANCE=.8,qt.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),qt.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),qt.MAX_PIXEL_DRIFT=3,qt.MAX_PATTERN_DRIFT=5,qt.SKIPPED_ROW_COUNT_MAX=25,qt.ROW_STEP=5,qt.BARCODE_MIN_HEIGHT=10;class Jt{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 Jt(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 Jt?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 Jt(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 Jt(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 Jt(this.field,t)}multiplyScalar(e){if(e===0)return new Jt(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 Jt(this.field,n)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return new Jt(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 Jt(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 Yt{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 Xt extends Yt{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 Jt(this,new Int32Array([0])),this.one=new Jt(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 Jt(this,n)}}Xt.PDF417_GF=new Xt(Gt.NUMBER_OF_CODEWORDS,3);class Zt{constructor(){this.field=Xt.PDF417_GF}decode(e,t,n){let r=new Jt(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 Jt(this.field,new Int32Array([this.field.subtract(0,n),1]));o=o.multiply(r)}let s=new Jt(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 Jt(this.field,i),o=n.length,s=new Int32Array(o);for(let t=0;t<o;t++){let r=this.field.inverse(n[t]),i=this.field.subtract(0,e.evaluateAt(r)),o=this.field.inverse(a.evaluateAt(r));s[t]=this.field.multiply(i,o)}return s}}class Qt{constructor(e,t,n,r,i){e instanceof Qt?this.constructor_2(e):this.constructor_1(e,t,n,r,i)}constructor_1(e,t,n,r,i){let a=t==null||n==null,o=r==null||i==null;if(a&&o)throw new k;a?(t=new 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 Qt(e.image,e.topLeft,e.bottomLeft,t.topRight,t.bottomRight)}addMissingRows(e,t,n){let r=this.topLeft,i=this.bottomLeft,a=this.topRight,o=this.bottomRight;if(e>0){let t=n?this.topLeft:this.topRight,i=Math.trunc(t.getY()-e);i<0&&(i=0);let o=new 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 Qt(this.image,r,i,a,o)}getMinX(){return this.minX}getMaxX(){return this.maxX}getMinY(){return this.minY}getMaxY(){return this.maxY}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}getBottomLeft(){return this.bottomLeft}getBottomRight(){return this.bottomRight}}class $t{constructor(e,t,n,r){this.columnCount=e,this.errorCorrectionLevel=r,this.rowCountUpperPart=t,this.rowCountLowerPart=n,this.rowCount=t+n}getColumnCount(){return this.columnCount}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getRowCount(){return this.rowCount}getRowCountUpperPart(){return this.rowCountUpperPart}getRowCountLowerPart(){return this.rowCountLowerPart}}class en{constructor(){this.buffer=``}static form(e,t){let n=-1;function r(e,r,i,a,o,s){if(e===`%%`)return`%`;if(t[++n]===void 0)return;e=a?parseInt(a.substr(1)):void 0;let c=o?parseInt(o.substr(1)):void 0,l;switch(s){case`s`:l=t[n];break;case`c`:l=t[n][0];break;case`f`:l=parseFloat(t[n]).toFixed(e);break;case`p`:l=parseFloat(t[n]).toPrecision(e);break;case`e`:l=parseFloat(t[n]).toExponential(e);break;case`x`:l=parseInt(t[n]).toString(c||16);break;case`d`:l=parseFloat(parseInt(t[n],c||10).toPrecision(e)).toFixed(0);break}l=typeof l==`object`?JSON.stringify(l):(+l).toString(c);let u=parseInt(i),d=i&&i[0]+``==`0`?`0`:` `;for(;l.length<u;)l=r===void 0?d+l:l+d;return l}return e.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,r)}format(e,...t){this.buffer+=en.form(e,t)}toString(){return this.buffer}}class tn{constructor(e){this.boundingBox=new Qt(e),this.codewords=Array(e.getMaxY()-e.getMinY()+1)}getCodewordNearby(e){let t=this.getCodeword(e);if(t!=null)return t;for(let n=1;n<tn.MAX_NEARBY_DISTANCE;n++){let r=this.imageRowToCodewordIndex(e)-n;if(r>=0&&(t=this.codewords[r],t!=null)||(r=this.imageRowToCodewordIndex(e)+n,r<this.codewords.length&&(t=this.codewords[r],t!=null)))return t}return null}imageRowToCodewordIndex(e){return e-this.boundingBox.getMinY()}setCodeword(e,t){this.codewords[this.imageRowToCodewordIndex(e)]=t}getCodeword(e){return this.codewords[this.imageRowToCodewordIndex(e)]}getBoundingBox(){return this.boundingBox}getCodewords(){return this.codewords}toString(){let e=new en,t=0;for(let n of this.codewords){if(n==null){e.format(`%3d: | %n`,t++);continue}e.format(`%3d: %3d|%3d%n`,t++,n.getRowNumber(),n.getValue())}return e.toString()}}tn.MAX_NEARBY_DISTANCE=5;class nn{constructor(){this.values=new Map}setValue(e){e=Math.trunc(e);let t=this.values.get(e);t??=0,t++,this.values.set(e,t)}getValue(){let e=-1,t=[];for(let[n,r]of this.values.entries()){let i={getKey:()=>n,getValue:()=>r};i.getValue()>e?(e=i.getValue(),t=[],t.push(i.getKey())):i.getValue()===e&&t.push(i.getKey())}return Gt.toIntArray(t)}getConfidence(e){return this.values.get(e)}}class rn extends tn{constructor(e,t){super(e),this._isLeft=t}setRowNumbers(){for(let e of this.getCodewords())e?.setRowNumberAsRowIndicatorColumn()}adjustCompleteIndicatorColumnRowNumbers(e){let t=this.getCodewords();this.setRowNumbers(),this.removeIncorrectCodewords(t,e);let n=this.getBoundingBox(),r=this._isLeft?n.getTopLeft():n.getTopRight(),i=this._isLeft?n.getBottomLeft():n.getBottomRight(),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.imageRowToCodewordIndex(Math.trunc(i.getY())),s=-1,c=1,l=0;for(let n=a;n<o;n++){if(t[n]==null)continue;let r=t[n],i=r.getRowNumber()-s;if(i===0)l++;else if(i===1)c=Math.max(c,l),l=1,s=r.getRowNumber();else if(i<0||r.getRowNumber()>=e.getRowCount()||i>n)t[n]=null;else{let e;e=c>2?(c-2)*i:i;let a=e>=n;for(let r=1;r<=e&&!a;r++)a=t[n-r]!=null;a?t[n]=null:(s=r.getRowNumber(),l=1)}}}getRowHeights(){let e=this.getBarcodeMetadata();if(e==null)return null;this.adjustIncompleteIndicatorColumnRowNumbers(e);let t=new Int32Array(e.getRowCount());for(let e of this.getCodewords())if(e!=null){let n=e.getRowNumber();if(n>=t.length)continue;t[n]++}return t}adjustIncompleteIndicatorColumnRowNumbers(e){let t=this.getBoundingBox(),n=this._isLeft?t.getTopLeft():t.getTopRight(),r=this._isLeft?t.getBottomLeft():t.getBottomRight(),i=this.imageRowToCodewordIndex(Math.trunc(n.getY())),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.getCodewords(),s=-1;for(let t=i;t<a;t++){if(o[t]==null)continue;let n=o[t];n.setRowNumberAsRowIndicatorColumn();let r=n.getRowNumber()-s;r===0||(r===1?s=n.getRowNumber():n.getRowNumber()>=e.getRowCount()?o[t]=null:s=n.getRowNumber())}}getBarcodeMetadata(){let e=this.getCodewords(),t=new nn,n=new nn,r=new nn,i=new nn;for(let a of e){if(a==null)continue;a.setRowNumberAsRowIndicatorColumn();let e=a.getValue()%30,o=a.getRowNumber();switch(this._isLeft||(o+=2),o%3){case 0:n.setValue(e*3+1);break;case 1:i.setValue(e/3),r.setValue(e%3);break;case 2:t.setValue(e+1);break}}if(t.getValue().length===0||n.getValue().length===0||r.getValue().length===0||i.getValue().length===0||t.getValue()[0]<1||n.getValue()[0]+r.getValue()[0]<Gt.MIN_ROWS_IN_BARCODE||n.getValue()[0]+r.getValue()[0]>Gt.MAX_ROWS_IN_BARCODE)return null;let a=new $t(t.getValue()[0],n.getValue()[0],r.getValue()[0],i.getValue()[0]);return this.removeIncorrectCodewords(e,a),a}removeIncorrectCodewords(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(e[n]==null)continue;let i=r.getValue()%30,a=r.getRowNumber();if(a>t.getRowCount()){e[n]=null;continue}switch(this._isLeft||(a+=2),a%3){case 0:i*3+1!==t.getRowCountUpperPart()&&(e[n]=null);break;case 1:(Math.trunc(i/3)!==t.getErrorCorrectionLevel()||i%3!==t.getRowCountLowerPart())&&(e[n]=null);break;case 2:i+1!==t.getColumnCount()&&(e[n]=null);break}}}isLeft(){return this._isLeft}toString(){return`IsLeft: `+this._isLeft+`
57
+ `+super.toString()}}class an{constructor(e,t){this.ADJUST_ROW_NUMBER_SKIP=2,this.barcodeMetadata=e,this.barcodeColumnCount=e.getColumnCount(),this.boundingBox=t,this.detectionResultColumns=Array(this.barcodeColumnCount+2)}getDetectionResultColumns(){this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[0]),this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[this.barcodeColumnCount+1]);let e=Gt.MAX_CODEWORDS_IN_BARCODE,t;do t=e,e=this.adjustRowNumbersAndGetCount();while(e>0&&e<t);return this.detectionResultColumns}adjustIndicatorColumnRowNumbers(e){e?.adjustCompleteIndicatorColumnRowNumbers(this.barcodeMetadata)}adjustRowNumbersAndGetCount(){let e=this.adjustRowNumbersByRow();if(e===0)return 0;for(let e=1;e<this.barcodeColumnCount+1;e++){let t=this.detectionResultColumns[e].getCodewords();for(let n=0;n<t.length;n++)t[n]!=null&&(t[n].hasValidRowNumber()||this.adjustRowNumbers(e,n,t))}return e}adjustRowNumbersByRow(){return this.adjustRowNumbersFromBothRI(),this.adjustRowNumbersFromLRI()+this.adjustRowNumbersFromRRI()}adjustRowNumbersFromBothRI(){if(this.detectionResultColumns[0]==null||this.detectionResultColumns[this.barcodeColumnCount+1]==null)return;let e=this.detectionResultColumns[0].getCodewords(),t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<e.length;n++)if(e[n]!=null&&t[n]!=null&&e[n].getRowNumber()===t[n].getRowNumber())for(let t=1;t<=this.barcodeColumnCount;t++){let r=this.detectionResultColumns[t].getCodewords()[n];r!=null&&(r.setRowNumber(e[n].getRowNumber()),r.hasValidRowNumber()||(this.detectionResultColumns[t].getCodewords()[n]=null))}}adjustRowNumbersFromRRI(){if(this.detectionResultColumns[this.barcodeColumnCount+1]==null)return 0;let e=0,t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=this.barcodeColumnCount+1;t>0&&i<this.ADJUST_ROW_NUMBER_SKIP;t--){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=an.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}adjustRowNumbersFromLRI(){if(this.detectionResultColumns[0]==null)return 0;let e=0,t=this.detectionResultColumns[0].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=1;t<this.barcodeColumnCount+1&&i<this.ADJUST_ROW_NUMBER_SKIP;t++){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=an.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}static adjustRowNumberIfValid(e,t,n){return n==null||n.hasValidRowNumber()||(n.isValidRowNumber(e)?(n.setRowNumber(e),t=0):++t),t}adjustRowNumbers(e,t,n){if(!this.detectionResultColumns[e-1])return;let r=n[t],i=this.detectionResultColumns[e-1].getCodewords(),a=i;this.detectionResultColumns[e+1]!=null&&(a=this.detectionResultColumns[e+1].getCodewords());let o=Array(14);o[2]=i[t],o[3]=a[t],t>0&&(o[0]=n[t-1],o[4]=i[t-1],o[5]=a[t-1]),t>1&&(o[8]=n[t-2],o[10]=i[t-2],o[11]=a[t-2]),t<n.length-1&&(o[1]=n[t+1],o[6]=i[t+1],o[7]=a[t+1]),t<n.length-2&&(o[9]=n[t+2],o[12]=i[t+2],o[13]=a[t+2]);for(let e of o)if(an.adjustRowNumber(r,e))return}static adjustRowNumber(e,t){return t==null?!1:t.hasValidRowNumber()&&t.getBucket()===e.getBucket()?(e.setRowNumber(t.getRowNumber()),!0):!1}getBarcodeColumnCount(){return this.barcodeColumnCount}getBarcodeRowCount(){return this.barcodeMetadata.getRowCount()}getBarcodeECLevel(){return this.barcodeMetadata.getErrorCorrectionLevel()}setBoundingBox(e){this.boundingBox=e}getBoundingBox(){return this.boundingBox}setDetectionResultColumn(e,t){this.detectionResultColumns[e]=t}getDetectionResultColumn(e){return this.detectionResultColumns[e]}toString(){let e=this.detectionResultColumns[0];e??=this.detectionResultColumns[this.barcodeColumnCount+1];let t=new en;for(let n=0;n<e.getCodewords().length;n++){t.format(`CW %3d:`,n);for(let e=0;e<this.barcodeColumnCount+2;e++){if(this.detectionResultColumns[e]==null){t.format(` | `);continue}let r=this.detectionResultColumns[e].getCodewords()[n];if(r==null){t.format(` | `);continue}t.format(` %3d|%3d`,r.getRowNumber(),r.getValue())}t.format(`%n`)}return t.toString()}}class on{constructor(e,t,n,r){this.rowNumber=on.BARCODE_ROW_UNKNOWN,this.startX=Math.trunc(e),this.endX=Math.trunc(t),this.bucket=Math.trunc(n),this.value=Math.trunc(r)}hasValidRowNumber(){return this.isValidRowNumber(this.rowNumber)}isValidRowNumber(e){return e!==on.BARCODE_ROW_UNKNOWN&&this.bucket===e%3*3}setRowNumberAsRowIndicatorColumn(){this.rowNumber=Math.trunc(Math.trunc(this.value/30)*3+Math.trunc(this.bucket/3))}getWidth(){return this.endX-this.startX}getStartX(){return this.startX}getEndX(){return this.endX}getBucket(){return this.bucket}getValue(){return this.value}getRowNumber(){return this.rowNumber}setRowNumber(e){this.rowNumber=e}toString(){return this.rowNumber+`|`+this.value}}on.BARCODE_ROW_UNKNOWN=-1;class sn{static initialize(){for(let e=0;e<Gt.SYMBOL_TABLE.length;e++){let t=Gt.SYMBOL_TABLE[e],n=t&1;for(let r=0;r<Gt.BARS_IN_MODULE;r++){let i=0;for(;(t&1)===n;)i+=1,t>>=1;n=t&1,sn.RATIOS_TABLE[e]||(sn.RATIOS_TABLE[e]=Array(Gt.BARS_IN_MODULE)),sn.RATIOS_TABLE[e][Gt.BARS_IN_MODULE-r-1]=Math.fround(i/Gt.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let t=sn.getDecodedCodewordValue(sn.sampleBitCounts(e));return t===-1?sn.getClosestDecodedValue(e):t}static sampleBitCounts(e){let t=de.sum(e),n=new Int32Array(Gt.BARS_IN_MODULE),r=0,i=0;for(let a=0;a<Gt.MODULES_IN_CODEWORD;a++){let o=t/(2*Gt.MODULES_IN_CODEWORD)+a*t/Gt.MODULES_IN_CODEWORD;i+e[r]<=o&&(i+=e[r],r++),n[r]++}return n}static getDecodedCodewordValue(e){let t=sn.getBitValue(e);return Gt.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(Gt.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||sn.initialize();for(let e=0;e<sn.RATIOS_TABLE.length;e++){let t=0,a=sn.RATIOS_TABLE[e];for(let e=0;e<Gt.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=Gt.SYMBOL_TABLE[e])}return i}}sn.bSymbolTableReady=!1,sn.RATIOS_TABLE=Array(Gt.SYMBOL_TABLE.length).map(e=>e=Array(Gt.BARS_IN_MODULE));class cn{constructor(){this.segmentCount=-1,this.fileSize=-1,this.timestamp=-1,this.checksum=-1}getSegmentIndex(){return this.segmentIndex}setSegmentIndex(e){this.segmentIndex=e}getFileId(){return this.fileId}setFileId(e){this.fileId=e}getOptionalData(){return this.optionalData}setOptionalData(e){this.optionalData=e}isLastSegment(){return this.lastSegment}setLastSegment(e){this.lastSegment=e}getSegmentCount(){return this.segmentCount}setSegmentCount(e){this.segmentCount=e}getSender(){return this.sender||null}setSender(e){this.sender=e}getAddressee(){return this.addressee||null}setAddressee(e){this.addressee=e}getFileName(){return this.fileName}setFileName(e){this.fileName=e}getFileSize(){return this.fileSize}setFileSize(e){this.fileSize=e}getChecksum(){return this.checksum}setChecksum(e){this.checksum=e}getTimestamp(){return this.timestamp}setTimestamp(e){this.timestamp=e}}class ln{static parseLong(e,t=void 0){return parseInt(e,t)}}class un extends s{}un.kind=`NullPointerException`;class dn{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,t,n){if(e==null)throw new un;if(t<0||t>e.length||n<0||t+n>e.length||t+n<0)throw new m;if(n!==0)for(let r=0;r<n;r++)this.write(e[t+r])}flush(){}close(){}}class fn extends s{}class pn extends dn{constructor(e=32){if(super(),this.count=0,e<0)throw new l(`Negative initial size: `+e);this.buf=new Uint8Array(e)}ensureCapacity(e){e-this.buf.length>0&&this.grow(e)}grow(e){let t=this.buf.length<<1;if(t-e<0&&(t=e),t<0){if(e<0)throw new fn;t=_.MAX_VALUE}this.buf=g.copyOfUint8Array(this.buf,t)}write(e){this.ensureCapacity(this.count+1),this.buf[this.count]=e,this.count+=1}writeBytesOffset(e,t,n){if(t<0||t>e.length||n<0||t+n-e.length>0)throw new m;this.ensureCapacity(this.count+n),p.arraycopy(e,t,this.buf,this.count,n),this.count+=n}writeTo(e){e.writeBytesOffset(this.buf,0,this.count)}reset(){this.count=0}toByteArray(){return g.copyOfUint8Array(this.buf,this.count)}size(){return this.count}toString(e){return e?typeof e==`string`?this.toString_string(e):this.toString_number(e):this.toString_void()}toString_void(){return new String(this.buf).toString()}toString_string(e){return new String(this.buf).toString()}toString_number(e){return new String(this.buf).toString()}close(){}}var mn;(function(e){e[e.ALPHA=0]=`ALPHA`,e[e.LOWER=1]=`LOWER`,e[e.MIXED=2]=`MIXED`,e[e.PUNCT=3]=`PUNCT`,e[e.ALPHA_SHIFT=4]=`ALPHA_SHIFT`,e[e.PUNCT_SHIFT=5]=`PUNCT_SHIFT`})(mn||={});function hn(){if(typeof window<`u`)return window.BigInt||null;if(typeof global<`u`)return global.BigInt||null;if(typeof self<`u`)return self.BigInt||null;throw Error(`Can't search globals for BigInt!`)}let gn;function _n(e){if(gn===void 0&&(gn=hn()),gn===null)throw Error(`BigInt is not supported!`);return gn(e)}function vn(){let e=[];e[0]=_n(1);let t=_n(900);e[1]=t;for(let n=2;n<16;n++)e[n]=e[n-1]*t;return e}class q{static decode(e,t){let n=new D(``),r=C.ISO8859_1;n.enableDecoding(r);let i=1,a=e[i++],o=new cn;for(;i<e[0];){switch(a){case q.TEXT_COMPACTION_MODE_LATCH:i=q.textCompaction(e,i,n);break;case q.BYTE_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:i=q.byteCompaction(a,e,r,i,n);break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:n.append(e[i++]);break;case q.NUMERIC_COMPACTION_MODE_LATCH:i=q.numericCompaction(e,i,n);break;case q.ECI_CHARSET:C.getCharacterSetECIByValue(e[i++]);break;case q.ECI_GENERAL_PURPOSE:i+=2;break;case q.ECI_USER_DEFINED:i++;break;case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:i=q.decodeMacroBlock(e,i,o);break;case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:throw new x;default:i--,i=q.textCompaction(e,i,n);break}if(i<e.length)a=e[i++];else throw x.getFormatInstance()}if(n.length()===0)throw x.getFormatInstance();let s=new ne(null,n.toString(),null,t);return s.setOther(o),s}static decodeMacroBlock(e,t,n){if(t+q.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw x.getFormatInstance();let r=new Int32Array(q.NUMBER_OF_SEQUENCE_CODEWORDS);for(let n=0;n<q.NUMBER_OF_SEQUENCE_CODEWORDS;n++,t++)r[n]=e[t];n.setSegmentIndex(_.parseInt(q.decodeBase900toBase10(r,q.NUMBER_OF_SEQUENCE_CODEWORDS)));let i=new D;t=q.textCompaction(e,t,i),n.setFileId(i.toString());let a=-1;for(e[t]===q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(a=t+1);t<e[0];)switch(e[t]){case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(t++,e[t]){case q.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let r=new D;t=q.textCompaction(e,t+1,r),n.setFileName(r.toString());break;case q.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let i=new D;t=q.textCompaction(e,t+1,i),n.setSender(i.toString());break;case q.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let a=new D;t=q.textCompaction(e,t+1,a),n.setAddressee(a.toString());break;case q.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let o=new D;t=q.numericCompaction(e,t+1,o),n.setSegmentCount(_.parseInt(o.toString()));break;case q.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let s=new D;t=q.numericCompaction(e,t+1,s),n.setTimestamp(ln.parseLong(s.toString()));break;case q.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let c=new D;t=q.numericCompaction(e,t+1,c),n.setChecksum(_.parseInt(c.toString()));break;case q.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let l=new D;t=q.numericCompaction(e,t+1,l),n.setFileSize(ln.parseLong(l.toString()));break;default:throw x.getFormatInstance()}break;case q.MACRO_PDF417_TERMINATOR:t++,n.setLastSegment(!0);break;default:throw x.getFormatInstance()}if(a!==-1){let r=t-a;n.isLastSegment()&&r--,n.setOptionalData(g.copyOfRange(e,a,a+r))}return t}static textCompaction(e,t,n){let r=new Int32Array((e[0]-t)*2),i=new Int32Array((e[0]-t)*2),a=0,o=!1;for(;t<e[0]&&!o;){let n=e[t++];if(n<q.TEXT_COMPACTION_MODE_LATCH)r[a]=n/30,r[a+1]=n%30,a+=2;else switch(n){case q.TEXT_COMPACTION_MODE_LATCH:r[a++]=q.TEXT_COMPACTION_MODE_LATCH;break;case q.BYTE_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.NUMERIC_COMPACTION_MODE_LATCH:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:t--,o=!0;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r[a]=q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,n=e[t++],i[a]=n,a++;break}}return q.decodeTextCompaction(r,i,a,n),t}static decodeTextCompaction(e,t,n,r){let i=mn.ALPHA,a=mn.ALPHA,o=0;for(;o<n;){let n=e[o],s=``;switch(i){case mn.ALPHA:if(n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case q.LL:i=mn.LOWER;break;case q.ML:i=mn.MIXED;break;case q.PS:a=i,i=mn.PUNCT_SHIFT;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.LOWER:if(n<26)s=String.fromCharCode(97+n);else switch(n){case 26:s=` `;break;case q.AS:a=i,i=mn.ALPHA_SHIFT;break;case q.ML:i=mn.MIXED;break;case q.PS:a=i,i=mn.PUNCT_SHIFT;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.MIXED:if(n<q.PL)s=q.MIXED_CHARS[n];else switch(n){case q.PL:i=mn.PUNCT;break;case 26:s=` `;break;case q.LL:i=mn.LOWER;break;case q.AL:i=mn.ALPHA;break;case q.PS:a=i,i=mn.PUNCT_SHIFT;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.PUNCT:if(n<q.PAL)s=q.PUNCT_CHARS[n];else switch(n){case q.PAL:i=mn.ALPHA;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.ALPHA_SHIFT:if(i=a,n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break;case mn.PUNCT_SHIFT:if(i=a,n<q.PAL)s=q.PUNCT_CHARS[n];else switch(n){case q.PAL:i=mn.ALPHA;break;case q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case q.TEXT_COMPACTION_MODE_LATCH:i=mn.ALPHA;break}break}s!==``&&r.append(s),o++}}static byteCompaction(e,t,n,r,i){let a=new pn,o=0,s=0,c=!1;switch(e){case q.BYTE_COMPACTION_MODE_LATCH:let e=new Int32Array(6),n=t[r++];for(;r<t[0]&&!c;)switch(e[o++]=n,s=900*s+n,n=t[r++],n){case q.TEXT_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH:case q.NUMERIC_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:r--,c=!0;break;default:if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(_n(s)>>_n(8*(5-e))));s=0,o=0}break}r===t[0]&&n<q.TEXT_COMPACTION_MODE_LATCH&&(e[o++]=n);for(let t=0;t<o;t++)a.write(e[t]);break;case q.BYTE_COMPACTION_MODE_LATCH_6:for(;r<t[0]&&!c;){let e=t[r++];if(e<q.TEXT_COMPACTION_MODE_LATCH)o++,s=900*s+e;else switch(e){case q.TEXT_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH:case q.NUMERIC_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:r--,c=!0;break}if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(_n(s)>>_n(8*(5-e))));s=0,o=0}}break}return i.append(T.decode(a.toByteArray(),n)),r}static numericCompaction(e,t,n){let r=0,i=!1,a=new Int32Array(q.MAX_NUMERIC_CODEWORDS);for(;t<e[0]&&!i;){let o=e[t++];if(t===e[0]&&(i=!0),o<q.TEXT_COMPACTION_MODE_LATCH)a[r]=o,r++;else switch(o){case q.TEXT_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH:case q.BYTE_COMPACTION_MODE_LATCH_6:case q.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case q.MACRO_PDF417_TERMINATOR:t--,i=!0;break}(r%q.MAX_NUMERIC_CODEWORDS===0||o===q.NUMERIC_COMPACTION_MODE_LATCH||i)&&r>0&&(n.append(q.decodeBase900toBase10(a,r)),r=0)}return t}static decodeBase900toBase10(e,t){let n=_n(0);for(let r=0;r<t;r++)n+=q.EXP900[t-r-1]*_n(e[r]);let r=n.toString();if(r.charAt(0)!==`1`)throw new x;return r.substring(1)}}q.TEXT_COMPACTION_MODE_LATCH=900,q.BYTE_COMPACTION_MODE_LATCH=901,q.NUMERIC_COMPACTION_MODE_LATCH=902,q.BYTE_COMPACTION_MODE_LATCH_6=924,q.ECI_USER_DEFINED=925,q.ECI_GENERAL_PURPOSE=926,q.ECI_CHARSET=927,q.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,q.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,q.MACRO_PDF417_TERMINATOR=922,q.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,q.MAX_NUMERIC_CODEWORDS=15,q.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,q.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,q.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,q.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,q.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,q.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,q.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,q.PL=25,q.LL=27,q.AS=27,q.ML=28,q.AL=28,q.PS=29,q.PAL=29,q.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
58
+ -.$/"|*()?{}'`,q.MIXED_CHARS=`0123456789&\r ,:#-.$/+%*=^`,q.EXP900=hn()?vn():[],q.NUMBER_OF_SEQUENCE_CODEWORDS=2;class yn{constructor(){}static decode(e,t,n,r,i,a,o){let s=new Qt(e,t,n,r,i),c=null,l=null,u;for(let n=!0;;n=!1){if(t!=null&&(c=yn.getRowIndicatorColumn(e,s,t,!0,a,o)),r!=null&&(l=yn.getRowIndicatorColumn(e,s,r,!1,a,o)),u=yn.merge(c,l),u==null)throw k.getNotFoundInstance();let i=u.getBoundingBox();if(n&&i!=null&&(i.getMinY()<s.getMinY()||i.getMaxY()>s.getMaxY()))s=i;else break}u.setBoundingBox(s);let d=u.getBarcodeColumnCount()+1;u.setDetectionResultColumn(0,c),u.setDetectionResultColumn(d,l);let f=c!=null;for(let t=1;t<=d;t++){let n=f?t:d-t;if(u.getDetectionResultColumn(n)!==void 0)continue;let r;r=n===0||n===d?new rn(s,n===0):new tn(s),u.setDetectionResultColumn(n,r);let i=-1,c=i;for(let t=s.getMinY();t<=s.getMaxY();t++){if(i=yn.getStartColumn(u,n,t,f),i<0||i>s.getMaxX()){if(c===-1)continue;i=c}let l=yn.detectCodeword(e,s.getMinX(),s.getMaxX(),f,i,t,a,o);l!=null&&(r.setCodeword(t,l),c=i,a=Math.min(a,l.getWidth()),o=Math.max(o,l.getWidth()))}}return yn.createDecoderResult(u)}static merge(e,t){if(e==null&&t==null)return null;let n=yn.getBarcodeMetadata(e,t);return n==null?null:new an(n,Qt.merge(yn.adjustBoundingBox(e),yn.adjustBoundingBox(t)))}static adjustBoundingBox(e){if(e==null)return null;let t=e.getRowHeights();if(t==null)return null;let n=yn.getMax(t),r=0;for(let e of t)if(r+=n-e,e>0)break;let i=e.getCodewords();for(let e=0;r>0&&i[e]==null;e++)r--;let a=0;for(let e=t.length-1;e>=0&&(a+=n-t[e],!(t[e]>0));e--);for(let e=i.length-1;a>0&&i[e]==null;e--)a--;return e.getBoundingBox().addMissingRows(r,a,e.isLeft())}static getMax(e){let t=-1;for(let n of e)t=Math.max(t,n);return t}static getBarcodeMetadata(e,t){let n;if(e==null||(n=e.getBarcodeMetadata())==null)return t==null?null:t.getBarcodeMetadata();let r;return t==null||(r=t.getBarcodeMetadata())==null?n:n.getColumnCount()!==r.getColumnCount()&&n.getErrorCorrectionLevel()!==r.getErrorCorrectionLevel()&&n.getRowCount()!==r.getRowCount()?null:n}static getRowIndicatorColumn(e,t,n,r,i,a){let o=new rn(t,r);for(let s=0;s<2;s++){let c=s===0?1:-1,l=Math.trunc(Math.trunc(n.getX()));for(let s=Math.trunc(Math.trunc(n.getY()));s<=t.getMaxY()&&s>=t.getMinY();s+=c){let t=yn.detectCodeword(e,0,e.getWidth(),r,l,s,i,a);t!=null&&(o.setCodeword(s,t),l=r?t.getStartX():t.getEndX())}}return o}static adjustCodewordCount(e,t){let n=t[0][1],r=n.getValue(),i=e.getBarcodeColumnCount()*e.getBarcodeRowCount()-yn.getNumberOfECCodeWords(e.getBarcodeECLevel());if(r.length===0){if(i<1||i>Gt.MAX_CODEWORDS_IN_BARCODE)throw k.getNotFoundInstance();n.setValue(i)}else r[0]!==i&&n.setValue(i)}static createDecoderResult(e){let t=yn.createBarcodeMatrix(e);yn.adjustCodewordCount(e,t);let n=[],r=new Int32Array(e.getBarcodeRowCount()*e.getBarcodeColumnCount()),i=[],a=[];for(let o=0;o<e.getBarcodeRowCount();o++)for(let s=0;s<e.getBarcodeColumnCount();s++){let c=t[o][s+1].getValue(),l=o*e.getBarcodeColumnCount()+s;c.length===0?n.push(l):c.length===1?r[l]=c[0]:(a.push(l),i.push(c))}let o=Array(i.length);for(let e=0;e<o.length;e++)o[e]=i[e];return yn.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),r,Gt.toIntArray(n),Gt.toIntArray(a),o)}static createDecoderResultFromAmbiguousValues(e,t,n,r,i){let a=new Int32Array(r.length),o=100;for(;o-- >0;){for(let e=0;e<a.length;e++)t[r[e]]=i[e][a[e]];try{return yn.decodeCodewords(t,e,n)}catch(e){if(!(e instanceof d))throw e}if(a.length===0)throw d.getChecksumInstance();for(let e=0;e<a.length;e++)if(a[e]<i[e].length-1){a[e]++;break}else if(a[e]=0,e===a.length-1)throw d.getChecksumInstance()}throw d.getChecksumInstance()}static createBarcodeMatrix(e){let t=Array.from({length:e.getBarcodeRowCount()},()=>Array(e.getBarcodeColumnCount()+2));for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length;n++)t[e][n]=new nn;let n=0;for(let r of e.getDetectionResultColumns()){if(r!=null){for(let e of r.getCodewords())if(e!=null){let r=e.getRowNumber();if(r>=0){if(r>=t.length)continue;t[r][n].setValue(e.getValue())}}}n++}return t}static isValidBarcodeColumn(e,t){return t>=0&&t<=e.getBarcodeColumnCount()+1}static getStartColumn(e,t,n,r){let i=r?1:-1,a=null;if(yn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodeword(n)),a!=null)return r?a.getEndX():a.getStartX();if(a=e.getDetectionResultColumn(t).getCodewordNearby(n),a!=null)return r?a.getStartX():a.getEndX();if(yn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodewordNearby(n)),a!=null)return r?a.getEndX():a.getStartX();let o=0;for(;yn.isValidBarcodeColumn(e,t-i);){t-=i;for(let n of e.getDetectionResultColumn(t).getCodewords())if(n!=null)return(r?n.getEndX():n.getStartX())+i*o*(n.getEndX()-n.getStartX());o++}return r?e.getBoundingBox().getMinX():e.getBoundingBox().getMaxX()}static detectCodeword(e,t,n,r,i,a,o,s){i=yn.adjustCodewordStartColumn(e,t,n,r,i,a);let c=yn.getModuleBitCount(e,t,n,r,i,a);if(c==null)return null;let l,u=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(!yn.checkCodewordSkew(u,o,s))return null;let d=sn.getDecodedValue(c),f=Gt.getCodeword(d);return f===-1?null:new on(i,l,yn.getCodewordBucketNumber(d),f)}static getModuleBitCount(e,t,n,r,i,a){let o=i,s=new Int32Array(8),c=0,l=r?1:-1,u=r;for(;(r?o<n:o>=t)&&c<s.length;)e.get(o,a)===u?(s[c]++,o+=l):(c++,u=!u);return c===s.length||o===(r?n:t)&&c===s.length-1?s:null}static getNumberOfECCodeWords(e){return 2<<e}static adjustCodewordStartColumn(e,t,n,r,i,a){let o=i,s=r?-1:1;for(let c=0;c<2;c++){for(;(r?o>=t:o<n)&&r===e.get(o,a);){if(Math.abs(i-o)>yn.CODEWORD_SKEW_SIZE)return i;o+=s}s=-s,r=!r}return o}static checkCodewordSkew(e,t,n){return t-yn.CODEWORD_SKEW_SIZE<=e&&e<=n+yn.CODEWORD_SKEW_SIZE}static decodeCodewords(e,t,n){if(e.length===0)throw x.getFormatInstance();let r=1<<t+1,i=yn.correctErrors(e,n,r);yn.verifyCodewordCount(e,r);let a=q.decode(e,``+t);return a.setErrorsCorrected(i),a.setErasures(n.length),a}static correctErrors(e,t,n){if(t!=null&&t.length>n/2+yn.MAX_ERRORS||n<0||n>yn.MAX_EC_CODEWORDS)throw d.getChecksumInstance();return yn.errorCorrection.decode(e,n,t)}static verifyCodewordCount(e,t){if(e.length<4)throw x.getFormatInstance();let n=e[0];if(n>e.length)throw x.getFormatInstance();if(n===0)if(t<e.length)e[0]=e.length-t;else throw x.getFormatInstance()}static getBitCountForCodeword(e){let t=new Int32Array(8),n=0,r=t.length-1;for(;!((e&1)!==n&&(n=e&1,r--,r<0));)t[r]++,e>>=1;return t}static getCodewordBucketNumber(e){return e instanceof Int32Array?this.getCodewordBucketNumber_Int32Array(e):this.getCodewordBucketNumber_number(e)}static getCodewordBucketNumber_number(e){return yn.getCodewordBucketNumber(yn.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let t=new en;for(let n=0;n<e.length;n++){t.format(`Row %2d: `,n);for(let r=0;r<e[n].length;r++){let i=e[n][r];i.getValue().length===0?t.format(` `,null):t.format(`%4d(%2d)`,i.getValue()[0],i.getConfidence(i.getValue()[0]))}t.format(`%n`)}return t.toString()}}yn.CODEWORD_SKEW_SIZE=2,yn.MAX_ERRORS=3,yn.MAX_EC_CODEWORDS=512,yn.errorCorrection=new Zt;class bn{decode(e,t=null){let n=bn.decode(e,t,!1);if(n==null||n.length===0||n[0]==null)throw k.getNotFoundInstance();return n[0]}decodeMultiple(e,t=null){try{return bn.decode(e,t,!0)}catch(e){throw e instanceof x||e instanceof d?k.getNotFoundInstance():e}}static decode(e,t,n){let r=[],i=qt.detectMultiple(e,t,n);for(let e of i.getPoints()){let t=yn.decode(i.getBits(),e[4],e[5],e[6],e[7],bn.getMinCodewordWidth(e),bn.getMaxCodewordWidth(e)),n=new R(t.getText(),t.getRawBytes(),void 0,e,B.PDF_417);n.putMetadata(te.ERROR_CORRECTION_LEVEL,t.getECLevel());let a=t.getOther();a!=null&&n.putMetadata(te.PDF417_EXTRA_METADATA,a),r.push(n)}return r.map(e=>e)}static getMaxWidth(e,t){return e==null||t==null?0:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMinWidth(e,t){return e==null||t==null?_.MAX_VALUE:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMaxCodewordWidth(e){return Math.floor(Math.max(Math.max(bn.getMaxWidth(e[0],e[4]),bn.getMaxWidth(e[6],e[2])*Gt.MODULES_IN_CODEWORD/Gt.MODULES_IN_STOP_PATTERN),Math.max(bn.getMaxWidth(e[1],e[5]),bn.getMaxWidth(e[7],e[3])*Gt.MODULES_IN_CODEWORD/Gt.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(bn.getMinWidth(e[0],e[4]),bn.getMinWidth(e[6],e[2])*Gt.MODULES_IN_CODEWORD/Gt.MODULES_IN_STOP_PATTERN),Math.min(bn.getMinWidth(e[1],e[5]),bn.getMinWidth(e[7],e[3])*Gt.MODULES_IN_CODEWORD/Gt.MODULES_IN_STOP_PATTERN)))}reset(){}}class xn extends s{}xn.kind=`ReaderException`;class Sn{constructor(e,t){this.verbose=e===!0,t&&this.setHints(t)}decode(e,t){return t&&this.setHints(t),this.decodeInternal(e)}decodeWithState(e){return(this.readers===null||this.readers===void 0)&&this.setHints(null),this.decodeInternal(e)}setHints(e){this.hints=e;let n=!t(e)&&e.get(b.TRY_HARDER)===!0,r=t(e)?null:e.get(b.POSSIBLE_FORMATS),i=[];if(!t(r)){let t=r.some(e=>e===B.UPC_A||e===B.UPC_E||e===B.EAN_13||e===B.EAN_8||e===B.CODABAR||e===B.CODE_39||e===B.CODE_93||e===B.CODE_128||e===B.ITF||e===B.RSS_14||e===B.RSS_EXPANDED);t&&!n&&i.push(new dt(e,this.verbose)),r.includes(B.QR_CODE)&&i.push(new Wt),r.includes(B.DATA_MATRIX)&&i.push(new Ct),r.includes(B.AZTEC)&&i.push(new xe),r.includes(B.PDF_417)&&i.push(new bn),t&&n&&i.push(new dt(e,this.verbose))}i.length===0&&(n||i.push(new dt(e,this.verbose)),i.push(new Wt),i.push(new Ct),i.push(new xe),i.push(new bn),n&&i.push(new dt(e,this.verbose))),this.readers=i}reset(){if(this.readers!==null)for(let e of this.readers)e.reset()}decodeInternal(e){if(this.readers===null)throw new xn(`No readers where selected, nothing can be read.`);for(let t of this.readers)try{return t.decode(e,this.hints)}catch(e){if(e instanceof xn)continue}throw new k(`No MultiFormat Readers were able to detect the code.`)}}class Cn extends L{constructor(e=null,t=500){let n=new Sn;n.setHints(e),super(n,t)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class wn extends L{constructor(e=500){super(new bn,e)}}class Tn extends L{constructor(e=500){super(new Wt,e)}}var J;(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`})(J||={});var En=J;class Dn{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new ie(e,Int32Array.from([1])))}buildGenerator(e){let t=this.cachedGenerators;if(e>=t.length){let n=t[t.length-1],r=this.field;for(let i=t.length;i<=e;i++){let e=n.multiply(new ie(r,Int32Array.from([1,r.exp(i-1+r.getGeneratorBase())])));t.push(e),n=e}}return t[e]}encode(e,t){if(t===0)throw new l(`No error correction bytes`);let n=e.length-t;if(n<=0)throw new l(`No data bytes provided`);let r=this.buildGenerator(t),i=new Int32Array(n);p.arraycopy(e,0,i,0,n);let a=new ie(this.field,i);a=a.multiplyByMonomial(t,1);let o=a.divide(r)[1].getCoefficients(),s=t-o.length;for(let t=0;t<s;t++)e[n+t]=0;p.arraycopy(o,0,e,n+s,o.length)}}class 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===Pt.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=Ot.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===Pt.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,Ot.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 Pt.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 Pt.BYTE}return r?Pt.ALPHANUMERIC:n?Pt.NUMERIC:Pt.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=Ot.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 Pt.NUMERIC:Pn.appendNumericBytes(e,n);break;case Pt.ALPHANUMERIC:Pn.appendAlphanumericBytes(e,n);break;case Pt.BYTE:Pn.append8BitBytes(e,n,r);break;case Pt.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(Pt.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=Et.L,a=Fn.QUIET_ZONE_SIZE;r!==null&&(r.get(En.ERROR_CORRECTION)!==void 0&&(i=Et.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!==B.QR_CODE)throw new l(`Can only encode QR_CODE, but got `+t);if(n<0||r<0)throw new l(`Requested dimensions are too small: ${n}x${r}`);let a=Et.L,o=In.QUIET_ZONE_SIZE;i!==null&&(i.get(En.ERROR_CORRECTION)!==void 0&&(a=Et.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 B.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!==B.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=Ye,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=B,e.Binarizer=f,e.BinaryBitmap=u,e.BitArray=v,e.BitMatrix=O,e.BitSource=vt,e.BrowserAztecCodeReader=Se,e.BrowserBarcodeReader=ft,e.BrowserCodeReader=L,e.BrowserDatamatrixCodeReader=wt,e.BrowserMultiFormatReader=Cn,e.BrowserPDF417Reader=wn,e.BrowserQRCodeReader=Tn,e.BrowserQRCodeSvgWriter=Fn,e.CharacterSetECI=C,e.ChecksumException=d,e.Code128Reader=we,e.Code39Reader=Te,e.DataMatrixDecodedBitStreamParser=bt,e.DataMatrixReader=Ct,e.DecodeHintType=b,e.DecoderResult=ne,e.DefaultGridSampler=_e,e.DetectorResult=pe,e.EAN13Reader=Me,e.EncodeHintType=En,e.Exception=s,e.FormatException=x,e.GenericGF=oe,e.GenericGFPoly=ie,e.GlobalHistogramBinarizer=A,e.GridSampler=ge,e.GridSamplerInstance=ve,e.HTMLCanvasElementLuminanceSource=P,e.HybridBinarizer=j,e.ITFReader=Ee,e.IllegalArgumentException=l,e.IllegalStateException=ce,e.InvertedLuminanceSource=N,e.LuminanceSource=M,e.MathUtils=de,e.MultiFormatOneDReader=dt,e.MultiFormatReader=Sn,e.MultiFormatWriter=Ln,e.NotFoundException=k,e.OneDReader=Ce,e.PDF417DecodedBitStreamParser=q,e.PDF417DecoderErrorCorrection=Zt,e.PDF417Reader=bn,e.PDF417ResultMetadata=cn,e.PerspectiveTransform=U,e.PlanarYUVLuminanceSource=Rn,e.QRCodeByteMatrix=kn,e.QRCodeDataMask=At,e.QRCodeDecodedBitStreamParser=Ft,e.QRCodeDecoderErrorCorrectionLevel=Et,e.QRCodeDecoderFormatInformation=Dt,e.QRCodeEncoder=Pn,e.QRCodeEncoderQRCode=An,e.QRCodeMaskUtil=On,e.QRCodeMatrixUtil=Mn,e.QRCodeMode=Pt,e.QRCodeReader=Wt,e.QRCodeVersion=Ot,e.QRCodeWriter=In,e.RGBLuminanceSource=zn,e.RSS14Reader=ut,e.RSSExpandedReader=W,e.ReaderException=xn,e.ReedSolomonDecoder=le,e.ReedSolomonEncoder=Dn,e.ReedSolomonException=se,e.Result=R,e.ResultMetadataType=te,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=ot,Object.defineProperty(e,"__esModule",{value:!0})}))}))()),__=function(){function e(e,t,n){if(this.formatMap=new Map([[$g.QR_CODE,g_.BarcodeFormat.QR_CODE],[$g.AZTEC,g_.BarcodeFormat.AZTEC],[$g.CODABAR,g_.BarcodeFormat.CODABAR],[$g.CODE_39,g_.BarcodeFormat.CODE_39],[$g.CODE_93,g_.BarcodeFormat.CODE_93],[$g.CODE_128,g_.BarcodeFormat.CODE_128],[$g.DATA_MATRIX,g_.BarcodeFormat.DATA_MATRIX],[$g.MAXICODE,g_.BarcodeFormat.MAXICODE],[$g.ITF,g_.BarcodeFormat.ITF],[$g.EAN_13,g_.BarcodeFormat.EAN_13],[$g.EAN_8,g_.BarcodeFormat.EAN_8],[$g.PDF_417,g_.BarcodeFormat.PDF_417],[$g.RSS_14,g_.BarcodeFormat.RSS_14],[$g.RSS_EXPANDED,g_.BarcodeFormat.RSS_EXPANDED],[$g.UPC_A,g_.BarcodeFormat.UPC_A],[$g.UPC_E,g_.BarcodeFormat.UPC_E],[$g.UPC_EAN_EXTENSION,g_.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!g_)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(g_.DecodeHintType.POSSIBLE_FORMATS,r),i.set(g_.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 g_.MultiFormatReader(this.verbose,this.hints),n=new g_.HTMLCanvasElementLuminanceSource(e),r=new g_.BinaryBitmap(new g_.HybridBinarizer(n)),i=t.decode(r);return{text:i.text,format:a_.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}(),v_=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())})},y_=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}}},b_=function(){function e(t,n,r){if(this.formatMap=new Map([[$g.QR_CODE,`qr_code`],[$g.AZTEC,`aztec`],[$g.CODABAR,`codabar`],[$g.CODE_39,`code_39`],[$g.CODE_93,`code_93`],[$g.CODE_128,`code_128`],[$g.DATA_MATRIX,`data_matrix`],[$g.ITF,`itf`],[$g.EAN_13,`ean_13`],[$g.EAN_8,`ean_8`],[$g.PDF_417,`pdf417`],[$g.UPC_A,`upc_a`],[$g.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 v_(this,void 0,void 0,function(){var t,n;return y_(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:a_.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}(),x_=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())})},S_=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}}},C_=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&&b_.isSupported()?(this.primaryDecoder=new b_(e,n,r),this.secondaryDecoder=new __(e,n,r)):this.primaryDecoder=new __(e,n,r)}return e.prototype.decodeAsync=function(e){return x_(this,void 0,void 0,function(){var t;return S_(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 x_(this,void 0,void 0,function(){var t,n;return S_(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}(),w_=(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)}})(),T_=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())})},E_=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}}},D_=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}(),O_=function(e){w_(t,e);function t(t){return e.call(this,`zoom`,t)||this}return t}(function(e){w_(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}(D_)),k_=function(e){w_(t,e);function t(t){return e.call(this,`torch`,t)||this}return t}(D_),A_=function(){function e(e){this.track=e}return e.prototype.zoomFeature=function(){return new O_(this.track)},e.prototype.torchFeature=function(){return new k_(this.track)},e}(),j_=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 T_(this,void 0,void 0,function(){var a,o;return E_(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 T_(this,void 0,void 0,function(){return E_(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 A_(this.getFirstTrackOrFail())},e}(),M_=function(){function e(e){this.mediaStream=e}return e.prototype.render=function(e,t,n){return T_(this,void 0,void 0,function(){return E_(this,function(r){return[2,j_.create(e,this.mediaStream,t,n)]})})},e.create=function(t){return T_(this,void 0,void 0,function(){var n,r;return E_(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}(),N_=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())})},P_=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}}},F_=function(){function e(){}return e.failIfNotSupported=function(){return N_(this,void 0,void 0,function(){return P_(this,function(t){if(!navigator.mediaDevices)throw`navigator.mediaDevices not supported`;return[2,new e]})})},e.prototype.create=function(e){return N_(this,void 0,void 0,function(){return P_(this,function(t){return[2,M_.create(e)]})})},e}(),I_=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},L_=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},R_=function(){function e(){}return e.retrieve=function(){return navigator.mediaDevices?e.getCamerasFromMediaDevices():MediaStreamTrack&&MediaStreamTrack.getSources?e.getCamerasFromMediaStreamTrack():e.rejectWithError()},e.rejectWithError=function(){var t=f_.unableToQuerySupportedDevices();return e.isHttpsOrLocalhost()||(t=f_.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 I_(this,void 0,void 0,function(){var e,t,n,r,i,a,o;return L_(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}(),z_;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.NOT_STARTED=1]=`NOT_STARTED`,e[e.SCANNING=2]=`SCANNING`,e[e.PAUSED=3]=`PAUSED`})(z_||={});var B_=function(){function e(){this.state=z_.NOT_STARTED,this.onGoingTransactionNewState=z_.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===z_.UNKNOWN)throw`Transaction is already cancelled, cannot execute().`;var e=this.onGoingTransactionNewState;this.onGoingTransactionNewState=z_.UNKNOWN,this.directTransition(e)},e.prototype.cancel=function(){if(this.onGoingTransactionNewState===z_.UNKNOWN)throw`Transaction is already cancelled, cannot cancel().`;this.onGoingTransactionNewState=z_.UNKNOWN},e.prototype.getState=function(){return this.state},e.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==z_.UNKNOWN)throw`Cannot transition to a new state, already under transition`},e.prototype.validateTransition=function(e){switch(this.state){case z_.UNKNOWN:throw`Transition from unknown is not allowed`;case z_.NOT_STARTED:this.failIfNewStateIs(e,[z_.PAUSED]);break;case z_.SCANNING:break;case z_.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}(),V_=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()===z_.NOT_STARTED},e.prototype.isScanning=function(){return this.stateManager.getState()!==z_.NOT_STARTED},e.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===z_.SCANNING},e.prototype.isPaused=function(){return this.stateManager.getState()===z_.PAUSED},e}(),H_=function(){function e(){}return e.create=function(){return new V_(new B_)},e}(),U_=(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)}})(),W_=function(e){U_(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}(i_),G_=function(){function e(e,t){this.logger=t,this.fps=W_.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=W_.DEFAULT_DISABLE_FLIP}return e.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?h_.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError(`Empty videoConstraints`,!0),!1)},e.prototype.isShadedBoxEnabled=function(){return!u_(this.qrbox)},e.create=function(t,n){return new e(t,n)},e}(),K_=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 l_(this.verbose),this.qrcode=new C_(this.getSupportedFormats(t),this.getUseBarCodeDetectorIfSupported(n),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=H_.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=G_.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:W_.DEFAULT_WIDTH,l.style.position=`relative`,this.shouldScan=!0,this.element=l;var u=this,d=this.stateManagerProxy.startTransition(z_.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)}};F_.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(f_.errorGettingUserMedia(e))})}).catch(function(e){d.cancel(),r(f_.cameraStreamingNotSupported())})})},e.prototype.pause=function(e){if(!this.stateManagerProxy.isStrictlyScanning())throw`Cannot pause, scanner is not scanning.`;this.stateManagerProxy.directTransition(z_.PAUSED),this.showPausedState(),(u_(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(z_.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(z_.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var n=function(){if(e.element){var t=document.getElementById(W_.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(u_(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:W_.DEFAULT_WIDTH,l=Math.max(s.clientHeight?s.clientHeight:o,W_.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=W_.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(o_.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 R_.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(!h_.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=[$g.QR_CODE,$g.AZTEC,$g.CODABAR,$g.CODE_39,$g.CODE_93,$g.CODE_128,$g.DATA_MATRIX,$g.MAXICODE,$g.ITF,$g.EAN_13,$g.EAN_8,$g.PDF_417,$g.RSS_14,$g.RSS_EXPANDED,$g.UPC_A,$g.UPC_E,$g.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];n_(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(u_(e))return!0;if(!u_(e.useBarCodeDetectorIfSupported))return e.useBarCodeDetectorIfSupported!==!1;if(u_(e.experimentalFeatures))return!0;var t=e.experimentalFeatures;return u_(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<W_.MIN_QR_BOX_SIZE)throw`minimum size of 'config.qrbox' dimension value is ${W_.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=u_(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=f_.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,o_.createFromQrcodeResult(t)),n.possiblyUpdateShaders(!0),!0}).catch(function(e){n.possiblyUpdateShaders(!1);var r=f_.codeParseError(e);return t(r,c_.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?W_.BORDER_SHADER_MATCH_COLOR:W_.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=u_(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=`${W_.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=W_.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}(),q_=`data:image/svg+xml;base64,`,J_=q_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNzEuNjQzIDM3MS42NDMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDM3MS42NDMgMzcxLjY0MyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZD0iTTEwNS4wODQgMzguMjcxaDE2My43Njh2MjBIMTA1LjA4NHoiLz48cGF0aCBkPSJNMzExLjU5NiAxOTAuMTg5Yy03LjQ0MS05LjM0Ny0xOC40MDMtMTYuMjA2LTMyLjc0My0yMC41MjJWMzBjMC0xNi41NDItMTMuNDU4LTMwLTMwLTMwSDEyNS4wODRjLTE2LjU0MiAwLTMwIDEzLjQ1OC0zMCAzMHYxMjAuMTQzaC04LjI5NmMtMTYuNTQyIDAtMzAgMTMuNDU4LTMwIDMwdjEuMzMzYTI5LjgwNCAyOS44MDQgMCAwIDAgNC42MDMgMTUuOTM5Yy03LjM0IDUuNDc0LTEyLjEwMyAxNC4yMjEtMTIuMTAzIDI0LjA2MXYxLjMzM2MwIDkuODQgNC43NjMgMTguNTg3IDEyLjEwMyAyNC4wNjJhMjkuODEgMjkuODEgMCAwIDAtNC42MDMgMTUuOTM4djEuMzMzYzAgMTYuNTQyIDEzLjQ1OCAzMCAzMCAzMGg4LjMyNGMuNDI3IDExLjYzMSA3LjUwMyAyMS41ODcgMTcuNTM0IDI2LjE3Ny45MzEgMTAuNTAzIDQuMDg0IDMwLjE4NyAxNC43NjggNDUuNTM3YTkuOTg4IDkuOTg4IDAgMCAwIDguMjE2IDQuMjg4IDkuOTU4IDkuOTU4IDAgMCAwIDUuNzA0LTEuNzkzYzQuNTMzLTMuMTU1IDUuNjUtOS4zODggMi40OTUtMTMuOTIxLTYuNzk4LTkuNzY3LTkuNjAyLTIyLjYwOC0xMC43Ni0zMS40aDgyLjY4NWMuMjcyLjQxNC41NDUuODE4LjgxNSAxLjIxIDMuMTQyIDQuNTQxIDkuMzcyIDUuNjc5IDEzLjkxMyAyLjUzNCA0LjU0Mi0zLjE0MiA1LjY3Ny05LjM3MSAyLjUzNS0xMy45MTMtMTEuOTE5LTE3LjIyOS04Ljc4Ny0zNS44ODQgOS41ODEtNTcuMDEyIDMuMDY3LTIuNjUyIDEyLjMwNy0xMS43MzIgMTEuMjE3LTI0LjAzMy0uODI4LTkuMzQzLTcuMTA5LTE3LjE5NC0xOC42NjktMjMuMzM3YTkuODU3IDkuODU3IDAgMCAwLTEuMDYxLS40ODZjLS40NjYtLjE4Mi0xMS40MDMtNC41NzktOS43NDEtMTUuNzA2IDEuMDA3LTYuNzM3IDE0Ljc2OC04LjI3MyAyMy43NjYtNy42NjYgMjMuMTU2IDEuNTY5IDM5LjY5OCA3LjgwMyA0Ny44MzYgMTguMDI2IDUuNzUyIDcuMjI1IDcuNjA3IDE2LjYyMyA1LjY3MyAyOC43MzMtLjQxMyAyLjU4NS0uODI0IDUuMjQxLTEuMjQ1IDcuOTU5LTUuNzU2IDM3LjE5NC0xMi45MTkgODMuNDgzLTQ5Ljg3IDExNC42NjEtNC4yMjEgMy41NjEtNC43NTYgOS44Ny0xLjE5NCAxNC4wOTJhOS45OCA5Ljk4IDAgMCAwIDcuNjQ4IDMuNTUxIDkuOTU1IDkuOTU1IDAgMCAwIDYuNDQ0LTIuMzU4YzQyLjY3Mi0zNi4wMDUgNTAuODAyLTg4LjUzMyA1Ni43MzctMTI2Ljg4OC40MTUtMi42ODQuODIxLTUuMzA5IDEuMjI5LTcuODYzIDIuODM0LTE3LjcyMS0uNDU1LTMyLjY0MS05Ljc3Mi00NC4zNDV6bS0yMzIuMzA4IDQyLjYyYy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM2MwLTUuNTE0IDQuNDg2LTEwIDEwLTEwaDE1djIxLjMzM2gtMTV6bS0yLjUtNTIuNjY2YzAtNS41MTQgNC40ODYtMTAgMTAtMTBoNy41djIxLjMzM2gtNy41Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM3ptMTcuNSA5My45OTloLTcuNWMtNS41MTQgMC0xMC00LjQ4Ni0xMC0xMHYtMS4zMzNjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGg3LjV2MjEuMzMzem0zMC43OTYgMjguODg3Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi04LjI3MWg5MS40NTdjLS44NTEgNi42NjgtLjQzNyAxMi43ODcuNzMxIDE4LjI3MWgtODIuMTg4em03OS40ODItMTEzLjY5OGMtMy4xMjQgMjAuOTA2IDEyLjQyNyAzMy4xODQgMjEuNjI1IDM3LjA0IDUuNDQxIDIuOTY4IDcuNTUxIDUuNjQ3IDcuNzAxIDcuMTg4LjIxIDIuMTUtMi41NTMgNS42ODQtNC40NzcgNy4yNTEtLjQ4Mi4zNzgtLjkyOS44LTEuMzM1IDEuMjYxLTYuOTg3IDcuOTM2LTExLjk4MiAxNS41Mi0xNS40MzIgMjIuNjg4aC05Ny41NjRWMzBjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGgxMjMuNzY5YzUuNTE0IDAgMTAgNC40ODYgMTAgMTB2MTM1LjU3OWMtMy4wMzItLjM4MS02LjE1LS42OTQtOS4zODktLjkxNC0yNS4xNTktMS42OTQtNDIuMzcgNy43NDgtNDQuODk4IDI0LjY2NnoiLz48cGF0aCBkPSJNMTc5LjEyOSA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXpNMTcyLjYyOSAxNDIuODZoLTEyLjU2VjEzMC44YTUgNSAwIDEgMC0xMCAwdjE3LjA2MWE1IDUgMCAwIDAgNSA1aDE3LjU2YTUgNSAwIDEgMCAwLTEwLjAwMXpNMjE2LjU2OCA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXptLTUgMjQuMDYxaC0xNC4wNlY5My4xNjdoMTQuMDZ2MTQuMDYxek0yMTEuNjY5IDEyNS45MzZIMTk3LjQxYTUgNSAwIDAgMC01IDV2MTQuMjU3YTUgNSAwIDAgMCA1IDVoMTQuMjU5YTUgNSAwIDAgMCA1LTV2LTE0LjI1N2E1IDUgMCAwIDAtNS01eiIvPjwvc3ZnPg==`,Y_=q_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1OS4wMTggNTkuMDE4IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1OS4wMTggNTkuMDE4IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJtNTguNzQxIDU0LjgwOS01Ljk2OS02LjI0NGExMC43NCAxMC43NCAwIDAgMCAyLjgyLTcuMjVjMC01Ljk1My00Ljg0My0xMC43OTYtMTAuNzk2LTEwLjc5NlMzNCAzNS4zNjEgMzQgNDEuMzE0IDM4Ljg0MyA1Mi4xMSA0NC43OTYgNTIuMTFjMi40NDEgMCA0LjY4OC0uODI0IDYuNDk5LTIuMTk2bDYuMDAxIDYuMjc3YS45OTguOTk4IDAgMCAwIDEuNDE0LjAzMiAxIDEgMCAwIDAgLjAzMS0xLjQxNHpNMzYgNDEuMzE0YzAtNC44NSAzLjk0Ni04Ljc5NiA4Ljc5Ni04Ljc5NnM4Ljc5NiAzLjk0NiA4Ljc5NiA4Ljc5Ni0zLjk0NiA4Ljc5Ni04Ljc5NiA4Ljc5NlMzNiA0Ni4xNjQgMzYgNDEuMzE0ek0xMC40MzEgMTYuMDg4YzAgMy4wNyAyLjQ5OCA1LjU2OCA1LjU2OSA1LjU2OHM1LjU2OS0yLjQ5OCA1LjU2OS01LjU2OGMwLTMuMDcxLTIuNDk4LTUuNTY5LTUuNTY5LTUuNTY5cy01LjU2OSAyLjQ5OC01LjU2OSA1LjU2OXptOS4xMzggMGMwIDEuOTY4LTEuNjAyIDMuNTY4LTMuNTY5IDMuNTY4cy0zLjU2OS0xLjYwMS0zLjU2OS0zLjU2OCAxLjYwMi0zLjU2OSAzLjU2OS0zLjU2OSAzLjU2OSAxLjYwMSAzLjU2OSAzLjU2OXoiLz48cGF0aCBkPSJtMzAuODgyIDI4Ljk4NyA5LjE4LTEwLjA1NCAxMS4yNjIgMTAuMzIzYTEgMSAwIDAgMCAxLjM1MS0xLjQ3NWwtMTItMTFhMSAxIDAgMCAwLTEuNDE0LjA2M2wtOS43OTQgMTAuNzI3LTQuNzQzLTQuNzQzYTEuMDAzIDEuMDAzIDAgMCAwLTEuMzY4LS4wNDRMNi4zMzkgMzcuNzY4YTEgMSAwIDEgMCAxLjMyMiAxLjUwMWwxNi4zMTMtMTQuMzYyIDcuMzE5IDcuMzE4YS45OTkuOTk5IDAgMSAwIDEuNDE0LTEuNDE0bC0xLjgyNS0xLjgyNHoiLz48cGF0aCBkPSJNMzAgNDYuNTE4SDJ2LTQyaDU0djI4YTEgMSAwIDEgMCAyIDB2LTI5YTEgMSAwIDAgMC0xLTFIMWExIDEgMCAwIDAtMSAxdjQ0YTEgMSAwIDAgMCAxIDFoMjlhMSAxIDAgMSAwIDAtMnoiLz48L3N2Zz4=`,X_=q_+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NjAgNDYwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0NjAgNDYwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNMjMwIDBDMTAyLjk3NSAwIDAgMTAyLjk3NSAwIDIzMHMxMDIuOTc1IDIzMCAyMzAgMjMwIDIzMC0xMDIuOTc0IDIzMC0yMzBTMzU3LjAyNSAwIDIzMCAwem0zOC4zMzMgMzc3LjM2YzAgOC42NzYtNy4wMzQgMTUuNzEtMTUuNzEgMTUuNzFoLTQzLjEwMWMtOC42NzYgMC0xNS43MS03LjAzNC0xNS43MS0xNS43MVYyMDIuNDc3YzAtOC42NzYgNy4wMzMtMTUuNzEgMTUuNzEtMTUuNzFoNDMuMTAxYzguNjc2IDAgMTUuNzEgNy4wMzMgMTUuNzEgMTUuNzFWMzc3LjM2ek0yMzAgMTU3Yy0yMS41MzkgMC0zOS0xNy40NjEtMzktMzlzMTcuNDYxLTM5IDM5LTM5IDM5IDE3LjQ2MSAzOSAzOS0xNy40NjEgMzktMzkgMzl6Ii8+PC9zdmc+`,Z_=`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}(),$_=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}(),ev=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=m_.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=m_.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}(),tv=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=X_,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=Z_,this.infoIcon.style.opacity=`1`):(this.isShowingInfoIcon=!0,this.onTapOut(),this.infoIcon.src=X_,this.infoIcon.style.opacity=`0.6`)},e}(),nv=function(){function e(){var e=this;this.infoDiv=new ev,this.infoIcon=new tv(function(){e.infoDiv.show()},function(){e.infoDiv.hide()})}return e.prototype.renderInto=function(e){this.infoDiv.renderInto(e),this.infoIcon.renderInto(e)},e}(),rv=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())})},iv=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}}},av=function(){function e(){}return e.hasPermissions=function(){return rv(this,void 0,void 0,function(){var e,t,n,r;return iv(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}(),ov=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===r_.SCAN_TYPE_CAMERA},e.isFileScanType=function(e){return e===r_.SCAN_TYPE_FILE},e.prototype.validateAndReturnScanTypes=function(e){if(!e||e.length===0)return i_.DEFAULT_SUPPORTED_SCAN_TYPE;var t=i_.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(!i_.DEFAULT_SUPPORTED_SCAN_TYPE.includes(i))throw`Unsupported scan type ${i}`}return e},e}(),sv=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}(),cv=function(){function e(){}return e.createElement=function(e,t){var n=document.createElement(e);return n.id=t,n.classList.add(sv.ALL_ELEMENT_CLASS),e===`button`&&n.setAttribute(`type`,`button`),n},e}(),lv=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())})},uv=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}}},dv=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 lv(this,void 0,void 0,function(){var e,t;return uv(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?p_.torchOffButton():p_.torchOnButton()),this.isTorchOn=t):this.propagateFailure(t),this.buttonController.enable()},e.prototype.propagateFailure=function(e,t){var n=e?p_.torchOnFailedMessage():p_.torchOffFailedMessage();t&&(n+=`; Error = `+t),this.onTorchActionFailureCallback(n)},e.prototype.reset=function(){this.isTorchOn=!1},e}(),fv=function(){function e(e,t){this.onTorchActionFailureCallback=t,this.torchButton=cv.createElement(`button`,sv.TORCH_BUTTON_ID),this.torchController=new dv(e,this,t)}return e.prototype.render=function(e,t){var n=this;this.torchButton.innerText=p_.torchOnButton(),this.torchButton.style.display=t.display,this.torchButton.style.marginLeft=t.marginLeft;var r=this;this.torchButton.addEventListener(`click`,function(e){return lv(n,void 0,void 0,function(){return uv(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(sv.TORCH_BUTTON_CLASS_TORCH_OFF),r.torchButton.classList.add(sv.TORCH_BUTTON_CLASS_TORCH_ON)):(r.torchButton.classList.remove(sv.TORCH_BUTTON_CLASS_TORCH_ON),r.torchButton.classList.add(sv.TORCH_BUTTON_CLASS_TORCH_OFF)),[2]}})})}),e.appendChild(this.torchButton)},e.prototype.updateTorchCapability=function(e){this.torchController=new dv(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=p_.torchOnButton(),this.torchController.reset()},e.create=function(t,n,r,i){var a=new e(n,i);return a.render(t,r),a},e}(),pv=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=cv.createElement(`button`,sv.FILE_SELECTION_BUTTON_ID),this.setInitialValueToButton(),this.fileSelectionButton.addEventListener(`click`,function(e){r.click()}),r.append(this.fileSelectionButton),this.fileScanInput=cv.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=p_.dragAndDropMessage();break}}o||(a.innerText=p_.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=p_.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=p_.fileSelectionChooseAnother()+` - `+e;this.fileSelectionButton.innerText=r},e.prototype.setInitialValueToButton=function(){var e=p_.fileSelectionChooseImage()+` - `+p_.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}(),mv=function(){function e(e){this.selectElement=cv.createElement(`select`,sv.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=`${p_.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=[p_.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}(),hv=function(){function e(){this.onChangeCallback=null,this.zoomElementContainer=document.createElement(`div`),this.rangeInput=cv.createElement(`input`,sv.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=p_.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=p_.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}(),gv;(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`})(gv||={});function _v(e){return{fps:e.fps,qrbox:e.qrbox,aspectRatio:e.aspectRatio,disableFlip:e.disableFlip,videoConstraints:e.videoConstraints}}function vv(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 ov(this.config.supportedScanTypes),this.currentScanType=this.scanTypeSelector.getDefaultScanType(),this.sectionSwapAllowed=!0,this.logger=new l_(this.verbose),this.persistedDataManager=new $_,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(p_.lastMatch(t),gv.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 K_(this.getScanRegionId(),vv(this.config,this.verbose))},e.prototype.pause=function(e){(u_(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||=i_.SCAN_DEFAULT_FPS,e.rememberLastUsedCamera!==!i_.DEFAULT_REMEMBER_LAST_CAMERA_USED&&(e.rememberLastUsedCamera=i_.DEFAULT_REMEMBER_LAST_CAMERA_USED),e.supportedScanTypes||=i_.DEFAULT_SUPPORTED_SCAN_TYPE,e):{fps:i_.SCAN_DEFAULT_FPS,rememberLastUsedCamera:i_.DEFAULT_REMEMBER_LAST_CAMERA_USED,supportedScanTypes:i_.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),ov.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 nv().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(p_.cameraPermissionRequesting());var i=function(){n||r.createPermissionButton(e,t)};K_.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(p_.noCameraFound(),gv.STATUS_WARNING),i())}).catch(function(e){r.persistedDataManager.setHasPermission(!1),n?n.disabled=!1:i(),r.setHeaderMessage(e,gv.STATUS_WARNING),r.showHideScanTypeSwapLink(!0)})},e.prototype.createPermissionButton=function(e,t){var n=this,r=cv.createElement(`button`,this.getCameraPermissionButtonId());r.innerText=p_.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(ov.isCameraScanType(this.currentScanType)&&this.persistedDataManager.hasCameraPermissions()){av.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=ov.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=ov.isFileScanType(this.currentScanType),n=this,r=function(e){if(!n.html5Qrcode)throw`html5Qrcode not defined`;ov.isFileScanType(n.currentScanType)&&(n.setHeaderMessage(p_.loadingImage()),n.html5Qrcode.scanFileV2(e,!0).then(function(e){n.resetHeaderMessage(),n.qrCodeSuccessCallback(e.decodedText,e)}).catch(function(e){n.setHeaderMessage(e,gv.STATUS_WARNING),n.qrCodeErrorCallback(e,c_.createFrom(e))}))};this.fileSelectionUi=pv.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=hv.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=d_(r,n.min(),n.max()),i.setValues(n.min(),n.max(),r,n.step()),i.show()}},o=mv.create(r,e),s=document.createElement(`span`),c=cv.createElement(`button`,sv.CAMERA_START_BUTTON_ID);c.innerText=p_.scanButtonStartScanningText(),s.appendChild(c);var l=cv.createElement(`button`,sv.CAMERA_STOP_BUTTON_ID);l.innerText=p_.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=fv.create(s,e.torchFeature(),{display:`none`,marginLeft:`5px`},function(e){n.setHeaderMessage(e,gv.STATUS_WARNING)}),u.show()};r.appendChild(s);var f=function(e){e||(c.style.display=`none`),c.innerText=p_.scanButtonStartScanningText(),c.style.opacity=`1`,c.disabled=!1,e&&(c.style.display=`inline-block`)};if(c.addEventListener(`click`,function(e){c.innerText=p_.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,_v(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,gv.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,gv.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=p_.textIfCameraScanSelected(),n=p_.textIfFileScanSelected(),r=document.getElementById(this.getDashboardSectionId()),i=document.createElement(`div`);i.style.textAlign=`center`;var a=cv.createElement(`span`,this.getDashboardSectionSwapLinkId());a.style.textDecoration=`underline`,a.style.cursor=`pointer`,a.innerText=ov.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,ov.isCameraScanType(e.currentScanType)?(e.clearScanRegion(),e.getCameraScanRegion().style.display=`none`,e.fileSelectionUi.show(),a.innerText=n,e.currentScanType=r_.SCAN_TYPE_FILE,e.insertFileScanImageToScanRegion()):(e.clearScanRegion(),e.getCameraScanRegion().style.display=`block`,e.fileSelectionUi.hide(),a.innerText=t,e.currentScanType=r_.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()){av.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||=gv.STATUS_DEFAULT;var n=this.getHeaderMessageDiv();switch(n.innerText=e,n.style.display=`block`,t){case gv.STATUS_SUCCESS:n.style.background=`rgba(106, 175, 80, 0.26)`,n.style.color=`#477735`;break;case gv.STATUS_WARNING:n.style.background=`rgba(203, 36, 49, 0.14)`,n.style.color=`#cb2431`;break;case gv.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=J_,this.cameraScanImage.alt=p_.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=Y_,this.fileScanImage.alt=p_.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 sv.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 sv.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 yv;(function(e){e[e.BACK=1]=`BACK`,e[e.FRONT=2]=`FRONT`})(yv||={});var bv;(function(e){e[e.PORTRAIT=1]=`PORTRAIT`,e[e.LANDSCAPE=2]=`LANDSCAPE`,e[e.ADAPTIVE=3]=`ADAPTIVE`})(bv||={});var xv;(function(e){e[e.ALL=17]=`ALL`})(xv||={});var Sv=Object.assign(Object.assign({},$g),xv),Cv;(function(e){e.ZXING=`zxing`,e.MLKIT=`mlkit`})(Cv||={});var wv=[{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 Tv(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 Ev=gh(`CapacitorBarcodeScanner`,{web:()=>(Tv(wv),$r(()=>import(`./web-Cq4yC7dg.js`).then(e=>new e.CapacitorBarcodeScannerWeb),[]))}),Dv=class{static async scanBarcode(e){return e.scanInstructions=e.scanInstructions||` `,e.scanButton=e.scanButton||!1,e.scanText=e.scanText||` `,e.cameraDirection=e.cameraDirection||yv.BACK,e.scanOrientation=e.scanOrientation||bv.ADAPTIVE,Ev.scanBarcode(e)}};function Ov(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 kv(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 Av(){let[e,t]=(0,Y.useState)(!1);return{scan:(0,Y.useCallback)(async()=>{if(!wn())return{value:null,error:null};t(!0);try{let e=await Dv.scanBarcode({hint:Sv.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 kv(e)?{value:null,error:null}:Ov(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:wn()}}function jv(){let[e,t]=(0,Y.useState)(!0),[n,r]=(0,Y.useState)(At),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(!1),u=Av();(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 d=(0,Y.useCallback)(async()=>{let e=en(n);if(e){a(null),l(!0);try{if(!await ft(e)){a(e);return}yn(n)}finally{l(!1)}}},[n]),f=(0,Y.useCallback)(async()=>{s(null);let e=await u.scan();if(e.error){s(e.error);return}if(e.value){r(e.value),a(null);let t=en(e.value);if(!t){s(`The scanned QR code did not contain a valid server address.`);return}l(!0);try{if(!await ft(t)){a(t);return}yn(e.value)}finally{l(!1)}}},[u]);return e?null:(0,$.jsx)(oi,{open:!0,children:(0,$.jsxs)(li,{children:[(0,$.jsxs)(si,{children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`mx-auto h-16 w-16 rounded-lg`}),(0,$.jsx)(ni,{children:`Connect to Tarsk`}),(0,$.jsx)(ii,{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)(Xe,{value:n,onChange:e=>{r(e.target.value),a(null),s(null)},onKeyDown:e=>{e.key===`Enter`&&!c&&d()},placeholder:`192.168.1.100`,autoComplete:`off`,spellCheck:!1,disabled:c,className:u.isAvailable?`pr-10`:void 0}),u.isAvailable&&(0,$.jsx)(V,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-1 top-1 h-8 w-8`,"aria-label":`Scan QR code`,disabled:c||u.isScanning,onClick:()=>void f(),children:u.isScanning?(0,$.jsx)(Et,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Qe,{className:`h-4 w-4`})})]}),o&&(0,$.jsxs)(mi,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsx)(`p`,{className:`flex-1`,children:o}),(0,$.jsx)(V,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>s(null),children:(0,$.jsx)(zn,{className:`h-4 w-4`})})]}),i&&(0,$.jsxs)(mi,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsxs)(`p`,{className:`flex-1`,children:[`Unable to connect to `,i,`. Please check that you are on the same network and that the Tarsk server is running and accessible on the network.`]}),(0,$.jsx)(V,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>a(null),children:(0,$.jsx)(zn,{className:`h-4 w-4`})})]}),(0,$.jsx)(ai,{children:(0,$.jsx)(V,{onClick:()=>void d(),disabled:!n.trim()||c,children:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Et,{className:`mr-2 h-4 w-4 animate-spin`}),`Connecting...`]}):`Connect`})}),(0,$.jsxs)(mi,{variant:`hint`,className:`mb-0`,children:[(0,$.jsx)(`p`,{className:J.bodyMuted,children:`Start the Tarsk server on your local machine by running:`}),(0,$.jsx)(`code`,{className:U(J.mono,`mt-2 block rounded bg-background/60 px-2 py-1 text-foreground`),children:`npx tarsk --server`})]})]})})}var Mv=(0,Y.lazy)(()=>$r(()=>import(`./dialogs-config-BF_RyK5j.js`).then(e=>e.t),__vite__mapDeps([3,1]))),Nv=(0,Y.lazy)(()=>$r(()=>import(`./onboarding-B_n7I3ri.js`).then(e=>e.t),__vite__mapDeps([4,1,5,3])));function Pv(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)(Mv,{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)(Xg,{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)(Zg,{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)(Nv,{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)(jv,{}),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 Fv=(0,Y.createContext)(null);function Iv(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(Lv)},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)(Fv.Provider,{value:u,children:n}),t[4]=n,t[5]=u,t[6]=d):d=t[6],d}function Lv(e){return e+1}function Rv(){let e=(0,Y.useContext)(Fv);if(!e)throw Error(`useBrowserTab must be used within a BrowserTabProvider`);return e}function zv(e){let t=e.trim();return t?t.startsWith(`http://`)||t.startsWith(`https://`)?t:`http://${t}`:``}function Bv(){return document.querySelector(`electrobun-webview`)}function Vv(e=2e4){return new Promise((t,n)=>{let r=Date.now();function i(){let a=Bv();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 Hv(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 Uv(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=Bv();if(!r||r.webviewId==null){requestAnimationFrame(n);return}rh(e,r.webviewId).catch(e=>{console.error(`[browser-tool] failed to report preview webview ready`,e)})}requestAnimationFrame(n)}async function Wv(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 Vv();t.syncDimensions(!0),await ih(r,{action:`set_viewport`,preset:e,webview_id:t.webviewId})}catch(t){console.error(`[browser-tool] failed to set viewport`,t),await ih(r,{action:`set_viewport`,preset:e,error:t instanceof Error?t.message:String(t)})}return}if(Fe(i.action)){try{await ih(r,await Hv(await Vv(),i,t))}catch(e){console.error(`[browser-tool] failed to execute host browser action`,e),await ih(r,{action:i.action,error:e instanceof Error?e.message:String(e)})}return}Uv(r)}}function Gv(){let{activeMainTab:e,setActiveMainTab:t}=hc(),{setDevServerUrl:n,devServerUrl:r}=Cd(),{setBrowserDeviceMode:i}=Rv(),a=(0,Y.useRef)(null),o=Q(e=>{let t=a.current;return t?e.threadStreamingStates[Bi(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(Xm,e),function(){window.removeEventListener(Xm,e)}},[]),(0,Y.useEffect)(()=>{if(!Dn())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=zv(n);e&&u.current(e)}Wv(t,s.current||``,d.current)}return window.addEventListener(Ym,e),function(){window.removeEventListener(Ym,e)}},[])}var Kv=lr,qv=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=U(`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)(Qn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});qv.displayName=Qn.displayName;var Jv=we(`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`}}),Yv=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=U(Jv({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)(_r,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});Yv.displayName=_r.displayName;var Xv=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=U(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive`,J.body,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(mr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Xv.displayName=mr.displayName;var Zv=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=U(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(zn,{className:`h-4 w-4`}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,$.jsx)(nr,{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});Zv.displayName=nr.displayName;var Qv=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=U(J.dialogTitle,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Qr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Qv.displayName=Qr.displayName;var $v=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=U(J.body,`opacity-90 text-muted-foreground group-[.destructive]:text-destructive-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(or,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});$v.displayName=or.displayName;function ey(){let e=(0,X.c)(5),{toasts:t}=no(),n;e[0]===t?n=e[1]:(n=t.map(ty),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(qv,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(Kv,{duration:1e4,children:[n,r]}),e[3]=n,e[4]=i),i}function ty(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,$.jsxs)(Yv,{...a,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(Qv,{children:n}),r&&(0,$.jsx)($v,{children:r})]}),i,(0,$.jsx)(Zv,{})]},t)}function ny(){return new Mi({defaultOptions:{queries:{staleTime:3e4,retry:1,refetchOnWindowFocus:!0},mutations:{retry:0}}})}function ry(e){let t=(0,X.c)(3),{children:n}=e,[r]=(0,Y.useState)(ny),i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Ar,{client:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function iy(){let e=(0,X.c)(4),{resolvedTheme:t,theme:n}=Ti(),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 ay(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)(iy,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsxs)(Ei,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}async function oy(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 sy(e,t){await oy(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 cy(){let e=(0,X.c)(14),t=za(),n=Q(dy),r=ci(`projects:bootstrap:${Q(uy)}`,C),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(ly);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 ly(e){return e.isSelected}function uy(e){return e.configUpdatedAt}function dy(e){return e.selectedThreadId}function fy(e){let t=za(),n=Q(e=>e.projects),r=Q(e=>e.selectedProjectId),i=Q(e=>e.selectedThreadId),{toast:a}=no(),o=Ba(`project-creation`).dispatch,[s,c]=(0,Y.useState)(null),l=(0,Y.useCallback)(async()=>{try{t({type:Z.SetProjectsLoading,projectsLoading:!0}),Qt(),fi(`projects:bootstrap:`);let e=await C();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}),Bn(e,n).catch(e=>{console.error(`Failed to select thread:`,e)})},[t,i,r]),d=(0,Y.useCallback)(async n=>{t({type:Z.SetCreatingProject,isCreating:!0});try{let r=await n.apiCall();if(!r){t({type:Z.SetCreatingProject,isCreating:!1}),await l();return}let i=n.useTerminalDispatch?o:t;i({type:Z.ClearTerminalOutput}),i({type:Z.SetTerminalOpen,open:!0}),i({type:Z.AppendTerminalLine,line:{type:`system`,content:n.initialMessage}});let a=r.getReader(),s=new TextDecoder,u=``,d=null,f=!1,p=null,m=null;for(;;){let{done:e,value:r}=await a.read();if(e)break;u+=s.decode(r,{stream:!0});let o=u.split(`
72
+ `);u=o.pop()??``;for(let e of o){let r=e.trim();if(r)try{let e=JSON.parse(r);if(e.type===`progress`)!f&&e.threadId&&e.projectId&&(f=!0,p=e.projectId,m=e.threadId,t({type:Z.AddCreatingProject,projectId:e.projectId,threadId:e.threadId,projectName:n.optimisticProjectName,gitUrl:n.gitUrl??``}),t({type:Z.AddProcessingThread,threadId:e.threadId})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`output`,content:e.message}});else if(e.type===`complete`){if(e.project){d=e.project.id;let r=n.includeThreadPath&&e.project.threads?.length>0?`${e.project.path}/${e.project.threads[0]}`:e.project.path;i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Project created successfully at: ${r}`}}),t({type:Z.SetTerminalOpen,open:!1}),n.handleSetupScript&&e.suggestedSetupScript&&c({projectId:e.project.id,command:e.suggestedSetupScript,remainingScripts:e.project.pendingSetupScripts??[]})}}else e.type===`error`&&(f&&p&&(t({type:Z.RemoveCreatingProject,projectId:p}),m&&t({type:Z.RemoveProcessingThread,threadId:m})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`error`,content:`Error: ${e.message}`}}))}catch(e){console.error(`Failed to parse ${n.logTag} event`,e)}}}t({type:Z.SetCreatingProject,isCreating:!1}),f&&m&&t({type:Z.RemoveProcessingThread,threadId:m}),Qt();let h=await C();if(t({type:Z.SetProjects,projects:h.projects}),t({type:Z.SetProjectsLoading,projectsLoading:!1}),d){let n=h.projects.find(e=>e.projectId===d);if(n&&n.threads.length>0){let e=n.threads[0].threadId;t({type:Z.SelectThread,threadId:e,projectId:d,focusInput:!0})}e?.onProjectCreated?.(d)}}catch(e){console.error(`Failed to ${n.logTag}:`,e),t({type:Z.SetCreatingProject,isCreating:!1}),(n.useTerminalDispatch?o:t)({type:Z.AppendTerminalLine,line:{type:`error`,content:`${n.catchErrorPrefix}: ${e instanceof Error?e.message:`Unknown error`}`}})}},[t,l,o,e?.onProjectCreated]),f=(0,Y.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await d({apiCall:()=>Rn(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[d]),p=(0,Y.useCallback)(async(e,t,n)=>{await d({apiCall:()=>Ae(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[d]),m=(0,Y.useCallback)(async e=>{await d({apiCall:()=>Vn(e),initialMessage:`Creating folder "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create folder`,catchErrorPrefix:`Failed to create folder`})},[d]),h=(0,Y.useCallback)(async(r,i)=>{try{let o=n.find(e=>e.projectId===r);e?.onThreadCreateStart?.(r),a({title:o?L(o):`Project`,description:`Creating a new thread....`});let s=i??(()=>{let e=n.find(e=>e.projectId===r)?.threads.map(e=>e.title)??[],t=/^thread-(\d+)$/i,i=0;for(let n of e){let e=n.match(t);e&&(i=Math.max(i,parseInt(e[1],10)))}return`thread-${i+1}`})(),c=await b(r,i);if(!c){await l();return}let u=c.getReader(),d=new TextDecoder,f=``,p=!1,m=null,h=!0,g=[{type:`system`,content:`Creating thread "${s}"...`}];try{for(;;){let{done:e,value:n}=await u.read();if(e)break;f+=d.decode(n,{stream:!0});let i=f.split(`
73
+ `);f=i.pop()??``;for(let e of i){let n=e.trim();if(n)try{let e=JSON.parse(n);if(e.type===`progress`){if(!p&&e.threadId){p=!0,m=e.threadId,t({type:Z.AddCreatingThread,projectId:r,threadId:e.threadId,title:s}),t({type:Z.AddProcessingThread,threadId:e.threadId}),t({type:Z.ClearTerminalOutput,threadId:m});for(let e of g)t({type:Z.AppendTerminalLine,threadId:m,line:e});g.length=0}let n={type:`output`,content:e.message};m?t({type:Z.AppendTerminalLine,threadId:m,line:n}):g.push(n)}else if(e.type===`error`){p&&m&&(t({type:Z.RemoveCreatingThread,projectId:r,threadId:m}),t({type:Z.RemoveProcessingThread,threadId:m}));let n={type:`error`,content:`Error: ${e.message}`};m?t({type:Z.AppendTerminalLine,threadId:m,line:n}):g.push(n),console.error(`Thread creation error:`,e.message),a({title:`Thread Creation Failed`,description:e.message,variant:`destructive`}),h=!1}}catch(e){console.error(`Failed to parse thread event`,e)}}}p&&m&&t({type:Z.RemoveProcessingThread,threadId:m}),Qt(),await l(),m&&h&&t({type:Z.SelectThread,threadId:m,projectId:r,focusInput:!0})}catch(e){throw p&&m&&(t({type:Z.RemoveCreatingThread,projectId:r,threadId:m}),t({type:Z.RemoveProcessingThread,threadId:m})),a({title:`Thread Creation Failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`}),e}}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,e?.onThreadCreateStart]),g=(0,Y.useCallback)(async(e,n)=>{t({type:Z.AddDeletingThread,threadId:n}),t({type:Z.ClearChatInputDraft,threadId:n});try{await ie(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]),_=(0,Y.useCallback)(async e=>{t({type:Z.AddDeletingProject,projectId:e});let i=n.find(t=>t.projectId===e)?.threads.map(e=>e.threadId)??[];for(let e of i)t({type:Z.AddDeletingThread,threadId:e}),t({type:Z.ClearChatInputDraft,threadId:e});try{await de(e),r===e&&t({type:Z.SelectThread,threadId:``,projectId:``}),await l(),t({type:Z.ConfigUpdated})}catch(e){console.error(`Failed to delete project:`,e)}finally{t({type:Z.RemoveDeletingProject,projectId:e});for(let e of i)t({type:Z.RemoveDeletingThread,threadId:e})}},[l,r,n,t]),v=(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 Le(r,n,!0);s&&await sy(s,{onOutput:e=>{t({type:Z.AppendTerminalLine,line:{type:`output`,content:e}})},onError:e=>{t({type:Z.AppendTerminalLine,line:{type:`error`,content:e}})}}),e<o.length-1&&(t({type:Z.AppendTerminalLine,line:{type:`system`,content:``}}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`---`}}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:``}}))}t({type:Z.AppendTerminalLine,line:{type:`system`,content:`All dependencies installed successfully!`}}),t({type:Z.SetCreatingProject,isCreating:!1}),await l()}catch(e){t({type:Z.SetCreatingProject,isCreating:!1}),console.error(`Failed to run setup script:`,e),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to run setup script: ${e instanceof Error?e.message:`Unknown error`}`}})}},[s,t,l]);return{projects:n,selectedProjectId:r,selectedThreadId:i,refreshProjects:l,handleSelectThread:u,handleCreateProject:f,handleCreateWebApp:p,handleCreateFolder:m,handleOpenFolder:(0,Y.useCallback)(async()=>{await d({apiCall:rn,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[d]),handleCreateThread:h,handleDeleteThread:g,confirmDeleteProject:_,pendingSetupScriptConfirmation:s,resolveSetupScriptConfirmation:v}}function py(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(my),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 my(){return document.hasFocus()}var hy=null;function gy(){hy??=new Audio(`/pop.wav`),hy.currentTime=0,hy.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function _y(){let e=za(),t=Ra(),n=Q(e=>e.processingThreadIds),r=Q(e=>e.completedThreadIds),i=py(),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=uh(await Wn()),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&&gy(),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 vy(){let e=(0,X.c)(15),t=za(),[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(!1),o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={queryKey:Zd.onboarding.status(),queryFn:pn,staleTime:1/0,retry:1},e[0]=o):o=e[0];let s=qr(o),c;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(c={queryKey:Zd.app.update(),queryFn:Kt,staleTime:1/0,retry:!1},e[1]=c):c=e[1];let l=qr(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 cn()}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 yy(e){return e.startsWith(`/settings`)||e===`/review`}function by(e){let t=(0,X.c)(45),{selectedThreadId:n,selectedProjectId:r,isMobile:i,mainTabBarRef:a}=e,o=rr(),s=hr(),{activeMainTab:c,setActiveMainTab:l,triggerReviewRefresh:u,triggerTasksRefresh:d}=hc(),{triggerExplorerRefresh:f}=yc(),{terminalState:p}=Ba(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&&!yy(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 z,B;t[35]!==c||t[36]!==g||t[37]!==h||t[38]!==r||t[39]!==d?(z=()=>{let e=w.current===`tasks`;w.current=c,c===`tasks`&&!e&&!T.current&&r&&!g&&!h&&d(),T.current=!1},B=[c,r,g,h,d],t[35]=c,t[36]=g,t[37]=h,t[38]=r,t[39]=d,t[40]=z,t[41]=B):(z=t[40],B=t[41]),(0,Y.useEffect)(z,B);let ee;return t[42]!==g||t[43]!==h?(ee={isSettingsRoute:h,isReviewRoute:g,explorerTabClickedRef:x,reviewTabClickedRef:C,tasksTabClickedRef:T},t[42]=g,t[43]=h,t[44]=ee):ee=t[44],ee}function xy(e,t){let n=(0,X.c)(8),r=za(),i=Q(Sy),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 Sy(e){return e.sidebarOpen}var Cy=gh(`App`,{web:()=>$r(()=>import(`./web-B4cuelyi.js`).then(e=>new e.AppWeb),[])}),wy=1e10,Ty=1e3;function Ey(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 Dy(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=Ty}=e;e.transport&&i(e.transport),e.requestHandler&&a(e.requestHandler),e._debugHooks&&(t=e._debugHooks);let s=0;function c(){return s<=wy?++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 Ey([`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 Ey([`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 Ey([`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 Ey([`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 Oy(e,t){let n=Dy({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 ky=window.__electrobunWebviewId,Ay=window.__electrobunRpcSocketPort,jy=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:${Ay}/socket?webviewId=${ky}`);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 Oy(`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 My(){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)(Iy,t);let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=[],e[1]=n):n=e[1],(0,Y.useEffect)(Ny,n)}function Ny(){if(!wn())return;let e=Cy.addListener(`backButton`,Fy);return()=>{e.then(Py)}}function Py(e){return e.remove()}function Fy(e){let{canGoBack:t}=e;t?window.history.back():Cy.exitApp()}function Iy(){window.__electrobunWebviewId&&new jy({})}function Ly(e){let t=(0,X.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(fc,{children:(0,$.jsx)(Sd,{children:(0,$.jsx)(_c,{children:(0,$.jsx)(Iv,{children:n})})})}),t[0]=n,t[1]=r),r}function Ry(){return Gv(),null}function zy(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={queryKey:[`health-status`,We()],queryFn:By,refetchInterval:3e4,retry:!1},e[0]=t):t=e[0],qr(t)}async function By(){let e=await fetch(`${We()}/health`,{method:`GET`});if(!e.ok)throw Error(`Failed to load health status`);return e.json()}function Vy(){let e=za(),t=rr(),n=hr(),r=Q(e=>e.selectedThreadId),i=Q(e=>e.selectedProjectId),a=Q(e=>e.sidebarOpen),o=Q(e=>e.deletingThreadIds),s=Q(e=>e.deletingProjectIds);My();let c=yf(),l=c||wn(),{data:u}=zy(),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(null),y=(0,Y.useRef)(()=>{}),{projects:b,handleSelectThread:x,handleCreateProject:S,handleCreateWebApp:C,handleCreateFolder:w,handleOpenFolder:T,handleCreateThread:E,handleDeleteThread:D,confirmDeleteProject:O,refreshProjects:k,pendingSetupScriptConfirmation:A,resolveSetupScriptConfirmation:j}=fy({onProjectCreated:f,onThreadCreateStart:f}),{processingThreadIds:M,completedThreadIds:N,clearCompleted:P}=_y(),{setActiveMainTab:F}=hc(),{triggerBrowserReset:I}=Rv(),{showOnboarding:R,setShowOnboarding:z,updateAvailable:B,updatingApp:ee,handleUpdateApp:te}=vy(),{isSettingsRoute:ne,isReviewRoute:re,explorerTabClickedRef:ie,reviewTabClickedRef:ae,tasksTabClickedRef:oe}=by({selectedThreadId:r,selectedProjectId:i,isMobile:c,mainTabBarRef:v});xy(ne,re);let se=(0,Y.useCallback)(e=>{let t=b.find(t=>t.projectId===e);t&&g({id:t.projectId,name:L(t)})},[b]),le=(0,Y.useCallback)(e=>{E(e,void 0)},[E]);y.current=le,(0,Y.useEffect)(()=>{function e(e){let t=e.key.toLowerCase();!((e.metaKey||e.ctrlKey)&&e.shiftKey&&!e.altKey)||t!==`t`||!i||(e.preventDefault(),y.current(i))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,Y.useEffect)(()=>{d&&i===d&&r&&f(null)},[d,i,r]);let V=(0,Y.useCallback)((i,a)=>{f(null),P(a),n.pathname!==`/`&&t(`/`),F(`chat`),r!==a&&I(),x(i,a),l&&e({type:Z.CloseSidebar})},[x,l,r,e,P,n.pathname,t,F,I]);return(0,Y.useEffect)(()=>{a?_.current?.expand():_.current?.collapse()},[a]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ry,{}),(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(cy,{})}),(0,$.jsxs)(ce,{delayDuration:200,children:[(0,$.jsxs)(yg,{direction:`horizontal`,className:`h-screen bg-background`,children:[(0,$.jsx)(bg,{ref:_,defaultSize:l?100:25,minSize:l?50:12,maxSize:l?100:32,collapsible:!0,collapsedSize:0,className:U(`border-r border-transparent`,l&&!a&&`hidden`),children:(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(uo,{projects:b,selectedThreadId:r,selectedProjectId:i,processingThreadIds:M,completedThreadIds:N,deletingThreadIds:o,deletingProjectIds:s,onSelectThread:V,onCreateProject:()=>m(!0),onCreateThread:le,onDeleteThread:D,onDeleteProject:se,collapsed:!a,updateAvailable:B,updatingApp:ee,onUpdateApp:te,isDevMode:u?.isDevMode===!0,expandProjectId:d})})}),!l&&(0,$.jsx)(xg,{withHandle:!0,className:a?`ml-[-40px]`:``}),(0,$.jsx)(bg,{minSize:40,className:U(`overflow-hidden`,l&&a&&`hidden`),children:(0,$.jsx)(qm,{threadId:r??void 0,children:(0,$.jsx)(Qp,{children:(0,$.jsx)(Yg,{selectedThreadId:r,selectedProjectId:i,isReviewRoute:re,isSettingsRoute:ne,onCreateThread:le,mainTabBarRef:v,explorerTabClickedRef:ie,reviewTabClickedRef:ae,tasksTabClickedRef:oe})})})}),(0,$.jsx)(Pv,{showCreateProject:p,onCreateProjectOpenChange:m,onSubmitClone:S,onSubmitWebApp:C,onSubmitFolder:w,onOpenFolder:T,deleteProject:h,onDeleteProjectOpenChange:e=>!e&&g(null),onConfirmDeleteProject:()=>{h&&(O(h.id),g(null))},pendingSetupScriptConfirmation:A,onResolveSetupScriptConfirmation:j,showOnboarding:R,onOnboardingOpenChange:z,onOnboardingComplete:()=>{k()}})]}),(0,$.jsx)(ey,{})]})]})}function Hy(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ly,{children:(0,$.jsx)(Vy,{})}),e[0]=t):t=e[0],t}function Uy(){let e=(0,X.c)(3),[t]=(0,Y.useState)(Ia),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)(ay,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,$.jsx)(ry,{children:(0,$.jsx)(La.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=i(e,qy());document.documentElement.style.fontSize=`${t}%`}var Yy=!1;function Xy(){Yy||(Yy=!0,window.matchMedia(`(max-width: 767px)`).addEventListener(`change`,()=>{Jy(Dt(Ky))}))}function Zy(){let[e,t]=(0,Y.useState)(()=>Dt(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(Dt(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=gh(`StatusBar`),nb=`--app-viewport-height`;function rb(){let e=window.visualViewport,t=Math.round(st()===`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=st()===`ios`?dg.None:dg.Body;await fg.setResizeMode({mode:e})}catch{}}function cb(){wn()&&(ab(),ob(),sb(),document.addEventListener(`visibilitychange`,()=>{if(document.visibilityState===`visible`){ib(),ob();return}Ph()}))}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=wn()?Zn:Ir;(0,Ni.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Y.StrictMode,{children:(0,$.jsx)(pb,{children:(0,$.jsx)(Uy,{})})}));export{yc as A,Ba as B,hu as C,gl as D,uu as E,to as F,Wa as I,Va as L,ac as M,ps as N,vl as O,oo as P,za as R,mu as S,bu as T,Z as V,bm as _,K_ as a,Cd as b,Dg as c,yg as d,Yh as f,Cm as g,Sm as h,Sv as i,hc as j,_l as k,xg as l,nh as m,Rv as n,kg as o,_h as p,bv as r,Ag as s,Zy as t,bg as u,yp as v,yu as w,lu as x,yf as y,Q as z};