@illgrenoble/webx-client 1.14.0 → 1.14.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.
- package/dist/WebXClient.d.ts +6 -0
- package/dist/webx-client.cjs +1 -1
- package/dist/webx-client.esm.js +1 -1
- package/package.json +1 -1
package/dist/WebXClient.d.ts
CHANGED
|
@@ -201,6 +201,12 @@ export declare class WebXClient {
|
|
|
201
201
|
* @param layout the keyboard layout
|
|
202
202
|
*/
|
|
203
203
|
setKeyboardLayout(layout: string): void;
|
|
204
|
+
/**
|
|
205
|
+
* Returns true if the WebXEngine is capable of changing the keyboard layout
|
|
206
|
+
*
|
|
207
|
+
* @returns True if keyboard changing is available
|
|
208
|
+
*/
|
|
209
|
+
canChangeKeyboardLayout(): boolean;
|
|
204
210
|
/**
|
|
205
211
|
* Retrieves the screen message from the WebX Engine.
|
|
206
212
|
*
|
package/dist/webx-client.cjs
CHANGED
|
@@ -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 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){null!=t&&(this.colorMap,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,this.colorMap,this.alphaMap,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 Z{constructor(e,t=0){this.type=e,this.commandId=t}static get convertToImageDataInWorker(){return Z._convertToImageDataInWorker}static set convertToImageDataInWorker(e){Z._convertToImageDataInWorker=e}}Z._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",b[b.SCREEN_RESIZE=13]="SCREEN_RESIZE",b[b.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT";class I extends Z{constructor(e,t,s,i,n,r){super(exports.WebXMessageType.SCREEN,e),this.screenSize=t,this.maxQualityIndex=s,this.engineVersion=i,this.canResizeScreen=n,this.keyboardLayoutName=r}}class x extends Z{constructor(e,t){super(exports.WebXMessageType.WINDOWS,t),this.windows=e}}class S extends Z{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 X extends Z{constructor(e,t,s,i){super(exports.WebXMessageType.SUBIMAGES,s),this.windowId=e,this.subImages=t,this.size=i}}class v extends Z{constructor(e,t,s,i){super(exports.WebXMessageType.MOUSE,i),this.x=e,this.y=t,this.cursorId=s}}class R extends Z{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 T extends Z{constructor(){super(exports.WebXMessageType.PING)}}class C extends Z{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 U extends Z{constructor(e){super(exports.WebXMessageType.CLIPBOARD),this.clipboardContent=e}}class G extends Z{constructor(e){super(exports.WebXMessageType.CONNECTION),this.isStarting=e}}class V extends Z{constructor(){super(exports.WebXMessageType.NOP)}}class E extends Z{constructor(e,t,s,i){super(exports.WebXMessageType.SHAPE,s),this.windowId=e,this.stencilMap=t,this.size=i}}class k extends Z{constructor(e){super(exports.WebXMessageType.SCREEN_RESIZE),this.screenSize=e}}class L extends Z{constructor(e){super(exports.WebXMessageType.KEYBOARD_LAYOUT),this.keyboardLayoutName=e}}class N extends e.ShaderMaterial{constructor(e){super(e)}}class F extends N{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 z=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 Y extends N{set tDiffuse(e){this.uniforms.tDiffuse.value=e}constructor(e){super({uniforms:z(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 D{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 H{static Build(e,t,s,i,n){return e instanceof w?null:new D(i,e,t,s,H._createFilterMaterial(i,n))}static _createFilterMaterial(e,t){return"test"===e?new F:"crt"===e?new Y(t):(console.log(`Unknown filter ${e}`),null)}}class O{get renderer(){return this._renderer}get filter(){return this._filter?.name}set filter(e){this._filter&&this._filter.dispose(),this._filter=e?H.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=H.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,Z.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}onScreenResized(e,t){this._screenWidth==e&&this._screenHeight==t||(this._screenWidth=e,this._screenHeight=t,this._displayElement.style.width=`${e}px`,this._displayElement.style.height=`${t}px`,this._renderer.setSize(this._screenWidth,this._screenHeight,!1),this._camera.right=this._screenWidth,this._camera.bottom=this._screenHeight,this._camera.updateProjectionMatrix(),this.filter&&(this.filter=this._filter.name),this.resize())}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 P,A=A||{};A.Keyboard=function(e){var t=this,s="_GUAC_KEYBOARD_HANDLED_BY_"+A.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?X(e):0,this.modifiers=e?A.Keyboard.ModifierState.fromKeyboardEvent(e):new A.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 A.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 Z=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)}},I=function(e){Z("alt",[65513,65514,65027],e),Z("shift",[65505,65506],e),Z("ctrl",[65507,65508],e),Z("meta",[65511,65512],e),Z("hyper",[65515,65516],e),t.modifiers=e.modifiers};function x(){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,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 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(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);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},X=function(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0},v=function(e){return!e[s]&&(e[s]=!0,!0)},R=function(e){if(t.onkeydown&&v(e)){var s=new r(e);e.isComposing||229===s.keyCode||(h.push(s),x()&&e.preventDefault())}},T=function(e){(t.onkeydown||t.onkeyup)&&v(e)&&(h.push(new a(e)),x()&&e.preventDefault())},C=function(e){t.onkeyup&&v(e)&&(e.preventDefault(),h.push(new o(e)),x())},U=function(e){(t.onkeydown||t.onkeyup)&&v(e)&&e.data&&!e.isComposing&&t.type(e.data)},G=function(t){e.removeEventListener("input",U,!1)},V=function(e){(t.onkeydown||t.onkeyup)&&v(e)&&e.data&&t.type(e.data)};this.listenTo=function(e){e.addEventListener("keydown",R,{passive:!1}),e.addEventListener("keypress",T,{passive:!1}),e.addEventListener("keyup",C,{passive:!1}),e.addEventListener("input",U,!1),e.addEventListener("compositionend",V,!1),e.addEventListener("compositionstart",G,!1)},e&&t.listenTo(e),this.dispose=function(){e&&(e.removeEventListener("keydown",R,!0),e.removeEventListener("keypress",T,!0),e.removeEventListener("keyup",C,!0),e.removeEventListener("input",U,!1),e.removeEventListener("compositionend",V,!1),e.removeEventListener("compositionstart",G,!1))}},A.Keyboard._nextID=0,A.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},A.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new A.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 K{set onKeyDown(e){this._keyboard.onkeydown=e}set onKeyUp(e){this._keyboard.onkeyup=e}constructor(e){this._keyboard=new A.Keyboard(e)}dispose(){this._keyboard.onkeydown=null,this._keyboard.onkeyup=null,this._keyboard.dispose()}reset(){this._keyboard.reset()}}class B{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 B({x:this._x,y:this._y,left:this._left,middle:this._middle,right:this._right,up:this._up,down:this._down})}}class J{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 B({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 Q{constructor(e){this.synchronous=!1,this.id=Q._INSTRUCTION_COUNTER++,this.type=e}}Q._INSTRUCTION_COUNTER=1;class j{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,(P=exports.WebXInstructionType||(exports.WebXInstructionType={}))[P.CONNECT=1]="CONNECT",P[P.WINDOWS=2]="WINDOWS",P[P.IMAGE=3]="IMAGE",P[P.SCREEN=4]="SCREEN",P[P.MOUSE=5]="MOUSE",P[P.KEYBOARD=6]="KEYBOARD",P[P.CURSOR_IMAGE=7]="CURSOR_IMAGE",P[P.QUALITY=8]="QUALITY",P[P.PONG=9]="PONG",P[P.DATA_ACK=10]="DATA_ACK",P[P.CLIPBOARD=11]="CLIPBOARD",P[P.SHAPE=12]="SHAPE",P[P.SCREEN_RESIZE=13]="SCREEN_RESIZE",P[P.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT",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;case"SCREEN_RESIZE":return e.SCREEN_RESIZE}}}(exports.WebXInstructionType||(exports.WebXInstructionType={}));class $ extends Q{constructor(){super(exports.WebXInstructionType.SCREEN)}}class q extends Q{constructor(){super(exports.WebXInstructionType.WINDOWS)}}class ee extends Q{constructor(e){super(exports.WebXInstructionType.IMAGE),this.windowId=e}}class te extends Q{constructor(e,t,s){super(exports.WebXInstructionType.MOUSE),this.x=e,this.y=t,this.buttonMask=s}}class se extends Q{constructor(e,t){super(exports.WebXInstructionType.KEYBOARD),this.key=e,this.pressed=t}}class ie extends Q{constructor(e){super(exports.WebXInstructionType.CURSOR_IMAGE),this.cursorId=e}}class ne extends Q{constructor(e){super(exports.WebXInstructionType.QUALITY),this.qualityIndex=e}}class re extends Q{constructor(e){super(exports.WebXInstructionType.PONG),this.timestampMs=e}}class ae extends Q{constructor(e,t){super(exports.WebXInstructionType.DATA_ACK),this.timestampMs=e,this.dataLength=t}}class oe extends Q{constructor(e){super(exports.WebXInstructionType.CLIPBOARD),this.clipboardContent=e}}class he extends Q{constructor(e){super(exports.WebXInstructionType.SHAPE),this.windowId=e}}class le extends Q{constructor(e,t){super(exports.WebXInstructionType.SCREEN_RESIZE),this.width=e,this.height=t}}class ce extends Q{constructor(e){super(exports.WebXInstructionType.KEYBOARD_LAYOUT),this.keyboardLayout=e}}class de{}class ue{}class pe{}class me{static randomColour(){const e=Math.floor(Math.random()*me._COLOURS.length);return me._COLOURS[e]}static indexedColour(e){return e%=me._COLOURS.length,me._COLOURS[e]}}me._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 ye{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 _e extends ue{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(_e._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,me.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,me.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()})}}_e._PLANE_GEOMETRY=new e.PlaneGeometry(1,1,2,2);class ge{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 be{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=be.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}}be.MESSAGE_HEADER_LENGTH=48;class fe{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):e.type===exports.WebXInstructionType.SCREEN_RESIZE?this._createScreenResizeInstruction(e):e.type===exports.WebXInstructionType.KEYBOARD_LAYOUT?this._createKeyboardLayoutInstruction(e):null}_createMouseInstruction(e){return new ge(e,12).putInt32(e.x).putInt32(e.y).putUInt32(e.buttonMask).buffer()}_createCursorImageInstruction(e){return new ge(e,4).putInt32(e.cursorId).buffer()}_createImageInstruction(e){return new ge(e,4).putUInt32(e.windowId).buffer()}_createKeyboardInstruction(e){return new ge(e,8).putUInt32(e.key).putBoolean(e.pressed).buffer()}_createScreenInstruction(e){return new ge(e,0).buffer()}_createWindowsInstruction(e){return new ge(e,0).buffer()}_createConnectInstruction(e){return new ge(e,0).buffer()}_createQualityInstruction(e){return new ge(e,4).putUInt32(e.qualityIndex).buffer()}_createPongInstruction(e){return new ge(e,8).putUInt8Array(e.timestampMs,8).buffer()}_createDataAckInstruction(e){return new ge(e,12).putUInt8Array(e.timestampMs,8).putUInt32(e.dataLength).buffer()}_createClipboardInstruction(e){const t=4+e.clipboardContent.length;return new ge(e,t).putUInt32(e.clipboardContent.length).putString(e.clipboardContent).buffer()}_createShapeInstruction(e){return new ge(e,4).putUInt32(e.windowId).buffer()}_createScreenResizeInstruction(e){return new ge(e,8).putUInt32(e.width).putUInt32(e.height).buffer()}_createKeyboardLayoutInstruction(e){const t=4+e.keyboardLayout.length;return new ge(e,t).putUInt32(e.keyboardLayout.length).putString(e.keyboardLayout).buffer()}}class Me{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):t===exports.WebXMessageType.SCREEN_RESIZE?this._createScreenResizeMessage(e):t===exports.WebXMessageType.KEYBOARD_LAYOUT?this._createKeyboardLayoutMessage(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 G(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 X(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(),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 x(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 R(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;e.bufferLength-e.readOffset>=12&&(r=e.getUint32(),a=e.getUint32(),o=e.getUint32()),l.version=new ye(r,a,o);let h=!1;e.bufferLength-e.readOffset>=4&&(h=e.getUint32()>0);let c=null;if(e.bufferLength-e.readOffset>=4){const t=e.getUint32();c=e.getString(t)}return new I(t,{width:s,height:i},n,new ye(r,a,o),h,c)}async _createPingMessage(){return new T}async _createQualityMessage(e){const t=e.getUint32(),s=e.getFloat(),i=e.getFloat(),n=e.getFloat(),r=e.getFloat();return new C(t,s,i,n,r)}async _createClipboardMessage(e){const t=e.getUint32(),s=e.getString(t);return new U(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))})})}async _createScreenResizeMessage(e){const t=e.getInt32(),s=e.getInt32();return new k({width:t,height:s})}async _createKeyboardLayoutMessage(e){const t=e.getUint32(),s=e.getString(t);return new L(s)}}var we,We=g("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZXtjb25zdHJ1Y3RvcihlLHQ9MCl7dGhpcy50eXBlPWUsdGhpcy5jb21tYW5kSWQ9dH1zdGF0aWMgZ2V0IGNvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyKCl7cmV0dXJuIGUuX2NvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyfXN0YXRpYyBzZXQgY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXIodCl7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9dH19dmFyIHQ7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9ITEsZnVuY3Rpb24oZSl7ZVtlLk5PUD0wXT0iTk9QIixlW2UuQ09OTkVDVElPTj0xXT0iQ09OTkVDVElPTiIsZVtlLldJTkRPV1M9Ml09IldJTkRPV1MiLGVbZS5JTUFHRT0zXT0iSU1BR0UiLGVbZS5T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LGhlaWdodDpzfSl9cmV0dXJuIG51bGx9fSgpOwovLyMgc291cmNlTWFwcGluZ1VSTD1XZWJYTWVzc2FnZURlY29kZXJXb3JrZXIuanMubWFwCgo=");class Ze{constructor(){this._pending=new Map,this._nextId=1,this._instructionEncoder=new fe,this._messageDecoder=new Me,"undefined"!=typeof Worker&&(this._worker=new We,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(G.prototype):e.type===exports.WebXMessageType.SCREEN?t=Object.create(I.prototype):e.type===exports.WebXMessageType.WINDOWS?t=Object.create(x.prototype):e.type===exports.WebXMessageType.IMAGE?t=Object.create(S.prototype):e.type===exports.WebXMessageType.SUBIMAGES?t=Object.create(X.prototype):e.type===exports.WebXMessageType.MOUSE?t=Object.create(v.prototype):e.type===exports.WebXMessageType.CURSOR_IMAGE?t=Object.create(R.prototype):e.type===exports.WebXMessageType.PING?t=Object.create(T.prototype):e.type===exports.WebXMessageType.QUALITY?t=Object.create(C.prototype):e.type===exports.WebXMessageType.CLIPBOARD?t=Object.create(U.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:Z.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 Ie{constructor(){this._serializer=new Ze,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 j(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<be.MESSAGE_HEADER_LENGTH)return console.warn("Message does not contain a valid header"),null;const t=new be(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 await this.handleMessage(s)}async 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 re(e.timestampMs)):e.messageTypeId!=exports.WebXMessageType.SUBIMAGES&&e.messageTypeId!=exports.WebXMessageType.IMAGE||e.bufferLength>Ie.MIN_BUFFER_LENGTH_FOR_ACK&&this.sendInstruction(new ae(e.timestampMs,e.bufferLength))}}Ie.MIN_BUFFER_LENGTH_FOR_ACK=32768;class xe{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 ie(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 Se{constructor(e){this._tunnel=e}async getWindowTexture(e){try{const t=await this._tunnel.sendRequest(new ee(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 he(e))).stencilMap}}catch(e){return console.warn("Failed to get stencil texture: "+e),null}}}exports.WebXConnectionStatus=void 0,(we=exports.WebXConnectionStatus||(exports.WebXConnectionStatus={}))[we.STARTING=0]="STARTING",we[we.RUNNING=1]="RUNNING";class Xe{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:ve}=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}set keyboardLayoutHandler(e){this._keyboardLayoutHandler=e}get maxQualityIndex(){return this._maxQualityIndex}get keyboardLayoutName(){return this._keyboardLayoutName}constructor(e,t){this._tunnel=e,this._options=t,this._tracers=new Map,this._clipboardHandler=e=>{},this._keyboardLayoutHandler=e=>{},this._connectionHandler=new Xe,this._maxQualityIndex=10,this._canResizeScreen=!1,this._windowImageFactory=new Se(this._tunnel),this._cursorFactory=new xe(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":ve})}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(),{screenSize:o,maxQualityIndex:h,engineVersion:c,canResizeScreen:d,keyboardLayoutName:u}=a,{width:p,height:m}=o;this._maxQualityIndex=h,l.version=c,this._canResizeScreen=d,this._keyboardLayoutName=u,this._display=this.createDisplay(e,p,m);const y=await this._sendRequest(new q);return await this._display.updateWindows(y.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 O(e,t,s,this._windowImageFactory,this._cursorFactory,this._options?.display)}createMouse(e){return new J(e)}createKeyboard(e){return new K(e)}sendMouse(e){this._display.setMousePosition(e.x,e.y),this._sendInstruction(new te(e.x,e.y,e.getButtonMask()))}sendKeyEvent(e,t){this._sendInstruction(new se(e,t))}sendKeyDown(e){this.sendKeyEvent(e,!0)}sendKeyUp(e){this.sendKeyEvent(e,!1)}sendClipboardContent(e){this._sendInstruction(new oe(e))}registerTracer(e,t){this._tracers.set(e,t)}createDebugImageMessageHandler(){return this._display?new _e(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 ne(e);this._sendInstruction(t)}async createScreenshot(e,t){return this.display.createScreenshot(e,t)}resizeScreen(e,t){if(l.version.versionNumber>=1.5&&this._canResizeScreen){const s=new le(e,t);this._sendInstruction(s)}}canResizeScreen(){return l.version.versionNumber>=1.5&&this._canResizeScreen}setKeyboardLayout(e){if(l.version.versionNumber>=1.5){const t=new ce(e);this._sendInstruction(t)}}async _getScreenMessage(){let e=0;for(;e<3;)try{return await this._sendRequest(new $,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 de&&t.handle(e)}))}_sendRequest(e,t){if(this._tunnel.isConnected())return this._tunnel.sendRequest(e,t)}async _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)}else if(e.type===exports.WebXMessageType.SCREEN_RESIZE){const t=e,{width:s,height:i}=t.screenSize;this._display.screenWidth==s&&this._display.screenHeight==i||this._display.onScreenResized(s,i)}else if(e.type===exports.WebXMessageType.KEYBOARD_LAYOUT){const t=e;this._keyboardLayoutName=t.keyboardLayoutName,this._keyboardLayoutHandler(t.keyboardLayoutName)}this._tracers.forEach(t=>{t instanceof ue&&t.handle(e)})}}_handleReceivedBytes(e){this._tracers.forEach(t=>{t instanceof pe&&t.handle({received:e.byteLength,sent:0})})}_handleSentBytes(e){this._tracers.forEach(t=>{t instanceof pe&&t.handle({received:0,sent:e.byteLength})})}_handleQuality(e){this._tracers.forEach(t=>{t instanceof pe&&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=oe,exports.WebXClipboardMessage=U,exports.WebXConnectInstruction=class extends Q{constructor(e){super(exports.WebXInstructionType.CONNECT),this.parameters=e}},exports.WebXConnectionHandler=Xe,exports.WebXConnectionMessage=G,exports.WebXCursorImageInstruction=ie,exports.WebXCursorImageMessage=R,exports.WebXDataAckInstruction=ae,exports.WebXDebugImageMessageHandler=_e,exports.WebXDisplay=O,exports.WebXImageInstruction=ee,exports.WebXImageMessage=S,exports.WebXInstruction=Q,exports.WebXInstructionHandler=de,exports.WebXInstructionResponse=j,exports.WebXKeyboard=K,exports.WebXKeyboardCombinationHandler=class extends de{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=se,exports.WebXKeyboardLayoutInstruction=ce,exports.WebXKeyboardLayoutMessage=L,exports.WebXMessage=Z,exports.WebXMessageHandler=ue,exports.WebXMouse=J,exports.WebXMouseInstruction=te,exports.WebXMouseMessage=v,exports.WebXMouseState=B,exports.WebXNopMessage=V,exports.WebXPingMessage=T,exports.WebXPongInstruction=re,exports.WebXQualityInstruction=ne,exports.WebXQualityMessage=C,exports.WebXScreenInstruction=$,exports.WebXScreenMessage=I,exports.WebXScreenResizeInstruction=le,exports.WebXScreenResizeMessage=k,exports.WebXShapeInstruction=he,exports.WebXShapeMessage=E,exports.WebXStatsHandler=pe,exports.WebXSubImage=r,exports.WebXSubImagesMessage=X,exports.WebXTexture=c,exports.WebXTextureFactory=d,exports.WebXTunnel=Ie,exports.WebXWebSocketTunnel=class extends Ie{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=q,exports.WebXWindowsMessage=x,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;
|
|
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){null!=t&&(this.colorMap,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,this.colorMap,this.alphaMap,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 Z{constructor(e,t=0){this.type=e,this.commandId=t}static get convertToImageDataInWorker(){return Z._convertToImageDataInWorker}static set convertToImageDataInWorker(e){Z._convertToImageDataInWorker=e}}Z._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",b[b.SCREEN_RESIZE=13]="SCREEN_RESIZE",b[b.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT";class I extends Z{constructor(e,t,s,i,n,r){super(exports.WebXMessageType.SCREEN,e),this.screenSize=t,this.maxQualityIndex=s,this.engineVersion=i,this.canResizeScreen=n,this.keyboardLayoutName=r}}class x extends Z{constructor(e,t){super(exports.WebXMessageType.WINDOWS,t),this.windows=e}}class S extends Z{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 X extends Z{constructor(e,t,s,i){super(exports.WebXMessageType.SUBIMAGES,s),this.windowId=e,this.subImages=t,this.size=i}}class v extends Z{constructor(e,t,s,i){super(exports.WebXMessageType.MOUSE,i),this.x=e,this.y=t,this.cursorId=s}}class R extends Z{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 T extends Z{constructor(){super(exports.WebXMessageType.PING)}}class C extends Z{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 U extends Z{constructor(e){super(exports.WebXMessageType.CLIPBOARD),this.clipboardContent=e}}class G extends Z{constructor(e){super(exports.WebXMessageType.CONNECTION),this.isStarting=e}}class V extends Z{constructor(){super(exports.WebXMessageType.NOP)}}class E extends Z{constructor(e,t,s,i){super(exports.WebXMessageType.SHAPE,s),this.windowId=e,this.stencilMap=t,this.size=i}}class k extends Z{constructor(e){super(exports.WebXMessageType.SCREEN_RESIZE),this.screenSize=e}}class L extends Z{constructor(e){super(exports.WebXMessageType.KEYBOARD_LAYOUT),this.keyboardLayoutName=e}}class N extends e.ShaderMaterial{constructor(e){super(e)}}class F extends N{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 z=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 Y extends N{set tDiffuse(e){this.uniforms.tDiffuse.value=e}constructor(e){super({uniforms:z(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 D{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 H{static Build(e,t,s,i,n){return e instanceof w?null:new D(i,e,t,s,H._createFilterMaterial(i,n))}static _createFilterMaterial(e,t){return"test"===e?new F:"crt"===e?new Y(t):(console.log(`Unknown filter ${e}`),null)}}class O{get renderer(){return this._renderer}get filter(){return this._filter?.name}set filter(e){this._filter&&this._filter.dispose(),this._filter=e?H.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=H.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,Z.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}onScreenResized(e,t){this._screenWidth==e&&this._screenHeight==t||(this._screenWidth=e,this._screenHeight=t,this._displayElement.style.width=`${e}px`,this._displayElement.style.height=`${t}px`,this._renderer.setSize(this._screenWidth,this._screenHeight,!1),this._camera.right=this._screenWidth,this._camera.bottom=this._screenHeight,this._camera.updateProjectionMatrix(),this.filter&&(this.filter=this._filter.name),this.resize())}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 P,A=A||{};A.Keyboard=function(e){var t=this,s="_GUAC_KEYBOARD_HANDLED_BY_"+A.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?X(e):0,this.modifiers=e?A.Keyboard.ModifierState.fromKeyboardEvent(e):new A.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 A.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 Z=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)}},I=function(e){Z("alt",[65513,65514,65027],e),Z("shift",[65505,65506],e),Z("ctrl",[65507,65508],e),Z("meta",[65511,65512],e),Z("hyper",[65515,65516],e),t.modifiers=e.modifiers};function x(){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,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 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(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);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},X=function(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0},v=function(e){return!e[s]&&(e[s]=!0,!0)},R=function(e){if(t.onkeydown&&v(e)){var s=new r(e);e.isComposing||229===s.keyCode||(h.push(s),x()&&e.preventDefault())}},T=function(e){(t.onkeydown||t.onkeyup)&&v(e)&&(h.push(new a(e)),x()&&e.preventDefault())},C=function(e){t.onkeyup&&v(e)&&(e.preventDefault(),h.push(new o(e)),x())},U=function(e){(t.onkeydown||t.onkeyup)&&v(e)&&e.data&&!e.isComposing&&t.type(e.data)},G=function(t){e.removeEventListener("input",U,!1)},V=function(e){(t.onkeydown||t.onkeyup)&&v(e)&&e.data&&t.type(e.data)};this.listenTo=function(e){e.addEventListener("keydown",R,{passive:!1}),e.addEventListener("keypress",T,{passive:!1}),e.addEventListener("keyup",C,{passive:!1}),e.addEventListener("input",U,!1),e.addEventListener("compositionend",V,!1),e.addEventListener("compositionstart",G,!1)},e&&t.listenTo(e),this.dispose=function(){e&&(e.removeEventListener("keydown",R,!0),e.removeEventListener("keypress",T,!0),e.removeEventListener("keyup",C,!0),e.removeEventListener("input",U,!1),e.removeEventListener("compositionend",V,!1),e.removeEventListener("compositionstart",G,!1))}},A.Keyboard._nextID=0,A.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},A.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new A.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 K{set onKeyDown(e){this._keyboard.onkeydown=e}set onKeyUp(e){this._keyboard.onkeyup=e}constructor(e){this._keyboard=new A.Keyboard(e)}dispose(){this._keyboard.onkeydown=null,this._keyboard.onkeyup=null,this._keyboard.dispose()}reset(){this._keyboard.reset()}}class B{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 B({x:this._x,y:this._y,left:this._left,middle:this._middle,right:this._right,up:this._up,down:this._down})}}class J{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 B({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 Q{constructor(e){this.synchronous=!1,this.id=Q._INSTRUCTION_COUNTER++,this.type=e}}Q._INSTRUCTION_COUNTER=1;class j{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,(P=exports.WebXInstructionType||(exports.WebXInstructionType={}))[P.CONNECT=1]="CONNECT",P[P.WINDOWS=2]="WINDOWS",P[P.IMAGE=3]="IMAGE",P[P.SCREEN=4]="SCREEN",P[P.MOUSE=5]="MOUSE",P[P.KEYBOARD=6]="KEYBOARD",P[P.CURSOR_IMAGE=7]="CURSOR_IMAGE",P[P.QUALITY=8]="QUALITY",P[P.PONG=9]="PONG",P[P.DATA_ACK=10]="DATA_ACK",P[P.CLIPBOARD=11]="CLIPBOARD",P[P.SHAPE=12]="SHAPE",P[P.SCREEN_RESIZE=13]="SCREEN_RESIZE",P[P.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT",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;case"SCREEN_RESIZE":return e.SCREEN_RESIZE}}}(exports.WebXInstructionType||(exports.WebXInstructionType={}));class $ extends Q{constructor(){super(exports.WebXInstructionType.SCREEN)}}class q extends Q{constructor(){super(exports.WebXInstructionType.WINDOWS)}}class ee extends Q{constructor(e){super(exports.WebXInstructionType.IMAGE),this.windowId=e}}class te extends Q{constructor(e,t,s){super(exports.WebXInstructionType.MOUSE),this.x=e,this.y=t,this.buttonMask=s}}class se extends Q{constructor(e,t){super(exports.WebXInstructionType.KEYBOARD),this.key=e,this.pressed=t}}class ie extends Q{constructor(e){super(exports.WebXInstructionType.CURSOR_IMAGE),this.cursorId=e}}class ne extends Q{constructor(e){super(exports.WebXInstructionType.QUALITY),this.qualityIndex=e}}class re extends Q{constructor(e){super(exports.WebXInstructionType.PONG),this.timestampMs=e}}class ae extends Q{constructor(e,t){super(exports.WebXInstructionType.DATA_ACK),this.timestampMs=e,this.dataLength=t}}class oe extends Q{constructor(e){super(exports.WebXInstructionType.CLIPBOARD),this.clipboardContent=e}}class he extends Q{constructor(e){super(exports.WebXInstructionType.SHAPE),this.windowId=e}}class le extends Q{constructor(e,t){super(exports.WebXInstructionType.SCREEN_RESIZE),this.width=e,this.height=t}}class ce extends Q{constructor(e){super(exports.WebXInstructionType.KEYBOARD_LAYOUT),this.keyboardLayout=e}}class de{}class ue{}class pe{}class me{static randomColour(){const e=Math.floor(Math.random()*me._COLOURS.length);return me._COLOURS[e]}static indexedColour(e){return e%=me._COLOURS.length,me._COLOURS[e]}}me._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 ye{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 _e extends ue{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(_e._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,me.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,me.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()})}}_e._PLANE_GEOMETRY=new e.PlaneGeometry(1,1,2,2);class ge{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 be{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=be.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}}be.MESSAGE_HEADER_LENGTH=48;class fe{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):e.type===exports.WebXInstructionType.SCREEN_RESIZE?this._createScreenResizeInstruction(e):e.type===exports.WebXInstructionType.KEYBOARD_LAYOUT?this._createKeyboardLayoutInstruction(e):null}_createMouseInstruction(e){return new ge(e,12).putInt32(e.x).putInt32(e.y).putUInt32(e.buttonMask).buffer()}_createCursorImageInstruction(e){return new ge(e,4).putInt32(e.cursorId).buffer()}_createImageInstruction(e){return new ge(e,4).putUInt32(e.windowId).buffer()}_createKeyboardInstruction(e){return new ge(e,8).putUInt32(e.key).putBoolean(e.pressed).buffer()}_createScreenInstruction(e){return new ge(e,0).buffer()}_createWindowsInstruction(e){return new ge(e,0).buffer()}_createConnectInstruction(e){return new ge(e,0).buffer()}_createQualityInstruction(e){return new ge(e,4).putUInt32(e.qualityIndex).buffer()}_createPongInstruction(e){return new ge(e,8).putUInt8Array(e.timestampMs,8).buffer()}_createDataAckInstruction(e){return new ge(e,12).putUInt8Array(e.timestampMs,8).putUInt32(e.dataLength).buffer()}_createClipboardInstruction(e){const t=4+e.clipboardContent.length;return new ge(e,t).putUInt32(e.clipboardContent.length).putString(e.clipboardContent).buffer()}_createShapeInstruction(e){return new ge(e,4).putUInt32(e.windowId).buffer()}_createScreenResizeInstruction(e){return new ge(e,8).putUInt32(e.width).putUInt32(e.height).buffer()}_createKeyboardLayoutInstruction(e){const t=4+e.keyboardLayout.length;return new ge(e,t).putUInt32(e.keyboardLayout.length).putString(e.keyboardLayout).buffer()}}class Me{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):t===exports.WebXMessageType.SCREEN_RESIZE?this._createScreenResizeMessage(e):t===exports.WebXMessageType.KEYBOARD_LAYOUT?this._createKeyboardLayoutMessage(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 G(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 X(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(),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 x(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 R(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;e.bufferLength-e.readOffset>=12&&(r=e.getUint32(),a=e.getUint32(),o=e.getUint32()),l.version=new ye(r,a,o);let h=!1;e.bufferLength-e.readOffset>=4&&(h=e.getUint32()>0);let c=null;if(e.bufferLength-e.readOffset>=4){const t=e.getUint32();c=e.getString(t)}return new I(t,{width:s,height:i},n,new ye(r,a,o),h,c)}async _createPingMessage(){return new T}async _createQualityMessage(e){const t=e.getUint32(),s=e.getFloat(),i=e.getFloat(),n=e.getFloat(),r=e.getFloat();return new C(t,s,i,n,r)}async _createClipboardMessage(e){const t=e.getUint32(),s=e.getString(t);return new U(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))})})}async _createScreenResizeMessage(e){const t=e.getInt32(),s=e.getInt32();return new k({width:t,height:s})}async _createKeyboardLayoutMessage(e){const t=e.getUint32(),s=e.getString(t);return new L(s)}}var we,We=g("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZXtjb25zdHJ1Y3RvcihlLHQ9MCl7dGhpcy50eXBlPWUsdGhpcy5jb21tYW5kSWQ9dH1zdGF0aWMgZ2V0IGNvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyKCl7cmV0dXJuIGUuX2NvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyfXN0YXRpYyBzZXQgY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXIodCl7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9dH19dmFyIHQ7ZS5fY29udmVydFRvSW1hZ2VEYXRhSW5Xb3JrZXI9ITEsZnVuY3Rpb24oZSl7ZVtlLk5PUD0wXT0iTk9QIixlW2UuQ09OTkVDVElPTj0xXT0iQ09OTkVDVElPTiIsZVtlLldJTkRPV1M9Ml09IldJTkRPV1MiLGVbZS5JTUFHRT0zXT0iSU1BR0UiLGVbZS5TQ1JFRU49NF09IlNDUkVFTiIsZVtlLlNVQklNQUdFUz01XT0iU1VCSU1BR0VTIixlW2UuTU9VU0U9Nl09Ik1PVVNFIixlW2UuQ1VSU09SX0lNQUdFPTddPSJDVVJTT1JfSU1B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Id=1,this._instructionEncoder=new fe,this._messageDecoder=new Me,"undefined"!=typeof Worker&&(this._worker=new We,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(G.prototype):e.type===exports.WebXMessageType.SCREEN?t=Object.create(I.prototype):e.type===exports.WebXMessageType.WINDOWS?t=Object.create(x.prototype):e.type===exports.WebXMessageType.IMAGE?t=Object.create(S.prototype):e.type===exports.WebXMessageType.SUBIMAGES?t=Object.create(X.prototype):e.type===exports.WebXMessageType.MOUSE?t=Object.create(v.prototype):e.type===exports.WebXMessageType.CURSOR_IMAGE?t=Object.create(R.prototype):e.type===exports.WebXMessageType.PING?t=Object.create(T.prototype):e.type===exports.WebXMessageType.QUALITY?t=Object.create(C.prototype):e.type===exports.WebXMessageType.CLIPBOARD?t=Object.create(U.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:Z.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 Ie{constructor(){this._serializer=new Ze,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 j(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<be.MESSAGE_HEADER_LENGTH)return console.warn("Message does not contain a valid header"),null;const t=new be(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 await this.handleMessage(s)}async 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 re(e.timestampMs)):e.messageTypeId!=exports.WebXMessageType.SUBIMAGES&&e.messageTypeId!=exports.WebXMessageType.IMAGE||e.bufferLength>Ie.MIN_BUFFER_LENGTH_FOR_ACK&&this.sendInstruction(new ae(e.timestampMs,e.bufferLength))}}Ie.MIN_BUFFER_LENGTH_FOR_ACK=32768;class xe{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 ie(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 Se{constructor(e){this._tunnel=e}async getWindowTexture(e){try{const t=await this._tunnel.sendRequest(new ee(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 he(e))).stencilMap}}catch(e){return console.warn("Failed to get stencil texture: "+e),null}}}exports.WebXConnectionStatus=void 0,(we=exports.WebXConnectionStatus||(exports.WebXConnectionStatus={}))[we.STARTING=0]="STARTING",we[we.RUNNING=1]="RUNNING";class Xe{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:ve}=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}set keyboardLayoutHandler(e){this._keyboardLayoutHandler=e}get maxQualityIndex(){return this._maxQualityIndex}get keyboardLayoutName(){return this._keyboardLayoutName}constructor(e,t){this._tunnel=e,this._options=t,this._tracers=new Map,this._clipboardHandler=e=>{},this._keyboardLayoutHandler=e=>{},this._connectionHandler=new Xe,this._maxQualityIndex=10,this._canResizeScreen=!1,this._windowImageFactory=new Se(this._tunnel),this._cursorFactory=new xe(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":ve})}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(),{screenSize:o,maxQualityIndex:h,engineVersion:c,canResizeScreen:d,keyboardLayoutName:u}=a,{width:p,height:m}=o;this._maxQualityIndex=h,l.version=c,this._canResizeScreen=d,this._keyboardLayoutName=u,this._display=this.createDisplay(e,p,m);const y=await this._sendRequest(new q);return await this._display.updateWindows(y.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 O(e,t,s,this._windowImageFactory,this._cursorFactory,this._options?.display)}createMouse(e){return new J(e)}createKeyboard(e){return new K(e)}sendMouse(e){this._display.setMousePosition(e.x,e.y),this._sendInstruction(new te(e.x,e.y,e.getButtonMask()))}sendKeyEvent(e,t){this._sendInstruction(new se(e,t))}sendKeyDown(e){this.sendKeyEvent(e,!0)}sendKeyUp(e){this.sendKeyEvent(e,!1)}sendClipboardContent(e){this._sendInstruction(new oe(e))}registerTracer(e,t){this._tracers.set(e,t)}createDebugImageMessageHandler(){return this._display?new _e(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 ne(e);this._sendInstruction(t)}async createScreenshot(e,t){return this.display.createScreenshot(e,t)}resizeScreen(e,t){if(l.version.versionNumber>=1.5&&this._canResizeScreen){const s=new le(e,t);this._sendInstruction(s)}}canResizeScreen(){return l.version.versionNumber>=1.5&&this._canResizeScreen}setKeyboardLayout(e){if(l.version.versionNumber>=1.5){const t=new ce(e);this._sendInstruction(t)}}canChangeKeyboardLayout(){return l.version.versionNumber>=1.5}async _getScreenMessage(){let e=0;for(;e<3;)try{return await this._sendRequest(new $,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 de&&t.handle(e)}))}_sendRequest(e,t){if(this._tunnel.isConnected())return this._tunnel.sendRequest(e,t)}async _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)}else if(e.type===exports.WebXMessageType.SCREEN_RESIZE){const t=e,{width:s,height:i}=t.screenSize;this._display.screenWidth==s&&this._display.screenHeight==i||this._display.onScreenResized(s,i)}else if(e.type===exports.WebXMessageType.KEYBOARD_LAYOUT){const t=e;this._keyboardLayoutName=t.keyboardLayoutName,this._keyboardLayoutHandler(t.keyboardLayoutName)}this._tracers.forEach(t=>{t instanceof ue&&t.handle(e)})}}_handleReceivedBytes(e){this._tracers.forEach(t=>{t instanceof pe&&t.handle({received:e.byteLength,sent:0})})}_handleSentBytes(e){this._tracers.forEach(t=>{t instanceof pe&&t.handle({received:0,sent:e.byteLength})})}_handleQuality(e){this._tracers.forEach(t=>{t instanceof pe&&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=oe,exports.WebXClipboardMessage=U,exports.WebXConnectInstruction=class extends Q{constructor(e){super(exports.WebXInstructionType.CONNECT),this.parameters=e}},exports.WebXConnectionHandler=Xe,exports.WebXConnectionMessage=G,exports.WebXCursorImageInstruction=ie,exports.WebXCursorImageMessage=R,exports.WebXDataAckInstruction=ae,exports.WebXDebugImageMessageHandler=_e,exports.WebXDisplay=O,exports.WebXImageInstruction=ee,exports.WebXImageMessage=S,exports.WebXInstruction=Q,exports.WebXInstructionHandler=de,exports.WebXInstructionResponse=j,exports.WebXKeyboard=K,exports.WebXKeyboardCombinationHandler=class extends de{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=se,exports.WebXKeyboardLayoutInstruction=ce,exports.WebXKeyboardLayoutMessage=L,exports.WebXMessage=Z,exports.WebXMessageHandler=ue,exports.WebXMouse=J,exports.WebXMouseInstruction=te,exports.WebXMouseMessage=v,exports.WebXMouseState=B,exports.WebXNopMessage=V,exports.WebXPingMessage=T,exports.WebXPongInstruction=re,exports.WebXQualityInstruction=ne,exports.WebXQualityMessage=C,exports.WebXScreenInstruction=$,exports.WebXScreenMessage=I,exports.WebXScreenResizeInstruction=le,exports.WebXScreenResizeMessage=k,exports.WebXShapeInstruction=he,exports.WebXShapeMessage=E,exports.WebXStatsHandler=pe,exports.WebXSubImage=r,exports.WebXSubImagesMessage=X,exports.WebXTexture=c,exports.WebXTextureFactory=d,exports.WebXTunnel=Ie,exports.WebXWebSocketTunnel=class extends Ie{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=q,exports.WebXWindowsMessage=x,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;
|
package/dist/webx-client.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"three";import{ShaderMaterial as t,BackSide as s,Color as i,Matrix3 as n,LinearFilter as a,MeshBasicMaterial as r,DataTexture as o,Mesh as h,ColorManagement as l,Vector3 as c,PlaneGeometry as d,Object3D as u}from"three";import{Group as p,Tween as m,Easing as _}from"@tweenjs/tween.js";class y{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 g{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 f=(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]},b=(e,t)=>{for(let s=0;s<e.length;s+=4)e[s+3]=t[s+1]},w=(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 b(a.data,r.data),a},Z=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};class M extends t{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(e){super({uniforms:{map:{value:null},alphaMap:{value:null},stencilMap:{value:null},mapTransform:{value:new n},alphaMapTransform:{value:new n},diffuse:{value:new i(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:s}),e&&e.color&&this.color.set(e.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 S{}class I{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 v{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 I({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 I({image:n});t(e)},n.onerror=e=>{console.warn(`Failed to create texture from binary data: ${e}`),s(e)},n.src=i})}}const W=t=>{if(t){const s=t.data?new e.DataTexture(t.data,t.width,t.height):new e.Texture(t.image);return s.needsUpdate=!0,s.flipY=t.flipY,s.minFilter=a,s}return null};class R{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(t,s){this._width=1,this._height=1,this._shaped=!1,this._loaded=!1,this._windowRefreshTimeout=null,this._windowImageFactory=s,this._colorIndex=R._COLOR_INDEX++,this._material=new M,this.visible=!1;const{id:i,x:n,y:a,z:r,width:o,height:h,shaped:l}=t;this._id=i,this._mesh=new e.Mesh(R._PLANE_GEOMETRY,this._material),this._mesh.onBeforeRender=()=>this._material.onBeforeRender(),this._x=n,this._y=a,this._z=r,this._width=o,this._height=h,this._shaped=l&&S.version.versionNumber>=1.4,this._updateScale(),this._updatePosition()}async loadWindowImage(){const e=await this._windowImageFactory.getWindowTexture(this._id);e&&this.updateTexture(e.depth,W(e.colorMap),W(e.alphaMap),!0)}async loadWindowShape(){const e=await this._windowImageFactory.getWindowStencilTexture(this._id);e?this.updateStencilTexture(W(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){null!=t&&(this.colorMap,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,this.colorMap,this.alphaMap,this._material.needsUpdate=!0,i||(this._windowRefreshTimeout&&(clearTimeout(this._windowRefreshTimeout),this._windowRefreshTimeout=null),this._windowRefreshTimeout=window.setTimeout(()=>{this._windowRefreshTimeout=null,this.loadWindowImage().then()},R.WINDOW_REFRESH_TIME_MS)))}updateStencilTexture(e){const t=this._shaped;e!=this.stencilMap&&(this._disposeStencilMap(),this.stencilMap=e),e?(e.minFilter=a,this.visible=null!=this.colorMap,this._shaped=!0):this._shaped=!1,t!==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)}}R.WINDOW_REFRESH_TIME_MS=5e3,R._PLANE_GEOMETRY=new e.PlaneGeometry(1,1,2,2),R._COLOR_INDEX=0;class U{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 M||this._mesh.material instanceof r){const e=this._mesh.material;if(this.updateStencilMap(e),e.map?.image){if(e.map!=this._colorMap||e.alphaMap!=this._alphaMap){this._colorMap=e.map,this._alphaMap=e.alphaMap;const t=e.map.image,s=t.width,i=t.height;if(this.isValidAlphaMap(e.alphaMap)||null!=this._stencilMap){const t=await this.blendAlphaAndStencil(e.map,e.alphaMap,0,0);this.resizeCanvas(s,i),this._context.putImageData(t,0,0)}else if(this.resizeCanvas(s,i),e.map instanceof o){const e=this.dataTextureToImageData(t);this._context.putImageData(e,0,0)}else this._context.clearRect(0,0,s,i),this._context.drawImage(t,0,0,s,i)}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 e of this._regionUpdates)if(e.dstColorMap===this._colorMap&&e.dstAlphaMap===this._alphaMap){const{srcColorMap:t,srcAlphaMap:s,width:i,height:n,dstPosition:a}=e,r=t.image;if(s||this._stencilData){const e=await this.blendAlphaAndStencil(t,s,a.x,a.y);e&&this._context.putImageData(e,a.x,a.y)}else if(t instanceof o){const e=this.dataTextureToImageData(r);this._context.putImageData(e,a.x,a.y)}else this._context.drawImage(r,0,0,i,n,a.x,a.y,i,n)}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(e){if(e instanceof M&&e.stencilMap){if(e.stencilMap!=this._stencilMap){this._stencilMap=e.stencilMap;const t=this._stencilMap.image,{width:s,height:i}=t;if(this._stencilMap instanceof o)this._stencilData=this.dataTextureToImageData(t);else{const e=this.createElementNS("canvas");e.width=s,e.height=i;const n=e.getContext("2d",{willReadFrequently:!0});n.drawImage(t,0,0),this._stencilData=n.getImageData(0,0,s,i)}}}else this._stencilMap&&(this._stencilMap=null,this._stencilData=null)}async blendAlphaAndStencil(e,t,s,i){const n=e instanceof o?this.dataTextureToImageData(e.image):this.getImageData(e.image),a=null==t?null:t instanceof o?this.dataTextureToImageData(t.image):this.getImageData(t.image),r=null==this._stencilData?null:this.getStencilDataRegion(s,i,n.width,n.height);return a||r?await this._imageBlender.blendAlphaAndStencil(n,a,r):n}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 C(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 V(e,t,s){var i;return function(t){return i=i||C(e),new Worker(i,t)}}var x,E=V("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7c2VsZi5vbm1lc3NhZ2U9ZT0+e2NvbnN0e2lkOmYsY29sb3JCdWZmZXI6bCxhbHBoYUJ1ZmZlcjp0LHN0ZW5jaWxCdWZmZXI6cix3aWR0aDpuLGhlaWdodDppfT1lLmRhdGEscz1uZXcgVWludDhDbGFtcGVkQXJyYXkobCk7KChlLGYsbCk9PntpZihmJiZsKWZvcihsZXQgdD0wO3Q8ZS5sZW5ndGg7dCs9NClsW3RdPDEyOD9lW3QrM109MDplW3QrM109Zlt0KzFdO2Vsc2UgaWYoZilmb3IobGV0IGw9MDtsPGUubGVuZ3RoO2wrPTQpZVtsKzNdPWZbbCsxXTtlbHNlIGlmKGwpZm9yKGxldCBmPTA7ZjxlLmxlbmd0aDtmKz00KWVbZiszXT1sW2ZdPDEyOD8wOmVbZiszXX0pKHMsdD9uZXcgVWludDhDbGFtcGVkQXJyYXkodCk6bnVsbCxyP25ldyBVaW50OENsYW1wZWRBcnJheShyKTpudWxsKSxzZWxmLnBvc3RNZXNzYWdlKHtpZDpmLGNvbG9yQnVmZmVyOnMuYnVmZmVyLHdpZHRoOm4saGVpZ2h0Oml9LFtzLmJ1ZmZlcl0pfX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9V2ViWEltYWdlQmxlbmRlcldvcmtlci5qcy5tYXAKCg==");class X{constructor(){this._pending=new Map,this._nextId=1,"undefined"!=typeof Worker&&(this._worker=new E,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 f(e.data,t?.data,s?.data),i(e)})}terminate(){this._worker.terminate(),this._pending.clear()}}class k{get domElement(){return this._desktopContainer}constructor(){this._clearColor=new i(0,0,0),this._windowCanvases=new Map,this.createMainElement(),this._imageBlender=new X}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(e,t){if(e.children.length>0){const t=e.children[0],s=new Set;for(const e of t.children)if(e instanceof h&&e.visible){this._windowCanvases.has(e.id)||this.createWindowCanvas(e);const t=this._windowCanvases.get(e.id);t.updateGeometry(),t.updateCanvas(),s.add(e.id)}for(const[e,t]of this._windowCanvases.entries())s.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 L{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 N{constructor(e,t=0){this.type=e,this.commandId=t}static get convertToImageDataInWorker(){return N._convertToImageDataInWorker}static set convertToImageDataInWorker(e){N._convertToImageDataInWorker=e}}N._convertToImageDataInWorker=!1,function(e){e[e.NOP=0]="NOP",e[e.CONNECTION=1]="CONNECTION",e[e.WINDOWS=2]="WINDOWS",e[e.IMAGE=3]="IMAGE",e[e.SCREEN=4]="SCREEN",e[e.SUBIMAGES=5]="SUBIMAGES",e[e.MOUSE=6]="MOUSE",e[e.CURSOR_IMAGE=7]="CURSOR_IMAGE",e[e.PING=8]="PING",e[e.DISCONNECT=9]="DISCONNECT",e[e.QUALITY=10]="QUALITY",e[e.CLIPBOARD=11]="CLIPBOARD",e[e.SHAPE=12]="SHAPE",e[e.SCREEN_RESIZE=13]="SCREEN_RESIZE",e[e.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT"}(x||(x={}));class T extends N{constructor(e,t,s,i,n,a){super(x.SCREEN,e),this.screenSize=t,this.maxQualityIndex=s,this.engineVersion=i,this.canResizeScreen=n,this.keyboardLayoutName=a}}class F extends N{constructor(e,t){super(x.WINDOWS,t),this.windows=e}}class z extends N{constructor(e,t,s,i,n,a){super(x.IMAGE,n),this.windowId=e,this.depth=t,this.colorMap=s,this.alphaMap=i,this.size=a}}class Y extends N{constructor(e,t,s,i){super(x.SUBIMAGES,s),this.windowId=e,this.subImages=t,this.size=i}}class H extends N{constructor(e,t,s,i){super(x.MOUSE,i),this.x=e,this.y=t,this.cursorId=s}}class D extends N{constructor(e,t,s,i,n,a,r){super(x.CURSOR_IMAGE,r),this.x=e,this.y=t,this.xHot=s,this.yHot=i,this.cursorId=n,this.texture=a}}class O extends N{constructor(){super(x.PING)}}class P extends N{constructor(e,t,s,i,n){super(x.QUALITY),this.index=e,this.imageFPS=t,this.rgbQuality=s,this.alphaQuality=i,this.maxMbps=n}}class A extends N{constructor(e){super(x.CLIPBOARD),this.clipboardContent=e}}class K extends N{constructor(e){super(x.CONNECTION),this.isStarting=e}}class B extends N{constructor(){super(x.NOP)}}class J extends N{constructor(e,t,s,i){super(x.SHAPE,s),this.windowId=e,this.stencilMap=t,this.size=i}}class Q extends N{constructor(e){super(x.SCREEN_RESIZE),this.screenSize=e}}class j extends N{constructor(e){super(x.KEYBOARD_LAYOUT),this.keyboardLayoutName=e}}class $ extends t{constructor(e){super(e)}}class q extends ${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 ee=e=>{const t={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",...(e=e||{})||{}};return Object.fromEntries(Object.entries(t).map(([t,s])=>{let n=null==e[t]?s:e[t];return"backgroundColor"===t&&(n=new i(n)),[t,{value:n}]}))};class te extends ${set tDiffuse(e){this.uniforms.tDiffuse.value=e}constructor(e){super({uniforms:ee(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 se{get name(){return this._name}constructor(t,s,i,n,a){if(this._rtTexture=null,this._name=t,this._renderer=s,this._filterMaterial=a,a){this._sceneScreen=new e.Scene,this._rtTexture=new e.WebGLRenderTarget(i,n),this._filterMaterial.tDiffuse=this._rtTexture.texture;const t=new e.PlaneGeometry(i,n),s=new e.Mesh(t,this._filterMaterial);s.rotateX(Math.PI),s.position.set(.5*i,.5*n,10),this._sceneScreen.add(s)}}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 ie{static Build(e,t,s,i,n){return e instanceof k?null:new se(i,e,t,s,ie._createFilterMaterial(i,n))}static _createFilterMaterial(e,t){return"test"===e?new q:"crt"===e?new te(t):(console.log(`Unknown filter ${e}`),null)}}class ne{get renderer(){return this._renderer}get filter(){return this._filter?.name}set filter(e){this._filter&&this._filter.dispose(),this._filter=e?ie.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,a,r,o){this._isWebGL=!0,this._windows=[],this._scale=1,this._disposed=!1,this._sceneDirty=!1,this._disableStencil=!1,l.enabled=!1,this._containerElement=t,this._screenWidth=s,this._screenHeight=n,this._windowImageFactory=a,this._options=o||{},this._cursor=new U(r),this._displayOverlay=new L(this._cursor),this._scene=new e.Scene,this._screen=new e.Object3D;const h=new e.Mesh(new e.PlaneGeometry(1,1,2,2),new e.MeshBasicMaterial({map:new e.DataTexture(new Uint8ClampedArray(4),1,1),side:e.BackSide,transparent:!0}));h.position.set(0,0,999),this._screen.add(h),this._camera=new e.OrthographicCamera(0,s,0,n,.1,1e4),this._camera.position.z=1e3,this._camera.lookAt(new c(0,0,0));const d=this._options.backgroundColor||window.getComputedStyle(this._containerElement).backgroundColor,u=this._detectWebGL2(),p=new URL(window.location.href).searchParams,m="true"===p.get("webx-canvas")||this._options.forceCanvas;if(this._disableStencil="false"===p.get("webx-stencil")||this._options.disableStencil,this._isWebGL=u.available&&!u.isSoftware&&!m,this._isWebGL){this._renderer=new e.WebGLRenderer;const t=this._options.filter?"string"==typeof this._options.filter?this._options.filter:this._options.filter.name:null,i=p.get("webx-filter")?p.get("webx-filter"):t;i&&(this._filter=ie.Build(this._renderer,s,n,i,this._getFilterParams()))}else console.log(`WebGL2 Info: available = ${u.available}, isSoftware = ${u.isSoftware}, vendor = ${u.vendor}, renderer = ${u.renderer}`),m?console.log("Canvas Renderer enabled through request param"):console.log("Falling back to Canvas Renderer"),this._renderer=new k,N.convertToImageDataInWorker=!0;this._renderer.setSize(s,n,!1),this._renderer.setClearColor(new i(d)),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}onScreenResized(e,t){this._screenWidth==e&&this._screenHeight==t||(this._screenWidth=e,this._screenHeight=t,this._displayElement.style.width=`${e}px`,this._displayElement.style.height=`${t}px`,this._renderer.setSize(this._screenWidth,this._screenHeight,!1),this._camera.right=this._screenWidth,this._camera.bottom=this._screenHeight,this._camera.updateProjectionMatrix(),this.filter&&(this.filter=this._filter.name),this.resize())}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 k)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 R({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,W(s),W(i),!0),this._sceneDirty=!0)}updateSubImages(t,s){const i=this.getWindow(t);if(null!=i&&i.colorMapValid){const t=i.colorMap,n=i.alphaMap;for(let a=0;a<s.length;a++){const r=s[a];this._renderer instanceof k?this._renderer.updateWindowRegion(i.mesh.id,W(r.colorMap),t,W(r.alphaMap),n,r.width,r.height,new e.Vector2(r.x,r.y)):(t&&r.colorMap&&this._renderer.copyTextureToTexture(W(r.colorMap),t,null,new e.Vector2(r.x,r.y)),n&&r.alphaMap&&this._renderer.copyTextureToTexture(W(r.alphaMap),n,null,new e.Vector2(r.x,r.y)))}i.updateTexture(i.depth,t,n,!1),this._sceneDirty=!0}}updateShape(e,t){if(this._disableStencil)return;const s=this.getWindow(e);null!=s&&null!=t&&(s.updateStencilTexture(W(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)}}_getFilterParams(){return{backgroundColor:this._options.backgroundColor||window.getComputedStyle(this._containerElement).backgroundColor,...this._options.filter?"string"==typeof this._options.filter?{}:this._options.filter.params:{}}}}var ae,re=re||{};re.Keyboard=function(e){var t=this,s="_GUAC_KEYBOARD_HANDLED_BY_"+re.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?R(e):0,this.modifiers=e?re.Keyboard.ModifierState.fromKeyboardEvent(e):new re.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=b(this.key,this.location)||Z(this.keyCode,this.location),this.keyupReliable=!i.keyupUnreliable,this.keysym&&!f(this.keysym)&&(this.reliable=!0),!this.keysym&&M(this.keyCode,this.keyIdentifier)&&(this.keysym=b(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};a.prototype=new n;var r=function(e){n.call(this,e),this.keysym=w(this.keyCode),this.reliable=!0};r.prototype=new n;var o=function(e){n.call(this,e),this.keysym=Z(this.keyCode,this.location)||b(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 re.Keyboard.ModifierState,this.pressed={};var u={},p={},m={},_=null,y=null,g=function(e,t){return e?e[t]||e[0]:null},f=function(e){return e>=0&&e<=255||16777216==(4294901760&e)};function b(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()),w(i.charCodeAt(0))}function w(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 M=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(_),window.clearInterval(y),d[e]||(_=window.setTimeout(function(){y=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(_),window.clearInterval(y),null!==e&&t.onkeyup&&t.onkeyup(e))},this.type=function(e){for(var s=0;s<e.length;s++){var i=w(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 S=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){S("alt",[65513,65514,65027],e),S("shift",[65505,65506],e),S("ctrl",[65507,65508],e),S("meta",[65511,65512],e),S("hyper",[65515,65516],e),t.modifiers=e.modifiers};function v(){var e,s=W();if(!s)return!1;do{e=s,s=W()}while(null!==s);return function(){for(var e in t.pressed)if(!u[e])return!1;return!0}()&&t.reset(),e.defaultPrevented}var W=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 m[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);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},R=function(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0},U=function(e){return!e[s]&&(e[s]=!0,!0)},G=function(e){if(t.onkeydown&&U(e)){var s=new a(e);e.isComposing||229===s.keyCode||(h.push(s),v()&&e.preventDefault())}},C=function(e){(t.onkeydown||t.onkeyup)&&U(e)&&(h.push(new r(e)),v()&&e.preventDefault())},V=function(e){t.onkeyup&&U(e)&&(e.preventDefault(),h.push(new o(e)),v())},x=function(e){(t.onkeydown||t.onkeyup)&&U(e)&&e.data&&!e.isComposing&&t.type(e.data)},E=function(t){e.removeEventListener("input",x,!1)},X=function(e){(t.onkeydown||t.onkeyup)&&U(e)&&e.data&&t.type(e.data)};this.listenTo=function(e){e.addEventListener("keydown",G,{passive:!1}),e.addEventListener("keypress",C,{passive:!1}),e.addEventListener("keyup",V,{passive:!1}),e.addEventListener("input",x,!1),e.addEventListener("compositionend",X,!1),e.addEventListener("compositionstart",E,!1)},e&&t.listenTo(e),this.dispose=function(){e&&(e.removeEventListener("keydown",G,!0),e.removeEventListener("keypress",C,!0),e.removeEventListener("keyup",V,!0),e.removeEventListener("input",x,!1),e.removeEventListener("compositionend",X,!1),e.removeEventListener("compositionstart",E,!1))}},re.Keyboard._nextID=0,re.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},re.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new re.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 oe{set onKeyDown(e){this._keyboard.onkeydown=e}set onKeyUp(e){this._keyboard.onkeyup=e}constructor(e){this._keyboard=new re.Keyboard(e)}dispose(){this._keyboard.onkeydown=null,this._keyboard.onkeyup=null,this._keyboard.dispose()}reset(){this._keyboard.reset()}}class he{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 he({x:this._x,y:this._y,left:this._left,middle:this._middle,right:this._right,up:this._up,down:this._down})}}class le{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 he({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 ce{constructor(e){this.synchronous=!1,this.id=ce._INSTRUCTION_COUNTER++,this.type=e}}ce._INSTRUCTION_COUNTER=1;class de{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))}}!function(e){e[e.CONNECT=1]="CONNECT",e[e.WINDOWS=2]="WINDOWS",e[e.IMAGE=3]="IMAGE",e[e.SCREEN=4]="SCREEN",e[e.MOUSE=5]="MOUSE",e[e.KEYBOARD=6]="KEYBOARD",e[e.CURSOR_IMAGE=7]="CURSOR_IMAGE",e[e.QUALITY=8]="QUALITY",e[e.PONG=9]="PONG",e[e.DATA_ACK=10]="DATA_ACK",e[e.CLIPBOARD=11]="CLIPBOARD",e[e.SHAPE=12]="SHAPE",e[e.SCREEN_RESIZE=13]="SCREEN_RESIZE",e[e.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT"}(ae||(ae={})),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;case"SCREEN_RESIZE":return e.SCREEN_RESIZE}}}(ae||(ae={}));class ue extends ce{constructor(e){super(ae.CONNECT),this.parameters=e}}class pe extends ce{constructor(){super(ae.SCREEN)}}class me extends ce{constructor(){super(ae.WINDOWS)}}class _e extends ce{constructor(e){super(ae.IMAGE),this.windowId=e}}class ye extends ce{constructor(e,t,s){super(ae.MOUSE),this.x=e,this.y=t,this.buttonMask=s}}class ge extends ce{constructor(e,t){super(ae.KEYBOARD),this.key=e,this.pressed=t}}class fe extends ce{constructor(e){super(ae.CURSOR_IMAGE),this.cursorId=e}}class be extends ce{constructor(e){super(ae.QUALITY),this.qualityIndex=e}}class we extends ce{constructor(e){super(ae.PONG),this.timestampMs=e}}class Ze extends ce{constructor(e,t){super(ae.DATA_ACK),this.timestampMs=e,this.dataLength=t}}class Me extends ce{constructor(e){super(ae.CLIPBOARD),this.clipboardContent=e}}class Se extends ce{constructor(e){super(ae.SHAPE),this.windowId=e}}class Ie extends ce{constructor(e,t){super(ae.SCREEN_RESIZE),this.width=e,this.height=t}}class ve extends ce{constructor(e){super(ae.KEYBOARD_LAYOUT),this.keyboardLayout=e}}class We{}class Re{}class Ue{}class Ge{static randomColour(){const e=Math.floor(Math.random()*Ge._COLOURS.length);return Ge._COLOURS[e]}static indexedColour(e){return e%=Ge._COLOURS.length,Ge._COLOURS[e]}}Ge._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 Ce{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 Ve extends Re{constructor(e){super(),this._display=e,this._debugLayer=new u,this._currentZ=0,this._disposed=!1,this._tweenGroup=new p,this._debugLayer.position.set(0,0,999),this._scene=this._display.scene,this._scene.add(this._debugLayer),this._animate()}_createMesh(e,t,i,n,a){const o=new r({color:a,opacity:.8,transparent:!0});o.side=s;const l=new h(Ve._PLANE_GEOMETRY,o);l.position.set(e+i/2,t+n/2,this._currentZ),l.scale.set(i,n,1),this._currentZ+=1e-4,this._debugLayer.add(l),new m(o,this._tweenGroup).to({opacity:0},500).easing(_.Quadratic.Out).onComplete(()=>this._debugLayer.remove(l)).onUpdate(()=>this._display.sceneDirty=!0).start()}handle(e){if(e.type===x.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,Ge.indexedColour(s.colorIndex))}else if(e.type===x.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,Ge.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()})}}Ve._PLANE_GEOMETRY=new d(1,1,2,2);class xe extends We{constructor(e,t){super(),this._combination=e,this._callback=t,this._keys=[]}handle(e){if(e.type===ae.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(){}}class Ee{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 Xe{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=Xe.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}}Xe.MESSAGE_HEADER_LENGTH=48;class ke{encode(e){return e.type===ae.MOUSE?this._createMouseInstruction(e):e.type===ae.KEYBOARD?this._createKeyboardInstruction(e):e.type===ae.CURSOR_IMAGE?this._createCursorImageInstruction(e):e.type===ae.IMAGE?this._createImageInstruction(e):e.type===ae.CONNECT?this._createConnectInstruction(e):e.type===ae.SCREEN?this._createScreenInstruction(e):e.type===ae.WINDOWS?this._createWindowsInstruction(e):e.type===ae.QUALITY?this._createQualityInstruction(e):e.type===ae.PONG?this._createPongInstruction(e):e.type===ae.DATA_ACK?this._createDataAckInstruction(e):e.type===ae.CLIPBOARD?this._createClipboardInstruction(e):e.type===ae.SHAPE?this._createShapeInstruction(e):e.type===ae.SCREEN_RESIZE?this._createScreenResizeInstruction(e):e.type===ae.KEYBOARD_LAYOUT?this._createKeyboardLayoutInstruction(e):null}_createMouseInstruction(e){return new Ee(e,12).putInt32(e.x).putInt32(e.y).putUInt32(e.buttonMask).buffer()}_createCursorImageInstruction(e){return new Ee(e,4).putInt32(e.cursorId).buffer()}_createImageInstruction(e){return new Ee(e,4).putUInt32(e.windowId).buffer()}_createKeyboardInstruction(e){return new Ee(e,8).putUInt32(e.key).putBoolean(e.pressed).buffer()}_createScreenInstruction(e){return new Ee(e,0).buffer()}_createWindowsInstruction(e){return new Ee(e,0).buffer()}_createConnectInstruction(e){return new Ee(e,0).buffer()}_createQualityInstruction(e){return new Ee(e,4).putUInt32(e.qualityIndex).buffer()}_createPongInstruction(e){return new Ee(e,8).putUInt8Array(e.timestampMs,8).buffer()}_createDataAckInstruction(e){return new Ee(e,12).putUInt8Array(e.timestampMs,8).putUInt32(e.dataLength).buffer()}_createClipboardInstruction(e){const t=4+e.clipboardContent.length;return new Ee(e,t).putUInt32(e.clipboardContent.length).putString(e.clipboardContent).buffer()}_createShapeInstruction(e){return new Ee(e,4).putUInt32(e.windowId).buffer()}_createScreenResizeInstruction(e){return new Ee(e,8).putUInt32(e.width).putUInt32(e.height).buffer()}_createKeyboardLayoutInstruction(e){const t=4+e.keyboardLayout.length;return new Ee(e,t).putUInt32(e.keyboardLayout.length).putString(e.keyboardLayout).buffer()}}class Le{constructor(){this._textureFactory=new v}decode(e){const{messageTypeId:t}=e;return t===x.NOP?this._createNopMessage():t===x.CONNECTION?this._createConnectionMessage(e):t===x.SCREEN?this._createScreenMessage(e):t===x.WINDOWS?this._createWindowsMessage(e):t===x.IMAGE?this._createImageMessage(e):t===x.SUBIMAGES?this._createSubImagesMessage(e):t===x.MOUSE?this._createMouseMessage(e):t===x.CURSOR_IMAGE?this._createCursorImageMessage(e):t===x.PING?this._createPingMessage():t===x.QUALITY?this._createQualityMessage(e):t===x.CLIPBOARD?this._createClipboardMessage(e):t===x.SHAPE?this._createShapeMessage(e):t===x.SCREEN_RESIZE?this._createScreenResizeMessage(e):t===x.KEYBOARD_LAYOUT?this._createKeyboardLayoutMessage(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 B}async _createConnectionMessage(e){const t=e.getUint32();return new K(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),c=e.getUint8Array(h),d=this._textureFactory.createTextureFromArray(l,r),u=this._textureFactory.createTextureFromArray(c,r);Promise.all([d,u]).then(([a,r])=>{t(new z(i,n,a,r,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(),r=e.getUint32(),o=e.getString(4),h=this._determineMimeType(o),l=e.getUint32(),c=e.getUint32(),d=e.getUint8Array(l),u=e.getUint8Array(c),p=new Promise((e,n)=>{const o=this._textureFactory.createTextureFromArray(d,h),l=this._textureFactory.createTextureFromArray(u,h);Promise.all([o,l]).then(([n,o])=>{e(new g({x:t,y:s,width:i,height:a,depth:r,colorMap:n,alphaMap:o}))}).catch(n)});n.push(p)}Promise.all(n).then(n=>{t(new Y(i,n,s,e.bufferLength))})})}async _createMouseMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32(),n=e.getUint32();return new H(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(S.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 F(i.map(e=>new y(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");return new D(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;e.bufferLength-e.readOffset>=12&&(a=e.getUint32(),r=e.getUint32(),o=e.getUint32()),S.version=new Ce(a,r,o);let h=!1;e.bufferLength-e.readOffset>=4&&(h=e.getUint32()>0);let l=null;if(e.bufferLength-e.readOffset>=4){const t=e.getUint32();l=e.getString(t)}return new T(t,{width:s,height:i},n,new Ce(a,r,o),h,l)}async _createPingMessage(){return new O}async _createQualityMessage(e){const t=e.getUint32(),s=e.getFloat(),i=e.getFloat(),n=e.getFloat(),a=e.getFloat();return new P(t,s,i,n,a)}async _createClipboardMessage(e){const t=e.getUint32(),s=e.getString(t);return new A(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).then(n=>{t(new J(i,n,s,e.bufferLength))})})}async _createScreenResizeMessage(e){const t=e.getInt32(),s=e.getInt32();return new Q({width:t,height:s})}async _createKeyboardLayoutMessage(e){const t=e.getUint32(),s=e.getString(t);return new j(s)}}var Ne,Te=V("Lyogcm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DApO2NvbnN0IGk9YS5nZXRJbWFnZURhdGEoMCwwLHMscik7cmV0dXJuKChlLHQpPT57Zm9yKGxldCBzPTA7czxlLmxlbmd0aDtzKz00KWVbcyszXT10W3MrMV19KShuLmRhdGEsaS5kYXRhKSxufSkoZS5pbWFnZSx0LmltYWdlKTtyZXR1cm4gbmV3IHcoe2RhdGE6YS5kYXRhLHdpZHRoOnMsaGVpZ2h0OnJ9KX1pZihlKXtjb25zdCB0PWUud2lkdGgscz1lLmhlaWdodCxyPShlPT57aWYoZSl7Y29uc3QgdD1lLndpZHRoLHM9ZS5oZWlnaHQscj1uZXcgT2Zmc2NyZWVuQ2FudmFzKHQscykuZ2V0Q29udGV4dCgiMmQiLHt3aWxsUmVhZEZyZXF1ZW50bHk6ITB9KTtyZXR1cm4gci5kcmF3SW1hZ2UoZSwwLDApLHIuZ2V0SW1hZ2VEYXRhKDAsMCx0LHMpfXJldHVybiBudWxsfSkoZS5pbWFnZSk7cmV0dXJuIG5ldyB3KHtkYXRhOnIuZGF0YSx3aWR0aDp0LGhlaWdodDpzfSl9cmV0dXJuIG51bGx9fSgpOwovLyMgc291cmNlTWFwcGluZ1VSTD1XZWJYTWVzc2FnZURlY29kZXJXb3JrZXIuanMubWFwCgo=");class Fe{constructor(){this._pending=new Map,this._nextId=1,this._instructionEncoder=new ke,this._messageDecoder=new Le,"undefined"!=typeof Worker&&(this._worker=new Te,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===x.NOP?t=Object.create(B.prototype):e.type===x.CONNECTION?t=Object.create(K.prototype):e.type===x.SCREEN?t=Object.create(T.prototype):e.type===x.WINDOWS?t=Object.create(F.prototype):e.type===x.IMAGE?t=Object.create(z.prototype):e.type===x.SUBIMAGES?t=Object.create(Y.prototype):e.type===x.MOUSE?t=Object.create(H.prototype):e.type===x.CURSOR_IMAGE?t=Object.create(D.prototype):e.type===x.PING?t=Object.create(O.prototype):e.type===x.QUALITY?t=Object.create(P.prototype):e.type===x.CLIPBOARD?t=Object.create(A.prototype):e.type===x.SHAPE&&(t=Object.create(J.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 x.IMAGE:case x.SUBIMAGES:case x.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:N.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 ze{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 de(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<Xe.MESSAGE_HEADER_LENGTH)return console.warn("Message does not contain a valid header"),null;const t=new Xe(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 await this.handleMessage(s)}async 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==x.PING?this.sendInstruction(new we(e.timestampMs)):e.messageTypeId!=x.SUBIMAGES&&e.messageTypeId!=x.IMAGE||e.bufferLength>ze.MIN_BUFFER_LENGTH_FOR_ACK&&this.sendInstruction(new Ze(e.timestampMs,e.bufferLength))}}ze.MIN_BUFFER_LENGTH_FOR_ACK=32768;class Ye extends ze{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}}class He{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 fe(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 De{constructor(e){this._tunnel=e}async getWindowTexture(e){try{const t=await this._tunnel.sendRequest(new _e(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}}}!function(e){e[e.STARTING=0]="STARTING",e[e.RUNNING=1]="RUNNING"}(Ne||(Ne={}));class Oe{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(Ne.STARTING):(this._connected=!0,this._connectionStatusCallback(Ne.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:Pe}=require("../package.json");class Ae{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}set keyboardLayoutHandler(e){this._keyboardLayoutHandler=e}get maxQualityIndex(){return this._maxQualityIndex}get keyboardLayoutName(){return this._keyboardLayoutName}constructor(e,t){this._tunnel=e,this._options=t,this._tracers=new Map,this._clipboardHandler=e=>{},this._keyboardLayoutHandler=e=>{},this._connectionHandler=new Oe,this._maxQualityIndex=10,this._canResizeScreen=!1,this._windowImageFactory=new De(this._tunnel),this._cursorFactory=new He(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":Pe})}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(),{screenSize:o,maxQualityIndex:h,engineVersion:l,canResizeScreen:c,keyboardLayoutName:d}=r,{width:u,height:p}=o;this._maxQualityIndex=h,S.version=l,this._canResizeScreen=c,this._keyboardLayoutName=d,this._display=this.createDisplay(e,u,p);const m=await this._sendRequest(new me);return await this._display.updateWindows(m.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 ne(e,t,s,this._windowImageFactory,this._cursorFactory,this._options?.display)}createMouse(e){return new le(e)}createKeyboard(e){return new oe(e)}sendMouse(e){this._display.setMousePosition(e.x,e.y),this._sendInstruction(new ye(e.x,e.y,e.getButtonMask()))}sendKeyEvent(e,t){this._sendInstruction(new ge(e,t))}sendKeyDown(e){this.sendKeyEvent(e,!0)}sendKeyUp(e){this.sendKeyEvent(e,!1)}sendClipboardContent(e){this._sendInstruction(new Me(e))}registerTracer(e,t){this._tracers.set(e,t)}createDebugImageMessageHandler(){return this._display?new Ve(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 be(e);this._sendInstruction(t)}async createScreenshot(e,t){return this.display.createScreenshot(e,t)}resizeScreen(e,t){if(S.version.versionNumber>=1.5&&this._canResizeScreen){const s=new Ie(e,t);this._sendInstruction(s)}}canResizeScreen(){return S.version.versionNumber>=1.5&&this._canResizeScreen}setKeyboardLayout(e){if(S.version.versionNumber>=1.5){const t=new ve(e);this._sendInstruction(t)}}async _getScreenMessage(){let e=0;for(;e<3;)try{return await this._sendRequest(new pe,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 We&&t.handle(e)}))}_sendRequest(e,t){if(this._tunnel.isConnected())return this._tunnel.sendRequest(e,t)}async _handleMessage(e){if(e.type===x.CONNECTION){const t=e;return void this._connectionHandler.setConnected(t.isStarting)}if(e.type===x.NOP&&this._connectionHandler.resetTimer(),this._display){if(e.type===x.WINDOWS){const t=e.windows;this._display.updateWindows(t)}else if(e.type===x.IMAGE){const t=e;this._display.updateImage(t.windowId,t.depth,t.colorMap,t.alphaMap)}else if(e.type===x.SUBIMAGES){const t=e;this._display.updateSubImages(t.windowId,t.subImages)}else if(e.type===x.SHAPE){const t=e;this._display.updateShape(t.windowId,t.stencilMap)}else if(e.type===x.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===x.CLIPBOARD){const t=e;this._clipboardHandler(t.clipboardContent)}else if(e.type===x.SCREEN_RESIZE){const t=e,{width:s,height:i}=t.screenSize;this._display.screenWidth==s&&this._display.screenHeight==i||this._display.onScreenResized(s,i)}else if(e.type===x.KEYBOARD_LAYOUT){const t=e;this._keyboardLayoutName=t.keyboardLayoutName,this._keyboardLayoutHandler(t.keyboardLayoutName)}this._tracers.forEach(t=>{t instanceof Re&&t.handle(e)})}}_handleReceivedBytes(e){this._tracers.forEach(t=>{t instanceof Ue&&t.handle({received:e.byteLength,sent:0})})}_handleSentBytes(e){this._tracers.forEach(t=>{t instanceof Ue&&t.handle({received:0,sent:e.byteLength})})}_handleQuality(e){this._tracers.forEach(t=>{t instanceof Ue&&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)}}}export{Ae as WebXClient,Me as WebXClipboardInstruction,A as WebXClipboardMessage,ue as WebXConnectInstruction,Oe as WebXConnectionHandler,K as WebXConnectionMessage,Ne as WebXConnectionStatus,fe as WebXCursorImageInstruction,D as WebXCursorImageMessage,Ze as WebXDataAckInstruction,Ve as WebXDebugImageMessageHandler,ne as WebXDisplay,_e as WebXImageInstruction,z as WebXImageMessage,ce as WebXInstruction,We as WebXInstructionHandler,de as WebXInstructionResponse,ae as WebXInstructionType,oe as WebXKeyboard,xe as WebXKeyboardCombinationHandler,ge as WebXKeyboardInstruction,ve as WebXKeyboardLayoutInstruction,j as WebXKeyboardLayoutMessage,N as WebXMessage,Re as WebXMessageHandler,x as WebXMessageType,le as WebXMouse,ye as WebXMouseInstruction,H as WebXMouseMessage,he as WebXMouseState,B as WebXNopMessage,O as WebXPingMessage,we as WebXPongInstruction,be as WebXQualityInstruction,P as WebXQualityMessage,pe as WebXScreenInstruction,T as WebXScreenMessage,Ie as WebXScreenResizeInstruction,Q as WebXScreenResizeMessage,Se as WebXShapeInstruction,J as WebXShapeMessage,Ue as WebXStatsHandler,g as WebXSubImage,Y as WebXSubImagesMessage,I as WebXTexture,v as WebXTextureFactory,ze as WebXTunnel,Ye as WebXWebSocketTunnel,y as WebXWindowProperties,me as WebXWindowsInstruction,F as WebXWindowsMessage,f as alphaAndStencilBlend,b as alphaBufferBlend,w as colorAndAlphaBlendImageToImageData,Z as imageToImageData,W as toThreeTexture};
|
|
1
|
+
import*as e from"three";import{ShaderMaterial as t,BackSide as s,Color as i,Matrix3 as n,LinearFilter as a,MeshBasicMaterial as r,DataTexture as o,Mesh as h,ColorManagement as l,Vector3 as c,PlaneGeometry as d,Object3D as u}from"three";import{Group as p,Tween as m,Easing as _}from"@tweenjs/tween.js";class y{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 g{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 f=(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]},b=(e,t)=>{for(let s=0;s<e.length;s+=4)e[s+3]=t[s+1]},w=(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 b(a.data,r.data),a},Z=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};class M extends t{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(e){super({uniforms:{map:{value:null},alphaMap:{value:null},stencilMap:{value:null},mapTransform:{value:new n},alphaMapTransform:{value:new n},diffuse:{value:new i(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:s}),e&&e.color&&this.color.set(e.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 S{}class I{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 v{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 I({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 I({image:n});t(e)},n.onerror=e=>{console.warn(`Failed to create texture from binary data: ${e}`),s(e)},n.src=i})}}const W=t=>{if(t){const s=t.data?new e.DataTexture(t.data,t.width,t.height):new e.Texture(t.image);return s.needsUpdate=!0,s.flipY=t.flipY,s.minFilter=a,s}return null};class R{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(t,s){this._width=1,this._height=1,this._shaped=!1,this._loaded=!1,this._windowRefreshTimeout=null,this._windowImageFactory=s,this._colorIndex=R._COLOR_INDEX++,this._material=new M,this.visible=!1;const{id:i,x:n,y:a,z:r,width:o,height:h,shaped:l}=t;this._id=i,this._mesh=new e.Mesh(R._PLANE_GEOMETRY,this._material),this._mesh.onBeforeRender=()=>this._material.onBeforeRender(),this._x=n,this._y=a,this._z=r,this._width=o,this._height=h,this._shaped=l&&S.version.versionNumber>=1.4,this._updateScale(),this._updatePosition()}async loadWindowImage(){const e=await this._windowImageFactory.getWindowTexture(this._id);e&&this.updateTexture(e.depth,W(e.colorMap),W(e.alphaMap),!0)}async loadWindowShape(){const e=await this._windowImageFactory.getWindowStencilTexture(this._id);e?this.updateStencilTexture(W(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){null!=t&&(this.colorMap,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,this.colorMap,this.alphaMap,this._material.needsUpdate=!0,i||(this._windowRefreshTimeout&&(clearTimeout(this._windowRefreshTimeout),this._windowRefreshTimeout=null),this._windowRefreshTimeout=window.setTimeout(()=>{this._windowRefreshTimeout=null,this.loadWindowImage().then()},R.WINDOW_REFRESH_TIME_MS)))}updateStencilTexture(e){const t=this._shaped;e!=this.stencilMap&&(this._disposeStencilMap(),this.stencilMap=e),e?(e.minFilter=a,this.visible=null!=this.colorMap,this._shaped=!0):this._shaped=!1,t!==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)}}R.WINDOW_REFRESH_TIME_MS=5e3,R._PLANE_GEOMETRY=new e.PlaneGeometry(1,1,2,2),R._COLOR_INDEX=0;class U{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 M||this._mesh.material instanceof r){const e=this._mesh.material;if(this.updateStencilMap(e),e.map?.image){if(e.map!=this._colorMap||e.alphaMap!=this._alphaMap){this._colorMap=e.map,this._alphaMap=e.alphaMap;const t=e.map.image,s=t.width,i=t.height;if(this.isValidAlphaMap(e.alphaMap)||null!=this._stencilMap){const t=await this.blendAlphaAndStencil(e.map,e.alphaMap,0,0);this.resizeCanvas(s,i),this._context.putImageData(t,0,0)}else if(this.resizeCanvas(s,i),e.map instanceof o){const e=this.dataTextureToImageData(t);this._context.putImageData(e,0,0)}else this._context.clearRect(0,0,s,i),this._context.drawImage(t,0,0,s,i)}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 e of this._regionUpdates)if(e.dstColorMap===this._colorMap&&e.dstAlphaMap===this._alphaMap){const{srcColorMap:t,srcAlphaMap:s,width:i,height:n,dstPosition:a}=e,r=t.image;if(s||this._stencilData){const e=await this.blendAlphaAndStencil(t,s,a.x,a.y);e&&this._context.putImageData(e,a.x,a.y)}else if(t instanceof o){const e=this.dataTextureToImageData(r);this._context.putImageData(e,a.x,a.y)}else this._context.drawImage(r,0,0,i,n,a.x,a.y,i,n)}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(e){if(e instanceof M&&e.stencilMap){if(e.stencilMap!=this._stencilMap){this._stencilMap=e.stencilMap;const t=this._stencilMap.image,{width:s,height:i}=t;if(this._stencilMap instanceof o)this._stencilData=this.dataTextureToImageData(t);else{const e=this.createElementNS("canvas");e.width=s,e.height=i;const n=e.getContext("2d",{willReadFrequently:!0});n.drawImage(t,0,0),this._stencilData=n.getImageData(0,0,s,i)}}}else this._stencilMap&&(this._stencilMap=null,this._stencilData=null)}async blendAlphaAndStencil(e,t,s,i){const n=e instanceof o?this.dataTextureToImageData(e.image):this.getImageData(e.image),a=null==t?null:t instanceof o?this.dataTextureToImageData(t.image):this.getImageData(t.image),r=null==this._stencilData?null:this.getStencilDataRegion(s,i,n.width,n.height);return a||r?await this._imageBlender.blendAlphaAndStencil(n,a,r):n}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 C(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 V(e,t,s){var i;return function(t){return i=i||C(e),new Worker(i,t)}}var x,E=V("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7c2VsZi5vbm1lc3NhZ2U9ZT0+e2NvbnN0e2lkOmYsY29sb3JCdWZmZXI6bCxhbHBoYUJ1ZmZlcjp0LHN0ZW5jaWxCdWZmZXI6cix3aWR0aDpuLGhlaWdodDppfT1lLmRhdGEscz1uZXcgVWludDhDbGFtcGVkQXJyYXkobCk7KChlLGYsbCk9PntpZihmJiZsKWZvcihsZXQgdD0wO3Q8ZS5sZW5ndGg7dCs9NClsW3RdPDEyOD9lW3QrM109MDplW3QrM109Zlt0KzFdO2Vsc2UgaWYoZilmb3IobGV0IGw9MDtsPGUubGVuZ3RoO2wrPTQpZVtsKzNdPWZbbCsxXTtlbHNlIGlmKGwpZm9yKGxldCBmPTA7ZjxlLmxlbmd0aDtmKz00KWVbZiszXT1sW2ZdPDEyOD8wOmVbZiszXX0pKHMsdD9uZXcgVWludDhDbGFtcGVkQXJyYXkodCk6bnVsbCxyP25ldyBVaW50OENsYW1wZWRBcnJheShyKTpudWxsKSxzZWxmLnBvc3RNZXNzYWdlKHtpZDpmLGNvbG9yQnVmZmVyOnMuYnVmZmVyLHdpZHRoOm4saGVpZ2h0Oml9LFtzLmJ1ZmZlcl0pfX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9V2ViWEltYWdlQmxlbmRlcldvcmtlci5qcy5tYXAKCg==");class X{constructor(){this._pending=new Map,this._nextId=1,"undefined"!=typeof Worker&&(this._worker=new E,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 f(e.data,t?.data,s?.data),i(e)})}terminate(){this._worker.terminate(),this._pending.clear()}}class k{get domElement(){return this._desktopContainer}constructor(){this._clearColor=new i(0,0,0),this._windowCanvases=new Map,this.createMainElement(),this._imageBlender=new X}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(e,t){if(e.children.length>0){const t=e.children[0],s=new Set;for(const e of t.children)if(e instanceof h&&e.visible){this._windowCanvases.has(e.id)||this.createWindowCanvas(e);const t=this._windowCanvases.get(e.id);t.updateGeometry(),t.updateCanvas(),s.add(e.id)}for(const[e,t]of this._windowCanvases.entries())s.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 L{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 N{constructor(e,t=0){this.type=e,this.commandId=t}static get convertToImageDataInWorker(){return N._convertToImageDataInWorker}static set convertToImageDataInWorker(e){N._convertToImageDataInWorker=e}}N._convertToImageDataInWorker=!1,function(e){e[e.NOP=0]="NOP",e[e.CONNECTION=1]="CONNECTION",e[e.WINDOWS=2]="WINDOWS",e[e.IMAGE=3]="IMAGE",e[e.SCREEN=4]="SCREEN",e[e.SUBIMAGES=5]="SUBIMAGES",e[e.MOUSE=6]="MOUSE",e[e.CURSOR_IMAGE=7]="CURSOR_IMAGE",e[e.PING=8]="PING",e[e.DISCONNECT=9]="DISCONNECT",e[e.QUALITY=10]="QUALITY",e[e.CLIPBOARD=11]="CLIPBOARD",e[e.SHAPE=12]="SHAPE",e[e.SCREEN_RESIZE=13]="SCREEN_RESIZE",e[e.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT"}(x||(x={}));class T extends N{constructor(e,t,s,i,n,a){super(x.SCREEN,e),this.screenSize=t,this.maxQualityIndex=s,this.engineVersion=i,this.canResizeScreen=n,this.keyboardLayoutName=a}}class F extends N{constructor(e,t){super(x.WINDOWS,t),this.windows=e}}class z extends N{constructor(e,t,s,i,n,a){super(x.IMAGE,n),this.windowId=e,this.depth=t,this.colorMap=s,this.alphaMap=i,this.size=a}}class Y extends N{constructor(e,t,s,i){super(x.SUBIMAGES,s),this.windowId=e,this.subImages=t,this.size=i}}class H extends N{constructor(e,t,s,i){super(x.MOUSE,i),this.x=e,this.y=t,this.cursorId=s}}class D extends N{constructor(e,t,s,i,n,a,r){super(x.CURSOR_IMAGE,r),this.x=e,this.y=t,this.xHot=s,this.yHot=i,this.cursorId=n,this.texture=a}}class O extends N{constructor(){super(x.PING)}}class P extends N{constructor(e,t,s,i,n){super(x.QUALITY),this.index=e,this.imageFPS=t,this.rgbQuality=s,this.alphaQuality=i,this.maxMbps=n}}class A extends N{constructor(e){super(x.CLIPBOARD),this.clipboardContent=e}}class K extends N{constructor(e){super(x.CONNECTION),this.isStarting=e}}class B extends N{constructor(){super(x.NOP)}}class J extends N{constructor(e,t,s,i){super(x.SHAPE,s),this.windowId=e,this.stencilMap=t,this.size=i}}class Q extends N{constructor(e){super(x.SCREEN_RESIZE),this.screenSize=e}}class j extends N{constructor(e){super(x.KEYBOARD_LAYOUT),this.keyboardLayoutName=e}}class $ extends t{constructor(e){super(e)}}class q extends ${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 ee=e=>{const t={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",...(e=e||{})||{}};return Object.fromEntries(Object.entries(t).map(([t,s])=>{let n=null==e[t]?s:e[t];return"backgroundColor"===t&&(n=new i(n)),[t,{value:n}]}))};class te extends ${set tDiffuse(e){this.uniforms.tDiffuse.value=e}constructor(e){super({uniforms:ee(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 se{get name(){return this._name}constructor(t,s,i,n,a){if(this._rtTexture=null,this._name=t,this._renderer=s,this._filterMaterial=a,a){this._sceneScreen=new e.Scene,this._rtTexture=new e.WebGLRenderTarget(i,n),this._filterMaterial.tDiffuse=this._rtTexture.texture;const t=new e.PlaneGeometry(i,n),s=new e.Mesh(t,this._filterMaterial);s.rotateX(Math.PI),s.position.set(.5*i,.5*n,10),this._sceneScreen.add(s)}}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 ie{static Build(e,t,s,i,n){return e instanceof k?null:new se(i,e,t,s,ie._createFilterMaterial(i,n))}static _createFilterMaterial(e,t){return"test"===e?new q:"crt"===e?new te(t):(console.log(`Unknown filter ${e}`),null)}}class ne{get renderer(){return this._renderer}get filter(){return this._filter?.name}set filter(e){this._filter&&this._filter.dispose(),this._filter=e?ie.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,a,r,o){this._isWebGL=!0,this._windows=[],this._scale=1,this._disposed=!1,this._sceneDirty=!1,this._disableStencil=!1,l.enabled=!1,this._containerElement=t,this._screenWidth=s,this._screenHeight=n,this._windowImageFactory=a,this._options=o||{},this._cursor=new U(r),this._displayOverlay=new L(this._cursor),this._scene=new e.Scene,this._screen=new e.Object3D;const h=new e.Mesh(new e.PlaneGeometry(1,1,2,2),new e.MeshBasicMaterial({map:new e.DataTexture(new Uint8ClampedArray(4),1,1),side:e.BackSide,transparent:!0}));h.position.set(0,0,999),this._screen.add(h),this._camera=new e.OrthographicCamera(0,s,0,n,.1,1e4),this._camera.position.z=1e3,this._camera.lookAt(new c(0,0,0));const d=this._options.backgroundColor||window.getComputedStyle(this._containerElement).backgroundColor,u=this._detectWebGL2(),p=new URL(window.location.href).searchParams,m="true"===p.get("webx-canvas")||this._options.forceCanvas;if(this._disableStencil="false"===p.get("webx-stencil")||this._options.disableStencil,this._isWebGL=u.available&&!u.isSoftware&&!m,this._isWebGL){this._renderer=new e.WebGLRenderer;const t=this._options.filter?"string"==typeof this._options.filter?this._options.filter:this._options.filter.name:null,i=p.get("webx-filter")?p.get("webx-filter"):t;i&&(this._filter=ie.Build(this._renderer,s,n,i,this._getFilterParams()))}else console.log(`WebGL2 Info: available = ${u.available}, isSoftware = ${u.isSoftware}, vendor = ${u.vendor}, renderer = ${u.renderer}`),m?console.log("Canvas Renderer enabled through request param"):console.log("Falling back to Canvas Renderer"),this._renderer=new k,N.convertToImageDataInWorker=!0;this._renderer.setSize(s,n,!1),this._renderer.setClearColor(new i(d)),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}onScreenResized(e,t){this._screenWidth==e&&this._screenHeight==t||(this._screenWidth=e,this._screenHeight=t,this._displayElement.style.width=`${e}px`,this._displayElement.style.height=`${t}px`,this._renderer.setSize(this._screenWidth,this._screenHeight,!1),this._camera.right=this._screenWidth,this._camera.bottom=this._screenHeight,this._camera.updateProjectionMatrix(),this.filter&&(this.filter=this._filter.name),this.resize())}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 k)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 R({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,W(s),W(i),!0),this._sceneDirty=!0)}updateSubImages(t,s){const i=this.getWindow(t);if(null!=i&&i.colorMapValid){const t=i.colorMap,n=i.alphaMap;for(let a=0;a<s.length;a++){const r=s[a];this._renderer instanceof k?this._renderer.updateWindowRegion(i.mesh.id,W(r.colorMap),t,W(r.alphaMap),n,r.width,r.height,new e.Vector2(r.x,r.y)):(t&&r.colorMap&&this._renderer.copyTextureToTexture(W(r.colorMap),t,null,new e.Vector2(r.x,r.y)),n&&r.alphaMap&&this._renderer.copyTextureToTexture(W(r.alphaMap),n,null,new e.Vector2(r.x,r.y)))}i.updateTexture(i.depth,t,n,!1),this._sceneDirty=!0}}updateShape(e,t){if(this._disableStencil)return;const s=this.getWindow(e);null!=s&&null!=t&&(s.updateStencilTexture(W(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)}}_getFilterParams(){return{backgroundColor:this._options.backgroundColor||window.getComputedStyle(this._containerElement).backgroundColor,...this._options.filter?"string"==typeof this._options.filter?{}:this._options.filter.params:{}}}}var ae,re=re||{};re.Keyboard=function(e){var t=this,s="_GUAC_KEYBOARD_HANDLED_BY_"+re.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?R(e):0,this.modifiers=e?re.Keyboard.ModifierState.fromKeyboardEvent(e):new re.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=b(this.key,this.location)||Z(this.keyCode,this.location),this.keyupReliable=!i.keyupUnreliable,this.keysym&&!f(this.keysym)&&(this.reliable=!0),!this.keysym&&M(this.keyCode,this.keyIdentifier)&&(this.keysym=b(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};a.prototype=new n;var r=function(e){n.call(this,e),this.keysym=w(this.keyCode),this.reliable=!0};r.prototype=new n;var o=function(e){n.call(this,e),this.keysym=Z(this.keyCode,this.location)||b(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 re.Keyboard.ModifierState,this.pressed={};var u={},p={},m={},_=null,y=null,g=function(e,t){return e?e[t]||e[0]:null},f=function(e){return e>=0&&e<=255||16777216==(4294901760&e)};function b(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()),w(i.charCodeAt(0))}function w(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 M=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(_),window.clearInterval(y),d[e]||(_=window.setTimeout(function(){y=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(_),window.clearInterval(y),null!==e&&t.onkeyup&&t.onkeyup(e))},this.type=function(e){for(var s=0;s<e.length;s++){var i=w(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 S=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){S("alt",[65513,65514,65027],e),S("shift",[65505,65506],e),S("ctrl",[65507,65508],e),S("meta",[65511,65512],e),S("hyper",[65515,65516],e),t.modifiers=e.modifiers};function v(){var e,s=W();if(!s)return!1;do{e=s,s=W()}while(null!==s);return function(){for(var e in t.pressed)if(!u[e])return!1;return!0}()&&t.reset(),e.defaultPrevented}var W=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 m[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);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},R=function(e){return"location"in e?e.location:"keyLocation"in e?e.keyLocation:0},U=function(e){return!e[s]&&(e[s]=!0,!0)},G=function(e){if(t.onkeydown&&U(e)){var s=new a(e);e.isComposing||229===s.keyCode||(h.push(s),v()&&e.preventDefault())}},C=function(e){(t.onkeydown||t.onkeyup)&&U(e)&&(h.push(new r(e)),v()&&e.preventDefault())},V=function(e){t.onkeyup&&U(e)&&(e.preventDefault(),h.push(new o(e)),v())},x=function(e){(t.onkeydown||t.onkeyup)&&U(e)&&e.data&&!e.isComposing&&t.type(e.data)},E=function(t){e.removeEventListener("input",x,!1)},X=function(e){(t.onkeydown||t.onkeyup)&&U(e)&&e.data&&t.type(e.data)};this.listenTo=function(e){e.addEventListener("keydown",G,{passive:!1}),e.addEventListener("keypress",C,{passive:!1}),e.addEventListener("keyup",V,{passive:!1}),e.addEventListener("input",x,!1),e.addEventListener("compositionend",X,!1),e.addEventListener("compositionstart",E,!1)},e&&t.listenTo(e),this.dispose=function(){e&&(e.removeEventListener("keydown",G,!0),e.removeEventListener("keypress",C,!0),e.removeEventListener("keyup",V,!0),e.removeEventListener("input",x,!1),e.removeEventListener("compositionend",X,!1),e.removeEventListener("compositionstart",E,!1))}},re.Keyboard._nextID=0,re.Keyboard.ModifierState=function(){this.shift=!1,this.ctrl=!1,this.alt=!1,this.meta=!1,this.hyper=!1},re.Keyboard.ModifierState.fromKeyboardEvent=function(e){var t=new re.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 oe{set onKeyDown(e){this._keyboard.onkeydown=e}set onKeyUp(e){this._keyboard.onkeyup=e}constructor(e){this._keyboard=new re.Keyboard(e)}dispose(){this._keyboard.onkeydown=null,this._keyboard.onkeyup=null,this._keyboard.dispose()}reset(){this._keyboard.reset()}}class he{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 he({x:this._x,y:this._y,left:this._left,middle:this._middle,right:this._right,up:this._up,down:this._down})}}class le{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 he({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 ce{constructor(e){this.synchronous=!1,this.id=ce._INSTRUCTION_COUNTER++,this.type=e}}ce._INSTRUCTION_COUNTER=1;class de{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))}}!function(e){e[e.CONNECT=1]="CONNECT",e[e.WINDOWS=2]="WINDOWS",e[e.IMAGE=3]="IMAGE",e[e.SCREEN=4]="SCREEN",e[e.MOUSE=5]="MOUSE",e[e.KEYBOARD=6]="KEYBOARD",e[e.CURSOR_IMAGE=7]="CURSOR_IMAGE",e[e.QUALITY=8]="QUALITY",e[e.PONG=9]="PONG",e[e.DATA_ACK=10]="DATA_ACK",e[e.CLIPBOARD=11]="CLIPBOARD",e[e.SHAPE=12]="SHAPE",e[e.SCREEN_RESIZE=13]="SCREEN_RESIZE",e[e.KEYBOARD_LAYOUT=14]="KEYBOARD_LAYOUT"}(ae||(ae={})),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;case"SCREEN_RESIZE":return e.SCREEN_RESIZE}}}(ae||(ae={}));class ue extends ce{constructor(e){super(ae.CONNECT),this.parameters=e}}class pe extends ce{constructor(){super(ae.SCREEN)}}class me extends ce{constructor(){super(ae.WINDOWS)}}class _e extends ce{constructor(e){super(ae.IMAGE),this.windowId=e}}class ye extends ce{constructor(e,t,s){super(ae.MOUSE),this.x=e,this.y=t,this.buttonMask=s}}class ge extends ce{constructor(e,t){super(ae.KEYBOARD),this.key=e,this.pressed=t}}class fe extends ce{constructor(e){super(ae.CURSOR_IMAGE),this.cursorId=e}}class be extends ce{constructor(e){super(ae.QUALITY),this.qualityIndex=e}}class we extends ce{constructor(e){super(ae.PONG),this.timestampMs=e}}class Ze extends ce{constructor(e,t){super(ae.DATA_ACK),this.timestampMs=e,this.dataLength=t}}class Me extends ce{constructor(e){super(ae.CLIPBOARD),this.clipboardContent=e}}class Se extends ce{constructor(e){super(ae.SHAPE),this.windowId=e}}class Ie extends ce{constructor(e,t){super(ae.SCREEN_RESIZE),this.width=e,this.height=t}}class ve extends ce{constructor(e){super(ae.KEYBOARD_LAYOUT),this.keyboardLayout=e}}class We{}class Re{}class Ue{}class Ge{static randomColour(){const e=Math.floor(Math.random()*Ge._COLOURS.length);return Ge._COLOURS[e]}static indexedColour(e){return e%=Ge._COLOURS.length,Ge._COLOURS[e]}}Ge._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 Ce{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 Ve extends Re{constructor(e){super(),this._display=e,this._debugLayer=new u,this._currentZ=0,this._disposed=!1,this._tweenGroup=new p,this._debugLayer.position.set(0,0,999),this._scene=this._display.scene,this._scene.add(this._debugLayer),this._animate()}_createMesh(e,t,i,n,a){const o=new r({color:a,opacity:.8,transparent:!0});o.side=s;const l=new h(Ve._PLANE_GEOMETRY,o);l.position.set(e+i/2,t+n/2,this._currentZ),l.scale.set(i,n,1),this._currentZ+=1e-4,this._debugLayer.add(l),new m(o,this._tweenGroup).to({opacity:0},500).easing(_.Quadratic.Out).onComplete(()=>this._debugLayer.remove(l)).onUpdate(()=>this._display.sceneDirty=!0).start()}handle(e){if(e.type===x.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,Ge.indexedColour(s.colorIndex))}else if(e.type===x.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,Ge.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()})}}Ve._PLANE_GEOMETRY=new d(1,1,2,2);class xe extends We{constructor(e,t){super(),this._combination=e,this._callback=t,this._keys=[]}handle(e){if(e.type===ae.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(){}}class Ee{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 Xe{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=Xe.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}}Xe.MESSAGE_HEADER_LENGTH=48;class ke{encode(e){return e.type===ae.MOUSE?this._createMouseInstruction(e):e.type===ae.KEYBOARD?this._createKeyboardInstruction(e):e.type===ae.CURSOR_IMAGE?this._createCursorImageInstruction(e):e.type===ae.IMAGE?this._createImageInstruction(e):e.type===ae.CONNECT?this._createConnectInstruction(e):e.type===ae.SCREEN?this._createScreenInstruction(e):e.type===ae.WINDOWS?this._createWindowsInstruction(e):e.type===ae.QUALITY?this._createQualityInstruction(e):e.type===ae.PONG?this._createPongInstruction(e):e.type===ae.DATA_ACK?this._createDataAckInstruction(e):e.type===ae.CLIPBOARD?this._createClipboardInstruction(e):e.type===ae.SHAPE?this._createShapeInstruction(e):e.type===ae.SCREEN_RESIZE?this._createScreenResizeInstruction(e):e.type===ae.KEYBOARD_LAYOUT?this._createKeyboardLayoutInstruction(e):null}_createMouseInstruction(e){return new Ee(e,12).putInt32(e.x).putInt32(e.y).putUInt32(e.buttonMask).buffer()}_createCursorImageInstruction(e){return new Ee(e,4).putInt32(e.cursorId).buffer()}_createImageInstruction(e){return new Ee(e,4).putUInt32(e.windowId).buffer()}_createKeyboardInstruction(e){return new Ee(e,8).putUInt32(e.key).putBoolean(e.pressed).buffer()}_createScreenInstruction(e){return new Ee(e,0).buffer()}_createWindowsInstruction(e){return new Ee(e,0).buffer()}_createConnectInstruction(e){return new Ee(e,0).buffer()}_createQualityInstruction(e){return new Ee(e,4).putUInt32(e.qualityIndex).buffer()}_createPongInstruction(e){return new Ee(e,8).putUInt8Array(e.timestampMs,8).buffer()}_createDataAckInstruction(e){return new Ee(e,12).putUInt8Array(e.timestampMs,8).putUInt32(e.dataLength).buffer()}_createClipboardInstruction(e){const t=4+e.clipboardContent.length;return new Ee(e,t).putUInt32(e.clipboardContent.length).putString(e.clipboardContent).buffer()}_createShapeInstruction(e){return new Ee(e,4).putUInt32(e.windowId).buffer()}_createScreenResizeInstruction(e){return new Ee(e,8).putUInt32(e.width).putUInt32(e.height).buffer()}_createKeyboardLayoutInstruction(e){const t=4+e.keyboardLayout.length;return new Ee(e,t).putUInt32(e.keyboardLayout.length).putString(e.keyboardLayout).buffer()}}class Le{constructor(){this._textureFactory=new v}decode(e){const{messageTypeId:t}=e;return t===x.NOP?this._createNopMessage():t===x.CONNECTION?this._createConnectionMessage(e):t===x.SCREEN?this._createScreenMessage(e):t===x.WINDOWS?this._createWindowsMessage(e):t===x.IMAGE?this._createImageMessage(e):t===x.SUBIMAGES?this._createSubImagesMessage(e):t===x.MOUSE?this._createMouseMessage(e):t===x.CURSOR_IMAGE?this._createCursorImageMessage(e):t===x.PING?this._createPingMessage():t===x.QUALITY?this._createQualityMessage(e):t===x.CLIPBOARD?this._createClipboardMessage(e):t===x.SHAPE?this._createShapeMessage(e):t===x.SCREEN_RESIZE?this._createScreenResizeMessage(e):t===x.KEYBOARD_LAYOUT?this._createKeyboardLayoutMessage(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 B}async _createConnectionMessage(e){const t=e.getUint32();return new K(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),c=e.getUint8Array(h),d=this._textureFactory.createTextureFromArray(l,r),u=this._textureFactory.createTextureFromArray(c,r);Promise.all([d,u]).then(([a,r])=>{t(new z(i,n,a,r,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(),r=e.getUint32(),o=e.getString(4),h=this._determineMimeType(o),l=e.getUint32(),c=e.getUint32(),d=e.getUint8Array(l),u=e.getUint8Array(c),p=new Promise((e,n)=>{const o=this._textureFactory.createTextureFromArray(d,h),l=this._textureFactory.createTextureFromArray(u,h);Promise.all([o,l]).then(([n,o])=>{e(new g({x:t,y:s,width:i,height:a,depth:r,colorMap:n,alphaMap:o}))}).catch(n)});n.push(p)}Promise.all(n).then(n=>{t(new Y(i,n,s,e.bufferLength))})})}async _createMouseMessage(e){const t=e.getUint32(),s=e.getInt32(),i=e.getInt32(),n=e.getUint32();return new H(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(S.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 F(i.map(e=>new y(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");return new D(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;e.bufferLength-e.readOffset>=12&&(a=e.getUint32(),r=e.getUint32(),o=e.getUint32()),S.version=new Ce(a,r,o);let h=!1;e.bufferLength-e.readOffset>=4&&(h=e.getUint32()>0);let l=null;if(e.bufferLength-e.readOffset>=4){const t=e.getUint32();l=e.getString(t)}return new T(t,{width:s,height:i},n,new Ce(a,r,o),h,l)}async _createPingMessage(){return new O}async _createQualityMessage(e){const t=e.getUint32(),s=e.getFloat(),i=e.getFloat(),n=e.getFloat(),a=e.getFloat();return new P(t,s,i,n,a)}async _createClipboardMessage(e){const t=e.getUint32(),s=e.getString(t);return new A(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).then(n=>{t(new J(i,n,s,e.bufferLength))})})}async _createScreenResizeMessage(e){const t=e.getInt32(),s=e.getInt32();return new Q({width:t,height:s})}async _createKeyboardLayoutMessage(e){const t=e.getUint32(),s=e.getString(t);return new j(s)}}var Ne,Te=V("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZXtjb25zdHJ1Y3RvcihlLHQ9MCl7dGhpcy50eXBlPWUsdGhpcy5jb21tYW5kSWQ9dH1zdGF0aWMgZ2V0IGNvbnZlcnRUb0ltYWdlRGF0YUluV29ya2VyKCl7cmV0dXJuIGUuX2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OnJ9KX1pZihlKXtjb25zdCB0PWUud2lkdGgscz1lLmhlaWdodCxyPShlPT57aWYoZSl7Y29uc3QgdD1lLndpZHRoLHM9ZS5oZWlnaHQscj1uZXcgT2Zmc2NyZWVuQ2FudmFzKHQscykuZ2V0Q29udGV4dCgiMmQiLHt3aWxsUmVhZEZyZXF1ZW50bHk6ITB9KTtyZXR1cm4gci5kcmF3SW1hZ2UoZSwwLDApLHIuZ2V0SW1hZ2VEYXRhKDAsMCx0LHMpfXJldHVybiBudWxsfSkoZS5pbWFnZSk7cmV0dXJuIG5ldyB3KHtkYXRhOnIuZGF0YSx3aWR0aDp0LGhlaWdodDpzfSl9cmV0dXJuIG51bGx9fSgpOwovLyMgc291cmNlTWFwcGluZ1VSTD1XZWJYTWVzc2FnZURlY29kZXJXb3JrZXIuanMubWFwCgo=");class Fe{constructor(){this._pending=new Map,this._nextId=1,this._instructionEncoder=new ke,this._messageDecoder=new Le,"undefined"!=typeof Worker&&(this._worker=new Te,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===x.NOP?t=Object.create(B.prototype):e.type===x.CONNECTION?t=Object.create(K.prototype):e.type===x.SCREEN?t=Object.create(T.prototype):e.type===x.WINDOWS?t=Object.create(F.prototype):e.type===x.IMAGE?t=Object.create(z.prototype):e.type===x.SUBIMAGES?t=Object.create(Y.prototype):e.type===x.MOUSE?t=Object.create(H.prototype):e.type===x.CURSOR_IMAGE?t=Object.create(D.prototype):e.type===x.PING?t=Object.create(O.prototype):e.type===x.QUALITY?t=Object.create(P.prototype):e.type===x.CLIPBOARD?t=Object.create(A.prototype):e.type===x.SHAPE&&(t=Object.create(J.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 x.IMAGE:case x.SUBIMAGES:case x.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:N.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 ze{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 de(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<Xe.MESSAGE_HEADER_LENGTH)return console.warn("Message does not contain a valid header"),null;const t=new Xe(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 await this.handleMessage(s)}async 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==x.PING?this.sendInstruction(new we(e.timestampMs)):e.messageTypeId!=x.SUBIMAGES&&e.messageTypeId!=x.IMAGE||e.bufferLength>ze.MIN_BUFFER_LENGTH_FOR_ACK&&this.sendInstruction(new Ze(e.timestampMs,e.bufferLength))}}ze.MIN_BUFFER_LENGTH_FOR_ACK=32768;class Ye extends ze{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}}class He{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 fe(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 De{constructor(e){this._tunnel=e}async getWindowTexture(e){try{const t=await this._tunnel.sendRequest(new _e(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}}}!function(e){e[e.STARTING=0]="STARTING",e[e.RUNNING=1]="RUNNING"}(Ne||(Ne={}));class Oe{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(Ne.STARTING):(this._connected=!0,this._connectionStatusCallback(Ne.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:Pe}=require("../package.json");class Ae{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}set keyboardLayoutHandler(e){this._keyboardLayoutHandler=e}get maxQualityIndex(){return this._maxQualityIndex}get keyboardLayoutName(){return this._keyboardLayoutName}constructor(e,t){this._tunnel=e,this._options=t,this._tracers=new Map,this._clipboardHandler=e=>{},this._keyboardLayoutHandler=e=>{},this._connectionHandler=new Oe,this._maxQualityIndex=10,this._canResizeScreen=!1,this._windowImageFactory=new De(this._tunnel),this._cursorFactory=new He(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":Pe})}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(),{screenSize:o,maxQualityIndex:h,engineVersion:l,canResizeScreen:c,keyboardLayoutName:d}=r,{width:u,height:p}=o;this._maxQualityIndex=h,S.version=l,this._canResizeScreen=c,this._keyboardLayoutName=d,this._display=this.createDisplay(e,u,p);const m=await this._sendRequest(new me);return await this._display.updateWindows(m.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 ne(e,t,s,this._windowImageFactory,this._cursorFactory,this._options?.display)}createMouse(e){return new le(e)}createKeyboard(e){return new oe(e)}sendMouse(e){this._display.setMousePosition(e.x,e.y),this._sendInstruction(new ye(e.x,e.y,e.getButtonMask()))}sendKeyEvent(e,t){this._sendInstruction(new ge(e,t))}sendKeyDown(e){this.sendKeyEvent(e,!0)}sendKeyUp(e){this.sendKeyEvent(e,!1)}sendClipboardContent(e){this._sendInstruction(new Me(e))}registerTracer(e,t){this._tracers.set(e,t)}createDebugImageMessageHandler(){return this._display?new Ve(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 be(e);this._sendInstruction(t)}async createScreenshot(e,t){return this.display.createScreenshot(e,t)}resizeScreen(e,t){if(S.version.versionNumber>=1.5&&this._canResizeScreen){const s=new Ie(e,t);this._sendInstruction(s)}}canResizeScreen(){return S.version.versionNumber>=1.5&&this._canResizeScreen}setKeyboardLayout(e){if(S.version.versionNumber>=1.5){const t=new ve(e);this._sendInstruction(t)}}canChangeKeyboardLayout(){return S.version.versionNumber>=1.5}async _getScreenMessage(){let e=0;for(;e<3;)try{return await this._sendRequest(new pe,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 We&&t.handle(e)}))}_sendRequest(e,t){if(this._tunnel.isConnected())return this._tunnel.sendRequest(e,t)}async _handleMessage(e){if(e.type===x.CONNECTION){const t=e;return void this._connectionHandler.setConnected(t.isStarting)}if(e.type===x.NOP&&this._connectionHandler.resetTimer(),this._display){if(e.type===x.WINDOWS){const t=e.windows;this._display.updateWindows(t)}else if(e.type===x.IMAGE){const t=e;this._display.updateImage(t.windowId,t.depth,t.colorMap,t.alphaMap)}else if(e.type===x.SUBIMAGES){const t=e;this._display.updateSubImages(t.windowId,t.subImages)}else if(e.type===x.SHAPE){const t=e;this._display.updateShape(t.windowId,t.stencilMap)}else if(e.type===x.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===x.CLIPBOARD){const t=e;this._clipboardHandler(t.clipboardContent)}else if(e.type===x.SCREEN_RESIZE){const t=e,{width:s,height:i}=t.screenSize;this._display.screenWidth==s&&this._display.screenHeight==i||this._display.onScreenResized(s,i)}else if(e.type===x.KEYBOARD_LAYOUT){const t=e;this._keyboardLayoutName=t.keyboardLayoutName,this._keyboardLayoutHandler(t.keyboardLayoutName)}this._tracers.forEach(t=>{t instanceof Re&&t.handle(e)})}}_handleReceivedBytes(e){this._tracers.forEach(t=>{t instanceof Ue&&t.handle({received:e.byteLength,sent:0})})}_handleSentBytes(e){this._tracers.forEach(t=>{t instanceof Ue&&t.handle({received:0,sent:e.byteLength})})}_handleQuality(e){this._tracers.forEach(t=>{t instanceof Ue&&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)}}}export{Ae as WebXClient,Me as WebXClipboardInstruction,A as WebXClipboardMessage,ue as WebXConnectInstruction,Oe as WebXConnectionHandler,K as WebXConnectionMessage,Ne as WebXConnectionStatus,fe as WebXCursorImageInstruction,D as WebXCursorImageMessage,Ze as WebXDataAckInstruction,Ve as WebXDebugImageMessageHandler,ne as WebXDisplay,_e as WebXImageInstruction,z as WebXImageMessage,ce as WebXInstruction,We as WebXInstructionHandler,de as WebXInstructionResponse,ae as WebXInstructionType,oe as WebXKeyboard,xe as WebXKeyboardCombinationHandler,ge as WebXKeyboardInstruction,ve as WebXKeyboardLayoutInstruction,j as WebXKeyboardLayoutMessage,N as WebXMessage,Re as WebXMessageHandler,x as WebXMessageType,le as WebXMouse,ye as WebXMouseInstruction,H as WebXMouseMessage,he as WebXMouseState,B as WebXNopMessage,O as WebXPingMessage,we as WebXPongInstruction,be as WebXQualityInstruction,P as WebXQualityMessage,pe as WebXScreenInstruction,T as WebXScreenMessage,Ie as WebXScreenResizeInstruction,Q as WebXScreenResizeMessage,Se as WebXShapeInstruction,J as WebXShapeMessage,Ue as WebXStatsHandler,g as WebXSubImage,Y as WebXSubImagesMessage,I as WebXTexture,v as WebXTextureFactory,ze as WebXTunnel,Ye as WebXWebSocketTunnel,y as WebXWindowProperties,me as WebXWindowsInstruction,F as WebXWindowsMessage,f as alphaAndStencilBlend,b as alphaBufferBlend,w as colorAndAlphaBlendImageToImageData,Z as imageToImageData,W as toThreeTexture};
|
package/package.json
CHANGED