@owloops/browserbird 1.2.10 → 1.2.11
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.
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))n(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const r of i.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&n(r)}).observe(document,{childList:!0,subtree:!0});function s(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function n(a){if(a.ep)return;a.ep=!0;const i=s(a);fetch(a.href,i)}})();const fr=!1;var Pr=Array.isArray,Dd=Array.prototype.indexOf,sa=Array.prototype.includes,Ki=Array.from,Rd=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,qo=Object.getOwnPropertyDescriptors,Id=Object.prototype,Qd=Array.prototype,Br=Object.getPrototypeOf,ll=Object.isExtensible;const ba=()=>{};function zd(t){return t()}function _r(t){for(var e=0;e<t.length;e++)t[e]()}function Wo(){var t,e,s=new Promise((n,a)=>{t=n,e=a});return{promise:s,resolve:t,reject:e}}const Bt=2,Qa=4,za=8,jo=1<<24,nn=16,Ts=32,On=64,vr=128,bs=512,Ft=1024,Dt=2048,Fs=4096,us=8192,Zs=16384,Qn=32768,zn=65536,ol=1<<17,Yo=1<<18,oa=1<<19,Zo=1<<20,Ys=1<<25,Nn=65536,pr=1<<21,Dr=1<<22,pn=1<<23,Js=Symbol("$state"),Nd=Symbol("legacy props"),Ud=Symbol(""),Mn=new class extends Error{name="StaleReactionError";message="The reaction that called `getAbortSignal()` was re-run or destroyed"},Hd=!!globalThis.document?.contentType&&globalThis.document.contentType.includes("xml");function Od(){throw new Error("https://svelte.dev/e/async_derived_orphan")}function Vd(t,e,s){throw new Error("https://svelte.dev/e/each_key_duplicate")}function Gd(t){throw new Error("https://svelte.dev/e/effect_in_teardown")}function qd(){throw new Error("https://svelte.dev/e/effect_in_unowned_derived")}function Wd(t){throw new Error("https://svelte.dev/e/effect_orphan")}function jd(){throw new Error("https://svelte.dev/e/effect_update_depth_exceeded")}function Yd(t){throw new Error("https://svelte.dev/e/props_invalid_value")}function Zd(){throw new Error("https://svelte.dev/e/state_descriptors_fixed")}function Jd(){throw new Error("https://svelte.dev/e/state_prototype_fixed")}function $d(){throw new Error("https://svelte.dev/e/state_unsafe_mutation")}function eu(){throw new Error("https://svelte.dev/e/svelte_boundary_reset_onerror")}const tu=1,su=2,Jo=4,nu=8,au=16,iu=1,ru=2,lu=4,ou=8,cu=16,du=1,uu=2,Lt=Symbol(),$o="http://www.w3.org/1999/xhtml",hu="http://www.w3.org/2000/svg",fu="http://www.w3.org/1998/Math/MathML";function _u(){console.warn("https://svelte.dev/e/select_multiple_invalid_value")}function vu(){console.warn("https://svelte.dev/e/svelte_boundary_reset_noop")}function ec(t){return t===this.v}function pu(t,e){return t!=t?e==e:t!==e||t!==null&&typeof t=="object"||typeof t=="function"}function tc(t){return!pu(t,this.v)}let Na=!1,gu=!1;function xu(){Na=!0}let Tt=null;function na(t){Tt=t}function st(t,e=!1,s){Tt={p:Tt,i:!1,c:null,e:null,s:t,x:null,l:Na&&!e?{s:null,u:null,$:[]}:null}}function nt(t){var e=Tt,s=e.e;if(s!==null){e.e=null;for(var n of s)wc(n)}return e.i=!0,Tt=e.p,{}}function Ua(){return!Na||Tt!==null&&Tt.l===null}let Xn=[];function sc(){var t=Xn;Xn=[],_r(t)}function $s(t){if(Xn.length===0&&!Ca){var e=Xn;queueMicrotask(()=>{e===Xn&&sc()})}Xn.push(t)}function bu(){for(;Xn.length>0;)sc()}function nc(t){var e=Qe;if(e===null)return Ie.f|=pn,t;if((e.f&Qn)===0&&(e.f&Qa)===0)throw t;fn(t,e)}function fn(t,e){for(;e!==null;){if((e.f&vr)!==0){if((e.f&Qn)===0)throw t;try{e.b.error(t);return}catch(s){t=s}}e=e.parent}throw t}const mu=-7169;function wt(t,e){t.f=t.f&mu|e}function Rr(t){(t.f&bs)!==0||t.deps===null?wt(t,Ft):wt(t,Fs)}function ac(t){if(t!==null)for(const e of t)(e.f&Bt)===0||(e.f&Nn)===0||(e.f^=Nn,ac(e.deps))}function ic(t,e,s){(t.f&Dt)!==0?e.add(t):(t.f&Fs)!==0&&s.add(t),ac(t.deps),wt(t,Ft)}const Za=new Set;let Ne=null,pi=null,Cs=null,es=[],Fi=null,gr=!1,Ca=!1;class gn{current=new Map;previous=new Map;#t=new Set;#l=new Set;#e=0;#i=0;#s=null;#r=new Set;#n=new Set;#a=new Map;is_fork=!1;#o=!1;#d(){return this.is_fork||this.#i>0}skip_effect(e){this.#a.has(e)||this.#a.set(e,{d:[],m:[]})}unskip_effect(e){var s=this.#a.get(e);if(s){this.#a.delete(e);for(var n of s.d)wt(n,Dt),Es(n);for(n of s.m)wt(n,Fs),Es(n)}}process(e){es=[],this.apply();var s=[],n=[];for(const a of e)this.#c(a,s,n);if(this.#d()){this.#u(n),this.#u(s);for(const[a,i]of this.#a)cc(a,i)}else{for(const a of this.#t)a();this.#t.clear(),this.#e===0&&this.#f(),pi=this,Ne=null,cl(n),cl(s),pi=null,this.#s?.resolve()}Cs=null}#c(e,s,n){e.f^=Ft;for(var a=e.first;a!==null;){var i=a.f,r=(i&(Ts|On))!==0,l=r&&(i&Ft)!==0,d=l||(i&us)!==0||this.#a.has(a);if(!d&&a.fn!==null){r?a.f^=Ft:(i&Qa)!==0?s.push(a):Va(a)&&((i&nn)!==0&&this.#n.add(a),ia(a));var o=a.first;if(o!==null){a=o;continue}}for(;a!==null;){var u=a.next;if(u!==null){a=u;break}a=a.parent}}}#u(e){for(var s=0;s<e.length;s+=1)ic(e[s],this.#r,this.#n)}capture(e,s){s!==Lt&&!this.previous.has(e)&&this.previous.set(e,s),(e.f&pn)===0&&(this.current.set(e,e.v),Cs?.set(e,e.v))}activate(){Ne=this,this.apply()}deactivate(){Ne===this&&(Ne=null,Cs=null)}flush(){if(this.activate(),es.length>0){if(rc(),Ne!==null&&Ne!==this)return}else this.#e===0&&this.process([]);this.deactivate()}discard(){for(const e of this.#l)e(this);this.#l.clear()}#f(){if(Za.size>1){this.previous.clear();var e=Cs,s=!0;for(const a of Za){if(a===this){s=!1;continue}const i=[];for(const[l,d]of this.current){if(a.current.has(l))if(s&&d!==a.current.get(l))a.current.set(l,d);else continue;i.push(l)}if(i.length===0)continue;const r=[...a.current.keys()].filter(l=>!this.current.has(l));if(r.length>0){var n=es;es=[];const l=new Set,d=new Map;for(const o of i)lc(o,r,l,d);if(es.length>0){Ne=a,a.apply();for(const o of es)a.#c(o,[],[]);a.deactivate()}es=n}}Ne=null,Cs=e}Za.delete(this)}increment(e){this.#e+=1,e&&(this.#i+=1)}decrement(e){this.#e-=1,e&&(this.#i-=1),!this.#o&&(this.#o=!0,$s(()=>{this.#o=!1,this.#d()?es.length>0&&this.flush():this.revive()}))}revive(){for(const e of this.#r)this.#n.delete(e),wt(e,Dt),Es(e);for(const e of this.#n)wt(e,Fs),Es(e);this.flush()}oncommit(e){this.#t.add(e)}ondiscard(e){this.#l.add(e)}settled(){return(this.#s??=Wo()).promise}static ensure(){if(Ne===null){const e=Ne=new gn;Za.add(Ne),Ca||$s(()=>{Ne===e&&e.flush()})}return Ne}apply(){}}function wu(t){var e=Ca;Ca=!0;try{for(var s;;){if(bu(),es.length===0&&(Ne?.flush(),es.length===0))return Fi=null,s;rc()}}finally{Ca=e}}function rc(){gr=!0;var t=null;try{for(var e=0;es.length>0;){var s=gn.ensure();if(e++>1e3){var n,a;yu()}s.process(es),xn.clear()}}finally{es=[],gr=!1,Fi=null}}function yu(){try{jd()}catch(t){fn(t,Fi)}}let qs=null;function cl(t){var e=t.length;if(e!==0){for(var s=0;s<e;){var n=t[s++];if((n.f&(Zs|us))===0&&Va(n)&&(qs=new Set,ia(n),n.deps===null&&n.first===null&&n.nodes===null&&n.teardown===null&&n.ac===null&&Cc(n),qs?.size>0)){xn.clear();for(const a of qs){if((a.f&(Zs|us))!==0)continue;const i=[a];let r=a.parent;for(;r!==null;)qs.has(r)&&(qs.delete(r),i.push(r)),r=r.parent;for(let l=i.length-1;l>=0;l--){const d=i[l];(d.f&(Zs|us))===0&&ia(d)}}qs.clear()}}qs=null}}function lc(t,e,s,n){if(!s.has(t)&&(s.add(t),t.reactions!==null))for(const a of t.reactions){const i=a.f;(i&Bt)!==0?lc(a,e,s,n):(i&(Dr|nn))!==0&&(i&Dt)===0&&oc(a,e,n)&&(wt(a,Dt),Es(a))}}function oc(t,e,s){const n=s.get(t);if(n!==void 0)return n;if(t.deps!==null)for(const a of t.deps){if(sa.call(e,a))return!0;if((a.f&Bt)!==0&&oc(a,e,s))return s.set(a,!0),!0}return s.set(t,!1),!1}function Es(t){var e=Fi=t,s=e.b;if(s?.is_pending&&(t.f&(Qa|za|jo))!==0&&(t.f&Qn)===0){s.defer_effect(t);return}for(;e.parent!==null;){e=e.parent;var n=e.f;if(gr&&e===Qe&&(n&nn)!==0&&(n&Yo)===0&&(n&Qn)!==0)return;if((n&(On|Ts))!==0){if((n&Ft)===0)return;e.f^=Ft}}es.push(e)}function cc(t,e){if(!((t.f&Ts)!==0&&(t.f&Ft)!==0)){(t.f&Dt)!==0?e.d.push(t):(t.f&Fs)!==0&&e.m.push(t),wt(t,Ft);for(var s=t.first;s!==null;)cc(s,e),s=s.next}}function ku(t){let e=0,s=Un(0),n;return()=>{zr()&&(c(s),Ur(()=>(e===0&&(n=Ga(()=>t(()=>Ea(s)))),e+=1,()=>{$s(()=>{e-=1,e===0&&(n?.(),n=void 0,Ea(s))})})))}}var Su=zn|oa;function Cu(t,e,s,n){new Eu(t,e,s,n)}class Eu{parent;is_pending=!1;transform_error;#t;#l=null;#e;#i;#s;#r=null;#n=null;#a=null;#o=null;#d=0;#c=0;#u=!1;#f=new Set;#_=new Set;#h=null;#b=ku(()=>(this.#h=Un(this.#d),()=>{this.#h=null}));constructor(e,s,n,a){this.#t=e,this.#e=s,this.#i=i=>{var r=Qe;r.b=this,r.f|=vr,n(i)},this.parent=Qe.b,this.transform_error=a??this.parent?.transform_error??(i=>i),this.#s=Mi(()=>{this.#g()},Su)}#m(){try{this.#r=ps(()=>this.#i(this.#t))}catch(e){this.error(e)}}#w(e){const s=this.#e.failed;s&&(this.#a=ps(()=>{s(this.#t,()=>e,()=>()=>{})}))}#y(){const e=this.#e.pending;e&&(this.is_pending=!0,this.#n=ps(()=>e(this.#t)),$s(()=>{var s=this.#o=document.createDocumentFragment(),n=en();s.append(n),this.#r=this.#p(()=>(gn.ensure(),ps(()=>this.#i(n)))),this.#c===0&&(this.#t.before(s),this.#o=null,Dn(this.#n,()=>{this.#n=null}),this.#v())}))}#g(){try{if(this.is_pending=this.has_pending_snippet(),this.#c=0,this.#d=0,this.#r=ps(()=>{this.#i(this.#t)}),this.#c>0){var e=this.#o=document.createDocumentFragment();Kc(this.#r,e);const s=this.#e.pending;this.#n=ps(()=>s(this.#t))}else this.#v()}catch(s){this.error(s)}}#v(){this.is_pending=!1;for(const e of this.#f)wt(e,Dt),Es(e);for(const e of this.#_)wt(e,Fs),Es(e);this.#f.clear(),this.#_.clear()}defer_effect(e){ic(e,this.#f,this.#_)}is_rendered(){return!this.is_pending&&(!this.parent||this.parent.is_rendered())}has_pending_snippet(){return!!this.#e.pending}#p(e){var s=Qe,n=Ie,a=Tt;Qs(this.#s),ws(this.#s),na(this.#s.ctx);try{return e()}catch(i){return nc(i),null}finally{Qs(s),ws(n),na(a)}}#x(e){if(!this.has_pending_snippet()){this.parent&&this.parent.#x(e);return}this.#c+=e,this.#c===0&&(this.#v(),this.#n&&Dn(this.#n,()=>{this.#n=null}),this.#o&&(this.#t.before(this.#o),this.#o=null))}update_pending_count(e){this.#x(e),this.#d+=e,!(!this.#h||this.#u)&&(this.#u=!0,$s(()=>{this.#u=!1,this.#h&&aa(this.#h,this.#d)}))}get_effect_pending(){return this.#b(),c(this.#h)}error(e){var s=this.#e.onerror;let n=this.#e.failed;if(!s&&!n)throw e;this.#r&&(as(this.#r),this.#r=null),this.#n&&(as(this.#n),this.#n=null),this.#a&&(as(this.#a),this.#a=null);var a=!1,i=!1;const r=()=>{if(a){vu();return}a=!0,i&&eu(),this.#a!==null&&Dn(this.#a,()=>{this.#a=null}),this.#p(()=>{gn.ensure(),this.#g()})},l=d=>{try{i=!0,s?.(d,r),i=!1}catch(o){fn(o,this.#s&&this.#s.parent)}n&&(this.#a=this.#p(()=>{gn.ensure();try{return ps(()=>{var o=Qe;o.b=this,o.f|=vr,n(this.#t,()=>d,()=>r)})}catch(o){return fn(o,this.#s.parent),null}}))};$s(()=>{var d;try{d=this.transform_error(e)}catch(o){fn(o,this.#s&&this.#s.parent);return}d!==null&&typeof d=="object"&&typeof d.then=="function"?d.then(l,o=>fn(o,this.#s&&this.#s.parent)):l(d)})}}function Au(t,e,s,n){const a=Ua()?Ha:Ir;var i=t.filter(_=>!_.settled);if(s.length===0&&i.length===0){n(e.map(a));return}var r=Qe,l=Ku(),d=i.length===1?i[0].promise:i.length>1?Promise.all(i.map(_=>_.promise)):null;function o(_){l();try{n(_)}catch(p){(r.f&Zs)===0&&fn(p,r)}xr()}if(s.length===0){d.then(()=>o(e.map(a)));return}function u(){l(),Promise.all(s.map(_=>Tu(_))).then(_=>o([...e.map(a),..._])).catch(_=>fn(_,r))}d?d.then(u):u()}function Ku(){var t=Qe,e=Ie,s=Tt,n=Ne;return function(i=!0){Qs(t),ws(e),na(s),i&&n?.activate()}}function xr(t=!0){Qs(null),ws(null),na(null),t&&Ne?.deactivate()}function Fu(){var t=Qe.b,e=Ne,s=t.is_rendered();return t.update_pending_count(1),e.increment(s),()=>{t.update_pending_count(-1),e.decrement(s)}}function Ha(t){var e=Bt|Dt,s=Ie!==null&&(Ie.f&Bt)!==0?Ie:null;return Qe!==null&&(Qe.f|=oa),{ctx:Tt,deps:null,effects:null,equals:ec,f:e,fn:t,reactions:null,rv:0,v:Lt,wv:0,parent:s??Qe,ac:null}}function Tu(t,e,s){Qe===null&&Od();var a=void 0,i=Un(Lt),r=!Ie,l=new Map;return Hu(()=>{var d=Wo();a=d.promise;try{Promise.resolve(t()).then(d.resolve,d.reject).finally(xr)}catch(p){d.reject(p),xr()}var o=Ne;if(r){var u=Fu();l.get(o)?.reject(Mn),l.delete(o),l.set(o,d)}const _=(p,v=void 0)=>{if(o.activate(),v)v!==Mn&&(i.f|=pn,aa(i,v));else{(i.f&pn)!==0&&(i.f^=pn),aa(i,p);for(const[x,y]of l){if(l.delete(x),x===o)break;y.reject(Mn)}}u&&u()};d.promise.then(_,p=>_(null,p||"unknown"))}),Nr(()=>{for(const d of l.values())d.reject(Mn)}),new Promise(d=>{function o(u){function _(){u===a?d(i):o(a)}u.then(_,_)}o(a)})}function Ae(t){const e=Ha(t);return Fc(e),e}function Ir(t){const e=Ha(t);return e.equals=tc,e}function Mu(t){var e=t.effects;if(e!==null){t.effects=null;for(var s=0;s<e.length;s+=1)as(e[s])}}function Xu(t){for(var e=t.parent;e!==null;){if((e.f&Bt)===0)return(e.f&Zs)===0?e:null;e=e.parent}return null}function Qr(t){var e,s=Qe;Qs(Xu(t));try{t.f&=~Nn,Mu(t),e=Lc(t)}finally{Qs(s)}return e}function dc(t){var e=Qr(t);if(!t.equals(e)&&(t.wv=Mc(),(!Ne?.is_fork||t.deps===null)&&(t.v=e,t.deps===null))){wt(t,Ft);return}yn||(Cs!==null?(zr()||Ne?.is_fork)&&Cs.set(t,e):Rr(t))}function Lu(t){if(t.effects!==null)for(const e of t.effects)(e.teardown||e.ac)&&(e.teardown?.(),e.ac?.abort(Mn),e.teardown=ba,e.ac=null,La(e,0),Hr(e))}function uc(t){if(t.effects!==null)for(const e of t.effects)e.teardown&&ia(e)}let br=new Set;const xn=new Map;let hc=!1;function Un(t,e){var s={f:0,v:t,reactions:null,equals:ec,rv:0,wv:0};return s}function q(t,e){const s=Un(t);return Fc(s),s}function Pu(t,e=!1,s=!0){const n=Un(t);return e||(n.equals=tc),Na&&s&&Tt!==null&&Tt.l!==null&&(Tt.l.s??=[]).push(n),n}function b(t,e,s=!1){Ie!==null&&(!As||(Ie.f&ol)!==0)&&Ua()&&(Ie.f&(Bt|nn|Dr|ol))!==0&&(ms===null||!sa.call(ms,t))&&$d();let n=s?He(e):e;return aa(t,n)}function aa(t,e){if(!t.equals(e)){var s=t.v;yn?xn.set(t,e):xn.set(t,s),t.v=e;var n=gn.ensure();if(n.capture(t,s),(t.f&Bt)!==0){const a=t;(t.f&Dt)!==0&&Qr(a),Rr(a)}t.wv=Mc(),fc(t,Dt),Ua()&&Qe!==null&&(Qe.f&Ft)!==0&&(Qe.f&(Ts|On))===0&&(vs===null?Vu([t]):vs.push(t)),!n.is_fork&&br.size>0&&!hc&&Bu()}return e}function Bu(){hc=!1;for(const t of br)(t.f&Ft)!==0&&wt(t,Fs),Va(t)&&ia(t);br.clear()}function mr(t,e=1){var s=c(t),n=e===1?s++:s--;return b(t,s),n}function Ea(t){b(t,t.v+1)}function fc(t,e){var s=t.reactions;if(s!==null)for(var n=Ua(),a=s.length,i=0;i<a;i++){var r=s[i],l=r.f;if(!(!n&&r===Qe)){var d=(l&Dt)===0;if(d&&wt(r,e),(l&Bt)!==0){var o=r;Cs?.delete(o),(l&Nn)===0&&(l&bs&&(r.f|=Nn),fc(o,Fs))}else d&&((l&nn)!==0&&qs!==null&&qs.add(r),Es(r))}}}function He(t){if(typeof t!="object"||t===null||Js in t)return t;const e=Br(t);if(e!==Id&&e!==Qd)return t;var s=new Map,n=Pr(t),a=q(0),i=Rn,r=l=>{if(Rn===i)return l();var d=Ie,o=Rn;ws(null),fl(i);var u=l();return ws(d),fl(o),u};return n&&s.set("length",q(t.length)),new Proxy(t,{defineProperty(l,d,o){(!("value"in o)||o.configurable===!1||o.enumerable===!1||o.writable===!1)&&Zd();var u=s.get(d);return u===void 0?r(()=>{var _=q(o.value);return s.set(d,_),_}):b(u,o.value,!0),!0},deleteProperty(l,d){var o=s.get(d);if(o===void 0){if(d in l){const u=r(()=>q(Lt));s.set(d,u),Ea(a)}}else b(o,Lt),Ea(a);return!0},get(l,d,o){if(d===Js)return t;var u=s.get(d),_=d in l;if(u===void 0&&(!_||$n(l,d)?.writable)&&(u=r(()=>{var v=He(_?l[d]:Lt),x=q(v);return x}),s.set(d,u)),u!==void 0){var p=c(u);return p===Lt?void 0:p}return Reflect.get(l,d,o)},getOwnPropertyDescriptor(l,d){var o=Reflect.getOwnPropertyDescriptor(l,d);if(o&&"value"in o){var u=s.get(d);u&&(o.value=c(u))}else if(o===void 0){var _=s.get(d),p=_?.v;if(_!==void 0&&p!==Lt)return{enumerable:!0,configurable:!0,value:p,writable:!0}}return o},has(l,d){if(d===Js)return!0;var o=s.get(d),u=o!==void 0&&o.v!==Lt||Reflect.has(l,d);if(o!==void 0||Qe!==null&&(!u||$n(l,d)?.writable)){o===void 0&&(o=r(()=>{var p=u?He(l[d]):Lt,v=q(p);return v}),s.set(d,o));var _=c(o);if(_===Lt)return!1}return u},set(l,d,o,u){var _=s.get(d),p=d in l;if(n&&d==="length")for(var v=o;v<_.v;v+=1){var x=s.get(v+"");x!==void 0?b(x,Lt):v in l&&(x=r(()=>q(Lt)),s.set(v+"",x))}if(_===void 0)(!p||$n(l,d)?.writable)&&(_=r(()=>q(void 0)),b(_,He(o)),s.set(d,_));else{p=_.v!==Lt;var y=r(()=>He(o));b(_,y)}var w=Reflect.getOwnPropertyDescriptor(l,d);if(w?.set&&w.set.call(u,o),!p){if(n&&typeof d=="string"){var S=s.get("length"),E=Number(d);Number.isInteger(E)&&E>=S.v&&b(S,E+1)}Ea(a)}return!0},ownKeys(l){c(a);var d=Reflect.ownKeys(l).filter(_=>{var p=s.get(_);return p===void 0||p.v!==Lt});for(var[o,u]of s)u.v!==Lt&&!(o in l)&&d.push(o);return d},setPrototypeOf(){Jd()}})}function dl(t){try{if(t!==null&&typeof t=="object"&&Js in t)return t[Js]}catch{}return t}function Du(t,e){return Object.is(dl(t),dl(e))}var gi,_c,vc,pc;function Ru(){if(gi===void 0){gi=window,_c=/Firefox/.test(navigator.userAgent);var t=Element.prototype,e=Node.prototype,s=Text.prototype;vc=$n(e,"firstChild").get,pc=$n(e,"nextSibling").get,ll(t)&&(t.__click=void 0,t.__className=void 0,t.__attributes=null,t.__style=void 0,t.__e=void 0),ll(s)&&(s.__t=void 0)}}function en(t=""){return document.createTextNode(t)}function tn(t){return vc.call(t)}function Oa(t){return pc.call(t)}function h(t,e){return tn(t)}function Ce(t,e=!1){{var s=tn(t);return s instanceof Comment&&s.data===""?Oa(s):s}}function f(t,e=1,s=!1){let n=t;for(;e--;)n=Oa(n);return n}function Iu(t){t.textContent=""}function gc(){return!1}function xc(t,e,s){return document.createElementNS(e??$o,t,void 0)}let ul=!1;function Qu(){ul||(ul=!0,document.addEventListener("reset",t=>{Promise.resolve().then(()=>{if(!t.defaultPrevented)for(const e of t.target.elements)e.__on_r?.()})},{capture:!0}))}function Ti(t){var e=Ie,s=Qe;ws(null),Qs(null);try{return t()}finally{ws(e),Qs(s)}}function bc(t,e,s,n=s){t.addEventListener(e,()=>Ti(s));const a=t.__on_r;a?t.__on_r=()=>{a(),n(!0)}:t.__on_r=()=>n(!0),Qu()}function mc(t){Qe===null&&(Ie===null&&Wd(),qd()),yn&&Gd()}function zu(t,e){var s=e.last;s===null?e.last=e.first=t:(s.next=t,t.prev=s,e.last=t)}function zs(t,e,s){var n=Qe;n!==null&&(n.f&us)!==0&&(t|=us);var a={ctx:Tt,deps:null,nodes:null,f:t|Dt|bs,first:null,fn:e,last:null,next:null,parent:n,b:n&&n.b,prev:null,teardown:null,wv:0,ac:null};if(s)try{ia(a)}catch(l){throw as(a),l}else e!==null&&Es(a);var i=a;if(s&&i.deps===null&&i.teardown===null&&i.nodes===null&&i.first===i.last&&(i.f&oa)===0&&(i=i.first,(t&nn)!==0&&(t&zn)!==0&&i!==null&&(i.f|=zn)),i!==null&&(i.parent=n,n!==null&&zu(i,n),Ie!==null&&(Ie.f&Bt)!==0&&(t&On)===0)){var r=Ie;(r.effects??=[]).push(i)}return a}function zr(){return Ie!==null&&!As}function Nr(t){const e=zs(za,null,!1);return wt(e,Ft),e.teardown=t,e}function mt(t){mc();var e=Qe.f,s=!Ie&&(e&Ts)!==0&&(e&Qn)===0;if(s){var n=Tt;(n.e??=[]).push(t)}else return wc(t)}function wc(t){return zs(Qa|Zo,t,!1)}function Nu(t){return mc(),zs(za|Zo,t,!0)}function Uu(t){gn.ensure();const e=zs(On|oa,t,!0);return(s={})=>new Promise(n=>{s.outro?Dn(e,()=>{as(e),n(void 0)}):(as(e),n(void 0))})}function yc(t){return zs(Qa,t,!1)}function Hu(t){return zs(Dr|oa,t,!0)}function Ur(t,e=0){return zs(za|e,t,!0)}function O(t,e=[],s=[],n=[]){Au(n,e,s,a=>{zs(za,()=>t(...a.map(c)),!0)})}function Mi(t,e=0){var s=zs(nn|e,t,!0);return s}function ps(t){return zs(Ts|oa,t,!0)}function kc(t){var e=t.teardown;if(e!==null){const s=yn,n=Ie;hl(!0),ws(null);try{e.call(null)}finally{hl(s),ws(n)}}}function Hr(t,e=!1){var s=t.first;for(t.first=t.last=null;s!==null;){const a=s.ac;a!==null&&Ti(()=>{a.abort(Mn)});var n=s.next;(s.f&On)!==0?s.parent=null:as(s,e),s=n}}function Ou(t){for(var e=t.first;e!==null;){var s=e.next;(e.f&Ts)===0&&as(e),e=s}}function as(t,e=!0){var s=!1;(e||(t.f&Yo)!==0)&&t.nodes!==null&&t.nodes.end!==null&&(Sc(t.nodes.start,t.nodes.end),s=!0),Hr(t,e&&!s),La(t,0),wt(t,Zs);var n=t.nodes&&t.nodes.t;if(n!==null)for(const i of n)i.stop();kc(t);var a=t.parent;a!==null&&a.first!==null&&Cc(t),t.next=t.prev=t.teardown=t.ctx=t.deps=t.fn=t.nodes=t.ac=null}function Sc(t,e){for(;t!==null;){var s=t===e?null:Oa(t);t.remove(),t=s}}function Cc(t){var e=t.parent,s=t.prev,n=t.next;s!==null&&(s.next=n),n!==null&&(n.prev=s),e!==null&&(e.first===t&&(e.first=n),e.last===t&&(e.last=s))}function Dn(t,e,s=!0){var n=[];Ec(t,n,!0);var a=()=>{s&&as(t),e&&e()},i=n.length;if(i>0){var r=()=>--i||a();for(var l of n)l.out(r)}else a()}function Ec(t,e,s){if((t.f&us)===0){t.f^=us;var n=t.nodes&&t.nodes.t;if(n!==null)for(const l of n)(l.is_global||s)&&e.push(l);for(var a=t.first;a!==null;){var i=a.next,r=(a.f&zn)!==0||(a.f&Ts)!==0&&(t.f&nn)!==0;Ec(a,e,r?s:!1),a=i}}}function Or(t){Ac(t,!0)}function Ac(t,e){if((t.f&us)!==0){t.f^=us,(t.f&Ft)===0&&(wt(t,Dt),Es(t));for(var s=t.first;s!==null;){var n=s.next,a=(s.f&zn)!==0||(s.f&Ts)!==0;Ac(s,a?e:!1),s=n}var i=t.nodes&&t.nodes.t;if(i!==null)for(const r of i)(r.is_global||e)&&r.in()}}function Kc(t,e){if(t.nodes)for(var s=t.nodes.start,n=t.nodes.end;s!==null;){var a=s===n?null:Oa(s);e.append(s),s=a}}let ui=!1,yn=!1;function hl(t){yn=t}let Ie=null,As=!1;function ws(t){Ie=t}let Qe=null;function Qs(t){Qe=t}let ms=null;function Fc(t){Ie!==null&&(ms===null?ms=[t]:ms.push(t))}let ts=null,cs=0,vs=null;function Vu(t){vs=t}let Tc=1,Ln=0,Rn=Ln;function fl(t){Rn=t}function Mc(){return++Tc}function Va(t){var e=t.f;if((e&Dt)!==0)return!0;if(e&Bt&&(t.f&=~Nn),(e&Fs)!==0){for(var s=t.deps,n=s.length,a=0;a<n;a++){var i=s[a];if(Va(i)&&dc(i),i.wv>t.wv)return!0}(e&bs)!==0&&Cs===null&&wt(t,Ft)}return!1}function Xc(t,e,s=!0){var n=t.reactions;if(n!==null&&!(ms!==null&&sa.call(ms,t)))for(var a=0;a<n.length;a++){var i=n[a];(i.f&Bt)!==0?Xc(i,e,!1):e===i&&(s?wt(i,Dt):(i.f&Ft)!==0&&wt(i,Fs),Es(i))}}function Lc(t){var e=ts,s=cs,n=vs,a=Ie,i=ms,r=Tt,l=As,d=Rn,o=t.f;ts=null,cs=0,vs=null,Ie=(o&(Ts|On))===0?t:null,ms=null,na(t.ctx),As=!1,Rn=++Ln,t.ac!==null&&(Ti(()=>{t.ac.abort(Mn)}),t.ac=null);try{t.f|=pr;var u=t.fn,_=u();t.f|=Qn;var p=t.deps,v=Ne?.is_fork;if(ts!==null){var x;if(v||La(t,cs),p!==null&&cs>0)for(p.length=cs+ts.length,x=0;x<ts.length;x++)p[cs+x]=ts[x];else t.deps=p=ts;if(zr()&&(t.f&bs)!==0)for(x=cs;x<p.length;x++)(p[x].reactions??=[]).push(t)}else!v&&p!==null&&cs<p.length&&(La(t,cs),p.length=cs);if(Ua()&&vs!==null&&!As&&p!==null&&(t.f&(Bt|Fs|Dt))===0)for(x=0;x<vs.length;x++)Xc(vs[x],t);if(a!==null&&a!==t){if(Ln++,a.deps!==null)for(let y=0;y<s;y+=1)a.deps[y].rv=Ln;if(e!==null)for(const y of e)y.rv=Ln;vs!==null&&(n===null?n=vs:n.push(...vs))}return(t.f&pn)!==0&&(t.f^=pn),_}catch(y){return nc(y)}finally{t.f^=pr,ts=e,cs=s,vs=n,Ie=a,ms=i,na(r),As=l,Rn=d}}function Gu(t,e){let s=e.reactions;if(s!==null){var n=Dd.call(s,t);if(n!==-1){var a=s.length-1;a===0?s=e.reactions=null:(s[n]=s[a],s.pop())}}if(s===null&&(e.f&Bt)!==0&&(ts===null||!sa.call(ts,e))){var i=e;(i.f&bs)!==0&&(i.f^=bs,i.f&=~Nn),Rr(i),Lu(i),La(i,0)}}function La(t,e){var s=t.deps;if(s!==null)for(var n=e;n<s.length;n++)Gu(t,s[n])}function ia(t){var e=t.f;if((e&Zs)===0){wt(t,Ft);var s=Qe,n=ui;Qe=t,ui=!0;try{(e&(nn|jo))!==0?Ou(t):Hr(t),kc(t);var a=Lc(t);t.teardown=typeof a=="function"?a:null,t.wv=Tc;var i;fr&&gu&&(t.f&Dt)!==0&&t.deps}finally{ui=n,Qe=s}}}async function Pc(){await Promise.resolve(),wu()}function c(t){var e=t.f,s=(e&Bt)!==0;if(Ie!==null&&!As){var n=Qe!==null&&(Qe.f&Zs)!==0;if(!n&&(ms===null||!sa.call(ms,t))){var a=Ie.deps;if((Ie.f&pr)!==0)t.rv<Ln&&(t.rv=Ln,ts===null&&a!==null&&a[cs]===t?cs++:ts===null?ts=[t]:ts.push(t));else{(Ie.deps??=[]).push(t);var i=t.reactions;i===null?t.reactions=[Ie]:sa.call(i,Ie)||i.push(Ie)}}}if(yn&&xn.has(t))return xn.get(t);if(s){var r=t;if(yn){var l=r.v;return((r.f&Ft)===0&&r.reactions!==null||Dc(r))&&(l=Qr(r)),xn.set(r,l),l}var d=(r.f&bs)===0&&!As&&Ie!==null&&(ui||(Ie.f&bs)!==0),o=(r.f&Qn)===0;Va(r)&&(d&&(r.f|=bs),dc(r)),d&&!o&&(uc(r),Bc(r))}if(Cs?.has(t))return Cs.get(t);if((t.f&pn)!==0)throw t.v;return t.v}function Bc(t){if(t.f|=bs,t.deps!==null)for(const e of t.deps)(e.reactions??=[]).push(t),(e.f&Bt)!==0&&(e.f&bs)===0&&(uc(e),Bc(e))}function Dc(t){if(t.v===Lt)return!0;if(t.deps===null)return!1;for(const e of t.deps)if(xn.has(e)||(e.f&Bt)!==0&&Dc(e))return!0;return!1}function Ga(t){var e=As;try{return As=!0,t()}finally{As=e}}function qu(t){if(!(typeof t!="object"||!t||t instanceof EventTarget)){if(Js in t)wr(t);else if(!Array.isArray(t))for(let e in t){const s=t[e];typeof s=="object"&&s&&Js in s&&wr(s)}}}function wr(t,e=new Set){if(typeof t=="object"&&t!==null&&!(t instanceof EventTarget)&&!e.has(t)){e.add(t),t instanceof Date&&t.getTime();for(let n in t)try{wr(t[n],e)}catch{}const s=Br(t);if(s!==Object.prototype&&s!==Array.prototype&&s!==Map.prototype&&s!==Set.prototype&&s!==Date.prototype){const n=qo(s);for(let a in n){const i=n[a].get;if(i)try{i.call(t)}catch{}}}}}const Wu=["touchstart","touchmove"];function ju(t){return Wu.includes(t)}const ma=Symbol("events"),Rc=new Set,yr=new Set;function Yu(t,e,s,n={}){function a(i){if(n.capture||kr.call(e,i),!i.cancelBubble)return Ti(()=>s?.call(this,i))}return t.startsWith("pointer")||t.startsWith("touch")||t==="wheel"?$s(()=>{e.addEventListener(t,a,n)}):e.addEventListener(t,a,n),a}function In(t,e,s,n,a){var i={capture:n,passive:a},r=Yu(t,e,s,i);(e===document.body||e===window||e===document||e instanceof HTMLMediaElement)&&Nr(()=>{e.removeEventListener(t,r,i)})}function V(t,e,s){(e[ma]??={})[t]=s}function ht(t){for(var e=0;e<t.length;e++)Rc.add(t[e]);for(var s of yr)s(t)}let _l=null;function kr(t){var e=this,s=e.ownerDocument,n=t.type,a=t.composedPath?.()||[],i=a[0]||t.target;_l=t;var r=0,l=_l===t&&t[ma];if(l){var d=a.indexOf(l);if(d!==-1&&(e===document||e===window)){t[ma]=e;return}var o=a.indexOf(e);if(o===-1)return;d<=o&&(r=d)}if(i=a[r]||t.target,i!==e){Rd(t,"currentTarget",{configurable:!0,get(){return i||s}});var u=Ie,_=Qe;ws(null),Qs(null);try{for(var p,v=[];i!==null;){var x=i.assignedSlot||i.parentNode||i.host||null;try{var y=i[ma]?.[n];y!=null&&(!i.disabled||t.target===i)&&y.call(i,t)}catch(w){p?v.push(w):p=w}if(t.cancelBubble||x===e||x===null)break;i=x}if(p){for(let w of v)queueMicrotask(()=>{throw w});throw p}}finally{t[ma]=e,delete t.currentTarget,ws(u),Qs(_)}}}const Zu=globalThis?.window?.trustedTypes&&globalThis.window.trustedTypes.createPolicy("svelte-trusted-html",{createHTML:t=>t});function Ju(t){return Zu?.createHTML(t)??t}function Ic(t){var e=xc("template");return e.innerHTML=Ju(t.replaceAll("<!>","<!---->")),e.content}function ra(t,e){var s=Qe;s.nodes===null&&(s.nodes={start:t,end:e,a:null,t:null})}function T(t,e){var s=(e&du)!==0,n=(e&uu)!==0,a,i=!t.startsWith("<!>");return()=>{a===void 0&&(a=Ic(i?t:"<!>"+t),s||(a=tn(a)));var r=n||_c?document.importNode(a,!0):a.cloneNode(!0);if(s){var l=tn(r),d=r.lastChild;ra(l,d)}else ra(r,r);return r}}function $u(t,e,s="svg"){var n=!t.startsWith("<!>"),a=`<${s}>${n?t:"<!>"+t}</${s}>`,i;return()=>{if(!i){var r=Ic(a),l=tn(r);i=tn(l)}var d=i.cloneNode(!0);return ra(d,d),d}}function Cn(t,e){return $u(t,e,"svg")}function Is(t=""){{var e=en(t+"");return ra(e,e),e}}function bt(){var t=document.createDocumentFragment(),e=document.createComment(""),s=en();return t.append(e,s),ra(e,s),t}function k(t,e){t!==null&&t.before(e)}function M(t,e){var s=e==null?"":typeof e=="object"?e+"":e;s!==(t.__t??=t.nodeValue)&&(t.__t=s,t.nodeValue=s+"")}function eh(t,e){return th(t,e)}const Ja=new Map;function th(t,{target:e,anchor:s,props:n={},events:a,context:i,intro:r=!0,transformError:l}){Ru();var d=void 0,o=Uu(()=>{var u=s??e.appendChild(en());Cu(u,{pending:()=>{}},v=>{st({});var x=Tt;i&&(x.c=i),a&&(n.$$events=a),d=t(v,n)||{},nt()},l);var _=new Set,p=v=>{for(var x=0;x<v.length;x++){var y=v[x];if(!_.has(y)){_.add(y);var w=ju(y);for(const K of[e,document]){var S=Ja.get(K);S===void 0&&(S=new Map,Ja.set(K,S));var E=S.get(y);E===void 0?(K.addEventListener(y,kr,{passive:w}),S.set(y,1)):S.set(y,E+1)}}}};return p(Ki(Rc)),yr.add(p),()=>{for(var v of _)for(const w of[e,document]){var x=Ja.get(w),y=x.get(v);--y==0?(w.removeEventListener(v,kr),x.delete(v),x.size===0&&Ja.delete(w)):x.set(v,y)}yr.delete(p),u!==s&&u.parentNode?.removeChild(u)}});return sh.set(d,o),d}let sh=new WeakMap;class Qc{anchor;#t=new Map;#l=new Map;#e=new Map;#i=new Set;#s=!0;constructor(e,s=!0){this.anchor=e,this.#s=s}#r=()=>{var e=Ne;if(this.#t.has(e)){var s=this.#t.get(e),n=this.#l.get(s);if(n)Or(n),this.#i.delete(s);else{var a=this.#e.get(s);a&&(this.#l.set(s,a.effect),this.#e.delete(s),a.fragment.lastChild.remove(),this.anchor.before(a.fragment),n=a.effect)}for(const[i,r]of this.#t){if(this.#t.delete(i),i===e)break;const l=this.#e.get(r);l&&(as(l.effect),this.#e.delete(r))}for(const[i,r]of this.#l){if(i===s||this.#i.has(i))continue;const l=()=>{if(Array.from(this.#t.values()).includes(i)){var o=document.createDocumentFragment();Kc(r,o),o.append(en()),this.#e.set(i,{effect:r,fragment:o})}else as(r);this.#i.delete(i),this.#l.delete(i)};this.#s||!n?(this.#i.add(i),Dn(r,l,!1)):l()}}};#n=e=>{this.#t.delete(e);const s=Array.from(this.#t.values());for(const[n,a]of this.#e)s.includes(n)||(as(a.effect),this.#e.delete(n))};ensure(e,s){var n=Ne,a=gc();if(s&&!this.#l.has(e)&&!this.#e.has(e))if(a){var i=document.createDocumentFragment(),r=en();i.append(r),this.#e.set(e,{effect:ps(()=>s(r)),fragment:i})}else this.#l.set(e,ps(()=>s(this.anchor)));if(this.#t.set(n,e),a){for(const[l,d]of this.#l)l===e?n.unskip_effect(d):n.skip_effect(d);for(const[l,d]of this.#e)l===e?n.unskip_effect(d.effect):n.skip_effect(d.effect);n.oncommit(this.#r),n.ondiscard(this.#n)}else this.#r()}}function H(t,e,s=!1){var n=new Qc(t),a=s?zn:0;function i(r,l){n.ensure(r,l)}Mi(()=>{var r=!1;e((l,d=0)=>{r=!0,i(d,l)}),r||i(!1,null)},a)}function Vr(t,e){return e}function nh(t,e,s){for(var n=[],a=e.length,i,r=e.length,l=0;l<a;l++){let _=e[l];Dn(_,()=>{if(i){if(i.pending.delete(_),i.done.add(_),i.pending.size===0){var p=t.outrogroups;Sr(Ki(i.done)),p.delete(i),p.size===0&&(t.outrogroups=null)}}else r-=1},!1)}if(r===0){var d=n.length===0&&s!==null;if(d){var o=s,u=o.parentNode;Iu(u),u.append(o),t.items.clear()}Sr(e,!d)}else i={pending:new Set(e),done:new Set},(t.outrogroups??=new Set).add(i)}function Sr(t,e=!0){for(var s=0;s<t.length;s++)as(t[s],e)}var vl;function Et(t,e,s,n,a,i=null){var r=t,l=new Map,d=(e&Jo)!==0;if(d){var o=t;r=o.appendChild(en())}var u=null,_=Ir(()=>{var S=s();return Pr(S)?S:S==null?[]:Ki(S)}),p,v=!0;function x(){w.fallback=u,ah(w,p,r,e,n),u!==null&&(p.length===0?(u.f&Ys)===0?Or(u):(u.f^=Ys,wa(u,null,r)):Dn(u,()=>{u=null}))}var y=Mi(()=>{p=c(_);for(var S=p.length,E=new Set,K=Ne,A=gc(),U=0;U<S;U+=1){var ee=p[U],X=n(ee,U),C=v?null:l.get(X);C?(C.v&&aa(C.v,ee),C.i&&aa(C.i,U),A&&K.unskip_effect(C.e)):(C=ih(l,v?r:vl??=en(),ee,X,U,a,e,s),v||(C.e.f|=Ys),l.set(X,C)),E.add(X)}if(S===0&&i&&!u&&(v?u=ps(()=>i(r)):(u=ps(()=>i(vl??=en())),u.f|=Ys)),S>E.size&&Vd(),!v)if(A){for(const[F,L]of l)E.has(F)||K.skip_effect(L.e);K.oncommit(x),K.ondiscard(()=>{})}else x();c(_)}),w={effect:y,items:l,outrogroups:null,fallback:u};v=!1}function ua(t){for(;t!==null&&(t.f&Ts)===0;)t=t.next;return t}function ah(t,e,s,n,a){var i=(n&nu)!==0,r=e.length,l=t.items,d=ua(t.effect.first),o,u=null,_,p=[],v=[],x,y,w,S;if(i)for(S=0;S<r;S+=1)x=e[S],y=a(x,S),w=l.get(y).e,(w.f&Ys)===0&&(w.nodes?.a?.measure(),(_??=new Set).add(w));for(S=0;S<r;S+=1){if(x=e[S],y=a(x,S),w=l.get(y).e,t.outrogroups!==null)for(const L of t.outrogroups)L.pending.delete(w),L.done.delete(w);if((w.f&Ys)!==0)if(w.f^=Ys,w===d)wa(w,null,s);else{var E=u?u.next:d;w===t.effect.last&&(t.effect.last=w.prev),w.prev&&(w.prev.next=w.next),w.next&&(w.next.prev=w.prev),cn(t,u,w),cn(t,w,E),wa(w,E,s),u=w,p=[],v=[],d=ua(u.next);continue}if((w.f&us)!==0&&(Or(w),i&&(w.nodes?.a?.unfix(),(_??=new Set).delete(w))),w!==d){if(o!==void 0&&o.has(w)){if(p.length<v.length){var K=v[0],A;u=K.prev;var U=p[0],ee=p[p.length-1];for(A=0;A<p.length;A+=1)wa(p[A],K,s);for(A=0;A<v.length;A+=1)o.delete(v[A]);cn(t,U.prev,ee.next),cn(t,u,U),cn(t,ee,K),d=K,u=ee,S-=1,p=[],v=[]}else o.delete(w),wa(w,d,s),cn(t,w.prev,w.next),cn(t,w,u===null?t.effect.first:u.next),cn(t,u,w),u=w;continue}for(p=[],v=[];d!==null&&d!==w;)(o??=new Set).add(d),v.push(d),d=ua(d.next);if(d===null)continue}(w.f&Ys)===0&&p.push(w),u=w,d=ua(w.next)}if(t.outrogroups!==null){for(const L of t.outrogroups)L.pending.size===0&&(Sr(Ki(L.done)),t.outrogroups?.delete(L));t.outrogroups.size===0&&(t.outrogroups=null)}if(d!==null||o!==void 0){var X=[];if(o!==void 0)for(w of o)(w.f&us)===0&&X.push(w);for(;d!==null;)(d.f&us)===0&&d!==t.fallback&&X.push(d),d=ua(d.next);var C=X.length;if(C>0){var F=(n&Jo)!==0&&r===0?s:null;if(i){for(S=0;S<C;S+=1)X[S].nodes?.a?.measure();for(S=0;S<C;S+=1)X[S].nodes?.a?.fix()}nh(t,X,F)}}i&&$s(()=>{if(_!==void 0)for(w of _)w.nodes?.a?.apply()})}function ih(t,e,s,n,a,i,r,l){var d=(r&tu)!==0?(r&au)===0?Pu(s,!1,!1):Un(s):null,o=(r&su)!==0?Un(a):null;return{v:d,i:o,e:ps(()=>(i(e,d??s,o??a,l),()=>{t.delete(n)}))}}function wa(t,e,s){if(t.nodes)for(var n=t.nodes.start,a=t.nodes.end,i=e&&(e.f&Ys)===0?e.nodes.start:s;n!==null;){var r=Oa(n);if(i.before(n),n===a)return;n=r}}function cn(t,e,s){e===null?t.effect.first=s:e.next=s,s===null?t.effect.last=e:s.prev=e}function rh(t,e,s=!1,n=!1,a=!1){var i=t,r="";O(()=>{var l=Qe;if(r!==(r=e()??"")&&(l.nodes!==null&&(Sc(l.nodes.start,l.nodes.end),l.nodes=null),r!=="")){var d=s?hu:n?fu:void 0,o=xc(s?"svg":n?"math":"template",d);o.innerHTML=r;var u=s||n?o:o.content;if(ra(tn(u),u.lastChild),s||n)for(;tn(u);)i.before(tn(u));else i.before(u)}})}function pl(t,e,...s){var n=new Qc(t);Mi(()=>{const a=e()??null;n.ensure(a,a&&(i=>a(i,...s)))},zn)}function zc(t){var e,s,n="";if(typeof t=="string"||typeof t=="number")n+=t;else if(typeof t=="object")if(Array.isArray(t)){var a=t.length;for(e=0;e<a;e++)t[e]&&(s=zc(t[e]))&&(n&&(n+=" "),n+=s)}else for(s in t)t[s]&&(n&&(n+=" "),n+=s);return n}function lh(){for(var t,e,s=0,n="",a=arguments.length;s<a;s++)(t=arguments[s])&&(e=zc(t))&&(n&&(n+=" "),n+=e);return n}function oh(t){return typeof t=="object"?lh(t):t??""}const gl=[...`
|
|
2
|
+
\r\f \v\uFEFF`];function ch(t,e,s){var n=t==null?"":""+t;if(e&&(n=n?n+" "+e:e),s){for(var a of Object.keys(s))if(s[a])n=n?n+" "+a:a;else if(n.length)for(var i=a.length,r=0;(r=n.indexOf(a,r))>=0;){var l=r+i;(r===0||gl.includes(n[r-1]))&&(l===n.length||gl.includes(n[l]))?n=(r===0?"":n.substring(0,r))+n.substring(l+1):r=l}}return n===""?null:n}function me(t,e,s,n,a,i){var r=t.__className;if(r!==s||r===void 0){var l=ch(s,n,i);l==null?t.removeAttribute("class"):t.className=l,t.__className=s}else if(i&&a!==i)for(var d in i){var o=!!i[d];(a==null||o!==!!a[d])&&t.classList.toggle(d,o)}return i}function Gr(t,e,s=!1){if(t.multiple){if(e==null)return;if(!Pr(e))return _u();for(var n of t.options)n.selected=e.includes(Aa(n));return}for(n of t.options){var a=Aa(n);if(Du(a,e)){n.selected=!0;return}}(!s||e!==void 0)&&(t.selectedIndex=-1)}function Nc(t){var e=new MutationObserver(()=>{Gr(t,t.__value)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),Nr(()=>{e.disconnect()})}function Uc(t,e,s=e){var n=new WeakSet,a=!0;bc(t,"change",i=>{var r=i?"[selected]":":checked",l;if(t.multiple)l=[].map.call(t.querySelectorAll(r),Aa);else{var d=t.querySelector(r)??t.querySelector("option:not([disabled])");l=d&&Aa(d)}s(l),Ne!==null&&n.add(Ne)}),yc(()=>{var i=e();if(t===document.activeElement){var r=pi??Ne;if(n.has(r))return}if(Gr(t,i,a),a&&i===void 0){var l=t.querySelector(":checked");l!==null&&(i=Aa(l),s(i))}t.__value=i,a=!1}),Nc(t)}function Aa(t){return"__value"in t?t.__value:t.value}const dh=Symbol("is custom element"),uh=Symbol("is html"),hh=Hd?"progress":"PROGRESS";function Hc(t,e){var s=Oc(t);s.value===(s.value=e??void 0)||t.value===e&&(e!==0||t.nodeName!==hh)||(t.value=e??"")}function ns(t,e,s,n){var a=Oc(t);a[e]!==(a[e]=s)&&(e==="loading"&&(t[Ud]=s),s==null?t.removeAttribute(e):typeof s!="string"&&fh(t).includes(e)?t[e]=s:t.setAttribute(e,s))}function Oc(t){return t.__attributes??={[dh]:t.nodeName.includes("-"),[uh]:t.namespaceURI===$o}}var xl=new Map;function fh(t){var e=t.getAttribute("is")||t.nodeName,s=xl.get(e);if(s)return s;xl.set(e,s=[]);for(var n,a=t,i=Element.prototype;i!==a;){n=qo(a);for(var r in n)n[r].set&&s.push(r);a=Br(a)}return s}function Ve(t,e,s=e){var n=new WeakSet;bc(t,"input",async a=>{var i=a?t.defaultValue:t.value;if(i=Ui(t)?Hi(i):i,s(i),Ne!==null&&n.add(Ne),await Pc(),i!==(i=e())){var r=t.selectionStart,l=t.selectionEnd,d=t.value.length;if(t.value=i??"",l!==null){var o=t.value.length;r===l&&l===d&&o>d?(t.selectionStart=o,t.selectionEnd=o):(t.selectionStart=r,t.selectionEnd=Math.min(l,o))}}}),Ga(e)==null&&t.value&&(s(Ui(t)?Hi(t.value):t.value),Ne!==null&&n.add(Ne)),Ur(()=>{var a=e();if(t===document.activeElement){var i=pi??Ne;if(n.has(i))return}Ui(t)&&a===Hi(t.value)||t.type==="date"&&!a&&!t.value||a!==t.value&&(t.value=a??"")})}function Ui(t){var e=t.type;return e==="number"||e==="range"}function Hi(t){return t===""?null:+t}function bl(t,e){return t===e||t?.[Js]===e}function _h(t={},e,s,n){return yc(()=>{var a,i;return Ur(()=>{a=i,i=[],Ga(()=>{t!==s(...i)&&(e(t,...i),a&&bl(s(...a),t)&&e(null,...a))})}),()=>{$s(()=>{i&&bl(s(...i),t)&&e(null,...i)})}}),t}function Vc(t=!1){const e=Tt,s=e.l.u;if(!s)return;let n=()=>qu(e.s);if(t){let a=0,i={};const r=Ha(()=>{let l=!1;const d=e.s;for(const o in d)d[o]!==i[o]&&(i[o]=d[o],l=!0);return l&&a++,a});n=()=>c(r)}s.b.length&&Nu(()=>{ml(e,n),_r(s.b)}),mt(()=>{const a=Ga(()=>s.m.map(zd));return()=>{for(const i of a)typeof i=="function"&&i()}}),s.a.length&&mt(()=>{ml(e,n),_r(s.a)})}function ml(t,e){if(t.l.s)for(const s of t.l.s)c(s);e()}let $a=!1;function vh(t){var e=$a;try{return $a=!1,[t(),$a]}finally{$a=e}}function jn(t,e,s,n){var a=!Na||(s&ru)!==0,i=(s&ou)!==0,r=(s&cu)!==0,l=n,d=!0,o=()=>(d&&(d=!1,l=r?Ga(n):n),l),u;if(i){var _=Js in t||Nd in t;u=$n(t,e)?.set??(_&&e in t?K=>t[e]=K:void 0)}var p,v=!1;i?[p,v]=vh(()=>t[e]):p=t[e],p===void 0&&n!==void 0&&(p=o(),u&&(a&&Yd(),u(p)));var x;if(a?x=()=>{var K=t[e];return K===void 0?o():(d=!0,K)}:x=()=>{var K=t[e];return K!==void 0&&(l=void 0),K===void 0?l:K},a&&(s&lu)===0)return x;if(u){var y=t.$$legacy;return(function(K,A){return arguments.length>0?((!a||!A||y||v)&&u(A?x():K),K):x()})}var w=!1,S=((s&iu)!==0?Ha:Ir)(()=>(w=!1,x()));i&&c(S);var E=Qe;return(function(K,A){if(arguments.length>0){const U=A?c(S):a&&i?He(K):K;return b(S,U),w=!0,l!==void 0&&(l=U),K}return yn&&w||(E.f&Zs)!==0?S.v:c(S)})}const ph="5";typeof window<"u"&&((window.__svelte??={}).v??=new Set).add(ph);const qr="browserbird_auth_token",la="";let Gc=null;function gh(t){Gc=t}function Xi(){return localStorage.getItem(qr)}function wl(t){localStorage.setItem(qr,t)}function Wr(){localStorage.removeItem(qr)}async function Ee(t,e){const s={},n=Xi();n&&(s.Authorization=`Bearer ${n}`),e?.body!==void 0&&(s["Content-Type"]="application/json");const a=await fetch(`${la}${t}`,{method:e?.method??"GET",headers:s,body:e?.body!==void 0?JSON.stringify(e.body):void 0});if(a.status===401)throw Wr(),Gc?.(),new Error("Unauthorized");if(!a.ok){const i=await a.json().catch(()=>({error:a.statusText}));throw new Error(i.error??`${a.status}`)}return a.json()}async function yl(){return(await fetch(`${la}/api/auth/check`)).json()}async function xh(t,e){const s=await fetch(`${la}/api/auth/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,password:e})});if(!s.ok){const n=await s.json().catch(()=>({error:"Login failed"}));throw new Error(n.error??"Login failed")}return s.json()}async function bh(t,e){const s=await fetch(`${la}/api/auth/setup`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,password:e})});if(!s.ok){const n=await s.json().catch(()=>({error:"Setup failed"}));throw new Error(n.error??"Setup failed")}return s.json()}async function mh(){try{return await Ee("/api/auth/verify",{method:"POST"}),!0}catch{return Wr(),!1}}function kl(){const t=window.location.hash.slice(2),e=t.indexOf("?");return(e===-1?t:t.slice(0,e))||"status"}function Li(){const t=window.location.hash.slice(2),e=t.indexOf("?");return new URLSearchParams(e===-1?"":t.slice(e+1))}async function wh(){return Ee("/api/onboarding/defaults")}async function yh(t,e){return Ee("/api/onboarding/slack",{method:"POST",body:{botToken:t,appToken:e}})}async function kh(t){return Ee("/api/onboarding/agent",{method:"POST",body:t})}async function Sh(t){return Ee("/api/onboarding/auth",{method:"POST",body:t})}async function Ch(t){return Ee("/api/onboarding/browser",{method:"POST",body:t})}async function Eh(t,e){return Ee("/api/onboarding/browser/probe",{method:"POST",body:{host:t,port:e}})}async function Ah(){return Ee("/api/onboarding/complete",{method:"POST",body:{}})}let ss=null,Cr=null,Er=null,ya=null,Ka=null,Fa=null;function Sl(t,e,s){qc(),Cr=t,Er=e??null,ya=s??null;const n=Xi(),a=n?`${la}/api/events?token=${encodeURIComponent(n)}`:`${la}/api/events`;ss=new EventSource(a),Ka=i=>{ya?.("connected");try{const r=JSON.parse(i.data);Cr?.(r)}catch{}},Fa=i=>{try{const r=JSON.parse(i.data);Er?.(r)}catch{}},ss.addEventListener("status",Ka),ss.addEventListener("invalidate",Fa),ss.onerror=()=>{ya?.("disconnected")},ss.onopen=()=>{ya?.("connected")}}function qc(){ss&&(Ka&&(ss.removeEventListener("status",Ka),Ka=null),Fa&&(ss.removeEventListener("invalidate",Fa),Fa=null),ss.onerror=null,ss.onopen=null,ss.close(),ss=null),Cr=null,Er=null,ya=null}function Kh(){return ss!==null&&ss.readyState===EventSource.OPEN}const Ar=new Set;function Pi(t){return Ar.add(t),()=>Ar.delete(t)}function Cl(t){for(const e of Ar)e(t)}var Fh=T('<div class="drawer-backdrop svelte-181dlmc" role="presentation"></div>'),Th=T('<a><svg class="nav-icon svelte-181dlmc" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><!></svg> <span class="nav-label svelte-181dlmc"> </span></a>'),Mh=Cn('<path d="m9 18 6-6-6-6"></path>'),Xh=Cn('<path d="m15 18-6-6 6-6"></path>'),Lh=T('<!> <nav><div class="sidebar-brand svelte-181dlmc"><img src="/logo.svg" alt="BrowserBird" class="brand-logo brand-logo-full svelte-181dlmc"/> <img src="/logo-icon.svg" alt="BrowserBird" class="brand-logo brand-logo-icon svelte-181dlmc"/></div> <div class="sidebar-nav svelte-181dlmc"><!> <button class="nav-item signout-item svelte-181dlmc"><svg class="nav-icon svelte-181dlmc" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg> <span class="nav-label svelte-181dlmc">Sign out</span></button></div> <div class="sidebar-footer svelte-181dlmc"><button class="toggle-btn svelte-181dlmc"><svg class="toggle-icon svelte-181dlmc" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><!></svg></button></div></nav>',1);function Ph(t,e){st(e,!0);const s=[{page:"status",label:"Status",svg:'<rect width="7" height="9" x="3" y="3" rx="1"/><rect width="7" height="5" x="14" y="3" rx="1"/><rect width="7" height="9" x="14" y="12" rx="1"/><rect width="7" height="5" x="3" y="16" rx="1"/>'},{page:"sessions",label:"Sessions",svg:'<path d="M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/><path d="M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1"/>'},{page:"birds",label:"Birds",svg:'<path d="M16 7h.01"/><path d="M3.4 18H12a8 8 0 0 0 8-8V7a4 4 0 0 0-7.28-2.3L2 20"/><path d="m20 7 2 .5-2 .5"/><path d="M10 18v3"/><path d="M14 17.75V21"/><path d="M7 18a6 6 0 0 0 3.84-10.61"/>'},{page:"browser",label:"Browser",svg:'<rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/>'},{page:"settings",label:"Settings",svg:'<path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/>'}];function n(){e.onmobileclose()}var a=Lh(),i=Ce(a);{var r=E=>{var K=Fh();V("click",K,function(...A){e.onmobileclose?.apply(this,A)}),k(E,K)};H(i,E=>{e.mobileOpen&&E(r)})}var l=f(i,2);let d;var o=f(h(l),2),u=h(o);Et(u,17,()=>s,Vr,(E,K)=>{var A=Th();let U;var ee=h(A),X=h(ee);rh(X,()=>c(K).svg,!0);var C=f(ee,2),F=h(C);O(()=>{U=me(A,1,"nav-item svelte-181dlmc",null,U,{active:e.currentPage===c(K).page}),ns(A,"href",`#/${(c(K).page==="status"?"":c(K).page)??""}`),ns(A,"title",e.collapsed?c(K).label:void 0),M(F,c(K).label)}),V("click",A,n),k(E,A)});var _=f(u,2),p=f(o,2),v=h(p),x=h(v),y=h(x);{var w=E=>{var K=Mh();k(E,K)},S=E=>{var K=Xh();k(E,K)};H(y,E=>{e.collapsed?E(w):E(S,!1)})}O(()=>{d=me(l,1,"sidebar svelte-181dlmc",null,d,{collapsed:e.collapsed,"mobile-open":e.mobileOpen}),ns(_,"title",e.collapsed?"Sign out":void 0),ns(v,"title",e.collapsed?"Expand sidebar":"Collapse sidebar")}),V("click",_,function(...E){e.onsignout?.apply(this,E)}),V("click",v,function(...E){e.ontoggle?.apply(this,E)}),k(t,a),nt()}ht(["click"]);var Bh=T('<div><span></span> <span class="svc-row-label svelte-nma0bt"> </span> <span class="svc-row-detail mono svelte-nma0bt"> </span></div>'),Dh=T('<div class="svc-popover svelte-nma0bt"></div>'),Rh=T('<div class="svc-status svelte-nma0bt"><button class="svc-btn svelte-nma0bt" title="Service status"><span></span></button> <!></div>');function Ih(t,e){st(e,!0);let s=q(!1);const n=Ae(()=>e.status?[{label:"Agent CLI",ok:e.status.agent.available,detail:e.status.agent.available?"ready":"not found",applicable:!0},{label:"Slack",ok:e.status.slack.connected,detail:e.status.slack.connected?"connected":"disconnected",applicable:!0},{label:"Browser",ok:e.status.browser.connected,detail:e.status.browser.connected?"connected":"unreachable",applicable:e.status.browser.enabled}]:[]),a=Ae(()=>c(n).filter(w=>w.applicable)),i=Ae(()=>c(a).length>0&&c(a).every(w=>w.ok)),r=Ae(()=>c(a).length===0||c(a).every(w=>!w.ok)),l=Ae(()=>c(i)?"ok":c(r)?"err":"warn");function d(){b(s,!c(s))}function o(w){w.target.closest(".svc-status")||b(s,!1)}mt(()=>{if(c(s))return document.addEventListener("click",o,!0),()=>document.removeEventListener("click",o,!0)});var u=Rh(),_=h(u),p=h(_);let v;var x=f(_,2);{var y=w=>{var S=Dh();Et(S,21,()=>c(n),E=>E.label,(E,K)=>{var A=Bh();let U;var ee=h(A);let X;var C=f(ee,2),F=h(C),L=f(C,2),j=h(L);O(()=>{U=me(A,1,"svc-row svelte-nma0bt",null,U,{"svc-row-disabled":!c(K).applicable}),X=me(ee,1,"svc-row-dot svelte-nma0bt",null,X,{"svc-ok":c(K).applicable&&c(K).ok,"svc-err":c(K).applicable&&!c(K).ok,"svc-off":!c(K).applicable}),M(F,c(K).label),M(j,c(K).applicable?c(K).detail:"disabled")}),k(E,A)}),k(w,S)};H(x,w=>{c(s)&&w(y)})}O(()=>v=me(p,1,"svc-dot svelte-nma0bt",null,v,{"svc-ok":c(l)==="ok","svc-warn":c(l)==="warn","svc-err":c(l)==="err"})),V("click",_,d),k(t,u),nt()}ht(["click"]);xu();let Qh=0;const Kr=new Map;let xi=He([]);function Pe(t,e="info"){const s=Qh++;xi.push({id:s,message:t,type:e}),Kr.set(s,setTimeout(()=>Wc(s),4e3))}function Wc(t){const e=Kr.get(t);e!=null&&(clearTimeout(e),Kr.delete(t));const s=xi.findIndex(n=>n.id===t);s!==-1&&xi.splice(s,1)}var zh=T('<div><span class="toast-message svelte-1ig2a9j"> </span> <button class="toast-close svelte-1ig2a9j" aria-label="Dismiss">×</button></div>'),Nh=T('<div class="toast-container svelte-1ig2a9j"></div>');function Uh(t,e){st(e,!1),Vc();var s=Nh();Et(s,5,()=>xi,n=>n.id,(n,a)=>{var i=zh(),r=h(i),l=h(r),d=f(r,2);O(()=>{me(i,1,`toast toast-${c(a).type??""}`,"svelte-1ig2a9j"),M(l,c(a).message)}),V("click",d,()=>Wc(c(a).id)),k(n,i)}),k(t,s),nt()}ht(["click"]);const bn=He({pending:null});function jr(t){return new Promise(e=>{bn.pending={message:t,resolve:e}})}function ha(t){if(bn.pending==null)return;const{resolve:e}=bn.pending;bn.pending=null,e(t)}var Hh=T('<div class="overlay svelte-1efofyg"><button class="backdrop svelte-1efofyg" type="button" aria-label="Close dialog"></button> <div class="dialog svelte-1efofyg" role="alertdialog" aria-modal="true"><p class="message svelte-1efofyg"> </p> <div class="actions svelte-1efofyg"><button class="btn btn-outline btn-sm">Cancel</button> <button class="btn btn-danger btn-sm">Confirm</button></div></div></div>');function Oh(t,e){st(e,!1);function s(r){bn.pending&&(r.key==="Escape"&&ha(!1),r.key==="Enter"&&ha(!0))}Vc();var n=bt();In("keydown",gi,s);var a=Ce(n);{var i=r=>{var l=Hh(),d=h(l),o=f(d,2),u=h(o),_=h(u),p=f(u,2),v=h(p),x=f(v,2);O(()=>M(_,bn.pending.message)),V("click",d,()=>ha(!1)),V("click",v,()=>ha(!1)),V("click",x,()=>ha(!0)),k(r,l)};H(a,r=>{bn.pending&&r(i)})}k(t,n),nt()}ht(["click"]);function Kt(t){const e=t.indexOf("_");return e===-1?t.slice(0,10):t.slice(0,e+1+7)}function Vh(t){const e=Math.floor(t/6e4),s=Math.floor(e/1440),n=Math.floor(e%1440/60),a=e%60;return s>0?`${s}d ${n}h`:n>0?`${n}h ${a}m`:`${a}m`}function xs(t){const e=Date.now()-new Date(t+"Z").getTime(),s=Math.floor(e/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const n=Math.floor(s/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function kn(){return new Date().toLocaleTimeString()}function Gh(t){const e=new Date(t).getTime()-Date.now();if(e<=0)return"now";const s=Math.floor(e/6e4);if(s<60)return`${s}m`;const n=Math.floor(s/60),a=s%60;return n<24?a>0?`${n}h ${a}m`:`${n}h`:`${Math.floor(n/24)}d ${n%24}h`}function bi(t,e){if(!e)return"-";const s=new Date(e).getTime()-new Date(t).getTime();if(s<0)return"-";const n=Math.round(s/1e3);return n>=60?`${Math.floor(n/60)}m ${n%60}s`:`${n}s`}var qh=T('<input type="search" class="search-input svelte-b78yyc"/>'),Wh=T('<div class="table-toolbar svelte-b78yyc"><!> <!></div>'),jh=Cn('<svg class="sort-icon svelte-b78yyc" viewBox="0 0 10 6" fill="none" aria-hidden="true"><path d="M1 5L5 1L9 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>'),Yh=Cn('<svg class="sort-icon svelte-b78yyc" viewBox="0 0 10 6" fill="none" aria-hidden="true"><path d="M1 1L5 5L9 1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>'),Zh=T('<button class="sort-btn svelte-b78yyc"> <!></button>'),Jh=T("<th><!></th>"),$h=T('<tr><td class="empty-state svelte-b78yyc"> </td></tr>'),e0=T('<div class="pagination svelte-b78yyc"><button class="pg-btn svelte-b78yyc"><svg class="pg-icon svelte-b78yyc" viewBox="0 0 6 10" fill="none" aria-hidden="true"><path d="M5 1L1 5L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg> Prev</button> <span class="pg-info svelte-b78yyc"> </span> <button class="pg-btn svelte-b78yyc">Next <svg class="pg-icon svelte-b78yyc" viewBox="0 0 6 10" fill="none" aria-hidden="true"><path d="M1 1L5 5L1 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></button></div>'),t0=T('<!> <div><div class="table-scroll svelte-b78yyc"><table class="table svelte-b78yyc"><thead><tr></tr></thead><tbody><!></tbody></table></div> <!></div>',1);function hn(t,e){st(e,!0);let s=jn(e,"emptyMessage",3,"No data"),n=jn(e,"searchPlaceholder",3,"Search...");const a=Ae(()=>e.page!=null&&e.totalPages!=null&&e.onPageChange!=null);function i(X){return e.sort?e.sort===`-${X}`?"desc":e.sort===X?"asc":null:null}let r;function l(X){const C=X.target.value;clearTimeout(r),r=setTimeout(()=>e.onSearchChange?.(C),300)}var d=t0(),o=Ce(d);{var u=X=>{var C=Wh(),F=h(C);{var L=de=>{var J=bt(),N=Ce(J);pl(N,()=>e.toolbar),k(de,J)};H(F,de=>{e.toolbar&&de(L)})}var j=f(F,2);{var oe=de=>{var J=qh();O(()=>{ns(J,"placeholder",n()),Hc(J,e.search??"")}),V("input",J,l),k(de,J)};H(j,de=>{e.onSearchChange&&de(oe)})}k(X,C)};H(o,X=>{(e.toolbar||e.onSearchChange)&&X(u)})}var _=f(o,2);let p;var v=h(_),x=h(v),y=h(x),w=h(y);Et(w,21,()=>e.columns,X=>X.key,(X,C)=>{var F=Jh(),L=h(F);{var j=de=>{const J=Ae(()=>i(c(C).key));var N=Zh(),se=h(N),ae=f(se);{var ke=fe=>{var Z=jh();k(fe,Z)},we=fe=>{var Z=Yh();k(fe,Z)};H(ae,fe=>{c(J)==="asc"?fe(ke):c(J)==="desc"&&fe(we,1)})}O(()=>M(se,`${c(C).label??""} `)),V("click",N,()=>e.onSortChange(c(C).key)),k(de,N)},oe=de=>{var J=Is();O(()=>M(J,c(C).label)),k(de,J)};H(L,de=>{c(C).sortable&&e.onSortChange?de(j):de(oe,!1)})}O(()=>me(F,1,oh(c(C).class??""),"svelte-b78yyc")),k(X,F)});var S=f(y),E=h(S);{var K=X=>{var C=$h(),F=h(C),L=h(F);O(()=>{ns(F,"colspan",e.columns.length),M(L,s())}),k(X,C)},A=X=>{var C=bt(),F=Ce(C);pl(F,()=>e.children),k(X,C)};H(E,X=>{e.isEmpty?X(K):X(A,!1)})}var U=f(v,2);{var ee=X=>{var C=e0(),F=h(C),L=f(F,2),j=h(L),oe=f(L,2);O(()=>{F.disabled=e.page===1,M(j,`Page ${e.page??""} of ${e.totalPages??""}${e.totalItems!=null?` | ${e.totalItems} total`:""}`),oe.disabled=e.page===e.totalPages}),V("click",F,()=>e.onPageChange(e.page-1)),V("click",oe,()=>e.onPageChange(e.page+1)),k(X,C)};H(U,X=>{c(a)&&e.totalPages>1&&X(ee)})}O(()=>p=me(_,1,"table-card svelte-b78yyc",null,p,{"table-fetching":e.fetching})),k(t,d),nt()}ht(["input","click"]);var s0=T("<span> </span>");function mn(t,e){const s={pending:"badge-warning",running:"badge-accent",completed:"badge-success",failed:"badge-error",success:"badge-success",error:"badge-error",triggered:"badge-accent",debug:"badge-muted",info:"badge-accent",warn:"badge-warning"},n=Ae(()=>s[e.status]??"badge-muted");var a=s0(),i=h(a);O(()=>{me(a,1,`badge ${c(n)??""}`,"svelte-1fmrh5r"),M(i,e.status)}),k(t,a)}var n0=T('<div class="loading">Loading...</div>'),a0=T('<div><span></span> <span class="svc-label svelte-1076tzk">Browser</span> <span class="svc-detail mono svelte-1076tzk"> </span></div>'),i0=T('<tr><td class="mono"> </td><td><a class="bird-link svelte-1076tzk"> </a></td><td class="mono failure-count svelte-1076tzk"> </td><td><!></td><td> </td><td><button class="btn btn-outline btn-sm">Retry</button></td></tr>'),r0=T('<div class="section svelte-1076tzk"><div class="section-header svelte-1076tzk"><h2 class="section-title section-title-error svelte-1076tzk">Failing Birds</h2> <span class="last-updated svelte-1076tzk"> </span></div> <!></div>'),l0=T('<tr class="clickable-row svelte-1076tzk"><td class="mono"> </td><td> </td><td><!></td><td class="mono"> </td><td> </td></tr>'),o0=T('<div class="section svelte-1076tzk"><div class="section-header svelte-1076tzk"><h2 class="section-title section-title-active svelte-1076tzk">Active Flights</h2></div> <!></div>'),c0=T('<tr class="clickable-row svelte-1076tzk"><td class="mono"> </td><td> </td><td class="mono"> </td><td class="mono countdown svelte-1076tzk"> </td></tr>'),d0=T('<div class="section svelte-1076tzk"><div class="section-header svelte-1076tzk"><h2 class="section-title svelte-1076tzk">Next Up</h2></div> <!></div>'),u0=T('<tr class="clickable-row svelte-1076tzk"><td class="mono"> </td><td> </td><td><!></td><td class="mono"> </td><td> </td></tr>'),h0=T('<tr class="clickable-row svelte-1076tzk"><td class="mono"> </td><td class="mono"> </td><td> </td><td> </td><td> </td></tr>'),f0=T('<div class="svc-row svelte-1076tzk"><div><span></span> <span class="svc-label svelte-1076tzk">Agent CLI</span> <span class="svc-detail mono svelte-1076tzk"> </span></div> <div><span></span> <span class="svc-label svelte-1076tzk">Slack</span> <span class="svc-detail mono svelte-1076tzk"> </span></div> <!></div> <div class="num-grid svelte-1076tzk"><div class="num-card num-card-accent svelte-1076tzk"><div class="num-head svelte-1076tzk"><span class="num-label svelte-1076tzk">Flights</span> <span class="num-badge mono svelte-1076tzk"> </span></div> <div class="num-value svelte-1076tzk"> </div> <div class="num-sub svelte-1076tzk"><span> </span> <span class="num-sep svelte-1076tzk"></span> <span> </span></div></div> <div class="num-card num-card-neutral svelte-1076tzk"><div class="num-head svelte-1076tzk"><span class="num-label svelte-1076tzk">Messages</span></div> <div class="num-value svelte-1076tzk"> </div> <div class="num-sub svelte-1076tzk"><span> </span></div></div> <div class="num-card num-card-warm svelte-1076tzk"><div class="num-head svelte-1076tzk"><span class="num-label svelte-1076tzk">Tokens</span></div> <div class="num-value svelte-1076tzk"> </div> <div class="num-sub svelte-1076tzk"><span> </span> <span class="num-sep svelte-1076tzk"></span> <span> </span></div></div></div> <!> <!> <!> <div class="section svelte-1076tzk"><div class="section-header svelte-1076tzk"><h2 class="section-title svelte-1076tzk">Recent Flights</h2> <a href="#/birds" class="section-link svelte-1076tzk">View all</a></div> <!></div> <div class="section svelte-1076tzk"><div class="section-header svelte-1076tzk"><h2 class="section-title svelte-1076tzk">Recent Sessions</h2> <a href="#/sessions" class="section-link svelte-1076tzk">View all</a></div> <!></div>',1);function _0(t,e){st(e,!0);let s=q(He([])),n=q(He([])),a=q(He([])),i=q(He([])),r=q(He([])),l=q(He(kn())),d=q(!0);const o=[{key:"uid",label:"ID"},{key:"name",label:"Bird"},{key:"failure_count",label:"Failures"},{key:"last_status",label:"Status"},{key:"last_run",label:"Last Run"},{key:"actions",label:""}],u=[{key:"uid",label:"ID"},{key:"name",label:"Bird"},{key:"schedule",label:"Schedule"},{key:"next_run",label:"Next Run"}],_=[{key:"uid",label:"ID"},{key:"bird_name",label:"Bird"},{key:"status",label:"Status"},{key:"duration",label:"Duration"},{key:"started_at",label:"Started"}],p=[{key:"uid",label:"ID"},{key:"channel_id",label:"Channel"},{key:"agent_id",label:"Agent"},{key:"message_count",label:"Messages"},{key:"last_active",label:"Last Active"}];async function v(X){try{const[C,F,L,j,oe]=await Promise.all([Ee("/api/birds?perPage=100"),Ee("/api/birds/upcoming?limit=5"),Ee("/api/flights?status=running&perPage=5"),Ee("/api/flights?perPage=5"),Ee("/api/sessions?perPage=5")]);if(X.aborted)return;b(s,C.items.filter(de=>de.failure_count>0),!0),c(s).sort((de,J)=>J.failure_count-de.failure_count),b(n,F,!0),b(a,L.items,!0),b(i,j.items,!0),b(r,oe.items,!0),b(l,kn(),!0)}catch{}finally{X.aborted||b(d,!1)}}mt(()=>{const X=new AbortController;v(X.signal);const C=Pi(F=>{(F.resource==="sessions"||F.resource==="birds")&&v(X.signal)});return()=>{X.abort(),C()}});async function x(X){try{await Ee(`/api/birds/${X}/fly`,{method:"POST"}),Pe(`Bird ${Kt(X)} sent on a flight`,"success")}catch(C){Pe(`Failed: ${C.message}`,"error")}}const y=Ae(()=>e.status?.slack.connected??!1),w=Ae(()=>e.status?.agent.available??!1),S=Ae(()=>e.status?.browser.enabled??!1),E=Ae(()=>e.status?.browser.connected??!1);var K=bt(),A=Ce(K);{var U=X=>{var C=n0();k(X,C)},ee=X=>{var C=f0(),F=Ce(C),L=h(F);let j;var oe=h(L);let de;var J=f(oe,4),N=h(J),se=f(L,2);let ae;var ke=h(se);let we;var fe=f(ke,4),Z=h(fe),le=f(se,2);{var be=qe=>{var We=a0();let _t;var ct=h(We);let At;var dt=f(ct,4),je=h(dt);O(()=>{_t=me(We,1,"svc-card svelte-1076tzk",null,_t,{"svc-ok":c(E),"svc-err":!c(E)}),At=me(ct,1,"svc-dot svelte-1076tzk",null,At,{"dot-ok":c(E),"dot-err":!c(E)}),M(je,c(E)?"connected":"unreachable")}),k(qe,We)};H(le,qe=>{c(S)&&qe(be)})}var ue=f(F,2),ve=h(ue),_e=h(ve),ye=f(h(_e),2),ce=h(ye),pe=f(_e,2),$=h(pe),Se=f(pe,2),he=h(Se),Le=h(he),Te=f(he,4),Be=h(Te),ne=f(ve,2),te=f(h(ne),2),ge=h(te),tt=f(te,2),is=h(tt),Gt=h(is),Zt=f(ne,2),at=f(h(Zt),2),hs=h(at),Jt=f(at,2),fs=h(Jt),ft=h(fs),$t=f(fs,4),an=h($t),Ns=f(ue,2);{var En=qe=>{var We=r0(),_t=h(We),ct=f(h(_t),2),At=h(ct),dt=f(_t,2);hn(dt,{get columns(){return o},isEmpty:!1,children:(je,vt)=>{var Ze=bt(),W=Ce(Ze);Et(W,17,()=>c(s),ie=>ie.uid,(ie,xe)=>{var Me=i0(),Ue=h(Me),Ye=h(Ue),ut=f(Ue),pt=h(ut),Rt=h(pt),Mt=f(ut),It=h(Mt),Ls=f(Mt),Xe=h(Ls);{var Je=Ps=>{mn(Ps,{get status(){return c(xe).last_status}})},it=Ps=>{var da=Is("-");k(Ps,da)};H(Xe,Ps=>{c(xe).last_status?Ps(Je):Ps(it,!1)})}var Qt=f(Ls),qt=h(Qt),An=f(Qt),Os=h(An);O((Ps,da,Qi)=>{M(Ye,Ps),ns(pt,"href",`#/birds?search=${da??""}`),M(Rt,c(xe).name),M(It,c(xe).failure_count),M(qt,Qi)},[()=>Kt(c(xe).uid),()=>encodeURIComponent(Kt(c(xe).uid)),()=>c(xe).last_run?xs(c(xe).last_run):"-"]),V("click",Os,()=>x(c(xe).uid)),k(ie,Me)}),k(je,Ze)},$$slots:{default:!0}}),O(()=>M(At,`Updated ${c(l)??""}`)),k(qe,We)};H(Ns,qe=>{c(s).length>0&&qe(En)})}var Us=f(Ns,2);{var ys=qe=>{var We=o0(),_t=f(h(We),2);hn(_t,{get columns(){return _},isEmpty:!1,children:(ct,At)=>{var dt=bt(),je=Ce(dt);Et(je,17,()=>c(a),vt=>vt.uid,(vt,Ze)=>{var W=l0(),ie=h(W),xe=h(ie),Me=f(ie),Ue=h(Me),Ye=f(Me),ut=h(Ye);mn(ut,{get status(){return c(Ze).status}});var pt=f(Ye),Rt=h(pt),Mt=f(pt),It=h(Mt);O((Ls,Xe,Je)=>{M(xe,Ls),M(Ue,c(Ze).bird_name),M(Rt,Xe),M(It,Je)},[()=>Kt(c(Ze).uid),()=>bi(c(Ze).started_at,c(Ze).finished_at),()=>xs(c(Ze).started_at)]),V("click",W,()=>{window.location.hash=`#/birds?expand=${c(Ze).bird_uid}`}),k(vt,W)}),k(ct,dt)},$$slots:{default:!0}}),k(qe,We)};H(Us,qe=>{c(a).length>0&&qe(ys)})}var Hs=f(Us,2);{var Ms=qe=>{var We=d0(),_t=f(h(We),2);hn(_t,{get columns(){return u},isEmpty:!1,children:(ct,At)=>{var dt=bt(),je=Ce(dt);Et(je,17,()=>c(n),vt=>vt.uid,(vt,Ze)=>{var W=c0(),ie=h(W),xe=h(ie),Me=f(ie),Ue=h(Me),Ye=f(Me),ut=h(Ye),pt=f(Ye),Rt=h(pt);O((Mt,It)=>{M(xe,Mt),M(Ue,c(Ze).name),M(ut,c(Ze).schedule),M(Rt,It)},[()=>Kt(c(Ze).uid),()=>Gh(c(Ze).next_run)]),V("click",W,()=>{window.location.hash=`#/birds?search=${encodeURIComponent(Kt(c(Ze).uid))}`}),k(vt,W)}),k(ct,dt)},$$slots:{default:!0}}),k(qe,We)};H(Hs,qe=>{c(n).length>0&&qe(Ms)})}var ks=f(Hs,2),rn=f(h(ks),2);{let qe=Ae(()=>c(i).length===0);hn(rn,{get columns(){return _},get isEmpty(){return c(qe)},emptyMessage:"No flights recorded",children:(We,_t)=>{var ct=bt(),At=Ce(ct);Et(At,17,()=>c(i),dt=>dt.uid,(dt,je)=>{var vt=u0(),Ze=h(vt),W=h(Ze),ie=f(Ze),xe=h(ie),Me=f(ie),Ue=h(Me);mn(Ue,{get status(){return c(je).status}});var Ye=f(Me),ut=h(Ye),pt=f(Ye),Rt=h(pt);O((Mt,It,Ls)=>{M(W,Mt),M(xe,c(je).bird_name),M(ut,It),M(Rt,Ls)},[()=>Kt(c(je).uid),()=>bi(c(je).started_at,c(je).finished_at),()=>xs(c(je).started_at)]),V("click",vt,()=>{window.location.hash=`#/birds?expand=${c(je).bird_uid}`}),k(dt,vt)}),k(We,ct)},$$slots:{default:!0}})}var Xs=f(ks,2),ln=f(h(Xs),2);{let qe=Ae(()=>c(r).length===0);hn(ln,{get columns(){return p},get isEmpty(){return c(qe)},emptyMessage:"No active sessions",children:(We,_t)=>{var ct=bt(),At=Ce(ct);Et(At,17,()=>c(r),dt=>dt.uid,(dt,je)=>{var vt=h0(),Ze=h(vt),W=h(Ze),ie=f(Ze),xe=h(ie),Me=f(ie),Ue=h(Me),Ye=f(Me),ut=h(Ye),pt=f(Ye),Rt=h(pt);O((Mt,It)=>{M(W,Mt),M(xe,c(je).channel_id),M(Ue,c(je).agent_id),M(ut,c(je).message_count),M(Rt,It)},[()=>Kt(c(je).uid),()=>xs(c(je).last_active)]),V("click",vt,()=>{window.location.hash=`#/session-detail?id=${c(je).uid}`}),k(dt,vt)}),k(We,ct)},$$slots:{default:!0}})}O((qe,We,_t)=>{j=me(L,1,"svc-card svelte-1076tzk",null,j,{"svc-ok":c(w),"svc-err":!c(w)}),de=me(oe,1,"svc-dot svelte-1076tzk",null,de,{"dot-ok":c(w),"dot-err":!c(w)}),M(N,c(w)?"ready":"unavailable"),ae=me(se,1,"svc-card svelte-1076tzk",null,ae,{"svc-ok":c(y),"svc-err":!c(y)}),we=me(ke,1,"svc-dot svelte-1076tzk",null,we,{"dot-ok":c(y),"dot-err":!c(y)}),M(Z,c(y)?"connected":"disconnected"),M(ce,`${e.status.processes.active??""}/${e.status.processes.maxConcurrent??""} processes`),M($,e.status.flights.running),M(Le,`${e.status.flights.completed??""} done`),M(Be,`${e.status.flights.failed??""} failed`),M(ge,e.status.messages.totalMessages),M(Gt,`${e.status.sessions.total??""} ${e.status.sessions.total===1?"session":"sessions"}`),M(hs,qe),M(ft,`${We??""} in`),M(an,`${_t??""} out`)},[()=>(e.status.messages.totalTokensIn+e.status.messages.totalTokensOut).toLocaleString(),()=>e.status.messages.totalTokensIn.toLocaleString(),()=>e.status.messages.totalTokensOut.toLocaleString()]),k(X,C)};H(A,X=>{e.status?X(ee,!1):X(U)})}k(t,K),nt()}ht(["click"]);function v0(t){const e=Li();return{page:Math.max(Number(e.get("page"))||1,1),sort:e.get("sort")??t,search:e.get("search")??""}}function p0(t,e,s,n){const a=window.location.hash,i=a.indexOf("?"),r=i===-1?a:a.slice(0,i),l=new URLSearchParams(i===-1?"":a.slice(i+1));t>1?l.set("page",String(t)):l.delete("page"),e&&e!==n?l.set("sort",e):l.delete("sort"),s?l.set("search",s):l.delete("search");const d=l.toString(),o=d?`${r}?${d}`:r;o!==a&&history.replaceState(null,"",o)}function Yr(t){const e=t.defaultSort??"",s=v0(e);let n=q(He([])),a=q(He(s.page)),i=q(1),r=q(0),l=q(He(t.defaultPerPage??15)),d=q(!0),o=q(!1),u=!1,_=q(He(s.sort)),p=q(He(s.search));mt(()=>{p0(c(a),c(_),c(p),e)}),mt(()=>{const w=c(a),S=c(_),E=c(p),K=c(l);t.watchExtras?.();const A=new AbortController,U=async()=>{const X=new URLSearchParams;X.set("page",String(w)),X.set("perPage",String(K)),S&&S!==e&&X.set("sort",S),E&&X.set("search",E);const C=t.buildParams?.();if(C)for(const[L,j]of Object.entries(C))j&&X.set(L,j);const F=t.endpoint.includes("?")?"&":"?";try{const L=await Ee(`${t.endpoint}${F}${X.toString()}`);if(A.signal.aborted)return;t.onResponse?.(L);const j=t.transformResponse?t.transformResponse(L):L;b(n,j.items,!0),b(i,j.totalPages,!0),b(r,j.totalItems,!0),b(l,j.perPage,!0)}catch{}finally{A.signal.aborted||(b(d,!1),b(o,!1),u=!0)}};u||b(d,!0),b(o,!0),U();const ee=t.invalidateOn?Pi(X=>{X.resource===t.invalidateOn&&U()}):()=>{};return()=>{A.abort(),ee()}});function v(w){b(a,w,!0)}function x(w){c(_)===w?b(_,`-${w}`):c(_)===`-${w}`?b(_,w,!0):b(_,`-${w}`),b(a,1)}function y(w){b(p,w,!0),b(a,1)}return{get items(){return c(n)},get page(){return c(a)},get totalPages(){return c(i)},get totalItems(){return c(r)},get perPage(){return c(l)},get loading(){return c(d)},get fetching(){return c(o)},get sort(){return c(_)},get search(){return c(p)},setPage:v,setSort:x,setSearch:y}}var g0=T('<div class="loading">Loading...</div>'),x0=T('<div class="filter-spacer svelte-15gdqrj"></div> <span class="last-updated svelte-15gdqrj"> </span>',1),b0=T('<tr class="clickable-row svelte-15gdqrj"><td class="mono"> </td><td class="mono"> </td><td class="mono"> </td><td> </td><td> </td><td> </td></tr>');function m0(t,e){st(e,!0);const s=[{key:"uid",label:"ID",sortable:!0},{key:"channel_id",label:"Channel",sortable:!0},{key:"thread_id",label:"Thread"},{key:"agent_id",label:"Agent",sortable:!0},{key:"message_count",label:"Messages",sortable:!0},{key:"last_active",label:"Last Active",sortable:!0}];let n=q(He(kn()));const a=Yr({endpoint:"/api/sessions",columns:s,defaultSort:"-last_active",invalidateOn:"sessions",onResponse:()=>{b(n,kn(),!0)}});var i=bt(),r=Ce(i);{var l=o=>{var u=g0();k(o,u)},d=o=>{{const u=p=>{var v=x0(),x=f(Ce(v),2),y=h(x);O(()=>M(y,`Updated ${c(n)??""}`)),k(p,v)};let _=Ae(()=>a.items.length===0);hn(o,{get columns(){return s},get isEmpty(){return c(_)},emptyMessage:"No active sessions",get fetching(){return a.fetching},get page(){return a.page},get totalPages(){return a.totalPages},get totalItems(){return a.totalItems},get sort(){return a.sort},get search(){return a.search},searchPlaceholder:"Search sessions...",get onPageChange(){return a.setPage},get onSortChange(){return a.setSort},get onSearchChange(){return a.setSearch},toolbar:u,children:(p,v)=>{var x=bt(),y=Ce(x);Et(y,17,()=>a.items,w=>w.uid,(w,S)=>{var E=b0(),K=h(E),A=h(K),U=f(K),ee=h(U),X=f(U),C=h(X),F=f(X),L=h(F),j=f(F),oe=h(j),de=f(j),J=h(de);O((N,se)=>{M(A,N),M(ee,c(S).channel_id),M(C,c(S).thread_id??"-"),M(L,c(S).agent_id),M(oe,c(S).message_count),M(J,se)},[()=>Kt(c(S).uid),()=>xs(c(S).last_active)]),V("click",E,()=>{window.location.hash=`#/session-detail?id=${c(S).uid}`}),k(w,E)}),k(p,x)},$$slots:{toolbar:!0,default:!0}})}};H(r,o=>{a.loading?o(l):o(d,!1)})}k(t,i),nt()}ht(["click"]);var w0=T('<div role="switch" tabindex="0"></div>');function Pn(t,e){st(e,!0);var s=w0();let n;O(()=>{n=me(s,1,"toggle svelte-aw96os",null,n,{active:e.active}),ns(s,"aria-checked",e.active)}),V("click",s,function(...a){e.onToggle?.apply(this,a)}),V("keydown",s,a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),e.onToggle())}),k(t,s),nt()}ht(["click","keydown"]);var y0=T("<textarea></textarea>"),k0=T('<input type="text"/>'),S0=Cn('<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-1npf1z3"><path d="M3 8.5l3.5 3.5L13 4.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'),C0=T('<div><!> <div class="inline-actions svelte-1npf1z3"><button class="inline-btn inline-btn-save svelte-1npf1z3" title="Save"><!></button> <button class="inline-btn inline-btn-cancel svelte-1npf1z3" title="Cancel"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-1npf1z3"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"></path></svg></button></div></div>');function xt(t,e){st(e,!0);let s=jn(e,"value",15,""),n=jn(e,"mono",3,!1),a=jn(e,"multiline",3,!1),i=jn(e,"saving",3,!1);function r(E){E.key==="Escape"?e.oncancel():E.key==="Enter"&&(a()?E.metaKey:!E.shiftKey)&&(E.preventDefault(),e.onsave(s()))}var l=C0();let d;var o=h(l);{var u=E=>{var K=y0();let A;O(()=>{A=me(K,1,"inline-input inline-textarea svelte-1npf1z3",null,A,{mono:n()}),ns(K,"placeholder",e.placeholder)}),V("keydown",K,r),Ve(K,s),k(E,K)},_=E=>{var K=k0();let A;O(()=>{A=me(K,1,"inline-input svelte-1npf1z3",null,A,{mono:n()}),ns(K,"placeholder",e.placeholder)}),V("keydown",K,r),Ve(K,s),k(E,K)};H(o,E=>{a()?E(u):E(_,!1)})}var p=f(o,2),v=h(p),x=h(v);{var y=E=>{var K=Is("...");k(E,K)},w=E=>{var K=S0();k(E,K)};H(x,E=>{i()?E(y):E(w,!1)})}var S=f(v,2);O(()=>{d=me(l,1,"inline-edit svelte-1npf1z3",null,d,{"inline-edit-multiline":a()}),v.disabled=i()}),V("click",v,()=>e.onsave(s())),V("click",S,function(...E){e.oncancel?.apply(this,E)}),k(t,l),nt()}ht(["keydown","click"]);var E0=T('<div class="flight-summary svelte-1jo1oiw"> </div>'),A0=T('<p class="detail-label error-label svelte-1jo1oiw">Error</p> <pre class="detail-pre error-pre svelte-1jo1oiw"> </pre>',1),K0=T('<p class="detail-label svelte-1jo1oiw">Result</p> <pre class="detail-pre svelte-1jo1oiw"> </pre>',1),F0=T('<button class="btn btn-outline btn-sm retry-btn svelte-1jo1oiw">Retry</button>'),T0=T('<div class="flight-detail svelte-1jo1oiw"><!> <!> <!></div>'),M0=T('<div role="button" tabindex="0"><div class="flight-top svelte-1jo1oiw"><span></span> <span class="flight-duration mono svelte-1jo1oiw"> </span> <span class="flight-age svelte-1jo1oiw"> </span></div> <!> <!></div>');function X0(t,e){st(e,!0);function s(w){return w==="success"?"dot-ok":w==="error"?"dot-err":"dot-running"}function n(w){(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),e.ontoggle())}var a=M0();let i;var r=h(a),l=h(r),d=f(l,2),o=h(d),u=f(d,2),_=h(u),p=f(r,2);{var v=w=>{var S=E0(),E=h(S);O(()=>M(E,e.flight.error??e.flight.result??"")),k(w,S)};H(p,w=>{(e.flight.error||e.flight.result)&&w(v)})}var x=f(p,2);{var y=w=>{var S=T0(),E=h(S);{var K=C=>{var F=A0(),L=f(Ce(F),2),j=h(L);O(()=>M(j,e.flight.error)),k(C,F)};H(E,C=>{e.flight.error&&C(K)})}var A=f(E,2);{var U=C=>{var F=K0(),L=f(Ce(F),2),j=h(L);O(()=>M(j,e.flight.result)),k(C,F)};H(A,C=>{e.flight.result&&C(U)})}var ee=f(A,2);{var X=C=>{var F=F0();V("click",F,L=>{L.stopPropagation(),e.onretry()}),k(C,F)};H(ee,C=>{e.flight.status==="error"&&C(X)})}k(w,S)};H(x,w=>{e.expanded&&w(y)})}O((w,S,E)=>{i=me(a,1,"flight-card svelte-1jo1oiw",null,i,{"flight-expanded":e.expanded}),me(l,1,`svc-dot ${w??""}`,"svelte-1jo1oiw"),M(o,S),M(_,E)},[()=>s(e.flight.status),()=>bi(e.flight.started_at,e.flight.finished_at),()=>xs(e.flight.started_at)]),V("click",a,function(...w){e.ontoggle?.apply(this,w)}),V("keydown",a,n),k(t,a),nt()}ht(["click","keydown"]);var L0=T("<button> </button>"),P0=T("<button> </button>"),B0=T("<button> </button>"),D0=T("<button> </button>"),R0=T('<button class="btn btn-danger btn-sm">Delete</button>'),I0=T('<span class="flights-count mono svelte-1o8kr72"> </span>'),Q0=T('<div class="flights-empty svelte-1o8kr72">Loading flights...</div>'),z0=T('<div class="flights-empty svelte-1o8kr72"> </div>'),N0=T('<div class="pagination svelte-1o8kr72"><button class="pg-btn svelte-1o8kr72"><svg class="pg-icon svelte-1o8kr72" viewBox="0 0 6 10" fill="none" aria-hidden="true"><path d="M5 1L1 5L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg> Prev</button> <span class="pg-info svelte-1o8kr72"> </span> <button class="pg-btn svelte-1o8kr72">Next <svg class="pg-icon svelte-1o8kr72" viewBox="0 0 6 10" fill="none" aria-hidden="true"><path d="M1 1L5 5L1 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></button></div>'),U0=T('<div class="flight-list svelte-1o8kr72"></div> <!>',1),H0=T('<div><button class="backdrop svelte-1o8kr72" aria-label="Close drawer"></button> <div class="drawer-panel svelte-1o8kr72"><div class="drawer-header svelte-1o8kr72"><div class="header-top svelte-1o8kr72"><h2 class="bird-name svelte-1o8kr72"> </h2> <button class="close-btn svelte-1o8kr72" aria-label="Close"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-1o8kr72"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"></path></svg></button></div> <div class="meta-row svelte-1o8kr72"><!> <div class="toggle-wrapper svelte-1o8kr72"><!></div> <!></div></div> <div class="drawer-body svelte-1o8kr72"><div class="config-section svelte-1o8kr72"><div class="config-grid svelte-1o8kr72"><div class="config-item svelte-1o8kr72"><span class="config-label svelte-1o8kr72">Agent</span> <!></div> <div class="config-item svelte-1o8kr72"><span class="config-label svelte-1o8kr72">Channel</span> <!></div></div> <div class="prompt-block svelte-1o8kr72"><span class="config-label svelte-1o8kr72">Prompt</span> <!></div></div> <div class="actions-row svelte-1o8kr72"><button class="btn btn-outline btn-sm">Fly</button> <!></div> <div class="divider svelte-1o8kr72"></div> <div class="flights-section svelte-1o8kr72"><div class="flights-header svelte-1o8kr72"><span class="flights-title svelte-1o8kr72">Flight Log</span> <!></div> <div class="filter-row svelte-1o8kr72"><button>All</button> <button>Success</button> <button>Error</button> <button>Running</button> <input type="search" class="flight-search svelte-1o8kr72" placeholder="Search flights..."/></div> <!></div></div></div></div>');function O0(t,e){st(e,!0);let s=q(He([])),n=q(!0),a=q(1),i=q(1),r=q(0),l=q(""),d=q(""),o=q(null),u=q(!1),_=q(null);const p=Ae(()=>c(_)??!!e.bird.enabled);mt(()=>{e.bird.enabled,b(_,null)});let v=q(null),x=q(""),y=q(!1),w,S=q("");const E=Ae(()=>e.bird.name.startsWith("__bb_"));Pc().then(()=>{b(u,!0)});function K(){b(u,!1),setTimeout(e.onclose,200)}function A(W){if(W.key==="Escape"){if(bn.pending)return;c(v)?L():K()}}function U(W,ie,xe,Me){let Ue=`/api/flights?birdUid=${W}&perPage=10&sort=-started_at&page=${ie}`;return xe&&(Ue+=`&status=${xe}`),Me&&(Ue+=`&search=${encodeURIComponent(Me)}`),Ue}mt(()=>{const W=e.bird.uid,ie=c(a),xe=c(l),Me=c(S),Ue=new AbortController;return b(n,!0),Ee(U(W,ie,xe,Me)).then(Ye=>{Ue.signal.aborted||(b(s,Ye.items,!0),b(i,Ye.totalPages,!0),b(r,Ye.totalItems,!0))}).catch(()=>{Ue.signal.aborted||(b(s,[],!0),b(i,1),b(r,0))}).finally(()=>{Ue.signal.aborted||b(n,!1)}),()=>Ue.abort()}),mt(()=>{const W=e.bird.uid;return Pi(xe=>{if(xe.resource==="birds"){const Me=U(W,c(a),c(l),c(S));Ee(Me).then(Ue=>{b(s,Ue.items,!0),b(i,Ue.totalPages,!0),b(r,Ue.totalItems,!0)}).catch(()=>{})}})});function ee(W){b(l,W,!0),b(a,1),b(o,null)}function X(W){const ie=W.target.value;b(d,ie,!0),clearTimeout(w),w=setTimeout(()=>{b(S,ie,!0),b(a,1),b(o,null)},300)}async function C(){const W=!c(p);b(_,W);const ie=W?"enable":"disable";try{await Ee(`/api/birds/${e.bird.uid}/${ie}`,{method:"PATCH"}),Pe(`Bird ${Kt(e.bird.uid)} ${ie}d`,"success")}catch(xe){b(_,null),Pe(`Failed: ${xe.message}`,"error")}}function F(W){c(E)||(b(v,W,!0),b(x,e.bird[W]??"",!0))}function L(){b(v,null),b(x,"")}async function j(){if(!c(v))return;const W=c(x).trim(),ie=(e.bird[c(v)]??"").trim();if(W===ie){L();return}const xe=c(v)==="target_channel_id";if(!W&&!xe){Pe("Value cannot be empty","error");return}b(y,!0);const Me={schedule:"schedule",prompt:"prompt",agent_id:"agent",target_channel_id:"channel"};try{await Ee(`/api/birds/${e.bird.uid}`,{method:"PATCH",body:{[Me[c(v)]]:W||null}}),Pe(`Updated ${c(v).replace("_"," ")}`,"success"),L()}catch(Ue){Pe(`Failed: ${Ue.message}`,"error")}finally{b(y,!1)}}async function oe(){try{const W=await Ee(`/api/birds/${e.bird.uid}/fly`,{method:"POST"});Pe(`Bird ${Kt(e.bird.uid)} sent on a flight (job #${W.jobId})`,"success")}catch(W){Pe(`Failed: ${W.message}`,"error")}}async function de(){if(await jr(`Delete bird "${e.bird.name}"? This will also remove all flight history.`))try{await Ee(`/api/birds/${e.bird.uid}`,{method:"DELETE"}),Pe(`Bird ${Kt(e.bird.uid)} deleted`,"success"),K()}catch(W){Pe(`Failed: ${W.message}`,"error")}}async function J(W){try{await Ee(`/api/birds/${W.bird_uid}/fly`,{method:"POST"}),Pe(`Retrying ${W.bird_name}`,"success")}catch(ie){Pe(`Failed: ${ie.message}`,"error")}}var N=H0();In("keydown",gi,A);let se;var ae=h(N),ke=f(ae,2),we=h(ke),fe=h(we),Z=h(fe),le=h(Z),be=f(Z,2),ue=f(fe,2),ve=h(ue);{var _e=W=>{xt(W,{mono:!0,get saving(){return c(y)},onsave:j,oncancel:L,get value(){return c(x)},set value(ie){b(x,ie,!0)}})},ye=W=>{var ie=L0();let xe;var Me=h(ie);O(()=>{xe=me(ie,1,"schedule-pill mono svelte-1o8kr72",null,xe,{editable:!c(E)}),M(Me,e.bird.schedule)}),V("click",ie,()=>F("schedule")),k(W,ie)};H(ve,W=>{c(v)==="schedule"?W(_e):W(ye,!1)})}var ce=f(ve,2),pe=h(ce);Pn(pe,{get active(){return c(p)},onToggle:C});var $=f(ce,2);{var Se=W=>{mn(W,{get status(){return e.bird.last_status}})};H($,W=>{e.bird.last_status&&W(Se)})}var he=f(we,2),Le=h(he),Te=h(Le),Be=h(Te),ne=f(h(Be),2);{var te=W=>{xt(W,{get saving(){return c(y)},onsave:j,oncancel:L,get value(){return c(x)},set value(ie){b(x,ie,!0)}})},ge=W=>{var ie=P0();let xe;var Me=h(ie);O(()=>{xe=me(ie,1,"config-value svelte-1o8kr72",null,xe,{editable:!c(E)}),M(Me,e.bird.agent_id)}),V("click",ie,()=>F("agent_id")),k(W,ie)};H(ne,W=>{c(v)==="agent_id"?W(te):W(ge,!1)})}var tt=f(Be,2),is=f(h(tt),2);{var Gt=W=>{xt(W,{mono:!0,placeholder:"Channel ID",get saving(){return c(y)},onsave:j,oncancel:L,get value(){return c(x)},set value(ie){b(x,ie,!0)}})},Zt=W=>{var ie=B0();let xe;var Me=h(ie);O(()=>{xe=me(ie,1,"config-value mono svelte-1o8kr72",null,xe,{editable:!c(E)}),M(Me,e.bird.target_channel_id??"default")}),V("click",ie,()=>F("target_channel_id")),k(W,ie)};H(is,W=>{c(v)==="target_channel_id"?W(Gt):W(Zt,!1)})}var at=f(Te,2),hs=f(h(at),2);{var Jt=W=>{xt(W,{mono:!0,multiline:!0,get saving(){return c(y)},onsave:j,oncancel:L,get value(){return c(x)},set value(ie){b(x,ie,!0)}})},fs=W=>{var ie=D0();let xe;var Me=h(ie);O(()=>{xe=me(ie,1,"prompt-pre svelte-1o8kr72",null,xe,{editable:!c(E)}),M(Me,e.bird.prompt)}),V("click",ie,()=>F("prompt")),k(W,ie)};H(hs,W=>{c(v)==="prompt"?W(Jt):W(fs,!1)})}var ft=f(Le,2),$t=h(ft),an=f($t,2);{var Ns=W=>{var ie=R0();V("click",ie,de),k(W,ie)};H(an,W=>{c(E)||W(Ns)})}var En=f(ft,4),Us=h(En),ys=f(h(Us),2);{var Hs=W=>{var ie=I0(),xe=h(ie);O(()=>M(xe,c(r))),k(W,ie)};H(ys,W=>{c(r)>0&&W(Hs)})}var Ms=f(Us,2),ks=h(Ms);let rn;var Xs=f(ks,2);let ln;var qe=f(Xs,2);let We;var _t=f(qe,2);let ct;var At=f(_t,2),dt=f(Ms,2);{var je=W=>{var ie=Q0();k(W,ie)},vt=W=>{var ie=z0(),xe=h(ie);O(()=>M(xe,c(d)||c(l)?"No matching flights":"No flights yet")),k(W,ie)},Ze=W=>{var ie=U0(),xe=Ce(ie);Et(xe,21,()=>c(s),Ye=>Ye.uid,(Ye,ut)=>{{let pt=Ae(()=>c(o)===c(ut).uid);X0(Ye,{get flight(){return c(ut)},get expanded(){return c(pt)},ontoggle:()=>{b(o,c(o)===c(ut).uid?null:c(ut).uid,!0)},onretry:()=>J(c(ut))})}});var Me=f(xe,2);{var Ue=Ye=>{var ut=N0(),pt=h(ut),Rt=f(pt,2),Mt=h(Rt),It=f(Rt,2);O(()=>{pt.disabled=c(a)===1,M(Mt,`${c(a)??""} / ${c(i)??""}`),It.disabled=c(a)===c(i)}),V("click",pt,()=>{mr(a,-1)}),V("click",It,()=>{mr(a)}),k(Ye,ut)};H(Me,Ye=>{c(i)>1&&Ye(Ue)})}k(W,ie)};H(dt,W=>{c(n)?W(je):c(s).length===0?W(vt,1):W(Ze,!1)})}O(()=>{se=me(N,1,"overlay svelte-1o8kr72",null,se,{visible:c(u)}),M(le,e.bird.name),rn=me(ks,1,"filter-chip svelte-1o8kr72",null,rn,{"filter-all-active":c(l)===""}),ln=me(Xs,1,"filter-chip svelte-1o8kr72",null,ln,{"filter-success-active":c(l)==="success"}),We=me(qe,1,"filter-chip svelte-1o8kr72",null,We,{"filter-error-active":c(l)==="error"}),ct=me(_t,1,"filter-chip svelte-1o8kr72",null,ct,{"filter-running-active":c(l)==="running"}),Hc(At,c(d))}),V("click",ae,K),V("click",be,K),V("click",$t,oe),V("click",ks,()=>ee("")),V("click",Xs,()=>ee("success")),V("click",qe,()=>ee("error")),V("click",_t,()=>ee("running")),V("input",At,X),k(t,N),nt()}ht(["click","input"]);var V0=T('<div class="loading">Loading...</div>'),G0=T('<span class="cell-btn-label svelte-3q62eu">...</span>'),q0=Cn('<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-3q62eu"><path d="M3 8.5l3.5 3.5L13 4.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'),W0=T('<div class="cell-edit-actions svelte-3q62eu"><button class="cell-btn cell-btn-save svelte-3q62eu" title="Save"><!></button> <button class="cell-btn cell-btn-cancel svelte-3q62eu" title="Cancel"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-3q62eu"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"></path></svg></button></div>'),j0=T('<div class="create-form svelte-3q62eu"><div class="form-title svelte-3q62eu">New Bird</div> <div class="form-row svelte-3q62eu"><label class="form-label">Schedule <input class="form-input" type="text" placeholder="*/30 * * * *"/></label> <label class="form-label">Channel ID <input class="form-input" type="text" placeholder="Optional"/></label> <label class="form-label">Agent ID <input class="form-input" type="text" placeholder="default"/></label></div> <label class="form-label">Prompt <textarea class="form-textarea" placeholder="What should the agent do?"></textarea></label> <div class="form-actions svelte-3q62eu"><button class="btn btn-primary btn-sm"> </button> <button class="btn btn-outline btn-sm">Cancel</button></div></div>'),Y0=T('<button class="btn btn-primary btn-sm"> </button> <div class="filter-spacer svelte-3q62eu"></div> <span class="last-updated svelte-3q62eu"> </span>',1),Z0=T('<div class="cell-edit-overlay svelte-3q62eu"><input class="cell-input mono svelte-3q62eu" type="text"/> <!></div>'),J0=T('<div class="cell-edit-overlay svelte-3q62eu"><textarea class="cell-input cell-textarea svelte-3q62eu"></textarea> <!></div>'),$0=T('<div class="cell-edit-overlay svelte-3q62eu"><input class="cell-input svelte-3q62eu" type="text"/> <!></div>'),ef=T('<div class="cell-edit-overlay svelte-3q62eu"><input class="cell-input mono svelte-3q62eu" type="text" placeholder="Channel ID"/> <!></div>'),tf=T('<span class="last-run-age svelte-3q62eu"> </span> <!>',1),sf=T('<button class="btn btn-danger btn-sm">Delete</button>'),nf=T('<tr class="bird-row svelte-3q62eu"><td class="mono"> </td><td> </td><td><span> </span> <!></td><td><span> </span> <!></td><td><span> </span> <!></td><td><span> </span> <!></td><td><div class="toggle-wrapper svelte-3q62eu"><!></div></td><td class="last-run-cell svelte-3q62eu"><!></td><td><div class="actions-cell svelte-3q62eu"><button class="btn btn-outline btn-sm">Fly</button> <!></div></td></tr>'),af=T("<!> <!> <!>",1);function rf(t,e){st(e,!0);const s=[{key:"uid",label:"ID",sortable:!0},{key:"name",label:"Name",sortable:!0},{key:"schedule",label:"Schedule",sortable:!0},{key:"prompt",label:"Prompt"},{key:"agent_id",label:"Agent",sortable:!0},{key:"target_channel_id",label:"Channel"},{key:"enabled",label:"Enabled",sortable:!0},{key:"last_run",label:"Last Run",sortable:!0},{key:"actions",label:"Actions"}];let n=q(He(kn()));const a=Yr({endpoint:"/api/birds",columns:s,defaultSort:"created_at",invalidateOn:"birds",onResponse:()=>{b(n,kn(),!0)}});let i=q(!1),r=q(""),l=q(""),d=q(""),o=q(""),u=q(!1),_=q(null),p=q(!1),v=q(null);const x=Ae(()=>c(v)?a.items.find(N=>N.uid===c(v))??null:null);mt(()=>{if(a.loading)return;const N=Li().get("expand");if(!N)return;const se=a.items.find(ae=>ae.uid===N);if(se){b(v,se.uid,!0);const ae=window.location.hash,ke=ae.indexOf("?"),we=ke===-1?ae:ae.slice(0,ke),fe=new URLSearchParams(ke===-1?"":ae.slice(ke+1));fe.delete("expand");const Z=fe.toString();history.replaceState(null,"",Z?`${we}?${Z}`:we)}});function y(N,se){N.target.closest(".cell-editable, .actions-cell, .toggle-wrapper")||b(v,se.uid,!0)}async function w(N,se){const ae=se?"disable":"enable";try{await Ee(`/api/birds/${N}/${ae}`,{method:"PATCH"}),Pe(`Bird ${Kt(N)} ${ae}d`,"success")}catch(ke){Pe(`Failed: ${ke.message}`,"error")}}function S(){b(r,""),b(l,""),b(d,""),b(o,""),b(i,!0)}function E(){b(i,!1)}async function K(){if(!c(r).trim()||!c(l).trim()){Pe("Schedule and prompt are required","error");return}b(u,!0);try{const N={schedule:c(r).trim(),prompt:c(l).trim()};c(d).trim()&&(N.channel=c(d).trim()),c(o).trim()&&(N.agent=c(o).trim()),await Ee("/api/birds",{method:"POST",body:N}),Pe("Bird created","success"),E()}catch(N){Pe(`Failed: ${N.message}`,"error")}finally{b(u,!1)}}function A(N,se){if(N.name.startsWith("__bb_"))return;const ae=N[se]??"";b(_,{uid:N.uid,field:se,value:ae,original:ae},!0)}function U(){b(_,null)}async function ee(){if(c(_)==null)return;const N=c(_).value.trim();if(N===c(_).original.trim()){b(_,null);return}const se=c(_).field==="target_channel_id";if(!N&&!se){Pe("Value cannot be empty","error");return}b(p,!0);const ae={schedule:"schedule",prompt:"prompt",agent_id:"agent",target_channel_id:"channel"};try{await Ee(`/api/birds/${c(_).uid}`,{method:"PATCH",body:{[ae[c(_).field]]:N||null}}),Pe(`Updated ${c(_).field.replace("_"," ")}`,"success"),b(_,null)}catch(ke){Pe(`Failed: ${ke.message}`,"error")}finally{b(p,!1)}}function X(N){N.key==="Escape"?U():N.key==="Enter"&&(c(_)?.field==="prompt"?N.metaKey:!N.shiftKey)&&(N.preventDefault(),ee())}function C(N,se){return c(_)!=null&&c(_).uid===N&&c(_).field===se}async function F(N){try{const se=await Ee(`/api/birds/${N}/fly`,{method:"POST"});Pe(`Bird ${Kt(N)} sent on a flight (job #${se.jobId})`,"success")}catch(se){Pe(`Failed: ${se.message}`,"error")}}async function L(N,se){if(await jr(`Delete bird "${se}"? This will also remove all flight history.`))try{await Ee(`/api/birds/${N}`,{method:"DELETE"}),Pe(`Bird ${Kt(N)} deleted`,"success")}catch(ae){Pe(`Failed: ${ae.message}`,"error")}}var j=bt(),oe=Ce(j);{var de=N=>{var se=V0();k(N,se)},J=N=>{const se=be=>{var ue=W0(),ve=h(ue),_e=h(ve);{var ye=$=>{var Se=G0();k($,Se)},ce=$=>{var Se=q0();k($,Se)};H(_e,$=>{c(p)?$(ye):$(ce,!1)})}var pe=f(ve,2);O(()=>ve.disabled=c(p)),V("click",ve,$=>{$.stopPropagation(),ee()}),V("click",pe,$=>{$.stopPropagation(),U()}),k(be,ue)};var ae=af(),ke=Ce(ae);{var we=be=>{var ue=j0(),ve=f(h(ue),2),_e=h(ve),ye=f(h(_e)),ce=f(_e,2),pe=f(h(ce)),$=f(ce,2),Se=f(h($)),he=f(ve,2),Le=f(h(he)),Te=f(he,2),Be=h(Te),ne=h(Be),te=f(Be,2);O(()=>{Be.disabled=c(u),M(ne,c(u)?"Saving...":"Create")}),Ve(ye,()=>c(r),ge=>b(r,ge)),Ve(pe,()=>c(d),ge=>b(d,ge)),Ve(Se,()=>c(o),ge=>b(o,ge)),Ve(Le,()=>c(l),ge=>b(l,ge)),V("click",Be,K),V("click",te,E),k(be,ue)};H(ke,be=>{c(i)&&be(we)})}var fe=f(ke,2);{const be=ve=>{var _e=Y0(),ye=Ce(_e),ce=h(ye),pe=f(ye,4),$=h(pe);O(()=>{M(ce,c(i)?"Cancel":"Add Bird"),M($,`Updated ${c(n)??""}`)}),V("click",ye,()=>{c(i)?E():S()}),k(ve,_e)};let ue=Ae(()=>a.items.length===0);hn(fe,{get columns(){return s},get isEmpty(){return c(ue)},emptyMessage:"No birds configured",get fetching(){return a.fetching},get page(){return a.page},get totalPages(){return a.totalPages},get totalItems(){return a.totalItems},get sort(){return a.sort},get search(){return a.search},searchPlaceholder:"Search birds...",get onPageChange(){return a.setPage},get onSortChange(){return a.setSort},get onSearchChange(){return a.setSearch},toolbar:be,children:(ve,_e)=>{var ye=bt(),ce=Ce(ye);Et(ce,17,()=>a.items,pe=>pe.uid,(pe,$)=>{const Se=Ae(()=>c($).name.startsWith("__bb_"));var he=nf(),Le=h(he),Te=h(Le),Be=f(Le),ne=h(Be),te=f(Be);let ge;var tt=h(te);let is;var Gt=h(tt),Zt=f(tt,2);{var at=Xe=>{var Je=Z0(),it=h(Je),Qt=f(it,2);se(Qt),V("keydown",it,X),Ve(it,()=>c(_).value,qt=>c(_).value=qt),k(Xe,Je)},hs=Ae(()=>C(c($).uid,"schedule"));H(Zt,Xe=>{c(hs)&&Xe(at)})}var Jt=f(te);let fs;var ft=h(Jt);let $t;var an=h(ft),Ns=f(ft,2);{var En=Xe=>{var Je=J0(),it=h(Je),Qt=f(it,2);se(Qt),V("keydown",it,X),Ve(it,()=>c(_).value,qt=>c(_).value=qt),k(Xe,Je)},Us=Ae(()=>C(c($).uid,"prompt"));H(Ns,Xe=>{c(Us)&&Xe(En)})}var ys=f(Jt);let Hs;var Ms=h(ys);let ks;var rn=h(Ms),Xs=f(Ms,2);{var ln=Xe=>{var Je=$0(),it=h(Je),Qt=f(it,2);se(Qt),V("keydown",it,X),Ve(it,()=>c(_).value,qt=>c(_).value=qt),k(Xe,Je)},qe=Ae(()=>C(c($).uid,"agent_id"));H(Xs,Xe=>{c(qe)&&Xe(ln)})}var We=f(ys);let _t;var ct=h(We);let At;var dt=h(ct),je=f(ct,2);{var vt=Xe=>{var Je=ef(),it=h(Je),Qt=f(it,2);se(Qt),V("keydown",it,X),Ve(it,()=>c(_).value,qt=>c(_).value=qt),k(Xe,Je)},Ze=Ae(()=>C(c($).uid,"target_channel_id"));H(je,Xe=>{c(Ze)&&Xe(vt)})}var W=f(We),ie=h(W),xe=h(ie);{let Xe=Ae(()=>!!c($).enabled);Pn(xe,{get active(){return c(Xe)},onToggle:()=>w(c($).uid,!!c($).enabled)})}var Me=f(W),Ue=h(Me);{var Ye=Xe=>{var Je=tf(),it=Ce(Je),Qt=h(it),qt=f(it,2);{var An=Os=>{mn(Os,{get status(){return c($).last_status}})};H(qt,Os=>{c($).last_status&&Os(An)})}O(Os=>M(Qt,Os),[()=>xs(c($).last_run)]),k(Xe,Je)},ut=Xe=>{var Je=Is("-");k(Xe,Je)};H(Ue,Xe=>{c($).last_run?Xe(Ye):Xe(ut,!1)})}var pt=f(Me),Rt=h(pt),Mt=h(Rt),It=f(Mt,2);{var Ls=Xe=>{var Je=sf();V("click",Je,()=>L(c($).uid,c($).name)),k(Xe,Je)};H(It,Xe=>{c(Se)||Xe(Ls)})}O((Xe,Je,it,Qt,qt,An)=>{M(Te,Xe),M(ne,c($).name),ge=me(te,1,"svelte-3q62eu",null,ge,{"cell-editable":!c(Se)}),is=me(tt,1,"mono cell-text svelte-3q62eu",null,is,Je),M(Gt,c($).schedule),fs=me(Jt,1,"svelte-3q62eu",null,fs,{"cell-editable":!c(Se)}),$t=me(ft,1,"cell-text prompt-text svelte-3q62eu",null,$t,it),ns(ft,"title",c($).prompt),M(an,`${Qt??""}${c($).prompt.length>60?"...":""}`),Hs=me(ys,1,"svelte-3q62eu",null,Hs,{"cell-editable":!c(Se)}),ks=me(Ms,1,"cell-text svelte-3q62eu",null,ks,qt),M(rn,c($).agent_id),_t=me(We,1,"svelte-3q62eu",null,_t,{"cell-editable":!c(Se)}),At=me(ct,1,"mono cell-text svelte-3q62eu",null,At,An),M(dt,c($).target_channel_id??"-")},[()=>Kt(c($).uid),()=>({"cell-text-hidden":C(c($).uid,"schedule")}),()=>({"cell-text-hidden":C(c($).uid,"prompt")}),()=>c($).prompt.slice(0,60),()=>({"cell-text-hidden":C(c($).uid,"agent_id")}),()=>({"cell-text-hidden":C(c($).uid,"target_channel_id")})]),V("click",he,Xe=>y(Xe,c($))),V("click",te,()=>A(c($),"schedule")),V("click",Jt,()=>A(c($),"prompt")),V("click",ys,()=>A(c($),"agent_id")),V("click",We,()=>A(c($),"target_channel_id")),V("click",Mt,()=>F(c($).uid)),k(pe,he)}),k(ve,ye)},$$slots:{toolbar:!0,default:!0}})}var Z=f(fe,2);{var le=be=>{O0(be,{get bird(){return c(x)},onclose:()=>{b(v,null)}})};H(Z,be=>{c(x)&&be(le)})}k(N,ae)};H(oe,N=>{a.loading?N(de):N(J,!1)})}k(t,j),nt()}ht(["click","keydown"]);function lf(t){return t>>>0}function Fr(t){return t|0}let El="warn",Ke=()=>{},Vt=()=>{},jt=()=>{},ot=()=>{};function of(t){if(typeof t>"u"?t=El:El=t,Ke=Vt=jt=ot=()=>{},typeof window.console<"u")switch(t){case"debug":Ke=console.debug.bind(window.console);case"info":Vt=console.info.bind(window.console);case"warn":jt=console.warn.bind(window.console);case"error":ot=console.error.bind(window.console);case"none":break;default:throw new window.Error("invalid logging type '"+t+"'")}}of();function Oi(t,e=!1){try{return decodeURIComponent(escape(t))}catch(s){if(s instanceof URIError&&e)return t;throw s}}function Ws(t){return unescape(encodeURIComponent(t))}const Zr={toBase64Table:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),base64Pad:"=",encode(t){let e="";const s=t.length,n=s%3;for(let i=0;i<s-2;i+=3)e+=this.toBase64Table[t[i]>>2],e+=this.toBase64Table[((t[i]&3)<<4)+(t[i+1]>>4)],e+=this.toBase64Table[((t[i+1]&15)<<2)+(t[i+2]>>6)],e+=this.toBase64Table[t[i+2]&63];const a=s-n;return n===2?(e+=this.toBase64Table[t[a]>>2],e+=this.toBase64Table[((t[a]&3)<<4)+(t[a+1]>>4)],e+=this.toBase64Table[(t[a+1]&15)<<2],e+=this.toBase64Table[64]):n===1&&(e+=this.toBase64Table[t[a]>>2],e+=this.toBase64Table[(t[a]&3)<<4],e+=this.toBase64Table[64],e+=this.toBase64Table[64]),e},toBinaryTable:[-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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1],decode(t,e=0){let s=t.indexOf("=")-e;s<0&&(s=t.length-e);const n=(s>>2)*3+Math.floor(s%4/1.5),a=new Array(n);let i=0,r=0;for(let l=0,d=e;d<t.length;d++){const o=this.toBinaryTable[t.charCodeAt(d)&127],u=t.charAt(d)===this.base64Pad;if(o===-1){ot("Illegal character code "+t.charCodeAt(d)+" at position "+d);continue}r=r<<6|o,i+=6,i>=8&&(i-=8,u||(a[l++]=r>>i&255),r&=(1<<i)-1)}if(i){const l=new Error("Corrupted base64 string");throw l.name="Base64-Error",l}return a}};let jc="ontouchstart"in document.documentElement||document.ontouchstart!==void 0||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;window.addEventListener("touchstart",function t(){jc=!0,window.removeEventListener("touchstart",t,!1)},!1);let ei=10*(window.devicePixelRatio||1),Yc=!1;try{const t=document.createElement("canvas");t.style.cursor='url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default',t.style.cursor.indexOf("url")===0?(Vt("Data URI scheme cursor supported"),Yc=!0):jt("Data URI scheme cursor not supported")}catch(t){ot("Data URI scheme cursor test exception: "+t)}const cf=Yc;let df=!0;try{const t=document.createElement("div");t.style.visibility="hidden",t.style.overflow="scroll",document.body.appendChild(t);const e=document.createElement("div");t.appendChild(e);const s=t.offsetWidth-e.offsetWidth;t.parentNode.removeChild(t),df=s!=0}catch(t){ot("Scrollbar test exception: "+t)}let Zc=!1;async function uf(){if(!("VideoDecoder"in window))return!1;const t={codec:"avc1.42401f",codedWidth:1920,codedHeight:1080,optimizeForLatency:!0};if(!(await VideoDecoder.isConfigSupported(t)).supported)return!1;const s=new Uint8Array(Zr.decode("AAAAAWdCwBTZnpuAgICgAAADACAAAAZB4oVNAAAAAWjJYyyAAAABBgX//4HcRem95tlIt5Ys2CDZI+7veDI2NCAtIGNvcmUgMTY0IHIzMTA4IDMxZTE5ZjkgLSBILjI2NC9NUEVHLTQgQVZDIGNvZGVjIC0gQ29weWxlZnQgMjAwMy0yMDIzIC0gaHR0cDovL3d3dy52aWRlb2xhbi5vcmcveDI2NC5odG1sIC0gb3B0aW9uczogY2FiYWM9MCByZWY9NSBkZWJsb2NrPTE6MDowIGFuYWx5c2U9MHgxOjB4MTExIG1lPWhleCBzdWJtZT04IHBzeT0xIHBzeV9yZD0xLjAwOjAuMDAgbWl4ZWRfcmVmPTEgbWVfcmFuZ2U9MTYgY2hyb21hX21lPTEgdHJlbGxpcz0yIDh4OGRjdD0wIGNxbT0wIGRlYWR6b25lPTIxLDExIGZhc3RfcHNraXA9MSBjaHJvbWFfcXBfb2Zmc2V0PS0yIHRocmVhZHM9MSBsb29rYWhlYWRfdGhyZWFkcz0xIHNsaWNlZF90aHJlYWRzPTAgbnI9MCBkZWNpbWF0ZT0xIGludGVybGFjZWQ9MCBibHVyYXlfY29tcGF0PTAgY29uc3RyYWluZWRfaW50cmE9MCBiZnJhbWVzPTAgd2VpZ2h0cD0wIGtleWludD1pbmZpbml0ZSBrZXlpbnRfbWluPTI1IHNjZW5lY3V0PTQwIGludHJhX3JlZnJlc2g9MCByY19sb29rYWhlYWQ9NTAgcmM9YWJyIG1idHJlZT0xIGJpdHJhdGU9NDAwIHJhdGV0b2w9MS4wIHFjb21wPTAuNjAgcXBtaW49MCBxcG1heD02OSBxcHN0ZXA9NCBpcF9yYXRpbz0xLjQwIGFxPTE6MS4wMACAAAABZYiEBrxmKAAPVccAAS044AA5DRJMnkycJk4TPw=="));let n=!1,a=null,i=new VideoDecoder({output:l=>{n=!0,l.close()},error:l=>{a=l}}),r=new EncodedVideoChunk({timestamp:0,type:"key",data:s});i.configure(t),i.decode(r);try{await i.flush()}catch(l){a=l}return!(!n||a!==null)}Zc=await uf();function Wn(){return!!/mac/i.exec(navigator.platform)}function hi(){return!!/win/i.exec(navigator.platform)}function fa(){return!!/ipad/i.exec(navigator.platform)||!!/iphone/i.exec(navigator.platform)||!!/ipod/i.exec(navigator.platform)}function _a(t,e,s){const n=s.getBoundingClientRect();let a={x:0,y:0};return t<n.left?a.x=0:t>=n.right?a.x=n.width-1:a.x=t-n.left,e<n.top?a.y=0:e>=n.bottom?a.y=n.height-1:a.y=e-n.top,a}function Vn(t){t.stopPropagation(),t.preventDefault()}let Vi=!1,Jc=null;document.captureElement=null;function Fn(t){if(Vi)return;const e=new t.constructor(t.type,t);Vi=!0,document.captureElement?document.captureElement.dispatchEvent(e):Jc.dispatchEvent(e),Vi=!1,t.stopPropagation(),e.defaultPrevented&&t.preventDefault(),t.type==="mouseup"&&td()}function $c(){const t=document.getElementById("noVNC_mouse_capture_elem");t.style.cursor=window.getComputedStyle(document.captureElement).cursor}const ed=new MutationObserver($c);function hf(t){if(t.setCapture)t.setCapture(),document.captureElement=t;else{td();let e=document.getElementById("noVNC_mouse_capture_elem");e===null&&(e=document.createElement("div"),e.id="noVNC_mouse_capture_elem",e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.width="100%",e.style.height="100%",e.style.zIndex=1e4,e.style.display="none",document.body.appendChild(e),e.addEventListener("contextmenu",Fn),e.addEventListener("mousemove",Fn),e.addEventListener("mouseup",Fn)),document.captureElement=t,ed.observe(t,{attributes:!0}),$c(),e.style.display="",window.addEventListener("mousemove",Fn),window.addEventListener("mouseup",Fn)}}function td(){if(document.releaseCapture)document.releaseCapture(),document.captureElement=null;else{if(!document.captureElement)return;Jc=document.captureElement,document.captureElement=null,ed.disconnect();const t=document.getElementById("noVNC_mouse_capture_elem");t.style.display="none",window.removeEventListener("mousemove",Fn),window.removeEventListener("mouseup",Fn)}}class sd{constructor(){this._listeners=new Map}addEventListener(e,s){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(s)}removeEventListener(e,s){this._listeners.has(e)&&this._listeners.get(e).delete(s)}dispatchEvent(e){return this._listeners.has(e.type)?(this._listeners.get(e.type).forEach(s=>s.call(this,e)),!e.defaultPrevented):!0}}class ff{constructor(e){if(this._drawCtx=null,this._renderQ=[],this._flushPromise=null,this._fbWidth=0,this._fbHeight=0,this._prevDrawStyle="",Ke(">> Display.constructor"),this._target=e,!this._target)throw new Error("Target must be set");if(typeof this._target=="string")throw new Error("target must be a DOM element");if(!this._target.getContext)throw new Error("no getContext method");this._targetCtx=this._target.getContext("2d"),this._viewportLoc={x:0,y:0,w:this._target.width,h:this._target.height},this._backbuffer=document.createElement("canvas"),this._drawCtx=this._backbuffer.getContext("2d"),this._damageBounds={left:0,top:0,right:this._backbuffer.width,bottom:this._backbuffer.height},Ke("User Agent: "+navigator.userAgent),Ke("<< Display.constructor"),this._scale=1,this._clipViewport=!1}get scale(){return this._scale}set scale(e){this._rescale(e)}get clipViewport(){return this._clipViewport}set clipViewport(e){this._clipViewport=e;const s=this._viewportLoc;this.viewportChangeSize(s.w,s.h),this.viewportChangePos(0,0)}get width(){return this._fbWidth}get height(){return this._fbHeight}viewportChangePos(e,s){const n=this._viewportLoc;e=Math.floor(e),s=Math.floor(s),this._clipViewport||(e=-n.w,s=-n.h);const a=n.x+n.w-1,i=n.y+n.h-1;e<0&&n.x+e<0&&(e=-n.x),a+e>=this._fbWidth&&(e-=a+e-this._fbWidth+1),n.y+s<0&&(s=-n.y),i+s>=this._fbHeight&&(s-=i+s-this._fbHeight+1),!(e===0&&s===0)&&(Ke("viewportChange deltaX: "+e+", deltaY: "+s),n.x+=e,n.y+=s,this._damage(n.x,n.y,n.w,n.h),this.flip())}viewportChangeSize(e,s){(!this._clipViewport||typeof e>"u"||typeof s>"u")&&(Ke("Setting viewport to full display region"),e=this._fbWidth,s=this._fbHeight),e=Math.floor(e),s=Math.floor(s),e>this._fbWidth&&(e=this._fbWidth),s>this._fbHeight&&(s=this._fbHeight);const n=this._viewportLoc;if(n.w!==e||n.h!==s){n.w=e,n.h=s;const a=this._target;a.width=e,a.height=s,this.viewportChangePos(0,0),this._damage(n.x,n.y,n.w,n.h),this.flip(),this._rescale(this._scale)}}absX(e){return this._scale===0?0:Fr(e/this._scale+this._viewportLoc.x)}absY(e){return this._scale===0?0:Fr(e/this._scale+this._viewportLoc.y)}resize(e,s){this._prevDrawStyle="",this._fbWidth=e,this._fbHeight=s;const n=this._backbuffer;if(n.width!==e||n.height!==s){let i=null;n.width>0&&n.height>0&&(i=this._drawCtx.getImageData(0,0,n.width,n.height)),n.width!==e&&(n.width=e),n.height!==s&&(n.height=s),i&&this._drawCtx.putImageData(i,0,0)}const a=this._viewportLoc;this.viewportChangeSize(a.w,a.h),this.viewportChangePos(0,0)}getImageData(){return this._drawCtx.getImageData(0,0,this.width,this.height)}toDataURL(e,s){return this._backbuffer.toDataURL(e,s)}toBlob(e,s,n){return this._backbuffer.toBlob(e,s,n)}_damage(e,s,n,a){e<this._damageBounds.left&&(this._damageBounds.left=e),s<this._damageBounds.top&&(this._damageBounds.top=s),e+n>this._damageBounds.right&&(this._damageBounds.right=e+n),s+a>this._damageBounds.bottom&&(this._damageBounds.bottom=s+a)}flip(e){if(this._renderQ.length!==0&&!e)this._renderQPush({type:"flip"});else{let s=this._damageBounds.left,n=this._damageBounds.top,a=this._damageBounds.right-s,i=this._damageBounds.bottom-n,r=s-this._viewportLoc.x,l=n-this._viewportLoc.y;r<0&&(a+=r,s-=r,r=0),l<0&&(i+=l,n-=l,l=0),r+a>this._viewportLoc.w&&(a=this._viewportLoc.w-r),l+i>this._viewportLoc.h&&(i=this._viewportLoc.h-l),a>0&&i>0&&this._targetCtx.drawImage(this._backbuffer,s,n,a,i,r,l,a,i),this._damageBounds.left=this._damageBounds.top=65535,this._damageBounds.right=this._damageBounds.bottom=0}}pending(){return this._renderQ.length>0}flush(){return this._renderQ.length===0?Promise.resolve():(this._flushPromise===null&&(this._flushPromise=new Promise(e=>{this._flushResolve=e})),this._flushPromise)}fillRect(e,s,n,a,i,r){this._renderQ.length!==0&&!r?this._renderQPush({type:"fill",x:e,y:s,width:n,height:a,color:i}):(this._setFillColor(i),this._drawCtx.fillRect(e,s,n,a),this._damage(e,s,n,a))}copyImage(e,s,n,a,i,r,l){this._renderQ.length!==0&&!l?this._renderQPush({type:"copy",oldX:e,oldY:s,x:n,y:a,width:i,height:r}):(this._drawCtx.mozImageSmoothingEnabled=!1,this._drawCtx.webkitImageSmoothingEnabled=!1,this._drawCtx.msImageSmoothingEnabled=!1,this._drawCtx.imageSmoothingEnabled=!1,this._drawCtx.drawImage(this._backbuffer,e,s,i,r,n,a,i,r),this._damage(n,a,i,r))}imageRect(e,s,n,a,i,r){if(n===0||a===0)return;const l=new Image;l.src="data: "+i+";base64,"+Zr.encode(r),this._renderQPush({type:"img",img:l,x:e,y:s,width:n,height:a})}videoFrame(e,s,n,a,i){this._renderQPush({type:"frame",frame:i,x:e,y:s,width:n,height:a})}blitImage(e,s,n,a,i,r,l){if(this._renderQ.length!==0&&!l){const d=new Uint8Array(n*a*4);d.set(new Uint8Array(i.buffer,0,d.length)),this._renderQPush({type:"blit",data:d,x:e,y:s,width:n,height:a})}else{let d=new Uint8ClampedArray(i.buffer,i.byteOffset+r,n*a*4),o=new ImageData(d,n,a);this._drawCtx.putImageData(o,e,s),this._damage(e,s,n,a)}}drawImage(e,...s){if(this._drawCtx.drawImage(e,...s),s.length<=4){const[n,a]=s;this._damage(n,a,e.width,e.height)}else{const[,,n,a,i,r]=s;this._damage(i,r,n,a)}}autoscale(e,s){let n;if(e===0||s===0)n=0;else{const a=this._viewportLoc,i=e/s;a.w/a.h>=i?n=e/a.w:n=s/a.h}this._rescale(n)}_rescale(e){this._scale=e;const s=this._viewportLoc,n=e*s.w+"px",a=e*s.h+"px";(this._target.style.width!==n||this._target.style.height!==a)&&(this._target.style.width=n,this._target.style.height=a)}_setFillColor(e){const s="rgb("+e[0]+","+e[1]+","+e[2]+")";s!==this._prevDrawStyle&&(this._drawCtx.fillStyle=s,this._prevDrawStyle=s)}_renderQPush(e){this._renderQ.push(e),this._renderQ.length===1&&this._scanRenderQ()}_resumeRenderQ(){this.removeEventListener("load",this._noVNCDisplay._resumeRenderQ),this._noVNCDisplay._scanRenderQ()}_scanRenderQ(){let e=!0;for(;e&&this._renderQ.length>0;){const s=this._renderQ[0];switch(s.type){case"flip":this.flip(!0);break;case"copy":this.copyImage(s.oldX,s.oldY,s.x,s.y,s.width,s.height,!0);break;case"fill":this.fillRect(s.x,s.y,s.width,s.height,s.color,!0);break;case"blit":this.blitImage(s.x,s.y,s.width,s.height,s.data,0,!0);break;case"img":if(s.img.complete){if(s.img.width!==s.width||s.img.height!==s.height){ot("Decoded image has incorrect dimensions. Got "+s.img.width+"x"+s.img.height+". Expected "+s.width+"x"+s.height+".");return}this.drawImage(s.img,s.x,s.y),s.img.src=""}else s.img._noVNCDisplay=this,s.img.addEventListener("load",this._resumeRenderQ),e=!1;break;case"frame":if(s.frame.ready){let n=s.frame.frame;(n.codedWidth<s.width||n.codedHeight<s.height)&&jt("Decoded video frame does not cover its full rectangle area. Expecting at least "+s.width+"x"+s.height+" but got "+n.codedWidth+"x"+n.codedHeight);const a=0,i=0,r=s.width,l=s.height,d=s.x,o=s.y,u=r,_=l;this.drawImage(n,a,i,r,l,d,o,u,_),n.close()}else{let n=this;s.frame.promise.then(()=>{n._scanRenderQ()}),e=!1}break}e&&this._renderQ.shift()}this._renderQ.length===0&&this._flushPromise!==null&&(this._flushResolve(),this._flushPromise=null,this._flushResolve=null)}}function sn(t,e,s,n,a){if(e.subarray&&t.subarray){t.set(e.subarray(s,s+n),a);return}for(var i=0;i<n;i++)t[a+i]=e[s+i]}var mi=Uint8Array,gs=Uint16Array,wi=Int32Array;function Tr(t,e,s,n){for(var a=t&65535|0,i=t>>>16&65535|0,r=0;s!==0;){r=s>2e3?2e3:s,s-=r;do a=a+e[n++]|0,i=i+a|0;while(--r);a%=65521,i%=65521}return a|i<<16|0}function Ct(){for(var t,e=[],s=0;s<256;s++){t=s;for(var n=0;n<8;n++)t=t&1?3988292384^t>>>1:t>>>1;e[s]=t}return e}Ct();var ti=30,_f=12;function vf(t,e){var s,n,a,i,r,l,d,o,u,_,p,v,x,y,w,S,E,K,A,U,ee,X,C,F,L;s=t.state,n=t.next_in,F=t.input,a=n+(t.avail_in-5),i=t.next_out,L=t.output,r=i-(e-t.avail_out),l=i+(t.avail_out-257),d=s.dmax,o=s.wsize,u=s.whave,_=s.wnext,p=s.window,v=s.hold,x=s.bits,y=s.lencode,w=s.distcode,S=(1<<s.lenbits)-1,E=(1<<s.distbits)-1;e:do{x<15&&(v+=F[n++]<<x,x+=8,v+=F[n++]<<x,x+=8),K=y[v&S];t:for(;;){if(A=K>>>24,v>>>=A,x-=A,A=K>>>16&255,A===0)L[i++]=K&65535;else if(A&16){U=K&65535,A&=15,A&&(x<A&&(v+=F[n++]<<x,x+=8),U+=v&(1<<A)-1,v>>>=A,x-=A),x<15&&(v+=F[n++]<<x,x+=8,v+=F[n++]<<x,x+=8),K=w[v&E];s:for(;;){if(A=K>>>24,v>>>=A,x-=A,A=K>>>16&255,A&16){if(ee=K&65535,A&=15,x<A&&(v+=F[n++]<<x,x+=8,x<A&&(v+=F[n++]<<x,x+=8)),ee+=v&(1<<A)-1,ee>d){t.msg="invalid distance too far back",s.mode=ti;break e}if(v>>>=A,x-=A,A=i-r,ee>A){if(A=ee-A,A>u&&s.sane){t.msg="invalid distance too far back",s.mode=ti;break e}if(X=0,C=p,_===0){if(X+=o-A,A<U){U-=A;do L[i++]=p[X++];while(--A);X=i-ee,C=L}}else if(_<A){if(X+=o+_-A,A-=_,A<U){U-=A;do L[i++]=p[X++];while(--A);if(X=0,_<U){A=_,U-=A;do L[i++]=p[X++];while(--A);X=i-ee,C=L}}}else if(X+=_-A,A<U){U-=A;do L[i++]=p[X++];while(--A);X=i-ee,C=L}for(;U>2;)L[i++]=C[X++],L[i++]=C[X++],L[i++]=C[X++],U-=3;U&&(L[i++]=C[X++],U>1&&(L[i++]=C[X++]))}else{X=i-ee;do L[i++]=L[X++],L[i++]=L[X++],L[i++]=L[X++],U-=3;while(U>2);U&&(L[i++]=L[X++],U>1&&(L[i++]=L[X++]))}}else if((A&64)===0){K=w[(K&65535)+(v&(1<<A)-1)];continue s}else{t.msg="invalid distance code",s.mode=ti;break e}break}}else if((A&64)===0){K=y[(K&65535)+(v&(1<<A)-1)];continue t}else if(A&32){s.mode=_f;break e}else{t.msg="invalid literal/length code",s.mode=ti;break e}break}}while(n<a&&i<l);U=x>>3,n-=U,x-=U<<3,v&=(1<<x)-1,t.next_in=n,t.next_out=i,t.avail_in=n<a?5+(a-n):5-(n-a),t.avail_out=i<l?257+(l-i):257-(i-l),s.hold=v,s.bits=x}var Gn=15,Al=852,Kl=592,Fl=0,Gi=1,Tl=2,pf=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],gf=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],xf=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],bf=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];function Ta(t,e,s,n,a,i,r,l){var d=l.bits,o=0,u=0,_=0,p=0,v=0,x=0,y=0,w=0,S=0,E=0,K,A,U,ee,X,C=null,F=0,L,j=new gs(Gn+1),oe=new gs(Gn+1),de=null,J=0,N,se,ae;for(o=0;o<=Gn;o++)j[o]=0;for(u=0;u<n;u++)j[e[s+u]]++;for(v=d,p=Gn;p>=1&&j[p]===0;p--);if(v>p&&(v=p),p===0)return a[i++]=1<<24|64<<16|0,a[i++]=1<<24|64<<16|0,l.bits=1,0;for(_=1;_<p&&j[_]===0;_++);for(v<_&&(v=_),w=1,o=1;o<=Gn;o++)if(w<<=1,w-=j[o],w<0)return-1;if(w>0&&(t===Fl||p!==1))return-1;for(oe[1]=0,o=1;o<Gn;o++)oe[o+1]=oe[o]+j[o];for(u=0;u<n;u++)e[s+u]!==0&&(r[oe[e[s+u]]++]=u);if(t===Fl?(C=de=r,L=19):t===Gi?(C=pf,F-=257,de=gf,J-=257,L=256):(C=xf,de=bf,L=-1),E=0,u=0,o=_,X=i,x=v,y=0,U=-1,S=1<<v,ee=S-1,t===Gi&&S>Al||t===Tl&&S>Kl)return 1;for(;;){N=o-y,r[u]<L?(se=0,ae=r[u]):r[u]>L?(se=de[J+r[u]],ae=C[F+r[u]]):(se=96,ae=0),K=1<<o-y,A=1<<x,_=A;do A-=K,a[X+(E>>y)+A]=N<<24|se<<16|ae|0;while(A!==0);for(K=1<<o-1;E&K;)K>>=1;if(K!==0?(E&=K-1,E+=K):E=0,u++,--j[o]===0){if(o===p)break;o=e[s+r[u]]}if(o>v&&(E&ee)!==U){for(y===0&&(y=v),X+=_,x=o-y,w=1<<x;x+y<p&&(w-=j[x+y],!(w<=0));)x++,w<<=1;if(S+=1<<x,t===Gi&&S>Al||t===Tl&&S>Kl)return 1;U=E&ee,a[U]=v<<24|x<<16|X-i|0}}return E!==0&&(a[X+E]=o-y<<24|64<<16|0),l.bits=v,0}var mf=0,nd=1,ad=2;const Ml=4,yi=0,wf=1,yf=2,Hn=-2,kf=-3,Sf=-4,Cf=-5,Xl=8;var id=1,Ll=2,Pl=3,Bl=4,Dl=5,Rl=6,Il=7,Ql=8,zl=9,Nl=10,Ul=11,Gs=12,qi=13,Hl=14,Wi=15,Ol=16,Vl=17,Gl=18,ql=19,si=20,ni=21,Wl=22,jl=23,Yl=24,Zl=25,Jl=26,ji=27,$l=28,eo=29,rt=30,Ef=31,Af=32,Kf=852,Ff=592,Tf=15,Mf=Tf;function to(t){return(t>>>24&255)+(t>>>8&65280)+((t&65280)<<8)+((t&255)<<24)}function Xf(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new gs(320),this.work=new gs(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Lf(t){var e;return!t||!t.state?Hn:(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=e.wrap&1),e.mode=id,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new wi(Kf),e.distcode=e.distdyn=new wi(Ff),e.sane=1,e.back=-1,yi)}function rd(t){var e;return!t||!t.state?Hn:(e=t.state,e.wsize=0,e.whave=0,e.wnext=0,Lf(t))}function Pf(t,e){var s,n;return!t||!t.state||(n=t.state,e<0?(s=0,e=-e):(s=(e>>4)+1,e<48&&(e&=15)),e&&(e<8||e>15))?Hn:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=s,n.wbits=e,rd(t))}function Bf(t,e){var s,n;return t?(n=new Xf,t.state=n,n.window=null,s=Pf(t,e),s!==yi&&(t.state=null),s):Hn}function Df(t){return Bf(t,Mf)}var so=!0,Yi,Zi;function Rf(t){if(so){var e;for(Yi=new wi(512),Zi=new wi(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Ta(nd,t.lens,0,288,Yi,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Ta(ad,t.lens,0,32,Zi,0,t.work,{bits:5}),so=!1}t.lencode=Yi,t.lenbits=9,t.distcode=Zi,t.distbits=5}function If(t,e,s,n){var a,i=t.state;return i.window===null&&(i.wsize=1<<i.wbits,i.wnext=0,i.whave=0,i.window=new mi(i.wsize)),n>=i.wsize?(sn(i.window,e,s-i.wsize,i.wsize,0),i.wnext=0,i.whave=i.wsize):(a=i.wsize-i.wnext,a>n&&(a=n),sn(i.window,e,s-n,a,i.wnext),n-=a,n?(sn(i.window,e,s-n,n,0),i.wnext=n,i.whave=i.wsize):(i.wnext+=a,i.wnext===i.wsize&&(i.wnext=0),i.whave<i.wsize&&(i.whave+=a))),0}function Qf(t,e){var s,n,a,i,r,l,d,o,u,_,p,v,x,y,w=0,S,E,K,A,U,ee,X,C,F=new mi(4),L,j,oe=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!t||!t.state||!t.output||!t.input&&t.avail_in!==0)return Hn;s=t.state,s.mode===Gs&&(s.mode=qi),r=t.next_out,a=t.output,d=t.avail_out,i=t.next_in,n=t.input,l=t.avail_in,o=s.hold,u=s.bits,_=l,p=d,C=yi;e:for(;;)switch(s.mode){case id:if(s.wrap===0){s.mode=qi;break}for(;u<16;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(s.wrap&2&&o===35615){s.check=0,F[0]=o&255,F[1]=o>>>8&255,s.check=Ct(s.check),o=0,u=0,s.mode=Ll;break}if(s.flags=0,s.head&&(s.head.done=!1),!(s.wrap&1)||(((o&255)<<8)+(o>>8))%31){t.msg="incorrect header check",s.mode=rt;break}if((o&15)!==Xl){t.msg="unknown compression method",s.mode=rt;break}if(o>>>=4,u-=4,X=(o&15)+8,s.wbits===0)s.wbits=X;else if(X>s.wbits){t.msg="invalid window size",s.mode=rt;break}s.dmax=1<<X,t.adler=s.check=1,s.mode=o&512?Nl:Gs,o=0,u=0;break;case Ll:for(;u<16;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(s.flags=o,(s.flags&255)!==Xl){t.msg="unknown compression method",s.mode=rt;break}if(s.flags&57344){t.msg="unknown header flags set",s.mode=rt;break}s.head&&(s.head.text=o>>8&1),s.flags&512&&(F[0]=o&255,F[1]=o>>>8&255,s.check=Ct(s.check)),o=0,u=0,s.mode=Pl;case Pl:for(;u<32;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}s.head&&(s.head.time=o),s.flags&512&&(F[0]=o&255,F[1]=o>>>8&255,F[2]=o>>>16&255,F[3]=o>>>24&255,s.check=Ct(s.check)),o=0,u=0,s.mode=Bl;case Bl:for(;u<16;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}s.head&&(s.head.xflags=o&255,s.head.os=o>>8),s.flags&512&&(F[0]=o&255,F[1]=o>>>8&255,s.check=Ct(s.check)),o=0,u=0,s.mode=Dl;case Dl:if(s.flags&1024){for(;u<16;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}s.length=o,s.head&&(s.head.extra_len=o),s.flags&512&&(F[0]=o&255,F[1]=o>>>8&255,s.check=Ct(s.check)),o=0,u=0}else s.head&&(s.head.extra=null);s.mode=Rl;case Rl:if(s.flags&1024&&(v=s.length,v>l&&(v=l),v&&(s.head&&(X=s.head.extra_len-s.length,s.head.extra||(s.head.extra=new Array(s.head.extra_len)),sn(s.head.extra,n,i,v,X)),s.flags&512&&(s.check=Ct(s.check)),l-=v,i+=v,s.length-=v),s.length))break e;s.length=0,s.mode=Il;case Il:if(s.flags&2048){if(l===0)break e;v=0;do X=n[i+v++],s.head&&X&&s.length<65536&&(s.head.name+=String.fromCharCode(X));while(X&&v<l);if(s.flags&512&&(s.check=Ct(s.check)),l-=v,i+=v,X)break e}else s.head&&(s.head.name=null);s.length=0,s.mode=Ql;case Ql:if(s.flags&4096){if(l===0)break e;v=0;do X=n[i+v++],s.head&&X&&s.length<65536&&(s.head.comment+=String.fromCharCode(X));while(X&&v<l);if(s.flags&512&&(s.check=Ct(s.check)),l-=v,i+=v,X)break e}else s.head&&(s.head.comment=null);s.mode=zl;case zl:if(s.flags&512){for(;u<16;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(o!==(s.check&65535)){t.msg="header crc mismatch",s.mode=rt;break}o=0,u=0}s.head&&(s.head.hcrc=s.flags>>9&1,s.head.done=!0),t.adler=s.check=0,s.mode=Gs;break;case Nl:for(;u<32;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}t.adler=s.check=to(o),o=0,u=0,s.mode=Ul;case Ul:if(s.havedict===0)return t.next_out=r,t.avail_out=d,t.next_in=i,t.avail_in=l,s.hold=o,s.bits=u,yf;t.adler=s.check=1,s.mode=Gs;case Gs:case qi:if(s.last){o>>>=u&7,u-=u&7,s.mode=ji;break}for(;u<3;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}switch(s.last=o&1,o>>>=1,u-=1,o&3){case 0:s.mode=Hl;break;case 1:Rf(s),s.mode=si;break;case 2:s.mode=Vl;break;case 3:t.msg="invalid block type",s.mode=rt}o>>>=2,u-=2;break;case Hl:for(o>>>=u&7,u-=u&7;u<32;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if((o&65535)!==(o>>>16^65535)){t.msg="invalid stored block lengths",s.mode=rt;break}s.length=o&65535,o=0,u=0,s.mode=Wi;case Wi:s.mode=Ol;case Ol:if(v=s.length,v){if(v>l&&(v=l),v>d&&(v=d),v===0)break e;sn(a,n,i,v,r),l-=v,i+=v,d-=v,r+=v,s.length-=v;break}s.mode=Gs;break;case Vl:for(;u<14;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(s.nlen=(o&31)+257,o>>>=5,u-=5,s.ndist=(o&31)+1,o>>>=5,u-=5,s.ncode=(o&15)+4,o>>>=4,u-=4,s.nlen>286||s.ndist>30){t.msg="too many length or distance symbols",s.mode=rt;break}s.have=0,s.mode=Gl;case Gl:for(;s.have<s.ncode;){for(;u<3;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}s.lens[oe[s.have++]]=o&7,o>>>=3,u-=3}for(;s.have<19;)s.lens[oe[s.have++]]=0;if(s.lencode=s.lendyn,s.lenbits=7,L={bits:s.lenbits},C=Ta(mf,s.lens,0,19,s.lencode,0,s.work,L),s.lenbits=L.bits,C){t.msg="invalid code lengths set",s.mode=rt;break}s.have=0,s.mode=ql;case ql:for(;s.have<s.nlen+s.ndist;){for(;w=s.lencode[o&(1<<s.lenbits)-1],S=w>>>24,E=w>>>16&255,K=w&65535,!(S<=u);){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(K<16)o>>>=S,u-=S,s.lens[s.have++]=K;else{if(K===16){for(j=S+2;u<j;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(o>>>=S,u-=S,s.have===0){t.msg="invalid bit length repeat",s.mode=rt;break}X=s.lens[s.have-1],v=3+(o&3),o>>>=2,u-=2}else if(K===17){for(j=S+3;u<j;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}o>>>=S,u-=S,X=0,v=3+(o&7),o>>>=3,u-=3}else{for(j=S+7;u<j;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}o>>>=S,u-=S,X=0,v=11+(o&127),o>>>=7,u-=7}if(s.have+v>s.nlen+s.ndist){t.msg="invalid bit length repeat",s.mode=rt;break}for(;v--;)s.lens[s.have++]=X}}if(s.mode===rt)break;if(s.lens[256]===0){t.msg="invalid code -- missing end-of-block",s.mode=rt;break}if(s.lenbits=9,L={bits:s.lenbits},C=Ta(nd,s.lens,0,s.nlen,s.lencode,0,s.work,L),s.lenbits=L.bits,C){t.msg="invalid literal/lengths set",s.mode=rt;break}if(s.distbits=6,s.distcode=s.distdyn,L={bits:s.distbits},C=Ta(ad,s.lens,s.nlen,s.ndist,s.distcode,0,s.work,L),s.distbits=L.bits,C){t.msg="invalid distances set",s.mode=rt;break}s.mode=si;case si:s.mode=ni;case ni:if(l>=6&&d>=258){t.next_out=r,t.avail_out=d,t.next_in=i,t.avail_in=l,s.hold=o,s.bits=u,vf(t,p),r=t.next_out,a=t.output,d=t.avail_out,i=t.next_in,n=t.input,l=t.avail_in,o=s.hold,u=s.bits,s.mode===Gs&&(s.back=-1);break}for(s.back=0;w=s.lencode[o&(1<<s.lenbits)-1],S=w>>>24,E=w>>>16&255,K=w&65535,!(S<=u);){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(E&&(E&240)===0){for(A=S,U=E,ee=K;w=s.lencode[ee+((o&(1<<A+U)-1)>>A)],S=w>>>24,E=w>>>16&255,K=w&65535,!(A+S<=u);){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}o>>>=A,u-=A,s.back+=A}if(o>>>=S,u-=S,s.back+=S,s.length=K,E===0){s.mode=Jl;break}if(E&32){s.back=-1,s.mode=Gs;break}if(E&64){t.msg="invalid literal/length code",s.mode=rt;break}s.extra=E&15,s.mode=Wl;case Wl:if(s.extra){for(j=s.extra;u<j;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}s.length+=o&(1<<s.extra)-1,o>>>=s.extra,u-=s.extra,s.back+=s.extra}s.was=s.length,s.mode=jl;case jl:for(;w=s.distcode[o&(1<<s.distbits)-1],S=w>>>24,E=w>>>16&255,K=w&65535,!(S<=u);){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if((E&240)===0){for(A=S,U=E,ee=K;w=s.distcode[ee+((o&(1<<A+U)-1)>>A)],S=w>>>24,E=w>>>16&255,K=w&65535,!(A+S<=u);){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}o>>>=A,u-=A,s.back+=A}if(o>>>=S,u-=S,s.back+=S,E&64){t.msg="invalid distance code",s.mode=rt;break}s.offset=K,s.extra=E&15,s.mode=Yl;case Yl:if(s.extra){for(j=s.extra;u<j;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}s.offset+=o&(1<<s.extra)-1,o>>>=s.extra,u-=s.extra,s.back+=s.extra}if(s.offset>s.dmax){t.msg="invalid distance too far back",s.mode=rt;break}s.mode=Zl;case Zl:if(d===0)break e;if(v=p-d,s.offset>v){if(v=s.offset-v,v>s.whave&&s.sane){t.msg="invalid distance too far back",s.mode=rt;break}v>s.wnext?(v-=s.wnext,x=s.wsize-v):x=s.wnext-v,v>s.length&&(v=s.length),y=s.window}else y=a,x=r-s.offset,v=s.length;v>d&&(v=d),d-=v,s.length-=v;do a[r++]=y[x++];while(--v);s.length===0&&(s.mode=ni);break;case Jl:if(d===0)break e;a[r++]=s.length,d--,s.mode=ni;break;case ji:if(s.wrap){for(;u<32;){if(l===0)break e;l--,o|=n[i++]<<u,u+=8}if(p-=d,t.total_out+=p,s.total+=p,p&&(t.adler=s.check=s.flags?Ct(s.check):Tr(s.check,a,p,r-p)),p=d,(s.flags?o:to(o))!==s.check){t.msg="incorrect data check",s.mode=rt;break}o=0,u=0}s.mode=$l;case $l:if(s.wrap&&s.flags){for(;u<32;){if(l===0)break e;l--,o+=n[i++]<<u,u+=8}if(o!==(s.total&4294967295)){t.msg="incorrect length check",s.mode=rt;break}o=0,u=0}s.mode=eo;case eo:C=wf;break e;case rt:C=kf;break e;case Ef:return Sf;case Af:default:return Hn}return t.next_out=r,t.avail_out=d,t.next_in=i,t.avail_in=l,s.hold=o,s.bits=u,(s.wsize||p!==t.avail_out&&s.mode<rt&&(s.mode<ji||e!==Ml))&&If(t,t.output,t.next_out,p-t.avail_out),_-=t.avail_in,p-=t.avail_out,t.total_in+=_,t.total_out+=p,s.total+=p,s.wrap&&p&&(t.adler=s.check=s.flags?Ct(s.check,a,p,t.next_out-p):Tr(s.check,a,p,t.next_out-p)),t.data_type=s.bits+(s.last?64:0)+(s.mode===Gs?128:0)+(s.mode===si||s.mode===Wi?256:0),(_===0&&p===0||e===Ml)&&C===yi&&(C=Cf),C}function ld(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}class Bi{constructor(){this.strm=new ld,this.chunkSize=1024*10*10,this.strm.output=new Uint8Array(this.chunkSize),Df(this.strm)}setInput(e){e?(this.strm.input=e,this.strm.avail_in=this.strm.input.length,this.strm.next_in=0):(this.strm.input=null,this.strm.avail_in=0,this.strm.next_in=0)}inflate(e){if(e>this.chunkSize&&(this.chunkSize=e,this.strm.output=new Uint8Array(this.chunkSize)),this.strm.next_out=0,this.strm.avail_out=e,Qf(this.strm,0)<0)throw new Error("zlib inflate failed");if(this.strm.next_out!=e)throw new Error("Incomplete zlib block");return new Uint8Array(this.strm.output.buffer,0,this.strm.next_out)}reset(){rd(this.strm)}}var zf=4,no=0,ao=1,Nf=2;function ca(t){for(var e=t.length;--e>=0;)t[e]=0}var Uf=0,Hf=1,Of=2,Vf=3,Gf=258,Jr=29,qa=256,Pa=qa+1+Jr,ea=30,$r=19,od=2*Pa+1,Bn=15,Ji=16,qf=7,cd=256,dd=16,ud=17,hd=18,Mr=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],fi=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Wf=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],fd=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],jf=512,un=new Array((Pa+2)*2);ca(un);var Ma=new Array(ea*2);ca(Ma);var Ba=new Array(jf);ca(Ba);var Da=new Array(Gf-Vf+1);ca(Da);var el=new Array(Jr);ca(el);var ki=new Array(ea);ca(ki);function $i(t,e,s,n,a){this.static_tree=t,this.extra_bits=e,this.extra_base=s,this.elems=n,this.max_length=a,this.has_stree=t&&t.length}var _d,vd,pd;function er(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}function gd(t){return t<256?Ba[t]:Ba[256+(t>>>7)]}function Si(t,e){t.pending_buf[t.pending++]=e&255,t.pending_buf[t.pending++]=e>>>8&255}function ds(t,e,s){t.bi_valid>Ji-s?(t.bi_buf|=e<<t.bi_valid&65535,Si(t,t.bi_buf),t.bi_buf=e>>Ji-t.bi_valid,t.bi_valid+=s-Ji):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=s)}function js(t,e,s){ds(t,s[e*2],s[e*2+1])}function xd(t,e){var s=0;do s|=t&1,t>>>=1,s<<=1;while(--e>0);return s>>>1}function Yf(t,e){var s=e.dyn_tree,n=e.max_code,a=e.stat_desc.static_tree,i=e.stat_desc.has_stree,r=e.stat_desc.extra_bits,l=e.stat_desc.extra_base,d=e.stat_desc.max_length,o,u,_,p,v,x,y=0;for(p=0;p<=Bn;p++)t.bl_count[p]=0;for(s[t.heap[t.heap_max]*2+1]=0,o=t.heap_max+1;o<od;o++)u=t.heap[o],p=s[s[u*2+1]*2+1]+1,p>d&&(p=d,y++),s[u*2+1]=p,!(u>n)&&(t.bl_count[p]++,v=0,u>=l&&(v=r[u-l]),x=s[u*2],t.opt_len+=x*(p+v),i&&(t.static_len+=x*(a[u*2+1]+v)));if(y!==0){do{for(p=d-1;t.bl_count[p]===0;)p--;t.bl_count[p]--,t.bl_count[p+1]+=2,t.bl_count[d]--,y-=2}while(y>0);for(p=d;p!==0;p--)for(u=t.bl_count[p];u!==0;)_=t.heap[--o],!(_>n)&&(s[_*2+1]!==p&&(t.opt_len+=(p-s[_*2+1])*s[_*2],s[_*2+1]=p),u--)}}function bd(t,e,s){var n=new Array(Bn+1),a=0,i,r;for(i=1;i<=Bn;i++)n[i]=a=a+s[i-1]<<1;for(r=0;r<=e;r++){var l=t[r*2+1];l!==0&&(t[r*2]=xd(n[l]++,l))}}function Zf(){var t,e,s,n,a,i=new Array(Bn+1);for(s=0,n=0;n<Jr-1;n++)for(el[n]=s,t=0;t<1<<Mr[n];t++)Da[s++]=n;for(Da[s-1]=n,a=0,n=0;n<16;n++)for(ki[n]=a,t=0;t<1<<fi[n];t++)Ba[a++]=n;for(a>>=7;n<ea;n++)for(ki[n]=a<<7,t=0;t<1<<fi[n]-7;t++)Ba[256+a++]=n;for(e=0;e<=Bn;e++)i[e]=0;for(t=0;t<=143;)un[t*2+1]=8,t++,i[8]++;for(;t<=255;)un[t*2+1]=9,t++,i[9]++;for(;t<=279;)un[t*2+1]=7,t++,i[7]++;for(;t<=287;)un[t*2+1]=8,t++,i[8]++;for(bd(un,Pa+1,i),t=0;t<ea;t++)Ma[t*2+1]=5,Ma[t*2]=xd(t,5);_d=new $i(un,Mr,qa+1,Pa,Bn),vd=new $i(Ma,fi,0,ea,Bn),pd=new $i(new Array(0),Wf,0,$r,qf)}function md(t){var e;for(e=0;e<Pa;e++)t.dyn_ltree[e*2]=0;for(e=0;e<ea;e++)t.dyn_dtree[e*2]=0;for(e=0;e<$r;e++)t.bl_tree[e*2]=0;t.dyn_ltree[cd*2]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function wd(t){t.bi_valid>8?Si(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function Jf(t,e,s,n){wd(t),Si(t,s),Si(t,~s),sn(t.pending_buf,t.window,e,s,t.pending),t.pending+=s}function io(t,e,s,n){var a=e*2,i=s*2;return t[a]<t[i]||t[a]===t[i]&&n[e]<=n[s]}function tr(t,e,s){for(var n=t.heap[s],a=s<<1;a<=t.heap_len&&(a<t.heap_len&&io(e,t.heap[a+1],t.heap[a],t.depth)&&a++,!io(e,n,t.heap[a],t.depth));)t.heap[s]=t.heap[a],s=a,a<<=1;t.heap[s]=n}function ro(t,e,s){var n,a,i=0,r,l;if(t.last_lit!==0)do n=t.pending_buf[t.d_buf+i*2]<<8|t.pending_buf[t.d_buf+i*2+1],a=t.pending_buf[t.l_buf+i],i++,n===0?js(t,a,e):(r=Da[a],js(t,r+qa+1,e),l=Mr[r],l!==0&&(a-=el[r],ds(t,a,l)),n--,r=gd(n),js(t,r,s),l=fi[r],l!==0&&(n-=ki[r],ds(t,n,l)));while(i<t.last_lit);js(t,cd,e)}function Xr(t,e){var s=e.dyn_tree,n=e.stat_desc.static_tree,a=e.stat_desc.has_stree,i=e.stat_desc.elems,r,l,d=-1,o;for(t.heap_len=0,t.heap_max=od,r=0;r<i;r++)s[r*2]!==0?(t.heap[++t.heap_len]=d=r,t.depth[r]=0):s[r*2+1]=0;for(;t.heap_len<2;)o=t.heap[++t.heap_len]=d<2?++d:0,s[o*2]=1,t.depth[o]=0,t.opt_len--,a&&(t.static_len-=n[o*2+1]);for(e.max_code=d,r=t.heap_len>>1;r>=1;r--)tr(t,s,r);o=i;do r=t.heap[1],t.heap[1]=t.heap[t.heap_len--],tr(t,s,1),l=t.heap[1],t.heap[--t.heap_max]=r,t.heap[--t.heap_max]=l,s[o*2]=s[r*2]+s[l*2],t.depth[o]=(t.depth[r]>=t.depth[l]?t.depth[r]:t.depth[l])+1,s[r*2+1]=s[l*2+1]=o,t.heap[1]=o++,tr(t,s,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],Yf(t,e),bd(s,d,t.bl_count)}function lo(t,e,s){var n,a=-1,i,r=e[1],l=0,d=7,o=4;for(r===0&&(d=138,o=3),e[(s+1)*2+1]=65535,n=0;n<=s;n++)i=r,r=e[(n+1)*2+1],!(++l<d&&i===r)&&(l<o?t.bl_tree[i*2]+=l:i!==0?(i!==a&&t.bl_tree[i*2]++,t.bl_tree[dd*2]++):l<=10?t.bl_tree[ud*2]++:t.bl_tree[hd*2]++,l=0,a=i,r===0?(d=138,o=3):i===r?(d=6,o=3):(d=7,o=4))}function oo(t,e,s){var n,a=-1,i,r=e[1],l=0,d=7,o=4;for(r===0&&(d=138,o=3),n=0;n<=s;n++)if(i=r,r=e[(n+1)*2+1],!(++l<d&&i===r)){if(l<o)do js(t,i,t.bl_tree);while(--l!==0);else i!==0?(i!==a&&(js(t,i,t.bl_tree),l--),js(t,dd,t.bl_tree),ds(t,l-3,2)):l<=10?(js(t,ud,t.bl_tree),ds(t,l-3,3)):(js(t,hd,t.bl_tree),ds(t,l-11,7));l=0,a=i,r===0?(d=138,o=3):i===r?(d=6,o=3):(d=7,o=4)}}function $f(t){var e;for(lo(t,t.dyn_ltree,t.l_desc.max_code),lo(t,t.dyn_dtree,t.d_desc.max_code),Xr(t,t.bl_desc),e=$r-1;e>=3&&t.bl_tree[fd[e]*2+1]===0;e--);return t.opt_len+=3*(e+1)+5+5+4,e}function e_(t,e,s,n){var a;for(ds(t,e-257,5),ds(t,s-1,5),ds(t,n-4,4),a=0;a<n;a++)ds(t,t.bl_tree[fd[a]*2+1],3);oo(t,t.dyn_ltree,e-1),oo(t,t.dyn_dtree,s-1)}function t_(t){var e=4093624447,s;for(s=0;s<=31;s++,e>>>=1)if(e&1&&t.dyn_ltree[s*2]!==0)return no;if(t.dyn_ltree[18]!==0||t.dyn_ltree[20]!==0||t.dyn_ltree[26]!==0)return ao;for(s=32;s<qa;s++)if(t.dyn_ltree[s*2]!==0)return ao;return no}var co=!1;function s_(t){co||(Zf(),co=!0),t.l_desc=new er(t.dyn_ltree,_d),t.d_desc=new er(t.dyn_dtree,vd),t.bl_desc=new er(t.bl_tree,pd),t.bi_buf=0,t.bi_valid=0,md(t)}function yd(t,e,s,n){ds(t,(Uf<<1)+(n?1:0),3),Jf(t,e,s)}function n_(t,e,s,n){var a,i,r=0;t.level>0?(t.strm.data_type===Nf&&(t.strm.data_type=t_(t)),Xr(t,t.l_desc),Xr(t,t.d_desc),r=$f(t),a=t.opt_len+3+7>>>3,i=t.static_len+3+7>>>3,i<=a&&(a=i)):a=i=s+5,s+4<=a&&e!==-1?yd(t,e,s,n):t.strategy===zf||i===a?(ds(t,(Hf<<1)+(n?1:0),3),ro(t,un,Ma)):(ds(t,(Of<<1)+(n?1:0),3),e_(t,t.l_desc.max_code+1,t.d_desc.max_code+1,r+1),ro(t,t.dyn_ltree,t.dyn_dtree)),md(t),n&&wd(t)}function wn(t,e,s){return t.pending_buf[t.d_buf+t.last_lit*2]=e>>>8&255,t.pending_buf[t.d_buf+t.last_lit*2+1]=e&255,t.pending_buf[t.l_buf+t.last_lit]=s&255,t.last_lit++,e===0?t.dyn_ltree[s*2]++:(t.matches++,e--,t.dyn_ltree[(Da[s]+qa+1)*2]++,t.dyn_dtree[gd(e)*2]++),t.last_lit===t.lit_bufsize-1}const a_={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Wa=0,uo=3,Ra=4,i_=5,Yn=0,ta=-2,sr=-5,kd=-1,r_=1,ai=2,l_=3,o_=4,c_=0,d_=2,tl=8;var u_=15,h_=8,f_=29,__=256,Lr=__+1+f_,v_=30,p_=19,g_=2*Lr+1,x_=15,Oe=3,_n=258,Ks=_n+Oe+1,b_=32,Sd=42,ho=69,nr=73,ar=91,ir=103,ka=113,ii=666,Pt=1,ja=2,Ia=3,Di=4,m_=3;function Zn(t,e){return t.msg=a_[e],e}function fo(t){return(t<<1)-(t>4?9:0)}function Tn(t){for(var e=t.length;--e>=0;)t[e]=0}function Kn(t){var e=t.state,s=e.pending;s>t.avail_out&&(s=t.avail_out),s!==0&&(sn(t.output,e.pending_buf,e.pending_out,s,t.next_out),t.next_out+=s,e.pending_out+=s,t.total_out+=s,t.avail_out-=s,e.pending-=s,e.pending===0&&(e.pending_out=0))}function Yt(t,e){n_(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,Kn(t.strm)}function lt(t,e){t.pending_buf[t.pending++]=e}function rr(t,e){t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=e&255}function w_(t,e,s,n){var a=t.avail_in;return a>n&&(a=n),a===0?0:(t.avail_in-=a,sn(e,t.input,t.next_in,a,s),t.state.wrap===1?t.adler=Tr(t.adler,e,a,s):t.state.wrap===2&&(t.adler=Ct(t.adler)),t.next_in+=a,t.total_in+=a,a)}function Cd(t,e){var s=t.max_chain_length,n=t.strstart,a,i,r=t.prev_length,l=t.nice_match,d=t.strstart>t.w_size-Ks?t.strstart-(t.w_size-Ks):0,o=t.window,u=t.w_mask,_=t.prev,p=t.strstart+_n,v=o[n+r-1],x=o[n+r];t.prev_length>=t.good_match&&(s>>=2),l>t.lookahead&&(l=t.lookahead);do if(a=e,!(o[a+r]!==x||o[a+r-1]!==v||o[a]!==o[n]||o[++a]!==o[n+1])){n+=2,a++;do;while(o[++n]===o[++a]&&o[++n]===o[++a]&&o[++n]===o[++a]&&o[++n]===o[++a]&&o[++n]===o[++a]&&o[++n]===o[++a]&&o[++n]===o[++a]&&o[++n]===o[++a]&&n<p);if(i=_n-(p-n),n=p-_n,i>r){if(t.match_start=e,r=i,i>=l)break;v=o[n+r-1],x=o[n+r]}}while((e=_[e&u])>d&&--s!==0);return r<=t.lookahead?r:t.lookahead}function Ya(t){var e=t.w_size,s,n,a,i,r;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-Ks)){sn(t.window,t.window,e,e,0),t.match_start-=e,t.strstart-=e,t.block_start-=e,n=t.hash_size,s=n;do a=t.head[--s],t.head[s]=a>=e?a-e:0;while(--n);n=e,s=n;do a=t.prev[--s],t.prev[s]=a>=e?a-e:0;while(--n);i+=e}if(t.strm.avail_in===0)break;if(n=w_(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=Oe)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=(t.ins_h<<t.hash_shift^t.window[r+1])&t.hash_mask;t.insert&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[r+Oe-1])&t.hash_mask,t.prev[r&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=r,r++,t.insert--,!(t.lookahead+t.insert<Oe)););}while(t.lookahead<Ks&&t.strm.avail_in!==0)}function y_(t,e){var s=65535;for(s>t.pending_buf_size-5&&(s=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Ya(t),t.lookahead===0&&e===Wa)return Pt;if(t.lookahead===0)break}t.strstart+=t.lookahead,t.lookahead=0;var n=t.block_start+s;if((t.strstart===0||t.strstart>=n)&&(t.lookahead=t.strstart-n,t.strstart=n,Yt(t,!1),t.strm.avail_out===0)||t.strstart-t.block_start>=t.w_size-Ks&&(Yt(t,!1),t.strm.avail_out===0))return Pt}return t.insert=0,e===Ra?(Yt(t,!0),t.strm.avail_out===0?Ia:Di):(t.strstart>t.block_start&&(Yt(t,!1),t.strm.avail_out===0),Pt)}function lr(t,e){for(var s,n;;){if(t.lookahead<Ks){if(Ya(t),t.lookahead<Ks&&e===Wa)return Pt;if(t.lookahead===0)break}if(s=0,t.lookahead>=Oe&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+Oe-1])&t.hash_mask,s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),s!==0&&t.strstart-s<=t.w_size-Ks&&(t.match_length=Cd(t,s)),t.match_length>=Oe)if(n=wn(t,t.strstart-t.match_start,t.match_length-Oe),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=Oe){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+Oe-1])&t.hash_mask,s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart;while(--t.match_length!==0);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+1])&t.hash_mask;else n=wn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(n&&(Yt(t,!1),t.strm.avail_out===0))return Pt}return t.insert=t.strstart<Oe-1?t.strstart:Oe-1,e===Ra?(Yt(t,!0),t.strm.avail_out===0?Ia:Di):t.last_lit&&(Yt(t,!1),t.strm.avail_out===0)?Pt:ja}function qn(t,e){for(var s,n,a;;){if(t.lookahead<Ks){if(Ya(t),t.lookahead<Ks&&e===Wa)return Pt;if(t.lookahead===0)break}if(s=0,t.lookahead>=Oe&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+Oe-1])&t.hash_mask,s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=Oe-1,s!==0&&t.prev_length<t.max_lazy_match&&t.strstart-s<=t.w_size-Ks&&(t.match_length=Cd(t,s),t.match_length<=5&&(t.strategy===r_||t.match_length===Oe&&t.strstart-t.match_start>4096)&&(t.match_length=Oe-1)),t.prev_length>=Oe&&t.match_length<=t.prev_length){a=t.strstart+t.lookahead-Oe,n=wn(t,t.strstart-1-t.prev_match,t.prev_length-Oe),t.lookahead-=t.prev_length-1,t.prev_length-=2;do++t.strstart<=a&&(t.ins_h=(t.ins_h<<t.hash_shift^t.window[t.strstart+Oe-1])&t.hash_mask,s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart);while(--t.prev_length!==0);if(t.match_available=0,t.match_length=Oe-1,t.strstart++,n&&(Yt(t,!1),t.strm.avail_out===0))return Pt}else if(t.match_available){if(n=wn(t,0,t.window[t.strstart-1]),n&&Yt(t,!1),t.strstart++,t.lookahead--,t.strm.avail_out===0)return Pt}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(n=wn(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<Oe-1?t.strstart:Oe-1,e===Ra?(Yt(t,!0),t.strm.avail_out===0?Ia:Di):t.last_lit&&(Yt(t,!1),t.strm.avail_out===0)?Pt:ja}function k_(t,e){for(var s,n,a,i,r=t.window;!(t.lookahead<=_n&&(Ya(t),t.lookahead<=_n,t.lookahead===0));){if(t.match_length=0,t.lookahead>=Oe&&t.strstart>0&&(a=t.strstart-1,n=r[a],n===r[++a]&&n===r[++a]&&n===r[++a])){i=t.strstart+_n;do;while(n===r[++a]&&n===r[++a]&&n===r[++a]&&n===r[++a]&&n===r[++a]&&n===r[++a]&&n===r[++a]&&n===r[++a]&&a<i);t.match_length=_n-(i-a),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=Oe?(s=wn(t,1,t.match_length-Oe),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(s=wn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),s&&(Yt(t,!1),t.strm.avail_out===0))return Pt}return t.insert=0,t.last_lit&&(Yt(t,!1),t.strm.avail_out===0)?Pt:ja}function S_(t,e){for(var s;!(t.lookahead===0&&(Ya(t),t.lookahead===0));)if(t.match_length=0,s=wn(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,s&&(Yt(t,!1),t.strm.avail_out===0))return Pt;return t.insert=0,t.last_lit&&(Yt(t,!1),t.strm.avail_out===0)?Pt:ja}function Bs(t,e,s,n,a){this.good_length=t,this.max_lazy=e,this.nice_length=s,this.max_chain=n,this.func=a}var Jn;Jn=[new Bs(0,0,0,0,y_),new Bs(4,4,8,4,lr),new Bs(4,5,16,8,lr),new Bs(4,6,32,32,lr),new Bs(4,4,16,16,qn),new Bs(8,16,32,32,qn),new Bs(8,16,128,128,qn),new Bs(8,32,128,256,qn),new Bs(32,128,258,1024,qn),new Bs(32,258,258,4096,qn)];function C_(t){t.window_size=2*t.w_size,Tn(t.head),t.max_lazy_match=Jn[t.level].max_lazy,t.good_match=Jn[t.level].good_length,t.nice_match=Jn[t.level].nice_length,t.max_chain_length=Jn[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=Oe-1,t.match_available=0,t.ins_h=0}function E_(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=tl,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new gs(g_*2),this.dyn_dtree=new gs((2*v_+1)*2),this.bl_tree=new gs((2*p_+1)*2),Tn(this.dyn_ltree),Tn(this.dyn_dtree),Tn(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new gs(x_+1),this.heap=new gs(2*Lr+1),Tn(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new gs(2*Lr+1),Tn(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function A_(t){var e;return!t||!t.state?Zn(t,ta):(t.total_in=t.total_out=0,t.data_type=d_,e=t.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?Sd:ka,t.adler=e.wrap===2?0:1,e.last_flush=Wa,s_(e),Yn)}function K_(t){var e=A_(t);return e===Yn&&C_(t.state),e}function F_(t,e,s,n,a,i){if(!t)return ta;var r=1;if(e===kd&&(e=6),e<0||e>9||i<0||i>o_)return Zn(t,ta);var l=new E_;return t.state=l,l.strm=t,l.wrap=r,l.gzhead=null,l.w_bits=n,l.w_size=1<<l.w_bits,l.w_mask=l.w_size-1,l.hash_bits=a+7,l.hash_size=1<<l.hash_bits,l.hash_mask=l.hash_size-1,l.hash_shift=~~((l.hash_bits+Oe-1)/Oe),l.window=new mi(l.w_size*2),l.head=new gs(l.hash_size),l.prev=new gs(l.w_size),l.lit_bufsize=1<<a+6,l.pending_buf_size=l.lit_bufsize*4,l.pending_buf=new mi(l.pending_buf_size),l.d_buf=1*l.lit_bufsize,l.l_buf=3*l.lit_bufsize,l.level=e,l.strategy=i,l.method=s,K_(t)}function T_(t,e){return F_(t,e,tl,u_,h_,c_)}function _o(t,e){var s,n,a,i;if(!t||!t.state||e>i_||e<0)return t?Zn(t,ta):ta;if(n=t.state,!t.output||!t.input&&t.avail_in!==0||n.status===ii&&e!==Ra)return Zn(t,t.avail_out===0?sr:ta);if(n.strm=t,s=n.last_flush,n.last_flush=e,n.status===Sd)if(n.wrap===2)t.adler=0,lt(n,31),lt(n,139),lt(n,8),n.gzhead?(lt(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),lt(n,n.gzhead.time&255),lt(n,n.gzhead.time>>8&255),lt(n,n.gzhead.time>>16&255),lt(n,n.gzhead.time>>24&255),lt(n,n.level===9?2:n.strategy>=ai||n.level<2?4:0),lt(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(lt(n,n.gzhead.extra.length&255),lt(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(t.adler=Ct(t.adler,n.pending_buf,n.pending)),n.gzindex=0,n.status=ho):(lt(n,0),lt(n,0),lt(n,0),lt(n,0),lt(n,0),lt(n,n.level===9?2:n.strategy>=ai||n.level<2?4:0),lt(n,m_),n.status=ka);else{var r=tl+(n.w_bits-8<<4)<<8,l=-1;n.strategy>=ai||n.level<2?l=0:n.level<6?l=1:n.level===6?l=2:l=3,r|=l<<6,n.strstart!==0&&(r|=b_),r+=31-r%31,n.status=ka,rr(n,r),n.strstart!==0&&(rr(n,t.adler>>>16),rr(n,t.adler&65535)),t.adler=1}if(n.status===ho)if(n.gzhead.extra){for(a=n.pending;n.gzindex<(n.gzhead.extra.length&65535)&&!(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>a&&(t.adler=Ct(t.adler,n.pending_buf,n.pending-a)),Kn(t),a=n.pending,n.pending===n.pending_buf_size));)lt(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>a&&(t.adler=Ct(t.adler,n.pending_buf,n.pending-a)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=nr)}else n.status=nr;if(n.status===nr)if(n.gzhead.name){a=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>a&&(t.adler=Ct(t.adler,n.pending_buf,n.pending-a)),Kn(t),a=n.pending,n.pending===n.pending_buf_size)){i=1;break}n.gzindex<n.gzhead.name.length?i=n.gzhead.name.charCodeAt(n.gzindex++)&255:i=0,lt(n,i)}while(i!==0);n.gzhead.hcrc&&n.pending>a&&(t.adler=Ct(t.adler,n.pending_buf,n.pending-a)),i===0&&(n.gzindex=0,n.status=ar)}else n.status=ar;if(n.status===ar)if(n.gzhead.comment){a=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>a&&(t.adler=Ct(t.adler,n.pending_buf,n.pending-a)),Kn(t),a=n.pending,n.pending===n.pending_buf_size)){i=1;break}n.gzindex<n.gzhead.comment.length?i=n.gzhead.comment.charCodeAt(n.gzindex++)&255:i=0,lt(n,i)}while(i!==0);n.gzhead.hcrc&&n.pending>a&&(t.adler=Ct(t.adler,n.pending_buf,n.pending-a)),i===0&&(n.status=ir)}else n.status=ir;if(n.status===ir&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&Kn(t),n.pending+2<=n.pending_buf_size&&(lt(n,t.adler&255),lt(n,t.adler>>8&255),t.adler=0,n.status=ka)):n.status=ka),n.pending!==0){if(Kn(t),t.avail_out===0)return n.last_flush=-1,Yn}else if(t.avail_in===0&&fo(e)<=fo(s)&&e!==Ra)return Zn(t,sr);if(n.status===ii&&t.avail_in!==0)return Zn(t,sr);if(t.avail_in!==0||n.lookahead!==0||n.status!==ii){var d=n.strategy===ai?S_(n):n.strategy===l_?k_(n,e):Jn[n.level].func(n,e);if((d===Ia||d===Di)&&(n.status=ii),d===Pt||d===Ia)return t.avail_out===0&&(n.last_flush=-1),Yn;if(d===ja&&(yd(n,0,0,!1),Tn(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0),Kn(t),t.avail_out===0))return n.last_flush=-1,Yn}return Yn}class M_{constructor(){this.strm=new ld,this.chunkSize=1024*10*10,this.outputBuffer=new Uint8Array(this.chunkSize),T_(this.strm,kd)}deflate(e){this.strm.input=e,this.strm.avail_in=this.strm.input.length,this.strm.next_in=0,this.strm.output=this.outputBuffer,this.strm.avail_out=this.chunkSize,this.strm.next_out=0;let s=_o(this.strm,uo),n=new Uint8Array(this.strm.output.buffer,0,this.strm.next_out);if(s<0)throw new Error("zlib deflate failed");if(this.strm.avail_in>0){let a=[n],i=n.length;do{if(this.strm.output=new Uint8Array(this.chunkSize),this.strm.next_out=0,this.strm.avail_out=this.chunkSize,s=_o(this.strm,uo),s<0)throw new Error("zlib deflate failed");let d=new Uint8Array(this.strm.output.buffer,0,this.strm.next_out);i+=d.length,a.push(d)}while(this.strm.avail_in>0);let r=new Uint8Array(i),l=0;for(let d=0;d<a.length;d++)r.set(a[d],l),l+=a[d].length;n=r}return this.strm.input=null,this.strm.avail_in=0,this.strm.next_in=0,n}}const m={XK_BackSpace:65288,XK_Tab:65289,XK_Clear:65291,XK_Return:65293,XK_Pause:65299,XK_Scroll_Lock:65300,XK_Escape:65307,XK_Delete:65535,XK_Multi_key:65312,XK_Codeinput:65335,XK_SingleCandidate:65340,XK_MultipleCandidate:65341,XK_PreviousCandidate:65342,XK_Kanji:65313,XK_Muhenkan:65314,XK_Henkan:65315,XK_Romaji:65316,XK_Hiragana:65317,XK_Katakana:65318,XK_Hiragana_Katakana:65319,XK_Zenkaku:65320,XK_Hankaku:65321,XK_Zenkaku_Hankaku:65322,XK_Kana_Shift:65326,XK_Eisu_toggle:65328,XK_Home:65360,XK_Left:65361,XK_Up:65362,XK_Right:65363,XK_Down:65364,XK_Prior:65365,XK_Next:65366,XK_End:65367,XK_Select:65376,XK_Print:65377,XK_Execute:65378,XK_Insert:65379,XK_Undo:65381,XK_Redo:65382,XK_Menu:65383,XK_Find:65384,XK_Cancel:65385,XK_Help:65386,XK_Mode_switch:65406,XK_Num_Lock:65407,XK_KP_Space:65408,XK_KP_Enter:65421,XK_KP_Home:65429,XK_KP_Left:65430,XK_KP_Up:65431,XK_KP_Right:65432,XK_KP_Down:65433,XK_KP_Prior:65434,XK_KP_Next:65435,XK_KP_End:65436,XK_KP_Begin:65437,XK_KP_Insert:65438,XK_KP_Delete:65439,XK_KP_Equal:65469,XK_KP_Multiply:65450,XK_KP_Add:65451,XK_KP_Separator:65452,XK_KP_Subtract:65453,XK_KP_Decimal:65454,XK_KP_Divide:65455,XK_KP_0:65456,XK_KP_1:65457,XK_KP_2:65458,XK_KP_3:65459,XK_KP_4:65460,XK_KP_5:65461,XK_KP_6:65462,XK_KP_7:65463,XK_KP_8:65464,XK_KP_9:65465,XK_F1:65470,XK_F2:65471,XK_F3:65472,XK_F4:65473,XK_F5:65474,XK_F6:65475,XK_F7:65476,XK_F8:65477,XK_F9:65478,XK_F10:65479,XK_F11:65480,XK_F12:65481,XK_F13:65482,XK_F14:65483,XK_F15:65484,XK_F16:65485,XK_F17:65486,XK_F18:65487,XK_F19:65488,XK_F20:65489,XK_F21:65490,XK_F22:65491,XK_F23:65492,XK_F24:65493,XK_F25:65494,XK_F26:65495,XK_F27:65496,XK_F28:65497,XK_F29:65498,XK_F30:65499,XK_F31:65500,XK_F32:65501,XK_F33:65502,XK_F34:65503,XK_F35:65504,XK_Shift_L:65505,XK_Shift_R:65506,XK_Control_L:65507,XK_Control_R:65508,XK_Caps_Lock:65509,XK_Meta_L:65511,XK_Meta_R:65512,XK_Alt_L:65513,XK_Alt_R:65514,XK_Super_L:65515,XK_Super_R:65516,XK_ISO_Level3_Shift:65027,XK_ISO_Next_Group:65032,XK_ISO_Prev_Group:65034,XK_ISO_First_Group:65036,XK_ISO_Last_Group:65038,XK_space:32,XK_asterisk:42,XK_plus:43,XK_comma:44,XK_minus:45,XK_period:46,XK_slash:47,XK_0:48,XK_1:49,XK_2:50,XK_3:51,XK_4:52,XK_5:53,XK_6:54,XK_7:55,XK_8:56,XK_9:57,XK_equal:61,XK_Hangul:65329,XK_Hangul_Hanja:65332,XK_Hangul_Jeonja:65336,XF86XK_MonBrightnessUp:269025026,XF86XK_MonBrightnessDown:269025027,XF86XK_Standby:269025040,XF86XK_AudioLowerVolume:269025041,XF86XK_AudioMute:269025042,XF86XK_AudioRaiseVolume:269025043,XF86XK_AudioPlay:269025044,XF86XK_AudioStop:269025045,XF86XK_AudioPrev:269025046,XF86XK_AudioNext:269025047,XF86XK_HomePage:269025048,XF86XK_Mail:269025049,XF86XK_Search:269025051,XF86XK_AudioRecord:269025052,XF86XK_Calculator:269025053,XF86XK_Calendar:269025056,XF86XK_PowerDown:269025057,XF86XK_Back:269025062,XF86XK_Forward:269025063,XF86XK_Stop:269025064,XF86XK_Refresh:269025065,XF86XK_PowerOff:269025066,XF86XK_WakeUp:269025067,XF86XK_Eject:269025068,XF86XK_ScreenSaver:269025069,XF86XK_WWW:269025070,XF86XK_Favorites:269025072,XF86XK_AudioPause:269025073,XF86XK_AudioMedia:269025074,XF86XK_MyComputer:269025075,XF86XK_BrightnessAdjust:269025083,XF86XK_AudioRewind:269025086,XF86XK_Close:269025110,XF86XK_Copy:269025111,XF86XK_Cut:269025112,XF86XK_Excel:269025116,XF86XK_LogOff:269025121,XF86XK_New:269025128,XF86XK_Open:269025131,XF86XK_Paste:269025133,XF86XK_Phone:269025134,XF86XK_Reply:269025138,XF86XK_Save:269025143,XF86XK_Send:269025147,XF86XK_Spell:269025148,XF86XK_SplitScreen:269025149,XF86XK_Word:269025161,XF86XK_ZoomIn:269025163,XF86XK_ZoomOut:269025164,XF86XK_WebCam:269025167,XF86XK_MailForward:269025168,XF86XK_Music:269025170,XF86XK_AudioForward:269025175,XF86XK_AudioRandomPlay:269025177,XF86XK_Subtitle:269025178,XF86XK_AudioCycleTrack:269025179,XF86XK_Hibernate:269025192,XF86XK_AudioMicMute:269025202,XF86XK_Next_VMode:269024802},X_={256:960,257:992,258:451,259:483,260:417,261:433,262:454,263:486,264:710,265:742,266:709,267:741,268:456,269:488,270:463,271:495,272:464,273:496,274:938,275:954,278:972,279:1004,280:458,281:490,282:460,283:492,284:728,285:760,286:683,287:699,288:725,289:757,290:939,291:955,292:678,293:694,294:673,295:689,296:933,297:949,298:975,299:1007,302:967,303:999,304:681,305:697,308:684,309:700,310:979,311:1011,312:930,313:453,314:485,315:934,316:950,317:421,318:437,321:419,322:435,323:465,324:497,325:977,326:1009,327:466,328:498,330:957,331:959,332:978,333:1010,336:469,337:501,338:5052,339:5053,340:448,341:480,342:931,343:947,344:472,345:504,346:422,347:438,348:734,349:766,350:426,351:442,352:425,353:441,354:478,355:510,356:427,357:443,358:940,359:956,360:989,361:1021,362:990,363:1022,364:733,365:765,366:473,367:505,368:475,369:507,370:985,371:1017,376:5054,377:428,378:444,379:431,380:447,381:430,382:446,402:2294,466:16777681,711:439,728:418,729:511,731:434,733:445,901:1966,902:1953,904:1954,905:1955,906:1956,908:1959,910:1960,911:1963,912:1974,913:1985,914:1986,915:1987,916:1988,917:1989,918:1990,919:1991,920:1992,921:1993,922:1994,923:1995,924:1996,925:1997,926:1998,927:1999,928:2e3,929:2001,931:2002,932:2004,933:2005,934:2006,935:2007,936:2008,937:2009,938:1957,939:1961,940:1969,941:1970,942:1971,943:1972,944:1978,945:2017,946:2018,947:2019,948:2020,949:2021,950:2022,951:2023,952:2024,953:2025,954:2026,955:2027,956:2028,957:2029,958:2030,959:2031,960:2032,961:2033,962:2035,963:2034,964:2036,965:2037,966:2038,967:2039,968:2040,969:2041,970:1973,971:1977,972:1975,973:1976,974:1979,1025:1715,1026:1713,1027:1714,1028:1716,1029:1717,1030:1718,1031:1719,1032:1720,1033:1721,1034:1722,1035:1723,1036:1724,1038:1726,1039:1727,1040:1761,1041:1762,1042:1783,1043:1767,1044:1764,1045:1765,1046:1782,1047:1786,1048:1769,1049:1770,1050:1771,1051:1772,1052:1773,1053:1774,1054:1775,1055:1776,1056:1778,1057:1779,1058:1780,1059:1781,1060:1766,1061:1768,1062:1763,1063:1790,1064:1787,1065:1789,1066:1791,1067:1785,1068:1784,1069:1788,1070:1760,1071:1777,1072:1729,1073:1730,1074:1751,1075:1735,1076:1732,1077:1733,1078:1750,1079:1754,1080:1737,1081:1738,1082:1739,1083:1740,1084:1741,1085:1742,1086:1743,1087:1744,1088:1746,1089:1747,1090:1748,1091:1749,1092:1734,1093:1736,1094:1731,1095:1758,1096:1755,1097:1757,1098:1759,1099:1753,1100:1752,1101:1756,1102:1728,1103:1745,1105:1699,1106:1697,1107:1698,1108:1700,1109:1701,1110:1702,1111:1703,1112:1704,1113:1705,1114:1706,1115:1707,1116:1708,1118:1710,1119:1711,1168:1725,1169:1709,1488:3296,1489:3297,1490:3298,1491:3299,1492:3300,1493:3301,1494:3302,1495:3303,1496:3304,1497:3305,1498:3306,1499:3307,1500:3308,1501:3309,1502:3310,1503:3311,1504:3312,1505:3313,1506:3314,1507:3315,1508:3316,1509:3317,1510:3318,1511:3319,1512:3320,1513:3321,1514:3322,1548:1452,1563:1467,1567:1471,1569:1473,1570:1474,1571:1475,1572:1476,1573:1477,1574:1478,1575:1479,1576:1480,1577:1481,1578:1482,1579:1483,1580:1484,1581:1485,1582:1486,1583:1487,1584:1488,1585:1489,1586:1490,1587:1491,1588:1492,1589:1493,1590:1494,1591:1495,1592:1496,1593:1497,1594:1498,1600:1504,1601:1505,1602:1506,1603:1507,1604:1508,1605:1509,1606:1510,1607:1511,1608:1512,1609:1513,1610:1514,1611:1515,1612:1516,1613:1517,1614:1518,1615:1519,1616:1520,1617:1521,1618:1522,3585:3489,3586:3490,3587:3491,3588:3492,3589:3493,3590:3494,3591:3495,3592:3496,3593:3497,3594:3498,3595:3499,3596:3500,3597:3501,3598:3502,3599:3503,3600:3504,3601:3505,3602:3506,3603:3507,3604:3508,3605:3509,3606:3510,3607:3511,3608:3512,3609:3513,3610:3514,3611:3515,3612:3516,3613:3517,3614:3518,3615:3519,3616:3520,3617:3521,3618:3522,3619:3523,3620:3524,3621:3525,3622:3526,3623:3527,3624:3528,3625:3529,3626:3530,3627:3531,3628:3532,3629:3533,3630:3534,3631:3535,3632:3536,3633:3537,3634:3538,3635:3539,3636:3540,3637:3541,3638:3542,3639:3543,3640:3544,3641:3545,3642:3546,3647:3551,3648:3552,3649:3553,3650:3554,3651:3555,3652:3556,3653:3557,3654:3558,3655:3559,3656:3560,3657:3561,3658:3562,3659:3563,3660:3564,3661:3565,3664:3568,3665:3569,3666:3570,3667:3571,3668:3572,3669:3573,3670:3574,3671:3575,3672:3576,3673:3577,8194:2722,8195:2721,8196:2723,8197:2724,8199:2725,8200:2726,8201:2727,8202:2728,8210:2747,8211:2730,8212:2729,8213:1967,8215:3295,8216:2768,8217:2769,8218:2813,8220:2770,8221:2771,8222:2814,8224:2801,8225:2802,8226:2790,8229:2735,8230:2734,8240:2773,8242:2774,8243:2775,8248:2812,8254:1150,8361:3839,8364:8364,8453:2744,8470:1712,8471:2811,8478:2772,8482:2761,8531:2736,8532:2737,8533:2738,8534:2739,8535:2740,8536:2741,8537:2742,8538:2743,8539:2755,8540:2756,8541:2757,8542:2758,8592:2299,8593:2300,8594:2301,8595:2302,8658:2254,8660:2253,8706:2287,8711:2245,8728:3018,8730:2262,8733:2241,8734:2242,8743:2270,8744:2271,8745:2268,8746:2269,8747:2239,8756:2240,8764:2248,8771:2249,8773:16785992,8800:2237,8801:2255,8804:2236,8805:2238,8834:2266,8835:2267,8866:3068,8867:3036,8868:3010,8869:3022,8968:3027,8970:3012,8981:2810,8992:2212,8993:2213,9109:3020,9115:2219,9117:2220,9118:2221,9120:2222,9121:2215,9123:2216,9124:2217,9126:2218,9128:2223,9132:2224,9143:2209,9146:2543,9147:2544,9148:2546,9149:2547,9225:2530,9226:2533,9227:2537,9228:2531,9229:2532,9251:2732,9252:2536,9472:2211,9474:2214,9484:2210,9488:2539,9492:2541,9496:2538,9500:2548,9508:2549,9516:2551,9524:2550,9532:2542,9618:2529,9642:2791,9643:2785,9644:2779,9645:2786,9646:2783,9647:2767,9650:2792,9651:2787,9654:2781,9655:2765,9660:2793,9661:2788,9664:2780,9665:2764,9670:2528,9675:2766,9679:2782,9702:2784,9734:2789,9742:2809,9747:2762,9756:2794,9758:2795,9792:2808,9794:2807,9827:2796,9829:2798,9830:2797,9837:2806,9839:2805,10003:2803,10007:2804,10013:2777,10016:2800,10216:2748,10217:2750,12289:1188,12290:1185,12300:1186,12301:1187,12443:1246,12444:1247,12449:1191,12450:1201,12451:1192,12452:1202,12453:1193,12454:1203,12455:1194,12456:1204,12457:1195,12458:1205,12459:1206,12461:1207,12463:1208,12465:1209,12467:1210,12469:1211,12471:1212,12473:1213,12475:1214,12477:1215,12479:1216,12481:1217,12483:1199,12484:1218,12486:1219,12488:1220,12490:1221,12491:1222,12492:1223,12493:1224,12494:1225,12495:1226,12498:1227,12501:1228,12504:1229,12507:1230,12510:1231,12511:1232,12512:1233,12513:1234,12514:1235,12515:1196,12516:1236,12517:1197,12518:1237,12519:1198,12520:1238,12521:1239,12522:1240,12523:1241,12524:1242,12525:1243,12527:1244,12530:1190,12531:1245,12539:1189,12540:1200},L_={lookup(t){if(t>=32&&t<=255)return t;const e=X_[t];return e!==void 0?e:16777216|t}},vo={8:"Backspace",9:"Tab",10:"NumpadClear",13:"Enter",16:"ShiftLeft",17:"ControlLeft",18:"AltLeft",19:"Pause",20:"CapsLock",21:"Lang1",25:"Lang2",27:"Escape",28:"Convert",29:"NonConvert",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",41:"Select",44:"PrintScreen",45:"Insert",46:"Delete",47:"Help",48:"Digit0",49:"Digit1",50:"Digit2",51:"Digit3",52:"Digit4",53:"Digit5",54:"Digit6",55:"Digit7",56:"Digit8",57:"Digit9",91:"MetaLeft",92:"MetaRight",93:"ContextMenu",95:"Sleep",96:"Numpad0",97:"Numpad1",98:"Numpad2",99:"Numpad3",100:"Numpad4",101:"Numpad5",102:"Numpad6",103:"Numpad7",104:"Numpad8",105:"Numpad9",106:"NumpadMultiply",107:"NumpadAdd",108:"NumpadDecimal",109:"NumpadSubtract",110:"NumpadDecimal",111:"NumpadDivide",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",124:"F13",125:"F14",126:"F15",127:"F16",128:"F17",129:"F18",130:"F19",131:"F20",132:"F21",133:"F22",134:"F23",135:"F24",144:"NumLock",145:"ScrollLock",166:"BrowserBack",167:"BrowserForward",168:"BrowserRefresh",169:"BrowserStop",170:"BrowserSearch",171:"BrowserFavorites",172:"BrowserHome",173:"AudioVolumeMute",174:"AudioVolumeDown",175:"AudioVolumeUp",176:"MediaTrackNext",177:"MediaTrackPrevious",178:"MediaStop",179:"MediaPlayPause",180:"LaunchMail",181:"MediaSelect",182:"LaunchApp1",183:"LaunchApp2",225:"AltRight"},po={Backspace:"Backspace",AltLeft:"Alt",AltRight:"Alt",CapsLock:"CapsLock",ContextMenu:"ContextMenu",ControlLeft:"Control",ControlRight:"Control",Enter:"Enter",MetaLeft:"Meta",MetaRight:"Meta",ShiftLeft:"Shift",ShiftRight:"Shift",Tab:"Tab",Delete:"Delete",End:"End",Help:"Help",Home:"Home",Insert:"Insert",PageDown:"PageDown",PageUp:"PageUp",ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowRight:"ArrowRight",ArrowUp:"ArrowUp",NumLock:"NumLock",NumpadBackspace:"Backspace",NumpadClear:"Clear",Escape:"Escape",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F30:"F30",F31:"F31",F32:"F32",F33:"F33",F34:"F34",F35:"F35",PrintScreen:"PrintScreen",ScrollLock:"ScrollLock",Pause:"Pause",BrowserBack:"BrowserBack",BrowserFavorites:"BrowserFavorites",BrowserForward:"BrowserForward",BrowserHome:"BrowserHome",BrowserRefresh:"BrowserRefresh",BrowserSearch:"BrowserSearch",BrowserStop:"BrowserStop",Eject:"Eject",LaunchApp1:"LaunchMyComputer",LaunchApp2:"LaunchCalendar",LaunchMail:"LaunchMail",MediaPlayPause:"MediaPlay",MediaStop:"MediaStop",MediaTrackNext:"MediaTrackNext",MediaTrackPrevious:"MediaTrackPrevious",Power:"Power",Sleep:"Sleep",AudioVolumeDown:"AudioVolumeDown",AudioVolumeMute:"AudioVolumeMute",AudioVolumeUp:"AudioVolumeUp",WakeUp:"WakeUp"},Sn={};function I(t,e){if(e===void 0)throw new Error('Undefined keysym for key "'+t+'"');if(t in Sn)throw new Error('Duplicate entry for key "'+t+'"');Sn[t]=[e,e,e,e]}function Ri(t,e,s){if(e===void 0)throw new Error('Undefined keysym for key "'+t+'"');if(s===void 0)throw new Error('Undefined keysym for key "'+t+'"');if(t in Sn)throw new Error('Duplicate entry for key "'+t+'"');Sn[t]=[e,e,s,e]}function Ge(t,e,s){if(e===void 0)throw new Error('Undefined keysym for key "'+t+'"');if(s===void 0)throw new Error('Undefined keysym for key "'+t+'"');if(t in Sn)throw new Error('Duplicate entry for key "'+t+'"');Sn[t]=[e,e,e,s]}Ri("Alt",m.XK_Alt_L,m.XK_Alt_R);I("AltGraph",m.XK_ISO_Level3_Shift);I("CapsLock",m.XK_Caps_Lock);Ri("Control",m.XK_Control_L,m.XK_Control_R);Ri("Meta",m.XK_Super_L,m.XK_Super_R);I("NumLock",m.XK_Num_Lock);I("ScrollLock",m.XK_Scroll_Lock);Ri("Shift",m.XK_Shift_L,m.XK_Shift_R);Ge("Enter",m.XK_Return,m.XK_KP_Enter);I("Tab",m.XK_Tab);Ge(" ",m.XK_space,m.XK_KP_Space);Ge("ArrowDown",m.XK_Down,m.XK_KP_Down);Ge("ArrowLeft",m.XK_Left,m.XK_KP_Left);Ge("ArrowRight",m.XK_Right,m.XK_KP_Right);Ge("ArrowUp",m.XK_Up,m.XK_KP_Up);Ge("End",m.XK_End,m.XK_KP_End);Ge("Home",m.XK_Home,m.XK_KP_Home);Ge("PageDown",m.XK_Next,m.XK_KP_Next);Ge("PageUp",m.XK_Prior,m.XK_KP_Prior);I("Backspace",m.XK_BackSpace);Ge("Clear",m.XK_Clear,m.XK_KP_Begin);I("Copy",m.XF86XK_Copy);I("Cut",m.XF86XK_Cut);Ge("Delete",m.XK_Delete,m.XK_KP_Delete);Ge("Insert",m.XK_Insert,m.XK_KP_Insert);I("Paste",m.XF86XK_Paste);I("Redo",m.XK_Redo);I("Undo",m.XK_Undo);I("Cancel",m.XK_Cancel);I("ContextMenu",m.XK_Menu);I("Escape",m.XK_Escape);I("Execute",m.XK_Execute);I("Find",m.XK_Find);I("Help",m.XK_Help);I("Pause",m.XK_Pause);I("Select",m.XK_Select);I("ZoomIn",m.XF86XK_ZoomIn);I("ZoomOut",m.XF86XK_ZoomOut);I("BrightnessDown",m.XF86XK_MonBrightnessDown);I("BrightnessUp",m.XF86XK_MonBrightnessUp);I("Eject",m.XF86XK_Eject);I("LogOff",m.XF86XK_LogOff);I("Power",m.XF86XK_PowerOff);I("PowerOff",m.XF86XK_PowerDown);I("PrintScreen",m.XK_Print);I("Hibernate",m.XF86XK_Hibernate);I("Standby",m.XF86XK_Standby);I("WakeUp",m.XF86XK_WakeUp);I("AllCandidates",m.XK_MultipleCandidate);I("Alphanumeric",m.XK_Eisu_toggle);I("CodeInput",m.XK_Codeinput);I("Compose",m.XK_Multi_key);I("Convert",m.XK_Henkan);I("GroupFirst",m.XK_ISO_First_Group);I("GroupLast",m.XK_ISO_Last_Group);I("GroupNext",m.XK_ISO_Next_Group);I("GroupPrevious",m.XK_ISO_Prev_Group);I("NonConvert",m.XK_Muhenkan);I("PreviousCandidate",m.XK_PreviousCandidate);I("SingleCandidate",m.XK_SingleCandidate);I("HangulMode",m.XK_Hangul);I("HanjaMode",m.XK_Hangul_Hanja);I("JunjaMode",m.XK_Hangul_Jeonja);I("Eisu",m.XK_Eisu_toggle);I("Hankaku",m.XK_Hankaku);I("Hiragana",m.XK_Hiragana);I("HiraganaKatakana",m.XK_Hiragana_Katakana);I("KanaMode",m.XK_Kana_Shift);I("KanjiMode",m.XK_Kanji);I("Katakana",m.XK_Katakana);I("Romaji",m.XK_Romaji);I("Zenkaku",m.XK_Zenkaku);I("ZenkakuHankaku",m.XK_Zenkaku_Hankaku);I("F1",m.XK_F1);I("F2",m.XK_F2);I("F3",m.XK_F3);I("F4",m.XK_F4);I("F5",m.XK_F5);I("F6",m.XK_F6);I("F7",m.XK_F7);I("F8",m.XK_F8);I("F9",m.XK_F9);I("F10",m.XK_F10);I("F11",m.XK_F11);I("F12",m.XK_F12);I("F13",m.XK_F13);I("F14",m.XK_F14);I("F15",m.XK_F15);I("F16",m.XK_F16);I("F17",m.XK_F17);I("F18",m.XK_F18);I("F19",m.XK_F19);I("F20",m.XK_F20);I("F21",m.XK_F21);I("F22",m.XK_F22);I("F23",m.XK_F23);I("F24",m.XK_F24);I("F25",m.XK_F25);I("F26",m.XK_F26);I("F27",m.XK_F27);I("F28",m.XK_F28);I("F29",m.XK_F29);I("F30",m.XK_F30);I("F31",m.XK_F31);I("F32",m.XK_F32);I("F33",m.XK_F33);I("F34",m.XK_F34);I("F35",m.XK_F35);I("Close",m.XF86XK_Close);I("MailForward",m.XF86XK_MailForward);I("MailReply",m.XF86XK_Reply);I("MailSend",m.XF86XK_Send);I("MediaFastForward",m.XF86XK_AudioForward);I("MediaPause",m.XF86XK_AudioPause);I("MediaPlay",m.XF86XK_AudioPlay);I("MediaRecord",m.XF86XK_AudioRecord);I("MediaRewind",m.XF86XK_AudioRewind);I("MediaStop",m.XF86XK_AudioStop);I("MediaTrackNext",m.XF86XK_AudioNext);I("MediaTrackPrevious",m.XF86XK_AudioPrev);I("New",m.XF86XK_New);I("Open",m.XF86XK_Open);I("Print",m.XK_Print);I("Save",m.XF86XK_Save);I("SpellCheck",m.XF86XK_Spell);I("AudioVolumeDown",m.XF86XK_AudioLowerVolume);I("AudioVolumeUp",m.XF86XK_AudioRaiseVolume);I("AudioVolumeMute",m.XF86XK_AudioMute);I("MicrophoneVolumeMute",m.XF86XK_AudioMicMute);I("LaunchApplication1",m.XF86XK_MyComputer);I("LaunchApplication2",m.XF86XK_Calculator);I("LaunchCalendar",m.XF86XK_Calendar);I("LaunchMail",m.XF86XK_Mail);I("LaunchMediaPlayer",m.XF86XK_AudioMedia);I("LaunchMusicPlayer",m.XF86XK_Music);I("LaunchPhone",m.XF86XK_Phone);I("LaunchScreenSaver",m.XF86XK_ScreenSaver);I("LaunchSpreadsheet",m.XF86XK_Excel);I("LaunchWebBrowser",m.XF86XK_WWW);I("LaunchWebCam",m.XF86XK_WebCam);I("LaunchWordProcessor",m.XF86XK_Word);I("BrowserBack",m.XF86XK_Back);I("BrowserFavorites",m.XF86XK_Favorites);I("BrowserForward",m.XF86XK_Forward);I("BrowserHome",m.XF86XK_HomePage);I("BrowserRefresh",m.XF86XK_Refresh);I("BrowserSearch",m.XF86XK_Search);I("BrowserStop",m.XF86XK_Stop);I("Dimmer",m.XF86XK_BrightnessAdjust);I("MediaAudioTrack",m.XF86XK_AudioCycleTrack);I("RandomToggle",m.XF86XK_AudioRandomPlay);I("SplitScreenToggle",m.XF86XK_SplitScreen);I("Subtitle",m.XF86XK_Subtitle);I("VideoModeNext",m.XF86XK_Next_VMode);Ge("=",m.XK_equal,m.XK_KP_Equal);Ge("+",m.XK_plus,m.XK_KP_Add);Ge("-",m.XK_minus,m.XK_KP_Subtract);Ge("*",m.XK_asterisk,m.XK_KP_Multiply);Ge("/",m.XK_slash,m.XK_KP_Divide);Ge(".",m.XK_period,m.XK_KP_Decimal);Ge(",",m.XK_comma,m.XK_KP_Separator);Ge("0",m.XK_0,m.XK_KP_0);Ge("1",m.XK_1,m.XK_KP_1);Ge("2",m.XK_2,m.XK_KP_2);Ge("3",m.XK_3,m.XK_KP_3);Ge("4",m.XK_4,m.XK_KP_4);Ge("5",m.XK_5,m.XK_KP_5);Ge("6",m.XK_6,m.XK_KP_6);Ge("7",m.XK_7,m.XK_KP_7);Ge("8",m.XK_8,m.XK_KP_8);Ge("9",m.XK_9,m.XK_KP_9);function Xa(t){if(t.code){switch(t.code){case"OSLeft":return"MetaLeft";case"OSRight":return"MetaRight"}return t.code}if(t.keyCode in vo){let e=vo[t.keyCode];if(Wn()&&e==="ContextMenu"&&(e="MetaRight"),t.location===2)switch(e){case"ShiftLeft":return"ShiftRight";case"ControlLeft":return"ControlRight";case"AltLeft":return"AltRight"}if(t.location===3)switch(e){case"Delete":return"NumpadDecimal";case"Insert":return"Numpad0";case"End":return"Numpad1";case"ArrowDown":return"Numpad2";case"PageDown":return"Numpad3";case"ArrowLeft":return"Numpad4";case"ArrowRight":return"Numpad6";case"Home":return"Numpad7";case"ArrowUp":return"Numpad8";case"PageUp":return"Numpad9";case"Enter":return"NumpadEnter"}return e}return"Unidentified"}function P_(t){if(t.key!==void 0&&t.key!=="Unidentified"){switch(t.key){case"OS":return"Meta";case"LaunchMyComputer":return"LaunchApplication1";case"LaunchCalculator":return"LaunchApplication2"}switch(t.key){case"UIKeyInputUpArrow":return"ArrowUp";case"UIKeyInputDownArrow":return"ArrowDown";case"UIKeyInputLeftArrow":return"ArrowLeft";case"UIKeyInputRightArrow":return"ArrowRight";case"UIKeyInputEscape":return"Escape"}return t.key==="\0"&&t.code==="NumpadDecimal"?"Delete":t.key}const e=Xa(t);return e in po?po[e]:t.charCode?String.fromCharCode(t.charCode):"Unidentified"}function B_(t){const e=P_(t);if(e==="Unidentified")return null;if(e in Sn){let n=t.location;if(e==="Meta"&&n===0&&(n=2),e==="Clear"&&n===3&&Xa(t)==="NumLock"&&(n=0),(n===void 0||n>3)&&(n=0),e==="Meta"){let a=Xa(t);if(a==="AltLeft")return m.XK_Meta_L;if(a==="AltRight")return m.XK_Meta_R}if(e==="Clear"&&Xa(t)==="NumLock")return m.XK_Num_Lock;if(hi())switch(e){case"Zenkaku":case"Hankaku":return m.XK_Zenkaku_Hankaku;case"Romaji":case"KanaMode":return m.XK_Romaji}return Sn[e][n]}if(e.length!==1)return null;const s=e.charCodeAt();return s?L_.lookup(s):null}class D_{constructor(e){this._target=e||null,this._keyDownList={},this._altGrArmed=!1,this._eventHandlers={keyup:this._handleKeyUp.bind(this),keydown:this._handleKeyDown.bind(this),blur:this._allKeysUp.bind(this)},this.onkeyevent=()=>{}}_sendKeyEvent(e,s,n,a=null,i=null){if(n)this._keyDownList[s]=e;else{if(!(s in this._keyDownList))return;delete this._keyDownList[s]}Ke("onkeyevent "+(n?"down":"up")+", keysym: "+e,", code: "+s+", numlock: "+a+", capslock: "+i),this.onkeyevent(e,s,n,a,i)}_getKeyCode(e){const s=Xa(e);if(s!=="Unidentified")return s;if(e.keyCode&&e.keyCode!==229)return"Platform"+e.keyCode;if(e.keyIdentifier){if(e.keyIdentifier.substr(0,2)!=="U+")return e.keyIdentifier;const n=parseInt(e.keyIdentifier.substr(2),16);return"Platform"+String.fromCharCode(n).toUpperCase().charCodeAt()}return"Unidentified"}_handleKeyDown(e){const s=this._getKeyCode(e);let n=B_(e),a=e.getModifierState("NumLock"),i=e.getModifierState("CapsLock");if((Wn()||fa())&&(a=null),this._altGrArmed&&(this._altGrArmed=!1,clearTimeout(this._altGrTimeout),s==="AltRight"&&e.timeStamp-this._altGrCtrlTime<50?n=m.XK_ISO_Level3_Shift:this._sendKeyEvent(m.XK_Control_L,"ControlLeft",!0,a,i)),s==="Unidentified"){n&&(this._sendKeyEvent(n,s,!0,a,i),this._sendKeyEvent(n,s,!1,a,i)),Vn(e);return}if(Wn()||fa())switch(n){case m.XK_Super_L:n=m.XK_Alt_L;break;case m.XK_Super_R:n=m.XK_Super_L;break;case m.XK_Alt_L:n=m.XK_Mode_switch;break;case m.XK_Alt_R:n=m.XK_ISO_Level3_Shift;break}if(s in this._keyDownList&&(n=this._keyDownList[s]),(Wn()||fa())&&e.metaKey&&s!=="MetaLeft"&&s!=="MetaRight"){this._sendKeyEvent(n,s,!0,a,i),this._sendKeyEvent(n,s,!1,a,i),Vn(e);return}if((Wn()||fa())&&s==="CapsLock"){this._sendKeyEvent(m.XK_Caps_Lock,"CapsLock",!0,a,i),this._sendKeyEvent(m.XK_Caps_Lock,"CapsLock",!1,a,i),Vn(e);return}const r=[m.XK_Zenkaku_Hankaku,m.XK_Eisu_toggle,m.XK_Katakana,m.XK_Hiragana,m.XK_Romaji];if(hi()&&r.includes(n)){this._sendKeyEvent(n,s,!0,a,i),this._sendKeyEvent(n,s,!1,a,i),Vn(e);return}if(Vn(e),s==="ControlLeft"&&hi()&&!("ControlLeft"in this._keyDownList)){this._altGrArmed=!0,this._altGrTimeout=setTimeout(this._interruptAltGrSequence.bind(this),100),this._altGrCtrlTime=e.timeStamp;return}this._sendKeyEvent(n,s,!0,a,i)}_handleKeyUp(e){Vn(e);const s=this._getKeyCode(e);if(this._interruptAltGrSequence(),(Wn()||fa())&&s==="CapsLock"){this._sendKeyEvent(m.XK_Caps_Lock,"CapsLock",!0),this._sendKeyEvent(m.XK_Caps_Lock,"CapsLock",!1);return}this._sendKeyEvent(this._keyDownList[s],s,!1),hi()&&(s==="ShiftLeft"||s==="ShiftRight")&&("ShiftRight"in this._keyDownList&&this._sendKeyEvent(this._keyDownList.ShiftRight,"ShiftRight",!1),"ShiftLeft"in this._keyDownList&&this._sendKeyEvent(this._keyDownList.ShiftLeft,"ShiftLeft",!1))}_interruptAltGrSequence(){this._altGrArmed&&(this._altGrArmed=!1,clearTimeout(this._altGrTimeout),this._sendKeyEvent(m.XK_Control_L,"ControlLeft",!0))}_allKeysUp(){Ke(">> Keyboard.allKeysUp"),this._interruptAltGrSequence();for(let e in this._keyDownList)this._sendKeyEvent(this._keyDownList[e],e,!1);Ke("<< Keyboard.allKeysUp")}grab(){this._target.addEventListener("keydown",this._eventHandlers.keydown),this._target.addEventListener("keyup",this._eventHandlers.keyup),window.addEventListener("blur",this._eventHandlers.blur)}ungrab(){this._target.removeEventListener("keydown",this._eventHandlers.keydown),this._target.removeEventListener("keyup",this._eventHandlers.keyup),window.removeEventListener("blur",this._eventHandlers.blur),this._allKeysUp()}}const Ds=0,go=1,xo=2,bo=4,mo=8,or=16,va=32,pa=64,cr=127,wo=50,R_=90,yo=250,I_=1e3,Q_=1e3,z_=50;class N_{constructor(){this._target=null,this._state=cr,this._tracked=[],this._ignored=[],this._waitingRelease=!1,this._releaseStart=0,this._longpressTimeoutId=null,this._twoTouchTimeoutId=null,this._boundEventHandler=this._eventHandler.bind(this)}attach(e){this.detach(),this._target=e,this._target.addEventListener("touchstart",this._boundEventHandler),this._target.addEventListener("touchmove",this._boundEventHandler),this._target.addEventListener("touchend",this._boundEventHandler),this._target.addEventListener("touchcancel",this._boundEventHandler)}detach(){this._target&&(this._stopLongpressTimeout(),this._stopTwoTouchTimeout(),this._target.removeEventListener("touchstart",this._boundEventHandler),this._target.removeEventListener("touchmove",this._boundEventHandler),this._target.removeEventListener("touchend",this._boundEventHandler),this._target.removeEventListener("touchcancel",this._boundEventHandler),this._target=null)}_eventHandler(e){let s;switch(e.stopPropagation(),e.preventDefault(),e.type){case"touchstart":s=this._touchStart;break;case"touchmove":s=this._touchMove;break;case"touchend":case"touchcancel":s=this._touchEnd;break}for(let n=0;n<e.changedTouches.length;n++){let a=e.changedTouches[n];s.call(this,a.identifier,a.clientX,a.clientY)}}_touchStart(e,s,n){if(this._hasDetectedGesture()||this._state===Ds){this._ignored.push(e);return}if(this._tracked.length>0&&Date.now()-this._tracked[0].started>yo){this._state=Ds,this._ignored.push(e);return}if(this._waitingRelease){this._state=Ds,this._ignored.push(e);return}switch(this._tracked.push({id:e,started:Date.now(),active:!0,firstX:s,firstY:n,lastX:s,lastY:n,angle:0}),this._tracked.length){case 1:this._startLongpressTimeout();break;case 2:this._state&=-26,this._stopLongpressTimeout();break;case 3:this._state&=-99;break;default:this._state=Ds}}_touchMove(e,s,n){let a=this._tracked.find(l=>l.id===e);if(a===void 0)return;a.lastX=s,a.lastY=n;let i=s-a.firstX,r=n-a.firstY;if((a.firstX!==a.lastX||a.firstY!==a.lastY)&&(a.angle=Math.atan2(r,i)*180/Math.PI),!this._hasDetectedGesture()){if(Math.hypot(i,r)<wo)return;if(this._state&=-24,this._stopLongpressTimeout(),this._tracked.length!==1&&(this._state&=~mo),this._tracked.length!==2&&(this._state&=-97),this._tracked.length===2){let l=this._tracked.find(o=>o.id!==e);if(Math.hypot(l.firstX-l.lastX,l.firstY-l.lastY)>wo){let o=Math.abs(a.angle-l.angle);o=Math.abs((o+180)%360-180),o>R_?this._state&=~va:this._state&=~pa,this._isTwoTouchTimeoutRunning()&&this._stopTwoTouchTimeout()}else this._isTwoTouchTimeoutRunning()||this._startTwoTouchTimeout()}if(!this._hasDetectedGesture())return;this._pushEvent("gesturestart")}this._pushEvent("gesturemove")}_touchEnd(e,s,n){if(this._ignored.indexOf(e)!==-1){this._ignored.splice(this._ignored.indexOf(e),1),this._ignored.length===0&&this._tracked.length===0&&(this._state=cr,this._waitingRelease=!1);return}if(!this._hasDetectedGesture()&&this._isTwoTouchTimeoutRunning()&&(this._stopTwoTouchTimeout(),this._state=Ds),!this._hasDetectedGesture()&&(this._state&=-105,this._state&=~or,this._stopLongpressTimeout(),!this._waitingRelease))switch(this._releaseStart=Date.now(),this._waitingRelease=!0,this._tracked.length){case 1:this._state&=-7;break;case 2:this._state&=-6;break}if(this._waitingRelease){Date.now()-this._releaseStart>yo&&(this._state=Ds),this._tracked.some(i=>Date.now()-i.started>I_)&&(this._state=Ds);let a=this._tracked.find(i=>i.id===e);if(a.active=!1,this._hasDetectedGesture())this._pushEvent("gesturestart");else if(this._state!==Ds)return}this._hasDetectedGesture()&&this._pushEvent("gestureend");for(let a=0;a<this._tracked.length;a++)this._tracked[a].active&&this._ignored.push(this._tracked[a].id);this._tracked=[],this._state=Ds,this._ignored.indexOf(e)!==-1&&this._ignored.splice(this._ignored.indexOf(e),1),this._ignored.length===0&&(this._state=cr,this._waitingRelease=!1)}_hasDetectedGesture(){return!(this._state===Ds||this._state&this._state-1||this._state&(go|xo|bo)&&this._tracked.some(e=>e.active))}_startLongpressTimeout(){this._stopLongpressTimeout(),this._longpressTimeoutId=setTimeout(()=>this._longpressTimeout(),Q_)}_stopLongpressTimeout(){clearTimeout(this._longpressTimeoutId),this._longpressTimeoutId=null}_longpressTimeout(){if(this._hasDetectedGesture())throw new Error("A longpress gesture failed, conflict with a different gesture");this._state=or,this._pushEvent("gesturestart")}_startTwoTouchTimeout(){this._stopTwoTouchTimeout(),this._twoTouchTimeoutId=setTimeout(()=>this._twoTouchTimeout(),z_)}_stopTwoTouchTimeout(){clearTimeout(this._twoTouchTimeoutId),this._twoTouchTimeoutId=null}_isTwoTouchTimeoutRunning(){return this._twoTouchTimeoutId!==null}_twoTouchTimeout(){if(this._tracked.length===0)throw new Error("A pinch or two drag gesture failed, no tracked touches");let e=this._getAverageMovement(),s=Math.abs(e.x),n=Math.abs(e.y),a=this._getAverageDistance(),i=Math.abs(Math.hypot(a.first.x,a.first.y)-Math.hypot(a.last.x,a.last.y));n<i&&s<i?this._state=pa:this._state=va,this._pushEvent("gesturestart"),this._pushEvent("gesturemove")}_pushEvent(e){let s={type:this._stateToGesture(this._state)},n=this._getPosition(),a=n.last;switch(e==="gesturestart"&&(a=n.first),this._state){case va:case pa:a=n.first;break}if(s.clientX=a.x,s.clientY=a.y,this._state===pa){let r=this._getAverageDistance();e==="gesturestart"?(s.magnitudeX=r.first.x,s.magnitudeY=r.first.y):(s.magnitudeX=r.last.x,s.magnitudeY=r.last.y)}else if(this._state===va)if(e==="gesturestart")s.magnitudeX=0,s.magnitudeY=0;else{let r=this._getAverageMovement();s.magnitudeX=r.x,s.magnitudeY=r.y}let i=new CustomEvent(e,{detail:s});this._target.dispatchEvent(i)}_stateToGesture(e){switch(e){case go:return"onetap";case xo:return"twotap";case bo:return"threetap";case mo:return"drag";case or:return"longpress";case va:return"twodrag";case pa:return"pinch"}throw new Error("Unknown gesture state: "+e)}_getPosition(){if(this._tracked.length===0)throw new Error("Failed to get gesture position, no tracked touches");let e=this._tracked.length,s=0,n=0,a=0,i=0;for(let r=0;r<this._tracked.length;r++)s+=this._tracked[r].firstX,n+=this._tracked[r].firstY,a+=this._tracked[r].lastX,i+=this._tracked[r].lastY;return{first:{x:s/e,y:n/e},last:{x:a/e,y:i/e}}}_getAverageMovement(){if(this._tracked.length===0)throw new Error("Failed to get gesture movement, no tracked touches");let e,s;e=s=0;let n=this._tracked.length;for(let a=0;a<this._tracked.length;a++)e+=this._tracked[a].lastX-this._tracked[a].firstX,s+=this._tracked[a].lastY-this._tracked[a].firstY;return{x:e/n,y:s/n}}_getAverageDistance(){if(this._tracked.length===0)throw new Error("Failed to get gesture distance, no tracked touches");let e=this._tracked[0],s=this._tracked[this._tracked.length-1],n=Math.abs(s.firstX-e.firstX),a=Math.abs(s.firstY-e.firstY),i=Math.abs(s.lastX-e.lastX),r=Math.abs(s.lastY-e.lastY);return{first:{x:n,y:a},last:{x:i,y:r}}}}const ga=!cf||jc;class U_{constructor(){this._target=null,this._canvas=document.createElement("canvas"),ga&&(this._canvas.style.position="fixed",this._canvas.style.zIndex="65535",this._canvas.style.pointerEvents="none",this._canvas.style.userSelect="none",this._canvas.style.WebkitUserSelect="none",this._canvas.style.visibility="hidden"),this._position={x:0,y:0},this._hotSpot={x:0,y:0},this._eventHandlers={mouseover:this._handleMouseOver.bind(this),mouseleave:this._handleMouseLeave.bind(this),mousemove:this._handleMouseMove.bind(this),mouseup:this._handleMouseUp.bind(this)}}attach(e){if(this._target&&this.detach(),this._target=e,ga){document.body.appendChild(this._canvas);const s={capture:!0,passive:!0};this._target.addEventListener("mouseover",this._eventHandlers.mouseover,s),this._target.addEventListener("mouseleave",this._eventHandlers.mouseleave,s),this._target.addEventListener("mousemove",this._eventHandlers.mousemove,s),this._target.addEventListener("mouseup",this._eventHandlers.mouseup,s)}this.clear()}detach(){if(this._target){if(ga){const e={capture:!0,passive:!0};this._target.removeEventListener("mouseover",this._eventHandlers.mouseover,e),this._target.removeEventListener("mouseleave",this._eventHandlers.mouseleave,e),this._target.removeEventListener("mousemove",this._eventHandlers.mousemove,e),this._target.removeEventListener("mouseup",this._eventHandlers.mouseup,e),document.contains(this._canvas)&&document.body.removeChild(this._canvas)}this._target=null}}change(e,s,n,a,i){if(a===0||i===0){this.clear();return}this._position.x=this._position.x+this._hotSpot.x-s,this._position.y=this._position.y+this._hotSpot.y-n,this._hotSpot.x=s,this._hotSpot.y=n;let r=this._canvas.getContext("2d");this._canvas.width=a,this._canvas.height=i;let l=new ImageData(new Uint8ClampedArray(e),a,i);if(r.clearRect(0,0,a,i),r.putImageData(l,0,0),ga)this._updatePosition();else{let d=this._canvas.toDataURL();this._target.style.cursor="url("+d+")"+s+" "+n+", default"}}clear(){this._target.style.cursor="none",this._canvas.width=0,this._canvas.height=0,this._position.x=this._position.x+this._hotSpot.x,this._position.y=this._position.y+this._hotSpot.y,this._hotSpot.x=0,this._hotSpot.y=0}move(e,s){if(!ga)return;window.visualViewport?(this._position.x=e+window.visualViewport.offsetLeft,this._position.y=s+window.visualViewport.offsetTop):(this._position.x=e,this._position.y=s),this._updatePosition();let n=document.elementFromPoint(e,s);this._updateVisibility(n)}_handleMouseOver(e){this._handleMouseMove(e)}_handleMouseLeave(e){this._updateVisibility(e.relatedTarget)}_handleMouseMove(e){this._updateVisibility(e.target),this._position.x=e.clientX-this._hotSpot.x,this._position.y=e.clientY-this._hotSpot.y,this._updatePosition()}_handleMouseUp(e){let s=document.elementFromPoint(e.clientX,e.clientY);this._updateVisibility(s),this._captureIsActive()&&window.setTimeout(()=>{this._target&&(s=document.elementFromPoint(e.clientX,e.clientY),this._updateVisibility(s))},0)}_showCursor(){this._canvas.style.visibility==="hidden"&&(this._canvas.style.visibility="")}_hideCursor(){this._canvas.style.visibility!=="hidden"&&(this._canvas.style.visibility="hidden")}_shouldShowCursor(e){return e?e===this._target?!0:!(!this._target.contains(e)||window.getComputedStyle(e).cursor!=="none"):!1}_updateVisibility(e){this._captureIsActive()&&(e=document.captureElement),this._shouldShowCursor(e)?this._showCursor():this._hideCursor()}_updatePosition(){this._canvas.style.left=this._position.x+"px",this._canvas.style.top=this._position.y+"px"}_captureIsActive(){return document.captureElement&&document.documentElement.contains(document.captureElement)}}const dr=40*1024*1024,ri={CONNECTING:"connecting",OPEN:"open",CLOSING:"closing",CLOSED:"closed"},li={CONNECTING:[WebSocket.CONNECTING,ri.CONNECTING],OPEN:[WebSocket.OPEN,ri.OPEN],CLOSING:[WebSocket.CLOSING,ri.CLOSING],CLOSED:[WebSocket.CLOSED,ri.CLOSED]},ko=["send","close","binaryType","onerror","onmessage","onopen","protocol","readyState"];class H_{constructor(){this._websocket=null,this._rQi=0,this._rQlen=0,this._rQbufferSize=1024*1024*4,this._rQ=null,this._sQbufferSize=1024*10,this._sQlen=0,this._sQ=null,this._eventHandlers={message:()=>{},open:()=>{},close:()=>{},error:()=>{}}}get readyState(){let e;return this._websocket===null?"unused":(e=this._websocket.readyState,li.CONNECTING.includes(e)?"connecting":li.OPEN.includes(e)?"open":li.CLOSING.includes(e)?"closing":li.CLOSED.includes(e)?"closed":"unknown")}rQpeek8(){return this._rQ[this._rQi]}rQskipBytes(e){this._rQi+=e}rQshift8(){return this._rQshift(1)}rQshift16(){return this._rQshift(2)}rQshift32(){return this._rQshift(4)}_rQshift(e){let s=0;for(let n=e-1;n>=0;n--)s+=this._rQ[this._rQi++]<<n*8;return s>>>0}rQlen(){return this._rQlen-this._rQi}rQshiftStr(e){let s="";for(let n=0;n<e;n+=4096){let a=this.rQshiftBytes(Math.min(4096,e-n),!1);s+=String.fromCharCode.apply(null,a)}return s}rQshiftBytes(e,s=!0){return this._rQi+=e,s?this._rQ.slice(this._rQi-e,this._rQi):this._rQ.subarray(this._rQi-e,this._rQi)}rQshiftTo(e,s){e.set(new Uint8Array(this._rQ.buffer,this._rQi,s)),this._rQi+=s}rQpeekBytes(e,s=!0){return s?this._rQ.slice(this._rQi,this._rQi+e):this._rQ.subarray(this._rQi,this._rQi+e)}rQwait(e,s,n){if(this._rQlen-this._rQi<s){if(n){if(this._rQi<n)throw new Error("rQwait cannot backup "+n+" bytes");this._rQi-=n}return!0}return!1}sQpush8(e){this._sQensureSpace(1),this._sQ[this._sQlen++]=e}sQpush16(e){this._sQensureSpace(2),this._sQ[this._sQlen++]=e>>8&255,this._sQ[this._sQlen++]=e>>0&255}sQpush32(e){this._sQensureSpace(4),this._sQ[this._sQlen++]=e>>24&255,this._sQ[this._sQlen++]=e>>16&255,this._sQ[this._sQlen++]=e>>8&255,this._sQ[this._sQlen++]=e>>0&255}sQpushString(e){let s=e.split("").map(n=>n.charCodeAt(0));this.sQpushBytes(new Uint8Array(s))}sQpushBytes(e){for(let s=0;s<e.length;){this._sQensureSpace(1);let n=this._sQbufferSize-this._sQlen;n>e.length-s&&(n=e.length-s),this._sQ.set(e.subarray(s,s+n),this._sQlen),this._sQlen+=n,s+=n}}flush(){this._sQlen>0&&this.readyState==="open"&&(this._websocket.send(new Uint8Array(this._sQ.buffer,0,this._sQlen)),this._sQlen=0)}_sQensureSpace(e){this._sQbufferSize-this._sQlen<e&&this.flush()}off(e){this._eventHandlers[e]=()=>{}}on(e,s){this._eventHandlers[e]=s}_allocateBuffers(){this._rQ=new Uint8Array(this._rQbufferSize),this._sQ=new Uint8Array(this._sQbufferSize)}init(){this._allocateBuffers(),this._rQi=0,this._websocket=null}open(e,s){this.attach(new WebSocket(e,s))}attach(e){this.init();const s=[...Object.keys(e),...Object.getOwnPropertyNames(Object.getPrototypeOf(e))];for(let n=0;n<ko.length;n++){const a=ko[n];if(s.indexOf(a)<0)throw new Error("Raw channel missing property: "+a)}this._websocket=e,this._websocket.binaryType="arraybuffer",this._websocket.onmessage=this._recvMessage.bind(this),this._websocket.onopen=()=>{Ke(">> WebSock.onopen"),this._websocket.protocol&&Vt("Server choose sub-protocol: "+this._websocket.protocol),this._eventHandlers.open(),Ke("<< WebSock.onopen")},this._websocket.onclose=n=>{Ke(">> WebSock.onclose"),this._eventHandlers.close(n),Ke("<< WebSock.onclose")},this._websocket.onerror=n=>{Ke(">> WebSock.onerror: "+n),this._eventHandlers.error(n),Ke("<< WebSock.onerror: "+n)}}close(){this._websocket&&((this.readyState==="connecting"||this.readyState==="open")&&(Vt("Closing WebSocket connection"),this._websocket.close()),this._websocket.onmessage=()=>{})}_expandCompactRQ(e){const s=(this._rQlen-this._rQi+e)*8,n=this._rQbufferSize<s;if(n&&(this._rQbufferSize=Math.max(this._rQbufferSize*2,s)),this._rQbufferSize>dr&&(this._rQbufferSize=dr,this._rQbufferSize-(this._rQlen-this._rQi)<e))throw new Error("Receive queue buffer exceeded "+dr+" bytes, and the new message could not fit");if(n){const a=this._rQ.buffer;this._rQ=new Uint8Array(this._rQbufferSize),this._rQ.set(new Uint8Array(a,this._rQi,this._rQlen-this._rQi))}else this._rQ.copyWithin(0,this._rQi,this._rQlen);this._rQlen=this._rQlen-this._rQi,this._rQi=0}_recvMessage(e){this._rQlen==this._rQi&&(this._rQlen=0,this._rQi=0);const s=new Uint8Array(e.data);s.length>this._rQbufferSize-this._rQlen&&this._expandCompactRQ(s.length),this._rQ.set(s,this._rQlen),this._rQlen+=s.length,this._rQlen-this._rQi>0?this._eventHandlers.message():Ke("Ignoring empty message")}}const O_={Again:57349,AltLeft:56,AltRight:57400,ArrowDown:57424,ArrowLeft:57419,ArrowRight:57421,ArrowUp:57416,AudioVolumeDown:57390,AudioVolumeMute:57376,AudioVolumeUp:57392,Backquote:41,Backslash:43,Backspace:14,BracketLeft:26,BracketRight:27,BrowserBack:57450,BrowserFavorites:57446,BrowserForward:57449,BrowserHome:57394,BrowserRefresh:57447,BrowserSearch:57445,BrowserStop:57448,CapsLock:58,Comma:51,ContextMenu:57437,ControlLeft:29,ControlRight:57373,Convert:121,Copy:57464,Cut:57404,Delete:57427,Digit0:11,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Eject:57469,End:57423,Enter:28,Equal:13,Escape:1,F1:59,F10:68,F11:87,F12:88,F13:93,F14:94,F15:95,F16:85,F17:57347,F18:57463,F19:57348,F2:60,F20:90,F21:116,F22:57465,F23:109,F24:111,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,Find:57409,Help:57461,Hiragana:119,Home:57415,Insert:57426,IntlBackslash:86,IntlRo:115,IntlYen:125,KanaMode:112,Katakana:120,KeyA:30,KeyB:48,KeyC:46,KeyD:32,KeyE:18,KeyF:33,KeyG:34,KeyH:35,KeyI:23,KeyJ:36,KeyK:37,KeyL:38,KeyM:50,KeyN:49,KeyO:24,KeyP:25,KeyQ:16,KeyR:19,KeyS:31,KeyT:20,KeyU:22,KeyV:47,KeyW:17,KeyX:45,KeyY:21,KeyZ:44,Lang1:114,Lang2:113,Lang3:120,Lang4:119,Lang5:118,LaunchApp1:57451,LaunchApp2:57377,LaunchMail:57452,MediaPlayPause:57378,MediaSelect:57453,MediaStop:57380,MediaTrackNext:57369,MediaTrackPrevious:57360,MetaLeft:57435,MetaRight:57436,Minus:12,NonConvert:123,NumLock:69,Numpad0:82,Numpad1:79,Numpad2:80,Numpad3:81,Numpad4:75,Numpad5:76,Numpad6:77,Numpad7:71,Numpad8:72,Numpad9:73,NumpadAdd:78,NumpadComma:126,NumpadDecimal:83,NumpadDivide:57397,NumpadEnter:57372,NumpadEqual:89,NumpadMultiply:55,NumpadParenLeft:57462,NumpadParenRight:57467,NumpadSubtract:74,Open:100,PageDown:57425,PageUp:57417,Paste:101,Pause:57414,Period:52,Power:57438,PrintScreen:84,Props:57350,Quote:40,ScrollLock:70,Semicolon:39,ShiftLeft:42,ShiftRight:54,Slash:53,Sleep:57439,Space:57,Suspend:57381,Tab:15,Undo:57351,WakeUp:57443},Fe={encodingRaw:0,encodingCopyRect:1,encodingRRE:2,encodingHextile:5,encodingZlib:6,encodingTight:7,encodingZRLE:16,encodingTightPNG:-260,encodingJPEG:21,encodingH264:50,pseudoEncodingQualityLevel0:-32,pseudoEncodingDesktopSize:-223,pseudoEncodingLastRect:-224,pseudoEncodingCursor:-239,pseudoEncodingQEMUExtendedKeyEvent:-258,pseudoEncodingQEMULedEvent:-261,pseudoEncodingDesktopName:-307,pseudoEncodingExtendedDesktopSize:-308,pseudoEncodingXvp:-309,pseudoEncodingFence:-312,pseudoEncodingContinuousUpdates:-313,pseudoEncodingExtendedMouseButtons:-316,pseudoEncodingCompressLevel0:-256,pseudoEncodingVMwareCursor:1464686180,pseudoEncodingExtendedClipboard:3231835598};class sl{constructor(){this._key=null}get algorithm(){return{name:"AES-ECB"}}static async importKey(e,s,n,a){const i=new sl;return await i._importKey(e,n,a),i}async _importKey(e,s,n){this._key=await window.crypto.subtle.importKey("raw",e,{name:"AES-CBC"},s,n)}async encrypt(e,s){const n=new Uint8Array(s);if(n.length%16!==0||this._key===null)return null;const a=n.length/16;for(let i=0;i<a;i++){const r=new Uint8Array(await window.crypto.subtle.encrypt({name:"AES-CBC",iv:new Uint8Array(16)},this._key,n.slice(i*16,i*16+16))).slice(0,16);n.set(r,i*16)}return n}}class nl{constructor(){this._rawKey=null,this._ctrKey=null,this._cbcKey=null,this._zeroBlock=new Uint8Array(16),this._prefixBlock0=this._zeroBlock,this._prefixBlock1=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]),this._prefixBlock2=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2])}get algorithm(){return{name:"AES-EAX"}}async _encryptBlock(e){const s=await window.crypto.subtle.encrypt({name:"AES-CBC",iv:this._zeroBlock},this._cbcKey,e);return new Uint8Array(s).slice(0,16)}async _initCMAC(){const e=await this._encryptBlock(this._zeroBlock),s=new Uint8Array(16),n=e[0]>>>6;for(let i=0;i<15;i++)s[i]=e[i+1]>>6|e[i]<<2,e[i]=e[i+1]>>7|e[i]<<1;const a=[0,135,14,137];s[14]^=n>>>1,s[15]=e[15]<<2^a[n],e[15]=e[15]<<1^a[n>>1],this._k1=e,this._k2=s}async _encryptCTR(e,s){const n=await window.crypto.subtle.encrypt({name:"AES-CTR",counter:s,length:128},this._ctrKey,e);return new Uint8Array(n)}async _decryptCTR(e,s){const n=await window.crypto.subtle.decrypt({name:"AES-CTR",counter:s,length:128},this._ctrKey,e);return new Uint8Array(n)}async _computeCMAC(e,s){if(s.length!==16)return null;const n=Math.floor(e.length/16),a=Math.ceil(e.length/16),i=e.length-n*16,r=new Uint8Array((a+1)*16);if(r.set(s),r.set(e,16),i===0)for(let o=0;o<16;o++)r[n*16+o]^=this._k1[o];else{r[(n+1)*16+i]=128;for(let o=0;o<16;o++)r[(n+1)*16+o]^=this._k2[o]}let l=await window.crypto.subtle.encrypt({name:"AES-CBC",iv:this._zeroBlock},this._cbcKey,r);return l=new Uint8Array(l),l.slice(l.length-32,l.length-16)}static async importKey(e,s,n,a){const i=new nl;return await i._importKey(e),i}async _importKey(e){this._rawKey=e,this._ctrKey=await window.crypto.subtle.importKey("raw",e,{name:"AES-CTR"},!1,["encrypt","decrypt"]),this._cbcKey=await window.crypto.subtle.importKey("raw",e,{name:"AES-CBC"},!1,["encrypt"]),await this._initCMAC()}async encrypt(e,s){const n=e.additionalData,a=e.iv,i=await this._computeCMAC(a,this._prefixBlock0),r=await this._encryptCTR(s,i),l=await this._computeCMAC(n,this._prefixBlock1),d=await this._computeCMAC(r,this._prefixBlock2);for(let u=0;u<16;u++)d[u]^=i[u]^l[u];const o=new Uint8Array(16+r.length);return o.set(r),o.set(d,r.length),o}async decrypt(e,s){const n=s.slice(0,s.length-16),a=e.additionalData,i=e.iv,r=s.slice(s.length-16),l=await this._computeCMAC(i,this._prefixBlock0),d=await this._computeCMAC(a,this._prefixBlock1),o=await this._computeCMAC(n,this._prefixBlock2);for(let _=0;_<16;_++)o[_]^=l[_]^d[_];if(o.length!==r.length)return null;for(let _=0;_<r.length;_++)if(o[_]!==r[_])return null;return await this._decryptCTR(n,l)}}const So=[13,16,10,23,0,4,2,27,14,5,20,9,22,18,11,3,25,7,15,6,26,19,12,1,40,51,30,36,46,54,29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31],V_=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],g=0;let P,B,Q,D,R,z;P=65536;B=1<<24;Q=P|B;D=4;R=1024;z=D|R;const Co=[Q|R,g|g,P|g,Q|z,Q|D,P|z,g|D,P|g,g|R,Q|R,Q|z,g|R,B|z,Q|D,B|g,g|D,g|z,B|R,B|R,P|R,P|R,Q|g,Q|g,B|z,P|D,B|D,B|D,P|D,g|g,g|z,P|z,B|g,P|g,Q|z,g|D,Q|g,Q|R,B|g,B|g,g|R,Q|D,P|g,P|R,B|D,g|R,g|D,B|z,P|z,Q|z,P|D,Q|g,B|z,B|D,g|z,P|z,Q|R,g|z,B|R,B|R,g|g,P|D,P|R,g|g,Q|D];P=1<<20;B=1<<31;Q=P|B;D=32;R=32768;z=D|R;const Eo=[Q|z,B|R,g|R,P|z,P|g,g|D,Q|D,B|z,B|D,Q|z,Q|R,B|g,B|R,P|g,g|D,Q|D,P|R,P|D,B|z,g|g,B|g,g|R,P|z,Q|g,P|D,B|D,g|g,P|R,g|z,Q|R,Q|g,g|z,g|g,P|z,Q|D,P|g,B|z,Q|g,Q|R,g|R,Q|g,B|R,g|D,Q|z,P|z,g|D,g|R,B|g,g|z,Q|R,P|g,B|D,P|D,B|z,B|D,P|D,P|R,g|g,B|R,g|z,B|g,Q|D,Q|z,P|R];P=1<<17;B=1<<27;Q=P|B;D=8;R=512;z=D|R;const Ao=[g|z,Q|R,g|g,Q|D,B|R,g|g,P|z,B|R,P|D,B|D,B|D,P|g,Q|z,P|D,Q|g,g|z,B|g,g|D,Q|R,g|R,P|R,Q|g,Q|D,P|z,B|z,P|R,P|g,B|z,g|D,Q|z,g|R,B|g,Q|R,B|g,P|D,g|z,P|g,Q|R,B|R,g|g,g|R,P|D,Q|z,B|R,B|D,g|R,g|g,Q|D,B|z,P|g,B|g,Q|z,g|D,P|z,P|R,B|D,Q|g,B|z,g|z,Q|g,P|z,g|D,Q|D,P|R];P=8192;B=1<<23;Q=P|B;D=1;R=128;z=D|R;const Ko=[Q|D,P|z,P|z,g|R,Q|R,B|z,B|D,P|D,g|g,Q|g,Q|g,Q|z,g|z,g|g,B|R,B|D,g|D,P|g,B|g,Q|D,g|R,B|g,P|D,P|R,B|z,g|D,P|R,B|R,P|g,Q|R,Q|z,g|z,B|R,B|D,Q|g,Q|z,g|z,g|g,g|g,Q|g,P|R,B|R,B|z,g|D,Q|D,P|z,P|z,g|R,Q|z,g|z,g|D,P|g,B|D,P|D,Q|R,B|z,P|D,P|R,B|g,Q|D,g|R,B|g,P|g,Q|R];P=1<<25;B=1<<30;Q=P|B;D=256;R=1<<19;z=D|R;const Fo=[g|D,P|z,P|R,Q|D,g|R,g|D,B|g,P|R,B|z,g|R,P|D,B|z,Q|D,Q|R,g|z,B|g,P|g,B|R,B|R,g|g,B|D,Q|z,Q|z,P|D,Q|R,B|D,g|g,Q|g,P|z,P|g,Q|g,g|z,g|R,Q|D,g|D,P|g,B|g,P|R,Q|D,B|z,P|D,B|g,Q|R,P|z,B|z,g|D,P|g,Q|R,Q|z,g|z,Q|g,Q|z,P|R,g|g,B|R,Q|g,g|z,P|D,B|D,g|R,g|g,B|R,P|z,B|D];P=1<<22;B=1<<29;Q=P|B;D=16;R=16384;z=D|R;const To=[B|D,Q|g,g|R,Q|z,Q|g,g|D,Q|z,P|g,B|R,P|z,P|g,B|D,P|D,B|R,B|g,g|z,g|g,P|D,B|z,g|R,P|R,B|z,g|D,Q|D,Q|D,g|g,P|z,Q|R,g|z,P|R,Q|R,B|g,B|R,g|D,Q|D,P|R,Q|z,P|g,g|z,B|D,P|g,B|R,B|g,g|z,B|D,Q|z,P|R,Q|g,P|z,Q|R,g|g,Q|D,g|D,g|R,Q|g,P|z,g|R,P|D,B|z,g|g,Q|R,B|g,P|D,B|z];P=1<<21;B=1<<26;Q=P|B;D=2;R=2048;z=D|R;const Mo=[P|g,Q|D,B|z,g|g,g|R,B|z,P|z,Q|R,Q|z,P|g,g|g,B|D,g|D,B|g,Q|D,g|z,B|R,P|z,P|D,B|R,B|D,Q|g,Q|R,P|D,Q|g,g|R,g|z,Q|z,P|R,g|D,B|g,P|R,B|g,P|R,P|g,B|z,B|z,Q|D,Q|D,g|D,P|D,B|g,B|R,P|g,Q|R,g|z,P|z,Q|R,g|z,B|D,Q|z,Q|g,P|R,g|g,g|D,Q|z,g|g,P|z,Q|g,g|R,B|D,B|R,g|R,P|D];P=1<<18;B=1<<28;Q=P|B;D=64;R=4096;z=D|R;const Xo=[B|z,g|R,P|g,Q|z,B|g,B|z,g|D,B|g,P|D,Q|g,Q|z,P|R,Q|R,P|z,g|R,g|D,Q|g,B|D,B|R,g|z,P|R,P|D,Q|D,Q|R,g|z,g|g,g|g,Q|D,B|D,B|R,P|z,P|g,P|z,P|g,Q|R,g|R,g|D,Q|D,g|R,P|z,B|R,g|D,B|D,Q|g,Q|D,B|g,P|g,B|z,g|g,Q|z,P|D,B|D,Q|g,B|R,B|z,g|g,Q|z,P|R,P|R,g|z,g|z,P|D,B|g,Q|R];class Ed{constructor(e){this.keys=[];const s=[],n=[],a=[];for(let i=0,r=56;i<56;++i,r-=8){r+=r<-5?65:r<-3?31:r<-1?63:r===27?35:0;const l=r&7;s[i]=(e[r>>>3]&1<<l)!==0?1:0}for(let i=0;i<16;++i){const r=i<<1,l=r+1;a[r]=a[l]=0;for(let d=28;d<59;d+=28)for(let o=d-28;o<d;++o){const u=o+V_[i];n[o]=u<d?s[u]:s[u-28]}for(let d=0;d<24;++d)n[So[d]]!==0&&(a[r]|=1<<23-d),n[So[d+24]]!==0&&(a[l]|=1<<23-d)}for(let i=0,r=0,l=0;i<16;++i){const d=a[r++],o=a[r++];this.keys[l]=(d&16515072)<<6,this.keys[l]|=(d&4032)<<10,this.keys[l]|=(o&16515072)>>>10,this.keys[l]|=(o&4032)>>>6,++l,this.keys[l]=(d&258048)<<12,this.keys[l]|=(d&63)<<16,this.keys[l]|=(o&258048)>>>4,this.keys[l]|=o&63,++l}}enc8(e){const s=e.slice();let n=0,a,i,r;a=s[n++]<<24|s[n++]<<16|s[n++]<<8|s[n++],i=s[n++]<<24|s[n++]<<16|s[n++]<<8|s[n++],r=(a>>>4^i)&252645135,i^=r,a^=r<<4,r=(a>>>16^i)&65535,i^=r,a^=r<<16,r=(i>>>2^a)&858993459,a^=r,i^=r<<2,r=(i>>>8^a)&16711935,a^=r,i^=r<<8,i=i<<1|i>>>31&1,r=(a^i)&2863311530,a^=r,i^=r,a=a<<1|a>>>31&1;for(let l=0,d=0;l<8;++l){r=i<<28|i>>>4,r^=this.keys[d++];let o=Mo[r&63];o|=Fo[r>>>8&63],o|=Ao[r>>>16&63],o|=Co[r>>>24&63],r=i^this.keys[d++],o|=Xo[r&63],o|=To[r>>>8&63],o|=Ko[r>>>16&63],o|=Eo[r>>>24&63],a^=o,r=a<<28|a>>>4,r^=this.keys[d++],o=Mo[r&63],o|=Fo[r>>>8&63],o|=Ao[r>>>16&63],o|=Co[r>>>24&63],r=a^this.keys[d++],o|=Xo[r&63],o|=To[r>>>8&63],o|=Ko[r>>>16&63],o|=Eo[r>>>24&63],i^=o}for(i=i<<31|i>>>1,r=(a^i)&2863311530,a^=r,i^=r,a=a<<31|a>>>1,r=(a>>>8^i)&16711935,i^=r,a^=r<<8,r=(a>>>2^i)&858993459,i^=r,a^=r<<2,r=(i>>>16^a)&65535,a^=r,i^=r<<16,r=(i>>>4^a)&252645135,a^=r,i^=r<<4,r=[i,a],n=0;n<8;n++)s[n]=(r[n>>>2]>>>8*(3-n%4))%256,s[n]<0&&(s[n]+=256);return s}}class al{constructor(){this._cipher=null}get algorithm(){return{name:"DES-ECB"}}static importKey(e,s,n,a){const i=new al;return i._importKey(e),i}_importKey(e,s,n){this._cipher=new Ed(e)}encrypt(e,s){const n=new Uint8Array(s);if(n.length%8!==0||this._cipher===null)return null;const a=n.length/8;for(let i=0;i<a;i++)n.set(this._cipher.enc8(n.slice(i*8,i*8+8)),i*8);return n}}class il{constructor(){this._cipher=null}get algorithm(){return{name:"DES-CBC"}}static importKey(e,s,n,a){const i=new il;return i._importKey(e),i}_importKey(e){this._cipher=new Ed(e)}encrypt(e,s){const n=new Uint8Array(s);let a=new Uint8Array(e.iv);if(n.length%8!==0||this._cipher===null)return null;const i=n.length/8;for(let r=0;r<i;r++){for(let l=0;l<8;l++)a[l]^=s[r*8+l];a=this._cipher.enc8(a),n.set(a,r*8)}return n}}function Ci(t,e,s){let n=1n;for(t=t%s;e>0n;)(e&1n)===1n&&(n=n*t%s),e=e>>1n,t=t*t%s;return n}function Ei(t,e=0){let s=t.toString(16);e===0&&(e=Math.ceil(s.length/2)),s=s.padStart(e*2,"0");const n=s.length/2,a=new Uint8Array(n);for(let i=0;i<n;i++)a[i]=parseInt(s.slice(i*2,i*2+2),16);return a}function Ss(t){let e="0x";for(let s=0;s<t.length;s++)e+=t[s].toString(16).padStart(2,"0");return BigInt(e)}class Ai{constructor(){this._keyLength=0,this._keyBytes=0,this._n=null,this._e=null,this._d=null,this._nBigInt=null,this._eBigInt=null,this._dBigInt=null,this._extractable=!1}get algorithm(){return{name:"RSA-PKCS1-v1_5"}}_base64urlDecode(e){return e=e.replace(/-/g,"+").replace(/_/g,"/"),e=e.padEnd(Math.ceil(e.length/4)*4,"="),Zr.decode(e)}_padArray(e,s){const n=new Uint8Array(s);return n.set(e,s-e.length),n}static async generateKey(e,s,n){const a=new Ai;return await a._generateKey(e,s),{privateKey:a}}async _generateKey(e,s){this._keyLength=e.modulusLength,this._keyBytes=Math.ceil(this._keyLength/8);const n=await window.crypto.subtle.generateKey({name:"RSA-OAEP",modulusLength:e.modulusLength,publicExponent:e.publicExponent,hash:{name:"SHA-256"}},!0,["encrypt","decrypt"]),a=await window.crypto.subtle.exportKey("jwk",n.privateKey);this._n=this._padArray(this._base64urlDecode(a.n),this._keyBytes),this._nBigInt=Ss(this._n),this._e=this._padArray(this._base64urlDecode(a.e),this._keyBytes),this._eBigInt=Ss(this._e),this._d=this._padArray(this._base64urlDecode(a.d),this._keyBytes),this._dBigInt=Ss(this._d),this._extractable=s}static async importKey(e,s,n,a){if(a.length!==1||a[0]!=="encrypt")throw new Error("only support importing RSA public key");const i=new Ai;return await i._importKey(e,n),i}async _importKey(e,s){const n=e.n,a=e.e;if(n.length!==a.length)throw new Error("the sizes of modulus and public exponent do not match");this._keyBytes=n.length,this._keyLength=this._keyBytes*8,this._n=new Uint8Array(this._keyBytes),this._e=new Uint8Array(this._keyBytes),this._n.set(n),this._e.set(a),this._nBigInt=Ss(this._n),this._eBigInt=Ss(this._e),this._extractable=s}async encrypt(e,s){if(s.length>this._keyBytes-11)return null;const n=new Uint8Array(this._keyBytes-s.length-3);window.crypto.getRandomValues(n);for(let l=0;l<n.length;l++)n[l]=Math.floor(n[l]*254/255+1);const a=new Uint8Array(this._keyBytes);a[1]=2,a.set(n,2),a.set(s,n.length+3);const i=Ss(a),r=Ci(i,this._eBigInt,this._nBigInt);return Ei(r,this._keyBytes)}async decrypt(e,s){if(s.length!==this._keyBytes)return null;const n=Ss(s),a=Ci(n,this._dBigInt,this._nBigInt),i=Ei(a,this._keyBytes);if(i[0]!==0||i[1]!==2)return null;let r=2;for(;r<i.length&&i[r]!==0;r++);return r===i.length?null:i.slice(r+1,i.length)}async exportKey(){if(!this._extractable)throw new Error("key is not extractable");return{n:this._n,e:this._e,d:this._d}}}class G_{constructor(e){this._key=e}get algorithm(){return{name:"DH"}}exportKey(){return this._key}}class rl{constructor(){this._g=null,this._p=null,this._gBigInt=null,this._pBigInt=null,this._privateKey=null}get algorithm(){return{name:"DH"}}static generateKey(e,s){const n=new rl;return n._generateKey(e),{privateKey:n,publicKey:new G_(n._publicKey)}}_generateKey(e){const s=e.g,n=e.p;this._keyBytes=n.length,this._gBigInt=Ss(s),this._pBigInt=Ss(n),this._privateKey=window.crypto.getRandomValues(new Uint8Array(this._keyBytes)),this._privateKeyBigInt=Ss(this._privateKey),this._publicKey=Ei(Ci(this._gBigInt,this._privateKeyBigInt,this._pBigInt),this._keyBytes)}deriveBits(e,s){const n=Math.ceil(s/8),a=new Uint8Array(e.public),i=n>this._keyBytes?n:this._keyBytes,r=Ci(Ss(a),this._privateKeyBigInt,this._pBigInt);return Ei(r,i).slice(0,i)}}async function q_(t){let e="";for(let s=0;s<t.length;s++)e+=String.fromCharCode(t[s]);return W_(Y_(Z_(j_(e),8*e.length)))}function W_(t){let e=new Uint8Array(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e}function j_(t){let e=Array(t.length>>2);for(let s=0;s<e.length;s++)e[s]=0;for(let s=0;s<8*t.length;s+=8)e[s>>5]|=(255&t.charCodeAt(s/8))<<s%32;return e}function Y_(t){let e="";for(let s=0;s<32*t.length;s+=8)e+=String.fromCharCode(t[s>>5]>>>s%32&255);return e}function Z_(t,e){t[e>>5]|=128<<e%32,t[14+(e+64>>>9<<4)]=e;let s=1732584193,n=-271733879,a=-1732584194,i=271733878;for(let r=0;r<t.length;r+=16){let l=s,d=n,o=a,u=i;n=Ot(n=Ot(n=Ot(n=Ot(n=Ht(n=Ht(n=Ht(n=Ht(n=Ut(n=Ut(n=Ut(n=Ut(n=Nt(n=Nt(n=Nt(n=Nt(n,a=Nt(a,i=Nt(i,s=Nt(s,n,a,i,t[r+0],7,-680876936),n,a,t[r+1],12,-389564586),s,n,t[r+2],17,606105819),i,s,t[r+3],22,-1044525330),a=Nt(a,i=Nt(i,s=Nt(s,n,a,i,t[r+4],7,-176418897),n,a,t[r+5],12,1200080426),s,n,t[r+6],17,-1473231341),i,s,t[r+7],22,-45705983),a=Nt(a,i=Nt(i,s=Nt(s,n,a,i,t[r+8],7,1770035416),n,a,t[r+9],12,-1958414417),s,n,t[r+10],17,-42063),i,s,t[r+11],22,-1990404162),a=Nt(a,i=Nt(i,s=Nt(s,n,a,i,t[r+12],7,1804603682),n,a,t[r+13],12,-40341101),s,n,t[r+14],17,-1502002290),i,s,t[r+15],22,1236535329),a=Ut(a,i=Ut(i,s=Ut(s,n,a,i,t[r+1],5,-165796510),n,a,t[r+6],9,-1069501632),s,n,t[r+11],14,643717713),i,s,t[r+0],20,-373897302),a=Ut(a,i=Ut(i,s=Ut(s,n,a,i,t[r+5],5,-701558691),n,a,t[r+10],9,38016083),s,n,t[r+15],14,-660478335),i,s,t[r+4],20,-405537848),a=Ut(a,i=Ut(i,s=Ut(s,n,a,i,t[r+9],5,568446438),n,a,t[r+14],9,-1019803690),s,n,t[r+3],14,-187363961),i,s,t[r+8],20,1163531501),a=Ut(a,i=Ut(i,s=Ut(s,n,a,i,t[r+13],5,-1444681467),n,a,t[r+2],9,-51403784),s,n,t[r+7],14,1735328473),i,s,t[r+12],20,-1926607734),a=Ht(a,i=Ht(i,s=Ht(s,n,a,i,t[r+5],4,-378558),n,a,t[r+8],11,-2022574463),s,n,t[r+11],16,1839030562),i,s,t[r+14],23,-35309556),a=Ht(a,i=Ht(i,s=Ht(s,n,a,i,t[r+1],4,-1530992060),n,a,t[r+4],11,1272893353),s,n,t[r+7],16,-155497632),i,s,t[r+10],23,-1094730640),a=Ht(a,i=Ht(i,s=Ht(s,n,a,i,t[r+13],4,681279174),n,a,t[r+0],11,-358537222),s,n,t[r+3],16,-722521979),i,s,t[r+6],23,76029189),a=Ht(a,i=Ht(i,s=Ht(s,n,a,i,t[r+9],4,-640364487),n,a,t[r+12],11,-421815835),s,n,t[r+15],16,530742520),i,s,t[r+2],23,-995338651),a=Ot(a,i=Ot(i,s=Ot(s,n,a,i,t[r+0],6,-198630844),n,a,t[r+7],10,1126891415),s,n,t[r+14],15,-1416354905),i,s,t[r+5],21,-57434055),a=Ot(a,i=Ot(i,s=Ot(s,n,a,i,t[r+12],6,1700485571),n,a,t[r+3],10,-1894986606),s,n,t[r+10],15,-1051523),i,s,t[r+1],21,-2054922799),a=Ot(a,i=Ot(i,s=Ot(s,n,a,i,t[r+8],6,1873313359),n,a,t[r+15],10,-30611744),s,n,t[r+6],15,-1560198380),i,s,t[r+13],21,1309151649),a=Ot(a,i=Ot(i,s=Ot(s,n,a,i,t[r+4],6,-145523070),n,a,t[r+11],10,-1120210379),s,n,t[r+2],15,718787259),i,s,t[r+9],21,-343485551),s=vn(s,l),n=vn(n,d),a=vn(a,o),i=vn(i,u)}return Array(s,n,a,i)}function Ii(t,e,s,n,a,i){return vn(J_(vn(vn(e,t),vn(n,i)),a),s)}function Nt(t,e,s,n,a,i,r){return Ii(e&s|~e&n,t,e,a,i,r)}function Ut(t,e,s,n,a,i,r){return Ii(e&n|s&~n,t,e,a,i,r)}function Ht(t,e,s,n,a,i,r){return Ii(e^s^n,t,e,a,i,r)}function Ot(t,e,s,n,a,i,r){return Ii(s^(e|~n),t,e,a,i,r)}function vn(t,e){let s=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(s>>16)<<16|65535&s}function J_(t,e){return t<<e|t>>>32-e}class $_{constructor(){this._algorithms={"AES-ECB":sl,"AES-EAX":nl,"DES-ECB":al,"DES-CBC":il,"RSA-PKCS1-v1_5":Ai,DH:rl,MD5:q_}}encrypt(e,s,n){if(s.algorithm.name!==e.name)throw new Error("algorithm does not match");if(typeof s.encrypt!="function")throw new Error("key does not support encryption");return s.encrypt(e,n)}decrypt(e,s,n){if(s.algorithm.name!==e.name)throw new Error("algorithm does not match");if(typeof s.decrypt!="function")throw new Error("key does not support encryption");return s.decrypt(e,n)}importKey(e,s,n,a,i){if(e!=="raw")throw new Error("key format is not supported");const r=this._algorithms[n.name];if(typeof r>"u"||typeof r.importKey!="function")throw new Error("algorithm is not supported");return r.importKey(s,n,a,i)}generateKey(e,s,n){const a=this._algorithms[e.name];if(typeof a>"u"||typeof a.generateKey!="function")throw new Error("algorithm is not supported");return a.generateKey(e,s,n)}exportKey(e,s){if(e!=="raw")throw new Error("key format is not supported");if(typeof s.exportKey!="function")throw new Error("key does not support exportKey");return s.exportKey()}digest(e,s){const n=this._algorithms[e];if(typeof n!="function")throw new Error("algorithm is not supported");return n(s)}deriveBits(e,s,n){if(s.algorithm.name!==e.name)throw new Error("algorithm does not match");if(typeof s.deriveBits!="function")throw new Error("key does not support deriveBits");return s.deriveBits(e,n)}}const gt=new $_;class Lo{constructor(){this._cipher=null,this._counter=new Uint8Array(16)}async setKey(e){this._cipher=await gt.importKey("raw",e,{name:"AES-EAX"},!1,["encrypt, decrypt"])}async makeMessage(e){const s=new Uint8Array([(e.length&65280)>>>8,e.length&255]),n=await gt.encrypt({name:"AES-EAX",iv:this._counter,additionalData:s},this._cipher,e);for(let i=0;i<16&&this._counter[i]++===255;i++);const a=new Uint8Array(e.length+2+16);return a.set(s),a.set(n,2),a}async receiveMessage(e,s){const n=new Uint8Array([(e&65280)>>>8,e&255]),a=await gt.decrypt({name:"AES-EAX",iv:this._counter,additionalData:n},this._cipher,s);for(let i=0;i<16&&this._counter[i]++===255;i++);return a}}class ev extends sd{constructor(e,s){super(),this._hasStarted=!1,this._checkSock=null,this._checkCredentials=null,this._approveServerResolve=null,this._sockReject=null,this._credentialsReject=null,this._approveServerReject=null,this._sock=e,this._getCredentials=s}_waitSockAsync(e){return new Promise((s,n)=>{const a=()=>!this._sock.rQwait("RA2",e);a()?s():(this._checkSock=()=>{a()&&(s(),this._checkSock=null,this._sockReject=null)},this._sockReject=n)})}_waitApproveKeyAsync(){return new Promise((e,s)=>{this._approveServerResolve=e,this._approveServerReject=s})}_waitCredentialsAsync(e){const s=()=>e===1&&this._getCredentials().username!==void 0&&this._getCredentials().password!==void 0?!0:e===2&&this._getCredentials().password!==void 0;return new Promise((n,a)=>{s()?n():(this._checkCredentials=()=>{s()&&(n(),this._checkCredentials=null,this._credentialsReject=null)},this._credentialsReject=a)})}checkInternalEvents(){this._checkSock!==null&&this._checkSock(),this._checkCredentials!==null&&this._checkCredentials()}approveServer(){this._approveServerResolve!==null&&(this._approveServerResolve(),this._approveServerResolve=null)}disconnect(){this._sockReject!==null&&(this._sockReject(new Error("disconnect normally")),this._sockReject=null),this._credentialsReject!==null&&(this._credentialsReject(new Error("disconnect normally")),this._credentialsReject=null),this._approveServerReject!==null&&(this._approveServerReject(new Error("disconnect normally")),this._approveServerReject=null)}async negotiateRA2neAuthAsync(){this._hasStarted=!0,await this._waitSockAsync(4);const e=this._sock.rQpeekBytes(4),s=this._sock.rQshift32();if(s<1024)throw new Error("RA2: server public key is too short: "+s);if(s>8192)throw new Error("RA2: server public key is too long: "+s);const n=Math.ceil(s/8);await this._waitSockAsync(n*2);const a=this._sock.rQshiftBytes(n),i=this._sock.rQshiftBytes(n),r=await gt.importKey("raw",{n:a,e:i},{name:"RSA-PKCS1-v1_5"},!1,["encrypt"]),l=new Uint8Array(4+n*2);l.set(e),l.set(a,4),l.set(i,4+n);let d=this._waitApproveKeyAsync();this.dispatchEvent(new CustomEvent("serververification",{detail:{type:"RSA",publickey:l}})),await d;const o=2048,u=Math.ceil(o/8),_=(await gt.generateKey({name:"RSA-PKCS1-v1_5",modulusLength:o,publicExponent:new Uint8Array([1,0,1])},!0,["encrypt"])).privateKey,p=await gt.exportKey("raw",_),v=p.n,x=p.e,y=new Uint8Array(4+u*2);y[0]=(o&4278190080)>>>24,y[1]=(o&16711680)>>>16,y[2]=(o&65280)>>>8,y[3]=o&255,y.set(v,4),y.set(x,4+u),this._sock.sQpushBytes(y),this._sock.flush();const w=new Uint8Array(16);window.crypto.getRandomValues(w);const S=await gt.encrypt({name:"RSA-PKCS1-v1_5"},r,w),E=new Uint8Array(2+n);if(E[0]=(n&65280)>>>8,E[1]=n&255,E.set(S,2),this._sock.sQpushBytes(E),this._sock.flush(),await this._waitSockAsync(2),this._sock.rQshift16()!==u)throw new Error("RA2: wrong encrypted message length");const K=this._sock.rQshiftBytes(u),A=await gt.decrypt({name:"RSA-PKCS1-v1_5"},_,K);if(A===null||A.length!==16)throw new Error("RA2: corrupted server encrypted random");let U=new Uint8Array(32),ee=new Uint8Array(32);U.set(A),U.set(w,16),ee.set(w),ee.set(A,16),U=await window.crypto.subtle.digest("SHA-1",U),U=new Uint8Array(U).slice(0,16),ee=await window.crypto.subtle.digest("SHA-1",ee),ee=new Uint8Array(ee).slice(0,16);const X=new Lo;await X.setKey(U);const C=new Lo;await C.setKey(ee);let F=new Uint8Array(8+n*2+u*2),L=new Uint8Array(8+n*2+u*2);if(F.set(l),F.set(y,4+n*2),L.set(y),L.set(l,4+u*2),F=await window.crypto.subtle.digest("SHA-1",F),L=await window.crypto.subtle.digest("SHA-1",L),F=new Uint8Array(F),L=new Uint8Array(L),this._sock.sQpushBytes(await X.makeMessage(L)),this._sock.flush(),await this._waitSockAsync(38),this._sock.rQshift16()!==20)throw new Error("RA2: wrong server hash");const j=await C.receiveMessage(20,this._sock.rQshiftBytes(36));if(j===null)throw new Error("RA2: failed to authenticate the message");for(let ae=0;ae<20;ae++)if(j[ae]!==F[ae])throw new Error("RA2: wrong server hash");if(await this._waitSockAsync(19),this._sock.rQshift16()!==1)throw new Error("RA2: wrong subtype");let oe=await C.receiveMessage(1,this._sock.rQshiftBytes(17));if(oe===null)throw new Error("RA2: failed to authenticate the message");oe=oe[0];let de=this._waitCredentialsAsync(oe);if(oe===1)(this._getCredentials().username===void 0||this._getCredentials().password===void 0)&&this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}}));else if(oe===2)this._getCredentials().password===void 0&&this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["password"]}}));else throw new Error("RA2: wrong subtype");await de;let J;oe===1?J=Ws(this._getCredentials().username).slice(0,255):J="";const N=Ws(this._getCredentials().password).slice(0,255),se=new Uint8Array(J.length+N.length+2);se[0]=J.length,se[J.length+1]=N.length;for(let ae=0;ae<J.length;ae++)se[ae+1]=J.charCodeAt(ae);for(let ae=0;ae<N.length;ae++)se[J.length+2+ae]=N.charCodeAt(ae);this._sock.sQpushBytes(await X.makeMessage(se)),this._sock.flush()}get hasStarted(){return this._hasStarted}set hasStarted(e){this._hasStarted=e}}class tv{constructor(){this._lines=0}decodeRect(e,s,n,a,i,r,l){if(n===0||a===0)return!0;this._lines===0&&(this._lines=a);const d=l==8?1:4,o=n*d;for(;this._lines>0;){if(i.rQwait("RAW",o))return!1;const u=s+(a-this._lines);let _=i.rQshiftBytes(o,!1);if(l==8){const p=new Uint8Array(n*4);for(let v=0;v<n;v++)p[v*4+0]=(_[v]>>0&3)*255/3,p[v*4+1]=(_[v]>>2&3)*255/3,p[v*4+2]=(_[v]>>4&3)*255/3,p[v*4+3]=255;_=p}for(let p=0;p<n;p++)_[p*4+3]=255;r.blitImage(e,u,n,1,_,0),this._lines--}return!0}}class sv{decodeRect(e,s,n,a,i,r,l){if(i.rQwait("COPYRECT",4))return!1;let d=i.rQshift16(),o=i.rQshift16();return n===0||a===0||r.copyImage(d,o,e,s,n,a),!0}}class nv{constructor(){this._subrects=0}decodeRect(e,s,n,a,i,r,l){if(this._subrects===0){if(i.rQwait("RRE",8))return!1;this._subrects=i.rQshift32();let d=i.rQshiftBytes(4);r.fillRect(e,s,n,a,d)}for(;this._subrects>0;){if(i.rQwait("RRE",12))return!1;let d=i.rQshiftBytes(4),o=i.rQshift16(),u=i.rQshift16(),_=i.rQshift16(),p=i.rQshift16();r.fillRect(e+o,s+u,_,p,d),this._subrects--}return!0}}class av{constructor(){this._tiles=0,this._lastsubencoding=0,this._tileBuffer=new Uint8Array(256*4)}decodeRect(e,s,n,a,i,r,l){for(this._tiles===0&&(this._tilesX=Math.ceil(n/16),this._tilesY=Math.ceil(a/16),this._totalTiles=this._tilesX*this._tilesY,this._tiles=this._totalTiles);this._tiles>0;){let d=1;if(i.rQwait("HEXTILE",d))return!1;let o=i.rQpeek8();if(o>30)throw new Error("Illegal hextile subencoding (subencoding: "+o+")");const u=this._totalTiles-this._tiles,_=u%this._tilesX,p=Math.floor(u/this._tilesX),v=e+_*16,x=s+p*16,y=Math.min(16,e+n-v),w=Math.min(16,s+a-x);if(o&1)d+=y*w*4;else if(o&2&&(d+=4),o&4&&(d+=4),o&8){if(d++,i.rQwait("HEXTILE",d))return!1;let S=i.rQpeekBytes(d).at(-1);o&16?d+=S*6:d+=S*2}if(i.rQwait("HEXTILE",d))return!1;if(i.rQshift8(),o===0)this._lastsubencoding&1?Ke(" Ignoring blank after RAW"):r.fillRect(v,x,y,w,this._background);else if(o&1){let S=y*w,E=i.rQshiftBytes(S*4,!1);for(let K=0;K<S;K++)E[K*4+3]=255;r.blitImage(v,x,y,w,E,0)}else{if(o&2&&(this._background=new Uint8Array(i.rQshiftBytes(4))),o&4&&(this._foreground=new Uint8Array(i.rQshiftBytes(4))),this._startTile(v,x,y,w,this._background),o&8){let S=i.rQshift8();for(let E=0;E<S;E++){let K;o&16?K=i.rQshiftBytes(4):K=this._foreground;const A=i.rQshift8(),U=A>>4,ee=A&15,X=i.rQshift8(),C=(X>>4)+1,F=(X&15)+1;this._subTile(U,ee,C,F,K)}}this._finishTile(r)}this._lastsubencoding=o,this._tiles--}return!0}_startTile(e,s,n,a,i){this._tileX=e,this._tileY=s,this._tileW=n,this._tileH=a;const r=i[0],l=i[1],d=i[2],o=this._tileBuffer;for(let u=0;u<n*a*4;u+=4)o[u]=r,o[u+1]=l,o[u+2]=d,o[u+3]=255}_subTile(e,s,n,a,i){const r=i[0],l=i[1],d=i[2],o=e+n,u=s+a,_=this._tileBuffer,p=this._tileW;for(let v=s;v<u;v++)for(let x=e;x<o;x++){const y=(x+v*p)*4;_[y]=r,_[y+1]=l,_[y+2]=d,_[y+3]=255}}_finishTile(e){e.blitImage(this._tileX,this._tileY,this._tileW,this._tileH,this._tileBuffer,0)}}class iv{constructor(){this._zlib=new Bi,this._length=0}decodeRect(e,s,n,a,i,r,l){if(n===0||a===0)return!0;if(this._length===0){if(i.rQwait("ZLIB",4))return!1;this._length=i.rQshift32()}if(i.rQwait("ZLIB",this._length))return!1;let d=new Uint8Array(i.rQshiftBytes(this._length,!1));this._length=0,this._zlib.setInput(d),d=this._zlib.inflate(n*a*4),this._zlib.setInput(null);for(let o=0;o<n*a;o++)d[o*4+3]=255;return r.blitImage(e,s,n,a,d,0),!0}}class Ad{constructor(){this._ctl=null,this._filter=null,this._numColors=0,this._palette=new Uint8Array(1024),this._len=0,this._zlibs=[];for(let e=0;e<4;e++)this._zlibs[e]=new Bi}decodeRect(e,s,n,a,i,r,l){if(this._ctl===null){if(i.rQwait("TIGHT compression-control",1))return!1;this._ctl=i.rQshift8();for(let o=0;o<4;o++)this._ctl>>o&1&&(this._zlibs[o].reset(),Vt("Reset zlib stream "+o));this._ctl=this._ctl>>4}let d;if(this._ctl===8)d=this._fillRect(e,s,n,a,i,r,l);else if(this._ctl===9)d=this._jpegRect(e,s,n,a,i,r,l);else if(this._ctl===10)d=this._pngRect(e,s,n,a,i,r,l);else if((this._ctl&8)==0)d=this._basicRect(this._ctl,e,s,n,a,i,r,l);else throw new Error("Illegal tight compression received (ctl: "+this._ctl+")");return d&&(this._ctl=null),d}_fillRect(e,s,n,a,i,r,l){if(i.rQwait("TIGHT",3))return!1;let d=i.rQshiftBytes(3);return r.fillRect(e,s,n,a,d,!1),!0}_jpegRect(e,s,n,a,i,r,l){let d=this._readData(i);return d===null?!1:(r.imageRect(e,s,n,a,"image/jpeg",d),!0)}_pngRect(e,s,n,a,i,r,l){throw new Error("PNG received in standard Tight rect")}_basicRect(e,s,n,a,i,r,l,d){if(this._filter===null)if(e&4){if(r.rQwait("TIGHT",1))return!1;this._filter=r.rQshift8()}else this._filter=0;let o=e&3,u;switch(this._filter){case 0:u=this._copyFilter(o,s,n,a,i,r,l,d);break;case 1:u=this._paletteFilter(o,s,n,a,i,r,l,d);break;case 2:u=this._gradientFilter(o,s,n,a,i,r,l,d);break;default:throw new Error("Illegal tight filter received (ctl: "+this._filter+")")}return u&&(this._filter=null),u}_copyFilter(e,s,n,a,i,r,l,d){const o=a*i*3;let u;if(o===0)return!0;if(o<12){if(r.rQwait("TIGHT",o))return!1;u=r.rQshiftBytes(o)}else{if(u=this._readData(r),u===null)return!1;this._zlibs[e].setInput(u),u=this._zlibs[e].inflate(o),this._zlibs[e].setInput(null)}let _=new Uint8Array(a*i*4);for(let p=0,v=0;p<a*i*4;p+=4,v+=3)_[p]=u[v],_[p+1]=u[v+1],_[p+2]=u[v+2],_[p+3]=255;return l.blitImage(s,n,a,i,_,0,!1),!0}_paletteFilter(e,s,n,a,i,r,l,d){if(this._numColors===0){if(r.rQwait("TIGHT palette",1))return!1;const v=r.rQpeek8()+1,x=v*3;if(r.rQwait("TIGHT palette",1+x))return!1;this._numColors=v,r.rQskipBytes(1),r.rQshiftTo(this._palette,x)}const o=this._numColors<=2?1:8,_=Math.floor((a*o+7)/8)*i;let p;if(_===0)return!0;if(_<12){if(r.rQwait("TIGHT",_))return!1;p=r.rQshiftBytes(_)}else{if(p=this._readData(r),p===null)return!1;this._zlibs[e].setInput(p),p=this._zlibs[e].inflate(_),this._zlibs[e].setInput(null)}return this._numColors==2?this._monoRect(s,n,a,i,p,this._palette,l):this._paletteRect(s,n,a,i,p,this._palette,l),this._numColors=0,!0}_monoRect(e,s,n,a,i,r,l){const d=this._getScratchBuffer(n*a*4),o=Math.floor((n+7)/8),u=Math.floor(n/8);for(let _=0;_<a;_++){let p,v,x;for(x=0;x<u;x++)for(let y=7;y>=0;y--)p=(_*n+x*8+7-y)*4,v=(i[_*o+x]>>y&1)*3,d[p]=r[v],d[p+1]=r[v+1],d[p+2]=r[v+2],d[p+3]=255;for(let y=7;y>=8-n%8;y--)p=(_*n+x*8+7-y)*4,v=(i[_*o+x]>>y&1)*3,d[p]=r[v],d[p+1]=r[v+1],d[p+2]=r[v+2],d[p+3]=255}l.blitImage(e,s,n,a,d,0,!1)}_paletteRect(e,s,n,a,i,r,l){const d=this._getScratchBuffer(n*a*4),o=n*a*4;for(let u=0,_=0;u<o;u+=4,_++){const p=i[_]*3;d[u]=r[p],d[u+1]=r[p+1],d[u+2]=r[p+2],d[u+3]=255}l.blitImage(e,s,n,a,d,0,!1)}_gradientFilter(e,s,n,a,i,r,l,d){const o=a*i*3;let u;if(o===0)return!0;if(o<12){if(r.rQwait("TIGHT",o))return!1;u=r.rQshiftBytes(o)}else{if(u=this._readData(r),u===null)return!1;this._zlibs[e].setInput(u),u=this._zlibs[e].inflate(o),this._zlibs[e].setInput(null)}let _=new Uint8Array(4*a*i),p=0,v=0,x=new Uint8Array(3);for(let E=0;E<a;E++){for(let K=0;K<3;K++){const A=x[K],U=u[v++]+A;_[p++]=U,x[K]=U}_[p++]=255}let y=0,w=new Uint8Array(3),S=new Uint8Array(3);for(let E=1;E<i;E++){x.fill(0),S.fill(0);for(let K=0;K<a;K++){for(let A=0;A<3;A++){w[A]=_[y++];let U=x[A]+w[A]-S[A];U<0?U=0:U>255&&(U=255);const ee=u[v++]+U;_[p++]=ee,S[A]=w[A],x[A]=ee}_[p++]=255,y++}}return l.blitImage(s,n,a,i,_,0,!1),!0}_readData(e){if(this._len===0){if(e.rQwait("TIGHT",3))return null;let n;n=e.rQshift8(),this._len=n&127,n&128&&(n=e.rQshift8(),this._len|=(n&127)<<7,n&128&&(n=e.rQshift8(),this._len|=n<<14))}if(e.rQwait("TIGHT",this._len))return null;let s=e.rQshiftBytes(this._len,!1);return this._len=0,s}_getScratchBuffer(e){return(!this._scratchBuffer||this._scratchBuffer.length<e)&&(this._scratchBuffer=new Uint8Array(e)),this._scratchBuffer}}class rv extends Ad{_pngRect(e,s,n,a,i,r,l){let d=this._readData(i);return d===null?!1:(r.imageRect(e,s,n,a,"image/png",d),!0)}_basicRect(e,s,n,a,i,r,l,d){throw new Error("BasicCompression received in TightPNG rect")}}const oi=64,ci=64;class lv{constructor(){this._length=0,this._inflator=new Bi,this._pixelBuffer=new Uint8Array(oi*ci*4),this._tileBuffer=new Uint8Array(oi*ci*4)}decodeRect(e,s,n,a,i,r,l){if(this._length===0){if(i.rQwait("ZLib data length",4))return!1;this._length=i.rQshift32()}if(i.rQwait("Zlib data",this._length))return!1;const d=i.rQshiftBytes(this._length,!1);this._inflator.setInput(d);for(let o=s;o<s+a;o+=ci){let u=Math.min(ci,s+a-o);for(let _=e;_<e+n;_+=oi){let p=Math.min(oi,e+n-_);const v=p*u,x=this._inflator.inflate(1)[0];if(x===0){const y=this._readPixels(v);r.blitImage(_,o,p,u,y,0,!1)}else if(x===1){const y=this._readPixels(1);r.fillRect(_,o,p,u,[y[0],y[1],y[2]])}else if(x>=2&&x<=16){const y=this._decodePaletteTile(x,v,p,u);r.blitImage(_,o,p,u,y,0,!1)}else if(x===128){const y=this._decodeRLETile(v);r.blitImage(_,o,p,u,y,0,!1)}else if(x>=130&&x<=255){const y=this._decodeRLEPaletteTile(x-128,v);r.blitImage(_,o,p,u,y,0,!1)}else throw new Error("Unknown subencoding: "+x)}}return this._length=0,!0}_getBitsPerPixelInPalette(e){if(e<=2)return 1;if(e<=4)return 2;if(e<=16)return 4}_readPixels(e){let s=this._pixelBuffer;const n=this._inflator.inflate(3*e);for(let a=0,i=0;a<e*4;a+=4,i+=3)s[a]=n[i],s[a+1]=n[i+1],s[a+2]=n[i+2],s[a+3]=255;return s}_decodePaletteTile(e,s,n,a){const i=this._tileBuffer,r=this._readPixels(e),l=this._getBitsPerPixelInPalette(e),d=(1<<l)-1;let o=0,u=this._inflator.inflate(1)[0];for(let _=0;_<a;_++){let p=8-l;for(let v=0;v<n;v++){p<0&&(p=8-l,u=this._inflator.inflate(1)[0]);let x=u>>p&d;i[o]=r[x*4],i[o+1]=r[x*4+1],i[o+2]=r[x*4+2],i[o+3]=r[x*4+3],o+=4,p-=l}p<8-l&&_<a-1&&(u=this._inflator.inflate(1)[0])}return i}_decodeRLETile(e){const s=this._tileBuffer;let n=0;for(;n<e;){const a=this._readPixels(1),i=this._readRLELength();for(let r=0;r<i;r++)s[n*4]=a[0],s[n*4+1]=a[1],s[n*4+2]=a[2],s[n*4+3]=a[3],n++}return s}_decodeRLEPaletteTile(e,s){const n=this._tileBuffer,a=this._readPixels(e);let i=0;for(;i<s;){let r=this._inflator.inflate(1)[0],l=1;if(r>=128&&(r-=128,l=this._readRLELength()),r>e)throw new Error("Too big index in palette: "+r+", palette size: "+e);if(i+l>s)throw new Error("Too big rle length in palette mode: "+l+", allowed length is: "+(s-i));for(let d=0;d<l;d++)n[i*4]=a[r*4],n[i*4+1]=a[r*4+1],n[i*4+2]=a[r*4+2],n[i*4+3]=a[r*4+3],i++}return n}_readRLELength(){let e=0,s=0;do s=this._inflator.inflate(1)[0],e+=s;while(s===255);return e+1}}class ov{constructor(){this._cachedQuantTables=[],this._cachedHuffmanTables=[],this._segments=[]}decodeRect(e,s,n,a,i,r,l){for(;;){let v=this._readSegment(i);if(v===null)return!1;if(this._segments.push(v),v[1]===217)break}let d=[],o=[];for(let v of this._segments){let x=v[1];x===196?d.push(v):x===219&&o.push(v)}const u=this._segments.findIndex(v=>v[1]==192||v[1]==194);if(u==-1)throw new Error("Illegal JPEG image without SOF");o.length===0&&this._segments.splice(u+1,0,...this._cachedQuantTables),d.length===0&&this._segments.splice(u+1,0,...this._cachedHuffmanTables);let _=0;for(let v of this._segments)_+=v.length;let p=new Uint8Array(_);_=0;for(let v of this._segments)p.set(v,_),_+=v.length;return r.imageRect(e,s,n,a,"image/jpeg",p),d.length!==0&&(this._cachedHuffmanTables=d),o.length!==0&&(this._cachedQuantTables=o),this._segments=[],!0}_readSegment(e){if(e.rQwait("JPEG",2))return null;let s=e.rQshift8();if(s!=255)throw new Error("Illegal JPEG marker received (byte: "+s+")");let n=e.rQshift8();if(n>=208&&n<=217||n==1)return new Uint8Array([s,n]);if(e.rQwait("JPEG",2,2))return null;let a=e.rQshift16();if(a<2)throw new Error("Illegal JPEG length received (length: "+a+")");if(e.rQwait("JPEG",a-2,4))return null;let i=0;if(n===218){if(e.rQwait("JPEG",a-2+2,4))return null;let l=e.rQlen(),d=e.rQpeekBytes(l,!1);for(;;){let o=d.indexOf(255,a-2+i);if(o===-1||o===l-1)return e.rQwait("JPEG",1/0,4),null;if(d.at(o+1)===0||d.at(o+1)>=208&&d.at(o+1)<=215){i=o+2-(a-2);continue}i=o-(a-2);break}}let r=new Uint8Array(2+a+i);return r[0]=s,r[1]=n,r[2]=a>>8,r[3]=a,r.set(e.rQshiftBytes(a-2+i,!1),4),r}}class cv{constructor(e){this._data=e,this._index=0,this.profileIdc=null,this.constraintSet=null,this.levelIdc=null}_getStartSequenceLen(e){let s=this._data;return s[e+0]==0&&s[e+1]==0&&s[e+2]==0&&s[e+3]==1?4:s[e+0]==0&&s[e+1]==0&&s[e+2]==1?3:0}_indexOfNextNalUnit(e){let s=this._data;for(let n=e;n<s.length;++n)if(this._getStartSequenceLen(n)!=0)return n;return-1}_parseSps(e){this.profileIdc=this._data[e],this.constraintSet=this._data[e+1],this.levelIdc=this._data[e+2]}_parseNalUnit(e){const s=this._data[e];if(s&128)throw new Error("H264 parsing sanity check failed, forbidden zero bit is set");const n=s&31;switch(n){case 1:return{slice:!0};case 5:return{slice:!0,key:!0};case 6:return{};case 7:return this._parseSps(e+1),{};case 8:return{};default:jt("Unhandled unit type: ",n);break}return{}}parse(){const e=this._index;let s=!1;for(;this._index<this._data.length;){const n=this._getStartSequenceLen(this._index);if(n==0)throw new Error("Invalid start sequence in bit stream");const{slice:a,key:i}=this._parseNalUnit(this._index+n);let r=this._indexOfNextNalUnit(this._index+n);if(r==-1?this._index=this._data.length:this._index=r,i&&(s=!0),a)break}return e===this._index?null:{frame:this._data.subarray(e,this._index),key:s}}}class dv{constructor(e,s){this.lastUsed=0,this._width=e,this._height=s,this._profileIdc=null,this._constraintSet=null,this._levelIdc=null,this._decoder=null,this._pendingFrames=[]}_handleFrame(e){let s=this._pendingFrames.shift();if(s===void 0)throw new Error("Pending frame queue empty when receiving frame from decoder");if(s.timestamp!=e.timestamp)throw new Error("Video frame timestamp mismatch. Expected "+e.timestamp+" but but got "+s.timestamp);s.frame=e,s.ready=!0,s.resolve(),s.keep||e.close()}_handleError(e){throw new Error("Failed to decode frame: "+e.message)}_configureDecoder(e,s,n){(this._decoder===null||this._decoder.state==="closed")&&(this._decoder=new VideoDecoder({output:i=>this._handleFrame(i),error:i=>this._handleError(i)}));const a="avc1."+e.toString(16).padStart(2,"0")+s.toString(16).padStart(2,"0")+n.toString(16).padStart(2,"0");this._decoder.configure({codec:a,codedWidth:this._width,codedHeight:this._height,optimizeForLatency:!0})}_preparePendingFrame(e){let s={timestamp:e,promise:null,resolve:null,frame:null,ready:!1,keep:!1};return s.promise=new Promise(n=>{s.resolve=n}),this._pendingFrames.push(s),s}decode(e){let s=new cv(e),n=null,a=Math.round(window.performance.now()*1e3);for(;;){let i=s.parse();if(i===null)break;if(s.profileIdc!==null&&(self._profileIdc=s.profileIdc,self._constraintSet=s.constraintSet,self._levelIdc=s.levelIdc),this._decoder===null||this._decoder.state!=="configured"){if(!i.key){jt("Missing key frame. Can't decode until one arrives");continue}if(self._profileIdc===null){jt("Cannot config decoder. Have not received SPS and PPS yet.");continue}this._configureDecoder(self._profileIdc,self._constraintSet,self._levelIdc)}n=this._preparePendingFrame(a);const r=new EncodedVideoChunk({timestamp:a,type:i.key?"key":"delta",data:i.frame});try{this._decoder.decode(r)}catch(l){jt("Failed to decode:",l)}}return n!==null&&(n.keep=!0),n}}class uv{constructor(){this._tick=0,this._contexts={}}_contextId(e,s,n,a){return[e,s,n,a].join(",")}_findOldestContextId(){let e=Number.MAX_VALUE,s;for(const[n,a]of Object.entries(this._contexts))a.lastUsed<e&&(e=a.lastUsed,s=n);return s}_createContext(e,s,n,a){if(Object.keys(this._contexts).length>=64){let l=this._findOldestContextId();delete this._contexts[l]}let r=new dv(n,a);return this._contexts[this._contextId(e,s,n,a)]=r,r}_getContext(e,s,n,a){let i=this._contexts[this._contextId(e,s,n,a)];return i!==void 0?i:this._createContext(e,s,n,a)}_resetContext(e,s,n,a){delete this._contexts[this._contextId(e,s,n,a)]}_resetAllContexts(){this._contexts={}}decodeRect(e,s,n,a,i,r,l){if(i.rQwait("h264 header",8))return!1;const u=i.rQshift32(),_=i.rQshift32();if(i.rQwait("h264 payload",u,8))return!1;_&2?this._resetAllContexts():_&1&&this._resetContext(e,s,n,a);let p=this._getContext(e,s,n,a);if(p.lastUsed=this._tick++,u!==0){let v=i.rQshiftBytes(u,!1),x=p.decode(v);x!==null&&r.videoFrame(e,s,n,a,x)}return!0}}const hv=3,fv="rgb(40, 40, 40)",Po=17,Bo=50,Do=19,xa=75,dn=50,_v=1e3,vv=50,Ro=1,di=2,Io=6,Qo=16,ur=19,zo=22,No=30,Uo=113,Ho=129,Oo=256,Rs=1,Vo=1<<24,_i=1<<25,Go=1<<26,Sa=1<<27,vi=1<<28;class De extends sd{constructor(e,s,n){if(!e)throw new Error("Must specify target");if(!s)throw new Error("Must specify URL, WebSocket or RTCDataChannel");window.isSecureContext||ot("noVNC requires a secure context (TLS). Expect crashes!"),super(),this._target=e,typeof s=="string"?this._url=s:(this._url=null,this._rawChannel=s),n=n||{},this._rfbCredentials=n.credentials||{},this._shared="shared"in n?!!n.shared:!0,this._repeaterID=n.repeaterID||"",this._wsProtocols=n.wsProtocols||[],this._rfbConnectionState="",this._rfbInitState="",this._rfbAuthScheme=-1,this._rfbCleanDisconnect=!0,this._rfbRSAAESAuthenticationState=null,this._rfbVersion=0,this._rfbMaxVersion=3.8,this._rfbTightVNC=!1,this._rfbVeNCryptState=0,this._rfbXvpVer=0,this._fbWidth=0,this._fbHeight=0,this._fbName="",this._capabilities={power:!1},this._supportsFence=!1,this._supportsContinuousUpdates=!1,this._enabledContinuousUpdates=!1,this._supportsSetDesktopSize=!1,this._screenID=0,this._screenFlags=0,this._pendingRemoteResize=!1,this._lastResize=0,this._qemuExtKeyEventSupported=!1,this._extendedPointerEventSupported=!1,this._clipboardText=null,this._clipboardServerCapabilitiesActions={},this._clipboardServerCapabilitiesFormats={},this._sock=null,this._display=null,this._flushing=!1,this._keyboard=null,this._gestures=null,this._resizeObserver=null,this._disconnTimer=null,this._resizeTimeout=null,this._mouseMoveTimer=null,this._decoders={},this._FBU={rects:0,x:0,y:0,width:0,height:0,encoding:null},this._mousePos={},this._mouseButtonMask=0,this._mouseLastMoveTime=0,this._viewportDragging=!1,this._viewportDragPos={},this._viewportHasMoved=!1,this._accumulatedWheelDeltaX=0,this._accumulatedWheelDeltaY=0,this._gestureLastTapTime=null,this._gestureFirstDoubleTapEv=null,this._gestureLastMagnitudeX=0,this._gestureLastMagnitudeY=0,this._eventHandlers={focusCanvas:this._focusCanvas.bind(this),handleResize:this._handleResize.bind(this),handleMouse:this._handleMouse.bind(this),handleWheel:this._handleWheel.bind(this),handleGesture:this._handleGesture.bind(this),handleRSAAESCredentialsRequired:this._handleRSAAESCredentialsRequired.bind(this),handleRSAAESServerVerification:this._handleRSAAESServerVerification.bind(this)},Ke(">> RFB.constructor"),this._screen=document.createElement("div"),this._screen.style.display="flex",this._screen.style.width="100%",this._screen.style.height="100%",this._screen.style.overflow="auto",this._screen.style.background=fv,this._canvas=document.createElement("canvas"),this._canvas.style.margin="auto",this._canvas.style.outline="none",this._canvas.width=0,this._canvas.height=0,this._canvas.tabIndex=-1,this._screen.appendChild(this._canvas),this._cursor=new U_,this._cursorImage=De.cursors.none,this._decoders[Fe.encodingRaw]=new tv,this._decoders[Fe.encodingCopyRect]=new sv,this._decoders[Fe.encodingRRE]=new nv,this._decoders[Fe.encodingHextile]=new av,this._decoders[Fe.encodingZlib]=new iv,this._decoders[Fe.encodingTight]=new Ad,this._decoders[Fe.encodingTightPNG]=new rv,this._decoders[Fe.encodingZRLE]=new lv,this._decoders[Fe.encodingJPEG]=new ov,this._decoders[Fe.encodingH264]=new uv;try{this._display=new ff(this._canvas)}catch(a){throw ot("Display exception: "+a),a}this._keyboard=new D_(this._canvas),this._keyboard.onkeyevent=this._handleKeyEvent.bind(this),this._remoteCapsLock=null,this._remoteNumLock=null,this._gestures=new N_,this._sock=new H_,this._sock.on("open",this._socketOpen.bind(this)),this._sock.on("close",this._socketClose.bind(this)),this._sock.on("message",this._handleMessage.bind(this)),this._sock.on("error",this._socketError.bind(this)),this._expectedClientWidth=null,this._expectedClientHeight=null,this._resizeObserver=new ResizeObserver(this._eventHandlers.handleResize),this._updateConnectionState("connecting"),Ke("<< RFB.constructor"),this.dragViewport=!1,this.focusOnClick=!0,this._viewOnly=!1,this._clipViewport=!1,this._clippingViewport=!1,this._scaleViewport=!1,this._resizeSession=!1,this._showDotCursor=!1,this._qualityLevel=6,this._compressionLevel=2}get viewOnly(){return this._viewOnly}set viewOnly(e){this._viewOnly=e,(this._rfbConnectionState==="connecting"||this._rfbConnectionState==="connected")&&(e?this._keyboard.ungrab():this._keyboard.grab())}get capabilities(){return this._capabilities}get clippingViewport(){return this._clippingViewport}_setClippingViewport(e){e!==this._clippingViewport&&(this._clippingViewport=e,this.dispatchEvent(new CustomEvent("clippingviewport",{detail:this._clippingViewport})))}get touchButton(){return 0}set touchButton(e){jt("Using old API!")}get clipViewport(){return this._clipViewport}set clipViewport(e){this._clipViewport=e,this._updateClip()}get scaleViewport(){return this._scaleViewport}set scaleViewport(e){this._scaleViewport=e,e&&this._clipViewport&&this._updateClip(),this._updateScale(),!e&&this._clipViewport&&this._updateClip()}get resizeSession(){return this._resizeSession}set resizeSession(e){this._resizeSession=e,e&&this._requestRemoteResize()}get showDotCursor(){return this._showDotCursor}set showDotCursor(e){this._showDotCursor=e,this._refreshCursor()}get background(){return this._screen.style.background}set background(e){this._screen.style.background=e}get qualityLevel(){return this._qualityLevel}set qualityLevel(e){if(!Number.isInteger(e)||e<0||e>9){ot("qualityLevel must be an integer between 0 and 9");return}this._qualityLevel!==e&&(this._qualityLevel=e,this._rfbConnectionState==="connected"&&this._sendEncodings())}get compressionLevel(){return this._compressionLevel}set compressionLevel(e){if(!Number.isInteger(e)||e<0||e>9){ot("compressionLevel must be an integer between 0 and 9");return}this._compressionLevel!==e&&(this._compressionLevel=e,this._rfbConnectionState==="connected"&&this._sendEncodings())}disconnect(){this._updateConnectionState("disconnecting"),this._sock.off("error"),this._sock.off("message"),this._sock.off("open"),this._rfbRSAAESAuthenticationState!==null&&this._rfbRSAAESAuthenticationState.disconnect()}approveServer(){this._rfbRSAAESAuthenticationState!==null&&this._rfbRSAAESAuthenticationState.approveServer()}sendCredentials(e){this._rfbCredentials=e,this._resumeAuthentication()}sendCtrlAltDel(){this._rfbConnectionState!=="connected"||this._viewOnly||(Vt("Sending Ctrl-Alt-Del"),this.sendKey(m.XK_Control_L,"ControlLeft",!0),this.sendKey(m.XK_Alt_L,"AltLeft",!0),this.sendKey(m.XK_Delete,"Delete",!0),this.sendKey(m.XK_Delete,"Delete",!1),this.sendKey(m.XK_Alt_L,"AltLeft",!1),this.sendKey(m.XK_Control_L,"ControlLeft",!1))}machineShutdown(){this._xvpOp(1,2)}machineReboot(){this._xvpOp(1,3)}machineReset(){this._xvpOp(1,4)}sendKey(e,s,n){if(this._rfbConnectionState!=="connected"||this._viewOnly)return;if(n===void 0){this.sendKey(e,s,!0),this.sendKey(e,s,!1);return}const a=O_[s];if(this._qemuExtKeyEventSupported&&a)e=e||0,Vt("Sending key ("+(n?"down":"up")+"): keysym "+e+", scancode "+a),De.messages.QEMUExtendedKeyEvent(this._sock,e,n,a);else{if(!e)return;Vt("Sending keysym ("+(n?"down":"up")+"): "+e),De.messages.keyEvent(this._sock,e,n?1:0)}}focus(e){this._canvas.focus(e)}blur(){this._canvas.blur()}clipboardPasteFrom(e){if(!(this._rfbConnectionState!=="connected"||this._viewOnly))if(this._clipboardServerCapabilitiesFormats[Rs]&&this._clipboardServerCapabilitiesActions[Sa])this._clipboardText=e,De.messages.extendedClipboardNotify(this._sock,[Rs]);else{let s,n,a;s=0;for(let i of e)s++;a=new Uint8Array(s),n=0;for(let i of e){let r=i.codePointAt(0);r>255&&(r=63),a[n++]=r}De.messages.clientCutText(this._sock,a)}}getImageData(){return this._display.getImageData()}toDataURL(e,s){return this._display.toDataURL(e,s)}toBlob(e,s,n){return this._display.toBlob(e,s,n)}_connect(){if(Ke(">> RFB.connect"),this._url)Vt(`connecting to ${this._url}`),this._sock.open(this._url,this._wsProtocols);else{if(Vt(`attaching ${this._rawChannel} to Websock`),this._sock.attach(this._rawChannel),this._sock.readyState==="closed")throw Error("Cannot use already closed WebSocket/RTCDataChannel");this._sock.readyState==="open"&&this._socketOpen()}this._target.appendChild(this._screen),this._gestures.attach(this._canvas),this._cursor.attach(this._canvas),this._refreshCursor(),this._resizeObserver.observe(this._screen),this._canvas.addEventListener("mousedown",this._eventHandlers.focusCanvas),this._canvas.addEventListener("touchstart",this._eventHandlers.focusCanvas),this._canvas.addEventListener("mousedown",this._eventHandlers.handleMouse),this._canvas.addEventListener("mouseup",this._eventHandlers.handleMouse),this._canvas.addEventListener("mousemove",this._eventHandlers.handleMouse),this._canvas.addEventListener("click",this._eventHandlers.handleMouse),this._canvas.addEventListener("contextmenu",this._eventHandlers.handleMouse),this._canvas.addEventListener("wheel",this._eventHandlers.handleWheel),this._canvas.addEventListener("gesturestart",this._eventHandlers.handleGesture),this._canvas.addEventListener("gesturemove",this._eventHandlers.handleGesture),this._canvas.addEventListener("gestureend",this._eventHandlers.handleGesture),Ke("<< RFB.connect")}_disconnect(){Ke(">> RFB.disconnect"),this._cursor.detach(),this._canvas.removeEventListener("gesturestart",this._eventHandlers.handleGesture),this._canvas.removeEventListener("gesturemove",this._eventHandlers.handleGesture),this._canvas.removeEventListener("gestureend",this._eventHandlers.handleGesture),this._canvas.removeEventListener("wheel",this._eventHandlers.handleWheel),this._canvas.removeEventListener("mousedown",this._eventHandlers.handleMouse),this._canvas.removeEventListener("mouseup",this._eventHandlers.handleMouse),this._canvas.removeEventListener("mousemove",this._eventHandlers.handleMouse),this._canvas.removeEventListener("click",this._eventHandlers.handleMouse),this._canvas.removeEventListener("contextmenu",this._eventHandlers.handleMouse),this._canvas.removeEventListener("mousedown",this._eventHandlers.focusCanvas),this._canvas.removeEventListener("touchstart",this._eventHandlers.focusCanvas),this._resizeObserver.disconnect(),this._keyboard.ungrab(),this._gestures.detach(),this._sock.close();try{this._target.removeChild(this._screen)}catch(e){if(e.name!=="NotFoundError")throw e}clearTimeout(this._resizeTimeout),clearTimeout(this._mouseMoveTimer),Ke("<< RFB.disconnect")}_socketOpen(){this._rfbConnectionState==="connecting"&&this._rfbInitState===""?(this._rfbInitState="ProtocolVersion",Ke("Starting VNC handshake")):this._fail("Unexpected server connection while "+this._rfbConnectionState)}_socketClose(e){Ke("WebSocket on-close event");let s="";switch(e.code&&(s="(code: "+e.code,e.reason&&(s+=", reason: "+e.reason),s+=")"),this._rfbConnectionState){case"connecting":this._fail("Connection closed "+s);break;case"connected":this._updateConnectionState("disconnecting"),this._updateConnectionState("disconnected");break;case"disconnecting":this._updateConnectionState("disconnected");break;case"disconnected":this._fail("Unexpected server disconnect when already disconnected "+s);break;default:this._fail("Unexpected server disconnect before connecting "+s);break}this._sock.off("close"),this._rawChannel=null}_socketError(e){jt("WebSocket on-error event")}_focusCanvas(e){this.focusOnClick&&this.focus({preventScroll:!0})}_setDesktopName(e){this._fbName=e,this.dispatchEvent(new CustomEvent("desktopname",{detail:{name:this._fbName}}))}_saveExpectedClientSize(){this._expectedClientWidth=this._screen.clientWidth,this._expectedClientHeight=this._screen.clientHeight}_currentClientSize(){return[this._screen.clientWidth,this._screen.clientHeight]}_clientHasExpectedSize(){const[e,s]=this._currentClientSize();return e==this._expectedClientWidth&&s==this._expectedClientHeight}_handleResize(){this._clientHasExpectedSize()||(window.requestAnimationFrame(()=>{this._updateClip(),this._updateScale(),this._saveExpectedClientSize()}),this._requestRemoteResize())}_updateClip(){const e=this._display.clipViewport;let s=this._clipViewport;if(this._scaleViewport&&(s=!1),e!==s&&(this._display.clipViewport=s),s){const n=this._screenSize();this._display.viewportChangeSize(n.w,n.h),this._fixScrollbars(),this._setClippingViewport(n.w<this._display.width||n.h<this._display.height)}else this._setClippingViewport(!1);e!==s&&this._saveExpectedClientSize()}_updateScale(){if(!this._scaleViewport)this._display.scale=1;else{const e=this._screenSize();this._display.autoscale(e.w,e.h)}this._fixScrollbars()}_requestRemoteResize(){if(!this._resizeSession||this._viewOnly||!this._supportsSetDesktopSize||this._pendingRemoteResize)return;if(Date.now()-this._lastResize<100){clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(this._requestRemoteResize.bind(this),100-(Date.now()-this._lastResize));return}this._resizeTimeout=null;const e=this._screenSize();e.w===this._fbWidth&&e.h===this._fbHeight||(this._pendingRemoteResize=!0,this._lastResize=Date.now(),De.messages.setDesktopSize(this._sock,Math.floor(e.w),Math.floor(e.h),this._screenID,this._screenFlags),Ke("Requested new desktop size: "+e.w+"x"+e.h))}_screenSize(){let e=this._screen.getBoundingClientRect();return{w:e.width,h:e.height}}_fixScrollbars(){const e=this._screen.style.overflow;this._screen.style.overflow="hidden",this._screen.getBoundingClientRect(),this._screen.style.overflow=e}_updateConnectionState(e){const s=this._rfbConnectionState;if(e===s){Ke("Already in state '"+e+"', ignoring");return}if(s==="disconnected"){ot("Tried changing state of a disconnected RFB object");return}switch(e){case"connected":if(s!=="connecting"){ot("Bad transition to connected state, previous connection state: "+s);return}break;case"disconnected":if(s!=="disconnecting"){ot("Bad transition to disconnected state, previous connection state: "+s);return}break;case"connecting":if(s!==""){ot("Bad transition to connecting state, previous connection state: "+s);return}break;case"disconnecting":if(s!=="connected"&&s!=="connecting"){ot("Bad transition to disconnecting state, previous connection state: "+s);return}break;default:ot("Unknown connection state: "+e);return}switch(this._rfbConnectionState=e,Ke("New state '"+e+"', was '"+s+"'."),this._disconnTimer&&e!=="disconnecting"&&(Ke("Clearing disconnect timer"),clearTimeout(this._disconnTimer),this._disconnTimer=null,this._sock.off("close")),e){case"connecting":this._connect();break;case"connected":this.dispatchEvent(new CustomEvent("connect",{detail:{}}));break;case"disconnecting":this._disconnect(),this._disconnTimer=setTimeout(()=>{ot("Disconnection timed out."),this._updateConnectionState("disconnected")},hv*1e3);break;case"disconnected":this.dispatchEvent(new CustomEvent("disconnect",{detail:{clean:this._rfbCleanDisconnect}}));break}}_fail(e){switch(this._rfbConnectionState){case"disconnecting":ot("Failed when disconnecting: "+e);break;case"connected":ot("Failed while connected: "+e);break;case"connecting":ot("Failed when connecting: "+e);break;default:ot("RFB failure: "+e);break}return this._rfbCleanDisconnect=!1,this._updateConnectionState("disconnecting"),this._updateConnectionState("disconnected"),!1}_setCapability(e,s){this._capabilities[e]=s,this.dispatchEvent(new CustomEvent("capabilities",{detail:{capabilities:this._capabilities}}))}_handleMessage(){if(this._sock.rQwait("message",1)){jt("handleMessage called on an empty receive queue");return}switch(this._rfbConnectionState){case"disconnected":ot("Got data while disconnected");break;case"connected":for(;!(this._flushing||!this._normalMsg()||this._sock.rQwait("message",1)););break;case"connecting":for(;this._rfbConnectionState==="connecting"&&this._initMsg(););break;default:ot("Got data while in an invalid state");break}}_handleKeyEvent(e,s,n,a,i){s=="CapsLock"&&n&&(this._remoteCapsLock=null),this._remoteCapsLock!==null&&i!==null&&this._remoteCapsLock!==i&&n&&(Ke("Fixing remote caps lock"),this.sendKey(m.XK_Caps_Lock,"CapsLock",!0),this.sendKey(m.XK_Caps_Lock,"CapsLock",!1),this._remoteCapsLock=null),s=="NumLock"&&n&&(this._remoteNumLock=null),this._remoteNumLock!==null&&a!==null&&this._remoteNumLock!==a&&n&&(Ke("Fixing remote num lock"),this.sendKey(m.XK_Num_Lock,"NumLock",!0),this.sendKey(m.XK_Num_Lock,"NumLock",!1),this._remoteNumLock=null),this.sendKey(e,s,n)}static _convertButtonMask(e){const s={0:1,1:4,2:2,3:128,4:256};let n=0;for(let a=0;a<5;a++)e&1<<a&&(n|=s[a]);return n}_handleMouse(e){if(e.type==="click"&&e.target!==this._canvas||(e.stopPropagation(),e.preventDefault(),e.type==="click"||e.type==="contextmenu"))return;let s=_a(e.clientX,e.clientY,this._canvas),n=De._convertButtonMask(e.buttons),a=e.type=="mousedown";switch(e.type){case"mousedown":case"mouseup":if(this.dragViewport)if(a&&!this._viewportDragging){this._viewportDragging=!0,this._viewportDragPos={x:s.x,y:s.y},this._viewportHasMoved=!1,this._flushMouseMoveTimer(s.x,s.y),this._mouseButtonMask=n;break}else{if(this._viewportDragging=!1,this._viewportHasMoved){this._mouseButtonMask=n;break}this._sendMouse(s.x,s.y,this._mouseButtonMask)}a&&hf(this._canvas),this._handleMouseButton(s.x,s.y,n);break;case"mousemove":if(this._viewportDragging){const i=this._viewportDragPos.x-s.x,r=this._viewportDragPos.y-s.y;(this._viewportHasMoved||Math.abs(i)>ei||Math.abs(r)>ei)&&(this._viewportHasMoved=!0,this._viewportDragPos={x:s.x,y:s.y},this._display.viewportChangePos(i,r));break}this._handleMouseMove(s.x,s.y);break}}_handleMouseButton(e,s,n){this._flushMouseMoveTimer(e,s),this._mouseButtonMask=n,this._sendMouse(e,s,this._mouseButtonMask)}_handleMouseMove(e,s){if(this._mousePos={x:e,y:s},this._mouseMoveTimer==null){const n=Date.now()-this._mouseLastMoveTime;n>Po?(this._sendMouse(e,s,this._mouseButtonMask),this._mouseLastMoveTime=Date.now()):this._mouseMoveTimer=setTimeout(()=>{this._handleDelayedMouseMove()},Po-n)}}_handleDelayedMouseMove(){this._mouseMoveTimer=null,this._sendMouse(this._mousePos.x,this._mousePos.y,this._mouseButtonMask),this._mouseLastMoveTime=Date.now()}_sendMouse(e,s,n){if(this._rfbConnectionState!=="connected"||this._viewOnly)return;if(n&32768)throw new Error("Illegal mouse button mask (mask: "+n+")");let a=n&32640;this._extendedPointerEventSupported&&a?De.messages.extendedPointerEvent(this._sock,this._display.absX(e),this._display.absY(s),n):De.messages.pointerEvent(this._sock,this._display.absX(e),this._display.absY(s),n)}_handleWheel(e){if(this._rfbConnectionState!=="connected"||this._viewOnly)return;e.stopPropagation(),e.preventDefault();let s=_a(e.clientX,e.clientY,this._canvas),n=De._convertButtonMask(e.buttons),a=e.deltaX,i=e.deltaY;e.deltaMode!==0&&(a*=Do,i*=Do),this._accumulatedWheelDeltaX+=a,this._accumulatedWheelDeltaY+=i,Math.abs(this._accumulatedWheelDeltaX)>=Bo&&(this._accumulatedWheelDeltaX<0?(this._handleMouseButton(s.x,s.y,n|32),this._handleMouseButton(s.x,s.y,n)):this._accumulatedWheelDeltaX>0&&(this._handleMouseButton(s.x,s.y,n|64),this._handleMouseButton(s.x,s.y,n)),this._accumulatedWheelDeltaX=0),Math.abs(this._accumulatedWheelDeltaY)>=Bo&&(this._accumulatedWheelDeltaY<0?(this._handleMouseButton(s.x,s.y,n|8),this._handleMouseButton(s.x,s.y,n)):this._accumulatedWheelDeltaY>0&&(this._handleMouseButton(s.x,s.y,n|16),this._handleMouseButton(s.x,s.y,n)),this._accumulatedWheelDeltaY=0)}_fakeMouseMove(e,s,n){this._handleMouseMove(s,n),this._cursor.move(e.detail.clientX,e.detail.clientY)}_handleTapEvent(e,s){let n=_a(e.detail.clientX,e.detail.clientY,this._canvas);if(this._gestureLastTapTime!==null&&Date.now()-this._gestureLastTapTime<_v&&this._gestureFirstDoubleTapEv.detail.type===e.detail.type){let a=this._gestureFirstDoubleTapEv.detail.clientX-e.detail.clientX,i=this._gestureFirstDoubleTapEv.detail.clientY-e.detail.clientY;Math.hypot(a,i)<vv?n=_a(this._gestureFirstDoubleTapEv.detail.clientX,this._gestureFirstDoubleTapEv.detail.clientY,this._canvas):this._gestureFirstDoubleTapEv=e}else this._gestureFirstDoubleTapEv=e;this._gestureLastTapTime=Date.now(),this._fakeMouseMove(this._gestureFirstDoubleTapEv,n.x,n.y),this._handleMouseButton(n.x,n.y,s),this._handleMouseButton(n.x,n.y,0)}_handleGesture(e){let s,n=_a(e.detail.clientX,e.detail.clientY,this._canvas);switch(e.type){case"gesturestart":switch(e.detail.type){case"onetap":this._handleTapEvent(e,1);break;case"twotap":this._handleTapEvent(e,4);break;case"threetap":this._handleTapEvent(e,2);break;case"drag":this.dragViewport?(this._viewportHasMoved=!1,this._viewportDragging=!0,this._viewportDragPos={x:n.x,y:n.y}):(this._fakeMouseMove(e,n.x,n.y),this._handleMouseButton(n.x,n.y,1));break;case"longpress":this.dragViewport?(this._viewportHasMoved=!1,this._viewportDragPos={x:n.x,y:n.y}):(this._fakeMouseMove(e,n.x,n.y),this._handleMouseButton(n.x,n.y,4));break;case"twodrag":this._gestureLastMagnitudeX=e.detail.magnitudeX,this._gestureLastMagnitudeY=e.detail.magnitudeY,this._fakeMouseMove(e,n.x,n.y);break;case"pinch":this._gestureLastMagnitudeX=Math.hypot(e.detail.magnitudeX,e.detail.magnitudeY),this._fakeMouseMove(e,n.x,n.y);break}break;case"gesturemove":switch(e.detail.type){case"onetap":case"twotap":case"threetap":break;case"drag":case"longpress":if(this.dragViewport){this._viewportDragging=!0;const a=this._viewportDragPos.x-n.x,i=this._viewportDragPos.y-n.y;(this._viewportHasMoved||Math.abs(a)>ei||Math.abs(i)>ei)&&(this._viewportHasMoved=!0,this._viewportDragPos={x:n.x,y:n.y},this._display.viewportChangePos(a,i))}else this._fakeMouseMove(e,n.x,n.y);break;case"twodrag":for(this._fakeMouseMove(e,n.x,n.y);e.detail.magnitudeY-this._gestureLastMagnitudeY>dn;)this._handleMouseButton(n.x,n.y,8),this._handleMouseButton(n.x,n.y,0),this._gestureLastMagnitudeY+=dn;for(;e.detail.magnitudeY-this._gestureLastMagnitudeY<-dn;)this._handleMouseButton(n.x,n.y,16),this._handleMouseButton(n.x,n.y,0),this._gestureLastMagnitudeY-=dn;for(;e.detail.magnitudeX-this._gestureLastMagnitudeX>dn;)this._handleMouseButton(n.x,n.y,32),this._handleMouseButton(n.x,n.y,0),this._gestureLastMagnitudeX+=dn;for(;e.detail.magnitudeX-this._gestureLastMagnitudeX<-dn;)this._handleMouseButton(n.x,n.y,64),this._handleMouseButton(n.x,n.y,0),this._gestureLastMagnitudeX-=dn;break;case"pinch":if(this._fakeMouseMove(e,n.x,n.y),s=Math.hypot(e.detail.magnitudeX,e.detail.magnitudeY),Math.abs(s-this._gestureLastMagnitudeX)>xa){for(this._handleKeyEvent(m.XK_Control_L,"ControlLeft",!0);s-this._gestureLastMagnitudeX>xa;)this._handleMouseButton(n.x,n.y,8),this._handleMouseButton(n.x,n.y,0),this._gestureLastMagnitudeX+=xa;for(;s-this._gestureLastMagnitudeX<-xa;)this._handleMouseButton(n.x,n.y,16),this._handleMouseButton(n.x,n.y,0),this._gestureLastMagnitudeX-=xa}this._handleKeyEvent(m.XK_Control_L,"ControlLeft",!1);break}break;case"gestureend":switch(e.detail.type){case"onetap":case"twotap":case"threetap":case"pinch":case"twodrag":break;case"drag":this.dragViewport?this._viewportDragging=!1:(this._fakeMouseMove(e,n.x,n.y),this._handleMouseButton(n.x,n.y,0));break;case"longpress":if(this._viewportHasMoved)break;this.dragViewport&&!this._viewportHasMoved?(this._fakeMouseMove(e,n.x,n.y),this._handleMouseButton(n.x,n.y,4),this._handleMouseButton(n.x,n.y,0),this._viewportDragging=!1):(this._fakeMouseMove(e,n.x,n.y),this._handleMouseButton(n.x,n.y,0));break}break}}_flushMouseMoveTimer(e,s){this._mouseMoveTimer!==null&&(clearTimeout(this._mouseMoveTimer),this._mouseMoveTimer=null,this._sendMouse(e,s,this._mouseButtonMask))}_negotiateProtocolVersion(){if(this._sock.rQwait("version",12))return!1;const e=this._sock.rQshiftStr(12).substr(4,7);Vt("Server ProtocolVersion: "+e);let s=0;switch(e){case"000.000":s=1;break;case"003.003":case"003.006":this._rfbVersion=3.3;break;case"003.007":this._rfbVersion=3.7;break;case"003.008":case"003.889":case"004.000":case"004.001":case"005.000":this._rfbVersion=3.8;break;default:return this._fail("Invalid server version "+e)}if(s){let a="ID:"+this._repeaterID;for(;a.length<250;)a+="\0";return this._sock.sQpushString(a),this._sock.flush(),!0}this._rfbVersion>this._rfbMaxVersion&&(this._rfbVersion=this._rfbMaxVersion);const n="00"+parseInt(this._rfbVersion,10)+".00"+this._rfbVersion*10%10;this._sock.sQpushString("RFB "+n+`
|
|
3
|
+
`),this._sock.flush(),Ke("Sent ProtocolVersion: "+n),this._rfbInitState="Security"}_isSupportedSecurityType(e){return[Ro,di,Io,Qo,ur,zo,No,Uo,Oo].includes(e)}_negotiateSecurity(){if(this._rfbVersion>=3.7){const e=this._sock.rQshift8();if(this._sock.rQwait("security type",e,1))return!1;if(e===0)return this._rfbInitState="SecurityReason",this._securityContext="no security types",this._securityStatus=1,!0;const s=this._sock.rQshiftBytes(e);Ke("Server security types: "+s),this._rfbAuthScheme=-1;for(let n of s)if(this._isSupportedSecurityType(n)){this._rfbAuthScheme=n;break}if(this._rfbAuthScheme===-1)return this._fail("Unsupported security types (types: "+s+")");this._sock.sQpush8(this._rfbAuthScheme),this._sock.flush()}else{if(this._sock.rQwait("security scheme",4))return!1;if(this._rfbAuthScheme=this._sock.rQshift32(),this._rfbAuthScheme==0)return this._rfbInitState="SecurityReason",this._securityContext="authentication scheme",this._securityStatus=1,!0}return this._rfbInitState="Authentication",Ke("Authenticating using scheme: "+this._rfbAuthScheme),!0}_handleSecurityReason(){if(this._sock.rQwait("reason length",4))return!1;const e=this._sock.rQshift32();let s="";if(e>0){if(this._sock.rQwait("reason",e,4))return!1;s=this._sock.rQshiftStr(e)}return s!==""?(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:this._securityStatus,reason:s}})),this._fail("Security negotiation failed on "+this._securityContext+" (reason: "+s+")")):(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:this._securityStatus}})),this._fail("Security negotiation failed on "+this._securityContext))}_negotiateXvpAuth(){return this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0||this._rfbCredentials.target===void 0?(this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password","target"]}})),!1):(this._sock.sQpush8(this._rfbCredentials.username.length),this._sock.sQpush8(this._rfbCredentials.target.length),this._sock.sQpushString(this._rfbCredentials.username),this._sock.sQpushString(this._rfbCredentials.target),this._sock.flush(),this._rfbAuthScheme=di,this._negotiateAuthentication())}_negotiateVeNCryptAuth(){if(this._rfbVeNCryptState==0){if(this._sock.rQwait("vencrypt version",2))return!1;const e=this._sock.rQshift8(),s=this._sock.rQshift8();if(!(e==0&&s==2))return this._fail("Unsupported VeNCrypt version "+e+"."+s);this._sock.sQpush8(0),this._sock.sQpush8(2),this._sock.flush(),this._rfbVeNCryptState=1}if(this._rfbVeNCryptState==1){if(this._sock.rQwait("vencrypt ack",1))return!1;const e=this._sock.rQshift8();if(e!=0)return this._fail("VeNCrypt failure "+e);this._rfbVeNCryptState=2}if(this._rfbVeNCryptState==2){if(this._sock.rQwait("vencrypt subtypes length",1))return!1;const e=this._sock.rQshift8();if(e<1)return this._fail("VeNCrypt subtypes empty");this._rfbVeNCryptSubtypesLength=e,this._rfbVeNCryptState=3}if(this._rfbVeNCryptState==3){if(this._sock.rQwait("vencrypt subtypes",4*this._rfbVeNCryptSubtypesLength))return!1;const e=[];for(let s=0;s<this._rfbVeNCryptSubtypesLength;s++)e.push(this._sock.rQshift32());this._rfbAuthScheme=-1;for(let s of e)if(s!==ur&&this._isSupportedSecurityType(s)){this._rfbAuthScheme=s;break}return this._rfbAuthScheme===-1?this._fail("Unsupported security types (types: "+e+")"):(this._sock.sQpush32(this._rfbAuthScheme),this._sock.flush(),this._rfbVeNCryptState=4,!0)}}_negotiatePlainAuth(){if(this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1;const e=Ws(this._rfbCredentials.username),s=Ws(this._rfbCredentials.password);return this._sock.sQpush32(e.length),this._sock.sQpush32(s.length),this._sock.sQpushString(e),this._sock.sQpushString(s),this._sock.flush(),this._rfbInitState="SecurityResult",!0}_negotiateStdVNCAuth(){if(this._sock.rQwait("auth challenge",16))return!1;if(this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["password"]}})),!1;const e=Array.prototype.slice.call(this._sock.rQshiftBytes(16)),s=De.genDES(this._rfbCredentials.password,e);return this._sock.sQpushBytes(s),this._sock.flush(),this._rfbInitState="SecurityResult",!0}_negotiateARDAuth(){if(this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1;if(this._rfbCredentials.ardPublicKey!=null&&this._rfbCredentials.ardCredentials!=null)return this._sock.sQpushBytes(this._rfbCredentials.ardCredentials),this._sock.sQpushBytes(this._rfbCredentials.ardPublicKey),this._sock.flush(),this._rfbCredentials.ardCredentials=null,this._rfbCredentials.ardPublicKey=null,this._rfbInitState="SecurityResult",!0;if(this._sock.rQwait("read ard",4))return!1;let e=this._sock.rQshiftBytes(2),s=this._sock.rQshift16();if(this._sock.rQwait("read ard keylength",s*2,4))return!1;let n=this._sock.rQshiftBytes(s),a=this._sock.rQshiftBytes(s),i=gt.generateKey({name:"DH",g:e,p:n},!1,["deriveBits"]);return this._negotiateARDAuthAsync(s,a,i),!1}async _negotiateARDAuthAsync(e,s,n){const a=gt.exportKey("raw",n.publicKey),i=gt.deriveBits({name:"DH",public:s},n.privateKey,e*8),r=Ws(this._rfbCredentials.username).substring(0,63),l=Ws(this._rfbCredentials.password).substring(0,63),d=window.crypto.getRandomValues(new Uint8Array(128));for(let p=0;p<r.length;p++)d[p]=r.charCodeAt(p);d[r.length]=0;for(let p=0;p<l.length;p++)d[64+p]=l.charCodeAt(p);d[64+l.length]=0;const o=await gt.digest("MD5",i),u=await gt.importKey("raw",o,{name:"AES-ECB"},!1,["encrypt"]),_=await gt.encrypt({name:"AES-ECB"},u,d);this._rfbCredentials.ardCredentials=_,this._rfbCredentials.ardPublicKey=a,this._resumeAuthentication()}_negotiateTightUnixAuth(){return this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0?(this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1):(this._sock.sQpush32(this._rfbCredentials.username.length),this._sock.sQpush32(this._rfbCredentials.password.length),this._sock.sQpushString(this._rfbCredentials.username),this._sock.sQpushString(this._rfbCredentials.password),this._sock.flush(),this._rfbInitState="SecurityResult",!0)}_negotiateTightTunnels(e){const s={0:{vendor:"TGHT",signature:"NOTUNNEL"}},n={};for(let a=0;a<e;a++){const i=this._sock.rQshift32(),r=this._sock.rQshiftStr(4),l=this._sock.rQshiftStr(8);n[i]={vendor:r,signature:l}}return Ke("Server Tight tunnel types: "+n),n[1]&&n[1].vendor==="SICR"&&n[1].signature==="SCHANNEL"&&(Ke("Detected Siemens server. Assuming NOTUNNEL support."),n[0]={vendor:"TGHT",signature:"NOTUNNEL"}),n[0]?n[0].vendor!=s[0].vendor||n[0].signature!=s[0].signature?this._fail("Client's tunnel type had the incorrect vendor or signature"):(Ke("Selected tunnel type: "+s[0]),this._sock.sQpush32(0),this._sock.flush(),!1):this._fail("Server wanted tunnels, but doesn't support the notunnel type")}_negotiateTightAuth(){if(!this._rfbTightVNC){if(this._sock.rQwait("num tunnels",4))return!1;const a=this._sock.rQshift32();if(a>0&&this._sock.rQwait("tunnel capabilities",16*a,4))return!1;if(this._rfbTightVNC=!0,a>0)return this._negotiateTightTunnels(a),!1}if(this._sock.rQwait("sub auth count",4))return!1;const e=this._sock.rQshift32();if(e===0)return this._rfbInitState="SecurityResult",!0;if(this._sock.rQwait("sub auth capabilities",16*e,4))return!1;const s={STDVNOAUTH__:1,STDVVNCAUTH_:2,TGHTULGNAUTH:129},n=[];for(let a=0;a<e;a++){this._sock.rQshift32();const i=this._sock.rQshiftStr(12);n.push(i)}Ke("Server Tight authentication types: "+n);for(let a in s)if(n.indexOf(a)!=-1)switch(this._sock.sQpush32(s[a]),this._sock.flush(),Ke("Selected authentication type: "+a),a){case"STDVNOAUTH__":return this._rfbInitState="SecurityResult",!0;case"STDVVNCAUTH_":return this._rfbAuthScheme=di,!0;case"TGHTULGNAUTH":return this._rfbAuthScheme=Ho,!0;default:return this._fail("Unsupported tiny auth scheme (scheme: "+a+")")}return this._fail("No supported sub-auth types!")}_handleRSAAESCredentialsRequired(e){this.dispatchEvent(e)}_handleRSAAESServerVerification(e){this.dispatchEvent(e)}_negotiateRA2neAuth(){return this._rfbRSAAESAuthenticationState===null&&(this._rfbRSAAESAuthenticationState=new ev(this._sock,()=>this._rfbCredentials),this._rfbRSAAESAuthenticationState.addEventListener("serververification",this._eventHandlers.handleRSAAESServerVerification),this._rfbRSAAESAuthenticationState.addEventListener("credentialsrequired",this._eventHandlers.handleRSAAESCredentialsRequired)),this._rfbRSAAESAuthenticationState.checkInternalEvents(),this._rfbRSAAESAuthenticationState.hasStarted||this._rfbRSAAESAuthenticationState.negotiateRA2neAuthAsync().catch(e=>{e.message!=="disconnect normally"&&this._fail(e.message)}).then(()=>(this._rfbInitState="SecurityResult",!0)).finally(()=>{this._rfbRSAAESAuthenticationState.removeEventListener("serververification",this._eventHandlers.handleRSAAESServerVerification),this._rfbRSAAESAuthenticationState.removeEventListener("credentialsrequired",this._eventHandlers.handleRSAAESCredentialsRequired),this._rfbRSAAESAuthenticationState=null}),!1}_negotiateMSLogonIIAuth(){if(this._sock.rQwait("mslogonii dh param",24))return!1;if(this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1;const e=this._sock.rQshiftBytes(8),s=this._sock.rQshiftBytes(8),n=this._sock.rQshiftBytes(8),a=gt.generateKey({name:"DH",g:e,p:s},!0,["deriveBits"]),i=gt.exportKey("raw",a.publicKey),r=gt.deriveBits({name:"DH",public:n},a.privateKey,64),l=gt.importKey("raw",r,{name:"DES-CBC"},!1,["encrypt"]),d=Ws(this._rfbCredentials.username).substring(0,255),o=Ws(this._rfbCredentials.password).substring(0,63);let u=new Uint8Array(256),_=new Uint8Array(64);window.crypto.getRandomValues(u),window.crypto.getRandomValues(_);for(let p=0;p<d.length;p++)u[p]=d.charCodeAt(p);u[d.length]=0;for(let p=0;p<o.length;p++)_[p]=o.charCodeAt(p);return _[o.length]=0,u=gt.encrypt({name:"DES-CBC",iv:r},l,u),_=gt.encrypt({name:"DES-CBC",iv:r},l,_),this._sock.sQpushBytes(i),this._sock.sQpushBytes(u),this._sock.sQpushBytes(_),this._sock.flush(),this._rfbInitState="SecurityResult",!0}_negotiateAuthentication(){switch(this._rfbAuthScheme){case Ro:return this._rfbVersion>=3.8?this._rfbInitState="SecurityResult":this._rfbInitState="ClientInitialisation",!0;case zo:return this._negotiateXvpAuth();case No:return this._negotiateARDAuth();case di:return this._negotiateStdVNCAuth();case Qo:return this._negotiateTightAuth();case ur:return this._negotiateVeNCryptAuth();case Oo:return this._negotiatePlainAuth();case Ho:return this._negotiateTightUnixAuth();case Io:return this._negotiateRA2neAuth();case Uo:return this._negotiateMSLogonIIAuth();default:return this._fail("Unsupported auth scheme (scheme: "+this._rfbAuthScheme+")")}}_handleSecurityResult(){if(this._sock.rQwait("VNC auth response ",4))return!1;const e=this._sock.rQshift32();return e===0?(this._rfbInitState="ClientInitialisation",Ke("Authentication OK"),!0):this._rfbVersion>=3.8?(this._rfbInitState="SecurityReason",this._securityContext="security result",this._securityStatus=e,!0):(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:e}})),this._fail("Security handshake failed"))}_negotiateServerInit(){if(this._sock.rQwait("server initialization",24))return!1;const e=this._sock.rQshift16(),s=this._sock.rQshift16(),n=this._sock.rQshift8(),a=this._sock.rQshift8(),i=this._sock.rQshift8(),r=this._sock.rQshift8(),l=this._sock.rQshift16(),d=this._sock.rQshift16(),o=this._sock.rQshift16(),u=this._sock.rQshift8(),_=this._sock.rQshift8(),p=this._sock.rQshift8();this._sock.rQskipBytes(3);const v=this._sock.rQshift32();if(this._sock.rQwait("server init name",v,24))return!1;let x=this._sock.rQshiftStr(v);if(x=Oi(x,!0),this._rfbTightVNC){if(this._sock.rQwait("TightVNC extended server init header",8,24+v))return!1;const y=this._sock.rQshift16(),w=this._sock.rQshift16(),S=this._sock.rQshift16();this._sock.rQskipBytes(2);const E=(y+w+S)*16;if(this._sock.rQwait("TightVNC extended server init header",E,32+v))return!1;this._sock.rQskipBytes(16*y),this._sock.rQskipBytes(16*w),this._sock.rQskipBytes(16*S)}return Vt("Screen: "+e+"x"+s+", bpp: "+n+", depth: "+a+", bigEndian: "+i+", trueColor: "+r+", redMax: "+l+", greenMax: "+d+", blueMax: "+o+", redShift: "+u+", greenShift: "+_+", blueShift: "+p),this._setDesktopName(x),this._resize(e,s),this._viewOnly||this._keyboard.grab(),this._fbDepth=24,this._fbName==="Intel(r) AMT KVM"&&(jt("Intel AMT KVM only supports 8/16 bit depths. Using low color mode."),this._fbDepth=8),De.messages.pixelFormat(this._sock,this._fbDepth,!0),this._sendEncodings(),De.messages.fbUpdateRequest(this._sock,!1,0,0,this._fbWidth,this._fbHeight),this._updateConnectionState("connected"),!0}_sendEncodings(){const e=[];e.push(Fe.encodingCopyRect),this._fbDepth==24&&(Zc&&e.push(Fe.encodingH264),e.push(Fe.encodingTight),e.push(Fe.encodingTightPNG),e.push(Fe.encodingZRLE),e.push(Fe.encodingJPEG),e.push(Fe.encodingHextile),e.push(Fe.encodingRRE),e.push(Fe.encodingZlib)),e.push(Fe.encodingRaw),e.push(Fe.pseudoEncodingQualityLevel0+this._qualityLevel),e.push(Fe.pseudoEncodingCompressLevel0+this._compressionLevel),e.push(Fe.pseudoEncodingDesktopSize),e.push(Fe.pseudoEncodingLastRect),e.push(Fe.pseudoEncodingQEMUExtendedKeyEvent),e.push(Fe.pseudoEncodingQEMULedEvent),e.push(Fe.pseudoEncodingExtendedDesktopSize),e.push(Fe.pseudoEncodingXvp),e.push(Fe.pseudoEncodingFence),e.push(Fe.pseudoEncodingContinuousUpdates),e.push(Fe.pseudoEncodingDesktopName),e.push(Fe.pseudoEncodingExtendedClipboard),e.push(Fe.pseudoEncodingExtendedMouseButtons),this._fbDepth==24&&(e.push(Fe.pseudoEncodingVMwareCursor),e.push(Fe.pseudoEncodingCursor)),De.messages.clientEncodings(this._sock,e)}_initMsg(){switch(this._rfbInitState){case"ProtocolVersion":return this._negotiateProtocolVersion();case"Security":return this._negotiateSecurity();case"Authentication":return this._negotiateAuthentication();case"SecurityResult":return this._handleSecurityResult();case"SecurityReason":return this._handleSecurityReason();case"ClientInitialisation":return this._sock.sQpush8(this._shared?1:0),this._sock.flush(),this._rfbInitState="ServerInitialisation",!0;case"ServerInitialisation":return this._negotiateServerInit();default:return this._fail("Unknown init state (state: "+this._rfbInitState+")")}}_resumeAuthentication(){setTimeout(this._initMsg.bind(this),0)}_handleSetColourMapMsg(){return Ke("SetColorMapEntries"),this._fail("Unexpected SetColorMapEntries message")}_handleServerCutText(){if(Ke("ServerCutText"),this._sock.rQwait("ServerCutText header",7,1))return!1;this._sock.rQskipBytes(3);let e=this._sock.rQshift32();if(e=Fr(e),this._sock.rQwait("ServerCutText content",Math.abs(e),8))return!1;if(e>=0){const s=this._sock.rQshiftStr(e);if(this._viewOnly)return!0;this.dispatchEvent(new CustomEvent("clipboard",{detail:{text:s}}))}else{e=Math.abs(e);const s=this._sock.rQshift32();let n=s&65535,a=s&4278190080;if(!!(a&Vo)){this._clipboardServerCapabilitiesFormats={},this._clipboardServerCapabilitiesActions={};for(let l=0;l<=15;l++){let d=1<<l;n&d&&(this._clipboardServerCapabilitiesFormats[d]=!0,this._sock.rQshift32())}for(let l=24;l<=31;l++){let d=1<<l;this._clipboardServerCapabilitiesActions[d]=!!(a&d)}let r=[Vo,_i,Go,Sa,vi];De.messages.extendedClipboardCaps(this._sock,r,{extendedClipboardFormatText:0})}else if(a===_i){if(this._viewOnly)return!0;this._clipboardText!=null&&this._clipboardServerCapabilitiesActions[vi]&&n&Rs&&De.messages.extendedClipboardProvide(this._sock,[Rs],[this._clipboardText])}else if(a===Go){if(this._viewOnly)return!0;this._clipboardServerCapabilitiesActions[Sa]&&(this._clipboardText!=null?De.messages.extendedClipboardNotify(this._sock,[Rs]):De.messages.extendedClipboardNotify(this._sock,[]))}else if(a===Sa){if(this._viewOnly)return!0;this._clipboardServerCapabilitiesActions[_i]&&n&Rs&&De.messages.extendedClipboardRequest(this._sock,[Rs])}else if(a===vi){if(this._viewOnly||!(n&Rs))return!0;this._clipboardText=null;let r=this._sock.rQshiftBytes(e-4),l=new Bi,d=null;l.setInput(r);for(let o=0;o<=15;o++){let u=1<<o;if(n&u){let _=0,p=l.inflate(4);_|=p[0]<<24,_|=p[1]<<16,_|=p[2]<<8,_|=p[3];let v=l.inflate(_);u===Rs&&(d=v)}}if(l.setInput(null),d!==null){let o="";for(let u=0;u<d.length;u++)o+=String.fromCharCode(d[u]);d=o,d=Oi(d),d.length>0&&d.charAt(d.length-1)==="\0"&&(d=d.slice(0,-1)),d=d.replaceAll(`\r
|
|
4
|
+
`,`
|
|
5
|
+
`),this.dispatchEvent(new CustomEvent("clipboard",{detail:{text:d}}))}}else return this._fail("Unexpected action in extended clipboard message: "+a)}return!0}_handleServerFenceMsg(){if(this._sock.rQwait("ServerFence header",8,1))return!1;this._sock.rQskipBytes(3);let e=this._sock.rQshift32(),s=this._sock.rQshift8();if(this._sock.rQwait("ServerFence payload",s,9))return!1;s>64&&(jt("Bad payload length ("+s+") in fence response"),s=64);const n=this._sock.rQshiftStr(s);return this._supportsFence=!0,e&1<<31?(e&=3,De.messages.clientFence(this._sock,e,n),!0):this._fail("Unexpected fence response")}_handleXvpMsg(){if(this._sock.rQwait("XVP version and message",3,1))return!1;this._sock.rQskipBytes(1);const e=this._sock.rQshift8(),s=this._sock.rQshift8();switch(s){case 0:ot("XVP operation failed");break;case 1:this._rfbXvpVer=e,Vt("XVP extensions enabled (version "+this._rfbXvpVer+")"),this._setCapability("power",!0);break;default:this._fail("Illegal server XVP message (msg: "+s+")");break}return!0}_normalMsg(){let e;this._FBU.rects>0?e=0:e=this._sock.rQshift8();let s,n;switch(e){case 0:return n=this._framebufferUpdate(),n&&!this._enabledContinuousUpdates&&De.messages.fbUpdateRequest(this._sock,!0,0,0,this._fbWidth,this._fbHeight),n;case 1:return this._handleSetColourMapMsg();case 2:return Ke("Bell"),this.dispatchEvent(new CustomEvent("bell",{detail:{}})),!0;case 3:return this._handleServerCutText();case 150:return s=!this._supportsContinuousUpdates,this._supportsContinuousUpdates=!0,this._enabledContinuousUpdates=!1,s&&(this._enabledContinuousUpdates=!0,this._updateContinuousUpdates(),Vt("Enabling continuous updates.")),!0;case 248:return this._handleServerFenceMsg();case 250:return this._handleXvpMsg();default:return this._fail("Unexpected server message (type "+e+")"),Ke("sock.rQpeekBytes(30): "+this._sock.rQpeekBytes(30)),!0}}_framebufferUpdate(){if(this._FBU.rects===0){if(this._sock.rQwait("FBU header",3,1))return!1;if(this._sock.rQskipBytes(1),this._FBU.rects=this._sock.rQshift16(),this._display.pending())return this._flushing=!0,this._display.flush().then(()=>{this._flushing=!1,this._sock.rQwait("message",1)||this._handleMessage()}),!1}for(;this._FBU.rects>0;){if(this._FBU.encoding===null){if(this._sock.rQwait("rect header",12))return!1;this._FBU.x=this._sock.rQshift16(),this._FBU.y=this._sock.rQshift16(),this._FBU.width=this._sock.rQshift16(),this._FBU.height=this._sock.rQshift16(),this._FBU.encoding=this._sock.rQshift32(),this._FBU.encoding>>=0}if(!this._handleRect())return!1;this._FBU.rects--,this._FBU.encoding=null}return this._display.flip(),!0}_handleRect(){switch(this._FBU.encoding){case Fe.pseudoEncodingLastRect:return this._FBU.rects=1,!0;case Fe.pseudoEncodingVMwareCursor:return this._handleVMwareCursor();case Fe.pseudoEncodingCursor:return this._handleCursor();case Fe.pseudoEncodingQEMUExtendedKeyEvent:return this._qemuExtKeyEventSupported=!0,!0;case Fe.pseudoEncodingDesktopName:return this._handleDesktopName();case Fe.pseudoEncodingDesktopSize:return this._resize(this._FBU.width,this._FBU.height),!0;case Fe.pseudoEncodingExtendedDesktopSize:return this._handleExtendedDesktopSize();case Fe.pseudoEncodingExtendedMouseButtons:return this._extendedPointerEventSupported=!0,!0;case Fe.pseudoEncodingQEMULedEvent:return this._handleLedEvent();default:return this._handleDataRect()}}_handleVMwareCursor(){const e=this._FBU.x,s=this._FBU.y,n=this._FBU.width,a=this._FBU.height;if(this._sock.rQwait("VMware cursor encoding",1))return!1;const i=this._sock.rQshift8();this._sock.rQshift8();let r;const l=4;if(i==0){if(r=new Array(n*a*l),this._sock.rQwait("VMware cursor classic encoding",n*a*l*2,2))return!1;let o=new Array(n*a);for(let _=0;_<n*a;_++)o[_]=this._sock.rQshift32();let u=new Array(n*a);for(let _=0;_<n*a;_++)u[_]=this._sock.rQshift32();for(let _=0;_<n*a;_++)if(o[_]==0){let p=u[_],v=p>>8&255,x=p>>16&255,y=p>>24&255;r[_*l]=v,r[_*l+1]=x,r[_*l+2]=y,r[_*l+3]=255}else(o[_]&-256)==-256?u[_]==0?(r[_*l]=0,r[_*l+1]=0,r[_*l+2]=0,r[_*l+3]=0):(u[_]&-256,r[_*l]=0,r[_*l+1]=0,r[_*l+2]=0,r[_*l+3]=255):(r[_*l]=0,r[_*l+1]=0,r[_*l+2]=0,r[_*l+3]=255)}else if(i==1){if(this._sock.rQwait("VMware cursor alpha encoding",n*a*4,2))return!1;r=new Array(n*a*l);for(let d=0;d<n*a;d++){let o=this._sock.rQshift32();r[d*4]=o>>24&255,r[d*4+1]=o>>16&255,r[d*4+2]=o>>8&255,r[d*4+3]=o&255}}else return jt("The given cursor type is not supported: "+i+" given."),!1;return this._updateCursor(r,e,s,n,a),!0}_handleCursor(){const e=this._FBU.x,s=this._FBU.y,n=this._FBU.width,a=this._FBU.height,i=n*a*4,r=Math.ceil(n/8)*a;let l=i+r;if(this._sock.rQwait("cursor encoding",l))return!1;const d=this._sock.rQshiftBytes(i),o=this._sock.rQshiftBytes(r);let u=new Uint8Array(n*a*4),_=0;for(let p=0;p<a;p++)for(let v=0;v<n;v++){let x=p*Math.ceil(n/8)+Math.floor(v/8),y=o[x]<<v%8&128?255:0;u[_]=d[_+2],u[_+1]=d[_+1],u[_+2]=d[_],u[_+3]=y,_+=4}return this._updateCursor(u,e,s,n,a),!0}_handleDesktopName(){if(this._sock.rQwait("DesktopName",4))return!1;let e=this._sock.rQshift32();if(this._sock.rQwait("DesktopName",e,4))return!1;let s=this._sock.rQshiftStr(e);return s=Oi(s,!0),this._setDesktopName(s),!0}_handleLedEvent(){if(this._sock.rQwait("LED status",1))return!1;let e=this._sock.rQshift8(),s=!!(e&2),n=!!(e&4);return this._remoteCapsLock=n,this._remoteNumLock=s,!0}_handleExtendedDesktopSize(){if(this._sock.rQwait("ExtendedDesktopSize",4))return!1;const e=this._sock.rQpeek8();let s=4+e*16;if(this._sock.rQwait("ExtendedDesktopSize",s))return!1;const n=!this._supportsSetDesktopSize;this._supportsSetDesktopSize=!0,this._sock.rQskipBytes(1),this._sock.rQskipBytes(3);for(let a=0;a<e;a+=1)a===0?(this._screenID=this._sock.rQshift32(),this._sock.rQskipBytes(2),this._sock.rQskipBytes(2),this._sock.rQskipBytes(2),this._sock.rQskipBytes(2),this._screenFlags=this._sock.rQshift32()):this._sock.rQskipBytes(16);if(this._FBU.x===1&&(this._pendingRemoteResize=!1),this._FBU.x===1&&this._FBU.y!==0){let a="";switch(this._FBU.y){case 1:a="Resize is administratively prohibited";break;case 2:a="Out of resources";break;case 3:a="Invalid screen layout";break;default:a="Unknown reason";break}jt("Server did not accept the resize request: "+a)}else this._resize(this._FBU.width,this._FBU.height);return n&&this._requestRemoteResize(),this._FBU.x===1&&this._FBU.y===0&&this._requestRemoteResize(),!0}_handleDataRect(){let e=this._decoders[this._FBU.encoding];if(!e)return this._fail("Unsupported encoding (encoding: "+this._FBU.encoding+")"),!1;try{return e.decodeRect(this._FBU.x,this._FBU.y,this._FBU.width,this._FBU.height,this._sock,this._display,this._fbDepth)}catch(s){return this._fail("Error decoding rect: "+s),!1}}_updateContinuousUpdates(){this._enabledContinuousUpdates&&De.messages.enableContinuousUpdates(this._sock,!0,0,0,this._fbWidth,this._fbHeight)}_resize(e,s){this._fbWidth=e,this._fbHeight=s,this._display.resize(this._fbWidth,this._fbHeight),this._updateClip(),this._updateScale(),this._updateContinuousUpdates(),this._saveExpectedClientSize()}_xvpOp(e,s){this._rfbXvpVer<e||(Vt("Sending XVP operation "+s+" (version "+e+")"),De.messages.xvpOp(this._sock,e,s))}_updateCursor(e,s,n,a,i){this._cursorImage={rgbaPixels:e,hotx:s,hoty:n,w:a,h:i},this._refreshCursor()}_shouldShowDotCursor(){if(!this._showDotCursor)return!1;for(let e=3;e<this._cursorImage.rgbaPixels.length;e+=4)if(this._cursorImage.rgbaPixels[e])return!1;return!0}_refreshCursor(){if(this._rfbConnectionState!=="connecting"&&this._rfbConnectionState!=="connected")return;const e=this._shouldShowDotCursor()?De.cursors.dot:this._cursorImage;this._cursor.change(e.rgbaPixels,e.hotx,e.hoty,e.w,e.h)}static genDES(e,s){const n=e.split("").map(i=>i.charCodeAt(0)),a=gt.importKey("raw",n,{name:"DES-ECB"},!1,["encrypt"]);return gt.encrypt({name:"DES-ECB"},a,s)}}De.messages={keyEvent(t,e,s){t.sQpush8(4),t.sQpush8(s),t.sQpush16(0),t.sQpush32(e),t.flush()},QEMUExtendedKeyEvent(t,e,s,n){function a(r){const l=n>>8,d=n&255;return l===224&&d<127?d|128:r}t.sQpush8(255),t.sQpush8(0),t.sQpush16(s),t.sQpush32(e);const i=a(n);t.sQpush32(i),t.flush()},pointerEvent(t,e,s,n){t.sQpush8(5),n=n&127,t.sQpush8(n),t.sQpush16(e),t.sQpush16(s),t.flush()},extendedPointerEvent(t,e,s,n){t.sQpush8(5);let a=n>>7&255;if(a&252)throw new Error("Invalid mouse button mask: "+n);let i=n&127;i|=128,t.sQpush8(i),t.sQpush16(e),t.sQpush16(s),t.sQpush8(a),t.flush()},_buildExtendedClipboardFlags(t,e){let s=new Uint8Array(4),n=0,a=0;for(let i=0;i<t.length;i++)a|=t[i];for(let i=0;i<e.length;i++)n|=e[i];return s[0]=a>>24,s[1]=0,s[2]=0,s[3]=n,s},extendedClipboardProvide(t,e,s){let n=new M_,a=[];for(let l=0;l<e.length;l++){if(e[l]!=Rs)throw new Error("Unsupported extended clipboard format for Provide message.");s[l]=s[l].replace(/\r\n|\r|\n/gm,`\r
|
|
6
|
+
`);let d=Ws(s[l]+"\0");a.push(d.length>>24&255,d.length>>16&255,d.length>>8&255,d.length&255);for(let o=0;o<d.length;o++)a.push(d.charCodeAt(o))}let i=n.deflate(new Uint8Array(a)),r=new Uint8Array(4+i.length);r.set(De.messages._buildExtendedClipboardFlags([vi],e)),r.set(i,4),De.messages.clientCutText(t,r,!0)},extendedClipboardNotify(t,e){let s=De.messages._buildExtendedClipboardFlags([Sa],e);De.messages.clientCutText(t,s,!0)},extendedClipboardRequest(t,e){let s=De.messages._buildExtendedClipboardFlags([_i],e);De.messages.clientCutText(t,s,!0)},extendedClipboardCaps(t,e,s){let n=Object.keys(s),a=new Uint8Array(4+4*n.length);n.map(r=>parseInt(r)),n.sort((r,l)=>r-l),a.set(De.messages._buildExtendedClipboardFlags(e,[]));let i=4;for(let r=0;r<n.length;r++)a[i]=s[n[r]]>>24,a[i+1]=s[n[r]]>>16,a[i+2]=s[n[r]]>>8,a[i+3]=s[n[r]]>>0,i+=4,a[3]|=1<<n[r];De.messages.clientCutText(t,a,!0)},clientCutText(t,e,s=!1){t.sQpush8(6),t.sQpush8(0),t.sQpush8(0),t.sQpush8(0);let n;s?n=lf(-e.length):n=e.length,t.sQpush32(n),t.sQpushBytes(e),t.flush()},setDesktopSize(t,e,s,n,a){t.sQpush8(251),t.sQpush8(0),t.sQpush16(e),t.sQpush16(s),t.sQpush8(1),t.sQpush8(0),t.sQpush32(n),t.sQpush16(0),t.sQpush16(0),t.sQpush16(e),t.sQpush16(s),t.sQpush32(a),t.flush()},clientFence(t,e,s){t.sQpush8(248),t.sQpush8(0),t.sQpush8(0),t.sQpush8(0),t.sQpush32(e),t.sQpush8(s.length),t.sQpushString(s),t.flush()},enableContinuousUpdates(t,e,s,n,a,i){t.sQpush8(150),t.sQpush8(e),t.sQpush16(s),t.sQpush16(n),t.sQpush16(a),t.sQpush16(i),t.flush()},pixelFormat(t,e,s){let n;e>16?n=32:e>8?n=16:n=8;const a=Math.floor(e/3);t.sQpush8(0),t.sQpush8(0),t.sQpush8(0),t.sQpush8(0),t.sQpush8(n),t.sQpush8(e),t.sQpush8(0),t.sQpush8(s?1:0),t.sQpush16((1<<a)-1),t.sQpush16((1<<a)-1),t.sQpush16((1<<a)-1),t.sQpush8(a*0),t.sQpush8(a*1),t.sQpush8(a*2),t.sQpush8(0),t.sQpush8(0),t.sQpush8(0),t.flush()},clientEncodings(t,e){t.sQpush8(2),t.sQpush8(0),t.sQpush16(e.length);for(let s=0;s<e.length;s++)t.sQpush32(e[s]);t.flush()},fbUpdateRequest(t,e,s,n,a,i){typeof s>"u"&&(s=0),typeof n>"u"&&(n=0),t.sQpush8(3),t.sQpush8(e?1:0),t.sQpush16(s),t.sQpush16(n),t.sQpush16(a),t.sQpush16(i),t.flush()},xvpOp(t,e,s){t.sQpush8(250),t.sQpush8(0),t.sQpush8(e),t.sQpush8(s),t.flush()}};De.cursors={none:{rgbaPixels:new Uint8Array,w:0,h:0,hotx:0,hoty:0},dot:{rgbaPixels:new Uint8Array([255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,255,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0,255,255,255,255,255]),w:3,h:3,hotx:1,hoty:1}};var pv=T('<div class="loading svelte-1szlhua">Loading...</div>'),gv=T('<div class="disabled-state svelte-1szlhua"><div class="disabled-icon svelte-1szlhua"><svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="svelte-1szlhua"><rect x="2" y="3" width="20" height="14" rx="2" class="svelte-1szlhua"></rect><line x1="8" y1="21" x2="16" y2="21" class="svelte-1szlhua"></line><line x1="12" y1="17" x2="12" y2="21" class="svelte-1szlhua"></line></svg></div> <h2 class="disabled-title svelte-1szlhua">Browser Not Enabled</h2> <p class="disabled-text svelte-1szlhua">Enable the browser from Settings to connect to a running VM with noVNC.</p> <a href="#/settings" class="btn btn-outline btn-sm svelte-1szlhua">Go to Settings</a></div>'),xv=T('<div class="conn-info-popover svelte-1szlhua"><div class="conn-info-row svelte-1szlhua"><span class="conn-info-key svelte-1szlhua">VNC port</span> <span class="mono conn-info-val svelte-1szlhua"> </span></div> <div class="conn-info-row svelte-1szlhua"><span class="conn-info-key svelte-1szlhua">noVNC port</span> <span class="mono conn-info-val svelte-1szlhua"> </span></div></div>'),bv=T('<button class="toolbar-btn toolbar-btn-danger svelte-1szlhua"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svelte-1szlhua"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" class="svelte-1szlhua"></path><polyline points="16 17 21 12 16 7" class="svelte-1szlhua"></polyline><line x1="21" y1="12" x2="9" y2="12" class="svelte-1szlhua"></line></svg> Disconnect</button>'),mv=T('<div class="toolbar-right svelte-1szlhua"><span class="toolbar-sep svelte-1szlhua"></span> <button><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svelte-1szlhua"><rect x="9" y="2" width="6" height="4" rx="1" class="svelte-1szlhua"></rect><path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-2" class="svelte-1szlhua"></path></svg> Clipboard</button> <!></div>'),wv=T('<div class="clipboard-popover svelte-1szlhua"><p class="clipboard-label svelte-1szlhua">Type or paste, then use Ctrl+V inside the desktop</p> <textarea class="clipboard-textarea svelte-1szlhua" placeholder="Paste text here..."></textarea></div>'),yv=T('<div class="error-overlay svelte-1szlhua"><p class="error-text svelte-1szlhua"> </p> <p class="error-hint svelte-1szlhua">Ensure the browser stack (noVNC) is running</p> <button class="btn btn-outline btn-sm svelte-1szlhua">Reconnect</button></div>'),kv=T('<div class="browser-viewer svelte-1szlhua"><div class="toolbar svelte-1szlhua"><div class="toolbar-left svelte-1szlhua"><button class="conn-status svelte-1szlhua"><span></span> <span class="toolbar-label svelte-1szlhua"> </span></button> <!></div> <!></div> <div class="vnc-container svelte-1szlhua"><!> <!> <div></div></div></div>');function Sv(t,e){st(e,!0);let s=q(null),n=q(!0),a=q("connecting"),i=q(void 0),r=q(0),l=q(null),d=q(!1),o=q(""),u=q(!1);const _=Ae(()=>e.status?.browser.enabled??!1),p={connecting:"Connecting",connected:"Connected",disconnected:"Disconnected",failed:"Failed"},v=Ae(()=>p[c(a)]);mt(()=>{const C=new AbortController;return Ee("/api/config").then(F=>{C.signal.aborted||b(s,F,!0)}).finally(()=>{C.signal.aborted||b(n,!1)}),()=>C.abort()});const x=Ae(()=>{if(!c(s)?.browser)return"";const C=Xi(),F=C?`?token=${encodeURIComponent(C)}`:"";return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/vnc${F}`});mt(()=>{if(!c(_)||!c(x)||!c(i)||c(r)<0)return;b(a,"connecting");let C=null;try{C=new De(c(i),c(x)),C.scaleViewport=!0,C.resizeSession=!1,C.qualityLevel=7,C.compressionLevel=2,b(l,C,!0),C.addEventListener("connect",()=>{b(a,"connected")}),C.addEventListener("disconnect",F=>{const L=F.detail;b(a,L.clean?"disconnected":"failed",!0),b(l,null)})}catch{b(a,"failed"),b(l,null)}return()=>{C?.disconnect(),b(l,null)}});function y(){b(a,"connecting"),b(r,c(r)+1)}function w(){c(l)?.disconnect()}function S(){b(d,!c(d)),b(o,"")}function E(){c(l)&&c(l).clipboardPasteFrom(c(o))}var K=bt(),A=Ce(K);{var U=C=>{var F=pv();k(C,F)},ee=C=>{var F=gv();k(C,F)},X=C=>{var F=kv(),L=h(F),j=h(L),oe=h(j),de=h(oe);let J;var N=f(de,2),se=h(N),ae=f(oe,2);{var ke=ce=>{var pe=xv(),$=h(pe),Se=f(h($),2),he=h(Se),Le=f($,2),Te=f(h(Le),2),Be=h(Te);O(()=>{M(he,c(s).browser.vncPort),M(Be,c(s).browser.novncPort)}),k(ce,pe)};H(ae,ce=>{c(u)&&c(s)?.browser&&ce(ke)})}var we=f(j,2);{var fe=ce=>{var pe=mv(),$=f(h(pe),2);let Se;var he=f($,2);{var Le=Te=>{var Be=bv();V("click",Be,w),k(Te,Be)};H(he,Te=>{c(a)==="connected"&&Te(Le)})}O(()=>{Se=me($,1,"toolbar-btn svelte-1szlhua",null,Se,{"toolbar-btn-active":c(d)}),$.disabled=c(a)!=="connected"}),V("click",$,S),k(ce,pe)};H(we,ce=>{c(s)?.browser&&ce(fe)})}var Z=f(L,2),le=h(Z);{var be=ce=>{var pe=wv(),$=f(h(pe),2);ns($,"rows",4),V("input",$,E),Ve($,()=>c(o),Se=>b(o,Se)),k(ce,pe)};H(le,ce=>{c(d)&&ce(be)})}var ue=f(le,2);{var ve=ce=>{var pe=yv(),$=h(pe),Se=h($),he=f($,4);O(()=>M(Se,c(a)==="failed"?"Connection failed":"Disconnected")),V("click",he,y),k(ce,pe)};H(ue,ce=>{(c(a)==="failed"||c(a)==="disconnected")&&ce(ve)})}var _e=f(ue,2);let ye;_h(_e,ce=>b(i,ce),()=>c(i)),O(()=>{J=me(de,1,"conn-dot svelte-1szlhua",null,J,{"conn-connecting":c(a)==="connecting","conn-on":c(a)==="connected","conn-off":c(a)==="disconnected"||c(a)==="failed"}),M(se,c(v)),ye=me(_e,1,"vnc-canvas svelte-1szlhua",null,ye,{"vnc-hidden":c(a)!=="connected"})}),V("click",oe,()=>{b(u,!c(u))}),k(C,F)};H(A,C=>{c(n)?C(U):c(_)?C(X,!1):C(ee,1)})}k(t,K),nt()}ht(["click","input"]);var Cv=T('<button class="val-btn agent-name editable svelte-ys3ftv"> </button>'),Ev=T('<button class="btn btn-outline btn-sm btn-danger">Delete</button>'),Av=T('<button class="val-btn mono editable"> </button>'),Kv=T('<button class="val-btn mono editable"> </button>'),Fv=T('<button class="val-btn mono editable"> </button>'),Tv=T('<button class="val-btn mono editable"> </button>'),Mv=T('<button class="val-btn mono editable"> </button>'),Xv=T('<button class="prompt-block editable svelte-ys3ftv"> </button>'),Lv=T('<div class="agent-card svelte-ys3ftv"><div class="agent-bar svelte-ys3ftv"></div> <div class="agent-top svelte-ys3ftv"><div class="agent-identity svelte-ys3ftv"><!> <span class="agent-id mono svelte-ys3ftv"> </span></div> <div class="agent-actions svelte-ys3ftv"><select class="inline-select mono"><option>claude</option><option>opencode</option></select> <!></div></div> <div class="agent-fields svelte-ys3ftv"><div class="agent-field svelte-ys3ftv"><span class="row-label">Model</span> <!></div> <div class="agent-field svelte-ys3ftv"><span class="row-label">Fallback</span> <!></div> <div class="agent-field svelte-ys3ftv"><span class="row-label">Turns</span> <!></div> <div class="agent-field svelte-ys3ftv"><span class="row-label">Timeout</span> <!></div> <div class="agent-field svelte-ys3ftv"><span class="row-label">Channels</span> <!></div></div> <div class="agent-prompt-area svelte-ys3ftv"><span class="row-label">System Prompt</span> <!></div></div>');function Pv(t,e){st(e,!0);let s=q("");function n(ne,te){b(s,String(te),!0),e.editor.startEdit(`agent.${e.index}.${ne}`,te)}function a(ne){return e.editor.editingField===`agent.${e.index}.${ne}`}var i=Lv(),r=f(h(i),2),l=h(r),d=h(l);{var o=ne=>{xt(ne,{get saving(){return e.editor.editingSaving},onsave:te=>e.onsavefield("name",te),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},u=Ae(()=>a("name")),_=ne=>{var te=Cv(),ge=h(te);O(()=>M(ge,e.agent.name)),V("click",te,()=>n("name",e.agent.name)),k(ne,te)};H(d,ne=>{c(u)?ne(o):ne(_,!1)})}var p=f(d,2),v=h(p),x=f(l,2),y=h(x),w=h(y);w.value=w.__value="claude";var S=f(w);S.value=S.__value="opencode";var E;Nc(y);var K=f(y,2);{var A=ne=>{var te=Ev();V("click",te,function(...ge){e.ondelete?.apply(this,ge)}),k(ne,te)};H(K,ne=>{e.agentCount>1&&ne(A)})}var U=f(r,2),ee=h(U),X=f(h(ee),2);{var C=ne=>{xt(ne,{mono:!0,get saving(){return e.editor.editingSaving},onsave:te=>e.onsavefield("model",te),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},F=Ae(()=>a("model")),L=ne=>{var te=Av(),ge=h(te);O(()=>M(ge,e.agent.model)),V("click",te,()=>n("model",e.agent.model)),k(ne,te)};H(X,ne=>{c(F)?ne(C):ne(L,!1)})}var j=f(ee,2),oe=f(h(j),2);{var de=ne=>{xt(ne,{mono:!0,get saving(){return e.editor.editingSaving},placeholder:"none",onsave:te=>e.onsavefield("fallbackModel",te,ge=>ge.trim()||null),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},J=Ae(()=>a("fallbackModel")),N=ne=>{var te=Kv(),ge=h(te);O(()=>M(ge,e.agent.fallbackModel??"none")),V("click",te,()=>n("fallbackModel",e.agent.fallbackModel??"")),k(ne,te)};H(oe,ne=>{c(J)?ne(de):ne(N,!1)})}var se=f(j,2),ae=f(h(se),2);{var ke=ne=>{xt(ne,{mono:!0,get saving(){return e.editor.editingSaving},onsave:te=>e.onsavefield("maxTurns",te,ge=>Number(ge)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},we=Ae(()=>a("maxTurns")),fe=ne=>{var te=Fv(),ge=h(te);O(()=>M(ge,e.agent.maxTurns)),V("click",te,()=>n("maxTurns",e.agent.maxTurns)),k(ne,te)};H(ae,ne=>{c(we)?ne(ke):ne(fe,!1)})}var Z=f(se,2),le=f(h(Z),2);{var be=ne=>{xt(ne,{mono:!0,get saving(){return e.editor.editingSaving},placeholder:"global",onsave:te=>e.onsavefield("processTimeoutMs",te,ge=>{const tt=ge.trim();return tt?Number(tt)*1e3:null}),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},ue=Ae(()=>a("processTimeoutMs")),ve=ne=>{var te=Tv(),ge=h(te);O(()=>M(ge,e.agent.processTimeoutMs?`${e.agent.processTimeoutMs/1e3}s`:"global")),V("click",te,()=>n("processTimeoutMs",e.agent.processTimeoutMs?String(e.agent.processTimeoutMs/1e3):"")),k(ne,te)};H(le,ne=>{c(ue)?ne(be):ne(ve,!1)})}var _e=f(Z,2),ye=f(h(_e),2);{var ce=ne=>{xt(ne,{mono:!0,get saving(){return e.editor.editingSaving},onsave:te=>e.onsavefield("channels",te,ge=>ge.split(",").map(tt=>tt.trim()).filter(Boolean)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},pe=Ae(()=>a("channels")),$=ne=>{var te=Mv(),ge=h(te);O(tt=>M(ge,tt),[()=>e.agent.channels.join(", ")||"*"]),V("click",te,()=>n("channels",e.agent.channels.join(", "))),k(ne,te)};H(ye,ne=>{c(pe)?ne(ce):ne($,!1)})}var Se=f(U,2),he=f(h(Se),2);{var Le=ne=>{xt(ne,{multiline:!0,get saving(){return e.editor.editingSaving},onsave:te=>e.onsavefield("systemPrompt",te),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(te){b(s,te,!0)}})},Te=Ae(()=>a("systemPrompt")),Be=ne=>{var te=Xv(),ge=h(te);O(()=>M(ge,e.agent.systemPrompt)),V("click",te,()=>n("systemPrompt",e.agent.systemPrompt)),k(ne,te)};H(he,ne=>{c(Te)?ne(Le):ne(Be,!1)})}O(()=>{M(v,e.agent.id),E!==(E=e.agent.provider)&&(y.value=(y.__value=e.agent.provider)??"",Gr(y,e.agent.provider))}),V("change",y,ne=>e.onsavefield("provider",ne.currentTarget.value)),k(t,i),nt()}ht(["click","change"]);var Bv=T('<div class="agent-card agent-card-new svelte-6z0nn3"><div class="agent-bar agent-bar-new svelte-6z0nn3"></div> <div class="agent-top svelte-6z0nn3"><span class="agent-name svelte-6z0nn3" style="color: var(--color-accent)">New Agent</span> <button class="btn btn-outline btn-sm">Cancel</button></div> <div class="new-agent-form svelte-6z0nn3"><div class="form-row svelte-6z0nn3"><label class="form-lbl svelte-6z0nn3" for="new-agent-name">Name</label> <input id="new-agent-name" class="form-field svelte-6z0nn3" type="text" placeholder="Agent name"/></div> <div class="form-row svelte-6z0nn3"><label class="form-lbl svelte-6z0nn3" for="new-agent-provider">Provider</label> <select id="new-agent-provider" class="inline-select mono"><option>claude</option><option>opencode</option></select></div> <div class="form-row svelte-6z0nn3"><label class="form-lbl svelte-6z0nn3" for="new-agent-model">Model</label> <input id="new-agent-model" class="form-field mono svelte-6z0nn3" type="text" placeholder="sonnet"/></div> <div class="form-row svelte-6z0nn3"><label class="form-lbl svelte-6z0nn3" for="new-agent-turns">Max Turns</label> <input id="new-agent-turns" class="form-field mono svelte-6z0nn3" type="text" placeholder="50"/></div> <div class="form-row svelte-6z0nn3"><label class="form-lbl svelte-6z0nn3" for="new-agent-channels">Channels</label> <input id="new-agent-channels" class="form-field mono svelte-6z0nn3" type="text" placeholder="* (comma-separated)"/></div> <div class="form-row form-row-full svelte-6z0nn3"><label class="form-lbl svelte-6z0nn3" for="new-agent-prompt">System Prompt</label> <textarea id="new-agent-prompt" class="form-field form-field-textarea svelte-6z0nn3" placeholder="Optional system prompt"></textarea></div> <div class="form-row form-row-actions svelte-6z0nn3"><button class="btn btn-primary btn-sm">Create Agent</button></div></div></div>');function Dv(t,e){st(e,!0);let s=q(He({name:"",provider:"claude",model:"",maxTurns:"50",systemPrompt:"",channels:"*"}));function n(F){return F.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}async function a(){const F=n(c(s).name)||"agent",L=c(s).channels.split(",").map(de=>de.trim()).filter(Boolean),j={id:F,name:c(s).name,provider:c(s).provider,model:c(s).model,fallbackModel:null,maxTurns:Number(c(s).maxTurns)||50,systemPrompt:c(s).systemPrompt||"You are responding in a Slack workspace. Be concise, helpful, and natural.",channels:L.length>0?L:["*"]};await e.onsave(j)&&b(s,{name:"",provider:"claude",model:"",maxTurns:"50",systemPrompt:"",channels:"*"},!0)}var i=Bv(),r=f(h(i),2),l=f(h(r),2),d=f(r,2),o=h(d),u=f(h(o),2),_=f(o,2),p=f(h(_),2),v=h(p);v.value=v.__value="claude";var x=f(v);x.value=x.__value="opencode";var y=f(_,2),w=f(h(y),2),S=f(y,2),E=f(h(S),2),K=f(S,2),A=f(h(K),2),U=f(K,2),ee=f(h(U),2),X=f(U,2),C=h(X);O(F=>C.disabled=F,[()=>!c(s).name.trim()||!c(s).model.trim()]),V("click",l,function(...F){e.oncancel?.apply(this,F)}),Ve(u,()=>c(s).name,F=>c(s).name=F),Uc(p,()=>c(s).provider,F=>c(s).provider=F),Ve(w,()=>c(s).model,F=>c(s).model=F),Ve(E,()=>c(s).maxTurns,F=>c(s).maxTurns=F),Ve(A,()=>c(s).channels,F=>c(s).channels=F),Ve(ee,()=>c(s).systemPrompt,F=>c(s).systemPrompt=F),V("click",C,a),k(t,i),nt()}ht(["click"]);var Rv=T('<button class="btn btn-outline btn-sm">Add Agent</button>'),Iv=T('<div class="section"><div class="section-header"><h2 class="section-title">Agents</h2> <!></div> <!> <!></div>');function Qv(t,e){st(e,!0);let s=q(!1);async function n(v,x,y,w){const S=e.config.agents.map(U=>({...U})),E=S[v];if(!E)return;const K=w?w(y):y;E[x]=K,await e.editor.saveConfigPatch({agents:S})&&e.editor.cancelEdit()}async function a(v){if(e.config.agents.length<=1)return;const x=e.config.agents[v];if(!x||!await jr(`Delete agent "${x.name}"?`))return;const w=e.config.agents.filter((S,E)=>E!==v);await e.editor.saveConfigPatch({agents:w})}async function i(v){const x=[...e.config.agents,v],y=await e.editor.saveConfigPatch({agents:x});return y&&b(s,!1),y}var r=Iv(),l=h(r),d=f(h(l),2);{var o=v=>{var x=Rv();V("click",x,()=>{b(s,!0)}),k(v,x)};H(d,v=>{c(s)||v(o)})}var u=f(l,2);Et(u,19,()=>e.config.agents,v=>v.id,(v,x,y)=>{Pv(v,{get agent(){return c(x)},get index(){return c(y)},get agentCount(){return e.config.agents.length},get editor(){return e.editor},onsavefield:(w,S,E)=>n(c(y),w,S,E),ondelete:()=>a(c(y))})});var _=f(u,2);{var p=v=>{Dv(v,{onsave:i,oncancel:()=>{b(s,!1)}})};H(_,v=>{c(s)&&v(p)})}k(t,r),nt()}ht(["click"]);var zv=T('<div class="row"><span class="row-label">Uptime</span> <span class="row-value mono"> </span></div>'),Nv=T('<button class="val-btn mono editable"> </button>'),Uv=T('<span class="cli-pill svelte-u0w225"><span class="dot dot-muted"></span> claude ...</span>'),Hv=T('<span class="cli-pill svelte-u0w225"><span class="dot dot-muted"></span> opencode ...</span>'),Ov=T('<span class="dim">Checking...</span>'),Vv=T("<!> <!> <!>",1),Gv=T('<span class="cli-pill cli-pill-ok svelte-u0w225"><span class="dot dot-on"></span> </span>'),qv=T('<span class="cli-pill cli-pill-err svelte-u0w225"><span class="dot dot-off"></span> </span>'),Wv=T('<span class="cli-pill svelte-u0w225"><span class="dot dot-muted"></span> </span>'),jv=T('<div class="row"><span class="row-label">Node.js</span> <span class="row-value mono"> </span></div>'),Yv=Cn('<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-u0w225"><path d="M3 8.5l3.5 3.5L13 4.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'),Zv=T('<div class="secret-edit svelte-u0w225"><input type="password" autocomplete="off" class="secret-input mono svelte-u0w225" placeholder="sk-ant-..."/> <button class="inline-btn inline-btn-save svelte-u0w225" title="Save"><!></button> <button class="inline-btn inline-btn-cancel svelte-u0w225" title="Cancel"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-u0w225"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"></path></svg></button></div>'),Jv=T('<button class="val-btn mono editable"> </button>'),$v=T('<span class="dim">...</span>'),ep=T('<button class="val-btn mono editable"> </button>'),tp=T('<button class="val-btn mono editable"> </button>'),sp=T('<button class="val-btn mono editable"> </button>'),np=T("<span><span></span> </span>"),ap=Cn('<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-u0w225"><path d="M3 8.5l3.5 3.5L13 4.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>'),ip=T('<div class="secret-edit svelte-u0w225"><input type="password" autocomplete="off" class="secret-input mono svelte-u0w225"/> <button class="inline-btn inline-btn-save svelte-u0w225" title="Save"><!></button> <button class="inline-btn inline-btn-cancel svelte-u0w225" title="Cancel"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="svelte-u0w225"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"></path></svg></button></div>'),rp=T('<button class="val-btn mono editable"> </button>'),lp=T('<span class="dim">...</span>'),op=T('<div class="row"><span class="row-label"> </span> <span class="row-value"><!></span></div>'),cp=T('<div class="notice svelte-u0w225">Restart the daemon to apply new Slack tokens.</div>'),dp=T('<button class="val-btn mono editable"> </button>'),up=T('<button class="val-btn mono editable"> </button>'),hp=T('<button class="val-btn mono editable"> </button>'),fp=T('<button class="val-btn mono editable"> </button>'),_p=T('<div class="row"><span class="row-label">Start / End</span> <span class="row-value"><!> <span class="dim">–</span> <!></span></div>'),vp=T("<span><span></span> </span>"),pp=T('<button class="val-btn mono editable"> </button>'),gp=T('<div class="row"><span class="row-label">VM Host</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Mode</span> <span class="row-value mono"> </span></div> <div class="row"><span class="row-label">VNC Port</span> <span class="row-value mono"> </span></div> <div class="row"><span class="row-label">noVNC Port</span> <span class="row-value mono"> </span></div>',1),xp=T('<button class="val-btn mono editable"> </button>'),bp=T('<button class="val-btn mono editable"> </button>'),mp=T('<div class="config-grid svelte-u0w225"><div class="panel"><div class="panel-header"><span class="panel-title">System</span></div> <div class="panel-body"><!> <div class="row"><span class="row-label">Timezone</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Web Port</span> <span class="row-value mono"> </span></div> <div class="row"><span class="row-label">Agent CLI</span> <span class="row-value"><!></span></div> <!> <div class="row"><span class="row-label">API Key</span> <span class="row-value"><!></span></div></div></div> <div class="panel"><div class="panel-header"><span class="panel-title">Sessions</span></div> <div class="panel-body"><div class="row"><span class="row-label">Max Concurrent</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">TTL</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Timeout</span> <span class="row-value"><!></span></div></div></div> <div class="panel"><div class="panel-header"><span class="panel-title">Slack</span> <!></div> <div class="panel-body"><!> <!> <!> <div class="row"><span class="row-label">Require Mention</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Debounce</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Bypass DMs</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Channels</span> <span class="row-value"><!></span></div> <div class="row"><span class="row-label">Quiet Hours</span> <span class="row-value"><!></span></div> <!></div></div> <div class="panel"><div class="panel-header"><span class="panel-title">Browser</span> <!></div> <div class="panel-body"><div class="row"><span class="row-label">Enabled</span> <span class="row-value"><!></span></div> <!></div></div> <div class="panel"><div class="panel-header"><span class="panel-title">Birds</span></div> <div class="panel-body"><div class="row"><span class="row-label">Max Attempts</span> <span class="row-value"><!></span></div></div></div> <div class="panel"><div class="panel-header"><span class="panel-title">Database</span></div> <div class="panel-body"><div class="row"><span class="row-label">Retention</span> <span class="row-value"><!></span></div></div></div></div> <!>',1);function wp(t,e){st(e,!0);let s=q("");const n=Ae(()=>new Set(e.config.agents.map(Y=>Y.provider)));function a(Y,G){b(s,String(G),!0),e.editor.startEdit(Y,G)}let i=q(null),r=q(""),l=q(!1),d=q(!1);function o(Y){b(i,Y,!0),b(r,"")}function u(){b(i,null),b(l,!1)}async function _(){if(!(!c(i)||!c(r).trim())){b(l,!0);try{if(c(i)==="slackBotToken"||c(i)==="slackAppToken"){const Y=c(i)==="slackBotToken"?{botToken:c(r).trim()}:{appToken:c(r).trim()},G=await Ee("/api/secrets/slack",{method:"PUT",body:Y});Pe("Slack token saved","success"),G.requiresRestart&&b(d,!0)}else await Ee("/api/secrets/anthropic",{method:"PUT",body:{apiKey:c(r).trim()}}),Pe("API key saved (effective next session)","success");b(i,null),b(r,""),e.onsecretsupdate()}catch(Y){Pe(Y.message,"error")}finally{b(l,!1)}}}function p(Y){Y.key==="Escape"?u():Y.key==="Enter"&&(Y.preventDefault(),_())}var v=mp(),x=Ce(v),y=h(x),w=f(h(y),2),S=h(w);{var E=Y=>{var G=zv(),re=f(h(G),2),Re=h(re);O(et=>M(Re,et),[()=>Vh(e.status.uptime)]),k(Y,G)};H(S,Y=>{e.status&&Y(E)})}var K=f(S,2),A=f(h(K),2),U=h(A);{var ee=Y=>{xt(Y,{mono:!0,get saving(){return e.editor.editingSaving},onsave:G=>e.editor.saveField("timezone",G),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(G){b(s,G,!0)}})},X=Y=>{var G=Nv(),re=h(G);O(()=>M(re,e.config.timezone)),V("click",G,()=>a("timezone",e.config.timezone)),k(Y,G)};H(U,Y=>{e.editor.editingField==="timezone"?Y(ee):Y(X,!1)})}var C=f(K,2),F=f(h(C),2),L=h(F),j=f(C,2),oe=f(h(j),2),de=h(oe);{var J=Y=>{const G=Ae(()=>c(n).has("claude")),re=Ae(()=>c(n).has("opencode"));var Re=Vv(),et=Ce(Re);{var yt=ze=>{var $e=Uv();k(ze,$e)};H(et,ze=>{c(G)&&ze(yt)})}var Xt=f(et,2);{var Wt=ze=>{var $e=Hv();k(ze,$e)};H(Xt,ze=>{c(re)&&ze(Wt)})}var St=f(Xt,2);{var rs=ze=>{var $e=Ov();k(ze,$e)};H(St,ze=>{!c(G)&&!c(re)&&ze(rs)})}k(Y,Re)},N=Y=>{var G=bt(),re=Ce(G);Et(re,17,()=>[{key:"claude",info:e.doctor.claude},{key:"opencode",info:e.doctor.opencode}],Vr,(Re,et)=>{let yt=()=>c(et).key,Xt=()=>c(et).info;const Wt=Ae(()=>c(n).has(yt()));var St=bt(),rs=Ce(St);{var ze=ls=>{var kt=Gv(),zt=f(h(kt));O(()=>M(zt,` ${yt()??""} ${Xt().version??""}`)),k(ls,kt)},$e=ls=>{var kt=qv(),zt=f(h(kt));O(()=>M(zt,` ${yt()??""} not found`)),k(ls,kt)},Vs=ls=>{var kt=Wv(),zt=f(h(kt));O(()=>M(zt,` ${yt()??""} ${Xt().version??""}`)),k(ls,kt)};H(rs,ls=>{c(Wt)&&Xt().available?ls(ze):c(Wt)&&!Xt().available?ls($e,1):!c(Wt)&&Xt().available&&ls(Vs,2)})}k(Re,St)}),k(Y,G)};H(de,Y=>{e.doctorLoading?Y(J):e.doctor&&Y(N,1)})}var se=f(j,2);{var ae=Y=>{var G=jv(),re=f(h(G),2),Re=h(re);O(()=>M(Re,e.doctor.node)),k(Y,G)};H(se,Y=>{e.doctor&&Y(ae)})}var ke=f(se,2),we=f(h(ke),2),fe=h(we);{var Z=Y=>{var G=Zv(),re=h(G),Re=f(re,2),et=h(Re);{var yt=St=>{var rs=Is("...");k(St,rs)},Xt=St=>{var rs=Yv();k(St,rs)};H(et,St=>{c(l)?St(yt):St(Xt,!1)})}var Wt=f(Re,2);O(()=>Re.disabled=c(l)||!c(r)),V("keydown",re,p),Ve(re,()=>c(r),St=>b(r,St)),V("click",Re,_),V("click",Wt,u),k(Y,G)},le=Y=>{var G=Jv(),re=h(G);O(()=>M(re,e.secrets.anthropic.set?e.secrets.anthropic.hint:"not set")),V("click",G,()=>o("apiKey")),k(Y,G)},be=Y=>{var G=$v();k(Y,G)};H(fe,Y=>{c(i)==="apiKey"?Y(Z):e.secrets?Y(le,1):Y(be,!1)})}var ue=f(y,2),ve=f(h(ue),2),_e=h(ve),ye=f(h(_e),2),ce=h(ye);{var pe=Y=>{xt(Y,{mono:!0,get saving(){return e.editor.editingSaving},onsave:G=>e.editor.saveField("sessions.maxConcurrent",G,re=>Number(re)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(G){b(s,G,!0)}})},$=Y=>{var G=ep(),re=h(G);O(()=>M(re,e.config.sessions.maxConcurrent)),V("click",G,()=>a("sessions.maxConcurrent",e.config.sessions.maxConcurrent)),k(Y,G)};H(ce,Y=>{e.editor.editingField==="sessions.maxConcurrent"?Y(pe):Y($,!1)})}var Se=f(_e,2),he=f(h(Se),2),Le=h(he);{var Te=Y=>{xt(Y,{mono:!0,get saving(){return e.editor.editingSaving},onsave:G=>e.editor.saveField("sessions.ttlHours",G,re=>Number(re)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(G){b(s,G,!0)}})},Be=Y=>{var G=tp(),re=h(G);O(()=>M(re,`${e.config.sessions.ttlHours??""}h`)),V("click",G,()=>a("sessions.ttlHours",e.config.sessions.ttlHours)),k(Y,G)};H(Le,Y=>{e.editor.editingField==="sessions.ttlHours"?Y(Te):Y(Be,!1)})}var ne=f(Se,2),te=f(h(ne),2),ge=h(te);{var tt=Y=>{xt(Y,{mono:!0,get saving(){return e.editor.editingSaving},onsave:G=>e.editor.saveField("sessions.processTimeoutMs",G,re=>Math.round(Number(re)*1e3)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(G){b(s,G,!0)}})},is=Y=>{var G=sp(),re=h(G);O(Re=>M(re,`${Re??""}s`),[()=>(e.config.sessions.processTimeoutMs/1e3).toFixed(0)]),V("click",G,()=>a("sessions.processTimeoutMs",(e.config.sessions.processTimeoutMs/1e3).toFixed(0))),k(Y,G)};H(ge,Y=>{e.editor.editingField==="sessions.processTimeoutMs"?Y(tt):Y(is,!1)})}var Gt=f(ue,2),Zt=h(Gt),at=f(h(Zt),2);{var hs=Y=>{var G=np();let re;var Re=h(G);let et;var yt=f(Re);O(()=>{re=me(G,1,"svc-chip",null,re,{"svc-chip-ok":e.status.slack.connected,"svc-chip-err":!e.status.slack.connected}),et=me(Re,1,"dot",null,et,{"dot-on":e.status.slack.connected,"dot-off":!e.status.slack.connected}),M(yt,` ${e.status.slack.connected?"connected":"disconnected"}`)}),k(Y,G)};H(at,Y=>{e.status&&Y(hs)})}var Jt=f(Zt,2);{const Y=(G,re=ba,Re=ba,et=ba,yt=ba)=>{var Xt=op(),Wt=h(Xt),St=h(Wt),rs=f(Wt,2),ze=h(rs);{var $e=kt=>{var zt=ip(),os=h(zt),_s=f(os,2),zi=h(_s);{var Ld=on=>{var Ni=Is("...");k(on,Ni)},Pd=on=>{var Ni=ap();k(on,Ni)};H(zi,on=>{c(l)?on(Ld):on(Pd,!1)})}var Bd=f(_s,2);O(()=>{ns(os,"placeholder",et()),_s.disabled=c(l)||!c(r)}),V("keydown",os,p),Ve(os,()=>c(r),on=>b(r,on)),V("click",_s,_),V("click",Bd,u),k(kt,zt)},Vs=kt=>{var zt=rp(),os=h(zt);O(()=>M(os,yt().set?yt().hint:"not set")),V("click",zt,()=>o(re())),k(kt,zt)},ls=kt=>{var zt=lp();k(kt,zt)};H(ze,kt=>{c(i)===re()?kt($e):yt()?kt(Vs,1):kt(ls,!1)})}O(()=>M(St,Re())),k(G,Xt)};var fs=h(Jt);{var ft=G=>{var re=cp();k(G,re)};H(fs,G=>{c(d)&&G(ft)})}var $t=f(fs,2);Y($t,()=>"slackBotToken",()=>"Bot Token",()=>"xoxb-...",()=>e.secrets?.slack.botToken);var an=f($t,2);Y(an,()=>"slackAppToken",()=>"App Token",()=>"xapp-...",()=>e.secrets?.slack.appToken);var Ns=f(an,2),En=f(h(Ns),2),Us=h(En);Pn(Us,{get active(){return e.config.slack.requireMention},onToggle:()=>e.editor.toggleField("slack.requireMention",e.config.slack.requireMention)});var ys=f(Ns,2),Hs=f(h(ys),2),Ms=h(Hs);{var ks=G=>{xt(G,{mono:!0,get saving(){return e.editor.editingSaving},onsave:re=>e.editor.saveField("slack.coalesce.debounceMs",re,Re=>Number(Re)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(re){b(s,re,!0)}})},rn=G=>{var re=dp(),Re=h(re);O(()=>M(Re,`${e.config.slack.coalesce.debounceMs??""}ms`)),V("click",re,()=>a("slack.coalesce.debounceMs",e.config.slack.coalesce.debounceMs)),k(G,re)};H(Ms,G=>{e.editor.editingField==="slack.coalesce.debounceMs"?G(ks):G(rn,!1)})}var Xs=f(ys,2),ln=f(h(Xs),2),qe=h(ln);Pn(qe,{get active(){return e.config.slack.coalesce.bypassDms},onToggle:()=>e.editor.toggleField("slack.coalesce.bypassDms",e.config.slack.coalesce.bypassDms)});var We=f(Xs,2),_t=f(h(We),2),ct=h(_t);{var At=G=>{xt(G,{mono:!0,get saving(){return e.editor.editingSaving},onsave:re=>e.editor.saveField("slack.channels",re,Re=>Re.split(",").map(et=>et.trim()).filter(Boolean)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(re){b(s,re,!0)}})},dt=G=>{var re=up(),Re=h(re);O(et=>M(Re,et),[()=>e.config.slack.channels.join(", ")||"*"]),V("click",re,()=>a("slack.channels",e.config.slack.channels.join(", "))),k(G,re)};H(ct,G=>{e.editor.editingField==="slack.channels"?G(At):G(dt,!1)})}var je=f(We,2),vt=f(h(je),2),Ze=h(vt);Pn(Ze,{get active(){return e.config.slack.quietHours.enabled},onToggle:()=>e.editor.toggleField("slack.quietHours.enabled",e.config.slack.quietHours.enabled)});var W=f(je,2);{var ie=G=>{var re=_p(),Re=f(h(re),2),et=h(Re);{var yt=ze=>{xt(ze,{mono:!0,get saving(){return e.editor.editingSaving},placeholder:"HH:MM",onsave:$e=>e.editor.saveField("slack.quietHours.start",$e),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value($e){b(s,$e,!0)}})},Xt=ze=>{var $e=hp(),Vs=h($e);O(()=>M(Vs,e.config.slack.quietHours.start)),V("click",$e,()=>a("slack.quietHours.start",e.config.slack.quietHours.start)),k(ze,$e)};H(et,ze=>{e.editor.editingField==="slack.quietHours.start"?ze(yt):ze(Xt,!1)})}var Wt=f(et,4);{var St=ze=>{xt(ze,{mono:!0,get saving(){return e.editor.editingSaving},placeholder:"HH:MM",onsave:$e=>e.editor.saveField("slack.quietHours.end",$e),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value($e){b(s,$e,!0)}})},rs=ze=>{var $e=fp(),Vs=h($e);O(()=>M(Vs,e.config.slack.quietHours.end)),V("click",$e,()=>a("slack.quietHours.end",e.config.slack.quietHours.end)),k(ze,$e)};H(Wt,ze=>{e.editor.editingField==="slack.quietHours.end"?ze(St):ze(rs,!1)})}k(G,re)};H(W,G=>{e.config.slack.quietHours.enabled&&G(ie)})}}var xe=f(Gt,2),Me=h(xe),Ue=f(h(Me),2);{var Ye=Y=>{var G=vp();let re;var Re=h(G);let et;var yt=f(Re);O(()=>{re=me(G,1,"svc-chip",null,re,{"svc-chip-ok":e.status.browser.connected,"svc-chip-err":!e.status.browser.connected}),et=me(Re,1,"dot",null,et,{"dot-on":e.status.browser.connected,"dot-off":!e.status.browser.connected}),M(yt,` ${e.status.browser.connected?"connected":"unreachable"}`)}),k(Y,G)};H(Ue,Y=>{e.config.browser.enabled&&e.status&&Y(Ye)})}var ut=f(Me,2),pt=h(ut),Rt=f(h(pt),2),Mt=h(Rt);Pn(Mt,{get active(){return e.config.browser.enabled},onToggle:()=>e.editor.toggleField("browser.enabled",e.config.browser.enabled)});var It=f(pt,2);{var Ls=Y=>{var G=gp(),re=Ce(G),Re=f(h(re),2),et=h(Re);{var yt=os=>{xt(os,{mono:!0,get saving(){return e.editor.editingSaving},onsave:_s=>e.editor.saveField("browser.novncHost",_s),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(_s){b(s,_s,!0)}})},Xt=os=>{var _s=pp(),zi=h(_s);O(()=>M(zi,e.config.browser.novncHost)),V("click",_s,()=>a("browser.novncHost",e.config.browser.novncHost)),k(os,_s)};H(et,os=>{e.editor.editingField==="browser.novncHost"?os(yt):os(Xt,!1)})}var Wt=f(re,2),St=f(h(Wt),2),rs=h(St),ze=f(Wt,2),$e=f(h(ze),2),Vs=h($e),ls=f(ze,2),kt=f(h(ls),2),zt=h(kt);O(()=>{M(rs,e.config.browser.mode),M(Vs,e.config.browser.vncPort),M(zt,e.config.browser.novncPort)}),k(Y,G)};H(It,Y=>{e.config.browser.enabled&&Y(Ls)})}var Xe=f(xe,2),Je=f(h(Xe),2),it=h(Je),Qt=f(h(it),2),qt=h(Qt);{var An=Y=>{xt(Y,{mono:!0,get saving(){return e.editor.editingSaving},onsave:G=>e.editor.saveField("birds.maxAttempts",G,re=>Number(re)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(G){b(s,G,!0)}})},Os=Y=>{var G=xp(),re=h(G);O(()=>M(re,e.config.birds.maxAttempts)),V("click",G,()=>a("birds.maxAttempts",e.config.birds.maxAttempts)),k(Y,G)};H(qt,Y=>{e.editor.editingField==="birds.maxAttempts"?Y(An):Y(Os,!1)})}var Ps=f(Xe,2),da=f(h(Ps),2),Qi=h(da),Kd=f(h(Qi),2),Fd=h(Kd);{var Td=Y=>{xt(Y,{mono:!0,get saving(){return e.editor.editingSaving},onsave:G=>e.editor.saveField("database.retentionDays",G,re=>Number(re)),get oncancel(){return e.editor.cancelEdit},get value(){return c(s)},set value(G){b(s,G,!0)}})},Md=Y=>{var G=bp(),re=h(G);O(()=>M(re,`${e.config.database.retentionDays??""} days`)),V("click",G,()=>a("database.retentionDays",e.config.database.retentionDays)),k(Y,G)};H(Fd,Y=>{e.editor.editingField==="database.retentionDays"?Y(Td):Y(Md,!1)})}var Xd=f(x,2);Qv(Xd,{get config(){return e.config},get editor(){return e.editor}}),O(()=>M(L,e.config.web.port)),k(t,v),nt()}ht(["click","keydown"]);var yp=T('<span class="queue-summary mono svelte-17vayue"> </span>'),kp=T('<div class="stat-row svelte-17vayue"><div class="stat-cell svelte-17vayue"><span class="stat-num svelte-17vayue"> </span> <span class="stat-lbl svelte-17vayue">pending</span></div> <div class="stat-cell svelte-17vayue"><span class="stat-num stat-num-active svelte-17vayue"> </span> <span class="stat-lbl svelte-17vayue">running</span></div> <div class="stat-cell svelte-17vayue"><span class="stat-num stat-num-ok svelte-17vayue"> </span> <span class="stat-lbl svelte-17vayue">completed</span></div> <div class="stat-cell svelte-17vayue"><span class="stat-num stat-num-err svelte-17vayue"> </span> <span class="stat-lbl svelte-17vayue">failed</span></div></div>'),Sp=T('<div class="panel"><div class="panel-header"><span class="panel-title">Job Queue</span> <!></div> <div class="panel-body"><!> <div class="action-row svelte-17vayue"><button class="btn btn-outline btn-sm"> </button> <button class="btn btn-outline btn-sm"> </button> <button class="btn btn-outline btn-sm"> </button></div></div></div>');function Cp(t,e){st(e,!0);let s=q(null);mt(()=>{e.initialStats!=null&&b(s,e.initialStats,!0)});let n=q(!1),a=q(!1),i=q(!1);async function r(){b(s,await Ee("/api/jobs/stats"),!0)}async function l(){b(n,!0);try{const C=await Ee("/api/jobs/retry-all",{method:"POST"});Pe(`${C.count} failed job(s) queued for retry`,"success"),await r()}catch(C){Pe(`Failed: ${C.message}`,"error")}finally{b(n,!1)}}async function d(){b(a,!0);try{const C=await Ee("/api/jobs/clear?status=completed",{method:"DELETE"});Pe(`${C.count} completed job(s) cleared`,"success"),await r()}catch(C){Pe(`Failed: ${C.message}`,"error")}finally{b(a,!1)}}async function o(){b(i,!0);try{const C=await Ee("/api/jobs/clear?status=failed",{method:"DELETE"});Pe(`${C.count} failed job(s) cleared`,"success"),await r()}catch(C){Pe(`Failed: ${C.message}`,"error")}finally{b(i,!1)}}var u=Sp(),_=h(u),p=f(h(_),2);{var v=C=>{var F=yp(),L=h(F);O(()=>M(L,`${c(s).total??""} total`)),k(C,F)};H(p,C=>{c(s)&&C(v)})}var x=f(_,2),y=h(x);{var w=C=>{var F=kp(),L=h(F),j=h(L),oe=h(j),de=f(L,2),J=h(de),N=h(J),se=f(de,2),ae=h(se),ke=h(ae),we=f(se,2),fe=h(we),Z=h(fe);O(()=>{M(oe,c(s).pending),M(N,c(s).running),M(ke,c(s).completed),M(Z,c(s).failed)}),k(C,F)};H(y,C=>{c(s)&&C(w)})}var S=f(y,2),E=h(S),K=h(E),A=f(E,2),U=h(A),ee=f(A,2),X=h(ee);O(()=>{E.disabled=c(n)||(c(s)?.failed??0)===0,M(K,c(n)?"Retrying...":"Retry Failed"),A.disabled=c(a)||(c(s)?.completed??0)===0,M(U,c(a)?"Clearing...":"Clear Completed"),ee.disabled=c(i)||(c(s)?.failed??0)===0,M(X,c(i)?"Clearing...":"Clear Failed")}),V("click",E,l),V("click",A,d),V("click",ee,o),k(t,u),nt()}ht(["click"]);var Ep=T('<div class="row"><span class="dim">No system birds registered</span></div>'),Ap=T('<span class="bird-last-run svelte-12folcn"> <!></span>'),Kp=T('<button class="btn btn-outline btn-sm">Flights</button>'),Fp=T('<div class="flight-empty svelte-12folcn"><span class="dim">No flights recorded</span></div>'),Tp=T('<div class="flight-row svelte-12folcn"><span class="mono flight-id svelte-12folcn"> </span> <!> <span class="mono"> </span> <span class="flight-time svelte-12folcn"> </span></div>'),Mp=T('<div class="flight-list svelte-12folcn"><!></div>'),Xp=T('<div><div class="bird-top svelte-12folcn"><div class="bird-info svelte-12folcn"><span class="bird-name mono svelte-12folcn"> </span> <span class="bird-schedule mono dim svelte-12folcn"> </span></div> <div class="bird-actions svelte-12folcn"><!> <!> <button class="btn btn-outline btn-sm">Fly</button></div></div> <!></div>'),Lp=T('<div class="panel"><div class="panel-header"><span class="panel-title">System Birds</span> <span class="bird-count mono svelte-12folcn"> </span></div> <div class="panel-body"><!></div></div>');function Pp(t,e){st(e,!0);let s=q(He({}));async function n(v){if(!c(s)[v])try{const x=await Ee(`/api/birds/${v}/flights?perPage=5`);b(s,{...c(s),[v]:x.items},!0)}catch{b(s,{...c(s),[v]:[]},!0)}}async function a(v,x){try{const y=await Ee(`/api/birds/${v}/fly`,{method:"POST"});Pe(`${x} sent on a flight (job #${y.jobId})`,"success");const{[v]:w,...S}=c(s);b(s,S,!0)}catch(y){Pe(`Failed: ${y.message}`,"error")}}var i=Lp(),r=h(i),l=f(h(r),2),d=h(l),o=f(r,2),u=h(o);{var _=v=>{var x=Ep();k(v,x)},p=v=>{var x=bt(),y=Ce(x);Et(y,19,()=>e.birds,w=>w.uid,(w,S,E)=>{var K=Xp();let A;var U=h(K),ee=h(U),X=h(ee),C=h(X),F=f(X,2),L=h(F),j=f(ee,2),oe=h(j);{var de=we=>{var fe=Ap(),Z=h(fe),le=f(Z);{var be=ue=>{mn(ue,{get status(){return c(S).last_status}})};H(le,ue=>{c(S).last_status&&ue(be)})}O(ue=>M(Z,`${ue??""} `),[()=>xs(c(S).last_run)]),k(we,fe)};H(oe,we=>{c(S).last_run&&we(de)})}var J=f(oe,2);{var N=we=>{var fe=Kp();V("click",fe,()=>n(c(S).uid)),k(we,fe)};H(J,we=>{c(s)[c(S).uid]||we(N)})}var se=f(J,2),ae=f(U,2);{var ke=we=>{var fe=Mp(),Z=h(fe);{var le=ue=>{var ve=Fp();k(ue,ve)},be=ue=>{var ve=bt(),_e=Ce(ve);Et(_e,17,()=>c(s)[c(S).uid],ye=>ye.uid,(ye,ce)=>{var pe=Tp(),$=h(pe),Se=h($),he=f($,2);mn(he,{get status(){return c(ce).status}});var Le=f(he,2),Te=h(Le),Be=f(Le,2),ne=h(Be);O((te,ge,tt)=>{M(Se,te),M(Te,ge),M(ne,tt)},[()=>Kt(c(ce).uid),()=>bi(c(ce).started_at,c(ce).finished_at),()=>xs(c(ce).started_at)]),k(ye,pe)}),k(ue,ve)};H(Z,ue=>{c(s)[c(S).uid].length===0?ue(le):ue(be,!1)})}k(we,fe)};H(ae,we=>{c(s)[c(S).uid]!=null&&we(ke)})}O(()=>{A=me(K,1,"bird-entry svelte-12folcn",null,A,{"bird-entry-border":c(E)<e.birds.length-1}),M(C,c(S).name),M(L,c(S).schedule)}),V("click",se,()=>a(c(S).uid,c(S).name)),k(w,K)}),k(v,x)};H(u,v=>{e.birds.length===0?v(_):v(p,!1)})}O(()=>M(d,e.birds.length)),k(t,i),nt()}ht(["click"]);var Bp=T('<span class="error-count svelte-ht9bxs"> </span>'),Dp=T('<div class="row"><span class="dim">No errors recorded</span></div>'),Rp=T('<div class="error-entry svelte-ht9bxs"><div class="error-top svelte-ht9bxs"><span class="error-source mono svelte-ht9bxs"> </span> <span class="error-time svelte-ht9bxs"> </span></div> <span class="error-message svelte-ht9bxs"> </span></div>'),Ip=T('<div class="db-grid svelte-ht9bxs"><!> <div class="panel"><div class="panel-header"><span class="panel-title">Recent Errors</span> <!></div> <div class="panel-body"><!></div></div></div> <!>',1);function Qp(t,e){st(e,!0);var s=Ip(),n=Ce(s),a=h(n);Cp(a,{get initialStats(){return e.jobStats}});var i=f(a,2),r=h(i),l=f(h(r),2);{var d=x=>{var y=Bp(),w=h(y);O(()=>M(w,e.recentErrors.length)),k(x,y)};H(l,x=>{e.recentErrors.length>0&&x(d)})}var o=f(r,2),u=h(o);{var _=x=>{var y=Dp();k(x,y)},p=x=>{var y=bt(),w=Ce(y);Et(w,17,()=>e.recentErrors,S=>S.id,(S,E)=>{var K=Rp(),A=h(K),U=h(A),ee=h(U),X=f(U,2),C=h(X),F=f(A,2),L=h(F);O(j=>{M(ee,c(E).source),M(C,j),M(L,c(E).message)},[()=>xs(c(E).created_at)]),k(S,K)}),k(x,y)};H(u,x=>{e.recentErrors.length===0?x(_):x(p,!1)})}var v=f(n,2);Pp(v,{get birds(){return e.systemBirds}}),k(t,s),nt()}var zp=T('<div class="loading">Loading...</div>'),Np=T('<div class="tabs svelte-1ozf5k3"><button>Config</button> <button>Database</button></div> <!> <!>',1);function Up(t,e){st(e,!0);let s=q(null),n=q(null),a=q(null),i=q(!0),r=q(He([])),l=q(null),d=q(He([])),o=q(!0),u=q("config"),_=q(null),p=q(!1);mt(()=>{const F=new AbortController;return Promise.all([Ee("/api/config"),Ee("/api/logs?level=error&perPage=10"),Ee("/api/jobs/stats"),Ee("/api/birds?system=true&perPage=100"),Ee("/api/secrets")]).then(([L,j,oe,de,J])=>{F.signal.aborted||(b(s,L,!0),b(r,j.items,!0),b(l,oe,!0),b(d,de.items.filter(N=>N.name.startsWith("__bb_")),!0),b(n,J,!0))}).finally(()=>{F.signal.aborted||b(o,!1)}),()=>F.abort()}),mt(()=>{const F=new AbortController;return Ee("/api/doctor").then(L=>{F.signal.aborted||b(a,L,!0)}).finally(()=>{F.signal.aborted||b(i,!1)}),()=>F.abort()}),mt(()=>Pi(F=>{F.resource==="config"&&Ee("/api/config").then(L=>{b(s,L,!0)}).catch(()=>{}),F.resource==="secrets"&&v()}));function v(){Ee("/api/secrets").then(F=>{b(n,F,!0)}).catch(()=>{})}function x(F,L){const j=F.split(".");let oe={};const de=oe;for(let J=0;J<j.length-1;J++){const N={};oe[j[J]]=N,oe=N}return oe[j[j.length-1]]=L,de}async function y(F){try{const L=await Ee("/api/config",{method:"PATCH",body:F});return b(s,L,!0),Pe("Config saved","success"),!0}catch(L){return Pe(`Failed: ${L.message}`,"error"),!1}}function w(F,L){b(_,F,!0),b(p,!1)}function S(){b(_,null),b(p,!1)}async function E(F,L,j){b(p,!0);const oe=j?j(L):L;await y(x(F,oe))?S():b(p,!1)}async function K(F,L){await y(x(F,!L))}const A=Ae(()=>({editingField:c(_),editingSaving:c(p),startEdit:w,cancelEdit:S,saveField:E,toggleField:K,saveConfigPatch:y}));var U=bt(),ee=Ce(U);{var X=F=>{var L=zp();k(F,L)},C=F=>{var L=Np(),j=Ce(L),oe=h(j);let de;var J=f(oe,2);let N;var se=f(j,2);{var ae=fe=>{wp(fe,{get config(){return c(s)},get status(){return e.status},get doctor(){return c(a)},get doctorLoading(){return c(i)},get editor(){return c(A)},get secrets(){return c(n)},onsecretsupdate:v})};H(se,fe=>{c(u)==="config"&&fe(ae)})}var ke=f(se,2);{var we=fe=>{Qp(fe,{get jobStats(){return c(l)},get systemBirds(){return c(d)},get recentErrors(){return c(r)}})};H(ke,fe=>{c(u)==="database"&&fe(we)})}O(()=>{de=me(oe,1,"tab svelte-1ozf5k3",null,de,{"tab-active":c(u)==="config"}),N=me(J,1,"tab svelte-1ozf5k3",null,N,{"tab-active":c(u)==="database"})}),V("click",oe,()=>{b(u,"config")}),V("click",J,()=>{b(u,"database")}),k(F,L)};H(ee,F=>{c(o)?F(X):c(s)&&F(C,1)})}k(t,U),nt()}ht(["click"]);var Hp=T('<div class="card-sub svelte-1tf674w"> </div>'),Op=T('<div><div class="card-label svelte-1tf674w"> </div> <div class="card-value svelte-1tf674w"> </div> <!></div>');function hr(t,e){var s=Op();let n;var a=h(s),i=h(a),r=f(a,2),l=h(r),d=f(r,2);{var o=u=>{var _=Hp(),p=h(_);O(()=>M(p,e.sub)),k(u,_)};H(d,u=>{e.sub&&u(o)})}O(()=>{n=me(s,1,"stat-card svelte-1tf674w",null,n,{"stat-card-info":e.variant==="info","stat-card-warning":e.variant==="warning","stat-card-success":e.variant==="success","stat-card-error":e.variant==="error"}),M(i,e.label),M(l,e.value)}),k(t,s)}var Vp=T('<div class="error-state svelte-1lyclyh"><p> </p> <button class="btn btn-outline btn-sm">Back to Sessions</button></div>'),Gp=T('<div class="loading">Loading...</div>'),qp=T('<div class="filter-spacer svelte-1lyclyh"></div> <span class="last-updated svelte-1lyclyh"> </span>',1),Wp=T('<tr><td><!></td><td class="mono"> </td><td class="content-cell svelte-1lyclyh"> </td><td class="mono"> </td><td class="mono"> </td><td> </td></tr>'),jp=T('<div class="detail-header svelte-1lyclyh"><button class="btn btn-outline btn-sm"><svg class="back-icon svelte-1lyclyh" viewBox="0 0 6 10" fill="none" aria-hidden="true"><path d="M5 1L1 5L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg> Sessions</button> <h2 class="session-title svelte-1lyclyh"> </h2> <span class="session-meta svelte-1lyclyh"><span class="mono"> </span> <span class="meta-sep svelte-1lyclyh"></span> <span class="meta-sep svelte-1lyclyh"></span> </span></div> <div class="stat-cards svelte-1lyclyh"><!> <!> <!></div> <!>',1);function Yp(t,e){st(e,!0);const s=Li().get("id")??"",n=[{key:"direction",label:"Dir"},{key:"user_id",label:"User",sortable:!0},{key:"content",label:"Content"},{key:"tokens_in",label:"Tokens In"},{key:"tokens_out",label:"Tokens Out"},{key:"created_at",label:"Time",sortable:!0}];let a=q(He(kn())),i=q(null),r=q(null),l=q("");const d=s?Yr({endpoint:`/api/sessions/${s}`,columns:n,defaultSort:"created_at",invalidateOn:"sessions",transformResponse:y=>y.messages,onResponse:y=>{b(a,kn(),!0),b(i,y.session,!0),b(r,y.stats,!0)}}):null;d||b(l,"Invalid session ID");function o(){window.location.hash="#/sessions"}var u=bt(),_=Ce(u);{var p=y=>{var w=Vp(),S=h(w),E=h(S),K=f(S,2);O(()=>M(E,c(l))),V("click",K,o),k(y,w)},v=y=>{var w=Gp();k(y,w)},x=y=>{var w=jp(),S=Ce(w),E=h(S),K=f(E,2),A=h(K),U=f(K,2),ee=h(U),X=h(ee),C=f(ee,3),F=f(C,2),L=f(S,2),j=h(L);hr(j,{label:"Messages",get value(){return c(i).message_count}});var oe=f(j,2);{let N=Ae(()=>c(r).totalTokensIn.toLocaleString());hr(oe,{label:"Tokens In",get value(){return c(N)}})}var de=f(oe,2);{let N=Ae(()=>c(r).totalTokensOut.toLocaleString());hr(de,{label:"Tokens Out",get value(){return c(N)}})}var J=f(L,2);{const N=ae=>{var ke=qp(),we=f(Ce(ke),2),fe=h(we);O(()=>M(fe,`Updated ${c(a)??""}`)),k(ae,ke)};let se=Ae(()=>d.items.length===0);hn(J,{get columns(){return n},get isEmpty(){return c(se)},emptyMessage:"No messages recorded for this session",get fetching(){return d.fetching},get page(){return d.page},get totalPages(){return d.totalPages},get totalItems(){return d.totalItems},get sort(){return d.sort},get search(){return d.search},searchPlaceholder:"Search messages...",get onPageChange(){return d.setPage},get onSortChange(){return d.setSort},get onSearchChange(){return d.setSearch},toolbar:N,children:(ae,ke)=>{var we=bt(),fe=Ce(we);Et(fe,17,()=>d.items,Z=>Z.id,(Z,le)=>{var be=Wp(),ue=h(be),ve=h(ue);{let ne=Ae(()=>c(le).direction==="in"?"info":"success");mn(ve,{get status(){return c(ne)}})}var _e=f(ue),ye=h(_e),ce=f(_e),pe=h(ce),$=f(ce),Se=h($),he=f($),Le=h(he),Te=f(he),Be=h(Te);O(ne=>{M(ye,c(le).user_id),M(pe,c(le).content??"-"),M(Se,c(le).tokens_in??"-"),M(Le,c(le).tokens_out??"-"),M(Be,ne)},[()=>xs(c(le).created_at)]),k(Z,be)}),k(ae,we)},$$slots:{toolbar:!0,default:!0}})}O((N,se)=>{M(A,`Session ${N??""}`),M(X,c(i).channel_id),M(C,` ${c(i).agent_id??""} `),M(F,` ${se??""}`)},[()=>Kt(c(i).uid),()=>xs(c(i).last_active)]),V("click",E,o),k(y,w)};H(_,y=>{c(l)?y(p):d?.loading?y(v,1):c(i)&&c(r)&&d&&y(x,2)})}k(t,u),nt()}ht(["click"]);var Zp=T("<div></div>"),Jp=T('<div><span class="step-number svelte-dm5b3b"></span></div> <!>',1),$p=T('<div class="step-indicator svelte-dm5b3b"></div>'),eg=T('<div class="login-error svelte-dm5b3b"> </div>'),tg=T(`<p class="onboarding-desc svelte-dm5b3b"><a target="_blank" rel="noopener" class="onboarding-link svelte-dm5b3b">Create a Slack app from the manifest</a>.</p> <form><label class="form-label">Bot Token <input type="password" class="form-input" placeholder="xoxb-..." autocomplete="off"/> <span class="form-hint svelte-dm5b3b">OAuth & Permissions, click "Install to Workspace", then copy the token</span></label> <label class="form-label">App Token <input type="password" class="form-input" placeholder="xapp-..." autocomplete="off"/> <span class="form-hint svelte-dm5b3b">Basic Information, click "Generate Token and Scopes", add connections:write, then copy
|
|
7
|
+
the token</span></label> <!> <button type="submit" class="btn btn-primary onboarding-submit svelte-dm5b3b"> </button></form>`,1),sg=T('<div class="login-error svelte-dm5b3b"> </div>'),ng=T('<p class="onboarding-desc svelte-dm5b3b">Configure your first agent. You can add more agents and change settings later.</p> <form><label class="form-label">Name <input type="text" class="form-input" placeholder="BrowserBird"/></label> <div class="form-row svelte-dm5b3b"><label class="form-label">Provider <select class="form-input"><option>Claude</option><option>OpenCode</option></select></label> <label class="form-label">Model <input type="text" class="form-input" placeholder="sonnet"/></label></div> <label class="form-label">System Prompt <textarea class="form-textarea" rows="3"></textarea></label> <label class="form-label">Anthropic Key <input type="password" class="form-input" placeholder="sk-ant-..." autocomplete="off"/> <span class="form-hint svelte-dm5b3b">API key from platform.claude.com/settings/keys</span></label> <!> <div class="onboarding-actions svelte-dm5b3b"><button type="button" class="btn btn-outline">Back</button> <button type="submit" class="btn btn-primary"> </button></div></form>',1),ag=T('<div class="probe-result probe-ok svelte-dm5b3b">Connected</div>'),ig=T('<div class="probe-result probe-fail svelte-dm5b3b">Not reachable. Make sure the VM container is running.</div>'),rg=T('<label class="form-label">VM Host <div class="probe-row svelte-dm5b3b"><input type="text" class="form-input svelte-dm5b3b" placeholder="vm"/> <button type="button" class="btn btn-outline btn-sm"> </button></div> <span class="form-hint svelte-dm5b3b">Hostname of the VM container (e.g. vm, vm.internal, localhost)</span></label> <!>',1),lg=T('<div class="login-error svelte-dm5b3b"> </div>'),og=T('<p class="onboarding-desc svelte-dm5b3b">Optionally enable browser access for your agent. You can configure this later.</p> <form><div class="browser-toggle svelte-dm5b3b"><span class="browser-toggle-label svelte-dm5b3b">Enable browser</span> <!></div> <!> <!> <div class="onboarding-actions svelte-dm5b3b"><button type="button" class="btn btn-outline">Back</button> <div class="onboarding-actions-right svelte-dm5b3b"><button type="button" class="btn btn-outline"> </button> <button type="submit" class="btn btn-primary"> </button></div></div></form>',1),cg=T('<div class="launch-summary svelte-dm5b3b"><div class="summary-row svelte-dm5b3b"><span class="summary-label svelte-dm5b3b">Slack</span> <span class="summary-value svelte-dm5b3b"> </span></div> <div class="summary-row svelte-dm5b3b"><span class="summary-label svelte-dm5b3b">Agent</span> <span class="summary-value svelte-dm5b3b"> </span></div> <div class="summary-row svelte-dm5b3b"><span class="summary-label svelte-dm5b3b">Browser</span> <span class="summary-value svelte-dm5b3b"> </span></div></div> <div class="done-tips svelte-dm5b3b"><div class="done-tip svelte-dm5b3b"><span class="done-tip-label svelte-dm5b3b">Mention your bot</span> <span class="done-tip-detail svelte-dm5b3b"> </span></div> <div class="done-tip svelte-dm5b3b"><span class="done-tip-label svelte-dm5b3b">Direct message</span> <span class="done-tip-detail svelte-dm5b3b">Open a DM with your bot in Slack</span></div> <div class="done-tip svelte-dm5b3b"><span class="done-tip-label svelte-dm5b3b">Slash commands</span> <span class="done-tip-detail svelte-dm5b3b">Type /bird in Slack to manage scheduled tasks</span></div> <div class="done-tip svelte-dm5b3b"><span class="done-tip-label svelte-dm5b3b">Scheduled tasks</span> <span class="done-tip-detail svelte-dm5b3b">Create birds from the dashboard, via /bird create, or ask your bot in Slack</span></div></div> <button type="button" class="btn btn-primary onboarding-submit svelte-dm5b3b">Go to Dashboard</button>',1),dg=T('<div class="login-error svelte-dm5b3b"> </div>'),ug=T('<!> <div class="onboarding-actions svelte-dm5b3b"><button type="button" class="btn btn-outline">Back</button> <button type="button" class="btn btn-primary"> </button></div>',1),hg=T('<div class="login-overlay svelte-dm5b3b"><div class="onboarding-card svelte-dm5b3b"><div class="onboarding-brand svelte-dm5b3b"><img src="/logo.svg" alt="BrowserBird" class="login-logo"/></div> <!> <h2 class="onboarding-heading svelte-dm5b3b"><!></h2> <!></div></div>');function fg(t,e){st(e,!0);const s=["Slack","Agent","Browser"],n="https://api.slack.com/apps?new_app=1&manifest_json=%7B%22display_information%22%3A%7B%22name%22%3A%22BrowserBird%22%2C%22description%22%3A%22A%20self-hosted%20AI%20assistant%20in%20Slack%2C%20with%20a%20real%20browser%20and%20a%20scheduler.%22%2C%22background_color%22%3A%22%231a1a2e%22%7D%2C%22features%22%3A%7B%22assistant_view%22%3A%7B%22assistant_description%22%3A%22A%20self-hosted%20AI%20assistant%20in%20Slack%2C%20with%20a%20real%20browser%20and%20a%20scheduler.%22%7D%2C%22app_home%22%3A%7B%22home_tab_enabled%22%3Atrue%2C%22messages_tab_enabled%22%3Atrue%2C%22messages_tab_read_only_enabled%22%3Afalse%7D%2C%22bot_user%22%3A%7B%22display_name%22%3A%22BrowserBird%22%2C%22always_online%22%3Atrue%7D%2C%22slash_commands%22%3A%5B%7B%22command%22%3A%22%2Fbird%22%2C%22description%22%3A%22Manage%20BrowserBird%20birds%22%2C%22usage_hint%22%3A%22list%20%7C%20fly%20%7C%20logs%20%7C%20enable%20%7C%20disable%20%7C%20create%20%7C%20status%22%2C%22should_escape%22%3Afalse%7D%5D%7D%2C%22oauth_config%22%3A%7B%22scopes%22%3A%7B%22bot%22%3A%5B%22app_mentions%3Aread%22%2C%22assistant%3Awrite%22%2C%22channels%3Ahistory%22%2C%22channels%3Aread%22%2C%22chat%3Awrite%22%2C%22files%3Aread%22%2C%22files%3Awrite%22%2C%22groups%3Ahistory%22%2C%22groups%3Aread%22%2C%22im%3Ahistory%22%2C%22im%3Aread%22%2C%22im%3Awrite%22%2C%22mpim%3Ahistory%22%2C%22mpim%3Aread%22%2C%22reactions%3Aread%22%2C%22reactions%3Awrite%22%2C%22users%3Aread%22%2C%22commands%22%5D%7D%7D%2C%22settings%22%3A%7B%22event_subscriptions%22%3A%7B%22bot_events%22%3A%5B%22app_mention%22%2C%22assistant_thread_context_changed%22%2C%22assistant_thread_started%22%2C%22message.channels%22%2C%22message.groups%22%2C%22message.im%22%2C%22message.mpim%22%5D%7D%2C%22interactivity%22%3A%7B%22is_enabled%22%3Atrue%7D%2C%22org_deploy_enabled%22%3Afalse%2C%22socket_mode_enabled%22%3Atrue%2C%22token_rotation_enabled%22%3Afalse%7D%7D";let a=q(0),i=q(!1),r=q(""),l=He({botToken:"",appToken:"",team:"",botUser:""}),d=He({name:"BrowserBird",provider:"claude",model:"sonnet",systemPrompt:"You are responding in a Slack workspace. Be concise, helpful, and natural.",maxTurns:50,channels:["*"],apiKey:""}),o=He({enabled:!1,novncHost:"localhost",novncPort:6080}),u=q("idle"),_=q(null);mt(()=>{wh().then(Z=>{b(_,Z,!0),d.name=Z.agent.name,d.provider=Z.agent.provider,d.model=Z.agent.model,d.systemPrompt=Z.agent.systemPrompt,d.maxTurns=Z.agent.maxTurns,d.channels=Z.agent.channels,o.enabled=Z.browser.enabled,o.novncHost=Z.browser.novncHost,o.novncPort=Z.browser.novncPort}).catch(()=>{})});async function p(Z){if(Z.preventDefault(),!(!l.botToken.trim()||!l.appToken.trim())){b(i,!0),b(r,"");try{const le=await yh(l.botToken.trim(),l.appToken.trim());l.team=le.team,l.botUser=le.botUser,b(a,1)}catch(le){b(r,le.message,!0)}finally{b(i,!1)}}}async function v(Z){if(Z.preventDefault(),!(!d.name.trim()||!d.provider.trim()||!d.model.trim())){if(!d.apiKey.trim()){b(r,"API key is required");return}b(i,!0),b(r,"");try{await kh({name:d.name.trim(),provider:d.provider.trim(),model:d.model.trim(),systemPrompt:d.systemPrompt.trim(),maxTurns:d.maxTurns,channels:d.channels}),await Sh({apiKey:d.apiKey.trim()}),b(a,2)}catch(le){b(r,le.message,!0)}finally{b(i,!1)}}}async function x(Z){Z.preventDefault(),b(i,!0),b(r,"");try{await Ch({enabled:o.enabled,novncHost:o.enabled?o.novncHost.trim():void 0}),await S()}catch(le){b(r,le.message,!0)}finally{b(i,!1)}}async function y(){b(i,!0),b(r,"");try{await S()}catch(Z){b(r,Z.message,!0)}finally{b(i,!1)}}let w=q(!1);async function S(){await Ah(),b(w,!0),b(a,3)}async function E(){b(i,!0),b(r,"");try{await S()}catch(Z){b(r,Z.message,!0)}finally{b(i,!1)}}async function K(){const Z=o.novncHost.trim();if(Z){b(u,"checking");try{const le=await Eh(Z,o.novncPort);b(u,le.reachable?"reachable":"unreachable",!0)}catch{b(u,"unreachable")}}}function A(){b(r,""),c(a)===3&&!c(w)?b(a,2):mr(a,-1)}var U=hg(),ee=h(U),X=f(h(ee),2);{var C=Z=>{var le=$p();Et(le,21,()=>s,Vr,(be,ue,ve)=>{var _e=Jp(),ye=Ce(_e);let ce;var pe=h(ye);pe.textContent=ve+1;var $=f(ye,2);{var Se=he=>{var Le=Zp();let Te;O(()=>Te=me(Le,1,"step-line svelte-dm5b3b",null,Te,{completed:ve<c(a)})),k(he,Le)};H($,he=>{ve<s.length-1&&he(Se)})}O(()=>ce=me(ye,1,"step-dot svelte-dm5b3b",null,ce,{active:ve===c(a),completed:ve<c(a)})),k(be,_e)}),k(Z,le)};H(X,Z=>{c(a)<s.length&&Z(C)})}var F=f(X,2),L=h(F);{var j=Z=>{var le=Is("Connect Slack");k(Z,le)},oe=Z=>{var le=Is("Configure Agent");k(Z,le)},de=Z=>{var le=Is("Browser");k(Z,le)},J=Z=>{var le=Is();O(()=>M(le,c(w)?"You're all set":"Launching...")),k(Z,le)};H(L,Z=>{c(a)===0?Z(j):c(a)===1?Z(oe,1):c(a)===2?Z(de,2):Z(J,!1)})}var N=f(F,2);{var se=Z=>{var le=tg(),be=Ce(le),ue=h(be);ns(ue,"href",n);var ve=f(be,2),_e=h(ve),ye=f(h(_e)),ce=f(_e,2),pe=f(h(ce)),$=f(ce,2);{var Se=Te=>{var Be=eg(),ne=h(Be);O(()=>M(ne,c(r))),k(Te,Be)};H($,Te=>{c(r)&&Te(Se)})}var he=f($,2),Le=h(he);O(()=>{he.disabled=c(i),M(Le,c(i)?"Validating...":"Validate & Save")}),In("submit",ve,p),Ve(ye,()=>l.botToken,Te=>l.botToken=Te),Ve(pe,()=>l.appToken,Te=>l.appToken=Te),k(Z,le)},ae=Z=>{var le=ng(),be=f(Ce(le),2),ue=h(be),ve=f(h(ue)),_e=f(ue,2),ye=h(_e),ce=f(h(ye)),pe=h(ce);pe.value=pe.__value="claude";var $=f(pe);$.value=$.__value="opencode";var Se=f(ye,2),he=f(h(Se)),Le=f(_e,2),Te=f(h(Le)),Be=f(Le,2),ne=f(h(Be)),te=f(Be,2);{var ge=at=>{var hs=sg(),Jt=h(hs);O(()=>M(Jt,c(r))),k(at,hs)};H(te,at=>{c(r)&&at(ge)})}var tt=f(te,2),is=h(tt),Gt=f(is,2),Zt=h(Gt);O(()=>{Gt.disabled=c(i),M(Zt,c(i)?"Saving...":"Save & Continue")}),In("submit",be,v),Ve(ve,()=>d.name,at=>d.name=at),Uc(ce,()=>d.provider,at=>d.provider=at),Ve(he,()=>d.model,at=>d.model=at),Ve(Te,()=>d.systemPrompt,at=>d.systemPrompt=at),Ve(ne,()=>d.apiKey,at=>d.apiKey=at),V("click",is,A),k(Z,le)},ke=Z=>{var le=og(),be=f(Ce(le),2),ue=h(be),ve=f(h(ue),2);Pn(ve,{get active(){return o.enabled},onToggle:()=>{o.enabled=!o.enabled,b(u,"idle")}});var _e=f(ue,2);{var ye=te=>{var ge=rg(),tt=Ce(ge),is=f(h(tt)),Gt=h(is),Zt=f(Gt,2),at=h(Zt),hs=f(tt,2);{var Jt=ft=>{var $t=ag();k(ft,$t)},fs=ft=>{var $t=ig();k(ft,$t)};H(hs,ft=>{c(u)==="reachable"?ft(Jt):c(u)==="unreachable"&&ft(fs,1)})}O(ft=>{Zt.disabled=ft,M(at,c(u)==="checking"?"Checking...":"Test Connection")},[()=>c(u)==="checking"||!o.novncHost.trim()]),V("input",Gt,()=>{b(u,"idle")}),Ve(Gt,()=>o.novncHost,ft=>o.novncHost=ft),V("click",Zt,K),k(te,ge)};H(_e,te=>{o.enabled&&te(ye)})}var ce=f(_e,2);{var pe=te=>{var ge=lg(),tt=h(ge);O(()=>M(tt,c(r))),k(te,ge)};H(ce,te=>{c(r)&&te(pe)})}var $=f(ce,2),Se=h($),he=f(Se,2),Le=h(he),Te=h(Le),Be=f(Le,2),ne=h(Be);O(()=>{Le.disabled=c(i),M(Te,c(i)?"Launching...":"Skip"),Be.disabled=c(i),M(ne,c(i)?"Launching...":"Save & Launch")}),In("submit",be,x),V("click",Se,A),V("click",Le,y),k(Z,le)},we=Z=>{var le=cg(),be=Ce(le),ue=h(be),ve=f(h(ue),2),_e=h(ve),ye=f(ue,2),ce=f(h(ye),2),pe=h(ce),$=f(ye,2),Se=f(h($),2),he=h(Se),Le=f(be,2),Te=h(Le),Be=f(h(Te),2),ne=h(Be),te=f(Le,2);O(()=>{M(_e,l.team||"Connected"),M(pe,`${d.name??""} (${d.provider??""}/${d.model??""})`),M(he,o.enabled?"Enabled":"Disabled"),M(ne,`@${d.name??""} in any channel`)}),V("click",te,function(...ge){e.oncomplete?.apply(this,ge)}),k(Z,le)},fe=Z=>{var le=ug(),be=Ce(le);{var ue=pe=>{var $=dg(),Se=h($);O(()=>M(Se,c(r))),k(pe,$)};H(be,pe=>{c(r)&&pe(ue)})}var ve=f(be,2),_e=h(ve),ye=f(_e,2),ce=h(ye);O(()=>{ye.disabled=c(i),M(ce,c(i)?"Launching...":"Retry")}),V("click",_e,A),V("click",ye,E),k(Z,le)};H(N,Z=>{c(a)===0?Z(se):c(a)===1?Z(ae,1):c(a)===2?Z(ke,2):c(w)?Z(we,3):Z(fe,!1)})}k(t,U),nt()}ht(["click","input"]);var _g=T('<div class="loading">Loading...</div>'),vg=T('<div class="login-error svelte-1n46o8q"> </div>'),pg=T('<div class="login-overlay svelte-1n46o8q"><div class="login-card svelte-1n46o8q"><div class="login-brand svelte-1n46o8q"><img src="/logo.svg" alt="BrowserBird" class="login-logo"/></div> <h2 class="login-heading svelte-1n46o8q">Create your account</h2> <form><label class="form-label">Email <input type="email" class="form-input" placeholder="you@example.com" autocomplete="email"/></label> <label class="form-label">Password <input type="password" class="form-input" placeholder="At least 8 characters" autocomplete="new-password"/></label> <label class="form-label">Confirm Password <input type="password" class="form-input" placeholder="Repeat password" autocomplete="new-password"/></label> <!> <button type="submit" class="btn btn-primary login-submit svelte-1n46o8q">Create Account</button></form></div></div>'),gg=T('<div class="login-error svelte-1n46o8q"> </div>'),xg=T('<div class="login-overlay svelte-1n46o8q"><div class="login-card svelte-1n46o8q"><div class="login-brand svelte-1n46o8q"><img src="/logo.svg" alt="BrowserBird" class="login-logo"/></div> <form><label class="form-label">Email <input type="email" class="form-input" placeholder="you@example.com" autocomplete="email"/></label> <label class="form-label">Password <input type="password" class="form-input" placeholder="Enter password" autocomplete="current-password"/></label> <!> <button type="submit" class="btn btn-primary login-submit svelte-1n46o8q">Sign In</button></form></div></div>'),bg=T('<div class="app svelte-1n46o8q"><!> <main class="content svelte-1n46o8q"><div class="content-header svelte-1n46o8q"><button class="hamburger svelte-1n46o8q" aria-label="Open navigation"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg></button> <h1 class="page-title svelte-1n46o8q"> </h1> <div class="header-right svelte-1n46o8q"><!></div></div> <div class="content-body svelte-1n46o8q"><!></div></main></div>'),mg=T("<!> <!> <!>",1);function wg(t,e){st(e,!0);const s={status:"Status",sessions:"Sessions","session-detail":"Session Detail",birds:"Birds",browser:"Browser",settings:"Settings"};let n=q(He(kl())),a=q("checking"),i=q(null),r=q("connecting"),l=q(localStorage.getItem("sidebar-collapsed")==="true"),d=q(!1),o=q(""),u=q(""),_=q(""),p=q(""),v=q(""),x=q(""),y=q("");const w=Ae(()=>s[c(n)]??"Status");mt(()=>{document.title=`${c(w)} - BrowserBird`});function S(){b(l,!c(l)),localStorage.setItem("sidebar-collapsed",String(c(l)))}gh(()=>{b(a,"login")}),mt(()=>{const J=()=>{b(n,kl(),!0),b(d,!1)};return window.addEventListener("hashchange",J),()=>window.removeEventListener("hashchange",J)}),mt(()=>{if(c(n)!=="flights")return;const J=Li().get("birdUid");window.location.hash=J?`#/birds?expand=${J}`:"#/birds"}),mt(()=>{yl().then(async J=>{J.setupRequired?b(a,"setup"):J.authRequired?Xi()?await mh()?J.onboardingRequired?b(a,"onboarding"):b(a,"authenticated"):b(a,"login"):b(a,(J.onboardingRequired,"login"),!0):b(a,"authenticated")})}),mt(()=>{if(c(a)!=="authenticated")return;Sl(N=>{b(i,N,!0),b(r,"connected")},N=>Cl(N),N=>{b(r,N,!0)});const J=setInterval(()=>{Kh()||Ee("/api/status").then(()=>{b(r,"connected"),Sl(N=>{b(i,N,!0),b(r,"connected")},N=>Cl(N),N=>{b(r,N,!0)})}).catch(()=>{b(r,"disconnected")})},3e4);return()=>{qc(),clearInterval(J)}});function E(){Wr(),b(a,"login")}async function K(J){J.preventDefault();const N=c(o).trim(),se=c(u);if(!(!N||!se))try{const ae=await xh(N,se);wl(ae.token),b(_,""),b(o,""),b(u,""),b(a,"authenticated")}catch(ae){b(_,ae.message,!0)}}async function A(J){J.preventDefault();const N=c(p).trim(),se=c(v),ae=c(x);if(!(!N||!se)){if(se!==ae){b(y,"Passwords do not match");return}if(se.length<8){b(y,"Password must be at least 8 characters");return}try{const ke=await bh(N,se);wl(ke.token),b(y,""),b(p,""),b(v,""),b(x,"");const we=await yl();b(a,we.onboardingRequired?"onboarding":"authenticated",!0)}catch(ke){b(y,ke.message,!0)}}}var U=mg(),ee=Ce(U);Uh(ee,{});var X=f(ee,2);Oh(X,{});var C=f(X,2);{var F=J=>{var N=_g();k(J,N)},L=J=>{var N=pg(),se=h(N),ae=f(h(se),4),ke=h(ae),we=f(h(ke)),fe=f(ke,2),Z=f(h(fe)),le=f(fe,2),be=f(h(le)),ue=f(le,2);{var ve=_e=>{var ye=vg(),ce=h(ye);O(()=>M(ce,c(y))),k(_e,ye)};H(ue,_e=>{c(y)&&_e(ve)})}In("submit",ae,A),Ve(we,()=>c(p),_e=>b(p,_e)),Ve(Z,()=>c(v),_e=>b(v,_e)),Ve(be,()=>c(x),_e=>b(x,_e)),k(J,N)},j=J=>{var N=xg(),se=h(N),ae=f(h(se),2),ke=h(ae),we=f(h(ke)),fe=f(ke,2),Z=f(h(fe)),le=f(fe,2);{var be=ue=>{var ve=gg(),_e=h(ve);O(()=>M(_e,c(_))),k(ue,ve)};H(le,ue=>{c(_)&&ue(be)})}In("submit",ae,K),Ve(we,()=>c(o),ue=>b(o,ue)),Ve(Z,()=>c(u),ue=>b(u,ue)),k(J,N)},oe=J=>{fg(J,{oncomplete:()=>{b(a,"authenticated")}})},de=J=>{var N=bg(),se=h(N);Ph(se,{get currentPage(){return c(n)},get collapsed(){return c(l)},get mobileOpen(){return c(d)},ontoggle:S,onmobileclose:()=>{b(d,!1)},onsignout:E});var ae=f(se,2),ke=h(ae),we=h(ke),fe=f(we,2),Z=h(fe),le=f(fe,2),be=h(le);Ih(be,{get status(){return c(i)}});var ue=f(ke,2),ve=h(ue);{var _e=he=>{m0(he,{})},ye=he=>{Yp(he,{})},ce=he=>{rf(he,{})},pe=he=>{Sv(he,{get status(){return c(i)}})},$=he=>{Up(he,{get status(){return c(i)}})},Se=he=>{_0(he,{get status(){return c(i)}})};H(ve,he=>{c(n)==="sessions"?he(_e):c(n)==="session-detail"?he(ye,1):c(n)==="birds"?he(ce,2):c(n)==="browser"?he(pe,3):c(n)==="settings"?he($,4):he(Se,!1)})}O(()=>M(Z,c(w))),V("click",we,()=>{b(d,!0)}),k(J,N)};H(C,J=>{c(a)==="checking"?J(F):c(a)==="setup"?J(L,1):c(a)==="login"?J(j,2):c(a)==="onboarding"?J(oe,3):J(de,!1)})}k(t,U),nt()}ht(["click"]);eh(wg,{target:document.getElementById("app")});
|