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