tarsk 0.5.40 → 0.5.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1898 -485
- package/dist/public/assets/{account-view-BT90zNSx.js → account-view-BAm4Az95.js} +1 -1
- package/dist/public/assets/api-C44iPrsZ.js +1 -0
- package/dist/public/assets/browser-tab-DV6mFCbu.js +1 -0
- package/dist/public/assets/commit-dialog-DYdmiA4p.js +1 -0
- package/dist/public/assets/context-menu-BVP2PUoS.js +1 -0
- package/dist/public/assets/create-repo-dialog-DrGJUrGO.js +1 -0
- package/dist/public/assets/{dialogs-config-DZKtVbNK.js → dialogs-config-BPzX42HH.js} +14 -14
- package/dist/public/assets/diff-view-BnNtDcmG.js +3 -0
- package/dist/public/assets/explorer-tab-view-OGWG1dH9.js +2 -0
- package/dist/public/assets/explorer-tree--Ho2K8-i.js +1 -0
- package/dist/public/assets/explorer-view-Dw0Kyxb8.js +1 -0
- package/dist/public/assets/git-history-dialog-BpOpNbze.js +1 -0
- package/dist/public/assets/git-ops-button-DKOfNm4s.js +2 -0
- package/dist/public/assets/history-view-DwSqsTGI.js +9 -0
- package/dist/public/assets/index-BdLH7zyV.css +1 -0
- package/dist/public/assets/index-BqaiWs7x.js +88 -0
- package/dist/public/assets/mcp-server-card-BbAUiI-X.js +1 -0
- package/dist/public/assets/merged-pr-dialog-Cvo93bRH.js +1 -0
- package/dist/public/assets/onboarding-BmBbv0At.js +1 -0
- package/dist/public/assets/project-settings-view-D-8Ua1Tu.js +1 -0
- package/dist/public/assets/providers-list-view-Gm13Fagd.js +1 -0
- package/dist/public/assets/pull-request-dialog-BkzdP5F2.js +1 -0
- package/dist/public/assets/pull-with-changes-dialog-DQU7jHYL.js +1 -0
- package/dist/public/assets/push-before-pr-dialog-DII3gUVw.js +1 -0
- package/dist/public/assets/radio-group-DkDRaQdF.js +1 -0
- package/dist/public/assets/react-vendor-BmFalJ0W.js +16 -0
- package/dist/public/assets/settings-general-view-Br89Vrbv.js +1 -0
- package/dist/public/assets/{settings-instructions-view-CV7lRPuw.js → settings-instructions-view-ByxlAb9U.js} +1 -1
- package/dist/public/assets/settings-list-DSrSoTv7.js +1 -0
- package/dist/public/assets/settings-mcp-servers-view-U_la7C8z.js +5 -0
- package/dist/public/assets/{settings-models-skeleton-l966LEN8.js → settings-models-skeleton-C5XrzM39.js} +1 -1
- package/dist/public/assets/settings-models-view-obQa4doG.js +1 -0
- package/dist/public/assets/settings-rules-view-Cd9WHEAE.js +8 -0
- package/dist/public/assets/settings-skills-view-B81njz98.js +2 -0
- package/dist/public/assets/settings-slash-commands-view-Ct8WC1Z0.js +1 -0
- package/dist/public/assets/settings-subagents-view-BwNTnGkz.js +2 -0
- package/dist/public/assets/{settings-system-prompt-view-DQmSdSnp.js → settings-system-prompt-view-C4uLn68y.js} +1 -1
- package/dist/public/assets/settings-view-DQW_9pnm.js +2 -0
- package/dist/public/assets/skeleton-HsHVnOKO.js +1 -0
- package/dist/public/assets/{terminal-panel-BzCO142Q.js → terminal-panel-wOltBu70.js} +2 -2
- package/dist/public/assets/{ui-components-f8jJJzEo.js → ui-components-CaeQlGTd.js} +1 -1
- package/dist/public/assets/{utils-BlXPFbY9.js → utils-5mrXWXCs.js} +1 -1
- package/dist/public/assets/web-Gjw6klhQ.js +1 -0
- package/dist/public/assets/web-NsuCXAqU.js +1 -0
- package/dist/public/browser-preview-rpc.js +484 -0
- package/dist/public/index.html +7 -7
- package/dist/recommended-models.txt +1 -1
- package/package.json +1 -1
- package/dist/public/assets/api-DWU0D34A.js +0 -1
- package/dist/public/assets/browser-tab-Bp486a9f.js +0 -1
- package/dist/public/assets/commit-dialog-90PGbqs8.js +0 -1
- package/dist/public/assets/context-menu-C7FTMa2c.js +0 -1
- package/dist/public/assets/create-repo-dialog-BkUdww3q.js +0 -1
- package/dist/public/assets/diff-view-B4G8vqZa.js +0 -3
- package/dist/public/assets/explorer-tab-view-DEQFid8r.js +0 -2
- package/dist/public/assets/explorer-tree-CPHGgahA.js +0 -1
- package/dist/public/assets/explorer-view-BTvhSMDQ.js +0 -1
- package/dist/public/assets/git-history-dialog-Bqv0bD41.js +0 -1
- package/dist/public/assets/git-ops-button-BnVMlOO3.js +0 -2
- package/dist/public/assets/history-view-jX3PPID6.js +0 -9
- package/dist/public/assets/index-DjD2SPNZ.js +0 -65
- package/dist/public/assets/index-jIBJk8xl.css +0 -1
- package/dist/public/assets/mcp-server-card-CTCrhFIS.js +0 -1
- package/dist/public/assets/merged-pr-dialog-B2qqrQ1g.js +0 -1
- package/dist/public/assets/onboarding-CxtzQldG.js +0 -1
- package/dist/public/assets/project-settings-view-ZJjQbFbQ.js +0 -1
- package/dist/public/assets/providers-list-view-BH13AB_H.js +0 -1
- package/dist/public/assets/pull-request-dialog-ZzVXh6M9.js +0 -1
- package/dist/public/assets/pull-with-changes-dialog-LUgd2a4S.js +0 -1
- package/dist/public/assets/push-before-pr-dialog-CFmgu9H_.js +0 -1
- package/dist/public/assets/radio-group-Bd8YbtFD.js +0 -1
- package/dist/public/assets/react-vendor-Ba8DSNiO.js +0 -16
- package/dist/public/assets/settings-general-view-C8muiP_K.js +0 -1
- package/dist/public/assets/settings-list-CKPEGohm.js +0 -1
- package/dist/public/assets/settings-mcp-servers-view-3gN9ly3z.js +0 -5
- package/dist/public/assets/settings-models-view-CAMouMhE.js +0 -1
- package/dist/public/assets/settings-rules-view-BnazfbJb.js +0 -8
- package/dist/public/assets/settings-skills-view-DpzKFcpf.js +0 -2
- package/dist/public/assets/settings-slash-commands-view-Drje2Dl4.js +0 -1
- package/dist/public/assets/settings-subagents-view-D05kHO1W.js +0 -2
- package/dist/public/assets/settings-view-B6e0GfSv.js +0 -2
- package/dist/public/assets/skeleton-qzmFgKhS.js +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-oojFghRi.js","assets/rolldown-runtime-aKtaBQYM.js","assets/git-ops-button-DKOfNm4s.js","assets/monaco-CZnIWXyV.js","assets/monaco-Br_kD0ds.css","assets/dialogs-config-BPzX42HH.js","assets/diff-view-BnNtDcmG.js","assets/history-view-DwSqsTGI.js","assets/onboarding-BmBbv0At.js","assets/context-menu-BVP2PUoS.js","assets/react-vendor-BmFalJ0W.js","assets/utils-5mrXWXCs.js","assets/terminal-panel-wOltBu70.js","assets/explorer-tab-view-OGWG1dH9.js","assets/browser-tab-DV6mFCbu.js","assets/settings-view-DQW_9pnm.js","assets/settings-models-skeleton-C5XrzM39.js","assets/skeleton-HsHVnOKO.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{i as e,t}from"./rolldown-runtime-aKtaBQYM.js";import{$ as n,$i as r,$t as i,A as a,Aa as o,Ai as s,An as c,Ao as l,Ar as u,At as d,Ba as f,Ca as p,Cn as m,Ct as h,D as g,Da as _,Di as v,Ea as y,Ei as b,Eo as x,Et as S,Fa as C,Fi as w,Fn as T,Fr as E,Ft as D,Gi as O,Gn as k,Ha as A,Hn as j,I as M,Ia as N,Ii as P,In as F,Ir as I,It as L,Jn as R,Jt as ee,Ki as z,Kn as te,La as ne,Li as re,Ln as ie,Ma as ae,Mi as oe,Mo as se,Mr as ce,N as le,Na as ue,Ni as de,Nn as fe,Nr as pe,Nt as me,Oi as B,On as he,Or as ge,Pa as _e,Pi as ve,Pn as ye,Pr as be,Pt as xe,Q as Se,Qa as Ce,Qi as we,Qn as Te,Qt as Ee,R as V,Ra as De,Ri as Oe,Rn as ke,Rt as Ae,S as je,Sn as Me,So as Ne,T as Pe,Ta as Fe,To as Ie,Tt as Le,Ua as Re,Vi as ze,Vn as Be,Vt as Ve,Wa as He,Wi as Ue,Wn as We,Wt as Ge,Xa as Ke,Xn as qe,Xt as Je,Ya as Ye,Yn as Xe,Yt as Ze,Z as Qe,Za as $e,Zi as et,Zn as tt,Zt as nt,_a as rt,_i as it,_n as at,_o as ot,_r as H,_t as st,an as ct,ao as lt,ar as U,b as ut,ba as dt,bn as ft,bo as pt,c as mt,ca as ht,cn as gt,d as _t,da as vt,do as yt,dr as bt,dt as xt,ea as St,en as Ct,et as wt,fa as Tt,fi as W,fo as Et,g as Dt,ga as G,gi as K,gn as Ot,gr as kt,hi as At,hn as jt,ho as Mt,ia as Nt,j as Pt,ji as Ft,jn as It,jo as Lt,jr as Rt,ko as zt,kt as Bt,la as Vt,ln as Ht,lo as Ut,m as Wt,mi as q,mn as Gt,mo as Kt,mr as qt,nn as Jt,no as Yt,nr as Xt,oo as Zt,or as Qt,p as $t,pa as en,po as tn,pr as nn,q as rn,qa as an,qn as on,rn as sn,rr as cn,sa as ln,sn as un,sr as dn,st as fn,ta as pn,to as mn,tr as hn,tt as gn,ur as _n,ut as J,v as vn,vi as yn,vn as bn,vo as xn,vr as Sn,w as Cn,wa as wn,wn as Tn,x as En,xa as Dn,xi as On,xn as kn,xo as An,xt as jn,ya as Mn,yi as Nn,yn as Pn,yr as Fn,zn as In}from"./dialogs-config-BPzX42HH.js";import{$ as Ln,A as Rn,B as zn,D as Bn,E as Vn,F as Hn,G as Un,H as Wn,I as Gn,J as Kn,K as qn,L as Jn,M as Yn,N as Xn,O as Zn,P as Qn,Q as $n,R as er,T as tr,U as nr,V as rr,W as ir,X as ar,Y as or,Z as sr,at as cr,ct as lr,et as ur,ft as dr,it as fr,j as pr,k as mr,lt as hr,nt as gr,ot as _r,q as vr,rt as yr,st as br,tt as xr,ut as Sr,z as Cr}from"./react-vendor-BmFalJ0W.js";import{r as wr}from"./monaco-CZnIWXyV.js";import{c as Tr,o as Er,r as Dr,s as Or}from"./onboarding-BmBbv0At.js";import{A as kr,F as Ar,I as jr,M as Mr,N as Nr,O as Pr,P as Fr,a as Ir,j as Lr,k as Rr,l as zr,n as Br,o as Vr,s as Hr,x as Ur}from"./history-view-DwSqsTGI.js";import{a as Wr,i as Gr,n as Kr,o as qr,r as Jr,t as Yr}from"./whisper-wasm-EGutPGND.js";import{n as Xr,t as Zr}from"./utils-5mrXWXCs.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 Y=e(se(),1),Qr=dr(),X=l(),$r;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})($r||={});var ei=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},ti=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,ni=e=>{let t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},i=()=>t===null?ti(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 ei(`"${e}" plugin is not implemented on ${c}`,$r.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 ei(`"${e}.${t}()" is not implemented on ${c}`,$r.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=ei,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},ri=(e=>e.Capacitor=ni(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),ii=ri.registerPlugin,ai=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 ri.Exception(e,$r.Unimplemented)}unavailable(e=`not available`){return new ri.Exception(e,$r.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)}))}},oi=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),si=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),ci=class extends ai{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=si(n).trim(),r=si(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=oi(e.key),n=oi(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)}}};ii(`CapacitorCookies`,{web:()=>new ci});var li=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)}),ui=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},di=(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,fi=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=ui(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},pi=class extends ai{async request(e){let t=fi(e,e.webFetchExtra),n=di(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 li(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`}))}};ii(`CapacitorHttp`,{web:()=>new pi});var mi;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(mi||={});var hi;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(hi||={});var gi=class extends ai{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`)}};ii(`SystemBars`,{web:()=>new gi});var _i=ii(`App`,{web:()=>wr(()=>import(`./web-Gjw6klhQ.js`).then(e=>new e.AppWeb),[])}),vi=1e10,yi=1e3;function bi(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 xi(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=yi}=e;e.transport&&i(e.transport),e.requestHandler&&a(e.requestHandler),e._debugHooks&&(t=e._debugHooks);let s=0;function c(){return s<=vi?++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 bi([`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 bi([`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 bi([`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 bi([`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 Si(e,t){let n=xi({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 Ci=window.__electrobunWebviewId,wi=window.__electrobunRpcSocketPort,Ti=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:${wi}/socket?webviewId=${Ci}`);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 Si(`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 Ei(e){return typeof e==`string`?e.replace(/\\n/g,`
|
|
3
|
+
`).replace(/✅/g,`✓`):``}function Di(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 Oi(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 ki(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 Ai(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 Oi(e);if(typeof e==`object`&&e)return ki(e)}catch{}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(a),r=Math.max(t.lastIndexOf(`]`),t.lastIndexOf(`}`));if(r!==-1){let e=t.substring(0,r+1);try{let i=JSON.parse(e);Array.isArray(i)?n.push(...Oi(i)):n.push(...ki(i));let a=t.substring(r+1).trim();return a&&n.push({type:`text`,text:a}),n}catch{}}}return null}function ji(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 Mi(e,t){return e[e.length-1]?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[t]}]:[...e,{type:`content`,chunks:[t]}]}function Ni(e,t){return[...e,{type:`long_running_confirmation`,prompt:t}]}function Pi(e,t){return[...e,{type:`shell_permission`,prompt:t}]}function Fi(e,t){return[...e,{type:`web_fetch_permission`,prompt:t}]}function Ii(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=Di(e)??[];t.push(...n)}else{let n=Ai(e)??(e.trim()?[{type:`text`,text:e}]:[]);t.push(...n)}}return t}function Li(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 Ri(e){let t=Ii(e);return t.length===0?`...`:t.length===1&&t[0]?.type===`text`&&`text`in t[0]?t[0].text:JSON.stringify(t)}var 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}({}),zi={isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0};function Bi(){return{...zi,streamingSegments:[]}}function Vi(e,t){return t?e[t]??Bi():Bi()}function Hi(e,t){return t.threadId??e.selectedThreadId}function Ui(e,t,n,r=!1){if(!t)return{...e,...n,toolCallProgress:r?{}:e.toolCallProgress};let i={...e.threadStreamingStates,[t]:n};return t===e.selectedThreadId?{...e,...n,threadStreamingStates:i,toolCallProgress:r?{}:e.toolCallProgress}:{...e,threadStreamingStates:i}}var Wi={projects:[],projectsLoading:!0,selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,queuedChatMessages:[],isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0,threadStreamingStates:{},projectModelSelections:{},sidebarOpen:!0,isCreatingProject:!1,configUpdatedAt:0,processingThreadIds:[],completedThreadIds:[],deletingThreadIds:[],deletingProjectIds:[],commandOutput:``,isRunningCommand:!1,terminalStates:{},focusChatInput:!1,toolCallProgress:{},pendingChatMessage:null,diffComments:{},chatInputDrafts:{}};function Gi(e,t){switch(t.type){case`SET_PROJECTS`:{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`SET_PROJECTS_LOADING`:return{...e,projectsLoading:t.projectsLoading};case`SELECT_THREAD`:{let n=Vi(e.threadStreamingStates,t.threadId);return{...e,...n,selectedThreadId:t.threadId,selectedProjectId:t.projectId,messages:t.initialMessages??[],messagesLoaded:!1,focusChatInput:t.focusInput??!1}}case`CLEAR_SELECTION`:return{...e,...Bi(),selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1};case`SET_MESSAGES`:return{...e,messages:t.messages,messagesLoaded:!0};case`ADD_MESSAGE`:return t.threadId&&t.threadId!==e.selectedThreadId?e:{...e,messages:[...e.messages,t.message]};case`ENQUEUE_CHAT_MESSAGE`:return{...e,queuedChatMessages:[...e.queuedChatMessages,t.message]};case`REMOVE_QUEUED_CHAT_MESSAGE`:return{...e,queuedChatMessages:e.queuedChatMessages.filter(e=>e.id!==t.queuedMessageId)};case`SET_STREAMING`:{let n=Hi(e,t);return Ui(e,n,{...Vi(e.threadStreamingStates,n),isStreaming:t.isStreaming})}case`APPEND_STREAM_CONTENT`:{let n=Hi(e,t),r=Vi(e.threadStreamingStates,n);return Ui(e,n,{...r,streamingContent:r.streamingContent+t.content})}case`SET_STREAM_CONTENT`:{let n=Hi(e,t),r=Vi(e.threadStreamingStates,n),i=Mi(r.streamingSegments,t.content);return Ui(e,n,{...r,streamingContent:t.content,streamingSegments:i})}case`APPEND_STREAM_THINKING`:{let n=Hi(e,t),r=Vi(e.threadStreamingStates,n);return Ui(e,n,{...r,streamingThinking:r.streamingThinking+t.content})}case`INCREMENT_STREAM_EVENT_COUNT`:{let n=Hi(e,t),r=Vi(e.threadStreamingStates,n);return Ui(e,n,{...r,streamingEventCount:r.streamingEventCount+1})}case`APPEND_STREAM_CHUNK`:{let n=Hi(e,t),r=Vi(e.threadStreamingStates,n);return Ui(e,n,{...r,streamingSegments:t.segments,streamingContent:t.chunkType===`content`?r.streamingContent+t.content:r.streamingContent,streamingThinking:t.chunkType===`thinking`?r.streamingThinking+t.content:r.streamingThinking})}case`SET_STREAM_MODEL`:{let n=Hi(e,t);return Ui(e,n,{...Vi(e.threadStreamingStates,n),streamingModel:t.model})}case`SET_PROJECT_MODEL`: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`RESET_STREAM`:return Ui(e,Hi(e,t),Bi(),!0);case`STOP_STREAM`:{let n=Hi(e,t);return Ui(e,n,{...Vi(e.threadStreamingStates,n),isStreaming:!1})}case`TOGGLE_SIDEBAR`:return{...e,sidebarOpen:!e.sidebarOpen};case`CLOSE_SIDEBAR`:return e.sidebarOpen?{...e,sidebarOpen:!1}:e;case`SET_CREATING_PROJECT`:return{...e,isCreatingProject:t.isCreating};case`CONFIG_UPDATED`:return{...e,configUpdatedAt:Date.now()};case`SET_PROCESSING_THREADS`:return{...e,processingThreadIds:t.threadIds};case`ADD_PROCESSING_THREAD`:return{...e,processingThreadIds:e.processingThreadIds.includes(t.threadId)?e.processingThreadIds:[...e.processingThreadIds,t.threadId]};case`REMOVE_PROCESSING_THREAD`:return{...e,processingThreadIds:e.processingThreadIds.filter(e=>e!==t.threadId)};case`ADD_CREATING_PROJECT`:return{...e,projects:[...e.projects,{projectId:t.projectId,name:t.projectName,gitUrl:t.gitUrl,threads:[{threadId:t.threadId,title:`thread-1`,path:``,currentBranch:``}]}]};case`ADD_CREATING_THREAD`: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`REMOVE_CREATING_PROJECT`:return{...e,projects:e.projects.filter(e=>e.projectId!==t.projectId)};case`REMOVE_CREATING_THREAD`:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.filter(e=>e.threadId!==t.threadId)}:e)};case`MARK_THREAD_COMPLETED`:return{...e,completedThreadIds:e.completedThreadIds.includes(t.threadId)?e.completedThreadIds:[...e.completedThreadIds,t.threadId]};case`CLEAR_THREAD_COMPLETED`:return{...e,completedThreadIds:e.completedThreadIds.filter(e=>e!==t.threadId)};case`ADD_DELETING_THREAD`:return{...e,deletingThreadIds:e.deletingThreadIds.includes(t.threadId)?e.deletingThreadIds:[...e.deletingThreadIds,t.threadId]};case`REMOVE_DELETING_THREAD`:return{...e,deletingThreadIds:e.deletingThreadIds.filter(e=>e!==t.threadId)};case`ADD_DELETING_PROJECT`:return{...e,deletingProjectIds:e.deletingProjectIds.includes(t.projectId)?e.deletingProjectIds:[...e.deletingProjectIds,t.projectId]};case`REMOVE_DELETING_PROJECT`:return{...e,deletingProjectIds:e.deletingProjectIds.filter(e=>e!==t.projectId)};case`APPEND_COMMAND_OUTPUT`:return{...e,commandOutput:e.commandOutput+t.content};case`SET_RUNNING_COMMAND`:return{...e,isRunningCommand:t.isRunning};case`CLEAR_COMMAND_OUTPUT`:return{...e,commandOutput:``};case`TOGGLE_TERMINAL`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:!r.open}}}}case`SET_TERMINAL_OPEN`:{let n=t.threadId??`default`,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:t.open}}}}case`QUEUE_TERMINAL_COMMAND`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,queuedCommand:t.command,queuedRelativeFolder:t.relativeFolder??null,open:!0}}}}case`CLEAR_QUEUED_TERMINAL_COMMAND`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,queuedCommand:null}}}}case`APPEND_TERMINAL_LINE`:{let n=t.threadId??`default`,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[...r.outputLines,t.line]}}}}case`CLEAR_TERMINAL_OUTPUT`:{let n=t.threadId??`default`,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[]}}}}case`SET_TERMINAL_HEIGHT`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,height:t.height}}}}case`SET_TERMINAL_CWD`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,cwd:t.cwd}}}}case`SET_TERMINAL_RUNNING`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,isRunning:t.isRunning}}}}case`SET_TERMINAL_HISTORY`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,history:t.history}}}}case`SET_TERMINAL_HISTORY_INDEX`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,historyIndex:t.index}}}}case`UPDATE_THREAD_TITLE`: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)};case`CLEAR_FOCUS_CHAT_INPUT`:return{...e,focusChatInput:!1};case`CLEAR_MESSAGES`:return{...e,messages:[]};case`UPDATE_TOOL_CALL_PROGRESS`:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{...n,...t.progress}}}}case`UPDATE_TOOL_EXECUTION_OUTPUT`:{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`APPEND_TOOL_EXECUTION_OUTPUT`:{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`CLEAR_TOOL_CALL_PROGRESS`:{if(!t.toolCallId)return{...e,toolCallProgress:{}};let{[t.toolCallId]:n,...r}=e.toolCallProgress;return{...e,toolCallProgress:r}}case`SET_PENDING_CHAT_MESSAGE`:return{...e,pendingChatMessage:t.message};case`CLEAR_PENDING_CHAT_MESSAGE`:return{...e,pendingChatMessage:null};case`SET_DIFF_COMMENTS`:return{...e,diffComments:{...e.diffComments,[t.threadId]:t.comments}};case`SET_CHAT_INPUT_DRAFT`:return{...e,chatInputDrafts:{...e.chatInputDrafts,[t.threadId]:t.draft}};case`CLEAR_CHAT_INPUT_DRAFT`:{let{[t.threadId]:n,...r}=e.chatInputDrafts;return{...e,chatInputDrafts:r}}default:return e}}var Ki=new Set([`APPEND_STREAM_CHUNK`,`INCREMENT_STREAM_EVENT_COUNT`,`SET_STREAM_MODEL`,`APPEND_STREAM_CONTENT`,`APPEND_STREAM_THINKING`,`SET_STREAM_CONTENT`]);function qi(e=Wi){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=Gi(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(Ki.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 Ji=(0,Y.createContext)(null);function Yi(){let e=(0,Y.useContext)(Ji);if(!e)throw Error(`useAppStore must be used within an AppStoreContext.Provider`);return e}function Q(e){let t=(0,X.c)(3),n=Yi(),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 Xi(){return Yi().dispatch}var Zi={open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};function Qi(e){let t=(0,X.c)(8),n=Xi(),r;t[0]===e?r=t[1]:(r=t=>(e?t.terminalStates[e]:void 0)??Zi,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 $=ze(),$i=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=q(`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});$i.displayName=`Textarea`;function ea(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:a,feedbackEmail:o,onFeedbackEmailChange:s,feedbackText:c,onFeedbackTextChange:l,loadingFeedbackUser:d,submittingFeedback:f,onSubmit:p}=e,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsxs)(E,{children:[(0,$.jsx)(I,{children:`Send Feedback`}),(0,$.jsx)(pe,{children:`Share feedback about Tarsk.`})]}),t[0]=m):m=t[0];let h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(ge,{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)(u,{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)(ge,{htmlFor:`feedback-email`,children:`Email`}),t[8]=y):y=t[8];let b;t[9]===s?b=t[10]:(b=e=>s(e.target.value),t[9]=s,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)(u,{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)(ge,{htmlFor:`feedback-text`,children:`Feedback`}),t[15]=C):C=t[15];let w;t[16]===l?w=t[17]:(w=e=>l(e.target.value),t[16]=l,t[17]=w);let T;t[18]!==c||t[19]!==f||t[20]!==w?(T=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[C,(0,$.jsx)($i,{id:`feedback-text`,value:c,onChange:w,placeholder:`Tell us what you think...`,className:`min-h-32`,disabled:f})]}),t[18]=c,t[19]=f,t[20]=w,t[21]=T):T=t[21];let D;t[22]!==T||t[23]!==v||t[24]!==S?(D=(0,$.jsxs)(`div`,{className:`grid gap-4 py-2`,children:[v,S,T]}),t[22]=T,t[23]=v,t[24]=S,t[25]=D):D=t[25];let O;t[26]===r?O=t[27]:(O=()=>r(!1),t[26]=r,t[27]=O);let k;t[28]!==f||t[29]!==O?(k=(0,$.jsx)(W,{variant:`outline`,onClick:O,disabled:f,children:`Cancel`}),t[28]=f,t[29]=O,t[30]=k):k=t[30];let A;t[31]===f?A=t[32]:(A=f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`mr-2 h-4 w-4 animate-spin`}),`Sending...`]}):`Send`,t[31]=f,t[32]=A);let j;t[33]!==p||t[34]!==f||t[35]!==A?(j=(0,$.jsx)(W,{onClick:p,disabled:f,children:A}),t[33]=p,t[34]=f,t[35]=A,t[36]=j):j=t[36];let M;t[37]!==k||t[38]!==j?(M=(0,$.jsxs)(be,{children:[k,j]}),t[37]=k,t[38]=j,t[39]=M):M=t[39];let P;t[40]!==D||t[41]!==M?(P=(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,D,M]}),t[40]=D,t[41]=M,t[42]=P):P=t[42];let F;return t[43]!==r||t[44]!==n||t[45]!==P?(F=(0,$.jsx)(Rt,{open:n,onOpenChange:r,children:P}),t[43]=r,t[44]=n,t[45]=P,t[46]=F):F=t[46],F}function ta(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)(ta,{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 na(e){let t=(0,X.c)(28),{nodes:n,renderNode:r,resetKey:i,defaultOpen:a,forceOpenIds:o,initialOpenIds:s,indent:c,childContainerClassName:l,className:u}=e,d=a===void 0?!1:a,f=c===void 0?16:c,p;t[0]===s?p=t[1]:(p=()=>{let e={};if(s)for(let t of s)e[t]=!0;return e},t[0]=s,t[1]=p);let[m,h]=(0,Y.useState)(p),[g,_]=(0,Y.useState)(i);if(i!==g){_(i);let e={};if(s)for(let t of s)e[t]=!0;h(e)}let v;t[2]===o?v=t[3]:(v=o?new Set(o):void 0,t[2]=o,t[3]=v);let y=v,b;t[4]===d?b=t[5]:(b=e=>{h(t=>({...t,[e]:!(t[e]??d)}))},t[4]=d,t[5]=b);let x=b,S;t[6]===u?S=t[7]:(S=q(`min-w-0`,u),t[6]=u,t[7]=S);let C;if(t[8]!==l||t[9]!==d||t[10]!==y||t[11]!==x||t[12]!==f||t[13]!==n||t[14]!==m||t[15]!==r){let e;t[17]!==l||t[18]!==d||t[19]!==y||t[20]!==x||t[21]!==f||t[22]!==m||t[23]!==r?(e=e=>(0,$.jsx)(ta,{node:e,level:0,renderNode:r,defaultOpen:d,indent:f,childContainerClassName:l,openState:m,onToggle:x,forceOpenIds:y},e.id),t[17]=l,t[18]=d,t[19]=y,t[20]=x,t[21]=f,t[22]=m,t[23]=r,t[24]=e):e=t[24],C=n.map(e),t[8]=l,t[9]=d,t[10]=y,t[11]=x,t[12]=f,t[13]=n,t[14]=m,t[15]=r,t[16]=C}else C=t[16];let w;return t[25]!==S||t[26]!==C?(w=(0,$.jsx)(`div`,{className:S,children:C}),t[25]=S,t[26]=C,t[27]=w):w=t[27],w}var ra=1,ia=1e6,aa=0;function oa(){return aa=(aa+1)%(2**53-1),aa.toString()}var sa=new Map,ca=e=>{if(sa.has(e))return;let t=setTimeout(()=>{sa.delete(e),fa({type:`REMOVE_TOAST`,toastId:e})},ia);sa.set(e,t)},la=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,ra)};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?ca(n):e.toasts.forEach(e=>{ca(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)}}},ua=[],da={toasts:[]};function fa(e){da=la(da,e),ua.forEach(e=>{e(da)})}function pa({...e}){let t=oa(),n=e=>fa({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>fa({type:`DISMISS_TOAST`,toastId:t});return fa({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function ma(){let e=(0,X.c)(4),[t,n]=Y.useState(da),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(ua.push(n),()=>{let e=ua.indexOf(n);e>-1&&ua.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:pa,dismiss:ha},e[2]=t,e[3]=a),a}function ha(e){return fa({type:`DISMISS_TOAST`,toastId:e})}function ga(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!0;return l(!0),fn().then(e=>{t&&(r(t=>t||e.name),a(t=>t||e.email))}).catch(()=>{t&&pa({title:`Could not load git details`,description:`You can still submit feedback by entering your name and email manually.`,variant:`destructive`})}).finally(()=>{t&&l(!1)}),()=>{t=!1}},[e]),{showFeedback:e,feedbackName:n,setFeedbackName:r,feedbackEmail:i,setFeedbackEmail:a,feedbackText:o,setFeedbackText:s,loadingFeedbackUser:c,submittingFeedback:u,handleFeedbackDialogChange:e=>{t(e),e||s(``)},handleSubmitFeedback:async()=>{let e=o.trim();if(!e){pa({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}d(!0);try{await j(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),pa({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),s(``),t(!1)}catch(e){pa({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{d(!1)}}}}var _a=Pr(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)(`div`,{className:`flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm`,children:(0,$.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:e.v2,onClick:e.v3})}),e.v4]}),e.v5]}),e.v6,e.v7]}),{name:`SidePanelContainer_1`,portals:[`v4`,`v5`,`v6`,`v7`]}),va=function(e){let t=(0,X.c)(25),{children:n,collapsed:r,title:i,onTitleClose:a,subtitle:o,headerAction:c,footer:l,onLogoClick:u}=e,d,f,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=ye(),d=_a,p=q(`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):(d=t[0],f=t[1],p=t[2]);let m;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(m={containerType:`inline-size`,height:f?`calc(100% - 42px)`:`calc(100% - 12px)`},t[3]=m):m=t[3];let h=u&&`cursor-pointer`,g;t[4]===h?g=t[5]:(g=q(`h-full w-full`,h),t[4]=h,t[5]=g);let _;t[6]!==r||t[7]!==o?(_=!r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`span`,{className:s.sectionTitle,children:`Tarsk`}),o&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xn,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,$.jsx)(`span`,{className:q(s.label,`text-sidebar-foreground/80`),children:o})]})]}),t[6]=r,t[7]=o,t[8]=_):_=t[8];let v;t[9]!==r||t[10]!==c||t[11]!==a||t[12]!==i?(v=(i??a??c)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[c&&!r&&c,i&&(0,$.jsx)(`span`,{className:q(s.compact,`font-medium text-sidebar-foreground/80`),children:i}),a&&(0,$.jsxs)(W,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:a,children:[(0,$.jsx)(z,{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]=v):v=t[13];let y;t[14]===n?y=t[15]:(y=(0,$.jsx)(mt,{className:`flex-1`,children:n}),t[14]=n,t[15]=y);let b;t[16]===l?b=t[17]:(b=l&&(0,$.jsx)(`div`,{className:`border-t border-sidebar-border`,children:l}),t[16]=l,t[17]=b);let x;return t[18]!==u||t[19]!==g||t[20]!==_||t[21]!==v||t[22]!==y||t[23]!==b?(x=(0,$.jsx)(d,{v0:p,v1:m,v2:g,v3:u,v4:_,v5:v,v6:y,v7:b}),t[18]=u,t[19]=g,t[20]=_,t[21]=v,t[22]=y,t[23]=b,t[24]=x):x=t[24],x};function ya(e){let t=(0,X.c)(85),{projects:n,selectedThreadId:r,selectedProjectId:i,processingThreadIds:a,completedThreadIds:o,deletingThreadIds:c,deletingProjectIds:l,onSelectThread:u,onCreateProject:d,onCreateThread:f,onDeleteThread:p,onDeleteProject:m,onDeselect:h,collapsed:g,updateAvailable:_,updatingApp:v,onUpdateApp:y,expandProjectId:b}=e,x=Sr(),{showFeedback:S,feedbackName:C,setFeedbackName:w,feedbackEmail:T,setFeedbackEmail:E,feedbackText:D,setFeedbackText:O,loadingFeedbackUser:k,submittingFeedback:A,handleFeedbackDialogChange:j,handleSubmitFeedback:M}=ga(),P;t[0]===n?P=t[1]:(P=[...n].sort(xa),t[0]=n,t[1]=P);let F=P,I;t[2]===F?I=t[3]:(I=F.map(ba),t[2]=F,t[3]=I);let L=I,R;bb0:{if(!i){R=void 0;break bb0}if(n.find(e=>e.projectId===i)?.threads.length===1){R=void 0;break bb0}let e;t[4]===i?e=t[5]:(e=[i],t[4]=i,t[5]=e),R=e}let ee=R,z;t[6]===b?z=t[7]:(z=b?[b]:void 0,t[6]=b,t[7]=z);let te=z,ne;t[8]!==g||t[9]!==d?(ne=!g&&(0,$.jsxs)(W,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:d,children:[(0,$.jsx)(dt,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[8]=g,t[9]=d,t[10]=ne):ne=t[10];let re;t[11]!==g||t[12]!==y||t[13]!==_||t[14]!==v?(re=_&&(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:y,disabled:v,children:[v?(0,$.jsx)(N,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Zt,{className:`h-4 w-4`}),!g&&(0,$.jsx)(`span`,{className:`truncate`,children:v?`Updating...`:`Update to Latest`})]}),t[11]=g,t[12]=y,t[13]=_,t[14]=v,t[15]=re):re=t[15];let ie;t[16]===x?ie=t[17]:(ie=()=>void x(`/settings/general`),t[16]=x,t[17]=ie);let ae;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,$.jsx)(ht,{className:`h-4 w-4`}),t[18]=ae):ae=t[18];let oe;t[19]===g?oe=t[20]:(oe=!g&&(0,$.jsx)(`span`,{className:`truncate`,children:`Settings`}),t[19]=g,t[20]=oe);let se;t[21]!==ie||t[22]!==oe?(se=(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:ie,children:[ae,oe]}),t[21]=ie,t[22]=oe,t[23]=se):se=t[23];let ce;t[24]===j?ce=t[25]:(ce=()=>j(!0),t[24]=j,t[25]=ce);let le,de;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(ue,{className:`h-4 w-4`}),de=(0,$.jsx)(`span`,{className:`sr-only`,children:`Feedback`}),t[26]=le,t[27]=de):(le=t[26],de=t[27]);let fe;t[28]===ce?fe=t[29]:(fe=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:ce,children:[le,de]})}),t[28]=ce,t[29]=fe);let pe;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(pe=(0,$.jsx)(H,{children:`Send feedback to the Tarsk team`}),t[30]=pe):pe=t[30];let me;t[31]===fe?me=t[32]:(me=(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{children:[fe,pe]})}),t[31]=fe,t[32]=me);let B;t[33]!==se||t[34]!==me?(B=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[se,me]}),t[33]=se,t[34]=me,t[35]=B):B=t[35];let he;t[36]!==B||t[37]!==re?(he=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[re,B]}),t[36]=B,t[37]=re,t[38]=he):he=t[38];let ge;t[39]===n.length?ge=t[40]:(ge=n.length===0&&(0,$.jsx)(`p`,{className:q(s.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]=ge);let _e;t[41]!==o||t[42]!==l||t[43]!==c||t[44]!==x||t[45]!==f||t[46]!==m||t[47]!==p||t[48]!==u||t[49]!==a||t[50]!==n||t[51]!==i||t[52]!==r?(_e=(e,t)=>{let{isOpen:s,toggle:d}=t;return e.kind===`project`?(0,$.jsx)(Sa,{project:e.project,isOpen:s,onToggle:d,isDeletingProject:l.includes(e.project.projectId),isSelected:i?e.project.projectId===i:!1,onCreateThread:f,onDeleteProject:m,onProjectSettings:e=>void x(`/settings/project/${e}`),hasSelectedThread:e.project.threads.some(e=>e.threadId===r),onSelectThread:u}):(0,$.jsx)(Ca,{thread:e.thread,projectId:e.projectId,selectedThreadId:r,isProcessing:a.includes(e.thread.threadId),isDeleting:c.includes(e.thread.threadId),isCompleted:o.includes(e.thread.threadId),projectTitlePrefix:`${K(n.find(t=>t.projectId===e.projectId))} - `,onSelectThread:u,onDeleteThread:p})},t[41]=o,t[42]=l,t[43]=c,t[44]=x,t[45]=f,t[46]=m,t[47]=p,t[48]=u,t[49]=a,t[50]=n,t[51]=i,t[52]=r,t[53]=_e):_e=t[53];let ve;t[54]!==te||t[55]!==ee||t[56]!==L||t[57]!==_e?(ve=(0,$.jsx)(na,{nodes:L,defaultOpen:!1,initialOpenIds:ee,forceOpenIds:te,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:_e}),t[54]=te,t[55]=ee,t[56]=L,t[57]=_e,t[58]=ve):ve=t[58];let ye;t[59]!==ge||t[60]!==ve?(ye=(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:[ge,ve]})}),t[59]=ge,t[60]=ve,t[61]=ye):ye=t[61];let be;t[62]!==g||t[63]!==h||t[64]!==he||t[65]!==ye||t[66]!==ne?(be=(0,$.jsx)(va,{collapsed:g,onLogoClick:h,headerAction:ne,footer:he,children:ye}),t[62]=g,t[63]=h,t[64]=he,t[65]=ye,t[66]=ne,t[67]=be):be=t[67];let xe;t[68]===M?xe=t[69]:(xe=()=>void M(),t[68]=M,t[69]=xe);let Se;t[70]!==T||t[71]!==C||t[72]!==D||t[73]!==j||t[74]!==k||t[75]!==E||t[76]!==w||t[77]!==O||t[78]!==S||t[79]!==A||t[80]!==xe?(Se=(0,$.jsx)(ea,{open:S,onOpenChange:j,feedbackName:C,onFeedbackNameChange:w,feedbackEmail:T,onFeedbackEmailChange:E,feedbackText:D,onFeedbackTextChange:O,loadingFeedbackUser:k,submittingFeedback:A,onSubmit:xe}),t[70]=T,t[71]=C,t[72]=D,t[73]=j,t[74]=k,t[75]=E,t[76]=w,t[77]=O,t[78]=S,t[79]=A,t[80]=xe,t[81]=Se):Se=t[81];let Ce;return t[82]!==be||t[83]!==Se?(Ce=(0,$.jsxs)($.Fragment,{children:[be,Se]}),t[82]=be,t[83]=Se,t[84]=Ce):Ce=t[84],Ce}function ba(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 xa(e,t){return K(e).localeCompare(K(t))}function Sa(e){let t=(0,X.c)(39),{project:n,isOpen:i,onToggle:a,isDeletingProject:o,hasSelectedThread:s,isSelected:c,onCreateThread:l,onDeleteProject:u,onProjectSettings:d,onSelectThread:f}=e,p;t[0]===n?p=t[1]:(p=K(n),t[0]=n,t[1]=p);let m=p,h=s||c,g=n.threads.length===1?n.threads[0]:null,_;t[2]!==f||t[3]!==a||t[4]!==n.projectId||t[5]!==g||t[6]!==h?(_=function(){if(!h&&g){f(n.projectId,g.threadId);return}a()},t[2]=f,t[3]=a,t[4]=n.projectId,t[5]=g,t[6]=h,t[7]=_):_=t[7];let v=_,y=s||c,b=i&&`rotate-90`,x;t[8]===b?x=t[9]:(x=q(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,b),t[8]=b,t[9]=x);let S;t[10]===x?S=t[11]:(S=(0,$.jsx)(xn,{className:x}),t[10]=x,t[11]=S);let C;t[12]===n.gitUrl?C=t[13]:(C=n.gitUrl?(0,$.jsx)(Ce,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,$.jsx)(Ke,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[12]=n.gitUrl,t[13]=C);let w=(s||c)&&`font-bold text-foreground`,T;t[14]===w?T=t[15]:(T=q(`min-w-0 truncate transition-all block`,w),t[14]=w,t[15]=T);let E;t[16]!==m||t[17]!==T?(E=(0,$.jsx)(`span`,{className:T,children:m}),t[16]=m,t[17]=T,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==S||t[21]!==C?(D=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[S,C,E]}),t[19]=E,t[20]=S,t[21]=C,t[22]=D):D=t[22];let O;t[23]!==v||t[24]!==D?(O=(0,$.jsx)(`button`,{type:`button`,className:`min-w-0`,onClick:v,children:D}),t[23]=v,t[24]=D,t[25]=O):O=t[25];let k;t[26]!==O||t[27]!==y?(k=(0,$.jsx)(Tr,{selected:y,noBackground:!0,className:`h-9 min-w-0 flex-1`,asChild:!0,children:O}),t[26]=O,t[27]=y,t[28]=k):k=t[28];let A;t[29]!==o||t[30]!==l||t[31]!==u||t[32]!==d||t[33]!==n.projectId||t[34]!==n.threads.length?(A=(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:o?(0,$.jsx)(N,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,$.jsxs)(Sn,{children:[(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{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)(ht,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,$.jsx)(H,{side:`right`,children:`Project settings`})]}),(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{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)(dt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,$.jsx)(H,{side:`right`,children:`Add thread`})]}),n.threads.length===0&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{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)(r,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(H,{side:`right`,children:`Delete project`})]})]})}),t[29]=o,t[30]=l,t[31]=u,t[32]=d,t[33]=n.projectId,t[34]=n.threads.length,t[35]=A):A=t[35];let j;return t[36]!==k||t[37]!==A?(j=(0,$.jsxs)(`div`,{className:`group mb-1 flex min-w-0 items-center`,children:[k,A]}),t[36]=k,t[37]=A,t[38]=j):j=t[38],j}function Ca(e){let t=(0,X.c)(58),{thread:n,projectId:i,selectedThreadId:a,isProcessing:o,isDeleting:c,isCompleted:l,projectTitlePrefix:u,onSelectThread:d,onDeleteThread:f}=e,[p,m]=(0,Y.useState)(!1),h=(0,Y.useRef)(null),g=n.threadId===a,_,v;t[0]===o?(_=t[1],v=t[2]):(_=()=>{o&&h.current&&h.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},v=[o],t[0]=o,t[1]=_,t[2]=v),(0,Y.useEffect)(_,v);let y;t[3]!==f||t[4]!==i||t[5]!==n.gitStatusDot||t[6]!==n.threadId?(y=e=>{e.stopPropagation(),n.gitStatusDot?m(!0):f(i,n.threadId)},t[3]=f,t[4]=i,t[5]=n.gitStatusDot,t[6]=n.threadId,t[7]=y):y=t[7];let b=y,x;t[8]!==u||t[9]!==n.threadId||t[10]!==n.title?(x=n.title?.startsWith(u)?n.title.slice(u.length):n.title??n.threadId,t[8]=u,t[9]=n.threadId,t[10]=n.title,t[11]=x):x=t[11];let S=x,C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(jr,{children:`Delete Thread`}),t[12]=C):C=t[12];let w;t[13]===S?w=t[14]:(w=(0,$.jsxs)(Nr,{children:[`Are you sure you want to delete "`,S,`" and all its files? This action cannot be undone.`]}),t[13]=S,t[14]=w);let T;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Lr,{children:`Cancel`}),t[15]=T):T=t[15];let E;t[16]!==f||t[17]!==i||t[18]!==n.threadId?(E=(0,$.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[T,(0,$.jsx)(kr,{onClick:()=>{m(!1),f(i,n.threadId)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[16]=f,t[17]=i,t[18]=n.threadId,t[19]=E):E=t[19];let D;t[20]!==w||t[21]!==E?(D=(0,$.jsxs)(Mr,{children:[C,w,E]}),t[20]=w,t[21]=E,t[22]=D):D=t[22];let O;t[23]!==p||t[24]!==D?(O=(0,$.jsx)(Rr,{open:p,onOpenChange:m,children:D}),t[23]=p,t[24]=D,t[25]=O):O=t[25];let k;t[26]!==d||t[27]!==i||t[28]!==n.threadId?(k=()=>d(i,n.threadId),t[26]=d,t[27]=i,t[28]=n.threadId,t[29]=k):k=t[29];let A;t[30]===n.gitStatusDot?A=t[31]:(A=n.gitStatusDot?(0,$.jsx)(`svg`,{className:`h-3 w-3 shrink-0`,viewBox:`0 0 12 12`,fill:`hsl(var(--brand))`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})}):(0,$.jsx)(`svg`,{className:`h-3 w-3 shrink-0 text-muted-foreground`,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`})}),t[30]=n.gitStatusDot,t[31]=A);let j;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(j=q(s.body,`truncate block`),t[32]=j):j=t[32];let M;t[33]===S?M=t[34]:(M=(0,$.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,$.jsx)(`span`,{className:j,children:S})}),t[33]=S,t[34]=M);let P;t[35]!==l||t[36]!==c||t[37]!==o?(P=o||c?(0,$.jsx)(N,{className:`ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground`}):l?(0,$.jsx)(An,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):null,t[35]=l,t[36]=c,t[37]=o,t[38]=P):P=t[38];let F;t[39]!==k||t[40]!==A||t[41]!==M||t[42]!==P?(F=(0,$.jsxs)(`button`,{type:`button`,className:`min-w-0 w-full`,onClick:k,children:[A,M,P]}),t[39]=k,t[40]=A,t[41]=M,t[42]=P,t[43]=F):F=t[43];let I;t[44]!==g||t[45]!==F?(I=(0,$.jsx)(Tr,{selected:g,className:`min-w-0 flex-1`,asChild:!0,children:F}),t[44]=g,t[45]=F,t[46]=I):I=t[46];let L;t[47]!==b||t[48]!==l||t[49]!==c||t[50]!==o?(L=!o&&!c&&!l&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{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:b,children:[(0,$.jsx)(r,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,$.jsx)(H,{side:`right`,children:`Delete thread and files from the repo`})]}),t[47]=b,t[48]=l,t[49]=c,t[50]=o,t[51]=L):L=t[51];let R;t[52]!==I||t[53]!==L?(R=(0,$.jsxs)(`div`,{ref:h,className:`group flex min-w-0 items-center`,children:[I,L]}),t[52]=I,t[53]=L,t[54]=R):R=t[54];let ee;return t[55]!==O||t[56]!==R?(ee=(0,$.jsxs)($.Fragment,{children:[O,R]}),t[55]=O,t[56]=R,t[57]=ee):ee=t[57],ee}var wa=e(Lt(),1),Ta=.1,Ea=10,Da=1.25,Oa=.001;function ka(){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=Aa,u;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>n(e=>l(e*Da)),e[1]=u):u=e[1];let d=u,f;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>n(e=>l(e/Da)),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*Oa;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 Aa(e){return Math.min(Math.max(e,Ta),Ea)}var ja=Pr(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`]}),Ma=Pr(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`]}),Na=Pr(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`div`,{className:e.v2,children:`Rendering diagram…`})]}),{name:`MermaidRenderer_2`,portals:[`v1`]}),Pa=Pr(e=>e.v0,{name:`MermaidRenderer_3`,portals:[`v0`]}),Fa=function(e){let t=(0,X.c)(47),{content:n,className:r}=e,[i,a]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(!1),{svgOutput:l,renderError:u}=La(n,Ia()),d;t[0]===n?d=t[1]:(d=async function(){await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=n,t[1]=d);let f=d,p;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(s.compact,`font-mono text-muted-foreground`),t[2]=p):p=t[2];let m=u?`mermaid (render error)`:`mermaid diagram`,h;t[3]!==u||t[4]!==l?(h=l&&!u&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`action`,size:`icon-xs`,onClick:()=>c(!0),children:[(0,$.jsx)(C,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View fullscreen`})]})}),(0,$.jsx)(H,{children:`View fullscreen`})]}),t[3]=u,t[4]=l,t[5]=h):h=t[5];let g;t[6]===i?g=t[7]:(g=i?(0,$.jsx)(An,{}):(0,$.jsx)(yt,{}),t[6]=i,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy mermaid code`}),t[8]=_):_=t[8];let v;t[9]!==f||t[10]!==g?(v=(0,$.jsxs)(W,{variant:`action`,size:`icon-xs`,onClick:f,children:[g,_]}),t[9]=f,t[10]=g,t[11]=v):v=t[11];let y;t[12]!==m||t[13]!==h||t[14]!==v?(y=(0,$.jsx)(ja,{v0:p,v1:m,v2:h,v3:v}),t[12]=m,t[13]=h,t[14]=v,t[15]=y):y=t[15];let b=y;if(u){let e;t[16]===r?e=t[17]:(e=q(`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=q(s.compact,`font-mono text-foreground leading-relaxed`),t[18]=i):i=t[18];let a;return t[19]!==n||t[20]!==b||t[21]!==e?(a=(0,$.jsx)(Ma,{v0:e,v1:b,v2:i,v3:n}),t[19]=n,t[20]=b,t[21]=e,t[22]=a):a=t[22],a}if(!l){let e;t[23]===r?e=t[24]:(e=q(`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=q(s.compact,`p-4 text-muted-foreground`),t[25]=n):n=t[25];let i;return t[26]!==b||t[27]!==e?(i=(0,$.jsx)(Na,{v0:e,v1:b,v2:n}),t[26]=b,t[27]=e,t[28]=i):i=t[28],i}let x;t[29]===r?x=t[30]:(x=q(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[29]=r,t[30]=x);let S;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>c(!0),t[31]=S):S=t[31];let w;t[32]===l?w=t[33]:(w=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`block w-full text-left cursor-zoom-in p-4 max-w-full overflow-hidden [&_svg]:max-w-full [&_svg]:h-auto hover:bg-muted/70 transition-colors`,onClick:S,dangerouslySetInnerHTML:{__html:l}})}),t[32]=l,t[33]=w);let T;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(H,{children:`Click to view fullscreen`}),t[34]=T):T=t[34];let E;t[35]===w?E=t[36]:(E=(0,$.jsxs)(kt,{children:[w,T]}),t[35]=w,t[36]=E);let D;t[37]!==b||t[38]!==E||t[39]!==x?(D=(0,$.jsxs)(`div`,{className:x,children:[b,E]}),t[37]=b,t[38]=E,t[39]=x,t[40]=D):D=t[40];let O;t[41]!==o||t[42]!==l?(O=o&&(0,$.jsx)(Ra,{svgOutput:l,onClose:()=>c(!1)}),t[41]=o,t[42]=l,t[43]=O):O=t[43];let k;return t[44]!==D||t[45]!==O?(k=(0,$.jsx)(Pa,{v0:(0,$.jsxs)(Sn,{children:[D,O]})}),t[44]=D,t[45]=O,t[46]=k):k=t[46],k};function Ia(){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 La(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 wr(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 Ra(e){let t=(0,X.c)(70),{svgOutput:n,onClose:r}=e,{scale:i,offset:a,isDragging:c,containerRef:l,zoomIn:u,zoomOut:d,reset:f,onMouseDown:p,onMouseMove:m,onMouseUp:h}=ka(),g,_;t[0]===r?(g=t[1],_=t[2]):(g=()=>{let e=function(e){e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},_=[r],t[0]=r,t[1]=g,t[2]=_),(0,Y.useEffect)(g,_);let v;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(v=[],t[3]=v):v=t[3],(0,Y.useEffect)(za,v);let y;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(`span`,{className:q(s.compact,`font-mono text-muted-foreground`),children:`mermaid diagram`}),t[4]=y):y=t[4];let b,x;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(o,{className:`h-3.5 w-3.5`}),x=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom out`}),t[5]=b,t[6]=x):(b=t[5],x=t[6]);let S;t[7]===d?S=t[8]:(S=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`icon-xs`,onClick:d,children:[b,x]})}),t[7]=d,t[8]=S);let C;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(H,{children:`Zoom out`}),t[9]=C):C=t[9];let w;t[10]===S?w=t[11]:(w=(0,$.jsxs)(kt,{children:[S,C]}),t[10]=S,t[11]=w);let T;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(T=q(s.compact,`min-w-[3rem] px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`),t[12]=T):T=t[12];let E;t[13]===i?E=t[14]:(E=Math.round(i*100),t[13]=i,t[14]=E);let D;t[15]!==f||t[16]!==E?(D=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:f,className:T,children:[E,`%`]})}),t[15]=f,t[16]=E,t[17]=D):D=t[17];let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(H,{children:`Reset zoom`}),t[18]=O):O=t[18];let k;t[19]===D?k=t[20]:(k=(0,$.jsxs)(kt,{children:[D,O]}),t[19]=D,t[20]=k);let A,j;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(dt,{className:`h-3.5 w-3.5`}),j=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom in`}),t[21]=A,t[22]=j):(A=t[21],j=t[22]);let M;t[23]===u?M=t[24]:(M=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`icon-xs`,onClick:u,children:[A,j]})}),t[23]=u,t[24]=M);let N;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(H,{children:`Zoom in`}),t[25]=N):N=t[25];let P;t[26]===M?P=t[27]:(P=(0,$.jsxs)(kt,{children:[M,N]}),t[26]=M,t[27]=P);let F,I;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,$.jsx)(G,{className:`h-3.5 w-3.5`}),I=(0,$.jsx)(`span`,{className:`sr-only`,children:`Reset view`}),t[28]=F,t[29]=I):(F=t[28],I=t[29]);let L;t[30]===f?L=t[31]:(L=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`icon-xs`,onClick:f,children:[F,I]})}),t[30]=f,t[31]=L);let R;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(H,{children:`Reset view`}),t[32]=R):R=t[32];let ee;t[33]===L?ee=t[34]:(ee=(0,$.jsxs)(kt,{children:[L,R]}),t[33]=L,t[34]=ee);let te;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),t[35]=te):te=t[35];let ne,re;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,$.jsx)(z,{className:`h-3.5 w-3.5`}),re=(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`}),t[36]=ne,t[37]=re):(ne=t[36],re=t[37]);let ie;t[38]===r?ie=t[39]:(ie=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`icon-xs`,onClick:r,children:[ne,re]})}),t[38]=r,t[39]=ie);let ae;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,$.jsx)(H,{children:`Close (Esc)`}),t[40]=ae):ae=t[40];let oe;t[41]===ie?oe=t[42]:(oe=(0,$.jsxs)(kt,{children:[ie,ae]}),t[41]=ie,t[42]=oe);let se;t[43]!==k||t[44]!==P||t[45]!==ee||t[46]!==oe||t[47]!==w?(se=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-background/90 border-b border-border shrink-0`,children:[y,(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[w,k,P,ee,te,oe]})]}),t[43]=k,t[44]=P,t[45]=ee,t[46]=oe,t[47]=w,t[48]=se):se=t[48];let ce=c?`cursor-grabbing`:`cursor-grab`,le;t[49]===ce?le=t[50]:(le=q(`flex-1 overflow-hidden select-none`,ce),t[49]=ce,t[50]=le);let ue=`translate(${a.x}px, ${a.y}px) scale(${i})`,de=c?`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 pe;t[54]===n?pe=t[55]:(pe={__html:n},t[54]=n,t[55]=pe);let me;t[56]!==fe||t[57]!==pe?(me=(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,style:fe,dangerouslySetInnerHTML:pe}),t[56]=fe,t[57]=pe,t[58]=me):me=t[58];let B;t[59]!==l||t[60]!==p||t[61]!==m||t[62]!==h||t[63]!==le||t[64]!==me?(B=(0,$.jsx)(`div`,{ref:l,className:le,onMouseDown:p,onMouseMove:m,onMouseUp:h,onMouseLeave:h,children:me}),t[59]=l,t[60]=p,t[61]=m,t[62]=h,t[63]=le,t[64]=me,t[65]=B):B=t[65];let he;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(`div`,{className:q(s.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]!==se||t[68]!==B?(ge=(0,wa.createPortal)((0,$.jsx)(Sn,{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:[se,B,he]})}),document.body),t[67]=se,t[68]=B,t[69]=ge):ge=t[69],ge}function za(){return document.body.style.overflow=`hidden`,Ba}function Ba(){document.body.style.overflow=``}function Va(e){return!!(oe(e.hostname)||typeof window<`u`&&e.origin===window.location.origin)}function Ha(e){let t=e.trim();if(!t||t.startsWith(`data:`)||t.includes(`/explorer/media`))return null;let n;if(/^https?:\/\//i.test(t)){let e;try{e=new URL(t)}catch{return null}if(!Va(e))return null;n=decodeURIComponent(e.pathname.replace(/^\/+/,``))}else n=decodeURIComponent(t.replace(/^\/+/,``));return On(n)===`image`?n:null}function Ua(e,t){if(t){let n=Ha(e);if(n)return`/api/threads/${encodeURIComponent(t)}/explorer/media?path=${encodeURIComponent(n)}`}return de(e,In())}var Wa=Pr(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`]}),Ga=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}`:Ua(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=Ft(u)??`generated-image-${Date.now()}.png`,{path:t}=await Ht(u.startsWith(`data:`)?{imageData:u.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:u,filename:e});pa({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 ut(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)(Zt,{className:`h-3.5 w-3.5`}),t[9]=g):g=t[9];let _;t[10]===f?_=t[11]:(_=(0,$.jsx)(Fn,{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)(H,{children:`Save image`}),t[12]=v):v=t[12];let y;t[13]===_?y=t[14]:(y=(0,$.jsxs)(kt,{children:[_,v]}),t[13]=_,t[14]=y);let b;t[15]===s?b=t[16]:(b=s?(0,$.jsx)(An,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(yt,{className:`h-3.5 w-3.5`}),t[15]=s,t[16]=b);let x;t[17]!==m||t[18]!==b?(x=(0,$.jsx)(Fn,{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)(H,{children:S}),t[20]=S,t[21]=C);let w;t[22]!==x||t[23]!==C?(w=(0,$.jsxs)(kt,{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)(Sn,{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)(Wa,{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 Ka(e){let t=ve(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 qa(e,t){let n=Ka(e)??Ka(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 Ja=`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(`.`),Ya=[/-->/,/--\./,/-\./,/==>/,/--\|/,/\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 Xa(e){if(!e||typeof e!=`string`)return!1;let t=e.split(`
|
|
6
|
+
`).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(Ja.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `)))return!0;let r=0;for(let t of Ya)t.test(e)&&r++;return r>=2}function Za(e){if(!Xa(e))return null;let t=/```mermaid\s*\n([\s\S]*?)\n```/.exec(e);if(t)return t[1].trim();let n=e.split(`
|
|
7
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)[0].toLowerCase();return Ja.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `))?e.trim():null}function Qa(e){let t=e.trim();if(t.startsWith(`/`)){let e=In().replace(/\/$/,``);return de(`${e}${t}`,e)}return de(t,In())}function $a(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(oe(e.hostname))return!0;let n=new URL(In());return e.origin===n.origin&&e.pathname.startsWith(`/api/`)}catch{return!1}}function eo(e){let t=e.trim();return!t||t.startsWith(`mailto:`)||t.startsWith(`tel:`)?!1:ye()?/^https?:\/\//i.test(t)||t.startsWith(`/api/`):$a(t)}function to(e){let t=Qa(e);return Xe()&&!ye()?(window.open(t,`_blank`,`noopener,noreferrer`),Promise.resolve()):Je(t)}function no(e){let t=(0,X.c)(14),{href:n,children:r}=e,i;t[0]===n?i=t[1]:(i=Qa(n),t[0]=n,t[1]=i);let a=i,o;t[2]===n?o=t[3]:(o=eo(n),t[2]=n,t[3]=o);let s=o,c;t[4]!==n||t[5]!==s?(c=function(e){s&&(e.preventDefault(),to(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 ro=Pr(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:`overflow-x-auto p-4 max-w-full`,children:(0,$.jsx)(`code`,{className:e.v3,children:e.v4})})]}),{name:`CodeBlock_1`,portals:[`v1`,`v2`,`v4`]}),io=function(e){let t=(0,X.c)(14),{language:n,code:r}=e,[i,a]=(0,Y.useState)(!1),o;t[0]===r?o=t[1]:(o=async()=>{await navigator.clipboard.writeText(r),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=r,t[1]=o);let c=o,l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=q(s.compact,`text-muted-foreground font-mono`),t[2]=l):l=t[2];let u=n||`text`,d;t[3]===i?d=t[4]:(d=i?(0,$.jsx)(An,{}):(0,$.jsx)(yt,{}),t[3]=i,t[4]=d);let f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[5]=f):f=t[5];let p;t[6]!==c||t[7]!==d?(p=(0,$.jsxs)(W,{variant:`action`,size:`icon-xs`,onClick:c,children:[d,f]}),t[6]=c,t[7]=d,t[8]=p):p=t[8];let m;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.mono,`text-foreground leading-relaxed`),t[9]=m):m=t[9];let h;return t[10]!==r||t[11]!==u||t[12]!==p?(h=(0,$.jsx)(ro,{v0:l,v1:u,v2:p,v3:m,v4:r}),t[10]=r,t[11]=u,t[12]=p,t[13]=h):h=t[13],h},ao=(0,Y.memo)(function({content:e,className:t,enableMermaid:n=!1,threadId:r}){let i=(0,Y.useMemo)(()=>!e||typeof e!=`string`?[]:co(e,n),[e,n]),a=(0,Y.useMemo)(()=>{let e=0;return i.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})},[i]);return i.length===0?null:(0,$.jsx)(`div`,{className:q(`prose-custom space-y-3 min-w-0 break-words`,t),children:i.map((e,t)=>(0,$.jsx)(bo,{block:e,start:a[t],threadId:r},t))})}),oo=/^!\[([^\]]*)\]\(([^)]+)\)\s*$/;function so(e){let t=e.match(oo);return t?{alt:t[1],src:t[2]}:null}function co(e,t=!1){let n=e.split(`
|
|
8
|
+
`),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`||Xa(o.join(`
|
|
9
|
+
`)))?r.push({type:`mermaid`,code:o.join(`
|
|
10
|
+
`)}):r.push({type:`code`,language:a,code:o.join(`
|
|
11
|
+
`)}),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(`
|
|
12
|
+
`)});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=so(e);if(o){r.push({type:`image`,...o}),i++;continue}let s=[];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]);)s.push(n[i]),i++;if(s.length>0){let e=s.join(`
|
|
13
|
+
`);if(t&&Xa(e)){let t=Za(e);t?r.push({type:`mermaid`,code:t}):r.push({type:`paragraph`,text:e})}else r.push({type:`paragraph`,text:e})}}return r}var lo=Pr(e=>e.v0,{name:`MarkdownBlock_2`,portals:[`v0`]}),uo=Pr(e=>e.v0,{name:`MarkdownBlock_3`,portals:[`v0`]}),fo=Pr(e=>(0,$.jsx)(`blockquote`,{className:`border-l-2 border-border pl-4 text-muted-foreground italic`,children:e.v0}),{name:`MarkdownBlock_4`,portals:[`v0`]}),po=Pr(e=>(0,$.jsx)(`ol`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_5`,portals:[`v1`]}),mo=Pr(e=>(0,$.jsx)(`ul`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_6`,portals:[`v1`]}),ho=Pr(e=>(0,$.jsx)(`p`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_7`,portals:[`v1`]}),go=Pr(()=>(0,$.jsx)(`hr`,{className:`border-border`}),{name:`MarkdownBlock_8`}),_o=Pr(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`]}),vo=Pr(e=>e.v0,{name:`MarkdownBlock_10`,portals:[`v0`]}),yo=Pr(e=>e.v0,{name:`MarkdownBlock_11`,portals:[`v0`]}),bo=(0,Y.memo)(function(e){let t=(0,X.c)(66),{block:n,start:r,threadId:i}=e,a=r===void 0?1:r;switch(n.type){case`heading`:{let e=`h${n.level}`,r,a,o;if(t[0]!==e||t[1]!==n.level){let i={1:s.sectionTitle,2:q(s.body,`font-semibold`),3:q(s.body,`font-semibold`),4:s.sectionSubtitle,5:s.sectionSubtitle,6:s.sectionSubtitle};a=lo,r=e,o=q(i[n.level]),t[0]=e,t[1]=n.level,t[2]=r,t[3]=a,t[4]=o}else r=t[2],a=t[3],o=t[4];let c;t[5]!==n.text||t[6]!==i?(c=(0,$.jsx)(xo,{text:n.text,threadId:i}),t[5]=n.text,t[6]=i,t[7]=c):c=t[7];let l;t[8]!==r||t[9]!==o||t[10]!==c?(l=(0,$.jsx)(r,{className:o,children:c}),t[8]=r,t[9]=o,t[10]=c,t[11]=l):l=t[11];let u;return t[12]!==a||t[13]!==l?(u=(0,$.jsx)(a,{v0:l}),t[12]=a,t[13]=l,t[14]=u):u=t[14],u}case`code`:{let e;return t[15]!==n.code||t[16]!==n.language?(e=(0,$.jsx)(uo,{v0:(0,$.jsx)(io,{language:n.language,code:n.code})}),t[15]=n.code,t[16]=n.language,t[17]=e):e=t[17],e}case`blockquote`:{let e;return t[18]!==n.text||t[19]!==i?(e=(0,$.jsx)(fo,{v0:(0,$.jsx)(xo,{text:n.text,threadId:i})}),t[18]=n.text,t[19]=i,t[20]=e):e=t[20],e}case`list`:{if(n.ordered){let e;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(s.body,`space-y-1`),t[21]=e):e=t[21];let r;if(t[22]!==n.items||t[23]!==a||t[24]!==i){let e;t[26]!==a||t[27]!==i?(e=(e,t)=>(0,$.jsxs)(`li`,{className:`flex gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`shrink-0 select-none tabular-nums`,children:[a+t,`.`]}),(0,$.jsx)(`span`,{children:(0,$.jsx)(xo,{text:e,threadId:i})})]},t),t[26]=a,t[27]=i,t[28]=e):e=t[28],r=n.items.map(e),t[22]=n.items,t[23]=a,t[24]=i,t[25]=r}else r=t[25];let o;return t[29]===r?o=t[30]:(o=(0,$.jsx)(po,{v0:e,v1:r}),t[29]=r,t[30]=o),o}let e;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(s.body,`space-y-1 pl-5 list-outside overflow-visible list-disc`),t[31]=e):e=t[31];let r;if(t[32]!==n.items||t[33]!==i){let e;t[35]===i?e=t[36]:(e=(e,t)=>(0,$.jsx)(`li`,{children:(0,$.jsx)(xo,{text:e,threadId:i})},t),t[35]=i,t[36]=e),r=n.items.map(e),t[32]=n.items,t[33]=i,t[34]=r}else r=t[34];let o;return t[37]===r?o=t[38]:(o=(0,$.jsx)(mo,{v0:e,v1:r}),t[37]=r,t[38]=o),o}case`paragraph`:{let e;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(s.body,`leading-relaxed whitespace-pre-wrap break-words`),t[39]=e):e=t[39];let r;return t[40]!==n.text||t[41]!==i?(r=(0,$.jsx)(ho,{v0:e,v1:(0,$.jsx)(xo,{text:n.text,threadId:i})}),t[40]=n.text,t[41]=i,t[42]=r):r=t[42],r}case`hr`:{let e;return t[43]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(go,{}),t[43]=e):e=t[43],e}case`table`:{let e;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(s.body,`w-full`),t[44]=e):e=t[44];let r;if(t[45]!==n.headers||t[46]!==i){let e;t[48]===i?e=t[49]:(e=(e,t)=>(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:(0,$.jsx)(xo,{text:e,threadId:i})},t),t[48]=i,t[49]=e),r=n.headers.map(e),t[45]=n.headers,t[46]=i,t[47]=r}else r=t[47];let a;if(t[50]!==n.rows||t[51]!==i){let e;t[53]===i?e=t[54]:(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)(xo,{text:e,threadId:i})},t))},t),t[53]=i,t[54]=e),a=n.rows.map(e),t[50]=n.rows,t[51]=i,t[52]=a}else a=t[52];let o;return t[55]!==r||t[56]!==a?(o=(0,$.jsx)(_o,{v0:e,v1:r,v2:a}),t[55]=r,t[56]=a,t[57]=o):o=t[57],o}case`mermaid`:{let e;return t[58]===n.code?e=t[59]:(e=(0,$.jsx)(vo,{v0:(0,$.jsx)(Fa,{content:n.code})}),t[58]=n.code,t[59]=e),e}case`image`:{let e;t[60]!==n.src||t[61]!==i?(e=Ua(n.src,i),t[60]=n.src,t[61]=i,t[62]=e):e=t[62];let r=n.alt||`Image`,a;return t[63]!==e||t[64]!==r?(a=(0,$.jsx)(yo,{v0:(0,$.jsx)(Ga,{imageUrl:e,alt:r})}),t[63]=e,t[64]=r,t[65]=a):a=t[65],a}default:return null}}),xo=(0,Y.memo)(function(e){let t=(0,X.c)(9),{text:n,threadId:r}=e,i;t[0]===n?i=t[1]:(i=So(n),t[0]=n,t[1]=i);let a=i,o;if(t[2]!==a||t[3]!==r){let e;t[5]===r?e=t[6]:(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:q(s.mono,`rounded bg-muted/20 px-1.5 py-0.5`),children:e.text},t);case`link`:return(0,$.jsx)(no,{href:e.href,children:e.text},t);case`image`:return(0,$.jsx)(Ga,{imageUrl:Ua(e.src,r),alt:e.alt||`Image`},t);default:return(0,$.jsx)(`span`,{children:e.text},t)}},t[5]=r,t[6]=e),o=a.map(e),t[2]=a,t[3]=r,t[4]=o}else o=t[4];let c;return t[7]===o?c=t[8]:(c=(0,$.jsx)($.Fragment,{children:o}),t[7]=o,t[8]=c),c});function So(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}]}var Co=(0,Y.createContext)({activeMainTab:`chat`,setActiveMainTab:()=>{},devServerUrl:null,setDevServerUrl:()=>{},devServerRunning:!1,setDevServerRunning:()=>{},devServerLoading:!1,setDevServerLoading:()=>{},terminalNotification:!1,setTerminalNotification:()=>{},pendingExplorerPath:null,setPendingExplorerPath:()=>{},explorerRefreshTick:0,triggerExplorerRefresh:()=>{},explorerClearPath:null,setExplorerClearPath:()=>{},browserResetTrigger:0,triggerBrowserReset:()=>{},browserDeviceMode:`desktop`,setBrowserDeviceMode:()=>{}});function wo(){return(0,Y.useContext)(Co)}var To=new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`,`g`),Eo=new RegExp(String.raw`\x1B\].*?(?:\x07|\x1B\\)`,`g`),Do=new RegExp(String.raw`\x1B[@-_]`,`g`),Oo=/\r(?!\n)/g,ko=/\\n/g;function Ao(e){return e.replace(Eo,``).replace(To,``).replace(Do,``)}function jo(e){return Ao(e).replace(ko,`
|
|
14
|
+
`).replace(Oo,`
|
|
15
|
+
`)}function Mo(e){return v(e)}function No(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 Po(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}var Fo=32;function Io(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 Lo(e,t=Fo,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=Io(a,t);e&&i.push(`${n}: ${e}`)}return i.length>0?i.join(`, `):null}function Ro(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 zo(e){return typeof e!=`object`||!e||Array.isArray(e)?e:w(e)}function Bo(e){try{return Wo(zo(JSON.parse(e)))}catch{return Wo(e)}}function Vo(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 Ho(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Ho);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=Vo(r);t[n]=typeof e==`object`?Ho(e):r}else t[n]=Ho(r);return t}function Uo(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
|
|
16
|
+
`),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
|
|
17
|
+
`),t=t.replace(/\\"/g,`"`),t}function Wo(e){if(e==null)return``;let t=typeof e==`object`&&e?Ho(e):e;return jo(Uo(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2)))}function Go(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:No(Po(i),t),d=No(o?String(i.prompt):null,t),f=No(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`,y=_&&a&&typeof a.query==`string`?a.query:null,x=_&&a&&typeof a.filePath==`string`?a.filePath:null,S=_&&a&&typeof a.fileGlob==`string`?a.fileGlob:null,C=No(a&&typeof a.path==`string`?a.path:null,t),w=a&&typeof a.offset==`number`?a.offset:null,T=a&&typeof a.limit==`number`?a.limit:null,E=n.toLowerCase(),D=E.includes(`read`)||E.includes(`write`)||E.includes(`edit`),O=E.includes(`edit`),k=D&&a&&typeof a.path==`string`?a.path:null,A=k?k.split(`/`).pop()??k:null,j=O&&a&&typeof a.oldText==`string`?a.oldText:null,M=O&&a&&typeof a.newText==`string`?a.newText:null,N=j===null?null:j.split(`
|
|
18
|
+
`).length,P=M===null?null:M.split(`
|
|
19
|
+
`).length,F=j!==null&&M!==null,I=n===`generate_image`&&a&&typeof a.prompt==`string`?a.prompt:null,L=n===`find_images`&&a&&typeof a.query==`string`?a.query:null,R=n===`todo`&&a?a.status:void 0,ee=e.displayName??v(n),z=e.activeDisplayName??b(n),te=`default`;return E===`bash`||E.includes(`terminal`)||E.includes(`shell`)?te=`bash`:E===`fetch`?te=`fetch`:D?te=`file`:_||E===`find`||E===`web_search`||E.includes(`search`)||E.includes(`grep`)?te=`search`:E===`agent`||E.includes(`subagent`)||o?te=`agent`:E===`todo`?te=`todo`:E===`generate_image`?te=`imageGen`:E===`find_images`?te=`findImages`:E===`browser`&&(te=`browser`),{toolType:te,toolName:n,toolId:r,displayName:ee,activeDisplayName:z,inputObj:a,toolInput:u,command:f,fetchUrl:p,pattern:m,webSearchQuery:h,codeSearchQuery:y,codeSearchFilePath:x,codeSearchFileGlob:S,isFileTool:D,isEditTool:O,filePath:k,fileDisplayName:A,editOldText:j,editNewText:M,editDeletedLineCount:N,editAddedLineCount:P,hasEditDiff:F,path:C,offset:w,limit:T,prompt:d,agentName:l,subagentType:c,lang:g,imageGenPrompt:I,findImagesQuery:L,todoStatus:R}}var Ko=new Map;function qo(e){return e.trim()}function Jo(){let e=Qt(tt.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[qo(e)]=r);return n}catch{return{}}}function Yo(e){qt(tt.BASH_COMMAND_DURATIONS,JSON.stringify(e))}function Xo(e){return Jo()[qo(e)]??null}function Zo(e,t){let n=qo(e);if(!n||!Number.isFinite(t)||t<=0)return;let r=Jo();r[n]=Math.round(t),Yo(r)}function Qo(e,t){!t?.trim()||Ko.has(e)||Ko.set(e,{command:qo(t),startedAt:Date.now()})}function $o(e){let t=Ko.get(e);if(!t)return;let n=Date.now()-t.startedAt;Zo(t.command,n),Ko.delete(e)}function es(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 ts(e,t){return t!==null&&t>0?`${Math.min(99,Math.round(e/t*100))}% complete`:es(e)}var ns=1e3;function rs(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?Xo(n):null),Qo(t,e),s.current=Date.now(),i(0)}else !n&&c.current&&($o(t),s.current=null,i(0),o(null));c.current=n},[n,e,t]),(0,Y.useEffect)(()=>()=>{l.current&&$o(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,ns);return()=>clearInterval(t)},[n]),n?ts(r,a):null}function is(e){let{maxHeight:t=`48`,padding:n=`2`,leading:r=!1,className:i}=e??{};return q(s.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 as(e){let t=(0,X.c)(12),{open:n,onOpenChange:r,title:i,content:a}=e,o;t[0]===i?o=t[1]:(o=(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:(0,$.jsx)(`code`,{className:s.mono,children:i})})}),t[0]=i,t[1]=o);let c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=is({padding:`3`,className:`flex-1 max-h-none`}),t[2]=c):c=t[2];let l;t[3]===a?l=t[4]:(l=(0,$.jsx)(`pre`,{className:c,children:a}),t[3]=a,t[4]=l);let u;t[5]!==o||t[6]!==l?(u=(0,$.jsxs)(ce,{className:`max-w-3xl h-[80vh] flex flex-col`,children:[o,l]}),t[5]=o,t[6]=l,t[7]=u):u=t[7];let d;return t[8]!==r||t[9]!==n||t[10]!==u?(d=(0,$.jsx)(Rt,{open:n,onOpenChange:r,children:u}),t[8]=r,t[9]=n,t[10]=u,t[11]=d):d=t[11],d}function os(e){let t=(0,X.c)(20),{open:n,onOpenChange:r,title:i,requestContent:a,responseContent:o}=e,c;t[0]===i?c=t[1]:(c=(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:(0,$.jsx)(`code`,{className:s.mono,children:i})})}),t[0]=i,t[1]=c);let l,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`div`,{className:q(s.compact,`mb-1 text-muted-foreground`),children:`Request`}),u=is({padding:`3`,className:`max-h-48`}),t[2]=l,t[3]=u):(l=t[2],u=t[3]);let d;t[4]===a?d=t[5]:(d=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[l,(0,$.jsx)(`pre`,{className:u,children:a})]}),t[4]=a,t[5]=d);let f,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(`div`,{className:q(s.compact,`mb-1 text-muted-foreground`),children:`Response`}),p=is({padding:`3`,className:`flex-1 max-h-none`}),t[6]=f,t[7]=p):(f=t[6],p=t[7]);let m;t[8]===o?m=t[9]:(m=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[f,(0,$.jsx)(`pre`,{className:p,children:o})]}),t[8]=o,t[9]=m);let h;t[10]!==d||t[11]!==m?(h=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[d,m]}),t[10]=d,t[11]=m,t[12]=h):h=t[12];let g;t[13]!==c||t[14]!==h?(g=(0,$.jsxs)(ce,{className:`max-w-3xl h-[80vh] flex flex-col gap-4`,children:[c,h]}),t[13]=c,t[14]=h,t[15]=g):g=t[15];let _;return t[16]!==r||t[17]!==n||t[18]!==g?(_=(0,$.jsx)(Rt,{open:n,onOpenChange:r,children:g}),t[16]=r,t[17]=n,t[18]=g,t[19]=_):_=t[19],_}function ss(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(`
|
|
20
|
+
`),c=r.split(`
|
|
21
|
+
`);t[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=q(s.caption,`font-mono whitespace-pre-wrap overflow-auto`),t[5]=i):i=t[5],a=e.map(ls),o=c.map(cs),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 c;return t[6]!==i||t[7]!==a||t[8]!==o?(c=(0,$.jsxs)(`pre`,{className:i,children:[a,o]}),t[6]=i,t[7]=a,t[8]=o,t[9]=c):c=t[9],c}function cs(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 ls(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 us(e){let t=(0,X.c)(3),{name:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(s.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 ds(e){let t=(0,X.c)(3),{type:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(s.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 fs(e){let t=(0,X.c)(3),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(s.caption,`font-mono break-all 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 ps(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=q(`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 ms(e){let t=(0,X.c)(15),{toolName:n,displayName:r,muted:i,size:a,className:o}=e,c=i===void 0?!0:i,l;t[0]===o?l=t[1]:(l=q(`inline-flex items-center gap-1`,o),t[0]=o,t[1]=l);let u=!c&&`text-foreground`,d;t[2]===u?d=t[3]:(d=q(s.caption,u),t[2]=u,t[3]=d);let f;t[4]!==r||t[5]!==d?(f=(0,$.jsx)(`span`,{className:d,children:r}),t[4]=r,t[5]=d,t[6]=f):f=t[6];let p;t[7]!==l||t[8]!==f?(p=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{className:l,children:f})}),t[7]=l,t[8]=f,t[9]=p):p=t[9];let m;t[10]===n?m=t[11]:(m=(0,$.jsx)(H,{children:n}),t[10]=n,t[11]=m);let h;return t[12]!==p||t[13]!==m?(h=(0,$.jsxs)(kt,{children:[p,m]}),t[12]=p,t[13]=m,t[14]=h):h=t[14],h}function hs(e){let t=(0,X.c)(102),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(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?jo(h):``,t[2]=h,t[3]=g);let _=g,v=a?_:``,y=rs(n.command,n.toolId,!!a),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]!==a||t[8]!==c?(S=()=>{c&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[7]=a,t[8]=c,t[9]=S):S=t[9];let C;if(t[10]!==a||t[11]!==c||t[12]!==v?(C=[c,a,v],t[10]=a,t[11]=c,t[12]=v,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)(ms,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!1}),t[16]=n.activeDisplayName,t[17]=n.toolName,t[18]=r):r=t[18];let i;t[19]===n.command?i=t[20]:(i=n.command!==null&&(0,$.jsx)(`span`,{className:q(s.caption,`break-all`),children:n.command}),t[19]=n.command,t[20]=i);let a;t[21]===y?a=t[22]:(a=y&&(0,$.jsx)(`span`,{className:q(s.caption,`tabular-nums shrink-0`),children:y}),t[21]=y,t[22]=a);let u;t[23]===c?u=t[24]:(u=c?(0,$.jsx)(pt,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(xn,{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=q(`grid transition-[grid-template-rows] duration-200 ease-in-out`,f),t[32]=f,t[33]=p);let m,h;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),h={maxHeight:`7.5em`},t[34]=m,t[35]=h):(m=t[34],h=t[35]);let g;t[36]===v?g=t[37]:(g=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:o,className:m,style:h,children:v})}),t[36]=v,t[37]=g);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 b;return t[41]!==d||t[42]!==_?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[d,_]}),t[41]=d,t[42]=_,t[43]=b):b=t[43],b}if(n.command!==null&&_){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[44]=n.displayName,t[45]=n.toolName,t[46]=e):e=t[46];let r,i;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>d(!0),i=q(s.caption,`font-mono hover:underline break-all cursor-pointer`),t[47]=r,t[48]=i):(r=t[47],i=t[48]);let a;t[49]===n.command?a=t[50]:(a=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:i,children:n.command})}),t[49]=n.command,t[50]=a);let o;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(H,{children:`View output`}),t[51]=o):o=t[51];let c;t[52]===a?c=t[53]:(c=(0,$.jsxs)(kt,{children:[a,o]}),t[52]=a,t[53]=c);let l;t[54]!==c||t[55]!==e?(l=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,c]}),t[54]=c,t[55]=e,t[56]=l):l=t[56];let f;t[57]!==n.command||t[58]!==u||t[59]!==_?(f=(0,$.jsx)(as,{open:u,onOpenChange:d,title:n.command,content:_}),t[57]=n.command,t[58]=u,t[59]=_,t[60]=f):f=t[60];let p;return t[61]!==l||t[62]!==f?(p=(0,$.jsxs)($.Fragment,{children:[l,f]}),t[61]=l,t[62]=f,t[63]=p):p=t[63],p}let e;t[64]!==n.displayName||t[65]!==n.toolName?(e=(0,$.jsx)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[64]=n.displayName,t[65]=n.toolName,t[66]=e):e=t[66];let r;t[67]===n.command?r=t[68]:(r=n.command!==null&&(0,$.jsx)(`code`,{className:q(s.caption,`font-mono break-all rounded bg-muted/60 px-1 py-0.5`),children:n.command}),t[67]=n.command,t[68]=r);let i;return t[69]!==e||t[70]!==r?(i=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[69]=e,t[70]=r,t[71]=i):i=t[71],i}let w;t[72]===c?w=t[73]:(w=()=>l(!c),t[72]=c,t[73]=w);let T;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(T=q(s.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[74]=T):T=t[74];let E;t[75]!==n.activeDisplayName||t[76]!==n.displayName||t[77]!==a||t[78]!==y?(E=a?(0,$.jsxs)($.Fragment,{children:[n.activeDisplayName,y&&(0,$.jsx)(`span`,{className:`ml-2 text-muted-foreground tabular-nums`,children:y})]}):n.displayName,t[75]=n.activeDisplayName,t[76]=n.displayName,t[77]=a,t[78]=y,t[79]=E):E=t[79];let D;t[80]===E?D=t[81]:(D=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:E}),t[80]=E,t[81]=D);let O;t[82]===c?O=t[83]:(O=c?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[82]=c,t[83]=O);let k;t[84]!==D||t[85]!==O||t[86]!==w?(k=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:w,className:T,children:[D,O]})}),t[84]=D,t[85]=O,t[86]=w,t[87]=k):k=t[87];let A;t[88]===n.toolName?A=t[89]:(A=(0,$.jsx)(H,{children:n.toolName}),t[88]=n.toolName,t[89]=A);let j;t[90]!==k||t[91]!==A?(j=(0,$.jsxs)(kt,{children:[k,A]}),t[90]=k,t[91]=A,t[92]=j):j=t[92];let M;t[93]!==n.toolId||t[94]!==n.toolInput||t[95]!==a||t[96]!==c||t[97]!==v?(M=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(`div`,{ref:o,className:q(s.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:is(),children:n.toolInput}):null]}),t[93]=n.toolId,t[94]=n.toolInput,t[95]=a,t[96]=c,t[97]=v,t[98]=M):M=t[98];let N;return t[99]!==j||t[100]!==M?(N=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[j,M]}),t[99]=j,t[100]=M,t[101]=N):N=t[101],N}function gs(e){let t=(0,X.c)(50),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,c]=(0,Y.useState)(!!a),[l,u]=(0,Y.useState)(!1),d=n.fetchUrl,f;t[0]===i?f=t[1]:(f=i?_s(i):null,t[0]=i,t[1]=f);let p=f;if(r){let e;t[2]===o?e=t[3]:(e=()=>c(!o),t[2]=o,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)(ms,{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:q(s.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:q(s.caption,`text-muted-foreground shrink-0`),children:[p.bytes,` bytes · HTTP `,p.code]}),t[10]=p,t[11]=h);let g;t[12]===o?g=t[13]:(g=o?(0,$.jsx)(pt,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(xn,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[12]=o,t[13]=g);let _;t[14]!==o||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":o,children:[f,m,h,g]}),t[14]=o,t[15]=e,t[16]=f,t[17]=m,t[18]=h,t[19]=g,t[20]=_):_=t[20];let v;t[21]!==o||t[22]!==i?(v=o&&i&&(0,$.jsx)(`pre`,{className:q(s.mono,s.caption,`whitespace-pre-wrap break-all rounded bg-muted/40 p-2 max-h-48 overflow-auto`),children:vs(i)}),t[21]=o,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)(ms,{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)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`code`,{className:q(s.mono,s.caption,`break-all`),children:d})}),(0,$.jsx)(H,{children:d})]}),t[31]=d,t[32]=v);let y;t[33]===p?y=t[34]:(y=p&&(0,$.jsxs)(`span`,{className:q(s.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:q(s.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?vs(i):``,t[42]=i,t[43]=S);let C;t[44]!==l||t[45]!==S?(C=(0,$.jsx)(as,{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 _s(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 vs(e){try{let t=JSON.parse(e);if(typeof t.result==`string`)return t.result}catch{}return e}var ys=gr,bs=yr,xs=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=q(`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)(xr,{children:(0,$.jsx)(ur,{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});xs.displayName=ur.displayName;function Ss(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=q(s.compact,`font-mono tabular-nums`,i),t[0]=i,t[1]=a);let o=n===`added`?`+`:`-`,c;return t[2]!==r||t[3]!==a||t[4]!==o?(c=(0,$.jsxs)(`span`,{className:a,children:[o,r]}),t[2]=r,t[3]=a,t[4]=o,t[5]=c):c=t[5],c}function Cs(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=q(s.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 ws(e){let t=(0,X.c)(51),{data:n,inline:r,rootPath:i,onOpenFile:a}=e,[o,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)(ys,{children:[(0,$.jsx)(bs,{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)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),(0,$.jsx)(xs,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:q(s.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)(ms,{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)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:n.hasEditDiff?()=>u(!0):f,className:q(`inline-flex max-w-full items-center gap-2 cursor-pointer`,s.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)(Cs,{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)(Ss,{type:`added`,count:n.editAddedLineCount}),n.editDeletedLineCount===null?null:(0,$.jsx)(Ss,{type:`deleted`,count:n.editDeletedLineCount})]}):null]})}),(0,$.jsx)(H,{children:n.hasEditDiff?`View diff`:n.filePath?No(n.filePath,i)??n.filePath:n.fileDisplayName})]}),n.hasEditDiff&&(0,$.jsx)(Rt,{open:l,onOpenChange:u,children:(0,$.jsxs)(ce,{className:`max-w-2xl h-[80vh] flex flex-col`,children:[(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:(0,$.jsx)(`code`,{className:q(s.caption,`font-mono`),children:No(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)(ss,{oldText:n.editOldText,newText:n.editNewText})})]})})]}):n.path===null?null:(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(s.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(H,{children:n.path})]}),t[10]=n.editAddedLineCount,t[11]=n.editDeletedLineCount,t[12]=n.editNewText,t[13]=n.editOldText,t[14]=n.fileDisplayName,t[15]=n.filePath,t[16]=n.hasEditDiff,t[17]=n.limit,t[18]=n.offset,t[19]=n.path,t[20]=n.toolName,t[21]=l,t[22]=f,t[23]=i,t[24]=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]===o?p=t[29]:(p=()=>c(!o),t[28]=o,t[29]=p);let m;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.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]===o?g=t[34]:(g=o?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[33]=o,t[34]=g);let _;t[35]!==p||t[36]!==h||t[37]!==g?(_=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:p,className:m,children:[h,g]})}),t[35]=p,t[36]=h,t[37]=g,t[38]=_):_=t[38];let v;t[39]===n.toolName?v=t[40]:(v=(0,$.jsx)(H,{children:n.toolName}),t[39]=n.toolName,t[40]=v);let y;t[41]!==_||t[42]!==v?(y=(0,$.jsxs)(kt,{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]!==o?(b=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:is(),children:n.toolInput}):null]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=o,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 Ts(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)(fs,{children:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsxs)(fs,{children:[`/`,n.pattern,`/`]}),n.codeSearchFilePath!==null&&(0,$.jsx)(fs,{children:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(fs,{children:n.codeSearchFileGlob})]}):(0,$.jsxs)($.Fragment,{children:[n.webSearchQuery!==null&&(0,$.jsx)(fs,{children:n.webSearchQuery}),n.pattern!==null&&(0,$.jsx)(fs,{children: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 Es(e){let t=(0,X.c)(68),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,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`;if(r){if(i&&(d||n.toolName===`find`||n.webSearchQuery!==null||n.pattern!==null)){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==a?(e=(0,$.jsx)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[0]=n.displayName,t[1]=n.toolName,t[2]=a,t[3]=e):e=t[3];let r,o;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>u(!0),o=q(s.caption,`font-mono hover:underline break-all cursor-pointer`),t[4]=r,t[5]=o):(r=t[4],o=t[5]);let c;t[6]===f?c=t[7]:(c=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:o,children:f})}),t[6]=f,t[7]=c);let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(H,{children:`View results`}),t[8]=d):d=t[8];let p;t[9]===c?p=t[10]:(p=(0,$.jsxs)(kt,{children:[c,d]}),t[9]=c,t[10]=p);let m;t[11]!==e||t[12]!==p?(m=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,p]}),t[11]=e,t[12]=p,t[13]=m):m=t[13];let h;t[14]!==l||t[15]!==i||t[16]!==f?(h=(0,$.jsx)(as,{open:l,onOpenChange:u,title:f,content:i}),t[14]=l,t[15]=i,t[16]=f,t[17]=h):h=t[17];let g;return t[18]!==m||t[19]!==h?(g=(0,$.jsxs)($.Fragment,{children:[m,h]}),t[18]=m,t[19]=h,t[20]=g):g=t[20],g}let e;t[21]!==n.displayName||t[22]!==n.toolName||t[23]!==a?(e=(0,$.jsx)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[21]=n.displayName,t[22]=n.toolName,t[23]=a,t[24]=e):e=t[24];let r;t[25]===n?r=t[26]:(r=(0,$.jsx)(Ts,{data:n}),t[25]=n,t[26]=r);let o;t[27]===n.lang?o=t[28]:(o=n.lang!==null&&(0,$.jsx)(`span`,{className:q(s.caption,`px-1.5 py-0.5 rounded bg-muted`),children:n.lang}),t[27]=n.lang,t[28]=o);let c;return t[29]!==e||t[30]!==r||t[31]!==o?(c=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r,o]}),t[29]=e,t[30]=r,t[31]=o,t[32]=c):c=t[32],c}let p;t[33]===o?p=t[34]:(p=()=>c(!o),t[33]=o,t[34]=p);let m;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[35]=m):m=t[35];let h;t[36]===a?h=t[37]:(h=a&&(0,$.jsx)(ps,{size:`md`}),t[36]=a,t[37]=h);let g;t[38]===n.displayName?g=t[39]:(g=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[38]=n.displayName,t[39]=g);let _;t[40]!==n.codeSearchFileGlob||t[41]!==n.codeSearchFilePath||t[42]!==n.codeSearchQuery||t[43]!==n.pattern||t[44]!==d?(_=d&&(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(`code`,{className:q(s.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:q(s.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:q(s.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:q(s.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFileGlob})]}),t[40]=n.codeSearchFileGlob,t[41]=n.codeSearchFilePath,t[42]=n.codeSearchQuery,t[43]=n.pattern,t[44]=d,t[45]=_):_=t[45];let v;t[46]===o?v=t[47]:(v=o?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[46]=o,t[47]=v);let y;t[48]!==p||t[49]!==h||t[50]!==g||t[51]!==_||t[52]!==v?(y=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:p,className:m,children:[h,g,_,v]})}),t[48]=p,t[49]=h,t[50]=g,t[51]=_,t[52]=v,t[53]=y):y=t[53];let b;t[54]===n.toolName?b=t[55]:(b=(0,$.jsx)(H,{children:n.toolName}),t[54]=n.toolName,t[55]=b);let x;t[56]!==y||t[57]!==b?(x=(0,$.jsxs)(kt,{children:[y,b]}),t[56]=y,t[57]=b,t[58]=x):x=t[58];let S;t[59]!==n.toolId||t[60]!==n.toolInput||t[61]!==o||t[62]!==d||t[63]!==i?(S=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:is(),children:n.toolInput}):null,d&&i&&(0,$.jsx)(`pre`,{className:is({maxHeight:`64`,className:`mt-2`}),children:i})]}),t[59]=n.toolId,t[60]=n.toolInput,t[61]=o,t[62]=d,t[63]=i,t[64]=S):S=t[64];let C;return t[65]!==S||t[66]!==x?(C=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[x,S]}),t[65]=S,t[66]=x,t[67]=C):C=t[67],C}function Ds(e){let t=(0,X.c)(134),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(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??m??``,g;t[2]===h?g=t[3]:(g=h?jo(h):``,t[2]=h,t[3]=g);let _=g,v=a?_:``,y,b;t[4]===a?(y=t[5],b=t[6]):(y=()=>{a&&!f.current?l(!0):!a&&f.current&&l(!1),f.current=!!a},b=[a],t[4]=a,t[5]=y,t[6]=b),(0,Y.useEffect)(y,b);let x;t[7]!==c||t[8]!==a?(x=()=>{c&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[7]=c,t[8]=a,t[9]=x):x=t[9];let S;if(t[10]!==c||t[11]!==a||t[12]!==v?(S=[c,a,v],t[10]=c,t[11]=a,t[12]=v,t[13]=S):S=t[13],(0,Y.useEffect)(x,S),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)(ms,{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)(us,{name:n.agentName}),t[19]=n.agentName,t[20]=i);let a;t[21]===n.subagentType?a=t[22]:(a=n.subagentType&&(0,$.jsx)(ds,{type:n.subagentType}),t[21]=n.subagentType,t[22]=a);let u;t[23]===c?u=t[24]:(u=c?(0,$.jsx)(pt,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(xn,{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=q(`grid transition-[grid-template-rows] duration-200 ease-in-out`,f),t[32]=f,t[33]=p);let m,h;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto`),h={maxHeight:`7.5em`},t[34]=m,t[35]=h):(m=t[34],h=t[35]);let g=v||`Running subagent...`,_;t[36]===g?_=t[37]:(_=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:o,className:m,style:h,children:g})}),t[36]=g,t[37]=_);let y;t[38]!==p||t[39]!==_?(y=(0,$.jsx)(`div`,{className:p,children:_}),t[38]=p,t[39]=_,t[40]=y):y=t[40];let b;return t[41]!==d||t[42]!==y?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[d,y]}),t[41]=d,t[42]=y,t[43]=b):b=t[43],b}if(_){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(bs,{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)(ms,{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=q(s.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)(xs,{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 c;t[56]!==o||t[57]!==e?(c=(0,$.jsxs)(ys,{children:[e,o]}),t[56]=o,t[57]=e,t[58]=c):c=t[58];let l;t[59]===n.agentName?l=t[60]:(l=n.agentName&&(0,$.jsx)(us,{name:n.agentName}),t[59]=n.agentName,t[60]=l);let f;t[61]===n.subagentType?f=t[62]:(f=n.subagentType&&(0,$.jsx)(ds,{type:n.subagentType}),t[61]=n.subagentType,t[62]=f);let p;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:q(s.caption,`text-muted-foreground hover:underline`),children:`View output`})}),(0,$.jsx)(H,{children:`View subagent output`})]}),t[63]=p):p=t[63];let m;t[64]!==c||t[65]!==l||t[66]!==f?(m=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[c,l,f,p]}),t[64]=c,t[65]=l,t[66]=f,t[67]=m):m=t[67];let h;t[68]!==n.displayName||t[69]!==u||t[70]!==_?(h=(0,$.jsx)(as,{open:u,onOpenChange:d,title:n.displayName,content:_}),t[68]=n.displayName,t[69]=u,t[70]=_,t[71]=h):h=t[71];let g;return t[72]!==m||t[73]!==h?(g=(0,$.jsxs)($.Fragment,{children:[m,h]}),t[72]=m,t[73]=h,t[74]=g):g=t[74],g}let e;t[75]!==n.displayName||t[76]!==n.toolName?(e=(0,$.jsx)(bs,{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)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),t[75]=n.displayName,t[76]=n.toolName,t[77]=e):e=t[77];let r;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(s.caption,`space-y-2`),t[78]=r):r=t[78];let i;t[79]===n.toolId?i=t[80]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[79]=n.toolId,t[80]=i);let f;t[81]!==n.prompt||t[82]!==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[81]=n.prompt,t[82]=n.toolInput,t[83]=f):f=t[83];let p;t[84]!==f||t[85]!==i?(p=(0,$.jsx)(xs,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,f]})}),t[84]=f,t[85]=i,t[86]=p):p=t[86];let m;t[87]!==p||t[88]!==e?(m=(0,$.jsxs)(ys,{children:[e,p]}),t[87]=p,t[88]=e,t[89]=m):m=t[89];let h;t[90]===n.agentName?h=t[91]:(h=n.agentName&&(0,$.jsx)(us,{name:n.agentName}),t[90]=n.agentName,t[91]=h);let g;t[92]===n.subagentType?g=t[93]:(g=n.subagentType&&(0,$.jsx)(ds,{type:n.subagentType}),t[92]=n.subagentType,t[93]=g);let y;return t[94]!==m||t[95]!==h||t[96]!==g?(y=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[m,h,g]}),t[94]=m,t[95]=h,t[96]=g,t[97]=y):y=t[97],y}let C;t[98]===c?C=t[99]:(C=()=>l(!c),t[98]=c,t[99]=C);let w;t[100]===Symbol.for(`react.memo_cache_sentinel`)?(w=q(s.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[100]=w):w=t[100];let T;t[101]===a?T=t[102]:(T=a&&(0,$.jsx)(ps,{size:`md`}),t[101]=a,t[102]=T);let E=a?n.activeDisplayName:n.displayName,D;t[103]===E?D=t[104]:(D=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:E}),t[103]=E,t[104]=D);let O;t[105]===n.agentName?O=t[106]:(O=n.agentName&&(0,$.jsx)(us,{name:n.agentName}),t[105]=n.agentName,t[106]=O);let k;t[107]===n.subagentType?k=t[108]:(k=n.subagentType&&(0,$.jsx)(ds,{type:n.subagentType}),t[107]=n.subagentType,t[108]=k);let A;t[109]===c?A=t[110]:(A=c?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[109]=c,t[110]=A);let j;t[111]!==D||t[112]!==O||t[113]!==k||t[114]!==A||t[115]!==C||t[116]!==T?(j=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:C,className:w,children:[T,D,O,k,A]})}),t[111]=D,t[112]=O,t[113]=k,t[114]=A,t[115]=C,t[116]=T,t[117]=j):j=t[117];let M;t[118]===n.toolName?M=t[119]:(M=(0,$.jsx)(H,{children:n.toolName}),t[118]=n.toolName,t[119]=M);let N;t[120]!==j||t[121]!==M?(N=(0,$.jsxs)(kt,{children:[j,M]}),t[120]=j,t[121]=M,t[122]=N):N=t[122];let P;t[123]!==n.prompt||t[124]!==n.toolId||t[125]!==n.toolInput||t[126]!==_||t[127]!==c||t[128]!==a||t[129]!==v?(P=c&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(`div`,{ref:o,className:q(s.caption,`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto`),style:{maxHeight:`7.5em`},children:v||`Running subagent...`}):n.prompt?(0,$.jsx)(`div`,{className:is({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:is(),children:n.toolInput}):_?(0,$.jsx)(`div`,{className:is({maxHeight:`64`,padding:`3`,leading:!0}),children:_}):null]}),t[123]=n.prompt,t[124]=n.toolId,t[125]=n.toolInput,t[126]=_,t[127]=c,t[128]=a,t[129]=v,t[130]=P):P=t[130];let F;return t[131]!==N||t[132]!==P?(F=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[N,P]}),t[131]=N,t[132]=P,t[133]=F):F=t[133],F}function Os(e){let t=(0,X.c)(26),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.useState)(!1);if(r)return null;let c;t[0]===a?c=t[1]:(c=()=>o(!a),t[0]=a,t[1]=c);let l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=q(s.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)(ps,{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)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{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)(Fn,{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)(H,{children:n.toolName}),t[14]=n.toolName,t[15]=m);let h;t[16]!==p||t[17]!==m?(h=(0,$.jsxs)(kt,{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:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:is(),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 ks(e){let t=(0,X.c)(35),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.useState)(!1);if(r){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==i?(e=(0,$.jsx)(ms,{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)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(s.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.imageGenPrompt})}),(0,$.jsx)(H,{children:n.imageGenPrompt})]}),t[4]=n.imageGenPrompt,t[5]=r);let a;return t[6]!==e||t[7]!==r?(a=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[6]=e,t[7]=r,t[8]=a):a=t[8],a}let c;t[9]===a?c=t[10]:(c=()=>o(!a),t[9]=a,t[10]=c);let l;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(l=q(s.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)(ps,{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)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{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)(Fn,{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)(H,{children:n.toolName}),t[23]=n.toolName,t[24]=m);let h;t[25]!==p||t[26]!==m?(h=(0,$.jsxs)(kt,{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:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:is(),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 As(e){if(!e)return null;try{let t=JSON.parse(e);return qa(t,{content:e,...t})}catch{return qa(e,{content:e})}}function js(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`image`}function Ms(e){let t=(0,X.c)(54),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(Ns),f,p;t[0]===i?(f=t[1],p=t[2]):(f=As(i),p=f?js(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)(ms,{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)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(s.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.findImagesQuery})}),(0,$.jsx)(H,{children:n.findImagesQuery})]}),t[7]=n.findImagesQuery,t[8]=f,t[9]=r):r=t[9];let i;t[10]!==f||t[11]!==m?(i=f&&m&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:q(s.caption,`hover:underline`),children:[`Found `,m]})}),(0,$.jsx)(H,{children:`View image`})]}),t[10]=f,t[11]=m,t[12]=i):i=t[12];let 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 c;t[17]!==l||t[18]!==f||t[19]!==m||t[20]!==d?(c=f&&(0,$.jsx)(Rt,{open:l,onOpenChange:u,children:(0,$.jsxs)(ce,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(E,{children:(0,$.jsxs)(I,{children:[`Found `,m]})}),(0,$.jsx)(Ga,{imageUrl:f.imageUrl,imageData:f.imageData,threadId:d,alt:m??`Found image`})]})}),t[17]=l,t[18]=f,t[19]=m,t[20]=d,t[21]=c):c=t[21];let p;return t[22]!==o||t[23]!==c?(p=(0,$.jsxs)($.Fragment,{children:[o,c]}),t[22]=o,t[23]=c,t[24]=p):p=t[24],p}let h;t[25]===o?h=t[26]:(h=()=>c(!o),t[25]=o,t[26]=h);let g;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(g=q(s.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)(ps,{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]===o?b=t[33]:(b=o?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[32]=o,t[33]=b);let x;t[34]!==h||t[35]!==_||t[36]!==y||t[37]!==b?(x=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:h,className:g,children:[_,y,b]})}),t[34]=h,t[35]=_,t[36]=y,t[37]=b,t[38]=x):x=t[38];let S;t[39]===n.toolName?S=t[40]:(S=(0,$.jsx)(H,{children:n.toolName}),t[39]=n.toolName,t[40]=S);let C;t[41]!==x||t[42]!==S?(C=(0,$.jsxs)(kt,{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]!==o||t[47]!==f||t[48]!==m||t[49]!==d?(w=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:is(),children:n.toolInput}):null,f&&(0,$.jsx)(Ga,{imageUrl:f.imageUrl,imageData:f.imageData,threadId:d,alt:m??`Found image`})]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=o,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 Ns(e){return e.selectedThreadId}function Ps(e){if(!e)return null;try{let t=JSON.parse(e);return t.action===`screenshot`?qa(t,{content:e,...t}):null}catch{return null}}function Fs(e){return e.savedPath?e.savedPath.split(`/`).pop()??e.savedPath:`screenshot`}function Is(e){let t=(0,X.c)(85),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(Ls),f;t[0]===n.inputObj?f=t[1]:(f=Ro(n.inputObj),t[0]=n.inputObj,t[1]=f);let p=f,m;t[2]===n.inputObj?m=t[3]:(m=Po(n.inputObj),t[2]=n.inputObj,t[3]=m);let h=m,g;t[4]===i?g=t[5]:(g=i?Bo(i):``,t[4]=i,t[5]=g);let _=g,v,y;t[6]===i?(v=t[7],y=t[8]):(v=Ps(i),y=v?Fs(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)(ms,{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)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:q(s.caption,`hover:underline`),children:[`Screenshot `,b]})}),(0,$.jsx)(H,{children:`View screenshot`})]}):i?(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:q(s.caption,`font-mono hover:underline break-all cursor-pointer`),children:p})}),(0,$.jsx)(H,{children:`View results`})]}):(0,$.jsx)(`span`,{className:q(s.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 c;t[21]!==l||t[22]!==h||t[23]!==p||t[24]!==_||t[25]!==i||t[26]!==b||t[27]!==v||t[28]!==d?(c=v?(0,$.jsx)(Rt,{open:l,onOpenChange:u,children:(0,$.jsxs)(ce,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(E,{children:(0,$.jsxs)(I,{children:[`Screenshot `,b]})}),(0,$.jsx)(Ga,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`})]})}):i&&(0,$.jsx)(os,{open:l,onOpenChange:u,title:p,requestContent:h,responseContent:_}),t[21]=l,t[22]=h,t[23]=p,t[24]=_,t[25]=i,t[26]=b,t[27]=v,t[28]=d,t[29]=c):c=t[29];let f;return t[30]!==o||t[31]!==c?(f=(0,$.jsxs)($.Fragment,{children:[o,c]}),t[30]=o,t[31]=c,t[32]=f):f=t[32],f}let x;t[33]===o?x=t[34]:(x=()=>c(!o),t[33]=o,t[34]=x);let S;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(S=q(s.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)(ps,{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 D;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(D=q(s.caption,`font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]`),t[40]=D):D=t[40];let O;t[41]===p?O=t[42]:(O=(0,$.jsx)(`span`,{className:D,children:p}),t[41]=p,t[42]=O);let k;t[43]!==i||t[44]!==v?(k=i&&!v&&(0,$.jsx)(`button`,{type:`button`,className:q(s.caption,`text-brand hover:underline shrink-0`),onClick:e=>{e.stopPropagation(),u(!0)},children:`View results`}),t[43]=i,t[44]=v,t[45]=k):k=t[45];let A;t[46]===v?A=t[47]:(A=v&&(0,$.jsx)(`button`,{type:`button`,className:q(s.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]===o?j=t[49]:(j=o?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[48]=o,t[49]=j);let M;t[50]!==O||t[51]!==k||t[52]!==A||t[53]!==j||t[54]!==x||t[55]!==C||t[56]!==T?(M=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:x,className:S,children:[C,T,O,k,A,j]})}),t[50]=O,t[51]=k,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)(H,{children:n.toolName}),t[58]=n.toolName,t[59]=N);let P;t[60]!==M||t[61]!==N?(P=(0,$.jsxs)(kt,{children:[M,N]}),t[60]=M,t[61]=N,t[62]=P):P=t[62];let F;t[63]!==n.toolId||t[64]!==o||t[65]!==h||t[66]!==_||t[67]!==i||t[68]!==b||t[69]!==v||t[70]!==d?(F=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border space-y-2`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground font-mono`),children:[`ID: `,n.toolId]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:q(s.compact,`text-muted-foreground mb-1`),children:`Request`}),(0,$.jsx)(`pre`,{className:is(),children:h})]}),v?(0,$.jsx)(Ga,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`}):i&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:q(s.compact,`text-muted-foreground mb-1`),children:`Response`}),(0,$.jsx)(`pre`,{className:is({maxHeight:`64`}),children:_})]})]}),t[63]=n.toolId,t[64]=o,t[65]=h,t[66]=_,t[67]=i,t[68]=b,t[69]=v,t[70]=d,t[71]=F):F=t[71];let L;t[72]!==l||t[73]!==h||t[74]!==p||t[75]!==_||t[76]!==i||t[77]!==b||t[78]!==v||t[79]!==d?(L=v?(0,$.jsx)(Rt,{open:l,onOpenChange:u,children:(0,$.jsxs)(ce,{className:`max-w-3xl max-h-[85vh] flex flex-col overflow-auto`,children:[(0,$.jsx)(E,{children:(0,$.jsxs)(I,{children:[`Screenshot `,b]})}),(0,$.jsx)(Ga,{imageUrl:v.imageUrl,imageData:v.imageData,threadId:d,alt:b??`Browser screenshot`})]})}):i&&(0,$.jsx)(os,{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]=L):L=t[80];let R;return t[81]!==P||t[82]!==F||t[83]!==L?(R=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[P,F,L]}),t[81]=P,t[82]=F,t[83]=L,t[84]=R):R=t[84],R}function Ls(e){return e.selectedThreadId}function Rs(e){let t=(0,X.c)(10),{summary:n,fullSummary:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=q(s.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 c;t[3]===o?c=t[4]:(c=(0,$.jsx)(Fn,{asChild:!0,children:o}),t[3]=o,t[4]=c);let l;t[5]===r?l=t[6]:(l=(0,$.jsx)(H,{className:`max-w-md break-all font-mono`,children:r}),t[5]=r,t[6]=l);let u;return t[7]!==c||t[8]!==l?(u=(0,$.jsxs)(kt,{children:[c,l]}),t[7]=c,t[8]=l,t[9]=u):u=t[9],u}function zs(e){let t=(0,X.c)(52),{data:n,inline:r,isActive:i}=e,[a,o]=(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?Lo(n.inputObj,32,e):null,l=n.prompt===null?Lo(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)(ys,{children:[(0,$.jsx)(bs,{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)(ms,{toolName:n.toolName,displayName:n.displayName,isActive:i,muted:!1})})})}),(0,$.jsx)(xs,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:q(s.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)(ms,{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)(Rs,{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)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(s.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(H,{children:n.path})]}),t[16]=n.path,t[17]=o);let l;return t[18]!==r||t[19]!==a||t[20]!==o?(l=(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]=l):l=t[21],l}let d;t[22]===a?d=t[23]:(d=()=>o(!a),t[22]=a,t[23]=d);let f;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(f=q(s.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)(ps,{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:q(s.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)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{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)(Fn,{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)(H,{children:n.toolName}),t[39]=n.toolName,t[40]=v);let y;t[41]!==_||t[42]!==v?(y=(0,$.jsxs)(kt,{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:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:is({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:is(),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 Bs(e){let t=(0,X.c)(51),{block:n,inline:r,resultContent:i,isActive:a}=e,{setPendingExplorerPath:o,setActiveMainTab:s}=wo(),c=Q(Vs),l=Go(n,c),u=!!a,d;t[0]!==s||t[1]!==o?(d=function(e){o(e),s(`explorer`)},t[0]=s,t[1]=o,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)(hs,{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)(gs,{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)(ws,{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)(Es,{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)(Ds,{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)(Os,{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)(ks,{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)(Ms,{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)(Is,{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)(zs,{data:l,inline:r,isActive:u}),t[47]=l,t[48]=r,t[49]=u,t[50]=e):e=t[50],e}}}function Vs(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Hs=(0,Y.createContext)({todos:[],setTodos:()=>{}});function Us(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)(Hs.Provider,{value:f,children:n}),t[7]=n,t[8]=f,t[9]=p):p=t[9],p}function Ws(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 Gs(e){let t=(0,X.c)(5),{todos:n,sequence:r}=e,{setTodos:i}=(0,Y.useContext)(Hs),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 Ks(e){let t=(0,X.c)(79),{block:n,inline:r,sequence:i}=e,a=i===void 0?0:i,[o,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=Q(Js),f=Q(qs),p=n.toolName??`Unknown Tool`,m=n.toolCallId??`unknown`,h=n,g=n.result??h.content,_;t[0]!==h||t[1]!==p?(_=p===`todo`?Ws(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`?qa(g,h):null,S=No(Wo(g),d),!(S.length>0)&&v===null&&!b){T=null;break bb0}if(y=Mo(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=Mo(p),t[22]=p,t[23]=e),y=`${e} (no result)`}if(b){let e=b.savedPath?No(b.savedPath.split(`/`).pop()??b.savedPath,d):null;y=e?`Found ${e}`:`Found image`}if(y=No(y,d),v!==null){let e;t[24]!==a||t[25]!==v?(e=(0,$.jsx)(Gs,{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=Ka(g)??Ka(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)(Ga,{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(`
|
|
22
|
+
`):[],w=x?C.slice(0,3).join(`
|
|
23
|
+
`):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 D=w,O=x&&C.length>3;if(x){let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(s.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]!==O||t[40]!==D||t[41]!==S||t[42]!==C?(r=S&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[O?(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`pre`,{className:q(s.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:[D,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
|
|
24
|
+
`,`...`]})]})}),(0,$.jsx)(H,{children:`Click to see full output`})]}):(0,$.jsx)(`pre`,{className:q(s.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2`),children:D}),O&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:q(s.caption,`mt-1 text-brand hover:underline`),children:[`Show full output (`,C.length,` lines)`]})]}),t[39]=O,t[40]=D,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]!==O||t[49]!==S?(a=O&&(0,$.jsx)(Rt,{open:l,onOpenChange:u,children:(0,$.jsxs)(ce,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:`Full Output`})}),(0,$.jsx)(`pre`,{className:q(s.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`),children:S})]})}),t[47]=l,t[48]=O,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 k;t[54]===o?k=t[55]:(k=()=>c(!o),t[54]=o,t[55]=k);let A;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(A=q(s.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]===o?M=t[60]:(M=o?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[59]=o,t[60]=M);let N;t[61]!==k||t[62]!==j||t[63]!==M?(N=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:k,className:A,children:[j,M]})}),t[61]=k,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)(H,{children:P}),t[65]=P,t[66]=F);let L;t[67]!==F||t[68]!==N?(L=(0,$.jsxs)(kt,{children:[N,F]}),t[67]=F,t[68]=N,t[69]=L):L=t[69];let R;t[70]!==o||t[71]!==b||t[72]!==S||t[73]!==f||t[74]!==m?(R=o&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,`text-muted-foreground mb-2 font-mono`),children:[`Call ID: `,m]}),b&&(0,$.jsx)(Ga,{imageUrl:b.imageUrl,imageData:b.imageData,threadId:f}),S&&!b&&(0,$.jsx)(`pre`,{className:q(s.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`),children:S})]}),t[70]=o,t[71]=b,t[72]=S,t[73]=f,t[74]=m,t[75]=R):R=t[75];let ee;return t[76]!==L||t[77]!==R?(ee=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[L,R]}),t[76]=L,t[77]=R,t[78]=ee):ee=t[78],ee}function qs(e){return e.selectedThreadId}function Js(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Ys=Pr(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`]}),Xs=function(e){let t=(0,X.c)(34),{text:n,isStreaming:r,label:i}=e,a=n===void 0?``:n,o=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)(o),h=(0,Y.useRef)(o),g,_;t[1]===o?(g=t[2],_=t[3]):(g=()=>{o&&!h.current?(u.current=Date.now(),f(0),m(!0)):o?m(!0):h.current&&!o&&(f(Date.now()-u.current),m(!1)),h.current=o},_=[o],t[1]=o,t[2]=g,t[3]=_),(0,Y.useEffect)(g,_);let v;t[4]!==p||t[5]!==o?(v=()=>{p&&o&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},t[4]=p,t[5]=o,t[6]=v):v=t[6];let y;if(t[7]!==p||t[8]!==o||t[9]!==a?(y=[a,p,o],t[7]=p,t[8]=o,t[9]=a,t[10]=y):y=t[10],(0,Y.useEffect)(v,y),!a&&!o)return null;let b=!o&&i===`Validated`,x;t[11]!==d||t[12]!==o||t[13]!==i?(x=Qs(o,i,d),t[11]=d,t[12]=o,t[13]=i,t[14]=x):x=t[14];let S=x,C;t[15]===a?C=t[16]:(C=a?jo(a):``,t[15]=a,t[16]=C);let w=C,T;t[17]===p?T=t[18]:(T=()=>m(!p),t[17]=p,t[18]=T);let E;t[19]===b?E=t[20]:(E=b?(0,$.jsx)(Mt,{className:`h-3.5 w-3.5 shrink-0 text-green-600`}):null,t[19]=b,t[20]=E);let D=p?`grid-rows-[1fr]`:`grid-rows-[0fr]`,O;t[21]===D?O=t[22]:(O=[`grid transition-[grid-template-rows] duration-200 ease-in-out`,D],t[21]=D,t[22]=O);let k=O.join(` `),A,j;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(A=q(s.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto`),j={maxHeight:`7.5em`},t[23]=A,t[24]=j):(A=t[23],j=t[24]);let M;t[25]===w?M=t[26]:(M=(0,$.jsx)(`div`,{ref:c,className:A,style:j,children:w}),t[25]=w,t[26]=M);let N;return t[27]!==p||t[28]!==S||t[29]!==T||t[30]!==E||t[31]!==k||t[32]!==M?(N=(0,$.jsx)(Ys,{v0:T,v1:p,v2:E,v3:s.caption,v4:S,v5:k,v6:M}),t[27]=p,t[28]=S,t[29]=T,t[30]=E,t[31]=k,t[32]=M,t[33]=N):N=t[33],N};function Zs(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 Qs(e,t,n){return e?t===`MCP`?`Connecting MCP servers...`:t===`Validating`?`Validating...`:`Thinking...`:t===`MCP`?`MCP setup complete.`:t===`Validated`?`Validated`:n<=0?`Thought complete.`:`Thought for ${Zs(n)}.`}function $s(e){let t=(0,X.c)(67),{toolCall:n,className:r}=e,i=Xi(),[a,o]=(0,Y.useState)(!1),c;t[0]===n.id?c=t[1]:(c=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=c);let l=Q(c),u=Q(rc),d=Q(nc),f;t[2]!==n.activeDisplayName||t[3]!==n.name?(f=n.activeDisplayName??b(n.name),t[2]=n.activeDisplayName,t[3]=n.name,t[4]=f):f=t[4];let p=f;if(!u)return null;let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{o(tc)},t[5]=m):m=t[5];let h=m,g;t[6]!==i||t[7]!==d||t[8]!==n.id||t[9]!==n.name?(g=()=>{i({type: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:d})},t[6]=i,t[7]=d,t[8]=n.id,t[9]=n.name,t[10]=g):g=t[10];let _=g,v=ec,y=n.name===`bash`&&typeof n.input?.command==`string`?n.input.command:null,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=!y&&typeof n.input?.description==`string`?n.input.description:null,w;t[11]===r?w=t[12]:(w=q(`overflow-hidden mb-2`,r),t[11]=r,t[12]=w);let T;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(ps,{}),t[13]=T):T=t[13];let E;t[14]===p?E=t[15]:(E=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[T,(0,$.jsx)(`span`,{className:s.bodyMuted,children:p})]})}),t[14]=p,t[15]=E);let D;t[16]===n.name?D=t[17]:(D=(0,$.jsx)(H,{children:n.name}),t[16]=n.name,t[17]=D);let O;t[18]!==E||t[19]!==D?(O=(0,$.jsxs)(kt,{children:[E,D]}),t[18]=E,t[19]=D,t[20]=O):O=t[20];let k;t[21]===y?k=t[22]:(k=y!==null&&(0,$.jsx)(`code`,{className:q(s.mono,s.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:y}),t[21]=y,t[22]=k);let A;t[23]===x?A=t[24]:(A=x!==null&&(0,$.jsx)(`code`,{className:q(s.mono,s.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:x.length>60?`${x.slice(0,59)}…`:x}),t[23]=x,t[24]=A);let j;t[25]===S?j=t[26]:(j=S!==null&&(0,$.jsx)(`code`,{className:q(s.mono,s.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:S.length>60?`${S.slice(0,59)}…`:S}),t[25]=S,t[26]=j);let M;t[27]===C?M=t[28]:(M=C!==null&&(0,$.jsx)(`span`,{className:s.bodyMuted,children:C}),t[27]=C,t[28]=M);let N;t[29]!==y||t[30]!==C||t[31]!==x||t[32]!==S?(N=!y&&!x&&!S&&!C&&(0,$.jsx)(`span`,{className:s.bodyMuted,children:`running`}),t[29]=y,t[30]=C,t[31]=x,t[32]=S,t[33]=N):N=t[33];let P;t[34]===a?P=t[35]:(P=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:h,className:`p-1 hover:bg-muted/50 rounded transition-colors`,children:a?(0,$.jsx)(ot,{className:`h-3 w-3`}):(0,$.jsx)(pt,{className:`h-3 w-3`})})}),t[34]=a,t[35]=P);let F=a?`Collapse`:`Expand`,I;t[36]===F?I=t[37]:(I=(0,$.jsx)(H,{children:F}),t[36]=F,t[37]=I);let L;t[38]!==P||t[39]!==I?(L=(0,$.jsxs)(kt,{children:[P,I]}),t[38]=P,t[39]=I,t[40]=L):L=t[40];let R;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(z,{className:`h-3 w-3`}),t[41]=R):R=t[41];let ee;t[42]===_?ee=t[43]:(ee=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:_,className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,children:R})}),t[42]=_,t[43]=ee);let te;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(H,{className:`bg-red-600 text-white border-red-600`,children:`Stop this process`}),t[44]=te):te=t[44];let ne;t[45]===ee?ne=t[46]:(ne=(0,$.jsxs)(kt,{children:[ee,te]}),t[45]=ee,t[46]=ne);let re;t[47]!==L||t[48]!==ne?(re=(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[L,ne]}),t[47]=L,t[48]=ne,t[49]=re):re=t[49];let ie;t[50]!==k||t[51]!==A||t[52]!==j||t[53]!==M||t[54]!==N||t[55]!==re||t[56]!==O?(ie=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[O,k,A,j,M,N,re]}),t[50]=k,t[51]=A,t[52]=j,t[53]=M,t[54]=N,t[55]=re,t[56]=O,t[57]=ie):ie=t[57];let ae;t[58]!==a||t[59]!==n.id||t[60]!==n.input||t[61]!==l?(ae=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border min-h-[8rem] overflow-auto`,children:[(0,$.jsxs)(`div`,{className:q(s.compact,s.bodyMuted,`mb-2 font-mono`),children:[`ID: `,n.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:q(s.compact,s.label,`text-muted-foreground mb-1`),children:`Input:`}),(0,$.jsx)(`pre`,{className:is({className:`border border-border`}),children:v(n.input)})]}),l&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:q(s.compact,s.label,`text-muted-foreground mb-1`),children:`Progress:`}),(0,$.jsxs)(`div`,{className:q(s.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:q(s.mono,`text-green-700 dark:text-green-300`),children:l.delta}),l.partial?.content?.[0]?.arguments&&typeof l.partial.content[0].arguments==`object`&&`content`in l.partial.content[0].arguments&&typeof l.partial.content[0].arguments.content==`string`&&(0,$.jsxs)(`div`,{className:q(s.mono,`mt-1 text-green-600 dark:text-green-400`),children:[`Building: `,l.partial.content[0].arguments.content.slice(-50),l.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,$.jsxs)(`div`,{className:q(s.compact,`flex items-center gap-1.5 text-muted-foreground`),children:[(0,$.jsx)(ps,{}),`Executing`,l&&` with progress`,`...`]})]}),t[58]=a,t[59]=n.id,t[60]=n.input,t[61]=l,t[62]=ae):ae=t[62];let oe;return t[63]!==ie||t[64]!==ae||t[65]!==w?(oe=(0,$.jsxs)(`div`,{className:w,children:[ie,ae]}),t[63]=ie,t[64]=ae,t[65]=w,t[66]=oe):oe=t[66],oe}function ec(e){return JSON.stringify(e,null,2)}function tc(e){return!e}function nc(e){return e.streamingSegments}function rc(e){return e.isStreaming}function ic(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 ac(e){return e.type!==`subagent_event`||!e.subagentEvent?null:oc(e.subagentEvent)}function oc(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?sc(e.content):null;case`shell_permission`:{let t=e.shellPermission?.command?.trim();return t?`\n⏳ Waiting for shell approval: ${t}\n`:`
|
|
25
|
+
⏳ Waiting for shell approval…
|
|
26
|
+
`}case`web_fetch_permission`:{let t=e.webFetchPermission?.hostname?.trim();return t?`\n⏳ Waiting for approval to fetch ${t}\n`:`
|
|
27
|
+
⏳ Waiting for web fetch approval…
|
|
28
|
+
`}case`error`:return e.content?`\n${e.content}`:null;default:return null}}function sc(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().slice(0,120):JSON.stringify(e.content).slice(0,120);t&&n.push(`✓ ${t}${t.length>=120?`…`:``}\n`)}return n.length>0?n.join(``):null}catch{return null}}var cc=Pr(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`]}),lc=Pr(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 gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:e.v5,onChange:e.v6,onKeyDown:e.v7,placeholder:e.v8,disabled:e.v9,className:`flex-1 rounded-md border border-border bg-background px-3 py-1.5 text-base text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`}),(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`]}),uc=function(e){let t=(0,X.c)(54),{toolCallId:n,question:r,options:i,context:a,answeredText:o,answeredLabel:c}=e,[l,u]=(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 S;t[3]!==h||t[4]!==n?(S=async e=>{if(!(!e.trim()||h)){g(!0);try{await ft(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]=S):S=t[5];let C=S,w;t[6]!==C||t[7]!==h||t[8]!==d?(w=e=>{d||h||(v(e),C(e))},t[6]=C,t[7]=h,t[8]=d,t[9]=w):w=t[9];let T=w,E;t[10]!==l||t[11]!==C||t[12]!==h||t[13]!==d?(E=()=>{if(d||h)return;let e=l.trim();e&&C(e)},t[10]=l,t[11]=C,t[12]=h,t[13]=d,t[14]=E):E=t[14];let D=E,O;t[15]===D?O=t[16]:(O=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},t[15]=D,t[16]=O);let k=O;if(d){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(An,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=q(s.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)(ao,{content:r}),t[19]=r,t[20]=i);let o;t[21]===a?o=t[22]:(o=a&&(0,$.jsx)(`p`,{className:q(s.bodyMuted,`mt-1`),children:a}),t[21]=a,t[22]=o);let l=c??`You answered`,u;return t[23]!==p||t[24]!==o||t[25]!==l||t[26]!==i?(u=(0,$.jsx)(cc,{v0:e,v1:n,v2:i,v3:o,v4:s.bodyMuted,v5:l,v6:p}),t[23]=p,t[24]=o,t[25]=l,t[26]=i,t[27]=u):u=t[27],u}let A,j;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(Kt,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),j=q(s.label,`text-foreground`),t[28]=A,t[29]=j):(A=t[28],j=t[29]);let M;t[30]===r?M=t[31]:(M=(0,$.jsx)(ao,{content:r}),t[30]=r,t[31]=M);let N;t[32]===a?N=t[33]:(N=a&&(0,$.jsx)(`p`,{className:q(s.bodyMuted,`mt-1`),children:a}),t[32]=a,t[33]=N);let P;t[34]!==T||t[35]!==h||t[36]!==i||t[37]!==_?(P=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:()=>T(e),disabled:h,className:q(`rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50 flex items-center gap-1.5`,s.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)(An,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[34]=T,t[35]=h,t[36]=i,t[37]=_,t[38]=P):P=t[38];let F;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>u(e.target.value),t[39]=F):F=t[39];let I=i?.length?`Or type a custom answer...`:`Type your answer...`,L;t[40]!==l||t[41]!==h?(L=h||!l.trim(),t[40]=l,t[41]=h,t[42]=L):L=t[42];let R;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(x,{className:`h-3 w-3`}),t[43]=R):R=t[43];let ee;return t[44]!==l||t[45]!==D||t[46]!==k||t[47]!==h||t[48]!==N||t[49]!==P||t[50]!==I||t[51]!==L||t[52]!==M?(ee=(0,$.jsx)(lc,{v0:A,v1:j,v2:M,v3:N,v4:P,v5:l,v6:F,v7:k,v8:I,v9:h,v10:D,v11:L,v12:R}),t[44]=l,t[45]=D,t[46]=k,t[47]=h,t[48]=N,t[49]=P,t[50]=I,t[51]=L,t[52]=M,t[53]=ee):ee=t[53],ee},dc=Kn,fc=Ln,pc=ar,mc=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:i,inset:a,children:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let c;n[5]!==i||n[6]!==a?(c=q(q(s.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)(xn,{className:`ml-auto`}),n[8]=l):l=n[8];let u;return n[9]!==r||n[10]!==o||n[11]!==t||n[12]!==c?(u=(0,$.jsxs)($n,{ref:t,className:c,...o,children:[r,l]}),n[9]=r,n[10]=o,n[11]=t,n[12]=c,n[13]=u):u=n[13],u});mc.displayName=$n.displayName;var hc=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=q(`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)(sr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});hc.displayName=sr.displayName;var gc=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=q(`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)(qn,{children:(0,$.jsx)(Wn,{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});gc.displayName=Wn.displayName;var _c=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=q(q(s.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 c;return n[7]!==a||n[8]!==t||n[9]!==o?(c=(0,$.jsx)(nr,{ref:t,className:o,...a}),n[7]=a,n[8]=t,n[9]=o,n[10]=c):c=n[10],c});_c.displayName=nr.displayName;var vc=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 c;n[5]===a?c=n[6]:(c=q(q(s.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]=c);let l;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(ir,{children:(0,$.jsx)(An,{className:`h-4 w-4`})})}),n[7]=l):l=n[7];let u;return n[8]!==r||n[9]!==i||n[10]!==o||n[11]!==t||n[12]!==c?(u=(0,$.jsxs)(rr,{ref:t,className:c,checked:r,...o,children:[l,i]}),n[8]=r,n[9]=i,n[10]=o,n[11]=t,n[12]=c,n[13]=u):u=n[13],u});vc.displayName=rr.displayName;var yc=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=q(q(s.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 c;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(ir,{children:(0,$.jsx)(tn,{className:`h-2 w-2 fill-current`})})}),n[6]=c):c=n[6];let l;return n[7]!==r||n[8]!==a||n[9]!==t||n[10]!==o?(l=(0,$.jsxs)(vr,{ref:t,className:o,...a,children:[c,r]}),n[7]=r,n[8]=a,n[9]=t,n[10]=o,n[11]=l):l=n[11],l});yc.displayName=vr.displayName;var bc=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`,c;n[4]!==r||n[5]!==o?(c=q(s.body,`px-2 py-1.5 font-semibold`,o,r),n[4]=r,n[5]=o,n[6]=c):c=n[6];let l;return n[7]!==a||n[8]!==t||n[9]!==c?(l=(0,$.jsx)(Un,{ref:t,className:c,...a}),n[7]=a,n[8]=t,n[9]=c,n[10]=l):l=n[10],l});bc.displayName=Un.displayName;var xc=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=q(`-mx-1 my-1 h-px bg-muted`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(or,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});xc.displayName=or.displayName;var Sc=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=q(s.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};Sc.displayName=`DropdownMenuShortcut`;var Cc=Pr(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:`Shell command permission`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3})]})]}),(0,$.jsx)(`div`,{className:e.v4,children:`Skipped`})]}),{name:`ShellPermissionBlock_1`,portals:[`v0`,`v3`]}),wc=Pr(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:`Allow the agent to run this command?`}),(0,$.jsx)(`code`,{className:e.v2,children: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:`ShellPermissionBlock_2`,portals:[`v0`,`v3`,`v4`,`v5`,`v6`]}),Tc=function({toolCallId:e,command:t,projectId:n,wildcardOptions:r,resolvedDecision:i}){let[a,o]=(0,Y.useState)(!!i),[c,l]=(0,Y.useState)(i??null),[u,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{i&&(o(!0),l(i),d(!1))},[i]);async function f(t,r){if(!(u||a)){d(!0);try{await Me(e,t,{pattern:r,projectId:n??void 0}),o(!0),l(t===`skip`?`skipped`:`allowed`)}catch(e){console.error(`Failed to submit shell permission response:`,e),d(!1)}}}return a&&c!==`skipped`?null:a?(0,$.jsx)(Cc,{v0:(0,$.jsx)(An,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:s.label,v2:q(s.mono,s.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:s.bodyMuted}):(0,$.jsx)(wc,{v0:(0,$.jsx)(ln,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:s.label,v2:q(s.mono,s.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:(0,$.jsx)(W,{type:`button`,size:`sm`,disabled:u,onClick:()=>void f(`allow_once`),className:`rounded-r-none`,children:`Allow`}),v5:r.length>0&&(0,$.jsxs)(dc,{children:[(0,$.jsx)(fc,{asChild:!0,children:(0,$.jsx)(W,{type:`button`,size:`sm`,disabled:u,className:q(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(pt,{className:`h-4 w-4`})})}),(0,$.jsx)(gc,{align:`end`,className:`max-w-md`,children:r.map(e=>(0,$.jsx)(_c,{onClick:()=>void f(e.scope===`project`?`allow_pattern_project`:`allow_pattern_session`,e.pattern),children:e.label},`${e.scope}-${e.pattern}`))})]}),v6:(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`outline`,disabled:u,onClick:()=>void f(`skip`),children:`Skip`})})},Ec=Pr(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:`Web fetch permission`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3})]})]}),(0,$.jsx)(`div`,{className:e.v4,children:`Skipped`})]}),{name:`WebFetchPermissionBlock_1`,portals:[`v0`,`v3`]}),Dc=Pr(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:`Allow the agent to fetch from this domain?`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3}),(0,$.jsx)(`div`,{className:e.v4,children:e.v5})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex rounded-md shadow-sm`,children:[e.v6,e.v7]}),e.v8]})]}),{name:`WebFetchPermissionBlock_2`,portals:[`v0`,`v3`,`v5`,`v6`,`v7`,`v8`]}),Oc=function({toolCallId:e,hostname:t,url:n,wildcardOptions:r,resolvedDecision:i}){let[a,o]=(0,Y.useState)(!!i),[c,l]=(0,Y.useState)(i??null),[u,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{i&&(o(!0),l(i),d(!1))},[i]);async function f(t){if(!(u||a)){d(!0);try{await m(e,t),o(!0),l(t===`skip`?`skipped`:`allowed`)}catch(e){console.error(`Failed to submit web fetch permission response:`,e),d(!1)}}}return a&&c!==`skipped`?null:a?(0,$.jsx)(Ec,{v0:(0,$.jsx)(An,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:s.label,v2:q(s.mono,s.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:s.bodyMuted}):(0,$.jsx)(Dc,{v0:(0,$.jsx)(He,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:s.label,v2:q(s.mono,s.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:q(s.caption,s.bodyMuted,`mt-1 break-all`),v5:n,v6:(0,$.jsx)(W,{type:`button`,size:`sm`,disabled:u,onClick:()=>void f(`allow_once`),className:`rounded-r-none`,children:`Allow`}),v7:r.length>0&&(0,$.jsxs)(dc,{children:[(0,$.jsx)(fc,{asChild:!0,children:(0,$.jsx)(W,{type:`button`,size:`sm`,disabled:u,className:q(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(pt,{className:`h-4 w-4`})})}),(0,$.jsx)(gc,{align:`end`,className:`max-w-md`,children:r.map(e=>(0,$.jsx)(_c,{onClick:()=>void f(e.scope===`project`?`allow_domain_project`:`allow_domain_session`),children:e.label},`${e.scope}-${e.pattern}`))})]}),v8:(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`outline`,disabled:u,onClick:()=>void f(`skip`),children:`Deny`})})},kc=new Map,Ac=new Map;function jc(e){return kc.get(e)}function Mc(e,t){let n=Ac.get(e);return n||(n=new Set,Ac.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Ac.delete(e)}}function Nc(e){let t=Ac.get(e);if(t)for(let e of t)e()}function Pc(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 Fc(e,t,n){if(kc.has(e))return;kc.set(e,{status:`running`}),Nc(e);let r=In();(async()=>{try{let i=Pc(r,n),a=Object.getPrototypeOf(async function(){}).constructor,o=await new a(`callTool`,t)(i),s=o===void 0?null:o;kc.set(e,{status:`success`,result:s}),Nc(e),await kn(e,s)}catch(t){let n=t instanceof Error?t.stack||t.message:String(t);kc.set(e,{status:`error`,error:n}),Nc(e);try{await kn(e,{error:n})}catch(e){console.error(`[browser-js-executor] failed to submit error result`,e)}}})()}var Ic=Pr(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`]}),Lc=Pr(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`]}),Rc=Pr(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`]}),zc=function(e){let t=(0,X.c)(41),{toolCallId:n,intention:r,code:i}=e,a=Q(Bc),o;t[0]===n?o=t[1]:(o=jc(n),t[0]=n,t[1]=o);let c=o,[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=()=>Mc(n,()=>{let e=jc(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&&Fc(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(Vc),t[12]=S):S=t[12];let C=S;if(l===`running`){let e,n;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(s.label,`w-full py-2 flex items-center gap-2`),n=(0,$.jsx)(Ut,{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)(Ic,{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=q(s.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),n=(0,$.jsx)(Ut,{className:`h-4 w-4 shrink-0 text-brand`}),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let a=r||`Browser JS Executed Successfully`,o;t[19]===b?o=t[20]:(o=b?(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{className:`h-4 w-4 shrink-0`}),t[19]=b,t[20]=o);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:q(s.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i}),f!=null&&(0,$.jsx)(`pre`,{className:q(s.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]!==o||t[27]!==c?(l=(0,$.jsx)(Lc,{v0:C,v1:e,v2:n,v3:a,v4:o,v5:c}),t[25]=a,t[26]=o,t[27]=c,t[28]=l):l=t[28],l}let w,T;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(w=q(s.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),T=(0,$.jsx)(Ut,{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)(pt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(xn,{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:q(s.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:m}),(0,$.jsx)(`pre`,{className:q(s.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)(Rc,{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 Bc(e){return e.selectedThreadId}function Vc(e){return!e}var Hc=Pr(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:`StreamingMessageComponent_1`,portals:[`v2`,`v3`]}),Uc=function({segments:e,model:t,threadId:n,projectId:r,isCreatingProject:i,isProcessingThread:a,totalMessages:o=0,showProcessingLine:c=!1}){let l=Q(e=>e.toolCallProgress),u=(0,Y.useRef)(new Map),d=(0,Y.useMemo)(()=>{let t=u.current,n=[],r=new Set;for(let i of e){if(r.add(i),i.type===`long_running_confirmation`){n.push({type:`long_running_confirmation`,prompt:i.prompt});continue}if(i.type===`shell_permission`){n.push({type:`shell_permission`,prompt:i.prompt});continue}if(i.type===`web_fetch_permission`){n.push({type:`web_fetch_permission`,prompt:i.prompt});continue}let e=t.get(i);if(e&&e.chunks===i.chunks){n.push(...e.blocks);continue}if(e&&e.chunks.length===i.chunks.length){n.push(...e.blocks);continue}let a=i.chunks.join(``),o;o=i.type===`thinking`?Di(a)??[]:Ai(a)??(a.trim()?[{type:`text`,text:a}]:[]),t.set(i,{chunks:i.chunks,blocks:o}),n.push(...o)}for(let e of t.keys())r.has(e)||t.delete(e);return n},[e]);return(0,$.jsx)(Hc,{v0:q(`group px-4 pt-4`,c?`pb-0`:`pb-4`),v1:q(s.compact,`font-medium text-foreground`),v2:t&&(0,$.jsxs)(`span`,{className:q(s.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Ut,{className:`h-2.5 w-2.5`}),Or(t)]}),v3:d.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 min-w-0 text-base`,children:Li(d,!0).map((e,t)=>{if(e.type===`thinking-group`){let n=e;return(0,$.jsx)(Xs,{text:n.text,label:n.label,isStreaming:n.isCurrentlyStreaming},`tg-${t}`)}let i=e;if(i.type===`tool_use`&&i.name===`todo`||i.type===`tool-result`&&i.toolName===`todo`)return i.type===`tool-result`?(0,$.jsx)(Ks,{inline:!0,sequence:o,block:i},`b-${t}`):null;if(i.type===`tool-result`&&i.toolName===`ask_user`)return null;if(i.type===`long_running_confirmation`){let e=i.prompt;return Xc(e,`stream-${t}`,Yc(d,e.toolCallId))}if(i.type===`shell_permission`){let e=i.prompt;return Zc(e,`stream-${t}`,r)}if(i.type===`web_fetch_permission`){let e=i.prompt;return Qc(e,`stream-${t}`,r)}return(0,$.jsx)(`div`,{children:i.type===`text`&&`text`in i?(0,$.jsx)(ao,{content:Ei(i.text),enableMermaid:!0,threadId:n}):i.type===`tool_use`?(()=>{let e=i.id,t=qc(d,e),n=Kc(l[e]??{});return $c(i,void 0,!Jc(d,e),t,n)})():i.type===`tool-result`?(0,$.jsx)(Ks,{inline:!0,block:i}):null},`b-${t}`)})}):i||a?(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(Xs,{isStreaming:!0})}):null})},Wc=Pr(e=>(0,$.jsxs)(`div`,{className:`mt-2 relative group/img inline-block max-w-full`,children:[(0,$.jsx)(`img`,{src:e.v0,alt:`Generated image`,className:`max-w-full rounded-lg border border-border block`,style:e.v1}),(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:e.v2})]}),{name:`GeneratedImagePreview_1`,portals:[`v2`]}),Gc=function(e){let t=(0,X.c)(30),{src:n,threadId:r}=e,[i,a]=(0,Y.useState)(!1),o;t[0]!==n||t[1]!==r?(o=n.startsWith(`data:`)?n:Ua(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()=>{let e=`generated-image-${Date.now()}.png`,{path:t}=await Ht(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:s,filename:e});pa({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[3]=s,t[4]=c);let l=c,u;t[5]===s?u=t[6]:(u=async()=>{await ut(s.startsWith(`data:`)?{imageData:s.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:s}),a(!0),setTimeout(()=>a(!1),2e3)},t[5]=s,t[6]=u);let d=u,f;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(f={maxHeight:`512px`},t[7]=f):f=t[7];let p;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Zt,{className:`h-3.5 w-3.5`}),t[8]=p):p=t[8];let m;t[9]===l?m=t[10]:(m=(0,$.jsx)(Fn,{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[9]=l,t[10]=m);let h;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(H,{children:`Save image`}),t[11]=h):h=t[11];let g;t[12]===m?g=t[13]:(g=(0,$.jsxs)(kt,{children:[m,h]}),t[12]=m,t[13]=g);let _;t[14]===i?_=t[15]:(_=i?(0,$.jsx)(An,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(yt,{className:`h-3.5 w-3.5`}),t[14]=i,t[15]=_);let v;t[16]!==d||t[17]!==_?(v=(0,$.jsx)(Fn,{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[16]=d,t[17]=_,t[18]=v):v=t[18];let y=i?`Copied!`:`Copy to clipboard`,b;t[19]===y?b=t[20]:(b=(0,$.jsx)(H,{children:y}),t[19]=y,t[20]=b);let x;t[21]!==v||t[22]!==b?(x=(0,$.jsxs)(kt,{children:[v,b]}),t[21]=v,t[22]=b,t[23]=x):x=t[23];let S;t[24]!==x||t[25]!==g?(S=(0,$.jsxs)(Sn,{children:[g,x]}),t[24]=x,t[25]=g,t[26]=S):S=t[26];let C;return t[27]!==s||t[28]!==S?(C=(0,$.jsx)(Wc,{v0:s,v1:f,v2:S}),t[27]=s,t[28]=S,t[29]=C):C=t[29],C};function Kc(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 qc(e,t){let n=e.find(e=>e.type===`tool-result`&&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 Jc(e,t){return e.some(e=>e.type===`tool-result`&&e.toolCallId===t)}function Yc(e,t){if(t)return qc(e,t)}function Xc(e,t,n){return(0,$.jsx)(uc,{toolCallId:e.toolCallId??`long-running-confirmation`,question:e.question,options:e.options,context:e.context,answeredText:n,answeredLabel:`You answered`},t)}function Zc(e,t,n){return(0,$.jsx)(Tc,{toolCallId:e.toolCallId,command:e.command,projectId:n,wildcardOptions:e.wildcardOptions},t)}function Qc(e,t,n){return(0,$.jsx)(Oc,{toolCallId:e.toolCallId,hostname:e.hostname,url:e.url,projectId:n,wildcardOptions:e.wildcardOptions},t)}function $c(e,t,n,r,i){if(e.name===`ask_user`)return(0,$.jsx)(uc,{toolCallId:e.id,question:typeof e.input?.question==`string`?e.input.question:``,options:e.input?.options,context:e.input?.context,answeredText:r},t);if(e.name===`run_js`||e.name===`run_web_worker`)return(0,$.jsx)(zc,{toolCallId:e.id,intention:e.input?.intention??``,code:e.input?.code??``},t);let a=n===!0&&r===void 0,o=e.name===`bash`||e.name===`read`||e.name===`file_read`||ic(e.name,e.input);return a&&!o?(0,$.jsx)($s,{toolCall:e},t):(0,$.jsx)(Bs,{inline:!0,block:e,resultContent:a?i:r,isActive:a},t)}function el({message:e,threadId:t,messageIndex:n=0,showCheckpointRestore:r=!1,checkpointRestoreTooltip:i}){let a=e.sender===`user`,o=(0,Y.useMemo)(()=>a?null:Ai(e.content),[a,e.content]),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=a&&(r||!!i),p=e.timestamp?new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``;async function m(){if(!(!e.checkpointRef||!t||c)){l(!0);try{let n=await ct(t,e.checkpointRef);n.success?pa({title:`Checkpoint restored`,description:`Working tree restored to before this agent run.`}):pa({title:`Restore failed`,description:n.error??`Could not restore checkpoint.`,variant:`destructive`})}catch(e){pa({title:`Restore failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{l(!1)}}}async function h(){try{await navigator.clipboard.writeText(e.content),d(!0),setTimeout(()=>d(!1),2e3)}catch(e){pa({title:`Copy failed`,description:e instanceof Error?e.message:`Could not copy prompt.`,variant:`destructive`})}}return(0,$.jsx)(`div`,{className:q(`group px-4 py-4`,a&&`flex justify-end`),children:(0,$.jsxs)(`div`,{className:q(`flex flex-col gap-1 min-w-0 max-w-full`,a&&`items-end`),children:[(0,$.jsxs)(`div`,{className:q(`flex items-center gap-2`,a&&`flex-row-reverse`),children:[(0,$.jsx)(`span`,{className:q(s.compact,`font-medium text-foreground`),children:a?`You`:`Agent`}),a&&(0,$.jsx)(Sn,{children:(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:h,"aria-label":u?`Prompt copied`:`Copy prompt`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted`,children:u?(0,$.jsx)(An,{className:`h-3 w-3 text-green-500`}):(0,$.jsx)(yt,{className:`h-3 w-3`})})})}),(0,$.jsx)(H,{side:`left`,children:u?`Copied prompt`:`Copy prompt`})]}),f&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:r?m:void 0,disabled:!r||c,"aria-label":i??`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)(G,{className:q(`h-3 w-3`,c&&`animate-spin`)})})})}),(0,$.jsx)(H,{side:`left`,children:i??`Restore checkpoint`})]})]})}),p&&(0,$.jsxs)(`span`,{className:q(s.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Et,{className:`h-2.5 w-2.5`}),p]}),e.model&&(0,$.jsxs)(`span`,{className:q(s.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Ut,{className:`h-2.5 w-2.5`}),Or(e.model)]}),e.metadata?.processingTimeMs&&(0,$.jsxs)(`span`,{className:q(s.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(St,{className:`h-2.5 w-2.5`}),e.metadata.processingTimeMs>=6e4?`${Math.floor(e.metadata.processingTimeMs/6e4)}m ${Math.round(e.metadata.processingTimeMs%6e4/1e3)}s`:`${Math.round(e.metadata.processingTimeMs/1e3)}s`]}),(e.metadata?.tokenCount||e.metadata?.estimatedCost)&&(0,$.jsxs)(`span`,{className:q(s.compact,`text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[e.metadata.tokenCount?`${e.metadata.tokenCount.toLocaleString()} tokens`:null,e.metadata.tokenCount&&e.metadata.estimatedCost?` · `:null,e.metadata.estimatedCost?Oe(e.metadata.estimatedCost):null]})]}),(0,$.jsx)(`div`,{className:q(`flex flex-col gap-0.5 min-w-0 text-base`,a&&`rounded-xl px-4 py-3 bg-foreground text-background`),children:e.isThinking?(()=>{let n=Di(e.content);return n?.length?(0,$.jsx)($.Fragment,{children:Li(n,!1).map((e,t)=>{if(e.type===`thinking-group`){let n=e;return(0,$.jsx)(Xs,{text:n.text,label:n.label,isStreaming:!1},`tg-${t}`)}let r=e;if(r.type===`tool_use`)return $c(r,t,!1,qc(n,r.id));if(r.type===`long_running_confirmation`){let e=r.prompt;return Xc(e,t,Yc(n,e.toolCallId))}if(r.type===`shell_permission`){let e=r.prompt;return Zc(e,t)}if(r.type===`web_fetch_permission`){let e=r.prompt;return Qc(e,t)}return r.type===`tool-result`?(0,$.jsx)(Ks,{inline:!0,block:r},t):null})}):(0,$.jsx)(`div`,{className:q(s.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:(0,$.jsx)(ao,{content:Ei(e.content),enableMermaid:!0,threadId:t})})})():o?(0,$.jsx)($.Fragment,{children:Li(o,!1).map((e,r)=>{if(e.type===`thinking-group`){let t=e;return(0,$.jsx)(Xs,{text:t.text,label:t.label,isStreaming:!1},`tg-${r}`)}let i=e;if(i.type===`tool_use`&&i.name===`todo`||i.type===`tool-result`&&i.toolName===`todo`)return i.type===`tool-result`?(0,$.jsx)(Ks,{inline:!0,sequence:n,block:i},r):null;if(i.type===`tool-result`&&i.toolName===`ask_user`)return null;if(i.type===`long_running_confirmation`){let e=i.prompt;return Xc(e,r,Yc(o,e.toolCallId))}return(0,$.jsx)(`div`,{children:i.type===`text`&&`text`in i?(0,$.jsx)(ao,{content:Ei(i.text),enableMermaid:!0,threadId:t}):i.type===`tool_use`?$c(i,void 0,!1,qc(o,i.id)):i.type===`tool-result`?(0,$.jsx)(Ks,{inline:!0,block:i}):null},r)})}):(0,$.jsx)(ao,{content:Ei(e.content),enableMermaid:!0,className:s.body,threadId:t})}),(e.generatedImageUrl||e.generatedImageData)&&(0,$.jsx)(Gc,{src:e.generatedImageData?`data:image/png;base64,${e.generatedImageData}`:e.generatedImageUrl,threadId:t}),e.attachments&&e.attachments.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:e.attachments.map((e,t)=>(0,$.jsxs)(`span`,{className:q(s.compact,`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-muted-foreground`),children:[(0,$.jsx)(Fe,{className:`h-2.5 w-2.5`}),e.fileName]},t))})]})})}var tl=(0,Y.memo)(el,(e,t)=>e.message.messageId===t.message.messageId&&e.message.content===t.message.content&&e.threadId===t.threadId&&e.messageIndex===t.messageIndex&&e.showCheckpointRestore===t.showCheckpointRestore&&e.checkpointRestoreTooltip===t.checkpointRestoreTooltip),nl=(0,Y.memo)(Uc,(e,t)=>{if(e.model!==t.model||e.threadId!==t.threadId||e.projectId!==t.projectId||e.isCreatingProject!==t.isCreatingProject||e.isProcessingThread!==t.isProcessingThread||e.showProcessingLine!==t.showProcessingLine||e.totalMessages!==t.totalMessages||e.segments.length!==t.segments.length)return!1;for(let n=0;n<e.segments.length;n++){let r=e.segments[n],i=t.segments[n];if(r.type!==i.type)return!1;if(r.type===`long_running_confirmation`){if(i.type!==`long_running_confirmation`||JSON.stringify(r.prompt)!==JSON.stringify(i.prompt))return!1;continue}if(r.type===`shell_permission`){if(i.type!==`shell_permission`||JSON.stringify(r.prompt)!==JSON.stringify(i.prompt))return!1;continue}if(r.type===`web_fetch_permission`){if(i.type!==`web_fetch_permission`||JSON.stringify(r.prompt)!==JSON.stringify(i.prompt))return!1;continue}if(i.type===`long_running_confirmation`||i.type===`shell_permission`||i.type===`web_fetch_permission`||r.chunks.length!==i.chunks.length)return!1;for(let e=0;e<r.chunks.length;e++)if(r.chunks[e]!==i.chunks[e])return!1}return!0}),rl=3e3;function il(e){let t=[...re],n=e?t.filter(t=>t!==e):t;return n[Math.floor(Math.random()*n.length)]}function al(e){let t=(0,X.c)(3),[n,r]=(0,Y.useState)(P),i=(0,Y.useRef)(P),a,o;return t[0]===e?(a=t[1],o=t[2]):(a=()=>{if(!e){r(P),i.current=P;return}let t=setInterval(()=>{let e=i.current===`Processing...`?il():il(i.current);i.current=e,r(e)},rl);return()=>clearInterval(t)},o=[e],t[0]=e,t[1]=a,t[2]=o),(0,Y.useEffect)(a,o),n}var ol=`w-7`,sl=`-ml-9`;function cl(e){let t=(0,X.c)(11),{active:n,className:r}=e,i=n===void 0?!0:n,a=al(i),o;t[0]===r?o=t[1]:(o=q(`flex items-center gap-2`,sl,r),t[0]=r,t[1]=o);let c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(ps,{className:ol}),t[2]=c):c=t[2];let l=i?`animate-shimmer`:void 0,u;t[3]===l?u=t[4]:(u=q(s.caption,l),t[3]=l,t[4]=u);let d;t[5]!==a||t[6]!==u?(d=(0,$.jsx)(`span`,{className:u,children:a}),t[5]=a,t[6]=u,t[7]=d):d=t[7];let f;return t[8]!==o||t[9]!==d?(f=(0,$.jsxs)(`div`,{className:o,"aria-live":`polite`,"aria-busy":`true`,children:[c,d]}),t[8]=o,t[9]=d,t[10]=f):f=t[10],f}var ll=Pr(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`]}),ul=function(e){let t=(0,X.c)(17),{projects:n,onSelectProject:r,onCreateThread:i,onConnectRepo:a,onNewApp:o,onOpenFolder:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=q(s.pageTitle,`tracking-tight text-balance`),t[0]=l):l=t[0];let u=n.length===0?`Start or connect your first project`:`Select a project to start coding`,d;if(t[1]!==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)(Ce,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`${s.body} text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:s.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],d=n.map(e),t[1]=i,t[2]=r,t[3]=n,t[4]=d}else d=t[4];let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(Ye,{className:`h-5 w-5 text-muted-foreground`}),t[8]=f):f=t[8];let p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(wn,{className:`h-5 w-5 text-muted-foreground`}),t[9]=p):p=t[9];let m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)($e,{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]!==c||t[14]!==u||t[15]!==d?(h=(0,$.jsx)(ll,{v0:l,v1:`mt-1 ${s.pageSubtitle}`,v2:u,v3:d,v4:a,v5:f,v6:`${s.body} text-foreground leading-snug font-medium`,v7:s.caption,v8:o,v9:p,v10:`${s.body} text-foreground leading-snug font-medium`,v11:s.caption,v12:c,v13:m,v14:`${s.body} text-foreground leading-snug font-medium`,v15:s.caption}),t[11]=a,t[12]=o,t[13]=c,t[14]=u,t[15]=d,t[16]=h):h=t[16],h};function dl(){let e=Q(e=>e.selectedThreadId),{dispatch:t}=Qi(e),{setActiveMainTab:n,setDevServerUrl:r,setDevServerRunning:i,setDevServerLoading:a}=wo();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 Ot(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(`
|
|
29
|
+
`).filter(e=>e.trim());for(let i of e)try{let e=JSON.parse(i);p||(p=!0,a(!1)),e.type===`url`&&e.url&&(clearTimeout(c),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`✓ Server running at: ${e.url}`}}),r(e.url),n(`browser`),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 fl=3e4,pl=2e3;function ml(e){let{devServerRunning:t,setDevServerRunning:n,devServerLoading:r}=wo(),i=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{e&&(i.current=!1,(async()=>{try{n((await Ze(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>fl){clearInterval(i);return}Ze(e).then(e=>{e.isRunning&&(n(!0),clearInterval(i))}).catch(()=>{})},pl);return()=>clearInterval(i)},[e,r,n]),{isRunning:t,isLoading:r,recheck:(0,Y.useCallback)(async()=>{if(e)try{n((await Ze(e)).isRunning)}catch{n(!1)}},[e,n])}}var hl=Pr(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`]}),gl=function(e){let t=(0,X.c)(14),{project:n}=e,{isRunning:r}=ml(n?.projectId),{startServer:i}=dl();n?.name;let a=n?.name??`your project`,o;t[0]===a?o=t[1]:(o=_l(a),t[0]=a,t[1]=o);let c=o,l=!r&&n?.runCommand,u;t[2]!==n||t[3]!==i?(u=()=>{n&&i(n)},t[2]=n,t[3]=i,t[4]=u):u=t[4];let d=u,f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=q(s.pageTitle,`tracking-tight text-foreground text-balance`),t[5]=f):f=t[5];let p=n?.name??`Project`,m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.pageSubtitle,`mt-2`),t[6]=m):m=t[6];let h;t[7]!==d||t[8]!==l?(h=l&&(0,$.jsx)(`button`,{type:`button`,onClick:d,className:q(s.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground hover:bg-primary/90 transition-colors`),children:`Start App`}),t[7]=d,t[8]=l,t[9]=h):h=t[9];let g;return t[10]!==c||t[11]!==p||t[12]!==h?(g=(0,$.jsx)(hl,{v0:f,v1:p,v2:m,v3:c,v4:h}),t[10]=c,t[11]=p,t[12]=h,t[13]=g):g=t[13],g};function _l(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)]}var vl=(0,Y.forwardRef)((e,t)=>{let n=(0,X.c)(9),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({style:a,children:r,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;return n[4]!==r||n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(`div`,{ref:t,style:a,...i,className:`mx-auto max-w-3xl w-full min-w-0`,children:r}),n[4]=r,n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});vl.displayName=`MessageList`;function yl(e){let t=(0,X.c)(24),{context:n}=e;if(!n)return null;let{bottomInset:r,isStreaming:i,isCreatingProject:a,isProcessingThread:o,hasPendingMessage:c,hasActiveBlockingPrompt:l,selectedProjectId:u,selectedThreadId:d,streamingSegments:f,streamingModel:p,totalMessages:m,error:h,onClearError:g}=n,_=f.length>0||a||o&&(i||c),v=(i||c)&&!l,y;t[0]===r?y=t[1]:(y={paddingBottom:r},t[0]=r,t[1]=y);let b;t[2]!==_||t[3]!==a||t[4]!==o||t[5]!==i||t[6]!==u||t[7]!==d||t[8]!==v||t[9]!==p||t[10]!==f||t[11]!==m?(b=_&&(i||a||o)&&(0,$.jsx)(nl,{segments:f,model:p,threadId:d,projectId:u,isCreatingProject:a,isProcessingThread:o,totalMessages:m,showProcessingLine:v}),t[2]=_,t[3]=a,t[4]=o,t[5]=i,t[6]=u,t[7]=d,t[8]=v,t[9]=p,t[10]=f,t[11]=m,t[12]=b):b=t[12];let x;t[13]!==_||t[14]!==v?(x=v&&(0,$.jsx)(`div`,{className:q(`px-4 pb-4`,_?`pt-0`:`pt-2`),children:(0,$.jsx)(cl,{active:v})}),t[13]=_,t[14]=v,t[15]=x):x=t[15];let S;t[16]!==h||t[17]!==g?(S=h&&(0,$.jsxs)(`div`,{className:`mx-4 my-2`,children:[(0,$.jsx)(Ur,{variant:`error`,className:`mb-0`,children:h}),(0,$.jsx)(`button`,{type:`button`,className:q(s.compact,`mt-1 text-destructive underline underline-offset-2 hover:text-destructive/80`),onClick:g,children:`Dismiss`})]}),t[16]=h,t[17]=g,t[18]=S):S=t[18];let C;return t[19]!==y||t[20]!==b||t[21]!==x||t[22]!==S?(C=(0,$.jsxs)(`div`,{className:`mx-auto max-w-3xl w-full min-w-0`,style:y,children:[b,x,S]}),t[19]=y,t[20]=b,t[21]=x,t[22]=S,t[23]=C):C=t[23],C}var bl={List:vl,Footer:yl};function xl(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 Sl(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 Cl(e){let t=e.some(e=>e.type!==`long_running_confirmation`&&e.type!==`shell_permission`&&e.type!==`web_fetch_permission`&&`chunks`in e&&e.chunks.some(e=>e.includes(`"type":"tool_use"`)&&e.includes(`"name":"ask_user"`))),n=e.some(e=>e.type!==`long_running_confirmation`&&e.type!==`shell_permission`&&e.type!==`web_fetch_permission`&&`chunks`in e&&e.chunks.some(e=>e.includes(`"type":"tool-result"`)&&e.includes(`"toolName":"ask_user"`)));if(t&&!n)return!0;let r=Sl(e);return r===-1?!1:!e.slice(r+1).some(e=>e.type===`content`||e.type===`thinking`?e.chunks.some(e=>e.trim().length>0):!1)}var wl=(0,Y.forwardRef)(function(e,t){let n=(0,X.c)(77),{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}=e,w=r===void 0?0:r,T=(0,Y.useRef)(null),E=(0,Y.useRef)(0),D=(0,Y.useRef)(!1),O=(0,Y.useRef)(!1),k=(0,Y.useRef)(0),A;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>({scrollToBottom:()=>{T.current?.scrollTo({top:2**53-1,behavior:`smooth`})}}),n[0]=A):A=n[0],(0,Y.useImperativeHandle)(t,A);let j;n[1]===d?j=n[2]:(j=()=>{d&&T.current?.getState(e=>{nn(d,e.scrollTop)})},n[1]=d,n[2]=j);let M=j,N,P;n[3]===M?(N=n[4],P=n[5]):(N=()=>{let e=()=>{M()};return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e),M()}},P=[M],n[3]=M,n[4]=N,n[5]=P),(0,Y.useEffect)(N,P);let F,I;n[6]===M?(F=n[7],I=n[8]):(F=()=>{let e=setInterval(()=>{M()},5e3);return()=>clearInterval(e)},I=[M],n[6]=M,n[7]=F,n[8]=I),(0,Y.useEffect)(F,I);let L;n[9]===Symbol.for(`react.memo_cache_sentinel`)?(L=()=>{O.current=!1,E.current=0},n[9]=L):L=n[9];let R;n[10]===d?R=n[11]:(R=[d],n[10]=d,n[11]=R),(0,Y.useEffect)(L,R);let ee,z;n[12]!==i.length||n[13]!==h||n[14]!==d?(ee=()=>{!d||!h||O.current||(O.current=!0,E.current=i.length)},z=[d,h,i.length],n[12]=i.length,n[13]=h,n[14]=d,n[15]=ee,n[16]=z):(ee=n[15],z=n[16]),(0,Y.useEffect)(ee,z);let te;n[17]!==u||n[18]!==a||n[19]!==i.length?(te=()=>{if(!O.current)return;let e=i.length>E.current,t=D.current&&!a;if(a||u||e||t){k.current&&cancelAnimationFrame(k.current);let e=t?`smooth`:`auto`;k.current=requestAnimationFrame(()=>{T.current?.scrollTo({top:2**53-1,behavior:e}),k.current=0})}return E.current=i.length,D.current=a,()=>{k.current&&=(cancelAnimationFrame(k.current),0)}},n[17]=u,n[18]=a,n[19]=i.length,n[20]=te):te=n[20];let ne;n[21]!==u||n[22]!==a||n[23]!==i.length||n[24]!==o.length?(ne=[a,u,i.length,o.length],n[21]=u,n[22]=a,n[23]=i.length,n[24]=o.length,n[25]=ne):ne=n[25],(0,Y.useEffect)(te,ne);let re=i.length===0&&!a&&!c&&!d,ie=h&&i.length===0&&!a&&!c&&!l&&!u&&d,ae;if(n[26]!==p||n[27]!==f){let e;n[29]===f?e=n[30]:(e=e=>e.projectId===f,n[29]=f,n[30]=e),ae=p.find(e),n[26]=p,n[27]=f,n[28]=ae}else ae=n[28];let oe=ae;if(re){let e=`flex-1 transition-opacity duration-500 ease-in-out ${m?`opacity-0`:`opacity-100`}`,t;n[31]!==v||n[32]!==_||n[33]!==y||n[34]!==b||n[35]!==g||n[36]!==p?(t=(0,$.jsx)(ul,{projects:p,onSelectProject:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b}),n[31]=v,n[32]=_,n[33]=y,n[34]=b,n[35]=g,n[36]=p,n[37]=t):t=n[37];let r;return n[38]!==e||n[39]!==t?(r=(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center overflow-hidden`,children:(0,$.jsx)(`div`,{className:e,children:t})}),n[38]=e,n[39]=t,n[40]=r):r=n[40],r}if(ie){let e;return n[41]===oe?e=n[42]:(e=(0,$.jsx)(gl,{project:oe}),n[41]=oe,n[42]=e),e}let se;n[43]===d?se=n[44]:(se=d?U(d):null,n[43]=d,n[44]=se);let ce=se,le;n[45]===o?le=n[46]:(le=Cl(o),n[45]=o,n[46]=le);let ue,de;n[47]!==u||n[48]!==c||n[49]!==l||n[50]!==a?(ue=e=>e.sender===`user`&&!!e.checkpointRef&&!a&&!u&&!c&&!l,de=e=>xl({isUser:e.sender===`user`,hasCheckpointRef:!!e.checkpointRef,isStreaming:a,hasPendingMessage:u,isCreatingProject:c,isProcessingThread:l}),n[47]=u,n[48]=c,n[49]=l,n[50]=a,n[51]=ue,n[52]=de):(ue=n[51],de=n[52]);let fe;n[53]!==w||n[54]!==x||n[55]!==u||n[56]!==c||n[57]!==l||n[58]!==a||n[59]!==i.length||n[60]!==S||n[61]!==f||n[62]!==d||n[63]!==s||n[64]!==o||n[65]!==le||n[66]!==ue||n[67]!==de?(fe={bottomInset:w,isStreaming:a,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,hasActiveBlockingPrompt:le,selectedProjectId:f,selectedThreadId:d,streamingSegments:o,streamingModel:s,totalMessages:i.length,error:x,onClearError:S,showCheckpointRestore:ue,getCheckpointTooltip:de},n[53]=w,n[54]=x,n[55]=u,n[56]=c,n[57]=l,n[58]=a,n[59]=i.length,n[60]=S,n[61]=f,n[62]=d,n[63]=s,n[64]=o,n[65]=le,n[66]=ue,n[67]=de,n[68]=fe):fe=n[68];let pe=fe,me=Tl,B;n[69]===Symbol.for(`react.memo_cache_sentinel`)?(B=q(`h-full overflow-hidden`),n[69]=B):B=n[69];let he=d??void 0,ge;n[70]===Symbol.for(`react.memo_cache_sentinel`)?(ge={height:`100%`},n[70]=ge):ge=n[70];let _e=ce!==null&&ce>0?ce:void 0,ve;return n[71]!==i||n[72]!==C||n[73]!==he||n[74]!==_e||n[75]!==pe?(ve=(0,$.jsx)(`div`,{className:B,children:(0,$.jsx)(fr,{ref:T,style:ge,initialScrollTop:_e,data:i,context:pe,itemContent:me,overscan:500,components:bl,atBottomStateChange:C},he)}),n[71]=i,n[72]=C,n[73]=he,n[74]=_e,n[75]=pe,n[76]=ve):ve=n[76],ve});function Tl(e,t,n){return(0,$.jsx)(tl,{message:t,threadId:n.selectedThreadId,messageIndex:e,showCheckpointRestore:n.showCheckpointRestore(t),checkpointRestoreTooltip:n.getCheckpointTooltip(t)})}function El(e,t){return e?`linear-gradient(to right, transparent 0, transparent 40px, ${t} 40px)`:`linear-gradient(to right, ${t}, ${t})`}function Dl(e){return El(e,`hsl(var(--background))`)}function Ol(e){let t=El(e,`hsl(var(--background))`);return e?`linear-gradient(to top, hsl(var(--background)) 0, hsl(var(--background)) calc(100% - 40px), transparent calc(100% - 40px), transparent 100%), ${t}`:`linear-gradient(to top, hsl(var(--background)) 0, transparent 100%), ${t}`}function kl(e,t){return El(e,t?`hsl(var(--background) / 0.8)`:`hsl(var(--background))`)}function Al({initialValue:e}={}){let t=Xi(),n=Q(e=>e.selectedThreadId),r=Q(e=>e.selectedProjectId),i=Q(e=>e.projects),a=Q(e=>e.projectModelSelections),o=Q(e=>e.chatInputDrafts),s=Q(e=>e.configUpdatedAt),c=Q(e=>e.focusChatInput),l=Q(e=>e.isStreaming),[u,d]=(0,Y.useState)(()=>n&&o[n]?o[n]:e??``),[f,p]=(0,Y.useState)(-1),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(0),v=(0,Y.useRef)(u);(0,Y.useEffect)(()=>{v.current=u},[u]);let y=(0,Y.useRef)(o);(0,Y.useEffect)(()=>{y.current=o},[o]);let b=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let[x,S]=(0,Y.useState)([]),[C,w]=(0,Y.useState)(()=>(n?a[n]:void 0)??null),T=(0,Y.useRef)(C?.id??``),E=(0,Y.useRef)(C?.provider??``),D=(0,Y.useRef)(null),[O,k]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(!1),[M,N]=(0,Y.useState)([]),[P,F]=(0,Y.useState)(!1),[I,L]=(0,Y.useState)(!1),[R,ee]=(0,Y.useState)(!1),[z,te]=(0,Y.useState)([]),[ne,re]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)([]),[oe,se]=(0,Y.useState)(!1),[ce,le]=(0,Y.useState)(``),[ue,de]=(0,Y.useState)(0),[pe,me]=(0,Y.useState)([]),[B,he]=(0,Y.useState)([]),[ge,_e]=(0,Y.useState)(!1),[ve,ye]=(0,Y.useState)(``),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(null),Ce=(0,Y.useRef)(null),we=(0,Y.useRef)(null),Te=(0,Y.useRef)(null),Ee=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{T.current=C?.id??``,E.current=C?.provider??``},[C?.id,C?.provider]);let V=(0,Y.useCallback)((e,r)=>{w(e);let i=n;if(!i||(t({type:Z.SetProjectModel,threadId:i,model:e}),r?.persist===!1))return;let a=`${i}:${e.provider??``}:${e.id}`;D.current!==a&&(D.current=a,console.log(`[useChatInputState] Persisting model to thread:`,{threadId:i,model:{id:e.id,provider:e.provider}}),fe(i,{model:e.id,modelProvider:e.provider}).then(()=>{D.current===a&&(D.current=null),console.log(`[useChatInputState] Model persisted successfully`)}).catch(e=>{D.current===a&&(D.current=null),console.error(`Failed to save model to thread:`,e)}))},[n,t]);(0,Y.useEffect)(()=>{(async()=>{let e=r?i.find(e=>e.projectId===r)?.threads.find(e=>e.threadId===n):void 0,t=n?a[n]:void 0,o=e?.model??t?.id??null,s=e?.modelProvider??t?.provider??null;console.log(`[useChatInputState] Loading models for thread:`,{threadId:n,projectId:r,currentThread:e?{model:e.model,modelProvider:e.modelProvider}:void 0,storedModel:t?{id:t.id,provider:t.provider}:void 0,savedModelId:o,savedModelProvider:s});try{let e=await Se(),t=Object.values(e).flat();if(t.length===0){S([]),w(null);return}S(t);let n=o&&s?t.find(e=>e.id===o&&e.provider===s)??null:null,r=t[0],i=n??r,a=!n&&!!(o||s),c=T.current===i.id&&E.current===i.provider;console.log(`[useChatInputState] Model selection decision:`,{matchedSavedModel:n?{id:n.id}:null,fallbackModel:{id:r.id},modelToSelect:{id:i.id},shouldPersistFallback:a,hasSameSelection:c,currentSelected:{id:T.current,provider:E.current}}),c||V(i,{persist:a})}catch(e){console.error(`Failed to load enabled models:`,e)}})()},[n,r,i,a,V]);let De=(0,Y.useRef)(V);(0,Y.useEffect)(()=>{De.current=V},[V]),(0,Y.useEffect)(()=>{s!==0&&(async()=>{try{let e=await Se(),t=Object.values(e).flat();if(t.length>0){S(t);let e=T.current,n=E.current;t.some(t=>t.id===e&&t.provider===n)||De.current(t[0],{persist:!0})}}catch(e){console.error(`Failed to reload enabled models:`,e)}})()},[s]),(0,Y.useEffect)(()=>{!R||z.length>0||(async()=>{try{let e=await Qe(),t=Object.values(e).flat();t.length>0&&(te(t),re(e=>e??t[0]))}catch(e){console.error(`Failed to load image models:`,e)}})()},[R,z.length]);let[Oe,ke]=(0,Y.useState)(n);(0,Y.useEffect)(()=>{if(n!==Oe){Oe&&v.current.trim()&&y.current[Oe]!==v.current&&t({type:Z.SetChatInputDraft,threadId:Oe,draft:v.current});let e=!1;return queueMicrotask(()=>{e||!b.current||(ke(n),d(n?y.current[n]??``:``),ae([]),se(!1),me([]),he([]),_e(!1),F(!1),ee(!1),L(!1))}),()=>{e=!0}}},[n,Oe]),(0,Y.useEffect)(()=>{n&&Bt(n).then(({commands:e,skills:t})=>{console.log(`Loaded slash commands:`,e,`skills:`,t),me(e),he(t)}).catch(e=>console.error(`Failed to load slash commands and skills:`,e))},[n]);let Ae=n?o[n]??``:``;return(0,Y.useEffect)(()=>{n&&d(Ae)},[n,Ae]),(0,Y.useLayoutEffect)(()=>{let e=xe.current;if(!e)return;e.style.height=`auto`;let t=Math.max(e.scrollHeight,e.offsetHeight);e.style.height=`${Math.min(t,160)}px`},[u]),(0,Y.useEffect)(()=>{c&&n&&!l&&(xe.current?.focus(),t({type:Z.ClearFocusChatInput}))},[c,n,l,t]),(0,Y.useEffect)(()=>{let e=n;return()=>{e&&v.current.trim()&&y.current[e]!==v.current&&t({type:Z.SetChatInputDraft,threadId:e,draft:v.current})}},[n,t]),(0,Y.useEffect)(()=>{let e=e=>{Ce.current&&!Ce.current.contains(e.target)&&k(!1),we.current&&!we.current.contains(e.target)&&j(!1)};if(O||A)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[O,A]),{message:u,setMessage:d,historyIndex:f,setHistoryIndex:p,draftMessage:m,setDraftMessage:h,cursorPosition:g,setCursorPosition:_,availableModels:x,setAvailableModels:S,selectedModel:C,setSelectedModel:V,selectedModelIdRef:T,showModelMenu:O,setShowModelMenu:k,showPlusMenu:A,setShowPlusMenu:j,attachments:M,setAttachments:N,planMode:P,setPlanMode:F,ralphMode:I,setRalphMode:L,imageMode:R,setImageMode:ee,availableImageModels:z,setAvailableImageModels:te,selectedImageModel:ne,setSelectedImageModel:re,allFiles:ie,setAllFiles:ae,showSuggestions:oe,setShowSuggestions:se,suggestionQuery:ce,setSuggestionQuery:le,selectedIndex:ue,setSelectedIndex:de,slashCommands:pe,setSlashCommands:me,skills:B,setSkills:he,showCommandSuggestions:ge,setShowCommandSuggestions:_e,commandQuery:ve,setCommandQuery:ye,fileInputRef:be,textareaRef:xe,modelMenuRef:Ce,plusMenuRef:we,suggestionsRef:Te,commandSuggestionsRef:Ee,handleNewChat:async()=>{if(n)try{let e=await Dt(n);t({type:Z.ClearMessages}),console.log(`New conversation started:`,e);let r=await wt(n);t({type:Z.SetMessages,messages:r.messages})}catch(e){console.error(`Failed to start new chat:`,e)}},selectedThreadId:n,dispatch:t}}var jl=e=>{Te(e)};function Ml(e){let t=(0,X.c)(107),{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,textareaRef:F,setAttachments:I,planMode:L,setPlanMode:R,ralphMode:ee,setRalphMode:z,imageMode:te,setImageMode:ne,selectedImageModel:re,hasConversationMessages:ie}=e,ae;t[0]!==o||t[1]!==m||t[2]!==te||t[3]!==d||t[4]!==l||t[5]!==n||t[6]!==a||t[7]!==c||t[8]!==L||t[9]!==ee||t[10]!==p||t[11]!==re||t[12]!==s||t[13]!==u||t[14]!==I||t[15]!==v||t[16]!==g||t[17]!==r||t[18]!==f||t[19]!==F||t[20]!==i?(ae=()=>{if(!n.trim()&&o.length===0||!u)return;let e=te?re:s;if(!e)return;d&&(f(),p()),l?m({type:Z.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:u,message:n,model:e.id,attachments:o,provider:e.provider,planMode:L,imageMode:te,ralphMode:ee}}):c(n,e.id,o,e.provider,L,te,ee);let t=n,h=i.find(e=>e.content===t);jl(n),r(``),I([]),h&&a?.(h),g(-1),v(``),u&&m({type:Z.ClearChatInputDraft,threadId:u}),F.current&&(F.current.style.height=`auto`)},t[0]=o,t[1]=m,t[2]=te,t[3]=d,t[4]=l,t[5]=n,t[6]=a,t[7]=c,t[8]=L,t[9]=ee,t[10]=p,t[11]=re,t[12]=s,t[13]=u,t[14]=I,t[15]=v,t[16]=g,t[17]=r,t[18]=f,t[19]=F,t[20]=i,t[21]=ae):ae=t[21];let oe=ae,se;t[22]!==y||t[23]!==n||t[24]!==r||t[25]!==S||t[26]!==C||t[27]!==F?(se=e=>{let t=n.substring(0,y-C.length-1);r(`${t}${e} ${n.substring(y)}`),S(!1),setTimeout(()=>{if(F.current){F.current.focus();let n=t.length+e.length+1;F.current.setSelectionRange(n,n)}},0)},t[22]=y,t[23]=n,t[24]=r,t[25]=S,t[26]=C,t[27]=F,t[28]=se):se=t[28];let ce=se,le;t[29]!==j||t[30]!==y||t[31]!==n||t[32]!==ne||t[33]!==r||t[34]!==R||t[35]!==z||t[36]!==A||t[37]!==F?(le=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(F.current){F.current.focus();let e=i.length+t.length;F.current.setSelectionRange(e,e)}},0),e.metadata.mode===`plan`?(R(!0),z(!1),ne(!1)):e.metadata.mode===`ralph`&&(z(!0),R(!1),ne(!1))},t[29]=j,t[30]=y,t[31]=n,t[32]=ne,t[33]=r,t[34]=R,t[35]=z,t[36]=A,t[37]=F,t[38]=le):le=t[38];let ue=le,de;t[39]!==j||t[40]!==y||t[41]!==n||t[42]!==r||t[43]!==A||t[44]!==F?(de=e=>{let t=n.substring(0,y-j.length-1),i=n.substring(y),a=e.name.includes(` `)?`/"${e.name}"`:`/${e.name}`;r(`${t}${a}${i}`),A(!1),setTimeout(()=>{if(F.current){F.current.focus();let e=t.length+a.length;F.current.setSelectionRange(e,e)}},0)},t[39]=j,t[40]=y,t[41]=n,t[42]=r,t[43]=A,t[44]=F,t[45]=de):de=t[45];let fe=de,pe,B,he,ge;if(t[46]!==T||t[47]!==j||t[48]!==_||t[49]!==oe||t[50]!==ie||t[51]!==h||t[52]!==ue||t[53]!==ce||t[54]!==fe||t[55]!==n||t[56]!==D||t[57]!==u||t[58]!==E||t[59]!==M||t[60]!==b||t[61]!==v||t[62]!==g||t[63]!==r||t[64]!==O||t[65]!==A||t[66]!==S||t[67]!==w||t[68]!==k||t[69]!==x||t[70]!==P||t[71]!==N||t[72]!==C){he=e=>{if(k){if(e.key===`ArrowDown`){e.preventDefault(),O((D+1)%pe.length);return}if(e.key===`ArrowUp`){e.preventDefault(),O((D-1+pe.length)%pe.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=pe[D];t&&(t.type===`command`?ue(t.data):fe(t.data));return}if(e.key===`Escape`){A(!1);return}}if(x){let t=B.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),O((D+1)%B.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),O((D-1+B.length)%B.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),B[D]&&ce(B[D]);return}if(e.key===`Escape`){S(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),oe();return}let t=Xt();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[77]!==T||t[78]!==u||t[79]!==E||t[80]!==M||t[81]!==b||t[82]!==r||t[83]!==O||t[84]!==A||t[85]!==S||t[86]!==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 e=a>0?i[a-1]:``;if(a===0||/\s/.test(e)){let e=i.substring(a+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&&me(u).then(e=>{E(e)}).catch(Fl))}else S(!1)}else S(!1)}let o=e.target;o.style.height=`auto`,o.style.height=`${Math.min(o.scrollHeight,160)}px`},t[77]=T,t[78]=u,t[79]=E,t[80]=M,t[81]=b,t[82]=r,t[83]=O,t[84]=A,t[85]=S,t[86]=w,t[87]=e):e=t[87],ge=e;let i;if(t[88]!==j||t[89]!==ie||t[90]!==P||t[91]!==N){let e;t[93]!==j||t[94]!==ie?(e=e=>e.metadata.action===`compact`&&!ie?!1:e.name.toLowerCase().includes(j.toLowerCase()),t[93]=j,t[94]=ie,t[95]=e):e=t[95];let n=N.filter(e),r;t[96]===j?r=t[97]:(r=e=>e.name.toLowerCase().includes(j.toLowerCase()),t[96]=j,t[97]=r);let a=P.filter(r);i=[...n.map(Pl),...a.map(Nl)],t[88]=j,t[89]=ie,t[90]=P,t[91]=N,t[92]=i}else i=t[92];pe=i.slice(0,10),B=x?T.filter(e=>e.toLowerCase().includes(C.toLowerCase())).slice(0,10):[],t[46]=T,t[47]=j,t[48]=_,t[49]=oe,t[50]=ie,t[51]=h,t[52]=ue,t[53]=ce,t[54]=fe,t[55]=n,t[56]=D,t[57]=u,t[58]=E,t[59]=M,t[60]=b,t[61]=v,t[62]=g,t[63]=r,t[64]=O,t[65]=A,t[66]=S,t[67]=w,t[68]=k,t[69]=x,t[70]=P,t[71]=N,t[72]=C,t[73]=pe,t[74]=B,t[75]=he,t[76]=ge}else pe=t[73],B=t[74],he=t[75],ge=t[76];let _e;return t[98]!==pe||t[99]!==B||t[100]!==he||t[101]!==oe||t[102]!==ge||t[103]!==ue||t[104]!==ce||t[105]!==fe?(_e={handleSend:oe,handleKeyDown:he,handleTextareaInput:ge,insertFileReference:ce,insertCommand:ue,insertSkill:fe,allSuggestions:pe,fileSuggestions:B},t[98]=pe,t[99]=B,t[100]=he,t[101]=oe,t[102]=ge,t[103]=ue,t[104]=ce,t[105]=fe,t[106]=_e):_e=t[106],_e}function Nl(e){return{type:`skill`,data:e}}function Pl(e){return{type:`command`,data:e}}function Fl(e){return console.error(`Failed to fetch files:`,e)}var Il=768;function Ll(){let e=(0,X.c)(2),[t,n]=Y.useState(Rl),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${Il-1}px)`),t=()=>{n(window.innerWidth<Il)};return e.addEventListener(`change`,t),n(window.innerWidth<Il),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),t}function Rl(){return typeof window>`u`?!1:window.innerWidth<Il}function zl(e){let t=(0,X.c)(22),{visible:n,commands:r,skills:i,query:a,selectedIndex:o,onSelectCommand:c,onSelectSkill:l,onMouseEnterSuggestion:u,containerRef:d}=e;if(!n)return null;let f;if(t[0]!==r||t[1]!==a||t[2]!==i){let e;t[4]===a?e=t[5]:(e=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[4]=a,t[5]=e);let n=r.filter(e),o;t[6]===a?o=t[7]:(o=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[6]=a,t[7]=o);let s=i.filter(o);f=[...n.map(Vl),...s.map(Bl)].slice(0,10),t[0]=r,t[1]=a,t[2]=i,t[3]=f}else f=t[3];let p=f,m,h;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(s.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),h=(0,$.jsx)(pn,{className:`h-3 w-3`}),t[8]=m,t[9]=h):(m=t[8],h=t[9]);let g=a&&` matching "${a}"`,_;t[10]===g?_=t[11]:(_=(0,$.jsxs)(`div`,{className:m,children:[h,`Commands & Skills`,g]}),t[10]=g,t[11]=_);let v;t[12]!==p||t[13]!==u||t[14]!==c||t[15]!==l||t[16]!==o?(v=p.length>0?p.map((e,t)=>{let n=t===o;if(e.type===`command`){let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>c(r),onMouseEnter:()=>u(t),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(pn,{className:`h-3 w-3 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),r.metadata.argumentHint&&(0,$.jsx)(`span`,{className:s.compact,children:r.metadata.argumentHint}),r.scope===`project`&&(0,$.jsx)(`span`,{className:q(s.compact,`ml-auto rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`),children:`project`})]}),r.metadata.description&&(0,$.jsx)(`span`,{className:s.compact,children:r.metadata.description})]},`cmd-${r.name}`)}else{let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>l(r),onMouseEnter:()=>u(t),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(O,{className:`h-3 w-3 text-amber-500`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),(0,$.jsx)(`span`,{className:q(s.compact,`ml-auto rounded-full bg-amber-500/10 px-1.5 py-0.5 text-amber-700 dark:text-amber-400`),children:`skill`}),r.scope===`project`&&(0,$.jsx)(`span`,{className:q(s.compact,`rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`),children:`project`})]}),(0,$.jsx)(`span`,{className:s.compact,children:r.description})]},`skill-${r.name}`)}}):(0,$.jsxs)(`div`,{className:q(s.compact,`px-3 py-4 text-center text-muted-foreground`),children:[`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:s.compact,children:[`Create commands in `,(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[12]=p,t[13]=u,t[14]=c,t[15]=l,t[16]=o,t[17]=v):v=t[17];let y;return t[18]!==d||t[19]!==_||t[20]!==v?(y=(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:[_,v]}),t[18]=d,t[19]=_,t[20]=v,t[21]=y):y=t[21],y}function Bl(e){return{type:`skill`,data:e}}function Vl(e){return{type:`command`,data:e}}function Hl(e){return e.startsWith(`image/`)}function Ul(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:q(s.compact,`group relative flex items-center gap-1 rounded-md bg-muted text-muted-foreground`),children:Hl(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)(z,{className:`h-2.5 w-2.5`}),(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)(Fe,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(z,{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 Wl=Pr(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`]}),Gl=function(e){let t=(0,X.c)(37),{breakdown:n,onClose:r}=e,{categories:i,totalTokens:a,contextWindow:o,percentageFull:c}=n,l,u,d,f,p,m,h,g;if(t[0]!==i||t[1]!==o||t[2]!==r||t[3]!==c||t[4]!==a){let e;t[13]===i?e=t[14]:(e=e=>i[e.key]>0,t[13]=i,t[14]=e);let n=Kl.filter(e);l=Wl,u=s.label,t[15]===r?d=t[16]:(d=r&&(0,$.jsxs)(W,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:r,children:[(0,$.jsx)(z,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[15]=r,t[16]=d),t[17]===Symbol.for(`react.memo_cache_sentinel`)?(f=q(s.compact,`flex items-center justify-between text-muted-foreground`),t[17]=f):f=t[17],p=c,t[18]===a?m=t[19]:(m=ql(a),t[18]=a,t[19]=m),t[20]===o?h=t[21]:(h=Jl(o),t[20]=o,t[21]=h);let _;t[22]!==i||t[23]!==o?(_=e=>{let t=i[e.key],n=o>0?t/o*100:0;return(0,$.jsx)(`div`,{style:{width:`${Math.max(n,t>0?.5:0)}%`,backgroundColor:e.color}},e.key)},t[22]=i,t[23]=o,t[24]=_):_=t[24],g=n.map(_),t[0]=i,t[1]=o,t[2]=r,t[3]=c,t[4]=a,t[5]=l,t[6]=u,t[7]=d,t[8]=f,t[9]=p,t[10]=m,t[11]=h,t[12]=g}else l=t[5],u=t[6],d=t[7],f=t[8],p=t[9],m=t[10],h=t[11],g=t[12];let _;t[25]===i?_=t[26]:(_=Kl.map(e=>(0,$.jsxs)(`div`,{className:q(s.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:ql(i[e.key])})]},e.key)),t[25]=i,t[26]=_);let v;return t[27]!==l||t[28]!==u||t[29]!==d||t[30]!==f||t[31]!==p||t[32]!==m||t[33]!==h||t[34]!==g||t[35]!==_?(v=(0,$.jsx)(l,{v0:u,v1:d,v2:f,v3:p,v4:m,v5:h,v6:g,v7:_}),t[27]=l,t[28]=u,t[29]=d,t[30]=f,t[31]=p,t[32]=m,t[33]=h,t[34]=g,t[35]=_,t[36]=v):v=t[36],v},Kl=[{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 ql(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function Jl(e){return e>=1e6?`${Math.round(e/1e6)}M`:e>=1e3?`${Math.round(e/1e3)}K`:e.toString()}function Yl({threadId:e,currentConversationId:t,initialBreakdown:n,refreshKey:r,children:i}){let[a,o]=(0,Y.useState)(n??null),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(n?t:void 0);return(0,Y.useEffect)(()=>{if(n){o(n),h(t),d(null);return}t!==m&&(o(null),h(void 0),d(null))},[n,t,m,r]),(0,Y.useEffect)(()=>{if(!f||!e||!t||m===t)return;let n=!1;async function r(){let r=t;if(r){l(!0),d(null);try{let t=await gn(e,r);if(n)return;o(t),h(r)}catch(e){if(console.error(`[TokenUsageTooltip] Failed to load context data:`,e),n)return;o(e=>(e||d(`Failed to load context data`),e))}finally{n||l(!1)}}}return r(),()=>{n=!0}},[f,e,t,m]),!e||e===``?(0,$.jsx)($.Fragment,{children:i}):(0,$.jsxs)(ys,{open:f,onOpenChange:p,children:[(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(bs,{asChild:!0,children:i})}),(0,$.jsx)(H,{side:`top`,className:`bg-popover text-popover-foreground`,children:`Show context usage`})]}),(0,$.jsxs)(xs,{side:`top`,align:`end`,className:`w-auto p-4`,children:[c&&(0,$.jsxs)(`div`,{className:q(s.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(Ne,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading context...`})]}),u&&!c&&(0,$.jsxs)(`div`,{className:q(s.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(Ne,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u})]}),!c&&!u&&a&&(0,$.jsx)(Gl,{breakdown:a,onClose:()=>p(!1)})]})]})}var Xl=Pr(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}),Zl=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=$l(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)(Xl,{v0:o,v1:7,v2:7,v3:r,v4:i}),t[2]=i,t[3]=o,t[4]=s):s=t[4],s};function Ql(e){return e.filter(e=>e.sender===`agent`).length}function $l(e){return e>75?`text-red-500`:e>50?`text-orange-500`:`text-muted-foreground`}var eu=500;function tu(e){let t=(0,X.c)(34),{threadId:n,messages:r}=e,i;t[0]===r?i=t[1]:(i=r===void 0?[]:r,t[0]=r,t[1]=i);let a=i,[o,s]=(0,Y.useState)(),[c,l]=(0,Y.useState)(),u;t[2]===a?u=t[3]:(u=Ql(a),t[2]=a,t[3]=u);let f=u,[p,m]=(0,Y.useState)(f),h=(0,Y.useRef)(null),g=(0,Y.useRef)(n),_,v;t[4]===f?(_=t[5],v=t[6]):(_=()=>(h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{m(f)},eu),()=>{h.current&&clearTimeout(h.current)}),v=[f],t[4]=f,t[5]=_,t[6]=v),(0,Y.useEffect)(_,v);let y,b;t[7]===n?(y=t[8],b=t[9]):(y=()=>{g.current!==n&&(g.current&&(T.invalidate(`thread-${g.current}`),T.invalidatePattern(RegExp(`^context-breakdown-${g.current}-`))),g.current=n,s(void 0),l(void 0))},b=[n],t[7]=n,t[8]=y,t[9]=b),(0,Y.useEffect)(y,b);let x;t[10]===n?x=t[11]:(x=()=>{let e=!1;return(async function(){if(!n){s(void 0),l(void 0);return}try{let t=await d(n);if(e)return;s(t.currentConversationId)}catch(e){console.error(`Failed to fetch thread data:`,e)}})(),()=>{e=!0}},t[10]=n,t[11]=x);let S;t[12]!==p||t[13]!==n?(S=[n,p],t[12]=p,t[13]=n,t[14]=S):S=t[14],(0,Y.useEffect)(x,S);let C;t[15]!==o||t[16]!==n?(C=()=>{let e=!1;return(async function(){if(!n||!o){l(void 0);return}try{let t=await gn(n,o);if(e)return;l(t)}catch(e){console.error(`Failed to fetch context breakdown:`,e)}})(),()=>{e=!0}},t[15]=o,t[16]=n,t[17]=C):C=t[17];let w;if(t[18]!==o||t[19]!==p||t[20]!==n?(w=[n,o,p],t[18]=o,t[19]=p,t[20]=n,t[21]=w):w=t[21],(0,Y.useEffect)(C,w),!n||n===``)return null;let E=c?.percentageFull,D=typeof E==`number`&&E>25,O=String(p),k;t[22]!==E||t[23]!==D?(k=D?(0,$.jsx)(Zl,{percentage:E}):(0,$.jsx)(we,{className:`h-4 w-4`}),t[22]=E,t[23]=D,t[24]=k):k=t[24];let A;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(`span`,{className:`sr-only`,children:`Show context usage`}),t[25]=A):A=t[25];let j;t[26]===k?j=t[27]:(j=(0,$.jsxs)(W,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[k,A]}),t[26]=k,t[27]=j);let M;return t[28]!==c||t[29]!==o||t[30]!==O||t[31]!==j||t[32]!==n?(M=(0,$.jsx)(Yl,{threadId:n,currentConversationId:o,initialBreakdown:c,refreshKey:O,children:j}),t[28]=c,t[29]=o,t[30]=O,t[31]=j,t[32]=n,t[33]=M):M=t[33],M}function nu(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 ru(e){let t=(0,X.c)(17),{showSuggestions:n,fileSuggestions:r,suggestionQuery:i,selectedIndex:a,onSelectFile:o,onMouseEnterSuggestion:c,containerRef:l}=e;if(!n||r.length===0)return null;let u,d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=q(s.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),d=(0,$.jsx)(Tt,{className:`h-3 w-3`}),t[0]=u,t[1]=d):(u=t[0],d=t[1]);let f;t[2]===i?f=t[3]:(f=(0,$.jsxs)(`div`,{className:u,children:[d,`Files matching "`,i,`"`]}),t[2]=i,t[3]=f);let p;if(t[4]!==r||t[5]!==c||t[6]!==o||t[7]!==a){let e;t[9]!==c||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:q(s.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:()=>c(t),children:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,$.jsx)(Yt,{className:`h-4 w-4 text-blue-500`}):(0,$.jsx)(mn,{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:q(s.compact,`truncate text-muted-foreground opacity-70`),children:e})]})]},e)},t[9]=c,t[10]=o,t[11]=a,t[12]=e):e=t[12],p=r.map(e),t[4]=r,t[5]=c,t[6]=o,t[7]=a,t[8]=p}else p=t[8];let m;return t[13]!==l||t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(`div`,{ref:l,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[f,p]}),t[13]=l,t[14]=f,t[15]=p,t[16]=m):m=t[16],m}function iu(e){let t=(0,X.c)(5),{providerSlug:n}=e;if(!n)return null;let r;t[0]===n?r=t[1]:(r=Le(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:au}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a}function au(e){e.currentTarget.style.visibility=`hidden`}function ou(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=q(s.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)(iu,{providerSlug:n}),t[1]=n,t[2]=o);let c;t[3]!==i||t[4]!==r?(c=r?.url?(0,$.jsx)(Dr,{url:r.url,showIcon:!1,variant:`inline`,children:i}):i,t[3]=i,t[4]=r,t[5]=c):c=t[5];let l;return t[6]!==o||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:a,children:[o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8],l}function su(e){let t=e.pricing?.prompt;return t==null?null:Math.ceil(t*3)}function cu(e){return`$${At(e)}`}function lu(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:`${cu(e.pricing.prompt??0)} input per million tokens`}),(0,$.jsx)(`div`,{children:`${cu(e.pricing.completion??0)} output per million tokens`}),(0,$.jsx)(`div`,{children:`Displayed value of ${t} is a relative price.`})]}):null}function uu(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=(su(e)??2**53-1)-(su(n)??2**53-1);if(t!==0)return t}return Or(e.id).localeCompare(Or(n.id))})}function du(e){let t=(0,X.c)(34),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Y.useState(!1),[c,l]=Y.useState(`relative-price`),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=new Map,t[0]=u):u=t[0];let[d,f]=Y.useState(u),p=Y.useRef(null),m,h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{S().then(function(e){f(new Map(e.map(pu)))})},h=[],t[1]=m,t[2]=h):(m=t[1],h=t[2]),Y.useEffect(m,h);let g,_;t[3]===a?(g=t[4],_=t[5]):(g=()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&o(!1)};if(a)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},_=[a],t[3]=a,t[4]=g,t[5]=_),Y.useEffect(g,_);let v;t[6]===i?v=t[7]:(v=e=>{i(e),o(!1)},t[6]=i,t[7]=v);let y=v,b;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{l(function(e){return e===`relative-price`?`alphabetical`:`relative-price`})},t[8]=b):b=t[8];let x=b,C;t[9]!==n||t[10]!==c?(C=uu(n,c),t[9]=n,t[10]=c,t[11]=C):C=t[11];let w=C,T=c===`relative-price`?Ie:zt,E=c===`relative-price`?`Sort by relative price`:`Sort alphabetically`,D;t[12]===a?D=t[13]:(D=()=>o(!a),t[12]=a,t[13]=D);let O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=q(s.body,`font-normal`),t[14]=O):O=t[14];let k;t[15]===r?k=t[16]:(k=r?Or(r.id):`No model`,t[15]=r,t[16]=k);let A;t[17]===k?A=t[18]:(A=(0,$.jsx)(`span`,{className:O,children:k}),t[17]=k,t[18]=A);let j;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(ot,{className:`h-3 w-3`}),t[19]=j):j=t[19];let M;t[20]!==A||t[21]!==D?(M=(0,$.jsxs)(W,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:D,children:[A,j]}),t[20]=A,t[21]=D,t[22]=M):M=t[22];let N;t[23]!==T||t[24]!==y||t[25]!==d||t[26]!==r?.id||t[27]!==a||t[28]!==E||t[29]!==w?(N=a&&(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 w-80 max-h-80 overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:(0,$.jsxs)(Sn,{children:[(0,$.jsx)(`div`,{className:`-mb-3 flex justify-end px-1 pb-1`,children:(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":E,className:`rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground`,onClick:x,children:(0,$.jsx)(T,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(H,{side:`left`,align:`start`,sideOffset:8,children:E})]})}),Object.entries(w.reduce(fu,{})).map((e,t)=>{let[n,i]=e;return(0,$.jsxs)(`div`,{children:[t>0&&(0,$.jsx)(Er,{className:`my-1`}),(0,$.jsx)(ou,{providerSlug:n,providerData:d.get(n)}),i.map(e=>{let t=su(e),n=t==null?null:lu(e,t);return(0,$.jsx)(`div`,{children:(0,$.jsx)(`div`,{children:(0,$.jsxs)(`button`,{type:`button`,className:q(s.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:Or(e.id)}),t!=null&&n&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:t})}),(0,$.jsx)(H,{side:`left`,align:`end`,sideOffset:8,className:`max-w-64`,children:n})]})]})})},e.id)})]},n)})]})}),t[23]=T,t[24]=y,t[25]=d,t[26]=r?.id,t[27]=a,t[28]=E,t[29]=w,t[30]=N):N=t[30];let P;return t[31]!==M||t[32]!==N?(P=(0,$.jsxs)(`div`,{className:`relative`,ref:p,children:[M,N]}),t[31]=M,t[32]=N,t[33]=P):P=t[33],P}function fu(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function pu(e){return[e.slug,e]}var mu=[{value:`build`,label:`Build`,icon:A,description:`Executes code changes and implements features`},{value:`plan`,label:`Plan`,icon:De,description:`Creates implementation plans without making changes`},{value:`image`,label:`Image`,icon:f,description:`Generates and edits images`},{value:`ralph`,label:`Ralph`,icon:rt,description:`Runs rapid iterative test-fix cycles`}];function hu(e,t,n){return n?`ralph`:e?`plan`:t?`image`:`build`}function gu({planMode:e,imageMode:t,ralphMode:n,setPlanMode:r,setImageMode:i,setRalphMode:a,projectId:o}){let s=Xi(),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=hu(e,t,n),m=mu.find(e=>e.value===p);Y.useEffect(()=>{c&&u(c.allowAllCommands===!1)},[c]);async function g(){if(!o||d)return;let e=!l;u(e),f(!0);try{await he(o,{allowAllCommands:!e}),ee(o);let t=await h();s({type:Z.SetProjects,projects:t.projects})}catch(t){u(!e),console.error(`Failed to update command confirmation setting:`,t)}finally{f(!1)}}function _(e){r(e===`plan`),i(e===`image`),a(e===`ralph`)}return{chatModes:mu,confirmCommands:l,currentConfig:m,currentMode:p,isUpdatingConfirmCommands:d,selectMode:_,toggleConfirmCommands:g}}function _u(e){let t=(0,X.c)(38),{planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:c,projectId:l}=e,[u,d]=Y.useState(!1),f=Y.useRef(null),p;t[0]!==r||t[1]!==n||t[2]!==l||t[3]!==i||t[4]!==o||t[5]!==a||t[6]!==c?(p={planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:c,projectId:l},t[0]=r,t[1]=n,t[2]=l,t[3]=i,t[4]=o,t[5]=a,t[6]=c,t[7]=p):p=t[7];let{chatModes:m,confirmCommands:h,currentConfig:g,currentMode:_,isUpdatingConfirmCommands:v,selectMode:y,toggleConfirmCommands:b}=gu(p),x,S;t[8]===u?(x=t[9],S=t[10]):(x=()=>{let e=function(e){f.current&&!f.current.contains(e.target)&&d(!1)};if(u)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},S=[u],t[8]=u,t[9]=x,t[10]=S),Y.useEffect(x,S);let C;t[11]===y?C=t[12]:(C=function(e){y(e),d(!1)},t[11]=y,t[12]=C);let w=C,T;t[13]===u?T=t[14]:(T=()=>d(!u),t[13]=u,t[14]=T);let E;t[15]===g.icon?E=t[16]:(E=(0,$.jsx)(g.icon,{className:`h-4 w-4`}),t[15]=g.icon,t[16]=E);let D;t[17]!==T||t[18]!==E?(D=(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{variant:`action`,size:`icon-sm`,onClick:T,children:E})}),t[17]=T,t[18]=E,t[19]=D):D=t[19];let O;t[20]!==g.description||t[21]!==g.label?(O=(0,$.jsx)(H,{children:(0,$.jsxs)(`p`,{children:[g.label,` - `,g.description]})}),t[20]=g.description,t[21]=g.label,t[22]=O):O=t[22];let k;t[23]!==D||t[24]!==O?(k=(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{children:[D,O]})}),t[23]=D,t[24]=O,t[25]=k):k=t[25];let A;t[26]!==m||t[27]!==h||t[28]!==_||t[29]!==w||t[30]!==v||t[31]!==u||t[32]!==l||t[33]!==b?(A=u&&(0,$.jsxs)(`div`,{className:`absolute bottom-full right-0 z-50 mb-1 w-56 rounded-lg border border-border bg-popover p-1 shadow-md`,children:[l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:q(s.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent disabled:opacity-50`),onClick:()=>{b()},disabled:v,children:[`Confirm Commands`,h&&(0,$.jsx)(An,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border`})]}),m.map(e=>{let t=e.icon,n=e.value===_;return(0,$.jsxs)(`button`,{type:`button`,className:q(s.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent`),onClick:()=>w(e.value),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(An,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[26]=m,t[27]=h,t[28]=_,t[29]=w,t[30]=v,t[31]=u,t[32]=l,t[33]=b,t[34]=A):A=t[34];let j;return t[35]!==A||t[36]!==k?(j=(0,$.jsxs)(`div`,{className:`relative hidden md:block`,ref:f,children:[k,A]}),t[35]=A,t[36]=k,t[37]=j):j=t[37],j}function vu(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??xu,b=d??bu,x=f??yu,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=gu(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)(dt,{}),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)(fc,{asChild:!0,children:(0,$.jsxs)(W,{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)(Fe,{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)(_c,{onClick:k,children:[A,`Attach File`]}),t[16]=k,t[17]=j);let M;t[18]!==r||t[19]!==a?(M=r&&(0,$.jsxs)(_c,{onClick:()=>T(a),children:[(0,$.jsx)(ne,{className:`mr-2 h-3.5 w-3.5`}),`Add to Pending Tasks`]}),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)(xc,{}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(_c,{onClick:()=>{C.toggleConfirmCommands()},disabled:C.isUpdatingConfirmCommands,children:[`Confirm Commands`,C.confirmCommands&&(0,$.jsx)(An,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(xc,{})]}),C.chatModes.map(e=>{let t=e.icon,n=e.value===C.currentMode;return(0,$.jsxs)(_c,{onClick:()=>C.selectMode(e.value),className:q(n&&`bg-accent`),children:[(0,$.jsx)(t,{className:`mr-2 h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(An,{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)(gc,{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)(dc,{children:[O,P]}),t[29]=O,t[30]=P,t[31]=F):F=t[31],F}function yu(){}function bu(){}function xu(){}var Su=Gr(`useWebSpeech`);function Cu(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 wu(e){let t=``;for(let n=0;n<e.results.length;n+=1)t+=e.results[n][0]?.transcript??``;return t}function Tu(){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=Wr();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=wu(e).trim();t&&a(t)},e.onerror=e=>{let t=Cu(e.error);Su.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}Su.info(`Web Speech recognition ended — restarting`),u()},c.current=e;try{e.start(),t(`recording`),Su.info(`Web Speech recognition started`)}catch(e){c.current=null,l.current=!1;let n=e instanceof Error?e.message:`Unknown error`;Su.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),Su.info(`Checking Web Speech API support`,{userAgent:navigator.userAgent,platform:navigator.platform});let n=qr();return r(n),n?(Su.info(`Web Speech API available — ready`),t(`ready`),`ready`):(Su.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(``),Su.info(`Starting Web Speech recognition`),u()},[u]),stopListening:(0,Y.useCallback)(async()=>{l.current=!1,c.current?.stop(),c.current=null,t(`ready`),Su.info(`Web Speech recognition stopped`)},[]),requestModelDownload:(0,Y.useCallback)(async()=>{},[]),ensureReady:d,resetTranscript:(0,Y.useCallback)(()=>{a(``),s(null)},[])}}var Eu=Gr(`useWhisperSpeech`),Du=150;function Ou(e){let t=new URLSearchParams;return t.set(`model`,e),`/api/voice-model/download?${t.toString()}`}function ku(){if(typeof SharedArrayBuffer>`u`)return 1;let e=navigator.hardwareConcurrency;return!e||e<=2?1:e<=4?2:Math.min(4,e-2)}function Au(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function ju(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(0),[m,h]=(0,Y.useState)(()=>dn()),g=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),b=(0,Y.useRef)(null),x=(0,Y.useRef)(!1),S=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=(0,Y.useRef)(!1),T=(0,Y.useCallback)(e=>{w.current=e,a(e)},[]);(0,Y.useEffect)(()=>{if(typeof window>`u`)return;function e(e){e.key===`tarsk.general.voiceModel`&&h(dn())}function t(){h(dn())}return window.addEventListener(`storage`,e),window.addEventListener(`tarsk:voice-model-changed`,t),()=>{window.removeEventListener(`storage`,e),window.removeEventListener(`tarsk:voice-model-changed`,t)}},[]),(0,Y.useEffect)(()=>{g.current=null,_.current=null,C.current=null,T(!1),p(0),d(null),t(`idle`)},[m,T]),(0,Y.useEffect)(()=>()=>{S.current!==null&&window.clearTimeout(S.current),v.current&&v.current.getTracks().forEach(e=>e.stop())},[]);let E=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`needs-model`||e===`error`)return e;if(C.current)return C.current;let n=Ou(m);async function i(){t(`checking-support`),T(!1),p(0),d(null),Eu.separator(`VOICE SESSION START`),Eu.info(`Checking WASM support`,{userAgent:navigator.userAgent,platform:navigator.platform,model:m,url:n});try{let e=new Jr;g.current=e;let i=await e.checkWasmSupport();if(Eu.info(`WASM SIMD support check result`,{supported:i}),r(i),!i)return Eu.error(`WASM SIMD not supported — voice input disabled`),t(`error`),d(`WebAssembly SIMD is not supported in this environment.`),`error`;let a=new Kr;_.current=a,Eu.info(`Checking IndexedDB model cache`,{url:n});try{let r=await a.loadModelByUrl(n);return Eu.info(`Cached model found — initializing WASM`,{sizeBytes:r.byteLength,sizeMB:(r.byteLength/1024/1024).toFixed(2),model:m}),T(!0),t(`initializing`),await e.initModel(r),Eu.info(`WASM model initialized from cache — ready`),t(`ready`),`ready`}catch(e){return Eu.info(`Model not in cache — download required`,{reason:e instanceof Error?e.message:String(e),model:m}),t(`needs-model`),`needs-model`}}catch(e){let n=e instanceof Error?e.message:`Unknown error`;return Eu.error(`Failed to check speech recognition support`,{error:n}),t(`error`),d(`Failed to check speech recognition support: ${n}`),`error`}}let a=i();C.current=a;try{return await a}finally{C.current=null}},[e,m,T]),D=(0,Y.useCallback)(async()=>{if(!g.current||!_.current)return;let e=Ou(m);t(`downloading-model`),p(0),d(null),Eu.info(`Model download requested`,{url:e,model:m});try{let n=await _.current.loadModelByUrl(e,e=>{p(e),e%10==0&&Eu.debug(`Model download progress`,{progress:e,model:m})});Eu.info(`Model download complete — initializing WASM`,{sizeBytes:n.byteLength,sizeMB:(n.byteLength/1024/1024).toFixed(2),model:m}),t(`initializing`),await g.current.initModel(n),Eu.info(`WASM model initialized after download — ready`),T(!0),t(`ready`)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred.`;Eu.error(`Model download or initialization failed`,{error:n,model:m}),t(`needs-model`),d(n)}},[m,T]),O=(0,Y.useCallback)(async()=>{if(!(!g.current||!w.current)){if(x.current=!1,t(`requesting-mic`),d(null),l(``),Eu.separator(`RECORDING START`),Eu.info(`Requesting microphone access`),!navigator.mediaDevices?.getUserMedia){Eu.error(`navigator.mediaDevices.getUserMedia not available in this environment`),t(`ready`),s(!1),d(`Microphone is not available in this environment.`);return}try{let e=Au(),n=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}}),r=n.getAudioTracks();Eu.info(`Microphone access granted`,{durationMs:Math.round(Au()-e),trackCount:r.length,tracks:r.map(e=>({label:e.label,readyState:e.readyState,settings:e.getSettings()}))}),v.current=n,s(!0);let i=new AbortController;y.current=i,t(`recording`),Eu.info(`Recording started`),b.current=Yr(n,{signal:i.signal,recordingDurationMs:12e4,logLevel:0},{onError:e=>{Eu.error(`Audio conversion error during recording`,{error:e instanceof Error?e.message:String(e)})}})}catch(e){if(t(`ready`),e instanceof DOMException&&e.name===`NotAllowedError`)Eu.error(`Microphone access denied (NotAllowedError)`),s(!1),d(`Microphone access was denied. Please allow microphone access to use voice input.`);else if(e instanceof DOMException&&e.name===`NotFoundError`)Eu.error(`No microphone found (NotFoundError)`),s(!1),d(`No microphone was found. Please connect a microphone to use voice input.`);else{let t=e instanceof Error?e.message:`Unknown error`;Eu.error(`Microphone error`,{error:t,type:e instanceof DOMException?e.name:typeof e}),d(`Microphone error: ${t}`)}}}},[]),k=(0,Y.useCallback)(async()=>{if(!b.current){Eu.info(`stopListening called but no active recording`),v.current&&=(v.current.getTracks().forEach(e=>e.stop()),null),w.current&&t(`ready`);return}Eu.info(`Stopping recording — waiting for audio data`);let e=Au();y.current?.abort(),t(`transcribing`);try{let n=Au(),r=await b.current;if(x.current){Eu.info(`Transcription cancelled by user`),t(`ready`);return}let i=(r.audioData.length/16e3).toFixed(2),a=Math.round(Au()-n);Eu.info(`Audio capture complete — starting transcription`,{sampleCount:r.audioData.length,durationSec:i,sampleRate:16e3,conversionDurationMs:a,stopToConversionReadyMs:Math.round(Au()-e)}),v.current&&=(v.current.getTracks().forEach(e=>e.stop()),null);let o=Au(),s=ku(),c=g.current.createSession(),u=``,d=``,f=null;function p(e=!1){if(!d)return;let t=d.trim();if(e){S.current!==null&&(window.clearTimeout(S.current),S.current=null),d=``,l(t);return}S.current===null&&(S.current=window.setTimeout(()=>{S.current=null;let e=d.trim();d=``,e&&l(e)},Du))}let m=c.streaming(r.audioData,{language:`en`,threads:s,translate:!1}),h=``,_=0;for await(let e of m){if(x.current)break;_++,f===null&&(f=Math.round(Au()-o)),u+=e.text.trim()+` `,h=u,d=h,Eu.debug(`Transcription segment received`,{index:_,text:e.text,timeStart:e.timeStart,timeEnd:e.timeEnd}),p()}p(!0),Eu.info(`Transcription complete`,{segmentCount:_,durationMs:Math.round(Au()-o),timeToFirstSegmentMs:f,threadCount:s,totalStopToReadyMs:Math.round(Au()-e),textLength:h.trim().length,text:h.trim().slice(0,100)}),t(`ready`)}catch(e){if(x.current){t(`ready`);return}let n=e instanceof Error?e.message:`Unknown transcription error`;if(Eu.error(`Transcription failed`,{error:n,errorType:e instanceof Error?e.constructor.name:typeof e,stack:e instanceof Error?e.stack?.split(`
|
|
30
|
+
`).slice(0,5).join(` | `):void 0}),g.current&&n.includes(`Aborted`)){Eu.info(`WASM aborted — reinitializing model for next attempt`),t(`initializing`);try{await g.current.restartModel(),Eu.info(`WASM reinitialized successfully`)}catch(e){Eu.error(`WASM reinitialization failed`,{error:e instanceof Error?e.message:String(e)})}}t(`ready`),d(`Transcription failed: ${n}`)}finally{S.current!==null&&(window.clearTimeout(S.current),S.current=null),b.current=null,y.current=null}},[]),A=(0,Y.useCallback)(()=>{l(``),d(null)},[]);return{state:e,isSupported:n===!0,isWasmSupported:n,isModelLoaded:i,isMicrophoneAvailable:o,transcript:c,error:u,downloadProgress:f,startListening:O,stopListening:k,requestModelDownload:D,ensureReady:E,resetTranscript:A}}function Mu(){let e=(0,X.c)(22),t=ju(),n=Tu();if(!Xe()){let n;return e[0]!==t.downloadProgress||e[1]!==t.ensureReady||e[2]!==t.error||e[3]!==t.isWasmSupported||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.isWasmSupported,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.isWasmSupported,e[4]=t.requestModelDownload,e[5]=t.resetTranscript,e[6]=t.startListening,e[7]=t.state,e[8]=t.stopListening,e[9]=t.transcript,e[10]=n):n=e[10],n}let r;return e[11]!==n.downloadProgress||e[12]!==n.ensureReady||e[13]!==n.error||e[14]!==n.isSupported||e[15]!==n.requestModelDownload||e[16]!==n.resetTranscript||e[17]!==n.startListening||e[18]!==n.state||e[19]!==n.stopListening||e[20]!==n.transcript?(r={state:n.state,isSupported:n.isSupported,usesLocalModel:!1,transcript:n.transcript,error:n.error,downloadProgress:n.downloadProgress,startListening:n.startListening,stopListening:n.stopListening,requestModelDownload:n.requestModelDownload,ensureReady:n.ensureReady,resetTranscript:n.resetTranscript},e[11]=n.downloadProgress,e[12]=n.ensureReady,e[13]=n.error,e[14]=n.isSupported,e[15]=n.requestModelDownload,e[16]=n.resetTranscript,e[17]=n.startListening,e[18]=n.state,e[19]=n.stopListening,e[20]=n.transcript,e[21]=r):r=e[21],r}var Nu=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=q(`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)(Cr,{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)(zn,{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});Nu.displayName=zn.displayName;var Pu=75;function Fu(e){let t=(0,X.c)(11),{open:n,onOpenChange:r,onConfirm:i,downloading:a,progress:o,error:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsxs)(E,{children:[(0,$.jsx)(I,{children:`Download Voice Model`}),(0,$.jsxs)(pe,{children:[`To enable voice-to-text, a voice model needs to be downloaded. This is a one-time download of approximately `,Pu,`MB. The model will be cached locally for future use.`]})]}),t[0]=l):l=t[0];let u;t[1]!==a||t[2]!==c||t[3]!==i||t[4]!==r||t[5]!==o?(u=(0,$.jsxs)(ce,{children:[l,a?(0,$.jsxs)(`div`,{className:`space-y-3 py-4`,children:[(0,$.jsx)(Nu,{value:o,className:`w-full`}),(0,$.jsx)(`p`,{className:q(s.bodyMuted,`text-center`),children:o<100?`Downloading model... ${o}%`:`Initializing model...`})]}):c?(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(Ur,{variant:`error`,className:`mb-0`,children:c}),(0,$.jsxs)(be,{children:[(0,$.jsx)(W,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(W,{onClick:i,children:`Try Again`})]})]}):(0,$.jsxs)(be,{children:[(0,$.jsx)(W,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(W,{onClick:i,children:`Download Model`})]})]}),t[1]=a,t[2]=c,t[3]=i,t[4]=r,t[5]=o,t[6]=u):u=t[6];let d;return t[7]!==r||t[8]!==n||t[9]!==u?(d=(0,$.jsx)(Rt,{open:n,onOpenChange:r,children:u}),t[7]=r,t[8]=n,t[9]=u,t[10]=d):d=t[10],d}var Iu=Pr(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`]}),Lu=function(e){let t=(0,X.c)(67),{onTranscript:n,children:r}=e,{state:i,isSupported:a,usesLocalModel:o,transcript:s,error:c,downloadProgress:l,startListening:u,stopListening:d,requestModelDownload:f,ensureReady:p,resetTranscript:m}=Mu(),{toast:h}=ma(),[g,_]=(0,Y.useState)(!1),v=(0,Y.useRef)(``),y=(0,Y.useRef)(null),b=i===`recording`,x=i===`transcribing`,S=b||x,C=i===`needs-model`,w=i===`downloading-model`||i===`initializing`,T=i===`checking-support`,E,D;t[0]!==g||t[1]!==c||t[2]!==h?(E=()=>{c&&c!==y.current&&!g&&h({title:`Voice Input Error`,description:c,variant:`destructive`}),y.current=c},D=[c,g,h],t[0]=g,t[1]=c,t[2]=h,t[3]=E,t[4]=D):(E=t[3],D=t[4]),(0,Y.useEffect)(E,D);let O,k;t[5]!==n||t[6]!==s?(O=()=>{if(s&&s!==v.current){let e=s.substring(v.current.length);v.current=s,n(e)}},k=[s,n],t[5]=n,t[6]=s,t[7]=O,t[8]=k):(O=t[7],k=t[8]),(0,Y.useEffect)(O,k);let A,j;t[9]===s?(A=t[10],j=t[11]):(A=()=>{s||(v.current=``)},j=[s],t[9]=s,t[10]=A,t[11]=j),(0,Y.useEffect)(A,j);let M;t[12]!==p||t[13]!==S||t[14]!==C||t[15]!==m||t[16]!==u||t[17]!==i||t[18]!==d?(M=async()=>{if(S){d();return}if(C){_(!0);return}if(i===`ready`){m(),u();return}if(i===`idle`){let e=await p();e===`needs-model`?_(!0):e===`ready`&&(m(),u())}},t[12]=p,t[13]=S,t[14]=C,t[15]=m,t[16]=u,t[17]=i,t[18]=d,t[19]=M):M=t[19];let P=M,F;t[20]===f?F=t[21]:(F=()=>{f()},t[20]=f,t[21]=F);let I=F,L,R;t[22]!==g||t[23]!==i?(R=()=>{i===`ready`&&g&&_(!1)},L=[i,g],t[22]=g,t[23]=i,t[24]=L,t[25]=R):(L=t[24],R=t[25]),(0,Y.useEffect)(R,L);let ee;t[26]!==c||t[27]!==T||t[28]!==w||t[29]!==b||t[30]!==a||t[31]!==x||t[32]!==C?(ee=()=>T?`Checking voice input support...`:a===!1?`Voice input not supported in this browser`:c||(w?`Downloading speech model...`:x?`Transcribing...`:b?`Stop listening`:C?`Click to download speech model`:`Start listening`),t[26]=c,t[27]=T,t[28]=w,t[29]=b,t[30]=a,t[31]=x,t[32]=C,t[33]=ee):ee=t[33];let z=ee,te;t[34]!==w||t[35]!==b||t[36]!==x?(te=()=>w||x?(0,$.jsx)(N,{className:`h-3 w-3 animate-spin`}):b?(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)(ae,{className:`h-3 w-3`}),t[34]=w,t[35]=b,t[36]=x,t[37]=te):te=t[37];let ne=te,re,ie;t[38]!==r||t[39]!==ne||t[40]!==z||t[41]!==P||t[42]!==T||t[43]!==w||t[44]!==b||t[45]!==a||t[46]!==x||t[47]!==C?(re=z(),ie=r({onClick:P,disabled:T||w||x||a===!1,icon:ne(),label:re,isRecording:b,isTranscribing:x,isDownloading:w,needsModel:C,isSupported:a!==!1}),t[38]=r,t[39]=ne,t[40]=z,t[41]=P,t[42]=T,t[43]=w,t[44]=b,t[45]=a,t[46]=x,t[47]=C,t[48]=re,t[49]=ie):(re=t[48],ie=t[49]);let oe=ie,se;t[50]===oe?se=t[51]:(se=(0,$.jsx)(Fn,{asChild:!0,children:oe}),t[50]=oe,t[51]=se);let ce;t[52]===re?ce=t[53]:(ce=(0,$.jsx)(H,{side:`top`,className:`bg-popover text-popover-foreground max-w-64`,children:re}),t[52]=re,t[53]=ce);let le;t[54]!==se||t[55]!==ce?(le=(0,$.jsxs)(kt,{children:[se,ce]}),t[54]=se,t[55]=ce,t[56]=le):le=t[56];let ue;t[57]!==g||t[58]!==l||t[59]!==c||t[60]!==I||t[61]!==w||t[62]!==o?(ue=o?(0,$.jsx)(Fu,{open:g,onOpenChange:_,onConfirm:I,downloading:w,progress:l,error:c}):null,t[57]=g,t[58]=l,t[59]=c,t[60]=I,t[61]=w,t[62]=o,t[63]=ue):ue=t[63];let de;return t[64]!==le||t[65]!==ue?(de=(0,$.jsx)(Iu,{v0:le,v1:ue}),t[64]=le,t[65]=ue,t[66]=de):de=t[66],de};function Ru(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:q(s.compact,s.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:q(s.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)(z,{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)(Ur,{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 zu(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,S;t[0]!==y||t[1]!==d?(b=()=>{d(y)},S=[y,d],t[0]=y,t[1]=d,t[2]=b,t[3]=S):(b=t[2],S=t[3]),(0,Y.useEffect)(b,S);let C=!f&&!y&&((p??!1)||!m&&r||!u&&h>0&&!g||u&&!g),w;t[4]!==m||t[5]!==f||t[6]!==y||t[7]!==v||t[8]!==n||t[9]!==_?(w=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]=w):w=t[10];let T=w,E=f?`Stop generation`:y?a:m?`Send message`:a,D=`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-['']`:``}`,O;t[11]!==m||t[12]!==i||t[13]!==f||t[14]!==y?(O=f?(0,$.jsx)(`span`,{className:`block h-3 w-3 shrink-0 rounded-[2px] bg-current`,"aria-hidden":`true`}):y||!m?i:(0,$.jsx)(x,{className:`h-3 w-3`}),t[11]=m,t[12]=i,t[13]=f,t[14]=y,t[15]=O):O=t[15];let k;t[16]===E?k=t[17]:(k=(0,$.jsx)(`span`,{className:`sr-only`,children:E}),t[16]=E,t[17]=k);let A;t[18]===l?A=t[19]:(A=!l&&(0,$.jsx)(`span`,{className:`sr-only`,children:`Voice input not supported`}),t[18]=l,t[19]=A);let j;return t[20]!==T||t[21]!==C||t[22]!==D||t[23]!==O||t[24]!==k||t[25]!==A?(j=(0,$.jsxs)(W,{size:`icon`,className:D,onClick:T,disabled:C,children:[O,k,A]}),t[20]=T,t[21]=C,t[22]=D,t[23]=O,t[24]=k,t[25]=A,t[26]=j):j=t[26],j}function Bu(e){let t=(0,X.c)(172),{onSend:n,onStop:r,isStreaming:i,disabled:o,initialValue:c,queuedMessages:l,onRemoveQueuedMessage:u,isOverlay:d,userTasks:f,onMatchedUserTaskSend:p,onUserTaskCreated:m}=e,h=i===void 0?!1:i,g=d===void 0?!1:d,_;t[0]===f?_=t[1]:(_=f===void 0?[]:f,t[0]=f,t[1]=_);let v=_,y=Q(Yu),b;t[2]===c?b=t[3]:(b={initialValue:c},t[2]=c,t[3]=b);let{message:x,setMessage:S,historyIndex:C,setHistoryIndex:w,draftMessage:T,setDraftMessage:E,cursorPosition:D,setCursorPosition:O,availableModels:k,selectedModel:A,setSelectedModel:j,attachments:M,setAttachments:N,planMode:P,setPlanMode:F,ralphMode:I,setRalphMode:L,imageMode:R,setImageMode:ee,availableImageModels:z,selectedImageModel:te,setSelectedImageModel:ne,allFiles:re,setAllFiles:ie,showSuggestions:ae,setShowSuggestions:oe,suggestionQuery:se,setSuggestionQuery:ce,selectedIndex:le,setSelectedIndex:ue,slashCommands:de,skills:fe,showCommandSuggestions:pe,setShowCommandSuggestions:me,commandQuery:B,setCommandQuery:he,fileInputRef:ge,textareaRef:_e,suggestionsRef:ve,commandSuggestionsRef:ye,selectedThreadId:be,dispatch:xe}=Al(b),Se=Q(Ju),Ce=Q(qu),we;t[4]===Se?we=t[5]:(we=Se.some(Ku),t[4]=Se,t[5]=we);let Te=we,Ee=R?te:A,V=R?z:k,De;t[6]===x?De=t[7]:(De=x.trim(),t[6]=x,t[7]=De);let Oe=De.length>0,ke=Oe||M.length>0,[Ae,je]=Y.useState(!1),Me=Ll(),Ne=be??void 0,Pe;t[8]!==re||t[9]!==M||t[10]!==B||t[11]!==D||t[12]!==xe||t[13]!==T||t[14]!==Te||t[15]!==C||t[16]!==R||t[17]!==h||t[18]!==x||t[19]!==p||t[20]!==n||t[21]!==P||t[22]!==I||t[23]!==te||t[24]!==le||t[25]!==A||t[26]!==ie||t[27]!==N||t[28]!==he||t[29]!==O||t[30]!==E||t[31]!==w||t[32]!==ee||t[33]!==S||t[34]!==F||t[35]!==L||t[36]!==ue||t[37]!==me||t[38]!==oe||t[39]!==ce||t[40]!==pe||t[41]!==ae||t[42]!==fe||t[43]!==de||t[44]!==se||t[45]!==Ne||t[46]!==_e||t[47]!==v?(Pe={message:x,setMessage:S,userTasks:v,onMatchedUserTaskSend:p,attachments:M,selectedModel:A,onSend:n,isStreaming:h,selectedThreadId:Ne,isListening:!1,stopListening:Gu,resetTranscript:Wu,dispatch:xe,historyIndex:C,setHistoryIndex:w,draftMessage:T,setDraftMessage:E,cursorPosition:D,setCursorPosition:O,showSuggestions:ae,setShowSuggestions:oe,suggestionQuery:se,setSuggestionQuery:ce,allFiles:re,setAllFiles:ie,selectedIndex:le,setSelectedIndex:ue,showCommandSuggestions:pe,setShowCommandSuggestions:me,commandQuery:B,setCommandQuery:he,slashCommands:de,skills:fe,textareaRef:_e,setAttachments:N,planMode:P,setPlanMode:F,ralphMode:I,setRalphMode:L,imageMode:R,setImageMode:ee,selectedImageModel:te,hasConversationMessages:Te},t[8]=re,t[9]=M,t[10]=B,t[11]=D,t[12]=xe,t[13]=T,t[14]=Te,t[15]=C,t[16]=R,t[17]=h,t[18]=x,t[19]=p,t[20]=n,t[21]=P,t[22]=I,t[23]=te,t[24]=le,t[25]=A,t[26]=ie,t[27]=N,t[28]=he,t[29]=O,t[30]=E,t[31]=w,t[32]=ee,t[33]=S,t[34]=F,t[35]=L,t[36]=ue,t[37]=me,t[38]=oe,t[39]=ce,t[40]=pe,t[41]=ae,t[42]=fe,t[43]=de,t[44]=se,t[45]=Ne,t[46]=_e,t[47]=v,t[48]=Pe):Pe=t[48];let{handleSend:Fe,handleKeyDown:Ie,handleTextareaInput:Le,insertFileReference:Re,insertCommand:ze,insertSkill:Be,fileSuggestions:Ve}=Ml(Pe),He;t[49]===S?He=t[50]:(He=e=>{S(t=>(t.endsWith(` `),t+e))},t[49]=S,t[50]=He);let Ue=He,We;t[51]===N?We=t[52]:(We=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(Uu);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];N(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[51]=N,t[52]=We);let Ge=We,Ke=g?`absolute inset-x-0 bottom-0 mx-auto w-full max-w-3xl max-md:px-2 px-4 pb-4 pointer-events-none`:`relative mx-auto w-full max-w-3xl max-md:px-0 pb-2 md:px-4 md:pb-4 md:-mx-[6px]`,qe=`flex flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto ${g?`border-border/50 shadow-lg backdrop-blur-sm`:`border-border shadow-2xl`}`,Je;t[53]!==g||t[54]!==y?(Je=kl(y,g),t[53]=g,t[54]=y,t[55]=Je):Je=t[55];let Ye;t[56]===Je?Ye=t[57]:(Ye={backgroundImage:Je},t[56]=Je,t[57]=Ye);let Xe;t[58]!==u||t[59]!==l?(Xe=(0,$.jsx)(Ru,{queuedMessages:l,onRemoveQueuedMessage:u}),t[58]=u,t[59]=l,t[60]=Xe):Xe=t[60];let Ze=I?`Describe stories for Ralph to implement autonomously...`:P?`Describe what you want Tarsk to plan...`:R?`Describe the image you want to generate...`:Ae?`Dictate your message...`:`Ask Tarsk anything, # for files, / for commands & skills`,Qe;t[61]===Symbol.for(`react.memo_cache_sentinel`)?(Qe=q(s.body,`min-h-[4.5rem] w-full resize-none bg-transparent px-6 pt-4 pb-4 text-foreground placeholder:text-muted-foreground focus:outline-none`),t[61]=Qe):Qe=t[61];let $e;t[62]!==o||t[63]!==Ie||t[64]!==Ge||t[65]!==Le||t[66]!==x||t[67]!==Ze||t[68]!==_e?($e=(0,$.jsx)(`textarea`,{ref:_e,value:x,onChange:Le,onKeyDown:Ie,onPaste:Ge,placeholder:Ze,rows:1,className:Qe,disabled:o}),t[62]=o,t[63]=Ie,t[64]=Ge,t[65]=Le,t[66]=x,t[67]=Ze,t[68]=_e,t[69]=$e):$e=t[69];let tt;t[70]!==B||t[71]!==ye||t[72]!==ze||t[73]!==Be||t[74]!==le||t[75]!==ue||t[76]!==pe||t[77]!==fe||t[78]!==de?(tt=(0,$.jsx)(zl,{visible:pe,commands:de,skills:fe,query:B,selectedIndex:le,onSelectCommand:ze,onSelectSkill:Be,onMouseEnterSuggestion:ue,containerRef:ye}),t[70]=B,t[71]=ye,t[72]=ze,t[73]=Be,t[74]=le,t[75]=ue,t[76]=pe,t[77]=fe,t[78]=de,t[79]=tt):tt=t[79];let nt;t[80]!==Ve||t[81]!==Re||t[82]!==le||t[83]!==ue||t[84]!==ae||t[85]!==se||t[86]!==ve?(nt=(0,$.jsx)(ru,{showSuggestions:ae,fileSuggestions:Ve,suggestionQuery:se,selectedIndex:le,onSelectFile:Re,onMouseEnterSuggestion:ue,containerRef:ve}),t[80]=Ve,t[81]=Re,t[82]=le,t[83]=ue,t[84]=ae,t[85]=se,t[86]=ve,t[87]=nt):nt=t[87];let rt;t[88]!==M||t[89]!==A?.id||t[90]!==A?.name||t[91]!==A?.supportsImages||t[92]!==N?(rt=M.length>0&&(0,$.jsxs)(`div`,{className:`px-4`,children:[(0,$.jsx)(Ul,{attachments:M,onRemove:e=>N(t=>t.filter((t,n)=>n!==e))}),M.some(Hu)&&A?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:q(s.compact,`mb-2 flex items-center gap-1.5 text-amber-500`),children:[(0,$.jsx)(et,{className:`h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[`Images are not supported by `,A?.name||A?.id]})]})]}),t[88]=M,t[89]=A?.id,t[90]=A?.name,t[91]=A?.supportsImages,t[92]=N,t[93]=rt):rt=t[93];let it;t[94]===ge?it=t[95]:(it=()=>ge.current?.click(),t[94]=ge,t[95]=it);let at;t[96]!==xe||t[97]!==x||t[98]!==m||t[99]!==N||t[100]!==S||t[101]!==be||t[102]!==_e?(at=()=>{let e=be;if(!e)return;let t=x.trim();t&&a(e,t).then(t=>{m?.(t),S(``),N([]),xe({type:Z.ClearChatInputDraft,threadId:e}),_e.current&&(_e.current.style.height=`auto`)}).catch(Vu)},t[96]=xe,t[97]=x,t[98]=m,t[99]=N,t[100]=S,t[101]=be,t[102]=_e,t[103]=at):at=t[103];let ot;t[104]!==o||t[105]!==Oe||t[106]!==R||t[107]!==Me||t[108]!==P||t[109]!==I||t[110]!==Ce||t[111]!==ee||t[112]!==F||t[113]!==L||t[114]!==it||t[115]!==at?(ot=(0,$.jsx)(vu,{disabled:o,canAddTask:Oe,showModes:Me,planMode:P,imageMode:R,ralphMode:I,setPlanMode:F,setImageMode:ee,setRalphMode:L,projectId:Ce,onFileAttach:it,onAddTask:at}),t[104]=o,t[105]=Oe,t[106]=R,t[107]=Me,t[108]=P,t[109]=I,t[110]=Ce,t[111]=ee,t[112]=F,t[113]=L,t[114]=it,t[115]=at,t[116]=ot):ot=t[116];let H=R?ne:j,st;t[117]!==V||t[118]!==Ee||t[119]!==H?(st=(0,$.jsx)(du,{availableModels:V,selectedModel:Ee,onModelSelect:H}),t[117]=V,t[118]=Ee,t[119]=H,t[120]=st):st=t[120];let ct;t[121]!==ot||t[122]!==st?(ct=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ot,st]}),t[121]=ot,t[122]=st,t[123]=ct):ct=t[123];let lt;t[124]!==R||t[125]!==P||t[126]!==I||t[127]!==Ce||t[128]!==ee||t[129]!==F||t[130]!==L?(lt=(0,$.jsx)(_u,{planMode:P,imageMode:R,ralphMode:I,setPlanMode:F,setImageMode:ee,setRalphMode:L,projectId:Ce}),t[124]=R,t[125]=P,t[126]=I,t[127]=Ce,t[128]=ee,t[129]=F,t[130]=L,t[131]=lt):lt=t[131];let U=be??void 0,ut;t[132]!==Se||t[133]!==U?(ut=(0,$.jsx)(tu,{threadId:U,messages:Se}),t[132]=Se,t[133]=U,t[134]=ut):ut=t[134];let dt;t[135]!==M.length||t[136]!==ke||t[137]!==o||t[138]!==Ee||t[139]!==Fe||t[140]!==Oe||t[141]!==h||t[142]!==r?(dt=e=>{let{onClick:t,disabled:n,icon:i,label:a,isRecording:s,isTranscribing:c,isDownloading:l,isSupported:u}=e;return(0,$.jsx)(zu,{onSpeechClick:t,speechDisabled:n,icon:i,label:a,isRecording:s,isTranscribing:c,isDownloading:l,isSupported:u,hasMessageText:Oe,setIsVoiceActive:je,isStreaming:h,disabled:o,canSubmitMessage:ke,attachmentsLength:M.length,effectiveModel:Ee,onStop:r,onSend:Fe})},t[135]=M.length,t[136]=ke,t[137]=o,t[138]=Ee,t[139]=Fe,t[140]=Oe,t[141]=h,t[142]=r,t[143]=dt):dt=t[143];let ft;t[144]!==Ue||t[145]!==dt?(ft=(0,$.jsx)(Lu,{onTranscript:Ue,children:dt}),t[144]=Ue,t[145]=dt,t[146]=ft):ft=t[146];let pt;t[147]!==lt||t[148]!==ut||t[149]!==ft?(pt=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[lt,ut,ft]}),t[147]=lt,t[148]=ut,t[149]=ft,t[150]=pt):pt=t[150];let mt;t[151]!==ct||t[152]!==pt?(mt=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[ct,pt]}),t[151]=ct,t[152]=pt,t[153]=mt):mt=t[153];let ht;t[154]!==qe||t[155]!==Ye||t[156]!==Xe||t[157]!==$e||t[158]!==tt||t[159]!==nt||t[160]!==rt||t[161]!==mt?(ht=(0,$.jsxs)(`div`,{className:qe,style:Ye,children:[Xe,$e,tt,nt,rt,mt]}),t[154]=qe,t[155]=Ye,t[156]=Xe,t[157]=$e,t[158]=tt,t[159]=nt,t[160]=rt,t[161]=mt,t[162]=ht):ht=t[162];let gt;t[163]===N?gt=t[164]:(gt=e=>nu(e,e=>N(t=>[...t,...e])),t[163]=N,t[164]=gt);let _t;t[165]!==ge||t[166]!==gt?(_t=(0,$.jsx)(`input`,{ref:ge,type:`file`,multiple:!0,className:`hidden`,onChange:gt}),t[165]=ge,t[166]=gt,t[167]=_t):_t=t[167];let vt;return t[168]!==Ke||t[169]!==ht||t[170]!==_t?(vt=(0,$.jsxs)(`div`,{className:Ke,children:[ht,_t]}),t[168]=Ke,t[169]=ht,t[170]=_t,t[171]=vt):vt=t[171],vt}function Vu(e){console.error(`Failed to create user task:`,e)}function Hu(e){return e.mimeType.startsWith(`image/`)}function Uu(e){return e.type.startsWith(`image/`)}function Wu(){}function Gu(){}function Ku(e){return e.sender===`agent`}function qu(e){return e.selectedProjectId}function Ju(e){return e.messages}function Yu(e){return e.sidebarOpen}var Xu=`[gitops-timing]`;function Zu(e){let t=[],n=performance.now();async function r(n,r){let i=performance.now();try{return await r()}finally{let r=Math.round(performance.now()-i);t.push({step:n,ms:r}),console.log(`${Xu} ${e} step=${n} ${r}ms`)}}function i(n,r,i){t.push({step:n,ms:r}),console.log(`${Xu} ${e} step=${n} ${r}ms${i?` ${i}`:``}`)}function a(r){let i=Math.round(performance.now()-n),a=t.reduce((e,t)=>t.ms>=e.ms?t:e,{step:`none`,ms:0}),o=t.map(e=>`${e.step}:${e.ms}`).join(` `);console.log(`${Xu} ${e} summary total=${i}ms slowest=${a.step}@${a.ms}ms breakdown=[${o}]${r?` ${r}`:``}`)}return{step:r,record:i,summary:a}}var Qu=3e4,$u={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},ed=new Map,td=new Map;function nd(e,t){let n=ed.get(e);if(n)for(let e of n)e(t)}function rd(e,t){let n=ed.get(e);return n||(n=new Set,ed.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&ed.delete(e)}}function id(e){return`unified-git-status-${e}`}function ad(e){return T.getSync(id(e))}function od(e){let[t,n]=(0,Y.useState)($u),[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=Zu(`hook fetch thread=${e} force=${t}`),a=setTimeout(()=>{o.current===n&&i(!0)},100);try{let i=id(e),a=performance.now(),c=ad(e);r.record(`local-cache-check`,Math.round(performance.now()-a),`result=${c?`hit`:`miss`}`),t&&(T.invalidate(i),r.record(`invalidate-local-cache`,0));let l=await r.step(`ttl-cache-get`,()=>T.get(i,()=>xe(e,t,!1),Qu));if(o.current!==n){r.summary(`stale-request`);return}await r.step(`update-state`,async()=>{s(l),nd(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 rd(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($u)});return}let t=a.current!==e,r=ad(e);t&&(console.log(`[gitops-timing] hook thread changed ${a.current??`none`} -> ${e}`),a.current=e),(0,Y.startTransition)(()=>{n(r??$u)}),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=td.get(s);if(e){console.log(`[gitops-timing] hook initial fetch already in flight thread=${s}`),e.then(()=>{if(l)return;let e=ad(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}`),td.delete(s)});td.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,isRefreshing:r,fetchUnifiedStatus:l}}var sd=(0,Y.createContext)(void 0);function cd(e){let t=(0,X.c)(8),{threadId:n,fetchUnifiedStatus:r}=e,i=Xi(),a=Q(dd),o=Q(ud),s=Q(ld),c,l;return t[0]!==o||t[1]!==i||t[2]!==r||t[3]!==a||t[4]!==s||t[5]!==n?(c=()=>{if(!(!n||n!==s)&&!a&&o.includes(n)){let e=setTimeout(()=>{r(!1),i({type:Z.ClearThreadCompleted,threadId:n})},1e3);return()=>clearTimeout(e)}},l=[n,s,a,o,r,i],t[0]=o,t[1]=i,t[2]=r,t[3]=a,t[4]=s,t[5]=n,t[6]=c,t[7]=l):(c=t[6],l=t[7]),(0,Y.useEffect)(c,l),null}function ld(e){return e.selectedThreadId}function ud(e){return e.completedThreadIds}function dd(e){return e.isStreaming}function fd(e){let t=(0,X.c)(7),{threadId:n,children:r}=e,i=od(n),a;t[0]!==n||t[1]!==i.fetchUnifiedStatus?(a=(0,$.jsx)(cd,{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)(sd.Provider,{value:i,children:[a,r]}),t[3]=r,t[4]=a,t[5]=i,t[6]=o):o=t[6],o}function pd(){let e=(0,Y.useContext)(sd);if(e===void 0)throw Error(`useGitStatus must be used within a GitStatusProvider`);return e}var md=Pr(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}),hd=function(e){let t=(0,X.c)(2),{completedCount:n,totalCount:r}=e,i=yd*(1-(r>0?n/r:0)),a=gd/2,o;return t[0]===i?o=t[1]:(o=(0,$.jsx)(md,{v0:gd,v1:gd,v2:`0 0 ${gd} ${gd}`,v3:a,v4:a,v5:vd,v6:_d,v7:a,v8:a,v9:vd,v10:_d,v11:yd,v12:i,v13:`rotate(-90 ${a} ${a})`}),t[0]=i,t[1]=o),o},gd=40,_d=4,vd=10,yd=2*Math.PI*vd;function bd(e){let t=(0,X.c)(13),{todos:n}=e,r;t[0]===n?r=t[1]:(r=n.filter(Sd),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:s.compact,children:`No todo items.`}),t[2]=n.length,t[3]=a);let o;t[4]===n?o=t[5]:(o=n.map(xd),t[4]=n,t[5]=o);let c;t[6]!==i||t[7]!==n.length?(c=n.length>0&&(0,$.jsxs)(`p`,{className:q(s.compact,`pt-1`),children:[i,`/`,n.length,` completed`]}),t[6]=i,t[7]=n.length,t[8]=c):c=t[8];let l;return t[9]!==a||t[10]!==o||t[11]!==c?(l=(0,$.jsxs)(`div`,{className:`space-y-1`,children:[a,o,c]}),t[9]=a,t[10]=o,t[11]=c,t[12]=l):l=t[12],l}function xd(e){return(0,$.jsxs)(`div`,{className:q(s.caption,`flex items-start gap-2`),children:[e.status===`done`?(0,$.jsx)(Mt,{className:`h-4 w-4 shrink-0 mt-0.5 text-brand`}):e.status===`working`?(0,$.jsx)(Et,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(tn,{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 Sd(e){return e.status===`done`}function Cd(e){let t=(0,X.c)(43),{layout:n}=e,r=n===void 0?`bar`:n,{todos:i}=(0,Y.useContext)(Hs),[a,o]=(0,Y.useState)(!1),s;t[0]===i?s=t[1]:(s=i.filter(wd),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)(hd,{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)(W,{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)(E,{children:(0,$.jsx)(I,{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)(bd,{todos:i})]}),t[12]=i,t[13]=d);let f;t[14]!==a||t[15]!==d?(f=(0,$.jsx)(Rt,{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)(hd,{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)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{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)(H,{children:u}),t[29]=u,t[30]=h);let g;t[31]!==m||t[32]!==h?(g=(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{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)(E,{children:(0,$.jsx)(I,{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)(bd,{todos:i})]}),t[35]=i,t[36]=v);let y;t[37]!==a||t[38]!==v?(y=(0,$.jsx)(Rt,{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 wd(e){return e.status===`done`}function Td(e){let t=(0,X.c)(30),{tasks:n,disabled:r,onSelectTask:i,onRemoveTask:a,layout:o}=e,c=r===void 0?!1:r,l=o===void 0?`bar`:o,[u,d]=(0,Y.useState)(!1),f=n.length,p=`${f} Pending ${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]!==a||t[3]!==f?(g=function(e){a(e),f===1&&d(!1)},t[2]=a,t[3]=f,t[4]=g):g=t[4];let _=g,v=l===`menu`?`ghost`:`outline`,y=l===`bar`&&`bg-background`,b=l===`menu`&&`w-full justify-start`,x;t[5]!==y||t[6]!==b?(x=q(`gap-2`,y,b),t[5]=y,t[6]=b,t[7]=x):x=t[7];let S;t[8]===p?S=t[9]:(S=(0,$.jsx)(`span`,{children:p}),t[8]=p,t[9]=S);let C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(ot,{className:`h-4 w-4 shrink-0`}),t[10]=C):C=t[10];let w;t[11]!==c||t[12]!==v||t[13]!==x||t[14]!==S?(w=(0,$.jsx)(bs,{asChild:!0,children:(0,$.jsxs)(W,{variant:v,size:`sm`,className:x,disabled:c,children:[S,C]})}),t[11]=c,t[12]=v,t[13]=x,t[14]=S,t[15]=w):w=t[15];let T;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`div`,{className:q(s.compact,s.label,`px-2 pb-1 pt-1 text-muted-foreground`),children:`Tasks`}),t[16]=T):T=t[16];let E;if(t[17]!==_||t[18]!==h||t[19]!==n){let e;t[21]!==_||t[22]!==h?(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)(vt,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:q(s.body,`line-clamp-3 text-foreground`),children:e.content})]}),(0,$.jsxs)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:()=>_(e.id),children:[(0,$.jsx)(z,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove task`})]})]},e.id),t[21]=_,t[22]=h,t[23]=e):e=t[23],E=n.map(e),t[17]=_,t[18]=h,t[19]=n,t[20]=E}else E=t[20];let D;t[24]===E?D=t[25]:(D=(0,$.jsx)(xs,{align:`start`,className:`w-96 p-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[T,E]})}),t[24]=E,t[25]=D);let O;return t[26]!==u||t[27]!==w||t[28]!==D?(O=(0,$.jsxs)(ys,{open:u,onOpenChange:d,children:[w,D]}),t[26]=u,t[27]=w,t[28]=D,t[29]=O):O=t[29],O}var Ed=(0,Y.createContext)(void 0);function Dd(e){let t=(0,X.c)(24),{children:n}=e,r=Xi(),i=Q(Ad),a=Q(kd),{toast:o}=ma(),s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=[],t[0]=s):s=t[0];let[c,l]=(0,Y.useState)(s),u=Q(Od),d,f;t[1]!==i||t[2]!==o?(d=()=>{if(!i){l([]);return}let e=!1;return(async function(){try{let t=await D(i);e||l(t)}catch(t){e||(console.error(`Failed to load user tasks:`,t),o({title:`Could not load tasks`,description:`Failed to load UserTasks for this thread.`,variant:`destructive`}))}})(),()=>{e=!0}},f=[i,o],t[1]=i,t[2]=o,t[3]=d,t[4]=f):(d=t[3],f=t[4]),(0,Y.useEffect)(d,f);let p;t[5]!==r||t[6]!==i?(p=async()=>{if(i)try{let e=await Dt(i);r({type:Z.ClearMessages}),console.log(`New conversation started:`,e),setTimeout(()=>{(async()=>{try{let e=await wt(i);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[5]=r,t[6]=i,t[7]=p):p=t[7];let m=p,h;t[8]!==i||t[9]!==o?(h=async e=>{if(i)try{await V(i,e),l(t=>t.filter(t=>t.id!==e))}catch(e){console.error(`Failed to delete user task:`,e),o({title:`Could not remove task`,description:`Failed to delete the selected task.`,variant:`destructive`})}},t[8]=i,t[9]=o,t[10]=h):h=t[10];let g=h,_;t[11]!==r||t[12]!==i?(_=e=>{i&&r({type:Z.SetChatInputDraft,threadId:i,draft:e.content})},t[11]=r,t[12]=i,t[13]=_):_=t[13];let v=_,y;t[14]!==u||t[15]!==m||t[16]!==g||t[17]!==v||t[18]!==a||t[19]!==c?(y={userTasks:c,setUserTasks:l,handleNewChat:m,handleSelectUserTask:v,handleRemoveUserTask:g,effectiveIsStreaming:u,isCreatingProject:a},t[14]=u,t[15]=m,t[16]=g,t[17]=v,t[18]=a,t[19]=c,t[20]=y):y=t[20];let b=y,x;return t[21]!==n||t[22]!==b?(x=(0,$.jsx)(Ed.Provider,{value:b,children:n}),t[21]=n,t[22]=b,t[23]=x):x=t[23],x}function Od(e){let t=e.pendingChatMessage?.threadId===e.selectedThreadId;return e.isStreaming||t}function kd(e){return e.isCreatingProject}function Ad(e){return e.selectedThreadId}function jd(){let e=(0,Y.useContext)(Ed);if(e===void 0)throw Error(`useChatInputToolbar must be used within a ChatInputToolbarProvider`);return e}var Md=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)(N,{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)(N,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))};function Nd({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){return t?e.map(([e,t])=>(0,$.jsxs)(pc,{children:[(0,$.jsx)(mc,{children:e}),(0,$.jsx)(hc,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,$.jsxs)(_c,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(N,{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)(_c,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(N,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))}function Pd({threadId:e,layout:t=`bar`}){let n=Xi(),{setTerminalNotification:r}=wo(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(new Set),c=(0,Y.useRef)(new Map);(0,Y.useEffect)(()=>((async()=>{try{let t=await jn(e);if(t.length===0){a(null);return}a(t),s(new Set(t.filter(e=>e.isRunning).map(e=>e.name)))}catch{a(null)}})(),()=>{for(let e of c.current.values())e.abort();c.current.clear()}),[e]);let l=async t=>{if(o.has(t.name)){let r=c.current.get(t.name);r&&(r.abort(),c.current.delete(t.name));try{await Pn(e,t.name)}catch{}n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`■ ${t.friendlyName} stopped`}}),s(e=>{let n=new Set(e);return n.delete(t.name),n})}else{let i=new AbortController;c.current.set(t.name,i),s(e=>new Set([...e,t.name])),r(!0),n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`▶ ${t.friendlyName}`}});try{let r=await un(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{let r=JSON.parse(t);typeof r==`string`?n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:r}}):r.type===`error`&&n({type:Z.AppendTerminalLine,threadId:e,line:{type:`error`,content:r.message}})}catch{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}})}}if(a.trim())try{let t=JSON.parse(a);typeof t==`string`?n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}}):t.type===`error`&&n({type:Z.AppendTerminalLine,threadId:e,line:{type:`error`,content:t.message}})}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{c.current.delete(t.name),s(e=>{let n=new Set(e);return n.delete(t.name),n})}}};if(!i)return null;let u=i.reduce((e,t)=>(e[t.workspace]||(e[t.workspace]=[]),e[t.workspace].push(t),e),{}),d=Object.entries(u).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort((e,t)=>e.friendlyName.localeCompare(t.friendlyName))]),f=d.length>1;function p(e){l(e)}return t===`menu`?(0,$.jsxs)(ys,{children:[(0,$.jsx)(bs,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),`Project Scripts`]})}),(0,$.jsx)(xs,{align:`start`,className:`w-56 p-1`,children:(0,$.jsx)(Md,{workspaceEntries:d,hasMultipleWorkspaces:f,runningScripts:o,onScriptClick:p})})]}):(0,$.jsxs)(dc,{children:[(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(fc,{asChild:!0,children:(0,$.jsx)(W,{variant:`action`,size:`icon-md`,children:(0,$.jsx)(en,{})})})}),(0,$.jsx)(H,{children:`Project Scripts`})]})}),(0,$.jsx)(gc,{align:`end`,className:`min-w-[180px]`,children:(0,$.jsx)(Nd,{workspaceEntries:d,hasMultipleWorkspaces:f,runningScripts:o,onScriptClick:p})})]})}var Fd=`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 Id({open:e,onOpenChange:t,projectId:n,commands:i,onRefresh:a}){let[o,c]=(0,Y.useState)(null),[l,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),[g,_]=(0,Y.useState)(0),[v,y]=(0,Y.useState)(!1),b=(0,Y.useRef)(null),x=(0,Y.useRef)(null),S=()=>{c({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),p(!1),h([])},C=e=>{c({...e}),p(!1),h([])},w=async()=>{try{y(!0);let e=await xt(n);h(e.scripts),_(0),p(e.scripts.length>0)}catch(e){console.error(`Failed to load package scripts:`,e),pa({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{y(!1)}},T=e=>{c(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),p(!1),h([]),b.current?.focus()},D=e=>{f&&(e.key===`ArrowDown`?(e.preventDefault(),_(e=>e<m.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),_(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),g<m.length&&T(m[g])):e.key===`Escape`&&(e.preventDefault(),p(!1),h([])))};(0,Y.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&(p(!1),h([]))};return f&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[f]);let O=async e=>{try{await Pt(n,e),pa({title:`Success`,description:`Command deleted`}),a()}catch{pa({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(Rt,{open:e,onOpenChange:t,children:(0,$.jsxs)(ce,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(E,{children:[(0,$.jsx)(I,{children:`Project Commands`}),(0,$.jsx)(pe,{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)(ge,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(u,{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)(ge,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)($i,{ref:b,id:`commandLine`,value:o.commandLine,onChange:e=>c({...o,commandLine:e.target.value}),onKeyDown:D,placeholder:`e.g. npm test`,className:`font-mono text-base min-h-[100px] resize-none pr-10`}),(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void w(),disabled:v,children:(0,$.jsx)(pt,{className:`h-4 w-4`})})}),(0,$.jsx)(H,{children:(0,$.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),f&&(0,$.jsx)(`div`,{ref:x,className:`absolute bottom-full left-0 right-0 mb-2 max-h-60 overflow-y-auto rounded-lg border border-border bg-popover shadow-lg z-50`,children:(0,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.jsxs)(`div`,{className:q(s.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),children:[(0,$.jsx)(pt,{className:`h-3 w-3`}),`Available Scripts `,v&&`(loading...)`]}),m.length>0?(()=>{let e={};m.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:q(s.dropdownGroupHeading,`px-3 py-1.5 text-muted-foreground/70 bg-muted/30`),children:t}),r.map(e=>{let t=n===g;return n++,(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full flex-col gap-1 rounded-lg mx-1 px-3 py-2 text-left transition-colors`,t?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>T(e),onMouseEnter:()=>_(n-1),children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:q(s.caption,`font-mono`),children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:q(s.caption,`px-3 py-4 text-center`),children:v?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(ge,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(u,{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:s.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)(ge,{children:`Icon`}),(0,$.jsx)(Sn,{children:(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:Fd.map(e=>{let t=Ue[e]||Kt;return(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{variant:o.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>c({...o,icon:e}),children:(0,$.jsx)(t,{className:`h-4 w-4`})})}),(0,$.jsx)(H,{children:e})]},e)})})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:[(0,$.jsx)(z,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsxs)(W,{size:`sm`,onClick:async()=>{if(!o?.name||!o?.commandLine){pa({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{d(!0),await gt(n,o),pa({title:`Success`,description:`Command saved`}),c(null),a()}catch{pa({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{d(!1)}},disabled:l,children:[(0,$.jsx)(An,{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:()=>C(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,$.jsx)(Ue[e.icon]||Dn,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:s.label,children:e.name}),(0,$.jsx)(`span`,{className:q(s.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)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors`,onClick:t=>{t.stopPropagation(),O(e.id)},children:(0,$.jsx)(r,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(W,{variant:`outline`,className:`w-full border-dashed`,onClick:S,children:[(0,$.jsx)(dt,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function Ld(e){let t=(0,X.c)(36),{layout:n}=e,r=n===void 0?`bar`:n,i=Q(Vd),a=Q(Bd),o=Q(zd),s=Q(Rd),{dispatch:c}=Qi(a),[l,u]=(0,Y.useState)(!1),d,f,p,m,h;if(t[0]!==c||t[1]!==s||t[2]!==r||t[3]!==o||t[4]!==i||t[5]!==a||t[6]!==l){h=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[12]===i?e=t[13]:(e=e=>e.projectId===i,t[12]=i,t[13]=e),d=o.find(e)?.commands??[];let n;t[14]!==c||t[15]!==i||t[16]!==a?(n=e=>{!i||!a||c({type:Z.QueueTerminalCommand,threadId:a,command:e.commandLine,relativeFolder:e.relativeFolder})},t[14]=c,t[15]=i,t[16]=a,t[17]=n):n=t[17];let g=n,_;if(t[18]===c?_=t[19]:(_=async()=>{c({type:Z.ConfigUpdated})},t[18]=c,t[19]=_),f=_,!i){h=null;break bb0}if(r===`menu`){let e;t[20]!==g||t[21]!==s?(e=e=>(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:()=>g({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:s,children:[(0,$.jsx)(Ue[e.icon]||Dn,{className:`h-4 w-4 shrink-0`}),e.name]},e.id),t[20]=g,t[21]=s,t[22]=e):e=t[22];let n,r;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>u(!0),n=(0,$.jsx)(Vt,{className:`h-4 w-4 shrink-0`}),t[23]=n,t[24]=r):(n=t[23],r=t[24]);let a=d.length===0?`Project Commands`:`Manage commands`,o;t[25]===a?o=t[26]:(o=(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:r,children:[n,a]}),t[25]=a,t[26]=o),h=(0,$.jsxs)($.Fragment,{children:[d.map(e),o,(0,$.jsx)(Id,{open:l,onOpenChange:u,projectId:i,commands:d,onRefresh:f})]});break bb0}p=`flex items-center gap-1`,m=d.length===0?(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{variant:`action`,size:`icon-md`,onClick:()=>u(!0),children:(0,$.jsx)(Vt,{})})}),(0,$.jsx)(H,{children:`Manage commands`})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(Sn,{children:[d.map(e=>(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{variant:`action`,size:`icon-md`,onClick:()=>g({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:s,children:(0,$.jsx)(Ue[e.icon]||Dn,{})})}),(0,$.jsx)(H,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto`,children:e.commandLine})]})})]},e.id)),(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>u(!0),children:(0,$.jsx)(Vt,{})})}),(0,$.jsx)(H,{children:`Manage commands`})]})]})})}t[0]=c,t[1]=s,t[2]=r,t[3]=o,t[4]=i,t[5]=a,t[6]=l,t[7]=d,t[8]=f,t[9]=p,t[10]=m,t[11]=h}else d=t[7],f=t[8],p=t[9],m=t[10],h=t[11];if(h!==Symbol.for(`react.early_return_sentinel`))return h;let g;t[27]!==d||t[28]!==f||t[29]!==i||t[30]!==l?(g=(0,$.jsx)(Id,{open:l,onOpenChange:u,projectId:i,commands:d,onRefresh:f}),t[27]=d,t[28]=f,t[29]=i,t[30]=l,t[31]=g):g=t[31];let _;return t[32]!==p||t[33]!==m||t[34]!==g?(_=(0,$.jsxs)(`div`,{className:p,children:[m,g]}),t[32]=p,t[33]=m,t[34]=g,t[35]=_):_=t[35],_}function Rd(e){return e.isRunningCommand}function zd(e){return e.projects}function Bd(e){return e.selectedThreadId}function Vd(e){return e.selectedProjectId}var Hd=`VS Code`;function Ud(e){return e||cn(Hd)}var Wd={"VS Code":`vscode`,Antigravity:`antigravity`,Cursor:`cursor`,"Devin Desktop":`devin`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function Gd({projectId:e,threadId:t,openWith:r,layout:a=`bar`}){let[o,s]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)([]),[d,f]=(0,Y.useState)(()=>Ud(r)),[p,m]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{let e=await n();u(e);let t=Ud(r);e.includes(t)?f(t):e.length>0&&f(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),u([Hd])}finally{m(!1)}})()},[]),(0,Y.useEffect)(()=>{if(r&&l.includes(r)){f(r);return}let e=cn(Hd);!r&&l.includes(e)&&f(e)},[r,l]);async function h(t){f(t),bt(t),await c(e,t)}let g=async n=>{try{s(!0),await h(n),t?await i(t,n):await Ee(e,n),pa({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}pa({title:`Error`,description:t,variant:`destructive`})}finally{s(!1)}};async function _(e){try{await h(e)}catch(t){console.error(`Failed to save preferred IDE (${e}):`,t),pa({title:`Error`,description:`Failed to save IDE preference`,variant:`destructive`})}}let v=async()=>{await g(d)};return p?(0,$.jsx)(W,{variant:`outline`,size:`sm`,className:`h-8`,disabled:!0,children:(0,$.jsx)(`div`,{className:`h-4 w-4 animate-pulse bg-muted rounded`})}):a===`menu`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,disabled:o,onClick:()=>{v()},children:[(0,$.jsx)(`img`,{src:`/ide/${Wd[d]||Wd[Hd]}.svg`,alt:d,className:`h-4 w-4 shrink-0`}),`Open in `,d]}),(0,$.jsxs)(ys,{children:[(0,$.jsx)(bs,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(pt,{className:`h-4 w-4 shrink-0`}),`Change IDE`]})}),(0,$.jsx)(xs,{align:`start`,className:`w-56 p-1`,children:l.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:()=>{_(e)},disabled:o,children:[(0,$.jsx)(`img`,{src:`/ide/${Wd[e]||Wd[Hd]}.svg`,alt:e,className:`h-4 w-4 shrink-0`}),e]},e))})]})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:o,onClick:v,children:(0,$.jsx)(`img`,{src:`/ide/${Wd[d]||Wd[Hd]}.svg`,alt:d,className:`h-4 w-4`})})}),(0,$.jsx)(H,{children:`Open in ${d}`})]}),(0,$.jsxs)(dc,{children:[(0,$.jsx)(fc,{asChild:!0,children:(0,$.jsx)(W,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:o,children:(0,$.jsx)(pt,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(gc,{align:`end`,children:l.map(e=>(0,$.jsxs)(_c,{onClick:()=>void _(e),disabled:o,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${Wd[e]||Wd[Hd]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}var Kd=Pr(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`]}),qd=Pr(e=>e.v0,{name:`RunStopButton_2`,portals:[`v0`]}),Jd=Pr(e=>(0,$.jsx)(`slot`,{children:e.v0}),{name:`RunStopButton_3`,portals:[`v0`]}),Yd=function({projectId:e,runCommand:t,large:n,layout:r=`bar`}){let{dispatch:i}=Qi(Q(e=>e.selectedThreadId)),{setDevServerUrl:a,setDevServerRunning:o,setDevServerLoading:c}=wo(),{startServer:l}=dl(),{isRunning:u,isLoading:d}=ml(e),f=(0,Y.useRef)(!1),p=()=>{l({projectId:e,runCommand:t||``})},m=async()=>{f.current=!0,c(!0);try{await bn(e),o(!1),a(null),i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server stopped`}})}catch(e){let t=e instanceof Error?e.message:`Failed to stop dev server`;i({type:Z.AppendTerminalLine,line:{type:`error`,content:t}}),pa({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)(Kd,{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)(N,{className:`h-10 w-10 animate-spin`}):u?(0,$.jsx)(Nt,{className:`h-10 w-10 fill-current`}):(0,$.jsx)(Dn,{className:`h-10 w-10 fill-current group-hover:text-foreground transition-colors`}),v4:q(s.body,`group-hover:text-foreground transition-colors`),v5:g}):r===`menu`?(0,$.jsx)(qd,{v0:(0,$.jsxs)(W,{variant:`ghost`,size:`sm`,className:q(`w-full justify-start gap-2`,u&&`text-orange-500`),onClick:u?m:p,disabled:d||!u&&!h,children:[d?(0,$.jsx)(N,{className:`h-4 w-4 shrink-0 animate-spin`}):u?(0,$.jsx)(Nt,{className:`h-4 w-4 shrink-0 fill-current`}):(0,$.jsx)(Dn,{className:`h-4 w-4 shrink-0`}),g]})}):(0,$.jsx)(Jd,{v0:(0,$.jsx)(Sn,{children:(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8 ${u?`text-orange-500 bg-orange-500/10`:`text-muted-foreground`}`,onClick:u?m:p,disabled:d||!u&&!h,children:[d?(0,$.jsx)(N,{className:`h-4 w-4 animate-spin`}):u?(0,$.jsx)(Nt,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(Dn,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:u?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(H,{children:u?`Stop dev server`:h?`Start dev server: ${t}`:`Set run command in project settings`})]})})})};function Xd(e){let t=(0,X.c)(31),{currentBranch:n,availableBranches:r,isLoadingBranches:i,isCheckingOut:a,onLoadBranches:o,onCheckoutBranch:c,onCreateBranch:l,onRenameBranch:u}=e,d;t[0]===o?d=t[1]:(d=e=>{e&&o()},t[0]=o,t[1]=d);let f,m;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=q(s.compact,`h-7 px-2 bg-background gap-1.5 border-none text-muted-foreground hover:bg-accent hover:text-accent-foreground`),m=(0,$.jsx)(Ye,{className:`h-3.5 w-3.5 shrink-0`}),t[2]=f,t[3]=m):(f=t[2],m=t[3]);let h=n||`Unknown`,g;t[4]===h?g=t[5]:(g=(0,$.jsx)(fc,{asChild:!0,children:(0,$.jsxs)(W,{variant:`outline`,size:`sm`,className:f,children:[m,h]})}),t[4]=h,t[5]=g);let _,v;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(dt,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),v=(0,$.jsx)(`span`,{children:`Create branch`}),t[6]=_,t[7]=v):(_=t[6],v=t[7]);let y;t[8]!==a||t[9]!==l?(y=(0,$.jsxs)(_c,{onClick:l,disabled:a,children:[_,v]}),t[8]=a,t[9]=l,t[10]=y):y=t[10];let b,x;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(p,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),b=(0,$.jsx)(`span`,{children:`Rename branch`}),t[11]=b,t[12]=x):(b=t[11],x=t[12]);let S;t[13]!==a||t[14]!==u?(S=(0,$.jsxs)(_c,{onClick:u,disabled:a,children:[x,b]}),t[13]=a,t[14]=u,t[15]=S):S=t[15];let C;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(xc,{}),t[16]=C):C=t[16];let w;t[17]!==r||t[18]!==n||t[19]!==a||t[20]!==i||t[21]!==c?(w=i?(0,$.jsxs)(`div`,{className:q(s.compact,`px-2 py-1.5 text-muted-foreground flex items-center gap-2`),children:[(0,$.jsx)(N,{className:`h-3 w-3 animate-spin`}),`Loading branches...`]}):r.length===0?(0,$.jsx)(`div`,{className:q(s.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)(_c,{disabled:e===n||a,onClick:()=>c(e),children:[(0,$.jsx)(Ye,{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:q(s.compact,`ml-auto text-muted-foreground`),children:`current`})]},e))}),t[17]=r,t[18]=n,t[19]=a,t[20]=i,t[21]=c,t[22]=w):w=t[22];let T;t[23]!==S||t[24]!==w||t[25]!==y?(T=(0,$.jsxs)(gc,{align:`start`,children:[y,S,C,w]}),t[23]=S,t[24]=w,t[25]=y,t[26]=T):T=t[26];let E;return t[27]!==d||t[28]!==T||t[29]!==g?(E=(0,$.jsxs)(dc,{onOpenChange:d,children:[g,T]}),t[27]=d,t[28]=T,t[29]=g,t[30]=E):E=t[30],E}function Zd(e){let t=(0,X.c)(35),{open:n,onOpenChange:r,branchName:i,onBranchNameChange:a,isLoading:o,onCreateBranch:s}=e,c;t[0]!==i||t[1]!==o||t[2]!==s?(c=e=>{e.key===`Enter`&&i.trim()&&!o&&s()},t[0]=i,t[1]=o,t[2]=s,t[3]=c):c=t[3];let l=c,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsxs)(E,{children:[(0,$.jsx)(I,{children:`New Branch`}),(0,$.jsx)(pe,{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)(ge,{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]!==l||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)(u,{id:`branch-name`,placeholder:`e.g. feature/my-feature`,value:i,onChange:p,onKeyDown:l,disabled:o,autoFocus:!0})]})}),t[8]=i,t[9]=l,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)(W,{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]!==s||t[22]!==_||t[23]!==v?(y=(0,$.jsx)(W,{onClick:s,disabled:_,children:v}),t[21]=s,t[22]=_,t[23]=v,t[24]=y):y=t[24];let b;t[25]!==y||t[26]!==g?(b=(0,$.jsxs)(be,{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)(Rt,{open:n,onOpenChange:r,children:x}),t[31]=r,t[32]=n,t[33]=x,t[34]=S):S=t[34],S}function Qd(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 $d(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,currentBranch:i,availableBranches:a,branchName:o,onBranchNameChange:s,isLoading:c,onRenameBranch:l}=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=Qd(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=c||h!==null,_;t[7]!==g||t[8]!==l?(_=e=>{e.key===`Enter`&&!g&&l()},t[7]=g,t[8]=l,t[9]=_):_=t[9];let v=_,y;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(I,{children:`Rename Branch`}),t[10]=y):y=t[10];let b;t[11]===i?b=t[12]:(b=(0,$.jsxs)(E,{children:[y,(0,$.jsxs)(pe,{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)(ge,{htmlFor:`rename-branch-name`,children:`New Branch Name`}),t[13]=x):x=t[13];let S;t[14]===s?S=t[15]:(S=e=>s(e.target.value),t[14]=s,t[15]=S);let C;t[16]!==o||t[17]!==v||t[18]!==c||t[19]!==S?(C=(0,$.jsx)(u,{id:`rename-branch-name`,placeholder:`e.g. feature/my-feature`,value:o,onChange:S,onKeyDown:v,disabled:c,autoFocus:!0,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1}),t[16]=o,t[17]=v,t[18]=c,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 D;t[27]===r?D=t[28]:(D=()=>r(!1),t[27]=r,t[28]=D);let O;t[29]!==c||t[30]!==D?(O=(0,$.jsx)(W,{variant:`outline`,onClick:D,disabled:c,children:`Cancel`}),t[29]=c,t[30]=D,t[31]=O):O=t[31];let k=c?`Renaming...`:`Rename Branch`,A;t[32]!==g||t[33]!==l||t[34]!==k?(A=(0,$.jsx)(W,{onClick:l,disabled:g,children:k}),t[32]=g,t[33]=l,t[34]=k,t[35]=A):A=t[35];let j;t[36]!==O||t[37]!==A?(j=(0,$.jsxs)(be,{children:[O,A]}),t[36]=O,t[37]=A,t[38]=j):j=t[38];let M;t[39]!==T||t[40]!==j||t[41]!==b?(M=(0,$.jsxs)(ce,{children:[b,T,j]}),t[39]=T,t[40]=j,t[41]=b,t[42]=M):M=t[42];let N;return t[43]!==r||t[44]!==n||t[45]!==M?(N=(0,$.jsx)(Rt,{open:n,onOpenChange:r,children:M}),t[43]=r,t[44]=n,t[45]=M,t[46]=N):N=t[46],N}var ef=`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 tf(){return ef[Math.floor(Math.random()*ef.length)]??`branch`}function nf(){let e=tf(),t=tf();for(;t===e;)t=tf();return`${e}-${t}`}function rf(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=pd();(0,Y.useEffect)(()=>{if(!s){u(``);return}u(nf())},[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 Ve(e)).branches)}catch{n([])}finally{i(!1)}}}async function C(t){if(!(!e||t===x.currentBranch)){o(!0);try{await L(e,t),await x.fetchUnifiedStatus(!0),pa({title:`Switched to branch "${t}"`})}catch(e){pa({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 Ae(e,y,l);c(!1),await S(),await x.fetchUnifiedStatus(!0),pa({title:`Branch created`,description:`Created branch "${t.branchName}" from ${y}`})}catch(e){pa({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 Ge(e,h);m(!1),await S(),await x.fetchUnifiedStatus(!0),pa({title:`Branch renamed`,description:`Renamed branch to "${t.branchName}"`})}catch(e){pa({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 af=(0,Y.lazy)(()=>wr(()=>import(`./git-ops-button-DKOfNm4s.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([2,1,3,4,5])));function of(e){return e===`menu`?`w-full justify-start gap-2`:`gap-2`}function sf(e){let t=(0,X.c)(4),{threadId:n,projectId:r,messages:i,userTasks:a}=e,{hasChanges:o}=pd(),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 cf(e){let t=(0,X.c)(91),{threadId:n,projectId:r,messages:i,userTasks:a,effectiveIsStreaming:o,isCreatingProject:s,onNewChat:c,onSelectUserTask:l,onRemoveUserTask:u,layout:d}=e,f=d===void 0?`bar`:d,{setActiveMainTab:p}=wo(),m;t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a?(m={threadId:n,projectId:r,messages:i,userTasks:a},t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=m):m=t[4];let{hasMessages:h,hasChanges:g,isVisible:_}=sf(m),{changedFilesCount:v}=pd(),y;t[5]===f?y=t[6]:(y=of(f),t[5]=f,t[6]=y);let b=y,{currentBranch:x,availableBranches:S,isLoadingBranches:C,isCheckingOut:w,loadBranches:T,checkoutBranch:E,isRenameDialogOpen:D,setIsRenameDialogOpen:O,renameBranchName:k,setRenameBranchName:A,isRenamingBranch:j,renameBranch:M,openRenameBranchDialog:N,isCreateDialogOpen:P,setIsCreateDialogOpen:F,newBranchName:I,setNewBranchName:L,isCreatingBranch:R,createBranch:ee}=rf(n),z=Q(lf),te;if(t[7]!==r||t[8]!==z){let e;t[10]===r?e=t[11]:(e=e=>e.projectId===r,t[10]=r,t[11]=e),te=z.find(e),t[7]=r,t[8]=z,t[9]=te}else te=t[9];let ne=te,re=f===`menu`&&!!n&&!!r,ie=h||g||a.length>0||!!(n&&r);if(!_)return null;let ae=f===`bar`&&`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,oe=f===`menu`&&`flex flex-col items-stretch gap-1 p-1 min-w-[220px]`,se;t[12]!==ae||t[13]!==oe?(se=q(ae,oe),t[12]=ae,t[13]=oe,t[14]=se):se=t[14];let ce=f===`bar`?!0:void 0,le;t[15]!==h||t[16]!==f||t[17]!==c||t[18]!==b?(le=h&&(0,$.jsxs)(W,{variant:f===`menu`?`ghost`:`outline`,size:`sm`,className:b,onClick:c,children:[(0,$.jsx)(dt,{className:`h-4 w-4 shrink-0`}),`New Chat`]}),t[15]=h,t[16]=f,t[17]=c,t[18]=b,t[19]=le):le=t[19];let ue;t[20]!==v||t[21]!==g||t[22]!==f||t[23]!==p||t[24]!==b?(ue=g&&(0,$.jsxs)(W,{variant:f===`menu`?`ghost`:`outline`,size:`sm`,className:b,onClick:()=>p(`review`),children:[(0,$.jsx)(an,{className:`h-4 w-4 shrink-0`}),v,` `,v===1?`File`:`Files`,` Changed`]}),t[20]=v,t[21]=g,t[22]=f,t[23]=p,t[24]=b,t[25]=ue):ue=t[25];let de;t[26]!==o||t[27]!==s||t[28]!==f||t[29]!==u||t[30]!==l||t[31]!==n||t[32]!==a?(de=a.length>0&&(0,$.jsx)(Td,{tasks:a,disabled:o||!n&&!s,onSelectTask:l,onRemoveTask:u,layout:f}),t[26]=o,t[27]=s,t[28]=f,t[29]=u,t[30]=l,t[31]=n,t[32]=a,t[33]=de):de=t[33];let fe;t[34]!==f||t[35]!==r||t[36]!==n?(fe=n&&r&&(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(af,{projectId:r,threadId:n,layout:f},n)}),t[34]=f,t[35]=r,t[36]=n,t[37]=fe):fe=t[37];let pe;t[38]!==h||t[39]!==f?(pe=h&&(0,$.jsx)(Cd,{layout:f}),t[38]=h,t[39]=f,t[40]=pe):pe=t[40];let me;t[41]!==S||t[42]!==E||t[43]!==x||t[44]!==w||t[45]!==C||t[46]!==f||t[47]!==T||t[48]!==N||t[49]!==F?(me=f===`bar`&&(0,$.jsx)(Xd,{currentBranch:x,availableBranches:S,isLoadingBranches:C,isCheckingOut:w,onLoadBranches:T,onCheckoutBranch:E,onCreateBranch:()=>F(!0),onRenameBranch:N}),t[41]=S,t[42]=E,t[43]=x,t[44]=w,t[45]=C,t[46]=f,t[47]=T,t[48]=N,t[49]=F,t[50]=me):me=t[50];let B;t[51]!==ie||t[52]!==re?(B=re&&ie&&(0,$.jsx)(xc,{className:`my-1`}),t[51]=ie,t[52]=re,t[53]=B):B=t[53];let he;t[54]!==r||t[55]!==ne?.openWith||t[56]!==ne?.runCommand||t[57]!==re||t[58]!==n?(he=re&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yd,{projectId:r,runCommand:ne?.runCommand,layout:`menu`}),(0,$.jsx)(Pd,{threadId:n,layout:`menu`}),(0,$.jsx)(Ld,{layout:`menu`}),(0,$.jsx)(Gd,{projectId:r,threadId:n,openWith:ne?.openWith,layout:`menu`})]}),t[54]=r,t[55]=ne?.openWith,t[56]=ne?.runCommand,t[57]=re,t[58]=n,t[59]=he):he=t[59];let ge;t[60]!==ue||t[61]!==de||t[62]!==fe||t[63]!==pe||t[64]!==me||t[65]!==B||t[66]!==he||t[67]!==se||t[68]!==ce||t[69]!==le?(ge=(0,$.jsxs)(`div`,{className:se,"data-chat-toolbar":ce,children:[le,ue,de,fe,pe,me,B,he]}),t[60]=ue,t[61]=de,t[62]=fe,t[63]=pe,t[64]=me,t[65]=B,t[66]=he,t[67]=se,t[68]=ce,t[69]=le,t[70]=ge):ge=t[70];let _e;t[71]!==ee||t[72]!==P||t[73]!==R||t[74]!==I||t[75]!==F||t[76]!==L?(_e=(0,$.jsx)(Zd,{open:P,onOpenChange:F,branchName:I,onBranchNameChange:L,isLoading:R,onCreateBranch:ee}),t[71]=ee,t[72]=P,t[73]=R,t[74]=I,t[75]=F,t[76]=L,t[77]=_e):_e=t[77];let ve;t[78]!==S||t[79]!==x||t[80]!==D||t[81]!==j||t[82]!==M||t[83]!==k||t[84]!==O||t[85]!==A?(ve=(0,$.jsx)($d,{open:D,onOpenChange:O,currentBranch:x,availableBranches:S,branchName:k,onBranchNameChange:A,isLoading:j,onRenameBranch:M}),t[78]=S,t[79]=x,t[80]=D,t[81]=j,t[82]=M,t[83]=k,t[84]=O,t[85]=A,t[86]=ve):ve=t[86];let ye;return t[87]!==ge||t[88]!==_e||t[89]!==ve?(ye=(0,$.jsxs)($.Fragment,{children:[ge,_e,ve]}),t[87]=ge,t[88]=_e,t[89]=ve,t[90]=ye):ye=t[90],ye}function lf(e){return e.projects}function uf(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(cf,{...e}),t[0]=e,t[1]=n),n}function df(){let e=(0,X.c)(20),t=Q(mf),n=Q(pf),r=Q(ff),{userTasks:i,handleNewChat:a,handleSelectUserTask:o,handleRemoveUserTask:s,effectiveIsStreaming:c,isCreatingProject:l}=jd(),u;e[0]!==r||e[1]!==n||e[2]!==t||e[3]!==i?(u={threadId:t,projectId:n,messages:r,userTasks:i},e[0]=r,e[1]=n,e[2]=t,e[3]=i,e[4]=u):u=e[4];let{isVisible:d}=sf(u);if(!t||!d)return null;let f;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(fc,{asChild:!0,children:(0,$.jsxs)(W,{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)(_e,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Chat actions`})]})}),e[5]=f):f=e[5];let p=n??``,m;e[6]===a?m=e[7]:(m=()=>{a()},e[6]=a,e[7]=m);let h;e[8]===s?h=e[9]:(h=e=>{s(e)},e[8]=s,e[9]=h);let g;return e[10]!==c||e[11]!==o||e[12]!==l||e[13]!==r||e[14]!==t||e[15]!==p||e[16]!==m||e[17]!==h||e[18]!==i?(g=(0,$.jsxs)(dc,{children:[f,(0,$.jsx)(gc,{align:`end`,className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(cf,{threadId:t,projectId:p,messages:r,userTasks:i,effectiveIsStreaming:c,isCreatingProject:l,onNewChat:m,onSelectUserTask:o,onRemoveUserTask:h,layout:`menu`})})]}),e[10]=c,e[11]=o,e[12]=l,e[13]=r,e[14]=t,e[15]=p,e[16]=m,e[17]=h,e[18]=i,e[19]=g):g=e[19],g}function ff(e){return e.messages}function pf(e){return e.selectedProjectId}function mf(e){return e.selectedThreadId}function hf(e){let t=(0,X.c)(3),{threadId:n,children:r}=e,i;return t[0]!==r||t[1]!==n?(i=(0,$.jsx)(fd,{threadId:n,children:r}),t[0]=r,t[1]=n,t[2]=i):i=t[2],i}var gf=`tarsk-browser-tool-request`,_f=new Set;function vf(e){ye()&&window.dispatchEvent(new CustomEvent(gf,{detail:e}))}function yf(e,t,n){!ye()||_f.has(e)||t.action&&(_f.add(e),vf({toolCallId:e,input:t,threadId:n}))}function bf(){return ye()?`views://public/browser-preview-rpc.js`:`${In()}/browser-preview-rpc.js`}async function xf(e,t){await sn(e,t)}async function Sf(e,t){await Jt(e,t)}var Cf=new Set,wf=new Map,Tf=5e3;function Ef(e){Cf.add(e);let t=wf.get(e);t&&clearTimeout(t),wf.set(e,setTimeout(()=>{Cf.delete(e),wf.delete(e)},Tf))}function Df(e){return Cf.has(e)}function Of(e){return e.filter(e=>!Cf.has(e))}function kf(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&&Fc(e.id,e.input.code,t)}catch{}}function Af(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&&yf(e.id,e.input,t)}catch{}}function jf(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`&&Qo(e.id,e.input.command)}catch{}}function Mf(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`&&$o(e.toolCallId)}catch{}}function Nf(e,t,n){let r={type:`thinking`,content:Ff,model:n};e({type:Z.SetStreaming,isStreaming:!0,threadId:t}),e({type:Z.SetStreamModel,model:n,threadId:t}),e({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r.content??``,segments:ji([],`thinking`,r.content??``),threadId:t})}var Pf=/^\/compact(?:\s+(.*))?$/i,Ff=`[Compact] Compaction in progress...`;function If(){let e=Xi(),{toast:t}=ma(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(new Map),u=Q(e=>e.selectedThreadId),d=Q(e=>e.selectedProjectId),f=Q(e=>e.messages),p=Q(e=>e.queuedChatMessages),m=Q(e=>e.isStreaming),h=Q(e=>e.processingThreadIds),g=Q(e=>e.streamingModel),_=Q(e=>e.pendingChatMessage);c.current=u;let v=(0,Y.useCallback)((t,n,r)=>{if(l.current.get(t)!==r){l.current.has(t)||(Ef(t),e({type:Z.ResetStream,threadId:t}),e({type:Z.RemoveProcessingThread,threadId:t}));return}if(l.current.delete(t),e({type:Z.ClearToolCallProgress}),r.stopHandled)return;if(Ef(t),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};e({type:Z.AddMessage,message:i,threadId:t}),e({type:Z.ResetStream,threadId:t}),e({type:Z.RemoveProcessingThread,threadId:t});return}let i=Ri(r.segments)||`...`,a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:i,contentType:`markdown`,timestamp:new Date().toISOString(),model:n||`default`,isThinking:!1};async function o(){for(let n=0;n<4;n++){n>0&&await new Promise(e=>setTimeout(e,150*n));try{let n=await wt(t);if(t===c.current){e({type:Z.SetMessages,messages:n.messages});return}}catch(e){console.error(`Failed to reload chat history after stream:`,e);break}}e({type:Z.AddMessage,message:a,threadId:t})}o(),e({type:Z.ResetStream,threadId:t}),e({type:Z.MarkThreadCompleted,threadId:t}),e({type:Z.RemoveProcessingThread,threadId:t})},[e]),y=(0,Y.useCallback)(()=>{if(!u)return;s(u);let t=l.current.get(u);t&&(t.stopHandled=!0,t.controller.abort(),t.cancel?.(),l.current.delete(u)),at(u);let n={messageId:`msg-${Date.now()}-stopped`,sender:`agent`,content:`I've stopped working on your request.`,contentType:`text`,timestamp:new Date().toISOString(),model:g||`default`,isThinking:!1};e({type:Z.AddMessage,message:n,threadId:u}),e({type:Z.ClearToolCallProgress}),e({type:Z.ResetStream,threadId:u}),e({type:Z.MarkThreadCompleted,threadId:u}),e({type:Z.RemoveProcessingThread,threadId:u}),Ef(u)},[u,e,g]);(0,Y.useEffect)(()=>()=>{for(let[t,n]of l.current.entries())n.controller.abort(),n.cancel?.(),e({type:Z.ResetStream,threadId:t});l.current.clear()},[e]);let b=(0,Y.useCallback)((t,n,i)=>{let o=l.current.get(t);o&&(o.controller.abort(),o.cancel?.());let s=new AbortController,u={controller:s,cancel:null,segments:[],assistantMessage:``,assistantThinking:``,hasStructuredContent:!1,error:null,stopHandled:!1,activeSubagentToolCallId:null};return l.current.set(t,u),e({type:Z.ResetStream,threadId:t}),e({type:Z.SetStreaming,isStreaming:!0,threadId:t}),n(s.signal).then(n=>{if(!n||s.signal.aborted){v(t,i,u);return}u.cancel=Ct(n,n=>{if(e({type:Z.IncrementStreamEventCount,threadId:t}),n.type===`error`){let e=n.content?.trim()||n.error?.message?.trim()||n.message?.trim()||`Unknown error occurred`;u.error=e,t===c.current&&r(e);return}if(n.type!==`message`){if(n.type===`long_running_confirmation`){let r=n.prompt;if(!r)return;u.segments=Ni(u.segments,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:u.segments,threadId:t});return}if(n.type===`shell_permission`){let r=n.shellPermission;if(!r)return;u.activeSubagentToolCallId&&e({type:Z.AppendToolExecutionOutput,toolCallId:u.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for shell approval: ${r.command}\n`}),u.segments=Pi(u.segments,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:u.segments,threadId:t});return}if(n.type===`web_fetch_permission`){let r=n.webFetchPermission;if(!r)return;u.activeSubagentToolCallId&&e({type:Z.AppendToolExecutionOutput,toolCallId:u.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for approval to fetch ${r.hostname}\n`}),u.segments=Fi(u.segments,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:u.segments,threadId:t});return}if(n.type===`toolcall_delta`){n.partial?.content?.[0]?.id&&n.delta&&e({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&&e({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:n.toolName,executionOutput:n.executionOutput});return}if(n.type===`subagent_start`){if(n.toolCallId){u.activeSubagentToolCallId=n.toolCallId;let t=n.subagentName?.trim()||`subagent`;e({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:`Running ${t}…\n`})}return}if(n.type===`subagent_event`){if(n.toolCallId){let t=ac(n);t&&e({type:Z.AppendToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,delta:t})}return}if(n.type===`subagent_complete`){n.toolCallId&&(u.activeSubagentToolCallId=null,n.subagentResult&&e({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:n.subagentResult}));return}if(n.model&&e({type:Z.SetStreamModel,model:n.model,threadId:t}),n.type===`thinking`||n.isThinking){let r=n.content??``;kf(r,t),Af(r,t),u.assistantThinking+=r,u.segments=ji(u.segments,`thinking`,r),e({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r,segments:u.segments,threadId:t})}else if(n.type===`result`){u.hasStructuredContent=!0;let r=n.content??``;u.assistantMessage=r,u.segments=Mi(u.segments,r),e({type:Z.SetStreamContent,content:r,threadId:t}),typeof r==`string`&&(kf(r,t),Af(r,t))}else{if(u.hasStructuredContent)return;let r=n.content??``;u.assistantMessage+=r,u.segments=ji(u.segments,`content`,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:r,segments:u.segments,threadId:t})}}},()=>{v(t,i,u)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){v(t,i,u);return}u.error=e,t===c.current&&r(e)},n=>{if(e({type:Z.IncrementStreamEventCount,threadId:t}),n.role===`assistant`){let r=n.content??``,i=typeof r==`string`?r:JSON.stringify(r);if(n.isThinking??!1){u.assistantThinking+=i,u.segments=ji(u.segments,`thinking`,i),e({type:Z.AppendStreamChunk,chunkType:`thinking`,content:i,segments:u.segments,threadId:t});return}let a=!1;if(typeof r==`object`&&Array.isArray(r)&&r.length>0)a=!0;else if(typeof i==`string`&&i.trim().startsWith(`[`))try{let e=JSON.parse(i);a=Array.isArray(e)&&e.length>0}catch{}a?(u.hasStructuredContent=!0,u.assistantMessage=i,u.segments=Mi(u.segments,i),e({type:Z.SetStreamContent,content:i,threadId:t}),kf(i,t),Af(i,t)):(u.assistantMessage+=i,u.segments=ji(u.segments,`content`,i),e({type:Z.AppendStreamChunk,chunkType:`content`,content:i,segments:u.segments,threadId:t}))}else if(n.role===`tool`){let r=n.content??``,i=typeof r==`string`?r:JSON.stringify(r);i&&(jf(i),Mf(i),u.assistantMessage+=i,u.segments=ji(u.segments,`content`,i),e({type:Z.AppendStreamChunk,chunkType:`content`,content:i,segments:u.segments,threadId:t}))}})}).catch(n=>{if(l.current.delete(t),n instanceof Error&&n.name===`AbortError`){e({type:Z.ResetStream,threadId:t});return}if(n instanceof _t){e({type:Z.ResetStream,threadId:t}),a(!0);return}if(n instanceof Error&&n.message.includes(`not currently processing`)){e({type:Z.ResetStream,threadId:t});return}let i=n instanceof Error?n.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`;t===c.current&&r(i),console.error(`Failed to subscribe to chat stream:`,n),e({type:Z.ResetStream,threadId:t})}),s},[e,v]),x=Yi();(0,Y.useEffect)(()=>{for(let e of h)l.current.has(e)||x.getState().threadStreamingStates[e]?.isStreaming||Df(e)||b(e,t=>Tn(e,t),`default`)},[b,h,x]);let S=(0,Y.useCallback)(async(n,i,a,o,c,l,p)=>{if(!u)return;let g=u;r(null),s(null);let _=n.trim().match(Pf);if(_){if(f.filter(e=>e.sender===`agent`).length<2){t({title:`Nothing to compact`,description:`Start a conversation with at least two exchanges first.`});return}if(h.includes(g)||m&&u===g){t({title:`Agent is busy`,description:`Wait for the agent to finish before compacting.`});return}let n=_[1]?.trim();Nf(e,g,i);try{let r=await vn(g,{model:i,provider:o,instructions:n});e({type:Z.SetMessages,messages:r.messages}),e({type:Z.ResetStream,threadId:g}),t({title:`Conversation compacted`,description:`${r.messagesBefore} messages → ${r.messagesAfter} summary`})}catch(n){e({type:Z.ResetStream,threadId:g}),t({title:`Compaction failed`,description:n instanceof Error?n.message:`Failed to compact conversation`,variant:`destructive`})}return}let v=`msg-${Date.now()}`,y;try{let e=await je(g,v);e.success&&e.stashed&&e.checkpointRef&&(y=e.checkpointRef)}catch{}let x={messageId:v,sender:`user`,content:n,contentType:`text`,timestamp:new Date().toISOString(),model:i,attachments:a.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType})),checkpointRef:y};e({type:Z.AddMessage,message:x,threadId:g});let S=n.trim().replace(/\n/g,` `).slice(0,100);if(d&&(fe(g,{title:S}).catch(e=>{console.error(`Failed to update thread title:`,e)}),e({type:Z.UpdateThreadTitle,projectId:d,threadId:g,title:S})),l){let t=o??void 0;if(!t&&typeof i==`string`){let e=i.split(/[:/]/)[0]?.trim();e&&(t=e)}if(!t){let t={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Image generation is not available because no provider is configured for the selected model.`,contentType:`text`,timestamp:new Date().toISOString(),model:i,isThinking:!1};e({type:Z.AddMessage,message:t,threadId:g}),e({type:Z.ResetStream,threadId:g});return}e({type:Z.SetStreaming,isStreaming:!0,threadId:g});try{let r=await rn(n,i,t,g),a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:n,contentType:`text`,timestamp:new Date().toISOString(),model:i,isThinking:!1,generatedImageUrl:r.imageUrl,generatedImageData:r.imageData};e({type:Z.AddMessage,message:a,threadId:g})}catch(t){let n=t instanceof Error?t.message:`Image generation failed`,r={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${n}`,contentType:`text`,timestamp:new Date().toISOString(),model:i,isThinking:!1};e({type:Z.AddMessage,message:r,threadId:g})}finally{e({type:Z.ResetStream,threadId:g})}return}b(g,e=>jt(g,n,i,a,e,o,c,p,y),i)},[u,d,e,b,f,h,m,t]);(0,Y.useEffect)(()=>{let t=_;if(!t||m||t.threadId!==u)return;let n=setTimeout(()=>{e({type:Z.ClearPendingChatMessage}),S(t.message,t.model,[],t.provider)},100);return()=>clearTimeout(n)},[_,m,u,e,S]);let C=(0,Y.useMemo)(()=>u?p.filter(e=>e.threadId===u):[],[u,p]),w=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{if(m||!u||C.length===0||w.current)return;let[t]=C;w.current=!0,e({type:Z.RemoveQueuedChatMessage,queuedMessageId:t.id});let n=setTimeout(()=>{S(t.message,t.model,t.attachments,t.provider,t.planMode,t.imageMode,t.ralphMode),w.current=!1},0);return()=>{clearTimeout(n),w.current=!1}},[e,S,m,C,u]),{error:n,setError:r,handleSend:S,handleStop:y,isStreaming:m,selectedThreadId:u,queuedMessagesForThread:C,handleRemoveQueuedMessage:(0,Y.useCallback)(t=>{let n=C.find(e=>e.id===t);e({type:Z.RemoveQueuedChatMessage,queuedMessageId:t}),!(!n||m||f.length>0||!u)&&S(n.message,n.model,n.attachments,n.provider,n.planMode,n.imageMode,n.ralphMode)},[e,S,m,f.length,C,u]),showEmptyBalanceDialog:i,setShowEmptyBalanceDialog:a}}function Lf(e){let t=(0,X.c)(10),{open:n,onClose:r}=e,i=Sr(),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)(Ar,{children:[(0,$.jsx)(jr,{children:`Balance empty`}),(0,$.jsx)(Nr,{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)(Mr,{children:[o,(0,$.jsx)(Fr,{children:(0,$.jsx)(W,{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)(Rr,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function Rf(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)(zf,{messages:i}),t[2]=i,t[3]=a),a}function zf(e){let t=(0,X.c)(40),{messages:n}=e,r=Q(Hf),i=Q(Vf),a=Q(Bf),{handleSend:o,handleStop:s,queuedMessagesForThread:c,handleRemoveQueuedMessage:l,showEmptyBalanceDialog:u,setShowEmptyBalanceDialog:d}=If(),{userTasks:f,setUserTasks:p,handleNewChat:m,handleSelectUserTask:h,handleRemoveUserTask:g,effectiveIsStreaming:_}=jd(),v=Ll()||Xe(),y;t[0]===d?y=t[1]:(y=()=>d(!1),t[0]=d,t[1]=y);let b;t[2]!==u||t[3]!==y?(b=(0,$.jsx)(Lf,{open:u,onClose:y}),t[2]=u,t[3]=y,t[4]=b):b=t[4];let x=v?`w-full min-w-0`:`w-[90vw] min-w-[400px]`,S;t[5]===x?S=t[6]:(S=q(`relative mx-auto max-w-3xl`,x),t[5]=x,t[6]=S);let C;t[7]!==_||t[8]!==m||t[9]!==g||t[10]!==h||t[11]!==r||t[12]!==n||t[13]!==a||t[14]!==i||t[15]!==f?(C=i&&(a||n.length>0||f.length>0)&&(0,$.jsx)(`div`,{className:`max-md:hidden`,children:(0,$.jsx)(uf,{threadId:i,projectId:a??``,messages:n,userTasks:f,effectiveIsStreaming:_,isCreatingProject:r,onNewChat:()=>{m()},onSelectUserTask:h,onRemoveUserTask:e=>{g(e)}})}),t[7]=_,t[8]=m,t[9]=g,t[10]=h,t[11]=r,t[12]=n,t[13]=a,t[14]=i,t[15]=f,t[16]=C):C=t[16];let w=!i&&!r,T;t[17]===g?T=t[18]:(T=e=>{g(e.id)},t[17]=g,t[18]=T);let E;t[19]===p?E=t[20]:(E=e=>{p(t=>[...t,e])},t[19]=p,t[20]=E);let D;t[21]!==_||t[22]!==l||t[23]!==o||t[24]!==s||t[25]!==c||t[26]!==w||t[27]!==T||t[28]!==E||t[29]!==f?(D=(0,$.jsx)(Bu,{onSend:o,onStop:s,isStreaming:_,disabled:w,initialValue:``,queuedMessages:c,onRemoveQueuedMessage:l,isOverlay:!1,userTasks:f,onMatchedUserTaskSend:T,onUserTaskCreated:E}),t[21]=_,t[22]=l,t[23]=o,t[24]=s,t[25]=c,t[26]=w,t[27]=T,t[28]=E,t[29]=f,t[30]=D):D=t[30];let O;t[31]!==C||t[32]!==D?(O=(0,$.jsxs)(`div`,{className:`relative`,children:[C,D]}),t[31]=C,t[32]=D,t[33]=O):O=t[33];let k;t[34]!==O||t[35]!==S?(k=(0,$.jsx)(`div`,{className:S,children:O}),t[34]=O,t[35]=S,t[36]=k):k=t[36];let A;return t[37]!==k||t[38]!==b?(A=(0,$.jsxs)($.Fragment,{children:[b,k]}),t[37]=k,t[38]=b,t[39]=A):A=t[39],A}function Bf(e){return e.selectedProjectId}function Vf(e){return e.selectedThreadId}function Hf(e){return e.isCreatingProject}var Uf=768;function Wf(){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: ${Uf-1}px)`),t=()=>{n(window.innerWidth<Uf)};return e.addEventListener(`change`,t),n(window.innerWidth<Uf),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),!!t}function Gf(){let e=(0,X.c)(7),t=Xi(),n=Q(qf),r=Q(Kf),i;e[0]!==t||e[1]!==n?(i=()=>{if(!n)return;let e=n,r=!1;return(async function(){try{let n=await wt(e);r||t({type:Z.SetMessages,messages:n.messages})}catch(e){console.error(`Failed to load chat history:`,e),r||t({type:Z.SetMessages,messages:[]})}})(),()=>{r=!0}},e[0]=t,e[1]=n,e[2]=i):i=e[2];let a;e[3]!==t||e[4]!==r||e[5]!==n?(a=[n,r,t],e[3]=t,e[4]=r,e[5]=n,e[6]=a):a=e[6],(0,Y.useEffect)(i,a)}function Kf(e){return e.selectedProjectId}function qf(e){return e.selectedThreadId}async function Jf(e){return ke(`api/projects/${ie(e)}/todos`)}async function Yf(e,t){return j(`api/projects/${ie(e)}/todos`,{description:t})}async function Xf(e,t,n){return Be(`api/projects/${ie(e)}/todos/${ie(t)}`,n)}async function Zf(e,t){await F(`api/projects/${ie(e)}/todos/${ie(t)}`)}var Qf=Pr(e=>(0,$.jsxs)(`div`,{className:e.v0,onClick:e.v1,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:e.v2,children:e.v3}),e.v4]}),e.v5]}),{name:`KanbanTodoCard_1`,portals:[`v3`,`v4`,`v5`]}),$f=function({todo:e,projectId:t,onUpdate:n,onEdit:r,onAction:i,onThreadSelect:a}){let[o,c]=(0,Y.useState)(!1),l=ep[e.status]??[];function u(t){t.stopPropagation(),e.threadId&&a&&a(e.threadId)}async function d(r,a){r.stopPropagation(),c(!0);try{i?await i(e,a):n(await Xf(t,e.id,{status:a,working:a!==`Done`}))}finally{c(!1)}}return(0,$.jsx)(Qf,{v0:q(`rounded-lg border bg-card p-3 shadow-sm space-y-2 cursor-pointer hover:bg-accent/50 transition-colors`,e.working&&`border-primary/50 bg-primary/5`),v1:t=>{t.stopPropagation(),r(e)},v2:q(s.label,`leading-tight`),v3:e.title,v4:e.working&&(0,$.jsx)(N,{className:`h-3 w-3 animate-spin text-primary shrink-0`}),v5:(l.length>0||e.status!==`Ready`&&e.threadId&&a)&&(0,$.jsxs)(`div`,{className:`flex gap-1.5 flex-wrap items-center pt-1`,children:[l.map(t=>(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsx)(W,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-base`,onClick:e=>void d(e,t.target),disabled:o||e.working,children:t.label})}),(0,$.jsx)(H,{side:`top`,children:e.status===`Ready`&&t.target===`Build`?`Implement this on a new branch of the project`:t.target===`Review`?`Review the code changes for this task`:t.target===`Done`?`Mark the task as done`:t.label})]},t.target)),e.status!==`Ready`&&e.threadId&&a&&(0,$.jsxs)(kt,{children:[(0,$.jsx)(Fn,{asChild:!0,children:(0,$.jsxs)(W,{size:`icon`,variant:`ghost`,className:`h-7 w-7 shrink-0 group-hover:flex items-center justify-center`,onClick:u,children:[(0,$.jsx)(lt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Open thread`})]})}),(0,$.jsx)(H,{side:`right`,children:`Open thread`})]})]})})},ep={Ready:[{label:`Plan`,target:`Plan`},{label:`Build`,target:`Build`}],Plan:[{label:`Build`,target:`Build`}],Build:[{label:`Test`,target:`Test`},{label:`Review`,target:`Review`}],Test:[{label:`Review`,target:`Review`}],Review:[{label:`Done`,target:`Done`}],Done:[]},tp=`Please analyze this task and create a detailed implementation plan.
|
|
51
|
+
|
|
52
|
+
Task description:
|
|
53
|
+
{description}`,np="\nWrite your complete plan to the file `{todoId}-plan.md` in the current directory.",rp=`Act as a Quality Assurance Manager. Rephrase the task into a rigorous test case: {description}`,ip=`Code review: The systematic examination of code to find mistakes, ensure it follows best practices, and identify areas for improvement
|
|
54
|
+
Directions:
|
|
55
|
+
Carefully read through the list of code changes creating a todo list of code to review.
|
|
56
|
+
Analyze the code structure, variable names, functions, and logic flow
|
|
57
|
+
Look for any syntax errors, bugs, or inefficiencies
|
|
58
|
+
Consider best practices for the specific programming language used
|
|
59
|
+
Provide clear and constructive feedback on areas that could be improved
|
|
60
|
+
If applicable, include examples of how to refactor problematic code
|
|
61
|
+
Offer praise for portions of the code that are well-written and follow best practices
|
|
62
|
+
|
|
63
|
+
Task description:
|
|
64
|
+
{description}`,ap={plan:tp,test:rp,review:ip},op={plan:`planPrompt`,test:`testPrompt`,review:`reviewPrompt`};function sp(e,t){let n=e?.[op[t]];return n&&n.trim()?n:ap[t]}function cp(e,t,n,r){let i=e.replace(/\{description\}/g,r);return t===`plan`&&(i+=np.replace(/\{todoId\}/g,n)),i}var lp=[`Ready`,`Plan`,`Build`,`Test`,`Review`,`Done`],up={Ready:`border-t-slate-400`,Plan:`border-t-blue-400`,Build:`border-t-orange-400`,Test:`border-t-yellow-400`,Review:`border-t-purple-400`,Done:`border-t-green-400`};async function dp(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=null;try{for(;;){let{done:e,value:o}=await n.read();if(e)break;i+=r.decode(o,{stream:!0});let s=i.split(`
|
|
65
|
+
`);i=s.pop()??``;for(let e of s){let n=e.trim();if(n)try{let e=JSON.parse(n);e.type===`progress`&&typeof e.threadId==`string`&&!a&&(a=e.threadId,t(a))}catch{}}}}catch{}return a}async function fp(e){let t=e.getReader();try{for(;;){let{done:e}=await t.read();if(e)break}}catch{}}async function pp(e){let t=e.getReader(),n=new TextDecoder,r=``,i=``;try{for(;;){let{done:e,value:a}=await t.read();if(e)break;r+=n.decode(a,{stream:!0});let o=r.split(`
|
|
66
|
+
`);r=o.pop()??``;for(let e of o){let t=e.trim();if(t)try{let e=JSON.parse(t);e.type===`token`&&e.content?i+=e.content:e.type===`result`&&e.content&&(i=e.content)}catch{}}}}catch{}return i}async function mp(e){let t=await Jf(e),n=t.filter(e=>e.threadId&&e.status!==`Done`),r=[...t];return await Promise.all(n.map(async t=>{try{await d(t.threadId)}catch(n){if(n instanceof Error&&n.message.includes(`not found`)){let n=await Xf(e,t.id,{status:`Done`}),i=r.findIndex(e=>e.id===t.id);i!==-1&&(r[i]=n)}}})),r}function hp(e,t){return`project-todos:${e}:${t}`}function gp({projectId:e,addOpen:t,onAddOpenChange:n,onThreadSelect:r,initialTodos:i}){let a=Xi(),o=Q(e=>e.selectedThreadId),c=Q(e=>e.projectModelSelections),l=Q(e=>e.projects),[u,f]=(0,Y.useState)(i),[p,m]=(0,Y.useState)(null),[h,_]=(0,Y.useState)(``),[v,y]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(!1),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(!u.some(e=>e.working))return;let t=setInterval(async()=>{try{let n=await Jf(e);f(n),n.some(e=>e.working)||clearInterval(t)}catch(e){console.error(`Failed to poll project todos:`,e)}},2e3);return()=>clearInterval(t)},[u,e]),(0,Y.useEffect)(()=>{t&&_(``)},[t]);function j(e){_(e.description),m({todo:e})}function P(){m(null),_(``)}async function F(){if(h.trim()){y(!0);try{let t=await Yf(e,h);f(e=>[...e,t]),n(!1),_(``)}finally{y(!1)}}}async function L(){if(!(!h.trim()||!p)){y(!0);try{let t=await Xf(e,p.todo.id,{description:h});f(e=>e.map(e=>e.id===t.id?t:e)),P()}finally{y(!1)}}}async function R(){if(p){y(!0);try{await Zf(e,p.todo.id),f(e=>e.filter(e=>e.id!==p.todo.id)),P()}finally{y(!1)}}}function ee(e){f(t=>t.map(t=>t.id===e.id?e:t))}async function z(t){let n=o?c[o]:void 0,r=l.find(t=>t.projectId===e),i=r?.threads.find(e=>e.threadId===o),s=n?.id??i?.model,u=n?.provider??i?.modelProvider;if(!s||!u)throw console.error(`No model or provider found for project`,e,i),Error(`No model configuration found. Please configure a model and provider for this project first.`);let d=await g(e);if(!d)return;let f=null,p=await dp(d,n=>{Xf(e,t.id,{status:`Plan`,working:!0,threadId:n}).then(e=>{f=e,ee(e)})});if(!p)return;f||ee(await Xf(e,t.id,{status:`Plan`,working:!0,threadId:p}));let m=n??{id:s,provider:u,name:s,description:``};a({type:Z.SetProjectModel,threadId:p,model:m}),fe(p,{model:s,modelProvider:u});let h=await jt(p,cp(sp(r,`plan`),`plan`,t.id,t.description),s,[],void 0,u);h&&fp(h)}async function te(t){let n=await g(e);if(!n)return;let r=null,i=await dp(n,n=>{Xf(e,t.id,{status:`Build`,working:!0,threadId:n}).then(e=>{r=e,ee(e)})});if(!i)return;r||ee(await Xf(e,t.id,{status:`Build`,working:!0,threadId:i}));let o=await d(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await ke(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{threadId:t.threadId??t.id,model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(s=t.model,c=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!s||!c)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Z.SetProjectModel,threadId:i,model:{id:s,provider:c,name:s,description:``}}),fe(i,{model:s,modelProvider:c}),console.log(`Sending chat message with provider:`,i,t.description,c);let l=await jt(i,t.description,s,[],void 0,c);l&&fp(l)}async function ne(t){try{let n=await g(e);if(!n){x(!1),C(null);return}let r=null;if(r=await dp(n,e=>{r=e}),!r){x(!1),C(null);return}let i=await d(r),a=i.model,o=i.modelProvider;if(!a||!o)try{let t=(await ke(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(a=t.model,o=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!a||!o){M(e,r),x(!1),C(null);return}let s=cp(sp(l.find(t=>t.projectId===e),`test`),`test`,t.id,t.description),c=await jt(r,s,a,[],void 0,o);c&&T(await pp(c)),M(e,r)}catch(e){console.error(`Failed to generate test case:`,e),x(!1),C(null)}finally{O(!1)}}function re(e){C(e),T(``),O(!0),x(!0),ne(e)}function ie(){x(!1),C(null),T(``)}async function ae(){if(!S||!w.trim())return;let t=S,n=w;ie(),A(!0);try{let r=await g(e);if(!r)return;let i=null,o=await dp(r,n=>{Xf(e,t.id,{status:`Test`,working:!0,threadId:n}).then(e=>{i=e,ee(e)})});if(!o)return;i||ee(await Xf(e,t.id,{status:`Test`,working:!0,threadId:o}));let s=await d(o),c=s.model,l=s.modelProvider;if(!c||!l)try{let t=(await ke(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(c=t.model,l=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!c||!l)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Z.SetProjectModel,threadId:o,model:{id:c,provider:l,name:c,description:``}}),fe(o,{model:c,modelProvider:l});let u=await jt(o,n,c,[],void 0,l);u&&fp(u)}finally{A(!1)}}async function oe(t){let n=await g(e);if(!n)return;let r=null,i=await dp(n,n=>{Xf(e,t.id,{status:`Review`,working:!0,threadId:n}).then(e=>{r=e,ee(e)})});if(!i)return;r||ee(await Xf(e,t.id,{status:`Review`,working:!0,threadId:i}));let o=await d(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await ke(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{threadId:t.threadId??t.id,model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(s=t.model,c=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!s||!c)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Z.SetProjectModel,threadId:i,model:{id:s,provider:c,name:s,description:``}}),fe(i,{model:s,modelProvider:c});let u=await jt(i,cp(sp(l.find(t=>t.projectId===e),`review`),`review`,t.id,t.description),s,[],void 0,c);u&&fp(u)}async function se(t,n){n===`Plan`?await z(t):n===`Build`?await te(t):n===`Test`?re(t):n===`Review`?await oe(t):ee(await Xf(e,t.id,{status:n,working:n!==`Done`}))}return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,$.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-8 flex-1 min-h-0`,children:lp.map(t=>{let i=u.filter(e=>e.status===t),a=t===`Ready`;return(0,$.jsxs)(`div`,{className:q(`flex flex-col rounded-lg border border-t-4 bg-muted/30 min-w-[200px] w-[200px] shrink-0`,up[t]),children:[(0,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:q(s.dropdownGroupHeading,`uppercase tracking-wide`),children:t}),(0,$.jsx)(`span`,{className:q(s.compact,`text-muted-foreground bg-muted rounded-full px-1.5 py-0.5`),children:i.length})]}),(0,$.jsx)(mt,{className:`flex-1 px-2 pb-2`,children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,$.jsxs)(W,{variant:`outline`,size:`sm`,className:`w-full h-8 border-dashed text-muted-foreground hover:text-foreground`,onClick:()=>n(!0),children:[(0,$.jsx)(dt,{className:`h-3 w-3 mr-1`}),`Add Task`]}),i.map(t=>(0,$.jsx)($f,{todo:t,projectId:e,onUpdate:ee,onEdit:j,onAction:se,onThreadSelect:r},t.id))]})})]},t)})}),(0,$.jsx)(Rt,{open:t,onOpenChange:n,children:(0,$.jsxs)(ce,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:`Add Task`})}),(0,$.jsxs)(`div`,{className:`py-2`,children:[(0,$.jsx)($i,{placeholder:`Describe what needs to be done...`,value:h,onChange:e=>_(e.target.value),rows:12,className:`resize-none text-base`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&F()}}),(0,$.jsx)(`p`,{className:q(s.caption,`mt-1.5`),children:`A title will be generated automatically from your description.`})]}),(0,$.jsx)(be,{children:(0,$.jsx)(W,{onClick:()=>void F(),disabled:v||!h.trim(),children:v?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3 animate-spin mr-1`}),`Generating title...`]}):`Add`})})]})}),(0,$.jsx)(Rt,{open:b,onOpenChange:e=>!e&&ie(),children:(0,$.jsxs)(ce,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:`Test Case`})}),(0,$.jsx)(`div`,{className:`py-2`,children:D?(0,$.jsxs)(`div`,{className:`flex items-center justify-center h-32 gap-2 text-muted-foreground`,children:[(0,$.jsx)(N,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{className:s.body,children:`Generating test case...`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)($i,{value:w,onChange:e=>T(e.target.value),rows:12,className:`resize-none text-base`,autoFocus:!0}),(0,$.jsx)(`p`,{className:q(s.caption,`mt-1.5`),children:`Review or edit the test case before confirming.`})]})}),(0,$.jsxs)(be,{children:[(0,$.jsx)(W,{variant:`outline`,onClick:ie,disabled:D,children:`Cancel`}),(0,$.jsx)(W,{onClick:()=>void ae(),disabled:D||!w.trim()||k,children:k?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3 animate-spin mr-1`}),`Starting...`]}):`Confirm`})]})]})}),(0,$.jsx)(Rt,{open:p!==null,onOpenChange:e=>!e&&P(),children:(0,$.jsxs)(ce,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(E,{children:(0,$.jsx)(I,{children:`Edit Task`})}),(0,$.jsx)(`div`,{className:`py-2`,children:(0,$.jsx)($i,{placeholder:`Describe what needs to be done...`,value:h,onChange:e=>_(e.target.value),rows:12,className:`resize-none text-base`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&L()}})}),(0,$.jsxs)(be,{className:`gap-2 sm:gap-0`,children:[(0,$.jsx)(W,{variant:`destructive`,onClick:()=>void R(),disabled:v,className:`mr-auto`,children:`Delete`}),(0,$.jsx)(W,{onClick:()=>void L(),disabled:v||!h.trim(),children:v?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3 animate-spin mr-1`}),`Saving...`]}):`Save`})]})]})})]})}function _p(e){let t=(0,X.c)(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({projectId:r,loadVersion:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]!==n||t[5]!==r?(a=hp(r,n),t[4]=n,t[5]=r,t[6]=a):a=t[6];let o;t[7]===r?o=t[8]:(o=()=>mp(r),t[7]=r,t[8]=o);let s=Ir(a,o),c;return t[9]!==s||t[10]!==r||t[11]!==i?(c=(0,$.jsx)(gp,{projectId:r,initialTodos:s,...i}),t[9]=s,t[10]=r,t[11]=i,t[12]=c):c=t[12],c}function vp(e){let t=(0,X.c)(11),[n,r]=(0,Y.useState)(0),i;t[0]!==n||t[1]!==e.projectId?(i=function(){Vr(hp(e.projectId,n)),r(yp)},t[0]=n,t[1]=e.projectId,t[2]=i):i=t[2];let a=i,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(zr,{className:`h-64`}),t[3]=o):o=t[3];let s=`${e.projectId}:${n}`,c;t[4]!==n||t[5]!==e||t[6]!==s?(c=(0,$.jsx)(Y.Suspense,{fallback:o,children:(0,$.jsx)(_p,{...e,loadVersion:n},s)}),t[4]=n,t[5]=e,t[6]=s,t[7]=c):c=t[7];let l;return t[8]!==a||t[9]!==c?(l=(0,$.jsx)(Br,{fallbackTitle:`Failed to load tasks`,onRetry:a,children:c}),t[8]=a,t[9]=c,t[10]=l):l=t[10],l}function yp(e){return e+1}var bp=Jn,xp=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=q(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Gn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});xp.displayName=Gn.displayName;var Sp=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=q(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-base font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(er,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Sp.displayName=er.displayName;var Cp=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=q(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Hn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Cp.displayName=Hn.displayName;var wp=[{value:`plan`,label:`Plan`,field:`planPrompt`,defaultPrompt:tp},{value:`review`,label:`Code Review`,field:`reviewPrompt`,defaultPrompt:ip},{value:`test`,label:`Test`,field:`testPrompt`,defaultPrompt:rp}];function Tp({open:e,onOpenChange:t,projectId:n}){let r=Q(e=>e.projects),[i,a]=(0,Y.useState)({plan:``,review:``,test:``}),[o,c]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(!e)return;let t=r.find(e=>e.projectId===n);a({plan:t?.planPrompt??``,review:t?.reviewPrompt??``,test:t?.testPrompt??``})},[e,n,r]);async function l(){c(!0);try{await he(n,{planPrompt:i.plan.trim()===tp?null:i.plan.trim()||null,testPrompt:i.test.trim()===rp?null:i.test.trim()||null,reviewPrompt:i.review.trim()===ip?null:i.review.trim()||null}),ee(),pa({title:`AI prompt settings saved`}),t(!1)}catch(e){pa({title:`Error`,description:e instanceof Error?e.message:`Failed to save prompt settings`,variant:`destructive`})}finally{c(!1)}}function u(e,t){a(n=>({...n,[e]:t}))}return(0,$.jsx)(Rt,{open:e,onOpenChange:t,children:(0,$.jsxs)(ce,{className:`max-w-2xl`,children:[(0,$.jsxs)(E,{children:[(0,$.jsx)(I,{children:`AI Prompt Settings`}),(0,$.jsx)(pe,{children:`Customize the prompts used when running Plan, Code Review, and Test actions from the task board. Leave empty to use the default prompt.`})]}),(0,$.jsxs)(bp,{defaultValue:`plan`,className:`w-full`,children:[(0,$.jsx)(xp,{className:`w-full`,children:wp.map(e=>(0,$.jsx)(Sp,{value:e.value,className:`flex-1`,children:e.label},e.value))}),wp.map(e=>(0,$.jsxs)(Cp,{value:e.value,children:[(0,$.jsx)($i,{value:i[e.value]||e.defaultPrompt,onChange:t=>u(e.value,t.target.value),className:`min-h-[250px] font-mono resize-none`,placeholder:e.defaultPrompt,disabled:o}),(0,$.jsxs)(`p`,{className:q(s.bodyMuted,`mt-1.5`),children:[`Use `,(0,$.jsx)(`code`,{className:s.mono,children:`{description}`}),` for the task description. Leave empty to use the default.`]})]},e.value))]}),(0,$.jsx)(be,{children:(0,$.jsx)(W,{onClick:()=>void l(),disabled:o,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`mr-2 h-4 w-4 animate-spin`}),`Saving...`]}):`Save`})})]})})}function Ep({projectId:e}){let t=Xi(),n=Q(e=>e.projects),r=Q(e=>e.selectedThreadId),i=Q(e=>e.selectedProjectId),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l=Sr(),{setActiveMainTab:u}=wo();async function d(a){if(n.find(t=>t.projectId===e)){l(`/`),u(`chat`);try{let{getProjects:n,invalidateProjectsCache:o}=await wr(async()=>{let{getProjects:e,invalidateProjectsCache:t}=await import(`./dialogs-config-BPzX42HH.js`).then(e=>e.f);return{getProjects:e,invalidateProjectsCache:t}},__vite__mapDeps([5,1]));o();let s=await n();t({type:Z.SetProjects,projects:s.projects});let c=s.projects.find(t=>t.projectId===e);if(c&&c.threads.find(e=>e.threadId===a)){(r!==a||i!==e)&&t({type:Z.SelectThread,threadId:a,projectId:e});try{let e=await st();t({type:Z.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after thread selection:`,e)}}}catch(n){console.error(`Failed to refresh projects for thread selection:`,n),(r!==a||i!==e)&&t({type:Z.SelectThread,threadId:a,projectId:e});try{let e=await st();t({type:Z.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after fallback thread selection:`,e)}}}}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden pt-8 pl-4`,children:(0,$.jsx)(vp,{projectId:e,addOpen:a,onAddOpenChange:o,onThreadSelect:d})}),(0,$.jsx)(W,{variant:`outline`,size:`icon`,className:`absolute bottom-8 right-4`,onClick:()=>c(!0),children:(0,$.jsx)(ht,{className:`h-4 w-4`})}),(0,$.jsx)(Tp,{open:s,onOpenChange:c,projectId:e})]})}var Dp=4,Op=`(max-width: 767px)`;function kp(e,t){let n=e.getBoundingClientRect().bottom,r=t.getBoundingClientRect().top,i=t.querySelector(`[data-chat-toolbar]`);return i&&i.getBoundingClientRect().height>0&&(r=Math.min(r,i.getBoundingClientRect().top)),Math.max(0,Math.ceil(n-r))+(window.matchMedia(Op).matches?Dp:0)}function Ap(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(kp(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 jp;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(jp||={});var Mp;(function(e){e.Body=`body`,e.Ionic=`ionic`,e.Native=`native`,e.None=`none`})(Mp||={});var Np=ii(`Keyboard`);function Pp(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 Fp(e,t){return R()?t:e>0?e:t}function Ip(e){let t=(0,X.c)(6),[n,r]=(0,Y.useState)(0),[i,a]=(0,Y.useState)(0),o,s;t[0]===e?(o=t[1],s=t[2]):(o=()=>{let t=function(){r(Pp(e.current))},n=function(){t(),requestAnimationFrame(t)};n();let i=window.visualViewport;i?.addEventListener(`resize`,n),i?.addEventListener(`scroll`,n),window.addEventListener(`resize`,n);let o=[];return Xe()&&o.push(Np.addListener(`keyboardWillShow`,e=>{a(e.keyboardHeight)}),Np.addListener(`keyboardDidShow`,e=>{a(e.keyboardHeight)}),Np.addListener(`keyboardWillHide`,()=>{a(0)}),Np.addListener(`keyboardDidHide`,()=>{a(0)})),()=>{i?.removeEventListener(`resize`,n),i?.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n);for(let e of o)e.then(Lp)}},s=[e],t[0]=e,t[1]=o,t[2]=s),(0,Y.useEffect)(o,s);let c;return t[3]!==n||t[4]!==i?(c=Fp(n,i),t[3]=n,t[4]=i,t[5]=c):c=t[5],c}function Lp(e){e.remove()}var Rp=(0,Y.lazy)(()=>wr(()=>import(`./diff-view-BnNtDcmG.js`),__vite__mapDeps([6,1,3,4,7,5,8,9,10,11]))),zp=(0,Y.lazy)(()=>wr(()=>import(`./dialogs-config-BPzX42HH.js`).then(e=>e.t),__vite__mapDeps([5,1])));function Bp(e){let t=(0,X.c)(61),{onCreateThread:n}=e,r=Xi(),i=Sr(),a=hr(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=Q(em),d=Q($p),f=Q(Qp),p=Q(Zp),m=Q(Xp),h=Q(Yp),g=Q(Jp),_=Q(qp),v=Q(Kp),y=Q(Gp),b=Q(Wp),x=Q(Up),S=Q(Hp),C;t[0]!==p||t[1]!==u?(C=u&&p.includes(u),t[0]=p,t[1]=u,t[2]=C):C=t[2];let w=!!C,T=b?.threadId===u,E;t[3]===r?E=t[4]:(E=()=>{r({type:Z.CloseSidebar})},t[3]=r,t[4]=E);let D=E,O;t[5]===D?O=t[6]:(O=()=>{D(),l(`clone`),s(!0)},t[5]=D,t[6]=O);let k=O,A;t[7]===D?A=t[8]:(A=()=>{D(),l(`webapp`),s(!0)},t[7]=D,t[8]=A);let j=A,M;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(M=async(e,t)=>{try{await Cn(e,t),s(!1),l(null)}catch(e){console.error(`Failed to clone repository:`,e)}},t[9]=M):M=t[9];let N=M,P;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(P=async(e,t,n)=>{try{await Pe(e,t,n),s(!1),l(null)}catch(e){console.error(`Failed to create project:`,e)}},t[10]=P):P=t[10];let F=P,I;t[11]===D?I=t[12]:(I=async()=>{D();try{await nt(),s(!1),l(null)}catch(e){console.error(`Failed to open folder:`,e)}},t[11]=D,t[12]=I);let L=I,R;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(R=async e=>{try{await En(e),s(!1),l(null)}catch(e){console.error(`Failed to create folder:`,e)}},t[13]=R):R=t[13];let ee=R,z=a.pathname===`/review`,te=a.pathname===`/todos`,ne;t[14]===i?ne=t[15]:(ne=()=>{i(`/`)},t[14]=i,t[15]=ne);let re=ne;Gf();let ie;t[16]===x?ie=t[17]:(ie=Dl(x),t[16]=x,t[17]=ie);let ae=ie,oe;t[18]===x?oe=t[19]:(oe=Ol(x),t[18]=x,t[19]=oe);let se=oe,ce=(0,Y.useRef)(null),le=(0,Y.useRef)(null),ue=(0,Y.useRef)(null),de=Wf(),[fe,pe]=(0,Y.useState)(!0),me=!z&&!te&&!!u,B=de&&me&&!fe,he=Ap(ce,le,me),ge=Ip(le),_e;t[20]!==he||t[21]!==D||t[22]!==r||t[23]!==k||t[24]!==re||t[25]!==j||t[26]!==L||t[27]!==T||t[28]!==f||t[29]!==w||t[30]!==_||t[31]!==d||t[32]!==g||t[33]!==n||t[34]!==m||t[35]!==h||t[36]!==z||t[37]!==S||t[38]!==u||t[39]!==y||t[40]!==v||t[41]!==te?(_e=te&&S?(0,$.jsx)(Ep,{projectId:S}):z&&u?(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(zr,{}),children:(0,$.jsx)(Rp,{threadId:u,onExit:re})}):(0,$.jsx)(wl,{ref:ue,bottomInset:he,messages:d,isStreaming:_,streamingSegments:v,streamingModel:y,isCreatingProject:f,isProcessingThread:w,hasPendingMessage:T,selectedThreadId:u,selectedProjectId:S,projects:m,projectsLoading:h,messagesLoaded:g,onSelectThread:(e,t)=>{D(),r({type:Z.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:k,onNewApp:j,onOpenFolder:L,error:null,onClearError:Vp,onAtBottomChange:pe}),t[20]=he,t[21]=D,t[22]=r,t[23]=k,t[24]=re,t[25]=j,t[26]=L,t[27]=T,t[28]=f,t[29]=w,t[30]=_,t[31]=d,t[32]=g,t[33]=n,t[34]=m,t[35]=h,t[36]=z,t[37]=S,t[38]=u,t[39]=y,t[40]=v,t[41]=te,t[42]=_e):_e=t[42];let ve;t[43]!==ae||t[44]!==se||t[45]!==ge||t[46]!==d||t[47]!==me||t[48]!==B?(ve=me&&(0,$.jsxs)(`div`,{ref:le,className:`absolute left-0 right-0 z-10 max-md:px-2`,style:{bottom:ge},children:[(0,$.jsx)(`div`,{className:`h-0 md:h-6`,style:{backgroundImage:se}}),(0,$.jsx)(`div`,{className:`h-0 md:h-8`,style:{backgroundImage:ae}}),B&&(0,$.jsx)(`div`,{className:`mb-1 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>ue.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)(pt,{className:`h-4 w-4`})})}),(0,$.jsx)(`div`,{style:{backgroundImage:ae},children:(0,$.jsx)(Rf,{messages:d})})]}),t[43]=ae,t[44]=se,t[45]=ge,t[46]=d,t[47]=me,t[48]=B,t[49]=ve):ve=t[49];let ye=c??void 0,be;t[50]!==o||t[51]!==L||t[52]!==ye?(be=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(zp,{open:o,onOpenChange:s,initialMode:ye,onSubmitClone:N,onSubmitWebApp:F,onSubmitFolder:ee,onOpenFolder:L})}),t[50]=o,t[51]=L,t[52]=ye,t[53]=be):be=t[53];let xe;t[54]!==_e||t[55]!==ve||t[56]!==be?(xe=(0,$.jsxs)(`div`,{ref:ce,className:`relative flex h-full flex-col`,children:[_e,ve,be]}),t[54]=_e,t[55]=ve,t[56]=be,t[57]=xe):xe=t[57];let Se;return t[58]!==u||t[59]!==xe?(Se=(0,$.jsx)(Us,{threadId:u,children:xe}),t[58]=u,t[59]=xe,t[60]=Se):Se=t[60],Se}function Vp(){}function Hp(e){return e.selectedProjectId}function Up(e){return e.sidebarOpen}function Wp(e){return e.pendingChatMessage}function Gp(e){return e.streamingModel}function Kp(e){return e.streamingSegments}function qp(e){return e.isStreaming}function Jp(e){return e.messagesLoaded}function Yp(e){return e.projectsLoading}function Xp(e){return e.projects}function Zp(e){return e.processingThreadIds}function Qp(e){return e.isCreatingProject}function $p(e){return e.messages}function em(e){return e.selectedThreadId}function tm(e){let t=(0,X.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=q(`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 nm(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}function rm(){let e=(0,X.c)(44),t=Xi(),n=Q(sm),r=Q(om),i=Q(am),a=Q(im),o;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),o=i.find(t),e[0]=i,e[1]=r,e[2]=o}else o=e[2];let c=o,l=!a,u,d;if(e[5]!==l){let t=ye();u=tm,d=q(t&&`pt-8 md:min-h-[103px]`,l&&t&&`max-md:pb-2 md:h-auto md:pb-3 md:h-[103px] md:pb-0`),e[5]=l,e[6]=u,e[7]=d}else u=e[6],d=e[7];let f;e[8]===t?f=e[9]:(f=()=>t({type:Z.ToggleSidebar}),e[8]=t,e[9]=f);let p;e[10]===a?p=e[11]:(p=a?(0,$.jsx)(_,{className:`h-4 w-4`}):(0,$.jsx)(y,{className:`h-4 w-4`}),e[10]=a,e[11]=p);let m;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle sidebar`}),e[12]=m):m=e[12];let h;e[13]!==f||e[14]!==p?(h=(0,$.jsxs)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0 electrobun-webkit-app-region-no-drag`,onClick:f,children:[p,m]}),e[13]=f,e[14]=p,e[15]=h):h=e[15];let g;e[16]!==i||e[17]!==r||e[18]!==n?(g=n&&(0,$.jsx)(`span`,{className:q(s.sectionTitle,`text-foreground truncate min-w-0`),children:it(i,r)}),e[16]=i,e[17]=r,e[18]=n,e[19]=g):g=e[19];let v;e[20]!==h||e[21]!==g?(v=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[h,g]}),e[20]=h,e[21]=g,e[22]=v):v=e[22];let b;e[23]===n?b=e[24]:(b=n&&(0,$.jsx)(df,{}),e[23]=n,e[24]=b);let x;e[25]!==c?.runCommand||e[26]!==r||e[27]!==n?(x=r&&(0,$.jsxs)(nm,{className:`electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(Yd,{projectId:r,runCommand:c?.runCommand}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pd,{threadId:n}),(0,$.jsx)(Ld,{})]})]}),e[25]=c?.runCommand,e[26]=r,e[27]=n,e[28]=x):x=e[28];let S;e[29]!==c?.openWith||e[30]!==r||e[31]!==n?(S=n&&r&&(0,$.jsx)(nm,{className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(Gd,{projectId:r,threadId:n,openWith:c?.openWith})}),e[29]=c?.openWith,e[30]=r,e[31]=n,e[32]=S):S=e[32];let C;e[33]!==S||e[34]!==x?(C=(0,$.jsxs)(`div`,{className:`hidden md:flex flex-wrap items-center justify-end gap-2`,children:[x,S]}),e[33]=S,e[34]=x,e[35]=C):C=e[35];let w;e[36]!==C||e[37]!==b?(w=(0,$.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[b,C]}),e[36]=C,e[37]=b,e[38]=w):w=e[38];let T;return e[39]!==u||e[40]!==d||e[41]!==w||e[42]!==v?(T=(0,$.jsxs)(u,{className:d,children:[v,w]}),e[39]=u,e[40]=d,e[41]=w,e[42]=v,e[43]=T):T=e[43],T}function im(e){return e.sidebarOpen}function am(e){return e.projects}function om(e){return e.selectedProjectId}function sm(e){return e.selectedThreadId}function cm(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)(jr,{children:`Delete Project`}),t[0]=o):o=t[0];let c;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=q(s.body,`font-semibold text-foreground`),t[1]=c):c=t[1];let l;t[2]===r?l=t[3]:(l=(0,$.jsxs)(Ar,{children:[o,(0,$.jsxs)(Nr,{children:[`Are you sure you want to delete`,` `,(0,$.jsxs)(`span`,{className:c,children:[`"`,r,`"`]}),`? This will remove the project and all its data. This action cannot be undone.`]})]}),t[2]=r,t[3]=l);let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Lr,{children:`Cancel`}),t[4]=u):u=t[4];let d;t[5]===a?d=t[6]:(d=(0,$.jsxs)(Fr,{children:[u,(0,$.jsx)(kr,{onClick:a,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[5]=a,t[6]=d);let f;t[7]!==l||t[8]!==d?(f=(0,$.jsxs)(Mr,{children:[l,d]}),t[7]=l,t[8]=d,t[9]=f):f=t[9];let p;return t[10]!==i||t[11]!==n||t[12]!==f?(p=(0,$.jsx)(Rr,{open:n,onOpenChange:i,children:f}),t[10]=i,t[11]=n,t[12]=f,t[13]=p):p=t[13],p}function lm(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)(jr,{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)(Ar,{children:[o,(0,$.jsxs)(Nr,{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(um),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)(Lr,{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)(kr,{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)(Fr,{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)(Mr,{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)(Rr,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function um(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:s.label,children:r||`root`}),(0,$.jsx)(`div`,{className:s.bodyMuted,children:i})]})]})},t)}function dm(e){let t=e.trim();return t?t.startsWith(`http://`)||t.startsWith(`https://`)?t:`http://${t}`:``}function fm(){return document.querySelector(`electrobun-webview`)}function pm(e=2e4){return new Promise((t,n)=>{let r=Date.now();function i(){let a=fm();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 mm(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 hm(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=fm();if(!r||r.webviewId==null){requestAnimationFrame(n);return}xf(e,r.webviewId).catch(e=>{console.error(`[browser-tool] failed to report preview webview ready`,e)})}requestAnimationFrame(n)}async function gm(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 pm();t.syncDimensions(!0),await Sf(r,{action:`set_viewport`,preset:e,webview_id:t.webviewId})}catch(t){console.error(`[browser-tool] failed to set viewport`,t),await Sf(r,{action:`set_viewport`,preset:e,error:t instanceof Error?t.message:String(t)})}return}if(Nn(i.action)){try{await Sf(r,await mm(await pm(),i,t))}catch(e){console.error(`[browser-tool] failed to execute host browser action`,e),await Sf(r,{action:i.action,error:e instanceof Error?e.message:String(e)})}return}hm(r)}}function _m(){let{activeMainTab:e,setActiveMainTab:t,setDevServerUrl:n,devServerUrl:r,setBrowserDeviceMode:i}=wo(),a=(0,Y.useRef)(null),o=Q(e=>{let t=a.current;return t?e.threadStreamingStates[t]?.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)(()=>{if(!ye())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=dm(n);e&&u.current(e)}gm(t,s.current||``,d.current)}return window.addEventListener(gf,e),function(){window.removeEventListener(gf,e)}},[])}var vm;(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`})(vm||={});var ym=new Map([[vm.QR_CODE,`QR_CODE`],[vm.AZTEC,`AZTEC`],[vm.CODABAR,`CODABAR`],[vm.CODE_39,`CODE_39`],[vm.CODE_93,`CODE_93`],[vm.CODE_128,`CODE_128`],[vm.DATA_MATRIX,`DATA_MATRIX`],[vm.MAXICODE,`MAXICODE`],[vm.ITF,`ITF`],[vm.EAN_13,`EAN_13`],[vm.EAN_8,`EAN_8`],[vm.PDF_417,`PDF_417`],[vm.RSS_14,`RSS_14`],[vm.RSS_EXPANDED,`RSS_EXPANDED`],[vm.UPC_A,`UPC_A`],[vm.UPC_E,`UPC_E`],[vm.UPC_EAN_EXTENSION,`UPC_EAN_EXTENSION`]]),bm;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.URL=1]=`URL`})(bm||={});function xm(e){return Object.values(vm).includes(e)}var Sm;(function(e){e[e.SCAN_TYPE_CAMERA=0]=`SCAN_TYPE_CAMERA`,e[e.SCAN_TYPE_FILE=1]=`SCAN_TYPE_FILE`})(Sm||={});var Cm=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=[Sm.SCAN_TYPE_CAMERA,Sm.SCAN_TYPE_FILE],e}(),wm=function(){function e(e,t){this.format=e,this.formatName=t}return e.prototype.toString=function(){return this.formatName},e.create=function(t){if(!ym.has(t))throw`${t} not in html5QrcodeSupportedFormatsTextMap`;return new e(t,ym.get(t))},e}(),Tm=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}(),Em;(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`})(Em||={});var Dm=function(){function e(){}return e.createFrom=function(e){return{errorMessage:e,type:Em.UNKWOWN_ERROR}},e}(),Om=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 km(e){return e==null}function Am(e,t,n){return e>n?n:e<t?t:e}var jm=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}(),Mm=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}(),Nm=function(){function e(){}return e.poweredBy=function(){return`Powered by `},e.reportIssues=function(){return`Report issues`},e}(),Pm=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}(),Fm=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)===`
|
|
67
|
+
`||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=`
|
|
68
|
+
`){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(`
|
|
69
|
+
`)}return t.toString()}}class N extends M{constructor(e){super(e.getWidth(),e.getHeight()),this.delegate=e}getRow(e,t){let n=this.delegate.getRow(e,t),r=this.getWidth();for(let e=0;e<r;e++)n[e]=255-(n[e]&255);return n}getMatrix(){let e=this.delegate.getMatrix(),t=this.getWidth()*this.getHeight(),n=new Uint8ClampedArray(t);for(let r=0;r<t;r++)n[r]=255-(e[r]&255);return n}isCropSupported(){return this.delegate.isCropSupported()}crop(e,t,n,r){return new N(this.delegate.crop(e,t,n,r))}isRotateSupported(){return this.delegate.isRotateSupported()}invert(){return this.delegate}rotateCounterClockwise(){return new N(this.delegate.rotateCounterClockwise())}rotateCounterClockwise45(){return new N(this.delegate.rotateCounterClockwise45())}}class P extends M{constructor(e){super(e.width,e.height),this.canvas=e,this.tempCanvasElement=null,this.buffer=P.makeBufferFromCanvasImageData(e)}static makeBufferFromCanvasImageData(e){let t=e.getContext(`2d`).getImageData(0,0,e.width,e.height);return P.toGrayscaleBuffer(t.data,e.width,e.height)}static toGrayscaleBuffer(e,t,n){let r=new Uint8ClampedArray(t*n);for(let t=0,n=0,i=e.length;t<i;t+=4,n++){let i;if(e[t+3]===0)i=255;else{let n=e[t],r=e[t+1],a=e[t+2];i=306*n+601*r+117*a+512>>10}r[n]=i}return r}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth(),r=e*n;return t===null?t=this.buffer.slice(r,r+n):(t.length<n&&(t=new Uint8ClampedArray(n)),t.set(this.buffer.slice(r,r+n))),t}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(e,t,n,r){return super.crop(e,t,n,r),this}isRotateSupported(){return!0}rotateCounterClockwise(){return this.rotate(-90),this}rotateCounterClockwise45(){return this.rotate(-45),this}getTempCanvasElement(){if(this.tempCanvasElement===null){let e=this.canvas.ownerDocument.createElement(`canvas`);e.width=this.canvas.width,e.height=this.canvas.height,this.tempCanvasElement=e}return this.tempCanvasElement}rotate(e){let t=this.getTempCanvasElement(),n=t.getContext(`2d`),r=e*P.DEGREE_TO_RADIANS,i=this.canvas.width,a=this.canvas.height,o=Math.ceil(Math.abs(Math.cos(r))*i+Math.abs(Math.sin(r))*a),s=Math.ceil(Math.abs(Math.sin(r))*i+Math.abs(Math.cos(r))*a);return t.width=o,t.height=s,n.translate(o/2,s/2),n.rotate(r),n.drawImage(this.canvas,i/-2,a/-2),this.buffer=P.makeBufferFromCanvasImageData(t),this}invert(){return new N(this)}}P.DEGREE_TO_RADIANS=Math.PI/180;class F{constructor(e,t,n){this.deviceId=e,this.label=t,this.kind=`videoinput`,this.groupId=n||void 0}toJSON(){return{kind:this.kind,groupId:this.groupId,deviceId:this.deviceId,label:this.label}}}var I=(globalThis||global||self||window||void 0)&&(globalThis||global||self||window||void 0).__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})};class L{constructor(e,t=500,n){this.reader=e,this.timeBetweenScansMillis=t,this._hints=n,this._stopContinuousDecode=!1,this._stopAsyncDecode=!1,this._timeBetweenDecodingAttempts=0}get hasNavigator(){return typeof navigator<`u`}get isMediaDevicesSuported(){return this.hasNavigator&&!!navigator.mediaDevices}get canEnumerateDevices(){return!!(this.isMediaDevicesSuported&&navigator.mediaDevices.enumerateDevices)}get timeBetweenDecodingAttempts(){return this._timeBetweenDecodingAttempts}set timeBetweenDecodingAttempts(e){this._timeBetweenDecodingAttempts=e<0?0:e}set hints(e){this._hints=e||null}get hints(){return this._hints}listVideoInputDevices(){return I(this,void 0,void 0,function*(){if(!this.hasNavigator)throw Error(`Can't enumerate devices, navigator is not present.`);if(!this.canEnumerateDevices)throw Error(`Can't enumerate devices, method not supported.`);let e=yield navigator.mediaDevices.enumerateDevices(),t=[];for(let n of e){let e=n.kind===`video`?`videoinput`:n.kind;if(e!==`videoinput`)continue;let r={deviceId:n.deviceId||n.id,label:n.label||`Video device ${t.length+1}`,kind:e,groupId:n.groupId};t.push(r)}return t})}getVideoInputDevices(){return I(this,void 0,void 0,function*(){return(yield this.listVideoInputDevices()).map(e=>new F(e.deviceId,e.label))})}findDeviceById(e){return I(this,void 0,void 0,function*(){let t=yield this.listVideoInputDevices();return t?t.find(t=>t.deviceId===e):null})}decodeFromInputVideoDevice(e,t){return I(this,void 0,void 0,function*(){return yield this.decodeOnceFromVideoDevice(e,t)})}decodeOnceFromVideoDevice(e,t){return I(this,void 0,void 0,function*(){this.reset();let n;n=e?{deviceId:{exact:e}}:{facingMode:`environment`};let r={video:n};return yield this.decodeOnceFromConstraints(r,t)})}decodeOnceFromConstraints(e,t){return I(this,void 0,void 0,function*(){let n=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeOnceFromStream(n,t)})}decodeOnceFromStream(e,t){return I(this,void 0,void 0,function*(){this.reset();let n=yield this.attachStreamToVideo(e,t);return yield this.decodeOnce(n)})}decodeFromInputVideoDeviceContinuously(e,t,n){return I(this,void 0,void 0,function*(){return yield this.decodeFromVideoDevice(e,t,n)})}decodeFromVideoDevice(e,t,n){return I(this,void 0,void 0,function*(){let r;r=e?{deviceId:{exact:e}}:{facingMode:`environment`};let i={video:r};return yield this.decodeFromConstraints(i,t,n)})}decodeFromConstraints(e,t,n){return I(this,void 0,void 0,function*(){let r=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeFromStream(r,t,n)})}decodeFromStream(e,t,n){return I(this,void 0,void 0,function*(){this.reset();let r=yield this.attachStreamToVideo(e,t);return yield this.decodeContinuously(r,n)})}stopAsyncDecode(){this._stopAsyncDecode=!0}stopContinuousDecode(){this._stopContinuousDecode=!0}attachStreamToVideo(e,t){return I(this,void 0,void 0,function*(){let n=this.prepareVideoElement(t);return this.addVideoSource(n,e),this.videoElement=n,this.stream=e,yield this.playVideoOnLoadAsync(n),n})}playVideoOnLoadAsync(e){return new Promise((t,n)=>this.playVideoOnLoad(e,()=>t()))}playVideoOnLoad(e,t){this.videoEndedListener=()=>this.stopStreams(),this.videoCanPlayListener=()=>this.tryPlayVideo(e),e.addEventListener(`ended`,this.videoEndedListener),e.addEventListener(`canplay`,this.videoCanPlayListener),e.addEventListener(`playing`,t),this.tryPlayVideo(e)}isVideoPlaying(e){return e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2}tryPlayVideo(e){return I(this,void 0,void 0,function*(){if(this.isVideoPlaying(e)){console.warn(`Trying to play video that is already playing.`);return}try{yield e.play()}catch{console.warn(`It was not possible to play the video.`)}})}getMediaElement(e,t){let n=document.getElementById(e);if(!n)throw new c(`element with id '${e}' not found`);if(n.nodeName.toLowerCase()!==t.toLowerCase())throw new c(`element with id '${e}' must be an ${t} element`);return n}decodeFromImage(e,t){if(!e&&!t)throw new c(`either imageElement with a src set or an url must be provided`);return t&&!e?this.decodeFromImageUrl(t):this.decodeFromImageElement(e)}decodeFromVideo(e,t){if(!e&&!t)throw new c(`Either an element with a src set or an URL must be provided`);return t&&!e?this.decodeFromVideoUrl(t):this.decodeFromVideoElement(e)}decodeFromVideoContinuously(e,t,n){if(e===void 0&&t===void 0)throw new c(`Either an element with a src set or an URL must be provided`);return t&&!e?this.decodeFromVideoUrlContinuously(t,n):this.decodeFromVideoElementContinuously(e,n)}decodeFromImageElement(e){if(!e)throw new c(`An image element must be provided.`);this.reset();let t=this.prepareImageElement(e);this.imageElement=t;let n;return n=this.isImageLoaded(t)?this.decodeOnce(t,!1,!0):this._decodeOnLoadImage(t),n}decodeFromVideoElement(e){let t=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideo(t)}decodeFromVideoElementContinuously(e,t){let n=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideoContinuously(n,t)}_decodeFromVideoElementSetup(e){if(!e)throw new c(`A video element must be provided.`);this.reset();let t=this.prepareVideoElement(e);return this.videoElement=t,t}decodeFromImageUrl(e){if(!e)throw new c(`An URL must be provided.`);this.reset();let t=this.prepareImageElement();this.imageElement=t;let n=this._decodeOnLoadImage(t);return t.src=e,n}decodeFromVideoUrl(e){if(!e)throw new c(`An URL must be provided.`);this.reset();let t=this.prepareVideoElement(),n=this.decodeFromVideoElement(t);return t.src=e,n}decodeFromVideoUrlContinuously(e,t){if(!e)throw new c(`An URL must be provided.`);this.reset();let n=this.prepareVideoElement(),r=this.decodeFromVideoElementContinuously(n,t);return n.src=e,r}_decodeOnLoadImage(e){return new Promise((t,n)=>{this.imageLoadedListener=()=>this.decodeOnce(e,!1,!0).then(t,n),e.addEventListener(`load`,this.imageLoadedListener)})}_decodeOnLoadVideo(e){return I(this,void 0,void 0,function*(){return yield this.playVideoOnLoadAsync(e),yield this.decodeOnce(e)})}_decodeOnLoadVideoContinuously(e,t){return I(this,void 0,void 0,function*(){yield this.playVideoOnLoadAsync(e),this.decodeContinuously(e,t)})}isImageLoaded(e){return!(!e.complete||e.naturalWidth===0)}prepareImageElement(e){let t;return e===void 0&&(t=document.createElement(`img`),t.width=200,t.height=200),typeof e==`string`&&(t=this.getMediaElement(e,`img`)),e instanceof HTMLImageElement&&(t=e),t}prepareVideoElement(e){let t;return!e&&typeof document<`u`&&(t=document.createElement(`video`),t.width=200,t.height=200),typeof e==`string`&&(t=this.getMediaElement(e,`video`)),e instanceof HTMLVideoElement&&(t=e),t.setAttribute(`autoplay`,`true`),t.setAttribute(`muted`,`true`),t.setAttribute(`playsinline`,`true`),t}decodeOnce(e,t=!0,n=!0){this._stopAsyncDecode=!1;let r=(i,a)=>{if(this._stopAsyncDecode){a(new k(`Video stream has ended before any code could be detected.`)),this._stopAsyncDecode=void 0;return}try{i(this.decode(e))}catch(e){let o=t&&e instanceof k,s=(e instanceof d||e instanceof x)&&n;if(o||s)return setTimeout(r,this._timeBetweenDecodingAttempts,i,a);a(e)}};return new Promise((e,t)=>r(e,t))}decodeContinuously(e,t){this._stopContinuousDecode=!1;let n=()=>{if(this._stopContinuousDecode){this._stopContinuousDecode=void 0;return}try{t(this.decode(e),null),setTimeout(n,this.timeBetweenScansMillis)}catch(e){t(null,e);let r=e instanceof d||e instanceof x,i=e instanceof k;(r||i)&&setTimeout(n,this._timeBetweenDecodingAttempts)}};n()}decode(e){let t=this.createBinaryBitmap(e);return this.decodeBitmap(t)}_isHTMLVideoElement(e){return e.videoWidth!==0}drawFrameOnCanvas(e,t,n){t||={sx:0,sy:0,sWidth:e.videoWidth,sHeight:e.videoHeight,dx:0,dy:0,dWidth:e.videoWidth,dHeight:e.videoHeight},n||=this.captureCanvasContext,n.drawImage(e,t.sx,t.sy,t.sWidth,t.sHeight,t.dx,t.dy,t.dWidth,t.dHeight)}drawImageOnCanvas(e,t,n=this.captureCanvasContext){t||={sx:0,sy:0,sWidth:e.naturalWidth,sHeight:e.naturalHeight,dx:0,dy:0,dWidth:e.naturalWidth,dHeight:e.naturalHeight},n||=this.captureCanvasContext,n.drawImage(e,t.sx,t.sy,t.sWidth,t.sHeight,t.dx,t.dy,t.dWidth,t.dHeight)}createBinaryBitmap(e){return this.getCaptureCanvasContext(e),this._isHTMLVideoElement(e)?this.drawFrameOnCanvas(e):this.drawImageOnCanvas(e),new u(new j(new P(this.getCaptureCanvas(e))))}getCaptureCanvasContext(e){if(!this.captureCanvasContext){let t=this.getCaptureCanvas(e).getContext(`2d`);this.captureCanvasContext=t}return this.captureCanvasContext}getCaptureCanvas(e){if(!this.captureCanvas){let t=this.createCaptureCanvas(e);this.captureCanvas=t}return this.captureCanvas}decodeBitmap(e){return this.reader.decode(e,this._hints)}createCaptureCanvas(e){if(typeof document>`u`)return this._destroyCaptureCanvas(),null;let t=document.createElement(`canvas`),n,r;return e!==void 0&&(e instanceof HTMLVideoElement?(n=e.videoWidth,r=e.videoHeight):e instanceof HTMLImageElement&&(n=e.naturalWidth||e.width,r=e.naturalHeight||e.height)),t.style.width=n+`px`,t.style.height=r+`px`,t.width=n,t.height=r,t}stopStreams(){this.stream&&=(this.stream.getVideoTracks().forEach(e=>e.stop()),void 0),this._stopAsyncDecode===!1&&this.stopAsyncDecode(),this._stopContinuousDecode===!1&&this.stopContinuousDecode()}reset(){this.stopStreams(),this._destroyVideoElement(),this._destroyImageElement(),this._destroyCaptureCanvas()}_destroyVideoElement(){this.videoElement&&=(this.videoEndedListener!==void 0&&this.videoElement.removeEventListener(`ended`,this.videoEndedListener),this.videoPlayingEventListener!==void 0&&this.videoElement.removeEventListener(`playing`,this.videoPlayingEventListener),this.videoCanPlayListener!==void 0&&this.videoElement.removeEventListener(`loadedmetadata`,this.videoCanPlayListener),this.cleanVideoSource(this.videoElement),void 0)}_destroyImageElement(){this.imageElement&&=(this.imageLoadedListener!==void 0&&this.imageElement.removeEventListener(`load`,this.imageLoadedListener),this.imageElement.src=void 0,this.imageElement.removeAttribute(`src`),void 0)}_destroyCaptureCanvas(){this.captureCanvasContext=void 0,this.captureCanvas=void 0}addVideoSource(e,t){try{e.srcObject=t}catch{e.src=URL.createObjectURL(t)}}cleanVideoSource(e){try{e.srcObject=null}catch{e.src=``}this.videoElement.removeAttribute(`src`)}}class R{constructor(e,t,n=t==null?0:8*t.length,r,i,a=p.currentTimeMillis()){this.text=e,this.rawBytes=t,this.numBits=n,this.resultPoints=r,this.format=i,this.timestamp=a,this.text=e,this.rawBytes=t,n==null?this.numBits=t==null?0:8*t.length:this.numBits=n,this.resultPoints=r,this.format=i,this.resultMetadata=null,a==null?this.timestamp=p.currentTimeMillis():this.timestamp=a}getText(){return this.text}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}getResultPoints(){return this.resultPoints}getBarcodeFormat(){return this.format}getResultMetadata(){return this.resultMetadata}putMetadata(e,t){this.resultMetadata===null&&(this.resultMetadata=new Map),this.resultMetadata.set(e,t)}putAllMetadata(e){e!==null&&(this.resultMetadata===null?this.resultMetadata=e:this.resultMetadata=new Map(e))}addResultPoints(e){let t=this.resultPoints;if(t===null)this.resultPoints=e;else if(e!==null&&e.length>0){let n=Array(t.length+e.length);p.arraycopy(t,0,n,0,t.length),p.arraycopy(e,0,n,t.length,e.length),this.resultPoints=n}}getTimestamp(){return this.timestamp}toString(){return this.text}}var ee;(function(e){e[e.AZTEC=0]=`AZTEC`,e[e.CODABAR=1]=`CODABAR`,e[e.CODE_39=2]=`CODE_39`,e[e.CODE_93=3]=`CODE_93`,e[e.CODE_128=4]=`CODE_128`,e[e.DATA_MATRIX=5]=`DATA_MATRIX`,e[e.EAN_8=6]=`EAN_8`,e[e.EAN_13=7]=`EAN_13`,e[e.ITF=8]=`ITF`,e[e.MAXICODE=9]=`MAXICODE`,e[e.PDF_417=10]=`PDF_417`,e[e.QR_CODE=11]=`QR_CODE`,e[e.RSS_14=12]=`RSS_14`,e[e.RSS_EXPANDED=13]=`RSS_EXPANDED`,e[e.UPC_A=14]=`UPC_A`,e[e.UPC_E=15]=`UPC_E`,e[e.UPC_EAN_EXTENSION=16]=`UPC_EAN_EXTENSION`})(ee||={});var z=ee,te;(function(e){e[e.OTHER=0]=`OTHER`,e[e.ORIENTATION=1]=`ORIENTATION`,e[e.BYTE_SEGMENTS=2]=`BYTE_SEGMENTS`,e[e.ERROR_CORRECTION_LEVEL=3]=`ERROR_CORRECTION_LEVEL`,e[e.ISSUE_NUMBER=4]=`ISSUE_NUMBER`,e[e.SUGGESTED_PRICE=5]=`SUGGESTED_PRICE`,e[e.POSSIBLE_COUNTRY=6]=`POSSIBLE_COUNTRY`,e[e.UPC_EAN_EXTENSION=7]=`UPC_EAN_EXTENSION`,e[e.PDF417_EXTRA_METADATA=8]=`PDF417_EXTRA_METADATA`,e[e.STRUCTURED_APPEND_SEQUENCE=9]=`STRUCTURED_APPEND_SEQUENCE`,e[e.STRUCTURED_APPEND_PARITY=10]=`STRUCTURED_APPEND_PARITY`})(te||={});var ne=te;class re{constructor(e,t,n,r,i=-1,a=-1){this.rawBytes=e,this.text=t,this.byteSegments=n,this.ecLevel=r,this.structuredAppendSequenceNumber=i,this.structuredAppendParity=a,this.numBits=e==null?0:8*e.length}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}setNumBits(e){this.numBits=e}getText(){return this.text}getByteSegments(){return this.byteSegments}getECLevel(){return this.ecLevel}getErrorsCorrected(){return this.errorsCorrected}setErrorsCorrected(e){this.errorsCorrected=e}getErasures(){return this.erasures}setErasures(e){this.erasures=e}getOther(){return this.other}setOther(e){this.other=e}hasStructuredAppend(){return this.structuredAppendParity>=0&&this.structuredAppendSequenceNumber>=0}getStructuredAppendParity(){return this.structuredAppendParity}getStructuredAppendSequenceNumber(){return this.structuredAppendSequenceNumber}}class ie{exp(e){return this.expTable[e]}log(e){if(e===0)throw new l;return this.logTable[e]}static addOrSubtract(e,t){return e^t}}class ae{constructor(e,t){if(t.length===0)throw new l;this.field=e;let n=t.length;if(n>1&&t[0]===0){let e=1;for(;e<n&&t[e]===0;)e++;e===n?this.coefficients=Int32Array.from([0]):(this.coefficients=new Int32Array(n-e),p.arraycopy(t,e,this.coefficients,0,this.coefficients.length))}else this.coefficients=t}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);let t=this.coefficients,n;if(e===1){n=0;for(let e=0,r=t.length;e!==r;e++){let r=t[e];n=ie.addOrSubtract(n,r)}return n}n=t[0];let r=t.length,i=this.field;for(let a=1;a<r;a++)n=ie.addOrSubtract(i.multiply(e,n),t[a]);return n}addOrSubtract(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(this.isZero())return e;if(e.isZero())return this;let t=this.coefficients,n=e.coefficients;if(t.length>n.length){let e=t;t=n,n=e}let r=new Int32Array(n.length),i=n.length-t.length;p.arraycopy(n,0,r,0,i);for(let e=i;e<n.length;e++)r[e]=ie.addOrSubtract(t[e-i],n[e]);return new ae(this.field,r)}multiply(e){if(!this.field.equals(e.field))throw new l(`GenericGFPolys do not have same GenericGF field`);if(this.isZero()||e.isZero())return this.field.getZero();let t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,a=new Int32Array(n+i-1),o=this.field;for(let e=0;e<n;e++){let n=t[e];for(let t=0;t<i;t++)a[e+t]=ie.addOrSubtract(a[e+t],o.multiply(n,r[t]))}return new ae(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 ae(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 ae(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 oe extends s{}oe.kind=`ArithmeticException`;class se extends ie{constructor(e,t,n){super(),this.primitive=e,this.size=t,this.generatorBase=n;let r=new Int32Array(t),i=1;for(let n=0;n<t;n++)r[n]=i,i*=2,i>=t&&(i^=e,i&=t-1);this.expTable=r;let a=new Int32Array(t);for(let e=0;e<t-1;e++)a[r[e]]=e;this.logTable=a,this.zero=new ae(this,Int32Array.from([0])),this.one=new ae(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 ae(this,n)}inverse(e){if(e===0)throw new oe;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}}se.AZTEC_DATA_12=new se(4201,4096,1),se.AZTEC_DATA_10=new se(1033,1024,1),se.AZTEC_DATA_6=new se(67,64,1),se.AZTEC_PARAM=new se(19,16,1),se.QR_CODE_FIELD_256=new se(285,256,0),se.DATA_MATRIX_FIELD_256=new se(301,256,1),se.AZTEC_DATA_8=se.DATA_MATRIX_FIELD_256,se.MAXICODE_FIELD_64=se.AZTEC_DATA_6;class ce extends s{}ce.kind=`ReedSolomonException`;class le extends s{}le.kind=`IllegalStateException`;class ue{constructor(e){this.field=e}decode(e,t){let n=this.field,r=new ae(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 ae(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 ce(`Bad error location`);e[r]=se.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 ce(`r_{i-1} was zero`);a=e;let n=r.getZero(),c=i.getCoefficient(i.getDegree()),l=r.inverse(c);for(;a.getDegree()>=i.getDegree()&&!a.isZero();){let e=a.getDegree()-i.getDegree(),t=r.multiply(a.getCoefficient(a.getDegree()),l);n=n.addOrSubtract(r.buildMonomial(e,t)),a=a.addOrSubtract(i.multiplyByMonomial(e,t))}if(s=n.multiply(o).addOrSubtract(t),a.getDegree()>=i.getDegree())throw new le(`Division algorithm failed to reduce polynomial?`)}let c=s.getCoefficient(0);if(c===0)throw new ce(`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 ce(`Error locator degree does not match number of roots`);return n}findErrorMagnitudes(e,t){let n=t.length,r=new Int32Array(n),i=this.field;for(let a=0;a<n;a++){let o=i.inverse(t[a]),s=1;for(let e=0;e<n;e++)if(a!==e){let n=i.multiply(t[e],o),r=n&1?n&-2:n|1;s=i.multiply(s,r)}r[a]=i.multiply(e.evaluateAt(o),i.inverse(s)),i.getGeneratorBase()!==0&&(r[a]=i.multiply(r[a],o))}return r}}var de;(function(e){e[e.UPPER=0]=`UPPER`,e[e.LOWER=1]=`LOWER`,e[e.MIXED=2]=`MIXED`,e[e.DIGIT=3]=`DIGIT`,e[e.PUNCT=4]=`PUNCT`,e[e.BINARY=5]=`BINARY`})(de||={});class fe{decode(e){this.ddata=e;let t=e.getBits(),n=this.extractBits(t),r=this.correctBits(n),i=new re(fe.convertBoolArrayToByteArray(r),fe.getEncodedData(r),null,null);return i.setNumBits(r.length),i}static highLevelDecode(e){return this.getEncodedData(e)}static getEncodedData(e){let t=e.length,n=de.UPPER,r=de.UPPER,i=``,a=0;for(;a<t;)if(r===de.BINARY){if(t-a<5)break;let o=fe.readCode(e,a,5);if(a+=5,o===0){if(t-a<11)break;o=fe.readCode(e,a,11)+31,a+=11}for(let n=0;n<o;n++){if(t-a<8){a=t;break}let n=fe.readCode(e,a,8);i+=E.castAsNonUtf8Char(n),a+=8}r=n}else{let o=r===de.DIGIT?4:5;if(t-a<o)break;let s=fe.readCode(e,a,o);a+=o;let c=fe.getCharacter(r,s);c.startsWith(`CTRL_`)?(n=r,r=fe.getTable(c.charAt(5)),c.charAt(6)===`L`&&(n=r)):(i+=c,r=n)}return i}static getTable(e){switch(e){case`L`:return de.LOWER;case`P`:return de.PUNCT;case`M`:return de.MIXED;case`D`:return de.DIGIT;case`B`:return de.BINARY;default:return de.UPPER}}static getCharacter(e,t){switch(e){case de.UPPER:return fe.UPPER_TABLE[t];case de.LOWER:return fe.LOWER_TABLE[t];case de.MIXED:return fe.MIXED_TABLE[t];case de.PUNCT:return fe.PUNCT_TABLE[t];case de.DIGIT:return fe.DIGIT_TABLE[t];default:throw new le(`Bad table`)}}correctBits(e){let t,n;this.ddata.getNbLayers()<=2?(n=6,t=se.AZTEC_DATA_6):this.ddata.getNbLayers()<=8?(n=8,t=se.AZTEC_DATA_8):this.ddata.getNbLayers()<=22?(n=10,t=se.AZTEC_DATA_10):(n=12,t=se.AZTEC_DATA_12);let r=this.ddata.getNbDatablocks(),i=e.length/n;if(i<r)throw new x;let a=e.length%n,o=new Int32Array(i);for(let t=0;t<i;t++,a+=n)o[t]=fe.readCode(e,a,n);try{new ue(t).decode(o,i-r)}catch(e){throw new x(e)}let s=(1<<n)-1,c=0;for(let e=0;e<r;e++){let t=o[e];if(t===0||t===s)throw new x;(t===1||t===s-1)&&c++}let l=Array(r*n-c),u=0;for(let e=0;e<r;e++){let t=o[e];if(t===1||t===s-1)l.fill(t>1,u,u+n-1),u+=n-1;else for(let e=n-1;e>=0;--e)l[u++]=(t&1<<e)!=0}return l}extractBits(e){let t=this.ddata.isCompact(),n=this.ddata.getNbLayers(),r=(t?11:14)+n*4,i=new Int32Array(r),a=Array(this.totalBitsInLayer(n,t));if(t)for(let e=0;e<i.length;e++)i[e]=e;else{let e=r+1+2*_.truncDivision(_.truncDivision(r,2)-1,15),t=r/2,n=_.truncDivision(e,2);for(let e=0;e<t;e++){let r=e+_.truncDivision(e,15);i[t-e-1]=n-r-1,i[t+e]=n+r+1}}for(let o=0,s=0;o<n;o++){let c=(n-o)*4+(t?9:12),l=o*2,u=r-1-l;for(let t=0;t<c;t++){let n=t*2;for(let r=0;r<2;r++)a[s+n+r]=e.get(i[l+r],i[l+t]),a[s+2*c+n+r]=e.get(i[l+t],i[u-r]),a[s+4*c+n+r]=e.get(i[u-r],i[u-t]),a[s+6*c+n+r]=e.get(i[u-t],i[l+r])}s+=c*8}return a}static readCode(e,t,n){let r=0;for(let i=t;i<t+n;i++)r<<=1,e[i]&&(r|=1);return r}static readByte(e,t){let n=e.length-t;return n>=8?fe.readCode(e,t,8):fe.readCode(e,t,n)<<8-n}static convertBoolArrayToByteArray(e){let t=new Uint8Array((e.length+7)/8);for(let n=0;n<t.length;n++)t[n]=fe.readByte(e,8*n);return t}totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}fe.UPPER_TABLE=`CTRL_PS. .A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z.CTRL_LL.CTRL_ML.CTRL_DL.CTRL_BS`.split(`.`),fe.LOWER_TABLE=`CTRL_PS. .a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.CTRL_US.CTRL_ML.CTRL_DL.CTRL_BS`.split(`.`),fe.MIXED_TABLE=`CTRL_PS. .\\1.\\2.\\3.\\4.\\5.\\6.\\7.\b. .
|
|
70
|
+
.\\13.\f.\r.\\33.\\34.\\35.\\36.\\37.@.\\.^._.\`.|.~.\\177.CTRL_LL.CTRL_UL.CTRL_PL.CTRL_BS`.split(`.`),fe.PUNCT_TABLE=[``,`\r`,`\r
|
|
71
|
+
`,`. `,`, `,`: `,`!`,`"`,`#`,`$`,`%`,`&`,`'`,`(`,`)`,`*`,`+`,`,`,`-`,`.`,`/`,`:`,`;`,`<`,`=`,`>`,`?`,`[`,`]`,`{`,`}`,`CTRL_UL`],fe.DIGIT_TABLE=[`CTRL_PS`,` `,`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`,`,`.`,`CTRL_UL`,`CTRL_US`];class pe{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 me{static floatToIntBits(e){return e}}me.MAX_VALUE=2**53-1;class B{constructor(e,t){this.x=e,this.y=t}getX(){return this.x}getY(){return this.y}equals(e){if(e instanceof B){let t=e;return this.x===t.x&&this.y===t.y}return!1}hashCode(){return 31*me.floatToIntBits(this.x)+me.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 pe.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 he{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class ge extends he{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 _e{constructor(e,t,n,r){this.image=e,this.height=e.getHeight(),this.width=e.getWidth(),t??=_e.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=pe.round(pe.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=pe.round(e+n*a),i=pe.round(t+n*o);if(s.get(r,i))return new B(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=_e.CORR;return i<this.width/2?[new B(u-f,d+f),new B(o+f,s+f),new B(c-f,l-f),new B(i+f,a-f)]:[new B(u+f,d+f),new B(o+f,s-f),new B(c-f,l+f),new B(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}}_e.INIT_SIZE=10,_e.CORR=1;class ve{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 ye{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=ye.quadrilateralToSquare(e,t,n,r,i,a,o,s);return ye.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 ye(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 ye(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 ye.squareToQuadrilateral(e,t,n,r,i,a,o,s).buildAdjoint()}buildAdjoint(){return new ye(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 ye(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 be extends ve{sampleGrid(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v){let y=ye.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),ve.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 xe{static setGridSampler(e){xe.gridSampler=e}static getInstance(){return xe.gridSampler}}xe.gridSampler=new be;class Se{constructor(e,t){this.x=e,this.y=t}toResultPoint(){return new B(this.getX(),this.getY())}getX(){return this.x}getY(){return this.y}}class Ce{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 ge(this.sampleGrid(this.image,n[this.shift%4],n[(this.shift+1)%4],n[(this.shift+2)%4],n[(this.shift+3)%4]),this.getMatrixCornerPoints(n),this.compact,this.nbDataBlocks,this.nbLayers)}extractParameters(e){if(!this.isValidPoint(e[0])||!this.isValidPoint(e[1])||!this.isValidPoint(e[2])||!this.isValidPoint(e[3]))throw new k;let t=2*this.nbCenterLayers,n=new Int32Array([this.sampleLine(e[0],e[1],t),this.sampleLine(e[1],e[2],t),this.sampleLine(e[2],e[3],t),this.sampleLine(e[3],e[0],t)]);this.shift=this.getRotation(n,t);let r=0;for(let e=0;e<4;e++){let t=n[(this.shift+e)%4];this.compact?(r<<=7,r+=t>>1&127):(r<<=10,r+=(t>>2&992)+(t>>1&31))}let i=this.getCorrectedParameterData(r,this.compact);this.compact?(this.nbLayers=(i>>6)+1,this.nbDataBlocks=(i&63)+1):(this.nbLayers=(i>>11)+1,this.nbDataBlocks=(i&2047)+1)}getRotation(e,t){let n=0;e.forEach((e,r,i)=>{let a=(e>>t-2<<1)+(e&1);n=(n<<3)+a}),n=((n&1)<<11)+(n>>1);for(let e=0;e<4;e++)if(_.bitCount(n^this.EXPECTED_CORNER_BITS[e])<=2)return e;throw new k}getCorrectedParameterData(e,t){let n,r;t?(n=7,r=2):(n=10,r=4);let i=n-r,a=new Int32Array(n);for(let t=n-1;t>=0;--t)a[t]=e&15,e>>=4;try{new ue(se.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 B(t.getX()+.5,t.getY()-.5),s=new B(n.getX()+.5,n.getY()+.5),c=new B(r.getX()-.5,r.getY()+.5),l=new B(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 _e(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 Se(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new Se(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new Se(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new Se(i-7,a-7),!1,-1,-1).toResultPoint()}let i=pe.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=pe.round((e.getY()+r.getY()+t.getY()+n.getY())/4);try{let o=new _e(this.image,15,i,a).detect();e=o[0],t=o[1],n=o[2],r=o[3]}catch{e=this.getFirstDifferent(new Se(i+7,a-7),!1,1,-1).toResultPoint(),t=this.getFirstDifferent(new Se(i+7,a+7),!1,1,1).toResultPoint(),n=this.getFirstDifferent(new Se(i-7,a+7),!1,-1,1).toResultPoint(),r=this.getFirstDifferent(new Se(i-7,a-7),!1,-1,-1).toResultPoint()}return i=pe.round((e.getX()+r.getX()+t.getX()+n.getX())/4),a=pe.round((e.getY()+r.getY()+t.getY()+n.getY())/4),new Se(i,a)}getMatrixCornerPoints(e){return this.expandSquare(e,2*this.nbCenterLayers,this.getDimension())}sampleGrid(e,t,n,r,i){let a=xe.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(pe.round(o+e*c),pe.round(s+e*l))&&(r|=1<<n-e-1);return r}isWhiteOrBlackRectangle(e,t,n,r){e=new Se(e.getX()-3,e.getY()+3),t=new Se(t.getX()-3,t.getY()-3),n=new Se(n.getX()+3,n.getY()-3),r=new Se(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(pe.round(o),pe.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 Se(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 B(o+r*i,s+r*a),l=new B(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 B(o+r*i,s+r*a),l,new B(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=pe.round(e.getX()),n=pe.round(e.getY());return this.isValid(t,n)}distancePoint(e,t){return pe.distance(e.getX(),e.getY(),t.getX(),t.getY())}distanceResultPoint(e,t){return pe.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 we{decode(e,t=null){let n=null,r=new Ce(e.getBlackMatrix()),i=null,a=null;try{let e=r.detectMirror(!1);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new fe().decode(e)}catch(e){n=e}if(a==null)try{let e=r.detectMirror(!0);i=e.getPoints(),this.reportFoundResultPoints(t,i),a=new fe().decode(e)}catch(e){throw n??e}let o=new R(a.getText(),a.getRawBytes(),a.getNumBits(),i,z.AZTEC,p.currentTimeMillis()),s=a.getByteSegments();s!=null&&o.putMetadata(ne.BYTE_SEGMENTS,s);let c=a.getECLevel();return c!=null&&o.putMetadata(ne.ERROR_CORRECTION_LEVEL,c),o}reportFoundResultPoints(e,t){if(e!=null){let n=e.get(b.NEED_RESULT_POINT_CALLBACK);n!=null&&t.forEach((e,t,r)=>{n.foundPossibleResultPoint(e)})}}reset(){}}class Te extends L{constructor(e=500){super(new we,e)}}class Ee{decode(e,t){try{return this.doDecode(e,t)}catch{if(t&&t.get(b.TRY_HARDER)===!0&&e.isRotateSupported()){let n=e.rotateCounterClockwise(),r=this.doDecode(n,t),i=r.getResultMetadata(),a=270;i!==null&&i.get(ne.ORIENTATION)===!0&&(a+=i.get(ne.ORIENTATION)%360),r.putMetadata(ne.ORIENTATION,a);let o=r.getResultPoints();if(o!==null){let e=n.getHeight();for(let t=0;t<o.length;t++)o[t]=new B(e-o[t].getY()-1,o[t].getX())}return r}else throw new k}}reset(){}doDecode(e,t){let n=e.getWidth(),r=e.getHeight(),i=new v(n),a=t&&t.get(b.TRY_HARDER)===!0,o=Math.max(1,r>>(a?8:5)),s;s=a?r:15;let c=Math.trunc(r/2);for(let a=0;a<s;a++){let s=Math.trunc((a+1)/2),l=c+o*(a&1?-s:s);if(l<0||l>=r)break;try{i=e.getBlackRow(l,i)}catch{continue}for(let e=0;e<2;e++){if(e===1&&(i.reverse(),t&&t.get(b.NEED_RESULT_POINT_CALLBACK)===!0)){let e=new Map;t.forEach((t,n)=>e.set(n,t)),e.delete(b.NEED_RESULT_POINT_CALLBACK),t=e}try{let r=this.decodeRow(l,i,t);if(e===1){r.putMetadata(ne.ORIENTATION,180);let e=r.getResultPoints();e!==null&&(e[0]=new B(n-e[0].getX()-1,e[0].getY()),e[1]=new B(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;Ee.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 V extends Ee{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=V.MAX_AVG_VARIANCE,n=-1;for(let e=V.CODE_START_A;e<=V.CODE_START_C;e++){let r=Ee.patternMatchVariance(i,V.CODE_PATTERNS[e],V.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){Ee.recordPattern(e,n,t);let r=V.MAX_AVG_VARIANCE,i=-1;for(let e=0;e<V.CODE_PATTERNS.length;e++){let n=V.CODE_PATTERNS[e],a=this.patternMatchVariance(t,n,V.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=V.findStartPattern(t),a=i[2],o=0,s=new Uint8Array(20);s[o++]=a;let c;switch(a){case V.CODE_START_A:c=V.CODE_CODE_A;break;case V.CODE_START_B:c=V.CODE_CODE_B;break;case V.CODE_START_C:c=V.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=_,_=V.decodeCode(t,h,m),s[o++]=_,_!==V.CODE_STOP&&(S=!0),_!==V.CODE_STOP&&(y++,v+=y*_),p=m,m+=h.reduce((e,t)=>e+t,0),_){case V.CODE_START_A:case V.CODE_START_B:case V.CODE_START_C:throw new x}switch(c){case V.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(_!==V.CODE_STOP&&(S=!1),_){case V.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case V.CODE_FNC_2:case V.CODE_FNC_3:break;case V.CODE_FNC_4_A:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case V.CODE_SHIFT:u=!0,c=V.CODE_CODE_B;break;case V.CODE_CODE_B:c=V.CODE_CODE_B;break;case V.CODE_CODE_C:c=V.CODE_CODE_C;break;case V.CODE_STOP:l=!0;break}break;case V.CODE_CODE_B:if(_<96)w===C?f+=String.fromCharCode(32+_):f+=String.fromCharCode(32+_+128),w=!1;else switch(_!==V.CODE_STOP&&(S=!1),_){case V.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case V.CODE_FNC_2:case V.CODE_FNC_3:break;case V.CODE_FNC_4_B:!C&&w?(C=!0,w=!1):C&&w?(C=!1,w=!1):w=!0;break;case V.CODE_SHIFT:u=!0,c=V.CODE_CODE_A;break;case V.CODE_CODE_A:c=V.CODE_CODE_A;break;case V.CODE_CODE_C:c=V.CODE_CODE_C;break;case V.CODE_STOP:l=!0;break}break;case V.CODE_CODE_C:if(_<100)_<10&&(f+=`0`),f+=_;else switch(_!==V.CODE_STOP&&(S=!1),_){case V.CODE_FNC_1:r&&(f.length===0?f+=`]C1`:f+=``);break;case V.CODE_CODE_A:c=V.CODE_CODE_A;break;case V.CODE_CODE_B:c=V.CODE_CODE_B;break;case V.CODE_STOP:l=!0;break}break}e&&(c=c===V.CODE_CODE_A?V.CODE_CODE_B:V.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===V.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 B(D,e),new B(O,e)];return new R(f,j,0,M,z.CODE_128,new Date().getTime())}}V.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])],V.MAX_AVG_VARIANCE=.25,V.MAX_INDIVIDUAL_VARIANCE=.7,V.CODE_SHIFT=98,V.CODE_CODE_C=99,V.CODE_CODE_B=100,V.CODE_CODE_A=101,V.CODE_FNC_1=102,V.CODE_FNC_2=97,V.CODE_FNC_3=96,V.CODE_FNC_4_A=101,V.CODE_FNC_4_B=100,V.CODE_START_A=103,V.CODE_START_B=104,V.CODE_START_C=105,V.CODE_STOP=106;class De extends Ee{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=De.findAsteriskPattern(t,r),a=t.getNextSet(i[1]),o=t.getSize(),s,c;do{De.recordPattern(t,a,r);let e=De.toNarrowWidePattern(r);if(e<0)throw new k;s=De.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+=De.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(n));if(this.decodeRowResult.charAt(e)!==De.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?De.decodeExtended(this.decodeRowResult):this.decodeRowResult;let p=(i[1]+i[0])/2,m=c+l/2;return new R(f,null,0,[new B(p,e),new B(m,e)],z.CODE_39,new Date().getTime())}static findAsteriskPattern(e,t){let n=e.getSize(),r=e.getNextSet(0),i=0,a=r,o=!1,s=t.length;for(let c=r;c<n;c++)if(e.get(c)!==o)t[i]++;else{if(i===s-1){if(this.toNarrowWidePattern(t)===De.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<De.CHARACTER_ENCODINGS.length;t++)if(De.CHARACTER_ENCODINGS[t]===e)return De.ALPHABET_STRING.charAt(t);if(e===De.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}}De.ALPHABET_STRING=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%`,De.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],De.ASTERISK_ENCODING=148;class Oe extends Ee{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,t,n){let r=this.decodeStart(t),i=this.decodeEnd(t),a=new D;Oe.decodeMiddle(t,r[1],i[0],a);let o=a.toString(),s=null;n!=null&&(s=n.get(b.ALLOWED_LENGTHS)),s??=Oe.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 B(r[1],e),new B(i[0],e)],z.ITF,new Date().getTime())}static decodeMiddle(e,t,n,r){let i=new Int32Array(10),a=new Int32Array(5),o=new Int32Array(5);for(i.fill(0),a.fill(0),o.fill(0);t<n;){Ee.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=Oe.decodeDigit(a);r.append(n.toString()),n=this.decodeDigit(o),r.append(n.toString()),i.forEach(function(e){t+=e})}}decodeStart(e){let t=Oe.skipWhiteSpace(e),n=Oe.findGuardPattern(e,t,Oe.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=Oe.skipWhiteSpace(e),n;try{n=Oe.findGuardPattern(e,t,Oe.END_PATTERN_REVERSED[0])}catch(r){r instanceof k&&(n=Oe.findGuardPattern(e,t,Oe.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(Ee.patternMatchVariance(i,n,Oe.MAX_INDIVIDUAL_VARIANCE)<Oe.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=Oe.MAX_AVG_VARIANCE,n=-1,r=Oe.PATTERNS.length;for(let i=0;i<r;i++){let r=Oe.PATTERNS[i],a=Ee.patternMatchVariance(e,r,Oe.MAX_INDIVIDUAL_VARIANCE);a<t?(t=a,n=i):a===t&&(n=-1)}if(n>=0)return n%10;throw new k}}Oe.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])],Oe.MAX_AVG_VARIANCE=.38,Oe.MAX_INDIVIDUAL_VARIANCE=.5,Oe.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],Oe.START_PATTERN=Int32Array.from([1,1,1,1]),Oe.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class ke extends Ee{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=ke.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 ke.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return ke.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 ke.findGuardPattern(e,t,!1,ke.START_END_PATTERN,new Int32Array(ke.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(Ee.patternMatchVariance(i,r,ke.MAX_INDIVIDUAL_VARIANCE)<ke.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=Ee.patternMatchVariance(t,n,ke.MAX_INDIVIDUAL_VARIANCE);o<i&&(i=o,a=e)}if(a>=0)return a;throw new k}}ke.MAX_AVG_VARIANCE=.48,ke.MAX_INDIVIDUAL_VARIANCE=.7,ke.START_END_PATTERN=Int32Array.from([1,1,1]),ke.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),ke.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),ke.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 Ae{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=Ae.parseExtensionString(a),s=new R(a,null,0,[new B((n[0]+n[1])/2,e),new B(i,e)],z.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<5&&a<i;t++){let i=ke.decodeDigit(e,r,a,ke.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(Ae.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=Ae.parseExtension5String(e);return t==null?null:new Map([[ne.SUGGESTED_PRICE,t]])}static parseExtension5String(e){let t;switch(e.charAt(0)){case`0`:t=`£`;break;case`5`:t=`$`;break;case`9`:switch(e){case`90000`:return null;case`99991`:return`0.00`;case`99990`:return`Used`}t=``;break;default:t=``;break}let n=parseInt(e.substring(1)),r=(n/100).toString(),i=n%100,a=i<10?`0`+i:i.toString();return t+r+`.`+a}}class je{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=je.parseExtensionString(a),s=new R(a,null,0,[new B((n[0]+n[1])/2,e),new B(i,e)],z.UPC_EAN_EXTENSION,new Date().getTime());return o!=null&&s.putAllMetadata(o),s}decodeMiddle(e,t,n){let r=this.decodeMiddleCounters;r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a=t[1],o=0;for(let t=0;t<2&&a<i;t++){let i=ke.decodeDigit(e,r,a,ke.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<1-t),t!==1&&(a=e.getNextSet(a),a=e.getNextUnset(a))}if(n.length!==2||parseInt(n.toString())%4!==o)throw new k;return a}static parseExtensionString(e){return e.length===2?new Map([[ne.ISSUE_NUMBER,parseInt(e)]]):null}}class Me{static decodeRow(e,t,n){let r=ke.findGuardPattern(t,n,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new Ae().decodeRow(e,t,r)}catch{return new je().decodeRow(e,t,r)}}}Me.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class Ne extends ke{constructor(){super(),this.decodeRowStringBuffer=``,Ne.L_AND_G_PATTERNS=Ne.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let t=Ne.L_PATTERNS[e-10],n=new Int32Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[t.length-e-1];Ne.L_AND_G_PATTERNS[e]=n}}decodeRow(e,t,n){let r=Ne.findStartGuardPattern(t),i=n==null?null:n.get(b.NEED_RESULT_POINT_CALLBACK);if(i!=null){let t=new B((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 B(o,e);i.foundPossibleResultPoint(t)}let c=this.decodeEnd(t,o);if(i!=null){let t=new B((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(!Ne.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 B(p,e),new B(m,e)],h,new Date().getTime()),_=0;try{let n=Me.decodeRow(e,t,c[1]);g.putMetadata(ne.UPC_EAN_EXTENSION,n.getText()),g.putAllMetadata(n.getResultMetadata()),g.addResultPoints(n.getResultPoints()),_=n.getText().length}catch{}let v=n==null?null:n.get(b.ALLOWED_EAN_EXTENSIONS);if(v!=null){let e=!1;for(let t in v)if(_.toString()===t){e=!0;break}if(!e)throw new k}return g}decodeEnd(e,t){return Ne.findGuardPattern(e,t,!1,Ne.START_END_PATTERN,new Int32Array(Ne.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return Ne.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let t=e.length;if(t===0)return!1;let n=parseInt(e.charAt(t-1),10);return Ne.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 Pe extends Ne{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=Ne.decodeDigit(e,r,a,Ne.L_AND_G_PATTERNS);n+=String.fromCharCode(48+i%10);for(let e of r)a+=e;i>=10&&(o|=1<<5-t)}n=Pe.determineFirstDigit(n,o),a=Ne.findGuardPattern(e,a,!0,Ne.MIDDLE_PATTERN,new Int32Array(Ne.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<6&&a<i;t++){let t=Ne.decodeDigit(e,r,a,Ne.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return z.EAN_13}static determineFirstDigit(e,t){for(let n=0;n<10;n++)if(t===this.FIRST_DIGIT_ENCODINGS[n])return e=String.fromCharCode(48+n)+e,e;throw new k}}Pe.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class Fe extends Ne{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=Ne.decodeDigit(e,r,a,Ne.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}a=Ne.findGuardPattern(e,a,!0,Ne.MIDDLE_PATTERN,new Int32Array(Ne.MIDDLE_PATTERN.length).fill(0))[1];for(let t=0;t<4&&a<i;t++){let t=Ne.decodeDigit(e,r,a,Ne.L_PATTERNS);n+=String.fromCharCode(48+t);for(let e of r)a+=e}return{rowOffset:a,resultString:n}}getBarcodeFormat(){return z.EAN_8}}class Ie extends Ne{constructor(){super(...arguments),this.ean13Reader=new Pe}getBarcodeFormat(){return z.UPC_A}decode(e,t){return this.maybeReturnResult(this.ean13Reader.decode(e))}decodeRow(e,t,n){return this.maybeReturnResult(this.ean13Reader.decodeRow(e,t,n))}decodeMiddle(e,t,n){return this.ean13Reader.decodeMiddle(e,t,n)}maybeReturnResult(e){let t=e.getText();if(t.charAt(0)===`0`){let n=new R(t.substring(1),null,null,e.getResultPoints(),z.UPC_A);return e.getResultMetadata()!=null&&n.putAllMetadata(e.getResultMetadata()),n}else throw new k}reset(){this.ean13Reader.reset()}}class Le extends Ne{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=Le.decodeDigit(e,r,a,Le.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=Le.determineNumSysAndCheckDigit(n,o);return{rowOffset:a,resultString:s}}decodeEnd(e,t){return Le.findGuardPatternWithoutCounters(e,t,!0,Le.MIDDLE_END_PATTERN)}checkChecksum(e){return Ne.checkChecksum(Le.convertUPCEtoUPCA(e))}static determineNumSysAndCheckDigit(e,t){for(let n=0;n<=1;n++)for(let r=0;r<10;r++)if(t===this.NUMSYS_AND_CHECK_DIGIT_PATTERNS[n][r]){let t=String.fromCharCode(48+n),i=String.fromCharCode(48+r);return t+e+i}throw k.getNotFoundInstance()}getBarcodeFormat(){return z.UPC_E}static convertUPCEtoUPCA(e){let t=e.slice(1,7).split(``).map(e=>e.charCodeAt(0)),n=new D;n.append(e.charAt(0));let r=t[5];switch(r){case 0:case 1:case 2:n.appendChars(t,0,2),n.append(r),n.append(`0000`),n.appendChars(t,2,3);break;case 3:n.appendChars(t,0,3),n.append(`00000`),n.appendChars(t,3,2);break;case 4:n.appendChars(t,0,4),n.append(`00000`),n.append(t[4]);break;default:n.appendChars(t,0,5),n.append(`0000`),n.append(r);break}return e.length>=8&&n.append(e.charAt(7)),n.toString()}}Le.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),Le.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 Re extends Ee{constructor(e){super();let n=e==null?null:e.get(b.POSSIBLE_FORMATS),r=[];t(n)?(r.push(new Pe),r.push(new Ie),r.push(new Fe),r.push(new Le)):(n.indexOf(z.EAN_13)>-1&&r.push(new Pe),n.indexOf(z.UPC_A)>-1&&r.push(new Ie),n.indexOf(z.EAN_8)>-1&&r.push(new Fe),n.indexOf(z.UPC_E)>-1&&r.push(new Le)),this.readers=r}decodeRow(e,t,n){for(let r of this.readers)try{let i=r.decodeRow(e,t,n),a=i.getBarcodeFormat()===z.EAN_13&&i.getText().charAt(0)===`0`,o=n==null?null:n.get(b.POSSIBLE_FORMATS),s=o==null||o.includes(z.UPC_A);if(a&&s){let e=i.getRawBytes(),t=new R(i.getText().substring(1),e,e?e.length:null,i.getResultPoints(),z.UPC_A);return t.putAllMetadata(i.getResultMetadata()),t}return i}catch{}throw new k}reset(){for(let e of this.readers)e.reset()}}class ze extends Ee{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(Ee.patternMatchVariance(e,t[n],ze.MAX_INDIVIDUAL_VARIANCE)<ze.MAX_AVG_VARIANCE)return n;throw new k}static count(e){return pe.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>=ze.MIN_FINDER_PATTERN_RATIO&&n<=ze.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}}ze.MAX_AVG_VARIANCE=.2,ze.MAX_INDIVIDUAL_VARIANCE=.45,ze.MIN_FINDER_PATTERN_RATIO=9.5/12,ze.MAX_FINDER_PATTERN_RATIO=12.5/14;class Be{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 Be))return!1;let t=e;return this.value===t.value&&this.checksumPortion===t.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class Ve{constructor(e,t,n,r,i){this.value=e,this.startEnd=t,this.value=e,this.startEnd=t,this.resultPoints=[],this.resultPoints.push(new B(n,i)),this.resultPoints.push(new B(r,i))}getValue(){return this.value}getStartEnd(){return this.startEnd}getResultPoints(){return this.resultPoints}equals(e){if(!(e instanceof Ve))return!1;let t=e;return this.value===t.value}hashCode(){return this.value}}class He{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=He.combins(r-c-1,o-s-2);if(n&&a===0&&r-c-(o-s-1)>=o-s-1&&(e-=He.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+=He.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 Ue{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 We{constructor(e,t){t?this.decodedInformation=null:(this.finished=e,this.decodedInformation=t)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class Ge{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class Ke extends Ge{constructor(e,t){super(e),this.value=t}getValue(){return this.value}isFNC1(){return this.value===Ke.FNC1}}Ke.FNC1=`$`;class qe extends Ge{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 Je extends Ge{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===Je.FNC1}isSecondDigitFNC1(){return this.secondDigit===Je.FNC1}isAnyFNC1(){return this.firstDigit===Je.FNC1||this.secondDigit===Je.FNC1}}Je.FNC1=10;class Ye{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 Ye.TWO_DIGIT_DATA_LENGTH)if(n[0]===t)return n[1]===Ye.VARIABLE_LENGTH?Ye.processVariableAI(2,n[2],e):Ye.processFixedAI(2,n[1],e);if(e.length<3)throw new k;let n=e.substring(0,3);for(let t of Ye.THREE_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Ye.VARIABLE_LENGTH?Ye.processVariableAI(3,t[2],e):Ye.processFixedAI(3,t[1],e);for(let t of Ye.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(t[0]===n)return t[1]===Ye.VARIABLE_LENGTH?Ye.processVariableAI(4,t[2],e):Ye.processFixedAI(4,t[1],e);if(e.length<4)throw new k;let r=e.substring(0,4);for(let t of Ye.FOUR_DIGIT_DATA_LENGTH)if(t[0]===r)return t[1]===Ye.VARIABLE_LENGTH?Ye.processVariableAI(4,t[2],e):Ye.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=Ye.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=Ye.parseFieldsInGeneralPurpose(o);return c==null?s:s+c}}Ye.VARIABLE_LENGTH=[],Ye.TWO_DIGIT_DATA_LENGTH=[[`00`,18],[`01`,14],[`02`,14],[`10`,Ye.VARIABLE_LENGTH,20],[`11`,6],[`12`,6],[`13`,6],[`15`,6],[`17`,6],[`20`,2],[`21`,Ye.VARIABLE_LENGTH,20],[`22`,Ye.VARIABLE_LENGTH,29],[`30`,Ye.VARIABLE_LENGTH,8],[`37`,Ye.VARIABLE_LENGTH,8],[`90`,Ye.VARIABLE_LENGTH,30],[`91`,Ye.VARIABLE_LENGTH,30],[`92`,Ye.VARIABLE_LENGTH,30],[`93`,Ye.VARIABLE_LENGTH,30],[`94`,Ye.VARIABLE_LENGTH,30],[`95`,Ye.VARIABLE_LENGTH,30],[`96`,Ye.VARIABLE_LENGTH,30],[`97`,Ye.VARIABLE_LENGTH,3],[`98`,Ye.VARIABLE_LENGTH,30],[`99`,Ye.VARIABLE_LENGTH,30]],Ye.THREE_DIGIT_DATA_LENGTH=[[`240`,Ye.VARIABLE_LENGTH,30],[`241`,Ye.VARIABLE_LENGTH,30],[`242`,Ye.VARIABLE_LENGTH,6],[`250`,Ye.VARIABLE_LENGTH,30],[`251`,Ye.VARIABLE_LENGTH,30],[`253`,Ye.VARIABLE_LENGTH,17],[`254`,Ye.VARIABLE_LENGTH,20],[`400`,Ye.VARIABLE_LENGTH,30],[`401`,Ye.VARIABLE_LENGTH,30],[`402`,17],[`403`,Ye.VARIABLE_LENGTH,30],[`410`,13],[`411`,13],[`412`,13],[`413`,13],[`414`,13],[`420`,Ye.VARIABLE_LENGTH,20],[`421`,Ye.VARIABLE_LENGTH,15],[`422`,3],[`423`,Ye.VARIABLE_LENGTH,15],[`424`,3],[`425`,3],[`426`,3]],Ye.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`,Ye.VARIABLE_LENGTH,15],[`391`,Ye.VARIABLE_LENGTH,18],[`392`,Ye.VARIABLE_LENGTH,15],[`393`,Ye.VARIABLE_LENGTH,18],[`703`,Ye.VARIABLE_LENGTH,30]],Ye.FOUR_DIGIT_DATA_LENGTH=[[`7001`,13],[`7002`,Ye.VARIABLE_LENGTH,30],[`7003`,10],[`8001`,14],[`8002`,Ye.VARIABLE_LENGTH,20],[`8003`,Ye.VARIABLE_LENGTH,30],[`8004`,Ye.VARIABLE_LENGTH,30],[`8005`,6],[`8006`,18],[`8007`,Ye.VARIABLE_LENGTH,30],[`8008`,Ye.VARIABLE_LENGTH,12],[`8018`,18],[`8020`,Ye.VARIABLE_LENGTH,25],[`8100`,6],[`8101`,10],[`8102`,2],[`8110`,Ye.VARIABLE_LENGTH,70],[`8200`,Ye.VARIABLE_LENGTH,70]];class Xe{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=Ye.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 Je(this.information.getSize(),Je.FNC1,Je.FNC1):new Je(this.information.getSize(),t-1,Je.FNC1)}let t=this.extractNumericValueFromBitArray(e,7),n=(t-8)/11,r=(t-8)%11;return new Je(e+7,n,r)}extractNumericValueFromBitArray(e,t){return Xe.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 qe(this.current.getPosition(),this.buffer.toString(),n.getRemainingValue()):new qe(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 qe(this.current.getPosition(),this.buffer.toString()):new qe(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new We(!0,t)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1())return new We(!0,new qe(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 We(!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 We(!0,new qe(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 We(!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 We(!0,new qe(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 We(!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 Ke(e+5,Ke.FNC1);if(t>=5&&t<15)return new Ke(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,7);if(n>=64&&n<90)return new Ke(e+7,``+(n+1));if(n>=90&&n<116)return new Ke(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 Ke(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 Ke(e+5,Ke.FNC1);if(t>=5&&t<15)return new Ke(e+5,`0`+(t-5));let n=this.extractNumericValueFromBitArray(e,6);if(n>=32&&n<58)return new Ke(e+6,``+(n+33));let r;switch(n){case 58:r=`*`;break;case 59:r=`,`;break;case 60:r=`-`;break;case 61:r=`.`;break;case 62:r=`/`;break;default:throw new le(`Decoding invalid alphanumeric value: `+n)}return new Ke(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 Ze{constructor(e){this.information=e,this.generalDecoder=new Xe(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class Qe extends Ze{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)}Qe.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)}}Qe.GTIN_SIZE=40;class $e extends Qe{constructor(e){super(e)}parseInformation(){let e=new D;e.append(`(01)`);let t=e.length(),n=this.getGeneralDecoder().extractNumericValueFromBitArray($e.HEADER_SIZE,4);return e.append(n),this.encodeCompressedGtinWithoutAI(e,$e.HEADER_SIZE+4,t),this.getGeneralDecoder().decodeAllCodes(e,$e.HEADER_SIZE+44)}}$e.HEADER_SIZE=4;class et extends Ze{constructor(e){super(e)}parseInformation(){let e=new D;return this.getGeneralDecoder().decodeAllCodes(e,et.HEADER_SIZE)}}et.HEADER_SIZE=5;class tt extends Qe{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 nt extends tt{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=nt.HEADER_SIZE+tt.GTIN_SIZE+nt.WEIGHT_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,nt.HEADER_SIZE),this.encodeCompressedWeight(e,nt.HEADER_SIZE+tt.GTIN_SIZE,nt.WEIGHT_SIZE),e.toString()}}nt.HEADER_SIZE=5,nt.WEIGHT_SIZE=15;class rt extends nt{constructor(e){super(e)}addWeightCode(e,t){e.append(`(3103)`)}checkWeight(e){return e}}class it extends nt{constructor(e){super(e)}addWeightCode(e,t){t<1e4?e.append(`(3202)`):e.append(`(3203)`)}checkWeight(e){return e<1e4?e:e-1e4}}class at extends Qe{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<at.HEADER_SIZE+Qe.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,at.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(at.HEADER_SIZE+Qe.GTIN_SIZE,at.LAST_DIGIT_SIZE);e.append(`(392`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().decodeGeneralPurposeField(at.HEADER_SIZE+Qe.GTIN_SIZE+at.LAST_DIGIT_SIZE,null);return e.append(n.getNewString()),e.toString()}}at.HEADER_SIZE=8,at.LAST_DIGIT_SIZE=2;class ot extends Qe{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<ot.HEADER_SIZE+Qe.GTIN_SIZE)throw new k;let e=new D;this.encodeCompressedGtin(e,ot.HEADER_SIZE);let t=this.getGeneralDecoder().extractNumericValueFromBitArray(ot.HEADER_SIZE+Qe.GTIN_SIZE,ot.LAST_DIGIT_SIZE);e.append(`(393`),e.append(t),e.append(`)`);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(ot.HEADER_SIZE+Qe.GTIN_SIZE+ot.LAST_DIGIT_SIZE,ot.FIRST_THREE_DIGITS_SIZE);n/100==0&&e.append(`0`),n/10==0&&e.append(`0`),e.append(n);let r=this.getGeneralDecoder().decodeGeneralPurposeField(ot.HEADER_SIZE+Qe.GTIN_SIZE+ot.LAST_DIGIT_SIZE+ot.FIRST_THREE_DIGITS_SIZE,null);return e.append(r.getNewString()),e.toString()}}ot.HEADER_SIZE=8,ot.LAST_DIGIT_SIZE=2,ot.FIRST_THREE_DIGITS_SIZE=10;class H extends tt{constructor(e,t,n){super(e),this.dateCode=n,this.firstAIdigits=t}parseInformation(){if(this.getInformation().getSize()!=H.HEADER_SIZE+H.GTIN_SIZE+H.WEIGHT_SIZE+H.DATE_SIZE)throw new k;let e=new D;return this.encodeCompressedGtin(e,H.HEADER_SIZE),this.encodeCompressedWeight(e,H.HEADER_SIZE+H.GTIN_SIZE,H.WEIGHT_SIZE),this.encodeCompressedDate(e,H.HEADER_SIZE+H.GTIN_SIZE+H.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,t){let n=this.getGeneralDecoder().extractNumericValueFromBitArray(t,H.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}}H.HEADER_SIZE=8,H.WEIGHT_SIZE=20,H.DATE_SIZE=16;function st(e){try{if(e.get(1))return new $e(e);if(!e.get(2))return new et(e);switch(Xe.extractNumericValueFromBitArray(e,1,4)){case 4:return new rt(e);case 5:return new it(e)}switch(Xe.extractNumericValueFromBitArray(e,1,5)){case 12:return new at(e);case 13:return new ot(e)}switch(Xe.extractNumericValueFromBitArray(e,1,7)){case 56:return new H(e,`310`,`11`);case 57:return new H(e,`320`,`11`);case 58:return new H(e,`310`,`13`);case 59:return new H(e,`320`,`13`);case 60:return new H(e,`310`,`15`);case 61:return new H(e,`320`,`15`);case 62:return new H(e,`310`,`17`);case 63:return new H(e,`320`,`17`)}}catch(t){throw console.log(t),new le(`unknown decoder: `+e)}}class ct{constructor(e,t,n,r){this.leftchar=e,this.rightchar=t,this.finderpattern=n,this.maybeLast=r}mayBeLast(){return this.maybeLast}getLeftChar(){return this.leftchar}getRightChar(){return this.rightchar}getFinderPattern(){return this.finderpattern}mustBeLast(){return this.rightchar==null}toString(){return`[ `+this.leftchar+`, `+this.rightchar+` : `+(this.finderpattern==null?`null`:this.finderpattern.getValue())+` ]`}static equals(e,t){return e instanceof ct?ct.equalsOrNull(e.leftchar,t.leftchar)&&ct.equalsOrNull(e.rightchar,t.rightchar)&&ct.equalsOrNull(e.finderpattern,t.finderpattern):!1}static equalsOrNull(e,t){return e===null?t===null:ct.equals(e,t)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class lt{constructor(e,t,n){this.pairs=e,this.rowNumber=t,this.wasReversed=n}getPairs(){return this.pairs}getRowNumber(){return this.rowNumber}isReversed(){return this.wasReversed}isEquivalent(e){return this.checkEqualitity(this,e)}toString(){return`{ `+this.pairs+` }`}equals(e,t){return e instanceof lt?this.checkEqualitity(e,t)&&e.wasReversed===t.wasReversed:!1}checkEqualitity(e,t){if(!e||!t)return;let n;return e.forEach((e,r)=>{t.forEach(t=>{e.getLeftChar().getValue()===t.getLeftChar().getValue()&&e.getRightChar().getValue()===t.getRightChar().getValue()&&e.getFinderPatter().getValue()===t.getFinderPatter().getValue()&&(n=!0)})}),n}}class U extends ze{constructor(e){super(...arguments),this.pairs=Array(U.MAX_PAIRS),this.rows=[],this.startEnd=[2],this.verbose=e===!0}decodeRow(e,t,n){this.pairs.length=0,this.startFromEven=!1;try{return U.constructResult(this.decodeRow2pairs(e,t))}catch(e){this.verbose&&console.log(e)}return this.pairs.length=0,this.startFromEven=!0,U.constructResult(this.decodeRow2pairs(e,t))}reset(){this.pairs.length=0,this.rows.length=0}decodeRow2pairs(e,t){let n=!1;for(;!n;)try{this.pairs.push(this.retrieveNextPair(t,this.pairs,e))}catch(e){if(e instanceof k){if(!this.pairs.length)throw new k;n=!0}}if(this.checkChecksum())return this.pairs;let r;if(r=!!this.rows.length,this.storeRow(e,!1),r){let e=this.checkRowsBoolean(!1);if(e!=null||(e=this.checkRowsBoolean(!0),e!=null))return e}throw new k}checkRowsBoolean(e){if(this.rows.length>25)return this.rows.length=0,null;this.pairs.length=0,e&&(this.rows=this.rows.reverse());let t=null;try{t=this.checkRows([],0)}catch(e){this.verbose&&console.log(e)}return e&&(this.rows=this.rows.reverse()),t}checkRows(e,t){for(let n=t;n<this.rows.length;n++){let t=this.rows[n];this.pairs.length=0;for(let t of e)this.pairs.push(t.getPairs());if(this.pairs.push(t.getPairs()),!U.isValidSequence(this.pairs))continue;if(this.checkChecksum())return this.pairs;let r=Array(e);r.push(t);try{return this.checkRows(r,n+1)}catch(e){this.verbose&&console.log(e)}}throw new k}static isValidSequence(e){for(let t of U.FINDER_PATTERN_SEQUENCES){if(e.length>t.length)continue;let n=!0;for(let r=0;r<e.length;r++)if(e[r].getFinderPattern().getValue()!=t[r]){n=!1;break}if(n)return!0}return!1}storeRow(e,t){let n=0,r=!1,i=!1;for(;n<this.rows.length;){let t=this.rows[n];if(t.getRowNumber()>e){i=t.isEquivalent(this.pairs);break}r=t.isEquivalent(this.pairs),n++}i||r||U.isPartialRow(this.pairs,this.rows)||(this.rows.push(n,new lt(this.pairs,e,t)),this.removePartialRows(this.pairs,this.rows))}removePartialRows(e,t){for(let n of t)if(n.getPairs().length!==e.length){for(let t of n.getPairs())for(let n of e)if(ct.equals(t,n))break}}static isPartialRow(e,t){for(let n of t){let t=!0;for(let r of e){let e=!1;for(let t of n.getPairs())if(r.equals(t)){e=!0;break}if(!e){t=!1;break}}if(t)return!0}return!1}getRows(){return this.rows}static constructResult(e){let t=st(Ue.buildBitArray(e)).parseInformation(),n=e[0].getFinderPattern().getResultPoints(),r=e[e.length-1].getFinderPattern().getResultPoints();return new R(t,null,null,[n[0],n[1],r[0],r[1]],z.RSS_EXPANDED,null)}checkChecksum(){let e=this.pairs.get(0),t=e.getLeftChar(),n=e.getRightChar();if(n==null)return!1;let r=n.getChecksumPortion(),i=2;for(let e=1;e<this.pairs.size();++e){let t=this.pairs.get(e);r+=t.getLeftChar().getChecksumPortion(),i++;let n=t.getRightChar();n!=null&&(r+=n.getChecksumPortion(),i++)}return r%=211,211*(i-4)+r==t.getValue()}static getNextSecondBar(e,t){let n;return e.get(t)?(n=e.getNextUnset(t),n=e.getNextSet(n)):(n=e.getNextSet(t),n=e.getNextUnset(n)),n}retrieveNextPair(e,t,n){let r=t.length%2==0;this.startFromEven&&(r=!r);let i,a=!0,o=-1;do this.findNextPair(e,t,o),i=this.parseFoundFinderPattern(e,n,r),i==null?o=U.getNextSecondBar(e,this.startEnd[0]):a=!1;while(a);let s=this.decodeDataCharacter(e,i,r,!0);if(!this.isEmptyPair(t)&&t[t.length-1].mustBeLast())throw new k;let c;try{c=this.decodeDataCharacter(e,i,r,!1)}catch(e){c=null,this.verbose&&console.log(e)}return new ct(s,c,i,!0)}isEmptyPair(e){return e.length===0}findNextPair(e,t,n){let r=this.getDecodeFinderCounters();r[0]=0,r[1]=0,r[2]=0,r[3]=0;let i=e.getSize(),a;a=n>=0?n:this.isEmptyPair(t)?0:t[t.length-1].getFinderPattern().getStartEnd()[1];let o=t.length%2!=0;this.startFromEven&&(o=!o);let s=!1;for(;a<i&&(s=!e.get(a),s);)a++;let c=0,l=a;for(let t=a;t<i;t++)if(e.get(t)!=s)r[c]++;else{if(c==3){if(o&&U.reverseCounters(r),U.isFinderPattern(r)){this.startEnd[0]=l,this.startEnd[1]=t;return}o&&U.reverseCounters(r),l+=r[0]+r[1],r[0]=r[2],r[1]=r[3],r[2]=0,r[3]=0,c--}else c++;r[c]=1,s=!s}throw new k}static reverseCounters(e){let t=e.length;for(let n=0;n<t/2;++n){let r=e[n];e[n]=e[t-n-1],e[t-n-1]=r}}parseFoundFinderPattern(e,t,n){let r,i,a;if(n){let t=this.startEnd[0]-1;for(;t>=0&&!e.get(t);)t--;t++,r=this.startEnd[0]-t,i=t,a=this.startEnd[1]}else i=this.startEnd[0],a=e.getNextUnset(this.startEnd[1]+1),r=a-this.startEnd[1];let o=this.getDecodeFinderCounters();p.arraycopy(o,0,o,1,o.length-1),o[0]=r;let s;try{s=this.parseFinderValue(o,U.FINDER_PATTERNS)}catch{return null}return new Ve(s,[i,a],i,a,t)}decodeDataCharacter(e,t,n,r){let i=this.getDataCharacterCounters();for(let e=0;e<i.length;e++)i[e]=0;if(r)U.recordPatternInReverse(e,t.getStartEnd()[0],i);else{U.recordPattern(e,t.getStartEnd()[1],i);for(let e=0,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}let a=pe.sum(new Int32Array(i))/17,o=(t.getStartEnd()[1]-t.getStartEnd()[0])/15;if(Math.abs(a-o)/o>.3)throw new k;let s=this.getOddCounts(),c=this.getEvenCounts(),l=this.getOddRoundingErrors(),u=this.getEvenRoundingErrors();for(let e=0;e<i.length;e++){let t=1*i[e]/a,n=t+.5;if(n<1){if(t<.3)throw new k;n=1}else if(n>8){if(t>8.7)throw new k;n=8}let r=e/2;e&1?(c[r]=n,u[r]=t-n):(s[r]=n,l[r]=t-n)}this.adjustOddEvenCounts(17);let d=4*t.getValue()+(n?0:2)+ +!r-1,f=0,p=0;for(let e=s.length-1;e>=0;e--){if(U.isNotA1left(t,n,r)){let t=U.WEIGHTS[d][2*e];p+=s[e]*t}f+=s[e]}let m=0;for(let e=c.length-1;e>=0;e--)if(U.isNotA1left(t,n,r)){let t=U.WEIGHTS[d][2*e+1];m+=c[e]*t}let h=p+m;if(f&1||f>13||f<4)throw new k;let g=(13-f)/2,_=U.SYMBOL_WIDEST[g],v=9-_,y=He.getRSSvalue(s,_,!0),b=He.getRSSvalue(c,v,!1),x=U.EVEN_TOTAL_SUBSET[g],S=U.GSUM[g];return new Be(y*x+b+S,h)}static isNotA1left(e,t,n){return!(e.getValue()==0&&t&&n)}adjustOddEvenCounts(e){let t=pe.sum(new Int32Array(this.getOddCounts())),n=pe.sum(new Int32Array(this.getEvenCounts())),r=!1,i=!1;t>13?i=!0:t<4&&(r=!0);let a=!1,o=!1;n>13?o=!0:n<4&&(a=!0);let s=t+n-e,c=(t&1)==1,l=(n&1)==0;if(s==1)if(c){if(l)throw new k;i=!0}else{if(!l)throw new k;o=!0}else if(s==-1)if(c){if(l)throw new k;r=!0}else{if(!l)throw new k;a=!0}else if(s==0){if(c){if(!l)throw new k;t<n?(r=!0,o=!0):(i=!0,a=!0)}else if(l)throw new k}else throw new k;if(r){if(i)throw new k;U.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(i&&U.decrement(this.getOddCounts(),this.getOddRoundingErrors()),a){if(o)throw new k;U.increment(this.getEvenCounts(),this.getOddRoundingErrors())}o&&U.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}U.SYMBOL_WIDEST=[7,5,4,3,1],U.EVEN_TOTAL_SUBSET=[4,20,52,104,204],U.GSUM=[0,348,1388,2948,3988],U.FINDER_PATTERNS=[Int32Array.from([1,8,4,1]),Int32Array.from([3,6,4,1]),Int32Array.from([3,4,6,1]),Int32Array.from([3,2,8,1]),Int32Array.from([2,6,5,1]),Int32Array.from([2,2,9,1])],U.WEIGHTS=[[1,3,9,27,81,32,96,77],[20,60,180,118,143,7,21,63],[189,145,13,39,117,140,209,205],[193,157,49,147,19,57,171,91],[62,186,136,197,169,85,44,132],[185,133,188,142,4,12,36,108],[113,128,173,97,80,29,87,50],[150,28,84,41,123,158,52,156],[46,138,203,187,139,206,196,166],[76,17,51,153,37,111,122,155],[43,129,176,106,107,110,119,146],[16,48,144,10,30,90,59,177],[109,116,137,200,178,112,125,164],[70,210,208,202,184,130,179,115],[134,191,151,31,93,68,204,190],[148,22,66,198,172,94,71,2],[6,18,54,162,64,192,154,40],[120,149,25,75,14,42,126,167],[79,26,78,23,69,207,199,175],[103,98,83,38,114,131,182,124],[161,61,183,127,170,88,53,159],[55,165,73,8,24,72,5,15],[45,135,194,160,58,174,100,89]],U.FINDER_PAT_A=0,U.FINDER_PAT_B=1,U.FINDER_PAT_C=2,U.FINDER_PAT_D=3,U.FINDER_PAT_E=4,U.FINDER_PAT_F=5,U.FINDER_PATTERN_SEQUENCES=[[U.FINDER_PAT_A,U.FINDER_PAT_A],[U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B],[U.FINDER_PAT_A,U.FINDER_PAT_C,U.FINDER_PAT_B,U.FINDER_PAT_D],[U.FINDER_PAT_A,U.FINDER_PAT_E,U.FINDER_PAT_B,U.FINDER_PAT_D,U.FINDER_PAT_C],[U.FINDER_PAT_A,U.FINDER_PAT_E,U.FINDER_PAT_B,U.FINDER_PAT_D,U.FINDER_PAT_D,U.FINDER_PAT_F],[U.FINDER_PAT_A,U.FINDER_PAT_E,U.FINDER_PAT_B,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_F,U.FINDER_PAT_F],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_D],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_E],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_F,U.FINDER_PAT_F],[U.FINDER_PAT_A,U.FINDER_PAT_A,U.FINDER_PAT_B,U.FINDER_PAT_B,U.FINDER_PAT_C,U.FINDER_PAT_D,U.FINDER_PAT_D,U.FINDER_PAT_E,U.FINDER_PAT_E,U.FINDER_PAT_F,U.FINDER_PAT_F]],U.MAX_PAIRS=11;class ut extends Be{constructor(e,t,n){super(e,t),this.count=0,this.finderPattern=n}getFinderPattern(){return this.finderPattern}getCount(){return this.count}incrementCount(){this.count++}}class dt extends ze{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,t,n){let r=this.decodePair(t,!1,e,n);dt.addOrTally(this.possibleLeftPairs,r),t.reverse();let i=this.decodePair(t,!0,e,n);dt.addOrTally(this.possibleRightPairs,i),t.reverse();for(let e of this.possibleLeftPairs)if(e.getCount()>1){for(let t of this.possibleRightPairs)if(t.getCount()>1&&dt.checkChecksum(e,t))return dt.constructResult(e,t)}throw new k}static addOrTally(e,t){if(t==null)return;let n=!1;for(let r of e)if(r.getValue()===t.getValue()){r.incrementCount(),n=!0;break}n||e.push(t)}reset(){this.possibleLeftPairs.length=0,this.possibleRightPairs.length=0}static constructResult(e,t){let n=4537077*e.getValue()+t.getValue(),r=new String(n).toString(),i=new D;for(let e=13-r.length;e>0;e--)i.append(`0`);i.append(r);let a=0;for(let e=0;e<13;e++){let t=i.charAt(e).charCodeAt(0)-48;a+=e&1?t:3*t}a=10-a%10,a===10&&(a=0),i.append(a.toString());let o=e.getFinderPattern().getResultPoints(),s=t.getFinderPattern().getResultPoints();return new R(i.toString(),null,0,[o[0],o[1],s[0],s[1]],z.RSS_14,new Date().getTime())}static checkChecksum(e,t){let n=(e.getChecksumPortion()+16*t.getChecksumPortion())%79,r=9*e.getFinderPattern().getValue()+t.getFinderPattern().getValue();return r>72&&r--,r>8&&r--,n===r}decodePair(e,t,n,r){try{let i=this.findFinderPattern(e,t),a=this.parseFoundFinderPattern(e,n,t,i),o=r==null?null:r.get(b.NEED_RESULT_POINT_CALLBACK);if(o!=null){let r=(i[0]+i[1])/2;t&&(r=e.getSize()-1-r),o.foundPossibleResultPoint(new B(r,n))}let s=this.decodeDataCharacter(e,a,!0),c=this.decodeDataCharacter(e,a,!1);return new ut(1597*s.getValue()+c.getValue(),s.getChecksumPortion()+4*c.getChecksumPortion(),a)}catch{return null}}decodeDataCharacter(e,t,n){let r=this.getDataCharacterCounters();for(let e=0;e<r.length;e++)r[e]=0;if(n)Ee.recordPatternInReverse(e,t.getStartEnd()[0],r);else{Ee.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=pe.sum(new Int32Array(r))/i,o=this.getOddCounts(),s=this.getEvenCounts(),c=this.getOddRoundingErrors(),l=this.getEvenRoundingErrors();for(let e=0;e<r.length;e++){let t=r[e]/a,n=Math.floor(t+.5);n<1?n=1:n>8&&(n=8);let i=Math.floor(e/2);e&1?(s[i]=n,l[i]=t-n):(o[i]=n,c[i]=t-n)}this.adjustOddEvenCounts(n,i);let u=0,d=0;for(let e=o.length-1;e>=0;e--)d*=9,d+=o[e],u+=o[e];let f=0,p=0;for(let e=s.length-1;e>=0;e--)f*=9,f+=s[e],p+=s[e];let m=d+3*f;if(n){if(u&1||u>12||u<4)throw new k;let e=(12-u)/2,t=dt.OUTSIDE_ODD_WIDEST[e],n=9-t,r=He.getRSSvalue(o,t,!1),i=He.getRSSvalue(s,n,!0),a=dt.OUTSIDE_EVEN_TOTAL_SUBSET[e],c=dt.OUTSIDE_GSUM[e];return new Be(r*a+i+c,m)}else{if(p&1||p>10||p<4)throw new k;let e=(10-p)/2,t=dt.INSIDE_ODD_WIDEST[e],n=9-t,r=He.getRSSvalue(o,t,!0),i=He.getRSSvalue(s,n,!1),a=dt.INSIDE_ODD_TOTAL_SUBSET[e],c=dt.INSIDE_GSUM[e];return new Be(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(ze.isFinderPattern(n))return[s,t];s+=n[0]+n[1],n[0]=n[2],n[1]=n[3],n[2]=0,n[3]=0,o--}else o++;n[o]=1,i=!i}throw new k}parseFoundFinderPattern(e,t,n,r){let i=e.get(r[0]),a=r[0]-1;for(;a>=0&&i!==e.get(a);)a--;a++;let o=r[0]-a,s=this.getDecodeFinderCounters(),c=new Int32Array(s.length);p.arraycopy(s,0,c,1,s.length-1),c[0]=o;let l=this.parseFinderValue(c,dt.FINDER_PATTERNS),u=a,d=r[1];return n&&(u=e.getSize()-1-u,d=e.getSize()-1-d),new Ve(l,[a,r[1]],u,d,t)}adjustOddEvenCounts(e,t){let n=pe.sum(new Int32Array(this.getOddCounts())),r=pe.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;ze.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&ze.decrement(this.getOddCounts(),this.getOddRoundingErrors()),o){if(s)throw new k;ze.increment(this.getEvenCounts(),this.getOddRoundingErrors())}s&&ze.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}dt.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],dt.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],dt.OUTSIDE_GSUM=[0,161,961,2015,2715],dt.INSIDE_GSUM=[0,336,1036,1516],dt.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],dt.INSIDE_ODD_WIDEST=[2,4,6,8],dt.FINDER_PATTERNS=[Int32Array.from([3,8,2,1]),Int32Array.from([3,5,5,1]),Int32Array.from([3,3,7,1]),Int32Array.from([3,1,9,1]),Int32Array.from([2,7,4,1]),Int32Array.from([2,5,6,1]),Int32Array.from([2,3,8,1]),Int32Array.from([1,5,7,1]),Int32Array.from([1,3,9,1])];class ft extends Ee{constructor(e,t){super(),this.readers=[],this.verbose=t===!0;let n=e?e.get(b.POSSIBLE_FORMATS):null,r=e&&e.get(b.ASSUME_CODE_39_CHECK_DIGIT)!==void 0;n?((n.includes(z.EAN_13)||n.includes(z.UPC_A)||n.includes(z.EAN_8)||n.includes(z.UPC_E))&&this.readers.push(new Re(e)),n.includes(z.CODE_39)&&this.readers.push(new De(r)),n.includes(z.CODE_128)&&this.readers.push(new V),n.includes(z.ITF)&&this.readers.push(new Oe),n.includes(z.RSS_14)&&this.readers.push(new dt),n.includes(z.RSS_EXPANDED)&&this.readers.push(new U(this.verbose))):(this.readers.push(new Re(e)),this.readers.push(new De),this.readers.push(new Re(e)),this.readers.push(new V),this.readers.push(new Oe),this.readers.push(new dt),this.readers.push(new U(this.verbose)))}decodeRow(e,t,n){for(let r=0;r<this.readers.length;r++)try{return this.readers[r].decodeRow(e,t,n)}catch{}throw new k}reset(){this.readers.forEach(e=>e.reset())}}class pt extends L{constructor(e=500,t){super(new ft(t),e,t)}}class mt{constructor(e,t,n){this.ecCodewords=e,this.ecBlocks=[t],n&&this.ecBlocks.push(n)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class ht{constructor(e,t){this.count=e,this.dataCodewords=t}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class gt{constructor(e,t,n,r,i,a){this.versionNumber=e,this.symbolSizeRows=t,this.symbolSizeColumns=n,this.dataRegionSizeRows=r,this.dataRegionSizeColumns=i,this.ecBlocks=a;let o=0,s=a.getECCodewords(),c=a.getECBlocks();for(let e of c)o+=e.getCount()*(e.getDataCodewords()+s);this.totalCodewords=o}getVersionNumber(){return this.versionNumber}getSymbolSizeRows(){return this.symbolSizeRows}getSymbolSizeColumns(){return this.symbolSizeColumns}getDataRegionSizeRows(){return this.dataRegionSizeRows}getDataRegionSizeColumns(){return this.dataRegionSizeColumns}getTotalCodewords(){return this.totalCodewords}getECBlocks(){return this.ecBlocks}static getVersionForDimensions(e,t){if(e&1||t&1)throw new x;for(let n of gt.VERSIONS)if(n.symbolSizeRows===e&&n.symbolSizeColumns===t)return n;throw new x}toString(){return``+this.versionNumber}static buildVersions(){return[new gt(1,10,10,8,8,new mt(5,new ht(1,3))),new gt(2,12,12,10,10,new mt(7,new ht(1,5))),new gt(3,14,14,12,12,new mt(10,new ht(1,8))),new gt(4,16,16,14,14,new mt(12,new ht(1,12))),new gt(5,18,18,16,16,new mt(14,new ht(1,18))),new gt(6,20,20,18,18,new mt(18,new ht(1,22))),new gt(7,22,22,20,20,new mt(20,new ht(1,30))),new gt(8,24,24,22,22,new mt(24,new ht(1,36))),new gt(9,26,26,24,24,new mt(28,new ht(1,44))),new gt(10,32,32,14,14,new mt(36,new ht(1,62))),new gt(11,36,36,16,16,new mt(42,new ht(1,86))),new gt(12,40,40,18,18,new mt(48,new ht(1,114))),new gt(13,44,44,20,20,new mt(56,new ht(1,144))),new gt(14,48,48,22,22,new mt(68,new ht(1,174))),new gt(15,52,52,24,24,new mt(42,new ht(2,102))),new gt(16,64,64,14,14,new mt(56,new ht(2,140))),new gt(17,72,72,16,16,new mt(36,new ht(4,92))),new gt(18,80,80,18,18,new mt(48,new ht(4,114))),new gt(19,88,88,20,20,new mt(56,new ht(4,144))),new gt(20,96,96,22,22,new mt(68,new ht(4,174))),new gt(21,104,104,24,24,new mt(56,new ht(6,136))),new gt(22,120,120,18,18,new mt(68,new ht(6,175))),new gt(23,132,132,20,20,new mt(62,new ht(8,163))),new gt(24,144,144,22,22,new mt(62,new ht(8,156),new ht(2,155))),new gt(25,8,18,6,16,new mt(7,new ht(1,5))),new gt(26,8,32,6,14,new mt(11,new ht(1,10))),new gt(27,12,26,10,24,new mt(14,new ht(1,16))),new gt(28,12,36,10,16,new mt(18,new ht(1,22))),new gt(29,16,36,14,16,new mt(24,new ht(1,32))),new gt(30,16,48,14,22,new mt(28,new ht(1,49)))]}}gt.VERSIONS=gt.buildVersions();class _t{constructor(e){let t=e.getHeight();if(t<8||t>144||t&1)throw new x;this.version=_t.readVersion(e),this.mappingBitMatrix=this.extractDataRegion(e),this.readMappingMatrix=new O(this.mappingBitMatrix.getWidth(),this.mappingBitMatrix.getHeight())}getVersion(){return this.version}static readVersion(e){let t=e.getHeight(),n=e.getWidth();return gt.getVersionForDimensions(t,n)}readCodewords(){let e=new Int8Array(this.version.getTotalCodewords()),t=0,n=4,r=0,i=this.mappingBitMatrix.getHeight(),a=this.mappingBitMatrix.getWidth(),o=!1,s=!1,c=!1,l=!1;do if(n===i&&r===0&&!o)e[t++]=this.readCorner1(i,a)&255,n-=2,r+=2,o=!0;else if(n===i-2&&r===0&&a&3&&!s)e[t++]=this.readCorner2(i,a)&255,n-=2,r+=2,s=!0;else if(n===i+4&&r===2&&!(a&7)&&!c)e[t++]=this.readCorner3(i,a)&255,n-=2,r+=2,c=!0;else if(n===i-2&&r===0&&(a&7)==4&&!l)e[t++]=this.readCorner4(i,a)&255,n-=2,r+=2,l=!0;else{do n<i&&r>=0&&!this.readMappingMatrix.get(r,n)&&(e[t++]=this.readUtah(n,r,i,a)&255),n-=2,r+=2;while(n>=0&&r<a);n+=1,r+=3;do n>=0&&r<a&&!this.readMappingMatrix.get(r,n)&&(e[t++]=this.readUtah(n,r,i,a)&255),n+=2,r-=2;while(n<i&&r>=0);n+=3,r+=1}while(n<i||r<a);if(t!==this.version.getTotalCodewords())throw new x;return e}readModule(e,t,n,r){return e<0&&(e+=n,t+=4-(n+4&7)),t<0&&(t+=r,e+=4-(r+4&7)),this.readMappingMatrix.set(t,e),this.mappingBitMatrix.get(t,e)}readUtah(e,t,n,r){let i=0;return this.readModule(e-2,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e-2,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e-1,t,n,r)&&(i|=1),i<<=1,this.readModule(e,t-2,n,r)&&(i|=1),i<<=1,this.readModule(e,t-1,n,r)&&(i|=1),i<<=1,this.readModule(e,t,n,r)&&(i|=1),i}readCorner1(e,t){let n=0;return this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,1,e,t)&&(n|=1),n<<=1,this.readModule(e-1,2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(2,t-1,e,t)&&(n|=1),n<<=1,this.readModule(3,t-1,e,t)&&(n|=1),n}readCorner2(e,t){let n=0;return this.readModule(e-3,0,e,t)&&(n|=1),n<<=1,this.readModule(e-2,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(0,t-4,e,t)&&(n|=1),n<<=1,this.readModule(0,t-3,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n}readCorner3(e,t){let n=0;return this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(0,t-3,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-3,e,t)&&(n|=1),n<<=1,this.readModule(1,t-2,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n}readCorner4(e,t){let n=0;return this.readModule(e-3,0,e,t)&&(n|=1),n<<=1,this.readModule(e-2,0,e,t)&&(n|=1),n<<=1,this.readModule(e-1,0,e,t)&&(n|=1),n<<=1,this.readModule(0,t-2,e,t)&&(n|=1),n<<=1,this.readModule(0,t-1,e,t)&&(n|=1),n<<=1,this.readModule(1,t-1,e,t)&&(n|=1),n<<=1,this.readModule(2,t-1,e,t)&&(n|=1),n<<=1,this.readModule(3,t-1,e,t)&&(n|=1),n}extractDataRegion(e){let t=this.version.getSymbolSizeRows(),n=this.version.getSymbolSizeColumns();if(e.getHeight()!==t)throw new l(`Dimension of bitMatrix must match the version size`);let r=this.version.getDataRegionSizeRows(),i=this.version.getDataRegionSizeColumns(),a=t/r|0,o=n/i|0,s=a*r,c=new O(o*i,s);for(let t=0;t<a;++t){let n=t*r;for(let a=0;a<o;++a){let o=a*i;for(let s=0;s<r;++s){let l=t*(r+2)+1+s,u=n+s;for(let t=0;t<i;++t){let n=a*(i+2)+1+t;if(e.get(n,l)){let e=o+t;c.set(e,u)}}}}}return c}}class vt{constructor(e,t){this.numDataCodewords=e,this.codewords=t}static getDataBlocks(e,t){let n=t.getECBlocks(),r=0,i=n.getECBlocks();for(let e of i)r+=e.getCount();let a=Array(r),o=0;for(let e of i)for(let t=0;t<e.getCount();t++){let t=e.getDataCodewords(),r=n.getECCodewords()+t;a[o++]=new vt(t,new Uint8Array(r))}let s=a[0].codewords.length-n.getECCodewords(),c=s-1,u=0;for(let t=0;t<c;t++)for(let n=0;n<o;n++)a[n].codewords[t]=e[u++];let d=t.getVersionNumber()===24,f=d?8:o;for(let t=0;t<f;t++)a[t].codewords[s-1]=e[u++];let p=a[0].codewords.length;for(let t=s;t<p;t++)for(let n=0;n<o;n++){let r=d?(n+8)%o:n,i=d&&r>7?t-1:t;a[r].codewords[i]=e[u++]}if(u!==e.length)throw new l;return a}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}class yt{constructor(e){this.bytes=e,this.byteOffset=0,this.bitOffset=0}getBitOffset(){return this.bitOffset}getByteOffset(){return this.byteOffset}readBits(e){if(e<1||e>32||e>this.available())throw new l(``+e);let t=0,n=this.bitOffset,r=this.byteOffset,i=this.bytes;if(n>0){let a=8-n,o=e<a?e:a,s=a-o,c=255>>8-o<<s;t=(i[r]&c)>>s,e-=o,n+=o,n===8&&(n=0,r++)}if(e>0){for(;e>=8;)t=t<<8|i[r]&255,r++,e-=8;if(e>0){let a=8-e,o=255>>a<<a;t=t<<e|(i[r]&o)>>a,n+=e}}return this.bitOffset=n,this.byteOffset=r,t}available(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset}}var bt;(function(e){e[e.PAD_ENCODE=0]=`PAD_ENCODE`,e[e.ASCII_ENCODE=1]=`ASCII_ENCODE`,e[e.C40_ENCODE=2]=`C40_ENCODE`,e[e.TEXT_ENCODE=3]=`TEXT_ENCODE`,e[e.ANSIX12_ENCODE=4]=`ANSIX12_ENCODE`,e[e.EDIFACT_ENCODE=5]=`EDIFACT_ENCODE`,e[e.BASE256_ENCODE=6]=`BASE256_ENCODE`})(bt||={});class xt{static decode(e){let t=new yt(e),n=new D,r=new D,i=[],a=bt.ASCII_ENCODE;do if(a===bt.ASCII_ENCODE)a=this.decodeAsciiSegment(t,n,r);else{switch(a){case bt.C40_ENCODE:this.decodeC40Segment(t,n);break;case bt.TEXT_ENCODE:this.decodeTextSegment(t,n);break;case bt.ANSIX12_ENCODE:this.decodeAnsiX12Segment(t,n);break;case bt.EDIFACT_ENCODE:this.decodeEdifactSegment(t,n);break;case bt.BASE256_ENCODE:this.decodeBase256Segment(t,n,i);break;default:throw new x}a=bt.ASCII_ENCODE}while(a!==bt.PAD_ENCODE&&t.available()>0);return r.length()>0&&n.append(r.toString()),new re(e,n.toString(),i.length===0?null:i,null)}static decodeAsciiSegment(e,t,n){let r=!1;do{let i=e.readBits(8);if(i===0)throw new x;if(i<=128)return r&&(i+=128),t.append(String.fromCharCode(i-1)),bt.ASCII_ENCODE;if(i===129)return bt.PAD_ENCODE;if(i<=229){let e=i-130;e<10&&t.append(`0`),t.append(``+e)}else switch(i){case 230:return bt.C40_ENCODE;case 231:return bt.BASE256_ENCODE;case 232:t.append(``);break;case 233:case 234:break;case 235:r=!0;break;case 236:t.append(`[)>05`),n.insert(0,``);break;case 237:t.append(`[)>06`),n.insert(0,``);break;case 238:return bt.ANSIX12_ENCODE;case 239:return bt.TEXT_ENCODE;case 240:return bt.EDIFACT_ENCODE;case 241:break;default:if(i!==254||e.available()!==0)throw new x;break}}while(e.available()>0);return bt.ASCII_ENCODE}static decodeC40Segment(e,t){let n=!1,r=[],i=0;do{if(e.available()===8)return;let a=e.readBits(8);if(a===254)return;this.parseTwoBytes(a,e.readBits(8),r);for(let e=0;e<3;e++){let a=r[e];switch(i){case 0:if(a<3)i=a+1;else if(a<this.C40_BASIC_SET_CHARS.length){let e=this.C40_BASIC_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else throw new x;break;case 1:n?(t.append(String.fromCharCode(a+128)),n=!1):t.append(String.fromCharCode(a)),i=0;break;case 2:if(a<this.C40_SHIFT2_SET_CHARS.length){let e=this.C40_SHIFT2_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else switch(a){case 27:t.append(``);break;case 30:n=!0;break;default:throw new x}i=0;break;case 3:n?(t.append(String.fromCharCode(a+224)),n=!1):t.append(String.fromCharCode(a+96)),i=0;break;default:throw new x}}}while(e.available()>0)}static decodeTextSegment(e,t){let n=!1,r=[],i=0;do{if(e.available()===8)return;let a=e.readBits(8);if(a===254)return;this.parseTwoBytes(a,e.readBits(8),r);for(let e=0;e<3;e++){let a=r[e];switch(i){case 0:if(a<3)i=a+1;else if(a<this.TEXT_BASIC_SET_CHARS.length){let e=this.TEXT_BASIC_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else throw new x;break;case 1:n?(t.append(String.fromCharCode(a+128)),n=!1):t.append(String.fromCharCode(a)),i=0;break;case 2:if(a<this.TEXT_SHIFT2_SET_CHARS.length){let e=this.TEXT_SHIFT2_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e)}else switch(a){case 27:t.append(``);break;case 30:n=!0;break;default:throw new x}i=0;break;case 3:if(a<this.TEXT_SHIFT3_SET_CHARS.length){let e=this.TEXT_SHIFT3_SET_CHARS[a];n?(t.append(String.fromCharCode(e.charCodeAt(0)+128)),n=!1):t.append(e),i=0}else throw new x;break;default:throw new x}}}while(e.available()>0)}static decodeAnsiX12Segment(e,t){let n=[];do{if(e.available()===8)return;let r=e.readBits(8);if(r===254)return;this.parseTwoBytes(r,e.readBits(8),n);for(let e=0;e<3;e++){let r=n[e];switch(r){case 0:t.append(`\r`);break;case 1:t.append(`*`);break;case 2:t.append(`>`);break;case 3:t.append(` `);break;default:if(r<14)t.append(String.fromCharCode(r+44));else if(r<40)t.append(String.fromCharCode(r+51));else throw new x;break}}}while(e.available()>0)}static parseTwoBytes(e,t,n){let r=(e<<8)+t-1,i=Math.floor(r/1600);n[0]=i,r-=i*1600,i=Math.floor(r/40),n[1]=i,n[2]=r-i*40}static decodeEdifactSegment(e,t){do{if(e.available()<=16)return;for(let n=0;n<4;n++){let n=e.readBits(6);if(n===31){let t=8-e.getBitOffset();t!==8&&e.readBits(t);return}n&32||(n|=64),t.append(String.fromCharCode(n))}}while(e.available()>0)}static decodeBase256Segment(e,t,n){let r=1+e.getByteOffset(),i=this.unrandomize255State(e.readBits(8),r++),a;if(a=i===0?e.available()/8|0:i<250?i:250*(i-249)+this.unrandomize255State(e.readBits(8),r++),a<0)throw new x;let o=new Uint8Array(a);for(let t=0;t<a;t++){if(e.available()<8)throw new x;o[t]=this.unrandomize255State(e.readBits(8),r++)}n.push(o);try{t.append(T.decode(o,E.ISO88591))}catch(e){throw new le(`Platform does not support required encoding: `+e.message)}}static unrandomize255State(e,t){let n=e-(149*t%255+1);return n>=0?n:n+256}}xt.C40_BASIC_SET_CHARS=`*** 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``),xt.C40_SHIFT2_SET_CHARS=`!"#$%&'()*+,-./:;<=>?@[\\]^_`.split(``),xt.TEXT_BASIC_SET_CHARS=`*** 0123456789abcdefghijklmnopqrstuvwxyz`.split(``),xt.TEXT_SHIFT2_SET_CHARS=xt.C40_SHIFT2_SET_CHARS,xt.TEXT_SHIFT3_SET_CHARS="`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~".split(``);class St{constructor(){this.rsDecoder=new ue(se.DATA_MATRIX_FIELD_256)}decode(e){let t=new _t(e),n=t.getVersion(),r=t.readCodewords(),i=vt.getDataBlocks(r,n),a=0;for(let e of i)a+=e.getNumDataCodewords();let o=new Uint8Array(a),s=i.length;for(let e=0;e<s;e++){let t=i[e],n=t.getCodewords(),r=t.getNumDataCodewords();this.correctErrors(n,r);for(let t=0;t<r;t++)o[t*s+e]=n[t]}return xt.decode(o)}correctErrors(e,t){let n=new Int32Array(e);try{this.rsDecoder.decode(n,e.length-t)}catch{throw new d}for(let r=0;r<t;r++)e[r]=n[r]}}class Ct{constructor(e){this.image=e,this.rectangleDetector=new _e(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 he(Ct.sampleGrid(this.image,n,r,i,a,o,s),[n,r,i,a])}static shiftPoint(e,t,n){let r=(t.getX()-e.getX())/(n+1),i=(t.getY()-e.getY())/(n+1);return new B(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 B(r,i)}detectSolid1(e){let t=e[0],n=e[1],r=e[3],i=e[2],a=this.transitionsBetween(t,n),o=this.transitionsBetween(n,r),s=this.transitionsBetween(r,i),c=this.transitionsBetween(i,t),l=a,u=[i,t,n,r];return l>o&&(l=o,u[0]=t,u[1]=n,u[2]=r,u[3]=i),l>s&&(l=s,u[0]=n,u[1]=r,u[2]=i,u[3]=t),l>c&&(u[0]=r,u[1]=i,u[2]=t,u[3]=n),u}detectSolid2(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i),o=Ct.shiftPoint(n,r,(a+1)*4),s=Ct.shiftPoint(r,n,(a+1)*4);return this.transitionsBetween(o,t)<this.transitionsBetween(s,i)?(e[0]=t,e[1]=n,e[2]=r,e[3]=i):(e[0]=n,e[1]=r,e[2]=i,e[3]=t),e}correctTopRight(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i),o=this.transitionsBetween(n,i),s=Ct.shiftPoint(t,n,(o+1)*4),c=Ct.shiftPoint(r,n,(a+1)*4);a=this.transitionsBetween(s,i),o=this.transitionsBetween(c,i);let l=new B(i.getX()+(r.getX()-n.getX())/(a+1),i.getY()+(r.getY()-n.getY())/(a+1)),u=new B(i.getX()+(t.getX()-n.getX())/(o+1),i.getY()+(t.getY()-n.getY())/(o+1));return this.isValid(l)?!this.isValid(u)||this.transitionsBetween(s,l)+this.transitionsBetween(c,l)>this.transitionsBetween(s,u)+this.transitionsBetween(c,u)?l:u:this.isValid(u)?u:null}shiftToModuleCenter(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=this.transitionsBetween(t,i)+1,o=this.transitionsBetween(r,i)+1,s=Ct.shiftPoint(t,n,o*4),c=Ct.shiftPoint(r,n,a*4);a=this.transitionsBetween(s,i)+1,o=this.transitionsBetween(c,i)+1,(a&1)==1&&(a+=1),(o&1)==1&&(o+=1);let l=(t.getX()+n.getX()+r.getX()+i.getX())/4,u=(t.getY()+n.getY()+r.getY()+i.getY())/4;t=Ct.moveAway(t,l,u),n=Ct.moveAway(n,l,u),r=Ct.moveAway(r,l,u),i=Ct.moveAway(i,l,u);let d,f;return s=Ct.shiftPoint(t,n,o*4),s=Ct.shiftPoint(s,i,a*4),d=Ct.shiftPoint(n,t,o*4),d=Ct.shiftPoint(d,r,a*4),c=Ct.shiftPoint(r,i,o*4),c=Ct.shiftPoint(c,n,a*4),f=Ct.shiftPoint(i,r,o*4),f=Ct.shiftPoint(f,t,a*4),[s,d,c,f]}isValid(e){return e.getX()>=0&&e.getX()<this.image.getWidth()&&e.getY()>0&&e.getY()<this.image.getHeight()}static sampleGrid(e,t,n,r,i,a,o){return xe.getInstance().sampleGrid(e,a,o,.5,.5,a-.5,.5,a-.5,o-.5,.5,o-.5,t.getX(),t.getY(),i.getX(),i.getY(),r.getX(),r.getY(),n.getX(),n.getY())}transitionsBetween(e,t){let n=Math.trunc(e.getX()),r=Math.trunc(e.getY()),i=Math.trunc(t.getX()),a=Math.trunc(t.getY()),o=Math.abs(a-r)>Math.abs(i-n);if(o){let e=n;n=r,r=e,e=i,i=a,a=e}let s=Math.abs(i-n),c=Math.abs(a-r),l=-s/2,u=r<a?1:-1,d=n<i?1:-1,f=0,p=this.image.get(o?r:n,o?n:r);for(let e=n,t=r;e!==i;e+=d){let n=this.image.get(o?t:e,o?e:t);if(n!==p&&(f++,p=n),l+=c,l>0){if(t===a)break;t+=u,l-=s}}return f}}class wt{constructor(){this.decoder=new St}decode(e,t=null){let n,r;if(t!=null&&t.has(b.PURE_BARCODE)){let t=wt.extractPureBits(e.getBlackMatrix());n=this.decoder.decode(t),r=wt.NO_POINTS}else{let t=new Ct(e.getBlackMatrix()).detect();n=this.decoder.decode(t.getBits()),r=t.getPoints()}let i=n.getRawBytes(),a=new R(n.getText(),i,8*i.length,r,z.DATA_MATRIX,p.currentTimeMillis()),o=n.getByteSegments();o!=null&&a.putMetadata(ne.BYTE_SEGMENTS,o);let s=n.getECLevel();return s!=null&&a.putMetadata(ne.ERROR_CORRECTION_LEVEL,s),a}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t==null||n==null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=(n[0]-o+1)/r,c=(a-i+1)/r;if(s<=0||c<=0)throw new k;let l=r/2;i+=l,o+=l;let u=new O(s,c);for(let t=0;t<c;t++){let n=i+t*r;for(let i=0;i<s;i++)e.get(o+i*r,n)&&u.set(i,t)}return u}static moduleSize(e,t){let n=t.getWidth(),r=e[0],i=e[1];for(;r<n&&t.get(r,i);)r++;if(r===n)throw new k;let a=r-e[0];if(a===0)throw new k;return a}}wt.NO_POINTS=[];class Tt extends L{constructor(e=500){super(new wt,e)}}var W;(function(e){e[e.L=0]=`L`,e[e.M=1]=`M`,e[e.Q=2]=`Q`,e[e.H=3]=`H`})(W||={});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(W.L,`L`,1),Et.M=new Et(W.M,`M`,0),Et.Q=new Et(W.Q,`Q`,3),Et.H=new Et(W.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 yt(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 re(e,a.toString(),o.length===0?null:o,n===null?null:n.toString(),s,c)}static decodeHanziSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/96<<8&4294967295|t%96;a<959?a+=41377:a+=42657,r[i]=a>>8&255,r[i+1]=a&255,i+=2,n--}try{t.append(T.decode(r,E.GB2312))}catch(e){throw new x(e)}}static decodeKanjiSegment(e,t,n){if(n*13>e.available())throw new x;let r=new Uint8Array(2*n),i=0;for(;n>0;){let t=e.readBits(13),a=t/192<<8&4294967295|t%192;a<7936?a+=33088:a+=49472,r[i]=a>>8,r[i+1]=a,i+=2,n--}try{t.append(T.decode(r,E.SHIFT_JIS))}catch(e){throw new x(e)}}static decodeByteSegment(e,t,n,r,i,a){if(8*n>e.available())throw new x;let o=new Uint8Array(n);for(let t=0;t<n;t++)o[t]=e.readBits(8);let s;s=r===null?E.guessEncoding(o,a):r.getName();try{t.append(T.decode(o,s))}catch(e){throw new x(e)}i.push(o)}static toAlphaNumericChar(e){if(e>=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 ue(se.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 B{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 B{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 B.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 he(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),ye.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 xe.getInstance().sampleGridWithTransform(e,n,n,t)}static computeDimension(e,t,n,r){let i=pe.round(B.distance(e,t)/r),a=pe.round(B.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 pe.distance(n,f,e,t);u++}if(s+=o,s>0){if(f===r)break;f+=l,s-=a}}return u===2?pe.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,z.QR_CODE,void 0),a=n.getByteSegments();a!==null&&i.putMetadata(ne.BYTE_SEGMENTS,a);let o=n.getECLevel();return o!==null&&i.putMetadata(ne.ERROR_CORRECTION_LEVEL,o),n.hasStructuredAppend()&&(i.putMetadata(ne.STRUCTURED_APPEND_SEQUENCE,n.getStructuredAppendSequenceNumber()),i.putMetadata(ne.STRUCTURED_APPEND_PARITY,n.getStructuredAppendParity())),i}reset(){}static extractPureBits(e){let t=e.getTopLeftOnBit(),n=e.getBottomRightOnBit();if(t===null||n===null)throw new k;let r=this.moduleSize(t,e),i=t[1],a=n[1],o=t[0],s=n[0];if(o>=s||i>=a||a-i!==s-o&&(s=o+(a-i),s>=e.getWidth()))throw new k;let c=Math.round((s-o+1)/r),l=Math.round((a-i+1)/r);if(c<=0||l<=0||l!==c)throw new k;let u=Math.floor(r/2);i+=u,o+=u;let d=o+Math.floor((c-1)*r)-s;if(d>0){if(d>u)throw new k;o-=d}let f=i+Math.floor((l-1)*r)-a;if(f>0){if(f>u)throw new k;i-=f}let p=new O(c,l);for(let t=0;t<l;t++){let n=i+Math.floor(t*r);for(let i=0;i<c;i++)e.get(o+Math.floor(i*r),n)&&p.set(i,t)}return p}static moduleSize(e,t){let n=t.getHeight(),r=t.getWidth(),i=e[0],a=e[1],o=!0,s=0;for(;i<r&&a<n;){if(o!==t.get(i,a)){if(++s===5)break;o=!o}i++,a++}if(i===r||a===n)throw new k;return(i-e[0])/7}}Wt.NO_POINTS=[];class q{PDF417Common(){}static getBitCountSum(e){return pe.sum(e)}static toIntArray(e){if(e==null||!e.length)return q.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(q.SYMBOL_TABLE,e&262143);return t<0?-1:(q.CODEWORD_TABLE[t]-1)%q.NUMBER_OF_CODEWORDS}}q.NUMBER_OF_CODEWORDS=929,q.MAX_CODEWORDS_IN_BARCODE=q.NUMBER_OF_CODEWORDS-1,q.MIN_ROWS_IN_BARCODE=3,q.MAX_ROWS_IN_BARCODE=90,q.MODULES_IN_CODEWORD=17,q.MODULES_IN_STOP_PATTERN=18,q.BARS_IN_MODULE=8,q.EMPTY_INT_ARRAY=new Int32Array([]),q.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]),q.CODEWORD_TABLE=Int32Array.from([2627,1819,2622,2621,1813,1812,2729,2724,2723,2779,2774,2773,902,896,908,868,865,861,859,2511,873,871,1780,835,2493,825,2491,842,837,844,1764,1762,811,810,809,2483,807,2482,806,2480,815,814,813,812,2484,817,816,1745,1744,1742,1746,2655,2637,2635,2626,2625,2623,2628,1820,2752,2739,2737,2728,2727,2725,2730,2785,2783,2778,2777,2775,2780,787,781,747,739,736,2413,754,752,1719,692,689,681,2371,678,2369,700,697,694,703,1688,1686,642,638,2343,631,2341,627,2338,651,646,643,2345,654,652,1652,1650,1647,1654,601,599,2322,596,2321,594,2319,2317,611,610,608,606,2324,603,2323,615,614,612,1617,1616,1614,1612,616,1619,1618,2575,2538,2536,905,901,898,909,2509,2507,2504,870,867,864,860,2512,875,872,1781,2490,2489,2487,2485,1748,836,834,832,830,2494,827,2492,843,841,839,845,1765,1763,2701,2676,2674,2653,2648,2656,2634,2633,2631,2629,1821,2638,2636,2770,2763,2761,2750,2745,2753,2736,2735,2733,2731,1848,2740,2738,2786,2784,591,588,576,569,566,2296,1590,537,534,526,2276,522,2274,545,542,539,548,1572,1570,481,2245,466,2242,462,2239,492,485,482,2249,496,494,1534,1531,1528,1538,413,2196,406,2191,2188,425,419,2202,415,2199,432,430,427,1472,1467,1464,433,1476,1474,368,367,2160,365,2159,362,2157,2155,2152,378,377,375,2166,372,2165,369,2162,383,381,379,2168,1419,1418,1416,1414,385,1411,384,1423,1422,1420,1424,2461,802,2441,2439,790,786,783,794,2409,2406,2403,750,742,738,2414,756,753,1720,2367,2365,2362,2359,1663,693,691,684,2373,680,2370,702,699,696,704,1690,1687,2337,2336,2334,2332,1624,2329,1622,640,637,2344,634,2342,630,2340,650,648,645,2346,655,653,1653,1651,1649,1655,2612,2597,2595,2571,2568,2565,2576,2534,2529,2526,1787,2540,2537,907,904,900,910,2503,2502,2500,2498,1768,2495,1767,2510,2508,2506,869,866,863,2513,876,874,1782,2720,2713,2711,2697,2694,2691,2702,2672,2670,2664,1828,2678,2675,2647,2646,2644,2642,1823,2639,1822,2654,2652,2650,2657,2771,1855,2765,2762,1850,1849,2751,2749,2747,2754,353,2148,344,342,336,2142,332,2140,345,1375,1373,306,2130,299,2128,295,2125,319,314,311,2132,1354,1352,1349,1356,262,257,2101,253,2096,2093,274,273,267,2107,263,2104,280,278,275,1316,1311,1308,1320,1318,2052,202,2050,2044,2040,219,2063,212,2060,208,2055,224,221,2066,1260,1258,1252,231,1248,229,1266,1264,1261,1268,155,1998,153,1996,1994,1991,1988,165,164,2007,162,2006,159,2003,2e3,172,171,169,2012,166,2010,1186,1184,1182,1179,175,1176,173,1192,1191,1189,1187,176,1194,1193,2313,2307,2305,592,589,2294,2292,2289,578,572,568,2297,580,1591,2272,2267,2264,1547,538,536,529,2278,525,2275,547,544,541,1574,1571,2237,2235,2229,1493,2225,1489,478,2247,470,2244,465,2241,493,488,484,2250,498,495,1536,1533,1530,1539,2187,2186,2184,2182,1432,2179,1430,2176,1427,414,412,2197,409,2195,405,2193,2190,426,424,421,2203,418,2201,431,429,1473,1471,1469,1466,434,1477,1475,2478,2472,2470,2459,2457,2454,2462,803,2437,2432,2429,1726,2443,2440,792,789,785,2401,2399,2393,1702,2389,1699,2411,2408,2405,745,741,2415,758,755,1721,2358,2357,2355,2353,1661,2350,1660,2347,1657,2368,2366,2364,2361,1666,690,687,2374,683,2372,701,698,705,1691,1689,2619,2617,2610,2608,2605,2613,2593,2588,2585,1803,2599,2596,2563,2561,2555,1797,2551,1795,2573,2570,2567,2577,2525,2524,2522,2520,1786,2517,1785,2514,1783,2535,2533,2531,2528,1788,2541,2539,906,903,911,2721,1844,2715,2712,1838,1836,2699,2696,2693,2703,1827,1826,1824,2673,2671,2669,2666,1829,2679,2677,1858,1857,2772,1854,1853,1851,1856,2766,2764,143,1987,139,1986,135,133,131,1984,128,1983,125,1981,138,137,136,1985,1133,1132,1130,112,110,1974,107,1973,104,1971,1969,122,121,119,117,1977,114,1976,124,1115,1114,1112,1110,1117,1116,84,83,1953,81,1952,78,1950,1948,1945,94,93,91,1959,88,1958,85,1955,99,97,95,1961,1086,1085,1083,1081,1078,100,1090,1089,1087,1091,49,47,1917,44,1915,1913,1910,1907,59,1926,56,1925,53,1922,1919,66,64,1931,61,1929,1042,1040,1038,71,1035,70,1032,68,1048,1047,1045,1043,1050,1049,12,10,1869,1867,1864,1861,21,1880,19,1877,1874,1871,28,1888,25,1886,22,1883,982,980,977,974,32,30,991,989,987,984,34,995,994,992,2151,2150,2147,2146,2144,356,355,354,2149,2139,2138,2136,2134,1359,343,341,338,2143,335,2141,348,347,346,1376,1374,2124,2123,2121,2119,1326,2116,1324,310,308,305,2131,302,2129,298,2127,320,318,316,313,2133,322,321,1355,1353,1351,1357,2092,2091,2089,2087,1276,2084,1274,2081,1271,259,2102,256,2100,252,2098,2095,272,269,2108,266,2106,281,279,277,1317,1315,1313,1310,282,1321,1319,2039,2037,2035,2032,1203,2029,1200,1197,207,2053,205,2051,201,2049,2046,2043,220,218,2064,215,2062,211,2059,228,226,223,2069,1259,1257,1254,232,1251,230,1267,1265,1263,2316,2315,2312,2311,2309,2314,2304,2303,2301,2299,1593,2308,2306,590,2288,2287,2285,2283,1578,2280,1577,2295,2293,2291,579,577,574,571,2298,582,581,1592,2263,2262,2260,2258,1545,2255,1544,2252,1541,2273,2271,2269,2266,1550,535,532,2279,528,2277,546,543,549,1575,1573,2224,2222,2220,1486,2217,1485,2214,1482,1479,2238,2236,2234,2231,1496,2228,1492,480,477,2248,473,2246,469,2243,490,487,2251,497,1537,1535,1532,2477,2476,2474,2479,2469,2468,2466,2464,1730,2473,2471,2453,2452,2450,2448,1729,2445,1728,2460,2458,2456,2463,805,804,2428,2427,2425,2423,1725,2420,1724,2417,1722,2438,2436,2434,2431,1727,2444,2442,793,791,788,795,2388,2386,2384,1697,2381,1696,2378,1694,1692,2402,2400,2398,2395,1703,2392,1701,2412,2410,2407,751,748,744,2416,759,757,1807,2620,2618,1806,1805,2611,2609,2607,2614,1802,1801,1799,2594,2592,2590,2587,1804,2600,2598,1794,1793,1791,1789,2564,2562,2560,2557,1798,2554,1796,2574,2572,2569,2578,1847,1846,2722,1843,1842,1840,1845,2716,2714,1835,1834,1832,1830,1839,1837,2700,2698,2695,2704,1817,1811,1810,897,862,1777,829,826,838,1760,1758,808,2481,1741,1740,1738,1743,2624,1818,2726,2776,782,740,737,1715,686,679,695,1682,1680,639,628,2339,647,644,1645,1643,1640,1648,602,600,597,595,2320,593,2318,609,607,604,1611,1610,1608,1606,613,1615,1613,2328,926,924,892,886,899,857,850,2505,1778,824,823,821,819,2488,818,2486,833,831,828,840,1761,1759,2649,2632,2630,2746,2734,2732,2782,2781,570,567,1587,531,527,523,540,1566,1564,476,467,463,2240,486,483,1524,1521,1518,1529,411,403,2192,399,2189,423,416,1462,1457,1454,428,1468,1465,2210,366,363,2158,360,2156,357,2153,376,373,370,2163,1410,1409,1407,1405,382,1402,380,1417,1415,1412,1421,2175,2174,777,774,771,784,732,725,722,2404,743,1716,676,674,668,2363,665,2360,685,1684,1681,626,624,622,2335,620,2333,617,2330,641,635,649,1646,1644,1642,2566,928,925,2530,2527,894,891,888,2501,2499,2496,858,856,854,851,1779,2692,2668,2665,2645,2643,2640,2651,2768,2759,2757,2744,2743,2741,2748,352,1382,340,337,333,1371,1369,307,300,296,2126,315,312,1347,1342,1350,261,258,250,2097,246,2094,271,268,264,1306,1301,1298,276,1312,1309,2115,203,2048,195,2045,191,2041,213,209,2056,1246,1244,1238,225,1234,222,1256,1253,1249,1262,2080,2079,154,1997,150,1995,147,1992,1989,163,160,2004,156,2001,1175,1174,1172,1170,1167,170,1164,167,1185,1183,1180,1177,174,1190,1188,2025,2024,2022,587,586,564,559,556,2290,573,1588,520,518,512,2268,508,2265,530,1568,1565,461,457,2233,450,2230,446,2226,479,471,489,1526,1523,1520,397,395,2185,392,2183,389,2180,2177,410,2194,402,422,1463,1461,1459,1456,1470,2455,799,2433,2430,779,776,773,2397,2394,2390,734,728,724,746,1717,2356,2354,2351,2348,1658,677,675,673,670,667,688,1685,1683,2606,2589,2586,2559,2556,2552,927,2523,2521,2518,2515,1784,2532,895,893,890,2718,2709,2707,2689,2687,2684,2663,2662,2660,2658,1825,2667,2769,1852,2760,2758,142,141,1139,1138,134,132,129,126,1982,1129,1128,1126,1131,113,111,108,105,1972,101,1970,120,118,115,1109,1108,1106,1104,123,1113,1111,82,79,1951,75,1949,72,1946,92,89,86,1956,1077,1076,1074,1072,98,1069,96,1084,1082,1079,1088,1968,1967,48,45,1916,42,1914,39,1911,1908,60,57,54,1923,50,1920,1031,1030,1028,1026,67,1023,65,1020,62,1041,1039,1036,1033,69,1046,1044,1944,1943,1941,11,9,1868,7,1865,1862,1859,20,1878,16,1875,13,1872,970,968,966,963,29,960,26,23,983,981,978,975,33,971,31,990,988,985,1906,1904,1902,993,351,2145,1383,331,330,328,326,2137,323,2135,339,1372,1370,294,293,291,289,2122,286,2120,283,2117,309,303,317,1348,1346,1344,245,244,242,2090,239,2088,236,2085,2082,260,2099,249,270,1307,1305,1303,1300,1314,189,2038,186,2036,183,2033,2030,2026,206,198,2047,194,216,1247,1245,1243,1240,227,1237,1255,2310,2302,2300,2286,2284,2281,565,563,561,558,575,1589,2261,2259,2256,2253,1542,521,519,517,514,2270,511,533,1569,1567,2223,2221,2218,2215,1483,2211,1480,459,456,453,2232,449,474,491,1527,1525,1522,2475,2467,2465,2451,2449,2446,801,800,2426,2424,2421,2418,1723,2435,780,778,775,2387,2385,2382,2379,1695,2375,1693,2396,735,733,730,727,749,1718,2616,2615,2604,2603,2601,2584,2583,2581,2579,1800,2591,2550,2549,2547,2545,1792,2542,1790,2558,929,2719,1841,2710,2708,1833,1831,2690,2688,2686,1815,1809,1808,1774,1756,1754,1737,1736,1734,1739,1816,1711,1676,1674,633,629,1638,1636,1633,1641,598,1605,1604,1602,1600,605,1609,1607,2327,887,853,1775,822,820,1757,1755,1584,524,1560,1558,468,464,1514,1511,1508,1519,408,404,400,1452,1447,1444,417,1458,1455,2208,364,361,358,2154,1401,1400,1398,1396,374,1393,371,1408,1406,1403,1413,2173,2172,772,726,723,1712,672,669,666,682,1678,1675,625,623,621,618,2331,636,632,1639,1637,1635,920,918,884,880,889,849,848,847,846,2497,855,852,1776,2641,2742,2787,1380,334,1367,1365,301,297,1340,1338,1335,1343,255,251,247,1296,1291,1288,265,1302,1299,2113,204,196,192,2042,1232,1230,1224,214,1220,210,1242,1239,1235,1250,2077,2075,151,148,1993,144,1990,1163,1162,1160,1158,1155,161,1152,157,1173,1171,1168,1165,168,1181,1178,2021,2020,2018,2023,585,560,557,1585,516,509,1562,1559,458,447,2227,472,1516,1513,1510,398,396,393,390,2181,386,2178,407,1453,1451,1449,1446,420,1460,2209,769,764,720,712,2391,729,1713,664,663,661,659,2352,656,2349,671,1679,1677,2553,922,919,2519,2516,885,883,881,2685,2661,2659,2767,2756,2755,140,1137,1136,130,127,1125,1124,1122,1127,109,106,102,1103,1102,1100,1098,116,1107,1105,1980,80,76,73,1947,1068,1067,1065,1063,90,1060,87,1075,1073,1070,1080,1966,1965,46,43,40,1912,36,1909,1019,1018,1016,1014,58,1011,55,1008,51,1029,1027,1024,1021,63,1037,1034,1940,1939,1937,1942,8,1866,4,1863,1,1860,956,954,952,949,946,17,14,969,967,964,961,27,957,24,979,976,972,1901,1900,1898,1896,986,1905,1903,350,349,1381,329,327,324,1368,1366,292,290,287,284,2118,304,1341,1339,1337,1345,243,240,237,2086,233,2083,254,1297,1295,1293,1290,1304,2114,190,187,184,2034,180,2031,177,2027,199,1233,1231,1229,1226,217,1223,1241,2078,2076,584,555,554,552,550,2282,562,1586,507,506,504,502,2257,499,2254,515,1563,1561,445,443,441,2219,438,2216,435,2212,460,454,475,1517,1515,1512,2447,798,797,2422,2419,770,768,766,2383,2380,2376,721,719,717,714,731,1714,2602,2582,2580,2548,2546,2543,923,921,2717,2706,2705,2683,2682,2680,1771,1752,1750,1733,1732,1731,1735,1814,1707,1670,1668,1631,1629,1626,1634,1599,1598,1596,1594,1603,1601,2326,1772,1753,1751,1581,1554,1552,1504,1501,1498,1509,1442,1437,1434,401,1448,1445,2206,1392,1391,1389,1387,1384,359,1399,1397,1394,1404,2171,2170,1708,1672,1669,619,1632,1630,1628,1773,1378,1363,1361,1333,1328,1336,1286,1281,1278,248,1292,1289,2111,1218,1216,1210,197,1206,193,1228,1225,1221,1236,2073,2071,1151,1150,1148,1146,152,1143,149,1140,145,1161,1159,1156,1153,158,1169,1166,2017,2016,2014,2019,1582,510,1556,1553,452,448,1506,1500,394,391,387,1443,1441,1439,1436,1450,2207,765,716,713,1709,662,660,657,1673,1671,916,914,879,878,877,882,1135,1134,1121,1120,1118,1123,1097,1096,1094,1092,103,1101,1099,1979,1059,1058,1056,1054,77,1051,74,1066,1064,1061,1071,1964,1963,1007,1006,1004,1002,999,41,996,37,1017,1015,1012,1009,52,1025,1022,1936,1935,1933,1938,942,940,938,935,932,5,2,955,953,950,947,18,943,15,965,962,958,1895,1894,1892,1890,973,1899,1897,1379,325,1364,1362,288,285,1334,1332,1330,241,238,234,1287,1285,1283,1280,1294,2112,188,185,181,178,2028,1219,1217,1215,1212,200,1209,1227,2074,2072,583,553,551,1583,505,503,500,513,1557,1555,444,442,439,436,2213,455,451,1507,1505,1502,796,763,762,760,767,711,710,708,706,2377,718,715,1710,2544,917,915,2681,1627,1597,1595,2325,1769,1749,1747,1499,1438,1435,2204,1390,1388,1385,1395,2169,2167,1704,1665,1662,1625,1623,1620,1770,1329,1282,1279,2109,1214,1207,1222,2068,2065,1149,1147,1144,1141,146,1157,1154,2013,2011,2008,2015,1579,1549,1546,1495,1487,1433,1431,1428,1425,388,1440,2205,1705,658,1667,1664,1119,1095,1093,1978,1057,1055,1052,1062,1962,1960,1005,1003,1e3,997,38,1013,1010,1932,1930,1927,1934,941,939,936,933,6,930,3,951,948,944,1889,1887,1884,1881,959,1893,1891,35,1377,1360,1358,1327,1325,1322,1331,1277,1275,1272,1269,235,1284,2110,1205,1204,1201,1198,182,1195,179,1213,2070,2067,1580,501,1551,1548,440,437,1497,1494,1490,1503,761,709,707,1706,913,912,2198,1386,2164,2161,1621,1766,2103,1208,2058,2054,1145,1142,2005,2002,1999,2009,1488,1429,1426,2200,1698,1659,1656,1975,1053,1957,1954,1001,998,1924,1921,1918,1928,937,934,931,1879,1876,1873,1870,945,1885,1882,1323,1273,1270,2105,1202,1199,1196,1211,2061,2057,1576,1543,1540,1484,1481,1478,1491,1700]);class Gt{constructor(e,t){this.bits=e,this.points=t}getBits(){return this.bits}getPoints(){return this.points}}class Kt{static detectMultiple(e,t,n){let r=e.getBlackMatrix(),i=Kt.detect(n,r);return i.length||(r=r.clone(),r.rotate180(),i=Kt.detect(n,r)),new Gt(r,i)}static detect(e,t){let n=[],r=0,i=0,a=!1;for(;r<t.getHeight();){let o=Kt.findVertices(t,r,i);if(o[0]==null&&o[3]==null){if(!a)break;a=!1,i=0;for(let e of n)e[1]!=null&&(r=Math.trunc(Math.max(r,e[1].getY()))),e[3]!=null&&(r=Math.max(r,Math.trunc(e[3].getY())));r+=Kt.ROW_STEP;continue}if(a=!0,n.push(o),!e)break;o[2]==null?(i=Math.trunc(o[4].getX()),r=Math.trunc(o[4].getY())):(i=Math.trunc(o[2].getX()),r=Math.trunc(o[2].getY()))}return n}static findVertices(e,t,n){let r=e.getHeight(),i=e.getWidth(),a=Array(8);return Kt.copyToResult(a,Kt.findRowsWithPattern(e,r,i,t,n,Kt.START_PATTERN),Kt.INDEXES_START_PATTERN),a[4]!=null&&(n=Math.trunc(a[4].getX()),t=Math.trunc(a[4].getY())),Kt.copyToResult(a,Kt.findRowsWithPattern(e,r,i,t,n,Kt.STOP_PATTERN),Kt.INDEXES_STOP_PATTERN),a}static copyToResult(e,t,n){for(let r=0;r<n.length;r++)e[n[r]]=t[r]}static findRowsWithPattern(e,t,n,r,i,a){let o=[,,,,],s=!1,c=new Int32Array(a.length);for(;r<t;r+=Kt.ROW_STEP){let t=Kt.findGuardPattern(e,i,r,n,!1,a,c);if(t!=null){for(;r>0;){let o=Kt.findGuardPattern(e,i,--r,n,!1,a,c);if(o!=null)t=o;else{r++;break}}o[0]=new B(t[0],r),o[1]=new B(t[1],r),s=!0;break}}let l=r+1;if(s){let r=0,i=Int32Array.from([Math.trunc(o[0].getX()),Math.trunc(o[1].getX())]);for(;l<t;l++){let t=Kt.findGuardPattern(e,i[0],l,n,!1,a,c);if(t!=null&&Math.abs(i[0]-t[0])<Kt.MAX_PATTERN_DRIFT&&Math.abs(i[1]-t[1])<Kt.MAX_PATTERN_DRIFT)i=t,r=0;else if(r>Kt.SKIPPED_ROW_COUNT_MAX)break;else r++}l-=r+1,o[2]=new B(i[0],l),o[3]=new B(i[1],l)}return l-r<Kt.BARCODE_MIN_HEIGHT&&g.fill(o,null),o}static findGuardPattern(e,t,n,r,i,a,o){g.fillWithin(o,0,o.length,0);let s=t,c=0;for(;e.get(s,n)&&s>0&&c++<Kt.MAX_PIXEL_DRIFT;)s--;let l=s,u=0,d=a.length;for(let t=i;l<r;l++)if(e.get(l,n)!==t)o[u]++;else{if(u===d-1){if(Kt.patternMatchVariance(o,a,Kt.MAX_INDIVIDUAL_VARIANCE)<Kt.MAX_AVG_VARIANCE)return new Int32Array([s,l]);s+=o[0]+o[1],p.arraycopy(o,2,o,0,u-1),o[u-1]=0,o[u]=0,u--}else u++;o[u]=1,t=!t}return u===d-1&&Kt.patternMatchVariance(o,a,Kt.MAX_INDIVIDUAL_VARIANCE)<Kt.MAX_AVG_VARIANCE?new Int32Array([s,l-1]):null}static patternMatchVariance(e,t,n){let r=e.length,i=0,a=0;for(let n=0;n<r;n++)i+=e[n],a+=t[n];if(i<a)return 1/0;let o=i/a;n*=o;let s=0;for(let i=0;i<r;i++){let r=e[i],a=t[i]*o,c=r>a?r-a:a-r;if(c>n)return 1/0;s+=c}return s/i}}Kt.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),Kt.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),Kt.MAX_AVG_VARIANCE=.42,Kt.MAX_INDIVIDUAL_VARIANCE=.8,Kt.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),Kt.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),Kt.MAX_PIXEL_DRIFT=3,Kt.MAX_PATTERN_DRIFT=5,Kt.SKIPPED_ROW_COUNT_MAX=25,Kt.ROW_STEP=5,Kt.BARCODE_MIN_HEIGHT=10;class qt{constructor(e,t){if(t.length===0)throw new l;this.field=e;let n=t.length;if(n>1&&t[0]===0){let e=1;for(;e<n&&t[e]===0;)e++;e===n?this.coefficients=new Int32Array([0]):(this.coefficients=new Int32Array(n-e),p.arraycopy(t,e,this.coefficients,0,this.coefficients.length))}else this.coefficients=t}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);if(e===1){let e=0;for(let t of this.coefficients)e=this.field.add(e,t);return e}let t=this.coefficients[0],n=this.coefficients.length;for(let r=1;r<n;r++)t=this.field.add(this.field.multiply(e,t),this.coefficients[r]);return t}add(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);if(this.isZero())return e;if(e.isZero())return this;let t=this.coefficients,n=e.coefficients;if(t.length>n.length){let e=t;t=n,n=e}let r=new Int32Array(n.length),i=n.length-t.length;p.arraycopy(n,0,r,0,i);for(let e=i;e<n.length;e++)r[e]=this.field.add(t[e-i],n[e]);return new qt(this.field,r)}subtract(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);return e.isZero()?this:this.add(e.negative())}multiply(e){return e instanceof qt?this.multiplyOther(e):this.multiplyScalar(e)}multiplyOther(e){if(!this.field.equals(e.field))throw new l(`ModulusPolys do not have same ModulusGF field`);if(this.isZero()||e.isZero())return new qt(this.field,new Int32Array([0]));let t=this.coefficients,n=t.length,r=e.coefficients,i=r.length,a=new Int32Array(n+i-1);for(let e=0;e<n;e++){let n=t[e];for(let t=0;t<i;t++)a[e+t]=this.field.add(a[e+t],this.field.multiply(n,r[t]))}return new qt(this.field,a)}negative(){let e=this.coefficients.length,t=new Int32Array(e);for(let n=0;n<e;n++)t[n]=this.field.subtract(0,this.coefficients[n]);return new qt(this.field,t)}multiplyScalar(e){if(e===0)return new qt(this.field,new Int32Array([0]));if(e===1)return this;let t=this.coefficients.length,n=new Int32Array(t);for(let r=0;r<t;r++)n[r]=this.field.multiply(this.coefficients[r],e);return new qt(this.field,n)}multiplyByMonomial(e,t){if(e<0)throw new l;if(t===0)return new qt(this.field,new Int32Array([0]));let n=this.coefficients.length,r=new Int32Array(n+e);for(let e=0;e<n;e++)r[e]=this.field.multiply(this.coefficients[e],t);return new qt(this.field,r)}toString(){let e=new D;for(let t=this.getDegree();t>=0;t--){let n=this.getCoefficient(t);n!==0&&(n<0?(e.append(` - `),n=-n):e.length()>0&&e.append(` + `),(t===0||n!==1)&&e.append(n),t!==0&&(t===1?e.append(`x`):(e.append(`x^`),e.append(t))))}return e.toString()}}class Jt{add(e,t){return(e+t)%this.modulus}subtract(e,t){return(this.modulus+e-t)%this.modulus}exp(e){return this.expTable[e]}log(e){if(e===0)throw new l;return this.logTable[e]}inverse(e){if(e===0)throw new oe;return this.expTable[this.modulus-this.logTable[e]-1]}multiply(e,t){return e===0||t===0?0:this.expTable[(this.logTable[e]+this.logTable[t])%(this.modulus-1)]}getSize(){return this.modulus}equals(e){return e===this}}class Yt extends Jt{constructor(e,t){super(),this.modulus=e,this.expTable=new Int32Array(e),this.logTable=new Int32Array(e);let n=1;for(let r=0;r<e;r++)this.expTable[r]=n,n=n*t%e;for(let t=0;t<e-1;t++)this.logTable[this.expTable[t]]=t;this.zero=new qt(this,new Int32Array([0])),this.one=new qt(this,new Int32Array([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,t){if(e<0)throw new l;if(t===0)return this.zero;let n=new Int32Array(e+1);return n[0]=t,new qt(this,n)}}Yt.PDF417_GF=new Yt(q.NUMBER_OF_CODEWORDS,3);class Xt{constructor(){this.field=Yt.PDF417_GF}decode(e,t,n){let r=new qt(this.field,e),i=new Int32Array(t),a=!1;for(let e=t;e>0;e--){let n=r.evaluateAt(this.field.exp(e));i[t-e]=n,n!==0&&(a=!0)}if(!a)return 0;let o=this.field.getOne();if(n!=null)for(let t of n){let n=this.field.exp(e.length-1-t),r=new qt(this.field,new Int32Array([this.field.subtract(0,n),1]));o=o.multiply(r)}let s=new qt(this.field,i),c=this.runEuclideanAlgorithm(this.field.buildMonomial(t,1),s,t),l=c[0],u=c[1],f=this.findErrorLocations(l),p=this.findErrorMagnitudes(u,l,f);for(let t=0;t<f.length;t++){let n=e.length-1-this.field.log(f[t]);if(n<0)throw d.getChecksumInstance();e[n]=this.field.subtract(e[n],p[t])}return f.length}runEuclideanAlgorithm(e,t,n){if(e.getDegree()<t.getDegree()){let n=e;e=t,t=n}let r=e,i=t,a=this.field.getZero(),o=this.field.getOne();for(;i.getDegree()>=Math.round(n/2);){let e=r,t=a;if(r=i,a=o,r.isZero())throw d.getChecksumInstance();i=e;let n=this.field.getZero(),s=r.getCoefficient(r.getDegree()),c=this.field.inverse(s);for(;i.getDegree()>=r.getDegree()&&!i.isZero();){let e=i.getDegree()-r.getDegree(),t=this.field.multiply(i.getCoefficient(i.getDegree()),c);n=n.add(this.field.buildMonomial(e,t)),i=i.subtract(r.multiplyByMonomial(e,t))}o=n.multiply(a).subtract(t).negative()}let s=o.getCoefficient(0);if(s===0)throw d.getChecksumInstance();let c=this.field.inverse(s);return[o.multiply(c),i.multiply(c)]}findErrorLocations(e){let t=e.getDegree(),n=new Int32Array(t),r=0;for(let i=1;i<this.field.getSize()&&r<t;i++)e.evaluateAt(i)===0&&(n[r]=this.field.inverse(i),r++);if(r!==t)throw d.getChecksumInstance();return n}findErrorMagnitudes(e,t,n){let r=t.getDegree(),i=new Int32Array(r);for(let e=1;e<=r;e++)i[r-e]=this.field.multiply(e,t.getCoefficient(e));let a=new qt(this.field,i),o=n.length,s=new Int32Array(o);for(let t=0;t<o;t++){let r=this.field.inverse(n[t]),i=this.field.subtract(0,e.evaluateAt(r)),o=this.field.inverse(a.evaluateAt(r));s[t]=this.field.multiply(i,o)}return s}}class Zt{constructor(e,t,n,r,i){e instanceof Zt?this.constructor_2(e):this.constructor_1(e,t,n,r,i)}constructor_1(e,t,n,r,i){let a=t==null||n==null,o=r==null||i==null;if(a&&o)throw new k;a?(t=new B(0,r.getY()),n=new B(0,i.getY())):o&&(r=new B(e.getWidth()-1,t.getY()),i=new B(e.getWidth()-1,n.getY())),this.image=e,this.topLeft=t,this.bottomLeft=n,this.topRight=r,this.bottomRight=i,this.minX=Math.trunc(Math.min(t.getX(),n.getX())),this.maxX=Math.trunc(Math.max(r.getX(),i.getX())),this.minY=Math.trunc(Math.min(t.getY(),r.getY())),this.maxY=Math.trunc(Math.max(n.getY(),i.getY()))}constructor_2(e){this.image=e.image,this.topLeft=e.getTopLeft(),this.bottomLeft=e.getBottomLeft(),this.topRight=e.getTopRight(),this.bottomRight=e.getBottomRight(),this.minX=e.getMinX(),this.maxX=e.getMaxX(),this.minY=e.getMinY(),this.maxY=e.getMaxY()}static merge(e,t){return e==null?t:t==null?e:new Zt(e.image,e.topLeft,e.bottomLeft,t.topRight,t.bottomRight)}addMissingRows(e,t,n){let r=this.topLeft,i=this.bottomLeft,a=this.topRight,o=this.bottomRight;if(e>0){let t=n?this.topLeft:this.topRight,i=Math.trunc(t.getY()-e);i<0&&(i=0);let o=new B(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 B(e.getX(),r);n?i=a:o=a}return new Zt(this.image,r,i,a,o)}getMinX(){return this.minX}getMaxX(){return this.maxX}getMinY(){return this.minY}getMaxY(){return this.maxY}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}getBottomLeft(){return this.bottomLeft}getBottomRight(){return this.bottomRight}}class Qt{constructor(e,t,n,r){this.columnCount=e,this.errorCorrectionLevel=r,this.rowCountUpperPart=t,this.rowCountLowerPart=n,this.rowCount=t+n}getColumnCount(){return this.columnCount}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getRowCount(){return this.rowCount}getRowCountUpperPart(){return this.rowCountUpperPart}getRowCountLowerPart(){return this.rowCountLowerPart}}class $t{constructor(){this.buffer=``}static form(e,t){let n=-1;function r(e,r,i,a,o,s){if(e===`%%`)return`%`;if(t[++n]===void 0)return;e=a?parseInt(a.substr(1)):void 0;let c=o?parseInt(o.substr(1)):void 0,l;switch(s){case`s`:l=t[n];break;case`c`:l=t[n][0];break;case`f`:l=parseFloat(t[n]).toFixed(e);break;case`p`:l=parseFloat(t[n]).toPrecision(e);break;case`e`:l=parseFloat(t[n]).toExponential(e);break;case`x`:l=parseInt(t[n]).toString(c||16);break;case`d`:l=parseFloat(parseInt(t[n],c||10).toPrecision(e)).toFixed(0);break}l=typeof l==`object`?JSON.stringify(l):(+l).toString(c);let u=parseInt(i),d=i&&i[0]+``==`0`?`0`:` `;for(;l.length<u;)l=r===void 0?d+l:l+d;return l}return e.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,r)}format(e,...t){this.buffer+=$t.form(e,t)}toString(){return this.buffer}}class en{constructor(e){this.boundingBox=new Zt(e),this.codewords=Array(e.getMaxY()-e.getMinY()+1)}getCodewordNearby(e){let t=this.getCodeword(e);if(t!=null)return t;for(let n=1;n<en.MAX_NEARBY_DISTANCE;n++){let r=this.imageRowToCodewordIndex(e)-n;if(r>=0&&(t=this.codewords[r],t!=null)||(r=this.imageRowToCodewordIndex(e)+n,r<this.codewords.length&&(t=this.codewords[r],t!=null)))return t}return null}imageRowToCodewordIndex(e){return e-this.boundingBox.getMinY()}setCodeword(e,t){this.codewords[this.imageRowToCodewordIndex(e)]=t}getCodeword(e){return this.codewords[this.imageRowToCodewordIndex(e)]}getBoundingBox(){return this.boundingBox}getCodewords(){return this.codewords}toString(){let e=new $t,t=0;for(let n of this.codewords){if(n==null){e.format(`%3d: | %n`,t++);continue}e.format(`%3d: %3d|%3d%n`,t++,n.getRowNumber(),n.getValue())}return e.toString()}}en.MAX_NEARBY_DISTANCE=5;class tn{constructor(){this.values=new Map}setValue(e){e=Math.trunc(e);let t=this.values.get(e);t??=0,t++,this.values.set(e,t)}getValue(){let e=-1,t=[];for(let[n,r]of this.values.entries()){let i={getKey:()=>n,getValue:()=>r};i.getValue()>e?(e=i.getValue(),t=[],t.push(i.getKey())):i.getValue()===e&&t.push(i.getKey())}return q.toIntArray(t)}getConfidence(e){return this.values.get(e)}}class nn extends en{constructor(e,t){super(e),this._isLeft=t}setRowNumbers(){for(let e of this.getCodewords())e?.setRowNumberAsRowIndicatorColumn()}adjustCompleteIndicatorColumnRowNumbers(e){let t=this.getCodewords();this.setRowNumbers(),this.removeIncorrectCodewords(t,e);let n=this.getBoundingBox(),r=this._isLeft?n.getTopLeft():n.getTopRight(),i=this._isLeft?n.getBottomLeft():n.getBottomRight(),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.imageRowToCodewordIndex(Math.trunc(i.getY())),s=-1,c=1,l=0;for(let n=a;n<o;n++){if(t[n]==null)continue;let r=t[n],i=r.getRowNumber()-s;if(i===0)l++;else if(i===1)c=Math.max(c,l),l=1,s=r.getRowNumber();else if(i<0||r.getRowNumber()>=e.getRowCount()||i>n)t[n]=null;else{let e;e=c>2?(c-2)*i:i;let a=e>=n;for(let r=1;r<=e&&!a;r++)a=t[n-r]!=null;a?t[n]=null:(s=r.getRowNumber(),l=1)}}}getRowHeights(){let e=this.getBarcodeMetadata();if(e==null)return null;this.adjustIncompleteIndicatorColumnRowNumbers(e);let t=new Int32Array(e.getRowCount());for(let e of this.getCodewords())if(e!=null){let n=e.getRowNumber();if(n>=t.length)continue;t[n]++}return t}adjustIncompleteIndicatorColumnRowNumbers(e){let t=this.getBoundingBox(),n=this._isLeft?t.getTopLeft():t.getTopRight(),r=this._isLeft?t.getBottomLeft():t.getBottomRight(),i=this.imageRowToCodewordIndex(Math.trunc(n.getY())),a=this.imageRowToCodewordIndex(Math.trunc(r.getY())),o=this.getCodewords(),s=-1;for(let t=i;t<a;t++){if(o[t]==null)continue;let n=o[t];n.setRowNumberAsRowIndicatorColumn();let r=n.getRowNumber()-s;r===0||(r===1?s=n.getRowNumber():n.getRowNumber()>=e.getRowCount()?o[t]=null:s=n.getRowNumber())}}getBarcodeMetadata(){let e=this.getCodewords(),t=new tn,n=new tn,r=new tn,i=new tn;for(let a of e){if(a==null)continue;a.setRowNumberAsRowIndicatorColumn();let e=a.getValue()%30,o=a.getRowNumber();switch(this._isLeft||(o+=2),o%3){case 0:n.setValue(e*3+1);break;case 1:i.setValue(e/3),r.setValue(e%3);break;case 2:t.setValue(e+1);break}}if(t.getValue().length===0||n.getValue().length===0||r.getValue().length===0||i.getValue().length===0||t.getValue()[0]<1||n.getValue()[0]+r.getValue()[0]<q.MIN_ROWS_IN_BARCODE||n.getValue()[0]+r.getValue()[0]>q.MAX_ROWS_IN_BARCODE)return null;let a=new Qt(t.getValue()[0],n.getValue()[0],r.getValue()[0],i.getValue()[0]);return this.removeIncorrectCodewords(e,a),a}removeIncorrectCodewords(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(e[n]==null)continue;let i=r.getValue()%30,a=r.getRowNumber();if(a>t.getRowCount()){e[n]=null;continue}switch(this._isLeft||(a+=2),a%3){case 0:i*3+1!==t.getRowCountUpperPart()&&(e[n]=null);break;case 1:(Math.trunc(i/3)!==t.getErrorCorrectionLevel()||i%3!==t.getRowCountLowerPart())&&(e[n]=null);break;case 2:i+1!==t.getColumnCount()&&(e[n]=null);break}}}isLeft(){return this._isLeft}toString(){return`IsLeft: `+this._isLeft+`
|
|
72
|
+
`+super.toString()}}class rn{constructor(e,t){this.ADJUST_ROW_NUMBER_SKIP=2,this.barcodeMetadata=e,this.barcodeColumnCount=e.getColumnCount(),this.boundingBox=t,this.detectionResultColumns=Array(this.barcodeColumnCount+2)}getDetectionResultColumns(){this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[0]),this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[this.barcodeColumnCount+1]);let e=q.MAX_CODEWORDS_IN_BARCODE,t;do t=e,e=this.adjustRowNumbersAndGetCount();while(e>0&&e<t);return this.detectionResultColumns}adjustIndicatorColumnRowNumbers(e){e?.adjustCompleteIndicatorColumnRowNumbers(this.barcodeMetadata)}adjustRowNumbersAndGetCount(){let e=this.adjustRowNumbersByRow();if(e===0)return 0;for(let e=1;e<this.barcodeColumnCount+1;e++){let t=this.detectionResultColumns[e].getCodewords();for(let n=0;n<t.length;n++)t[n]!=null&&(t[n].hasValidRowNumber()||this.adjustRowNumbers(e,n,t))}return e}adjustRowNumbersByRow(){return this.adjustRowNumbersFromBothRI(),this.adjustRowNumbersFromLRI()+this.adjustRowNumbersFromRRI()}adjustRowNumbersFromBothRI(){if(this.detectionResultColumns[0]==null||this.detectionResultColumns[this.barcodeColumnCount+1]==null)return;let e=this.detectionResultColumns[0].getCodewords(),t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<e.length;n++)if(e[n]!=null&&t[n]!=null&&e[n].getRowNumber()===t[n].getRowNumber())for(let t=1;t<=this.barcodeColumnCount;t++){let r=this.detectionResultColumns[t].getCodewords()[n];r!=null&&(r.setRowNumber(e[n].getRowNumber()),r.hasValidRowNumber()||(this.detectionResultColumns[t].getCodewords()[n]=null))}}adjustRowNumbersFromRRI(){if(this.detectionResultColumns[this.barcodeColumnCount+1]==null)return 0;let e=0,t=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=this.barcodeColumnCount+1;t>0&&i<this.ADJUST_ROW_NUMBER_SKIP;t--){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=rn.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}adjustRowNumbersFromLRI(){if(this.detectionResultColumns[0]==null)return 0;let e=0,t=this.detectionResultColumns[0].getCodewords();for(let n=0;n<t.length;n++){if(t[n]==null)continue;let r=t[n].getRowNumber(),i=0;for(let t=1;t<this.barcodeColumnCount+1&&i<this.ADJUST_ROW_NUMBER_SKIP;t++){let a=this.detectionResultColumns[t].getCodewords()[n];a!=null&&(i=rn.adjustRowNumberIfValid(r,i,a),a.hasValidRowNumber()||e++)}}return e}static adjustRowNumberIfValid(e,t,n){return n==null||n.hasValidRowNumber()||(n.isValidRowNumber(e)?(n.setRowNumber(e),t=0):++t),t}adjustRowNumbers(e,t,n){if(!this.detectionResultColumns[e-1])return;let r=n[t],i=this.detectionResultColumns[e-1].getCodewords(),a=i;this.detectionResultColumns[e+1]!=null&&(a=this.detectionResultColumns[e+1].getCodewords());let o=Array(14);o[2]=i[t],o[3]=a[t],t>0&&(o[0]=n[t-1],o[4]=i[t-1],o[5]=a[t-1]),t>1&&(o[8]=n[t-2],o[10]=i[t-2],o[11]=a[t-2]),t<n.length-1&&(o[1]=n[t+1],o[6]=i[t+1],o[7]=a[t+1]),t<n.length-2&&(o[9]=n[t+2],o[12]=i[t+2],o[13]=a[t+2]);for(let e of o)if(rn.adjustRowNumber(r,e))return}static adjustRowNumber(e,t){return t==null?!1:t.hasValidRowNumber()&&t.getBucket()===e.getBucket()?(e.setRowNumber(t.getRowNumber()),!0):!1}getBarcodeColumnCount(){return this.barcodeColumnCount}getBarcodeRowCount(){return this.barcodeMetadata.getRowCount()}getBarcodeECLevel(){return this.barcodeMetadata.getErrorCorrectionLevel()}setBoundingBox(e){this.boundingBox=e}getBoundingBox(){return this.boundingBox}setDetectionResultColumn(e,t){this.detectionResultColumns[e]=t}getDetectionResultColumn(e){return this.detectionResultColumns[e]}toString(){let e=this.detectionResultColumns[0];e??=this.detectionResultColumns[this.barcodeColumnCount+1];let t=new $t;for(let n=0;n<e.getCodewords().length;n++){t.format(`CW %3d:`,n);for(let e=0;e<this.barcodeColumnCount+2;e++){if(this.detectionResultColumns[e]==null){t.format(` | `);continue}let r=this.detectionResultColumns[e].getCodewords()[n];if(r==null){t.format(` | `);continue}t.format(` %3d|%3d`,r.getRowNumber(),r.getValue())}t.format(`%n`)}return t.toString()}}class an{constructor(e,t,n,r){this.rowNumber=an.BARCODE_ROW_UNKNOWN,this.startX=Math.trunc(e),this.endX=Math.trunc(t),this.bucket=Math.trunc(n),this.value=Math.trunc(r)}hasValidRowNumber(){return this.isValidRowNumber(this.rowNumber)}isValidRowNumber(e){return e!==an.BARCODE_ROW_UNKNOWN&&this.bucket===e%3*3}setRowNumberAsRowIndicatorColumn(){this.rowNumber=Math.trunc(Math.trunc(this.value/30)*3+Math.trunc(this.bucket/3))}getWidth(){return this.endX-this.startX}getStartX(){return this.startX}getEndX(){return this.endX}getBucket(){return this.bucket}getValue(){return this.value}getRowNumber(){return this.rowNumber}setRowNumber(e){this.rowNumber=e}toString(){return this.rowNumber+`|`+this.value}}an.BARCODE_ROW_UNKNOWN=-1;class on{static initialize(){for(let e=0;e<q.SYMBOL_TABLE.length;e++){let t=q.SYMBOL_TABLE[e],n=t&1;for(let r=0;r<q.BARS_IN_MODULE;r++){let i=0;for(;(t&1)===n;)i+=1,t>>=1;n=t&1,on.RATIOS_TABLE[e]||(on.RATIOS_TABLE[e]=Array(q.BARS_IN_MODULE)),on.RATIOS_TABLE[e][q.BARS_IN_MODULE-r-1]=Math.fround(i/q.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let t=on.getDecodedCodewordValue(on.sampleBitCounts(e));return t===-1?on.getClosestDecodedValue(e):t}static sampleBitCounts(e){let t=pe.sum(e),n=new Int32Array(q.BARS_IN_MODULE),r=0,i=0;for(let a=0;a<q.MODULES_IN_CODEWORD;a++){let o=t/(2*q.MODULES_IN_CODEWORD)+a*t/q.MODULES_IN_CODEWORD;i+e[r]<=o&&(i+=e[r],r++),n[r]++}return n}static getDecodedCodewordValue(e){let t=on.getBitValue(e);return q.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=pe.sum(e),n=Array(q.BARS_IN_MODULE);if(t>1)for(let r=0;r<n.length;r++)n[r]=Math.fround(e[r]/t);let r=me.MAX_VALUE,i=-1;this.bSymbolTableReady||on.initialize();for(let e=0;e<on.RATIOS_TABLE.length;e++){let t=0,a=on.RATIOS_TABLE[e];for(let e=0;e<q.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=q.SYMBOL_TABLE[e])}return i}}on.bSymbolTableReady=!1,on.RATIOS_TABLE=Array(q.SYMBOL_TABLE.length).map(e=>e=Array(q.BARS_IN_MODULE));class sn{constructor(){this.segmentCount=-1,this.fileSize=-1,this.timestamp=-1,this.checksum=-1}getSegmentIndex(){return this.segmentIndex}setSegmentIndex(e){this.segmentIndex=e}getFileId(){return this.fileId}setFileId(e){this.fileId=e}getOptionalData(){return this.optionalData}setOptionalData(e){this.optionalData=e}isLastSegment(){return this.lastSegment}setLastSegment(e){this.lastSegment=e}getSegmentCount(){return this.segmentCount}setSegmentCount(e){this.segmentCount=e}getSender(){return this.sender||null}setSender(e){this.sender=e}getAddressee(){return this.addressee||null}setAddressee(e){this.addressee=e}getFileName(){return this.fileName}setFileName(e){this.fileName=e}getFileSize(){return this.fileSize}setFileSize(e){this.fileSize=e}getChecksum(){return this.checksum}setChecksum(e){this.checksum=e}getTimestamp(){return this.timestamp}setTimestamp(e){this.timestamp=e}}class cn{static parseLong(e,t=void 0){return parseInt(e,t)}}class ln extends s{}ln.kind=`NullPointerException`;class un{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,t,n){if(e==null)throw new ln;if(t<0||t>e.length||n<0||t+n>e.length||t+n<0)throw new m;if(n!==0)for(let r=0;r<n;r++)this.write(e[t+r])}flush(){}close(){}}class dn extends s{}class fn extends un{constructor(e=32){if(super(),this.count=0,e<0)throw new l(`Negative initial size: `+e);this.buf=new Uint8Array(e)}ensureCapacity(e){e-this.buf.length>0&&this.grow(e)}grow(e){let t=this.buf.length<<1;if(t-e<0&&(t=e),t<0){if(e<0)throw new dn;t=_.MAX_VALUE}this.buf=g.copyOfUint8Array(this.buf,t)}write(e){this.ensureCapacity(this.count+1),this.buf[this.count]=e,this.count+=1}writeBytesOffset(e,t,n){if(t<0||t>e.length||n<0||t+n-e.length>0)throw new m;this.ensureCapacity(this.count+n),p.arraycopy(e,t,this.buf,this.count,n),this.count+=n}writeTo(e){e.writeBytesOffset(this.buf,0,this.count)}reset(){this.count=0}toByteArray(){return g.copyOfUint8Array(this.buf,this.count)}size(){return this.count}toString(e){return e?typeof e==`string`?this.toString_string(e):this.toString_number(e):this.toString_void()}toString_void(){return new String(this.buf).toString()}toString_string(e){return new String(this.buf).toString()}toString_number(e){return new String(this.buf).toString()}close(){}}var pn;(function(e){e[e.ALPHA=0]=`ALPHA`,e[e.LOWER=1]=`LOWER`,e[e.MIXED=2]=`MIXED`,e[e.PUNCT=3]=`PUNCT`,e[e.ALPHA_SHIFT=4]=`ALPHA_SHIFT`,e[e.PUNCT_SHIFT=5]=`PUNCT_SHIFT`})(pn||={});function mn(){if(typeof window<`u`)return window.BigInt||null;if(typeof global<`u`)return global.BigInt||null;if(typeof self<`u`)return self.BigInt||null;throw Error(`Can't search globals for BigInt!`)}let hn;function gn(e){if(hn===void 0&&(hn=mn()),hn===null)throw Error(`BigInt is not supported!`);return hn(e)}function _n(){let e=[];e[0]=gn(1);let t=gn(900);e[1]=t;for(let n=2;n<16;n++)e[n]=e[n-1]*t;return e}class J{static decode(e,t){let n=new D(``),r=C.ISO8859_1;n.enableDecoding(r);let i=1,a=e[i++],o=new sn;for(;i<e[0];){switch(a){case J.TEXT_COMPACTION_MODE_LATCH:i=J.textCompaction(e,i,n);break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:i=J.byteCompaction(a,e,r,i,n);break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:n.append(e[i++]);break;case J.NUMERIC_COMPACTION_MODE_LATCH:i=J.numericCompaction(e,i,n);break;case J.ECI_CHARSET:C.getCharacterSetECIByValue(e[i++]);break;case J.ECI_GENERAL_PURPOSE:i+=2;break;case J.ECI_USER_DEFINED:i++;break;case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:i=J.decodeMacroBlock(e,i,o);break;case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:throw new x;default:i--,i=J.textCompaction(e,i,n);break}if(i<e.length)a=e[i++];else throw x.getFormatInstance()}if(n.length()===0)throw x.getFormatInstance();let s=new re(null,n.toString(),null,t);return s.setOther(o),s}static decodeMacroBlock(e,t,n){if(t+J.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw x.getFormatInstance();let r=new Int32Array(J.NUMBER_OF_SEQUENCE_CODEWORDS);for(let n=0;n<J.NUMBER_OF_SEQUENCE_CODEWORDS;n++,t++)r[n]=e[t];n.setSegmentIndex(_.parseInt(J.decodeBase900toBase10(r,J.NUMBER_OF_SEQUENCE_CODEWORDS)));let i=new D;t=J.textCompaction(e,t,i),n.setFileId(i.toString());let a=-1;for(e[t]===J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(a=t+1);t<e[0];)switch(e[t]){case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(t++,e[t]){case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let r=new D;t=J.textCompaction(e,t+1,r),n.setFileName(r.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let i=new D;t=J.textCompaction(e,t+1,i),n.setSender(i.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let a=new D;t=J.textCompaction(e,t+1,a),n.setAddressee(a.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let o=new D;t=J.numericCompaction(e,t+1,o),n.setSegmentCount(_.parseInt(o.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let s=new D;t=J.numericCompaction(e,t+1,s),n.setTimestamp(cn.parseLong(s.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let c=new D;t=J.numericCompaction(e,t+1,c),n.setChecksum(_.parseInt(c.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let l=new D;t=J.numericCompaction(e,t+1,l),n.setFileSize(cn.parseLong(l.toString()));break;default:throw x.getFormatInstance()}break;case J.MACRO_PDF417_TERMINATOR:t++,n.setLastSegment(!0);break;default:throw x.getFormatInstance()}if(a!==-1){let r=t-a;n.isLastSegment()&&r--,n.setOptionalData(g.copyOfRange(e,a,a+r))}return t}static textCompaction(e,t,n){let r=new Int32Array((e[0]-t)*2),i=new Int32Array((e[0]-t)*2),a=0,o=!1;for(;t<e[0]&&!o;){let n=e[t++];if(n<J.TEXT_COMPACTION_MODE_LATCH)r[a]=n/30,r[a+1]=n%30,a+=2;else switch(n){case J.TEXT_COMPACTION_MODE_LATCH:r[a++]=J.TEXT_COMPACTION_MODE_LATCH;break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:t--,o=!0;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r[a]=J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,n=e[t++],i[a]=n,a++;break}}return J.decodeTextCompaction(r,i,a,n),t}static decodeTextCompaction(e,t,n,r){let i=pn.ALPHA,a=pn.ALPHA,o=0;for(;o<n;){let n=e[o],s=``;switch(i){case pn.ALPHA:if(n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case J.LL:i=pn.LOWER;break;case J.ML:i=pn.MIXED;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.LOWER:if(n<26)s=String.fromCharCode(97+n);else switch(n){case 26:s=` `;break;case J.AS:a=i,i=pn.ALPHA_SHIFT;break;case J.ML:i=pn.MIXED;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.MIXED:if(n<J.PL)s=J.MIXED_CHARS[n];else switch(n){case J.PL:i=pn.PUNCT;break;case 26:s=` `;break;case J.LL:i=pn.LOWER;break;case J.AL:i=pn.ALPHA;break;case J.PS:a=i,i=pn.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.PUNCT:if(n<J.PAL)s=J.PUNCT_CHARS[n];else switch(n){case J.PAL:i=pn.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.ALPHA_SHIFT:if(i=a,n<26)s=String.fromCharCode(65+n);else switch(n){case 26:s=` `;break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break;case pn.PUNCT_SHIFT:if(i=a,n<J.PAL)s=J.PUNCT_CHARS[n];else switch(n){case J.PAL:i=pn.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:r.append(t[o]);break;case J.TEXT_COMPACTION_MODE_LATCH:i=pn.ALPHA;break}break}s!==``&&r.append(s),o++}}static byteCompaction(e,t,n,r,i){let a=new fn,o=0,s=0,c=!1;switch(e){case J.BYTE_COMPACTION_MODE_LATCH:let e=new Int32Array(6),n=t[r++];for(;r<t[0]&&!c;)switch(e[o++]=n,s=900*s+n,n=t[r++],n){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:r--,c=!0;break;default:if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(gn(s)>>gn(8*(5-e))));s=0,o=0}break}r===t[0]&&n<J.TEXT_COMPACTION_MODE_LATCH&&(e[o++]=n);for(let t=0;t<o;t++)a.write(e[t]);break;case J.BYTE_COMPACTION_MODE_LATCH_6:for(;r<t[0]&&!c;){let e=t[r++];if(e<J.TEXT_COMPACTION_MODE_LATCH)o++,s=900*s+e;else switch(e){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:r--,c=!0;break}if(o%5==0&&o>0){for(let e=0;e<6;++e)a.write(Number(gn(s)>>gn(8*(5-e))));s=0,o=0}}break}return i.append(T.decode(a.toByteArray(),n)),r}static numericCompaction(e,t,n){let r=0,i=!1,a=new Int32Array(J.MAX_NUMERIC_CODEWORDS);for(;t<e[0]&&!i;){let o=e[t++];if(t===e[0]&&(i=!0),o<J.TEXT_COMPACTION_MODE_LATCH)a[r]=o,r++;else switch(o){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:t--,i=!0;break}(r%J.MAX_NUMERIC_CODEWORDS===0||o===J.NUMERIC_COMPACTION_MODE_LATCH||i)&&r>0&&(n.append(J.decodeBase900toBase10(a,r)),r=0)}return t}static decodeBase900toBase10(e,t){let n=gn(0);for(let r=0;r<t;r++)n+=J.EXP900[t-r-1]*gn(e[r]);let r=n.toString();if(r.charAt(0)!==`1`)throw new x;return r.substring(1)}}J.TEXT_COMPACTION_MODE_LATCH=900,J.BYTE_COMPACTION_MODE_LATCH=901,J.NUMERIC_COMPACTION_MODE_LATCH=902,J.BYTE_COMPACTION_MODE_LATCH_6=924,J.ECI_USER_DEFINED=925,J.ECI_GENERAL_PURPOSE=926,J.ECI_CHARSET=927,J.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,J.MACRO_PDF417_TERMINATOR=922,J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,J.MAX_NUMERIC_CODEWORDS=15,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,J.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,J.PL=25,J.LL=27,J.AS=27,J.ML=28,J.AL=28,J.PS=29,J.PAL=29,J.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
|
|
73
|
+
-.$/"|*()?{}'`,J.MIXED_CHARS=`0123456789&\r ,:#-.$/+%*=^`,J.EXP900=mn()?_n():[],J.NUMBER_OF_SEQUENCE_CODEWORDS=2;class vn{constructor(){}static decode(e,t,n,r,i,a,o){let s=new Zt(e,t,n,r,i),c=null,l=null,u;for(let n=!0;;n=!1){if(t!=null&&(c=vn.getRowIndicatorColumn(e,s,t,!0,a,o)),r!=null&&(l=vn.getRowIndicatorColumn(e,s,r,!1,a,o)),u=vn.merge(c,l),u==null)throw k.getNotFoundInstance();let i=u.getBoundingBox();if(n&&i!=null&&(i.getMinY()<s.getMinY()||i.getMaxY()>s.getMaxY()))s=i;else break}u.setBoundingBox(s);let d=u.getBarcodeColumnCount()+1;u.setDetectionResultColumn(0,c),u.setDetectionResultColumn(d,l);let f=c!=null;for(let t=1;t<=d;t++){let n=f?t:d-t;if(u.getDetectionResultColumn(n)!==void 0)continue;let r;r=n===0||n===d?new nn(s,n===0):new en(s),u.setDetectionResultColumn(n,r);let i=-1,c=i;for(let t=s.getMinY();t<=s.getMaxY();t++){if(i=vn.getStartColumn(u,n,t,f),i<0||i>s.getMaxX()){if(c===-1)continue;i=c}let l=vn.detectCodeword(e,s.getMinX(),s.getMaxX(),f,i,t,a,o);l!=null&&(r.setCodeword(t,l),c=i,a=Math.min(a,l.getWidth()),o=Math.max(o,l.getWidth()))}}return vn.createDecoderResult(u)}static merge(e,t){if(e==null&&t==null)return null;let n=vn.getBarcodeMetadata(e,t);return n==null?null:new rn(n,Zt.merge(vn.adjustBoundingBox(e),vn.adjustBoundingBox(t)))}static adjustBoundingBox(e){if(e==null)return null;let t=e.getRowHeights();if(t==null)return null;let n=vn.getMax(t),r=0;for(let e of t)if(r+=n-e,e>0)break;let i=e.getCodewords();for(let e=0;r>0&&i[e]==null;e++)r--;let a=0;for(let e=t.length-1;e>=0&&(a+=n-t[e],!(t[e]>0));e--);for(let e=i.length-1;a>0&&i[e]==null;e--)a--;return e.getBoundingBox().addMissingRows(r,a,e.isLeft())}static getMax(e){let t=-1;for(let n of e)t=Math.max(t,n);return t}static getBarcodeMetadata(e,t){let n;if(e==null||(n=e.getBarcodeMetadata())==null)return t==null?null:t.getBarcodeMetadata();let r;return t==null||(r=t.getBarcodeMetadata())==null?n:n.getColumnCount()!==r.getColumnCount()&&n.getErrorCorrectionLevel()!==r.getErrorCorrectionLevel()&&n.getRowCount()!==r.getRowCount()?null:n}static getRowIndicatorColumn(e,t,n,r,i,a){let o=new nn(t,r);for(let s=0;s<2;s++){let c=s===0?1:-1,l=Math.trunc(Math.trunc(n.getX()));for(let s=Math.trunc(Math.trunc(n.getY()));s<=t.getMaxY()&&s>=t.getMinY();s+=c){let t=vn.detectCodeword(e,0,e.getWidth(),r,l,s,i,a);t!=null&&(o.setCodeword(s,t),l=r?t.getStartX():t.getEndX())}}return o}static adjustCodewordCount(e,t){let n=t[0][1],r=n.getValue(),i=e.getBarcodeColumnCount()*e.getBarcodeRowCount()-vn.getNumberOfECCodeWords(e.getBarcodeECLevel());if(r.length===0){if(i<1||i>q.MAX_CODEWORDS_IN_BARCODE)throw k.getNotFoundInstance();n.setValue(i)}else r[0]!==i&&n.setValue(i)}static createDecoderResult(e){let t=vn.createBarcodeMatrix(e);vn.adjustCodewordCount(e,t);let n=[],r=new Int32Array(e.getBarcodeRowCount()*e.getBarcodeColumnCount()),i=[],a=[];for(let o=0;o<e.getBarcodeRowCount();o++)for(let s=0;s<e.getBarcodeColumnCount();s++){let c=t[o][s+1].getValue(),l=o*e.getBarcodeColumnCount()+s;c.length===0?n.push(l):c.length===1?r[l]=c[0]:(a.push(l),i.push(c))}let o=Array(i.length);for(let e=0;e<o.length;e++)o[e]=i[e];return vn.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),r,q.toIntArray(n),q.toIntArray(a),o)}static createDecoderResultFromAmbiguousValues(e,t,n,r,i){let a=new Int32Array(r.length),o=100;for(;o-- >0;){for(let e=0;e<a.length;e++)t[r[e]]=i[e][a[e]];try{return vn.decodeCodewords(t,e,n)}catch(e){if(!(e instanceof d))throw e}if(a.length===0)throw d.getChecksumInstance();for(let e=0;e<a.length;e++)if(a[e]<i[e].length-1){a[e]++;break}else if(a[e]=0,e===a.length-1)throw d.getChecksumInstance()}throw d.getChecksumInstance()}static createBarcodeMatrix(e){let t=Array.from({length:e.getBarcodeRowCount()},()=>Array(e.getBarcodeColumnCount()+2));for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length;n++)t[e][n]=new tn;let n=0;for(let r of e.getDetectionResultColumns()){if(r!=null){for(let e of r.getCodewords())if(e!=null){let r=e.getRowNumber();if(r>=0){if(r>=t.length)continue;t[r][n].setValue(e.getValue())}}}n++}return t}static isValidBarcodeColumn(e,t){return t>=0&&t<=e.getBarcodeColumnCount()+1}static getStartColumn(e,t,n,r){let i=r?1:-1,a=null;if(vn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodeword(n)),a!=null)return r?a.getEndX():a.getStartX();if(a=e.getDetectionResultColumn(t).getCodewordNearby(n),a!=null)return r?a.getStartX():a.getEndX();if(vn.isValidBarcodeColumn(e,t-i)&&(a=e.getDetectionResultColumn(t-i).getCodewordNearby(n)),a!=null)return r?a.getEndX():a.getStartX();let o=0;for(;vn.isValidBarcodeColumn(e,t-i);){t-=i;for(let n of e.getDetectionResultColumn(t).getCodewords())if(n!=null)return(r?n.getEndX():n.getStartX())+i*o*(n.getEndX()-n.getStartX());o++}return r?e.getBoundingBox().getMinX():e.getBoundingBox().getMaxX()}static detectCodeword(e,t,n,r,i,a,o,s){i=vn.adjustCodewordStartColumn(e,t,n,r,i,a);let c=vn.getModuleBitCount(e,t,n,r,i,a);if(c==null)return null;let l,u=pe.sum(c);if(r)l=i+u;else{for(let e=0;e<c.length/2;e++){let t=c[e];c[e]=c[c.length-1-e],c[c.length-1-e]=t}l=i,i=l-u}if(!vn.checkCodewordSkew(u,o,s))return null;let d=on.getDecodedValue(c),f=q.getCodeword(d);return f===-1?null:new an(i,l,vn.getCodewordBucketNumber(d),f)}static getModuleBitCount(e,t,n,r,i,a){let o=i,s=new Int32Array(8),c=0,l=r?1:-1,u=r;for(;(r?o<n:o>=t)&&c<s.length;)e.get(o,a)===u?(s[c]++,o+=l):(c++,u=!u);return c===s.length||o===(r?n:t)&&c===s.length-1?s:null}static getNumberOfECCodeWords(e){return 2<<e}static adjustCodewordStartColumn(e,t,n,r,i,a){let o=i,s=r?-1:1;for(let c=0;c<2;c++){for(;(r?o>=t:o<n)&&r===e.get(o,a);){if(Math.abs(i-o)>vn.CODEWORD_SKEW_SIZE)return i;o+=s}s=-s,r=!r}return o}static checkCodewordSkew(e,t,n){return t-vn.CODEWORD_SKEW_SIZE<=e&&e<=n+vn.CODEWORD_SKEW_SIZE}static decodeCodewords(e,t,n){if(e.length===0)throw x.getFormatInstance();let r=1<<t+1,i=vn.correctErrors(e,n,r);vn.verifyCodewordCount(e,r);let a=J.decode(e,``+t);return a.setErrorsCorrected(i),a.setErasures(n.length),a}static correctErrors(e,t,n){if(t!=null&&t.length>n/2+vn.MAX_ERRORS||n<0||n>vn.MAX_EC_CODEWORDS)throw d.getChecksumInstance();return vn.errorCorrection.decode(e,n,t)}static verifyCodewordCount(e,t){if(e.length<4)throw x.getFormatInstance();let n=e[0];if(n>e.length)throw x.getFormatInstance();if(n===0)if(t<e.length)e[0]=e.length-t;else throw x.getFormatInstance()}static getBitCountForCodeword(e){let t=new Int32Array(8),n=0,r=t.length-1;for(;!((e&1)!==n&&(n=e&1,r--,r<0));)t[r]++,e>>=1;return t}static getCodewordBucketNumber(e){return e instanceof Int32Array?this.getCodewordBucketNumber_Int32Array(e):this.getCodewordBucketNumber_number(e)}static getCodewordBucketNumber_number(e){return vn.getCodewordBucketNumber(vn.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let t=new $t;for(let n=0;n<e.length;n++){t.format(`Row %2d: `,n);for(let r=0;r<e[n].length;r++){let i=e[n][r];i.getValue().length===0?t.format(` `,null):t.format(`%4d(%2d)`,i.getValue()[0],i.getConfidence(i.getValue()[0]))}t.format(`%n`)}return t.toString()}}vn.CODEWORD_SKEW_SIZE=2,vn.MAX_ERRORS=3,vn.MAX_EC_CODEWORDS=512,vn.errorCorrection=new Xt;class yn{decode(e,t=null){let n=yn.decode(e,t,!1);if(n==null||n.length===0||n[0]==null)throw k.getNotFoundInstance();return n[0]}decodeMultiple(e,t=null){try{return yn.decode(e,t,!0)}catch(e){throw e instanceof x||e instanceof d?k.getNotFoundInstance():e}}static decode(e,t,n){let r=[],i=Kt.detectMultiple(e,t,n);for(let e of i.getPoints()){let t=vn.decode(i.getBits(),e[4],e[5],e[6],e[7],yn.getMinCodewordWidth(e),yn.getMaxCodewordWidth(e)),n=new R(t.getText(),t.getRawBytes(),void 0,e,z.PDF_417);n.putMetadata(ne.ERROR_CORRECTION_LEVEL,t.getECLevel());let a=t.getOther();a!=null&&n.putMetadata(ne.PDF417_EXTRA_METADATA,a),r.push(n)}return r.map(e=>e)}static getMaxWidth(e,t){return e==null||t==null?0:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMinWidth(e,t){return e==null||t==null?_.MAX_VALUE:Math.trunc(Math.abs(e.getX()-t.getX()))}static getMaxCodewordWidth(e){return Math.floor(Math.max(Math.max(yn.getMaxWidth(e[0],e[4]),yn.getMaxWidth(e[6],e[2])*q.MODULES_IN_CODEWORD/q.MODULES_IN_STOP_PATTERN),Math.max(yn.getMaxWidth(e[1],e[5]),yn.getMaxWidth(e[7],e[3])*q.MODULES_IN_CODEWORD/q.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(yn.getMinWidth(e[0],e[4]),yn.getMinWidth(e[6],e[2])*q.MODULES_IN_CODEWORD/q.MODULES_IN_STOP_PATTERN),Math.min(yn.getMinWidth(e[1],e[5]),yn.getMinWidth(e[7],e[3])*q.MODULES_IN_CODEWORD/q.MODULES_IN_STOP_PATTERN)))}reset(){}}class bn extends s{}bn.kind=`ReaderException`;class xn{constructor(e,t){this.verbose=e===!0,t&&this.setHints(t)}decode(e,t){return t&&this.setHints(t),this.decodeInternal(e)}decodeWithState(e){return(this.readers===null||this.readers===void 0)&&this.setHints(null),this.decodeInternal(e)}setHints(e){this.hints=e;let n=!t(e)&&e.get(b.TRY_HARDER)===!0,r=t(e)?null:e.get(b.POSSIBLE_FORMATS),i=[];if(!t(r)){let t=r.some(e=>e===z.UPC_A||e===z.UPC_E||e===z.EAN_13||e===z.EAN_8||e===z.CODABAR||e===z.CODE_39||e===z.CODE_93||e===z.CODE_128||e===z.ITF||e===z.RSS_14||e===z.RSS_EXPANDED);t&&!n&&i.push(new ft(e,this.verbose)),r.includes(z.QR_CODE)&&i.push(new Wt),r.includes(z.DATA_MATRIX)&&i.push(new wt),r.includes(z.AZTEC)&&i.push(new we),r.includes(z.PDF_417)&&i.push(new yn),t&&n&&i.push(new ft(e,this.verbose))}i.length===0&&(n||i.push(new ft(e,this.verbose)),i.push(new Wt),i.push(new wt),i.push(new we),i.push(new yn),n&&i.push(new ft(e,this.verbose))),this.readers=i}reset(){if(this.readers!==null)for(let e of this.readers)e.reset()}decodeInternal(e){if(this.readers===null)throw new bn(`No readers where selected, nothing can be read.`);for(let t of this.readers)try{return t.decode(e,this.hints)}catch(e){if(e instanceof bn)continue}throw new k(`No MultiFormat Readers were able to detect the code.`)}}class Sn extends L{constructor(e=null,t=500){let n=new xn;n.setHints(e),super(n,t)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class Cn extends L{constructor(e=500){super(new yn,e)}}class wn extends L{constructor(e=500){super(new Wt,e)}}var Tn;(function(e){e[e.ERROR_CORRECTION=0]=`ERROR_CORRECTION`,e[e.CHARACTER_SET=1]=`CHARACTER_SET`,e[e.DATA_MATRIX_SHAPE=2]=`DATA_MATRIX_SHAPE`,e[e.MIN_SIZE=3]=`MIN_SIZE`,e[e.MAX_SIZE=4]=`MAX_SIZE`,e[e.MARGIN=5]=`MARGIN`,e[e.PDF417_COMPACT=6]=`PDF417_COMPACT`,e[e.PDF417_COMPACTION=7]=`PDF417_COMPACTION`,e[e.PDF417_DIMENSIONS=8]=`PDF417_DIMENSIONS`,e[e.AZTEC_LAYERS=9]=`AZTEC_LAYERS`,e[e.QR_VERSION=10]=`QR_VERSION`})(Tn||={});var En=Tn;class Dn{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new ae(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 ae(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 ae(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(`
|
|
74
|
+
`)}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(`<<
|
|
75
|
+
`),e.append(` mode: `),e.append(this.mode?this.mode.toString():`null`),e.append(`
|
|
76
|
+
ecLevel: `),e.append(this.ecLevel?this.ecLevel.toString():`null`),e.append(`
|
|
77
|
+
version: `),e.append(this.version?this.version.toString():`null`),e.append(`
|
|
78
|
+
maskPattern: `),e.append(this.maskPattern.toString()),this.matrix?(e.append(`
|
|
79
|
+
matrix:
|
|
80
|
+
`),e.append(this.matrix.toString())):e.append(`
|
|
81
|
+
matrix: null
|
|
82
|
+
`),e.append(`>>
|
|
83
|
+
`),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(se.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 le;let a=i.getWidth(),o=i.getHeight(),s=a+r*2,c=o+r*2,l=Math.max(t,s),u=Math.max(n,c),d=Math.min(Math.floor(l/s),Math.floor(u/c)),f=Math.floor((l-a*d)/2),p=Math.floor((u-o*d)/2),m=this.createSVGElement(l,u);for(let e=0,t=p;e<o;e++,t+=d)for(let n=0,r=f;n<a;n++,r+=d)if(i.get(n,e)===1){let e=this.createSvgRectElement(r,t,d,d);m.appendChild(e)}return m}createSVGElement(e,t){let n=document.createElementNS(Fn.SVG_NS,`svg`);return n.setAttributeNS(null,`height`,e.toString()),n.setAttributeNS(null,`width`,t.toString()),n}createSvgRectElement(e,t,n,r){let i=document.createElementNS(Fn.SVG_NS,`rect`);return i.setAttributeNS(null,`x`,e.toString()),i.setAttributeNS(null,`y`,t.toString()),i.setAttributeNS(null,`height`,n.toString()),i.setAttributeNS(null,`width`,r.toString()),i.setAttributeNS(null,`fill`,`#000000`),i}}Fn.QUIET_ZONE_SIZE=4,Fn.SVG_NS=`http://www.w3.org/2000/svg`;class In{encode(e,t,n,r,i){if(e.length===0)throw new l(`Found empty contents`);if(t!==z.QR_CODE)throw new l(`Can only encode QR_CODE, but got `+t);if(n<0||r<0)throw new l(`Requested dimensions are too small: ${n}x${r}`);let a=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 le;let a=i.getWidth(),o=i.getHeight(),s=a+r*2,c=o+r*2,l=Math.max(t,s),u=Math.max(n,c),d=Math.min(Math.floor(l/s),Math.floor(u/c)),f=Math.floor((l-a*d)/2),p=Math.floor((u-o*d)/2),m=new O(l,u);for(let e=0,t=p;e<o;e++,t+=d)for(let n=0,r=f;n<a;n++,r+=d)i.get(n,e)===1&&m.setRegion(r,t,d,d);return m}}In.QUIET_ZONE_SIZE=4;class Ln{encode(e,t,n,r,i){let a;switch(t){case z.QR_CODE:a=new In;break;default:throw new l(`No encoder available for format `+t)}return a.encode(e,t,n,r,i)}}class Rn extends M{constructor(e,t,n,r,i,a,o,s){if(super(a,o),this.yuvData=e,this.dataWidth=t,this.dataHeight=n,this.left=r,this.top=i,r+a>t||i+o>n)throw new l(`Crop rectangle does not fit within image data.`);s&&this.reverseHorizontal(a,o)}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth();(t==null||t.length<n)&&(t=new Uint8ClampedArray(n));let r=(e+this.top)*this.dataWidth+this.left;return p.arraycopy(this.yuvData,r,t,0,n),t}getMatrix(){let e=this.getWidth(),t=this.getHeight();if(e===this.dataWidth&&t===this.dataHeight)return this.yuvData;let n=e*t,r=new Uint8ClampedArray(n),i=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return p.arraycopy(this.yuvData,i,r,0,n),r;for(let n=0;n<t;n++){let t=n*e;p.arraycopy(this.yuvData,i,r,t,e),i+=this.dataWidth}return r}isCropSupported(){return!0}crop(e,t,n,r){return new Rn(this.yuvData,this.dataWidth,this.dataHeight,this.left+e,this.top+t,n,r,!1)}renderThumbnail(){let e=this.getWidth()/Rn.THUMBNAIL_SCALE_FACTOR,t=this.getHeight()/Rn.THUMBNAIL_SCALE_FACTOR,n=new Int32Array(e*t),r=this.yuvData,i=this.top*this.dataWidth+this.left;for(let a=0;a<t;a++){let t=a*e;for(let a=0;a<e;a++){let e=r[i+a*Rn.THUMBNAIL_SCALE_FACTOR]&255;n[t+a]=4278190080|e*65793}i+=this.dataWidth*Rn.THUMBNAIL_SCALE_FACTOR}return n}getThumbnailWidth(){return this.getWidth()/Rn.THUMBNAIL_SCALE_FACTOR}getThumbnailHeight(){return this.getHeight()/Rn.THUMBNAIL_SCALE_FACTOR}reverseHorizontal(e,t){let n=this.yuvData;for(let r=0,i=this.top*this.dataWidth+this.left;r<t;r++,i+=this.dataWidth){let t=i+e/2;for(let r=i,a=i+e-1;r<t;r++,a--){let e=n[r];n[r]=n[a],n[a]=e}}}invert(){return new N(this)}}Rn.THUMBNAIL_SCALE_FACTOR=2;class zn extends M{constructor(e,t,n,r,i,a,o){if(super(t,n),this.dataWidth=r,this.dataHeight=i,this.left=a,this.top=o,e.BYTES_PER_ELEMENT===4){let r=t*n,i=new Uint8ClampedArray(r);for(let t=0;t<r;t++){let n=e[t],r=n>>16&255,a=n>>7&510,o=n&255;i[t]=(r+a+o)/4&255}this.luminances=i}else this.luminances=e;if(r===void 0&&(this.dataWidth=t),i===void 0&&(this.dataHeight=n),a===void 0&&(this.left=0),o===void 0&&(this.top=0),this.left+t>this.dataWidth||this.top+n>this.dataHeight)throw new l(`Crop rectangle does not fit within image data.`)}getRow(e,t){if(e<0||e>=this.getHeight())throw new l(`Requested row is outside the image: `+e);let n=this.getWidth();(t==null||t.length<n)&&(t=new Uint8ClampedArray(n));let r=(e+this.top)*this.dataWidth+this.left;return p.arraycopy(this.luminances,r,t,0,n),t}getMatrix(){let e=this.getWidth(),t=this.getHeight();if(e===this.dataWidth&&t===this.dataHeight)return this.luminances;let n=e*t,r=new Uint8ClampedArray(n),i=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return p.arraycopy(this.luminances,i,r,0,n),r;for(let n=0;n<t;n++){let t=n*e;p.arraycopy(this.luminances,i,r,t,e),i+=this.dataWidth}return r}isCropSupported(){return!0}crop(e,t,n,r){return new zn(this.luminances,n,r,this.dataWidth,this.dataHeight,this.left+e,this.top+t)}invert(){return new N(this)}}class Bn extends C{static forName(e){return this.getCharacterSetECIByName(e)}}class Vn{}Vn.ISO_8859_1=C.ISO8859_1;class Hn{isCompact(){return this.compact}setCompact(e){this.compact=e}getSize(){return this.size}setSize(e){this.size=e}getLayers(){return this.layers}setLayers(e){this.layers=e}getCodeWords(){return this.codeWords}setCodeWords(e){this.codeWords=e}getMatrix(){return this.matrix}setMatrix(e){this.matrix=e}}class Un{static singletonList(e){return[e]}static min(e,t){return e.sort(t)[0]}}class Wn{constructor(e){this.previous=e}getPrevious(){return this.previous}}class Gn extends Wn{constructor(e,t,n){super(e),this.value=t,this.bitCount=n}appendTo(e,t){e.appendBits(this.value,this.bitCount)}add(e,t){return new Gn(this,e,t)}addBinaryShift(e,t){return console.warn(`addBinaryShift on SimpleToken, this simply returns a copy of this token`),new Gn(this,e,t)}toString(){let e=this.value&(1<<this.bitCount)-1;return e|=1<<this.bitCount,`<`+_.toBinaryString(e|1<<this.bitCount).substring(1)+`>`}}class Kn extends Gn{constructor(e,t,n){super(e,0,0),this.binaryShiftStart=t,this.binaryShiftByteCount=n}appendTo(e,t){for(let n=0;n<this.binaryShiftByteCount;n++)(n===0||n===31&&this.binaryShiftByteCount<=62)&&(e.appendBits(31,5),this.binaryShiftByteCount>62?e.appendBits(this.binaryShiftByteCount-31,16):n===0?e.appendBits(Math.min(this.binaryShiftByteCount,31),5):e.appendBits(this.binaryShiftByteCount-31,5)),e.appendBits(t[this.binaryShiftStart+n],8)}addBinaryShift(e,t){return new Kn(this,e,t)}toString(){return`<`+this.binaryShiftStart+`::`+(this.binaryShiftStart+this.binaryShiftByteCount-1)+`>`}}function qn(e,t,n){return new Kn(e,t,n)}function Jn(e,t,n){return new Gn(e,t,n)}let Yn=[`UPPER`,`LOWER`,`DIGIT`,`MIXED`,`PUNCT`],Xn=new Gn(null,0,0),Zn=[Int32Array.from([0,327708,327710,327709,656318]),Int32Array.from([590318,0,327710,327709,656318]),Int32Array.from([262158,590300,0,590301,932798]),Int32Array.from([327709,327708,656318,0,327710]),Int32Array.from([327711,656380,656382,656381,0])];function Qn(e){for(let t of e)g.fill(t,-1);return e[0][4]=0,e[1][4]=0,e[1][0]=28,e[3][4]=0,e[2][4]=0,e[2][0]=15,e}let $n=Qn(g.createInt32Array(6,6));class er{constructor(e,t,n,r){this.token=e,this.mode=t,this.binaryShiftByteCount=n,this.bitCount=r}getMode(){return this.mode}getToken(){return this.token}getBinaryShiftByteCount(){return this.binaryShiftByteCount}getBitCount(){return this.bitCount}latchAndAppend(e,t){let n=this.bitCount,r=this.token;if(e!==this.mode){let t=Zn[this.mode][e];r=Jn(r,t&65535,t>>16),n+=t>>16}let i=e===2?4:5;return r=Jn(r,t,i),new er(r,e,0,n+i)}shiftAndAppend(e,t){let n=this.token,r=this.mode===2?4:5;return n=Jn(n,$n[this.mode][e],r),n=Jn(n,t,5),new er(n,this.mode,0,this.bitCount+r+5)}addBinaryShiftChar(e){let t=this.token,n=this.mode,r=this.bitCount;if(this.mode===4||this.mode===2){let e=Zn[n][0];t=Jn(t,e&65535,e>>16),r+=e>>16,n=0}let i=this.binaryShiftByteCount===0||this.binaryShiftByteCount===31?18:this.binaryShiftByteCount===62?9:8,a=new er(t,n,this.binaryShiftByteCount+1,r+i);return a.binaryShiftByteCount===2078&&(a=a.endBinaryShift(e+1)),a}endBinaryShift(e){if(this.binaryShiftByteCount===0)return this;let t=this.token;return t=qn(t,e-this.binaryShiftByteCount,this.binaryShiftByteCount),new er(t,this.mode,0,this.bitCount)}isBetterThanOrEqualTo(e){let t=this.bitCount+(Zn[this.mode][e.mode]>>16);return this.binaryShiftByteCount<e.binaryShiftByteCount?t+=er.calculateBinaryShiftCost(e)-er.calculateBinaryShiftCost(this):this.binaryShiftByteCount>e.binaryShiftByteCount&&e.binaryShiftByteCount>0&&(t+=10),t<=e.bitCount}toBitArray(e){let t=[];for(let n=this.endBinaryShift(e.length).token;n!==null;n=n.getPrevious())t.unshift(n);let n=new v;for(let r of t)r.appendTo(n,e);return n}toString(){return E.format(`%s bits=%d bytes=%d`,Yn[this.mode],this.bitCount,this.binaryShiftByteCount)}static calculateBinaryShiftCost(e){return e.binaryShiftByteCount>62?21:e.binaryShiftByteCount>31?20:e.binaryShiftByteCount>0?10:0}}er.INITIAL_STATE=new er(Xn,0,0,0);function tr(e){let t=E.getCharCode(` `),n=E.getCharCode(`.`),r=E.getCharCode(`,`);e[0][t]=1;let i=E.getCharCode(`Z`),a=E.getCharCode(`A`);for(let t=a;t<=i;t++)e[0][t]=t-a+2;e[1][t]=1;let o=E.getCharCode(`z`),s=E.getCharCode(`a`);for(let t=s;t<=o;t++)e[1][t]=t-s+2;e[2][t]=1;let c=E.getCharCode(`9`),l=E.getCharCode(`0`);for(let t=l;t<=c;t++)e[2][t]=t-l+2;e[2][r]=12,e[2][n]=13;let u=`\0 \x07\b
|
|
84
|
+
\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(`
|
|
85
|
+
`),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 se.AZTEC_PARAM;case 6:return se.AZTEC_DATA_6;case 8:return se.AZTEC_DATA_8;case 10:return se.AZTEC_DATA_10;case 12:return se.AZTEC_DATA_12;default:throw new l(`Unsupported word size `+e)}}static stuffBits(e,t){let n=new v,r=e.getSize(),i=(1<<t)-2;for(let a=0;a<r;a+=t){let o=0;for(let n=0;n<t;n++)(a+n>=r||e.get(a+n))&&(o|=1<<t-1-n);(o&i)===i?(n.appendBits(o&i,t),a--):(o&i)===0?(n.appendBits(o|1,t),a--):n.appendBits(o,t)}return n}static totalBitsInLayer(e,t){return((t?88:112)+16*e)*e}}ir.DEFAULT_EC_PERCENT=33,ir.DEFAULT_AZTEC_LAYERS=0,ir.MAX_NB_BITS=32,ir.MAX_NB_BITS_COMPACT=4,ir.WORD_SIZE=Int32Array.from([4,6,6,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12]);class ar{encode(e,t,n,r){return this.encodeWithHints(e,t,n,r,null)}encodeWithHints(e,t,n,r,i){let a=Vn.ISO_8859_1,o=ir.DEFAULT_EC_PERCENT,s=ir.DEFAULT_AZTEC_LAYERS;return i!=null&&(i.has(En.CHARACTER_SET)&&(a=Bn.forName(i.get(En.CHARACTER_SET).toString())),i.has(En.ERROR_CORRECTION)&&(o=_.parseInt(i.get(En.ERROR_CORRECTION).toString())),i.has(En.AZTEC_LAYERS)&&(s=_.parseInt(i.get(En.AZTEC_LAYERS).toString()))),ar.encodeLayers(e,t,n,r,a,o,s)}static encodeLayers(e,t,n,r,i,a,o){if(t!==z.AZTEC)throw new l(`Can only encode AZTEC, but got `+t);let s=ir.encode(E.getBytes(e,i),a,o);return ar.renderResult(s,n,r)}static renderResult(e,t,n){let r=e.getMatrix();if(r==null)throw new le;let i=r.getWidth(),a=r.getHeight(),o=Math.max(t,i),s=Math.max(n,a),c=Math.min(o/i,s/a),l=(o-i*c)/2,u=(s-a*c)/2,d=new O(o,s);for(let e=0,t=u;e<a;e++,t+=c)for(let n=0,a=l;n<i;n++,a+=c)r.get(n,e)&&d.setRegion(a,t,c,c);return d}}e.AbstractExpandedDecoder=Ze,e.ArgumentException=c,e.ArithmeticException=oe,e.AztecCode=Hn,e.AztecCodeReader=we,e.AztecCodeWriter=ar,e.AztecDecoder=fe,e.AztecDetector=Ce,e.AztecDetectorResult=ge,e.AztecEncoder=ir,e.AztecHighLevelEncoder=rr,e.AztecPoint=Se,e.BarcodeFormat=z,e.Binarizer=f,e.BinaryBitmap=u,e.BitArray=v,e.BitMatrix=O,e.BitSource=yt,e.BrowserAztecCodeReader=Te,e.BrowserBarcodeReader=pt,e.BrowserCodeReader=L,e.BrowserDatamatrixCodeReader=Tt,e.BrowserMultiFormatReader=Sn,e.BrowserPDF417Reader=Cn,e.BrowserQRCodeReader=wn,e.BrowserQRCodeSvgWriter=Fn,e.CharacterSetECI=C,e.ChecksumException=d,e.Code128Reader=V,e.Code39Reader=De,e.DataMatrixDecodedBitStreamParser=xt,e.DataMatrixReader=wt,e.DecodeHintType=b,e.DecoderResult=re,e.DefaultGridSampler=be,e.DetectorResult=he,e.EAN13Reader=Pe,e.EncodeHintType=En,e.Exception=s,e.FormatException=x,e.GenericGF=se,e.GenericGFPoly=ae,e.GlobalHistogramBinarizer=A,e.GridSampler=ve,e.GridSamplerInstance=xe,e.HTMLCanvasElementLuminanceSource=P,e.HybridBinarizer=j,e.ITFReader=Oe,e.IllegalArgumentException=l,e.IllegalStateException=le,e.InvertedLuminanceSource=N,e.LuminanceSource=M,e.MathUtils=pe,e.MultiFormatOneDReader=ft,e.MultiFormatReader=xn,e.MultiFormatWriter=Ln,e.NotFoundException=k,e.OneDReader=Ee,e.PDF417DecodedBitStreamParser=J,e.PDF417DecoderErrorCorrection=Xt,e.PDF417Reader=yn,e.PDF417ResultMetadata=sn,e.PerspectiveTransform=ye,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=dt,e.RSSExpandedReader=U,e.ReaderException=bn,e.ReedSolomonDecoder=ue,e.ReedSolomonEncoder=Dn,e.ReedSolomonException=ce,e.Result=R,e.ResultMetadataType=ne,e.ResultPoint=B,e.StringUtils=E,e.UnsupportedOperationException=w,e.VideoInputDevice=F,e.WhiteRectangleDetector=_e,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=st,Object.defineProperty(e,"__esModule",{value:!0})}))}))()),Im=function(){function e(e,t,n){if(this.formatMap=new Map([[vm.QR_CODE,Fm.BarcodeFormat.QR_CODE],[vm.AZTEC,Fm.BarcodeFormat.AZTEC],[vm.CODABAR,Fm.BarcodeFormat.CODABAR],[vm.CODE_39,Fm.BarcodeFormat.CODE_39],[vm.CODE_93,Fm.BarcodeFormat.CODE_93],[vm.CODE_128,Fm.BarcodeFormat.CODE_128],[vm.DATA_MATRIX,Fm.BarcodeFormat.DATA_MATRIX],[vm.MAXICODE,Fm.BarcodeFormat.MAXICODE],[vm.ITF,Fm.BarcodeFormat.ITF],[vm.EAN_13,Fm.BarcodeFormat.EAN_13],[vm.EAN_8,Fm.BarcodeFormat.EAN_8],[vm.PDF_417,Fm.BarcodeFormat.PDF_417],[vm.RSS_14,Fm.BarcodeFormat.RSS_14],[vm.RSS_EXPANDED,Fm.BarcodeFormat.RSS_EXPANDED],[vm.UPC_A,Fm.BarcodeFormat.UPC_A],[vm.UPC_E,Fm.BarcodeFormat.UPC_E],[vm.UPC_EAN_EXTENSION,Fm.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!Fm)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(Fm.DecodeHintType.POSSIBLE_FORMATS,r),i.set(Fm.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 Fm.MultiFormatReader(this.verbose,this.hints),n=new Fm.HTMLCanvasElementLuminanceSource(e),r=new Fm.BinaryBitmap(new Fm.HybridBinarizer(n)),i=t.decode(r);return{text:i.text,format:wm.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}(),Lm=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())})},Rm=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}}},zm=function(){function e(t,n,r){if(this.formatMap=new Map([[vm.QR_CODE,`qr_code`],[vm.AZTEC,`aztec`],[vm.CODABAR,`codabar`],[vm.CODE_39,`code_39`],[vm.CODE_93,`code_93`],[vm.CODE_128,`code_128`],[vm.DATA_MATRIX,`data_matrix`],[vm.ITF,`itf`],[vm.EAN_13,`ean_13`],[vm.EAN_8,`ean_8`],[vm.PDF_417,`pdf417`],[vm.UPC_A,`upc_a`],[vm.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 Lm(this,void 0,void 0,function(){var t,n;return Rm(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:wm.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}(),Bm=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())})},Vm=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}}},Hm=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&&zm.isSupported()?(this.primaryDecoder=new zm(e,n,r),this.secondaryDecoder=new Im(e,n,r)):this.primaryDecoder=new Im(e,n,r)}return e.prototype.decodeAsync=function(e){return Bm(this,void 0,void 0,function(){var t;return Vm(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 Bm(this,void 0,void 0,function(){var t,n;return Vm(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}(),Um=(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)}})(),Wm=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())})},Gm=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}}},Km=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}(),qm=function(e){Um(t,e);function t(t){return e.call(this,`zoom`,t)||this}return t}(function(e){Um(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}(Km)),Jm=function(e){Um(t,e);function t(t){return e.call(this,`torch`,t)||this}return t}(Km),Ym=function(){function e(e){this.track=e}return e.prototype.zoomFeature=function(){return new qm(this.track)},e.prototype.torchFeature=function(){return new Jm(this.track)},e}(),Xm=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 Wm(this,void 0,void 0,function(){var a,o;return Gm(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 Wm(this,void 0,void 0,function(){return Gm(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 Ym(this.getFirstTrackOrFail())},e}(),Zm=function(){function e(e){this.mediaStream=e}return e.prototype.render=function(e,t,n){return Wm(this,void 0,void 0,function(){return Gm(this,function(r){return[2,Xm.create(e,this.mediaStream,t,n)]})})},e.create=function(t){return Wm(this,void 0,void 0,function(){var n,r;return Gm(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}(),Qm=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},$m=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},eh=function(){function e(){}return e.failIfNotSupported=function(){return Qm(this,void 0,void 0,function(){return $m(this,function(t){if(!navigator.mediaDevices)throw`navigator.mediaDevices not supported`;return[2,new e]})})},e.prototype.create=function(e){return Qm(this,void 0,void 0,function(){return $m(this,function(t){return[2,Zm.create(e)]})})},e}(),th=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())})},nh=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}}},rh=function(){function e(){}return e.retrieve=function(){return navigator.mediaDevices?e.getCamerasFromMediaDevices():MediaStreamTrack&&MediaStreamTrack.getSources?e.getCamerasFromMediaStreamTrack():e.rejectWithError()},e.rejectWithError=function(){var t=jm.unableToQuerySupportedDevices();return e.isHttpsOrLocalhost()||(t=jm.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 th(this,void 0,void 0,function(){var e,t,n,r,i,a,o;return nh(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}(),ih;(function(e){e[e.UNKNOWN=0]=`UNKNOWN`,e[e.NOT_STARTED=1]=`NOT_STARTED`,e[e.SCANNING=2]=`SCANNING`,e[e.PAUSED=3]=`PAUSED`})(ih||={});var ah=function(){function e(){this.state=ih.NOT_STARTED,this.onGoingTransactionNewState=ih.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===ih.UNKNOWN)throw`Transaction is already cancelled, cannot execute().`;var e=this.onGoingTransactionNewState;this.onGoingTransactionNewState=ih.UNKNOWN,this.directTransition(e)},e.prototype.cancel=function(){if(this.onGoingTransactionNewState===ih.UNKNOWN)throw`Transaction is already cancelled, cannot cancel().`;this.onGoingTransactionNewState=ih.UNKNOWN},e.prototype.getState=function(){return this.state},e.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==ih.UNKNOWN)throw`Cannot transition to a new state, already under transition`},e.prototype.validateTransition=function(e){switch(this.state){case ih.UNKNOWN:throw`Transition from unknown is not allowed`;case ih.NOT_STARTED:this.failIfNewStateIs(e,[ih.PAUSED]);break;case ih.SCANNING:break;case ih.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}(),oh=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()===ih.NOT_STARTED},e.prototype.isScanning=function(){return this.stateManager.getState()!==ih.NOT_STARTED},e.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===ih.SCANNING},e.prototype.isPaused=function(){return this.stateManager.getState()===ih.PAUSED},e}(),sh=function(){function e(){}return e.create=function(){return new oh(new ah)},e}(),ch=(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)}})(),lh=function(e){ch(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}(Cm),uh=function(){function e(e,t){this.logger=t,this.fps=lh.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=lh.DEFAULT_DISABLE_FLIP}return e.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?Pm.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError(`Empty videoConstraints`,!0),!1)},e.prototype.isShadedBoxEnabled=function(){return!km(this.qrbox)},e.create=function(t,n){return new e(t,n)},e}(),dh=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 Om(this.verbose),this.qrcode=new Hm(this.getSupportedFormats(t),this.getUseBarCodeDetectorIfSupported(n),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=sh.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=uh.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:lh.DEFAULT_WIDTH,l.style.position=`relative`,this.shouldScan=!0,this.element=l;var u=this,d=this.stateManagerProxy.startTransition(ih.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)}};eh.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(jm.errorGettingUserMedia(e))})}).catch(function(e){d.cancel(),r(jm.cameraStreamingNotSupported())})})},e.prototype.pause=function(e){if(!this.stateManagerProxy.isStrictlyScanning())throw`Cannot pause, scanner is not scanning.`;this.stateManagerProxy.directTransition(ih.PAUSED),this.showPausedState(),(km(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(ih.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(ih.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var n=function(){if(e.element){var t=document.getElementById(lh.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(km(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:lh.DEFAULT_WIDTH,l=Math.max(s.clientHeight?s.clientHeight:o,lh.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=lh.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(Tm.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 rh.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(!Pm.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=[vm.QR_CODE,vm.AZTEC,vm.CODABAR,vm.CODE_39,vm.CODE_93,vm.CODE_128,vm.DATA_MATRIX,vm.MAXICODE,vm.ITF,vm.EAN_13,vm.EAN_8,vm.PDF_417,vm.RSS_14,vm.RSS_EXPANDED,vm.UPC_A,vm.UPC_E,vm.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];xm(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(km(e))return!0;if(!km(e.useBarCodeDetectorIfSupported))return e.useBarCodeDetectorIfSupported!==!1;if(km(e.experimentalFeatures))return!0;var t=e.experimentalFeatures;return km(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<lh.MIN_QR_BOX_SIZE)throw`minimum size of 'config.qrbox' dimension value is ${lh.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=km(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=jm.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,Tm.createFromQrcodeResult(t)),n.possiblyUpdateShaders(!0),!0}).catch(function(e){n.possiblyUpdateShaders(!1);var r=jm.codeParseError(e);return t(r,Dm.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?lh.BORDER_SHADER_MATCH_COLOR:lh.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=km(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=`${lh.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=lh.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}(),fh=`data:image/svg+xml;base64,`,ph=fh+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNzEuNjQzIDM3MS42NDMiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDM3MS42NDMgMzcxLjY0MyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZD0iTTEwNS4wODQgMzguMjcxaDE2My43Njh2MjBIMTA1LjA4NHoiLz48cGF0aCBkPSJNMzExLjU5NiAxOTAuMTg5Yy03LjQ0MS05LjM0Ny0xOC40MDMtMTYuMjA2LTMyLjc0My0yMC41MjJWMzBjMC0xNi41NDItMTMuNDU4LTMwLTMwLTMwSDEyNS4wODRjLTE2LjU0MiAwLTMwIDEzLjQ1OC0zMCAzMHYxMjAuMTQzaC04LjI5NmMtMTYuNTQyIDAtMzAgMTMuNDU4LTMwIDMwdjEuMzMzYTI5LjgwNCAyOS44MDQgMCAwIDAgNC42MDMgMTUuOTM5Yy03LjM0IDUuNDc0LTEyLjEwMyAxNC4yMjEtMTIuMTAzIDI0LjA2MXYxLjMzM2MwIDkuODQgNC43NjMgMTguNTg3IDEyLjEwMyAyNC4wNjJhMjkuODEgMjkuODEgMCAwIDAtNC42MDMgMTUuOTM4djEuMzMzYzAgMTYuNTQyIDEzLjQ1OCAzMCAzMCAzMGg4LjMyNGMuNDI3IDExLjYzMSA3LjUwMyAyMS41ODcgMTcuNTM0IDI2LjE3Ny45MzEgMTAuNTAzIDQuMDg0IDMwLjE4NyAxNC43NjggNDUuNTM3YTkuOTg4IDkuOTg4IDAgMCAwIDguMjE2IDQuMjg4IDkuOTU4IDkuOTU4IDAgMCAwIDUuNzA0LTEuNzkzYzQuNTMzLTMuMTU1IDUuNjUtOS4zODggMi40OTUtMTMuOTIxLTYuNzk4LTkuNzY3LTkuNjAyLTIyLjYwOC0xMC43Ni0zMS40aDgyLjY4NWMuMjcyLjQxNC41NDUuODE4LjgxNSAxLjIxIDMuMTQyIDQuNTQxIDkuMzcyIDUuNjc5IDEzLjkxMyAyLjUzNCA0LjU0Mi0zLjE0MiA1LjY3Ny05LjM3MSAyLjUzNS0xMy45MTMtMTEuOTE5LTE3LjIyOS04Ljc4Ny0zNS44ODQgOS41ODEtNTcuMDEyIDMuMDY3LTIuNjUyIDEyLjMwNy0xMS43MzIgMTEuMjE3LTI0LjAzMy0uODI4LTkuMzQzLTcuMTA5LTE3LjE5NC0xOC42NjktMjMuMzM3YTkuODU3IDkuODU3IDAgMCAwLTEuMDYxLS40ODZjLS40NjYtLjE4Mi0xMS40MDMtNC41NzktOS43NDEtMTUuNzA2IDEuMDA3LTYuNzM3IDE0Ljc2OC04LjI3MyAyMy43NjYtNy42NjYgMjMuMTU2IDEuNTY5IDM5LjY5OCA3LjgwMyA0Ny44MzYgMTguMDI2IDUuNzUyIDcuMjI1IDcuNjA3IDE2LjYyMyA1LjY3MyAyOC43MzMtLjQxMyAyLjU4NS0uODI0IDUuMjQxLTEuMjQ1IDcuOTU5LTUuNzU2IDM3LjE5NC0xMi45MTkgODMuNDgzLTQ5Ljg3IDExNC42NjEtNC4yMjEgMy41NjEtNC43NTYgOS44Ny0xLjE5NCAxNC4wOTJhOS45OCA5Ljk4IDAgMCAwIDcuNjQ4IDMuNTUxIDkuOTU1IDkuOTU1IDAgMCAwIDYuNDQ0LTIuMzU4YzQyLjY3Mi0zNi4wMDUgNTAuODAyLTg4LjUzMyA1Ni43MzctMTI2Ljg4OC40MTUtMi42ODQuODIxLTUuMzA5IDEuMjI5LTcuODYzIDIuODM0LTE3LjcyMS0uNDU1LTMyLjY0MS05Ljc3Mi00NC4zNDV6bS0yMzIuMzA4IDQyLjYyYy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM2MwLTUuNTE0IDQuNDg2LTEwIDEwLTEwaDE1djIxLjMzM2gtMTV6bS0yLjUtNTIuNjY2YzAtNS41MTQgNC40ODYtMTAgMTAtMTBoNy41djIxLjMzM2gtNy41Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi0xLjMzM3ptMTcuNSA5My45OTloLTcuNWMtNS41MTQgMC0xMC00LjQ4Ni0xMC0xMHYtMS4zMzNjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGg3LjV2MjEuMzMzem0zMC43OTYgMjguODg3Yy01LjUxNCAwLTEwLTQuNDg2LTEwLTEwdi04LjI3MWg5MS40NTdjLS44NTEgNi42NjgtLjQzNyAxMi43ODcuNzMxIDE4LjI3MWgtODIuMTg4em03OS40ODItMTEzLjY5OGMtMy4xMjQgMjAuOTA2IDEyLjQyNyAzMy4xODQgMjEuNjI1IDM3LjA0IDUuNDQxIDIuOTY4IDcuNTUxIDUuNjQ3IDcuNzAxIDcuMTg4LjIxIDIuMTUtMi41NTMgNS42ODQtNC40NzcgNy4yNTEtLjQ4Mi4zNzgtLjkyOS44LTEuMzM1IDEuMjYxLTYuOTg3IDcuOTM2LTExLjk4MiAxNS41Mi0xNS40MzIgMjIuNjg4aC05Ny41NjRWMzBjMC01LjUxNCA0LjQ4Ni0xMCAxMC0xMGgxMjMuNzY5YzUuNTE0IDAgMTAgNC40ODYgMTAgMTB2MTM1LjU3OWMtMy4wMzItLjM4MS02LjE1LS42OTQtOS4zODktLjkxNC0yNS4xNTktMS42OTQtNDIuMzcgNy43NDgtNDQuODk4IDI0LjY2NnoiLz48cGF0aCBkPSJNMTc5LjEyOSA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXpNMTcyLjYyOSAxNDIuODZoLTEyLjU2VjEzMC44YTUgNSAwIDEgMC0xMCAwdjE3LjA2MWE1IDUgMCAwIDAgNSA1aDE3LjU2YTUgNSAwIDEgMCAwLTEwLjAwMXpNMjE2LjU2OCA4My4xNjdoLTI0LjA2YTUgNSAwIDAgMC01IDV2MjQuMDYxYTUgNSAwIDAgMCA1IDVoMjQuMDZhNSA1IDAgMCAwIDUtNVY4OC4xNjdhNSA1IDAgMCAwLTUtNXptLTUgMjQuMDYxaC0xNC4wNlY5My4xNjdoMTQuMDZ2MTQuMDYxek0yMTEuNjY5IDEyNS45MzZIMTk3LjQxYTUgNSAwIDAgMC01IDV2MTQuMjU3YTUgNSAwIDAgMCA1IDVoMTQuMjU5YTUgNSAwIDAgMCA1LTV2LTE0LjI1N2E1IDUgMCAwIDAtNS01eiIvPjwvc3ZnPg==`,mh=fh+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1OS4wMTggNTkuMDE4IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1OS4wMTggNTkuMDE4IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJtNTguNzQxIDU0LjgwOS01Ljk2OS02LjI0NGExMC43NCAxMC43NCAwIDAgMCAyLjgyLTcuMjVjMC01Ljk1My00Ljg0My0xMC43OTYtMTAuNzk2LTEwLjc5NlMzNCAzNS4zNjEgMzQgNDEuMzE0IDM4Ljg0MyA1Mi4xMSA0NC43OTYgNTIuMTFjMi40NDEgMCA0LjY4OC0uODI0IDYuNDk5LTIuMTk2bDYuMDAxIDYuMjc3YS45OTguOTk4IDAgMCAwIDEuNDE0LjAzMiAxIDEgMCAwIDAgLjAzMS0xLjQxNHpNMzYgNDEuMzE0YzAtNC44NSAzLjk0Ni04Ljc5NiA4Ljc5Ni04Ljc5NnM4Ljc5NiAzLjk0NiA4Ljc5NiA4Ljc5Ni0zLjk0NiA4Ljc5Ni04Ljc5NiA4Ljc5NlMzNiA0Ni4xNjQgMzYgNDEuMzE0ek0xMC40MzEgMTYuMDg4YzAgMy4wNyAyLjQ5OCA1LjU2OCA1LjU2OSA1LjU2OHM1LjU2OS0yLjQ5OCA1LjU2OS01LjU2OGMwLTMuMDcxLTIuNDk4LTUuNTY5LTUuNTY5LTUuNTY5cy01LjU2OSAyLjQ5OC01LjU2OSA1LjU2OXptOS4xMzggMGMwIDEuOTY4LTEuNjAyIDMuNTY4LTMuNTY5IDMuNTY4cy0zLjU2OS0xLjYwMS0zLjU2OS0zLjU2OCAxLjYwMi0zLjU2OSAzLjU2OS0zLjU2OSAzLjU2OSAxLjYwMSAzLjU2OSAzLjU2OXoiLz48cGF0aCBkPSJtMzAuODgyIDI4Ljk4NyA5LjE4LTEwLjA1NCAxMS4yNjIgMTAuMzIzYTEgMSAwIDAgMCAxLjM1MS0xLjQ3NWwtMTItMTFhMSAxIDAgMCAwLTEuNDE0LjA2M2wtOS43OTQgMTAuNzI3LTQuNzQzLTQuNzQzYTEuMDAzIDEuMDAzIDAgMCAwLTEuMzY4LS4wNDRMNi4zMzkgMzcuNzY4YTEgMSAwIDEgMCAxLjMyMiAxLjUwMWwxNi4zMTMtMTQuMzYyIDcuMzE5IDcuMzE4YS45OTkuOTk5IDAgMSAwIDEuNDE0LTEuNDE0bC0xLjgyNS0xLjgyNHoiLz48cGF0aCBkPSJNMzAgNDYuNTE4SDJ2LTQyaDU0djI4YTEgMSAwIDEgMCAyIDB2LTI5YTEgMSAwIDAgMC0xLTFIMWExIDEgMCAwIDAtMSAxdjQ0YTEgMSAwIDAgMCAxIDFoMjlhMSAxIDAgMSAwIDAtMnoiLz48L3N2Zz4=`,hh=fh+`PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NjAgNDYwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0NjAgNDYwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNMjMwIDBDMTAyLjk3NSAwIDAgMTAyLjk3NSAwIDIzMHMxMDIuOTc1IDIzMCAyMzAgMjMwIDIzMC0xMDIuOTc0IDIzMC0yMzBTMzU3LjAyNSAwIDIzMCAwem0zOC4zMzMgMzc3LjM2YzAgOC42NzYtNy4wMzQgMTUuNzEtMTUuNzEgMTUuNzFoLTQzLjEwMWMtOC42NzYgMC0xNS43MS03LjAzNC0xNS43MS0xNS43MVYyMDIuNDc3YzAtOC42NzYgNy4wMzMtMTUuNzEgMTUuNzEtMTUuNzFoNDMuMTAxYzguNjc2IDAgMTUuNzEgNy4wMzMgMTUuNzEgMTUuNzFWMzc3LjM2ek0yMzAgMTU3Yy0yMS41MzkgMC0zOS0xNy40NjEtMzktMzlzMTcuNDYxLTM5IDM5LTM5IDM5IDE3LjQ2MSAzOSAzOS0xNy40NjEgMzktMzkgMzl6Ii8+PC9zdmc+`,gh=`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAQgAAAEIBarqQRAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAE1SURBVDiNfdI7S0NBEAXgLya1otFgpbYSbISAgpXYi6CmiH9KCAiChaVga6OiWPgfRDQ+0itaGVNosXtluWwcuMzePfM4M3sq8lbHBubwg1dc4m1E/J/N4ghDPOIsfk/4xiEao5KX0McFljN4C9d4QTPXuY99jP3DsIoDPGM6BY5i5yI5R7O4q+ImFkJY2DCh3cAH2klyB+9J1xUMMAG7eCh1a+Mr+k48b5diXrFVwwLuS+BJ9MfR7+G0FHOHhTHhnXNWS87VDF4pcnfQK4Ep7XScNLmPTZgURNKKYENYWDpzW1BhscS1WHS8CDgURFJQrWcoF3c13KKbgg1BYQfy8xZWEzTTw1QZbAoKu8FqJnktdu5hcVSHmchiILzzuaDQvjBzV2m8yohCE1jHfPx/xhU+y4G/D75ELlRJsSYAAAAASUVORK5CYII=`,_h=function(){function e(){}return e.createDefault=function(){return{hasPermission:!1,lastUsedCameraId:null}},e}(),vh=function(){function e(){this.data=_h.createDefault();var t=localStorage.getItem(e.LOCAL_STORAGE_KEY);t?this.data=JSON.parse(t):this.reset()}return e.prototype.hasCameraPermissions=function(){return this.data.hasPermission},e.prototype.getLastUsedCameraId=function(){return this.data.lastUsedCameraId},e.prototype.setHasPermission=function(e){this.data.hasPermission=e,this.flush()},e.prototype.setLastUsedCameraId=function(e){this.data.lastUsedCameraId=e,this.flush()},e.prototype.resetLastUsedCameraId=function(){this.data.lastUsedCameraId=null,this.flush()},e.prototype.reset=function(){this.data=_h.createDefault(),this.flush()},e.prototype.flush=function(){localStorage.setItem(e.LOCAL_STORAGE_KEY,JSON.stringify(this.data))},e.LOCAL_STORAGE_KEY=`HTML5_QRCODE_DATA`,e}(),yh=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=Nm.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=Nm.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}(),bh=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=hh,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=gh,this.infoIcon.style.opacity=`1`):(this.isShowingInfoIcon=!0,this.onTapOut(),this.infoIcon.src=hh,this.infoIcon.style.opacity=`0.6`)},e}(),xh=function(){function e(){var e=this;this.infoDiv=new yh,this.infoIcon=new bh(function(){e.infoDiv.show()},function(){e.infoDiv.hide()})}return e.prototype.renderInto=function(e){this.infoDiv.renderInto(e),this.infoIcon.renderInto(e)},e}(),Sh=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())})},Ch=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}}},wh=function(){function e(){}return e.hasPermissions=function(){return Sh(this,void 0,void 0,function(){var e,t,n,r;return Ch(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}(),Th=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===Sm.SCAN_TYPE_CAMERA},e.isFileScanType=function(e){return e===Sm.SCAN_TYPE_FILE},e.prototype.validateAndReturnScanTypes=function(e){if(!e||e.length===0)return Cm.DEFAULT_SUPPORTED_SCAN_TYPE;var t=Cm.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(!Cm.DEFAULT_SUPPORTED_SCAN_TYPE.includes(i))throw`Unsupported scan type ${i}`}return e},e}(),Eh=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}(),Dh=function(){function e(){}return e.createElement=function(e,t){var n=document.createElement(e);return n.id=t,n.classList.add(Eh.ALL_ELEMENT_CLASS),e===`button`&&n.setAttribute(`type`,`button`),n},e}(),Oh=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())})},kh=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}}},Ah=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 Oh(this,void 0,void 0,function(){var e,t;return kh(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?Mm.torchOffButton():Mm.torchOnButton()),this.isTorchOn=t):this.propagateFailure(t),this.buttonController.enable()},e.prototype.propagateFailure=function(e,t){var n=e?Mm.torchOnFailedMessage():Mm.torchOffFailedMessage();t&&(n+=`; Error = `+t),this.onTorchActionFailureCallback(n)},e.prototype.reset=function(){this.isTorchOn=!1},e}(),jh=function(){function e(e,t){this.onTorchActionFailureCallback=t,this.torchButton=Dh.createElement(`button`,Eh.TORCH_BUTTON_ID),this.torchController=new Ah(e,this,t)}return e.prototype.render=function(e,t){var n=this;this.torchButton.innerText=Mm.torchOnButton(),this.torchButton.style.display=t.display,this.torchButton.style.marginLeft=t.marginLeft;var r=this;this.torchButton.addEventListener(`click`,function(e){return Oh(n,void 0,void 0,function(){return kh(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(Eh.TORCH_BUTTON_CLASS_TORCH_OFF),r.torchButton.classList.add(Eh.TORCH_BUTTON_CLASS_TORCH_ON)):(r.torchButton.classList.remove(Eh.TORCH_BUTTON_CLASS_TORCH_ON),r.torchButton.classList.add(Eh.TORCH_BUTTON_CLASS_TORCH_OFF)),[2]}})})}),e.appendChild(this.torchButton)},e.prototype.updateTorchCapability=function(e){this.torchController=new Ah(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=Mm.torchOnButton(),this.torchController.reset()},e.create=function(t,n,r,i){var a=new e(n,i);return a.render(t,r),a},e}(),Mh=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=Dh.createElement(`button`,Eh.FILE_SELECTION_BUTTON_ID),this.setInitialValueToButton(),this.fileSelectionButton.addEventListener(`click`,function(e){r.click()}),r.append(this.fileSelectionButton),this.fileScanInput=Dh.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=Mm.dragAndDropMessage();break}}o||(a.innerText=Mm.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=Mm.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=Mm.fileSelectionChooseAnother()+` - `+e;this.fileSelectionButton.innerText=r},e.prototype.setInitialValueToButton=function(){var e=Mm.fileSelectionChooseImage()+` - `+Mm.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}(),Nh=function(){function e(e){this.selectElement=Dh.createElement(`select`,Eh.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=`${Mm.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=[Mm.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}(),Ph=function(){function e(){this.onChangeCallback=null,this.zoomElementContainer=document.createElement(`div`),this.rangeInput=Dh.createElement(`input`,Eh.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=Mm.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=Mm.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}(),Fh;(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`})(Fh||={});function Ih(e){return{fps:e.fps,qrbox:e.qrbox,aspectRatio:e.aspectRatio,disableFlip:e.disableFlip,videoConstraints:e.videoConstraints}}function Lh(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 Th(this.config.supportedScanTypes),this.currentScanType=this.scanTypeSelector.getDefaultScanType(),this.sectionSwapAllowed=!0,this.logger=new Om(this.verbose),this.persistedDataManager=new vh,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(Mm.lastMatch(t),Fh.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 dh(this.getScanRegionId(),Lh(this.config,this.verbose))},e.prototype.pause=function(e){(km(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||=Cm.SCAN_DEFAULT_FPS,e.rememberLastUsedCamera!==!Cm.DEFAULT_REMEMBER_LAST_CAMERA_USED&&(e.rememberLastUsedCamera=Cm.DEFAULT_REMEMBER_LAST_CAMERA_USED),e.supportedScanTypes||=Cm.DEFAULT_SUPPORTED_SCAN_TYPE,e):{fps:Cm.SCAN_DEFAULT_FPS,rememberLastUsedCamera:Cm.DEFAULT_REMEMBER_LAST_CAMERA_USED,supportedScanTypes:Cm.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),Th.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 xh().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(Mm.cameraPermissionRequesting());var i=function(){n||r.createPermissionButton(e,t)};dh.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(Mm.noCameraFound(),Fh.STATUS_WARNING),i())}).catch(function(e){r.persistedDataManager.setHasPermission(!1),n?n.disabled=!1:i(),r.setHeaderMessage(e,Fh.STATUS_WARNING),r.showHideScanTypeSwapLink(!0)})},e.prototype.createPermissionButton=function(e,t){var n=this,r=Dh.createElement(`button`,this.getCameraPermissionButtonId());r.innerText=Mm.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(Th.isCameraScanType(this.currentScanType)&&this.persistedDataManager.hasCameraPermissions()){wh.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=Th.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=Th.isFileScanType(this.currentScanType),n=this,r=function(e){if(!n.html5Qrcode)throw`html5Qrcode not defined`;Th.isFileScanType(n.currentScanType)&&(n.setHeaderMessage(Mm.loadingImage()),n.html5Qrcode.scanFileV2(e,!0).then(function(e){n.resetHeaderMessage(),n.qrCodeSuccessCallback(e.decodedText,e)}).catch(function(e){n.setHeaderMessage(e,Fh.STATUS_WARNING),n.qrCodeErrorCallback(e,Dm.createFrom(e))}))};this.fileSelectionUi=Mh.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=Ph.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=Am(r,n.min(),n.max()),i.setValues(n.min(),n.max(),r,n.step()),i.show()}},o=Nh.create(r,e),s=document.createElement(`span`),c=Dh.createElement(`button`,Eh.CAMERA_START_BUTTON_ID);c.innerText=Mm.scanButtonStartScanningText(),s.appendChild(c);var l=Dh.createElement(`button`,Eh.CAMERA_STOP_BUTTON_ID);l.innerText=Mm.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=jh.create(s,e.torchFeature(),{display:`none`,marginLeft:`5px`},function(e){n.setHeaderMessage(e,Fh.STATUS_WARNING)}),u.show()};r.appendChild(s);var f=function(e){e||(c.style.display=`none`),c.innerText=Mm.scanButtonStartScanningText(),c.style.opacity=`1`,c.disabled=!1,e&&(c.style.display=`inline-block`)};if(c.addEventListener(`click`,function(e){c.innerText=Mm.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,Ih(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,Fh.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,Fh.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=Mm.textIfCameraScanSelected(),n=Mm.textIfFileScanSelected(),r=document.getElementById(this.getDashboardSectionId()),i=document.createElement(`div`);i.style.textAlign=`center`;var a=Dh.createElement(`span`,this.getDashboardSectionSwapLinkId());a.style.textDecoration=`underline`,a.style.cursor=`pointer`,a.innerText=Th.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,Th.isCameraScanType(e.currentScanType)?(e.clearScanRegion(),e.getCameraScanRegion().style.display=`none`,e.fileSelectionUi.show(),a.innerText=n,e.currentScanType=Sm.SCAN_TYPE_FILE,e.insertFileScanImageToScanRegion()):(e.clearScanRegion(),e.getCameraScanRegion().style.display=`block`,e.fileSelectionUi.hide(),a.innerText=t,e.currentScanType=Sm.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()){wh.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||=Fh.STATUS_DEFAULT;var n=this.getHeaderMessageDiv();switch(n.innerText=e,n.style.display=`block`,t){case Fh.STATUS_SUCCESS:n.style.background=`rgba(106, 175, 80, 0.26)`,n.style.color=`#477735`;break;case Fh.STATUS_WARNING:n.style.background=`rgba(203, 36, 49, 0.14)`,n.style.color=`#cb2431`;break;case Fh.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=ph,this.cameraScanImage.alt=Mm.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=mh,this.fileScanImage.alt=Mm.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 Eh.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 Eh.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 Rh;(function(e){e[e.BACK=1]=`BACK`,e[e.FRONT=2]=`FRONT`})(Rh||={});var zh;(function(e){e[e.PORTRAIT=1]=`PORTRAIT`,e[e.LANDSCAPE=2]=`LANDSCAPE`,e[e.ADAPTIVE=3]=`ADAPTIVE`})(zh||={});var Bh;(function(e){e[e.ALL=17]=`ALL`})(Bh||={});var Vh=Object.assign(Object.assign({},vm),Bh),Hh;(function(e){e.ZXING=`zxing`,e.MLKIT=`mlkit`})(Hh||={});var Uh=[{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 Wh(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 Gh=ii(`CapacitorBarcodeScanner`,{web:()=>(Wh(Uh),wr(()=>import(`./web-NsuCXAqU.js`).then(e=>new e.CapacitorBarcodeScannerWeb),[]))}),Kh=class{static async scanBarcode(e){return e.scanInstructions=e.scanInstructions||` `,e.scanButton=e.scanButton||!1,e.scanText=e.scanText||` `,e.cameraDirection=e.cameraDirection||Rh.BACK,e.scanOrientation=e.scanOrientation||zh.ADAPTIVE,Gh.scanBarcode(e)}};function qh(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 Jh(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 Yh(){let[e,t]=(0,Y.useState)(!1);return{scan:(0,Y.useCallback)(async()=>{if(!Xe())return{value:null,error:null};t(!0);try{let e=await Kh.scanBarcode({hint:Vh.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 Jh(e)?{value:null,error:null}:qh(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:Xe()}}function Xh(){let[e,t]=(0,Y.useState)(!0),[n,r]=(0,Y.useState)(te),[i,a]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(null),[l,d]=(0,Y.useState)(!1),f=Yh();(0,Y.useEffect)(()=>{let e=!0;return(async()=>{try{let n=await fetch(`${In()}/health`,{method:`GET`});e&&t(n.ok)}catch{e&&t(!1)}})(),()=>{e=!1}},[]);let p=(0,Y.useCallback)(async()=>{let e=We(n);if(e){a(null),d(!0);try{if(!await qe(e)){a(e);return}k(n)}finally{d(!1)}}},[n]),m=(0,Y.useCallback)(async()=>{c(null);let e=await f.scan();if(e.error){c(e.error);return}if(e.value){r(e.value),a(null);let t=We(e.value);if(!t){c(`The scanned QR code did not contain a valid server address.`);return}d(!0);try{if(!await qe(t)){a(t);return}k(e.value)}finally{d(!1)}}},[f]);return e?null:(0,$.jsx)(Rr,{open:!0,children:(0,$.jsxs)(Mr,{children:[(0,$.jsxs)(Ar,{children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`mx-auto h-16 w-16 rounded-lg`}),(0,$.jsx)(jr,{children:`Connect to Tarsk`}),(0,$.jsx)(Nr,{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)(u,{value:n,onChange:e=>{r(e.target.value),a(null),c(null)},onKeyDown:e=>{e.key===`Enter`&&!l&&p()},placeholder:`192.168.1.100`,autoComplete:`off`,spellCheck:!1,disabled:l,className:f.isAvailable?`pr-10`:void 0}),f.isAvailable&&(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-1 top-1 h-8 w-8`,"aria-label":`Scan QR code`,disabled:l||f.isScanning,onClick:()=>void m(),children:f.isScanning?(0,$.jsx)(N,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Mn,{className:`h-4 w-4`})})]}),o&&(0,$.jsxs)(Ur,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsx)(`p`,{className:`flex-1`,children:o}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>c(null),children:(0,$.jsx)(z,{className:`h-4 w-4`})})]}),i&&(0,$.jsxs)(Ur,{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)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>a(null),children:(0,$.jsx)(z,{className:`h-4 w-4`})})]}),(0,$.jsx)(Fr,{children:(0,$.jsx)(W,{onClick:()=>void p(),disabled:!n.trim()||l,children:l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`mr-2 h-4 w-4 animate-spin`}),`Connecting...`]}):`Connect`})}),(0,$.jsxs)(Ur,{variant:`hint`,className:`mb-0`,children:[(0,$.jsx)(`p`,{className:s.bodyMuted,children:`Start the Tarsk server on your local machine by running:`}),(0,$.jsx)(`code`,{className:q(s.mono,`mt-2 block rounded bg-background/60 px-2 py-1 text-foreground`),children:`npx tarsk --server`})]})]})})}var Zh=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=q(`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)(Xn,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},Qh=Yn,$h=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=q(`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)(Re,{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)(Qn,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},eg=Zn,tg=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=q(`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)(pr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});tg.displayName=pr.displayName;var ng=yn(`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`}}),rg=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=q(ng({variant:a}),r),n[4]=r,n[5]=a,n[6]=o):o=n[6];let s;return n[7]!==i||n[8]!==t||n[9]!==o?(s=(0,$.jsx)(mr,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});rg.displayName=mr.displayName;var ig=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=q(`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`,s.body,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(tr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});ig.displayName=tr.displayName;var ag=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=q(`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)(z,{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)(Vn,{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});ag.displayName=Vn.displayName;var og=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=q(s.dialogTitle,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Rn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});og.displayName=Rn.displayName;var sg=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=q(s.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)(Bn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});sg.displayName=Bn.displayName;function cg(){let e=(0,X.c)(5),{toasts:t}=ma(),n;e[0]===t?n=e[1]:(n=t.map(lg),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(tg,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(eg,{children:[n,r]}),e[3]=n,e[4]=i),i}function lg(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,$.jsxs)(rg,{...a,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(og,{children:n}),r&&(0,$.jsx)(sg,{children:r})]}),i,(0,$.jsx)(ag,{})]},t)}function ug(){let e=(0,X.c)(4),{resolvedTheme:t,theme:n}=Xr(),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 dg(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)(ug,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsxs)(Zr,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function fg(){let e=(0,X.c)(14),t=Xi(),n=Q(hg),r=Ir(`projects:bootstrap:${Q(mg)}`,h),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(pg);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 pg(e){return e.isSelected}function mg(e){return e.configUpdatedAt}function hg(e){return e.selectedThreadId}function gg(e){let t=Xi(),n=Q(e=>e.projects),r=Q(e=>e.selectedProjectId),i=Q(e=>e.selectedThreadId),{toast:a}=ma(),o=Qi(`project-creation`).dispatch,[s,c]=(0,Y.useState)(null),l=(0,Y.useCallback)(async()=>{try{t({type:Z.SetProjectsLoading,projectsLoading:!0}),ee(),Hr(`projects:bootstrap:`);let e=await h();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}),Gt(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(`
|
|
86
|
+
`);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}),ee();let g=await h();if(t({type:Z.SetProjects,projects:g.projects}),t({type:Z.SetProjectsLoading,projectsLoading:!1}),d){let n=g.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:()=>Cn(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:()=>Pe(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:()=>En(e),initialMessage:`Creating folder "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create folder`,catchErrorPrefix:`Failed to create folder`})},[d]),_=(0,Y.useCallback)(async(e,r)=>{try{let i=r??(()=>{let t=n.find(t=>t.projectId===e)?.threads.map(e=>e.title)??[],r=/^thread-(\d+)$/i,i=0;for(let e of t){let t=e.match(r);t&&(i=Math.max(i,parseInt(t[1],10)))}return`thread-${i+1}`})(),o=await g(e,r);if(!o){await l();return}let s=o.getReader(),c=new TextDecoder,u=``,d=!1,f=null,p=!0,m=[{type:`system`,content:`Creating thread "${i}"...`}];try{for(;;){let{done:n,value:r}=await s.read();if(n)break;u+=c.decode(r,{stream:!0});let o=u.split(`
|
|
87
|
+
`);u=o.pop()??``;for(let n of o){let r=n.trim();if(r)try{let n=JSON.parse(r);if(n.type===`progress`){if(!d&&n.threadId){d=!0,f=n.threadId,t({type:Z.AddCreatingThread,projectId:e,threadId:n.threadId,title:i}),t({type:Z.AddProcessingThread,threadId:n.threadId}),t({type:Z.ClearTerminalOutput,threadId:f});for(let e of m)t({type:Z.AppendTerminalLine,threadId:f,line:e});m.length=0}let r={type:`output`,content:n.message};f?t({type:Z.AppendTerminalLine,threadId:f,line:r}):m.push(r)}else if(n.type===`error`){d&&f&&(t({type:Z.RemoveCreatingThread,projectId:e,threadId:f}),t({type:Z.RemoveProcessingThread,threadId:f}));let r={type:`error`,content:`Error: ${n.message}`};f?t({type:Z.AppendTerminalLine,threadId:f,line:r}):m.push(r),console.error(`Thread creation error:`,n.message),a({title:`Thread Creation Failed`,description:n.message,variant:`destructive`}),p=!1}}catch(e){console.error(`Failed to parse thread event`,e)}}}d&&f&&t({type:Z.RemoveProcessingThread,threadId:f}),ee(),await l(),f&&p&&t({type:Z.SelectThread,threadId:f,projectId:e,focusInput:!0})}catch(n){throw d&&f&&(t({type:Z.RemoveCreatingThread,projectId:e,threadId:f}),t({type:Z.RemoveProcessingThread,threadId:f})),a({title:`Thread Creation Failed`,description:n instanceof Error?n.message:String(n),variant:`destructive`}),n}}catch(e){console.error(`Failed to create thread:`,e);let n=`Failed to create thread: ${e instanceof Error?e.message:`Unknown error`}`;throw t({type:Z.AppendTerminalLine,line:{type:`error`,content:n}}),a({variant:`destructive`,title:`Thread Creation Failed`,description:n}),e}},[l,t,n,a]),v=(0,Y.useCallback)(async(e,n)=>{t({type:Z.AddDeletingThread,threadId:n}),t({type:Z.ClearChatInputDraft,threadId:n});try{await M(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]),y=(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 le(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]),b=(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 It(r,n,!0);if(s){let e=s.getReader(),n=new TextDecoder,r=``;for(;;){let{done:i,value:a}=await e.read();if(i)break;r+=n.decode(a,{stream:!0});let o=r.split(`
|
|
88
|
+
`);r=o.pop()??``;for(let e of o)if(e.trim())try{let n=JSON.parse(e);typeof n==`string`?t({type:Z.AppendTerminalLine,line:{type:`output`,content:n}}):n.type===`error`&&t({type:Z.AppendTerminalLine,line:{type:`error`,content:n.message}})}catch{t({type:Z.AppendTerminalLine,line:{type:`output`,content:e}})}}if(r.trim())try{let e=JSON.parse(r);typeof e==`string`?t({type:Z.AppendTerminalLine,line:{type:`output`,content:e}}):e.type===`error`&&t({type:Z.AppendTerminalLine,line:{type:`error`,content:e.message}})}catch{t({type:Z.AppendTerminalLine,line:{type:`output`,content:r}})}}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:nt,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[d]),handleCreateThread:_,handleDeleteThread:v,confirmDeleteProject:y,pendingSetupScriptConfirmation:s,resolveSetupScriptConfirmation:b}}function _g(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(vg),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 vg(){return document.hasFocus()}var yg=null;function bg(){yg??=new Audio(`/pop.wav`),yg.currentTime=0,yg.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function xg(){let e=Xi(),t=Yi(),n=Q(e=>e.processingThreadIds),r=Q(e=>e.completedThreadIds),i=_g(),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=Of(await st()),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&&bg(),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])}}var Sg=(0,Y.lazy)(()=>wr(()=>import(`./terminal-panel-wOltBu70.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([12,1,5]))),Cg=(0,Y.lazy)(()=>wr(()=>import(`./diff-view-BnNtDcmG.js`),__vite__mapDeps([6,1,3,4,7,5,8,9,10,11]))),wg=(0,Y.lazy)(()=>wr(()=>import(`./explorer-tab-view-OGWG1dH9.js`),__vite__mapDeps([13,1,3,4,7,5]))),Tg=(0,Y.lazy)(()=>wr(()=>import(`./browser-tab-DV6mFCbu.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([14,1,5]))),Eg=(0,Y.lazy)(()=>wr(()=>import(`./dialogs-config-BPzX42HH.js`).then(e=>e.t),__vite__mapDeps([5,1]))),Dg=(0,Y.lazy)(()=>wr(()=>import(`./onboarding-BmBbv0At.js`).then(e=>e.t),__vite__mapDeps([8,1,7,5]))),Og=(0,Y.lazy)(()=>wr(()=>import(`./settings-view-DQW_9pnm.js`),__vite__mapDeps([15,1,3,4,7,5,8,16,17,10])));function kg(e){return e.startsWith(`/settings`)||e===`/review`}function Ag(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background`,children:(0,$.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-muted border-t-primary`})}),e[0]=t):t=e[0],t}function jg(){return _m(),null}function Mg(){let e=Xi(),t=Q(e=>e.selectedThreadId),n=Q(e=>e.selectedProjectId),r=Q(e=>e.sidebarOpen),i=Q(e=>e.deletingThreadIds),a=Q(e=>e.deletingProjectIds);(0,Y.useEffect)(()=>{window.__electrobunWebviewId&&new Ti({})},[]),(0,Y.useEffect)(()=>{if(!Xe())return;let e=_i.addListener(`backButton`,({canGoBack:e})=>{e?window.history.back():_i.exitApp()});return()=>{e.then(e=>e.remove())}},[]);let o=Sr(),s=hr(),c=Ll(),l=c||Xe(),[u,d]=(0,Y.useState)(null),{projects:f,handleSelectThread:p,handleCreateProject:m,handleCreateWebApp:h,handleCreateFolder:g,handleOpenFolder:_,handleCreateThread:v,handleDeleteThread:y,confirmDeleteProject:b,refreshProjects:x,pendingSetupScriptConfirmation:S,resolveSetupScriptConfirmation:C}=gg({onProjectCreated:d}),{processingThreadIds:w,completedThreadIds:T,clearCompleted:E}=xg(),[D,O]=(0,Y.useState)(`chat`),[k,A]=(0,Y.useState)(null),[j,M]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(!1),[F,I]=(0,Y.useState)(!1),[L,R]=(0,Y.useState)(null),[ee,z]=(0,Y.useState)(0),[te,ne]=(0,Y.useState)(null),[re,ie]=(0,Y.useState)(0),[ae,oe]=(0,Y.useState)(`desktop`),{terminalState:se}=Qi(t),ce=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{se.open&&t===ce.current&&!kg(s.pathname)&&O(`terminal`),ce.current=t},[se.open,t,s.pathname]);let[le,ue]=(0,Y.useState)(!1),[de,fe]=(0,Y.useState)(!1),[pe,me]=(0,Y.useState)(!1),[B,he]=(0,Y.useState)(null),[ge,_e]=(0,Y.useState)(!1),[ve,ye]=(0,Y.useState)(!1),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(null),Se=s.pathname.startsWith(`/settings`),Ce=s.pathname===`/review`;(0,Y.useEffect)(()=>{c&&(xe.current?.querySelector(`[data-tab="${D}"]`))?.scrollIntoView({inline:`nearest`,block:`nearest`})},[D,c]);let we=(0,Y.useRef)(D),Te=(0,Y.useRef)(D),Ee=(0,Y.useRef)(!1),V=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(Se){if(V.current===null){V.current=Date.now(),we.current=D;return}we.current!==D&&o(`/`)}else V.current=null;we.current=D},[D,Se,o]),(0,Y.useEffect)(()=>{let e=Te.current===`explorer`;Te.current=D,D===`explorer`&&!e&&!Ee.current&&t&&!Ce&&!Se&&z(e=>e+1),Ee.current=!1},[D,t,Ce,Se]);let De=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let t=Se||Ce;if(t&&De.current===null)De.current=r,r&&e({type:Z.ToggleSidebar});else if(!t&&De.current!==null){let t=De.current;De.current=null,t&&!r&&e({type:Z.ToggleSidebar})}},[Se,Ce]),(0,Y.useEffect)(()=>{(async()=>{try{(await Wt()).updateAvailable&&_e(!0)}catch{}})()},[]);let Oe=(0,Y.useCallback)(async()=>{ye(!0);try{await $t()}catch{ye(!1)}},[]);(0,Y.useEffect)(()=>{pe||(async()=>{try{(await J()).onboardingCompleted||fe(!0)}catch(e){console.error(`Failed to check onboarding status:`,e)}finally{me(!0)}})()},[pe]),(0,Y.useEffect)(()=>{de||e({type:Z.ConfigUpdated})},[de,e]);let ke=(0,Y.useCallback)(e=>{let t=f.find(t=>t.projectId===e);t&&he({id:t.projectId,name:K(t)})},[f]),Ae=(0,Y.useCallback)(e=>{d(e),v(e,void 0)},[v]);(0,Y.useEffect)(()=>{u&&n===u&&t&&d(null)},[u,n,t]);let je=(0,Y.useCallback)(async(n,r)=>{d(null),E(r),s.pathname!==`/`&&o(`/`),O(`chat`),t!==r&&ie(e=>e+1),p(n,r),l&&e({type:Z.CloseSidebar})},[p,l,t,e,E,s.pathname,o]);(0,Y.useEffect)(()=>{r?be.current?.expand():be.current?.collapse()},[r]);let Me=(0,Y.useCallback)(()=>z(e=>e+1),[]),Ne=(0,Y.useCallback)(()=>ie(e=>e+1),[]),Pe=(0,Y.useMemo)(()=>({activeMainTab:D,setActiveMainTab:O,devServerUrl:k,setDevServerUrl:A,devServerRunning:j,setDevServerRunning:M,devServerLoading:N,setDevServerLoading:P,terminalNotification:F,setTerminalNotification:I,pendingExplorerPath:L,setPendingExplorerPath:R,explorerRefreshTick:ee,triggerExplorerRefresh:Me,explorerClearPath:te,setExplorerClearPath:ne,browserResetTrigger:re,triggerBrowserReset:Ne,browserDeviceMode:ae,setBrowserDeviceMode:oe}),[D,O,k,A,j,M,N,P,F,I,L,R,ee,Me,te,ne,re,Ne,ae,oe]);return(0,$.jsxs)(Co.Provider,{value:Pe,children:[(0,$.jsx)(jg,{}),(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(fg,{})}),(0,$.jsxs)(Sn,{delayDuration:200,children:[(0,$.jsxs)(Zh,{direction:`horizontal`,className:`h-screen bg-background`,children:[(0,$.jsx)(Qh,{ref:be,defaultSize:l?100:25,minSize:l?50:12,maxSize:l?100:32,collapsible:!0,collapsedSize:0,className:q(`border-r border-transparent`,l&&!r&&`hidden`),children:(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(ya,{projects:f,selectedThreadId:t,selectedProjectId:n,processingThreadIds:w,completedThreadIds:T,deletingThreadIds:i,deletingProjectIds:a,onSelectThread:je,onCreateProject:()=>ue(!0),onCreateThread:Ae,onDeleteThread:y,onDeleteProject:ke,onDeselect:()=>e({type:Z.ClearSelection}),collapsed:!r,updateAvailable:ge,updatingApp:ve,onUpdateApp:Oe,expandProjectId:u})})}),!l&&(0,$.jsx)($h,{withHandle:!0,className:r?`ml-[-40px]`:``}),(0,$.jsx)(Qh,{minSize:40,className:q(`overflow-hidden`,l&&r&&`hidden`),children:(0,$.jsx)(hf,{threadId:t??void 0,children:(0,$.jsx)(Dd,{children:(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[!Ce&&!Se&&(0,$.jsx)(rm,{}),!Ce&&!Se&&t&&(0,$.jsx)(`div`,{ref:xe,className:`flex shrink-0 select-none overflow-x-auto overflow-y-hidden border-b border-border`,children:[`Chat`,`Explorer`,`Review`,`Browser`,`Terminal`].map(e=>{let t=e.toLowerCase();return(0,$.jsxs)(`button`,{"data-tab":t,onClick:()=>{O(t),t===`terminal`&&I(!1),t===`explorer`&&(Ee.current=!0,z(e=>e+1))},className:`relative shrink-0 px-4 py-2 text-base font-medium transition-colors ${D===t?`border-b-2 border-primary text-foreground -mb-px`:`text-muted-foreground hover:text-foreground`}`,children:[e,t===`terminal`&&F&&D!==`terminal`&&(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1 h-1.5 w-1.5 rounded-full bg-brand`})]},t)})}),(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden${!Ce&&!Se&&D!==`chat`?` hidden`:``}`,children:(0,$.jsxs)(lr,{children:[(0,$.jsx)(br,{path:`/settings/providers/:providerSlug`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Ag,{}),children:(0,$.jsx)(Og,{})})}),(0,$.jsx)(br,{path:`/settings/project/:projectId`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Ag,{}),children:(0,$.jsx)(Og,{})})}),(0,$.jsx)(br,{path:`/settings/:tab?`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Ag,{}),children:(0,$.jsx)(Og,{})})}),(0,$.jsx)(br,{path:`*`,element:(0,$.jsx)(Bp,{onCreateThread:Ae})})]})}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden${D===`terminal`&&!Ce&&!Se?``:` hidden`}`,children:(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Sg,{})})}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden${D===`browser`&&!Ce&&!Se?``:` hidden`}`,children:(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Tg,{})})}),t&&(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden${D===`explorer`&&!Ce&&!Se?``:` hidden`}`,children:(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(wg,{})})}),!Ce&&!Se&&D!==`chat`&&D!==`terminal`&&D!==`browser`&&D!==`explorer`&&(D===`review`&&t?(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Cg,{threadId:t,onExit:()=>O(`chat`)})}):(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`}))]})})})}),(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Eg,{open:le,onOpenChange:ue,onSubmitClone:m,onSubmitWebApp:h,onSubmitFolder:g,onOpenFolder:_})}),(0,$.jsx)(cm,{open:B!==null,projectName:B?.name,onOpenChange:e=>!e&&he(null),onConfirm:()=>{B&&(b(B.id),he(null))}}),(0,$.jsx)(lm,{open:S!==null,setupScripts:S?[S.command,...S.remainingScripts||[]]:[],onConfirm:C}),(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Dg,{open:de,onOpenChange:fe,onComplete:()=>{me(!0),x()}})}),(0,$.jsx)(Xh,{})]}),(0,$.jsx)(cg,{})]})]})}function Ng(){let e=(0,X.c)(3),[t]=(0,Y.useState)(qi),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(Mg,{}),e[0]=n):n=e[0];let r;return e[1]===t?r=e[2]:(r=(0,$.jsx)(dg,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,$.jsx)(Ji.Provider,{value:t,children:n})}),e[1]=t,e[2]=r),r}var Pg=75,Fg=125,Ig=100;function Lg(){return window.matchMedia(`(max-width: 767px)`).matches}function Rg(e){let t=B(e,Lg());document.documentElement.style.fontSize=`${t}%`}var zg=!1;function Bg(){zg||(zg=!0,window.matchMedia(`(max-width: 767px)`).addEventListener(`change`,()=>{Rg(hn(Ig))}))}function Vg(){let[e,t]=(0,Y.useState)(()=>hn(Ig));(0,Y.useEffect)(()=>{Bg(),Rg(e)},[e]);function n(e){let n=Math.max(Pg,Math.min(Fg,Math.round(e)));t(n),_n(n)}return{scale:e,updateScale:n,resetScale:(0,Y.useCallback)(()=>{n(Ig)},[]),min:Pg,max:Fg,default:Ig}}function Hg(){Bg(),Rg(hn(Ig))}var Ug;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(Ug||={});var Wg;(function(e){e.None=`NONE`,e.Slide=`SLIDE`,e.Fade=`FADE`})(Wg||={});var Gg=ii(`StatusBar`),Kg=`--app-viewport-height`;function qg(){let e=window.visualViewport,t=Math.round(on()===`ios`?window.innerHeight:e?.height??window.innerHeight);document.documentElement.style.setProperty(Kg,`${t}px`)}function Jg(){qg(),requestAnimationFrame(qg)}function Yg(){document.documentElement.dataset.nativeShell=`true`,Jg(),window.addEventListener(`resize`,qg),window.addEventListener(`orientationchange`,Jg);let e=window.visualViewport;e?.addEventListener(`resize`,qg),e?.addEventListener(`scroll`,qg)}async function Xg(){try{await Gg.setOverlaysWebView({overlay:!0}),await Gg.show(),Jg()}catch{}}async function Zg(){try{let e=on()===`ios`?Mp.None:Mp.Body;await Np.setResizeMode({mode:e})}catch{}}function Qg(){Xe()&&(Yg(),Xg(),Zg(),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&(Jg(),Xg())}))}Hg(),Qg();var $g=!1;window.addEventListener(`resize`,()=>{$g||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100%)`),!0)});var e_=Xe()?cr:_r;(0,Qr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Y.StrictMode,{children:(0,$.jsx)(e_,{children:(0,$.jsx)(Ng,{})})}));export{pa as A,ys as C,wo as D,jo as E,Q as F,Qi as I,ai as L,$i as M,Z as N,ao as O,Xi as P,fc as S,bs as T,Ll as _,zh as a,_c as b,tm as c,xp as d,Sp as f,pd as g,Yd as h,Zh as i,na as j,va as k,bp as l,bf as m,$h as n,Vh as o,Rf as p,Qh as r,dh as s,Vg as t,Cp as u,dc as v,xs as w,xc as x,gc as y};
|