1import{dq as es,dr as As,ds as Is,dt as Ts,du as Ps,dv as kt,dw as Ft,d as Us,k as B,al as Ct,g as Bs,aG as Hs,h as Ns,x as Vs,c as ve,o as ie,w as O,a as N,e as Pe,f as ke,p as Os,b as V,l as A,ag as zs,Y as Ws,B as Gs,bz as Ys,by as js,ay as qs,cG as $s,n as Zs,aB as Js,H as ei,az as ti,aA as si,t as _e,bw as ii,bn as ni,i as it,S as ri,br as ai,M as oi,Q as hi,am as St}from"./vendor-Bh6u8-zI.js";import{o as ci,p as li}from"./dedicated-store-agent-tool-BS3wYQWT.js";import{U as di}from"./windows-D4kRLOCn.js";import{b as ui,F as _i,aU as fi,c as pi,dH as xi,_ as gi}from"./index-DoWvVrc1.js";import{u as mi,_ as yi,C as bi,R as wi}from"./index.vue_vue_type_style_index_0_lang-sxipQVYT.js";import{e as vi,f as ki}from"./strategy_94_global-DiGUAnnv.js";const Fi="/workbench/assets/bell-BmA9-LrF.oga",Ci="/workbench/assets/bell-Bd8kEWkF.mp3";let Et="warn",C=()=>{},I=()=>{},H=()=>{},Q=()=>{};function Si(c){if(typeof c>"u"?c=Et:Et=c,C=I=H=Q=()=>{},typeof window.console<"u")switch(c){case"debug":C=void 0;case"info":I=void 0;case"warn":H=void 0;case"error":Q=void 0;case"none":break;default:throw new window.Error("invalid logging type '"+c+"'")}}Si();let ts="ontouchstart"in document.documentElement||document.ontouchstart!==void 0||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;window.addEventListener("touchstart",function c(){ts=!0,window.removeEventListener("touchstart",c,!1)},!1);let Kt=10*(window.devicePixelRatio||1),ss=!1;try{const c=document.createElement("canvas");c.style.cursor='url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default',c.style.cursor.indexOf("url")===0?(I("Data URI scheme cursor supported"),ss=!0):H("Data URI scheme cursor not supported")}catch(c){Q("Data URI scheme cursor test exception: "+c)}const Ei=ss;let Ki=!0;try{const c=document.createElement("div");c.style.visibility="hidden",c.style.overflow="scroll",document.body.appendChild(c);const e=document.createElement("div");c.appendChild(e);const t=c.offsetWidth-e.offsetWidth;c.parentNode.removeChild(c),Ki=t!=0}catch(c){Q("Scrollbar test exception: "+c)}function pe(){return navigator&&!!/mac/i.exec(navigator.platform)}function Ve(){return navigator&&!!/win/i.exec(navigator.platform)}function Qe(){return navigator&&(!!/ipad/i.exec(navigator.platform)||!!/iphone/i.exec(navigator.platform)||!!/ipod/i.exec(navigator.platform))}function Xi(){return navigator&&navigator.userAgent.indexOf("Safari")!==-1&&navigator.userAgent.indexOf("Chrome")===-1}function Mi(){var c=navigator.userAgent;return Qe()||c.indexOf("OculusBrowser")!=-1||c.indexOf("SamsungBrowser")!=-1?!1:c.indexOf("Windows")!=-1||c.indexOf("Mac")!=-1||c.indexOf("X11")!=-1||c.indexOf("Linux")!=-1}function Ri(){return!!window.chrome}function Qi(){return navigator&&!!/firefox/i.exec(navigator.userAgent)}function is(){return Xi()||Qi()?!1:navigator.clipboard&&typeof navigator.clipboard.read=="function"}function ge(c){c.stopPropagation(),c.preventDefault()}let nt=!1,ns=null;document.captureElement=null;function fe(c){if(nt)return;const e=new c.constructor(c.type,c);nt=!0,document.captureElement?document.captureElement.dispatchEvent(e):ns.dispatchEvent(e),nt=!1,c.stopPropagation(),e.defaultPrevented&&c.preventDefault(),c.type==="mouseup"&&os()}function rs(){const c=document.getElementById("noVNC_mouse_capture_elem");c.style.cursor=window.getComputedStyle(document.captureElement).cursor}const as=new MutationObserver(rs);function Di(c){if(c.setCapture)c.setCapture(),document.captureElement=c;else{os();let e=document.getElementById("noVNC_mouse_capture_elem");e===null&&(e=document.createElement("div"),e.id="noVNC_mouse_capture_elem",e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.width="100%",e.style.height="100%",e.style.zIndex=1e4,e.style.display="none",document.body.appendChild(e),e.addEventListener("contextmenu",fe),e.addEventListener("mousemove",fe),e.addEventListener("mouseup",fe)),document.captureElement=c,as.observe(c,{attributes:!0}),rs(),e.style.display="",window.addEventListener("mousemove",fe),window.addEventListener("mouseup",fe)}}function os(){if(document.releaseCapture)document.releaseCapture(),document.captureElement=null;else{if(!document.captureElement)return;ns=document.captureElement,document.captureElement=null,as.disconnect();const c=document.getElementById("noVNC_mouse_capture_elem");c.style.display="none",window.removeEventListener("mousemove",fe),window.removeEventListener("mouseup",fe)}}const d={XK_BackSpace:65288,XK_Tab:65289,XK_Clear:65291,XK_Return:65293,XK_Pause:65299,XK_Scroll_Lock:65300,XK_Escape:65307,XK_Delete:65535,XK_Multi_key:65312,XK_Codeinput:65335,XK_SingleCandidate:65340,XK_MultipleCandidate:65341,XK_PreviousCandidate:65342,XK_Kanji:65313,XK_Muhenkan:65314,XK_Henkan:65315,XK_Romaji:65316,XK_Hiragana:65317,XK_Katakana:65318,XK_Hiragana_Katakana:65319,XK_Zenkaku:65320,XK_Hankaku:65321,XK_Zenkaku_Hankaku:65322,XK_Kana_Shift:65326,XK_Eisu_toggle:65328,XK_Home:65360,XK_Left:65361,XK_Up:65362,XK_Right:65363,XK_Down:65364,XK_Prior:65365,XK_Next:65366,XK_End:65367,XK_Select:65376,XK_Print:65377,XK_Execute:65378,XK_Insert:65379,XK_Undo:65381,XK_Redo:65382,XK_Menu:65383,XK_Find:65384,XK_Cancel:65385,XK_Help:65386,XK_Mode_switch:65406,XK_Num_Lock:65407,XK_KP_Space:65408,XK_KP_Enter:65421,XK_KP_Home:65429,XK_KP_Left:65430,XK_KP_Up:65431,XK_KP_Right:65432,XK_KP_Down:65433,XK_KP_Prior:65434,XK_KP_Next:65435,XK_KP_End:65436,XK_KP_Begin:65437,XK_KP_Insert:65438,XK_KP_Delete:65439,XK_KP_Equal:65469,XK_KP_Multiply:65450,XK_KP_Add:65451,XK_KP_Separator:65452,XK_KP_Subtract:65453,XK_KP_Decimal
1:65454,XK_KP_Divide:65455,XK_KP_0:65456,XK_KP_1:65457,XK_KP_2:65458,XK_KP_3:65459,XK_KP_4:65460,XK_KP_5:65461,XK_KP_6:65462,XK_KP_7:65463,XK_KP_8:65464,XK_KP_9:65465,XK_F1:65470,XK_F2:65471,XK_F3:65472,XK_F4:65473,XK_F5:65474,XK_F6:65475,XK_F7:65476,XK_F8:65477,XK_F9:65478,XK_F10:65479,XK_F11:65480,XK_F12:65481,XK_F13:65482,XK_F14:65483,XK_F15:65484,XK_F16:65485,XK_F17:65486,XK_F18:65487,XK_F19:65488,XK_F20:65489,XK_F21:65490,XK_F22:65491,XK_F23:65492,XK_F24:65493,XK_F25:65494,XK_F26:65495,XK_F27:65496,XK_F28:65497,XK_F29:65498,XK_F30:65499,XK_F31:65500,XK_F32:65501,XK_F33:65502,XK_F34:65503,XK_F35:65504,XK_Shift_L:65505,XK_Shift_R:65506,XK_Control_L:65507,XK_Control_R:65508,XK_Caps_Lock:65509,XK_Meta_L:65511,XK_Meta_R:65512,XK_Alt_L:65513,XK_Alt_R:65514,XK_Super_L:65515,XK_Super_R:65516,XK_ISO_Level3_Shift:65027,XK_ISO_Next_Group:65032,XK_ISO_Prev_Group:65034,XK_ISO_First_Group:65036,XK_ISO_Last_Group:65038,XK_space:32,XK_asterisk:42,XK_plus:43,XK_comma:44,XK_minus:45,XK_period:46,XK_slash:47,XK_0:48,XK_1:49,XK_2:50,XK_3:51,XK_4:52,XK_5:53,XK_6:54,XK_7:55,XK_8:56,XK_9:57,XK_equal:61,XK_Hangul:65329,XK_Hangul_Hanja:65332,XK_Hangul_Jeonja:65336,XF86XK_MonBrightnessUp:269025026,XF86XK_MonBrightnessDown:269025027,XF86XK_Standby:269025040,XF86XK_AudioLowerVolume:269025041,XF86XK_AudioMute:269025042,XF86XK_AudioRaiseVolume:269025043,XF86XK_AudioPlay:269025044,XF86XK_AudioStop:269025045,XF86XK_AudioPrev:269025046,XF86XK_AudioNext:269025047,XF86XK_HomePage:269025048,XF86XK_Mail:269025049,XF86XK_Search:269025051,XF86XK_AudioRecord:269025052,XF86XK_Calculator:269025053,XF86XK_Calendar:269025056,XF86XK_PowerDown:269025057,XF86XK_Back:269025062,XF86XK_Forward:269025063,XF86XK_Stop:269025064,XF86XK_Refresh:269025065,XF86XK_PowerOff:269025066,XF86XK_WakeUp:269025067,XF86XK_Eject:269025068,XF86XK_ScreenSaver:269025069,XF86XK_WWW:269025070,XF86XK_Favorites:269025072,XF86XK_AudioPause:269025073,XF86XK_AudioMedia:269025074,XF86XK_MyComputer:269025075,XF86XK_BrightnessAdjust:269025083,XF86XK_AudioRewind:269025086,XF86XK_Close:269025110,XF86XK_Copy:269025111,XF86XK_Cut:269025112,XF86XK_Excel:269025116,XF86XK_LogOff:269025121,XF86XK_New:269025128,XF86XK_Open:269025131,XF86XK_Paste:269025133,XF86XK_Phone:269025134,XF86XK_Reply:269025138,XF86XK_Save:269025143,XF86XK_Send:269025147,XF86XK_Spell:269025148,XF86XK_SplitScreen:269025149,XF86XK_Word:269025161,XF86XK_ZoomIn:269025163,XF86XK_ZoomOut:269025164,XF86XK_WebCam:269025167,XF86XK_MailForward:269025168,XF86XK_Music:269025170,XF86XK_AudioForward:269025175,XF86XK_AudioRandomPlay:269025177,XF86XK_Subtitle:269025178,XF86XK_AudioCycleTrack:269025179,XF86XK_Hibernate:269025192,XF86XK_AudioMicMute:269025202,XF86XK_Next_VMode:269024802},Li={256:960,257:992,258:451,259:483,260:417,261:433,262:454,263:486,264:710,265:742,266:709,267:741,268:456,269:488,270:463,271:495,272:464,273:496,274:938,275:954,278:972,279:1004,280:458,281:490,282:460,283:492,284:728,285:760,286:683,287:699,288:725,289:757,290:939,291:955,292:678,293:694,294:673,295:689,296:933,297:949,298:975,299:1007,302:967,303:999,304:681,305:697,308:684,309:700,310:979,311:1011,312:930,313:453,314:485,315:934,316:950,317:421,318:437,321:419,322:435,323:465,324:497,325:977,326:1009,327:466,328:498,330:957,331:959,332:978,333:1010,336:469,337:501,338:5052,339:5053,340:448,341:480,342:931,343:947,344:472,345:504,346:422,347:438,348:734,349:766,350:426,351:442,352:425,353:441,354:478,355:510,356:427,357:443,358:940,359:956,360:989,361:1021,362:990,363:1022,364:733,365:765,366:473,367:505,368:475,369:507,370:985,371:1017,376:5054,377:428,378:444,379:431,380:447,381:430,382:446,402:2294,466:16777681,711:439,728:418,729:511,731:434,733:445,901:1966,902:1953,904:1954,905:1955,906:1956,908:1959,910:1960,911:1963,912:1974,913:1985,914:1986,915:1987,916:1988,917:1989,918:1990,919:1991,920:1992,921:1993,922:1994,923:1995,924:1996,925:1997,926:1998,927:1999,928:2e3,929:2001,931:2002,932:2004,933:2005,934:2006,935:2007,936:2008,937:2009,938:1957,939:1961,940:1969,941:1970,942:1971,943:1972,944:1978,945:2017,946:2018,947:2019,948:2020,949:2021,950:2022,951:2023,952:2024,953:2025,954:2026,955:2027,956:2028,957:2029,958:2030,959:2031,960:2032,961:2033,962:2035,963:2034,964:2036,965:2037,966:2038,967:2039,968:2040,9
169:2041,970:1973,971:1977,972:1975,973:1976,974:1979,1025:1715,1026:1713,1027:1714,1028:1716,1029:1717,1030:1718,1031:1719,1032:1720,1033:1721,1034:1722,1035:1723,1036:1724,1038:1726,1039:1727,1040:1761,1041:1762,1042:1783,1043:1767,1044:1764,1045:1765,1046:1782,1047:1786,1048:1769,1049:1770,1050:1771,1051:1772,1052:1773,1053:1774,1054:1775,1055:1776,1056:1778,1057:1779,1058:1780,1059:1781,1060:1766,1061:1768,1062:1763,1063:1790,1064:1787,1065:1789,1066:1791,1067:1785,1068:1784,1069:1788,1070:1760,1071:1777,1072:1729,1073:1730,1074:1751,1075:1735,1076:1732,1077:1733,1078:1750,1079:1754,1080:1737,1081:1738,1082:1739,1083:1740,1084:1741,1085:1742,1086:1743,1087:1744,1088:1746,1089:1747,1090:1748,1091:1749,1092:1734,1093:1736,1094:1731,1095:1758,1096:1755,1097:1757,1098:1759,1099:1753,1100:1752,1101:1756,1102:1728,1103:1745,1105:1699,1106:1697,1107:1698,1108:1700,1109:1701,1110:1702,1111:1703,1112:1704,1113:1705,1114:1706,1115:1707,1116:1708,1118:1710,1119:1711,1168:1725,1169:1709,1488:3296,1489:3297,1490:3298,1491:3299,1492:3300,1493:3301,1494:3302,1495:3303,1496:3304,1497:3305,1498:3306,1499:3307,1500:3308,1501:3309,1502:3310,1503:3311,1504:3312,1505:3313,1506:3314,1507:3315,1508:3316,1509:3317,1510:3318,1511:3319,1512:3320,1513:3321,1514:3322,1548:1452,1563:1467,1567:1471,1569:1473,1570:1474,1571:1475,1572:1476,1573:1477,1574:1478,1575:1479,1576:1480,1577:1481,1578:1482,1579:1483,1580:1484,1581:1485,1582:1486,1583:1487,1584:1488,1585:1489,1586:1490,1587:1491,1588:1492,1589:1493,1590:1494,1591:1495,1592:1496,1593:1497,1594:1498,1600:1504,1601:1505,1602:1506,1603:1507,1604:1508,1605:1509,1606:1510,1607:1511,1608:1512,1609:1513,1610:1514,1611:1515,1612:1516,1613:1517,1614:1518,1615:1519,1616:1520,1617:1521,1618:1522,3585:3489,3586:3490,3587:3491,3588:3492,3589:3493,3590:3494,3591:3495,3592:3496,3593:3497,3594:3498,3595:3499,3596:3500,3597:3501,3598:3502,3599:3503,3600:3504,3601:3505,3602:3506,3603:3507,3604:3508,3605:3509,3606:3510,3607:3511,3608:3512,3609:3513,3610:3514,3611:3515,3612:3516,3613:3517,3614:3518,3615:3519,3616:3520,3617:3521,3618:3522,3619:3523,3620:3524,3621:3525,3622:3526,3623:3527,3624:3528,3625:3529,3626:3530,3627:3531,3628:3532,3629:3533,3630:3534,3631:3535,3632:3536,3633:3537,3634:3538,3635:3539,3636:3540,3637:3541,3638:3542,3639:3543,3640:3544,3641:3545,3642:3546,3647:3551,3648:3552,3649:3553,3650:3554,3651:3555,3652:3556,3653:3557,3654:3558,3655:3559,3656:3560,3657:3561,3658:3562,3659:3563,3660:3564,3661:3565,3664:3568,3665:3569,3666:3570,3667:3571,3668:3572,3669:3573,3670:3574,3671:3575,3672:3576,3673:3577,8194:2722,8195:2721,8196:2723,8197:2724,8199:2725,8200:2726,8201:2727,8202:2728,8210:2747,8211:2730,8212:2729,8213:1967,8215:3295,8216:2768,8217:2769,8218:2813,8220:2770,8221:2771,8222:2814,8224:2801,8225:2802,8226:2790,8229:2735,8230:2734,8240:2773,8242:2774,8243:2775,8248:2812,8254:1150,8361:3839,8364:8364,8453:2744,8470:1712,8471:2811,8478:2772,8482:2761,8531:2736,8532:2737,8533:2738,8534:2739,8535:2740,8536:2741,8537:2742,8538:2743,8539:2755,8540:2756,8541:2757,8542:2758,8592:2299,8593:2300,8594:2301,8595:2302,8658:2254,8660:2253,8706:2287,8711:2245,8728:3018,8730:2262,8733:2241,8734:2242,8743:2270,8744:2271,8745:2268,8746:2269,8747:2239,8756:2240,8764:2248,8771:2249,8773:16785992,8800:2237,8801:2255,8804:2236,8805:2238,8834:2266,8835:2267,8866:3068,8867:3036,8868:3010,8869:3022,8968:3027,8970:3012,8981:2810,8992:2212,8993:2213,9109:3020,9115:2219,9117:2220,9118:2221,9120:2222,9121:2215,9123:2216,9124:2217,9126:2218,9128:2223,9132:2224,9143:2209,9146:2543,9147:2544,9148:2546,9149:2547,9225:2530,9226:2533,9227:2537,9228:2531,9229:2532,9251:2732,9252:2536,9472:2211,9474:2214,9484:2210,9488:2539,9492:2541,9496:2538,9500:2548,9508:2549,9516:2551,9524:2550,9532:2542,9618:2529,9642:2791,9643:2785,9644:2779,9645:2786,9646:2783,9647:2767,9650:2792,9651:2787,9654:2781,9655:2765,9660:2793,9661:2788,9664:2780,9665:2764,9670:2528,9675:2766,9679:2782,9702:2784,9734:2789,9742:2809,9747:2762,9756:2794,9758:2795,9792:2808,9794:2807,9827:2796,9829:2798,9830:2797,9837:2806,9839:2805,10003:2803,10007:2804,10013:2777,10016:2800,10216:2748,10217:2750,12289:1188,12290:1185,12300:1186,12301:1187,12443:1246,12444:1247,12449:1191,12450:1201,12451:1192,12452:1202,12453:1193,12454:1203,12455:1194,12456:1204,12457:1195,12458:1205,12459:1206,12461:1207,12463:1208,12465:1209,12467:1210,12469:1211,12471:1212,12473:1213,12475:1214,12477:1215,12479:1216,12481:1217,12483:1199,12484:1218,12486:1219,12488:1220,12490:1221,12491:1222,12492:1223,12493:1224,12494:1225,12495:1226,12498:1227,12501:1228,12504:1229,12507:1230,12510:1231,12511:1232,12512:1233,12513:1234,12514:1235,12515:1196,12516:1236,12517:1197,12518:1237,12519:1198,12520:1238,12521:1239,12522:1240,12523:1241,12524:1242,12525:1243,12527:1244,12530:1190,12531:1245,12539:1189,12540:1200},Xe={lookup(c){if(c>=32&&c<=255)return c;const e=Li[c];return e!==void 0?e:16777216|c}},Xt={8:"Backspace",9:"Tab",10:"NumpadClear",13:"Enter",16:"ShiftLeft",17:"Control
1Left",18:"AltLeft",19:"Pause",20:"CapsLock",21:"Lang1",25:"Lang2",27:"Escape",28:"Convert",29:"NonConvert",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",41:"Select",44:"PrintScreen",45:"Insert",46:"Delete",47:"Help",48:"Digit0",49:"Digit1",50:"Digit2",51:"Digit3",52:"Digit4",53:"Digit5",54:"Digit6",55:"Digit7",56:"Digit8",57:"Digit9",91:"MetaLeft",92:"MetaRight",93:"ContextMenu",95:"Sleep",96:"Numpad0",97:"Numpad1",98:"Numpad2",99:"Numpad3",100:"Numpad4",101:"Numpad5",102:"Numpad6",103:"Numpad7",104:"Numpad8",105:"Numpad9",106:"NumpadMultiply",107:"NumpadAdd",108:"NumpadDecimal",109:"NumpadSubtract",110:"NumpadDecimal",111:"NumpadDivide",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",124:"F13",125:"F14",126:"F15",127:"F16",128:"F17",129:"F18",130:"F19",131:"F20",132:"F21",133:"F22",134:"F23",135:"F24",144:"NumLock",145:"ScrollLock",166:"BrowserBack",167:"BrowserForward",168:"BrowserRefresh",169:"BrowserStop",170:"BrowserSearch",171:"BrowserFavorites",172:"BrowserHome",173:"AudioVolumeMute",174:"AudioVolumeDown",175:"AudioVolumeUp",176:"MediaTrackNext",177:"MediaTrackPrevious",178:"MediaStop",179:"MediaPlayPause",180:"LaunchMail",181:"MediaSelect",182:"LaunchApp1",183:"LaunchApp2",225:"AltRight"},Mt={Backspace:"Backspace",AltLeft:"Alt",AltRight:"Alt",CapsLock:"CapsLock",ContextMenu:"ContextMenu",ControlLeft:"Control",ControlRight:"Control",Enter:"Enter",MetaLeft:"Meta",MetaRight:"Meta",ShiftLeft:"Shift",ShiftRight:"Shift",Tab:"Tab",Delete:"Delete",End:"End",Help:"Help",Home:"Home",Insert:"Insert",PageDown:"PageDown",PageUp:"PageUp",ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowRight:"ArrowRight",ArrowUp:"ArrowUp",NumLock:"NumLock",NumpadBackspace:"Backspace",NumpadClear:"Clear",Escape:"Escape",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F30:"F30",F31:"F31",F32:"F32",F33:"F33",F34:"F34",F35:"F35",PrintScreen:"PrintScreen",ScrollLock:"ScrollLock",Pause:"Pause",BrowserBack:"BrowserBack",BrowserFavorites:"BrowserFavorites",BrowserForward:"BrowserForward",BrowserHome:"BrowserHome",BrowserRefresh:"BrowserRefresh",BrowserSearch:"BrowserSearch",BrowserStop:"BrowserStop",Eject:"Eject",LaunchApp1:"LaunchMyComputer",LaunchApp2:"LaunchCalendar",LaunchMail:"LaunchMail",MediaPlayPause:"MediaPlay",MediaStop:"MediaStop",MediaTrackNext:"MediaTrackNext",MediaTrackPrevious:"MediaTrackPrevious",Power:"Power",Sleep:"Sleep",AudioVolumeDown:"AudioVolumeDown",AudioVolumeMute:"AudioVolumeMute",AudioVolumeUp:"AudioVolumeUp",WakeUp:"WakeUp"},he={};function m(c,e){if(e===void 0)throw new Error('Undefined keysym for key "'+c+'"');if(c in he)throw new Error('Duplicate entry for key "'+c+'"');he[c]=[e,e,e,e]}function Ye(c,e,t){if(e===void 0)throw new Error('Undefined keysym for key "'+c+'"');if(t===void 0)throw new Error('Undefined keysym for key "'+c+'"');if(c in he)throw new Error('Duplicate entry for key "'+c+'"');he[c]=[e,e,t,e]}function U(c,e,t){if(e===void 0)throw new Error('Undefined keysym for key "'+c+'"');if(t===void 0)throw new Error('Undefined keysym for key "'+c+'"');if(c in he)throw new Error('Duplicate entry for key "'+c+'"');he[c]=[e,e,e,t]}Ye("Alt",d.XK_Alt_L,d.XK_Alt_R);m("AltGraph",d.XK_ISO_Level3_Shift);m("CapsLock",d.XK_Caps_Lock);Ye("Control",d.XK_Control_L,d.XK_Control_R);Ye("Meta",d.XK_Super_L,d.XK_Super_R);m("NumLock",d.XK_Num_Lock);m("ScrollLock",d.XK_Scroll_Lock);Ye("Shift",d.XK_Shift_L,d.XK_Shift_R);U("Enter",d.XK_Return,d.XK_KP_Enter);m("Tab",d.XK_Tab);U(" ",d.XK_space,d.XK_KP_Space);U("ArrowDown",d.XK_Down,d.XK_KP_Down);U("ArrowLeft",d.XK_Left,d.XK_KP_Left);U("ArrowRight",d.XK_Right,d.XK_KP_Right);U("ArrowUp",d.XK_Up,d.XK_KP_Up);U("End",d.XK_End,d.XK_KP_End);U("Home",d.XK_Home,d.XK_KP_Home);U("PageDown",d.XK_Next,d.XK_KP_Next);U("PageUp",d.XK_Prior,d.XK_KP_Prior);m("Backspace",d.XK_BackSpace);U("Clear",d.XK_Clear,d.XK_KP_Begin);m("Copy",d.XF86XK_Copy);m("Cut",d.XF86XK_Cut);U("Delete",d.XK_Delete,d.XK_KP_Delete);U("Insert",d.XK_Insert,d.XK_KP_Insert);m("Paste",d.XF86XK_Paste);m("Redo",d.XK_Redo);m("Undo",d.XK_Undo);m("Cancel",d.XK_Cancel);m("ContextMenu",d.XK_Menu);m("Escape",d.XK_Escape);m("Execute",d.XK_Execute);m("Find",d.XK_Find);m("Help",d.XK_Help);m("Pause",d.XK_Pause);m("Select",d.XK_Select);m("ZoomIn",d.XF86XK_ZoomIn);m("ZoomOut",d.XF86XK_ZoomOut);m("BrightnessDown",d.XF86XK_MonBrightnessDown);m("BrightnessUp",d.XF86XK_MonBrightnessUp);m("Eject",d.XF86XK_Eject);m("LogOff",d.XF86XK_LogOff);m("Power",d.XF86XK_PowerOff);m("PowerOff",d.XF86XK_PowerDown);m("PrintScreen",d.XK_Print);m("Hibernate",d.XF86XK_Hibernate);m("Standby",d.XF86XK_Standby);m("WakeUp",d.XF86XK_WakeUp);m("AllCandidates",d.XK_MultipleCandidate);
1m("Alphanumeric",d.XK_Eisu_toggle);m("CodeInput",d.XK_Codeinput);m("Compose",d.XK_Multi_key);m("Convert",d.XK_Henkan);m("GroupFirst",d.XK_ISO_First_Group);m("GroupLast",d.XK_ISO_Last_Group);m("GroupNext",d.XK_ISO_Next_Group);m("GroupPrevious",d.XK_ISO_Prev_Group);m("NonConvert",d.XK_Muhenkan);m("PreviousCandidate",d.XK_PreviousCandidate);m("SingleCandidate",d.XK_SingleCandidate);m("HangulMode",d.XK_Hangul);m("HanjaMode",d.XK_Hangul_Hanja);m("JunjaMode",d.XK_Hangul_Jeonja);m("Eisu",d.XK_Eisu_toggle);m("Hankaku",d.XK_Hankaku);m("Hiragana",d.XK_Hiragana);m("HiraganaKatakana",d.XK_Hiragana_Katakana);m("KanaMode",d.XK_Kana_Shift);m("KanjiMode",d.XK_Kanji);m("Katakana",d.XK_Katakana);m("Romaji",d.XK_Romaji);m("Zenkaku",d.XK_Zenkaku);m("ZenkakuHankaku",d.XK_Zenkaku_Hankaku);m("F1",d.XK_F1);m("F2",d.XK_F2);m("F3",d.XK_F3);m("F4",d.XK_F4);m("F5",d.XK_F5);m("F6",d.XK_F6);m("F7",d.XK_F7);m("F8",d.XK_F8);m("F9",d.XK_F9);m("F10",d.XK_F10);m("F11",d.XK_F11);m("F12",d.XK_F12);m("F13",d.XK_F13);m("F14",d.XK_F14);m("F15",d.XK_F15);m("F16",d.XK_F16);m("F17",d.XK_F17);m("F18",d.XK_F18);m("F19",d.XK_F19);m("F20",d.XK_F20);m("F21",d.XK_F21);m("F22",d.XK_F22);m("F23",d.XK_F23);m("F24",d.XK_F24);m("F25",d.XK_F25);m("F26",d.XK_F26);m("F27",d.XK_F27);m("F28",d.XK_F28);m("F29",d.XK_F29);m("F30",d.XK_F30);m("F31",d.XK_F31);m("F32",d.XK_F32);m("F33",d.XK_F33);m("F34",d.XK_F34);m("F35",d.XK_F35);m("Close",d.XF86XK_Close);m("MailForward",d.XF86XK_MailForward);m("MailReply",d.XF86XK_Reply);m("MailSend",d.XF86XK_Send);m("MediaFastForward",d.XF86XK_AudioForward);m("MediaPause",d.XF86XK_AudioPause);m("MediaPlay",d.XF86XK_AudioPlay);m("MediaRecord",d.XF86XK_AudioRecord);m("MediaRewind",d.XF86XK_AudioRewind);m("MediaStop",d.XF86XK_AudioStop);m("MediaTrackNext",d.XF86XK_AudioNext);m("MediaTrackPrevious",d.XF86XK_AudioPrev);m("New",d.XF86XK_New);m("Open",d.XF86XK_Open);m("Print",d.XK_Print);m("Save",d.XF86XK_Save);m("SpellCheck",d.XF86XK_Spell);m("AudioVolumeDown",d.XF86XK_AudioLowerVolume);m("AudioVolumeUp",d.XF86XK_AudioRaiseVolume);m("AudioVolumeMute",d.XF86XK_AudioMute);m("MicrophoneVolumeMute",d.XF86XK_AudioMicMute);m("LaunchApplication1",d.XF86XK_MyComputer);m("LaunchApplication2",d.XF86XK_Calculator);m("LaunchCalendar",d.XF86XK_Calendar);m("LaunchMail",d.XF86XK_Mail);m("LaunchMediaPlayer",d.XF86XK_AudioMedia);m("LaunchMusicPlayer",d.XF86XK_Music);m("LaunchPhone",d.XF86XK_Phone);m("LaunchScreenSaver",d.XF86XK_ScreenSaver);m("LaunchSpreadsheet",d.XF86XK_Excel);m("LaunchWebBrowser",d.XF86XK_WWW);m("LaunchWebCam",d.XF86XK_WebCam);m("LaunchWordProcessor",d.XF86XK_Word);m("BrowserBack",d.XF86XK_Back);m("BrowserFavorites",d.XF86XK_Favorites);m("BrowserForward",d.XF86XK_Forward);m("BrowserHome",d.XF86XK_HomePage);m("BrowserRefresh",d.XF86XK_Refresh);m("BrowserSearch",d.XF86XK_Search);m("BrowserStop",d.XF86XK_Stop);m("Dimmer",d.XF86XK_BrightnessAdjust);m("MediaAudioTrack",d.XF86XK_AudioCycleTrack);m("RandomToggle",d.XF86XK_AudioRandomPlay);m("SplitScreenToggle",d.XF86XK_SplitScreen);m("Subtitle",d.XF86XK_Subtitle);m("VideoModeNext",d.XF86XK_Next_VMode);U("=",d.XK_equal,d.XK_KP_Equal);U("+",d.XK_plus,d.XK_KP_Add);U("-",d.XK_minus,d.XK_KP_Subtract);U("*",d.XK_asterisk,d.XK_KP_Multiply);U("/",d.XK_slash,d.XK_KP_Divide);U(".",d.XK_period,d.XK_KP_Decimal);U(",",d.XK_comma,d.XK_KP_Separator);U("0",d.XK_0,d.XK_KP_0);U("1",d.XK_1,d.XK_KP_1);U("2",d.XK_2,d.XK_KP_2);U("3",d.XK_3,d.XK_KP_3);U("4",d.XK_4,d.XK_KP_4);U("5",d.XK_5,d.XK_KP_5);U("6",d.XK_6,d.XK_KP_6);U("7",d.XK_7,d.XK_KP_7);U("8",d.XK_8,d.XK_KP_8);U("9",d.XK_9,d.XK_KP_9);function De(c){if(c.code){switch(c.code){case"OSLeft":return"MetaLeft";case"OSRight":return"MetaRight"}return c.code}if(c.keyCode in Xt){let e=Xt[c.keyCode];if(pe()&&e==="ContextMenu"&&(e="MetaRight"),c.location===2)switch(e){case"ShiftLeft":return"ShiftRight";case"ControlLeft":return"ControlRight";case"AltLeft":return"AltRight"}if(c.location===3)switch(e){case"Delete":return"NumpadDecimal";case"Insert":return"Numpad0";case"End":return"Numpad1";case"ArrowDown":return"Numpad2";case"PageDown":return"Numpad3";case"ArrowLeft":return"Numpad4";case"ArrowRight":return"Numpad6";case"Home":return"Numpad7";case"ArrowUp":return"Numpad8";case"PageUp":return"Numpad9";case"Enter":return"NumpadEnter"}return e}return"Unidentified"}function Ai(c){if(c.key!==void 0&&c.key!=="Unidentified"){switch(c.key){case"OS":return"Meta";case"LaunchMyComputer":return"LaunchApplication1";case"LaunchCalculator":return"LaunchApplication2"}switch(c.key){case"UIKeyInputUpArrow":return"ArrowUp";case"UIKeyInputDownArrow":return"ArrowDown";case"UIKeyInputLeftArrow":return"ArrowLeft";case"UIKeyInputRightArrow":return"ArrowRight";case"UIKeyInputEscape":return"Escape"}return c.key==="\0"&&c.code==="NumpadDecimal"?"Delete":c.key}const e=De(c);return e in Mt?Mt[e]:c.charCode?String.fromCharCode(c.charCode):"Unidentified"}function Ii(c){const e=Ai(c);if(e==="Unidentified")return null;if(e in he){let s=c.location;if(e==="Meta"&&s===0&&(s=2),e==="Clear"&&s===3&&De(c)==="NumLock"&&(s=0),(s===void 0||s>3)&&(s=0),e==="Meta"){let i=De(c);if(i==="AltLeft")return d.XK_Meta_L;if(i==="AltRight")return d.XK_Meta_R}if(e==="Clear"&&De(c)==="NumLock")return d.XK_Num_Lock;if(Ve())switch(e){case"Zenkaku":case"Hankaku":return d.XK_Zenkaku_Hankaku;case"Romaji":case"KanaMode":return d.XK_Romaji}return he[e][s]}if(e.length!==1)return null;const t=e.charCodeAt();return t?Xe.lookup(t):null}const Ti={48:"Digit0",49:"Digit1",50:"Digit2",51:"Digit3",52:"Digit4",53:"Digit5",54:"Digit6",5
15:"Digit7",56:"Digit8",57:"Digit9",96:"Numpad0",97:"Numpad1",98:"Numpad2",99:"Numpad3",100:"Numpad4",101:"Numpad5",102:"Numpad6",103:"Numpad7",104:"Numpad8",105:"Numpad9"};class Pi{constructor(e,t){this._screenInput=e,this._touchInput=t,this._keyDownList={},this._altGrArmed=!1,this._eventHandlers={keyup:this._handleKeyUp.bind(this),keydown:this._handleKeyDown.bind(this),blur:this._allKeysUp.bind(this),compositionstart:this._handleCompositionStart.bind(this),compositionend:this._handleCompositionEnd.bind(this),input:this._handleInput.bind(this)},this.onkeyevent=()=>{},this._enableIME=!1,this._imeHold=!1,this._imeInProgress=!1,this._lastKeyboardInput=null,this._defaultKeyboardInputLen=100,this._keyboardInputReset(),this._translateShortcuts=!0}get enableIME(){return this._enableIME}set enableIME(e){this._enableIME=e,this.focus()}get translateShortcuts(){return this._translateShortcuts}set translateShortcuts(e){this._translateShortcuts=e}clearKeysDown(e){if(e)for(const[t,s]of Object.entries(this._keyDownList))switch(t){case"ControlLeft":case"ControlRight":e.ctrlKey||(Q("A control key is stuck down, sending up."),this._sendKeyEvent(s,t,!1));break;case"MetaLeft":case"MetaRight":e.metaKey||(Q("A meta key is stuck down, sending up."),this._sendKeyEvent(s,t,!1));break;case"AltLeft":case"AltRight":e.altKey||(Q("A alt key is stuck down, sending up. "),this._sendKeyEvent(s,t,!1));break;case"ShiftRight":case"ShiftLeft":e.shiftKey||(Q("A shift key is stuck down, sending up."),this._sendKeyEvent(s,t,!1));break}}_sendKeyEvent(e,t,s){if(s)this._keyDownList[t]=e;else{if(!(t in this._keyDownList))return;delete this._keyDownList[t]}C("onkeyevent "+(s?"down":"up")+", keysym: "+e,", code: "+t),this.onkeyevent(e,t,s)}_getKeyCode(e){const t=De(e);if(t!=="Unidentified")return t;if(e.keyCode&&e.keyCode!==229)return"Platform"+e.keyCode;if(e.keyIdentifier){if(e.keyIdentifier.substr(0,2)!=="U+")return e.keyIdentifier;const s=parseInt(e.keyIdentifier.substr(2),16);return"Platform"+String.fromCharCode(s).toUpperCase().charCodeAt()}return"Unidentified"}_handleCompositionStart(e){C("composition started"),this._enableIME&&(this._imeHold=!0,this._imeInProgress=!0)}_handleCompositionEnd(e){C("Composition ended"),this._enableIME&&(this._imeInProgress=!1),Ri()&&(this._imeHold=!1)}_handleInput(e){if(this._enableIME&&this._imeHold){C("IME input change, sending differential"),this._imeInProgress||(this._imeHold=!1);const t=this._lastKeyboardInput,s=e.target.value;let i=0;for(let n=0;n<Math.min(t.length,s.length)&&s.charAt(n)==t.charAt(n);n++)i++;for(let n=t.length-i;n>0;n--)this._sendKeyEvent(d.XK_BackSpace,"Backspace",!0),this._sendKeyEvent(d.XK_BackSpace,"Backspace",!1);for(let n=i;n<s.length;n++)this._sendKeyEvent(Xe.lookup(s.charCodeAt(n)),"Unidentified",!0),this._sendKeyEvent(Xe.lookup(s.charCodeAt(n)),"Unidentified",!1);this._lastKeyboardInput=s}else{C("Non-IME input change, sending new characters");const t=e.target.value;this._lastKeyboardInput||this._keyboardInputReset();const s=this._lastKeyboardInput;let i;try{i=Math.max(e.target.selectionStart,t.length)}catch{i=t.length}const n=s.length;let r=i-n,a=r<0?-r:0;for(let o=0;o<Math.min(n,i);o++)if(t.charAt(o)!=s.charAt(o)){r=i-o,a=n-o;break}for(let o=0;o<a;o++)this._sendKeyEvent(d.XK_BackSpace,"Backspace",!0),this._sendKeyEvent(d.XK_BackSpace,"Backspace",!1);for(let o=i-r;o<i;o++)this._sendKeyEvent(Xe.lookup(t.charCodeAt(o)),"Unidentified",!0),this._sendKeyEvent(Xe.lookup(t.charCodeAt(o)),"Unidentified",!1);i>2*this._defaultKeyboardInputLen?this._keyboardInputReset():i<1?(this._keyboardInputReset(),e.target.blur(),setTimeout(e.target.focus.bind(e.target),0)):this._lastKeyboardInput=t}}_keyboardInputReset(){this._touchInput.value=new Array(this._defaultKeyboardInputLen).join("_"),this._lastKeyboardInput=this._touchInput.value}_handleKeyDown(e){const t=this._getKeyCode(e);let s=Ii(e);if(this.clearKeysDown(e),this._isIMEInteraction(e)){C("Skipping keydown, IME interaction, code: "+t+" keysym: "+s+" keycode: "+e.keyCode);return}if(this._altGrArmed&&(this._altGrArmed=!1,clearTimeout(this._altGrTimeout),t==="AltRight"&&e.timeStamp-this._altGrCtrlTime<50?s=d.XK_ISO_Level3_Shift:this._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0)),t==="Unidentified"){s&&(this._sendKeyEvent(s,t,!0),this._sendKeyEvent(s,t,!1)),ge(e);return}if(pe()&&this._translateShortcuts&&t!=="MetaLeft"&&t!=="MetaRight"&&e.metaKey&&!e.ctrlKey&&!e.altKey){this._sendKeyEvent(this._keyDownList.MetaLeft,"MetaLeft",!1),this._sendKeyEvent(this._keyDownList.MetaRight,"MetaRight",!1),this._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0),this._sendKeyEvent(s,t,!0),ge(e);return}if(pe()||Qe())switch(s){case d.XK_Super_L:s=d.XK_Alt_L;break;case d.XK_Super_R:s=d.XK_Super_L;break;case d.XK_Alt_L:s=d.XK_Mode_switch;break;case d.XK_Alt_R:s=d.XK_ISO_Level3_Shift;break}if(t in this._keyDownList&&(s=this._keyDownList[t]),(pe()||Qe())&&t==="CapsLock"){this._sendKeyEvent(d.XK_Caps_Lock,"CapsLock",!0),this._sendKeyEvent(d.XK_Caps_Lock,"CapsLock",!1),ge(e);return}const i=[d.XK_Zenkaku_Hankaku,d.XK_Eisu_toggle,d.XK_Katakana,d.XK_Hiragana,d.XK_Romaji];if(Ve()&&i.includes(s)){this._sendKeyEvent(s,t,!0),this._sendKeyEvent(s,t,!1),ge(e);return}
1if(ge(e),t==="ControlLeft"&&Ve()&&!("ControlLeft"in this._keyDownList)){this._altGrArmed=!0,this._altGrTimeout=setTimeout(this._handleAltGrTimeout.bind(this),100),this._altGrCtrlTime=e.timeStamp;return}this._sendKeyEvent(s,t,!0)}_handleKeyUp(e){const t=this._getKeyCode(e);if(this._isIMEInteraction(e)){C("Skipping keyup, IME interaction, code: "+t+" keycode: "+e.keyCode);return}if(ge(e),this._altGrArmed&&(this._altGrArmed=!1,clearTimeout(this._altGrTimeout),this._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0)),(pe()||Qe())&&t==="CapsLock"){this._sendKeyEvent(d.XK_Caps_Lock,"CapsLock",!0),this._sendKeyEvent(d.XK_Caps_Lock,"CapsLock",!1);return}this._sendKeyEvent(this._keyDownList[t],t,!1),Ve()&&(t==="ShiftLeft"||t==="ShiftRight")&&("ShiftRight"in this._keyDownList&&this._sendKeyEvent(this._keyDownList.ShiftRight,"ShiftRight",!1),"ShiftLeft"in this._keyDownList&&this._sendKeyEvent(this._keyDownList.ShiftLeft,"ShiftLeft",!1))}_handleAltGrTimeout(){this._altGrArmed=!1,clearTimeout(this._altGrTimeout),this._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0)}_allKeysUp(){C(">> Keyboard.allKeysUp");for(let e in this._keyDownList)this._sendKeyEvent(this._keyDownList[e],e,!1);C("<< Keyboard.allKeysUp")}_isIMEInteraction(e){return e.target!=this._touchInput||!this._enableIME?!1:e.keyCode==229||e.keyCode in Ti}focus(){this._enableIME?this._touchInput.focus():this._screenInput.focus()}blur(){this._enableIME?this._touchInput.blur():this._screenInput.blur()}grab(){this._screenInput.addEventListener("keydown",this._eventHandlers.keydown),this._screenInput.addEventListener("keyup",this._eventHandlers.keyup),this._touchInput.addEventListener("keydown",this._eventHandlers.keydown),this._touchInput.addEventListener("keyup",this._eventHandlers.keyup),this._touchInput.addEventListener("compositionstart",this._eventHandlers.compositionstart),this._touchInput.addEventListener("compositionend",this._eventHandlers.compositionend),this._touchInput.addEventListener("input",this._eventHandlers.input),window.addEventListener("blur",this._eventHandlers.blur)}ungrab(){this._screenInput.removeEventListener("keydown",this._eventHandlers.keydown),this._screenInput.removeEventListener("keyup",this._eventHandlers.keyup),this._touchInput.removeEventListener("keydown",this._eventHandlers.keydown),this._touchInput.removeEventListener("keyup",this._eventHandlers.keyup),this._touchInput.removeEventListener("compositionstart",this._eventHandlers.compositionstart),this._touchInput.removeEventListener("compositionend",this._eventHandlers.compositionend),this._touchInput.removeEventListener("input",this._eventHandlers.input),window.removeEventListener("blur",this._eventHandlers.blur),this._allKeysUp()}}function Ui(c){return c>>>0}function Me(c){return c|0}function Rt(c){var e=32768,t=1<<31,s=16384,i=c|0;return c&t&&(i*=-1,i|=e),i|=s,i}function Re(c){typeof c=="string"&&(c=[...c].map(t=>t.charCodeAt(0)));let e=0;for(let t=0;t<c.length;t++)e=Math.imul(31,e)+c[t]|0;return e}function rt(c,e=!1){try{return decodeURIComponent(escape(c))}catch(t){if(t instanceof URIError&&e)return c;throw t}}function dt(c){return unescape(encodeURIComponent(c))}function Bi(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,c=>(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16))}function Fe(c,e,t){const s=t.getBoundingClientRect();let i={x:0,y:0};return c<s.left?i.x=0:c>=s.right?i.x=s.width-1:i.x=c-s.left,e<s.top?i.y=0:e>=s.bottom?i.y=s.height-1:i.y=e-s.top,c>window.innerWidth?i.x+=c-window.innerWidth:c<0&&(i.x=c+s.left),e>window.innerHeight?i.y+=e-window.innerHeight:e<0&&(i.y=e+s.top),i}class Hi{constructor(){this._listeners=new Map}addEventListener(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}removeEventListener(e,t){this._listeners.has(e)&&this._listeners.get(e).delete(t)}dispatchEvent(e){return this._listeners.has(e.type)?(this._listeners.get(e.type).forEach(t=>t.call(this,e)),!e.defaultPrevented):!0}}const Ni="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ue=Object.fromEntries(Array.from(Ni).map((c,e)=>
1[e,c.charCodeAt(0)])),Vi=new TextDecoder,Qt={base64Pad:"=",encode(c){let e=c.length,t=e%3,s=Math.floor(e/3)*4+(t&&t+1),i=Math.ceil(e/3)*4,n=new Uint8Array(i);for(let a=0,o=0;o<e;a+=4,o+=3){let h=(c[o]<<16)+(c[o+1]<<8)+(c[o+2]|0);n[a]=Ue[h>>18],n[a+1]=Ue[h>>12&63],n[a+2]=Ue[h>>6&63],n[a+3]=Ue[h&63]}let r=Vi.decode(new Uint8Array(n.buffer,0,s));return t===1&&(r+="=="),t===2&&(r+="="),r},toBinaryTable:[-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,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,0,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1],decode(c,e=0){let t=c.indexOf("=")-e;t<0&&(t=c.length-e);const s=(t>>2)*3+Math.floor(t%4/1.5),i=new Uint8Array(s);let n=0,r=0;for(let a=0,o=e;o<c.length;o++){const h=this.toBinaryTable[c.charCodeAt(o)&127],u=c.charAt(o)===this.base64Pad;if(h===-1){Q("Illegal character code "+c.charCodeAt(o)+" at position "+o);continue}r=r<<6|h,n+=6,n>=8&&(n-=8,u||(i[a++]=r>>n&255),r&=(1<<n)-1)}if(n){const a=new Error("Corrupted base64 string");throw a.name="Base64-Error",a}return i}};class Oi{constructor(e,t){if(C(">> Display.constructor"),this._asyncFrameQueue=[],this._maxAsyncFrameQueue=3,this._clearAsyncQueue(),this._syncFrameQueue=[],this._transparentOverlayImg=null,this._transparentOverlayRect=null,this._lastTransparentRectId="",this._flushing=!1,this._fbWidth=0,this._fbHeight=0,this._renderMs=0,this._prevDrawStyle="",this._target=e,!this._target)throw new Error("Target must be set");if(typeof this._target=="string")throw new Error("target must be a DOM element");if(!this._target.getContext)throw new Error("no getContext method");this._targetCtx=this._target.getContext("2d",{willReadFrequently:!0}),C("User Agent: "+navigator.userAgent),this._flipCnt=0,this._lastFlip=Date.now(),this._droppedFrames=0,this._droppedFramesRate=0,this._droppedFramesCnt=0,this._droppedRects=0,this._forcedFrameCnt=0,this._missingFlipRect=0,this._lateFlipRect=0,this._frameStatsInterval=setInterval(function(){let s=Date.now()-this._lastFlip;if(s>0){if(this._fps=(this._flipCnt/(s/1e3)).toFixed(2),this._droppedFrames>this._droppedFramesCnt){let i=this._droppedFrames-this._droppedFramesCnt;this._droppedFramesRate=(i/(s/1e3)).toFixed(2)}else this._droppedFramesRate=0;this._droppedFramesCnt=this._droppedFrames}C("Dropped Frames: "+this._droppedFrames+" Dropped Rects: "+this._droppedRects+" Forced Frames: "+this._forcedFrameCnt+" Missing Flips: "+this._missingFlipRect+" Late Flips: "+this._lateFlipRect),this._flipCnt=0,this._lastFlip=Date.now()}.bind(this),5e3),this._maxScreens=4,this._scale=1,this._clipViewport=!1,this._antiAliasing=0,this._fps=0,this._isPrimaryDisplay=t,this._screenID=Bi(),this._screens=[{screenID:this._screenID,screenIndex:0,width:this._target.width,height:this._target.height,serverWidth:0,serverHeight:0,serverReportedWidth:0,serverReportedHeight:0,x:0,y:0,scale:1,relativePosition:0,relativePositionX:0,relativePositionY:0,pixelRatio:window.devicePixelRatio,containerHeight:this._target.parentNode.offsetHeight,containerWidth:this._target.parentNode.offsetWidth,channel:null,x2:0,y2:0}],this._threading=!0,this._primaryChannel=null,this._enableCanvasBuffer=!1,this._backbuffer=document.createElement("canvas"),this._drawCtx=this._backbuffer.getContext("2d",{willReadFrequently:!0}),this._damageBounds={left:0,top:0,right:this._backbuffer.width,bottom:this._backbuffer.height},this.onflush=()=>{},this._isPrimaryDisplay||window.addEventListener("message",this._handleSecondaryDisplayMessage.bind(this)),C("<< Display.constructor")}get enableCanvasBuffer(){return this._enableCanvasBuffer}set enableCanvasBuffer(e){if(e!==this._enableCanvasBuffer){if(this._enableCanvasBuffer=e,e&&this._target){let t=this._targetCtx.getImageData(0,0,this._target.width,this._target.height);this._drawCtx.putImageData(t,0,0),this._transparentOverlayImg&&this.drawImage(this._transparentOverlayImg,this._transparentOverlayRect.x,this._transparentOverlayRect.y,this._transparentOverlayRect.width,this._transparentOverlayRect.height,!0)}else if(!e&&this._target){let t=this._targetCtx.getImageData(0,0,this._target.width,this._target.height);this._drawCtx.putImageData(t,0,0)}}}get screens(){return this._screens}get screenID(){return this._screenID}get screenIndex(){return!this._isPrimaryDisplay&&this._screens[0].screenIndex==0?-1:this._screens[0].screenIndex}get antiAliasing(){return this._antiAliasing}set antiAliasing(e){this._antiAliasing=e,this._rescale(this._scale)}
1get scale(){return this._scale}set scale(e){this._rescale(e)}get threading(){return this._threading}set threading(e){this._threading=e}get clipViewport(){return this._clipViewport}set clipViewport(e){this._clipViewport=e;const t=this._screens[0];this.viewportChangeSize(t.width,t.height),this.viewportChangePos(0,0)}get width(){return this._fbWidth}get height(){return this._fbHeight}get renderMs(){return this._renderMs}set renderMs(e){this._renderMs=e}get fps(){return this._fps}get droppedFps(){return this._droppedFramesRate}getClientRelativeCoordinates(e,t){for(let s=0;s<this._screens.length;s++)if(e>=this._screens[s].x&&e<=this._screens[s].x+this._screens[s].serverWidth&&t>=this._screens[s].y&&t<=this._screens[s].y+this._screens[s].serverHeight)return{screenIndex:s,x:e-this._screens[s].x,y:t-this._screens[s].y}}getServerRelativeCoordinates(e,t,s){return e>=0&&e<this._screens.length&&(t=Me(t/this._screens[e].scale+this._screens[e].x),s=Me(s/this._screens[e].scale+this._screens[e].y)),[t,s]}getScreenSize(e,t,s,i,n,r){let a={screens:null,serverWidth:0,serverHeight:0},o=0;this._screens[o].containerHeight=this._target.parentNode.offsetHeight,this._screens[o].containerWidth=this._target.parentNode.offsetWidth,this._screens[o].pixelRatio=window.devicePixelRatio,this._screens[o].width=this._target.parentNode.offsetWidth,this._screens[o].height=this._target.parentNode.offsetHeight;let h=t||this._screens[o].containerWidth,u=s||this._screens[o].containerHeight;if(this._screens[o].serverReportedWidth>0&&this._screens[o].serverReportedHeight>0&&(r||this._screens[o].serverReportedWidth!==this._screens[o].serverWidth||this._screens[o].serverReportedHeight!==this._screens[o].serverHeight)&&!t&&!s)u=this._screens[o].serverReportedHeight,h=this._screens[o].serverReportedWidth;else if(h>1280&&!n&&e==1)u=Math.floor(1280*(u/h)),h=1280;else if(e==0&&!n)h=1280,u=720;else if(i)h=Math.floor(h*this._screens[o].pixelRatio),u=Math.floor(u*this._screens[o].pixelRatio),1/this._screens[o].pixelRatio;else if([0,1].includes(this._antiAliasing)&&this._screens[o].pixelRatio>1&&h<1e3&&h>0){I("Device Pixel ratio: "+this._screens[o].pixelRatio+" Reported Resolution: "+h+"x"+u);let k=1.5;this._screens[o].pixelRatio>2&&(k=2);let K=h*this._screens[o].pixelRatio*(1/k)/h;h=h*K,u=u*K,I("Small device with hDPI screen detected, auto scaling at "+K+" to "+h+"x"+u)}let _=this._screens[o].containerHeight/u,w=this._screens[o].containerWidth/h;for(this._screens[o].height=Math.floor(u*_),this._screens[o].width=Math.floor(h*w),this._screens[o].serverWidth=h,this._screens[o].serverHeight=u,this._screens[o].scale=Math.min(_,w),o=0;o<this._screens.length;o++)this._screens[o].x2=this._screens[o].x+this._screens[o].serverWidth,this._screens[o].y2=this._screens[o].y+this._screens[o].serverHeight,a.serverWidth=Math.max(a.serverWidth,this._screens[o].x+this._screens[o].serverWidth),a.serverHeight=Math.max(a.serverHeight,this._screens[o].y+this._screens[o].serverHeight);return a.screens=this._screens,a}applyServerResolution(e,t,s){for(let i=0;i<this._screens.length;i++)s===this._screens[i].screenIndex&&(this._screens[i].serverReportedWidth=e,this._screens[i].serverReportedHeight=t)}applyScreenPlan(e){let t=!1;for(let s=0;s<e.screens.length;s++)for(let i=0;i<this._screens.length;i++)e.screens[s].screenID===this._screens[i].screenID&&((this._screens[i].x!==e.screens[s].x||this._screens[i].y!==e.screens[s].y)&&(i==0&&(this._screens[i].x=e.screens[s].x,this._screens[i].y=e.screens[s].y),t=!0),(this._screens[i].x2!==this._screens[i].x+this._screens[i].serverWidth||this._screens[i].y2!==this._screens[i].y+this._screens[i].serverHeight)&&(i==0&&(this._screens[i].x2=this._screens[i].x+this._screens[i].serverWidth,this._screens[i].y2=this._screens[i].y+this._screens[i].serverHeight),t=!0));return t}addScreen(e,t,s,i,n,r,a,o,h,u,_){if(this._isPrimaryDisplay)(n===0||r===0||i===0)&&H("Invalid screen configuration.");else throw new Error("Cannot add a screen to a secondary display.");let w=-1;for(let v=0;v<this._screens.length;v++)this._screens[v].screenID===e&&(w=v);if(w>0){const v=this._screens[w];if(v.serverHeight!==h||v.serverWidth!==o||v.width!==t||v.height!==s||v.containerHeight!==n||v.containerWidth!==r||v.scale!==a||v.pixelRatio!==i||v.x!==u||v.y!==_)return v.width=t,v.height=s,v.containerHeight=n,v.containerWidth=r,v.pixelRatio=i,v.scale=a,v.serverWidth=o,v.serverHeight=h,v.x=u,v.y=_,v.x2=v.x+v.serverWidth,v.y2=v.y+v.serverHeight,!0}else{for(let v=0;v<this._screens.length;v++)u=Math.max(u,this._screens[v].x+this._screens[v].serverWidth);var k={screenID:e,screenIndex:this.screens.length,width:t,height:s,serverWidth:o,serverHeight:h,serverReportedWidth:0,serverReportedHeight:0,x:u,y:0,pixelRatio:i,containerHeight:n,
1containerWidth:r,channel:null,scale:a,x2:u+o,y2:h};return this._screens.push(k),k.channel.postMessage({eventType:"registered",screenIndex:k.screenIndex}),k.screenIndex}return!1}removeScreen(e){let t=!1;if(this._isPrimaryDisplay){for(let s=1;s<this._screens.length;s++)if(this._screens[s].screenID==e){this._flushRectsScreen(s),this._screens.splice(s,1),t=!0;break}for(let s=1;s<this._screens.length;s++)this.screens[s].screenIndex=s,s>0&&this._screens[s].channel.postMessage({eventType:"registered",screenIndex:s});return t}else throw new Error("Secondary screens only allowed on primary display.")}viewportChangePos(e,t){const s=this._screens[0];e=Math.floor(e),t=Math.floor(t),this._clipViewport||(e=-s.width,t=-s.height);const i=s.x+s.width-1,n=s.y+s.height-1;e<0&&s.x+e<0&&(e=-s.x),i+e>=this._fbWidth&&(e-=i+e-this._fbWidth+1),s.y+t<0&&(t=-s.y),n+t>=this._fbHeight&&(t-=n+t-this._fbHeight+1),!(e===0&&t===0)&&C("viewportChange deltaX: "+e+", deltaY: "+t)}viewportChangeSize(e,t){(!this._clipViewport&&this._screens.length===1||typeof e>"u"||typeof t>"u")&&(C("Setting viewport to full display region"),e=this._fbWidth,t=this._fbHeight),e=Math.floor(e),t=Math.floor(t),e>this._fbWidth&&(e=this._fbWidth),t>this._fbHeight&&(t=this._fbHeight);const s=this._screens[0],i=this._target;if(i.width!==e||i.height!==t){let n=null;i.width>0&&i.height>0&&(n=this._targetCtx.getImageData(0,0,i.width,i.height)),s.serverWidth=e,s.serverHeight=t,i.width=e,i.height=t,n&&this._targetCtx.putImageData(n,0,0),this.viewportChangePos(0,0),this._rescale(this._scale)}
1}absX(e){return this._scale===0?0:Me(e/this._scale+this._screens[0].x)}absY(e){return this._scale===0?0:Me(e/this._scale+this._screens[0].y)}resize(e,t){this._prevDrawStyle="",this._fbWidth=e,this._fbHeight=t;let s=this._backbuffer;if(s==null)return;if(this._screens.length>0&&(e=this._screens[0].serverWidth,t=this._screens[0].serverHeight),s.width!==e||s.height!==t){let n=null;s.width>0&&s.height>0&&(n=this._drawCtx.getImageData(0,0,s.width,s.height)),s.width!==e&&(s.width=e),s.height!==t&&(s.height=t),n&&this._drawCtx.putImageData(n,0,0)}const i=this._screens[0];this.viewportChangeSize(i.serverWidth,i.serverHeight),this.viewportChangePos(0,0)}flip(e,t){this._asyncRenderQPush({type:"flip",frame_id:e,rect_cnt:t,screenLocations:[{screenIndex:0,x:0,y:0}]})}pending(){return this._asyncFrameQueue[this._maxAsyncFrameQueue-1][0]>0}flush(e=!0){this._asyncFrameComplete(0,!0),e&&this.onflush()}clear(){this._clearAsyncQueue()}dispose(){clearInterval(this._frameStatsInterval),this.clear()}fillRect(e,t,s,i,n,r,a){if(a)this._setFillColor(n),this._enableCanvasBuffer?this._drawCtx.fillRect(e,t,s,i):this._targetCtx.fillRect(e,t,s,i);else{let o={type:"fill",x:e,y:t,width:s,height:i,color:n,frame_id:r};this._processRectScreens(o),this._asyncRenderQPush(o)}}copyImage(e,t,s,i,n,r,a,o){if(o){let h=this._enableCanvasBuffer?this._drawCtx:this._targetCtx,u=this._enableCanvasBuffer?this._backbuffer:this._target;h.mozImageSmoothingEnabled=!1,h.webkitImageSmoothingEnabled=!1,h.msImageSmoothingEnabled=!1,h.imageSmoothingEnabled=!1,h.drawImage(u,e,t,n,r,s,i,n,r)}else{let h={type:"copy",oldX:e,oldY:t,x:s,y:i,width:n,height:r,frame_id:a};this._processRectScreens(h),this._asyncRenderQPush(h)}}_handleVidChunk(e,t){let s=e[0],i=e[1];e[2].close(),s.img=t.image,i._asyncRenderQPush(s)}imageRect(e,t,s,i,n,r,a){if(s===0||i===0)return;if(typeof ImageDecoder<"u"&&this._threading){let h=new ImageDecoder({data:r,type:n}),u={type:"vid",img:null,x:e,y:t,width:s,height:i,frame_id:a,mime:n};this._processRectScreens(u),h.decode().then(this._handleVidChunk.bind(null,[u,this,h]));return}let o={type:"img",img:null,x:e,y:t,width:s,height:i,frame_id:a};if(this._processRectScreens(o),o.inPrimary){const h=new Image;h.src="data: "+n+";base64,"+Qt.encode(r),o.img=h}else o.type="_img";o.inSecondary&&(o.mime=n,o.src="data: "+n+";base64,"+Qt.encode(r)),this._asyncRenderQPush(o)}transparentRect(e,t,s,i,n,r,a){if(!(s===0||i===0)){var o={type:"transparent",img:null,x:e,y:t,width:s,height:i,frame_id:r,arr:n,hash_id:a};this._processRectScreens(o),o.inPrimary&&createImageBitmap(n).then(function(u){this._transparentOverlayImg=u,this.enableCanvasBuffer=!0}.bind(this)),this._transparentOverlayRect=o,this._asyncRenderQPush(o)}}dummyRect(e,t,s,i,n){let r={type:"dummy",img:null,x:e,y:t,width:s,height:i,frame_id:n};this._processRectScreens(r),this._asyncRenderQPush(r)}blitImage(e,t,s,i,n,r,a,o){if(o){var u;ArrayBuffer.isView(n)?u=new Uint8ClampedArray(n.buffer,n.byteOffset+r,s*i*4):u=new Uint8ClampedArray(n,n.length+r,s*i*4);let _=new ImageData(u,s,i);this._enableCanvasBuffer?this._drawCtx.putImageData(_,e,t):this._targetCtx.putImageData(_,e,t)}else{var h;ArrayBuffer.isView(n)?h=n.buffer:h=n;const _=new Uint8Array(s*i*4);_.set(new Uint8Array(h,0,_.length));let w={type:"blit",data:_,x:e,y:t,width:s,height:i,frame_id:a};this._processRectScreens(w),this._asyncRenderQPush(w)}}blitQoi(e,t,s,i,n,r,a,o){if(o)this._enableCanvasBuffer?this._drawCtx.putImageData(n,e,t):this._targetCtx.putImageData(n,e,t);else{let h={type:"blitQ",data:n,x:e,y:t,width:s,height:i,frame_id:a};this._processRectScreens(h),this._asyncRenderQPush(h)}}drawImage(e,t,s,i,n,r=!1){try{let a=this._enableCanvasBuffer&&!r?this._drawCtx:this._targetCtx;e.width!=i||e.height!=n?a.drawImage(e,t,s,i,n):a.drawImage(e,t,s)}catch{Q("Invalid image recieved.")}}autoscale(e,t,s=0){if(e===0||t===0)s=0;else if(s===0){const i=this._screens[0],n=e/t;i.width/i.height>=n?s=e/i.serverWidth:s=t/i.serverHeight}this._rescale(s)}_writeCtxBuffer(){this._backbuffer.width>0&&this._targetCtx.drawImage(this._backbuffer,0,0)}_handleSecondaryDisplayMessage(e){if(!this._isPrimaryDisplay&&e.data)switch(e.data.eventType){case"re
1ct":let t=e.data.rect;switch(t.screenLocations=[t.screenLocations[e.data.screenLocationIndex]],t.screenLocations[0].screenIndex=0,t.type){case"img":t.img=new Image,t.img.src=t.src;break;case"_img":t.img=new Image,t.img.src=t.src,t.type="img";break;case"transparent":createImageBitmap(t.arr).then(function(i){this._transparentOverlayImg=i,this.enableCanvasBuffer||(this._enableCanvasBuffer=!0)}.bind(this)),this._transparentOverlayRect=t;break}this._syncFrameQueue.push(t),this._syncFrameQueue.length>5e3&&(this._syncFrameQueue.shift(),this._droppedRects++);break;case"frameComplete":window.requestAnimationFrame(()=>{this._pushSyncRects()});break;case"registered":this._isPrimaryDisplay||(this._screens[0].screenIndex=e.data.screenIndex,I(`Screen with index (${e.data.screenIndex}) successfully registered with the primary display.`),this._screens.length>0&&this.resize(this._screens[0].serverWidth,this._screens[0].serverHeight));break}}_pushSyncRects(){let e=0;e:for(;this._syncFrameQueue.length>0;){const t=this._syncFrameQueue[0],s=t.screenLocations[0];switch(t.type){case"copy":this.copyImage(s.oldX,s.oldY,s.x,s.y,t.width,t.height,t.frame_id,!0);break;case"fill":this.fillRect(s.x,s.y,t.width,t.height,t.color,t.frame_id,!0);break;case"blit":this.blitImage(s.x,s.y,t.width,t.height,t.data,0,t.frame_id,!0);break;case"blitQ":this.blitQoi(s.x,s.y,t.width,t.height,t.data,0,t.frame_id,!0);break;case"img":if(t.img.complete)this.drawImage(t.img,s.x,s.y,t.width,t.height);else if(this._syncFrameQueue.length>5e3)this._syncFrameQueue.shift(),this._droppedRects++;else break e;break;case"vid":this.drawImage(t.img,s.x,s.y,t.width,t.height),t.img.close();break;default:this._syncFrameQueue.shift();continue}e++,this._syncFrameQueue.shift()}this._enableCanvasBuffer&&e>0&&(this._writeCtxBuffer(),this._transparentOverlayImg&&this.drawImage(this._transparentOverlayImg,this._transparentOverlayRect.x,this._transparentOverlayRect.y,this._transparentOverlayRect.width,this._transparentOverlayRect.height,!0)),this._syncFrameQueue.length>0&&window.requestAnimationFrame(()=>{this._pushSyncRects()})}_flushRectsScreen(e){for(let t=0;t<this._asyncFrameQueue.length;t++){const s=this._asyncFrameQueue[t];for(let i=0;i<s[2].length;i++){const n=s[2][i];for(let r=0;r<n.screenLocations.length;r++)if(n.screenLocations[r].screenIndex===e){n.screenLocations.splice(r,1);break}}}}_asyncRenderQPush(e){let t=-1,s=Number.MAX_SAFE_INTEGER,i=0;for(let n=0;n<this._asyncFrameQueue.length;n++){if(e.frame_id==this._asyncFrameQueue[n][0]){this._asyncFrameQueue[n][2].push(e),t=n;break}else if(this._asyncFrameQueue[n][0]==0){let r=e.type=="flip"?e.rect_cnt:0;this._asyncFrameQueue[n][0]=e.frame_id,this._asyncFrameQueue[n][2].push(e),this._asyncFrameQueue[n][3]=r==1,t=n;break}s=Math.min(s,this._asyncFrameQueue[n][0]),i=Math.max(i,this._asyncFrameQueue[n][0])}if(this._firstRect||(this._firstRect=!0,I("First rect received.")),t>=0)e.type=="flip"&&(this._asyncFrameQueue[t][1]!==0&&H("Redundant flip rect, current rect_cnt: "+this._asyncFrameQueue[t][1]+", new rect_cnt: "+e.rect_cnt),this._asyncFrameQueue[t][1]+=e.rect_cnt,e.rect_cnt==0&&H("Invalid rect count")),this._asyncFrameQueue[t][1]>0&&this._asyncFrameQueue[t][2].length>=this._asyncFrameQueue[t][1]&&this._asyncFrameComplete(t);else if(e.frame_id<s){this._droppedRects++,e.type=="flip"&&this._lateFlipRect++;return}else if(e.frame_id>i){this._asyncFrameQueue[0][3]==!0?(H("Forced frame to canvas"),this._pushAsyncFrame(!0),this._droppedFrames+=e.frame_id-(i+1),this._forcedFrameCnt++):(H("Old frame dropped"),this._asyncFrameQueue.shift(),this._droppedFrames+=e.frame_id-i);let n=e.type=="flip"?e.rect_cnt:0;this._asyncFrameQueue.push([e.frame_id,n,[e],n==1,0,0])}}_clearAsyncQueue(){this._droppedFrames+=this._asyncFrameQueue.length,this._asyncFrameQueue=[];for(let e=0;e<this._maxAsyncFrameQueue;e++)this._asyncFrameQueue.push([0,0,[],!1,0,0])}_asyncFrameComplete(e,t=!1){if(e>=this._asyncFrameQueue.length)return;let s=this._asyncFrameQueue[e][4];if(t)for(this._asyncFrameQueue[e][1]==0?this._missingFlipRect++:this._asyncFrameQueue[e][1]!==this._asyncFrameQueue[e][2].length&&(this._droppedRects+=this._asyncFrameQueue[e][1]-this._asyncFrameQueue[e][2].length,this._asyncFrameQueue[e][2].length>this._asyncFrameQueue[e][1]&&H("Frame has more rects than the reported rect_cnt."));s<this._asyncFrameQueue[e][2].length;)this._asyncFrameQueue[e][2][s].type=="img"&&this._asyncFrameQueue[e][2][s].img&&!this._asyncFrameQueue[e][2][s].img.complete&&(this._asyncFrameQueue[e][2][s].type="skip",this._droppedRects++),s++;else for(;s<this._asyncFrameQueue[e][2].length;){if(this._asyncFrameQueue[e][2][s].type=="img"&&!this._asyncFrameQueue[e][2][s].img.complete){this._asyncFrameQueue[e][2][s].img.addEventListener("load",()=>{this._asyncFrameComplete(e)}),this._asyncFrameQueue[e][4]=s;return}s++}this._asyncFrameQueue[e][4]=s,this._asyncFrameQueue[e][3]=!0,t&&e==0?this._pushAsyncFrame(!0):window.requestAnimationFrame(()=>{this._pushAsyncFrame()})}_pushAsyncFrame(e=!1){if(this._asyncFrameQueue[0][3]||e){let t=this._asyncFrameQueue[0][2],s=this._asyncFrameQueue.shift()[0];this._asyncFrameQueue.length<this._maxAsyncFrameQueue&&this._asyncFrameQueue.push([0,0,[],!1,0,0]);let i=0,n=0;for(let r=0;r<t.length;r++){const a=t[r];for(let o=0;o<a.screenLocations.length;o++){let h=a.screenLocations[o];if(h.screenIndex==0){switch(a.type){case"copy":this.copyImage(h.oldX,h.oldY,h.x,h.y,a.width,a.height,a.frame_id,!0);break;case"fill":this.fillRect(h.x,h.y,a.width,a.height,a.color,a.frame_id,!0);break;case"blit":this.blitImage(h.x,h.y,a.width,a.height,a.data,0,a.frame_id,!0);break;case"blitQ":this.blitQoi(h.x,h.y,a.width,a.height,a.data,0,a.frame_id,!0);break;case"img":this.drawImage(a.img,h.x,h.y,a.width,a.height);break;case"vid":this.drawImage(a.img,h.x,h.y,a.width,a.height);break;default:continue}n++}else switch(a.type){case"dummy":case"transparent":case"flip":break;case"vid":i++,this._screens[h.screenIndex].channel&&this._screens[h.screenIndex].channel.postMessage({eventType:"rect",rect:{type:"vid",img:a.img,x:a.x,y:a.y,width:a.width,height:a.height,frame_id:a.frame_id,screenLocations:a.screenLocations},screenLocationIndex:o},[a.img]);break;case"blit":i++;let u=a.data.buffer;this._screens[h.screenIndex].channel&&this._screens[h.screenIndex].channel.postMessage({eventType:"rect",rect:{type:"blit",img:null,data:u,x:a.x,y:a.y,width:a.width,height:a.height,frame_id:a.frame_id,screenLocations:a.screenLocations},screenLocationIndex:o},[u]);break;case"img":i++,this._screens[h.screenIndex].channel&&this._screens[h.screenIndex].channel.postMessage({eventType:"rect",rect:{type:"img",img:null,x:a.x,y:a.y,width:a.width,height:a.height,frame_id:a.frame_id,screenLocations:a.screenLocations,src:a.src},screenLocationIndex:o});break;default:i++,this._screens[h.screenIndex].channel&&this._screens[h.screenIndex].channel.postMessage({eventType:"rect",rect:a,screenLocationIndex:o})}}}if(this._enableCanvasBuffer&&(n>0&&this._writeCtxBuffer(),this._transparentOverlayImg)){if(n>0&&this.drawImage(this._transparentOverlayImg,this._transparentOverlayRect.x,this._transparentOverlayRect.y,this._transparentOverlayRect.width,this._transparentOverlayRect.height,!0),i>0&&this._lastTransparentRectId!==this._transparentOverlayRect.hash_id)for(let r=1;r<this._transparentOverlayRect.screenLocations.length;r++)this._screens[this._transparentOverlayRect.screenLocations[r].screenIndex].channel&&this._screens[this._transparentOverlayRect.screenLocations[r].screenIndex].channel.postMessage({eventType:"rect",rect:this._transparentOverlayRect,screenLocationIndex:r});this._lastTransparentRectId=this._transparentOverlayRect.hash_id}if(i>0)for(let r=1;r<this.screens.length;r++)this._screens[r].channel&&this._screens[r].channel.postMessage({eventType:"frameComplete",frameId:s,rectCnt:i});this._flipCnt+=1,this._flushing&&(this._flushing=!1,this.onflush()),this._asyncFrameQueue[0][2].length>0&&window.requestAnimationFrame(()=>{this._pushAsyncFrame()})}else this._asyncFrameQueue[0][1]>0&&this._asyncFrameQueue[0][1]==this._asyncFrameQueue[0][2].length&&(this._asyncFrameQueue[0][5]+=1,this._asyncFrameQueue[0][5]>5&&this._pushAsyncFrame(!0))}_processRectScreens(e){let t=[];e.inPrimary=!1,e.inSecondary=!1;for(let s=0;s<this._screens.length;s++){let i=this._screens[s];if(!((e.x>i.x2||i.x>e.x+e.width)&&(e.y>i.y2||i.y>e.y+e.height))){let n={x:0-(i.x-e.x),y:0-(i.y-e.y),screenIndex:s};e.type==="copy"&&(n.oldX=0-(i.x-e.oldX),n.oldY=0-(i.y-e.oldY)),t.push(n),s==0?e.inPrimary=!0:e.inSecondary=!0}}e.screenLocations=t}_rescale(e){this._scale=e;const t=this._screens[0],s=e*t.serverWidth+"px",i=e*t.serverHeight+"px";(this._target.style.width!==s||this._target.style.height!==i)&&(this._target.style.width=s,this._target.style.height=i),I("Pixel Ratio: "+window.devicePixelRatio+", VNC Scale: "+e+"VNC Res: "+t.serverWidth+"x"+t.serverHeight);var n=Math.abs(Math.ceil(window.devicePixelRatio)),r=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;this.antiAliasing===2||this.antiAliasing===0&&e===1&&this._target.style.imageRendering!=="pixelated"&&n===window.devicePixelRatio&&t.width>0?(this._target.style.imageRendering=r?"crisp-edges":"pixelated",C("Smoothing disabled")):(this.antiAliasing===1||this.antiAliasing===0&&e!==1&&this._target.style.imageRendering!=="auto")&&(this._target.style.imageRendering="auto",C("Smoothing enabled"))}_setFillColor(e){const t="rgb("+e[0]+","+e[1]+","+e[2]+")";let s=this._enableCanvasBuffer?this._drawCtx:this._targetCtx;t!==this._prevDrawStyle&&(s.fillStyle=t,this._prevDrawStyle=t)}}class Ge{constructor(){this.strm=new es,this.chunkSize=1024*10*10,this.strm.output=new Uint8Array(this.chunkSize),this.windowBits=5,As(this.strm,this.windowBits)}setInput(e){e?(this.strm.input=e,this.strm.avail_in=this.strm.input.length,this.strm.next_in=0):(this.strm.input=null,this.strm.avail_in=0,this.strm.next_in=0)}inflate(e){if(e>this.chunkSize&&(this.chunkSize=e,this.strm.output=new Uint8Array(this.chunkSize)),this.strm.next_out=0,this.strm.avail_out=e,Is(this.strm,0)<0)throw new Error("zlib inflate failed");if(this.strm.next_out!=e)throw new Error("Incomplete zlib block, got "+this.strm.next_out+" expected "+e);return new Uint8Array(this.strm.output.buffer,0,this.strm.next_out)}reset(){Ts(this.strm)}}class zi{constructor(){this.strm=new es,this.chunkSize=1024*10*10,this.outputBuffer=new Uint8Array(this.chunkSize),this.windowBits=5,Ps(this.strm,this.windowBits)}deflate(e){this.strm.input=e,this.strm.avail_in=this.strm.input.length,this.strm.next_in=0,this.strm.output=this.outputBuffer,this.strm.avail_out=this.chunkSize,this.strm.next_out=0;let t=kt(this.strm,Ft.Z_FULL_FLUSH),s=new Uint8Array(this.strm.output.buffer,0,this.strm.next_out);if(t<0)throw new Error("zlib deflate failed");if(this.strm.avail_in>0){let i=[s],n=s.length;do{if(this.strm.output=new Uint8Array(this.chunkSize),this.strm.next_out=0,this.strm.avail_out=this.chunkSize,t=kt(this.strm,Ft.Z_FULL_FLUSH),t<0)throw new Error("zlib deflate failed");let o=new Uint8Array(this.strm.output.buffer,0,this.strm.next_out);n+=o.length,i.push(o)}while(this.strm.avail_in>0);let r=new Uint8Array(n),a=0;for(let o=0;o<i.length;o++)r.set(i[o],a),a+=i[o].length;s=r}return this.strm.input=null,this.strm.avail_in=0,this.strm.next_in=0,s}}const at={DOCUMENT_START:0,DOCUMENT_CHUNK:1,DOCUMENT_END:2},Wi=async c=>{const e=document.createElement("iframe");e.style.display="none",document.body.appendChild(e),e.onload=()=>{setTimeout(()=>{e.focus(),e.contentWindow.print()},1)};const t=new Blob([new Uint8Array(c)],{type:"application/pdf"});e.src=URL.createObjectURL(t)},Gi=c=>{let e=0,t=0,s=[];const i=n=>{const r=Array.from(n),a=new Uint8Array(r).buffer,o=new DataView(a);switch(o.getUint32(0,!1)){case at.DOCUMENT_START:e=o.getUint32(4,!1),t=0;break;case at.DOCUMENT_CHUNK:let u=o.getUint32(4,!1),_=new Uint8Array(a,8);t+=u,s.push(..._);break;case at.DOCUMENT_END:Wi(s),t=0,e=0;break;default:break}};c.subscribeUnixRelay("printer",i)},ee=0,Dt=1,Lt=2,At=4,It=8,ot=16,Ce=32,Se=64,Be=128,ht=127,ct=50,Yi=90,Tt=250,ji=500,qi=500,$i=50;class Zi{constructor(){this._target=null,this._state=ht,this._tracked=[],this._ignored=[],this._waitingRelease=!1,this._releaseStart=0,this._longpressTimeoutId=null,this._twoTouchTimeoutId=null,this._boundEventHandler=this._eventHandler.bind(this),this._isDrag=!1}attach(e){this.detach(),this._target=e,this._target.addEventListener("touchstart",this._boundEventHandler),this._target.addEventListener("touchmove",this._boundEventHandler),this._target.addEventListener("touchend",this._boundEventHandler),this._target.addEventListener("touchcancel",this._boundEventHandler)}detach(){this._target&&(this._stopLongpressTimeout(),this._stopTwoTouchTimeout(),this._target.removeEventListener("touchstart",this._boundEventHandler),this._target.removeEventListener("touchmove",this._boundEventHandler),this._target.removeEventListener("touchend",this._boundEventHandler),this._target.removeEventListener("touchcancel",this._boundEventHandler),this._target=null)}_eventHandler(e){let t;switch(e.stopPropagation(),e.preventDefault(),e.type){case"touchstart":t=this._touchStart;break;case"touchmove":t=this._touchMove;break;case"touchend":case"touchcancel":t=this._touchEnd;break}for(let s=0;s<e.changedTouches.length;s++){let i=e.changedTouches[s];t.call(this,i.identifier,i.clientX,i.clientY)}}_touchStart(e,t,s){if(this._hasDetectedGesture()||this._state===ee){this._ignored.push(e);return}if(this._tracked.length>0&&Date.now()-this._tracked[0].started>Tt){this._state=ee,this._ignored.push(e);return}if(this._waitingRelease){this._state=ee,this._ignored.push(e);return}switch(this._tracked.push({id:e,started:Date.now(),active:!0,firstX:t,firstY:s,lastX:t,lastY:s,angle:0}),this._tracked.length){case 1:this._startLongpressTimeout();break;case 2:this._state&=-154,this._stopLongpressTimeout();break;case 3:this._state&=-99;break;default:this._state=ee}}_touchMove(e,t,s){let i=this._tracked.find(a=>a.id===e);if(i===void 0)return;i.lastX=t,i.lastY=s;let n=t-i.firstX,r=s-i.firstY;if((i.firstX!==i.lastX||i.firstY!==i.lastY)&&(i.angle=Math.atan2(r,n)*180/Math.PI),!this._hasDetectedGesture()){if(Math.hypot(n,r)<ct)return;if(this._state&=-24,this._stopLongpressTimeout(),this._tracked.length!==1&&(this._state&=-137),this._tracked.length!==2&&(this._state&=-97),this._tracked.length===1&&(this._isDrag?this._state=It:this._state=Be),this._tracked.length===2){let a=this._tracked.find(h=>h.id!==e);if(Math.hypot(a.firstX-a.lastX,a.firstY-a.lastY)>ct){let h=Math.abs(i.angle-a.angle);h=Math.abs((h+180)%360-180),h>Yi?this._state&=~Ce:this._state&=~Se,this._isTwoTouchTimeoutRunning()&&this._stopTwoTouchTimeout()}}if(!this._hasDetectedGesture())return;this._pushEvent("gesturestart")}this._pushEvent("gesturemove")}_touchEnd(e,t,s){if(this._ignored.indexOf(e)!==-1){this._ignored.splice(this._ignored.indexOf(e),1),this._ignored.length===0&&this._tracked.length===0&&(this._state=ht,this._waitingRelease=!1);return}if(!this._hasDetectedGesture()&&this._isTwoTouchTimeoutRunning()&&(this._stopTwoTouchTimeout(),this._state=ee),!this._hasDetectedGesture()&&
1(this._state&=-233,this._state&=~ot,this._stopLongpressTimeout(),!this._waitingRelease))switch(this._releaseStart=Date.now(),this._waitingRelease=!0,this._tracked.length){case 1:this._state&=-7;break;case 2:this._state&=-6;break}let i=this._tracked.find(n=>n.id===e);if(this._waitingRelease){if(Date.now()-this._releaseStart>Tt&&(this._state=ee),this._tracked.some(n=>Date.now()-n.started>ji)&&(this._state=ee),i.active=!1,this._hasDetectedGesture())this._pushEvent("gesturestart");else if(this._state!==ee)return}!this._hasDetectedGesture()&&Math.hypot(t-i.firstX,s-i.firstY)<ct&&(this._state=ot,this._pushEvent("gesturestart")),this._hasDetectedGesture()&&this._pushEvent("gestureend");for(let n=0;n<this._tracked.length;n++)this._tracked[n].active&&this._ignored.push(this._tracked[n].id);this._tracked=[],this._state=ee,this._ignored.indexOf(e)!==-1&&this._ignored.splice(this._ignored.indexOf(e),1),this._ignored.length===0&&(this._state=ht,this._waitingRelease=!1)}_hasDetectedGesture(){return!(this._state===ee||this._state&this._state-1||this._state&(Dt|Lt|At)&&this._tracked.some(e=>e.active))}_startLongpressTimeout(){this._stopLongpressTimeout(),this._longpressTimeoutId=setTimeout(()=>this._longpressTimeout(),qi)}_stopLongpressTimeout(){clearTimeout(this._longpressTimeoutId),this._longpressTimeoutId=null}_longpressTimeout(){if(this._hasDetectedGesture())throw new Error("A longpress gesture failed, conflict with a different gesture");this._isDrag=!0,this._target.dispatchEvent(new CustomEvent("drag_cb",{})),this._pushEvent("gesturestart"),this._pushEvent("gesturemove")}_startTwoTouchTimeout(){this._stopTwoTouchTimeout(),this._twoTouchTimeoutId=setTimeout(()=>this._twoTouchTimeout(),$i)}_stopTwoTouchTimeout(){clearTimeout(this._twoTouchTimeoutId),this._twoTouchTimeoutId=null}_isTwoTouchTimeoutRunning(){return this._twoTouchTimeoutId!==null}_twoTouchTimeout(){if(this._tracked.length===0)throw new Error("A pinch or two drag gesture failed, no tracked touches");let e=this._getAverageMovement(),t=Math.abs(e.x),s=Math.abs(e.y),i=this._getAverageDistance(),n=Math.abs(Math.hypot(i.first.x,i.first.y)-Math.hypot(i.last.x,i.last.y));s<n&&t<n?this._state=Se:this._state=Ce,this._pushEvent("gesturestart"),this._pushEvent("gesturemove")}_pushEvent(e){let t={type:this._stateToGesture(this._state)},s=this._getPosition(),i=s.last;switch(e==="gesturestart"&&(i=s.first),this._state){case Be:case Ce:case Se:i=s.first;break}if(t.clientX=i.x,t.clientY=i.y,this._state===Se){let r=this._getAverageDistance();e==="gesturestart"?(t.magnitudeX=r.first.x,t.magnitudeY=r.first.y):(t.magnitudeX=r.last.x,t.magnitudeY=r.last.y)}else if(this._state===Ce||this._state===Be)if(e==="gesturestart")t.magnitudeX=0,t.magnitudeY=0;else{let r=this._getAverageMovement();t.magnitudeX=r.x,t.magnitudeY=r.y}let n=new CustomEvent(e,{detail:t});this._target.dispatchEvent(n),this._isDrag=!1}_stateToGesture(e){switch(e){case Dt:return"onetap";case Lt:return"twotap";case At:return"threetap";case It:return"drag";case ot:return"longpress";case Ce:return"twodrag";case Se:return"pinch";case Be:return"swipe"}throw new Error("Unknown gesture state: "+e)}_getPosition(){if(this._tracked.length===0)throw new Error("Failed to get gesture position, no tracked touches");let e=this._tracked.length,t=0,s=0,i=0,n=0;for(let r=0;r<this._tracked.length;r++)t+=this._tracked[r].firstX,s+=this._tracked[r].firstY,i+=this._tracked[r].lastX,n+=this._tracked[r].lastY;return{first:{x:t/e,y:s/e},last:{x:i/e,y:n/e}}}_getAverageMovement(){if(this._tracked.length===0)throw new Error("Failed to get gesture movement, no tracked touches");let e,t;e=t=0;let s=this._tracked.length;for(let i=0;i<this._tracked.length;i++)e+=this._tracked[i].lastX-this._tracked[i].firstX,t+=this._tracked[i].lastY-this._tracked[i].firstY;return{x:e/s,y:t/s}}_getAverageDistance(){if(this._tracked.length===0)throw new Error("Failed to get gesture distance, no tracked touches");let e=this._tracked[0],t=this._tracked[this._tracked.length-1],s=Math.abs(t.firstX-e.firstX),i=Math.abs(t.firstY-e.firstY),n=Math.abs(t.lastX-e.lastX),r=Math.abs(t.lastY-e.lastY);return{first:{x:s,y:i},last:{x:n,y:r}}}}const me=!Ei||ts,Pt=["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange"];class Ji{constructor(){this._target=null,this._canvas=document.createElement("canvas"),this._canvas.style.position="fixed",this._canvas.style.zIndex="65535",this._canvas.style.pointerEvents="none",this._canvas.style.visibility="hidden",this._useFallback=me,this._position={x:0,y:0},this._hotSpot={x:0,y:0},this._eventHandlers={mouseover:this._handleMouseOver.bind(this),mouseleave:this._handleMouseLeave.bind(this),mousemove:this._handleMouseMove.bind(this),mouseup:this._handleMouseUp.bind(this),fullscreenchange:this._updateCanvasParent.bind(this)}}attach(e){if(this._target&&this.detach(),this._target=e,document.body.appendChild(this._canvas),Pt.forEach(t=>{document.addEventListener(t,this._eventHandlers.fullscreenchange)}),this._updateCanvasParent(),me){const t={capture:!0,passive:!0};this._target.addEventListener("mouseover",this._eventHandlers.mouseover,t),this._target.addEventListener("mouseleave",this._eventHandlers.mouseleave,t),this._target.addEventListener("mousemove",this._eventHandlers.mousemove,t),this._target.addEventListener("mouseup",this._eventHandlers.mouseup,t)}this.clear()}detach(){if(this._target){if(me){const e={capture:!0,passive:!0};this._target.removeEventListener("mouseover",this._eventHandlers.mouseover,e),this._target.removeEventListener("mouseleave",this._eventHandlers.mouseleave,e),this._target.removeEventListener("mousemove",this._eventHandlers.mousemove,e),this._target.removeEventListener("mouseup",this._eventHandlers.mouseup,e)}
1Pt.forEach(e=>{document.removeEventListener(e,this._eventHandlers.fullscreenchange)}),this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas),this._target=null}}change(e,t,s,i,n){if(i===0||n===0){this.clear();return}this._position.x=this._position.x+this._hotSpot.x-t,this._position.y=this._position.y+this._hotSpot.y-s,this._hotSpot.x=t,this._hotSpot.y=s;let r=this._canvas.getContext("2d");this._canvas.width=i,this._canvas.height=n;let a=new ImageData(new Uint8ClampedArray(e),i,n);if(r.clearRect(0,0,i,n),r.putImageData(a,0,0),(this._useFallback||me)&&this._updatePosition(),!me){let o=this._canvas.toDataURL();this._target.style.cursor="url("+o+")"+t+" "+s+", default"}}clear(){this._target.style.cursor="none",this._canvas.width=0,this._canvas.height=0,this._position.x=this._position.x+this._hotSpot.x,this._position.y=this._position.y+this._hotSpot.y,this._hotSpot.x=0,this._hotSpot.y=0}move(e,t){if(!this._useFallback)return;window.visualViewport?(this._position.x=e+window.visualViewport.offsetLeft,this._position.y=t+window.visualViewport.offsetTop):(this._position.x=e,this._position.y=t),this._updatePosition();let s=document.elementFromPoint(e,t);this._updateVisibility(s)}setEmulateCursor(e){me||(this._useFallback=e,this._useFallback?this._showCursor():this._hideCursor())}_handleMouseOver(e){this._handleMouseMove(e)}_handleMouseLeave(e){this._updateVisibility(e.relatedTarget)}_handleMouseMove(e){this._updateVisibility(e.target),this._position.x=e.clientX-this._hotSpot.x,this._position.y=e.clientY-this._hotSpot.y,this._updatePosition()}_handleMouseUp(e){let t=document.elementFromPoint(e.clientX,e.clientY);this._updateVisibility(t),this._captureIsActive()&&window.setTimeout(()=>{this._target&&(t=document.elementFromPoint(e.clientX,e.clientY),this._updateVisibility(t))},0)}_showCursor(){this._canvas.style.visibility==="hidden"&&(this._canvas.style.visibility="")}_hideCursor(){this._canvas.style.visibility!=="hidden"&&(this._canvas.style.visibility="hidden")}_shouldShowCursor(e){return e?e===this._target?!0:!(!this._target.contains(e)||window.getComputedStyle(e).cursor!=="none"):!1}_updateVisibility(e){this._captureIsActive()&&(e=document.captureElement),this._shouldShowCursor(e)?this._showCursor():this._hideCursor()}_updatePosition(){this._canvas.style.left=this._position.x+"px",this._canvas.style.top=this._position.y+"px"}_updateCanvasParent(){if(!this._target)return;const e=document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement,t=e&&e.contains(this._target)?e:document.body;this._canvas.parentNode!==t&&t.appendChild(this._canvas)}_captureIsActive(){return document.captureElement&&document.documentElement.contains(document.captureElement)}}const lt=40*1024*1024,Ut={CONNECTING:"connecting",OPEN:"open"},He={CONNECTING:[WebSocket.CONNECTING,Ut.CONNECTING],OPEN:[WebSocket.OPEN,Ut.OPEN]},Bt=["send","close","binaryType","onerror","onmessage","onopen","protocol","readyState"];class en{constructor(){this._websocket=null,this._rQi=0,this._rQlen=0,this._rQbufferSize=1024*1024*4,this._rQ=null,this._sQbufferSize=1024*10,this._sQlen=0,this._sQ=null,this._eventHandlers={message:()=>{},open:()=>{},close:()=>{},error:()=>{}}}get sQ(){return this._sQ}get rQ(){return this._rQ}get rQi(){return this._rQi}set rQi(e){this._rQi=e}get rQlen(){return this._rQlen-this._rQi}rQpeek8(){return this._rQ[this._rQi]}rQskipBytes(e){this._rQi+=e}rQshift8(){return this._rQshift(1)}rQshift16(){return this._rQshift(2)}rQshift32(){return this._rQshift(4)}_rQshift(e){let t=0;for(let s=e-1;s>=0;s--)t+=this._rQ[this._rQi++]<<s*8;return t}rQshiftStr(e){typeof e>"u"&&(e=this.rQlen);let t="";for(let s=0;s<e;s+=4096){let i=this.rQshiftBytes(Math.min(4096,e-s));t+=String.fromCharCode.apply(null,i)}return t}rQshiftBytes(e){return typeof e>"u"&&(e=this.rQlen),this._rQi+=e,new Uint8Array(this._rQ.buffer,this._rQi-e,e)}rQshiftTo(e,t){t===void 0&&(t=this.rQlen),e.set(new Uint8Array(this._rQ.buffer,this._rQi,t)),this._rQi+=t}rQslice(e,t=this.rQlen){return new Uint8Array(this._rQ.buffer,this._rQi+e,t-e)}
1rQwait(e,t,s){if(this.rQlen<t){if(s){if(this._rQi<s)throw new Error("rQwait cannot backup "+s+" bytes");this._rQi-=s}return!0}return!1}flush(){this._sQlen>0&&He.OPEN.indexOf(this._websocket.readyState)>=0&&(this._websocket.send(this._encodeMessage()),this._sQlen=0)}send(e){this._sQ.set(e,this._sQlen),this._sQlen+=e.length,this.flush()}sendString(e){this.send(e.split("").map(t=>t.charCodeAt(0)))}off(e){this._eventHandlers[e]=()=>{}}on(e,t){this._eventHandlers[e]=t}_allocateBuffers(){this._rQ=new Uint8Array(this._rQbufferSize),this._sQ=new Uint8Array(this._sQbufferSize)}init(){this._allocateBuffers(),this._rQi=0,this._websocket=null}open(e,t){this.attach(new WebSocket(e,t))}attach(e){this.init();const t=[...Object.keys(e),...Object.getOwnPropertyNames(Object.getPrototypeOf(e))];for(let n=0;n<Bt.length;n++){const r=Bt[n];if(t.indexOf(r)<0)throw new Error("Raw channel missing property: "+r)}this._websocket=e,this._websocket.binaryType="arraybuffer",this._websocket.onmessage=this._recvMessage.bind(this);const s=()=>{C(">> WebSock.onopen"),this._websocket.protocol&&I("Server choose sub-protocol: "+this._websocket.protocol),this._eventHandlers.open(),C("<< WebSock.onopen")};He.OPEN.indexOf(this._websocket.readyState)>=0?s():this._websocket.onopen=s,this._websocket.onclose=n=>{C(">> WebSock.onclose"),this._eventHandlers.close(n),C("<< WebSock.onclose")},this._websocket.onerror=n=>{C(">> WebSock.onerror: "+n),this._eventHandlers.error(n),C("<< WebSock.onerror: "+n)}}close(){this._websocket&&((He.CONNECTING.indexOf(this._websocket.readyState)>=0||He.OPEN.indexOf(this._websocket.readyState)>=0)&&(I("Closing WebSocket connection"),this._websocket.close()),this._websocket.onmessage=()=>{})}_encodeMessage(){return new Uint8Array(this._sQ.buffer,0,this._sQlen)}_expandCompactRQ(e){const t=(this._rQlen-this._rQi+e)*8,s=this._rQbufferSize<t;if(s&&(this._rQbufferSize=Math.max(this._rQbufferSize*2,t)),this._rQbufferSize>lt&&(this._rQbufferSize=lt,this._rQbufferSize-this.rQlen<e))throw new Error("Receive Queue buffer exceeded "+lt+" bytes, and the new message could not fit");if(s){const i=this._rQ.buffer;this._rQ=new Uint8Array(this._rQbufferSize),this._rQ.set(new Uint8Array(i,this._rQi,this._rQlen-this._rQi))}else this._rQ.copyWithin(0,this._rQi,this._rQlen);this._rQlen=this._rQlen-this._rQi,this._rQi=0}_DecodeMessage(e){const t=new Uint8Array(e);t.length>this._rQbufferSize-this._rQlen&&this._expandCompactRQ(t.length),this._rQ.set(t,this._rQlen),this._rQlen+=t.length}_insertIntoMiddle(e){const t=new Uint8Array(e);t.length>this._rQbufferSize-this._rQlen&&this._expandCompactRQ(t.length),this._rQ.copyWithin(this._rQi+t.length,this._rQi,this._rQlen-this._rQi),this._rQ.set(t,this._rQi),this._rQlen+=t.length}_recvMessage(e){this._DecodeMessage(e.data),this.rQlen>0?(this._eventHandlers.message(),this._rQlen==this._rQi&&(this._rQlen=0,this._rQi=0)):C("Ignoring empty message")}}const Ht=[13,16,10,23,0,4,2,27,14,5,20,9,22,18,11,3,25,7,15,6,26,19,12,1,40,51,30,36,46,54,29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31],tn=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],l=0;let f,p,y,x,g,b;f=65536;p=1<<24;y=f|p;x=4;g=1024;b=x|g;const Nt=[y|g,l|l,f|l,y|b,y|x,f|b,l|x,f|l,l|g,y|g,y|b,l|g,p|b,y|x,p|l,l|x,l|b,p|g,p|g,f|g,f|g,y|l,y|l,p|b,f|x,p|x,p|x,f|x,l|l,l|b,f|b,p|l,f|l,y|b,l|x,y|l,y|g,p|l,p|l,l|g,y|x,f|l,f|g,p|x,l|g,l|x,p|b,f|b,y|b,f|x,y|l,p|b,p|x,l|b,f|b,y|g,l|b,p|g,p|g,l|l,f|x,f|g,l|l,y|x];f=1<<20;p=1<<31;y=f|p;x=32;g=32768;b=x|g;const Vt=[y|b,p|g,l|g,f|b,f|l,l|x,y|x,p|b,p|x,y|b,y|g,p|l,p|g,f|l,l|x,y|x,f|g,f|x,p|b,l|l,p|l,l|g,f|b,y|l,f|x,p|x,l|l,f|g,l|b,y|g,y|l,l|b,l|l,f|b,y|x,f|l,p|b,y|l,y|g,l|g,y|l,p|g,l|x,y|b,f|b,l|x,l|g,p|l,l|b,y|g,f|l,p|x,f|x,p|b,p|x,f|x,f|g,l|l,p|g,l|b,p|l,y|x,y|b,f|g];f=1<<17;p=1<<27;y=f|p;x=8;g=512;b=x|g;const Ot=[l|b,y|g,l|l,y|x,p|g,l|l,f|b,p|g,f|x,p|x,p|x,f|l,y|b,f|x,y|l,l|b,p|l,l|x,y|g,l|g,f|g,y|l,y|x,f|b,p|b,f|g,f|l,p|b,l|x,y|b,l|g,p|l,y|g,p|l,f|x,l|b,f|l,y|g,p|g,l|l,l|g,f|x,y|b,p|g,p|x,l|g,l|l,y|x,p|b,f|l,p|l,y|b,l|x,f|b,f|g,p|x,y|l,p|b,l|b,y|l,f|b,l|x,y|x,f|g];f=8192;p=1<<23;y=f|p;x=1;g=128;b=x|g;const zt=[y|x,f|b,f|b,l|g,y|g,p|b,p|x,f|x,l|l,y|l,y|l,y|b,l|b,l|l,p|g,p|x,l|x,f|l,p|l,y|x,l|g,p|l,f|x,f|g,p|b,l|x,f|g,p|g,f|l,y|g,y|b,l|b,p|g,p|x,y|l,y|b,l|b,l|l,l|l,y|l,f|g,p|g,p|b,l|x,y|x,f|b,f|b,l|g,y|b,l|b,l|x,f|l,p|x,f|x,y|g,p|b,f|x,f|g,p|l,y|x,l|g,p|l,f|l,y|g];f=1<<25;p=1<<30;y=f|p;x=256;g=1<<19;b=x|g;const Wt=[l|x,f|b,f|g,y|x,l|g,l|x,p|l,f|g,p|b,l|g,f|x,p|b,y|x,y|g,l|b,p|l,f|l,p|g,p|g,l|l,p|x,y|b,y|b,f|x,y|g,p|x,l|l,y|l,f|b,f|l,y|l,l|b,l|g,y|x,l|x,f|l,p|l,f|g,y|x,p|b,f|x,p|l,y|g,f|b,p|b,l|x,f|l,y|g,y|b,l|b,y|l,y|b,f|g,l|l,p|g,y|l,l|b,f|x,p|x,l|g,l|l,p|g,f|b,p|x];f=1<<22;p=1<<29;y=f|p;x=16;g=16384;b=x|g;const Gt=[p|x,y|l,l|g,y|b,y|l,l|x,y|b,f|l,p|g,f|b,f|l,p|x,f|x,p|g,p|l,l|b,l|l,f|x,p|b,l|g,f|g,p|b,l|x,y|x,y|x,l|l,f|b,y|g,l|b,f|g,y|g,p|l,p|g,l|x,y|x,f|g,y|b,f|l,l|b,p|x,f|l,p|g,p|l,l|b,p|x,y|b,f|g,y|l,f|b,y|g,l|l,y|x,l|x,l|g,y|l,f|b,l|g,f|x,p|b,l|l,y|g,p|l,f|x,p|b];f=1<<21;p=1<<26;y=f|p;x=2;g=2048;b=x|g;const Yt=[f|l,y|x,p|b,l|l,l|g,p|b,f|b,y|g,y|b,f|l,l|l,p|x,l|x,p|l,y|x,l|b,p|g,f|b,f|x,p|g,p|x,y|l,y|g,f|x,y|l,l|g,l|b,y|b,f|g,l|x,p|l,f|g,p|l,f|g,f|l,p|b,p|b,y|x,y|x,l|x,f|x,p|l,p|g,f|l,y|g,l|b,f|b,y|g,l|b,p|x,y|b,y|l,f|g,l|l,l|x,y|b,l|l,f|b,y|l,l|g,p|x,p|g,l|g,f|x];f=1<<18;p=1<<28;y=f|p;x=64;g=4096;b=x|g;const jt=[p|b,l|g,f|l,y|b,p|l,p|b,l|x,p|l,f|x,y|l,y|b,f|g,y|g,f|b,l|g,l|x,y|l,p|x,p|g,l|b,f|g,f|x,y|x,y|g,l|b,l|l,l|l,y|x,p|x,p|g,f|b,f|l,f|b,f|l,y|g,l|g,l|x,y|x,l|g,f|b,p|g,l|x,p|x,y|l,y|x,p|l,f|l,p|b,l|l,y|b,f|x,p|x,y|l,p|g,p|b,l|l,y|b,f|g,f|g,l|b,l|b,f|x,p|l,y|g];class sn{constructor(e){this.keys=[];const t=[],s=[],i=[];for(let n=0,r=56;n<56;++n,r-=8){r+=r<-5?65:r<-3?31:r<-1?63:r===27?35:0;const a=r&7;t[n]=e[r>>>3]&1<<a?1:0}for(let n=0;n<16;++n){const r=n<<1,a=r+1;i[r]=i[a]=0;for(let o=28;o<59;o+=28)for(let h=o-28;h<o;++h){const u=h+tn[n];s[h]=u<o?t[u]:t[u-28]}for(let o=0;o<24;++o)s[Ht[o]]!==0&&(i[r]|=1<<23-o),s[Ht[o+24]]!==0&&(i[a]|=1<<23-o)}for(let n=0,r=0,a=0;n<16;++n){const o=i[r++],h=i[r++];this.keys[a]=(o&16515072)<<6,this.keys[a]|=(o&4032)<<10,this.keys[a]|=(h&16515072)>>>10,this.keys[a]|=(h&4032)>>>6,++a,this.keys[a]=(o&258048)<<12,this.keys[a]|=(o&63)<<16,this.keys[a]|=(h&258048)>>>4,this.keys[a]|=h&63,++a}}enc8(e){const t=e.slice();let s=0,i,n,r;i=t[s++]<<24|t[s++]<<16|t[s++]<<8|t[s++],n=t[s++]<<24|t[s++]<<16|t[s++]<<8|t[s++],r=(i>>>4^n)&252645135,n^=r,i^=r<<4,r=(i>>>16^n)&65535,n^=r,i^=r<<16,r=(n>>>2^i)&858993459,i^=r,n^=r<<2,r=(n>>>8^i)&16711935,i^=r,n^=r<<8,n=n<<1|n>>>31&1,r=(i^n)&2863311530,i^=r,n^=r,i=i<<1|i>>>31&1;for(let a=0,o=0;a<8;++a){r=n<<28|n>>>4,r^=this.keys[o++];let h=Yt[r&63];h|=Wt[r>>>8&63],h|=Ot[r>>>16&63],h|=Nt[r>>>24&63],r=n^this.keys[o++],h|=jt[r&63],h|=Gt[r>>>8&63],h|=zt[r>>>16&63],h|=Vt[r>>>24&63],i^=h,r=i<<28|i>>>4,r^=this.keys[o++],h=Yt[r&63],h|=Wt[r>>>8&63],h|=Ot[r>>>16&63],h|=Nt[r>>>24&63],r=i^this.keys[o++],h|=jt[r&63],h|=Gt[r>>>8&63],h|=zt[r>>>16&63],h|=Vt[r>>>24&63],n^=h}for(n=n<<31|n>>>1,r=(i^n)&2863311530,i^=r,n^=r,i=i<<31|i>>>1,r=(i>>>8^n)&16711935,n^=r,i^=r<<8,r=(i>>>2^n)&858993459,n^=r,i^=r<<2,r=(n>>>16^i)&65535,i^=r,n^=r<<16,r=(n>>>4^i)&252645135,i^=r,n^=r<<4,r=[n,i],s=0;s<8;s++)t[s]=(r[s>>>2]>>>8*(3-s%4))%256,t[s]<0&&(t[s]+=256);return t}encrypt(e){return this.enc8(e.slice(0,8)).concat(this.enc8(e.slice(8,16)))}}const nn={Again:57349,AltLeft:56,AltRight:57400,ArrowDown:57424,ArrowLeft:57419,ArrowRight:57421,ArrowUp:57416,AudioVolumeDown:57390,AudioVolumeMute:57376,AudioVolumeUp:57392,Backquote:41,Backslash:43,Backspace:14,BracketLeft:26,BracketRight:27,BrowserBack:57450,BrowserFavorites:57446,BrowserForward:57449,BrowserHome:57394,BrowserRefresh:57447,BrowserSearch:57445,BrowserStop:57448,CapsLock:58,Comma:51,ContextMenu:57437,Control
1Left:29,ControlRight:57373,Convert:121,Copy:57464,Cut:57404,Delete:57427,Digit0:11,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Eject:57469,End:57423,Enter:28,Equal:13,Escape:1,F1:59,F10:68,F11:87,F12:88,F13:93,F14:94,F15:95,F16:85,F17:57347,F18:57463,F19:57348,F2:60,F20:90,F21:116,F22:57465,F23:109,F24:111,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,Find:57409,Help:57461,Hiragana:119,Home:57415,Insert:57426,IntlBackslash:86,IntlRo:115,IntlYen:125,KanaMode:112,Katakana:120,KeyA:30,KeyB:48,KeyC:46,KeyD:32,KeyE:18,KeyF:33,KeyG:34,KeyH:35,KeyI:23,KeyJ:36,KeyK:37,KeyL:38,KeyM:50,KeyN:49,KeyO:24,KeyP:25,KeyQ:16,KeyR:19,KeyS:31,KeyT:20,KeyU:22,KeyV:47,KeyW:17,KeyX:45,KeyY:21,KeyZ:44,Lang1:114,Lang2:113,Lang3:120,Lang4:119,Lang5:118,LaunchApp1:57451,LaunchApp2:57377,LaunchMail:57452,MediaPlayPause:57378,MediaSelect:57453,MediaStop:57380,MediaTrackNext:57369,MediaTrackPrevious:57360,MetaLeft:57435,MetaRight:57436,Minus:12,NonConvert:123,NumLock:69,Numpad0:82,Numpad1:79,Numpad2:80,Numpad3:81,Numpad4:75,Numpad5:76,Numpad6:77,Numpad7:71,Numpad8:72,Numpad9:73,NumpadAdd:78,NumpadComma:126,NumpadDecimal:83,NumpadDivide:57397,NumpadEnter:57372,NumpadEqual:89,NumpadMultiply:55,NumpadParenLeft:57462,NumpadParenRight:57467,NumpadSubtract:74,Open:100,PageDown:57425,PageUp:57417,Paste:101,Pause:57414,Period:52,Power:57438,PrintScreen:84,Props:57350,Quote:40,ScrollLock:70,Semicolon:39,ShiftLeft:42,ShiftRight:54,Slash:53,Sleep:57439,Space:57,Suspend:57381,Tab:15,Undo:57351,WakeUp:57443},X={encodingRaw:0,encodingCopyRect:1,encodingRRE:2,encodingHextile:5,encodingTight:7,encodingTightPNG:-260,encodingUDP:-261,pseudoEncodingQualityLevel0:-32,pseudoEncodingDesktopSize:-223,pseudoEncodingLastRect:-224,pseudoEncodingCursor:-239,pseudoEncodingQEMUExtendedKeyEvent:-258,pseudoEncodingDesktopName:-307,pseudoEncodingExtendedDesktopSize:-308,pseudoEncodingXvp:-309,pseudoEncodingFence:-312,pseudoEncodingContinuousUpdates:-313,pseudoEncodingCompressLevel0:-256,pseudoEncodingWEBP:-1024,pseudoEncodingJpegVideoQualityLevel0:-1023,pseudoEncodingWebpVideoQualityLevel0:-1013,pseudoEncodingTreatLosslessLevel0:-1003,pseudoEncodingPreferBandwidth:-992,pseudoEncodingDynamicQualityMinLevel0:-991,pseudoEncodingDynamicQualityMaxLevel0:-981,pseudoEncodingVideoAreaLevel1:-971,pseudoEncodingVideoTimeLevel0:-870,pseudoEncodingFrameRateLevel10:-2048,pseudoEncodingMaxVideoResolution:-1997,pseudoEncodingVideoScalingLevel0:-1996,pseudoEncodingVideoOutTimeLevel1:-1986,pseudoEncodingQOI:-1886,pseudoEncodingVMwareCursor:1464686180,pseudoEncodingVMwareCursorPosition:1464686182,pseudoEncodingExtendedClipboard:3231835598},Ee={LEFT_BUTTON:1,MIDDLE_BUTTON:2,RIGHT_BUTTON:3,BACK_BUTTON:8,FORWARD_BUTTON:9};function Ne(c){return 1<<c-1}class rn{constructor(){this.map=new Map}get(e){return this.map.has(e)?this.map.get(e):e}set(e,t){return this.map.set(e,t)}delete(e){return this.map.delete(e)}dump(){return JSON.stringify(this.map,this._replacer)}load(e){this.map=JSON.parse(e,this._reviver)}_replacer(e,t){return t instanceof Map?{dataType:"Map",value:Array.from(t.entries())}:t}_reviver(e,t){return typeof t=="object"&&t!==null&&t.dataType==="Map"?new Map(t.value):t}}class an{constructor(){this._lines=0}decodeRect(e,t,s,i,n,r,a,o){if(s===0||i===0)return!0;this._lines===0&&(this._lines=i);const h=a==8?1:4,u=s*h;if(n.rQwait("RAW",u))return!1;const _=t+(i-this._lines),w=Math.min(this._lines,Math.floor(n.rQlen/u)),k=s*w;let v=n.rQ,K=n.rQi;if(a==8){const R=new Uint8Array(k*4);for(let P=0;P<k;P++)R[P*4+0]=(v[K+P]>>0&3)*255/3,R[P*4+1]=(v[K+P]>>2&3)*255/3,R[P*4+2]=(v[K+P]>>4&3)*255/3,R[P*4+3]=255;v=R,K=0}for(let R=0;R<k;R++)v[R*4+3]=255;return r.blitImage(e,_,s,w,v,K,o),n.rQskipBytes(w*u),this._lines-=w,!(this._lines>0)}}class on{decodeRect(e,t,s,i,n,r,a,o){if(n.rQwait("COPYRECT",4))return!1;let h=n.rQshift16(),u=n.rQshift16();return s===0||i===0||r.copyImage(h,u,e,t,s,i,o),!0}}class hn{constructor(){this._subrects=0}
1decodeRect(e,t,s,i,n,r,a,o){if(this._subrects===0){if(n.rQwait("RRE",8))return!1;this._subrects=n.rQshift32();let h=n.rQshiftBytes(4);r.fillRect(e,t,s,i,h)}for(;this._subrects>0;){if(n.rQwait("RRE",12))return!1;let h=n.rQshiftBytes(4),u=n.rQshift16(),_=n.rQshift16(),w=n.rQshift16(),k=n.rQshift16();r.fillRect(e+u,t+_,w,k,h,o),this._subrects--}return!0}}class cn{constructor(){this._tiles=0,this._lastsubencoding=0,this._tileBuffer=new Uint8Array(16*16*4)}decodeRect(e,t,s,i,n,r,a,o){for(this._tiles===0&&(this._tilesX=Math.ceil(s/16),this._tilesY=Math.ceil(i/16),this._totalTiles=this._tilesX*this._tilesY,this._tiles=this._totalTiles);this._tiles>0;){let h=1;if(n.rQwait("HEXTILE",h))return!1;let u=n.rQ,_=n.rQi,w=u[_];if(w>30)throw new Error("Illegal hextile subencoding (subencoding: "+w+")");const k=this._totalTiles-this._tiles,v=k%this._tilesX,K=Math.floor(k/this._tilesX),R=e+v*16,P=t+K*16,G=Math.min(16,e+s-R),Y=Math.min(16,t+i-P);if(w&1)h+=G*Y*4;else if(w&2&&(h+=4),w&4&&(h+=4),w&8){if(h++,n.rQwait("HEXTILE",h))return!1;let E=u[_+h-1];w&16?h+=E*6:h+=E*2}if(n.rQwait("HEXTILE",h))return!1;if(_++,w===0)this._lastsubencoding&1?C(" Ignoring blank after RAW"):r.fillRect(R,P,G,Y,this._background,o);else if(w&1){let E=G*Y;for(let L=0;L<E;L++)u[_+L*4+3]=255;r.blitImage(R,P,G,Y,u,_,o),_+=h-1}else{if(w&2&&(this._background=[u[_],u[_+1],u[_+2],u[_+3]],_+=4),w&4&&(this._foreground=[u[_],u[_+1],u[_+2],u[_+3]],_+=4),this._startTile(R,P,G,Y,this._background),w&8){let E=u[_];_++;for(let L=0;L<E;L++){let $;w&16?($=[u[_],u[_+1],u[_+2],u[_+3]],_+=4):$=this._foreground;const j=u[_];_++;const ce=j>>4,Z=j&15,le=u[_];_++;const te=(le>>4)+1,je=(le&15)+1;this._subTile(ce,Z,te,je,$)}}this._finishTile(r,o)}n.rQi=_,this._lastsubencoding=w,this._tiles--}return!0}_startTile(e,t,s,i,n){this._tileX=e,this._tileY=t,this._tileW=s,this._tileH=i;const r=n[0],a=n[1],o=n[2],h=this._tileBuffer;for(let u=0;u<s*i*4;u+=4)h[u]=r,h[u+1]=a,h[u+2]=o,h[u+3]=255}_subTile(e,t,s,i,n){const r=n[0],a=n[1],o=n[2],h=e+s,u=t+i,_=this._tileBuffer,w=this._tileW;for(let k=t;k<u;k++)for(let v=e;v<h;v++){const K=(v+k*w)*4;_[K]=r,_[K+1]=a,_[K+2]=o,_[K+3]=255}}_finishTile(e,t){e.blitImage(this._tileX,this._tileY,this._tileW,this._tileH,this._tileBuffer,0,t)}}function ln(c){return new Worker("/workbench/assets/decoder-Cr3qsWkC.js",{name:c==null?void 0:c.name})}class hs{constructor(e){this._ctl=null,this._filter=null,this._numColors=0,this._palette=new Uint8Array(1024),this._len=0,this._enableQOI=!1,this._displayGlobal=e,this._lastTransparentRectHash="",this._lastTransparentRectInfo="",this._zlibs=[];for(let t=0;t<4;t++)this._zlibs[t]=new Ge;this._itzlib=new Ge}get enableQOI(){return this._enableQOI}set enableQOI(e){this._enableQOI!==e&&(e?this._enableQOI=this._enableQOIWorkers():(this._enableQOI=!1,this._disableQOIWorkers()))}decodeRect(e,t,s,i,n,r,a,o){if(this._ctl===null){if(n.rQwait("TIGHT compression-control",1))return!1;this._ctl=n.rQshift8();for(let u=0;u<4;u++)this._ctl>>u&1&&(this._zlibs[u].reset(),I("Reset zlib stream "+u));this._ctl=this._ctl>>4}let h;if(this._ctl===8)h=this._fillRect(e,t,s,i,n,r,a,o);else if(this._ctl===9)h=this._jpegRect(e,t,s,i,n,r,a,o);else if(this._ctl===10)h=this._pngRect(e,t,s,i,n,r,a,o);else if(!(this._ctl&8))h=this._basicRect(this._ctl,e,t,s,i,n,r,a,o);else if(this._ctl===11)h=this._webpRect(e,t,s,i,n,r,a,o);else if(this._ctl===12)h=this._qoiRect(e,t,s,i,n,r,a,o);else if(this._ctl===13)h=this._itRect(e,t,s,i,n,r,a,o);else throw new Error("Illegal tight compression received (ctl: "+this._ctl+")");return h&&(this._ctl=null),h}_fillRect(e,t,s,i,n,r,a,o){if(n.rQwait("TIGHT",3))return!1;const h=n.rQi,u=n.rQ;return r.fillRect(e,t,s,i,[u[h],u[h+1],u[h+2]],o,!1),n.rQskipBytes(3),!0}_jpegRect(e,t,s,i,n,r,a,o){let h=this._readData(n);return h===null?!1:(r.imageRect(e,t,s,i,"image/jpeg",h,o),!0)}_webpRect(e,t,s,i,n,r,a,o){let h=this._readData(n);return h===null?!1:(r.imageRect(e,t,s,i,"image/webp",h,o),!0)}_processRectQ(){for(;this._availableWorkers.length>0&&this._qoiRects.length>0;){let t=this._availableWorkers.pop(),s=this._workers[t],i=this._qoiRects.shift();var e=new ArrayBuffer(i.data.length);new Uint8Array(e).set(new Uint8Array(i.data)),s.postMessage({x:i.x,y:i.y,width:i.width,height:i.height,depth:i.depth,frame_id:i.frame_id,image:e},[e])}}_qoiRect(e,t,s,i,n,r,a,o){let h=this._readData(n);if(h===null)return!1;if(this._enableQOI){let u=new Uint8Array(h),_={x:e,y:t,width:s,height:i,data:u,depth:a,frame_id:o};this._qoiRects.length<1e3?(this._qoiRects.push(_),this._processRectQ()):(H("QOI queue exceeded limit."),this._qoiRects.splice(0,500))}return!0}_itRect(e,t,s,i,n,r,a,o){let h=this._readData(n);if(h===null)return!1;let u=Re(h),_=`${e}.${t}.${s}.${i}`;if(u===this._lastTransparentRectHash&&_===this._lastTransparentRectInfo)r.dummyRect(e,t,s,i,o);else{const w=h[0],k=h[1],v=h[2],K=h[3],R=Math.floor(s*i/2+1);this._itzlib.reset(),this._itzlib.setInput(h.slice(4)),h=this._itzlib.inflate(R),this._itzlib.setInput(null);let P=new Uint8Array(s*i*4+4);for(let Y=0,E=0;Y<R;Y++,E+=8){let L=h[Y];P[E+0]=w,P[E+1]=k,P[E+2]=v,P[E+3]=K*((L&15)<<4)/255,P[E+4]=w,P[E+5]=k,P[E+6]=v,P[E+7]=K*(L&240)/255}let G=new ImageData(new Uint8ClampedArray(P.buffer,0,s*i*4),s,i);r.transparentRect(e,t,s,i,G,o,u),this._lastTransparentRectHash=u,this._lastTransparentRectInfo=_}return!0}
1_pngRect(e,t,s,i,n,r,a,o){throw new Error("PNG received in standard Tight rect")}_basicRect(e,t,s,i,n,r,a,o,h){if(this._filter===null)if(e&4){if(r.rQwait("TIGHT",1))return!1;this._filter=r.rQshift8()}else this._filter=0;let u=e&3,_;switch(this._filter){case 0:_=this._copyFilter(u,t,s,i,n,r,a,o,h);break;case 1:_=this._paletteFilter(u,t,s,i,n,r,a,o,h);break;case 2:_=this._gradientFilter(u,t,s,i,n,r,a,o,h);break;default:throw new Error("Illegal tight filter received (ctl: "+this._filter+")")}return _&&(this._filter=null),_}_copyFilter(e,t,s,i,n,r,a,o,h){const u=i*n*3;let _;if(u===0)return!0;if(u<12){if(r.rQwait("TIGHT",u))return!1;_=r.rQshiftBytes(u)}else{if(_=this._readData(r),_===null)return!1;this._zlibs[e].setInput(_),_=this._zlibs[e].inflate(u),this._zlibs[e].setInput(null)}let w=new Uint8Array(i*n*4);for(let k=0,v=0;k<i*n*4;k+=4,v+=3)w[k]=_[v],w[k+1]=_[v+1],w[k+2]=_[v+2],w[k+3]=255;return a.blitImage(t,s,i,n,w,0,h,!1),!0}_paletteFilter(e,t,s,i,n,r,a,o,h){if(this._numColors===0){if(r.rQwait("TIGHT palette",1))return!1;const v=r.rQpeek8()+1,K=v*3;if(r.rQwait("TIGHT palette",1+K))return!1;this._numColors=v,r.rQskipBytes(1),r.rQshiftTo(this._palette,K)}const u=this._numColors<=2?1:8,w=Math.floor((i*u+7)/8)*n;let k;if(w===0)return!0;if(w<12){if(r.rQwait("TIGHT",w))return!1;k=r.rQshiftBytes(w)}else{if(k=this._readData(r),k===null)return!1;this._zlibs[e].setInput(k),k=this._zlibs[e].inflate(w),this._zlibs[e].setInput(null)}return this._numColors==2?this._monoRect(t,s,i,n,k,this._palette,a,h):this._paletteRect(t,s,i,n,k,this._palette,a,h),this._numColors=0,!0}_monoRect(e,t,s,i,n,r,a,o){const h=this._getScratchBuffer(s*i*4),u=Math.floor((s+7)/8),_=Math.floor(s/8);for(let w=0;w<i;w++){let k,v,K;for(K=0;K<_;K++)for(let R=7;R>=0;R--)k=(w*s+K*8+7-R)*4,v=(n[w*u+K]>>R&1)*3,h[k]=r[v],h[k+1]=r[v+1],h[k+2]=r[v+2],h[k+3]=255;for(let R=7;R>=8-s%8;R--)k=(w*s+K*8+7-R)*4,v=(n[w*u+K]>>R&1)*3,h[k]=r[v],h[k+1]=r[v+1],h[k+2]=r[v+2],h[k+3]=255}a.blitImage(e,t,s,i,h,0,o,!1)}_paletteRect(e,t,s,i,n,r,a,o){const h=this._getScratchBuffer(s*i*4),u=s*i*4;for(let _=0,w=0;_<u;_+=4,w++){const k=n[w]*3;h[_]=r[k],h[_+1]=r[k+1],h[_+2]=r[k+2],h[_+3]=255}a.blitImage(e,t,s,i,h,0,o,!1)}_gradientFilter(e,t,s,i,n,r,a,o,h){throw new Error("Gradient filter not implemented")}_readData(e){if(this._len===0){if(e.rQwait("TIGHT",3))return null;let s;s=e.rQshift8(),this._len=s&127,s&128&&(s=e.rQshift8(),this._len|=(s&127)<<7,s&128&&(s=e.rQshift8(),this._len|=s<<14))}if(e.rQwait("TIGHT",this._len))return null;let t=e.rQshiftBytes(this._len);return this._len=0,t}_getScratchBuffer(e){return(!this._scratchBuffer||this._scratchBuffer.length<e)&&(this._scratchBuffer=new Uint8Array(e)),this._scratchBuffer}async _disableQOIWorkers(){if(this._workers){this._enableQOI=!1,this._availableWorkers=null,this._qoiRects=null,this._rectQlooping=null;for await(let e of Array.from(Array(this._threads).keys()))this._workers[e].terminate(),delete this._workers[e];this._workers=null}}_enableQOIWorkers(){let e=window.location.pathname,t=e.substring(0,e.lastIndexOf("/")+1);window.navigator.hardwareConcurrency&&window.navigator.hardwareConcurrency>=4?this._threads=16:this._threads=8,this._workers=[],this._availableWorkers=[],this._qoiRects=[],this._rectQlooping=!1;for(let s=0;s<this._threads;s++)this._workers.push(new ln),this._workers[s].onmessage=i=>{switch(this._availableWorkers.push(s),i.data.result){case 0:i.data.freemem=null;let n=new Uint8ClampedArray(i.data.data),r=new ImageData(n,i.data.img.width,i.data.img.height,{colorSpace:i.data.img.colorSpace});this._displayGlobal.blitQoi(i.data.x,i.data.y,i.data.width,i.data.height,r,0,i.data.frame_id,!1),this._processRectQ(),this._workers[s].postMessage({freemem:i.data.data});break;case 1:I("QOI Worker is now available.");break;case 2:I("Error on worker: "+i.error);break}};for(let s=0;s<this._threads;s++)this._workers[s].postMessage({path:t});return!0}}class dn extends hs{_pngRect(e,t,s,i,n,r,a,o){let h=this._readData(n);return h===null?!1:(r.imageRect(e,t,s,i,"image/png",h,o),!0)}_basicRect(e,t,s,i,n,r,a,o){throw new Error("BasicCompression received in TightPNG rect")}}class un{constructor(){this._filter=null,this._palette=new Uint8Array(1024),this._directDraw=!1,this._zlibs=[];for(let e=0;e<4;e++)this._zlibs[e]=new Ge}decodeRect(e,t,s,i,n,r,a,o){let h=n[12];h=h>>4;let u;if(h===8)u=this._fillRect(e,t,s,i,n,r,a,o);else if(h===9)u=this._jpegRect(e,t,s,i,n,r,a,o);else if(h===10)u=this._pngRect(e,t,s,i,n,r,a,o);else if(!(h&8))u=this._basicRect(h,e,t,s,i,n,r,a,o);else if(h===11)u=this._webpRect(e,t,s,i,n,r,a,o);else throw new Error("Illegal udp compression received (ctl: "+h+")");return u}_fillRect(e,t,s,i,n,r,a,o){return r.fillRect(e,t,s,i,[n[13],n[14],n[15]],o,this._directDraw),!0}_jpegRect(e,t,s,i,n,r,a,o){let h=this._readData(n);return h===null?!1:(r.imageRect(e,t,s,i,"image/jpeg",h,o,this._directDraw),!0)}_webpRect(e,t,s,i,n,r,a,o){let h=this._readData(n);return h===null?!1:(r.imageRect(e,t,s,i,"image/webp",h,o,this._directDraw),!0)}
1_pngRect(e,t,s,i,n,r,a,o){Q("PNG received in UDP rect")}_basicRect(e,t,s,i,n,r,a,o,h){let u=r[12];for(let K=0;K<4;K++)u>>K&1&&this._zlibs[K].reset();let _=r[13],w=14,k=e&3;e&4||(_=0,w=13);let v;switch(_){case 0:v=this._copyFilter(k,t,s,i,n,r,a,o,h,w);break;case 1:v=this._paletteFilter(k,t,s,i,n,r,a,o,h);break;case 2:v=this._gradientFilter(k,t,s,i,n,r,a,o,h);break;default:throw new Error("Illegal tight filter received (ctl: "+this._filter+")")}return v}_copyFilter(e,t,s,i,n,r,a,o,h,u=14){const _=i*n*3;if(_===0)return!0;if(_<12)r=r.slice(u,u+_);else{if(r=this._readData(r,u),r===null)return!1;this._zlibs[e].setInput(r),r=this._zlibs[e].inflate(_),this._zlibs[e].setInput(null)}let w=new Uint8Array(i*n*4);for(let k=0,v=0;k<i*n*4;k+=4,v+=3)w[k]=r[v],w[k+1]=r[v+1],w[k+2]=r[v+2],w[k+3]=255;return a.blitImage(t,s,i,n,w,0,h,this._directDraw),!0}_paletteFilter(e,t,s,i,n,r,a,o,h){const u=r[14]+1,_=u*3;let w=r.slice(15,15+_);const k=u<=2?1:8,K=Math.floor((i*k+7)/8)*n;let R=15+_;if(K===0)return!0;if(K<12)r=r.slice(R,R+K);else{if(r=this._readData(r,R),r===null)return!1;this._zlibs[e].setInput(r),r=this._zlibs[e].inflate(K),this._zlibs[e].setInput(null)}return u==2?this._monoRect(t,s,i,n,r,w,a,h):this._paletteRect(t,s,i,n,r,w,a,h),!0}_monoRect(e,t,s,i,n,r,a,o){const h=this._getScratchBuffer(s*i*4),u=Math.floor((s+7)/8),_=Math.floor(s/8);for(let w=0;w<i;w++){let k,v,K;for(K=0;K<_;K++)for(let R=7;R>=0;R--)k=(w*s+K*8+7-R)*4,v=(n[w*u+K]>>R&1)*3,h[k]=r[v],h[k+1]=r[v+1],h[k+2]=r[v+2],h[k+3]=255;for(let R=7;R>=8-s%8;R--)k=(w*s+K*8+7-R)*4,v=(n[w*u+K]>>R&1)*3,h[k]=r[v],h[k+1]=r[v+1],h[k+2]=r[v+2],h[k+3]=255}a.blitImage(e,t,s,i,h,0,o,this._directDraw)}_paletteRect(e,t,s,i,n,r,a,o){const h=this._getScratchBuffer(s*i*4),u=s*i*4;for(let _=0,w=0;_<u;_+=4,w++){const k=n[w]*3;h[_]=r[k],h[_+1]=r[k+1],h[_+2]=r[k+2],h[_+3]=255}a.blitImage(e,t,s,i,h,0,o,this._directDraw)}_gradientFilter(e,t,s,i,n,r,a,o,h){throw new Error("Gradient filter not implemented")}_readData(e,t=13){if(e.length<t+2)return Q("UDP Decoder, readData, invalid data len"),null;let s=t,i=e[s++],n=i&127;return i&128&&(i=e[s++],n|=(i&127)<<7,i&128&&(i=e[s++],n|=i<<14)),e.length,n+s,e.slice(s)}_getScratchBuffer(e){return(!this._scratchBuffer||this._scratchBuffer.length<e)&&(this._scratchBuffer=new Uint8Array(e)),this._scratchBuffer}}const _n=3,fn="rgb(40, 40, 40)",qt=17;let $t=19;const Ke=75,ae=50,pn=1e3,xn=50,oe=1,Zt=1<<24,Oe=1<<25,Jt=1<<26,ze=1<<27,We=1<<28;class M extends Hi{constructor(e,t,s,i,n){if(!e)throw new Error("Mu
1st specify target");if(!s&&n)throw new Error("Must specify URL, WebSocket or RTCDataChannel");super(),this.errorCode=0,this._target=e,typeof s=="string"?this._url=s:(this._url=null,this._rawChannel=s),i=i||{},this._rfbCredentials=i.credentials||{},this._shared="shared"in i?!!i.shared:!0,this._repeaterID=i.repeaterID||"",this._wsProtocols=i.wsProtocols||["binary"],this._isPrimaryDisplay=n!==!1,this._rfbConnectionState="",this._rfbInitState="",this._rfbAuthScheme=-1,this._rfbCleanDisconnect=!0,this._isFirstConnect=0,this._rfbVersion=0,this._rfbMaxVersion=3.8,this._rfbTightVNC=!1,this._rfbVeNCryptState=0,this._rfbXvpVer=0,this._fbWidth=0,this._fbHeight=0,this._fbName="",this._capabilities={power:!1},this._supportsFence=!1,this._supportsContinuousUpdates=!1,this._enabledContinuousUpdates=!1,this._supportsSetDesktopSize=!1,this._connectionID=window.location.href.split("?")[0].match(/^(.+)(\/)/)[0],this._screenFlags=0,this._qemuExtKeyEventSupported=!1,this._jpegVideoQuality=5,this._webpVideoQuality=5,this._treatLossless=7,this._preferBandwidth=!0,this._dynamicQualityMin=3,this._dynamicQualityMax=9,this._videoArea=65,this._videoTime=5,this._videoOutTime=3,this._videoScaling=2,this._frameRate=30,this._maxVideoResolutionX=960,this._maxVideoResolutionY=540,this._forcedResolutionX=null,this._forcedResolutionY=null,this._clipboardBinary=!0,this._resendClipboardNextUserDrivenEvent=!0,this._useUdp=!0,this._hiDpi="hiDpi"in i?!!i.hiDpi:!1,this._enableQOI=!1,this._videoQuality=2,this._enableWebP=!1,this.TransitConnectionStates={Tcp:Symbol("tcp"),Udp:Symbol("udp"),Upgrading:Symbol("upgrading"),Downgrading:Symbol("downgrading"),Failure:Symbol("failure")},this._transitConnectionState=this.TransitConnectionStates.Tcp,this._lastTransition=null,this._udpConnectFailures=0,this._udpTransitFailures=0,this._trackFrameStats=!1,this._clipboardText=null,this._clipboardServerCapabilitiesActions={},this._clipboardServerCapabilitiesFormats={},this._threading=!0,this._sock=null,this._display=null,this._flushing=!1,this._keyboard=null,this._gestures=null,this._disconnTimer=null,this._resizeTimeout=null,this._mouseMoveTimer=null,this._forceFullFrameUpdateTimeout=null,this._decoders={},this._FBU={rects:0,x:0,y:0,width:0,height:0,encoding:null,frame_id:0,rect_total:0},this._mousePos={},this._mouseButtonMask=0,this._mouseLastMoveTime=0,this._pointerLock=!1,this._pointerLockPos={x:0,y:0},this._pointerRelativeEnabled=!1,this._mouseLastPinchAndZoomTime=0,this._viewportDragging=!1,this._viewportDragPos={},this._viewportHasMoved=!1,this._accumulatedWheelDeltaX=0,this._accumulatedWheelDeltaY=0,this.mouseButtonMapper=null,this._mouseLastScreenIndex=-1,this._sendLeftClickonNextMove=!1,this._gestureLastTapTime=null,this._gestureFirstDoubleTapEv=null,this._gestureLastMagnitudeX=0,this._gestureLastMagnitudeY=0,this._supportsBroadcastChannel=typeof BroadcastChannel<"u",this._supportsBroadcastChannel&&(this._controlChannel=new BroadcastChannel(this._connectionID),this._controlChannel.addEventListener("message",this._handleControlMessage.bind(this)),C("Attached to registrationChannel for secondary displays.")),this._isPrimaryDisplay||(this._screenIndex=2),this._eventHandlers={updateHiddenKeyboard:this._updateHiddenKeyboard.bind(this),focusCanvas:this._focusCanvas.bind(this),windowResize:this._windowResize.bind(this),handleMouse:this._handleMouse.bind(this),handlePointerLockChange:this._handlePointerLockChange.bind(this),handlePointerLockError:this._handlePointerLockError.bind(this),handleWheel:this._handleWheel.bind(this),handleGesture:this._handleGesture.bind(this),handleFocusChange:this._handleFocusChange.bind(this),handleMouseOut:this._handleMouseOut.bind(this),handleVisibilityChange:this._handleVisibilityChange.bind(this)},C(">> RFB.constructor"),this._screen=document.createElement("div"),this._screen.style.display="flex",this._screen.style.width="100%",this._screen.style.height="100%",this._screen.style.overflow="auto",this._screen.style.background=fn,this._canvas=document.createElement("canvas"),this._canvas.style.margin="auto",this._canvas.style.outline="none",this._canvas.width=0,this._canvas.height=0,this._canvas.tabIndex=-1,this._canvas.overflow="hidden",this._screen.appendChild(this._canvas),this._cursor=new Ji,this._cursorImage=M.cursors.none;try{this._display=new Oi(this._canvas,this._isPrimaryDisplay)}catch(r){throw Q("Display exception: "+r),r}this._display.onflush=this._onFlush.bind(this),this._decoders[X.encodingRaw]=new an,this._decoders[X.encodingCopyRect]=new on,this._decoders[X.encodingRRE]=new hn,this._decoders[X.encodingHextile]=new cn,this._decoders[X.encodingTight]=new hs(this._display),this._decoders[X.encodingTightPNG]=new dn,this._decoders[X.encodingU
1DP]=new un,this._keyboard=new Pi(this._canvas,t),this._keyboard.onkeyevent=this._handleKeyEvent.bind(this),this._gestures=new Zi,this._isPrimaryDisplay&&this._setupWebSocket(),C("<< RFB.constructor"),this.dragViewport=!1,this.focusOnClick=!0,this.lastActiveAt=Date.now(),this._viewOnly=!1,this._clipViewport=!1,this._scaleViewport=!1,this._resizeSession=!1,this._lastVisibilityState="visible",this._showDotCursor=!1,i.showDotCursor!==void 0&&(H("Specifying showDotCursor as a RFB constructor argument is deprecated"),this._showDotCursor=i.showDotCursor),this._qualityLevel=6,this._compressionLevel=2,this._clipHash=0}get connectionID(){return this._connectionID}get translateShortcuts(){return this._keyboard.translateShortcuts}set translateShortcuts(e){this._keyboard.translateShortcuts=e}get pointerLock(){return this._pointerLock}set pointerLock(e){this._pointerLock?window.document.exitPointerLock?(window.document.exitPointerLock(),this._pointerLockChanging=!0):window.document.mozExitPointerLock&&(window.document.mozExitPointerLock(),this._pointerLockChanging=!0):this._canvas.requestPointerLock?(this._canvas.requestPointerLock(),this._pointerLockChanging=!0):this._canvas.mozRequestPointerLock&&(this._canvas.mozRequestPointerLock(),this._pointerLockChanging=!0)}get pointerRelative(){return this._pointerRelativeEnabled}set pointerRelative(e){if(this._pointerRelativeEnabled=e,e){let t=this._display.scale===1?this._fbWidth:this._fbWidth*this._display.scale,s=this._display.scale===1?this._fbHeight:this._fbHeight*this._display.scale;this._pointerLockPos.x=Math.floor(t/2),this._pointerLockPos.y=Math.floor(s/2),this._mousePos={x:this._pointerLockPos.x,y:this._pointerLockPos.y},this._cursor.move(this._pointerLockPos.x,this._pointerLockPos.y)}}get keyboard(){return this._keyboard}get clipboardBinary(){return this._clipboardMode}set clipboardBinary(e){this._clipboardMode=e}get videoQuality(){return this._videoQuality}set videoQuality(e){(this._videoQuality<=1||e<=1)&&(this._pendingApplyResolutionChange=!0),this._videoQuality=e,this._pendingApplyEncodingChanges=!0}get preferBandwidth(){return this._preferBandwidth}set preferBandwidth(e){this._preferBandwidth=e,this._pendingApplyEncodingChanges=!0}get viewOnly(){return this._viewOnly}set viewOnly(e){this._viewOnly=e,(this._rfbConnectionState==="connecting"||this._rfbConnectionState==="connected")&&(e?this._keyboard.ungrab():this._keyboard.grab())}get capabilities(){return this._capabilities}get touchButton(){return 0}set touchButton(e){H("Using old API!")}get clipViewport(){return this._clipViewport}set clipViewport(e){this._clipViewport=e}get scaleViewport(){return this._scaleViewport}set scaleViewport(e){this._scaleViewport!==e&&(this._scaleViewport=e,this._pendingApplyResolutionChange=!0)}get resizeSession(){return this._resizeSession}set resizeSession(e){this._resizeSession=e,e&&(this.scaleViewport=!0,this._pendingApplyResolutionChange=!0)}get showDotCursor(){return this._showDotCursor}set showDotCursor(e){this._showDotCursor=e,this._refreshCursor()}get background(){return this._screen.style.background}set background(e){this._screen.style.background=e}get enableWebP(){return this._enableWebP}set enableWebP(e){this._enableWebP!==e&&(this._enableWebP=e,this._pendingApplyEncodingChanges=!0)}get enableQOI(){return this._enableQOI}set enableQOI(e){this._enableQOI!==e&&(this._decoders[X.encodingTight].enableQOI=e,this._enableQOI=this._decoders[X.encodingTight].enableQOI,this._enableQOI===e&&(this._pendingApplyEncodingChanges=!0))}get antiAliasing(){return this._display.antiAliasing}set antiAliasing(e){this._display.antiAliasing=e}get jpegVideoQuality(){return this._jpegVideoQuality}set jpegVideoQuality(e){if(!Number.isInteger(e)||e<0||e>9){Q("qualityLevel must be an integer between 0 and 9");return}this._jpegVideoQuality!==e&&(this._jpegVideoQuality=e,this._pendingApplyEncodingChanges=!0)}get webpVideoQuality(){return this._webpVideoQuality}set webpVideoQuality(e){if(!Number.isInteger(e)||e<0||e>9){Q("qualityLevel must be an integer between 0 and 9");return}this._webpVideoQuality!==e&&(this._webpVideoQuality=e,this._pendingApplyEncodingChanges=!0)}get treatLossless(){return this._treatLossless}set treatLossless(e){if(!Number.isInteger(e)||e<0||e>9){Q("qualityLevel must be an integer between 0 and 9");return}this._treatLossless!==e&&(this._treatLossless=e)}get dynamicQualityMin(){return this._dynamicQualityMin}set dynamicQualityMin(e){if(!Number.isInteger(e)||e<0||e>9){Q("qualityLevel must be an integer between 0 and 9");return}this._dynamicQualityMin!==e&&(this._dynamicQualityMin=e,this._pendingApplyEncodingChanges=!0)}get dynamicQualityMax(){return this._dynamicQualityMax}set dynamicQualityMax(e){if(!Number.isInteger(e)||e<0||e>9){Q("qualityLevel must be an integer between 0 and 9");return}this._dynamicQualityMax!==e&&(this._dynamicQualityMax=e,this._pendingApplyEncodingChanges=!0)}get videoArea(){return this._videoArea}set videoArea(e){if(!Number.isInteger(e)||e<0||e>100){Q("video area must be an integer between 0 and 100");return}this._videoArea!==e&&(this._videoArea=e,this._pendingApplyEncodingChanges=!0)}get videoTime(){return this._videoTime}set videoTime(e){if(!Number.isInteger(e)||e<0||e>100){Q("video time must be an integer between 0 and 100");return}this._videoTime!==e&&(this._videoTime=e,this._pendingApplyEncodingChanges=!0)}get videoOutTime(){return this._videoOutTime}set videoOutTime(e){if(!Number.isInteger(e)||e<0||e>100){Q("video out time must be an integer between 0 and 100");return}this._videoOutTime!==e&&(this._videoOutTime=e,this._pendingApplyEncodingChanges=!0)}get videoScaling(){return this._videoScaling}set videoScaling(e){if(!Number.isInteger(e)||e<0||e>2){Q("video scaling must be an integer between 0 and 2");return}this._videoScaling!==e&&(this._videoScaling=e,this._pendingApplyEncodingChanges=!0)}get frameRate(){return this._frameRate}set frameRate(e){if(!Number.isInteger(e)||e<1||e>120){Q("frame rate must be an integer between 1 and 120");return}this._frameRate!==e&&(this._frameRate=e,this._pendingApplyEncodingChanges=!0)}get maxVideoResolutionX(){return this._maxVideoResolutionX}set maxVideoResolutionX(e){if(!Number.isInteger(e)||e<100){Q("max video resolution must be an integer greater than 100");return}this._maxVideoResolutionX!==e&&(this._maxVideoResolutionX=e,this._pendingApplyVideoRes=!0)}get maxVideoResolutionY(){return this._maxVideoResolutionY}set maxVideoResolutionY(e){if(!Number.isInteger(e)||e<100){Q("max video resolution must be an integer greater than 100");return}this._maxVideoResolutionY!==e&&(this._maxVideoResolutionY=e,this._pendingApplyVideoRes=!0)}get forcedResolutionX(){return this._forcedResolutionX}set forcedResolutionX(e){e!==this._forcedResolutionX&&(this._forcedResolutionX=e,this._pendingApplyResolutionChange=!0)}get forcedResolutionY(){return this._forcedResolutionY}set forcedResolutionY(e){e!==this._forcedResolutionY&&(this._forcedResolutionY=e,this._pendingApplyResolutionChange=!0)}get qualityLevel(){return this._qualityLevel}set qualityLevel(e){if(!Number.isInteger(e)||e<0||e>9){Q("qualityLevel must be an integer between 0 and 9");return}this._qualityLevel!==e&&(this._qualityLevel=e,this._pendingApplyEncodingChanges=!0)}get compressionLevel(){return this._compressionLevel}set compressionLevel(e){if(!Number.isInteger(e)||e<0||e>9){Q("compressionLevel must be an integer between 0 and 9");return}this._compressionLevel!==e&&(this._compressionLevel=e,this._rfbConnectionState==="connected"&&this._sendEncodings())}get statsFps(){return this._display.fps}get statsDroppedFps(){return this._display.droppedFps}get enableWebRTC(){return this._useUdp}set enableWebRTC(e){this._useUdp=e,e?this._rfbConnectionState==="connected"&&this._transitConnectionState!==this.TransitConnectionStates.Udp&&this._sendUdpUpgrade():this._rfbConnectionState==="connected"&&this._transitConnectionState!==this.TransitConnectionStates.Tcp&&this._sendUdpDowngrade()}get enableHiDpi(){return this._hiDpi}set enableHiDpi(e){e!==this._hiDpi&&(this._hiDpi=e,this._pendingApplyResolutionChange=!0,this._display.applyServerResolution(0,0,0))}get threading(){return this._threading}set threading(e){e!==this._threading&&(this._threading=e,this._display.threading=e)}
1refreshSecondaryDisplays(){this._display.screens.length>1&&this._proxyRFBMessage("applySettings",[this._hiDpi,this._clipViewport,this._scaleViewport,this._resizeSession,this._videoQuality,this._forcedResolutionX,this._forcedResolutionY])}attachSecondaryDisplay(e){this._updateConnectionState("connecting");const t=this._registerSecondaryDisplay(!1,e);return this._updateConnectionState("connected"),t}reattachSecondaryDisplay(e,t){return this._updateConnectionState("connecting"),this._registerSecondaryDisplay(e,t),this._updateConnectionState("connected"),e}applyScreenPlan(e){if(this._isPrimaryDisplay){let t=this._screenSize(),s=Number.MAX_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER,n=0;for(let a=0;a<e.screens.length;a++){s=Math.min(s,e.screens[a].x),i=Math.min(i,e.screens[a].y);for(let o=0;o<t.screens.length;o++)e.screens[a].screenID==t.screens[o].screenID&&n++}if(s!==0||i!==0)throw new Error("Screen plan invalid, improper coordinates provided.");if(n>t.screens.length)throw new Error("Screen plan contained more screens then there are registered.");if(n<t.screens.length)throw new Error("Screen plan contained fewer screens then there are registered.");let r=this._display.applyScreenPlan(e);if(r){for(let a=0;a<e.screens.length;a++)for(let o=1;o<t.screens.length;o++)e.screens[a].screenID==t.screens[o].screenID&&this._proxyRFBMessage("applyScreenPlan",[t.screens[o].screenID,t.screens[o].screenIndex,e.screens[a].width,e.screens[a].height,e.screens[a].x,e.screens[a].y]);this._pendingApplyResolutionChange=!0}else C("Screen plan did not apply, no changes detected.");return r}}getScreenPlan(){let e=this._screenSize(),t={screens:[],serverWidth:e.serverWidth,serverHeight:e.serverHeight};for(let s=0;s<e.screens.length;
1s++)t.screens.push({screenID:e.screens[s].screenID,serverWidth:e.screens[s].serverWidth,serverHeight:e.screens[s].serverHeight,x:e.screens[s].x,y:e.screens[s].y,pixelRatio:e.screens[s].pixelRatio});return t}updateConnectionSettings(){this._rfbConnectionState==="connected"&&this._isPrimaryDisplay?(this._pendingApplyVideoRes&&M.messages.setMaxVideoResolution(this._sock,this._maxVideoResolutionX,this._maxVideoResolutionY),this._pendingApplyResolutionChange&&(this._screenSize(),this._scaleViewport&&this._clipViewport&&this._updateClip(),this._updateScale(),!this._scaleViewport&&this._clipViewport&&this._updateClip(),this._display.screens.length>1&&this.refreshSecondaryDisplays(),(this._resizeSession||this._forcedResolutionX&&this._forcedResolutionY)&&(this.dispatchEvent(new CustomEvent("screenregistered",{})),clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(this._requestRemoteResize.bind(this),500))),this._pendingApplyEncodingChanges&&this._sendEncodings(),this._pendingApplyVideoRes=!1,this._pendingApplyEncodingChanges=!1,this._pendingApplyResolutionChange=!1):this._isPrimaryDisplay||(this._pendingApplyResolutionChange&&(this._scaleViewport&&this._clipViewport&&this._updateClip(),this._updateScale(),!this._scaleViewport&&this._clipViewport&&this._updateClip()),(this._resizeSession||this._forcedResolutionX&&this._forcedResolutionY)&&this._requestRemoteResize())}disconnect(){this._isPrimaryDisplay?(this._updateConnectionState("disconnecting"),this._sock.off("error"),this._sock.off("message"),this._sock.off("open"),this._proxyRFBMessage("disconnect")):(this._updateConnectionState("disconnecting"),this._unregisterSecondaryDisplay(),this._rfbConnectionState="",this._isFirstConnect=0)}terminate(){this._isPrimaryDisplay&&(this._updateConnectionState("disconnecting"),this._sock.off("error"),this._sock.off("message"),this._sock.off("open"),this._proxyRFBMessage("terminate"))}sendCtrlAltDel(){this._rfbConnectionState!=="connected"||this._viewOnly||(I("Sending Ctrl-Alt-Del"),this.sendKey(d.XK_Control_L,"ControlLeft",!0),this.sendKey(d.XK_Alt_L,"AltLeft",!0),this.sendKey(d.XK_Delete,"Delete",!0),this.sendKey(d.XK_Delete,"Delete",!1),this.sendKey(d.XK_Alt_L,"AltLeft",!1),this.sendKey(d.XK_Control_L,"ControlLeft",!1))}machineShutdown(){this._xvpOp(1,2)}machineReboot(){this._xvpOp(1,3)}machineReset(){this._xvpOp(1,4)}sendKey(e,t,s){if(this._rfbConnectionState!=="connected"||this._viewOnly)return;if(t!==null&&this._setLastActive(),s===void 0){this.sendKey(e,t,!0),this.sendKey(e,t,!1);return}const i=nn[t];if(this._qemuExtKeyEventSupported&&i)e=e||0,I("Sending key ("+(s?"down":"up")+"): keysym "+e+", scancode "+i),this._isPrimaryDisplay?M.messages.QEMUExtendedKeyEvent(this._sock,e,s,i):this._proxyRFBMessage("QEMUExtendedKeyEvent",[e,s,i]);else{if(!e)return;I("Sending keysym ("+(s?"down":"up")+"): "+e),this._isPrimaryDisplay?M.messages.keyEvent(this._sock,e,s?1:0):this._proxyRFBMessage("keyEvent",[e,s?1:0])}}focus(){this._keyboard.focus()}blur(){this._keyboard.blur()}checkLocalClipboard(){this.clipboardUp&&this.clipboardSeamless&&this._resendClipboardNextUserDrivenEvent&&(this._resendClipboardNextUserDrivenEvent=!1,this.clipboardBinary?navigator.clipboard.read().then(e=>{this.clipboardPasteDataFrom(e)},e=>{C("No data in clipboard: "+e)}):navigator.clipboard&&navigator.clipboard.readText&&navigator.clipboard.readText().then(function(e){this.clipboardPasteFrom(e)}.bind(this)).catch(function(){return C("Failed to read system clipboard")}))}clipboardPasteFrom(e){if(this._rfbConnectionState!=="connected"||this._viewOnly||!(typeof e=="string"&&e.length>0))return;let t=new TextEncoder().encode(e),s=Re(t);if(s===this._clipHash){C("No clipboard changes");return}else this._clipHash=s;let i=[],n=["text/plain"];i.push(t),this._isPrimaryDisplay?M.messages.sendBinaryClipboard(this._sock,i,n):this._proxyRFBMessage("sendBinaryClipboard",[i,n])}async clipboardPasteDataFrom(e){if(this._rfbConnectionState!=="connected"||this._viewOnly)return;let t=[],s=[],i=0;for(let n=0;n<e.length;n++)for(let r=0;r<e[n].types.length;r++){let a=e[n].types[r];switch(a){case"image/png":case"text/plain":case"text/html":let o=await e[n].getType(a);if(!o)continue;let h=await o.arrayBuffer(),u=new Uint8Array(h);
1if(!i)if(i=Re(u),i===this._clipHash){C("No clipboard changes");return}else this._clipHash=i;if(s.includes(a))continue;s.push(a),t.push(u),C("Sending mime type: "+a);break;default:I("skipping clip send mime type: "+a)}}if(s.includes("image/png")&&!s.includes("text/plain")){let n=s.indexOf("image/png");s=s.slice(n,n+1),t=t.slice(n,n+1)}else if(s.includes("image/png")&&s.includes("text/plain")){let n=s.indexOf("image/png");s.splice(n,1),t.splice(n,1)}t.length>0&&(this._isPrimaryDisplay?M.messages.sendBinaryClipboard(this._sock,t,s):this._proxyRFBMessage("sendBinaryClipboard",[t,s]))}requestBottleneckStats(){this._isPrimaryDisplay&&M.messages.requestStats(this._sock)}subscribeUnixRelay(e,t){this._isPrimaryDisplay&&(this._unixRelays=this._unixRelays||{},this._unixRelays[e]=t,M.messages.sendSubscribeUnixRelay(this._sock,e))}sendUnixRelayData(e,t){this._isPrimaryDisplay&&M.messages.sendUnixRelay(this._sock,e,t)}_setLastActive(){this.lastActiveAt=Date.now()}_changeTransitConnectionState(e){I("Transit state change from "+this._transitConnectionState.toString()+" to "+e.toString()),this._transitConnectionState=e}_setupWebSocket(){this._sock=new en,this._sock.on("message",()=>{this._handleMessage()}),this._sock.on("open",()=>{this._rfbConnectionState==="connecting"&&this._rfbInitState===""?(this._rfbInitState="ProtocolVersion",C("Starting VNC handshake")):this._fail("Unexpected server connection while "+this._rfbConnectionState)}),this._sock.on("close",e=>{C("WebSocket on-close event");let t="";switch(e.code&&(t="(code: "+e.code,e.reason&&(t+=", reason: "+e.reason),t+=")",this.errorCode=e.code),this._rfbConnectionState){case"connecting":this._fail("Connection closed "+t);break;case"connected":this._updateConnectionState("disconnecting"),this._updateConnectionState("disconnected");break;case"disconnecting":this._updateConnectionState("disconnected");break;case"disconnected":this._fail("Unexpected server disconnect when already disconnected "+t);break;default:this._fail("Unexpected server disconnect before connecting "+t);break}this._sock.off("close"),this._rawChannel=null}),this._sock.on("error",e=>{H("WebSocket on-error event",e)}),setTimeout(this._updateConnectionState.bind(this,"connecting"))}_connect(){if(C(">> RFB.connect"),this._url&&this._isPrimaryDisplay)try{I(`connecting to ${this._url}`),this._sock.open(this._url,this._wsProtocols),this._setLastActive()}catch(e){e.name==="SyntaxError"?this._fail("Invalid host or port ("+e+")"):this._fail("Error when opening socket ("+e+")")}else if(this._isPrimaryDisplay)try{I(`attaching ${this._rawChannel} to Websock`),this._sock.attach(this._rawChannel)}catch(e){this._fail("Error attaching channel ("+e+")")}if(this._target.appendChild(this._screen),this._gestures.attach(this._canvas),this._cursor.attach(this._canvas),this._refreshCursor(),window.addEventListener("resize",this._eventHandlers.windowResize),this._canvas.addEventListener("drag_cb",e=>{this.dispatchEvent(new CustomEvent("tap_cb",{detail:{}}))}),this._canvas.addEventListener("mousedown",this._eventHandlers.focusCanvas),this._canvas.addEventListener("touchstart",this._eventHandlers.focusCanvas),this._canvas.addEventListener("focus",this._eventHandlers.handleFocusChange),window.addEventListener("focus",this._eventHandlers.handleFocusChange),window.addEventListener("blur",this._eventHandlers.handleFocusChange),document.addEventListener("visibilitychange",this._eventHandlers.handleVisibilityChange),window.addEventListener("mouseover",this._eventHandlers.handleMouseOut),Qe()&&this._canvas.addEventListener("touchend",this._eventHandlers.updateHiddenKeyboard),this._canvas.addEventListener("mousedown",this._eventHandlers.handleMouse),this._canvas.addEventListener("mouseup",this._eventHandlers.handleMouse),this._canvas.addEventListener("mousemove",this._eventHandlers.handleMouse),this._canvas.addEventListener("click",this._eventHandlers.handleMouse),this._canvas.addEventListener("contextmenu",this._eventHandlers.handleMouse),document.onpointerlockchange!==void 0?(document.addEventListener("pointerlockchange",this._eventHandlers.handlePointerLockChange,!1),document.addEventListener("pointerlockerror",this._eventHandlers.handlePointerLockError,!1)):document.onmozpointerlockchange!==void 0&&(document.addEventListener("mozpointerlockchange",this._eventHandlers.handlePointerLockChange,!1),document.addEventListener("mozpointerlockerror",this._eventHandlers.handlePointerLockError,!1)),this._canvas.addEventListener("wheel",this._eventHandlers.handleWheel),this._canvas.addEventListener("gesturestart",this._eventHandlers.handleGesture),this._canvas.addEventListener("gesturemove",this._eventHandlers.handleGesture),this._canvas.addEventListener("gestureend",this._eventHandlers.handleGesture),this._resendClipboardNextUserDrivenEvent=!0,typeof RTCPeerConnection<"u"&&this._isPrimaryDisplay){this._udpBuffer=new Map,this._udpPeer=new RTCPeerConnection({iceServers:[{urls:["stun:stun.l.google.com:19302"]}]});let e=this._udpPeer;e.onicecandidate=function(i){i.candidate?C("received ice candidate",i.candidate):C("all candidates received")},e.ondatachannel=function(i){C("peer connection on data channel",i)}
1,this._udpChannel=e.createDataChannel("webudp",{ordered:!1,maxRetransmits:0}),this._udpChannel.binaryType="arraybuffer",this._udpChannel.onerror=function(i){Q("data channel error "+i.message),this._udpTransitFailures+=1,this._sendUdpDowngrade()},this._sock;let t=this._udpBuffer,s=this;this._udpChannel.onmessage=function(i){const n=new Uint8Array(i.data),r=parseInt(n[0]+(n[1]<<8)+(n[2]<<16)+(n[3]<<24),10),a=parseInt(n[4]+(n[5]<<8)+(n[6]<<16)+(n[7]<<24),10),o=parseInt(n[8]+(n[9]<<8)+(n[10]<<16)+(n[11]<<24),10);parseInt(n[12]+(n[13]<<8)+(n[14]<<16)+(n[15]<<24),10);const h=parseInt(n[16]+(n[17]<<8)+(n[18]<<16)+(n[19]<<24),10);if(s._transitConnectionState!==s.TransitConnectionStates.Udp&&(s._display.clear(),s._changeTransitConnectionState(s.TransitConnectionStates.Udp)),o==1)s._handleUdpRect(n.slice(20),h);else{const _=Date.now();if(t.has(r)){let w=t.get(r);if(w.recieved_pieces+=1,w.data[a]=n.slice(20),w.total_bytes+=w.data[a].length,w.total_pieces==w.recieved_pieces){var u=new Uint8Array(w.total_bytes);let k=0;for(let v=0;v<w.data.length;v++)u.set(w.data[v],k),k+=w.data[v].length;t.delete(r),s._handleUdpRect(u,h)}}else{let w={total_pieces:o,arrival:_,recieved_pieces:1,total_bytes:0,data:new Array(o)};w.data[a]=n.slice(20),w.total_bytes=w.data[a].length,t.set(r,w)}}}}this._useUdp&&typeof RTCPeerConnection<"u"&&this._isPrimaryDisplay&&setTimeout(function(){this._sendUdpUpgrade()}.bind(this),3e3),C("<< RFB.connect")}_disconnect(){C(">> RFB.disconnect"),this._cursor.detach(),this._canvas.removeEventListener("gesturestart",this._eventHandlers.handleGesture),this._canvas.removeEventListener("gesturemove",this._eventHandlers.handleGesture),this._canvas.removeEventListener("gestureend",this._eventHandlers.handleGesture),this._canvas.removeEventListener("wheel",this._eventHandlers.handleWheel),this._canvas.removeEventListener("mousedown",this._eventHandlers.handleMouse),this._canvas.removeEventListener("mouseup",this._eventHandlers.handleMouse),this._canvas.removeEventListener("mousemove",this._eventHandlers.handleMouse),this._canvas.removeEventListener("click",this._eventHandlers.handleMouse),this._canvas.removeEventListener("contextmenu",this._eventHandlers.handleMouse),document.onpointerlockchange!==void 0?(document.removeEventListener("pointerlockchange",this._eventHandlers.handlePointerLockChange),document.removeEventListener("pointerlockerror",this._eventHandlers.handlePointerLockError)):document.onmozpointerlockchange!==void 0&&(document.removeEventListener("mozpointerlockchange",this._eventHandlers.handlePointerLockChange),document.removeEventListener("mozpointerlockerror",this._eventHandlers.handlePointerLockError)),this._canvas.removeEventListener("mousedown",this._eventHandlers.focusCanvas),this._canvas.removeEventListener("touchstart",this._eventHandlers.focusCanvas),this._canvas.removeEventListener("focus",this._eventHandlers.handleFocusChange),window.removeEventListener("resize",this._eventHandlers.windowResize),window.removeEventListener("focus",this._eventHandlers.handleFocusChange),document.removeEventListener("visibilitychange",this._eventHandlers.handleVisibilityChange),this._keyboard.ungrab(),this._gestures.detach(),this._isPrimaryDisplay?this._sock.close():this._primaryDisplayChannel&&(this._primaryDisplayChannel.postMessage({eventType:"unregister",screenID:this._display.screenID}),this._primaryDisplayChannel.removeEventListener("message",this._handleSecondaryDisplayMessage),this._primaryDisplayChannel.close(),this._primaryDisplayChannel=null);try{this._target.removeChild(this._screen)}catch(e){if(e.name!=="NotFoundError")throw e}this._display.dispose(),clearTimeout(this._resizeTimeout),clearTimeout(this._mouseMoveTimer),window.localStorage.removeItem("lastWindow"),C("<< RFB.disconnect")}_updateHiddenKeyboard(e){const t=Math.max(0,e.pageY-50);document.querySelector("#qinghu_keyboard_input").style.top=`${t}px`}_handleFocusChange(e){if(this._resendClipboardNextUserDrivenEvent=!0,e.type=="focus"&&e.currentTarget instanceof Window)if(this._lastVisibilityState==="visible"){const t=window.localStorage.getItem("lastWindow");C("Window focused while user switched between windows."),t!=e.currentTarget.name&&(this._sendLeftClickonNextMove=!0,window.localStorage.setItem("lastWindow",e.currentTarget.name))}else C("Window focused while user switched between tabs.");document.visibilityState==="visible"&&this._lastVisibilityState==="hidden"&&(C("Window is now visible."),this._lastVisibilityState=document.visibilityState)}_handleVisibilityChange(e){document.visibilityState==="hidden"&&(this._lastVisibilityState=document.visibilityState,C("Window is not visible."))}_focusCanvas(e){window.parent.postMessage({action:"enable_audio",value:null},"*"),!this._pointerLock&&this._pointerRelativeEnabled&&(this.pointerLock=!0),this._resendClipboardNextUserDrivenEvent&&this.checkLocalClipboard(),this.focusOnClick&&this.focus()}_setDesktopName(e){this._fbName=e,this.dispatchEvent(new CustomEvent("desktopname",{detail:{name:this._fbName}}))}_windowResize(e){window.requestAnimationFrame(()=>{this._screenSize(),this._updateClip(),this._updateScale()}),this.dispatchEvent(new CustomEvent("screenregistered",{})),this._resizeSession&&(clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(this._requestRemoteResize.bind(this),500))}_updateClip(){const e=this._display.clipViewport;let t=this._clipViewport;if(this._scaleViewport&&(t=!1),e!==t&&(this._display.clipViewport=t),t){const s=this._screenSize();this._display.viewportChangeSize(s.screens[0].serverWidth,s.screens[0].serverHeight),this._fixScrollbars()}}_updateScale(){if(!this._scaleViewport)this._display.scale=1;else{const e=this._screenSize();this._display.autoscale(e.screens[0].width,e.screens[0].height,e.screens[0].scale)}
1this._fixScrollbars()}_requestRemoteResize(){if(clearTimeout(this._resizeTimeout),this._resizeTimeout=null,this._isPrimaryDisplay){if(this._viewOnly||!this._supportsSetDesktopSize||!this._resizeSession&&!this._forcedResolutionX&&!this._forcedResolutionY)return;for(let t=0;t<this._display.screens.length;t++)this._display.applyServerResolution(0,0,this._display.screens[t].screenIndex);const e=this._screenSize();this._forceFullFrameUpdateAfterResize=!0,M.messages.setDesktopSize(this._sock,e,this._screenFlags),C("Requested new desktop size: "+e.serverWidth+"x"+e.serverHeight)}else if(this._display.screenIndex>0){let e=null;window.localStorage.getItem("autoPlacement")===null&&(e={left:window.screenLeft,top:window.screenTop}),this._registerSecondaryDisplay(this._display.screens[0],e)}}_screenSize(e){return this._display.getScreenSize(this.videoQuality,this.forcedResolutionX,this.forcedResolutionY,this._hiDpi,e,!this._resizeSession)}_fixScrollbars(){const e=this._screen.style.overflow;this._screen.style.overflow="hidden",this._screen.getBoundingClientRect(),this._screen.style.overflow=e}_updateConnectionState(e){const t=this._rfbConnectionState;if(e===t){C("Already in state '"+e+"', ignoring");return}if(t==="disconnected"){Q("Tried changing state of a disconnected RFB object");return}switch(e){case"connected":if(t!=="connecting"){Q("Bad transition to connected state, previous connection state: "+t);return}break;case"disconnected":if(t!=="disconnecting"){Q("Bad transition to disconnected state, previous connection state: "+t);return}break;case"connecting":if(t!==""){Q("Bad transition to connecting state, previous connection state: "+t);return}break;case"disconnecting":if(t!=="connected"&&t!=="connecting"){Q("Bad transition to disconnecting state, previous connection state: "+t);return}break;case"proxied":break;default:Q("Unknown connection state: "+e);return}switch(this._rfbConnectionState=e,C("New state '"+e+"', was '"+t+"'."),this._disconnTimer&&e!=="disconnecting"&&(C("Clearing disconnect timer"),clearTimeout(this._disconnTimer),this._disconnTimer=null,this._isPrimaryDisplay&&this._sock.off("close")),e){case"connecting":this._connect();break;case"connected":this.dispatchEvent(new CustomEvent("connect",{detail:{}}));break;case"disconnecting":this._disconnect(),this._disconnTimer=setTimeout(()=>{Q("Disconnection timed out."),this._updateConnectionState("disconnected"),this._proxyRFBMessage("secondarydisconnected")},_n*1e3);break;case"disconnected":this.dispatchEvent(new CustomEvent("disconnect",{detail:{clean:this._rfbCleanDisconnect,code:this.errorCode}})),this.errorCode=0;break}}_fail(e){switch(this._rfbConnectionState){case"disconnecting":Q("Failed when disconnecting: "+e);break;case"connected":Q("Failed while connected: "+e);break;case"connecting":Q("Failed when connecting: "+e);break;default:Q("RFB failure: "+e);break}return this._rfbCleanDisconnect=!1,this._updateConnectionState("disconnecting"),this._updateConnectionState("disconnected"),!1}_setCapability(e,t){this._capabilities[e]=t,this.dispatchEvent(new CustomEvent("capabilities",{detail:{capabilities:this._capabilities}}))}_proxyRFBMessage(e,t){let s={eventType:e,args:t,screenID:this._display.screenID,screenIndex:this._display.screenIndex,mouseLastScreenIndex:this._mouseLastScreenIndex};this._controlChannel.postMessage(s)}_handleControlMessage(e){if(this._isPrimaryDisplay){let t;switch(e.data.eventType){case"register":const s={...e.data.details,screenID:e.data.screenID};let i=this._display.addScreen(e.data.screenID,e.data.width,e.data.height,e.data.pixelRatio,e.data.containerHeight,e.data.containerWidth,e.data.scale,e.data.serverWidth,e.data.serverHeight,e.data.x,e.data.y);this._proxyRFBMessage("screenRegistrationConfirmed",[this._display.screens[i].screenID,i]),this._sendEncodings(),clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(this._requestRemoteResize.bind(this),500),this.dispatchEvent(new CustomEvent("screenregistered",{detail:s})),I(`Secondary monitor (${e.data.screenID}) has been registered.`);break;case"reattach":this._display.addScreen(e.data.screenID,e.data.width,e.data.height,e.data.pixelRatio,e.data.containerHeight,e.data.containerWidth,e.data.scale,e.data.serverWidth,e.data.serverHeight,e.data.x,e.data.y),clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(this._requestRemoteResize.bind(this),500),this.dispatchEvent(new CustomEvent("screenregistered",{})),I(`Secondary monitor (${e.data.screenID}) has been reattached.`);break;case"unregister":if(this._display.removeScreen(e.data.screenID)){this.dispatchEvent(new CustomEvent("screenregistered",{})),I(`Secondary monitor (${e.data.screenID}) has been removed.`);const n=this._screenSize();M.messages.setDesktopSize(this._sock,n,this._screenFlags),this._sendEncodings(),this._updateContinuousUpdates(),this.dispatchEvent(new CustomEvent("screenregistered",{}))}else I(`Secondary monitor (${e.data.screenID}) not found.`);break;case"mousemove":t=this._display.getServerRelativeCoordinates(e.data.screenIndex,e.data.args[0],e.data.args[
11]),this._mouseLastScreenIndex=e.data.screenIndex,this._mousePos={x:t[0],y:t[1]},this._mouseButtonMask!==0&&!e.data.args[2]&&(this._mouseButtonMask=0),M.messages.pointerEvent(this._sock,this._mousePos.x,this._mousePos.y,this._mouseButtonMask),e.data.args[3]&&(this._mouseButtonMask|=1,M.messages.pointerEvent(this._sock,this._mousePos.x,this._mousePos.y,this._mouseButtonMask),this._mouseButtonMask&=-2,M.messages.pointerEvent(this._sock,this._mousePos.x,this._mousePos.y,this._mouseButtonMask),C("Simulated Left Click on secondary display."));break;case"mousedown":t=this._display.getServerRelativeCoordinates(e.data.screenIndex,e.data.args[0],e.data.args[1]),this._mouseLastScreenIndex=e.data.screenIndex,this._mousePos={x:t[0],y:t[1]},this._mouseButtonMask|=e.data.args[2],M.messages.pointerEvent(this._sock,this._mousePos.x,this._mousePos.y,this._mouseButtonMask);break;case"mouseup":t=this._display.getServerRelativeCoordinates(e.data.screenIndex,e.data.args[0],e.data.args[1]),this._mouseLastScreenIndex=e.data.screenIndex,this._mousePos={x:t[0],y:t[1]},this._mouseButtonMask&=~e.data.args[2],M.messages.pointerEvent(this._sock,this._mousePos.x,this._mousePos.y,this._mouseButtonMask);break;case"scroll":t=this._display.getServerRelativeCoordinates(e.data.screenIndex,e.data.args[0],e.data.args[1]),this._mouseLastScreenIndex=e.data.screenIndex,this._mousePos={x:t[0],y:t[1]},M.messages.pointerEvent(this._sock,this._mousePos.x,this._mousePos.y,0,e.data.args[2],e.data.args[3]);break;case"keyEvent":M.messages.keyEvent(this._sock,...e.data.args);break;case"sendBinaryClipboard":M.messages.sendBinaryClipboard(this._sock,...e.data.args);break}}else switch(e.data.eventType){case"updateCursor":this._updateCursor(...e.data.args),this._mouseLastScreenIndex=e.data.mouseLastScreenIndex;break;case"receivedClipboard":e.data.mouseLastScreenIndex===this._display.screenIndex&&this._write_binary_clipboard(...e.data.args);break;case"disconnect":this.disconnect();break;case"terminate":this.disconnect(),window.close();break;case"applySettings":this._isPrimaryDisplay||(this.enableHiDpi=e.data.args[0],this.clipViewport=e.data.args[1],this.scaleViewport=e.data.args[2],this.resizeSession=e.data.args[3],this.videoQuality=e.data.args[4],this.scaleViewport=e.data.args[3],this.updateConnectionSettings());break;case"applyScreenPlan":e.data.args[0]==this._display.screenID&&(this._display.screens[0].screenIndex=e.data.args[1],this._display.screens[0].width=e.data.args[2],this._display.screens[0].height=e.data.args[3],this._display.screens[0].x=e.data.args[4],this._display.screens[0].y=e.data.args[5],this.updateConnectionSettings());break;case"screenRegistrationConfirmed":e.data.args[0]==this._display.screenID&&(this._display.screens[0].screenIndex=e.data.args[1]);break}}_unregisterSecondaryDisplay(){if(!this._isPrimaryDisplay){let e={eventType:"unregister",screenID:this._display.screenID};this._controlChannel.postMessage(e)}}_registerSecondaryDisplay(e=!1,t=null){if(!this._isPrimaryDisplay){const s=e?"reattach":"register";let i=this._screenSize();this._display.resize(i.screens[0].serverWidth,i.screens[0].serverHeight),this._display.autoscale(i.screens[0].serverWidth,i.screens[0].serverHeight,i.screens[0].scale);let n=i.screens[0],r={eventType:s,screenID:n.screenID,width:n.width,height:n.height,x:e.x||0,y:e.y||0,pixelRatio:n.pixelRatio,scale:n.scale,serverWidth:n.serverWidth,serverHeight:n.serverHeight,containerWidth:n.containerWidth,containerHeight:n.containerHeight,channel:null,details:t};return this._controlChannel.postMessage(r),this._viewOnly||this._keyboard.grab(),n}}identify(e){let t={eventType:"identify",screens:e};this._controlChannel.postMessage(t)}_handleSecondaryDisplayMessage(e){this._isPrimaryDisplay}_handleMessage(){if(this._sock.rQlen===0){H("handleMessage called on an empty receive queue");return}switch(this._rfbConnectionState){case"disconnected":Q("Got data while disconnected");break;case"connected":for(;!(this._flushing||!this._normalMsg()||this._sock.rQlen===0););break;default:this._initMsg();break}}_handleKeyEvent(e,t,s){this.sendKey(e,t,s)}_handleMouseOut(e){e.toElement!==null&&e.relatedTarget===null&&e.fromElement===null&&this._display.screens[0].pixelRatio!==window.devicePixelRatio&&(C("Window moved to another screen with different pixel ratio, sending resize request."),this._isPrimaryDisplay&&this._display.screens.length>1?this.dispatchEvent(new CustomEvent("screenregistered",{})):this._requestRemoteResize())}_handleMouse(e){if(e.type==="click"&&e.target!==this._canvas)return;if(e.stopPropagation(),e.type==="click"||e.type==="contextmenu"){e.preventDefault();return}let t;if(this._pointerLock&&!this._pointerRelativeEnabled){let i=this._display.scale===1?this._fbWidth:this._fbWidth*this._display.scale,n=this._display.scale===1?this._fbHeight:this._fbHeight*this._display.scale;t={x:this._mousePos.x+e.movementX,y:this._mousePos.y+e.movementY},t.x<0?t.x=0:t.x>i&&(t.x=i),t.y<0?t.y=0:t.y>n&&(t.y=n),this._cursor.move(t.x,t.y)}else this._pointerLock&&this._pointerRelativeEnabled?t={x:this._mousePos.x+e.movementX,y:this._mousePos.y+e.movementY}:t=Fe(e.clientX,e.clientY,this._canvas);this._mouseLastScreenIndex=this._display.screenIndex,this._setLastActive();const s=this.mouseButtonMapper.get(e.button);switch(e.type){case"mousedown":(this._display.screens.length===0||window.self===window.top)&&e.preventDefault(),Di(this._canvas),pe()&&e.metaKey&&(this._keyboard._keyDownList.MetaLeft||this._keyboard._keyDownList.MetaRight)&&(this._keyboard._sendKeyEvent(this._keyboard._keyDownList.MetaLeft,"MetaLeft",!1),this._keyboard._sendKeyEvent(this._keyboard._keyDownList.MetaRight,"MetaRight",!1),this._keyboard._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0)),this._keyboard.clearKeysDown(e),this._isPrimaryDisplay?this._handleMouseButton(t.x,t.y,!0,Ne(s)):this._proxyRFBMessage("mousedown",[t.x,t.y,Ne(s)]),C("Mouse Down");break;case"mouseup":e.preventDefault(),this._isPrimaryDisplay?this._handleMouseButton(t.x,t.y,!1,Ne(s)):this._proxyRFBMessage("mouseup",[t.x,t.y,Ne(s)]),C("Mouse Up");break;case"mousemove":e.preventDefault(),this._isPrimaryDisplay?this._handleMouseMove(t.x,t.y,e.buttons>0):(this._proxyRFBMessage("mousemove",[t.x,t.y,e.buttons>0,this._sendLeftClickonNextMove]),this._sendLeftClickonNextMove=!1);break;default:e.preventDefault();break}}_handleMouseButton(e,t,s,i){if(this.dragViewport)if(s&&!this._viewportDragging){this._viewportDragging=!0,this._viewportDragPos={x:e,y:t},this._viewportHasMoved=!1;return}else{if(this._viewportDragging=!1,this._viewportHasMoved)return;this._sendMouse(e,t,i)}this._mouseMoveTimer!==null&&(clearTimeout(this._mouseMoveTimer),this._mouseMoveTimer=null,this._sendMouse(e,t,this._mouseButtonMask)),s?this._mouseButtonMask|=i:this._mouseButtonMask&=~i,this._sendMouse(e,t,this._mouseButtonMask),this._sendLeftClickonNextMove=!1}_handleMouseMove(e,t,s,i=!1){if(this._viewportDragging){const n=this._viewportDragPos.x-e,r=this._viewportDragPos.y-t;(this._viewportHasMoved||Math.abs(n)>Kt||Math.abs(r)>Kt)&&(this._viewportHasMoved=!0,this._viewportDragPos={x:e,y:t},this._display.viewportChangePos(n,r));return}if(this._display.screens.length>1&&this._mouseButtonMask!==0&&!s&&!i&&Mi()&&(this._mouseButtonMask=0,C("Mouse event button down mismatch with current mask, resetting mask to 0.")),this._mousePos={x:e,y:t},this._mouseMoveTimer==null){const n=Date.now()-this._mouseLastMoveTime;n>qt?(this._sendMouse(e,t,this._mouseButtonMask),this._mouseLastMoveTime=Date.now()):this._mouseMoveTimer=setTimeout(()=>{this._handleDelayedMouseMove()},qt-n)}this._sendLeftClickonNextMove&&this._display.screens.length>1&&(this._sendLeftClickonNextMove=!1,this._handleMouseButton(this._mousePos.x,this._mousePos.y,!0,1),this._handleMouseButton(this._mousePos.x,this._mousePos.y,!1,1))}_handleDelayedMouseMove(){this._mouseMoveTimer=null,this._sendMouse(this._mousePos.x,this._mousePos.y,this._mouseButtonMask),this._mouseLastMoveTime=Date.now()}_handlePointerLockChange(e){document.pointerLockElement===this._canvas||document.mozPointerLockElement===this._canvas?(this._pointerLock=!0,this._cursor.setEmulateCursor(!0)):(this._pointerLock=!1,this._cursor.setEmulateCursor(!1)),this.dispatchEvent(new CustomEvent("inputlock",{detail:{pointer:this._pointerLock}}))}_handlePointerLockError(){this._pointerLockChanging=!1,this.dispatchEvent(new CustomEvent("inputlockerror",{detail:{pointer:this._pointerLock}}))}_sendMouse(e,t,s){if(this._rfbConnectionState==="connected"&&!this._viewOnly&&this._isPrimaryDisplay)if(this._pointerLock&&this._pointerRelativeEnabled){var i=Rt(e-this._pointerLockPos.x),n=Rt(t-this._pointerLockPos.y);M.messages.pointerEvent(this._sock,i,n,s),this._mousePos={x:this._pointerLockPos.x,y:this._pointerLockPos.y},this._cursor.move(this._pointerLockPos.x,this._pointerLockPos.y)}else M.messages.pointerEvent(this._sock,this._display.absX(e),this._display.absY(t),s)}_sendScroll(e,t,s,i){this._rfbConnectionState==="connected"&&(this._viewOnly||(this._isPrimaryDisplay?M.messages.pointerEvent(this._sock,this._display.absX(e),this._display.absY(t),
10,s,i):this._proxyRFBMessage("scroll",[e,t,s,i])))}_handleWheel(e){if(this._rfbConnectionState!=="connected"||this._viewOnly)return;e.stopPropagation(),e.preventDefault(),this._keyboard.clearKeysDown(e),pe()&&(this._keyboard._keyDownList.MetaLeft||this._keyboard._keyDownList.MetaRight)&&(this._keyboard._sendKeyEvent(this._keyboard._keyDownList.MetaLeft,"MetaLeft",!1),this._keyboard._sendKeyEvent(this._keyboard._keyDownList.MetaRight,"MetaRight",!1),this._keyboard._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0)),e.ctrlKey&&!this._keyboard._keyDownList.ControlLeft&&(this._keyboard._sendKeyEvent(d.XK_Control_L,"ControlLeft",!0),this._watchForPinchAndZoom=this._watchForPinchAndZoom||setInterval(()=>{+new Date-this._mouseLastPinchAndZoomTime>250&&(clearInterval(this._watchForPinchAndZoom),this._keyboard._sendKeyEvent(d.XK_Control_L,"ControlLeft",!1),this._watchForPinchAndZoom=null,this._mouseLastPinchAndZoomTime=0)},10)),this._watchForPinchAndZoom&&(this._mouseLastPinchAndZoomTime=+new Date);let t=e.deltaX,s=e.deltaY;e.deltaMode!==0&&(t*=$t,s*=$t);const i=Fe(e.clientX,e.clientY,this._canvas);this._sendScroll(i.x,i.y,t,s)}_fakeMouseMove(e,t,s){this._isPrimaryDisplay?(this._handleMouseMove(t,s,!1,!0),this._cursor.move(e.detail.clientX,e.detail.clientY)):(this._proxyRFBMessage("mousemove",[t,s,!0,!1]),this._cursor.move(e.detail.clientX,e.detail.clientY))}_handleTapEvent(e,t){let s=Fe(e.detail.clientX,e.detail.clientY,this._canvas);if(this._gestureLastTapTime!==null&&Date.now()-this._gestureLastTapTime<pn&&this._gestureFirstDoubleTapEv.detail.type===e.detail.type){let i=this._gestureFirstDoubleTapEv.detail.clientX-e.detail.clientX,n=this._gestureFirstDoubleTapEv.detail.clientY-e.detail.clientY;Math.hypot(i,n)<xn?s=Fe(this._gestureFirstDoubleTapEv.detail.clientX,this._gestureFirstDoubleTapEv.detail.clientY,this._canvas):this._gestureFirstDoubleTapEv=e}else this._gestureFirstDoubleTapEv=e;this._gestureLastTapTime=Date.now(),this._fakeMouseMove(this._gestureFirstDoubleTapEv,s.x,s.y),this._fakeMouseButton(s.x,s.y,!0,t),this._fakeMouseButton(s.x,s.y,!1,t)}_fakeMouseButton(e,t,s,i){this._isPrimaryDisplay?this._handleMouseButton(e,t,s,i):s?this._proxyRFBMessage("mousedown",[e,t,i]):this._proxyRFBMessage("mouseup",[e,t,i])}_handleGesture(e){let t,s=Fe(e.detail.clientX,e.detail.clientY,this._canvas);switch(e.type){case"gesturestart":switch(e.detail.type){case"onetap":this.dispatchEvent(new CustomEvent("tap_cb",{detail:{pos:s}})),this._handleTapEvent(e,1);break;case"twotap":this._handleTapEvent(e,4);break;case"threetap":this._handleTapEvent(e,2);break;case"drag":this._fakeMouseMove(e,s.x,s.y),this._fakeMouseButton(s.x,s.y,!0,1);break;case"swipe":this._gestureLastMagnitudeX=e.detail.magnitudeX,this._gestureLastMagnitudeY=e.detail.magnitudeY,this._fakeMouseMove(e,s.x,s.y);break;case"longpress":this._fakeMouseMove(e,s.x,s.y),this._fakeMouseButton(s.x,s.y,!0,4);break;case"twodrag":this._gestureLastMagnitudeX=e.detail.magnitudeX,this._gestureLastMagnitudeY=e.detail.magnitudeY,this._fakeMouseMove(e,s.x,s.y);break;case"pinch":this._gestureLastMagnitudeX=Math.hypot(e.detail.magnitudeX,e.detail.magnitudeY),this._fakeMouseMove(e,s.x,s.y);break}break;case"gesturemove":switch(e.detail.type){case"onetap":case"twotap":case"threetap":break;case"drag":case"longpress":this._fakeMouseMove(e,s.x,s.y);break;case"swipe":case"twodrag":for(this._fakeMouseMove(e,s.x,s.y);e.detail.magnitudeY-this._gestureLastMagnitudeY>ae;)this._fakeMouseButton(s.x,s.y,!0,8),this._fakeMouseButton(s.x,s.y,!1,8),this._gestureLastMagnitudeY+=ae;for(;e.detail.magnitudeY-this._gestureLastMagnitudeY<-ae;)this._fakeMouseButton(s.x,s.y,!0,16),this._fakeMouseButton(s.x,s.y,!1,16),this._gestureLastMagnitudeY-=ae;for(;e.detail.magnitudeX-this._gestureLastMagnitudeX>ae;)this._fakeMouseButton(s.x,s.y,!0,32),this._fakeMouseButton(s.x,s.y,!1,32),this._gestureLastMagnitudeX+=ae;for(;e.detail.magnitudeX-this._gestureLastMagnitudeX<-ae;)this._fakeMouseButton(s.x,s.y,!0,64),this._fakeMouseButton(s.x,s.y,!1,64),this._gestureLastMagnitudeX-=ae;break;case"pinch":if(this._fakeMouseMove(e,s.x,s.y),t=Math.hypot(e.detail.magnitudeX,e.detail.magnitudeY),Math.abs(t-this._gestureLastMagnitudeX)>Ke){for(this._handleKeyEvent(d.XK_Control_L,"ControlLeft",!0);t-this._gestureLastMagnitudeX>Ke;)this._fakeMouseButton(s.x,s.y,!0,8),this._fakeMouseButton(s.x,s.y,!1,8),this._gestureLastMagnitudeX+=Ke;for(;t-this._gestureLastMagnitudeX<-Ke;)this._fakeMouseButton(s.x,s.y,!0,16),this._fakeMouseButton(s.x,s.y,!1,16),this._gestureLastMagnitudeX-=Ke}this._handleKeyEvent(d.XK_Control_L,"ControlLeft",!1);break}break;
1case"gestureend":switch(e.detail.type){case"onetap":case"twotap":case"threetap":case"pinch":case"swipe":case"twodrag":break;case"drag":this._fakeMouseMove(e,s.x,s.y),this._fakeMouseButton(s.x,s.y,!1,1);break;case"longpress":this._fakeMouseMove(e,s.x,s.y),this._fakeMouseButton(s.x,s.y,!1,4);break}break}}_negotiateProtocolVersion(){if(this._sock.rQwait("version",12))return!1;const e=this._sock.rQshiftStr(12).substr(4,7);I("Server ProtocolVersion: "+e);let t=0;switch(e){case"000.000":t=1;break;case"003.003":case"003.006":case"003.889":this._rfbVersion=3.3;break;case"003.007":this._rfbVersion=3.7;break;case"003.008":case"004.000":case"004.001":case"005.000":this._rfbVersion=3.8;break;default:return this._fail("Invalid server version "+e)}if(t){let i="ID:"+this._repeaterID;for(;i.length<250;)i+="\0";return this._sock.sendString(i),!0}this._rfbVersion>this._rfbMaxVersion&&(this._rfbVersion=this._rfbMaxVersion);const s="00"+parseInt(this._rfbVersion,10)+".00"+this._rfbVersion*10%10;this._sock.sendString("RFB "+s+` 2`),C("Sent ProtocolVersion: "+s),this._rfbInitState="Security"}_negotiateSecurity(){if(this._rfbVersion>=3.7){const e=this._sock.rQshift8();if(this._sock.rQwait("security type",e,1))return!1;if(e===0)return this._rfbInitState="SecurityReason",this._securityContext="no security types",this._securityStatus=1,this._initMsg();const t=this._sock.rQshiftBytes(e);if(C("Server security types: "+t),t.includes(1))this._rfbAuthScheme=1;else if(t.includes(22))this._rfbAuthScheme=22;else if(t.includes(16))this._rfbAuthScheme=16;else if(t.includes(2))this._rfbAuthScheme=2;else if(t.includes(19))this._rfbAuthScheme=19;else return this._fail("Unsupported security types (types: "+t+")");this._sock.send([this._rfbAuthScheme])}else{if(this._sock.rQwait("security scheme",4))return!1;if(this._rfbAuthScheme=this._sock.rQshift32(),this._rfbAuthScheme==0)return this._rfbInitState="SecurityReason",this._securityContext="authentication scheme",this._securityStatus=1,this._initMsg()}return this._rfbInitState="Authentication",C("Authenticating using scheme: "+this._rfbAuthScheme),this._initMsg()}_handleSecurityReason(){if(this._sock.rQwait("reason length",4))return!1;const e=this._sock.rQshift32();let t="";if(e>0){if(this._sock.rQwait("reason",e,4))return!1;t=this._sock.rQshiftStr(e)}return t!==""?(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:this._securityStatus,reason:t}})),this._fail("Security negotiation failed on "+this._securityContext+" (reason: "+t+")")):(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:this._securityStatus}})),this._fail("Security negotiation failed on "+this._securityContext))}_negotiateXvpAuth(){if(this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0||this._rfbCredentials.target===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password","target"]}})),!1;const e=String.fromCharCode(this._rfbCredentials.username.length)+String.fromCharCode(this._rfbCredentials.target.length)+this._rfbCredentials.username+this._rfbCredentials.target;return this._sock.sendString(e),this._rfbAuthScheme=2,this._negotiateAuthentication()}_negotiateVeNCryptAuth(){if(this._rfbVeNCryptState==0){if(this._sock.rQwait("vencrypt version",2))return!1;const e=this._sock.rQshift8(),t=this._sock.rQshift8();if(!(e==0&&t==2))return this._fail("Unsupported VeNCrypt version "+e+"."+t);this._sock.send([0,2]),this._rfbVeNCryptState=1}if(this._rfbVeNCryptState==1){if(this._sock.rQwait("vencrypt ack",1))return!1;const e=this._sock.rQshift8();if(e!=0)return this._fail("VeNCrypt failure "+e);this._rfbVeNCryptState=2}if(this._rfbVeNCryptState==2){if(this._sock.rQwait("vencrypt subtypes length",1))return!1;const e=this._sock.rQshift8();if(e<1)return this._fail("VeNCrypt subtypes empty");this._rfbVeNCryptSubtypesLength=e,this._rfbVeNCryptState=3}if(this._rfbVeNCryptState==3){if(this._sock.rQwait("vencrypt subtypes",4*this._rfbVeNCryptSubtypesLength))return!1;const e=[];for(let t=0;t<this._rfbVeNCryptSubtypesLength;t++)e.push(this._sock.rQshift32());if(e.indexOf(256)!=-1)this._sock.send([0,0,1,0]),this._rfbVeNCryptState=4;else return this._fail("VeNCrypt Plain subtype not offered by server")}if(this._rfbVeNCryptState==4){if(this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0)return this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1;const e=dt(this._rfbCredentials.username),t=dt(this._rfbCredentials.password);return this._sock.send([e.length>>24&255,e.length>>16&255,e.length>>8&255,e.length&255]),this._sock.send([t.length>>24&255,t.length>>16&255,t.length>>8&255,t.length&255]),this._sock.sendString(e),this._sock.sendString(t),this._rfbInitState="SecurityResult",!0}}_negotiateStdVNCAuth(){if(this._sock.rQwait("auth challenge",16))return!1;this._rfbCredentials.password="";const e=Array.prototype.slice.call(this._sock.rQshiftBytes(16)),t=M.genDES(this._rfbCredentials.password,e);return this._sock.send(t),this._rfbInitState="SecurityResult",!0}_negotiateTightUnixAuth(){return this._rfbCredentials.username===void 0||this._rfbCredentials.password===void 0?(this.dispatchEvent(new CustomEvent("credentialsrequired",{detail:{types:["username","password"]}})),!1):(this._sock.send([0,0,0,this._rfbCredentials.username.length]),this._sock.send([0,0,0,this._rfbCredentials.password.length]),this._sock.sendString(this._rfbCredentials.username),this._sock.sendString(this._rfbCredentials.password),this._rfbInitState="SecurityResult",!0)}
2_negotiateTightTunnels(e){const t={0:{vendor:"TGHT",signature:"NOTUNNEL"}},s={};for(let i=0;i<e;i++){const n=this._sock.rQshift32(),r=this._sock.rQshiftStr(4),a=this._sock.rQshiftStr(8);s[n]={vendor:r,signature:a}}return C("Server Tight tunnel types: "+s),s[1]&&s[1].vendor==="SICR"&&s[1].signature==="SCHANNEL"&&(C("Detected Siemens server. Assuming NOTUNNEL support."),s[0]={vendor:"TGHT",signature:"NOTUNNEL"}),s[0]?s[0].vendor!=t[0].vendor||s[0].signature!=t[0].signature?this._fail("Client's tunnel type had the incorrect vendor or signature"):(C("Selected tunnel type: "+t[0]),this._sock.send([0,0,0,0]),!1):this._fail("Server wanted tunnels, but doesn't support the notunnel type")}_negotiateTightAuth(){if(!this._rfbTightVNC){if(this._sock.rQwait("num tunnels",4))return!1;const i=this._sock.rQshift32();if(i>0&&this._sock.rQwait("tunnel capabilities",16*i,4))return!1;if(this._rfbTightVNC=!0,i>0)return this._negotiateTightTunnels(i),!1}if(this._sock.rQwait("sub auth count",4))return!1;const e=this._sock.rQshift32();if(e===0)return this._rfbInitState="SecurityResult",!0;if(this._sock.rQwait("sub auth capabilities",16*e,4))return!1;const t={STDVNOAUTH__:1,STDVVNCAUTH_:2,TGHTULGNAUTH:129},s=[];for(let i=0;i<e;i++){this._sock.rQshift32();const n=this._sock.rQshiftStr(12);s.push(n)}C("Server Tight authentication types: "+s);for(let i in t)if(s.indexOf(i)!=-1)switch(this._sock.send([0,0,0,t[i]]),C("Selected authentication type: "+i),i){case"STDVNOAUTH__":return this._rfbInitState="SecurityResult",!0;case"STDVVNCAUTH_":return this._rfbAuthScheme=2,this._initMsg();case"TGHTULGNAUTH":return this._rfbAuthScheme=129,this._initMsg();default:return this._fail("Unsupported tiny auth scheme (scheme: "+i+")")}return this._fail("No supported sub-auth types!")}_negotiateAuthentication(){switch(this._rfbAuthScheme){case 1:return this._rfbVersion>=3.8?(this._rfbInitState="SecurityResult",!0):(this._rfbInitState="ClientInitialisation",this._initMsg());case 22:return this._negotiateXvpAuth();case 2:return this._negotiateStdVNCAuth();case 16:return this._negotiateTightAuth();case 19:return this._negotiateVeNCryptAuth();case 129:return this._negotiateTightUnixAuth();default:return this._fail("Unsupported auth scheme (scheme: "+this._rfbAuthScheme+")")}}_handleSecurityResult(){if(this._sock.rQwait("VNC auth response ",4))return!1;const e=this._sock.rQshift32();return e===0?(this._rfbInitState="ClientInitialisation",C("Authentication OK"),this._initMsg()):this._rfbVersion>=3.8?(this._rfbInitState="SecurityReason",this._securityContext="security result",this._securityStatus=e,this._initMsg()):(this.dispatchEvent(new CustomEvent("securityfailure",{detail:{status:e}})),this._fail("Security handshake failed"))}_negotiateServerInit(){if(this._sock.rQwait("server initialization",24))return!1;const e=this._sock.rQshift16(),t=this._sock.rQshift16(),s=this._sock.rQshift8(),i=this._sock.rQshift8(),n=this._sock.rQshift8(),r=this._sock.rQshift8(),a=this._sock.rQshift16(),o=this._sock.rQshift16(),h=this._sock.rQshift16(),u=this._sock.rQshift8(),_=this._sock.rQshift8(),w=this._sock.rQshift8();this._sock.rQskipBytes(3);const k=this._sock.rQshift32();if(this._sock.rQwait("server init name",k,24))return!1;let v=this._sock.rQshiftStr(k);if(v=rt(v,!0),this._rfbTightVNC){if(this._sock.rQwait("TightVNC extended server init header",8,24+k))return!1;const K=this._sock.rQshift16(),R=this._sock.rQshift16(),P=this._sock.rQshift16();this._sock.rQskipBytes(2);const G=(K+R+P)*16;if(this._sock.rQwait("TightVNC extended server init header",G,32+k))return!1;this._sock.rQskipBytes(16*K),this._sock.rQskipBytes(16*R),this._sock.rQskipBytes(16*P)}return I("Screen: "+e+"x"+t+", bpp: "+s+", depth: "+i+", bigEndian: "+n+", trueColor: "+r+", redMax: "+a+", greenMax: "+o+", blueMax: "+h+", redShift: "+u+", greenShift: "+_+", blueShift: "+w),this._setDesktopName(v),this._resize(e,t),this._viewOnly||this._keyboard.grab(),this._fbDepth=24,this._fbName==="Intel(r) AMT KVM"&&(H("Intel AMT KVM only supports 8/16 bit depths. Using low color mode."),this._fbDepth=8),M.messages.pixelFormat(this._sock,this._fbDepth,!0),this._sendEncodings(),M.messages.fbUpdateRequest(this._sock,!1,0,0,this._fbWidth,this._fbHeight),this._updateConnectionState("connected"),Gi(this),!0}_hasWebp(){if(!this.enableWebP)return!1;var e=navigator.userAgent.toLowerCase(),t=e.match(/firefox\/([0-9]+)\./);return!!(t&&parseInt(t[1])>=65||(t=e.match(/chrome\/([0-9]+)\./),t&&parseInt(t[1])>=23))}_sendEncodings(){const e=[];this._display.screens.length===1?e.push(X.encodingCopyRect):C("Multiple displays detected, disabling copyrect encoding."),this._fbDepth==24&&(e.push(X.encodingTight),e.push(X.encodingTightPNG),e.push(X.encodingHextile),e.push(X.encodingRRE)),e.push(X.encodingRaw),e.push(X.pseudoEncodingQualityLevel0+this._qualityLevel),e.push(X.pseudoEncodingCompressLevel0+this._compressionLevel),e.push(X.pseudoEncodingDesktopSize),e.push(X.pseudoEncodingLastRect),e.push(X.pseudoEncodingQEMUExtendedKeyEvent),e.push(X.pseudoEncodingExtendedDesktopSize),e.push(X.pseudoEncodingXvp),e.push(X.pseudoEncodingFence),e.push(X.pseudoEncodingContinuousUpdates),e.push(X.pseudoEncodingDesktopName),e.push(X.pseudoEncodingExtendedClipboard),this._hasWebp()&&e.push(X.pseudoEncodingWEBP),this._enableQOI&&e.push(X.pseudoEncodingQOI),e.push(X.pseudoEncodingJpegVideoQualityLevel0+this.jpegVideoQuality),e.push(X.pseudoEncodingWebpVideoQualityLevel0+this.webpVideoQuality),e.push(X.pseudoEncodingTreatLosslessLevel0+this.treatLossless),e.push(X.pseudoEncodingDynamicQualityMinLevel0+this.dynamicQualityMin),e.push(X.pseudoEncodingDynamicQualityMaxLevel0+this.dynamicQualityMax),e.push(X.pseudoEncodingVideoAreaLevel1+this.videoArea-1),e.push(X.pseudoEncodingVideoTimeLevel0+this.videoTime),e.push(X.pseudoEncodingVideoOutTimeLevel1+this.videoOutTime-1),e.push(X.pseudoEncodingVideoScalingLevel0+this.videoScaling),e.push(X.pseudoEncodingFrameRateLevel10+this.frameRate-10),e.push(X.pseudoEncodingMaxVideoResolution),this.preferBandwidth&&e.push(X.pseudoEncodingPreferBandwidth),this._fbDepth==24&&(e.push(X.pseudoEncodingVMwareCursor),e.push(X.pseudoEncodingCursor)),e.push(X.pseudoEncodingVMwareCursorPosition),M.messages.clientEncodings(this._sock,e)}_initMsg(){switch(this._rfbInitState){case"ProtocolVersion":return this._negotiateProtocolVersion();case"Security":return this._negotiateSecurity();case"Authentication":return this._negotiateAuthentication();case"SecurityResult":return this._handleSecurityResult();case"SecurityReason":return this._handleSecurityReason();case"ClientInitialisation":return this._sock.send([this._shared?1:0]),this._rfbInitState="ServerInitialisation",!0;case"ServerInitialisation":return this._negotiateServerInit();default:return this._fail("Unknown init state (state: "+this._rfbInitState+")")}}_handleSetColourMapMsg(){return C("SetColorMapEntries"),this._fail("Unexpected SetColorMapEntries message")}_handleServerCutText(){if(C("ServerCutText"),this._sock.rQwait("ServerCutText header",7,1))return!1;this._sock.rQskipBytes(3);let e=this._sock.rQshift32();if(e=Me(e),this._sock.rQwait("ServerCutText content",Math.abs(e),8))return!1;if(e>=0){const t=this._sock.rQshiftStr(e);if(this._viewOnly)return!0;this.dispatchEvent(new CustomEvent("clipboard",{detail:{text:t}})),this._clipHash=0}else{e=Math.abs(e);const t=this._sock.rQshift32();let s=t&65535,i=t&4278190080;if(!!(i&Zt)){this._clipboardServerCapabilitiesFormats={},this._clipboardServerCapabilitiesActions={};for(let a=0;a<=15;a++){let o=1<<a;s&o&&(this._clipboardServerCapabilitiesFormats[o]=!0,this._sock.rQshift32())}for(let a=24;a<=31;a++){let o=1<<a;this._clipboardServerCapabilitiesActions[o]=!!(i&o)}let r=[Zt,Oe,Jt,ze,We];M.messages.extendedClipboardCaps(this._sock,r,{extendedClipboardFormatText:0})}else if(i===Oe){if(this._viewOnly)return!0;this._clipboardText!=null&&this._clipboardServerCapabilitiesActions[We]&&s&oe&&M.messages.extendedClipboardProvide(this._sock,[oe],[this._clipboardText])}else if(i===Jt){if(this._viewOnly)return!0;this._clipboardServerCapabilitiesActions[ze]&&(this._clipboardText!=null?M.messages.extendedClipboardNotify(this._sock,[oe]):M.messages.extendedClipboardNotify(this._sock,[]))}else if(i===ze){if(this._viewOnly)return!0;this._clipboardServerCapabilitiesActions[Oe]&&s&oe&&M.messages.extendedClipboardRequest(this._sock,[oe])}else if(i===We){if(this._viewOnly||!(s&oe))return!0;this._clipboardText=null;let r=this._sock.rQshiftBytes(e-4),a=new Ge,o=null;a.setInput(r);for(let h=0;h<=15;h++){let u=1<<h;if(s&u){let _=0,w=a.inflate(4);_|=w[0]<<24,_|=w[1]<<16,_|=w[2]<<8,_|=w[3];let k=a.inflate(_);u===oe&&(o=k)}}if(a.setInput(null),o!==null){let h="";for(let u=0;u<o.length;u++)h+=String.fromCharCode(o[u]);o=h,o=rt(o),o.length>0&&o.charAt(o.length-1)==="\0"&&(o=o.slice(0,-1)),o=o.replace(`\r 3`,` 4`),this.dispatchEvent(new CustomEvent("clipboard",{detail:{text:o}}))}}else return this._fail("Unexpected action in extended clipboard message: "+i)}return!0}_handleBinaryClipboard(){if(C("HandleBinaryClipboard"),this._sock.rQwait("Binary Clipboard header",2,1))return!1;let e=this._sock.rQshift8(),t={},s=2,i="";I(e+" Clipboard items recieved."),C("Started clipbooard processing with Client sockjs buffer size "+this._sock.rQlen);for(let n=0;n<e;n++){if(this._sock.rQwait("Binary Clipboard op id",4,s))return!1;s+=4;let r=this._sock.rQshift32();
4if(this._sock.rQwait("Binary Clipboard mimelen",1,s))return!1;s++;let a=this._sock.rQshift8();if(this._sock.rQwait("Binary Clipboard mime",Math.abs(a),s))return!1;s+=a;let o=this._sock.rQshiftStr(a);if(this._sock.rQwait("Binary Clipboard data len",4,s))return!1;s+=4;let h=this._sock.rQshift32();if(this._sock.rQwait("Binary Clipboard data",Math.abs(h),s))return!1;let u=this._sock.rQshiftBytes(h);switch(s+=h,o){case"image/png":case"text/html":case"text/plain":if(o=="text/plain"&&(i=new TextDecoder().decode(u),i.length>0&&i.charAt(i.length-1)==="\0"&&(i=i.slice(0,-1)),C("Plain text clipboard recieved and placed in text element, size: "+i.length),this.dispatchEvent(new CustomEvent("clipboard",{detail:{text:i}}))),I("Processed binary clipboard (ID: "+r+") of MIME "+o+" of length "+h),!this.clipboardBinary)continue;t[o]=new Blob([u],{type:o});break;default:C("Mime type skipped: "+o);break}}return C("Finished processing binary clipboard with client sockjs buffer size "+this._sock.rQlen),Object.keys(t).length>0&&this.clipboardBinary&&(this._clipHash=0,this._mouseLastScreenIndex===0?this._write_binary_clipboard(t,i):this._proxyRFBMessage("receivedClipboard",[t,i])),!0}_write_binary_clipboard(e,t){navigator.clipboard.write([new ClipboardItem(e)]).then(()=>{t&&(this._clipHash=Re(t))},s=>{Q("Error writing to client clipboard: "+s),t.length>0&&navigator.clipboard.writeText(t).then(()=>{this._clipHash=Re(t)},i=>{Q("Error writing text to client clipboard: "+i)})})}_handle_server_stats_msg(){this._sock.rQskipBytes(3);const e=this._sock.rQshift32();if(this._sock.rQwait("KASM bottleneck stats",e,8))return!1;const t=this._sock.rQshiftStr(e);return C("Received KASM bottleneck stats:"),C(t),this.dispatchEvent(new CustomEvent("bottleneck_stats",{detail:{text:t}})),!0}_handleServerFenceMsg(){if(this._sock.rQwait("ServerFence header",8,1))return!1;this._sock.rQskipBytes(3);let e=this._sock.rQshift32(),t=this._sock.rQshift8();if(this._sock.rQwait("ServerFence payload",t,9))return!1;t>64&&(H("Bad payload length ("+t+") in fence response"),t=64);const s=this._sock.rQshiftStr(t);return this._supportsFence=!0,e&1<<31?(e&=3,M.messages.clientFence(this._sock,e,s),!0):this._fail("Unexpected fence response")}_handleXvpMsg(){if(this._sock.rQwait("XVP version and message",3,1))return!1;this._sock.rQskipBytes(1);const e=this._sock.rQshift8(),t=this._sock.rQshift8();switch(t){case 0:Q("XVP Operation Failed");break;case 1:this._rfbXvpVer=e,I("XVP extensions enabled (version "+this._rfbXvpVer+")"),this._setCapability("power",!0);break;default:this._fail("Illegal server XVP message (msg: "+t+")");break}return!0}_normalMsg(){let e;this._FBU.rects>0?e=0:e=this._sock.rQshift8();let t,s;switch(e){case 0:return this._display.renderMs=0,s=this._framebufferUpdate(),s&&!this._enabledContinuousUpdates&&M.messages.fbUpdateRequest(this._sock,!0,0,0,this._fbWidth,this._fbHeight),this._trackFrameStats&&(M.messages.sendFrameStats(this._sock,this._display.fps,this._display.renderMs),this._trackFrameStats=!1),s;case 1:return this._handleSetColourMapMsg();case 2:return C("Bell"),this.dispatchEvent(new CustomEvent("bell",{detail:{}})),!0;case 3:return this._handleServerCutText();case 150:return t=!this._supportsContinuousUpdates,this._supportsContinuousUpdates=!0,this._enabledContinuousUpdates=!1,t&&(this._enabledContinuousUpdates=!0,this._updateContinuousUpdates(),I("Enabling continuous updates.")),!0;case 178:return this._handle_server_stats_msg();case 179:return this._trackFrameStats=!0,!0;case 180:return this._handleBinaryClipboard();case 181:return this._handleUdpUpgrade();case 182:return this._handleSubscribeUnixRelay();case 183:return this._handleUnixRelay();case 248:return this._handleServerFenceMsg();case 250:return this._handleXvpMsg();default:return this._fail("Unexpected server message (type "+e+")"),C("sock.rQslice(0, 30): "+this._sock.rQslice(0,30)),!0}}_onFlush(){this._flushing=!1,this._sock.rQlen>0&&this._handleMessage()}_handleUdpRect(e,t){let s={x:(e[0]<<8)+e[1],y:(e[2]<<8)+e[3],width:(e[4]<<8)+e[5],height:(e[6]<<8)+e[7],encoding:parseInt((e[8]<<24)+(e[9]<<16)+(e[10]<<8)+e[11],10)};switch(s.encoding){case X.pseudoEncodingLastRect:this._display.flip(t,s.x+1),this._display.pending()&&this._display.flush(!1);break;
4case X.encodingTight:let i=this._decoders[X.encodingUDP];try{i.decodeRect(s.x,s.y,s.width,s.height,e,this._display,this._fbDepth,t)}catch(n){return this._fail("Error decoding rect: "+n),!1}break;default:return Q("Invalid rect encoding via UDP: "+s.encoding),!1}return!0}_sendUdpUpgrade(){if(this._transitConnectionState==this.TransitConnectionStates.Upgrading)return;this._changeTransitConnectionState(this.TransitConnectionStates.Upgrading);let e=this._udpPeer,t=this._sock;e.createOffer().then(function(s){return e.setLocalDescription(s)}).then(function(){const s=t._sQ,i=t._sQlen,n=Uint8Array.from(Array.from(e.localDescription.sdp).map(r=>r.charCodeAt(0)));s[i]=181,s[i+1]=n.length>>8,s[i+2]=n.length,s.set(n,i+3),t._sQlen+=3+n.length,t.flush()}).catch(function(s){Q("Failed to create offer "+s),this._changeTransitConnectionState(this.TransitConnectionStates.Tcp),this._udpConnectFailures++})}_sendUdpDowngrade(){this._changeTransitConnectionState(this.TransitConnectionStates.Downgrading);const e=this._sock._sQ,t=this._sock._sQlen;e[t]=181,e[t+1]=0,e[t+2]=0,this._sock._sQlen+=3,this._sock.flush()}_handleUdpUpgrade(){if(this._sock.rQwait("UdpUgrade header",2,1))return!1;let e=this._sock.rQshift16();if(this._sock.rQwait("UdpUpgrade payload",e,3))return!1;const t=this._sock.rQshiftStr(e);let s=this._udpPeer;var i=JSON.parse(t);C("UDP Upgrade recieved from server: "+t),s.setRemoteDescription(new RTCSessionDescription(i.answer)).then(function(){var n=new RTCIceCandidate(i.candidate);s.addIceCandidate(n).then(function(){C("success in addicecandidate")}.bind(this)).catch(function(r){Q("Failure in addIceCandidate",r),this._changeTransitConnectionState(this.TransitConnectionStates.Failure),this._udpConnectFailures++}.bind(this))}.bind(this)).catch(function(n){Q("Failure in setRemoteDescription",n),this._changeTransitConnectionState(this.TransitConnectionStates.Failure),this._udpConnectFailures++}.bind(this))}_handleSubscribeUnixRelay(){if(this._sock.rQwait("SubscribeUnixRelay header",2,1))return!1;let e=this._sock.rQshift8(),t=this._sock.rQshift8();if(this._sock.rQwait("SubscribeUnixRelay message",t,3))return!1;const s=this._sock.rQshiftStr(t);e?I("Unix relay subscription succeeded"):H("Unix relay subscription failed, "+s)}_handleUnixRelay(){if(this._sock.rQwait("UnixRelay header",1,1))return!1;let e=this._sock.rQshift8();if(this._sock.rQwait("UnixRelay name",e,2))return!1;const t=this._sock.rQshiftStr(e);if(this._sock.rQwait("UnixRelay len",4,2+e))return!1;let s=this._sock.rQshift32();if(this._sock.rQwait("UnixRelay data",s,6+e))return!1;const i=this._sock.rQshiftBytes(s),n=this._unixRelays[t];n&&n(i)}_framebufferUpdate(){if(this._FBU.rects===0){if(this._sock.rQwait("FBU header",3,1))return!1;if(this._sock.rQskipBytes(1),this._FBU.rects=this._sock.rQshift16(),this._FBU.frame_id++,this._FBU.rect_total=0,this._display.pending())return this._flushing=!0,this._display.flush(),!1}for(;this._FBU.rects>0;){if(this._FBU.encoding===null){if(this._sock.rQwait("rect header",12))return!1;const e=this._sock.rQshiftBytes(12);this._FBU.x=(e[0]<<8)+e[1],this._FBU.y=(e[2]<<8)+e[3],this._FBU.width=(e[4]<<8)+e[5],this._FBU.height=(e[6]<<8)+e[7],this._FBU.encoding=parseInt((e[8]<<24)+(e[9]<<16)+(e[10]<<8)+e[11],10)}if(!this._handleRect())return!1;this._FBU.rects--,this._FBU.encoding=null}return this._FBU.rect_total>1&&this._display.flip(this._FBU.frame_id,this._FBU.rect_total),!0}_handleRect(){switch(this._FBU.encoding){case X.pseudoEncodingLastRect:return this._FBU.rect_total++,this._FBU.rects=1,!0;case X.pseudoEncodingVMwareCursor:return this._handleVMwareCursor(
4);case X.pseudoEncodingVMwareCursorPosition:return this._handleVMwareCursorPosition();case X.pseudoEncodingCursor:return this._handleCursor();case X.pseudoEncodingQEMUExtendedKeyEvent:return this._qemuExtKeyEventSupported=!0,!0;case X.pseudoEncodingDesktopName:return this._handleDesktopName();case X.pseudoEncodingDesktopSize:return this._resize(this._FBU.width,this._FBU.height),!0;case X.pseudoEncodingExtendedDesktopSize:return this._handleExtendedDesktopSize();default:return this._handleDataRect()?(this._FBU.rect_total++,!0):!1}}_handleVMwareCursor(){const e=this._FBU.x,t=this._FBU.y,s=this._FBU.width,i=this._FBU.height;if(this._sock.rQwait("VMware cursor encoding",1))return!1;const n=this._sock.rQshift8();this._sock.rQshift8();let r;const a=4;if(n==0){if(r=new Array(s*i*a),this._sock.rQwait("VMware cursor classic encoding",s*i*a*2,2))return!1;let h=new Array(s*i);for(let _=0;_<s*i;_++)h[_]=this._sock.rQshift32();let u=new Array(s*i);for(let _=0;_<s*i;_++)u[_]=this._sock.rQshift32();for(let _=0;_<s*i;_++)if(h[_]==0){let w=u[_],k=w>>8&255,v=w>>16&255,K=w>>24&255;r[_*a]=k,r[_*a+1]=v,r[_*a+2]=K,r[_*a+3]=255}else(h[_]&-256)==-256?u[_]==0?(r[_*a]=0,r[_*a+1]=0,r[_*a+2]=0,r[_*a+3]=0):(u[_]&-256,r[_*a]=0,r[_*a+1]=0,r[_*a+2]=0,r[_*a+3]=255):(r[_*a]=0,r[_*a+1]=0,r[_*a+2]=0,r[_*a+3]=255)}else if(n==1){if(this._sock.rQwait("VMware cursor alpha encoding",s*i*4,2))return!1;r=new Array(s*i*a);for(let o=0;o<s*i;o++){let h=this._sock.rQshift32();r[o*4]=h>>24&255,r[o*4+1]=h>>16&255,r[o*4+2]=h>>8&255,r[o*4+3]=h&255}}else return H("The given cursor type is not supported: "+n+" given."),!1;return this._updateCursor(r,e,t,s,i),!0}_handleVMwareCursorPosition(){const e=this._FBU.x,t=this._FBU.y;return this._pointerLock&&(this._mousePos={x:e,y:t}),!0}_handleCursor(){const e=this._FBU.x,t=this._FBU.y,s=this._FBU.width,i=this._FBU.height,n=s*i*4,r=Math.ceil(s/8)*i;let a=n+r;if(this._sock.rQwait("cursor encoding",a))return!1;const o=this._sock.rQshiftBytes(n),h=this._sock.rQshiftBytes(r);let u=new Uint8Array(s*i*4),_=0;for(let w=0;w<i;w++)for(let k=0;k<s;k++){let v=w*Math.ceil(s/8)+Math.floor(k/8),K=h[v]<<k%8&128?255:0;u[_]=o[_+2],u[_+1]=o[_+1],u[_+2]=o[_],u[_+3]=K,_+=4}return this._updateCursor(u,e,t,s,i),!0}_handleDesktopName(){if(this._sock.rQwait("DesktopName",4))return!1;let e=this._sock.rQshift32();if(this._sock.rQwait("DesktopName",e,4))return!1;let t=this._sock.rQshiftStr(e);return t=rt(t,!0),this._setDesktopName(t),!0}_handleExtendedDesktopSize(){if(this._sock.rQwait("ExtendedDesktopSize",4))return!1;const e=this._sock.rQpeek8();let t=4+e*16;if(this._sock.rQwait("ExtendedDesktopSize",t))return!1;const s=!this._supportsSetDesktopSize;this._supportsSetDesktopSize=!0,s&&(this._requestRemoteResize(),M.messages.setMaxVideoResolution(this._sock,this._maxVideoResolutionX,this._maxVideoResolutionY)),this._sock.rQskipBytes(1),this._sock.rQskipBytes(3);for(let i=0;i<e;i+=1){let n=this._sock.rQshift32(),r=this._sock.rQshift16(),a=this._sock.rQshift16(),o=this._sock.rQshift16(),h=this._sock.rQshift16();i==0?(this._screenIndex=0,this._screenFlags=this._sock.rQshiftBytes(4)):this._sock.rQskipBytes(4),this._display.applyServerResolution(o,h,i),C(`Server reported screen ${n} with resolution ${o}x${h} at ${r}x${a}`)}if(this._FBU.x===1&&this._FBU.y!==0){let i="";switch(this._FBU.y){case 1:i="Resize is administratively prohibited",this._resizeSession=!1,this._clipViewport=!1,this._scaleViewport=!1,this.updateConnectionSettings();break;case 2:i="Out of resources";break;case 3:i="Invalid screen layout";break;default:i="Unknown reason";break}H("Server did not accept the resize request: "+i)}else this._resize(this._FBU.width,this._FBU.height);return this._display.screens.length>1&&this._forceFullFrameUpdateAfterResize&&(this._forceFullFrameUpdateAfterResize=!1,clearTimeout(this._forceFullFrameUpdateTimeout),this._forceFullFrameUpdateTimeout=setTimeout(function(){M.messages.fbUpdateRequest(this._sock,!1,0,0,this._fbWidth,this._fbHeight)}.bind(this),500)),!0}_handleDataRect(){let e=this._decoders[this._FBU.encoding];if(!e)return this._fail("Unsupported encoding (encoding: "+this._FBU.encoding+")"),!1;try{return this._transitConnectionState==this.TransitConnectionStates.Udp||this._transitConnectionState==this.TransitConnectionStates.Failure?(this._transitConnectionState==this.TransitConnectionStates.Udp&&(H("Implicit UDP Transit Failure, TCP rects recieved while in UDP mode."),this._udpTransitFailures++),this._changeTransitConnectionState(this.TransitConnectionStates.Tcp),this._display.clear(),this._useUdp&&(this._udpConnectFailures<3&&this._udpTransitFailures<3?setTimeout(function(){H("Attempting to connect via UDP again after failure."),this.enableWebRTC=!0}.bind(this),3e3):H("UDP connection failures exceeded limit, remaining on TCP transit."))):this._transitConnectionState==this.TransitConnectionStates.Downgrading&&(this._display.clear(),this._changeTransitConnectionState(this.TransitConnectionStates.Tcp)),e.decodeRect(this._FBU.x,this._FBU.y,this._FBU.width,this._FBU.height,this._sock,this._display,this._fbDepth,this._FBU.frame_id)}catch(t){return this._fail("Error decoding rect: "+t),!1}}_updateContinuousUpdates(){this._enabledContinuousUpdates&&M.messages.enableContinuousUpdates(this._sock,!0,0,0,this._fbWidth,this._fbHeight)}_resize(e,t){this._fbWidth=e,this._fbHeight=t,this._display.resize(this._fbWidth,this._fbHeight),this._updateClip(),this._updateScale(),this._updateContinuousUpdates()}_xvpOp(e,t){this._rfbXvpVer<e||(I("Sending XVP operation "+t+" (version "+e+")"),M.messages.xvpOp(this._sock,e,t))}_updateCursor(e,t,s,i,n){this._cursorImage={rgbaPixels:e,hotx:t,hoty:s,w:i,h:n},this._refreshCursor(),this._isPrimaryDisplay&&this._proxyRFBMessage("updateCursor",[e,t,s,i,n])}
4_shouldShowDotCursor(){if(!this._showDotCursor)return!1;for(let e=3;e<this._cursorImage.rgbaPixels.length;e+=4)if(this._cursorImage.rgbaPixels[e])return!1;return!0}_refreshCursor(){if(this._rfbConnectionState!=="connecting"&&this._rfbConnectionState!=="connected")return;const e=this._shouldShowDotCursor()?M.cursors.dot:this._cursorImage;this._cursor.change(e.rgbaPixels,e.hotx,e.hoty,e.w,e.h)}static genDES(e,t){const s=e.split("").map(i=>i.charCodeAt(0));return new sn(s).encrypt(t)}}M.messages={keyEvent(c,e,t){const s=c._sQ,i=c._sQlen;s[i]=4,s[i+1]=t,s[i+2]=0,s[i+3]=0,s[i+4]=e>>24,s[i+5]=e>>16,s[i+6]=e>>8,s[i+7]=e,c._sQlen+=8,c.flush()},QEMUExtendedKeyEvent(c,e,t,s){function i(o){const h=s>>8,u=s&255;return h===224&&u<127?u|128:o}const n=c._sQ,r=c._sQlen;n[r]=255,n[r+1]=0,n[r+2]=t>>8,n[r+3]=t,n[r+4]=e>>24,n[r+5]=e>>16,n[r+6]=e>>8,n[r+7]=e;const a=i(s);n[r+8]=a>>24,n[r+9]=a>>16,n[r+10]=a>>8,n[r+11]=a,c._sQlen+=12,c.flush()},pointerEvent(c,e,t,s,i=0,n=0){const r=c._sQ,a=c._sQlen;r[a]=5,r[a+1]=s>>8,r[a+2]=s,r[a+3]=e>>8,r[a+4]=e,r[a+5]=t>>8,r[a+6]=t,r[a+7]=i>>8,r[a+8]=i,r[a+9]=n>>8,r[a+10]=n,c._sQlen+=11,c.flush()},_buildExtendedClipboardFlags(c,e){let t=new Uint8Array(4),s=0,i=0;for(let n=0;n<c.length;n++)i|=c[n];for(let n=0;n<e.length;n++)s|=e[n];return t[0]=i>>24,t[1]=0,t[2]=0,t[3]=s,t},extendedClipboardProvide(c,e,t){let s=new zi,i=[];for(let a=0;a<e.length;a++){if(e[a]!=oe)throw new Error("Unsupported extended clipboard format for Provide message.");t[a]=t[a].replace(/\r\n|\r|\n/gm,`\r 5`);let o=dt(t[a]+"\0");i.push(o.length>>24&255,o.length>>16&255,o.length>>8&255,o.length&255);for(let h=0;h<o.length;h++)i.push(o.charCodeAt(h))}let n=s.deflate(new Uint8Array(i)),r=new Uint8Array(4+n.length);r.set(M.messages._buildExtendedClipboardFlags([We],e)),r.set(n,4),M.messages.clientCutText(c,r,!0)},extendedClipboardNotify(c,e){let t=M.messages._buildExtendedClipboardFlags([ze],e);M.messages.clientCutText(c,t,!0)},extendedClipboardRequest(c,e){let t=M.messages._buildExtendedClipboardFlags([Oe],e);M.messages.clientCutText(c,t,!0)},extendedClipboardCaps(c,e,t){let s=Object.keys(t),i=new Uint8Array(4+4*s.length);s.map(r=>parseInt(r)),s.sort((r,a)=>r-a),i.set(M.messages._buildExtendedClipboardFlags(e,[]));let n=4;for(let r=0;r<s.length;r++)i[n]=t[s[r]]>>24,i[n+1]=t[s[r]]>>16,i[n+2]=t[s[r]]>>8,i[n+3]=t[s[r]]>>0,n+=4,i[3]|=1<<s[r];M.messages.clientCutText(c,i,!0)},clientCutText(c,e,t=!1){const s=c._sQ,i=c._sQlen;s[i]=6,s[i+1]=0,s[i+2]=0,s[i+3]=0;let n;t?n=Ui(-e.length):n=e.length,s[i+4]=n>>24,s[i+5]=n>>16,s[i+6]=n>>8,s[i+7]=n,c._sQlen+=8;let r=0,a=e.length;for(;a>0;){let o=Math.min(a,c._sQbufferSize-c._sQlen);for(let h=0;h<o;h++)s[c._sQlen+h]=e[r+h];c._sQlen+=o,c.flush(),a-=o,r+=o}},sendBinaryClipboard(c,e,t){const s=c._sQ;let i=c._sQlen;s[i]=180,s[i+1]=e.length,c._sQlen+=2,i+=2;for(let n=0;n<e.length;n++){let r=t[n],a=e[n];s[i++]=r.length;for(let _=0;_<r.length;_++)s[i++]=r.charCodeAt(_);let o=a.length;I("Clipboard data sent mime type "+r+" len "+o),s[i++]=o>>24,s[i++]=o>>16,s[i++]=o>>8,s[i++]=o,c._sQlen+=1+r.length+4;let h=0,u=a.length;for(;u>0;){let _=Math.min(u,c._sQbufferSize-c._sQlen);for(let w=0;w<_;w++)s[c._sQlen+w]=a[h+w];c._sQlen+=_,c.flush(),u-=_,h+=_}i=c._sQlen}},sendSubscribeUnixRelay(c,e){const t=c._sQ,s=c._sQlen;t[s]=182,t[s+1]=e.length;for(let i=0;i<e.length;i++)t[s+2+i]=e.charCodeAt(i);c._sQlen+=2+e.length,c.flush()},sendUnixRelay(c,e,t){const s=c._sQ;let i=c._sQlen;s[i++]=183,s[i++]=e.length;for(let o=0;o<e.length;o++)s[i++]=e.charCodeAt(o);let n=t.length;I("Sent unix relay data len "+n),s[i++]=n>>24,s[i++]=n>>16,s[i++]=n>>8,s[i++]=n,c._sQlen+=2+e.length+4;let r=0,a=t.length;for(;a>0;){let o=Math.min(a,c._sQbufferSize-c._sQlen);for(let h=0;h<o;h++)s[c._sQlen+h]=t[r+h];c._sQlen+=o,c.flush(),a-=o,r+=o}},setDesktopSize(c,e,t){const s=c._sQ,i=c._sQlen;s[i]=251,s[i+1]=0,s[i+2]=e.serverWidth>>8,s[i+3]=e.serverWidth,s[i+4]=e.serverHeight>>8,s[i+5]=e.serverHeight,s[i+6]=e.screens.length,s[i+7]=0;let n=8;for(let r=0;r<e.screens.length;r++)s[i+n++]=r>>24,s[i+n++]=r>>16,s[i+n++]=r>>8,s[i+n++]=r,s[i+n++]=e.screens[r].x>>8,s[i+n++]=e.screens[r].x,s[i+n++]=e.screens[r].y>>8,s[i+n++]=e.screens[r].y,s[i+n++]=e.screens[r].serverWidth>>8,s[i+n++]=e.screens[r].serverWidth,s[i+n++]=e.screens[r].serverHeight>>8,s[i+n++]=e.screens[r].serverHeight,s[i+n++]=t>>
524,s[i+n++]=t>>16,s[i+n++]=t>>8,s[i+n++]=t;c._sQlen+=n,c.flush()},setMaxVideoResolution(c,e,t){const s=c._sQ,i=c._sQlen;s[i]=252,s[i+1]=e>>8,s[i+2]=e,s[i+3]=t>>8,s[i+4]=t,c._sQlen+=5,c.flush()},clientFence(c,e,t){const s=c._sQ,i=c._sQlen;s[i]=248,s[i+1]=0,s[i+2]=0,s[i+3]=0,s[i+4]=e>>24,s[i+5]=e>>16,s[i+6]=e>>8,s[i+7]=e;const n=t.length;s[i+8]=n;for(let r=0;r<n;r++)s[i+9+r]=t.charCodeAt(r);c._sQlen+=9+n,c.flush()},requestStats(c){const e=c._sQ,t=c._sQlen;e!=null&&(e[t]=178,e[t+1]=0,e[t+2]=0,e[t+3]=0,c._sQlen+=4,c.flush())},sendFrameStats(c,e,t){const s=c._sQ,i=c._sQlen;s!=null&&(s[i]=179,s[i+1]=0,s[i+2]=0,s[i+3]=0,s[i+4]=e>>24,s[i+5]=e>>16,s[i+6]=e>>8,s[i+7]=e,s[i+8]=t>>24,s[i+9]=t>>16,s[i+10]=t>>8,s[i+11]=t,c._sQlen+=12,c.flush())},enableContinuousUpdates(c,e,t,s,i,n){const r=c._sQ,a=c._sQlen;r[a]=150,r[a+1]=e,r[a+2]=t>>8,r[a+3]=t,r[a+4]=s>>8,r[a+5]=s,r[a+6]=i>>8,r[a+7]=i,r[a+8]=n>>8,r[a+9]=n,c._sQlen+=10,c.flush()},pixelFormat(c,e,t){const s=c._sQ,i=c._sQlen;let n;e>16?n=32:e>8?n=16:n=8;const r=Math.floor(e/3);s[i]=0,s[i+1]=0,s[i+2]=0,s[i+3]=0,s[i+4]=n,s[i+5]=e,s[i+6]=0,s[i+7]=t?1:0,s[i+8]=0,s[i+9]=(1<<r)-1,s[i+10]=0,s[i+11]=(1<<r)-1,s[i+12]=0,s[i+13]=(1<<r)-1,s[i+14]=r*0,s[i+15]=r*1,s[i+16]=r*2,s[i+17]=0,s[i+18]=0,s[i+19]=0,c._sQlen+=20,c.flush()},clientEncodings(c,e){const t=c._sQ,s=c._sQlen;t[s]=2,t[s+1]=0,t[s+2]=e.length>>8,t[s+3]=e.length;let i=s+4;for(let n=0;n<e.length;n++){const r=e[n];t[i]=r>>24,t[i+1]=r>>16,t[i+2]=r>>8,t[i+3]=r,i+=4}c._sQlen+=i-s,c.flush()},fbUpdateRequest(c,e,t,s,i,n){const r=c._sQ,a=c._sQlen;typeof t>"u"&&(t=0),typeof s>"u"&&(s=0),r[a]=3,r[a+1]=e?1:0,r[a+2]=t>>8&255,r[a+3]=t&255,r[a+4]=s>>8&255,r[a+5]=s&255,r[a+6]=i>>8&255,r[a+7]=i&255,r[a+8]=n>>8&255,r[a+9]=n&255,c._sQlen+=10,c.flush()},xvpOp(c,e,t){const s=c._sQ,i=c._sQlen;s[i]=250,s[i+1]=0,s[i+2]=e,s[i+3]=t,c._sQlen+=4,c.flush()}};M.cursors={none:{rgbaPixels:new Uint8Array,w:0,h:0,hotx:0,hoty:0},dot:{rgbaPixels:new Uint8Array([255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,255,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0,255,255,255,255,255]),w:3,h:3,hotx:1,hoty:1}};const gn=()=>{const c=new rn;return c.set(0,Ee.LEFT_BUTTON),c.set(1,Ee.MIDDLE_BUTTON),c.set(2,Ee.RIGHT_BUTTON),c.set(3,Ee.BACK_BUTTON),c.set(4,Ee.FORWARD_BUTTON),c},mn={dynamicQualityMin:8,dynamicQualityMax:9,treatLossless:8,frameRate:60,jpegVideoQuality:9,webpVideoQuality:9,videoArea:100,videoTime:100,videoOutTime:3,videoScaling:0,maxVideoResolutionX:1920,maxVideoResolutionY:1080},ye={viewOnly:!1,shared:!0,clipViewport:!0,scaleViewport:!1,resizeSession:!0,compressionLevel:2,showDotCursor:!1,idleDisconnect:20,pointerRelative:!1,videoQuality:2,antiAliasing:1,clipboardUp:!0,clipboardDown:!0,clipboardSeamless:!0,enableWebRTC:!0,enableHiDpi:!1,threading:!0,enableWebP:!0,preferLocalCursor:!0,translateShortcuts:!1,enableQOI:!1,clipboardBinary:is(),mouseButtonMapper:gn(),...mn},yn={class:"right-actions"},bn={key:0,class:"relative error-message flex flex-col items-center justify-center h-full z-2"},wn={class:"text-16px mt-54px mb-2"},vn={class:"flex items-center justify-center mt-5px"},kn={key:1,class:"connecting-message flex flex-col items-center justify-center h-full"},Fn={key:0,class:"w-full h-full bg-[rgba(0,0,0,0.3)] pos-absolute left-0 top-0 z-9999 flex-center"},Cn={class:"flex-center flex-col"},Sn={class:"text-white text-18px"},En=1500,Kn=20,Xn=Us({__name:"index",props:{isMobile:{type:Boolean,default:!1},usiId:{type:String},logicId:{type:String},workspaceId:{type:String,required:!0},terminalType:{type:String,default:"WEB"},instanceName:{type:String,default:""},embedded:{type:Boolean,default:!1},hideInternalHeader:{type:Boolean,default:!1},displayMode:{type:String,default:"default"}},emits:["disconnect","update:viewMode","back"],setup(c,{expose:e,emit:t}){const s={width:1600,height:900},i=c,{t:n}=ui(),r=t,a=B(!1),o=B(i.isMobile),h=B(i.usiId),u=B(i.logicId),_=B(i.workspaceId),w=B(i.terminalType),k=B(i.instanceName),v=_i(),K=B(null),R=B(null),P=B(null),G=B(null),Y=B(!1),E=B(void 0),L=B({connected:!1,connecting:!1,fullscreen:!1,statsInterval:null});let $=null,j=null,ce=null,Z=0,le=0,te=0;const{showRemotePasswordVerify:je}=mi(),ut=B(!1),be=B("");Ct(()=>a.value,F=>{E.value&&(E.value.viewOnly=F)});const _t=B(0),de=B({ip:"",workspaceIp:"",port:"",tunnelUrl:"",protocol:"",workspaceId:"",sessionId:""}),J=B(""),qe=Bs(()=>i.embedded&&i.displayMode==="fit-preview"),cs=async()=>{const{success:F,payload:S}=await xi({id:_.value,productType:"CLOUD_BROWSER"});F&&(a.value=S)},xe=()=>{ce&&(clearTimeout(ce),ce=null)},ft=(F="")=>/STARTING|å¯å¨ä¸/i.test(F),ls=F=>{var S,D,T,z;return((D=(S=F==null?void 0:F.response)==null?void 0:S.data)==null?void 0:D.message)||((z=(T=F==null?void 0:F.response)==null?void 0:T.data)==null?void 0:z.msg)||(F==null?void 0:F.message)||""},pt=(F,S)=>{if(xe(),S===Z){if(le>=Kn){L.value.connecting=!1,J.value="å®ä¾ä»å¨å¯å¨ä¸ï¼è¯·ç¨åç¹å»éè¯";return}le+=1,ce=setTimeout(()=>{ce=null,S===Z&&ue(F,{isRetry:!0})},En)}},ue=async(F,S={})=>{S.isRetry||(le=0),xe();const D=++Z;if(!((L.value.connected||E.value)&&(await we(!1),D!==Z))){L.value.connecting=!0,J.value="";try{const{success:T,message:z,msg:se,payload:ne,code:W}=await vi({workspaceId:Number(_.value),terminalType:w.value,usiId:h.value,clientInfo:JSON.stringify({userAgent:navigator.userAgent,platform:navigator.platform})},F);if(D!==Z)return;if(T&&ne)le=0,de.value=ne,_s();else{const re=z||se||"";if(ft(re)){pt(F,D);return}if(W===1014){ut.value=!0,L.value.connecting=!1,xe(),F&&v.error(n("cloud-browser-connect.index.902201-0")),je({deviceName:k.value,onVerifySuccess:q=>{be.value=q,ue(q)},onCancel:()=>{ut.value=!1,J.value=n("cloud-browser-connect.index.902201-1")}});return}throw new Error(re||n("cloud-browser-connect.index.902201-2"))}}catch(T){if(D!==Z)return;const z=ls(T);if(ft(z)){pt(F,D);return}v.error(n("cloud-browser-connect.index.902201-3",[z||"æªç¥é误"])),J.value=n("cloud-browser-connect.index.902201-4",[z||"æªç¥é误"]),L.value.connecting=!1,xe()}}},xt=()=>{const F=R.value;document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement?(document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen(),L.value.fullscreen=!1):(F.requestFullscreen?F.requestFullscreen():F.webkitRequestFullscreen?F.webkitRequestFullscreen():F.mozRequestFullScreen?F.mozRequestFullScreen():F.msRequestFullscreen&&F.msRequestFullscreen(),L.value.fullscreen=!0)},we=async(F=!0)=>{var T;F&&(Z+=1),xe(),wt(!0);const S=E.value,D=(T=de.value)==null?void 0:T.sessionId;if(!S){L.value.connected=!1,L.value.connecting=!1;return}J.value=n("cloud-browser-connect.index.902201-5");try{S.disconnect()}catch{}await ds(D),E.value===S&&(E.value=void 0,L.value.connected=!1,L.value.connecting=!1)},ds=async(F=(S=>(S=de.value)==null?void 0:S.sessionId)())=>{if(F)try{let D=await ki(F);D.success||v.error(D.message||n("cloud-browser-connect.index.902201-6"))}catch{}};function us(F){return/^((25[0-5]|2[0-4]\d|1?\d?\d)(\.|$)){4}$/.test(F)}const $e=(F=!1)=>{var S,D;E.value&&(qe.value?(E.value.resizeSession=!1,E.value.forcedResolutionX=s.width,E.value.forcedResolutionY=s.height,E.value.clipViewport=!1,E.value.scaleViewport=!0):(E.value.forcedResolutionX=null,E.value.forcedResolutionY=null,E.value.resizeSession=ye.resizeSession,E.value.clipViewport=ye.clipViewport,E.value.scaleViewport=ye.scaleViewport),F&&L.value.connected&&((D=(S=E.value).updateConnectionSettings)==null||D.call(S)))},_s=()=>{const F=de.value.ip,S=de.value.port,T=us(F)?`${F}:${S}`:F,z=pi().value,se=de.value.sessionId,ne=`wss://${T}/websockify?token=${z}&sessionId=${se}`,W=new M(R.value,G.value,ne,{shared:ye.shared,repeaterID:"",credentials:{password:""}},!0),re=++te;E.value=W,W.addEventListener("connect",()=>fs(re)),W.addEventListener("disconnect",q=>ps(q,re)),W.addEventListener("credentialsrequired",W.credentials),W.addEventListener("clipboard",xs),W.addEventListener("bottleneck_stats",q=>gs(q,re)),W.addEventListener("bell",ms),W.addEventListener("desktopname",ws),W.addEventListener("tap_cb",bs),E.value.keyboard.enableIME=!0,Object.keys(ye).forEach(q=>{E.value[q]=ye[q]}),$e(),E.value.viewOnly=a.value,is()&&(o.value||navigator.permissions.query({name:"clipboard-read"}).then(()=>{}).catch(()=>{})),/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&(E.value.clipboardSeamless=!1),o.value&&(E.value.keyboard.enableIME=!1,E.value._cursor._canvas.style.display="none"),window.browserClient=E.value,cs()},gt=()=>{var F,S;!E.value||!L.value.connected||($e(),(S=(F=E.value)._windowResize)==null||S.call(F))},Le=()=>{E.value&&($&&clearTimeout($),gt(),$=setTimeout(()=>{gt()},180))},mt=()=>{$&&(clearTimeout($),$=null)},yt=async()=>{!qe.value||typeof ResizeObserver>"u"||(await St(),P.value&&(j==null||j.disconnect(),j=new ResizeObserver(()=>{Le()}),j.observe(P.value)))},bt=()=>{j==null||j.disconnect(),j=null},Ae=()=>{L.value.statsInterval!==null&&(clearInterval(L.value.statsInterval),L.value.statsInterval=null)},wt=F=>
5{if(F){Ae();return}const S=E.value;!S||!L.value.connected||L.value.statsInterval||(L.value.statsInterval=setInterval(()=>{if(E.value!==S||!L.value.connected){Ae();return}try{S.requestBottleneckStats()}catch{Ae()}},700))},fs=(F=te)=>{F!==te||!E.value||(L.value.connecting=!1,L.value.connected=!0,E.value.focus(),Le())},ps=(F,S=te)=>{var T;if(S!==te)return;Ae();const D=(T=F==null?void 0:F.detail)==null?void 0:T.code;D&&(D===3412&&(J.value=n("cloud-browser-connect.index.902201-9")),D===3411&&(J.value=n("cloud-browser-connect.index.902201-10")),[1006,1002].includes(D)&&(J.value=n("cloud-browser-connect.index.902201-11"))),L.value.connected=!1,L.value.connecting=!1,E.value=void 0},xs=F=>{E.value.clipboardDown},gs=(F,S=te)=>{if(!(S!==te||!E.value))try{let D=JSON.parse(F.detail.text),T=E.value.statsFps,z=E.value.statsDroppedFps;const se={CPU:D[0]+"/"+D[1],Network:D[2]+"/"+D[3],FPS:T,DroppedFPS:z};_t.value=T}catch{}},ms=()=>{var S;const F=(S=K.value)==null?void 0:S.play();F&&F.catch(D=>{D.name})},ys=()=>{window.FlutterApp&&window.FlutterApp.postMessage(JSON.stringify({message:"haptic",data:""}))},bs=F=>{ys();const{x:S,y:D}=F.detail.pos,T=document.createElement("div");T.className="touch-ripple",T.style.left=`${S}px`,T.style.top=`${D}px`,document.body.appendChild(T),T.addEventListener("animationend",()=>{document.body.contains(T)&&document.body.removeChild(T)})},ws=()=>{i.embedded||(document.title+=document.title=n("cloud-browser-connect.index.902201-13",[k.value]))},vs=()=>{E.value&&(E.value.focusOnClick=!1)},ks=()=>{E.value&&(E.value.focusOnClick=!0)},Fs=()=>{Y.value=!0;const F=G.value;if(!(document.activeElement==F||!E.value)){E.value.keyboard.enableIME=!0,F.focus();try{const S=F.value.length;F.setSelectionRange(S,S)}catch{}document.querySelector("canvas").addEventListener("touchstart",()=>{document.activeElement===F&&F.blur()},{once:!0})}},Ze=()=>{Y.value=!1;const F=G.value;document.activeElement!=F||!E.value||(F.blur(),E.value.keyboard.enableIME=!1)},Cs=()=>{i.embedded||vt(),we(),r("back")},Ie=Hs(!1),Ss=()=>{Ie.value=!0},vt=()=>{if(window.webviewApi){window.webviewApi.invoke("close-webview",u.value);return}if(window.FlutterApp){window.FlutterApp.postMessage(JSON.stringify({message:"close-webview",data:""}));return}},Es=()=>{document.documentElement.addEventListener("touchend",Ze,!0)},Ks=()=>{document.documentElement.removeEventListener("touchend",Ze,!0)},Te=B({right:"10px",top:"10px"}),Je=B(!1),et=B({x:0,y:0}),tt=B({x:0,y:0}),Xs=F=>{Je.value=!0;const S=F.touches[0];et.value={x:S.clientX,y:S.clientY};const D=parseInt(Te.value.right),T=parseInt(Te.value.top);tt.value={x:D,y:T}},Ms=F=>{if(!Je.value)return;F.preventDefault();const S=F.touches[0],D=S.clientX-et.value.x,T=S.clientY-et.value.y,z=Math.max(0,tt.value.x-D),se=Math.max(0,tt.value.y+T),ne=window.innerWidth-60,W=window.innerHeight-120;Te.value={right:`${Math.min(z,ne)}px`,top:`${Math.min(se,W)}px`}},Rs=()=>{Je.value=!1},Qs=F=>{switch(F.key){case"resolution":ue(be.value||void 0);break;case"disconnect":vt(),we();break}},Ds=()=>{Y.value?Ze():Fs()};return fi(F=>{F.deviceId===Number(_.value)&&(a.value=F.status==="RUNNING")}),Ns(()=>{Es(),ue(),yt()}),Vs(()=>{Z+=1,xe(),mt(),bt(),Ks(),we()}),Ct(()=>i.displayMode,async()=>{mt(),$e(!0),qe.value?await yt():bt(),await St(),Le()}),e({toggleFullscreen:xt,refreshConnection:()=>ue(be.value||void 0),syncViewport:Le}),(F,S)=>{const D=Gs,T=Ws,z=zs,se=si,ne=ii,W=ti,re=Js,q=ri,Ls=oi;return ie(),ve(wi,null,{default:O(()=>[N("div",{class:Os(["cloud-browser-connect-container",{"is-embedded":i.embedded}])},[i.hideInternalHeader?ke("",!0):(ie(),ve(yi,{key:0,connected:A(L).connected,connecting:A(L).connecting,instanceName:A(k),frameRate:A(_t),workspaceIp:A(de).workspaceIp,"enter-header-func":wt},{rightAction:O(()=>[N("div",yn,[V(z,null,{default:O(()=>[V(T,{title:`${A(n)("cloud-browser-connect.index.902201-15")} (F11)`},{default:O(()=>[V(D,{shape:"circle",onClick:xt},{icon:O(()=>[A(L).fullscreen?(ie(),ve(A(js),{key:1})):(ie(),ve(A(Ys),{key:0}))]),_:1})]),_:1},8,["title"]),V(T,{title:A(n)("cloud-browser-connect.index.902201-16")},{default:O(()=>[V(D,{shape:"circle",onClick:S[0]||(S[0]=()=>ue(A(be)||void 0))},{icon:O(()=>[V(A(qs))]),_:1})]),_:1},8,["title"]),V(T,{title:A(n)("cloud-browser-connect.index.902201-17")},{default:O(()=>[V(D,{shape:"circle",type:"primary",danger:"",onClick:S[1]||(S[1]=()=>we())},{icon:O(()=>[V(A($s))]),_:1})]),_:1},8,["title"])]),_:1})])]),_:1}
5,8,["connected","connecting","instanceName","frameRate","workspaceIp"])),A(L).connected&&A(o)?(ie(),Pe("div",{key:1,class:"pos-absolute z-999",style:Zs(A(Te)),onTouchstart:Xs,onTouchmove:Ms,onTouchend:Rs},[V(re,{trigger:["click"],overlayStyle:{width:"100px"},onClick:S[2]||(S[2]=ei(()=>{},["prevent"])),getPopupContainer:st=>st.parentNode},{overlay:O(()=>[V(W,{onClick:Qs},{default:O(()=>[V(se,{key:"resolution"},{default:O(()=>[N("div",null,_e(A(n)("cloud-browser-connect.index.902201-18")),1)]),_:1}),V(ne),V(se,{key:"disconnect"},{default:O(()=>[N("div",null,_e(A(n)("cloud-browser-connect.index.902201-17")),1)]),_:1})]),_:1})]),default:O(()=>[S[5]||(S[5]=N("div",{class:"w-54px h-54px rounded-50% bg-#D5D5D5 flex-center flex-col"},[N("img",{src:ci,class:"w-36px h-36px",alt:""})],-1))]),_:1},8,["getPopupContainer"]),N("div",{class:"w-54px h-54px rounded-50% bg-#D5D5D5 flex-center mt-5px",onClick:Ds},[...S[6]||(S[6]=[N("img",{src:li,class:"w-36px h-36px",alt:""},null,-1)])])],36)):ke("",!0),N("div",{ref_key:"displayContainerRef",ref:P,class:"browser-display-container flex-1"},[A(J)?(ie(),Pe("div",bn,[S[7]||(S[7]=N("img",{src:di,alt:"",class:"w-289px h-229px"},null,-1)),N("p",wn,_e(A(J)),1),N("div",vn,[i.embedded?ke("",!0):(ie(),ve(D,{key:0,onClick:Cs,class:"mr-4"},{default:O(()=>[it(_e(A(n)("cloud-browser-connect.index.902201-19")),1)]),_:1})),V(D,{onClick:Ss,class:"mr-4",loading:A(L).connecting},{default:O(()=>[it(_e(A(n)("cloud-browser-connect.index.902201-20")),1)]),_:1},8,["loading"]),V(D,{type:"primary",onClick:S[3]||(S[3]=()=>ue(A(be)||void 0)),loading:A(L).connecting},{default:O(()=>[it(_e(A(n)("cloud-browser-connect.index.902201-16")),1)]),_:1},8,["loading"])])])):A(L).connecting?(ie(),Pe("div",kn,[V(q,{tip:A(n)("cloud-browser-connect.index.902201-21"),size:"large"},null,8,["tip"])])):ke("",!0),ni(N("div",{ref_key:"containerRef",ref:R,id:"qinghu_container"},[N("textarea",{onFocus:vs,onBlur:ks,onSubmit:()=>!1,ref_key:"keyboardInputRef",ref:G,id:"qinghu_keyboard_input",autocapitalize:"off",autocomplete:"off",spellcheck:"false",tabindex:"-1"},null,544)],512),[[ai,A(L).connected]]),N("audio",{id:"qinghu_bell",ref_key:"bellRef",ref:K},[...S[8]||(S[8]=[N("source",{src:Fi,type:"audio/ogg"},null,-1),N("source",{src:Ci,type:"audio/mpeg"},null,-1)])],512)],512),V(Ls,{open:A(Ie),"onUpdate:open":S[4]||(S[4]=st=>hi(Ie)?Ie.value=st:null),width:260,title:A(n)("cloud-browser-connect.index.902201-20"),centered:"",footer:null,"body-style":{padding:0}},{default:O(()=>[V(bi,{width:260,status:void 0})]),_:1},8,["open","title"])],2),A(a)?(ie(),Pe("div",Fn,[N("div",Cn,[N("span",Sn,_e(A(n)("cloud-browser-connect.index.902201-22")),1)])])):ke("",!0)]),_:1})}}}),In=gi(Xn,[["__scopeId","data-v-a063dd20"]]);export{In as C};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.