Your IP : 216.73.216.52


Current Path : /snap/lxd/38450/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38450/share/lxd-ui/assets/InstanceDetail-CyR_ZDSN.js

import{a2 as za,j as h,d as b,aD as Wc,r as O,u as $c,Q as Ks,p as zs,aE as Vc,aF as qc,aG as lo,w as Fi,R as ee,aC as Oi,a3 as fi,E as He,v as _t,f as Ht,aH as ho,ar as Xc,h as Kt,k as ft,aI as ji,x as ve,C as si,aJ as pt,aK as Ya,aL as Ys,aM as Ha,aN as Qc,aO as Ki,O as $i,aP as Zc,aQ as Jc,aR as co,aS as uo,aT as ed,a9 as td,aU as Rr,aV as id,aW as Ga,Z as ge,ay as Vi,aX as Wa,L as An,aY as Hs,aZ as $a,a_ as Va,_ as qa,z as _s,W as Pn,a$ as Xa,s as qi,b0 as sd,T as ci,ax as rd,b1 as nd,S as kn,b2 as od,b3 as ad,b4 as ld,b5 as hd,b6 as cd,b7 as _o,b8 as Qa,V as Za,b9 as Ja,ba as dd,J as el,bb as ud,c as Gs,a6 as Ie,bc as _d,bd as Ws,be as fd,P as pd,bf as md,b as tl,bg as gd,bh as vd,H as Sd,bi as bd,bj as yd,$ as Cd,bk as wd,bl as Ed,bm as xd}from"./index-BsQN_SZU.js";import{w as Id,A as il,E as Zt,F as ys,g as sl,r as Ad,Y as Ei,I as Pd,M as ur,H as kd,D as Md,N as Dd,G as Td,b as Rd,O as Ld,R as Nd,c as Bd,d as Od,e as Ud,f as Fd,h as jd,i as Kd,B as zd,j as Yd,C as Hd,k as Gd,l as Wd,J as fo}from"./SshKeyForm-BNz7yPwa.js";import{g as po,u as $d,a as Vd,I as qd,b as mo,c as go,D as Xd}from"./DeleteInstanceBtn-C0d6l5Yt.js";import{M as Qd}from"./Meter-cq8smrSm.js";import{N as Zd,D as Jd}from"./NetworkListTable-ClJXyVRh.js";import{a as rl}from"./ClusterMemberRichChip-Di9w-E3M.js";import{S as nl}from"./SnapshotForm-BuAjnGGJ.js";import{t as eu,a as tu,b as iu,g as ol,i as su,c as ru}from"./snapshots-LtzKNDw1.js";import{u as Wt}from"./projects-CczQ3aFg.js";import{f as al}from"./images-dZFGKb1g.js";import{C as ll}from"./ClusterMemberSelector-o7hg9ebZ.js";import{S as nu}from"./SelectableMainTable-DBx4rRiq.js";import{B as ou}from"./BulkDeleteButton-DbqPCHnz.js";import{u as au}from"./useBulkDetails-ydqvQ5wa.js";import{S as lu}from"./SelectedTableNotification-BpePAhdG.js";import{u as hu}from"./useSortTableData-DkMx8bMp.js";import{P as hl}from"./ProjectRichChip-DZzjTfq6.js";import{C as cu,a as vo,h as So,D as du,N as uu,G as _u,P as fu,O as pu,c as mu}from"./NetworkDevicePanel-Dyz6smUO.js";import{y as gu,Y as vu,o as Su}from"./YamlSwitch-BStSXJFs.js";import{F as bu}from"./FormFooterLayout-CcbL_-PB.js";import{Y as yu}from"./NetworkDefaultACLSelector-8KsXe1ya.js";import{F as Cu}from"./FormSubmitBtn-DEfKgZu7.js";import{u as wu,p as bo}from"./usePanelParams-CNAJZsSX.js";import{R as Eu}from"./RenameHeader-BdCO5Nid.js";import{F as _r,B as xu}from"./FormLink-3uUdaYvf.js";import{C as Iu,S as Au,P as Pu}from"./ProjectSelectTable-Di9-f3cz.js";import{S as ku}from"./StoragePoolRichChip-Daex_aZU.js";import{S as Mu}from"./StoragePoolSelector-Bvqvds5t.js";import{T as Du}from"./TabLinks-N89T_JJh.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./ExpandableList-DsGr0BpD.js";import"./useNetworks-1j5RF-bH.js";import"./NetworkRichChip-Cp8QBNS_.js";import"./ClusterMemberMemoryUsage-DYUQFY0n.js";import"./DiskSizeSelector-C9kWj54D.js";import"./StorageVolumeForm-C6mvm1BU.js";import"./formChangeCount-Kjdextdt.js";import"./useVolumes-Bxw5lKYj.js";import"./storage-volumes-CG043sqG.js";import"./UploadCustomIso-C4mIsVip.js";import"./ProgressBar-CZqVHpuJ.js";import"./NetworkSelector-DuJmwRYk.js";import"./useNetworkAcls-Bl3lzJua.js";import"./network-acls-bpCzo6oH.js";import"./StoragePoolSize-BNbqTfwA.js";import"./StoragePoolClusterMember-BaBZgKZ2.js";const Tu=({instance:e,onFailure:t})=>{const{data:i=[],error:s,isLoading:r}=za(e.project);s&&t("Loading profiles failed",s);const n=[{content:"Name",sortKey:"name",className:"u-text--muted"},{content:"Description",sortKey:"description",className:"u-text--muted"}],o=e.profiles.map(a=>{const c=i.find(d=>d.name===a)?.description??"";return{key:a,columns:[{content:h.jsx(Id,{profileName:a,projectName:e.project,className:"force-truncate"}),role:"rowheader","aria-label":"Name"},{content:c,role:"cell",title:`Description ${c}`,"aria-label":"Description"}],sortData:{name:a.toLowerCase(),description:c.toLowerCase()}}});return r?h.jsx(b.Spinner,{className:"u-loader",text:"Loading profiles..."}):h.jsx(b.MainTable,{headers:n,rows:o,sortable:!0})},Ru=({instance:e})=>{const{getMetricHistory:t}=Wc(),i=t(),[s,r]=O.useState(15);O.useEffect(()=>{const a=setInterval(()=>{r(l=>l-1)},1e3);return()=>{clearInterval(a)}},[]);const o=(()=>{if(i.length===0)return null;const a=i.length-1,l=po(i[a],e);if(!l)return null;let c=null;for(let S=i.length-2;S>=0&&(c=po(i[S],e),c?.cpuSecondsTotal==l.cpuSecondsTotal);S--);if(!c)return null;const d=()=>{const S=l.cpuSecondsTotal-l.cpuSecondsIdle,v=c.cpuSecondsTotal-c.cpuSecondsIdle;return S-v},p=()=>{if(l.coreCount>0)return l.coreCount;const S=e.expanded_config["limits.cpu"];if(S){const v=parseInt(S);return v>0?v:1}return 1},f=d(),g=p(),u=(l.time-c.time)*g,_=100*f/u;return _<0?null:Math.min(_,100)})();return o===null?h.jsxs("div",{className:"u-text--muted p-text--small",children:["loading",s>0?`, ${s} seconds remaining to first CPU snapshot`:" takes longer than expected"]},s>0?s:"long"):h.jsx("div",{children:h.jsx(Qd,{percentage:o,text:`${Math.round(o*100)/100}%`})})},Lu=({instance:e,onFailure:t})=>{const{isRestricted:i}=$c(),[s,r]=O.useState(!1),{data:n=[],error:o,isLoading:a}=$d(e.location);o&&t("Loading metrics failed",o);const l=Vd(n,e);if(i)return h.jsx("div",{className:"u-text--muted",children:"Details are not available for restricted users"});const c=l.otherFilesystems.length>0;return h.jsx(h.Fragment,{children:a?h.jsx(b.Spinner,{className:"u-loader",text:"Loading metrics..."}):h.jsx("table",{children:h.jsxs("tbody",{children:[h.jsxs("tr",{className:"metric-row",children:[h.jsx("th",{className:"u-text--muted",children:"Memory"}),h.jsx("td",{children:l.memory?h.jsx(qd,{memory:l.memory}):"-"})]}),h.jsxs("tr",{className:"metric-row",children:[h.jsx("th",{className:"u-text--muted",children:"Root filesystem"}),h.jsx("td",{children:l.rootFilesystem?h.jsx(mo,{filesystem:l.rootFilesystem}):"-"})]}),s&&l.otherFilesystems.map(d=>h.jsxs("tr",{className:"metric-row",children:[h.jsx("th",{className:"u-text--muted",children:d.device}),h.jsx("td",{children:h.jsx(mo,{filesystem:d})})]},d.device)),c&&h.jsxs("tr",{className:"metric-row",children:[h.jsx("th",{}),h.jsx("td",{children:h.jsx(b.Button,{appearance:"link",className:"u-no-margin--bottom",onClick:()=>{r(!s)},children:s?"Hide other filesystems":"Show other filesystems"})})]}),h.jsxs("tr",{className:"metric-row",children:[h.jsx("th",{className:"u-text--muted",children:"CPU"}),h.jsx("td",{children:l.memory?h.jsx(Ru,{instance:e}):"-"},l.memory?.free)]})]})})})},Nu=({instance:e})=>{const t=b.useNotify(),i=Ks(),s=(o,a)=>{t.failure(o,a)},r=()=>{fi("instance-overview-tab")};O.useEffect(r,[t.notification?.message]),b.useListener(window,r,"resize",!0);const n=!e.state||e.state.pid===0?"-":e.state.pid;return h.jsxs("div",{className:"instance-overview-tab",children:[h.jsx(zs,{}),h.jsxs(b.Row,{className:"general",children:[h.jsx(b.Col,{size:3,children:h.jsx("h2",{className:"p-heading--5",children:"General"})}),h.jsx(b.Col,{size:7,children:h.jsx("table",{children:h.jsxs("tbody",{children:[h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Base image"}),h.jsx("td",{children:Vc(e)})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Description"}),h.jsx("td",{children:e.description?e.description:"-"})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Type"}),h.jsx("td",{children:qc(e)})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"IPv4"}),h.jsx("td",{children:h.jsx(go,{instance:e,family:"inet"})},lo(e,"inet").length)]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"IPv6"}),h.jsx("td",{children:h.jsx(go,{instance:e,family:"inet6"})},lo(e,"inet6").length)]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Architecture"}),h.jsx("td",{children:e.architecture})]}),i&&h.jsxs(h.Fragment,{children:[h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Cluster member"}),h.jsx("td",{children:e.location?h.jsx(rl,{clusterMember:e.location}):"-"})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Placement group"}),h.jsx("td",{children:e.expanded_config["placement.group"]?h.jsx(Fi,{type:"placement-group",value:e.expanded_config["placement.group"],to:`${ee}/ui/project/${e.project}/placement-groups`}):"-"})]})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"PID"}),h.jsx("td",{children:n})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Date created"}),h.jsx("td",{children:Oi(e.created_at)})]}),h.jsxs("tr",{children:[h.jsx("th",{className:"u-text--muted",children:"Last used"}),h.jsx("td",{children:Oi(e.last_used_at)})]})]})})})]}),h.jsxs(b.Row,{className:"usage",children:[h.jsx(b.Col,{size:3,children:h.jsx("h2",{className:"p-heading--5",children:"Usage"})}),h.jsx(b.Col,{size:7,children:h.jsx(Lu,{instance:e,onFailure:s})})]}),h.jsxs(b.Row,{className:"networks",children:[h.jsx(b.Col,{size:3,children:h.jsx("h2",{className:"p-heading--5",children:"Networks"})}),h.jsx(b.Col,{size:7,children:h.jsx(Zd,{devices:e.expanded_devices,instance:e,onFailure:s})})]}),h.jsxs(b.Row,{className:"networks",children:[h.jsx(b.Col,{size:3,children:h.jsx("h2",{className:"p-heading--5",children:"Devices"})}),h.jsx(b.Col,{size:7,children:h.jsx(Jd,{configBaseURL:`${ee}/ui/project/${encodeURIComponent(e.project)}/instance/${encodeURIComponent(e.name)}/configuration`,devices:e.expanded_devices,location:e.location})})]}),h.jsxs(b.Row,{className:"profiles",children:[h.jsx(b.Col,{size:3,children:h.jsx("h2",{className:"p-heading--5",children:"Profiles"})}),h.jsx(b.Col,{size:7,children:h.jsx(Tu,{instance:e,onFailure:s})})]})]})};var Bu=2,Ou=1,cl=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,i=window.getComputedStyle(this._terminal.element.parentElement),s=parseInt(i.getPropertyValue("height")),r=Math.max(0,parseInt(i.getPropertyValue("width"))),n=window.getComputedStyle(this._terminal.element),o={top:parseInt(n.getPropertyValue("padding-top")),bottom:parseInt(n.getPropertyValue("padding-bottom")),right:parseInt(n.getPropertyValue("padding-right")),left:parseInt(n.getPropertyValue("padding-left"))},a=o.top+o.bottom,l=o.right+o.left,c=s-a,d=r-l-t;return{cols:Math.max(Bu,Math.floor(d/e.css.cell.width)),rows:Math.max(Ou,Math.floor(c/e.css.cell.height))}}};const Uu=({payload:e,close:t,reconnect:i,instance:s})=>{const r=He(),[n,o]=O.useState(null),a=_t(),l=O.useRef(null),c=Ht().shape({command:Kt().required("This field is required"),environment:Xc().of(Ht().shape({key:Kt(),value:Kt()})),user:ho(),group:ho()}),d=ft({initialValues:e,validationSchema:c,onSubmit:i}),p=()=>{const S=[...d.values.environment];S.push({key:"",value:""}),d.setFieldValue("environment",S)},f=S=>{const v=[...d.values.environment];v.splice(S,1),d.setFieldValue("environment",v)},g=()=>{s.config={...s.config,[ih]:JSON.stringify(d.values)},ji(s,s.project).then(S=>{r.set(S.metadata.id,()=>{o(b.success("Saved terminal connection defaults for this instance.","Saved successfully"))},v=>{o(b.failure("Failed to save terminal connection defaults.",new Error(v)))},()=>{a.invalidateQueries({queryKey:[ve.instances,s.name,s.project]})})}).catch(S=>{o(b.failure("Failed to save terminal connection defaults.",S))})},u=S=>{S.key==="Escape"&&t()},_=()=>{fi("content-wrapper","p-modal__footer",64,"max-height")};return b.useListener(window,_,"resize",!0),O.useEffect(_,[]),O.useEffect(()=>{l.current?.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),window.dispatchEvent(new Event("resize"))},[d.values.environment]),h.jsxs(b.Modal,{close:t,title:"Reconnect terminal",buttonRow:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button","aria-label":"cancel reconnect",onClick:t,children:"Cancel"}),h.jsx(b.Button,{className:"u-no-margin--bottom",type:"button",title:"Save as default for this instance",onClick:g,children:"Save as default"}),h.jsx(b.ActionButton,{className:"u-no-margin--bottom",appearance:"positive","aria-label":"submit reconnect",onClick:()=>{d.submitForm()},children:"Reconnect"})]}),onKeyDown:u,children:[n&&h.jsx(b.Notification,{severity:n.type,title:n.title,onDismiss:()=>{o(null)},className:"margin-right",children:n.message}),h.jsxs(b.Form,{onSubmit:d.handleSubmit,children:[h.jsx(b.Input,{type:"submit",hidden:!0,value:"Hidden input"}),h.jsxs("div",{className:"content-wrapper",children:[h.jsx(b.Input,{id:"command",name:"command",label:"Command",labelClassName:"u-no-margin--bottom",type:"text",required:!0,onBlur:d.handleBlur,onChange:d.handleChange,error:d.touched.command?d.errors.command:null,value:d.values.command}),h.jsx(b.Input,{id:"user",name:"user",label:"User ID",labelClassName:"u-no-margin--bottom",type:"number",onBlur:d.handleBlur,onChange:d.handleChange,value:d.values.user}),h.jsx(b.Input,{id:"group",name:"group",label:"Group ID",labelClassName:"u-no-margin--bottom",type:"number",onBlur:d.handleBlur,onChange:d.handleChange,value:d.values.group}),h.jsx("p",{className:"u-no-margin--bottom p-form__label",children:"Environment variables"}),d.values.environment.map((S,v)=>h.jsxs("div",{className:"env-variables",children:[h.jsx(b.Input,{type:"text",placeholder:"Key",labelClassName:"u-off-screen",label:`Key of variable ${v}`,id:`environment.${v}.key`,name:`environment.${v}.key`,onBlur:d.handleBlur,onChange:d.handleChange,value:d.values.environment[v].key}),h.jsx(b.Input,{type:"text",placeholder:"Value",labelClassName:"u-off-screen",label:`Value of variable ${v}`,id:`environment.${v}.value`,name:`environment.${v}.value`,onBlur:d.handleBlur,onChange:d.handleChange,value:d.values.environment[v].value}),h.jsx(b.Button,{"aria-label":`remove variable ${v}`,onClick:()=>{f(v)},type:"button",hasIcon:!0,children:h.jsx(b.Icon,{name:"delete"})})]},v)),h.jsx("div",{ref:l,children:h.jsx(b.Button,{"aria-label":"add variable",onClick:p,type:"button",children:h.jsx("span",{children:"Add variable"})})})]})]})]})},Fu=({payload:e,reconnect:t,instance:i})=>{const[s,r]=O.useState(!1),n=()=>{r(!1)},o=()=>{r(!0)},a=l=>{n(),t(l)};return h.jsxs(h.Fragment,{children:[s&&h.jsx(Uu,{close:n,reconnect:a,instance:i,payload:e}),h.jsxs(b.Button,{className:"u-no-margin--bottom",hasIcon:!0,onClick:o,children:[h.jsx(b.Icon,{name:"connected"}),h.jsx("span",{children:"Reconnect"})]})]})};var dl=Object.defineProperty,ju=Object.getOwnPropertyDescriptor,Ku=(e,t)=>{for(var i in t)dl(e,i,{get:t[i],enumerable:!0})},ce=(e,t,i,s)=>{for(var r=s>1?void 0:s?ju(t,i):t,n=e.length-1,o;n>=0;n--)(o=e[n])&&(r=(s?o(t,i,r):o(r))||r);return s&&r&&dl(t,i,r),r},L=(e,t)=>(i,s)=>t(i,s,e),yo="Terminal input",Lr={get:()=>yo,set:e=>yo=e},Co="Too much output to announce, navigate to rows manually to read",Nr={get:()=>Co,set:e=>Co=e};function zu(e){return e.replace(/\r?\n/g,"\r")}function Yu(e,t){return t?"\x1B[200~"+e+"\x1B[201~":e}function Hu(e,t){e.clipboardData&&e.clipboardData.setData("text/plain",t.selectionText),e.preventDefault()}function Gu(e,t,i,s){if(e.stopPropagation(),e.clipboardData){let r=e.clipboardData.getData("text/plain");ul(r,t,i,s)}}function ul(e,t,i,s){e=zu(e),e=Yu(e,i.decPrivateModes.bracketedPasteMode&&s.rawOptions.ignoreBracketedPasteMode!==!0),i.triggerDataEvent(e,!0),t.value=""}function _l(e,t,i){let s=i.getBoundingClientRect(),r=e.clientX-s.left-10,n=e.clientY-s.top-10;t.style.width="20px",t.style.height="20px",t.style.left=`${r}px`,t.style.top=`${n}px`,t.style.zIndex="1000",t.focus()}function wo(e,t,i,s,r){_l(e,t,i),r&&s.rightClickSelect(e),t.value=s.selectionText,t.select()}function Ut(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function $s(e,t=0,i=e.length){let s="";for(let r=t;r<i;++r){let n=e[r];n>65535?(n-=65536,s+=String.fromCharCode((n>>10)+55296)+String.fromCharCode(n%1024+56320)):s+=String.fromCharCode(n)}return s}var Wu=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let i=e.length;if(!i)return 0;let s=0,r=0;if(this._interim){let n=e.charCodeAt(r++);56320<=n&&n<=57343?t[s++]=(this._interim-55296)*1024+n-56320+65536:(t[s++]=this._interim,t[s++]=n),this._interim=0}for(let n=r;n<i;++n){let o=e.charCodeAt(n);if(55296<=o&&o<=56319){if(++n>=i)return this._interim=o,s;let a=e.charCodeAt(n);56320<=a&&a<=57343?t[s++]=(o-55296)*1024+a-56320+65536:(t[s++]=o,t[s++]=a);continue}o!==65279&&(t[s++]=o)}return s}},$u=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let i=e.length;if(!i)return 0;let s=0,r,n,o,a,l=0,c=0;if(this.interim[0]){let f=!1,g=this.interim[0];g&=(g&224)===192?31:(g&240)===224?15:7;let u=0,_;for(;(_=this.interim[++u]&63)&&u<4;)g<<=6,g|=_;let S=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,v=S-u;for(;c<v;){if(c>=i)return 0;if(_=e[c++],(_&192)!==128){c--,f=!0;break}else this.interim[u++]=_,g<<=6,g|=_&63}f||(S===2?g<128?c--:t[s++]=g:S===3?g<2048||g>=55296&&g<=57343||g===65279||(t[s++]=g):g<65536||g>1114111||(t[s++]=g)),this.interim.fill(0)}let d=i-4,p=c;for(;p<i;){for(;p<d&&!((r=e[p])&128)&&!((n=e[p+1])&128)&&!((o=e[p+2])&128)&&!((a=e[p+3])&128);)t[s++]=r,t[s++]=n,t[s++]=o,t[s++]=a,p+=4;if(r=e[p++],r<128)t[s++]=r;else if((r&224)===192){if(p>=i)return this.interim[0]=r,s;if(n=e[p++],(n&192)!==128){p--;continue}if(l=(r&31)<<6|n&63,l<128){p--;continue}t[s++]=l}else if((r&240)===224){if(p>=i)return this.interim[0]=r,s;if(n=e[p++],(n&192)!==128){p--;continue}if(p>=i)return this.interim[0]=r,this.interim[1]=n,s;if(o=e[p++],(o&192)!==128){p--;continue}if(l=(r&15)<<12|(n&63)<<6|o&63,l<2048||l>=55296&&l<=57343||l===65279)continue;t[s++]=l}else if((r&248)===240){if(p>=i)return this.interim[0]=r,s;if(n=e[p++],(n&192)!==128){p--;continue}if(p>=i)return this.interim[0]=r,this.interim[1]=n,s;if(o=e[p++],(o&192)!==128){p--;continue}if(p>=i)return this.interim[0]=r,this.interim[1]=n,this.interim[2]=o,s;if(a=e[p++],(a&192)!==128){p--;continue}if(l=(r&7)<<18|(n&63)<<12|(o&63)<<6|a&63,l<65536||l>1114111)continue;t[s++]=l}}return s}},fl="",jt=" ",Xi=class pl{constructor(){this.fg=0,this.bg=0,this.extended=new Cs}static toColorRGB(t){return[t>>>16&255,t>>>8&255,t&255]}static fromColorRGB(t){return(t[0]&255)<<16|(t[1]&255)<<8|t[2]&255}clone(){let t=new pl;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},Cs=class ml{constructor(t=0,i=0){this._ext=0,this._urlId=0,this._ext=t,this._urlId=i}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(t){this._ext=t}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(t){this._ext&=-469762049,this._ext|=t<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(t){this._ext&=-67108864,this._ext|=t&67108863}get urlId(){return this._urlId}set urlId(t){this._urlId=t}get underlineVariantOffset(){let t=(this._ext&3758096384)>>29;return t<0?t^4294967288:t}set underlineVariantOffset(t){this._ext&=536870911,this._ext|=t<<29&3758096384}clone(){return new ml(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},ct=class gl extends Xi{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new Cs,this.combinedData=""}static fromCharData(t){let i=new gl;return i.setFromCharData(t),i}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?Ut(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(t){this.fg=t[0],this.bg=0;let i=!1;if(t[1].length>2)i=!0;else if(t[1].length===2){let s=t[1].charCodeAt(0);if(55296<=s&&s<=56319){let r=t[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(s-55296)*1024+r-56320+65536|t[2]<<22:i=!0}else i=!0}else this.content=t[1].charCodeAt(0)|t[2]<<22;i&&(this.combinedData=t[1],this.content=2097152|t[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Eo="di$target",Br="di$dependencies",fr=new Map;function Vu(e){return e[Br]||[]}function Te(e){if(fr.has(e))return fr.get(e);let t=function(i,s,r){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");qu(t,i,r)};return t._id=e,fr.set(e,t),t}function qu(e,t,i){t[Eo]===t?t[Br].push({id:e,index:i}):(t[Br]=[{id:e,index:i}],t[Eo]=t)}var Ge=Te("BufferService"),vl=Te("CoreMouseService"),ri=Te("CoreService"),Xu=Te("CharsetService"),Mn=Te("InstantiationService"),Sl=Te("LogService"),We=Te("OptionsService"),bl=Te("OscLinkService"),Qu=Te("UnicodeService"),Qi=Te("DecorationService"),Or=class{constructor(e,t,i){this._bufferService=e,this._optionsService=t,this._oscLinkService=i}provideLinks(e,t){let i=this._bufferService.buffer.lines.get(e-1);if(!i){t(void 0);return}let s=[],r=this._optionsService.rawOptions.linkHandler,n=new ct,o=i.getTrimmedLength(),a=-1,l=-1,c=!1;for(let d=0;d<o;d++)if(!(l===-1&&!i.hasContent(d))){if(i.loadCell(d,n),n.hasExtendedAttrs()&&n.extended.urlId)if(l===-1){l=d,a=n.extended.urlId;continue}else c=n.extended.urlId!==a;else l!==-1&&(c=!0);if(c||l!==-1&&d===o-1){let p=this._oscLinkService.getLinkData(a)?.uri;if(p){let f={start:{x:l+1,y:e},end:{x:d+(!c&&d===o-1?1:0),y:e}},g=!1;if(!r?.allowNonHttpProtocols)try{let u=new URL(p);["http:","https:"].includes(u.protocol)||(g=!0)}catch{g=!0}g||s.push({text:p,range:f,activate:(u,_)=>r?r.activate(u,_,f):Zu(u,_),hover:(u,_)=>r?.hover?.(u,_,f),leave:(u,_)=>r?.leave?.(u,_,f)})}c=!1,n.hasExtendedAttrs()&&n.extended.urlId?(l=d,a=n.extended.urlId):(l=-1,a=-1)}}t(s)}};Or=ce([L(0,Ge),L(1,We),L(2,bl)],Or);function Zu(e,t){if(confirm(`Do you want to navigate to ${t}?

WARNING: This link could potentially be dangerous`)){let i=window.open();if(i){try{i.opener=null}catch{}i.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}}var Vs=Te("CharSizeService"),Mt=Te("CoreBrowserService"),Dn=Te("MouseService"),Dt=Te("RenderService"),Ju=Te("SelectionService"),yl=Te("CharacterJoinerService"),pi=Te("ThemeService"),Cl=Te("LinkProviderService"),e_=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?xo.isErrorNoTelemetry(e)?new xo(e.message+`

`+e.stack):new Error(e.message+`

`+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}},t_=new e_;function fs(e){i_(e)||t_.onUnexpectedError(e)}var Ur="Canceled";function i_(e){return e instanceof s_?!0:e instanceof Error&&e.name===Ur&&e.message===Ur}var s_=class extends Error{constructor(){super(Ur),this.name=this.message}};function r_(e){return new Error(`Illegal argument: ${e}`)}var xo=class Fr extends Error{constructor(t){super(t),this.name="CodeExpectedError"}static fromError(t){if(t instanceof Fr)return t;let i=new Fr;return i.message=t.message,i.stack=t.stack,i}static isErrorNoTelemetry(t){return t.name==="CodeExpectedError"}},jr=class wl extends Error{constructor(t){super(t||"An unexpected bug occurred."),Object.setPrototypeOf(this,wl.prototype)}};function Xe(e,t=0){return e[e.length-(1+t)]}var n_;(e=>{function t(n){return n<0}e.isLessThan=t;function i(n){return n<=0}e.isLessThanOrEqual=i;function s(n){return n>0}e.isGreaterThan=s;function r(n){return n===0}e.isNeitherLessOrGreaterThan=r,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(n_||={});function o_(e,t){let i=this,s=!1,r;return function(){return s||(s=!0,t||(r=e.apply(i,arguments))),r}}var El;(e=>{function t(E){return E&&typeof E=="object"&&typeof E[Symbol.iterator]=="function"}e.is=t;let i=Object.freeze([]);function s(){return i}e.empty=s;function*r(E){yield E}e.single=r;function n(E){return t(E)?E:r(E)}e.wrap=n;function o(E){return E||i}e.from=o;function*a(E){for(let D=E.length-1;D>=0;D--)yield E[D]}e.reverse=a;function l(E){return!E||E[Symbol.iterator]().next().done===!0}e.isEmpty=l;function c(E){return E[Symbol.iterator]().next().value}e.first=c;function d(E,D){let N=0;for(let U of E)if(D(U,N++))return!0;return!1}e.some=d;function p(E,D){for(let N of E)if(D(N))return N}e.find=p;function*f(E,D){for(let N of E)D(N)&&(yield N)}e.filter=f;function*g(E,D){let N=0;for(let U of E)yield D(U,N++)}e.map=g;function*u(E,D){let N=0;for(let U of E)yield*D(U,N++)}e.flatMap=u;function*_(...E){for(let D of E)yield*D}e.concat=_;function S(E,D,N){let U=N;for(let X of E)U=D(U,X);return U}e.reduce=S;function*v(E,D,N=E.length){for(D<0&&(D+=E.length),N<0?N+=E.length:N>E.length&&(N=E.length);D<N;D++)yield E[D]}e.slice=v;function P(E,D=Number.POSITIVE_INFINITY){let N=[];if(D===0)return[N,E];let U=E[Symbol.iterator]();for(let X=0;X<D;X++){let ie=U.next();if(ie.done)return[N,e.empty()];N.push(ie.value)}return[N,{[Symbol.iterator](){return U}}]}e.consume=P;async function w(E){let D=[];for await(let N of E)D.push(N);return Promise.resolve(D)}e.asyncToArray=w})(El||={});function ei(e){if(El.is(e)){let t=[];for(let i of e)if(i)try{i.dispose()}catch(s){t.push(s)}if(t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"Encountered errors while disposing of store");return Array.isArray(e)?[]:e}else if(e)return e.dispose(),e}function a_(...e){return ne(()=>ei(e))}function ne(e){return{dispose:o_(()=>{e()})}}var xl=class Il{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{ei(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?Il.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}delete(t){if(t){if(t===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(t),t.dispose()}}deleteAndLeak(t){t&&this._toDispose.has(t)&&(this._toDispose.delete(t),void 0)}};xl.DISABLE_DISPOSED_WARNING=!1;var zt=xl,W=class{constructor(){this._store=new zt,this._store}dispose(){this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}};W.None=Object.freeze({dispose(){}});var ui=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e}},At=typeof window=="object"?window:globalThis,Kr=class zr{constructor(t){this.element=t,this.next=zr.Undefined,this.prev=zr.Undefined}};Kr.Undefined=new Kr(void 0);var oe=Kr,Io=class{constructor(){this._first=oe.Undefined,this._last=oe.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===oe.Undefined}clear(){let e=this._first;for(;e!==oe.Undefined;){let t=e.next;e.prev=oe.Undefined,e.next=oe.Undefined,e=t}this._first=oe.Undefined,this._last=oe.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let i=new oe(e);if(this._first===oe.Undefined)this._first=i,this._last=i;else if(t){let r=this._last;this._last=i,i.prev=r,r.next=i}else{let r=this._first;this._first=i,i.next=r,r.prev=i}this._size+=1;let s=!1;return()=>{s||(s=!0,this._remove(i))}}shift(){if(this._first!==oe.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==oe.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==oe.Undefined&&e.next!==oe.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===oe.Undefined&&e.next===oe.Undefined?(this._first=oe.Undefined,this._last=oe.Undefined):e.next===oe.Undefined?(this._last=this._last.prev,this._last.next=oe.Undefined):e.prev===oe.Undefined&&(this._first=this._first.next,this._first.prev=oe.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==oe.Undefined;)yield e.element,e=e.next}},l_=globalThis.performance&&typeof globalThis.performance.now=="function",h_=class Al{static create(t){return new Al(t)}constructor(t){this._now=l_&&t===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},Be;(e=>{e.None=()=>W.None;function t(R,I){return p(R,()=>{},0,void 0,!0,void 0,I)}e.defer=t;function i(R){return(I,M=null,T)=>{let F=!1,Y;return Y=R(B=>{if(!F)return Y?Y.dispose():F=!0,I.call(M,B)},null,T),F&&Y.dispose(),Y}}e.once=i;function s(R,I,M){return c((T,F=null,Y)=>R(B=>T.call(F,I(B)),null,Y),M)}e.map=s;function r(R,I,M){return c((T,F=null,Y)=>R(B=>{I(B),T.call(F,B)},null,Y),M)}e.forEach=r;function n(R,I,M){return c((T,F=null,Y)=>R(B=>I(B)&&T.call(F,B),null,Y),M)}e.filter=n;function o(R){return R}e.signal=o;function a(...R){return(I,M=null,T)=>{let F=a_(...R.map(Y=>Y(B=>I.call(M,B))));return d(F,T)}}e.any=a;function l(R,I,M,T){let F=M;return s(R,Y=>(F=I(F,Y),F),T)}e.reduce=l;function c(R,I){let M,T={onWillAddFirstListener(){M=R(F.fire,F)},onDidRemoveLastListener(){M?.dispose()}},F=new k(T);return I?.add(F),F.event}function d(R,I){return I instanceof Array?I.push(R):I&&I.add(R),R}function p(R,I,M=100,T=!1,F=!1,Y,B){let H,se,we,Ve=0,tt,Ue={leakWarningThreshold:Y,onWillAddFirstListener(){H=R(xe=>{Ve++,se=I(se,xe),T&&!we&&(Ee.fire(se),se=void 0),tt=()=>{let te=se;se=void 0,we=void 0,(!T||Ve>1)&&Ee.fire(te),Ve=0},typeof M=="number"?(clearTimeout(we),we=setTimeout(tt,M)):we===void 0&&(we=0,queueMicrotask(tt))})},onWillRemoveListener(){F&&Ve>0&&tt?.()},onDidRemoveLastListener(){tt=void 0,H.dispose()}},Ee=new k(Ue);return B?.add(Ee),Ee.event}e.debounce=p;function f(R,I=0,M){return e.debounce(R,(T,F)=>T?(T.push(F),T):[F],I,void 0,!0,void 0,M)}e.accumulate=f;function g(R,I=(T,F)=>T===F,M){let T=!0,F;return n(R,Y=>{let B=T||!I(Y,F);return T=!1,F=Y,B},M)}e.latch=g;function u(R,I,M){return[e.filter(R,I,M),e.filter(R,T=>!I(T),M)]}e.split=u;function _(R,I=!1,M=[],T){let F=M.slice(),Y=R(se=>{F?F.push(se):H.fire(se)});T&&T.add(Y);let B=()=>{F?.forEach(se=>H.fire(se)),F=null},H=new k({onWillAddFirstListener(){Y||(Y=R(se=>H.fire(se)),T&&T.add(Y))},onDidAddFirstListener(){F&&(I?setTimeout(B):B())},onDidRemoveLastListener(){Y&&Y.dispose(),Y=null}});return T&&T.add(H),H.event}e.buffer=_;function S(R,I){return(M,T,F)=>{let Y=I(new P);return R(function(B){let H=Y.evaluate(B);H!==v&&M.call(T,H)},void 0,F)}}e.chain=S;let v=Symbol("HaltChainable");class P{constructor(){this.steps=[]}map(I){return this.steps.push(I),this}forEach(I){return this.steps.push(M=>(I(M),M)),this}filter(I){return this.steps.push(M=>I(M)?M:v),this}reduce(I,M){let T=M;return this.steps.push(F=>(T=I(T,F),T)),this}latch(I=(M,T)=>M===T){let M=!0,T;return this.steps.push(F=>{let Y=M||!I(F,T);return M=!1,T=F,Y?F:v}),this}evaluate(I){for(let M of this.steps)if(I=M(I),I===v)break;return I}}function w(R,I,M=T=>T){let T=(...H)=>B.fire(M(...H)),F=()=>R.on(I,T),Y=()=>R.removeListener(I,T),B=new k({onWillAddFirstListener:F,onDidRemoveLastListener:Y});return B.event}e.fromNodeEventEmitter=w;function E(R,I,M=T=>T){let T=(...H)=>B.fire(M(...H)),F=()=>R.addEventListener(I,T),Y=()=>R.removeEventListener(I,T),B=new k({onWillAddFirstListener:F,onDidRemoveLastListener:Y});return B.event}e.fromDOMEventEmitter=E;function D(R){return new Promise(I=>i(R)(I))}e.toPromise=D;function N(R){let I=new k;return R.then(M=>{I.fire(M)},()=>{I.fire(void 0)}).finally(()=>{I.dispose()}),I.event}e.fromPromise=N;function U(R,I){return R(M=>I.fire(M))}e.forward=U;function X(R,I,M){return I(M),R(T=>I(T))}e.runAndSubscribe=X;class ie{constructor(I,M){this._observable=I,this._counter=0,this._hasChanged=!1;let T={onWillAddFirstListener:()=>{I.addObserver(this)},onDidRemoveLastListener:()=>{I.removeObserver(this)}};this.emitter=new k(T),M&&M.add(this.emitter)}beginUpdate(I){this._counter++}handlePossibleChange(I){}handleChange(I,M){this._hasChanged=!0}endUpdate(I){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function Oe(R,I){return new ie(R,I).emitter.event}e.fromObservable=Oe;function V(R){return(I,M,T)=>{let F=0,Y=!1,B={beginUpdate(){F++},endUpdate(){F--,F===0&&(R.reportChanges(),Y&&(Y=!1,I.call(M)))},handlePossibleChange(){},handleChange(){Y=!0}};R.addObserver(B),R.reportChanges();let H={dispose(){R.removeObserver(B)}};return T instanceof zt?T.add(H):Array.isArray(T)&&T.push(H),H}}e.fromObservableLight=V})(Be||={});var Yr=class Hr{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${Hr._idPool++}`,Hr.all.add(this)}start(t){this._stopWatch=new h_,this.listenerCount=t}stop(){if(this._stopWatch){let t=this._stopWatch.elapsed();this.durations.push(t),this.elapsedOverall+=t,this.invocationCount+=1,this._stopWatch=void 0}}};Yr.all=new Set,Yr._idPool=0;var c_=Yr,d_=-1,Pl=class kl{constructor(t,i,s=(kl._idPool++).toString(16).padStart(3,"0")){this._errorHandler=t,this.threshold=i,this.name=s,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(t,i){let s=this.threshold;if(s<=0||i<s)return;this._stacks||(this._stacks=new Map);let r=this._stacks.get(t.value)||0;if(this._stacks.set(t.value,r+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=s*.5;let[n,o]=this.getMostFrequentStack(),a=`[${this.name}] potential listener LEAK detected, having ${i} listeners already. MOST frequent listener (${o}):`;console.warn(a),console.warn(n);let l=new f_(a,n);this._errorHandler(l)}return()=>{let n=this._stacks.get(t.value)||0;this._stacks.set(t.value,n-1)}}getMostFrequentStack(){if(!this._stacks)return;let t,i=0;for(let[s,r]of this._stacks)(!t||i<r)&&(t=[s,r],i=r);return t}};Pl._idPool=1;var u_=Pl,__=class Ml{constructor(t){this.value=t}static create(){let t=new Error;return new Ml(t.stack??"")}print(){console.warn(this.value.split(`
`).slice(2).join(`
`))}},f_=class extends Error{constructor(e,t){super(e),this.name="ListenerLeakError",this.stack=t}},p_=class extends Error{constructor(e,t){super(e),this.name="ListenerRefusalError",this.stack=t}},m_=0,pr=class{constructor(e){this.value=e,this.id=m_++}},g_=2,v_,k=class{constructor(e){this._size=0,this._options=e,this._leakageMon=this._options?.leakWarningThreshold?new u_(e?.onListenerError??fs,this._options?.leakWarningThreshold??d_):void 0,this._perfMon=this._options?._profName?new c_(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){this._disposed||(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose())}get event(){return this._event??=(e,t,i)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let o=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(o);let a=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],l=new p_(`${o}. HINT: Stack shows most frequent listener (${a[1]}-times)`,a[0]);return(this._options?.onListenerError||fs)(l),W.None}if(this._disposed)return W.None;t&&(e=e.bind(t));let s=new pr(e),r;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(s.stack=__.create(),r=this._leakageMon.check(s.stack,this._size+1)),this._listeners?this._listeners instanceof pr?(this._deliveryQueue??=new S_,this._listeners=[this._listeners,s]):this._listeners.push(s):(this._options?.onWillAddFirstListener?.(this),this._listeners=s,this._options?.onDidAddFirstListener?.(this)),this._size++;let n=ne(()=>{r?.(),this._removeListener(s)});return i instanceof zt?i.add(n):Array.isArray(i)&&i.push(n),n},this._event}_removeListener(e){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let t=this._listeners,i=t.indexOf(e);if(i===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,t[i]=void 0;let s=this._deliveryQueue.current===this;if(this._size*g_<=t.length){let r=0;for(let n=0;n<t.length;n++)t[n]?t[r++]=t[n]:s&&(this._deliveryQueue.end--,r<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=r}}_deliver(e,t){if(!e)return;let i=this._options?.onListenerError||fs;if(!i){e.value(t);return}try{e.value(t)}catch(s){i(s)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners)if(this._listeners instanceof pr)this._deliver(this._listeners,e);else{let t=this._deliveryQueue;t.enqueue(this,e,this._listeners.length),this._deliverQueue(t)}this._perfMon?.stop()}hasListeners(){return this._size>0}},S_=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,i){this.i=0,this.end=i,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Gr=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new k,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new k,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(t){return this.mapWindowIdToZoomLevel.get(this.getWindowId(t))??0}setZoomLevel(t,i){if(this.getZoomLevel(i)===t)return;let s=this.getWindowId(i);this.mapWindowIdToZoomLevel.set(s,t),this._onDidChangeZoomLevel.fire(s)}getZoomFactor(t){return this.mapWindowIdToZoomFactor.get(this.getWindowId(t))??1}setZoomFactor(t,i){this.mapWindowIdToZoomFactor.set(this.getWindowId(i),t)}setFullscreen(t,i){if(this.isFullscreen(i)===t)return;let s=this.getWindowId(i);this.mapWindowIdToFullScreen.set(s,t),this._onDidChangeFullscreen.fire(s)}isFullscreen(t){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(t))}getWindowId(t){return t.vscodeWindowId}};Gr.INSTANCE=new Gr;var Tn=Gr;function b_(e,t,i){typeof t=="string"&&(t=e.matchMedia(t)),t.addEventListener("change",i)}Tn.INSTANCE.onDidChangeZoomLevel;function y_(e){return Tn.INSTANCE.getZoomFactor(e)}Tn.INSTANCE.onDidChangeFullscreen;var mi=typeof navigator=="object"?navigator.userAgent:"",Wr=mi.indexOf("Firefox")>=0,C_=mi.indexOf("AppleWebKit")>=0,Rn=mi.indexOf("Chrome")>=0,w_=!Rn&&mi.indexOf("Safari")>=0;mi.indexOf("Electron/")>=0;mi.indexOf("Android")>=0;var mr=!1;if(typeof At.matchMedia=="function"){let e=At.matchMedia("(display-mode: standalone) or (display-mode: window-controls-overlay)"),t=At.matchMedia("(display-mode: fullscreen)");mr=e.matches,b_(At,e,({matches:i})=>{mr&&t.matches||(mr=i)})}var di="en",$r=!1,Vr=!1,ps=!1,Dl=!1,ss,ms=di,Ao=di,E_,It,Jt=globalThis,Ze;typeof Jt.vscode<"u"&&typeof Jt.vscode.process<"u"?Ze=Jt.vscode.process:typeof process<"u"&&typeof process?.versions?.node=="string"&&(Ze=process);var x_=typeof Ze?.versions?.electron=="string",I_=x_&&Ze?.type==="renderer";if(typeof Ze=="object"){$r=Ze.platform==="win32",Vr=Ze.platform==="darwin",ps=Ze.platform==="linux",ps&&Ze.env.SNAP&&Ze.env.SNAP_REVISION,Ze.env.CI||Ze.env.BUILD_ARTIFACTSTAGINGDIRECTORY,ss=di,ms=di;let e=Ze.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);ss=t.userLocale,Ao=t.osLocale,ms=t.resolvedLanguage||di,E_=t.languagePack?.translationsConfigFile}catch{}Dl=!0}else typeof navigator=="object"&&!I_?(It=navigator.userAgent,$r=It.indexOf("Windows")>=0,Vr=It.indexOf("Macintosh")>=0,(It.indexOf("Macintosh")>=0||It.indexOf("iPad")>=0||It.indexOf("iPhone")>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>0,ps=It.indexOf("Linux")>=0,It?.indexOf("Mobi")>=0,ms=globalThis._VSCODE_NLS_LANGUAGE||di,ss=navigator.language.toLowerCase(),Ao=ss):console.error("Unable to resolve platform.");var Tl=$r,bt=Vr,A_=ps,Po=Dl,Ct=It,Nt=ms,P_;(e=>{function t(){return Nt}e.value=t;function i(){return Nt.length===2?Nt==="en":Nt.length>=3?Nt[0]==="e"&&Nt[1]==="n"&&Nt[2]==="-":!1}e.isDefaultVariant=i;function s(){return Nt==="en"}e.isDefault=s})(P_||={});var k_=typeof Jt.postMessage=="function"&&!Jt.importScripts;(()=>{if(k_){let e=[];Jt.addEventListener("message",i=>{if(i.data&&i.data.vscodeScheduleAsyncWork)for(let s=0,r=e.length;s<r;s++){let n=e[s];if(n.id===i.data.vscodeScheduleAsyncWork){e.splice(s,1),n.callback();return}}});let t=0;return i=>{let s=++t;e.push({id:s,callback:i}),Jt.postMessage({vscodeScheduleAsyncWork:s},"*")}}return e=>setTimeout(e)})();var M_=!!(Ct&&Ct.indexOf("Chrome")>=0);Ct&&Ct.indexOf("Firefox")>=0;!M_&&Ct&&Ct.indexOf("Safari")>=0;Ct&&Ct.indexOf("Edg/")>=0;Ct&&Ct.indexOf("Android")>=0;var ai=typeof navigator=="object"?navigator:{};Po||document.queryCommandSupported&&document.queryCommandSupported("copy")||ai&&ai.clipboard&&ai.clipboard.writeText,Po||ai&&ai.clipboard&&ai.clipboard.readText;var Ln=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(e,t){this._keyCodeToStr[e]=t,this._strToKeyCode[t.toLowerCase()]=e}keyCodeToStr(e){return this._keyCodeToStr[e]}strToKeyCode(e){return this._strToKeyCode[e.toLowerCase()]||0}},gr=new Ln,ko=new Ln,Mo=new Ln,D_=new Array(230),Rl;(e=>{function t(a){return gr.keyCodeToStr(a)}e.toString=t;function i(a){return gr.strToKeyCode(a)}e.fromString=i;function s(a){return ko.keyCodeToStr(a)}e.toUserSettingsUS=s;function r(a){return Mo.keyCodeToStr(a)}e.toUserSettingsGeneral=r;function n(a){return ko.strToKeyCode(a)||Mo.strToKeyCode(a)}e.fromUserSettings=n;function o(a){if(a>=98&&a<=113)return null;switch(a){case 16:return"Up";case 18:return"Down";case 15:return"Left";case 17:return"Right"}return gr.keyCodeToStr(a)}e.toElectronAccelerator=o})(Rl||={});var T_=class Ll{constructor(t,i,s,r,n){this.ctrlKey=t,this.shiftKey=i,this.altKey=s,this.metaKey=r,this.keyCode=n}equals(t){return t instanceof Ll&&this.ctrlKey===t.ctrlKey&&this.shiftKey===t.shiftKey&&this.altKey===t.altKey&&this.metaKey===t.metaKey&&this.keyCode===t.keyCode}getHashCode(){let t=this.ctrlKey?"1":"0",i=this.shiftKey?"1":"0",s=this.altKey?"1":"0",r=this.metaKey?"1":"0";return`K${t}${i}${s}${r}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new R_([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},R_=class{constructor(e){if(e.length===0)throw r_("chords");this.chords=e}getHashCode(){let e="";for(let t=0,i=this.chords.length;t<i;t++)t!==0&&(e+=";"),e+=this.chords[t].getHashCode();return e}equals(e){if(e===null||this.chords.length!==e.chords.length)return!1;for(let t=0;t<this.chords.length;t++)if(!this.chords[t].equals(e.chords[t]))return!1;return!0}};function L_(e){if(e.charCode){let i=String.fromCharCode(e.charCode).toUpperCase();return Rl.fromString(i)}let t=e.keyCode;if(t===3)return 7;if(Wr)switch(t){case 59:return 85;case 60:if(A_)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(bt)return 57;break}else if(C_&&(bt&&t===93||!bt&&t===92))return 57;return D_[t]||0}var N_=bt?256:2048,B_=512,O_=1024,U_=bt?2048:256,Do=class{constructor(e){this._standardKeyboardEventBrand=!0;let t=e;this.browserEvent=t,this.target=t.target,this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,this.altGraphKey=t.getModifierState?.("AltGraph"),this.keyCode=L_(t),this.code=t.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(e){return this._asKeybinding===e}_computeKeybinding(){let e=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode);let t=0;return this.ctrlKey&&(t|=N_),this.altKey&&(t|=B_),this.shiftKey&&(t|=O_),this.metaKey&&(t|=U_),t|=e,t}_computeKeyCodeChord(){let e=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode),new T_(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,e)}},To=new WeakMap;function F_(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,i=e.parent.location;if(t.origin!=="null"&&i.origin!=="null"&&t.origin!==i.origin)return null}catch{return null}return e.parent}var j_=class{static getSameOriginWindowChain(e){let t=To.get(e);if(!t){t=[],To.set(e,t);let i=e,s;do s=F_(i),s?t.push({window:new WeakRef(i),iframeElement:i.frameElement||null}):t.push({window:new WeakRef(i),iframeElement:null}),i=s;while(i)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let i=0,s=0,r=this.getSameOriginWindowChain(e);for(let n of r){let o=n.window.deref();if(i+=o?.scrollY??0,s+=o?.scrollX??0,o===t||!n.iframeElement)break;let a=n.iframeElement.getBoundingClientRect();i+=a.top,s+=a.left}return{top:i,left:s}}},rs=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail||1,t.type==="dblclick"&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX=="number"?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let i=j_.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=i.left,this.posy-=i.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},Ro=class{constructor(e,t=0,i=0){this.browserEvent=e||null,this.target=e?e.target||e.targetNode||e.srcElement:null,this.deltaY=i,this.deltaX=t;let s=!1;if(Rn){let r=navigator.userAgent.match(/Chrome\/(\d+)/);s=(r?parseInt(r[1]):123)<=122}if(e){let r=e,n=e,o=e.view?.devicePixelRatio||1;if(typeof r.wheelDeltaY<"u")s?this.deltaY=r.wheelDeltaY/(120*o):this.deltaY=r.wheelDeltaY/120;else if(typeof n.VERTICAL_AXIS<"u"&&n.axis===n.VERTICAL_AXIS)this.deltaY=-n.detail/3;else if(e.type==="wheel"){let a=e;a.deltaMode===a.DOM_DELTA_LINE?Wr&&!bt?this.deltaY=-e.deltaY/3:this.deltaY=-e.deltaY:this.deltaY=-e.deltaY/40}if(typeof r.wheelDeltaX<"u")w_&&Tl?this.deltaX=-(r.wheelDeltaX/120):s?this.deltaX=r.wheelDeltaX/(120*o):this.deltaX=r.wheelDeltaX/120;else if(typeof n.HORIZONTAL_AXIS<"u"&&n.axis===n.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type==="wheel"){let a=e;a.deltaMode===a.DOM_DELTA_LINE?Wr&&!bt?this.deltaX=-e.deltaX/3:this.deltaX=-e.deltaX:this.deltaX=-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(s?this.deltaY=e.wheelDelta/(120*o):this.deltaY=e.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},Nl=Object.freeze(function(e,t){let i=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(i)}}}),K_;(e=>{function t(i){return i===e.None||i===e.Cancelled||i instanceof z_?!0:!i||typeof i!="object"?!1:typeof i.isCancellationRequested=="boolean"&&typeof i.onCancellationRequested=="function"}e.isCancellationToken=t,e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:Be.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:Nl})})(K_||={});var z_=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?Nl:(this._emitter||(this._emitter=new k),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}},Nn=class{constructor(e,t){this._isDisposed=!1,this._token=-1,typeof e=="function"&&typeof t=="number"&&this.setIfNotSet(e,t)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new jr("Calling 'cancelAndSet' on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new jr("Calling 'setIfNotSet' on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},Y_=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){this.disposable?.dispose(),this.disposable=void 0}cancelAndSet(e,t,i=globalThis){if(this.isDisposed)throw new jr("Calling 'cancelAndSet' on a disposed IntervalTimer");this.cancel();let s=i.setInterval(()=>{e()},t);this.disposable=ne(()=>{i.clearInterval(s),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}},H_;(e=>{async function t(s){let r,n=await Promise.all(s.map(o=>o.then(a=>a,a=>{r||(r=a)})));if(typeof r<"u")throw r;return n}e.settled=t;function i(s){return new Promise(async(r,n)=>{try{await s(r,n)}catch(o){n(o)}})}e.withAsyncBody=i})(H_||={});var Lo=class ot{static fromArray(t){return new ot(i=>{i.emitMany(t)})}static fromPromise(t){return new ot(async i=>{i.emitMany(await t)})}static fromPromises(t){return new ot(async i=>{await Promise.all(t.map(async s=>i.emitOne(await s)))})}static merge(t){return new ot(async i=>{await Promise.all(t.map(async s=>{for await(let r of s)i.emitOne(r)}))})}constructor(t,i){this._state=0,this._results=[],this._error=null,this._onReturn=i,this._onStateChanged=new k,queueMicrotask(async()=>{let s={emitOne:r=>this.emitOne(r),emitMany:r=>this.emitMany(r),reject:r=>this.reject(r)};try{await Promise.resolve(t(s)),this.resolve()}catch(r){this.reject(r)}finally{s.emitOne=void 0,s.emitMany=void 0,s.reject=void 0}})}[Symbol.asyncIterator](){let t=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(t<this._results.length)return{done:!1,value:this._results[t++]};if(this._state===1)return{done:!0,value:void 0};await Be.toPromise(this._onStateChanged.event)}while(!0)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(t,i){return new ot(async s=>{for await(let r of t)s.emitOne(i(r))})}map(t){return ot.map(this,t)}static filter(t,i){return new ot(async s=>{for await(let r of t)i(r)&&s.emitOne(r)})}filter(t){return ot.filter(this,t)}static coalesce(t){return ot.filter(t,i=>!!i)}coalesce(){return ot.coalesce(this)}static async toPromise(t){let i=[];for await(let s of t)i.push(s);return i}toPromise(){return ot.toPromise(this)}emitOne(t){this._state===0&&(this._results.push(t),this._onStateChanged.fire())}emitMany(t){this._state===0&&(this._results=this._results.concat(t),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(t){this._state===0&&(this._state=2,this._error=t,this._onStateChanged.fire())}};Lo.EMPTY=Lo.fromArray([]);var{getWindow:St,getWindowId:G_,onDidRegisterWindow:W_}=(function(){let e=new Map,t={window:At,disposables:new zt};e.set(At.vscodeWindowId,t);let i=new k,s=new k,r=new k;function n(o,a){return(typeof o=="number"?e.get(o):void 0)??(a?t:void 0)}return{onDidRegisterWindow:i.event,onWillUnregisterWindow:r.event,onDidUnregisterWindow:s.event,registerWindow(o){if(e.has(o.vscodeWindowId))return W.None;let a=new zt,l={window:o,disposables:a.add(new zt)};return e.set(o.vscodeWindowId,l),a.add(ne(()=>{e.delete(o.vscodeWindowId),s.fire(o)})),a.add(K(o,Ae.BEFORE_UNLOAD,()=>{r.fire(o)})),i.fire(l),a},getWindows(){return e.values()},getWindowsCount(){return e.size},getWindowId(o){return o.vscodeWindowId},hasWindow(o){return e.has(o)},getWindowById:n,getWindow(o){let a=o;if(a?.ownerDocument?.defaultView)return a.ownerDocument.defaultView.window;let l=o;return l?.view?l.view.window:At},getDocument(o){return St(o).document}}})(),$_=class{constructor(e,t,i,s){this._node=e,this._type=t,this._handler=i,this._options=s||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function K(e,t,i,s){return new $_(e,t,i,s)}var No=function(e,t,i,s){return K(e,t,i,s)},Bn,V_=class extends Y_{constructor(e){super(),this.defaultTarget=e&&St(e)}cancelAndSet(e,t,i){return super.cancelAndSet(e,t,i??this.defaultTarget)}},Bo=class{constructor(e,t=0){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){fs(e)}}static sort(e,t){return t.priority-e.priority}};(function(){let e=new Map,t=new Map,i=new Map,s=new Map,r=n=>{i.set(n,!1);let o=e.get(n)??[];for(t.set(n,o),e.set(n,[]),s.set(n,!0);o.length>0;)o.sort(Bo.sort),o.shift().execute();s.set(n,!1)};Bn=(n,o,a=0)=>{let l=G_(n),c=new Bo(o,a),d=e.get(l);return d||(d=[],e.set(l,d)),d.push(c),i.get(l)||(i.set(l,!0),n.requestAnimationFrame(()=>r(l))),c}})();function q_(e){let t=e.getBoundingClientRect(),i=St(e);return{left:t.left+i.scrollX,top:t.top+i.scrollY,width:t.width,height:t.height}}var Ae={CLICK:"click",MOUSE_DOWN:"mousedown",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",MOUSE_WHEEL:"wheel",POINTER_UP:"pointerup",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",KEY_DOWN:"keydown",KEY_UP:"keyup",BEFORE_UNLOAD:"beforeunload",CHANGE:"change",FOCUS:"focus",BLUR:"blur",INPUT:"input"},X_=class{constructor(e){this.domNode=e,this._maxWidth="",this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._paddingTop="",this._paddingLeft="",this._paddingBottom="",this._paddingRight="",this._fontFamily="",this._fontWeight="",this._fontSize="",this._fontStyle="",this._fontFeatureSettings="",this._fontVariationSettings="",this._textDecoration="",this._lineHeight="",this._letterSpacing="",this._className="",this._display="",this._position="",this._visibility="",this._color="",this._backgroundColor="",this._layerHint=!1,this._contain="none",this._boxShadow=""}setMaxWidth(e){let t=qe(e);this._maxWidth!==t&&(this._maxWidth=t,this.domNode.style.maxWidth=this._maxWidth)}setWidth(e){let t=qe(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=qe(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=qe(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=qe(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=qe(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=qe(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setPaddingTop(e){let t=qe(e);this._paddingTop!==t&&(this._paddingTop=t,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(e){let t=qe(e);this._paddingLeft!==t&&(this._paddingLeft=t,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(e){let t=qe(e);this._paddingBottom!==t&&(this._paddingBottom=t,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(e){let t=qe(e);this._paddingRight!==t&&(this._paddingRight=t,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(e){let t=qe(e);this._fontSize!==t&&(this._fontSize=t,this.domNode.style.fontSize=this._fontSize)}setFontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(e){this._fontFeatureSettings!==e&&(this._fontFeatureSettings=e,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(e){this._fontVariationSettings!==e&&(this._fontVariationSettings=e,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(e){this._textDecoration!==e&&(this._textDecoration=e,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(e){let t=qe(e);this._lineHeight!==t&&(this._lineHeight=t,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(e){let t=qe(e);this._letterSpacing!==t&&(this._letterSpacing=t,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setDisplay(e){this._display!==e&&(this._display=e,this.domNode.style.display=this._display)}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this.domNode.style.visibility=this._visibility)}setColor(e){this._color!==e&&(this._color=e,this.domNode.style.color=this._color)}setBackgroundColor(e){this._backgroundColor!==e&&(this._backgroundColor=e,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,this.domNode.style.transform=this._layerHint?"translate3d(0px, 0px, 0px)":"")}setBoxShadow(e){this._boxShadow!==e&&(this._boxShadow=e,this.domNode.style.boxShadow=e)}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}removeAttribute(e){this.domNode.removeAttribute(e)}appendChild(e){this.domNode.appendChild(e.domNode)}removeChild(e){this.domNode.removeChild(e.domNode)}};function qe(e){return typeof e=="number"?`${e}px`:e}function Ui(e){return new X_(e)}var Bl=class{constructor(){this._hooks=new zt,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e,t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let i=this._onStopCallback;this._onStopCallback=null,e&&i&&i(t)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,i,s,r){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=s,this._onStopCallback=r;let n=e;try{e.setPointerCapture(t),this._hooks.add(ne(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{n=St(e)}this._hooks.add(K(n,Ae.POINTER_MOVE,o=>{if(o.buttons!==i){this.stopMonitoring(!0);return}o.preventDefault(),this._pointerMoveCallback(o)})),this._hooks.add(K(n,Ae.POINTER_UP,o=>this.stopMonitoring(!0)))}};function Q_(e,t,i){let s=null,r=null;if(typeof i.value=="function"?(s="value",r=i.value,r.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof i.get=="function"&&(s="get",r=i.get),!r)throw new Error("not supported");let n=`$memoize$${t}`;i[s]=function(...o){return this.hasOwnProperty(n)||Object.defineProperty(this,n,{configurable:!1,enumerable:!1,writable:!1,value:r.apply(this,o)}),this[n]}}var vt;(e=>(e.Tap="-xterm-gesturetap",e.Change="-xterm-gesturechange",e.Start="-xterm-gesturestart",e.End="-xterm-gesturesend",e.Contextmenu="-xterm-gesturecontextmenu"))(vt||={});var Ti=class Fe extends W{constructor(){super(),this.dispatched=!1,this.targets=new Io,this.ignoreTargets=new Io,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(Be.runAndSubscribe(W_,({window:t,disposables:i})=>{i.add(K(t.document,"touchstart",s=>this.onTouchStart(s),{passive:!1})),i.add(K(t.document,"touchend",s=>this.onTouchEnd(t,s))),i.add(K(t.document,"touchmove",s=>this.onTouchMove(s),{passive:!1}))},{window:At,disposables:this._store}))}static addTarget(t){if(!Fe.isTouchDevice())return W.None;Fe.INSTANCE||(Fe.INSTANCE=new Fe);let i=Fe.INSTANCE.targets.push(t);return ne(i)}static ignoreTarget(t){if(!Fe.isTouchDevice())return W.None;Fe.INSTANCE||(Fe.INSTANCE=new Fe);let i=Fe.INSTANCE.ignoreTargets.push(t);return ne(i)}static isTouchDevice(){return"ontouchstart"in At||navigator.maxTouchPoints>0}dispose(){this.handle&&(this.handle.dispose(),this.handle=null),super.dispose()}onTouchStart(t){let i=Date.now();this.handle&&(this.handle.dispose(),this.handle=null);for(let s=0,r=t.targetTouches.length;s<r;s++){let n=t.targetTouches.item(s);this.activeTouches[n.identifier]={id:n.identifier,initialTarget:n.target,initialTimeStamp:i,initialPageX:n.pageX,initialPageY:n.pageY,rollingTimestamps:[i],rollingPageX:[n.pageX],rollingPageY:[n.pageY]};let o=this.newGestureEvent(vt.Start,n.target);o.pageX=n.pageX,o.pageY=n.pageY,this.dispatchEvent(o)}this.dispatched&&(t.preventDefault(),t.stopPropagation(),this.dispatched=!1)}onTouchEnd(t,i){let s=Date.now(),r=Object.keys(this.activeTouches).length;for(let n=0,o=i.changedTouches.length;n<o;n++){let a=i.changedTouches.item(n);if(!this.activeTouches.hasOwnProperty(String(a.identifier))){console.warn("move of an UNKNOWN touch",a);continue}let l=this.activeTouches[a.identifier],c=Date.now()-l.initialTimeStamp;if(c<Fe.HOLD_DELAY&&Math.abs(l.initialPageX-Xe(l.rollingPageX))<30&&Math.abs(l.initialPageY-Xe(l.rollingPageY))<30){let d=this.newGestureEvent(vt.Tap,l.initialTarget);d.pageX=Xe(l.rollingPageX),d.pageY=Xe(l.rollingPageY),this.dispatchEvent(d)}else if(c>=Fe.HOLD_DELAY&&Math.abs(l.initialPageX-Xe(l.rollingPageX))<30&&Math.abs(l.initialPageY-Xe(l.rollingPageY))<30){let d=this.newGestureEvent(vt.Contextmenu,l.initialTarget);d.pageX=Xe(l.rollingPageX),d.pageY=Xe(l.rollingPageY),this.dispatchEvent(d)}else if(r===1){let d=Xe(l.rollingPageX),p=Xe(l.rollingPageY),f=Xe(l.rollingTimestamps)-l.rollingTimestamps[0],g=d-l.rollingPageX[0],u=p-l.rollingPageY[0],_=[...this.targets].filter(S=>l.initialTarget instanceof Node&&S.contains(l.initialTarget));this.inertia(t,_,s,Math.abs(g)/f,g>0?1:-1,d,Math.abs(u)/f,u>0?1:-1,p)}this.dispatchEvent(this.newGestureEvent(vt.End,l.initialTarget)),delete this.activeTouches[a.identifier]}this.dispatched&&(i.preventDefault(),i.stopPropagation(),this.dispatched=!1)}newGestureEvent(t,i){let s=document.createEvent("CustomEvent");return s.initEvent(t,!1,!0),s.initialTarget=i,s.tapCount=0,s}dispatchEvent(t){if(t.type===vt.Tap){let i=new Date().getTime(),s=0;i-this._lastSetTapCountTime>Fe.CLEAR_TAP_COUNT_TIME?s=1:s=2,this._lastSetTapCountTime=i,t.tapCount=s}else(t.type===vt.Change||t.type===vt.Contextmenu)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let s of this.ignoreTargets)if(s.contains(t.initialTarget))return;let i=[];for(let s of this.targets)if(s.contains(t.initialTarget)){let r=0,n=t.initialTarget;for(;n&&n!==s;)r++,n=n.parentElement;i.push([r,s])}i.sort((s,r)=>s[0]-r[0]);for(let[s,r]of i)r.dispatchEvent(t),this.dispatched=!0}}inertia(t,i,s,r,n,o,a,l,c){this.handle=Bn(t,()=>{let d=Date.now(),p=d-s,f=0,g=0,u=!0;r+=Fe.SCROLL_FRICTION*p,a+=Fe.SCROLL_FRICTION*p,r>0&&(u=!1,f=n*r*p),a>0&&(u=!1,g=l*a*p);let _=this.newGestureEvent(vt.Change);_.translationX=f,_.translationY=g,i.forEach(S=>S.dispatchEvent(_)),u||this.inertia(t,i,d,r,n,o+f,a,l,c+g)})}onTouchMove(t){let i=Date.now();for(let s=0,r=t.changedTouches.length;s<r;s++){let n=t.changedTouches.item(s);if(!this.activeTouches.hasOwnProperty(String(n.identifier))){console.warn("end of an UNKNOWN touch",n);continue}let o=this.activeTouches[n.identifier],a=this.newGestureEvent(vt.Change,o.initialTarget);a.translationX=n.pageX-Xe(o.rollingPageX),a.translationY=n.pageY-Xe(o.rollingPageY),a.pageX=n.pageX,a.pageY=n.pageY,this.dispatchEvent(a),o.rollingPageX.length>3&&(o.rollingPageX.shift(),o.rollingPageY.shift(),o.rollingTimestamps.shift()),o.rollingPageX.push(n.pageX),o.rollingPageY.push(n.pageY),o.rollingTimestamps.push(i)}this.dispatched&&(t.preventDefault(),t.stopPropagation(),this.dispatched=!1)}};Ti.SCROLL_FRICTION=-.005,Ti.HOLD_DELAY=700,Ti.CLEAR_TAP_COUNT_TIME=400,ce([Q_],Ti,"isTouchDevice",1);var Z_=Ti,On=class extends W{onclick(e,t){this._register(K(e,Ae.CLICK,i=>t(new rs(St(e),i))))}onmousedown(e,t){this._register(K(e,Ae.MOUSE_DOWN,i=>t(new rs(St(e),i))))}onmouseover(e,t){this._register(K(e,Ae.MOUSE_OVER,i=>t(new rs(St(e),i))))}onmouseleave(e,t){this._register(K(e,Ae.MOUSE_LEAVE,i=>t(new rs(St(e),i))))}onkeydown(e,t){this._register(K(e,Ae.KEY_DOWN,i=>t(new Do(i))))}onkeyup(e,t){this._register(K(e,Ae.KEY_UP,i=>t(new Do(i))))}oninput(e,t){this._register(K(e,Ae.INPUT,t))}onblur(e,t){this._register(K(e,Ae.BLUR,t))}onfocus(e,t){this._register(K(e,Ae.FOCUS,t))}onchange(e,t){this._register(K(e,Ae.CHANGE,t))}ignoreGesture(e){return Z_.ignoreTarget(e)}},Oo=11,J_=class extends On{constructor(e){super(),this._onActivate=e.onActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=e.bgWidth+"px",this.bgDomNode.style.height=e.bgHeight+"px",typeof e.top<"u"&&(this.bgDomNode.style.top="0px"),typeof e.left<"u"&&(this.bgDomNode.style.left="0px"),typeof e.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof e.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=e.className,this.domNode.style.position="absolute",this.domNode.style.width=Oo+"px",this.domNode.style.height=Oo+"px",typeof e.top<"u"&&(this.domNode.style.top=e.top+"px"),typeof e.left<"u"&&(this.domNode.style.left=e.left+"px"),typeof e.bottom<"u"&&(this.domNode.style.bottom=e.bottom+"px"),typeof e.right<"u"&&(this.domNode.style.right=e.right+"px"),this._pointerMoveMonitor=this._register(new Bl),this._register(No(this.bgDomNode,Ae.POINTER_DOWN,t=>this._arrowPointerDown(t))),this._register(No(this.domNode,Ae.POINTER_DOWN,t=>this._arrowPointerDown(t))),this._pointerdownRepeatTimer=this._register(new V_),this._pointerdownScheduleRepeatTimer=this._register(new Nn)}_arrowPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,St(e))};this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(t,200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,i=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault()}},ef=class qr{constructor(t,i,s,r,n,o,a){this._forceIntegerValues=t,this._scrollStateBrand=void 0,this._forceIntegerValues&&(i=i|0,s=s|0,r=r|0,n=n|0,o=o|0,a=a|0),this.rawScrollLeft=r,this.rawScrollTop=a,i<0&&(i=0),r+i>s&&(r=s-i),r<0&&(r=0),n<0&&(n=0),a+n>o&&(a=o-n),a<0&&(a=0),this.width=i,this.scrollWidth=s,this.scrollLeft=r,this.height=n,this.scrollHeight=o,this.scrollTop=a}equals(t){return this.rawScrollLeft===t.rawScrollLeft&&this.rawScrollTop===t.rawScrollTop&&this.width===t.width&&this.scrollWidth===t.scrollWidth&&this.scrollLeft===t.scrollLeft&&this.height===t.height&&this.scrollHeight===t.scrollHeight&&this.scrollTop===t.scrollTop}withScrollDimensions(t,i){return new qr(this._forceIntegerValues,typeof t.width<"u"?t.width:this.width,typeof t.scrollWidth<"u"?t.scrollWidth:this.scrollWidth,i?this.rawScrollLeft:this.scrollLeft,typeof t.height<"u"?t.height:this.height,typeof t.scrollHeight<"u"?t.scrollHeight:this.scrollHeight,i?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new qr(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<"u"?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<"u"?t.scrollTop:this.rawScrollTop)}createScrollEvent(t,i){let s=this.width!==t.width,r=this.scrollWidth!==t.scrollWidth,n=this.scrollLeft!==t.scrollLeft,o=this.height!==t.height,a=this.scrollHeight!==t.scrollHeight,l=this.scrollTop!==t.scrollTop;return{inSmoothScrolling:i,oldWidth:t.width,oldScrollWidth:t.scrollWidth,oldScrollLeft:t.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:t.height,oldScrollHeight:t.scrollHeight,oldScrollTop:t.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:s,scrollWidthChanged:r,scrollLeftChanged:n,heightChanged:o,scrollHeightChanged:a,scrollTopChanged:l}}},tf=class extends W{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new k),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new ef(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){let i=this._state.withScrollDimensions(e,t);this._setState(i,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(e);if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>"u"?this._smoothScrolling.to.scrollTop:e.scrollTop};let i=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===i.scrollLeft&&this._smoothScrolling.to.scrollTop===i.scrollTop)return;let s;t?s=new Fo(this._smoothScrolling.from,i,this._smoothScrolling.startTime,this._smoothScrolling.duration):s=this._smoothScrolling.combine(this._state,i,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=s}else{let i=this._state.withScrollPosition(e);this._smoothScrolling=Fo.start(this._state,i,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),!!this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let i=this._state;i.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(i,t)))}},Uo=class{constructor(e,t,i){this.scrollLeft=e,this.scrollTop=t,this.isDone=i}};function vr(e,t){let i=t-e;return function(s){return e+i*nf(s)}}function sf(e,t,i){return function(s){return s<i?e(s/i):t((s-i)/(1-i))}}var Fo=class Xr{constructor(t,i,s,r){this.from=t,this.to=i,this.duration=r,this.startTime=s,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(t,i,s){if(Math.abs(t-i)>2.5*s){let r,n;return t<i?(r=t+.75*s,n=i-.75*s):(r=t-.75*s,n=i+.75*s),sf(vr(t,r),vr(n,i),.33)}return vr(t,i)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(t){this.to=t.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(t){let i=(t-this.startTime)/this.duration;if(i<1){let s=this.scrollLeft(i),r=this.scrollTop(i);return new Uo(s,r,!1)}return new Uo(this.to.scrollLeft,this.to.scrollTop,!0)}combine(t,i,s){return Xr.start(t,i,s)}static start(t,i,s){s=s+10;let r=Date.now()-10;return new Xr(t,i,r,s)}};function rf(e){return Math.pow(e,3)}function nf(e){return 1-rf(1-e)}var of=class extends W{constructor(e,t,i){super(),this._visibility=e,this._visibleClassName=t,this._invisibleClassName=i,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new Nn)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this._updateShouldBeVisible())}setShouldBeVisible(e){this._rawShouldBeVisible=e,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3?!0:this._rawShouldBeVisible}_updateShouldBeVisible(){let e=this._applyVisibilitySetting();this._shouldBeVisible!==e&&(this._shouldBeVisible=e,this.ensureVisibility())}setIsNeeded(e){this._isNeeded!==e&&(this._isNeeded=e,this.ensureVisibility())}setDomNode(e){this._domNode=e,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){if(!this._isNeeded){this._hide(!1);return}this._shouldBeVisible?this._reveal():this._hide(!0)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(e){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(e?" fade":"")))}},af=140,Ol=class extends On{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new of(e.visibility,"visible scrollbar "+e.extraScrollbarClassName,"invisible scrollbar "+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new Bl),this._shouldRender=!0,this.domNode=Ui(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(K(this.domNode.domNode,Ae.POINTER_DOWN,t=>this._domNodePointerDown(t)))}_createArrow(e){let t=this._register(new J_(e));this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode)}_createSlider(e,t,i,s){this.slider=Ui(document.createElement("div")),this.slider.setClassName("slider"),this.slider.setPosition("absolute"),this.slider.setTop(e),this.slider.setLeft(t),typeof i=="number"&&this.slider.setWidth(i),typeof s=="number"&&this.slider.setHeight(s),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(K(this.slider.domNode,Ae.POINTER_DOWN,r=>{r.button===0&&(r.preventDefault(),this._sliderPointerDown(r))})),this.onclick(this.slider.domNode,r=>{r.leftButton&&r.stopPropagation()})}_onElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._onPointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,i=t+this._scrollbarState.getSliderPosition(),s=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),r=this._sliderPointerPosition(e);i<=r&&r<=s?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._onPointerDown(e)}_onPointerDown(e){let t,i;if(e.target===this.domNode.domNode&&typeof e.offsetX=="number"&&typeof e.offsetY=="number")t=e.offsetX,i=e.offsetY;else{let r=q_(this.domNode.domNode);t=e.pageX-r.left,i=e.pageY-r.top}let s=this._pointerDownRelativePosition(t,i);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(s):this._scrollbarState.getDesiredScrollPositionFromOffset(s)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),i=this._sliderOrthogonalPointerPosition(e),s=this._scrollbarState.clone();this.slider.toggleClassName("active",!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,r=>{let n=this._sliderOrthogonalPointerPosition(r),o=Math.abs(n-i);if(Tl&&o>af){this._setDesiredScrollPositionNow(s.getScrollPosition());return}let a=this._sliderPointerPosition(r)-t;this._setDesiredScrollPositionNow(s.getDesiredScrollPositionFromDelta(a))},()=>{this.slider.toggleClassName("active",!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},Ul=class Qr{constructor(t,i,s,r,n,o){this._scrollbarSize=Math.round(i),this._oppositeScrollbarSize=Math.round(s),this._arrowSize=Math.round(t),this._visibleSize=r,this._scrollSize=n,this._scrollPosition=o,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new Qr(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(t){let i=Math.round(t);return this._visibleSize!==i?(this._visibleSize=i,this._refreshComputedValues(),!0):!1}setScrollSize(t){let i=Math.round(t);return this._scrollSize!==i?(this._scrollSize=i,this._refreshComputedValues(),!0):!1}setScrollPosition(t){let i=Math.round(t);return this._scrollPosition!==i?(this._scrollPosition=i,this._refreshComputedValues(),!0):!1}setScrollbarSize(t){this._scrollbarSize=Math.round(t)}setOppositeScrollbarSize(t){this._oppositeScrollbarSize=Math.round(t)}static _computeValues(t,i,s,r,n){let o=Math.max(0,s-t),a=Math.max(0,o-2*i),l=r>0&&r>s;if(!l)return{computedAvailableSize:Math.round(o),computedIsNeeded:l,computedSliderSize:Math.round(a),computedSliderRatio:0,computedSliderPosition:0};let c=Math.round(Math.max(20,Math.floor(s*a/r))),d=(a-c)/(r-s),p=n*d;return{computedAvailableSize:Math.round(o),computedIsNeeded:l,computedSliderSize:Math.round(c),computedSliderRatio:d,computedSliderPosition:Math.round(p)}}_refreshComputedValues(){let t=Qr._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(t){if(!this._computedIsNeeded)return 0;let i=t-this._arrowSize-this._computedSliderSize/2;return Math.round(i/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(t){if(!this._computedIsNeeded)return 0;let i=t-this._arrowSize,s=this._scrollPosition;return i<this._computedSliderPosition?s-=this._visibleSize:s+=this._visibleSize,s}getDesiredScrollPositionFromDelta(t){if(!this._computedIsNeeded)return 0;let i=this._computedSliderPosition+t;return Math.round(i/this._computedSliderRatio)}},lf=class extends Ol{constructor(e,t,i){let s=e.getScrollDimensions(),r=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:i,scrollbarState:new Ul(t.horizontalHasArrows?t.arrowSize:0,t.horizontal===2?0:t.horizontalScrollbarSize,t.vertical===2?0:t.verticalScrollbarSize,s.width,s.scrollWidth,r.scrollLeft),visibility:t.horizontal,extraScrollbarClassName:"horizontal",scrollable:e,scrollByPage:t.scrollByPage}),t.horizontalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(Math.floor((t.horizontalScrollbarSize-t.horizontalSliderSize)/2),0,void 0,t.horizontalSliderSize)}_updateSlider(e,t){this.slider.setWidth(e),this.slider.setLeft(t)}_renderDomNode(e,t){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(e.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return e}_sliderPointerPosition(e){return e.pageX}_sliderOrthogonalPointerPosition(e){return e.pageY}_updateScrollbarSize(e){this.slider.setHeight(e)}writeScrollPosition(e,t){e.scrollLeft=t}updateOptions(e){this.updateScrollbarSize(e.horizontal===2?0:e.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._visibilityController.setVisibility(e.horizontal),this._scrollByPage=e.scrollByPage}},hf=class extends Ol{constructor(e,t,i){let s=e.getScrollDimensions(),r=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:i,scrollbarState:new Ul(t.verticalHasArrows?t.arrowSize:0,t.vertical===2?0:t.verticalScrollbarSize,0,s.height,s.scrollHeight,r.scrollTop),visibility:t.vertical,extraScrollbarClassName:"vertical",scrollable:e,scrollByPage:t.scrollByPage}),t.verticalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(0,Math.floor((t.verticalScrollbarSize-t.verticalSliderSize)/2),t.verticalSliderSize,void 0)}_updateSlider(e,t){this.slider.setHeight(e),this.slider.setTop(t)}_renderDomNode(e,t){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(e.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return t}_sliderPointerPosition(e){return e.pageY}_sliderOrthogonalPointerPosition(e){return e.pageX}_updateScrollbarSize(e){this.slider.setWidth(e)}writeScrollPosition(e,t){e.scrollTop=t}updateOptions(e){this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},cf=500,jo=50,df=class{constructor(e,t,i){this.timestamp=e,this.deltaX=t,this.deltaY=i,this.score=0}},Zr=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let t=1,i=0,s=1,r=this._rear;do{let n=r===this._front?t:Math.pow(2,-s);if(t-=n,i+=this._memory[r].score*n,r===this._front)break;r=(this._capacity+r-1)%this._capacity,s++}while(!0);return i<=.5}acceptStandardWheelEvent(t){if(Rn){let i=St(t.browserEvent),s=y_(i);this.accept(Date.now(),t.deltaX*s,t.deltaY*s)}else this.accept(Date.now(),t.deltaX,t.deltaY)}accept(t,i,s){let r=null,n=new df(t,i,s);this._front===-1&&this._rear===-1?(this._memory[0]=n,this._front=0,this._rear=0):(r=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=n),n.score=this._computeScore(n,r)}_computeScore(t,i){if(Math.abs(t.deltaX)>0&&Math.abs(t.deltaY)>0)return 1;let s=.5;if((!this._isAlmostInt(t.deltaX)||!this._isAlmostInt(t.deltaY))&&(s+=.25),i){let r=Math.abs(t.deltaX),n=Math.abs(t.deltaY),o=Math.abs(i.deltaX),a=Math.abs(i.deltaY),l=Math.max(Math.min(r,o),1),c=Math.max(Math.min(n,a),1),d=Math.max(r,o),p=Math.max(n,a);d%l===0&&p%c===0&&(s-=.5)}return Math.min(Math.max(s,0),1)}_isAlmostInt(t){return Math.abs(Math.round(t)-t)<.01}};Zr.INSTANCE=new Zr;var uf=Zr,_f=class extends On{constructor(e,t,i){super(),this._onScroll=this._register(new k),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new k),this.onWillScroll=this._onWillScroll.event,this._options=pf(t),this._scrollable=i,this._register(this._scrollable.onScroll(r=>{this._onWillScroll.fire(r),this._onDidScroll(r),this._onScroll.fire(r)}));let s={onMouseWheel:r=>this._onMouseWheel(r),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new hf(this._scrollable,this._options,s)),this._horizontalScrollbar=this._register(new lf(this._scrollable,this._options,s)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=Ui(document.createElement("div")),this._leftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=Ui(document.createElement("div")),this._topShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=Ui(document.createElement("div")),this._topLeftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,r=>this._onMouseOver(r)),this.onmouseleave(this._listenOnDomNode,r=>this._onMouseLeave(r)),this._hideTimeout=this._register(new Nn),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=ei(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(e){this._verticalScrollbar.delegatePointerDown(e)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}updateClassName(e){this._options.className=e,bt&&(this._options.className+=" mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(e){typeof e.handleMouseWheel<"u"&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<"u"&&(this._options.horizontal=e.horizontal),typeof e.vertical<"u"&&(this._options.vertical=e.vertical),typeof e.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<"u"&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(e){this._revealOnScroll=e}delegateScrollFromMouseWheelEvent(e){this._onMouseWheel(new Ro(e))}_setListeningToMouseWheel(e){if(this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=ei(this._mouseWheelToDispose),e)){let t=i=>{this._onMouseWheel(new Ro(i))};this._mouseWheelToDispose.push(K(this._listenOnDomNode,Ae.MOUSE_WHEEL,t,{passive:!1}))}}_onMouseWheel(e){if(e.browserEvent?.defaultPrevented)return;let t=uf.INSTANCE;t.acceptStandardWheelEvent(e);let i=!1;if(e.deltaY||e.deltaX){let r=e.deltaY*this._options.mouseWheelScrollSensitivity,n=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&n+r===0?n=r=0:Math.abs(r)>=Math.abs(n)?n=0:r=0),this._options.flipAxes&&([r,n]=[n,r]);let o=!bt&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||o)&&!n&&(n=r,r=0),e.browserEvent&&e.browserEvent.altKey&&(n=n*this._options.fastScrollSensitivity,r=r*this._options.fastScrollSensitivity);let a=this._scrollable.getFutureScrollPosition(),l={};if(r){let c=jo*r,d=a.scrollTop-(c<0?Math.floor(c):Math.ceil(c));this._verticalScrollbar.writeScrollPosition(l,d)}if(n){let c=jo*n,d=a.scrollLeft-(c<0?Math.floor(c):Math.ceil(c));this._horizontalScrollbar.writeScrollPosition(l,d)}l=this._scrollable.validateScrollPosition(l),(a.scrollLeft!==l.scrollLeft||a.scrollTop!==l.scrollTop)&&(this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(l):this._scrollable.setScrollPositionNow(l),i=!0)}let s=i;!s&&this._options.alwaysConsumeMouseWheel&&(s=!0),!s&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(s=!0),s&&(e.preventDefault(),e.stopPropagation())}_onDidScroll(e){this._shouldRender=this._horizontalScrollbar.onDidScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,i=e.scrollLeft>0,s=i?" left":"",r=t?" top":"",n=i||t?" top-left-corner":"";this._leftShadowDomNode.setClassName(`shadow${s}`),this._topShadowDomNode.setClassName(`shadow${r}`),this._topLeftShadowDomNode.setClassName(`shadow${n}${r}${s}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(e){this._mouseIsOver=!1,this._hide()}_onMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),cf)}},ff=class extends _f{constructor(e,t,i){super(e,t,i)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function pf(e){let t={lazyRender:typeof e.lazyRender<"u"?e.lazyRender:!1,className:typeof e.className<"u"?e.className:"",useShadows:typeof e.useShadows<"u"?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<"u"?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<"u"?e.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<"u"?e.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<"u"?e.alwaysConsumeMouseWheel:!1,scrollYToX:typeof e.scrollYToX<"u"?e.scrollYToX:!1,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<"u"?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<"u"?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<"u"?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<"u"?e.mouseWheelSmoothScroll:!0,arrowSize:typeof e.arrowSize<"u"?e.arrowSize:11,listenOnDomNode:typeof e.listenOnDomNode<"u"?e.listenOnDomNode:null,horizontal:typeof e.horizontal<"u"?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<"u"?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<"u"?e.horizontalHasArrows:!1,vertical:typeof e.vertical<"u"?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<"u"?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<"u"?e.verticalHasArrows:!1,verticalSliderSize:typeof e.verticalSliderSize<"u"?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<"u"?e.scrollByPage:!1};return t.horizontalSliderSize=typeof e.horizontalSliderSize<"u"?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<"u"?e.verticalSliderSize:t.verticalScrollbarSize,bt&&(t.className+=" mac"),t}var Jr=class extends W{constructor(e,t,i,s,r,n,o,a){super(),this._bufferService=i,this._optionsService=o,this._renderService=a,this._onRequestScrollLines=this._register(new k),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let l=this._register(new tf({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:c=>Bn(s.window,c)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{l.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new ff(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},l)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","overviewRuler"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(r.onProtocolChange(c=>{this._scrollableElement.updateOptions({handleMouseWheel:!(c&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(Be.runAndSubscribe(n.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=n.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(ne(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=s.mainDocument.createElement("style"),t.appendChild(this._styleElement),this._register(ne(()=>this._styleElement.remove())),this._register(Be.runAndSubscribe(n.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .scrollbar > .slider {",`  background: ${n.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider:hover {",`  background: ${n.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider.active {",`  background: ${n.colors.scrollbarSliderActiveBackground.css};`,"}"].join(`
`)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(c=>this._handleScroll(c)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:this._optionsService.rawOptions.overviewRuler?.width||14}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),i=t-this._bufferService.buffer.ydisp;i!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(i)),this._isHandlingScroll=!1}};Jr=ce([L(2,Ge),L(3,Mt),L(4,vl),L(5,pi),L(6,We),L(7,Dt)],Jr);var en=class extends W{constructor(e,t,i,s,r){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=i,this._decorationService=s,this._renderService=r,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(n=>this._removeDecoration(n))),this._register(ne(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement("div");t.classList.add("xterm-decoration"),t.classList.toggle("xterm-decoration-top-layer",e?.options?.layer==="top"),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let i=e.options.x??0;return i&&i>this._bufferService.cols&&(t.style.display="none"),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display="none",e.onRenderEmitter.fire(e.element));else{let i=this._decorationElements.get(e);i||(i=this._createElement(e),e.element=i,this._decorationElements.set(e,i),this._container.appendChild(i),e.onDispose(()=>{this._decorationElements.delete(e),i.remove()})),i.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(i.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,i.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,i.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,i.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(i)}}_refreshXPosition(e,t=e.element){if(!t)return;let i=e.options.x??0;(e.options.anchor||"left")==="right"?t.style.right=i?`${i*this._renderService.dimensions.css.cell.width}px`:"":t.style.left=i?`${i*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};en=ce([L(1,Ge),L(2,Mt),L(3,Qi),L(4,Dt)],en);var mf=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,i){return t>=e.startBufferLine-this._linePadding[i||"full"]&&t<=e.endBufferLine+this._linePadding[i||"full"]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},mt={full:0,left:0,center:0,right:0},Bt={full:0,left:0,center:0,right:0},xi={full:0,left:0,center:0,right:0},ws=class extends W{constructor(e,t,i,s,r,n,o,a){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=i,this._decorationService=s,this._renderService=r,this._optionsService=n,this._themeService=o,this._coreBrowserService=a,this._colorZoneStore=new mf,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(ne(()=>this._canvas?.remove()));let l=this._canvas.getContext("2d");if(l)this._ctx=l;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("overviewRuler",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){return this._optionsService.options.overviewRuler?.width||0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);Bt.full=this._canvas.width,Bt.left=e,Bt.center=t,Bt.right=e,this._refreshDrawHeightConstants(),xi.full=1,xi.left=1,xi.center=1+Bt.left,xi.right=1+Bt.left+Bt.center}_refreshDrawHeightConstants(){mt.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);mt.left=t,mt.center=t,mt.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*mt.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*mt.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*mt.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*mt.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let t of this._decorationService.decorations)this._colorZoneStore.addDecoration(t);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!=="full"&&this._renderColorZone(t);for(let t of e)t.position==="full"&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(xi[e.position||"full"],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-mt[e.position||"full"]/2),Bt[e.position||"full"],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+mt[e.position||"full"]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};ws=ce([L(2,Ge),L(3,Qi),L(4,Dt),L(5,We),L(6,pi),L(7,Mt)],ws);var x;(e=>(e.NUL="\0",e.SOH="",e.STX="",e.ETX="",e.EOT="",e.ENQ="",e.ACK="",e.BEL="\x07",e.BS="\b",e.HT="	",e.LF=`
`,e.VT="\v",e.FF="\f",e.CR="\r",e.SO="",e.SI="",e.DLE="",e.DC1="",e.DC2="",e.DC3="",e.DC4="",e.NAK="",e.SYN="",e.ETB="",e.CAN="",e.EM="",e.SUB="",e.ESC="\x1B",e.FS="",e.GS="",e.RS="",e.US="",e.SP=" ",e.DEL=""))(x||={});var gs;(e=>(e.PAD="€",e.HOP="",e.BPH="‚",e.NBH="ƒ",e.IND="„",e.NEL="…",e.SSA="†",e.ESA="‡",e.HTS="ˆ",e.HTJ="‰",e.VTS="Š",e.PLD="‹",e.PLU="Œ",e.RI="",e.SS2="Ž",e.SS3="",e.DCS="",e.PU1="‘",e.PU2="’",e.STS="“",e.CCH="”",e.MW="•",e.SPA="–",e.EPA="—",e.SOS="˜",e.SGCI="™",e.SCI="š",e.CSI="›",e.ST="œ",e.OSC="",e.PM="ž",e.APC="Ÿ"))(gs||={});var Fl;(e=>e.ST=`${x.ESC}\\`)(Fl||={});var tn=class{constructor(e,t,i,s,r,n){this._textarea=e,this._compositionView=t,this._bufferService=i,this._optionsService=s,this._coreService=r,this._renderService=n,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(e){if(this._compositionView.classList.remove("active"),this._isComposing=!1,e){let t={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let i;t.start+=this._dataAlreadySent.length,this._isComposing?i=this._textarea.value.substring(t.start,this._compositionPosition.start):i=this._textarea.value.substring(t.start),i.length>0&&this._coreService.triggerDataEvent(i,!0)}},0)}else{this._isSendingComposition=!1;let t=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(t,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let t=this._textarea.value,i=t.replace(e,"");this._dataAlreadySent=i,t.length>e.length?this._coreService.triggerDataEvent(i,!0):t.length<e.length?this._coreService.triggerDataEvent(`${x.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}},0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let t=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),i=this._renderService.dimensions.css.cell.height,s=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,r=t*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=r+"px",this._compositionView.style.top=s+"px",this._compositionView.style.height=i+"px",this._compositionView.style.lineHeight=i+"px",this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+"px";let n=this._compositionView.getBoundingClientRect();this._textarea.style.left=r+"px",this._textarea.style.top=s+"px",this._textarea.style.width=Math.max(n.width,1)+"px",this._textarea.style.height=Math.max(n.height,1)+"px",this._textarea.style.lineHeight=n.height+"px"}e||setTimeout(()=>this.updateCompositionElements(!0),0)}}};tn=ce([L(2,Ge),L(3,We),L(4,ri),L(5,Dt)],tn);var Pe=0,ke=0,Me=0,he=0,Ko={css:"#00000000",rgba:0},_e;(e=>{function t(r,n,o,a){return a!==void 0?`#${$t(r)}${$t(n)}${$t(o)}${$t(a)}`:`#${$t(r)}${$t(n)}${$t(o)}`}e.toCss=t;function i(r,n,o,a=255){return(r<<24|n<<16|o<<8|a)>>>0}e.toRgba=i;function s(r,n,o,a){return{css:e.toCss(r,n,o,a),rgba:e.toRgba(r,n,o,a)}}e.toColor=s})(_e||={});var re;(e=>{function t(l,c){if(he=(c.rgba&255)/255,he===1)return{css:c.css,rgba:c.rgba};let d=c.rgba>>24&255,p=c.rgba>>16&255,f=c.rgba>>8&255,g=l.rgba>>24&255,u=l.rgba>>16&255,_=l.rgba>>8&255;Pe=g+Math.round((d-g)*he),ke=u+Math.round((p-u)*he),Me=_+Math.round((f-_)*he);let S=_e.toCss(Pe,ke,Me),v=_e.toRgba(Pe,ke,Me);return{css:S,rgba:v}}e.blend=t;function i(l){return(l.rgba&255)===255}e.isOpaque=i;function s(l,c,d){let p=vs.ensureContrastRatio(l.rgba,c.rgba,d);if(p)return _e.toColor(p>>24&255,p>>16&255,p>>8&255)}e.ensureContrastRatio=s;function r(l){let c=(l.rgba|255)>>>0;return[Pe,ke,Me]=vs.toChannels(c),{css:_e.toCss(Pe,ke,Me),rgba:c}}e.opaque=r;function n(l,c){return he=Math.round(c*255),[Pe,ke,Me]=vs.toChannels(l.rgba),{css:_e.toCss(Pe,ke,Me,he),rgba:_e.toRgba(Pe,ke,Me,he)}}e.opacity=n;function o(l,c){return he=l.rgba&255,n(l,he*c/255)}e.multiplyOpacity=o;function a(l){return[l.rgba>>24&255,l.rgba>>16&255,l.rgba>>8&255]}e.toColorRGB=a})(re||={});var ae;(e=>{let t,i;try{let r=document.createElement("canvas");r.width=1,r.height=1;let n=r.getContext("2d",{willReadFrequently:!0});n&&(t=n,t.globalCompositeOperation="copy",i=t.createLinearGradient(0,0,1,1))}catch{}function s(r){if(r.match(/#[\da-f]{3,8}/i))switch(r.length){case 4:return Pe=parseInt(r.slice(1,2).repeat(2),16),ke=parseInt(r.slice(2,3).repeat(2),16),Me=parseInt(r.slice(3,4).repeat(2),16),_e.toColor(Pe,ke,Me);case 5:return Pe=parseInt(r.slice(1,2).repeat(2),16),ke=parseInt(r.slice(2,3).repeat(2),16),Me=parseInt(r.slice(3,4).repeat(2),16),he=parseInt(r.slice(4,5).repeat(2),16),_e.toColor(Pe,ke,Me,he);case 7:return{css:r,rgba:(parseInt(r.slice(1),16)<<8|255)>>>0};case 9:return{css:r,rgba:parseInt(r.slice(1),16)>>>0}}let n=r.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(n)return Pe=parseInt(n[1]),ke=parseInt(n[2]),Me=parseInt(n[3]),he=Math.round((n[5]===void 0?1:parseFloat(n[5]))*255),_e.toColor(Pe,ke,Me,he);if(!t||!i)throw new Error("css.toColor: Unsupported css format");if(t.fillStyle=i,t.fillStyle=r,typeof t.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(t.fillRect(0,0,1,1),[Pe,ke,Me,he]=t.getImageData(0,0,1,1).data,he!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:_e.toRgba(Pe,ke,Me,he),css:r}}e.toColor=s})(ae||={});var ze;(e=>{function t(s){return i(s>>16&255,s>>8&255,s&255)}e.relativeLuminance=t;function i(s,r,n){let o=s/255,a=r/255,l=n/255,c=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),d=a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4),p=l<=.03928?l/12.92:Math.pow((l+.055)/1.055,2.4);return c*.2126+d*.7152+p*.0722}e.relativeLuminance2=i})(ze||={});var vs;(e=>{function t(o,a){if(he=(a&255)/255,he===1)return a;let l=a>>24&255,c=a>>16&255,d=a>>8&255,p=o>>24&255,f=o>>16&255,g=o>>8&255;return Pe=p+Math.round((l-p)*he),ke=f+Math.round((c-f)*he),Me=g+Math.round((d-g)*he),_e.toRgba(Pe,ke,Me)}e.blend=t;function i(o,a,l){let c=ze.relativeLuminance(o>>8),d=ze.relativeLuminance(a>>8);if(Et(c,d)<l){if(d<c){let g=s(o,a,l),u=Et(c,ze.relativeLuminance(g>>8));if(u<l){let _=r(o,a,l),S=Et(c,ze.relativeLuminance(_>>8));return u>S?g:_}return g}let p=r(o,a,l),f=Et(c,ze.relativeLuminance(p>>8));if(f<l){let g=s(o,a,l),u=Et(c,ze.relativeLuminance(g>>8));return f>u?p:g}return p}}e.ensureContrastRatio=i;function s(o,a,l){let c=o>>24&255,d=o>>16&255,p=o>>8&255,f=a>>24&255,g=a>>16&255,u=a>>8&255,_=Et(ze.relativeLuminance2(f,g,u),ze.relativeLuminance2(c,d,p));for(;_<l&&(f>0||g>0||u>0);)f-=Math.max(0,Math.ceil(f*.1)),g-=Math.max(0,Math.ceil(g*.1)),u-=Math.max(0,Math.ceil(u*.1)),_=Et(ze.relativeLuminance2(f,g,u),ze.relativeLuminance2(c,d,p));return(f<<24|g<<16|u<<8|255)>>>0}e.reduceLuminance=s;function r(o,a,l){let c=o>>24&255,d=o>>16&255,p=o>>8&255,f=a>>24&255,g=a>>16&255,u=a>>8&255,_=Et(ze.relativeLuminance2(f,g,u),ze.relativeLuminance2(c,d,p));for(;_<l&&(f<255||g<255||u<255);)f=Math.min(255,f+Math.ceil((255-f)*.1)),g=Math.min(255,g+Math.ceil((255-g)*.1)),u=Math.min(255,u+Math.ceil((255-u)*.1)),_=Et(ze.relativeLuminance2(f,g,u),ze.relativeLuminance2(c,d,p));return(f<<24|g<<16|u<<8|255)>>>0}e.increaseLuminance=r;function n(o){return[o>>24&255,o>>16&255,o>>8&255,o&255]}e.toChannels=n})(vs||={});function $t(e){let t=e.toString(16);return t.length<2?"0"+t:t}function Et(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}var gf=class extends Xi{constructor(e,t,i){super(),this.content=0,this.combinedData="",this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=i}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Es=class{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new ct}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let i=[],s=t.translateToString(!0),r=0,n=0,o=0,a=t.getFg(0),l=t.getBg(0);for(let c=0;c<t.getTrimmedLength();c++)if(t.loadCell(c,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==a||this._workCell.bg!==l){if(c-r>1){let d=this._getJoinedRanges(s,o,n,t,r);for(let p=0;p<d.length;p++)i.push(d[p])}r=c,o=n,a=this._workCell.fg,l=this._workCell.bg}n+=this._workCell.getChars().length||jt.length}if(this._bufferService.cols-r>1){let c=this._getJoinedRanges(s,o,n,t,r);for(let d=0;d<c.length;d++)i.push(c[d])}return i}_getJoinedRanges(e,t,i,s,r){let n=e.substring(t,i),o=[];try{o=this._characterJoiners[0].handler(n)}catch(a){console.error(a)}for(let a=1;a<this._characterJoiners.length;a++)try{let l=this._characterJoiners[a].handler(n);for(let c=0;c<l.length;c++)Es._mergeRanges(o,l[c])}catch(l){console.error(l)}return this._stringRangesToCellRanges(o,s,r),o}_stringRangesToCellRanges(e,t,i){let s=0,r=!1,n=0,o=e[s];if(o){for(let a=i;a<this._bufferService.cols;a++){let l=t.getWidth(a),c=t.getString(a).length||jt.length;if(l!==0){if(!r&&o[0]<=n&&(o[0]=a,r=!0),o[1]<=n){if(o[1]=a,o=e[++s],!o)break;o[0]<=n?(o[0]=a,r=!0):r=!1}n+=c}}o&&(o[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let i=!1;for(let s=0;s<e.length;s++){let r=e[s];if(i){if(t[1]<=r[0])return e[s-1][1]=t[1],e;if(t[1]<=r[1])return e[s-1][1]=Math.max(t[1],r[1]),e.splice(s,1),e;e.splice(s,1),s--}else{if(t[1]<=r[0])return e.splice(s,0,t),e;if(t[1]<=r[1])return r[0]=Math.min(t[0],r[0]),e;t[0]<r[1]&&(r[0]=Math.min(t[0],r[0]),i=!0);continue}}return i?e[e.length-1][1]=t[1]:e.push(t),e}};Es=ce([L(0,Ge)],Es);function vf(e){return 57508<=e&&e<=57558}function Sf(e){return 9472<=e&&e<=9631}function bf(e){return vf(e)||Sf(e)}function yf(){return{css:{canvas:ns(),cell:ns()},device:{canvas:ns(),cell:ns(),char:{width:0,height:0,left:0,top:0}}}}function ns(){return{width:0,height:0}}var sn=class{constructor(e,t,i,s,r,n,o){this._document=e,this._characterJoinerService=t,this._optionsService=i,this._coreBrowserService=s,this._coreService=r,this._decorationService=n,this._themeService=o,this._workCell=new ct,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,i){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=i}createRow(e,t,i,s,r,n,o,a,l,c,d){let p=[],f=this._characterJoinerService.getJoinedCharacters(t),g=this._themeService.colors,u=e.getNoBgTrimmedLength();i&&u<n+1&&(u=n+1);let _,S=0,v="",P=0,w=0,E=0,D=0,N=!1,U=0,X=!1,ie=0,Oe=0,V=[],R=c!==-1&&d!==-1;for(let I=0;I<u;I++){e.loadCell(I,this._workCell);let M=this._workCell.getWidth();if(M===0)continue;let T=!1,F=I>=Oe,Y=I,B=this._workCell;if(f.length>0&&I===f[0][0]&&F){let Q=f.shift(),dr=this._isCellInSelection(Q[0],t);for(P=Q[0]+1;P<Q[1];P++)F&&=dr===this._isCellInSelection(P,t);F&&=!i||n<Q[0]||n>=Q[1],F?(T=!0,B=new gf(this._workCell,e.translateToString(!0,Q[0],Q[1]),Q[1]-Q[0]),Y=Q[1]-1,M=B.getWidth()):Oe=Q[1]}let H=this._isCellInSelection(I,t),se=i&&I===n,we=R&&I>=c&&I<=d,Ve=!1;this._decorationService.forEachDecorationAtCell(I,t,void 0,Q=>{Ve=!0});let tt=B.getChars()||jt;if(tt===" "&&(B.isUnderline()||B.isOverline())&&(tt=" "),ie=M*a-l.get(tt,B.isBold(),B.isItalic()),!_)_=this._document.createElement("span");else if(S&&(H&&X||!H&&!X&&B.bg===w)&&(H&&X&&g.selectionForeground||B.fg===E)&&B.extended.ext===D&&we===N&&ie===U&&!se&&!T&&!Ve&&F){B.isInvisible()?v+=jt:v+=tt,S++;continue}else S&&(_.textContent=v),_=this._document.createElement("span"),S=0,v="";if(w=B.bg,E=B.fg,D=B.extended.ext,N=we,U=ie,X=H,T&&n>=I&&n<=Y&&(n=I),!this._coreService.isCursorHidden&&se&&this._coreService.isCursorInitialized){if(V.push("xterm-cursor"),this._coreBrowserService.isFocused)o&&V.push("xterm-cursor-blink"),V.push(s==="bar"?"xterm-cursor-bar":s==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(r)switch(r){case"outline":V.push("xterm-cursor-outline");break;case"block":V.push("xterm-cursor-block");break;case"bar":V.push("xterm-cursor-bar");break;case"underline":V.push("xterm-cursor-underline");break}}if(B.isBold()&&V.push("xterm-bold"),B.isItalic()&&V.push("xterm-italic"),B.isDim()&&V.push("xterm-dim"),B.isInvisible()?v=jt:v=B.getChars()||jt,B.isUnderline()&&(V.push(`xterm-underline-${B.extended.underlineStyle}`),v===" "&&(v=" "),!B.isUnderlineColorDefault()))if(B.isUnderlineColorRGB())_.style.textDecorationColor=`rgb(${Xi.toColorRGB(B.getUnderlineColor()).join(",")})`;else{let Q=B.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&B.isBold()&&Q<8&&(Q+=8),_.style.textDecorationColor=g.ansi[Q].css}B.isOverline()&&(V.push("xterm-overline"),v===" "&&(v=" ")),B.isStrikethrough()&&V.push("xterm-strikethrough"),we&&(_.style.textDecoration="underline");let Ue=B.getFgColor(),Ee=B.getFgColorMode(),xe=B.getBgColor(),te=B.getBgColorMode(),Ci=!!B.isInverse();if(Ci){let Q=Ue;Ue=xe,xe=Q;let dr=Ee;Ee=te,te=dr}let Rt,is,wi=!1;this._decorationService.forEachDecorationAtCell(I,t,void 0,Q=>{Q.options.layer!=="top"&&wi||(Q.backgroundColorRGB&&(te=50331648,xe=Q.backgroundColorRGB.rgba>>8&16777215,Rt=Q.backgroundColorRGB),Q.foregroundColorRGB&&(Ee=50331648,Ue=Q.foregroundColorRGB.rgba>>8&16777215,is=Q.foregroundColorRGB),wi=Q.options.layer==="top")}),!wi&&H&&(Rt=this._coreBrowserService.isFocused?g.selectionBackgroundOpaque:g.selectionInactiveBackgroundOpaque,xe=Rt.rgba>>8&16777215,te=50331648,wi=!0,g.selectionForeground&&(Ee=50331648,Ue=g.selectionForeground.rgba>>8&16777215,is=g.selectionForeground)),wi&&V.push("xterm-decoration-top");let Lt;switch(te){case 16777216:case 33554432:Lt=g.ansi[xe],V.push(`xterm-bg-${xe}`);break;case 50331648:Lt=_e.toColor(xe>>16,xe>>8&255,xe&255),this._addStyle(_,`background-color:#${zo((xe>>>0).toString(16),"0",6)}`);break;default:Ci?(Lt=g.foreground,V.push("xterm-bg-257")):Lt=g.background}switch(Rt||B.isDim()&&(Rt=re.multiplyOpacity(Lt,.5)),Ee){case 16777216:case 33554432:B.isBold()&&Ue<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(Ue+=8),this._applyMinimumContrast(_,Lt,g.ansi[Ue],B,Rt,void 0)||V.push(`xterm-fg-${Ue}`);break;case 50331648:let Q=_e.toColor(Ue>>16&255,Ue>>8&255,Ue&255);this._applyMinimumContrast(_,Lt,Q,B,Rt,is)||this._addStyle(_,`color:#${zo(Ue.toString(16),"0",6)}`);break;default:this._applyMinimumContrast(_,Lt,g.foreground,B,Rt,is)||Ci&&V.push("xterm-fg-257")}V.length&&(_.className=V.join(" "),V.length=0),!se&&!T&&!Ve&&F?S++:_.textContent=v,ie!==this.defaultSpacing&&(_.style.letterSpacing=`${ie}px`),p.push(_),I=Y}return _&&S&&(_.textContent=v),p}_applyMinimumContrast(e,t,i,s,r,n){if(this._optionsService.rawOptions.minimumContrastRatio===1||bf(s.getCode()))return!1;let o=this._getContrastCache(s),a;if(!r&&!n&&(a=o.getColor(t.rgba,i.rgba)),a===void 0){let l=this._optionsService.rawOptions.minimumContrastRatio/(s.isDim()?2:1);a=re.ensureContrastRatio(r||t,n||i,l),o.setColor((r||t).rgba,(n||i).rgba,a??null)}return a?(this._addStyle(e,`color:${a.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute("style",`${e.getAttribute("style")||""}${t};`)}_isCellInSelection(e,t){let i=this._selectionStart,s=this._selectionEnd;return!i||!s?!1:this._columnSelectMode?i[0]<=s[0]?e>=i[0]&&t>=i[1]&&e<s[0]&&t<=s[1]:e<i[0]&&t>=i[1]&&e>=s[0]&&t<=s[1]:t>i[1]&&t<s[1]||i[1]===s[1]&&t===i[1]&&e>=i[0]&&e<s[0]||i[1]<s[1]&&t===s[1]&&e<s[0]||i[1]<s[1]&&t===i[1]&&e>=i[0]}};sn=ce([L(1,yl),L(2,We),L(3,Mt),L(4,ri),L(5,Qi),L(6,pi)],sn);function zo(e,t,i){for(;e.length<i;)e=t+e;return e}var Cf=class{constructor(e,t){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._measureElements=[],this._container=e.createElement("div"),this._container.classList.add("xterm-width-cache-measure-container"),this._container.setAttribute("aria-hidden","true"),this._container.style.whiteSpace="pre",this._container.style.fontKerning="none";let i=e.createElement("span");i.classList.add("xterm-char-measure-element");let s=e.createElement("span");s.classList.add("xterm-char-measure-element"),s.style.fontWeight="bold";let r=e.createElement("span");r.classList.add("xterm-char-measure-element"),r.style.fontStyle="italic";let n=e.createElement("span");n.classList.add("xterm-char-measure-element"),n.style.fontWeight="bold",n.style.fontStyle="italic",this._measureElements=[i,s,r,n],this._container.appendChild(i),this._container.appendChild(s),this._container.appendChild(r),this._container.appendChild(n),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,i,s){e===this._font&&t===this._fontSize&&i===this._weight&&s===this._weightBold||(this._font=e,this._fontSize=t,this._weight=i,this._weightBold=s,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${i}`,this._measureElements[1].style.fontWeight=`${s}`,this._measureElements[2].style.fontWeight=`${i}`,this._measureElements[3].style.fontWeight=`${s}`,this.clear())}get(e,t,i){let s=0;if(!t&&!i&&e.length===1&&(s=e.charCodeAt(0))<256){if(this._flat[s]!==-9999)return this._flat[s];let o=this._measure(e,0);return o>0&&(this._flat[s]=o),o}let r=e;t&&(r+="B"),i&&(r+="I");let n=this._holey.get(r);if(n===void 0){let o=0;t&&(o|=1),i&&(o|=2),n=this._measure(e,o),n>0&&this._holey.set(r,n)}return n}_measure(e,t){let i=this._measureElements[t];return i.textContent=e.repeat(32),i.offsetWidth/32}},wf=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,i,s=!1){if(this.selectionStart=t,this.selectionEnd=i,!t||!i||t[0]===i[0]&&t[1]===i[1]){this.clear();return}let r=e.buffers.active.ydisp,n=t[1]-r,o=i[1]-r,a=Math.max(n,0),l=Math.min(o,e.rows-1);if(a>=e.rows||l<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=s,this.viewportStartRow=n,this.viewportEndRow=o,this.viewportCappedStartRow=a,this.viewportCappedEndRow=l,this.startCol=t[0],this.endCol=i[0]}isCellSelected(e,t,i){return this.hasSelection?(i-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&i>=this.viewportCappedStartRow&&t<this.endCol&&i<=this.viewportCappedEndRow:t<this.startCol&&i>=this.viewportCappedStartRow&&t>=this.endCol&&i<=this.viewportCappedEndRow:i>this.viewportStartRow&&i<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&i===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&i===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&i===this.viewportStartRow&&t>=this.startCol):!1}};function Ef(){return new wf}var Sr="xterm-dom-renderer-owner-",it="xterm-rows",os="xterm-fg-",Yo="xterm-bg-",Ii="xterm-focus",as="xterm-selection",xf=1,rn=class extends W{constructor(e,t,i,s,r,n,o,a,l,c,d,p,f,g){super(),this._terminal=e,this._document=t,this._element=i,this._screenElement=s,this._viewportElement=r,this._helperContainer=n,this._linkifier2=o,this._charSizeService=l,this._optionsService=c,this._bufferService=d,this._coreService=p,this._coreBrowserService=f,this._themeService=g,this._terminalClass=xf++,this._rowElements=[],this._selectionRenderModel=Ef(),this.onRequestRedraw=this._register(new k).event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add(it),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add(as),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=yf(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(u=>this._injectCss(u))),this._injectCss(this._themeService.colors),this._rowFactory=a.createInstance(sn,document),this._element.classList.add(Sr+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(u=>this._handleLinkHover(u))),this._register(this._linkifier2.onHideLinkUnderline(u=>this._handleLinkLeave(u))),this._register(ne(()=>{this._element.classList.remove(Sr+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new Cf(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let i of this._rowElements)i.style.width=`${this.dimensions.css.canvas.width}px`,i.style.height=`${this.dimensions.css.cell.height}px`,i.style.lineHeight=`${this.dimensions.css.cell.height}px`,i.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${it} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${it} { pointer-events: none; color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${it} .xterm-dim { color: ${re.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let i=`blink_underline_${this._terminalClass}`,s=`blink_bar_${this._terminalClass}`,r=`blink_block_${this._terminalClass}`;t+=`@keyframes ${i} { 50% {  border-bottom-style: hidden; }}`,t+=`@keyframes ${s} { 50% {  box-shadow: none; }}`,t+=`@keyframes ${r} { 0% {  background-color: ${e.cursor.css};  color: ${e.cursorAccent.css}; } 50% {  background-color: inherit;  color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${it}.${Ii} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${it}.${Ii} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .${it}.${Ii} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .${it} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${it} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${it} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${it} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${it} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${as} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${as} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${as} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,o]of e.ansi.entries())t+=`${this._terminalSelector} .${os}${n} { color: ${o.css}; }${this._terminalSelector} .${os}${n}.xterm-dim { color: ${re.multiplyOpacity(o,.5).css}; }${this._terminalSelector} .${Yo}${n} { background-color: ${o.css}; }`;t+=`${this._terminalSelector} .${os}257 { color: ${re.opaque(e.background).css}; }${this._terminalSelector} .${os}257.xterm-dim { color: ${re.multiplyOpacity(re.opaque(e.background),.5).css}; }${this._terminalSelector} .${Yo}257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let i=this._rowElements.length;i<=t;i++){let s=this._document.createElement("div");this._rowContainer.appendChild(s),this._rowElements.push(s)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(Ii),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(Ii),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,i){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,i),this.renderRows(0,this._bufferService.rows-1),!e||!t||(this._selectionRenderModel.update(this._terminal,e,t,i),!this._selectionRenderModel.hasSelection))return;let s=this._selectionRenderModel.viewportStartRow,r=this._selectionRenderModel.viewportEndRow,n=this._selectionRenderModel.viewportCappedStartRow,o=this._selectionRenderModel.viewportCappedEndRow,a=this._document.createDocumentFragment();if(i){let l=e[0]>t[0];a.appendChild(this._createSelectionElement(n,l?t[0]:e[0],l?e[0]:t[0],o-n+1))}else{let l=s===n?e[0]:0,c=n===r?t[0]:this._bufferService.cols;a.appendChild(this._createSelectionElement(n,l,c));let d=o-n-1;if(a.appendChild(this._createSelectionElement(n+1,0,this._bufferService.cols,d)),n!==o){let p=r===o?t[0]:this._bufferService.cols;a.appendChild(this._createSelectionElement(o,0,p))}}this._selectionContainer.appendChild(a)}_createSelectionElement(e,t,i,s=1){let r=this._document.createElement("div"),n=t*this.dimensions.css.cell.width,o=this.dimensions.css.cell.width*(i-t);return n+o>this.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-n),r.style.height=`${s*this.dimensions.css.cell.height}px`,r.style.top=`${e*this.dimensions.css.cell.height}px`,r.style.left=`${n}px`,r.style.width=`${o}px`,r}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let i=this._bufferService.buffer,s=i.ybase+i.y,r=Math.min(i.x,this._bufferService.cols-1),n=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,o=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,a=this._optionsService.rawOptions.cursorInactiveStyle;for(let l=e;l<=t;l++){let c=l+i.ydisp,d=this._rowElements[l],p=i.lines.get(c);if(!d||!p)break;d.replaceChildren(...this._rowFactory.createRow(p,c,c===s,o,a,r,n,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${Sr}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,i,s,r,n){i<0&&(e=0),s<0&&(t=0);let o=this._bufferService.rows-1;i=Math.max(Math.min(i,o),0),s=Math.max(Math.min(s,o),0),r=Math.min(r,this._bufferService.cols);let a=this._bufferService.buffer,l=a.ybase+a.y,c=Math.min(a.x,r-1),d=this._optionsService.rawOptions.cursorBlink,p=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let g=i;g<=s;++g){let u=g+a.ydisp,_=this._rowElements[g],S=a.lines.get(u);if(!_||!S)break;_.replaceChildren(...this._rowFactory.createRow(S,u,u===l,p,f,c,d,this.dimensions.css.cell.width,this._widthCache,n?g===i?e:0:-1,n?(g===s?t:r)-1:-1))}}};rn=ce([L(7,Mn),L(8,Vs),L(9,We),L(10,Ge),L(11,ri),L(12,Mt),L(13,pi)],rn);var nn=class extends W{constructor(e,t,i){super(),this._optionsService=i,this.width=0,this.height=0,this._onCharSizeChange=this._register(new k),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new Af(this._optionsService))}catch{this._measureStrategy=this._register(new If(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};nn=ce([L(2,We)],nn);var jl=class extends W{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},If=class extends jl{constructor(e,t,i){super(),this._document=e,this._parentElement=t,this._optionsService=i,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},Af=class extends jl{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let t=this._ctx.measureText("W");if(!("width"in t&&"fontBoundingBoxAscent"in t&&"fontBoundingBoxDescent"in t))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText("W");return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},Pf=class extends W{constructor(e,t,i){super(),this._textarea=e,this._window=t,this.mainDocument=i,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new kf(this._window)),this._onDprChange=this._register(new k),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new k),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(s=>this._screenDprMonitor.setWindow(s))),this._register(Be.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(K(this._textarea,"focus",()=>this._isFocused=!0)),this._register(K(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},kf=class extends W{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new ui),this._onDprChange=this._register(new k),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(ne(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=K(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},Mf=class extends W{constructor(){super(),this.linkProviders=[],this._register(ne(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function Un(e,t,i){let s=i.getBoundingClientRect(),r=e.getComputedStyle(i),n=parseInt(r.getPropertyValue("padding-left")),o=parseInt(r.getPropertyValue("padding-top"));return[t.clientX-s.left-n,t.clientY-s.top-o]}function Df(e,t,i,s,r,n,o,a,l){if(!n)return;let c=Un(e,t,i);if(c)return c[0]=Math.ceil((c[0]+(l?o/2:0))/o),c[1]=Math.ceil(c[1]/a),c[0]=Math.min(Math.max(c[0],1),s+(l?1:0)),c[1]=Math.min(Math.max(c[1],1),r),c}var on=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,i,s,r){return Df(window,e,t,i,s,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,r)}getMouseReportCoords(e,t){let i=Un(window,e,t);if(this._charSizeService.hasValidSize)return i[0]=Math.min(Math.max(i[0],0),this._renderService.dimensions.css.canvas.width-1),i[1]=Math.min(Math.max(i[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(i[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(i[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(i[0]),y:Math.floor(i[1])}}};on=ce([L(0,Dt),L(1,Vs)],on);var Tf=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh())),this._animationFrame}refresh(e,t,i){this._rowCount=i,e=e!==void 0?e:0,t=t!==void 0?t:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t,!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},Kl={};Ku(Kl,{getSafariVersion:()=>Lf,isChromeOS:()=>Gl,isFirefox:()=>zl,isIpad:()=>Nf,isIphone:()=>Bf,isLegacyEdge:()=>Rf,isLinux:()=>Fn,isMac:()=>xs,isNode:()=>qs,isSafari:()=>Yl,isWindows:()=>Hl});var qs=typeof process<"u"&&"title"in process,Zi=qs?"node":navigator.userAgent,Ji=qs?"node":navigator.platform,zl=Zi.includes("Firefox"),Rf=Zi.includes("Edge"),Yl=/^((?!chrome|android).)*safari/i.test(Zi);function Lf(){if(!Yl)return 0;let e=Zi.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])}var xs=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(Ji),Nf=Ji==="iPad",Bf=Ji==="iPhone",Hl=["Windows","Win16","Win32","WinCE"].includes(Ji),Fn=Ji.indexOf("Linux")>=0,Gl=/\bCrOS\b/.test(Zi),Wl=class{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&(this._cancelCallback(this._idleCallback),this._idleCallback=void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||(this._idleCallback=this._requestCallback(this._process.bind(this)))}_process(e){this._idleCallback=void 0;let t=0,i=0,s=e.timeRemaining(),r=0;for(;this._i<this._tasks.length;){if(t=performance.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,performance.now()-t),i=Math.max(t,i),r=e.timeRemaining(),i*1.5>r){s-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(s-t))}ms`),this._start();return}s=r}this.clear()}},Of=class extends Wl{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},Uf=class extends Wl{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},Is=!qs&&"requestIdleCallback"in window?Uf:Of,Ff=class{constructor(){this._queue=new Is}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}},an=class extends W{constructor(e,t,i,s,r,n,o,a,l){super(),this._rowCount=e,this._optionsService=i,this._charSizeService=s,this._coreService=r,this._coreBrowserService=a,this._renderer=this._register(new ui),this._pausedResizeTask=new Ff,this._observerDisposable=this._register(new ui),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new k),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new k),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new k),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new k),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new Tf((c,d)=>this._renderRows(c,d),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new jf(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(ne(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(o.onResize(()=>this._fullRefresh())),this._register(o.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(n.onDecorationRegistered(()=>this._fullRefresh())),this._register(n.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["customGlyphs","drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(o.cols,o.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(o.buffer.y,o.buffer.y,!0))),this._register(l.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(c=>this._registerIntersectionObserver(c,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if("IntersectionObserver"in e){let i=new e.IntersectionObserver(s=>this._handleIntersectionChange(s[s.length-1]),{threshold:0});i.observe(t),this._observerDisposable.value=ne(()=>i.disconnect())}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,i=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let s=this._syncOutputHandler.flush();s&&(e=Math.min(e,s.start),t=Math.max(t,s.end)),i||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(t=>this.refreshRows(t.start,t.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(e,t)):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,i){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=i,this._renderer.value?.handleSelectionChanged(e,t,i)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};an=ce([L(2,We),L(3,Vs),L(4,ri),L(5,Qi),L(6,Ge),L(7,Mt),L(8,pi)],an);var jf=class{constructor(e,t,i){this._coreBrowserService=e,this._coreService=t,this._onTimeout=i,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function Kf(e,t,i,s){let r=i.buffer.x,n=i.buffer.y;if(!i.buffer.hasScrollback)return Hf(r,n,e,t,i,s)+Xs(n,t,i,s)+Gf(r,n,e,t,i,s);let o;if(n===t)return o=r>e?"D":"C",Yi(Math.abs(r-e),zi(o,s));o=n>t?"D":"C";let a=Math.abs(n-t),l=Yf(n>t?e:r,i)+(a-1)*i.cols+1+zf(n>t?r:e);return Yi(l,zi(o,s))}function zf(e,t){return e-1}function Yf(e,t){return t.cols-e}function Hf(e,t,i,s,r,n){return Xs(t,s,r,n).length===0?"":Yi(Vl(e,t,e,t-ti(t,r),!1,r).length,zi("D",n))}function Xs(e,t,i,s){let r=e-ti(e,i),n=t-ti(t,i),o=Math.abs(r-n)-Wf(e,t,i);return Yi(o,zi($l(e,t),s))}function Gf(e,t,i,s,r,n){let o;Xs(t,s,r,n).length>0?o=s-ti(s,r):o=t;let a=s,l=$f(e,t,i,s,r,n);return Yi(Vl(e,o,i,a,l==="C",r).length,zi(l,n))}function Wf(e,t,i){let s=0,r=e-ti(e,i),n=t-ti(t,i);for(let o=0;o<Math.abs(r-n);o++){let a=$l(e,t)==="A"?-1:1;i.buffer.lines.get(r+a*o)?.isWrapped&&s++}return s}function ti(e,t){let i=0,s=t.buffer.lines.get(e),r=s?.isWrapped;for(;r&&e>=0&&e<t.rows;)i++,s=t.buffer.lines.get(--e),r=s?.isWrapped;return i}function $f(e,t,i,s,r,n){let o;return Xs(i,s,r,n).length>0?o=s-ti(s,r):o=t,e<i&&o<=s||e>=i&&o<s?"C":"D"}function $l(e,t){return e>t?"A":"B"}function Vl(e,t,i,s,r,n){let o=e,a=t,l="";for(;(o!==i||a!==s)&&a>=0&&a<n.buffer.lines.length;)o+=r?1:-1,r&&o>n.cols-1?(l+=n.buffer.translateBufferLineToString(a,!1,e,o),o=0,e=0,a++):!r&&o<0&&(l+=n.buffer.translateBufferLineToString(a,!1,0,e+1),o=n.cols-1,e=o,a--);return l+n.buffer.translateBufferLineToString(a,!1,e,o)}function zi(e,t){let i=t?"O":"[";return x.ESC+i+e}function Yi(e,t){e=Math.floor(e);let i="";for(let s=0;s<e;s++)i+=t;return i}var Vf=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function Ho(e,t){if(e.start.y>e.end.y)throw new Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var br=50,qf=15,Xf=50,Qf=500,Zf=" ",Jf=new RegExp(Zf,"g"),ln=class extends W{constructor(e,t,i,s,r,n,o,a,l){super(),this._element=e,this._screenElement=t,this._linkifier=i,this._bufferService=s,this._coreService=r,this._mouseService=n,this._optionsService=o,this._renderService=a,this._coreBrowserService=l,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new ct,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new k),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new k),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new k),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new k),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=c=>this._handleMouseMove(c),this._mouseUpListener=c=>this._handleMouseUp(c),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(c=>this._handleTrim(c)),this._register(this._bufferService.buffers.onBufferActivate(c=>this._handleBufferActivate(c))),this.enable(),this._model=new Vf(this._bufferService),this._activeSelectionMode=0,this._register(ne(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(c=>{c.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return"";let i=this._bufferService.buffer,s=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return"";let r=e[0]<t[0]?e[0]:t[0],n=e[0]<t[0]?t[0]:e[0];for(let o=e[1];o<=t[1];o++){let a=i.translateBufferLineToString(o,!0,r,n);s.push(a)}}else{let r=e[1]===t[1]?t[0]:void 0;s.push(i.translateBufferLineToString(e[1],!0,e[0],r));for(let n=e[1]+1;n<=t[1]-1;n++){let o=i.lines.get(n),a=i.translateBufferLineToString(n,!0);o?.isWrapped?s[s.length-1]+=a:s.push(a)}if(e[1]!==t[1]){let n=i.lines.get(t[1]),o=i.translateBufferLineToString(t[1],!0,0,t[0]);n&&n.isWrapped?s[s.length-1]+=o:s.push(o)}}return s.map(r=>r.replace(Jf," ")).join(Hl?`\r
`:`
`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),Fn&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!i||!s||!t?!1:this._areCoordsInSelection(t,i,s)}isCellInSelection(e,t){let i=this._model.finalSelectionStart,s=this._model.finalSelectionEnd;return!i||!s?!1:this._areCoordsInSelection([e,t],i,s)}_areCoordsInSelection(e,t,i){return e[1]>t[1]&&e[1]<i[1]||t[1]===i[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<i[0]||t[1]<i[1]&&e[1]===i[1]&&e[0]<i[0]||t[1]<i[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){let i=this._linkifier.currentLink?.link?.range;if(i)return this._model.selectionStart=[i.start.x-1,i.start.y-1],this._model.selectionStartLength=Ho(i,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let s=this._getMouseBufferCoords(e);return s?(this._selectWordAt(s,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=Un(this._coreBrowserService.window,e,this._screenElement)[1],i=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=i?0:(t>i&&(t-=i),t=Math.min(Math.max(t,-br),br),t/=br,t/Math.abs(t)+Math.round(t*(qf-1)))}shouldForceSelection(e){return xs?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),Xf)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(xs&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let i=this._bufferService.buffer;if(this._model.selectionEnd[1]<i.lines.length){let s=i.lines.get(this._model.selectionEnd[1]);s&&s.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!t||t[0]!==this._model.selectionEnd[0]||t[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(!(!this._model.selectionEnd||!this._model.selectionStart)&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<Qf&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let i=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(i&&i[0]!==void 0&&i[1]!==void 0){let s=Kf(i[0]-1,i[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(s,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,i=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);if(!i){this._oldHasSelection&&this._fireOnSelectionChange(e,t,i);return}!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,i)}_fireOnSelectionChange(e,t,i){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=i,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(t=>this._handleTrim(t))}_convertViewportColToCharacterIndex(e,t){let i=t;for(let s=0;t>=s;s++){let r=e.loadCell(s,this._workCell).getChars().length;this._workCell.getWidth()===0?i--:r>1&&t!==s&&(i+=r-1)}return i}setSelection(e,t,i){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=i,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,i=!0,s=!0){if(e[0]>=this._bufferService.cols)return;let r=this._bufferService.buffer,n=r.lines.get(e[1]);if(!n)return;let o=r.translateBufferLineToString(e[1],!1),a=this._convertViewportColToCharacterIndex(n,e[0]),l=a,c=e[0]-a,d=0,p=0,f=0,g=0;if(o.charAt(a)===" "){for(;a>0&&o.charAt(a-1)===" ";)a--;for(;l<o.length&&o.charAt(l+1)===" ";)l++}else{let S=e[0],v=e[0];n.getWidth(S)===0&&(d++,S--),n.getWidth(v)===2&&(p++,v++);let P=n.getString(v).length;for(P>1&&(g+=P-1,l+=P-1);S>0&&a>0&&!this._isCharWordSeparator(n.loadCell(S-1,this._workCell));){n.loadCell(S-1,this._workCell);let w=this._workCell.getChars().length;this._workCell.getWidth()===0?(d++,S--):w>1&&(f+=w-1,a-=w-1),a--,S--}for(;v<n.length&&l+1<o.length&&!this._isCharWordSeparator(n.loadCell(v+1,this._workCell));){n.loadCell(v+1,this._workCell);let w=this._workCell.getChars().length;this._workCell.getWidth()===2?(p++,v++):w>1&&(g+=w-1,l+=w-1),l++,v++}}l++;let u=a+c-d+f,_=Math.min(this._bufferService.cols,l-a+d+p-f-g);if(!(!t&&o.slice(a,l).trim()==="")){if(i&&u===0&&n.getCodePoint(0)!==32){let S=r.lines.get(e[1]-1);if(S&&n.isWrapped&&S.getCodePoint(this._bufferService.cols-1)!==32){let v=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(v){let P=this._bufferService.cols-v.start;u-=P,_+=P}}}if(s&&u+_===this._bufferService.cols&&n.getCodePoint(this._bufferService.cols-1)!==32){let S=r.lines.get(e[1]+1);if(S?.isWrapped&&S.getCodePoint(0)!==32){let v=this._getWordAt([0,e[1]+1],!1,!1,!0);v&&(_+=v.length)}}return{start:u,length:_}}}_selectWordAt(e,t){let i=this._getWordAt(e,t);if(i){for(;i.start<0;)i.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[i.start,e[1]],this._model.selectionStartLength=i.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let i=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,i--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,i++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,i]}}_isCharWordSeparator(e){return e.getWidth()===0?!1:this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),i={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=Ho(i,this._bufferService.cols)}};ln=ce([L(3,Ge),L(4,ri),L(5,Dn),L(6,We),L(7,Dt),L(8,Mt)],ln);var Go=class{constructor(){this._data={}}set(e,t,i){this._data[e]||(this._data[e]={}),this._data[e][t]=i}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},Wo=class{constructor(){this._color=new Go,this._css=new Go}setCss(e,t,i){this._css.set(e,t,i)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,i){this._color.set(e,t,i)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},fe=Object.freeze((()=>{let e=[ae.toColor("#2e3436"),ae.toColor("#cc0000"),ae.toColor("#4e9a06"),ae.toColor("#c4a000"),ae.toColor("#3465a4"),ae.toColor("#75507b"),ae.toColor("#06989a"),ae.toColor("#d3d7cf"),ae.toColor("#555753"),ae.toColor("#ef2929"),ae.toColor("#8ae234"),ae.toColor("#fce94f"),ae.toColor("#729fcf"),ae.toColor("#ad7fa8"),ae.toColor("#34e2e2"),ae.toColor("#eeeeec")],t=[0,95,135,175,215,255];for(let i=0;i<216;i++){let s=t[i/36%6|0],r=t[i/6%6|0],n=t[i%6];e.push({css:_e.toCss(s,r,n),rgba:_e.toRgba(s,r,n)})}for(let i=0;i<24;i++){let s=8+i*10;e.push({css:_e.toCss(s,s,s),rgba:_e.toRgba(s,s,s)})}return e})()),qt=ae.toColor("#ffffff"),Ri=ae.toColor("#000000"),$o=ae.toColor("#ffffff"),Vo=Ri,Ai={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},ep=qt,hn=class extends W{constructor(e){super(),this._optionsService=e,this._contrastCache=new Wo,this._halfContrastCache=new Wo,this._onChangeColors=this._register(new k),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:qt,background:Ri,cursor:$o,cursorAccent:Vo,selectionForeground:void 0,selectionBackgroundTransparent:Ai,selectionBackgroundOpaque:re.blend(Ri,Ai),selectionInactiveBackgroundTransparent:Ai,selectionInactiveBackgroundOpaque:re.blend(Ri,Ai),scrollbarSliderBackground:re.opacity(qt,.2),scrollbarSliderHoverBackground:re.opacity(qt,.4),scrollbarSliderActiveBackground:re.opacity(qt,.5),overviewRulerBorder:qt,ansi:fe.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange("theme",()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=Z(e.foreground,qt),t.background=Z(e.background,Ri),t.cursor=re.blend(t.background,Z(e.cursor,$o)),t.cursorAccent=re.blend(t.background,Z(e.cursorAccent,Vo)),t.selectionBackgroundTransparent=Z(e.selectionBackground,Ai),t.selectionBackgroundOpaque=re.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=Z(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=re.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?Z(e.selectionForeground,Ko):void 0,t.selectionForeground===Ko&&(t.selectionForeground=void 0),re.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=re.opacity(t.selectionBackgroundTransparent,.3)),re.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=re.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=Z(e.scrollbarSliderBackground,re.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=Z(e.scrollbarSliderHoverBackground,re.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=Z(e.scrollbarSliderActiveBackground,re.opacity(t.foreground,.5)),t.overviewRulerBorder=Z(e.overviewRulerBorder,ep),t.ansi=fe.slice(),t.ansi[0]=Z(e.black,fe[0]),t.ansi[1]=Z(e.red,fe[1]),t.ansi[2]=Z(e.green,fe[2]),t.ansi[3]=Z(e.yellow,fe[3]),t.ansi[4]=Z(e.blue,fe[4]),t.ansi[5]=Z(e.magenta,fe[5]),t.ansi[6]=Z(e.cyan,fe[6]),t.ansi[7]=Z(e.white,fe[7]),t.ansi[8]=Z(e.brightBlack,fe[8]),t.ansi[9]=Z(e.brightRed,fe[9]),t.ansi[10]=Z(e.brightGreen,fe[10]),t.ansi[11]=Z(e.brightYellow,fe[11]),t.ansi[12]=Z(e.brightBlue,fe[12]),t.ansi[13]=Z(e.brightMagenta,fe[13]),t.ansi[14]=Z(e.brightCyan,fe[14]),t.ansi[15]=Z(e.brightWhite,fe[15]),e.extendedAnsi){let i=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let s=0;s<i;s++)t.ansi[s+16]=Z(e.extendedAnsi[s],fe[s+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0){for(let t=0;t<this._restoreColors.ansi.length;++t)this._colors.ansi[t]=this._restoreColors.ansi[t];return}switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};hn=ce([L(0,We)],hn);function Z(e,t){if(e!==void 0)try{return ae.toColor(e)}catch{}return t}var tp=class{constructor(...e){this._entries=new Map;for(let[t,i]of e)this.set(t,i)}set(e,t){let i=this._entries.get(e);return this._entries.set(e,t),i}forEach(e){for(let[t,i]of this._entries.entries())e(t,i)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},ip=class{constructor(){this._services=new tp,this._services.set(Mn,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let i=Vu(e).sort((n,o)=>n.index-o.index),s=[];for(let n of i){let o=this._services.get(n.id);if(!o)throw new Error(`[createInstance] ${e.name} depends on UNKNOWN service ${n.id._id}.`);s.push(o)}let r=i.length>0?i[0].index:t.length;if(t.length!==r)throw new Error(`[createInstance] First service dependency of ${e.name} at position ${r+1} conflicts with ${t.length} static arguments`);return new e(...t,...s)}},sp={trace:0,debug:1,info:2,warn:3,error:4,off:5},rp="xterm.js: ",cn=class extends W{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange("logLevel",()=>this._updateLogLevel()))}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=sp[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]=="function"&&(e[t]=e[t]())}_log(e,t,i){this._evalLazyOptionalParams(i),e.call(console,(this._optionsService.options.logger?"":rp)+t,...i)}trace(e,...t){this._logLevel<=0&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=1&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=2&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=3&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=4&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};cn=ce([L(0,We)],cn);var qo=class extends W{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new k),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new k),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new k),this.onTrim=this.onTrimEmitter.event,this._array=new Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=new Array(e);for(let i=0;i<Math.min(e,this.length);i++)t[i]=this._array[this._getCyclicIndex(i)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw new Error("Can only recycle when the buffer is full");return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...i){if(t){for(let s=e;s<this._length-t;s++)this._array[this._getCyclicIndex(s)]=this._array[this._getCyclicIndex(s+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let s=this._length-1;s>=e;s--)this._array[this._getCyclicIndex(s+i.length)]=this._array[this._getCyclicIndex(s)];for(let s=0;s<i.length;s++)this._array[this._getCyclicIndex(e+s)]=i[s];if(i.length&&this.onInsertEmitter.fire({index:e,amount:i.length}),this._length+i.length>this._maxLength){let s=this._length+i.length-this._maxLength;this._startIndex+=s,this._length=this._maxLength,this.onTrimEmitter.fire(s)}else this._length+=i.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,i){if(!(t<=0)){if(e<0||e>=this._length)throw new Error("start argument out of range");if(e+i<0)throw new Error("Cannot shift elements in list beyond index 0");if(i>0){for(let r=t-1;r>=0;r--)this.set(e+r+i,this.get(e+r));let s=e+t+i-this._length;if(s>0)for(this._length+=s;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let s=0;s<t;s++)this.set(e+s+i,this.get(e+s))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},G=3,ue=Object.freeze(new Xi),ls=0,yr=2,Li=class ql{constructor(t,i,s=!1){this.isWrapped=s,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(t*G);let r=i||ct.fromCharData([0,fl,1,0]);for(let n=0;n<t;++n)this.setCell(n,r);this.length=t}get(t){let i=this._data[t*G+0],s=i&2097151;return[this._data[t*G+1],i&2097152?this._combined[t]:s?Ut(s):"",i>>22,i&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):s]}set(t,i){this._data[t*G+1]=i[0],i[1].length>1?(this._combined[t]=i[1],this._data[t*G+0]=t|2097152|i[2]<<22):this._data[t*G+0]=i[1].charCodeAt(0)|i[2]<<22}getWidth(t){return this._data[t*G+0]>>22}hasWidth(t){return this._data[t*G+0]&12582912}getFg(t){return this._data[t*G+1]}getBg(t){return this._data[t*G+2]}hasContent(t){return this._data[t*G+0]&4194303}getCodePoint(t){let i=this._data[t*G+0];return i&2097152?this._combined[t].charCodeAt(this._combined[t].length-1):i&2097151}isCombined(t){return this._data[t*G+0]&2097152}getString(t){let i=this._data[t*G+0];return i&2097152?this._combined[t]:i&2097151?Ut(i&2097151):""}isProtected(t){return this._data[t*G+2]&536870912}loadCell(t,i){return ls=t*G,i.content=this._data[ls+0],i.fg=this._data[ls+1],i.bg=this._data[ls+2],i.content&2097152&&(i.combinedData=this._combined[t]),i.bg&268435456&&(i.extended=this._extendedAttrs[t]),i}setCell(t,i){i.content&2097152&&(this._combined[t]=i.combinedData),i.bg&268435456&&(this._extendedAttrs[t]=i.extended),this._data[t*G+0]=i.content,this._data[t*G+1]=i.fg,this._data[t*G+2]=i.bg}setCellFromCodepoint(t,i,s,r){r.bg&268435456&&(this._extendedAttrs[t]=r.extended),this._data[t*G+0]=i|s<<22,this._data[t*G+1]=r.fg,this._data[t*G+2]=r.bg}addCodepointToCell(t,i,s){let r=this._data[t*G+0];r&2097152?this._combined[t]+=Ut(i):r&2097151?(this._combined[t]=Ut(r&2097151)+Ut(i),r&=-2097152,r|=2097152):r=i|1<<22,s&&(r&=-12582913,r|=s<<22),this._data[t*G+0]=r}insertCells(t,i,s){if(t%=this.length,t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,s),i<this.length-t){let r=new ct;for(let n=this.length-t-i-1;n>=0;--n)this.setCell(t+i+n,this.loadCell(t+n,r));for(let n=0;n<i;++n)this.setCell(t+n,s)}else for(let r=t;r<this.length;++r)this.setCell(r,s);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,s)}deleteCells(t,i,s){if(t%=this.length,i<this.length-t){let r=new ct;for(let n=0;n<this.length-t-i;++n)this.setCell(t+n,this.loadCell(t+i+n,r));for(let n=this.length-i;n<this.length;++n)this.setCell(n,s)}else for(let r=t;r<this.length;++r)this.setCell(r,s);t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,s),this.getWidth(t)===0&&!this.hasContent(t)&&this.setCellFromCodepoint(t,0,1,s)}replaceCells(t,i,s,r=!1){if(r){for(t&&this.getWidth(t-1)===2&&!this.isProtected(t-1)&&this.setCellFromCodepoint(t-1,0,1,s),i<this.length&&this.getWidth(i-1)===2&&!this.isProtected(i)&&this.setCellFromCodepoint(i,0,1,s);t<i&&t<this.length;)this.isProtected(t)||this.setCell(t,s),t++;return}for(t&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t-1,0,1,s),i<this.length&&this.getWidth(i-1)===2&&this.setCellFromCodepoint(i,0,1,s);t<i&&t<this.length;)this.setCell(t++,s)}resize(t,i){if(t===this.length)return this._data.length*4*yr<this._data.buffer.byteLength;let s=t*G;if(t>this.length){if(this._data.buffer.byteLength>=s*4)this._data=new Uint32Array(this._data.buffer,0,s);else{let r=new Uint32Array(s);r.set(this._data),this._data=r}for(let r=this.length;r<t;++r)this.setCell(r,i)}else{this._data=this._data.subarray(0,s);let r=Object.keys(this._combined);for(let o=0;o<r.length;o++){let a=parseInt(r[o],10);a>=t&&delete this._combined[a]}let n=Object.keys(this._extendedAttrs);for(let o=0;o<n.length;o++){let a=parseInt(n[o],10);a>=t&&delete this._extendedAttrs[a]}}return this.length=t,s*4*yr<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*yr<this._data.buffer.byteLength){let t=new Uint32Array(this._data.length);return t.set(this._data),this._data=t,1}return 0}fill(t,i=!1){if(i){for(let s=0;s<this.length;++s)this.isProtected(s)||this.setCell(s,t);return}this._combined={},this._extendedAttrs={};for(let s=0;s<this.length;++s)this.setCell(s,t)}copyFrom(t){this.length!==t.length?this._data=new Uint32Array(t._data):this._data.set(t._data),this.length=t.length,this._combined={};for(let i in t._combined)this._combined[i]=t._combined[i];this._extendedAttrs={};for(let i in t._extendedAttrs)this._extendedAttrs[i]=t._extendedAttrs[i];this.isWrapped=t.isWrapped}clone(){let t=new ql(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let i in this._combined)t._combined[i]=this._combined[i];for(let i in this._extendedAttrs)t._extendedAttrs[i]=this._extendedAttrs[i];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*G+0]&4194303)return t+(this._data[t*G+0]>>22);return 0}getNoBgTrimmedLength(){for(let t=this.length-1;t>=0;--t)if(this._data[t*G+0]&4194303||this._data[t*G+2]&50331648)return t+(this._data[t*G+0]>>22);return 0}copyCellsFrom(t,i,s,r,n){let o=t._data;if(n)for(let l=r-1;l>=0;l--){for(let c=0;c<G;c++)this._data[(s+l)*G+c]=o[(i+l)*G+c];o[(i+l)*G+2]&268435456&&(this._extendedAttrs[s+l]=t._extendedAttrs[i+l])}else for(let l=0;l<r;l++){for(let c=0;c<G;c++)this._data[(s+l)*G+c]=o[(i+l)*G+c];o[(i+l)*G+2]&268435456&&(this._extendedAttrs[s+l]=t._extendedAttrs[i+l])}let a=Object.keys(t._combined);for(let l=0;l<a.length;l++){let c=parseInt(a[l],10);c>=i&&(this._combined[c-i+s]=t._combined[c])}}translateToString(t,i,s,r){i=i??0,s=s??this.length,t&&(s=Math.min(s,this.getTrimmedLength())),r&&(r.length=0);let n="";for(;i<s;){let o=this._data[i*G+0],a=o&2097151,l=o&2097152?this._combined[i]:a?Ut(a):jt;if(n+=l,r)for(let c=0;c<l.length;++c)r.push(i);i+=o>>22||1}return r&&r.push(i),n}};function np(e,t,i,s,r,n){let o=[];for(let a=0;a<e.length-1;a++){let l=a,c=e.get(++l);if(!c.isWrapped)continue;let d=[e.get(a)];for(;l<e.length&&c.isWrapped;)d.push(c),c=e.get(++l);if(!n&&s>=a&&s<l){a+=d.length-1;continue}let p=0,f=Hi(d,p,t),g=1,u=0;for(;g<d.length;){let S=Hi(d,g,t),v=S-u,P=i-f,w=Math.min(v,P);d[p].copyCellsFrom(d[g],u,f,w,!1),f+=w,f===i&&(p++,f=0),u+=w,u===S&&(g++,u=0),f===0&&p!==0&&d[p-1].getWidth(i-1)===2&&(d[p].copyCellsFrom(d[p-1],i-1,f++,1,!1),d[p-1].setCell(i-1,r))}d[p].replaceCells(f,i,r);let _=0;for(let S=d.length-1;S>0&&(S>p||d[S].getTrimmedLength()===0);S--)_++;_>0&&(o.push(a+d.length-_),o.push(_)),a+=d.length-1}return o}function op(e,t){let i=[],s=0,r=t[s],n=0;for(let o=0;o<e.length;o++)if(r===o){let a=t[++s];e.onDeleteEmitter.fire({index:o-n,amount:a}),o+=a-1,n+=a,r=t[++s]}else i.push(o);return{layout:i,countRemoved:n}}function ap(e,t){let i=[];for(let s=0;s<t.length;s++)i.push(e.get(t[s]));for(let s=0;s<i.length;s++)e.set(s,i[s]);e.length=t.length}function lp(e,t,i){let s=[],r=e.map((l,c)=>Hi(e,c,t)).reduce((l,c)=>l+c),n=0,o=0,a=0;for(;a<r;){if(r-a<i){s.push(r-a);break}n+=i;let l=Hi(e,o,t);n>l&&(n-=l,o++);let c=e[o].getWidth(n-1)===2;c&&n--;let d=c?i-1:i;s.push(d),a+=d}return s}function Hi(e,t,i){if(t===e.length-1)return e[t].getTrimmedLength();let s=!e[t].hasContent(i-1)&&e[t].getWidth(i-1)===1,r=e[t+1].getWidth(0)===2;return s&&r?i-1:i}var Xl=class Ql{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=Ql._nextId++,this._onDispose=this.register(new k),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),ei(this._disposables),this._disposables.length=0)}register(t){return this._disposables.push(t),t}};Xl._nextId=1;var hp=Xl,be={},Xt=be.B;be[0]={"`":"◆",a:"▒",b:"␉",c:"␌",d:"␍",e:"␊",f:"°",g:"±",h:"␤",i:"␋",j:"┘",k:"┐",l:"┌",m:"└",n:"┼",o:"⎺",p:"⎻",q:"─",r:"⎼",s:"⎽",t:"├",u:"┤",v:"┴",w:"┬",x:"│",y:"≤",z:"≥","{":"π","|":"≠","}":"£","~":"·"};be.A={"#":"£"};be.B=void 0;be[4]={"#":"£","@":"¾","[":"ij","\\":"½","]":"|","{":"¨","|":"f","}":"¼","~":"´"};be.C=be[5]={"[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};be.R={"#":"£","@":"à","[":"°","\\":"ç","]":"§","{":"é","|":"ù","}":"è","~":"¨"};be.Q={"@":"à","[":"â","\\":"ç","]":"ê","^":"î","`":"ô","{":"é","|":"ù","}":"è","~":"û"};be.K={"@":"§","[":"Ä","\\":"Ö","]":"Ü","{":"ä","|":"ö","}":"ü","~":"ß"};be.Y={"#":"£","@":"§","[":"°","\\":"ç","]":"é","`":"ù","{":"à","|":"ò","}":"è","~":"ì"};be.E=be[6]={"@":"Ä","[":"Æ","\\":"Ø","]":"Å","^":"Ü","`":"ä","{":"æ","|":"ø","}":"å","~":"ü"};be.Z={"#":"£","@":"§","[":"¡","\\":"Ñ","]":"¿","{":"°","|":"ñ","}":"ç"};be.H=be[7]={"@":"É","[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};be["="]={"#":"ù","@":"à","[":"é","\\":"ç","]":"ê","^":"î",_:"è","`":"ô","{":"ä","|":"ö","}":"ü","~":"û"};var Xo=4294967295,Qo=class{constructor(e,t,i){this._hasScrollback=e,this._optionsService=t,this._bufferService=i,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=ue.clone(),this.savedCharset=Xt,this.markers=[],this._nullCell=ct.fromCharData([0,fl,1,0]),this._whitespaceCell=ct.fromCharData([0,jt,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Is,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new qo(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new Cs),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new Cs),this._whitespaceCell}getBlankLine(e,t){return new Li(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>Xo?Xo:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=ue);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new qo(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let i=this.getNullCell(ue),s=0,r=this._getCorrectBufferLength(t);if(r>this.lines.maxLength&&(this.lines.maxLength=r),this.lines.length>0){if(this._cols<e)for(let o=0;o<this.lines.length;o++)s+=+this.lines.get(o).resize(e,i);let n=0;if(this._rows<t)for(let o=this._rows;o<t;o++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new Li(e,i)):this.ybase>0&&this.lines.length<=this.ybase+this.y+n+1?(this.ybase--,n++,this.ydisp>0&&this.ydisp--):this.lines.push(new Li(e,i)));else for(let o=this._rows;o>t;o--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(r<this.lines.maxLength){let o=this.lines.length-r;o>0&&(this.lines.trimStart(o),this.ybase=Math.max(this.ybase-o,0),this.ydisp=Math.max(this.ydisp-o,0),this.savedY=Math.max(this.savedY-o,0)),this.lines.maxLength=r}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),n&&(this.y+=n),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let n=0;n<this.lines.length;n++)s+=+this.lines.get(n).resize(e,i);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),s>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend==="conpty"&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let i=this._optionsService.rawOptions.reflowCursorLine,s=np(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(ue),i);if(s.length>0){let r=op(this.lines,s);ap(this.lines,r.layout),this._reflowLargerAdjustViewport(e,t,r.countRemoved)}}_reflowLargerAdjustViewport(e,t,i){let s=this.getNullCell(ue),r=i;for(;r-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new Li(e,s))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-i,0)}_reflowSmaller(e,t){let i=this._optionsService.rawOptions.reflowCursorLine,s=this.getNullCell(ue),r=[],n=0;for(let o=this.lines.length-1;o>=0;o--){let a=this.lines.get(o);if(!a||!a.isWrapped&&a.getTrimmedLength()<=e)continue;let l=[a];for(;a.isWrapped&&o>0;)a=this.lines.get(--o),l.unshift(a);if(!i){let w=this.ybase+this.y;if(w>=o&&w<o+l.length)continue}let c=l[l.length-1].getTrimmedLength(),d=lp(l,this._cols,e),p=d.length-l.length,f;this.ybase===0&&this.y!==this.lines.length-1?f=Math.max(0,this.y-this.lines.maxLength+p):f=Math.max(0,this.lines.length-this.lines.maxLength+p);let g=[];for(let w=0;w<p;w++){let E=this.getBlankLine(ue,!0);g.push(E)}g.length>0&&(r.push({start:o+l.length+n,newLines:g}),n+=g.length),l.push(...g);let u=d.length-1,_=d[u];_===0&&(u--,_=d[u]);let S=l.length-p-1,v=c;for(;S>=0;){let w=Math.min(v,_);if(l[u]===void 0)break;if(l[u].copyCellsFrom(l[S],v-w,_-w,w,!0),_-=w,_===0&&(u--,_=d[u]),v-=w,v===0){S--;let E=Math.max(S,0);v=Hi(l,E,this._cols)}}for(let w=0;w<l.length;w++)d[w]<e&&l[w].setCell(d[w],s);let P=p-f;for(;P-- >0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+n)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+p,this.ybase+t-1)}if(r.length>0){let o=[],a=[];for(let _=0;_<this.lines.length;_++)a.push(this.lines.get(_));let l=this.lines.length,c=l-1,d=0,p=r[d];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+n);let f=0;for(let _=Math.min(this.lines.maxLength-1,l+n-1);_>=0;_--)if(p&&p.start>c+f){for(let S=p.newLines.length-1;S>=0;S--)this.lines.set(_--,p.newLines[S]);_++,o.push({index:c+1,amount:p.newLines.length}),f+=p.newLines.length,p=r[++d]}else this.lines.set(_,a[c--]);let g=0;for(let _=o.length-1;_>=0;_--)o[_].index+=g,this.lines.onInsertEmitter.fire(o[_]),g+=o[_].amount;let u=Math.max(0,l+n-this.lines.maxLength);u>0&&this.lines.onTrimEmitter.fire(u)}}translateBufferLineToString(e,t,i=0,s){let r=this.lines.get(e);return r?r.translateToString(t,i,s):""}getWrappedRangeForLine(e){let t=e,i=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;i+1<this.lines.length&&this.lines.get(i+1).isWrapped;)i++;return{first:t,last:i}}setupTabStops(e){for(e!=null?this.tabs[e]||(e=this.prevStop(e)):(this.tabs={},e=0);e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e==null&&(e=this.x);!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e==null&&(e=this.x);!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new hp(e);return this.markers.push(t),t.register(this.lines.onTrim(i=>{t.line-=i,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(i=>{t.line>=i.index&&(t.line+=i.amount)})),t.register(this.lines.onDelete(i=>{t.line>=i.index&&t.line<i.index+i.amount&&t.dispose(),t.line>i.index&&(t.line-=i.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},cp=class extends W{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new k),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange("scrollback",()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange("tabStopWidth",()=>this.setupTabStops()))}reset(){this._normal=new Qo(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new Qo(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},Zl=2,Jl=1,dn=class extends W{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new k),this.onResize=this._onResize.event,this._onScroll=this._register(new k),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,Zl),this.rows=Math.max(e.rawOptions.rows||0,Jl),this.buffers=this._register(new cp(e,this)),this._register(this.buffers.onBufferActivate(t=>{this._onScroll.fire(t.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let i=this.cols!==e,s=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:i,rowsChanged:s})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let i=this.buffer,s;s=this._cachedBlankLine,(!s||s.length!==this.cols||s.getFg(0)!==e.fg||s.getBg(0)!==e.bg)&&(s=i.getBlankLine(e,t),this._cachedBlankLine=s),s.isWrapped=t;let r=i.ybase+i.scrollTop,n=i.ybase+i.scrollBottom;if(i.scrollTop===0){let o=i.lines.isFull;n===i.lines.length-1?o?i.lines.recycle().copyFrom(s):i.lines.push(s.clone()):i.lines.splice(n+1,0,s.clone()),o?this.isUserScrolling&&(i.ydisp=Math.max(i.ydisp-1,0)):(i.ybase++,this.isUserScrolling||i.ydisp++)}else{let o=n-r+1;i.lines.shiftElements(r+1,o-1,-1),i.lines.set(n,s.clone())}this.isUserScrolling||(i.ydisp=i.ybase),this._onScroll.fire(i.ydisp)}scrollLines(e,t){let i=this.buffer;if(e<0){if(i.ydisp===0)return;this.isUserScrolling=!0}else e+i.ydisp>=i.ybase&&(this.isUserScrolling=!1);let s=i.ydisp;i.ydisp=Math.max(Math.min(i.ydisp+e,i.ybase),0),s!==i.ydisp&&(t||this._onScroll.fire(i.ydisp))}};dn=ce([L(0,We)],dn);var li={cols:80,rows:24,cursorBlink:!1,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:"alt",fastScrollSensitivity:5,fontFamily:"monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:xs,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRuler:{}},dp=["normal","bold","100","200","300","400","500","600","700","800","900"],up=class extends W{constructor(e){super(),this._onOptionChange=this._register(new k),this.onOptionChange=this._onOptionChange.event;let t={...li};for(let i in e)if(i in t)try{let s=e[i];t[i]=this._sanitizeAndValidateOption(i,s)}catch(s){console.error(s)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(ne(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(i=>{i===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(i=>{e.indexOf(i)!==-1&&t()})}_setupOptions(){let e=i=>{if(!(i in li))throw new Error(`No option with key "${i}"`);return this.rawOptions[i]},t=(i,s)=>{if(!(i in li))throw new Error(`No option with key "${i}"`);s=this._sanitizeAndValidateOption(i,s),this.rawOptions[i]!==s&&(this.rawOptions[i]=s,this._onOptionChange.fire(i))};for(let i in this.rawOptions){let s={get:e.bind(this,i),set:t.bind(this,i)};Object.defineProperty(this.options,i,s)}}_sanitizeAndValidateOption(e,t){switch(e){case"cursorStyle":if(t||(t=li[e]),!_p(t))throw new Error(`"${t}" is not a valid value for ${e}`);break;case"wordSeparator":t||(t=li[e]);break;case"fontWeight":case"fontWeightBold":if(typeof t=="number"&&1<=t&&t<=1e3)break;t=dp.includes(t)?t:li[e];break;case"cursorWidth":t=Math.floor(t);case"lineHeight":case"tabStopWidth":if(t<1)throw new Error(`${e} cannot be less than 1, value: ${t}`);break;case"minimumContrastRatio":t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case"scrollback":if(t=Math.min(t,4294967295),t<0)throw new Error(`${e} cannot be less than 0, value: ${t}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(t<=0)throw new Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case"rows":case"cols":if(!t&&t!==0)throw new Error(`${e} must be numeric, value: ${t}`);break;case"windowsPty":t=t??{};break}return t}};function _p(e){return e==="block"||e==="underline"||e==="bar"}function Ni(e,t=5){if(typeof e!="object")return e;let i=Array.isArray(e)?[]:{};for(let s in e)i[s]=t<=1?e[s]:e[s]&&Ni(e[s],t-1);return i}var Zo=Object.freeze({insertMode:!1}),Jo=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),un=class extends W{constructor(e,t,i){super(),this._bufferService=e,this._logService=t,this._optionsService=i,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new k),this.onData=this._onData.event,this._onUserInput=this._register(new k),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new k),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new k),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=Ni(Zo),this.decPrivateModes=Ni(Jo)}reset(){this.modes=Ni(Zo),this.decPrivateModes=Ni(Jo)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let i=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&i.ybase!==i.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace("sending data (codes)",()=>e.split("").map(s=>s.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace("sending binary (codes)",()=>e.split("").map(t=>t.charCodeAt(0))),this._onBinary.fire(e))}};un=ce([L(0,Ge),L(1,Sl),L(2,We)],un);var ea={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>!(e.action===32&&e.button===3)},ANY:{events:31,restrict:e=>!0}};function Cr(e,t){let i=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(i|=64,i|=e.action):(i|=e.button&3,e.button&4&&(i|=64),e.button&8&&(i|=128),e.action===32?i|=32:e.action===0&&!t&&(i|=3)),i}var wr=String.fromCharCode,ta={DEFAULT:e=>{let t=[Cr(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?"":`\x1B[M${wr(t[0])}${wr(t[1])}${wr(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${Cr(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?"m":"M";return`\x1B[<${Cr(e,!0)};${e.x};${e.y}${t}`}},_n=class extends W{constructor(e,t,i){super(),this._bufferService=e,this._coreService=t,this._optionsService=i,this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new k),this.onProtocolChange=this._onProtocolChange.event;for(let s of Object.keys(ea))this.addProtocol(s,ea[s]);for(let s of Object.keys(ta))this.addEncoding(s,ta[s]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw new Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw new Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT",this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,i){if(e.deltaY===0||e.shiftKey||t===void 0||i===void 0)return 0;let s=t/i,r=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(r/=s+0,Math.abs(e.deltaY)<50&&(r*=.3),this._wheelPartialScroll+=r,r=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(r*=this._bufferService.rows),r}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding==="SGR_PIXELS"))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding==="DEFAULT"?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,i){if(i){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return!(e.button!==t.button||e.action!==t.action||e.ctrl!==t.ctrl||e.alt!==t.alt||e.shift!==t.shift)}};_n=ce([L(0,Ge),L(1,ri),L(2,We)],_n);var Er=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],fp=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],pe;function pp(e,t){let i=0,s=t.length-1,r;if(e<t[0][0]||e>t[s][1])return!1;for(;s>=i;)if(r=i+s>>1,e>t[r][1])i=r+1;else if(e<t[r][0])s=r-1;else return!0;return!1}var mp=class{constructor(){if(this.version="6",!pe){pe=new Uint8Array(65536),pe.fill(1),pe[0]=0,pe.fill(0,1,32),pe.fill(0,127,160),pe.fill(2,4352,4448),pe[9001]=2,pe[9002]=2,pe.fill(2,11904,42192),pe[12351]=1,pe.fill(2,44032,55204),pe.fill(2,63744,64256),pe.fill(2,65040,65050),pe.fill(2,65072,65136),pe.fill(2,65280,65377),pe.fill(2,65504,65511);for(let e=0;e<Er.length;++e)pe.fill(0,Er[e][0],Er[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?pe[e]:pp(e,fp)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let i=this.wcwidth(e),s=i===0&&t!==0;if(s){let r=Qt.extractWidth(t);r===0?s=!1:r>i&&(i=r)}return Qt.createPropertyValue(0,i,s)}},Qt=class Ss{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new k,this.onChange=this._onChange.event;let t=new mp;this.register(t),this._active=t.version,this._activeProvider=t}static extractShouldJoin(t){return(t&1)!==0}static extractWidth(t){return t>>1&3}static extractCharKind(t){return t>>3}static createPropertyValue(t,i,s=!1){return(t&16777215)<<3|(i&3)<<1|(s?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(t){if(!this._providers[t])throw new Error(`unknown Unicode version "${t}"`);this._active=t,this._activeProvider=this._providers[t],this._onChange.fire(t)}register(t){this._providers[t.version]=t}wcwidth(t){return this._activeProvider.wcwidth(t)}getStringCellWidth(t){let i=0,s=0,r=t.length;for(let n=0;n<r;++n){let o=t.charCodeAt(n);if(55296<=o&&o<=56319){if(++n>=r)return i+this.wcwidth(o);let c=t.charCodeAt(n);56320<=c&&c<=57343?o=(o-55296)*1024+c-56320+65536:i+=this.wcwidth(c)}let a=this.charProperties(o,s),l=Ss.extractWidth(a);Ss.extractShouldJoin(a)&&(l-=Ss.extractWidth(s)),i+=l,s=a}return i}charProperties(t,i){return this._activeProvider.charProperties(t,i)}},gp=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function ia(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),i=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);i&&t&&(i.isWrapped=t[3]!==0&&t[3]!==32)}var Pi=2147483647,vp=256,eh=class fn{constructor(t=32,i=32){if(this.maxLength=t,this.maxSubParamsLength=i,i>vp)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(t),this.length=0,this._subParams=new Int32Array(i),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(t),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let i=new fn;if(!t.length)return i;for(let s=Array.isArray(t[0])?1:0;s<t.length;++s){let r=t[s];if(Array.isArray(r))for(let n=0;n<r.length;++n)i.addSubParam(r[n]);else i.addParam(r)}return i}clone(){let t=new fn(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let t=[];for(let i=0;i<this.length;++i){t.push(this.params[i]);let s=this._subParamsIdx[i]>>8,r=this._subParamsIdx[i]&255;r-s>0&&t.push(Array.prototype.slice.call(this._subParams,s,r))}return t}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(t){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(t<-1)throw new Error("values lesser than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=t>Pi?Pi:t}addSubParam(t){if(this._digitIsSub=!0,!!this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(t<-1)throw new Error("values lesser than -1 are not allowed");this._subParams[this._subParamsLength++]=t>Pi?Pi:t,this._subParamsIdx[this.length-1]++}}hasSubParams(t){return(this._subParamsIdx[t]&255)-(this._subParamsIdx[t]>>8)>0}getSubParams(t){let i=this._subParamsIdx[t]>>8,s=this._subParamsIdx[t]&255;return s-i>0?this._subParams.subarray(i,s):null}getSubParamsAll(){let t={};for(let i=0;i<this.length;++i){let s=this._subParamsIdx[i]>>8,r=this._subParamsIdx[i]&255;r-s>0&&(t[i]=this._subParams.slice(s,r))}return t}addDigit(t){let i;if(this._rejectDigits||!(i=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let s=this._digitIsSub?this._subParams:this.params,r=s[i-1];s[i-1]=~r?Math.min(r*10+t,Pi):t}},ki=[],Sp=class{constructor(){this._state=0,this._active=ki,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=ki}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=ki,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||ki,!this._active.length)this._handlerFb(this._id,"START");else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,i){if(!this._active.length)this._handlerFb(this._id,"PUT",$s(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}start(){this.reset(),this._state=1}put(e,t,i){if(this._state!==3){if(this._state===1)for(;t<i;){let s=e[t++];if(s===59){this._state=2,this._start();break}if(s<48||57<s){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+s-48}this._state===2&&i-t>0&&this._put(e,t,i)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,"END",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].end(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].end(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=ki,this._id=-1,this._state=0}}},Qe=class{constructor(e){this._handler=e,this._data="",this._hitLimit=!1}start(){this._data="",this._hitLimit=!1}put(e,t,i){this._hitLimit||(this._data+=$s(e,t,i),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(i=>(this._data="",this._hitLimit=!1,i));return this._data="",this._hitLimit=!1,t}},Mi=[],bp=class{constructor(){this._handlers=Object.create(null),this._active=Mi,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=Mi}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let i=this._handlers[e];return i.push(t),{dispose:()=>{let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=Mi,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||Mi,!this._active.length)this._handlerFb(this._ident,"HOOK",t);else for(let i=this._active.length-1;i>=0;i--)this._active[i].hook(t)}put(e,t,i){if(!this._active.length)this._handlerFb(this._ident,"PUT",$s(e,t,i));else for(let s=this._active.length-1;s>=0;s--)this._active[s].put(e,t,i)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,"UNHOOK",e);else{let i=!1,s=this._active.length-1,r=!1;if(this._stack.paused&&(s=this._stack.loopPosition-1,i=t,r=this._stack.fallThrough,this._stack.paused=!1),!r&&i===!1){for(;s>=0&&(i=this._active[s].unhook(e),i!==!0);s--)if(i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!1,i;s--}for(;s>=0;s--)if(i=this._active[s].unhook(!1),i instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=s,this._stack.fallThrough=!0,i}this._active=Mi,this._ident=0}},Bi=new eh;Bi.addParam(0);var sa=class{constructor(e){this._handler=e,this._data="",this._params=Bi,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():Bi,this._data="",this._hitLimit=!1}put(e,t,i){this._hitLimit||(this._data+=$s(e,t,i),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(i=>(this._params=Bi,this._data="",this._hitLimit=!1,i));return this._params=Bi,this._data="",this._hitLimit=!1,t}},yp=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,i,s){this.table[t<<8|e]=i<<4|s}addMany(e,t,i,s){for(let r=0;r<e.length;r++)this.table[t<<8|e[r]]=i<<4|s}},at=160,Cp=(function(){let e=new yp(4095),t=Array.apply(null,Array(256)).map((a,l)=>l),i=(a,l)=>t.slice(a,l),s=i(32,127),r=i(0,24);r.push(25),r.push.apply(r,i(28,32));let n=i(0,14),o;e.setDefault(1,0),e.addMany(s,0,2,0);for(o in n)e.addMany([24,26,153,154],o,3,0),e.addMany(i(128,144),o,3,0),e.addMany(i(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(r,0,3,0),e.addMany(r,1,3,1),e.add(127,1,0,1),e.addMany(r,8,0,8),e.addMany(r,3,3,3),e.add(127,3,0,3),e.addMany(r,4,3,4),e.add(127,4,0,4),e.addMany(r,6,3,6),e.addMany(r,5,3,5),e.add(127,5,0,5),e.addMany(r,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(s,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(i(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(s,7,0,7),e.addMany(r,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(i(64,127),3,7,0),e.addMany(i(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(i(48,60),4,8,4),e.addMany(i(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(i(32,64),6,0,6),e.add(127,6,0,6),e.addMany(i(64,127),6,0,0),e.addMany(i(32,48),3,9,5),e.addMany(i(32,48),5,9,5),e.addMany(i(48,64),5,0,6),e.addMany(i(64,127),5,7,0),e.addMany(i(32,48),4,9,5),e.addMany(i(32,48),1,9,2),e.addMany(i(32,48),2,9,2),e.addMany(i(48,127),2,10,0),e.addMany(i(48,80),1,10,0),e.addMany(i(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(i(96,127),1,10,0),e.add(80,1,11,9),e.addMany(r,9,0,9),e.add(127,9,0,9),e.addMany(i(28,32),9,0,9),e.addMany(i(32,48),9,9,12),e.addMany(i(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(r,11,0,11),e.addMany(i(32,128),11,0,11),e.addMany(i(28,32),11,0,11),e.addMany(r,10,0,10),e.add(127,10,0,10),e.addMany(i(28,32),10,0,10),e.addMany(i(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(i(32,48),10,9,12),e.addMany(r,12,0,12),e.add(127,12,0,12),e.addMany(i(28,32),12,0,12),e.addMany(i(32,48),12,9,12),e.addMany(i(48,64),12,0,11),e.addMany(i(64,127),12,12,13),e.addMany(i(64,127),10,12,13),e.addMany(i(64,127),9,12,13),e.addMany(r,13,13,13),e.addMany(s,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(at,0,2,0),e.add(at,8,5,8),e.add(at,6,0,6),e.add(at,11,0,11),e.add(at,13,13,13),e})(),wp=class extends W{constructor(e=Cp){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new eh,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(t,i,s)=>{},this._executeHandlerFb=t=>{},this._csiHandlerFb=(t,i)=>{},this._escHandlerFb=t=>{},this._errorHandlerFb=t=>t,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(ne(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new Sp),this._dcsParser=this._register(new bp),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},()=>!0)}_identifier(e,t=[64,126]){let i=0;if(e.prefix){if(e.prefix.length>1)throw new Error("only one byte as prefix supported");if(i=e.prefix.charCodeAt(0),i&&60>i||i>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(e.intermediates){if(e.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let r=0;r<e.intermediates.length;++r){let n=e.intermediates.charCodeAt(r);if(32>n||n>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");i<<=8,i|=n}}if(e.final.length!==1)throw new Error("final must be a single byte");let s=e.final.charCodeAt(0);if(t[0]>s||s>t[1])throw new Error(`final must be in range ${t[0]} .. ${t[1]}`);return i<<=8,i|=s,i}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join("")}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let i=this._identifier(e,[48,126]);this._escHandlers[i]===void 0&&(this._escHandlers[i]=[]);let s=this._escHandlers[i];return s.push(t),{dispose:()=>{let r=s.indexOf(t);r!==-1&&s.splice(r,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let i=this._identifier(e);this._csiHandlers[i]===void 0&&(this._csiHandlers[i]=[]);let s=this._csiHandlers[i];return s.push(t),{dispose:()=>{let r=s.indexOf(t);r!==-1&&s.splice(r,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,i,s,r){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=i,this._parseStack.transition=s,this._parseStack.chunkPos=r}parse(e,t,i){let s=0,r=0,n=0,o;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,n=this._parseStack.chunkPos+1;else{if(i===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");let a=this._parseStack.handlers,l=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(i===!1&&l>-1){for(;l>=0&&(o=a[l](this._params),o!==!0);l--)if(o instanceof Promise)return this._parseStack.handlerPos=l,o}this._parseStack.handlers=[];break;case 4:if(i===!1&&l>-1){for(;l>=0&&(o=a[l](),o!==!0);l--)if(o instanceof Promise)return this._parseStack.handlerPos=l,o}this._parseStack.handlers=[];break;case 6:if(s=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(s=e[this._parseStack.chunkPos],o=this._oscParser.end(s!==24&&s!==26,i),o)return o;s===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break}this._parseStack.state=0,n=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}for(let a=n;a<t;++a){switch(s=e[a],r=this._transitions.table[this.currentState<<8|(s<160?s:at)],r>>4){case 2:for(let f=a+1;;++f){if(f>=t||(s=e[f])<32||s>126&&s<at){this._printHandler(e,a,f),a=f-1;break}if(++f>=t||(s=e[f])<32||s>126&&s<at){this._printHandler(e,a,f),a=f-1;break}if(++f>=t||(s=e[f])<32||s>126&&s<at){this._printHandler(e,a,f),a=f-1;break}if(++f>=t||(s=e[f])<32||s>126&&s<at){this._printHandler(e,a,f),a=f-1;break}}break;case 3:this._executeHandlers[s]?this._executeHandlers[s]():this._executeHandlerFb(s),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:a,code:s,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let l=this._csiHandlers[this._collect<<8|s],c=l?l.length-1:-1;for(;c>=0&&(o=l[c](this._params),o!==!0);c--)if(o instanceof Promise)return this._preserveStack(3,l,c,r,a),o;c<0&&this._csiHandlerFb(this._collect<<8|s,this._params),this.precedingJoinState=0;break;case 8:do switch(s){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(s-48)}while(++a<t&&(s=e[a])>47&&s<60);a--;break;case 9:this._collect<<=8,this._collect|=s;break;case 10:let d=this._escHandlers[this._collect<<8|s],p=d?d.length-1:-1;for(;p>=0&&(o=d[p](),o!==!0);p--)if(o instanceof Promise)return this._preserveStack(4,d,p,r,a),o;p<0&&this._escHandlerFb(this._collect<<8|s),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|s,this._params);break;case 13:for(let f=a+1;;++f)if(f>=t||(s=e[f])===24||s===26||s===27||s>127&&s<at){this._dcsParser.put(e,a,f),a=f-1;break}break;case 14:if(o=this._dcsParser.unhook(s!==24&&s!==26),o)return this._preserveStack(6,[],0,r,a),o;s===27&&(r|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let f=a+1;;f++)if(f>=t||(s=e[f])<32||s>127&&s<at){this._oscParser.put(e,a,f),a=f-1;break}break;case 6:if(o=this._oscParser.end(s!==24&&s!==26),o)return this._preserveStack(5,[],0,r,a),o;s===27&&(r|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=r&15}}},Ep=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,xp=/^[\da-f]+$/;function ra(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf("rgb:")===0){t=t.slice(4);let i=Ep.exec(t);if(i){let s=i[1]?15:i[4]?255:i[7]?4095:65535;return[Math.round(parseInt(i[1]||i[4]||i[7]||i[10],16)/s*255),Math.round(parseInt(i[2]||i[5]||i[8]||i[11],16)/s*255),Math.round(parseInt(i[3]||i[6]||i[9]||i[12],16)/s*255)]}}else if(t.indexOf("#")===0&&(t=t.slice(1),xp.exec(t)&&[3,6,9,12].includes(t.length))){let i=t.length/3,s=[0,0,0];for(let r=0;r<3;++r){let n=parseInt(t.slice(i*r,i*r+i),16);s[r]=i===1?n<<4:i===2?n:i===3?n>>4:n>>8}return s}}function xr(e,t){let i=e.toString(16),s=i.length<2?"0"+i:i;switch(t){case 4:return i[0];case 8:return s;case 12:return(s+s).slice(0,3);default:return s+s}}function Ip(e,t=16){let[i,s,r]=e;return`rgb:${xr(i,t)}/${xr(s,t)}/${xr(r,t)}`}var Ap={"(":0,")":1,"*":2,"+":3,"-":1,".":2},Ot=131072,na=10;function oa(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var aa=5e3,la=0,Pp=class extends W{constructor(e,t,i,s,r,n,o,a,l=new wp){super(),this._bufferService=e,this._charsetService=t,this._coreService=i,this._logService=s,this._optionsService=r,this._oscLinkService=n,this._coreMouseService=o,this._unicodeService=a,this._parser=l,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new Wu,this._utf8Decoder=new $u,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=ue.clone(),this._eraseAttrDataInternal=ue.clone(),this._onRequestBell=this._register(new k),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new k),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new k),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new k),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new k),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new k),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new k),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new k),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new k),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new k),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new k),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new k),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new k),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new pn(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(c=>this._activeBuffer=c.activeBuffer)),this._parser.setCsiHandlerFallback((c,d)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(c),params:d.toArray()})}),this._parser.setEscHandlerFallback(c=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(c)})}),this._parser.setExecuteHandlerFallback(c=>{this._logService.debug("Unknown EXECUTE code: ",{code:c})}),this._parser.setOscHandlerFallback((c,d,p)=>{this._logService.debug("Unknown OSC code: ",{identifier:c,action:d,data:p})}),this._parser.setDcsHandlerFallback((c,d,p)=>{d==="HOOK"&&(p=p.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(c),action:d,payload:p})}),this._parser.setPrintHandler((c,d,p)=>this.print(c,d,p)),this._parser.registerCsiHandler({final:"@"},c=>this.insertChars(c)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},c=>this.scrollLeft(c)),this._parser.registerCsiHandler({final:"A"},c=>this.cursorUp(c)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},c=>this.scrollRight(c)),this._parser.registerCsiHandler({final:"B"},c=>this.cursorDown(c)),this._parser.registerCsiHandler({final:"C"},c=>this.cursorForward(c)),this._parser.registerCsiHandler({final:"D"},c=>this.cursorBackward(c)),this._parser.registerCsiHandler({final:"E"},c=>this.cursorNextLine(c)),this._parser.registerCsiHandler({final:"F"},c=>this.cursorPrecedingLine(c)),this._parser.registerCsiHandler({final:"G"},c=>this.cursorCharAbsolute(c)),this._parser.registerCsiHandler({final:"H"},c=>this.cursorPosition(c)),this._parser.registerCsiHandler({final:"I"},c=>this.cursorForwardTab(c)),this._parser.registerCsiHandler({final:"J"},c=>this.eraseInDisplay(c,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},c=>this.eraseInDisplay(c,!0)),this._parser.registerCsiHandler({final:"K"},c=>this.eraseInLine(c,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},c=>this.eraseInLine(c,!0)),this._parser.registerCsiHandler({final:"L"},c=>this.insertLines(c)),this._parser.registerCsiHandler({final:"M"},c=>this.deleteLines(c)),this._parser.registerCsiHandler({final:"P"},c=>this.deleteChars(c)),this._parser.registerCsiHandler({final:"S"},c=>this.scrollUp(c)),this._parser.registerCsiHandler({final:"T"},c=>this.scrollDown(c)),this._parser.registerCsiHandler({final:"X"},c=>this.eraseChars(c)),this._parser.registerCsiHandler({final:"Z"},c=>this.cursorBackwardTab(c)),this._parser.registerCsiHandler({final:"`"},c=>this.charPosAbsolute(c)),this._parser.registerCsiHandler({final:"a"},c=>this.hPositionRelative(c)),this._parser.registerCsiHandler({final:"b"},c=>this.repeatPrecedingCharacter(c)),this._parser.registerCsiHandler({final:"c"},c=>this.sendDeviceAttributesPrimary(c)),this._parser.registerCsiHandler({prefix:">",final:"c"},c=>this.sendDeviceAttributesSecondary(c)),this._parser.registerCsiHandler({final:"d"},c=>this.linePosAbsolute(c)),this._parser.registerCsiHandler({final:"e"},c=>this.vPositionRelative(c)),this._parser.registerCsiHandler({final:"f"},c=>this.hVPosition(c)),this._parser.registerCsiHandler({final:"g"},c=>this.tabClear(c)),this._parser.registerCsiHandler({final:"h"},c=>this.setMode(c)),this._parser.registerCsiHandler({prefix:"?",final:"h"},c=>this.setModePrivate(c)),this._parser.registerCsiHandler({final:"l"},c=>this.resetMode(c)),this._parser.registerCsiHandler({prefix:"?",final:"l"},c=>this.resetModePrivate(c)),this._parser.registerCsiHandler({final:"m"},c=>this.charAttributes(c)),this._parser.registerCsiHandler({final:"n"},c=>this.deviceStatus(c)),this._parser.registerCsiHandler({prefix:"?",final:"n"},c=>this.deviceStatusPrivate(c)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},c=>this.softReset(c)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},c=>this.setCursorStyle(c)),this._parser.registerCsiHandler({final:"r"},c=>this.setScrollRegion(c)),this._parser.registerCsiHandler({final:"s"},c=>this.saveCursor(c)),this._parser.registerCsiHandler({final:"t"},c=>this.windowOptions(c)),this._parser.registerCsiHandler({final:"u"},c=>this.restoreCursor(c)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},c=>this.insertColumns(c)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},c=>this.deleteColumns(c)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},c=>this.selectProtected(c)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},c=>this.requestMode(c,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},c=>this.requestMode(c,!1)),this._parser.setExecuteHandler(x.BEL,()=>this.bell()),this._parser.setExecuteHandler(x.LF,()=>this.lineFeed()),this._parser.setExecuteHandler(x.VT,()=>this.lineFeed()),this._parser.setExecuteHandler(x.FF,()=>this.lineFeed()),this._parser.setExecuteHandler(x.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler(x.BS,()=>this.backspace()),this._parser.setExecuteHandler(x.HT,()=>this.tab()),this._parser.setExecuteHandler(x.SO,()=>this.shiftOut()),this._parser.setExecuteHandler(x.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(gs.IND,()=>this.index()),this._parser.setExecuteHandler(gs.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(gs.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new Qe(c=>(this.setTitle(c),this.setIconName(c),!0))),this._parser.registerOscHandler(1,new Qe(c=>this.setIconName(c))),this._parser.registerOscHandler(2,new Qe(c=>this.setTitle(c))),this._parser.registerOscHandler(4,new Qe(c=>this.setOrReportIndexedColor(c))),this._parser.registerOscHandler(8,new Qe(c=>this.setHyperlink(c))),this._parser.registerOscHandler(10,new Qe(c=>this.setOrReportFgColor(c))),this._parser.registerOscHandler(11,new Qe(c=>this.setOrReportBgColor(c))),this._parser.registerOscHandler(12,new Qe(c=>this.setOrReportCursorColor(c))),this._parser.registerOscHandler(104,new Qe(c=>this.restoreIndexedColor(c))),this._parser.registerOscHandler(110,new Qe(c=>this.restoreFgColor(c))),this._parser.registerOscHandler(111,new Qe(c=>this.restoreBgColor(c))),this._parser.registerOscHandler(112,new Qe(c=>this.restoreCursorColor(c))),this._parser.registerEscHandler({final:"7"},()=>this.saveCursor()),this._parser.registerEscHandler({final:"8"},()=>this.restoreCursor()),this._parser.registerEscHandler({final:"D"},()=>this.index()),this._parser.registerEscHandler({final:"E"},()=>this.nextLine()),this._parser.registerEscHandler({final:"H"},()=>this.tabSet()),this._parser.registerEscHandler({final:"M"},()=>this.reverseIndex()),this._parser.registerEscHandler({final:"="},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:">"},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:"c"},()=>this.fullReset()),this._parser.registerEscHandler({final:"n"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"o"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"|"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"}"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"~"},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:"%",final:"@"},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:"%",final:"G"},()=>this.selectDefaultCharset());for(let c in be)this._parser.registerEscHandler({intermediates:"(",final:c},()=>this.selectCharset("("+c)),this._parser.registerEscHandler({intermediates:")",final:c},()=>this.selectCharset(")"+c)),this._parser.registerEscHandler({intermediates:"*",final:c},()=>this.selectCharset("*"+c)),this._parser.registerEscHandler({intermediates:"+",final:c},()=>this.selectCharset("+"+c)),this._parser.registerEscHandler({intermediates:"-",final:c},()=>this.selectCharset("-"+c)),this._parser.registerEscHandler({intermediates:".",final:c},()=>this.selectCharset("."+c)),this._parser.registerEscHandler({intermediates:"/",final:c},()=>this.selectCharset("/"+c));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(c=>(this._logService.error("Parsing error: ",c),c)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new sa((c,d)=>this.requestStatusString(c,d)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,i,s){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=i,this._parseStack.position=s}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((t,i)=>setTimeout(()=>i("#SLOW_TIMEOUT"),aa))]).catch(t=>{if(t!=="#SLOW_TIMEOUT")throw t;console.warn(`async parser handler taking longer than ${aa} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let i,s=this._activeBuffer.x,r=this._activeBuffer.y,n=0,o=this._parseStack.paused;if(o){if(i=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(i),i;s=this._parseStack.cursorStartX,r=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>Ot&&(n=this._parseStack.position+Ot)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e=="string"?` "${e}"`:` "${Array.prototype.map.call(e,c=>String.fromCharCode(c)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof e=="string"?e.split("").map(c=>c.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<Ot&&(this._parseBuffer=new Uint32Array(Math.min(e.length,Ot))),o||this._dirtyRowTracker.clearRange(),e.length>Ot)for(let c=n;c<e.length;c+=Ot){let d=c+Ot<e.length?c+Ot:e.length,p=typeof e=="string"?this._stringDecoder.decode(e.substring(c,d),this._parseBuffer):this._utf8Decoder.decode(e.subarray(c,d),this._parseBuffer);if(i=this._parser.parse(this._parseBuffer,p))return this._preserveStack(s,r,p,c),this._logSlowResolvingAsync(i),i}else if(!o){let c=typeof e=="string"?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(i=this._parser.parse(this._parseBuffer,c))return this._preserveStack(s,r,c,0),this._logSlowResolvingAsync(i),i}(this._activeBuffer.x!==s||this._activeBuffer.y!==r)&&this._onCursorMove.fire();let a=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),l=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);l<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(l,this._bufferService.rows-1),end:Math.min(a,this._bufferService.rows-1)})}print(e,t,i){let s,r,n=this._charsetService.charset,o=this._optionsService.rawOptions.screenReaderMode,a=this._bufferService.cols,l=this._coreService.decPrivateModes.wraparound,c=this._coreService.modes.insertMode,d=this._curAttrData,p=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&i-t>0&&p.getWidth(this._activeBuffer.x-1)===2&&p.setCellFromCodepoint(this._activeBuffer.x-1,0,1,d);let f=this._parser.precedingJoinState;for(let g=t;g<i;++g){if(s=e[g],s<127&&n){let v=n[String.fromCharCode(s)];v&&(s=v.charCodeAt(0))}let u=this._unicodeService.charProperties(s,f);r=Qt.extractWidth(u);let _=Qt.extractShouldJoin(u),S=_?Qt.extractWidth(f):0;if(f=u,o&&this._onA11yChar.fire(Ut(s)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+r-S>a){if(l){let v=p,P=this._activeBuffer.x-S;for(this._activeBuffer.x=S,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),p=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),S>0&&p instanceof Li&&p.copyCellsFrom(v,P,0,S,!1);P<a;)v.setCellFromCodepoint(P++,0,1,d)}else if(this._activeBuffer.x=a-1,r===2)continue}if(_&&this._activeBuffer.x){let v=p.getWidth(this._activeBuffer.x-1)?1:2;p.addCodepointToCell(this._activeBuffer.x-v,s,r);for(let P=r-S;--P>=0;)p.setCellFromCodepoint(this._activeBuffer.x++,0,0,d);continue}if(c&&(p.insertCells(this._activeBuffer.x,r-S,this._activeBuffer.getNullCell(d)),p.getWidth(a-1)===2&&p.setCellFromCodepoint(a-1,0,1,d)),p.setCellFromCodepoint(this._activeBuffer.x++,s,r,d),r>0)for(;--r;)p.setCellFromCodepoint(this._activeBuffer.x++,0,0,d)}this._parser.precedingJoinState=f,this._activeBuffer.x<a&&i-t>0&&p.getWidth(this._activeBuffer.x)===0&&!p.hasContent(this._activeBuffer.x)&&p.setCellFromCodepoint(this._activeBuffer.x,0,1,d),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final==="t"&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,i=>oa(i.params[0],this._optionsService.rawOptions.windowOptions)?t(i):!0):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new sa(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new Qe(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,i,s=!1,r=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.replaceCells(t,i,this._activeBuffer.getNullCell(this._eraseAttrData()),r),s&&(n.isWrapped=!1)}_resetBufferLine(e,t=!1){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);i&&(i.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),i.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let i;switch(e.params[0]){case 0:for(i=this._activeBuffer.y,this._dirtyRowTracker.markDirty(i),this._eraseInBufferLine(i++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);i<this._bufferService.rows;i++)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(i);break;case 1:for(i=this._activeBuffer.y,this._dirtyRowTracker.markDirty(i),this._eraseInBufferLine(i,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(i+1).isWrapped=!1);i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(i=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,i-1);i--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+i)?.getTrimmedLength(););for(;i>=0;i--)this._bufferService.scroll(this._eraseAttrData())}else{for(i=this._bufferService.rows,this._dirtyRowTracker.markDirty(i-1);i--;)this._resetBufferLine(i,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let s=this._activeBuffer.lines.length-this._bufferService.rows;s>0&&(this._activeBuffer.lines.trimStart(s),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-s,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-s,0),this._onScroll.fire(0));break}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let i=this._activeBuffer.ybase+this._activeBuffer.y,s=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-s+1;for(;t--;)this._activeBuffer.lines.splice(r-1,1),this._activeBuffer.lines.splice(i,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let i=this._activeBuffer.ybase+this._activeBuffer.y,s;for(s=this._bufferService.rows-1-this._activeBuffer.scrollBottom,s=this._bufferService.rows-1+this._activeBuffer.ybase-s;t--;)this._activeBuffer.lines.splice(i,1),this._activeBuffer.lines.splice(s,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(ue));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let i=this._activeBuffer.scrollTop;i<=this._activeBuffer.scrollBottom;++i){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+i);s.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),s.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let i=this._activeBuffer.scrollTop;i<=this._activeBuffer.scrollBottom;++i){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+i);s.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),s.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let i=this._activeBuffer.scrollTop;i<=this._activeBuffer.scrollBottom;++i){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+i);s.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),s.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let i=this._activeBuffer.scrollTop;i<=this._activeBuffer.scrollBottom;++i){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+i);s.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),s.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let i=e.params[0]||1,s=Qt.extractWidth(t),r=this._activeBuffer.x-s,n=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(r),o=new Uint32Array(n.length*i),a=0;for(let c=0;c<n.length;){let d=n.codePointAt(c)||0;o[a++]=d,c+=d>65535?2:1}let l=a;for(let c=1;c<i;++c)o.copyWithin(l,0,a),l+=a;return this.print(o,0,l),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent(x.ESC+"[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent(x.ESC+"[?6c")),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent(x.ESC+"[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent(x.ESC+"[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(e.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent(x.ESC+"[>83;40003;0c")),!0}_is(e){return(this._optionsService.rawOptions.termName+"").indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0;break}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,Xt),this._charsetService.setgCharset(1,Xt),this._charsetService.setgCharset(2,Xt),this._charsetService.setgCharset(3,Xt);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol="X10";break;case 1e3:this._coreMouseService.activeProtocol="VT200";break;case 1002:this._coreMouseService.activeProtocol="DRAG";break;case 1003:this._coreMouseService.activeProtocol="ANY";break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug("DECSET 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="SGR";break;case 1015:this._logService.debug("DECSET 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="SGR_PIXELS";break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0;break}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1;break}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol="NONE";break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug("DECRST 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="DEFAULT";break;case 1015:this._logService.debug("DECRST 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="DEFAULT";break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0);break}return!0}requestMode(e,t){let i;(_=>(_[_.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",_[_.SET=1]="SET",_[_.RESET=2]="RESET",_[_.PERMANENTLY_SET=3]="PERMANENTLY_SET",_[_.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(i||={});let s=this._coreService.decPrivateModes,{activeProtocol:r,activeEncoding:n}=this._coreMouseService,o=this._coreService,{buffers:a,cols:l}=this._bufferService,{active:c,alt:d}=a,p=this._optionsService.rawOptions,f=(_,S)=>(o.triggerDataEvent(`${x.ESC}[${t?"":"?"}${_};${S}$y`),!0),g=_=>_?1:2,u=e.params[0];return t?u===2?f(u,4):u===4?f(u,g(o.modes.insertMode)):u===12?f(u,3):u===20?f(u,g(p.convertEol)):f(u,0):u===1?f(u,g(s.applicationCursorKeys)):u===3?f(u,p.windowOptions.setWinLines?l===80?2:l===132?1:0:0):u===6?f(u,g(s.origin)):u===7?f(u,g(s.wraparound)):u===8?f(u,3):u===9?f(u,g(r==="X10")):u===12?f(u,g(p.cursorBlink)):u===25?f(u,g(!o.isCursorHidden)):u===45?f(u,g(s.reverseWraparound)):u===66?f(u,g(s.applicationKeypad)):u===67?f(u,4):u===1e3?f(u,g(r==="VT200")):u===1002?f(u,g(r==="DRAG")):u===1003?f(u,g(r==="ANY")):u===1004?f(u,g(s.sendFocus)):u===1005?f(u,4):u===1006?f(u,g(n==="SGR")):u===1015?f(u,4):u===1016?f(u,g(n==="SGR_PIXELS")):u===1048?f(u,1):u===47||u===1047||u===1049?f(u,g(c===d)):u===2004?f(u,g(s.bracketedPasteMode)):u===2026?f(u,g(s.synchronizedOutput)):f(u,0)}_updateAttrColor(e,t,i,s,r){return t===2?(e|=50331648,e&=-16777216,e|=Xi.fromColorRGB([i,s,r])):t===5&&(e&=-50331904,e|=33554432|i&255),e}_extractColor(e,t,i){let s=[0,0,-1,0,0,0],r=0,n=0;do{if(s[n+r]=e.params[t+n],e.hasSubParams(t+n)){let o=e.getSubParams(t+n),a=0;do s[1]===5&&(r=1),s[n+a+1+r]=o[a];while(++a<o.length&&a+n+1+r<s.length);break}if(s[1]===5&&n+r>=2||s[1]===2&&n+r>=5)break;s[1]&&(r=1)}while(++n+t<e.length&&n+r<s.length);for(let o=2;o<s.length;++o)s[o]===-1&&(s[o]=0);switch(s[0]){case 38:i.fg=this._updateAttrColor(i.fg,s[1],s[3],s[4],s[5]);break;case 48:i.bg=this._updateAttrColor(i.bg,s[1],s[3],s[4],s[5]);break;case 58:i.extended=i.extended.clone(),i.extended.underlineColor=this._updateAttrColor(i.extended.underlineColor,s[1],s[3],s[4],s[5])}return n}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=ue.fg,e.bg=ue.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,i,s=this._curAttrData;for(let r=0;r<t;r++)i=e.params[r],i>=30&&i<=37?(s.fg&=-50331904,s.fg|=16777216|i-30):i>=40&&i<=47?(s.bg&=-50331904,s.bg|=16777216|i-40):i>=90&&i<=97?(s.fg&=-50331904,s.fg|=16777216|i-90|8):i>=100&&i<=107?(s.bg&=-50331904,s.bg|=16777216|i-100|8):i===0?this._processSGR0(s):i===1?s.fg|=134217728:i===3?s.bg|=67108864:i===4?(s.fg|=268435456,this._processUnderline(e.hasSubParams(r)?e.getSubParams(r)[0]:1,s)):i===5?s.fg|=536870912:i===7?s.fg|=67108864:i===8?s.fg|=1073741824:i===9?s.fg|=2147483648:i===2?s.bg|=134217728:i===21?this._processUnderline(2,s):i===22?(s.fg&=-134217729,s.bg&=-134217729):i===23?s.bg&=-67108865:i===24?(s.fg&=-268435457,this._processUnderline(0,s)):i===25?s.fg&=-536870913:i===27?s.fg&=-67108865:i===28?s.fg&=-1073741825:i===29?s.fg&=2147483647:i===39?(s.fg&=-67108864,s.fg|=ue.fg&16777215):i===49?(s.bg&=-67108864,s.bg|=ue.bg&16777215):i===38||i===48||i===58?r+=this._extractColor(e,r,s):i===53?s.bg|=1073741824:i===55?s.bg&=-1073741825:i===59?(s.extended=s.extended.clone(),s.extended.underlineColor=-1,s.updateExtended()):i===100?(s.fg&=-67108864,s.fg|=ue.fg&16777215,s.bg&=-67108864,s.bg|=ue.bg&16777215):this._logService.debug("Unknown SGR attribute: %d.",i);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${x.ESC}[0n`);break;case 6:let t=this._activeBuffer.y+1,i=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${x.ESC}[${t};${i}R`);break}return!0}deviceStatusPrivate(e){if(e.params[0]===6){let t=this._activeBuffer.y+1,i=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${x.ESC}[?${t};${i}R`)}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=ue.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle="block";break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle="underline";break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle="bar";break}let i=t%2===1;this._coreService.decPrivateModes.cursorBlink=i}return!0}setScrollRegion(e){let t=e.params[0]||1,i;return(e.length<2||(i=e.params[1])>this._bufferService.rows||i===0)&&(i=this._bufferService.rows),i>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=i-1,this._setCursor(0,0)),!0}windowOptions(e){if(!oa(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${x.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>na&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>na&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],i=e.split(";");for(;i.length>1;){let s=i.shift(),r=i.shift();if(/^\d+$/.exec(s)){let n=parseInt(s);if(ha(n))if(r==="?")t.push({type:0,index:n});else{let o=ra(r);o&&t.push({type:1,index:n,color:o})}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(";");if(t===-1)return!0;let i=e.slice(0,t).trim(),s=e.slice(t+1);return s?this._createHyperlink(i,s):i.trim()?!1:this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let i=e.split(":"),s,r=i.findIndex(n=>n.startsWith("id="));return r!==-1&&(s=i[r].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:s,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let i=e.split(";");for(let s=0;s<i.length&&!(t>=this._specialColors.length);++s,++t)if(i[s]==="?")this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=ra(i[s]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],i=e.split(";");for(let s=0;s<i.length;++s)if(/^\d+$/.exec(i[s])){let r=parseInt(i[s]);ha(r)&&t.push({type:2,index:r})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,Xt),!0}selectCharset(e){return e.length!==2?(this.selectDefaultCharset(),!0):(e[0]==="/"||this._charsetService.setgCharset(Ap[e[0]],be[e[1]]||Xt),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=ue.clone(),this._eraseAttrDataInternal=ue.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new ct;e.content=1<<22|69,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let i=this._activeBuffer.ybase+this._activeBuffer.y+t,s=this._activeBuffer.lines.get(i);s&&(s.fill(e),s.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let i=o=>(this._coreService.triggerDataEvent(`${x.ESC}${o}${x.ESC}\\`),!0),s=this._bufferService.buffer,r=this._optionsService.rawOptions;return i(e==='"q'?`P1$r${this._curAttrData.isProtected()?1:0}"q`:e==='"p'?'P1$r61;1"p':e==="r"?`P1$r${s.scrollTop+1};${s.scrollBottom+1}r`:e==="m"?"P1$r0m":e===" q"?`P1$r${{block:2,underline:4,bar:6}[r.cursorStyle]-(r.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},pn=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(la=e,e=t,t=la),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};pn=ce([L(0,Ge)],pn);function ha(e){return 0<=e&&e<256}var kp=5e7,ca=12,Mp=50,Dp=class extends W{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new k),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let i;for(;i=this._writeBuffer.shift();){this._action(i);let s=this._callbacks.shift();s&&s()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>kp)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let i=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let s=this._writeBuffer[this._bufferOffset],r=this._action(s,t);if(r){let o=a=>performance.now()-i>=ca?setTimeout(()=>this._innerWrite(0,a)):this._innerWrite(i,a);r.catch(a=>(queueMicrotask(()=>{throw a}),Promise.resolve(!1))).then(o);return}let n=this._callbacks[this._bufferOffset];if(n&&n(),this._bufferOffset++,this._pendingData-=s.length,performance.now()-i>=ca)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>Mp&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout(()=>this._innerWrite())):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},mn=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let a=t.addMarker(t.ybase+t.y),l={data:e,id:this._nextId++,lines:[a]};return a.onDispose(()=>this._removeMarkerFromLink(l,a)),this._dataByLinkId.set(l.id,l),l.id}let i=e,s=this._getEntryIdKey(i),r=this._entriesWithId.get(s);if(r)return this.addLineToLink(r.id,t.ybase+t.y),r.id;let n=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(i),data:i,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(o,n)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let i=this._dataByLinkId.get(e);if(i&&i.lines.every(s=>s.line!==t)){let s=this._bufferService.buffer.addMarker(t);i.lines.push(s),s.onDispose(()=>this._removeMarkerFromLink(i,s))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let i=e.lines.indexOf(t);i!==-1&&(e.lines.splice(i,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};mn=ce([L(0,Ge)],mn);var da=!1,Tp=class extends W{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new ui),this._onBinary=this._register(new k),this.onBinary=this._onBinary.event,this._onData=this._register(new k),this.onData=this._onData.event,this._onLineFeed=this._register(new k),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new k),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new k),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new k),this._instantiationService=new ip,this.optionsService=this._register(new up(e)),this._instantiationService.setService(We,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(dn)),this._instantiationService.setService(Ge,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(cn)),this._instantiationService.setService(Sl,this._logService),this.coreService=this._register(this._instantiationService.createInstance(un)),this._instantiationService.setService(ri,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(_n)),this._instantiationService.setService(vl,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(Qt)),this._instantiationService.setService(Qu,this.unicodeService),this._charsetService=this._instantiationService.createInstance(gp),this._instantiationService.setService(Xu,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(mn),this._instantiationService.setService(bl,this._oscLinkService),this._inputHandler=this._register(new Pp(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(Be.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(Be.forward(this._bufferService.onResize,this._onResize)),this._register(Be.forward(this.coreService.onData,this._onData)),this._register(Be.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange(["windowsMode","windowsPty"],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new Dp((t,i)=>this._inputHandler.parse(t,i))),this._register(Be.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new k),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!da&&(this._logService.warn("writeSync is unreliable and will be removed soon."),da=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,Zl),t=Math.max(t,Jl),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend==="conpty"&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(ia.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:"H"},()=>(ia(this._bufferService),!1))),this._windowsWrappingHeuristics.value=ne(()=>{for(let t of e)t.dispose()})}}},Rp={48:["0",")"],49:["1","!"],50:["2","@"],51:["3","#"],52:["4","$"],53:["5","%"],54:["6","^"],55:["7","&"],56:["8","*"],57:["9","("],186:[";",":"],187:["=","+"],188:[",","<"],189:["-","_"],190:[".",">"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"']};function Lp(e,t,i,s){let r={type:0,cancel:!1,key:void 0},n=(e.shiftKey?1:0)|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key==="UIKeyInputUpArrow"?t?r.key=x.ESC+"OA":r.key=x.ESC+"[A":e.key==="UIKeyInputLeftArrow"?t?r.key=x.ESC+"OD":r.key=x.ESC+"[D":e.key==="UIKeyInputRightArrow"?t?r.key=x.ESC+"OC":r.key=x.ESC+"[C":e.key==="UIKeyInputDownArrow"&&(t?r.key=x.ESC+"OB":r.key=x.ESC+"[B");break;case 8:r.key=e.ctrlKey?"\b":x.DEL,e.altKey&&(r.key=x.ESC+r.key);break;case 9:if(e.shiftKey){r.key=x.ESC+"[Z";break}r.key=x.HT,r.cancel=!0;break;case 13:r.key=e.altKey?x.ESC+x.CR:x.CR,r.cancel=!0;break;case 27:r.key=x.ESC,e.altKey&&(r.key=x.ESC+x.ESC),r.cancel=!0;break;case 37:if(e.metaKey)break;n?r.key=x.ESC+"[1;"+(n+1)+"D":t?r.key=x.ESC+"OD":r.key=x.ESC+"[D";break;case 39:if(e.metaKey)break;n?r.key=x.ESC+"[1;"+(n+1)+"C":t?r.key=x.ESC+"OC":r.key=x.ESC+"[C";break;case 38:if(e.metaKey)break;n?r.key=x.ESC+"[1;"+(n+1)+"A":t?r.key=x.ESC+"OA":r.key=x.ESC+"[A";break;case 40:if(e.metaKey)break;n?r.key=x.ESC+"[1;"+(n+1)+"B":t?r.key=x.ESC+"OB":r.key=x.ESC+"[B";break;case 45:!e.shiftKey&&!e.ctrlKey&&(r.key=x.ESC+"[2~");break;case 46:n?r.key=x.ESC+"[3;"+(n+1)+"~":r.key=x.ESC+"[3~";break;case 36:n?r.key=x.ESC+"[1;"+(n+1)+"H":t?r.key=x.ESC+"OH":r.key=x.ESC+"[H";break;case 35:n?r.key=x.ESC+"[1;"+(n+1)+"F":t?r.key=x.ESC+"OF":r.key=x.ESC+"[F";break;case 33:e.shiftKey?r.type=2:e.ctrlKey?r.key=x.ESC+"[5;"+(n+1)+"~":r.key=x.ESC+"[5~";break;case 34:e.shiftKey?r.type=3:e.ctrlKey?r.key=x.ESC+"[6;"+(n+1)+"~":r.key=x.ESC+"[6~";break;case 112:n?r.key=x.ESC+"[1;"+(n+1)+"P":r.key=x.ESC+"OP";break;case 113:n?r.key=x.ESC+"[1;"+(n+1)+"Q":r.key=x.ESC+"OQ";break;case 114:n?r.key=x.ESC+"[1;"+(n+1)+"R":r.key=x.ESC+"OR";break;case 115:n?r.key=x.ESC+"[1;"+(n+1)+"S":r.key=x.ESC+"OS";break;case 116:n?r.key=x.ESC+"[15;"+(n+1)+"~":r.key=x.ESC+"[15~";break;case 117:n?r.key=x.ESC+"[17;"+(n+1)+"~":r.key=x.ESC+"[17~";break;case 118:n?r.key=x.ESC+"[18;"+(n+1)+"~":r.key=x.ESC+"[18~";break;case 119:n?r.key=x.ESC+"[19;"+(n+1)+"~":r.key=x.ESC+"[19~";break;case 120:n?r.key=x.ESC+"[20;"+(n+1)+"~":r.key=x.ESC+"[20~";break;case 121:n?r.key=x.ESC+"[21;"+(n+1)+"~":r.key=x.ESC+"[21~";break;case 122:n?r.key=x.ESC+"[23;"+(n+1)+"~":r.key=x.ESC+"[23~";break;case 123:n?r.key=x.ESC+"[24;"+(n+1)+"~":r.key=x.ESC+"[24~";break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?r.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?r.key=x.NUL:e.keyCode>=51&&e.keyCode<=55?r.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?r.key=x.DEL:e.keyCode===219?r.key=x.ESC:e.keyCode===220?r.key=x.FS:e.keyCode===221&&(r.key=x.GS);else if((!i||s)&&e.altKey&&!e.metaKey){let o=Rp[e.keyCode]?.[e.shiftKey?1:0];if(o)r.key=x.ESC+o;else if(e.keyCode>=65&&e.keyCode<=90){let a=e.ctrlKey?e.keyCode-64:e.keyCode+32,l=String.fromCharCode(a);e.shiftKey&&(l=l.toUpperCase()),r.key=x.ESC+l}else if(e.keyCode===32)r.key=x.ESC+(e.ctrlKey?x.NUL:" ");else if(e.key==="Dead"&&e.code.startsWith("Key")){let a=e.code.slice(3,4);e.shiftKey||(a=a.toLowerCase()),r.key=x.ESC+a,r.cancel=!0}}else i&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(r.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?r.key=e.key:e.key&&e.ctrlKey&&(e.key==="_"&&(r.key=x.US),e.key==="@"&&(r.key=x.NUL));break}return r}var de=0,Np=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Is,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Is,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((r,n)=>this._getKey(r)-this._getKey(n)),t=0,i=0,s=new Array(this._array.length+this._insertedValues.length);for(let r=0;r<s.length;r++)i>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[i])?(s[r]=e[t],t++):s[r]=this._array[i++];this._array=s,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(de=this._search(t),de===-1)||this._getKey(this._array[de])!==t)return!1;do if(this._array[de]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(de),!0;while(++de<this._array.length&&this._getKey(this._array[de])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((r,n)=>r-n),t=0,i=new Array(this._array.length-e.length),s=0;for(let r=0;r<this._array.length;r++)e[t]===r?t++:i[s++]=this._array[r];this._array=i,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(de=this._search(e),!(de<0||de>=this._array.length)&&this._getKey(this._array[de])===e))do yield this._array[de];while(++de<this._array.length&&this._getKey(this._array[de])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(de=this._search(e),!(de<0||de>=this._array.length)&&this._getKey(this._array[de])===e))do t(this._array[de]);while(++de<this._array.length&&this._getKey(this._array[de])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,i=this._array.length-1;for(;i>=t;){let s=t+i>>1,r=this._getKey(this._array[s]);if(r>e)i=s-1;else if(r<e)t=s+1;else{for(;s>0&&this._getKey(this._array[s-1])===e;)s--;return s}}return t}},Ir=0,ua=0,Bp=class extends W{constructor(){super(),this._decorations=new Np(e=>e?.marker.line),this._onDecorationRegistered=this._register(new k),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new k),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(ne(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new Op(e);if(t){let i=t.marker.onDispose(()=>t.dispose()),s=t.onDispose(()=>{s.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),i.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,i){let s=0,r=0;for(let n of this._decorations.getKeyIterator(t))s=n.options.x??0,r=s+(n.options.width??1),e>=s&&e<r&&(!i||(n.options.layer??"bottom")===i)&&(yield n)}forEachDecorationAtCell(e,t,i,s){this._decorations.forEachByKey(t,r=>{Ir=r.options.x??0,ua=Ir+(r.options.width??1),e>=Ir&&e<ua&&(!i||(r.options.layer??"bottom")===i)&&s(r)})}},Op=class extends zt{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new k),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new k),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=ae.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=ae.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},Up=1e3,Fp=class{constructor(e,t=Up){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,i){this._rowCount=i,e=e!==void 0?e:0,t=t!==void 0?t:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,e):e,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,t):t;let s=performance.now();if(s-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=s,this._innerRefresh();else if(!this._additionalRefreshRequested){let r=s-this._lastRefreshMs,n=this._debounceThresholdMS-r;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},n)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},_a=20,As=class extends W{constructor(e,t,i,s){super(),this._terminal=e,this._coreBrowserService=i,this._renderService=s,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="";let r=this._coreBrowserService.mainDocument;this._accessibilityContainer=r.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=r.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let n=0;n<this._terminal.rows;n++)this._rowElements[n]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[n]);if(this._topBoundaryFocusListener=n=>this._handleBoundaryFocus(n,0),this._bottomBoundaryFocusListener=n=>this._handleBoundaryFocus(n,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=r.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new Fp(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this._register(this._terminal.onResize(n=>this._handleResize(n.rows))),this._register(this._terminal.onRender(n=>this._refreshRows(n.start,n.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(n=>this._handleChar(n))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
`))),this._register(this._terminal.onA11yTab(n=>this._handleTab(n))),this._register(this._terminal.onKey(n=>this._handleKey(n.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(K(r,"selectionchange",()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(ne(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(" ")}_handleChar(e){this._liveRegionLineCount<_a+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===_a+1&&(this._liveRegion.textContent+=Nr.get())))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let i=this._terminal.buffer,s=i.lines.length.toString();for(let r=e;r<=t;r++){let n=i.lines.get(i.ydisp+r),o=[],a=n?.translateToString(!0,void 0,void 0,o)||"",l=(i.ydisp+r+1).toString(),c=this._rowElements[r];c&&(a.length===0?(c.textContent=" ",this._rowColumns.set(c,[0,1])):(c.textContent=a,this._rowColumns.set(c,o)),c.setAttribute("aria-posinset",l),c.setAttribute("aria-setsize",s),this._alignRowWidth(c))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(e,t){let i=e.target,s=this._rowElements[t===0?1:this._rowElements.length-2],r=i.getAttribute("aria-posinset"),n=t===0?"1":`${this._terminal.buffer.lines.length}`;if(r===n||e.relatedTarget!==s)return;let o,a;if(t===0?(o=i,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(o=this._rowElements.shift(),a=i,this._rowContainer.removeChild(o)),o.removeEventListener("focus",this._topBoundaryFocusListener),a.removeEventListener("focus",this._bottomBoundaryFocusListener),t===0){let l=this._createAccessibilityTreeNode();this._rowElements.unshift(l),this._rowContainer.insertAdjacentElement("afterbegin",l)}else{let l=this._createAccessibilityTreeNode();this._rowElements.push(l),this._rowContainer.appendChild(l)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error("anchorNode and/or focusNode are null");return}let t={node:e.anchorNode,offset:e.anchorOffset},i={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(i.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===i.node&&t.offset>i.offset)&&([t,i]=[i,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let s=this._rowElements.slice(-1)[0];if(i.node.compareDocumentPosition(s)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(i={node:s,offset:s.textContent?.length??0}),!this._rowContainer.contains(i.node))return;let r=({node:a,offset:l})=>{let c=a instanceof Text?a.parentNode:a,d=parseInt(c?.getAttribute("aria-posinset"),10)-1;if(isNaN(d))return console.warn("row is invalid. Race condition?"),null;let p=this._rowColumns.get(c);if(!p)return console.warn("columns is null. Race condition?"),null;let f=l<p.length?p[l]:p.slice(-1)[0]+1;return f>=this._terminal.cols&&(++d,f=0),{row:d,column:f}},n=r(t),o=r(i);if(!(!n||!o)){if(n.row>o.row||n.row===o.row&&n.column>=o.column)throw new Error("invalid range");this._terminal.select(n.column,n.row,(o.row-n.row)*this._terminal.cols-n.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let t=this._rowContainer.children.length;t<this._terminal.rows;t++)this._rowElements[t]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[t]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement("div");return e.setAttribute("role","listitem"),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform="";let t=e.getBoundingClientRect().width,i=this._rowColumns.get(e)?.slice(-1)?.[0];if(!i)return;let s=i*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${s/t})`}};As=ce([L(1,Mn),L(2,Mt),L(3,Dt)],As);var gn=class extends W{constructor(e,t,i,s,r){super(),this._element=e,this._mouseService=t,this._renderService=i,this._bufferService=s,this._linkProviderService=r,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new k),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new k),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(ne(()=>{ei(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(K(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(K(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(K(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(K(this._element,"mouseup",this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let i=e.composedPath();for(let s=0;s<i.length;s++){let r=i[s];if(r.classList.contains("xterm"))break;if(r.classList.contains("xterm-hover"))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(s=>{s?.forEach(r=>{r.link.dispose&&r.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let i=!1;for(let[s,r]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(s)&&(i=this._checkLinkProviderResult(s,e,i)):r.provideLinks(e.y,n=>{if(this._isMouseOut)return;let o=n?.map(a=>({link:a}));this._activeProviderReplies?.set(s,o),i=this._checkLinkProviderResult(s,e,i),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let i=new Set;for(let s=0;s<t.size;s++){let r=t.get(s);if(r)for(let n=0;n<r.length;n++){let o=r[n],a=o.link.range.start.y<e?0:o.link.range.start.x,l=o.link.range.end.y>e?this._bufferService.cols:o.link.range.end.x;for(let c=a;c<=l;c++){if(i.has(c)){r.splice(n--,1);break}i.add(c)}}}}_checkLinkProviderResult(e,t,i){if(!this._activeProviderReplies)return i;let s=this._activeProviderReplies.get(e),r=!1;for(let n=0;n<e;n++)(!this._activeProviderReplies.has(n)||this._activeProviderReplies.get(n))&&(r=!0);if(!r&&s){let n=s.find(o=>this._linkAtPosition(o.link,t));n&&(i=!0,this._handleNewLink(n))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!i)for(let n=0;n<this._activeProviderReplies.size;n++){let o=this._activeProviderReplies.get(n)?.find(a=>this._linkAtPosition(a.link,t));if(o){i=!0,this._handleNewLink(o);break}}return i}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&jp(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,ei(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0?!0:e.link.decorations.underline,pointerCursor:e.link.decorations===void 0?!0:e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:i=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==i&&(this._currentLink.state.decorations.pointerCursor=i,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",i))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:i=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==i&&(this._currentLink.state.decorations.underline=i,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,i))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(i=>{if(!this._currentLink)return;let s=i.start===0?0:i.start+1+this._bufferService.buffer.ydisp,r=this._bufferService.buffer.ydisp+1+i.end;if(this._currentLink.link.range.start.y>=s&&this._currentLink.link.range.end.y<=r&&(this._clearCurrentLink(s,r),this._lastMouseEvent)){let n=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);n&&this._askForLink(n,!1)}})))}_linkHover(e,t,i){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add("xterm-cursor-pointer")),t.hover&&t.hover(i,t.text)}_fireUnderlineEvent(e,t){let i=e.range,s=this._bufferService.buffer.ydisp,r=this._createLinkUnderlineEvent(i.start.x-1,i.start.y-s-1,i.end.x,i.end.y-s-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(r)}_linkLeave(e,t,i){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove("xterm-cursor-pointer")),t.leave&&t.leave(i,t.text)}_linkAtPosition(e,t){let i=e.range.start.y*this._bufferService.cols+e.range.start.x,s=e.range.end.y*this._bufferService.cols+e.range.end.x,r=t.y*this._bufferService.cols+t.x;return i<=r&&r<=s}_positionFromMouseEvent(e,t,i){let s=i.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(s)return{x:s[0],y:s[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,i,s,r){return{x1:e,y1:t,x2:i,y2:s,cols:this._bufferService.cols,fg:r}}};gn=ce([L(1,Dn),L(2,Dt),L(3,Ge),L(4,Cl)],gn);function jp(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var Kp=class extends Tp{constructor(e={}){super(e),this._linkifier=this._register(new ui),this.browser=Kl,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new ui),this._onCursorMove=this._register(new k),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new k),this.onKey=this._onKey.event,this._onRender=this._register(new k),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new k),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new k),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new k),this.onBell=this._onBell.event,this._onFocus=this._register(new k),this._onBlur=this._register(new k),this._onA11yCharEmitter=this._register(new k),this._onA11yTabEmitter=this._register(new k),this._onWillOpen=this._register(new k),this._setup(),this._decorationService=this._instantiationService.createInstance(Bp),this._instantiationService.setService(Qi,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(Mf),this._instantiationService.setService(Cl,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Or)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(t=>this.refresh(t?.start??0,t?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(t=>this._reportWindowsOptions(t))),this._register(this._inputHandler.onColor(t=>this._handleColorEvent(t))),this._register(Be.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(Be.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(Be.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(Be.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(t=>this._afterResize(t.cols,t.rows))),this._register(ne(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let i,s="";switch(t.index){case 256:i="foreground",s="10";break;case 257:i="background",s="11";break;case 258:i="cursor",s="12";break;default:i="ansi",s="4;"+t.index}switch(t.type){case 0:let r=re.toColorRGB(i==="ansi"?this._themeService.colors.ansi[t.index]:this._themeService.colors[i]);this.coreService.triggerDataEvent(`${x.ESC}]${s};${Ip(r)}${Fl.ST}`);break;case 1:if(i==="ansi")this._themeService.modifyColors(n=>n.ansi[t.index]=_e.toColor(...t.color));else{let n=i;this._themeService.modifyColors(o=>o[n]=_e.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index);break}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(As,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(x.ESC+"[I"),this.element.classList.add("focus"),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value="",this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(x.ESC+"[O"),this.element.classList.remove("focus"),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let i=Math.min(this.buffer.x,this.cols-1),s=this._renderService.dimensions.css.cell.height,r=t.getWidth(i),n=this._renderService.dimensions.css.cell.width*r,o=this.buffer.y*this._renderService.dimensions.css.cell.height,a=i*this._renderService.dimensions.css.cell.width;this.textarea.style.left=a+"px",this.textarea.style.top=o+"px",this.textarea.style.width=n+"px",this.textarea.style.height=s+"px",this.textarea.style.lineHeight=s+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this._register(K(this.element,"copy",t=>{this.hasSelection()&&Hu(t,this._selectionService)}));let e=t=>Gu(t,this.textarea,this.coreService,this.optionsService);this._register(K(this.textarea,"paste",e)),this._register(K(this.element,"paste",e)),zl?this._register(K(this.element,"mousedown",t=>{t.button===2&&wo(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(K(this.element,"contextmenu",t=>{wo(t,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Fn&&this._register(K(this.element,"auxclick",t=>{t.button===1&&_l(t,this.textarea,this.screenElement)}))}_bindKeys(){this._register(K(this.textarea,"keyup",e=>this._keyUp(e),!0)),this._register(K(this.textarea,"keydown",e=>this._keyDown(e),!0)),this._register(K(this.textarea,"keypress",e=>this._keyPress(e),!0)),this._register(K(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(K(this.textarea,"compositionupdate",e=>this._compositionHelper.compositionupdate(e))),this._register(K(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(K(this.textarea,"input",e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw new Error("Terminal requires a parent element.");if(e.isConnected||this._logService.debug("Terminal.open was called on an element that was not attached to the DOM"),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement("div"),this.element.dir="ltr",this.element.classList.add("terminal"),this.element.classList.add("xterm"),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement("div"),this._viewportElement.classList.add("xterm-viewport"),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement("div"),this.screenElement.classList.add("xterm-screen"),this._register(K(this.screenElement,"mousemove",r=>this.updateCursorStyle(r))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let i=this.textarea=this._document.createElement("textarea");this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",Lr.get()),Gl||this.textarea.setAttribute("aria-multiline","false"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange("disableStdin",()=>i.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(Pf,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(Mt,this._coreBrowserService),this._register(K(this.textarea,"focus",r=>this._handleTextAreaFocus(r))),this._register(K(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(nn,this._document,this._helperContainer),this._instantiationService.setService(Vs,this._charSizeService),this._themeService=this._instantiationService.createInstance(hn),this._instantiationService.setService(pi,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Es),this._instantiationService.setService(yl,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(an,this.rows,this.screenElement)),this._instantiationService.setService(Dt,this._renderService),this._register(this._renderService.onRenderedViewportChange(r=>this._onRender.fire(r))),this.onResize(r=>this._renderService.resize(r.cols,r.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(tn,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(on),this._instantiationService.setService(Dn,this._mouseService);let s=this._linkifier.value=this._register(this._instantiationService.createInstance(gn,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(Jr,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(r=>{super.scrollLines(r,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(ln,this.element,this.screenElement,s)),this._instantiationService.setService(Ju,this._selectionService),this._register(this._selectionService.onRequestScrollLines(r=>this.scrollLines(r.amount,r.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(r=>this._renderService.handleSelectionChanged(r.start,r.end,r.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(r=>{this.textarea.value=r,this.textarea.focus(),this.textarea.select()})),this._register(Be.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(en,this.screenElement)),this._register(K(this.element,"mousedown",r=>this._selectionService.handleMouseDown(r))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add("enable-mouse-events")):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(As,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",r=>this._handleScreenReaderModeOptionChange(r))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(ws,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",r=>{!this._overviewRulerRenderer&&r&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(ws,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(rn,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function i(n){let o=e._mouseService.getMouseReportCoords(n,e.screenElement);if(!o)return!1;let a,l;switch(n.overrideType||n.type){case"mousemove":l=32,n.buttons===void 0?(a=3,n.button!==void 0&&(a=n.button<3?n.button:3)):a=n.buttons&1?0:n.buttons&4?1:n.buttons&2?2:3;break;case"mouseup":l=0,a=n.button<3?n.button:3;break;case"mousedown":l=1,a=n.button<3?n.button:3;break;case"wheel":if(e._customWheelEventHandler&&e._customWheelEventHandler(n)===!1)return!1;let c=n.deltaY;if(c===0||e.coreMouseService.consumeWheelEvent(n,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;l=c<0?0:1,a=4;break;default:return!1}return l===void 0||a===void 0||a>4?!1:e.coreMouseService.triggerMouseEvent({col:o.col,row:o.row,x:o.x,y:o.y,button:a,action:l,ctrl:n.ctrlKey,alt:n.altKey,shift:n.shiftKey})}let s={mouseup:null,wheel:null,mousedrag:null,mousemove:null},r={mouseup:n=>(i(n),n.buttons||(this._document.removeEventListener("mouseup",s.mouseup),s.mousedrag&&this._document.removeEventListener("mousemove",s.mousedrag)),this.cancel(n)),wheel:n=>(i(n),this.cancel(n,!0)),mousedrag:n=>{n.buttons&&i(n)},mousemove:n=>{n.buttons||i(n)}};this._register(this.coreMouseService.onProtocolChange(n=>{n?(this.optionsService.rawOptions.logLevel==="debug"&&this._logService.debug("Binding to mouse events:",this.coreMouseService.explainEvents(n)),this.element.classList.add("enable-mouse-events"),this._selectionService.disable()):(this._logService.debug("Unbinding from mouse events."),this.element.classList.remove("enable-mouse-events"),this._selectionService.enable()),n&8?s.mousemove||(t.addEventListener("mousemove",r.mousemove),s.mousemove=r.mousemove):(t.removeEventListener("mousemove",s.mousemove),s.mousemove=null),n&16?s.wheel||(t.addEventListener("wheel",r.wheel,{passive:!1}),s.wheel=r.wheel):(t.removeEventListener("wheel",s.wheel),s.wheel=null),n&2?s.mouseup||(s.mouseup=r.mouseup):(this._document.removeEventListener("mouseup",s.mouseup),s.mouseup=null),n&4?s.mousedrag||(s.mousedrag=r.mousedrag):(this._document.removeEventListener("mousemove",s.mousedrag),s.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(K(t,"mousedown",n=>{if(n.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(n)))return i(n),s.mouseup&&this._document.addEventListener("mouseup",s.mouseup),s.mousedrag&&this._document.addEventListener("mousemove",s.mousedrag),this.cancel(n)})),this._register(K(t,"wheel",n=>{if(!s.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(n)===!1)return!1;if(!this.buffer.hasScrollback){if(n.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(n,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(n,!0);let o=x.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(n.deltaY<0?"A":"B");return this.coreService.triggerDataEvent(o,!0),this.cancel(n,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add("column-select"):this.element.classList.remove("column-select")}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){ul(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,i){this._selectionService.setSelection(e,t,i)}getSelection(){return this._selectionService?this._selectionService.selectionText:""}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key==="Dead"||e.key==="AltGraph")&&(this._unprocessedDeadKey=!0);let i=Lp(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),i.type===3||i.type===2){let s=this.rows-1;return this.scrollLines(i.type===2?-s:s),this.cancel(e,!0)}if(i.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(i.cancel&&this.cancel(e,!0),!i.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((i.key===x.ETX||i.key===x.CR)&&(this.textarea.value=""),this._onKey.fire({key:i.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(i.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let i=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState("AltGraph");return t.type==="keypress"?i:i&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(zp(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType==="insertText"&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(!(this.buffer.ybase===0&&this.buffer.y===0)){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(ue));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains("focus")?this.coreService.triggerDataEvent(x.ESC+"[I"):this.coreService.triggerDataEvent(x.ESC+"[O")}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let t=this._renderService.dimensions.css.canvas.width.toFixed(0),i=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${x.ESC}[4;${i};${t}t`);break;case 1:let s=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${x.ESC}[6;${r};${s}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function zp(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var Yp=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let i={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(i),t.dispose=()=>this._wrappedAddonDispose(i),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let i=0;i<this._addons.length;i++)if(this._addons[i]===e){t=i;break}if(t===-1)throw new Error("Could not dispose an addon that has not been loaded");e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},Hp=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new ct)}translateToString(e,t,i){return this._line.translateToString(e,t,i)}},fa=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new Hp(t)}getNullCell(){return new ct}},Gp=class extends W{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new k),this.onBufferChange=this._onBufferChange.event,this._normal=new fa(this._core.buffers.normal,"normal"),this._alternate=new fa(this._core.buffers.alt,"alternate"),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw new Error("Active buffer is neither normal nor alternate")}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},Wp=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,i=>t(i.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(i,s)=>t(i,s.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},$p=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},Vp=["cols","rows"],gt=0,qp=class extends W{constructor(e){super(),this._core=this._register(new Kp(e)),this._addonManager=this._register(new Yp),this._publicOptions={...this._core.options};let t=s=>this._core.options[s],i=(s,r)=>{this._checkReadonlyOptions(s),this._core.options[s]=r};for(let s in this._core.options){let r={get:t.bind(this,s),set:i.bind(this,s)};Object.defineProperty(this._publicOptions,s,r)}}_checkReadonlyOptions(e){if(Vp.includes(e))throw new Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw new Error("You must set the allowProposedApi option to true to use proposed API")}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||(this._parser=new Wp(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new $p(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||(this._buffer=this._register(new Gp(this._core))),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t="none";switch(this._core.coreMouseService.activeProtocol){case"X10":t="x10";break;case"VT200":t="vt200";break;case"DRAG":t="drag";break;case"ANY":t="any";break}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,i){this._verifyIntegers(e,t,i),this._core.select(e,t,i)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return Lr.get()},set promptLabel(e){Lr.set(e)},get tooMuchOutput(){return Nr.get()},set tooMuchOutput(e){Nr.set(e)}}}_verifyIntegers(...e){for(gt of e)if(gt===1/0||isNaN(gt)||gt%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...e){for(gt of e)if(gt&&(gt===1/0||isNaN(gt)||gt%1!==0||gt<0))throw new Error("This API only accepts positive integers")}};const th=O.forwardRef(function({options:t={},addons:i,className:s,onBinary:r,onCursorMove:n,onData:o,onKey:a,onLineFeed:l,onScroll:c,onSelectionChange:d,onRender:p,onResize:f,onTitleChange:g,customKeyEventHandler:u,onOpen:_},S){const[v,P]=O.useState(!1),w=O.useRef(null),E=O.useRef(new qp(t));O.useImperativeHandle(S,()=>E.current);const D=()=>{i&&i.forEach(N=>{E.current?.loadAddon(N)}),r&&E.current.onBinary(r),n&&E.current.onCursorMove(n),o&&E.current.onData(o),a&&E.current.onKey(a),l&&E.current.onLineFeed(l),c&&E.current.onScroll(c),d&&E.current.onSelectionChange(d),p&&E.current.onRender(p),f&&E.current.onResize(f),g&&E.current.onTitleChange(g),u&&E.current.attachCustomKeyEventHandler(u)};return O.useEffect(()=>{const N=w.current;return N&&(D(),E.current?.open(N),P(!0)),()=>{E.current?.dispose()}},[]),O.useLayoutEffect(()=>{v&&_&&_()},[v]),h.jsx("div",{className:s,ref:w})}),Xp={theme:{background:"#292c2f"}},Qp={command:"su -l",environment:[{key:"TERM",value:"xterm-256color"},{key:"HOME",value:"/root"},{key:"PATH",value:"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/run/current-system/sw/bin"},{key:"LANG",value:"C.UTF-8"},{key:"USER",value:"root"}],user:0,group:0},ih="user.ui_terminal_default_payload",Zp=e=>{const t=e.config[ih];return t?JSON.parse(t):Qp},Jp=({instance:e,refreshInstance:t})=>{const{name:i,project:s}=si(),r=new TextEncoder,n=b.useNotify(),[o,a]=O.useState(!1),[l,c]=O.useState(null),[d,p]=O.useState(null),[f,g]=O.useState(Zp(e)),[u]=O.useState(new cl),[_,S]=O.useState(!1),v=O.useRef(null),P=O.useRef(null),[w,E]=O.useState(0),{canUpdateInstanceState:D,canExecInstance:N}=pt();Ya({when:_,message:"Are you sure you want to leave this page?"});const U=H=>{_&&(H.returnValue="Are you sure you want to leave this page?")};b.useListener(window,U,"beforeunload");const X=async H=>{if(!i){n.failure("Missing name",new Error);return}if(!s){n.failure("Missing project",new Error);return}a(!0);const se=await Qc(i,s,H).catch(te=>{a(!1),n.failure("Connection failed",te)});if(!se)return;const we=se.operation.split("?")[0],Ve=location.protocol==="https:"?"wss":"ws",tt=`${Ve}://${location.host}${ee}${we}/websocket?secret=${se.metadata.metadata.fds[0]}`,Ue=`${Ve}://${location.host}${ee}${we}/websocket?secret=${se.metadata.metadata.fds.control}`,Ee=new WebSocket(tt),xe=new WebSocket(Ue);return xe.onopen=()=>{a(!1),p(xe)},xe.onerror=te=>{n.failure("Error",te)},xe.onclose=te=>{te.code!==1005&&n.failure("Error",te.reason,Ki(te.code)),p(null)},Ee.onopen=()=>{c(Ee)},Ee.onerror=te=>{n.failure("Error",te)},Ee.onclose=te=>{te.code!==1005&&n.failure("Error",te.reason,Ki(te.code)),c(null),S(!1)},Ee.binaryType="arraybuffer",Ee.onmessage=te=>{const Ci=te.origin===`${Ve}://${location.host}`;te.isTrusted&&Ci?v.current?.write(new Uint8Array(te.data)):console.error("Ignoring untrusted message",te)},[Ee,xe]},ie=Ys(e),Oe=ie&&(e.state?.processes??0)<1,V=ie&&!Oe,R=N(e);O.useEffect(()=>{if(Oe&&P.current===null){const we=setTimeout(()=>{t(),P.current=null,E(Ve=>Ve+1)},1e3);return P.current=we,()=>{clearTimeout(we)}}else return()=>{}},[Oe,w]),O.useEffect(()=>{if(v.current?.clear(),n.clear(),V&&R){const H=X(f);return()=>{H.then(se=>{se?.map(we=>{we.close()})})}}else return()=>{}},[f,e.status,V,R]);const I=()=>{if(d?.readyState===WebSocket.CLOSED)return;fi("p-terminal",void 0,10),v.current?.element?.style.setProperty("padding","1rem"),u.fit();const H=u.proposeDimensions();d?.send(r.encode(JSON.stringify({command:"window-resize",args:{height:H?.rows.toString(),width:H?.cols.toString()}})))};b.useListener(window,()=>{I(),setTimeout(I,500)},"resize",!0),b.useListener(window,I,"menu-collapse-toggle");const M=()=>{I(),v.current?.focus()},{handleStart:T,isLoading:F}=Ha(e);if(!R)return h.jsx(b.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to use the terminal for this instance."});const Y=!D(e)||Oe||F,B=()=>{v.current?.element?.requestFullscreen().then(I).then(()=>{v.current?.focus()}).catch(H=>{n.failure("Failed to enter full-screen mode",H)})};return h.jsxs("div",{className:"instance-terminal-tab",children:[V&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"p-panel__controls",children:[h.jsx(b.Button,{className:"u-no-margin--bottom",onClick:B,disabled:o||!d,children:"Fullscreen"}),h.jsx(Fu,{reconnect:g,payload:f,instance:e})]}),h.jsx(zs,{}),o&&h.jsx(b.Spinner,{className:"u-loader",text:"Loading terminal session..."}),d&&h.jsx(th,{ref:v,addons:[u],options:Xp,onData:H=>{S(!0),l?.send(r.encode(H))},onOpen:M,className:"p-terminal"})]}),!V&&h.jsxs(b.EmptyState,{className:"empty-state",image:h.jsx(b.Icon,{name:"pods",className:"empty-state-icon"}),title:Oe?"Instance starting":"Instance stopped",children:[h.jsx("p",{children:Oe?"Terminal will be ready once the instance has finished booting.":"Start the instance to access the terminal."}),h.jsx(b.ActionButton,{appearance:"positive",loading:F||Oe,onClick:T,disabled:Y,title:D(e)?"":"You do not have permission to start this instance.",children:"Start instance"})]})]})},em=async(e,t,i,s)=>{const r=new URLSearchParams;return r.set("project",e.project),fetch(`${ee}/1.0/instances/${encodeURIComponent(e.name)}/snapshots?${r.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,expires_at:i,stateful:s})}).then($i).then(n=>n)},sh=async(e,t)=>{const i=new URLSearchParams;return i.set("project",e.project),fetch(`${ee}/1.0/instances/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${i.toString()}`,{method:"DELETE"}).then($i).then(s=>s)},tm=async(e,t,i)=>{const s=[];return new Promise((r,n)=>{Promise.allSettled(t.map(async o=>{const a={name:o,type:"snapshot",href:`${Zc(e.name,e.project)}/snapshots`};await sh(e,{name:o}).then(l=>{i.set(l.metadata.id,()=>{Jc(s,a)},c=>{co(s,c,a)},()=>{uo(s,t.length,r)})}).catch(l=>{co(s,l instanceof Error?l.message:"",a),uo(s,t.length,r)})})).catch(n)})},im=async(e,t,i)=>{const s=new URLSearchParams;return s.set("project",e.project),fetch(`${ee}/1.0/instances/${encodeURIComponent(e.name)}?${s.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({restore:t.name,stateful:t.stateful?i:!1})}).then($i).then(r=>r)},sm=async(e,t,i)=>{const s=new URLSearchParams;return s.set("project",e.project),fetch(`${ee}/1.0/instances/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${s.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:i})}).then($i).then(r=>r)},rm=async(e,t,i)=>{const s=new URLSearchParams;return s.set("project",e.project),fetch(`${ee}/1.0/instances/${encodeURIComponent(e.name)}/snapshots/${encodeURIComponent(t.name)}?${s.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({expires_at:i})}).then($i).then(r=>r)},nm=e=>!!e.config["migration.stateful"],om=(e,t,i)=>["deduplicate","Snapshot name already in use",async s=>i&&s===i||td(s,e.project,t,`instances/${encodeURIComponent(e.name)}/snapshots`)],rh=(e,t,i)=>Ht().shape({name:Kt().test(...om(e,t,i)).matches(/^[A-Za-z0-9-_.:]+$/,{message:"Only alphanumeric characters, underscores, periods, hyphens, and colons are allowed in this field"}),expirationDate:Kt().nullable().optional().test(...tu()).test(...iu()),expirationTime:Kt().nullable().optional().test(...eu()),stateful:ed()}),Gi=({name:e,instance:t})=>h.jsx(Fi,{type:"snapshot",value:e,to:`${ee}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}/snapshots`}),am=({instance:e,snapshot:t,close:i,onSuccess:s})=>{const r=He(),n=b.useToastNotification(),o=_t(),a=O.useState(null),l=u=>{o.invalidateQueries({predicate:_=>_.queryKey[0]===ve.instances}),s(h.jsxs(h.Fragment,{children:["Snapshot ",h.jsx(Gi,{name:u,instance:e})," ","saved for instance"," ",h.jsx(ge,{instanceName:e.name,projectName:e.project}),"."]})),i()},c=(u,_)=>{const S=_?{name:_}:t,v=h.jsx(ge,{instanceName:e.name,projectName:e.project});rm(e,S,u).then(P=>{r.set(P.metadata.id,()=>{l(_??t.name)},w=>{n.failure(`Snapshot update failed for instance ${e.name}`,new Error(w),v),g.setSubmitting(!1)})}).catch(P=>{n.failure(`Snapshot update failed for instance ${e.name}`,P,v),g.setSubmitting(!1)})},d=(u,_)=>{const S=h.jsx(Gi,{name:t.name,instance:e});sm(e,t,u).then(v=>{r.set(v.metadata.id,()=>{_?c(_,u):l(u)},P=>{n.failure(`Snapshot rename failed for ${t.name}`,new Error(P),S),g.setSubmitting(!1)})}).catch(v=>{n.failure(`Snapshot rename failed for ${t.name}`,v,S),g.setSubmitting(!1)})},[p,f]=t.expires_at===Rr?[null,null]:id(new Date(t.expires_at)).slice(0,16).split(" "),g=ft({initialValues:{name:t.name,stateful:t.stateful,expirationDate:p,expirationTime:f},validateOnMount:!0,validationSchema:rh(e,a,t.name),onSubmit:u=>{const _=u.name,S=u.expirationDate&&u.expirationTime?Ga(ol(u.expirationDate,u.expirationTime)):Rr,v=_!==t.name,P=S!==t.expires_at;v&&P?d(_,S):v?d(_):c(S)}});return h.jsx(nl,{isEdit:!0,formik:g,close:i})},lm=({instance:e,snapshot:t,onSuccess:i,isDeleting:s,isRestoring:r,disabledReason:n})=>{const{openPortal:o,closePortal:a,isOpen:l,Portal:c}=b.usePortal();return h.jsxs(h.Fragment,{children:[l&&h.jsx(c,{children:h.jsx(am,{close:a,instance:e,onSuccess:i,snapshot:t})}),h.jsx(b.Button,{appearance:"base",hasIcon:!0,dense:!0,disabled:s||r||!!n,onClick:o,type:"button","aria-label":"Edit snapshot",title:n??"Edit",children:h.jsx(b.Icon,{name:"edit"})})]})},hm=({instance:e,snapshot:t,close:i})=>{const s=He(),r=b.useToastNotification(),n=_t(),o=h.jsx(Gi,{name:t.name,instance:e}),{data:a}=Vi(e.project),{canCreateImageAliases:l}=Wt(),c=()=>{const f=h.jsx(An,{to:`${ee}/ui/project/${encodeURIComponent(e.project)}/images`,children:"created"});r.success(h.jsxs(h.Fragment,{children:["Image ",f," from snapshot ",o,"."]}))},d=()=>{n.invalidateQueries({predicate:f=>f.queryKey[0]===ve.images})},p=ft({initialValues:{alias:"",isPublic:!1},validationSchema:Ht().shape({alias:Kt()}),onSubmit:f=>{const g=JSON.stringify({aliases:al(f.alias),public:f.isPublic,source:{name:`${e.name}/${t.name}`,type:"snapshot"}});Wa(g,e.project).then(u=>{r.info(h.jsxs(h.Fragment,{children:["Creation of image from snapshot ",o," started."]})),s.set(u.metadata.id,()=>{d(),c()},_=>{r.failure(`Image creation from snapshot "${t.name}" failed.`,new Error(_),o)})}).catch(u=>{r.failure(`Image creation from snapshot "${t.name}" failed.`,u,o)}).finally(()=>{i()})}});return h.jsx(b.Modal,{close:i,title:"Create image from instance snapshot",buttonRow:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:i,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:p.isSubmitting,disabled:!p.isValid||p.isSubmitting,onClick:()=>{p.submitForm()},children:"Create image"})]}),children:h.jsxs(b.Form,{onSubmit:p.handleSubmit,children:[h.jsx(b.Input,{type:"text",label:"Instance",value:e.name,disabled:!0}),h.jsx(b.Input,{type:"text",label:"Snapshot",value:t.name,disabled:!0}),h.jsx(b.Input,{...p.getFieldProps("alias"),type:"text",label:"Alias",error:p.touched.alias?p.errors.alias:null,disabled:!l(a),title:l(a)?"":"You do not have permission to create image aliases in this project"}),h.jsx(b.Input,{...p.getFieldProps("isPublic"),type:"checkbox",label:"Make the image publicly available",error:p.touched.isPublic?p.errors.isPublic:null}),h.jsx(b.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},cm=({instance:e,snapshot:t,isDeleting:i,isRestoring:s})=>{const{openPortal:r,closePortal:n,isOpen:o,Portal:a}=b.usePortal(),{data:l}=Vi(e.project),{canCreateImages:c}=Wt();return h.jsxs(h.Fragment,{children:[o&&h.jsx(a,{children:h.jsx(hm,{close:n,instance:e,snapshot:t})}),h.jsx(b.Button,{appearance:"base",hasIcon:!0,dense:!0,disabled:i||s||!c(l),onClick:r,type:"button","aria-label":"Create image",title:c(l)?"Create image":"You do not have permission to create images in this project",children:h.jsx(b.Icon,{name:"export"})})]})},dm=(e,t,i)=>{const s={name:e.instanceName,description:t.description,architecture:t.architecture,ephemeral:i.ephemeral,mode:"pull",devices:{...t.devices,root:{path:"/",type:"disk",pool:e.targetStoragePool}}},r={project:t.project,type:"copy",source:`${t.name}/${i.name}`,base_image:i.config["volatile.base_image"]??""};return i.stateful&&e.stateful&&(s.stateful=!0,r.live=!1),{...s,source:r}},um=({instance:e,snapshot:t,close:i})=>{const s=b.useToastNotification(),r=Ks(),n=O.useState(null),o=He(),{data:a=[],isLoading:l}=Hs(),{canCreateInstances:c}=Wt(),{data:d=[],isLoading:p}=$a(),{data:f=[]}=Va(e.project),g=(w,E)=>{const D=h.jsx(ge,{instanceName:w,projectName:E}),N=h.jsxs(h.Fragment,{children:["Created instance ",D,"."]});s.success(N)},u=w=>{const E=f.map(N=>N.name),D=Xa(w.name,`-${t.name}-copy`);if(E.includes(D)){let N=1;for(;E.includes(`${D}-${N}`);)N++;return`${D}-${N}`}return D},_=w=>{const E={};return w.stateful&&(w.targetProject===e.project&&(E.targetProject="Stateful instance snapshot duplication must be in a different project"),w.instanceName!==e.name&&(E.instanceName="Instance name must be the same for stateful duplication")),E},S=a.filter(c),v=S.some(w=>w.name===e.project),P=ft({initialValues:{instanceName:u(e),targetProject:v?e.project:S[0]?.name,stateful:!1,targetClusterMember:r?e.location:"",targetStoragePool:e.devices.root?.pool??d[0]?.name},enableReinitialize:!0,validate:_,validationSchema:Ht().shape({instanceName:Pn(e.project,n).required()}),onSubmit:w=>{const E=h.jsx(ge,{instanceName:e.name,projectName:e.project});qa(JSON.stringify(dm(w,e,t)),w.targetProject,w.targetClusterMember).then(D=>{s.info(h.jsxs(h.Fragment,{children:["Instance creation started for"," ",h.jsx(_s,{bold:!0,type:e.type,value:w.instanceName}),"."]})),o.set(D.metadata.id,()=>{g(w.instanceName,w.targetProject)},N=>s.failure("Instance creation failed.",new Error(N),E))}).catch(D=>{s.failure("Instance creation failed.",D,E)}).finally(()=>{i()})}});return h.jsx(b.Modal,{close:i,className:"create-instance-from-snapshot-modal",title:"Create instance from snapshot",buttonRow:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:i,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:P.isSubmitting,disabled:!P.isValid||P.isSubmitting||p||l,onClick:()=>{P.submitForm()},children:"Create"})]}),children:h.jsxs(b.Form,{onSubmit:P.handleSubmit,children:[h.jsx(b.Input,{type:"text",label:"Snapshot name",disabled:!0,value:t.name}),h.jsx(b.Input,{...P.getFieldProps("instanceName"),type:"text",label:"New instance name",error:P.errors.instanceName}),h.jsx(ll,{...P.getFieldProps("targetClusterMember"),id:"targetClusterMember",label:"Target cluster member"}),h.jsx(b.Select,{...P.getFieldProps("targetStoragePool"),id:"storagePool",label:"Storage pool",options:d.map(w=>({label:w.name,value:w.name}))}),h.jsx(b.Select,{...P.getFieldProps("targetProject"),id:"project",label:"Target project",options:S.map(w=>({label:w.name,value:w.name})),error:P.errors.targetProject}),t.stateful&&h.jsx(b.Input,{...P.getFieldProps("stateful"),type:"checkbox",label:"Copy stateful"}),h.jsx(b.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},_m=({instance:e,snapshot:t,isDeleting:i,isRestoring:s})=>{const{openPortal:r,closePortal:n,isOpen:o,Portal:a}=b.usePortal(),{data:l=[]}=Hs(),{canCreateInstances:c}=Wt(),d=l.filter(c);return h.jsxs(h.Fragment,{children:[o&&h.jsx(a,{children:h.jsx(um,{close:n,instance:e,snapshot:t})}),h.jsx(b.Button,{appearance:"base",hasIcon:!0,dense:!0,"aria-label":"Create instance",disabled:i||s||!d.length,onClick:r,title:d.length>0?"Create instance":"You do not have permission to create instances",children:h.jsx(b.Icon,{name:"plus"})})]})},fm=({instance:e,snapshot:t,onSuccess:i,onFailure:s})=>{const r=He(),[n,o]=O.useState(!1),[a,l]=O.useState(!1),[c,d]=O.useState(!0),p=_t(),{canManageInstanceSnapshots:f}=pt(),g=f(e)?void 0:"You do not have permission to manage snapshots for this instance",u=()=>{o(!0),sh(e,t).then(S=>{r.set(S.metadata.id,()=>{i(h.jsxs(h.Fragment,{children:["Snapshot"," ",h.jsx(_s,{bold:!0,type:"snapshot",value:t.name})," ","deleted for instance"," ",h.jsx(ge,{instanceName:e.name,projectName:e.project}),"."]}))},v=>{s("Snapshot deletion failed",new Error(v))},()=>{o(!1),p.invalidateQueries({predicate:v=>v.queryKey[0]===ve.instances})})}).catch(S=>{s("Snapshot deletion failed",S),o(!1)})},_=()=>{l(!0),im(e,t,c).then(S=>{r.set(S.metadata.id,()=>{i(h.jsxs(h.Fragment,{children:["Snapshot"," ",h.jsx(Gi,{name:t.name,instance:e})," ","restored for instance"," ",h.jsx(ge,{instanceName:e.name,projectName:e.project}),"."]}))},v=>{s("Snapshot restore failed",new Error(v))},()=>{l(!1),p.invalidateQueries({predicate:v=>v.queryKey[0]===ve.instances})})}).catch(S=>{s("Snapshot restore failed",S),l(!1)})};return h.jsx(h.Fragment,{children:h.jsx(b.List,{inline:!0,className:qi("u-no-margin--bottom","actions-list",{"u-snapshot-actions":!n&&!a}),items:[h.jsx(lm,{instance:e,snapshot:t,onSuccess:i,isDeleting:n,isRestoring:a,disabledReason:g},"edit"),h.jsx(b.ConfirmationButton,{appearance:"base",loading:a,className:"has-icon is-dense",title:"Confirm restore",confirmationModalProps:{title:"Confirm restore",children:h.jsxs("p",{children:["This will restore snapshot"," ",h.jsx(_s,{type:"snapshot",value:t.name,bold:!0}),".",h.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmExtra:t.stateful?h.jsx(sd,{label:"Restore the instance state",confirmed:[c,d]}):void 0,confirmButtonLabel:g??"Restore snapshot",confirmButtonAppearance:"positive",close:()=>{d(!0)},onConfirm:_},disabled:n||a||!!g,shiftClickEnabled:!0,showShiftClickHint:!0,children:h.jsx(b.Icon,{name:"change-version"})},"restore"),h.jsx(cm,{instance:e,snapshot:t,isRestoring:a,isDeleting:n},"publish"),h.jsx(_m,{instance:e,snapshot:t,isDeleting:n,isRestoring:a},"duplicate"),h.jsx(b.ConfirmationButton,{appearance:"base",loading:n,className:"has-icon is-dense",confirmationModalProps:{title:"Confirm delete",children:h.jsxs("p",{children:["This will permanently delete snapshot"," ",h.jsx(_s,{type:"snapshot",value:t.name,bold:!0}),".",h.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:g??"Delete snapshot",onConfirm:u},disabled:n||a||!!g,shiftClickEnabled:!0,showShiftClickHint:!0,children:h.jsx(b.Icon,{name:"delete"})},"delete")]})})},pm=({instance:e,snapshotNames:t,onStart:i,onFinish:s,onSuccess:r,onFailure:n})=>{const o=He(),[a,l]=O.useState(!1),c=_t(),{canManageInstanceSnapshots:d}=pt(),p=au(),f=t.length,g=()=>{l(!0),i(),tm(e,t,o).then(u=>{const{fulfilledCount:_,rejectedCount:S}=rd(u);_===f?r(h.jsxs(h.Fragment,{children:[h.jsx("b",{children:t.length})," ",ci("snapshot",t.length)," deleted."]}),p(u)):S===f?n("Snapshot bulk deletion failed",void 0,h.jsxs(h.Fragment,{children:[h.jsx("b",{children:f})," ",ci("snapshot",f)," could not be deleted."]}),p(u)):n("Snapshot bulk deletion partially failed",void 0,h.jsxs(h.Fragment,{children:[h.jsx("b",{children:_})," ",ci("snapshot",_)," ","deleted.",h.jsx("br",{}),h.jsx("b",{children:S})," ",ci("snapshot",S)," ","could not be deleted."]}),p(u)),c.invalidateQueries({predicate:v=>v.queryKey[0]===ve.instances}),l(!1),s()}).catch(u=>{n("Snapshot bulk deletion failed",u),l(!1)})};return h.jsx(ou,{confirmationButtonProps:{loading:a,disabled:a||!d(e),appearance:""},onDelete:g,entityType:"snapshot",entities:t,deletableEntities:t,disabledReason:d(e)?void 0:"You do not have permission to manage snapshots for this instance",buttonLabel:`Delete ${ci("snapshot",t.length)}`})},mm=({instance:e,close:t,onSuccess:i,onFailure:s})=>{const r=He(),{project:n}=si(),o=_t(),a=ft({initialValues:Zt(e),validationSchema:il,onSubmit:c=>{const d=ys(e,c);ji(d,n??"").then(p=>{r.set(p.metadata.id,()=>{i("Configuration updated.")},f=>{s("Configuration update failed",new Error(f))},()=>{t(),o.invalidateQueries({queryKey:[ve.instances]})})}).catch(p=>{s("Configuration update failed",p)})}}),l=c=>{c.key==="Escape"&&t()};return h.jsx(b.Modal,{close:t,className:"edit-snapshot-config",title:"Snapshot configuration",buttonRow:a.values.readOnly?h.jsx(b.Button,{className:"u-no-margin--bottom u-no-margin--right",onClick:t,children:"Close"}):h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:t,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:a.isSubmitting,disabled:a.isSubmitting,onClick:()=>{a.submitForm()},children:"Save"})]}),onKeyDown:l,children:h.jsx(sl,{formik:a})})},pa=({instance:e,onSuccess:t,onFailure:i,isDisabled:s,className:r})=>{const{openPortal:n,closePortal:o,isOpen:a,Portal:l}=b.usePortal(),{canEditInstance:c}=pt();return h.jsxs(h.Fragment,{children:[a&&h.jsx(l,{children:h.jsx("div",{className:"snapshot-list",children:h.jsx(mm,{close:o,instance:e,onSuccess:t,onFailure:i})})}),h.jsx(b.Button,{onClick:n,className:r,disabled:s||!c(e),title:c()?"":"You do not have permission to configure this instance",children:"See configuration"})]})},gm=150,vm=({close:e,instance:t,onSuccess:i})=>{const s=He(),r=b.useNotify(),n=b.useToastNotification(),o=_t(),a=O.useState(null),l=ft({initialValues:{name:"",stateful:!1,expirationDate:null,expirationTime:null},validateOnMount:!0,validationSchema:rh(t,a),onSubmit:(g,{resetForm:u})=>{r.clear();const _=g.expirationDate&&g.expirationTime?Ga(ol(g.expirationDate,g.expirationTime)):Rr,S=h.jsx(ge,{instanceName:t.name,projectName:t.project});em(t,g.name,_,g.stateful||!1).then(v=>{s.set(v.metadata.id,()=>{o.invalidateQueries({predicate:P=>P.queryKey[0]===ve.instances}),i(h.jsxs(h.Fragment,{children:["Snapshot"," ",h.jsx(Gi,{name:nd(v.metadata),instance:t})," ","created for instance ",S,"."]})),u(),e()},P=>{n.failure(`Snapshot creation failed for instance ${t.name}`,new Error(P),S),l.setSubmitting(!1),e()})}).catch(v=>{r.failure("Snapshot creation failed",v,S),l.setSubmitting(!1),e()})}});let c=h.jsxs(h.Fragment,{children:[`To create a stateful snapshot, the instance needs
`,"the ",h.jsx("code",{children:"migration.stateful"})," config set to true"]});const d=nm(t),p=t.status==="Running";d&&(c=`To create a stateful snapshot,
the instance must be running`),d&&p&&(c="");const f=h.jsx(b.List,{inline:!0,items:[h.jsx(b.Input,{id:"stateful",name:"stateful",type:"checkbox",label:"Stateful",wrapperClassName:"u-inline-block",disabled:!d||!p,onChange:l.handleChange,onBlur:l.handleBlur,defaultChecked:l.values.stateful},"stateful"),...c?[h.jsx(b.Tooltip,{position:"btm-left",message:c,zIndex:gm,children:h.jsx(b.Icon,{name:"information"})},"stateful-info")]:[]]});return h.jsx(nl,{isEdit:!1,formik:l,close:e,additionalFormInput:f})},ma=({instance:e,onSuccess:t,isDisabled:i,className:s})=>{const{openPortal:r,closePortal:n,isOpen:o,Portal:a}=b.usePortal(),{canManageInstanceSnapshots:l}=pt();return h.jsxs(h.Fragment,{children:[o&&h.jsx(a,{children:h.jsx(vm,{close:n,instance:e,onSuccess:t})}),h.jsx(b.Button,{appearance:"positive",className:s,onClick:r,disabled:i||!l(e),title:l(e)?"":"You do not have permission to create snapshots for this instance",children:i?h.jsx(b.Tooltip,{message:`Snapshot creation has been disabled for instances in the project ${e.project}`,children:"Create snapshot"}):"Create snapshot"})]})},Sm=1250,ga=()=>window.innerWidth<=Sm,bm=e=>{const{instance:t}=e,[i,s]=O.useState(""),r=b.useNotify(),n=b.useToastNotification(),[o,a]=O.useState([]),[l,c]=O.useState([]),[d,p]=O.useState(ga()),{project:f}=kn(),g=su(f),u=(U,X)=>{n.success(U,X)},_=(U,X,ie,Oe)=>{r.failure(U,X,ie,Oe)};O.useEffect(()=>{const U=new Set(t.snapshots?.map(ie=>ie.name)),X=o.filter(ie=>U.has(ie));X.length!==o.length&&a(X)},[t.snapshots]);const S=t.snapshots?.filter(U=>!(i&&!U.name.toLowerCase().includes(i.toLowerCase())))??[],v=t.snapshots&&t.snapshots.length>0,P=[{content:d?h.jsxs(h.Fragment,{children:["Name",h.jsx("br",{}),h.jsx("div",{className:"header-second-row",children:"Date created"})]}):"Name",sortKey:d?"created_at":"name",className:"name"},...d?[]:[{content:"Date created",sortKey:"created_at",className:"created"}],{content:"Expiry date",sortKey:"expires_at",className:"expiration"},{content:"Stateful",sortKey:"stateful",className:"stateful"},{"aria-label":"Actions",className:"actions"}],w=S.map(U=>{const X=h.jsx(fm,{instance:t,snapshot:U,onSuccess:u,onFailure:_});return{key:U.name,className:"u-row",name:U.name,columns:[{content:h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"u-truncate",title:`Snapshot ${U.name}`,children:h.jsx(od,{item:U})}),d&&h.jsx("div",{className:"u-text--muted",children:Oi(U.created_at)})]}),role:"rowheader","aria-label":"Name",className:"name"},...d?[]:[{content:Oi(U.created_at),role:"cell","aria-label":"Created at",className:"created"}],{content:Oi(U.expires_at),role:"cell","aria-label":"Expires at",className:"expiration"},{content:U.stateful?"Yes":"No",role:"cell","aria-label":"Stateful",className:"stateful"},{content:X,role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:U.name.toLowerCase(),created_at:U.created_at,expires_at:U.expires_at,stateful:U.stateful}}}),{rows:E,updateSort:D}=hu({rows:w,defaultSort:"created_at",defaultSortDirection:"descending"}),N=()=>{p(ga())};return b.useListener(window,N,"resize",!0),h.jsxs("div",{className:"snapshot-list",children:[v&&h.jsx("div",{className:"upper-controls-bar",children:o.length===0?h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"search-box-wrapper",children:h.jsx(b.SearchBox,{name:"search-snapshot",className:"search-box margin-right",type:"text",onChange:U=>{s(U)},placeholder:"Search for snapshots",value:i,"aria-label":"Search for snapshots"})}),h.jsx(pa,{instance:t,className:"u-no-margin--right",onFailure:_,onSuccess:u}),h.jsx(ma,{instance:t,onSuccess:u,onFailure:_,className:"u-float-right",isDisabled:g})]}):h.jsx("div",{className:"p-panel__controls",children:h.jsx(pm,{instance:t,snapshotNames:o,onStart:()=>{c(o)},onFinish:()=>{c([])},onSuccess:u,onFailure:_})})}),h.jsx(zs,{}),v?h.jsx(h.Fragment,{children:h.jsx(b.ScrollableTable,{dependencies:[S,r.notification],tableId:"instance-snapshot-table",belowIds:["status-bar"],children:h.jsx(b.TablePagination,{data:E,id:"pagination",itemName:"snapshot",className:"u-no-margin--top","aria-label":"Table pagination control",description:o.length>0&&h.jsx(lu,{totalCount:t.snapshots?.length??0,itemName:"snapshot",parentName:"instance",selectedNames:o,setSelectedNames:a,filteredNames:S.map(U=>U.name)}),children:h.jsx(nu,{id:"instance-snapshot-table",headers:P,rows:E,responsive:!0,sortable:!0,emptyStateMsg:"No snapshot found matching this search",itemName:"snapshot",parentName:"instance",selectedNames:o,setSelectedNames:a,disabledNames:l,filteredNames:S.map(U=>U.name),onUpdateSort:D,defaultSort:"created_at",defaultSortDirection:"descending"})})})}):h.jsxs(b.EmptyState,{className:"empty-state",image:h.jsx(b.Icon,{name:"snapshot",className:"empty-state-icon"}),title:"No snapshots found",children:[h.jsx("p",{children:f&&g?h.jsxs(h.Fragment,{children:["Snapshots are disabled for project"," ",h.jsx(hl,{projectName:f.name,urlSuffix:"/configuration"}),"."]}):"There are no snapshots of this instance."}),h.jsx("p",{children:h.jsx(ad,{docPath:"/howto/storage_backup_volume/#storage-backup-snapshots",hasExternalIcon:!0,children:"Learn more about snapshots"})}),h.jsx(pa,{instance:t,onFailure:_,onSuccess:u,isDisabled:g}),h.jsx(ma,{instance:t,onSuccess:u,onFailure:_,className:"empty-state-button",isDisabled:g})]})]})};var m={SPICE_MAGIC:"REDQ",SPICE_VERSION_MAJOR:2,SPICE_VERSION_MINOR:2,SPICE_CONNECT_TIMEOUT:30*1e3,SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION:0,SPICE_COMMON_CAP_AUTH_SPICE:1,SPICE_COMMON_CAP_MINI_HEADER:3,SPICE_TICKET_KEY_PAIR_LENGTH:1024,SPICE_TICKET_PUBKEY_BYTES:1024/8+34,SPICE_LINK_ERR_OK:0,SPICE_LINK_ERR_PERMISSION_DENIED:7,SPICE_MSG_SET_ACK:3,SPICE_MSG_PING:4,SPICE_MSG_NOTIFY:7,SPICE_MSG_MAIN_MIGRATE_BEGIN:101,SPICE_MSG_MAIN_MIGRATE_CANCEL:102,SPICE_MSG_MAIN_INIT:103,SPICE_MSG_MAIN_CHANNELS_LIST:104,SPICE_MSG_MAIN_MOUSE_MODE:105,SPICE_MSG_MAIN_MULTI_MEDIA_TIME:106,SPICE_MSG_MAIN_AGENT_CONNECTED:107,SPICE_MSG_MAIN_AGENT_DISCONNECTED:108,SPICE_MSG_MAIN_AGENT_DATA:109,SPICE_MSG_MAIN_AGENT_TOKEN:110,SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST:111,SPICE_MSG_MAIN_MIGRATE_END:112,SPICE_MSG_MAIN_NAME:113,SPICE_MSG_MAIN_UUID:114,SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS:115,SPICE_MSG_MAIN_MIGRATE_BEGIN_SEAMLESS:116,SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK:117,SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK:118,SPICE_MSGC_ACK_SYNC:1,SPICE_MSGC_ACK:2,SPICE_MSGC_PONG:3,SPICE_MSGC_MAIN_ATTACH_CHANNELS:104,SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST:105,SPICE_MSGC_MAIN_AGENT_START:106,SPICE_MSGC_MAIN_AGENT_DATA:107,SPICE_MSG_DISPLAY_MODE:101,SPICE_MSG_DISPLAY_MARK:102,SPICE_MSG_DISPLAY_RESET:103,SPICE_MSG_DISPLAY_COPY_BITS:104,SPICE_MSG_DISPLAY_INVAL_LIST:105,SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS:106,SPICE_MSG_DISPLAY_INVAL_PALETTE:107,SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES:108,SPICE_MSG_DISPLAY_STREAM_CREATE:122,SPICE_MSG_DISPLAY_STREAM_DATA:123,SPICE_MSG_DISPLAY_STREAM_CLIP:124,SPICE_MSG_DISPLAY_STREAM_DESTROY:125,SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL:126,SPICE_MSG_DISPLAY_DRAW_FILL:302,SPICE_MSG_DISPLAY_DRAW_OPAQUE:303,SPICE_MSG_DISPLAY_DRAW_COPY:304,SPICE_MSG_DISPLAY_DRAW_BLEND:305,SPICE_MSG_DISPLAY_DRAW_BLACKNESS:306,SPICE_MSG_DISPLAY_DRAW_WHITENESS:307,SPICE_MSG_DISPLAY_DRAW_INVERS:308,SPICE_MSG_DISPLAY_DRAW_ROP3:309,SPICE_MSG_DISPLAY_DRAW_STROKE:310,SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:312,SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:313,SPICE_MSG_DISPLAY_SURFACE_CREATE:314,SPICE_MSG_DISPLAY_SURFACE_DESTROY:315,SPICE_MSG_DISPLAY_STREAM_DATA_SIZED:316,SPICE_MSG_DISPLAY_MONITORS_CONFIG:317,SPICE_MSG_DISPLAY_DRAW_COMPOSITE:318,SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT:319,SPICE_MSGC_DISPLAY_INIT:101,SPICE_MSGC_DISPLAY_STREAM_REPORT:102,SPICE_MSG_INPUTS_INIT:101,SPICE_MSG_INPUTS_KEY_MODIFIERS:102,SPICE_MSG_INPUTS_MOUSE_MOTION_ACK:111,SPICE_MSGC_INPUTS_KEY_DOWN:101,SPICE_MSGC_INPUTS_KEY_UP:102,SPICE_MSGC_INPUTS_MOUSE_MOTION:111,SPICE_MSGC_INPUTS_MOUSE_POSITION:112,SPICE_MSGC_INPUTS_MOUSE_PRESS:113,SPICE_MSGC_INPUTS_MOUSE_RELEASE:114,SPICE_MSG_CURSOR_INIT:101,SPICE_MSG_CURSOR_RESET:102,SPICE_MSG_CURSOR_SET:103,SPICE_MSG_CURSOR_MOVE:104,SPICE_MSG_CURSOR_HIDE:105,SPICE_MSG_CURSOR_TRAIL:106,SPICE_MSG_CURSOR_INVAL_ONE:107,SPICE_MSG_CURSOR_INVAL_ALL:108,SPICE_MSG_PLAYBACK_DATA:101,SPICE_MSG_PLAYBACK_MODE:102,SPICE_MSG_PLAYBACK_START:103,SPICE_MSG_PLAYBACK_STOP:104,SPICE_MSG_PLAYBACK_VOLUME:105,SPICE_MSG_PLAYBACK_MUTE:106,SPICE_MSG_PLAYBACK_LATENCY:107,SPICE_MSG_SPICEVMC_DATA:101,SPICE_MSG_PORT_INIT:201,SPICE_MSG_PORT_EVENT:202,SPICE_PLAYBACK_CAP_OPUS:3,SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS:2,SPICE_DISPLAY_CAP_SIZED_STREAM:0,SPICE_DISPLAY_CAP_STREAM_REPORT:4,SPICE_DISPLAY_CAP_MULTI_CODEC:8,SPICE_DISPLAY_CAP_CODEC_MJPEG:9,SPICE_DISPLAY_CAP_CODEC_VP8:10,SPICE_AUDIO_DATA_MODE_OPUS:3,SPICE_AUDIO_FMT_S16:1,SPICE_CHANNEL_MAIN:1,SPICE_CHANNEL_DISPLAY:2,SPICE_CHANNEL_INPUTS:3,SPICE_CHANNEL_CURSOR:4,SPICE_CHANNEL_PLAYBACK:5,SPICE_CHANNEL_RECORD:6,SPICE_CHANNEL_TUNNEL:7,SPICE_CHANNEL_SMARTCARD:8,SPICE_CHANNEL_USBREDIR:9,SPICE_CHANNEL_PORT:10,SPICE_CHANNEL_WEBDAV:11,SPICE_SURFACE_FLAGS_PRIMARY:1,SPICE_NOTIFY_SEVERITY_WARN:1,SPICE_NOTIFY_SEVERITY_ERROR:2,SPICE_MOUSE_MODE_SERVER:1,SPICE_MOUSE_MODE_CLIENT:2,SPICE_CLIP_TYPE_NONE:0,SPICE_CLIP_TYPE_RECTS:1,SPICE_IMAGE_TYPE_BITMAP:0,SPICE_IMAGE_TYPE_QUIC:1,SPICE_IMAGE_TYPE_LZ_RGB:101,SPICE_IMAGE_TYPE_FROM_CACHE:103,SPICE_IMAGE_TYPE_SURFACE:104,SPICE_IMAGE_TYPE_JPEG:105,SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:106,SPICE_IMAGE_TYPE_JPEG_ALPHA:108,SPICE_IMAGE_FLAGS_CACHE_ME:1,SPICE_IMAGE_FLAGS_HIGH_BITS_SET:2,SPICE_BITMAP_FLAGS_PAL_FROM_CACHE:2,SPICE_BITMAP_FLAGS_TOP_DOWN:4,SPICE_BITMAP_FMT_32BIT:8,SPICE_BITMAP_FMT_RGBA:9,SPICE_CURSOR_FLAGS_NONE:1,SPICE_MOUSE_BUTTON_MASK_LEFT:1,SPICE_MOUSE_BUTTON_LEFT:1,SPICE_MOUSE_BUTTON_UP:4,SPICE_MOUSE_BUTTON_DOWN:5,SPICE_BRUSH_TYPE_SOLID:1,SPICE_BRUSH_TYPE_PATTERN:2,SPICE_SURFACE_FMT_32_xRGB:32,SPICE_SURFACE_FMT_32_ARGB:96,SPICE_ROPD_OP_PUT:8,LZ_IMAGE_TYPE_RGB32:8,LZ_IMAGE_TYPE_RGBA:9,LZ_IMAGE_TYPE_XXXA:10,SPICE_INPUT_MOTION_ACK_BUNCH:4,SPICE_CURSOR_TYPE_ALPHA:0,SPICE_VIDEO_CODEC_TYPE_MJPEG:1,SPICE_VIDEO_CODEC_TYPE_VP8:2,VD_AGENT_PROTOCOL:1,VD_AGENT_MAX_DATA_SIZE:2048,VD_AGENT_MONITORS_CONFIG:2,VD_AGENT_CLIPBOARD:4,VD_AGENT_ANNOUNCE_CAPABILITIES:6,VD_AGENT_CLIPBOARD_GRAB:7,VD_AGENT_CLIPBOARD_REQUEST:8,VD_AGENT_CLIPBOARD_RELEASE:9,VD_AGENT_FILE_XFER_START:10,VD_AGENT_FILE_XFER_STATUS:11,VD_AGENT_FILE_XFER_DATA:12,VD_AGENT_CAP_MOUSE_STATE:0,VD_AGENT_CAP_MONITORS_CONFIG:1,VD_AGENT_CAP_REPLY:2,VD_AGENT_CAP_CLIPBOARD_BY_DEMAND:5,VD_AGENT_CAP_CLIPBOARD_SELECTION:6,VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:0,VD_AGENT_FILE_XFER_STATUS_CANCELLED:1,VD_AGENT_FILE_XFER_STATUS_ERROR:2,VD_AGENT_FILE_XFER_STATUS_SUCCESS:3,VD_AGENT_CLIPBOARD_UTF8_TEXT:1};function j(e,t,i){t!==void 0?i!==void 0?this.u8=new Uint8Array(e,t,i):this.u8=new Uint8Array(e,t):this.u8=new Uint8Array(e)}j.prototype={getUint8:function(e){return this.u8[e]},getUint16:function(e,t){var i=1,s=0;return t&&(i=0,s=1),this.u8[e+s]<<8|this.u8[e+i]},getUint32:function(e,t){var i=2,s=0;return t&&(i=0,s=2),this.getUint16(e+s,t)<<16|this.getUint16(e+i,t)},getUint64:function(e,t){var i=4,s=0;return t&&(i=0,s=4),this.getUint32(e+s,t)<<32|this.getUint32(e+i,t)},setUint8:function(e,t){this.u8[e]=t&255},setUint16:function(e,t,i){var s=1,r=0;i&&(s=0,r=1),this.u8[e+r]=(t&65535)>>8,this.u8[e+s]=t&255},setUint32:function(e,t,i){var s=2,r=0;i&&(s=0,r=2),this.setUint16(e+r,(t&4294967295)>>16,i),this.setUint16(e+s,t&65535,i)},setUint64:function(e,t,i){var s=4,r=0;i&&(s=0,r=4),this.setUint32(e+r,(t&18446744073709552e3)>>32,i),this.setUint32(e+s,t&4294967295,i)}};var Yt;function z(e,t,i){e!=null&&(typeof e=="number"?this.fromNumber(e,t,i):t==null&&typeof e!="string"?this.fromString(e,256):this.fromString(e,t))}function yt(){return new z(null)}function ym(e,t,i,s,r,n){for(;--n>=0;){var o=t*this[e++]+i[s]+r;r=Math.floor(o/67108864),i[s++]=o&67108863}return r}function Cm(e,t,i,s,r,n){for(var o=t&32767,a=t>>15;--n>=0;){var l=this[e]&32767,c=this[e++]>>15,d=a*l+c*o;l=o*l+((d&32767)<<15)+i[s]+(r&1073741823),r=(l>>>30)+(d>>>15)+a*c+(r>>>30),i[s++]=l&1073741823}return r}function wm(e,t,i,s,r,n){for(var o=t&16383,a=t>>14;--n>=0;){var l=this[e]&16383,c=this[e++]>>14,d=a*l+c*o;l=o*l+((d&16383)<<14)+i[s]+r,r=(l>>28)+(d>>14)+a*c,i[s++]=l&268435455}return r}navigator.appName=="Microsoft Internet Explorer"?(z.prototype.am=Cm,Yt=30):navigator.appName!="Netscape"?(z.prototype.am=ym,Yt=26):(z.prototype.am=wm,Yt=28);z.prototype.DB=Yt;z.prototype.DM=(1<<Yt)-1;z.prototype.DV=1<<Yt;var jn=52;z.prototype.FV=Math.pow(2,jn);z.prototype.F1=jn-Yt;z.prototype.F2=2*Yt-jn;var Em="0123456789abcdefghijklmnopqrstuvwxyz",Qs=new Array,gi,ht;gi=48;for(ht=0;ht<=9;++ht)Qs[gi++]=ht;gi=97;for(ht=10;ht<36;++ht)Qs[gi++]=ht;gi=65;for(ht=10;ht<36;++ht)Qs[gi++]=ht;function va(e){return Em.charAt(e)}function xm(e,t){var i=Qs[e.charCodeAt(t)];return i??-1}function Im(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function Am(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+DV:this.t=0}function nh(e){var t=yt();return t.fromInt(e),t}function Pm(e,t){var i;if(t==16)i=4;else if(t==8)i=3;else if(t==256)i=8;else if(t==2)i=1;else if(t==32)i=5;else if(t==4)i=2;else{this.fromRadix(e,t);return}this.t=0,this.s=0;for(var s=e.length,r=!1,n=0;--s>=0;){var o=i==8?e[s]&255:xm(e,s);if(o<0){e.charAt(s)=="-"&&(r=!0);continue}r=!1,n==0?this[this.t++]=o:n+i>this.DB?(this[this.t-1]|=(o&(1<<this.DB-n)-1)<<n,this[this.t++]=o>>this.DB-n):this[this.t-1]|=o<<n,n+=i,n>=this.DB&&(n-=this.DB)}i==8&&(e[0]&128)!=0&&(this.s=-1,n>0&&(this[this.t-1]|=(1<<this.DB-n)-1<<n)),this.clamp(),r&&z.ZERO.subTo(this,this)}function km(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t}function Mm(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(e==16)t=4;else if(e==8)t=3;else if(e==2)t=1;else if(e==32)t=5;else if(e==4)t=2;else return this.toRadix(e);var i=(1<<t)-1,s,r=!1,n="",o=this.t,a=this.DB-o*this.DB%t;if(o-- >0)for(a<this.DB&&(s=this[o]>>a)>0&&(r=!0,n=va(s));o>=0;)a<t?(s=(this[o]&(1<<a)-1)<<t-a,s|=this[--o]>>(a+=this.DB-t)):(s=this[o]>>(a-=t)&i,a<=0&&(a+=this.DB,--o)),s>0&&(r=!0),r&&(n+=va(s));return r?n:"0"}function Dm(){var e=yt();return z.ZERO.subTo(this,e),e}function Tm(){return this.s<0?this.negate():this}function Rm(e){var t=this.s-e.s;if(t!=0)return t;var i=this.t;if(t=i-e.t,t!=0)return t;for(;--i>=0;)if((t=this[i]-e[i])!=0)return t;return 0}function Kn(e){var t=1,i;return(i=e>>>16)!=0&&(e=i,t+=16),(i=e>>8)!=0&&(e=i,t+=8),(i=e>>4)!=0&&(e=i,t+=4),(i=e>>2)!=0&&(e=i,t+=2),(i=e>>1)!=0&&(e=i,t+=1),t}function Lm(){return this.t<=0?0:this.DB*(this.t-1)+Kn(this[this.t-1]^this.s&this.DM)}function Nm(e,t){var i;for(i=this.t-1;i>=0;--i)t[i+e]=this[i];for(i=e-1;i>=0;--i)t[i]=0;t.t=this.t+e,t.s=this.s}function Bm(e,t){for(var i=e;i<this.t;++i)t[i-e]=this[i];t.t=Math.max(this.t-e,0),t.s=this.s}function Om(e,t){var i=e%this.DB,s=this.DB-i,r=(1<<s)-1,n=Math.floor(e/this.DB),o=this.s<<i&this.DM,a;for(a=this.t-1;a>=0;--a)t[a+n+1]=this[a]>>s|o,o=(this[a]&r)<<i;for(a=n-1;a>=0;--a)t[a]=0;t[n]=o,t.t=this.t+n+1,t.s=this.s,t.clamp()}function Um(e,t){t.s=this.s;var i=Math.floor(e/this.DB);if(i>=this.t){t.t=0;return}var s=e%this.DB,r=this.DB-s,n=(1<<s)-1;t[0]=this[i]>>s;for(var o=i+1;o<this.t;++o)t[o-i-1]|=(this[o]&n)<<r,t[o-i]=this[o]>>s;s>0&&(t[this.t-i-1]|=(this.s&n)<<r),t.t=this.t-i,t.clamp()}function Fm(e,t){for(var i=0,s=0,r=Math.min(e.t,this.t);i<r;)s+=this[i]-e[i],t[i++]=s&this.DM,s>>=this.DB;if(e.t<this.t){for(s-=e.s;i<this.t;)s+=this[i],t[i++]=s&this.DM,s>>=this.DB;s+=this.s}else{for(s+=this.s;i<e.t;)s-=e[i],t[i++]=s&this.DM,s>>=this.DB;s-=e.s}t.s=s<0?-1:0,s<-1?t[i++]=this.DV+s:s>0&&(t[i++]=s),t.t=i,t.clamp()}function jm(e,t){var i=this.abs(),s=e.abs(),r=i.t;for(t.t=r+s.t;--r>=0;)t[r]=0;for(r=0;r<s.t;++r)t[r+i.t]=i.am(0,s[r],t,r,0,i.t);t.s=0,t.clamp(),this.s!=e.s&&z.ZERO.subTo(t,t)}function Km(e){for(var t=this.abs(),i=e.t=2*t.t;--i>=0;)e[i]=0;for(i=0;i<t.t-1;++i){var s=t.am(i,t[i],e,2*i,0,1);(e[i+t.t]+=t.am(i+1,2*t[i],e,2*i+1,s,t.t-i-1))>=t.DV&&(e[i+t.t]-=t.DV,e[i+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(i,t[i],e,2*i,0,1)),e.s=0,e.clamp()}function zm(e,t,i){var s=e.abs();if(!(s.t<=0)){var r=this.abs();if(r.t<s.t){t?.fromInt(0),i!=null&&this.copyTo(i);return}i==null&&(i=yt());var n=yt(),o=this.s,a=e.s,l=this.DB-Kn(s[s.t-1]);l>0?(s.lShiftTo(l,n),r.lShiftTo(l,i)):(s.copyTo(n),r.copyTo(i));var c=n.t,d=n[c-1];if(d!=0){var p=d*(1<<this.F1)+(c>1?n[c-2]>>this.F2:0),f=this.FV/p,g=(1<<this.F1)/p,u=1<<this.F2,_=i.t,S=_-c,v=t??yt();for(n.dlShiftTo(S,v),i.compareTo(v)>=0&&(i[i.t++]=1,i.subTo(v,i)),z.ONE.dlShiftTo(c,v),v.subTo(n,n);n.t<c;)n[n.t++]=0;for(;--S>=0;){var P=i[--_]==d?this.DM:Math.floor(i[_]*f+(i[_-1]+u)*g);if((i[_]+=n.am(0,P,i,S,0,c))<P)for(n.dlShiftTo(S,v),i.subTo(v,i);i[_]<--P;)i.subTo(v,i)}t!=null&&(i.drShiftTo(c,t),o!=a&&z.ZERO.subTo(t,t)),i.t=c,i.clamp(),l>0&&i.rShiftTo(l,i),o<0&&z.ZERO.subTo(i,i)}}}function Ym(e){var t=yt();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(z.ZERO)>0&&e.subTo(t,t),t}function vi(e){this.m=e}function Hm(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function Gm(e){return e}function Wm(e){e.divRemTo(this.m,null,e)}function $m(e,t,i){e.multiplyTo(t,i),this.reduce(i)}function Vm(e,t){e.squareTo(t),this.reduce(t)}vi.prototype.convert=Hm;vi.prototype.revert=Gm;vi.prototype.reduce=Wm;vi.prototype.mulTo=$m;vi.prototype.sqrTo=Vm;function qm(){if(this.t<1)return 0;var e=this[0];if((e&1)==0)return 0;var t=e&3;return t=t*(2-(e&15)*t)&15,t=t*(2-(e&255)*t)&255,t=t*(2-((e&65535)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function Si(e){this.m=e,this.mp=e.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function Xm(e){var t=yt();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(z.ZERO)>0&&this.m.subTo(t,t),t}function Qm(e){var t=yt();return e.copyTo(t),this.reduce(t),t}function Zm(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var i=e[t]&32767,s=i*this.mpl+((i*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(i=t+this.m.t,e[i]+=this.m.am(0,s,e,t,0,this.m.t);e[i]>=e.DV;)e[i]-=e.DV,e[++i]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function Jm(e,t){e.squareTo(t),this.reduce(t)}function eg(e,t,i){e.multiplyTo(t,i),this.reduce(i)}Si.prototype.convert=Xm;Si.prototype.revert=Qm;Si.prototype.reduce=Zm;Si.prototype.mulTo=eg;Si.prototype.sqrTo=Jm;function tg(){return(this.t>0?this[0]&1:this.s)==0}function ig(e,t){if(e>4294967295||e<1)return z.ONE;var i=yt(),s=yt(),r=t.convert(this),n=Kn(e)-1;for(r.copyTo(i);--n>=0;)if(t.sqrTo(i,s),(e&1<<n)>0)t.mulTo(s,r,i);else{var o=i;i=s,s=o}return t.revert(i)}function sg(e,t){var i;return e<256||t.isEven()?i=new vi(t):i=new Si(t),this.exp(e,i)}z.prototype.copyTo=Im;z.prototype.fromInt=Am;z.prototype.fromString=Pm;z.prototype.clamp=km;z.prototype.dlShiftTo=Nm;z.prototype.drShiftTo=Bm;z.prototype.lShiftTo=Om;z.prototype.rShiftTo=Um;z.prototype.subTo=Fm;z.prototype.multiplyTo=jm;z.prototype.squareTo=Km;z.prototype.divRemTo=zm;z.prototype.invDigit=qm;z.prototype.isEven=tg;z.prototype.exp=ig;z.prototype.toString=Mm;z.prototype.negate=Dm;z.prototype.abs=Tm;z.prototype.compareTo=Rm;z.prototype.bitLength=Lm;z.prototype.mod=Ym;z.prototype.modPowInt=sg;z.ZERO=nh(0);z.ONE=nh(1);function zn(){this.i=0,this.j=0,this.S=new Array}function rg(e){var t,i,s;for(t=0;t<256;++t)this.S[t]=t;for(i=0,t=0;t<256;++t)i=i+this.S[t]+e[t%e.length]&255,s=this.S[t],this.S[t]=this.S[i],this.S[i]=s;this.i=0,this.j=0}function ng(){var e;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,e=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=e,this.S[e+this.S[this.i]&255]}zn.prototype.init=rg;zn.prototype.next=ng;function og(){return new zn}var vn=256,hs,lt,Le;function ag(e){lt[Le++]^=e&255,lt[Le++]^=e>>8&255,lt[Le++]^=e>>16&255,lt[Le++]^=e>>24&255,Le>=vn&&(Le-=vn)}function oh(){ag(new Date().getTime())}if(lt==null){lt=new Array,Le=0;var Vt;if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&window.crypto){var Sa=window.crypto.random(32);for(Vt=0;Vt<Sa.length;++Vt)lt[Le++]=Sa.charCodeAt(Vt)&255}for(;Le<vn;)Vt=Math.floor(65536*Math.random()),lt[Le++]=Vt>>>8,lt[Le++]=Vt&255;Le=0,oh()}function lg(){if(hs==null){for(oh(),hs=og(),hs.init(lt),Le=0;Le<lt.length;++Le)lt[Le]=0;Le=0}return hs.next()}function hg(e){var t;for(t=0;t<e.length;++t)e[t]=lg()}function Yn(){}Yn.prototype.nextBytes=hg;function cg(e,t){return new z(e,t)}function dg(e,t){if(t<e.length+11)return alert("Message too long for RSA"),null;for(var i=new Array,s=e.length-1;s>=0&&t>0;){var r=e.charCodeAt(s--);r<128?i[--t]=r:r>127&&r<2048?(i[--t]=r&63|128,i[--t]=r>>6|192):(i[--t]=r&63|128,i[--t]=r>>6&63|128,i[--t]=r>>12|224)}i[--t]=0;for(var n=new Yn,o=new Array;t>2;){for(o[0]=0;o[0]==0;)n.nextBytes(o);i[--t]=o[0]}return i[--t]=2,i[--t]=0,new z(i)}function Zs(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function ug(e,t){e!=null&&t!=null&&e.length>0&&t.length>0?(this.n=cg(e,16),this.e=parseInt(t,16)):alert("Invalid RSA public key")}function _g(e){return e.modPowInt(this.e,this.n)}function fg(e){var t=dg(e,this.n.bitLength()+7>>3);if(t==null)return null;var i=this.doPublic(t);if(i==null)return null;var s=i.toString(16);return(s.length&1)==0?s:"0"+s}Zs.prototype.doPublic=_g;Zs.prototype.setPublic=ug;Zs.prototype.encrypt=fg;var ba=0;function pg(e){return mg(Hn(gg(e)))}function Hn(e){return Sg(bg(vg(e),e.length*8))}function mg(e){for(var t=ba?"0123456789ABCDEF":"0123456789abcdef",i="",s,r=0;r<e.length;r++)s=e.charCodeAt(r),i+=t.charAt(s>>>4&15)+t.charAt(s&15);return i}function gg(e){for(var t="",i=-1,s,r;++i<e.length;)s=e.charCodeAt(i),r=i+1<e.length?e.charCodeAt(i+1):0,55296<=s&&s<=56319&&56320<=r&&r<=57343&&(s=65536+((s&1023)<<10)+(r&1023),i++),s<=127?t+=String.fromCharCode(s):s<=2047?t+=String.fromCharCode(192|s>>>6&31,128|s&63):s<=65535?t+=String.fromCharCode(224|s>>>12&15,128|s>>>6&63,128|s&63):s<=2097151&&(t+=String.fromCharCode(240|s>>>18&7,128|s>>>12&63,128|s>>>6&63,128|s&63));return t}function vg(e){for(var t=Array(e.length>>2),i=0;i<t.length;i++)t[i]=0;for(var i=0;i<e.length*8;i+=8)t[i>>5]|=(e.charCodeAt(i/8)&255)<<24-i%32;return t}function Sg(e){for(var t="",i=0;i<e.length*32;i+=8)t+=String.fromCharCode(e[i>>5]>>>24-i%32&255);return t}function bg(e,t){e[t>>5]|=128<<24-t%32,e[(t+64>>9<<4)+15]=t;for(var i=Array(80),s=1732584193,r=-271733879,n=-1732584194,o=271733878,a=-1009589776,l=0;l<e.length;l+=16){for(var c=s,d=r,p=n,f=o,g=a,u=0;u<80;u++){u<16?i[u]=e[l+u]:i[u]=Ar(i[u-3]^i[u-8]^i[u-14]^i[u-16],1);var _=xt(xt(Ar(s,5),yg(u,r,n,o)),xt(xt(a,i[u]),Cg(u)));a=o,o=n,n=Ar(r,30),r=s,s=_}s=xt(s,c),r=xt(r,d),n=xt(n,p),o=xt(o,f),a=xt(a,g)}return Array(s,r,n,o,a)}function yg(e,t,i,s){return e<20?t&i|~t&s:e<40?t^i^s:e<60?t&i|t&s|i&s:t^i^s}function Cg(e){return e<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514}function xt(e,t){var i=(e&65535)+(t&65535),s=(e>>16)+(t>>16)+(i>>16);return s<<16|i&65535}function Ar(e,t){return e<<t|e>>>32-t}var Pr=20;function ya(e,t){var i,s,r;for(i=0,r=0;r<e.length;i++){var n=new String;for(s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);n+=String.fromCharCode(i>>24&255),n+=String.fromCharCode(i>>16&255),n+=String.fromCharCode(i>>8&255),n+=String.fromCharCode(i&255);var o=Hn(n);for(s=0;s<o.length&&r<e.length;s++,r++)e[r]=o.charCodeAt(s)}}function wg(e,t,i){var s=new Array(Pr),r=new Yn;r.nextBytes(s);var n=e-1-s.length,o=new Array(n),a=n-t.length-1,l;if(i===void 0&&(i=""),a<Pr)return console.log("Error - data too large for key size."),null;for(l=0;l<a;l++)o[l]=0;var c=Hn(i);for(l=0;l<c.length;l++)o[l]=c.charCodeAt(l);for(o[a]=1,l=0;l<t.length;l++)o[l+a+1]=t.charCodeAt(l);var d=new Array(n);if(ya(d,s)<0)return null;for(l=0;l<d.length;l++)o[l]^=d[l];var p=Array(Pr);if(ya(p,o)<0)return null;for(l=0;l<p.length;l++)s[l]^=p[l];var f=new String;for(f+="\0",l=0;l<s.length;l++)f+=String.fromCharCode(s[l]);for(l=0;l<o.length;l++)f+=String.fromCharCode(o[l]);return f}function bs(e,t){var i=e[t++];if(i>128){if(i!=129)return console.log("Error:  we lazily don't support keys bigger than 255 bytes.  It'd be easy to fix."),null;i=e[t++]}return[t,i]}function kr(e,t){var i;return t=t||0,e[t++]!=48?(console.log("Error:  public key should start with a sequence flag."),null):(i=bs(e,t),i||null)}function Eg(e,t){var i=new Uint8Array(e),s,r,n,o,a;if(r=kr(i,t),!r||(t=r[0],r=kr(i,t),!r))return null;if(t=r[0]+r[1],i[t++]!=3)return console.log("Error: expecting bit string next."),null;if(s=bs(i,t),!s)return null;if(t=s[0],i[t]!=0&&i[t+1]!=48)return console.log("Error: unexpected values in bit string."),null;if(r=kr(i,t+1),!r)return null;if(t=r[0],i[t++]!=2)return console.log("Error: expecting integer n next."),null;if(s=bs(i,t),!s)return null;for(t=s[0],n=new Array(s[1]),o=0;o<s[1];o++)n[o]=i[t+o];if(a=new Zs,a.n=new z(n),t+=s[1],i[t++]!=2)return console.log("Error: expecting integer e next."),null;if(s=bs(i,t),!s)return null;for(t=s[0],a.e=i[t++],o=1;o<s[1];o++)a.e<<=8,a.e|=i[t++];return a}function xg(e,t){var i,s=[],r=wg(e.n.bitLength()+7>>3,t);if(!r)return null;var n=new Array(r.length);for(i=0;i<r.length;i++)n[i]=r.charCodeAt(i);var o=new z(n),a=e.doPublic(o),l=a.toString(16);for((l.length&1)!=0&&(l="0"+l),i=0;i<l.length;i+=2)s[i/2]=parseInt(l.substring(i,i+2),16);return s}var Ft,Ne={QUIC_IMAGE_TYPE_INVALID:0,QUIC_IMAGE_TYPE_GRAY:1,QUIC_IMAGE_TYPE_RGB16:2,QUIC_IMAGE_TYPE_RGB24:3,QUIC_IMAGE_TYPE_RGB32:4,QUIC_IMAGE_TYPE_RGBA:5},Ig=3,Ag=6,Pg=2048,Ca=!0,wa=26,ah=Ig,Gt=Ag,_i=Pg,kg={nGRcodewords:[0,0,0,0,0,0,0,0],notGRcwlen:[0,0,0,0,0,0,0,0],notGRprefixmask:[0,0,0,0,0,0,0,0],notGRsuffixlen:[0,0,0,0,0,0,0,0],xlatU2L:[0,0,0,0,0,0,0,0],xlatL2U:[0,0,0,0,0,0,0,0]},Se={nGRcodewords:[0,0,0,0,0,0,0,0],notGRcwlen:[0,0,0,0,0,0,0,0],notGRprefixmask:[0,0,0,0,0,0,0,0],notGRsuffixlen:[0,0,0,0,0,0,0,0],xlatU2L:[0,0,0,0,0,0,0,0],xlatL2U:[0,0,0,0,0,0,0,0]},Je=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,2147483647,4294967295],lh=[],Mg=[[550,900,800,700,500,350,300,200,180,180,160],[110,550,900,800,550,400,350,250,140,160,140],[100,120,550,900,700,500,400,300,220,250,160]],Sn=[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,15],cs=[8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],Dg=[46495042,893548311,794435923,2453991765,2077388039,894197842,1462934312,697534094,1826128012,343623392,2581292719,3811265708,459739748,2638427270,1654964626,101227083,2654850628,3668700691,572794346,2758751005,3445133904,2344099199,3367450297,898927923,3618406352,1606297603,754696453,20823118,2050458127,972590750,3990194068,3305596553,4239238564,1690498157,3015324227,2306127097,1510321853,548392192,971157512,2292288069,1611390505,4086766286,4084927083,1883326811,1891043243,113180603,1107690783,3778825955,3248980775,2443839100,2190866218,1932072870,495393613,1078522166,4051963518,1784694977,1768732442,2146763203,264646923,1474361405,2361552500,296035746,2489922759,2094565616,2409465348,1334241083,72483606,3740181004,4057920662,1734898312,4114662834,574624900,880305546,3258472262,26713132,1571648456,52557195,4043234286,2458021343,676064371,1528437109,64953873,546717185,2709319979,1947039598,2812723004,28691684,286829174,4235176970,3465707163,12526951,2154766700,3165032534,2036061161,3386656087,2301212354,2023576300,1061142336,3105452904,2743866805,3283373992,3397596080,3085489552,3196092395,3210707808,3651022684,925444321,2088074316,230011220,3223248386,533229176,523863486,3028311159,13140218,2538347282,900399636,3000796173,1526771255,3541282854,2992674461,2135722105,389334227,1225164337,3119947809,1803959919,3471171263,704170491,1407019136,1924534819,526887421,168782227,333811993,298623278,4268451686,381087740,2542899140,3266880867,2498950977,200969370,3511909096,3252303004,2268881098,2499828613,2606499854,3163208665,3790254546,1840025712,1319758833,3771674836,519421307,3512796222,1563402978,4284300462,2263719815,715250337,3178437172,2660191010,2982332026,3256309961,2709659997,3434092872,2367065591,69438718,915160508,183164069,3134331940,175242981,2680543346,1421955782,4231173251,1736652874,3990568476,1710820912,2286604440,3464587098,1261907837,1757387321,1128554270,1090050251,2429922486,1288729218,882830086,211637042,1376462063,2147615815,1737974929,798170275,4271572277,4241687072,1638524620,2760366295,1065115089,2097227717,1224023317,1625204849,3383303351,1488272307,2640186157,1649047732,819719707,2615091943,502645401,760628135,4108137983,63606742,1404337880,1865161130,4272996852,1239761976,790984678,3213322601,1917062825,4195069880,1962259360,2111002573,2311983960,1861406170,511141875,2797510619,1331661048,3130608186,147483493,3767089176,2650841450,4096523407,2574446300,1956416337,851468126,3607527519,1811658703,3642821136,832691095,2453312857,933732854,94341217,3393797730,1695907457,2405722077,2877685663,2469507058,2249636341,3988608661,4001245617,825934927,3103985967,1127151177,3691656896,1640967098,2168932645,2830550957,3998822878,3002602893,1509651465,775813869,2599574079,3791574229],$=3,st=2,rt=1,nt=0,q=4;function Ea(e){if(e===1)return 0;var t=1;for(e-=1;e=e>>>1;)t++;return t}function xa(e,t,i){var s;for(s=0;s<t;s++){var r,n;r=i-t,r>Je[t-s]&&(r=Je[t-s]),n=Je[t]+1-(r<<s),e.nGRcodewords[s]=r<<s,e.notGRcwlen[s]=r+Ea(n),e.notGRprefixmask[s]=Je[32-r]>>>0,e.notGRsuffixlen[s]=Ea(n)}var o=Je[t],a=o>>>1,l;for(l=0;l<=o;l++)l<=a?e.xlatU2L[l]=l<<1:e.xlatU2L[l]=(o-l<<1)+1;for(l=0;l<=o;l++)l&1?e.xlatL2U[l]=o-(l>>>1):e.xlatL2U[l]=l>>>1}function Tg(e){switch(e){case Ne.QUIC_IMAGE_TYPE_GRAY:return 8;case Ne.QUIC_IMAGE_TYPE_RGB16:return 5;case Ne.QUIC_IMAGE_TYPE_RGB24:return 8;case Ne.QUIC_IMAGE_TYPE_RGB32:return 8;case Ne.QUIC_IMAGE_TYPE_RGBA:return 8;case Ne.QUIC_IMAGE_TYPE_INVALID:default:return console.log(`quic: bad image type
`),0}}function Rg(e){return e&4286578688?cs[e>>>24]:e&4294934528?8+cs[e>>>16&255]:e&4294967168?16+cs[e>>>8&255]:24+cs[e&255]}function dt(e,t){var i,s;if(t<0||t>Se.notGRprefixmask[e]){var r=Rg(t);s=r+1+e,i=r<<e|t>>32-s&Je[e]}else s=Se.notGRcwlen[e],i=Se.nGRcodewords[e]+(t>>32-s&Je[Se.notGRsuffixlen[e]]);return{codewordlen:s,rc:i}}function Ia(e,t){return e<Se.nGRcodewords[t]?(e>>>t)+1+t:Se.notGRcwlen[t]}function bn(e){var t,i=0;switch(this.levels=1<<e,this.n_buckets_ptrs=0,ah){case 1:this.repfirst=3,this.firstsize=1,this.repnext=2,this.mulsize=2;break;case 3:this.repfirst=1,this.firstsize=1,this.repnext=1,this.mulsize=2;break;case 5:this.repfirst=1,this.firstsize=1,this.repnext=1,this.mulsize=4;break;case 0:case 2:case 4:console.log(`quic: findmodelparams(): evol value obsolete!!!
`);break;default:console.log(`quic: findmodelparams(): evol out of range!!!
`)}this.n_buckets=0;var s=this.repfirst+1,r=this.firstsize;do this.n_buckets?t=i+1:t=0,--s||(s=this.repnext,r*=this.mulsize),i=t+r-1,i+r>=this.levels&&(i=this.levels-1),this.n_buckets_ptrs||(this.n_buckets_ptrs=this.levels),this.n_buckets++;while(i<this.levels-1)}bn.prototype={n_buckets:0,n_buckets_ptrs:0,repfirst:0,firstsize:0,repnext:0,mulsize:0,levels:0};function hh(){this.counters=[0,0,0,0,0,0,0,0]}hh.prototype={bestcode:0,reste:function(e){this.bestcode=e,this.counters=[0,0,0,0,0,0,0,0]},update_model_8bpc:function(e,t,i){var s,r=i-1,n=this.counters[r]+=Ia(t,r);for(s=i-2;s>=0;s--){var o=this.counters[s]+=Ia(t,s);o<n&&(r=s,n=o)}if(this.bestcode=r,n>e.wm_trigger)for(s=0;s<i;s++)this.counters[s]=this.counters[s]>>>1}};function yn(){this.buckets_ptrs=[],this.buckets_buf=[]}yn.prototype={fill_model_structures:function(e){var t,i=0,s=0,r=e.repfirst+1,n=e.firstsize;do{s?t=i+1:t=0,--r||(r=e.repnext,n*=e.mulsize),i=t+n-1,i+n>=e.levels&&(i=e.levels-1),this.buckets_buf[s]=new hh;var o;for(o=t;o<=i;o++)this.buckets_ptrs[o]=this.buckets_buf[s];s++}while(i<e.levels-1);return!0}};function ch(e,t){this.state=new Gn,this.family_stat_8bpc=new yn,this.family_stat_5bpc=new yn,this.correlate_row={zero:0,row:[]},this.model_8bpc=e,this.model_5bpc=t,this.buckets_ptrs=[],this.family_stat_8bpc.fill_model_structures(this.model_8bpc)&&this.family_stat_5bpc.fill_model_structures(this.model_5bpc)}ch.prototype={reste:function(e){var t;if(this.correlate_row={zero:0,row:[]},e==8){for(t=0;t<this.model_8bpc.n_buckets;t++)this.family_stat_8bpc.buckets_buf[t].reste(7);this.buckets_ptrs=this.family_stat_8bpc.buckets_ptrs}else if(e==5){for(t=0;t<this.model_5bpc.n_buckets;t++)this.family_stat_8bpc.buckets_buf[t].reste(4);this.buckets_ptrs=this.family_stat_5bpc.buckets_ptrs}else return console.log(`quic: %s: bad bpc %d
`,__FUNCTION__,e),!1;return this.state.reste(),!0}};function Gn(){}Gn.prototype={waitcnt:0,tabrand_seed:255,wm_trigger:0,wmidx:0,wmileft:_i,melcstate:0,melclen:0,melcorder:0,set_wm_trigger:function(){var e=this.wmidx;e>10&&(e=10),this.wm_trigger=Mg[Math.floor(ah/2)][e]},reste:function(){this.waitcnt=0,this.tabrand_seed=255,this.wmidx=0,this.wmileft=_i,this.set_wm_trigger(),this.melcstate=0,this.melclen=Sn[0],this.melcorder=1<<this.melclen},tabrand:function(){return this.tabrand_seed++,Dg[this.tabrand_seed&255]}};function ye(){this.rgb_state=new Gn,this.model_8bpc=new bn(8),this.model_5bpc=new bn(5),this.channels=[];var e;for(e=0;e<4;e++)if(this.channels[e]=new ch(this.model_8bpc,this.model_5bpc),!this.channels[e]){console.log("quic: failed to create channel");return}}ye.prototype={type:0,width:0,height:0,io_idx:0,io_available_bits:0,io_word:0,io_next_word:0,io_now:0,io_end:0,rows_completed:0};ye.prototype.reste=function(e){return this.rgb_state.reste(),this.io_now=e,this.io_end=this.io_now.length,this.io_idx=0,this.rows_completed=0,!0};ye.prototype.read_io_word=function(){if(this.io_idx>=this.io_end)throw"quic: out of data";this.io_next_word=this.io_now[this.io_idx++]|this.io_now[this.io_idx++]<<8|this.io_now[this.io_idx++]<<16|this.io_now[this.io_idx++]<<24};ye.prototype.decode_eatbits=function(e){this.io_word=this.io_word<<e;var t=this.io_available_bits-e;t>=0?(this.io_available_bits=t,this.io_word|=this.io_next_word>>>this.io_available_bits):(t=-1*t,this.io_word|=this.io_next_word<<t,this.read_io_word(),this.io_available_bits=32-t,this.io_word|=this.io_next_word>>>this.io_available_bits)};ye.prototype.decode_eat32bits=function(){this.decode_eatbits(16),this.decode_eatbits(16)};ye.prototype.reste_channels=function(e){var t;for(t=0;t<4;t++)if(!this.channels[t].reste(e))return!1;return!0};ye.prototype.quic_decode_begin=function(e){if(!this.reste(e))return!1;this.io_idx=0,this.io_next_word=this.io_now[this.io_idx++]|this.io_now[this.io_idx++]<<8|this.io_now[this.io_idx++]<<16|this.io_now[this.io_idx++]<<24,this.io_word=this.io_next_word,this.io_available_bits=0;var t=this.io_word;if(this.decode_eat32bits(),t!=1128879441)return console.log("quic: bad magic "+t.toString(16)),!1;var i=this.io_word;if(this.decode_eat32bits(),i!=0)return console.log("quic: bad version "+i.toString(16)),!1;this.type=this.io_word,this.decode_eat32bits(),this.width=this.io_word,this.decode_eat32bits(),this.height=this.io_word,this.decode_eat32bits();var s=Tg(this.type);return!!this.reste_channels(s)};ye.prototype.quic_rgb32_uncompress_row0_seg=function(e,t,i,s,r,n){var o,a=3,l,c;if(e)o=e+this.rgb_state.waitcnt;else{t[$]=0,l=0;do c=dt(this.channels[l].buckets_ptrs[this.channels[l].correlate_row.zero].bestcode,this.io_word),this.channels[l].correlate_row.row[0]=c.rc,t[2-l]=Se.xlatL2U[c.rc]&255,this.decode_eatbits(c.codewordlen);while(++l<a);if(this.rgb_state.waitcnt)--this.rgb_state.waitcnt;else{this.rgb_state.waitcnt=this.rgb_state.tabrand()&s,l=0;do this.channels[l].buckets_ptrs[this.channels[l].correlate_row.zero].update_model_8bpc(this.rgb_state,this.channels[l].correlate_row.row[0],r);while(++l<a)}o=++e+this.rgb_state.waitcnt}for(;o<i;){for(;e<=o;e++){t[e*q+$]=0,l=0;do c=dt(this.channels[l].buckets_ptrs[this.channels[l].correlate_row.row[e-1]].bestcode,this.io_word),this.channels[l].correlate_row.row[e]=c.rc,t[e*q+(2-l)]=Se.xlatL2U[c.rc]+t[(e-1)*q+(2-l)]&n,this.decode_eatbits(c.codewordlen);while(++l<a)}l=0;do this.channels[l].buckets_ptrs[this.channels[l].correlate_row.row[o-1]].update_model_8bpc(this.rgb_state,this.channels[l].correlate_row.row[o],r);while(++l<a);o=e+(this.rgb_state.tabrand()&s)}for(;e<i;e++){t[e*q+$]=0,l=0;do c=dt(this.channels[l].buckets_ptrs[this.channels[l].correlate_row.row[e-1]].bestcode,this.io_word),this.channels[l].correlate_row.row[e]=c.rc,t[e*q+(2-l)]=Se.xlatL2U[c.rc]+t[(e-1)*q+(2-l)]&n,this.decode_eatbits(c.codewordlen);while(++l<a)}this.rgb_state.waitcnt=o-i};ye.prototype.quic_rgb32_uncompress_row0=function(e){for(var t=8,i=255,s=0,r=this.width;Gt>this.rgb_state.wmidx&&this.rgb_state.wmileft<=r;)this.rgb_state.wmileft&&(this.quic_rgb32_uncompress_row0_seg(s,e,s+this.rgb_state.wmileft,Je[this.rgb_state.wmidx],t,i),s+=this.rgb_state.wmileft,r-=this.rgb_state.wmileft),this.rgb_state.wmidx++,this.rgb_state.set_wm_trigger(),this.rgb_state.wmileft=_i;r&&(this.quic_rgb32_uncompress_row0_seg(s,e,s+r,Je[this.rgb_state.wmidx],t,i),Gt>this.rgb_state.wmidx&&(this.rgb_state.wmileft-=r))};ye.prototype.quic_rgb32_uncompress_row_seg=function(e,t,i,s,r,n){var o=3,a=Je[this.rgb_state.wmidx],l,c=0,d=0,p=0,f;if(i)d=i+this.rgb_state.waitcnt;else{t[$]=0,f=0;do l=dt(this.channels[f].buckets_ptrs[this.channels[f].correlate_row.zero].bestcode,this.io_word),this.channels[f].correlate_row.row[0]=l.rc,t[2-f]=Se.xlatL2U[this.channels[f].correlate_row.row[0]]+e[2-f]&n,this.decode_eatbits(l.codewordlen);while(++f<o);if(this.rgb_state.waitcnt)--this.rgb_state.waitcnt;else{this.rgb_state.waitcnt=this.rgb_state.tabrand()&a,f=0;do this.channels[f].buckets_ptrs[this.channels[f].correlate_row.zero].update_model_8bpc(this.rgb_state,this.channels[f].correlate_row.row[0],r);while(++f<o)}d=++i+this.rgb_state.waitcnt}for(;;){for(var g=0;d<s&&!g;){for(;i<=d&&!g;i++){var u=i*q,_=(i-1)*q,S=(i-2)*q;if(e[_+st]==e[u+st]&&e[_+rt]==e[u+rt]&&e[_+nt]==e[u+nt]&&c!=i&&i>2&&t[_+st]==t[S+st]&&t[_+rt]==t[S+rt]&&t[_+nt]==t[S+nt]){for(this.rgb_state.waitcnt=d-i,c=i,p=i+this.decode_run(this.rgb_state);i<p;i++){var u=i*q,_=(i-1)*q;t[u+$]=0,t[u+st]=t[_+st],t[u+rt]=t[_+rt],t[u+nt]=t[_+nt]}if(i==s)return;d=i+this.rgb_state.waitcnt,g=1;break}f=0,t[u+$]=0;do{var v=this.channels[f],P=v.correlate_row;l=dt(v.buckets_ptrs[P.row[i-1]].bestcode,this.io_word),P.row[i]=l.rc,t[u+(2-f)]=Se.xlatL2U[l.rc]+(t[_+(2-f)]+e[u+(2-f)]>>1)&n,this.decode_eatbits(l.codewordlen)}while(++f<o)}if(g)break;f=0;do this.channels[f].buckets_ptrs[this.channels[f].correlate_row.row[d-1]].update_model_8bpc(this.rgb_state,this.channels[f].correlate_row.row[d],r);while(++f<o);d=i+(this.rgb_state.tabrand()&a)}for(;i<s&&!g;i++){var u=i*q,_=(i-1)*q,S=(i-2)*q;if(e[_+st]==e[u+st]&&e[_+rt]==e[u+rt]&&e[_+nt]==e[u+nt]&&c!=i&&i>2&&t[_+st]==t[S+st]&&t[_+rt]==t[S+rt]&&t[_+nt]==t[S+nt]){for(this.rgb_state.waitcnt=d-i,c=i,p=i+this.decode_run(this.rgb_state);i<p;i++){var u=i*q,_=(i-1)*q;t[u+$]=0,t[u+st]=t[_+st],t[u+rt]=t[_+rt],t[u+nt]=t[_+nt]}if(i==s)return;d=i+this.rgb_state.waitcnt,g=1;break}t[u+$]=0,f=0;do l=dt(this.channels[f].buckets_ptrs[this.channels[f].correlate_row.row[i-1]].bestcode,this.io_word),this.channels[f].correlate_row.row[i]=l.rc,t[u+(2-f)]=Se.xlatL2U[l.rc]+(t[_+(2-f)]+e[u+(2-f)]>>1)&n,this.decode_eatbits(l.codewordlen);while(++f<o)}if(!g){this.rgb_state.waitcnt=d-s;return}}};ye.prototype.decode_run=function(e){var t=0;do{var i,s=~(this.io_word>>>24)>>>0&255,r=lh[s];for(i=1;i<=r;i++)t+=e.melcorder,e.melcstate<32&&(e.melclen=Sn[++e.melcstate],e.melcorder=1<<e.melclen);if(r!=8){this.decode_eatbits(r+1);break}this.decode_eatbits(8)}while(!0);return e.melclen&&(t+=this.io_word>>>32-e.melclen,this.decode_eatbits(e.melclen)),e.melcstate&&(e.melclen=Sn[--e.melcstate],e.melcorder=1<<e.melclen),t};ye.prototype.quic_rgb32_uncompress_row=function(e,t){for(var i=8,s=255,r=0,n=this.width;Gt>this.rgb_state.wmidx&&this.rgb_state.wmileft<=n;)this.rgb_state.wmileft&&(this.quic_rgb32_uncompress_row_seg(e,t,r,r+this.rgb_state.wmileft,i,s),r+=this.rgb_state.wmileft,n-=this.rgb_state.wmileft),this.rgb_state.wmidx++,this.rgb_state.set_wm_trigger(),this.rgb_state.wmileft=_i;n&&(this.quic_rgb32_uncompress_row_seg(e,t,r,r+n,i,s),Gt>this.rgb_state.wmidx&&(this.rgb_state.wmileft-=n))};ye.prototype.quic_four_uncompress_row0_seg=function(e,t,i,s,r,n,o,a){var l,c;for(t==0?(c=dt(e.buckets_ptrs[i.zero].bestcode,this.io_word),i.row[0]=c.rc,s[$]=Se.xlatL2U[c.rc],this.decode_eatbits(c.codewordlen),e.state.waitcnt?--e.state.waitcnt:(e.state.waitcnt=e.state.tabrand()&n,e.buckets_ptrs[i.zero].update_model_8bpc(e.state,i.row[0],o)),l=++t+e.state.waitcnt):l=t+e.state.waitcnt;l<r;){for(var d;t<=l;t++)d=e.buckets_ptrs[i.row[t-1]],c=dt(d.bestcode,this.io_word),i.row[t]=c.rc,s[t*q+$]=Se.xlatL2U[c.rc]+s[(t-1)*q+$]&a,this.decode_eatbits(c.codewordlen);d.update_model_8bpc(e.state,i.row[l],o),l=t+(e.state.tabrand()&n)}for(;t<r;t++)c=dt(e.buckets_ptrs[i.row[t-1]].bestcode,this.io_word),i.row[t]=c.rc,s[t*q+$]=Se.xlatL2U[c.rc]+s[(t-1)*q+$]&a,this.decode_eatbits(c.codewordlen);e.state.waitcnt=l-r};ye.prototype.quic_four_uncompress_row0=function(e,t){for(var i=8,s=255,r=e.correlate_row,n=0,o=this.width;Gt>e.state.wmidx&&e.state.wmileft<=o;)e.state.wmileft&&(this.quic_four_uncompress_row0_seg(e,n,r,t,n+e.state.wmileft,Je[e.state.wmidx],i,s),n+=e.state.wmileft,o-=e.state.wmileft),e.state.wmidx++,e.state.set_wm_trigger(),e.state.wmileft=_i;o&&(this.quic_four_uncompress_row0_seg(e,n,r,t,n+o,Je[e.state.wmidx],i,s),Gt>e.state.wmidx&&(e.state.wmileft-=o))};ye.prototype.quic_four_uncompress_row_seg=function(e,t,i,s,r,n,o,a){var l=Je[e.state.wmidx],c,d=0,p,f;for(r==0?(f=dt(e.buckets_ptrs[t.zero].bestcode,this.io_word),t.row[0]=f.rc,s[$]=Se.xlatL2U[f.rc]+i[$]&a,this.decode_eatbits(f.codewordlen),e.state.waitcnt?--e.state.waitcnt:(e.state.waitcnt=e.state.tabrand()&l,e.buckets_ptrs[t.zero].update_model_8bpc(e.state,t.row[0],o)),c=++r+e.state.waitcnt):c=r+e.state.waitcnt;;){for(var g=0;c<n&&!g;){for(var u;r<=c&&!g;r++){var _=r*q,S=(r-1)*q,v=(r-2)*q;if(i[S+$]==i[_+$]&&d!=r&&r>2&&s[S+$]==s[v+$]){for(e.state.waitcnt=c-r,d=r,p=r+this.decode_run(e.state);r<p;r++){var _=r*q,S=(r-1)*q;s[_+$]=s[S+$]}if(r==n)return;c=r+e.state.waitcnt,g=1;break}u=e.buckets_ptrs[t.row[r-1]],f=dt(u.bestcode,this.io_word),t.row[r]=f.rc,s[_+$]=Se.xlatL2U[f.rc]+(s[S+$]+i[_+$]>>1)&a,this.decode_eatbits(f.codewordlen)}if(g)break;u.update_model_8bpc(e.state,t.row[c],o),c=r+(e.state.tabrand()&l)}for(;r<n&&!g;r++){var _=r*q,S=(r-1)*q,v=(r-2)*q;if(i[S+$]==i[_+$]&&d!=r&&r>2&&s[S+$]==s[v+$]){for(e.state.waitcnt=c-r,d=r,p=r+this.decode_run(e.state);r<p;r++){var _=r*q,S=(r-1)*q;s[_+$]=s[S+$]}if(r==n)return;c=r+e.state.waitcnt,g=1;break}f=dt(e.buckets_ptrs[t.row[r-1]].bestcode,this.io_word),t.row[r]=f.rc,s[_+$]=Se.xlatL2U[f.rc]+(s[S+$]+i[_+$]>>1)&a,this.decode_eatbits(f.codewordlen)}if(!g){e.state.waitcnt=c-n;return}}};ye.prototype.quic_four_uncompress_row=function(e,t,i){for(var s=8,r=255,n=e.correlate_row,o=0,a=this.width;Gt>e.state.wmidx&&e.state.wmileft<=a;)e.state.wmileft&&(this.quic_four_uncompress_row_seg(e,n,t,i,o,o+e.state.wmileft,s,r),o+=e.state.wmileft,a-=e.state.wmileft),e.state.wmidx++,e.state.set_wm_trigger(),e.state.wmileft=_i;a&&(this.quic_four_uncompress_row_seg(e,n,t,i,o,o+a,s,r),Gt>e.state.wmidx&&(e.state.wmileft-=a))};ye.prototype.quic_decode=function(e,t){var i;switch(this.type){case Ne.QUIC_IMAGE_TYPE_RGB32:case Ne.QUIC_IMAGE_TYPE_RGB24:for(this.channels[0].correlate_row.zero=0,this.channels[1].correlate_row.zero=0,this.channels[2].correlate_row.zero=0,this.quic_rgb32_uncompress_row0(e),this.rows_completed++,i=1;i<this.height;i++){var s=e;e=s.subarray(t),this.channels[0].correlate_row.zero=this.channels[0].correlate_row.row[0],this.channels[1].correlate_row.zero=this.channels[1].correlate_row.row[0],this.channels[2].correlate_row.zero=this.channels[2].correlate_row.row[0],this.quic_rgb32_uncompress_row(s,e),this.rows_completed++}break;case Ne.QUIC_IMAGE_TYPE_RGB16:return console.log(`quic: unsupported output format
`),!1;case Ne.QUIC_IMAGE_TYPE_RGBA:for(this.channels[0].correlate_row.zero=0,this.channels[1].correlate_row.zero=0,this.channels[2].correlate_row.zero=0,this.quic_rgb32_uncompress_row0(e),this.channels[3].correlate_row.zero=0,this.quic_four_uncompress_row0(this.channels[3],e),this.rows_completed++,i=1;i<this.height;i++){var s=e;e=s.subarray(t),this.channels[0].correlate_row.zero=this.channels[0].correlate_row.row[0],this.channels[1].correlate_row.zero=this.channels[1].correlate_row.row[0],this.channels[2].correlate_row.zero=this.channels[2].correlate_row.row[0],this.quic_rgb32_uncompress_row(s,e),this.channels[3].correlate_row.zero=this.channels[3].correlate_row.row[0],this.quic_four_uncompress_row(Ft.channels[3],s,e),this.rows_completed++}break;case Ne.QUIC_IMAGE_TYPE_GRAY:return console.log(`quic: unsupported output format
`),!1;case Ne.QUIC_IMAGE_TYPE_INVALID:default:return console.log(`quic: bad image type
`),!1}return!0};ye.prototype.simple_quic_decode=function(e){var t=4;if(this.quic_decode_begin(e)&&!(this.type!=Ne.QUIC_IMAGE_TYPE_RGB32&&this.type!=Ne.QUIC_IMAGE_TYPE_RGB24&&this.type!=Ne.QUIC_IMAGE_TYPE_RGBA)){var i=new Uint8Array(this.width*this.height*4);if(i[0]=69,this.quic_decode(i,this.width*t))return i}};function dh(){}dh.prototype={from_dv:function(e,t,i){if(!Ft)throw"quic: no quic encoder";this.data_size=e.getUint32(t,!0),t+=4;var s=new Uint8Array(i.slice(t));return this.outptr=Ft.simple_quic_decode(s),this.outptr&&(this.type=Ft.type,this.width=Ft.width,this.height=Ft.height),t+=s.length,t}};function Lg(e,t){var i=e.createImageData(t.width,t.height),s;for(s=0;s<i.width*i.height*4;s+=4)i.data[s+0]=t.outptr[s+2],i.data[s+1]=t.outptr[s+1],i.data[s+2]=t.outptr[s+0],t.type!==Ne.QUIC_IMAGE_TYPE_RGBA?i.data[s+3]=255:i.data[s+3]=255-t.outptr[s+3];return i}if(Ca){Ca=!1,xa(Se,8,wa),xa(kg,5,wa);var ds,Mr,us,Dr;for(Mr=us=1,Dr=8,ds=0;ds<256;++ds)lh[ds]=Dr,--us,us==0&&(us=Mr,--Dr,Mr*=2);if(Ft=new ye,!Ft)throw"quic: failed to create encoder"}function uh(){}uh.prototype={from_dv:function(e,t,i){return this.type=e.getUint8(t,!0),t++,this.id=e.getUint8(t,!0),t++,t}};function ni(){}ni.prototype={from_dv:function(e,t,i){return this.top=e.getUint32(t,!0),t+=4,this.left=e.getUint32(t,!0),t+=4,this.bottom=e.getUint32(t,!0),t+=4,this.right=e.getUint32(t,!0),t+=4,t},is_same_size:function(e){return this.bottom-this.top==e.bottom-e.top&&this.right-this.left==e.right-e.left}};function _h(){}_h.prototype={from_dv:function(e,t,i){var s;for(this.num_rects=e.getUint32(t,!0),t+=4,this.num_rects>0&&(this.rects=[]),s=0;s<this.num_rects;s++)this.rects[s]=new ni,t=this.rects[s].from_dv(e,t,i);return t}};function Js(){}Js.prototype={from_dv:function(e,t,i){return this.type=e.getUint8(t,!0),t++,this.type==m.SPICE_CLIP_TYPE_RECTS&&(this.rects=new _h,t=this.rects.from_dv(e,t,i)),t}};function fh(){}fh.prototype={from_dv:function(e,t,i){return this.id=e.getUint64(t,!0),t+=8,this.type=e.getUint8(t,!0),t++,this.flags=e.getUint8(t,!0),t++,this.width=e.getUint32(t,!0),t+=4,this.height=e.getUint32(t,!0),t+=4,t}};function ph(){}ph.prototype={from_dv:function(e,t,i){var s;for(this.unique=e.getUint64(t,!0),t+=8,this.num_ents=e.getUint16(t,!0),t+=2,this.ents=[],s=0;s<this.num_ents;s++)this.ents[s]=e.getUint32(t,!0),t+=4;return t}};function mh(){}mh.prototype={from_dv:function(e,t,i){if(this.format=e.getUint8(t,!0),t++,this.flags=e.getUint8(t,!0),t++,this.x=e.getUint32(t,!0),t+=4,this.y=e.getUint32(t,!0),t+=4,this.stride=e.getUint32(t,!0),t+=4,this.flags&m.SPICE_BITMAP_FLAGS_PAL_FROM_CACHE)this.palette_id=e.getUint64(t,!0),t+=8;else{var s=e.getUint32(t,!0);t+=4,s==0?this.palette=null:(this.palette=new ph,this.palette.from_dv(e,s,i))}return this.data=i.slice(t),t+=this.data.byteLength,t}};function er(){}er.prototype={from_dv:function(e,t,i){if(this.descriptor=new fh,t=this.descriptor.from_dv(e,t,i),this.descriptor.type==m.SPICE_IMAGE_TYPE_LZ_RGB){this.lz_rgb=new Object,this.lz_rgb.length=e.getUint32(t,!0),t+=4;var s=t;this.lz_rgb.magic="";for(var r=3;r>=0;r--)this.lz_rgb.magic+=String.fromCharCode(e.getUint8(t+r));t+=4,this.lz_rgb.version=e.getUint32(t),t+=4,this.lz_rgb.type=e.getUint32(t),t+=4,this.lz_rgb.width=e.getUint32(t),t+=4,this.lz_rgb.height=e.getUint32(t),t+=4,this.lz_rgb.stride=e.getUint32(t),t+=4,this.lz_rgb.top_down=e.getUint32(t),t+=4;var n=t-s;this.lz_rgb.data=i.slice(t,this.lz_rgb.length+t-n),t+=this.lz_rgb.data.byteLength}if(this.descriptor.type==m.SPICE_IMAGE_TYPE_BITMAP&&(this.bitmap=new mh,t=this.bitmap.from_dv(e,t,i)),this.descriptor.type==m.SPICE_IMAGE_TYPE_SURFACE&&(this.surface_id=e.getUint32(t,!0),t+=4),this.descriptor.type==m.SPICE_IMAGE_TYPE_JPEG&&(this.jpeg=new Object,this.jpeg.data_size=e.getUint32(t,!0),t+=4,this.jpeg.data=i.slice(t),t+=this.jpeg.data.byteLength),this.descriptor.type==m.SPICE_IMAGE_TYPE_JPEG_ALPHA){this.jpeg_alpha=new Object,this.jpeg_alpha.flags=e.getUint8(t,!0),t+=1,this.jpeg_alpha.jpeg_size=e.getUint32(t,!0),t+=4,this.jpeg_alpha.data_size=e.getUint32(t,!0),t+=4,this.jpeg_alpha.data=i.slice(t,this.jpeg_alpha.jpeg_size+t),t+=this.jpeg_alpha.data.byteLength,this.jpeg_alpha.alpha=new Object,this.jpeg_alpha.alpha.length=this.jpeg_alpha.data_size-this.jpeg_alpha.jpeg_size;var s=t;this.jpeg_alpha.alpha.magic="";for(var r=3;r>=0;r--)this.jpeg_alpha.alpha.magic+=String.fromCharCode(e.getUint8(t+r));t+=4,this.jpeg_alpha.alpha.version=e.getUint32(t),t+=4,this.jpeg_alpha.alpha.type=e.getUint32(t),t+=4,this.jpeg_alpha.alpha.width=e.getUint32(t),t+=4,this.jpeg_alpha.alpha.height=e.getUint32(t),t+=4,this.jpeg_alpha.alpha.stride=e.getUint32(t),t+=4,this.jpeg_alpha.alpha.top_down=e.getUint32(t),t+=4;var n=t-s;this.jpeg_alpha.alpha.data=i.slice(t,this.jpeg_alpha.alpha.length+t-n),t+=this.jpeg_alpha.alpha.data.byteLength}return this.descriptor.type==m.SPICE_IMAGE_TYPE_QUIC&&(this.quic=new dh,t=this.quic.from_dv(e,t,i)),t}};function Wn(){}Wn.prototype={from_dv:function(e,t,i){this.flags=e.getUint8(t,!0),t++,this.pos=new tr,t=this.pos.from_dv(e,t,i);var s=e.getUint32(t,!0);return t+=4,s==0?(this.bitmap=null,t):(this.bitmap=new er,this.bitmap.from_dv(e,s,i))}};function gh(){}gh.prototype={from_dv:function(e,t,i){var s=e.getUint32(t,!0);return t+=4,s==0?this.pat=null:(this.pat=new er,this.pat.from_dv(e,s,i)),this.pos=new tr,this.pos.from_dv(e,t,i)}};function vh(){}vh.prototype={from_dv:function(e,t,i){return this.type=e.getUint8(t,!0),t++,this.type==m.SPICE_BRUSH_TYPE_SOLID?(this.color=e.getUint32(t,!0),t+=4):this.type==m.SPICE_BRUSH_TYPE_PATTERN&&(this.pattern=new gh,t=this.pattern.from_dv(e,t,i)),t}};function Sh(){}Sh.prototype={from_dv:function(e,t,i){return this.brush=new vh,t=this.brush.from_dv(e,t,i),this.rop_descriptor=e.getUint16(t,!0),t+=2,this.mask=new Wn,this.mask.from_dv(e,t,i)}};function bh(){}bh.prototype={from_dv:function(e,t,i){var s=e.getUint32(t,!0);return t+=4,s==0?this.src_bitmap=null:(this.src_bitmap=new er,this.src_bitmap.from_dv(e,s,i)),this.src_area=new ni,t=this.src_area.from_dv(e,t,i),this.rop_descriptor=e.getUint16(t,!0),t+=2,this.scale_mode=e.getUint8(t,!0),t++,this.mask=new Wn,this.mask.from_dv(e,t,i)}};function $n(){}$n.prototype={from_dv:function(e,t,i){return this.x=e.getUint16(t,!0),t+=2,this.y=e.getUint16(t,!0),t+=2,t}};function tr(){}tr.prototype={from_dv:function(e,t,i){return this.x=e.getUint32(t,!0),t+=4,this.y=e.getUint32(t,!0),t+=4,t}};function yh(){}yh.prototype={from_dv:function(e,t,i){return this.unique=e.getUint64(t,!0),t+=8,this.type=e.getUint8(t,!0),t++,this.width=e.getUint16(t,!0),t+=2,this.height=e.getUint16(t,!0),t+=2,this.hot_spot_x=e.getUint16(t,!0),t+=2,this.hot_spot_y=e.getUint16(t,!0),t+=2,t}};function Vn(){}Vn.prototype={from_dv:function(e,t,i){return this.flags=e.getUint16(t,!0),t+=2,this.flags&m.SPICE_CURSOR_FLAGS_NONE?this.header=null:(this.header=new yh,t=this.header.from_dv(e,t,i),this.data=i.slice(t),t+=this.data.byteLength),t}};function Ch(){}Ch.prototype={from_dv:function(e,t,i){return this.surface_id=e.getUint32(t,!0),t+=4,this.width=e.getUint32(t,!0),t+=4,this.height=e.getUint32(t,!0),t+=4,this.format=e.getUint32(t,!0),t+=4,this.flags=e.getUint32(t,!0),t+=4,t}};var C={KEY_Escape:1,KEY_1:2,KEY_2:3,KEY_3:4,KEY_4:5,KEY_5:6,KEY_6:7,KEY_7:8,KEY_8:9,KEY_9:10,KEY_0:11,KEY_Minus:12,KEY_Equal:13,KEY_BackSpace:14,KEY_Tab:15,KEY_Q:16,KEY_W:17,KEY_E:18,KEY_R:19,KEY_T:20,KEY_Y:21,KEY_U:22,KEY_I:23,KEY_O:24,KEY_P:25,KEY_LBrace:26,KEY_RBrace:27,KEY_Enter:28,KEY_LCtrl:29,KEY_A:30,KEY_S:31,KEY_D:32,KEY_F:33,KEY_G:34,KEY_H:35,KEY_J:36,KEY_K:37,KEY_L:38,KEY_SemiColon:39,KEY_Quote:40,KEY_Tilde:41,KEY_ShiftL:42,KEY_BSlash:43,KEY_Z:44,KEY_X:45,KEY_C:46,KEY_V:47,KEY_B:48,KEY_N:49,KEY_M:50,KEY_Comma:51,KEY_Period:52,KEY_Slash:53,KEY_KP_Multiply:55,KEY_Alt:56,KEY_Space:57,KEY_CapsLock:58,KEY_F1:59,KEY_F2:60,KEY_F3:61,KEY_F4:62,KEY_F5:63,KEY_F6:64,KEY_F7:65,KEY_F8:66,KEY_F9:67,KEY_F10:68,KEY_NumLock:69,KEY_ScrollLock:70,KEY_KP_7:71,KEY_KP_8:72,KEY_KP_9:73,KEY_KP_4:75,KEY_KP_5:76,KEY_KP_6:77,KEY_KP_Plus:78,KEY_KP_1:79,KEY_KP_2:80,KEY_KP_3:81,KEY_KP_0:82,KEY_KP_Decimal:83,KEY_F11:87,KEY_F12:88,KEY_Delete:21472,KEY_PrintScreen:14304};const y=[];y.Escape=1;y.Digit1=2;y.Digit2=3;y.Digit3=4;y.Digit4=5;y.Digit5=6;y.Digit6=7;y.Digit7=8;y.Digit8=9;y.Digit9=10;y.Digit0=11;y.Minus=12;y.Equal=13;y.Backspace=14;y.Tab=15;y.KeyQ=16;y.KeyW=17;y.KeyE=18;y.KeyR=19;y.KeyT=20;y.KeyY=21;y.KeyU=22;y.KeyI=23;y.KeyO=24;y.KeyP=25;y.BracketLeft=26;y.BracketRight=27;y.Enter=28;y.ControlLeft=29;y.KeyA=30;y.KeyS=31;y.KeyD=32;y.KeyF=33;y.KeyG=34;y.KeyH=35;y.KeyJ=36;y.KeyK=37;y.KeyL=38;y.Semicolon=39;y.Quote=40;y.Backquote=41;y.ShiftLeft=42;y.Backslash=43;y.KeyZ=44;y.KeyX=45;y.KeyC=46;y.KeyV=47;y.KeyB=48;y.KeyN=49;y.KeyM=50;y.Comma=51;y.Period=52;y.Slash=53;y.ShiftRight=54;y.NumpadMultiply=55;y.AltLeft=56;y.Space=57;y.CapsLock=58;y.F1=59;y.F2=60;y.F3=61;y.F4=62;y.F5=63;y.F6=64;y.F7=65;y.F8=66;y.F9=67;y.F10=68;y.Pause=69;y.ScrollLock=70;y.Numpad7=71;y.Numpad8=72;y.Numpad9=73;y.NumpadSubtract=74;y.Numpad4=75;y.Numpad5=76;y.Numpad6=77;y.NumpadAdd=78;y.Numpad1=79;y.Numpad2=80;y.Numpad3=81;y.Numpad0=82;y.NumpadDecimal=83;y.PrintScreen=84;y.IntlBackslash=86;y.F11=87;y.F12=88;y.NumpadEqual=89;y.F13=100;y.F14=101;y.F15=102;y.F16=103;y.F17=104;y.F18=105;y.F19=106;y.F20=107;y.F21=108;y.F22=109;y.F23=110;y.KanaMode=112;y.IntlRo=115;y.F24=118;y.Convert=121;y.NonConvert=123;y.IntlYen=125;y.NumpadComma=126;y.MediaTrackPrevious=4320;y.MediaTrackNext=6624;y.NumpadEnter=7392;y.ControlRight=7648;y.AudioVolumeMute=8416;y.LaunchApp2=8672;y.MediaPlayPause=8928;y.MediaStop=9440;y.VolumeDown=12e3;y.VolumeUp=12512;y.BrowserHome=13024;y.NumpadDivide=13792;y.PrintScreen=14304;y.AltRight=14560;y.NumLock=17888;y.Pause=18144;y.Home=18400;y.ArrowUp=18656;y.PageUp=18912;y.ArrowLeft=19424;y.ArrowRight=19936;y.End=20448;y.ArrowDown=20704;y.PageDown=20960;y.Insert=21216;y.Delete=21472;y.MetaLeft=23520;y.MetaRight=23776;y.ContextMenu=24032;y.Power=24288;y.BrowserSearch=26080;y.BrowserFavorites=26336;y.BrowserRefresh=26592;y.BrowserStop=26848;y.BrowserForward=27104;y.BrowserBack=27360;y.LaunchApp1=27616;y.LaunchMail=27872;y.MediaSelect=28128;var Ng=0,Bg="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";function Og(e){return String.fromCharCode.apply(null,new Uint16Array(e))}var A=[];A[49]=C.KEY_1;A[50]=C.KEY_2;A[51]=C.KEY_3;A[52]=C.KEY_4;A[53]=C.KEY_5;A[54]=C.KEY_6;A[55]=C.KEY_7;A[56]=C.KEY_8;A[57]=C.KEY_9;A[48]=C.KEY_0;A[145]=C.KEY_ScrollLock;A[103]=C.KEY_KP_7;A[104]=C.KEY_KP_8;A[105]=C.KEY_KP_9;A[100]=C.KEY_KP_4;A[101]=C.KEY_KP_5;A[102]=C.KEY_KP_6;A[107]=C.KEY_KP_Plus;A[97]=C.KEY_KP_1;A[98]=C.KEY_KP_2;A[99]=C.KEY_KP_3;A[96]=C.KEY_KP_0;A[109]=C.KEY_Minus;A[110]=C.KEY_KP_Decimal;A[191]=C.KEY_Slash;A[190]=C.KEY_Period;A[188]=C.KEY_Comma;A[220]=C.KEY_BSlash;A[192]=C.KEY_Tilde;A[222]=C.KEY_Quote;A[219]=C.KEY_LBrace;A[221]=C.KEY_RBrace;A[81]=C.KEY_Q;A[87]=C.KEY_W;A[69]=C.KEY_E;A[82]=C.KEY_R;A[84]=C.KEY_T;A[89]=C.KEY_Y;A[85]=C.KEY_U;A[73]=C.KEY_I;A[79]=C.KEY_O;A[80]=C.KEY_P;A[65]=C.KEY_A;A[83]=C.KEY_S;A[68]=C.KEY_D;A[70]=C.KEY_F;A[71]=C.KEY_G;A[72]=C.KEY_H;A[74]=C.KEY_J;A[75]=C.KEY_K;A[76]=C.KEY_L;A[90]=C.KEY_Z;A[88]=C.KEY_X;A[67]=C.KEY_C;A[86]=C.KEY_V;A[66]=C.KEY_B;A[78]=C.KEY_N;A[77]=C.KEY_M;A[32]=C.KEY_Space;A[13]=C.KEY_Enter;A[27]=C.KEY_Escape;A[8]=C.KEY_BackSpace;A[9]=C.KEY_Tab;A[16]=C.KEY_ShiftL;A[17]=C.KEY_LCtrl;A[18]=C.KEY_Alt;A[20]=C.KEY_CapsLock;A[44]=C.KEY_SysReqest;A[144]=C.KEY_NumLock;A[112]=C.KEY_F1;A[113]=C.KEY_F2;A[114]=C.KEY_F3;A[115]=C.KEY_F4;A[116]=C.KEY_F5;A[117]=C.KEY_F6;A[118]=C.KEY_F7;A[119]=C.KEY_F8;A[120]=C.KEY_F9;A[121]=C.KEY_F10;A[122]=C.KEY_F11;A[123]=C.KEY_F12;A[42]=99;A[19]=101;A[111]=224|C.KEY_Slash<<8;A[106]=224|C.KEY_KP_Multiply<<8;A[36]=224|C.KEY_KP_7<<8;A[38]=224|C.KEY_KP_8<<8;A[33]=224|C.KEY_KP_9<<8;A[37]=224|C.KEY_KP_4<<8;A[39]=224|C.KEY_KP_6<<8;A[35]=224|C.KEY_KP_1<<8;A[40]=224|C.KEY_KP_2<<8;A[34]=224|C.KEY_KP_3<<8;A[45]=224|C.KEY_KP_0<<8;A[46]=224|C.KEY_KP_Decimal<<8;A[91]=23520;A[92]=23776;A[93]=24032;var ir=[];ir[173]=C.KEY_Minus;ir[61]=C.KEY_Equal;ir[59]=C.KEY_SemiColon;var sr=[];sr[189]=C.KEY_Minus;sr[187]=C.KEY_Equal;sr[186]=C.KEY_SemiColon;var ut=[];ut.Numpad0=C.KEY_0;ut.Numpad1=C.KEY_1;ut.Numpad2=C.KEY_2;ut.Numpad3=C.KEY_3;ut.Numpad4=C.KEY_4;ut.Numpad5=C.KEY_5;ut.Numpad6=C.KEY_6;ut.Numpad7=C.KEY_7;ut.Numpad8=C.KEY_8;ut.Numpad9=C.KEY_9;function wh(e,t,i){return i&&i.getModifierState("NumLock")&&ut[t]!==void 0?ut[t]:y[t]!==void 0?y[t]:A[e]===void 0?navigator.userAgent.indexOf("Firefox")!=-1?ir[e]:sr[e]:A[e]}function Ug(e,t,i){var s=wh(e,t,i);return s===void 0?(alert("no map for "+e),0):s}function Fg(e,t,i){var s=wh(e,t,i);return s===void 0?0:s<256?s|128:s|32768}function Eh(e){var t="[networkState "+e.networkState+"|readyState "+e.readyState+"|error "+e.error+"|seeking "+e.seeking+"|duration "+e.duration+"|paused "+e.paused+"|ended "+e.error+"|buffered "+jg(e.buffered)+"]";return t}function jg(e){var t;if(e){var i=e.length;t="{len "+i,i>0&&(t+="; start "+e.start(0)+"; end "+e.end(i-1)),t+="}"}else t="N/A";return t}function Ps(e,t){this.magic=m.SPICE_MAGIC,this.major_version=m.SPICE_VERSION_MAJOR,this.minor_version=m.SPICE_VERSION_MINOR,this.size=0,e!==void 0&&this.from_buffer(e,t)}Ps.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.magic="";for(var s=0;s<4;s++)this.magic+=String.fromCharCode(i.getUint8(t+s));t+=4,this.major_version=i.getUint32(t,!0),t+=4,this.minor_version=i.getUint32(t,!0),t+=4,this.size=i.getUint32(t,!0),t+=4},to_buffer:function(e,t){t=t||0;for(var i=new j(e),s=0;s<4;s++)i.setUint8(t+s,this.magic.charCodeAt(s));t+=4,i.setUint32(t,this.major_version,!0),t+=4,i.setUint32(t,this.minor_version,!0),t+=4,i.setUint32(t,this.size,!0),t+=4},buffer_size:function(){return 16}};function xh(e,t){this.connection_id=0,this.channel_type=0,this.channel_id=0,this.common_caps=[],this.channel_caps=[],e!==void 0&&this.from_buffer(e,t)}xh.prototype={from_buffer:function(e,t){t=t||0;var i,s=t,r=new j(e);this.connection_id=r.getUint32(t,!0),t+=4,this.channel_type=r.getUint8(t,!0),t++,this.channel_id=r.getUint8(t,!0),t++;var n=r.getUint32(t,!0);t+=4;var o=r.getUint32(t,!0);t+=4;var a=r.getUint32(t,!0);for(t+=4,t=s+a,this.common_caps=[],i=0;i<n;i++)this.common_caps.unshift(r.getUint32(t,!0)),t+=4;for(this.channel_caps=[],i=0;i<o;i++)this.channel_caps.unshift(r.getUint32(t,!0)),t+=4},to_buffer:function(e,t){t=t||0;var i=t,s,r=new j(e);for(r.setUint32(t,this.connection_id,!0),t+=4,r.setUint8(t,this.channel_type,!0),t++,r.setUint8(t,this.channel_id,!0),t++,r.setUint32(t,this.common_caps.length,!0),t+=4,r.setUint32(t,this.channel_caps.length,!0),t+=4,r.setUint32(t,t-i+4,!0),t+=4,s=0;s<this.common_caps.length;s++)r.setUint32(t,this.common_caps[s],!0),t+=4;for(s=0;s<this.channel_caps.length;s++)r.setUint32(t,this.channel_caps[s],!0),t+=4},buffer_size:function(){return 18+4*this.common_caps.length+4*this.channel_caps.length}};function Ih(e,t){this.error=0,this.pub_key=void 0,this.common_caps=[],this.channel_caps=[],e!==void 0&&this.from_buffer(e,t)}Ih.prototype={from_buffer:function(e,t){t=t||0;var i,s=t,r=new j(e);this.error=r.getUint32(t,!0),t+=4,this.pub_key=Eg(e,t),t+=m.SPICE_TICKET_PUBKEY_BYTES;var n=r.getUint32(t,!0);t+=4;var o=r.getUint32(t,!0);t+=4;var a=r.getUint32(t,!0);for(t+=4,t=s+a,this.common_caps=[],i=0;i<n;i++)this.common_caps.unshift(r.getUint32(t,!0)),t+=4;for(this.channel_caps=[],i=0;i<o;i++)this.channel_caps.unshift(r.getUint32(t,!0)),t+=4}};function Ah(e,t){this.auth_mechanism=0,this.encrypted_data=void 0}Ah.prototype={to_buffer:function(e,t){t=t||0;var i,s=new j(e);for(s.setUint32(t,this.auth_mechanism,!0),t+=4,i=0;i<m.SPICE_TICKET_KEY_PAIR_LENGTH/8;i++)this.encrypted_data&&i<this.encrypted_data.length?s.setUint8(t,this.encrypted_data[i],!0):s.setUint8(t,0,!0),t++},buffer_size:function(){return 4+m.SPICE_TICKET_KEY_PAIR_LENGTH/8}};function Cn(e,t){this.auth_code=0,e!==void 0&&this.from_buffer(e,t)}Cn.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.auth_code=i.getUint32(t,!0),t+=4},buffer_size:function(){return 4}};function le(e,t){this.type=0,this.size=0,this.data=void 0,e!==void 0&&this.from_buffer(e,t)}le.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.type=i.getUint16(t,!0),t+=2,this.size=i.getUint32(t,!0),t+=4,e.byteLength>t&&(this.data=e.slice(t),t+=this.data.byteLength)},to_buffer:function(e,t){t=t||0;var i,s=new j(e);if(s.setUint16(t,this.type,!0),t+=2,s.setUint32(t,this.data?this.data.byteLength:0,!0),t+=4,this.data&&this.data.byteLength>0){var r=new Uint8Array(this.data);for(i=0;i<r.length;i++,t++)s.setUint8(t,r[i],!0)}},build_msg:function(e,t){this.type=e,this.size=t.buffer_size(),this.data=new ArrayBuffer(this.size),t.to_buffer(this.data)},buffer_size:function(){return this.data?6+this.data.byteLength:6}};function Ph(e,t){this.num_of_channels=0,this.channels=[],e!==void 0&&this.from_buffer(e,t)}Ph.prototype={from_buffer:function(e,t){t=t||0;var i,s=new j(e);for(this.num_of_channels=s.getUint32(t,!0),t+=4,i=0;i<this.num_of_channels;i++){var r=new uh;t=r.from_dv(s,t,e),this.channels.push(r)}}};function rr(e){return(e[0]>>m.VD_AGENT_CAP_CLIPBOARD_SELECTION&1)!=0}function kh(e,t){this.has_clipboard_selection=rr(t),this.type=e}kh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);this.has_clipboard_selection&&(i.setUint32(t,0,!0),t+=4),i.setUint32(t,this.type,!0),t+=4},buffer_size:function(){return this.has_clipboard_selection?8:4}};function Mh(e,t){this.has_clipboard_selection=rr(t);const i=new DataView(e.data);var s=this.has_clipboard_selection?4:0;this.type=i.getUint32(s,!0),s+=4,this.payload=e.data.slice(s)}Mh.prototype={get_text:function(){return new TextDecoder("utf-8").decode(this.payload)}};function Dh(e,t){this.has_clipboard_selection=rr(t),this.type=e}Dh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);this.has_clipboard_selection&&(i.setUint32(t,0,!0),t+=4),i.setUint32(t,this.type,!0),t+=4},buffer_size:function(){return this.has_clipboard_selection?8:4}};function Th(e,t,i){this.has_clipboard_selection=rr(i),this.type=e,this.text=t}Th.prototype={to_buffer:function(e,t){t=t||0;const i=new j(e);this.has_clipboard_selection&&(i.setUint32(t,0,!0),t+=4),i.setUint32(t,this.type,!0),t+=4;const s=new TextEncoder().encode(this.text);new Uint8Array(e,t,s.byteLength).set(s),t+=s.byteLength},buffer_size:function(){const e=new TextEncoder().encode(this.text).byteLength;return(this.has_clipboard_selection?8:4)+e}};function Rh(e,t){this.from_buffer(e,t)}Rh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.session_id=i.getUint32(t,!0),t+=4,this.display_channels_hint=i.getUint32(t,!0),t+=4,this.supported_mouse_modes=i.getUint32(t,!0),t+=4,this.current_mouse_mode=i.getUint32(t,!0),t+=4,this.agent_connected=i.getUint32(t,!0),t+=4,this.agent_tokens=i.getUint32(t,!0),t+=4,this.multi_media_time=i.getUint32(t,!0),t+=4,this.ram_hint=i.getUint32(t,!0),t+=4}};function Lh(e,t){this.from_buffer(e,t)}Lh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.supported_modes=i.getUint16(t,!0),t+=2,this.current_mode=i.getUint16(t,!0),t+=2}};function Nh(e,t){this.from_buffer(e,t)}Nh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.protocol=i.getUint32(t,!0),t+=4,this.type=i.getUint32(t,!0),t+=4,this.opaque=i.getUint64(t,!0),t+=8,this.size=i.getUint32(t,!0),t+=4,e.byteLength>t&&(this.data=e.slice(t),t+=this.data.byteLength)}};function wn(e,t){this.from_buffer(e,t)}wn.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.num_tokens=i.getUint32(t,!0),t+=4}};function Bh(e,t){this.from_buffer(e,t)}Bh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.generation=i.getUint32(t,!0),t+=4,this.window=i.getUint32(t,!0),t+=4}};function Oh(e){this.generation=e.generation}Oh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.generation,!0),t+=4},buffer_size:function(){return 4}};function Uh(e){this.mode=e}Uh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint16(t,this.mode,!0),t+=2},buffer_size:function(){return 2}};function Fh(e){this.num_tokens=e}Fh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.num_tokens,!0),t+=4},buffer_size:function(){return 4}};function jh(e,t){this.protocol=m.VD_AGENT_PROTOCOL,this.type=e,this.opaque=0,this.size=t.buffer_size(),this.data=t}jh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.protocol,!0),t+=4,i.setUint32(t,this.type,!0),t+=4,i.setUint64(t,this.opaque,!0),t+=8,i.setUint32(t,this.size,!0),t+=4,this.data.to_buffer(e,t)},buffer_size:function(){return 20+this.data.buffer_size()}};function qn(e,t){t?(this.request=e,this.caps=t):this.from_buffer(e)}qn.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.request,!0),t+=4,i.setUint32(t,this.caps,!0),t+=4},from_buffer:function(e,t){t=t||0;var i=new j(e);return this.request=i.getUint32(t,!0),t+=4,this.caps=i.getUint32(t,!0),t+=4,t},buffer_size:function(){return 8}};function Kh(e,t,i,s,r,n){this.num_mon=1,this.flags=e,this.width=t,this.height=i,this.depth=s,this.x=r,this.y=n}Kh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.num_mon,!0),t+=4,i.setUint32(t,this.flags,!0),t+=4,i.setUint32(t,this.height,!0),t+=4,i.setUint32(t,this.width,!0),t+=4,i.setUint32(t,this.depth,!0),t+=4,i.setUint32(t,this.x,!0),t+=4,i.setUint32(t,this.y,!0),t+=4},buffer_size:function(){return 28}};function Xn(e,t){t?(this.id=e,this.result=t):this.from_buffer(e)}Xn.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.id,!0),t+=4,i.setUint32(t,this.result,!0),t+=4},from_buffer:function(e,t){t=t||0;var i=new j(e);return this.id=i.getUint32(t,!0),t+=4,this.result=i.getUint32(t,!0),t+=4,t},buffer_size:function(){return 8}};function zh(e,t,i){this.id=e,this.string=`[vdagent-file-xfer]
name=`+t+`
size=`+i+`
`}zh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint32(t,this.id,!0),t+=4;for(var s=0;s<this.string.length;s++,t++)i.setUint8(t,this.string.charCodeAt(s))},buffer_size:function(){return 4+this.string.length+1}};function Yh(e,t,i){this.id=e,this.size=t,this.data=i}Yh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);if(i.setUint32(t,this.id,!0),t+=4,i.setUint64(t,this.size,!0),t+=8,this.data&&this.data.byteLength>0)for(var s=new Uint8Array(this.data),r=0;r<s.length;r++,t++)i.setUint8(t,s[r])},buffer_size:function(){return 12+this.size}};function Hh(e,t){this.from_buffer(e,t)}Hh.prototype={from_buffer:function(e,t){t=t||0;var i,s=new j(e);for(this.time_stamp=s.getUint64(t,!0),t+=8,this.severity=s.getUint32(t,!0),t+=4,this.visibility=s.getUint32(t,!0),t+=4,this.what=s.getUint32(t,!0),t+=4,this.message_len=s.getUint32(t,!0),t+=4,this.message="",i=0;i<this.message_len;i++){var r=s.getUint8(t,!0);t++,this.message+=String.fromCharCode(r)}}};function Gh(){this.pixmap_cache_id=1,this.glz_dictionary_id=0,this.pixmap_cache_size=10*1024*1024,this.glz_dictionary_window_size=0}Gh.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);i.setUint8(t,this.pixmap_cache_id,!0),t++,i.setUint64(t,this.pixmap_cache_size,!0),t+=8,i.setUint8(t,this.glz_dictionary_id,!0),t++,i.setUint32(t,this.glz_dictionary_window_size,!0),t+=4},buffer_size:function(){return 14}};function es(){}es.prototype={from_dv:function(e,t,i){return this.surface_id=e.getUint32(t,!0),t+=4,this.box=new ni,t=this.box.from_dv(e,t,i),this.clip=new Js,this.clip.from_dv(e,t,i)}};function Wh(e,t){this.from_buffer(e,t)}Wh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);return this.base=new es,t=this.base.from_dv(i,t,e),this.data=new bh,this.data.from_dv(i,t,e)}};function $h(e,t){this.from_buffer(e,t)}$h.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);return this.base=new es,t=this.base.from_dv(i,t,e),this.data=new Sh,this.data.from_dv(i,t,e)}};function Vh(e,t){this.from_buffer(e,t)}Vh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);return this.base=new es,t=this.base.from_dv(i,t,e),this.src_pos=new tr,this.src_pos.from_dv(i,t,e)}};function qh(e,t){this.from_buffer(e,t)}qh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);return this.surface=new Ch,this.surface.from_dv(i,t,e)}};function Xh(e,t){this.from_buffer(e,t)}Xh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.surface_id=i.getUint32(t,!0),t+=4}};function Qh(e,t){this.from_buffer(e,t)}Qh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);return this.keyboard_modifiers=i.getUint16(t,!0),t+=2,t}};function Zh(e,t){this.from_buffer(e,t)}Zh.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);return this.keyboard_modifiers=i.getUint16(t,!0),t+=2,t}};function Jh(e,t){this.from_buffer(e,t)}Jh.prototype={from_buffer:function(e,t,i){t=t||0;var s=new j(e);return this.position=new $n,t=this.position.from_dv(s,t,i),this.trail_length=s.getUint16(t,!0),t+=2,this.trail_frequency=s.getUint16(t,!0),t+=2,this.visible=s.getUint8(t,!0),t++,this.cursor=new Vn,this.cursor.from_dv(s,t,e)}};function ec(e,t){this.from_buffer(e,t)}ec.prototype={from_buffer:function(e,t,i){t=t||0;var s=new j(e);return this.time=s.getUint32(t,!0),t+=4,e.byteLength>t&&(this.data=e.slice(t),t+=this.data.byteLength),t}};function tc(e,t){this.from_buffer(e,t)}tc.prototype={from_buffer:function(e,t,i){t=t||0;var s=new j(e);return this.time=s.getUint32(t,!0),t+=4,this.mode=s.getUint16(t,!0),t+=2,e.byteLength>t&&(this.data=e.slice(t),t+=this.data.byteLength),t}};function ic(e,t){this.from_buffer(e,t)}ic.prototype={from_buffer:function(e,t,i){t=t||0;var s=new j(e);return this.channels=s.getUint32(t,!0),t+=4,this.format=s.getUint16(t,!0),t+=2,this.frequency=s.getUint32(t,!0),t+=4,this.time=s.getUint32(t,!0),t+=4,t}};function sc(e,t){this.from_buffer(e,t)}sc.prototype={from_buffer:function(e,t,i){t=t||0;var s=new j(e);return this.position=new $n,t=this.position.from_dv(s,t,i),this.visible=s.getUint8(t,!0),t++,this.cursor=new Vn,this.cursor.from_dv(s,t,e)}};function rc(e){const t=document.getElementById(e.screen_id),i=t?.clientWidth,s=t?.firstChild.width;return!s||!i?1:i>0&&s>i?s/i:1}function nr(e,t){if(this.display_id=0,this.buttons_state=e.buttons_state,t){const i=rc(e);this.x=t.offsetX*i,this.y=t.offsetY*i,e.mousex=t.offsetX*i,e.mousey=t.offsetY*i}else this.x=this.y=this.buttons_state=0}nr.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);return i.setUint32(t,this.x,!0),t+=4,i.setUint32(t,this.y,!0),t+=4,i.setUint16(t,this.buttons_state,!0),t+=2,i.setUint8(t,this.display_id,!0),t+=1,t},buffer_size:function(){return 11}};function Qn(e,t){if(this.display_id=0,this.buttons_state=e.buttons_state,t){const i=rc(e);this.x=t.offsetX*i,this.y=t.offsetY*i,e.mousex!==void 0&&(this.x-=e.mousex*i,this.y-=e.mousey*i),e.mousex=t.offsetX*i,e.mousey=t.offsetY*i}else this.x=this.y=this.buttons_state=0}Qn.prototype.to_buffer=nr.prototype.to_buffer;Qn.prototype.buffer_size=nr.prototype.buffer_size;function ts(e,t){t?(this.button=t.button+1,this.buttons_state=1<<t.button,e.buttons_state=this.buttons_state):(this.button=m.SPICE_MOUSE_BUTTON_LEFT,this.buttons_state=m.SPICE_MOUSE_BUTTON_MASK_LEFT)}ts.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);return i.setUint8(t,this.button,!0),t++,i.setUint16(t,this.buttons_state,!0),t+=2,t},buffer_size:function(){return 3}};function or(e,t){t?(this.button=t.button+1,this.buttons_state=0,e.buttons_state=this.buttons_state):(this.button=m.SPICE_MOUSE_BUTTON_LEFT,this.buttons_state=0)}or.prototype.to_buffer=ts.prototype.to_buffer;or.prototype.buffer_size=ts.prototype.buffer_size;function bi(e){e?this.code=Ug(e.keyCode,e.code,e):this.code=0}bi.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);return i.setUint32(t,this.code,!0),t+=4,t},buffer_size:function(){return 4}};function ar(e){e?this.code=Fg(e.keyCode,e.code,e):this.code=0}ar.prototype.to_buffer=bi.prototype.to_buffer;ar.prototype.buffer_size=bi.prototype.buffer_size;function nc(e,t){this.from_buffer(e,t)}nc.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.surface_id=i.getUint32(t,!0),t+=4,this.id=i.getUint32(t,!0),t+=4,this.flags=i.getUint8(t,!0),t+=1,this.codec_type=i.getUint8(t,!0),t+=1,this.stamp=i.getUint64(t,!0),t+=8,this.stream_width=i.getUint32(t,!0),t+=4,this.stream_height=i.getUint32(t,!0),t+=4,this.src_width=i.getUint32(t,!0),t+=4,this.src_height=i.getUint32(t,!0),t+=4,this.dest=new ni,t=this.dest.from_dv(i,t,e),this.clip=new Js,this.clip.from_dv(i,t,e)}};function Zn(e,t){}Zn.prototype={from_dv:function(e,t,i){return this.id=e.getUint32(t,!0),t+=4,this.multi_media_time=e.getUint32(t,!0),t+=4,t}};function oc(e,t){this.from_buffer(e,t)}oc.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.base=new Zn,t=this.base.from_dv(i,t,e),this.data_size=i.getUint32(t,!0),t+=4,this.data=i.u8.subarray(t,t+this.data_size)}};function ac(e,t){this.from_buffer(e,t)}ac.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.base=new Zn,t=this.base.from_dv(i,t,e),this.width=i.getUint32(t,!0),t+=4,this.height=i.getUint32(t,!0),t+=4,this.dest=new ni,t=this.dest.from_dv(i,t,e),this.data_size=i.getUint32(t,!0),t+=4,this.data=i.u8.subarray(t,t+this.data_size)}};function lc(e,t){this.from_buffer(e,t)}lc.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.id=i.getUint32(t,!0),t+=4,this.clip=new Js,this.clip.from_dv(i,t,e)}};function hc(e,t){this.from_buffer(e,t)}hc.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.id=i.getUint32(t,!0),t+=4}};function cc(e,t){this.from_buffer(e,t)}cc.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e);this.stream_id=i.getUint32(t,!0),t+=4,this.unique_id=i.getUint32(t,!0),t+=4,this.max_window_size=i.getUint32(t,!0),t+=4,this.timeout_ms=i.getUint32(t,!0),t+=4}};function dc(e,t){this.stream_id=e,this.unique_id=t,this.start_frame_mm_time=0,this.end_frame_mm_time=0,this.num_frames=0,this.num_drops=0,this.last_frame_delay=0,this.audio_delay=-1}dc.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);return i.setUint32(t,this.stream_id,!0),t+=4,i.setUint32(t,this.unique_id,!0),t+=4,i.setUint32(t,this.start_frame_mm_time,!0),t+=4,i.setUint32(t,this.end_frame_mm_time,!0),t+=4,i.setUint32(t,this.num_frames,!0),t+=4,i.setUint32(t,this.num_drops,!0),t+=4,i.setUint32(t,this.last_frame_delay,!0),t+=4,i.setUint32(t,this.audio_delay,!0),t+=4,t},buffer_size:function(){return 32}};function uc(e,t){this.count=0,this.resources=[],this.from_buffer(e,t)}uc.prototype={from_buffer:function(e,t){var i;t=t||0;var s=new j(e);for(this.count=s.getUint16(t,!0),t+=2,i=0;i<this.count;i++)this.resources[i]={},this.resources[i].type=s.getUint8(t,!0),t++,this.resources[i].id=s.getUint64(t,!0),t+=8}};function _c(e,t){this.from_buffer(e,t)}_c.prototype={from_buffer:function(e,t){t=t||0;var i=new j(e),s=i.getUint32(t,!0);t+=4;var r=i.getUint32(t,!0);t+=4,this.opened=i.getUint8(t,!0),t+=1,this.name=e.slice(r,r+s-1)}};var fc=Array(256),pc=0;function Kg(){var e,t,i;for(t=0;t<256;t++){for(e=t,i=0;i<8;i++)e&1?e=(3988292384^e>>>1)>>>0&4294967295:e=e>>>1;fc[t]=e}pc=1}function zg(e,t,i,s){var r=e,n;for(pc||Kg(),n=0;n<s;n++)r=fc[(r^t[i+n])&255]^r>>>8;return r}function Yg(e,t,i){return zg(4294967295,e,t,i)^4294967295}function Jn(e,t,i){var s=new Uint8Array(e);return Yg(s,t,i)}function mc(e,t){this.width=e,this.height=t,this.depth=8,this.type=6,this.compression=0,this.filter=0,this.interlace=0}mc.prototype={to_buffer:function(e,t){t=t||0;var i=t,s=new j(e);return s.setUint32(t,this.buffer_size()-12),t+=4,s.setUint8(t,73),t++,s.setUint8(t,72),t++,s.setUint8(t,68),t++,s.setUint8(t,82),t++,s.setUint32(t,this.width),t+=4,s.setUint32(t,this.height),t+=4,s.setUint8(t,this.depth),t++,s.setUint8(t,this.type),t++,s.setUint8(t,this.compression),t++,s.setUint8(t,this.filter),t++,s.setUint8(t,this.interlace),t++,s.setUint32(t,Jn(e,i+4,this.buffer_size()-8)),t+=4,t},buffer_size:function(){return 25}};function gc(){this.s1=1,this.s2=0}gc.prototype.update=function(e){this.s1+=e,this.s1%=65521,this.s2+=this.s1,this.s2%=65521};function vc(e,t,i){if(i.byteLength>65535)throw new Error("Cannot handle more than 64K");this.data=i,this.width=e,this.height=t}vc.prototype={to_buffer:function(e,t){t=t||0;var i=t,s,r,n,o=new j(e),a=new gc;o.setUint32(t,this.buffer_size()-12),t+=4,o.setUint8(t,73),t++,o.setUint8(t,68),t++,o.setUint8(t,65),t++,o.setUint8(t,84),t++,o.setUint8(t,120),t++,o.setUint8(t,1),t++,o.setUint8(t,128),t++,o.setUint16(t,this.data.byteLength+this.height),t+=2,o.setUint16(t,~(this.data.byteLength+this.height)),t+=2;var l=new Uint8Array(this.data);for(n=0,r=0;r<this.height;r++)for(o.setUint8(t,0),t++,a.update(0),s=0;s<this.width&&n<this.data.byteLength;s++)a.update(l[n]),o.setUint8(t,l[n++]),t++,a.update(l[n]),o.setUint8(t,l[n++]),t++,a.update(l[n]),o.setUint8(t,l[n++]),t++,a.update(l[n]),o.setUint8(t,l[n++]),t++;return o.setUint16(t,a.s2),t+=2,o.setUint16(t,a.s1),t+=2,o.setUint32(t,Jn(e,i+4,this.buffer_size()-8)),t+=4,t},buffer_size:function(){return 12+this.data.byteLength+this.height+4+2+1+2+2}};function Sc(){}Sc.prototype={to_buffer:function(e,t){t=t||0;var i=t,s=new j(e);return s.setUint32(t,this.buffer_size()-12),t+=4,s.setUint8(t,73),t++,s.setUint8(t,69),t++,s.setUint8(t,78),t++,s.setUint8(t,68),t++,s.setUint32(t,Jn(e,i+4,this.buffer_size()-8)),t+=4,t},buffer_size:function(){return 12}};function Hg(e,t,i){var s,r=new mc(e,t),n=new vc(e,t,i),o=new Sc,a=new ArrayBuffer(r.buffer_size()+n.buffer_size()+o.buffer_size()),l=r.to_buffer(a);l=n.to_buffer(a,l),l=o.to_buffer(a,l);var c=new Uint8Array(a),d="";for(s=0;s<l;s++)d+="%",c[s]<16&&(d+="0"),d+=c[s].toString(16);return"%89PNG%0D%0A%1A%0A"+d}var Re={cursors:new Array,unknown_cursors:new Array,warned:!1,add_cursor:function(e,t){Re.cursors[e]=t},unknown_cursor:function(e,t){Re.warned||(Re.warned=!0,alert(`Internet Explorer does not support dynamic cursors.  This page will now simulate cursors with images, which will be imperfect.  We recommend using Chrome or Firefox instead.  

If you need to use Internet Explorer, you can create a static cursor file for each cursor your application uses.  View the console log for more information on creating static cursors for your environment.`)),Re.unknown_cursors[e]||(Re.unknown_cursors[e]=t,console.log("Unknown cursor.  Simulation required.  To avoid simulation for this cursor, create and include a custom javascript file, and add the following line:"),console.log('SpiceCursorSimulator.add_cursor("'+e+'"), "<your filename here>.cur");'),console.log("And then run following command, redirecting output into <your filename here>.cur:"),console.log(`php -r "echo urldecode('`+t+`');"`))},simulate_cursor:function(e,t,i,s){var r=pg(s+" "+t.header.hot_spot_x+" "+t.header.hot_spot_y);if(typeof Re.cursors<"u"&&typeof Re.cursors[r]<"u"){var n="url("+Re.cursors[r]+"), default";i.style.cursor=n}window.getComputedStyle(i,null).cursor=="auto"?(Re.unknown_cursor(r,Re.create_icondir(t.header.width,t.header.height,t.data.byteLength,t.header.hot_spot_x,t.header.hot_spot_y)+s),document.getElementById(e.parent.screen_id).style.cursor="none",e.spice_simulated_cursor||(e.spice_simulated_cursor=document.createElement("img"),e.spice_simulated_cursor.style.position="absolute",e.spice_simulated_cursor.style.display="none",e.spice_simulated_cursor.style.overflow="hidden",e.spice_simulated_cursor.spice_screen=document.getElementById(e.parent.screen_id),e.spice_simulated_cursor.addEventListener("mousemove",Re.handle_sim_mousemove),e.spice_simulated_cursor.spice_screen.appendChild(e.spice_simulated_cursor)),e.spice_simulated_cursor.src="data:image/png,"+s,e.spice_simulated_cursor.spice_hot_x=t.header.hot_spot_x,e.spice_simulated_cursor.spice_hot_y=t.header.hot_spot_y,e.spice_simulated_cursor.style.pointerEvents="none"):e.spice_simulated_cursor&&(e.spice_simulated_cursor.spice_screen.removeChild(e.spice_simulated_cursor),delete e.spice_simulated_cursor)},handle_sim_mousemove:function(e){var t=Re.duplicate_mouse_event(e,this.spice_screen);return this.spice_screen.dispatchEvent(t)},duplicate_mouse_event:function(e,t){var i=document.createEvent("mouseevent");return i.initMouseEvent(e.type,!0,!0,e.view,e.detail,e.screenX,e.screenY,e.clientX,e.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,e.button,e.relatedTarget),i},ICONDIR:function(){},ICONDIRENTRY:function(e,t,i,s,r){this.width=e,this.height=t,this.bytes=i,this.hot_x=s,this.hot_y=r},create_icondir:function(e,t,i,s,r){var n,o=new Re.ICONDIR,a=new Re.ICONDIRENTRY(e,t,i,s,r),l=new ArrayBuffer(o.buffer_size()+a.buffer_size()),c=o.to_buffer(l);c=a.to_buffer(l,c);var d=new Uint8Array(l),p="";for(n=0;n<c;n++)p+="%",d[n]<16&&(p+="0"),p+=d[n].toString(16);return p}};Re.ICONDIR.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);return i.setUint16(t,0,!0),t+=2,i.setUint16(t,2,!0),t+=2,i.setUint16(t,1,!0),t+=2,t},buffer_size:function(){return 6}};Re.ICONDIRENTRY.prototype={to_buffer:function(e,t){t=t||0;var i=new j(e);return i.setUint8(t,this.width),t++,i.setUint8(t,this.height),t++,i.setUint8(t,0),t++,i.setUint8(t,0),t++,i.setUint16(t,this.hot_x,!0),t+=2,i.setUint16(t,this.hot_y,!0),t+=2,i.setUint32(t,this.bytes,!0),t+=4,i.setUint32(t,t+4,!0),t+=4,t},buffer_size:function(){return 16}};function eo(e,t){this.sc=e,this.callback=t,this.needed=0,this.size=0,this.buffers=[],this.sc.ws.wire_reader=this,this.sc.ws.binaryType="arraybuffer",this.sc.ws.addEventListener("message",Gg)}eo.prototype={inbound:function(e){if(this.needed==0){this.buffers.push(e),this.size+=e.byteLength;return}for(this.buffers.length==0&&e.byteLength>=this.needed?(e.byteLength>this.needed&&(this.size=e.byteLength-this.needed,this.buffers.push(e.slice(this.needed)),e=e.slice(0,this.needed)),this.callback.call(this.sc,e,this.saved_msg_header||void 0)):(this.buffers.push(e),this.size+=e.byteLength);this.size>=this.needed;){for(var t=0,i=new ArrayBuffer(this.needed),s=new Uint8Array(i);t<i.byteLength&&this.buffers.length>0;){var r=this.buffers.shift();if(!r)return;var n=new Uint8Array(r),o=i.byteLength-t;if(n.length<=o)s.set(n,t),t+=n.length,this.size-=n.length;else{var a=n.slice(0,o);s.set(a,t),t+=a.length,this.size-=a.length,this.buffers.unshift(n.slice(o))}}this.callback.call(this.sc,i,this.saved_msg_header||void 0)}},request:function(e){this.needed=e},save_header:function(e){this.saved_msg_header=e},clear_header:function(){this.saved_msg_header=void 0}};function Gg(e){eo.prototype.inbound.call(this.wire_reader,e.data)}var Wg=[26,69,223,163],$g=[66,134],Vg=[66,247],qg=[66,242],Xg=[66,243],Qg=[66,130],Zg=[66,135],Jg=[66,133],ev=[24,83,128,103],bc=[21,73,169,102],Aa=[42,215,177],Pa=[77,128],ka=[87,65],tv=[17,77,155,116],iv=[77,187],Ma=[83,171],Da=[83,172],yc=[22,84,174,107],Cc=[174],ks=[215],Ms=[115,197],Ds=[131],Ts=[185],Rs=[136],Ls=[85,170],Ns=[156],Bs=[109,231],Os=[85,238],Us=[170],Fs=[86,187],Ta=[86,170],Ra=[99,162],js=[134],sv=[224],La=[154],Na=[176],Ba=[186],rv=[225],Oa=[181],Ua=[159],nv=[31,67,182,117],Fa=[231],ov=[163],me={CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME:128,OPUS_FREQUENCY:48e3,OPUS_CHANNELS:2,SPICE_PLAYBACK_CODEC:'audio/webm; codecs="opus"',MAX_CLUSTER_TIME:1e3,EXPECTED_PACKET_DURATION:10,GAP_DETECTION_THRESHOLD:50,SPICE_VP8_CODEC:'video/webm; codecs="vp8"'};function oi(e,t,i){var s=128|e;return t.setUint8(i,s),i+1}function J(e,t,i,s){return s=De(e,i,s),s=oi(1,i,s),i.setUint8(s,t),s+1}function Wi(e,t,i,s){return s=De(e,i,s),s=oi(4,i,s),i.setUint32(s,t),s+4}function En(e,t,i,s){return s=De(e,i,s),s=oi(2,i,s),i.setUint16(s,t),s+2}function av(e,t,i,s){return s=De(e,i,s),s=oi(4,i,s),i.setFloat32(s,t),s+4}function wt(e,t,i){t.setUint8(i++,1),t.setUint8(i++,0),t.setUint8(i++,0),t.setUint8(i++,0);for(var s=e&4294967295,r=24;r>=0;r-=8)t.setUint8(i++,s>>r);return i}function De(e,t,i){for(var s=0;s<e.length;s++)t.setUint8(i+s,e[s]);return i+e.length}function lv(e,t,i){for(var s=0;s<e.length;s++)t.setUint8(i+s,e.charCodeAt(s));return i+e.length}function ii(e,t,i,s){return s=De(e,i,s),t.length<127?s=oi(t.length,i,s):s=wt(t.length,i,s),typeof t=="string"?s=lv(t,i,s):s=De(t,i,s),s}function wc(){this.id=Wg,this.Version=1,this.ReadVersion=1,this.MaxIDLength=4,this.MaxSizeLength=8,this.DocType="webm",this.DocTypeVersion=2,this.DocTypeReadVersion=2}wc.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(31,i,t),t=J($g,this.Version,i,t),t=J(Vg,this.ReadVersion,i,t),t=J(qg,this.MaxIDLength,i,t),t=J(Xg,this.MaxSizeLength,i,t),t=ii(Qg,this.DocType,i,t),t=J(Zg,this.DocTypeVersion,i,t),t=J(Jg,this.DocTypeReadVersion,i,t),t},buffer_size:function(){return 39+this.id.length}};function Ec(){this.id=ev}Ec.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),i.setUint8(t++,255),t},buffer_size:function(){return this.id.length+1}};function xc(){this.id=bc,this.timecode_scale=1e6,this.muxing_app="spice",this.writing_app="spice-html5"}xc.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=Wi(Aa,this.timecode_scale,i,t),t=ii(Pa,this.muxing_app,i,t),t=ii(ka,this.writing_app,i,t),t},buffer_size:function(){return this.id.length+8+Aa.length+1+4+Pa.length+1+this.muxing_app.length+ka.length+1+this.writing_app.length}};function Ic(e){this.id=rv,this.sampling_frequency=e,this.channels=me.OPUS_CHANNELS}Ic.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=J(Ua,this.channels,i,t),t=av(Oa,this.sampling_frequency,i,t),t},buffer_size:function(){return this.id.length+8+Oa.length+1+4+Ua.length+1+1}};function Ac(e,t){this.id=sv,this.flag_interlaced=0,this.width=e,this.height=t}Ac.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=J(La,this.flag_interlaced,i,t),t=En(Na,this.width,i,t),t=En(Ba,this.height,i,t),t},buffer_size:function(){return this.id.length+8+La.length+1+1+Na.length+1+2+Ba.length+1+2}};function xn(e,t){this.id=iv,this.pos=t,this.seekid=e}xn.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=oi(this.buffer_size()-1-this.id.length,i,t),t=ii(Ma,this.seekid,i,t),t=En(Da,this.pos,i,t),t},buffer_size:function(){return this.id.length+1+Ma.length+1+this.seekid.length+Da.length+1+2}};function Pc(e,t){this.id=tv,this.info=new xn(bc,e),this.track=new xn(yc,t)}Pc.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=this.info.to_buffer(e,t),t=this.track.to_buffer(e,t),t},buffer_size:function(){return this.id.length+8+this.info.buffer_size()+this.track.buffer_size()}};function kc(){this.id=Cc,this.number=1,this.uid=2,this.type=2,this.flag_enabled=1,this.flag_default=1,this.flag_forced=1,this.flag_lacing=0,this.min_cache=0,this.max_block_addition_id=0,this.codec_decode_all=0,this.seek_pre_roll=0,this.codec_delay=8e7,this.codec_id="A_OPUS",this.audio=new Ic(me.OPUS_FREQUENCY),this.codec_private=[79,112,117,115,72,101,97,100,1,me.OPUS_CHANNELS,0,15,128,187,0,0,0,0,0]}kc.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=J(ks,this.number,i,t),t=J(Ms,this.uid,i,t),t=J(Ts,this.flag_enabled,i,t),t=J(Rs,this.flag_default,i,t),t=J(Ls,this.flag_forced,i,t),t=J(Ns,this.flag_lacing,i,t),t=ii(js,this.codec_id,i,t),t=J(Bs,this.min_cache,i,t),t=J(Os,this.max_block_addition_id,i,t),t=J(Us,this.codec_decode_all,i,t),t=Wi(Ta,this.codec_delay,i,t),t=Wi(Fs,this.seek_pre_roll,i,t),t=J(Ds,this.type,i,t),t=ii(Ra,this.codec_private,i,t),t=this.audio.to_buffer(e,t),t},buffer_size:function(){return this.id.length+8+ks.length+1+1+Ms.length+1+1+Ds.length+1+1+Ts.length+1+1+Rs.length+1+1+Ls.length+1+1+Ns.length+1+1+Bs.length+1+1+Os.length+1+1+Us.length+1+1+Fs.length+1+4+Ta.length+1+4+js.length+this.codec_id.length+1+Ra.length+1+this.codec_private.length+this.audio.buffer_size()}};function Mc(e,t){this.id=Cc,this.number=1,this.uid=1,this.type=1,this.flag_enabled=1,this.flag_default=1,this.flag_forced=1,this.flag_lacing=1,this.min_cache=0,this.max_block_addition_id=0,this.codec_id="V_VP8",this.codec_decode_all=1,this.seek_pre_roll=0,this.video=new Ac(e,t)}Mc.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=J(ks,this.number,i,t),t=J(Ms,this.uid,i,t),t=J(Ts,this.flag_enabled,i,t),t=J(Rs,this.flag_default,i,t),t=J(Ls,this.flag_forced,i,t),t=J(Ns,this.flag_lacing,i,t),t=ii(js,this.codec_id,i,t),t=J(Bs,this.min_cache,i,t),t=J(Os,this.max_block_addition_id,i,t),t=J(Us,this.codec_decode_all,i,t),t=Wi(Fs,this.seek_pre_roll,i,t),t=J(Ds,this.type,i,t),t=this.video.to_buffer(e,t),t},buffer_size:function(){return this.id.length+8+ks.length+1+1+Ms.length+1+1+Ts.length+1+1+Rs.length+1+1+Ls.length+1+1+Ns.length+1+1+js.length+this.codec_id.length+1+Bs.length+1+1+Os.length+1+1+Us.length+1+1+Fs.length+1+4+Ds.length+1+1+this.video.buffer_size()}};function to(e){this.id=yc,this.track_entry=e}to.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),t=wt(this.buffer_size()-8-this.id.length,i,t),t=this.track_entry.to_buffer(e,t),t},buffer_size:function(){return this.id.length+8+this.track_entry.buffer_size()}};function io(e,t){this.id=nv,this.timecode=e,this.data=t}io.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);return t=De(this.id,i,t),i.setUint8(t++,255),t=Wi(Fa,this.timecode,i,t),t},buffer_size:function(){return this.id.length+1+Fa.length+1+4}};function so(e,t,i){this.id=ov,this.timecode=e,this.data=t,this.keyframe=i}so.prototype={to_buffer:function(e,t){t=t||0;var i=new DataView(e);t=De(this.id,i,t),t=wt(this.data.byteLength+4,i,t),t=oi(1,i,t),i.setUint16(t,this.timecode),t+=2,i.setUint8(t,this.keyframe?me.CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME:0),t+=1;for(var s=new Uint8Array(this.data),r=0;r<this.data.byteLength;r++)i.setUint8(t++,s[r]);return t},buffer_size:function(){return this.id.length+8+1+2+1+this.data.byteLength}};function ro(){this.ebml=new wc,this.segment=new Ec,this.seek_head=new Pc(0,0),this.seek_head.info.pos=this.segment.buffer_size()+this.seek_head.buffer_size(),this.info=new xc,this.seek_head.track.pos=this.seek_head.info.pos+this.info.buffer_size()}ro.prototype={to_buffer:function(e,t){return t=t||0,t=this.ebml.to_buffer(e,t),t=this.segment.to_buffer(e,t),t=this.info.to_buffer(e,t),t},buffer_size:function(){return this.ebml.buffer_size()+this.segment.buffer_size()+this.info.buffer_size()}};function $e(e){if(e===void 0||e.uri===void 0||!e.uri)throw new Error("You must specify a uri");if(this.ws=new WebSocket(e.uri),!this.ws.binaryType)throw new Error("WebSocket doesn't support binaryType.  Try a different browser.");if(this.connection_id=e.connection_id!==void 0?e.connection_id:0,this.type=e.type!==void 0?e.type:m.SPICE_CHANNEL_MAIN,this.chan_id=e.chan_id!==void 0?e.chan_id:0,e.parent!==void 0&&(this.parent=e.parent,this.message_id=e.parent.message_id,this.password=e.parent.password),e.screen_id!==void 0&&(this.screen_id=e.screen_id),e.dump_id!==void 0&&(this.dump_id=e.dump_id),e.message_id!==void 0&&(this.message_id=e.message_id),e.password!==void 0&&(this.password=e.password),e.onerror!==void 0&&(this.onerror=e.onerror),e.onsuccess!==void 0&&(this.onsuccess=e.onsuccess),e.onagent!==void 0&&(this.onagent=e.onagent),this.state="connecting",this.ws.parent=this,this.wire_reader=new eo(this,this.process_inbound),this.messages_sent=0,this.warnings=[],this.ws.addEventListener("open",function(t){this.parent.send_hdr(),this.parent.wire_reader.request(Ps.prototype.buffer_size()),this.parent.state="start"}),this.ws.addEventListener("error",function(t){"url"in t.target&&this.parent.log_err("WebSocket error: Can't connect to websocket on URL: "+t.target.url),this.parent.report_error(t)}),this.ws.addEventListener("close",function(t){if(this.parent.state!="closing"&&this.parent.state!="error"&&this.parent.onerror!==void 0){var t;this.parent.state=="connecting"?t=new Error("Connection refused."):this.parent.state=="start"||this.parent.state=="link"?t=new Error("Unexpected protocol mismatch."):this.parent.state=="ticket"?t=new Error("Bad password."):t=new Error("Unexpected close while "+this.parent.state),this.parent.onerror(t),this.parent.log_err(t.toString())}else this.parent?.parent?.onerror!==void 0&&this.parent.parent.onerror(new Error("Connection closed"))}),this.ws.readyState==2||this.ws.readyState==3)throw new Error("Unable to connect to "+e.uri);this.timeout=window.setTimeout(hv,m.SPICE_CONNECT_TIMEOUT,this)}$e.prototype={send_hdr:function(){var e=new Ps,t=new xh;if(t.connection_id=this.connection_id,t.channel_type=this.type,t.channel_id=this.chan_id,t.common_caps.push(1<<m.SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION|1<<m.SPICE_COMMON_CAP_MINI_HEADER),t.channel_type==m.SPICE_CHANNEL_PLAYBACK){var i=0;"MediaSource"in window&&MediaSource.isTypeSupported(me.SPICE_PLAYBACK_CODEC)&&(i|=1<<m.SPICE_PLAYBACK_CAP_OPUS),t.channel_caps.push(i)}else if(t.channel_type==m.SPICE_CHANNEL_MAIN)t.channel_caps.push(1<<m.SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS);else if(t.channel_type==m.SPICE_CHANNEL_DISPLAY){var i=1<<m.SPICE_DISPLAY_CAP_SIZED_STREAM|1<<m.SPICE_DISPLAY_CAP_STREAM_REPORT|1<<m.SPICE_DISPLAY_CAP_MULTI_CODEC|1<<m.SPICE_DISPLAY_CAP_CODEC_MJPEG;"MediaSource"in window&&MediaSource.isTypeSupported(me.SPICE_VP8_CODEC)&&(i|=1<<m.SPICE_DISPLAY_CAP_CODEC_VP8),t.channel_caps.push(i)}e.size=t.buffer_size();var s=new ArrayBuffer(e.buffer_size()+t.buffer_size());e.to_buffer(s),t.to_buffer(s,e.buffer_size()),this.ws.send(s)},send_ticket:function(e){var t=new Ah;t.auth_mechanism=m.SPICE_COMMON_CAP_AUTH_SPICE,t.encrypted_data=e;var i=new ArrayBuffer(t.buffer_size());t.to_buffer(i),this.ws.send(i)},send_msg:function(e){var t=new ArrayBuffer(e.buffer_size());e.to_buffer(t),this.messages_sent++,this.ws.send(t)},process_inbound:function(e,t){if(this.state=="ready")if(t==null){var i=new le(e);i.type>500,i.size==0?(this.process_message(i),this.wire_reader.request(le.prototype.buffer_size())):(this.wire_reader.request(i.size),this.wire_reader.save_header(i))}else t.data=e,this.process_message(t),this.wire_reader.request(le.prototype.buffer_size()),this.wire_reader.save_header(void 0);else if(this.state=="start")if(this.reply_hdr=new Ps(e),this.reply_hdr.magic!=m.SPICE_MAGIC){this.state="error";var s=new Error("Error: magic mismatch: "+this.reply_hdr.magic);this.report_error(s)}else this.wire_reader.request(this.reply_hdr.size),this.state="link";else if(this.state=="link")if(this.reply_link=new Ih(e),this.reply_link.error){this.state="error";var s=new Error("Error: reply link error "+this.reply_link.error);this.report_error(s)}else this.send_ticket(xg(this.reply_link.pub_key,this.password+"\0")),this.state="ticket",this.wire_reader.request(Cn.prototype.buffer_size());else if(this.state=="ticket")if(this.auth_reply=new Cn(e),this.auth_reply.auth_code==m.SPICE_LINK_ERR_OK){if(this.type==m.SPICE_CHANNEL_DISPLAY){var r=new Gh,n=new le;n.build_msg(m.SPICE_MSGC_DISPLAY_INIT,r),this.send_msg(n)}this.state="ready",this.wire_reader.request(le.prototype.buffer_size()),this.timeout&&(window.clearTimeout(this.timeout),delete this.timeout)}else{if(this.state="error",this.auth_reply.auth_code==m.SPICE_LINK_ERR_PERMISSION_DENIED)var s=new Error("Permission denied.");else var s=new Error("Unexpected link error "+this.auth_reply.auth_code);this.report_error(s)}},process_common_messages:function(e){if(e.type==m.SPICE_MSG_SET_ACK){var t=new Bh(e.data);this.ack_window=t.window,this.msgs_until_ack=this.ack_window;var i=new Oh(t),s=new le;return s.build_msg(m.SPICE_MSGC_ACK_SYNC,i),this.send_msg(s),!0}if(e.type==m.SPICE_MSG_PING){var r=new le;return r.type=m.SPICE_MSGC_PONG,e.data&&(r.data=e.data.slice(0,12)),r.size=r.buffer_size(),this.send_msg(r),!0}if(e.type==m.SPICE_MSG_NOTIFY){var n=new Hh(e.data);return n.severity==m.SPICE_NOTIFY_SEVERITY_ERROR?this.log_err(n.message):n.severity==m.SPICE_NOTIFY_SEVERITY_WARN?this.log_warn(n.message):this.log_info(n.message),!0}return!1},process_message:function(e){var t,i=Date.now();if(t=this.process_common_messages(e),t||(this.process_channel_message?(t=this.process_channel_message(e),t||this.log_warn(this.channel_type()+": Unknown message type "+e.type+"!")):this.log_err(this.channel_type()+": No message handlers for this channel; message "+e.type)),this.msgs_until_ack!==void 0&&this.ack_window&&(this.msgs_until_ack--,this.msgs_until_ack<=0)){this.msgs_until_ack=this.ack_window;var s=new le;s.type=m.SPICE_MSGC_ACK,this.send_msg(s)}var r=Date.now()-i;return r>me.GAP_DETECTION_THRESHOLD&&console.log("delta "+this.channel_type()+":"+e.type+" "+r),t},channel_type:function(){return this.type==m.SPICE_CHANNEL_MAIN?"main":this.type==m.SPICE_CHANNEL_DISPLAY?"display":this.type==m.SPICE_CHANNEL_INPUTS?"inputs":this.type==m.SPICE_CHANNEL_CURSOR?"cursor":this.type==m.SPICE_CHANNEL_PLAYBACK?"playback":this.type==m.SPICE_CHANNEL_RECORD?"record":this.type==m.SPICE_CHANNEL_TUNNEL?"tunnel":this.type==m.SPICE_CHANNEL_SMARTCARD?"smartcard":this.type==m.SPICE_CHANNEL_USBREDIR?"usbredir":this.type==m.SPICE_CHANNEL_PORT?"port":this.type==m.SPICE_CHANNEL_WEBDAV?"webdav":"unknown-"+this.type},log_info:function(){var e=Array.prototype.join.call(arguments," ");if(console.log(e),this.message_id){var t=document.createElement("p");t.appendChild(document.createTextNode(e)),t.className+="spice-message-info",document.getElementById(this.message_id).appendChild(t)}},log_warn:function(){var e=Array.prototype.join.call(arguments," ");if(console.log("WARNING: "+e),this.message_id){var t=document.createElement("p");t.appendChild(document.createTextNode(e)),t.className+="spice-message-warning",document.getElementById(this.message_id).appendChild(t)}},log_err:function(){var e=Array.prototype.join.call(arguments," ");if(console.log("ERROR: "+e),this.message_id){var t=document.createElement("p");t.appendChild(document.createTextNode(e)),t.className+="spice-message-error",document.getElementById(this.message_id).appendChild(t)}},known_unimplemented:function(e,t){if(!this.warnings[e]||Ng>1){var i="";i=" [ further notices suppressed ]",this.log_warn("Unimplemented function "+e+"("+t+")"+i),this.warnings[e]=!0}},report_error:function(e){if(this.log_err(e.toString()),this.onerror!=null)this.onerror(e);else throw e},report_success:function(e){this.onsuccess!=null&&this.onsuccess(e)},cleanup:function(){this.timeout&&(window.clearTimeout(this.timeout),delete this.timeout),this.ws&&(this.ws.close(),this.ws=void 0)},handle_timeout:function(){var e=new Error("Connection timed out.");this.report_error(e)}};function hv(e){$e.prototype.handle_timeout.call(e)}function lr(){$e.apply(this,arguments)}lr.prototype=Object.create($e.prototype);lr.prototype.process_channel_message=function(e){if(e.type==m.SPICE_MSG_CURSOR_INIT){var t=new Jh(e.data);return this.parent&&this.parent.inputs&&this.parent.inputs.mouse_mode==m.SPICE_MOUSE_MODE_SERVER&&(this.parent.inputs.mousex=t.position.x,this.parent.inputs.mousey=t.position.y),!0}if(e.type==m.SPICE_MSG_CURSOR_SET){var i=new sc(e.data);return i.flags&m.SPICE_CURSOR_FLAGS_NONE?(document.getElementById(this.parent.screen_id).style.cursor="none",!0):(i.flags>0&&this.log_warn("FIXME: No support for cursor flags "+i.flags),i.cursor.header.type!=m.SPICE_CURSOR_TYPE_ALPHA?(this.log_warn("FIXME: No support for cursor type "+i.cursor.header.type),!1):(this.set_cursor(i.cursor),!0))}return e.type==m.SPICE_MSG_CURSOR_MOVE?(this.known_unimplemented(e.type,"Cursor Move"),!0):e.type==m.SPICE_MSG_CURSOR_HIDE?(document.getElementById(this.parent.screen_id).style.cursor="none",!0):e.type==m.SPICE_MSG_CURSOR_TRAIL?(this.known_unimplemented(e.type,"Cursor Trail"),!0):e.type==m.SPICE_MSG_CURSOR_RESET?(document.getElementById(this.parent.screen_id).style.cursor="auto",!0):e.type==m.SPICE_MSG_CURSOR_INVAL_ONE?(this.known_unimplemented(e.type,"Cursor Inval One"),!0):e.type==m.SPICE_MSG_CURSOR_INVAL_ALL};lr.prototype.set_cursor=function(e){var t=Hg(e.header.width,e.header.height,e.data),i="url(data:image/png,"+t+") "+e.header.hot_spot_x+" "+e.header.hot_spot_y+", default",s=document.getElementById(this.parent.screen_id);s.style.cursor="auto",s.style.cursor=i,window.getComputedStyle(s,null).cursor=="auto"&&Re.simulate_cursor(this,e,s,t)};function hr(e,t){this.id=e,this.file=t}hr.prototype.create_progressbar=function(){var e=this,t=document.createElement("input");this.progressbar_container=document.createElement("div"),this.progressbar=document.createElement("progress"),t.type="button",t.value="Cancel",t.style.float="right",t.onclick=function(){e.cancelled=!0,e.remove_progressbar()},this.progressbar.setAttribute("max",this.file.size),this.progressbar.setAttribute("value",0),this.progressbar.style.width="100%",this.progressbar.style.margin="4px auto",this.progressbar.style.display="inline-block",this.progressbar_container.style.width="90%",this.progressbar_container.style.margin="auto",this.progressbar_container.style.padding="4px",this.progressbar_container.textContent=this.file.name,this.progressbar_container.appendChild(t),this.progressbar_container.appendChild(this.progressbar),document.getElementById("spice-xfer-area").appendChild(this.progressbar_container)};hr.prototype.update_progressbar=function(e){this.progressbar.setAttribute("value",e)};hr.prototype.remove_progressbar=function(){this.progressbar_container&&this.progressbar_container.parentNode&&this.progressbar_container.parentNode.removeChild(this.progressbar_container)};var hi=-1,et=!1,Ye=!1,Di=-1,Pt=!1,kt=!1;function no(){$e.apply(this,arguments),this.mousex=void 0,this.mousey=void 0,this.button_state=0,this.waiting_for_ack=0}no.prototype=Object.create($e.prototype);no.prototype.process_channel_message=function(e){if(e.type==m.SPICE_MSG_INPUTS_INIT){var t=new Qh(e.data);return this.keyboard_modifiers=t.keyboard_modifiers,!0}if(e.type==m.SPICE_MSG_INPUTS_KEY_MODIFIERS){var i=new Zh(e.data);return this.keyboard_modifiers=i.keyboard_modifiers,!0}return e.type==m.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK?(this.waiting_for_ack-=m.SPICE_INPUT_MOTION_ACK_BUNCH,!0):!1};function Dc(e){var t=new le,i;this.sc.mouse_mode==m.SPICE_MOUSE_MODE_CLIENT?(i=new nr(this.sc,e),t.build_msg(m.SPICE_MSGC_INPUTS_MOUSE_POSITION,i)):(i=new Qn(this.sc,e),t.build_msg(m.SPICE_MSGC_INPUTS_MOUSE_MOTION,i)),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.waiting_for_ack<2*m.SPICE_INPUT_MOTION_ACK_BUNCH&&(this.sc.inputs.send_msg(t),this.sc.inputs.waiting_for_ack++),this.sc&&this.sc.cursor&&this.sc.cursor.spice_simulated_cursor&&(this.sc.cursor.spice_simulated_cursor.style.display="block",this.sc.cursor.spice_simulated_cursor.style.left=e.pageX-this.sc.cursor.spice_simulated_cursor.spice_hot_x+"px",this.sc.cursor.spice_simulated_cursor.style.top=e.pageY-this.sc.cursor.spice_simulated_cursor.spice_hot_y+"px",e.preventDefault())}function Tc(e){var t=new ts(this.sc,e),i=new le;i.build_msg(m.SPICE_MSGC_INPUTS_MOUSE_PRESS,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),e.preventDefault()}function Rc(e){return e.preventDefault(),!1}function Lc(e){var t=new or(this.sc,e),i=new le;i.build_msg(m.SPICE_MSGC_INPUTS_MOUSE_RELEASE,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),e.preventDefault()}function Nc(e){var t=new ts,i=new or;e.deltaY<0?t.button=i.button=m.SPICE_MOUSE_BUTTON_UP:t.button=i.button=m.SPICE_MOUSE_BUTTON_DOWN,t.buttons_state=0,i.buttons_state=0;var s=new le;s.build_msg(m.SPICE_MSGC_INPUTS_MOUSE_PRESS,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(s),s.build_msg(m.SPICE_MSGC_INPUTS_MOUSE_RELEASE,i),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(s),e.preventDefault(),window.dispatchEvent(new CustomEvent("spice-wheel",{detail:{wheelEvent:e}}))}function Bc(e){var t=new bi(e),i=new le;Uc(e,t.code,this.sc),i.build_msg(m.SPICE_MSGC_INPUTS_KEY_DOWN,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),e.preventDefault()}function Oc(e){var t=new ar(e),i=new le;Uc(e,t.code,this.sc),i.build_msg(m.SPICE_MSGC_INPUTS_KEY_UP,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(i),e.preventDefault()}function Ke(e,t){var i=new le,s=new bi;s.code=t,i.build_msg(m.SPICE_MSGC_INPUTS_KEY_DOWN,s),e.inputs.send_msg(i),s.code=128|t,i.build_msg(m.SPICE_MSGC_INPUTS_KEY_UP,s),e.inputs.send_msg(i)}function cv(e){e&&e.inputs&&e.inputs.state==="ready"&&(je(!0,C.KEY_LCtrl,e),et=!0,kt=!1,je(!0,C.KEY_Alt,e),Ye=!0,Pt=!1,Ke(e,C.KEY_Delete),setTimeout(()=>{je(!1,C.KEY_LCtrl,e),et=!1,je(!1,C.KEY_Alt,e),Ye=!1},100))}function dv(e){e&&e.inputs&&e.inputs.state==="ready"&&(je(!0,C.KEY_Alt,e),Ye=!0,Pt=!1,je(!1,C.KEY_LCtrl,e),et=!1,kt=!1,Ke(e,C.KEY_F4),setTimeout(()=>{je(!1,C.KEY_Alt,e),Ye=!1},100))}function uv(e){e&&e.inputs&&e.inputs.state==="ready"&&(je(!0,C.KEY_Alt,e),Ye=!0,Pt=!1,je(!1,C.KEY_LCtrl,e),et=!1,kt=!1,Ke(e,C.KEY_Tab),setTimeout(()=>{je(!1,C.KEY_Alt,e),Ye=!1},100))}function _v(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F1)}function fv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F2)}function pv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F3)}function mv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F4)}function gv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F5)}function vv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F6)}function Sv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F7)}function bv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F8)}function yv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F9)}function Cv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F10)}function wv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F11)}function Ev(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_F12)}function xv(e){e&&e.inputs&&e.inputs.state==="ready"&&Ke(e,C.KEY_PrintScreen)}function Iv(e){e&&e.inputs&&e.inputs.state==="ready"&&(Ye=!Ye,Pt=!Pt,je(Ye,C.KEY_Alt,e))}function Av(){return Ye===!0}function Pv(e){e&&e.inputs&&e.inputs.state==="ready"&&(et=!et,kt=!kt,je(et,C.KEY_LCtrl,e))}function kv(){return et===!0}function je(e,t,i){var s=new le;if(e){var r=new bi;r.code=t,s.build_msg(m.SPICE_MSGC_INPUTS_KEY_DOWN,r)}else{var r=new ar;r.code=128|t,s.build_msg(m.SPICE_MSGC_INPUTS_KEY_UP,r)}i.inputs.send_msg(s)}function Uc(e,t,i){hi===-1&&(hi=e.shiftKey,kt||(et=e.ctrlKey),Pt||(Ye=e.altKey),Di=e.metaKey),t===C.KEY_ShiftL?hi=!0:t===C.KEY_Alt?(Ye=!0,Pt=!1):t===C.KEY_LCtrl?(et=!0,kt=!1):t===57525?Di=!0:t===(128|C.KEY_ShiftL)?hi=!1:t===(128|C.KEY_Alt)?(Ye=!1,Pt=!1):t===(128|C.KEY_LCtrl)?(et=!1,kt=!1):t===57525&&(Di=!1),i&&i.inputs&&i.inputs.state==="ready"&&(hi!=e.shiftKey&&(console.log("Shift state out of sync"),je(e.shiftKey,C.KEY_ShiftL,i),hi=e.shiftKey),Ye!=e.altKey&&!Pt&&(console.log("Alt state out of sync"),je(e.altKey,C.KEY_Alt,i),Ye=e.altKey),et!=e.ctrlKey&&!kt&&(console.log("Ctrl state out of sync"),je(e.ctrlKey,C.KEY_LCtrl,i),et=e.ctrlKey),Di!=e.metaKey&&(console.log("Meta state out of sync"),je(e.metaKey,57525,i),Di=e.metaKey))}function Tr(e,t,i,s,r){var n=t,o=0,a,l=0;for(a=e[n++];o*4<i.length;a=e[n++]){var c=o,d=a>>5,p=(a&31)<<8;if(a>=32){var f;if(d--,d==6)do f=e[n++],d+=f;while(f==255);if(f=e[n++],p+=f,f==255&&p-f==7936&&(p=e[n++]<<8,p+=e[n++],p+=8191),d+=1,s==m.LZ_IMAGE_TYPE_RGBA&&(d+=2),p+=1,c-=p,c==o-1)for(var g=c;d;--d){if(s==m.LZ_IMAGE_TYPE_RGBA)i[o*4+3]=i[g*4+3];else for(l=0;l<4;l++)i[o*4+l]=i[g*4+l];o++}else for(;d;--d){if(s==m.LZ_IMAGE_TYPE_RGBA)i[o*4+3]=i[c*4+3];else for(l=0;l<4;l++)i[o*4+l]=i[c*4+l];o++,c++}}else for(a++,s==m.LZ_IMAGE_TYPE_RGBA?i[o*4+3]=e[n++]:(i[o*4+0]=e[n+2],i[o*4+1]=e[n+1],i[o*4+2]=e[n+0],r&&(i[o*4+3]=255),n+=3),o++,--a;a;a--)s==m.LZ_IMAGE_TYPE_RGBA?i[o*4+3]=e[n++]:(i[o*4+0]=e[n+2],i[o*4+1]=e[n+1],i[o*4+2]=e[n+0],r&&(i[o*4+3]=255),n+=3),o++}return n-1}function Mv(e){for(var t=e.width*4,i=e.height,s=i,r=new Uint8Array(e.width*e.height*4);s--;)r.set(e.data.subarray(s*t,(s+1)*t),(i-s-1)*t);e.data.set(r)}function ja(e,t){var i;if(t.type===m.LZ_IMAGE_TYPE_RGB32||t.type===m.LZ_IMAGE_TYPE_RGBA){var s=new Uint8Array(t.data),r=e.createImageData(t.width,t.height);i=Tr(s,0,r.data,m.LZ_IMAGE_TYPE_RGB32,t.type!=m.LZ_IMAGE_TYPE_RGBA),t.top_down||Mv(r),t.type==m.LZ_IMAGE_TYPE_RGBA&&Tr(s,i,r.data,m.LZ_IMAGE_TYPE_RGBA,!1)}else if(t.type===m.LZ_IMAGE_TYPE_XXXA){var s=new Uint8Array(t.data),r=e.createImageData(t.width,t.height);Tr(s,0,r.data,m.LZ_IMAGE_TYPE_RGBA,!1)}else return;return r}function Dv(e,t){var i,s,r,n=0,o=0,a=new Uint8Array(t.data);if(!(t.format!=m.SPICE_BITMAP_FMT_32BIT&&t.format!=m.SPICE_BITMAP_FMT_RGBA)){for(t.flags&m.SPICE_BITMAP_FLAGS_TOP_DOWN||(n=(t.y-1)*t.stride,o=2*t.stride),i=e.createImageData(t.x,t.y),s=0;s<t.y*t.stride;n-=o)for(r=0;r<t.x;r++,s+=4,n+=4)i.data[s+0]=a[n+2],i.data[s+1]=a[n+1],i.data[s+2]=a[n+0],t.format==m.SPICE_BITMAP_FMT_32BIT?i.data[s+3]=255:i.data[s+3]=a[n];return i}}function Fc(e,t,i,s){var r=document.createElement("canvas"),n=r.getContext("2d");r.setAttribute("width",t.width),r.setAttribute("height",t.height),n.putImageData(t,0,0),e.drawImage(r,i,s,t.width,t.height)}function Tv(e){var t;for(t=0;t<e.width*e.height*4;t+=4)e.data[t+3]=255}function Tt(){$e.apply(this,arguments)}Tt.prototype=Object.create($e.prototype);Tt.prototype.process_channel_message=function(e){if(e.type==m.SPICE_MSG_DISPLAY_MODE)return this.known_unimplemented(e.type,"Display Mode"),!0;if(e.type==m.SPICE_MSG_DISPLAY_MARK)return this.known_unimplemented(e.type,"Display Mark"),!0;if(e.type==m.SPICE_MSG_DISPLAY_RESET)return this.surfaces[this.primary_surface].canvas.context.restore(),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_COPY){var t=new Wh(e.data);if(t.base.box.is_same_size(t.data.src_area)||this.log_warn("FIXME: DrawCopy src_area is a different size than base.box; we do not handle that yet."),t.base.clip.type!=m.SPICE_CLIP_TYPE_NONE&&this.log_warn("FIXME: DrawCopy we don't handle clipping yet"),t.data.rop_descriptor!=m.SPICE_ROPD_OP_PUT&&this.log_warn("FIXME: DrawCopy we don't handle ropd type: "+t.data.rop_descriptor),t.data.mask.flags&&this.log_warn("FIXME: DrawCopy we don't handle mask flag: "+t.data.mask.flags),t.data.mask.bitmap&&this.log_warn("FIXME: DrawCopy we don't handle mask"),t.data&&t.data.src_bitmap)if(t.data.src_bitmap.descriptor.flags&&t.data.src_bitmap.descriptor.flags!=m.SPICE_IMAGE_FLAGS_CACHE_ME&&t.data.src_bitmap.descriptor.flags!=m.SPICE_IMAGE_FLAGS_HIGH_BITS_SET&&(this.log_warn("FIXME: DrawCopy unhandled image flags: "+t.data.src_bitmap.descriptor.flags),this.log_draw("DrawCopy",t)),t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_QUIC){var i=this.surfaces[t.base.surface_id].canvas;if(!t.data.src_bitmap.quic)return this.log_warn("FIXME: DrawCopy could not handle this QUIC file."),!1;var s=Lg(i.context,t.data.src_bitmap.quic);return this.draw_copy_helper({base:t.base,src_area:t.data.src_area,image_data:s,tag:"copyquic."+t.data.src_bitmap.quic.type,has_alpha:t.data.src_bitmap.quic.type==Ne.QUIC_IMAGE_TYPE_RGBA,descriptor:t.data.src_bitmap.descriptor})}else{if(t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_FROM_CACHE||t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS)return!this.cache||!this.cache[t.data.src_bitmap.descriptor.id]?(this.log_warn("FIXME: DrawCopy did not find image id "+t.data.src_bitmap.descriptor.id+" in cache."),!1):this.draw_copy_helper({base:t.base,src_area:t.data.src_area,image_data:this.cache[t.data.src_bitmap.descriptor.id],tag:"copycache."+t.data.src_bitmap.descriptor.id,has_alpha:!0,descriptor:t.data.src_bitmap.descriptor});if(t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_SURFACE){var r=this.surfaces[t.data.src_bitmap.surface_id].canvas.context;this.surfaces[t.base.surface_id].canvas.context;var s=r.getImageData(t.data.src_area.left,t.data.src_area.top,t.data.src_area.right-t.data.src_area.left,t.data.src_area.bottom-t.data.src_area.top),n=new ni;return n.top=n.left=0,n.right=s.width,n.bottom=s.height,this.draw_copy_helper({base:t.base,src_area:n,image_data:s,tag:"copysurf."+t.data.src_bitmap.surface_id,has_alpha:this.surfaces[t.data.src_bitmap.surface_id].format!=m.SPICE_SURFACE_FMT_32_xRGB,descriptor:t.data.src_bitmap.descriptor})}else if(t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_JPEG){if(!t.data.src_bitmap.jpeg)return this.log_warn("FIXME: DrawCopy could not handle this JPEG file."),!1;var o="data:image/jpeg,",a=new Image,l,c=new Uint8Array(t.data.src_bitmap.jpeg.data);for(l=0;l<c.length;l++)o+="%",c[l]<16&&(o+="0"),o+=c[l].toString(16);return a.o={base:t.base,tag:"jpeg."+t.data.src_bitmap.surface_id,descriptor:t.data.src_bitmap.descriptor,sc:this},a.onload=In,a.src=o,!0}else if(t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_JPEG_ALPHA){if(!t.data.src_bitmap.jpeg_alpha)return this.log_warn("FIXME: DrawCopy could not handle this JPEG ALPHA file."),!1;var o="data:image/jpeg,",a=new Image,l,c=new Uint8Array(t.data.src_bitmap.jpeg_alpha.data);for(l=0;l<c.length;l++)o+="%",c[l]<16&&(o+="0"),o+=c[l].toString(16);if(a.o={base:t.base,tag:"jpeg."+t.data.src_bitmap.surface_id,descriptor:t.data.src_bitmap.descriptor,sc:this},this.surfaces[t.base.surface_id].format==m.SPICE_SURFACE_FMT_32_ARGB){var i=this.surfaces[t.base.surface_id].canvas;a.alpha_img=ja(i.context,t.data.src_bitmap.jpeg_alpha.alpha)}return a.onload=In,a.src=o,!0}else if(t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_BITMAP){var i=this.surfaces[t.base.surface_id].canvas;if(!t.data.src_bitmap.bitmap)return this.log_err("null bitmap"),!1;var s=Dv(i.context,t.data.src_bitmap.bitmap);return s?this.draw_copy_helper({base:t.base,src_area:t.data.src_area,image_data:s,tag:"bitmap."+t.data.src_bitmap.bitmap.format,has_alpha:t.data.src_bitmap.bitmap!=m.SPICE_BITMAP_FMT_32BIT,descriptor:t.data.src_bitmap.descriptor}):(this.log_warn("FIXME: Unable to interpret bitmap of format: "+t.data.src_bitmap.bitmap.format),!1)}else if(t.data.src_bitmap.descriptor.type==m.SPICE_IMAGE_TYPE_LZ_RGB){var i=this.surfaces[t.base.surface_id].canvas;if(!t.data.src_bitmap.lz_rgb)return this.log_err("null lz_rgb "),!1;var s=ja(i.context,t.data.src_bitmap.lz_rgb);return s?this.draw_copy_helper({base:t.base,src_area:t.data.src_area,image_data:s,tag:"lz_rgb."+t.data.src_bitmap.lz_rgb.type,has_alpha:t.data.src_bitmap.lz_rgb.type==m.LZ_IMAGE_TYPE_RGBA,descriptor:t.data.src_bitmap.descriptor}):(this.log_warn("FIXME: Unable to interpret bitmap of type: "+t.data.src_bitmap.lz_rgb.type),!1)}else return this.log_warn("FIXME: DrawCopy unhandled image type: "+t.data.src_bitmap.descriptor.type),this.log_draw("DrawCopy",t),!1}return this.log_warn("FIXME: DrawCopy no src_bitmap."),!1}if(e.type==m.SPICE_MSG_DISPLAY_DRAW_FILL){var d=new $h(e.data);if(d.data.rop_descriptor!=m.SPICE_ROPD_OP_PUT&&this.log_warn("FIXME: DrawFill we don't handle ropd type: "+d.data.rop_descriptor),d.data.mask.flags&&this.log_warn("FIXME: DrawFill we don't handle mask flag: "+d.data.mask.flags),d.data.mask.bitmap&&this.log_warn("FIXME: DrawFill we don't handle mask"),d.data.brush.type==m.SPICE_BRUSH_TYPE_SOLID){var p=d.data.brush.color&16777215,f="rgb("+(p>>16)+", "+(p>>8&255)+", "+(p&255)+")";this.surfaces[d.base.surface_id].canvas.context.fillStyle=f,this.surfaces[d.base.surface_id].canvas.context.fillRect(d.base.box.left,d.base.box.top,d.base.box.right-d.base.box.left,d.base.box.bottom-d.base.box.top),this.surfaces[d.base.surface_id].draw_count++}else this.log_warn("FIXME: DrawFill can't handle brush type: "+d.data.brush.type);return!0}if(e.type==m.SPICE_MSG_DISPLAY_DRAW_OPAQUE)return this.known_unimplemented(e.type,"Display Draw Opaque"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_BLEND)return this.known_unimplemented(e.type,"Display Draw Blend"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_BLACKNESS)return this.known_unimplemented(e.type,"Display Draw Blackness"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_WHITENESS)return this.known_unimplemented(e.type,"Display Draw Whiteness"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_INVERS)return this.known_unimplemented(e.type,"Display Draw Invers"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_ROP3)return this.known_unimplemented(e.type,"Display Draw ROP3"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_STROKE)return this.known_unimplemented(e.type,"Display Draw Stroke"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT)return this.known_unimplemented(e.type,"Display Draw Transparent"),!0;if(e.type==m.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND)return this.known_unimplemented(e.type,"Display Draw Alpha Blend"),!0;if(e.type==m.SPICE_MSG_DISPLAY_COPY_BITS){var g=new Vh(e.data),u=this.surfaces[g.base.surface_id].canvas,r=u.context,_=u.width-g.src_pos.x,S=u.height-g.src_pos.y;_>g.base.box.right-g.base.box.left&&(_=g.base.box.right-g.base.box.left),S>g.base.box.bottom-g.base.box.top&&(S=g.base.box.bottom-g.base.box.top);var s=r.getImageData(g.src_pos.x,g.src_pos.y,_,S);return Fc(r,s,g.base.box.left,g.base.box.top),this.surfaces[g.base.surface_id].draw_count++,!0}if(e.type==m.SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS)return this.known_unimplemented(e.type,"Display Inval All Pixmaps"),!0;if(e.type==m.SPICE_MSG_DISPLAY_INVAL_PALETTE)return this.known_unimplemented(e.type,"Display Inval Palette"),!0;if(e.type==m.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES)return this.known_unimplemented(e.type,"Inval All Palettes"),!0;if(e.type==m.SPICE_MSG_DISPLAY_SURFACE_CREATE){"surfaces"in this||(this.surfaces=[]);var v=new qh(e.data);if(v.surface.format!=m.SPICE_SURFACE_FMT_32_xRGB&&v.surface.format!=m.SPICE_SURFACE_FMT_32_ARGB)return this.log_warn("FIXME: cannot handle surface format "+v.surface.format+" yet."),!1;var i=document.createElement("canvas");return i.setAttribute("width",v.surface.width),i.setAttribute("height",v.surface.height),i.setAttribute("id","spice_surface_"+v.surface.surface_id),i.setAttribute("tabindex",v.surface.surface_id),i.context=i.getContext("2d"),v.surface.canvas=i,v.surface.draw_count=0,this.surfaces[v.surface.surface_id]=v.surface,v.surface.flags&m.SPICE_SURFACE_FLAGS_PRIMARY&&(this.primary_surface=v.surface.surface_id,i.context.save(),document.getElementById(this.parent.screen_id).appendChild(i),this.hook_events()),!0}if(e.type==m.SPICE_MSG_DISPLAY_SURFACE_DESTROY){var v=new Xh(e.data);return this.delete_surface(v.surface_id),!0}if(e.type==m.SPICE_MSG_DISPLAY_STREAM_CREATE){var v=new nc(e.data);if(this.streams||(this.streams=new Array),this.streams[v.id]?console.log("Stream "+v.id+" already exists"):this.streams[v.id]=v,v.codec_type==m.SPICE_VIDEO_CODEC_TYPE_VP8){var P=new MediaSource,w=document.createElement("video");w.src=window.URL.createObjectURL(P),w.setAttribute("muted",!0),w.setAttribute("autoplay",!0),w.setAttribute("width",v.stream_width),w.setAttribute("height",v.stream_height);var E=v.dest.left,D=v.dest.top;this.surfaces[v.surface_id]!==void 0&&(E+=this.surfaces[v.surface_id].canvas.offsetLeft,D+=this.surfaces[v.surface_id].canvas.offsetTop),document.getElementById(this.parent.screen_id).appendChild(w),w.setAttribute("style","pointer-events:none; position: absolute; top:"+D+"px; left:"+E+"px;"),P.addEventListener("sourceopen",Lv,!1),P.addEventListener("sourceended",Nv,!1),P.addEventListener("sourceclosed",Bv,!1);var N=this.streams[v.id];N.video=w,N.media=P,N.queue=new Array,N.start_time=0,N.cluster_time=0,N.append_okay=!1,P.stream=N,P.spiceconn=this,w.spice_stream=N}else v.codec_type==m.SPICE_VIDEO_CODEC_TYPE_MJPEG?this.streams[v.id].frames_loading=0:console.log("Unhandled stream codec: "+v.codec_type);return!0}if(e.type==m.SPICE_MSG_DISPLAY_STREAM_DATA||e.type==m.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED){var v;if(e.type==m.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED?v=new ac(e.data):v=new oc(e.data),!this.streams[v.base.id])return console.log("no stream for data"),!1;var U=v.base.multi_media_time-this.parent.relative_now();return this.streams[v.base.id].codec_type===m.SPICE_VIDEO_CODEC_TYPE_MJPEG&&Rv(this,v,U),this.streams[v.base.id].codec_type===m.SPICE_VIDEO_CODEC_TYPE_VP8&&Fv(this.streams[v.base.id],v),!0}if(e.type==m.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT){var v=new cc(e.data),X=new dc(v.stream_id,v.unique_id);return this.streams[v.stream_id]&&(this.streams[v.stream_id].report=X,this.streams[v.stream_id].max_window_size=v.max_window_size,this.streams[v.stream_id].timeout_ms=v.timeout_ms),!0}if(e.type==m.SPICE_MSG_DISPLAY_STREAM_CLIP){var v=new lc(e.data);return this.streams[v.id].clip=v.clip,!0}if(e.type==m.SPICE_MSG_DISPLAY_STREAM_DESTROY){var v=new hc(e.data);return this.streams[v.id].codec_type==m.SPICE_VIDEO_CODEC_TYPE_VP8&&(document.getElementById(this.parent.screen_id).removeChild(this.streams[v.id].video),this.streams[v.id].source_buffer=null,this.streams[v.id].media=null,this.streams[v.id].video=null),this.streams[v.id]=void 0,!0}if(e.type==m.SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL)return this.known_unimplemented(e.type,"Display Stream Destroy All"),!0;if(e.type==m.SPICE_MSG_DISPLAY_INVAL_LIST){var v=new uc(e.data),l;for(l=0;l<v.count;l++)this.cache[v.resources[l].id]!=null&&delete this.cache[v.resources[l].id];return!0}return e.type==m.SPICE_MSG_DISPLAY_MONITORS_CONFIG?(this.known_unimplemented(e.type,"Display Monitors Config"),!0):e.type==m.SPICE_MSG_DISPLAY_DRAW_COMPOSITE?(this.known_unimplemented(e.type,"Display Draw Composite"),!0):!1};Tt.prototype.delete_surface=function(e){var t=document.getElementById("spice_surface_"+e);this.primary_surface==e&&(this.unhook_events(),this.primary_surface=void 0,document.getElementById(this.parent.screen_id)?.removeChild(t)),delete this.surfaces[e]};Tt.prototype.draw_copy_helper=function(e){var t=this.surfaces[e.base.surface_id].canvas;return e.has_alpha?this.surfaces[e.base.surface_id].format==m.SPICE_SURFACE_FMT_32_xRGB?(Tv(e.image_data),t.context.putImageData(e.image_data,e.base.box.left,e.base.box.top)):Fc(t.context,e.image_data,e.base.box.left,e.base.box.top):t.context.putImageData(e.image_data,e.base.box.left,e.base.box.top),(e.src_area.left>0||e.src_area.top>0)&&this.log_warn("FIXME: DrawCopy not shifting draw copies just yet..."),e.descriptor&&e.descriptor.flags&m.SPICE_IMAGE_FLAGS_CACHE_ME&&("cache"in this||(this.cache={}),this.cache[e.descriptor.id]=e.image_data),this.surfaces[e.base.surface_id].draw_count++,!0};Tt.prototype.log_draw=function(e,t){var i=e+"."+t.base.surface_id+"."+this.surfaces[t.base.surface_id].draw_count+": ";i+="base.box "+t.base.box.left+", "+t.base.box.top+" to "+t.base.box.right+", "+t.base.box.bottom,i+="; clip.type "+t.base.clip.type,t.data&&(t.data.src_area&&(i+="; src_area "+t.data.src_area.left+", "+t.data.src_area.top+" to "+t.data.src_area.right+", "+t.data.src_area.bottom),t.data.src_bitmap&&t.data.src_bitmap!=null?(i+="; src_bitmap id: "+t.data.src_bitmap.descriptor.id,i+="; src_bitmap width "+t.data.src_bitmap.descriptor.width+", height "+t.data.src_bitmap.descriptor.height,i+="; src_bitmap type "+t.data.src_bitmap.descriptor.type+", flags "+t.data.src_bitmap.descriptor.flags,t.data.src_bitmap.surface_id!==void 0&&(i+="; src_bitmap surface_id "+t.data.src_bitmap.surface_id),t.data.src_bitmap.bitmap&&(i+="; BITMAP format "+t.data.src_bitmap.bitmap.format+"; flags "+t.data.src_bitmap.bitmap.flags+"; x "+t.data.src_bitmap.bitmap.x+"; y "+t.data.src_bitmap.bitmap.y+"; stride "+t.data.src_bitmap.bitmap.stride),t.data.src_bitmap.quic&&(i+="; QUIC type "+t.data.src_bitmap.quic.type+"; width "+t.data.src_bitmap.quic.width+"; height "+t.data.src_bitmap.quic.height),t.data.src_bitmap.lz_rgb&&(i+="; LZ_RGB length "+t.data.src_bitmap.lz_rgb.length+"; magic "+t.data.src_bitmap.lz_rgb.magic+"; version 0x"+t.data.src_bitmap.lz_rgb.version.toString(16)+"; type "+t.data.src_bitmap.lz_rgb.type+"; width "+t.data.src_bitmap.lz_rgb.width+"; height "+t.data.src_bitmap.lz_rgb.height+"; stride "+t.data.src_bitmap.lz_rgb.stride+"; top down "+t.data.src_bitmap.lz_rgb.top_down)):i+="; src_bitmap is null",t.data.brush&&(t.data.brush.type==m.SPICE_BRUSH_TYPE_SOLID&&(i+="; brush.color 0x"+t.data.brush.color.toString(16)),t.data.brush.type==m.SPICE_BRUSH_TYPE_PATTERN&&(i+="; brush.pat ",t.data.brush.pattern.pat!=null?i+="[SpiceImage]":i+="[null]",i+=" at "+t.data.brush.pattern.pos.x+", "+t.data.brush.pattern.pos.y)),i+="; rop_descriptor "+t.data.rop_descriptor,t.data.scale_mode!==void 0&&(i+="; scale_mode "+t.data.scale_mode),i+="; mask.flags "+t.data.mask.flags,i+="; mask.pos "+t.data.mask.pos.x+", "+t.data.mask.pos.y,t.data.mask.bitmap!=null?(i+="; mask.bitmap width "+t.data.mask.bitmap.descriptor.width+", height "+t.data.mask.bitmap.descriptor.height,i+="; mask.bitmap type "+t.data.mask.bitmap.descriptor.type+", flags "+t.data.mask.bitmap.descriptor.flags):i+="; mask.bitmap is null"),console.log(i)};Tt.prototype.hook_events=function(){if(this.primary_surface!==void 0){var e=this.surfaces[this.primary_surface].canvas;e.sc=this.parent,e.addEventListener("mousemove",Dc),e.addEventListener("mousedown",Tc),e.addEventListener("contextmenu",Rc),e.addEventListener("mouseup",Lc),e.addEventListener("keydown",Bc),e.addEventListener("keyup",Oc),e.addEventListener("mouseout",Kc),e.addEventListener("mouseover",jc),e.addEventListener("wheel",Nc),e.focus(),this.focusListener=()=>this.parent.send_clipboard_grab(),this.focusListener(),e.addEventListener("focus",this.focusListener)}};Tt.prototype.unhook_events=function(){if(this.primary_surface!==void 0){var e=this.surfaces[this.primary_surface].canvas;e.removeEventListener("mousemove",Dc),e.removeEventListener("mousedown",Tc),e.removeEventListener("contextmenu",Rc),e.removeEventListener("mouseup",Lc),e.removeEventListener("keydown",Bc),e.removeEventListener("keyup",Oc),e.removeEventListener("mouseout",Kc),e.removeEventListener("mouseover",jc),e.removeEventListener("wheel",Nc),e.removeEventListener("focus",this.focusListener)}};Tt.prototype.destroy_surfaces=function(){for(var e in this.surfaces)this.delete_surface(this.surfaces[e].surface_id);this.surfaces=void 0};function jc(e){this.focus()}function Kc(e){this.sc&&this.sc.cursor&&this.sc.cursor.spice_simulated_cursor&&(this.sc.cursor.spice_simulated_cursor.style.display="none"),this.blur()}function In(){var e=null,t;if("streams"in this.o.sc&&this.o.sc.streams[this.o.id]&&this.o.sc.streams[this.o.id].frames_loading--,this.o.sc.surfaces[this.o.base.surface_id]===void 0?(e=document.createElement("canvas"),e.setAttribute("width",this.o.base.box.right),e.setAttribute("height",this.o.base.box.bottom),t=e.getContext("2d")):t=this.o.sc.surfaces[this.o.base.surface_id].canvas.context,this.alpha_img){var i=document.createElement("canvas"),s=i.getContext("2d");i.setAttribute("width",this.alpha_img.width),i.setAttribute("height",this.alpha_img.height),s.putImageData(this.alpha_img,0,0),s.globalCompositeOperation="source-in",s.drawImage(this,0,0),t.drawImage(i,this.o.base.box.left,this.o.base.box.top),this.o.descriptor&&this.o.descriptor.flags&m.SPICE_IMAGE_FLAGS_CACHE_ME&&("cache"in this.o.sc||(this.o.sc.cache={}),this.o.sc.cache[this.o.descriptor.id]=s.getImageData(0,0,this.alpha_img.width,this.alpha_img.height))}else t.drawImage(this,this.o.base.box.left,this.o.base.box.top),this.onload=void 0,this.src=Bg,this.o.descriptor&&this.o.descriptor.flags&m.SPICE_IMAGE_FLAGS_CACHE_ME&&("cache"in this.o.sc||(this.o.sc.cache={}),this.o.sc.cache[this.o.descriptor.id]=t.getImageData(this.o.base.box.left,this.o.base.box.top,this.o.base.box.right-this.o.base.box.left,this.o.base.box.bottom-this.o.base.box.top));e==null&&this.o.sc.surfaces[this.o.base.surface_id].draw_count++,this.o.sc.streams[this.o.id]&&"report"in this.o.sc.streams[this.o.id]&&zc(this.o.sc,this.o.id,this.o.msg_mmtime,this.o.msg_mmtime-this.o.sc.parent.relative_now())}function Rv(e,t,i){if(i<0&&e.streams[t.base.id].frames_loading>0){"report"in e.streams[t.base.id]&&e.streams[t.base.id].report.num_drops++;return}var s="data:image/jpeg,",r=new Image,n;for(n=0;n<t.data.length;n++)s+="%",t.data[n]<16&&(s+="0"),s+=t.data[n].toString(16);var o=new es;o.surface_id=e.streams[t.base.id].surface_id,o.box=t.dest||e.streams[t.base.id].dest,o.clip=e.streams[t.base.id].clip,r.o={base:o,tag:"mjpeg."+t.base.id,descriptor:null,sc:e,id:t.base.id,msg_mmtime:t.base.multi_media_time},r.onload=In,r.src=s,e.streams[t.base.id].frames_loading++}function zc(e,t,i,s){if(e.streams[t].report.num_frames++,e.streams[t].report.start_frame_mm_time==0&&(e.streams[t].report.start_frame_mm_time=i),e.streams[t].report.num_frames>e.streams[t].max_window_size||i-e.streams[t].report.start_frame_mm_time>e.streams[t].timeout_ms){e.streams[t].report.end_frame_mm_time=i,e.streams[t].report.last_frame_delay=s;var r=new le;r.build_msg(m.SPICE_MSGC_DISPLAY_STREAM_REPORT,e.streams[t].report),e.send_msg(r),e.streams[t].report.start_frame_mm_time=0,e.streams[t].report.num_frames=0,e.streams[t].report.num_drops=0}}function Lv(e){var t=this.stream,i=this.spiceconn;if(!t.source_buffer){var s=this.addSourceBuffer(me.SPICE_VP8_CODEC);if(!s){i.log_err("Codec "+me.SPICE_VP8_CODEC+" not available.");return}t.source_buffer=s,s.spiceconn=i,s.stream=t,zv(t);var r=new ro,n=new Mc(this.stream.stream_width,this.stream.stream_height),o=new to(n),a=new ArrayBuffer(r.buffer_size()+o.buffer_size()),l=r.to_buffer(a);o.to_buffer(a,l),s.addEventListener("error",Uv,!1),s.addEventListener("updateend",Ov,!1),oo(s,a)}}function Nv(e){var t=this.spiceconn;t.log_err("Video source unexpectedly ended.")}function Bv(e){var t=this.spiceconn;t.log_err("Video source unexpectedly closed.")}function oo(e,t){try{e.stream.append_okay=!1,e.appendBuffer(t)}catch(s){var i=e.spiceconn;i.log_err("Error invoking appendBuffer: "+s.message)}}function Ov(e){var t=this.stream;if(t.current_frame&&"report"in t){var i=this.stream.media.spiceconn,s=this.stream.current_frame.msg_mmtime;zc(i,t.id,s,s-i.parent.relative_now())}if(t.queue.length>0?(t.current_frame=t.queue.shift(),oo(t.source_buffer,t.current_frame.mb)):t.append_okay=!0,!!t.video&&(t.video.buffered.length>0&&t.video.currentTime<t.video.buffered.start(t.video.buffered.length-1)&&(console.log("Video appears to have fallen behind; advancing to "+t.video.buffered.start(t.video.buffered.length-1)),t.video.currentTime=t.video.buffered.start(t.video.buffered.length-1)),this.stream.video.paused&&this.stream.video.readyState>=2))var r=this.stream.video.play()}function Uv(e){var t=this.spiceconn;t.log_err("source_buffer error "+e.message)}function Yc(e,t,i){var s={msg_mmtime:t.base.multi_media_time};e.append_okay?(e.current_frame=s,oo(e.source_buffer,i)):(s.mb=i,e.queue.push(s))}function Hc(e,t,i){var s=new so(t.base.multi_media_time-e.cluster_time,t.data,i),r=new ArrayBuffer(s.buffer_size());s.to_buffer(r),Yc(e,t,r)}function Ka(e,t){e.cluster_time=t.base.multi_media_time;var i=new io(e.cluster_time-e.start_time,t.data),s=new ArrayBuffer(i.buffer_size());i.to_buffer(s),Yc(e,t,s),Hc(e,t,!0)}function Fv(e,t){e.start_time==0?(e.start_time=t.base.multi_media_time,Ka(e,t)):t.base.multi_media_time-e.cluster_time>=me.MAX_CLUSTER_TIME?Ka(e,t):Hc(e,t,!1)}function jv(e){var t=this.spice_stream;t.video&&t.video.buffered.len>1&&console.log(t.video.currentTime+":id "+t.id+" event "+e.type+Eh(t.video)),t.queue.length>1&&console.log("  queue len "+t.queue.length+"; append_okay: "+t.append_okay)}function Kv(e){this.addEventListener(e,jv)}function zv(e){var t=["abort","error"];t.forEach(Kv,e.video)}function yi(){$e.apply(this,arguments),this.queue=new Array,this.append_okay=!1,this.start_time=0}yi.prototype=Object.create($e.prototype);yi.prototype.process_channel_message=function(e){if(!window.MediaSource)return this.log_err("MediaSource API is not available"),!1;if(e.type==m.SPICE_MSG_PLAYBACK_START){var t=new ic(e.data);if(t.frequency!=me.OPUS_FREQUENCY)return this.log_err("This player cannot handle frequency "+t.frequency),!1;if(t.channels!=me.OPUS_CHANNELS)return this.log_err("This player cannot handle "+t.channels+" channels"),!1;if(t.format!=m.SPICE_AUDIO_FMT_S16)return this.log_err("This player cannot format "+t.format),!1;if(!this.source_buffer)return this.media_source=new MediaSource,this.media_source.spiceconn=this,this.audio=document.createElement("audio"),this.audio.spiceconn=this,this.audio.setAttribute("autoplay",!0),this.audio.src=window.URL.createObjectURL(this.media_source),document.getElementById(this.parent.screen_id).appendChild(this.audio),this.media_source.addEventListener("sourceopen",Yv,!1),this.media_source.addEventListener("sourceended",Hv,!1),this.media_source.addEventListener("sourceclosed",Gv,!1),this.bytes_written=0,!0}if(e.type==m.SPICE_MSG_PLAYBACK_DATA){var i=new ec(e.data);return this.source_buffer&&(this.audio.readyState>=3&&this.audio.buffered.length>1&&this.audio.currentTime==this.audio.buffered.end(0)&&this.audio.currentTime<this.audio.buffered.start(this.audio.buffered.length-1)&&(console.log("Audio underrun: we appear to have fallen behind; advancing to "+this.audio.buffered.start(this.audio.buffered.length-1)),this.audio.currentTime=this.audio.buffered.start(this.audio.buffered.length-1)),this.start_time!=0&&i.time!=this.last_data_time+me.EXPECTED_PACKET_DURATION&&Math.abs(i.time-(me.EXPECTED_PACKET_DURATION+this.last_data_time))<me.MAX_CLUSTER_TIME&&(i.time=this.last_data_time+me.EXPECTED_PACKET_DURATION),this.last_data_time=i.time,this.start_time==0?this.start_playback(i):i.time-this.cluster_time>=me.MAX_CLUSTER_TIME?this.new_cluster(i):this.simple_block(i,!1)),!0}if(e.type==m.SPICE_MSG_PLAYBACK_MODE){var s=new tc(e.data);return s.mode!=m.SPICE_AUDIO_DATA_MODE_OPUS&&(this.log_err("This player cannot handle mode "+s.mode),delete this.source_buffer),!0}return e.type==m.SPICE_MSG_PLAYBACK_STOP&&this.source_buffer?(document.getElementById(this.parent.screen_id).removeChild(this.audio),window.URL.revokeObjectURL(this.audio.src),delete this.source_buffer,delete this.media_source,delete this.audio,this.append_okay=!1,this.queue=new Array,this.start_time=0,!0):e.type==m.SPICE_MSG_PLAYBACK_VOLUME?(this.known_unimplemented(e.type,"Playback Volume"),!0):e.type==m.SPICE_MSG_PLAYBACK_MUTE?(this.known_unimplemented(e.type,"Playback Mute"),!0):e.type==m.SPICE_MSG_PLAYBACK_LATENCY?(this.known_unimplemented(e.type,"Playback Latency"),!0):!1};yi.prototype.start_playback=function(e){this.start_time=e.time;var t=new ro,i=new kc,s=new to(i),r=new ArrayBuffer(t.buffer_size()+s.buffer_size());this.bytes_written=t.to_buffer(r),this.bytes_written=s.to_buffer(r,this.bytes_written),this.source_buffer.addEventListener("error",Vv,!1),this.source_buffer.addEventListener("updateend",$v,!1),cr(this,r),this.new_cluster(e)};yi.prototype.new_cluster=function(e){this.cluster_time=e.time;var t=new io(e.time-this.start_time),i=new ArrayBuffer(t.buffer_size());this.bytes_written+=t.to_buffer(i),this.append_okay?cr(this,i):this.queue.push(i),this.simple_block(e,!0)};yi.prototype.simple_block=function(e,t){var i=new so(e.time-this.cluster_time,e.data,t),s=new ArrayBuffer(i.buffer_size());this.bytes_written+=i.to_buffer(s),this.append_okay?cr(this,s):this.queue.push(s)};function Yv(e){var t=this.spiceconn;if(!t.source_buffer){if(t.source_buffer=this.addSourceBuffer(me.SPICE_PLAYBACK_CODEC),!t.source_buffer){t.log_err("Codec "+me.SPICE_PLAYBACK_CODEC+" not available.");return}Qv(t),t.source_buffer.spiceconn=t,t.source_buffer.mode="segments"}}function Hv(e){var t=this.spiceconn;t.log_err("Audio source unexpectedly ended.")}function Gv(e){var t=this.spiceconn;t.log_err("Audio source unexpectedly closed.")}function Wv(e){if(e.length==1)return e.shift();var t=0,i=0;for(i=0;i<e.length;i++)t+=e[i].byteLength;var s=new ArrayBuffer(t),r=new Uint8Array(s);for(t=0,i=0;i<e.length;i++)r.set(new Uint8Array(e[i]),t),t+=e[i].byteLength;return e.length=0,s}function $v(e){var t=this.spiceconn;if(t.queue.length>0){var i=Wv(t.queue);cr(t,i)}else t.append_okay=!0}function Vv(e){var t=this.spiceconn;t.log_err("source_buffer error "+e.message)}function cr(e,t){try{e.source_buffer.appendBuffer(t),e.append_okay=!1}catch(i){e.log_err("Error invoking appendBuffer: "+i.message)}}function qv(e){var t=this.spiceconn;t.audio&&t.audio.buffered.len>1&&console.log(t.audio.currentTime+": event "+e.type+Eh(t.audio)),t.queue.length>1&&console.log("  queue len "+t.queue.length+"; append_okay: "+t.append_okay)}function Xv(e){this.addEventListener(e,qv)}function Qv(e){var t=["abort","error"];t.forEach(Xv,e.audio)}function ao(){$e.apply(this,arguments),this.port_name=null}ao.prototype=Object.create($e.prototype);ao.prototype.process_channel_message=function(e){if(e.type==m.SPICE_MSG_PORT_INIT){if(this.port_name===null){var t=new _c(e.data);return this.portName=Og(new Uint8Array(t.name)),this.portOpened=t.opened,!0}}else if(e.type==m.SPICE_MSG_PORT_EVENT){var i=new CustomEvent("spice-port-event",{detail:{channel:this,spiceEvent:new Uint8Array(e.data)},bubbles:!0,cancelable:!0});return window.dispatchEvent(i),!0}else if(e.type==m.SPICE_MSG_SPICEVMC_DATA){var i=new CustomEvent("spice-port-data",{detail:{channel:this,data:e.data},bubbles:!0,cancelable:!0});return window.dispatchEvent(i),!0}return!1};function Zv(e){if(e){var t=document.getElementById(e.screen_id).clientWidth,i=document.getElementById("spice-area"),s=document.isFullScreen||document.fullscreenElement||document.webkitIsFullScreen||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement,r=window.innerHeight-i.getBoundingClientRect().top-i.parentNode.scrollTop;s||(r=r-65),r<200&&(r=200),r%8>0&&(r-=r%8),t%8>0&&(t-=t%8),e.resize_window(0,t,r,32,0,0),e.spice_resize_timer=void 0}}function Jv(e){var t=window.spice_connection;t&&(t.spice_resize_timer&&(window.clearTimeout(t.spice_resize_timer),t.spice_resize_timer=void 0),t.spice_resize_timer=window.setTimeout(Zv,200,t))}function Ce(){if(typeof WebSocket>"u")throw new Error("WebSocket unavailable.  You need to use a different browser.");$e.apply(this,arguments),this.agent_msg_queue=[],this.file_xfer_tasks={},this.file_xfer_task_id=0,this.file_xfer_read_queue=[],this.ports=[],this.agent_caps=[0]}Ce.prototype=Object.create($e.prototype);Ce.prototype.process_channel_message=function(e){if(e.type==m.SPICE_MSG_MAIN_MIGRATE_BEGIN)return this.known_unimplemented(e.type,"Main Migrate Begin"),!0;if(e.type==m.SPICE_MSG_MAIN_MIGRATE_CANCEL)return this.known_unimplemented(e.type,"Main Migrate Cancel"),!0;if(e.type==m.SPICE_MSG_MAIN_INIT){this.log_info("Connected to "+this.ws.url),this.report_success("Connected"),this.main_init=new Rh(e.data),this.connection_id=this.main_init.session_id,this.agent_tokens=this.main_init.agent_tokens,this.our_mm_time=Date.now(),this.mm_time=this.main_init.multi_media_time,this.handle_mouse_mode(this.main_init.current_mouse_mode,this.main_init.supported_mouse_modes),this.main_init.agent_connected&&this.connect_agent();var t=new le;return t.type=m.SPICE_MSGC_MAIN_ATTACH_CHANNELS,t.size=t.buffer_size(),this.send_msg(t),!0}if(e.type==m.SPICE_MSG_MAIN_MOUSE_MODE){var i=new Lh(e.data);return this.handle_mouse_mode(i.current_mode,i.supported_modes),!0}if(e.type==m.SPICE_MSG_MAIN_MULTI_MEDIA_TIME)return this.known_unimplemented(e.type,"Main Multi Media Time"),!0;if(e.type==m.SPICE_MSG_MAIN_CHANNELS_LIST){var s,r;for(r=new Ph(e.data),s=0;s<r.channels.length;s++){var n={uri:this.ws.url,parent:this,connection_id:this.connection_id,type:r.channels[s].type,chan_id:r.channels[s].id};r.channels[s].type==m.SPICE_CHANNEL_DISPLAY?r.channels[s].id==0?this.display=new Tt(n):this.log_warn("The spice-html5 client does not handle multiple heads."):r.channels[s].type==m.SPICE_CHANNEL_INPUTS?(this.inputs=new no(n),this.inputs.mouse_mode=this.mouse_mode):r.channels[s].type==m.SPICE_CHANNEL_CURSOR?this.cursor=new lr(n):r.channels[s].type==m.SPICE_CHANNEL_PLAYBACK?this.cursor=new yi(n):r.channels[s].type==m.SPICE_CHANNEL_PORT?this.ports.push(new ao(n)):("extra_channels"in this||(this.extra_channels=[]),this.extra_channels[s]=new $e(n),this.log_err("Channel type "+this.extra_channels[s].channel_type()+" not implemented"))}return!0}if(e.type==m.SPICE_MSG_MAIN_AGENT_CONNECTED)return this.connect_agent(),!0;if(e.type==m.SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS){var o=new wn(e.data);return this.agent_tokens=o.num_tokens,this.connect_agent(),!0}if(e.type==m.SPICE_MSG_MAIN_AGENT_TOKEN){var a,l=new wn(e.data);for(this.agent_tokens+=l.num_tokens,this.send_agent_message_queue(),a=this.agent_tokens;a>0&&this.file_xfer_read_queue.length>0;){var c=this.file_xfer_read_queue.shift();this.file_xfer_read(c,c.read_bytes),a--}return!0}if(e.type==m.SPICE_MSG_MAIN_AGENT_DISCONNECTED)return this.agent_connected=!1,!0;if(e.type==m.SPICE_MSG_MAIN_AGENT_DATA){var d=new Nh(e.data);if(d.type==m.VD_AGENT_ANNOUNCE_CAPABILITIES){var p=new qn(d.data);return this.agent_caps=[p.caps],p.request&&this.announce_agent_capabilities(0),!0}else{if(d.type==m.VD_AGENT_FILE_XFER_STATUS)return this.handle_file_xfer_status(new Xn(d.data)),!0;if(d.type==m.VD_AGENT_CLIPBOARD_GRAB)return this.handle_clipboard_grab(),!0;if(d.type==m.VD_AGENT_CLIPBOARD)return this.handle_clipboard_receive(d),!0;if(d.type==m.VD_AGENT_CLIPBOARD_REQUEST)return this.handle_clipboard_send(),!0;if(d.type==m.VD_AGENT_CLIPBOARD_RELEASE)return!0}return!1}return e.type==m.SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST?(this.known_unimplemented(e.type,"Main Migrate Switch Host"),!0):e.type==m.SPICE_MSG_MAIN_MIGRATE_END?(this.known_unimplemented(e.type,"Main Migrate End"),!0):e.type==m.SPICE_MSG_MAIN_NAME?(this.known_unimplemented(e.type,"Main Name"),!0):e.type==m.SPICE_MSG_MAIN_UUID?(this.known_unimplemented(e.type,"Main UUID"),!0):e.type==m.SPICE_MSG_MAIN_MIGRATE_BEGIN_SEAMLESS?(this.known_unimplemented(e.type,"Main Migrate Begin Seamless"),!0):e.type==m.SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK?(this.known_unimplemented(e.type,"Main Migrate Dst Seamless ACK"),!0):e.type==m.SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK?(this.known_unimplemented(e.type,"Main Migrate Dst Seamless NACK"),!0):!1};Ce.prototype.stop=function(e){if(this.state="closing",this.inputs&&(this.inputs.cleanup(),this.inputs=void 0),this.cursor&&(this.cursor.cleanup(),this.cursor=void 0),this.display&&(this.display.cleanup(),this.display.destroy_surfaces(),this.display=void 0),this.cleanup(),"extra_channels"in this)for(var t in this.extra_channels)this.extra_channels[t].cleanup();this.extra_channels=void 0};Ce.prototype.send_agent_message_queue=function(e){if(this.agent_connected)for(e&&this.agent_msg_queue.push(e);this.agent_tokens>0&&this.agent_msg_queue.length>0;){var t=this.agent_msg_queue.shift();this.send_msg(t),this.agent_tokens--}};Ce.prototype.send_agent_message=function(e,t){var i=new jh(e,t),s=0,r=m.VD_AGENT_MAX_DATA_SIZE-le.prototype.buffer_size(),n=new ArrayBuffer(i.buffer_size());for(i.to_buffer(n);s<i.buffer_size();){var o=Math.min(s+r,i.buffer_size()),a=new le;a.type=m.SPICE_MSGC_MAIN_AGENT_DATA,a.size=o-s,a.data=n.slice(s,o),this.send_agent_message_queue(a),s=o}};Ce.prototype.announce_agent_capabilities=function(e){var t=new qn(e,1<<m.VD_AGENT_CAP_MOUSE_STATE|1<<m.VD_AGENT_CAP_MONITORS_CONFIG|1<<m.VD_AGENT_CAP_REPLY|1<<m.VD_AGENT_CAP_CLIPBOARD_SELECTION|1<<m.VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);this.send_agent_message(m.VD_AGENT_ANNOUNCE_CAPABILITIES,t)};Ce.prototype.resize_window=function(e,t,i,s,r,n){var o=new Kh(e,t,i,s,r,n);this.send_agent_message(m.VD_AGENT_MONITORS_CONFIG,o)};Ce.prototype.file_xfer_start=function(e){var t,i,s;t=this.file_xfer_task_id++,s=new hr(t,e),s.create_progressbar(),this.file_xfer_tasks[t]=s,i=new zh(t,e.name,e.size),this.send_agent_message(m.VD_AGENT_FILE_XFER_START,i)};Ce.prototype.handle_file_xfer_status=function(e){var t,i;if(this.file_xfer_tasks[e.id]){switch(i=this.file_xfer_tasks[e.id],e.result){case m.VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:this.file_xfer_read(i);return;case m.VD_AGENT_FILE_XFER_STATUS_CANCELLED:t="transfer is cancelled by spice agent";break;case m.VD_AGENT_FILE_XFER_STATUS_ERROR:t="some errors occurred in the spice agent";break;case m.VD_AGENT_FILE_XFER_STATUS_SUCCESS:break;default:t="unhandled status type: "+e.result;break}this.file_xfer_completed(i,t)}};Ce.prototype.file_xfer_read=function(e,t){var i=32*m.VD_AGENT_MAX_DATA_SIZE,s=this,r,n,o,a;if(!(!e||!this.file_xfer_tasks[e.id]||t>0&&t==e.file.size)){if(e.cancelled){var l=new Xn(e.id,m.VD_AGENT_FILE_XFER_STATUS_CANCELLED);this.send_agent_message(m.VD_AGENT_FILE_XFER_STATUS,l),delete this.file_xfer_tasks[e.id];return}if(r=t||0,n=Math.min(r+i,e.file.size),!this.agent_tokens){e.read_bytes=r,this.file_xfer_read_queue.push(e);return}a=new FileReader,a.onload=function(c){var d=new Yh(e.id,c.target.result.byteLength,c.target.result);s.send_agent_message(m.VD_AGENT_FILE_XFER_DATA,d),s.file_xfer_read(e,n),e.update_progressbar(n)},o=e.file.slice(r,n),a.readAsArrayBuffer(o)}};Ce.prototype.file_xfer_completed=function(e,t){t?this.log_err(t):this.log_info("transfer of '"+e.file.name+"' was successful"),e.remove_progressbar(),delete this.file_xfer_tasks[e.id]};Ce.prototype.handle_clipboard_grab=function(){const e=m.VD_AGENT_CLIPBOARD_UTF8_TEXT,t=new Dh(e,this.agent_caps);this.send_agent_message(m.VD_AGENT_CLIPBOARD_REQUEST,t)};Ce.prototype.handle_clipboard_receive=function(e){const t=new Mh(e,this.agent_caps);if(t.type===m.VD_AGENT_CLIPBOARD_UTF8_TEXT){if(navigator.clipboard&&navigator.clipboard.writeText){const i=t.get_text();navigator.clipboard.writeText(i).catch(s=>{console.warn("Failed to write to navigator clipboard:",s)})}}else console.log("Unsupported clipboard type:",t.type)};Ce.prototype.handle_clipboard_send=function(){navigator.clipboard&&navigator.clipboard.readText&&navigator.clipboard.readText().then(e=>{const t=m.VD_AGENT_CLIPBOARD_UTF8_TEXT,i=new Th(t,e,this.agent_caps);this.send_agent_message(m.VD_AGENT_CLIPBOARD,i)}).catch(e=>{console.log("Failed to read clipboard:",e)})};Ce.prototype.send_clipboard_grab=function(){const e=m.VD_AGENT_CLIPBOARD_UTF8_TEXT,t=new kh(e,this.agent_caps);this.send_agent_message(m.VD_AGENT_CLIPBOARD_GRAB,t)};Ce.prototype.connect_agent=function(){this.agent_connected=!0;var e=new Fh(-1),t=new le;t.build_msg(m.SPICE_MSGC_MAIN_AGENT_START,e),this.send_msg(t),this.announce_agent_capabilities(1),this.onagent!==void 0&&this.onagent(this)};Ce.prototype.handle_mouse_mode=function(e,t){if(this.mouse_mode=e,e!=m.SPICE_MOUSE_MODE_CLIENT&&t&m.SPICE_MOUSE_MODE_CLIENT){var i=new Uh(m.SPICE_MOUSE_MODE_CLIENT),s=new le;s.build_msg(m.SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST,i),this.send_msg(s)}this.inputs&&(this.inputs.mouse_mode=e)};Ce.prototype.relative_now=function(){var e=Date.now()-this.our_mm_time+this.mm_time;return e};const Gc=()=>{const e=O.useRef(!0);return O.useEffect(()=>()=>{e.current=!1},[]),e},e0=({instance:e,onMount:t,onFailure:i})=>{const{name:s,project:r}=si(),n=b.useNotify(),o=O.useRef(null),[a,l]=O.useState(!1),c=Gc(),d=Ys(e),p=(_,S)=>{c.current&&i("Console error",_,S)},f=()=>{fi("spice-wrapper"),Jv()},g=async()=>{if(!s){i("Missing name",new Error);return}if(!r){i("Missing project",new Error);return}l(!0);const _=await ld(s,r).catch(D=>{l(!1),d&&i("Connection failed",D)});if(!_)return;const S=_.operation.split("?")[0],v=location.protocol==="https:"?"wss":"ws",P=`${v}://${location.host}${ee}${S}/websocket?secret=${_.metadata.metadata.fds[0]}`,w=`${v}://${location.host}${ee}${S}/websocket?secret=${_.metadata.metadata.fds.control}`,E=new WebSocket(w);E.onerror=p,E.onclose=D=>{D.code!==1005&&c.current&&i("Console error",D.reason,Ki(D.code))},E.onmessage=D=>{console.log("control message",D)};try{window.spice_connection=new Ce({uri:P,screen_id:"spice-screen",onerror:p,onsuccess:()=>{l(!1),f()},onagent:f})}catch(D){d&&i("Connection failed",D)}return E};return b.useListener(window,f,"resize",!0),O.useEffect(f,[n.notification?.message]),b.useListener(window,_=>{if(!o.current?.parentElement||!("detail"in _))return;const S=_.detail.wheelEvent;o.current.parentElement.scrollBy(S.deltaX,S.deltaY)},"spice-wheel"),O.useEffect(()=>{n.clear();const _=g();return()=>{try{window.spice_connection?.stop()}catch(S){console.error(S)}_.then(S=>S?.close())}},[e.status]),t(()=>{const _=o.current;_&&_.requestFullscreen().then(f).catch(S=>{i("Failed to enter full-screen mode",S)})}),h.jsx(h.Fragment,{children:a?h.jsx(b.Spinner,{className:"u-loader",text:"Loading VGA session..."}):h.jsx("div",{id:"spice-area",ref:o,children:h.jsx("div",{id:"spice-screen",className:"spice-screen"})})})},t0=({instance:e,onFailure:t,showNotRunningInfo:i})=>{const{name:s,project:r}=si(),n=new TextEncoder,[o,a]=O.useState(!1),[l,c]=O.useState(""),[d,p]=O.useState(null),[f]=O.useState(new cl),[g,u]=O.useState(!1),_=O.useRef(null),S=b.useNotify(),v=Gc();Ya({when:g,message:"Are you sure you want to leave this page?"});const P=U=>{g&&(U.returnValue="Are you sure you want to leave this page?")};b.useListener(window,P,"beforeunload");const w=Ys(e),E=U=>{v.current&&t("Error",U)},D=async()=>{if(!s){t("Missing name",new Error);return}if(!r){t("Missing project",new Error);return}a(!0),hd(s,r).then(c).catch(console.error);const U=await cd(s,r).catch(M=>{a(!1),w?t("Connection failed",M):i()});if(!U)return;const X=U.operation.split("?")[0],ie=location.protocol==="https:"?"wss":"ws",Oe=`${ie}://${location.host}${ee}${X}/websocket?secret=${U.metadata.metadata.fds[0]}`,V=`${ie}://${location.host}${ee}${X}/websocket?secret=${U.metadata.metadata.fds.control}`,R=new WebSocket(Oe),I=new WebSocket(V);return I.onopen=()=>{a(!1)},I.onerror=E,I.onclose=M=>{M.code!==1005&&v.current&&t("Error",M.reason,Ki(M.code))},R.onopen=()=>{p(R)},R.onerror=E,R.onclose=M=>{M.code!==1005&&v.current&&t("Error",M.reason,Ki(M.code)),p(null),u(!1)},R.binaryType="arraybuffer",R.onmessage=M=>{const T=M.origin===`${ie}://${location.host}`;M.isTrusted&&T?_.current?.write(new Uint8Array(M.data)):console.warn("Ignored untrusted message",M)},[R,I]};O.useEffect(()=>{w&&_.current?.focus()},[w]),O.useEffect(()=>{if(d)return;S.clear();const U=D();return()=>{U.then(X=>{X?.map(ie=>{ie.close()})})}},[f,e.status]),O.useEffect(()=>{!l||!_.current||o||(_.current.write(l),c(""))},[l,o]);const N=()=>{fi("p-terminal",void 0,10),_.current?.element?.style.setProperty("padding","1rem"),f.fit()};return b.useListener(window,()=>{N(),setTimeout(N,500)},"resize",!0),b.useListener(window,N,"menu-collapse-toggle"),h.jsx(h.Fragment,{children:o?h.jsx(b.Spinner,{className:"u-loader",text:"Loading text console..."}):h.jsx(th,{ref:_,addons:[f],onData:U=>{u(!0),d?.send(n.encode(U))},className:"p-terminal",onOpen:N})})},i0=({instance:e})=>{const t=He(),{project:i}=si(),s=b.useToastNotification(),r=_t(),{openPortal:n,closePortal:o,isOpen:a,Portal:l}=b.usePortal(),[c,d]=O.useState(!1),{canEditInstance:p}=pt(),f=Zt(e).devices.find(S=>S.name===_o),g=()=>{d(!0);const S=Zt(e);S.devices=S.devices.filter(w=>w.name!==_o);const v=ys(e,S),P=h.jsx(ge,{instanceName:e.name,projectName:e.project});ji(v,i??"").then(w=>{t.set(w.metadata.id,()=>s.success(h.jsxs(h.Fragment,{children:["ISO"," ",h.jsx(Fi,{to:`${ee}/ui/project/${encodeURIComponent(i??"")}/storage/custom-isos`,type:"iso-volume",value:f?.bare?.source??""})," ","detached from ",P]})),E=>s.failure("Detaching ISO failed.",new Error(E),P),()=>{r.invalidateQueries({queryKey:[ve.instances,e.name,i]}),d(!1)})}).catch(w=>{d(!1),s.failure("Detaching ISO failed.",w,P)})},u=S=>{d(!0),o();const v=Zt(e),P=Ad(S);v.devices.push(P);const w=ys(e,v);ji(w,i??"").then(E=>{const D=Qa({operation:E,project:i});t.set(E.metadata.id,()=>s.success(h.jsxs(h.Fragment,{children:["ISO"," ",h.jsx(Fi,{to:`${ee}/ui/project/${encodeURIComponent(i??"")}/storage/custom-isos`,type:"iso-volume",value:S.aliases})," ","attached to ",D]})),N=>s.failure("Attaching ISO failed.",new Error(N),D),()=>{r.invalidateQueries({queryKey:[ve.instances,e.name,i]}),d(!1)})}).catch(E=>{d(!1),s.failure("Attaching ISO failed.",E)})},_=p(e)?void 0:"You do not have permission to edit this instance.";return f?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"u-text--muted margin-right",children:f?.bare?.source}),h.jsx(b.ActionButton,{loading:c,onClick:g,className:"u-no-margin--bottom",disabled:!!_||c,title:_,children:"Detach ISO"})]}):h.jsxs(h.Fragment,{children:[h.jsx(b.ActionButton,{loading:c,onClick:n,className:"u-no-margin--bottom",disabled:!!_||c,title:_,children:"Attach ISO"}),a&&h.jsx(l,{children:h.jsx(cu,{onClose:o,onSelect:u})})]})},s0=({disabled:e})=>{const[t,i]=O.useState(!1),[s,r]=O.useState(!1),n=()=>{const l=Av(),c=kv();l!==t&&i(l),c!==s&&r(c)};O.useEffect(()=>{const l=setInterval(n,500);return()=>{clearInterval(l)}});const o=()=>{Iv(window.spice_connection)},a=()=>{Pv(window.spice_connection)};return h.jsx(b.ContextualMenu,{hasToggleIcon:!0,toggleLabel:"Shortcuts",toggleClassName:"u-no-margin--bottom",toggleDisabled:e,toggleProps:{title:e?"Start the instance to access shortcuts":void 0},dropdownClassName:"instance-console-shortcut-dropdown",links:[{children:t?"Release and unlock Alt":"Hold and lock Alt",onClick:o},{children:s?"Release and unlock Ctrl":"Hold and lock Ctrl",onClick:a},{children:"Send Ctrl + Alt + Del",onClick:()=>{cv(window.spice_connection)}},{children:"Send Alt + Tab",onClick:()=>{uv(window.spice_connection)}},{children:"Send Alt + F4",onClick:()=>{dv(window.spice_connection)}},{children:"Send Print Screen",onClick:()=>{xv(window.spice_connection)}},{children:"Send F1",onClick:()=>{_v(window.spice_connection)}},{children:"Send F2",onClick:()=>{fv(window.spice_connection)}},{children:"Send F3",onClick:()=>{pv(window.spice_connection)}},{children:"Send F4",onClick:()=>{mv(window.spice_connection)}},{children:"Send F5",onClick:()=>{gv(window.spice_connection)}},{children:"Send F6",onClick:()=>{vv(window.spice_connection)}},{children:"Send F7",onClick:()=>{Sv(window.spice_connection)}},{children:"Send F8",onClick:()=>{bv(window.spice_connection)}},{children:"Send F9",onClick:()=>{yv(window.spice_connection)}},{children:"Send F10",onClick:()=>{Cv(window.spice_connection)}},{children:"Send F11",onClick:()=>{wv(window.spice_connection)}},{children:"Send F12",onClick:()=>{Ev(window.spice_connection)}}]})},r0=({instance:e})=>{const t=b.useNotify(),i=e.type==="virtual-machine",[s,r]=O.useState(i),{hasCustomVolumeIso:n}=Za(),{canUpdateInstanceState:o,canAccessInstanceConsole:a}=pt(),l=Ys(e),c=(S,v,P)=>{t.failure(S,v,P)},d=()=>{t.info("Start the instance to interact with the text console.","Instance not running")};let p=()=>{};const f=S=>{p=S},g=S=>{t.clear(),r(S)},{handleStart:u,isLoading:_}=Ha(e);return a(e)?h.jsxs("div",{className:"instance-console-tab",children:[i&&h.jsxs("div",{className:"p-panel__controls",children:[h.jsxs("div",{className:"console-radio-wrapper",children:[h.jsx(b.RadioInput,{labelClassName:"right-margin",label:"Graphic",checked:s,onChange:()=>{g(!0)}}),h.jsx(b.RadioInput,{label:"Text console",checked:!s,onChange:()=>{g(!1)}})]}),s&&h.jsxs("div",{children:[n&&h.jsx(i0,{instance:e}),h.jsx(b.Button,{className:"u-no-margin--bottom",disabled:!l,title:l?void 0:"Start the instance to enter fullscreen",onClick:()=>{p()},children:h.jsx("span",{children:"Fullscreen"})}),h.jsx(s0,{disabled:!l})]})]}),h.jsx(zs,{}),s&&!l&&h.jsxs(b.EmptyState,{className:"empty-state",image:h.jsx(b.Icon,{name:"pods",className:"empty-state-icon"}),title:"Instance stopped",children:[h.jsx("p",{children:"Start the instance to access the graphic console."}),h.jsx(b.ActionButton,{appearance:"positive",loading:_,"aria-disabled":_,onClick:u,disabled:!o(e)||_,title:o(e)?"":"You do not have permission to start this instance.",children:"Start instance"})]}),s&&l&&h.jsx("div",{className:"spice-wrapper",children:h.jsx(e0,{instance:e,onMount:f,onFailure:c})}),!s&&h.jsx(t0,{instance:e,onFailure:c,showNotRunningInfo:d})]}):h.jsx(b.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to access the console for this instance."})},n0=({instance:e,content:t,fileName:i})=>{const s=O.useRef(null),r=(o,a)=>{const l=document.createElement("a");return l.setAttribute("href",a),l.setAttribute("target","_blank"),l.setAttribute("download",i),l.setAttribute("id",o),l.style.display="none",l},n=async()=>{const o=`link-${i.toLowerCase().replace(" ","-")}`,a=document.getElementById(o);if(a){a.click();return}const l=t||await Ja(e.name,e.project,i),c=new Blob([l],{type:"text/plain"}),d=URL.createObjectURL(c),p=r(o,d);s.current?.appendChild(p),p.click()};return h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:()=>{n()},title:`Download ${i}`,"aria-label":`Download ${i} file`,hasIcon:!0,dense:!0,ref:s,children:h.jsx(b.Icon,{name:"begin-downloading",alt:"download"})})},o0=({instance:e,path:t})=>{const i=t.split("/").at(-1)??"",s=`${ee}/ui/project/${encodeURIComponent(e.project)}/instance/${encodeURIComponent(e.name)}/logs/?file=${encodeURIComponent(i)}`,[r,n]=O.useState(dd("file")===i),{data:o,isLoading:a,isSuccess:l}=el({queryKey:[ve.logs,e.name,e.project,i],queryFn:async()=>Ja(e.name,e.project,i),enabled:r}),c=()=>{n(d=>!d)};return h.jsxs("div",{className:"p-code-snippet file-row",children:[h.jsxs("div",{className:"p-code-snippet__header file-row-header",children:[h.jsxs(b.Button,{appearance:"base",hasIcon:!0,className:"u-no-margin--bottom file-row-toggle","aria-label":`Toggle ${i} visibility`,"aria-controls":i,"aria-hidden":!r,onClick:c,children:[h.jsx(b.Icon,{name:r?"chevron-up":"chevron-down"}),h.jsx("h2",{className:"p-code-snippet__title file-row-title",children:i})]}),h.jsx("a",{href:s,"aria-label":`File ${i} URL`,className:"p-button--base u-no-margin--bottom",children:h.jsx(b.Icon,{name:"get-link",alt:"link"})}),h.jsx(n0,{fileName:i,instance:e,content:o??""})]}),r&&h.jsx("pre",{id:i,className:"p-code-snippet__block","aria-hidden":!r,children:h.jsxs("code",{children:[a&&h.jsx(h.Fragment,{children:"Downloading file content..."}),l&&!o&&h.jsx(h.Fragment,{children:"This file is empty."}),l&&o&&h.jsx(h.Fragment,{children:o})]})})]})},a0=({instance:e})=>{const{data:t=[],isLoading:i}=el({queryKey:[ve.logs,e.name,e.project],queryFn:async()=>ud(e.name,e.project)});return h.jsxs(h.Fragment,{children:[i&&h.jsx(b.Spinner,{className:"u-loader",text:"Loading logs..."}),!i&&t.length===0&&h.jsx("div",{className:"u-align-text--center",children:"There are no log files for this instance."}),!i&&t.length>0&&t.map(s=>h.jsx(o0,{instance:e,path:s},s))]})},l0=({instanceProfiles:e,profiles:t})=>e.some(s=>!t?.find(r=>r.name===s))?h.jsx(b.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to view all profiles applied to this instance. This may cause inherited configuration values to be displayed incorrectly."}):null,h0=({instance:e})=>{const t=He(),i=b.useToastNotification(),{project:s,section:r}=si(),n=wu(),o=_t(),a=Gs(),[l,c]=O.useState(0),{canEditInstance:d}=pt();if(!s)return h.jsx(h.Fragment,{children:"Missing project"});const{data:p=[]}=za(s),f=()=>{fi("form-contents","p-bottom-controls")};O.useEffect(f,[r]),b.useListener(window,f,"resize",!0);const g=d(e)?void 0:"You do not have permission to edit this instance",u=ft({initialValues:Zt(e,g),validationSchema:il,enableReinitialize:!0,onSubmit:w=>{const E=w.yaml?gu(w.yaml):ys(e,w);E.etag=e.etag;const D=h.jsx(ge,{instanceName:e.name,projectName:e.project});ji(E,s).then(N=>{t.set(N.metadata.id,()=>{i.success(h.jsxs(h.Fragment,{children:["Instance ",D," updated."]})),u.resetForm({values:Zt(E)})},U=>i.failure("Instance update failed.",new Error(U),D),()=>{u.setSubmitting(!1),o.invalidateQueries({queryKey:[ve.instances]})})}).catch(N=>{u.setSubmitting(!1),i.failure("Instance update failed.",N,D)})}}),_=`${ee}/ui/project/${encodeURIComponent(s)}/instance/${encodeURIComponent(e.name)}/configuration`,S=w=>{u.values.yaml&&w!==Ei&&u.setFieldValue("yaml",void 0),a(w===ur?_:`${_}/${Ie(w)}`)},v=()=>{const w=new Set(["backups","snapshots","state","expanded_config","expanded_devices","etag"]),E=Object.fromEntries(Object.entries(e).filter(D=>!w.has(D[0])));return Su(E)},P=u.values.readOnly;return h.jsxs("div",{className:"edit-instance",children:[h.jsxs(b.Form,{onSubmit:u.handleSubmit,className:"form",children:[r!==Ie(Ei)&&h.jsx(Pd,{active:r??Ie(ur),setActive:S,isDisabled:!1,hasDiskError:So(u),hasNetworkError:vo(u),formik:u}),h.jsx(b.Row,{className:"form-contents",children:h.jsxs(b.Col,{size:12,children:[r!==Ie(Ei)&&h.jsx(l0,{instanceProfiles:e.profiles,profiles:p}),(r===Ie(ur)||!r)&&h.jsx(kd,{formik:u,project:s}),r===Ie(Md)&&h.jsx(du,{formik:u,project:s}),r===Ie(Dd)&&h.jsx(uu,{formik:u,project:s}),r===Ie(Td)&&h.jsx(_u,{formik:u,project:s}),r===Ie(Rd)&&h.jsx(fu,{formik:u,project:s}),r===Ie(Ld)&&h.jsx(pu,{formik:u,project:s}),r===Ie(Nd)&&h.jsx(Bd,{formik:u}),r===Ie(Od)&&h.jsx(Ud,{formik:u,setSection:S}),r===Ie(Fd)&&h.jsx(sl,{formik:u}),r===Ie(jd)&&h.jsx(Kd,{formik:u}),r===Ie(zd)&&h.jsx(Yd,{formik:u}),r===Ie(Hd)&&h.jsx(Gd,{formik:u,project:s},`yaml-form-${l}`),r===Ie(Ei)&&h.jsx(Wd,{yaml:v(),setYaml:w=>{fo(u),u.setFieldValue("yaml",w)},readOnly:!!u.values.editRestriction,readOnlyMessage:u.values.editRestriction,children:h.jsx(yu,{entity:"instance",docPath:"/instances"})},`yaml-form-${l}`)]})},r)]}),h.jsxs(bu,{children:[h.jsx(vu,{formik:u,section:r,setSection:S}),P?null:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",onClick:()=>{u.resetForm({values:Zt(e)}),c(w=>w+1)},children:"Cancel"}),h.jsx(Cu,{formik:u,baseUrl:_,isYaml:r===Ie(Ei),disabled:So(u)||vo(u)})]})]}),(n.panel===bo.editNetworkDevice||n.panel===bo.createNetworkDevice)&&h.jsx(mu,{project:s,formik:u,onSave:()=>{fo(u)}})]})},c0=({instance:e,onSelect:t,targetMember:i,onCancel:s,migrate:r})=>{const n=h.jsx("div",{className:"migrate-instance-summary",children:h.jsxs("p",{children:["This will migrate instance ",h.jsx("strong",{children:e.name})," to cluster member ",h.jsx("b",{children:i}),"."]})});return h.jsxs(h.Fragment,{children:[i&&n,!i&&h.jsx(Iu,{onSelect:t,disableMember:{name:e.location,reason:"Instance already on this member"}}),h.jsxs("footer",{id:"migrate-instance-actions",className:"p-modal__footer",children:[h.jsx(b.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:s,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{r(i)},disabled:!i,children:"Migrate"})]})]})},d0=({instance:e,onSelect:t,targetPool:i,onCancel:s,migrate:r})=>{const n=h.jsx("div",{className:"migrate-instance-summary",children:h.jsxs("p",{children:["This will migrate the instance ",h.jsx("strong",{children:e.name})," root storage to pool ",h.jsx("b",{children:i}),"."]})});return h.jsxs(h.Fragment,{children:[i&&n,!i&&h.jsx(Au,{onSelect:t,disablePool:{name:_d(e),reason:"Instance root storage already in this pool"}}),h.jsxs("footer",{id:"migrate-instance-actions",className:"p-modal__footer",children:[h.jsx(b.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:s,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{r(i)},disabled:!i,children:"Migrate"})]})]})},u0=({instance:e,close:t,type:i,target:s})=>{const r=b.useToastNotification(),n=Ws(),o=He(),a=_t(),l=Gs(),c=()=>{let u="";if(i==="cluster member"&&(u=h.jsxs(h.Fragment,{children:["Instance"," ",h.jsx(ge,{instanceName:e.name,projectName:e.project})," ","successfully migrated to cluster member"," ",h.jsx(rl,{clusterMember:s})]})),i==="root storage pool"&&(u=h.jsxs(h.Fragment,{children:["Instance"," ",h.jsx(ge,{instanceName:e.name,projectName:e.project})," ","root storage successfully moved to pool"," ",h.jsx(ku,{poolName:s,projectName:e.project,location:e.location})]})),i==="project"){u=h.jsxs(h.Fragment,{children:["Instance"," ",h.jsx(ge,{instanceName:e.name,projectName:s}),"successfully moved to project ",h.jsx(hl,{projectName:s})]});const _=window.location.pathname,S=_.replace(`${ee}/ui/project/${e.project}/instance/${e.name}`,`${ee}/ui/project/${s}/instance/${e.name}`);_!==S&&l(S)}r.success(u)},d=u=>{let _="";i==="cluster member"&&(_=`Cluster member migration failed for instance ${e.name}`),i==="root storage pool"&&(_=`Root storage move failed for instance ${e.name}`),i==="project"&&(_=`Project move failed for instance ${e.name}`),n.setFinish(e),r.failure(_,u,h.jsx(ge,{instanceName:e.name,projectName:e.project}))},p=u=>{d(new Error(u))},f=()=>{a.invalidateQueries({queryKey:[ve.instances,e.name,e.project]}),a.invalidateQueries({queryKey:[ve.instances,e.project]}),a.invalidateQueries({queryKey:[ve.operations,e.project]}),n.setFinish(e)};return{handleMigrate:()=>{n.setLoading(e,"Migrating");const u=i==="cluster member"?s:void 0,_=i==="root storage pool"?s:void 0,S=i==="project"?s:void 0;fd(e.name,e.project,u,_,S).then(v=>{o.set(v.metadata.id,c,P=>{p(P)},f),r.info(h.jsxs(h.Fragment,{children:[pd(i)," migration started for"," ",h.jsx(ge,{instanceName:e.name,projectName:e.project}),"."]})),a.invalidateQueries({queryKey:[ve.instances,e.name,e.project]})}).catch(v=>{d(v)}).finally(()=>{t()})}}},_0=({instance:e,onSelect:t,targetProject:i,onCancel:s,migrate:r})=>{const n=h.jsx("div",{className:"migrate-instance-summary",children:h.jsxs("p",{children:["This will migrate the instance ",h.jsx("strong",{children:e.name})," to the project ",h.jsx("b",{children:i}),"."]})});return h.jsxs(h.Fragment,{children:[i&&n,!i&&h.jsx(Pu,{onSelect:t,disableProject:{name:e.project,reason:"Instance already in this project"}}),h.jsxs("footer",{id:"migrate-instance-actions",className:"p-modal__footer",children:[h.jsx(b.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:s,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{r(i)},disabled:!i,children:"Migrate"})]})]})},f0=({close:e,instance:t})=>{const i=Ks(),[s,r]=O.useState(""),[n,o]=O.useState(""),{handleMigrate:a}=u0({close:e,instance:t,type:s,target:n}),l=f=>{f.key==="Escape"&&e()},c=()=>{if(n){o("");return}if(s){r("");return}},d=h.jsxs(h.Fragment,{children:["Choose ",s," for instance ",h.jsx("strong",{children:t.name})]}),p=s?h.jsx(xu,{title:n?"Confirm migration":d,onClick:c,linkText:n?`Choose ${s}`:"Choose migration method"}):"Choose migration method";return h.jsxs(b.Modal,{close:e,className:"migrate-instance-modal",onKeyDown:l,"aria-labelledby":"migrate-title",children:[h.jsxs("header",{className:"p-modal__header",children:[h.jsx("h2",{className:"p-modal__title",id:"migrate-title",children:p},s?n?"confirm":"select":"start"),h.jsx("button",{className:"p-modal__close","aria-label":"Close active modal",onClick:e,children:"Close"})]}),!s&&h.jsxs("div",{className:"choose-migration-type",children:[i&&h.jsx(_r,{icon:"cluster-host",title:"Migrate instance to a different cluster member",onClick:()=>{r("cluster member")}}),h.jsx(_r,{icon:"storage-pool",title:"Move instance root storage to a different pool",onClick:()=>{r("root storage pool")}}),h.jsx(_r,{icon:"folder",title:"Move instance to a different project",onClick:()=>{r("project")}})]}),s==="cluster member"&&h.jsx(c0,{instance:t,onSelect:o,targetMember:n,onCancel:c,migrate:a}),s==="root storage pool"&&h.jsx(d0,{instance:t,onSelect:o,targetPool:n,onCancel:c,migrate:a}),s==="project"&&h.jsx(_0,{instance:t,onSelect:o,targetProject:n,onCancel:c,migrate:a})]})},p0=({instance:e,classname:t})=>{const{openPortal:i,closePortal:s,isOpen:r,Portal:n}=b.usePortal(),{canEditInstance:o}=pt(),a=Ws(),l=a.getType(e)==="Migrating"||e.status==="Migrating",c=l||!!a.getType(e);return h.jsxs(h.Fragment,{children:[r&&h.jsx(n,{children:h.jsx(f0,{close:s,instance:e})}),h.jsxs(b.ActionButton,{onClick:i,type:"button",className:qi("u-no-margin--bottom has-icon",t),loading:l,disabled:c||!o(e)||l,title:o()?"Migrate instance":"You do not have permission to migrate this instance",children:[h.jsx(b.Icon,{name:"machines"}),h.jsx("span",{children:"Migrate"})]})]})},m0=({instance:e,close:t})=>{const i=He(),s=b.useToastNotification(),r=_t(),n=h.jsx(ge,{instanceName:e.name,projectName:e.project}),{data:o}=Vi(e.project),{canCreateImageAliases:a}=Wt(),l=()=>{const p=h.jsx(An,{to:`${ee}/ui/project/${encodeURIComponent(e.project)}/images`,children:"created"});s.success(h.jsxs(h.Fragment,{children:["Image ",p," from instance ",n,"."]}))},c=()=>{r.invalidateQueries({predicate:p=>p.queryKey[0]===ve.images})},d=ft({initialValues:{alias:a(o)?`from-instance-${e.name}`:"",isPublic:!1},validationSchema:Ht().shape({alias:Kt()}),onSubmit:p=>{const f=JSON.stringify({aliases:al(p.alias),public:p.isPublic,source:{name:e.name,type:"instance"}});Wa(f,e.project).then(g=>{s.info(h.jsxs(h.Fragment,{children:["Creation of image from instance ",n," started."]})),i.set(g.metadata.id,()=>{c(),l()},u=>{s.failure(`Image creation from instance "${e.name}" failed.`,new Error(u),n)})}).catch(g=>{s.failure(`Image creation from instance "${e.name}" failed.`,g,n)}).finally(()=>{t()})}});return h.jsx(b.Modal,{close:t,className:"create-image-from-instance-modal",title:"Create image from instance",buttonRow:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:t,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:d.isSubmitting,disabled:!d.isValid||d.isSubmitting,onClick:()=>{d.submitForm()},children:"Create image"})]}),children:h.jsxs(b.Form,{onSubmit:d.handleSubmit,children:[h.jsx(b.Input,{type:"text",label:"Instance",value:e.name,disabled:!0}),h.jsx(b.Input,{...d.getFieldProps("alias"),type:"text",label:"Alias",error:d.touched.alias?d.errors.alias:null,disabled:!a(o),title:a(o)?"":"You do not have permission to create image aliases in this project"}),h.jsx(b.Input,{...d.getFieldProps("isPublic"),type:"checkbox",label:"Make the image publicly available",error:d.touched.isPublic?d.errors.isPublic:null}),h.jsx(b.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},g0=({instance:e,classname:t,onClose:i})=>{const{openPortal:s,closePortal:r,isOpen:n,Portal:o}=b.usePortal(),{data:a}=Vi(e.project),{canCreateImages:l}=Wt(),c=Ws(),d=["Error","Frozen","Running"],p=()=>{r(),i?.()},f=()=>l(a)?d.includes(e?.status)||!!c.getType(e)?"Stop the instance to create an image":"":"You do not have permission to create images in this project";return h.jsxs(h.Fragment,{children:[n&&h.jsx(o,{children:h.jsx(m0,{close:p,instance:e})}),h.jsxs(b.ActionButton,{appearance:"default",className:qi("u-no-margin--bottom has-icon",t),onClick:s,"aria-label":"Create image",title:f()||"Create image",disabled:!!f(),children:[h.jsx(b.Icon,{name:"plus"}),h.jsx("span",{children:"Create Image"})]})]})},v0=({instance:e,close:t})=>{const i=b.useToastNotification(),s=Ks(),r=O.useState(null),n=Gs(),o=He(),{data:a=[],isLoading:l}=Hs(),{canCreateInstances:c}=Wt(),{data:d=[],isLoading:p}=$a(),{data:f=[]}=Va(e.project),g=(S,v,P)=>{const w=`${ee}/ui/project/${encodeURIComponent(v)}/instance/${encodeURIComponent(S)}`,E=h.jsxs(h.Fragment,{children:["Created instance"," ",h.jsx(Fi,{type:P,value:S,to:w}),"."]}),D=[{label:"Configure",onClick:async()=>n(`${w}/configuration`)}];i.success(E,D)},_=ft({initialValues:{instanceName:(S=>{const v=Xa(S.name,"-copy");return md(v,f)})(e),targetProject:e.project,allowInconsistent:!1,instanceOnly:!1,targetClusterMember:s?e.location:"",targetStoragePool:e.devices.root?.pool??d[0]?.name},enableReinitialize:!0,validationSchema:Ht().shape({instanceName:Pn(e.project,r).required()}),onSubmit:S=>{const v=h.jsx(ge,{instanceName:e.name,projectName:e.project});qa(JSON.stringify({description:e.description,name:S.instanceName,architecture:e.architecture,source:{allow_inconsistent:S.allowInconsistent,instance_only:S.instanceOnly,source:e.name,type:"copy",project:e.project},devices:{...e.devices,root:{path:"/",type:"disk",pool:S.targetStoragePool}}}),S.targetProject,S.targetClusterMember).then(P=>{i.info(h.jsxs(h.Fragment,{children:["Copy of instance ",v," started."]})),o.set(P.metadata.id,()=>{g(S.instanceName,S.targetProject,e.type)},w=>i.failure("Instance copy failed.",new Error(w),v))}).catch(P=>{i.failure("Instance copy failed.",P,v)}).finally(()=>{t()})}});return h.jsx(b.Modal,{close:t,className:"copy-instances-modal",title:"Copy Instance",buttonRow:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:t,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:_.isSubmitting,disabled:!_.isValid||_.isSubmitting||p||l,onClick:()=>{_.submitForm()},children:"Copy"})]}),children:h.jsxs(b.Form,{onSubmit:_.handleSubmit,children:[h.jsx(b.Input,{..._.getFieldProps("instanceName"),type:"text",label:"New instance name",error:_.touched.instanceName?_.errors.instanceName:null}),h.jsx(ll,{..._.getFieldProps("targetClusterMember"),id:"targetClusterMember",label:"Target cluster member"}),h.jsx(Mu,{..._.getFieldProps("targetStoragePool"),setValue:S=>{_.setFieldValue("targetStoragePool",S)},selectProps:{id:"storagePool",label:"Storage pool"}}),h.jsx(b.Select,{..._.getFieldProps("targetProject"),id:"project",label:"Target project",options:a.filter(c).map(S=>({label:S.name,value:S.name}))}),h.jsx(b.Input,{..._.getFieldProps("allowInconsistent"),type:"checkbox",label:"Ignore copy errors for volatile files",error:_.touched.allowInconsistent?_.errors.allowInconsistent:null}),h.jsx(b.Input,{..._.getFieldProps("instanceOnly"),type:"checkbox",label:"Copy without instance snapshots",error:_.touched.instanceOnly?_.errors.instanceOnly:null}),h.jsx(b.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},S0=({instance:e,isLoading:t,classname:i,onClose:s})=>{const{openPortal:r,closePortal:n,isOpen:o,Portal:a}=b.usePortal(),{data:l}=Vi(e.project),{data:c}=Hs(),{canCreateInstances:d}=Wt(),p=()=>{n(),s?.()},f=()=>{const g=c?.filter(d);return!d(l)||!g?.length?"You do not have permission to copy instances":t?"Loading...":""};return h.jsxs(h.Fragment,{children:[o&&h.jsx(a,{children:h.jsx(v0,{close:p,instance:e})}),h.jsxs(b.Button,{appearance:"default","aria-label":"Copy instance",className:qi("u-no-margin--bottom has-icon",i),disabled:!!f(),onClick:r,title:f()||"Copy instance",children:[h.jsx(b.Icon,{name:"canvas"}),h.jsx("span",{children:"Copy"})]})]})},b0=({instance:e,close:t})=>{const i=He(),s=b.useToastNotification(),r=h.jsx(ge,{instanceName:e.name,projectName:e.project}),{hasBackupMetadataVersion:n}=Za(),o=_t(),{data:a}=tl(),l=a?.environment?.backup_metadata_version_range??[],c=_=>{const S=`${ee}/1.0/instances/${encodeURIComponent(e.name)}/backups/${encodeURIComponent(_)}/export?project=${encodeURIComponent(e.project)}`,v=document.createElement("a");v.href=S,v.download=_,v.click(),window.URL.revokeObjectURL(S),s.success(h.jsxs(h.Fragment,{children:["Instance ",r," download started:",h.jsx("br",{}),h.jsx("a",{href:S,children:_})]}))},d=_=>{const S=new Date;return S.setHours(S.getHours()+_),S},p=_=>{const S=new Date().toISOString().replaceAll(":","-").split(".")[0],v=`${e.name}-${S}.tar${_.compression==="gzip"?".gz":""}`,P=JSON.stringify({name:v,expires_at:d(_.expirationHours).toISOString(),compression_algorithm:_.compression,instance_only:_.instanceOnly,optimized_storage:_.optimizedStorage,version:n?Number(_.exportVersion):void 0});vd(e.name,e.project,P).then(w=>{s.info(h.jsxs(h.Fragment,{children:["Backing up instance ",r,".",h.jsx("br",{}),"Download will start, when the export is ready."]})),i.set(w.metadata.id,()=>{c(v)},E=>s.failure(`Could not download instance ${e.name}`,new Error(E),r))}).catch(w=>s.failure(`Could not download instance ${e.name}`,w,r)).finally(()=>{o.invalidateQueries({queryKey:[ve.operations]}),t()})},f=ft({initialValues:{compression:"gzip",exportVersion:"2",expirationHours:6,instanceOnly:!1,optimizedStorage:!0},onSubmit:_=>{p(_)}}),g=Object.values(e?.expanded_devices??{}).filter(gd).filter(_=>_.path!=="/"),u=g.length>0;return h.jsx(b.Modal,{close:t,className:"export-instance-modal",title:"Export Instance",buttonRow:h.jsxs(h.Fragment,{children:[h.jsx(b.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:t,children:"Cancel"}),h.jsx(b.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:f.isSubmitting,disabled:f.isSubmitting,onClick:()=>{f.submitForm()},children:"Export instance"})]}),children:h.jsxs(b.Form,{onSubmit:f.handleSubmit,children:[u&&h.jsxs(b.Notification,{severity:"information",title:"Custom disks wil be ignored",children:["This instance has ",g.length," custom"," ",ci("disk",g.length),", which will be ignored in the export."]}),h.jsx(b.Select,{...f.getFieldProps("compression"),id:"project",label:"Compression",help:"No compression will be faster, but larger",options:[{value:"gzip",label:"Gzip"},{value:"none",label:"None"}]}),h.jsx(b.Select,{...f.getFieldProps("expirationHours"),id:"project",label:"Expiration",help:"Duration that the backup remains on the server",options:[{value:1,label:"1 hour"},{value:6,label:"6 hours"},{value:12,label:"12 hours"},{value:24,label:"1 day"},{value:72,label:"3 days"},{value:168,label:"7 days"}]}),n&&h.jsx(b.Select,{...f.getFieldProps("exportVersion"),id:"exportVersion",label:"Export version",help:"Lower versions allow imports on older LXD versions",options:l.map(_=>({value:_.toString(),label:_.toString()}))}),h.jsx(b.Input,{...f.getFieldProps("optimizedStorage"),type:"checkbox",label:"Use storage driver optimized format",help:"Can only be restored on a similar pool",checked:f.values.optimizedStorage}),h.jsx(b.Input,{...f.getFieldProps("instanceOnly"),type:"checkbox",label:"Export without instance snapshots",error:f.touched.instanceOnly?f.errors.instanceOnly:null,checked:f.values.instanceOnly}),h.jsx(b.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},y0=({instance:e,classname:t,onClose:i})=>{const{openPortal:s,closePortal:r,isOpen:n,Portal:o}=b.usePortal(),{canManageInstanceBackups:a}=pt(),{project:l}=kn(),c=ru(l),d=()=>{r(),i?.()},p=()=>a(e)?c?`Project "${l?.name}" doesn't allow for backup creation.`:"Export instance":"You do not have permission to export this instance.";return h.jsxs(h.Fragment,{children:[n&&h.jsx(o,{children:h.jsx(b0,{close:d,instance:e})}),h.jsxs(b.Button,{appearance:"default",className:qi("u-no-margin--bottom has-icon",t),onClick:s,title:p(),disabled:!a(e)||c,children:[h.jsx(b.Icon,{name:"export"}),h.jsx("span",{children:"Export"})]})]})},C0=({instance:e,project:t,isLoading:i})=>{const s=Sd(bd),r=s?"p-contextual-menu__link":"p-segmented-control__button",n=[h.jsx(p0,{instance:e,project:t,classname:r},"migrate"),h.jsx(g0,{instance:e,classname:r},"publish"),h.jsx(S0,{instance:e,isLoading:i,classname:r},"copy"),h.jsx(y0,{instance:e,classname:r},"export"),h.jsx(Xd,{instance:e,classname:r},"delete")];return h.jsx(h.Fragment,{children:s?h.jsx(b.ContextualMenu,{closeOnOutsideClick:!1,toggleLabel:"Actions",position:"left",hasToggleIcon:!0,title:"actions",children:o=>h.jsx("span",{children:[...n].map(a=>O.cloneElement(a,{onClose:o}))})}):h.jsx("div",{className:"p-segmented-control",children:h.jsx("div",{className:"p-segmented-control__list",children:n})})})},w0=({name:e,instance:t,project:i,isLoading:s})=>{const r=He(),n=Gs(),o=b.useToastNotification(),{canEditInstance:a}=pt(),l=O.useState(null),{canViewProject:c}=kn(),d=Ws(),p=t?d.getType(t):void 0,f=Ht().shape({name:Pn(i,l,e).required("Instance name is required")}),g=ft({initialValues:{name:e,isRenaming:!1},validationSchema:f,onSubmit:_=>{if(e===_.name){g.setFieldValue("isRenaming",!1),g.setSubmitting(!1);return}yd(e,_.name,i).then(S=>{const v=h.jsx(ge,{instanceName:_.name,projectName:i});r.set(S.metadata.id,()=>{n(`${ee}/ui/project/${encodeURIComponent(i)}/instance/${encodeURIComponent(_.name)}`),o.success(h.jsxs(h.Fragment,{children:["Instance"," ",h.jsx("strong",{children:Cd(S.metadata)})," renamed to ",v,"."]})),g.setFieldValue("isRenaming",!1)},P=>o.failure("Renaming instance failed.",new Error(P),Qa({operation:S,project:i})),()=>{g.setSubmitting(!1)})}).catch(S=>{g.setSubmitting(!1),o.failure("Renaming instance failed.",S,t&&h.jsx(ge,{instanceName:t.name,projectName:t.project}))})}}),u=()=>{if(!a(t))return"You do not have permission to rename this instance";if(!t)return"Invalid Instance: Cannot be renamed";if(t.status!=="Stopped")return"Stop the instance to rename"};return!s&&h.jsx(Eu,{name:e,titleClassName:"instance-detail-title",parentItems:[h.jsx(An,{to:c?`${ee}/ui/project/${encodeURIComponent(i)}/instances`:`${ee}/ui/all-projects/instances`,children:"Instances"},1)],renameDisabledReason:u(),centerControls:t?h.jsxs("div",{className:"instance-header-state-controls",children:[h.jsx("i",{className:"status u-text--muted",children:p??t.status}),h.jsx(wd,{instance:t},"state")]}):null,controls:t?h.jsx(C0,{instance:t,project:i,isLoading:s}):null,isLoaded:!!t,formik:g})},E0=(e,t,i)=>{const s=i?.config?.["user.ui_grafana_base_url"]??i?.config?.["user.grafana_base_url"]??"";return s?(s.includes("{instance}")?s:`${s}&var-job=lxd&var-project={project}&var-name={instance}&var-top=5`).replace("{instance}",encodeURIComponent(e)).replace("{project}",encodeURIComponent(t)):""},x0=["Overview","Configuration","Snapshots","Terminal","Console","Logs"],ES=()=>{const{data:e}=tl(),{name:t,project:i,activeTab:s}=si();if(!t)return h.jsx(h.Fragment,{children:"Missing name"});if(!i)return h.jsx(h.Fragment,{children:"Missing project"});const{data:r,error:n,refetch:o,isLoading:a}=Ed(t,i),l=[...x0],c=E0(t,i,e);return c&&l.push({label:h.jsxs("div",{children:[h.jsx(b.Icon,{name:"external-link"})," Metrics"]}),href:c,target:"_blank",rel:"noopener noreferrer"}),h.jsxs(b.CustomLayout,{header:h.jsx(w0,{name:t,instance:r,project:i,isLoading:a}),contentClassName:"detail-page",children:[a&&h.jsx(b.Spinner,{className:"u-loader",text:"Loading instance details...",isMainComponent:!0}),!a&&!r&&h.jsx(xd,{entityType:"instance",entityName:t,errorMessage:n?.message}),!a&&r&&h.jsxs(b.Row,{children:[h.jsx(Du,{tabs:l,activeTab:s,tabUrl:`${ee}/ui/project/${encodeURIComponent(i)}/instance/${encodeURIComponent(t)}`}),!s&&h.jsx("div",{role:"tabpanel","aria-labelledby":"overview",children:h.jsx(Nu,{instance:r})}),s==="configuration"&&h.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:h.jsx(h0,{instance:r})}),s==="snapshots"&&h.jsx("div",{role:"tabpanel","aria-labelledby":"snapshots",children:h.jsx(bm,{instance:r})}),s==="terminal"&&h.jsx("div",{role:"tabpanel","aria-labelledby":"terminal",children:h.jsx(Jp,{instance:r,refreshInstance:o})}),s==="console"&&h.jsx("div",{role:"tabpanel","aria-labelledby":"console",children:h.jsx(r0,{instance:r})}),s==="logs"&&h.jsx("div",{role:"tabpanel","aria-labelledby":"logs",children:h.jsx(a0,{instance:r})})]})]})};export{ES as default};