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