spice-client 1.0.0

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.
Files changed (74) hide show
  1. package/COPYING +674 -0
  2. package/COPYING.LESSER +165 -0
  3. package/LICENSE +14 -0
  4. package/README.cn.md +143 -0
  5. package/README.md +143 -0
  6. package/dist/cjs/index.js +14 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/esm/atKeynames.d.ts +92 -0
  9. package/dist/esm/atKeynames.d.ts.map +1 -0
  10. package/dist/esm/bitmap.d.ts +11 -0
  11. package/dist/esm/bitmap.d.ts.map +1 -0
  12. package/dist/esm/code_to_scancode.d.ts +148 -0
  13. package/dist/esm/code_to_scancode.d.ts.map +1 -0
  14. package/dist/esm/cursor.d.ts +6 -0
  15. package/dist/esm/cursor.d.ts.map +1 -0
  16. package/dist/esm/display.d.ts +26 -0
  17. package/dist/esm/display.d.ts.map +1 -0
  18. package/dist/esm/enums.d.ts +312 -0
  19. package/dist/esm/enums.d.ts.map +1 -0
  20. package/dist/esm/filexfer.d.ts +14 -0
  21. package/dist/esm/filexfer.d.ts.map +1 -0
  22. package/dist/esm/index.d.ts +9 -0
  23. package/dist/esm/index.d.ts.map +1 -0
  24. package/dist/esm/index.js +5328 -0
  25. package/dist/esm/index.js.map +1 -0
  26. package/dist/esm/inputs.d.ts +31 -0
  27. package/dist/esm/inputs.d.ts.map +1 -0
  28. package/dist/esm/lz.d.ts +2 -0
  29. package/dist/esm/lz.d.ts.map +1 -0
  30. package/dist/esm/main.d.ts +49 -0
  31. package/dist/esm/main.d.ts.map +1 -0
  32. package/dist/esm/playback.d.ts +18 -0
  33. package/dist/esm/playback.d.ts.map +1 -0
  34. package/dist/esm/png.d.ts +2 -0
  35. package/dist/esm/png.d.ts.map +1 -0
  36. package/dist/esm/port.d.ts +9 -0
  37. package/dist/esm/port.d.ts.map +1 -0
  38. package/dist/esm/quic.d.ts +19 -0
  39. package/dist/esm/quic.d.ts.map +1 -0
  40. package/dist/esm/resize.d.ts +4 -0
  41. package/dist/esm/resize.d.ts.map +1 -0
  42. package/dist/esm/simulatecursor.d.ts +26 -0
  43. package/dist/esm/simulatecursor.d.ts.map +1 -0
  44. package/dist/esm/spicearraybuffer.d.ts +2 -0
  45. package/dist/esm/spicearraybuffer.d.ts.map +1 -0
  46. package/dist/esm/spiceconn.d.ts +46 -0
  47. package/dist/esm/spiceconn.d.ts.map +1 -0
  48. package/dist/esm/spicedataview.d.ts +13 -0
  49. package/dist/esm/spicedataview.d.ts.map +1 -0
  50. package/dist/esm/spicemsg.d.ts +469 -0
  51. package/dist/esm/spicemsg.d.ts.map +1 -0
  52. package/dist/esm/spicetype.d.ts +125 -0
  53. package/dist/esm/spicetype.d.ts.map +1 -0
  54. package/dist/esm/thirdparty/jsbn.d.ts +52 -0
  55. package/dist/esm/thirdparty/jsbn.d.ts.map +1 -0
  56. package/dist/esm/thirdparty/prng4.d.ts +12 -0
  57. package/dist/esm/thirdparty/prng4.d.ts.map +1 -0
  58. package/dist/esm/thirdparty/rng.d.ts +4 -0
  59. package/dist/esm/thirdparty/rng.d.ts.map +1 -0
  60. package/dist/esm/thirdparty/rsa.d.ts +15 -0
  61. package/dist/esm/thirdparty/rsa.d.ts.map +1 -0
  62. package/dist/esm/thirdparty/sha1.d.ts +10 -0
  63. package/dist/esm/thirdparty/sha1.d.ts.map +1 -0
  64. package/dist/esm/ticket.d.ts +4 -0
  65. package/dist/esm/ticket.d.ts.map +1 -0
  66. package/dist/esm/utils.d.ts +16 -0
  67. package/dist/esm/utils.d.ts.map +1 -0
  68. package/dist/esm/webm.d.ts +142 -0
  69. package/dist/esm/webm.d.ts.map +1 -0
  70. package/dist/esm/wire.d.ts +14 -0
  71. package/dist/esm/wire.d.ts.map +1 -0
  72. package/dist/global/spice-client.min.js +14 -0
  73. package/dist/global/spice-client.min.js.map +1 -0
  74. package/package.json +436 -0
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o={SPICE_MAGIC:"REDQ",SPICE_VERSION_MAJOR:2,SPICE_VERSION_MINOR:2,SPICE_CONNECT_TIMEOUT:30*1e3,SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION:0,SPICE_COMMON_CAP_AUTH_SPICE:1,SPICE_COMMON_CAP_AUTH_SASL:2,SPICE_COMMON_CAP_MINI_HEADER:3,SPICE_TICKET_KEY_PAIR_LENGTH:1024,SPICE_TICKET_PUBKEY_BYTES:1024/8+34,SPICE_LINK_ERR_OK:0,SPICE_LINK_ERR_ERROR:1,SPICE_LINK_ERR_INVALID_MAGIC:2,SPICE_LINK_ERR_INVALID_DATA:3,SPICE_LINK_ERR_VERSION_MISMATCH:4,SPICE_LINK_ERR_NEED_SECURED:5,SPICE_LINK_ERR_NEED_UNSECURED:6,SPICE_LINK_ERR_PERMISSION_DENIED:7,SPICE_LINK_ERR_BAD_CONNECTION_ID:8,SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE:9,SPICE_MSG_MIGRATE:1,SPICE_MSG_MIGRATE_DATA:2,SPICE_MSG_SET_ACK:3,SPICE_MSG_PING:4,SPICE_MSG_WAIT_FOR_CHANNELS:5,SPICE_MSG_DISCONNECTING:6,SPICE_MSG_NOTIFY:7,SPICE_MSG_LIST:8,SPICE_MSG_MAIN_MIGRATE_BEGIN:101,SPICE_MSG_MAIN_MIGRATE_CANCEL:102,SPICE_MSG_MAIN_INIT:103,SPICE_MSG_MAIN_CHANNELS_LIST:104,SPICE_MSG_MAIN_MOUSE_MODE:105,SPICE_MSG_MAIN_MULTI_MEDIA_TIME:106,SPICE_MSG_MAIN_AGENT_CONNECTED:107,SPICE_MSG_MAIN_AGENT_DISCONNECTED:108,SPICE_MSG_MAIN_AGENT_DATA:109,SPICE_MSG_MAIN_AGENT_TOKEN:110,SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST:111,SPICE_MSG_MAIN_MIGRATE_END:112,SPICE_MSG_MAIN_NAME:113,SPICE_MSG_MAIN_UUID:114,SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS:115,SPICE_MSG_MAIN_MIGRATE_BEGIN_SEAMLESS:116,SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK:117,SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK:118,SPICE_MSG_END_MAIN:119,SPICE_MSGC_ACK_SYNC:1,SPICE_MSGC_ACK:2,SPICE_MSGC_PONG:3,SPICE_MSGC_MIGRATE_FLUSH_MARK:4,SPICE_MSGC_MIGRATE_DATA:5,SPICE_MSGC_DISCONNECTING:6,SPICE_MSGC_MAIN_CLIENT_INFO:101,SPICE_MSGC_MAIN_MIGRATE_CONNECTED:102,SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR:103,SPICE_MSGC_MAIN_ATTACH_CHANNELS:104,SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST:105,SPICE_MSGC_MAIN_AGENT_START:106,SPICE_MSGC_MAIN_AGENT_DATA:107,SPICE_MSGC_MAIN_AGENT_TOKEN:108,SPICE_MSGC_MAIN_MIGRATE_END:109,SPICE_MSGC_END_MAIN:110,SPICE_MSG_DISPLAY_MODE:101,SPICE_MSG_DISPLAY_MARK:102,SPICE_MSG_DISPLAY_RESET:103,SPICE_MSG_DISPLAY_COPY_BITS:104,SPICE_MSG_DISPLAY_INVAL_LIST:105,SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS:106,SPICE_MSG_DISPLAY_INVAL_PALETTE:107,SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES:108,SPICE_MSG_DISPLAY_STREAM_CREATE:122,SPICE_MSG_DISPLAY_STREAM_DATA:123,SPICE_MSG_DISPLAY_STREAM_CLIP:124,SPICE_MSG_DISPLAY_STREAM_DESTROY:125,SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL:126,SPICE_MSG_DISPLAY_DRAW_FILL:302,SPICE_MSG_DISPLAY_DRAW_OPAQUE:303,SPICE_MSG_DISPLAY_DRAW_COPY:304,SPICE_MSG_DISPLAY_DRAW_BLEND:305,SPICE_MSG_DISPLAY_DRAW_BLACKNESS:306,SPICE_MSG_DISPLAY_DRAW_WHITENESS:307,SPICE_MSG_DISPLAY_DRAW_INVERS:308,SPICE_MSG_DISPLAY_DRAW_ROP3:309,SPICE_MSG_DISPLAY_DRAW_STROKE:310,SPICE_MSG_DISPLAY_DRAW_TEXT:311,SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:312,SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:313,SPICE_MSG_DISPLAY_SURFACE_CREATE:314,SPICE_MSG_DISPLAY_SURFACE_DESTROY:315,SPICE_MSG_DISPLAY_STREAM_DATA_SIZED:316,SPICE_MSG_DISPLAY_MONITORS_CONFIG:317,SPICE_MSG_DISPLAY_DRAW_COMPOSITE:318,SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT:319,SPICE_MSGC_DISPLAY_INIT:101,SPICE_MSGC_DISPLAY_STREAM_REPORT:102,SPICE_MSG_INPUTS_INIT:101,SPICE_MSG_INPUTS_KEY_MODIFIERS:102,SPICE_MSG_INPUTS_MOUSE_MOTION_ACK:111,SPICE_MSGC_INPUTS_KEY_DOWN:101,SPICE_MSGC_INPUTS_KEY_UP:102,SPICE_MSGC_INPUTS_KEY_MODIFIERS:103,SPICE_MSGC_INPUTS_MOUSE_MOTION:111,SPICE_MSGC_INPUTS_MOUSE_POSITION:112,SPICE_MSGC_INPUTS_MOUSE_PRESS:113,SPICE_MSGC_INPUTS_MOUSE_RELEASE:114,SPICE_MSG_CURSOR_INIT:101,SPICE_MSG_CURSOR_RESET:102,SPICE_MSG_CURSOR_SET:103,SPICE_MSG_CURSOR_MOVE:104,SPICE_MSG_CURSOR_HIDE:105,SPICE_MSG_CURSOR_TRAIL:106,SPICE_MSG_CURSOR_INVAL_ONE:107,SPICE_MSG_CURSOR_INVAL_ALL:108,SPICE_MSG_PLAYBACK_DATA:101,SPICE_MSG_PLAYBACK_MODE:102,SPICE_MSG_PLAYBACK_START:103,SPICE_MSG_PLAYBACK_STOP:104,SPICE_MSG_PLAYBACK_VOLUME:105,SPICE_MSG_PLAYBACK_MUTE:106,SPICE_MSG_PLAYBACK_LATENCY:107,SPICE_MSG_SPICEVMC_DATA:101,SPICE_MSG_PORT_INIT:201,SPICE_MSG_PORT_EVENT:202,SPICE_MSG_END_PORT:203,SPICE_MSGC_SPICEVMC_DATA:101,SPICE_MSGC_PORT_EVENT:201,SPICE_MSGC_END_PORT:202,SPICE_PLAYBACK_CAP_CELT_0_5_1:0,SPICE_PLAYBACK_CAP_VOLUME:1,SPICE_PLAYBACK_CAP_LATENCY:2,SPICE_PLAYBACK_CAP_OPUS:3,SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE:0,SPICE_MAIN_CAP_NAME_AND_UUID:1,SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS:2,SPICE_MAIN_CAP_SEAMLESS_MIGRATE:3,SPICE_DISPLAY_CAP_SIZED_STREAM:0,SPICE_DISPLAY_CAP_MONITORS_CONFIG:1,SPICE_DISPLAY_CAP_COMPOSITE:2,SPICE_DISPLAY_CAP_A8_SURFACE:3,SPICE_DISPLAY_CAP_STREAM_REPORT:4,SPICE_DISPLAY_CAP_LZ4_COMPRESSION:5,SPICE_DISPLAY_CAP_PREF_COMPRESSION:6,SPICE_DISPLAY_CAP_GL_SCANOUT:7,SPICE_DISPLAY_CAP_MULTI_CODEC:8,SPICE_DISPLAY_CAP_CODEC_MJPEG:9,SPICE_DISPLAY_CAP_CODEC_VP8:10,SPICE_AUDIO_DATA_MODE_INVALID:0,SPICE_AUDIO_DATA_MODE_RAW:1,SPICE_AUDIO_DATA_MODE_CELT_0_5_1:2,SPICE_AUDIO_DATA_MODE_OPUS:3,SPICE_AUDIO_FMT_INVALID:0,SPICE_AUDIO_FMT_S16:1,SPICE_CHANNEL_MAIN:1,SPICE_CHANNEL_DISPLAY:2,SPICE_CHANNEL_INPUTS:3,SPICE_CHANNEL_CURSOR:4,SPICE_CHANNEL_PLAYBACK:5,SPICE_CHANNEL_RECORD:6,SPICE_CHANNEL_TUNNEL:7,SPICE_CHANNEL_SMARTCARD:8,SPICE_CHANNEL_USBREDIR:9,SPICE_CHANNEL_PORT:10,SPICE_CHANNEL_WEBDAV:11,SPICE_SURFACE_FLAGS_PRIMARY:1,SPICE_NOTIFY_SEVERITY_INFO:0,SPICE_NOTIFY_SEVERITY_WARN:1,SPICE_NOTIFY_SEVERITY_ERROR:2,SPICE_MOUSE_MODE_SERVER:1,SPICE_MOUSE_MODE_CLIENT:2,SPICE_MOUSE_MODE_MASK:3,SPICE_CLIP_TYPE_NONE:0,SPICE_CLIP_TYPE_RECTS:1,SPICE_IMAGE_TYPE_BITMAP:0,SPICE_IMAGE_TYPE_QUIC:1,SPICE_IMAGE_TYPE_RESERVED:2,SPICE_IMAGE_TYPE_LZ_PLT:100,SPICE_IMAGE_TYPE_LZ_RGB:101,SPICE_IMAGE_TYPE_GLZ_RGB:102,SPICE_IMAGE_TYPE_LZ4_RGB:103,SPICE_IMAGE_TYPE_FROM_CACHE:104,SPICE_IMAGE_TYPE_SURFACE:105,SPICE_IMAGE_TYPE_JPEG:106,SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:107,SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB:108,SPICE_IMAGE_TYPE_JPEG_ALPHA:109,SPICE_IMAGE_TYPE_LZ4:110,SPICE_IMAGE_FLAGS_CACHE_ME:1,SPICE_IMAGE_FLAGS_HIGH_BITS_SET:2,SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME:4,SPICE_BITMAP_FLAGS_PAL_CACHE_ME:1,SPICE_BITMAP_FLAGS_PAL_FROM_CACHE:2,SPICE_BITMAP_FLAGS_TOP_DOWN:4,SPICE_BITMAP_FLAGS_MASK:7,SPICE_BITMAP_FMT_INVALID:0,SPICE_BITMAP_FMT_1BIT_LE:1,SPICE_BITMAP_FMT_1BIT_BE:2,SPICE_BITMAP_FMT_4BIT_LE:3,SPICE_BITMAP_FMT_4BIT_BE:4,SPICE_BITMAP_FMT_8BIT:5,SPICE_BITMAP_FMT_16BIT:6,SPICE_BITMAP_FMT_24BIT:7,SPICE_BITMAP_FMT_32BIT:8,SPICE_BITMAP_FMT_RGBA:9,SPICE_CURSOR_FLAGS_NONE:1,SPICE_CURSOR_FLAGS_CACHE_ME:2,SPICE_CURSOR_FLAGS_FROM_CACHE:4,SPICE_CURSOR_FLAGS_MASK:7,SPICE_MOUSE_BUTTON_MASK_LEFT:1,SPICE_MOUSE_BUTTON_MASK_MIDDLE:2,SPICE_MOUSE_BUTTON_MASK_RIGHT:4,SPICE_MOUSE_BUTTON_MASK_MASK:7,SPICE_MOUSE_BUTTON_INVALID:0,SPICE_MOUSE_BUTTON_LEFT:1,SPICE_MOUSE_BUTTON_MIDDLE:2,SPICE_MOUSE_BUTTON_RIGHT:3,SPICE_MOUSE_BUTTON_UP:4,SPICE_MOUSE_BUTTON_DOWN:5,SPICE_BRUSH_TYPE_NONE:0,SPICE_BRUSH_TYPE_SOLID:1,SPICE_BRUSH_TYPE_PATTERN:2,SPICE_SURFACE_FMT_INVALID:0,SPICE_SURFACE_FMT_1_A:1,SPICE_SURFACE_FMT_8_A:8,SPICE_SURFACE_FMT_16_555:16,SPICE_SURFACE_FMT_32_xRGB:32,SPICE_SURFACE_FMT_16_565:80,SPICE_SURFACE_FMT_32_ARGB:96,SPICE_ROPD_INVERS_SRC:1,SPICE_ROPD_INVERS_BRUSH:2,SPICE_ROPD_INVERS_DEST:4,SPICE_ROPD_OP_PUT:8,SPICE_ROPD_OP_OR:16,SPICE_ROPD_OP_AND:32,SPICE_ROPD_OP_XOR:64,SPICE_ROPD_OP_BLACKNESS:128,SPICE_ROPD_OP_WHITENESS:256,SPICE_ROPD_OP_INVERS:512,SPICE_ROPD_INVERS_RES:1024,SPICE_ROPD_MASK:2047,LZ_IMAGE_TYPE_INVALID:0,LZ_IMAGE_TYPE_PLT1_LE:1,LZ_IMAGE_TYPE_PLT1_BE:2,LZ_IMAGE_TYPE_PLT4_LE:3,LZ_IMAGE_TYPE_PLT4_BE:4,LZ_IMAGE_TYPE_PLT8:5,LZ_IMAGE_TYPE_RGB16:6,LZ_IMAGE_TYPE_RGB24:7,LZ_IMAGE_TYPE_RGB32:8,LZ_IMAGE_TYPE_RGBA:9,LZ_IMAGE_TYPE_XXXA:10,LZ_IMAGE_TYPE_LZ4_PLT1_LE:21,LZ_IMAGE_TYPE_LZ4_PLT1_BE:22,LZ_IMAGE_TYPE_LZ4_PLT4_LE:23,LZ_IMAGE_TYPE_LZ4_PLT4_BE:24,LZ_IMAGE_TYPE_LZ4_PLT8:25,LZ_IMAGE_TYPE_LZ4_RGB16:26,LZ_IMAGE_TYPE_LZ4_RGB24:27,LZ_IMAGE_TYPE_LZ4_RGB32:28,LZ_IMAGE_TYPE_LZ4_RGBA:29,LZ_IMAGE_TYPE_LZ4_XXXA:30,SPICE_INPUT_MOTION_ACK_BUNCH:4,SPICE_CURSOR_TYPE_ALPHA:0,SPICE_CURSOR_TYPE_MONO:1,SPICE_CURSOR_TYPE_COLOR4:2,SPICE_CURSOR_TYPE_COLOR8:3,SPICE_CURSOR_TYPE_COLOR16:4,SPICE_CURSOR_TYPE_COLOR24:5,SPICE_CURSOR_TYPE_COLOR32:6,SPICE_VIDEO_CODEC_TYPE_MJPEG:1,SPICE_VIDEO_CODEC_TYPE_VP8:2,VD_AGENT_PROTOCOL:1,VD_AGENT_MAX_DATA_SIZE:2048,VD_AGENT_MOUSE_STATE:1,VD_AGENT_MONITORS_CONFIG:2,VD_AGENT_REPLY:3,VD_AGENT_CLIPBOARD:4,VD_AGENT_DISPLAY_CONFIG:5,VD_AGENT_ANNOUNCE_CAPABILITIES:6,VD_AGENT_CLIPBOARD_GRAB:7,VD_AGENT_CLIPBOARD_REQUEST:8,VD_AGENT_CLIPBOARD_RELEASE:9,VD_AGENT_FILE_XFER_START:10,VD_AGENT_FILE_XFER_STATUS:11,VD_AGENT_FILE_XFER_DATA:12,VD_AGENT_CLIENT_DISCONNECTED:13,VD_AGENT_MAX_CLIPBOARD:14,VD_AGENT_CAP_MOUSE_STATE:0,VD_AGENT_CAP_MONITORS_CONFIG:1,VD_AGENT_CAP_REPLY:2,VD_AGENT_CAP_CLIPBOARD:3,VD_AGENT_CAP_DISPLAY_CONFIG:4,VD_AGENT_CAP_CLIPBOARD_BY_DEMAND:5,VD_AGENT_CAP_CLIPBOARD_SELECTION:6,VD_AGENT_CAP_SPARSE_MONITORS_CONFIG:7,VD_AGENT_CAP_GUEST_LINEEND_LF:8,VD_AGENT_CAP_GUEST_LINEEND_CRLF:9,VD_AGENT_CAP_MAX_CLIPBOARD:10,VD_AGENT_END_CAP:11,VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:0,VD_AGENT_FILE_XFER_STATUS_CANCELLED:1,VD_AGENT_FILE_XFER_STATUS_ERROR:2,VD_AGENT_FILE_XFER_STATUS_SUCCESS:3,VD_AGENT_CLIPBOARD_NONE:0,VD_AGENT_CLIPBOARD_UTF8_TEXT:1,VD_AGENT_CLIPBOARD_IMAGE_PNG:2,VD_AGENT_CLIPBOARD_IMAGE_BMP:3,VD_AGENT_CLIPBOARD_IMAGE_TIFF:4,VD_AGENT_CLIPBOARD_IMAGE_JPG:5};class m{constructor(t,e,s){e!==void 0?s!==void 0?this.u8=new Uint8Array(t,e,s):this.u8=new Uint8Array(t,e):this.u8=new Uint8Array(t)}getUint8(t,e){return this.u8[t]}getUint16(t,e){let s=1,i=0;return e&&(s=0,i=1),this.u8[t+i]<<8|this.u8[t+s]}getUint32(t,e){let s=2,i=0;return e&&(s=0,i=2),this.getUint16(t+i,e)<<16|this.getUint16(t+s,e)}getUint64(t,e){let s=4,i=0;return e&&(s=0,i=4),this.getUint32(t+i,e)<<32|this.getUint32(t+s,e)}setUint8(t,e,s){this.u8[t]=e&255}setUint16(t,e,s){let i=1,n=0;s&&(i=0,n=1),this.u8[t+n]=(e&65535)>>8,this.u8[t+i]=e&255}setUint32(t,e,s){let i=2,n=0;s&&(i=0,n=2),this.setUint16(t+n,(e&4294967295)>>16,s),this.setUint16(t+i,e&65535,s)}setUint64(t,e,s){let i=4,n=0;s&&(i=0,n=4),this.setUint32(t+n,(e&18446744073709552e3)>>32,s),this.setUint32(t+i,e&4294967295,s)}}let x;class A{constructor(t,e,s){t!=null&&(typeof t=="number"?this.fromNumber(t,e,s):e==null&&typeof t!="string"?this.fromString(t,256):this.fromString(t,e))}copyTo(t){for(let e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}fromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}fromString(t,e){let s;if(e==16)s=4;else if(e==8)s=3;else if(e==256)s=8;else if(e==2)s=1;else if(e==32)s=5;else if(e==4)s=2;else{this.fromRadix(t,e);return}this.t=0,this.s=0;let i=t.length,n=!1,_=0;for(;--i>=0;){const h=s==8?t[i]&255:this.intAt(t,i);if(h<0){t.charAt(i)=="-"&&(n=!0);continue}n=!1,_==0?this[this.t++]=h:_+s>this.DB?(this[this.t-1]|=(h&(1<<this.DB-_)-1)<<_,this[this.t++]=h>>this.DB-_):this[this.t-1]|=h<<_,_+=s,_>=this.DB&&(_-=this.DB)}s==8&&t[0]&128&&(this.s=-1,_>0&&(this[this.t-1]|=(1<<this.DB-_)-1<<_)),this.clamp(),n&&A.ZERO.subTo(this,this)}clamp(){const t=this.s&this.DM;for(;this.t>0&&this[this.t-1]==t;)--this.t}toString(t){if(this.s<0)return"-"+this.negate().toString(t);let e;if(t==16)e=4;else if(t==8)e=3;else if(t==2)e=1;else if(t==32)e=5;else if(t==4)e=2;else return this.toRadix(t);const s=(1<<e)-1;let i,n=this.t,_=this.DB-n*this.DB%e,h="";if(n-- >0)for(_<this.DB&&(i=this[n]>>_)>0&&(h+=this.int2char(i));n>=0;)_<e?(i=(this[n]&(1<<_)-1)<<e-_,i|=this[--n]>>(_+=this.DB-e)):(i=this[n]>>(_-=e)&s,_<=0&&(_+=this.DB,--n)),(i>0||h.length>0)&&(h+=this.int2char(i));return h.length>0?h:"0"}negate(){const t=this.nbi();return A.ZERO.subTo(this,t),t}abs(){return this.s<0?this.negate():this}compareTo(t){const e=this.s-t.s;if(e!=0)return e;const s=this.t,i=s-t.t;if(i!=0)return i;for(let n=s-1;n>=0;n--){const _=this[n]-t[n];if(_!=0)return _}return 0}bitLength(){return this.t<=0?0:this.DB*(this.t-1)+this.nbits(this[this.t-1]^this.s&this.DM)}dlShiftTo(t,e){for(let s=this.t-1;s>=0;--s)e[s+t]=this[s];for(let s=t-1;s>=0;--s)e[s]=0;e.t=this.t+t,e.s=this.s}drShiftTo(t,e){for(let s=t;s<this.t;++s)e[s-t]=this[s];e.t=Math.max(this.t-t,0),e.s=this.s}lShiftTo(t,e){const s=t%this.DB,i=this.DB-s,n=(1<<i)-1,_=Math.floor(t/this.DB);let h=this.s<<s&this.DM;for(let c=this.t-1;c>=0;--c)e[c+_+1]=this[c]>>i|h,h=(this[c]&n)<<s;for(let c=_-1;c>=0;--c)e[c]=0;e[_]=h,e.t=this.t+_+1,e.s=this.s,e.clamp()}rShiftTo(t,e){e.s=this.s;const s=Math.floor(t/this.DB);if(s>=this.t){e.t=0;return}const i=t%this.DB,n=this.DB-i,_=(1<<i)-1;e[0]=this[s]>>i;for(let h=s+1;h<this.t;++h)e[h-s-1]|=(this[h]&_)<<n,e[h-s]=this[h]>>i;i>0&&(e[this.t-s-1]|=(this.s&_)<<n),e.t=this.t-s,e.clamp()}subTo(t,e){let s=0,i=0;const n=Math.min(t.t,this.t);for(;s<n;)i+=this[s]-t[s],e[s++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;s<this.t;)i+=this[s],e[s++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;s<t.t;)i-=t[s],e[s++]=i&this.DM,i>>=this.DB;i-=t.s}e.s=i<0?-1:0,i<-1?e[s++]=this.DV+i:i>0&&(e[s++]=i),e.t=s,e.clamp()}multiplyTo(t,e){const s=this.abs(),i=t.abs(),n=s.t;e.t=n+i.t;for(let _=e.t-1;_>=0;--_)e[_]=0;for(let _=0;_<i.t;++_)e[_+s.t]=s.am(0,i[_],e,_,0,s.t);e.s=0,e.clamp(),this.s!=t.s&&A.ZERO.subTo(e,e)}squareTo(t){const e=this.abs();let s=t.t=2*e.t;for(let i=s-1;i>=0;--i)t[i]=0;for(s=0;s<e.t-1;++s){const i=e.am(s,e[s],t,2*s,0,1);(t[s+e.t]+=e.am(s+1,2*e[s],t,2*s+1,i,e.t-s-1))>=e.DV&&(t[s+e.t]-=e.DV,t[s+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(s,e[s],t,2*s,0,1)),t.s=0,t.clamp()}divRemTo(t,e,s){const i=t.abs();if(i.t<=0)return;const n=this.abs();if(n.t<i.t){e!=null&&e.fromInt(0),s!=null&&this.copyTo(s);return}s==null&&(s=this.nbi());const _=this.nbi(),h=this.s,c=t.s,a=this.DB-this.nbits(i[i.t-1]);a>0?(i.lShiftTo(a,_),n.lShiftTo(a,s)):(i.copyTo(_),n.copyTo(s));const d=_.t,E=_[d-1];if(E==0)return;const S=E*(1<<this.F1)+(d>1?_[d-2]>>this.F2:0),p=this.FV/S,I=(1<<this.F1)/S,b=1<<this.F2;let C=s.t,T=C-d;const w=e??this.nbi();for(_.dlShiftTo(T,w),s.compareTo(w)>=0&&(s[s.t++]=1,s.subTo(w,s)),A.ONE.dlShiftTo(d,w),w.subTo(_,_);_.t<d;)_[_.t++]=0;for(;--T>=0;){let D=s[--C]==E?this.DM:Math.floor(s[C]*p+(s[C-1]+b)*I);if((s[C]+=_.am(0,D,s,T,0,d))<D)for(_.dlShiftTo(T,w),s.subTo(w,s);s[C]<--D;)s.subTo(w,s)}e!=null&&(s.drShiftTo(d,e),h!=c&&A.ZERO.subTo(e,e)),s.t=d,s.clamp(),a>0&&s.rShiftTo(a,s),h<0&&A.ZERO.subTo(s,s)}mod(t){const e=this.nbi();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(A.ZERO)>0&&t.subTo(e,e),e}invDigit(){if(this.t<1)return 0;const t=this[0];if(!(t&1))return 0;let e=t&3;return e=e*(2-(t&15)*e)&15,e=e*(2-(t&255)*e)&255,e=e*(2-((t&65535)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e}isEven(){return(this.t>0?this[0]&1:this.s)==0}exp(t,e){if(t>4294967295||t<1)return A.ONE;let s=this.nbi(),i=this.nbi();const n=e.convert(this);let _=this.nbits(t)-1;for(n.copyTo(s);--_>=0;)if(e.sqrTo(s,i),(t&1<<_)>0)e.mulTo(i,n,s);else{const h=s;s=i,i=h}return e.revert(s)}modPowInt(t,e){let s;return t<256||e.isEven()?s=new ms(e):s=new Ss(e),this.exp(t,s)}multiply(t){const e=this.nbi();return this.multiplyTo(t,e),e}add(t){const e=this.nbi();return this.addTo(t,e),e}nbi(){return new A}nbits(t){let e=1,s;return(s=t>>>16)!=0&&(t=s,e+=16),(s=t>>8)!=0&&(t=s,e+=8),(s=t>>4)!=0&&(t=s,e+=4),(s=t>>2)!=0&&(t=s,e+=2),(s=t>>1)!=0&&(t=s,e+=1),e}fromRadix(t,e){this.t=0,this.s=0;let s=0,i=!1;t.length>0&&t.charAt(0)==="-"&&(i=!0,s=1);const n=new A(e);for(;s<t.length;s++){const _=this.intAt(t,s);if(!(_<0||_>=e)){if(this.t>0){const h=this.nbi();this.multiplyTo(n,h),h.copyTo(this)}if(this.t===0)this.fromInt(_);else{const h=new A(_),c=this.nbi();this.addTo(h,c),c.copyTo(this)}}}i&&A.ZERO.subTo(this,this)}addTo(t,e){let s=0,i=0;const n=Math.min(t.t,this.t);for(;s<n;)i+=this[s]+t[s],e[s++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;s<this.t;)i+=this[s],e[s++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;s<t.t;)i+=t[s],e[s++]=i&this.DM,i>>=this.DB;i+=t.s}e.s=i<0?-1:0,i>0?e[s++]=i:i<-1&&(e[s++]=this.DV+i),e.t=s,e.clamp()}toRadix(t){if(this.signum()==0)return"0";const e=this.signum()<0,s=this.nbi();this.copyTo(s),e&&A.ZERO.subTo(s,s);const i=[],n=this.nbi(),_=this.nbi(),h=new A(t);for(;s.compareTo(h)>=0;)s.divRemTo(h,n,_),i.push(this.int2char(_[0])),n.copyTo(s);return i.push(this.int2char(s[0])),e&&i.push("-"),i.reverse(),i.join("")}signum(){return this.s<0?-1:this.t<=0?0:1}dMultiply(t){if(this.t===0){t>0&&(this[0]=t,this.t=1);return}let e=0;for(let s=0;s<this.t;s++){const i=this[s]*t+e;this[s]=i&this.DM,e=i/this.DV}e>0&&(this[this.t++]=e),this.clamp()}int2char(t){return A.RM.charAt(t)}intAt(t,e){const s=A.RC[t.charCodeAt(e)];return s??-1}fromNumber(t,e,s){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}}typeof navigator<"u"?navigator.appName=="Microsoft Internet Explorer"?x=30:navigator.appName!="Netscape"?x=26:x=28:x=28;function fs(r,t,e,s,i,n){for(;--n>=0;){const _=t*this[r++]+e[s]+i;i=Math.floor(_/67108864),e[s++]=_&67108863}return i}function Es(r,t,e,s,i,n){const _=t&32767,h=t>>15;for(;--n>=0;){let c=this[r]&32767;const a=this[r++]>>15,d=h*c+a*_;c=_*c+((d&32767)<<15)+e[s]+(i&1073741823),i=(c>>>30)+(d>>>15)+h*a+(i>>>30),e[s++]=c&1073741823}return i}function ps(r,t,e,s,i,n){const _=t&16383,h=t>>14;for(;--n>=0;){let c=this[r]&16383;const a=this[r++]>>14,d=h*c+a*_;c=_*c+((d&16383)<<14)+e[s]+i,i=(c>>28)+(d>>14)+h*a,e[s++]=c&268435455}return i}x==26?A.prototype.am=fs:x==30?A.prototype.am=Es:A.prototype.am=ps;A.prototype.DB=x;A.prototype.DM=(1<<x)-1;A.prototype.DV=1<<x;const ze=52;A.prototype.FV=Math.pow(2,ze);A.prototype.F1=ze-x;A.prototype.F2=2*x-ze;A.RM="0123456789abcdefghijklmnopqrstuvwxyz";A.RC=[];let _e=48;for(let r=0;r<=9;++r)A.RC[_e++]=r;_e=97;for(let r=10;r<36;++r)A.RC[_e++]=r;_e=65;for(let r=10;r<36;++r)A.RC[_e++]=r;function Ye(){return new A}function vt(r){const t=Ye();return t.fromInt(r),t}class ms{constructor(t){this.m=t}convert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}revert(t){return t}reduce(t){t.divRemTo(this.m,null,t)}mulTo(t,e,s){t.multiplyTo(e,s),this.reduce(s)}sqrTo(t,e){t.squareTo(e),this.reduce(e)}}class Ss{constructor(t){this.m=t,this.mp=t.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}convert(t){const e=Ye();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(A.ZERO)>0&&this.m.subTo(e,e),e}revert(t){const e=Ye();return t.copyTo(e),this.reduce(e),e}reduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(let e=0;e<this.m.t;++e){const s=t[e]&32767,i=s*this.mpl+((s*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&this.m.DM;let n=e+this.m.t;for(t[n]+=this.m.am(0,i,t,e,0,this.m.t);t[n]>=this.m.DV;)t[n]-=this.m.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}sqrTo(t,e){t.squareTo(e),this.reduce(e)}mulTo(t,e,s){t.multiplyTo(e,s),this.reduce(s)}}A.ZERO=vt(0);A.ONE=vt(1);class Is{constructor(){this.i=0,this.j=0,this.S=[]}init(t){let e,s,i;for(e=0;e<256;++e)this.S[e]=e;for(s=0,e=0;e<256;++e)s=s+this.S[e]+t[e%t.length]&255,i=this.S[e],this.S[e]=this.S[s],this.S[s]=i;this.i=0,this.j=0}next(){let t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}}function As(){return new Is}const ve=256;let oe,k,G;function Cs(r){k[G++]^=r&255,k[G++]^=r>>8&255,k[G++]^=r>>16&255,k[G++]^=r>>24&255,G>=ve&&(G-=ve)}function Kt(){Cs(new Date().getTime())}if(k==null){k=[],G=0;let r;if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&window.crypto){const t=window.crypto.random(32);for(r=0;r<t.length;++r)k[G++]=t.charCodeAt(r)&255}for(;G<ve;)r=Math.floor(65536*Math.random()),k[G++]=r>>>8,k[G++]=r&255;G=0,Kt()}function gs(){if(oe==null){for(Kt(),oe=As(),oe.init(k),G=0;G<k.length;++G)k[G]=0;G=0}return oe.next()}function bs(r){let t;for(t=0;t<r.length;++t)r[t]=gs()}class Bt{nextBytes(t){bs(t)}}function Ps(r,t){return new A(r,t)}function ws(r,t){if(t<r.length+11)return alert("Message too long for RSA"),null;const e=[];let s=r.length-1;for(;s>=0&&t>0;){const _=r.charCodeAt(s--);_<128?e[--t]=_:_>127&&_<2048?(e[--t]=_&63|128,e[--t]=_>>6|192):(e[--t]=_&63|128,e[--t]=_>>6&63|128,e[--t]=_>>12|224)}e[--t]=0;const i=new Bt,n=[];for(;t>2;){for(n[0]=0;n[0]==0;)i.nextBytes(n);e[--t]=n[0]}return e[--t]=2,e[--t]=0,new A(e)}class Ms{constructor(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}setPublic(t,e){t!=null&&e!=null&&t.length>0&&e.length>0?(this.n=Ps(t,16),this.e=parseInt(e,16)):alert("Invalid RSA public key")}doPublic(t){return t.modPowInt(this.e,this.n)}encrypt(t){if(!this.n)return null;const e=ws(t,this.n.bitLength()+7>>3);if(e==null)return null;const s=this.doPublic(e);if(s==null)return null;const i=s.toString(16);return i.length&1?"0"+i:i}}let Le=0;function Ts(r){return ys(Ve(Ds(r)))}function Ve(r){return Us(Ns(Ls(r),r.length*8))}function ys(r){try{}catch{Le=0}const t=Le?"0123456789ABCDEF":"0123456789abcdef";let e="",s;for(let i=0;i<r.length;i++)s=r.charCodeAt(i),e+=t.charAt(s>>>4&15)+t.charAt(s&15);return e}function Ds(r){let t="",e=-1,s,i;for(;++e<r.length;)s=r.charCodeAt(e),i=e+1<r.length?r.charCodeAt(e+1):0,s>=55296&&s<=56319&&i>=56320&&i<=57343&&(s=65536+((s&1023)<<10)+(i&1023),e++),s<=127?t+=String.fromCharCode(s):s<=2047?t+=String.fromCharCode(192|s>>>6&31,128|s&63):s<=65535?t+=String.fromCharCode(224|s>>>12&15,128|s>>>6&63,128|s&63):s<=2097151&&(t+=String.fromCharCode(240|s>>>18&7,128|s>>>12&63,128|s>>>6&63,128|s&63));return t}function Ls(r){const t=Array(r.length>>2);for(var e=0;e<t.length;e++)t[e]=0;for(var e=0;e<r.length*8;e+=8)t[e>>5]|=(r.charCodeAt(e/8)&255)<<24-e%32;return t}function Us(r){let t="";for(let e=0;e<r.length*32;e+=8)t+=String.fromCharCode(r[e>>5]>>>24-e%32&255);return t}function Ns(r,t){r[t>>5]|=128<<24-t%32,r[(t+64>>9<<4)+15]=t;const e=Array(80);let s=1732584193,i=-271733879,n=-1732584194,_=271733878,h=-1009589776;for(let c=0;c<r.length;c+=16){const a=s,d=i,E=n,S=_,p=h;for(let I=0;I<80;I++){I<16?e[I]=r[c+I]:e[I]=Ue(e[I-3]^e[I-8]^e[I-14]^e[I-16],1);const b=z(z(Ue(s,5),Rs(I,i,n,_)),z(z(h,e[I]),Gs(I)));h=_,_=n,n=Ue(i,30),i=s,s=b}s=z(s,a),i=z(i,d),n=z(n,E),_=z(_,S),h=z(h,p)}return Array(s,i,n,_,h)}function Rs(r,t,e,s){return r<20?t&e|~t&s:r<40?t^e^s:r<60?t&e|t&s|e&s:t^e^s}function Gs(r){return r<20?1518500249:r<40?1859775393:r<60?-1894007588:-899497514}function z(r,t){const e=(r&65535)+(t&65535);return(r>>16)+(t>>16)+(e>>16)<<16|e&65535}function Ue(r,t){return r<<t|r>>>32-t}const Ne=20;function Ze(r,t){let e=0,s=0,i=0;for(e=0,i=0;i<r.length;e++){let n=new String;for(s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);n+=String.fromCharCode(e>>24&255),n+=String.fromCharCode(e>>16&255),n+=String.fromCharCode(e>>8&255),n+=String.fromCharCode(e&255);const _=Ve(n);for(s=0;s<_.length&&i<r.length;s++,i++)r[i]=_.charCodeAt(s)}return 0}function Os(r,t,e){const s=new Array(Ne);new Bt().nextBytes(s);const n=r-1-s.length,_=new Array(n),h=n-t.length-1;let c;if(e===void 0&&(e=""),h<Ne)return console.log("Error - data too large for key size."),null;for(c=0;c<h;c++)_[c]=0;const a=Ve(e);for(c=0;c<a.length;c++)_[c]=a.charCodeAt(c);for(_[h]=1,c=0;c<t.length;c++)_[c+h+1]=t.charCodeAt(c);const d=new Array(n);for(Ze(d,s)<0,c=0;c<d.length;c++)_[c]^=d[c];const E=Array(Ne);for(Ze(E,_)<0,c=0;c<E.length;c++)s[c]^=E[c];let S=new String;for(S+="\0",c=0;c<s.length;c++)S+=String.fromCharCode(s[c]);for(c=0;c<_.length;c++)S+=String.fromCharCode(_[c]);return S}function ce(r,t){let e=r[t++];if(e>128){if(e!=129)return console.log("Error: we lazily don't support keys bigger than 255 bytes. It'd be easy to fix."),null;e=r[t++]}return[t,e]}function Re(r,t){let e;return t=t||0,r[t++]!=48?(console.log("Error: public key should start with a sequence flag."),null):(e=ce(r,t),e||null)}function Ys(r,t){const e=new Uint8Array(r);let s,i,n,_,h;if(i=Re(e,t),!i||(t=i[0],i=Re(e,t),!i))return null;if(t=i[0]+i[1],e[t++]!=3)return console.log("Error: expecting bit string next."),null;if(s=ce(e,t),!s)return null;if(t=s[0],e[t]!=0&&e[t+1]!=48)return console.log("Error: unexpected values in bit string."),null;if(i=Re(e,t+1),!i)return null;if(t=i[0],e[t++]!=2)return console.log("Error: expecting integer n next."),null;if(s=ce(e,t),!s)return null;for(t=s[0],n=new Array(s[1]),_=0;_<s[1];_++)n[_]=e[t+_];if(h=new Ms,h.n=new A(n),t+=s[1],e[t++]!=2)return console.log("Error: expecting integer e next."),null;if(s=ce(e,t),!s)return null;for(t=s[0],h.e=e[t++],_=1;_<s[1];_++)h.e<<=8,h.e|=e[t++];return h}function vs(r,t){let e;const s=[];if(!r.n)return null;const i=Os(r.n.bitLength()+7>>3,t);if(!i)return null;const n=new Array(i.length);for(e=0;e<i.length;e++)n[e]=i.charCodeAt(e);const _=new A(n);let c=r.doPublic(_).toString(16);for(c.length&1&&(c="0"+c),e=0;e<c.length;e+=2)s[e/2]=parseInt(c.substring(e,e+2),16);return s}let X;const R={QUIC_IMAGE_TYPE_INVALID:0,QUIC_IMAGE_TYPE_GRAY:1,QUIC_IMAGE_TYPE_RGB16:2,QUIC_IMAGE_TYPE_RGB24:3,QUIC_IMAGE_TYPE_RGB32:4,QUIC_IMAGE_TYPE_RGBA:5},Ks=3,Bs=6,ks=2048;let je=!0;const Qe=26,kt=Ks,V=Bs,te=ks,xs={nGRcodewords:[0,0,0,0,0,0,0,0],notGRcwlen:[0,0,0,0,0,0,0,0],notGRprefixmask:[0,0,0,0,0,0,0,0],notGRsuffixlen:[0,0,0,0,0,0,0,0],xlatU2L:[0,0,0,0,0,0,0,0],xlatL2U:[0,0,0,0,0,0,0,0]},L={nGRcodewords:[0,0,0,0,0,0,0,0],notGRcwlen:[0,0,0,0,0,0,0,0],notGRprefixmask:[0,0,0,0,0,0,0,0],notGRsuffixlen:[0,0,0,0,0,0,0,0],xlatU2L:[0,0,0,0,0,0,0,0],xlatL2U:[0,0,0,0,0,0,0,0]},O=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,2147483647,4294967295],xt=[],Fs=[[550,900,800,700,500,350,300,200,180,180,160],[110,550,900,800,550,400,350,250,140,160,140],[100,120,550,900,700,500,400,300,220,250,160]],le=[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,15],he=[8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],zs=[46495042,893548311,794435923,2453991765,2077388039,894197842,1462934312,697534094,1826128012,343623392,2581292719,3811265708,459739748,2638427270,1654964626,101227083,2654850628,3668700691,572794346,2758751005,3445133904,2344099199,3367450297,898927923,3618406352,1606297603,754696453,20823118,2050458127,972590750,3990194068,3305596553,4239238564,1690498157,3015324227,2306127097,1510321853,548392192,971157512,2292288069,1611390505,4086766286,4084927083,1883326811,1891043243,113180603,1107690783,3778825955,3248980775,2443839100,2190866218,1932072870,495393613,1078522166,4051963518,1784694977,1768732442,2146763203,264646923,1474361405,2361552500,296035746,2489922759,2094565616,2409465348,1334241083,72483606,3740181004,4057920662,1734898312,4114662834,574624900,880305546,3258472262,26713132,1571648456,52557195,4043234286,2458021343,676064371,1528437109,64953873,546717185,2709319979,1947039598,2812723004,28691684,286829174,4235176970,3465707163,12526951,2154766700,3165032534,2036061161,3386656087,2301212354,2023576300,1061142336,3105452904,2743866805,3283373992,3397596080,3085489552,3196092395,3210707808,3651022684,925444321,2088074316,230011220,3223248386,533229176,523863486,3028311159,13140218,2538347282,900399636,3000796173,1526771255,3541282854,2992674461,2135722105,389334227,1225164337,3119947809,1803959919,3471171263,704170491,1407019136,1924534819,526887421,168782227,333811993,298623278,4268451686,381087740,2542899140,3266880867,2498950977,200969370,3511909096,3252303004,2268881098,2499828613,2606499854,3163208665,3790254546,1840025712,1319758833,3771674836,519421307,3512796222,1563402978,4284300462,2263719815,715250337,3178437172,2660191010,2982332026,3256309961,2709659997,3434092872,2367065591,69438718,915160508,183164069,3134331940,175242981,2680543346,1421955782,4231173251,1736652874,3990568476,1710820912,2286604440,3464587098,1261907837,1757387321,1128554270,1090050251,2429922486,1288729218,882830086,211637042,1376462063,2147615815,1737974929,798170275,4271572277,4241687072,1638524620,2760366295,1065115089,2097227717,1224023317,1625204849,3383303351,1488272307,2640186157,1649047732,819719707,2615091943,502645401,760628135,4108137983,63606742,1404337880,1865161130,4272996852,1239761976,790984678,3213322601,1917062825,4195069880,1962259360,2111002573,2311983960,1861406170,511141875,2797510619,1331661048,3130608186,147483493,3767089176,2650841450,4096523407,2574446300,1956416337,851468126,3607527519,1811658703,3642821136,832691095,2453312857,933732854,94341217,3393797730,1695907457,2405722077,2877685663,2469507058,2249636341,3988608661,4001245617,825934927,3103985967,1127151177,3691656896,1640967098,2168932645,2830550957,3998822878,3002602893,1509651465,775813869,2599574079,3791574229],g=3,Y=2,v=1,K=0,P=4;function Je(r){if(r===1)return 0;let t=1;for(r-=1;r=r>>>1;)t++;return t}function $e(r,t,e){let s;for(s=0;s<t;s++){let h,c;h=e-t,h>O[t-s]&&(h=O[t-s]),c=O[t]+1-(h<<s),r.nGRcodewords[s]=h<<s,r.notGRcwlen[s]=h+Je(c),r.notGRprefixmask[s]=O[32-h]>>>0,r.notGRsuffixlen[s]=Je(c)}const i=O[t],n=i>>>1;let _;for(_=0;_<=i;_++)_<=n?r.xlatU2L[_]=_<<1:r.xlatU2L[_]=(i-_<<1)+1;for(_=0;_<=i;_++)_&1?r.xlatL2U[_]=i-(_>>>1):r.xlatL2U[_]=_>>>1}function Vs(r){switch(r){case R.QUIC_IMAGE_TYPE_GRAY:return 8;case R.QUIC_IMAGE_TYPE_RGB16:return 5;case R.QUIC_IMAGE_TYPE_RGB24:return 8;case R.QUIC_IMAGE_TYPE_RGB32:return 8;case R.QUIC_IMAGE_TYPE_RGBA:return 8;case R.QUIC_IMAGE_TYPE_INVALID:default:return console.log(`quic: bad image type
2
+ `),0}}function Hs(r){return r&4286578688?he[r>>>24]:r&4294934528?8+he[r>>>16&255]:r&4294967168?16+he[r>>>8&255]:24+he[r&255]}function B(r,t){let e,s;if(t<0||t>L.notGRprefixmask[r]){const i=Hs(t);s=i+1+r,e=i<<r|t>>32-s&O[r]}else s=L.notGRcwlen[r],e=L.nGRcodewords[r]+(t>>32-s&O[L.notGRsuffixlen[r]]);return{codewordlen:s,rc:e}}function et(r,t){return r<L.nGRcodewords[t]?(r>>>t)+1+t:L.notGRcwlen[t]}class tt{constructor(t){let e,s=0;switch(this.levels=1<<t,this.n_buckets_ptrs=0,kt){case 1:this.repfirst=3,this.firstsize=1,this.repnext=2,this.mulsize=2;break;case 3:this.repfirst=1,this.firstsize=1,this.repnext=1,this.mulsize=2;break;case 5:this.repfirst=1,this.firstsize=1,this.repnext=1,this.mulsize=4;break;case 0:case 2:case 4:console.log(`quic: findmodelparams(): evol value obsolete!!!
3
+ `);break;default:console.log(`quic: findmodelparams(): evol out of range!!!
4
+ `)}this.n_buckets=0;let i=this.repfirst+1,n=this.firstsize;do this.n_buckets?e=s+1:e=0,--i||(i=this.repnext,n*=this.mulsize),s=e+n-1,s+n>=this.levels&&(s=this.levels-1),this.n_buckets_ptrs||(this.n_buckets_ptrs=this.levels),this.n_buckets++;while(s<this.levels-1)}}class qs{constructor(){this.counters=[0,0,0,0,0,0,0,0],this.bestcode=0}reste(t){this.bestcode=t,this.counters=[0,0,0,0,0,0,0,0]}update_model_8bpc(t,e,s){let i,n=s-1,_=this.counters[n]+=et(e,n);for(i=s-2;i>=0;i--){const h=this.counters[i]+=et(e,i);h<_&&(n=i,_=h)}if(this.bestcode=n,_>t.wm_trigger)for(i=0;i<s;i++)this.counters[i]=this.counters[i]>>>1}}class st{constructor(){this.buckets_ptrs=[],this.buckets_buf=[]}fill_model_structures(t){let e,s=0,i=0,n=t.repfirst+1,_=t.firstsize;do{i?e=s+1:e=0,--n||(n=t.repnext,_*=t.mulsize),s=e+_-1,s+_>=t.levels&&(s=t.levels-1),this.buckets_buf[i]=new qs;let h;for(h=e;h<=s;h++)this.buckets_ptrs[h]=this.buckets_buf[i];i++}while(s<t.levels-1);return!0}}class Ft{constructor(){this.waitcnt=0,this.tabrand_seed=255,this.wm_trigger=0,this.wmidx=0,this.wmileft=te,this.melcstate=0,this.melclen=le[0],this.melcorder=1<<this.melclen}set_wm_trigger(){let t=this.wmidx;t>10&&(t=10),this.wm_trigger=Fs[Math.floor(kt/2)][t]}reste(){this.waitcnt=0,this.tabrand_seed=255,this.wmidx=0,this.wmileft=te,this.set_wm_trigger(),this.melcstate=0,this.melclen=le[0],this.melcorder=1<<this.melclen}tabrand(){return this.tabrand_seed++,zs[this.tabrand_seed&255]}}class Xs{constructor(t,e){if(this.state=new Ft,this.family_stat_8bpc=new st,this.family_stat_5bpc=new st,this.correlate_row={zero:0,row:[]},this.model_8bpc=t,this.model_5bpc=e,this.buckets_ptrs=[],!this.family_stat_8bpc.fill_model_structures(this.model_8bpc))throw new Error("Failed to create 8bpc model structures");if(!this.family_stat_5bpc.fill_model_structures(this.model_5bpc))throw new Error("Failed to create 5bpc model structures")}reste(t){let e;if(this.correlate_row={zero:0,row:[]},t==8){for(e=0;e<this.model_8bpc.n_buckets;e++)this.family_stat_8bpc.buckets_buf[e].reste(7);this.buckets_ptrs=this.family_stat_8bpc.buckets_ptrs}else if(t==5){for(e=0;e<this.model_5bpc.n_buckets;e++)this.family_stat_8bpc.buckets_buf[e].reste(4);this.buckets_ptrs=this.family_stat_5bpc.buckets_ptrs}else return console.log(`quic: bad bpc %d
5
+ `,t),!1;return this.state.reste(),!0}}class Ws{constructor(){this.type=0,this.width=0,this.height=0,this.io_idx=0,this.io_available_bits=0,this.io_word=0,this.io_next_word=0,this.io_now=new Uint8Array(0),this.io_end=0,this.rows_completed=0,this.rgb_state=new Ft,this.model_8bpc=new tt(8),this.model_5bpc=new tt(5),this.channels=[];for(let t=0;t<4;t++)this.channels[t]=new Xs(this.model_8bpc,this.model_5bpc)}reste(t){return this.rgb_state.reste(),this.io_now=t,this.io_end=this.io_now.length,this.io_idx=0,this.rows_completed=0,!0}read_io_word(){if(this.io_idx>=this.io_end)throw new Error("quic: out of data");this.io_next_word=this.io_now[this.io_idx++]|this.io_now[this.io_idx++]<<8|this.io_now[this.io_idx++]<<16|this.io_now[this.io_idx++]<<24}decode_eatbits(t){this.io_word=this.io_word<<t;const e=this.io_available_bits-t;if(e>=0)this.io_available_bits=e,this.io_word|=this.io_next_word>>>this.io_available_bits;else{const s=-1*e;this.io_word|=this.io_next_word<<s,this.read_io_word(),this.io_available_bits=32-s,this.io_word|=this.io_next_word>>>this.io_available_bits}}decode_eat32bits(){this.decode_eatbits(16),this.decode_eatbits(16)}reste_channels(t){for(let e=0;e<4;e++)if(!this.channels[e].reste(t))return!1;return!0}quic_decode_begin(t){if(!this.reste(t))return!1;this.io_idx=0,this.io_next_word=this.io_now[this.io_idx++]|this.io_now[this.io_idx++]<<8|this.io_now[this.io_idx++]<<16|this.io_now[this.io_idx++]<<24,this.io_word=this.io_next_word,this.io_available_bits=0;const e=this.io_word;if(this.decode_eat32bits(),e!=1128879441)return console.log("quic: bad magic "+e.toString(16)),!1;const s=this.io_word;if(this.decode_eat32bits(),s!=0)return console.log("quic: bad version "+s.toString(16)),!1;this.type=this.io_word,this.decode_eat32bits(),this.width=this.io_word,this.decode_eat32bits(),this.height=this.io_word,this.decode_eat32bits();const i=Vs(this.type);return!!this.reste_channels(i)}quic_rgb32_uncompress_row0_seg(t,e,s,i,n,_){let h,a,d;if(t)h=t+this.rgb_state.waitcnt;else{e[g]=0,a=0;do d=B(this.channels[a].buckets_ptrs[this.channels[a].correlate_row.zero].bestcode,this.io_word),this.channels[a].correlate_row.row[0]=d.rc,e[2-a]=L.xlatL2U[d.rc]&255,this.decode_eatbits(d.codewordlen);while(++a<3);if(this.rgb_state.waitcnt)--this.rgb_state.waitcnt;else{this.rgb_state.waitcnt=this.rgb_state.tabrand()&i,a=0;do this.channels[a].buckets_ptrs[this.channels[a].correlate_row.zero].update_model_8bpc(this.rgb_state,this.channels[a].correlate_row.row[0],n);while(++a<3)}h=++t+this.rgb_state.waitcnt}for(;h<s;){for(;t<=h;t++){e[t*P+g]=0,a=0;do d=B(this.channels[a].buckets_ptrs[this.channels[a].correlate_row.row[t-1]].bestcode,this.io_word),this.channels[a].correlate_row.row[t]=d.rc,e[t*P+(2-a)]=L.xlatL2U[d.rc]+e[(t-1)*P+(2-a)]&_,this.decode_eatbits(d.codewordlen);while(++a<3)}a=0;do this.channels[a].buckets_ptrs[this.channels[a].correlate_row.row[h-1]].update_model_8bpc(this.rgb_state,this.channels[a].correlate_row.row[h],n);while(++a<3);h=t+(this.rgb_state.tabrand()&i)}for(;t<s;t++){e[t*P+g]=0,a=0;do d=B(this.channels[a].buckets_ptrs[this.channels[a].correlate_row.row[t-1]].bestcode,this.io_word),this.channels[a].correlate_row.row[t]=d.rc,e[t*P+(2-a)]=L.xlatL2U[d.rc]+e[(t-1)*P+(2-a)]&_,this.decode_eatbits(d.codewordlen);while(++a<3)}this.rgb_state.waitcnt=h-s}quic_rgb32_uncompress_row0(t){let i=0,n=this.width;for(;V>this.rgb_state.wmidx&&this.rgb_state.wmileft<=n;)this.rgb_state.wmileft&&(this.quic_rgb32_uncompress_row0_seg(i,t,i+this.rgb_state.wmileft,O[this.rgb_state.wmidx],8,255),i+=this.rgb_state.wmileft,n-=this.rgb_state.wmileft),this.rgb_state.wmidx++,this.rgb_state.set_wm_trigger(),this.rgb_state.wmileft=te;n&&(this.quic_rgb32_uncompress_row0_seg(i,t,i+n,O[this.rgb_state.wmidx],8,255),V>this.rgb_state.wmidx&&(this.rgb_state.wmileft-=n))}quic_rgb32_uncompress_row_seg(t,e,s,i,n,_){const c=O[this.rgb_state.wmidx];let a,d=0,E=0,S=0,p;if(s)E=s+this.rgb_state.waitcnt;else{e[g]=0,p=0;do a=B(this.channels[p].buckets_ptrs[this.channels[p].correlate_row.zero].bestcode,this.io_word),this.channels[p].correlate_row.row[0]=a.rc,e[2-p]=L.xlatL2U[this.channels[p].correlate_row.row[0]]+t[2-p]&_,this.decode_eatbits(a.codewordlen);while(++p<3);if(this.rgb_state.waitcnt)--this.rgb_state.waitcnt;else{this.rgb_state.waitcnt=this.rgb_state.tabrand()&c,p=0;do this.channels[p].buckets_ptrs[this.channels[p].correlate_row.zero].update_model_8bpc(this.rgb_state,this.channels[p].correlate_row.row[0],n);while(++p<3)}E=++s+this.rgb_state.waitcnt}for(;;){let I=0;for(;E<i&&!I;){for(;s<=E&&!I;s++){const b=s*P,C=(s-1)*P,T=(s-2)*P;if(t[C+Y]==t[b+Y]&&t[C+v]==t[b+v]&&t[C+K]==t[b+K]&&d!=s&&s>2&&e[C+Y]==e[T+Y]&&e[C+v]==e[T+v]&&e[C+K]==e[T+K]){for(this.rgb_state.waitcnt=E-s,d=s,S=s+this.decode_run(this.rgb_state);s<S;s++){const w=s*P,D=(s-1)*P;e[w+g]=0,e[w+Y]=e[D+Y],e[w+v]=e[D+v],e[w+K]=e[D+K]}if(s==i)return;E=s+this.rgb_state.waitcnt,I=1;break}p=0,e[b+g]=0;do{const w=this.channels[p],D=w.correlate_row;a=B(w.buckets_ptrs[D.row[s-1]].bestcode,this.io_word),D.row[s]=a.rc,e[b+(2-p)]=L.xlatL2U[a.rc]+(e[C+(2-p)]+t[b+(2-p)]>>1)&_,this.decode_eatbits(a.codewordlen)}while(++p<3)}if(I)break;p=0;do this.channels[p].buckets_ptrs[this.channels[p].correlate_row.row[E-1]].update_model_8bpc(this.rgb_state,this.channels[p].correlate_row.row[E],n);while(++p<3);E=s+(this.rgb_state.tabrand()&c)}for(;s<i&&!I;s++){const b=s*P,C=(s-1)*P,T=(s-2)*P;if(t[C+Y]==t[b+Y]&&t[C+v]==t[b+v]&&t[C+K]==t[b+K]&&d!=s&&s>2&&e[C+Y]==e[T+Y]&&e[C+v]==e[T+v]&&e[C+K]==e[T+K]){for(this.rgb_state.waitcnt=E-s,d=s,S=s+this.decode_run(this.rgb_state);s<S;s++){const w=s*P,D=(s-1)*P;e[w+g]=0,e[w+Y]=e[D+Y],e[w+v]=e[D+v],e[w+K]=e[D+K]}if(s==i)return;E=s+this.rgb_state.waitcnt,I=1;break}e[b+g]=0,p=0;do a=B(this.channels[p].buckets_ptrs[this.channels[p].correlate_row.row[s-1]].bestcode,this.io_word),this.channels[p].correlate_row.row[s]=a.rc,e[b+(2-p)]=L.xlatL2U[a.rc]+(e[C+(2-p)]+t[b+(2-p)]>>1)&_,this.decode_eatbits(a.codewordlen);while(++p<3)}if(!I){this.rgb_state.waitcnt=E-i;return}}}decode_run(t){let e=0;do{let s;const i=~(this.io_word>>>24)>>>0&255,n=xt[i];for(s=1;s<=n;s++)e+=t.melcorder,t.melcstate<32&&(t.melclen=le[++t.melcstate],t.melcorder=1<<t.melclen);if(n!=8){this.decode_eatbits(n+1);break}this.decode_eatbits(8)}while(!0);return t.melclen&&(e+=this.io_word>>>32-t.melclen,this.decode_eatbits(t.melclen)),t.melcstate&&(t.melclen=le[--t.melcstate],t.melcorder=1<<t.melclen),e}quic_rgb32_uncompress_row(t,e){let n=0,_=this.width;for(;V>this.rgb_state.wmidx&&this.rgb_state.wmileft<=_;)this.rgb_state.wmileft&&(this.quic_rgb32_uncompress_row_seg(t,e,n,n+this.rgb_state.wmileft,8,255),n+=this.rgb_state.wmileft,_-=this.rgb_state.wmileft),this.rgb_state.wmidx++,this.rgb_state.set_wm_trigger(),this.rgb_state.wmileft=te;_&&(this.quic_rgb32_uncompress_row_seg(t,e,n,n+_,8,255),V>this.rgb_state.wmidx&&(this.rgb_state.wmileft-=_))}quic_four_uncompress_row0_seg(t,e,s,i,n,_,h,c){let a,d;for(e==0?(d=B(t.buckets_ptrs[s.zero].bestcode,this.io_word),s.row[0]=d.rc,i[g]=L.xlatL2U[d.rc],this.decode_eatbits(d.codewordlen),t.state.waitcnt?--t.state.waitcnt:(t.state.waitcnt=t.state.tabrand()&_,t.buckets_ptrs[s.zero].update_model_8bpc(t.state,s.row[0],h)),a=++e+t.state.waitcnt):a=e+t.state.waitcnt;a<n;){let E;for(;e<=a;e++)E=t.buckets_ptrs[s.row[e-1]],d=B(E.bestcode,this.io_word),s.row[e]=d.rc,i[e*P+g]=L.xlatL2U[d.rc]+i[(e-1)*P+g]&c,this.decode_eatbits(d.codewordlen);E.update_model_8bpc(t.state,s.row[a],h),a=e+(t.state.tabrand()&_)}for(;e<n;e++)d=B(t.buckets_ptrs[s.row[e-1]].bestcode,this.io_word),s.row[e]=d.rc,i[e*P+g]=L.xlatL2U[d.rc]+i[(e-1)*P+g]&c,this.decode_eatbits(d.codewordlen);t.state.waitcnt=a-n}quic_four_uncompress_row0(t,e){const n=t.correlate_row;let _=0,h=this.width;for(;V>t.state.wmidx&&t.state.wmileft<=h;)t.state.wmileft&&(this.quic_four_uncompress_row0_seg(t,_,n,e,_+t.state.wmileft,O[t.state.wmidx],8,255),_+=t.state.wmileft,h-=t.state.wmileft),t.state.wmidx++,t.state.set_wm_trigger(),t.state.wmileft=te;h&&(this.quic_four_uncompress_row0_seg(t,_,n,e,_+h,O[t.state.wmidx],8,255),V>t.state.wmidx&&(t.state.wmileft-=h))}quic_four_uncompress_row_seg(t,e,s,i,n,_,h,c){const a=O[t.state.wmidx];let d,E=0,S,p;for(n==0?(p=B(t.buckets_ptrs[e.zero].bestcode,this.io_word),e.row[0]=p.rc,i[g]=L.xlatL2U[p.rc]+s[g]&c,this.decode_eatbits(p.codewordlen),t.state.waitcnt?--t.state.waitcnt:(t.state.waitcnt=t.state.tabrand()&a,t.buckets_ptrs[e.zero].update_model_8bpc(t.state,e.row[0],h)),d=++n+t.state.waitcnt):d=n+t.state.waitcnt;;){let I=0;for(;d<_&&!I;){let b;for(;n<=d&&!I;n++){const C=n*P,T=(n-1)*P,w=(n-2)*P;if(s[T+g]==s[C+g]&&E!=n&&n>2&&i[T+g]==i[w+g]){for(t.state.waitcnt=d-n,E=n,S=n+this.decode_run(t.state);n<S;n++){const D=n*P,Q=(n-1)*P;i[D+g]=i[Q+g]}if(n==_)return;d=n+t.state.waitcnt,I=1;break}b=t.buckets_ptrs[e.row[n-1]],p=B(b.bestcode,this.io_word),e.row[n]=p.rc,i[C+g]=L.xlatL2U[p.rc]+(i[T+g]+s[C+g]>>1)&c,this.decode_eatbits(p.codewordlen)}if(I)break;b.update_model_8bpc(t.state,e.row[d],h),d=n+(t.state.tabrand()&a)}for(;n<_&&!I;n++){const b=n*P,C=(n-1)*P,T=(n-2)*P;if(s[C+g]==s[b+g]&&E!=n&&n>2&&i[C+g]==i[T+g]){for(t.state.waitcnt=d-n,E=n,S=n+this.decode_run(t.state);n<S;n++){const w=n*P,D=(n-1)*P;i[w+g]=i[D+g]}if(n==_)return;d=n+t.state.waitcnt,I=1;break}p=B(t.buckets_ptrs[e.row[n-1]].bestcode,this.io_word),e.row[n]=p.rc,i[b+g]=L.xlatL2U[p.rc]+(i[C+g]+s[b+g]>>1)&c,this.decode_eatbits(p.codewordlen)}if(!I){t.state.waitcnt=d-_;return}}}quic_four_uncompress_row(t,e,s){const _=t.correlate_row;let h=0,c=this.width;for(;V>t.state.wmidx&&t.state.wmileft<=c;)t.state.wmileft&&(this.quic_four_uncompress_row_seg(t,_,e,s,h,h+t.state.wmileft,8,255),h+=t.state.wmileft,c-=t.state.wmileft),t.state.wmidx++,t.state.set_wm_trigger(),t.state.wmileft=te;c&&(this.quic_four_uncompress_row_seg(t,_,e,s,h,h+c,8,255),V>t.state.wmidx&&(t.state.wmileft-=c))}quic_decode(t,e){let s;switch(this.type){case R.QUIC_IMAGE_TYPE_RGB32:case R.QUIC_IMAGE_TYPE_RGB24:for(this.channels[0].correlate_row.zero=0,this.channels[1].correlate_row.zero=0,this.channels[2].correlate_row.zero=0,this.quic_rgb32_uncompress_row0(t),this.rows_completed++,s=1;s<this.height;s++){const i=t;t=i.subarray(e),this.channels[0].correlate_row.zero=this.channels[0].correlate_row.row[0],this.channels[1].correlate_row.zero=this.channels[1].correlate_row.row[0],this.channels[2].correlate_row.zero=this.channels[2].correlate_row.row[0],this.quic_rgb32_uncompress_row(i,t),this.rows_completed++}break;case R.QUIC_IMAGE_TYPE_RGB16:return console.log(`quic: unsupported output format
6
+ `),!1;case R.QUIC_IMAGE_TYPE_RGBA:for(this.channels[0].correlate_row.zero=0,this.channels[1].correlate_row.zero=0,this.channels[2].correlate_row.zero=0,this.quic_rgb32_uncompress_row0(t),this.channels[3].correlate_row.zero=0,this.quic_four_uncompress_row0(this.channels[3],t),this.rows_completed++,s=1;s<this.height;s++){const i=t;t=i.subarray(e),this.channels[0].correlate_row.zero=this.channels[0].correlate_row.row[0],this.channels[1].correlate_row.zero=this.channels[1].correlate_row.row[0],this.channels[2].correlate_row.zero=this.channels[2].correlate_row.row[0],this.quic_rgb32_uncompress_row(i,t),this.channels[3].correlate_row.zero=this.channels[3].correlate_row.row[0],this.quic_four_uncompress_row(this.channels[3],i,t),this.rows_completed++}break;case R.QUIC_IMAGE_TYPE_GRAY:return console.log(`quic: unsupported output format
7
+ `),!1;case R.QUIC_IMAGE_TYPE_INVALID:default:return console.log(`quic: bad image type
8
+ `),!1}return!0}simple_quic_decode(t){if(!this.quic_decode_begin(t)||this.type!=R.QUIC_IMAGE_TYPE_RGB32&&this.type!=R.QUIC_IMAGE_TYPE_RGB24&&this.type!=R.QUIC_IMAGE_TYPE_RGBA)return;const s=new Uint8Array(this.width*this.height*4);if(s[0]=69,this.quic_decode(s,this.width*4))return s}}class Zs{constructor(){this.data_size=0,this.type=0,this.width=0,this.height=0}from_dv(t,e,s){if(!X)throw"quic: no quic encoder";this.data_size=t.getUint32(e,!0),e+=4;const i=new Uint8Array(s.slice(e));return this.outptr=X.simple_quic_decode(i),this.outptr&&(this.type=X.type,this.width=X.width,this.height=X.height),e+=i.length,e}}function js(r,t){const e=r.createImageData(t.width,t.height);for(let s=0;s<e.width*e.height*4;s+=4)e.data[s+0]=t.outptr[s+2],e.data[s+1]=t.outptr[s+1],e.data[s+2]=t.outptr[s+0],t.type!==R.QUIC_IMAGE_TYPE_RGBA?e.data[s+3]=255:e.data[s+3]=255-t.outptr[s+3];return e}if(je){je=!1,$e(L,8,Qe),$e(xs,5,Qe);let r,t,e,s;for(t=e=1,s=8,r=0;r<256;++r)xt[r]=s,--e,e==0&&(e=t,--s,t*=2);if(X=new Ws,!X)throw"quic: failed to create encoder"}class Qs{constructor(){this.type=0,this.id=0}from_dv(t,e,s){return this.type=t.getUint8(e,!0),e++,this.id=t.getUint8(e,!0),e++,e}}class W{constructor(){this.top=0,this.left=0,this.bottom=0,this.right=0}from_dv(t,e,s){return this.top=t.getUint32(e,!0),e+=4,this.left=t.getUint32(e,!0),e+=4,this.bottom=t.getUint32(e,!0),e+=4,this.right=t.getUint32(e,!0),e+=4,e}is_same_size(t){return this.bottom-this.top==t.bottom-t.top&&this.right-this.left==t.right-t.left}}class Js{constructor(){this.num_rects=0,this.rects=[]}from_dv(t,e,s){let i;for(this.num_rects=t.getUint32(e,!0),e+=4,this.num_rects>0&&(this.rects=[]),i=0;i<this.num_rects;i++)this.rects[i]=new W,e=this.rects[i].from_dv(t,e,s);return e}}class He{constructor(){this.type=0}from_dv(t,e,s){return this.type=t.getUint8(e,!0),e++,this.type==o.SPICE_CLIP_TYPE_RECTS&&(this.rects=new Js,e=this.rects.from_dv(t,e,s)),e}}class it{constructor(){this.id=0,this.type=0,this.flags=0,this.width=0,this.height=0}from_dv(t,e,s){return this.id=t.getUint64(e,!0),e+=8,this.type=t.getUint8(e,!0),e++,this.flags=t.getUint8(e,!0),e++,this.width=t.getUint32(e,!0),e+=4,this.height=t.getUint32(e,!0),e+=4,e}}class $s{constructor(){this.unique=0,this.num_ents=0,this.ents=[]}from_dv(t,e,s){let i;for(this.unique=t.getUint64(e,!0),e+=8,this.num_ents=t.getUint16(e,!0),e+=2,this.ents=[],i=0;i<this.num_ents;i++)this.ents[i]=t.getUint32(e,!0),e+=4;return e}}class ei{constructor(){this.format=0,this.flags=0,this.x=0,this.y=0,this.stride=0,this.palette=null,this.data=new ArrayBuffer(0)}from_dv(t,e,s){if(this.format=t.getUint8(e,!0),e++,this.flags=t.getUint8(e,!0),e++,this.x=t.getUint32(e,!0),e+=4,this.y=t.getUint32(e,!0),e+=4,this.stride=t.getUint32(e,!0),e+=4,this.flags&o.SPICE_BITMAP_FLAGS_PAL_FROM_CACHE)this.palette_id=t.getUint64(e,!0),e+=8;else{const i=t.getUint32(e,!0);e+=4,i==0?this.palette=null:(this.palette=new $s,this.palette.from_dv(t,i,s))}return this.data=s.slice(e),e+=this.data.byteLength,e}}class qe{constructor(){this.descriptor=new it}from_dv(t,e,s){if(this.descriptor=new it,e=this.descriptor.from_dv(t,e,s),this.descriptor.type==o.SPICE_IMAGE_TYPE_LZ_RGB){this.lz_rgb=new Object,this.lz_rgb.length=t.getUint32(e,!0),e+=4;var i=e;this.lz_rgb.magic="";for(var n=3;n>=0;n--)this.lz_rgb.magic+=String.fromCharCode(t.getUint8(e+n));e+=4,this.lz_rgb.version=t.getUint32(e),e+=4,this.lz_rgb.type=t.getUint32(e),e+=4,this.lz_rgb.width=t.getUint32(e),e+=4,this.lz_rgb.height=t.getUint32(e),e+=4,this.lz_rgb.stride=t.getUint32(e),e+=4,this.lz_rgb.top_down=t.getUint32(e),e+=4;var _=e-i;this.lz_rgb.data=s.slice(e,this.lz_rgb.length+e-_),e+=this.lz_rgb.data.byteLength}if(this.descriptor.type==o.SPICE_IMAGE_TYPE_BITMAP&&(this.bitmap=new ei,e=this.bitmap.from_dv(t,e,s)),this.descriptor.type==o.SPICE_IMAGE_TYPE_SURFACE&&(this.surface_id=t.getUint32(e,!0),e+=4),this.descriptor.type==o.SPICE_IMAGE_TYPE_JPEG&&(this.jpeg=new Object,this.jpeg.data_size=t.getUint32(e,!0),e+=4,this.jpeg.data=s.slice(e),e+=this.jpeg.data.byteLength),this.descriptor.type==o.SPICE_IMAGE_TYPE_JPEG_ALPHA){this.jpeg_alpha=new Object,this.jpeg_alpha.flags=t.getUint8(e,!0),e+=1,this.jpeg_alpha.jpeg_size=t.getUint32(e,!0),e+=4,this.jpeg_alpha.data_size=t.getUint32(e,!0),e+=4,this.jpeg_alpha.data=s.slice(e,this.jpeg_alpha.jpeg_size+e),e+=this.jpeg_alpha.data.byteLength,this.jpeg_alpha.alpha=new Object,this.jpeg_alpha.alpha.length=this.jpeg_alpha.data_size-this.jpeg_alpha.jpeg_size;var i=e;this.jpeg_alpha.alpha.magic="";for(var n=3;n>=0;n--)this.jpeg_alpha.alpha.magic+=String.fromCharCode(t.getUint8(e+n));e+=4,this.jpeg_alpha.alpha.version=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.type=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.width=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.height=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.stride=t.getUint32(e),e+=4,this.jpeg_alpha.alpha.top_down=t.getUint32(e),e+=4;var _=e-i;this.jpeg_alpha.alpha.data=s.slice(e,this.jpeg_alpha.alpha.length+e-_),e+=this.jpeg_alpha.alpha.data.byteLength}return this.descriptor.type==o.SPICE_IMAGE_TYPE_QUIC&&(this.quic=new Zs,e=this.quic.from_dv(t,e,s)),e}}class ue{constructor(){this.flags=0,this.pos=new ie,this.bitmap=null}from_dv(t,e,s){this.flags=t.getUint8(e,!0),e++,this.pos=new ie,e=this.pos.from_dv(t,e,s);const i=t.getUint32(e,!0);return e+=4,i==0?(this.bitmap=null,e):(this.bitmap=new qe,this.bitmap.from_dv(t,i,s))}}class ti{constructor(){this.pat=null,this.pos=new ie}from_dv(t,e,s){const i=t.getUint32(e,!0);return e+=4,i==0?this.pat=null:(this.pat=new qe,this.pat.from_dv(t,i,s)),this.pos=new ie,this.pos.from_dv(t,e,s)}}class rt{constructor(){this.type=0}from_dv(t,e,s){return this.type=t.getUint8(e,!0),e++,this.type==o.SPICE_BRUSH_TYPE_SOLID?(this.color=t.getUint32(e,!0),e+=4):this.type==o.SPICE_BRUSH_TYPE_PATTERN&&(this.pattern=new ti,e=this.pattern.from_dv(t,e,s)),e}}class si{constructor(){this.brush=new rt,this.rop_descriptor=0,this.mask=new ue}from_dv(t,e,s){return this.brush=new rt,e=this.brush.from_dv(t,e,s),this.rop_descriptor=t.getUint16(e,!0),e+=2,this.mask=new ue,this.mask.from_dv(t,e,s)}}class ii{constructor(){this.src_bitmap=null,this.src_area=new W,this.rop_descriptor=0,this.scale_mode=0,this.mask=new ue}from_dv(t,e,s){const i=t.getUint32(e,!0);return e+=4,i==0?this.src_bitmap=null:(this.src_bitmap=new qe,this.src_bitmap.from_dv(t,i,s)),this.src_area=new W,e=this.src_area.from_dv(t,e,s),this.rop_descriptor=t.getUint16(e,!0),e+=2,this.scale_mode=t.getUint8(e,!0),e++,this.mask=new ue,this.mask.from_dv(t,e,s)}}class zt{constructor(){this.x=0,this.y=0}from_dv(t,e,s){return this.x=t.getUint16(e,!0),e+=2,this.y=t.getUint16(e,!0),e+=2,e}}class ie{constructor(){this.x=0,this.y=0}from_dv(t,e,s){return this.x=t.getUint32(e,!0),e+=4,this.y=t.getUint32(e,!0),e+=4,e}}class ri{constructor(){this.unique=0,this.type=0,this.width=0,this.height=0,this.hot_spot_x=0,this.hot_spot_y=0}from_dv(t,e,s){return this.unique=t.getUint64(e,!0),e+=8,this.type=t.getUint8(e,!0),e++,this.width=t.getUint16(e,!0),e+=2,this.height=t.getUint16(e,!0),e+=2,this.hot_spot_x=t.getUint16(e,!0),e+=2,this.hot_spot_y=t.getUint16(e,!0),e+=2,e}}class Vt{constructor(){this.flags=0,this.header=null,this.data=new ArrayBuffer(0)}from_dv(t,e,s){return this.flags=t.getUint16(e,!0),e+=2,this.flags&o.SPICE_CURSOR_FLAGS_NONE?this.header=null:(this.header=new ri,e=this.header.from_dv(t,e,s),this.data=s.slice(e),e+=this.data.byteLength),e}}class ni{constructor(){this.surface_id=0,this.width=0,this.height=0,this.format=0,this.flags=0}from_dv(t,e,s){return this.surface_id=t.getUint32(e,!0),e+=4,this.width=t.getUint32(e,!0),e+=4,this.height=t.getUint32(e,!0),e+=4,this.format=t.getUint32(e,!0),e+=4,this.flags=t.getUint32(e,!0),e+=4,e}}const u={KEY_Escape:1,KEY_1:2,KEY_2:3,KEY_3:4,KEY_4:5,KEY_5:6,KEY_6:7,KEY_7:8,KEY_8:9,KEY_9:10,KEY_0:11,KEY_Minus:12,KEY_Equal:13,KEY_BackSpace:14,KEY_Tab:15,KEY_Q:16,KEY_W:17,KEY_E:18,KEY_R:19,KEY_T:20,KEY_Y:21,KEY_U:22,KEY_I:23,KEY_O:24,KEY_P:25,KEY_LBrace:26,KEY_RBrace:27,KEY_Enter:28,KEY_LCtrl:29,KEY_A:30,KEY_S:31,KEY_D:32,KEY_F:33,KEY_G:34,KEY_H:35,KEY_J:36,KEY_K:37,KEY_L:38,KEY_SemiColon:39,KEY_Quote:40,KEY_Tilde:41,KEY_ShiftL:42,KEY_BSlash:43,KEY_Z:44,KEY_X:45,KEY_C:46,KEY_V:47,KEY_B:48,KEY_N:49,KEY_M:50,KEY_Comma:51,KEY_Period:52,KEY_Slash:53,KEY_KP_Multiply:55,KEY_Alt:56,KEY_Space:57,KEY_CapsLock:58,KEY_F1:59,KEY_F2:60,KEY_F3:61,KEY_F4:62,KEY_F5:63,KEY_F6:64,KEY_F7:65,KEY_F8:66,KEY_F9:67,KEY_F10:68,KEY_NumLock:69,KEY_ScrollLock:70,KEY_KP_7:71,KEY_KP_8:72,KEY_KP_9:73,KEY_KP_4:75,KEY_KP_5:76,KEY_KP_6:77,KEY_KP_Plus:78,KEY_KP_1:79,KEY_KP_2:80,KEY_KP_3:81,KEY_KP_0:82,KEY_KP_Decimal:83,KEY_SysRequest:84,KEY_F11:87,KEY_F12:88},l=[];l.Escape=1;l.Digit1=2;l.Digit2=3;l.Digit3=4;l.Digit4=5;l.Digit5=6;l.Digit6=7;l.Digit7=8;l.Digit8=9;l.Digit9=10;l.Digit0=11;l.Minus=12;l.Equal=13;l.Backspace=14;l.Tab=15;l.KeyQ=16;l.KeyW=17;l.KeyE=18;l.KeyR=19;l.KeyT=20;l.KeyY=21;l.KeyU=22;l.KeyI=23;l.KeyO=24;l.KeyP=25;l.BracketLeft=26;l.BracketRight=27;l.Enter=28;l.ControlLeft=29;l.KeyA=30;l.KeyS=31;l.KeyD=32;l.KeyF=33;l.KeyG=34;l.KeyH=35;l.KeyJ=36;l.KeyK=37;l.KeyL=38;l.Semicolon=39;l.Quote=40;l.Backquote=41;l.ShiftLeft=42;l.Backslash=43;l.KeyZ=44;l.KeyX=45;l.KeyC=46;l.KeyV=47;l.KeyB=48;l.KeyN=49;l.KeyM=50;l.Comma=51;l.Period=52;l.Slash=53;l.ShiftRight=54;l.NumpadMultiply=55;l.AltLeft=56;l.Space=57;l.CapsLock=58;l.F1=59;l.F2=60;l.F3=61;l.F4=62;l.F5=63;l.F6=64;l.F7=65;l.F8=66;l.F9=67;l.F10=68;l.Pause=69;l.ScrollLock=70;l.Numpad7=71;l.Numpad8=72;l.Numpad9=73;l.NumpadSubtract=74;l.Numpad4=75;l.Numpad5=76;l.Numpad6=77;l.NumpadAdd=78;l.Numpad1=79;l.Numpad2=80;l.Numpad3=81;l.Numpad0=82;l.NumpadDecimal=83;l.PrintScreen=84;l.IntlBackslash=86;l.F11=87;l.F12=88;l.NumpadEqual=89;l.F13=100;l.F14=101;l.F15=102;l.F16=103;l.F17=104;l.F18=105;l.F19=106;l.F20=107;l.F21=108;l.F22=109;l.F23=110;l.KanaMode=112;l.IntlRo=115;l.F24=118;l.Convert=121;l.NonConvert=123;l.IntlYen=125;l.NumpadComma=126;l.MediaTrackPrevious=4320;l.MediaTrackNext=6624;l.NumpadEnter=7392;l.ControlRight=7648;l.AudioVolumeMute=8416;l.LaunchApp2=8672;l.MediaPlayPause=8928;l.MediaStop=9440;l.VolumeDown=12e3;l.VolumeUp=12512;l.BrowserHome=13024;l.NumpadDivide=13792;l.PrintScreen=14304;l.AltRight=14560;l.NumLock=17888;l.Pause=18144;l.Home=18400;l.ArrowUp=18656;l.PageUp=18912;l.ArrowLeft=19424;l.ArrowRight=19936;l.End=20448;l.ArrowDown=20704;l.PageDown=20960;l.Insert=21216;l.Delete=21472;l.MetaLeft=23520;l.MetaRight=23776;l.ContextMenu=24032;l.Power=24288;l.BrowserSearch=26080;l.BrowserFavorites=26336;l.BrowserRefresh=26592;l.BrowserStop=26848;l.BrowserForward=27104;l.BrowserBack=27360;l.LaunchApp1=27616;l.LaunchMail=27872;l.MediaSelect=28128;const nt=l,_i=0,oi="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";function hi(r){return String.fromCharCode.apply(null,new Uint16Array(r))}const f=[];f[49]=u.KEY_1;f[50]=u.KEY_2;f[51]=u.KEY_3;f[52]=u.KEY_4;f[53]=u.KEY_5;f[54]=u.KEY_6;f[55]=u.KEY_7;f[56]=u.KEY_8;f[57]=u.KEY_9;f[48]=u.KEY_0;f[145]=u.KEY_ScrollLock;f[103]=u.KEY_KP_7;f[104]=u.KEY_KP_8;f[105]=u.KEY_KP_9;f[100]=u.KEY_KP_4;f[101]=u.KEY_KP_5;f[102]=u.KEY_KP_6;f[107]=u.KEY_KP_Plus;f[97]=u.KEY_KP_1;f[98]=u.KEY_KP_2;f[99]=u.KEY_KP_3;f[96]=u.KEY_KP_0;f[109]=u.KEY_Minus;f[110]=u.KEY_KP_Decimal;f[191]=u.KEY_Slash;f[190]=u.KEY_Period;f[188]=u.KEY_Comma;f[220]=u.KEY_BSlash;f[192]=u.KEY_Tilde;f[222]=u.KEY_Quote;f[219]=u.KEY_LBrace;f[221]=u.KEY_RBrace;f[81]=u.KEY_Q;f[87]=u.KEY_W;f[69]=u.KEY_E;f[82]=u.KEY_R;f[84]=u.KEY_T;f[89]=u.KEY_Y;f[85]=u.KEY_U;f[73]=u.KEY_I;f[79]=u.KEY_O;f[80]=u.KEY_P;f[65]=u.KEY_A;f[83]=u.KEY_S;f[68]=u.KEY_D;f[70]=u.KEY_F;f[71]=u.KEY_G;f[72]=u.KEY_H;f[74]=u.KEY_J;f[75]=u.KEY_K;f[76]=u.KEY_L;f[90]=u.KEY_Z;f[88]=u.KEY_X;f[67]=u.KEY_C;f[86]=u.KEY_V;f[66]=u.KEY_B;f[78]=u.KEY_N;f[77]=u.KEY_M;f[32]=u.KEY_Space;f[13]=u.KEY_Enter;f[27]=u.KEY_Escape;f[8]=u.KEY_BackSpace;f[9]=u.KEY_Tab;f[16]=u.KEY_ShiftL;f[17]=u.KEY_LCtrl;f[18]=u.KEY_Alt;f[20]=u.KEY_CapsLock;f[44]=u.KEY_SysRequest;f[144]=u.KEY_NumLock;f[112]=u.KEY_F1;f[113]=u.KEY_F2;f[114]=u.KEY_F3;f[115]=u.KEY_F4;f[116]=u.KEY_F5;f[117]=u.KEY_F6;f[118]=u.KEY_F7;f[119]=u.KEY_F8;f[120]=u.KEY_F9;f[121]=u.KEY_F10;f[122]=u.KEY_F11;f[123]=u.KEY_F12;f[42]=99;f[19]=101;f[111]=224|u.KEY_Slash<<8;f[106]=224|u.KEY_KP_Multiply<<8;f[36]=224|u.KEY_KP_7<<8;f[38]=224|u.KEY_KP_8<<8;f[33]=224|u.KEY_KP_9<<8;f[37]=224|u.KEY_KP_4<<8;f[39]=224|u.KEY_KP_6<<8;f[35]=224|u.KEY_KP_1<<8;f[40]=224|u.KEY_KP_2<<8;f[34]=224|u.KEY_KP_3<<8;f[45]=224|u.KEY_KP_0<<8;f[46]=224|u.KEY_KP_Decimal<<8;f[91]=23520;f[92]=23776;f[93]=24032;const Me=[];Me[173]=u.KEY_Minus;Me[61]=u.KEY_Equal;Me[59]=u.KEY_SemiColon;const Te=[];Te[189]=u.KEY_Minus;Te[187]=u.KEY_Equal;Te[186]=u.KEY_SemiColon;function Ht(r,t){return nt[t]!==void 0?nt[t]:f[r]===void 0?typeof navigator<"u"&&navigator.userAgent.includes("Firefox")?Me[r]:Te[r]:f[r]}function ci(r,t){const e=Ht(r,t);return e===void 0?(typeof alert=="function"&&alert("no map for "+r),0):e}function ai(r,t){const e=Ht(r,t);return e===void 0?0:e<256?e|128:e|32768}function Ke(r){return"[networkState "+r.networkState+"|readyState "+r.readyState+"|error "+r.error+"|seeking "+r.seeking+"|duration "+r.duration+"|paused "+r.paused+"|ended "+r.error+"|buffered "+li(r.buffered)+"]"}function li(r){let t;if(r){const e=r.length;t="{len "+e,e>0&&(t+="; start "+r.start(0)+"; end "+r.end(e-1)),t+="}"}else t="N/A";return t}class Ge{constructor(t,e){this.magic=o.SPICE_MAGIC,this.major_version=o.SPICE_VERSION_MAJOR,this.minor_version=o.SPICE_VERSION_MINOR,this.size=0,t!==void 0&&this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.magic="";for(let i=0;i<4;i++)this.magic+=String.fromCharCode(s.getUint8(e+i));e+=4,this.major_version=s.getUint32(e,!0),e+=4,this.minor_version=s.getUint32(e,!0),e+=4,this.size=s.getUint32(e,!0),e+=4}to_buffer(t,e){e=e||0;const s=new m(t);for(let i=0;i<4;i++)s.setUint8(e+i,this.magic.charCodeAt(i));e+=4,s.setUint32(e,this.major_version,!0),e+=4,s.setUint32(e,this.minor_version,!0),e+=4,s.setUint32(e,this.size,!0),e+=4}buffer_size(){return 16}}class ui{constructor(t,e){this.connection_id=0,this.channel_type=0,this.channel_id=0,this.common_caps=[],this.channel_caps=[],t!==void 0&&this.from_buffer(t,e)}from_buffer(t,e){e=e||0;let s;const i=e,n=new m(t);this.connection_id=n.getUint32(e,!0),e+=4,this.channel_type=n.getUint8(e,!0),e++,this.channel_id=n.getUint8(e,!0),e++;const _=n.getUint32(e,!0);e+=4;const h=n.getUint32(e,!0);e+=4;const c=n.getUint32(e,!0);for(e+=4,e=i+c,this.common_caps=[],s=0;s<_;s++)this.common_caps.unshift(n.getUint32(e,!0)),e+=4;for(this.channel_caps=[],s=0;s<h;s++)this.channel_caps.unshift(n.getUint32(e,!0)),e+=4}to_buffer(t,e){e=e||0;const s=e;let i;const n=new m(t);for(n.setUint32(e,this.connection_id,!0),e+=4,n.setUint8(e,this.channel_type,!0),e++,n.setUint8(e,this.channel_id,!0),e++,n.setUint32(e,this.common_caps.length,!0),e+=4,n.setUint32(e,this.channel_caps.length,!0),e+=4,n.setUint32(e,e-s+4,!0),e+=4,i=0;i<this.common_caps.length;i++)n.setUint32(e,this.common_caps[i],!0),e+=4;for(i=0;i<this.channel_caps.length;i++)n.setUint32(e,this.channel_caps[i],!0),e+=4}buffer_size(){return 18+4*this.common_caps.length+4*this.channel_caps.length}}class di{constructor(t,e){this.error=0,this.pub_key=void 0,this.common_caps=[],this.channel_caps=[],t!==void 0&&this.from_buffer(t,e)}from_buffer(t,e){e=e||0;let s;const i=e,n=new m(t);this.error=n.getUint32(e,!0),e+=4,this.pub_key=Ys(t,e),e+=o.SPICE_TICKET_PUBKEY_BYTES;const _=n.getUint32(e,!0);e+=4;const h=n.getUint32(e,!0);e+=4;const c=n.getUint32(e,!0);for(e+=4,e=i+c,this.common_caps=[],s=0;s<_;s++)this.common_caps.unshift(n.getUint32(e,!0)),e+=4;for(this.channel_caps=[],s=0;s<h;s++)this.channel_caps.unshift(n.getUint32(e,!0)),e+=4}}class fi{constructor(t,e){this.auth_mechanism=0,this.encrypted_data=void 0}to_buffer(t,e){e=e||0;let s;const i=new m(t);for(i.setUint32(e,this.auth_mechanism,!0),e+=4,s=0;s<o.SPICE_TICKET_KEY_PAIR_LENGTH/8;s++)this.encrypted_data&&s<this.encrypted_data.length?i.setUint8(e,this.encrypted_data[s],!0):i.setUint8(e,0,!0),e++}buffer_size(){return 4+o.SPICE_TICKET_KEY_PAIR_LENGTH/8}}class _t{constructor(t,e){this.auth_code=0,t!==void 0&&this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.auth_code=s.getUint32(e,!0),e+=4}buffer_size(){return 4}}class y{constructor(t,e){this.type=0,this.size=0,this.data=void 0,t!==void 0&&this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.type=s.getUint16(e,!0),e+=2,this.size=s.getUint32(e,!0),e+=4,t.byteLength>e&&(this.data=t.slice(e),e+=this.data.byteLength)}to_buffer(t,e){e=e||0;let s;const i=new m(t);if(i.setUint16(e,this.type,!0),e+=2,i.setUint32(e,this.data?this.data.byteLength:0,!0),e+=4,this.data&&this.data.byteLength>0){const n=new Uint8Array(this.data);for(s=0;s<n.length;s++,e++)i.setUint8(e,n[s],!0)}}build_msg(t,e){this.type=t,this.size=e.buffer_size(),this.data=new ArrayBuffer(this.size),e.to_buffer(this.data)}buffer_size(){return this.data?6+this.data.byteLength:6}}class Ei{constructor(t,e){this.num_of_channels=0,this.channels=[],t!==void 0&&this.from_buffer(t,e)}from_buffer(t,e){e=e||0;let s;const i=new m(t);for(this.num_of_channels=i.getUint32(e,!0),e+=4,s=0;s<this.num_of_channels;s++){const n=new Qs;e=n.from_dv(i,e,t),this.channels.push(n)}}}function ye(r){return(r[0]>>o.VD_AGENT_CAP_CLIPBOARD_SELECTION&1)!=0}class pi{constructor(t,e){this.has_clipboard_selection=ye(e),this.type=t}to_buffer(t,e){e=e||0;const s=new m(t);this.has_clipboard_selection&&(s.setUint32(e,0,!0),e+=4),s.setUint32(e,this.type,!0),e+=4}buffer_size(){return this.has_clipboard_selection?8:4}}class mi{constructor(t,e){this.has_clipboard_selection=ye(e);const s=new DataView(t.data);let i=this.has_clipboard_selection?4:0;this.type=s.getUint32(i,!0),i+=4,this.payload=t.data.slice(i)}get_text(){return new TextDecoder("utf-8").decode(this.payload)}}class Si{constructor(t,e){this.has_clipboard_selection=ye(e),this.type=t}to_buffer(t,e){e=e||0;const s=new m(t);this.has_clipboard_selection&&(s.setUint32(e,0,!0),e+=4),s.setUint32(e,this.type,!0),e+=4}buffer_size(){return this.has_clipboard_selection?8:4}}class Ii{constructor(t,e,s){this.has_clipboard_selection=ye(s),this.type=t,this.text=e}to_buffer(t,e){e=e||0;const s=new m(t);this.has_clipboard_selection&&(s.setUint32(e,0,!0),e+=4),s.setUint32(e,this.type,!0),e+=4;const i=new TextEncoder().encode(this.text);new Uint8Array(t,e,i.byteLength).set(i),e+=i.byteLength}buffer_size(){const t=new TextEncoder().encode(this.text).byteLength;return(this.has_clipboard_selection?8:4)+t}}class Ai{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.session_id=s.getUint32(e,!0),e+=4,this.display_channels_hint=s.getUint32(e,!0),e+=4,this.supported_mouse_modes=s.getUint32(e,!0),e+=4,this.current_mouse_mode=s.getUint32(e,!0),e+=4,this.agent_connected=s.getUint32(e,!0),e+=4,this.agent_tokens=s.getUint32(e,!0),e+=4,this.multi_media_time=s.getUint32(e,!0),e+=4,this.ram_hint=s.getUint32(e,!0),e+=4}}class Ci{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.supported_modes=s.getUint16(e,!0),e+=2,this.current_mode=s.getUint16(e,!0),e+=2}}class gi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.protocol=s.getUint32(e,!0),e+=4,this.type=s.getUint32(e,!0),e+=4,this.opaque=s.getUint64(e,!0),e+=8,this.size=s.getUint32(e,!0),e+=4,t.byteLength>e&&(this.data=t.slice(e),e+=this.data.byteLength)}}class ot{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.num_tokens=s.getUint32(e,!0),e+=4}}class bi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.generation=s.getUint32(e,!0),e+=4,this.window=s.getUint32(e,!0),e+=4}}class Pi{constructor(t){this.generation=t.generation}to_buffer(t,e){e=e||0,new m(t).setUint32(e,this.generation,!0),e+=4}buffer_size(){return 4}}class wi{constructor(t){this.mode=t}to_buffer(t,e){e=e||0,new m(t).setUint16(e,this.mode,!0),e+=2}buffer_size(){return 2}}class Mi{constructor(t){this.num_tokens=t}to_buffer(t,e){e=e||0,new m(t).setUint32(e,this.num_tokens,!0),e+=4}buffer_size(){return 4}}class Ti{constructor(t,e){this.protocol=o.VD_AGENT_PROTOCOL,this.type=t,this.opaque=0,this.size=e.buffer_size(),this.data=e}to_buffer(t,e){e=e||0;const s=new m(t);s.setUint32(e,this.protocol,!0),e+=4,s.setUint32(e,this.type,!0),e+=4,s.setUint64(e,this.opaque,!0),e+=8,s.setUint32(e,this.size,!0),e+=4,this.data.to_buffer(t,e)}buffer_size(){return 20+this.data.buffer_size()}}class ht{constructor(t,e){e?(this.request=t,this.caps=e):this.from_buffer(t)}to_buffer(t,e){e=e||0;const s=new m(t);s.setUint32(e,this.request,!0),e+=4,s.setUint32(e,this.caps,!0),e+=4}from_buffer(t,e){e=e||0;const s=new m(t);return this.request=s.getUint32(e,!0),e+=4,this.caps=s.getUint32(e,!0),e+=4,e}buffer_size(){return 8}}class yi{constructor(t,e,s,i,n,_){this.num_mon=1,this.flags=t,this.width=e,this.height=s,this.depth=i,this.x=n,this.y=_}to_buffer(t,e){e=e||0;const s=new m(t);s.setUint32(e,this.num_mon,!0),e+=4,s.setUint32(e,this.flags,!0),e+=4,s.setUint32(e,this.height,!0),e+=4,s.setUint32(e,this.width,!0),e+=4,s.setUint32(e,this.depth,!0),e+=4,s.setUint32(e,this.x,!0),e+=4,s.setUint32(e,this.y,!0),e+=4}buffer_size(){return 28}}class ct{constructor(t,e){e?(this.id=t,this.result=e):this.from_buffer(t)}to_buffer(t,e){e=e||0;const s=new m(t);s.setUint32(e,this.id,!0),e+=4,s.setUint32(e,this.result,!0),e+=4}from_buffer(t,e){e=e||0;const s=new m(t);return this.id=s.getUint32(e,!0),e+=4,this.result=s.getUint32(e,!0),e+=4,e}buffer_size(){return 8}}class Di{constructor(t,e,s){this.id=t,this.string=`[vdagent-file-xfer]
9
+ name=`+e+`
10
+ size=`+s+`
11
+ `}to_buffer(t,e){e=e||0;const s=new m(t);s.setUint32(e,this.id,!0),e+=4;for(let i=0;i<this.string.length;i++,e++)s.setUint8(e,this.string.charCodeAt(i))}buffer_size(){return 4+this.string.length+1}}class Li{constructor(t,e,s){this.id=t,this.size=e,this.data=s}to_buffer(t,e){e=e||0;const s=new m(t);if(s.setUint32(e,this.id,!0),e+=4,s.setUint64(e,this.size,!0),e+=8,this.data&&this.data.byteLength>0){const i=new Uint8Array(this.data);for(let n=0;n<i.length;n++,e++)s.setUint8(e,i[n])}}buffer_size(){return 12+this.size}}class Ui{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;let s;const i=new m(t);for(this.time_stamp=i.getUint64(e,!0),e+=8,this.severity=i.getUint32(e,!0),e+=4,this.visibility=i.getUint32(e,!0),e+=4,this.what=i.getUint32(e,!0),e+=4,this.message_len=i.getUint32(e,!0),e+=4,this.message="",s=0;s<this.message_len;s++){const n=i.getUint8(e,!0);e++,this.message+=String.fromCharCode(n)}}}class Ni{constructor(){this.pixmap_cache_id=1,this.glz_dictionary_id=0,this.pixmap_cache_size=10*1024*1024,this.glz_dictionary_window_size=0}to_buffer(t,e){e=e||0;const s=new m(t);s.setUint8(e,this.pixmap_cache_id,!0),e++,s.setUint64(e,this.pixmap_cache_size,!0),e+=8,s.setUint8(e,this.glz_dictionary_id,!0),e++,s.setUint32(e,this.glz_dictionary_window_size,!0),e+=4}buffer_size(){return 14}}class De{from_dv(t,e,s){return this.surface_id=t.getUint32(e,!0),e+=4,this.box=new W,e=this.box.from_dv(t,e,s),this.clip=new He,this.clip.from_dv(t,e,s)}}class Ri{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);return this.base=new De,e=this.base.from_dv(s,e,t),this.data=new ii,this.data.from_dv(s,e,t)}}class Gi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);return this.base=new De,e=this.base.from_dv(s,e,t),this.data=new si,this.data.from_dv(s,e,t)}}class Oi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);return this.base=new De,e=this.base.from_dv(s,e,t),this.src_pos=new ie,this.src_pos.from_dv(s,e,t)}}class Yi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);return this.surface=new ni,this.surface.from_dv(s,e,t)}}class vi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.surface_id=s.getUint32(e,!0),e+=4}}class Ki{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);return this.keyboard_modifiers=s.getUint16(e,!0),e+=2,e}}class Bi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);return this.keyboard_modifiers=s.getUint16(e,!0),e+=2,e}}class ki{constructor(t,e,s){this.from_buffer(t,e,s)}from_buffer(t,e,s){e=e||0;const i=new m(t);return this.position=new zt,e=this.position.from_dv(i,e,s),this.trail_length=i.getUint16(e,!0),e+=2,this.trail_frequency=i.getUint16(e,!0),e+=2,this.visible=i.getUint8(e,!0),e++,this.cursor=new Vt,this.cursor.from_dv(i,e,t)}}class xi{constructor(t,e,s){this.from_buffer(t,e,s)}from_buffer(t,e,s){e=e||0;const i=new m(t);return this.time=i.getUint32(e,!0),e+=4,t.byteLength>e&&(this.data=t.slice(e),e+=this.data.byteLength),e}}class Fi{constructor(t,e,s){this.from_buffer(t,e,s)}from_buffer(t,e,s){e=e||0;const i=new m(t);return this.time=i.getUint32(e,!0),e+=4,this.mode=i.getUint16(e,!0),e+=2,t.byteLength>e&&(this.data=t.slice(e),e+=this.data.byteLength),e}}class zi{constructor(t,e,s){this.from_buffer(t,e,s)}from_buffer(t,e,s){e=e||0;const i=new m(t);return this.channels=i.getUint32(e,!0),e+=4,this.format=i.getUint16(e,!0),e+=2,this.frequency=i.getUint32(e,!0),e+=4,this.time=i.getUint32(e,!0),e+=4,e}}class Vi{constructor(t,e,s){this.from_buffer(t,e,s)}from_buffer(t,e,s){e=e||0;const i=new m(t);return this.position=new zt,e=this.position.from_dv(i,e,s),this.visible=i.getUint8(e,!0),e++,this.cursor=new Vt,this.cursor.from_dv(i,e,t)}}class Be{constructor(t,e){this.display_id=0,this.buttons_state=t.buttons_state,e?(this.x=e.offsetX,this.y=e.offsetY,t.mousex=e.offsetX,t.mousey=e.offsetY):this.x=this.y=this.buttons_state=0}to_buffer(t,e){e=e||0;const s=new m(t);return s.setUint32(e,this.x,!0),e+=4,s.setUint32(e,this.y,!0),e+=4,s.setUint16(e,this.buttons_state,!0),e+=2,s.setUint8(e,this.display_id,!0),e+=1,e}buffer_size(){return 11}}class Hi{constructor(t,e){this.to_buffer=Be.prototype.to_buffer,this.buffer_size=Be.prototype.buffer_size,this.display_id=0,this.buttons_state=t.buttons_state,e?(this.x=e.offsetX,this.y=e.offsetY,t.mousex!==void 0&&(this.x-=t.mousex,this.y-=t.mousey),t.mousex=e.offsetX,t.mousey=e.offsetY):this.x=this.y=this.buttons_state=0}}class de{constructor(t,e){e?(this.button=e.button+1,this.buttons_state=1<<e.button,t.buttons_state=this.buttons_state):(this.button=o.SPICE_MOUSE_BUTTON_LEFT,this.buttons_state=o.SPICE_MOUSE_BUTTON_MASK_LEFT)}to_buffer(t,e){e=e||0;const s=new m(t);return s.setUint8(e,this.button,!0),e++,s.setUint16(e,this.buttons_state,!0),e+=2,e}buffer_size(){return 3}}class qt{constructor(t,e){this.to_buffer=de.prototype.to_buffer,this.buffer_size=de.prototype.buffer_size,e?(this.button=e.button+1,this.buttons_state=0,t.buttons_state=this.buttons_state):(this.button=o.SPICE_MOUSE_BUTTON_LEFT,this.buttons_state=0)}}class re{constructor(t){t?this.code=ci(t.keyCode,t.code):this.code=0}to_buffer(t,e){return e=e||0,new m(t).setUint32(e,this.code,!0),e+=4,e}buffer_size(){return 4}}class Xt{constructor(t){this.to_buffer=re.prototype.to_buffer,this.buffer_size=re.prototype.buffer_size,t?this.code=ai(t.keyCode,t.code):this.code=0}}class qi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.surface_id=s.getUint32(e,!0),e+=4,this.id=s.getUint32(e,!0),e+=4,this.flags=s.getUint8(e,!0),e+=1,this.codec_type=s.getUint8(e,!0),e+=1,this.stamp=s.getUint64(e,!0),e+=8,this.stream_width=s.getUint32(e,!0),e+=4,this.stream_height=s.getUint32(e,!0),e+=4,this.src_width=s.getUint32(e,!0),e+=4,this.src_height=s.getUint32(e,!0),e+=4,this.dest=new W,e=this.dest.from_dv(s,e,t),this.clip=new He,this.clip.from_dv(s,e,t)}}class Wt{from_dv(t,e,s){return this.id=t.getUint32(e,!0),e+=4,this.multi_media_time=t.getUint32(e,!0),e+=4,e}}class Xi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.base=new Wt,e=this.base.from_dv(s,e,t),this.data_size=s.getUint32(e,!0),e+=4,this.data=s.u8.subarray(e,e+this.data_size)}}class Wi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.base=new Wt,e=this.base.from_dv(s,e,t),this.width=s.getUint32(e,!0),e+=4,this.height=s.getUint32(e,!0),e+=4,this.dest=new W,e=this.dest.from_dv(s,e,t),this.data_size=s.getUint32(e,!0),e+=4,this.data=s.u8.subarray(e,e+this.data_size)}}class Zi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.id=s.getUint32(e,!0),e+=4,this.clip=new He,this.clip.from_dv(s,e,t)}}class ji{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.id=s.getUint32(e,!0),e+=4}}class Qi{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t);this.stream_id=s.getUint32(e,!0),e+=4,this.unique_id=s.getUint32(e,!0),e+=4,this.max_window_size=s.getUint32(e,!0),e+=4,this.timeout_ms=s.getUint32(e,!0),e+=4}}class Ji{constructor(t,e){this.stream_id=t,this.unique_id=e,this.start_frame_mm_time=0,this.end_frame_mm_time=0,this.num_frames=0,this.num_drops=0,this.last_frame_delay=0,this.audio_delay=-1}to_buffer(t,e){e=e||0;const s=new m(t);return s.setUint32(e,this.stream_id,!0),e+=4,s.setUint32(e,this.unique_id,!0),e+=4,s.setUint32(e,this.start_frame_mm_time,!0),e+=4,s.setUint32(e,this.end_frame_mm_time,!0),e+=4,s.setUint32(e,this.num_frames,!0),e+=4,s.setUint32(e,this.num_drops,!0),e+=4,s.setUint32(e,this.last_frame_delay,!0),e+=4,s.setUint32(e,this.audio_delay,!0),e+=4,e}buffer_size(){return 8*4}}class $i{constructor(t,e){this.count=0,this.resources=[],this.from_buffer(t,e)}from_buffer(t,e){let s;e=e||0;const i=new m(t);for(this.count=i.getUint16(e,!0),e+=2,s=0;s<this.count;s++)this.resources[s]={},this.resources[s].type=i.getUint8(e,!0),e++,this.resources[s].id=i.getUint64(e,!0),e+=8}}class er{constructor(t,e){this.from_buffer(t,e)}from_buffer(t,e){e=e||0;const s=new m(t),i=s.getUint32(e,!0);e+=4;const n=s.getUint32(e,!0);e+=4,this.opened=s.getUint8(e,!0),e+=1,this.name=t.slice(n,n+i-1)}}const Zt=Array(256);let jt=0;function tr(){let r,t,e;for(t=0;t<256;t++){for(r=t,e=0;e<8;e++)r&1?r=(3988292384^r>>>1)>>>0&4294967295:r=r>>>1;Zt[t]=r}jt=1}function sr(r,t,e,s){let i=r,n;for(jt||tr(),n=0;n<s;n++)i=Zt[(i^t[e+n])&255]^i>>>8;return i}function ir(r,t,e){return sr(4294967295,r,t,e)^4294967295}function Xe(r,t,e){const s=new Uint8Array(r);return ir(s,t,e)}class rr{constructor(t,e){this.width=t,this.height=e,this.depth=8,this.type=6,this.compression=0,this.filter=0,this.interlace=0}to_buffer(t,e){e=e||0;const s=e,i=new m(t);return i.setUint32(e,this.buffer_size()-12),e+=4,i.setUint8(e,73),e++,i.setUint8(e,72),e++,i.setUint8(e,68),e++,i.setUint8(e,82),e++,i.setUint32(e,this.width),e+=4,i.setUint32(e,this.height),e+=4,i.setUint8(e,this.depth),e++,i.setUint8(e,this.type),e++,i.setUint8(e,this.compression),e++,i.setUint8(e,this.filter),e++,i.setUint8(e,this.interlace),e++,i.setUint32(e,Xe(t,s+4,this.buffer_size()-8)),e+=4,e}buffer_size(){return 25}}class nr{constructor(){this.s1=1,this.s2=0}update(t){this.s1+=t,this.s1%=65521,this.s2+=this.s1,this.s2%=65521}}class _r{constructor(t,e,s){if(this.width=t,this.height=e,this.data=s,s.byteLength>65535)throw new Error("Cannot handle more than 64K")}to_buffer(t,e){e=e||0;const s=e;let i,n,_;const h=new m(t),c=new nr;h.setUint32(e,this.buffer_size()-12),e+=4,h.setUint8(e,73),e++,h.setUint8(e,68),e++,h.setUint8(e,65),e++,h.setUint8(e,84),e++,h.setUint8(e,120),e++,h.setUint8(e,1),e++,h.setUint8(e,128),e++,h.setUint16(e,this.data.byteLength+this.height),e+=2,h.setUint16(e,~(this.data.byteLength+this.height)),e+=2;const a=new Uint8Array(this.data);for(_=0,n=0;n<this.height;n++)for(h.setUint8(e,0),e++,c.update(0),i=0;i<this.width&&_<this.data.byteLength;i++)c.update(a[_]),h.setUint8(e,a[_++]),e++,c.update(a[_]),h.setUint8(e,a[_++]),e++,c.update(a[_]),h.setUint8(e,a[_++]),e++,c.update(a[_]),h.setUint8(e,a[_++]),e++;return h.setUint16(e,c.s2),e+=2,h.setUint16(e,c.s1),e+=2,h.setUint32(e,Xe(t,s+4,this.buffer_size()-8)),e+=4,e}buffer_size(){return 12+this.data.byteLength+this.height+4+2+1+2+2}}class or{to_buffer(t,e){e=e||0;const s=e,i=new m(t);return i.setUint32(e,this.buffer_size()-12),e+=4,i.setUint8(e,73),e++,i.setUint8(e,69),e++,i.setUint8(e,78),e++,i.setUint8(e,68),e++,i.setUint32(e,Xe(t,s+4,this.buffer_size()-8)),e+=4,e}buffer_size(){return 12}}function hr(r,t,e){let s;const i=new rr(r,t),n=new _r(r,t,e),_=new or,h=new ArrayBuffer(i.buffer_size()+n.buffer_size()+_.buffer_size());let c=i.to_buffer(h);c=n.to_buffer(h,c),c=_.to_buffer(h,c);const a=new Uint8Array(h);let d="";for(s=0;s<c;s++)d+="%",a[s]<16&&(d+="0"),d+=a[s].toString(16);return"%89PNG%0D%0A%1A%0A"+d}var ke;(r=>{r.cursors={},r.unknown_cursors={},r.warned=!1;function t(a,d){r.cursors[a]=d}r.add_cursor=t;function e(a,d){r.warned||(r.warned=!0,alert(`Internet Explorer does not support dynamic cursors. This page will now simulate cursors with images, which will be imperfect. We recommend using Chrome or Firefox instead.
12
+
13
+ If you need to use Internet Explorer, you can create a static cursor file for each cursor your application uses. View the console log for more information on creating static cursors for your environment.`)),r.unknown_cursors[a]||(r.unknown_cursors[a]=d,console.log("Unknown cursor. Simulation required. To avoid simulation for this cursor, create and include a custom javascript file, and add the following line:"),console.log('SpiceCursorSimulator.add_cursor("'+a+'"), "<your filename here>.cur");'),console.log("And then run following command, redirecting output into <your filename here>.cur:"),console.log(`php -r "echo urldecode('`+d+`');"`))}r.unknown_cursor=e;function s(a,d,E,S){var I,b,C;const p=Ts(S+" "+d.header.hot_spot_x+" "+d.header.hot_spot_y);if(typeof r.cursors[p]<"u"){const T="url("+r.cursors[p]+"), default";E.style.cursor=T}window.getComputedStyle(E,null).cursor=="auto"?(e(p,c(d.header.width,d.header.height,d.data.byteLength,d.header.hot_spot_x,d.header.hot_spot_y)+S),(I=document.getElementById(a.parent.screen_id))==null||I.style.setProperty("cursor","none"),a.spice_simulated_cursor||(a.spice_simulated_cursor=document.createElement("img"),a.spice_simulated_cursor.style.position="absolute",a.spice_simulated_cursor.style.display="none",a.spice_simulated_cursor.style.overflow="hidden",a.spice_simulated_cursor.spice_screen=document.getElementById(a.parent.screen_id),a.spice_simulated_cursor.addEventListener("mousemove",i),(b=a.spice_simulated_cursor.spice_screen)==null||b.appendChild(a.spice_simulated_cursor)),a.spice_simulated_cursor.src="data:image/png,"+S,a.spice_simulated_cursor.spice_hot_x=d.header.hot_spot_x,a.spice_simulated_cursor.spice_hot_y=d.header.hot_spot_y,a.spice_simulated_cursor.style.pointerEvents="none"):a.spice_simulated_cursor&&((C=a.spice_simulated_cursor.spice_screen)==null||C.removeChild(a.spice_simulated_cursor),delete a.spice_simulated_cursor)}r.simulate_cursor=s;function i(a){const d=n(a,this.spice_screen);return this.spice_screen.dispatchEvent(d)}r.handle_sim_mousemove=i;function n(a,d){const E=document.createEvent("mouseevent");return E.initMouseEvent(a.type,!0,!0,a.view,a.detail,a.screenX,a.screenY,a.clientX,a.clientY,a.ctrlKey,a.altKey,a.shiftKey,a.metaKey,a.button,a.relatedTarget),E}r.duplicate_mouse_event=n;class _{to_buffer(d,E){E=E||0;const S=new m(d);return S.setUint16(E,0,!0),E+=2,S.setUint16(E,2,!0),E+=2,S.setUint16(E,1,!0),E+=2,E}buffer_size(){return 6}}r.ICONDIR=_;class h{constructor(d,E,S,p,I){this.width=d,this.height=E,this.bytes=S,this.hot_x=p,this.hot_y=I}to_buffer(d,E){E=E||0;const S=new m(d);return S.setUint8(E,this.width),E++,S.setUint8(E,this.height),E++,S.setUint8(E,0),E++,S.setUint8(E,0),E++,S.setUint16(E,this.hot_x,!0),E+=2,S.setUint16(E,this.hot_y,!0),E+=2,S.setUint32(E,this.bytes,!0),E+=4,S.setUint32(E,E+4,!0),E+=4,E}buffer_size(){return 16}}r.ICONDIRENTRY=h;function c(a,d,E,S,p){let I;const b=new _,C=new h(a,d,E,S,p),T=new ArrayBuffer(b.buffer_size()+C.buffer_size());let w=b.to_buffer(T);w=C.to_buffer(T,w);const D=new Uint8Array(T);let Q="";for(I=0;I<w;I++)Q+="%",D[I]<16&&(Q+="0"),Q+=D[I].toString(16);return Q}r.create_icondir=c})(ke||(ke={}));class cr{constructor(t,e){this.needed=0,this.size=0,this.buffers=[],this.sc=t,this.callback=e,this.sc.ws.wire_reader=this,this.sc.ws.binaryType="arraybuffer",this.sc.ws.addEventListener("message",ar)}inbound(t){if(this.needed==0){this.buffers.push(t),this.size+=t.byteLength;return}for(this.buffers.length==0&&t.byteLength>=this.needed?(t.byteLength>this.needed&&(this.size=t.byteLength-this.needed,this.buffers.push(t.slice(this.needed)),t=t.slice(0,this.needed)),this.callback.call(this.sc,t,this.saved_msg_header||void 0)):(this.buffers.push(t),this.size+=t.byteLength);this.size>=this.needed;){let e=0;const s=new ArrayBuffer(this.needed),i=new Uint8Array(s);for(;e<s.byteLength&&this.buffers.length>0;){const n=this.buffers.shift();if(!n)return;const _=new Uint8Array(n),h=s.byteLength-e;if(_.length<=h)i.set(_,e),e+=_.length,this.size-=_.length;else{const c=_.slice(0,h);i.set(c,e),e+=c.length,this.size-=c.length,this.buffers.unshift(_.slice(h).buffer)}}this.callback.call(this.sc,s,this.saved_msg_header||void 0)}}request(t){this.needed=t}save_header(t){this.saved_msg_header=t}clear_header(){this.saved_msg_header=void 0}}function ar(r){this.wire_reader.inbound(r.data)}const lr=[26,69,223,163],ur=[66,134],dr=[66,247],fr=[66,242],Er=[66,243],pr=[66,130],mr=[66,135],Sr=[66,133],Ir=[24,83,128,103],Qt=[21,73,169,102],at=[42,215,177],lt=[77,128],ut=[87,65],Ar=[17,77,155,116],Cr=[77,187],dt=[83,171],ft=[83,172],Jt=[22,84,174,107],$t=[174],fe=[215],Ee=[115,197],pe=[131],me=[185],Se=[136],Ie=[85,170],Ae=[156],Ce=[109,231],ge=[85,238],be=[170],Pe=[86,187],Et=[86,170],pt=[99,162],we=[134],gr=[224],mt=[154],St=[176],It=[186],br=[225],At=[181],Ct=[159],Pr=[31,67,182,117],gt=[231],wr=[163],U={CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME:128,OPUS_FREQUENCY:48e3,OPUS_CHANNELS:2,SPICE_PLAYBACK_CODEC:'audio/webm; codecs="opus"',MAX_CLUSTER_TIME:1e3,EXPECTED_PACKET_DURATION:10,GAP_DETECTION_THRESHOLD:50,SPICE_VP8_CODEC:'video/webm; codecs="vp8"'};function j(r,t,e){const s=128|r;return t.setUint8(e,s),e+1}function M(r,t,e,s){return s=N(r,e,s),s=j(1,e,s),e.setUint8(s,t),s+1}function ne(r,t,e,s){return s=N(r,e,s),s=j(4,e,s),e.setUint32(s,t),s+4}function xe(r,t,e,s){return s=N(r,e,s),s=j(2,e,s),e.setUint16(s,t),s+2}function Mr(r,t,e,s){return s=N(r,e,s),s=j(4,e,s),e.setFloat32(s,t),s+4}function F(r,t,e){t.setUint8(e++,1),t.setUint8(e++,0),t.setUint8(e++,0),t.setUint8(e++,0);const s=r&4294967295;for(let i=24;i>=0;i-=8)t.setUint8(e++,s>>i);return e}function N(r,t,e){for(let s=0;s<r.length;s++)t.setUint8(e+s,r[s]);return e+r.length}function Tr(r,t,e){for(let s=0;s<r.length;s++)t.setUint8(e+s,r.charCodeAt(s));return e+r.length}function Z(r,t,e,s){return s=N(r,e,s),t.length<127?s=j(t.length,e,s):s=F(t.length,e,s),typeof t=="string"?s=Tr(t,e,s):s=N(t,e,s),s}class yr{constructor(){this.id=lr,this.Version=1,this.ReadVersion=1,this.MaxIDLength=4,this.MaxSizeLength=8,this.DocType="webm",this.DocTypeVersion=2,this.DocTypeReadVersion=2}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(31,s,e),e=M(ur,this.Version,s,e),e=M(dr,this.ReadVersion,s,e),e=M(fr,this.MaxIDLength,s,e),e=M(Er,this.MaxSizeLength,s,e),e=Z(pr,this.DocType,s,e),e=M(mr,this.DocTypeVersion,s,e),e=M(Sr,this.DocTypeReadVersion,s,e),e}buffer_size(){return 39+this.id.length}}class Dr{constructor(){this.id=Ir}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),s.setUint8(e++,255),e}buffer_size(){return this.id.length+1}}class Lr{constructor(){this.id=Qt,this.timecode_scale=1e6,this.muxing_app="spice",this.writing_app="spice-html5"}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=ne(at,this.timecode_scale,s,e),e=Z(lt,this.muxing_app,s,e),e=Z(ut,this.writing_app,s,e),e}buffer_size(){return this.id.length+8+at.length+1+4+lt.length+1+this.muxing_app.length+ut.length+1+this.writing_app.length}}class Ur{constructor(t){this.id=br,this.channels=U.OPUS_CHANNELS,this.sampling_frequency=t}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=M(Ct,this.channels,s,e),e=Mr(At,this.sampling_frequency,s,e),e}buffer_size(){return this.id.length+8+At.length+1+4+Ct.length+1+1}}class Nr{constructor(t,e){this.id=gr,this.flag_interlaced=0,this.width=t,this.height=e}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=M(mt,this.flag_interlaced,s,e),e=xe(St,this.width,s,e),e=xe(It,this.height,s,e),e}buffer_size(){return this.id.length+8+mt.length+1+1+St.length+1+2+It.length+1+2}}class bt{constructor(t,e){this.id=Cr,this.pos=e,this.seekid=t}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=j(this.buffer_size()-1-this.id.length,s,e),e=Z(dt,this.seekid,s,e),e=xe(ft,this.pos,s,e),e}buffer_size(){return this.id.length+1+dt.length+1+this.seekid.length+ft.length+1+2}}class Rr{constructor(t,e){this.id=Ar,this.info=new bt(Qt,t),this.track=new bt(Jt,e)}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=this.info.to_buffer(t,e),e=this.track.to_buffer(t,e),e}buffer_size(){return this.id.length+8+this.info.buffer_size()+this.track.buffer_size()}}class Gr{constructor(){this.id=$t,this.number=1,this.uid=2,this.type=2,this.flag_enabled=1,this.flag_default=1,this.flag_forced=1,this.flag_lacing=0,this.min_cache=0,this.max_block_addition_id=0,this.codec_decode_all=0,this.seek_pre_roll=0,this.codec_delay=8e7,this.codec_id="A_OPUS",this.audio=new Ur(U.OPUS_FREQUENCY),this.codec_private=[79,112,117,115,72,101,97,100,1,U.OPUS_CHANNELS,0,15,128,187,0,0,0,0,0]}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=M(fe,this.number,s,e),e=M(Ee,this.uid,s,e),e=M(me,this.flag_enabled,s,e),e=M(Se,this.flag_default,s,e),e=M(Ie,this.flag_forced,s,e),e=M(Ae,this.flag_lacing,s,e),e=Z(we,this.codec_id,s,e),e=M(Ce,this.min_cache,s,e),e=M(ge,this.max_block_addition_id,s,e),e=M(be,this.codec_decode_all,s,e),e=ne(Et,this.codec_delay,s,e),e=ne(Pe,this.seek_pre_roll,s,e),e=M(pe,this.type,s,e),e=Z(pt,this.codec_private,s,e),e=this.audio.to_buffer(t,e),e}buffer_size(){return this.id.length+8+fe.length+1+1+Ee.length+1+1+pe.length+1+1+me.length+1+1+Se.length+1+1+Ie.length+1+1+Ae.length+1+1+Ce.length+1+1+ge.length+1+1+be.length+1+1+Pe.length+1+4+Et.length+1+4+we.length+this.codec_id.length+1+pt.length+1+this.codec_private.length+this.audio.buffer_size()}}class Or{constructor(t,e){this.id=$t,this.number=1,this.uid=1,this.type=1,this.flag_enabled=1,this.flag_default=1,this.flag_forced=1,this.flag_lacing=1,this.min_cache=0,this.max_block_addition_id=0,this.codec_id="V_VP8",this.codec_decode_all=1,this.seek_pre_roll=0,this.video=new Nr(t,e)}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=M(fe,this.number,s,e),e=M(Ee,this.uid,s,e),e=M(me,this.flag_enabled,s,e),e=M(Se,this.flag_default,s,e),e=M(Ie,this.flag_forced,s,e),e=M(Ae,this.flag_lacing,s,e),e=Z(we,this.codec_id,s,e),e=M(Ce,this.min_cache,s,e),e=M(ge,this.max_block_addition_id,s,e),e=M(be,this.codec_decode_all,s,e),e=ne(Pe,this.seek_pre_roll,s,e),e=M(pe,this.type,s,e),e=this.video.to_buffer(t,e),e}buffer_size(){return this.id.length+8+fe.length+1+1+Ee.length+1+1+me.length+1+1+Se.length+1+1+Ie.length+1+1+Ae.length+1+1+we.length+this.codec_id.length+1+Ce.length+1+1+ge.length+1+1+be.length+1+1+Pe.length+1+4+pe.length+1+1+this.video.buffer_size()}}class es{constructor(t){this.id=Jt,this.track_entry=t}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),e=F(this.buffer_size()-8-this.id.length,s,e),e=this.track_entry.to_buffer(t,e),e}buffer_size(){return this.id.length+8+this.track_entry.buffer_size()}}class ts{constructor(t,e){this.id=Pr,this.timecode=t,this.data=e}to_buffer(t,e){e=e||0;const s=new DataView(t);return e=N(this.id,s,e),s.setUint8(e++,255),e=ne(gt,this.timecode,s,e),e}buffer_size(){return this.id.length+1+gt.length+1+4}}class ss{constructor(t,e,s){this.id=wr,this.timecode=t,this.data=e,this.keyframe=s}to_buffer(t,e){e=e||0;const s=new DataView(t);e=N(this.id,s,e),e=F(this.data.byteLength+4,s,e),e=j(1,s,e),s.setUint16(e,this.timecode),e+=2,s.setUint8(e,this.keyframe?U.CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME:0),e+=1;const i=new Uint8Array(this.data);for(let n=0;n<this.data.byteLength;n++)s.setUint8(e++,i[n]);return e}buffer_size(){return this.id.length+8+1+2+1+this.data.byteLength}}class is{constructor(){this.ebml=new yr,this.segment=new Dr,this.seek_head=new Rr(0,0),this.info=new Lr,this.seek_head.info.pos=this.segment.buffer_size()+this.seek_head.buffer_size(),this.seek_head.track.pos=this.seek_head.info.pos+this.info.buffer_size()}to_buffer(t,e){return e=e||0,e=this.ebml.to_buffer(t,e),e=this.segment.to_buffer(t,e),e=this.info.to_buffer(t,e),e}buffer_size(){return this.ebml.buffer_size()+this.segment.buffer_size()+this.info.buffer_size()}}class q{constructor(t){if(t===void 0||t.uri===void 0||!t.uri)throw new Error("You must specify a uri");if(this.ws=new WebSocket(t.uri,"binary"),!this.ws.binaryType)throw new Error("WebSocket doesn't support binaryType. Try a different browser.");if(this.connection_id=t.connection_id!==void 0?t.connection_id:0,this.type=t.type!==void 0?t.type:o.SPICE_CHANNEL_MAIN,this.chan_id=t.chan_id!==void 0?t.chan_id:0,t.parent!==void 0&&(this.parent=t.parent,this.message_id=t.parent.message_id,this.password=t.parent.password),t.screen_id!==void 0&&(this.screen_id=t.screen_id),t.dump_id!==void 0&&(this.dump_id=t.dump_id),t.message_id!==void 0&&(this.message_id=t.message_id),t.password!==void 0&&(this.password=t.password),t.onerror!==void 0&&(this.onerror=t.onerror),t.onsuccess!==void 0&&(this.onsuccess=t.onsuccess),t.onagent!==void 0&&(this.onagent=t.onagent),this.state="connecting",this.ws.parent=this,this.wire_reader=new cr(this,this.process_inbound.bind(this)),this.messages_sent=0,this.warnings=[],this.ws.addEventListener("open",function(e){this.parent.send_hdr(),this.parent.wire_reader.request(Ge.prototype.buffer_size()),this.parent.state="start"}),this.ws.addEventListener("error",function(e){"url"in e.target&&this.parent.log_err("WebSocket error: Can't connect to websocket on URL: "+e.target.url),this.parent.report_error(e)}),this.ws.addEventListener("close",function(e){if(this.parent.state!="closing"&&this.parent.state!="error"&&this.parent.onerror!==void 0){var e;this.parent.state=="connecting"?e=new Error("Connection refused."):this.parent.state=="start"||this.parent.state=="link"?e=new Error("Unexpected protocol mismatch."):this.parent.state=="ticket"?e=new Error("Bad password."):e=new Error("Unexpected close while "+this.parent.state),this.parent.onerror(e),this.parent.log_err(e.toString())}}),this.ws.readyState==2||this.ws.readyState==3)throw new Error("Unable to connect to "+t.uri);this.timeout=window.setTimeout(Yr,o.SPICE_CONNECT_TIMEOUT,this)}send_hdr(){const t=new Ge,e=new ui;if(e.connection_id=this.connection_id,e.channel_type=this.type,e.channel_id=this.chan_id,e.common_caps.push(1<<o.SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION|1<<o.SPICE_COMMON_CAP_MINI_HEADER),e.channel_type==o.SPICE_CHANNEL_PLAYBACK){var s=0;"MediaSource"in window&&MediaSource.isTypeSupported(U.SPICE_PLAYBACK_CODEC)&&(s|=1<<o.SPICE_PLAYBACK_CAP_OPUS),e.channel_caps.push(s)}else if(e.channel_type==o.SPICE_CHANNEL_MAIN)e.channel_caps.push(1<<o.SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS);else if(e.channel_type==o.SPICE_CHANNEL_DISPLAY){var s=1<<o.SPICE_DISPLAY_CAP_SIZED_STREAM|1<<o.SPICE_DISPLAY_CAP_STREAM_REPORT|1<<o.SPICE_DISPLAY_CAP_MULTI_CODEC|1<<o.SPICE_DISPLAY_CAP_CODEC_MJPEG;"MediaSource"in window&&MediaSource.isTypeSupported(U.SPICE_VP8_CODEC)&&(s|=1<<o.SPICE_DISPLAY_CAP_CODEC_VP8),e.channel_caps.push(s)}t.size=e.buffer_size();const i=new ArrayBuffer(t.buffer_size()+e.buffer_size());t.to_buffer(i),e.to_buffer(i,t.buffer_size()),this.ws.send(i)}send_ticket(t){const e=new fi;e.auth_mechanism=o.SPICE_COMMON_CAP_AUTH_SPICE,e.encrypted_data=t;const s=new ArrayBuffer(e.buffer_size());e.to_buffer(s),this.ws.send(s)}send_msg(t){const e=new ArrayBuffer(t.buffer_size());t.to_buffer(e),this.messages_sent++,this.ws.send(e)}process_inbound(t,e){if(this.state=="ready")if(e==null){const i=new y(t);i.type>500,i.size==0?(this.process_message(i),this.wire_reader.request(y.prototype.buffer_size())):(this.wire_reader.request(i.size),this.wire_reader.save_header(i))}else e.data=t,this.process_message(e),this.wire_reader.request(y.prototype.buffer_size()),this.wire_reader.save_header(void 0);else if(this.state=="start")if(this.reply_hdr=new Ge(t),this.reply_hdr.magic!=o.SPICE_MAGIC){this.state="error";var s=new Error("Error: magic mismatch: "+this.reply_hdr.magic);this.report_error(s)}else this.wire_reader.request(this.reply_hdr.size),this.state="link";else if(this.state=="link")if(this.reply_link=new di(t),this.reply_link.error){this.state="error";var s=new Error("Error: reply link error "+this.reply_link.error);this.report_error(s)}else this.send_ticket(vs(this.reply_link.pub_key,this.password+"\0")),this.state="ticket",this.wire_reader.request(_t.prototype.buffer_size());else if(this.state=="ticket")if(this.auth_reply=new _t(t),this.auth_reply.auth_code==o.SPICE_LINK_ERR_OK){if(this.type==o.SPICE_CHANNEL_DISPLAY){const i=new Ni,n=new y;n.build_msg(o.SPICE_MSGC_DISPLAY_INIT,i),this.send_msg(n)}this.state="ready",this.wire_reader.request(y.prototype.buffer_size()),this.timeout&&(window.clearTimeout(this.timeout),delete this.timeout)}else{if(this.state="error",this.auth_reply.auth_code==o.SPICE_LINK_ERR_PERMISSION_DENIED)var s=new Error("Permission denied.");else var s=new Error("Unexpected link error "+this.auth_reply.auth_code);this.report_error(s)}}process_common_messages(t){if(t.type==o.SPICE_MSG_SET_ACK){const e=new bi(t.data);this.ack_window=e.window,this.msgs_until_ack=this.ack_window;const s=new Pi(e),i=new y;return i.build_msg(o.SPICE_MSGC_ACK_SYNC,s),this.send_msg(i),!0}if(t.type==o.SPICE_MSG_PING){const e=new y;return e.type=o.SPICE_MSGC_PONG,t.data&&(e.data=t.data.slice(0,12)),e.size=e.buffer_size(),this.send_msg(e),!0}if(t.type==o.SPICE_MSG_NOTIFY){const e=new Ui(t.data);return e.severity==o.SPICE_NOTIFY_SEVERITY_ERROR?this.log_err(e.message):e.severity==o.SPICE_NOTIFY_SEVERITY_WARN?this.log_warn(e.message):this.log_info(e.message),!0}return!1}process_message(t){let e;const s=Date.now();if(e=this.process_common_messages(t),e||(this.process_channel_message?(e=this.process_channel_message(t),e||this.log_warn(this.channel_type()+": Unknown message type "+t.type+"!")):this.log_err(this.channel_type()+": No message handlers for this channel; message "+t.type)),this.msgs_until_ack!==void 0&&this.ack_window&&(this.msgs_until_ack--,this.msgs_until_ack<=0)){this.msgs_until_ack=this.ack_window;const n=new y;n.type=o.SPICE_MSGC_ACK,this.send_msg(n)}const i=Date.now()-s;return i>U.GAP_DETECTION_THRESHOLD&&console.log("delta "+this.channel_type()+":"+t.type+" "+i),e}channel_type(){return this.type==o.SPICE_CHANNEL_MAIN?"main":this.type==o.SPICE_CHANNEL_DISPLAY?"display":this.type==o.SPICE_CHANNEL_INPUTS?"inputs":this.type==o.SPICE_CHANNEL_CURSOR?"cursor":this.type==o.SPICE_CHANNEL_PLAYBACK?"playback":this.type==o.SPICE_CHANNEL_RECORD?"record":this.type==o.SPICE_CHANNEL_TUNNEL?"tunnel":this.type==o.SPICE_CHANNEL_SMARTCARD?"smartcard":this.type==o.SPICE_CHANNEL_USBREDIR?"usbredir":this.type==o.SPICE_CHANNEL_PORT?"port":this.type==o.SPICE_CHANNEL_WEBDAV?"webdav":"unknown-"+this.type}log_info(){const t=Array.prototype.join.call(arguments," ");if(console.log(t),this.message_id){const e=document.createElement("p");e.appendChild(document.createTextNode(t)),e.className+="spice-message-info";const s=document.getElementById(this.message_id);s&&s.appendChild(e)}}log_warn(){const t=Array.prototype.join.call(arguments," ");if(console.log("WARNING: "+t),this.message_id){const e=document.createElement("p");e.appendChild(document.createTextNode(t)),e.className+="spice-message-warning";const s=document.getElementById(this.message_id);s&&s.appendChild(e)}}log_err(){const t=Array.prototype.join.call(arguments," ");if(console.log("ERROR: "+t),this.message_id){const e=document.createElement("p");e.appendChild(document.createTextNode(t)),e.className+="spice-message-error";const s=document.getElementById(this.message_id);s&&s.appendChild(e)}}known_unimplemented(t,e){if(!this.warnings[t]||_i>1){let s="";s=" [ further notices suppressed ]",this.log_warn("Unimplemented function "+t+"("+e+")"+s),this.warnings[t]=!0}}report_error(t){if(this.log_err(t.toString()),this.onerror!=null)this.onerror(t);else throw t}report_success(t){this.onsuccess!=null&&this.onsuccess(t)}cleanup(){this.timeout&&(window.clearTimeout(this.timeout),delete this.timeout),this.ws&&(this.ws.close(),this.ws=void 0)}handle_timeout(){const t=new Error("Connection timed out.");this.report_error(t)}}function Yr(r){r.handle_timeout()}class rs extends q{process_channel_message(t){if(t.type==o.SPICE_MSG_CURSOR_INIT){const e=new ki(t.data);return this.parent&&this.parent.inputs&&this.parent.inputs.mouse_mode==o.SPICE_MOUSE_MODE_SERVER&&(this.parent.inputs.mousex=e.position.x,this.parent.inputs.mousey=e.position.y),!0}if(t.type==o.SPICE_MSG_CURSOR_SET){const e=new Vi(t.data);return e.flags&o.SPICE_CURSOR_FLAGS_NONE?(document.getElementById(this.parent.screen_id).style.cursor="none",!0):(e.flags>0&&this.log_warn("FIXME: No support for cursor flags "+e.flags),e.cursor.header.type!=o.SPICE_CURSOR_TYPE_ALPHA?(this.log_warn("FIXME: No support for cursor type "+e.cursor.header.type),!1):(this.set_cursor(e.cursor),!0))}return t.type==o.SPICE_MSG_CURSOR_MOVE?(this.known_unimplemented(t.type,"Cursor Move"),!0):t.type==o.SPICE_MSG_CURSOR_HIDE?(document.getElementById(this.parent.screen_id).style.cursor="none",!0):t.type==o.SPICE_MSG_CURSOR_TRAIL?(this.known_unimplemented(t.type,"Cursor Trail"),!0):t.type==o.SPICE_MSG_CURSOR_RESET?(document.getElementById(this.parent.screen_id).style.cursor="auto",!0):t.type==o.SPICE_MSG_CURSOR_INVAL_ONE?(this.known_unimplemented(t.type,"Cursor Inval One"),!0):t.type==o.SPICE_MSG_CURSOR_INVAL_ALL}set_cursor(t){const e=hr(t.header.width,t.header.height,t.data),s="url(data:image/png,"+e+") "+t.header.hot_spot_x+" "+t.header.hot_spot_y+", default",i=document.getElementById(this.parent.screen_id);i.style.cursor="auto",i.style.cursor=s,window.getComputedStyle(i,null).cursor=="auto"&&ke.simulate_cursor(this,t,i,e)}}class vr{constructor(t,e){this.progressbar_container=null,this.progressbar=null,this.cancelled=!1,this.id=t,this.file=e}create_progressbar(){const t=this,e=document.createElement("input");if(this.progressbar_container=document.createElement("div"),this.progressbar=document.createElement("progress"),e.type="button",e.value="Cancel",e.style.float="right",e.onclick=function(){t.cancelled=!0,t.remove_progressbar()},this.progressbar&&(this.progressbar.setAttribute("max",this.file.size.toString()),this.progressbar.setAttribute("value","0"),this.progressbar.style.width="100%",this.progressbar.style.margin="4px auto",this.progressbar.style.display="inline-block"),this.progressbar_container){this.progressbar_container.style.width="90%",this.progressbar_container.style.margin="auto",this.progressbar_container.style.padding="4px",this.progressbar_container.textContent=this.file.name,this.progressbar_container.appendChild(e),this.progressbar&&this.progressbar_container.appendChild(this.progressbar);const s=document.getElementById("spice-xfer-area");s&&s.appendChild(this.progressbar_container)}}update_progressbar(t){this.progressbar&&this.progressbar.setAttribute("value",t.toString())}remove_progressbar(){this.progressbar_container&&this.progressbar_container.parentNode&&this.progressbar_container.parentNode.removeChild(this.progressbar_container)}}function Kr(r){r.stopPropagation(),r.preventDefault(),r.dataTransfer&&(r.dataTransfer.dropEffect="copy")}function Br(r){var s;const t=window.spice_connection,e=(s=r.dataTransfer)==null?void 0:s.files;if(r.stopPropagation(),r.preventDefault(),e)for(let i=e.length-1;i>=0;i--)e[i].type&&t.file_xfer_start(e[i])}let J=-1,$=-1,ee=-1,se=-1;class ns extends q{constructor(...t){super(...t),this.button_state=0,this.waiting_for_ack=0}process_channel_message(t){if(t.type==o.SPICE_MSG_INPUTS_INIT){const e=new Ki(t.data);return this.keyboard_modifiers=e.keyboard_modifiers,!0}if(t.type==o.SPICE_MSG_INPUTS_KEY_MODIFIERS){const e=new Bi(t.data);return this.keyboard_modifiers=e.keyboard_modifiers,!0}return t.type==o.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK?(this.waiting_for_ack-=o.SPICE_INPUT_MOTION_ACK_BUNCH,!0):!1}}function Pt(r){const t=new y;let e;this.sc.mouse_mode==o.SPICE_MOUSE_MODE_CLIENT?(e=new Be(this.sc,r),t.build_msg(o.SPICE_MSGC_INPUTS_MOUSE_POSITION,e)):(e=new Hi(this.sc,r),t.build_msg(o.SPICE_MSGC_INPUTS_MOUSE_MOTION,e)),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.waiting_for_ack<2*o.SPICE_INPUT_MOTION_ACK_BUNCH&&(this.sc.inputs.send_msg(t),this.sc.inputs.waiting_for_ack++),this.sc&&this.sc.cursor&&this.sc.cursor.spice_simulated_cursor&&(this.sc.cursor.spice_simulated_cursor.style.display="block",this.sc.cursor.spice_simulated_cursor.style.left=r.pageX-this.sc.cursor.spice_simulated_cursor.spice_hot_x+"px",this.sc.cursor.spice_simulated_cursor.style.top=r.pageY-this.sc.cursor.spice_simulated_cursor.spice_hot_y+"px",r.preventDefault())}function wt(r){const t=new de(this.sc,r),e=new y;e.build_msg(o.SPICE_MSGC_INPUTS_MOUSE_PRESS,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(e),r.preventDefault()}function Mt(r){return r.preventDefault(),!1}function Tt(r){const t=new qt(this.sc,r),e=new y;e.build_msg(o.SPICE_MSGC_INPUTS_MOUSE_RELEASE,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(e),r.preventDefault()}function yt(r){const t=new de,e=new qt;r.deltaY<0?t.button=e.button=o.SPICE_MOUSE_BUTTON_UP:t.button=e.button=o.SPICE_MOUSE_BUTTON_DOWN,t.buttons_state=0,e.buttons_state=0;const s=new y;s.build_msg(o.SPICE_MSGC_INPUTS_MOUSE_PRESS,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(s),s.build_msg(o.SPICE_MSGC_INPUTS_MOUSE_RELEASE,e),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(s),r.preventDefault()}function Dt(r){const t=new re(r),e=new y;_s(r,t.code,this.sc),e.build_msg(o.SPICE_MSGC_INPUTS_KEY_DOWN,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(e),r.preventDefault()}function Lt(r){const t=new Xt(r),e=new y;_s(r,t.code,this.sc),e.build_msg(o.SPICE_MSGC_INPUTS_KEY_UP,t),this.sc&&this.sc.inputs&&this.sc.inputs.state==="ready"&&this.sc.inputs.send_msg(e),r.preventDefault()}function kr(r){if(r&&r.inputs&&r.inputs.state==="ready"){const t=new re,e=new y;H(!0,u.KEY_LCtrl,r),H(!0,u.KEY_Alt,r),t.code=u.KEY_KP_Decimal,e.build_msg(o.SPICE_MSGC_INPUTS_KEY_DOWN,t),r.inputs.send_msg(e),e.build_msg(o.SPICE_MSGC_INPUTS_KEY_UP,t),r.inputs.send_msg(e),$==!1&&H(!1,u.KEY_LCtrl,r),ee==!1&&H(!1,u.KEY_Alt,r)}}function H(r,t,e){const s=new y;if(r){var i=new re;i.code=t,s.build_msg(o.SPICE_MSGC_INPUTS_KEY_DOWN,i)}else{var i=new Xt;i.code=128|t,s.build_msg(o.SPICE_MSGC_INPUTS_KEY_UP,i)}e.inputs.send_msg(s)}function _s(r,t,e){J===-1&&(J=r.shiftKey,$=r.ctrlKey,ee=r.altKey,se=r.metaKey),t===u.KEY_ShiftL?J=!0:t===u.KEY_Alt?ee=!0:t===u.KEY_LCtrl?$=!0:t===57525?se=!0:t===(128|u.KEY_ShiftL)?J=!1:t===(128|u.KEY_Alt)?ee=!1:t===(128|u.KEY_LCtrl)?$=!1:t===57525&&(se=!1),e&&e.inputs&&e.inputs.state==="ready"&&(J!=r.shiftKey&&(console.log("Shift state out of sync"),H(r.shiftKey,u.KEY_ShiftL,e),J=r.shiftKey),ee!=r.altKey&&(console.log("Alt state out of sync"),H(r.altKey,u.KEY_Alt,e),ee=r.altKey),$!=r.ctrlKey&&(console.log("Ctrl state out of sync"),H(r.ctrlKey,u.KEY_LCtrl,e),$=r.ctrlKey),se!=r.metaKey&&(console.log("Meta state out of sync"),H(r.metaKey,57525,e),se=r.metaKey))}function Oe(r,t,e,s,i){let n=t,_=0,h,c=0;for(h=r[n++];_*4<e.length;h=r[n++]){let d=_,E=h>>5,S=(h&31)<<8;if(h>=32){var a;if(E--,E==6)do a=r[n++],E+=a;while(a==255);if(a=r[n++],S+=a,a==255&&S-a==7936&&(S=r[n++]<<8,S+=r[n++],S+=8191),E+=1,s==o.LZ_IMAGE_TYPE_RGBA&&(E+=2),S+=1,d-=S,d==_-1){const p=d;for(;E;--E){if(s==o.LZ_IMAGE_TYPE_RGBA)e[_*4+3]=e[p*4+3];else for(c=0;c<4;c++)e[_*4+c]=e[p*4+c];_++}}else for(;E;--E){if(s==o.LZ_IMAGE_TYPE_RGBA)e[_*4+3]=e[d*4+3];else for(c=0;c<4;c++)e[_*4+c]=e[d*4+c];_++,d++}}else for(h++,s==o.LZ_IMAGE_TYPE_RGBA?e[_*4+3]=r[n++]:(e[_*4+0]=r[n+2],e[_*4+1]=r[n+1],e[_*4+2]=r[n+0],i&&(e[_*4+3]=255),n+=3),_++,--h;h;h--)s==o.LZ_IMAGE_TYPE_RGBA?e[_*4+3]=r[n++]:(e[_*4+0]=r[n+2],e[_*4+1]=r[n+1],e[_*4+2]=r[n+0],i&&(e[_*4+3]=255),n+=3),_++}return n-1}function Ut(r){const t=r.width*4,e=r.height;let s=e;const i=new Uint8Array(r.width*r.height*4);for(;s--;)i.set(r.data.subarray(s*t,(s+1)*t),(e-s-1)*t);r.data.set(i)}function xr(r,t){let e=0,s=0;const i=r.length,n=t.length;for(;e<i&&s<n;){const h=r[e++];let c=h>>4,a=h&15;if(c>0){if(c===15){var _;do _=r[e++],c+=_;while(_===255&&e<i)}if(s+c>n&&(c=n-s),t.set(r.subarray(e,e+c),s),e+=c,s+=c,s>=n||e>=i)break}const d=r[e]|r[e+1]<<8;if(e+=2,a===15){var _;do _=r[e++],a+=_;while(_===255&&e<i)}a+=4;let E=s-d;if(E<0)break;s+a>n&&(a=n-s);for(let S=0;S<a;S++)t[s++]=t[E++]}return s}function Nt(r,t){let e;if(t.type>=o.LZ_IMAGE_TYPE_LZ4_RGB32&&t.type<=o.LZ_IMAGE_TYPE_LZ4_XXXA){const n=new Uint8Array(t.data);var s=r.createImageData(t.width,t.height);const _=t.width*t.height*4,h=new Uint8Array(_);if(xr(n,h),t.type===o.LZ_IMAGE_TYPE_LZ4_RGBA||t.type===o.LZ_IMAGE_TYPE_LZ4_XXXA)s.data.set(h);else for(let c=0;c<_;c+=4)s.data[c]=h[c+2],s.data[c+1]=h[c+1],s.data[c+2]=h[c],s.data[c+3]=255;return t.top_down||Ut(s),s}if(t.type===o.LZ_IMAGE_TYPE_RGB32||t.type===o.LZ_IMAGE_TYPE_RGBA){var i=new Uint8Array(t.data),s=r.createImageData(t.width,t.height);return e=Oe(i,0,s.data,o.LZ_IMAGE_TYPE_RGB32,t.type!=o.LZ_IMAGE_TYPE_RGBA),t.top_down||Ut(s),t.type==o.LZ_IMAGE_TYPE_RGBA&&Oe(i,e,s.data,o.LZ_IMAGE_TYPE_RGBA,!1),s}else if(t.type===o.LZ_IMAGE_TYPE_XXXA){var i=new Uint8Array(t.data),s=r.createImageData(t.width,t.height);return Oe(i,0,s.data,o.LZ_IMAGE_TYPE_RGBA,!1),s}}function Fr(r,t){let e,s,i,n=0,_=0;const h=new Uint8Array(t.data);if(!(t.format!=o.SPICE_BITMAP_FMT_32BIT&&t.format!=o.SPICE_BITMAP_FMT_RGBA)){for(t.flags&o.SPICE_BITMAP_FLAGS_TOP_DOWN||(n=(t.y-1)*t.stride,_=2*t.stride),e=r.createImageData(t.x,t.y),s=0;s<t.y*t.stride;n-=_)for(i=0;i<t.x;i++,s+=4,n+=4)e.data[s+0]=h[n+2],e.data[s+1]=h[n+1],e.data[s+2]=h[n+0],t.format==o.SPICE_BITMAP_FMT_32BIT?e.data[s+3]=255:e.data[s+3]=h[n];return e}}function Rt(r,t,e,s){const i=document.createElement("canvas"),n=i.getContext("2d");n&&(i.setAttribute("width",t.width.toString()),i.setAttribute("height",t.height.toString()),n.putImageData(t,0,0),r.drawImage(i,e,s,t.width,t.height))}function zr(r){for(let t=0;t<r.width*r.height*4;t+=4)r.data[t+3]=255}class os extends q{process_channel_message(t){if(t.type==o.SPICE_MSG_DISPLAY_MODE)return this.known_unimplemented(t.type,"Display Mode"),!0;if(t.type==o.SPICE_MSG_DISPLAY_MARK)return this.known_unimplemented(t.type,"Display Mark"),!0;if(t.type==o.SPICE_MSG_DISPLAY_RESET)return this.surfaces[this.primary_surface].canvas.context.restore(),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_COPY){const e=new Ri(t.data);if(e.base.box.is_same_size(e.data.src_area)||this.log_warn("FIXME: DrawCopy src_area is a different size than base.box; we do not handle that yet."),e.base.clip.type!=o.SPICE_CLIP_TYPE_NONE&&this.log_warn("FIXME: DrawCopy we don't handle clipping yet"),e.data.rop_descriptor!=o.SPICE_ROPD_OP_PUT&&this.log_warn("FIXME: DrawCopy we don't handle ropd type: "+e.data.rop_descriptor),e.data.mask.flags&&this.log_warn("FIXME: DrawCopy we don't handle mask flag: "+e.data.mask.flags),e.data.mask.bitmap&&this.log_warn("FIXME: DrawCopy we don't handle mask"),e.data&&e.data.src_bitmap)if(e.data.src_bitmap.descriptor.flags&&e.data.src_bitmap.descriptor.flags!=o.SPICE_IMAGE_FLAGS_CACHE_ME&&e.data.src_bitmap.descriptor.flags!=o.SPICE_IMAGE_FLAGS_HIGH_BITS_SET&&(this.log_warn("FIXME: DrawCopy unhandled image flags: "+e.data.src_bitmap.descriptor.flags),this.log_draw("DrawCopy",e)),e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_QUIC){const s=this.surfaces[e.base.surface_id].canvas;if(!e.data.src_bitmap.quic)return this.log_warn("FIXME: DrawCopy could not handle this QUIC file."),!1;const i=js(s.context,e.data.src_bitmap.quic);return this.draw_copy_helper({base:e.base,src_area:e.data.src_area,image_data:i,tag:"copyquic."+e.data.src_bitmap.quic.type,has_alpha:e.data.src_bitmap.quic.type==R.QUIC_IMAGE_TYPE_RGBA,descriptor:e.data.src_bitmap.descriptor})}else{if(e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_FROM_CACHE||e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS)return!this.cache||!this.cache[e.data.src_bitmap.descriptor.id]?(this.log_warn("FIXME: DrawCopy did not find image id "+e.data.src_bitmap.descriptor.id+" in cache."),!1):this.draw_copy_helper({base:e.base,src_area:e.data.src_area,image_data:this.cache[e.data.src_bitmap.descriptor.id],tag:"copycache."+e.data.src_bitmap.descriptor.id,has_alpha:!0,descriptor:e.data.src_bitmap.descriptor});if(e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_SURFACE){const i=this.surfaces[e.data.src_bitmap.surface_id].canvas.context.getImageData(e.data.src_area.left,e.data.src_area.top,e.data.src_area.right-e.data.src_area.left,e.data.src_area.bottom-e.data.src_area.top),n=new W;return n.top=n.left=0,n.right=i.width,n.bottom=i.height,this.draw_copy_helper({base:e.base,src_area:n,image_data:i,tag:"copysurf."+e.data.src_bitmap.surface_id,has_alpha:this.surfaces[e.data.src_bitmap.surface_id].format!=o.SPICE_SURFACE_FMT_32_xRGB,descriptor:e.data.src_bitmap.descriptor})}else if(e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_JPEG){if(!e.data.src_bitmap.jpeg)return this.log_warn("FIXME: DrawCopy could not handle this JPEG file."),!1;let s="data:image/jpeg,";const i=new Image,n=new Uint8Array(e.data.src_bitmap.jpeg.data);for(let _=0;_<n.length;_++)s+="%",n[_]<16&&(s+="0"),s+=n[_].toString(16);return i.o={base:e.base,tag:"jpeg."+e.data.src_bitmap.surface_id,descriptor:e.data.src_bitmap.descriptor,sc:this},i.onload=Fe,i.src=s,!0}else if(e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_JPEG_ALPHA){if(!e.data.src_bitmap.jpeg_alpha)return this.log_warn("FIXME: DrawCopy could not handle this JPEG ALPHA file."),!1;let s="data:image/jpeg,";const i=new Image,n=new Uint8Array(e.data.src_bitmap.jpeg_alpha.data);for(let _=0;_<n.length;_++)s+="%",n[_]<16&&(s+="0"),s+=n[_].toString(16);if(i.o={base:e.base,tag:"jpeg."+e.data.src_bitmap.surface_id,descriptor:e.data.src_bitmap.descriptor,sc:this},this.surfaces[e.base.surface_id].format==o.SPICE_SURFACE_FMT_32_ARGB){const _=this.surfaces[e.base.surface_id].canvas;i.alpha_img=Nt(_.context,e.data.src_bitmap.jpeg_alpha.alpha)}return i.onload=Fe,i.src=s,!0}else if(e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_BITMAP){const s=this.surfaces[e.base.surface_id].canvas;if(!e.data.src_bitmap.bitmap)return this.log_err("null bitmap"),!1;const i=Fr(s.context,e.data.src_bitmap.bitmap);return i?this.draw_copy_helper({base:e.base,src_area:e.data.src_area,image_data:i,tag:"bitmap."+e.data.src_bitmap.bitmap.format,has_alpha:e.data.src_bitmap.bitmap!=o.SPICE_BITMAP_FMT_32BIT,descriptor:e.data.src_bitmap.descriptor}):(this.log_warn("FIXME: Unable to interpret bitmap of format: "+e.data.src_bitmap.bitmap.format),!1)}else if(e.data.src_bitmap.descriptor.type==o.SPICE_IMAGE_TYPE_LZ_RGB){const s=this.surfaces[e.base.surface_id].canvas;if(!e.data.src_bitmap.lz_rgb)return this.log_err("null lz_rgb "),!1;const i=Nt(s.context,e.data.src_bitmap.lz_rgb);return i?this.draw_copy_helper({base:e.base,src_area:e.data.src_area,image_data:i,tag:"lz_rgb."+e.data.src_bitmap.lz_rgb.type,has_alpha:e.data.src_bitmap.lz_rgb.type==o.LZ_IMAGE_TYPE_RGBA,descriptor:e.data.src_bitmap.descriptor}):(this.log_warn("FIXME: Unable to interpret bitmap of type: "+e.data.src_bitmap.lz_rgb.type),!1)}else return this.log_warn("FIXME: DrawCopy unhandled image type: "+e.data.src_bitmap.descriptor.type),this.log_draw("DrawCopy",e),!1}return this.log_warn("FIXME: DrawCopy no src_bitmap."),!1}if(t.type==o.SPICE_MSG_DISPLAY_DRAW_FILL){const e=new Gi(t.data);if(e.data.rop_descriptor!=o.SPICE_ROPD_OP_PUT&&this.log_warn("FIXME: DrawFill we don't handle ropd type: "+e.data.rop_descriptor),e.data.mask.flags&&this.log_warn("FIXME: DrawFill we don't handle mask flag: "+e.data.mask.flags),e.data.mask.bitmap&&this.log_warn("FIXME: DrawFill we don't handle mask"),e.data.brush.type==o.SPICE_BRUSH_TYPE_SOLID){const s=e.data.brush.color&16777215,i="rgb("+(s>>16)+", "+(s>>8&255)+", "+(s&255)+")";this.surfaces[e.base.surface_id].canvas.context.fillStyle=i,this.surfaces[e.base.surface_id].canvas.context.fillRect(e.base.box.left,e.base.box.top,e.base.box.right-e.base.box.left,e.base.box.bottom-e.base.box.top),this.surfaces[e.base.surface_id].draw_count++}else this.log_warn("FIXME: DrawFill can't handle brush type: "+e.data.brush.type);return!0}if(t.type==o.SPICE_MSG_DISPLAY_DRAW_OPAQUE)return this.known_unimplemented(t.type,"Display Draw Opaque"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_BLEND)return this.known_unimplemented(t.type,"Display Draw Blend"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_BLACKNESS)return this.known_unimplemented(t.type,"Display Draw Blackness"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_WHITENESS)return this.known_unimplemented(t.type,"Display Draw Whiteness"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_INVERS)return this.known_unimplemented(t.type,"Display Draw Invers"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_ROP3)return this.known_unimplemented(t.type,"Display Draw ROP3"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_STROKE)return this.known_unimplemented(t.type,"Display Draw Stroke"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT)return this.known_unimplemented(t.type,"Display Draw Transparent"),!0;if(t.type==o.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND)return this.known_unimplemented(t.type,"Display Draw Alpha Blend"),!0;if(t.type==o.SPICE_MSG_DISPLAY_COPY_BITS){const e=new Oi(t.data),s=this.surfaces[e.base.surface_id].canvas,i=s.context;let n=s.width-e.src_pos.x,_=s.height-e.src_pos.y;n>e.base.box.right-e.base.box.left&&(n=e.base.box.right-e.base.box.left),_>e.base.box.bottom-e.base.box.top&&(_=e.base.box.bottom-e.base.box.top);const h=i.getImageData(e.src_pos.x,e.src_pos.y,n,_);return Rt(i,h,e.base.box.left,e.base.box.top),this.surfaces[e.base.surface_id].draw_count++,!0}if(t.type==o.SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS)return this.known_unimplemented(t.type,"Display Inval All Pixmaps"),!0;if(t.type==o.SPICE_MSG_DISPLAY_INVAL_PALETTE)return this.known_unimplemented(t.type,"Display Inval Palette"),!0;if(t.type==o.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES)return this.known_unimplemented(t.type,"Inval All Palettes"),!0;if(t.type==o.SPICE_MSG_DISPLAY_SURFACE_CREATE){this.surfaces||(this.surfaces=[]);const e=new Yi(t.data);if(e.surface.format!=o.SPICE_SURFACE_FMT_32_xRGB&&e.surface.format!=o.SPICE_SURFACE_FMT_32_ARGB)return this.log_warn("FIXME: cannot handle surface format "+e.surface.format+" yet."),!1;const s=document.createElement("canvas");return s.setAttribute("width",e.surface.width.toString()),s.setAttribute("height",e.surface.height.toString()),s.setAttribute("id","spice_surface_"+e.surface.surface_id),s.setAttribute("tabindex",e.surface.surface_id.toString()),s.context=s.getContext("2d"),e.surface.canvas=s,e.surface.draw_count=0,this.surfaces[e.surface.surface_id]=e.surface,e.surface.flags&o.SPICE_SURFACE_FLAGS_PRIMARY&&(this.primary_surface=e.surface.surface_id,s.context.save(),document.getElementById(this.parent.screen_id).appendChild(s),document.getElementById(this.parent.screen_id).style.height=e.surface.height+"px",this.hook_events()),!0}if(t.type==o.SPICE_MSG_DISPLAY_SURFACE_DESTROY){const e=new vi(t.data);return this.delete_surface(e.surface_id),!0}if(t.type==o.SPICE_MSG_DISPLAY_STREAM_CREATE){const e=new qi(t.data);if(this.streams||(this.streams=[]),this.streams[e.id]?console.log("Stream "+e.id+" already exists"):this.streams[e.id]=e,e.codec_type==o.SPICE_VIDEO_CODEC_TYPE_VP8){const s=new MediaSource,i=document.createElement("video");i.src=window.URL.createObjectURL(s),i.setAttribute("muted","true"),i.setAttribute("autoplay","true"),i.setAttribute("width",e.stream_width.toString()),i.setAttribute("height",e.stream_height.toString());let n=e.dest.left,_=e.dest.top;this.surfaces[e.surface_id]!==void 0&&(n+=this.surfaces[e.surface_id].canvas.offsetLeft,_+=this.surfaces[e.surface_id].canvas.offsetTop),document.getElementById(this.parent.screen_id).appendChild(i),i.setAttribute("style","pointer-events:none; position: absolute; top:"+_+"px; left:"+n+"px;"),s.addEventListener("sourceopen",Hr,!1),s.addEventListener("sourceended",qr,!1),s.addEventListener("sourceclosed",Xr,!1);const h=this.streams[e.id];h.video=i,h.media=s,h.queue=[],h.start_time=0,h.cluster_time=0,h.append_okay=!1,s.stream=h,s.spiceconn=this,i.spice_stream=h}else e.codec_type==o.SPICE_VIDEO_CODEC_TYPE_MJPEG?this.streams[e.id].frames_loading=0:console.log("Unhandled stream codec: "+e.codec_type);return!0}if(t.type==o.SPICE_MSG_DISPLAY_STREAM_DATA||t.type==o.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED){let e;if(t.type==o.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED?e=new Wi(t.data):e=new Xi(t.data),!this.streams[e.base.id])return console.log("no stream for data"),!1;const s=e.base.multi_media_time-this.parent.relative_now();return this.streams[e.base.id].codec_type===o.SPICE_VIDEO_CODEC_TYPE_MJPEG&&Vr(this,e,s),this.streams[e.base.id].codec_type===o.SPICE_VIDEO_CODEC_TYPE_VP8&&jr(this.streams[e.base.id],e),!0}if(t.type==o.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT){const e=new Qi(t.data),s=new Ji(e.stream_id,e.unique_id);return this.streams[e.stream_id]&&(this.streams[e.stream_id].report=s,this.streams[e.stream_id].max_window_size=e.max_window_size,this.streams[e.stream_id].timeout_ms=e.timeout_ms),!0}if(t.type==o.SPICE_MSG_DISPLAY_STREAM_CLIP){const e=new Zi(t.data);return this.streams[e.id].clip=e.clip,!0}if(t.type==o.SPICE_MSG_DISPLAY_STREAM_DESTROY){const e=new ji(t.data);return this.streams[e.id].codec_type==o.SPICE_VIDEO_CODEC_TYPE_VP8&&(document.getElementById(this.parent.screen_id).removeChild(this.streams[e.id].video),this.streams[e.id].source_buffer=null,this.streams[e.id].media=null,this.streams[e.id].video=null),this.streams[e.id]=void 0,!0}if(t.type==o.SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL)return this.known_unimplemented(t.type,"Display Stream Destroy All"),!0;if(t.type==o.SPICE_MSG_DISPLAY_INVAL_LIST){const e=new $i(t.data);for(let s=0;s<e.count;s++)this.cache[e.resources[s].id]!=null&&delete this.cache[e.resources[s].id];return!0}return t.type==o.SPICE_MSG_DISPLAY_MONITORS_CONFIG?(this.known_unimplemented(t.type,"Display Monitors Config"),!0):t.type==o.SPICE_MSG_DISPLAY_DRAW_COMPOSITE?(this.known_unimplemented(t.type,"Display Draw Composite"),!0):!1}delete_surface(t){const e=document.getElementById("spice_surface_"+t);this.primary_surface==t&&(this.unhook_events(),this.primary_surface=void 0,document.getElementById(this.parent.screen_id).removeChild(e)),delete this.surfaces[t]}draw_copy_helper(t){const e=this.surfaces[t.base.surface_id].canvas;return t.has_alpha?this.surfaces[t.base.surface_id].format==o.SPICE_SURFACE_FMT_32_xRGB?(zr(t.image_data),e.context.putImageData(t.image_data,t.base.box.left,t.base.box.top)):Rt(e.context,t.image_data,t.base.box.left,t.base.box.top):e.context.putImageData(t.image_data,t.base.box.left,t.base.box.top),(t.src_area.left>0||t.src_area.top>0)&&this.log_warn("FIXME: DrawCopy not shifting draw copies just yet..."),t.descriptor&&t.descriptor.flags&o.SPICE_IMAGE_FLAGS_CACHE_ME&&(this.cache||(this.cache={}),this.cache[t.descriptor.id]=t.image_data),this.surfaces[t.base.surface_id].draw_count++,!0}log_draw(t,e){let s=t+"."+e.base.surface_id+"."+this.surfaces[e.base.surface_id].draw_count+": ";s+="base.box "+e.base.box.left+", "+e.base.box.top+" to "+e.base.box.right+", "+e.base.box.bottom,s+="; clip.type "+e.base.clip.type,e.data&&(e.data.src_area&&(s+="; src_area "+e.data.src_area.left+", "+e.data.src_area.top+" to "+e.data.src_area.right+", "+e.data.src_area.bottom),e.data.src_bitmap&&e.data.src_bitmap!=null?(s+="; src_bitmap id: "+e.data.src_bitmap.descriptor.id,s+="; src_bitmap width "+e.data.src_bitmap.descriptor.width+", height "+e.data.src_bitmap.descriptor.height,s+="; src_bitmap type "+e.data.src_bitmap.descriptor.type+", flags "+e.data.src_bitmap.descriptor.flags,e.data.src_bitmap.surface_id!==void 0&&(s+="; src_bitmap surface_id "+e.data.src_bitmap.surface_id),e.data.src_bitmap.bitmap&&(s+="; BITMAP format "+e.data.src_bitmap.bitmap.format+"; flags "+e.data.src_bitmap.bitmap.flags+"; x "+e.data.src_bitmap.bitmap.x+"; y "+e.data.src_bitmap.bitmap.y+"; stride "+e.data.src_bitmap.bitmap.stride),e.data.src_bitmap.quic&&(s+="; QUIC type "+e.data.src_bitmap.quic.type+"; width "+e.data.src_bitmap.quic.width+"; height "+e.data.src_bitmap.quic.height),e.data.src_bitmap.lz_rgb&&(s+="; LZ_RGB length "+e.data.src_bitmap.lz_rgb.length+"; magic "+e.data.src_bitmap.lz_rgb.magic+"; version 0x"+e.data.src_bitmap.lz_rgb.version.toString(16)+"; type "+e.data.src_bitmap.lz_rgb.type+"; width "+e.data.src_bitmap.lz_rgb.width+"; height "+e.data.src_bitmap.lz_rgb.height+"; stride "+e.data.src_bitmap.lz_rgb.stride+"; top down "+e.data.src_bitmap.lz_rgb.top_down)):s+="; src_bitmap is null",e.data.brush&&(e.data.brush.type==o.SPICE_BRUSH_TYPE_SOLID&&(s+="; brush.color 0x"+e.data.brush.color.toString(16)),e.data.brush.type==o.SPICE_BRUSH_TYPE_PATTERN&&(s+="; brush.pat ",e.data.brush.pattern.pat!=null?s+="[SpiceImage]":s+="[null]",s+=" at "+e.data.brush.pattern.pos.x+", "+e.data.brush.pattern.pos.y)),s+="; rop_descriptor "+e.data.rop_descriptor,e.data.scale_mode!==void 0&&(s+="; scale_mode "+e.data.scale_mode),s+="; mask.flags "+e.data.mask.flags,s+="; mask.pos "+e.data.mask.pos.x+", "+e.data.mask.pos.y,e.data.mask.bitmap!=null?(s+="; mask.bitmap width "+e.data.mask.bitmap.descriptor.width+", height "+e.data.mask.bitmap.descriptor.height,s+="; mask.bitmap type "+e.data.mask.bitmap.descriptor.type+", flags "+e.data.mask.bitmap.descriptor.flags):s+="; mask.bitmap is null"),console.log(s)}hook_events(){if(this.primary_surface!==void 0){const t=this.surfaces[this.primary_surface].canvas;t.sc=this.parent,t.addEventListener("mousemove",Pt),t.addEventListener("mousedown",wt),t.addEventListener("contextmenu",Mt),t.addEventListener("mouseup",Tt),t.addEventListener("keydown",Dt),t.addEventListener("keyup",Lt),t.addEventListener("mouseout",Ot),t.addEventListener("mouseover",Gt),t.addEventListener("wheel",yt),t.focus(),this.focusListener=()=>this.parent.send_clipboard_grab(),this.focusListener(),t.addEventListener("focus",this.focusListener)}}unhook_events(){if(this.primary_surface!==void 0){const t=this.surfaces[this.primary_surface].canvas;t.removeEventListener("mousemove",Pt),t.removeEventListener("mousedown",wt),t.removeEventListener("contextmenu",Mt),t.removeEventListener("mouseup",Tt),t.removeEventListener("keydown",Dt),t.removeEventListener("keyup",Lt),t.removeEventListener("mouseout",Ot),t.removeEventListener("mouseover",Gt),t.removeEventListener("wheel",yt),t.removeEventListener("focus",this.focusListener)}}destroy_surfaces(){for(const t in this.surfaces)this.delete_surface(this.surfaces[t].surface_id);this.surfaces=void 0}}function Gt(r){this.focus()}function Ot(r){this.sc&&this.sc.cursor&&this.sc.cursor.spice_simulated_cursor&&(this.sc.cursor.spice_simulated_cursor.style.display="none"),this.blur()}function Fe(){let r=null,t;if("streams"in this.o.sc&&this.o.sc.streams[this.o.id]&&this.o.sc.streams[this.o.id].frames_loading--,this.o.sc.surfaces[this.o.base.surface_id]===void 0?(r=document.createElement("canvas"),r.setAttribute("width",this.o.base.box.right.toString()),r.setAttribute("height",this.o.base.box.bottom.toString()),t=r.getContext("2d")):t=this.o.sc.surfaces[this.o.base.surface_id].canvas.context,this.alpha_img){const e=document.createElement("canvas"),s=e.getContext("2d");e.setAttribute("width",this.alpha_img.width.toString()),e.setAttribute("height",this.alpha_img.height.toString()),s.putImageData(this.alpha_img,0,0),s.globalCompositeOperation="source-in",s.drawImage(this,0,0),t.drawImage(e,this.o.base.box.left,this.o.base.box.top),this.o.descriptor&&this.o.descriptor.flags&o.SPICE_IMAGE_FLAGS_CACHE_ME&&(this.o.sc.cache||(this.o.sc.cache={}),this.o.sc.cache[this.o.descriptor.id]=s.getImageData(0,0,this.alpha_img.width,this.alpha_img.height))}else t.drawImage(this,this.o.base.box.left,this.o.base.box.top),this.onload=void 0,this.src=oi,this.o.descriptor&&this.o.descriptor.flags&o.SPICE_IMAGE_FLAGS_CACHE_ME&&(this.o.sc.cache||(this.o.sc.cache={}),this.o.sc.cache[this.o.descriptor.id]=t.getImageData(this.o.base.box.left,this.o.base.box.top,this.o.base.box.right-this.o.base.box.left,this.o.base.box.bottom-this.o.base.box.top));r==null&&this.o.sc.surfaces[this.o.base.surface_id].draw_count++,this.o.sc.streams[this.o.id]&&"report"in this.o.sc.streams[this.o.id]&&hs(this.o.sc,this.o.id,this.o.msg_mmtime,this.o.msg_mmtime-this.o.sc.parent.relative_now())}function Vr(r,t,e){if(e<0&&r.streams[t.base.id].frames_loading>0){"report"in r.streams[t.base.id]&&r.streams[t.base.id].report.num_drops++;return}let s="data:image/jpeg,";const i=new Image,n=new Uint8Array(t.data);for(let h=0;h<n.length;h++)s+="%",n[h]<16&&(s+="0"),s+=n[h].toString(16);const _=new De;_.surface_id=r.streams[t.base.id].surface_id,_.box=t.dest||r.streams[t.base.id].dest,_.clip=r.streams[t.base.id].clip,i.o={base:_,tag:"mjpeg."+t.base.id,descriptor:null,sc:r,id:t.base.id,msg_mmtime:t.base.multi_media_time},i.onload=Fe,i.src=s,r.streams[t.base.id].frames_loading++}function hs(r,t,e,s){if(r.streams[t].report.num_frames++,r.streams[t].report.start_frame_mm_time==0&&(r.streams[t].report.start_frame_mm_time=e),r.streams[t].report.num_frames>r.streams[t].max_window_size||e-r.streams[t].report.start_frame_mm_time>r.streams[t].timeout_ms){r.streams[t].report.end_frame_mm_time=e,r.streams[t].report.last_frame_delay=s;const i=new y;i.build_msg(o.SPICE_MSGC_DISPLAY_STREAM_REPORT,r.streams[t].report),r.send_msg(i),r.streams[t].report.start_frame_mm_time=0,r.streams[t].report.num_frames=0,r.streams[t].report.num_drops=0}}function Hr(r){const t=r.target,e=t.stream,s=t.spiceconn;if(e.source_buffer)return;let i;try{i=t.addSourceBuffer(U.SPICE_VP8_CODEC)}catch{s.log_err("Codec "+U.SPICE_VP8_CODEC+" not available.");return}e.source_buffer=i,i.spiceconn=s,i.stream=e,$r(e);const n=new is,_=new Or(e.stream_width,e.stream_height),h=new es(_),c=new ArrayBuffer(n.buffer_size()+h.buffer_size()),a=n.to_buffer(c);h.to_buffer(c,a),i.addEventListener("error",Zr,!1),i.addEventListener("updateend",Wr,!1),We(i,c)}function qr(r){r.target.spiceconn.log_err("Video source unexpectedly ended.")}function Xr(r){r.target.spiceconn.log_err("Video source unexpectedly closed.")}function We(r,t){try{r.stream.append_okay=!1,r.appendBuffer(t)}catch(e){r.spiceconn.log_err("Error invoking appendBuffer: "+e.message)}}function Wr(r){const e=r.target.stream;if(e.current_frame&&"report"in e){const s=e.media.spiceconn,i=e.current_frame.msg_mmtime;hs(s,e.id,i,i-s.parent.relative_now())}e.queue.length>0?(e.current_frame=e.queue.shift(),We(e.source_buffer,e.current_frame.mb)):e.append_okay=!0,e.video&&(e.video.buffered.length>0&&e.video.currentTime<e.video.buffered.start(e.video.buffered.length-1)&&(console.log("Video appears to have fallen behind; advancing to "+e.video.buffered.start(e.video.buffered.length-1)),e.video.currentTime=e.video.buffered.start(e.video.buffered.length-1)),e.video.paused&&e.video.readyState>=2&&e.video.play())}function Zr(r){r.target.spiceconn.log_err("source_buffer error "+r.message)}function cs(r,t,e){const s={msg_mmtime:t.base.multi_media_time};r.append_okay?(r.current_frame=s,We(r.source_buffer,e)):(s.mb=e,r.queue.push(s))}function as(r,t,e){const s=new ss(t.base.multi_media_time-r.cluster_time,t.data,e),i=new ArrayBuffer(s.buffer_size());s.to_buffer(i),cs(r,t,i)}function Yt(r,t){r.cluster_time=t.base.multi_media_time;const e=new ts(r.cluster_time-r.start_time,t.data),s=new ArrayBuffer(e.buffer_size());e.to_buffer(s),cs(r,t,s),as(r,t,!0)}function jr(r,t){r.start_time==0?(r.start_time=t.base.multi_media_time,Yt(r,t)):t.base.multi_media_time-r.cluster_time>=U.MAX_CLUSTER_TIME?Yt(r,t):as(r,t,!1)}function Qr(r){const t=r.target.spice_stream;t.video&&t.video.buffered.length>1&&console.log(t.video.currentTime+":id "+t.id+" event "+r.type+Ke(t.video)),t.queue.length>1&&console.log(" queue len "+t.queue.length+"; append_okay: "+t.append_okay)}function Jr(r){this.addEventListener(r,Qr)}function $r(r){["abort","error"].forEach(Jr,r.video)}class ls extends q{constructor(...t){super(...t),this.queue=[],this.append_okay=!1,this.start_time=0,this.bytes_written=0,this.cluster_time=0,this.last_data_time=0}process_channel_message(t){if(!window.MediaSource)return this.log_err("MediaSource API is not available"),!1;if(t.type==o.SPICE_MSG_PLAYBACK_START){const s=new zi(t.data);if(s.frequency!=U.OPUS_FREQUENCY)return this.log_err("This player cannot handle frequency "+s.frequency),!1;if(s.channels!=U.OPUS_CHANNELS)return this.log_err("This player cannot handle "+s.channels+" channels"),!1;if(s.format!=o.SPICE_AUDIO_FMT_S16)return this.log_err("This player cannot format "+s.format),!1;if(!this.source_buffer){this.media_source=new MediaSource,this.media_source.spiceconn=this,this.audio=document.createElement("audio"),this.audio.spiceconn=this,this.audio.setAttribute("autoplay","true"),this.audio.src=window.URL.createObjectURL(this.media_source);var e=document.getElementById(this.parent.screen_id);return e&&e.appendChild(this.audio),this.media_source.addEventListener("sourceopen",en,!1),this.media_source.addEventListener("sourceended",tn,!1),this.media_source.addEventListener("sourceclosed",sn,!1),this.bytes_written=0,!0}}if(t.type==o.SPICE_MSG_PLAYBACK_DATA){const s=new xi(t.data);return this.source_buffer&&(this.audio&&this.audio.readyState>=3&&this.audio.buffered.length>1&&this.audio.currentTime==this.audio.buffered.end(0)&&this.audio.currentTime<this.audio.buffered.start(this.audio.buffered.length-1)&&(console.log("Audio underrun: we appear to have fallen behind; advancing to "+this.audio.buffered.start(this.audio.buffered.length-1)),this.audio.currentTime=this.audio.buffered.start(this.audio.buffered.length-1)),this.start_time!=0&&s.time!=this.last_data_time+U.EXPECTED_PACKET_DURATION&&Math.abs(s.time-(U.EXPECTED_PACKET_DURATION+this.last_data_time))<U.MAX_CLUSTER_TIME&&(s.time=this.last_data_time+U.EXPECTED_PACKET_DURATION),this.last_data_time=s.time,this.start_time==0?this.start_playback(s):s.time-this.cluster_time>=U.MAX_CLUSTER_TIME?this.new_cluster(s):this.simple_block(s,!1)),!0}if(t.type==o.SPICE_MSG_PLAYBACK_MODE){const s=new Fi(t.data);return s.mode!=o.SPICE_AUDIO_DATA_MODE_OPUS&&(this.log_err("This player cannot handle mode "+s.mode),delete this.source_buffer),!0}if(t.type==o.SPICE_MSG_PLAYBACK_STOP&&this.source_buffer){var e=document.getElementById(this.parent.screen_id);return e&&this.audio&&(e.removeChild(this.audio),window.URL.revokeObjectURL(this.audio.src)),delete this.source_buffer,delete this.media_source,delete this.audio,this.append_okay=!1,this.queue=[],this.start_time=0,!0}return t.type==o.SPICE_MSG_PLAYBACK_VOLUME?(this.known_unimplemented(t.type,"Playback Volume"),!0):t.type==o.SPICE_MSG_PLAYBACK_MUTE?(this.known_unimplemented(t.type,"Playback Mute"),!0):t.type==o.SPICE_MSG_PLAYBACK_LATENCY?(this.known_unimplemented(t.type,"Playback Latency"),!0):!1}start_playback(t){this.start_time=t.time;const e=new is,s=new Gr,i=new es(s),n=new ArrayBuffer(e.buffer_size()+i.buffer_size());this.bytes_written=e.to_buffer(n),this.bytes_written=i.to_buffer(n,this.bytes_written),this.source_buffer&&(this.source_buffer.addEventListener("error",_n,!1),this.source_buffer.addEventListener("updateend",nn,!1),ae(this,n)),this.new_cluster(t)}new_cluster(t){this.cluster_time=t.time;const e=new ts(t.time-this.start_time),s=new ArrayBuffer(e.buffer_size());this.bytes_written+=e.to_buffer(s),this.append_okay?ae(this,s):this.queue.push(s),this.simple_block(t,!0)}simple_block(t,e){const s=new ss(t.time-this.cluster_time,t.data,e),i=new ArrayBuffer(s.buffer_size());this.bytes_written+=s.to_buffer(i),this.append_okay?ae(this,i):this.queue.push(i)}}function en(r){const t=this.spiceconn;if(!t.source_buffer){try{t.source_buffer=this.addSourceBuffer(U.SPICE_PLAYBACK_CODEC)}catch{t.log_err("Codec "+U.SPICE_PLAYBACK_CODEC+" not available.");return}cn(t),t.source_buffer&&(t.source_buffer.spiceconn=t,t.source_buffer.mode="segments")}}function tn(r){this.spiceconn.log_err("Audio source unexpectedly ended.")}function sn(r){this.spiceconn.log_err("Audio source unexpectedly closed.")}function rn(r){if(r.length==1)return r.shift();let t=0,e=0;for(e=0;e<r.length;e++)t+=r[e].byteLength;const s=new ArrayBuffer(t),i=new Uint8Array(s);for(t=0,e=0;e<r.length;e++)i.set(new Uint8Array(r[e]),t),t+=r[e].byteLength;return r.length=0,s}function nn(r){const t=this.spiceconn;if(t.queue.length>0){const e=rn(t.queue);ae(t,e)}else t.append_okay=!0}function _n(r){this.spiceconn.log_err("source_buffer error")}function ae(r,t){try{r.source_buffer&&(r.source_buffer.appendBuffer(t),r.append_okay=!1)}catch(e){r.log_err("Error invoking appendBuffer: "+e.message)}}function on(r){const t=this.spiceconn;t.audio&&t.audio.buffered.length>1&&console.log(t.audio.currentTime+": event "+r.type+(Ke?Ke(t.audio):"")),t.queue.length>1&&console.log(" queue len "+t.queue.length+"; append_okay: "+t.append_okay)}function hn(r){this.addEventListener(r,on)}function cn(r){const t=["abort","error"];r.audio&&t.forEach(hn,r.audio)}class us extends q{constructor(...t){super(...t),this.port_name=null,this.portName="",this.portOpened=!1}process_channel_message(t){if(t.type==o.SPICE_MSG_PORT_INIT){if(this.port_name===null){const s=new er(t.data);return this.portName=hi(new Uint8Array(s.name)),this.portOpened=s.opened,!0}}else if(t.type==o.SPICE_MSG_PORT_EVENT){var e=new CustomEvent("spice-port-event",{detail:{channel:this,spiceEvent:new Uint8Array(t.data)},bubbles:!0,cancelable:!0});return window.dispatchEvent(e),!0}else if(t.type==o.SPICE_MSG_SPICEVMC_DATA){var e=new CustomEvent("spice-port-data",{detail:{channel:this,data:t.data},bubbles:!0,cancelable:!0});return window.dispatchEvent(e),!0}return!1}}function ds(r){let t=document.getElementById(r.screen_id).clientWidth;const e=document.getElementById(r.message_id);let s=window.innerHeight-20;if(e!=null)if(window.getComputedStyle(e).getPropertyValue("display")=="none"){const i=parseInt(window.getComputedStyle(e).getPropertyValue("height"),10);s=s-i}else s=s-e.offsetHeight-e.clientHeight;s%8>0&&(s-=s%8),t%8>0&&(t-=t%8),r.resize_window(0,t,s,32,0,0),r.spice_resize_timer=void 0}function an(r){const t=window.spice_connection;t&&t.spice_resize_timer&&(window.clearTimeout(t.spice_resize_timer),t.spice_resize_timer=void 0),t.spice_resize_timer=window.setTimeout(ds,200,t)}class ln extends q{constructor(t){if(typeof WebSocket>"u")throw new Error("WebSocket unavailable. You need to use a different browser.");super(t),this.agent_msg_queue=[],this.file_xfer_tasks={},this.file_xfer_task_id=0,this.file_xfer_read_queue=[],this.ports=[],this.agent_caps=[0]}process_channel_message(t){if(t.type==o.SPICE_MSG_MAIN_MIGRATE_BEGIN)return this.known_unimplemented(t.type,"Main Migrate Begin"),!0;if(t.type==o.SPICE_MSG_MAIN_MIGRATE_CANCEL)return this.known_unimplemented(t.type,"Main Migrate Cancel"),!0;if(t.type==o.SPICE_MSG_MAIN_INIT){this.log_info("Connected to "+this.ws.url),this.report_success("Connected"),this.main_init=new Ai(t.data),this.connection_id=this.main_init.session_id,this.agent_tokens=this.main_init.agent_tokens,this.our_mm_time=Date.now(),this.mm_time=this.main_init.multi_media_time,this.handle_mouse_mode(this.main_init.current_mouse_mode,this.main_init.supported_mouse_modes),this.main_init.agent_connected&&this.connect_agent();const e=new y;return e.type=o.SPICE_MSGC_MAIN_ATTACH_CHANNELS,e.size=e.buffer_size(),this.send_msg(e),!0}if(t.type==o.SPICE_MSG_MAIN_MOUSE_MODE){const e=new Ci(t.data);return this.handle_mouse_mode(e.current_mode,e.supported_modes),!0}if(t.type==o.SPICE_MSG_MAIN_MULTI_MEDIA_TIME)return this.known_unimplemented(t.type,"Main Multi Media Time"),!0;if(t.type==o.SPICE_MSG_MAIN_CHANNELS_LIST){let e,s;for(s=new Ei(t.data),e=0;e<s.channels.length;e++){const i={uri:this.ws.url,parent:this,connection_id:this.connection_id,type:s.channels[e].type,chan_id:s.channels[e].id};s.channels[e].type==o.SPICE_CHANNEL_DISPLAY?s.channels[e].id==0?this.display=new os(i):this.log_warn("The spice-html5 client does not handle multiple heads."):s.channels[e].type==o.SPICE_CHANNEL_INPUTS?(this.inputs=new ns(i),this.inputs&&(this.inputs.mouse_mode=this.mouse_mode)):s.channels[e].type==o.SPICE_CHANNEL_CURSOR?this.cursor=new rs(i):s.channels[e].type==o.SPICE_CHANNEL_PLAYBACK?this.cursor=new ls(i):s.channels[e].type==o.SPICE_CHANNEL_PORT?this.ports.push(new us(i)):("extra_channels"in this||(this.extra_channels=[]),this.extra_channels[e]=new q(i),this.log_err("Channel type "+this.extra_channels[e].channel_type()+" not implemented"))}return!0}if(t.type==o.SPICE_MSG_MAIN_AGENT_CONNECTED)return this.connect_agent(),!0;if(t.type==o.SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS){const e=new ot(t.data);return this.agent_tokens=e.num_tokens,this.connect_agent(),!0}if(t.type==o.SPICE_MSG_MAIN_AGENT_TOKEN){let e;const s=new ot(t.data);for(this.agent_tokens+=s.num_tokens,this.send_agent_message_queue(),e=this.agent_tokens;e>0&&this.file_xfer_read_queue.length>0;){const i=this.file_xfer_read_queue.shift();i&&(this.file_xfer_read(i,i.read_bytes),e--)}return!0}if(t.type==o.SPICE_MSG_MAIN_AGENT_DISCONNECTED)return this.agent_connected=!1,!0;if(t.type==o.SPICE_MSG_MAIN_AGENT_DATA){const e=new gi(t.data);if(e.type==o.VD_AGENT_ANNOUNCE_CAPABILITIES){const s=new ht(e.data);return this.agent_caps=[s.caps],s.request&&this.announce_agent_capabilities(0),!0}else{if(e.type==o.VD_AGENT_FILE_XFER_STATUS)return this.handle_file_xfer_status(new ct(e.data)),!0;if(e.type==o.VD_AGENT_CLIPBOARD_GRAB)return this.handle_clipboard_grab(),!0;if(e.type==o.VD_AGENT_CLIPBOARD)return this.handle_clipboard_receive(e),!0;if(e.type==o.VD_AGENT_CLIPBOARD_REQUEST)return this.handle_clipboard_send(),!0;if(e.type==o.VD_AGENT_CLIPBOARD_RELEASE)return!0}return!1}return t.type==o.SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST?(this.known_unimplemented(t.type,"Main Migrate Switch Host"),!0):t.type==o.SPICE_MSG_MAIN_MIGRATE_END?(this.known_unimplemented(t.type,"Main Migrate End"),!0):t.type==o.SPICE_MSG_MAIN_NAME?(this.known_unimplemented(t.type,"Main Name"),!0):t.type==o.SPICE_MSG_MAIN_UUID?(this.known_unimplemented(t.type,"Main UUID"),!0):t.type==o.SPICE_MSG_MAIN_MIGRATE_BEGIN_SEAMLESS?(this.known_unimplemented(t.type,"Main Migrate Begin Seamless"),!0):t.type==o.SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK?(this.known_unimplemented(t.type,"Main Migrate Dst Seamless ACK"),!0):t.type==o.SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK?(this.known_unimplemented(t.type,"Main Migrate Dst Seamless NACK"),!0):!1}stop(t){if(this.state="closing",this.inputs&&(this.inputs.cleanup(),this.inputs=void 0),this.cursor&&(this.cursor.cleanup(),this.cursor=void 0),this.display&&(this.display.cleanup(),this.display.destroy_surfaces(),this.display=void 0),this.cleanup(),"extra_channels"in this)for(const e in this.extra_channels)this.extra_channels[e].cleanup();this.extra_channels=void 0}send_agent_message_queue(t){if(this.agent_connected)for(t&&this.agent_msg_queue.push(t);this.agent_tokens>0&&this.agent_msg_queue.length>0;){const e=this.agent_msg_queue.shift();this.send_msg(e),this.agent_tokens--}}send_agent_message(t,e){const s=new Ti(t,e);let i=0;const n=o.VD_AGENT_MAX_DATA_SIZE-y.prototype.buffer_size(),_=new ArrayBuffer(s.buffer_size());for(s.to_buffer(_);i<s.buffer_size();){const h=Math.min(i+n,s.buffer_size()),c=new y;c.type=o.SPICE_MSGC_MAIN_AGENT_DATA,c.size=h-i,c.data=_.slice(i,h),this.send_agent_message_queue(c),i=h}}announce_agent_capabilities(t){const e=new ht(t,1<<o.VD_AGENT_CAP_MOUSE_STATE|1<<o.VD_AGENT_CAP_MONITORS_CONFIG|1<<o.VD_AGENT_CAP_REPLY|1<<o.VD_AGENT_CAP_CLIPBOARD_SELECTION|1<<o.VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);this.send_agent_message(o.VD_AGENT_ANNOUNCE_CAPABILITIES,e)}resize_window(t,e,s,i,n,_){const h=new yi(t,e,s,i,n,_);this.send_agent_message(o.VD_AGENT_MONITORS_CONFIG,h)}file_xfer_start(t){let e,s,i;e=this.file_xfer_task_id++,i=new vr(e,t),i.create_progressbar(),this.file_xfer_tasks[e]=i,s=new Di(e,t.name,t.size),this.send_agent_message(o.VD_AGENT_FILE_XFER_START,s)}handle_file_xfer_status(t){let e,s;if(this.file_xfer_tasks[t.id]){switch(s=this.file_xfer_tasks[t.id],t.result){case o.VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:this.file_xfer_read(s);return;case o.VD_AGENT_FILE_XFER_STATUS_CANCELLED:e="transfer is cancelled by spice agent";break;case o.VD_AGENT_FILE_XFER_STATUS_ERROR:e="some errors occurred in the spice agent";break;case o.VD_AGENT_FILE_XFER_STATUS_SUCCESS:break;default:e="unhandled status type: "+t.result;break}this.file_xfer_completed(s,e)}}file_xfer_read(t,e){const s=32*o.VD_AGENT_MAX_DATA_SIZE,i=this;let n,_,h,c;if(!(!t||!this.file_xfer_tasks[t.id]||e!==void 0&&e>0&&e==t.file.size)){if(t.cancelled){const a=new ct(t.id,o.VD_AGENT_FILE_XFER_STATUS_CANCELLED);this.send_agent_message(o.VD_AGENT_FILE_XFER_STATUS,a),delete this.file_xfer_tasks[t.id];return}if(n=e||0,_=Math.min(n+s,t.file.size),!this.agent_tokens){t.read_bytes=n,this.file_xfer_read_queue.push(t);return}c=new FileReader,c.onload=function(a){const d=new Li(t.id,a.target.result.byteLength,a.target.result);i.send_agent_message(o.VD_AGENT_FILE_XFER_DATA,d),i.file_xfer_read(t,_),t.update_progressbar(_)},h=t.file.slice(n,_),c.readAsArrayBuffer(h)}}file_xfer_completed(t,e){e?this.log_err(e):this.log_info("transfer of '"+t.file.name+"' was successful"),t.remove_progressbar(),delete this.file_xfer_tasks[t.id]}handle_clipboard_grab(){const t=o.VD_AGENT_CLIPBOARD_UTF8_TEXT,e=new Si(t,this.agent_caps);this.send_agent_message(o.VD_AGENT_CLIPBOARD_REQUEST,e)}handle_clipboard_receive(t){const e=new mi(t,this.agent_caps);if(e.type===o.VD_AGENT_CLIPBOARD_UTF8_TEXT){if(typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.writeText){const s=e.get_text();navigator.clipboard.writeText(s).catch(i=>{console.warn("Failed to write to navigator clipboard:",i)})}}else console.log("Unsupported clipboard type:",e.type)}handle_clipboard_send(){typeof navigator<"u"&&navigator.clipboard&&navigator.clipboard.readText&&navigator.clipboard.readText().then(t=>{const e=o.VD_AGENT_CLIPBOARD_UTF8_TEXT,s=new Ii(e,t,this.agent_caps);this.send_agent_message(o.VD_AGENT_CLIPBOARD,s)}).catch(t=>{console.log("Failed to read clipboard:",t)})}send_clipboard_grab(){const t=o.VD_AGENT_CLIPBOARD_UTF8_TEXT,e=new pi(t,this.agent_caps);this.send_agent_message(o.VD_AGENT_CLIPBOARD_GRAB,e)}connect_agent(){this.agent_connected=!0;const t=new Mi(-1),e=new y;e.build_msg(o.SPICE_MSGC_MAIN_AGENT_START,t),this.send_msg(e),this.announce_agent_capabilities(1),this.onagent!==void 0&&this.onagent(this)}handle_mouse_mode(t,e){if(this.mouse_mode=t,t!=o.SPICE_MOUSE_MODE_CLIENT&&e&o.SPICE_MOUSE_MODE_CLIENT){const s=new wi(o.SPICE_MOUSE_MODE_CLIENT),i=new y;i.build_msg(o.SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST,s),this.send_msg(i)}this.inputs&&(this.inputs.mouse_mode=t)}relative_now(){return Date.now()-this.our_mm_time+this.mm_time}}exports.Constants=o;exports.SpiceConn=q;exports.SpiceCursorConn=rs;exports.SpiceDisplayConn=os;exports.SpiceInputsConn=ns;exports.SpiceMainConn=ln;exports.SpicePlaybackConn=ls;exports.SpicePortConn=us;exports.handle_file_dragover=Kr;exports.handle_file_drop=Br;exports.handle_resize=an;exports.resize_helper=ds;exports.sendCtrlAltDel=kr;
14
+ //# sourceMappingURL=index.js.map