@illgrenoble/webx-client 1.12.1 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var e=require("three"),t=require("@tweenjs/tween.js");function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}}),t.default=e,Object.freeze(t)}var i=s(e);class n{constructor(e){this.id=e.id,this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.shaped=e.shaped||!1}}class a{constructor(e){this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.depth=e.depth,this.colorMap=e.colorMap,this.alphaMap=e.alphaMap}}const r=(e,t,s)=>{if(t&&s)for(let i=0;i<e.length;i+=4)s[i]<128?e[i+3]=0:e[i+3]=t[i+1];else if(t)for(let s=0;s<e.length;s+=4)e[s+3]=t[s+1];else if(s)for(let t=0;t<e.length;t+=4)e[t+3]=s[t]<128?0:e[t+3]},o=(e,t)=>{for(let s=0;s<e.length;s+=4)e[s+3]=t[s+1]};class h extends e.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get alphaMap(){return this.uniforms.alphaMap.value}set alphaMap(e){this.uniforms.alphaMap.value=e}get stencilMap(){return this.uniforms.stencilMap.value}set stencilMap(e){this.uniforms.stencilMap.value=e,e?this.defines.USE_STENCILMAP="":delete this.defines.USE_STENCILMAP}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value.copy(e)}constructor(t){super({uniforms:{map:{value:null},alphaMap:{value:null},stencilMap:{value:null},mapTransform:{value:new e.Matrix3},alphaMapTransform:{value:new e.Matrix3},diffuse:{value:new e.Color(16777215)},opacity:{value:1}},vertexShader:"\n#ifdef USE_MAP\nuniform mat3 mapTransform;\nvarying vec2 vMapUv;\n#endif\n\n#ifdef USE_ALPHAMAP\nuniform mat3 alphaMapTransform;\nvarying vec2 vAlphaMapUv;\n#endif\n\n#ifdef USE_STENCILMAP\nvarying vec2 vStencilMapUv;\n#endif\n\nvoid main() {\n#ifdef USE_MAP\n vMapUv = (mapTransform * vec3(uv, 1)).xy;\n#endif\n\n#ifdef USE_ALPHAMAP\n vAlphaMapUv = (alphaMapTransform * vec3(uv, 1)).xy;\n#endif\n\n#ifdef USE_STENCILMAP\n vStencilMapUv = uv;\n#endif\n\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\nuniform vec3 diffuse;\nuniform float opacity;\n\n#ifdef USE_MAP\nuniform sampler2D map;\nvarying vec2 vMapUv;\n#endif\n\n#ifdef USE_ALPHAMAP\nuniform sampler2D alphaMap;\nvarying vec2 vAlphaMapUv;\n#endif\n\n#ifdef USE_STENCILMAP\nuniform sampler2D stencilMap;\nvarying vec2 vStencilMapUv;\n#endif\n\nvoid main() {\n vec4 diffuseColor = vec4(diffuse, opacity);\n\n#ifdef USE_STENCILMAP\n vec4 stencil = texture2D(stencilMap, vStencilMapUv);\n if (stencil.r < 0.5) {\n discard;\n }\n#endif\n\n#ifdef USE_MAP\n vec4 sampledDiffuseColor = texture2D(map, vMapUv);\n diffuseColor *= sampledDiffuseColor;\n#endif\n\n#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D(alphaMap, vAlphaMapUv).g;\n#endif\n\n gl_FragColor = diffuseColor;\n gl_FragColor = linearToOutputTexel( gl_FragColor );\n}\n",transparent:!0,depthTest:!0,side:e.BackSide}),t&&t.color&&this.color.set(t.color)}onBeforeRender(){this.map&&this.map.matrixAutoUpdate&&(this.map.updateMatrix(),this.uniforms.mapTransform.value.copy(this.map.matrix)),this.alphaMap&&this.alphaMap.matrixAutoUpdate&&(this.alphaMap.updateMatrix(),this.uniforms.alphaMapTransform.value.copy(this.alphaMap.matrix))}}class l{}const c="srgb",d="srgb-linear";class u{constructor(e){this.image=e.image?e.image:null,this.data=e.data,this.width=e.image?e.image.width:e.width,this.height=e.image?e.image.height:e.height,this.colorSpace=c,this.flipY=!1}isTransferable(){return this.image&&this.image instanceof ImageBitmap||null!=this.data}get transferable(){return this.image&&this.image instanceof ImageBitmap?this.image:this.data?this.data.buffer:null}}class p{constructor(){}async createTextureFromArray(e,t,s){if(null!=e&&e.byteLength>0){const i=new Blob([e],{type:t}),n=await this.createTextureFromBlob(i);return n.flipY=!1,n.colorSpace=s,n}return null}createTextureFromBlob(e){return"function"==typeof createImageBitmap?new Promise((t,s)=>{createImageBitmap(e).then(e=>{const s=new u({image:e});t(s)}).catch(e=>{console.warn(`Failed to create texture using createImageBitmap from binary data: ${e}`),s(e)})}):new Promise((t,s)=>{const i=URL.createObjectURL(e),n=new Image;n.onload=()=>{URL.revokeObjectURL(i);const e=new u({image:n});t(e)},n.onerror=e=>{console.warn(`Failed to create texture from binary data: ${e}`),s(e)},n.src=i})}}const y=t=>{if(t){const s=t.data?new i.DataTexture(t.data,t.width,t.height):new i.Texture(t.image);return s.needsUpdate=!0,s.flipY=t.flipY,s.colorSpace=t.colorSpace,s.minFilter=e.LinearFilter,s}return null};class m{get mesh(){return this._mesh}get colorIndex(){return this._colorIndex}get id(){return this._id}get visible(){return this._material.visible}set visible(e){this._material.visible!==e&&(this._material.visible=e)}get loaded(){return this._loaded}get colorMap(){return this._material.map}set colorMap(e){this._material.map=e}get alphaMap(){return this._material.alphaMap}set alphaMap(e){this._material.alphaMap=e}get stencilMap(){return this._material.stencilMap}set stencilMap(e){this._material.stencilMap=e}get colorMapValid(){return null!=this.colorMap&&this.colorMap.image.width===this._width&&this.colorMap.image.height===this._height}get depth(){return this._depth}get x(){return this._x}set x(e){this._x=e,this._updatePosition()}get y(){return this._y}set y(e){this._y=e,this._updatePosition()}get z(){return this._z}set z(e){this._z=e,this._updatePosition()}get width(){return this._width}set width(e){this._width=e,this._updateScale(),this._updatePosition()}get height(){return this._height}set height(e){this._height=e,this._updateScale(),this._updatePosition()}get shaped(){return this._shaped}set shaped(e){this._shaped=e,e||this.updateStencilTexture(null)}constructor(e,t){this._width=1,this._height=1,this._shaped=!1,this._loaded=!1,this._windowRefreshTimeout=null,this._windowImageFactory=t,this._colorIndex=m._COLOR_INDEX++,this._material=new h,this.visible=!1;const{id:s,x:n,y:a,z:r,width:o,height:c,shaped:d}=e;this._id=s,this._mesh=new i.Mesh(m._PLANE_GEOMETRY,this._material),this._mesh.onBeforeRender=()=>this._material.onBeforeRender(),this._x=n,this._y=a,this._z=r,this._width=o,this._height=c,this._shaped=d&&l.version.versionNumber>=1.4,this._updateScale(),this._updatePosition()}async loadWindowImage(){const e=await this._windowImageFactory.getWindowTexture(this._id);e&&this.updateTexture(e.depth,y(e.colorMap),y(e.alphaMap),!0)}async loadWindowShape(){const e=await this._windowImageFactory.getWindowStencilTexture(this._id);e?this.updateStencilTexture(y(e.stencilMap)):(this._shaped=!1,this.visible=null!=this.colorMap)}async loadWindowImageAndShape(){if(this._shaped){const e=this.loadWindowImage(),t=this.loadWindowShape();await Promise.all([e,t])}else await this.loadWindowImage();this._loaded=!0}setRectangle(e,t,s,i,n){this._x=e,this._y=t,this._z=s,this._width=i,this._height=n,this.colorMap&&(this.colorMap.repeat.set(this._width/this.colorMap.image.width,this._height/this.colorMap.image.height),this.alphaMap&&this.alphaMap.repeat.set(this._width/this.alphaMap.image.width,this._height/this.alphaMap.image.height),this.colorMap.image.width===this._width&&this.colorMap.image.height===this._height||this.loadWindowImageAndShape()),this._updateScale(),this._updatePosition()}updateTexture(e,t,s,i){if(null==t)return;const n=null!=this.colorMap,a=null!=this.alphaMap;this._depth=e,t!=this.colorMap&&(this._disposeColorMap(),this.colorMap=t),this.colorMap.repeat.set(this._width/this.colorMap.image.width,this._height/this.colorMap.image.height),this.visible=!this._shaped||null!=this.stencilMap,s?(s!=this.alphaMap&&(this._disposeAlphaMap(),this.alphaMap=s),this.alphaMap.repeat.set(this._width/this.alphaMap.image.width,this._height/this.alphaMap.image.height)):24==e&&this._disposeAlphaMap(),this._material.transparent=null!=this.alphaMap||32===e;const r=null!=this.colorMap,o=null!=this.alphaMap;n==r&&a==o||(this._material.needsUpdate=!0),i||(this._windowRefreshTimeout&&(clearTimeout(this._windowRefreshTimeout),this._windowRefreshTimeout=null),this._windowRefreshTimeout=window.setTimeout(()=>{this._windowRefreshTimeout=null,this.loadWindowImage().then()},m.WINDOW_REFRESH_TIME_MS))}updateStencilTexture(t){const s=this._shaped;t!=this.stencilMap&&(this._disposeStencilMap(),this.stencilMap=t),t?(t.minFilter=e.LinearFilter,this.visible=null!=this.colorMap,this._shaped=!0):this._shaped=!1,s!==this._shaped&&(this._material.needsUpdate=!0)}_updateScale(){this._mesh.scale.set(this._width,this._height,1)}_updatePosition(){this._mesh.position.set(this._x+.5*this._width,this._y+.5*this._height,this._z)}dispose(){this._disposeColorMap(),this._disposeAlphaMap(),this._disposeStencilMap(),this._material.dispose(),this._windowRefreshTimeout&&(clearTimeout(this._windowRefreshTimeout),this._windowRefreshTimeout=null)}_disposeColorMap(){this.colorMap&&(this.colorMap.dispose(),this.colorMap=null)}_disposeAlphaMap(){this.alphaMap&&(this.alphaMap.dispose(),this.alphaMap=null)}_disposeStencilMap(){this.stencilMap&&(this.stencilMap.dispose(),this.stencilMap=null)}}m.WINDOW_REFRESH_TIME_MS=5e3,m._PLANE_GEOMETRY=new i.PlaneGeometry(1,1,2,2),m._COLOR_INDEX=0;class _{get canvas(){return this._canvas}get cursorId(){return this._cursorId}set x(e){this._x=e,this._updatePosition()}set y(e){this._y=e,this._updatePosition()}constructor(e){this._cursorFactory=e,this._x=-1,this._y=-1,this._xHot=0,this._yHot=0,this._width=1,this._height=1,this._canvas=document.createElement("canvas"),this._canvas.id="webx-cursor",this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._context=this._canvas.getContext("2d"),this.setPosition(-1,-1),this.setCursorId(0)}setPosition(e,t){this._x=e,this._y=t,this._updatePosition()}setCursorId(e){this._cursorId!==e&&(this._cursorId=e,this._cursorFactory.getCursor(e).then(e=>{const t=e.cursor;(this._x<0||this._y<0)&&this.setPosition(e.x,e.y),this._updateCursor(t.xHot,t.yHot,t.cursorId,t.texture)}))}_updateCursor(e,t,s,i){this._xHot=e,this._yHot=t,this._cursorId=s,null!=i&&null!=i.image&&(this._width=i.image.width,this._height=i.image.height,this._canvas.style.width=`${this._width}px`,this._canvas.style.height=`${this._height}px`,this._canvas.width=this._width,this._canvas.height=this._height,this._texture=i,this._context.clearRect(0,0,this._width,this._height),this._context.drawImage(this._texture.image,0,0,this._width,this._height))}_updatePosition(){this._canvas.style.left=this._x-this._xHot+"px",this._canvas.style.top=this._y-this._yHot+"px"}}class g{get id(){return this._mesh.id}get canvas(){return this._canvas}get x(){return this._x}get y(){return this._y}get zIndex(){return this._zIndex}get width(){return this._width}get height(){return this._height}constructor(e,t){this._mesh=e,this._imageBlender=t,this._x=0,this._y=0,this._zIndex=0,this._width=0,this._height=0,this._regionUpdates=[],this._canvas=this.createElementNS("canvas"),this._canvas.id=`webx-window-${this.id}`,this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.style.top="0",this._canvas.style.left="0",this._canvas.style.overflow="hidden",this._context=this._canvas.getContext("2d"),this.updateGeometry(),this.updateCanvas()}updateGeometry(){const e=this._mesh.scale.x,t=this._mesh.scale.y,s=this._mesh.position.x-.5*e,i=this._mesh.position.y-.5*t,n=this._mesh.position.z;s===this._x&&i===this._y||(this._canvas.style.top=`${i}px`,this._canvas.style.left=`${s}px`,this._x=s,this._y=i),e===this._width&&t===this._height||(this._width=e,this._height=t),n!==this._zIndex&&(this._canvas.style.zIndex=`${this._mesh.position.z}`,this._zIndex=n)}async updateCanvas(){if(this._mesh.material instanceof h||this._mesh.material instanceof e.MeshBasicMaterial){const t=this._mesh.material;if(this.updateStencilMap(t),t.map?.image){if(t.map!=this._colorMap||t.alphaMap!=this._alphaMap){this._colorMap=t.map,this._alphaMap=t.alphaMap;const s=t.map.image,i=s.width,n=s.height;if(this.isValidAlphaMap(t.alphaMap)||null!=this._stencilMap){const e=await this.blendAlphaAndStencil(t.map,t.alphaMap,0,0);this.resizeCanvas(i,n),this._context.putImageData(e,0,0)}else if(this.resizeCanvas(i,n),t.map instanceof e.DataTexture){const e=this.dataTextureToImageData(s);this._context.putImageData(e,0,0)}else this._context.clearRect(0,0,i,n),this._context.drawImage(s,0,0,i,n)}await this.handleRegionUpdates()}else this._colorMap&&(this._colorMap=null,this._alphaMap=null,this._regionUpdates=[],this._context.clearRect(0,0,this._canvas.width,this._canvas.height))}}addRegionUpdate(e,t,s,i,n,a,r){this._regionUpdates.push({srcColorMap:e,dstColorMap:t,srcAlphaMap:s,dstAlphaMap:i,width:n,height:a,dstPosition:r})}resizeCanvas(e,t){this._canvas.width===e&&this._canvas.height===t||(this._canvas.width=e,this._canvas.height=t,this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`)}async handleRegionUpdates(){for(const t of this._regionUpdates)if(t.dstColorMap===this._colorMap&&t.dstAlphaMap===this._alphaMap){const{srcColorMap:s,srcAlphaMap:i,width:n,height:a,dstPosition:r}=t,o=s.image;if(i||this._stencilData){const e=await this.blendAlphaAndStencil(s,i,r.x,r.y);e&&this._context.putImageData(e,r.x,r.y)}else if(s instanceof e.DataTexture){const e=this.dataTextureToImageData(o);this._context.putImageData(e,r.x,r.y)}else this._context.drawImage(o,0,0,n,a,r.x,r.y,n,a)}this._regionUpdates=[]}isValidAlphaMap(e){if(e){const t=e.image.width,s=e.image.height;return t===this._canvas.width&&s===this._canvas.height}return!1}updateStencilMap(t){if(t instanceof h&&t.stencilMap){if(t.stencilMap!=this._stencilMap){this._stencilMap=t.stencilMap;const s=this._stencilMap.image,{width:i,height:n}=s;if(this._stencilMap instanceof e.DataTexture)this._stencilData=this.dataTextureToImageData(s);else{const e=this.createElementNS("canvas");e.width=i,e.height=n;const t=e.getContext("2d",{willReadFrequently:!0});t.drawImage(s,0,0),this._stencilData=t.getImageData(0,0,i,n)}}}else this._stencilMap&&(this._stencilMap=null,this._stencilData=null)}async blendAlphaAndStencil(t,s,i,n){const a=t instanceof e.DataTexture?this.dataTextureToImageData(t.image):this.getImageData(t.image),r=null==s?null:s instanceof e.DataTexture?this.dataTextureToImageData(s.image):this.getImageData(s.image),o=null==this._stencilData?null:this.getStencilDataRegion(i,n,a.width,a.height);return r||o?await this._imageBlender.blendAlphaAndStencil(a,r,o):a}createElementNS(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}getImageData(e){const t=this.createElementNS("canvas");t.width=e.width,t.height=e.height;const s=t.getContext("2d");return s.drawImage(e,0,0),s.getImageData(0,0,e.width,e.height)}dataTextureToImageData(e){if(e.data.byteLength>0){const t=e.data instanceof Uint8ClampedArray?e.data:new Uint8ClampedArray(e.data.buffer);return new ImageData(t,e.width,e.height)}return new ImageData(new Uint8ClampedArray(4),1,1)}getStencilDataRegion(e,t,s,i){const n=this._stencilData.data,a=this._stencilData.width,r=new Uint8ClampedArray(s*i*4);for(let o=0;o<i;o++){const i=4*((t+o)*a+e),h=o*s*4;r.set(n.subarray(i,i+4*s),h)}return new ImageData(r,s,i)}}function b(e,t,s){var i=function(e){return atob(e)}(e),n=i.indexOf("\n",10)+1,a=i.substring(n)+"",r=new Blob([a],{type:"application/javascript"});return URL.createObjectURL(r)}function f(e,t,s){var i;return function(t){return i=i||b(e),new Worker(i,t)}}var M,Z=f("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7c2VsZi5vbm1lc3NhZ2U9ZT0+e2NvbnN0e2lkOmYsY29sb3JCdWZmZXI6bCxhbHBoYUJ1ZmZlcjp0LHN0ZW5jaWxCdWZmZXI6cix3aWR0aDpuLGhlaWdodDppfT1lLmRhdGEscz1uZXcgVWludDhDbGFtcGVkQXJyYXkobCk7KChlLGYsbCk9PntpZihmJiZsKWZvcihsZXQgdD0wO3Q8ZS5sZW5ndGg7dCs9NClsW3RdPDEyOD9lW3QrM109MDplW3QrM109Zlt0KzFdO2Vsc2UgaWYoZilmb3IobGV0IGw9MDtsPGUubGVuZ3RoO2wrPTQpZVtsKzNdPWZbbCsxXTtlbHNlIGlmKGwpZm9yKGxldCBmPTA7ZjxlLmxlbmd0aDtmKz00KWVbZiszXT1sW2ZdPDEyOD8wOmVbZiszXX0pKHMsdD9uZXcgVWludDhDbGFtcGVkQXJyYXkodCk6bnVsbCxyP25ldyBVaW50OENsYW1wZWRBcnJheShyKTpudWxsKSxzZWxmLnBvc3RNZXNzYWdlKHtpZDpmLGNvbG9yQnVmZmVyOnMuYnVmZmVyLHdpZHRoOm4saGVpZ2h0Oml9LFtzLmJ1ZmZlcl0pfX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9V2ViWEltYWdlQmxlbmRlcldvcmtlci5qcy5tYXAKCg==");class w{constructor(){this._pending=new Map,this._nextId=1,"undefined"!=typeof Worker&&(this._worker=new Z,this._worker.onmessage=e=>{const{id:t,colorBuffer:s,width:i,height:n}=e.data,a=this._pending.get(t);if(!a)return;this._pending.delete(t);const r=new Uint8ClampedArray(s);a(new ImageData(r,i,n))})}async blendAlphaAndStencil(e,t,s){return new Promise(i=>{if(this._worker){const n=this._nextId++;this._pending.set(n,i);const a=e.width,r=e.height,o=e.data.buffer;let h=null,l=null;const c=[o];t&&(h=t.data.buffer,c.push(h)),s&&(l=s.data.buffer,c.push(l)),this._worker.postMessage({id:n,colorBuffer:o,alphaBuffer:h,stencilBuffer:l,width:a,height:r},c)}else r(e.data,t?.data,s?.data),i(e)})}terminate(){this._worker.terminate(),this._pending.clear()}}class W{get domElement(){return this._desktopContainer}constructor(){this._clearColor=new e.Color(0,0,0),this._windowCanvases=new Map,this.createMainElement(),this._imageBlender=new w}setSize(e,t,s){this._width=e,this._height=t,this._desktop.style.width=`${e}px`,this._desktop.style.height=`${t}px`}setClearColor(e){this._clearColor.set(e),this._desktop.style.backgroundColor=`#${this._clearColor.getHexString()}`}render(t,s){if(t.children.length>0){const s=t.children[0],i=new Set;for(const t of s.children)if(t instanceof e.Mesh&&t.visible){this._windowCanvases.has(t.id)||this.createWindowCanvas(t);const e=this._windowCanvases.get(t.id);e.updateGeometry(),e.updateCanvas(),i.add(t.id)}for(const[e,t]of this._windowCanvases.entries())i.has(e)||this.removeWindowCanvas(t)}else if(this._windowCanvases.size>0)for(const[e,t]of this._windowCanvases.entries())this.removeWindowCanvas(t)}createScreenshot(e,t){return new Promise((s,i)=>{try{const i=this.createElementNS("canvas");i.width=this._width,i.height=this._height;const n=i.getContext("2d");n.fillStyle=`#${this._clearColor.getHexString()}`,n.fillRect(0,0,this._width,this._height),Array.from(this._windowCanvases.values()).sort((e,t)=>e.zIndex-t.zIndex).forEach(e=>{n.drawImage(e.canvas,e.x,e.y)}),i.toBlob(e=>{s(e)},e,t)}catch(e){i(e)}})}dispose(){for(const[e,t]of this._windowCanvases.entries())this.removeWindowCanvas(t);this._imageBlender.terminate()}updateWindowRegion(e,t,s,i,n,a,r,o){const h=this._windowCanvases.get(e);h&&h.addRegionUpdate(t,s,i,n,a,r,o)}createMainElement(){const e=this.createElementNS("div");e.id="webx-desktop-container",e.style.display="block",e.style.position="relative",e.style.overflow="hidden";const t=document.createElement("div");t.id="webx-desktop",e.style.position="absolute",e.style.transformOrigin="top left",e.appendChild(t),this._desktopContainer=e,this._desktop=t}createWindowCanvas(e){const t=new g(e,this._imageBlender);this._desktop.appendChild(t.canvas),this._windowCanvases.set(e.id,t)}removeWindowCanvas(e){this._desktop.removeChild(e.canvas),this._windowCanvases.delete(e.id)}createElementNS(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}}class I{get overlayElement(){return this._overlayElement}set visible(e){this._overlayElement.style.visibility=e?"visible":"hidden"}constructor(e){this._cursor=e,this._overlayElement=this._createDisplayOverlayElement(),this._overlayElement.appendChild(this._cursor.canvas)}update(){}_createDisplayOverlayElement(){const e=document.createElement("div");return e.id="webx-overlay",e.style.position="absolute",e.style.width="100%",e.style.height="100%",e.style.zIndex="999",e.style.visibility="hidden",e.style.overflow="clip",e}}class x{constructor(e,t=0){this.type=e,this.commandId=t}static get convertToImageDataInWorker(){return x._convertToImageDataInWorker}static set convertToImageDataInWorker(e){x._convertToImageDataInWorker=e}}x._convertToImageDataInWorker=!1,exports.WebXMessageType=void 0,(M=exports.WebXMessageType||(exports.WebXMessageType={}))[M.NOP=0]="NOP",M[M.CONNECTION=1]="CONNECTION",M[M.WINDOWS=2]="WINDOWS",M[M.IMAGE=3]="IMAGE",M[M.SCREEN=4]="SCREEN",M[M.SUBIMAGES=5]="SUBIMAGES",M[M.MOUSE=6]="MOUSE",M[M.CURSOR_IMAGE=7]="CURSOR_IMAGE",M[M.PING=8]="PING",M[M.DISCONNECT=9]="DISCONNECT",M[M.QUALITY=10]="QUALITY",M[M.CLIPBOARD=11]="CLIPBOARD",M[M.SHAPE=12]="SHAPE";class X extends x{constructor(e,t,s,i){super(exports.WebXMessageType.SCREEN,i),this.screenSize=e,this.maxQualityIndex=t,this.engineVersion=s}}class S extends x{constructor(e,t){super(exports.WebXMessageType.WINDOWS,t),this.windows=e}}class G extends x{constructor(e,t,s,i,n,a){super(exports.WebXMessageType.IMAGE,n),this.windowId=e,this.depth=t,this.colorMap=s,this.alphaMap=i,this.size=a}}class R extends x{constructor(e,t,s,i){super(exports.WebXMessageType.SUBIMAGES,s),this.windowId=e,this.subImages=t,this.size=i}}class v extends x{constructor(e,t,s,i){super(exports.WebXMessageType.MOUSE,i),this.x=e,this.y=t,this.cursorId=s}}class T extends x{constructor(e,t,s,i,n,a,r){super(exports.WebXMessageType.CURSOR_IMAGE,r),this.x=e,this.y=t,this.xHot=s,this.yHot=i,this.cursorId=n,this.texture=a}}class U extends x{constructor(){super(exports.WebXMessageType.PING)}}class C extends x{constructor(e,t,s,i,n){super(exports.WebXMessageType.QUALITY),this.index=e,this.imageFPS=t,this.rgbQuality=s,this.alphaQuality=i,this.maxMbps=n}}class V extends x{constructor(e){super(exports.WebXMessageType.CLIPBOARD),this.clipboardContent=e}}class E extends x{constructor(e){super(exports.WebXMessageType.CONNECTION),this.isStarting=e}}class L extends x{constructor(){super(exports.WebXMessageType.NOP)}}class k extends x{constructor(e,t,s,i){super(exports.WebXMessageType.SHAPE,s),this.windowId=e,this.stencilMap=t,this.size=i}}class N{get renderer(){return this._renderer}get screenWidth(){return this._screenWidth}get screenHeight(){return this._screenHeight}get containerElement(){return this._containerElement}get scale(){return this._scale}get scene(){return this._scene}get camera(){return this._camera}get sceneDirty(){return this._sceneDirty}set sceneDirty(e){this._sceneDirty=e}constructor(t,s,n,a,r){this._windows=[],this._scale=1,this._disposed=!1,this._sceneDirty=!1,this._disableStencil=!1,this._containerElement=t,this._screenWidth=s,this._screenHeight=n,this._windowImageFactory=a,this._cursor=new _(r),this._displayOverlay=new I(this._cursor),this._scene=new i.Scene,this._screen=new i.Object3D;const o=new i.Mesh(new i.PlaneGeometry(1,1,2,2),new i.MeshBasicMaterial({map:new i.DataTexture(new Uint8ClampedArray(4),1,1),side:i.BackSide,transparent:!0}));o.position.set(0,0,999),this._screen.add(o),this._camera=new i.OrthographicCamera(0,s,0,n,.1,1e4),this._camera.position.z=1e3,this._camera.lookAt(new e.Vector3(0,0,0));const h=this._detectWebGL2(),l=new URL(window.location.href).searchParams,c="true"===l.get("webx-canvas");this._disableStencil="false"===l.get("webx-stencil"),!h.available||h.isSoftware||c?(console.log(`WebGL2 Info: available = ${h.available}, isSoftware = ${h.isSoftware}, vendor = ${h.vendor}, renderer = ${h.renderer}`),c?console.log("Canvas Renderer enabled through request param"):console.log("Falling back to Canvas Renderer"),this._renderer=new W,x.convertToImageDataInWorker=!0):this._renderer=new i.WebGLRenderer,this._renderer.setSize(s,n,!1);const d=window.getComputedStyle(this._containerElement).backgroundColor;this._renderer.setClearColor(d),this._render(),this._bindListeners(),this.resize(),this._renderer.render(this._scene,this._camera)}showScreen(){this._scene.add(this._screen),this._displayOverlay.visible=!0,this._sceneDirty=!0}hideScreen(){this._scene.remove(this._screen),this._displayOverlay.visible=!1,this._sceneDirty=!0}dispose(){this.hideScreen();for(const e of this._windows)this._screen.remove(e.mesh),e.dispose();this._clearElements(),this._renderer.dispose(),this._disposed=!0}animate(){this._disposed||(requestAnimationFrame(()=>{this.animate()}),this._displayOverlay.update(),this._sceneDirty&&(this._sceneDirty=!1,this.render()))}render(){this._renderer.render(this._scene,this._camera)}async createScreenshot(e,t){if(this._renderer instanceof W)return this._renderer.createScreenshot(e,t);{const s=this._renderer;return new Promise((i,n)=>{try{this.render(),s.domElement.toBlob(e=>{i(e)},e,t)}catch(e){n(e)}})}}addWindow(e){null==this._windows.find(t=>t.id===e.id)&&(this._windows.push(e),this._screen.add(e.mesh),this._sceneDirty=!0)}removeWindow(e){null!=this._windows.find(t=>t.id===e.id)&&(this._windows=this._windows.filter(t=>t.id!==e.id),e.dispose(),this._screen.remove(e.mesh),this._sceneDirty=!0)}updateWindows(e){return new Promise(t=>{this._windows.filter(t=>null==e.find(e=>e.id===t.id)).forEach(e=>this.removeWindow(e));let s=!1;e.forEach((i,n)=>{let a=this.getWindow(i.id);null==a?(s=!0,a=new m({id:i.id,x:i.x,y:i.y,z:n,width:i.width,height:i.height,shaped:i.shaped&&!this._disableStencil},this._windowImageFactory),this.addWindow(a),a.loadWindowImageAndShape().then(()=>{this.checkAllLoaded(e.map(e=>e.id))&&t()})):(a.shaped=i.shaped&&!this._disableStencil,a.setRectangle(i.x,i.y,n,i.width,i.height))}),s||t()})}checkAllLoaded(e){return e.map(e=>this.getWindow(e)).filter(e=>null!=e).map(e=>e.loaded).reduce((e,t)=>e&&t,!0)}updateImage(e,t,s,i){const n=this.getWindow(e);null==n||null==s&&null==i||(n.updateTexture(t,y(s),y(i),!0),this._sceneDirty=!0)}updateSubImages(e,t){const s=this.getWindow(e);if(null!=s&&s.colorMapValid){const e=s.colorMap,n=s.alphaMap;for(let a=0;a<t.length;a++){const r=t[a];this._renderer instanceof W?this._renderer.updateWindowRegion(s.mesh.id,y(r.colorMap),e,y(r.alphaMap),n,r.width,r.height,new i.Vector2(r.x,r.y)):(e&&r.colorMap&&this._renderer.copyTextureToTexture(y(r.colorMap),e,null,new i.Vector2(r.x,r.y)),n&&r.alphaMap&&this._renderer.copyTextureToTexture(y(r.alphaMap),n,null,new i.Vector2(r.x,r.y)))}s.updateTexture(s.depth,e,n,!1),this._sceneDirty=!0}}updateShape(e,t){if(this._disableStencil)return;const s=this.getWindow(e);null!=s&&null!=t&&(s.updateStencilTexture(y(t)),this._sceneDirty=!0)}setMouseCursor(e){this._cursor.setCursorId(e)}setMousePosition(e,t){this._cursor.setPosition(e,t)}getWindow(e){return this._windows.find(t=>t.id===e)}setScale(e){this._scale=e,this._sceneDirty=!0}autoScale(){const e=this._containerElement,{clientWidth:t,clientHeight:s}=e,{screenWidth:i,screenHeight:n}=this;this._scale=Math.min(t/i,s/n),this._sceneDirty=!0}resize(e){const t=this._boundsElement;e?this.setScale(e):this.autoScale(),t.style.transform=`scale(${this._scale},${this._scale})`}_clearElements(){for(;this._containerElement.firstChild;)this._containerElement.removeChild(this._containerElement.firstChild)}_createDisplayElement(){const e=document.createElement("div");return e.style.width=`${this._screenWidth}px`,e.style.height=`${this._screenHeight}px`,e.appendChild(this._displayOverlay.overlayElement),e.appendChild(this._renderer.domElement),e}_createDisplayBoundingElement(){const e=document.createElement("div");return e.appendChild(this._displayElement),e}_render(){this._clearElements(),this._displayElement=this._createDisplayElement(),this._boundsElement=this._createDisplayBoundingElement(),this._containerElement.appendChild(this._boundsElement)}_bindListeners(){this.resize=this.resize.bind(this)}_detectWebGL2(){const e=document.createElement("canvas").getContext("webgl2");if(!e)return{available:!1};const t=e.getParameter(e.RENDERER),s=e.getParameter(e.VENDOR);let i=null,n=null;const a=e.getExtension("WEBGL_debug_renderer_info");a&&(i=e.getParameter(a.UNMASKED_RENDERER_WEBGL),n=e.getParameter(a.UNMASKED_VENDOR_WEBGL));const r=(i||t||"").toLowerCase();return{available:!0,vendor:n||s,renderer:i||t,isSoftware:/swiftshader|llvmpipe|basic render|software/i.test(r)}}}var Y,F=F||{};F.Keyboard=function(e){var t=this,s="_GUAC_KEYBOARD_HANDLED_BY_"+F.Keyboard._nextID++;this.onkeydown=null,this.onkeyup=null;var i={keyupUnreliable:!1,altIsTypableOnly:!1,capsLockKeyupUnreliable:!1};navigator&&navigator.platform&&(navigator.platform.match(/ipad|iphone|ipod/i)?i.keyupUnreliable=!0:navigator.platform.match(/^mac/i)&&(i.altIsTypableOnly=!0,i.capsLockKeyupUnreliable=!0));var n=function(e){var t=this;this.keyCode=e?e.which||e.keyCode:0,this.keyIdentifier=e&&e.keyIdentifier,this.key=e&&e.key,this.location=e?S(e):0,this.modifiers=e?F.Keyboard.ModifierState.fromKeyboardEvent(e):new F.Keyboard.ModifierState,this.timestamp=(new Date).getTime(),this.defaultPrevented=!1,this.keysym=null,this.reliable=!1,this.getAge=function(){return(new Date).getTime()-t.timestamp}},a=function(e){n.call(this,e),this.keysym=f(this.key,this.location)||Z(this.keyCode,this.location),this.keyupReliable=!i.keyupUnreliable,this.keysym&&!b(this.keysym)&&(this.reliable=!0),!this.keysym&&w(this.keyCode,this.keyIdentifier)&&(this.keysym=f(this.keyIdentifier,this.location,this.modifiers.shift)),(this.modifiers.meta&&65511!==this.keysym&&65512!==this.keysym||65509===this.keysym&&i.capsLockKeyupUnreliable)&&(this.keyupReliable=!1);var t=!this.modifiers.ctrl&&!i.altIsTypableOnly;!i.altIsTypableOnly||65513!==this.keysym&&65514!==this.keysym||(this.keysym=65027),(!this.modifiers.alt&&this.modifiers.ctrl||t&&this.modifiers.alt||this.modifiers.meta||this.modifiers.hyper)&&(this.reliable=!0),y[this.keyCode]=this.keysym};a.prototype=new n;var r=function(e){n.call(this,e),this.keysym=M(this.keyCode),this.reliable=!0};r.prototype=new n;var o=function(e){n.call(this,e),this.keysym=Z(this.keyCode,this.location)||f(this.key,this.location),t.pressed[this.keysym]||(this.keysym=y[this.keyCode]||this.keysym),this.reliable=!0};o.prototype=new n;var h=[],l={8:[65288],9:[65289],12:[65291,65291,65291,65461],13:[65293],16:[65505,65505,65506],17:[65507,65507,65508],18:[65513,65513,65514],19:[65299],20:[65509],27:[65307],32:[32],33:[65365,65365,65365,65465],34:[65366,65366,65366,65459],35:[65367,65367,65367,65457],36:[65360,65360,65360,65463],37:[65361,65361,65361,65460],38:[65362,65362,65362,65464],39:[65363,65363,65363,65462],40:[65364,65364,65364,65458],45:[65379,65379,65379,65456],46:[65535,65535,65535,65454],91:[65511],92:[65512],93:[65383],96:[65456],97:[65457],98:[65458],99:[65459],100:[65460],101:[65461],102:[65462],103:[65463],104:[65464],105:[65465],106:[65450],107:[65451],109:[65453],110:[65454],111:[65455],112:[65470],113:[65471],114:[65472],115:[65473],116:[65474],117:[65475],118:[65476],119:[65477],120:[65478],121:[65479],122:[65480],123:[65481],144:[65407],145:[65300],225:[65027]},c={Again:[65382],AllCandidates:[65341],Alphanumeric:[65328],Alt:[65513,65513,65514],Attn:[64782],AltGraph:[65027],ArrowDown:[65364],ArrowLeft:[65361],ArrowRight:[65363],ArrowUp:[65362],Backspace:[65288],CapsLock:[65509],Cancel:[65385],Clear:[65291],Convert:[65315],Copy:[64789],Crsel:[64796],CrSel:[64796],CodeInput:[65335],Compose:[65312],Control:[65507,65507,65508],ContextMenu:[65383],Delete:[65535],Down:[65364],End:[65367],Enter:[65293],EraseEof:[64774],Escape:[65307],Execute:[65378],Exsel:[64797],ExSel:[64797],F1:[65470],F2:[65471],F3:[65472],F4:[65473],F5:[65474],F6:[65475],F7:[65476],F8:[65477],F9:[65478],F10:[65479],F11:[65480],F12:[65481],F13:[65482],F14:[65483],F15:[65484],F16:[65485],F17:[65486],F18:[65487],F19:[65488],F20:[65489],F21:[65490],F22:[65491],F23:[65492],F24:[65493],Find:[65384],GroupFirst:[65036],GroupLast:[65038],GroupNext:[65032],GroupPrevious:[65034],FullWidth:null,HalfWidth:null,HangulMode:[65329],Hankaku:[65321],HanjaMode:[65332],Help:[65386],Hiragana:[65317],HiraganaKatakana:[65319],Home:[65360],Hyper:[65517,65517,65518],Insert:[65379],JapaneseHiragana:[65317],JapaneseKatakana:[65318],JapaneseRomaji:[65316],JunjaMode:[65336],KanaMode:[65325],KanjiMode:[65313],Katakana:[65318],Left:[65361],Meta:[65511,65511,65512],ModeChange:[65406],NonConvert:[65314],NumLock:[65407],PageDown:[65366],PageUp:[65365],Pause:[65299],Play:[64790],PreviousCandidate:[65342],PrintScreen:[65377],Redo:[65382],Right:[65363],Romaji:[65316],RomanCharacters:null,Scroll:[65300],Select:[65376],Separator:[65452],Shift:[65505,65505,65506],SingleCandidate:[65340],Super:[65515,65515,65516],Tab:[65289],UIKeyInputDownArrow:[65364],UIKeyInputEscape:[65307],UIKeyInputLeftArrow:[65361],UIKeyInputRightArrow:[65363],UIKeyInputUpArrow:[65362],Up:[65362],Undo:[65381],Win:[65511,65511,65512],Zenkaku:[65320],ZenkakuHankaku:[65322]},d={65027:!0,65505:!0,65506:!0,65507:!0,65508:!0,65509:!0,65511:!0,65512:!0,65513:!0,65514:!0,65515:!0,65516:!0};this.modifiers=new F.Keyboard.ModifierState,this.pressed={};var u={},p={},y={},m=null,_=null,g=function(e,t){return e?e[t]||e[0]:null},b=function(e){return e>=0&&e<=255||16777216==(4294901760&e)};function f(e,t,s){if(!e)return null;var i,n=e.indexOf("U+");if(n>=0){var a=e.substring(n+2);i=String.fromCharCode(parseInt(a,16))}else{if(1!==e.length||3===t)return g(c[e],t);i=e}return!0===s?i=i.toUpperCase():!1===s&&(i=i.toLowerCase()),M(i.charCodeAt(0))}function M(e){return function(e){return e<=31||e>=127&&e<=159}(e)?65280|e:e>=0&&e<=255?e:e>=256&&e<=1114111?16777216|e:null}function Z(e,t){return g(l[e],t)}var w=function(e,t){if(!t)return!1;var s=t.indexOf("U+");return-1===s||(e!==parseInt(t.substring(s+2),16)||(e>=65&&e<=90||e>=48&&e<=57))};this.press=function(e){if(null!==e){if(!t.pressed[e]&&(t.pressed[e]=!0,t.onkeydown)){var s=t.onkeydown(e);return p[e]=s,window.clearTimeout(m),window.clearInterval(_),d[e]||(m=window.setTimeout(function(){_=window.setInterval(function(){t.onkeyup(e),t.onkeydown(e)},50)},500)),s}return p[e]||!1}},this.release=function(e){t.pressed[e]&&(delete t.pressed[e],delete u[e],window.clearTimeout(m),window.clearInterval(_),null!==e&&t.onkeyup&&t.onkeyup(e))},this.type=function(e){for(var s=0;s<e.length;s++){var i=M(e.codePointAt?e.codePointAt(s):e.charCodeAt(s));t.press(i),t.release(i)}},this.reset=function(){for(var e in t.pressed)t.release(parseInt(e));h=[]};var W=function(e,s,i){var n,a=i.modifiers[e],r=t.modifiers[e];if(-1===s.indexOf(i.keysym))if(r&&!1===a)for(n=0;n<s.length;n++)t.release(s[n]);else if(!r&&a){for(n=0;n<s.length;n++)if(t.pressed[s[n]])return;var o=s[0];i.keysym&&(u[o]=!0),t.press(o)}},I=function(e){W("alt",[65513,65514,65027],e),W("shift",[65505,65506],e),W("ctrl",[65507,65508],e),W("meta",[65511,65512],e),W("hyper",[65515,65516],e),t.modifiers=e.modifiers};function x(){var e,s=X();if(!s)return!1;do{e=s,s=X()}while(null!==s);return function(){for(var e in t.pressed)if(!u[e])return!1;return!0}()&&t.reset(),e.defaultPrevented}var X=function(){var e=h[0];if(!e)return null;if(!(e instanceof a))return e instanceof o&&!i.keyupUnreliable?(s=e.keysym)?(t.release(s),delete y[e.keyCode],e.defaultPrevented=!0,I(e),h.shift()):(t.reset(),e):h.shift();var s=null,n=[];if(65511===e.keysym||65512===e.keysym){if(1===h.length)return null;if(h[1].keysym!==e.keysym){if(!h[1].modifiers.meta)return h.shift()}else if(h[1]instanceof a)return h.shift()}if(e.reliable?(s=e.keysym,n=h.splice(0,1)):h[1]instanceof r?(s=h[1].keysym,n=h.splice(0,2)):h[1]&&(s=e.keysym,n=h.splice(0,1)),n.length>0){if(I(e),s){!function(e){t.modifiers.ctrl&&t.modifiers.alt&&(e>=65&&e<=90||e>=97&&e<=122||(e<=255||16777216==(4278190080&e))&&(t.release(65507),t.release(65508),t.release(65513),t.release(65514)))}(s);var l=!t.press(s);y[e.keyCode]=s,e.keyupReliable||t.release(s);for(var c=0;c<n.length;c++)n[c].defaultPrevented=l}return e}return null},S=function(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0},G=function(e){return!e[s]&&(e[s]=!0,!0)},R=function(e){if(t.onkeydown&&G(e)){var s=new a(e);e.isComposing||229===s.keyCode||(h.push(s),x()&&e.preventDefault())}},v=function(e){(t.onkeydown||t.onkeyup)&&G(e)&&(h.push(new r(e)),x()&&e.preventDefault())},T=function(e){t.onkeyup&&G(e)&&(e.preventDefault(),h.push(new o(e)),x())},U=function(e){(t.onkeydown||t.onkeyup)&&G(e)&&e.data&&!e.isComposing&&t.type(e.data)},C=function(t){e.removeEventListener("input",U,!1)},V=function(e){(t.onkeydown||t.onkeyup)&&G(e)&&e.data&&t.type(e.data)};this.listenTo=function(e){e.addEventListener("keydown",R,{passive:!1}),e.addEventListener("keypress",v,{passive:!1}),e.addEventListener("keyup",T,{passive:!1}),e.addEventListener("input",U,!1),e.addEventListener("compositionend",V,!1),e.addEventListener("compositionstart",C,!1)},e&&t.listenTo(e),this.dispose=function(){e&&(e.removeEventListener("keydown",R,!0),e.removeEventListener("keypress",v,!0),e.removeEventListener("keyup",T,!0),e.removeEventListener("input",U,!1),e.removeEventListener("compositionend",V,!1),e.removeEventListener("compositionstart",C,!1))}},F.Keyboard._nextID=0,F.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},F.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new F.Keyboard.ModifierState;return t.shift=e.shiftKey,t.ctrl=e.ctrlKey,t.alt=e.altKey,t.meta=e.metaKey,e.getModifierState&&(t.hyper=e.getModifierState("OS")||e.getModifierState("Super")||e.getModifierState("Hyper")||e.getModifierState("Win")),t};class H{set onKeyDown(e){this._keyboard.onkeydown=e}set onKeyUp(e){this._keyboard.onkeyup=e}constructor(e){this._keyboard=new F.Keyboard(e)}dispose(){this._keyboard.onkeydown=null,this._keyboard.onkeyup=null,this._keyboard.dispose()}reset(){this._keyboard.reset()}}class z{get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}get left(){return this._left}set left(e){this._left=e}get middle(){return this._middle}set middle(e){this._middle=e}get right(){return this._right}set right(e){this._right=e}get up(){return this._up}set up(e){this._up=e}get down(){return this._down}set down(e){this._down=e}get shift(){return this._shift}set shift(e){this._shift=e}get ctrl(){return this._ctrl}set ctrl(e){this._ctrl=e}get alt(){return this._alt}set alt(e){this._alt=e}constructor(e){const{x:t,y:s,left:i,middle:n,right:a,up:r,down:o}=e;this._x=t,this._y=s,this._left=i,this._middle=n,this._right=a,this._up=r,this._down=o}releaseButtons(){this._left=!1,this._middle=!1,this._right=!1}getButtonMask(){let e=0;return e|=this._left?256:0,e|=this._middle?512:0,e|=this._right?1024:0,e|=this._up?2048:0,e|=this._down?4096:0,e|=this._shift?1:0,e|=this._ctrl?4:0,e|=this._alt?8:0,e}clone(){return new z({x:this._x,y:this._y,left:this._left,middle:this._middle,right:this._right,up:this._up,down:this._down})}}class D{constructor(e){this._element=e,this._contextMenuHandler=this._handleContextMenu.bind(this),this._mouseMoveHandler=this._handleMouseMove.bind(this),this._mouseDownHandler=this._handleMouseDown.bind(this),this._mouseUpHandler=this._handleMouseUp.bind(this),this._mouseOutHandler=this._handleMouseOut.bind(this),this._mouseWheelHandler=this._handleMouseWheel.bind(this),this._bindListeners(),this._createDefaultState()}dispose(){this._unbindListeners()}_cancelEvent(e){e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.returnValue=!1}_bindListeners(){const e=this._element;e.addEventListener("contextmenu",this._contextMenuHandler,!1),e.addEventListener("mousemove",this._mouseMoveHandler),e.addEventListener("mousedown",this._mouseDownHandler),e.addEventListener("mouseup",this._mouseUpHandler),e.addEventListener("mouseout",this._mouseOutHandler),["DOMMouseScroll","mousewheel","wheel"].forEach(t=>{e.addEventListener(t,this._mouseWheelHandler,{passive:!1})}),this.reset=this.reset.bind(this)}_unbindListeners(){const e=this._element;e.removeEventListener("contextmenu",this._contextMenuHandler,!1),e.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseout",this._mouseOutHandler),["DOMMouseScroll","mousewheel","wheel"].forEach(t=>{e.removeEventListener(t,this._mouseWheelHandler)}),this.reset=this.reset.bind(this)}_createDefaultState(){this._currentState=new z({x:0,y:0,left:!1,middle:!1,right:!1,up:!1,down:!1})}_handleMouseUp(e){switch(e.button){case 0:this._currentState.left=!1;break;case 1:this._currentState.middle=!1;break;case 2:this._currentState.right=!1}this._notifyMouseUp()}_handleMouseDown(e){switch(this._cancelEvent(e),e.button){case 0:this._currentState.left=!0;break;case 1:this._currentState.middle=!0;break;case 2:this._currentState.right=!0}this._notifyMouseDown()}_handleMouseWheel(e){e.deltaY<0&&(this._currentState.up=!0,this._notifyMouseDown(),this._currentState.up=!1,this._notifyMouseUp()),e.deltaY>0&&(this._currentState.down=!0,this._notifyMouseDown(),this._currentState.down=!1,this._notifyMouseUp()),this._cancelEvent(e)}_handleMouseOut(){this._currentState.releaseButtons(),this._notifyMouseOut()}_handleMouseMove(e){this._cancelEvent(e);const t=this._element.firstElementChild.getBoundingClientRect();this._currentState.x=e.clientX-t.left,this._currentState.y=e.clientY-t.top,this._notifyMouseMove()}reset(){this._currentState.releaseButtons()}_handleContextMenu(e){this._cancelEvent(e)}_notifyMouseMove(){this.onMouseMove(this._currentState.clone())}_notifyMouseUp(){this.onMouseUp(this._currentState.clone())}_notifyMouseDown(){this.onMouseDown(this._currentState.clone())}_notifyMouseOut(){this.onMouseOut(this._currentState.clone())}onMouseMove(e){}onMouseDown(e){}onMouseUp(e){}onMouseOut(e){}}class P{constructor(e){this.synchronous=!1,this.id=P._INSTRUCTION_COUNTER++,this.type=e}}P._INSTRUCTION_COUNTER=1;class K{constructor(e,t){this._timeoutId=0,this.instructionId=e.id,this.data=null,t&&(this._timeoutMs=t,this._timeoutId=setTimeout(()=>{this.reject("Request failed due to timeout")},this._timeoutMs))}then(e){return this._onResponseReceived=e,this}catch(e){return this._onError=e,this}resolve(e){this._timeoutId>0&&clearTimeout(this._timeoutId),null!=this._onResponseReceived&&this._onResponseReceived(e)}reject(e){this._onError&&this._onError(new Error(e))}}exports.WebXInstructionType=void 0,(Y=exports.WebXInstructionType||(exports.WebXInstructionType={}))[Y.CONNECT=1]="CONNECT",Y[Y.WINDOWS=2]="WINDOWS",Y[Y.IMAGE=3]="IMAGE",Y[Y.SCREEN=4]="SCREEN",Y[Y.MOUSE=5]="MOUSE",Y[Y.KEYBOARD=6]="KEYBOARD",Y[Y.CURSOR_IMAGE=7]="CURSOR_IMAGE",Y[Y.QUALITY=8]="QUALITY",Y[Y.PONG=9]="PONG",Y[Y.DATA_ACK=10]="DATA_ACK",Y[Y.CLIPBOARD=11]="CLIPBOARD",Y[Y.SHAPE=12]="SHAPE",function(e){e.fromString=function(t){switch(t){case"CONNECT":return e.CONNECT;case"WINDOWS":return e.WINDOWS;case"IMAGE":return e.IMAGE;case"SCREEN":return e.SCREEN;case"MOUSE":return e.MOUSE;case"KEYBOARD":return e.KEYBOARD;case"CURSOR_IMAGE":return e.CURSOR_IMAGE;case"QUALITY":return e.QUALITY;case"PONG":return e.PONG;case"DATA_ACK":return e.DATA_ACK;case"CLIPBOARD":return e.CLIPBOARD;case"SHAPE":return e.SHAPE}}}(exports.WebXInstructionType||(exports.WebXInstructionType={}));class O extends P{constructor(){super(exports.WebXInstructionType.SCREEN)}}class A extends P{constructor(){super(exports.WebXInstructionType.WINDOWS)}}class J extends P{constructor(e){super(exports.WebXInstructionType.IMAGE),this.windowId=e}}class B extends P{constructor(e,t,s){super(exports.WebXInstructionType.MOUSE),this.x=e,this.y=t,this.buttonMask=s}}class Q extends P{constructor(e,t){super(exports.WebXInstructionType.KEYBOARD),this.key=e,this.pressed=t}}class j extends P{constructor(e){super(exports.WebXInstructionType.CURSOR_IMAGE),this.cursorId=e}}class $ extends P{constructor(e){super(exports.WebXInstructionType.QUALITY),this.qualityIndex=e}}class q extends P{constructor(e){super(exports.WebXInstructionType.PONG),this.timestampMs=e}}class ee extends P{constructor(e,t){super(exports.WebXInstructionType.DATA_ACK),this.timestampMs=e,this.dataLength=t}}class te extends P{constructor(e){super(exports.WebXInstructionType.CLIPBOARD),this.clipboardContent=e}}class se extends P{constructor(e){super(exports.WebXInstructionType.SHAPE),this.windowId=e}}class ie{}class ne{}class ae{}class re{static randomColour(){const e=Math.floor(Math.random()*re._COLOURS.length);return re._COLOURS[e]}static indexedColour(e){return e%=re._COLOURS.length,re._COLOURS[e]}}re._COLOURS=["#FF6633","#FFB399","#FF33FF","#FFFF99","#00B3E6","#E6B333","#3366E6","#999966","#99FF99","#B34D4D","#80B300","#809900","#E6B3B3","#6680B3","#66991A","#FF99E6","#CCFF1A","#FF1A66","#E6331A","#33FFCC","#66994D","#B366CC","#4D8000","#B33300","#CC80CC","#66664D","#991AFF","#E666FF","#4DB3FF","#1AB399","#E666B3","#33991A","#CC9999","#B3B31A","#00E680","#4D8066","#809980","#E6FF80","#1AFF33","#999933","#FF3380","#CCCC00","#66E64D","#4D80CC","#9900B3","#E64D66","#4DB380","#FF4D4D","#99E6E6","#6666FF"];class oe{constructor(e=0,t=0,s=0){this.major=e,this.minor=t,this.patch=s,this.version=`${e}.${t}.${s}`,this.versionNumber=parseFloat(`${e}.${t}`)}}class he extends ne{constructor(s){super(),this._display=s,this._debugLayer=new e.Object3D,this._currentZ=0,this._disposed=!1,this._tweenGroup=new t.Group,this._debugLayer.position.set(0,0,999),this._scene=this._display.scene,this._scene.add(this._debugLayer),this._animate()}_createMesh(s,i,n,a,r){const o=new e.MeshBasicMaterial({color:r,opacity:.8,transparent:!0});o.side=e.BackSide;const h=new e.Mesh(he._PLANE_GEOMETRY,o);h.position.set(s+n/2,i+a/2,this._currentZ),h.scale.set(n,a,1),this._currentZ+=1e-4,this._debugLayer.add(h),new t.Tween(o,this._tweenGroup).to({opacity:0},500).easing(t.Easing.Quadratic.Out).onComplete(()=>this._debugLayer.remove(h)).onUpdate(()=>this._display.sceneDirty=!0).start()}handle(e){if(e.type===exports.WebXMessageType.IMAGE){const t=e,s=this._display.getWindow(t.windowId),{width:i,height:n}=t.colorMap.image;this._createMesh(s.x,s.y,i,n,re.indexedColour(s.colorIndex))}else if(e.type===exports.WebXMessageType.SUBIMAGES){const t=e,s=this._display.getWindow(t.windowId);t.subImages.forEach(e=>{this._createMesh(s.x+e.x,s.y+e.y,e.width,e.height,re.indexedColour(s.colorIndex))})}}destroy(){this._disposed=!0,this._debugLayer.children.forEach(e=>{e.material.dispose()}),this._debugLayer.clear(),this._debugLayer.removeFromParent()}_animate(){this._disposed||requestAnimationFrame(e=>{this._tweenGroup.update(e),this._animate()})}}he._PLANE_GEOMETRY=new e.PlaneGeometry(1,1,2,2);class le{constructor(e,t){this._buffer=new ArrayBuffer(t+32),this._offset=20,e.synchronous?this.putUInt32(2147483648|e.type):this.putUInt32(e.type),this.putUInt32(e.id),this.putUInt32(0)}_getNextOffset(e){const t=this._offset%e>0?e-this._offset%e:0,s=this._offset+t;return this._offset+=e+t,s}putInt32(e){const t=this._getNextOffset(4);return new Int32Array(this._buffer,t,1)[0]=e,this}putUInt8(e){const t=this._getNextOffset(1);return new Uint8Array(this._buffer,t,1)[0]=e,this}putUInt32(e){const t=this._getNextOffset(4);return new Uint32Array(this._buffer,t,1)[0]=e,this}putUInt8Array(e,t){const s=this._getNextOffset(8);return new Uint8Array(this._buffer,s,t).set(e),this}putString(e){for(let t=0;t<e.length;t++)this.putUInt8(e.charCodeAt(t));return this}putBoolean(e){return this.putUInt32(!0===e?255:0),this}buffer(){return this._buffer}}class ce{get readOffset(){return this._readOffset}get buffer(){return this._buffer}constructor(e){this._buffer=e,this._readOffset=24,this._encoder=new TextDecoder("utf-8"),this._readOffset=24,this.timestampMs=this.getUint8Array(8),this.messageTypeId=this.getUint32(),this.messageId=this.getUint32(),this.bufferLength=this.getUint32(),this._readOffset=ce.MESSAGE_HEADER_LENGTH}getInt32(){const e=this._getNextReadOffset(4);return new Int32Array(this._buffer,e,1)[0]}getUint32(){const e=this._getNextReadOffset(4);return new Uint32Array(this._buffer,e,1)[0]}getFloat(){const e=this._getNextReadOffset(4);return new Float32Array(this._buffer,e,1)[0]}getUint8Array(e){const t=new Uint8Array(this._buffer,this._readOffset,e);return this._readOffset+=e,t}getString(e){const t=new Uint8Array(this._buffer,this._readOffset,e);return this._readOffset+=e,this._encoder.decode(t)}_getNextReadOffset(e){const t=this._readOffset%e>0?e-this._readOffset%e:0,s=this._readOffset+t;return this._readOffset+=e+t,s}}ce.MESSAGE_HEADER_LENGTH=48;class de{encode(e){return e.type===exports.WebXInstructionType.MOUSE?this._createMouseInstruction(e):e.type===exports.WebXInstructionType.KEYBOARD?this._createKeyboardInstruction(e):e.type===exports.WebXInstructionType.CURSOR_IMAGE?this._createCursorImageInstruction(e):e.type===exports.WebXInstructionType.IMAGE?this._createImageInstruction(e):e.type===exports.WebXInstructionType.CONNECT?this._createConnectInstruction(e):e.type===exports.WebXInstructionType.SCREEN?this._createScreenInstruction(e):e.type===exports.WebXInstructionType.WINDOWS?this._createWindowsInstruction(e):e.type===exports.WebXInstructionType.QUALITY?this._createQualityInstruction(e):e.type===exports.WebXInstructionType.PONG?this._createPongInstruction(e):e.type===exports.WebXInstructionType.DATA_ACK?this._createDataAckInstruction(e):e.type===exports.WebXInstructionType.CLIPBOARD?this._createClipboardInstruction(e):e.type===exports.WebXInstructionType.SHAPE?this._createShapeInstruction(e):null}_createMouseInstruction(e){return new le(e,12).putInt32(e.x).putInt32(e.y).putUInt32(e.buttonMask).buffer()}_createCursorImageInstruction(e){return new le(e,4).putInt32(e.cursorId).buffer()}_createImageInstruction(e){return new le(e,4).putUInt32(e.windowId).buffer()}_createKeyboardInstruction(e){return new le(e,8).putUInt32(e.key).putBoolean(e.pressed).buffer()}_createScreenInstruction(e){return new le(e,0).buffer()}_createWindowsInstruction(e){return new le(e,0).buffer()}_createConnectInstruction(e){return new le(e,0).buffer()}_createQualityInstruction(e){return new le(e,4).putUInt32(e.qualityIndex).buffer()}_createPongInstruction(e){return new le(e,8).putUInt8Array(e.timestampMs,8).buffer()}_createDataAckInstruction(e){return new le(e,12).putUInt8Array(e.timestampMs,8).putUInt32(e.dataLength).buffer()}_createClipboardInstruction(e){const t=4+e.clipboardContent.length;return new le(e,t).putUInt32(e.clipboardContent.length).putString(e.clipboardContent).buffer()}_createShapeInstruction(e){return new le(e,4).putUInt32(e.windowId).buffer()}}class ue{constructor(){this._textureFactory=new p}decode(e){const{messageTypeId:t}=e;return t===exports.WebXMessageType.NOP?this._createNopMessage():t===exports.WebXMessageType.CONNECTION?this._createConnectionMessage(e):t===exports.WebXMessageType.SCREEN?this._createScreenMessage(e):t===exports.WebXMessageType.WINDOWS?this._createWindowsMessage(e):t===exports.WebXMessageType.IMAGE?this._createImageMessage(e):t===exports.WebXMessageType.SUBIMAGES?this._createSubImagesMessage(e):t===exports.WebXMessageType.MOUSE?this._createMouseMessage(e):t===exports.WebXMessageType.CURSOR_IMAGE?this._createCursorImageMessage(e):t===exports.WebXMessageType.PING?this._createPingMessage():t===exports.WebXMessageType.QUALITY?this._createQualityMessage(e):t===exports.WebXMessageType.CLIPBOARD?this._createClipboardMessage(e):t===exports.WebXMessageType.SHAPE?this._createShapeMessage(e):void console.error(`Failed to decode message with typeId ${t}`)}_determineMimeType(e){return"jpg"===e.substr(0,3)?"image/jpeg":"png"===e.substr(0,3)?"image/png":"image/bmp"}async _createNopMessage(){return new L}async _createConnectionMessage(e){const t=e.getUint32();return new E(t>0)}_createImageMessage(e){return new Promise(t=>{const s=e.getUint32(),i=e.getUint32(),n=e.getUint32(),a=e.getString(4),r=this._determineMimeType(a),o=e.getUint32(),h=e.getUint32(),l=e.getUint8Array(o),u=e.getUint8Array(h),p=this._textureFactory.createTextureFromArray(l,r,c),y=this._textureFactory.createTextureFromArray(u,r,d);Promise.all([p,y]).then(([a,r])=>{t(new G(i,n,a,r,s,e.bufferLength))})})}_createSubImagesMessage(e){return new Promise(t=>{const s=e.getUint32(),i=e.getUint32(),n=new Array,r=e.getUint32();for(let t=0;t<r;t++){const t=e.getInt32(),s=e.getInt32(),i=e.getInt32(),r=e.getInt32(),o=e.getUint32(),h=e.getString(4),l=this._determineMimeType(h),u=e.getUint32(),p=e.getUint32(),y=e.getUint8Array(u),m=e.getUint8Array(p),_=new Promise((e,n)=>{const h=this._textureFactory.createTextureFromArray(y,l,c),u=this._textureFactory.createTextureFromArray(m,l,d);Promise.all([h,u]).then(([n,h])=>{e(new a({x:t,y:s,width:i,height:r,depth:o,colorMap:n,alphaMap:h}))}).catch(n)});n.push(_)}Promise.all(n).then(n=>{t(new R(i,n,s,e.bufferLength))})})}async _createMouseMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32(),n=e.getUint32();return new v(s,i,n,t)}async _createWindowsMessage(e){const t=e.getUint32(),s=e.getUint32(),i=new Array;for(let t=0;t<s;t++){const t=e.getUint32(),s=e.getInt32(),n=e.getInt32(),a=e.getInt32(),r=e.getInt32();i.push({id:t,x:s,y:n,width:a,height:r,shaped:!1})}if(l.version.versionNumber>=1.4&&e.bufferLength-e.readOffset>=4){const t=e.getUint32();for(let s=0;s<t;s++){const t=e.getUint32();i.find(e=>e.id===t).shaped=!0}}return new S(i.map(e=>new n(e)),t)}async _createCursorImageMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32(),n=e.getInt32(),a=e.getInt32(),r=e.getUint32(),o=e.getUint32(),h=e.getUint8Array(o);try{const e=await this._textureFactory.createTextureFromArray(h,"image/png",c);return new T(s,i,n,a,r,e,t)}catch(e){console.error(`Failed to get texture for cursor image: ${e}`)}}async _createScreenMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32();let n=10;e.bufferLength-e.readOffset>=4&&(n=e.getInt32());let a=0,r=0,o=0;return e.bufferLength-e.readOffset>=12&&(a=e.getUint32(),r=e.getUint32(),o=e.getUint32()),l.version=new oe(a,r,o),new X({width:s,height:i},n,new oe(a,r,o),t)}async _createPingMessage(){return new U}async _createQualityMessage(e){const t=e.getUint32(),s=e.getFloat(),i=e.getFloat(),n=e.getFloat(),a=e.getFloat();return new C(t,s,i,n,a)}async _createClipboardMessage(e){const t=e.getUint32(),s=e.getString(t);return new V(s)}_createShapeMessage(e){return new Promise(t=>{const s=e.getUint32(),i=e.getUint32(),n=e.getString(4),a=this._determineMimeType(n),r=e.getUint32(),o=e.getUint8Array(r);this._textureFactory.createTextureFromArray(o,a,d).then(n=>{t(new k(i,n,s,e.bufferLength))})})}}var pe,ye=f("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZXtjb25zdHJ1Y3RvcihlLHQ9MCl7dGhpcy50eXBlPWUsdGhpcy5jb21tYW5kSWQ9dH1zdGF0aWMgZ2V0IGNvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyKCl7cmV0dXJuIGUuX2NvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyfXN0YXRpYyBzZXQgY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXIodCl7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9dH19dmFyIHQ7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9ITEsZnVuY3Rpb24oZSl7ZVtlLk5PUD0wXT0iTk9QIixlW2UuQ09OTkVDVElPTj0xXT0iQ09OTkVDVElPTiIsZVtlLldJTkRPV1M9Ml09IldJTkRPV1MiLGVbZS5JTUFHRT0zXT0iSU1BR0UiLGVbZS5TQ1JFRU49NF09IlNDUkVFTiIsZVtlLlNVQklNQUdFUz01XT0iU1VCSU1BR0VTIixlW2UuTU9VU0U9Nl09Ik1PVVNFIixlW2UuQ1VSU09SX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1yZXR1cm4gbnVsbH0pKGUuaW1hZ2UpO3JldHVybiBuZXcgdyh7ZGF0YTpyLmRhdGEsd2lkdGg6dCxoZWlnaHQ6c30pfXJldHVybiBudWxsfX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9V2ViWE1lc3NhZ2VEZWNvZGVyV29ya2VyLmpzLm1hcAoK");class me{constructor(){this._pending=new Map,this._nextId=1,this._instructionEncoder=new de,this._messageDecoder=new ue,"undefined"!=typeof Worker&&(this._worker=new ye,this._worker.onmessage=e=>{const{id:t,message:s,error:i}=e.data,n=this._pending.get(t);if(this._pending.delete(t),i)console.error(i);else if(n){const e=(e=>{let t;return e&&(e.type===exports.WebXMessageType.NOP?t=Object.create(L.prototype):e.type===exports.WebXMessageType.CONNECTION?t=Object.create(E.prototype):e.type===exports.WebXMessageType.SCREEN?t=Object.create(X.prototype):e.type===exports.WebXMessageType.WINDOWS?t=Object.create(S.prototype):e.type===exports.WebXMessageType.IMAGE?t=Object.create(G.prototype):e.type===exports.WebXMessageType.SUBIMAGES?t=Object.create(R.prototype):e.type===exports.WebXMessageType.MOUSE?t=Object.create(v.prototype):e.type===exports.WebXMessageType.CURSOR_IMAGE?t=Object.create(T.prototype):e.type===exports.WebXMessageType.PING?t=Object.create(U.prototype):e.type===exports.WebXMessageType.QUALITY?t=Object.create(C.prototype):e.type===exports.WebXMessageType.CLIPBOARD?t=Object.create(V.prototype):e.type===exports.WebXMessageType.SHAPE&&(t=Object.create(k.prototype)),t&&Object.assign(t,e)),t})(s);n(e)}})}terminate(){this._worker.terminate(),this._pending.clear()}serializeInstruction(e){const t=this._instructionEncoder.encode(e);return null==t&&console.warn("Could not serialize instruction: Unknown type"),t}async deserializeMessage(e){if(this._worker&&(e=>{switch(e.messageTypeId){case exports.WebXMessageType.IMAGE:case exports.WebXMessageType.SUBIMAGES:case exports.WebXMessageType.SHAPE:return!0;default:return!1}})(e))return new Promise(t=>{const s=this._nextId++;this._pending.set(s,t);const i=[e.buffer];this._worker.postMessage({id:s,buffer:e.buffer,convertToImageData:x.convertToImageDataInWorker},i)});try{const t=await this._messageDecoder.decode(e);return null==t&&console.error("Failed to decode message data"),t}catch(e){console.error(`Caught error decoding message data: ${e.message}`)}}}class _e{constructor(){this._serializer=new me,this._instructionResponses=new Map}terminate(){this._serializer.terminate()}sendInstruction(e){const t=this._serializer.serializeInstruction(e);this.send(t)}sendRequest(e,t){e.synchronous=!0;const s=new K(e,t=t||1e4);return this._instructionResponses.set(e.id,s),new Promise((t,i)=>{const n=this._serializer.serializeInstruction(e);this.send(n),s.then(t).catch(t=>{this._instructionResponses.delete(e.id),i(t)})})}async onMessage(e){if(0===e.byteLength)return console.warn("Got a zero length message"),null;if(e.byteLength<ce.MESSAGE_HEADER_LENGTH)return console.warn("Message does not contain a valid header"),null;const t=new ce(e);this._handleCriticalMessages(t),this.handleReceivedBytes(e);const s=await this._serializer.deserializeMessage(t);if(null!=s)if(null!=s.commandId&&null!=this._instructionResponses.get(s.commandId)){const e=this._instructionResponses.get(s.commandId);this._instructionResponses.delete(s.commandId),e.resolve(s)}else this.handleMessage(s)}handleMessage(e){throw new Error("Method not implemented.")}handleReceivedBytes(e){throw new Error("Method not implemented.")}handleSentBytes(e){throw new Error("Method not implemented")}handleClose(e){this._instructionResponses.forEach(e=>{e.reject("Tunnel closed")}),this.onClosed()}onClosed(){console.log("Websocket closed")}_handleCriticalMessages(e){e.messageTypeId==exports.WebXMessageType.PING?this.sendInstruction(new q(e.timestampMs)):e.messageTypeId!=exports.WebXMessageType.SUBIMAGES&&e.messageTypeId!=exports.WebXMessageType.IMAGE||e.bufferLength>_e.MIN_BUFFER_LENGTH_FOR_ACK&&this.sendInstruction(new ee(e.timestampMs,e.bufferLength))}}_e.MIN_BUFFER_LENGTH_FOR_ACK=32768;class ge{constructor(e){this._tunnel=e,this._cursorMap=new Map}async getCursor(e){const t=this._cursorMap.get(e);if(null!=t)return{cursor:t};{const t=await this._tunnel.sendRequest(new j(e)),s={xHot:t.xHot,yHot:t.yHot,cursorId:t.cursorId,texture:t.texture};return this._cursorMap.set(t.cursorId,s),{x:t.x,y:t.y,cursor:s}}}}class be{constructor(e){this._tunnel=e}async getWindowTexture(e){try{const t=await this._tunnel.sendRequest(new J(e));return{depth:t.depth,colorMap:t.colorMap,alphaMap:t.alphaMap}}catch(e){console.warn("Failed to get texture: "+e)}}async getWindowStencilTexture(e){try{return{stencilMap:(await this._tunnel.sendRequest(new se(e))).stencilMap}}catch(e){return console.warn("Failed to get stencil texture: "+e),null}}}exports.WebXConnectionStatus=void 0,(pe=exports.WebXConnectionStatus||(exports.WebXConnectionStatus={}))[pe.STARTING=0]="STARTING",pe[pe.RUNNING=1]="RUNNING";class fe{constructor(){this._connected=!1,this._connectionCallback=()=>{},this._connectionError=()=>{},this._connectionStatusCallback=()=>{}}onConnected(e,t){return this._timeoutMs=e||1e4,this._connectionStatusCallback=t,new Promise((e,t)=>{this._connected?e():(this._connectionCallback=()=>{window.clearTimeout(this._timeout),this._timeout=null,e()},this._connectionError=()=>{this._timeout=null,t(new Error("Connection timed out"))},this._createTimer())})}setConnected(e){e?this._connectionStatusCallback(exports.WebXConnectionStatus.STARTING):(this._connected=!0,this._connectionStatusCallback(exports.WebXConnectionStatus.RUNNING),this._connectionCallback())}resetTimer(){this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null,this._createTimer())}dispose(){this._timeout&&window.clearTimeout(this._timeout)}_createTimer(){this._timeout=window.setTimeout(()=>{this._connectionError()},this._timeoutMs)}}const{version:Me}=require("../package.json");exports.LinearSRGBColorSpace=d,exports.SRGBColorSpace=c,exports.WebXClient=class{get tunnel(){return this._tunnel}get tracers(){return this._tracers}get display(){return this._display}get mouse(){return this._mouse}get keyboard(){return this._keyboard}set clipboardHandler(e){this._clipboardHandler=e}get maxQualityIndex(){return this._maxQualityIndex}constructor(e){this._tunnel=e,this._tracers=new Map,this._clipboardHandler=e=>{},this._connectionHandler=new fe,this._maxQualityIndex=10,this._windowImageFactory=new be(this._tunnel),this._cursorFactory=new ge(this._tunnel)}async connect(e,t){this._onCloseCallback=e,this._tunnel.handleMessage=this._handleMessage.bind(this),this._tunnel.handleReceivedBytes=this._handleReceivedBytes.bind(this),this._tunnel.handleSentBytes=this._handleSentBytes.bind(this),this._tunnel.onClosed=this._onTunnelClosed.bind(this),await this._tunnel.connect({...t,"client-version":Me})}disconnect(){this._tunnel.disconnect(),this._tunnel.terminate()}async initialise(e,t){try{t={useDefaultMouseAdapter:!0,useDefaultKeyboardAdapter:!0,waitForConnectionWithTimeout:1e4,connectionStatusCallback:()=>{},...t};const{useDefaultMouseAdapter:s,useDefaultKeyboardAdapter:i,waitForConnectionWithTimeout:n,connectionStatusCallback:a}=t;n>0&&await this._connectionHandler.onConnected(n,a);const r=await this._getScreenMessage(),{width:o,height:h}=r.screenSize;this._maxQualityIndex=r.maxQualityIndex,l.version=r.engineVersion,this._display=this.createDisplay(e,o,h);const c=await this._sendRequest(new A);return await this._display.updateWindows(c.windows),this._display.showScreen(),s&&(this._mouse=this.createMouse(e),this._addMouseListeners()),i&&(this._keyboard=this.createKeyboard(document.body),this._addKeyboardListeners()),this._display}catch(e){throw this._dispose(),new Error(`Failed to initialise display: ${e.message}`)}}createDisplay(e,t,s){return new N(e,t,s,this._windowImageFactory,this._cursorFactory)}createMouse(e){return new D(e)}createKeyboard(e){return new H(e)}sendMouse(e){this._display.setMousePosition(e.x,e.y),this._sendInstruction(new B(e.x,e.y,e.getButtonMask()))}sendKeyEvent(e,t){this._sendInstruction(new Q(e,t))}sendKeyDown(e){this.sendKeyEvent(e,!0)}sendKeyUp(e){this.sendKeyEvent(e,!1)}sendClipboardContent(e){this._sendInstruction(new te(e))}registerTracer(e,t){this._tracers.set(e,t)}createDebugImageMessageHandler(){return this._display?new he(this._display):(console.log("Cannot create DebugImageMessageHandler as display is null"),null)}resetInputs(){this._mouse&&this._mouse.reset(),this._keyboard&&this._keyboard.reset()}resizeDisplay(){this._display&&this._display.resize()}unregisterTracer(e){const t=this._tracers.get(e);t&&(t.destroy(),this._tracers.delete(e))}setQualityIndex(e){const t=new $(e);this._sendInstruction(t)}async createScreenshot(e,t){return this.display.createScreenshot(e,t)}async _getScreenMessage(){let e=0;for(;e<3;)try{return await this._sendRequest(new O,5e3)}catch(t){if(e++,console.log(`Failed to initialise screen size at attempt ${e}/3...`),3==e||!this._tunnel.isConnected())throw new Error(`unable to get screen size: ${t.message}`)}}_sendInstruction(e){this._tunnel.isConnected()&&(this._tunnel.sendInstruction(e),this._tracers.forEach(t=>{t instanceof ie&&t.handle(e)}))}_sendRequest(e,t){if(this._tunnel.isConnected())return this._tunnel.sendRequest(e,t)}_handleMessage(e){if(e.type===exports.WebXMessageType.CONNECTION){const t=e;return void this._connectionHandler.setConnected(t.isStarting)}if(e.type===exports.WebXMessageType.NOP&&this._connectionHandler.resetTimer(),this._display){if(e.type===exports.WebXMessageType.WINDOWS){const t=e.windows;this._display.updateWindows(t)}else if(e.type===exports.WebXMessageType.IMAGE){const t=e;this._display.updateImage(t.windowId,t.depth,t.colorMap,t.alphaMap)}else if(e.type===exports.WebXMessageType.SUBIMAGES){const t=e;this._display.updateSubImages(t.windowId,t.subImages)}else if(e.type===exports.WebXMessageType.SHAPE){const t=e;this._display.updateShape(t.windowId,t.stencilMap)}else if(e.type===exports.WebXMessageType.MOUSE){const t=e;t.x>0&&t.y>0&&this._display.setMousePosition(t.x,t.y),this._display.setMouseCursor(t.cursorId)}else if(e.type===exports.WebXMessageType.CLIPBOARD){const t=e;this._clipboardHandler(t.clipboardContent)}this._tracers.forEach(t=>{t instanceof ne&&t.handle(e)})}}_handleReceivedBytes(e){this._tracers.forEach(t=>{t instanceof ae&&t.handle({received:e.byteLength,sent:0})})}_handleSentBytes(e){this._tracers.forEach(t=>{t instanceof ae&&t.handle({received:0,sent:e.byteLength})})}_handleQuality(e){this._tracers.forEach(t=>{t instanceof ae&&t.handle({received:0,sent:e.byteLength})})}_onTunnelClosed(){this._dispose(),this._onCloseCallback&&this._onCloseCallback()}_dispose(){this._connectionHandler.dispose(),this._display&&this._display.dispose(),this._mouse&&this._mouse.dispose(),this._keyboard&&this._keyboard.dispose()}_addMouseListeners(){this._mouse.onMouseMove=this._mouse.onMouseOut=e=>{const t=this._display.scale;e.x=e.x/t,e.y=e.y/t,this.sendMouse(e)},this._mouse.onMouseDown=this._mouse.onMouseUp=e=>{const t=this._display.scale;e.x=e.x/t,e.y=e.y/t,this.sendMouse(e)}}_addKeyboardListeners(){this._keyboard.onKeyDown=e=>{this.sendKeyDown(e)},this._keyboard.onKeyUp=e=>{this.sendKeyUp(e)}}},exports.WebXClipboardInstruction=te,exports.WebXClipboardMessage=V,exports.WebXConnectInstruction=class extends P{constructor(e){super(exports.WebXInstructionType.CONNECT),this.parameters=e}},exports.WebXConnectionHandler=fe,exports.WebXConnectionMessage=E,exports.WebXCursorImageInstruction=j,exports.WebXCursorImageMessage=T,exports.WebXDataAckInstruction=ee,exports.WebXDebugImageMessageHandler=he,exports.WebXDisplay=N,exports.WebXImageInstruction=J,exports.WebXImageMessage=G,exports.WebXInstruction=P,exports.WebXInstructionHandler=ie,exports.WebXInstructionResponse=K,exports.WebXKeyboard=H,exports.WebXKeyboardInstruction=Q,exports.WebXMessage=x,exports.WebXMessageHandler=ne,exports.WebXMouse=D,exports.WebXMouseInstruction=B,exports.WebXMouseMessage=v,exports.WebXMouseState=z,exports.WebXNopMessage=L,exports.WebXPingMessage=U,exports.WebXPongInstruction=q,exports.WebXQualityInstruction=$,exports.WebXQualityMessage=C,exports.WebXScreenInstruction=O,exports.WebXScreenMessage=X,exports.WebXShapeInstruction=se,exports.WebXShapeMessage=k,exports.WebXStatsHandler=ae,exports.WebXSubImage=a,exports.WebXSubImagesMessage=R,exports.WebXTexture=u,exports.WebXTextureFactory=p,exports.WebXTunnel=_e,exports.WebXWebSocketTunnel=class extends _e{constructor(e,t={}){if(super(),this._socketOpen=!1,this._connectionOptions=t,"ws:"!==e.substring(0,3)&&"wss:"!==e.substring(0,4)){const t=window.location,s="https:"===t.protocol?"wss:":"ws:",i=t.hostname,n=t.port?`:${t.port}`:"";e="/"===e.substring(0,1)?`${s}//${i}${n}${e}`:`${s}//${i}${n}/${e}`}this._url=e}getSocket(){return this._socket}send(e){null!=this._socket&&(this._socket.send(e),this.handleSentBytes(e))}connect(e){const t={...this._connectionOptions,...e},s=new URLSearchParams(t),i=`${this._url}?${s}`;return new Promise((e,t)=>{this._socket=new WebSocket(i),this._socket.binaryType="arraybuffer",this._socket.onopen=()=>{this._socketOpen=!0,e(null)},this._socket.onerror=e=>t(e),this._socket.onclose=this.handleClose.bind(this),this._socket.onmessage=e=>this.onMessage(e.data)})}disconnect(){this._socket&&(this._socketOpen=!1,this._socket.close(),this._socket=null)}isConnected(){return this._socketOpen}},exports.WebXWindowProperties=n,exports.WebXWindowsInstruction=A,exports.WebXWindowsMessage=S,exports.alphaAndStencilBlend=r,exports.alphaBufferBlend=o,exports.colorAndAlphaBlendImageToImageData=(e,t)=>{const s=e.width,i=e.height,n=new OffscreenCanvas(s,i).getContext("2d",{willReadFrequently:!0});n.drawImage(e,0,0);const a=n.getImageData(0,0,s,i);n.drawImage(t,0,0);const r=n.getImageData(0,0,s,i);return o(a.data,r.data),a},exports.imageToImageData=e=>{if(e){const t=e.width,s=e.height,i=new OffscreenCanvas(t,s).getContext("2d",{willReadFrequently:!0});return i.drawImage(e,0,0),i.getImageData(0,0,t,s)}return null},exports.toThreeTexture=y;
1
+ "use strict";var e=require("three"),t=require("@tweenjs/tween.js");function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}}),t.default=e,Object.freeze(t)}var i=s(e);class n{constructor(e){this.id=e.id,this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.shaped=e.shaped||!1}}class r{constructor(e){this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.depth=e.depth,this.colorMap=e.colorMap,this.alphaMap=e.alphaMap}}const a=(e,t,s)=>{if(t&&s)for(let i=0;i<e.length;i+=4)s[i]<128?e[i+3]=0:e[i+3]=t[i+1];else if(t)for(let s=0;s<e.length;s+=4)e[s+3]=t[s+1];else if(s)for(let t=0;t<e.length;t+=4)e[t+3]=s[t]<128?0:e[t+3]},o=(e,t)=>{for(let s=0;s<e.length;s+=4)e[s+3]=t[s+1]};class h extends e.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get alphaMap(){return this.uniforms.alphaMap.value}set alphaMap(e){this.uniforms.alphaMap.value=e}get stencilMap(){return this.uniforms.stencilMap.value}set stencilMap(e){this.uniforms.stencilMap.value=e,e?this.defines.USE_STENCILMAP="":delete this.defines.USE_STENCILMAP}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value.copy(e)}constructor(t){super({uniforms:{map:{value:null},alphaMap:{value:null},stencilMap:{value:null},mapTransform:{value:new e.Matrix3},alphaMapTransform:{value:new e.Matrix3},diffuse:{value:new e.Color(16777215)},opacity:{value:1}},vertexShader:"\n#ifdef USE_MAP\nuniform mat3 mapTransform;\nvarying vec2 vMapUv;\n#endif\n\n#ifdef USE_ALPHAMAP\nuniform mat3 alphaMapTransform;\nvarying vec2 vAlphaMapUv;\n#endif\n\n#ifdef USE_STENCILMAP\nvarying vec2 vStencilMapUv;\n#endif\n\nvoid main() {\n#ifdef USE_MAP\n vMapUv = (mapTransform * vec3(uv, 1)).xy;\n#endif\n\n#ifdef USE_ALPHAMAP\n vAlphaMapUv = (alphaMapTransform * vec3(uv, 1)).xy;\n#endif\n\n#ifdef USE_STENCILMAP\n vStencilMapUv = uv;\n#endif\n\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\nuniform vec3 diffuse;\nuniform float opacity;\n\n#ifdef USE_MAP\nuniform sampler2D map;\nvarying vec2 vMapUv;\n#endif\n\n#ifdef USE_ALPHAMAP\nuniform sampler2D alphaMap;\nvarying vec2 vAlphaMapUv;\n#endif\n\n#ifdef USE_STENCILMAP\nuniform sampler2D stencilMap;\nvarying vec2 vStencilMapUv;\n#endif\n\nvoid main() {\n vec4 diffuseColor = vec4(diffuse, opacity);\n\n#ifdef USE_STENCILMAP\n vec4 stencil = texture2D(stencilMap, vStencilMapUv);\n if (stencil.r < 0.5) {\n discard;\n }\n#endif\n\n#ifdef USE_MAP\n vec4 sampledDiffuseColor = texture2D(map, vMapUv);\n diffuseColor *= sampledDiffuseColor;\n#endif\n\n#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D(alphaMap, vAlphaMapUv).g;\n#endif\n\n gl_FragColor = diffuseColor;\n}\n",transparent:!0,depthTest:!0,side:e.BackSide}),t&&t.color&&this.color.set(t.color)}onBeforeRender(){this.map&&this.map.matrixAutoUpdate&&(this.map.updateMatrix(),this.uniforms.mapTransform.value.copy(this.map.matrix)),this.alphaMap&&this.alphaMap.matrixAutoUpdate&&(this.alphaMap.updateMatrix(),this.uniforms.alphaMapTransform.value.copy(this.alphaMap.matrix))}}class l{}class c{constructor(e){this.image=e.image?e.image:null,this.data=e.data,this.width=e.image?e.image.width:e.width,this.height=e.image?e.image.height:e.height,this.flipY=!1}isTransferable(){return this.image&&this.image instanceof ImageBitmap||null!=this.data}get transferable(){return this.image&&this.image instanceof ImageBitmap?this.image:this.data?this.data.buffer:null}}class d{constructor(){}async createTextureFromArray(e,t){if(null!=e&&e.byteLength>0){const s=new Blob([e],{type:t}),i=await this.createTextureFromBlob(s);return i.flipY=!1,i}return null}createTextureFromBlob(e){return"function"==typeof createImageBitmap?new Promise((t,s)=>{createImageBitmap(e).then(e=>{const s=new c({image:e});t(s)}).catch(e=>{console.warn(`Failed to create texture using createImageBitmap from binary data: ${e}`),s(e)})}):new Promise((t,s)=>{const i=URL.createObjectURL(e),n=new Image;n.onload=()=>{URL.revokeObjectURL(i);const e=new c({image:n});t(e)},n.onerror=e=>{console.warn(`Failed to create texture from binary data: ${e}`),s(e)},n.src=i})}}const u=t=>{if(t){const s=t.data?new i.DataTexture(t.data,t.width,t.height):new i.Texture(t.image);return s.needsUpdate=!0,s.flipY=t.flipY,s.minFilter=e.LinearFilter,s}return null};class p{get mesh(){return this._mesh}get colorIndex(){return this._colorIndex}get id(){return this._id}get visible(){return this._material.visible}set visible(e){this._material.visible!==e&&(this._material.visible=e)}get loaded(){return this._loaded}get colorMap(){return this._material.map}set colorMap(e){this._material.map=e}get alphaMap(){return this._material.alphaMap}set alphaMap(e){this._material.alphaMap=e}get stencilMap(){return this._material.stencilMap}set stencilMap(e){this._material.stencilMap=e}get colorMapValid(){return null!=this.colorMap&&this.colorMap.image.width===this._width&&this.colorMap.image.height===this._height}get depth(){return this._depth}get x(){return this._x}set x(e){this._x=e,this._updatePosition()}get y(){return this._y}set y(e){this._y=e,this._updatePosition()}get z(){return this._z}set z(e){this._z=e,this._updatePosition()}get width(){return this._width}set width(e){this._width=e,this._updateScale(),this._updatePosition()}get height(){return this._height}set height(e){this._height=e,this._updateScale(),this._updatePosition()}get shaped(){return this._shaped}set shaped(e){this._shaped=e,e||this.updateStencilTexture(null)}constructor(e,t){this._width=1,this._height=1,this._shaped=!1,this._loaded=!1,this._windowRefreshTimeout=null,this._windowImageFactory=t,this._colorIndex=p._COLOR_INDEX++,this._material=new h,this.visible=!1;const{id:s,x:n,y:r,z:a,width:o,height:c,shaped:d}=e;this._id=s,this._mesh=new i.Mesh(p._PLANE_GEOMETRY,this._material),this._mesh.onBeforeRender=()=>this._material.onBeforeRender(),this._x=n,this._y=r,this._z=a,this._width=o,this._height=c,this._shaped=d&&l.version.versionNumber>=1.4,this._updateScale(),this._updatePosition()}async loadWindowImage(){const e=await this._windowImageFactory.getWindowTexture(this._id);e&&this.updateTexture(e.depth,u(e.colorMap),u(e.alphaMap),!0)}async loadWindowShape(){const e=await this._windowImageFactory.getWindowStencilTexture(this._id);e?this.updateStencilTexture(u(e.stencilMap)):(this._shaped=!1,this.visible=null!=this.colorMap)}async loadWindowImageAndShape(){if(this._shaped){const e=this.loadWindowImage(),t=this.loadWindowShape();await Promise.all([e,t])}else await this.loadWindowImage();this._loaded=!0}setRectangle(e,t,s,i,n){this._x=e,this._y=t,this._z=s,this._width=i,this._height=n,this.colorMap&&(this.colorMap.repeat.set(this._width/this.colorMap.image.width,this._height/this.colorMap.image.height),this.alphaMap&&this.alphaMap.repeat.set(this._width/this.alphaMap.image.width,this._height/this.alphaMap.image.height),this.colorMap.image.width===this._width&&this.colorMap.image.height===this._height||this.loadWindowImageAndShape()),this._updateScale(),this._updatePosition()}updateTexture(e,t,s,i){if(null==t)return;const n=null!=this.colorMap,r=null!=this.alphaMap;this._depth=e,t!=this.colorMap&&(this._disposeColorMap(),this.colorMap=t),this.colorMap.repeat.set(this._width/this.colorMap.image.width,this._height/this.colorMap.image.height),this.visible=!this._shaped||null!=this.stencilMap,s?(s!=this.alphaMap&&(this._disposeAlphaMap(),this.alphaMap=s),this.alphaMap.repeat.set(this._width/this.alphaMap.image.width,this._height/this.alphaMap.image.height)):24==e&&this._disposeAlphaMap(),this._material.transparent=null!=this.alphaMap||32===e;const a=null!=this.colorMap,o=null!=this.alphaMap;n==a&&r==o||(this._material.needsUpdate=!0),i||(this._windowRefreshTimeout&&(clearTimeout(this._windowRefreshTimeout),this._windowRefreshTimeout=null),this._windowRefreshTimeout=window.setTimeout(()=>{this._windowRefreshTimeout=null,this.loadWindowImage().then()},p.WINDOW_REFRESH_TIME_MS))}updateStencilTexture(t){const s=this._shaped;t!=this.stencilMap&&(this._disposeStencilMap(),this.stencilMap=t),t?(t.minFilter=e.LinearFilter,this.visible=null!=this.colorMap,this._shaped=!0):this._shaped=!1,s!==this._shaped&&(this._material.needsUpdate=!0)}_updateScale(){this._mesh.scale.set(this._width,this._height,1)}_updatePosition(){this._mesh.position.set(this._x+.5*this._width,this._y+.5*this._height,this._z)}dispose(){this._disposeColorMap(),this._disposeAlphaMap(),this._disposeStencilMap(),this._material.dispose(),this._windowRefreshTimeout&&(clearTimeout(this._windowRefreshTimeout),this._windowRefreshTimeout=null)}_disposeColorMap(){this.colorMap&&(this.colorMap.dispose(),this.colorMap=null)}_disposeAlphaMap(){this.alphaMap&&(this.alphaMap.dispose(),this.alphaMap=null)}_disposeStencilMap(){this.stencilMap&&(this.stencilMap.dispose(),this.stencilMap=null)}}p.WINDOW_REFRESH_TIME_MS=5e3,p._PLANE_GEOMETRY=new i.PlaneGeometry(1,1,2,2),p._COLOR_INDEX=0;class m{get canvas(){return this._canvas}get cursorId(){return this._cursorId}set x(e){this._x=e,this._updatePosition()}set y(e){this._y=e,this._updatePosition()}constructor(e){this._cursorFactory=e,this._x=-1,this._y=-1,this._xHot=0,this._yHot=0,this._width=1,this._height=1,this._canvas=document.createElement("canvas"),this._canvas.id="webx-cursor",this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._context=this._canvas.getContext("2d"),this.setPosition(-1,-1),this.setCursorId(0)}setPosition(e,t){this._x=e,this._y=t,this._updatePosition()}setCursorId(e){this._cursorId!==e&&(this._cursorId=e,this._cursorFactory.getCursor(e).then(e=>{const t=e.cursor;(this._x<0||this._y<0)&&this.setPosition(e.x,e.y),this._updateCursor(t.xHot,t.yHot,t.cursorId,t.texture)}))}_updateCursor(e,t,s,i){this._xHot=e,this._yHot=t,this._cursorId=s,null!=i&&null!=i.image&&(this._width=i.image.width,this._height=i.image.height,this._canvas.style.width=`${this._width}px`,this._canvas.style.height=`${this._height}px`,this._canvas.width=this._width,this._canvas.height=this._height,this._texture=i,this._context.clearRect(0,0,this._width,this._height),this._context.drawImage(this._texture.image,0,0,this._width,this._height))}_updatePosition(){this._canvas.style.left=this._x-this._xHot+"px",this._canvas.style.top=this._y-this._yHot+"px"}}class y{get id(){return this._mesh.id}get canvas(){return this._canvas}get x(){return this._x}get y(){return this._y}get zIndex(){return this._zIndex}get width(){return this._width}get height(){return this._height}constructor(e,t){this._mesh=e,this._imageBlender=t,this._x=0,this._y=0,this._zIndex=0,this._width=0,this._height=0,this._regionUpdates=[],this._canvas=this.createElementNS("canvas"),this._canvas.id=`webx-window-${this.id}`,this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvas.style.top="0",this._canvas.style.left="0",this._canvas.style.overflow="hidden",this._context=this._canvas.getContext("2d"),this.updateGeometry(),this.updateCanvas()}updateGeometry(){const e=this._mesh.scale.x,t=this._mesh.scale.y,s=this._mesh.position.x-.5*e,i=this._mesh.position.y-.5*t,n=this._mesh.position.z;s===this._x&&i===this._y||(this._canvas.style.top=`${i}px`,this._canvas.style.left=`${s}px`,this._x=s,this._y=i),e===this._width&&t===this._height||(this._width=e,this._height=t),n!==this._zIndex&&(this._canvas.style.zIndex=`${this._mesh.position.z}`,this._zIndex=n)}async updateCanvas(){if(this._mesh.material instanceof h||this._mesh.material instanceof e.MeshBasicMaterial){const t=this._mesh.material;if(this.updateStencilMap(t),t.map?.image){if(t.map!=this._colorMap||t.alphaMap!=this._alphaMap){this._colorMap=t.map,this._alphaMap=t.alphaMap;const s=t.map.image,i=s.width,n=s.height;if(this.isValidAlphaMap(t.alphaMap)||null!=this._stencilMap){const e=await this.blendAlphaAndStencil(t.map,t.alphaMap,0,0);this.resizeCanvas(i,n),this._context.putImageData(e,0,0)}else if(this.resizeCanvas(i,n),t.map instanceof e.DataTexture){const e=this.dataTextureToImageData(s);this._context.putImageData(e,0,0)}else this._context.clearRect(0,0,i,n),this._context.drawImage(s,0,0,i,n)}await this.handleRegionUpdates()}else this._colorMap&&(this._colorMap=null,this._alphaMap=null,this._regionUpdates=[],this._context.clearRect(0,0,this._canvas.width,this._canvas.height))}}addRegionUpdate(e,t,s,i,n,r,a){this._regionUpdates.push({srcColorMap:e,dstColorMap:t,srcAlphaMap:s,dstAlphaMap:i,width:n,height:r,dstPosition:a})}resizeCanvas(e,t){this._canvas.width===e&&this._canvas.height===t||(this._canvas.width=e,this._canvas.height=t,this._canvas.style.width=`${e}px`,this._canvas.style.height=`${t}px`)}async handleRegionUpdates(){for(const t of this._regionUpdates)if(t.dstColorMap===this._colorMap&&t.dstAlphaMap===this._alphaMap){const{srcColorMap:s,srcAlphaMap:i,width:n,height:r,dstPosition:a}=t,o=s.image;if(i||this._stencilData){const e=await this.blendAlphaAndStencil(s,i,a.x,a.y);e&&this._context.putImageData(e,a.x,a.y)}else if(s instanceof e.DataTexture){const e=this.dataTextureToImageData(o);this._context.putImageData(e,a.x,a.y)}else this._context.drawImage(o,0,0,n,r,a.x,a.y,n,r)}this._regionUpdates=[]}isValidAlphaMap(e){if(e){const t=e.image.width,s=e.image.height;return t===this._canvas.width&&s===this._canvas.height}return!1}updateStencilMap(t){if(t instanceof h&&t.stencilMap){if(t.stencilMap!=this._stencilMap){this._stencilMap=t.stencilMap;const s=this._stencilMap.image,{width:i,height:n}=s;if(this._stencilMap instanceof e.DataTexture)this._stencilData=this.dataTextureToImageData(s);else{const e=this.createElementNS("canvas");e.width=i,e.height=n;const t=e.getContext("2d",{willReadFrequently:!0});t.drawImage(s,0,0),this._stencilData=t.getImageData(0,0,i,n)}}}else this._stencilMap&&(this._stencilMap=null,this._stencilData=null)}async blendAlphaAndStencil(t,s,i,n){const r=t instanceof e.DataTexture?this.dataTextureToImageData(t.image):this.getImageData(t.image),a=null==s?null:s instanceof e.DataTexture?this.dataTextureToImageData(s.image):this.getImageData(s.image),o=null==this._stencilData?null:this.getStencilDataRegion(i,n,r.width,r.height);return a||o?await this._imageBlender.blendAlphaAndStencil(r,a,o):r}createElementNS(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}getImageData(e){const t=this.createElementNS("canvas");t.width=e.width,t.height=e.height;const s=t.getContext("2d");return s.drawImage(e,0,0),s.getImageData(0,0,e.width,e.height)}dataTextureToImageData(e){if(e.data.byteLength>0){const t=e.data instanceof Uint8ClampedArray?e.data:new Uint8ClampedArray(e.data.buffer);return new ImageData(t,e.width,e.height)}return new ImageData(new Uint8ClampedArray(4),1,1)}getStencilDataRegion(e,t,s,i){const n=this._stencilData.data,r=this._stencilData.width,a=new Uint8ClampedArray(s*i*4);for(let o=0;o<i;o++){const i=4*((t+o)*r+e),h=o*s*4;a.set(n.subarray(i,i+4*s),h)}return new ImageData(a,s,i)}}function _(e,t,s){var i=function(e){return atob(e)}(e),n=i.indexOf("\n",10)+1,r=i.substring(n)+"",a=new Blob([r],{type:"application/javascript"});return URL.createObjectURL(a)}function g(e,t,s){var i;return function(t){return i=i||_(e),new Worker(i,t)}}var b,f=g("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7c2VsZi5vbm1lc3NhZ2U9ZT0+e2NvbnN0e2lkOmYsY29sb3JCdWZmZXI6bCxhbHBoYUJ1ZmZlcjp0LHN0ZW5jaWxCdWZmZXI6cix3aWR0aDpuLGhlaWdodDppfT1lLmRhdGEscz1uZXcgVWludDhDbGFtcGVkQXJyYXkobCk7KChlLGYsbCk9PntpZihmJiZsKWZvcihsZXQgdD0wO3Q8ZS5sZW5ndGg7dCs9NClsW3RdPDEyOD9lW3QrM109MDplW3QrM109Zlt0KzFdO2Vsc2UgaWYoZilmb3IobGV0IGw9MDtsPGUubGVuZ3RoO2wrPTQpZVtsKzNdPWZbbCsxXTtlbHNlIGlmKGwpZm9yKGxldCBmPTA7ZjxlLmxlbmd0aDtmKz00KWVbZiszXT1sW2ZdPDEyOD8wOmVbZiszXX0pKHMsdD9uZXcgVWludDhDbGFtcGVkQXJyYXkodCk6bnVsbCxyP25ldyBVaW50OENsYW1wZWRBcnJheShyKTpudWxsKSxzZWxmLnBvc3RNZXNzYWdlKHtpZDpmLGNvbG9yQnVmZmVyOnMuYnVmZmVyLHdpZHRoOm4saGVpZ2h0Oml9LFtzLmJ1ZmZlcl0pfX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9V2ViWEltYWdlQmxlbmRlcldvcmtlci5qcy5tYXAKCg==");class M{constructor(){this._pending=new Map,this._nextId=1,"undefined"!=typeof Worker&&(this._worker=new f,this._worker.onmessage=e=>{const{id:t,colorBuffer:s,width:i,height:n}=e.data,r=this._pending.get(t);if(!r)return;this._pending.delete(t);const a=new Uint8ClampedArray(s);r(new ImageData(a,i,n))})}async blendAlphaAndStencil(e,t,s){return new Promise(i=>{if(this._worker){const n=this._nextId++;this._pending.set(n,i);const r=e.width,a=e.height,o=e.data.buffer;let h=null,l=null;const c=[o];t&&(h=t.data.buffer,c.push(h)),s&&(l=s.data.buffer,c.push(l)),this._worker.postMessage({id:n,colorBuffer:o,alphaBuffer:h,stencilBuffer:l,width:r,height:a},c)}else a(e.data,t?.data,s?.data),i(e)})}terminate(){this._worker.terminate(),this._pending.clear()}}class w{get domElement(){return this._desktopContainer}constructor(){this._clearColor=new e.Color(0,0,0),this._windowCanvases=new Map,this.createMainElement(),this._imageBlender=new M}setSize(e,t,s){this._width=e,this._height=t,this._desktop.style.width=`${e}px`,this._desktop.style.height=`${t}px`}setClearColor(e){this._clearColor.set(e),this._desktop.style.backgroundColor=`#${this._clearColor.getHexString()}`}render(t,s){if(t.children.length>0){const s=t.children[0],i=new Set;for(const t of s.children)if(t instanceof e.Mesh&&t.visible){this._windowCanvases.has(t.id)||this.createWindowCanvas(t);const e=this._windowCanvases.get(t.id);e.updateGeometry(),e.updateCanvas(),i.add(t.id)}for(const[e,t]of this._windowCanvases.entries())i.has(e)||this.removeWindowCanvas(t)}else if(this._windowCanvases.size>0)for(const[e,t]of this._windowCanvases.entries())this.removeWindowCanvas(t)}createScreenshot(e,t){return new Promise((s,i)=>{try{const i=this.createElementNS("canvas");i.width=this._width,i.height=this._height;const n=i.getContext("2d");n.fillStyle=`#${this._clearColor.getHexString()}`,n.fillRect(0,0,this._width,this._height),Array.from(this._windowCanvases.values()).sort((e,t)=>e.zIndex-t.zIndex).forEach(e=>{n.drawImage(e.canvas,e.x,e.y)}),i.toBlob(e=>{s(e)},e,t)}catch(e){i(e)}})}dispose(){for(const[e,t]of this._windowCanvases.entries())this.removeWindowCanvas(t);this._imageBlender.terminate()}updateWindowRegion(e,t,s,i,n,r,a,o){const h=this._windowCanvases.get(e);h&&h.addRegionUpdate(t,s,i,n,r,a,o)}createMainElement(){const e=this.createElementNS("div");e.id="webx-desktop-container",e.style.display="block",e.style.position="relative",e.style.overflow="hidden";const t=document.createElement("div");t.id="webx-desktop",e.style.position="absolute",e.style.transformOrigin="top left",e.appendChild(t),this._desktopContainer=e,this._desktop=t}createWindowCanvas(e){const t=new y(e,this._imageBlender);this._desktop.appendChild(t.canvas),this._windowCanvases.set(e.id,t)}removeWindowCanvas(e){this._desktop.removeChild(e.canvas),this._windowCanvases.delete(e.id)}createElementNS(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}}class W{get overlayElement(){return this._overlayElement}set visible(e){this._overlayElement.style.visibility=e?"visible":"hidden"}constructor(e){this._cursor=e,this._overlayElement=this._createDisplayOverlayElement(),this._overlayElement.appendChild(this._cursor.canvas)}update(){}_createDisplayOverlayElement(){const e=document.createElement("div");return e.id="webx-overlay",e.style.position="absolute",e.style.width="100%",e.style.height="100%",e.style.zIndex="999",e.style.visibility="hidden",e.style.overflow="clip",e}}class I{constructor(e,t=0){this.type=e,this.commandId=t}static get convertToImageDataInWorker(){return I._convertToImageDataInWorker}static set convertToImageDataInWorker(e){I._convertToImageDataInWorker=e}}I._convertToImageDataInWorker=!1,exports.WebXMessageType=void 0,(b=exports.WebXMessageType||(exports.WebXMessageType={}))[b.NOP=0]="NOP",b[b.CONNECTION=1]="CONNECTION",b[b.WINDOWS=2]="WINDOWS",b[b.IMAGE=3]="IMAGE",b[b.SCREEN=4]="SCREEN",b[b.SUBIMAGES=5]="SUBIMAGES",b[b.MOUSE=6]="MOUSE",b[b.CURSOR_IMAGE=7]="CURSOR_IMAGE",b[b.PING=8]="PING",b[b.DISCONNECT=9]="DISCONNECT",b[b.QUALITY=10]="QUALITY",b[b.CLIPBOARD=11]="CLIPBOARD",b[b.SHAPE=12]="SHAPE";class x extends I{constructor(e,t,s,i){super(exports.WebXMessageType.SCREEN,i),this.screenSize=e,this.maxQualityIndex=t,this.engineVersion=s}}class Z extends I{constructor(e,t){super(exports.WebXMessageType.WINDOWS,t),this.windows=e}}class S extends I{constructor(e,t,s,i,n,r){super(exports.WebXMessageType.IMAGE,n),this.windowId=e,this.depth=t,this.colorMap=s,this.alphaMap=i,this.size=r}}class v extends I{constructor(e,t,s,i){super(exports.WebXMessageType.SUBIMAGES,s),this.windowId=e,this.subImages=t,this.size=i}}class X extends I{constructor(e,t,s,i){super(exports.WebXMessageType.MOUSE,i),this.x=e,this.y=t,this.cursorId=s}}class U extends I{constructor(e,t,s,i,n,r,a){super(exports.WebXMessageType.CURSOR_IMAGE,a),this.x=e,this.y=t,this.xHot=s,this.yHot=i,this.cursorId=n,this.texture=r}}class G extends I{constructor(){super(exports.WebXMessageType.PING)}}class R extends I{constructor(e,t,s,i,n){super(exports.WebXMessageType.QUALITY),this.index=e,this.imageFPS=t,this.rgbQuality=s,this.alphaQuality=i,this.maxMbps=n}}class C extends I{constructor(e){super(exports.WebXMessageType.CLIPBOARD),this.clipboardContent=e}}class T extends I{constructor(e){super(exports.WebXMessageType.CONNECTION),this.isStarting=e}}class V extends I{constructor(){super(exports.WebXMessageType.NOP)}}class E extends I{constructor(e,t,s,i){super(exports.WebXMessageType.SHAPE,s),this.windowId=e,this.stencilMap=t,this.size=i}}class k extends e.ShaderMaterial{constructor(e){super(e)}}class L extends k{set tDiffuse(e){this.uniforms.tDiffuse.value=e}constructor(e){super({uniforms:{tDiffuse:{value:e?.map},time:{value:0}},vertexShader:"\nvarying vec2 vUv;\n\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\nvarying vec2 vUv;\nuniform float time;\nuniform sampler2D tDiffuse;\n\nvoid main() {\n vec4 color = texture2D(tDiffuse, vUv);\n color.r = (1.0 - time) * color.r + time * color.g;\n color.g = (1.0 - time) * color.g + time * color.b;\n color.b = (1.0 - time) * color.b + time * color.r;\n gl_FragColor = color;\n}\n",transparent:!1,depthTest:!1})}update(){}}const N=t=>{const s={time:0,tDiffuse:null,curvature:10,scanlineIntensity:.2,scanlineCount:800,vignetteIntensity:.7,noiseIntensity:.08,flickerIntensity:.03,rgbOffset:8e-4,brightness:1.1,contrast:1.05,backgroundColor:"#000000",...(t=t||{})||{}};return Object.fromEntries(Object.entries(s).map(([s,i])=>{let n=null==t[s]?i:t[s];return"backgroundColor"===s&&(n=new e.Color(n)),[s,{value:n}]}))};class F extends k{set tDiffuse(e){this.uniforms.tDiffuse.value=e}constructor(e){super({uniforms:N(e),vertexShader:"\nvarying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n",fragmentShader:"\nuniform sampler2D tDiffuse;\nuniform float time;\nuniform float curvature;\nuniform float scanlineIntensity;\nuniform float scanlineCount;\nuniform float vignetteIntensity;\nuniform float noiseIntensity;\nuniform float flickerIntensity;\nuniform float rgbOffset;\nuniform float brightness;\nuniform float contrast;\nuniform vec3 backgroundColor;\nvarying vec2 vUv;\n\n// Random noise function\nfloat random(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\n\n// Apply screen curvature\nvec2 curveRemapUV(vec2 uv) {\n uv = uv * 2.0 - 1.0;\n vec2 offset = abs(uv.yx) / vec2(curvature, curvature);\n uv = uv + uv * offset * offset;\n uv = uv * 0.5 + 0.5;\n return uv;\n}\n\nvoid main() {\n // Apply screen curvature\n vec2 remappedUv = curveRemapUV(vUv);\n vec3 color = vec3(0.0);\n\n // Check if UV is outside the curved screen\n if (remappedUv.x < 0.0 || remappedUv.x > 1.0 || remappedUv.y < 0.0 || remappedUv.y > 1.0) {\n gl_FragColor = vec4(backgroundColor, 1.0);\n return;\n }\n\n // RGB color separation (chromatic aberration)\n float r = texture2D(tDiffuse, remappedUv + vec2(rgbOffset, 0.0)).r;\n float g = texture2D(tDiffuse, remappedUv).g;\n float b = texture2D(tDiffuse, remappedUv - vec2(rgbOffset, 0.0)).b;\n color = vec3(r, g, b);\n\n // Apply scanlines\n float scanline = sin(remappedUv.y * scanlineCount * 3.14159 * 2.0) * 0.5 + 0.5;\n scanline = pow(scanline, 1.0) * scanlineIntensity;\n color *= 1.0 - scanline;\n\n // Apply noise\n float noise = random(vUv + vec2(time * 0.01, 0.0)) * noiseIntensity;\n color += noise;\n\n // Apply flicker\n float flicker = random(vec2(time * 0.1, 0.0)) * flickerIntensity;\n color *= 1.0 - flicker;\n\n // Apply vignette\n float vignette = length(vUv - 0.5) * vignetteIntensity;\n color *= 1.0 - vignette;\n\n // Apply brightness and contrast\n color = (color - 0.5) * contrast + 0.5;\n color *= brightness;\n\n // Add subtle phosphor glow\n float glow = max(max(r, g), b) * 0.3;\n color += vec3(glow * 0.3, glow * 0.2, glow * 0.4);\n\n gl_FragColor = vec4(color, 1.0);\n}\n",transparent:!1,depthTest:!1}),this._startTime=(new Date).getTime()/1e3}update(){const e=(new Date).getTime()/1e3;this.uniforms.time.value=.3*(e-this._startTime)}}class Y{get name(){return this._name}constructor(e,t,s,n,r){if(this._rtTexture=null,this._name=e,this._renderer=t,this._filterMaterial=r,r){this._sceneScreen=new i.Scene,this._rtTexture=new i.WebGLRenderTarget(s,n),this._filterMaterial.tDiffuse=this._rtTexture.texture;const e=new i.PlaneGeometry(s,n),t=new i.Mesh(e,this._filterMaterial);t.rotateX(Math.PI),t.position.set(.5*s,.5*n,10),this._sceneScreen.add(t)}}render(e,t,s){s&&(this._renderer.setRenderTarget(this._rtTexture),this._renderer.render(e,t),this._renderer.setRenderTarget(null)),this._sceneScreen&&(this._filterMaterial.update(),this._renderer.render(this._sceneScreen,t))}dispose(){this._filterMaterial.dispose(),this._rtTexture.dispose()}}class D{static Build(e,t,s,i,n){return e instanceof w?null:new Y(i,e,t,s,D._createFilterMaterial(i,n))}static _createFilterMaterial(e,t){return"test"===e?new L:"crt"===e?new F(t):(console.log(`Unknown filter ${e}`),null)}}class H{get renderer(){return this._renderer}get filter(){return this._filter?.name}set filter(e){this._filter&&this._filter.dispose(),this._filter=e?D.Build(this._renderer,this._screenWidth,this._screenHeight,e,this._getFilterParams()):null,this._sceneDirty=!0,this._render()}get screenWidth(){return this._screenWidth}get screenHeight(){return this._screenHeight}get containerElement(){return this._containerElement}get scale(){return this._scale}get scene(){return this._scene}get camera(){return this._camera}get sceneDirty(){return this._sceneDirty}set sceneDirty(e){this._sceneDirty=e}constructor(t,s,n,r,a,o){this._isWebGL=!0,this._windows=[],this._scale=1,this._disposed=!1,this._sceneDirty=!1,this._disableStencil=!1,e.ColorManagement.enabled=!1,this._containerElement=t,this._screenWidth=s,this._screenHeight=n,this._windowImageFactory=r,this._options=o||{},this._cursor=new m(a),this._displayOverlay=new W(this._cursor),this._scene=new i.Scene,this._screen=new i.Object3D;const h=new i.Mesh(new i.PlaneGeometry(1,1,2,2),new i.MeshBasicMaterial({map:new i.DataTexture(new Uint8ClampedArray(4),1,1),side:i.BackSide,transparent:!0}));h.position.set(0,0,999),this._screen.add(h),this._camera=new i.OrthographicCamera(0,s,0,n,.1,1e4),this._camera.position.z=1e3,this._camera.lookAt(new e.Vector3(0,0,0));const l=this._options.backgroundColor||window.getComputedStyle(this._containerElement).backgroundColor,c=this._detectWebGL2(),d=new URL(window.location.href).searchParams,u="true"===d.get("webx-canvas")||this._options.forceCanvas;if(this._disableStencil="false"===d.get("webx-stencil")||this._options.disableStencil,this._isWebGL=c.available&&!c.isSoftware&&!u,this._isWebGL){this._renderer=new i.WebGLRenderer;const e=this._options.filter?"string"==typeof this._options.filter?this._options.filter:this._options.filter.name:null,t=d.get("webx-filter")?d.get("webx-filter"):e;t&&(this._filter=D.Build(this._renderer,s,n,t,this._getFilterParams()))}else console.log(`WebGL2 Info: available = ${c.available}, isSoftware = ${c.isSoftware}, vendor = ${c.vendor}, renderer = ${c.renderer}`),u?console.log("Canvas Renderer enabled through request param"):console.log("Falling back to Canvas Renderer"),this._renderer=new w,I.convertToImageDataInWorker=!0;this._renderer.setSize(s,n,!1),this._renderer.setClearColor(new e.Color(l)),this._render(),this._bindListeners(),this.resize()}showScreen(){this._scene.add(this._screen),this._displayOverlay.visible=!0,this._sceneDirty=!0}hideScreen(){this._scene.remove(this._screen),this._displayOverlay.visible=!1,this._sceneDirty=!0}dispose(){this.hideScreen();for(const e of this._windows)this._screen.remove(e.mesh),e.dispose();this._clearElements(),this._filter&&this._filter.dispose(),this._renderer.dispose(),this._disposed=!0}animate(){this._disposed||(requestAnimationFrame(()=>{this.animate()}),this._displayOverlay.update(),this.render())}render(){this._filter?this._filter.render(this._scene,this._camera,this._sceneDirty):this._sceneDirty&&this._renderer.render(this._scene,this._camera),this._sceneDirty=!1}async createScreenshot(e,t){if(this._renderer instanceof w)return this._renderer.createScreenshot(e,t);{const s=this._renderer;return new Promise((i,n)=>{try{this.render(),s.domElement.toBlob(e=>{i(e)},e,t)}catch(e){n(e)}})}}addWindow(e){null==this._windows.find(t=>t.id===e.id)&&(this._windows.push(e),this._screen.add(e.mesh),this._sceneDirty=!0)}removeWindow(e){null!=this._windows.find(t=>t.id===e.id)&&(this._windows=this._windows.filter(t=>t.id!==e.id),e.dispose(),this._screen.remove(e.mesh),this._sceneDirty=!0)}updateWindows(e){return new Promise(t=>{this._windows.filter(t=>null==e.find(e=>e.id===t.id)).forEach(e=>this.removeWindow(e));let s=!1;e.forEach((i,n)=>{let r=this.getWindow(i.id);null==r?(s=!0,r=new p({id:i.id,x:i.x,y:i.y,z:n,width:i.width,height:i.height,shaped:i.shaped&&!this._disableStencil},this._windowImageFactory),this.addWindow(r),r.loadWindowImageAndShape().then(()=>{this.checkAllLoaded(e.map(e=>e.id))&&t()})):(r.shaped=i.shaped&&!this._disableStencil,r.setRectangle(i.x,i.y,n,i.width,i.height))}),s||t()})}checkAllLoaded(e){return e.map(e=>this.getWindow(e)).filter(e=>null!=e).map(e=>e.loaded).reduce((e,t)=>e&&t,!0)}updateImage(e,t,s,i){const n=this.getWindow(e);null==n||null==s&&null==i||(n.updateTexture(t,u(s),u(i),!0),this._sceneDirty=!0)}updateSubImages(e,t){const s=this.getWindow(e);if(null!=s&&s.colorMapValid){const e=s.colorMap,n=s.alphaMap;for(let r=0;r<t.length;r++){const a=t[r];this._renderer instanceof w?this._renderer.updateWindowRegion(s.mesh.id,u(a.colorMap),e,u(a.alphaMap),n,a.width,a.height,new i.Vector2(a.x,a.y)):(e&&a.colorMap&&this._renderer.copyTextureToTexture(u(a.colorMap),e,null,new i.Vector2(a.x,a.y)),n&&a.alphaMap&&this._renderer.copyTextureToTexture(u(a.alphaMap),n,null,new i.Vector2(a.x,a.y)))}s.updateTexture(s.depth,e,n,!1),this._sceneDirty=!0}}updateShape(e,t){if(this._disableStencil)return;const s=this.getWindow(e);null!=s&&null!=t&&(s.updateStencilTexture(u(t)),this._sceneDirty=!0)}setMouseCursor(e){this._cursor.setCursorId(e)}setMousePosition(e,t){this._cursor.setPosition(e,t)}getWindow(e){return this._windows.find(t=>t.id===e)}setScale(e){this._scale=e,this._sceneDirty=!0}autoScale(){const e=this._containerElement,{clientWidth:t,clientHeight:s}=e,{screenWidth:i,screenHeight:n}=this;this._scale=Math.min(t/i,s/n),this._sceneDirty=!0}resize(e){const t=this._boundsElement;e?this.setScale(e):this.autoScale(),t.style.transform=`scale(${this._scale},${this._scale})`}_clearElements(){for(;this._containerElement.firstChild;)this._containerElement.removeChild(this._containerElement.firstChild)}_createDisplayElement(){const e=document.createElement("div");return e.style.width=`${this._screenWidth}px`,e.style.height=`${this._screenHeight}px`,e.appendChild(this._displayOverlay.overlayElement),e.appendChild(this._renderer.domElement),e}_createDisplayBoundingElement(){const e=document.createElement("div");return e.appendChild(this._displayElement),e}_render(){this._clearElements(),this._displayElement=this._createDisplayElement(),this._boundsElement=this._createDisplayBoundingElement(),this._containerElement.appendChild(this._boundsElement)}_bindListeners(){this.resize=this.resize.bind(this)}_detectWebGL2(){const e=document.createElement("canvas").getContext("webgl2");if(!e)return{available:!1};const t=e.getParameter(e.RENDERER),s=e.getParameter(e.VENDOR);let i=null,n=null;const r=e.getExtension("WEBGL_debug_renderer_info");r&&(i=e.getParameter(r.UNMASKED_RENDERER_WEBGL),n=e.getParameter(r.UNMASKED_VENDOR_WEBGL));const a=(i||t||"").toLowerCase();return{available:!0,vendor:n||s,renderer:i||t,isSoftware:/swiftshader|llvmpipe|basic render|software/i.test(a)}}_getFilterParams(){return{backgroundColor:this._options.backgroundColor||window.getComputedStyle(this._containerElement).backgroundColor,...this._options.filter?"string"==typeof this._options.filter?{}:this._options.filter.params:{}}}}var z,P=P||{};P.Keyboard=function(e){var t=this,s="_GUAC_KEYBOARD_HANDLED_BY_"+P.Keyboard._nextID++;this.onkeydown=null,this.onkeyup=null;var i={keyupUnreliable:!1,altIsTypableOnly:!1,capsLockKeyupUnreliable:!1};navigator&&navigator.platform&&(navigator.platform.match(/ipad|iphone|ipod/i)?i.keyupUnreliable=!0:navigator.platform.match(/^mac/i)&&(i.altIsTypableOnly=!0,i.capsLockKeyupUnreliable=!0));var n=function(e){var t=this;this.keyCode=e?e.which||e.keyCode:0,this.keyIdentifier=e&&e.keyIdentifier,this.key=e&&e.key,this.location=e?v(e):0,this.modifiers=e?P.Keyboard.ModifierState.fromKeyboardEvent(e):new P.Keyboard.ModifierState,this.timestamp=(new Date).getTime(),this.defaultPrevented=!1,this.keysym=null,this.reliable=!1,this.getAge=function(){return(new Date).getTime()-t.timestamp}},r=function(e){n.call(this,e),this.keysym=f(this.key,this.location)||w(this.keyCode,this.location),this.keyupReliable=!i.keyupUnreliable,this.keysym&&!b(this.keysym)&&(this.reliable=!0),!this.keysym&&W(this.keyCode,this.keyIdentifier)&&(this.keysym=f(this.keyIdentifier,this.location,this.modifiers.shift)),(this.modifiers.meta&&65511!==this.keysym&&65512!==this.keysym||65509===this.keysym&&i.capsLockKeyupUnreliable)&&(this.keyupReliable=!1);var t=!this.modifiers.ctrl&&!i.altIsTypableOnly;!i.altIsTypableOnly||65513!==this.keysym&&65514!==this.keysym||(this.keysym=65027),(!this.modifiers.alt&&this.modifiers.ctrl||t&&this.modifiers.alt||this.modifiers.meta||this.modifiers.hyper)&&(this.reliable=!0),m[this.keyCode]=this.keysym};r.prototype=new n;var a=function(e){n.call(this,e),this.keysym=M(this.keyCode),this.reliable=!0};a.prototype=new n;var o=function(e){n.call(this,e),this.keysym=w(this.keyCode,this.location)||f(this.key,this.location),t.pressed[this.keysym]||(this.keysym=m[this.keyCode]||this.keysym),this.reliable=!0};o.prototype=new n;var h=[],l={8:[65288],9:[65289],12:[65291,65291,65291,65461],13:[65293],16:[65505,65505,65506],17:[65507,65507,65508],18:[65513,65513,65514],19:[65299],20:[65509],27:[65307],32:[32],33:[65365,65365,65365,65465],34:[65366,65366,65366,65459],35:[65367,65367,65367,65457],36:[65360,65360,65360,65463],37:[65361,65361,65361,65460],38:[65362,65362,65362,65464],39:[65363,65363,65363,65462],40:[65364,65364,65364,65458],45:[65379,65379,65379,65456],46:[65535,65535,65535,65454],91:[65511],92:[65512],93:[65383],96:[65456],97:[65457],98:[65458],99:[65459],100:[65460],101:[65461],102:[65462],103:[65463],104:[65464],105:[65465],106:[65450],107:[65451],109:[65453],110:[65454],111:[65455],112:[65470],113:[65471],114:[65472],115:[65473],116:[65474],117:[65475],118:[65476],119:[65477],120:[65478],121:[65479],122:[65480],123:[65481],144:[65407],145:[65300],225:[65027]},c={Again:[65382],AllCandidates:[65341],Alphanumeric:[65328],Alt:[65513,65513,65514],Attn:[64782],AltGraph:[65027],ArrowDown:[65364],ArrowLeft:[65361],ArrowRight:[65363],ArrowUp:[65362],Backspace:[65288],CapsLock:[65509],Cancel:[65385],Clear:[65291],Convert:[65315],Copy:[64789],Crsel:[64796],CrSel:[64796],CodeInput:[65335],Compose:[65312],Control:[65507,65507,65508],ContextMenu:[65383],Delete:[65535],Down:[65364],End:[65367],Enter:[65293],EraseEof:[64774],Escape:[65307],Execute:[65378],Exsel:[64797],ExSel:[64797],F1:[65470],F2:[65471],F3:[65472],F4:[65473],F5:[65474],F6:[65475],F7:[65476],F8:[65477],F9:[65478],F10:[65479],F11:[65480],F12:[65481],F13:[65482],F14:[65483],F15:[65484],F16:[65485],F17:[65486],F18:[65487],F19:[65488],F20:[65489],F21:[65490],F22:[65491],F23:[65492],F24:[65493],Find:[65384],GroupFirst:[65036],GroupLast:[65038],GroupNext:[65032],GroupPrevious:[65034],FullWidth:null,HalfWidth:null,HangulMode:[65329],Hankaku:[65321],HanjaMode:[65332],Help:[65386],Hiragana:[65317],HiraganaKatakana:[65319],Home:[65360],Hyper:[65517,65517,65518],Insert:[65379],JapaneseHiragana:[65317],JapaneseKatakana:[65318],JapaneseRomaji:[65316],JunjaMode:[65336],KanaMode:[65325],KanjiMode:[65313],Katakana:[65318],Left:[65361],Meta:[65511,65511,65512],ModeChange:[65406],NonConvert:[65314],NumLock:[65407],PageDown:[65366],PageUp:[65365],Pause:[65299],Play:[64790],PreviousCandidate:[65342],PrintScreen:[65377],Redo:[65382],Right:[65363],Romaji:[65316],RomanCharacters:null,Scroll:[65300],Select:[65376],Separator:[65452],Shift:[65505,65505,65506],SingleCandidate:[65340],Super:[65515,65515,65516],Tab:[65289],UIKeyInputDownArrow:[65364],UIKeyInputEscape:[65307],UIKeyInputLeftArrow:[65361],UIKeyInputRightArrow:[65363],UIKeyInputUpArrow:[65362],Up:[65362],Undo:[65381],Win:[65511,65511,65512],Zenkaku:[65320],ZenkakuHankaku:[65322]},d={65027:!0,65505:!0,65506:!0,65507:!0,65508:!0,65509:!0,65511:!0,65512:!0,65513:!0,65514:!0,65515:!0,65516:!0};this.modifiers=new P.Keyboard.ModifierState,this.pressed={};var u={},p={},m={},y=null,_=null,g=function(e,t){return e?e[t]||e[0]:null},b=function(e){return e>=0&&e<=255||16777216==(4294901760&e)};function f(e,t,s){if(!e)return null;var i,n=e.indexOf("U+");if(n>=0){var r=e.substring(n+2);i=String.fromCharCode(parseInt(r,16))}else{if(1!==e.length||3===t)return g(c[e],t);i=e}return!0===s?i=i.toUpperCase():!1===s&&(i=i.toLowerCase()),M(i.charCodeAt(0))}function M(e){return function(e){return e<=31||e>=127&&e<=159}(e)?65280|e:e>=0&&e<=255?e:e>=256&&e<=1114111?16777216|e:null}function w(e,t){return g(l[e],t)}var W=function(e,t){if(!t)return!1;var s=t.indexOf("U+");return-1===s||(e!==parseInt(t.substring(s+2),16)||(e>=65&&e<=90||e>=48&&e<=57))};this.press=function(e){if(null!==e){if(!t.pressed[e]&&(t.pressed[e]=!0,t.onkeydown)){var s=t.onkeydown(e);return p[e]=s,window.clearTimeout(y),window.clearInterval(_),d[e]||(y=window.setTimeout(function(){_=window.setInterval(function(){t.onkeyup(e),t.onkeydown(e)},50)},500)),s}return p[e]||!1}},this.release=function(e){t.pressed[e]&&(delete t.pressed[e],delete u[e],window.clearTimeout(y),window.clearInterval(_),null!==e&&t.onkeyup&&t.onkeyup(e))},this.type=function(e){for(var s=0;s<e.length;s++){var i=M(e.codePointAt?e.codePointAt(s):e.charCodeAt(s));t.press(i),t.release(i)}},this.reset=function(){for(var e in t.pressed)t.release(parseInt(e));h=[]};var I=function(e,s,i){var n,r=i.modifiers[e],a=t.modifiers[e];if(-1===s.indexOf(i.keysym))if(a&&!1===r)for(n=0;n<s.length;n++)t.release(s[n]);else if(!a&&r){for(n=0;n<s.length;n++)if(t.pressed[s[n]])return;var o=s[0];i.keysym&&(u[o]=!0),t.press(o)}},x=function(e){I("alt",[65513,65514,65027],e),I("shift",[65505,65506],e),I("ctrl",[65507,65508],e),I("meta",[65511,65512],e),I("hyper",[65515,65516],e),t.modifiers=e.modifiers};function Z(){var e,s=S();if(!s)return!1;do{e=s,s=S()}while(null!==s);return function(){for(var e in t.pressed)if(!u[e])return!1;return!0}()&&t.reset(),e.defaultPrevented}var S=function(){var e=h[0];if(!e)return null;if(!(e instanceof r))return e instanceof o&&!i.keyupUnreliable?(s=e.keysym)?(t.release(s),delete m[e.keyCode],e.defaultPrevented=!0,x(e),h.shift()):(t.reset(),e):h.shift();var s=null,n=[];if(65511===e.keysym||65512===e.keysym){if(1===h.length)return null;if(h[1].keysym!==e.keysym){if(!h[1].modifiers.meta)return h.shift()}else if(h[1]instanceof r)return h.shift()}if(e.reliable?(s=e.keysym,n=h.splice(0,1)):h[1]instanceof a?(s=h[1].keysym,n=h.splice(0,2)):h[1]&&(s=e.keysym,n=h.splice(0,1)),n.length>0){if(x(e),s){!function(e){t.modifiers.ctrl&&t.modifiers.alt&&(e>=65&&e<=90||e>=97&&e<=122||(e<=255||16777216==(4278190080&e))&&(t.release(65507),t.release(65508),t.release(65513),t.release(65514)))}(s);var l=!t.press(s);m[e.keyCode]=s,e.keyupReliable||t.release(s);for(var c=0;c<n.length;c++)n[c].defaultPrevented=l}return e}return null},v=function(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0},X=function(e){return!e[s]&&(e[s]=!0,!0)},U=function(e){if(t.onkeydown&&X(e)){var s=new r(e);e.isComposing||229===s.keyCode||(h.push(s),Z()&&e.preventDefault())}},G=function(e){(t.onkeydown||t.onkeyup)&&X(e)&&(h.push(new a(e)),Z()&&e.preventDefault())},R=function(e){t.onkeyup&&X(e)&&(e.preventDefault(),h.push(new o(e)),Z())},C=function(e){(t.onkeydown||t.onkeyup)&&X(e)&&e.data&&!e.isComposing&&t.type(e.data)},T=function(t){e.removeEventListener("input",C,!1)},V=function(e){(t.onkeydown||t.onkeyup)&&X(e)&&e.data&&t.type(e.data)};this.listenTo=function(e){e.addEventListener("keydown",U,{passive:!1}),e.addEventListener("keypress",G,{passive:!1}),e.addEventListener("keyup",R,{passive:!1}),e.addEventListener("input",C,!1),e.addEventListener("compositionend",V,!1),e.addEventListener("compositionstart",T,!1)},e&&t.listenTo(e),this.dispose=function(){e&&(e.removeEventListener("keydown",U,!0),e.removeEventListener("keypress",G,!0),e.removeEventListener("keyup",R,!0),e.removeEventListener("input",C,!1),e.removeEventListener("compositionend",V,!1),e.removeEventListener("compositionstart",T,!1))}},P.Keyboard._nextID=0,P.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},P.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new P.Keyboard.ModifierState;return t.shift=e.shiftKey,t.ctrl=e.ctrlKey,t.alt=e.altKey,t.meta=e.metaKey,e.getModifierState&&(t.hyper=e.getModifierState("OS")||e.getModifierState("Super")||e.getModifierState("Hyper")||e.getModifierState("Win")),t};class A{set onKeyDown(e){this._keyboard.onkeydown=e}set onKeyUp(e){this._keyboard.onkeyup=e}constructor(e){this._keyboard=new P.Keyboard(e)}dispose(){this._keyboard.onkeydown=null,this._keyboard.onkeyup=null,this._keyboard.dispose()}reset(){this._keyboard.reset()}}class O{get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}get left(){return this._left}set left(e){this._left=e}get middle(){return this._middle}set middle(e){this._middle=e}get right(){return this._right}set right(e){this._right=e}get up(){return this._up}set up(e){this._up=e}get down(){return this._down}set down(e){this._down=e}get shift(){return this._shift}set shift(e){this._shift=e}get ctrl(){return this._ctrl}set ctrl(e){this._ctrl=e}get alt(){return this._alt}set alt(e){this._alt=e}constructor(e){const{x:t,y:s,left:i,middle:n,right:r,up:a,down:o}=e;this._x=t,this._y=s,this._left=i,this._middle=n,this._right=r,this._up=a,this._down=o}releaseButtons(){this._left=!1,this._middle=!1,this._right=!1}getButtonMask(){let e=0;return e|=this._left?256:0,e|=this._middle?512:0,e|=this._right?1024:0,e|=this._up?2048:0,e|=this._down?4096:0,e|=this._shift?1:0,e|=this._ctrl?4:0,e|=this._alt?8:0,e}clone(){return new O({x:this._x,y:this._y,left:this._left,middle:this._middle,right:this._right,up:this._up,down:this._down})}}class K{constructor(e){this._element=e,this._contextMenuHandler=this._handleContextMenu.bind(this),this._mouseMoveHandler=this._handleMouseMove.bind(this),this._mouseDownHandler=this._handleMouseDown.bind(this),this._mouseUpHandler=this._handleMouseUp.bind(this),this._mouseOutHandler=this._handleMouseOut.bind(this),this._mouseWheelHandler=this._handleMouseWheel.bind(this),this._bindListeners(),this._createDefaultState()}dispose(){this._unbindListeners()}_cancelEvent(e){e.stopPropagation(),e.preventDefault&&e.preventDefault(),e.returnValue=!1}_bindListeners(){const e=this._element;e.addEventListener("contextmenu",this._contextMenuHandler,!1),e.addEventListener("mousemove",this._mouseMoveHandler),e.addEventListener("mousedown",this._mouseDownHandler),e.addEventListener("mouseup",this._mouseUpHandler),e.addEventListener("mouseout",this._mouseOutHandler),["DOMMouseScroll","mousewheel","wheel"].forEach(t=>{e.addEventListener(t,this._mouseWheelHandler,{passive:!1})}),this.reset=this.reset.bind(this)}_unbindListeners(){const e=this._element;e.removeEventListener("contextmenu",this._contextMenuHandler,!1),e.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseout",this._mouseOutHandler),["DOMMouseScroll","mousewheel","wheel"].forEach(t=>{e.removeEventListener(t,this._mouseWheelHandler)}),this.reset=this.reset.bind(this)}_createDefaultState(){this._currentState=new O({x:0,y:0,left:!1,middle:!1,right:!1,up:!1,down:!1})}_handleMouseUp(e){switch(e.button){case 0:this._currentState.left=!1;break;case 1:this._currentState.middle=!1;break;case 2:this._currentState.right=!1}this._notifyMouseUp()}_handleMouseDown(e){switch(this._cancelEvent(e),e.button){case 0:this._currentState.left=!0;break;case 1:this._currentState.middle=!0;break;case 2:this._currentState.right=!0}this._notifyMouseDown()}_handleMouseWheel(e){e.deltaY<0&&(this._currentState.up=!0,this._notifyMouseDown(),this._currentState.up=!1,this._notifyMouseUp()),e.deltaY>0&&(this._currentState.down=!0,this._notifyMouseDown(),this._currentState.down=!1,this._notifyMouseUp()),this._cancelEvent(e)}_handleMouseOut(){this._currentState.releaseButtons(),this._notifyMouseOut()}_handleMouseMove(e){this._cancelEvent(e);const t=this._element.firstElementChild.getBoundingClientRect();this._currentState.x=e.clientX-t.left,this._currentState.y=e.clientY-t.top,this._notifyMouseMove()}reset(){this._currentState.releaseButtons()}_handleContextMenu(e){this._cancelEvent(e)}_notifyMouseMove(){this.onMouseMove(this._currentState.clone())}_notifyMouseUp(){this.onMouseUp(this._currentState.clone())}_notifyMouseDown(){this.onMouseDown(this._currentState.clone())}_notifyMouseOut(){this.onMouseOut(this._currentState.clone())}onMouseMove(e){}onMouseDown(e){}onMouseUp(e){}onMouseOut(e){}}class J{constructor(e){this.synchronous=!1,this.id=J._INSTRUCTION_COUNTER++,this.type=e}}J._INSTRUCTION_COUNTER=1;class B{constructor(e,t){this._timeoutId=0,this.instructionId=e.id,this.data=null,t&&(this._timeoutMs=t,this._timeoutId=setTimeout(()=>{this.reject("Request failed due to timeout")},this._timeoutMs))}then(e){return this._onResponseReceived=e,this}catch(e){return this._onError=e,this}resolve(e){this._timeoutId>0&&clearTimeout(this._timeoutId),null!=this._onResponseReceived&&this._onResponseReceived(e)}reject(e){this._onError&&this._onError(new Error(e))}}exports.WebXInstructionType=void 0,(z=exports.WebXInstructionType||(exports.WebXInstructionType={}))[z.CONNECT=1]="CONNECT",z[z.WINDOWS=2]="WINDOWS",z[z.IMAGE=3]="IMAGE",z[z.SCREEN=4]="SCREEN",z[z.MOUSE=5]="MOUSE",z[z.KEYBOARD=6]="KEYBOARD",z[z.CURSOR_IMAGE=7]="CURSOR_IMAGE",z[z.QUALITY=8]="QUALITY",z[z.PONG=9]="PONG",z[z.DATA_ACK=10]="DATA_ACK",z[z.CLIPBOARD=11]="CLIPBOARD",z[z.SHAPE=12]="SHAPE",function(e){e.fromString=function(t){switch(t){case"CONNECT":return e.CONNECT;case"WINDOWS":return e.WINDOWS;case"IMAGE":return e.IMAGE;case"SCREEN":return e.SCREEN;case"MOUSE":return e.MOUSE;case"KEYBOARD":return e.KEYBOARD;case"CURSOR_IMAGE":return e.CURSOR_IMAGE;case"QUALITY":return e.QUALITY;case"PONG":return e.PONG;case"DATA_ACK":return e.DATA_ACK;case"CLIPBOARD":return e.CLIPBOARD;case"SHAPE":return e.SHAPE}}}(exports.WebXInstructionType||(exports.WebXInstructionType={}));class Q extends J{constructor(){super(exports.WebXInstructionType.SCREEN)}}class j extends J{constructor(){super(exports.WebXInstructionType.WINDOWS)}}class $ extends J{constructor(e){super(exports.WebXInstructionType.IMAGE),this.windowId=e}}class q extends J{constructor(e,t,s){super(exports.WebXInstructionType.MOUSE),this.x=e,this.y=t,this.buttonMask=s}}class ee extends J{constructor(e,t){super(exports.WebXInstructionType.KEYBOARD),this.key=e,this.pressed=t}}class te extends J{constructor(e){super(exports.WebXInstructionType.CURSOR_IMAGE),this.cursorId=e}}class se extends J{constructor(e){super(exports.WebXInstructionType.QUALITY),this.qualityIndex=e}}class ie extends J{constructor(e){super(exports.WebXInstructionType.PONG),this.timestampMs=e}}class ne extends J{constructor(e,t){super(exports.WebXInstructionType.DATA_ACK),this.timestampMs=e,this.dataLength=t}}class re extends J{constructor(e){super(exports.WebXInstructionType.CLIPBOARD),this.clipboardContent=e}}class ae extends J{constructor(e){super(exports.WebXInstructionType.SHAPE),this.windowId=e}}class oe{}class he{}class le{}class ce{static randomColour(){const e=Math.floor(Math.random()*ce._COLOURS.length);return ce._COLOURS[e]}static indexedColour(e){return e%=ce._COLOURS.length,ce._COLOURS[e]}}ce._COLOURS=["#FF6633","#FFB399","#FF33FF","#FFFF99","#00B3E6","#E6B333","#3366E6","#999966","#99FF99","#B34D4D","#80B300","#809900","#E6B3B3","#6680B3","#66991A","#FF99E6","#CCFF1A","#FF1A66","#E6331A","#33FFCC","#66994D","#B366CC","#4D8000","#B33300","#CC80CC","#66664D","#991AFF","#E666FF","#4DB3FF","#1AB399","#E666B3","#33991A","#CC9999","#B3B31A","#00E680","#4D8066","#809980","#E6FF80","#1AFF33","#999933","#FF3380","#CCCC00","#66E64D","#4D80CC","#9900B3","#E64D66","#4DB380","#FF4D4D","#99E6E6","#6666FF"];class de{constructor(e=0,t=0,s=0){this.major=e,this.minor=t,this.patch=s,this.version=`${e}.${t}.${s}`,this.versionNumber=parseFloat(`${e}.${t}`)}}class ue extends he{constructor(s){super(),this._display=s,this._debugLayer=new e.Object3D,this._currentZ=0,this._disposed=!1,this._tweenGroup=new t.Group,this._debugLayer.position.set(0,0,999),this._scene=this._display.scene,this._scene.add(this._debugLayer),this._animate()}_createMesh(s,i,n,r,a){const o=new e.MeshBasicMaterial({color:a,opacity:.8,transparent:!0});o.side=e.BackSide;const h=new e.Mesh(ue._PLANE_GEOMETRY,o);h.position.set(s+n/2,i+r/2,this._currentZ),h.scale.set(n,r,1),this._currentZ+=1e-4,this._debugLayer.add(h),new t.Tween(o,this._tweenGroup).to({opacity:0},500).easing(t.Easing.Quadratic.Out).onComplete(()=>this._debugLayer.remove(h)).onUpdate(()=>this._display.sceneDirty=!0).start()}handle(e){if(e.type===exports.WebXMessageType.IMAGE){const t=e,s=this._display.getWindow(t.windowId),{width:i,height:n}=t.colorMap.image;this._createMesh(s.x,s.y,i,n,ce.indexedColour(s.colorIndex))}else if(e.type===exports.WebXMessageType.SUBIMAGES){const t=e,s=this._display.getWindow(t.windowId);t.subImages.forEach(e=>{this._createMesh(s.x+e.x,s.y+e.y,e.width,e.height,ce.indexedColour(s.colorIndex))})}}destroy(){this._disposed=!0,this._debugLayer.children.forEach(e=>{e.material.dispose()}),this._debugLayer.clear(),this._debugLayer.removeFromParent()}_animate(){this._disposed||requestAnimationFrame(e=>{this._tweenGroup.update(e),this._animate()})}}ue._PLANE_GEOMETRY=new e.PlaneGeometry(1,1,2,2);class pe{constructor(e,t){this._buffer=new ArrayBuffer(t+32),this._offset=20,e.synchronous?this.putUInt32(2147483648|e.type):this.putUInt32(e.type),this.putUInt32(e.id),this.putUInt32(0)}_getNextOffset(e){const t=this._offset%e>0?e-this._offset%e:0,s=this._offset+t;return this._offset+=e+t,s}putInt32(e){const t=this._getNextOffset(4);return new Int32Array(this._buffer,t,1)[0]=e,this}putUInt8(e){const t=this._getNextOffset(1);return new Uint8Array(this._buffer,t,1)[0]=e,this}putUInt32(e){const t=this._getNextOffset(4);return new Uint32Array(this._buffer,t,1)[0]=e,this}putUInt8Array(e,t){const s=this._getNextOffset(8);return new Uint8Array(this._buffer,s,t).set(e),this}putString(e){for(let t=0;t<e.length;t++)this.putUInt8(e.charCodeAt(t));return this}putBoolean(e){return this.putUInt32(!0===e?255:0),this}buffer(){return this._buffer}}class me{get readOffset(){return this._readOffset}get buffer(){return this._buffer}constructor(e){this._buffer=e,this._readOffset=24,this._encoder=new TextDecoder("utf-8"),this._readOffset=24,this.timestampMs=this.getUint8Array(8),this.messageTypeId=this.getUint32(),this.messageId=this.getUint32(),this.bufferLength=this.getUint32(),this._readOffset=me.MESSAGE_HEADER_LENGTH}getInt32(){const e=this._getNextReadOffset(4);return new Int32Array(this._buffer,e,1)[0]}getUint32(){const e=this._getNextReadOffset(4);return new Uint32Array(this._buffer,e,1)[0]}getFloat(){const e=this._getNextReadOffset(4);return new Float32Array(this._buffer,e,1)[0]}getUint8Array(e){const t=new Uint8Array(this._buffer,this._readOffset,e);return this._readOffset+=e,t}getString(e){const t=new Uint8Array(this._buffer,this._readOffset,e);return this._readOffset+=e,this._encoder.decode(t)}_getNextReadOffset(e){const t=this._readOffset%e>0?e-this._readOffset%e:0,s=this._readOffset+t;return this._readOffset+=e+t,s}}me.MESSAGE_HEADER_LENGTH=48;class ye{encode(e){return e.type===exports.WebXInstructionType.MOUSE?this._createMouseInstruction(e):e.type===exports.WebXInstructionType.KEYBOARD?this._createKeyboardInstruction(e):e.type===exports.WebXInstructionType.CURSOR_IMAGE?this._createCursorImageInstruction(e):e.type===exports.WebXInstructionType.IMAGE?this._createImageInstruction(e):e.type===exports.WebXInstructionType.CONNECT?this._createConnectInstruction(e):e.type===exports.WebXInstructionType.SCREEN?this._createScreenInstruction(e):e.type===exports.WebXInstructionType.WINDOWS?this._createWindowsInstruction(e):e.type===exports.WebXInstructionType.QUALITY?this._createQualityInstruction(e):e.type===exports.WebXInstructionType.PONG?this._createPongInstruction(e):e.type===exports.WebXInstructionType.DATA_ACK?this._createDataAckInstruction(e):e.type===exports.WebXInstructionType.CLIPBOARD?this._createClipboardInstruction(e):e.type===exports.WebXInstructionType.SHAPE?this._createShapeInstruction(e):null}_createMouseInstruction(e){return new pe(e,12).putInt32(e.x).putInt32(e.y).putUInt32(e.buttonMask).buffer()}_createCursorImageInstruction(e){return new pe(e,4).putInt32(e.cursorId).buffer()}_createImageInstruction(e){return new pe(e,4).putUInt32(e.windowId).buffer()}_createKeyboardInstruction(e){return new pe(e,8).putUInt32(e.key).putBoolean(e.pressed).buffer()}_createScreenInstruction(e){return new pe(e,0).buffer()}_createWindowsInstruction(e){return new pe(e,0).buffer()}_createConnectInstruction(e){return new pe(e,0).buffer()}_createQualityInstruction(e){return new pe(e,4).putUInt32(e.qualityIndex).buffer()}_createPongInstruction(e){return new pe(e,8).putUInt8Array(e.timestampMs,8).buffer()}_createDataAckInstruction(e){return new pe(e,12).putUInt8Array(e.timestampMs,8).putUInt32(e.dataLength).buffer()}_createClipboardInstruction(e){const t=4+e.clipboardContent.length;return new pe(e,t).putUInt32(e.clipboardContent.length).putString(e.clipboardContent).buffer()}_createShapeInstruction(e){return new pe(e,4).putUInt32(e.windowId).buffer()}}class _e{constructor(){this._textureFactory=new d}decode(e){const{messageTypeId:t}=e;return t===exports.WebXMessageType.NOP?this._createNopMessage():t===exports.WebXMessageType.CONNECTION?this._createConnectionMessage(e):t===exports.WebXMessageType.SCREEN?this._createScreenMessage(e):t===exports.WebXMessageType.WINDOWS?this._createWindowsMessage(e):t===exports.WebXMessageType.IMAGE?this._createImageMessage(e):t===exports.WebXMessageType.SUBIMAGES?this._createSubImagesMessage(e):t===exports.WebXMessageType.MOUSE?this._createMouseMessage(e):t===exports.WebXMessageType.CURSOR_IMAGE?this._createCursorImageMessage(e):t===exports.WebXMessageType.PING?this._createPingMessage():t===exports.WebXMessageType.QUALITY?this._createQualityMessage(e):t===exports.WebXMessageType.CLIPBOARD?this._createClipboardMessage(e):t===exports.WebXMessageType.SHAPE?this._createShapeMessage(e):void console.error(`Failed to decode message with typeId ${t}`)}_determineMimeType(e){return"jpg"===e.substr(0,3)?"image/jpeg":"png"===e.substr(0,3)?"image/png":"image/bmp"}async _createNopMessage(){return new V}async _createConnectionMessage(e){const t=e.getUint32();return new T(t>0)}_createImageMessage(e){return new Promise(t=>{const s=e.getUint32(),i=e.getUint32(),n=e.getUint32(),r=e.getString(4),a=this._determineMimeType(r),o=e.getUint32(),h=e.getUint32(),l=e.getUint8Array(o),c=e.getUint8Array(h),d=this._textureFactory.createTextureFromArray(l,a),u=this._textureFactory.createTextureFromArray(c,a);Promise.all([d,u]).then(([r,a])=>{t(new S(i,n,r,a,s,e.bufferLength))})})}_createSubImagesMessage(e){return new Promise(t=>{const s=e.getUint32(),i=e.getUint32(),n=new Array,a=e.getUint32();for(let t=0;t<a;t++){const t=e.getInt32(),s=e.getInt32(),i=e.getInt32(),a=e.getInt32(),o=e.getUint32(),h=e.getString(4),l=this._determineMimeType(h),c=e.getUint32(),d=e.getUint32(),u=e.getUint8Array(c),p=e.getUint8Array(d),m=new Promise((e,n)=>{const h=this._textureFactory.createTextureFromArray(u,l),c=this._textureFactory.createTextureFromArray(p,l);Promise.all([h,c]).then(([n,h])=>{e(new r({x:t,y:s,width:i,height:a,depth:o,colorMap:n,alphaMap:h}))}).catch(n)});n.push(m)}Promise.all(n).then(n=>{t(new v(i,n,s,e.bufferLength))})})}async _createMouseMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32(),n=e.getUint32();return new X(s,i,n,t)}async _createWindowsMessage(e){const t=e.getUint32(),s=e.getUint32(),i=new Array;for(let t=0;t<s;t++){const t=e.getUint32(),s=e.getInt32(),n=e.getInt32(),r=e.getInt32(),a=e.getInt32();i.push({id:t,x:s,y:n,width:r,height:a,shaped:!1})}if(l.version.versionNumber>=1.4&&e.bufferLength-e.readOffset>=4){const t=e.getUint32();for(let s=0;s<t;s++){const t=e.getUint32();i.find(e=>e.id===t).shaped=!0}}return new Z(i.map(e=>new n(e)),t)}async _createCursorImageMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32(),n=e.getInt32(),r=e.getInt32(),a=e.getUint32(),o=e.getUint32(),h=e.getUint8Array(o);try{const e=await this._textureFactory.createTextureFromArray(h,"image/png");return new U(s,i,n,r,a,e,t)}catch(e){console.error(`Failed to get texture for cursor image: ${e}`)}}async _createScreenMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32();let n=10;e.bufferLength-e.readOffset>=4&&(n=e.getInt32());let r=0,a=0,o=0;return e.bufferLength-e.readOffset>=12&&(r=e.getUint32(),a=e.getUint32(),o=e.getUint32()),l.version=new de(r,a,o),new x({width:s,height:i},n,new de(r,a,o),t)}async _createPingMessage(){return new G}async _createQualityMessage(e){const t=e.getUint32(),s=e.getFloat(),i=e.getFloat(),n=e.getFloat(),r=e.getFloat();return new R(t,s,i,n,r)}async _createClipboardMessage(e){const t=e.getUint32(),s=e.getString(t);return new C(s)}_createShapeMessage(e){return new Promise(t=>{const s=e.getUint32(),i=e.getUint32(),n=e.getString(4),r=this._determineMimeType(n),a=e.getUint32(),o=e.getUint8Array(a);this._textureFactory.createTextureFromArray(o,r).then(n=>{t(new E(i,n,s,e.bufferLength))})})}}var ge,be=g("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZXtjb25zdHJ1Y3RvcihlLHQ9MCl7dGhpcy50eXBlPWUsdGhpcy5jb21tYW5kSWQ9dH1zdGF0aWMgZ2V0IGNvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyKCl7cmV0dXJuIGUuX2NvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyfXN0YXRpYyBzZXQgY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXIodCl7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9dH19dmFyIHQ7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW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2h0LHI9bmV3IE9mZnNjcmVlbkNhbnZhcyh0LHMpLmdldENvbnRleHQoIjJkIix7d2lsbFJlYWRGcmVxdWVudGx5OiEwfSk7cmV0dXJuIHIuZHJhd0ltYWdlKGUsMCwwKSxyLmdldEltYWdlRGF0YSgwLDAsdCxzKX1yZXR1cm4gbnVsbH0pKGUuaW1hZ2UpO3JldHVybiBuZXcgbSh7ZGF0YTpyLmRhdGEsd2lkdGg6dCxoZWlnaHQ6c30pfXJldHVybiBudWxsfX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9V2ViWE1lc3NhZ2VEZWNvZGVyV29ya2VyLmpzLm1hcAoK");class fe{constructor(){this._pending=new Map,this._nextId=1,this._instructionEncoder=new ye,this._messageDecoder=new _e,"undefined"!=typeof Worker&&(this._worker=new be,this._worker.onmessage=e=>{const{id:t,message:s,error:i}=e.data,n=this._pending.get(t);if(this._pending.delete(t),i)console.error(i);else if(n){const e=(e=>{let t;return e&&(e.type===exports.WebXMessageType.NOP?t=Object.create(V.prototype):e.type===exports.WebXMessageType.CONNECTION?t=Object.create(T.prototype):e.type===exports.WebXMessageType.SCREEN?t=Object.create(x.prototype):e.type===exports.WebXMessageType.WINDOWS?t=Object.create(Z.prototype):e.type===exports.WebXMessageType.IMAGE?t=Object.create(S.prototype):e.type===exports.WebXMessageType.SUBIMAGES?t=Object.create(v.prototype):e.type===exports.WebXMessageType.MOUSE?t=Object.create(X.prototype):e.type===exports.WebXMessageType.CURSOR_IMAGE?t=Object.create(U.prototype):e.type===exports.WebXMessageType.PING?t=Object.create(G.prototype):e.type===exports.WebXMessageType.QUALITY?t=Object.create(R.prototype):e.type===exports.WebXMessageType.CLIPBOARD?t=Object.create(C.prototype):e.type===exports.WebXMessageType.SHAPE&&(t=Object.create(E.prototype)),t&&Object.assign(t,e)),t})(s);n(e)}})}terminate(){this._worker.terminate(),this._pending.clear()}serializeInstruction(e){const t=this._instructionEncoder.encode(e);return null==t&&console.warn("Could not serialize instruction: Unknown type"),t}async deserializeMessage(e){if(this._worker&&(e=>{switch(e.messageTypeId){case exports.WebXMessageType.IMAGE:case exports.WebXMessageType.SUBIMAGES:case exports.WebXMessageType.SHAPE:return!0;default:return!1}})(e))return new Promise(t=>{const s=this._nextId++;this._pending.set(s,t);const i=[e.buffer];this._worker.postMessage({id:s,buffer:e.buffer,convertToImageData:I.convertToImageDataInWorker},i)});try{const t=await this._messageDecoder.decode(e);return null==t&&console.error("Failed to decode message data"),t}catch(e){console.error(`Caught error decoding message data: ${e.message}`)}}}class Me{constructor(){this._serializer=new fe,this._instructionResponses=new Map}terminate(){this._serializer.terminate()}sendInstruction(e){const t=this._serializer.serializeInstruction(e);this.send(t)}sendRequest(e,t){e.synchronous=!0;const s=new B(e,t=t||1e4);return this._instructionResponses.set(e.id,s),new Promise((t,i)=>{const n=this._serializer.serializeInstruction(e);this.send(n),s.then(t).catch(t=>{this._instructionResponses.delete(e.id),i(t)})})}async onMessage(e){if(0===e.byteLength)return console.warn("Got a zero length message"),null;if(e.byteLength<me.MESSAGE_HEADER_LENGTH)return console.warn("Message does not contain a valid header"),null;const t=new me(e);this._handleCriticalMessages(t),this.handleReceivedBytes(e);const s=await this._serializer.deserializeMessage(t);if(null!=s)if(null!=s.commandId&&null!=this._instructionResponses.get(s.commandId)){const e=this._instructionResponses.get(s.commandId);this._instructionResponses.delete(s.commandId),e.resolve(s)}else this.handleMessage(s)}handleMessage(e){throw new Error("Method not implemented.")}handleReceivedBytes(e){throw new Error("Method not implemented.")}handleSentBytes(e){throw new Error("Method not implemented")}handleClose(e){this._instructionResponses.forEach(e=>{e.reject("Tunnel closed")}),this.onClosed()}onClosed(){console.log("Websocket closed")}_handleCriticalMessages(e){e.messageTypeId==exports.WebXMessageType.PING?this.sendInstruction(new ie(e.timestampMs)):e.messageTypeId!=exports.WebXMessageType.SUBIMAGES&&e.messageTypeId!=exports.WebXMessageType.IMAGE||e.bufferLength>Me.MIN_BUFFER_LENGTH_FOR_ACK&&this.sendInstruction(new ne(e.timestampMs,e.bufferLength))}}Me.MIN_BUFFER_LENGTH_FOR_ACK=32768;class we{constructor(e){this._tunnel=e,this._cursorMap=new Map}async getCursor(e){const t=this._cursorMap.get(e);if(null!=t)return{cursor:t};{const t=await this._tunnel.sendRequest(new te(e)),s={xHot:t.xHot,yHot:t.yHot,cursorId:t.cursorId,texture:t.texture};return this._cursorMap.set(t.cursorId,s),{x:t.x,y:t.y,cursor:s}}}}class We{constructor(e){this._tunnel=e}async getWindowTexture(e){try{const t=await this._tunnel.sendRequest(new $(e));return{depth:t.depth,colorMap:t.colorMap,alphaMap:t.alphaMap}}catch(e){console.warn("Failed to get texture: "+e)}}async getWindowStencilTexture(e){try{return{stencilMap:(await this._tunnel.sendRequest(new ae(e))).stencilMap}}catch(e){return console.warn("Failed to get stencil texture: "+e),null}}}exports.WebXConnectionStatus=void 0,(ge=exports.WebXConnectionStatus||(exports.WebXConnectionStatus={}))[ge.STARTING=0]="STARTING",ge[ge.RUNNING=1]="RUNNING";class Ie{constructor(){this._connected=!1,this._connectionCallback=()=>{},this._connectionError=()=>{},this._connectionStatusCallback=()=>{}}onConnected(e,t){return this._timeoutMs=e||1e4,this._connectionStatusCallback=t,new Promise((e,t)=>{this._connected?e():(this._connectionCallback=()=>{window.clearTimeout(this._timeout),this._timeout=null,e()},this._connectionError=()=>{this._timeout=null,t(new Error("Connection timed out"))},this._createTimer())})}setConnected(e){e?this._connectionStatusCallback(exports.WebXConnectionStatus.STARTING):(this._connected=!0,this._connectionStatusCallback(exports.WebXConnectionStatus.RUNNING),this._connectionCallback())}resetTimer(){this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null,this._createTimer())}dispose(){this._timeout&&window.clearTimeout(this._timeout)}_createTimer(){this._timeout=window.setTimeout(()=>{this._connectionError()},this._timeoutMs)}}const{version:xe}=require("../package.json");exports.WebXClient=class{get tunnel(){return this._tunnel}get tracers(){return this._tracers}get display(){return this._display}get mouse(){return this._mouse}get keyboard(){return this._keyboard}set clipboardHandler(e){this._clipboardHandler=e}get maxQualityIndex(){return this._maxQualityIndex}constructor(e,t){this._tunnel=e,this._options=t,this._tracers=new Map,this._clipboardHandler=e=>{},this._connectionHandler=new Ie,this._maxQualityIndex=10,this._windowImageFactory=new We(this._tunnel),this._cursorFactory=new we(this._tunnel)}async connect(e,t){this._onCloseCallback=e,this._tunnel.handleMessage=this._handleMessage.bind(this),this._tunnel.handleReceivedBytes=this._handleReceivedBytes.bind(this),this._tunnel.handleSentBytes=this._handleSentBytes.bind(this),this._tunnel.onClosed=this._onTunnelClosed.bind(this),await this._tunnel.connect({...t,"client-version":xe})}disconnect(){this._tunnel.disconnect(),this._tunnel.terminate()}async initialise(e,t){try{t={useDefaultMouseAdapter:!0,useDefaultKeyboardAdapter:!0,waitForConnectionWithTimeout:1e4,connectionStatusCallback:()=>{},...t};const{useDefaultMouseAdapter:s,useDefaultKeyboardAdapter:i,waitForConnectionWithTimeout:n,connectionStatusCallback:r}=t;n>0&&await this._connectionHandler.onConnected(n,r);const a=await this._getScreenMessage(),{width:o,height:h}=a.screenSize;this._maxQualityIndex=a.maxQualityIndex,l.version=a.engineVersion,this._display=this.createDisplay(e,o,h);const c=await this._sendRequest(new j);return await this._display.updateWindows(c.windows),this._display.showScreen(),s&&(this._mouse=this.createMouse(e),this._addMouseListeners()),i&&(this._keyboard=this.createKeyboard(document.body),this._addKeyboardListeners()),this._display}catch(e){throw this._dispose(),new Error(`Failed to initialise display: ${e.message}`)}}createDisplay(e,t,s){return new H(e,t,s,this._windowImageFactory,this._cursorFactory,this._options?.display)}createMouse(e){return new K(e)}createKeyboard(e){return new A(e)}sendMouse(e){this._display.setMousePosition(e.x,e.y),this._sendInstruction(new q(e.x,e.y,e.getButtonMask()))}sendKeyEvent(e,t){this._sendInstruction(new ee(e,t))}sendKeyDown(e){this.sendKeyEvent(e,!0)}sendKeyUp(e){this.sendKeyEvent(e,!1)}sendClipboardContent(e){this._sendInstruction(new re(e))}registerTracer(e,t){this._tracers.set(e,t)}createDebugImageMessageHandler(){return this._display?new ue(this._display):(console.log("Cannot create DebugImageMessageHandler as display is null"),null)}resetInputs(){this._mouse&&this._mouse.reset(),this._keyboard&&this._keyboard.reset()}resizeDisplay(){this._display&&this._display.resize()}unregisterTracer(e){const t=this._tracers.get(e);t&&(t.destroy(),this._tracers.delete(e))}setQualityIndex(e){const t=new se(e);this._sendInstruction(t)}async createScreenshot(e,t){return this.display.createScreenshot(e,t)}async _getScreenMessage(){let e=0;for(;e<3;)try{return await this._sendRequest(new Q,5e3)}catch(t){if(e++,console.log(`Failed to initialise screen size at attempt ${e}/3...`),3==e||!this._tunnel.isConnected())throw new Error(`unable to get screen size: ${t.message}`)}}_sendInstruction(e){this._tunnel.isConnected()&&(this._tunnel.sendInstruction(e),this._tracers.forEach(t=>{t instanceof oe&&t.handle(e)}))}_sendRequest(e,t){if(this._tunnel.isConnected())return this._tunnel.sendRequest(e,t)}_handleMessage(e){if(e.type===exports.WebXMessageType.CONNECTION){const t=e;return void this._connectionHandler.setConnected(t.isStarting)}if(e.type===exports.WebXMessageType.NOP&&this._connectionHandler.resetTimer(),this._display){if(e.type===exports.WebXMessageType.WINDOWS){const t=e.windows;this._display.updateWindows(t)}else if(e.type===exports.WebXMessageType.IMAGE){const t=e;this._display.updateImage(t.windowId,t.depth,t.colorMap,t.alphaMap)}else if(e.type===exports.WebXMessageType.SUBIMAGES){const t=e;this._display.updateSubImages(t.windowId,t.subImages)}else if(e.type===exports.WebXMessageType.SHAPE){const t=e;this._display.updateShape(t.windowId,t.stencilMap)}else if(e.type===exports.WebXMessageType.MOUSE){const t=e;t.x>0&&t.y>0&&this._display.setMousePosition(t.x,t.y),this._display.setMouseCursor(t.cursorId)}else if(e.type===exports.WebXMessageType.CLIPBOARD){const t=e;this._clipboardHandler(t.clipboardContent)}this._tracers.forEach(t=>{t instanceof he&&t.handle(e)})}}_handleReceivedBytes(e){this._tracers.forEach(t=>{t instanceof le&&t.handle({received:e.byteLength,sent:0})})}_handleSentBytes(e){this._tracers.forEach(t=>{t instanceof le&&t.handle({received:0,sent:e.byteLength})})}_handleQuality(e){this._tracers.forEach(t=>{t instanceof le&&t.handle({received:0,sent:e.byteLength})})}_onTunnelClosed(){this._dispose(),this._onCloseCallback&&this._onCloseCallback()}_dispose(){this._connectionHandler.dispose(),this._display&&this._display.dispose(),this._mouse&&this._mouse.dispose(),this._keyboard&&this._keyboard.dispose()}_addMouseListeners(){this._mouse.onMouseMove=this._mouse.onMouseOut=e=>{const t=this._display.scale;e.x=e.x/t,e.y=e.y/t,this.sendMouse(e)},this._mouse.onMouseDown=this._mouse.onMouseUp=e=>{const t=this._display.scale;e.x=e.x/t,e.y=e.y/t,this.sendMouse(e)}}_addKeyboardListeners(){this._keyboard.onKeyDown=e=>{this.sendKeyDown(e)},this._keyboard.onKeyUp=e=>{this.sendKeyUp(e)}}},exports.WebXClipboardInstruction=re,exports.WebXClipboardMessage=C,exports.WebXConnectInstruction=class extends J{constructor(e){super(exports.WebXInstructionType.CONNECT),this.parameters=e}},exports.WebXConnectionHandler=Ie,exports.WebXConnectionMessage=T,exports.WebXCursorImageInstruction=te,exports.WebXCursorImageMessage=U,exports.WebXDataAckInstruction=ne,exports.WebXDebugImageMessageHandler=ue,exports.WebXDisplay=H,exports.WebXImageInstruction=$,exports.WebXImageMessage=S,exports.WebXInstruction=J,exports.WebXInstructionHandler=oe,exports.WebXInstructionResponse=B,exports.WebXKeyboard=A,exports.WebXKeyboardCombinationHandler=class extends oe{constructor(e,t){super(),this._combination=e,this._callback=t,this._keys=[]}handle(e){if(e.type===exports.WebXInstructionType.KEYBOARD){const t=e;t.pressed&&(this._keys.push(t.key),this._keys.length>this._combination.length&&this._keys.shift(),this._keys.length==this._combination.length&&this._keys.every((e,t)=>e===this._combination[t])&&this._callback())}}destroy(){}},exports.WebXKeyboardInstruction=ee,exports.WebXMessage=I,exports.WebXMessageHandler=he,exports.WebXMouse=K,exports.WebXMouseInstruction=q,exports.WebXMouseMessage=X,exports.WebXMouseState=O,exports.WebXNopMessage=V,exports.WebXPingMessage=G,exports.WebXPongInstruction=ie,exports.WebXQualityInstruction=se,exports.WebXQualityMessage=R,exports.WebXScreenInstruction=Q,exports.WebXScreenMessage=x,exports.WebXShapeInstruction=ae,exports.WebXShapeMessage=E,exports.WebXStatsHandler=le,exports.WebXSubImage=r,exports.WebXSubImagesMessage=v,exports.WebXTexture=c,exports.WebXTextureFactory=d,exports.WebXTunnel=Me,exports.WebXWebSocketTunnel=class extends Me{constructor(e,t={}){if(super(),this._socketOpen=!1,this._connectionOptions=t,"ws:"!==e.substring(0,3)&&"wss:"!==e.substring(0,4)){const t=window.location,s="https:"===t.protocol?"wss:":"ws:",i=t.hostname,n=t.port?`:${t.port}`:"";e="/"===e.substring(0,1)?`${s}//${i}${n}${e}`:`${s}//${i}${n}/${e}`}this._url=e}getSocket(){return this._socket}send(e){null!=this._socket&&(this._socket.send(e),this.handleSentBytes(e))}connect(e){const t={...this._connectionOptions,...e},s=new URLSearchParams(t),i=`${this._url}?${s}`;return new Promise((e,t)=>{this._socket=new WebSocket(i),this._socket.binaryType="arraybuffer",this._socket.onopen=()=>{this._socketOpen=!0,e(null)},this._socket.onerror=e=>t(e),this._socket.onclose=this.handleClose.bind(this),this._socket.onmessage=e=>this.onMessage(e.data)})}disconnect(){this._socket&&(this._socketOpen=!1,this._socket.close(),this._socket=null)}isConnected(){return this._socketOpen}},exports.WebXWindowProperties=n,exports.WebXWindowsInstruction=j,exports.WebXWindowsMessage=Z,exports.alphaAndStencilBlend=a,exports.alphaBufferBlend=o,exports.colorAndAlphaBlendImageToImageData=(e,t)=>{const s=e.width,i=e.height,n=new OffscreenCanvas(s,i).getContext("2d",{willReadFrequently:!0});n.drawImage(e,0,0);const r=n.getImageData(0,0,s,i);n.drawImage(t,0,0);const a=n.getImageData(0,0,s,i);return o(r.data,a.data),r},exports.imageToImageData=e=>{if(e){const t=e.width,s=e.height,i=new OffscreenCanvas(t,s).getContext("2d",{willReadFrequently:!0});return i.drawImage(e,0,0),i.getImageData(0,0,t,s)}return null},exports.toThreeTexture=u;