bfg-common 1.5.459 → 1.5.460

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,4 +67,4 @@ function(e,t){var n,r,i,o,s,a,u,l,c,f,p,d,h,g,m,y,v,x="sizzle"+-new Date,w=e.doc
67
67
  * Dual licensed under the MIT or GPL Version 2 licenses.
68
68
  * http://jquery.org/license
69
69
  */
70
- !function(e){function t(e){e.startMove=e.startMove?e.startMove:{startX:null,startY:null,timestamp:null};var t=(new Date).getTime();if(e.touches){var s=[{lastX:e.deltaX,lastY:e.deltaY,moved:null,startX:e.screenX-e.startMove.screenX,startY:e.screenY-e.startMove.screenY}],r={vector:e.vector,orientation:window.orientation||null,lastX:s[0].lastX>0?1:s[0].lastX<0?-1:0,lastY:s[0].lastY>0?1:s[0].lastY<0?-1:0,startX:s[0].startX>0?1:s[0].startX<0?-1:0,startY:s[0].startY>0?1:s[0].startY<0?-1:0};s[0].moved=Math.sqrt(Math.pow(Math.abs(s[0].startX),2)+Math.pow(Math.abs(s[0].startY),2))}return{type:e.type||null,originalEvent:e.event||null,delta:s||null,direction:r||{orientation:window.orientation||null,vector:e.vector||null},duration:e.startMove.timestamp?t-e.timestamp:null,rotation:e.rotation||null,scale:e.scale||null,description:e.description||[e.type,":",e.touches,":",0!=s[0].lastX?s[0].lastX>0?"right":"left":"steady",":",0!=s[0].lastY?s[0].lastY>0?"down":"up":"steady"].join("")}}function s(t){e(window).triggerHandler("orientationchange",{direction:{orientation:window.orientation},description:["orientationchange:",["landscape:clockwise:","portrait:default:","landscape:counterclockwise:","portrait:upsidedown:"][window.orientation/90+1],window.orientation].join("")})}function r(t){var s=jQuery(t.currentTarget);s.triggerHandler(e.jGestures.events.touchstart,t),e.hasGestures?(t.currentTarget.addEventListener("touchmove",a,!1),t.currentTarget.addEventListener("touchend",o,!1)):(s.bind("mousemove",a),s.bind("mouseup",o));var r=s.data("ojQueryGestures"),n=t.touches?t.touches[0]:t,c={};c.oLastSwipemove={screenX:n.screenX,screenY:n.screenY,timestamp:(new Date).getTime()},c.oStartTouch={screenX:n.screenX,screenY:n.screenY,timestamp:(new Date).getTime()},s.data("ojQueryGestures",e.extend(!0,r,c))}function a(s){var r=jQuery(s.currentTarget),a=r.data("ojQueryGestures"),o=!!s.touches,n=o?s.changedTouches[0].screenX:s.screenX,c=o?s.changedTouches[0].screenY:s.screenY,i=a.oLastSwipemove,u=n-i.screenX,h=c-i.screenY;if(a.oLastSwipemove){var p=t({type:"swipemove",touches:o?s.touches.length:"1",screenY:c,screenX:n,deltaY:h,deltaX:u,startMove:i,event:s,timestamp:i.timestamp});r.triggerHandler(p.type,p)}var d={},l=s.touches?s.touches[0]:s;d.oLastSwipemove={screenX:l.screenX,screenY:l.screenY,timestamp:(new Date).getTime()},r.data("ojQueryGestures",e.extend(!0,a,d))}function o(s){var r=jQuery(s.currentTarget),n=!!s.changedTouches,c=n?s.changedTouches.length:"1",i=n?s.changedTouches[0].screenX:s.screenX,u=n?s.changedTouches[0].screenY:s.screenY;r.triggerHandler(e.jGestures.events.touchendStart,s),e.hasGestures?(s.currentTarget.removeEventListener("touchmove",a,!1),s.currentTarget.removeEventListener("touchend",o,!1)):(r.unbind("mousemove",a),r.unbind("mouseup",o));var h,p=r.data("ojQueryGestures"),d=Math.abs(p.oStartTouch.screenX-i)>e.jGestures.defaults.thresholdMove||Math.abs(p.oStartTouch.screenY-u)>e.jGestures.defaults.thresholdMove,l=Math.abs(p.oStartTouch.screenX-i)>e.jGestures.defaults.thresholdSwipe||Math.abs(p.oStartTouch.screenY-u)>e.jGestures.defaults.thresholdSwipe;for(h in p){var w=p.oStartTouch,g=(i=n?s.changedTouches[0].screenX:s.screenX,u=n?s.changedTouches[0].screenY:s.screenY,i-w.screenX),v=t({type:"swipe",touches:c,screenY:u,screenX:i,deltaY:u-w.screenY,deltaX:g,startMove:w,event:s,timestamp:w.timestamp}),j=["zero","one","two","three","four"],m=!1;switch(h){case"swipeone":if(!1===n&&1==c&&!1===d)break;(!1===n||1==c&&!0===d&&!0===l)&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipetwo":n&&2==c&&!0===d&&!0===l&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipethree":n&&3==c&&!0===d&&!0===l&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipefour":n&&4==c&&!0===d&&!0===l&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":case"swipeleftup":n&&!0===d&&!0===l&&(m=!0,v.type=["swipe",0!=v.delta[0].lastX?v.delta[0].lastX>0?"right":"left":"",0!=v.delta[0].lastY?v.delta[0].lastY>0?"down":"up":""].join(""),r.triggerHandler(v.type,v));break;case"tapone":case"taptwo":case"tapthree":case"tapfour":!0!==d&&!0!==m&&j[c]==h.slice(3)&&(v.description=["tap",j[c]].join(""),v.type=["tap",j[c]].join(""),r.triggerHandler(v.type,v))}var G={};r.data("ojQueryGestures",e.extend(!0,p,G)),r.data("ojQueryGestures",e.extend(!0,p,G))}r.triggerHandler(e.jGestures.events.touchendProcessed,s)}function n(t){var s=jQuery(t.currentTarget);s.triggerHandler(e.jGestures.events.gesturestart,t);var r=s.data("ojQueryGestures"),a={};a.oStartTouch={timestamp:(new Date).getTime()},s.data("ojQueryGestures",e.extend(!0,r,a))}function c(s){var r,a,o,n,c=jQuery(s.currentTarget),i=c.data("ojQueryGestures");for(n in i)switch(n){case"pinch":((r=s.scale)<1&&r%1<1-e.jGestures.defaults.thresholdPinchclose||r>1&&r%1>e.jGestures.defaults.thresholdPinchopen)&&(a=r<1?-1:1,o=t({type:"pinch",scale:r,touches:null,startMove:i.oStartTouch,event:s,timestamp:i.oStartTouch.timestamp,vector:a,description:["pinch:",a,":",r<1?"close":"open"].join("")}),c.triggerHandler(o.type,o));break;case"rotate":((r=s.rotation)<1&&-1*r>e.jGestures.defaults.thresholdRotateccw||r>1&&r>e.jGestures.defaults.thresholdRotatecw)&&(a=r<1?-1:1,o=t({type:"rotate",rotation:r,touches:null,startMove:i.oStartTouch,event:s,timestamp:i.oStartTouch.timestamp,vector:a,description:["rotate:",a,":",r<1?"counterclockwise":"clockwise"].join("")}),c.triggerHandler(o.type,o))}}function i(s){var r,a=jQuery(s.currentTarget);a.triggerHandler(e.jGestures.events.gestureendStart,s);var o,n=a.data("ojQueryGestures");for(o in n)switch(o){case"pinchclose":(r=s.scale)<1&&r%1<1-e.jGestures.defaults.thresholdPinchclose&&a.triggerHandler("pinchclose",t({type:"pinchclose",scale:r,vector:-1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"pinch:-1:close"}));break;case"pinchopen":(r=s.scale)>1&&r%1>e.jGestures.defaults.thresholdPinchopen&&a.triggerHandler("pinchopen",t({type:"pinchopen",scale:r,vector:1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"pinch:+1:open"}));break;case"rotatecw":(r=s.rotation)>1&&r>e.jGestures.defaults.thresholdRotatecw&&a.triggerHandler("rotatecw",t({type:"rotatecw",rotation:r,vector:1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"rotate:+1:clockwise"}));break;case"rotateccw":(r=s.rotation)<1&&-1*r>e.jGestures.defaults.thresholdRotateccw&&a.triggerHandler("rotateccw",t({type:"rotateccw",rotation:r,vector:-1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"rotate:-1:counterclockwise"}))}a.triggerHandler(e.jGestures.events.gestureendProcessed,s)}e.jGestures={},e.jGestures.defaults={},e.jGestures.defaults.thresholdPinchopen=.05,e.jGestures.defaults.thresholdPinchmove=.05,e.jGestures.defaults.thresholdPinch=.05,e.jGestures.defaults.thresholdPinchclose=.05,e.jGestures.defaults.thresholdRotatecw=5,e.jGestures.defaults.thresholdRotateccw=5,e.jGestures.defaults.thresholdMove=20,e.jGestures.defaults.thresholdSwipe=100,e.jGestures.data={},e.jGestures.data.capableDevicesInUserAgentString=["iPad","iPhone","iPod","Mobile Safari"],e.jGestures.data.hasGestures=function(){var t;for(t=0;t<e.jGestures.data.capableDevicesInUserAgentString.length;t++)if(-1!==navigator.userAgent.indexOf(e.jGestures.data.capableDevicesInUserAgentString[t]))return!0;return!1}(),e.hasGestures=e.jGestures.data.hasGestures,e.jGestures.events={touchstart:"jGestures.touchstart",touchendStart:"jGestures.touchend;start",touchendProcessed:"jGestures.touchend;processed",gesturestart:"jGestures.gesturestart",gestureendStart:"jGestures.gestureend;start",gestureendProcessed:"jGestures.gestureend;processed"},jQuery.each({orientationchange_orientationchange01:"orientationchange",gestureend_pinchopen01:"pinchopen",gestureend_pinchclose01:"pinchclose",gestureend_rotatecw01:"rotatecw",gestureend_rotateccw01:"rotateccw",gesturechange_pinch01:"pinch",gesturechange_rotate01:"rotate",touchstart_swipe13:"swipemove",touchstart_swipe01:"swipeone",touchstart_swipe02:"swipetwo",touchstart_swipe03:"swipethree",touchstart_swipe04:"swipefour",touchstart_swipe05:"swipeup",touchstart_swipe06:"swiperightup",touchstart_swipe07:"swiperight",touchstart_swipe08:"swiperightdown",touchstart_swipe09:"swipedown",touchstart_swipe10:"swipeleftdown",touchstart_swipe11:"swipeleft",touchstart_swipe12:"swipeleftup",touchstart_tap01:"tapone",touchstart_tap02:"taptwo",touchstart_tap03:"tapthree",touchstart_tap04:"tapfour"},(function(t,u){jQuery.event.special[u]={setup:function(){var a=t.split("_"),o=a[0],u=a[1].slice(0,a[1].length-2),h=jQuery(this);if(!h.data("ojQueryGestures")||!h.data("ojQueryGestures")[o]){var p=h.data("ojQueryGestures")||{},d={};if(d[o]=!0,e.extend(!0,p,d),h.data("ojQueryGestures",p),e.hasGestures)switch(u){case"orientationchange":h.get(0).addEventListener("orientationchange",s,!1);break;case"tap":case"swipe":case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":h.get(0).addEventListener("touchstart",r,!1);break;case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":h.get(0).addEventListener("gesturestart",n,!1),h.get(0).addEventListener("gestureend",i,!1);break;case"pinch":case"rotate":h.get(0).addEventListener("gesturestart",n,!1),h.get(0).addEventListener("gesturechange",c,!1)}else switch(u){case"tap":case"swipe":h.bind("mousedown",r)}}return!1},add:function(e){return jQuery(this).data("ojQueryGestures")[e.type]={originalType:e.type},!1},remove:function(e){var t=jQuery(this),s=t.data("ojQueryGestures");return s[e.type]=!1,t.data("ojQueryGestures",s),!1},teardown:function(){var u=t.split("_"),h=u[0],p=u[1].slice(0,u[1].length-2),d=jQuery(this);if(!d.data("ojQueryGestures")||!d.data("ojQueryGestures")[h]){var l=d.data("ojQueryGestures")||{},w={};if(w[h]=!1,e.extend(!0,l,w),d.data("ojQueryGestures",l),e.hasGestures)switch(p){case"orientationchange":d.get(0).removeEventListener("orientationchange",s,!1);break;case"tap":case"swipe":case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":case"swipeleftup":d.get(0).removeEventListener("touchstart",r,!1),d.get(0).removeEventListener("touchmove",a,!1),d.get(0).removeEventListener("touchend",o,!1);break;case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":d.get(0).removeEventListener("gesturestart",n,!1),d.get(0).removeEventListener("gestureend",i,!1);break;case"pinch":case"rotate":d.get(0).removeEventListener("gesturestart",n,!1),d.get(0).removeEventListener("gesturechange",c,!1)}else switch(p){case"tap":case"swipe":d.unbind("mousedown",r),d.unbind("mousemove",a),d.unbind("mouseup",o)}}return!1}}}))}(jQuery);var Pixastic=function(){function t(t,a,e){var r=new Array;null==a&&(a=document),null==e&&(e="*");var n=a.getElementsByTagName(e),s=n.length,o=new RegExp("(^|\\s)"+t+"(\\s|$)");for(i=0,j=0;i<s;i++)o.test(n[i].className)&&(r[j]=n[i],j++);return r}function a(t,a){if(Pixastic.debug){try{switch(a){case"warn":console.warn("Pixastic:",t);break;case"error":console.error("Pixastic:",t);break;default:console.log("Pixastic:",t)}}catch(t){}1}}"undefined"!=typeof pixastic_parseonload&&pixastic_parseonload&&function(t){var a=!1,e=function(){a||(a=!0,t())};document.write('<script defer src="//:" id="__onload_ie_pixastic__"><\/script>');var i=document.getElementById("__onload_ie_pixastic__");i.onreadystatechange=function(){"complete"==i.readyState&&(i.parentNode.removeChild(i),e())},document.addEventListener&&document.addEventListener("DOMContentLoaded",e,!1),function(t,a,e){t.addEventListener?t.addEventListener(a,e,!1):t.attachEvent&&t.attachEvent("on"+a,e)}(window,"load",e)}((function(){for(var a=t("pixastic",null,"img"),e=t("pixastic",null,"canvas"),i=a.concat(e),r=0;r<i.length;r++)!function(){for(var t=i[r],a=[],e=t.className.split(" "),n=0;n<e.length;n++){var s=e[n];if("pixastic-"==s.substring(0,9)){var o=s.substring(9);""!=o&&a.push(o)}}if(a.length)if("img"==t.tagName.toLowerCase()){var c=new Image;if(c.src=t.src,c.complete)for(var h=0;h<a.length;h++){var l=Pixastic.applyAction(t,t,a[h],null);l&&(t=l)}else c.onload=function(){for(var e=0;e<a.length;e++){var i=Pixastic.applyAction(t,t,a[e],null);i&&(t=i)}}}else setTimeout((function(){for(var e=0;e<a.length;e++){var i=Pixastic.applyAction(t,t,a[e],null);i&&(t=i)}}),1)}()}));var e=function(){var t=document.createElement("canvas"),a=!1;try{a=!("function"!=typeof t.getContext||!t.getContext("2d"))}catch(t){}return function(){return a}}(),r=function(){var t,a=document.createElement("canvas"),e=!1;try{"function"==typeof a.getContext&&(t=a.getContext("2d"))&&(e="function"==typeof t.getImageData)}catch(t){}return function(){return e}}(),n=function(){var t=!1,a=document.createElement("canvas");if(e()&&r()){a.width=a.height=1;var i=a.getContext("2d");i.fillStyle="rgb(255,0,0)",i.fillRect(0,0,1,1);var n=document.createElement("canvas");n.width=n.height=1;var s=n.getContext("2d");s.fillStyle="rgb(0,0,255)",s.fillRect(0,0,1,1),i.globalAlpha=.5,i.drawImage(n,0,0);var o=i.getImageData(0,0,1,1).data;t=255!=o[2]}return function(){return t}}();return{parseOnLoad:!1,debug:!1,applyAction:function(t,e,i,r){r=r||{};var n,s,o="canvas"==t.tagName.toLowerCase();if(o&&Pixastic.Client.isIE())return Pixastic.debug&&a("Tried to process a canvas element but browser is IE."),!1;var c=!1;Pixastic.Client.hasCanvas()&&(c=!!r.resultCanvas,s=(n=r.resultCanvas||document.createElement("canvas")).getContext("2d"));var h=t.offsetWidth,l=t.offsetHeight;if(o&&(h=t.width,l=t.height),0==h||0==l){if(null!=t.parentNode)return void(Pixastic.debug&&a("Image has 0 width and/or height."));var p=t.style.position,g=t.style.left;t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),h=t.offsetWidth,l=t.offsetHeight,document.body.removeChild(t),t.style.position=p,t.style.left=g}if(i.indexOf("(")>-1){var v=i;i=v.substr(0,v.indexOf("("));var d=v.match(/\((.*?)\)/);if(d[1]){d=d[1].split(";");for(var u=0;u<d.length;u++)if(thisArg=d[u].split("="),2==thisArg.length)if("rect"==thisArg[0]){var f=thisArg[1].split(",");r[thisArg[0]]={left:parseInt(f[0],10)||0,top:parseInt(f[1],10)||0,width:parseInt(f[2],10)||0,height:parseInt(f[3],10)||0}}else r[thisArg[0]]=thisArg[1]}}r.rect?(r.rect.left=Math.round(r.rect.left),r.rect.top=Math.round(r.rect.top),r.rect.width=Math.round(r.rect.width),r.rect.height=Math.round(r.rect.height)):r.rect={left:0,top:0,width:h,height:l};var m=!1;if(Pixastic.Actions[i]&&"function"==typeof Pixastic.Actions[i].process&&(m=!0),!m)return Pixastic.debug&&a('Invalid action "'+i+'". Maybe file not included?'),!1;if(!Pixastic.Actions[i].checkSupport())return Pixastic.debug&&a('Action "'+i+'" not supported by this browser.'),!1;Pixastic.Client.hasCanvas()?(n!==t&&(n.width=h,n.height=l),c||(n.style.width=h+"px",n.style.height=l+"px"),s.drawImage(e,0,0,h,l),t.__pixastic_org_image?(n.__pixastic_org_image=t.__pixastic_org_image,n.__pixastic_org_width=t.__pixastic_org_width,n.__pixastic_org_height=t.__pixastic_org_height):(n.__pixastic_org_image=t,n.__pixastic_org_width=h,n.__pixastic_org_height=l)):Pixastic.Client.isIE()&&void 0===t.__pixastic_org_style&&(t.__pixastic_org_style=t.style.cssText);var x={image:t,canvas:n,width:h,height:l,useData:!0,options:r};return!!Pixastic.Actions[i].process(x)&&(Pixastic.Client.hasCanvas()?(x.useData&&Pixastic.Client.hasCanvasImageData()&&(n.getContext("2d").putImageData(x.canvasData,r.rect.left,r.rect.top),n.getContext("2d").fillRect(0,0,0,0)),r.leaveDOM||(n.title=t.title,n.imgsrc=t.imgsrc,o||(n.alt=t.alt),o||(n.imgsrc=t.src),n.className=t.className,n.style.cssText=t.style.cssText,n.name=t.name,n.tabIndex=t.tabIndex,n.id=t.id,t.parentNode&&t.parentNode.replaceChild&&t.parentNode.replaceChild(n,t)),r.resultCanvas=n,n):t)},prepareData:function(t,a){var e=t.canvas.getContext("2d"),i=t.options.rect,r=e.getImageData(i.left,i.top,i.width,i.height),n=r.data;return a||(t.canvasData=r),n},process:function(t,a,e,i){if("img"==t.tagName.toLowerCase()){var r=new Image;if(r.src=t.src,r.complete){var n=Pixastic.applyAction(t,r,a,e);return i&&i(n),n}r.onload=function(){var n=Pixastic.applyAction(t,r,a,e);i&&i(n)}}if("canvas"==t.tagName.toLowerCase()){n=Pixastic.applyAction(t,t,a,e);return i&&i(n),n}},revert:function(t){if(Pixastic.Client.hasCanvas()){if("canvas"==t.tagName.toLowerCase()&&t.__pixastic_org_image)return t.width=t.__pixastic_org_width,t.height=t.__pixastic_org_height,t.getContext("2d").drawImage(t.__pixastic_org_image,0,0),t.parentNode&&t.parentNode.replaceChild&&t.parentNode.replaceChild(t.__pixastic_org_image,t),t}else Pixastic.Client.isIE()&&void 0!==t.__pixastic_org_style&&(t.style.cssText=t.__pixastic_org_style)},Client:{hasCanvas:e,hasCanvasImageData:r,hasGlobalAlpha:n,isIE:function(){return!!document.all&&!!window.attachEvent&&!window.opera}},Actions:{}}}();"undefined"!=typeof jQuery&&jQuery&&jQuery.fn&&(jQuery.fn.pixastic=function(t,a){var e=[];return this.each((function(){if("img"!=this.tagName.toLowerCase()||this.complete){var i=Pixastic.process(this,t,a);i&&e.push(i)}})),e.length>0?jQuery(e):this}),Pixastic.Actions.blend={process:function(t){var a=parseFloat(t.options.amount),e=(t.options.mode||"normal").toLowerCase(),i=t.options.image;if(a=Math.max(0,Math.min(1,a)),!i)return!1;if(Pixastic.Client.hasCanvasImageData()){var r=t.options.rect,n=Pixastic.prepareData(t),s=r.width,o=r.height;t.useData=!1;var c=document.createElement("canvas");c.width=t.canvas.width,c.height=t.canvas.height;var h=c.getContext("2d");h.drawImage(i,0,0);var l,p,g,v,d,u,f,m,x,C,w,P,I,D,M={canvas:c,options:t.options},b=Pixastic.prepareData(M),y=M.canvasData,_=4*(S=s*o),k=!1;switch(e){case"normal":break;case"multiply":for(;S--;)b[_-=4]=n[_]*b[_]/255,b[l=_+1]=n[l]*b[l]/255,b[p=_+2]=n[p]*b[p]/255;k=!0;break;case"lighten":for(;S--;)(g=n[_-=4])>b[_]&&(b[_]=g),(v=n[l=_+1])>b[l]&&(b[l]=v),(d=n[p=_+2])>b[p]&&(b[p]=d);k=!0;break;case"darken":for(;S--;)(g=n[_-=4])<b[_]&&(b[_]=g),(v=n[l=_+1])<b[l]&&(b[l]=v),(d=n[p=_+2])<b[p]&&(b[p]=d);k=!0;break;case"darkercolor":for(;S--;).3*(g=n[_-=4])+.59*(v=n[l=_+1])+.11*(d=n[p=_+2])<=.3*b[_]+.59*b[l]+.11*b[p]&&(b[_]=g,b[l]=v,b[p]=d);k=!0;break;case"lightercolor":for(;S--;).3*(g=n[_-=4])+.59*(v=n[l=_+1])+.11*(d=n[p=_+2])>.3*b[_]+.59*b[l]+.11*b[p]&&(b[_]=g,b[l]=v,b[p]=d);k=!0;break;case"lineardodge":for(;S--;)(x=n[_-=4]+b[_])>255?b[_]=255:b[_]=x,(C=n[l=_+1]+b[l])>255?b[l]=255:b[l]=C,(w=n[p=_+2]+b[p])>255?b[p]=255:b[p]=w;k=!0;break;case"linearburn":for(;S--;)(x=n[_-=4]+b[_])<255?b[_]=0:b[_]=x-255,(C=n[l=_+1]+b[l])<255?b[l]=0:b[l]=C-255,(w=n[p=_+2]+b[p])<255?b[p]=0:b[p]=w-255;k=!0;break;case"difference":for(;S--;)(x=n[_-=4]-b[_])<0?b[_]=-x:b[_]=x,(C=n[l=_+1]-b[l])<0?b[l]=-C:b[l]=C,(w=n[p=_+2]-b[p])<0?b[p]=-w:b[p]=w;k=!0;break;case"screen":for(;S--;)b[_-=4]=255-((255-b[_])*(255-n[_])>>8),b[l=_+1]=255-((255-b[l])*(255-n[l])>>8),b[p=_+2]=255-((255-b[p])*(255-n[p])>>8);k=!0;break;case"exclusion":for(var A=2/255;S--;)b[_-=4]=(g=n[_])-(g*A-1)*b[_],b[l=_+1]=(v=n[l])-(v*A-1)*b[l],b[p=_+2]=(d=n[p])-(d*A-1)*b[p];k=!0;break;case"overlay":for(A=2/255;S--;)(g=n[_-=4])<128?b[_]=b[_]*g*A:b[_]=255-(255-b[_])*(255-g)*A,(v=n[l=_+1])<128?b[l]=b[l]*v*A:b[l]=255-(255-b[l])*(255-v)*A,(d=n[p=_+2])<128?b[p]=b[p]*d*A:b[p]=255-(255-b[p])*(255-d)*A;k=!0;break;case"softlight":for(A=2/255;S--;)(g=n[_-=4])<128?b[_]=(64+(b[_]>>1))*g*A:b[_]=255-(191-(b[_]>>1))*(255-g)*A,(v=n[l=_+1])<128?b[l]=(64+(b[l]>>1))*v*A:b[l]=255-(191-(b[l]>>1))*(255-v)*A,(d=n[p=_+2])<128?b[p]=(64+(b[p]>>1))*d*A:b[p]=255-(191-(b[p]>>1))*(255-d)*A;k=!0;break;case"hardlight":for(A=2/255;S--;)(u=b[_-=4])<128?b[_]=n[_]*u*A:b[_]=255-(255-n[_])*(255-u)*A,(f=b[l=_+1])<128?b[l]=n[l]*f*A:b[l]=255-(255-n[l])*(255-f)*A,(m=b[p=_+2])<128?b[p]=n[p]*m*A:b[p]=255-(255-n[p])*(255-m)*A;k=!0;break;case"colordodge":for(;S--;)(x=(n[_-=4]<<8)/(255-(u=b[_])))>255||255==u?b[_]=255:b[_]=x,(C=(n[l=_+1]<<8)/(255-(f=b[l])))>255||255==f?b[l]=255:b[l]=C,(w=(n[p=_+2]<<8)/(255-(m=b[p])))>255||255==m?b[p]=255:b[p]=w;k=!0;break;case"colorburn":for(;S--;)(x=255-(255-n[_-=4]<<8)/b[_])<0||0==b[_]?b[_]=0:b[_]=x,(C=255-(255-n[l=_+1]<<8)/b[l])<0||0==b[l]?b[l]=0:b[l]=C,(w=255-(255-n[p=_+2]<<8)/b[p])<0||0==b[p]?b[p]=0:b[p]=w;k=!0;break;case"linearlight":for(;S--;)(x=2*(u=b[_-=4])+n[_]-256)<0||u<128&&x<0?b[_]=0:b[_]=x>255?255:x,(C=2*(f=b[l=_+1])+n[l]-256)<0||f<128&&C<0?b[l]=0:b[l]=C>255?255:C,(w=2*(m=b[p=_+2])+n[p]-256)<0||m<128&&w<0?b[p]=0:b[p]=w>255?255:w;k=!0;break;case"vividlight":for(;S--;)(u=b[_-=4])<128?u?(x=255-(255-n[_]<<8)/(2*u))<0?b[_]=0:b[_]=x:b[_]=0:(x=P=2*u-256)<255?(x=(n[_]<<8)/(255-P))>255?b[_]=255:b[_]=x:b[_]=x<0?0:x,(f=b[l=_+1])<128?f?(C=255-(255-n[l]<<8)/(2*f))<0?b[l]=0:b[l]=C:b[l]=0:(C=I=2*f-256)<255?(C=(n[l]<<8)/(255-I))>255?b[l]=255:b[l]=C:b[l]=C<0?0:C,(m=b[p=_+2])<128?m?(w=255-(255-n[p]<<8)/(2*m))<0?b[p]=0:b[p]=w:b[p]=0:(w=D=2*m-256)<255?(w=(n[p]<<8)/(255-D))>255?b[p]=255:b[p]=w:b[p]=w<0?0:w;k=!0;break;case"pinlight":for(;S--;)(u=b[_-=4])<128?(g=n[_])<(P=2*u)?b[_]=g:b[_]=P:(g=n[_])>(P=2*u-256)?b[_]=g:b[_]=P,(f=b[l=_+1])<128?(v=n[l])<(I=2*f)?b[l]=v:b[l]=I:(v=n[l])>(I=2*f-256)?b[l]=v:b[l]=I,(u=b[p=_+2])<128?(g=n[p])<(P=2*u)?b[p]=g:b[p]=P:(g=n[p])>(P=2*u-256)?b[p]=g:b[p]=P;k=!0;break;case"hardmix":for(;S--;)(u=b[_-=4])<128?255-(255-n[_]<<8)/(2*u)<128||0==u?b[_]=0:b[_]=255:(P=2*u-256)<255&&(n[_]<<8)/(255-P)<128?b[_]=0:b[_]=255,(f=b[l=_+1])<128?255-(255-n[l]<<8)/(2*f)<128||0==f?b[l]=0:b[l]=255:(I=2*f-256)<255&&(n[l]<<8)/(255-I)<128?b[l]=0:b[l]=255,(m=b[p=_+2])<128?255-(255-n[p]<<8)/(2*m)<128||0==m?b[p]=0:b[p]=255:(D=2*m-256)<255&&(n[p]<<8)/(255-D)<128?b[p]=0:b[p]=255;k=!0}if(k&&h.putImageData(y,0,0),1==a||Pixastic.Client.hasGlobalAlpha()){var E=t.canvas.getContext("2d");E.save(),E.globalAlpha=a,E.drawImage(c,0,0,r.width,r.height,r.left,r.top,r.width,r.height),E.globalAlpha=1,E.restore()}else{for(var S=s*o,F=a,L=1-a;S--;){var N=n[_=4*S]*L+b[_]*F|0,R=n[_+1]*L+b[_+1]*F|0,T=n[_+2]*L+b[_+2]*F|0;n[_]=N,n[_+1]=R,n[_+2]=T}t.useData=!0}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.blur={process:function(t){if(void 0===t.options.fixMargin&&(t.options.fixMargin=!0),Pixastic.Client.hasCanvasImageData()){for(var a=Pixastic.prepareData(t),e=Pixastic.prepareData(t,!0),i=[[0,1,0],[1,2,1],[0,1,0]],r=0,n=0;n<3;n++)for(var s=0;s<3;s++)r+=i[n][s];r=1/(2*r);var o=t.options.rect,c=o.width,h=o.height,l=4*c,p=h;do{var g=(p-1)*l,v=(1==p?0:p-2)*c*4,d=(p==h?p-1:p)*c*4,u=c;do{var f=g+(4*u-4),m=v+4*(1==u?0:u-2),x=d+4*(u==c?u-1:u);a[f]=(2*(e[m]+e[f-4]+e[f+4]+e[x])+4*e[f])*r,a[f+1]=(2*(e[m+1]+e[f-3]+e[f+5]+e[x+1])+4*e[f+1])*r,a[f+2]=(2*(e[m+2]+e[f-2]+e[f+6]+e[x+2])+4*e[f+2])*r}while(--u)}while(--p);return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" progid:DXImageTransform.Microsoft.Blur(pixelradius=1.5)",t.options.fixMargin&&(t.image.style.marginLeft=(parseInt(t.image.style.marginLeft,10)||0)-2+"px",t.image.style.marginTop=(parseInt(t.image.style.marginTop,10)||0)-2+"px"),!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.blurfast={process:function(t){var a=parseFloat(t.options.amount)||0,e=!(!t.options.clear||"false"==t.options.clear);if(a=Math.max(0,Math.min(5,a)),Pixastic.Client.hasCanvas()){var i=t.options.rect,r=t.canvas.getContext("2d");r.save(),r.beginPath(),r.rect(i.left,i.top,i.width,i.height),r.clip();var n=Math.round(t.width/2),s=Math.round(t.height/2),o=document.createElement("canvas");o.width=n,o.height=s;e=!1;for(var c=Math.round(20*a),h=o.getContext("2d"),l=0;l<c;l++){var p=Math.max(1,Math.round(n-l)),g=Math.max(1,Math.round(s-l));h.clearRect(0,0,n,s),h.drawImage(t.canvas,0,0,t.width,t.height,0,0,p,g),e&&r.clearRect(i.left,i.top,i.width,i.height),r.drawImage(o,0,0,p,g,0,0,t.width,t.height)}return r.restore(),t.useData=!1,!0}if(Pixastic.Client.isIE()){var v=10*a;return t.image.style.filter+=" progid:DXImageTransform.Microsoft.Blur(pixelradius="+v+")",t.options.fixMargin,t.image.style.marginLeft=(parseInt(t.image.style.marginLeft,10)||0)-Math.round(v)+"px",t.image.style.marginTop=(parseInt(t.image.style.marginTop,10)||0)-Math.round(v)+"px",!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()||Pixastic.Client.isIE()}},Pixastic.Actions.brightness={process:function(t){var a=parseInt(t.options.brightness,10)||0,e=parseFloat(t.options.contrast)||0,i=!(!t.options.legacy||"false"==t.options.legacy);if(i)a=Math.min(150,Math.max(-150,a));else var r=1+Math.min(150,Math.max(-150,a))/150;if(e=Math.max(0,e+1),Pixastic.Client.hasCanvasImageData()){var n,s,o,c,h,l,p,g=Pixastic.prepareData(t),v=t.options.rect,d=v.width*v.height,u=4*d;for(1!=e?i?(o=e,c=(a-128)*e+128):(o=r*e,c=128*-e+128):i?(o=1,c=a):(o=r,c=0);d--;)(h=g[u-=4]*o+c)>255?g[u]=255:g[u]=h<0?0:h,(l=g[n=u+1]*o+c)>255?g[n]=255:g[n]=l<0?0:l,(p=g[s=u+2]*o+c)>255?g[s]=255:g[s]=p<0?0:p;return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.coloradjust={process:function(t){var a=parseFloat(t.options.red)||0,e=parseFloat(t.options.green)||0,i=parseFloat(t.options.blue)||0;if(a=Math.round(255*a),e=Math.round(255*e),i=Math.round(255*i),Pixastic.Client.hasCanvasImageData()){for(var r,n,s,o,c,h=Pixastic.prepareData(t),l=t.options.rect,p=l.width*l.height,g=4*p;p--;)g-=4,a&&((s=h[g]+a)<0?h[g]=0:h[g]=s>255?255:s),e&&((o=h[r=g+1]+e)<0?h[r]=0:h[r]=o>255?255:o),i&&((c=h[n=g+2]+i)<0?h[n]=0:h[n]=c>255?255:c);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.colorhistogram={array256:function(t){arr=[];for(var a=0;a<256;a++)arr[a]=t;return arr},process:function(t){"object"!=typeof t.options.returnValue&&(t.options.returnValue={rvals:[],gvals:[],bvals:[]});var a=!!t.options.paint,e=t.options.returnValue;if("array"!=typeof e.values&&(e.rvals=[],e.gvals=[],e.bvals=[]),Pixastic.Client.hasCanvasImageData()){var i=Pixastic.prepareData(t);t.useData=!1;for(var r=this.array256(0),n=this.array256(0),s=this.array256(0),o=t.options.rect,c=o.width*o.height,h=4*c;c--;)r[i[h-=4]]++,n[i[h+1]]++,s[i[h+2]]++;if(e.rvals=r,e.gvals=n,e.bvals=s,a)for(var l=t.canvas.getContext("2d"),p=[r,n,s],g=0;g<3;g++){for(var v=(g+1)*t.height/3,d=0,u=0;u<256;u++)p[g][u]>d&&(d=p[g][u]);var f=t.height/3/d,m=t.width/256;0==g?l.fillStyle="rgba(255,0,0,0.5)":1==g?l.fillStyle="rgba(0,255,0,0.5)":2==g&&(l.fillStyle="rgba(0,0,255,0.5)");for(u=0;u<256;u++)l.fillRect(u*m,t.height-f*p[g][u]-t.height+v,m,p[g][u]*f)}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.crop={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.options.rect,e=a.width,i=a.height,r=a.top,n=a.left;void 0!==t.options.left&&(n=parseInt(t.options.left,10)),void 0!==t.options.top&&(r=parseInt(t.options.top,10)),void 0!==t.options.height&&(e=parseInt(t.options.width,10)),void 0!==t.options.height&&(i=parseInt(t.options.height,10)),n<0&&(n=0),n>t.width-1&&(n=t.width-1),r<0&&(r=0),r>t.height-1&&(r=t.height-1),e<1&&(e=1),n+e>t.width&&(e=t.width-n),i<1&&(i=1),r+i>t.height&&(i=t.height-r);var s=document.createElement("canvas");return s.width=t.width,s.height=t.height,s.getContext("2d").drawImage(t.canvas,0,0),t.canvas.width=e,t.canvas.height=i,t.canvas.getContext("2d").clearRect(0,0,e,i),t.canvas.getContext("2d").drawImage(s,n,r,e,i,0,0,e,i),t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.desaturate={process:function(t){var a=!(!t.options.average||"false"==t.options.average);if(Pixastic.Client.hasCanvasImageData()){var e,i,r=Pixastic.prepareData(t),n=t.options.rect,s=n.width*n.height,o=4*s;if(a)for(;s--;)r[o-=4]=r[e=o+1]=r[i=o+2]=(r[o]+r[e]+r[i])/3;else for(;s--;)r[o-=4]=r[e=o+1]=r[i=o+2]=.3*r[o]+.59*r[e]+.11*r[i];return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" gray",!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.edges={process:function(t){var a=!(!t.options.mono||"false"==t.options.mono),e=!(!t.options.invert||"false"==t.options.invert);if(Pixastic.Client.hasCanvasImageData()){var i=Pixastic.prepareData(t),r=Pixastic.prepareData(t,!0),n=-1/8;weight=-8;var s=t.options.rect,o=s.width,c=s.height,h=4*o,l=c;do{var p=(l-1)*h,g=(1==l?0:l-2)*o*4,v=(l==c?l-1:l)*o*4,d=o;do{var u=p+(4*d-4),f=g+4*(1==d?0:d-2),m=v+4*(d==o?d-1:d),x=((r[f-4]+r[f]+r[f+4]+r[u-4]+r[u+4]+r[m-4]+r[m]+r[m+4])*n+r[u])*weight,C=((r[f-3]+r[f+1]+r[f+5]+r[u-3]+r[u+5]+r[m-3]+r[m+1]+r[m+5])*n+r[u+1])*weight,w=((r[f-2]+r[f+2]+r[f+6]+r[u-2]+r[u+6]+r[m-2]+r[m+2]+r[m+6])*n+r[u+2])*weight;if(a){var P=.3*x+.59*C+.11*w||0;e&&(P=255-P),P<0&&(P=0),P>255&&(P=255),x=C=w=P}else e&&(x=255-x,C=255-C,w=255-w),x<0&&(x=0),C<0&&(C=0),w<0&&(w=0),x>255&&(x=255),C>255&&(C=255),w>255&&(w=255);i[u]=x,i[u+1]=C,i[u+2]=w}while(--d)}while(--l);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.edges2={process:function(t){if(Pixastic.Client.hasCanvasImageData()){for(var a=Pixastic.prepareData(t),e=Pixastic.prepareData(t,!0),i=t.options.rect,r=i.width,n=4*r,s=n+4,o=i.height-1,c=r-1,h=1;h<o;++h){for(var l=s-4,p=l-n,g=l+n,v=-e[p]-e[l]-e[g],d=-e[++p]-e[++l]-e[++g],u=-e[++p]-e[++l]-e[++g],f=e[p+=2],m=e[++p],x=e[++p],C=e[l+=2],w=e[++l],P=e[++l],I=e[g+=2],D=e[++g],M=e[++g],b=-f-C-I,y=-m-w-D,_=-x-P-M,k=1;k<c;++k){g=(l=s+4)+n;var A=127+v-f- -8*C-I,E=127+d-m- -8*w-D,S=127+u-x- -8*P-M;v=b,d=y,u=_,f=e[p=l-n],m=e[++p],x=e[++p],C=e[l],w=e[++l],P=e[++l],(A+=b=-f-C-(I=e[g]))>255&&(A=255),(E+=y=-m-w-(D=e[++g]))>255&&(E=255),(S+=_=-x-P-(M=e[++g]))>255&&(S=255),A<0&&(A=0),E<0&&(E=0),S<0&&(S=0),a[s]=A,a[++s]=E,a[++s]=S,s+=2}s+=8}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.emboss={process:function(t){var a=parseFloat(t.options.strength)||1,e=void 0!==t.options.greyLevel?parseInt(t.options.greyLevel):180,i=t.options.direction||"topleft",r=!(!t.options.blend||"false"==t.options.blend),n=0,s=0;switch(i){case"topleft":n=-1,s=-1;break;case"top":n=-1,s=0;break;case"topright":n=-1,s=1;break;case"right":n=0,s=1;break;case"bottomright":n=1,s=1;break;case"bottom":n=1,s=0;break;case"bottomleft":n=1,s=-1;break;case"left":n=0,s=-1}if(Pixastic.Client.hasCanvasImageData()){var o=Pixastic.prepareData(t),c=Pixastic.prepareData(t,!0),h=(t.options.invertAlpha,t.options.rect),l=h.width,p=h.height,g=4*l,v=p;do{var d=(v-1)*g,u=n;v+u<1&&(u=0),v+u>p&&(u=0);var f=(v-1+u)*l*4,m=l;do{var x=d+4*(m-1),C=s;m+C<1&&(C=0),m+C>l&&(C=0);var w=f+4*(m-1+C),P=c[x]-c[w],I=c[x+1]-c[w+1],D=c[x+2]-c[w+2],M=P,b=M>0?M:-M;if((I>0?I:-I)>b&&(M=I),(D>0?D:-D)>b&&(M=D),M*=a,r){var y=o[x]+M,_=o[x+1]+M,k=o[x+2]+M;o[x]=y>255?255:y<0?0:y,o[x+1]=_>255?255:_<0?0:_,o[x+2]=k>255?255:k<0?0:k}else{var A=e-M;A<0?A=0:A>255&&(A=255),o[x]=o[x+1]=o[x+2]=A}}while(--m)}while(--v);return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" progid:DXImageTransform.Microsoft.emboss()",!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.flip={process:function(t){var a=t.options.rect,e=document.createElement("canvas");e.width=a.width,e.height=a.height,e.getContext("2d").drawImage(t.image,a.left,a.top,a.width,a.height,0,0,a.width,a.height);var i=t.canvas.getContext("2d");return i.clearRect(a.left,a.top,a.width,a.height),"horizontal"==t.options.axis?(i.scale(-1,1),i.drawImage(e,-a.left-a.width,a.top,a.width,a.height)):(i.scale(1,-1),i.drawImage(e,a.left,-a.top-a.height,a.width,a.height)),t.useData=!1,!0},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.fliph={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.options.rect,e=document.createElement("canvas");e.width=a.width,e.height=a.height,e.getContext("2d").drawImage(t.image,a.left,a.top,a.width,a.height,0,0,a.width,a.height);var i=t.canvas.getContext("2d");return i.clearRect(a.left,a.top,a.width,a.height),i.scale(-1,1),i.drawImage(e,-a.left-a.width,a.top,a.width,a.height),t.useData=!1,!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" fliph",!0},checkSupport:function(){return Pixastic.Client.hasCanvas()||Pixastic.Client.isIE()}},Pixastic.Actions.flipv={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.options.rect,e=document.createElement("canvas");e.width=a.width,e.height=a.height,e.getContext("2d").drawImage(t.image,a.left,a.top,a.width,a.height,0,0,a.width,a.height);var i=t.canvas.getContext("2d");return i.clearRect(a.left,a.top,a.width,a.height),i.scale(1,-1),i.drawImage(e,a.left,-a.top-a.height,a.width,a.height),t.useData=!1,!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" flipv",!0},checkSupport:function(){return Pixastic.Client.hasCanvas()||Pixastic.Client.isIE()}},Pixastic.Actions.glow={process:function(t){var a=parseFloat(t.options.amount)||0,e=parseFloat(t.options.radius)||0;if(a=Math.min(1,Math.max(0,a)),e=Math.min(5,Math.max(0,e)),Pixastic.Client.hasCanvasImageData()){var i=t.options.rect,r=document.createElement("canvas");r.width=t.width,r.height=t.height;var n=r.getContext("2d");n.drawImage(t.canvas,0,0);var s=Math.round(t.width/2),o=Math.round(t.height/2),c=document.createElement("canvas");c.width=s,c.height=o;for(var h=Math.round(20*e),l=c.getContext("2d"),p=0;p<h;p++){var g=Math.max(1,Math.round(s-p)),v=Math.max(1,Math.round(o-p));l.clearRect(0,0,s,o),l.drawImage(r,0,0,t.width,t.height,0,0,g,v),n.clearRect(0,0,t.width,t.height),n.drawImage(c,0,0,g,v,0,0,t.width,t.height)}for(var d=Pixastic.prepareData(t),u=Pixastic.prepareData({canvas:r,options:t.options}),f=i.width*i.height,m=4*f,x=m+1,C=m+2;f--;)(d[m-=4]+=a*u[m])>255&&(d[m]=255),(d[x-=4]+=a*u[x])>255&&(d[x]=255),(d[C-=4]+=a*u[C])>255&&(d[C]=255);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.histogram={process:function(t){var a=!(!t.options.average||"false"==t.options.average),e=!(!t.options.paint||"false"==t.options.paint),i=t.options.color||"rgba(255,255,255,0.5)",r=[];"object"!=typeof t.options.returnValue&&(t.options.returnValue={values:[]});var n=t.options.returnValue;if("array"!=typeof n.values&&(n.values=[]),r=n.values,Pixastic.Client.hasCanvasImageData()){var s=Pixastic.prepareData(t);t.useData=!1;for(var o=0;o<256;o++)r[o]=0;var c=t.options.rect,h=c.width*c.height,l=4*h,p=Math.round;if(a)for(;h--;)r[p((s[l-=4]+s[l+1]+s[l+2])/3)]++;else for(;h--;)r[p(.3*s[l-=4]+.59*s[l+1]+.11*s[l+2])]++;if(e){var g=0;for(o=0;o<256;o++)r[o]>g&&(g=r[o]);var v=t.height/g,d=t.width/256,u=t.canvas.getContext("2d");u.fillStyle=i;for(o=0;o<256;o++)u.fillRect(o*d,t.height-v*r[o],d,r[o]*v)}return n.values=r,!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.hsl={process:function(t){var a=parseInt(t.options.hue,10)||0,e=(parseInt(t.options.saturation,10)||0)/100,i=(parseInt(t.options.lightness,10)||0)/100;if(e<0)var r=1+e;else r=1+2*e;var n=6*(a=a%360/360),s=255*i,o=1+i,c=1-i;if(Pixastic.Client.hasCanvasImageData()){for(var h=Pixastic.prepareData(t),l=t.options.rect,p=l.width*l.height,g=4*p,v=g+1,d=g+2;p--;){var u=h[g-=4],f=h[v=g+1],m=h[d=g+2];if(0!=a||0!=e){var x=u;f>x&&(x=f),m>x&&(x=m);var C=u;f<C&&(C=f),m<C&&(C=m);var w=x-C,P=(C+x)/510;if(P>0&&w>0){if(P<=.5){(D=w/(x+C)*r)>1&&(D=1);var I=P*(1+D)}else{var D;(D=w/(510-x-C)*r)>1&&(D=1);I=P+D-P*D}if(u==x)if(f==C)var M=5+(x-m)/w+n;else M=1-(x-f)/w+n;else if(f==x)if(m==C)M=1+(x-u)/w+n;else M=3-(x-m)/w+n;else if(u==C)M=3+(x-f)/w+n;else M=5-(x-u)/w+n;M<0&&(M+=6),M>=6&&(M-=6);var b=P+P-I,y=M|0;0==y?(u=255*I,f=255*(b+(I-b)*(M-y)),m=255*b):1==y?(u=255*(I-(I-b)*(M-y)),f=255*I,m=255*b):2==y?(u=255*b,f=255*I,m=255*(b+(I-b)*(M-y))):3==y?(u=255*b,f=255*(I-(I-b)*(M-y)),m=255*I):4==y?(u=255*(b+(I-b)*(M-y)),f=255*b,m=255*I):5==y&&(u=255*I,f=255*b,m=255*(I-(I-b)*(M-y)))}}i<0?(u*=o,f*=o,m*=o):i>0&&(u=u*c+s,f=f*c+s,m=m*c+s),h[g]=u<0?0:u>255?255:u,h[v]=f<0?0:f>255?255:f,h[d]=m<0?0:m>255?255:m}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.invert={process:function(t){if(Pixastic.Client.hasCanvasImageData()){for(var a=Pixastic.prepareData(t),e=!!t.options.invertAlpha,i=t.options.rect,r=i.width*i.height,n=4*r,s=n+1,o=n+2,c=n+3;r--;)a[n-=4]=255-a[n],a[s-=4]=255-a[s],a[o-=4]=255-a[o],e&&(a[c-=4]=255-a[c]);return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" invert",!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.laplace={process:function(t){var a=!(!t.options.invert||"false"==t.options.invert),e=parseFloat(t.options.edgeStrength)||0,i=parseInt(t.options.greyLevel)||0;if(e=-e,Pixastic.Client.hasCanvasImageData()){var r=Pixastic.prepareData(t),n=Pixastic.prepareData(t,!0),s=1/8,o=t.options.rect,c=o.width,h=o.height,l=4*c,p=h;do{var g=(p-1)*l,v=(1==p?0:p-2)*c*4,d=(p==h?p-1:p)*c*4,u=c;do{var f=g+(4*u-4),m=v+4*(1==u?0:u-2),x=d+4*(u==c?u-1:u),C=((-n[m-4]-n[m]-n[m+4]-n[f-4]-n[f+4]-n[x-4]-n[x]-n[x+4]+8*n[f])*s+(-n[m-3]-n[m+1]-n[m+5]-n[f-3]-n[f+5]-n[x-3]-n[x+1]-n[x+5]+8*n[f+1])*s+(-n[m-2]-n[m+2]-n[m+6]-n[f-2]-n[f+6]-n[x-2]-n[x+2]-n[x+6]+8*n[f+2])*s)/3+i;0!=e&&(C>127?C+=(C+1-128)*e:C<127&&(C-=(C+1)*e)),a&&(C=255-C),C<0&&(C=0),C>255&&(C=255),r[f]=r[f+1]=r[f+2]=C}while(--u)}while(--p);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.lighten={process:function(t){var a=parseFloat(t.options.amount)||0;if(a=Math.max(-1,Math.min(1,a)),Pixastic.Client.hasCanvasImageData()){for(var e=Pixastic.prepareData(t),i=t.options.rect,r=i.width*i.height,n=4*r,s=n+1,o=n+2,c=a+1;r--;)(e[n-=4]=e[n]*c)>255&&(e[n]=255),(e[s-=4]=e[s]*c)>255&&(e[s]=255),(e[o-=4]=e[o]*c)>255&&(e[o]=255);return!0}if(Pixastic.Client.isIE()){var h=t.image;return a<0?(h.style.filter+=" light()",h.filters[h.filters.length-1].addAmbient(255,255,255,100*-a)):a>0&&(h.style.filter+=" light()",h.filters[h.filters.length-1].addAmbient(255,255,255,100),h.filters[h.filters.length-1].addAmbient(255,255,255,100*a)),!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.mosaic={process:function(t){var a=Math.max(1,parseInt(t.options.blockSize,10));if(Pixastic.Client.hasCanvasImageData()){var e=t.options.rect,i=e.width,r=e.height,n=r,s=t.canvas.getContext("2d"),o=document.createElement("canvas");o.width=o.height=1;var c=o.getContext("2d"),h=document.createElement("canvas");h.width=i,h.height=r,h.getContext("2d").drawImage(t.canvas,e.left,e.top,i,r,0,0,i,r);for(n=0;n<r;n+=a)for(var l=0;l<i;l+=a){var p=a,g=a;p+l>i&&(p=i-l),g+n>r&&(g=r-n),c.drawImage(h,l,n,p,g,0,0,1,1);var v=c.getImageData(0,0,1,1).data;s.fillStyle="rgb("+v[0]+","+v[1]+","+v[2]+")",s.fillRect(e.left+l,e.top+n,a,a)}return t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.noise={process:function(t){var a=0,e=0,i=!1;void 0!==t.options.amount&&(a=parseFloat(t.options.amount)||0),void 0!==t.options.strength&&(e=parseFloat(t.options.strength)||0),void 0!==t.options.mono&&(i=!(!t.options.mono||"false"==t.options.mono)),a=Math.max(0,Math.min(1,a));var r=128*(e=Math.max(0,Math.min(1,e))),n=r/2;if(Pixastic.Client.hasCanvasImageData()){var s=Pixastic.prepareData(t),o=t.options.rect,c=o.width,h=4*c,l=o.height,p=Math.random;do{var g=(l-1)*h,v=c;do{var d=g+4*(v-1);if(p()<a){if(i)var u=-n+p()*r,f=s[d]+u,m=s[d+1]+u,x=s[d+2]+u;else f=s[d]-n+p()*r,m=s[d+1]-n+p()*r,x=s[d+2]-n+p()*r;f<0&&(f=0),m<0&&(m=0),x<0&&(x=0),f>255&&(f=255),m>255&&(m=255),x>255&&(x=255),s[d]=f,s[d+1]=m,s[d+2]=x}}while(--v)}while(--l);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.posterize={process:function(t){var a=256;if(void 0!==t.options.levels&&(a=parseInt(t.options.levels,10)||1),Pixastic.Client.hasCanvasImageData()){var e=Pixastic.prepareData(t),i=256/(a=Math.max(2,Math.min(256,a))),r=256/(a-1),n=t.options.rect,s=n.width,o=4*s,c=n.height;do{var h=(c-1)*o,l=s;do{var p=h+4*(l-1),g=r*(e[p]/i|0),v=r*(e[p+1]/i|0),d=r*(e[p+2]/i|0);g>255&&(g=255),v>255&&(v=255),d>255&&(d=255),e[p]=g,e[p+1]=v,e[p+2]=d}while(--l)}while(--c);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.pointillize={process:function(t){var a=Math.max(1,parseInt(t.options.radius,10)),e=Math.min(5,Math.max(0,parseFloat(t.options.density)||0)),i=Math.max(0,parseFloat(t.options.noise)||0),r=!(!t.options.transparent||"false"==t.options.transparent);if(Pixastic.Client.hasCanvasImageData()){var n=t.options.rect,s=n.width,o=n.height,c=o,h=t.canvas.getContext("2d"),l=t.canvas.width,p=t.canvas.height,g=document.createElement("canvas");g.width=g.height=1;var v=g.getContext("2d"),d=document.createElement("canvas");d.width=s,d.height=o,d.getContext("2d").drawImage(t.canvas,n.left,n.top,s,o,0,0,s,o);var u=2*a;r&&h.clearRect(n.left,n.top,n.width,n.height);var f=a*i,m=1/e;for(c=0;c<o+a;c+=u*m)for(var x=0;x<s+a;x+=u*m){rndX=i?x+(2*Math.random()-1)*f|0:x,rndY=i?c+(2*Math.random()-1)*f|0:c;var C=rndX-a,w=rndY-a;C<0&&(C=0),w<0&&(w=0);var P=rndX+n.left,I=rndY+n.top;P<0&&(P=0),P>l&&(P=l),I<0&&(I=0),I>p&&(I=p);var D=u,M=u;D+C>s&&(D=s-C),M+w>o&&(M=o-w),D<1&&(D=1),M<1&&(M=1),v.drawImage(d,C,w,D,M,0,0,1,1);var b=v.getImageData(0,0,1,1).data;h.fillStyle="rgb("+b[0]+","+b[1]+","+b[2]+")",h.beginPath(),h.arc(P,I,a,0,2*Math.PI,!0),h.closePath(),h.fill()}return t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.removenoise={process:function(t){if(Pixastic.Client.hasCanvasImageData()){var a=Pixastic.prepareData(t),e=t.options.rect,i=e.width,r=e.height,n=4*i,s=r;do{var o=(s-1)*n,c=(1==s?0:s-2)*i*4,h=(s==r?s-1:s)*i*4,l=i;do{var p,g,v,d,u,f,m=o+(4*l-4),x=c+4*(1==l?0:l-2),C=h+4*(l==i?l-1:l);p=g=a[x];var w=a[m-4],P=a[m+4],I=a[C];w<p&&(p=w),P<p&&(p=P),I<p&&(p=I),w>g&&(g=w),P>g&&(g=P),I>g&&(g=I),v=d=a[x+1];var D=a[m-3],M=a[m+5],b=a[C+1];D<v&&(v=D),M<v&&(v=M),b<v&&(v=b),D>d&&(d=D),M>d&&(d=M),b>d&&(d=b),u=f=a[x+2];var y=a[m-2],_=a[m+6],k=a[C+2];y<u&&(u=y),_<u&&(u=_),k<u&&(u=k),y>f&&(f=y),_>f&&(f=_),k>f&&(f=k),a[m]>g?a[m]=g:a[m]<p&&(a[m]=p),a[m+1]>d?a[m+1]=d:a[m+1]<v&&(a[m+1]=v),a[m+2]>f?a[m+2]=f:a[m+2]<u&&(a[m+2]=u)}while(--l)}while(--s);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.resize={process:function(t){if(Pixastic.Client.hasCanvas()){var a=parseInt(t.options.width,10),e=parseInt(t.options.height,10),i=t.canvas;a<1&&(a=1),a<2&&(a=2);var r=document.createElement("canvas");return r.width=a,r.height=e,r.getContext("2d").drawImage(i,0,0,a,e),i.width=a,i.height=e,i.getContext("2d").drawImage(r,0,0),t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.rotate={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.canvas,e=t.width,i=t.height,r=document.createElement("canvas");r.width=e,r.height=i,r.getContext("2d").drawImage(a,0,0,e,i);var n=-parseFloat(t.options.angle)*Math.PI/180,s=n;s>.5*Math.PI&&(s=Math.PI-s),s<.5*-Math.PI&&(s=-Math.PI-s);var o=Math.sqrt(e*e+i*i),c=Math.abs(s)-Math.abs(Math.atan2(i,e)),h=Math.abs(s)+Math.abs(Math.atan2(i,e)),l=Math.abs(Math.cos(c)*o),p=Math.abs(Math.sin(h)*o);a.width=l,a.height=p;var g=a.getContext("2d");return g.translate(l/2,p/2),g.rotate(n),g.drawImage(r,-e/2,-i/2),t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.sepia={process:function(t){var a=parseInt(t.options.mode,10)||0;if(a<0&&(a=0),a>1&&(a=1),Pixastic.Client.hasCanvasImageData()){var e=Pixastic.prepareData(t),i=t.options.rect,r=i.width,n=4*r,s=i.height;do{var o=(s-1)*n,c=r;do{var h=o+4*(c-1);if(a)var l=.299*e[h]+.587*e[h+1]+.114*e[h+2],p=l+39,g=l+14,v=l-36;else{var d=e[h],u=e[h+1],f=e[h+2];p=.393*d+.769*u+.189*f,g=.349*d+.686*u+.168*f,v=.272*d+.534*u+.131*f}p<0&&(p=0),p>255&&(p=255),g<0&&(g=0),g>255&&(g=255),v<0&&(v=0),v>255&&(v=255),e[h]=p,e[h+1]=g,e[h+2]=v}while(--c)}while(--s);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.sharpen={process:function(t){var a=0;if(void 0!==t.options.amount&&(a=parseFloat(t.options.amount)||0),a<0&&(a=0),a>1&&(a=1),Pixastic.Client.hasCanvasImageData()){for(var e=Pixastic.prepareData(t),i=Pixastic.prepareData(t,!0),r=15,n=1+3*a,s=[[0,-n,0],[-n,r,-n],[0,-n,0]],o=0,c=0;c<3;c++)for(var h=0;h<3;h++)o+=s[c][h];o=1/o;var l=t.options.rect,p=l.width,g=l.height;r*=o,n*=o;var v=4*p,d=g;do{var u=(d-1)*v,f=(1==d?0:d-2)*v,m=(d==g?d-1:d)*v,x=p;do{var C=u+(4*x-4),w=f+4*(1==x?0:x-2),P=m+4*(x==p?x-1:x),I=(-i[w]-i[C-4]-i[C+4]-i[P])*n+i[C]*r,D=(-i[w+1]-i[C-3]-i[C+5]-i[P+1])*n+i[C+1]*r,M=(-i[w+2]-i[C-2]-i[C+6]-i[P+2])*n+i[C+2]*r;I<0&&(I=0),D<0&&(D=0),M<0&&(M=0),I>255&&(I=255),D>255&&(D=255),M>255&&(M=255),e[C]=I,e[C+1]=D,e[C+2]=M}while(--x)}while(--d);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.solarize={process:function(t){!t.options.average||t.options.average;if(Pixastic.Client.hasCanvasImageData()){var a=Pixastic.prepareData(t),e=t.options.rect,i=e.width,r=4*i,n=e.height;do{var s=(n-1)*r,o=i;do{var c=s+4*(o-1),h=a[c],l=a[c+1],p=a[c+2];h>127&&(h=255-h),l>127&&(l=255-l),p>127&&(p=255-p),a[c]=h,a[c+1]=l,a[c+2]=p}while(--o)}while(--n);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.unsharpmask={process:function(t){var a=parseFloat(t.options.amount)||0,e=parseFloat(t.options.radius)||0,i=parseFloat(t.options.threshold)||0;a=Math.min(500,Math.max(0,a))/2,e=Math.min(5,Math.max(0,e))/10,i=Math.min(255,Math.max(0,i));var r=- --i;if(a*=.016,a++,Pixastic.Client.hasCanvasImageData()){var n=t.options.rect,s=document.createElement("canvas");s.width=t.width,s.height=t.height;var o=s.getContext("2d");o.drawImage(t.canvas,0,0);var c=Math.round(t.width/2),h=Math.round(t.height/2),l=document.createElement("canvas");l.width=c,l.height=h;for(var p=Math.round(20*e),g=l.getContext("2d"),v=0;v<p;v++){var d=Math.max(1,Math.round(c-v)),u=Math.max(1,Math.round(h-v));g.clearRect(0,0,c,h),g.drawImage(s,0,0,t.width,t.height,0,0,d,u),o.clearRect(0,0,t.width,t.height),o.drawImage(l,0,0,d,u,0,0,t.width,t.height)}var f=Pixastic.prepareData(t),m=Pixastic.prepareData({canvas:s,options:t.options}),x=n.width,C=4*x,w=n.height;do{var P=(w-1)*C,I=x;do{var D=P+(4*I-4),M=f[D]-m[D];if(M>i||M<r){var b=m[D];b=a*M+b,f[D]=b>255?255:b<0?0:b}var y=f[D+1]-m[D+1];if(y>i||y<r){var _=m[D+1];_=a*y+_,f[D+1]=_>255?255:_<0?0:_}var k=f[D+2]-m[D+2];if(k>i||k<r){var A=m[D+2];A=a*k+A,f[D+2]=A>255?255:A<0?0:A}}while(--I)}while(--w);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}};var Base64={toBase64Table:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Pad:"=",encode:function(r){"use strict";var e,t="",a=Base64.toBase64Table.split(""),o=Base64.base64Pad,n=r.length;for(e=0;e<n-2;e+=3)t+=a[r[e]>>2],t+=a[((3&r[e])<<4)+(r[e+1]>>4)],t+=a[((15&r[e+1])<<2)+(r[e+2]>>6)],t+=a[63&r[e+2]];return n%3&&(t+=a[r[e=n-n%3]>>2],n%3==2?(t+=a[((3&r[e])<<4)+(r[e+1]>>4)],t+=a[(15&r[e+1])<<2],t+=o):(t+=a[(3&r[e])<<4],t+=o+o)),t},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:function(r,e){"use strict";e=void 0!==e?e:0;var t,a,o,n,c,h,d=Base64.toBinaryTable,i=Base64.base64Pad,f=0,C=0,s=r.indexOf("=")-e;for(s<0&&(s=r.length-e),a=3*(s>>2)+Math.floor(s%4/1.5),t=new Array(a),o=0,n=e;n<r.length;n++)c=d[127&r.charCodeAt(n)],h=r.charAt(n)===i,-1!==c?(C=C<<6|c,(f+=6)>=8&&(f-=8,h||(t[o++]=C>>f&255),C&=(1<<f)-1)):console.error("Illegal character code "+r.charCodeAt(n)+" at position "+n);if(f)throw{name:"Base64-Error",message:"Corrupted base64 string"};return t},_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encodeStr:function(r){var e,t,a,o,n,c,h,d="",i=0;for(r=Base64._utf8_encode(r);i<r.length;)o=(e=r.charCodeAt(i++))>>2,n=(3&e)<<4|(t=r.charCodeAt(i++))>>4,c=(15&t)<<2|(a=r.charCodeAt(i++))>>6,h=63&a,isNaN(t)?c=h=64:isNaN(a)&&(h=64),d=d+this._keyStr.charAt(o)+this._keyStr.charAt(n)+this._keyStr.charAt(c)+this._keyStr.charAt(h);return d},decodeStr:function(r){var e,t,a,o,n,c,h="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<r.length;)e=this._keyStr.indexOf(r.charAt(d++))<<2|(o=this._keyStr.indexOf(r.charAt(d++)))>>4,t=(15&o)<<4|(n=this._keyStr.indexOf(r.charAt(d++)))>>2,a=(3&n)<<6|(c=this._keyStr.indexOf(r.charAt(d++))),h+=String.fromCharCode(e),64!=n&&(h+=String.fromCharCode(t)),64!=c&&(h+=String.fromCharCode(a));return h=Base64._utf8_decode(h)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var e="",t=0;t<r.length;t++){var a=r.charCodeAt(t);a<128?e+=String.fromCharCode(a):a>127&&a<2048?(e+=String.fromCharCode(a>>6|192),e+=String.fromCharCode(63&a|128)):(e+=String.fromCharCode(a>>12|224),e+=String.fromCharCode(a>>6&63|128),e+=String.fromCharCode(63&a|128))}return e},_utf8_decode:function(r){for(var e="",t=0,a=c1=c2=0;t<r.length;)(a=r.charCodeAt(t))<128?(e+=String.fromCharCode(a),t++):a>191&&a<224?(c2=r.charCodeAt(t+1),e+=String.fromCharCode((31&a)<<6|63&c2),t+=2):(c2=r.charCodeAt(t+1),c3=r.charCodeAt(t+2),e+=String.fromCharCode((15&a)<<12|(63&c2)<<6|63&c3),t+=3);return e}};function BigInteger(e,t){if(!(this instanceof BigInteger))return e instanceof BigInteger?e:void 0===e?BigInteger.ZERO:BigInteger.parse(e);for(e=e||[];e.length&&!e[e.length-1];)--e.length;this._d=e,this._s=e.length?t||1:0}Array.prototype.map||(Array.prototype.map=function(e){var t=this.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=new Array(t),n=arguments[1],i=0;i<t;i++)i in this&&(r[i]=e.call(n,this[i],i,this));return r}),BigInteger.base=1e7,BigInteger.base_log10=7,BigInteger.init=function(){BigInteger.ZERO=new BigInteger([],0),BigInteger.ONE=new BigInteger([1],1),BigInteger.M_ONE=new BigInteger(BigInteger.ONE._d,-1),BigInteger._0=BigInteger.ZERO,BigInteger._1=BigInteger.ONE,BigInteger.small=[BigInteger.ZERO,BigInteger.ONE,new BigInteger([2],1),new BigInteger([3],1),new BigInteger([4],1),new BigInteger([5],1),new BigInteger([6],1),new BigInteger([7],1),new BigInteger([8],1),new BigInteger([9],1),new BigInteger([10],1),new BigInteger([11],1),new BigInteger([12],1),new BigInteger([13],1),new BigInteger([14],1),new BigInteger([15],1),new BigInteger([16],1),new BigInteger([17],1),new BigInteger([18],1),new BigInteger([19],1),new BigInteger([20],1),new BigInteger([21],1),new BigInteger([22],1),new BigInteger([23],1),new BigInteger([24],1),new BigInteger([25],1),new BigInteger([26],1),new BigInteger([27],1),new BigInteger([28],1),new BigInteger([29],1),new BigInteger([30],1),new BigInteger([31],1),new BigInteger([32],1),new BigInteger([33],1),new BigInteger([34],1),new BigInteger([35],1),new BigInteger([36],1)]},BigInteger.init(),BigInteger.digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),BigInteger.prototype.toString=function(e){if((e=+e||10)<2||e>36)throw new Error("illegal radix "+e+".");if(0===this._s)return"0";if(10===e){var t=this._s<0?"-":"";t+=this._d[this._d.length-1].toString();for(var r=this._d.length-2;r>=0;r--){for(var n=this._d[r].toString();n.length<BigInteger.base_log10;)n="0"+n;t+=n}return t}var i=BigInteger.digits;e=BigInteger.small[e];for(var g,s=this._s,o=this.abs(),a=[];0!==o._s;){var I=o.divRem(e);o=I[0],g=I[1],a.push(i[g.valueOf()])}return(s<0?"-":"")+a.reverse().join("")},BigInteger.radixRegex=[/^$/,/^$/,/^[01]*$/,/^[012]*$/,/^[0-3]*$/,/^[0-4]*$/,/^[0-5]*$/,/^[0-6]*$/,/^[0-7]*$/,/^[0-8]*$/,/^[0-9]*$/,/^[0-9aA]*$/,/^[0-9abAB]*$/,/^[0-9abcABC]*$/,/^[0-9a-dA-D]*$/,/^[0-9a-eA-E]*$/,/^[0-9a-fA-F]*$/,/^[0-9a-gA-G]*$/,/^[0-9a-hA-H]*$/,/^[0-9a-iA-I]*$/,/^[0-9a-jA-J]*$/,/^[0-9a-kA-K]*$/,/^[0-9a-lA-L]*$/,/^[0-9a-mA-M]*$/,/^[0-9a-nA-N]*$/,/^[0-9a-oA-O]*$/,/^[0-9a-pA-P]*$/,/^[0-9a-qA-Q]*$/,/^[0-9a-rA-R]*$/,/^[0-9a-sA-S]*$/,/^[0-9a-tA-T]*$/,/^[0-9a-uA-U]*$/,/^[0-9a-vA-V]*$/,/^[0-9a-wA-W]*$/,/^[0-9a-xA-X]*$/,/^[0-9a-yA-Y]*$/,/^[0-9a-zA-Z]*$/],BigInteger.parse=function(e,t){e=e.toString(),void 0!==t&&10!=+t||(e=e.replace(/\s*[*xX]\s*10\s*(\^|\*\*)\s*/,"e").replace(/^([+\-])?(\d+)\.?(\d*)[eE]([+\-]?\d+)$/,(function(e,t,r,n,i){var g=(i=+i)<0,s=r.length+i;e=(g?r:n).length,i=(i=Math.abs(i))>=e?i-e+g:0;var o=new Array(i+1).join("0"),a=r+n;return(t||"")+(g?a=o+a:a+=o).substr(0,s+=g?o.length:0)+(s<a.length?"."+a.substr(s):"")})));var r=/^([+\-]?)(0[xXcCbB])?([0-9A-Za-z]*)(?:\.\d*)?$/.exec(e);if(r){var n=r[1]||"+",i=r[2]||"",g=r[3]||"";if(void 0===t)t="0x"===i||"0X"===i?16:"0c"===i||"0C"===i?8:"0b"===i||"0B"===i?2:10;else if(t<2||t>36)throw new Error("Illegal radix "+t+".");if(t=+t,!BigInteger.radixRegex[t].test(g))throw new Error("Bad digit for radix "+t);if(0===(g=g.replace(/^0+/,"").split("")).length)return BigInteger.ZERO;if(n="-"===n?-1:1,10==t){for(var s=[];g.length>=BigInteger.base_log10;)s.push(parseInt(g.splice(-BigInteger.base_log10).join(""),10));return s.push(parseInt(g.join(""),10)),new BigInteger(s,n)}if(t===BigInteger.base)return new BigInteger(g.map(Number).reverse(),n);s=BigInteger.ZERO;t=BigInteger.small[t];for(var o=BigInteger.small,a=0;a<g.length;a++)s=s.multiply(t).add(o[parseInt(g[a],36)]);return new BigInteger(s._d,n)}throw new Error("Invalid BigInteger format: "+e)},BigInteger.prototype.add=function(e){if(0===this._s)return BigInteger(e);if(0===(e=BigInteger(e))._s)return this;if(this._s!==e._s)return e=e.negate(),this.subtract(e);for(var t,r=this._d,n=e._d,i=r.length,g=n.length,s=new Array(Math.max(i,g)+1),o=Math.min(i,g),a=0,I=0;I<o;I++)t=r[I]+n[I]+a,s[I]=t%BigInteger.base,a=t/BigInteger.base|0;for(g>i&&(r=n,i=g),I=o;a&&I<i;I++)t=r[I]+a,s[I]=t%BigInteger.base,a=t/BigInteger.base|0;for(a&&(s[I]=a);I<i;I++)s[I]=r[I];return new BigInteger(s,this._s)},BigInteger.prototype.negate=function(){return new BigInteger(this._d,-this._s)},BigInteger.prototype.abs=function(){return this._s<0?this.negate():this},BigInteger.prototype.subtract=function(e){if(0===this._s)return BigInteger(e).negate();if(0===(e=BigInteger(e))._s)return this;if(this._s!==e._s)return e=e.negate(),this.add(e);var t,r=this;this._s<0&&(t=r,r=new BigInteger(e._d,1),e=new BigInteger(t._d,1));var n=r.compareAbs(e);if(0===n)return BigInteger.ZERO;n<0&&(t=e,e=r,r=t);var i,g,s=r._d,o=e._d,a=s.length,I=o.length,B=new Array(a),h=0;for(i=0;i<I;i++)(g=s[i]-h-o[i])<0?(g+=BigInteger.base,h=1):h=0,B[i]=g;for(i=I;i<a;i++){if(!((g=s[i]-h)<0)){B[i++]=g;break}g+=BigInteger.base,B[i]=g}for(;i<a;i++)B[i]=s[i];return new BigInteger(B,n)},function(){function e(e,t){for(var r=e._d,n=r.slice(),i=0;;){var g=(r[i]||0)+1;if(n[i]=g%BigInteger.base,g<=BigInteger.base-1)break;++i}return new BigInteger(n,t)}function t(e,t){for(var r=e._d,n=r.slice(),i=0;;){var g=(r[i]||0)-1;if(!(g<0)){n[i]=g;break}n[i]=g+BigInteger.base,++i}return new BigInteger(n,t)}BigInteger.prototype.next=function(){switch(this._s){case 0:return BigInteger.ONE;case-1:return t(this,-1);default:return e(this,1)}},BigInteger.prototype.prev=function(){switch(this._s){case 0:return BigInteger.M_ONE;case-1:return e(this,-1);default:return t(this,1)}}}(),BigInteger.prototype.compareAbs=function(e){if(this===e)return 0;if(!(e instanceof BigInteger)){if(!isFinite(e))return isNaN(e)?e:-1;e=BigInteger(e)}if(0===this._s)return 0!==e._s?-1:0;if(0===e._s)return 1;var t=this._d.length,r=e._d.length;if(t<r)return-1;if(t>r)return 1;for(var n=this._d,i=e._d,g=t-1;g>=0;g--)if(n[g]!==i[g])return n[g]<i[g]?-1:1;return 0},BigInteger.prototype.compare=function(e){return this===e?0:(e=BigInteger(e),0===this._s?-e._s:this._s===e._s?this.compareAbs(e)*this._s:this._s)},BigInteger.prototype.isUnit=function(){return this===BigInteger.ONE||this===BigInteger.M_ONE||1===this._d.length&&1===this._d[0]},BigInteger.prototype.multiply=function(e){if(0===this._s)return BigInteger.ZERO;if(0===(e=BigInteger(e))._s)return BigInteger.ZERO;if(this.isUnit())return this._s<0?e.negate():e;if(e.isUnit())return e._s<0?this.negate():this;if(this===e)return this.square();var t,r=this._d.length>=e._d.length,n=(r?this:e)._d,i=(r?e:this)._d,g=n.length,s=i.length,o=g+s,a=new Array(o);for(t=0;t<o;t++)a[t]=0;for(t=0;t<s;t++){for(var I,B=0,h=i[t],u=g+t,f=t;f<u;f++)B=(I=a[f]+h*n[f-t]+B)/BigInteger.base|0,a[f]=I%BigInteger.base|0;B&&(B=(I=a[f]+B)/BigInteger.base|0,a[f]=I%BigInteger.base)}return new BigInteger(a,this._s*e._s)},BigInteger.prototype.multiplySingleDigit=function(e){if(0===e||0===this._s)return BigInteger.ZERO;if(1===e)return this;var t;if(1===this._d.length)return(t=this._d[0]*e)>=BigInteger.base?new BigInteger([t%BigInteger.base|0,t/BigInteger.base|0],1):new BigInteger([t],1);if(2===e)return this.add(this);if(this.isUnit())return new BigInteger([e],1);for(var r=this._d,n=r.length,i=n+1,g=new Array(i),s=0;s<i;s++)g[s]=0;for(var o=0,a=0;a<n;a++)o=(t=e*r[a]+o)/BigInteger.base|0,g[a]=t%BigInteger.base|0;return o&&(o=(t=o)/BigInteger.base|0,g[a]=t%BigInteger.base),new BigInteger(g,1)},BigInteger.prototype.square=function(){if(0===this._s)return BigInteger.ZERO;if(this.isUnit())return BigInteger.ONE;var e,t,r,n,i=this._d,g=i.length,s=new Array(g+g+1);for(n=0;n<g;n++)r=2*n,t=(e=i[n]*i[n])/BigInteger.base|0,s[r]=e%BigInteger.base,s[r+1]=t;for(n=0;n<g;n++){t=0,r=2*n+1;for(var o=n+1;o<g;o++,r++)t=(e=i[o]*i[n]*2+s[r]+t)/BigInteger.base|0,s[r]=e%BigInteger.base;var a=t+s[r=g+n];t=a/BigInteger.base|0,s[r]=a%BigInteger.base,s[r+1]+=t}return new BigInteger(s,1)},BigInteger.prototype.quotient=function(e){return this.divRem(e)[0]},BigInteger.prototype.divide=BigInteger.prototype.quotient,BigInteger.prototype.remainder=function(e){return this.divRem(e)[1]},BigInteger.prototype.divRem=function(e){if(0===(e=BigInteger(e))._s)throw new Error("Divide by zero");if(0===this._s)return[BigInteger.ZERO,BigInteger.ZERO];if(1===e._d.length)return this.divRemSmall(e._s*e._d[0]);switch(this.compareAbs(e)){case 0:return[this._s===e._s?BigInteger.ONE:BigInteger.M_ONE,BigInteger.ZERO];case-1:return[BigInteger.ZERO,this]}var t,r=this._s*e._s,n=e.abs(),i=this._d.slice(),g=(e._d.length,i.length,[]),s=new BigInteger([],1);for(s._s=1;i.length;)if(s._d.unshift(i.pop()),(s=new BigInteger(s._d,1)).compareAbs(e)<0)g.push(0);else{if(0===s._s)t=0;else{var o=s._d.length,a=n._d.length,I=s._d[o-1]*BigInteger.base+s._d[o-2],B=n._d[a-1]*BigInteger.base+n._d[a-2];s._d.length>n._d.length&&(I=(I+1)*BigInteger.base),t=Math.ceil(I/B)}do{var h=n.multiplySingleDigit(t);if(h.compareAbs(s)<=0)break;t--}while(t);if(g.push(t),t){var u=s.subtract(h);s._d=u._d.slice()}}return[new BigInteger(g.reverse(),r),new BigInteger(s._d,this._s)]},BigInteger.prototype.divRemSmall=function(e){var t;if(0===(e=+e))throw new Error("Divide by zero");var r=e<0?-1:1,n=this._s*r;if((e=Math.abs(e))<1||e>=BigInteger.base)throw new Error("Argument out of range");if(0===this._s)return[BigInteger.ZERO,BigInteger.ZERO];if(1===e||-1===e)return[1===n?this.abs():new BigInteger(this._d,n),BigInteger.ZERO];if(1===this._d.length){var i=new BigInteger([this._d[0]/e|0],1);return t=new BigInteger([this._d[0]%e|0],1),n<0&&(i=i.negate()),this._s<0&&(t=t.negate()),[i,t]}for(var g,s=this._d.slice(),o=new Array(s.length),a=0,I=0,B=0;s.length;){if((a=a*BigInteger.base+s[s.length-1])<e)o[B++]=0,s.pop(),I=BigInteger.base*I+a;else I=a-e*(g=0===a?0:a/e|0),o[B++]=g,g?(s.pop(),a=I):s.pop()}return t=new BigInteger([I],1),this._s<0&&(t=t.negate()),[new BigInteger(o.reverse(),n),t]},BigInteger.prototype.isEven=function(){var e=this._d;return 0===this._s||0===e.length||e[0]%2==0},BigInteger.prototype.isOdd=function(){return!this.isEven()},BigInteger.prototype.sign=function(){return this._s},BigInteger.prototype.isPositive=function(){return this._s>0},BigInteger.prototype.isNegative=function(){return this._s<0},BigInteger.prototype.isZero=function(){return 0===this._s},BigInteger.prototype.exp10=function(e){if(0===(e=+e))return this;if(Math.abs(e)>Number(BigInteger.MAX_EXP))throw new Error("exponent too large in BigInteger.exp10");if(e>0){for(var t=new BigInteger(this._d.slice(),this._s);e>=BigInteger.base_log10;e-=BigInteger.base_log10)t._d.unshift(0);return 0==e?t:(t._s=1,t=t.multiplySingleDigit(Math.pow(10,e)),this._s<0?t.negate():t)}if(-e>=this._d.length*BigInteger.base_log10)return BigInteger.ZERO;t=new BigInteger(this._d.slice(),this._s);for(e=-e;e>=BigInteger.base_log10;e-=BigInteger.base_log10)t._d.shift();return 0==e?t:t.divRemSmall(Math.pow(10,e))[0]},BigInteger.prototype.pow=function(e){if(this.isUnit())return this._s>0||BigInteger(e).isOdd()?this:this.negate();if(0===(e=BigInteger(e))._s)return BigInteger.ONE;if(e._s<0){if(0===this._s)throw new Error("Divide by zero");return BigInteger.ZERO}if(0===this._s)return BigInteger.ZERO;if(e.isUnit())return this;if(e.compareAbs(BigInteger.MAX_EXP)>0)throw new Error("exponent too large in BigInteger.pow");for(var t=this,r=BigInteger.ONE,n=BigInteger.small[2];e.isPositive();){if(e.isOdd()&&(r=r.multiply(t),e.isUnit()))return r;t=t.square(),e=e.quotient(n)}return r},BigInteger.prototype.modPow=function(e,t){for(var r=BigInteger.ONE,n=this;e.isPositive();)e.isOdd()&&(r=r.multiply(n).remainder(t)),(e=e.quotient(BigInteger.small[2])).isPositive()&&(n=n.square().remainder(t));return r},BigInteger.prototype.log=function(){switch(this._s){case 0:return-1/0;case-1:return NaN}var e=this._d.length;if(e*BigInteger.base_log10<30)return Math.log(this.valueOf());var t=Math.ceil(30/BigInteger.base_log10),r=this._d.slice(e-t);return Math.log(new BigInteger(r,1).valueOf())+(e-t)*Math.log(BigInteger.base)},BigInteger.prototype.valueOf=function(){return parseInt(this.toString(),10)},BigInteger.prototype.toJSValue=function(){return parseInt(this.toString(),10)},BigInteger.MAX_EXP=BigInteger(2147483647),function(){function e(e){return function(t){return e.call(BigInteger(t))}}function t(e){return function(t,r){return e.call(BigInteger(t),BigInteger(r))}}function r(e){return function(t,r,n){return e.call(BigInteger(t),BigInteger(r),BigInteger(n))}}!function(){var n,i,g="toJSValue,isEven,isOdd,sign,isZero,isNegative,abs,isUnit,square,negate,isPositive,toString,next,prev,log".split(","),s="compare,remainder,divRem,subtract,add,quotient,divide,multiply,pow,compareAbs".split(","),o=["modPow"];for(n=0;n<g.length;n++)BigInteger[i=g[n]]=e(BigInteger.prototype[i]);for(n=0;n<s.length;n++)BigInteger[i=s[n]]=t(BigInteger.prototype[i]);for(n=0;n<o.length;n++)BigInteger[i=o[n]]=r(BigInteger.prototype[i]);BigInteger.exp10=function(e,t){return BigInteger(e).exp10(t)}}()}(),"undefined"!=typeof exports&&(exports.BigInteger=BigInteger);var VirtualJoystick=function(t){t=t||{},this._container=t.container||document.body,this._stickEl=t.stickElement||this._buildJoystickStick(),this._baseEl=t.baseElement||this._buildJoystickBase(),this._mouseLeft=t.mouseLeft||this._buildJoystickButton(),this._mouseSupport="mouseSupport"in t&&t.mouseSupport,this._range=t.range||60,this._timer=null,this._callback="callback"in t&&t.callback,this._callbackcontext="callbackcontext"in t?t.callbackcontext:this,this._callbackButton="callbackbutton"in t&&t.callbackbutton,this._referenceItem=t.referenceItem,this._container.style.position="relative",this._container.appendChild(this._baseEl),this._container.appendChild(this._mouseLeft),this._baseEl.style.position="absolute",this._baseEl.style.display="block",this._mouseLeft.style.position="absolute",this._mouseLeft.style.display="block";var e=$(this._referenceItem),s=e.height()-e.offset().top-130;this._baseEl.style.top=s+"px",this._baseEl.style.left="20px",this._container.appendChild(this._stickEl),this._stickEl.style.position="absolute",this._stickEl.style.display="none",this._mouseLeft.style.top=s+20+"px",this._mouseLeft.style.right="20px",this._pressed=!1,this._baseX=0,this._baseY=0,this._stickX=0,this._stickY=0,__bind=function(t,e){return function(){return t.apply(e,arguments)}},this._$onTouchStart=__bind(this._onTouchStart,this),this._$onTouchEnd=__bind(this._onTouchEnd,this),this._$onTouchMove=__bind(this._onTouchMove,this),this._$onTouchStartButton=__bind(this._onTouchStartButton,this),this._$onTouchEndButton=__bind(this._onTouchEndButton,this),this._baseEl.addEventListener("touchstart",this._$onTouchStart,!1),this._mouseLeft.addEventListener("touchstart",this._$onTouchStartButton,!1),this._mouseLeft.addEventListener("touchend",this._$onTouchEndButton,!1),this._container.addEventListener("touchend",this._$onTouchEnd,!1),this._container.addEventListener("touchmove",this._$onTouchMove,!1),this._mouseSupport&&(this._$onMouseDown=__bind(this._onMouseDown,this),this._$onMouseUp=__bind(this._onMouseUp,this),this._$onMouseMove=__bind(this._onMouseMove,this),this._$onMouseDownButton=__bind(this._onMouseDownButton,this),this._$onMouseUpButton=__bind(this._onMouseUpButton,this),this._baseEl.addEventListener("mousedown",this._$onMouseDown,!1),this._container.addEventListener("mouseup",this._$onMouseUp,!1),this._mouseLeft.addEventListener("mousedown",this._$onTouchStartButton,!1),this._mouseLeft.addEventListener("mouseup",this._$onTouchEndButton,!1),this._container.addEventListener("mousemove",this._$onMouseMove,!1))};VirtualJoystick.prototype.destroy=function(){this._container.removeChild(this._baseEl),this._container.removeChild(this._stickEl),this._mouseLeft.removeEventListener("touchstart",this._$onTouchStartButton,!1),this._mouseLeft.removeEventListener("touchend",this._$onTouchEndButton,!1),this._container.removeChild(this._mouseLeft),this._container.removeEventListener("touchstart",this._$onTouchStart,!1),this._container.removeEventListener("touchend",this._$onTouchEnd,!1),this._container.removeEventListener("touchmove",this._$onTouchMove,!1),this._mouseSupport&&(this._container.removeEventListener("mouseup",this._$onMouseUp,!1),this._container.removeEventListener("mousedown",this._$onMouseDown,!1),this._container.removeEventListener("mousemove",this._$onMouseMove,!1))},VirtualJoystick.touchScreenAvailable=function(){return"createTouch"in document},VirtualJoystick.prototype.deltaX=function(){return this._stickX-this._baseX},VirtualJoystick.prototype.deltaY=function(){return this._stickY-this._baseY},VirtualJoystick.prototype.up=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(e>=0)&&!(Math.abs(e)<this._range&&Math.abs(e)<Math.abs(t))},VirtualJoystick.prototype.down=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(e<=0)&&!(Math.abs(e)<this._range&&Math.abs(e)<Math.abs(t))},VirtualJoystick.prototype.right=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(t<=0)&&!(Math.abs(t)<this._range&&Math.abs(e)>Math.abs(t))},VirtualJoystick.prototype.left=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(t>=0)&&!(Math.abs(t)<this._range&&Math.abs(e)>Math.abs(t))},VirtualJoystick.prototype._onUp=function(){this._pressed=!1,this._stickEl.style.display="none",this._baseX=this._baseY=0,this._stickX=this._stickY=0,this._eraseInterval()},VirtualJoystick.prototype._onDown=function(t,e){this._pressed=!0,this._stickX=t,this._stickY=e,this._stickEl.style.display="",this._stickEl.style.left=this._stickX-this._stickEl.width/2+"px",this._stickEl.style.top=this._stickY-this._stickEl.height/2+"px",this._startInterval()},VirtualJoystick.prototype._onMove=function(t,e){!0===this._pressed&&(this._stickX=t,this._stickY=e,this._stickEl.style.left=t-this._stickEl.width/2+"px",this._stickEl.style.top=e-this._stickEl.height/2+"px",this._startInterval())},VirtualJoystick.prototype._startInterval=function(t,e){this._eraseInterval();var s=$(this._baseEl).offset().left+$(this._baseEl).width()/2,i=$(this._stickEl).offset().left+$(this._stickEl).width()/2;this.offsetX=parseInt((i-s)/5);var o=$(this._baseEl).offset().top+$(this._baseEl).height()/2,n=$(this._stickEl).offset().top+$(this._stickEl).height()/2;this.offsetY=parseInt((n-o)/5),this.offsetX>15&&(this.offsetX=15),this.offsetY>15&&(this.offsetY=15);var h=this;this._timer=setInterval((function(){h._callback&&h._callback.call(h._callbackcontext,[h.offsetX,h.offsetY])}),10)},VirtualJoystick.prototype._eraseInterval=function(){this._timer&&(clearTimeout(this._timer),this._timer=null)},VirtualJoystick.prototype._onMouseUp=function(t){return this._onUp()},VirtualJoystick.prototype._onMouseDown=function(t){var e=t.pageX,s=t.pageY;return this._onDown(e,s)},VirtualJoystick.prototype._onMouseMove=function(t){var e=t.pageX,s=t.pageY;return this._onMove(e,s)},VirtualJoystick.prototype._onTouchStart=function(t){if(1==t.touches.length){t.preventDefault();var e=t.touches[0].pageX,s=t.touches[0].pageY;return this._onDown(e,s)}},VirtualJoystick.prototype._onTouchEnd=function(t){return t.preventDefault(),this._onUp()},VirtualJoystick.prototype._onTouchMove=function(t){if(!t.touches||1==t.touches.length){t.preventDefault();var e=t.touches[0].pageX,s=t.touches[0].pageY;return this._onMove(e,s)}},VirtualJoystick.prototype._onTouchStartButton=function(t){t.touches&&1!=t.touches.length||(t.preventDefault(),this._callbackButton.call(this._callbackcontext,["down"]))},VirtualJoystick.prototype._onTouchEndButton=function(t){t.preventDefault(),this._callbackButton.call(this._callbackcontext,["up"])},VirtualJoystick.prototype._buildJoystickBase=function(){var t=document.createElement("canvas");t.style.zIndex=2,t.width=126,t.height=126;var e=t.getContext("2d");return e.beginPath(),e.strokeStyle="cyan",e.lineWidth=6,e.arc(t.width/2,t.width/2,40,0,2*Math.PI,!0),e.stroke(),e.beginPath(),e.strokeStyle="cyan",e.lineWidth=2,e.arc(t.width/2,t.width/2,60,0,2*Math.PI,!0),e.stroke(),t},VirtualJoystick.prototype._buildJoystickStick=function(){var t=document.createElement("canvas");t.style.zIndex=2,t.width=86,t.height=86;var e=t.getContext("2d");return e.beginPath(),e.strokeStyle="cyan",e.lineWidth=6,e.arc(t.width/2,t.width/2,40,0,2*Math.PI,!0),e.stroke(),t},VirtualJoystick.prototype._buildJoystickButton=function(){var t=document.createElement("canvas");t.style.zIndex=2,t.width=86,t.height=86;var e=t.getContext("2d");return e.beginPath(),e.strokeStyle="green",e.lineWidth=6,e.arc(t.width/2,t.width/2,40,0,2*Math.PI,!0),e.stroke(),t};var prettyPrint=function(){var e={el:function(t,n){var o,r=document.createElement(t);if((n=e.merge({},n))&&n.style){n.style;e.applyCSS(r,n.style),delete n.style}for(o in n)n.hasOwnProperty(o)&&(r[o]=n[o]);return r},applyCSS:function(e,t){for(var n in t)if(t.hasOwnProperty(n))try{e.style[n]=t[n]}catch(e){}},txt:function(e){return document.createTextNode(e)},row:function(t,n,o){o=o||"td";var r,a=e.count(t,null)+1,d=e.el("tr"),i={style:e.getStyles(o,n),colSpan:a,onmouseover:function(){var t=this.parentNode.childNodes;e.forEach(t,(function(t){"td"===t.nodeName.toLowerCase()&&e.applyCSS(t,e.getStyles("td_hover",n))}))},onmouseout:function(){var t=this.parentNode.childNodes;e.forEach(t,(function(t){"td"===t.nodeName.toLowerCase()&&e.applyCSS(t,e.getStyles("td",n))}))}};return e.forEach(t,(function(t){null!==t&&(r=e.el(o,i),t.nodeType?r.appendChild(t):r.innerHTML=e.shorten(t.toString()),d.appendChild(r))})),d},hRow:function(t,n){return e.row(t,n,"th")},table:function(t,n){t=t||[];var o={thead:{style:e.getStyles("thead",n)},tbody:{style:e.getStyles("tbody",n)},table:{style:e.getStyles("table",n)}},r=e.el("table",o.table),a=e.el("thead",o.thead),d=e.el("tbody",o.tbody);return t.length&&(r.appendChild(a),a.appendChild(e.hRow(t,n))),r.appendChild(d),{node:r,tbody:d,thead:a,appendChild:function(e){this.tbody.appendChild(e)},addRow:function(t,o,r){return this.appendChild(e.row.call(e,t,o||n,r)),this}}},shorten:function(e){return(e=e.replace(/^\s\s*|\s\s*$|\n/g,"")).length>40?e.substring(0,39)+"...":e},htmlentities:function(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},merge:function(t,n){for(var o in"object"!=typeof t&&(t={}),n)if(n.hasOwnProperty(o)){var r=n[o];if("object"==typeof r){t[o]=e.merge(t[o],r);continue}t[o]=r}for(var a=2,d=arguments.length;a<d;a++)e.merge(t,arguments[a]);return t},count:function(e,t){for(var n=0,o=0,r=e.length;o<r;o++)e[o]===t&&n++;return n},thead:function(e){return e.getElementsByTagName("thead")[0]},forEach:function(e,t,n){n||(n=t);for(var o=e.length,r=-1;++r<o&&!1!==n(e[r],r,e););return!0},type:function(e){try{if(null===e)return"null";if(void 0===e)return"undefined";var t=Object.prototype.toString.call(e).match(/\s(.+?)\]/)[1].toLowerCase();return e.nodeType?1===e.nodeType?"domelement":"domnode":/^(string|number|array|regexp|function|date|boolean)$/.test(t)?t:"object"==typeof e?e.jquery&&"string"==typeof e.jquery?"jquery":"object":e===window||e===document?"object":"default"}catch(e){return"default"}},within:function(e){return{is:function(t){for(var n in e)if(e[n]===t)return n;return""}}},common:{circRef:function(n,o,r){return e.expander("[POINTS BACK TO <strong>"+o+"</strong>]","Click to show this item anyway",(function(){this.parentNode.appendChild(t(n,{maxDepth:1}))}))},depthReached:function(n,o){return e.expander("[DEPTH REACHED]","Click to show this item anyway",(function(){try{this.parentNode.appendChild(t(n,{maxDepth:1}))}catch(t){this.parentNode.appendChild(e.table(["ERROR OCCURED DURING OBJECT RETRIEVAL"],"error").addRow([t.message]).node)}}))}},getStyles:function(n,o){return o=t.settings.styles[o]||{},e.merge({},t.settings.styles.default[n],o[n])},expander:function(t,n,o){return e.el("a",{innerHTML:e.shorten(t)+' <b style="visibility:hidden;">[+]</b>',title:n,onmouseover:function(){this.getElementsByTagName("b")[0].style.visibility="visible"},onmouseout:function(){this.getElementsByTagName("b")[0].style.visibility="hidden"},onclick:function(){return this.style.display="none",o.call(this),!1},style:{cursor:"pointer"}})},stringify:function(t){var n,o=e.type(t),r=!0;if("array"===o)return n="[",e.forEach(t,(function(t,o){n+=(0===o?"":", ")+e.stringify(t)})),n+"]";if("object"==typeof t){for(var a in n="{",t)t.hasOwnProperty(a)&&(n+=(r?"":", ")+a+":"+e.stringify(t[a]),r=!1);return n+"}"}return"regexp"===o?"/"+t.source+"/":"string"===o?'"'+t.replace(/"/g,'\\"')+'"':t.toString()},headerGradient:function(){var e=document.createElement("canvas");if(!e.getContext)return"";var t=e.getContext("2d");e.height=30,e.width=1;var n=t.createLinearGradient(0,0,0,30);return n.addColorStop(0,"rgba(0,0,0,0)"),n.addColorStop(1,"rgba(0,0,0,0.25)"),t.fillStyle=n,t.fillRect(0,0,1,30),"url("+(e.toDataURL&&e.toDataURL()||"")+")"}()},t=function(n,o){o=o||{};var r=e.merge({},t.config,o),a=e.el("div"),d=(t.config,{}),i=!1;t.settings=r;var l={string:function(t){return e.txt('"'+e.shorten(t.replace(/"/g,'\\"'))+'"')},number:function(t){return e.txt(t)},regexp:function(t){var n=e.table(["RegExp",null],"regexp"),o=e.table(),a=e.expander("/"+t.source+"/","Click to show more",(function(){this.parentNode.appendChild(n.node)}));return o.addRow(["g",t.global]).addRow(["i",t.ignoreCase]).addRow(["m",t.multiline]),n.addRow(["source","/"+t.source+"/"]).addRow(["flags",o.node]).addRow(["lastIndex",t.lastIndex]),r.expanded?n.node:a},domelement:function(t,n){var o=e.table(["DOMElement",null],"domelement"),a=t.nodeName||"";return o.addRow(["tag","&lt;"+a.toLowerCase()+"&gt;"]),e.forEach(["id","className","innerHTML","src","href"],(function(n){t[n]&&o.addRow([n,e.htmlentities(t[n])])})),r.expanded?o.node:e.expander("DOMElement ("+a.toLowerCase()+")","Click to show more",(function(){this.parentNode.appendChild(o.node)}))},domnode:function(t){var n=e.table(["DOMNode",null],"domelement"),o=e.htmlentities((t.data||"UNDEFINED").replace(/\n/g,"\\n"));return n.addRow(["nodeType",t.nodeType+" ("+t.nodeName+")"]).addRow(["data",o]),r.expanded?n.node:e.expander("DOMNode","Click to show more",(function(){this.parentNode.appendChild(n.node)}))},jquery:function(e,t,n){return l.array(e,t,n,!0)},object:function(t,n,o){var a=e.within(d).is(t);if(a)return e.common.circRef(t,a,r);if(d[o||"TOP"]=t,n===r.maxDepth)return e.common.depthReached(t,r);var c=e.table(["Object",null],"object"),u=!0;for(var s in t)if(!t.hasOwnProperty||t.hasOwnProperty(s)){var p=t[s],h=e.type(p);u=!1;try{c.addRow([s,l[h](p,n+1,s)],h)}catch(e){window.console&&window.console.log&&console.log(e.message)}}u?c.addRow(["<small>[empty]</small>"]):c.thead.appendChild(e.hRow(["key","value"],"colHeader"));var f=r.expanded||i?c.node:e.expander(e.stringify(t),"Click to show more",(function(){this.parentNode.appendChild(c.node)}));return i=!0,f},array:function(t,n,o,a){var i=e.within(d).is(t);if(i)return e.common.circRef(t,i);if(d[o||"TOP"]=t,n===r.maxDepth)return e.common.depthReached(t);var c=a?"jQuery":"Array",u=e.table([c+"("+t.length+")",null],a?"jquery":c.toLowerCase()),s=!0,p=0;return a&&u.addRow(["selector",t.selector]),e.forEach(t,(function(o,a){if(r.maxArray>=0&&++p>r.maxArray)return u.addRow([a+".."+(t.length-1),l[e.type(o)]("...",n+1,a)]),!1;s=!1,u.addRow([a,l[e.type(o)](o,n+1,a)])})),a||(s?u.addRow(["<small>[empty]</small>"]):u.thead.appendChild(e.hRow(["index","value"],"colHeader"))),r.expanded?u.node:e.expander(e.stringify(t),"Click to show more",(function(){this.parentNode.appendChild(u.node)}))},function:function(t,n,o){var a=e.within(d).is(t);if(a)return e.common.circRef(t,a);d[o||"TOP"]=t;var i=e.table(["Function",null],"function"),l=(e.table(["Arguments"]),t.toString().match(/\((.+?)\)/)),c=t.toString().match(/\(.*?\)\s+?\{?([\S\s]+)/)[1].replace(/\}?$/,"");return i.addRow(["arguments",l?l[1].replace(/[^\w_,\s]/g,""):"<small>[none/native]</small>"]).addRow(["body",c]),r.expanded?i.node:e.expander("function(){...}","Click to see more about this function.",(function(){this.parentNode.appendChild(i.node)}))},date:function(t){var n=e.table(["Date",null],"date"),o=t.toString().split(/\s/);return n.addRow(["Time",o[4]]).addRow(["Date",o.slice(0,4).join("-")]),r.expanded?n.node:e.expander("Date (timestamp): "+ +t,"Click to see a little more info about this date",(function(){this.parentNode.appendChild(n.node)}))},boolean:function(t){return e.txt(t.toString().toUpperCase())},undefined:function(){return e.txt("UNDEFINED")},null:function(){return e.txt("NULL")},default:function(){return e.txt("prettyPrint: TypeNotFound Error")}};return a.appendChild(l[r.forceObject?"object":e.type(n)](n,0)),a};return t.config={expanded:!0,forceObject:!1,maxDepth:3,maxArray:-1,styles:{array:{th:{backgroundColor:"#6DBD2A",color:"white"}},function:{th:{backgroundColor:"#D82525"}},regexp:{th:{backgroundColor:"#E2F3FB",color:"#000"}},object:{th:{backgroundColor:"#1F96CF"}},jquery:{th:{backgroundColor:"#FBF315"}},error:{th:{backgroundColor:"red",color:"yellow"}},domelement:{th:{backgroundColor:"#F3801E"}},date:{th:{backgroundColor:"#A725D8"}},colHeader:{th:{backgroundColor:"#EEE",color:"#000",textTransform:"uppercase"}},default:{table:{borderCollapse:"collapse",width:"100%"},td:{padding:"5px",fontSize:"12px",backgroundColor:"#FFF",color:"#222",border:"1px solid #000",verticalAlign:"top",fontFamily:'"Consolas","Lucida Console",Courier,mono',whiteSpace:"nowrap"},td_hover:{},th:{padding:"5px",fontSize:"12px",backgroundColor:"#222",color:"#EEE",textAlign:"left",border:"1px solid #000",verticalAlign:"top",fontFamily:'"Consolas","Lucida Console",Courier,mono',backgroundImage:e.headerGradient,backgroundRepeat:"repeat-x"}}}},t}();var dbits,canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);function encryptionBigInteger(t,i,n){null!=t&&("number"==typeof t?this.fromNumber(t,i,n):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function nbi(){return new encryptionBigInteger(null)}function am1(t,i,n,r,o,e){for(;--e>=0;){var s=i*this[t++]+n[r]+o;o=Math.floor(s/67108864),n[r++]=67108863&s}return o}function am2(t,i,n,r,o,e){for(var s=32767&i,h=i>>15;--e>=0;){var p=32767&this[t],c=this[t++]>>15,a=h*p+c*s;o=((p=s*p+((32767&a)<<15)+n[r]+(1073741823&o))>>>30)+(a>>>15)+h*c+(o>>>30),n[r++]=1073741823&p}return o}function am3(t,i,n,r,o,e){for(var s=16383&i,h=i>>14;--e>=0;){var p=16383&this[t],c=this[t++]>>14,a=h*p+c*s;o=((p=s*p+((16383&a)<<14)+n[r]+o)>>28)+(a>>14)+h*c,n[r++]=268435455&p}return o}j_lm&&"Microsoft Internet Explorer"==navigator.appName?(encryptionBigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(encryptionBigInteger.prototype.am=am1,dbits=26):(encryptionBigInteger.prototype.am=am3,dbits=28),encryptionBigInteger.prototype.DB=dbits,encryptionBigInteger.prototype.DM=(1<<dbits)-1,encryptionBigInteger.prototype.DV=1<<dbits;var BI_FP=52;encryptionBigInteger.prototype.FV=Math.pow(2,BI_FP),encryptionBigInteger.prototype.F1=BI_FP-dbits,encryptionBigInteger.prototype.F2=2*dbits-BI_FP;var rr,vv,BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(t){return BI_RM.charAt(t)}function intAt(t,i){var n=BI_RC[t.charCodeAt(i)];return null==n?-1:n}function bnpCopyTo(t){for(var i=this.t-1;i>=0;--i)t[i]=this[i];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+DV:this.t=0}function nbv(t){var i=nbi();return i.fromInt(t),i}function bnpFromString(t,i){var n;if(16==i)n=4;else if(8==i)n=3;else if(256==i)n=8;else if(2==i)n=1;else if(32==i)n=5;else{if(4!=i)return void this.fromRadix(t,i);n=2}this.t=0,this.s=0;for(var r=t.length,o=!1,e=0;--r>=0;){var s=8==n?255&t[r]:intAt(t,r);s<0?"-"==t.charAt(r)&&(o=!0):(o=!1,0==e?this[this.t++]=s:e+n>this.DB?(this[this.t-1]|=(s&(1<<this.DB-e)-1)<<e,this[this.t++]=s>>this.DB-e):this[this.t-1]|=s<<e,(e+=n)>=this.DB&&(e-=this.DB))}8==n&&128&t[0]&&(this.s=-1,e>0&&(this[this.t-1]|=(1<<this.DB-e)-1<<e)),this.clamp(),o&&encryptionBigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function bnToString(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var n,r=(1<<i)-1,o=!1,e="",s=this.t,h=this.DB-s*this.DB%i;if(s-- >0)for(h<this.DB&&(n=this[s]>>h)>0&&(o=!0,e=int2char(n));s>=0;)h<i?(n=(this[s]&(1<<h)-1)<<i-h,n|=this[--s]>>(h+=this.DB-i)):(n=this[s]>>(h-=i)&r,h<=0&&(h+=this.DB,--s)),n>0&&(o=!0),o&&(e+=int2char(n));return o?e:"0"}function bnNegate(){var t=nbi();return encryptionBigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var i=this.s-t.s;if(0!=i)return i;var n=this.t;if(0!=(i=n-t.t))return this.s<0?-i:i;for(;--n>=0;)if(0!=(i=this[n]-t[n]))return i;return 0}function nbits(t){var i,n=1;return 0!=(i=t>>>16)&&(t=i,n+=16),0!=(i=t>>8)&&(t=i,n+=8),0!=(i=t>>4)&&(t=i,n+=4),0!=(i=t>>2)&&(t=i,n+=2),0!=(i=t>>1)&&(t=i,n+=1),n}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,i){var n;for(n=this.t-1;n>=0;--n)i[n+t]=this[n];for(n=t-1;n>=0;--n)i[n]=0;i.t=this.t+t,i.s=this.s}function bnpDRShiftTo(t,i){for(var n=t;n<this.t;++n)i[n-t]=this[n];i.t=Math.max(this.t-t,0),i.s=this.s}function bnpLShiftTo(t,i){var n,r=t%this.DB,o=this.DB-r,e=(1<<o)-1,s=Math.floor(t/this.DB),h=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)i[n+s+1]=this[n]>>o|h,h=(this[n]&e)<<r;for(n=s-1;n>=0;--n)i[n]=0;i[s]=h,i.t=this.t+s+1,i.s=this.s,i.clamp()}function bnpRShiftTo(t,i){i.s=this.s;var n=Math.floor(t/this.DB);if(n>=this.t)i.t=0;else{var r=t%this.DB,o=this.DB-r,e=(1<<r)-1;i[0]=this[n]>>r;for(var s=n+1;s<this.t;++s)i[s-n-1]|=(this[s]&e)<<o,i[s-n]=this[s]>>r;r>0&&(i[this.t-n-1]|=(this.s&e)<<o),i.t=this.t-n,i.clamp()}}function bnpSubTo(t,i){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]-t[n],i[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;n<this.t;)r+=this[n],i[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r-=t[n],i[n++]=r&this.DM,r>>=this.DB;r-=t.s}i.s=r<0?-1:0,r<-1?i[n++]=this.DV+r:r>0&&(i[n++]=r),i.t=n,i.clamp()}function bnpMultiplyTo(t,i){var n=this.abs(),r=t.abs(),o=n.t;for(i.t=o+r.t;--o>=0;)i[o]=0;for(o=0;o<r.t;++o)i[o+n.t]=n.am(0,r[o],i,o,0,n.t);i.s=0,i.clamp(),this.s!=t.s&&encryptionBigInteger.ZERO.subTo(i,i)}function bnpSquareTo(t){for(var i=this.abs(),n=t.t=2*i.t;--n>=0;)t[n]=0;for(n=0;n<i.t-1;++n){var r=i.am(n,i[n],t,2*n,0,1);(t[n+i.t]+=i.am(n+1,2*i[n],t,2*n+1,r,i.t-n-1))>=i.DV&&(t[n+i.t]-=i.DV,t[n+i.t+1]=1)}t.t>0&&(t[t.t-1]+=i.am(n,i[n],t,2*n,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,i,n){var r=t.abs();if(!(r.t<=0)){var o=this.abs();if(o.t<r.t)return null!=i&&i.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=nbi());var e=nbi(),s=this.s,h=t.s,p=this.DB-nbits(r[r.t-1]);p>0?(r.lShiftTo(p,e),o.lShiftTo(p,n)):(r.copyTo(e),o.copyTo(n));var c=e.t,a=e[c-1];if(0!=a){var f=a*(1<<this.F1)+(c>1?e[c-2]>>this.F2:0),u=this.FV/f,g=(1<<this.F1)/f,m=1<<this.F2,y=n.t,v=y-c,b=null==i?nbi():i;for(e.dlShiftTo(v,b),n.compareTo(b)>=0&&(n[n.t++]=1,n.subTo(b,n)),encryptionBigInteger.ONE.dlShiftTo(c,b),b.subTo(e,e);e.t<c;)e[e.t++]=0;for(;--v>=0;){var l=n[--y]==a?this.DM:Math.floor(n[y]*u+(n[y-1]+m)*g);if((n[y]+=e.am(0,l,n,v,0,c))<l)for(e.dlShiftTo(v,b),n.subTo(b,n);n[y]<--l;)n.subTo(b,n)}null!=i&&(n.drShiftTo(c,i),s!=h&&encryptionBigInteger.ZERO.subTo(i,i)),n.t=c,n.clamp(),p>0&&n.rShiftTo(p,n),s<0&&encryptionBigInteger.ZERO.subTo(n,n)}}}function bnMod(t){var i=nbi();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(encryptionBigInteger.ZERO)>0&&t.subTo(i,i),i}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function cSqrTo(t,i){t.squareTo(i),this.reduce(i)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function montConvert(t){var i=nbi();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(encryptionBigInteger.ZERO)>0&&this.m.subTo(i,i),i}function montRevert(t){var i=nbi();return t.copyTo(i),this.reduce(i),i}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var i=0;i<this.m.t;++i){var n=32767&t[i],r=n*this.mpl+((n*this.mph+(t[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=i+this.m.t]+=this.m.am(0,r,t,i,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,i){t.squareTo(i),this.reduce(i)}function montMulTo(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,i){if(t>4294967295||t<1)return encryptionBigInteger.ONE;var n=nbi(),r=nbi(),o=i.convert(this),e=nbits(t)-1;for(o.copyTo(n);--e>=0;)if(i.sqrTo(n,r),(t&1<<e)>0)i.mulTo(r,o,n);else{var s=n;n=r,r=s}return i.revert(n)}function bnModPowInt(t,i){var n;return n=t<256||i.isEven()?new Classic(i):new Montgomery(i),this.exp(t,n)}Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,encryptionBigInteger.prototype.copyTo=bnpCopyTo,encryptionBigInteger.prototype.fromInt=bnpFromInt,encryptionBigInteger.prototype.fromString=bnpFromString,encryptionBigInteger.prototype.clamp=bnpClamp,encryptionBigInteger.prototype.dlShiftTo=bnpDLShiftTo,encryptionBigInteger.prototype.drShiftTo=bnpDRShiftTo,encryptionBigInteger.prototype.lShiftTo=bnpLShiftTo,encryptionBigInteger.prototype.rShiftTo=bnpRShiftTo,encryptionBigInteger.prototype.subTo=bnpSubTo,encryptionBigInteger.prototype.multiplyTo=bnpMultiplyTo,encryptionBigInteger.prototype.squareTo=bnpSquareTo,encryptionBigInteger.prototype.divRemTo=bnpDivRemTo,encryptionBigInteger.prototype.invDigit=bnpInvDigit,encryptionBigInteger.prototype.isEven=bnpIsEven,encryptionBigInteger.prototype.exp=bnpExp,encryptionBigInteger.prototype.toString=bnToString,encryptionBigInteger.prototype.negate=bnNegate,encryptionBigInteger.prototype.abs=bnAbs,encryptionBigInteger.prototype.compareTo=bnCompareTo,encryptionBigInteger.prototype.bitLength=bnBitLength,encryptionBigInteger.prototype.mod=bnMod,encryptionBigInteger.prototype.modPowInt=bnModPowInt,encryptionBigInteger.ZERO=nbv(0),encryptionBigInteger.ONE=nbv(1);function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var i=this.chunkSize(t),n=Math.pow(t,i),r=nbv(n),e=nbi(),o=nbi(),s="";for(this.divRemTo(r,e,o);e.signum()>0;)s=(n+o.intValue()).toString(t).substr(1)+s,e.divRemTo(r,e,o);return o.intValue().toString(t)+s}function bnpFromRadix(t,i){this.fromInt(0),null==i&&(i=10);for(var n=this.chunkSize(i),r=Math.pow(i,n),e=!1,o=0,s=0,p=0;p<t.length;++p){var h=intAt(t,p);h<0?"-"==t.charAt(p)&&0==this.signum()&&(e=!0):(s=i*s+h,++o>=n&&(this.dMultiply(r),this.dAddOffset(s,0),o=0,s=0))}o>0&&(this.dMultiply(Math.pow(i,o)),this.dAddOffset(s,0)),e&&encryptionBigInteger.ZERO.subTo(this,this)}function bnpFromNumber(t,i,n){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(encryptionBigInteger.ONE.shiftLeft(t-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(encryptionBigInteger.ONE.shiftLeft(t-1),this);else{var r=new Array,e=7&t;r.length=1+(t>>3),i.nextBytes(r),e>0?r[0]&=(1<<e)-1:r[0]=0,this.fromString(r,256)}}function bnToByteArray(){var t=this.t,i=new Array;i[0]=this.s;var n,r=this.DB-t*this.DB%8,e=0;if(t-- >0)for(r<this.DB&&(n=this[t]>>r)!=(this.s&this.DM)>>r&&(i[e++]=n|this.s<<this.DB-r);t>=0;)r<8?(n=(this[t]&(1<<r)-1)<<8-r,n|=this[--t]>>(r+=this.DB-8)):(n=this[t]>>(r-=8)&255,r<=0&&(r+=this.DB,--t)),128&n&&(n|=-256),0==e&&(128&this.s)!=(128&n)&&++e,(e>0||n!=this.s)&&(i[e++]=n);return i}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,i,n){var r,e,o=Math.min(t.t,this.t);for(r=0;r<o;++r)n[r]=i(this[r],t[r]);if(t.t<this.t){for(e=t.s&this.DM,r=o;r<this.t;++r)n[r]=i(this[r],e);n.t=this.t}else{for(e=this.s&this.DM,r=o;r<t.t;++r)n[r]=i(e,t[r]);n.t=t.t}n.s=i(this.s,t.s),n.clamp()}function op_and(t,i){return t&i}function bnAnd(t){var i=nbi();return this.bitwiseTo(t,op_and,i),i}function op_or(t,i){return t|i}function bnOr(t){var i=nbi();return this.bitwiseTo(t,op_or,i),i}function op_xor(t,i){return t^i}function bnXor(t){var i=nbi();return this.bitwiseTo(t,op_xor,i),i}function op_andnot(t,i){return t&~i}function bnAndNot(t){var i=nbi();return this.bitwiseTo(t,op_andnot,i),i}function bnNot(){for(var t=nbi(),i=0;i<this.t;++i)t[i]=this.DM&~this[i];return t.t=this.t,t.s=~this.s,t}function bnShiftLeft(t){var i=nbi();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i}function bnShiftRight(t){var i=nbi();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i}function lbit(t){if(0==t)return-1;var i=0;return 65535&t||(t>>=16,i+=16),255&t||(t>>=8,i+=8),15&t||(t>>=4,i+=4),3&t||(t>>=2,i+=2),1&t||++i,i}function bnGetLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+lbit(this[t]);return this.s<0?this.t*this.DB:-1}function cbit(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function bnBitCount(){for(var t=0,i=this.s&this.DM,n=0;n<this.t;++n)t+=cbit(this[n]^i);return t}function bnTestBit(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:!!(this[i]&1<<t%this.DB)}function bnpChangeBit(t,i){var n=encryptionBigInteger.ONE.shiftLeft(t);return this.bitwiseTo(n,i,n),n}function bnSetBit(t){return this.changeBit(t,op_or)}function bnClearBit(t){return this.changeBit(t,op_andnot)}function bnFlipBit(t){return this.changeBit(t,op_xor)}function bnpAddTo(t,i){for(var n=0,r=0,e=Math.min(t.t,this.t);n<e;)r+=this[n]+t[n],i[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;n<this.t;)r+=this[n],i[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r+=t[n],i[n++]=r&this.DM,r>>=this.DB;r+=t.s}i.s=r<0?-1:0,r>0?i[n++]=r:r<-1&&(i[n++]=this.DV+r),i.t=n,i.clamp()}function bnAdd(t){var i=nbi();return this.addTo(t,i),i}function bnSubtract(t){var i=nbi();return this.subTo(t,i),i}function bnMultiply(t){var i=nbi();return this.multiplyTo(t,i),i}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var i=nbi();return this.divRemTo(t,i,null),i}function bnRemainder(t){var i=nbi();return this.divRemTo(t,null,i),i}function bnDivideAndRemainder(t){var i=nbi(),n=nbi();return this.divRemTo(t,i,n),new Array(i,n)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,i){if(0!=t){for(;this.t<=i;)this[this.t++]=0;for(this[i]+=t;this[i]>=this.DV;)this[i]-=this.DV,++i>=this.t&&(this[this.t++]=0),++this[i]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,i,n){t.multiplyTo(i,n)}function nSqrTo(t,i){t.squareTo(i)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,i,n){var r,e=Math.min(this.t+t.t,i);for(n.s=0,n.t=e;e>0;)n[--e]=0;for(r=n.t-this.t;e<r;++e)n[e+this.t]=this.am(0,t[e],n,e,0,this.t);for(r=Math.min(t.t,i);e<r;++e)this.am(0,t[e],n,e,0,i-e);n.clamp()}function bnpMultiplyUpperTo(t,i,n){--i;var r=n.t=this.t+t.t-i;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(i-this.t,0);r<t.t;++r)n[this.t+r-i]=this.am(i-r,t[r],n,0,0,this.t+r-i);n.clamp(),n.drShiftTo(1,n)}function Barrett(t){this.r2=nbi(),this.q3=nbi(),encryptionBigInteger.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function barrettConvert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=nbi();return t.copyTo(i),this.reduce(i),i}function barrettRevert(t){return t}function barrettReduce(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}function barrettSqrTo(t,i){t.squareTo(i),this.reduce(i)}function barrettMulTo(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function bnModPow(t,i){var n,r,e=t.bitLength(),o=nbv(1);if(e<=0)return o;n=e<18?1:e<48?3:e<144?4:e<768?5:6,r=e<8?new Classic(i):i.isEven()?new Barrett(i):new Montgomery(i);var s=new Array,p=3,h=n-1,u=(1<<n)-1;if(s[1]=r.convert(this),n>1){var f=nbi();for(r.sqrTo(s[1],f);p<=u;)s[p]=nbi(),r.mulTo(f,s[p-2],s[p]),p+=2}var a,b,c=t.t-1,g=!0,l=nbi();for(e=nbits(t[c])-1;c>=0;){for(e>=h?a=t[c]>>e-h&u:(a=(t[c]&(1<<e+1)-1)<<h-e,c>0&&(a|=t[c-1]>>this.DB+e-h)),p=n;!(1&a);)a>>=1,--p;if((e-=p)<0&&(e+=this.DB,--c),g)s[a].copyTo(o),g=!1;else{for(;p>1;)r.sqrTo(o,l),r.sqrTo(l,o),p-=2;p>0?r.sqrTo(o,l):(b=o,o=l,l=b),r.mulTo(l,s[a],o)}for(;c>=0&&!(t[c]&1<<e);)r.sqrTo(o,l),b=o,o=l,l=b,--e<0&&(e=this.DB-1,--c)}return r.revert(o)}function bnGCD(t){var i=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(i.compareTo(n)<0){var r=i;i=n,n=r}var e=i.getLowestSetBit(),o=n.getLowestSetBit();if(o<0)return i;for(e<o&&(o=e),o>0&&(i.rShiftTo(o,i),n.rShiftTo(o,n));i.signum()>0;)(e=i.getLowestSetBit())>0&&i.rShiftTo(e,i),(e=n.getLowestSetBit())>0&&n.rShiftTo(e,n),i.compareTo(n)>=0?(i.subTo(n,i),i.rShiftTo(1,i)):(n.subTo(i,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n}function bnpModInt(t){if(t<=0)return 0;var i=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(0==i)n=this[0]%t;else for(var r=this.t-1;r>=0;--r)n=(i*n+this[r])%t;return n}function bnModInverse(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return encryptionBigInteger.ZERO;for(var n=t.clone(),r=this.clone(),e=nbv(1),o=nbv(0),s=nbv(0),p=nbv(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),i?(e.isEven()&&o.isEven()||(e.addTo(this,e),o.subTo(t,o)),e.rShiftTo(1,e)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;r.isEven();)r.rShiftTo(1,r),i?(s.isEven()&&p.isEven()||(s.addTo(this,s),p.subTo(t,p)),s.rShiftTo(1,s)):p.isEven()||p.subTo(t,p),p.rShiftTo(1,p);n.compareTo(r)>=0?(n.subTo(r,n),i&&e.subTo(s,e),o.subTo(p,o)):(r.subTo(n,r),i&&s.subTo(e,s),p.subTo(o,p))}return 0!=r.compareTo(encryptionBigInteger.ONE)?encryptionBigInteger.ZERO:p.compareTo(t)>=0?p.subtract(t):p.signum()<0?(p.addTo(t,p),p.signum()<0?p.add(t):p):p}NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=(1<<26)/lowprimes[lowprimes.length-1];function bnIsProbablePrime(t){var i,n=this.abs();if(1==n.t&&n[0]<=lowprimes[lowprimes.length-1]){for(i=0;i<lowprimes.length;++i)if(n[0]==lowprimes[i])return!0;return!1}if(n.isEven())return!1;for(i=1;i<lowprimes.length;){for(var r=lowprimes[i],e=i+1;e<lowprimes.length&&r<lplim;)r*=lowprimes[e++];for(r=n.modInt(r);i<e;)if(r%lowprimes[i++]==0)return!1}return n.millerRabin(t)}function bnpMillerRabin(t){var i=this.subtract(encryptionBigInteger.ONE),n=i.getLowestSetBit();if(n<=0)return!1;var r=i.shiftRight(n);(t=t+1>>1)>lowprimes.length&&(t=lowprimes.length);for(var e=nbi(),o=0;o<t;++o){e.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var s=e.modPow(r,this);if(0!=s.compareTo(encryptionBigInteger.ONE)&&0!=s.compareTo(i)){for(var p=1;p++<n&&0!=s.compareTo(i);)if(0==(s=s.modPowInt(2,this)).compareTo(encryptionBigInteger.ONE))return!1;if(0!=s.compareTo(i))return!1}}return!0}encryptionBigInteger.prototype.chunkSize=bnpChunkSize,encryptionBigInteger.prototype.toRadix=bnpToRadix,encryptionBigInteger.prototype.fromRadix=bnpFromRadix,encryptionBigInteger.prototype.fromNumber=bnpFromNumber,encryptionBigInteger.prototype.bitwiseTo=bnpBitwiseTo,encryptionBigInteger.prototype.changeBit=bnpChangeBit,encryptionBigInteger.prototype.addTo=bnpAddTo,encryptionBigInteger.prototype.dMultiply=bnpDMultiply,encryptionBigInteger.prototype.dAddOffset=bnpDAddOffset,encryptionBigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,encryptionBigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,encryptionBigInteger.prototype.modInt=bnpModInt,encryptionBigInteger.prototype.millerRabin=bnpMillerRabin,encryptionBigInteger.prototype.clone=bnClone,encryptionBigInteger.prototype.intValue=bnIntValue,encryptionBigInteger.prototype.byteValue=bnByteValue,encryptionBigInteger.prototype.shortValue=bnShortValue,encryptionBigInteger.prototype.signum=bnSigNum,encryptionBigInteger.prototype.toByteArray=bnToByteArray,encryptionBigInteger.prototype.equals=bnEquals,encryptionBigInteger.prototype.min=bnMin,encryptionBigInteger.prototype.max=bnMax,encryptionBigInteger.prototype.and=bnAnd,encryptionBigInteger.prototype.or=bnOr,encryptionBigInteger.prototype.xor=bnXor,encryptionBigInteger.prototype.andNot=bnAndNot,encryptionBigInteger.prototype.not=bnNot,encryptionBigInteger.prototype.shiftLeft=bnShiftLeft,encryptionBigInteger.prototype.shiftRight=bnShiftRight,encryptionBigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,encryptionBigInteger.prototype.bitCount=bnBitCount,encryptionBigInteger.prototype.testBit=bnTestBit,encryptionBigInteger.prototype.setBit=bnSetBit,encryptionBigInteger.prototype.clearBit=bnClearBit,encryptionBigInteger.prototype.flipBit=bnFlipBit,encryptionBigInteger.prototype.add=bnAdd,encryptionBigInteger.prototype.subtract=bnSubtract,encryptionBigInteger.prototype.multiply=bnMultiply,encryptionBigInteger.prototype.divide=bnDivide,encryptionBigInteger.prototype.remainder=bnRemainder,encryptionBigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,encryptionBigInteger.prototype.modPow=bnModPow,encryptionBigInteger.prototype.modInverse=bnModInverse,encryptionBigInteger.prototype.pow=bnPow,encryptionBigInteger.prototype.gcd=bnGCD,encryptionBigInteger.prototype.isProbablePrime=bnIsProbablePrime,encryptionBigInteger.prototype.square=bnSquare;function Arcfour(){this.i=0,this.j=0,this.S=new Array}function ARC4init(i){var t,s,h;for(t=0;t<256;++t)this.S[t]=t;for(s=0,t=0;t<256;++t)s=s+this.S[t]+i[t%i.length]&255,h=this.S[t],this.S[t]=this.S[s],this.S[s]=h;this.i=0,this.j=0}function ARC4next(){var i;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,i=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=i,this.S[i+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256;var rng_state,rng_pool,rng_pptr;function rng_seed_int(r){rng_pool[rng_pptr++]^=255&r,rng_pool[rng_pptr++]^=r>>8&255,rng_pool[rng_pptr++]^=r>>16&255,rng_pool[rng_pptr++]^=r>>24&255,rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}if(null==rng_pool){var t;if(rng_pool=new Array,rng_pptr=0,"Netscape"==navigator.appName&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t<z.length;++t)rng_pool[rng_pptr++]=255&z.charCodeAt(t)}for(;rng_pptr<rng_psize;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=255&t;rng_pptr=0,rng_seed_time()}function rng_get_byte(){if(null==rng_state){for(rng_seed_time(),(rng_state=prng_newstate()).init(rng_pool),rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr)rng_pool[rng_pptr]=0;rng_pptr=0}return rng_state.next()}function rng_get_bytes(r){var n;for(n=0;n<r.length;++n)r[n]=rng_get_byte()}function SecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;function sha1Hash(r){for(var t=[1518500249,1859775393,2400959708,3395469782],o=(r+=String.fromCharCode(128)).length/4+2,e=Math.ceil(o/16),a=new Array(e),n=0;n<e;n++){a[n]=new Array(16);for(var h=0;h<16;h++)a[n][h]=r.charCodeAt(64*n+4*h)<<24|r.charCodeAt(64*n+4*h+1)<<16|r.charCodeAt(64*n+4*h+2)<<8|r.charCodeAt(64*n+4*h+3)}a[e-1][14]=8*(r.length-1)/Math.pow(2,32),a[e-1][14]=Math.floor(a[e-1][14]),a[e-1][15]=8*(r.length-1)&4294967295;var c,u,i,s,S,A=1732584193,H=4023233417,l=2562383102,v=271733878,x=3285377520,C=new Array(80);for(n=0;n<e;n++){for(var d=0;d<16;d++)C[d]=a[n][d];for(d=16;d<80;d++)C[d]=ROTL(C[d-3]^C[d-8]^C[d-14]^C[d-16],1);c=A,u=H,i=l,s=v,S=x;for(d=0;d<80;d++){var g=Math.floor(d/20),w=ROTL(c,5)+f(g,u,i,s)+S+t[g]+C[d]&4294967295;S=s,s=i,i=ROTL(u,30),u=c,c=w}A=A+c&4294967295,H=H+u&4294967295,l=l+i&4294967295,v=v+s&4294967295,x=x+S&4294967295}return A.toHexStr()+H.toHexStr()+l.toHexStr()+v.toHexStr()+x.toHexStr()}function f(r,t,o,e){switch(r){case 0:return t&o^~t&e;case 1:case 3:return t^o^e;case 2:return t&o^t&e^o&e}}function ROTL(r,t){return r<<t|r>>>32-t}Number.prototype.toHexStr=function(){for(var r="",t=7;t>=0;t--)r+=(this>>>4*t&15).toString(16);return r};function pack(r){for(var t="",n=0;n<r.length;n+=2)t+=String.fromCharCode(parseInt(r.substring(n,n+2),16));return t}function char2hex(r){for(var t="",n=0;n<r.length;n+=1){switch(temp=r[n].toString(16),temp.length){case 1:temp="0"+temp;break;case 0:temp="00"}t+=temp}return t}function xor(r,t){length=Math.min(r.length,t.length),temp="";for(var n=0;n<length;n++)temp+=String.fromCharCode(r.charCodeAt(n)^t.charCodeAt(n));length=Math.max(r.length,t.length)-length;for(n=0;n<length;n++)temp+="\0";return temp}function mgf1(r,n){t="",hLen=20,count=Math.ceil(n/hLen);for(var e=0;e<count;e++)c=String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e),t+=pack(sha1Hash(r+c));return t.substring(0,n)}function rsa_oaep_encrypt(r,t,n){for(var e="Ú9£î^kK\r2U¿ï•`¯Ø\t",o=128-r.length-40-2,a=0;a<o;a++)e+="\0";var g=e+""+r,h="";for(a=0;a<24;a+=4)o=new Array(4),rng.nextBytes(o),h+=String.fromCharCode(o[0],o[1],o[2],o[3]);var i=xor(g,mgf1(h=h.substring(4-h.length%4),107)),f="\0"+xor(h,mgf1(i,20))+i;for(m=new Array,a=0;a<f.length;a++)m[a]=f.charCodeAt(a);return m=new encryptionBigInteger(m,256),c=m.modPowInt(n,t),c=c.toString(16),1&c.length&&(c="0"+c),c}function RSA_public_encrypt(r,t){for(var n=new Uint8Array(t),e=new Array(129),o=0;o<129;o++)e[o]=n[28+o];var a=new encryptionBigInteger(e),g=new encryptionBigInteger("010001",16);return rsa_oaep_encrypt(r+String.fromCharCode(0),a,g)}rng=new SecureRandom;var SWCanvas=function(t){this.arr=new ArrayBuffer(t.width*t.height*4),this.arr32=new Uint32Array(this.arr),this.arr8=new Uint8ClampedArray(this.arr),this.canvas=t,this.width=this.canvas.width,this.height=this.canvas.height};SWCanvas.prototype.putImageData=function(t,a,r){for(var i,h,e=t.data.buffer,s=t.width,n=t.height,o=this.width;n--;)i=(r+n)*o+a,h=new Uint32Array(e,s*n*4,s),this.arr32.set(h,i)},SWCanvas.prototype.getImageData=function(t,a,r,i){for(var h,e=new Uint32Array(r*i),s=this.arr32,n=i,o=this.width;n--;){h=(a+n)*o+t;var f=s.subarray(h,h+r);e.set(f,r*n)}return new ImageData(new Uint8ClampedArray(e.buffer),r,i)},SWCanvas.prototype.fillRect=function(t,a,r,i,h,e,s){for(var n,o=new Uint32Array(e),f=4278190080|t|a<<8|r<<16,v=this.width,w=e;w--;)o[w]=f;for(;s--;)n=(h+s)*v+i,this.arr32.set(o,n)},SWCanvas.prototype.flushBack=function(){var t=this.canvas.getContext("2d").getImageData(0,0,this.width,this.height).data;this.arr8.set(t)},SWCanvas.prototype.flush=function(){var t=new ImageData(this.arr8,this.width,this.height);this.canvas.getContext("2d").putImageData(t,0,0)};!function(e,i){"undefined"!=typeof module&&module.exports?module.exports.browser=i():this.bowser=i()}(0,(function(){var e=!0;function i(i){function o(e){var o=i.match(e);return o&&o.length>1&&o[1]||""}var s,r=o(/(ipod|iphone|ipad)/i).toLowerCase(),n=!/like android/i.test(i)&&/android/i.test(i),a=o(/version\/(\d+(\.\d+)?)/i),t=/tablet/i.test(i),d=!t&&/[^-]mobi/i.test(i);/opera|opr/i.test(i)?s={name:"Opera",opera:e,version:a||o(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(i)?s={name:"Windows Phone",windowsphone:e,msie:e,version:o(/iemobile\/(\d+(\.\d+)?)/i)}:/msie|trident/i.test(i)?s={name:"Internet Explorer",msie:e,version:o(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome|crios|crmo/i.test(i)?s={name:"Chrome",chrome:e,version:o(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:r?(s={name:"iphone"==r?"iPhone":"ipad"==r?"iPad":"iPod"},a&&(s.version=a)):/sailfish/i.test(i)?s={name:"Sailfish",sailfish:e,version:o(/sailfish\s?browser\/(\d+(\.\d+)?)/i)}:/seamonkey\//i.test(i)?s={name:"SeaMonkey",seamonkey:e,version:o(/seamonkey\/(\d+(\.\d+)?)/i)}:/firefox|iceweasel/i.test(i)?(s={name:"Firefox",firefox:e,version:o(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(i)&&(s.firefoxos=e)):/silk/i.test(i)?s={name:"Amazon Silk",silk:e,version:o(/silk\/(\d+(\.\d+)?)/i)}:n?s={name:"Android",version:a}:/phantom/i.test(i)?s={name:"PhantomJS",phantom:e,version:o(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(i)||/rim\stablet/i.test(i)?s={name:"BlackBerry",blackberry:e,version:a||o(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(i)?(s={name:"WebOS",webos:e,version:a||o(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(i)&&(s.touchpad=e)):s=/bada/i.test(i)?{name:"Bada",bada:e,version:o(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(i)?{name:"Tizen",tizen:e,version:o(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||a}:/safari/i.test(i)?{name:"Safari",safari:e,version:a}:{},/(apple)?webkit/i.test(i)?(s.name=s.name||"Webkit",s.webkit=e,!s.version&&a&&(s.version=a)):!s.opera&&/gecko\//i.test(i)&&(s.name=s.name||"Gecko",s.gecko=e,s.version=s.version||o(/gecko\/(\d+(\.\d+)?)/i)),n||s.silk?s.android=e:r&&(s[r]=e,s.ios=e);var m="";r?m=(m=o(/os (\d+([_\s]\d+)*) like mac os x/i)).replace(/[_\s]/g,"."):n?m=o(/android[ \/-](\d+(\.\d+)*)/i):s.windowsphone?m=o(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):s.webos?m=o(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):s.blackberry?m=o(/rim\stablet\sos\s(\d+(\.\d+)*)/i):s.bada?m=o(/bada\/(\d+(\.\d+)*)/i):s.tizen&&(m=o(/tizen[\/\s](\d+(\.\d+)*)/i)),m&&(s.osversion=m);var v=m.split(".")[0];return t||"ipad"==r||n&&(3==v||4==v&&!d)||s.silk?s.tablet=e:(d||"iphone"==r||"ipod"==r||n||s.blackberry||s.webos||s.bada)&&(s.mobile=e),s.msie&&s.version>=9||s.chrome&&s.version>=20||s.firefox&&s.version>=10||s.safari&&s.version>=5||s.opera&&s.version>=10||s.ios&&s.osversion&&s.osversion.split(".")[0]>=6?s.a=e:s.msie&&s.version<9||s.chrome&&s.version<20||s.firefox&&s.version<10||s.safari&&s.version<5||s.opera&&s.version<10||s.ios&&s.osversion&&s.osversion.split(".")[0]<6?s.c=e:s.x=e,s}var o=i("undefined"!=typeof navigator?navigator.userAgent:"");return o._detect=i,window.bowser||(window.bowser=o),o}));wdi.Flipper={flip:function(e){return this._handMadeFlip(e)},_handMadeFlip:function(e){var t=document.createElement("canvas");t.width=e.width,t.height=e.height;var a=t.getContext("2d");return a.save(),a.scale(1,-1),a.drawImage(e,0,-e.height),a.restore(),t}};wdi.CollisionDetector={thereIsBoxCollision:function(t,o){return!(t.bottom<o.top)&&(!(t.top>o.bottom)&&(!(t.right<o.left)&&t.left<o.right))}};wdi.GlobalPool={pools:{},retained:null,init:function(){this.retained={};var e=this;this.pools.ViewQueue=new wdi.GenericObjectPool([function(){return new wdi.ViewQueue},function(e,n){e.poolIndex=n,e.setData([])}]),this.pools.RawSpiceMessage=new wdi.GenericObjectPool([function(){return new wdi.RawSpiceMessage},function(e,n){e.poolIndex=n,e.set(null,null,null)}]),this.retained.Image=[],this.pools.Image=new wdi.GenericObjectPool([function(){return new Image},function(n,i){n.poolIndex=i,n.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",n.onload=null,n.keepAlive=!1,e.retained.Image[i]=n}]),this.retained.Canvas=[],this.pools.Canvas=new wdi.GenericObjectPool([function(){return e.createCanvas()},function(n,i){n.keepAlive=!1,n.poolIndex=i,e.retained.Canvas[i]=n}])},dispose:function(){var e=this;Object.keys(this.retained).forEach((function(n){e.cleanPool(n),e.retained[n].length=0})),Object.keys(this.pools).forEach((function(n){e.pools[n].dispose()})),this.pools={},this.retained=null},createCanvas:function(){return $("<canvas/>")[0]},create:function(e){return this.pools[e].create()},discard:function(e,n){return this.retained.hasOwnProperty(e)&&delete this.retained[e][n.poolIndex],this.pools[e].discard(n.poolIndex)},cleanPool:function(e){if(this.retained.hasOwnProperty(e)){var n=this.pools[e];for(var i in this.retained[e])n.discard(this.retained[e][i].poolIndex)&&delete this.retained[e][i]}else wdi.Debug.error("GlobalPool: cleanPool called with invalid objectType: ",e)}};wdi.GenericObjectPool=$.spcExtend(wdi.EventObject.prototype,{expandFactor:.2,expandMinUnits:16,elems:null,freeElems:null,allocator:null,resetor:null,init:function(e){var t=e[0],s=e[1];this.allocator=t,this.resetor=s,this.elems=[this.allocator()],this.freeElems=[0]},dispose:function(){this.elems=null,this.freeElems=null,this.allocator=null,this.resetor=null},create:function(){this.freeElems.length||this.expand();var e=this.freeElems.pop(),t=this.elems[e];return this.resetor(t,e),t},length:function(){return this.elems.length-this.freeElems.length},expand:function(){var e=this.elems.length,t=Math.ceil(this.elems.length*this.expandFactor);t<this.expandMinUnits&&(t=this.expandMinUnits),this.elems.length=this.elems.length+t;for(var s=e;s<this.elems.length;s++)this.elems[s]=this.allocator(),this.freeElems.push(s)},discard:function(e){if(this.freeElems.indexOf(e)>=0)throw"GeneircObjectPool: Double-free for element index: "+e;return!this.elems[e].keepAlive&&(this.freeElems.push(e),!0)},get:function(e){return this.elems[e]}});wdi.AsyncConsumer=$.spcExtend(wdi.EventObject.prototype,{worker:null,task:null,packetWorkerIdentifier:null,imageProperties:null,disposed:!1,init:function(e){this.superInit(),this.worker=e.AsyncWorker||new wdi.AsyncWorker({script:wdi.spiceClientPath+"/spice-console-minify/WorkerProcess.min.js"}),this.packetWorkerIdentifier=e.packetWorkerIdentifier||new wdi.PacketWorkerIdentifier},consume:function(e){this.task=e;var t,i,r,s,a,n,o,p=e.message,d=this.packetWorkerIdentifier.shouldUseWorker(p);if(d==wdi.PacketWorkerIdentifier.processingType.DECOMPRESS&&(t=this.packetWorkerIdentifier.getImageProperties(p),this.imageProperties=t,t&&t.descriptor.type!=wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB&&t.descriptor.type!=wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC?d=0:t||(d=0)),0!==d)if(d==wdi.PacketWorkerIdentifier.processingType.DECOMPRESS){if(i=t.data,r=t.descriptor,s=t.opaque,a=t.brush,r.type===wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB){var h=null;if(a)h=wdi.LZSS.demarshall_rgb(i);else{var k=i.subarray(0,32).toJSArray();i=i.subarray(32),h=wdi.LZSS.demarshall_rgb(k)}n=new ArrayBuffer(i.length+16),(o=new Uint8Array(n))[0]=1,o[1]=s,o[2]=h.type,o[3]=h.top_down;for(var w=h.width*h.height*4,c=0;c<4;c++)o[4+c]=255&w,w>>=8;(l=new DataView(n)).setUint32(8,h.width),l.setUint32(12,h.height),o.set(i,16),this.worker.run(n,this._workerCompleted,{type:"lz",top_down:h.top_down,opaque:s},this)}else if(r.type===wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC){var l,g=new ArrayBuffer(i.length+4);(l=new Uint8Array(g)).set(i,4),l[1]=s?1:0,l[0]=0,this.worker.run(g,this._workerCompleted,{type:"quic"},this)}}else d==wdi.PacketWorkerIdentifier.processingType.PROCESSVIDEO&&(i=this.packetWorkerIdentifier.getVideoData(p),n=new ArrayBuffer(i.length+4),(o=new Uint8Array(n))[0]=2,o[1]=0,o[2]=0,o[3]=0,o.set(i,4),this.worker.run(n,(function(e,t){p.args.data=e,this.taskDone()}),null,this));else this.taskDone()},_workerCompleted:function(e,t){if(e){var i=this.imageProperties.descriptor,r=new Uint8ClampedArray(e),s=new ImageData(r,i.width,i.height),a=s;if("lz"===t.type){var n=t.top_down,o=t.opaque;n||o||(a=wdi.graphics.getImageFromData(s,!0),a=wdi.RasterOperation.flip(a))}i.originalType=i.type,i.type=wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS,this.task.message.messageType===wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL?(this.task.message.args.brush.pattern.imageData=a,this.task.message.args.brush.pattern.image.type=wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS):this.task.message.args.image.data=a,this.taskDone()}else this.taskDone()},taskDone:function(){this.task.state=1,this.fire("done",this)},dispose:function(){this.disposed||(this.disposed=!0,this.worker.dispose(),this.worker=null,this.task=null,this.packetWorkerIdentifier=null,this.imageProperties=null)}});wdi.AsyncWorker=$.spcExtend(wdi.EventObject.prototype,{worker:null,fn:null,scope:null,params:null,callback:null,init:function(s){this.superInit(),this.worker=new Worker(s.script);var t=this;this.callback=function(s){t.fn.call(t.scope,s.data,t.params)},this.worker.addEventListener("message",this.callback)},run:function(s,t,e,i){this.fn=t,this.scope=i,this.params=e,wdi.postMessageW3CCompilant?this.worker.postMessage(s,[s]):this.worker.postMessage(s)},dispose:function(){this.worker.removeEventListener("message",this.callback),this.worker.terminate(),this.worker=null,this.fn=null,this.scope=null,this.params=null,this.callback=null}});wdi.PacketWorkerIdentifier=$.spcExtend(wdi.EventObject.prototype,{init:function(e){},dispose:function(){},shouldUseWorker:function(e){switch(e.messageType){case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY:return wdi.PacketWorkerIdentifier.processingType.DECOMPRESS;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL:if(e.args.brush.type===wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN)return wdi.PacketWorkerIdentifier.processingType.DECOMPRESS;break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:return wdi.PacketWorkerIdentifier.processingType.DECOMPRESS}return 0},getImageProperties:function(e){var r={data:null,descriptor:null,opaque:!0,brush:null};switch(e.messageType){case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY:r.descriptor=e.args.image.imageDescriptor,r.data=e.args.image.data;break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL:if(r.brush=e.args.brush,r.brush.type!==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN)return!1;r.descriptor=r.brush.pattern.image,r.data=r.brush.pattern.imageData;break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:r.data=e.args.image.data,r.descriptor=e.args.image.imageDescriptor,r.opaque=!1;break;default:return wdi.Debug.log("PacketWorkerIdentifier: Unknown Packet in getImageProperties"),!1}return r},getVideoData:function(e){return e.messageType!==wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA?(wdi.Debug.log("PacketWOrkerIdentifier: Invalid packet in getVideoData"),!1):e.args.data}}),wdi.PacketWorkerIdentifier.processingType={},wdi.PacketWorkerIdentifier.processingType.DECOMPRESS=1,wdi.PacketWorkerIdentifier.processingType.PROCESSVIDEO=2;wdi.SpiceObject={properties:{},bytesToString:function(t){const e=new Uint8Array(t);return new TextDecoder("utf-8").decode(e)},bytesToURI:function(t){var e=new Blob([t],{type:"image/jpeg"});return URL.createObjectURL(e)},bytesToStringBE:function(t,e){for(var i="",s=e||t.length;s>=0;s--)i+=String.fromCharCode(t[s]);return i},bytesToInt8:function(t){return t.shift()},bytesToInt8NoAllocate:function(t){var e=t.getByte(0);return t.eatBytes(1),e},bytesToInt16:function(t){var e=t.shift();return t.shift()*Math.pow(16,2)+e},bytesToInt16BE:function(t){var e=t.shift(),i=t.shift();return e*Math.pow(16,2)+i},bytesToInt32:function(t){var e=wdi.SpiceObject.bytesToInt16(t);return wdi.SpiceObject.bytesToInt16(t)*Math.pow(16,4)+e},bytesToInt16NoAllocate:function(t){var e=t.getByte(0),i=t.getByte(1);return t.eatBytes(2),i*Math.pow(16,2)+e},bytesToInt32NoAllocate:function(t){var e=wdi.SpiceObject.bytesToInt16NoAllocate(t);return wdi.SpiceObject.bytesToInt16NoAllocate(t)*Math.pow(16,4)+e},bytesToInt32BE:function(t){var e=wdi.SpiceObject.bytesToInt16BE(t),i=wdi.SpiceObject.bytesToInt16BE(t);return e*Math.pow(16,4)+i},bytesToInt64:function(t){var e=wdi.SpiceObject.bytesToInt32(t).toString(2).lpad("0",32),i=wdi.SpiceObject.bytesToInt32(t).toString(2).lpad("0",32);return BigInteger.parse(i+e,2)},bytesToInt64NoAllocate:function(t){var e=wdi.SpiceObject.bytesToInt32NoAllocate(t).toString(2).lpad("0",32),i=wdi.SpiceObject.bytesToInt32NoAllocate(t).toString(2).lpad("0",32);return BigInteger.parse(i+e,2)},bytesToInt64BE:function(t){var e=wdi.SpiceObject.bytesToInt32BE(t).toString(2).lpad("0",32),i=wdi.SpiceObject.bytesToInt32BE(t).toString(2).lpad("0",32);return BigInteger.parse(e+i,2)},bytesToArray:function(t,e,i,s){var n=t.length,o=i||n,h=s||"LE",a=[],r=null;switch(e){case 8:r=wdi.SpiceObject.bytesToInt8;break;case 16:r="LE"==h?wdi.SpiceObject.bytesToInt16:wdi.SpiceObject.bytesToInt16BE;break;case 32:r="LE"==h?wdi.SpiceObject.bytesToInt32:wdi.SpiceObject.bytesToInt32BE;break;case 64:r="LE"==h?wdi.SpiceObject.bytesToInt64:wdi.SpiceObject.bytesToInt64BE;break;default:throw new Exception("Not supported number of bits",1)}for(var c=0;c<o;c++)a=a.concat(r(t));return a},int32ToDouble:function(t){return(15&t)/15+wdi.SpiceObject.unsignedToSigned(t>>4)},unsignedToSigned:function(t,e){var i=Math.pow(2,e)-1;return t&Math.pow(2,e-1)&&(t=-1*(i-t)),t},arrayToBytes:function(t,e,i){var s=t.length,n=i||s,o=null,h=[];switch(e){case 8:o=wdi.SpiceObject.numberTo8;break;case 16:o=wdi.SpiceObject.numberTo16;break;case 32:o=wdi.SpiceObject.numberTo32;break;case 64:o=wdi.SpiceObject.numberTo64;break;default:throw new Exception("Not supported number of bits",1)}for(var a=0;a<n;a++)a<=s?h=h.concat(o(t[a])):h.push(0);return h},stringToBytes:function(t){for(var e=[],i=0;i<t.length;i++){var s=t.charCodeAt(i);s<128?e.push(s):s<2048?e.push(192|s>>6,128|63&s):s<55296||s>=57344?e.push(224|s>>12,128|s>>6&63,128|63&s):(i++,s=65536+((1023&s)<<10|1023&t.charCodeAt(i)),e.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|63&s))}return e},arrayBufferToBytes:function(t){return new Uint8Array(t).toJSArray()},stringHexToBytes:function(t){for(var e=t.length,i=[],s=0;s<e;s+=2)i.push(parseInt(t[s]+t[s+1],16));return i},stringBinaryToBytes:function(t,e){t=t.lpad("0",e);for(var i=[],s=e;s>=8;s-=8)i=i.concat(parseInt(t.substr(s-8,8),2));return i},stringToBytesPadding:function(t,e){for(var i=[],s=t.length,n=0;n<e;n++)e>s-1?i.push(0):i.push(t.charCodeAt(n));return i},numberTo64:function(t){var e=this.numberTo32((0x10000000000000000&t)>>32);return this.numberTo32(4294967295&t).concat(e)},numberTo32:function(t){for(var e=new Array(3),i=0;i<4;i++)e[i]=255&t,t>>=8;return e},numberTo16:function(t){for(var e=new Array(1),i=0;i<2;i++)e[i]=255&t,t>>=8;return e},numberTo8:function(t){return[255&t]},getMessageProperties:function(){return this.properties},getMessageProperty:function(t,e){return this.properties.hasOwnProperty(t)?this.properties[t]:e}},wdi.SpiceDataHeader=$.spcExtend(wdi.SpiceObject,{objectSize:6,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.size=t.size},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.type),this.numberTo32(this.size)),this.rawData},demarshall:function(t){return this.type=this.bytesToInt16NoAllocate(t),this.size=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceCompatibility=$.spcExtend(wdi.SpiceObject,{init:function(t){t&&this.setContent(t)},setContent:function(t){this.channel_type=t.channel_type,this.caps=t.caps},marshall:function(){return this.rawData=[],this.rawData=[this.numberTo8(this.channel_type),...this.caps.map((t=>this.numberTo32(t)))],this.rawData},demarshall:function(t){}}),wdi.SpiceLinkAuthMechanism=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.auth_mechanism=t.auth_mechanism},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.auth_mechanism)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.auth_mechanism=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkReply=$.spcExtend(wdi.SpiceObject,{objectSize:178,init:function(t){t&&this.setContent(t)},setContent:function(t){this.error=t.error,this.pub_key=t.pub_key,this.num_common_caps=t.num_common_caps,this.num_channel_caps=t.num_channel_caps,this.caps_offset=t.caps_offset},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.error),this.arrayToBytes(this.pub_key,8),this.numberTo32(this.num_common_caps),this.numberTo32(this.num_channel_caps),this.numberTo32(this.caps_offset)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.error=this.bytesToInt32NoAllocate(t),this.pub_key=this.bytesToArray(t.shift(this.expectedSize),8),this.num_common_caps=this.bytesToInt32NoAllocate(t),this.num_channel_caps=this.bytesToInt32NoAllocate(t),this.caps_offset=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkEncryptedTicket=$.spcExtend(wdi.SpiceObject,{objectSize:128,init:function(t){t&&this.setContent(t)},setContent:function(t){this.encrypted_data=t.encrypted_data},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.stringToBytes(this.encrypted_data,8)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.encrypted_data=this.bytesToArray(t.shift(this.expectedSize),8),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkMess=$.spcExtend(wdi.SpiceObject,{objectSize:18,init:function(t){t&&this.setContent(t)},setContent:function(t){this.connection_id=t.connection_id,this.channel_type=t.channel_type,this.channel_id=t.channel_id,this.num_common_caps=t.num_common_caps,this.num_channel_caps=t.num_channel_caps,this.caps_offset=t.caps_offset,this.common_caps=t.common_caps,this.channel_caps=t.channel_caps},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.connection_id),this.numberTo8(this.channel_type),this.numberTo8(this.channel_id),this.numberTo32(this.num_common_caps),this.numberTo32(this.num_channel_caps),this.numberTo32(this.caps_offset)),this.num_common_caps>0&&(this.rawData=this.rawData.concat(this.numberTo32(this.common_caps))),this.num_channel_caps>0&&(this.rawData=this.rawData.concat(this.numberTo32(this.channel_caps))),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.connection_id=this.bytesToInt32NoAllocate(t),this.channel_type=this.bytesToInt8NoAllocate(t),this.channel_id=this.bytesToInt8NoAllocate(t),this.num_common_caps=this.bytesToInt32NoAllocate(t),this.num_channel_caps=this.bytesToInt32NoAllocate(t),this.caps_offset=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkHeader=$.spcExtend(wdi.SpiceObject,{objectSize:16,init:function(t){t&&this.setContent(t)},setContent:function(t){this.magic=t.magic,this.major_version=t.major_version,this.minor_version=t.minor_version,this.size=t.size},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.magic),this.numberTo32(this.major_version),this.numberTo32(this.minor_version),this.numberTo32(this.size)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.magic=this.bytesToInt32NoAllocate(t),this.major_version=this.bytesToInt32NoAllocate(t),this.minor_version=this.bytesToInt32NoAllocate(t),this.size=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.RedMigrateData=$.spcExtend(wdi.SpiceObject,{objectSize:0,init:function(t){t&&this.setContent(t)},setContent:function(t){this.vector=t.vector},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.arrayToBytes(this.vector,8)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.vector=this.bytesToArray(t.shift(this.expectedSize),8),this}}),wdi.RedMainInit=$.spcExtend(wdi.SpiceObject,{objectSize:32,init:function(t){t&&this.setContent(t)},setContent:function(t){this.session_id=t.session_id,this.display_channels_hint=t.display_channels_hint,this.supported_mouse_modes=t.supported_mouse_modes,this.current_mouse_mode=t.current_mouse_mode,this.agent_connected=t.agent_connected,this.agent_tokens=t.agent_tokens,this.multi_media_time=t.multi_media_time,this.ram_hint=t.ram_hint},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.session_id),this.numberTo32(this.display_channels_hint),this.numberTo32(this.supported_mouse_modes),this.numberTo32(this.current_mouse_mode),this.numberTo32(this.agent_connected),this.numberTo32(this.agent_tokens),this.numberTo32(this.multi_media_time),this.numberTo32(this.ram_hint)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.session_id=this.bytesToInt32NoAllocate(t),this.display_channels_hint=this.bytesToInt32NoAllocate(t),this.supported_mouse_modes=this.bytesToInt32NoAllocate(t),this.current_mouse_mode=this.bytesToInt32NoAllocate(t),this.agent_connected=this.bytesToInt32NoAllocate(t),this.agent_tokens=this.bytesToInt32NoAllocate(t),this.multi_media_time=this.bytesToInt32NoAllocate(t),this.ram_hint=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMsgMainAgentConnected=$.spcExtend(wdi.SpiceObject,{objectSize:0,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.SpiceChannelsList=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_of_channels=t.num_of_channels,this.channels=t.channels},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_of_channels),this.arrayToBytes(this.channels,16)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.num_of_channels=this.bytesToInt32NoAllocate(t),this.channels=this.bytesToArray(t.shift(this.expectedSize),16),this}}),wdi.RedSetAck=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.generation=t.generation,this.window=t.window},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.generation),this.numberTo32(this.window)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.generation=this.bytesToInt32NoAllocate(t),this.window=this.bytesToInt32NoAllocate(t),this}}),wdi.RedPing=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.id=t.id,this.time=t.time},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.id),this.numberTo64(this.time)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.time=this.bytesToInt64NoAllocate(t),this.expectedSize>12&&t.shift(this.expectedSize-12),this}}),wdi.RedMigrate=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.flags=t.flags},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.flags)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.flags=this.bytesToInt32NoAllocate(t),this}}),wdi.RedWaitForChannel=$.spcExtend(wdi.SpiceObject,{objectSize:10,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.id=t.id,this.serial=t.serial},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.type),this.numberTo8(this.id),this.numberTo64(this.serial)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt8NoAllocate(t),this.id=this.bytesToInt8NoAllocate(t),this.serial=this.bytesToInt64NoAllocate(t),this}}),wdi.RedWaitForChannels=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){this.wait_count=t.wait_count,this.wait_list=t.wait_list},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.wait_count),this.arrayToBytes(this.wait_list,8)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.wait_count=this.bytesToInt8NoAllocate(t),this.wait_list=this.bytesToArray(t.shift(this.expectedSize),8),this}}),wdi.RedDisconnect=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.time_stamp=t.time_stamp,this.reason=t.reason},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo64(this.time_stamp),this.numberTo32(this.reason)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.time_stamp=this.bytesToInt64NoAllocate(t),this.reason=this.bytesToInt32NoAllocate(t),this}}),wdi.RedMigrationBegin=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.port=t.port,this.sport=t.sport,this.host_name=t.host_name},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.port),this.numberTo16(this.sport),this.arrayToBytes(this.host_name,8)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.port=this.bytesToInt16NoAllocate(t),this.sport=this.bytesToInt16NoAllocate(t),this.host_name=this.bytesToArray(t.shift(this.expectedSize),8),this}}),wdi.RedNotify=$.spcExtend(wdi.SpiceObject,{objectSize:25,init:function(t){t&&this.setContent(t)},setContent:function(t){this.time_stamp=t.time_stamp,this.severity=t.severity,this.visibility=t.visibility,this.what=t.what,this.message_len=t.message_len,this.message=t.message,this.zero=t.zero},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo64(this.time_stamp),this.numberTo32(this.severity),this.numberTo32(this.visibility),this.numberTo32(this.what),this.numberTo32(this.message_len),this.arrayToBytes(this.message,8),this.numberTo8(this.zero)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.time_stamp=this.bytesToInt64NoAllocate(t),this.severity=this.bytesToInt32NoAllocate(t),this.visibility=this.bytesToInt32NoAllocate(t),this.what=this.bytesToInt32NoAllocate(t),this.message_len=this.bytesToInt32NoAllocate(t),this.message=this.bytesToString(t.shift(this.message_len)),this.zero=this.bytesToInt8NoAllocate(t),this}}),wdi.RedMode=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.width=t.width,this.height=t.height,this.depth=t.depth},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.width),this.numberTo32(this.height),this.numberTo32(this.depth)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this.depth=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceCDisplayInit=$.spcExtend(wdi.SpiceObject,{objectSize:14,init:function(t){t&&this.setContent(t)},setContent:function(t){this.pixmap_cache_id=t.pixmap_cache_id,this.pixmap_cache_size=t.pixmap_cache_size,this.glz_dictionary_id=t.glz_dictionary_id,this.glz_dictionary_window_size=t.glz_dictionary_window_size},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.pixmap_cache_id),this.numberTo8(0),this.numberTo8(127),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(this.glz_dictionary_id),this.numberTo32(this.glz_dictionary_window_size)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.pixmap_cache_id=this.bytesToInt8NoAllocate(t),this.pixmap_cache_size=this.bytesToInt64NoAllocate(t),this.glz_dictionary_id=this.bytesToInt8NoAllocate(t),this.glz_dictionary_window_size=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceSurfaceDestroy=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.surface_id=t.surface_id},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.surface_id)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceSurface=$.spcExtend(wdi.SpiceObject,{objectSize:20,init:function(t){t&&this.setContent(t)},setContent:function(t){this.surface_id=t.surface_id,this.width=t.width,this.height=t.height,this.format=t.format,this.flags=t.flags},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.surface_id),this.numberTo32(this.width),this.numberTo32(this.height),this.numberTo32(this.format),this.numberTo32(this.flags)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this.format=this.bytesToInt32NoAllocate(t),this.flags=this.bytesToInt32NoAllocate(t),this}}),wdi.SpicePath=$.spcExtend(wdi.SpiceObject,{objectSize:4,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});var i=this.num_segments=this.bytesToInt32NoAllocate(t);this.segments=[];for(var s=0;s<i;s++)this.segments[s]=(new wdi.SpicePathSeg).demarshall(t);return this}}),wdi.SpicePathSeg=$.spcExtend(wdi.SpiceObject,{objectSize:8,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.flags=this.bytesToInt8NoAllocate(t);var i=this.count=this.bytesToInt32NoAllocate(t);this.points=[];for(var s=0;s<i;s++)this.points[s]=(new wdi.SpicePointFix).demarshall(t);return this}}),wdi.SpicePoint=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.unsignedToSigned(this.bytesToInt32(t.shift(4)),32),this.y=this.unsignedToSigned(this.bytesToInt32(t.shift(4)),32),this}}),wdi.SpicePoint16=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.x),this.numberTo16(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.bytesToInt16NoAllocate(t),this.y=this.bytesToInt16NoAllocate(t),this}}),wdi.SpicePointFix=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.hasOwnProperty("x")?t.x:0,this.y=t.hasOwnProperty("y")?t.y:0},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.int32ToDouble(this.bytesToInt32(t.shift(4)),32),this.y=this.int32ToDouble(this.bytesToInt32(t.shift(4)),32),this}}),wdi.SpiceRect=$.spcExtend(wdi.SpiceObject,{objectSize:16,init:function(t){t&&this.setContent(t)},setContent:function(t){this.top=t.top,this.left=t.left,this.bottom=t.bottom,this.right=t.right},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.top),this.numberTo32(this.left),this.numberTo32(this.bottom),this.numberTo32(this.right)),this.rawData},demarshall:function(t,e){return this.top=this.bytesToInt32NoAllocate(t),this.left=this.bytesToInt32NoAllocate(t),this.bottom=this.bytesToInt32NoAllocate(t),this.right=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceClipRects=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_rects=t.num_rects},marshall:function(){this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_rects));for(var t=0;t<this.num_rects;t++)this.rawData=this.rawData.concat(this.rects[t].marshall());return this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});if(this.num_rects=this.bytesToInt32NoAllocate(t),this.num_rects>0){this.rects=[];for(var i=0;i<this.num_rects;i++)this.rects[i]=(new wdi.SpiceRect).demarshall(t)}return this}}),wdi.SpiceClip=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.type)),this.type==wdi.SpiceClipType.SPICE_CLIP_TYPE_RECTS&&(this.rawData=this.rawData.concat(this.rects.marshall())),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt8NoAllocate(t),this.type==wdi.SpiceClipType.SPICE_CLIP_TYPE_RECTS&&(this.rects=(new wdi.SpiceClipRects).demarshall(t)),this}}),wdi.SpiceDisplayBase=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.surface_id=t.surface_id},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.surface_id),this.box.marshall(),this.clip.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.box=(new wdi.SpiceRect).demarshall(t),this.clip=(new wdi.SpiceClip).demarshall(t),this}}),wdi.SpiceQMask=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo8(this.flags),this.pos.marshall(),this.numberTo32(this.offset)),this.offset&&(t=t.concat(this.image.marshall())),t},demarshall:function(t,e){t.eatBytes(13)}}),wdi.SpiceImageDescriptor=$.spcExtend(wdi.SpiceObject,{objectSize:18,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo64(this.id),this.numberTo8(this.type),this.numberTo8(this.flags),this.numberTo32(this.width),this.numberTo32(this.height))},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});var i=this.bytesToInt32NoAllocate(t);return this.id=i.toString(16)+this.bytesToInt32NoAllocate(t).toString(16),this.type=this.bytesToInt8NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this.offset=t.getPosition(),this}}),wdi.SpiceImage=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.imageDescriptor.marshall(),this.data)},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.imageDescriptor=(new wdi.SpiceImageDescriptor).demarshall(t),this.data=t.getRawData(),this}}),wdi.SpiceDrawCopy=$.spcExtend(wdi.SpiceObject,{objectSize:4,properties:{overWriteScreenArea:!0},init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.base.marshall(),this.numberTo32(this.offset),this.src_area.marshall(),this.numberTo16(this.rop_descriptor),this.numberTo8(this.scale_mode),this.mask.marshall(),this.image.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});if(this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.rop_descriptor=this.bytesToInt16NoAllocate(t),this.scale_mode=this.bytesToInt8NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),t.getPosition()==this.offset)this.image=(new wdi.SpiceImage).demarshall(t);else{var i=new wdi.ViewQueue;i.setData(t.getDataOffset(this.offset)),this.image=(new wdi.SpiceImage).demarshall(i)}return this}}),wdi.drawBlend=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.base=t.base,this.alpha_flags=t.alpha_flags,this.alpha=t.alpha,this.offset=t.offset,this.src_area=t.src_area},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.numberTo32(this.offset),this.src_area.marshall(),this.numberTo16(this.rop_descriptor),this.numberTo8(this.flags),this.mask.marshall(),this.image.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.rop_descriptor=this.bytesToInt16NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this.image=(new wdi.SpiceImage).demarshall(t),this}}),wdi.drawAlphaBlend=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.base=t.base,this.alpha_flags=t.alpha_flags,this.alpha=t.alpha,this.offset=t.offset,this.src_area=t.src_area},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.alpha_flags=this.bytesToInt8NoAllocate(t),this.alpha=this.bytesToInt8NoAllocate(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.image=(new wdi.SpiceImage).demarshall(t),this}}),wdi.drawTransparent=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.transparent_color=(new wdi.SpiceColor).demarshall(t),this.transparent_true_color=(new wdi.SpiceColor).demarshall(t),this.image=(new wdi.SpiceImage).demarshall(t),this}}),wdi.SpiceCopyBits=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.src_position.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.src_position=(new wdi.SpicePoint).demarshall(t),this}}),wdi.SpiceImageLZRGB=$.spcExtend(wdi.SpiceObject,{objectSize:32,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.length=this.bytesToInt32BE(t.shift(4)),this.magic=this.bytesToStringBE(t.shift(4)),this.version=this.bytesToInt32BE(t.shift(4)),this.type=this.bytesToInt32BE(t.shift(4)),this.width=this.bytesToInt32BE(t.shift(4)),this.height=this.bytesToInt32BE(t.shift(4)),this.stride=this.bytesToInt32BE(t.shift(4)),this.top_down=this.bytesToInt32BE(t.shift(4)),this.data=t.shift(this.length),this}}),wdi.SpiceMouseModeRequest=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.request_mode=t.request_mode},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.request_mode)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.request_mode=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMouseMode=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.supported_modes=t.supported_modes,this.current_mode=t.current_mode},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.supported_modes),this.numberTo32(this.current_mode)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,!(t.getLength()<this.expectedSize))return this.supported_modes=this.bytesToInt16NoAllocate(t),this.current_mode=this.bytesToInt16NoAllocate(t),this}}),wdi.RedcMousePress=$.spcExtend(wdi.SpiceObject,{objectSize:3,init:function(t){t&&this.setContent(t)},setContent:function(t){this.button_id=t.button_id,this.buttons_state=t.buttons_state},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.button_id),this.numberTo16(this.buttons_state)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.button_id=this.bytesToInt8NoAllocate(t),this.buttons_state=this.bytesToInt16NoAllocate(t),this}}),wdi.RedcMousePosition=$.spcExtend(wdi.SpiceObject,{objectSize:11,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y,this.buttons_state=t.buttons_state,this.display_id=t.display_id},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y),this.numberTo16(this.buttons_state),this.numberTo8(this.display_id)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.bytesToInt32NoAllocate(t),this.y=this.bytesToInt32NoAllocate(t),this.buttons_state=this.bytesToInt16NoAllocate(t),this.display_id=this.bytesToInt8NoAllocate(t),this}}),wdi.RedcMouseMotion=$.spcExtend(wdi.SpiceObject,{objectSize:10,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y,this.buttons_state=t.buttons_state},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y),this.numberTo16(this.buttons_state)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.bytesToInt32NoAllocate(t),this.y=this.bytesToInt32NoAllocate(t),this.buttons_state=this.bytesToInt16NoAllocate(t),this}}),wdi.SpiceBrush=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.color=t.color},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt8NoAllocate(t),this.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN?this.pattern=(new wdi.SpicePattern).demarshall(t):this.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_SOLID&&(this.color=(new wdi.SpiceColor).demarshall(t)),this}}),wdi.SpiceColor=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){return[this.r,this.g,this.b]},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.data=16777215&this.bytesToInt32(t.shift(4)),this.r=this.data>>16,this.g=this.data>>8&255,this.b=255&this.data,this.html_color="rgb("+this.r+", "+this.g+", "+this.b+")";var i=this.r.toString(16),s=this.g.toString(16),n=this.b.toString(16);return i.length<2&&(i="0"+i),s.length<2&&(s="0"+s),n.length<2&&(n="0"+n),this.simple_html_color="#"+i+s+n,this}}),wdi.RgbaColor=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.data=4294967295&this.bytesToInt32(t.shift(4)),this.a=this.data>>>24,this.r=this.data>>>16&255,this.g=this.data>>>8&255,this.b=255&this.data,this.html_color="rgb("+this.r+", "+this.g+", "+this.b+")",this}}),wdi.SpicePattern=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.offset=this.bytesToInt32NoAllocate(t),this.point=(new wdi.SpicePoint).demarshall(t);var i=new wdi.ViewQueue;return i.setData(t.getDataOffset(this.offset)),this.image=(new wdi.SpiceImage).demarshall(i),this}}),wdi.SpiceDrawFill=$.spcExtend(wdi.SpiceObject,{objectSize:4,properties:{overWriteScreenArea:!0},init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.offset)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.brush=(new wdi.SpiceBrush).demarshall(t),this.rop_descriptor=this.bytesToInt16NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this.brush.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN&&(this.brush.pattern.image=(new wdi.SpiceImageDescriptor).demarshall(t),this.brush.pattern.imageData=t.getData()),this}}),wdi.SpiceDrawRop3=$.spcExtend(wdi.SpiceObject,{objectSize:4,marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.numberTo32(this.offset),this.src_area.marshall(),this.brush.marshall(),this.numberTo8(this.rop_descriptor),this.numberTo8(this.scale_mode),this.mask.marshall(),this.src_image.marshall()),this.brush.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN&&(t=t.concat(this.brush.pattern.image.marshall(),this.brush.pattern.imageData)),t},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.brush=(new wdi.SpiceBrush).demarshall(t),this.rop_descriptor=this.bytesToInt8NoAllocate(t),this.scale_mode=this.bytesToInt8NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this.src_image=(new wdi.SpiceImage).demarshall(t),this.brush.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN&&(this.brush.pattern.image=(new wdi.SpiceImageDescriptor).demarshall(t),this.brush.pattern.imageData=t.getData()),this}}),wdi.SpiceDrawBlackness=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.mask.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this}}),wdi.SpiceDrawWhiteness=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.mask.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this}}),wdi.SpiceScanCode=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){this.code=t||0,this.zero=0},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.arrayToBytes(this.code,8),this.numberTo8(this.zero)),this.rawData},demarshall:function(t,e){return this},getCode:function(){return this.code}}),wdi.RedCursorInit=$.spcExtend(wdi.SpiceObject,{objectSize:9,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.position=(new wdi.SpicePoint16).demarshall(t),this.trail_length=this.bytesToInt16NoAllocate(t),this.trail_frequency=this.bytesToInt16NoAllocate(t),this.visible=this.bytesToInt8NoAllocate(t),this.cursor=(new wdi.RedCursor).demarshall(t),this}}),wdi.RedCursor=$.spcExtend(wdi.SpiceObject,{objectSize:2,marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.flags)),1&this.flags||(this.rawData=this.rawData.concat(this.header.marshall(),this.data)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.flags=this.bytesToInt16NoAllocate(t),this.header=null,this.data=null,1&this.flags||(this.header=(new wdi.RedCursorHeader).demarshall(t),this.data=t.getData()),this}}),wdi.RedCursorHeader=$.spcExtend(wdi.SpiceObject,{objectSize:17,marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo64(this.unique),this.numberTo8(this.type),this.numberTo16(this.width),this.numberTo16(this.height),this.numberTo16(this.hot_spot_x),this.numberTo16(this.hot_spot_y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.unique=this.bytesToInt64NoAllocate(t),this.type=this.bytesToInt8NoAllocate(t),this.width=this.bytesToInt16NoAllocate(t),this.height=this.bytesToInt16NoAllocate(t),this.hot_spot_x=this.bytesToInt16NoAllocate(t),this.hot_spot_y=this.bytesToInt16NoAllocate(t),this}}),wdi.RedCursorSet=$.spcExtend(wdi.SpiceObject,{objectSize:5,marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.position.marshall(),this.numberTo8(this.visible),this.cursor.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.position=(new wdi.SpicePoint16).demarshall(t),this.visible=this.bytesToInt8NoAllocate(t),this.cursor=(new wdi.RedCursor).demarshall(t),this}}),wdi.RedCursorHide=$.spcExtend(wdi.SpiceObject,{objectSize:5,marshall:function(){},demarshall:function(){return this}}),wdi.RasterGlyph=$.spcExtend(wdi.SpiceObject,{objectSize:20,marshall:function(){},demarshall:function(t,e,i){for(var s=1==e?1:2*e,n=[],o=0;o<i;o++)n[o]={},n[o].render_pos=(new wdi.SpicePoint).demarshall(t),n[o].glyph_origin=(new wdi.SpicePoint).demarshall(t),n[o].width=this.bytesToInt16NoAllocate(t),n[o].height=this.bytesToInt16NoAllocate(t),n[o].data=t.shift(n[o].height*Math.ceil(n[o].width*s/8));return n}}),wdi.GlyphString=$.spcExtend(wdi.SpiceObject,{objectSize:3,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.len=this.bytesToInt16NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.raster_glyph=(new wdi.RasterGlyph).demarshall(t,this.flags,this.len),this}}),wdi.SpiceDrawText=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.back_area=(new wdi.SpiceRect).demarshall(t),this.fore_brush=(new wdi.SpiceBrush).demarshall(t),this.back_brush=(new wdi.SpiceBrush).demarshall(t),this.fore_mode=this.bytesToInt16NoAllocate(t),this.back_mode=this.bytesToInt16NoAllocate(t),this.glyph_string=(new wdi.GlyphString).demarshall(t),this}}),wdi.SpiceLineAttr=$.spcExtend(wdi.SpiceObject,{objectSize:8,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.flags=this.bytesToInt8NoAllocate(t),this.flags&&(this.style_nseg=this.bytesToInt8NoAllocate(t),this.style=this.int32ToDouble(this.bytesToInt32(t.shift(4)))),this}}),wdi.SpiceStroke=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.attr=(new wdi.SpiceLineAttr).demarshall(t),this.brush=(new wdi.SpiceBrush).demarshall(t),this.fore_mode=this.bytesToInt16NoAllocate(t),this.back_mode=this.bytesToInt16NoAllocate(t),this.path=(new wdi.SpicePath).demarshall(t),this}}),wdi.SpiceDrawInvers=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.mask.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this}}),wdi.SpiceStreamCreate=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t.concat(this.numberTo32(this.surface_id),this.numberTo32(this.id),this.numberTo8(this.flags),this.numberTo8(this.codec),this.numberTo64(this.stamp),this.numberTo32(this.stream_width),this.numberTo32(this.stream_height),this.numberTo32(this.src_width),this.numberTo32(this.src_height),this.rect.marshall(),this.clip.marshall()),t},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.id=this.bytesToInt32NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.codec=this.bytesToInt8NoAllocate(t),this.stamp=this.bytesToInt64NoAllocate(t),this.stream_width=this.bytesToInt32NoAllocate(t),this.stream_height=this.bytesToInt32NoAllocate(t),this.src_width=this.bytesToInt32NoAllocate(t),this.src_height=this.bytesToInt32NoAllocate(t),this.rect=(new wdi.SpiceRect).demarshall(t),this.clip=(new wdi.SpiceClip).demarshall(t),this}}),wdi.SpiceStreamDestroy=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.surface_id),this.numberTo32(this.id))},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.id=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceStreamData=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.id),this.numberTo32(this.multi_media_type),this.numberTo32(this.data_size),this.data)},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.multi_media_type=this.bytesToInt32NoAllocate(t),this.data_size=this.bytesToInt32NoAllocate(t),this.data=t.getRawData(),this}}),wdi.SpiceStreamClip=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.id),this.clip.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.clip=(new wdi.SpiceClip).demarshall(t),this}}),wdi.SpiceStreamDataSized=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.id),this.numberTo32(this.width),this.numberTo32(this.height))},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceStreamActiveReport=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){},demarshall:function(t,e){}}),wdi.SpiceModifierData=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},setModifierData:function(t){6===t?(wdi.Keymap.capsLock=!0,wdi.Keymap.numLock=!0):4===t?(wdi.Keymap.capsLock=!0,wdi.Keymap.numLock=!1):2===t?(wdi.Keymap.capsLock=!1,wdi.Keymap.numLock=!0):0===t&&(wdi.Keymap.capsLock=!1,wdi.Keymap.numLock=!1)},marshall:function(){var t=[];return t=t.concat(this.numberTo16(this.data))},demarshall:function(t,e){return this.expectedSize=e||this.objectSize,this.data=this.bytesToInt16NoAllocate(t),this}}),wdi.SpiceResourceList=$.spcExtend(wdi.SpiceObject,{objectSize:2,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){for(var t=[],e=0;e<this.num_items;e++)t=t.concat(this.numberTo8(this.items[e].type),this.numberTo64(this.items[e].id));return t},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.num_items=this.bytesToInt16NoAllocate(t),this.items=[];for(var i=0;i<this.num_items;i++)this.items[i]={type:this.bytesToInt8(t.shift(1)),id:this.bytesToInt64(t.shift(8))};return this}}),wdi.SpiceMsgMainAgentTokens=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_tokens=t.num_tokens},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_tokens)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.num_tokens=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMsgMainAgentDisconnected=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.error=t.error},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.error)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.error=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMsgMainAgentData=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.agentMessage=t.agentMessage},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.agentMessage.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.agentMessage=(new wdi.VDAgentMessage).demarshall(t),this}}),wdi.VDIChunkHeader=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.port=t.port,this.size=t.size,this.packet=t.packet},marshall:function(){this.rawData=[];var t=this.packet.marshall();return this.rawData=this.rawData.concat(this.numberTo32(this.port),this.numberTo32(t.length),t),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMessage=$.spcExtend(wdi.SpiceObject,{objectSize:20,init:function(t){t&&this.setContent(t)},setContent:function(t){this.protocol=t.protocol,this.type=t.type,this.opaque=t.opaque,this.size=t.size,this.data=t.data},marshall:function(){this.rawData=[];var t=this.data.marshall();return this.rawData=this.rawData.concat(this.numberTo32(this.protocol),this.numberTo32(this.type),this.numberTo64(this.opaque),this.numberTo32(t.length),t),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});if(this.protocol=this.bytesToInt32NoAllocate(t),this.type=this.bytesToInt32NoAllocate(t),this.opaque=this.bytesToInt64NoAllocate(t),this.size=this.bytesToInt32NoAllocate(t),this.type==wdi.AgentMessageTypes.VD_AGENT_GET_WINDOWS_LIST){var i=this.bytesToString(t.shift(t.length));this.window_list="change"==i?i:jQuery.parseJSON(i)}else this.type==wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES?this.caps=(new wdi.VDAgentAnnounceCapabilities).demarshall(t):this.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB?0==t.getLength()?this.clipboardType=wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_NONE:this.clipboardType=this.bytesToInt32NoAllocate(t):this.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST?this.clipboardType=this.bytesToInt32NoAllocate(t):this.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD&&(this.clipboardType=this.bytesToInt32NoAllocate(t),this.clipboardData=this.bytesToString(t.shift(t.length)));return this}}),wdi.VDAgentHwndWindow=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.hwnd=t.hwnd},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.hwnd)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMoveWindow=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.hwnd=t.hwnd,this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.hwnd),this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentResizeWindow=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.hwnd=t.hwnd,this.width=t.width,this.height=t.height},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.hwnd),this.numberTo32(this.width),this.numberTo32(this.height)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMonitorsConfig=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_of_monitors=t.num_of_monitors,this.flags=t.flags,this.data=t.data},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_of_monitors),this.numberTo32(this.flags),this.data.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMonConfig=$.spcExtend(wdi.SpiceObject,{objectSize:20,init:function(t){t&&this.setContent(t)},setContent:function(t){this.height=t.height,this.width=t.width,this.depth=t.depth,this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.height),this.numberTo32(this.width),this.numberTo32(this.depth),this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentAnnounceCapabilities=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.request=t.request,this.caps=t.caps},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.request),this.numberTo32(this.caps)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.request=this.bytesToInt32NoAllocate(t),this.caps=this.bytesToInt32NoAllocate(t),this}}),wdi.VDAgentExecuteCommand=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.size=t.size,this.data=t.data},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.size),this.stringToBytes(this.data)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentClipboardRequest=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.type)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt32NoAllocate(t),this}}),wdi.VDAgentClipboardGrab=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.types=t.types},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.types)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.types=this.bytesToInt32NoAllocate(t),this}}),wdi.VDAgentClipboard=$.spcExtend(wdi.SpiceObject,{objectSize:6,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.data=t.data},marshall:function(){var t;return this.rawData=[],t=this.type===wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT?this.stringToBytes(this.data):this.arrayBufferToBytes(this.data),this.rawData=this.rawData.concat(this.numberTo32(this.type),t),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt32NoAllocate(t),this.data=t.getData(),this}}),wdi.PlaybackMode=$.spcExtend(wdi.SpiceObject,{objectSize:6,init:function(t){t&&this.setContent(t)},setContent:function(t){this.multimedia_time=t.multimedia_time,this.audio_data_mode=t.audio_data_mode,this.data=t.data},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.multimedia_time=this.bytesToInt32NoAllocate(t),this.audio_data_mode=this.bytesToInt16NoAllocate(t),this.data=t.getData(),this}}),wdi.PlaybackStart=$.spcExtend(wdi.SpiceObject,{objectSize:14,init:function(t){t&&this.setContent(t)},setContent:function(t){this.channels=t.channels,this.format=t.format,this.frequency=t.frequency,this.time=t.time},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.channels=this.bytesToInt32NoAllocate(t),this.format=this.bytesToInt16NoAllocate(t),this.frequency=this.bytesToInt32NoAllocate(t),this.time=this.bytesToInt32NoAllocate(t),this}}),wdi.PlaybackData=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.multimedia_time=t.multimedia_time,this.data=t.data},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.multimedia_time=this.bytesToInt32NoAllocate(t),this.data=t.getData(),this}}),wdi.MainMultiMediaTime=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.multimedia_time=t.multimedia_time},marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.multimedia_time=this.bytesToInt32NoAllocate(t),this}}),wdi.PlaybackStop=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.MainMChannelsList=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_of_channels=t.num_of_channels},marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.num_of_channels=this.bytesToInt32NoAllocate(t),this.channels=[];for(var i=null,s=0;s<this.num_of_channels;s++)i=this.bytesToInt8NoAllocate(t),this.bytesToInt8NoAllocate(t),this.channels.push(i);return this}}),wdi.SpiceDisplayInvalidAllPalettes=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.SpiceDisplayMark=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.SpiceDisplayReset=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.CodecConfig=$.spcExtend(wdi.SpiceObject,{objectSize:4,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.encodePoint=this.bytesToInt8NoAllocate(t),this.encodeDevice=this.bytesToInt8NoAllocate(t),this.codec=this.bytesToInt8NoAllocate(t),this.pixelFormat=this.bytesToInt8NoAllocate(t),this}});wdi.SpicePubkeyType={SPICE_PUBKEY_TYPE_INVALID:0,SPICE_PUBKEY_TYPE_RSA:1,SPICE_PUBKEY_TYPE_RSA2:2,SPICE_PUBKEY_TYPE_DSA:3,SPICE_PUBKEY_TYPE_DSA1:4,SPICE_PUBKEY_TYPE_DSA2:5,SPICE_PUBKEY_TYPE_DSA3:6,SPICE_PUBKEY_TYPE_DSA4:7,SPICE_PUBKEY_TYPE_DH:8,SPICE_PUBKEY_TYPE_EC:9,SPICE_PUBKEY_TYPE_ENUM_END:10},wdi.SpiceWarnCode={SPICE_WARN_GENERAL:0,SPICE_WARN_CODE_ENUM_END:1},wdi.SpiceLineFlags={SPICE_LINE_FLAGS_START_WITH_GAP:4,SPICE_LINE_FLAGS_STYLED:8,SPICE_LINE_FLAGS_MASK:12},wdi.SpiceNotifyVisibility={SPICE_NOTIFY_VISIBILITY_LOW:0,SPICE_NOTIFY_VISIBILITY_MEDIUM:1,SPICE_NOTIFY_VISIBILITY_HIGH:2,SPICE_NOTIFY_VISIBILITY_ENUM_END:3},wdi.SpiceVars={SPICE_MSGC_ACK_SYNC:1,SPICE_MSGC_ACK:2,SPICE_MSGC_PONG:3,SPICE_MSGC_MIGRATE_FLUSH_MARK:4,SPICE_MSGC_MIGRATE_DATA:5,SPICE_MSGC_DISCONNECTING:6,SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE:105,SPICE_MSGC_DISPLAY_INIT:101,SPICE_MSGC_END_DISPLAY:102,SPICE_CHANNEL_MAIN:1,SPICE_CHANNEL_DISPLAY:2,SPICE_CHANNEL_INPUTS:3,SPICE_CHANNEL_CURSOR:4,SPICE_CHANNEL_PLAYBACK:5,SPICE_CHANNEL_RECORD:6,SPICE_CHANNEL_TUNNEL:7,SPICE_CHANNEL_SMARTCARD:8,SPICE_CHANNEL_USBREDIR:9,SPICE_END_CHANNEL:10,SPICE_MSG_MIGRATE:1,SPICE_MSG_MIGRATE_DATA:2,SPICE_MSG_SET_ACK:3,SPICE_MSG_PING:4,SPICE_MSG_WAIT_FOR_CHANNELS:5,SPICE_MSG_DISCONNECTING:6,SPICE_MSG_NOTIFY:7,SPICE_MSG_LIST:8,SPICE_MSGC_MAIN_CLIENT_INFO:101,SPICE_MSGC_MAIN_MIGRATE_CONNECTED:102,SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR:103,SPICE_MSGC_MAIN_ATTACH_CHANNELS:104,SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST:105,SPICE_MSGC_MAIN_AGENT_START:106,SPICE_MSGC_MAIN_AGENT_DATA:107,SPICE_MSGC_MAIN_AGENT_TOKEN:108,SPICE_MSGC_MAIN_MIGRATE_END:109,SPICE_MSGC_END_MAIN:110,SPICE_MSG_DISPLAY_MODE:101,SPICE_MSG_DISPLAY_MARK:102,SPICE_MSG_DISPLAY_RESET:103,SPICE_MSG_DISPLAY_COPY_BITS:104,SPICE_MSG_DISPLAY_INVAL_LIST:105,SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS:106,SPICE_MSG_DISPLAY_INVAL_PALETTE:107,SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES:108,SPICE_MSG_DISPLAY_STREAM_CREATE:122,SPICE_MSG_DISPLAY_STREAM_DATA:123,SPICE_MSG_DISPLAY_STREAM_CLIP:124,SPICE_MSG_DISPLAY_STREAM_DESTROY:125,SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL:126,SPICE_MSG_DISPLAY_CURRENT_VIDEO_ENCODE_SETUP_RESPONSE:131,SPICE_MSG_DISPLAY_STREAM_DATA_SIZED:316,SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT:319,SPICE_MSG_DISPLAY_DRAW_FILL:302,SPICE_MSG_DISPLAY_DRAW_OPAQUE:303,SPICE_MSG_DISPLAY_DRAW_COPY:304,SPICE_MSG_DISPLAY_DRAW_BLEND:305,SPICE_MSG_DISPLAY_DRAW_BLACKNESS:306,SPICE_MSG_DISPLAY_DRAW_WHITENESS:307,SPICE_MSG_DISPLAY_DRAW_INVERS:308,SPICE_MSG_DISPLAY_DRAW_ROP3:309,SPICE_MSG_DISPLAY_DRAW_STROKE:310,SPICE_MSG_DISPLAY_DRAW_TEXT:311,SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:312,SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:313,SPICE_MSG_DISPLAY_SURFACE_CREATE:314,SPICE_MSG_DISPLAY_SURFACE_DESTROY:315,SPICE_MSG_END_DISPLAY:316,SPICE_MSG_INPUTS_INIT:101,SPICE_MSG_INPUTS_KEY_MODIFIERS:102,SPICE_MSG_INPUTS_MOUSE_MOTION_ACK:111,SPICE_MSG_END_INPUTS:112,SPICE_MSGC_INPUTS_KEY_DOWN:101,SPICE_MSGC_INPUTS_KEY_UP:102,SPICE_MSGC_INPUTS_KEY_MODIFIERS:103,SPICE_MSGC_INPUTS_MOUSE_MOTION:111,SPICE_MSGC_INPUTS_MOUSE_POSITION:112,SPICE_MSGC_INPUTS_MOUSE_PRESS:113,SPICE_MSGC_INPUTS_MOUSE_RELEASE:114,SPICE_MSGC_END_INPUTS:115,SPICE_MSG_CURSOR_INIT:101,SPICE_MSG_CURSOR_RESET:102,SPICE_MSG_CURSOR_SET:103,SPICE_MSG_CURSOR_MOVE:104,SPICE_MSG_CURSOR_HIDE:105,SPICE_MSG_CURSOR_TRAIL:106,SPICE_MSG_CURSOR_INVAL_ONE:107,SPICE_MSG_CURSOR_INVAL_ALL:108,SPICE_MSG_END_CURSOR:109,SPICE_MSG_RECORD_START:101,SPICE_MSG_RECORD_STOP:102,SPICE_MSG_RECORD_VOLUME:103,SPICE_MSG_RECORD_MUTE:104,SPICE_MSG_END_RECORD:105,SPICE_MSGC_SMARTCARD_DATA:101,SPICE_MSGC_END_SMARTCARD:102,SPICE_MSGC_SPICEVMC_DATA:101,SPICE_MSGC_END_SPICEVMC:102,SPICE_MSG_MAIN_MIGRATE_BEGIN:101,SPICE_MSG_MAIN_MIGRATE_CANCEL:102,SPICE_MSG_MAIN_INIT:103,SPICE_MSG_MAIN_CHANNELS_LIST:104,SPICE_MSG_MAIN_MOUSE_MODE:105,SPICE_MSG_MAIN_MULTI_MEDIA_TIME:106,SPICE_MSG_MAIN_AGENT_CONNECTED:107,SPICE_MSG_MAIN_AGENT_DISCONNECTED:108,SPICE_MSG_MAIN_AGENT_DATA:109,SPICE_MSG_MAIN_AGENT_TOKEN:110,SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST:111,SPICE_MSG_MAIN_MIGRATE_END:112,SPICE_MSG_END_MAIN:113,SPICE_MSG_PLAYBACK_DATA:101,SPICE_MSG_PLAYBACK_MODE:102,SPICE_MSG_PLAYBACK_START:103,SPICE_MSG_PLAYBACK_STOP:104,SPICE_MSG_PLAYBACK_VOLUME:105,SPICE_MSG_PLAYBACK_MUTE:106,SPICE_MSG_END_PLAYBACK:107,SPICE_MSGC_RECORD_DATA:101,SPICE_MSGC_RECORD_MODE:102,SPICE_MSGC_RECORD_START_MARK:103,SPICE_MSGC_END_RECORD:104,SPICE_MSG_TUNNEL_INIT:101,SPICE_MSG_TUNNEL_SERVICE_IP_MAP:102,SPICE_MSG_TUNNEL_SOCKET_OPEN:103,SPICE_MSG_TUNNEL_SOCKET_FIN:104,SPICE_MSG_TUNNEL_SOCKET_CLOSE:105,SPICE_MSG_TUNNEL_SOCKET_DATA:106,SPICE_MSG_TUNNEL_SOCKET_CLOSED_ACK:107,SPICE_MSG_TUNNEL_SOCKET_TOKEN:108,SPICE_MSG_END_TUNNEL:109,SPICE_MSGC_TUNNEL_SERVICE_ADD:101,SPICE_MSGC_TUNNEL_SERVICE_REMOVE:102,SPICE_MSGC_TUNNEL_SOCKET_OPEN_ACK:103,SPICE_MSGC_TUNNEL_SOCKET_OPEN_NACK:104,SPICE_MSGC_TUNNEL_SOCKET_FIN:105,SPICE_MSGC_TUNNEL_SOCKET_CLOSED:106,SPICE_MSGC_TUNNEL_SOCKET_CLOSED_ACK:107,SPICE_MSGC_TUNNEL_SOCKET_DATA:108,SPICE_MSGC_TUNNEL_SOCKET_TOKEN:109,SPICE_MSGC_END_TUNNEL:110,SPICE_MSG_SMARTCARD_DATA:101,SPICE_MSG_END_SMARTCARD:102,SPICE_MSG_SPICEVMC_DATA:101,SPICE_MSG_END_SPICEVMC:102,SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION:0,SPICE_COMMON_CAP_AUTH_SPICE:1,SPICE_COMMON_CAP_AUTH_SASL:2,SPICE_COMMON_CAP_MINI_HEADER:3,SPICE_PLAYBACK_CAP_CELT_0_5_1:0,SPICE_PLAYBACK_CAP_VOLUME:1,SPICE_RECORD_CAP_CELT_0_5_1:0,SPICE_RECORD_CAP_VOLUME:1,SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE:0},wdi.SpiceTunnelServiceType={SPICE_TUNNEL_SERVICE_TYPE_INVALID:0,SPICE_TUNNEL_SERVICE_TYPE_GENERIC:1,SPICE_TUNNEL_SERVICE_TYPE_IPP:2,SPICE_TUNNEL_SERVICE_TYPE_ENUM_END:3},wdi.SpiceJpegAlphaFlags={SPICE_JPEG_ALPHA_FLAGS_TOP_DOWN:1,SPICE_JPEG_ALPHA_FLAGS_MASK:1},wdi.SpiceMaskFlags={SPICE_MASK_FLAGS_INVERS:1,SPICE_MASK_FLAGS_MASK:1},wdi.SpiceCursorType={SPICE_CURSOR_TYPE_ALPHA:0,SPICE_CURSOR_TYPE_MONO:1,SPICE_CURSOR_TYPE_COLOR4:2,SPICE_CURSOR_TYPE_COLOR8:3,SPICE_CURSOR_TYPE_COLOR16:4,SPICE_CURSOR_TYPE_COLOR24:5,SPICE_CURSOR_TYPE_COLOR32:6,SPICE_CURSOR_TYPE_ENUM_END:7,SPICE_CURSOR_TYPE_URL:8},wdi.SpiceImageFlags={SPICE_IMAGE_FLAGS_CACHE_ME:1,SPICE_IMAGE_FLAGS_HIGH_BITS_SET:2,SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME:4,SPICE_IMAGE_FLAGS_MASK:7},wdi.SpiceAudioDataMode={SPICE_AUDIO_DATA_MODE_INVALID:0,SPICE_AUDIO_DATA_MODE_RAW:1,SPICE_AUDIO_DATA_MODE_CELT_0_5_1:2,SPICE_AUDIO_DATA_MODE_ENUM_END:3},wdi.SpiceAudioFmt={SPICE_AUDIO_FMT_INVALID:0,SPICE_AUDIO_FMT_S16:1,SPICE_AUDIO_FMT_ENUM_END:2},wdi.SpiceBitmapFmt={SPICE_BITMAP_FMT_INVALID:0,SPICE_BITMAP_FMT_1BIT_LE:1,SPICE_BITMAP_FMT_1BIT_BE:2,SPICE_BITMAP_FMT_4BIT_LE:3,SPICE_BITMAP_FMT_4BIT_BE:4,SPICE_BITMAP_FMT_8BIT:5,SPICE_BITMAP_FMT_16BIT:6,SPICE_BITMAP_FMT_24BIT:7,SPICE_BITMAP_FMT_32BIT:8,SPICE_BITMAP_FMT_RGBA:9,SPICE_BITMAP_FMT_ENUM_END:10},wdi.SpiceStreamFlags={SPICE_STREAM_FLAGS_TOP_DOWN:1,SPICE_STREAM_FLAGS_MASK:1},wdi.SpiceTunnelIpType={SPICE_TUNNEL_IP_TYPE_INVALID:0,SPICE_TUNNEL_IP_TYPE_IPv4:1,SPICE_TUNNEL_IP_TYPE_ENUM_END:2},wdi.SpiceBitmapFlags={SPICE_BITMAP_FLAGS_PAL_CACHE_ME:1,SPICE_BITMAP_FLAGS_PAL_FROM_CACHE:2,SPICE_BITMAP_FLAGS_TOP_DOWN:4,SPICE_BITMAP_FLAGS_MASK:7},wdi.SpiceStringFlags={SPICE_STRING_FLAGS_RASTER_A1:1,SPICE_STRING_FLAGS_RASTER_A4:2,SPICE_STRING_FLAGS_RASTER_A8:4,SPICE_STRING_FLAGS_RASTER_TOP_DOWN:8,SPICE_STRING_FLAGS_MASK:15},wdi.SpiceSurfaceFmt={SPICE_SURFACE_FMT_INVALID:0,SPICE_SURFACE_FMT_1_A:1,SPICE_SURFACE_FMT_8_A:8,SPICE_SURFACE_FMT_16_555:16,SPICE_SURFACE_FMT_32_xRGB:32,SPICE_SURFACE_FMT_16_565:80,SPICE_SURFACE_FMT_32_ARGB:96,SPICE_SURFACE_FMT_ENUM_END:97},wdi.SpiceCursorFlags={SPICE_CURSOR_FLAGS_NONE:1,SPICE_CURSOR_FLAGS_CACHE_ME:2,SPICE_CURSOR_FLAGS_FROM_CACHE:4,SPICE_CURSOR_FLAGS_MASK:7},wdi.SpiceLinkErr={SPICE_LINK_ERR_OK:0,SPICE_LINK_ERR_ERROR:1,SPICE_LINK_ERR_INVALID_MAGIC:2,SPICE_LINK_ERR_INVALID_DATA:3,SPICE_LINK_ERR_VERSION_MISMATCH:4,SPICE_LINK_ERR_NEED_SECURED:5,SPICE_LINK_ERR_NEED_UNSECURED:6,SPICE_LINK_ERR_PERMISSION_DENIED:7,SPICE_LINK_ERR_BAD_CONNECTION_ID:8,SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE:9,SPICE_LINK_ERR_ENUM_END:10},wdi.SpiceNotifySeverity={SPICE_NOTIFY_SEVERITY_INFO:0,SPICE_NOTIFY_SEVERITY_WARN:1,SPICE_NOTIFY_SEVERITY_ERROR:2,SPICE_NOTIFY_SEVERITY_ENUM_END:3},wdi.SpiceBrushType={SPICE_BRUSH_TYPE_NONE:0,SPICE_BRUSH_TYPE_SOLID:1,SPICE_BRUSH_TYPE_PATTERN:2,SPICE_BRUSH_TYPE_ENUM_END:3},wdi.SpiceAlphaFlags={SPICE_ALPHA_FLAGS_DEST_HAS_ALPHA:1,SPICE_ALPHA_FLAGS_SRC_SURFACE_HAS_ALPHA:2,SPICE_ALPHA_FLAGS_MASK:3},wdi.SpiceSurfaceFlags={SPICE_SURFACE_FLAGS_PRIMARY:1,SPICE_SURFACE_FLAGS_MASK:1},wdi.QuicImageType={QUIC_IMAGE_TYPE_INVALID:0,QUIC_IMAGE_TYPE_GRAY:1,QUIC_IMAGE_TYPE_RGB16:2,QUIC_IMAGE_TYPE_RGB24:3,QUIC_IMAGE_TYPE_RGB32:4,QUIC_IMAGE_TYPE_RGBA:5},wdi.SpiceImageType={SPICE_IMAGE_TYPE_BITMAP:0,SPICE_IMAGE_TYPE_QUIC:1,SPICE_IMAGE_TYPE_RESERVED:2,SPICE_IMAGE_TYPE_LZ_PLT:100,SPICE_IMAGE_TYPE_LZ_RGB:101,SPICE_IMAGE_TYPE_GLZ_RGB:102,SPICE_IMAGE_TYPE_FROM_CACHE:103,SPICE_IMAGE_TYPE_SURFACE:104,SPICE_IMAGE_TYPE_JPEG:105,SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:106,SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB:107,SPICE_IMAGE_TYPE_JPEG_ALPHA:108,SPICE_IMAGE_TYPE_CANVAS:109,SPICE_IMAGE_TYPE_PNG:110,SPICE_IMAGE_TYPE_ENUM_END:111},wdi.SpiceImageScaleMode={SPICE_IMAGE_SCALE_MODE_INTERPOLATE:0,SPICE_IMAGE_SCALE_MODE_NEAREST:1,SPICE_IMAGE_SCALE_MODE_ENUM_END:2},wdi.SpiceResourceType={SPICE_RES_TYPE_INVALID:0,SPICE_RES_TYPE_PIXMAP:1,SPICE_RESOURCE_TYPE_ENUM_END:2},wdi.SpicePathFlags={SPICE_PATH_BEGIN:1,SPICE_PATH_END:2,SPICE_PATH_CLOSE:8,SPICE_PATH_BEZIER:16,SPICE_PATH_FLAGS_MASK:27},wdi.SpiceVideoCodecType={SPICE_VIDEO_CODEC_TYPE_MJPEG:1,SPICE_VIDEO_CODEC_TYPE_VP8:2,SPICE_VIDEO_CODEC_TYPE_H264:3,SPICE_VIDEO_CODEC_TYPE_VP9:4,SPICE_VIDEO_CODEC_TYPE_H265:5,SPICE_VIDEO_CODEC_TYPE_ENUM_END:2},wdi.SpiceVideoCodecValue={1:"",2:"vp8",3:"avc1.64001f",4:"vp09.00.31.08",5:"hvc1.1.6.L93.90"},wdi.SpiceRopd={SPICE_ROPD_INVERS_SRC:1,SPICE_ROPD_INVERS_BRUSH:2,SPICE_ROPD_INVERS_DEST:4,SPICE_ROPD_OP_PUT:8,SPICE_ROPD_OP_OR:16,SPICE_ROPD_OP_AND:32,SPICE_ROPD_OP_XOR:64,SPICE_ROPD_OP_BLACKNESS:128,SPICE_ROPD_OP_WHITENESS:256,SPICE_ROPD_OP_INVERS:512,SPICE_ROPD_INVERS_RES:1024,SPICE_ROPD_MASK:2047},wdi.SpiceMigrateFlags={SPICE_MIGRATE_NEED_FLUSH:1,SPICE_MIGRATE_NEED_DATA_TRANSFER:2,SPICE_MIGRATE_FLAGS_MASK:3},wdi.SpiceKeyboardModifierFlags={SPICE_KEYBOARD_MODIFIER_FLAGS_SCROLL_LOCK:1,SPICE_KEYBOARD_MODIFIER_FLAGS_NUM_LOCK:2,SPICE_KEYBOARD_MODIFIER_FLAGS_CAPS_LOCK:4,SPICE_KEYBOARD_MODIFIER_FLAGS_MASK:7},wdi.SpiceInfoCode={SPICE_INFO_GENERAL:0,SPICE_INFO_CODE_ENUM_END:1},wdi.SpiceMouseButton={SPICE_MOUSE_BUTTON_INVALID:0,SPICE_MOUSE_BUTTON_LEFT:1,SPICE_MOUSE_BUTTON_MIDDLE:2,SPICE_MOUSE_BUTTON_RIGHT:3,SPICE_MOUSE_BUTTON_UP:4,SPICE_MOUSE_BUTTON_DOWN:5,SPICE_MOUSE_BUTTON_ENUM_END:6},wdi.SpiceClipType={SPICE_CLIP_TYPE_NONE:0,SPICE_CLIP_TYPE_RECTS:1,SPICE_CLIP_TYPE_ENUM_END:2},wdi.SpiceMouseButtonMask={SPICE_MOUSE_BUTTON_MASK_LEFT:1,SPICE_MOUSE_BUTTON_MASK_MIDDLE:2,SPICE_MOUSE_BUTTON_MASK_RIGHT:4,SPICE_MOUSE_BUTTON_MASK_MASK:7},wdi.SpiceMouseModeTypes={SPICE_MOUSE_MODE_SERVER:1,SPICE_MOUSE_MODE_CLIENT:2,SPICE_MOUSE_MODE_MASK:3},wdi.SpiceDisplayCaps={SPICE_DISPLAY_CAP_SIZED_STREAM:0,SPICE_DISPLAY_CAP_MONITORS_CONFIG:1,SPICE_DISPLAY_CAP_COMPOSITE:2,SPICE_DISPLAY_CAP_A8_SURFACE:3,SPICE_DISPLAY_CAP_STREAM_REPORT:4,SPICE_DISPLAY_CAP_LZ4_COMPRESSION:5,SPICE_DISPLAY_CAP_PREF_COMPRESSION:6,SPICE_DISPLAY_CAP_GL_SCANOUT:7,SPICE_DISPLAY_CAP_MULTI_CODEC:8,SPICE_DISPLAY_CAP_CODEC_MJPEG:9,SPICE_DISPLAY_CAP_CODEC_VP8:10,SPICE_DISPLAY_CAP_CODEC_H264:11,SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE:12,SPICE_DISPLAY_CAP_CODEC_VP9:13,SPICE_DISPLAY_CAP_CODEC_H265:14},wdi.AgentCaps={VD_AGENT_CAP_MOUSE_STATE:0,VD_AGENT_CAP_MONITORS_CONFIG:1,VD_AGENT_CAP_REPLY:2,VD_AGENT_CAP_CLIPBOARD:3,VD_AGENT_CAP_DISPLAY_CONFIG:4,VD_AGENT_CAP_CLIPBOARD_BY_DEMAND:5,VD_AGENT_CAP_CLIPBOARD_SELECTION:6},wdi.AgentMessageTypes={VD_AGENT_MOUSE_STATE:1,VD_AGENT_MONITORS_CONFIG:2,VD_AGENT_REPLY:3,VD_AGENT_CLIPBOARD:4,VD_AGENT_DISPLAY_CONFIG:5,VD_AGENT_ANNOUNCE_CAPABILITIES:6,VD_AGENT_CLIPBOARD_GRAB:7,VD_AGENT_CLIPBOARD_REQUEST:8,VD_AGENT_CLIPBOARD_RELEASE:9,VD_AGENT_GET_WINDOWS_LIST:10,VD_AGENT_CLOSE_WINDOW:11,VD_AGENT_MOVE_WINDOW:12,VD_AGENT_RESIZE_WINDOW:13,VD_AGENT_MINIMIZE_WINDOW:14,VD_AGENT_RESTORE_WINDOW:15,VD_AGENT_MAXIMIZE_WINDOW:16,VD_AGENT_FOCUS_WINDOW:17,VD_AGENT_EXECUTE_COMMAND:18},wdi.ClipBoardTypes={VD_AGENT_CLIPBOARD_NONE:0,VD_AGENT_CLIPBOARD_UTF8_TEXT:1,VD_AGENT_CLIPBOARD_IMAGE_PNG:2,VD_AGENT_CLIPBOARD_IMAGE_BMP:3,VD_AGENT_CLIPBOARD_IMAGE_TIFF:4,VD_AGENT_CLIPBOARD_IMAGE_JPG:5};wdi.GraphicDebug=$.spcExtend(wdi.DomainObject,{debugMode:null,spiceGraphicMessageTypes:[],cloneSpiceMessage:null,clientGui:null,tmpCanvas:null,tmpContext:null,originalCanvas:null,spiceMessageData:null,endCanvas:null,currentOperation:null,init:function(e){this.debugMode=e.debugMode,this.debugMode?(this._generateArray(),this._showDebug()):this._hideDebug()},_generateArray:function(){var e=this;$.each(wdi.SpiceVars,(function(a,t){-1!=a.search("SPICE_MSG_DISPLAY_")&&(e.spiceGraphicMessageTypes[t]=a)}))},_showDebug:function(){$("#canvasSpace").show(),$("#graphicDebug").show()},_hideDebug:function(){$("#canvasSpace").hide(),$("#graphicDebug").hide()},printDebugMessageOnFilter:function(e,a){if(e.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY&&this.debugMode&&$("#logActive").prop("checked")){var t=null;if(this.clientGui=a,this.cloneSpiceMessage=$.extend(!0,{},e),this.cloneSpiceMessage.args.base&&null!==this.cloneSpiceMessage.args.base.surface_id){t=this.cloneSpiceMessage.args.base.surface_id;var i=wdi.graphics.getBoxFromSrcArea(this.cloneSpiceMessage.args.base.box),s=$("<div/>").append(prettyPrint(this.cloneSpiceMessage)).hide();this.originalCanvas=this._copyCanvasFromSurfaceId(t),this.spiceMessageData=e.args.originalData,this.currentOperation=this.spiceGraphicMessageTypes[this.cloneSpiceMessage.messageType],$("#debugInfo").append($("<br/>")).append($("<hr/>")).append(this._copyAndHighlightCanvas(t,i)).append($("<br/>")).append($("<div/>").append(this.currentOperation+" (Click to hide/show)").css("cursor","pointer").css("color","blue").css("text-decoration","underline").click((function(){s.toggle()}))).append(s),this.cloneSpiceMessage.args.hasOwnProperty("image")&&this._printImage(s)}}},_printImage:function(e){wdi.graphics.getImageFromSpice(this.cloneSpiceMessage.args.image.imageDescriptor,this.cloneSpiceMessage.args.image.data,this.clientGui,(function(a){a&&e.append($("<div/>").css("font-size","12px").append("Image inside spiceMessage:").append($("<br/>")).css("border","1px solid black").append(a))}),this)},handleStreamInfo:function(){if(wdi.Stream.streams){$("#debug-stream").text("");for(let e in wdi.Stream.streams){const a=wdi.Stream.streams[e];a&&$("#debug-stream").append(`<p style="color: rgb(100, 255, 100)">Codec: ${a.codec} | Stream ID: ${a.id}</p>`)}}},printDebugMessageOnNotifyEnd:function(e,a){if(this.clientGui=a,e.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY&&this.debugMode&&$("#logActive").prop("checked")){var t=null;if(e.args.base&&null!==e.args.base.surface_id){var i=this;t=e.args.base.surface_id;var s=wdi.graphics.getBoxFromSrcArea(e.args.base.box),n=this._copyCanvasFromSurfaceId(t);$("#debugInfo").append($("<br/>")).append($("<div/>").append($("<button>Create test</button>").css("cursor","pointer").click((r=this.spiceMessageData,c=this.originalCanvas,o=n,p=this.currentOperation,function(){i.createImageTest(r,c,o,p)}))).append($("<button>Create replay window</button>").css("cursor","pointer").click(function(e,a,t,s){return function(){i.createReplay(e,a,t,s)}}(this.spiceMessageData,this.originalCanvas,n,this.currentOperation)))).append($("<br/>")).append(this._copyAndHighlightCanvas(t,s))}}var r,c,o,p},createImageTest:function(e,a,t,i){var s=prompt("Name of the test",i),n={origin:a.toDataURL("image/png"),expected:t.toDataURL("image/png"),object:e,name:s},r=JSON.stringify(n),c=s.replace(/\s/g,"_");$.post("graphictestgenerator.php","data="+r+"&name="+c).done((function(e,a,t){alert("Test created")})).fail((function(e,a,t){alert("Test creation failed.\n\nGot response: "+e.status+" "+e.statusText+"\n\n"+e.responseText)}))},createReplay:function(e,a){var t={origin:a.toDataURL("image/png"),object:e,width:a.width,height:a.height},i=JSON.stringify(t);$.post("graphictestgenerator.php","data="+i+"&replay=true").done((function(e,a,t){window.open("replay.html","replay")})).fail((function(e,a,t){alert("Replay failed.\n\nGot response: "+e.status+" "+e.statusText+"\n\n"+e.responseText)}))},_copyCanvasFromSurfaceId:function(e){var a=this.clientGui.getContext(e);this.tmpCanvas=a.canvas;var t=document.createElement("canvas");return t.width=this.tmpCanvas.width,t.height=this.tmpCanvas.height,t.getContext("2d").drawImage(this.tmpCanvas,0,0),t},_copyAndHighlightCanvas:function(e,a){var t=this._copyCanvasFromSurfaceId(e);return context=t.getContext("2d"),context.fillStyle="rgba(255,0,0,0.3)",context.fillRect(a.x,a.y,a.width,a.height),t}});wdi.LZSS={LZ_IMAGE_TYPE_INVALID:0,LZ_IMAGE_TYPE_PLT1_LE:1,LZ_IMAGE_TYPE_PLT1_BE:2,LZ_IMAGE_TYPE_PLT4_LE:3,LZ_IMAGE_TYPE_PLT4_BE:4,LZ_IMAGE_TYPE_PLT8:5,LZ_IMAGE_TYPE_RGB16:6,LZ_IMAGE_TYPE_RGB24:7,LZ_IMAGE_TYPE_RGB32:8,LZ_IMAGE_TYPE_RGBA:9,LZ_IMAGE_TYPE_XXXA:10,LZPALETTE_FLAG_PAL_CACHE_ME:1,LZPALETTE_FLAG_PAL_FROM_CACHE:2,LZPALETTE_FLAG_TOP_DOWN:4,PLT_PIXELS_PER_BYTE:[0,8,8,2,2,1],PLT1_MASK:[1,2,4,8,16,32,64,128],copy_pixel:function(e,i,_){_[e+0]=i.r,_[e+1]=i.g,_[e+2]=i.b},lz_rgb32_decompress_rgb:function(e){var i,_=0,t=0,s=new Uint8Array(e),p=(s[_++],s[_++]),E=s[_++],c=s[++_+1]*Math.pow(16,2)+s[_],o=s[(_+=2)+1]*Math.pow(16,2)+s[_];_+=2;var T,r,l=o*Math.pow(16,4)+c,L=new ArrayBuffer(l),P=new Uint8Array(L),a=new Uint32Array(L),h=l/4;for(i=s[_++];t<h;i=s[_++])if(A=t,l=i>>5,I=(31&i)<<8,i>31){if(6===--l)do{l+=b=s[_++]}while(255===b);if(I+=b=s[_++],255===b&&I-b==7936&&(I=s[_++]<<8,I+=s[_++],I+=8191),l+=1,(A-=I+=1)===t-1)for(r=4*(f=A);l;--l)a[t]=255<<24|P[r+2]<<16|P[r+1]<<8|P[r],t++;else for(;l;--l)T=4*A,a[t]=255<<24|P[T+2]<<16|P[T+1]<<8|P[T],t++,A++}else for(i++,a[t]=255<<24|s[_]<<16|s[_+1]<<8|s[_+2],_+=3,t++,--i;i;i--)a[t]=255<<24|s[_]<<16|s[_+1]<<8|s[_+2],_+=3,t++;if(E===this.LZ_IMAGE_TYPE_RGBA&&!p)for(t=0,i=null,_--,i=s[_++];t<h;i=s[_++]){var A=t,I=(l=i>>5,(31&i)<<8),n=4*t;if(i>=32){var b;if(6===--l)do{l+=b=s[_++]}while(255===b);if(I+=b=s[_++],255===b&&I-b==7936&&(I=s[_++]<<8,I+=s[_++],I+=8191),l+=3,(A-=I+=1)===t-1)for(var f=A;l;--l)P[(n=4*t)+3]=P[4*f+3],t++;else for(;l;--l)P[(n=4*t)+3]=P[4*A+3],t++,A++}else for(i++,P[n+3]=s[_++],t++,--i;i;i--)P[(n=4*t)+3]=s[_++],t++}return L},lz_rgb32_decompress:function(e,i,_,t,s,p,E){var c,o=i,T=0,r=_.length/4,l=t===this.LZ_IMAGE_TYPE_RGBA;for(c=e[o++];T<r;c=e[o++]){var L=T,P=c>>5,a=(31&c)<<8,h=4*T;if(c>=32){var A;if(6===--P)do{P+=A=e[o++]}while(255===A);if(a+=A=e[o++],255===A&&a-A==7936&&(a=e[o++]<<8,a+=e[o++],a+=8191),P+=1,(l||p)&&(P+=2),a+=1,t===this.LZ_IMAGE_TYPE_PLT4_LE||t===this.LZ_IMAGE_TYPE_PLT4_BE?(a*=2,P*=2):t!==this.LZ_IMAGE_TYPE_PLT1_BE&&t!==this.LZ_IMAGE_TYPE_PLT1_LE||(a*=8,P*=8),(L-=a)===T-1)for(var I=L;P;--P){if(h=4*T,l)_[h+3]=E?255:_[4*I+3];else for(var n=0;n<4;n++)_[h+n]=_[4*I+n];T++}else for(;P;--P){if(h=4*T,l)_[h+3]=E?255:_[4*L+3];else for(n=0;n<4;n++)_[h+n]=_[4*L+n];T++,L++}}else{if(c++,l)E?(_[h+3]=255,o++):_[h+3]=e[o++];else if(p){if(t===this.LZ_IMAGE_TYPE_PLT1_LE){var b=e[o++],f=p[1],d=p[0];for(n=0;n<8;n++)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n<7&&T++,h=4*T}else if(t===this.LZ_IMAGE_TYPE_PLT1_BE)for(b=e[o++],f=p[1],d=p[0],n=7;n>=0;n--)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n>0&&T++,h=4*T;else if(t===this.LZ_IMAGE_TYPE_PLT4_LE){var w=p[15&(b=e[o++])];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[b>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT4_BE){var y=15&(b=e[o++]);w=p[b>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[y];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT8){w=p[e[o++]];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}}else _[h+0]=e[o+2],_[h+1]=e[o+1],_[h+2]=e[o+0],s&&(_[h+3]=255),o+=3;for(T++,--c;c;c--){if(h=4*T,l)_[h+3]=E?255:e[o++];else if(p){if(t===this.LZ_IMAGE_TYPE_PLT1_LE)for(b=e[o++],f=p[1],d=p[0],n=0;n<8;n++)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n<7&&T++,h=4*T;else if(t===this.LZ_IMAGE_TYPE_PLT1_BE)for(b=e[o++],f=p[1],d=p[0],n=7;n>=0;n--)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n>0&&T++,h=4*T;else if(t===this.LZ_IMAGE_TYPE_PLT4_LE){w=p[15&(b=e[o++])];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[b>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT4_BE){w=p[(b=e[o++])>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[15&b];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT8){w=p[e[o++]];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}}else _[h+0]=e[o+2],_[h+1]=e[o+1],_[h+2]=e[o+0],s&&(_[h+3]=255),o+=3;T++}}}return o-1},convert_spice_lz_to_web:function(e,i,_,t){var s=_.type;if(i=i.toJSArray(),s===wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_PLT){var p=wdi.SpiceObject.bytesToInt8(i.splice(0,1));if(p===this.LZPALETTE_FLAG_PAL_FROM_CACHE){var E=i.splice(0,12),c=(wdi.SpiceObject.bytesToInt32(E.splice(0,4)),wdi.SpiceObject.bytesToInt64(E.splice(0,8)));E=i;wdi.SpiceObject.bytesToStringBE(E.splice(0,4)),wdi.SpiceObject.bytesToInt32BE(E.splice(0,4));var o=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),T=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),r=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),l=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),L=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4))}else if(p===this.LZPALETTE_FLAG_PAL_CACHE_ME){for(var P=_.offset+1,a=(E=i.splice(0,36),wdi.SpiceObject.bytesToInt32(E.splice(0,4)),wdi.SpiceObject.bytesToInt32(E.splice(0,4))-P-36),h=(wdi.SpiceObject.bytesToStringBE(E.splice(0,4)),wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),o=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),T=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),r=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),l=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),L=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),c=wdi.SpiceObject.bytesToInt64(i.splice(a,8)),wdi.SpiceObject.bytesToInt16(i.splice(a,2))),A=[],I=0;I<h;I++){var n=new wdi.Queue;n.setData(i.splice(a,4)),A.push((new wdi.SpiceColor).demarshall(n))}wdi.ImageCache.addPalette(c,A)}else wdi.Debug.error("Unimplemented lz palette top down");A=wdi.ImageCache.getPalette(c)}if(o!==this.LZ_IMAGE_TYPE_RGB32&&o!==this.LZ_IMAGE_TYPE_RGBA&&o!==this.LZ_IMAGE_TYPE_RGB24&&o!==this.LZ_IMAGE_TYPE_PLT8&&o!==this.LZ_IMAGE_TYPE_PLT1_LE&&o!==this.LZ_IMAGE_TYPE_PLT1_BE&&o!==this.LZ_IMAGE_TYPE_PLT4_LE&&o!==this.LZ_IMAGE_TYPE_PLT4_BE)return!1;if(A){var b=e.createImageData(l*this.PLT_PIXELS_PER_BYTE[o],r);this.lz_rgb32_decompress(i,0,b.data,o,o!==this.LZ_IMAGE_TYPE_RGBA,A);var f=wdi.graphics.getNewTmpCanvas(T,r);f.getContext("2d").putImageData(b,0,0,0,0,T,r),b=f}else{var d=new ArrayBuffer(i.length+8),w=new Uint8Array(d);w[0]=1,w[1]=t,w[2]=o,w[3]=0;var y=b.data.length;for(I=0;I<4;I++)w[4+I]=255&y,y>>=8;w.set(i,8);var G=new Uint8ClampedArray(this.lz_rgb32_decompress_rgb(d));b=new ImageData(G,T,r),b=wdi.graphics.getImageFromData(b)}return L||(b=wdi.RasterOperation.flip(b)),b},demarshall_rgb:function(e){var i=e.splice(0,32);return{length:wdi.SpiceObject.bytesToInt32(i.splice(0,4)),magic:wdi.SpiceObject.bytesToStringBE(i.splice(0,4)),version:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),type:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),width:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),height:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),stride:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),top_down:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4))}},lz_rgb32_plt1_be_decompress:function(e,i,_){var t,s,p,E,c,o,T,r,l,L,P=0,a=0,h=i.length/4,A=this.LZ_IMAGE_TYPE_PLT1_BE,I=this.PLT_PIXELS_PER_BYTE[A];for(t=e[P++];a<h;t=e[P++])if(s=a,p=t>>5,E=(31&t)<<8,t>31){if(7===p)do{p+=c=e[P++]}while(255===c);if(8191===(E+=e[P++])&&(E+=e[P++]<<8+e[P++]),p=(p+2)*I,(s-=(E+1)*I)===a-1)for(o=4*s;0!=p--;)op_4=4*a,i[op_4]=i[o],i[op_4+1]=i[o+1],i[op_4+2]=i[o+2],i[op_4+3]=i[o+3],a++;else for(;0!=p--;)op_4=4*a,o=4*s,i[op_4]=i[o],i[op_4+1]=i[o+1],i[op_4+2]=i[o+2],i[op_4+3]=i[o+3],a++,s++}else for(;-1!=t--;)for(op_4=4*a,T=e[P++],r=_[1],l=_[0],L=7;L>=0;L--)op_4=4*a,T&this.PLT1_MASK[L]?(i[op_4+0]=r.r,i[op_4+1]=r.g,i[op_4+2]=r.b):(i[op_4+0]=l.r,i[op_4+1]=l.g,i[op_4+2]=l.b),i[op_4+3]=255,a++}};function intToByteArray(t){let e=new Uint8Array(1);return e[0]=255&t,e}wdi.BMP2=$.spcExtend(wdi.SpiceObject,{objectSize:0,mapper:[0,1,1,4,4,8,16,24,32,32],init:function(t){var e,i,a,s,h=this.bytesToInt8(t),r=this.bytesToInt8(t),n=this.bytesToInt32(t),p=this.bytesToInt32(t),l=this.bytesToInt32(t),o=this.mapper[h],g=0;if(o<=8&&o>0){var m=[];if(1&r){this.bytesToInt32(t);e=t.length;var f,d=4*Math.pow(2,o)+8+2;for(e-=d,s=t.splice(e,d),a=this.bytesToInt64(s),g=this.bytesToInt16(s),i=0;i<4*g;i+=4)(f=new wdi.Queue).setData(s.slice(i,i+4)),m.push((new wdi.SpiceColor).demarshall(f));wdi.ImageCache.addPalette(a,m)}else{var I;for(a=this.bytesToInt64(t),e=t.length,s=[],g=(m=wdi.ImageCache.getPalette(a)).length,i=0;i<g;i++)(I=m[i].marshall()).push(0),s=s.concat(I)}}else this.bytesToInt32(t);this.setContent({imageSize:e,width:n,height:p,bpp:o,imageData:t,paletteSize:4*g,palette:m,stride:l,flags:r,type:h})},setContent:function(t){this.imageSize=t.imageSize,this.width=t.width,this.height=t.height,this.bpp=t.bpp,this.imageData=t.imageData,this.palette=t.palette,this.offset=t.paletteSize+54,this.size=this.offset+this.imageSize,this.stride=t.stride,this.flags=t.flags,this.type=9},marshall:function(t){var e,i,a,s,h,r,n=this.type,p=this.palette,l=this.width,o=this.height,g=this.stride,m=this.imageData,f=this.flags,d=m.length,I=8*g/this.bpp,w=new ArrayBuffer(4*I*o),T=new Uint8ClampedArray(w),c=new Uint32Array(w);m[1];if(p){if(s=0,n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_1BIT_BE){var b=(h=p[1]).r<<24|h.g<<16|h.b<<8|255,y=(h=p[0]).r<<24|h.g<<16|h.b<<8|255,B=[1,2,4,8,16,32,64,128];for(a=0;a<d;a++)for(e=m[a],i=7;i>=0;i--)c[s++]=e&B[i]?b:y}else if(n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_4BIT_BE)for(a=0;a<d;a++)h=p[(e=m[a])>>>4],c[s++]=h.r<<24|h.g<<16|h.b<<8|255,h=p[15&e],c[s++]=h.r<<24|h.g<<16|h.b<<8|255}else{if(n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_32BIT||n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_RGBA)for(a=0;a<d;a+=4){let t,e,i;t=m[a],e=m[a+1],i=m[a+2],m[a]=i,m[a+1]=e,m[a+2]=t,m[a+3]=255}else if(n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_24BIT)for(a=0;a<d;a+=3)r=m[a],m[a]=m[a+2],m[a+2]=r;T=new Uint8ClampedArray(m)}var S=new ImageData(T,I,o),_=wdi.graphics.getNewTmpCanvas(l,o);return _.getContext("2d").putImageData(S,0,0,0,0,l,o),S=_,!4&f&&(S=wdi.RasterOperation.flip(S)),S}});"use strict";var rfc2083_crc_table=Array(256),rfc2083_crc_table_computed=0;function rfc2083_make_crc_table(){var t,e,i;for(e=0;e<256;e++){for(t=e,i=0;i<8;i++)1&t?t=(3988292384^t>>>1)>>>0&4294967295:t>>>=1;rfc2083_crc_table[e]=t}rfc2083_crc_table_computed=1}function rfc2083_update_crc(t,e,i,r){var n,s=t;for(rfc2083_crc_table_computed||rfc2083_make_crc_table(),n=0;n<r;n++)s=rfc2083_crc_table[255&(s^e[i+n])]^s>>>8;return s}function rfc2083_crc(t,e,i){return 4294967295^rfc2083_update_crc(4294967295,t,e,i)}function crc32(t,e,i){return rfc2083_crc(new Uint8Array(t),e,i)}function PngIHDR(t,e){this.width=t,this.height=e,this.depth=8,this.type=6,this.compression=0,this.filter=0,this.interlace=0}function adler(){this.s1=1,this.s2=0}function PngIDAT(t,e,i){if(i.byteLength>65535)throw new Error("Cannot handle more than 64K");this.data=i,this.width=t,this.height=e}function PngIEND(){}function create_rgba_png(t,e,i){var r,n=new PngIHDR(t,e),s=new PngIDAT(t,e,i),c=new PngIEND,h=new ArrayBuffer(n.buffer_size()+s.buffer_size()+c.buffer_size()),f=n.to_buffer(h);f=s.to_buffer(h,f),f=c.to_buffer(h,f);var a=new Uint8Array(h),o="";for(r=0;r<f;r++)o+="%",a[r]<16&&(o+="0"),o+=a[r].toString(16);return"%89PNG%0D%0A%1A%0A"+o}PngIHDR.prototype={to_buffer:function(t,e){var i=e=e||0,r=new SpiceDataView(t);return r.setUint32(e,this.buffer_size()-12),e+=4,r.setUint8(e,"I".charCodeAt(0)),e++,r.setUint8(e,"H".charCodeAt(0)),e++,r.setUint8(e,"D".charCodeAt(0)),e++,r.setUint8(e,"R".charCodeAt(0)),e++,r.setUint32(e,this.width),e+=4,r.setUint32(e,this.height),e+=4,r.setUint8(e,this.depth),e++,r.setUint8(e,this.type),e++,r.setUint8(e,this.compression),e++,r.setUint8(e,this.filter),e++,r.setUint8(e,this.interlace),e++,r.setUint32(e,crc32(t,i+4,this.buffer_size()-8)),e+=4},buffer_size:function(){return 25}},adler.prototype.update=function(t){this.s1+=t,this.s1%=65521,this.s2+=this.s1,this.s2%=65521},PngIDAT.prototype={to_buffer:function(t,e){var i,r,n,s=e=e||0,c=new SpiceDataView(t),h=new adler;c.setUint32(e,this.buffer_size()-12),e+=4,c.setUint8(e,"I".charCodeAt(0)),e++,c.setUint8(e,"D".charCodeAt(0)),e++,c.setUint8(e,"A".charCodeAt(0)),e++,c.setUint8(e,"T".charCodeAt(0)),e++,c.setUint8(e,120),e++,c.setUint8(e,1),e++,c.setUint8(e,128),e++,c.setUint16(e,this.data.byteLength+this.height),e+=2,c.setUint16(e,~(this.data.byteLength+this.height)),e+=2;var f=new Uint8Array(this.data);for(n=0,r=0;r<this.height;r++)for(c.setUint8(e,0),e++,h.update(0),i=0;i<this.width&&n<this.data.byteLength;i++)h.update(f[n]),c.setUint8(e,f[n++]),e++,h.update(f[n]),c.setUint8(e,f[n++]),e++,h.update(f[n]),c.setUint8(e,f[n++]),e++,h.update(f[n]),c.setUint8(e,f[n++]),e++;return c.setUint16(e,h.s2),e+=2,c.setUint16(e,h.s1),e+=2,c.setUint32(e,crc32(t,s+4,this.buffer_size()-8)),e+=4},buffer_size:function(){return 12+this.data.byteLength+this.height+4+2+1+2+2}},PngIEND.prototype={to_buffer:function(t,e){var i=e=e||0,r=new SpiceDataView(t);return r.setUint32(e,this.buffer_size()-12),e+=4,r.setUint8(e,"I".charCodeAt(0)),e++,r.setUint8(e,"E".charCodeAt(0)),e++,r.setUint8(e,"N".charCodeAt(0)),e++,r.setUint8(e,"D".charCodeAt(0)),e++,r.setUint32(e,crc32(t,i+4,this.buffer_size()-8)),e+=4},buffer_size:function(){return 12}};wdi.RunQueue=$.spcExtend(wdi.DomainObject,{tasks:null,isRunning:!1,init:function(){this.tasks=[]},getTasksLength:function(){return this.tasks.length},add:function(n,s,i,t){return this.tasks.push({fn:n,scope:s,fnFinish:i,params:t}),this},clear:function(){return wdi.Debug.log("runqueue clear"),this.tasks=[],this},_process:function(){wdi.ExecutionControl.sync=!0;var n,s=this;this.isRunning=!0;var i=this.tasks.shift();if(i){n={end:function(){i.fnFinish&&i.fnFinish.call(i.scope),s._process()}};try{i.fn.call(i.scope,n,i.params)}catch(s){wdi.Debug.error(s.message),n.end()}return this}this.isRunning=!1},process:function(){this.isRunning||this._process()}}),wdi.ExecutionControl={currentProxy:null,sync:!0,runQ:new wdi.RunQueue};"undefined"==typeof CanvasPixelArray||CanvasPixelArray.prototype.set||(CanvasPixelArray.prototype.set=function(n){for(var t=n.length,r=0;r<t;r++)this[r]=n[r]}),wdi.graphics={tmpCanvas:document.createElement("canvas"),imageLoader:new Image,dispose:function(){wdi.Debug.log("Disposing graphics"),$(this.tmpCanvas).remove(),$(this.imageLoader).remove(),this.tmpCanvas=document.createElement("canvas"),this.imageLoader=new Image,wdi.GlobalPool.dispose(),wdi.ImageCache.dispose(),wdi.ImageUncompressor.dispose(),wdi.RasterOperation.dispose()},getRect:function(n,t){if(0===n.x&&0===n.y&&n.width===t.width&&n.height===t.height)return t;var r=this.getImageFromData(t),e=wdi.graphics.getNewTmpCanvas(n.width,n.height);return e.getContext("2d").drawImage(r,n.x,n.y,n.width,n.height,0,0,n.width,n.height),e},argbToImageData:function(n,t,r){for(var e=n.length,u=wdi.graphics.getTmpCanvas(t,r).getContext("2d").createImageData(t,r),i=0;i<e;i+=4)u.data[i]=n[i],u.data[i+1]=n[i+1],u.data[i+2]=n[i+2],u.data[i+3]=n[i+3];return u},align:function(n,t){return n+(t-1)&~(t-1)},monoMask:[1,2,4,8,16,32,64,128],monoToImageData:function(n,t,r){this.align(t,8);for(var e=n.length,u=e/2,i=wdi.graphics.getTmpCanvas(t,r).getContext("2d").createImageData(t,r),o=[],c=[],a=0;a<e;a++){var f=n[a],d=8;if(a>=u)for(;d--;){var g=f&this.monoMask[d]&&!0;o.push(g)}else if(a<u)for(;d--;){g=f&this.monoMask[d]&&!0;c.push(g)}}var s=0;for(u=c.length,a=0;a<u;a++)s=4*a,o[a]||c[a]?!o[a]&&c[a]?(i.data[s]=255,i.data[s+1]=255,i.data[s+2]=255,i.data[s+3]=0):o[a]&&!c[a]?(i.data[s]=255,i.data[s+1]=255,i.data[s+2]=255,i.data[s+3]=255):o[a]&&c[a]&&(i.data[s]=0,i.data[s+1]=0,i.data[s+2]=0,i.data[s+3]=255):(i.data[s]=0,i.data[s+1]=0,i.data[s+2]=0,i.data[s+3]=255);return i},drawJpeg:function(n,t,r,e){return this.drawBrowserImage(n,t,r,e,"jpeg",!1)},drawBrowserImage:function(n,t,r,e,u,i){var o,c,a=wdi.GlobalPool.create("Image");a.onload=function(){URL.revokeObjectURL(c);try{if(n.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME){var t=wdi.graphics.getTmpCanvas(this.width,this.height);t.getContext("2d").drawImage(this,0,0),wdi.ImageCache.addImage(n,t)}r.call(e,this)}catch(n){wdi.Debug.error(n.message)}finally{wdi.ExecutionControl.currentProxy.end()}},a.onerror=function(){URL.revokeObjectURL(c),wdi.Debug.error("failed to load JPEG image"),wdi.ExecutionControl.currentProxy.end()},i?(o=t,a.src=o):(c=wdi.SpiceObject.bytesToURI(t),a.src=c)},getImageFromSpice:function(n,t,r,e,u,i){var o,c,a,f,d=null;switch(i?(c=i.opaque,a=i.brush,f=i.raw):(c=!1,f=!1,a=!1),n.type){case wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB:d=this.processLz(n,t,a,c,r);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_PLT:wdi.Debug.log("lz plt decode"),d=wdi.LZSS.convert_spice_lz_to_web(r.getContext(0),t,n,c);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC:d=this.processQuic(n,t,a,c,r);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG:return wdi.Debug.log("JPEG decode"),wdi.ExecutionControl.sync=!1,void this.drawJpeg(n,t.subarray(4),e,u);case wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG_ALPHA:wdi.Debug.log("JPEG Alpha decode"),wdi.ExecutionControl.sync=!1;var g=t.subarray(9);return void this.drawJpeg(n,g,e,u);case wdi.SpiceImageType.SPICE_IMAGE_TYPE_BITMAP:wdi.Debug.log("BMP"),t.toJSArray&&(t=t.toJSArray()),d=new wdi.BMP2(t).marshall(r.getContext(0));break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:case wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE:return wdi.ExecutionControl.sync=!1,void wdi.ImageCache.getImageFrom(n,(function(n){e.call(u,n),wdi.ExecutionControl.currentProxy.end()}));case wdi.SpiceImageType.SPICE_IMAGE_TYPE_SURFACE:var s=wdi.SpiceObject.bytesToInt32(t.toJSArray());d=r.getContext(s).canvas;break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS:d=t;break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_PNG:return wdi.ExecutionControl.sync=!1,t=wdi.SpiceObject.bytesToString(t.toJSArray()),void this.drawBrowserImage(n,t,e,u,"png",!0);default:return wdi.Debug.log("Unknown image type: "+n.type),void wdi.ExecutionControl.currentProxy.end()}o=null,n.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME&&wdi.ImageCache.addImage(n,d),o=d.getContext||f?d:this.getImageFromData(d),n.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME&&wdi.ImageCache.addImage(n,o),wdi.ExecutionControl.sync&&e.call(u,o)},processUncompress:function(n,t,r,e,u,i){wdi.ImageUncompressor.getSyncInstance().process(n,t,r,e,u,i,this)},processQuic:function(n,t,r,e,u){var i;return this.processUncompress(n,t,r,e,u,(function(t){var r=new Uint8ClampedArray(t);i=new ImageData(r,n.width,n.height)})),i},processLz:function(n,t,r,e,u){var i;return this.processUncompress(n,t,r,e,u,(function(u){var o=wdi.ImageUncompressor.getSyncInstance().extractLzHeader(t,r),c=new Uint8ClampedArray(u);i=new ImageData(c,n.width,n.height),o.header.top_down||e||(i=this.imageFlip(i))})),i},imageFlip:function(n){return wdi.RasterOperation.flip(this.getImageFromData(n))},getImageFromData:function(n,t){return n.getContext||n instanceof Image?n:((r=t?$("<canvas/>").attr({width:n.width,height:n.height})[0]:this.getNewTmpCanvas(n.width,n.height)).getContext("2d").putImageData(n,0,0),r);var r},getDataFromImage:function(n){return n.getContext("2d").getImageData(0,0,n.width,n.height)},getBoxFromSrcArea:function(n){return{width:n.right-n.left,height:n.bottom-n.top,x:n.left,y:n.top}},setBrush:function(n,t,r,e,u){var i,o,c;if(r.type===wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN)o=r.pattern.image,this.getImageFromSpice(o,r.pattern.imageData,n,(function(n){if(i=t.createPattern(n,"repeat"),u===wdi.SpiceRopd.SPICE_ROPD_OP_PUT)t.fillStyle=i,t.fillRect(e.x,e.y,e.width,e.height);else{var r=wdi.graphics.getTmpCanvas(e.width,e.height),o=r.getContext("2d");o.fillStyle=i,o.fillRect(0,0,e.width,e.height);var a=wdi.graphics.getRect(e,t.canvas);c=wdi.RasterOperation.process(u,r,a),t.drawImage(c,e.x,e.y,e.width,e.height)}}),this,{opaque:!0});else if(r.type===wdi.SpiceBrushType.SPICE_BRUSH_TYPE_SOLID)if(u===wdi.SpiceRopd.SPICE_ROPD_OP_PUT)t.fillStyle!=r.color.simple_html_color&&(t.fillStyle=r.color.simple_html_color),t.fillRect(e.x,e.y,e.width,e.height);else{var a=wdi.graphics.getTmpCanvas(e.width,e.height),f=a.getContext("2d");f.fillStyle=r.color.html_color,f.fillRect(0,0,e.width,e.height);var d=wdi.graphics.getRect(e,t.canvas);c=wdi.RasterOperation.process(u,a,d),t.drawImage(c,e.x,e.y,e.width,e.height)}},imageIsEntireColor:function(n,t,r,e,u){var i,o=0;do{i=u[o]===n&&u[o+1]===t&&u[o+2]===r,o+=4}while(o!=e&&i);return i},drawBackText:function(n,t,r){var e=r.back_brush,u=r.back_mode,i=wdi.graphics.getBoxFromSrcArea(r.base.box);this.setBrush(n,t,e,i,u)},drawString:function(n,t,r,e,u,i){var o,c,a,f,d,g,s,h,p,w,l,m,I,C,_,E,S,y,v,P,T,x,A,b=e.color,D=t.len,G=t.raster_glyph;for(h=1===r?255:4===r?17:1,l=0;l<D;l++){for(o=(y=G[l]).render_pos,c=y.glyph_origin,a=y.width,f=y.height,d=y.data,g=f,m=new ArrayBuffer(a*f*4),I=new Uint8ClampedArray(m),C=new Uint32Array(m),p=0,w=0;g--;){for(E=_=Math.ceil(a*r/8),S=[];E--;)S.push(d.pop());for(;_--;)for(v=S.pop(),P=8,T=0;P;)x=wdi.bppMask[r][T]&v,1===r&&x?x=1:4===r&&x&&x>15&&(x>>=4),x&&(C[w*a+p]=h*x<<24|b.b<<16|b.g<<8|b.r),P-=r,p++,T++;w++,p=0}A={x:o.x+c.x,y:o.y+c.y-1,width:a,height:f},s=new ImageData(I,a,f);var R=wdi.graphics.getImageFromData(s);i.drawClip(R,A,n),wdi.GlobalPool.discard("Canvas",R)}},getImgDataPosition:function(n,t,r){return 4*(t*r+n)},getTmpCanvas:function(n,t){var r=this.tmpCanvas;return r.width=n,r.height=t,r},getNewTmpCanvas:function(n,t){var r=wdi.GlobalPool.create("Canvas");return r.width=n,r.height=t,r}},wdi.Rop3={1:function(n,t,r){return~(n|t|r)},2:function(n,t,r){return~(n|t)&r},4:function(n,t,r){return~(n|r)&t},6:function(n,t,r){return~(t^~r|n)},7:function(n,t,r){return~(t&r|n)},8:function(n,t,r){return~n&r&t},9:function(n,t,r){return~(t^r|n)},11:function(n,t,r){return~(~r&t|n)},13:function(n,t,r){return~(~t&r|n)},14:function(n,t,r){return~(~(t|r)|n)},16:function(n,t,r){return~(t|r)&n},18:function(n,t,r){return~(n^~r|t)},19:function(n,t,r){return~(n&r|t)},20:function(n,t,r){return~(n^~t|r)},21:function(n,t,r){return~(n&t|r)},22:function(n,t,r){return~(n&t)&r^t^n},23:function(n,t,r){return(t^r)&(t^n)^~t},24:function(n,t,r){return(t^n)&(n^r)},25:function(n,t,r){return~(n&t)&r^~t},26:function(n,t,r){return(n&t|r)^n},27:function(n,t,r){return(n^t)&r^~t},28:function(n,t,r){return(n&r|t)^n},29:function(n,t,r){return(n^r)&t^~r},30:function(n,t,r){return(r|t)^n},31:function(n,t,r){return~((t|r)&n)},32:function(n,t,r){return~t&n&r},33:function(n,t,r){return~(n^r|t)},35:function(n,t,r){return~(~r&n|t)},36:function(n,t,r){return(t^n)&(r^t)},37:function(n,t,r){return~(t&n)&r^~n},38:function(n,t,r){return(t&n|r)^t},39:function(n,t,r){return(t^~n|r)^t},40:function(n,t,r){return(n^t)&r},41:function(n,t,r){return(t&n|r)^t^~n},42:function(n,t,r){return~(t&n)&r},43:function(n,t,r){return(n^r)&(t^n)^~t},44:function(n,t,r){return(t|r)&n^t},45:function(n,t,r){return(~r|t)^n},46:function(n,t,r){return(n^r|t)^n},47:function(n,t,r){return~((~r|t)&n)},49:function(n,t,r){return~(~n&r|t)},50:function(n,t,r){return(t|n|r)^t},52:function(n,t,r){return(t&r|n)^t},53:function(n,t,r){return(t^~r|n)^t},54:function(n,t,r){return(n|r)^t},55:function(n,t,r){return~((n|r)&t)},56:function(n,t,r){return(n|r)&t^n},57:function(n,t,r){return(~r|n)^t},58:function(n,t,r){return(t^r|n)^t},59:function(n,t,r){return~((~r|n)&t)},61:function(n,t,r){return(~(t|r)|n)^t},62:function(n,t,r){return(~t&r|n)^t},64:function(n,t,r){return~r&t&n},65:function(n,t,r){return~(t^n|r)},66:function(n,t,r){return(t^r)&(n^r)},67:function(n,t,r){return~(t&r)&n^~t},69:function(n,t,r){return~(~t&n|r)},70:function(n,t,r){return(r&n|t)^r},71:function(n,t,r){return(n^r)&t^~n},72:function(n,t,r){return(n^r)&t},73:function(n,t,r){return(r&n|t)^r^~n},74:function(n,t,r){return(r|t)&n^r},75:function(n,t,r){return(~t|r)^n},76:function(n,t,r){return~(n&r)&t},77:function(n,t,r){return(t^r|t^n)^~t},78:function(n,t,r){return(n^t|r)^n},79:function(n,t,r){return~((~t|r)&n)},81:function(n,t,r){return~(~n&t|r)},82:function(n,t,r){return(r&t|n)^r},83:function(n,t,r){return(t^r)&n^~t},84:function(n,t,r){return~(~(t|n)|r)},86:function(n,t,r){return(t|n)^r},87:function(n,t,r){return~((t|n)&r)},88:function(n,t,r){return(n|t)&r^n},89:function(n,t,r){return(~t|n)^r},91:function(n,t,r){return(~(r|t)|n)^r},92:function(n,t,r){return(r^t|n)^r},93:function(n,t,r){return~((~t|n)&r)},94:function(n,t,r){return(~r&t|n)^r},96:function(n,t,r){return(t^r)&n},97:function(n,t,r){return(t&r|n)^t^~r},98:function(n,t,r){return(r|n)&t^r},99:function(n,t,r){return(~n|r)^t},100:function(n,t,r){return(t|n)&r^t},101:function(n,t,r){return(~n|t)^r},103:function(n,t,r){return(~(t|n)|r)^t},104:function(n,t,r){return(~(t|r)|n)^t^~r},105:function(n,t,r){return t^r^~n},106:function(n,t,r){return t&n^r},107:function(n,t,r){return(t|n)&r^t^~n},108:function(n,t,r){return n&r^t},109:function(n,t,r){return(r|n)&t^r^~n},110:function(n,t,r){return(~t|n)&r^t},111:function(n,t,r){return~((t^~r)&n)},112:function(n,t,r){return~(t&r)&n},113:function(n,t,r){return(r^n)&(t^r)^~t},114:function(n,t,r){return(t^n|r)^t},115:function(n,t,r){return~((~n|r)&t)},116:function(n,t,r){return(r^n|t)^r},117:function(n,t,r){return~((~n|t)&r)},118:function(n,t,r){return(~t&n|r)^t},120:function(n,t,r){return t&r^n},121:function(n,t,r){return(t|r)&n^t^~r},122:function(n,t,r){return(~r|t)&n^r},123:function(n,t,r){return~((n^~r)&t)},124:function(n,t,r){return(~t|r)&n^t},125:function(n,t,r){return~((t^~n)&r)},126:function(n,t,r){return t^r|n^t},127:function(n,t,r){return~(t&n&r)},128:function(n,t,r){return t&n&r},129:function(n,t,r){return~(t^r|n^t)},130:function(n,t,r){return(t^~n)&r},131:function(n,t,r){return(~t|r)&n^~t},132:function(n,t,r){return(n^~r)&t},133:function(n,t,r){return(~n|t)&r^~n},134:function(n,t,r){return(t|r)&n^t^r},135:function(n,t,r){return t&r^~n},137:function(n,t,r){return(~t&n|r)^~t},138:function(n,t,r){return(~n|t)&r},139:function(n,t,r){return(r^n|t)^~r},140:function(n,t,r){return(~n|r)&t},141:function(n,t,r){return(t^n|r)^~t},142:function(n,t,r){return(r^n)&(r^t)^t},143:function(n,t,r){return~(~(t&r)&n)},144:function(n,t,r){return(t^~r)&n},145:function(n,t,r){return(~t|n)&r^~t},146:function(n,t,r){return(n|r)&t^n^r},147:function(n,t,r){return r&n^~t},148:function(n,t,r){return(t|n)&r^t^n},149:function(n,t,r){return t&n^~r},150:function(n,t,r){return t^n^r},151:function(n,t,r){return(~(t|n)|r)^t^n},152:function(n,t,r){return(~(t|n)|r)^~t},154:function(n,t,r){return~t&n^r},155:function(n,t,r){return(t|n)&r^~t},156:function(n,t,r){return~r&n^t},157:function(n,t,r){return(r|n)&t^~r},158:function(n,t,r){return(t&r|n)^t^r},159:function(n,t,r){return~((t^r)&n)},161:function(n,t,r){return(~n&t|r)^~n},162:function(n,t,r){return(~t|n)&r},163:function(n,t,r){return(r^t|n)^~r},164:function(n,t,r){return(~(n|t)|r)^~n},166:function(n,t,r){return~n&t^r},167:function(n,t,r){return(n|t)&r^~n},168:function(n,t,r){return(t|n)&r},169:function(n,t,r){return(t|n)^~r},171:function(n,t,r){return~(t|n)|r},172:function(n,t,r){return(t^r)&n^t},173:function(n,t,r){return(r&t|n)^~r},174:function(n,t,r){return~n&t|r},176:function(n,t,r){return(~t|r)&n},177:function(n,t,r){return(n^t|r)^~n},178:function(n,t,r){return(t^r|n^t)^t},179:function(n,t,r){return~(~(n&r)&t)},180:function(n,t,r){return~r&t^n},181:function(n,t,r){return(r|t)&n^~r},182:function(n,t,r){return(n&r|t)^n^r},183:function(n,t,r){return~((n^r)&t)},184:function(n,t,r){return(r^n)&t^n},185:function(n,t,r){return(r&n|t)^~r},186:function(n,t,r){return~t&n|r},188:function(n,t,r){return~(t&r)&n^t},189:function(n,t,r){return~((r^n)&(r^t))},190:function(n,t,r){return t^n|r},191:function(n,t,r){return~(t&n)|r},193:function(n,t,r){return(~t&r|n)^~t},194:function(n,t,r){return(~(t|r)|n)^~t},196:function(n,t,r){return(~r|n)&t},197:function(n,t,r){return(t^r|n)^~t},198:function(n,t,r){return~n&r^t},199:function(n,t,r){return(n|r)&t^~n},200:function(n,t,r){return(n|r)&t},201:function(n,t,r){return(r|n)^~t},202:function(n,t,r){return(r^t)&n^r},203:function(n,t,r){return(t&r|n)^~t},205:function(n,t,r){return~(n|r)|t},206:function(n,t,r){return~n&r|t},208:function(n,t,r){return(~r|t)&n},209:function(n,t,r){return(n^r|t)^~n},210:function(n,t,r){return~t&r^n},211:function(n,t,r){return(t|r)&n^~t},212:function(n,t,r){return(r^n)&(n^t)^t},213:function(n,t,r){return~(~(t&n)&r)},214:function(n,t,r){return(t&n|r)^t^n},215:function(n,t,r){return~((t^n)&r)},216:function(n,t,r){return(n^t)&r^n},217:function(n,t,r){return(t&n|r)^~t},218:function(n,t,r){return~(r&t)&n^r},219:function(n,t,r){return~((t^r)&(n^t))},220:function(n,t,r){return~r&n|t},222:function(n,t,r){return n^r|t},223:function(n,t,r){return~(n&r)|t},224:function(n,t,r){return(t|r)&n},225:function(n,t,r){return(t|r)^~n},226:function(n,t,r){return(r^n)&t^r},227:function(n,t,r){return(n&r|t)^~n},228:function(n,t,r){return(t^n)&r^t},229:function(n,t,r){return(n&t|r)^~n},230:function(n,t,r){return~(t&n)&r^t},231:function(n,t,r){return~((r^n)&(n^t))},232:function(n,t,r){return(t^r)&(n^t)^t},233:function(n,t,r){return~(t&r)&n^t^~r},234:function(n,t,r){return t&n|r},235:function(n,t,r){return t^~n|r},236:function(n,t,r){return n&r|t},237:function(n,t,r){return n^~r|t},239:function(n,t,r){return~n|r|t},241:function(n,t,r){return~(t|r)|n},242:function(n,t,r){return~t&r|n},244:function(n,t,r){return~r&t|n},246:function(n,t,r){return t^r|n},247:function(n,t,r){return~(t&r)|n},248:function(n,t,r){return t&r|n},249:function(n,t,r){return t^~r|n},251:function(n,t,r){return~t|n|r},253:function(n,t,r){return~r|t|n},254:function(n,t,r){return t|n|r}};Uint8Array.prototype.toJSArray=function(){if(1==this.length)return[this[0]];for(var t=this.length,i=new Array(t),s=0;s<t;s++)i[s]=this[s];return i},wdi.FixedQueue=$.spcExtend(wdi.DomainObject,{q:null,size:10485760,grow:10485760,woffset:0,roffset:0,init:function(t){this.q=new Uint8Array(this.size)},setData:function(t){this.woffset=t.length,this.roffset=0,this.q.set(t)},shift:function(t){if(this.roffset+t>this.woffset)throw"Not enough queue to read";var i=this.q.subarray(this.roffset,this.roffset+t);return this.roffset=this.roffset+t,this.woffset==this.roffset&&(this.woffset=0,this.roffset=0),i},push:function(t){if(this.woffset+t.byteLength>this.size){var i=this.q;this.size+=this.grow,this.q=new Uint8Array(this.size),this.q.set(i)}this.q.set(t,this.woffset),this.woffset+=t.byteLength},getLength:function(){return this.woffset-this.roffset}}),wdi.Queue=$.spcExtend(wdi.DomainObject,{q:null,raw:!1,init:function(t){t.raw&&(this.raw=t.raw),this.q=new Uint8Array(0)},getData:function(){return this.toJSArray(this.q)},setData:function(t){this.q=new Uint8Array(t.length),this.q.set(t)},shift:function(){var t=arguments[0]||this.getLength();if(t===this.q.length){var i=this.q;this.q=new Uint8Array(0)}else{i=this.q.subarray(0,t);this.q=this.q.subarray(t)}return this.toJSArray(i)},peek:function(t,i){var s=null;return s=0!=t||i?this.q.subarray(t,i):this.q,this.toJSArray(s)},push:function(t){if("string"==typeof t){var i=t.length;(e=new Uint8Array(this.q.length+i)).set(this.q);for(var s=0;s<i;s++)e[s+this.q.length]=t[s];this.q=e}else{var e;if(0===this.getLength())this.q=new Uint8Array(t.length),this.q.set(t);else(e=new Uint8Array(t.length+this.q.length)).set(this.q),e.set(t,this.q.length),this.q=e}},getLength:function(){return this.q.length},toJSArray:function(t){return this.raw?t:t.toJSArray()}}),wdi.ViewQueue=$.spcExtend(wdi.DomainObject,{q:null,at:null,init:function(){this.q=new Uint8Array,this.at=0},getData:function(){return this.toJSArray(this.q.subarray(this.at))},getDataOffset:function(t){return this.toJSArray(this.q.subarray(t))},getRawData:function(){return this.q.subarray(this.at)},getRawDataOffset:function(t){return this.q.subarray(t)},setData:function(t){this.q=new Uint8Array(t.length),this.q.set(t),this.at=0},shift:function(t){var i=t||this.getLength();i>this.getLength()&&(i=this.getLength());var s=this.q.subarray(0+this.at,i+this.at);return this.at+=i,this.toJSArray(s)},eatBytes:function(t){this.at+=t},getByte:function(t){return this.q[t+this.at]},peek:function(t,i){var s=null;return 0!=t||i?(i&&(i+=this.at),s=this.q.subarray(t+this.at,i)):s=this.q,this.toJSArray(s)},push:function(t){if("string"==typeof t){var i=t.length;(e=new Uint8Array(this.q.length+i)).set(this.q);for(var s=0;s<i;s++)e[s+this.q.length]=t[s];this.q=e}else{var e;if(0===this.getLength())this.q=new Uint8Array(t.length),this.q.set(t);else(e=new Uint8Array(t.length+this.q.length)).set(this.q),e.set(t,this.q.length),this.q=e}},getLength:function(){return this.q.length-this.at},getPosition:function(){return this.at},toJSArray:function(t){return 1==t.length?[t[0]]:t.toJSArray()}});var syncInstance,asyncInstance;wdi.ImageUncompressor=$.spcExtend(wdi.EventObject.prototype,{init:function(e){this.syncAsyncHandler=e.syncAsyncHandler||new wdi.SyncAsyncHandler({isAsync:e.isAsync})},lzHeaderSize:32,extractLzHeader:function(e,n){var s,c;return n?c=wdi.LZSS.demarshall_rgb(e):("[object Array]"===Object.prototype.toString.call(e)?(s=e.slice(0,this.lzHeaderSize),e=e.slice(this.lzHeaderSize)):(s=e.subarray(0,this.lzHeaderSize).toJSArray(),e=e.subarray(this.lzHeaderSize)),c=wdi.LZSS.demarshall_rgb(s)),{header:c,imageData:e}},processLz:function(e,n,s,c,a,r){var t,i,d,y;e=(t=this.extractLzHeader(e,n)).imageData,y=t.header.width*t.header.height*4,d=new ArrayBuffer(e.length+16),(i=new Uint8Array(d))[0]=1,i[1]=s,i[2]=t.header.type,i[3]=t.header.top_down;for(var o=0;o<4;o++)i[4+o]=255&y,y>>=8;var h=new DataView(d);h.setUint32(8,t.header.width),h.setUint32(12,t.header.height),i.set(e,16),this.syncAsyncHandler.dispatch(d,a,r)},processQuic:function(e,n,s,c,a){wdi.Debug.log("Quic decode"),buffer=new ArrayBuffer(e.length+4),view=new Uint8Array(buffer),view.set(e,4),view[3]=n?1:0,view[0]=0,this.syncAsyncHandler.dispatch(buffer,c,a)},process:function(e,n,s,c,a,r,t){switch(e.type){case wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC:this.processQuic(n,c,a,r,t);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB:this.processLz(n,s,c,a,r,t)}},dispose:function(){this.syncAsyncHandler.dispose()}}),wdi.ImageUncompressor.dispose=function(){syncInstance&&syncInstance.dispose(),asyncInstance&&asyncInstance.dispose()},wdi.ImageUncompressor.getSyncInstance=function(){return syncInstance||(syncInstance=new wdi.ImageUncompressor({isAsync:!1})),syncInstance},wdi.ImageUncompressor.getAsyncInstance=function(){return asyncInstance||(asyncInstance=new wdi.ImageUncompressor({isAsync:!0})),asyncInstance};wdi.SyncAsyncHandler=$.spcExtend(wdi.EventObject.prototype,{init:function(s){this.isAsync=!!s.isAsync,this.isAsync&&(this.asyncWorker=s.asyncWorker||new wdi.AsyncWorker({script:wdi.spiceClientPath+"/spice-console-minify/WorkerProcess.min.js"}))},isAsync:null,dispatch:function(s,i,n){if(this.isAsync)this.asyncWorker.run(s,i,n);else{var c=window.workerDispatch(s,this.isAsync);i.call(n,c)}},dispose:function(){this.isAsync&&this.asyncWorker.dispose()}});wdi.IntegrationBenchmark={benchmarking:!1,startTime:0,timeoutInterval:3e3,timeOutId:void 0,busConnection:void 0,setEndTime:function(){var t=this;this.timeOutId=setTimeout((function(){t.timeOutId=void 0,t.benchmarking=!1;var e=(new Date).getTime()-t.startTime-t.timeoutInterval;t.onEndBenchmarkCallback(e);var i={type:wdi.BUS_TYPES.killApplicationDoNotUseInProductionEver,application:"EXCEL.EXE"};t.busConnection.send(i)}),this.timeoutInterval)},setStartTime:function(){void 0!==this.timeOutId&&clearTimeout(this.timeOutId)},launchApp:function(t,e){this.busConnection=t,wdi.IntegrationBenchmark.benchmarking=!0,wdi.IntegrationBenchmark.setStartTime(),this.onEndBenchmarkCallback=e,this.startTime=(new Date).getTime();var i={type:wdi.BUS_TYPES.launchApplication,file:"c:\\Users\\eyeos\\Desktop\\test.xlsx"};this.busConnection.send(i)}};wdi.StuckKeysHandler=$.spcExtend(wdi.EventObject.prototype,{ctrlTimeoutId:null,altTimeoutId:null,shiftTimeoutId:null,shiftKeyPressed:!1,ctrlKeyPressed:!1,altKeyPressed:!1,dispose:function(){wdi.Debug.log("Disposing StuckKeysHandler"),clearTimeout(this.ctrlTimeoutId),clearTimeout(this.altTimeoutId),clearTimeout(this.shiftTimeoutId),this.ctrlTimeoutId=null,this.altTimeoutId=null,this.shiftTimeoutId=null,this.shiftKeyPressed=!1,this.ctrlKeyPressed=!1,this.altKeyPressed=!1},handleStuckKeys:function(e){if(e)switch(e.keyCode){case 16:this._handleKey("shiftTimeoutId",e.type,16);break;case 17:this._handleKey("ctrlTimeoutId",e.type,17);break;case 18:this._handleKey("altTimeoutId",e.type,18)}},releaseAllKeys:function(){var e;for(e=0;e<300;e++)this.releaseKeyPressed(e)},_handleKey:function(e,s,t){"keydown"===s?this[e]=this._configureTimeout(t):"keyup"===s&&clearTimeout(this[e])},_configureTimeout:function(e){var s=this;return setTimeout((function(){s.releaseKeyPressed(e)}),wdi.StuckKeysHandler.defaultTimeout)},releaseKeyPressed:function(e){var s=window.jQuery.Event("keyup");s.which=e,s.keyCode=e,s.charCode=0,s.generated=!0,this.fire("inputStuck",["keyup",[s]])},checkSpecialKey:function(e,s){switch(s){case 16:this.shiftKeyPressed="keydown"===e;break;case 17:this.ctrlKeyPressed="keydown"===e;break;case 18:this.altKeyPressed="keydown"===e}},releaseSpecialKeysPressed:function(){this.shiftKeyPressed&&(this.releaseKeyPressed(16),this.shiftKeyPressed=!1),this.ctrlKeyPressed&&(this.releaseKeyPressed(17),this.ctrlKeyPressed=!1),this.altKeyPressed&&(this.releaseKeyPressed(18),this.altKeyPressed=!1)}}),wdi.StuckKeysHandler.defaultTimeout=2e3;wdi.TimeLapseDetector=$.spcExtend(wdi.EventObject.prototype,{lastTime:null,init:function(t){this.superInit()},dispose:function(){this.lastTime=null},startTimer:function(){var t=this;this.lastTime=Date.now(),window.setInterval((function(){var e=Date.now(),i=e-t.lastTime;i>=t.constructor.maxIntervalAllowed&&t.fire("timeLapseDetected",i),t.lastTime=e}),wdi.TimeLapseDetector.defaultInterval)},getLastTime:function(){return this.lastTime},setLastTime:function(t){return this.lastTime=t,this}}),wdi.TimeLapseDetector.defaultInterval=5e3,wdi.TimeLapseDetector.maxIntervalAllowed=3*wdi.TimeLapseDetector.defaultInterval;wdi.DisplayRouter=$.spcExtend(wdi.EventObject.prototype,{init:function(i){this.time=Date.now(),this.clientGui=i.clientGui,this.rasterEngine=i.rasterEngine||new wdi.RasterEngine({clientGui:this.clientGui}),i.routeList?this.routeList=i.routeList:this._initRoutes()},dispose:function(){this.rasterEngine.dispose(),this.clientGui=null,this.rasterEngine=null,this.routeList=null},_initRoutes:function(){wdi.Debug.log("displayRouter",this.time),this.routeList={},this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_CREATE]=this.rasterEngine.drawCanvas,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_DESTROY]=this.rasterEngine.removeCanvas,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY]=this.rasterEngine.drawImage,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL]=this.rasterEngine.drawFill,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND]=this.rasterEngine.drawAlphaBlend,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_WHITENESS]=this.rasterEngine.drawWhiteness,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLACKNESS]=this.rasterEngine.drawBlackness,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT]=this.rasterEngine.drawTransparent,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS]=this.rasterEngine.drawCopyBits,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TEXT]=this.rasterEngine.drawText,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_STROKE]=this.rasterEngine.drawStroke,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ROP3]=this.rasterEngine.drawRop3,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_INVERS]=this.rasterEngine.drawInvers,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CREATE]=this.rasterEngine.handleStreamCreate,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY]=this.rasterEngine.handleStreamDestroy,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA]=this.rasterEngine.handleStreamData,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CLIP]=this.rasterEngine.handleStreamClip,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED]=this.rasterEngine.handleStreamDataSized,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT]=this.rasterEngine.handleStreamActiveReport,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND]=this.rasterEngine.drawBlend,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_LIST]=this.rasterEngine.invalList,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES]=this.rasterEngine.invalPalettes,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_MARK]=!1,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_RESET]=this.rasterEngine.handleReset},processPacket:function(i){if(i){var t=this.routeList[i.messageType];t&&t.call(this.rasterEngine,i)}else wdi.Debug.log("DisplayProcess processPacket: Skipping empty message...")}});const _SOI=new Uint8Array([255,216]),_EOI=new Uint8Array([255,217]);wdi.RasterEngine=$.spcExtend(wdi.EventObject.prototype,{chunks:[],size:0,jpegInst:null,init:function(e){this.time=Date.now(),this.clientGui=e.clientGui,this.codecH264=wdi.CodecH264,this.codecVp8=wdi.CodecVp8,this.codecH265=wdi.CodecH265},dispose:function(){this.clientGui=null},drawCanvas:function(e){return wdi.Debug.log("rasterEngine",this.time),this.clientGui.drawCanvas(e)},removeCanvas:function(e){return this.clientGui.removeCanvas(e)},invalList:function(e){var t=e.args.items,i=null;for(var a in t)i=t[a],wdi.ImageCache.delImage(i.id)},handleStreamCreate:function(e){var t=e.args;switch(t.computedBox=wdi.graphics.getBoxFromSrcArea(t.rect),wdi.Stream.addStream(e.args.id,t),console.log("%chandleStreamCreate","color:rgb(100,255,100)"),t.codec){case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H264:this.handleH264StreamCreate(t.id);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP8:this.handleVp8StreamCreate(t.id);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP9:break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H265:this.handleH265StreamCreate(t.id)}wdi.graphicDebug&&wdi.graphicDebug.handleStreamInfo()},handleVp8StreamCreate:function(e){this.codecVp8.create(e)},handleH265StreamCreate:async function(e){const t=wdi.Stream.getStream(e),i=this.clientGui.getContext(t.surface_id),a=t.computedBox;this.codecH265.create(e,i,a)},handleH264StreamCreate:function(e){this.codecH264.create(e)},handleStreamData:function(e){switch(wdi.Stream.getStream(e.args.id).codec){case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_MJPEG:this.handleMjpegStream(e);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H264:this.handleH264Stream(e);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP8:this.handleVp8Stream(e);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP9:break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H265:this.handleH265Stream(e);break;default:this.handleMjpegStream(e)}},handleStreamClip:function(e){wdi.Stream.clip(e.args.id,e.args.clip),wdi.Stream.startTransition(e.args.id),console.log("%chandleStreamClip","color:rgb(100,100,255)")},handleStreamDataSized:function(e){},handleStreamActiveReport:function(e){},handleStreamDestroy:function(e){wdi.Stream.deleteStream(e.args.surface_id),this.codecH264.destroy(e.args.surface_id),this.codecVp8.destroy(),this.codecH265.destroy(),wdi.graphicDebug&&wdi.graphicDebug.handleStreamInfo(),console.log("%chandleStreamDestroy","color:rgb(255,100,100)")},indexOfBytes:function(e,t,i=0){for(let a=i;a<=e.length-t.length;a++){let i=!0;for(let r=0;r<t.length;r++)if(e[a+r]!==t[r]){i=!1;break}if(i)return a}return-1},concatenateChunks:function(e,t){const i=new Uint8Array(t);let a=0;for(const t of e)i.set(t,a),a+=t.length;return i},pushWholeMjpegFrame:function(e){const t=e.length;let i=0;for(;;)if(this.size){const a=this.indexOfBytes(e,_EOI);if(-1===a){this.chunks.push(e),size+=t;break}{i=a+_EOI.length;const r=e.slice(0,i);if(this.chunks.push(r),this.size+=r.length,this.jpegInst=this.concatenateChunks(chunks,size),this.chunks=[],size=0,i===t)break}}else{const a=this.indexOfBytes(e,_SOI,i);if(-1===a)break;i=a+500;const r=this.indexOfBytes(e,_EOI,i);if(-1===r){const t=e.slice(a);this.chunks=[t],this.size=t.length;break}if(i=r+_EOI.length,this.jpegInst=e.slice(a,i),i===t)break}},handleMjpegStream:function(e){const t=e.args.data,i=wdi.Stream.getStream(e.args.id),a=this.clientGui.getContext(i.surface_id),r=i.computedBox;if(this.pushWholeMjpegFrame(new Uint8Array(t)),this.jpegInst){const e=new Blob([this.jpegInst],{type:"image/jpeg"});createImageBitmap(e).then((e=>{if(i.flags&wdi.SpiceStreamFlags.SPICE_STREAM_FLAGS_TOP_DOWN)a.drawImage(e,r.x,r.y,r.width,r.height);else{const t=r.x+e.width/2,i=r.y+e.height/2;a.save(),a.translate(t,i),a.rotate(Math.PI),a.scale(-1,1),a.drawImage(e,r.x-t,r.y-i,r.width,r.height),a.restore()}})).catch(console.error),this.jpegInst=null}},handleH264Stream:function(e){var t=e.args.data,i=wdi.Stream.getStream(e.args.id);if(this.codecH264.isReady[i.id]){var a=this.clientGui.getContext(i.surface_id);wdi.ExecutionControl.sync=!0,wdi.Stream.endTransition(e.args.id),this.codecH264.loadedVideo[i.id]=()=>{var e=i.computedBox;if(!i.flags&wdi.SpiceStreamFlags.SPICE_STREAM_FLAGS_TOP_DOWN){var t=e.x+this.codecH264.video[i.id].width/2,r=e.y+this.codecH264.video[i.id].height/2;a.save(),a.translate(t,r),a.rotate(Math.PI),a.scale(-1,1),a.drawImage(this.codecH264.video[i.id],e.x-t,e.y-r,e.width,e.height),a.restore()}else{if(!this.codecH264.video[i.id]||!this.codecH264.loadedVideo[i.id])return;if(i.transiting)return void requestAnimationFrame(this.codecH264.loadedVideo[i.id]);a.drawImage(this.codecH264.video[i.id],e.x,e.y,e.width,e.height),requestAnimationFrame(this.codecH264.loadedVideo[i.id])}},this.codecH264.feed(i.id,t)}else this.codecH264.addQueue(i.id,t)},handleH265Stream:function(e){const t=e.args.data,i=wdi.Stream.getStream(e.args.id),a=i.computedBox;this.codecH265.isReady[i.id]?(this.codecH265.configed[i.id]||this.codecH265.setConfig(i.id,a),this.codecH265.decode(i.id,t)):this.codecH265.addQueue(i.id,t)},handleVp8Stream:function(e){var t=e.args.data,i=wdi.Stream.getStream(e.args.id),a=this.clientGui.getContext(i.surface_id),r=i.computedBox;this.codecVp8.feed(i.id,t,a,r)},drawRop3:function(e){var t=wdi.graphics.getBoxFromSrcArea(e.args.base.box),i=this.clientGui.getContext(e.args.base.surface_id),a=i.getImageData(t.x,t.y,t.width,t.height),r=this.clientGui,s=e.args.brush,d=e.args.rop_descriptor,g=wdi.graphics.getBoxFromSrcArea(e.args.src_area);wdi.graphics.getImageFromSpice(e.args.src_image.imageDescriptor,e.args.src_image.data,this.clientGui,(function(e){if(e){var c=e.getContext("2d").getImageData(g.x,g.y,g.width,g.height),h=c.data,o=wdi.graphics.getNewTmpCanvas(t.width,t.height),n=o.getContext("2d"),l={width:t.width,height:t.height,x:0,y:0};wdi.graphics.setBrush(r,n,s,l,wdi.SpiceRopd.SPICE_ROPD_OP_PUT);var w=n.getImageData(0,0,t.width,t.height),p=w.data,m=a.data,u=(n=(o=wdi.graphics.getNewTmpCanvas(t.width,t.height)).getContext("2d")).createImageData(t.width,t.height),f=u.data;c.width!=w.width||c.width!=a.width||c.height!=w.height||(c.height,a.height);for(var S=m.length,C=wdi.Rop3[d],_=0;_<S;_+=4)f[_]=255&C(p[_],h[_],m[_]),f[_+1]=255&C(p[_+1],h[_+1],m[_+1]),f[_+2]=255&C(p[_+2],h[_+2],m[_+2]),f[_+3]=255;n.putImageData(u,0,0),this.drawClip(o,t,i)}else wdi.Debug.log("Unable to get image!")}),this)},drawInvers:function(e){var t=e.args.base,i=wdi.graphics.getBoxFromSrcArea(t.box),a=t.surface_id,r=this.clientGui.getContext(a),s=wdi.graphics.getRect(i,r.canvas),d=wdi.RasterOperation.process(wdi.SpiceRopd.SPICE_ROPD_OP_INVERS,null,s);r.drawImage(d,i.x,i.y,i.width,i.height)},drawStroke:function(e){var t,i,a,r,s=e.args,d=this.clientGui.getContext(e.args.base.surface_id),g=s.brush.color.html_color,c=s.path.num_segments;s.attr.flags&wdi.SpiceLineFlags.SPICE_LINE_FLAGS_STYLED&&wdi.Debug.log("SPICE_LINE_FLAGS_STYLED");for(var h=0;h<c;h++){if((r=s.path.segments[h]).flags&wdi.SpicePathFlags.SPICE_PATH_BEGIN&&(d.beginPath(),d.moveTo(r.points[0].x,r.points[0].y),d.strokeStyle=g,d.lineWidth=1),r.flags&wdi.SpicePathFlags.SPICE_PATH_BEZIER){if((t=r.points.length)%3==0)for(a=0;a<t;a+=3)d.bezierCurveTo(r.points[a].x,r.points[a].y,r.points[a+1].x,r.points[a+1].y,r.points[a+2].x,r.points[a+2].y)}else for(t=r.points.length,a=0;a<t;a++)0==a&&(i=r.points[a]),d.lineTo(r.points[a].x+.5,r.points[a].y+.5);r.flags&wdi.SpicePathFlags.SPICE_PATH_END&&(r.flags&wdi.SpicePathFlags.SPICE_PATH_CLOSE&&d.lineTo(i.x+.5,i.y+.5),d.stroke(),d.closePath())}},drawImage:function(e){var t=e.args,i=t.base,a=i.surface_id,r=t.rop_descriptor,s=(t.scale_mode,wdi.graphics.getBoxFromSrcArea(t.src_area)),d=wdi.graphics.getBoxFromSrcArea(i.box);window.vdiLoadTest&&void 0===window.firstImage&&(window.firstImage=!0),wdi.graphics.getImageFromSpice(t.image.imageDescriptor,t.image.data,this.clientGui,(function(e){if(e){var t;if(window.firstImage)t=e.getContext?e.getContext("2d").getImageData(0,0,e.width,e.height).data.buffer.slice(0):e.data.buffer.slice(0),window.firstImageData=t,window.firstImage=!1;var i=!1;if(s.width!==d.width&&s.height!==d.height){i=!0,e=wdi.graphics.getRect(s,e),e=wdi.graphics.getImageFromData(e);var g=wdi.graphics.getNewTmpCanvas(d.width,d.height);g.getContext("2d").drawImage(e,0,0,s.width,s.height,0,0,d.width,d.height),e=g}if(r!==wdi.SpiceRopd.SPICE_ROPD_OP_PUT){i||(e=wdi.graphics.getRect(s,e));var c=wdi.graphics.getRect(d,this.clientGui.getCanvas(a));e=wdi.RasterOperation.process(r,e,c)}var h=this.clientGui.getContext(a);e instanceof ImageData?i?h.putImageData(e,d.x,d.y,0,0,d.width,d.height):h.putImageData(e,d.x,d.y,s.x,s.y,s.width,s.height):i?h.drawImage(e,d.x,d.y,d.width,d.height):h.drawImage(e,s.x,s.y,s.width,s.height,d.x,d.y,d.width,d.height)}else wdi.Debug.log("Unable to get image!")}),this,{opaque:!0,brush:t.brush,raw:!1})},drawClip:function(e,t,i){i.drawImage(e,t.x,t.y,t.width,t.height)},drawFill:function(e){var t=e.args,i=this.clientGui.getContext(t.base.surface_id),a=wdi.graphics.getBoxFromSrcArea(t.base.box),r=t.brush,s=t.rop_descriptor;wdi.graphics.setBrush(this.clientGui,i,r,a,s)},drawCopyBits:function(e){var t=e.args.base,i=t.surface_id,a=e.args.src_position,r=this.clientGui.getContext(i),s=t.box,d=s.right-s.left,g=s.bottom-s.top;r.drawImage(r.canvas,a.x,a.y,d,g,t.box.left,t.box.top,d,g)},drawBlend:function(e){var t=e.args.image.imageDescriptor,i=e.args.base,a=e.args.image.data,r=e.args.base.surface_id,s=e.args.rop_descriptor;e.args.flags;wdi.graphics.getImageFromSpice(t,a,this.clientGui,(function(t){if(t){var a=wdi.graphics.getBoxFromSrcArea(e.args.src_area);t=wdi.graphics.getRect(a,t);var d=wdi.graphics.getBoxFromSrcArea(i.box),g=wdi.graphics.getRect(d,this.clientGui.getCanvas(r)),c=wdi.RasterOperation.process(s,t,g);this.clientGui.getCanvas(r).getContext("2d").drawImage(c,d.x,d.y,d.width,d.height)}else wdi.Debug.log("There is no image on Blend")}),this)},drawAlphaBlend:function(e){var t=e.args.image.imageDescriptor,i=e.args.base,a=e.args.image.data,r=e.args.base.surface_id,s=e.args.alpha_flags,d=e.args.alpha;wdi.graphics.getImageFromSpice(t,a,this.clientGui,(function(t){t||wdi.Debug.log("There is no image on drawAlphaBlend");var a=wdi.graphics.getBoxFromSrcArea(e.args.src_area);t=wdi.graphics.getRect(a,t);var g=wdi.graphics.getBoxFromSrcArea(i.box),c=wdi.graphics.getRect(g,this.clientGui.getCanvas(r));if(a.width!==g.width&&a.height!==g.height){var h=wdi.graphics.getNewTmpCanvas(g.width,g.height);h.getContext("2d").drawImage(t,0,0,a.width,a.height,0,0,g.width,g.height),t=h}for(var o,n,l,w,p,m,u,f=wdi.graphics.getDataFromImage(t).data,S=wdi.graphics.getDataFromImage(c).data,C=f.length-1,_=wdi.graphics.getNewTmpCanvas(g.width,g.height),x=_.getContext("2d").createImageData(g.width,g.height),I=x.data,b=0;b<C;b+=4)o=f[b],l=f[b+1],p=f[b+2],u=s||255===d?f[b+3]:d,n=S[b],w=S[b+1],m=S[b+2],u>30&&255===d?(I[b]=n*(255-u)/255+o&255,I[b+1]=w*(255-u)/255+l&255,I[b+2]=m*(255-u)/255+p&255):(I[b]=(o*u+n*(255-u))/255&255,I[b+1]=(l*u+w*(255-u))/255&255,I[b+2]=(p*u+m*(255-u))/255&255),I[b+3]=255;_.getContext("2d").putImageData(x,0,0),this.drawClip(_,g,this.clientGui.getContext(r))}),this)},drawWhiteness:function(e){var t=e.args.base,i=this.clientGui.getContext(t.surface_id),a=wdi.graphics.getBoxFromSrcArea(t.box);i.fillStyle="white",i.fillRect(a.x,a.y,a.width,a.height)},drawBlackness:function(e){var t=e.args.base,i=this.clientGui.getContext(t.surface_id),a=wdi.graphics.getBoxFromSrcArea(t.box);i.fillStyle="black",i.fillRect(a.x,a.y,a.width,a.height)},drawTransparent:function(e){var t=e.args.base,i=t.surface_id,a=wdi.graphics.getBoxFromSrcArea(e.args.src_area),r=wdi.graphics.getBoxFromSrcArea(t.box),s=this.clientGui.getContext(i).getImageData(r.x,r.y,r.width,r.height);wdi.graphics.getImageFromSpice(e.args.image.imageDescriptor,e.args.image.data,this.clientGui,(function(t){if(t){t=wdi.graphics.getRect(a,t);for(var d=wdi.graphics.getDataFromImage(t).data,g=s.data,c=d.length-1,h=this.clientGui.getContext(i).createImageData(r.width,r.height),o=e.args.transparent_true_color;c>0;)h.data[c]=255,d[c-1]===o.b&&d[c-2]===o.g&&d[c-3]===o.r?(h.data[c-1]=g[c-1],h.data[c-2]=g[c-2],h.data[c-3]=g[c-3]):(h.data[c-1]=d[c-1],h.data[c-2]=d[c-2],h.data[c-3]=d[c-3]),c-=4;var n=wdi.graphics.getImageFromData(h);this.drawClip(n,r,this.clientGui.getContext(i))}else wdi.Debug.log("Unable to get image!")}),this)},drawText:function(e){var t=this.clientGui.getContext(e.args.base.surface_id),i=(e.args.base.box,e.args.base.clip),a=e.args,r=a.glyph_string,s=1===r.flags?1:2*r.flags;0!==a.back_mode&&wdi.graphics.drawBackText(this.clientGui,t,a),wdi.graphics.drawString(t,r,s,a.fore_brush,i.type,this)},invalPalettes:function(e){wdi.ImageCache.clearPalettes()},handleReset:function(e){}});wdi.DataLogger={testStartTime:0,testStopTime:0,networkStart:0,networkTotalTime:0,data:{},routeList:{},imageTypes:{},startTimes:[],init:function(){this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_CREATE]="drawCanvas",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_DESTROY]="removeCanvas",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY]="drawImage",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL]="drawFill",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND]="drawAlphaBlend",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_WHITENESS]="drawWhiteness",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLACKNESS]="drawBlackness",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT]="drawTransparent",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS]="drawCopyBits",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TEXT]="drawText",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_STROKE]="drawStroke",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ROP3]="drawRop3",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_INVERS]="drawInvers",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CREATE]="handleStreamCreate",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY]="handleStreamDestroy",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA]="handleStreamData",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CLIP]="handleStreamClip",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED]="handleStreamDataSized",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT]="handleStreamActiveReport",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND]="drawBlend",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_LIST]="invalList",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES]="invalPalettes",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_MARK]="displayMark",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_RESET]="displayReset",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_BITMAP]="bitmap",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC]="quic",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_RESERVED]="reserved",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_PNG]="png",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_PLT]="lz_plt",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB]="lz_rgb",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_GLZ_RGB]="glz_rgb",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE]="cache",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_SURFACE]="surface",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG]="jpeg",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS]="cache_lossless",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB]="zlib_glz_rgb",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG_ALPHA]="jpeg_alpha",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS]="canvas"},setStartTime:function(t){this.startTimes.push(t)},getSpiceMessageType:function(t,e,i){var s=this.routeList[t.messageType];return"drawImage"===s&&(s+="_"+this.imageTypes[t.args.image.imageDescriptor.type]),(e||"")+s+(i||"")},setNetworkTimeStart:function(t){this.networkStart=this.networkStart||t||Date.now()},logNetworkTime:function(){this.networkStart&&(this.networkTotalTime+=Date.now()-this.networkStart,this.networkStart=0)},startTestSession:function(){this.clear(),wdi.logOperations=!0,this.testStartTime=Date.now()},stopTestSession:function(){this.testStopTime=Date.now(),wdi.logOperations=!1},log:function(t,e,i,s,a,S){var _,r=Date.now();_=i||this.getSpiceMessageType(t,a,S),this.data.hasOwnProperty(_)||(this.data[_]=[]),s&&(e=this.startTimes.shift()),this.data[_].push({start:e,end:r})},clear:function(){this.data={},this.testStartTime=0,this.testStopTime=0,this.networkTotalTime=0,this.networkStart=0},getData:function(){return this.data},getStats:function(){var t,e=this.networkTotalTime,i=0,s=e,a=this.testStopTime-this.testStartTime,S=this.data,_={},r="";for(var E in this.data)if(this.data.hasOwnProperty(E)){i+=(t=S[E]).length,_[E]=0;for(var T=0;T<t.length;T++)_[E]+=t[T].end-t[T].start;s+=_[E]}r+="Total operations by number:\n";for(var E in S)S.hasOwnProperty(E)&&(r+=E+": "+~~(S[E].length/i*100)+"% ("+S[E].length+")\n");for(E in r+="Total numOperations: "+i+"\n",r+="---------------------------------\n",r+="\n",r+="Total Operations by time:\n",_)_.hasOwnProperty(E)&&(r+=E+": "+~~(_[E]/a*100)+"% ("+_[E]+"ms)\n");var I=a-s;return r+="Idle: "+~~(I/a*100)+"% ("+I+"ms)\n",r+="Network: "+~~(e/a*100)+"% ("+e+"ms)\n","BEGIN OF PERFORMANCE STATS\n"+(r+="Total time: "+a+"ms \n")+"\nEND OF PERFORMANCE STATS\n"}},wdi.DataLogger.init();wdi.socketStatus={idle:0,prepared:1,connected:2,disconnected:3,failed:4},wdi.Socket=$.spcExtend(wdi.EventObject.prototype,{websocket:null,status:wdi.socketStatus.idle,binary:!1,connect:function(t){var e=this,s="base64";Modernizr.websocketsbinary&&(s="binary",this.binary=!0),this.websocket=new WebSocket(t,s),wdi.Debug.log("Socket: using protocol: "+s),this.binary&&(this.websocket.binaryType="arraybuffer"),this.status=wdi.socketStatus.prepared,this.websocket.onopen=function(){e.status=wdi.socketStatus.connected,e.fire("open")},this.websocket.onmessage=function(t){e.fire("message",t.data)},this.websocket.onclose=function(t){e.status=wdi.socketStatus.disconnected,console.warn("Spice Web Client: ",t.code,t.reason),e.disconnect(),e.fire("close",t)},this.websocket.onerror=function(t){e.status=wdi.socketStatus.failed,e.fire("error",t)}},setOnMessageCallback:function(t){this.websocket.onmessage=t},send:function(t){try{this.websocket.send(this.encode_message(t))}catch(t){this.status=wdi.socketStatus.failed,this.fire("error",t)}},disconnect:function(){this.websocket&&(this.websocket.onopen=function(){},this.websocket.onmessage=function(){},this.websocket.onclose=function(){},this.websocket.onerror=function(){},this.websocket.close(),this.status=wdi.socketStatus.idle,this.binary=!1,this.websocket=null)},setStatus:function(t){this.status=t,this.fire("status",t)},getStatus:function(){return this.status},encode_message:function(t){if(!this.binary)return Base64.encode(t);var e=t.length,s=new ArrayBuffer(e),n=new Uint8Array(s);return n.set(t),n}});wdi.ClusterNodeChooser=$.spcExtend(wdi.EventObject.prototype,{init:function(t){},setNodeList:function(t){this._nodeList=this._shuffle(t),this._nodeListLength=this._nodeList.length,this._currentIndex=0},getAnother:function(){return this._nodeList[this._currentIndex++%this._nodeListLength]},_shuffle:function(t){for(var e,n,i=t.length;i>0;)n=Math.floor(Math.random()*i),e=t[--i],t[i]=t[n],t[n]=e;return t}});wdi.SocketQueue=$.spcExtend(wdi.EventObject.prototype,{rQ:null,sQ:null,socket:null,init:function(t){this.superInit(),this.socket=t.socket||new wdi.Socket,this.rQ=t.rQ||new wdi.FixedQueue,this.sQ=t.sQ||new wdi.Queue,this.setup()},setup:function(){this.socket.addListener("open",(function(){this.fire("open")}),this),this.socket.addListener("message",(function(t){this.rQ.push(new Uint8Array(t)),this.fire("message")}),this),this.socket.addListener("close",(function(t){this.fire("close",t)}),this),this.socket.addListener("error",(function(t){this.fire("error",t)}),this)},getStatus:function(){return this.socket.getStatus()},connect:function(t){this.socket.connect(t)},disconnect:function(){wdi.Debug.log("socket Queue disconnect"),this.socket&&(this.socket.clearEvents(),this.socket.disconnect()),this.rQ=null,this.sQ=null,this.socket=null},send:function(t,s){if(void 0===s)var e=!0;else e=s;this.sQ&&0===this.sQ.getLength()&&e?this.socket.send(t):this.sQ&&(this.sQ.push(t),e&&this.flush())},flush:function(){var t=this.sQ.shift();this.socket.send(t)}});wdi.PacketController=$.spcExtend(wdi.EventObject.prototype,{sizeDefiner:null,packetExtractor:null,init:function(t){this.superInit(),this.sizeDefiner=t.sizeDefiner,this.packetExtractor=t.packetExtractor},dispose:function(){wdi.Debug.log("PacketTroller dispose"),this.clearEvents(),this.packetExtractor.dispose(),this.packetExtractor=null,this.sizeDefiner=null},getNextPacket:function(t){var e=this;wdi.logOperations&&wdi.DataLogger.setNetworkTimeStart();var i=this.sizeDefiner.getSize(t);this.packetExtractor.getBytes(i,(function(t){var i=this.sizeDefiner.getStatus();this.execute(new wdi.RawMessage({status:i,data:t})),e.getNextPacket(t)}),this)},execute:function(t){try{this.fire("chunkComplete",t)}catch(t){console.error("PacketTroller: ",t)}}});wdi.PacketExtractor=$.spcExtend(wdi.EventObject.prototype,{socketQ:null,numBytes:null,callback:null,scope:null,init:function(t){this.superInit(),this.socketQ=t.socketQ,this.setListener()},dispose:function(){this.clearEvents(),this.socketQ.disconnect(),this.socketQ=null,this.numBytes=null,this.callback=null,this.scope=null},setListener:function(){this.socketQ.addListener("message",(function(){wdi.logOperations&&wdi.DataLogger.setNetworkTimeStart(),this.getBytes(this.numBytes,this.callback,this.scope)}),this)},getBytes:function(t,s,e){var i,n=this.socketQ.rQ.getLength();(this.numBytes=t,this.callback=s,this.scope=e,null!==t&&n>=t)?(i=t?this.socketQ.rQ.shift(t):new Uint8Array(0),this.numBytes=null,this.callback=null,this.scope=null,s.call(e,i)):wdi.logOperations&&wdi.DataLogger.logNetworkTime()}});wdi.PacketReassembler=$.spcExtend(wdi.EventObject.prototype,{packetController:null,currentHeader:null,statusToString:null,sizeDefinerConstant:null,init:function(t){this.superInit(),this.packetController=t.packetController,this.sizeDefinerConstant=wdi.SizeDefiner.prototype,this.statusToString=[],this.statusToString[this.sizeDefinerConstant.STATUS_REPLY_BODY]="reply",this.statusToString[this.sizeDefinerConstant.STATUS_ERROR_CODE]="errorCode",this.statusToString[this.sizeDefinerConstant.STATUS_BODY]="spicePacket",this.setListeners()},dispose:function(){wdi.Debug.log("packetReassembler dispose"),this.clearEvents(),this.packetController.dispose(),this.packetController=null,this.currentHeader=null,this.statusToString=null,this.sizeDefinerConstant=null},start:function(){this.packetController.getNextPacket()},setListeners:function(){this.packetController.addListener("chunkComplete",(function(t){var e=t,s=e.status;switch(s){case this.sizeDefinerConstant.STATUS_HEADER:case this.sizeDefinerConstant.STATUS_REPLY:this.currentHeader=e;break;case this.sizeDefinerConstant.STATUS_REPLY_BODY:case this.sizeDefinerConstant.STATUS_BODY:var i=new Uint8Array(e.data.length+this.currentHeader.data.length);i.set(this.currentHeader.data),i.set(e.data,this.currentHeader.data.length),e.data=i,e.status=this.statusToString[s],this.fire("packetComplete",e);break;default:e.status=this.statusToString[s],this.fire("packetComplete",e)}}),this)}});wdi.ReassemblerFactory={getPacketReassembler:function(e){var t=this.getPacketExtractor(e),r=this.getSizeDefiner(),n=this.getPacketController(t,r);return new wdi.PacketReassembler({packetController:n})},getPacketExtractor:function(e){return new wdi.PacketExtractor({socketQ:e})},getSizeDefiner:function(){return new wdi.SizeDefiner},getPacketController:function(e,t){return new wdi.PacketController({packetExtractor:e,sizeDefiner:t})}};wdi.SizeDefiner=$.spcExtend(wdi.DomainObject,{ERROR_CODE_SIZE:4,status:null,STATUS_READY:0,STATUS_REPLY:1,STATUS_REPLY_BODY:2,STATUS_ERROR_CODE:3,STATUS_MESSAGE:4,STATUS_HEADER:5,STATUS_BODY:6,isHeader:!1,init:function(t){this.status=this.STATUS_READY},getSize:function(t){return this.STATUS_READY===this.status?(this.status++,wdi.SpiceLinkHeader.prototype.objectSize):this.STATUS_REPLY===this.status?(this.status++,this.getReplyBodySize(t)):this.STATUS_REPLY_BODY===this.status?(this.status++,this.ERROR_CODE_SIZE):this.STATUS_ERROR_CODE===this.status?(this.status++,this.isHeader=!0,6):this.isHeader?(this.isHeader=!1,this.getBodySizeFromArrayHeader(t)):(this.isHeader=!0,6)},getReplyBodySize:function(t){var e=wdi.GlobalPool.create("ViewQueue");e.setData(t);var i=(new wdi.SpiceLinkHeader).demarshall(e);return wdi.GlobalPool.discard("ViewQueue",e),i.size},getBodySizeFromArrayHeader:function(t){var e=wdi.GlobalPool.create("ViewQueue");e.setData(t);var i=(new wdi.SpiceDataHeader).demarshall(e);return wdi.GlobalPool.discard("ViewQueue",e),i.size},getStatus:function(){return this.status===this.STATUS_MESSAGE&&this.isHeader?this.STATUS_HEADER:this.status!==this.STATUS_MESSAGE||this.isHeader?this.status:this.STATUS_BODY}});wdi.PacketLinkFactory={extract:function(e,i){switch(e.type){case wdi.SpiceVars.SPICE_MSG_SET_ACK:return(new wdi.RedSetAck).demarshall(i);case wdi.SpiceVars.SPICE_MSG_PING:return(new wdi.RedPing).demarshall(i,e.size);case wdi.SpiceVars.SPICE_MSG_MIGRATE:return(new wdi.RedMigrate).demarshall(i);case wdi.SpiceVars.SPICE_MSG_MIGRATE_DATA:return(new wdi.RedMigrateData).demarshall(i,e.size);case wdi.SpiceVars.SPICE_MSG_WAIT_FOR_CHANNELS:return(new wdi.RedWaitForChannels).demarshall(i);case wdi.SpiceVars.SPICE_MSG_DISCONNECTING:return(new wdi.RedDisconnect).demarshall(i);case wdi.SpiceVars.SPICE_MSG_NOTIFY:return(new wdi.RedNotify).demarshall(i);case wdi.SpiceVars.SPICE_MSG_MAIN_MOUSE_MODE:return(new wdi.SpiceMouseMode).demarshall(i)}}},wdi.PacketLinkProcess={process:function(e,i,a){switch(e.type){case wdi.SpiceVars.SPICE_MSG_SET_ACK:var r=wdi.SpiceObject.numberTo32(i.generation);a.setAckWindow(i.window),a.sendObject(r,wdi.SpiceVars.SPICE_MSGC_ACK_SYNC);break;case wdi.SpiceVars.SPICE_MSG_PING:r=new wdi.RedPing({id:i.id,time:i.time}).marshall();a.sendObject(r,wdi.SpiceVars.SPICE_MSGC_PONG);break;case wdi.SpiceVars.SPICE_MSG_MAIN_MOUSE_MODE:a.fire("mouseMode",i.current_mode);break;case wdi.SpiceVars.SPICE_MSG_NOTIFY:a.fire("notify")}}};wdi.SpiceChannel=$.spcExtend(wdi.EventObject.prototype,{counter:0,ackWindow:0,connectionId:0,socketQ:null,packetReassembler:null,channel:1,codec:wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_MJPEG,proxy:null,token:null,init:function(e){this.superInit(),this.socketQ=e.socketQ||new wdi.SocketQueue,this.packetReassembler=e.packetReassembler||wdi.ReassemblerFactory.getPacketReassembler(this.socketQ),this.setListeners(),this.ackWindow=0},fireHandshakeTimeoutError:function(){var e=new Error("Handshake timeout");e.code=4200,wdi.Debug.error("Handshake timeout reached, raising error"),this.fire("error",e)},setListeners:function(){var e,i=this;this.packetReassembler.addListener("packetComplete",(function(t){var s=t;if("spicePacket"===s.status){wdi.Debug.log("packetComplete spicePacket"),wdi.logOperations&&(wdi.DataLogger.logNetworkTime(),e=Date.now());var a=this.getRawSpiceMessage(s.data);a&&(wdi.logOperations&&a.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY&&wdi.DataLogger.setStartTime(e),this.fire("message",a))}else if("reply"===s.status){wdi.Debug.log("packetComplete reply");var n=this.getRedLinkReplyBytes(s.data);this.send(n)}else if("errorCode"===s.status){wdi.Debug.log("packetComplete errorCode"),(n=this.getErrorCodeBytes(s.data))&&(this.send(n),this.channel,wdi.SpiceVars.SPICE_CHANNEL_DISPLAY),this.fire("channelConnected")}else i.fireHandshakeTimeoutError()}),this),this.socketQ.addListener("open",(function(){var e=this.getRedLinkMessBytes();this.send(e),this.proxy&&this.proxy.end()}),this),this.socketQ.addListener("close",(function(e){1===this.channel&&this.fire("error",e),this.socketQ.disconnect()}),this),this.socketQ.addListener("error",(function(e){this.fire("error",e),this.socketQ.disconnect()}),this)},changeCodec:function(e){this.sendObject([...wdi.SpiceObject.numberTo16(2),...wdi.SpiceObject.numberTo16(e),...wdi.SpiceObject.numberTo16(3)],wdi.SpiceVars.SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE),wdi.currentCodec=e;const{$console:i}=useNuxtApp();i.changeCodec(e),console.log(`codec changed: ${e}`)},connect:function(e,i,t,s){var a=wdi.Utils.generateWebSocketUrl(e.protocol,e.host,e.port,e.vmHost,e.vmPort,"spice",e.vmInfoToken,e.vmid);this.channel=i,this.connectionId=t||0,this.socketQ.connect(a),this.proxy=s,this.token=e.token,this.packetReassembler.start()},disconnect:function(){wdi.Debug.log("spicechannel disconnect"),this.counter=0,this.ackWindow=0,this.connectionId=0,this.socketQ.disconnect(),this.socketQ=null,this.packetReassembler.dispose(),this.packetReassembler=null,this.channel=1,this.proxy=null,this.token=null},send:function(e,i){this.socketQ.send(e,i)},sendObject:function(e,i,t){for(var s=0;s<e.length;s+=2048){var a=e.slice(s,s+2048),n=new wdi.SpiceDataHeader({type:i,size:a.length}).marshall();n=n.concat(a),this.send(n,t)}},arrayOfNumberToUint32:function(e){let i=0;for(let t of e)i|=1<<t;return i},setAckWindow:function(e){this.ackWindow=e,this.counter=0},getRawSpiceMessage:function(e){var i=wdi.GlobalPool.create("ViewQueue"),t=wdi.GlobalPool.create("ViewQueue"),s=new Uint8Array(e,0,wdi.SpiceDataHeader.prototype.objectSize);i.setData(s);var a=(new wdi.SpiceDataHeader).demarshall(i);wdi.GlobalPool.discard("ViewQueue",i);var n=e.subarray(wdi.SpiceDataHeader.prototype.objectSize);if(t.setData(n),this.counter++,this.ackWindow&&this.counter===this.ackWindow){this.counter=0;var o=new wdi.SpiceDataHeader({type:wdi.SpiceVars.SPICE_MSGC_ACK,size:0}).marshall();this.send(o)}var c=wdi.PacketLinkFactory.extract(a,t)||!1;if(c)return wdi.PacketLinkProcess.process(a,c,this),wdi.GlobalPool.discard("ViewQueue",t),!1;var r=wdi.GlobalPool.create("RawSpiceMessage");return r.set(a,t,this.channel),r},getRedLinkReplyBytes:function(e){if(this.token){var i=new wdi.ViewQueue;i.setData(e),i.eatBytes(wdi.SpiceLinkHeader.prototype.objectSize);var t=(new wdi.SpiceLinkReply).demarshall(i);const s=window.password||this.token;return wdi.SpiceObject.stringHexToBytes(RSA_public_encrypt(s,t.pub_key))}return wdi.SpiceObject.stringToBytesPadding("",128)},getRedLinkMessBytes:function(){var e=new wdi.SpiceLinkHeader({magic:1363428690,major_version:2,minor_version:2,size:26}).marshall(),i=new wdi.SpiceLinkMess({connection_id:this.connectionId,channel_type:this.channel,caps_offset:18,num_common_caps:1,num_channel_caps:1,common_caps:1<<wdi.SpiceVars.SPICE_COMMON_CAP_MINI_HEADER,channel_caps:this.arrayOfNumberToUint32([wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_SIZED_STREAM,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_STREAM_REPORT,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_MONITORS_CONFIG,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_MULTI_CODEC,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_MJPEG,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_VP8,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_H264,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_VP9,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_H265,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_LZ4_COMPRESSION,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_PREF_COMPRESSION])}).marshall();return e.concat(i)},getErrorCodeBytes:function(e){var i=wdi.GlobalPool.create("ViewQueue");i.setData(e);var t=wdi.SpiceObject.bytesToInt32NoAllocate(i);if(wdi.GlobalPool.discard("ViewQueue",i),0===t){if(this.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY){var s=new wdi.SpiceDataHeader({type:wdi.SpiceVars.SPICE_MSGC_DISPLAY_INIT,size:14}).marshall(),a=new wdi.SpiceCDisplayInit({pixmap_cache_id:1,pixmap_cache_size:1,glz_dictionary_id:0,glz_dictionary_window_size:0}).marshall();return s.concat(a)}if(this.channel==wdi.SpiceVars.SPICE_CHANNEL_MAIN)return new wdi.SpiceDataHeader({type:wdi.SpiceVars.SPICE_MSGC_MAIN_ATTACH_CHANNELS,size:0}).marshall()}else{if(7!==t)throw new wdi.Exception({message:"Server refused client",errorCode:2});if(window.vmHasPassword){const e=location.pathname.match(/id=(.+)/)[1];let i=window.sessionStorage.getItem(`password-${e}`);window.passwordInit&&(i=""),window.password=i||window.prompt("Enter the password"),window.password&&window.sessionStorage.setItem(`password-${e}`,window.password),window.passwordInit=!0}}}});wdi.BusConnection=$.spcExtend(wdi.EventObject.prototype,{ws:null,subscriptions:[],_busUser:null,_busPass:null,queue:"",binary:!1,init:function(s){this.superInit(),this.ws=s.websocket||new wdi.WebSocketWrapper,this.clusterNodeChooser=s.clusterNodeChooser||new wdi.ClusterNodeChooser,this.binary=s.binary||!1},connect:function(s){s.useBus?(this._vdiBusToken=s.vdiBusToken,s.busHostList||(wdi.Debug.warn("Deprecated: using old busHost & busPort params"),s.busHostList=[{host:s.busHost,port:s.busPort}]),this.clusterNodeChooser.setNodeList(s.busHostList),Modernizr.websocketsbinary&&(this.binary=!0),this._busUser=s.busUser,this._busPass=s.busPass,this._websockifyProtocol=s.protocol,this._websockifyHost=s.host,this._websockifyPort=s.port,this.subscriptions=s.busSubscriptions,this._connectToNextHost()):wdi.Debug.warn("Not using the bus")},_connectToNextHost:function(){var s=this.clusterNodeChooser.getAnother(),t=wdi.Utils.generateWebSocketUrl(this._websockifyProtocol,this._websockifyHost,this._websockifyPort,s.host,s.port,"raw",this._vdiBusToken),e="base64";this.binary&&(e="binary"),this.ws.connect(t,e),wdi.Debug.log("BusConnection: using protocol: "+e),this.binary&&this.ws.setBinaryType("arraybuffer"),this.setListeners()},disconnect:function(){this.ws.close(),this.queue="",this.subscriptions=[]},setListeners:function(){var s=this;this.ws.onOpen((function(t){s._send("CONNECT\nlogin:"+s._busUser+"\npasscode:"+s._busPass+"\n\n\0")})),this.ws.onMessage((function(t){var e,n;s.binary?(e=String.fromCharCode.apply(null,new Uint8Array(t.data)),e=decodeURIComponent(escape(e))):e=Base64.decodeStr(t.data);var i=e.split("\0");if(1==i.length)s.queue+=i[0];else{for(var o=0;o<i.length-1;o++)e=s.queue+i[o],n=s.parseMessage(e),s.fire("busMessage",n),s.queue="";s.queue=i[i.length-1]}})),this.ws.onClose((function(t){wdi.Debug.log("BusConnection CLOSED! connecting again in 1 second"),s.fire("error",t)})),this.ws.onError((function(s){wdi.Debug.error("BusConnection ERROR:",s)}))},parseMessage:function(s){try{var t=s.split("\n\n"),e=t[0].trim(),n=t[1].replace(/\x00/,"").trim();n=0!=n.length?JSON.parse(n):null;var i=(t=e.split("\n")).shift();e="{";for(var o=t.length,r=0;r<o;r++){var u=t[r].split(":")[0];e+='"'+u+'":"'+t[r].replace(u+":","")+'"',r!=o-1&&(e+=",")}return e+="}",{verb:i,header:JSON.parse(e),body:n}}catch(s){return wdi.Debug.error("Error parsing Bus Info: ",s),{verb:"ERROR"}}},setSubscriptions:function(){for(var s=this.subscriptions.length,t=0;t<s;t++)this.subscribe(this.subscriptions[t])},send:function(s){var t=this.subscriptions[0];this._send("SEND\ndestination:"+t+"\ncontent-type:text/plain\n\n"+JSON.stringify(s)+"\0")},subscribe:function(s){this._send("SUBSCRIBE\ndestination:"+s+"\n\n\0")},_send:function(s){this.binary?this.ws.send(s):this.ws.send(Base64.encodeStr(s))}});wdi.WebSocketWrapper=$.spcExtend({},{ws:{},onopen:null,onmessage:null,onclose:null,onerror:null,init:function(){},connect:function(n,o){this.ws=new WebSocket(n,o)},onOpen:function(n){this.ws.onopen=n},onMessage:function(n){this.ws.onmessage=n},onClose:function(n){this.ws.onclose=n},onError:function(n){this.ws.onerror=n},setBinaryType:function(n){this.ws.binaryType=n},close:function(){this.ws&&this.ws.close&&(this.ws.close(),this.ws.onopen=function(){},this.ws.onmessage=function(){},this.ws.onclose=function(){},this.ws.onerror=function(){},this.onopen=function(){},this.onmessage=function(){},this.onclose=function(){},this.onerror=function(){})},send:function(n){this.ws.send(n)}});wdi.ConnectionControl=$.spcExtend(wdi.EventObject.prototype,{socket:null,pendingTimeToConnectionLost:null,previousTimeOut:null,init:function(t){this.superInit(),this.socket=t.socket||new wdi.Socket},connect:function(t){var n=wdi.Utils.generateWebSocketUrl(t.protocol,t.host,t.port,null,null,"raw",t.heartbeatToken);this.socket.connect(n),this.pendingTimeToConnectionLost=t.heartbeatTimeout,wdi.Debug.log("ConnectionControl: connected"),this.setListeners()},disconnect:function(){wdi.Debug.log("Connection Control disconnect"),this.previousTimeOut&&clearTimeout(this.previousTimeOut),this.socket.disconnect(),this.socket=null,this.pendingTimeToConnectionLost=null,this.previousTimeOut=null},setListeners:function(){var t=this;this.socket.setOnMessageCallback((function(n){wdi.Debug.log("ConectionControl: beat"),clearTimeout(t.previousTimeOut),t.previousTimeOut=setTimeout((function(){wdi.Debug.log("ConnectionControl: firing connectionLost event"),t.fire("connectionLost",n)}),t.pendingTimeToConnectionLost)}))}});wdi.CheckActivity=$.spcExtend(wdi.EventObject.prototype,{init:function(t){this.superInit(),this.milliseconds=t||6e5,this.eventHandlers={keydown:this.resetActivity.bind(this),mousemove:this.resetActivity.bind(this),click:this.resetActivity.bind(this)},this.activityTimeout=this.createTimeout(),$(document).on(this.eventHandlers)},resetActivity:function(t){clearTimeout(this.activityTimeout),this.activityTimeout=this.createTimeout()},createTimeout:function(){var t=this;return setTimeout((function(){t.fire("activityLost")}),this.milliseconds)},dispose:function(){$(document).off(this.eventHandlers),clearTimeout(this.activityTimeout)}});wdi.Agent=$.spcExtend(wdi.EventObject.prototype,{clientTokens:null,serverTokens:10,app:null,clipboardEnabled:!0,windows:null,clipboard:null,DELAY_BETWEEN_GRAB_AND_CTRLV:30,init:function(e){this.superInit(),this.app=e.app,this.clipboard=new wdi.Clipboard},dispose:function(){this.clientTokens=null,this.serverTokens=10,this.app=null,this.clipboardContent=null,this.clipboardEnabled=!0,this.windows=null},sendInitMessage:function(){var e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_START,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.SpiceMsgMainAgentTokens({num_tokens:this.serverTokens})});this.app.spiceConnection.send(e);var n=1<<wdi.AgentCaps.VD_AGENT_CAP_MONITORS_CONFIG;this.clipboardEnabled&&(n|=1<<wdi.AgentCaps.VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);var s={type:wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES,opaque:0,data:new wdi.VDAgentAnnounceCapabilities({request:0,caps:n})};this.sendAgentPacket(s)},setResolution:function(e,n){e<800&&(e=800),n<600&&(n=600);var s={type:wdi.AgentMessageTypes.VD_AGENT_MONITORS_CONFIG,opaque:0,data:new wdi.VDAgentMonitorsConfig({num_of_monitors:1,flags:0,data:new wdi.VDAgentMonConfig({width:e,height:n,depth:32,x:0,y:0})})};this.sendAgentPacket(s)},setClientTokens:function(e){this.clientTokens=e},sendAgentPacket:function(e){this.clientTokens--;var n=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.VDAgentMessage({protocol:1,type:e.type,opaque:e.opaque,data:e.data})});this.app.spiceConnection.send(n)},sendServerTokens:function(){var e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_TOKEN,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.SpiceMsgMainAgentTokens({num_tokens:10})});this.app.spiceConnection.send(e),this.serverTokens=10},onAgentData:function(e){if(this.serverTokens--,0==this.serverTokens&&this.sendServerTokens(),e.type==wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES);else if(e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB){var n=this.clipboard.createRequest(e.clipboardType);this.sendAgentPacket(n)}else if(e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD)this.fire("clipBoardData",e.clipboardData);else if(e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST){n=this.clipboard.createContent();this.sendAgentPacket(n)}else e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_RELEASE||e.type==wdi.AgentMessageTypes.VD_AGENT_REPLY||(e.type==wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_TOKEN?this.clientTokens+=e.args.num_tokens:console.warn("unknown message received by agent",e))},setClipboard:function(e){this.clipboard.setContent(e);var n=this.clipboard.createGrab();this.sendAgentPacket(n)},disableClipboard:function(){this.clipboardEnabled=!1}});wdi.CodecH264={video:{},jmuxer:{},loadedVideo:{},queues:{},isReady:{},create:function(e){if(this.video[e])return;const t=document.createElement("video");t.id=`video${e}`,t.setAttribute("autoplay",""),this.video[e]=t,this.jmuxer[e]=new JMuxer({node:t,mode:"video",flushingTime:0,fps:60,onReady:()=>{this.isReady[e]=!0}})},addQueue:function(e,t){this.queues[e]||(this.queues[e]=[]),this.queues[e].push(t)},resetQueues:function(e){this.queues[e]=[]},feed:function(e,t){this._addListener(e),this.queues[e]?.length&&(this.queues[e].forEach((t=>{this.jmuxer[e].feed({video:t})})),this.resetQueues(e)),this.jmuxer[e].feed({video:t})},destroy:function(e){this._removeListener(e),this.video[e]?.remove(),this.video={},this.jmuxer={},this.loadedVideo={}},_addListener:function(e){this.video[e]?.removeEventListener("loadedmetadata",this.loadedVideo[e]),this.video[e].addEventListener("loadedmetadata",this.loadedVideo[e])},_removeListener:function(e){this.video[e]?.removeEventListener("loadedmetadata",this.loadedVideo[e])}},wdi.CodecVp8={decoders:{},create:function(e){this.decoders[e]=new vp8_decoder_ctx},destroy:function(){this.decoders={}},feed:function(e,t,i,d){const s=vp8_dixie_decode_frame(this.decoders[e],t,t.length);VPX_CODEC_OK===s&&this._I420toRGBA(this.decoders[e].ref_frames[0].img,i,d)},_I420toRGBA:function(e,t,i){const d=e.w,s=e.d_h,o=e.d_w;let n,r,u,a=t.createImageData(o,s),h=a.data;for(let t=0;t<s;t++)for(let i=0;i<o;i++){const a=e.planes[0][e.planes_off[0]+0+i+d*t],c=e.planes[1][e.planes_off[1]+0+(i>>1)+(d>>1)*(t>>1)],f=e.planes[2][e.planes_off[2]+0+(i>>1)+(d>>1)*(t>>1)];n=Math.round(a+1.13983*(f-128)),r=Math.round(a-.39465*(c-128)-.5806*(f-128)),u=Math.round(a+2.03211*(c-128));const m=4*((s-1-t)*o+i);h[m]=n,h[m+1]=r,h[m+2]=u,h[m+3]=255}t.putImageData(a,i.x,i.y)}},wdi.CodecH265={queue:{},configed:{},isReady:{},decoders:{},pendingFrames:{},underflow:{},baseTime:{},create:async function(e,t,i){const d={output:this._handleFrame.bind(this,e,t,i),error:e=>{console.log(e)}},s={codec:wdi.SpiceVideoCodecValue[wdi.currentCodec],codedWidth:640,codedHeight:480},{supported:o}=await VideoDecoder.isConfigSupported(s);o?(this.decoders[e]=new VideoDecoder(d),this.decoders[e].configure(s),this.isReady[e]=!0):(window.alert("H.265 codec is not supported in this browser. Please try a different codec or use another browser."),console.log("not supported"))},destroy:function(){this.queue={},this.configed={},this.isReady={},this.decoders={},this.pendingFrames={},this.underflow={},this.baseTime={}},addQueue:function(e,t){this.queues[e]||(this.queues[e]=[]),this.queues[e].push(t)},resetQueues:function(e){this.queues[e]=[]},setConfig:function(e,t){const i={codec:wdi.SpiceVideoCodecValue[wdi.currentCodec],codedWidth:t.width,codedHeight:t.height};this.decoders[e].configure(i),this.configed[e]=!0},decode:function(e,t){this.queue[e]?.length&&(this.queue[e].forEach((t=>{const i=new EncodedVideoChunk({type:"key",data:t,timestamp:performance.now()});this.decoders[e].decode(i)})),this.resetQueues(e));const i=new EncodedVideoChunk({type:"key",data:t,timestamp:performance.now()});this.decoders[e].decode(i)},_handleFrame:function(e,t,i,d){this.pendingFrames[e]||(this.pendingFrames[e]=[]),this.pendingFrames[e].push(d),void 0===this.underflow[e]&&(this.underflow[e]=!0),this.underflow[e]&&setTimeout(this._renderFrame.bind(this,e,t,i),0)},_renderFrame:async function(e,t,i){if(this.underflow[e]=0===this.pendingFrames[e].length,this.underflow[e])return;const d=this.pendingFrames[e].shift(),s=this._calculateTimeUntilNextFrame(d.timestamp,e);await new Promise((e=>{setTimeout(e,s)})),t.drawImage(d,i.x,i.y,i.width,i.height),d.close(),setTimeout(this._renderFrame.bind(this,e,t,i),0)},_calculateTimeUntilNextFrame:function(e,t){this.baseTime[t]||(this.baseTime[t]=performance.now());const i=performance.now()-this.baseTime[t];return Math.max(0,e/1e3-i)}};wdi.Clipboard=$.spcExtend(wdi.EventObject.prototype,{_blob:null,_type:null,getSpiceType:function(e){switch(e){case"text/plain":return wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT;case"image/png":return wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_IMAGE_PNG;default:throw new Error("Unsupported mime type "+e)}},getMimeType:function(e){switch(e){case wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT:return"text/plain";case wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_IMAGE_PNG:return"image/png";default:throw new Error("Unsupported spice type "+e)}},createGrab:function(){return{type:wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB,opaque:0,data:new wdi.VDAgentClipboardGrab({types:[this.getSpiceType(this._type)]})}},createRequest:function(e){return{type:wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST,opaque:0,data:new wdi.VDAgentClipboardRequest({type:e})}},createContent:function(){return{type:wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD,opaque:0,data:new wdi.VDAgentClipboard({type:this.getSpiceType(this._type),data:this._blob})}},setContent:function(e){this._type=e.type,this._blob=e.blob},getContent:function(){return{blob:this._blob,type:this._type}}});wdi.ClipboardDataParser=$.spcExtend(wdi.EventObject.prototype,{fileReader:null,init:function(e){this.fileReader=e.FileReader||FileReader},parse:function(e,t){var n=this,r=["image/png","text/plain"];function i(e,t){switch(e.kind){case"string":return function(e,t){var n=e.type;e.getAsString((function(e){return t({type:n,blob:e})}))}(e,t);case"file":return function(e,t){var r=e.type,i=e.getAsFile(),a=new n.fileReader;a.addEventListener("loadend",(function(){return t({type:r,blob:a.result})})),a.readAsArrayBuffer(i)}(e,t)}}var a=e.items;if(a)for(var l=0;l<r.length;l++)for(var f=r[l],s=0;s<a.length;s++){var o=a[s];if(o.type==f)return i(o,t)}else if(e.getData){f="text/plain";e.types.contains(f)&&t({type:f,blob:e.getData(f)})}}});wdi.LocalClipboard=$.spcExtend(wdi.EventObject.prototype,{init:function(o){this.clipboardContainer=$('<div style="position:absolute;top:-10000000px;"><textarea id="remoteClipboard" style="position:absolute;top:-10000000px;font-size: 20px;color:black;z-index: 100" rows="4" cols="50"></textarea></div>'),$("#vmw").prepend(this.clipboardContainer),this.clientGui=o.clientGui,this.eventHandlers={keydown:this.triggerCopyToClipboard.bind(this)},$(document).on(this.eventHandlers),this.delayCopyEvents={mousedown:this.copyToClipboard.bind(this),mouseup:this.copyToClipboard.bind(this),keydown:this.copyToClipboard.bind(this),keyup:this.copyToClipboard.bind(this)},$(document).on(this.delayCopyEvents)},updateClipboardBuffer:function(o){$("#remoteClipboard").val(o)},triggerCopyToClipboard:function(o){(function(o){var e=o.ctrlKey;return-1!=navigator.appVersion.indexOf("Mac")&&(e=o.metaKey),67===o.keyCode&&e})(o)&&(this.clipboardCopyDelay=Date.now()+1e3,o.preventDefault(),this.copyToClipboard(o))},copyToClipboard:function(o){if(this.clipboardCopyDelay&&!(this.clipboardCopyDelay<Date.now())){!function(o){$("#remoteClipboard").focus();try{var e=document.execCommand("copy");$("#remoteClipboard").blur(),$("#inputmanager").focus(),console.log("Result executeCommand",o.type,"-----",e)}catch(o){console.error(o)}}(o)}},dispose:function(){this.clipboardContainer.remove(),$(document).off(this.eventHandlers),$(document).off(this.delayCopyEvents)}});wdi.SpiceConnection=$.spcExtend(wdi.EventObject.prototype,{channels:null,connectionId:null,connectionInfo:null,runQ:null,token:null,connectionControl:null,init:function(n){this.superInit(),this.channels={},this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN]=n.mainChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_DISPLAY]=n.displayChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_INPUTS]=n.inputsChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_CURSOR]=n.cursorChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK]=n.playbackChannel||new wdi.SpiceChannel,this.runQ=n.runQ||new wdi.RunQueue,this.connectionControl=n.connectionControl||new wdi.ConnectionControl,this.setup()},connect:function(n){this.connectionInfo=n,n.connectionControl&&this.connectionControl.connect(n),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].connect(this.connectionInfo,wdi.SpiceVars.SPICE_CHANNEL_MAIN)},disconnect:function(){for(var n in wdi.Debug.log("spiceConnection disconnect"),this.runQ.clear(),this.clearEvents(),this.channels)this.channels[n].disconnect(),this.channels[n].clearEvents(),this.channels[n]=null,delete this.channels[n];this.connectionControl.disconnect(),this.runQ=null,this.token=null,this.channels=null,this.connectionId=null,this.connectionInfo=null,this.connectionControl=null},send:function(n){var e=n.args.marshall();this.channels[n.channel]?this.channels[n.channel].sendObject(e,n.messageType):console.error("channel not available",n.channel)},setup:function(){this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("connectionId",this.onConnectionId,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("channelListAvailable",this.onChannelList,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("mouseMode",this.onMouseMode,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("initAgent",this.onInitAgent,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("notify",this.onNotify,this),this.connectionControl.addListener("connectionLost",this.onDisconnect,this),this._setConnectedListeners();var n=null;for(var e in n=wdi.exceptionHandling?this.onChannelMessageExceptionHandled:this.processChannelMessage,this.channels)this.channels.hasOwnProperty(e)&&(this.channels[e].addListener("message",n,this),this.channels[e].addListener("status",this.onStatus,this),this.channels[e].addListener("error",this.onDisconnect,this))},_setConnectedListeners:function(){this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_MAIN),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_DISPLAY),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_INPUTS),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_CURSOR),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK)},_setConnectedListener:function(n){this.channels[n].addListener("channelConnected",(function(){this.fire("channelConnected",n)}),this)},onDisconnect:function(n){this.fire("error",n)},onConnectionId:function(n){this.connectionId=n},onChannelList:function(n){this.connectChannels(n)},connectChannels:function(n){for(var e in this.channels)(e=parseInt(e,10))!=wdi.SpiceVars.SPICE_CHANNEL_MAIN&&-1!=n.indexOf(e)&&this.runQ.add((function(n,e){this.channels[e].connect(this.connectionInfo,e,this.connectionId,n)}),this,!1,e);this.runQ.process()},onInitAgent:function(n){var e=n;this.fire("initAgent",e)},onMouseMode:function(n){var e=n;this.fire("mouseMode",e)},onNotify:function(n){this.fire("notify")},onStatus:function(n){},onChannelMessageExceptionHandled:function(n){try{return this.processChannelMessage(n)}catch(n){wdi.Debug.error("SpiceConnection: Packet decodification error",n)}},processChannelMessage:function(n){var e=wdi.PacketFactory.extract(n);wdi.GlobalPool.discard("ViewQueue",n.body),wdi.GlobalPool.discard("RawSpiceMessage",n),e?this.fire("message",e):(wdi.Debug.log("Unknown packet "+n.channel+" "+n.header.type),wdi.Debug.log(n))}});wdi.SPICE_INPUT_MOTION_ACK_BUNCH=8,wdi.ClientGui=$.spcExtend(wdi.EventObject.prototype,{width:null,height:null,canvas:null,ack_wait:0,mouse_mode:0,mouse_status:0,eventLayer:null,counter:0,mainCanvas:0,firstTime:!0,clientOffsetX:0,clientOffsetY:0,magnifier:null,magnifierBackground:null,firstMove:!0,isMagnified:!0,isMouseDown:!1,soundStarted:!1,canvasMarginY:0,canvasMarginX:0,stuckKeysHandler:null,isKeyboardEnabled:!1,subCanvas:{},inputManager:null,clipboardEnabled:!0,layer:null,freezeClass:"freeze",app:{},init:function(e){this.time=Date.now(),this.canvas={},this.contexts={},this.superInit(),this.magnifier=window.$("<canvas/>").attr({width:150,height:150}).css({position:"absolute",left:"0px",top:"0px"}),this.stuckKeysHandler=e.stuckKeysHandler||new wdi.StuckKeysHandler,this.settings=e.settings||{},this.stuckKeysHandler.addListener("inputStuck",this._sendInput.bind(this),this),this.magnifierBackground=window.$("<img/>"),this.magnifierBackground.attr("src","/spice-console/resources/magnifier.png"),this.initSound(),this.inputManager=e.inputManager||new wdi.InputManager({stuckKeysHandler:this.stuckKeysHandler,window:$(window)}),this.inputManager.setCurrentWindow(window),this.clipBoardDataParser=e.clipBoardDataParser||new wdi.ClipboardDataParser({}),this.localClipboard=e.localClipboard||new wdi.LocalClipboard({clientGui:this}),this.app=e.app;var t=this;this.eventHandlers={hide:function(){t.stuckKeysHandler.releaseAllKeys()}},window.$(document).on(this.eventHandlers)},dispose:function(){wdi.Debug.log("Disposing ClientGui"),$(document).off(this.eventHandlers),this.unbindDOM(),this.removeAllCanvases(),this.inputManager.dispose(),this.stuckKeysHandler.dispose(),this.localClipboard.dispose(),this.width=null,this.height=null,this.canvas=null,this.ack_wait=0,this.mouse_mode=0,this.mouse_status=0,this.eventLayer=null,this.counter=0,this.mainCanvas=0,this.firstTime=!0,this.clientOffsetX=0,this.clientOffsetY=0,this.magnifier=null,this.magnifierBackground=null,this.firstMove=!0,this.isMagnified=!0,this.isMouseDown=!1,this.soundStarted=!1,this.canvasMarginY=0,this.canvasMarginX=0,this.stuckKeysHandler=null,this.subCanvas={},this.inputManager=null,this.clipboardEnabled=!0,this.layer=null,clearInterval(self.rightClickTimer),clearInterval(self.mouseDownTimer)},removeAllCanvases:function(){var e=this;Object.keys(this.canvas).forEach((function(t){$(e.canvas[t]).remove(),delete e.canvas[t],delete e.contexts[t]})),$(this.eventLayer).remove(),this.eventLayer=null},unbindDOM:function(){if(this.eventLayer){["touchstart","touchmove","touchend","mouseup","mousedown","mousemove","contextmenu","mousewheel"].forEach((function(e){$(this.eventLayer).unbind(e)}))}},freeze:function(){if(this.canvas[0]){var e=new Image,t=this.canvas[0],n=$(t);$(e).attr("style",n.attr("style")),$(e).attr("class",this.freezeClass),e.src=t.toDataURL("image/png"),n.parent().append($(e))}},cancelFreeze:function(){$("."+this.freezeClass).remove()},setLayer:function(e){this.layer=e},disableClipboard:function(){this.clipboardEnabled=!1},_sendInput:function(e){var t=e,n=t[0],i=t[1];this.fire("input",[n,i])},releaseAllKeys:function(){this.stuckKeysHandler.releaseAllKeys()},getContext:function(e){return this.contexts[e]},getCanvas:function(e){return this.canvas[e]},checkFeatures:function(){return!(!Modernizr.canvas||!Modernizr.websockets)||(alert("Your Browser is not compatible with WDI. Visit ... for a list of compatible browsers"),!1)},deleteSubCanvas:function(e){var t=this.subCanvas[e.hwnd];return this.subCanvas[e.hwnd]=null,t},moveSubCanvas:function(e){var t=this.subCanvas[e.hwnd];return t.info=e,this._fillSubCanvasFromWindow(e),t},resizeSubCanvas:function(e){var t=this.subCanvas[e.hwnd];return $([t.canvas,t.eventLayer]).attr({width:e.width,height:e.height}),t.info=e,this._fillSubCanvasFromWindow(e),t},_fillSubCanvasFromWindow:function(e){var t=parseInt(e.top,10),n=parseInt(e.left,10),i=parseInt(e.width,10),a=parseInt(e.height,10);this.fillSubCanvas({top:t,left:n,right:n+i,bottom:t+a})},createNewSubCanvas:function(e){var t=this.createEventLayer(e.hwnd+"_event",e.width,e.height);return this.subCanvas[e.hwnd]={canvas:$("<canvas/>").attr({width:e.width,height:e.height}).css({display:e.iconic?"none":"block"})[0],eventLayer:t,info:e,position:0},this.canvas[this.mainCanvas]&&this._fillSubCanvasFromWindow(e),[this.subCanvas[e.hwnd]]},fillSubCanvas:function(e){var t=this.canvas[this.mainCanvas],n=null;for(var i in this.subCanvas)if(null!=this.subCanvas[i]&&void 0!==this.subCanvas[i]&&this.subCanvas.hasOwnProperty(i))if(n=this.subCanvas[i].info,null!=e||null!=e){var a=parseInt(n.top,10),s=parseInt(n.left,10),o={top:a,left:s,right:s+parseInt(n.width,10),bottom:a+parseInt(n.height,10)};wdi.CollisionDetector.thereIsBoxCollision(o,e)&&this._doDrawSubCanvas(t,this.subCanvas[i],n)}else this._doDrawSubCanvas(t,this.subCanvas[i],n)},_doDrawSubCanvas:function(e,t,n){if(null!=this.canvas[this.mainCanvas]&&null!=this.canvas[this.mainCanvas]){var i=null;if(0===n.iconic){i=t.canvas.getContext("2d");var a=0,s=0,o=+n.width,r=+n.height,u=+n.left,l=+n.top;u<0&&(o+=u,a=-u,u=0),l<0&&(r+=l,s=-l,l=0);try{o=Math.max(1,Math.floor(o)),r=Math.max(1,Math.floor(r)),o>e.width&&(o=e.width),r>e.height&&(r=e.height),i.drawImage(e,u,l,o,r,a,s,o,r)}catch(e){wdi.Debug.error(e)}}}},removeCanvas:function(e){var t=e.args;t.surface_id===this.mainCanvas&&($(this.eventLayer).remove(),this.eventLayer=null),this.canvas[t.surface_id].keepAlive=!1,delete this.canvas[t.surface_id],delete this.contexts[t.surface_id]},drawCanvas:function(e){wdi.Debug.log("clientgui time: ",this.time);var t=e.args,n=wdi.GlobalPool.create("Canvas");if(n.keepAlive=!0,n.id="canvas_"+t.surface_id,n.width=t.width*this.pixelRatio,n.height=t.height*this.pixelRatio,n.style.position="absolute",n.style.top=this.canvasMarginY+"px",n.style.left=this.canvasMarginX+"px",n.style.width=t.width+"px",n.style.height=t.height+"px",this.canvas[t.surface_id]=n,this.contexts[t.surface_id]=n.getContext("2d"),t.flags&&!wdi.SeamlessIntegration){this.mainCanvas=t.surface_id,this.eventLayer=this.createEventLayer("eventLayer",t.width,t.height);var i=$(this.eventLayer).css({position:"absolute",top:this.canvasMarginY+"px",left:this.canvasMarginX+"px"})[0];this.layer?(this.layer.appendChild(n),this.layer.appendChild(i)):(document.body.appendChild(n),document.body.appendChild(i)),!this.isKeyboardEnabled&&this.enableKeyboard()}if(this.firstTime&&this.clipboardEnabled){var a=this,s=this.settings.PASTES_PER_SECOND||5,o=_.throttle((function(e){a.fire("paste",e)}),1e3/s);$(document).bind("paste",(function(e){a.clipBoardDataParser.parse(e.originalEvent.clipboardData,o)})),$(document).bind("copy",(function(e){a.app.sendShortcut(wdi.keyShortcutsHandled.CTRLC)})),this.firstTime=!1}t.flags&&this.fire("resolution",[this.canvas[t.surface_id].width,this.canvas[t.surface_id].height])},disableKeyboard:function(){var e=window.$(window.document);e.unbind("keydown",this.handleKey),e.unbind("keyup",this.handleKey),e.unbind("keypress",this.handleKey),this.inputManager.disable()},enableKeyboard:function(){var e=this,t=window.$(window.document);t.keydown([e],this.handleKey),t.keypress([e],this.handleKey),t.keyup([e],this.handleKey),this.inputManager.enable(),!this.isKeyboardEnabled&&(this.isKeyboardEnabled=!0)},setCanvasMargin:function(e){this.canvasMarginX=e.x,this.canvasMarginY=e.y},createEventLayer:function(e,t,n){var i=this,a=$("<canvas/>").css({cursor:"default",position:"absolute"}).attr({id:e,width:t,height:n});window.bowser.firefox&&a.attr("contentEditable",!0),a.bind("touchstart",(function(e){e.preventDefault();var t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],n=t.pageX,a=t.pageY;i.generateEvent.call(i,"mousemove",[n+i.clientOffsetX,a+i.clientOffsetY,i.mouse_status]),1===e.originalEvent.touches.length?(i.enabledTouchMove=!0,i.launchRightClick.call(i,n,a)):2===e.originalEvent.touches.length?(i.touchX=n,i.touchY=a,i.enabledTouchMove=!1):3===e.originalEvent.touches.length&&(i.touchY3=a,i.enabledTouchMove=!1)})),a.bind("touchmove",(function(e){var t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],n=t.pageX,a=t.pageY;if(1===e.originalEvent.touches.length&&i.enabledTouchMove){i.isMagnified=!0,clearInterval(i.rightClickTimer),i.isMouseDown||(clearInterval(i.mouseDownTimer),i.launchMouseDown()),i.generateEvent.call(i,"mousemove",[n+i.clientOffsetX,a+i.clientOffsetY-80,i.mouse_status]);var s=$(this).offset(),o=n-s.left,r=a-s.top;i.firstMove&&($("body").append(i.magnifier),i.firstMove=!1);var u=o-75,l=r-160;i.magnifier.css({left:u,top:l});var h=i.magnifier[0].getContext("2d");h.clearRect(0,0,150,150),h.save(),h.beginPath(),h.arc(75,75,75,0,2*Math.PI,!1),h.clip(),h.drawImage(i.getCanvas(0),o-50,r-50-80,100,100,0,0,150,150),h.drawImage(i.magnifierBackground[0],0,0),h.restore()}else if(2===e.originalEvent.touches.length){var c=i.touchY-a;if(Math.abs(c)>10){var d=c>0?4:3;i.touchX=n,i.touchY=a,i.generateEvent.call(i,"mousedown",d),i.generateEvent.call(i,"mouseup",d)}}else if(3===e.originalEvent.touches.length){(c=i.touchY3-a)>100&&document.getElementById("hiddeninput").select()}e.preventDefault()})),a.bind("touchend",(function(e){if(i.enabledTouchMove){var t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0];t.pageX,t.pageY;i.isMouseDown||i.generateEvent.call(i,"mousedown",0),i.isMouseDown=!1,i.generateEvent.call(i,"mouseup",0);$(this).offset();i.enabledTouchMove=!1,i.firstMove=!0,i.isMagnified&&i.magnifier.remove(),i.isMagnified=!1}clearInterval(i.rightClickTimer),clearInterval(i.mouseDownTimer)})),a.mouseup((function(e){var t=e.button;i.generateEvent.call(i,"mouseup",t),i.mouse_status=0,e.preventDefault()})),a.mousedown((function(e){var t=e.button;i.generateEvent.call(i,"mousedown",t),i.mouse_status=1,e.preventDefault()})),a.mousemove((function(e){var t=e.pageX,n=e.pageY;i.generateEvent.call(i,"mousemove",[(t+i.clientOffsetX-i.eventLayer.offsetLeft)*i.pixelRatio,(n+i.clientOffsetY-i.eventLayer.offsetTop)*i.pixelRatio,i.mouse_status]),e.preventDefault()})),a.bind("contextmenu",(function(e){return e.preventDefault(),!1}));var s=_.throttle((function(e,t){var n=t>0?3:4;return i.generateEvent.call(i,"mousedown",n),i.generateEvent.call(i,"mouseup",n),!1}),60);return a.bind("mousewheel",s),this.fire("eventLayerCreated",a[0]),wdi.VirtualMouse.setEventLayer(a[0],0,0,t,n,1),a[0]},launchRightClick:function(e,t){var n=this;this.rightClickTimer=setTimeout((function(){n.generateEvent.call(n,"mousedown",2),n.generateEvent.call(n,"mouseup",2),n.enabledTouchMove=!1}),400)},launchMouseDown:function(e,t){var n=this;this.mouseDownTimer=setTimeout((function(){n.isMouseDown=!0,n.generateEvent.call(n,"mousedown",0)}),1500)},showError:function(e){wdi.Debug.warn(e),$("<div/>",{id:"error"}).html(e).css({"background-color":"#ff4141"}).appendTo("body"),setTimeout("$('#error').remove()",2e3)},generateEvent:function(e,t){if("mousemove"===e||"joystick"===e)this.ack_wait<wdi.SPICE_INPUT_MOTION_ACK_BUNCH&&(this.ack_wait++,this.fire("input",[e,t]));else{if(e.indexOf("key")>-1){if(this.stuckKeysHandler.checkSpecialKey(e,t[0].keyCode),!this.shouldGenerateKeyEvents(t[0].keyCode))return;var n="keypress"===e?this.inputManager.getValue():"";"keypress"===e&&$("#inputmanager").val(""),n&&(t=this.inputManager.manageChar(n,t))}this.fire("input",[e,t])}},shouldGenerateKeyEvents:function(e){return!this.inputManager.isSpecialKey(e)},motion_ack:function(){this.ack_wait=0},setMouseMode:function(e){this.mouse_mode=e},handleKey:function(e){e.data[0].generateEvent.call(e.data[0],e.type,[e]),wdi.Keymap.isInKeymap(e.keyCode)&&"keypress"!==e.type&&e.preventDefault()},setClientOffset:function(e,t){this.clientOffsetX=e,this.clientOffsetY=t},setClipBoardData:function(e){navigator.clipboard.writeText(e)},setToLocalClipboard:function(e){this.localClipboard.updateClipboardBuffer(e.value)},getStuckKeysHandler:function(){return this.stuckKeysHandler},initSound:function(){var e=this;if(Modernizr.touch){var t=$("<button>Start</button>",{id:"startAudio"}).css({padding:"10px 25px",fontSize:"25px",fontFamily:"Verdana",cursor:"pointer",margin:"0 auto"}).click((function(){e.soundStarted=!0,e.fire("startAudio"),$("#soundButtonContainer").remove()})),n=$('<div id="messageContainer"><p>Click to start using your virtual session:</p></div>').css({color:"white",textAlign:"center",fontSize:"25px",fontFamily:"Verdana",marginTop:"75px"}),i=$("<div></div>",{id:"soundButtonContainer"});t.appendTo(n),n.appendTo(i),i.appendTo("body"),i.css({position:"absolute",zIndex:999999999,top:0,left:0,width:"100%",height:document.height,backgroundColor:"black"})}else this.soundStarted=!0,window.setTimeout((function(){e.fire("startAudio")}),100)}});wdi.PacketProcess=$.spcExtend(wdi.DomainObject,{processors:{},init:function(s){this.processors[wdi.SpiceVars.SPICE_CHANNEL_MAIN]=s.mainProcess||new wdi.MainProcess({app:s.app}),this.processors[wdi.SpiceVars.SPICE_CHANNEL_DISPLAY]=s.displayProcess||new wdi.DisplayPreProcess({clientGui:s.clientGui,disableMessageBuffering:s.disableMessageBuffering}),this.processors[wdi.SpiceVars.SPICE_CHANNEL_INPUTS]=s.inputsProcess||new wdi.InputProcess({clientGui:s.clientGui,spiceConnection:s.spiceConnection}),this.processors[wdi.SpiceVars.SPICE_CHANNEL_CURSOR]=s.cursorProcess||new wdi.CursorProcess,this.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK]=s.playbackProcess||new wdi.PlaybackProcess({app:s.app})},process:function(s){return wdi.exceptionHandling?this.processExceptionHandled(s):this.processPacket(s)},processExceptionHandled:function(s){try{return this.processPacket(s)}catch(s){wdi.Debug.error("PacketProcess: Error processing packet",s)}},processPacket:function(s){if(!s||!this.processors[s.channel])throw"Invalid channel or null message";this.processors[s.channel].process(s)},dispose:function(){wdi.Debug.log("Disposing PacketProcess all processors"),this.processors[wdi.SpiceVars.SPICE_CHANNEL_MAIN].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_DISPLAY].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_INPUTS].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_CURSOR].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK].dispose(),this.processors={}}});wdi.PacketFilter={restoreContext:!1,start:null,dispose:function(){wdi.Debug.log("Disposing PacketFilter"),this.restoreContext=!1,this.start=null},filter:function(e,t,i,a){if(wdi.logOperations&&(this.start=Date.now()),wdi.graphicDebug&&wdi.graphicDebug.debugMode&&wdi.graphicDebug.printDebugMessageOnFilter(e,a),wdi.IntegrationBenchmark&&wdi.IntegrationBenchmark.benchmarking){var r=new Date;wdi.IntegrationBenchmark.setStartTime(r.getTime())}if(e.args.base&&e.args.base.clip.type===wdi.SpiceClipType.SPICE_CLIP_TYPE_RECTS){var n=a.getContext(e.args.base.surface_id);n.save(),n.beginPath();for(var s=e.args.base.clip.rects.rects,o=s.length;o--;){var g=wdi.graphics.getBoxFromSrcArea(s[o]);n.rect(g.x,g.y,g.width,g.height)}n.clip(),this.restoreContext=e.args.base.surface_id}t.call(i,e)},notifyEnd:function(e,t){!1!==this.restoreContext&&(t.getContext(this.restoreContext).restore(),this.restoreContext=!1);if(wdi.SeamlessIntegration){var i=null;e.args.base&&e.args.base.box&&(i=e.args.base.box),t.fillSubCanvas(i)}if(wdi.graphicDebug&&wdi.graphicDebug.debugMode&&wdi.graphicDebug.printDebugMessageOnNotifyEnd(e,t),wdi.IntegrationBenchmark&&wdi.IntegrationBenchmark.benchmarking){var a=new Date;wdi.IntegrationBenchmark.setEndTime(a.getTime())}wdi.GlobalPool.cleanPool("Canvas"),wdi.GlobalPool.cleanPool("Image"),wdi.logOperations&&wdi.DataLogger.log(e,this.start)}};wdi.PacketFactory={dispose:function(){wdi.Debug.log("Disposing PacketFactory")},extract:function(e){var a=null;switch(e.channel){case wdi.SpiceVars.SPICE_CHANNEL_DISPLAY:if(wdi.graphicDebug&&wdi.graphicDebug.debugMode)var S=JSON.stringify(e);switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_DISPLAY_MODE:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_MARK:a=(new wdi.SpiceDisplayMark).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_RESET:a=(new wdi.SpiceDisplayReset).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS:a=(new wdi.SpiceCopyBits).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_LIST:a=(new wdi.SpiceResourceList).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS:case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_PALETTE:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES:a=(new wdi.SpiceDisplayInvalidAllPalettes).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CREATE:a=(new wdi.SpiceStreamCreate).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA:a=(new wdi.SpiceStreamData).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CLIP:a=(new wdi.SpiceStreamClip).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED:a=(new wdi.SpiceStreamDataSized).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT:a=(new wdi.SpiceStreamActiveReport).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY:a=(new wdi.SpiceStreamDestroy).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_CURRENT_VIDEO_ENCODE_SETUP_RESPONSE:const S=(new wdi.CodecConfig).demarshall(e.body);(new wdi.SpiceChannel).changeCodec(S.codec);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL:a=(new wdi.SpiceDrawFill).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_OPAQUE:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY:a=(new wdi.SpiceDrawCopy).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND:a=(new wdi.drawBlend).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLACKNESS:a=(new wdi.SpiceDrawBlackness).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_WHITENESS:a=(new wdi.SpiceDrawWhiteness).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_INVERS:a=(new wdi.SpiceDrawInvers).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ROP3:a=(new wdi.SpiceDrawRop3).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_STROKE:a=(new wdi.SpiceStroke).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TEXT:a=(new wdi.SpiceDrawText).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:a=(new wdi.drawTransparent).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:a=(new wdi.drawAlphaBlend).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_CREATE:a=(new wdi.SpiceSurface).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_DESTROY:a=(new wdi.SpiceSurfaceDestroy).demarshall(e.body)}break;case wdi.SpiceVars.SPICE_CHANNEL_INPUTS:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK:a=new Object;break;case wdi.SpiceVars.SPICE_MSG_INPUTS_INIT:const S=new wdi.SpiceModifierData,i=S.demarshall(e.body);S.setModifierData(i.data);break;case wdi.SpiceVars.SPICE_MSG_INPUTS_KEY_MODIFIERS:const d=new wdi.SpiceModifierData,r=d.demarshall(e.body);d.setModifierData(r.data)}break;case wdi.SpiceVars.SPICE_CHANNEL_MAIN:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_MAIN_INIT:a=(new wdi.RedMainInit).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_DATA:a=(new wdi.VDAgentMessage).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_DISCONNECTED:a=(new wdi.SpiceMsgMainAgentDisconnected).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_CONNECTED:a=(new wdi.SpiceMsgMainAgentConnected).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_MULTI_MEDIA_TIME:a=(new wdi.MainMultiMediaTime).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_CHANNELS_LIST:a=(new wdi.MainMChannelsList).demarshall(e.body)}break;case wdi.SpiceVars.SPICE_CHANNEL_CURSOR:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_CURSOR_INIT:a=(new wdi.RedCursorInit).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_CURSOR_SET:a=(new wdi.RedCursorSet).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_CURSOR_HIDE:a=(new wdi.RedCursorHide).demarshall(e.body,e.header.size)}break;case wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_PLAYBACK_MODE:a=(new wdi.PlaybackMode).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_START:a=(new wdi.PlaybackStart).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_STOP:a=(new wdi.PlaybackStop).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_DATA:a=(new wdi.PlaybackData).demarshall(e.body,e.header.size)}}return a?(wdi.graphicDebug&&wdi.graphicDebug.debugMode&&S&&(a.originalData=S),new wdi.SpiceMessage({messageType:e.header.type,channel:e.channel,args:a})):(wdi.Debug.log(e.header.type,e.header.channel),!1)}};Application=$.spcExtend(wdi.DomainObject,{spiceConnection:null,clientGui:null,agent:null,externalCallback:null,keyboardEnabled:!0,packetProcess:null,inputProcess:null,multimediaTime:null,lastMultimediaTime:null,busConnection:null,busProcess:null,timeLapseDetector:null,connectionInfo:null,reconnecting:null,checkActivity:null,configs:null,init:function(e){this.disposed=!1,e?this.configs=e:e=this.configs||{},wdi.spiceClientPath=e.spiceClientPath||"",wdi.Debug.log("application init"),wdi.GlobalPool.init(),this.spiceConnection=e.spiceConnection||new wdi.SpiceConnection,this.clientGui=e.clientGui||new wdi.ClientGui({app:this}),this.agent=e.agent||new wdi.Agent({app:this}),this.inputProcess=e.inputProcess||new wdi.InputProcess({clientGui:this.clientGui,spiceConnection:this.spiceConnection}),this.packetProcess=e.packetProcess,this.busConnection=e.busConnection||new wdi.BusConnection,this.busProcess=e.busProcess||new wdi.BusProcess({clientGui:this.clientGui,busConnection:this.busConnection}),this.timeLapseDetector=e.timeLapseDetector||new wdi.TimeLapseDetector,this.checkActivity=e.checkActivity,this.setup(),e.supportHighDPI?(this.clientGui.pixelRatio=window.devicePixelRatio,this.pixelRatio=window.devicePixelRatio):(this.clientGui.pixelRatio=1,this.pixelRatio=1)},run:function(e){if(this.runParams=e,e.hasOwnProperty("seamlessDesktopIntegration")&&(wdi.SeamlessIntegration=e.seamlessDesktopIntegration),!this.packetProcess){var t=!1;!1===e.useWorkers&&(t=new wdi.DisplayProcess({clientGui:this.clientGui,disableMessageBuffering:e.disableMessageBuffering})),this.packetProcess=new wdi.PacketProcess({app:this,clientGui:this.clientGui,agent:this.agent,spiceConnection:this.spiceConnection,inputsProcess:this.inputProcess,displayProcess:t,disableMessageBuffering:e.disableMessageBuffering})}if(this.checkActivity||(this.checkActivity=new wdi.CheckActivity(e.checkActivityInterval),this.checkActivity.addListener("activityLost",this.onActivityLost,this)),window.vdiLoadTest?this.spiceConnection.addListener("message",this.onMessage,this):this.spiceConnection.addListener("message",this.packetProcess.process,this.packetProcess),this.busConnection.connect(e),this.timeLapseDetector.startTimer(),e.canvasMargin&&this.clientGui.setCanvasMargin(e.canvasMargin),e.disableClipboard&&(this.agent.disableClipboard(),this.clientGui.disableClipboard(),this.enableCtrlC(),this.enableCtrlV()),e.layer&&this.clientGui.setLayer(e.layer),this.clientGui.checkFeatures()){wdi.SeamlessIntegration&&this.disableKeyboard(),wdi.Keymap.loadKeyMap(e.layout,this.clientGui.getStuckKeysHandler()),this.setExternalCallback(e.callback,e.context);try{this.connect({host:e.host,port:e.port,protocol:e.protocol,vmHost:e.vmHost,vmPort:e.vmPort,vmid:e.vmid,vmInfoToken:e.vmInfoToken,busHost:e.busHost,token:e.token,connectionControl:e.connectionControl,heartbeatToken:e.heartbeatToken,heartbeatTimeout:e.heartbeatTimeout})}catch(e){this.executeExternalCallback("error",1)}this.clientGui.setClientOffset(e.clientOffset.x,e.clientOffset.y)}e.hasOwnProperty("externalClipboardHandling")&&(this.externalClipoardHandling=e.externalClipboardHandling)},end:function(){},setup:function(){this.spiceConnection.addListener("mouseMode",this.onMouseMode,this),this.spiceConnection.addListener("initAgent",this.onInitAgent,this),this.spiceConnection.addListener("error",this.onDisconnect,this),this.spiceConnection.addListener("channelConnected",this.onChannelConnected,this),this.clientGui.addListener("input",this.onClientInput,this),this.clientGui.addListener("resolution",this.onResolution,this),this.clientGui.addListener("paste",this.onPaste,this),this.clientGui.addListener("startAudio",this.onStartAudio,this),this.clientGui.addListener("eventLayerCreated",this.onEventLayerCreated,this),this.busProcess.addListener("windowCreated",this.onWindowCreated,this),this.busProcess.addListener("windowClosed",this.onWindowClosed,this),this.busProcess.addListener("windowMoved",this.onWindowMoved,this),this.busProcess.addListener("windowResized",this.onWindowResized,this),this.busProcess.addListener("windowFocused",this.onWindowFocused,this),this.busProcess.addListener("windowMinimized",this.onWindowMinimized,this),this.busProcess.addListener("windowRestored",this.onWindowRestored,this),this.busProcess.addListener("windowMaximized",this.onWindowMaximized,this),this.busProcess.addListener("busConnected",this.onBusConnected,this),this.busProcess.addListener("menuResponse",this.onMenuResponse,this),this.busProcess.addListener("networkDriveResponse",this.onNetworkDriveResponse,this),this.busProcess.addListener("wrongPathError",this.onWrongPathError,this),this.busProcess.addListener("applicationLaunchedSuccessfully",this.onApplicationLaunchedSuccessfully,this),this.busProcess.addListener("selectedText",this.onRemoteSelectedText,this),this.busProcess.addListener("copiedText",this.onRemoteCopiedText,this),this.agent.addListener("clipBoardData",this.onClipBoardData,this),this.busConnection.addListener("busMessage",this.onBusMessage,this),this.busConnection.addListener("error",this.onDisconnect,this),this.timeLapseDetector.addListener("timeLapseDetected",this.onTimeLapseDetected,this),this.busProcess.addListener("defaultTypeEvent",this.onDefaultTypeEvent,this)},onChannelConnected:function(e){e===wdi.SpiceVars.SPICE_CHANNEL_INPUTS&&this.clientGui.releaseAllKeys()},onDefaultTypeEvent:function(e){this.executeExternalCallback(e.event,e)},onNetworkDriveResponse:function(e){this.executeExternalCallback("networkDriveResponse",e)},onDisconnect:function(e){var t=e;this.executeExternalCallback("error",t)},onResolution:function(e){this.executeExternalCallback("resolution",e)},onClipBoardData:function(e){this.externalClipoardHandling?this.executeExternalCallback("clipboardEvent",e):this.clientGui.setClipBoardData(e)},onRemoteCopiedText:function(e){this.clientGui.setToLocalClipboard(e)},onRemoteSelectedText:function(e){this.clientGui.setToLocalClipboard(e)},onWindowMinimized:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowMinimized",e)},onWindowFocused:function(e){this.executeExternalCallback("windowFocused",e)},onWindowRestored:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowRestored",e)},onWindowMaximized:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowMaximized",e)},onWindowResized:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowResized",e)},onWindowMoved:function(e){var t=e;e=this.clientGui.moveSubCanvas(t);this.executeExternalCallback("windowMoved",e)},onWindowClosed:function(e){var t=e;e=this.clientGui.deleteSubCanvas(t);this.executeExternalCallback("windowClosed",e)},onWindowCreated:function(e){var t=e;e=this.clientGui.createNewSubCanvas(t);this.executeExternalCallback("windowCreated",e)},onMenuResponse:function(e){var t=e;this.executeExternalCallback("menuResponse",t)},onClientInput:function(e){var t=e,i=t[0],n=t[1][0];this.inputProcess.isKeyboardShortcut(i,n)?this._sendCtrlKey(n.keyCode):this.inputProcess.send(t,i)},onMessage:function(e){var t=e;this.packetProcess.process(t);var i=this;window.checkResultsTimer&&clearTimeout(window.checkResultsTimer),window.checkResultsTimer=window.setTimeout((function(){i.executeExternalCallback("checkResults"),window.vdiLoadTest=!1}),5e3)},onBusConnected:function(e){wdi.SeamlessIntegration&&this.busProcess.requestWindowList()},onBusMessage:function(e){var t=e;this.busProcess.process(t)},onInitAgent:function(e){this.agent.setClientTokens(e),this.agent.sendInitMessage(this),this.reconnecting=!1,this.executeExternalCallback("ready",e)},onMouseMode:function(e){this.clientGui.setMouseMode(e)},onPaste:function(e){this.agent.setClipboard(e)},onStartAudio:function(){this.packetProcess.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK].startAudio()},onEventLayerCreated:function(e){this.executeExternalCallback("eventLayerCreated",e)},onTimeLapseDetected:function(e){var t=e;this.executeExternalCallback("timeLapseDetected",t)},connect:function(e){wdi.Debug.log("application connect"),this.connectionInfo=e;try{this.spiceConnection.connect(e)}catch(e){wdi.Debug.error("application connect error",e),this.clientGui.showError(e.message)}},reconnect:function(e){this.reconnecting=!0,e.freeze&&this.freeze(),this.dispose(),this.init(),this.run(this.runParams)},freeze:function(){this.clientGui.freeze()},cancelFreeze:function(){this.clientGui.cancelFreeze()},setReconnecting:function(e){this.reconnecting=e},getReconnecting:function(){return this.reconnecting},setExternalCallback:function(e,t){this.externalCallback=[e,t]},executeExternalCallback:function(e,t){this.externalCallback[0].call(this.externalCallback[1],e,t)},sendCommand:function(e,t){switch(e){case"close":this.busProcess.closeWindow(t.hwnd);break;case"move":this.busProcess.moveWindow(t.hwnd,t.x,t.y);break;case"minimize":this.busProcess.minimizeWindow(t.hwnd);break;case"maximize":this.busProcess.maximizeWindow(t.hwnd);break;case"restore":this.busProcess.restoreWindow(t.hwnd);break;case"focus":this.busProcess.focusWindow(t.hwnd);break;case"resize":this.busProcess.resizeWindow(t.hwnd,t.width,t.height);break;case"run":this.busProcess.executeCommand(t.cmd);break;case"setResolution":this.agent.setResolution(t.width,t.height);break;case"getMenu":this.busProcess.getMenu();break;case"reMountNetworkDrive":this.busProcess.reMountNetworkDrive(t.host,t.username,t.password);break;case"refreshFileSystem":this.busProcess.refreshFileSystem();break;default:this.busProcess.sendGenericMessage(e,t)}},enableKeyboard:function(){this.clientGui.enableKeyboard()},disableKeyboard:function(){this.clientGui.disableKeyboard()},enableCtrlC:function(){wdi.KeymapES.setCtrlKey(67,46),wdi.KeymapUS.setCtrlKey(67,46)},enableCtrlV:function(){wdi.KeymapES.setCtrlKey(86,47),wdi.KeymapUS.setCtrlKey(86,47)},disconnect:function(){this.busConnection.disconnect(),this.spiceConnection.disconnect()},setMultimediaTime:function(e){this.multimediaTime=e,this.lastMultimediaTime=Date.now()},sendShortcut:function(e){e===wdi.keyShortcutsHandled.CTRLV?this._sendCtrlKey(86):e===wdi.keyShortcutsHandled.CTRLC&&this._sendCtrlKey(67)},sendCtrlAltDelete:function(){this._sendCtrlKey(18,46)},_sendCtrlKey:function(e,t){this.inputProcess.send(["keydown",[{generated:!0,type:"keydown",keyCode:17,charCode:0}]],"keydown"),this.inputProcess.send(["keydown",[{generated:!0,type:"keydown",keyCode:e,charCode:0}]],"keydown"),t&&this.inputProcess.send(["keydown",[{generated:!0,type:"keydown",keyCode:t,charCode:0}]],"keydown"),this.inputProcess.send(["keyup",[{generated:!0,type:"keyup",keyCode:e,charCode:0}]],"keyup"),t&&this.inputProcess.send(["keyup",[{generated:!0,type:"keyup",keyCode:t,charCode:0}]],"keyup"),this.inputProcess.send(["keyup",[{generated:!0,type:"keyup",keyCode:17,charCode:0}]],"keyup")},dispose:function(){this.disposed=!0,wdi.Debug.log("application dispose"),wdi.ExecutionControl.runQ.clear(),wdi.ExecutionControl.currentProxy=null,wdi.ExecutionControl.sync=!0,this.disableKeyboard(),this.disconnect(),this.packetProcess.dispose(),this.clientGui.dispose(),this.busProcess.clearEvents(),this.busProcess.dispose(),this.busConnection.clearEvents(),this.agent.clearEvents(),this.agent.dispose(),this.timeLapseDetector.clearEvents(),this.timeLapseDetector.dispose(),this.checkActivity.dispose()},onWrongPathError:function(e){this.executeExternalCallback("wrongPathError",e)},onApplicationLaunchedSuccessfully:function(e){this.executeExternalCallback("applicationLaunchedSuccessfully",e)},getKeyboardHandler:function(){return this.clientGui.handleKey},getClientGui:function(){return this.clientGui},setCurrentWindow:function(e){this.clientGui.inputManager.setCurrentWindow(e)},onActivityLost:function(e){this.executeExternalCallback("activityLost",e)},resetActivity:function(){this.checkActivity.resetActivity()},toSpiceResolution:function(e){return{width:e.width*this.pixelRatio,height:e.height*this.pixelRatio,scaleFactor:this.pixelRatio}}}),window.Application=Application,Application.prototype.run=Application.prototype.run,Application.prototype.sendCommand=Application.prototype.sendCommand,Application.prototype.enableKeyboard=Application.prototype.enableKeyboard,Application.prototype.disableKeyboard=Application.prototype.disableKeyboard,Application.prototype.dispose=Application.prototype.dispose,Application.prototype.getKeyboardHandler=Application.prototype.getKeyboardHandler,Application.prototype.getClientGui=Application.prototype.getClientGui,Application.prototype.setCurrentWindow=Application.prototype.setCurrentWindow,Application.prototype.reconnect=Application.prototype.reconnect,Application.prototype.freeze=Application.prototype.freeze,Application.prototype.cancelFreeze=Application.prototype.cancelFreeze,Application.prototype.setReconnecting=Application.prototype.setReconnecting,Application.prototype.getReconnecting=Application.prototype.getReconnecting;wdi.VirtualMouse={eventLayers:[],mouseData:null,visible:null,lastLayer:null,hotspot:{x:0,y:0},lastMousePosition:{x:0,y:0,width:0,height:0},dispose:function(){wdi.Debug.log("Disposing VirtualMouse"),this.eventLayers=[],this.mouseData=null,this.visible=null,this.lastLayer=null,this.hotspot={x:0,y:0},this.lastMousePosition={x:0,y:0,width:0,height:0}},setHotspot:function(t,e){this.hotspot.x=t,this.hotspot.y=e},setEventLayer:function(t,e,s,i,o,n){this.eventLayers.push({layer:t,left:e,top:s,right:e+i,bottom:s+o,position:n})},removeEventLayer:function(t){for(var e=this.eventLayers.length,s=0;s<e;s++)this.eventLayers[s].layer.id===t.id&&(this.eventLayers[t.id]=void 0)},getEventLayer:function(t,e){for(var s=this.eventLayers.length,i=null,o=0;o<s;o++)if(t>=(i=this.eventLayers[o]).left&&t<=i.right&&e>=i.top&&e<=i.bottom)return i.layer},setMouse:function(t,e,s){for(var i=this.eventLayers.length,o=0;o<i;o++)this.eventLayers[o].layer.style.cursor="url("+t+") "+e+" "+s+", default"},hideMouse:function(){for(var t=this.eventLayers.length,e=0;e<t;e++)this.eventLayers[e].layer.style.cursor="none"}};wdi.ImageCache={images:{},cursor:{},palettes:{},dispose:function(){wdi.Debug.log("Disposing ImageCache"),this.images={},this.cursor={},this.palettes={}},getImageFrom:function(t,e){var i=wdi.GlobalPool.create("Canvas"),a=this.images[t.id.toString()];i.width=a.width,i.height=a.height,i.getContext("2d").putImageData(a,0,0),e(i)},isImageInCache:function(t){return t.id.toString()in this.images},delImage:function(t){delete this.images[t.toString()]},addImage:function(t,e){e.getContext?this.images[t.id.toString()]=e.getContext("2d").getImageData(0,0,2e3,e.height):this.images[t.id.toString()]=e},getCursorFrom:function(t){return this.cursor[t.header.unique.toString()]},addCursor:function(t,e){this.cursor[t.header.unique.toString()]=e},getPalette:function(t){return this.palettes[t.toString()]},addPalette:function(t,e){this.palettes[t.toString()]=e},clearPalettes:function(){this.palettes={}}};wdi.RasterOperation={dispose:function(){wdi.Debug.log("Disposing RasterOperation")},process:function(i,t,e){var a=null;return i&wdi.SpiceRopd.SPICE_ROPD_INVERS_SRC||i&wdi.SpiceRopd.SPICE_ROPD_INVERS_BRUSH?t=this.invert(t):i&wdi.SpiceRopd.SPICE_ROPD_INVERS_DEST&&(e=this.invert(e)),i&wdi.SpiceRopd.SPICE_ROPD_OP_PUT?t:(i&wdi.SpiceRopd.SPICE_ROPD_OP_OR?a=this.boolOp(t,e,"or"):i&wdi.SpiceRopd.SPICE_ROPD_OP_AND?a=this.boolOp(t,e,"and"):i&wdi.SpiceRopd.SPICE_ROPD_OP_XOR?a=this.boolOp(t,e,"xor"):i&wdi.SpiceRopd.SPICE_ROPD_OP_BLACKNESS?a=this.lightness(e,"b"):i&wdi.SpiceRopd.SPICE_ROPD_OP_WHITENESS?a=this.lightness(e):i&wdi.SpiceRopd.SPICE_ROPD_OP_INVERS&&(a=this.invert(e)),i&wdi.SpiceRopd.SPICE_ROPD_INVERS_RES?this.invert(a):a)},flip:function(i){return i=wdi.Flipper.flip(i)},invert:function(i){return i=$(i).pixastic("invert")[0]},lightness:function(i,t){t="b"===t?-100:100;return i=$(i).pixastic("hsl",{hue:30,saturation:20,lightness:t})[0]},boolOp:function(i,t,e){var a=wdi.graphics.getDataFromImage(i).data,o=wdi.graphics.getDataFromImage(t).data,p=a.length-1,d=wdi.graphics.getNewTmpCanvas(i.width,i.height),r=d.getContext("2d"),n=r.createImageData(i.width,i.height),s=n.data;if("or"===e)for(;p>0;)n.data[p]=255,s[p-1]=a[p-1]|o[p-1],s[p-2]=a[p-2]|o[p-2],s[p-3]=a[p-3]|o[p-3],p-=4;else if("and"===e)for(;p>0;)n.data[p]=255,s[p-1]=a[p-1]&o[p-1],s[p-2]=a[p-2]&o[p-2],s[p-3]=a[p-3]&o[p-3],p-=4;else if("xor"===e)for(;p>0;)n.data[p]=255,s[p-1]=a[p-1]^o[p-1],s[p-2]=a[p-2]^o[p-2],s[p-3]=a[p-3]^o[p-3],p-=4;return r.putImageData(n,0,0),d}};wdi.Stream={streams:{},dispose:function(){wdi.Debug.log("Disposing Stream"),this.streams={}},addStream:function(s,t){this.streams[s]=t},deleteStream:function(s){this.streams[s]=void 0},getStream:function(s){return this.streams[s]},clip:function(s,t){this.streams[s].clip=t},startTransition:function(s){this.streams[s].transiting=!0},endTransition:function(s){this.streams[s].transiting=!1},setReady:function(s){this.streams[s].ready=!0},addQueue:function(s,t){this.streams[s].queues||(this.streams[s].queues=[]),this.streams[s].queues.push(t)},resetQueues:function(s){this.streams[s].queues=[]}};wdi.InputManager=$.spcExtend(wdi.EventObject.prototype,{checkFocus:!1,input:null,window:null,stuckKeysHandler:null,init:function(t){this.time=Date.now(),wdi.Debug.log("inputmanager init: ",this.time),this.superInit(),this.input=t.input,this.window=t.window,this.stuckKeysHandler=t.stuckKeysHandler,this.$=t.jQuery||$,t.disableInput||(this.inputElement=this.$('<div style="position:absolute"><input type="text" id="inputmanager" autocomplete="off" value="_" style="opacity: 0; color: transparent"/></div>')),this.currentWindow=null,this.getClientSO(),this.tildeMarks=["´","`","^","¨"],this.lastChar=null,this.tildeReplacements={a:{0:"á",1:"à",2:"â",3:"ä"},e:{0:"é",1:"è",2:"ê",3:"ë"},i:{0:"í",1:"ì",2:"î",3:"ï"},o:{0:"ó",1:"ò",2:"ô",3:"ö"},u:{0:"ú",1:"ù",2:"û",3:"ü"},A:{0:"Á",1:"À",2:"Â",3:"Ä"},E:{0:"É",1:"È",2:"Ê",3:"Ë"},I:{0:"Í",1:"Ì",2:"Î",3:"Ï"},O:{0:"Ó",1:"Ò",2:"Ô",3:"Ö"},U:{0:"Ú",1:"Ù",2:"Û",3:"Ü"}}},getClientSO:function(){var t=window.navigator.platform.toLowerCase();t.indexOf("mac")>-1?this.clientSO="mac":t.indexOf("linux")?this.clientSO="linux":this.clientSO="windows"},setCurrentWindow:function(t){t=this.$(t),this.currentWindow&&(this.inputElement.remove(),this.currentWindow.unbind("blur")),this.$(t[0].document.getElementById("vmw")).prepend(this.inputElement),this.input=this.$(t[0].document.getElementById("inputmanager")),this.addListeners(t),this.currentWindow=t},dispose:function(){this.disposed=!0,this.inputElement.remove(),this.currentWindow.unbind("blur"),this.currentWindow.unbind("input"),this.inputElement=null,this.checkFocus=!1,this.input=null,this.window=null,this.stuckKeysHandler=null},addListeners:function(t){this._onBlur(t),this._onInput()},_onBlur:function(t){var i=this;t.on("blur",(function(t){i.checkFocus&&i.input.focus(),i.stuckKeysHandler.releaseSpecialKeysPressed()}))},_onInput:function(){var t=this;this.input.on("input",(function(i){t.input.val().length>1&&t.reset()}))},enable:function(){wdi.Debug.log("enable!!!!!!!!!! ",this.time),this.checkFocus=!0,this.input.select()},disable:function(){this.checkFocus=!1,this.input&&this.input.blur()},reset:function(){this.input.val("")},getValue:function(){var t=this.input.val();if(t&&this.reset(),"mac"===this.clientSO){if(this.tildeMarks.indexOf(this.lastChar)>-1&&this.tildeReplacements.hasOwnProperty(t))switch(this.lastChar){case this.tildeMarks[0]:t=this.tildeReplacements[t][0];break;case this.tildeMarks[1]:t=this.tildeReplacements[t][1];break;case this.tildeMarks[2]:t=this.tildeReplacements[t][2];break;case this.tildeMarks[3]:t=this.tildeReplacements[t][3]}t&&this.tildeMarks.indexOf(t)>-1?t!=this.lastChar?(this.lastChar=t,t=""):t===this.lastChar&&(this.lastChar=""):this.lastChar=t||this.lastChar}return t},manageChar:function(t,i){var e=[Object.create(i[0])];return e[0].type="inputmanager",e[0].charCode=t.charCodeAt(0),e},isSpecialKey:function(t){return-1!==[17].indexOf(t)}});wdi.BUS_TYPES={file:0,print:1,launchApplication:2,windowManagement:3,menu:5,networkDriveManagement:6,clipboard:9,generic:99,killApplicationDoNotUseInProductionEver:34423423},wdi.BusProcess=$.spcExtend(wdi.EventObject.prototype,{busConnection:null,clientGui:null,init:function(e){this.superInit(),this.clientGui=e.clientGui,this.busConnection=e.busConnection},dispose:function(){this.clientGui=null,this.busConnection=null},process:function(e){switch(e.verb){case"CONNECTED":this.busConnection.setSubscriptions(),this.fire("busConnected");break;case"MESSAGE":this.parseMessage(e.body);break;case"ERROR":console.error("Bus error");break;default:wdi.Debug.warn("Not implemented Stomp Verb: "+e.verb)}},parseMessage:function(e){switch(parseInt(e.type)){case wdi.BUS_TYPES.launchApplication:this.parseLaunchApplicationMessage(e);break;case wdi.BUS_TYPES.killApplicationDoNotUseInProductionEver:break;case wdi.BUS_TYPES.windowManagement:this.parseWindowManagementMessage(e);break;case wdi.BUS_TYPES.menu:this.handleMenuMessage(e);break;case wdi.BUS_TYPES.networkDriveManagement:this._handleNetworkDriveMessage(e);break;case wdi.BUS_TYPES.clipboard:this.handleClipboardMessage(e);break;default:this.fire("defaultTypeEvent",e)}},_handleNetworkDriveMessage:function(e){"reMountNetworkDrive"!=e.event&&this.fire("networkDriveResponse",e)},getMenu:function(){this.busConnection.send({type:wdi.BUS_TYPES.menu,value:!1,event:"request"})},handleMenuMessage:function(e){"response"==e.event&&this.fire("menuResponse",e)},handleClipboardMessage:function(e){"selectedText"!==e.event&&"copiedText"!==e.event||this.fire(e.event,e)},parseWindowManagementMessage:function(e){switch(e.event){case"windowList":case"windowCreated":case"windowClosed":case"windowMoved":case"windowResized":case"windowFocused":case"windowMinimized":case"windowRestored":case"windowMaximized":this.fire(e.event,e.value);break;default:wdi.Debug.info("Event '"+e.event+"' not implemented.")}},closeWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"closeWindow",hwnd:e}))},moveWindow:function(e,n,t){this.busConnection.send(this._constructWindowManagementMessage({event:"moveWindow",hwnd:e,left:n,top:t}))},minimizeWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"minimizeWindow",hwnd:e}))},maximizeWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"maximizeWindow",hwnd:e}))},restoreWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"restoreWindow",hwnd:e}))},focusWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"focusWindow",hwnd:e}))},resizeWindow:function(e,n,t){this.busConnection.send(this._constructWindowManagementMessage({event:"resizeWindow",hwnd:e,width:n,height:t}))},requestWindowList:function(){this.busConnection.send(this._constructWindowManagementMessage({event:"getWindowList"}))},executeCommand:function(e){this.busConnection.send({type:wdi.BUS_TYPES.launchApplication,application:e})},refreshFileSystem:function(e){this.busConnection.send({type:wdi.BUS_TYPES.file,event:"refreshFileSystem",value:{}})},_constructGenericMessage:function(e,n){return{type:wdi.BUS_TYPES.generic,event:e,value:n||{}}},_constructWindowManagementMessage:function(e){if(void 0===e.event)throw new Error("You should pass an 'event' attribute in the object");var n={type:wdi.BUS_TYPES.windowManagement,event:e.event,value:{}};for(var t in e)"event"!=t&&e.hasOwnProperty(t)&&(n.value[t]=e[t]);return n},reMountNetworkDrive:function(e,n,t){this.busConnection.send({type:wdi.BUS_TYPES.networkDriveManagement,event:"reMountNetworkDrive",host:e,username:n,password:t})},parseLaunchApplicationMessage:function(e){switch(e.event){case"applicationLauncherWrongAppPathError":this.fire("wrongPathError",e);break;case"applicationLaunchedSuccessfully":this.fire("applicationLaunchedSuccessfully",e);break;default:wdi.Debug.info("Event '"+e.event+"' not implemented.")}},sendGenericMessage:function(e,n){this.busConnection.send(this._constructGenericMessage(e,n))}});wdi.DisplayProcess=$.spcExtend(wdi.EventObject.prototype,{runQ:null,packetFilter:null,init:function(i){this.runQ=i.runQ||wdi.ExecutionControl.runQ,this.packetFilter=i.packetFilter||wdi.PacketFilter,this.clientGui=i.clientGui,this.displayRouter=i.displayRouter||new wdi.DisplayRouter({clientGui:this.clientGui}),this.started=!1,this.waitingMessages=[],this.packetWorkerIdentifier=i.packetWorkerIdentifier||new wdi.PacketWorkerIdentifier,this.disableMessageBuffering=i.disableMessageBuffering},dispose:function(){wdi.Debug.log("Disposing DisplayProcess"),clearInterval(this.timer),this.timer=null,this.runQ=null,this.packetFilter.dispose(),this.packetFilter=null,this.clientGui=null,this.displayRouter.dispose(),this.displayRouter=null,this.packetWorkerIdentifier.dispose(),this.packetWorkerIdentifier=null,this.started=!1,this.waitingMessages=[]},process:function(i){if(this.disableMessageBuffering)this._process(i);else{var e=this;this.waitingMessages.push(i),this.started||(this.timer=setInterval((function(){e.flush()}),50),this.started=!0)}},flush:function(){if(0!==this.waitingMessages.length){var i,e=0;this.removeRedundantDraws();for(var t=this.waitingMessages.length;e<t;)i=this.waitingMessages[e],this._process(i),e++;this.waitingMessages=[]}},removeRedundantDraws:function(){if(!(this.waitingMessages.length<2)){for(var i,e,t,s,r,n,a,o,l,c,h=this.waitingMessages.length,u={},p=[],d=!1;h--;)if(r=(e=(i=this.waitingMessages[h]).args).base,s=e.rop_descriptor,d=!1,r){if(r.surface_id,a=r.box,n=r.surface_id,t=this.packetWorkerIdentifier.getImageProperties(i),u[n]||(u[n]=[]),(!t||t&&!(t.descriptor.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME))&&0===n)for(l=0;l<u[n].length;l++)if((o=u[n][l]).bottom>=a.bottom&&o.top<=a.top&&o.left<=a.left&&o.right>=a.right){d=!0,p.push(h);break}if(!d&&i.messageType===wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS)break;!d&&e.getMessageProperty("overWriteScreenArea",!1)&&0==r.clip.type&&s==wdi.SpiceRopd.SPICE_ROPD_OP_PUT&&u[n].push(r.box)}for(c=0;c<p.length;c++)this.waitingMessages.splice(p[c],1)}},_process:function(i){wdi.logOperations&&wdi.DataLogger.log(i,0,null,!0,"","_decode"),this.runQ.add((function(e){this.packetFilter.filter(i,(function(i){wdi.ExecutionControl.currentProxy=e,this.displayRouter.processPacket(i),this.postProcess()}),this,this.clientGui),wdi.ExecutionControl.sync&&e.end()}),this,(function(){this.processEnd(i,this.clientGui)})),this.runQ.process()},processEnd:function(i,e){this.packetFilter.notifyEnd(i,e)},postProcess:function(){}});wdi.DisplayPreProcess=$.spcExtend(wdi.EventObject.prototype,{displayProcess:null,queued:[],inProcess:[],idleConsumers:[],consumers:[],init:function(s){this.idleConsumers=[],this.superInit(),this.displayProcess=s.displayProcess||new wdi.DisplayProcess({clientGui:s.clientGui,disableMessageBuffering:s.disableMessageBuffering}),this.clientGui=s.clientGui,null!=s.numConsumers&&null!=s.numConsumers||(s.numConsumers=4);for(var e=s.numConsumers,i=0;i<e;i++){var n=new wdi.AsyncConsumer;this.consumers.push(n),this.idleConsumers.push(n),n.addListener("done",this.onConsumerDone,this)}},onConsumerDone:function(s){for(var e=this.inProcess[0],i=null;e&&1===e.state;){i=this.inProcess.shift();try{this.displayProcess.process(i.message)}catch(s){wdi.Debug.error("DisplayPreProcess error: ",s)}e=this.inProcess[0]}this.idleConsumers.push(s),this.queued.length>0&&this.executeConsumer()},process:function(s){this.addTask(s),this.executeConsumer()},addTask:function(s){this.queued.push({message:s,clientGui:this.clientGui})},getNextTask:function(){for(var s=this.queued.shift();void 0===s&&0!=this.queued.length;)s=this.queued.shift();return void 0!==s&&(s.state=0,this.inProcess.push(s),s)},executeConsumer:function(){if(this.idleConsumers.length>0){wdi.Debug.log("DisplayPreProcess: available workers: "+this.idleConsumers.length),wdi.Debug.log("DisplaypreProcess: pending tasks: "+this.queued.length);var s=this.idleConsumers.shift(),e=this.getNextTask();e&&s.consume(e)}},dispose:function(){wdi.Debug.log("displaypreprocess dispose ################ idleConsumers: ",this.idleConsumers.length),this.clearEvents(),this.clientGui=null,this.queued=[],this.inProcess=[],this.idleConsumers=[],this.displayProcess.dispose(),this.displayProcess=null,this.consumers.forEach((function(s){s.clearEvents(),s.dispose()})),this.consumers=[]}});wdi.InputProcess=$.spcExtend(wdi.EventObject.prototype,{clientGui:null,spiceConnection:null,capsLockPressed:!1,numLockPressed:!1,shiftPressed:!1,init:function(e){this.superInit(),this.clientGui=e.clientGui,this.spiceConnection=e.spiceConnection},dispose:function(){this.clearEvents(),this.clientGui=null,this.spiceConnection=null},process:function(e){if(e.messageType===wdi.SpiceVars.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK)this.clientGui.motion_ack()},send:function(e,s){var i,n,c;if("mousemove"==s)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_POSITION,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMousePosition({x:e[1][0]+wdi.VirtualMouse.hotspot.x,y:e[1][1]+wdi.VirtualMouse.hotspot.y,buttons_state:e[1][2],display_id:0})}),this.spiceConnection.send(i);else if("mousedown"==s)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_PRESS,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMousePress({button_id:e[1]+1,buttons_state:1<<e[1]})}),this.spiceConnection.send(i);else if("mouseup"==s)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_RELEASE,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMousePress({button_id:e[1]+1,buttons_state:0})}),this.spiceConnection.send(i);else if("keydown"==s||"keypress"==s){n=wdi.Keymap.getScanCodes(e[1][0]);const t=e[1][0].originalEvent;if("keydown"==s&&20!==e[1][0].keyCode&&(!wdi.Keymap.isVirtualKeyboard&&t&&t.getModifierState&&wdi.Keymap.capsLock!==t.getModifierState("CapsLock")||wdi.Keymap.isVirtualKeyboard&&wdi.Keymap.isVirtualCapsLockOn!==wdi.Keymap.capsLock)){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([58,0,0])});this.capsLockPressed=!0,this.spiceConnection.send(e)}if("keydown"==s&&t&&t.getModifierState&&144!==e[1][0].keyCode&&wdi.Keymap.numLock!==t.getModifierState("NumLock")){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([69,0,0])});this.numLockPressed=!0,this.spiceConnection.send(e)}for(c=0;c<n.length;c++)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode(n[c])}),n[0]&&42===n[0][0]&&(this.shiftPressed=!0),this.spiceConnection.send(i)}else if("keyup"==s){if((n=wdi.Keymap.getScanCodes(e[1][0]))&&n[0]&&199===n[0][0]&&0===n[0][1]&&0===n[0][2]&&(n=[[224,199,0,0]]),this.capsLockPressed){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([186,0,0])});this.spiceConnection.send(e),this.capsLockPressed=!1}if(this.numLockPressed){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([197,0,0])});this.spiceConnection.send(e),this.numLockPressed=!1}for(n[0]&&142===n[0][0]&&(this.shiftPressed=!1),c=0;c<n.length;c++)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode(n[c])}),this.spiceConnection.send(i);this.clientGui.inputManager.input.val("_")}else"joystick"==s&&(i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_MOTION,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMouseMotion({x:e[1][0],y:e[1][1],buttons_state:0})}),this.spiceConnection.send(i))},isKeyboardShortcut:function(e,s){if("keydown"===e){var i=s.keyCode;return wdi.Keymap.controlPressed(i,e,s),wdi.Keymap.handledByCtrlKeyCode(e,i,!0)}}});wdi.CursorProcess=$.spcExtend(wdi.EventObject.prototype,{imageData:null,process:function(r){switch(r.messageType){case wdi.SpiceVars.SPICE_MSG_CURSOR_INIT:case wdi.SpiceVars.SPICE_MSG_CURSOR_SET:var e=this.extractCursor(r);e&&(wdi.VirtualMouse.setHotspot(0,0),wdi.VirtualMouse.setMouse(e.data,e.header.hot_spot_x,e.header.hot_spot_y));case wdi.SpiceVars.SPICE_MSG_CURSOR_HIDE:}},dispose:function(){this.clearEvents(),this.imageData=null},_toUrl:function(r){var e=$("<canvas/>").attr({width:r.width,height:r.height})[0];return e.getContext("2d").putImageData(r,0,0),e.toDataURL("image/png")},extractCursor:function(r){var e=r.args.cursor.flags,s=r.args.position,a=r.args.visible;if(1&e)return null;var i=null;if(e&wdi.SpiceCursorFlags.SPICE_CURSOR_FLAGS_FROM_CACHE)i=wdi.ImageCache.getCursorFrom(r.args.cursor);else switch(r.args.cursor.header.type){case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_ALPHA:i=this._toUrl(wdi.graphics.argbToImageData(r.args.cursor.data,r.args.cursor.header.width,r.args.cursor.header.height));break;case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_MONO:i=this._toUrl(wdi.graphics.monoToImageData(r.args.cursor.data,r.args.cursor.header.width,r.args.cursor.header.height));break;case 8:i=wdi.SpiceObject.bytesToString(r.args.cursor.data);case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR4:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR8:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR16:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR24:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR32:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_ENUM_END:}return i?(e&wdi.SpiceCursorFlags.SPICE_CURSOR_FLAGS_CACHE_ME&&wdi.ImageCache.addCursor(r.args.cursor,i),{data:i,position:s,visible:a,header:r.args.cursor.header}):null}});wdi.PlaybackProcess=$.spcExtend(wdi.EventObject.prototype,{_lastApp:null,started:!1,minBuffSize:32768,frequency:null,channels:null,audioContext:null,startTime:null,hasAudioSupport:!0,typedBuffer:null,position:null,init:function(t){this.app=t.app,this.audioContext=this.getAudioContext(),this.audioContext?this.hasAudioSupport=!0:(this.hasAudioSupport=!1,wdi.Debug.warn("The client browser does not support Web Audio API")),this.startTime=0,this.typedBuffer=new ArrayBuffer(34688),this.position=0},dispose:function(){this.clearEvents(),this._lastApp=null,this.started=!1,this.frequency=null,this.channels=null,this.audioContext=null,this.startTime=null,this.hasAudioSupport=!0,this.typedBuffer=null,this.position=null},getAudioContext:function(){try{return new AudioContext}catch(t){}try{return new webkitAudioContext}catch(t){}return!1},process:function(t){if(this.hasAudioSupport)switch(t.messageType){case wdi.SpiceVars.SPICE_MSG_PLAYBACK_MODE:break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_START:var e=t.args;this.channels=e.channels,this.frequency=e.frequency;break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_STOP:this.startTime=0;e=t.args;this.flush();break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_DATA:e=t.args;var i=t.args.multimedia_time;new Uint8Array(this.typedBuffer).set(e.data,this.position),this.position+=e.data.length,this._lastApp=this.app,this.position>=this.minBuffSize&&this.flush(i)}},flush:function(t){this.position>0&&(this.started&&this.playSound(this.typedBuffer,t),this.position=0,this.typedBuffer=new ArrayBuffer(34688))},playSound:function(t,e){if(2==this.channels)return this.playSoundStereo(t,e);for(var i=new Int16Array(t),s=new Array(this.channels),n=0;n<this.channels;n++)s[n]=new Float32Array(i.length/2);var a=0;for(n=0;n<i.length;){for(var r=0;r<this.channels;r++)s[r][a]=i[n++]/32768;a++}var h=this.audioContext.createBufferSource(),o=this.audioContext.createBuffer(this.channels,a,this.frequency);for(n=0;n<this.channels;n++)o.getChannelData(n).set(s[n]);this._play(h,o,e)},playSoundStereo:function(t,e){for(var i=new Int16Array(t),s=new Float32Array(i.length/2),n=new Float32Array(i.length/2),a=0,r=this.audioContext,h=i.length,o=0;o<h;)s[a]=i[o++]/32768,n[a]=i[o++]/32768,a++;var u=r.createBufferSource(),l=r.createBuffer(2,a,this.frequency);l.getChannelData(0).set(s),l.getChannelData(1).set(n),this._play(u,l,e)},_play:function(t,e,i){var s=0;i&&((s=i-(Date.now()-this.app.lastMultimediaTime+this.app.multimediaTime))<0&&(s=0));t.buffer=e,t.connect(this.audioContext.destination),t.start(this.startTime+s),this.startTime+=e.duration},startAudio:function(){this.started=!0,this.flush()}});wdi.MainProcess=$.spcExtend(wdi.EventObject.prototype,{init:function(e){this.superInit(),this.app=e.app,this.spiceConnection=e.app.spiceConnection,this.agent=e.app.agent},dispose:function(){this.clearEvents(),this.app=null,this.spiceConnection=null,this.agent=null},process:function(e){var i=this.spiceConnection.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN];switch(e.messageType){case wdi.SpiceVars.SPICE_MSG_MAIN_INIT:i.connectionId=e.args.session_id,i.fire("connectionId",i.connectionId),1==e.args.agent_connected&&i.fire("initAgent",e.args.agent_tokens),1==e.args.current_mouse_mode&&i.fire("mouseMode",e.args.current_mouse_mode),this.changeMouseMode();break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_DATA:var s=e.args;this.agent.onAgentData(s);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_CONNECTED:i.fire("initAgent",e.args.agent_tokens),this.changeMouseMode();break;case wdi.SpiceVars.SPICE_MSG_MAIN_MULTI_MEDIA_TIME:this.app.multimediaTime=e.args.multimedia_time;break;case wdi.SpiceVars.SPICE_MSG_MAIN_CHANNELS_LIST:i.fire("channelListAvailable",e.args.channels)}},changeMouseMode:function(){var e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.SpiceMouseModeRequest({request_mode:wdi.SpiceMouseModeTypes.SPICE_MOUSE_MODE_CLIENT})});this.spiceConnection.send(e)}});wdi.KeyEvent={isCtrlPressed:function(e){if(!e)throw new Error("isCtrlPressed: No event provided.");var r=e.ctrlKey;return-1!=navigator.platform.indexOf("Mac")&&(r=e.metaKey),r}};wdi.KeymapES=function(){var e={Backquote:[[5,0,0,0],[133,0,0,0]],Digit1:[[2,0,0,0],[130,0,0,0]],Digit2:[[3,0,0,0],[131,0,0,0]],Digit3:[[4,0,0,0],[132,0,0,0]],Digit4:[[5,0,0,0],[133,0,0,0]],Digit5:[[6,0,0,0],[134,0,0,0]],Digit6:[[7,0,0,0],[135,0,0,0]],Digit7:[[8,0,0,0],[136,0,0,0]],Digit8:[[9,0,0,0],[137,0,0,0]],Digit9:[[10,0,0,0],[138,0,0,0]],Digit0:[[11,0,0,0],[139,0,0,0]],Minus:[[53,0,0,0],[181,0,0,0]],Equal:[[11,0,0,0],[139,0,0,0]],KeyQ:[[16,0,0,0],[144,0,0,0]],KeyW:[[17,0,0,0],[145,0,0,0]],KeyE:[[18,0,0,0],[146,0,0,0]],KeyR:[[19,0,0,0],[147,0,0,0]],KeyT:[[20,0,0,0],[148,0,0,0]],KeyY:[[21,0,0,0],[149,0,0,0]],KeyU:[[22,0,0,0],[150,0,0,0]],KeyI:[[23,0,0,0],[151,0,0,0]],KeyO:[[24,0,0,0],[152,0,0,0]],KeyP:[[25,0,0,0],[153,0,0,0]],BracketLeft:[[26,0,0,0],[154,0,0,0]],BracketRight:[[27,0,0,0],[155,0,0,0]],Backslash:[[41,0,0,0],[169,0,0,0]],KeyA:[[30,0,0,0],[158,0,0,0]],KeyS:[[31,0,0,0],[159,0,0,0]],KeyD:[[32,0,0,0],[160,0,0,0]],KeyF:[[33,0,0,0],[161,0,0,0]],KeyG:[[34,0,0,0],[162,0,0,0]],KeyH:[[35,0,0,0],[163,0,0,0]],KeyJ:[[36,0,0,0],[164,0,0,0]],KeyK:[[37,0,0,0],[165,0,0,0]],KeyL:[[38,0,0,0],[166,0,0,0]],Semicolon:[[51,0,0,0],[179,0,0,0]],Quote:[[12,0,0,0],[140,0,0,0]],KeyZ:[[44,0,0,0],[172,0,0,0]],KeyX:[[45,0,0,0],[173,0,0,0]],KeyC:[[46,0,0,0],[174,0,0,0]],KeyV:[[47,0,0,0],[175,0,0,0]],KeyB:[[48,0,0,0],[176,0,0,0]],KeyN:[[49,0,0,0],[177,0,0,0]],KeyM:[[50,0,0,0],[178,0,0,0]],Comma:[[51,0,0,0],[179,0,0,0]],Period:[[52,0,0,0],[180,0,0,0]],Slash:[[53,0,0,0],[181,0,0,0]],Numpad0:[[11,0,0,0],[139,0,0,0]],Numpad1:[[2,0,0,0],[130,0,0,0]],Numpad2:[[3,0,0,0],[131,0,0,0]],Numpad3:[[4,0,0,0],[132,0,0,0]],Numpad4:[[5,0,0,0],[133,0,0,0]],Numpad5:[[6,0,0,0],[134,0,0,0]],Numpad6:[[7,0,0,0],[135,0,0,0]],Numpad7:[[8,0,0,0],[136,0,0,0]],Numpad8:[[9,0,0,0],[137,0,0,0]],Numpad9:[[10,0,0,0],[138,0,0,0]],NumpadDivide:[[53,0,0,0],[181,0,0,0]],NumpadMultiply:[[55,0,0,0],[183,0,0,0]],NumpadSubtract:[[74,0,0,0],[202,0,0,0]],NumpadAdd:[[78,0,0,0],[206,0,0,0]],NumpadDecimal:[[52,0,0,0],[180,0,0,0]]},t=[];t[27]=1,t[9]=15,t[20]=58,t[16]=42,t[91]=29,t[17]=29,t[32]=57,t[8]=14,t[13]=28,t[18]=56,t[92]=92,t[93]=93,t[38]=72,t[37]=75,t[40]=80,t[39]=77,t[45]=82,t[46]=83,t[36]=71,t[35]=79,t[33]=73,t[34]=81,t[144]=69,t[145]=70,t[112]=59,t[113]=60,t[114]=61,t[115]=62,t[116]=63,t[117]=64,t[118]=65,t[119]=66,t[120]=67,t[121]=68,t[122]=87,t[123]=88;var i=[];i[81]=16,i[87]=17,i[69]=18,i[82]=19,i[84]=20,i[89]=21,i[85]=22,i[73]=23,i[79]=24,i[80]=25,i[65]=30,i[83]=31,i[68]=32,i[70]=33,i[71]=34,i[72]=35,i[74]=36,i[75]=37,i[76]=38,i[90]=44,i[88]=45,i[67]=46,i[86]=47,i[66]=48,i[78]=49,i[77]=50;var a=[];a[9]=15;var u=[];return u[81]=16,u[87]=17,u[69]=18,u[82]=19,u[84]=20,u[89]=21,u[85]=22,u[73]=23,u[79]=24,u[80]=25,u[65]=30,u[83]=31,u[68]=32,u[70]=33,u[71]=34,u[72]=35,u[74]=36,u[75]=37,u[76]=38,u[90]=44,u[88]=45,u[86]=47,u[67]=46,u[66]=48,u[78]=49,u[77]=50,{getKeymap:function(){return t},getCtrlKeymap:function(){return i},getCtrlForbiddenKeymap:function(){return a},getReservedCtrlKeymap:function(){return u},getCharmap:function(){return e},setCtrlKey:function(e,t){i[e]=t}}}();wdi.scanCodeObjProvider=$.spcExtend(wdi.EventObject.prototype,{init:function(t){this.charObj=t},getPrefix:function(){return this.prefix},getSufix:function(){return this.suffix},setPrefix:function(t){},setSuffix:function(t){},getScanCode:function(){var t=[],i=this.charObj.main;return t=t.concat(i)}});wdi.ScanCodeObjModifier=$.spcExtend(wdi.EventObject.prototype,{SHIFTDOWN:[42,0,0,0],SHIFTUP:[170,0,0,0],init:function(n){this.scanCodeObjProvider=new wdi.scanCodeObjProvider(n),this.prefix=[],this.suffix=[]},removeShift:function(){return this.getScanCode()},containsShiftDown:function(){return!1},addShiftUp:function(){},addShiftDown:function(){},getScanCode:function(){return this.scanCodeObjProvider.getScanCode()},_removeKeyFromPart:function(n,t){return t.filter((function(t){return!_.isEqual(t,n)}))}});wdi.KeymapObjES=function(){var i={Backquote:{prefix:[],main:[[41,0,0,0],[169,0,0,0]],suffix:[]},Digit1:{prefix:[],main:[[2,0,0,0],[130,0,0,0]],suffix:[]},Digit2:{prefix:[],main:[[3,0,0,0],[131,0,0,0]],suffix:[]},Digit3:{prefix:[],main:[[4,0,0,0],[132,0,0,0]],suffix:[]},Digit4:{prefix:[],main:[[5,0,0,0],[133,0,0,0]],suffix:[]},Digit5:{prefix:[],main:[[6,0,0,0],[134,0,0,0]],suffix:[]},Digit6:{prefix:[],main:[[7,0,0,0],[135,0,0,0]],suffix:[]},Digit7:{prefix:[],main:[[8,0,0,0],[136,0,0,0]],suffix:[]},Digit8:{prefix:[],main:[[9,0,0,0],[137,0,0,0]],suffix:[]},Digit9:{prefix:[],main:[[10,0,0,0],[138,0,0,0]],suffix:[]},Digit0:{prefix:[],main:[[11,0,0,0],[139,0,0,0]],suffix:[]},Minus:{prefix:[],main:[[12,0,0,0],[140,0,0,0]],suffix:[]},Equal:{prefix:[],main:[[13,0,0,0],[141,0,0,0]],suffix:[]},KeyQ:{prefix:[],main:[[16,0,0,0],[144,0,0,0]],suffix:[]},KeyW:{prefix:[],main:[[17,0,0,0],[145,0,0,0]],suffix:[]},KeyE:{prefix:[],main:[[18,0,0,0],[146,0,0,0]],suffix:[]},KeyR:{prefix:[],main:[[19,0,0,0],[147,0,0,0]],suffix:[]},KeyT:{prefix:[],main:[[20,0,0,0],[148,0,0,0]],suffix:[]},KeyY:{prefix:[],main:[[21,0,0,0],[149,0,0,0]],suffix:[]},KeyU:{prefix:[],main:[[22,0,0,0],[150,0,0,0]],suffix:[]},KeyI:{prefix:[],main:[[23,0,0,0],[151,0,0,0]],suffix:[]},KeyO:{prefix:[],main:[[24,0,0,0],[152,0,0,0]],suffix:[]},KeyP:{prefix:[],main:[[25,0,0,0],[153,0,0,0]],suffix:[]},BracketLeft:{prefix:[],main:[[26,0,0,0],[154,0,0,0]],suffix:[]},BracketRight:{prefix:[],main:[[27,0,0,0],[155,0,0,0]],suffix:[]},Backslash:{prefix:[],main:[[43,0,0,0],[171,0,0,0]],suffix:[]},KeyA:{prefix:[],main:[[30,0,0,0],[158,0,0,0]],suffix:[]},KeyS:{prefix:[],main:[[31,0,0,0],[159,0,0,0]],suffix:[]},KeyD:{prefix:[],main:[[32,0,0,0],[160,0,0,0]],suffix:[]},KeyF:{prefix:[],main:[[33,0,0,0],[161,0,0,0]],suffix:[]},KeyG:{prefix:[],main:[[34,0,0,0],[162,0,0,0]],suffix:[]},KeyH:{prefix:[],main:[[35,0,0,0],[163,0,0,0]],suffix:[]},KeyJ:{prefix:[],main:[[36,0,0,0],[164,0,0,0]],suffix:[]},KeyK:{prefix:[],main:[[37,0,0,0],[165,0,0,0]],suffix:[]},KeyL:{prefix:[],main:[[38,0,0,0],[166,0,0,0]],suffix:[]},Semicolon:{prefix:[],main:[[39,0,0,0],[167,0,0,0]],suffix:[]},Quote:{prefix:[],main:[[40,0,0,0],[168,0,0,0]],suffix:[]},KeyZ:{prefix:[],main:[[44,0,0,0],[172,0,0,0]],suffix:[]},KeyX:{prefix:[],main:[[45,0,0,0],[173,0,0,0]],suffix:[]},KeyC:{prefix:[],main:[[46,0,0,0],[174,0,0,0]],suffix:[]},KeyV:{prefix:[],main:[[47,0,0,0],[175,0,0,0]],suffix:[]},KeyB:{prefix:[],main:[[48,0,0,0],[176,0,0,0]],suffix:[]},KeyN:{prefix:[],main:[[49,0,0,0],[177,0,0,0]],suffix:[]},KeyM:{prefix:[],main:[[50,0,0,0],[178,0,0,0]],suffix:[]},Comma:{prefix:[],main:[[51,0,0,0],[179,0,0,0]],suffix:[]},Period:{prefix:[],main:[[52,0,0,0],[180,0,0,0]],suffix:[]},Slash:{prefix:[],main:[[53,0,0,0],[181,0,0,0]],suffix:[]},Numpad0:{prefix:[],main:[[11,0,0,0],[139,0,0,0]],suffix:[]},Numpad1:{prefix:[],main:[[2,0,0,0],[130,0,0,0]],suffix:[]},Numpad2:{prefix:[],main:[[3,0,0,0],[131,0,0,0]],suffix:[]},Numpad3:{prefix:[],main:[[4,0,0,0],[132,0,0,0]],suffix:[]},Numpad4:{prefix:[],main:[[5,0,0,0],[133,0,0,0]],suffix:[]},Numpad5:{prefix:[],main:[[6,0,0,0],[134,0,0,0]],suffix:[]},Numpad6:{prefix:[],main:[[7,0,0,0],[135,0,0,0]],suffix:[]},Numpad7:{prefix:[],main:[[8,0,0,0],[136,0,0,0]],suffix:[]},Numpad8:{prefix:[],main:[[9,0,0,0],[137,0,0,0]],suffix:[]},Numpad9:{prefix:[],main:[[10,0,0,0],[138,0,0,0]],suffix:[]},NumpadDivide:{prefix:[],main:[[224,53,0,0],[0,0,0,0]],suffix:[]},NumpadMultiply:{prefix:[],main:[[55,0,0,0],[183,0,0,0]],suffix:[]},NumpadSubtract:{prefix:[],main:[[74,0,0,0],[202,0,0,0]],suffix:[]},NumpadAdd:{prefix:[],main:[[78,0,0,0],[206,0,0,0]],suffix:[]},NumpadDecimal:{prefix:[],main:[[83,0,0,0],[211,0,0,0]],suffix:[]}};return{getScanCode:function(i){return new wdi.scanCodeObjProvider(this.getCharmap()[i]).getScanCode()},getCharmap:function(){return i}}}();wdi.KeymapUS=function(){var e=[];e.Backquote=[[5,0,0,0],[133,0,0,0]],e.Digit1=[[2,0,0,0],[130,0,0,0]],e.Digit2=[[3,0,0,0],[131,0,0,0]],e.Digit3=[[4,0,0,0],[132,0,0,0]],e.Digit4=[[5,0,0,0],[133,0,0,0]],e.Digit5=[[6,0,0,0],[134,0,0,0]],e.Digit6=[[7,0,0,0],[135,0,0,0]],e.Digit7=[[8,0,0,0],[136,0,0,0]],e.Digit8=[[9,0,0,0],[137,0,0,0]],e.Digit9=[[10,0,0,0],[138,0,0,0]],e.Digit0=[[11,0,0,0],[139,0,0,0]],e.Minus=[[53,0,0,0],[181,0,0,0]],e.Equal=[[11,0,0,0],[139,0,0,0]],e.KeyQ=[[16,0,0,0],[144,0,0,0]],e.KeyW=[[17,0,0,0],[145,0,0,0]],e.KeyE=[[18,0,0,0],[146,0,0,0]],e.KeyR=[[19,0,0,0],[147,0,0,0]],e.KeyT=[[20,0,0,0],[148,0,0,0]],e.KeyY=[[21,0,0,0],[149,0,0,0]],e.KeyU=[[22,0,0,0],[150,0,0,0]],e.KeyI=[[23,0,0,0],[151,0,0,0]],e.KeyO=[[24,0,0,0],[152,0,0,0]],e.KeyP=[[25,0,0,0],[153,0,0,0]],e.BracketLeft=[[26,0,0,0],[154,0,0,0]],e.BracketRight=[[27,0,0,0],[155,0,0,0]],e.Backslash=[[41,0,0,0],[169,0,0,0]],e.KeyA=[[30,0,0,0],[158,0,0,0]],e.KeyS=[[31,0,0,0],[159,0,0,0]],e.KeyD=[[32,0,0,0],[160,0,0,0]],e.KeyF=[[33,0,0,0],[161,0,0,0]],e.KeyG=[[34,0,0,0],[162,0,0,0]],e.KeyH=[[35,0,0,0],[163,0,0,0]],e.KeyJ=[[36,0,0,0],[164,0,0,0]],e.KeyK=[[37,0,0,0],[165,0,0,0]],e.KeyL=[[38,0,0,0],[166,0,0,0]],e.Semicolon=[[51,0,0,0],[179,0,0,0]],e.Quote=[[12,0,0,0],[140,0,0,0]],e.KeyZ=[[44,0,0,0],[172,0,0,0]],e.KeyX=[[45,0,0,0],[173,0,0,0]],e.KeyC=[[46,0,0,0],[174,0,0,0]],e.KeyV=[[47,0,0,0],[175,0,0,0]],e.KeyB=[[48,0,0,0],[176,0,0,0]],e.KeyN=[[49,0,0,0],[177,0,0,0]],e.KeyM=[[50,0,0,0],[178,0,0,0]],e.Comma=[[51,0,0,0],[179,0,0,0]],e.Period=[[52,0,0,0],[180,0,0,0]],e.Slash=[[53,0,0,0],[181,0,0,0]],e.Numpad0=[[11,0,0,0],[139,0,0,0]],e.Numpad1=[[2,0,0,0],[130,0,0,0]],e.Numpad2=[[3,0,0,0],[131,0,0,0]],e.Numpad3=[[4,0,0,0],[132,0,0,0]],e.Numpad4=[[5,0,0,0],[133,0,0,0]],e.Numpad5=[[6,0,0,0],[134,0,0,0]],e.Numpad6=[[7,0,0,0],[135,0,0,0]],e.Numpad7=[[8,0,0,0],[136,0,0,0]],e.Numpad8=[[9,0,0,0],[137,0,0,0]],e.Numpad9=[[10,0,0,0],[138,0,0,0]],e.NumpadDivide=[[53,0,0,0],[181,0,0,0]],e.NumpadMultiply=[[55,0,0,0],[183,0,0,0]],e.NumpadSubtract=[[74,0,0,0],[202,0,0,0]],e.NumpadAdd=[[78,0,0,0],[206,0,0,0]],e.NumpadDecimal=[[52,0,0,0],[180,0,0,0]];var t=[];t[27]=1,t[9]=15,t[20]=58,t[16]=42,t[91]=29,t[17]=29,t[32]=57,t[8]=14,t[13]=28,t[18]=56,t[92]=92,t[93]=93,t[38]=72,t[37]=75,t[40]=80,t[39]=77,t[45]=82,t[46]=83,t[36]=71,t[35]=79,t[33]=73,t[34]=81,t[144]=69,t[145]=70,t[112]=59,t[113]=60,t[114]=61,t[115]=62,t[116]=63,t[117]=64,t[118]=65,t[119]=66,t[120]=67,t[121]=68,t[122]=87,t[123]=88;var a=[];a[65]=30,a[81]=16,a[87]=17,a[69]=18,a[82]=19,a[84]=20,a[89]=21,a[85]=22,a[73]=23,a[79]=24,a[80]=25,a[65]=30,a[83]=31,a[68]=32,a[70]=33,a[71]=34,a[72]=35,a[74]=36,a[75]=37,a[76]=38,a[90]=44,a[88]=45,a[67]=46,a[86]=47,a[66]=48,a[78]=49,a[77]=50;var i=[];i[9]=15;var u=[];return u[81]=16,u[87]=17,u[69]=18,u[82]=19,u[84]=20,u[89]=21,u[85]=22,u[73]=23,u[79]=24,u[80]=25,u[65]=30,u[83]=31,u[68]=32,u[70]=33,u[71]=34,u[72]=35,u[74]=36,u[75]=37,u[76]=38,u[88]=45,u[90]=44,u[86]=47,u[67]=46,u[66]=48,u[78]=49,u[77]=50,{getKeymap:function(){return t},getCtrlKeymap:function(){return a},getCtrlForbiddenKeymap:function(){return i},getReservedCtrlKeymap:function(){return u},getCharmap:function(){return e},setCtrlKey:function(e,t){a[e]=t}}}();wdi.keyShortcutsHandled={CTRLV:0,CTRLC:1},wdi.Keymap={keymap:{},ctrlKeymap:{},ctrlForbiddenKeymap:{},charmap:{},ctrlPressed:!1,capsLock:!1,numLock:!1,isVirtualKeyboard:!1,isVirtualCapsLockOn:!1,twoBytesScanCodes:[91,219,92,220,29,157,93,221,82,210,83,211,75,203,71,201,79,207,72,200,80,208,73,201,81,209,77,205,28,156],loadKeyMap:function(e,t){try{this.keymap=wdi["Keymap"+e.toUpperCase()].getKeymap(),this.ctrlKeymap=wdi["Keymap"+e.toUpperCase()].getCtrlKeymap(),this.ctrlForbiddenKeymap=wdi["Keymap"+e.toUpperCase()].getCtrlForbiddenKeymap(),this.reservedCtrlKeymap=wdi["Keymap"+e.toUpperCase()].getReservedCtrlKeymap(),this.charmap=wdi["KeymapObj"+e.toUpperCase()].getCharmap(),this.stuckKeysHandler=t}catch(e){this.keymap=wdi.KeymapES.getKeymap(),this.ctrlKeymap=wdi.KeymapES.getCtrlKeymap(),this.ctrlForbiddenKeymap=wdi.KeymapES.getCtrlForbiddenKeymap(),this.reservedCtrlKeymap=wdi.KeymapES.getReservedCtrlKeymap(),this.charmap=wdi.KeymapObjES.getCharmap(),this.stuckKeysHandler=t}},isInKeymap:function(e){return void 0!==this.keymap[e]},getScanCodes:function(e){return e.hasScanCode?e.scanCode:this.isForbiddenCombination(e)?[]:this.isGeneratedShortcut(e.type,e.keyCode,e.generated)?this.getScanCodeFromKeyCode(e.keyCode,e.type,this.ctrlKeymap,this.reservedCtrlKeymap):this.handledByCharmap(e.type)&&e.originalEvent?this.getScanCodesFromCharCode(e.originalEvent.code):this.handledByNormalKeyCode(e.type,e.keyCode)?this.getScanCodeFromKeyCode(e.keyCode,e.type,this.keymap):[]},getScanCodeFromKeyCode:function(e,t,r,i){this.controlPressed(e,t);var a=null;if(void 0===(a=e in r?r[e]:i[e]))return[];if(a<256){if("keydown"==t)return[this.makeKeymap(a)];if("keyup"==t)return[this.makeKeymap(128|a)]}else{if("keydown"==t)return[this.makeKeymap(224|a-256<<8)];if("keyup"==t)return[this.makeKeymap(32992|a-256<<8)]}return a},isForbiddenCombination:function(e){var t=e.keyCode,r=(e.type,this.ctrlForbiddenKeymap);return!!(wdi.KeyEvent.isCtrlPressed(e)&&r[t]&&r[t])},controlPressed:function(e,t,r){if(17===e&&(this.ctrlPressed="keydown"===t),!r)return!1;17!==e&&91!==e&&("keydown"===t?wdi.KeyEvent.isCtrlPressed(r)&&(this.ctrlPressed=!0):"keyup"===t&&(wdi.KeyEvent.isCtrlPressed(r)||(this.ctrlPressed=!1)))},handledByCtrlKeyCode:function(e,t,r){if(("keydown"===e||"keyup"===e||"keypress"===e)&&this.ctrlPressed){if("keypress"===e)return!0;if(this.ctrlKeymap[t])return!0;if(r&&this.reservedCtrlKeymap[t])return!0}return!1},isGeneratedShortcut:function(e,t,r){if(("keydown"===e||"keyup"===e||"keypress"===e)&&this.ctrlPressed){if("keypress"===e)return!0;if(this.ctrlKeymap[t])return!0;if(r&&this.reservedCtrlKeymap[t])return!0}return!1},handledByNormalKeyCode:function(e,t){return!("keydown"!==e&&"keyup"!==e||!this.keymap[t])},handledByCharmap:function(e){return"inputmanager"===e},getScanCodesFromCharCode:function(e){var t=this.charmap[e];return new wdi.ScanCodeObjModifier(t).getScanCode()},makeKeymap:function(e){return-1!=$.inArray(e,this.twoBytesScanCodes)?[224,e,0,0]:[e,0,0]}};const getURLParameter=e=>{const t=new RegExp(`${e}=([^&]+)`).exec(window.location.pathname);return t&&t[1]};let vmHost=window.location.hostname;"localhost"===vmHost&&(vmHost="10.10.101.107");const vmId=getURLParameter("id"),vmPort=window.config.public.PORT;function start(){wdi.graphicDebug=new wdi.GraphicDebug({debugMode:!1});let e,t,o=!1;$(window).resize((function(){app.sendCommand("setResolution",app.toSpiceResolution({width:$(window).width(),height:$(window).height()}))}));const n={callback:function(n,s){if("windowClosed"===n)$(s.canvas).remove(),$(s.eventLayer).remove();else if("windowMoved"===n)$(s.canvas).css({top:s.info.top+"px",left:s.info.left+"px"}),$(s.eventLayer).css({top:s.info.top+"px",left:s.info.left+"px"});else if("init"===n||"windowCreated"===n){let e=null,t=null,o=null;const n=$("body");for(let i in s){e=s[i];const a=2*e.position;t=$(e.canvas).css({zIndex:1e4-a-1,position:"absolute",top:e.info.top+"px",left:e.info.left+"px"}),o=$(e.eventLayer).css({top:e.info.top+"px",left:e.info.left+"px",zIndex:1e4-a}),n.append(t),n.append(o)}}else if("ready"===n){app.setReconnecting(!1),t?.clearTimeout&&(t(),t=!1);const e=$(window).width(),o=$(window).height();app.sendCommand("setResolution",app.toSpiceResolution({width:e,height:o})),wdi.IntegrationBenchmarkEnabled&&($("#integrationBenchmark").css({display:"inline"}),$("#launchWordButton").prop("disabled",!1))}else if("resolution"===n){const{0:e}=s,t=(window.innerWidth-e)/2;t>=0&&(document.getElementById("canvas_0").style.left=t+"px",document.getElementById("eventLayer").style.left=t+"px")}else"windowMinimized"===n?($(s.canvas).css({display:"none"}),$(s.eventLayer).css({display:"none"})):"windowMaximized"===n?($(s.canvas).css({top:s.info.top+"px",left:s.info.left+"px"}),$(s.eventLayer).css({top:s.info.top+"px",left:s.info.left+"px"})):"windowRestored"===n?($(s.canvas).css({display:"block"}),$(s.eventLayer).css({display:"block"}),$(s.canvas).css({top:s.info.top+"px",left:s.info.left+"px"}),$(s.eventLayer).css({top:s.info.top+"px",left:s.info.left+"px"})):"windowFocused"===n||("timeLapseDetected"===n?wdi.Debug.log("Detected time lapse of ",s,"seconds"):"error"===n&&(app.getReconnecting()||(e||(e=setTimeout((function(){console.log("cancelFreeze"),app.cancelFreeze()}),1e4)),t||(t=setTimeout((function(){console.log("cancel reconnection"),o=!0}),6e4))),setTimeout((function(){o||(console.log("Trying reconnect ",Date.now()),app.reconnect({freeze:!0}))}),1e3)))},context:this,host:vmHost,port:vmPort,protocol:"wss",token:"password",vmHost:vmHost,vmPort:vmPort,vmid:vmId,useBus:!1,busHost:"localhost",busPort:61613,busSubscriptions:["/topic/00000000-0000-0000-0000-000000000000"],busUser:"00000000-0000-0000-0000-000000000000",busPass:"potato",layout:"es",useWorkers:!0,seamlessDesktopIntegration:!1,connectionControl:!1,heartbeatToken:"heartbeat",heartbeatTimeout:4e3,externalClipboardHandling:!1,disableClipboard:!1,layer:document.getElementById("vmw"),disableMessageBuffering:!0,clientOffset:{x:0,y:0}};app.run(n)}window.app=new Application({supportHighDPI:!1}),$(document).ready(start);
70
+ !function(e){function t(e){e.startMove=e.startMove?e.startMove:{startX:null,startY:null,timestamp:null};var t=(new Date).getTime();if(e.touches){var s=[{lastX:e.deltaX,lastY:e.deltaY,moved:null,startX:e.screenX-e.startMove.screenX,startY:e.screenY-e.startMove.screenY}],r={vector:e.vector,orientation:window.orientation||null,lastX:s[0].lastX>0?1:s[0].lastX<0?-1:0,lastY:s[0].lastY>0?1:s[0].lastY<0?-1:0,startX:s[0].startX>0?1:s[0].startX<0?-1:0,startY:s[0].startY>0?1:s[0].startY<0?-1:0};s[0].moved=Math.sqrt(Math.pow(Math.abs(s[0].startX),2)+Math.pow(Math.abs(s[0].startY),2))}return{type:e.type||null,originalEvent:e.event||null,delta:s||null,direction:r||{orientation:window.orientation||null,vector:e.vector||null},duration:e.startMove.timestamp?t-e.timestamp:null,rotation:e.rotation||null,scale:e.scale||null,description:e.description||[e.type,":",e.touches,":",0!=s[0].lastX?s[0].lastX>0?"right":"left":"steady",":",0!=s[0].lastY?s[0].lastY>0?"down":"up":"steady"].join("")}}function s(t){e(window).triggerHandler("orientationchange",{direction:{orientation:window.orientation},description:["orientationchange:",["landscape:clockwise:","portrait:default:","landscape:counterclockwise:","portrait:upsidedown:"][window.orientation/90+1],window.orientation].join("")})}function r(t){var s=jQuery(t.currentTarget);s.triggerHandler(e.jGestures.events.touchstart,t),e.hasGestures?(t.currentTarget.addEventListener("touchmove",a,!1),t.currentTarget.addEventListener("touchend",o,!1)):(s.bind("mousemove",a),s.bind("mouseup",o));var r=s.data("ojQueryGestures"),n=t.touches?t.touches[0]:t,c={};c.oLastSwipemove={screenX:n.screenX,screenY:n.screenY,timestamp:(new Date).getTime()},c.oStartTouch={screenX:n.screenX,screenY:n.screenY,timestamp:(new Date).getTime()},s.data("ojQueryGestures",e.extend(!0,r,c))}function a(s){var r=jQuery(s.currentTarget),a=r.data("ojQueryGestures"),o=!!s.touches,n=o?s.changedTouches[0].screenX:s.screenX,c=o?s.changedTouches[0].screenY:s.screenY,i=a.oLastSwipemove,u=n-i.screenX,h=c-i.screenY;if(a.oLastSwipemove){var p=t({type:"swipemove",touches:o?s.touches.length:"1",screenY:c,screenX:n,deltaY:h,deltaX:u,startMove:i,event:s,timestamp:i.timestamp});r.triggerHandler(p.type,p)}var d={},l=s.touches?s.touches[0]:s;d.oLastSwipemove={screenX:l.screenX,screenY:l.screenY,timestamp:(new Date).getTime()},r.data("ojQueryGestures",e.extend(!0,a,d))}function o(s){var r=jQuery(s.currentTarget),n=!!s.changedTouches,c=n?s.changedTouches.length:"1",i=n?s.changedTouches[0].screenX:s.screenX,u=n?s.changedTouches[0].screenY:s.screenY;r.triggerHandler(e.jGestures.events.touchendStart,s),e.hasGestures?(s.currentTarget.removeEventListener("touchmove",a,!1),s.currentTarget.removeEventListener("touchend",o,!1)):(r.unbind("mousemove",a),r.unbind("mouseup",o));var h,p=r.data("ojQueryGestures"),d=Math.abs(p.oStartTouch.screenX-i)>e.jGestures.defaults.thresholdMove||Math.abs(p.oStartTouch.screenY-u)>e.jGestures.defaults.thresholdMove,l=Math.abs(p.oStartTouch.screenX-i)>e.jGestures.defaults.thresholdSwipe||Math.abs(p.oStartTouch.screenY-u)>e.jGestures.defaults.thresholdSwipe;for(h in p){var w=p.oStartTouch,g=(i=n?s.changedTouches[0].screenX:s.screenX,u=n?s.changedTouches[0].screenY:s.screenY,i-w.screenX),v=t({type:"swipe",touches:c,screenY:u,screenX:i,deltaY:u-w.screenY,deltaX:g,startMove:w,event:s,timestamp:w.timestamp}),j=["zero","one","two","three","four"],m=!1;switch(h){case"swipeone":if(!1===n&&1==c&&!1===d)break;(!1===n||1==c&&!0===d&&!0===l)&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipetwo":n&&2==c&&!0===d&&!0===l&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipethree":n&&3==c&&!0===d&&!0===l&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipefour":n&&4==c&&!0===d&&!0===l&&(m=!0,v.type=["swipe",j[c]].join(""),r.triggerHandler(v.type,v));break;case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":case"swipeleftup":n&&!0===d&&!0===l&&(m=!0,v.type=["swipe",0!=v.delta[0].lastX?v.delta[0].lastX>0?"right":"left":"",0!=v.delta[0].lastY?v.delta[0].lastY>0?"down":"up":""].join(""),r.triggerHandler(v.type,v));break;case"tapone":case"taptwo":case"tapthree":case"tapfour":!0!==d&&!0!==m&&j[c]==h.slice(3)&&(v.description=["tap",j[c]].join(""),v.type=["tap",j[c]].join(""),r.triggerHandler(v.type,v))}var G={};r.data("ojQueryGestures",e.extend(!0,p,G)),r.data("ojQueryGestures",e.extend(!0,p,G))}r.triggerHandler(e.jGestures.events.touchendProcessed,s)}function n(t){var s=jQuery(t.currentTarget);s.triggerHandler(e.jGestures.events.gesturestart,t);var r=s.data("ojQueryGestures"),a={};a.oStartTouch={timestamp:(new Date).getTime()},s.data("ojQueryGestures",e.extend(!0,r,a))}function c(s){var r,a,o,n,c=jQuery(s.currentTarget),i=c.data("ojQueryGestures");for(n in i)switch(n){case"pinch":((r=s.scale)<1&&r%1<1-e.jGestures.defaults.thresholdPinchclose||r>1&&r%1>e.jGestures.defaults.thresholdPinchopen)&&(a=r<1?-1:1,o=t({type:"pinch",scale:r,touches:null,startMove:i.oStartTouch,event:s,timestamp:i.oStartTouch.timestamp,vector:a,description:["pinch:",a,":",r<1?"close":"open"].join("")}),c.triggerHandler(o.type,o));break;case"rotate":((r=s.rotation)<1&&-1*r>e.jGestures.defaults.thresholdRotateccw||r>1&&r>e.jGestures.defaults.thresholdRotatecw)&&(a=r<1?-1:1,o=t({type:"rotate",rotation:r,touches:null,startMove:i.oStartTouch,event:s,timestamp:i.oStartTouch.timestamp,vector:a,description:["rotate:",a,":",r<1?"counterclockwise":"clockwise"].join("")}),c.triggerHandler(o.type,o))}}function i(s){var r,a=jQuery(s.currentTarget);a.triggerHandler(e.jGestures.events.gestureendStart,s);var o,n=a.data("ojQueryGestures");for(o in n)switch(o){case"pinchclose":(r=s.scale)<1&&r%1<1-e.jGestures.defaults.thresholdPinchclose&&a.triggerHandler("pinchclose",t({type:"pinchclose",scale:r,vector:-1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"pinch:-1:close"}));break;case"pinchopen":(r=s.scale)>1&&r%1>e.jGestures.defaults.thresholdPinchopen&&a.triggerHandler("pinchopen",t({type:"pinchopen",scale:r,vector:1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"pinch:+1:open"}));break;case"rotatecw":(r=s.rotation)>1&&r>e.jGestures.defaults.thresholdRotatecw&&a.triggerHandler("rotatecw",t({type:"rotatecw",rotation:r,vector:1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"rotate:+1:clockwise"}));break;case"rotateccw":(r=s.rotation)<1&&-1*r>e.jGestures.defaults.thresholdRotateccw&&a.triggerHandler("rotateccw",t({type:"rotateccw",rotation:r,vector:-1,touches:null,startMove:n.oStartTouch,event:s,timestamp:n.oStartTouch.timestamp,description:"rotate:-1:counterclockwise"}))}a.triggerHandler(e.jGestures.events.gestureendProcessed,s)}e.jGestures={},e.jGestures.defaults={},e.jGestures.defaults.thresholdPinchopen=.05,e.jGestures.defaults.thresholdPinchmove=.05,e.jGestures.defaults.thresholdPinch=.05,e.jGestures.defaults.thresholdPinchclose=.05,e.jGestures.defaults.thresholdRotatecw=5,e.jGestures.defaults.thresholdRotateccw=5,e.jGestures.defaults.thresholdMove=20,e.jGestures.defaults.thresholdSwipe=100,e.jGestures.data={},e.jGestures.data.capableDevicesInUserAgentString=["iPad","iPhone","iPod","Mobile Safari"],e.jGestures.data.hasGestures=function(){var t;for(t=0;t<e.jGestures.data.capableDevicesInUserAgentString.length;t++)if(-1!==navigator.userAgent.indexOf(e.jGestures.data.capableDevicesInUserAgentString[t]))return!0;return!1}(),e.hasGestures=e.jGestures.data.hasGestures,e.jGestures.events={touchstart:"jGestures.touchstart",touchendStart:"jGestures.touchend;start",touchendProcessed:"jGestures.touchend;processed",gesturestart:"jGestures.gesturestart",gestureendStart:"jGestures.gestureend;start",gestureendProcessed:"jGestures.gestureend;processed"},jQuery.each({orientationchange_orientationchange01:"orientationchange",gestureend_pinchopen01:"pinchopen",gestureend_pinchclose01:"pinchclose",gestureend_rotatecw01:"rotatecw",gestureend_rotateccw01:"rotateccw",gesturechange_pinch01:"pinch",gesturechange_rotate01:"rotate",touchstart_swipe13:"swipemove",touchstart_swipe01:"swipeone",touchstart_swipe02:"swipetwo",touchstart_swipe03:"swipethree",touchstart_swipe04:"swipefour",touchstart_swipe05:"swipeup",touchstart_swipe06:"swiperightup",touchstart_swipe07:"swiperight",touchstart_swipe08:"swiperightdown",touchstart_swipe09:"swipedown",touchstart_swipe10:"swipeleftdown",touchstart_swipe11:"swipeleft",touchstart_swipe12:"swipeleftup",touchstart_tap01:"tapone",touchstart_tap02:"taptwo",touchstart_tap03:"tapthree",touchstart_tap04:"tapfour"},(function(t,u){jQuery.event.special[u]={setup:function(){var a=t.split("_"),o=a[0],u=a[1].slice(0,a[1].length-2),h=jQuery(this);if(!h.data("ojQueryGestures")||!h.data("ojQueryGestures")[o]){var p=h.data("ojQueryGestures")||{},d={};if(d[o]=!0,e.extend(!0,p,d),h.data("ojQueryGestures",p),e.hasGestures)switch(u){case"orientationchange":h.get(0).addEventListener("orientationchange",s,!1);break;case"tap":case"swipe":case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":h.get(0).addEventListener("touchstart",r,!1);break;case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":h.get(0).addEventListener("gesturestart",n,!1),h.get(0).addEventListener("gestureend",i,!1);break;case"pinch":case"rotate":h.get(0).addEventListener("gesturestart",n,!1),h.get(0).addEventListener("gesturechange",c,!1)}else switch(u){case"tap":case"swipe":h.bind("mousedown",r)}}return!1},add:function(e){return jQuery(this).data("ojQueryGestures")[e.type]={originalType:e.type},!1},remove:function(e){var t=jQuery(this),s=t.data("ojQueryGestures");return s[e.type]=!1,t.data("ojQueryGestures",s),!1},teardown:function(){var u=t.split("_"),h=u[0],p=u[1].slice(0,u[1].length-2),d=jQuery(this);if(!d.data("ojQueryGestures")||!d.data("ojQueryGestures")[h]){var l=d.data("ojQueryGestures")||{},w={};if(w[h]=!1,e.extend(!0,l,w),d.data("ojQueryGestures",l),e.hasGestures)switch(p){case"orientationchange":d.get(0).removeEventListener("orientationchange",s,!1);break;case"tap":case"swipe":case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":case"swipeleftup":d.get(0).removeEventListener("touchstart",r,!1),d.get(0).removeEventListener("touchmove",a,!1),d.get(0).removeEventListener("touchend",o,!1);break;case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":d.get(0).removeEventListener("gesturestart",n,!1),d.get(0).removeEventListener("gestureend",i,!1);break;case"pinch":case"rotate":d.get(0).removeEventListener("gesturestart",n,!1),d.get(0).removeEventListener("gesturechange",c,!1)}else switch(p){case"tap":case"swipe":d.unbind("mousedown",r),d.unbind("mousemove",a),d.unbind("mouseup",o)}}return!1}}}))}(jQuery);var Pixastic=function(){function t(t,a,e){var r=new Array;null==a&&(a=document),null==e&&(e="*");var n=a.getElementsByTagName(e),s=n.length,o=new RegExp("(^|\\s)"+t+"(\\s|$)");for(i=0,j=0;i<s;i++)o.test(n[i].className)&&(r[j]=n[i],j++);return r}function a(t,a){if(Pixastic.debug){try{switch(a){case"warn":console.warn("Pixastic:",t);break;case"error":console.error("Pixastic:",t);break;default:console.log("Pixastic:",t)}}catch(t){}1}}"undefined"!=typeof pixastic_parseonload&&pixastic_parseonload&&function(t){var a=!1,e=function(){a||(a=!0,t())};document.write('<script defer src="//:" id="__onload_ie_pixastic__"><\/script>');var i=document.getElementById("__onload_ie_pixastic__");i.onreadystatechange=function(){"complete"==i.readyState&&(i.parentNode.removeChild(i),e())},document.addEventListener&&document.addEventListener("DOMContentLoaded",e,!1),function(t,a,e){t.addEventListener?t.addEventListener(a,e,!1):t.attachEvent&&t.attachEvent("on"+a,e)}(window,"load",e)}((function(){for(var a=t("pixastic",null,"img"),e=t("pixastic",null,"canvas"),i=a.concat(e),r=0;r<i.length;r++)!function(){for(var t=i[r],a=[],e=t.className.split(" "),n=0;n<e.length;n++){var s=e[n];if("pixastic-"==s.substring(0,9)){var o=s.substring(9);""!=o&&a.push(o)}}if(a.length)if("img"==t.tagName.toLowerCase()){var c=new Image;if(c.src=t.src,c.complete)for(var h=0;h<a.length;h++){var l=Pixastic.applyAction(t,t,a[h],null);l&&(t=l)}else c.onload=function(){for(var e=0;e<a.length;e++){var i=Pixastic.applyAction(t,t,a[e],null);i&&(t=i)}}}else setTimeout((function(){for(var e=0;e<a.length;e++){var i=Pixastic.applyAction(t,t,a[e],null);i&&(t=i)}}),1)}()}));var e=function(){var t=document.createElement("canvas"),a=!1;try{a=!("function"!=typeof t.getContext||!t.getContext("2d"))}catch(t){}return function(){return a}}(),r=function(){var t,a=document.createElement("canvas"),e=!1;try{"function"==typeof a.getContext&&(t=a.getContext("2d"))&&(e="function"==typeof t.getImageData)}catch(t){}return function(){return e}}(),n=function(){var t=!1,a=document.createElement("canvas");if(e()&&r()){a.width=a.height=1;var i=a.getContext("2d");i.fillStyle="rgb(255,0,0)",i.fillRect(0,0,1,1);var n=document.createElement("canvas");n.width=n.height=1;var s=n.getContext("2d");s.fillStyle="rgb(0,0,255)",s.fillRect(0,0,1,1),i.globalAlpha=.5,i.drawImage(n,0,0);var o=i.getImageData(0,0,1,1).data;t=255!=o[2]}return function(){return t}}();return{parseOnLoad:!1,debug:!1,applyAction:function(t,e,i,r){r=r||{};var n,s,o="canvas"==t.tagName.toLowerCase();if(o&&Pixastic.Client.isIE())return Pixastic.debug&&a("Tried to process a canvas element but browser is IE."),!1;var c=!1;Pixastic.Client.hasCanvas()&&(c=!!r.resultCanvas,s=(n=r.resultCanvas||document.createElement("canvas")).getContext("2d"));var h=t.offsetWidth,l=t.offsetHeight;if(o&&(h=t.width,l=t.height),0==h||0==l){if(null!=t.parentNode)return void(Pixastic.debug&&a("Image has 0 width and/or height."));var p=t.style.position,g=t.style.left;t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),h=t.offsetWidth,l=t.offsetHeight,document.body.removeChild(t),t.style.position=p,t.style.left=g}if(i.indexOf("(")>-1){var v=i;i=v.substr(0,v.indexOf("("));var d=v.match(/\((.*?)\)/);if(d[1]){d=d[1].split(";");for(var u=0;u<d.length;u++)if(thisArg=d[u].split("="),2==thisArg.length)if("rect"==thisArg[0]){var f=thisArg[1].split(",");r[thisArg[0]]={left:parseInt(f[0],10)||0,top:parseInt(f[1],10)||0,width:parseInt(f[2],10)||0,height:parseInt(f[3],10)||0}}else r[thisArg[0]]=thisArg[1]}}r.rect?(r.rect.left=Math.round(r.rect.left),r.rect.top=Math.round(r.rect.top),r.rect.width=Math.round(r.rect.width),r.rect.height=Math.round(r.rect.height)):r.rect={left:0,top:0,width:h,height:l};var m=!1;if(Pixastic.Actions[i]&&"function"==typeof Pixastic.Actions[i].process&&(m=!0),!m)return Pixastic.debug&&a('Invalid action "'+i+'". Maybe file not included?'),!1;if(!Pixastic.Actions[i].checkSupport())return Pixastic.debug&&a('Action "'+i+'" not supported by this browser.'),!1;Pixastic.Client.hasCanvas()?(n!==t&&(n.width=h,n.height=l),c||(n.style.width=h+"px",n.style.height=l+"px"),s.drawImage(e,0,0,h,l),t.__pixastic_org_image?(n.__pixastic_org_image=t.__pixastic_org_image,n.__pixastic_org_width=t.__pixastic_org_width,n.__pixastic_org_height=t.__pixastic_org_height):(n.__pixastic_org_image=t,n.__pixastic_org_width=h,n.__pixastic_org_height=l)):Pixastic.Client.isIE()&&void 0===t.__pixastic_org_style&&(t.__pixastic_org_style=t.style.cssText);var x={image:t,canvas:n,width:h,height:l,useData:!0,options:r};return!!Pixastic.Actions[i].process(x)&&(Pixastic.Client.hasCanvas()?(x.useData&&Pixastic.Client.hasCanvasImageData()&&(n.getContext("2d").putImageData(x.canvasData,r.rect.left,r.rect.top),n.getContext("2d").fillRect(0,0,0,0)),r.leaveDOM||(n.title=t.title,n.imgsrc=t.imgsrc,o||(n.alt=t.alt),o||(n.imgsrc=t.src),n.className=t.className,n.style.cssText=t.style.cssText,n.name=t.name,n.tabIndex=t.tabIndex,n.id=t.id,t.parentNode&&t.parentNode.replaceChild&&t.parentNode.replaceChild(n,t)),r.resultCanvas=n,n):t)},prepareData:function(t,a){var e=t.canvas.getContext("2d"),i=t.options.rect,r=e.getImageData(i.left,i.top,i.width,i.height),n=r.data;return a||(t.canvasData=r),n},process:function(t,a,e,i){if("img"==t.tagName.toLowerCase()){var r=new Image;if(r.src=t.src,r.complete){var n=Pixastic.applyAction(t,r,a,e);return i&&i(n),n}r.onload=function(){var n=Pixastic.applyAction(t,r,a,e);i&&i(n)}}if("canvas"==t.tagName.toLowerCase()){n=Pixastic.applyAction(t,t,a,e);return i&&i(n),n}},revert:function(t){if(Pixastic.Client.hasCanvas()){if("canvas"==t.tagName.toLowerCase()&&t.__pixastic_org_image)return t.width=t.__pixastic_org_width,t.height=t.__pixastic_org_height,t.getContext("2d").drawImage(t.__pixastic_org_image,0,0),t.parentNode&&t.parentNode.replaceChild&&t.parentNode.replaceChild(t.__pixastic_org_image,t),t}else Pixastic.Client.isIE()&&void 0!==t.__pixastic_org_style&&(t.style.cssText=t.__pixastic_org_style)},Client:{hasCanvas:e,hasCanvasImageData:r,hasGlobalAlpha:n,isIE:function(){return!!document.all&&!!window.attachEvent&&!window.opera}},Actions:{}}}();"undefined"!=typeof jQuery&&jQuery&&jQuery.fn&&(jQuery.fn.pixastic=function(t,a){var e=[];return this.each((function(){if("img"!=this.tagName.toLowerCase()||this.complete){var i=Pixastic.process(this,t,a);i&&e.push(i)}})),e.length>0?jQuery(e):this}),Pixastic.Actions.blend={process:function(t){var a=parseFloat(t.options.amount),e=(t.options.mode||"normal").toLowerCase(),i=t.options.image;if(a=Math.max(0,Math.min(1,a)),!i)return!1;if(Pixastic.Client.hasCanvasImageData()){var r=t.options.rect,n=Pixastic.prepareData(t),s=r.width,o=r.height;t.useData=!1;var c=document.createElement("canvas");c.width=t.canvas.width,c.height=t.canvas.height;var h=c.getContext("2d");h.drawImage(i,0,0);var l,p,g,v,d,u,f,m,x,C,w,P,I,D,M={canvas:c,options:t.options},b=Pixastic.prepareData(M),y=M.canvasData,_=4*(S=s*o),k=!1;switch(e){case"normal":break;case"multiply":for(;S--;)b[_-=4]=n[_]*b[_]/255,b[l=_+1]=n[l]*b[l]/255,b[p=_+2]=n[p]*b[p]/255;k=!0;break;case"lighten":for(;S--;)(g=n[_-=4])>b[_]&&(b[_]=g),(v=n[l=_+1])>b[l]&&(b[l]=v),(d=n[p=_+2])>b[p]&&(b[p]=d);k=!0;break;case"darken":for(;S--;)(g=n[_-=4])<b[_]&&(b[_]=g),(v=n[l=_+1])<b[l]&&(b[l]=v),(d=n[p=_+2])<b[p]&&(b[p]=d);k=!0;break;case"darkercolor":for(;S--;).3*(g=n[_-=4])+.59*(v=n[l=_+1])+.11*(d=n[p=_+2])<=.3*b[_]+.59*b[l]+.11*b[p]&&(b[_]=g,b[l]=v,b[p]=d);k=!0;break;case"lightercolor":for(;S--;).3*(g=n[_-=4])+.59*(v=n[l=_+1])+.11*(d=n[p=_+2])>.3*b[_]+.59*b[l]+.11*b[p]&&(b[_]=g,b[l]=v,b[p]=d);k=!0;break;case"lineardodge":for(;S--;)(x=n[_-=4]+b[_])>255?b[_]=255:b[_]=x,(C=n[l=_+1]+b[l])>255?b[l]=255:b[l]=C,(w=n[p=_+2]+b[p])>255?b[p]=255:b[p]=w;k=!0;break;case"linearburn":for(;S--;)(x=n[_-=4]+b[_])<255?b[_]=0:b[_]=x-255,(C=n[l=_+1]+b[l])<255?b[l]=0:b[l]=C-255,(w=n[p=_+2]+b[p])<255?b[p]=0:b[p]=w-255;k=!0;break;case"difference":for(;S--;)(x=n[_-=4]-b[_])<0?b[_]=-x:b[_]=x,(C=n[l=_+1]-b[l])<0?b[l]=-C:b[l]=C,(w=n[p=_+2]-b[p])<0?b[p]=-w:b[p]=w;k=!0;break;case"screen":for(;S--;)b[_-=4]=255-((255-b[_])*(255-n[_])>>8),b[l=_+1]=255-((255-b[l])*(255-n[l])>>8),b[p=_+2]=255-((255-b[p])*(255-n[p])>>8);k=!0;break;case"exclusion":for(var A=2/255;S--;)b[_-=4]=(g=n[_])-(g*A-1)*b[_],b[l=_+1]=(v=n[l])-(v*A-1)*b[l],b[p=_+2]=(d=n[p])-(d*A-1)*b[p];k=!0;break;case"overlay":for(A=2/255;S--;)(g=n[_-=4])<128?b[_]=b[_]*g*A:b[_]=255-(255-b[_])*(255-g)*A,(v=n[l=_+1])<128?b[l]=b[l]*v*A:b[l]=255-(255-b[l])*(255-v)*A,(d=n[p=_+2])<128?b[p]=b[p]*d*A:b[p]=255-(255-b[p])*(255-d)*A;k=!0;break;case"softlight":for(A=2/255;S--;)(g=n[_-=4])<128?b[_]=(64+(b[_]>>1))*g*A:b[_]=255-(191-(b[_]>>1))*(255-g)*A,(v=n[l=_+1])<128?b[l]=(64+(b[l]>>1))*v*A:b[l]=255-(191-(b[l]>>1))*(255-v)*A,(d=n[p=_+2])<128?b[p]=(64+(b[p]>>1))*d*A:b[p]=255-(191-(b[p]>>1))*(255-d)*A;k=!0;break;case"hardlight":for(A=2/255;S--;)(u=b[_-=4])<128?b[_]=n[_]*u*A:b[_]=255-(255-n[_])*(255-u)*A,(f=b[l=_+1])<128?b[l]=n[l]*f*A:b[l]=255-(255-n[l])*(255-f)*A,(m=b[p=_+2])<128?b[p]=n[p]*m*A:b[p]=255-(255-n[p])*(255-m)*A;k=!0;break;case"colordodge":for(;S--;)(x=(n[_-=4]<<8)/(255-(u=b[_])))>255||255==u?b[_]=255:b[_]=x,(C=(n[l=_+1]<<8)/(255-(f=b[l])))>255||255==f?b[l]=255:b[l]=C,(w=(n[p=_+2]<<8)/(255-(m=b[p])))>255||255==m?b[p]=255:b[p]=w;k=!0;break;case"colorburn":for(;S--;)(x=255-(255-n[_-=4]<<8)/b[_])<0||0==b[_]?b[_]=0:b[_]=x,(C=255-(255-n[l=_+1]<<8)/b[l])<0||0==b[l]?b[l]=0:b[l]=C,(w=255-(255-n[p=_+2]<<8)/b[p])<0||0==b[p]?b[p]=0:b[p]=w;k=!0;break;case"linearlight":for(;S--;)(x=2*(u=b[_-=4])+n[_]-256)<0||u<128&&x<0?b[_]=0:b[_]=x>255?255:x,(C=2*(f=b[l=_+1])+n[l]-256)<0||f<128&&C<0?b[l]=0:b[l]=C>255?255:C,(w=2*(m=b[p=_+2])+n[p]-256)<0||m<128&&w<0?b[p]=0:b[p]=w>255?255:w;k=!0;break;case"vividlight":for(;S--;)(u=b[_-=4])<128?u?(x=255-(255-n[_]<<8)/(2*u))<0?b[_]=0:b[_]=x:b[_]=0:(x=P=2*u-256)<255?(x=(n[_]<<8)/(255-P))>255?b[_]=255:b[_]=x:b[_]=x<0?0:x,(f=b[l=_+1])<128?f?(C=255-(255-n[l]<<8)/(2*f))<0?b[l]=0:b[l]=C:b[l]=0:(C=I=2*f-256)<255?(C=(n[l]<<8)/(255-I))>255?b[l]=255:b[l]=C:b[l]=C<0?0:C,(m=b[p=_+2])<128?m?(w=255-(255-n[p]<<8)/(2*m))<0?b[p]=0:b[p]=w:b[p]=0:(w=D=2*m-256)<255?(w=(n[p]<<8)/(255-D))>255?b[p]=255:b[p]=w:b[p]=w<0?0:w;k=!0;break;case"pinlight":for(;S--;)(u=b[_-=4])<128?(g=n[_])<(P=2*u)?b[_]=g:b[_]=P:(g=n[_])>(P=2*u-256)?b[_]=g:b[_]=P,(f=b[l=_+1])<128?(v=n[l])<(I=2*f)?b[l]=v:b[l]=I:(v=n[l])>(I=2*f-256)?b[l]=v:b[l]=I,(u=b[p=_+2])<128?(g=n[p])<(P=2*u)?b[p]=g:b[p]=P:(g=n[p])>(P=2*u-256)?b[p]=g:b[p]=P;k=!0;break;case"hardmix":for(;S--;)(u=b[_-=4])<128?255-(255-n[_]<<8)/(2*u)<128||0==u?b[_]=0:b[_]=255:(P=2*u-256)<255&&(n[_]<<8)/(255-P)<128?b[_]=0:b[_]=255,(f=b[l=_+1])<128?255-(255-n[l]<<8)/(2*f)<128||0==f?b[l]=0:b[l]=255:(I=2*f-256)<255&&(n[l]<<8)/(255-I)<128?b[l]=0:b[l]=255,(m=b[p=_+2])<128?255-(255-n[p]<<8)/(2*m)<128||0==m?b[p]=0:b[p]=255:(D=2*m-256)<255&&(n[p]<<8)/(255-D)<128?b[p]=0:b[p]=255;k=!0}if(k&&h.putImageData(y,0,0),1==a||Pixastic.Client.hasGlobalAlpha()){var E=t.canvas.getContext("2d");E.save(),E.globalAlpha=a,E.drawImage(c,0,0,r.width,r.height,r.left,r.top,r.width,r.height),E.globalAlpha=1,E.restore()}else{for(var S=s*o,F=a,L=1-a;S--;){var N=n[_=4*S]*L+b[_]*F|0,R=n[_+1]*L+b[_+1]*F|0,T=n[_+2]*L+b[_+2]*F|0;n[_]=N,n[_+1]=R,n[_+2]=T}t.useData=!0}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.blur={process:function(t){if(void 0===t.options.fixMargin&&(t.options.fixMargin=!0),Pixastic.Client.hasCanvasImageData()){for(var a=Pixastic.prepareData(t),e=Pixastic.prepareData(t,!0),i=[[0,1,0],[1,2,1],[0,1,0]],r=0,n=0;n<3;n++)for(var s=0;s<3;s++)r+=i[n][s];r=1/(2*r);var o=t.options.rect,c=o.width,h=o.height,l=4*c,p=h;do{var g=(p-1)*l,v=(1==p?0:p-2)*c*4,d=(p==h?p-1:p)*c*4,u=c;do{var f=g+(4*u-4),m=v+4*(1==u?0:u-2),x=d+4*(u==c?u-1:u);a[f]=(2*(e[m]+e[f-4]+e[f+4]+e[x])+4*e[f])*r,a[f+1]=(2*(e[m+1]+e[f-3]+e[f+5]+e[x+1])+4*e[f+1])*r,a[f+2]=(2*(e[m+2]+e[f-2]+e[f+6]+e[x+2])+4*e[f+2])*r}while(--u)}while(--p);return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" progid:DXImageTransform.Microsoft.Blur(pixelradius=1.5)",t.options.fixMargin&&(t.image.style.marginLeft=(parseInt(t.image.style.marginLeft,10)||0)-2+"px",t.image.style.marginTop=(parseInt(t.image.style.marginTop,10)||0)-2+"px"),!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.blurfast={process:function(t){var a=parseFloat(t.options.amount)||0,e=!(!t.options.clear||"false"==t.options.clear);if(a=Math.max(0,Math.min(5,a)),Pixastic.Client.hasCanvas()){var i=t.options.rect,r=t.canvas.getContext("2d");r.save(),r.beginPath(),r.rect(i.left,i.top,i.width,i.height),r.clip();var n=Math.round(t.width/2),s=Math.round(t.height/2),o=document.createElement("canvas");o.width=n,o.height=s;e=!1;for(var c=Math.round(20*a),h=o.getContext("2d"),l=0;l<c;l++){var p=Math.max(1,Math.round(n-l)),g=Math.max(1,Math.round(s-l));h.clearRect(0,0,n,s),h.drawImage(t.canvas,0,0,t.width,t.height,0,0,p,g),e&&r.clearRect(i.left,i.top,i.width,i.height),r.drawImage(o,0,0,p,g,0,0,t.width,t.height)}return r.restore(),t.useData=!1,!0}if(Pixastic.Client.isIE()){var v=10*a;return t.image.style.filter+=" progid:DXImageTransform.Microsoft.Blur(pixelradius="+v+")",t.options.fixMargin,t.image.style.marginLeft=(parseInt(t.image.style.marginLeft,10)||0)-Math.round(v)+"px",t.image.style.marginTop=(parseInt(t.image.style.marginTop,10)||0)-Math.round(v)+"px",!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()||Pixastic.Client.isIE()}},Pixastic.Actions.brightness={process:function(t){var a=parseInt(t.options.brightness,10)||0,e=parseFloat(t.options.contrast)||0,i=!(!t.options.legacy||"false"==t.options.legacy);if(i)a=Math.min(150,Math.max(-150,a));else var r=1+Math.min(150,Math.max(-150,a))/150;if(e=Math.max(0,e+1),Pixastic.Client.hasCanvasImageData()){var n,s,o,c,h,l,p,g=Pixastic.prepareData(t),v=t.options.rect,d=v.width*v.height,u=4*d;for(1!=e?i?(o=e,c=(a-128)*e+128):(o=r*e,c=128*-e+128):i?(o=1,c=a):(o=r,c=0);d--;)(h=g[u-=4]*o+c)>255?g[u]=255:g[u]=h<0?0:h,(l=g[n=u+1]*o+c)>255?g[n]=255:g[n]=l<0?0:l,(p=g[s=u+2]*o+c)>255?g[s]=255:g[s]=p<0?0:p;return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.coloradjust={process:function(t){var a=parseFloat(t.options.red)||0,e=parseFloat(t.options.green)||0,i=parseFloat(t.options.blue)||0;if(a=Math.round(255*a),e=Math.round(255*e),i=Math.round(255*i),Pixastic.Client.hasCanvasImageData()){for(var r,n,s,o,c,h=Pixastic.prepareData(t),l=t.options.rect,p=l.width*l.height,g=4*p;p--;)g-=4,a&&((s=h[g]+a)<0?h[g]=0:h[g]=s>255?255:s),e&&((o=h[r=g+1]+e)<0?h[r]=0:h[r]=o>255?255:o),i&&((c=h[n=g+2]+i)<0?h[n]=0:h[n]=c>255?255:c);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.colorhistogram={array256:function(t){arr=[];for(var a=0;a<256;a++)arr[a]=t;return arr},process:function(t){"object"!=typeof t.options.returnValue&&(t.options.returnValue={rvals:[],gvals:[],bvals:[]});var a=!!t.options.paint,e=t.options.returnValue;if("array"!=typeof e.values&&(e.rvals=[],e.gvals=[],e.bvals=[]),Pixastic.Client.hasCanvasImageData()){var i=Pixastic.prepareData(t);t.useData=!1;for(var r=this.array256(0),n=this.array256(0),s=this.array256(0),o=t.options.rect,c=o.width*o.height,h=4*c;c--;)r[i[h-=4]]++,n[i[h+1]]++,s[i[h+2]]++;if(e.rvals=r,e.gvals=n,e.bvals=s,a)for(var l=t.canvas.getContext("2d"),p=[r,n,s],g=0;g<3;g++){for(var v=(g+1)*t.height/3,d=0,u=0;u<256;u++)p[g][u]>d&&(d=p[g][u]);var f=t.height/3/d,m=t.width/256;0==g?l.fillStyle="rgba(255,0,0,0.5)":1==g?l.fillStyle="rgba(0,255,0,0.5)":2==g&&(l.fillStyle="rgba(0,0,255,0.5)");for(u=0;u<256;u++)l.fillRect(u*m,t.height-f*p[g][u]-t.height+v,m,p[g][u]*f)}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.crop={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.options.rect,e=a.width,i=a.height,r=a.top,n=a.left;void 0!==t.options.left&&(n=parseInt(t.options.left,10)),void 0!==t.options.top&&(r=parseInt(t.options.top,10)),void 0!==t.options.height&&(e=parseInt(t.options.width,10)),void 0!==t.options.height&&(i=parseInt(t.options.height,10)),n<0&&(n=0),n>t.width-1&&(n=t.width-1),r<0&&(r=0),r>t.height-1&&(r=t.height-1),e<1&&(e=1),n+e>t.width&&(e=t.width-n),i<1&&(i=1),r+i>t.height&&(i=t.height-r);var s=document.createElement("canvas");return s.width=t.width,s.height=t.height,s.getContext("2d").drawImage(t.canvas,0,0),t.canvas.width=e,t.canvas.height=i,t.canvas.getContext("2d").clearRect(0,0,e,i),t.canvas.getContext("2d").drawImage(s,n,r,e,i,0,0,e,i),t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.desaturate={process:function(t){var a=!(!t.options.average||"false"==t.options.average);if(Pixastic.Client.hasCanvasImageData()){var e,i,r=Pixastic.prepareData(t),n=t.options.rect,s=n.width*n.height,o=4*s;if(a)for(;s--;)r[o-=4]=r[e=o+1]=r[i=o+2]=(r[o]+r[e]+r[i])/3;else for(;s--;)r[o-=4]=r[e=o+1]=r[i=o+2]=.3*r[o]+.59*r[e]+.11*r[i];return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" gray",!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.edges={process:function(t){var a=!(!t.options.mono||"false"==t.options.mono),e=!(!t.options.invert||"false"==t.options.invert);if(Pixastic.Client.hasCanvasImageData()){var i=Pixastic.prepareData(t),r=Pixastic.prepareData(t,!0),n=-1/8;weight=-8;var s=t.options.rect,o=s.width,c=s.height,h=4*o,l=c;do{var p=(l-1)*h,g=(1==l?0:l-2)*o*4,v=(l==c?l-1:l)*o*4,d=o;do{var u=p+(4*d-4),f=g+4*(1==d?0:d-2),m=v+4*(d==o?d-1:d),x=((r[f-4]+r[f]+r[f+4]+r[u-4]+r[u+4]+r[m-4]+r[m]+r[m+4])*n+r[u])*weight,C=((r[f-3]+r[f+1]+r[f+5]+r[u-3]+r[u+5]+r[m-3]+r[m+1]+r[m+5])*n+r[u+1])*weight,w=((r[f-2]+r[f+2]+r[f+6]+r[u-2]+r[u+6]+r[m-2]+r[m+2]+r[m+6])*n+r[u+2])*weight;if(a){var P=.3*x+.59*C+.11*w||0;e&&(P=255-P),P<0&&(P=0),P>255&&(P=255),x=C=w=P}else e&&(x=255-x,C=255-C,w=255-w),x<0&&(x=0),C<0&&(C=0),w<0&&(w=0),x>255&&(x=255),C>255&&(C=255),w>255&&(w=255);i[u]=x,i[u+1]=C,i[u+2]=w}while(--d)}while(--l);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.edges2={process:function(t){if(Pixastic.Client.hasCanvasImageData()){for(var a=Pixastic.prepareData(t),e=Pixastic.prepareData(t,!0),i=t.options.rect,r=i.width,n=4*r,s=n+4,o=i.height-1,c=r-1,h=1;h<o;++h){for(var l=s-4,p=l-n,g=l+n,v=-e[p]-e[l]-e[g],d=-e[++p]-e[++l]-e[++g],u=-e[++p]-e[++l]-e[++g],f=e[p+=2],m=e[++p],x=e[++p],C=e[l+=2],w=e[++l],P=e[++l],I=e[g+=2],D=e[++g],M=e[++g],b=-f-C-I,y=-m-w-D,_=-x-P-M,k=1;k<c;++k){g=(l=s+4)+n;var A=127+v-f- -8*C-I,E=127+d-m- -8*w-D,S=127+u-x- -8*P-M;v=b,d=y,u=_,f=e[p=l-n],m=e[++p],x=e[++p],C=e[l],w=e[++l],P=e[++l],(A+=b=-f-C-(I=e[g]))>255&&(A=255),(E+=y=-m-w-(D=e[++g]))>255&&(E=255),(S+=_=-x-P-(M=e[++g]))>255&&(S=255),A<0&&(A=0),E<0&&(E=0),S<0&&(S=0),a[s]=A,a[++s]=E,a[++s]=S,s+=2}s+=8}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.emboss={process:function(t){var a=parseFloat(t.options.strength)||1,e=void 0!==t.options.greyLevel?parseInt(t.options.greyLevel):180,i=t.options.direction||"topleft",r=!(!t.options.blend||"false"==t.options.blend),n=0,s=0;switch(i){case"topleft":n=-1,s=-1;break;case"top":n=-1,s=0;break;case"topright":n=-1,s=1;break;case"right":n=0,s=1;break;case"bottomright":n=1,s=1;break;case"bottom":n=1,s=0;break;case"bottomleft":n=1,s=-1;break;case"left":n=0,s=-1}if(Pixastic.Client.hasCanvasImageData()){var o=Pixastic.prepareData(t),c=Pixastic.prepareData(t,!0),h=(t.options.invertAlpha,t.options.rect),l=h.width,p=h.height,g=4*l,v=p;do{var d=(v-1)*g,u=n;v+u<1&&(u=0),v+u>p&&(u=0);var f=(v-1+u)*l*4,m=l;do{var x=d+4*(m-1),C=s;m+C<1&&(C=0),m+C>l&&(C=0);var w=f+4*(m-1+C),P=c[x]-c[w],I=c[x+1]-c[w+1],D=c[x+2]-c[w+2],M=P,b=M>0?M:-M;if((I>0?I:-I)>b&&(M=I),(D>0?D:-D)>b&&(M=D),M*=a,r){var y=o[x]+M,_=o[x+1]+M,k=o[x+2]+M;o[x]=y>255?255:y<0?0:y,o[x+1]=_>255?255:_<0?0:_,o[x+2]=k>255?255:k<0?0:k}else{var A=e-M;A<0?A=0:A>255&&(A=255),o[x]=o[x+1]=o[x+2]=A}}while(--m)}while(--v);return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" progid:DXImageTransform.Microsoft.emboss()",!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.flip={process:function(t){var a=t.options.rect,e=document.createElement("canvas");e.width=a.width,e.height=a.height,e.getContext("2d").drawImage(t.image,a.left,a.top,a.width,a.height,0,0,a.width,a.height);var i=t.canvas.getContext("2d");return i.clearRect(a.left,a.top,a.width,a.height),"horizontal"==t.options.axis?(i.scale(-1,1),i.drawImage(e,-a.left-a.width,a.top,a.width,a.height)):(i.scale(1,-1),i.drawImage(e,a.left,-a.top-a.height,a.width,a.height)),t.useData=!1,!0},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.fliph={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.options.rect,e=document.createElement("canvas");e.width=a.width,e.height=a.height,e.getContext("2d").drawImage(t.image,a.left,a.top,a.width,a.height,0,0,a.width,a.height);var i=t.canvas.getContext("2d");return i.clearRect(a.left,a.top,a.width,a.height),i.scale(-1,1),i.drawImage(e,-a.left-a.width,a.top,a.width,a.height),t.useData=!1,!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" fliph",!0},checkSupport:function(){return Pixastic.Client.hasCanvas()||Pixastic.Client.isIE()}},Pixastic.Actions.flipv={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.options.rect,e=document.createElement("canvas");e.width=a.width,e.height=a.height,e.getContext("2d").drawImage(t.image,a.left,a.top,a.width,a.height,0,0,a.width,a.height);var i=t.canvas.getContext("2d");return i.clearRect(a.left,a.top,a.width,a.height),i.scale(1,-1),i.drawImage(e,a.left,-a.top-a.height,a.width,a.height),t.useData=!1,!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" flipv",!0},checkSupport:function(){return Pixastic.Client.hasCanvas()||Pixastic.Client.isIE()}},Pixastic.Actions.glow={process:function(t){var a=parseFloat(t.options.amount)||0,e=parseFloat(t.options.radius)||0;if(a=Math.min(1,Math.max(0,a)),e=Math.min(5,Math.max(0,e)),Pixastic.Client.hasCanvasImageData()){var i=t.options.rect,r=document.createElement("canvas");r.width=t.width,r.height=t.height;var n=r.getContext("2d");n.drawImage(t.canvas,0,0);var s=Math.round(t.width/2),o=Math.round(t.height/2),c=document.createElement("canvas");c.width=s,c.height=o;for(var h=Math.round(20*e),l=c.getContext("2d"),p=0;p<h;p++){var g=Math.max(1,Math.round(s-p)),v=Math.max(1,Math.round(o-p));l.clearRect(0,0,s,o),l.drawImage(r,0,0,t.width,t.height,0,0,g,v),n.clearRect(0,0,t.width,t.height),n.drawImage(c,0,0,g,v,0,0,t.width,t.height)}for(var d=Pixastic.prepareData(t),u=Pixastic.prepareData({canvas:r,options:t.options}),f=i.width*i.height,m=4*f,x=m+1,C=m+2;f--;)(d[m-=4]+=a*u[m])>255&&(d[m]=255),(d[x-=4]+=a*u[x])>255&&(d[x]=255),(d[C-=4]+=a*u[C])>255&&(d[C]=255);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.histogram={process:function(t){var a=!(!t.options.average||"false"==t.options.average),e=!(!t.options.paint||"false"==t.options.paint),i=t.options.color||"rgba(255,255,255,0.5)",r=[];"object"!=typeof t.options.returnValue&&(t.options.returnValue={values:[]});var n=t.options.returnValue;if("array"!=typeof n.values&&(n.values=[]),r=n.values,Pixastic.Client.hasCanvasImageData()){var s=Pixastic.prepareData(t);t.useData=!1;for(var o=0;o<256;o++)r[o]=0;var c=t.options.rect,h=c.width*c.height,l=4*h,p=Math.round;if(a)for(;h--;)r[p((s[l-=4]+s[l+1]+s[l+2])/3)]++;else for(;h--;)r[p(.3*s[l-=4]+.59*s[l+1]+.11*s[l+2])]++;if(e){var g=0;for(o=0;o<256;o++)r[o]>g&&(g=r[o]);var v=t.height/g,d=t.width/256,u=t.canvas.getContext("2d");u.fillStyle=i;for(o=0;o<256;o++)u.fillRect(o*d,t.height-v*r[o],d,r[o]*v)}return n.values=r,!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.hsl={process:function(t){var a=parseInt(t.options.hue,10)||0,e=(parseInt(t.options.saturation,10)||0)/100,i=(parseInt(t.options.lightness,10)||0)/100;if(e<0)var r=1+e;else r=1+2*e;var n=6*(a=a%360/360),s=255*i,o=1+i,c=1-i;if(Pixastic.Client.hasCanvasImageData()){for(var h=Pixastic.prepareData(t),l=t.options.rect,p=l.width*l.height,g=4*p,v=g+1,d=g+2;p--;){var u=h[g-=4],f=h[v=g+1],m=h[d=g+2];if(0!=a||0!=e){var x=u;f>x&&(x=f),m>x&&(x=m);var C=u;f<C&&(C=f),m<C&&(C=m);var w=x-C,P=(C+x)/510;if(P>0&&w>0){if(P<=.5){(D=w/(x+C)*r)>1&&(D=1);var I=P*(1+D)}else{var D;(D=w/(510-x-C)*r)>1&&(D=1);I=P+D-P*D}if(u==x)if(f==C)var M=5+(x-m)/w+n;else M=1-(x-f)/w+n;else if(f==x)if(m==C)M=1+(x-u)/w+n;else M=3-(x-m)/w+n;else if(u==C)M=3+(x-f)/w+n;else M=5-(x-u)/w+n;M<0&&(M+=6),M>=6&&(M-=6);var b=P+P-I,y=M|0;0==y?(u=255*I,f=255*(b+(I-b)*(M-y)),m=255*b):1==y?(u=255*(I-(I-b)*(M-y)),f=255*I,m=255*b):2==y?(u=255*b,f=255*I,m=255*(b+(I-b)*(M-y))):3==y?(u=255*b,f=255*(I-(I-b)*(M-y)),m=255*I):4==y?(u=255*(b+(I-b)*(M-y)),f=255*b,m=255*I):5==y&&(u=255*I,f=255*b,m=255*(I-(I-b)*(M-y)))}}i<0?(u*=o,f*=o,m*=o):i>0&&(u=u*c+s,f=f*c+s,m=m*c+s),h[g]=u<0?0:u>255?255:u,h[v]=f<0?0:f>255?255:f,h[d]=m<0?0:m>255?255:m}return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.invert={process:function(t){if(Pixastic.Client.hasCanvasImageData()){for(var a=Pixastic.prepareData(t),e=!!t.options.invertAlpha,i=t.options.rect,r=i.width*i.height,n=4*r,s=n+1,o=n+2,c=n+3;r--;)a[n-=4]=255-a[n],a[s-=4]=255-a[s],a[o-=4]=255-a[o],e&&(a[c-=4]=255-a[c]);return!0}if(Pixastic.Client.isIE())return t.image.style.filter+=" invert",!0},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.laplace={process:function(t){var a=!(!t.options.invert||"false"==t.options.invert),e=parseFloat(t.options.edgeStrength)||0,i=parseInt(t.options.greyLevel)||0;if(e=-e,Pixastic.Client.hasCanvasImageData()){var r=Pixastic.prepareData(t),n=Pixastic.prepareData(t,!0),s=1/8,o=t.options.rect,c=o.width,h=o.height,l=4*c,p=h;do{var g=(p-1)*l,v=(1==p?0:p-2)*c*4,d=(p==h?p-1:p)*c*4,u=c;do{var f=g+(4*u-4),m=v+4*(1==u?0:u-2),x=d+4*(u==c?u-1:u),C=((-n[m-4]-n[m]-n[m+4]-n[f-4]-n[f+4]-n[x-4]-n[x]-n[x+4]+8*n[f])*s+(-n[m-3]-n[m+1]-n[m+5]-n[f-3]-n[f+5]-n[x-3]-n[x+1]-n[x+5]+8*n[f+1])*s+(-n[m-2]-n[m+2]-n[m+6]-n[f-2]-n[f+6]-n[x-2]-n[x+2]-n[x+6]+8*n[f+2])*s)/3+i;0!=e&&(C>127?C+=(C+1-128)*e:C<127&&(C-=(C+1)*e)),a&&(C=255-C),C<0&&(C=0),C>255&&(C=255),r[f]=r[f+1]=r[f+2]=C}while(--u)}while(--p);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.lighten={process:function(t){var a=parseFloat(t.options.amount)||0;if(a=Math.max(-1,Math.min(1,a)),Pixastic.Client.hasCanvasImageData()){for(var e=Pixastic.prepareData(t),i=t.options.rect,r=i.width*i.height,n=4*r,s=n+1,o=n+2,c=a+1;r--;)(e[n-=4]=e[n]*c)>255&&(e[n]=255),(e[s-=4]=e[s]*c)>255&&(e[s]=255),(e[o-=4]=e[o]*c)>255&&(e[o]=255);return!0}if(Pixastic.Client.isIE()){var h=t.image;return a<0?(h.style.filter+=" light()",h.filters[h.filters.length-1].addAmbient(255,255,255,100*-a)):a>0&&(h.style.filter+=" light()",h.filters[h.filters.length-1].addAmbient(255,255,255,100),h.filters[h.filters.length-1].addAmbient(255,255,255,100*a)),!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE()}},Pixastic.Actions.mosaic={process:function(t){var a=Math.max(1,parseInt(t.options.blockSize,10));if(Pixastic.Client.hasCanvasImageData()){var e=t.options.rect,i=e.width,r=e.height,n=r,s=t.canvas.getContext("2d"),o=document.createElement("canvas");o.width=o.height=1;var c=o.getContext("2d"),h=document.createElement("canvas");h.width=i,h.height=r,h.getContext("2d").drawImage(t.canvas,e.left,e.top,i,r,0,0,i,r);for(n=0;n<r;n+=a)for(var l=0;l<i;l+=a){var p=a,g=a;p+l>i&&(p=i-l),g+n>r&&(g=r-n),c.drawImage(h,l,n,p,g,0,0,1,1);var v=c.getImageData(0,0,1,1).data;s.fillStyle="rgb("+v[0]+","+v[1]+","+v[2]+")",s.fillRect(e.left+l,e.top+n,a,a)}return t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.noise={process:function(t){var a=0,e=0,i=!1;void 0!==t.options.amount&&(a=parseFloat(t.options.amount)||0),void 0!==t.options.strength&&(e=parseFloat(t.options.strength)||0),void 0!==t.options.mono&&(i=!(!t.options.mono||"false"==t.options.mono)),a=Math.max(0,Math.min(1,a));var r=128*(e=Math.max(0,Math.min(1,e))),n=r/2;if(Pixastic.Client.hasCanvasImageData()){var s=Pixastic.prepareData(t),o=t.options.rect,c=o.width,h=4*c,l=o.height,p=Math.random;do{var g=(l-1)*h,v=c;do{var d=g+4*(v-1);if(p()<a){if(i)var u=-n+p()*r,f=s[d]+u,m=s[d+1]+u,x=s[d+2]+u;else f=s[d]-n+p()*r,m=s[d+1]-n+p()*r,x=s[d+2]-n+p()*r;f<0&&(f=0),m<0&&(m=0),x<0&&(x=0),f>255&&(f=255),m>255&&(m=255),x>255&&(x=255),s[d]=f,s[d+1]=m,s[d+2]=x}}while(--v)}while(--l);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.posterize={process:function(t){var a=256;if(void 0!==t.options.levels&&(a=parseInt(t.options.levels,10)||1),Pixastic.Client.hasCanvasImageData()){var e=Pixastic.prepareData(t),i=256/(a=Math.max(2,Math.min(256,a))),r=256/(a-1),n=t.options.rect,s=n.width,o=4*s,c=n.height;do{var h=(c-1)*o,l=s;do{var p=h+4*(l-1),g=r*(e[p]/i|0),v=r*(e[p+1]/i|0),d=r*(e[p+2]/i|0);g>255&&(g=255),v>255&&(v=255),d>255&&(d=255),e[p]=g,e[p+1]=v,e[p+2]=d}while(--l)}while(--c);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.pointillize={process:function(t){var a=Math.max(1,parseInt(t.options.radius,10)),e=Math.min(5,Math.max(0,parseFloat(t.options.density)||0)),i=Math.max(0,parseFloat(t.options.noise)||0),r=!(!t.options.transparent||"false"==t.options.transparent);if(Pixastic.Client.hasCanvasImageData()){var n=t.options.rect,s=n.width,o=n.height,c=o,h=t.canvas.getContext("2d"),l=t.canvas.width,p=t.canvas.height,g=document.createElement("canvas");g.width=g.height=1;var v=g.getContext("2d"),d=document.createElement("canvas");d.width=s,d.height=o,d.getContext("2d").drawImage(t.canvas,n.left,n.top,s,o,0,0,s,o);var u=2*a;r&&h.clearRect(n.left,n.top,n.width,n.height);var f=a*i,m=1/e;for(c=0;c<o+a;c+=u*m)for(var x=0;x<s+a;x+=u*m){rndX=i?x+(2*Math.random()-1)*f|0:x,rndY=i?c+(2*Math.random()-1)*f|0:c;var C=rndX-a,w=rndY-a;C<0&&(C=0),w<0&&(w=0);var P=rndX+n.left,I=rndY+n.top;P<0&&(P=0),P>l&&(P=l),I<0&&(I=0),I>p&&(I=p);var D=u,M=u;D+C>s&&(D=s-C),M+w>o&&(M=o-w),D<1&&(D=1),M<1&&(M=1),v.drawImage(d,C,w,D,M,0,0,1,1);var b=v.getImageData(0,0,1,1).data;h.fillStyle="rgb("+b[0]+","+b[1]+","+b[2]+")",h.beginPath(),h.arc(P,I,a,0,2*Math.PI,!0),h.closePath(),h.fill()}return t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.removenoise={process:function(t){if(Pixastic.Client.hasCanvasImageData()){var a=Pixastic.prepareData(t),e=t.options.rect,i=e.width,r=e.height,n=4*i,s=r;do{var o=(s-1)*n,c=(1==s?0:s-2)*i*4,h=(s==r?s-1:s)*i*4,l=i;do{var p,g,v,d,u,f,m=o+(4*l-4),x=c+4*(1==l?0:l-2),C=h+4*(l==i?l-1:l);p=g=a[x];var w=a[m-4],P=a[m+4],I=a[C];w<p&&(p=w),P<p&&(p=P),I<p&&(p=I),w>g&&(g=w),P>g&&(g=P),I>g&&(g=I),v=d=a[x+1];var D=a[m-3],M=a[m+5],b=a[C+1];D<v&&(v=D),M<v&&(v=M),b<v&&(v=b),D>d&&(d=D),M>d&&(d=M),b>d&&(d=b),u=f=a[x+2];var y=a[m-2],_=a[m+6],k=a[C+2];y<u&&(u=y),_<u&&(u=_),k<u&&(u=k),y>f&&(f=y),_>f&&(f=_),k>f&&(f=k),a[m]>g?a[m]=g:a[m]<p&&(a[m]=p),a[m+1]>d?a[m+1]=d:a[m+1]<v&&(a[m+1]=v),a[m+2]>f?a[m+2]=f:a[m+2]<u&&(a[m+2]=u)}while(--l)}while(--s);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.resize={process:function(t){if(Pixastic.Client.hasCanvas()){var a=parseInt(t.options.width,10),e=parseInt(t.options.height,10),i=t.canvas;a<1&&(a=1),a<2&&(a=2);var r=document.createElement("canvas");return r.width=a,r.height=e,r.getContext("2d").drawImage(i,0,0,a,e),i.width=a,i.height=e,i.getContext("2d").drawImage(r,0,0),t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.rotate={process:function(t){if(Pixastic.Client.hasCanvas()){var a=t.canvas,e=t.width,i=t.height,r=document.createElement("canvas");r.width=e,r.height=i,r.getContext("2d").drawImage(a,0,0,e,i);var n=-parseFloat(t.options.angle)*Math.PI/180,s=n;s>.5*Math.PI&&(s=Math.PI-s),s<.5*-Math.PI&&(s=-Math.PI-s);var o=Math.sqrt(e*e+i*i),c=Math.abs(s)-Math.abs(Math.atan2(i,e)),h=Math.abs(s)+Math.abs(Math.atan2(i,e)),l=Math.abs(Math.cos(c)*o),p=Math.abs(Math.sin(h)*o);a.width=l,a.height=p;var g=a.getContext("2d");return g.translate(l/2,p/2),g.rotate(n),g.drawImage(r,-e/2,-i/2),t.useData=!1,!0}},checkSupport:function(){return Pixastic.Client.hasCanvas()}},Pixastic.Actions.sepia={process:function(t){var a=parseInt(t.options.mode,10)||0;if(a<0&&(a=0),a>1&&(a=1),Pixastic.Client.hasCanvasImageData()){var e=Pixastic.prepareData(t),i=t.options.rect,r=i.width,n=4*r,s=i.height;do{var o=(s-1)*n,c=r;do{var h=o+4*(c-1);if(a)var l=.299*e[h]+.587*e[h+1]+.114*e[h+2],p=l+39,g=l+14,v=l-36;else{var d=e[h],u=e[h+1],f=e[h+2];p=.393*d+.769*u+.189*f,g=.349*d+.686*u+.168*f,v=.272*d+.534*u+.131*f}p<0&&(p=0),p>255&&(p=255),g<0&&(g=0),g>255&&(g=255),v<0&&(v=0),v>255&&(v=255),e[h]=p,e[h+1]=g,e[h+2]=v}while(--c)}while(--s);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.sharpen={process:function(t){var a=0;if(void 0!==t.options.amount&&(a=parseFloat(t.options.amount)||0),a<0&&(a=0),a>1&&(a=1),Pixastic.Client.hasCanvasImageData()){for(var e=Pixastic.prepareData(t),i=Pixastic.prepareData(t,!0),r=15,n=1+3*a,s=[[0,-n,0],[-n,r,-n],[0,-n,0]],o=0,c=0;c<3;c++)for(var h=0;h<3;h++)o+=s[c][h];o=1/o;var l=t.options.rect,p=l.width,g=l.height;r*=o,n*=o;var v=4*p,d=g;do{var u=(d-1)*v,f=(1==d?0:d-2)*v,m=(d==g?d-1:d)*v,x=p;do{var C=u+(4*x-4),w=f+4*(1==x?0:x-2),P=m+4*(x==p?x-1:x),I=(-i[w]-i[C-4]-i[C+4]-i[P])*n+i[C]*r,D=(-i[w+1]-i[C-3]-i[C+5]-i[P+1])*n+i[C+1]*r,M=(-i[w+2]-i[C-2]-i[C+6]-i[P+2])*n+i[C+2]*r;I<0&&(I=0),D<0&&(D=0),M<0&&(M=0),I>255&&(I=255),D>255&&(D=255),M>255&&(M=255),e[C]=I,e[C+1]=D,e[C+2]=M}while(--x)}while(--d);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.solarize={process:function(t){!t.options.average||t.options.average;if(Pixastic.Client.hasCanvasImageData()){var a=Pixastic.prepareData(t),e=t.options.rect,i=e.width,r=4*i,n=e.height;do{var s=(n-1)*r,o=i;do{var c=s+4*(o-1),h=a[c],l=a[c+1],p=a[c+2];h>127&&(h=255-h),l>127&&(l=255-l),p>127&&(p=255-p),a[c]=h,a[c+1]=l,a[c+2]=p}while(--o)}while(--n);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}},Pixastic.Actions.unsharpmask={process:function(t){var a=parseFloat(t.options.amount)||0,e=parseFloat(t.options.radius)||0,i=parseFloat(t.options.threshold)||0;a=Math.min(500,Math.max(0,a))/2,e=Math.min(5,Math.max(0,e))/10,i=Math.min(255,Math.max(0,i));var r=- --i;if(a*=.016,a++,Pixastic.Client.hasCanvasImageData()){var n=t.options.rect,s=document.createElement("canvas");s.width=t.width,s.height=t.height;var o=s.getContext("2d");o.drawImage(t.canvas,0,0);var c=Math.round(t.width/2),h=Math.round(t.height/2),l=document.createElement("canvas");l.width=c,l.height=h;for(var p=Math.round(20*e),g=l.getContext("2d"),v=0;v<p;v++){var d=Math.max(1,Math.round(c-v)),u=Math.max(1,Math.round(h-v));g.clearRect(0,0,c,h),g.drawImage(s,0,0,t.width,t.height,0,0,d,u),o.clearRect(0,0,t.width,t.height),o.drawImage(l,0,0,d,u,0,0,t.width,t.height)}var f=Pixastic.prepareData(t),m=Pixastic.prepareData({canvas:s,options:t.options}),x=n.width,C=4*x,w=n.height;do{var P=(w-1)*C,I=x;do{var D=P+(4*I-4),M=f[D]-m[D];if(M>i||M<r){var b=m[D];b=a*M+b,f[D]=b>255?255:b<0?0:b}var y=f[D+1]-m[D+1];if(y>i||y<r){var _=m[D+1];_=a*y+_,f[D+1]=_>255?255:_<0?0:_}var k=f[D+2]-m[D+2];if(k>i||k<r){var A=m[D+2];A=a*k+A,f[D+2]=A>255?255:A<0?0:A}}while(--I)}while(--w);return!0}},checkSupport:function(){return Pixastic.Client.hasCanvasImageData()}};var Base64={toBase64Table:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",base64Pad:"=",encode:function(r){"use strict";var e,t="",a=Base64.toBase64Table.split(""),o=Base64.base64Pad,n=r.length;for(e=0;e<n-2;e+=3)t+=a[r[e]>>2],t+=a[((3&r[e])<<4)+(r[e+1]>>4)],t+=a[((15&r[e+1])<<2)+(r[e+2]>>6)],t+=a[63&r[e+2]];return n%3&&(t+=a[r[e=n-n%3]>>2],n%3==2?(t+=a[((3&r[e])<<4)+(r[e+1]>>4)],t+=a[(15&r[e+1])<<2],t+=o):(t+=a[(3&r[e])<<4],t+=o+o)),t},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:function(r,e){"use strict";e=void 0!==e?e:0;var t,a,o,n,c,h,d=Base64.toBinaryTable,i=Base64.base64Pad,f=0,C=0,s=r.indexOf("=")-e;for(s<0&&(s=r.length-e),a=3*(s>>2)+Math.floor(s%4/1.5),t=new Array(a),o=0,n=e;n<r.length;n++)c=d[127&r.charCodeAt(n)],h=r.charAt(n)===i,-1!==c?(C=C<<6|c,(f+=6)>=8&&(f-=8,h||(t[o++]=C>>f&255),C&=(1<<f)-1)):console.error("Illegal character code "+r.charCodeAt(n)+" at position "+n);if(f)throw{name:"Base64-Error",message:"Corrupted base64 string"};return t},_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encodeStr:function(r){var e,t,a,o,n,c,h,d="",i=0;for(r=Base64._utf8_encode(r);i<r.length;)o=(e=r.charCodeAt(i++))>>2,n=(3&e)<<4|(t=r.charCodeAt(i++))>>4,c=(15&t)<<2|(a=r.charCodeAt(i++))>>6,h=63&a,isNaN(t)?c=h=64:isNaN(a)&&(h=64),d=d+this._keyStr.charAt(o)+this._keyStr.charAt(n)+this._keyStr.charAt(c)+this._keyStr.charAt(h);return d},decodeStr:function(r){var e,t,a,o,n,c,h="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<r.length;)e=this._keyStr.indexOf(r.charAt(d++))<<2|(o=this._keyStr.indexOf(r.charAt(d++)))>>4,t=(15&o)<<4|(n=this._keyStr.indexOf(r.charAt(d++)))>>2,a=(3&n)<<6|(c=this._keyStr.indexOf(r.charAt(d++))),h+=String.fromCharCode(e),64!=n&&(h+=String.fromCharCode(t)),64!=c&&(h+=String.fromCharCode(a));return h=Base64._utf8_decode(h)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var e="",t=0;t<r.length;t++){var a=r.charCodeAt(t);a<128?e+=String.fromCharCode(a):a>127&&a<2048?(e+=String.fromCharCode(a>>6|192),e+=String.fromCharCode(63&a|128)):(e+=String.fromCharCode(a>>12|224),e+=String.fromCharCode(a>>6&63|128),e+=String.fromCharCode(63&a|128))}return e},_utf8_decode:function(r){for(var e="",t=0,a=c1=c2=0;t<r.length;)(a=r.charCodeAt(t))<128?(e+=String.fromCharCode(a),t++):a>191&&a<224?(c2=r.charCodeAt(t+1),e+=String.fromCharCode((31&a)<<6|63&c2),t+=2):(c2=r.charCodeAt(t+1),c3=r.charCodeAt(t+2),e+=String.fromCharCode((15&a)<<12|(63&c2)<<6|63&c3),t+=3);return e}};function BigInteger(e,t){if(!(this instanceof BigInteger))return e instanceof BigInteger?e:void 0===e?BigInteger.ZERO:BigInteger.parse(e);for(e=e||[];e.length&&!e[e.length-1];)--e.length;this._d=e,this._s=e.length?t||1:0}Array.prototype.map||(Array.prototype.map=function(e){var t=this.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=new Array(t),n=arguments[1],i=0;i<t;i++)i in this&&(r[i]=e.call(n,this[i],i,this));return r}),BigInteger.base=1e7,BigInteger.base_log10=7,BigInteger.init=function(){BigInteger.ZERO=new BigInteger([],0),BigInteger.ONE=new BigInteger([1],1),BigInteger.M_ONE=new BigInteger(BigInteger.ONE._d,-1),BigInteger._0=BigInteger.ZERO,BigInteger._1=BigInteger.ONE,BigInteger.small=[BigInteger.ZERO,BigInteger.ONE,new BigInteger([2],1),new BigInteger([3],1),new BigInteger([4],1),new BigInteger([5],1),new BigInteger([6],1),new BigInteger([7],1),new BigInteger([8],1),new BigInteger([9],1),new BigInteger([10],1),new BigInteger([11],1),new BigInteger([12],1),new BigInteger([13],1),new BigInteger([14],1),new BigInteger([15],1),new BigInteger([16],1),new BigInteger([17],1),new BigInteger([18],1),new BigInteger([19],1),new BigInteger([20],1),new BigInteger([21],1),new BigInteger([22],1),new BigInteger([23],1),new BigInteger([24],1),new BigInteger([25],1),new BigInteger([26],1),new BigInteger([27],1),new BigInteger([28],1),new BigInteger([29],1),new BigInteger([30],1),new BigInteger([31],1),new BigInteger([32],1),new BigInteger([33],1),new BigInteger([34],1),new BigInteger([35],1),new BigInteger([36],1)]},BigInteger.init(),BigInteger.digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),BigInteger.prototype.toString=function(e){if((e=+e||10)<2||e>36)throw new Error("illegal radix "+e+".");if(0===this._s)return"0";if(10===e){var t=this._s<0?"-":"";t+=this._d[this._d.length-1].toString();for(var r=this._d.length-2;r>=0;r--){for(var n=this._d[r].toString();n.length<BigInteger.base_log10;)n="0"+n;t+=n}return t}var i=BigInteger.digits;e=BigInteger.small[e];for(var g,s=this._s,o=this.abs(),a=[];0!==o._s;){var I=o.divRem(e);o=I[0],g=I[1],a.push(i[g.valueOf()])}return(s<0?"-":"")+a.reverse().join("")},BigInteger.radixRegex=[/^$/,/^$/,/^[01]*$/,/^[012]*$/,/^[0-3]*$/,/^[0-4]*$/,/^[0-5]*$/,/^[0-6]*$/,/^[0-7]*$/,/^[0-8]*$/,/^[0-9]*$/,/^[0-9aA]*$/,/^[0-9abAB]*$/,/^[0-9abcABC]*$/,/^[0-9a-dA-D]*$/,/^[0-9a-eA-E]*$/,/^[0-9a-fA-F]*$/,/^[0-9a-gA-G]*$/,/^[0-9a-hA-H]*$/,/^[0-9a-iA-I]*$/,/^[0-9a-jA-J]*$/,/^[0-9a-kA-K]*$/,/^[0-9a-lA-L]*$/,/^[0-9a-mA-M]*$/,/^[0-9a-nA-N]*$/,/^[0-9a-oA-O]*$/,/^[0-9a-pA-P]*$/,/^[0-9a-qA-Q]*$/,/^[0-9a-rA-R]*$/,/^[0-9a-sA-S]*$/,/^[0-9a-tA-T]*$/,/^[0-9a-uA-U]*$/,/^[0-9a-vA-V]*$/,/^[0-9a-wA-W]*$/,/^[0-9a-xA-X]*$/,/^[0-9a-yA-Y]*$/,/^[0-9a-zA-Z]*$/],BigInteger.parse=function(e,t){e=e.toString(),void 0!==t&&10!=+t||(e=e.replace(/\s*[*xX]\s*10\s*(\^|\*\*)\s*/,"e").replace(/^([+\-])?(\d+)\.?(\d*)[eE]([+\-]?\d+)$/,(function(e,t,r,n,i){var g=(i=+i)<0,s=r.length+i;e=(g?r:n).length,i=(i=Math.abs(i))>=e?i-e+g:0;var o=new Array(i+1).join("0"),a=r+n;return(t||"")+(g?a=o+a:a+=o).substr(0,s+=g?o.length:0)+(s<a.length?"."+a.substr(s):"")})));var r=/^([+\-]?)(0[xXcCbB])?([0-9A-Za-z]*)(?:\.\d*)?$/.exec(e);if(r){var n=r[1]||"+",i=r[2]||"",g=r[3]||"";if(void 0===t)t="0x"===i||"0X"===i?16:"0c"===i||"0C"===i?8:"0b"===i||"0B"===i?2:10;else if(t<2||t>36)throw new Error("Illegal radix "+t+".");if(t=+t,!BigInteger.radixRegex[t].test(g))throw new Error("Bad digit for radix "+t);if(0===(g=g.replace(/^0+/,"").split("")).length)return BigInteger.ZERO;if(n="-"===n?-1:1,10==t){for(var s=[];g.length>=BigInteger.base_log10;)s.push(parseInt(g.splice(-BigInteger.base_log10).join(""),10));return s.push(parseInt(g.join(""),10)),new BigInteger(s,n)}if(t===BigInteger.base)return new BigInteger(g.map(Number).reverse(),n);s=BigInteger.ZERO;t=BigInteger.small[t];for(var o=BigInteger.small,a=0;a<g.length;a++)s=s.multiply(t).add(o[parseInt(g[a],36)]);return new BigInteger(s._d,n)}throw new Error("Invalid BigInteger format: "+e)},BigInteger.prototype.add=function(e){if(0===this._s)return BigInteger(e);if(0===(e=BigInteger(e))._s)return this;if(this._s!==e._s)return e=e.negate(),this.subtract(e);for(var t,r=this._d,n=e._d,i=r.length,g=n.length,s=new Array(Math.max(i,g)+1),o=Math.min(i,g),a=0,I=0;I<o;I++)t=r[I]+n[I]+a,s[I]=t%BigInteger.base,a=t/BigInteger.base|0;for(g>i&&(r=n,i=g),I=o;a&&I<i;I++)t=r[I]+a,s[I]=t%BigInteger.base,a=t/BigInteger.base|0;for(a&&(s[I]=a);I<i;I++)s[I]=r[I];return new BigInteger(s,this._s)},BigInteger.prototype.negate=function(){return new BigInteger(this._d,-this._s)},BigInteger.prototype.abs=function(){return this._s<0?this.negate():this},BigInteger.prototype.subtract=function(e){if(0===this._s)return BigInteger(e).negate();if(0===(e=BigInteger(e))._s)return this;if(this._s!==e._s)return e=e.negate(),this.add(e);var t,r=this;this._s<0&&(t=r,r=new BigInteger(e._d,1),e=new BigInteger(t._d,1));var n=r.compareAbs(e);if(0===n)return BigInteger.ZERO;n<0&&(t=e,e=r,r=t);var i,g,s=r._d,o=e._d,a=s.length,I=o.length,B=new Array(a),h=0;for(i=0;i<I;i++)(g=s[i]-h-o[i])<0?(g+=BigInteger.base,h=1):h=0,B[i]=g;for(i=I;i<a;i++){if(!((g=s[i]-h)<0)){B[i++]=g;break}g+=BigInteger.base,B[i]=g}for(;i<a;i++)B[i]=s[i];return new BigInteger(B,n)},function(){function e(e,t){for(var r=e._d,n=r.slice(),i=0;;){var g=(r[i]||0)+1;if(n[i]=g%BigInteger.base,g<=BigInteger.base-1)break;++i}return new BigInteger(n,t)}function t(e,t){for(var r=e._d,n=r.slice(),i=0;;){var g=(r[i]||0)-1;if(!(g<0)){n[i]=g;break}n[i]=g+BigInteger.base,++i}return new BigInteger(n,t)}BigInteger.prototype.next=function(){switch(this._s){case 0:return BigInteger.ONE;case-1:return t(this,-1);default:return e(this,1)}},BigInteger.prototype.prev=function(){switch(this._s){case 0:return BigInteger.M_ONE;case-1:return e(this,-1);default:return t(this,1)}}}(),BigInteger.prototype.compareAbs=function(e){if(this===e)return 0;if(!(e instanceof BigInteger)){if(!isFinite(e))return isNaN(e)?e:-1;e=BigInteger(e)}if(0===this._s)return 0!==e._s?-1:0;if(0===e._s)return 1;var t=this._d.length,r=e._d.length;if(t<r)return-1;if(t>r)return 1;for(var n=this._d,i=e._d,g=t-1;g>=0;g--)if(n[g]!==i[g])return n[g]<i[g]?-1:1;return 0},BigInteger.prototype.compare=function(e){return this===e?0:(e=BigInteger(e),0===this._s?-e._s:this._s===e._s?this.compareAbs(e)*this._s:this._s)},BigInteger.prototype.isUnit=function(){return this===BigInteger.ONE||this===BigInteger.M_ONE||1===this._d.length&&1===this._d[0]},BigInteger.prototype.multiply=function(e){if(0===this._s)return BigInteger.ZERO;if(0===(e=BigInteger(e))._s)return BigInteger.ZERO;if(this.isUnit())return this._s<0?e.negate():e;if(e.isUnit())return e._s<0?this.negate():this;if(this===e)return this.square();var t,r=this._d.length>=e._d.length,n=(r?this:e)._d,i=(r?e:this)._d,g=n.length,s=i.length,o=g+s,a=new Array(o);for(t=0;t<o;t++)a[t]=0;for(t=0;t<s;t++){for(var I,B=0,h=i[t],u=g+t,f=t;f<u;f++)B=(I=a[f]+h*n[f-t]+B)/BigInteger.base|0,a[f]=I%BigInteger.base|0;B&&(B=(I=a[f]+B)/BigInteger.base|0,a[f]=I%BigInteger.base)}return new BigInteger(a,this._s*e._s)},BigInteger.prototype.multiplySingleDigit=function(e){if(0===e||0===this._s)return BigInteger.ZERO;if(1===e)return this;var t;if(1===this._d.length)return(t=this._d[0]*e)>=BigInteger.base?new BigInteger([t%BigInteger.base|0,t/BigInteger.base|0],1):new BigInteger([t],1);if(2===e)return this.add(this);if(this.isUnit())return new BigInteger([e],1);for(var r=this._d,n=r.length,i=n+1,g=new Array(i),s=0;s<i;s++)g[s]=0;for(var o=0,a=0;a<n;a++)o=(t=e*r[a]+o)/BigInteger.base|0,g[a]=t%BigInteger.base|0;return o&&(o=(t=o)/BigInteger.base|0,g[a]=t%BigInteger.base),new BigInteger(g,1)},BigInteger.prototype.square=function(){if(0===this._s)return BigInteger.ZERO;if(this.isUnit())return BigInteger.ONE;var e,t,r,n,i=this._d,g=i.length,s=new Array(g+g+1);for(n=0;n<g;n++)r=2*n,t=(e=i[n]*i[n])/BigInteger.base|0,s[r]=e%BigInteger.base,s[r+1]=t;for(n=0;n<g;n++){t=0,r=2*n+1;for(var o=n+1;o<g;o++,r++)t=(e=i[o]*i[n]*2+s[r]+t)/BigInteger.base|0,s[r]=e%BigInteger.base;var a=t+s[r=g+n];t=a/BigInteger.base|0,s[r]=a%BigInteger.base,s[r+1]+=t}return new BigInteger(s,1)},BigInteger.prototype.quotient=function(e){return this.divRem(e)[0]},BigInteger.prototype.divide=BigInteger.prototype.quotient,BigInteger.prototype.remainder=function(e){return this.divRem(e)[1]},BigInteger.prototype.divRem=function(e){if(0===(e=BigInteger(e))._s)throw new Error("Divide by zero");if(0===this._s)return[BigInteger.ZERO,BigInteger.ZERO];if(1===e._d.length)return this.divRemSmall(e._s*e._d[0]);switch(this.compareAbs(e)){case 0:return[this._s===e._s?BigInteger.ONE:BigInteger.M_ONE,BigInteger.ZERO];case-1:return[BigInteger.ZERO,this]}var t,r=this._s*e._s,n=e.abs(),i=this._d.slice(),g=(e._d.length,i.length,[]),s=new BigInteger([],1);for(s._s=1;i.length;)if(s._d.unshift(i.pop()),(s=new BigInteger(s._d,1)).compareAbs(e)<0)g.push(0);else{if(0===s._s)t=0;else{var o=s._d.length,a=n._d.length,I=s._d[o-1]*BigInteger.base+s._d[o-2],B=n._d[a-1]*BigInteger.base+n._d[a-2];s._d.length>n._d.length&&(I=(I+1)*BigInteger.base),t=Math.ceil(I/B)}do{var h=n.multiplySingleDigit(t);if(h.compareAbs(s)<=0)break;t--}while(t);if(g.push(t),t){var u=s.subtract(h);s._d=u._d.slice()}}return[new BigInteger(g.reverse(),r),new BigInteger(s._d,this._s)]},BigInteger.prototype.divRemSmall=function(e){var t;if(0===(e=+e))throw new Error("Divide by zero");var r=e<0?-1:1,n=this._s*r;if((e=Math.abs(e))<1||e>=BigInteger.base)throw new Error("Argument out of range");if(0===this._s)return[BigInteger.ZERO,BigInteger.ZERO];if(1===e||-1===e)return[1===n?this.abs():new BigInteger(this._d,n),BigInteger.ZERO];if(1===this._d.length){var i=new BigInteger([this._d[0]/e|0],1);return t=new BigInteger([this._d[0]%e|0],1),n<0&&(i=i.negate()),this._s<0&&(t=t.negate()),[i,t]}for(var g,s=this._d.slice(),o=new Array(s.length),a=0,I=0,B=0;s.length;){if((a=a*BigInteger.base+s[s.length-1])<e)o[B++]=0,s.pop(),I=BigInteger.base*I+a;else I=a-e*(g=0===a?0:a/e|0),o[B++]=g,g?(s.pop(),a=I):s.pop()}return t=new BigInteger([I],1),this._s<0&&(t=t.negate()),[new BigInteger(o.reverse(),n),t]},BigInteger.prototype.isEven=function(){var e=this._d;return 0===this._s||0===e.length||e[0]%2==0},BigInteger.prototype.isOdd=function(){return!this.isEven()},BigInteger.prototype.sign=function(){return this._s},BigInteger.prototype.isPositive=function(){return this._s>0},BigInteger.prototype.isNegative=function(){return this._s<0},BigInteger.prototype.isZero=function(){return 0===this._s},BigInteger.prototype.exp10=function(e){if(0===(e=+e))return this;if(Math.abs(e)>Number(BigInteger.MAX_EXP))throw new Error("exponent too large in BigInteger.exp10");if(e>0){for(var t=new BigInteger(this._d.slice(),this._s);e>=BigInteger.base_log10;e-=BigInteger.base_log10)t._d.unshift(0);return 0==e?t:(t._s=1,t=t.multiplySingleDigit(Math.pow(10,e)),this._s<0?t.negate():t)}if(-e>=this._d.length*BigInteger.base_log10)return BigInteger.ZERO;t=new BigInteger(this._d.slice(),this._s);for(e=-e;e>=BigInteger.base_log10;e-=BigInteger.base_log10)t._d.shift();return 0==e?t:t.divRemSmall(Math.pow(10,e))[0]},BigInteger.prototype.pow=function(e){if(this.isUnit())return this._s>0||BigInteger(e).isOdd()?this:this.negate();if(0===(e=BigInteger(e))._s)return BigInteger.ONE;if(e._s<0){if(0===this._s)throw new Error("Divide by zero");return BigInteger.ZERO}if(0===this._s)return BigInteger.ZERO;if(e.isUnit())return this;if(e.compareAbs(BigInteger.MAX_EXP)>0)throw new Error("exponent too large in BigInteger.pow");for(var t=this,r=BigInteger.ONE,n=BigInteger.small[2];e.isPositive();){if(e.isOdd()&&(r=r.multiply(t),e.isUnit()))return r;t=t.square(),e=e.quotient(n)}return r},BigInteger.prototype.modPow=function(e,t){for(var r=BigInteger.ONE,n=this;e.isPositive();)e.isOdd()&&(r=r.multiply(n).remainder(t)),(e=e.quotient(BigInteger.small[2])).isPositive()&&(n=n.square().remainder(t));return r},BigInteger.prototype.log=function(){switch(this._s){case 0:return-1/0;case-1:return NaN}var e=this._d.length;if(e*BigInteger.base_log10<30)return Math.log(this.valueOf());var t=Math.ceil(30/BigInteger.base_log10),r=this._d.slice(e-t);return Math.log(new BigInteger(r,1).valueOf())+(e-t)*Math.log(BigInteger.base)},BigInteger.prototype.valueOf=function(){return parseInt(this.toString(),10)},BigInteger.prototype.toJSValue=function(){return parseInt(this.toString(),10)},BigInteger.MAX_EXP=BigInteger(2147483647),function(){function e(e){return function(t){return e.call(BigInteger(t))}}function t(e){return function(t,r){return e.call(BigInteger(t),BigInteger(r))}}function r(e){return function(t,r,n){return e.call(BigInteger(t),BigInteger(r),BigInteger(n))}}!function(){var n,i,g="toJSValue,isEven,isOdd,sign,isZero,isNegative,abs,isUnit,square,negate,isPositive,toString,next,prev,log".split(","),s="compare,remainder,divRem,subtract,add,quotient,divide,multiply,pow,compareAbs".split(","),o=["modPow"];for(n=0;n<g.length;n++)BigInteger[i=g[n]]=e(BigInteger.prototype[i]);for(n=0;n<s.length;n++)BigInteger[i=s[n]]=t(BigInteger.prototype[i]);for(n=0;n<o.length;n++)BigInteger[i=o[n]]=r(BigInteger.prototype[i]);BigInteger.exp10=function(e,t){return BigInteger(e).exp10(t)}}()}(),"undefined"!=typeof exports&&(exports.BigInteger=BigInteger);var VirtualJoystick=function(t){t=t||{},this._container=t.container||document.body,this._stickEl=t.stickElement||this._buildJoystickStick(),this._baseEl=t.baseElement||this._buildJoystickBase(),this._mouseLeft=t.mouseLeft||this._buildJoystickButton(),this._mouseSupport="mouseSupport"in t&&t.mouseSupport,this._range=t.range||60,this._timer=null,this._callback="callback"in t&&t.callback,this._callbackcontext="callbackcontext"in t?t.callbackcontext:this,this._callbackButton="callbackbutton"in t&&t.callbackbutton,this._referenceItem=t.referenceItem,this._container.style.position="relative",this._container.appendChild(this._baseEl),this._container.appendChild(this._mouseLeft),this._baseEl.style.position="absolute",this._baseEl.style.display="block",this._mouseLeft.style.position="absolute",this._mouseLeft.style.display="block";var e=$(this._referenceItem),s=e.height()-e.offset().top-130;this._baseEl.style.top=s+"px",this._baseEl.style.left="20px",this._container.appendChild(this._stickEl),this._stickEl.style.position="absolute",this._stickEl.style.display="none",this._mouseLeft.style.top=s+20+"px",this._mouseLeft.style.right="20px",this._pressed=!1,this._baseX=0,this._baseY=0,this._stickX=0,this._stickY=0,__bind=function(t,e){return function(){return t.apply(e,arguments)}},this._$onTouchStart=__bind(this._onTouchStart,this),this._$onTouchEnd=__bind(this._onTouchEnd,this),this._$onTouchMove=__bind(this._onTouchMove,this),this._$onTouchStartButton=__bind(this._onTouchStartButton,this),this._$onTouchEndButton=__bind(this._onTouchEndButton,this),this._baseEl.addEventListener("touchstart",this._$onTouchStart,!1),this._mouseLeft.addEventListener("touchstart",this._$onTouchStartButton,!1),this._mouseLeft.addEventListener("touchend",this._$onTouchEndButton,!1),this._container.addEventListener("touchend",this._$onTouchEnd,!1),this._container.addEventListener("touchmove",this._$onTouchMove,!1),this._mouseSupport&&(this._$onMouseDown=__bind(this._onMouseDown,this),this._$onMouseUp=__bind(this._onMouseUp,this),this._$onMouseMove=__bind(this._onMouseMove,this),this._$onMouseDownButton=__bind(this._onMouseDownButton,this),this._$onMouseUpButton=__bind(this._onMouseUpButton,this),this._baseEl.addEventListener("mousedown",this._$onMouseDown,!1),this._container.addEventListener("mouseup",this._$onMouseUp,!1),this._mouseLeft.addEventListener("mousedown",this._$onTouchStartButton,!1),this._mouseLeft.addEventListener("mouseup",this._$onTouchEndButton,!1),this._container.addEventListener("mousemove",this._$onMouseMove,!1))};VirtualJoystick.prototype.destroy=function(){this._container.removeChild(this._baseEl),this._container.removeChild(this._stickEl),this._mouseLeft.removeEventListener("touchstart",this._$onTouchStartButton,!1),this._mouseLeft.removeEventListener("touchend",this._$onTouchEndButton,!1),this._container.removeChild(this._mouseLeft),this._container.removeEventListener("touchstart",this._$onTouchStart,!1),this._container.removeEventListener("touchend",this._$onTouchEnd,!1),this._container.removeEventListener("touchmove",this._$onTouchMove,!1),this._mouseSupport&&(this._container.removeEventListener("mouseup",this._$onMouseUp,!1),this._container.removeEventListener("mousedown",this._$onMouseDown,!1),this._container.removeEventListener("mousemove",this._$onMouseMove,!1))},VirtualJoystick.touchScreenAvailable=function(){return"createTouch"in document},VirtualJoystick.prototype.deltaX=function(){return this._stickX-this._baseX},VirtualJoystick.prototype.deltaY=function(){return this._stickY-this._baseY},VirtualJoystick.prototype.up=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(e>=0)&&!(Math.abs(e)<this._range&&Math.abs(e)<Math.abs(t))},VirtualJoystick.prototype.down=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(e<=0)&&!(Math.abs(e)<this._range&&Math.abs(e)<Math.abs(t))},VirtualJoystick.prototype.right=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(t<=0)&&!(Math.abs(t)<this._range&&Math.abs(e)>Math.abs(t))},VirtualJoystick.prototype.left=function(){if(!1===this._pressed)return!1;var t=this.deltaX(),e=this.deltaY();return!(t>=0)&&!(Math.abs(t)<this._range&&Math.abs(e)>Math.abs(t))},VirtualJoystick.prototype._onUp=function(){this._pressed=!1,this._stickEl.style.display="none",this._baseX=this._baseY=0,this._stickX=this._stickY=0,this._eraseInterval()},VirtualJoystick.prototype._onDown=function(t,e){this._pressed=!0,this._stickX=t,this._stickY=e,this._stickEl.style.display="",this._stickEl.style.left=this._stickX-this._stickEl.width/2+"px",this._stickEl.style.top=this._stickY-this._stickEl.height/2+"px",this._startInterval()},VirtualJoystick.prototype._onMove=function(t,e){!0===this._pressed&&(this._stickX=t,this._stickY=e,this._stickEl.style.left=t-this._stickEl.width/2+"px",this._stickEl.style.top=e-this._stickEl.height/2+"px",this._startInterval())},VirtualJoystick.prototype._startInterval=function(t,e){this._eraseInterval();var s=$(this._baseEl).offset().left+$(this._baseEl).width()/2,i=$(this._stickEl).offset().left+$(this._stickEl).width()/2;this.offsetX=parseInt((i-s)/5);var o=$(this._baseEl).offset().top+$(this._baseEl).height()/2,n=$(this._stickEl).offset().top+$(this._stickEl).height()/2;this.offsetY=parseInt((n-o)/5),this.offsetX>15&&(this.offsetX=15),this.offsetY>15&&(this.offsetY=15);var h=this;this._timer=setInterval((function(){h._callback&&h._callback.call(h._callbackcontext,[h.offsetX,h.offsetY])}),10)},VirtualJoystick.prototype._eraseInterval=function(){this._timer&&(clearTimeout(this._timer),this._timer=null)},VirtualJoystick.prototype._onMouseUp=function(t){return this._onUp()},VirtualJoystick.prototype._onMouseDown=function(t){var e=t.pageX,s=t.pageY;return this._onDown(e,s)},VirtualJoystick.prototype._onMouseMove=function(t){var e=t.pageX,s=t.pageY;return this._onMove(e,s)},VirtualJoystick.prototype._onTouchStart=function(t){if(1==t.touches.length){t.preventDefault();var e=t.touches[0].pageX,s=t.touches[0].pageY;return this._onDown(e,s)}},VirtualJoystick.prototype._onTouchEnd=function(t){return t.preventDefault(),this._onUp()},VirtualJoystick.prototype._onTouchMove=function(t){if(!t.touches||1==t.touches.length){t.preventDefault();var e=t.touches[0].pageX,s=t.touches[0].pageY;return this._onMove(e,s)}},VirtualJoystick.prototype._onTouchStartButton=function(t){t.touches&&1!=t.touches.length||(t.preventDefault(),this._callbackButton.call(this._callbackcontext,["down"]))},VirtualJoystick.prototype._onTouchEndButton=function(t){t.preventDefault(),this._callbackButton.call(this._callbackcontext,["up"])},VirtualJoystick.prototype._buildJoystickBase=function(){var t=document.createElement("canvas");t.style.zIndex=2,t.width=126,t.height=126;var e=t.getContext("2d");return e.beginPath(),e.strokeStyle="cyan",e.lineWidth=6,e.arc(t.width/2,t.width/2,40,0,2*Math.PI,!0),e.stroke(),e.beginPath(),e.strokeStyle="cyan",e.lineWidth=2,e.arc(t.width/2,t.width/2,60,0,2*Math.PI,!0),e.stroke(),t},VirtualJoystick.prototype._buildJoystickStick=function(){var t=document.createElement("canvas");t.style.zIndex=2,t.width=86,t.height=86;var e=t.getContext("2d");return e.beginPath(),e.strokeStyle="cyan",e.lineWidth=6,e.arc(t.width/2,t.width/2,40,0,2*Math.PI,!0),e.stroke(),t},VirtualJoystick.prototype._buildJoystickButton=function(){var t=document.createElement("canvas");t.style.zIndex=2,t.width=86,t.height=86;var e=t.getContext("2d");return e.beginPath(),e.strokeStyle="green",e.lineWidth=6,e.arc(t.width/2,t.width/2,40,0,2*Math.PI,!0),e.stroke(),t};var prettyPrint=function(){var e={el:function(t,n){var o,r=document.createElement(t);if((n=e.merge({},n))&&n.style){n.style;e.applyCSS(r,n.style),delete n.style}for(o in n)n.hasOwnProperty(o)&&(r[o]=n[o]);return r},applyCSS:function(e,t){for(var n in t)if(t.hasOwnProperty(n))try{e.style[n]=t[n]}catch(e){}},txt:function(e){return document.createTextNode(e)},row:function(t,n,o){o=o||"td";var r,a=e.count(t,null)+1,d=e.el("tr"),i={style:e.getStyles(o,n),colSpan:a,onmouseover:function(){var t=this.parentNode.childNodes;e.forEach(t,(function(t){"td"===t.nodeName.toLowerCase()&&e.applyCSS(t,e.getStyles("td_hover",n))}))},onmouseout:function(){var t=this.parentNode.childNodes;e.forEach(t,(function(t){"td"===t.nodeName.toLowerCase()&&e.applyCSS(t,e.getStyles("td",n))}))}};return e.forEach(t,(function(t){null!==t&&(r=e.el(o,i),t.nodeType?r.appendChild(t):r.innerHTML=e.shorten(t.toString()),d.appendChild(r))})),d},hRow:function(t,n){return e.row(t,n,"th")},table:function(t,n){t=t||[];var o={thead:{style:e.getStyles("thead",n)},tbody:{style:e.getStyles("tbody",n)},table:{style:e.getStyles("table",n)}},r=e.el("table",o.table),a=e.el("thead",o.thead),d=e.el("tbody",o.tbody);return t.length&&(r.appendChild(a),a.appendChild(e.hRow(t,n))),r.appendChild(d),{node:r,tbody:d,thead:a,appendChild:function(e){this.tbody.appendChild(e)},addRow:function(t,o,r){return this.appendChild(e.row.call(e,t,o||n,r)),this}}},shorten:function(e){return(e=e.replace(/^\s\s*|\s\s*$|\n/g,"")).length>40?e.substring(0,39)+"...":e},htmlentities:function(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},merge:function(t,n){for(var o in"object"!=typeof t&&(t={}),n)if(n.hasOwnProperty(o)){var r=n[o];if("object"==typeof r){t[o]=e.merge(t[o],r);continue}t[o]=r}for(var a=2,d=arguments.length;a<d;a++)e.merge(t,arguments[a]);return t},count:function(e,t){for(var n=0,o=0,r=e.length;o<r;o++)e[o]===t&&n++;return n},thead:function(e){return e.getElementsByTagName("thead")[0]},forEach:function(e,t,n){n||(n=t);for(var o=e.length,r=-1;++r<o&&!1!==n(e[r],r,e););return!0},type:function(e){try{if(null===e)return"null";if(void 0===e)return"undefined";var t=Object.prototype.toString.call(e).match(/\s(.+?)\]/)[1].toLowerCase();return e.nodeType?1===e.nodeType?"domelement":"domnode":/^(string|number|array|regexp|function|date|boolean)$/.test(t)?t:"object"==typeof e?e.jquery&&"string"==typeof e.jquery?"jquery":"object":e===window||e===document?"object":"default"}catch(e){return"default"}},within:function(e){return{is:function(t){for(var n in e)if(e[n]===t)return n;return""}}},common:{circRef:function(n,o,r){return e.expander("[POINTS BACK TO <strong>"+o+"</strong>]","Click to show this item anyway",(function(){this.parentNode.appendChild(t(n,{maxDepth:1}))}))},depthReached:function(n,o){return e.expander("[DEPTH REACHED]","Click to show this item anyway",(function(){try{this.parentNode.appendChild(t(n,{maxDepth:1}))}catch(t){this.parentNode.appendChild(e.table(["ERROR OCCURED DURING OBJECT RETRIEVAL"],"error").addRow([t.message]).node)}}))}},getStyles:function(n,o){return o=t.settings.styles[o]||{},e.merge({},t.settings.styles.default[n],o[n])},expander:function(t,n,o){return e.el("a",{innerHTML:e.shorten(t)+' <b style="visibility:hidden;">[+]</b>',title:n,onmouseover:function(){this.getElementsByTagName("b")[0].style.visibility="visible"},onmouseout:function(){this.getElementsByTagName("b")[0].style.visibility="hidden"},onclick:function(){return this.style.display="none",o.call(this),!1},style:{cursor:"pointer"}})},stringify:function(t){var n,o=e.type(t),r=!0;if("array"===o)return n="[",e.forEach(t,(function(t,o){n+=(0===o?"":", ")+e.stringify(t)})),n+"]";if("object"==typeof t){for(var a in n="{",t)t.hasOwnProperty(a)&&(n+=(r?"":", ")+a+":"+e.stringify(t[a]),r=!1);return n+"}"}return"regexp"===o?"/"+t.source+"/":"string"===o?'"'+t.replace(/"/g,'\\"')+'"':t.toString()},headerGradient:function(){var e=document.createElement("canvas");if(!e.getContext)return"";var t=e.getContext("2d");e.height=30,e.width=1;var n=t.createLinearGradient(0,0,0,30);return n.addColorStop(0,"rgba(0,0,0,0)"),n.addColorStop(1,"rgba(0,0,0,0.25)"),t.fillStyle=n,t.fillRect(0,0,1,30),"url("+(e.toDataURL&&e.toDataURL()||"")+")"}()},t=function(n,o){o=o||{};var r=e.merge({},t.config,o),a=e.el("div"),d=(t.config,{}),i=!1;t.settings=r;var l={string:function(t){return e.txt('"'+e.shorten(t.replace(/"/g,'\\"'))+'"')},number:function(t){return e.txt(t)},regexp:function(t){var n=e.table(["RegExp",null],"regexp"),o=e.table(),a=e.expander("/"+t.source+"/","Click to show more",(function(){this.parentNode.appendChild(n.node)}));return o.addRow(["g",t.global]).addRow(["i",t.ignoreCase]).addRow(["m",t.multiline]),n.addRow(["source","/"+t.source+"/"]).addRow(["flags",o.node]).addRow(["lastIndex",t.lastIndex]),r.expanded?n.node:a},domelement:function(t,n){var o=e.table(["DOMElement",null],"domelement"),a=t.nodeName||"";return o.addRow(["tag","&lt;"+a.toLowerCase()+"&gt;"]),e.forEach(["id","className","innerHTML","src","href"],(function(n){t[n]&&o.addRow([n,e.htmlentities(t[n])])})),r.expanded?o.node:e.expander("DOMElement ("+a.toLowerCase()+")","Click to show more",(function(){this.parentNode.appendChild(o.node)}))},domnode:function(t){var n=e.table(["DOMNode",null],"domelement"),o=e.htmlentities((t.data||"UNDEFINED").replace(/\n/g,"\\n"));return n.addRow(["nodeType",t.nodeType+" ("+t.nodeName+")"]).addRow(["data",o]),r.expanded?n.node:e.expander("DOMNode","Click to show more",(function(){this.parentNode.appendChild(n.node)}))},jquery:function(e,t,n){return l.array(e,t,n,!0)},object:function(t,n,o){var a=e.within(d).is(t);if(a)return e.common.circRef(t,a,r);if(d[o||"TOP"]=t,n===r.maxDepth)return e.common.depthReached(t,r);var c=e.table(["Object",null],"object"),u=!0;for(var s in t)if(!t.hasOwnProperty||t.hasOwnProperty(s)){var p=t[s],h=e.type(p);u=!1;try{c.addRow([s,l[h](p,n+1,s)],h)}catch(e){window.console&&window.console.log&&console.log(e.message)}}u?c.addRow(["<small>[empty]</small>"]):c.thead.appendChild(e.hRow(["key","value"],"colHeader"));var f=r.expanded||i?c.node:e.expander(e.stringify(t),"Click to show more",(function(){this.parentNode.appendChild(c.node)}));return i=!0,f},array:function(t,n,o,a){var i=e.within(d).is(t);if(i)return e.common.circRef(t,i);if(d[o||"TOP"]=t,n===r.maxDepth)return e.common.depthReached(t);var c=a?"jQuery":"Array",u=e.table([c+"("+t.length+")",null],a?"jquery":c.toLowerCase()),s=!0,p=0;return a&&u.addRow(["selector",t.selector]),e.forEach(t,(function(o,a){if(r.maxArray>=0&&++p>r.maxArray)return u.addRow([a+".."+(t.length-1),l[e.type(o)]("...",n+1,a)]),!1;s=!1,u.addRow([a,l[e.type(o)](o,n+1,a)])})),a||(s?u.addRow(["<small>[empty]</small>"]):u.thead.appendChild(e.hRow(["index","value"],"colHeader"))),r.expanded?u.node:e.expander(e.stringify(t),"Click to show more",(function(){this.parentNode.appendChild(u.node)}))},function:function(t,n,o){var a=e.within(d).is(t);if(a)return e.common.circRef(t,a);d[o||"TOP"]=t;var i=e.table(["Function",null],"function"),l=(e.table(["Arguments"]),t.toString().match(/\((.+?)\)/)),c=t.toString().match(/\(.*?\)\s+?\{?([\S\s]+)/)[1].replace(/\}?$/,"");return i.addRow(["arguments",l?l[1].replace(/[^\w_,\s]/g,""):"<small>[none/native]</small>"]).addRow(["body",c]),r.expanded?i.node:e.expander("function(){...}","Click to see more about this function.",(function(){this.parentNode.appendChild(i.node)}))},date:function(t){var n=e.table(["Date",null],"date"),o=t.toString().split(/\s/);return n.addRow(["Time",o[4]]).addRow(["Date",o.slice(0,4).join("-")]),r.expanded?n.node:e.expander("Date (timestamp): "+ +t,"Click to see a little more info about this date",(function(){this.parentNode.appendChild(n.node)}))},boolean:function(t){return e.txt(t.toString().toUpperCase())},undefined:function(){return e.txt("UNDEFINED")},null:function(){return e.txt("NULL")},default:function(){return e.txt("prettyPrint: TypeNotFound Error")}};return a.appendChild(l[r.forceObject?"object":e.type(n)](n,0)),a};return t.config={expanded:!0,forceObject:!1,maxDepth:3,maxArray:-1,styles:{array:{th:{backgroundColor:"#6DBD2A",color:"white"}},function:{th:{backgroundColor:"#D82525"}},regexp:{th:{backgroundColor:"#E2F3FB",color:"#000"}},object:{th:{backgroundColor:"#1F96CF"}},jquery:{th:{backgroundColor:"#FBF315"}},error:{th:{backgroundColor:"red",color:"yellow"}},domelement:{th:{backgroundColor:"#F3801E"}},date:{th:{backgroundColor:"#A725D8"}},colHeader:{th:{backgroundColor:"#EEE",color:"#000",textTransform:"uppercase"}},default:{table:{borderCollapse:"collapse",width:"100%"},td:{padding:"5px",fontSize:"12px",backgroundColor:"#FFF",color:"#222",border:"1px solid #000",verticalAlign:"top",fontFamily:'"Consolas","Lucida Console",Courier,mono',whiteSpace:"nowrap"},td_hover:{},th:{padding:"5px",fontSize:"12px",backgroundColor:"#222",color:"#EEE",textAlign:"left",border:"1px solid #000",verticalAlign:"top",fontFamily:'"Consolas","Lucida Console",Courier,mono',backgroundImage:e.headerGradient,backgroundRepeat:"repeat-x"}}}},t}();var dbits,canary=0xdeadbeefcafe,j_lm=15715070==(16777215&canary);function encryptionBigInteger(t,i,n){null!=t&&("number"==typeof t?this.fromNumber(t,i,n):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function nbi(){return new encryptionBigInteger(null)}function am1(t,i,n,r,o,e){for(;--e>=0;){var s=i*this[t++]+n[r]+o;o=Math.floor(s/67108864),n[r++]=67108863&s}return o}function am2(t,i,n,r,o,e){for(var s=32767&i,h=i>>15;--e>=0;){var p=32767&this[t],c=this[t++]>>15,a=h*p+c*s;o=((p=s*p+((32767&a)<<15)+n[r]+(1073741823&o))>>>30)+(a>>>15)+h*c+(o>>>30),n[r++]=1073741823&p}return o}function am3(t,i,n,r,o,e){for(var s=16383&i,h=i>>14;--e>=0;){var p=16383&this[t],c=this[t++]>>14,a=h*p+c*s;o=((p=s*p+((16383&a)<<14)+n[r]+o)>>28)+(a>>14)+h*c,n[r++]=268435455&p}return o}j_lm&&"Microsoft Internet Explorer"==navigator.appName?(encryptionBigInteger.prototype.am=am2,dbits=30):j_lm&&"Netscape"!=navigator.appName?(encryptionBigInteger.prototype.am=am1,dbits=26):(encryptionBigInteger.prototype.am=am3,dbits=28),encryptionBigInteger.prototype.DB=dbits,encryptionBigInteger.prototype.DM=(1<<dbits)-1,encryptionBigInteger.prototype.DV=1<<dbits;var BI_FP=52;encryptionBigInteger.prototype.FV=Math.pow(2,BI_FP),encryptionBigInteger.prototype.F1=BI_FP-dbits,encryptionBigInteger.prototype.F2=2*dbits-BI_FP;var rr,vv,BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=new Array;for(rr="0".charCodeAt(0),vv=0;vv<=9;++vv)BI_RC[rr++]=vv;for(rr="a".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;for(rr="A".charCodeAt(0),vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(t){return BI_RM.charAt(t)}function intAt(t,i){var n=BI_RC[t.charCodeAt(i)];return null==n?-1:n}function bnpCopyTo(t){for(var i=this.t-1;i>=0;--i)t[i]=this[i];t.t=this.t,t.s=this.s}function bnpFromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+DV:this.t=0}function nbv(t){var i=nbi();return i.fromInt(t),i}function bnpFromString(t,i){var n;if(16==i)n=4;else if(8==i)n=3;else if(256==i)n=8;else if(2==i)n=1;else if(32==i)n=5;else{if(4!=i)return void this.fromRadix(t,i);n=2}this.t=0,this.s=0;for(var r=t.length,o=!1,e=0;--r>=0;){var s=8==n?255&t[r]:intAt(t,r);s<0?"-"==t.charAt(r)&&(o=!0):(o=!1,0==e?this[this.t++]=s:e+n>this.DB?(this[this.t-1]|=(s&(1<<this.DB-e)-1)<<e,this[this.t++]=s>>this.DB-e):this[this.t-1]|=s<<e,(e+=n)>=this.DB&&(e-=this.DB))}8==n&&128&t[0]&&(this.s=-1,e>0&&(this[this.t-1]|=(1<<this.DB-e)-1<<e)),this.clamp(),o&&encryptionBigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}function bnToString(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var n,r=(1<<i)-1,o=!1,e="",s=this.t,h=this.DB-s*this.DB%i;if(s-- >0)for(h<this.DB&&(n=this[s]>>h)>0&&(o=!0,e=int2char(n));s>=0;)h<i?(n=(this[s]&(1<<h)-1)<<i-h,n|=this[--s]>>(h+=this.DB-i)):(n=this[s]>>(h-=i)&r,h<=0&&(h+=this.DB,--s)),n>0&&(o=!0),o&&(e+=int2char(n));return o?e:"0"}function bnNegate(){var t=nbi();return encryptionBigInteger.ZERO.subTo(this,t),t}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(t){var i=this.s-t.s;if(0!=i)return i;var n=this.t;if(0!=(i=n-t.t))return this.s<0?-i:i;for(;--n>=0;)if(0!=(i=this[n]-t[n]))return i;return 0}function nbits(t){var i,n=1;return 0!=(i=t>>>16)&&(t=i,n+=16),0!=(i=t>>8)&&(t=i,n+=8),0!=(i=t>>4)&&(t=i,n+=4),0!=(i=t>>2)&&(t=i,n+=2),0!=(i=t>>1)&&(t=i,n+=1),n}function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(t,i){var n;for(n=this.t-1;n>=0;--n)i[n+t]=this[n];for(n=t-1;n>=0;--n)i[n]=0;i.t=this.t+t,i.s=this.s}function bnpDRShiftTo(t,i){for(var n=t;n<this.t;++n)i[n-t]=this[n];i.t=Math.max(this.t-t,0),i.s=this.s}function bnpLShiftTo(t,i){var n,r=t%this.DB,o=this.DB-r,e=(1<<o)-1,s=Math.floor(t/this.DB),h=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)i[n+s+1]=this[n]>>o|h,h=(this[n]&e)<<r;for(n=s-1;n>=0;--n)i[n]=0;i[s]=h,i.t=this.t+s+1,i.s=this.s,i.clamp()}function bnpRShiftTo(t,i){i.s=this.s;var n=Math.floor(t/this.DB);if(n>=this.t)i.t=0;else{var r=t%this.DB,o=this.DB-r,e=(1<<r)-1;i[0]=this[n]>>r;for(var s=n+1;s<this.t;++s)i[s-n-1]|=(this[s]&e)<<o,i[s-n]=this[s]>>r;r>0&&(i[this.t-n-1]|=(this.s&e)<<o),i.t=this.t-n,i.clamp()}}function bnpSubTo(t,i){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]-t[n],i[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;n<this.t;)r+=this[n],i[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r-=t[n],i[n++]=r&this.DM,r>>=this.DB;r-=t.s}i.s=r<0?-1:0,r<-1?i[n++]=this.DV+r:r>0&&(i[n++]=r),i.t=n,i.clamp()}function bnpMultiplyTo(t,i){var n=this.abs(),r=t.abs(),o=n.t;for(i.t=o+r.t;--o>=0;)i[o]=0;for(o=0;o<r.t;++o)i[o+n.t]=n.am(0,r[o],i,o,0,n.t);i.s=0,i.clamp(),this.s!=t.s&&encryptionBigInteger.ZERO.subTo(i,i)}function bnpSquareTo(t){for(var i=this.abs(),n=t.t=2*i.t;--n>=0;)t[n]=0;for(n=0;n<i.t-1;++n){var r=i.am(n,i[n],t,2*n,0,1);(t[n+i.t]+=i.am(n+1,2*i[n],t,2*n+1,r,i.t-n-1))>=i.DV&&(t[n+i.t]-=i.DV,t[n+i.t+1]=1)}t.t>0&&(t[t.t-1]+=i.am(n,i[n],t,2*n,0,1)),t.s=0,t.clamp()}function bnpDivRemTo(t,i,n){var r=t.abs();if(!(r.t<=0)){var o=this.abs();if(o.t<r.t)return null!=i&&i.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=nbi());var e=nbi(),s=this.s,h=t.s,p=this.DB-nbits(r[r.t-1]);p>0?(r.lShiftTo(p,e),o.lShiftTo(p,n)):(r.copyTo(e),o.copyTo(n));var c=e.t,a=e[c-1];if(0!=a){var f=a*(1<<this.F1)+(c>1?e[c-2]>>this.F2:0),u=this.FV/f,g=(1<<this.F1)/f,m=1<<this.F2,y=n.t,v=y-c,b=null==i?nbi():i;for(e.dlShiftTo(v,b),n.compareTo(b)>=0&&(n[n.t++]=1,n.subTo(b,n)),encryptionBigInteger.ONE.dlShiftTo(c,b),b.subTo(e,e);e.t<c;)e[e.t++]=0;for(;--v>=0;){var l=n[--y]==a?this.DM:Math.floor(n[y]*u+(n[y-1]+m)*g);if((n[y]+=e.am(0,l,n,v,0,c))<l)for(e.dlShiftTo(v,b),n.subTo(b,n);n[y]<--l;)n.subTo(b,n)}null!=i&&(n.drShiftTo(c,i),s!=h&&encryptionBigInteger.ZERO.subTo(i,i)),n.t=c,n.clamp(),p>0&&n.rShiftTo(p,n),s<0&&encryptionBigInteger.ZERO.subTo(n,n)}}}function bnMod(t){var i=nbi();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(encryptionBigInteger.ZERO)>0&&t.subTo(i,i),i}function Classic(t){this.m=t}function cConvert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function cRevert(t){return t}function cReduce(t){t.divRemTo(this.m,null,t)}function cMulTo(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function cSqrTo(t,i){t.squareTo(i),this.reduce(i)}function bnpInvDigit(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i}function Montgomery(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function montConvert(t){var i=nbi();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(encryptionBigInteger.ZERO)>0&&this.m.subTo(i,i),i}function montRevert(t){var i=nbi();return t.copyTo(i),this.reduce(i),i}function montReduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var i=0;i<this.m.t;++i){var n=32767&t[i],r=n*this.mpl+((n*this.mph+(t[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=i+this.m.t]+=this.m.am(0,r,t,i,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function montSqrTo(t,i){t.squareTo(i),this.reduce(i)}function montMulTo(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function bnpIsEven(){return 0==(this.t>0?1&this[0]:this.s)}function bnpExp(t,i){if(t>4294967295||t<1)return encryptionBigInteger.ONE;var n=nbi(),r=nbi(),o=i.convert(this),e=nbits(t)-1;for(o.copyTo(n);--e>=0;)if(i.sqrTo(n,r),(t&1<<e)>0)i.mulTo(r,o,n);else{var s=n;n=r,r=s}return i.revert(n)}function bnModPowInt(t,i){var n;return n=t<256||i.isEven()?new Classic(i):new Montgomery(i),this.exp(t,n)}Classic.prototype.convert=cConvert,Classic.prototype.revert=cRevert,Classic.prototype.reduce=cReduce,Classic.prototype.mulTo=cMulTo,Classic.prototype.sqrTo=cSqrTo,Montgomery.prototype.convert=montConvert,Montgomery.prototype.revert=montRevert,Montgomery.prototype.reduce=montReduce,Montgomery.prototype.mulTo=montMulTo,Montgomery.prototype.sqrTo=montSqrTo,encryptionBigInteger.prototype.copyTo=bnpCopyTo,encryptionBigInteger.prototype.fromInt=bnpFromInt,encryptionBigInteger.prototype.fromString=bnpFromString,encryptionBigInteger.prototype.clamp=bnpClamp,encryptionBigInteger.prototype.dlShiftTo=bnpDLShiftTo,encryptionBigInteger.prototype.drShiftTo=bnpDRShiftTo,encryptionBigInteger.prototype.lShiftTo=bnpLShiftTo,encryptionBigInteger.prototype.rShiftTo=bnpRShiftTo,encryptionBigInteger.prototype.subTo=bnpSubTo,encryptionBigInteger.prototype.multiplyTo=bnpMultiplyTo,encryptionBigInteger.prototype.squareTo=bnpSquareTo,encryptionBigInteger.prototype.divRemTo=bnpDivRemTo,encryptionBigInteger.prototype.invDigit=bnpInvDigit,encryptionBigInteger.prototype.isEven=bnpIsEven,encryptionBigInteger.prototype.exp=bnpExp,encryptionBigInteger.prototype.toString=bnToString,encryptionBigInteger.prototype.negate=bnNegate,encryptionBigInteger.prototype.abs=bnAbs,encryptionBigInteger.prototype.compareTo=bnCompareTo,encryptionBigInteger.prototype.bitLength=bnBitLength,encryptionBigInteger.prototype.mod=bnMod,encryptionBigInteger.prototype.modPowInt=bnModPowInt,encryptionBigInteger.ZERO=nbv(0),encryptionBigInteger.ONE=nbv(1);function bnClone(){var t=nbi();return this.copyTo(t),t}function bnIntValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return 0==this.t?this.s:this[0]<<24>>24}function bnShortValue(){return 0==this.t?this.s:this[0]<<16>>16}function bnpChunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function bnSigNum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function bnpToRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var i=this.chunkSize(t),n=Math.pow(t,i),r=nbv(n),e=nbi(),o=nbi(),s="";for(this.divRemTo(r,e,o);e.signum()>0;)s=(n+o.intValue()).toString(t).substr(1)+s,e.divRemTo(r,e,o);return o.intValue().toString(t)+s}function bnpFromRadix(t,i){this.fromInt(0),null==i&&(i=10);for(var n=this.chunkSize(i),r=Math.pow(i,n),e=!1,o=0,s=0,p=0;p<t.length;++p){var h=intAt(t,p);h<0?"-"==t.charAt(p)&&0==this.signum()&&(e=!0):(s=i*s+h,++o>=n&&(this.dMultiply(r),this.dAddOffset(s,0),o=0,s=0))}o>0&&(this.dMultiply(Math.pow(i,o)),this.dAddOffset(s,0)),e&&encryptionBigInteger.ZERO.subTo(this,this)}function bnpFromNumber(t,i,n){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(encryptionBigInteger.ONE.shiftLeft(t-1),op_or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(encryptionBigInteger.ONE.shiftLeft(t-1),this);else{var r=new Array,e=7&t;r.length=1+(t>>3),i.nextBytes(r),e>0?r[0]&=(1<<e)-1:r[0]=0,this.fromString(r,256)}}function bnToByteArray(){var t=this.t,i=new Array;i[0]=this.s;var n,r=this.DB-t*this.DB%8,e=0;if(t-- >0)for(r<this.DB&&(n=this[t]>>r)!=(this.s&this.DM)>>r&&(i[e++]=n|this.s<<this.DB-r);t>=0;)r<8?(n=(this[t]&(1<<r)-1)<<8-r,n|=this[--t]>>(r+=this.DB-8)):(n=this[t]>>(r-=8)&255,r<=0&&(r+=this.DB,--t)),128&n&&(n|=-256),0==e&&(128&this.s)!=(128&n)&&++e,(e>0||n!=this.s)&&(i[e++]=n);return i}function bnEquals(t){return 0==this.compareTo(t)}function bnMin(t){return this.compareTo(t)<0?this:t}function bnMax(t){return this.compareTo(t)>0?this:t}function bnpBitwiseTo(t,i,n){var r,e,o=Math.min(t.t,this.t);for(r=0;r<o;++r)n[r]=i(this[r],t[r]);if(t.t<this.t){for(e=t.s&this.DM,r=o;r<this.t;++r)n[r]=i(this[r],e);n.t=this.t}else{for(e=this.s&this.DM,r=o;r<t.t;++r)n[r]=i(e,t[r]);n.t=t.t}n.s=i(this.s,t.s),n.clamp()}function op_and(t,i){return t&i}function bnAnd(t){var i=nbi();return this.bitwiseTo(t,op_and,i),i}function op_or(t,i){return t|i}function bnOr(t){var i=nbi();return this.bitwiseTo(t,op_or,i),i}function op_xor(t,i){return t^i}function bnXor(t){var i=nbi();return this.bitwiseTo(t,op_xor,i),i}function op_andnot(t,i){return t&~i}function bnAndNot(t){var i=nbi();return this.bitwiseTo(t,op_andnot,i),i}function bnNot(){for(var t=nbi(),i=0;i<this.t;++i)t[i]=this.DM&~this[i];return t.t=this.t,t.s=~this.s,t}function bnShiftLeft(t){var i=nbi();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i}function bnShiftRight(t){var i=nbi();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i}function lbit(t){if(0==t)return-1;var i=0;return 65535&t||(t>>=16,i+=16),255&t||(t>>=8,i+=8),15&t||(t>>=4,i+=4),3&t||(t>>=2,i+=2),1&t||++i,i}function bnGetLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+lbit(this[t]);return this.s<0?this.t*this.DB:-1}function cbit(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function bnBitCount(){for(var t=0,i=this.s&this.DM,n=0;n<this.t;++n)t+=cbit(this[n]^i);return t}function bnTestBit(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:!!(this[i]&1<<t%this.DB)}function bnpChangeBit(t,i){var n=encryptionBigInteger.ONE.shiftLeft(t);return this.bitwiseTo(n,i,n),n}function bnSetBit(t){return this.changeBit(t,op_or)}function bnClearBit(t){return this.changeBit(t,op_andnot)}function bnFlipBit(t){return this.changeBit(t,op_xor)}function bnpAddTo(t,i){for(var n=0,r=0,e=Math.min(t.t,this.t);n<e;)r+=this[n]+t[n],i[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;n<this.t;)r+=this[n],i[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r+=t[n],i[n++]=r&this.DM,r>>=this.DB;r+=t.s}i.s=r<0?-1:0,r>0?i[n++]=r:r<-1&&(i[n++]=this.DV+r),i.t=n,i.clamp()}function bnAdd(t){var i=nbi();return this.addTo(t,i),i}function bnSubtract(t){var i=nbi();return this.subTo(t,i),i}function bnMultiply(t){var i=nbi();return this.multiplyTo(t,i),i}function bnSquare(){var t=nbi();return this.squareTo(t),t}function bnDivide(t){var i=nbi();return this.divRemTo(t,i,null),i}function bnRemainder(t){var i=nbi();return this.divRemTo(t,null,i),i}function bnDivideAndRemainder(t){var i=nbi(),n=nbi();return this.divRemTo(t,i,n),new Array(i,n)}function bnpDMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function bnpDAddOffset(t,i){if(0!=t){for(;this.t<=i;)this[this.t++]=0;for(this[i]+=t;this[i]>=this.DV;)this[i]-=this.DV,++i>=this.t&&(this[this.t++]=0),++this[i]}}function NullExp(){}function nNop(t){return t}function nMulTo(t,i,n){t.multiplyTo(i,n)}function nSqrTo(t,i){t.squareTo(i)}function bnPow(t){return this.exp(t,new NullExp)}function bnpMultiplyLowerTo(t,i,n){var r,e=Math.min(this.t+t.t,i);for(n.s=0,n.t=e;e>0;)n[--e]=0;for(r=n.t-this.t;e<r;++e)n[e+this.t]=this.am(0,t[e],n,e,0,this.t);for(r=Math.min(t.t,i);e<r;++e)this.am(0,t[e],n,e,0,i-e);n.clamp()}function bnpMultiplyUpperTo(t,i,n){--i;var r=n.t=this.t+t.t-i;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(i-this.t,0);r<t.t;++r)n[this.t+r-i]=this.am(i-r,t[r],n,0,0,this.t+r-i);n.clamp(),n.drShiftTo(1,n)}function Barrett(t){this.r2=nbi(),this.q3=nbi(),encryptionBigInteger.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function barrettConvert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=nbi();return t.copyTo(i),this.reduce(i),i}function barrettRevert(t){return t}function barrettReduce(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}function barrettSqrTo(t,i){t.squareTo(i),this.reduce(i)}function barrettMulTo(t,i,n){t.multiplyTo(i,n),this.reduce(n)}function bnModPow(t,i){var n,r,e=t.bitLength(),o=nbv(1);if(e<=0)return o;n=e<18?1:e<48?3:e<144?4:e<768?5:6,r=e<8?new Classic(i):i.isEven()?new Barrett(i):new Montgomery(i);var s=new Array,p=3,h=n-1,u=(1<<n)-1;if(s[1]=r.convert(this),n>1){var f=nbi();for(r.sqrTo(s[1],f);p<=u;)s[p]=nbi(),r.mulTo(f,s[p-2],s[p]),p+=2}var a,b,c=t.t-1,g=!0,l=nbi();for(e=nbits(t[c])-1;c>=0;){for(e>=h?a=t[c]>>e-h&u:(a=(t[c]&(1<<e+1)-1)<<h-e,c>0&&(a|=t[c-1]>>this.DB+e-h)),p=n;!(1&a);)a>>=1,--p;if((e-=p)<0&&(e+=this.DB,--c),g)s[a].copyTo(o),g=!1;else{for(;p>1;)r.sqrTo(o,l),r.sqrTo(l,o),p-=2;p>0?r.sqrTo(o,l):(b=o,o=l,l=b),r.mulTo(l,s[a],o)}for(;c>=0&&!(t[c]&1<<e);)r.sqrTo(o,l),b=o,o=l,l=b,--e<0&&(e=this.DB-1,--c)}return r.revert(o)}function bnGCD(t){var i=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(i.compareTo(n)<0){var r=i;i=n,n=r}var e=i.getLowestSetBit(),o=n.getLowestSetBit();if(o<0)return i;for(e<o&&(o=e),o>0&&(i.rShiftTo(o,i),n.rShiftTo(o,n));i.signum()>0;)(e=i.getLowestSetBit())>0&&i.rShiftTo(e,i),(e=n.getLowestSetBit())>0&&n.rShiftTo(e,n),i.compareTo(n)>=0?(i.subTo(n,i),i.rShiftTo(1,i)):(n.subTo(i,n),n.rShiftTo(1,n));return o>0&&n.lShiftTo(o,n),n}function bnpModInt(t){if(t<=0)return 0;var i=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(0==i)n=this[0]%t;else for(var r=this.t-1;r>=0;--r)n=(i*n+this[r])%t;return n}function bnModInverse(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return encryptionBigInteger.ZERO;for(var n=t.clone(),r=this.clone(),e=nbv(1),o=nbv(0),s=nbv(0),p=nbv(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),i?(e.isEven()&&o.isEven()||(e.addTo(this,e),o.subTo(t,o)),e.rShiftTo(1,e)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;r.isEven();)r.rShiftTo(1,r),i?(s.isEven()&&p.isEven()||(s.addTo(this,s),p.subTo(t,p)),s.rShiftTo(1,s)):p.isEven()||p.subTo(t,p),p.rShiftTo(1,p);n.compareTo(r)>=0?(n.subTo(r,n),i&&e.subTo(s,e),o.subTo(p,o)):(r.subTo(n,r),i&&s.subTo(e,s),p.subTo(o,p))}return 0!=r.compareTo(encryptionBigInteger.ONE)?encryptionBigInteger.ZERO:p.compareTo(t)>=0?p.subtract(t):p.signum()<0?(p.addTo(t,p),p.signum()<0?p.add(t):p):p}NullExp.prototype.convert=nNop,NullExp.prototype.revert=nNop,NullExp.prototype.mulTo=nMulTo,NullExp.prototype.sqrTo=nSqrTo,Barrett.prototype.convert=barrettConvert,Barrett.prototype.revert=barrettRevert,Barrett.prototype.reduce=barrettReduce,Barrett.prototype.mulTo=barrettMulTo,Barrett.prototype.sqrTo=barrettSqrTo;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],lplim=(1<<26)/lowprimes[lowprimes.length-1];function bnIsProbablePrime(t){var i,n=this.abs();if(1==n.t&&n[0]<=lowprimes[lowprimes.length-1]){for(i=0;i<lowprimes.length;++i)if(n[0]==lowprimes[i])return!0;return!1}if(n.isEven())return!1;for(i=1;i<lowprimes.length;){for(var r=lowprimes[i],e=i+1;e<lowprimes.length&&r<lplim;)r*=lowprimes[e++];for(r=n.modInt(r);i<e;)if(r%lowprimes[i++]==0)return!1}return n.millerRabin(t)}function bnpMillerRabin(t){var i=this.subtract(encryptionBigInteger.ONE),n=i.getLowestSetBit();if(n<=0)return!1;var r=i.shiftRight(n);(t=t+1>>1)>lowprimes.length&&(t=lowprimes.length);for(var e=nbi(),o=0;o<t;++o){e.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var s=e.modPow(r,this);if(0!=s.compareTo(encryptionBigInteger.ONE)&&0!=s.compareTo(i)){for(var p=1;p++<n&&0!=s.compareTo(i);)if(0==(s=s.modPowInt(2,this)).compareTo(encryptionBigInteger.ONE))return!1;if(0!=s.compareTo(i))return!1}}return!0}encryptionBigInteger.prototype.chunkSize=bnpChunkSize,encryptionBigInteger.prototype.toRadix=bnpToRadix,encryptionBigInteger.prototype.fromRadix=bnpFromRadix,encryptionBigInteger.prototype.fromNumber=bnpFromNumber,encryptionBigInteger.prototype.bitwiseTo=bnpBitwiseTo,encryptionBigInteger.prototype.changeBit=bnpChangeBit,encryptionBigInteger.prototype.addTo=bnpAddTo,encryptionBigInteger.prototype.dMultiply=bnpDMultiply,encryptionBigInteger.prototype.dAddOffset=bnpDAddOffset,encryptionBigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo,encryptionBigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo,encryptionBigInteger.prototype.modInt=bnpModInt,encryptionBigInteger.prototype.millerRabin=bnpMillerRabin,encryptionBigInteger.prototype.clone=bnClone,encryptionBigInteger.prototype.intValue=bnIntValue,encryptionBigInteger.prototype.byteValue=bnByteValue,encryptionBigInteger.prototype.shortValue=bnShortValue,encryptionBigInteger.prototype.signum=bnSigNum,encryptionBigInteger.prototype.toByteArray=bnToByteArray,encryptionBigInteger.prototype.equals=bnEquals,encryptionBigInteger.prototype.min=bnMin,encryptionBigInteger.prototype.max=bnMax,encryptionBigInteger.prototype.and=bnAnd,encryptionBigInteger.prototype.or=bnOr,encryptionBigInteger.prototype.xor=bnXor,encryptionBigInteger.prototype.andNot=bnAndNot,encryptionBigInteger.prototype.not=bnNot,encryptionBigInteger.prototype.shiftLeft=bnShiftLeft,encryptionBigInteger.prototype.shiftRight=bnShiftRight,encryptionBigInteger.prototype.getLowestSetBit=bnGetLowestSetBit,encryptionBigInteger.prototype.bitCount=bnBitCount,encryptionBigInteger.prototype.testBit=bnTestBit,encryptionBigInteger.prototype.setBit=bnSetBit,encryptionBigInteger.prototype.clearBit=bnClearBit,encryptionBigInteger.prototype.flipBit=bnFlipBit,encryptionBigInteger.prototype.add=bnAdd,encryptionBigInteger.prototype.subtract=bnSubtract,encryptionBigInteger.prototype.multiply=bnMultiply,encryptionBigInteger.prototype.divide=bnDivide,encryptionBigInteger.prototype.remainder=bnRemainder,encryptionBigInteger.prototype.divideAndRemainder=bnDivideAndRemainder,encryptionBigInteger.prototype.modPow=bnModPow,encryptionBigInteger.prototype.modInverse=bnModInverse,encryptionBigInteger.prototype.pow=bnPow,encryptionBigInteger.prototype.gcd=bnGCD,encryptionBigInteger.prototype.isProbablePrime=bnIsProbablePrime,encryptionBigInteger.prototype.square=bnSquare;function Arcfour(){this.i=0,this.j=0,this.S=new Array}function ARC4init(i){var t,s,h;for(t=0;t<256;++t)this.S[t]=t;for(s=0,t=0;t<256;++t)s=s+this.S[t]+i[t%i.length]&255,h=this.S[t],this.S[t]=this.S[s],this.S[s]=h;this.i=0,this.j=0}function ARC4next(){var i;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,i=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=i,this.S[i+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}Arcfour.prototype.init=ARC4init,Arcfour.prototype.next=ARC4next;var rng_psize=256;var rng_state,rng_pool,rng_pptr;function rng_seed_int(r){rng_pool[rng_pptr++]^=255&r,rng_pool[rng_pptr++]^=r>>8&255,rng_pool[rng_pptr++]^=r>>16&255,rng_pool[rng_pptr++]^=r>>24&255,rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}if(null==rng_pool){var t;if(rng_pool=new Array,rng_pptr=0,"Netscape"==navigator.appName&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t<z.length;++t)rng_pool[rng_pptr++]=255&z.charCodeAt(t)}for(;rng_pptr<rng_psize;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=255&t;rng_pptr=0,rng_seed_time()}function rng_get_byte(){if(null==rng_state){for(rng_seed_time(),(rng_state=prng_newstate()).init(rng_pool),rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr)rng_pool[rng_pptr]=0;rng_pptr=0}return rng_state.next()}function rng_get_bytes(r){var n;for(n=0;n<r.length;++n)r[n]=rng_get_byte()}function SecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;function sha1Hash(r){for(var t=[1518500249,1859775393,2400959708,3395469782],o=(r+=String.fromCharCode(128)).length/4+2,e=Math.ceil(o/16),a=new Array(e),n=0;n<e;n++){a[n]=new Array(16);for(var h=0;h<16;h++)a[n][h]=r.charCodeAt(64*n+4*h)<<24|r.charCodeAt(64*n+4*h+1)<<16|r.charCodeAt(64*n+4*h+2)<<8|r.charCodeAt(64*n+4*h+3)}a[e-1][14]=8*(r.length-1)/Math.pow(2,32),a[e-1][14]=Math.floor(a[e-1][14]),a[e-1][15]=8*(r.length-1)&4294967295;var c,u,i,s,S,A=1732584193,H=4023233417,l=2562383102,v=271733878,x=3285377520,C=new Array(80);for(n=0;n<e;n++){for(var d=0;d<16;d++)C[d]=a[n][d];for(d=16;d<80;d++)C[d]=ROTL(C[d-3]^C[d-8]^C[d-14]^C[d-16],1);c=A,u=H,i=l,s=v,S=x;for(d=0;d<80;d++){var g=Math.floor(d/20),w=ROTL(c,5)+f(g,u,i,s)+S+t[g]+C[d]&4294967295;S=s,s=i,i=ROTL(u,30),u=c,c=w}A=A+c&4294967295,H=H+u&4294967295,l=l+i&4294967295,v=v+s&4294967295,x=x+S&4294967295}return A.toHexStr()+H.toHexStr()+l.toHexStr()+v.toHexStr()+x.toHexStr()}function f(r,t,o,e){switch(r){case 0:return t&o^~t&e;case 1:case 3:return t^o^e;case 2:return t&o^t&e^o&e}}function ROTL(r,t){return r<<t|r>>>32-t}Number.prototype.toHexStr=function(){for(var r="",t=7;t>=0;t--)r+=(this>>>4*t&15).toString(16);return r};function pack(r){for(var t="",n=0;n<r.length;n+=2)t+=String.fromCharCode(parseInt(r.substring(n,n+2),16));return t}function char2hex(r){for(var t="",n=0;n<r.length;n+=1){switch(temp=r[n].toString(16),temp.length){case 1:temp="0"+temp;break;case 0:temp="00"}t+=temp}return t}function xor(r,t){length=Math.min(r.length,t.length),temp="";for(var n=0;n<length;n++)temp+=String.fromCharCode(r.charCodeAt(n)^t.charCodeAt(n));length=Math.max(r.length,t.length)-length;for(n=0;n<length;n++)temp+="\0";return temp}function mgf1(r,n){t="",hLen=20,count=Math.ceil(n/hLen);for(var e=0;e<count;e++)c=String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e),t+=pack(sha1Hash(r+c));return t.substring(0,n)}function rsa_oaep_encrypt(r,t,n){for(var e="Ú9£î^kK\r2U¿ï•`¯Ø\t",o=128-r.length-40-2,a=0;a<o;a++)e+="\0";var g=e+""+r,h="";for(a=0;a<24;a+=4)o=new Array(4),rng.nextBytes(o),h+=String.fromCharCode(o[0],o[1],o[2],o[3]);var i=xor(g,mgf1(h=h.substring(4-h.length%4),107)),f="\0"+xor(h,mgf1(i,20))+i;for(m=new Array,a=0;a<f.length;a++)m[a]=f.charCodeAt(a);return m=new encryptionBigInteger(m,256),c=m.modPowInt(n,t),c=c.toString(16),1&c.length&&(c="0"+c),c}function RSA_public_encrypt(r,t){for(var n=new Uint8Array(t),e=new Array(129),o=0;o<129;o++)e[o]=n[28+o];var a=new encryptionBigInteger(e),g=new encryptionBigInteger("010001",16);return rsa_oaep_encrypt(r+String.fromCharCode(0),a,g)}rng=new SecureRandom;var SWCanvas=function(t){this.arr=new ArrayBuffer(t.width*t.height*4),this.arr32=new Uint32Array(this.arr),this.arr8=new Uint8ClampedArray(this.arr),this.canvas=t,this.width=this.canvas.width,this.height=this.canvas.height};SWCanvas.prototype.putImageData=function(t,a,r){for(var i,h,e=t.data.buffer,s=t.width,n=t.height,o=this.width;n--;)i=(r+n)*o+a,h=new Uint32Array(e,s*n*4,s),this.arr32.set(h,i)},SWCanvas.prototype.getImageData=function(t,a,r,i){for(var h,e=new Uint32Array(r*i),s=this.arr32,n=i,o=this.width;n--;){h=(a+n)*o+t;var f=s.subarray(h,h+r);e.set(f,r*n)}return new ImageData(new Uint8ClampedArray(e.buffer),r,i)},SWCanvas.prototype.fillRect=function(t,a,r,i,h,e,s){for(var n,o=new Uint32Array(e),f=4278190080|t|a<<8|r<<16,v=this.width,w=e;w--;)o[w]=f;for(;s--;)n=(h+s)*v+i,this.arr32.set(o,n)},SWCanvas.prototype.flushBack=function(){var t=this.canvas.getContext("2d").getImageData(0,0,this.width,this.height).data;this.arr8.set(t)},SWCanvas.prototype.flush=function(){var t=new ImageData(this.arr8,this.width,this.height);this.canvas.getContext("2d").putImageData(t,0,0)};!function(e,i){"undefined"!=typeof module&&module.exports?module.exports.browser=i():this.bowser=i()}(0,(function(){var e=!0;function i(i){function o(e){var o=i.match(e);return o&&o.length>1&&o[1]||""}var s,r=o(/(ipod|iphone|ipad)/i).toLowerCase(),n=!/like android/i.test(i)&&/android/i.test(i),a=o(/version\/(\d+(\.\d+)?)/i),t=/tablet/i.test(i),d=!t&&/[^-]mobi/i.test(i);/opera|opr/i.test(i)?s={name:"Opera",opera:e,version:a||o(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(i)?s={name:"Windows Phone",windowsphone:e,msie:e,version:o(/iemobile\/(\d+(\.\d+)?)/i)}:/msie|trident/i.test(i)?s={name:"Internet Explorer",msie:e,version:o(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome|crios|crmo/i.test(i)?s={name:"Chrome",chrome:e,version:o(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:r?(s={name:"iphone"==r?"iPhone":"ipad"==r?"iPad":"iPod"},a&&(s.version=a)):/sailfish/i.test(i)?s={name:"Sailfish",sailfish:e,version:o(/sailfish\s?browser\/(\d+(\.\d+)?)/i)}:/seamonkey\//i.test(i)?s={name:"SeaMonkey",seamonkey:e,version:o(/seamonkey\/(\d+(\.\d+)?)/i)}:/firefox|iceweasel/i.test(i)?(s={name:"Firefox",firefox:e,version:o(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(i)&&(s.firefoxos=e)):/silk/i.test(i)?s={name:"Amazon Silk",silk:e,version:o(/silk\/(\d+(\.\d+)?)/i)}:n?s={name:"Android",version:a}:/phantom/i.test(i)?s={name:"PhantomJS",phantom:e,version:o(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(i)||/rim\stablet/i.test(i)?s={name:"BlackBerry",blackberry:e,version:a||o(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(i)?(s={name:"WebOS",webos:e,version:a||o(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(i)&&(s.touchpad=e)):s=/bada/i.test(i)?{name:"Bada",bada:e,version:o(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(i)?{name:"Tizen",tizen:e,version:o(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||a}:/safari/i.test(i)?{name:"Safari",safari:e,version:a}:{},/(apple)?webkit/i.test(i)?(s.name=s.name||"Webkit",s.webkit=e,!s.version&&a&&(s.version=a)):!s.opera&&/gecko\//i.test(i)&&(s.name=s.name||"Gecko",s.gecko=e,s.version=s.version||o(/gecko\/(\d+(\.\d+)?)/i)),n||s.silk?s.android=e:r&&(s[r]=e,s.ios=e);var m="";r?m=(m=o(/os (\d+([_\s]\d+)*) like mac os x/i)).replace(/[_\s]/g,"."):n?m=o(/android[ \/-](\d+(\.\d+)*)/i):s.windowsphone?m=o(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):s.webos?m=o(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):s.blackberry?m=o(/rim\stablet\sos\s(\d+(\.\d+)*)/i):s.bada?m=o(/bada\/(\d+(\.\d+)*)/i):s.tizen&&(m=o(/tizen[\/\s](\d+(\.\d+)*)/i)),m&&(s.osversion=m);var v=m.split(".")[0];return t||"ipad"==r||n&&(3==v||4==v&&!d)||s.silk?s.tablet=e:(d||"iphone"==r||"ipod"==r||n||s.blackberry||s.webos||s.bada)&&(s.mobile=e),s.msie&&s.version>=9||s.chrome&&s.version>=20||s.firefox&&s.version>=10||s.safari&&s.version>=5||s.opera&&s.version>=10||s.ios&&s.osversion&&s.osversion.split(".")[0]>=6?s.a=e:s.msie&&s.version<9||s.chrome&&s.version<20||s.firefox&&s.version<10||s.safari&&s.version<5||s.opera&&s.version<10||s.ios&&s.osversion&&s.osversion.split(".")[0]<6?s.c=e:s.x=e,s}var o=i("undefined"!=typeof navigator?navigator.userAgent:"");return o._detect=i,window.bowser||(window.bowser=o),o}));wdi.Flipper={flip:function(e){return this._handMadeFlip(e)},_handMadeFlip:function(e){var t=document.createElement("canvas");t.width=e.width,t.height=e.height;var a=t.getContext("2d");return a.save(),a.scale(1,-1),a.drawImage(e,0,-e.height),a.restore(),t}};wdi.CollisionDetector={thereIsBoxCollision:function(t,o){return!(t.bottom<o.top)&&(!(t.top>o.bottom)&&(!(t.right<o.left)&&t.left<o.right))}};wdi.GlobalPool={pools:{},retained:null,init:function(){this.retained={};var e=this;this.pools.ViewQueue=new wdi.GenericObjectPool([function(){return new wdi.ViewQueue},function(e,n){e.poolIndex=n,e.setData([])}]),this.pools.RawSpiceMessage=new wdi.GenericObjectPool([function(){return new wdi.RawSpiceMessage},function(e,n){e.poolIndex=n,e.set(null,null,null)}]),this.retained.Image=[],this.pools.Image=new wdi.GenericObjectPool([function(){return new Image},function(n,i){n.poolIndex=i,n.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",n.onload=null,n.keepAlive=!1,e.retained.Image[i]=n}]),this.retained.Canvas=[],this.pools.Canvas=new wdi.GenericObjectPool([function(){return e.createCanvas()},function(n,i){n.keepAlive=!1,n.poolIndex=i,e.retained.Canvas[i]=n}])},dispose:function(){var e=this;Object.keys(this.retained).forEach((function(n){e.cleanPool(n),e.retained[n].length=0})),Object.keys(this.pools).forEach((function(n){e.pools[n].dispose()})),this.pools={},this.retained=null},createCanvas:function(){return $("<canvas/>")[0]},create:function(e){return this.pools[e].create()},discard:function(e,n){return this.retained.hasOwnProperty(e)&&delete this.retained[e][n.poolIndex],this.pools[e].discard(n.poolIndex)},cleanPool:function(e){if(this.retained.hasOwnProperty(e)){var n=this.pools[e];for(var i in this.retained[e])n.discard(this.retained[e][i].poolIndex)&&delete this.retained[e][i]}else wdi.Debug.error("GlobalPool: cleanPool called with invalid objectType: ",e)}};wdi.GenericObjectPool=$.spcExtend(wdi.EventObject.prototype,{expandFactor:.2,expandMinUnits:16,elems:null,freeElems:null,allocator:null,resetor:null,init:function(e){var t=e[0],s=e[1];this.allocator=t,this.resetor=s,this.elems=[this.allocator()],this.freeElems=[0]},dispose:function(){this.elems=null,this.freeElems=null,this.allocator=null,this.resetor=null},create:function(){this.freeElems.length||this.expand();var e=this.freeElems.pop(),t=this.elems[e];return this.resetor(t,e),t},length:function(){return this.elems.length-this.freeElems.length},expand:function(){var e=this.elems.length,t=Math.ceil(this.elems.length*this.expandFactor);t<this.expandMinUnits&&(t=this.expandMinUnits),this.elems.length=this.elems.length+t;for(var s=e;s<this.elems.length;s++)this.elems[s]=this.allocator(),this.freeElems.push(s)},discard:function(e){if(this.freeElems.indexOf(e)>=0)throw"GeneircObjectPool: Double-free for element index: "+e;return!this.elems[e].keepAlive&&(this.freeElems.push(e),!0)},get:function(e){return this.elems[e]}});wdi.AsyncConsumer=$.spcExtend(wdi.EventObject.prototype,{worker:null,task:null,packetWorkerIdentifier:null,imageProperties:null,disposed:!1,init:function(e){this.superInit(),this.worker=e.AsyncWorker||new wdi.AsyncWorker({script:wdi.spiceClientPath+"/spice-console-minify/WorkerProcess.min.js"}),this.packetWorkerIdentifier=e.packetWorkerIdentifier||new wdi.PacketWorkerIdentifier},consume:function(e){this.task=e;var t,i,r,s,a,n,o,p=e.message,d=this.packetWorkerIdentifier.shouldUseWorker(p);if(d==wdi.PacketWorkerIdentifier.processingType.DECOMPRESS&&(t=this.packetWorkerIdentifier.getImageProperties(p),this.imageProperties=t,t&&t.descriptor.type!=wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB&&t.descriptor.type!=wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC?d=0:t||(d=0)),0!==d)if(d==wdi.PacketWorkerIdentifier.processingType.DECOMPRESS){if(i=t.data,r=t.descriptor,s=t.opaque,a=t.brush,r.type===wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB){var h=null;if(a)h=wdi.LZSS.demarshall_rgb(i);else{var k=i.subarray(0,32).toJSArray();i=i.subarray(32),h=wdi.LZSS.demarshall_rgb(k)}n=new ArrayBuffer(i.length+16),(o=new Uint8Array(n))[0]=1,o[1]=s,o[2]=h.type,o[3]=h.top_down;for(var w=h.width*h.height*4,c=0;c<4;c++)o[4+c]=255&w,w>>=8;(l=new DataView(n)).setUint32(8,h.width),l.setUint32(12,h.height),o.set(i,16),this.worker.run(n,this._workerCompleted,{type:"lz",top_down:h.top_down,opaque:s},this)}else if(r.type===wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC){var l,g=new ArrayBuffer(i.length+4);(l=new Uint8Array(g)).set(i,4),l[1]=s?1:0,l[0]=0,this.worker.run(g,this._workerCompleted,{type:"quic"},this)}}else d==wdi.PacketWorkerIdentifier.processingType.PROCESSVIDEO&&(i=this.packetWorkerIdentifier.getVideoData(p),n=new ArrayBuffer(i.length+4),(o=new Uint8Array(n))[0]=2,o[1]=0,o[2]=0,o[3]=0,o.set(i,4),this.worker.run(n,(function(e,t){p.args.data=e,this.taskDone()}),null,this));else this.taskDone()},_workerCompleted:function(e,t){if(e){var i=this.imageProperties.descriptor,r=new Uint8ClampedArray(e),s=new ImageData(r,i.width,i.height),a=s;if("lz"===t.type){var n=t.top_down,o=t.opaque;n||o||(a=wdi.graphics.getImageFromData(s,!0),a=wdi.RasterOperation.flip(a))}i.originalType=i.type,i.type=wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS,this.task.message.messageType===wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL?(this.task.message.args.brush.pattern.imageData=a,this.task.message.args.brush.pattern.image.type=wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS):this.task.message.args.image.data=a,this.taskDone()}else this.taskDone()},taskDone:function(){this.task.state=1,this.fire("done",this)},dispose:function(){this.disposed||(this.disposed=!0,this.worker.dispose(),this.worker=null,this.task=null,this.packetWorkerIdentifier=null,this.imageProperties=null)}});wdi.AsyncWorker=$.spcExtend(wdi.EventObject.prototype,{worker:null,fn:null,scope:null,params:null,callback:null,init:function(s){this.superInit(),this.worker=new Worker(s.script);var t=this;this.callback=function(s){t.fn.call(t.scope,s.data,t.params)},this.worker.addEventListener("message",this.callback)},run:function(s,t,e,i){this.fn=t,this.scope=i,this.params=e,wdi.postMessageW3CCompilant?this.worker.postMessage(s,[s]):this.worker.postMessage(s)},dispose:function(){this.worker.removeEventListener("message",this.callback),this.worker.terminate(),this.worker=null,this.fn=null,this.scope=null,this.params=null,this.callback=null}});wdi.PacketWorkerIdentifier=$.spcExtend(wdi.EventObject.prototype,{init:function(e){},dispose:function(){},shouldUseWorker:function(e){switch(e.messageType){case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY:return wdi.PacketWorkerIdentifier.processingType.DECOMPRESS;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL:if(e.args.brush.type===wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN)return wdi.PacketWorkerIdentifier.processingType.DECOMPRESS;break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:return wdi.PacketWorkerIdentifier.processingType.DECOMPRESS}return 0},getImageProperties:function(e){var r={data:null,descriptor:null,opaque:!0,brush:null};switch(e.messageType){case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY:r.descriptor=e.args.image.imageDescriptor,r.data=e.args.image.data;break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL:if(r.brush=e.args.brush,r.brush.type!==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN)return!1;r.descriptor=r.brush.pattern.image,r.data=r.brush.pattern.imageData;break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND:case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:r.data=e.args.image.data,r.descriptor=e.args.image.imageDescriptor,r.opaque=!1;break;default:return wdi.Debug.log("PacketWorkerIdentifier: Unknown Packet in getImageProperties"),!1}return r},getVideoData:function(e){return e.messageType!==wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA?(wdi.Debug.log("PacketWOrkerIdentifier: Invalid packet in getVideoData"),!1):e.args.data}}),wdi.PacketWorkerIdentifier.processingType={},wdi.PacketWorkerIdentifier.processingType.DECOMPRESS=1,wdi.PacketWorkerIdentifier.processingType.PROCESSVIDEO=2;wdi.SpiceObject={properties:{},bytesToString:function(t){const e=new Uint8Array(t);return new TextDecoder("utf-8").decode(e)},bytesToURI:function(t){var e=new Blob([t],{type:"image/jpeg"});return URL.createObjectURL(e)},bytesToStringBE:function(t,e){for(var i="",s=e||t.length;s>=0;s--)i+=String.fromCharCode(t[s]);return i},bytesToInt8:function(t){return t.shift()},bytesToInt8NoAllocate:function(t){var e=t.getByte(0);return t.eatBytes(1),e},bytesToInt16:function(t){var e=t.shift();return t.shift()*Math.pow(16,2)+e},bytesToInt16BE:function(t){var e=t.shift(),i=t.shift();return e*Math.pow(16,2)+i},bytesToInt32:function(t){var e=wdi.SpiceObject.bytesToInt16(t);return wdi.SpiceObject.bytesToInt16(t)*Math.pow(16,4)+e},bytesToInt16NoAllocate:function(t){var e=t.getByte(0),i=t.getByte(1);return t.eatBytes(2),i*Math.pow(16,2)+e},bytesToInt32NoAllocate:function(t){var e=wdi.SpiceObject.bytesToInt16NoAllocate(t);return wdi.SpiceObject.bytesToInt16NoAllocate(t)*Math.pow(16,4)+e},bytesToInt32BE:function(t){var e=wdi.SpiceObject.bytesToInt16BE(t),i=wdi.SpiceObject.bytesToInt16BE(t);return e*Math.pow(16,4)+i},bytesToInt64:function(t){var e=wdi.SpiceObject.bytesToInt32(t).toString(2).lpad("0",32),i=wdi.SpiceObject.bytesToInt32(t).toString(2).lpad("0",32);return BigInteger.parse(i+e,2)},bytesToInt64NoAllocate:function(t){var e=wdi.SpiceObject.bytesToInt32NoAllocate(t).toString(2).lpad("0",32),i=wdi.SpiceObject.bytesToInt32NoAllocate(t).toString(2).lpad("0",32);return BigInteger.parse(i+e,2)},bytesToInt64BE:function(t){var e=wdi.SpiceObject.bytesToInt32BE(t).toString(2).lpad("0",32),i=wdi.SpiceObject.bytesToInt32BE(t).toString(2).lpad("0",32);return BigInteger.parse(e+i,2)},bytesToArray:function(t,e,i,s){var n=t.length,o=i||n,h=s||"LE",a=[],r=null;switch(e){case 8:r=wdi.SpiceObject.bytesToInt8;break;case 16:r="LE"==h?wdi.SpiceObject.bytesToInt16:wdi.SpiceObject.bytesToInt16BE;break;case 32:r="LE"==h?wdi.SpiceObject.bytesToInt32:wdi.SpiceObject.bytesToInt32BE;break;case 64:r="LE"==h?wdi.SpiceObject.bytesToInt64:wdi.SpiceObject.bytesToInt64BE;break;default:throw new Exception("Not supported number of bits",1)}for(var c=0;c<o;c++)a=a.concat(r(t));return a},int32ToDouble:function(t){return(15&t)/15+wdi.SpiceObject.unsignedToSigned(t>>4)},unsignedToSigned:function(t,e){var i=Math.pow(2,e)-1;return t&Math.pow(2,e-1)&&(t=-1*(i-t)),t},arrayToBytes:function(t,e,i){var s=t.length,n=i||s,o=null,h=[];switch(e){case 8:o=wdi.SpiceObject.numberTo8;break;case 16:o=wdi.SpiceObject.numberTo16;break;case 32:o=wdi.SpiceObject.numberTo32;break;case 64:o=wdi.SpiceObject.numberTo64;break;default:throw new Exception("Not supported number of bits",1)}for(var a=0;a<n;a++)a<=s?h=h.concat(o(t[a])):h.push(0);return h},stringToBytes:function(t){for(var e=[],i=0;i<t.length;i++){var s=t.charCodeAt(i);s<128?e.push(s):s<2048?e.push(192|s>>6,128|63&s):s<55296||s>=57344?e.push(224|s>>12,128|s>>6&63,128|63&s):(i++,s=65536+((1023&s)<<10|1023&t.charCodeAt(i)),e.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|63&s))}return e},arrayBufferToBytes:function(t){return new Uint8Array(t).toJSArray()},stringHexToBytes:function(t){for(var e=t.length,i=[],s=0;s<e;s+=2)i.push(parseInt(t[s]+t[s+1],16));return i},stringBinaryToBytes:function(t,e){t=t.lpad("0",e);for(var i=[],s=e;s>=8;s-=8)i=i.concat(parseInt(t.substr(s-8,8),2));return i},stringToBytesPadding:function(t,e){for(var i=[],s=t.length,n=0;n<e;n++)e>s-1?i.push(0):i.push(t.charCodeAt(n));return i},numberTo64:function(t){var e=this.numberTo32((0x10000000000000000&t)>>32);return this.numberTo32(4294967295&t).concat(e)},numberTo32:function(t){for(var e=new Array(3),i=0;i<4;i++)e[i]=255&t,t>>=8;return e},numberTo16:function(t){for(var e=new Array(1),i=0;i<2;i++)e[i]=255&t,t>>=8;return e},numberTo8:function(t){return[255&t]},getMessageProperties:function(){return this.properties},getMessageProperty:function(t,e){return this.properties.hasOwnProperty(t)?this.properties[t]:e}},wdi.SpiceDataHeader=$.spcExtend(wdi.SpiceObject,{objectSize:6,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.size=t.size},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.type),this.numberTo32(this.size)),this.rawData},demarshall:function(t){return this.type=this.bytesToInt16NoAllocate(t),this.size=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceCompatibility=$.spcExtend(wdi.SpiceObject,{init:function(t){t&&this.setContent(t)},setContent:function(t){this.channel_type=t.channel_type,this.caps=t.caps},marshall:function(){return this.rawData=[],this.rawData=[this.numberTo8(this.channel_type),...this.caps.map((t=>this.numberTo32(t)))],this.rawData},demarshall:function(t){}}),wdi.SpiceLinkAuthMechanism=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.auth_mechanism=t.auth_mechanism},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.auth_mechanism)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.auth_mechanism=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkReply=$.spcExtend(wdi.SpiceObject,{objectSize:178,init:function(t){t&&this.setContent(t)},setContent:function(t){this.error=t.error,this.pub_key=t.pub_key,this.num_common_caps=t.num_common_caps,this.num_channel_caps=t.num_channel_caps,this.caps_offset=t.caps_offset},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.error),this.arrayToBytes(this.pub_key,8),this.numberTo32(this.num_common_caps),this.numberTo32(this.num_channel_caps),this.numberTo32(this.caps_offset)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.error=this.bytesToInt32NoAllocate(t),this.pub_key=this.bytesToArray(t.shift(this.expectedSize),8),this.num_common_caps=this.bytesToInt32NoAllocate(t),this.num_channel_caps=this.bytesToInt32NoAllocate(t),this.caps_offset=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkEncryptedTicket=$.spcExtend(wdi.SpiceObject,{objectSize:128,init:function(t){t&&this.setContent(t)},setContent:function(t){this.encrypted_data=t.encrypted_data},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.stringToBytes(this.encrypted_data,8)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.encrypted_data=this.bytesToArray(t.shift(this.expectedSize),8),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkMess=$.spcExtend(wdi.SpiceObject,{objectSize:18,init:function(t){t&&this.setContent(t)},setContent:function(t){this.connection_id=t.connection_id,this.channel_type=t.channel_type,this.channel_id=t.channel_id,this.num_common_caps=t.num_common_caps,this.num_channel_caps=t.num_channel_caps,this.caps_offset=t.caps_offset,this.common_caps=t.common_caps,this.channel_caps=t.channel_caps},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.connection_id),this.numberTo8(this.channel_type),this.numberTo8(this.channel_id),this.numberTo32(this.num_common_caps),this.numberTo32(this.num_channel_caps),this.numberTo32(this.caps_offset)),this.num_common_caps>0&&(this.rawData=this.rawData.concat(this.numberTo32(this.common_caps))),this.num_channel_caps>0&&(this.rawData=this.rawData.concat(this.numberTo32(this.channel_caps))),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.connection_id=this.bytesToInt32NoAllocate(t),this.channel_type=this.bytesToInt8NoAllocate(t),this.channel_id=this.bytesToInt8NoAllocate(t),this.num_common_caps=this.bytesToInt32NoAllocate(t),this.num_channel_caps=this.bytesToInt32NoAllocate(t),this.caps_offset=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.SpiceLinkHeader=$.spcExtend(wdi.SpiceObject,{objectSize:16,init:function(t){t&&this.setContent(t)},setContent:function(t){this.magic=t.magic,this.major_version=t.major_version,this.minor_version=t.minor_version,this.size=t.size},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.magic),this.numberTo32(this.major_version),this.numberTo32(this.minor_version),this.numberTo32(this.size)),this.rawData},demarshall:function(t){if(this.expectedSize=arguments[1]||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.magic=this.bytesToInt32NoAllocate(t),this.major_version=this.bytesToInt32NoAllocate(t),this.minor_version=this.bytesToInt32NoAllocate(t),this.size=this.bytesToInt32NoAllocate(t),"customDemarshall"in this&&this.customDemarshall(t),this}}),wdi.RedMigrateData=$.spcExtend(wdi.SpiceObject,{objectSize:0,init:function(t){t&&this.setContent(t)},setContent:function(t){this.vector=t.vector},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.arrayToBytes(this.vector,8)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.vector=this.bytesToArray(t.shift(this.expectedSize),8),this}}),wdi.RedMainInit=$.spcExtend(wdi.SpiceObject,{objectSize:32,init:function(t){t&&this.setContent(t)},setContent:function(t){this.session_id=t.session_id,this.display_channels_hint=t.display_channels_hint,this.supported_mouse_modes=t.supported_mouse_modes,this.current_mouse_mode=t.current_mouse_mode,this.agent_connected=t.agent_connected,this.agent_tokens=t.agent_tokens,this.multi_media_time=t.multi_media_time,this.ram_hint=t.ram_hint},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.session_id),this.numberTo32(this.display_channels_hint),this.numberTo32(this.supported_mouse_modes),this.numberTo32(this.current_mouse_mode),this.numberTo32(this.agent_connected),this.numberTo32(this.agent_tokens),this.numberTo32(this.multi_media_time),this.numberTo32(this.ram_hint)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.session_id=this.bytesToInt32NoAllocate(t),this.display_channels_hint=this.bytesToInt32NoAllocate(t),this.supported_mouse_modes=this.bytesToInt32NoAllocate(t),this.current_mouse_mode=this.bytesToInt32NoAllocate(t),this.agent_connected=this.bytesToInt32NoAllocate(t),this.agent_tokens=this.bytesToInt32NoAllocate(t),this.multi_media_time=this.bytesToInt32NoAllocate(t),this.ram_hint=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMsgMainAgentConnected=$.spcExtend(wdi.SpiceObject,{objectSize:0,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.SpiceChannelsList=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_of_channels=t.num_of_channels,this.channels=t.channels},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_of_channels),this.arrayToBytes(this.channels,16)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.num_of_channels=this.bytesToInt32NoAllocate(t),this.channels=this.bytesToArray(t.shift(this.expectedSize),16),this}}),wdi.RedSetAck=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.generation=t.generation,this.window=t.window},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.generation),this.numberTo32(this.window)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.generation=this.bytesToInt32NoAllocate(t),this.window=this.bytesToInt32NoAllocate(t),this}}),wdi.RedPing=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.id=t.id,this.time=t.time},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.id),this.numberTo64(this.time)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.time=this.bytesToInt64NoAllocate(t),this.expectedSize>12&&t.shift(this.expectedSize-12),this}}),wdi.RedMigrate=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.flags=t.flags},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.flags)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.flags=this.bytesToInt32NoAllocate(t),this}}),wdi.RedWaitForChannel=$.spcExtend(wdi.SpiceObject,{objectSize:10,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.id=t.id,this.serial=t.serial},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.type),this.numberTo8(this.id),this.numberTo64(this.serial)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt8NoAllocate(t),this.id=this.bytesToInt8NoAllocate(t),this.serial=this.bytesToInt64NoAllocate(t),this}}),wdi.RedWaitForChannels=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){this.wait_count=t.wait_count,this.wait_list=t.wait_list},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.wait_count),this.arrayToBytes(this.wait_list,8)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.wait_count=this.bytesToInt8NoAllocate(t),this.wait_list=this.bytesToArray(t.shift(this.expectedSize),8),this}}),wdi.RedDisconnect=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.time_stamp=t.time_stamp,this.reason=t.reason},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo64(this.time_stamp),this.numberTo32(this.reason)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.time_stamp=this.bytesToInt64NoAllocate(t),this.reason=this.bytesToInt32NoAllocate(t),this}}),wdi.RedMigrationBegin=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.port=t.port,this.sport=t.sport,this.host_name=t.host_name},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.port),this.numberTo16(this.sport),this.arrayToBytes(this.host_name,8)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.port=this.bytesToInt16NoAllocate(t),this.sport=this.bytesToInt16NoAllocate(t),this.host_name=this.bytesToArray(t.shift(this.expectedSize),8),this}}),wdi.RedNotify=$.spcExtend(wdi.SpiceObject,{objectSize:25,init:function(t){t&&this.setContent(t)},setContent:function(t){this.time_stamp=t.time_stamp,this.severity=t.severity,this.visibility=t.visibility,this.what=t.what,this.message_len=t.message_len,this.message=t.message,this.zero=t.zero},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo64(this.time_stamp),this.numberTo32(this.severity),this.numberTo32(this.visibility),this.numberTo32(this.what),this.numberTo32(this.message_len),this.arrayToBytes(this.message,8),this.numberTo8(this.zero)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.time_stamp=this.bytesToInt64NoAllocate(t),this.severity=this.bytesToInt32NoAllocate(t),this.visibility=this.bytesToInt32NoAllocate(t),this.what=this.bytesToInt32NoAllocate(t),this.message_len=this.bytesToInt32NoAllocate(t),this.message=this.bytesToString(t.shift(this.message_len)),this.zero=this.bytesToInt8NoAllocate(t),this}}),wdi.RedMode=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.width=t.width,this.height=t.height,this.depth=t.depth},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.width),this.numberTo32(this.height),this.numberTo32(this.depth)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this.depth=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceCDisplayInit=$.spcExtend(wdi.SpiceObject,{objectSize:14,init:function(t){t&&this.setContent(t)},setContent:function(t){this.pixmap_cache_id=t.pixmap_cache_id,this.pixmap_cache_size=t.pixmap_cache_size,this.glz_dictionary_id=t.glz_dictionary_id,this.glz_dictionary_window_size=t.glz_dictionary_window_size},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.pixmap_cache_id),this.numberTo8(0),this.numberTo8(127),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(0),this.numberTo8(this.glz_dictionary_id),this.numberTo32(this.glz_dictionary_window_size)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.pixmap_cache_id=this.bytesToInt8NoAllocate(t),this.pixmap_cache_size=this.bytesToInt64NoAllocate(t),this.glz_dictionary_id=this.bytesToInt8NoAllocate(t),this.glz_dictionary_window_size=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceSurfaceDestroy=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.surface_id=t.surface_id},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.surface_id)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceSurface=$.spcExtend(wdi.SpiceObject,{objectSize:20,init:function(t){t&&this.setContent(t)},setContent:function(t){this.surface_id=t.surface_id,this.width=t.width,this.height=t.height,this.format=t.format,this.flags=t.flags},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.surface_id),this.numberTo32(this.width),this.numberTo32(this.height),this.numberTo32(this.format),this.numberTo32(this.flags)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this.format=this.bytesToInt32NoAllocate(t),this.flags=this.bytesToInt32NoAllocate(t),this}}),wdi.SpicePath=$.spcExtend(wdi.SpiceObject,{objectSize:4,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});var i=this.num_segments=this.bytesToInt32NoAllocate(t);this.segments=[];for(var s=0;s<i;s++)this.segments[s]=(new wdi.SpicePathSeg).demarshall(t);return this}}),wdi.SpicePathSeg=$.spcExtend(wdi.SpiceObject,{objectSize:8,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.flags=this.bytesToInt8NoAllocate(t);var i=this.count=this.bytesToInt32NoAllocate(t);this.points=[];for(var s=0;s<i;s++)this.points[s]=(new wdi.SpicePointFix).demarshall(t);return this}}),wdi.SpicePoint=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.unsignedToSigned(this.bytesToInt32(t.shift(4)),32),this.y=this.unsignedToSigned(this.bytesToInt32(t.shift(4)),32),this}}),wdi.SpicePoint16=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.x),this.numberTo16(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.bytesToInt16NoAllocate(t),this.y=this.bytesToInt16NoAllocate(t),this}}),wdi.SpicePointFix=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.hasOwnProperty("x")?t.x:0,this.y=t.hasOwnProperty("y")?t.y:0},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.int32ToDouble(this.bytesToInt32(t.shift(4)),32),this.y=this.int32ToDouble(this.bytesToInt32(t.shift(4)),32),this}}),wdi.SpiceRect=$.spcExtend(wdi.SpiceObject,{objectSize:16,init:function(t){t&&this.setContent(t)},setContent:function(t){this.top=t.top,this.left=t.left,this.bottom=t.bottom,this.right=t.right},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.top),this.numberTo32(this.left),this.numberTo32(this.bottom),this.numberTo32(this.right)),this.rawData},demarshall:function(t,e){return this.top=this.bytesToInt32NoAllocate(t),this.left=this.bytesToInt32NoAllocate(t),this.bottom=this.bytesToInt32NoAllocate(t),this.right=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceClipRects=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_rects=t.num_rects},marshall:function(){this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_rects));for(var t=0;t<this.num_rects;t++)this.rawData=this.rawData.concat(this.rects[t].marshall());return this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});if(this.num_rects=this.bytesToInt32NoAllocate(t),this.num_rects>0){this.rects=[];for(var i=0;i<this.num_rects;i++)this.rects[i]=(new wdi.SpiceRect).demarshall(t)}return this}}),wdi.SpiceClip=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.type)),this.type==wdi.SpiceClipType.SPICE_CLIP_TYPE_RECTS&&(this.rawData=this.rawData.concat(this.rects.marshall())),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt8NoAllocate(t),this.type==wdi.SpiceClipType.SPICE_CLIP_TYPE_RECTS&&(this.rects=(new wdi.SpiceClipRects).demarshall(t)),this}}),wdi.SpiceDisplayBase=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.surface_id=t.surface_id},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.surface_id),this.box.marshall(),this.clip.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.box=(new wdi.SpiceRect).demarshall(t),this.clip=(new wdi.SpiceClip).demarshall(t),this}}),wdi.SpiceQMask=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo8(this.flags),this.pos.marshall(),this.numberTo32(this.offset)),this.offset&&(t=t.concat(this.image.marshall())),t},demarshall:function(t,e){t.eatBytes(13)}}),wdi.SpiceImageDescriptor=$.spcExtend(wdi.SpiceObject,{objectSize:18,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo64(this.id),this.numberTo8(this.type),this.numberTo8(this.flags),this.numberTo32(this.width),this.numberTo32(this.height))},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});var i=this.bytesToInt32NoAllocate(t);return this.id=i.toString(16)+this.bytesToInt32NoAllocate(t).toString(16),this.type=this.bytesToInt8NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this.offset=t.getPosition(),this}}),wdi.SpiceImage=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.imageDescriptor.marshall(),this.data)},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.imageDescriptor=(new wdi.SpiceImageDescriptor).demarshall(t),this.data=t.getRawData(),this}}),wdi.SpiceDrawCopy=$.spcExtend(wdi.SpiceObject,{objectSize:4,properties:{overWriteScreenArea:!0},init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.base.marshall(),this.numberTo32(this.offset),this.src_area.marshall(),this.numberTo16(this.rop_descriptor),this.numberTo8(this.scale_mode),this.mask.marshall(),this.image.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});if(this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.rop_descriptor=this.bytesToInt16NoAllocate(t),this.scale_mode=this.bytesToInt8NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),t.getPosition()==this.offset)this.image=(new wdi.SpiceImage).demarshall(t);else{var i=new wdi.ViewQueue;i.setData(t.getDataOffset(this.offset)),this.image=(new wdi.SpiceImage).demarshall(i)}return this}}),wdi.drawBlend=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.base=t.base,this.alpha_flags=t.alpha_flags,this.alpha=t.alpha,this.offset=t.offset,this.src_area=t.src_area},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.numberTo32(this.offset),this.src_area.marshall(),this.numberTo16(this.rop_descriptor),this.numberTo8(this.flags),this.mask.marshall(),this.image.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.rop_descriptor=this.bytesToInt16NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this.image=(new wdi.SpiceImage).demarshall(t),this}}),wdi.drawAlphaBlend=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.base=t.base,this.alpha_flags=t.alpha_flags,this.alpha=t.alpha,this.offset=t.offset,this.src_area=t.src_area},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.alpha_flags=this.bytesToInt8NoAllocate(t),this.alpha=this.bytesToInt8NoAllocate(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.image=(new wdi.SpiceImage).demarshall(t),this}}),wdi.drawTransparent=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.transparent_color=(new wdi.SpiceColor).demarshall(t),this.transparent_true_color=(new wdi.SpiceColor).demarshall(t),this.image=(new wdi.SpiceImage).demarshall(t),this}}),wdi.SpiceCopyBits=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.src_position.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.src_position=(new wdi.SpicePoint).demarshall(t),this}}),wdi.SpiceImageLZRGB=$.spcExtend(wdi.SpiceObject,{objectSize:32,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.length=this.bytesToInt32BE(t.shift(4)),this.magic=this.bytesToStringBE(t.shift(4)),this.version=this.bytesToInt32BE(t.shift(4)),this.type=this.bytesToInt32BE(t.shift(4)),this.width=this.bytesToInt32BE(t.shift(4)),this.height=this.bytesToInt32BE(t.shift(4)),this.stride=this.bytesToInt32BE(t.shift(4)),this.top_down=this.bytesToInt32BE(t.shift(4)),this.data=t.shift(this.length),this}}),wdi.SpiceMouseModeRequest=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.request_mode=t.request_mode},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.request_mode)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.request_mode=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMouseMode=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.supported_modes=t.supported_modes,this.current_mode=t.current_mode},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.supported_modes),this.numberTo32(this.current_mode)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,!(t.getLength()<this.expectedSize))return this.supported_modes=this.bytesToInt16NoAllocate(t),this.current_mode=this.bytesToInt16NoAllocate(t),this}}),wdi.RedcMousePress=$.spcExtend(wdi.SpiceObject,{objectSize:3,init:function(t){t&&this.setContent(t)},setContent:function(t){this.button_id=t.button_id,this.buttons_state=t.buttons_state},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo8(this.button_id),this.numberTo16(this.buttons_state)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.button_id=this.bytesToInt8NoAllocate(t),this.buttons_state=this.bytesToInt16NoAllocate(t),this}}),wdi.RedcMousePosition=$.spcExtend(wdi.SpiceObject,{objectSize:11,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y,this.buttons_state=t.buttons_state,this.display_id=t.display_id},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y),this.numberTo16(this.buttons_state),this.numberTo8(this.display_id)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.bytesToInt32NoAllocate(t),this.y=this.bytesToInt32NoAllocate(t),this.buttons_state=this.bytesToInt16NoAllocate(t),this.display_id=this.bytesToInt8NoAllocate(t),this}}),wdi.RedcMouseMotion=$.spcExtend(wdi.SpiceObject,{objectSize:10,init:function(t){t&&this.setContent(t)},setContent:function(t){this.x=t.x,this.y=t.y,this.buttons_state=t.buttons_state},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.x),this.numberTo32(this.y),this.numberTo16(this.buttons_state)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.x=this.bytesToInt32NoAllocate(t),this.y=this.bytesToInt32NoAllocate(t),this.buttons_state=this.bytesToInt16NoAllocate(t),this}}),wdi.SpiceBrush=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.color=t.color},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt8NoAllocate(t),this.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN?this.pattern=(new wdi.SpicePattern).demarshall(t):this.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_SOLID&&(this.color=(new wdi.SpiceColor).demarshall(t)),this}}),wdi.SpiceColor=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){return[this.r,this.g,this.b]},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.data=16777215&this.bytesToInt32(t.shift(4)),this.r=this.data>>16,this.g=this.data>>8&255,this.b=255&this.data,this.html_color="rgb("+this.r+", "+this.g+", "+this.b+")";var i=this.r.toString(16),s=this.g.toString(16),n=this.b.toString(16);return i.length<2&&(i="0"+i),s.length<2&&(s="0"+s),n.length<2&&(n="0"+n),this.simple_html_color="#"+i+s+n,this}}),wdi.RgbaColor=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.data=4294967295&this.bytesToInt32(t.shift(4)),this.a=this.data>>>24,this.r=this.data>>>16&255,this.g=this.data>>>8&255,this.b=255&this.data,this.html_color="rgb("+this.r+", "+this.g+", "+this.b+")",this}}),wdi.SpicePattern=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.offset=this.bytesToInt32NoAllocate(t),this.point=(new wdi.SpicePoint).demarshall(t);var i=new wdi.ViewQueue;return i.setData(t.getDataOffset(this.offset)),this.image=(new wdi.SpiceImage).demarshall(i),this}}),wdi.SpiceDrawFill=$.spcExtend(wdi.SpiceObject,{objectSize:4,properties:{overWriteScreenArea:!0},init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.offset)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.brush=(new wdi.SpiceBrush).demarshall(t),this.rop_descriptor=this.bytesToInt16NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this.brush.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN&&(this.brush.pattern.image=(new wdi.SpiceImageDescriptor).demarshall(t),this.brush.pattern.imageData=t.getData()),this}}),wdi.SpiceDrawRop3=$.spcExtend(wdi.SpiceObject,{objectSize:4,marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.numberTo32(this.offset),this.src_area.marshall(),this.brush.marshall(),this.numberTo8(this.rop_descriptor),this.numberTo8(this.scale_mode),this.mask.marshall(),this.src_image.marshall()),this.brush.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN&&(t=t.concat(this.brush.pattern.image.marshall(),this.brush.pattern.imageData)),t},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.src_area=(new wdi.SpiceRect).demarshall(t),this.brush=(new wdi.SpiceBrush).demarshall(t),this.rop_descriptor=this.bytesToInt8NoAllocate(t),this.scale_mode=this.bytesToInt8NoAllocate(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this.src_image=(new wdi.SpiceImage).demarshall(t),this.brush.type==wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN&&(this.brush.pattern.image=(new wdi.SpiceImageDescriptor).demarshall(t),this.brush.pattern.imageData=t.getData()),this}}),wdi.SpiceDrawBlackness=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.mask.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this}}),wdi.SpiceDrawWhiteness=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.offset=t.offset},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.mask.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this}}),wdi.SpiceScanCode=$.spcExtend(wdi.SpiceObject,{objectSize:1,init:function(t){t&&this.setContent(t)},setContent:function(t){this.code=t||0,this.zero=0},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.arrayToBytes(this.code,8),this.numberTo8(this.zero)),this.rawData},demarshall:function(t,e){return this},getCode:function(){return this.code}}),wdi.RedCursorInit=$.spcExtend(wdi.SpiceObject,{objectSize:9,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.position=(new wdi.SpicePoint16).demarshall(t),this.trail_length=this.bytesToInt16NoAllocate(t),this.trail_frequency=this.bytesToInt16NoAllocate(t),this.visible=this.bytesToInt8NoAllocate(t),this.cursor=(new wdi.RedCursor).demarshall(t),this}}),wdi.RedCursor=$.spcExtend(wdi.SpiceObject,{objectSize:2,marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo16(this.flags)),1&this.flags||(this.rawData=this.rawData.concat(this.header.marshall(),this.data)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.flags=this.bytesToInt16NoAllocate(t),this.header=null,this.data=null,1&this.flags||(this.header=(new wdi.RedCursorHeader).demarshall(t),this.data=t.getData()),this}}),wdi.RedCursorHeader=$.spcExtend(wdi.SpiceObject,{objectSize:17,marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo64(this.unique),this.numberTo8(this.type),this.numberTo16(this.width),this.numberTo16(this.height),this.numberTo16(this.hot_spot_x),this.numberTo16(this.hot_spot_y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.unique=this.bytesToInt64NoAllocate(t),this.type=this.bytesToInt8NoAllocate(t),this.width=this.bytesToInt16NoAllocate(t),this.height=this.bytesToInt16NoAllocate(t),this.hot_spot_x=this.bytesToInt16NoAllocate(t),this.hot_spot_y=this.bytesToInt16NoAllocate(t),this}}),wdi.RedCursorSet=$.spcExtend(wdi.SpiceObject,{objectSize:5,marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.position.marshall(),this.numberTo8(this.visible),this.cursor.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.position=(new wdi.SpicePoint16).demarshall(t),this.visible=this.bytesToInt8NoAllocate(t),this.cursor=(new wdi.RedCursor).demarshall(t),this}}),wdi.RedCursorHide=$.spcExtend(wdi.SpiceObject,{objectSize:5,marshall:function(){},demarshall:function(){return this}}),wdi.RasterGlyph=$.spcExtend(wdi.SpiceObject,{objectSize:20,marshall:function(){},demarshall:function(t,e,i){for(var s=1==e?1:2*e,n=[],o=0;o<i;o++)n[o]={},n[o].render_pos=(new wdi.SpicePoint).demarshall(t),n[o].glyph_origin=(new wdi.SpicePoint).demarshall(t),n[o].width=this.bytesToInt16NoAllocate(t),n[o].height=this.bytesToInt16NoAllocate(t),n[o].data=t.shift(n[o].height*Math.ceil(n[o].width*s/8));return n}}),wdi.GlyphString=$.spcExtend(wdi.SpiceObject,{objectSize:3,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.len=this.bytesToInt16NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.raster_glyph=(new wdi.RasterGlyph).demarshall(t,this.flags,this.len),this}}),wdi.SpiceDrawText=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.back_area=(new wdi.SpiceRect).demarshall(t),this.fore_brush=(new wdi.SpiceBrush).demarshall(t),this.back_brush=(new wdi.SpiceBrush).demarshall(t),this.fore_mode=this.bytesToInt16NoAllocate(t),this.back_mode=this.bytesToInt16NoAllocate(t),this.glyph_string=(new wdi.GlyphString).demarshall(t),this}}),wdi.SpiceLineAttr=$.spcExtend(wdi.SpiceObject,{objectSize:8,marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.flags=this.bytesToInt8NoAllocate(t),this.flags&&(this.style_nseg=this.bytesToInt8NoAllocate(t),this.style=this.int32ToDouble(this.bytesToInt32(t.shift(4)))),this}}),wdi.SpiceStroke=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.offset=this.bytesToInt32NoAllocate(t),this.attr=(new wdi.SpiceLineAttr).demarshall(t),this.brush=(new wdi.SpiceBrush).demarshall(t),this.fore_mode=this.bytesToInt16NoAllocate(t),this.back_mode=this.bytesToInt16NoAllocate(t),this.path=(new wdi.SpicePath).demarshall(t),this}}),wdi.SpiceDrawInvers=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.base.marshall(),this.mask.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.base=(new wdi.SpiceDisplayBase).demarshall(t),this.mask=(new wdi.SpiceQMask).demarshall(t),this}}),wdi.SpiceStreamCreate=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t.concat(this.numberTo32(this.surface_id),this.numberTo32(this.id),this.numberTo8(this.flags),this.numberTo8(this.codec),this.numberTo64(this.stamp),this.numberTo32(this.stream_width),this.numberTo32(this.stream_height),this.numberTo32(this.src_width),this.numberTo32(this.src_height),this.rect.marshall(),this.clip.marshall()),t},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.id=this.bytesToInt32NoAllocate(t),this.flags=this.bytesToInt8NoAllocate(t),this.codec=this.bytesToInt8NoAllocate(t),this.stamp=this.bytesToInt64NoAllocate(t),this.stream_width=this.bytesToInt32NoAllocate(t),this.stream_height=this.bytesToInt32NoAllocate(t),this.src_width=this.bytesToInt32NoAllocate(t),this.src_height=this.bytesToInt32NoAllocate(t),this.rect=(new wdi.SpiceRect).demarshall(t),this.clip=(new wdi.SpiceClip).demarshall(t),this}}),wdi.SpiceStreamDestroy=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.surface_id),this.numberTo32(this.id))},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.surface_id=this.bytesToInt32NoAllocate(t),this.id=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceStreamData=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.id),this.numberTo32(this.multi_media_type),this.numberTo32(this.data_size),this.data)},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.multi_media_type=this.bytesToInt32NoAllocate(t),this.data_size=this.bytesToInt32NoAllocate(t),this.data=t.getRawData(),this}}),wdi.SpiceStreamClip=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.id),this.clip.marshall())},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.clip=(new wdi.SpiceClip).demarshall(t),this}}),wdi.SpiceStreamDataSized=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){var t=[];return t=t.concat(this.numberTo32(this.id),this.numberTo32(this.width),this.numberTo32(this.height))},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.id=this.bytesToInt32NoAllocate(t),this.width=this.bytesToInt32NoAllocate(t),this.height=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceStreamActiveReport=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){},demarshall:function(t,e){}}),wdi.SpiceModifierData=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){},setModifierData:function(t){6===t?(wdi.Keymap.capsLock=!0,wdi.Keymap.numLock=!0):4===t?(wdi.Keymap.capsLock=!0,wdi.Keymap.numLock=!1):2===t?(wdi.Keymap.capsLock=!1,wdi.Keymap.numLock=!0):0===t&&(wdi.Keymap.capsLock=!1,wdi.Keymap.numLock=!1)},marshall:function(){var t=[];return t=t.concat(this.numberTo16(this.data))},demarshall:function(t,e){return this.expectedSize=e||this.objectSize,this.data=this.bytesToInt16NoAllocate(t),this}}),wdi.SpiceResourceList=$.spcExtend(wdi.SpiceObject,{objectSize:2,init:function(t){t&&this.setContent(t)},setContent:function(t){},marshall:function(){for(var t=[],e=0;e<this.num_items;e++)t=t.concat(this.numberTo8(this.items[e].type),this.numberTo64(this.items[e].id));return t},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.num_items=this.bytesToInt16NoAllocate(t),this.items=[];for(var i=0;i<this.num_items;i++)this.items[i]={type:this.bytesToInt8(t.shift(1)),id:this.bytesToInt64(t.shift(8))};return this}}),wdi.SpiceMsgMainAgentTokens=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_tokens=t.num_tokens},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_tokens)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.num_tokens=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMsgMainAgentDisconnected=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.error=t.error},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.error)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.error=this.bytesToInt32NoAllocate(t),this}}),wdi.SpiceMsgMainAgentData=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.agentMessage=t.agentMessage},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.agentMessage.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.agentMessage=(new wdi.VDAgentMessage).demarshall(t),this}}),wdi.VDIChunkHeader=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.port=t.port,this.size=t.size,this.packet=t.packet},marshall:function(){this.rawData=[];var t=this.packet.marshall();return this.rawData=this.rawData.concat(this.numberTo32(this.port),this.numberTo32(t.length),t),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMessage=$.spcExtend(wdi.SpiceObject,{objectSize:20,init:function(t){t&&this.setContent(t)},setContent:function(t){this.protocol=t.protocol,this.type=t.type,this.opaque=t.opaque,this.size=t.size,this.data=t.data},marshall:function(){this.rawData=[];var t=this.data.marshall();return this.rawData=this.rawData.concat(this.numberTo32(this.protocol),this.numberTo32(this.type),this.numberTo64(this.opaque),this.numberTo32(t.length),t),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});if(this.protocol=this.bytesToInt32NoAllocate(t),this.type=this.bytesToInt32NoAllocate(t),this.opaque=this.bytesToInt64NoAllocate(t),this.size=this.bytesToInt32NoAllocate(t),this.type==wdi.AgentMessageTypes.VD_AGENT_GET_WINDOWS_LIST){var i=this.bytesToString(t.shift(t.length));this.window_list="change"==i?i:jQuery.parseJSON(i)}else this.type==wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES?this.caps=(new wdi.VDAgentAnnounceCapabilities).demarshall(t):this.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB?0==t.getLength()?this.clipboardType=wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_NONE:this.clipboardType=this.bytesToInt32NoAllocate(t):this.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST?this.clipboardType=this.bytesToInt32NoAllocate(t):this.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD&&(this.clipboardType=this.bytesToInt32NoAllocate(t),this.clipboardData=this.bytesToString(t.shift(t.length)));return this}}),wdi.VDAgentHwndWindow=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.hwnd=t.hwnd},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.hwnd)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMoveWindow=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.hwnd=t.hwnd,this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.hwnd),this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentResizeWindow=$.spcExtend(wdi.SpiceObject,{objectSize:12,init:function(t){t&&this.setContent(t)},setContent:function(t){this.hwnd=t.hwnd,this.width=t.width,this.height=t.height},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.hwnd),this.numberTo32(this.width),this.numberTo32(this.height)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMonitorsConfig=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_of_monitors=t.num_of_monitors,this.flags=t.flags,this.data=t.data},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.num_of_monitors),this.numberTo32(this.flags),this.data.marshall()),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentMonConfig=$.spcExtend(wdi.SpiceObject,{objectSize:20,init:function(t){t&&this.setContent(t)},setContent:function(t){this.height=t.height,this.width=t.width,this.depth=t.depth,this.x=t.x,this.y=t.y},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.height),this.numberTo32(this.width),this.numberTo32(this.depth),this.numberTo32(this.x),this.numberTo32(this.y)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentAnnounceCapabilities=$.spcExtend(wdi.SpiceObject,{objectSize:8,init:function(t){t&&this.setContent(t)},setContent:function(t){this.request=t.request,this.caps=t.caps},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.request),this.numberTo32(this.caps)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.request=this.bytesToInt32NoAllocate(t),this.caps=this.bytesToInt32NoAllocate(t),this}}),wdi.VDAgentExecuteCommand=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.size=t.size,this.data=t.data},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.size),this.stringToBytes(this.data)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.VDAgentClipboardRequest=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.type)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt32NoAllocate(t),this}}),wdi.VDAgentClipboardGrab=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.types=t.types},marshall:function(){return this.rawData=[],this.rawData=this.rawData.concat(this.numberTo32(this.types)),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.types=this.bytesToInt32NoAllocate(t),this}}),wdi.VDAgentClipboard=$.spcExtend(wdi.SpiceObject,{objectSize:6,init:function(t){t&&this.setContent(t)},setContent:function(t){this.type=t.type,this.data=t.data},marshall:function(){var t;return this.rawData=[],t=this.type===wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT?this.stringToBytes(this.data):this.arrayBufferToBytes(this.data),this.rawData=this.rawData.concat(this.numberTo32(this.type),t),this.rawData},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.type=this.bytesToInt32NoAllocate(t),this.data=t.getData(),this}}),wdi.PlaybackMode=$.spcExtend(wdi.SpiceObject,{objectSize:6,init:function(t){t&&this.setContent(t)},setContent:function(t){this.multimedia_time=t.multimedia_time,this.audio_data_mode=t.audio_data_mode,this.data=t.data},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.multimedia_time=this.bytesToInt32NoAllocate(t),this.audio_data_mode=this.bytesToInt16NoAllocate(t),this.data=t.getData(),this}}),wdi.PlaybackStart=$.spcExtend(wdi.SpiceObject,{objectSize:14,init:function(t){t&&this.setContent(t)},setContent:function(t){this.channels=t.channels,this.format=t.format,this.frequency=t.frequency,this.time=t.time},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.channels=this.bytesToInt32NoAllocate(t),this.format=this.bytesToInt16NoAllocate(t),this.frequency=this.bytesToInt32NoAllocate(t),this.time=this.bytesToInt32NoAllocate(t),this}}),wdi.PlaybackData=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.multimedia_time=t.multimedia_time,this.data=t.data},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.multimedia_time=this.bytesToInt32NoAllocate(t),this.data=t.getData(),this}}),wdi.MainMultiMediaTime=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.multimedia_time=t.multimedia_time},marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.multimedia_time=this.bytesToInt32NoAllocate(t),this}}),wdi.PlaybackStop=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.MainMChannelsList=$.spcExtend(wdi.SpiceObject,{objectSize:4,init:function(t){t&&this.setContent(t)},setContent:function(t){this.num_of_channels=t.num_of_channels},marshall:function(){},demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});this.num_of_channels=this.bytesToInt32NoAllocate(t),this.channels=[];for(var i=null,s=0;s<this.num_of_channels;s++)i=this.bytesToInt8NoAllocate(t),this.bytesToInt8NoAllocate(t),this.channels.push(i);return this}}),wdi.SpiceDisplayInvalidAllPalettes=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.SpiceDisplayMark=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.SpiceDisplayReset=$.spcExtend(wdi.SpiceObject,{objectSize:0,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this}}),wdi.CodecConfig=$.spcExtend(wdi.SpiceObject,{objectSize:4,demarshall:function(t,e){if(this.expectedSize=e||this.objectSize,t.getLength()<this.expectedSize)throw new wdi.Exception({message:"Not enough queue to read",errorCode:3});return this.encodePoint=this.bytesToInt8NoAllocate(t),this.encodeDevice=this.bytesToInt8NoAllocate(t),this.codec=this.bytesToInt8NoAllocate(t),this.pixelFormat=this.bytesToInt8NoAllocate(t),this}});wdi.SpicePubkeyType={SPICE_PUBKEY_TYPE_INVALID:0,SPICE_PUBKEY_TYPE_RSA:1,SPICE_PUBKEY_TYPE_RSA2:2,SPICE_PUBKEY_TYPE_DSA:3,SPICE_PUBKEY_TYPE_DSA1:4,SPICE_PUBKEY_TYPE_DSA2:5,SPICE_PUBKEY_TYPE_DSA3:6,SPICE_PUBKEY_TYPE_DSA4:7,SPICE_PUBKEY_TYPE_DH:8,SPICE_PUBKEY_TYPE_EC:9,SPICE_PUBKEY_TYPE_ENUM_END:10},wdi.SpiceWarnCode={SPICE_WARN_GENERAL:0,SPICE_WARN_CODE_ENUM_END:1},wdi.SpiceLineFlags={SPICE_LINE_FLAGS_START_WITH_GAP:4,SPICE_LINE_FLAGS_STYLED:8,SPICE_LINE_FLAGS_MASK:12},wdi.SpiceNotifyVisibility={SPICE_NOTIFY_VISIBILITY_LOW:0,SPICE_NOTIFY_VISIBILITY_MEDIUM:1,SPICE_NOTIFY_VISIBILITY_HIGH:2,SPICE_NOTIFY_VISIBILITY_ENUM_END:3},wdi.SpiceVars={SPICE_MSGC_ACK_SYNC:1,SPICE_MSGC_ACK:2,SPICE_MSGC_PONG:3,SPICE_MSGC_MIGRATE_FLUSH_MARK:4,SPICE_MSGC_MIGRATE_DATA:5,SPICE_MSGC_DISCONNECTING:6,SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE:105,SPICE_MSGC_DISPLAY_INIT:101,SPICE_MSGC_END_DISPLAY:102,SPICE_CHANNEL_MAIN:1,SPICE_CHANNEL_DISPLAY:2,SPICE_CHANNEL_INPUTS:3,SPICE_CHANNEL_CURSOR:4,SPICE_CHANNEL_PLAYBACK:5,SPICE_CHANNEL_RECORD:6,SPICE_CHANNEL_TUNNEL:7,SPICE_CHANNEL_SMARTCARD:8,SPICE_CHANNEL_USBREDIR:9,SPICE_END_CHANNEL:10,SPICE_MSG_MIGRATE:1,SPICE_MSG_MIGRATE_DATA:2,SPICE_MSG_SET_ACK:3,SPICE_MSG_PING:4,SPICE_MSG_WAIT_FOR_CHANNELS:5,SPICE_MSG_DISCONNECTING:6,SPICE_MSG_NOTIFY:7,SPICE_MSG_LIST:8,SPICE_MSGC_MAIN_CLIENT_INFO:101,SPICE_MSGC_MAIN_MIGRATE_CONNECTED:102,SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR:103,SPICE_MSGC_MAIN_ATTACH_CHANNELS:104,SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST:105,SPICE_MSGC_MAIN_AGENT_START:106,SPICE_MSGC_MAIN_AGENT_DATA:107,SPICE_MSGC_MAIN_AGENT_TOKEN:108,SPICE_MSGC_MAIN_MIGRATE_END:109,SPICE_MSGC_END_MAIN:110,SPICE_MSG_DISPLAY_MODE:101,SPICE_MSG_DISPLAY_MARK:102,SPICE_MSG_DISPLAY_RESET:103,SPICE_MSG_DISPLAY_COPY_BITS:104,SPICE_MSG_DISPLAY_INVAL_LIST:105,SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS:106,SPICE_MSG_DISPLAY_INVAL_PALETTE:107,SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES:108,SPICE_MSG_DISPLAY_STREAM_CREATE:122,SPICE_MSG_DISPLAY_STREAM_DATA:123,SPICE_MSG_DISPLAY_STREAM_CLIP:124,SPICE_MSG_DISPLAY_STREAM_DESTROY:125,SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL:126,SPICE_MSG_DISPLAY_CURRENT_VIDEO_ENCODE_SETUP_RESPONSE:131,SPICE_MSG_DISPLAY_STREAM_DATA_SIZED:316,SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT:319,SPICE_MSG_DISPLAY_DRAW_FILL:302,SPICE_MSG_DISPLAY_DRAW_OPAQUE:303,SPICE_MSG_DISPLAY_DRAW_COPY:304,SPICE_MSG_DISPLAY_DRAW_BLEND:305,SPICE_MSG_DISPLAY_DRAW_BLACKNESS:306,SPICE_MSG_DISPLAY_DRAW_WHITENESS:307,SPICE_MSG_DISPLAY_DRAW_INVERS:308,SPICE_MSG_DISPLAY_DRAW_ROP3:309,SPICE_MSG_DISPLAY_DRAW_STROKE:310,SPICE_MSG_DISPLAY_DRAW_TEXT:311,SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:312,SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:313,SPICE_MSG_DISPLAY_SURFACE_CREATE:314,SPICE_MSG_DISPLAY_SURFACE_DESTROY:315,SPICE_MSG_END_DISPLAY:316,SPICE_MSG_INPUTS_INIT:101,SPICE_MSG_INPUTS_KEY_MODIFIERS:102,SPICE_MSG_INPUTS_MOUSE_MOTION_ACK:111,SPICE_MSG_END_INPUTS:112,SPICE_MSGC_INPUTS_KEY_DOWN:101,SPICE_MSGC_INPUTS_KEY_UP:102,SPICE_MSGC_INPUTS_KEY_MODIFIERS:103,SPICE_MSGC_INPUTS_MOUSE_MOTION:111,SPICE_MSGC_INPUTS_MOUSE_POSITION:112,SPICE_MSGC_INPUTS_MOUSE_PRESS:113,SPICE_MSGC_INPUTS_MOUSE_RELEASE:114,SPICE_MSGC_END_INPUTS:115,SPICE_MSG_CURSOR_INIT:101,SPICE_MSG_CURSOR_RESET:102,SPICE_MSG_CURSOR_SET:103,SPICE_MSG_CURSOR_MOVE:104,SPICE_MSG_CURSOR_HIDE:105,SPICE_MSG_CURSOR_TRAIL:106,SPICE_MSG_CURSOR_INVAL_ONE:107,SPICE_MSG_CURSOR_INVAL_ALL:108,SPICE_MSG_END_CURSOR:109,SPICE_MSG_RECORD_START:101,SPICE_MSG_RECORD_STOP:102,SPICE_MSG_RECORD_VOLUME:103,SPICE_MSG_RECORD_MUTE:104,SPICE_MSG_END_RECORD:105,SPICE_MSGC_SMARTCARD_DATA:101,SPICE_MSGC_END_SMARTCARD:102,SPICE_MSGC_SPICEVMC_DATA:101,SPICE_MSGC_END_SPICEVMC:102,SPICE_MSG_MAIN_MIGRATE_BEGIN:101,SPICE_MSG_MAIN_MIGRATE_CANCEL:102,SPICE_MSG_MAIN_INIT:103,SPICE_MSG_MAIN_CHANNELS_LIST:104,SPICE_MSG_MAIN_MOUSE_MODE:105,SPICE_MSG_MAIN_MULTI_MEDIA_TIME:106,SPICE_MSG_MAIN_AGENT_CONNECTED:107,SPICE_MSG_MAIN_AGENT_DISCONNECTED:108,SPICE_MSG_MAIN_AGENT_DATA:109,SPICE_MSG_MAIN_AGENT_TOKEN:110,SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST:111,SPICE_MSG_MAIN_MIGRATE_END:112,SPICE_MSG_END_MAIN:113,SPICE_MSG_PLAYBACK_DATA:101,SPICE_MSG_PLAYBACK_MODE:102,SPICE_MSG_PLAYBACK_START:103,SPICE_MSG_PLAYBACK_STOP:104,SPICE_MSG_PLAYBACK_VOLUME:105,SPICE_MSG_PLAYBACK_MUTE:106,SPICE_MSG_END_PLAYBACK:107,SPICE_MSGC_RECORD_DATA:101,SPICE_MSGC_RECORD_MODE:102,SPICE_MSGC_RECORD_START_MARK:103,SPICE_MSGC_END_RECORD:104,SPICE_MSG_TUNNEL_INIT:101,SPICE_MSG_TUNNEL_SERVICE_IP_MAP:102,SPICE_MSG_TUNNEL_SOCKET_OPEN:103,SPICE_MSG_TUNNEL_SOCKET_FIN:104,SPICE_MSG_TUNNEL_SOCKET_CLOSE:105,SPICE_MSG_TUNNEL_SOCKET_DATA:106,SPICE_MSG_TUNNEL_SOCKET_CLOSED_ACK:107,SPICE_MSG_TUNNEL_SOCKET_TOKEN:108,SPICE_MSG_END_TUNNEL:109,SPICE_MSGC_TUNNEL_SERVICE_ADD:101,SPICE_MSGC_TUNNEL_SERVICE_REMOVE:102,SPICE_MSGC_TUNNEL_SOCKET_OPEN_ACK:103,SPICE_MSGC_TUNNEL_SOCKET_OPEN_NACK:104,SPICE_MSGC_TUNNEL_SOCKET_FIN:105,SPICE_MSGC_TUNNEL_SOCKET_CLOSED:106,SPICE_MSGC_TUNNEL_SOCKET_CLOSED_ACK:107,SPICE_MSGC_TUNNEL_SOCKET_DATA:108,SPICE_MSGC_TUNNEL_SOCKET_TOKEN:109,SPICE_MSGC_END_TUNNEL:110,SPICE_MSG_SMARTCARD_DATA:101,SPICE_MSG_END_SMARTCARD:102,SPICE_MSG_SPICEVMC_DATA:101,SPICE_MSG_END_SPICEVMC:102,SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION:0,SPICE_COMMON_CAP_AUTH_SPICE:1,SPICE_COMMON_CAP_AUTH_SASL:2,SPICE_COMMON_CAP_MINI_HEADER:3,SPICE_PLAYBACK_CAP_CELT_0_5_1:0,SPICE_PLAYBACK_CAP_VOLUME:1,SPICE_RECORD_CAP_CELT_0_5_1:0,SPICE_RECORD_CAP_VOLUME:1,SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE:0},wdi.SpiceTunnelServiceType={SPICE_TUNNEL_SERVICE_TYPE_INVALID:0,SPICE_TUNNEL_SERVICE_TYPE_GENERIC:1,SPICE_TUNNEL_SERVICE_TYPE_IPP:2,SPICE_TUNNEL_SERVICE_TYPE_ENUM_END:3},wdi.SpiceJpegAlphaFlags={SPICE_JPEG_ALPHA_FLAGS_TOP_DOWN:1,SPICE_JPEG_ALPHA_FLAGS_MASK:1},wdi.SpiceMaskFlags={SPICE_MASK_FLAGS_INVERS:1,SPICE_MASK_FLAGS_MASK:1},wdi.SpiceCursorType={SPICE_CURSOR_TYPE_ALPHA:0,SPICE_CURSOR_TYPE_MONO:1,SPICE_CURSOR_TYPE_COLOR4:2,SPICE_CURSOR_TYPE_COLOR8:3,SPICE_CURSOR_TYPE_COLOR16:4,SPICE_CURSOR_TYPE_COLOR24:5,SPICE_CURSOR_TYPE_COLOR32:6,SPICE_CURSOR_TYPE_ENUM_END:7,SPICE_CURSOR_TYPE_URL:8},wdi.SpiceImageFlags={SPICE_IMAGE_FLAGS_CACHE_ME:1,SPICE_IMAGE_FLAGS_HIGH_BITS_SET:2,SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME:4,SPICE_IMAGE_FLAGS_MASK:7},wdi.SpiceAudioDataMode={SPICE_AUDIO_DATA_MODE_INVALID:0,SPICE_AUDIO_DATA_MODE_RAW:1,SPICE_AUDIO_DATA_MODE_CELT_0_5_1:2,SPICE_AUDIO_DATA_MODE_ENUM_END:3},wdi.SpiceAudioFmt={SPICE_AUDIO_FMT_INVALID:0,SPICE_AUDIO_FMT_S16:1,SPICE_AUDIO_FMT_ENUM_END:2},wdi.SpiceBitmapFmt={SPICE_BITMAP_FMT_INVALID:0,SPICE_BITMAP_FMT_1BIT_LE:1,SPICE_BITMAP_FMT_1BIT_BE:2,SPICE_BITMAP_FMT_4BIT_LE:3,SPICE_BITMAP_FMT_4BIT_BE:4,SPICE_BITMAP_FMT_8BIT:5,SPICE_BITMAP_FMT_16BIT:6,SPICE_BITMAP_FMT_24BIT:7,SPICE_BITMAP_FMT_32BIT:8,SPICE_BITMAP_FMT_RGBA:9,SPICE_BITMAP_FMT_ENUM_END:10},wdi.SpiceStreamFlags={SPICE_STREAM_FLAGS_TOP_DOWN:1,SPICE_STREAM_FLAGS_MASK:1},wdi.SpiceTunnelIpType={SPICE_TUNNEL_IP_TYPE_INVALID:0,SPICE_TUNNEL_IP_TYPE_IPv4:1,SPICE_TUNNEL_IP_TYPE_ENUM_END:2},wdi.SpiceBitmapFlags={SPICE_BITMAP_FLAGS_PAL_CACHE_ME:1,SPICE_BITMAP_FLAGS_PAL_FROM_CACHE:2,SPICE_BITMAP_FLAGS_TOP_DOWN:4,SPICE_BITMAP_FLAGS_MASK:7},wdi.SpiceStringFlags={SPICE_STRING_FLAGS_RASTER_A1:1,SPICE_STRING_FLAGS_RASTER_A4:2,SPICE_STRING_FLAGS_RASTER_A8:4,SPICE_STRING_FLAGS_RASTER_TOP_DOWN:8,SPICE_STRING_FLAGS_MASK:15},wdi.SpiceSurfaceFmt={SPICE_SURFACE_FMT_INVALID:0,SPICE_SURFACE_FMT_1_A:1,SPICE_SURFACE_FMT_8_A:8,SPICE_SURFACE_FMT_16_555:16,SPICE_SURFACE_FMT_32_xRGB:32,SPICE_SURFACE_FMT_16_565:80,SPICE_SURFACE_FMT_32_ARGB:96,SPICE_SURFACE_FMT_ENUM_END:97},wdi.SpiceCursorFlags={SPICE_CURSOR_FLAGS_NONE:1,SPICE_CURSOR_FLAGS_CACHE_ME:2,SPICE_CURSOR_FLAGS_FROM_CACHE:4,SPICE_CURSOR_FLAGS_MASK:7},wdi.SpiceLinkErr={SPICE_LINK_ERR_OK:0,SPICE_LINK_ERR_ERROR:1,SPICE_LINK_ERR_INVALID_MAGIC:2,SPICE_LINK_ERR_INVALID_DATA:3,SPICE_LINK_ERR_VERSION_MISMATCH:4,SPICE_LINK_ERR_NEED_SECURED:5,SPICE_LINK_ERR_NEED_UNSECURED:6,SPICE_LINK_ERR_PERMISSION_DENIED:7,SPICE_LINK_ERR_BAD_CONNECTION_ID:8,SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE:9,SPICE_LINK_ERR_ENUM_END:10},wdi.SpiceNotifySeverity={SPICE_NOTIFY_SEVERITY_INFO:0,SPICE_NOTIFY_SEVERITY_WARN:1,SPICE_NOTIFY_SEVERITY_ERROR:2,SPICE_NOTIFY_SEVERITY_ENUM_END:3},wdi.SpiceBrushType={SPICE_BRUSH_TYPE_NONE:0,SPICE_BRUSH_TYPE_SOLID:1,SPICE_BRUSH_TYPE_PATTERN:2,SPICE_BRUSH_TYPE_ENUM_END:3},wdi.SpiceAlphaFlags={SPICE_ALPHA_FLAGS_DEST_HAS_ALPHA:1,SPICE_ALPHA_FLAGS_SRC_SURFACE_HAS_ALPHA:2,SPICE_ALPHA_FLAGS_MASK:3},wdi.SpiceSurfaceFlags={SPICE_SURFACE_FLAGS_PRIMARY:1,SPICE_SURFACE_FLAGS_MASK:1},wdi.QuicImageType={QUIC_IMAGE_TYPE_INVALID:0,QUIC_IMAGE_TYPE_GRAY:1,QUIC_IMAGE_TYPE_RGB16:2,QUIC_IMAGE_TYPE_RGB24:3,QUIC_IMAGE_TYPE_RGB32:4,QUIC_IMAGE_TYPE_RGBA:5},wdi.SpiceImageType={SPICE_IMAGE_TYPE_BITMAP:0,SPICE_IMAGE_TYPE_QUIC:1,SPICE_IMAGE_TYPE_RESERVED:2,SPICE_IMAGE_TYPE_LZ_PLT:100,SPICE_IMAGE_TYPE_LZ_RGB:101,SPICE_IMAGE_TYPE_GLZ_RGB:102,SPICE_IMAGE_TYPE_FROM_CACHE:103,SPICE_IMAGE_TYPE_SURFACE:104,SPICE_IMAGE_TYPE_JPEG:105,SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:106,SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB:107,SPICE_IMAGE_TYPE_JPEG_ALPHA:108,SPICE_IMAGE_TYPE_CANVAS:109,SPICE_IMAGE_TYPE_PNG:110,SPICE_IMAGE_TYPE_ENUM_END:111},wdi.SpiceImageScaleMode={SPICE_IMAGE_SCALE_MODE_INTERPOLATE:0,SPICE_IMAGE_SCALE_MODE_NEAREST:1,SPICE_IMAGE_SCALE_MODE_ENUM_END:2},wdi.SpiceResourceType={SPICE_RES_TYPE_INVALID:0,SPICE_RES_TYPE_PIXMAP:1,SPICE_RESOURCE_TYPE_ENUM_END:2},wdi.SpicePathFlags={SPICE_PATH_BEGIN:1,SPICE_PATH_END:2,SPICE_PATH_CLOSE:8,SPICE_PATH_BEZIER:16,SPICE_PATH_FLAGS_MASK:27},wdi.SpiceVideoCodecType={SPICE_VIDEO_CODEC_TYPE_MJPEG:1,SPICE_VIDEO_CODEC_TYPE_VP8:2,SPICE_VIDEO_CODEC_TYPE_H264:3,SPICE_VIDEO_CODEC_TYPE_VP9:4,SPICE_VIDEO_CODEC_TYPE_H265:5,SPICE_VIDEO_CODEC_TYPE_ENUM_END:2},wdi.SpiceVideoCodecValue={1:"",2:"vp8",3:"avc1.64001f",4:"vp09.00.31.08",5:"hvc1.1.6.L93.90"},wdi.SpiceRopd={SPICE_ROPD_INVERS_SRC:1,SPICE_ROPD_INVERS_BRUSH:2,SPICE_ROPD_INVERS_DEST:4,SPICE_ROPD_OP_PUT:8,SPICE_ROPD_OP_OR:16,SPICE_ROPD_OP_AND:32,SPICE_ROPD_OP_XOR:64,SPICE_ROPD_OP_BLACKNESS:128,SPICE_ROPD_OP_WHITENESS:256,SPICE_ROPD_OP_INVERS:512,SPICE_ROPD_INVERS_RES:1024,SPICE_ROPD_MASK:2047},wdi.SpiceMigrateFlags={SPICE_MIGRATE_NEED_FLUSH:1,SPICE_MIGRATE_NEED_DATA_TRANSFER:2,SPICE_MIGRATE_FLAGS_MASK:3},wdi.SpiceKeyboardModifierFlags={SPICE_KEYBOARD_MODIFIER_FLAGS_SCROLL_LOCK:1,SPICE_KEYBOARD_MODIFIER_FLAGS_NUM_LOCK:2,SPICE_KEYBOARD_MODIFIER_FLAGS_CAPS_LOCK:4,SPICE_KEYBOARD_MODIFIER_FLAGS_MASK:7},wdi.SpiceInfoCode={SPICE_INFO_GENERAL:0,SPICE_INFO_CODE_ENUM_END:1},wdi.SpiceMouseButton={SPICE_MOUSE_BUTTON_INVALID:0,SPICE_MOUSE_BUTTON_LEFT:1,SPICE_MOUSE_BUTTON_MIDDLE:2,SPICE_MOUSE_BUTTON_RIGHT:3,SPICE_MOUSE_BUTTON_UP:4,SPICE_MOUSE_BUTTON_DOWN:5,SPICE_MOUSE_BUTTON_ENUM_END:6},wdi.SpiceClipType={SPICE_CLIP_TYPE_NONE:0,SPICE_CLIP_TYPE_RECTS:1,SPICE_CLIP_TYPE_ENUM_END:2},wdi.SpiceMouseButtonMask={SPICE_MOUSE_BUTTON_MASK_LEFT:1,SPICE_MOUSE_BUTTON_MASK_MIDDLE:2,SPICE_MOUSE_BUTTON_MASK_RIGHT:4,SPICE_MOUSE_BUTTON_MASK_MASK:7},wdi.SpiceMouseModeTypes={SPICE_MOUSE_MODE_SERVER:1,SPICE_MOUSE_MODE_CLIENT:2,SPICE_MOUSE_MODE_MASK:3},wdi.SpiceDisplayCaps={SPICE_DISPLAY_CAP_SIZED_STREAM:0,SPICE_DISPLAY_CAP_MONITORS_CONFIG:1,SPICE_DISPLAY_CAP_COMPOSITE:2,SPICE_DISPLAY_CAP_A8_SURFACE:3,SPICE_DISPLAY_CAP_STREAM_REPORT:4,SPICE_DISPLAY_CAP_LZ4_COMPRESSION:5,SPICE_DISPLAY_CAP_PREF_COMPRESSION:6,SPICE_DISPLAY_CAP_GL_SCANOUT:7,SPICE_DISPLAY_CAP_MULTI_CODEC:8,SPICE_DISPLAY_CAP_CODEC_MJPEG:9,SPICE_DISPLAY_CAP_CODEC_VP8:10,SPICE_DISPLAY_CAP_CODEC_H264:11,SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE:12,SPICE_DISPLAY_CAP_CODEC_VP9:13,SPICE_DISPLAY_CAP_CODEC_H265:14},wdi.AgentCaps={VD_AGENT_CAP_MOUSE_STATE:0,VD_AGENT_CAP_MONITORS_CONFIG:1,VD_AGENT_CAP_REPLY:2,VD_AGENT_CAP_CLIPBOARD:3,VD_AGENT_CAP_DISPLAY_CONFIG:4,VD_AGENT_CAP_CLIPBOARD_BY_DEMAND:5,VD_AGENT_CAP_CLIPBOARD_SELECTION:6},wdi.AgentMessageTypes={VD_AGENT_MOUSE_STATE:1,VD_AGENT_MONITORS_CONFIG:2,VD_AGENT_REPLY:3,VD_AGENT_CLIPBOARD:4,VD_AGENT_DISPLAY_CONFIG:5,VD_AGENT_ANNOUNCE_CAPABILITIES:6,VD_AGENT_CLIPBOARD_GRAB:7,VD_AGENT_CLIPBOARD_REQUEST:8,VD_AGENT_CLIPBOARD_RELEASE:9,VD_AGENT_GET_WINDOWS_LIST:10,VD_AGENT_CLOSE_WINDOW:11,VD_AGENT_MOVE_WINDOW:12,VD_AGENT_RESIZE_WINDOW:13,VD_AGENT_MINIMIZE_WINDOW:14,VD_AGENT_RESTORE_WINDOW:15,VD_AGENT_MAXIMIZE_WINDOW:16,VD_AGENT_FOCUS_WINDOW:17,VD_AGENT_EXECUTE_COMMAND:18},wdi.ClipBoardTypes={VD_AGENT_CLIPBOARD_NONE:0,VD_AGENT_CLIPBOARD_UTF8_TEXT:1,VD_AGENT_CLIPBOARD_IMAGE_PNG:2,VD_AGENT_CLIPBOARD_IMAGE_BMP:3,VD_AGENT_CLIPBOARD_IMAGE_TIFF:4,VD_AGENT_CLIPBOARD_IMAGE_JPG:5};wdi.GraphicDebug=$.spcExtend(wdi.DomainObject,{debugMode:null,spiceGraphicMessageTypes:[],cloneSpiceMessage:null,clientGui:null,tmpCanvas:null,tmpContext:null,originalCanvas:null,spiceMessageData:null,endCanvas:null,currentOperation:null,init:function(e){this.debugMode=e.debugMode,this.debugMode?(this._generateArray(),this._showDebug()):this._hideDebug()},_generateArray:function(){var e=this;$.each(wdi.SpiceVars,(function(a,t){-1!=a.search("SPICE_MSG_DISPLAY_")&&(e.spiceGraphicMessageTypes[t]=a)}))},_showDebug:function(){$("#canvasSpace").show(),$("#graphicDebug").show()},_hideDebug:function(){$("#canvasSpace").hide(),$("#graphicDebug").hide()},printDebugMessageOnFilter:function(e,a){if(e.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY&&this.debugMode&&$("#logActive").prop("checked")){var t=null;if(this.clientGui=a,this.cloneSpiceMessage=$.extend(!0,{},e),this.cloneSpiceMessage.args.base&&null!==this.cloneSpiceMessage.args.base.surface_id){t=this.cloneSpiceMessage.args.base.surface_id;var i=wdi.graphics.getBoxFromSrcArea(this.cloneSpiceMessage.args.base.box),s=$("<div/>").append(prettyPrint(this.cloneSpiceMessage)).hide();this.originalCanvas=this._copyCanvasFromSurfaceId(t),this.spiceMessageData=e.args.originalData,this.currentOperation=this.spiceGraphicMessageTypes[this.cloneSpiceMessage.messageType],$("#debugInfo").append($("<br/>")).append($("<hr/>")).append(this._copyAndHighlightCanvas(t,i)).append($("<br/>")).append($("<div/>").append(this.currentOperation+" (Click to hide/show)").css("cursor","pointer").css("color","blue").css("text-decoration","underline").click((function(){s.toggle()}))).append(s),this.cloneSpiceMessage.args.hasOwnProperty("image")&&this._printImage(s)}}},_printImage:function(e){wdi.graphics.getImageFromSpice(this.cloneSpiceMessage.args.image.imageDescriptor,this.cloneSpiceMessage.args.image.data,this.clientGui,(function(a){a&&e.append($("<div/>").css("font-size","12px").append("Image inside spiceMessage:").append($("<br/>")).css("border","1px solid black").append(a))}),this)},handleStreamInfo:function(){if(wdi.Stream.streams){$("#debug-stream").text("");for(let e in wdi.Stream.streams){const a=wdi.Stream.streams[e];a&&$("#debug-stream").append(`<p style="color: rgb(100, 255, 100)">Codec: ${a.codec} | Stream ID: ${a.id}</p>`)}}},printDebugMessageOnNotifyEnd:function(e,a){if(this.clientGui=a,e.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY&&this.debugMode&&$("#logActive").prop("checked")){var t=null;if(e.args.base&&null!==e.args.base.surface_id){var i=this;t=e.args.base.surface_id;var s=wdi.graphics.getBoxFromSrcArea(e.args.base.box),n=this._copyCanvasFromSurfaceId(t);$("#debugInfo").append($("<br/>")).append($("<div/>").append($("<button>Create test</button>").css("cursor","pointer").click((r=this.spiceMessageData,c=this.originalCanvas,o=n,p=this.currentOperation,function(){i.createImageTest(r,c,o,p)}))).append($("<button>Create replay window</button>").css("cursor","pointer").click(function(e,a,t,s){return function(){i.createReplay(e,a,t,s)}}(this.spiceMessageData,this.originalCanvas,n,this.currentOperation)))).append($("<br/>")).append(this._copyAndHighlightCanvas(t,s))}}var r,c,o,p},createImageTest:function(e,a,t,i){var s=prompt("Name of the test",i),n={origin:a.toDataURL("image/png"),expected:t.toDataURL("image/png"),object:e,name:s},r=JSON.stringify(n),c=s.replace(/\s/g,"_");$.post("graphictestgenerator.php","data="+r+"&name="+c).done((function(e,a,t){alert("Test created")})).fail((function(e,a,t){alert("Test creation failed.\n\nGot response: "+e.status+" "+e.statusText+"\n\n"+e.responseText)}))},createReplay:function(e,a){var t={origin:a.toDataURL("image/png"),object:e,width:a.width,height:a.height},i=JSON.stringify(t);$.post("graphictestgenerator.php","data="+i+"&replay=true").done((function(e,a,t){window.open("replay.html","replay")})).fail((function(e,a,t){alert("Replay failed.\n\nGot response: "+e.status+" "+e.statusText+"\n\n"+e.responseText)}))},_copyCanvasFromSurfaceId:function(e){var a=this.clientGui.getContext(e);this.tmpCanvas=a.canvas;var t=document.createElement("canvas");return t.width=this.tmpCanvas.width,t.height=this.tmpCanvas.height,t.getContext("2d").drawImage(this.tmpCanvas,0,0),t},_copyAndHighlightCanvas:function(e,a){var t=this._copyCanvasFromSurfaceId(e);return context=t.getContext("2d"),context.fillStyle="rgba(255,0,0,0.3)",context.fillRect(a.x,a.y,a.width,a.height),t}});wdi.LZSS={LZ_IMAGE_TYPE_INVALID:0,LZ_IMAGE_TYPE_PLT1_LE:1,LZ_IMAGE_TYPE_PLT1_BE:2,LZ_IMAGE_TYPE_PLT4_LE:3,LZ_IMAGE_TYPE_PLT4_BE:4,LZ_IMAGE_TYPE_PLT8:5,LZ_IMAGE_TYPE_RGB16:6,LZ_IMAGE_TYPE_RGB24:7,LZ_IMAGE_TYPE_RGB32:8,LZ_IMAGE_TYPE_RGBA:9,LZ_IMAGE_TYPE_XXXA:10,LZPALETTE_FLAG_PAL_CACHE_ME:1,LZPALETTE_FLAG_PAL_FROM_CACHE:2,LZPALETTE_FLAG_TOP_DOWN:4,PLT_PIXELS_PER_BYTE:[0,8,8,2,2,1],PLT1_MASK:[1,2,4,8,16,32,64,128],copy_pixel:function(e,i,_){_[e+0]=i.r,_[e+1]=i.g,_[e+2]=i.b},lz_rgb32_decompress_rgb:function(e){var i,_=0,t=0,s=new Uint8Array(e),p=(s[_++],s[_++]),E=s[_++],c=s[++_+1]*Math.pow(16,2)+s[_],o=s[(_+=2)+1]*Math.pow(16,2)+s[_];_+=2;var T,r,l=o*Math.pow(16,4)+c,L=new ArrayBuffer(l),P=new Uint8Array(L),a=new Uint32Array(L),h=l/4;for(i=s[_++];t<h;i=s[_++])if(A=t,l=i>>5,I=(31&i)<<8,i>31){if(6===--l)do{l+=b=s[_++]}while(255===b);if(I+=b=s[_++],255===b&&I-b==7936&&(I=s[_++]<<8,I+=s[_++],I+=8191),l+=1,(A-=I+=1)===t-1)for(r=4*(f=A);l;--l)a[t]=255<<24|P[r+2]<<16|P[r+1]<<8|P[r],t++;else for(;l;--l)T=4*A,a[t]=255<<24|P[T+2]<<16|P[T+1]<<8|P[T],t++,A++}else for(i++,a[t]=255<<24|s[_]<<16|s[_+1]<<8|s[_+2],_+=3,t++,--i;i;i--)a[t]=255<<24|s[_]<<16|s[_+1]<<8|s[_+2],_+=3,t++;if(E===this.LZ_IMAGE_TYPE_RGBA&&!p)for(t=0,i=null,_--,i=s[_++];t<h;i=s[_++]){var A=t,I=(l=i>>5,(31&i)<<8),n=4*t;if(i>=32){var b;if(6===--l)do{l+=b=s[_++]}while(255===b);if(I+=b=s[_++],255===b&&I-b==7936&&(I=s[_++]<<8,I+=s[_++],I+=8191),l+=3,(A-=I+=1)===t-1)for(var f=A;l;--l)P[(n=4*t)+3]=P[4*f+3],t++;else for(;l;--l)P[(n=4*t)+3]=P[4*A+3],t++,A++}else for(i++,P[n+3]=s[_++],t++,--i;i;i--)P[(n=4*t)+3]=s[_++],t++}return L},lz_rgb32_decompress:function(e,i,_,t,s,p,E){var c,o=i,T=0,r=_.length/4,l=t===this.LZ_IMAGE_TYPE_RGBA;for(c=e[o++];T<r;c=e[o++]){var L=T,P=c>>5,a=(31&c)<<8,h=4*T;if(c>=32){var A;if(6===--P)do{P+=A=e[o++]}while(255===A);if(a+=A=e[o++],255===A&&a-A==7936&&(a=e[o++]<<8,a+=e[o++],a+=8191),P+=1,(l||p)&&(P+=2),a+=1,t===this.LZ_IMAGE_TYPE_PLT4_LE||t===this.LZ_IMAGE_TYPE_PLT4_BE?(a*=2,P*=2):t!==this.LZ_IMAGE_TYPE_PLT1_BE&&t!==this.LZ_IMAGE_TYPE_PLT1_LE||(a*=8,P*=8),(L-=a)===T-1)for(var I=L;P;--P){if(h=4*T,l)_[h+3]=E?255:_[4*I+3];else for(var n=0;n<4;n++)_[h+n]=_[4*I+n];T++}else for(;P;--P){if(h=4*T,l)_[h+3]=E?255:_[4*L+3];else for(n=0;n<4;n++)_[h+n]=_[4*L+n];T++,L++}}else{if(c++,l)E?(_[h+3]=255,o++):_[h+3]=e[o++];else if(p){if(t===this.LZ_IMAGE_TYPE_PLT1_LE){var b=e[o++],f=p[1],d=p[0];for(n=0;n<8;n++)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n<7&&T++,h=4*T}else if(t===this.LZ_IMAGE_TYPE_PLT1_BE)for(b=e[o++],f=p[1],d=p[0],n=7;n>=0;n--)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n>0&&T++,h=4*T;else if(t===this.LZ_IMAGE_TYPE_PLT4_LE){var w=p[15&(b=e[o++])];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[b>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT4_BE){var y=15&(b=e[o++]);w=p[b>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[y];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT8){w=p[e[o++]];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}}else _[h+0]=e[o+2],_[h+1]=e[o+1],_[h+2]=e[o+0],s&&(_[h+3]=255),o+=3;for(T++,--c;c;c--){if(h=4*T,l)_[h+3]=E?255:e[o++];else if(p){if(t===this.LZ_IMAGE_TYPE_PLT1_LE)for(b=e[o++],f=p[1],d=p[0],n=0;n<8;n++)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n<7&&T++,h=4*T;else if(t===this.LZ_IMAGE_TYPE_PLT1_BE)for(b=e[o++],f=p[1],d=p[0],n=7;n>=0;n--)b&this.PLT1_MASK[n]?this.copy_pixel(h,f,_):this.copy_pixel(h,d,_),s&&(_[h+3]=255),n>0&&T++,h=4*T;else if(t===this.LZ_IMAGE_TYPE_PLT4_LE){w=p[15&(b=e[o++])];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[b>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT4_BE){w=p[(b=e[o++])>>>4&15];this.copy_pixel(h,w,_),s&&(_[h+3]=255),h=4*++T;w=p[15&b];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}else if(t===this.LZ_IMAGE_TYPE_PLT8){w=p[e[o++]];this.copy_pixel(h,w,_),s&&(_[h+3]=255)}}else _[h+0]=e[o+2],_[h+1]=e[o+1],_[h+2]=e[o+0],s&&(_[h+3]=255),o+=3;T++}}}return o-1},convert_spice_lz_to_web:function(e,i,_,t){var s=_.type;if(i=i.toJSArray(),s===wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_PLT){var p=wdi.SpiceObject.bytesToInt8(i.splice(0,1));if(p===this.LZPALETTE_FLAG_PAL_FROM_CACHE){var E=i.splice(0,12),c=(wdi.SpiceObject.bytesToInt32(E.splice(0,4)),wdi.SpiceObject.bytesToInt64(E.splice(0,8)));E=i;wdi.SpiceObject.bytesToStringBE(E.splice(0,4)),wdi.SpiceObject.bytesToInt32BE(E.splice(0,4));var o=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),T=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),r=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),l=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),L=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4))}else if(p===this.LZPALETTE_FLAG_PAL_CACHE_ME){for(var P=_.offset+1,a=(E=i.splice(0,36),wdi.SpiceObject.bytesToInt32(E.splice(0,4)),wdi.SpiceObject.bytesToInt32(E.splice(0,4))-P-36),h=(wdi.SpiceObject.bytesToStringBE(E.splice(0,4)),wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),o=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),T=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),r=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),l=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),L=wdi.SpiceObject.bytesToInt32BE(E.splice(0,4)),c=wdi.SpiceObject.bytesToInt64(i.splice(a,8)),wdi.SpiceObject.bytesToInt16(i.splice(a,2))),A=[],I=0;I<h;I++){var n=new wdi.Queue;n.setData(i.splice(a,4)),A.push((new wdi.SpiceColor).demarshall(n))}wdi.ImageCache.addPalette(c,A)}else wdi.Debug.error("Unimplemented lz palette top down");A=wdi.ImageCache.getPalette(c)}if(o!==this.LZ_IMAGE_TYPE_RGB32&&o!==this.LZ_IMAGE_TYPE_RGBA&&o!==this.LZ_IMAGE_TYPE_RGB24&&o!==this.LZ_IMAGE_TYPE_PLT8&&o!==this.LZ_IMAGE_TYPE_PLT1_LE&&o!==this.LZ_IMAGE_TYPE_PLT1_BE&&o!==this.LZ_IMAGE_TYPE_PLT4_LE&&o!==this.LZ_IMAGE_TYPE_PLT4_BE)return!1;if(A){var b=e.createImageData(l*this.PLT_PIXELS_PER_BYTE[o],r);this.lz_rgb32_decompress(i,0,b.data,o,o!==this.LZ_IMAGE_TYPE_RGBA,A);var f=wdi.graphics.getNewTmpCanvas(T,r);f.getContext("2d").putImageData(b,0,0,0,0,T,r),b=f}else{var d=new ArrayBuffer(i.length+8),w=new Uint8Array(d);w[0]=1,w[1]=t,w[2]=o,w[3]=0;var y=b.data.length;for(I=0;I<4;I++)w[4+I]=255&y,y>>=8;w.set(i,8);var G=new Uint8ClampedArray(this.lz_rgb32_decompress_rgb(d));b=new ImageData(G,T,r),b=wdi.graphics.getImageFromData(b)}return L||(b=wdi.RasterOperation.flip(b)),b},demarshall_rgb:function(e){var i=e.splice(0,32);return{length:wdi.SpiceObject.bytesToInt32(i.splice(0,4)),magic:wdi.SpiceObject.bytesToStringBE(i.splice(0,4)),version:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),type:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),width:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),height:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),stride:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4)),top_down:wdi.SpiceObject.bytesToInt32BE(i.splice(0,4))}},lz_rgb32_plt1_be_decompress:function(e,i,_){var t,s,p,E,c,o,T,r,l,L,P=0,a=0,h=i.length/4,A=this.LZ_IMAGE_TYPE_PLT1_BE,I=this.PLT_PIXELS_PER_BYTE[A];for(t=e[P++];a<h;t=e[P++])if(s=a,p=t>>5,E=(31&t)<<8,t>31){if(7===p)do{p+=c=e[P++]}while(255===c);if(8191===(E+=e[P++])&&(E+=e[P++]<<8+e[P++]),p=(p+2)*I,(s-=(E+1)*I)===a-1)for(o=4*s;0!=p--;)op_4=4*a,i[op_4]=i[o],i[op_4+1]=i[o+1],i[op_4+2]=i[o+2],i[op_4+3]=i[o+3],a++;else for(;0!=p--;)op_4=4*a,o=4*s,i[op_4]=i[o],i[op_4+1]=i[o+1],i[op_4+2]=i[o+2],i[op_4+3]=i[o+3],a++,s++}else for(;-1!=t--;)for(op_4=4*a,T=e[P++],r=_[1],l=_[0],L=7;L>=0;L--)op_4=4*a,T&this.PLT1_MASK[L]?(i[op_4+0]=r.r,i[op_4+1]=r.g,i[op_4+2]=r.b):(i[op_4+0]=l.r,i[op_4+1]=l.g,i[op_4+2]=l.b),i[op_4+3]=255,a++}};function intToByteArray(t){let e=new Uint8Array(1);return e[0]=255&t,e}wdi.BMP2=$.spcExtend(wdi.SpiceObject,{objectSize:0,mapper:[0,1,1,4,4,8,16,24,32,32],init:function(t){var e,i,a,s,h=this.bytesToInt8(t),r=this.bytesToInt8(t),n=this.bytesToInt32(t),p=this.bytesToInt32(t),l=this.bytesToInt32(t),o=this.mapper[h],g=0;if(o<=8&&o>0){var m=[];if(1&r){this.bytesToInt32(t);e=t.length;var f,d=4*Math.pow(2,o)+8+2;for(e-=d,s=t.splice(e,d),a=this.bytesToInt64(s),g=this.bytesToInt16(s),i=0;i<4*g;i+=4)(f=new wdi.Queue).setData(s.slice(i,i+4)),m.push((new wdi.SpiceColor).demarshall(f));wdi.ImageCache.addPalette(a,m)}else{var I;for(a=this.bytesToInt64(t),e=t.length,s=[],g=(m=wdi.ImageCache.getPalette(a)).length,i=0;i<g;i++)(I=m[i].marshall()).push(0),s=s.concat(I)}}else this.bytesToInt32(t);this.setContent({imageSize:e,width:n,height:p,bpp:o,imageData:t,paletteSize:4*g,palette:m,stride:l,flags:r,type:h})},setContent:function(t){this.imageSize=t.imageSize,this.width=t.width,this.height=t.height,this.bpp=t.bpp,this.imageData=t.imageData,this.palette=t.palette,this.offset=t.paletteSize+54,this.size=this.offset+this.imageSize,this.stride=t.stride,this.flags=t.flags,this.type=9},marshall:function(t){var e,i,a,s,h,r,n=this.type,p=this.palette,l=this.width,o=this.height,g=this.stride,m=this.imageData,f=this.flags,d=m.length,I=8*g/this.bpp,w=new ArrayBuffer(4*I*o),T=new Uint8ClampedArray(w),c=new Uint32Array(w);m[1];if(p){if(s=0,n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_1BIT_BE){var b=(h=p[1]).r<<24|h.g<<16|h.b<<8|255,y=(h=p[0]).r<<24|h.g<<16|h.b<<8|255,B=[1,2,4,8,16,32,64,128];for(a=0;a<d;a++)for(e=m[a],i=7;i>=0;i--)c[s++]=e&B[i]?b:y}else if(n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_4BIT_BE)for(a=0;a<d;a++)h=p[(e=m[a])>>>4],c[s++]=h.r<<24|h.g<<16|h.b<<8|255,h=p[15&e],c[s++]=h.r<<24|h.g<<16|h.b<<8|255}else{if(n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_32BIT||n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_RGBA)for(a=0;a<d;a+=4){let t,e,i;t=m[a],e=m[a+1],i=m[a+2],m[a]=i,m[a+1]=e,m[a+2]=t,m[a+3]=255}else if(n===wdi.SpiceBitmapFmt.SPICE_BITMAP_FMT_24BIT)for(a=0;a<d;a+=3)r=m[a],m[a]=m[a+2],m[a+2]=r;T=new Uint8ClampedArray(m)}var S=new ImageData(T,I,o),_=wdi.graphics.getNewTmpCanvas(l,o);return _.getContext("2d").putImageData(S,0,0,0,0,l,o),S=_,!4&f&&(S=wdi.RasterOperation.flip(S)),S}});"use strict";var rfc2083_crc_table=Array(256),rfc2083_crc_table_computed=0;function rfc2083_make_crc_table(){var t,e,i;for(e=0;e<256;e++){for(t=e,i=0;i<8;i++)1&t?t=(3988292384^t>>>1)>>>0&4294967295:t>>>=1;rfc2083_crc_table[e]=t}rfc2083_crc_table_computed=1}function rfc2083_update_crc(t,e,i,r){var n,s=t;for(rfc2083_crc_table_computed||rfc2083_make_crc_table(),n=0;n<r;n++)s=rfc2083_crc_table[255&(s^e[i+n])]^s>>>8;return s}function rfc2083_crc(t,e,i){return 4294967295^rfc2083_update_crc(4294967295,t,e,i)}function crc32(t,e,i){return rfc2083_crc(new Uint8Array(t),e,i)}function PngIHDR(t,e){this.width=t,this.height=e,this.depth=8,this.type=6,this.compression=0,this.filter=0,this.interlace=0}function adler(){this.s1=1,this.s2=0}function PngIDAT(t,e,i){if(i.byteLength>65535)throw new Error("Cannot handle more than 64K");this.data=i,this.width=t,this.height=e}function PngIEND(){}function create_rgba_png(t,e,i){var r,n=new PngIHDR(t,e),s=new PngIDAT(t,e,i),c=new PngIEND,h=new ArrayBuffer(n.buffer_size()+s.buffer_size()+c.buffer_size()),f=n.to_buffer(h);f=s.to_buffer(h,f),f=c.to_buffer(h,f);var a=new Uint8Array(h),o="";for(r=0;r<f;r++)o+="%",a[r]<16&&(o+="0"),o+=a[r].toString(16);return"%89PNG%0D%0A%1A%0A"+o}PngIHDR.prototype={to_buffer:function(t,e){var i=e=e||0,r=new SpiceDataView(t);return r.setUint32(e,this.buffer_size()-12),e+=4,r.setUint8(e,"I".charCodeAt(0)),e++,r.setUint8(e,"H".charCodeAt(0)),e++,r.setUint8(e,"D".charCodeAt(0)),e++,r.setUint8(e,"R".charCodeAt(0)),e++,r.setUint32(e,this.width),e+=4,r.setUint32(e,this.height),e+=4,r.setUint8(e,this.depth),e++,r.setUint8(e,this.type),e++,r.setUint8(e,this.compression),e++,r.setUint8(e,this.filter),e++,r.setUint8(e,this.interlace),e++,r.setUint32(e,crc32(t,i+4,this.buffer_size()-8)),e+=4},buffer_size:function(){return 25}},adler.prototype.update=function(t){this.s1+=t,this.s1%=65521,this.s2+=this.s1,this.s2%=65521},PngIDAT.prototype={to_buffer:function(t,e){var i,r,n,s=e=e||0,c=new SpiceDataView(t),h=new adler;c.setUint32(e,this.buffer_size()-12),e+=4,c.setUint8(e,"I".charCodeAt(0)),e++,c.setUint8(e,"D".charCodeAt(0)),e++,c.setUint8(e,"A".charCodeAt(0)),e++,c.setUint8(e,"T".charCodeAt(0)),e++,c.setUint8(e,120),e++,c.setUint8(e,1),e++,c.setUint8(e,128),e++,c.setUint16(e,this.data.byteLength+this.height),e+=2,c.setUint16(e,~(this.data.byteLength+this.height)),e+=2;var f=new Uint8Array(this.data);for(n=0,r=0;r<this.height;r++)for(c.setUint8(e,0),e++,h.update(0),i=0;i<this.width&&n<this.data.byteLength;i++)h.update(f[n]),c.setUint8(e,f[n++]),e++,h.update(f[n]),c.setUint8(e,f[n++]),e++,h.update(f[n]),c.setUint8(e,f[n++]),e++,h.update(f[n]),c.setUint8(e,f[n++]),e++;return c.setUint16(e,h.s2),e+=2,c.setUint16(e,h.s1),e+=2,c.setUint32(e,crc32(t,s+4,this.buffer_size()-8)),e+=4},buffer_size:function(){return 12+this.data.byteLength+this.height+4+2+1+2+2}},PngIEND.prototype={to_buffer:function(t,e){var i=e=e||0,r=new SpiceDataView(t);return r.setUint32(e,this.buffer_size()-12),e+=4,r.setUint8(e,"I".charCodeAt(0)),e++,r.setUint8(e,"E".charCodeAt(0)),e++,r.setUint8(e,"N".charCodeAt(0)),e++,r.setUint8(e,"D".charCodeAt(0)),e++,r.setUint32(e,crc32(t,i+4,this.buffer_size()-8)),e+=4},buffer_size:function(){return 12}};wdi.RunQueue=$.spcExtend(wdi.DomainObject,{tasks:null,isRunning:!1,init:function(){this.tasks=[]},getTasksLength:function(){return this.tasks.length},add:function(n,s,i,t){return this.tasks.push({fn:n,scope:s,fnFinish:i,params:t}),this},clear:function(){return wdi.Debug.log("runqueue clear"),this.tasks=[],this},_process:function(){wdi.ExecutionControl.sync=!0;var n,s=this;this.isRunning=!0;var i=this.tasks.shift();if(i){n={end:function(){i.fnFinish&&i.fnFinish.call(i.scope),s._process()}};try{i.fn.call(i.scope,n,i.params)}catch(s){wdi.Debug.error(s.message),n.end()}return this}this.isRunning=!1},process:function(){this.isRunning||this._process()}}),wdi.ExecutionControl={currentProxy:null,sync:!0,runQ:new wdi.RunQueue};"undefined"==typeof CanvasPixelArray||CanvasPixelArray.prototype.set||(CanvasPixelArray.prototype.set=function(n){for(var t=n.length,r=0;r<t;r++)this[r]=n[r]}),wdi.graphics={tmpCanvas:document.createElement("canvas"),imageLoader:new Image,dispose:function(){wdi.Debug.log("Disposing graphics"),$(this.tmpCanvas).remove(),$(this.imageLoader).remove(),this.tmpCanvas=document.createElement("canvas"),this.imageLoader=new Image,wdi.GlobalPool.dispose(),wdi.ImageCache.dispose(),wdi.ImageUncompressor.dispose(),wdi.RasterOperation.dispose()},getRect:function(n,t){if(0===n.x&&0===n.y&&n.width===t.width&&n.height===t.height)return t;var r=this.getImageFromData(t),e=wdi.graphics.getNewTmpCanvas(n.width,n.height);return e.getContext("2d").drawImage(r,n.x,n.y,n.width,n.height,0,0,n.width,n.height),e},argbToImageData:function(n,t,r){for(var e=n.length,u=wdi.graphics.getTmpCanvas(t,r).getContext("2d").createImageData(t,r),i=0;i<e;i+=4)u.data[i]=n[i],u.data[i+1]=n[i+1],u.data[i+2]=n[i+2],u.data[i+3]=n[i+3];return u},align:function(n,t){return n+(t-1)&~(t-1)},monoMask:[1,2,4,8,16,32,64,128],monoToImageData:function(n,t,r){this.align(t,8);for(var e=n.length,u=e/2,i=wdi.graphics.getTmpCanvas(t,r).getContext("2d").createImageData(t,r),o=[],c=[],a=0;a<e;a++){var f=n[a],d=8;if(a>=u)for(;d--;){var g=f&this.monoMask[d]&&!0;o.push(g)}else if(a<u)for(;d--;){g=f&this.monoMask[d]&&!0;c.push(g)}}var s=0;for(u=c.length,a=0;a<u;a++)s=4*a,o[a]||c[a]?!o[a]&&c[a]?(i.data[s]=255,i.data[s+1]=255,i.data[s+2]=255,i.data[s+3]=0):o[a]&&!c[a]?(i.data[s]=255,i.data[s+1]=255,i.data[s+2]=255,i.data[s+3]=255):o[a]&&c[a]&&(i.data[s]=0,i.data[s+1]=0,i.data[s+2]=0,i.data[s+3]=255):(i.data[s]=0,i.data[s+1]=0,i.data[s+2]=0,i.data[s+3]=255);return i},drawJpeg:function(n,t,r,e){return this.drawBrowserImage(n,t,r,e,"jpeg",!1)},drawBrowserImage:function(n,t,r,e,u,i){var o,c,a=wdi.GlobalPool.create("Image");a.onload=function(){URL.revokeObjectURL(c);try{if(n.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME){var t=wdi.graphics.getTmpCanvas(this.width,this.height);t.getContext("2d").drawImage(this,0,0),wdi.ImageCache.addImage(n,t)}r.call(e,this)}catch(n){wdi.Debug.error(n.message)}finally{wdi.ExecutionControl.currentProxy.end()}},a.onerror=function(){URL.revokeObjectURL(c),wdi.Debug.error("failed to load JPEG image"),wdi.ExecutionControl.currentProxy.end()},i?(o=t,a.src=o):(c=wdi.SpiceObject.bytesToURI(t),a.src=c)},getImageFromSpice:function(n,t,r,e,u,i){var o,c,a,f,d=null;switch(i?(c=i.opaque,a=i.brush,f=i.raw):(c=!1,f=!1,a=!1),n.type){case wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB:d=this.processLz(n,t,a,c,r);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_PLT:wdi.Debug.log("lz plt decode"),d=wdi.LZSS.convert_spice_lz_to_web(r.getContext(0),t,n,c);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC:d=this.processQuic(n,t,a,c,r);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG:return wdi.Debug.log("JPEG decode"),wdi.ExecutionControl.sync=!1,void this.drawJpeg(n,t.subarray(4),e,u);case wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG_ALPHA:wdi.Debug.log("JPEG Alpha decode"),wdi.ExecutionControl.sync=!1;var g=t.subarray(9);return void this.drawJpeg(n,g,e,u);case wdi.SpiceImageType.SPICE_IMAGE_TYPE_BITMAP:wdi.Debug.log("BMP"),t.toJSArray&&(t=t.toJSArray()),d=new wdi.BMP2(t).marshall(r.getContext(0));break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS:case wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE:return wdi.ExecutionControl.sync=!1,void wdi.ImageCache.getImageFrom(n,(function(n){e.call(u,n),wdi.ExecutionControl.currentProxy.end()}));case wdi.SpiceImageType.SPICE_IMAGE_TYPE_SURFACE:var s=wdi.SpiceObject.bytesToInt32(t.toJSArray());d=r.getContext(s).canvas;break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS:d=t;break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_PNG:return wdi.ExecutionControl.sync=!1,t=wdi.SpiceObject.bytesToString(t.toJSArray()),void this.drawBrowserImage(n,t,e,u,"png",!0);default:return wdi.Debug.log("Unknown image type: "+n.type),void wdi.ExecutionControl.currentProxy.end()}o=null,n.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME&&wdi.ImageCache.addImage(n,d),o=d.getContext||f?d:this.getImageFromData(d),n.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME&&wdi.ImageCache.addImage(n,o),wdi.ExecutionControl.sync&&e.call(u,o)},processUncompress:function(n,t,r,e,u,i){wdi.ImageUncompressor.getSyncInstance().process(n,t,r,e,u,i,this)},processQuic:function(n,t,r,e,u){var i;return this.processUncompress(n,t,r,e,u,(function(t){var r=new Uint8ClampedArray(t);i=new ImageData(r,n.width,n.height)})),i},processLz:function(n,t,r,e,u){var i;return this.processUncompress(n,t,r,e,u,(function(u){var o=wdi.ImageUncompressor.getSyncInstance().extractLzHeader(t,r),c=new Uint8ClampedArray(u);i=new ImageData(c,n.width,n.height),o.header.top_down||e||(i=this.imageFlip(i))})),i},imageFlip:function(n){return wdi.RasterOperation.flip(this.getImageFromData(n))},getImageFromData:function(n,t){return n.getContext||n instanceof Image?n:((r=t?$("<canvas/>").attr({width:n.width,height:n.height})[0]:this.getNewTmpCanvas(n.width,n.height)).getContext("2d").putImageData(n,0,0),r);var r},getDataFromImage:function(n){return n.getContext("2d").getImageData(0,0,n.width,n.height)},getBoxFromSrcArea:function(n){return{width:n.right-n.left,height:n.bottom-n.top,x:n.left,y:n.top}},setBrush:function(n,t,r,e,u){var i,o,c;if(r.type===wdi.SpiceBrushType.SPICE_BRUSH_TYPE_PATTERN)o=r.pattern.image,this.getImageFromSpice(o,r.pattern.imageData,n,(function(n){if(i=t.createPattern(n,"repeat"),u===wdi.SpiceRopd.SPICE_ROPD_OP_PUT)t.fillStyle=i,t.fillRect(e.x,e.y,e.width,e.height);else{var r=wdi.graphics.getTmpCanvas(e.width,e.height),o=r.getContext("2d");o.fillStyle=i,o.fillRect(0,0,e.width,e.height);var a=wdi.graphics.getRect(e,t.canvas);c=wdi.RasterOperation.process(u,r,a),t.drawImage(c,e.x,e.y,e.width,e.height)}}),this,{opaque:!0});else if(r.type===wdi.SpiceBrushType.SPICE_BRUSH_TYPE_SOLID)if(u===wdi.SpiceRopd.SPICE_ROPD_OP_PUT)t.fillStyle!=r.color.simple_html_color&&(t.fillStyle=r.color.simple_html_color),t.fillRect(e.x,e.y,e.width,e.height);else{var a=wdi.graphics.getTmpCanvas(e.width,e.height),f=a.getContext("2d");f.fillStyle=r.color.html_color,f.fillRect(0,0,e.width,e.height);var d=wdi.graphics.getRect(e,t.canvas);c=wdi.RasterOperation.process(u,a,d),t.drawImage(c,e.x,e.y,e.width,e.height)}},imageIsEntireColor:function(n,t,r,e,u){var i,o=0;do{i=u[o]===n&&u[o+1]===t&&u[o+2]===r,o+=4}while(o!=e&&i);return i},drawBackText:function(n,t,r){var e=r.back_brush,u=r.back_mode,i=wdi.graphics.getBoxFromSrcArea(r.base.box);this.setBrush(n,t,e,i,u)},drawString:function(n,t,r,e,u,i){var o,c,a,f,d,g,s,h,p,w,l,m,I,C,_,E,S,y,v,P,T,x,A,b=e.color,D=t.len,G=t.raster_glyph;for(h=1===r?255:4===r?17:1,l=0;l<D;l++){for(o=(y=G[l]).render_pos,c=y.glyph_origin,a=y.width,f=y.height,d=y.data,g=f,m=new ArrayBuffer(a*f*4),I=new Uint8ClampedArray(m),C=new Uint32Array(m),p=0,w=0;g--;){for(E=_=Math.ceil(a*r/8),S=[];E--;)S.push(d.pop());for(;_--;)for(v=S.pop(),P=8,T=0;P;)x=wdi.bppMask[r][T]&v,1===r&&x?x=1:4===r&&x&&x>15&&(x>>=4),x&&(C[w*a+p]=h*x<<24|b.b<<16|b.g<<8|b.r),P-=r,p++,T++;w++,p=0}A={x:o.x+c.x,y:o.y+c.y-1,width:a,height:f},s=new ImageData(I,a,f);var R=wdi.graphics.getImageFromData(s);i.drawClip(R,A,n),wdi.GlobalPool.discard("Canvas",R)}},getImgDataPosition:function(n,t,r){return 4*(t*r+n)},getTmpCanvas:function(n,t){var r=this.tmpCanvas;return r.width=n,r.height=t,r},getNewTmpCanvas:function(n,t){var r=wdi.GlobalPool.create("Canvas");return r.width=n,r.height=t,r}},wdi.Rop3={1:function(n,t,r){return~(n|t|r)},2:function(n,t,r){return~(n|t)&r},4:function(n,t,r){return~(n|r)&t},6:function(n,t,r){return~(t^~r|n)},7:function(n,t,r){return~(t&r|n)},8:function(n,t,r){return~n&r&t},9:function(n,t,r){return~(t^r|n)},11:function(n,t,r){return~(~r&t|n)},13:function(n,t,r){return~(~t&r|n)},14:function(n,t,r){return~(~(t|r)|n)},16:function(n,t,r){return~(t|r)&n},18:function(n,t,r){return~(n^~r|t)},19:function(n,t,r){return~(n&r|t)},20:function(n,t,r){return~(n^~t|r)},21:function(n,t,r){return~(n&t|r)},22:function(n,t,r){return~(n&t)&r^t^n},23:function(n,t,r){return(t^r)&(t^n)^~t},24:function(n,t,r){return(t^n)&(n^r)},25:function(n,t,r){return~(n&t)&r^~t},26:function(n,t,r){return(n&t|r)^n},27:function(n,t,r){return(n^t)&r^~t},28:function(n,t,r){return(n&r|t)^n},29:function(n,t,r){return(n^r)&t^~r},30:function(n,t,r){return(r|t)^n},31:function(n,t,r){return~((t|r)&n)},32:function(n,t,r){return~t&n&r},33:function(n,t,r){return~(n^r|t)},35:function(n,t,r){return~(~r&n|t)},36:function(n,t,r){return(t^n)&(r^t)},37:function(n,t,r){return~(t&n)&r^~n},38:function(n,t,r){return(t&n|r)^t},39:function(n,t,r){return(t^~n|r)^t},40:function(n,t,r){return(n^t)&r},41:function(n,t,r){return(t&n|r)^t^~n},42:function(n,t,r){return~(t&n)&r},43:function(n,t,r){return(n^r)&(t^n)^~t},44:function(n,t,r){return(t|r)&n^t},45:function(n,t,r){return(~r|t)^n},46:function(n,t,r){return(n^r|t)^n},47:function(n,t,r){return~((~r|t)&n)},49:function(n,t,r){return~(~n&r|t)},50:function(n,t,r){return(t|n|r)^t},52:function(n,t,r){return(t&r|n)^t},53:function(n,t,r){return(t^~r|n)^t},54:function(n,t,r){return(n|r)^t},55:function(n,t,r){return~((n|r)&t)},56:function(n,t,r){return(n|r)&t^n},57:function(n,t,r){return(~r|n)^t},58:function(n,t,r){return(t^r|n)^t},59:function(n,t,r){return~((~r|n)&t)},61:function(n,t,r){return(~(t|r)|n)^t},62:function(n,t,r){return(~t&r|n)^t},64:function(n,t,r){return~r&t&n},65:function(n,t,r){return~(t^n|r)},66:function(n,t,r){return(t^r)&(n^r)},67:function(n,t,r){return~(t&r)&n^~t},69:function(n,t,r){return~(~t&n|r)},70:function(n,t,r){return(r&n|t)^r},71:function(n,t,r){return(n^r)&t^~n},72:function(n,t,r){return(n^r)&t},73:function(n,t,r){return(r&n|t)^r^~n},74:function(n,t,r){return(r|t)&n^r},75:function(n,t,r){return(~t|r)^n},76:function(n,t,r){return~(n&r)&t},77:function(n,t,r){return(t^r|t^n)^~t},78:function(n,t,r){return(n^t|r)^n},79:function(n,t,r){return~((~t|r)&n)},81:function(n,t,r){return~(~n&t|r)},82:function(n,t,r){return(r&t|n)^r},83:function(n,t,r){return(t^r)&n^~t},84:function(n,t,r){return~(~(t|n)|r)},86:function(n,t,r){return(t|n)^r},87:function(n,t,r){return~((t|n)&r)},88:function(n,t,r){return(n|t)&r^n},89:function(n,t,r){return(~t|n)^r},91:function(n,t,r){return(~(r|t)|n)^r},92:function(n,t,r){return(r^t|n)^r},93:function(n,t,r){return~((~t|n)&r)},94:function(n,t,r){return(~r&t|n)^r},96:function(n,t,r){return(t^r)&n},97:function(n,t,r){return(t&r|n)^t^~r},98:function(n,t,r){return(r|n)&t^r},99:function(n,t,r){return(~n|r)^t},100:function(n,t,r){return(t|n)&r^t},101:function(n,t,r){return(~n|t)^r},103:function(n,t,r){return(~(t|n)|r)^t},104:function(n,t,r){return(~(t|r)|n)^t^~r},105:function(n,t,r){return t^r^~n},106:function(n,t,r){return t&n^r},107:function(n,t,r){return(t|n)&r^t^~n},108:function(n,t,r){return n&r^t},109:function(n,t,r){return(r|n)&t^r^~n},110:function(n,t,r){return(~t|n)&r^t},111:function(n,t,r){return~((t^~r)&n)},112:function(n,t,r){return~(t&r)&n},113:function(n,t,r){return(r^n)&(t^r)^~t},114:function(n,t,r){return(t^n|r)^t},115:function(n,t,r){return~((~n|r)&t)},116:function(n,t,r){return(r^n|t)^r},117:function(n,t,r){return~((~n|t)&r)},118:function(n,t,r){return(~t&n|r)^t},120:function(n,t,r){return t&r^n},121:function(n,t,r){return(t|r)&n^t^~r},122:function(n,t,r){return(~r|t)&n^r},123:function(n,t,r){return~((n^~r)&t)},124:function(n,t,r){return(~t|r)&n^t},125:function(n,t,r){return~((t^~n)&r)},126:function(n,t,r){return t^r|n^t},127:function(n,t,r){return~(t&n&r)},128:function(n,t,r){return t&n&r},129:function(n,t,r){return~(t^r|n^t)},130:function(n,t,r){return(t^~n)&r},131:function(n,t,r){return(~t|r)&n^~t},132:function(n,t,r){return(n^~r)&t},133:function(n,t,r){return(~n|t)&r^~n},134:function(n,t,r){return(t|r)&n^t^r},135:function(n,t,r){return t&r^~n},137:function(n,t,r){return(~t&n|r)^~t},138:function(n,t,r){return(~n|t)&r},139:function(n,t,r){return(r^n|t)^~r},140:function(n,t,r){return(~n|r)&t},141:function(n,t,r){return(t^n|r)^~t},142:function(n,t,r){return(r^n)&(r^t)^t},143:function(n,t,r){return~(~(t&r)&n)},144:function(n,t,r){return(t^~r)&n},145:function(n,t,r){return(~t|n)&r^~t},146:function(n,t,r){return(n|r)&t^n^r},147:function(n,t,r){return r&n^~t},148:function(n,t,r){return(t|n)&r^t^n},149:function(n,t,r){return t&n^~r},150:function(n,t,r){return t^n^r},151:function(n,t,r){return(~(t|n)|r)^t^n},152:function(n,t,r){return(~(t|n)|r)^~t},154:function(n,t,r){return~t&n^r},155:function(n,t,r){return(t|n)&r^~t},156:function(n,t,r){return~r&n^t},157:function(n,t,r){return(r|n)&t^~r},158:function(n,t,r){return(t&r|n)^t^r},159:function(n,t,r){return~((t^r)&n)},161:function(n,t,r){return(~n&t|r)^~n},162:function(n,t,r){return(~t|n)&r},163:function(n,t,r){return(r^t|n)^~r},164:function(n,t,r){return(~(n|t)|r)^~n},166:function(n,t,r){return~n&t^r},167:function(n,t,r){return(n|t)&r^~n},168:function(n,t,r){return(t|n)&r},169:function(n,t,r){return(t|n)^~r},171:function(n,t,r){return~(t|n)|r},172:function(n,t,r){return(t^r)&n^t},173:function(n,t,r){return(r&t|n)^~r},174:function(n,t,r){return~n&t|r},176:function(n,t,r){return(~t|r)&n},177:function(n,t,r){return(n^t|r)^~n},178:function(n,t,r){return(t^r|n^t)^t},179:function(n,t,r){return~(~(n&r)&t)},180:function(n,t,r){return~r&t^n},181:function(n,t,r){return(r|t)&n^~r},182:function(n,t,r){return(n&r|t)^n^r},183:function(n,t,r){return~((n^r)&t)},184:function(n,t,r){return(r^n)&t^n},185:function(n,t,r){return(r&n|t)^~r},186:function(n,t,r){return~t&n|r},188:function(n,t,r){return~(t&r)&n^t},189:function(n,t,r){return~((r^n)&(r^t))},190:function(n,t,r){return t^n|r},191:function(n,t,r){return~(t&n)|r},193:function(n,t,r){return(~t&r|n)^~t},194:function(n,t,r){return(~(t|r)|n)^~t},196:function(n,t,r){return(~r|n)&t},197:function(n,t,r){return(t^r|n)^~t},198:function(n,t,r){return~n&r^t},199:function(n,t,r){return(n|r)&t^~n},200:function(n,t,r){return(n|r)&t},201:function(n,t,r){return(r|n)^~t},202:function(n,t,r){return(r^t)&n^r},203:function(n,t,r){return(t&r|n)^~t},205:function(n,t,r){return~(n|r)|t},206:function(n,t,r){return~n&r|t},208:function(n,t,r){return(~r|t)&n},209:function(n,t,r){return(n^r|t)^~n},210:function(n,t,r){return~t&r^n},211:function(n,t,r){return(t|r)&n^~t},212:function(n,t,r){return(r^n)&(n^t)^t},213:function(n,t,r){return~(~(t&n)&r)},214:function(n,t,r){return(t&n|r)^t^n},215:function(n,t,r){return~((t^n)&r)},216:function(n,t,r){return(n^t)&r^n},217:function(n,t,r){return(t&n|r)^~t},218:function(n,t,r){return~(r&t)&n^r},219:function(n,t,r){return~((t^r)&(n^t))},220:function(n,t,r){return~r&n|t},222:function(n,t,r){return n^r|t},223:function(n,t,r){return~(n&r)|t},224:function(n,t,r){return(t|r)&n},225:function(n,t,r){return(t|r)^~n},226:function(n,t,r){return(r^n)&t^r},227:function(n,t,r){return(n&r|t)^~n},228:function(n,t,r){return(t^n)&r^t},229:function(n,t,r){return(n&t|r)^~n},230:function(n,t,r){return~(t&n)&r^t},231:function(n,t,r){return~((r^n)&(n^t))},232:function(n,t,r){return(t^r)&(n^t)^t},233:function(n,t,r){return~(t&r)&n^t^~r},234:function(n,t,r){return t&n|r},235:function(n,t,r){return t^~n|r},236:function(n,t,r){return n&r|t},237:function(n,t,r){return n^~r|t},239:function(n,t,r){return~n|r|t},241:function(n,t,r){return~(t|r)|n},242:function(n,t,r){return~t&r|n},244:function(n,t,r){return~r&t|n},246:function(n,t,r){return t^r|n},247:function(n,t,r){return~(t&r)|n},248:function(n,t,r){return t&r|n},249:function(n,t,r){return t^~r|n},251:function(n,t,r){return~t|n|r},253:function(n,t,r){return~r|t|n},254:function(n,t,r){return t|n|r}};Uint8Array.prototype.toJSArray=function(){if(1==this.length)return[this[0]];for(var t=this.length,i=new Array(t),s=0;s<t;s++)i[s]=this[s];return i},wdi.FixedQueue=$.spcExtend(wdi.DomainObject,{q:null,size:10485760,grow:10485760,woffset:0,roffset:0,init:function(t){this.q=new Uint8Array(this.size)},setData:function(t){this.woffset=t.length,this.roffset=0,this.q.set(t)},shift:function(t){if(this.roffset+t>this.woffset)throw"Not enough queue to read";var i=this.q.subarray(this.roffset,this.roffset+t);return this.roffset=this.roffset+t,this.woffset==this.roffset&&(this.woffset=0,this.roffset=0),i},push:function(t){if(this.woffset+t.byteLength>this.size){var i=this.q;this.size+=this.grow,this.q=new Uint8Array(this.size),this.q.set(i)}this.q.set(t,this.woffset),this.woffset+=t.byteLength},getLength:function(){return this.woffset-this.roffset}}),wdi.Queue=$.spcExtend(wdi.DomainObject,{q:null,raw:!1,init:function(t){t.raw&&(this.raw=t.raw),this.q=new Uint8Array(0)},getData:function(){return this.toJSArray(this.q)},setData:function(t){this.q=new Uint8Array(t.length),this.q.set(t)},shift:function(){var t=arguments[0]||this.getLength();if(t===this.q.length){var i=this.q;this.q=new Uint8Array(0)}else{i=this.q.subarray(0,t);this.q=this.q.subarray(t)}return this.toJSArray(i)},peek:function(t,i){var s=null;return s=0!=t||i?this.q.subarray(t,i):this.q,this.toJSArray(s)},push:function(t){if("string"==typeof t){var i=t.length;(e=new Uint8Array(this.q.length+i)).set(this.q);for(var s=0;s<i;s++)e[s+this.q.length]=t[s];this.q=e}else{var e;if(0===this.getLength())this.q=new Uint8Array(t.length),this.q.set(t);else(e=new Uint8Array(t.length+this.q.length)).set(this.q),e.set(t,this.q.length),this.q=e}},getLength:function(){return this.q.length},toJSArray:function(t){return this.raw?t:t.toJSArray()}}),wdi.ViewQueue=$.spcExtend(wdi.DomainObject,{q:null,at:null,init:function(){this.q=new Uint8Array,this.at=0},getData:function(){return this.toJSArray(this.q.subarray(this.at))},getDataOffset:function(t){return this.toJSArray(this.q.subarray(t))},getRawData:function(){return this.q.subarray(this.at)},getRawDataOffset:function(t){return this.q.subarray(t)},setData:function(t){this.q=new Uint8Array(t.length),this.q.set(t),this.at=0},shift:function(t){var i=t||this.getLength();i>this.getLength()&&(i=this.getLength());var s=this.q.subarray(0+this.at,i+this.at);return this.at+=i,this.toJSArray(s)},eatBytes:function(t){this.at+=t},getByte:function(t){return this.q[t+this.at]},peek:function(t,i){var s=null;return 0!=t||i?(i&&(i+=this.at),s=this.q.subarray(t+this.at,i)):s=this.q,this.toJSArray(s)},push:function(t){if("string"==typeof t){var i=t.length;(e=new Uint8Array(this.q.length+i)).set(this.q);for(var s=0;s<i;s++)e[s+this.q.length]=t[s];this.q=e}else{var e;if(0===this.getLength())this.q=new Uint8Array(t.length),this.q.set(t);else(e=new Uint8Array(t.length+this.q.length)).set(this.q),e.set(t,this.q.length),this.q=e}},getLength:function(){return this.q.length-this.at},getPosition:function(){return this.at},toJSArray:function(t){return 1==t.length?[t[0]]:t.toJSArray()}});var syncInstance,asyncInstance;wdi.ImageUncompressor=$.spcExtend(wdi.EventObject.prototype,{init:function(e){this.syncAsyncHandler=e.syncAsyncHandler||new wdi.SyncAsyncHandler({isAsync:e.isAsync})},lzHeaderSize:32,extractLzHeader:function(e,n){var s,c;return n?c=wdi.LZSS.demarshall_rgb(e):("[object Array]"===Object.prototype.toString.call(e)?(s=e.slice(0,this.lzHeaderSize),e=e.slice(this.lzHeaderSize)):(s=e.subarray(0,this.lzHeaderSize).toJSArray(),e=e.subarray(this.lzHeaderSize)),c=wdi.LZSS.demarshall_rgb(s)),{header:c,imageData:e}},processLz:function(e,n,s,c,a,r){var t,i,d,y;e=(t=this.extractLzHeader(e,n)).imageData,y=t.header.width*t.header.height*4,d=new ArrayBuffer(e.length+16),(i=new Uint8Array(d))[0]=1,i[1]=s,i[2]=t.header.type,i[3]=t.header.top_down;for(var o=0;o<4;o++)i[4+o]=255&y,y>>=8;var h=new DataView(d);h.setUint32(8,t.header.width),h.setUint32(12,t.header.height),i.set(e,16),this.syncAsyncHandler.dispatch(d,a,r)},processQuic:function(e,n,s,c,a){wdi.Debug.log("Quic decode"),buffer=new ArrayBuffer(e.length+4),view=new Uint8Array(buffer),view.set(e,4),view[3]=n?1:0,view[0]=0,this.syncAsyncHandler.dispatch(buffer,c,a)},process:function(e,n,s,c,a,r,t){switch(e.type){case wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC:this.processQuic(n,c,a,r,t);break;case wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB:this.processLz(n,s,c,a,r,t)}},dispose:function(){this.syncAsyncHandler.dispose()}}),wdi.ImageUncompressor.dispose=function(){syncInstance&&syncInstance.dispose(),asyncInstance&&asyncInstance.dispose()},wdi.ImageUncompressor.getSyncInstance=function(){return syncInstance||(syncInstance=new wdi.ImageUncompressor({isAsync:!1})),syncInstance},wdi.ImageUncompressor.getAsyncInstance=function(){return asyncInstance||(asyncInstance=new wdi.ImageUncompressor({isAsync:!0})),asyncInstance};wdi.SyncAsyncHandler=$.spcExtend(wdi.EventObject.prototype,{init:function(s){this.isAsync=!!s.isAsync,this.isAsync&&(this.asyncWorker=s.asyncWorker||new wdi.AsyncWorker({script:wdi.spiceClientPath+"/spice-console-minify/WorkerProcess.min.js"}))},isAsync:null,dispatch:function(s,i,n){if(this.isAsync)this.asyncWorker.run(s,i,n);else{var c=window.workerDispatch(s,this.isAsync);i.call(n,c)}},dispose:function(){this.isAsync&&this.asyncWorker.dispose()}});wdi.IntegrationBenchmark={benchmarking:!1,startTime:0,timeoutInterval:3e3,timeOutId:void 0,busConnection:void 0,setEndTime:function(){var t=this;this.timeOutId=setTimeout((function(){t.timeOutId=void 0,t.benchmarking=!1;var e=(new Date).getTime()-t.startTime-t.timeoutInterval;t.onEndBenchmarkCallback(e);var i={type:wdi.BUS_TYPES.killApplicationDoNotUseInProductionEver,application:"EXCEL.EXE"};t.busConnection.send(i)}),this.timeoutInterval)},setStartTime:function(){void 0!==this.timeOutId&&clearTimeout(this.timeOutId)},launchApp:function(t,e){this.busConnection=t,wdi.IntegrationBenchmark.benchmarking=!0,wdi.IntegrationBenchmark.setStartTime(),this.onEndBenchmarkCallback=e,this.startTime=(new Date).getTime();var i={type:wdi.BUS_TYPES.launchApplication,file:"c:\\Users\\eyeos\\Desktop\\test.xlsx"};this.busConnection.send(i)}};wdi.StuckKeysHandler=$.spcExtend(wdi.EventObject.prototype,{ctrlTimeoutId:null,altTimeoutId:null,shiftTimeoutId:null,shiftKeyPressed:!1,ctrlKeyPressed:!1,altKeyPressed:!1,dispose:function(){wdi.Debug.log("Disposing StuckKeysHandler"),clearTimeout(this.ctrlTimeoutId),clearTimeout(this.altTimeoutId),clearTimeout(this.shiftTimeoutId),this.ctrlTimeoutId=null,this.altTimeoutId=null,this.shiftTimeoutId=null,this.shiftKeyPressed=!1,this.ctrlKeyPressed=!1,this.altKeyPressed=!1},handleStuckKeys:function(e){if(e)switch(e.keyCode){case 16:this._handleKey("shiftTimeoutId",e.type,16);break;case 17:this._handleKey("ctrlTimeoutId",e.type,17);break;case 18:this._handleKey("altTimeoutId",e.type,18)}},releaseAllKeys:function(){var e;for(e=0;e<300;e++)this.releaseKeyPressed(e)},_handleKey:function(e,s,t){"keydown"===s?this[e]=this._configureTimeout(t):"keyup"===s&&clearTimeout(this[e])},_configureTimeout:function(e){var s=this;return setTimeout((function(){s.releaseKeyPressed(e)}),wdi.StuckKeysHandler.defaultTimeout)},releaseKeyPressed:function(e){var s=window.jQuery.Event("keyup");s.which=e,s.keyCode=e,s.charCode=0,s.generated=!0,this.fire("inputStuck",["keyup",[s]])},checkSpecialKey:function(e,s){switch(s){case 16:this.shiftKeyPressed="keydown"===e;break;case 17:this.ctrlKeyPressed="keydown"===e;break;case 18:this.altKeyPressed="keydown"===e}},releaseSpecialKeysPressed:function(){this.shiftKeyPressed&&(this.releaseKeyPressed(16),this.shiftKeyPressed=!1),this.ctrlKeyPressed&&(this.releaseKeyPressed(17),this.ctrlKeyPressed=!1),this.altKeyPressed&&(this.releaseKeyPressed(18),this.altKeyPressed=!1)}}),wdi.StuckKeysHandler.defaultTimeout=2e3;wdi.TimeLapseDetector=$.spcExtend(wdi.EventObject.prototype,{lastTime:null,init:function(t){this.superInit()},dispose:function(){this.lastTime=null},startTimer:function(){var t=this;this.lastTime=Date.now(),window.setInterval((function(){var e=Date.now(),i=e-t.lastTime;i>=t.constructor.maxIntervalAllowed&&t.fire("timeLapseDetected",i),t.lastTime=e}),wdi.TimeLapseDetector.defaultInterval)},getLastTime:function(){return this.lastTime},setLastTime:function(t){return this.lastTime=t,this}}),wdi.TimeLapseDetector.defaultInterval=5e3,wdi.TimeLapseDetector.maxIntervalAllowed=3*wdi.TimeLapseDetector.defaultInterval;wdi.DisplayRouter=$.spcExtend(wdi.EventObject.prototype,{init:function(i){this.time=Date.now(),this.clientGui=i.clientGui,this.rasterEngine=i.rasterEngine||new wdi.RasterEngine({clientGui:this.clientGui}),i.routeList?this.routeList=i.routeList:this._initRoutes()},dispose:function(){this.rasterEngine.dispose(),this.clientGui=null,this.rasterEngine=null,this.routeList=null},_initRoutes:function(){wdi.Debug.log("displayRouter",this.time),this.routeList={},this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_CREATE]=this.rasterEngine.drawCanvas,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_DESTROY]=this.rasterEngine.removeCanvas,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY]=this.rasterEngine.drawImage,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL]=this.rasterEngine.drawFill,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND]=this.rasterEngine.drawAlphaBlend,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_WHITENESS]=this.rasterEngine.drawWhiteness,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLACKNESS]=this.rasterEngine.drawBlackness,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT]=this.rasterEngine.drawTransparent,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS]=this.rasterEngine.drawCopyBits,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TEXT]=this.rasterEngine.drawText,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_STROKE]=this.rasterEngine.drawStroke,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ROP3]=this.rasterEngine.drawRop3,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_INVERS]=this.rasterEngine.drawInvers,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CREATE]=this.rasterEngine.handleStreamCreate,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY]=this.rasterEngine.handleStreamDestroy,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA]=this.rasterEngine.handleStreamData,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CLIP]=this.rasterEngine.handleStreamClip,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED]=this.rasterEngine.handleStreamDataSized,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT]=this.rasterEngine.handleStreamActiveReport,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND]=this.rasterEngine.drawBlend,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_LIST]=this.rasterEngine.invalList,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES]=this.rasterEngine.invalPalettes,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_MARK]=!1,this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_RESET]=this.rasterEngine.handleReset},processPacket:function(i){if(i){var t=this.routeList[i.messageType];t&&t.call(this.rasterEngine,i)}else wdi.Debug.log("DisplayProcess processPacket: Skipping empty message...")}});const _SOI=new Uint8Array([255,216]),_EOI=new Uint8Array([255,217]);wdi.RasterEngine=$.spcExtend(wdi.EventObject.prototype,{chunks:[],size:0,jpegInst:null,init:function(e){this.time=Date.now(),this.clientGui=e.clientGui,this.codecH264=wdi.CodecH264,this.codecVp8=wdi.CodecVp8,this.codecH265=wdi.CodecH265},dispose:function(){this.clientGui=null},drawCanvas:function(e){return wdi.Debug.log("rasterEngine",this.time),this.clientGui.drawCanvas(e)},removeCanvas:function(e){return this.clientGui.removeCanvas(e)},invalList:function(e){var t=e.args.items,i=null;for(var a in t)i=t[a],wdi.ImageCache.delImage(i.id)},handleStreamCreate:function(e){var t=e.args;switch(t.computedBox=wdi.graphics.getBoxFromSrcArea(t.rect),wdi.Stream.addStream(e.args.id,t),console.log("%chandleStreamCreate","color:rgb(100,255,100)"),t.codec){case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H264:this.handleH264StreamCreate(t.id);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP8:this.handleVp8StreamCreate(t.id);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP9:break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H265:this.handleH265StreamCreate(t.id)}wdi.graphicDebug&&wdi.graphicDebug.handleStreamInfo()},handleVp8StreamCreate:function(e){this.codecVp8.create(e)},handleH265StreamCreate:async function(e){const t=wdi.Stream.getStream(e),i=this.clientGui.getContext(t.surface_id),a=t.computedBox;this.codecH265.create(e,i,a)},handleH264StreamCreate:function(e){this.codecH264.create(e)},handleStreamData:function(e){switch(wdi.Stream.getStream(e.args.id).codec){case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_MJPEG:this.handleMjpegStream(e);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H264:this.handleH264Stream(e);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP8:this.handleVp8Stream(e);break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_VP9:break;case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H265:this.handleH265Stream(e);break;default:this.handleMjpegStream(e)}},handleStreamClip:function(e){wdi.Stream.clip(e.args.id,e.args.clip),wdi.Stream.startTransition(e.args.id),console.log("%chandleStreamClip","color:rgb(100,100,255)")},handleStreamDataSized:function(e){},handleStreamActiveReport:function(e){},handleStreamDestroy:function(e){wdi.Stream.deleteStream(e.args.surface_id),this.codecH264.destroy(e.args.surface_id),this.codecVp8.destroy(),this.codecH265.destroy(),wdi.graphicDebug&&wdi.graphicDebug.handleStreamInfo(),console.log("%chandleStreamDestroy","color:rgb(255,100,100)")},indexOfBytes:function(e,t,i=0){for(let a=i;a<=e.length-t.length;a++){let i=!0;for(let r=0;r<t.length;r++)if(e[a+r]!==t[r]){i=!1;break}if(i)return a}return-1},concatenateChunks:function(e,t){const i=new Uint8Array(t);let a=0;for(const t of e)i.set(t,a),a+=t.length;return i},pushWholeMjpegFrame:function(e){const t=e.length;let i=0;for(;;)if(this.size){const a=this.indexOfBytes(e,_EOI);if(-1===a){this.chunks.push(e),size+=t;break}{i=a+_EOI.length;const r=e.slice(0,i);if(this.chunks.push(r),this.size+=r.length,this.jpegInst=this.concatenateChunks(chunks,size),this.chunks=[],size=0,i===t)break}}else{const a=this.indexOfBytes(e,_SOI,i);if(-1===a)break;i=a+500;const r=this.indexOfBytes(e,_EOI,i);if(-1===r){const t=e.slice(a);this.chunks=[t],this.size=t.length;break}if(i=r+_EOI.length,this.jpegInst=e.slice(a,i),i===t)break}},handleMjpegStream:function(e){const t=e.args.data,i=wdi.Stream.getStream(e.args.id),a=this.clientGui.getContext(i.surface_id),r=i.computedBox;if(this.pushWholeMjpegFrame(new Uint8Array(t)),this.jpegInst){const e=new Blob([this.jpegInst],{type:"image/jpeg"});createImageBitmap(e).then((e=>{if(i.flags&wdi.SpiceStreamFlags.SPICE_STREAM_FLAGS_TOP_DOWN)a.drawImage(e,r.x,r.y,r.width,r.height);else{const t=r.x+e.width/2,i=r.y+e.height/2;a.save(),a.translate(t,i),a.rotate(Math.PI),a.scale(-1,1),a.drawImage(e,r.x-t,r.y-i,r.width,r.height),a.restore()}})).catch(console.error),this.jpegInst=null}},handleH264Stream:function(e){var t=e.args.data,i=wdi.Stream.getStream(e.args.id);if(this.codecH264.isReady[i.id]){var a=this.clientGui.getContext(i.surface_id);wdi.ExecutionControl.sync=!0,wdi.Stream.endTransition(e.args.id),this.codecH264.loadedVideo[i.id]=()=>{var e=i.computedBox;if(!i.flags&wdi.SpiceStreamFlags.SPICE_STREAM_FLAGS_TOP_DOWN){var t=e.x+this.codecH264.video[i.id].width/2,r=e.y+this.codecH264.video[i.id].height/2;a.save(),a.translate(t,r),a.rotate(Math.PI),a.scale(-1,1),a.drawImage(this.codecH264.video[i.id],e.x-t,e.y-r,e.width,e.height),a.restore()}else{if(!this.codecH264.video[i.id]||!this.codecH264.loadedVideo[i.id])return;if(i.transiting)return void requestAnimationFrame(this.codecH264.loadedVideo[i.id]);a.drawImage(this.codecH264.video[i.id],e.x,e.y,e.width,e.height),requestAnimationFrame(this.codecH264.loadedVideo[i.id])}},this.codecH264.feed(i.id,t)}else this.codecH264.addQueue(i.id,t)},handleH265Stream:function(e){const t=e.args.data,i=wdi.Stream.getStream(e.args.id),a=i.computedBox;this.codecH265.isReady[i.id]?(this.codecH265.configed[i.id]||this.codecH265.setConfig(i.id,a),this.codecH265.decode(i.id,t)):this.codecH265.addQueue(i.id,t)},handleVp8Stream:function(e){var t=e.args.data,i=wdi.Stream.getStream(e.args.id),a=this.clientGui.getContext(i.surface_id),r=i.computedBox;this.codecVp8.feed(i.id,t,a,r)},drawRop3:function(e){var t=wdi.graphics.getBoxFromSrcArea(e.args.base.box),i=this.clientGui.getContext(e.args.base.surface_id),a=i.getImageData(t.x,t.y,t.width,t.height),r=this.clientGui,s=e.args.brush,d=e.args.rop_descriptor,g=wdi.graphics.getBoxFromSrcArea(e.args.src_area);wdi.graphics.getImageFromSpice(e.args.src_image.imageDescriptor,e.args.src_image.data,this.clientGui,(function(e){if(e){var c=e.getContext("2d").getImageData(g.x,g.y,g.width,g.height),h=c.data,o=wdi.graphics.getNewTmpCanvas(t.width,t.height),n=o.getContext("2d"),l={width:t.width,height:t.height,x:0,y:0};wdi.graphics.setBrush(r,n,s,l,wdi.SpiceRopd.SPICE_ROPD_OP_PUT);var w=n.getImageData(0,0,t.width,t.height),p=w.data,m=a.data,u=(n=(o=wdi.graphics.getNewTmpCanvas(t.width,t.height)).getContext("2d")).createImageData(t.width,t.height),f=u.data;c.width!=w.width||c.width!=a.width||c.height!=w.height||(c.height,a.height);for(var S=m.length,C=wdi.Rop3[d],_=0;_<S;_+=4)f[_]=255&C(p[_],h[_],m[_]),f[_+1]=255&C(p[_+1],h[_+1],m[_+1]),f[_+2]=255&C(p[_+2],h[_+2],m[_+2]),f[_+3]=255;n.putImageData(u,0,0),this.drawClip(o,t,i)}else wdi.Debug.log("Unable to get image!")}),this)},drawInvers:function(e){var t=e.args.base,i=wdi.graphics.getBoxFromSrcArea(t.box),a=t.surface_id,r=this.clientGui.getContext(a),s=wdi.graphics.getRect(i,r.canvas),d=wdi.RasterOperation.process(wdi.SpiceRopd.SPICE_ROPD_OP_INVERS,null,s);r.drawImage(d,i.x,i.y,i.width,i.height)},drawStroke:function(e){var t,i,a,r,s=e.args,d=this.clientGui.getContext(e.args.base.surface_id),g=s.brush.color.html_color,c=s.path.num_segments;s.attr.flags&wdi.SpiceLineFlags.SPICE_LINE_FLAGS_STYLED&&wdi.Debug.log("SPICE_LINE_FLAGS_STYLED");for(var h=0;h<c;h++){if((r=s.path.segments[h]).flags&wdi.SpicePathFlags.SPICE_PATH_BEGIN&&(d.beginPath(),d.moveTo(r.points[0].x,r.points[0].y),d.strokeStyle=g,d.lineWidth=1),r.flags&wdi.SpicePathFlags.SPICE_PATH_BEZIER){if((t=r.points.length)%3==0)for(a=0;a<t;a+=3)d.bezierCurveTo(r.points[a].x,r.points[a].y,r.points[a+1].x,r.points[a+1].y,r.points[a+2].x,r.points[a+2].y)}else for(t=r.points.length,a=0;a<t;a++)0==a&&(i=r.points[a]),d.lineTo(r.points[a].x+.5,r.points[a].y+.5);r.flags&wdi.SpicePathFlags.SPICE_PATH_END&&(r.flags&wdi.SpicePathFlags.SPICE_PATH_CLOSE&&d.lineTo(i.x+.5,i.y+.5),d.stroke(),d.closePath())}},drawImage:function(e){var t=e.args,i=t.base,a=i.surface_id,r=t.rop_descriptor,s=(t.scale_mode,wdi.graphics.getBoxFromSrcArea(t.src_area)),d=wdi.graphics.getBoxFromSrcArea(i.box);window.vdiLoadTest&&void 0===window.firstImage&&(window.firstImage=!0),wdi.graphics.getImageFromSpice(t.image.imageDescriptor,t.image.data,this.clientGui,(function(e){if(e){var t;if(window.firstImage)t=e.getContext?e.getContext("2d").getImageData(0,0,e.width,e.height).data.buffer.slice(0):e.data.buffer.slice(0),window.firstImageData=t,window.firstImage=!1;var i=!1;if(s.width!==d.width&&s.height!==d.height){i=!0,e=wdi.graphics.getRect(s,e),e=wdi.graphics.getImageFromData(e);var g=wdi.graphics.getNewTmpCanvas(d.width,d.height);g.getContext("2d").drawImage(e,0,0,s.width,s.height,0,0,d.width,d.height),e=g}if(r!==wdi.SpiceRopd.SPICE_ROPD_OP_PUT){i||(e=wdi.graphics.getRect(s,e));var c=wdi.graphics.getRect(d,this.clientGui.getCanvas(a));e=wdi.RasterOperation.process(r,e,c)}var h=this.clientGui.getContext(a);e instanceof ImageData?i?h.putImageData(e,d.x,d.y,0,0,d.width,d.height):h.putImageData(e,d.x,d.y,s.x,s.y,s.width,s.height):i?h.drawImage(e,d.x,d.y,d.width,d.height):h.drawImage(e,s.x,s.y,s.width,s.height,d.x,d.y,d.width,d.height)}else wdi.Debug.log("Unable to get image!")}),this,{opaque:!0,brush:t.brush,raw:!1})},drawClip:function(e,t,i){i.drawImage(e,t.x,t.y,t.width,t.height)},drawFill:function(e){var t=e.args,i=this.clientGui.getContext(t.base.surface_id),a=wdi.graphics.getBoxFromSrcArea(t.base.box),r=t.brush,s=t.rop_descriptor;wdi.graphics.setBrush(this.clientGui,i,r,a,s)},drawCopyBits:function(e){var t=e.args.base,i=t.surface_id,a=e.args.src_position,r=this.clientGui.getContext(i),s=t.box,d=s.right-s.left,g=s.bottom-s.top;r.drawImage(r.canvas,a.x,a.y,d,g,t.box.left,t.box.top,d,g)},drawBlend:function(e){var t=e.args.image.imageDescriptor,i=e.args.base,a=e.args.image.data,r=e.args.base.surface_id,s=e.args.rop_descriptor;e.args.flags;wdi.graphics.getImageFromSpice(t,a,this.clientGui,(function(t){if(t){var a=wdi.graphics.getBoxFromSrcArea(e.args.src_area);t=wdi.graphics.getRect(a,t);var d=wdi.graphics.getBoxFromSrcArea(i.box),g=wdi.graphics.getRect(d,this.clientGui.getCanvas(r)),c=wdi.RasterOperation.process(s,t,g);this.clientGui.getCanvas(r).getContext("2d").drawImage(c,d.x,d.y,d.width,d.height)}else wdi.Debug.log("There is no image on Blend")}),this)},drawAlphaBlend:function(e){var t=e.args.image.imageDescriptor,i=e.args.base,a=e.args.image.data,r=e.args.base.surface_id,s=e.args.alpha_flags,d=e.args.alpha;wdi.graphics.getImageFromSpice(t,a,this.clientGui,(function(t){t||wdi.Debug.log("There is no image on drawAlphaBlend");var a=wdi.graphics.getBoxFromSrcArea(e.args.src_area);t=wdi.graphics.getRect(a,t);var g=wdi.graphics.getBoxFromSrcArea(i.box),c=wdi.graphics.getRect(g,this.clientGui.getCanvas(r));if(a.width!==g.width&&a.height!==g.height){var h=wdi.graphics.getNewTmpCanvas(g.width,g.height);h.getContext("2d").drawImage(t,0,0,a.width,a.height,0,0,g.width,g.height),t=h}for(var o,n,l,w,p,m,u,f=wdi.graphics.getDataFromImage(t).data,S=wdi.graphics.getDataFromImage(c).data,C=f.length-1,_=wdi.graphics.getNewTmpCanvas(g.width,g.height),x=_.getContext("2d").createImageData(g.width,g.height),I=x.data,b=0;b<C;b+=4)o=f[b],l=f[b+1],p=f[b+2],u=s||255===d?f[b+3]:d,n=S[b],w=S[b+1],m=S[b+2],u>30&&255===d?(I[b]=n*(255-u)/255+o&255,I[b+1]=w*(255-u)/255+l&255,I[b+2]=m*(255-u)/255+p&255):(I[b]=(o*u+n*(255-u))/255&255,I[b+1]=(l*u+w*(255-u))/255&255,I[b+2]=(p*u+m*(255-u))/255&255),I[b+3]=255;_.getContext("2d").putImageData(x,0,0),this.drawClip(_,g,this.clientGui.getContext(r))}),this)},drawWhiteness:function(e){var t=e.args.base,i=this.clientGui.getContext(t.surface_id),a=wdi.graphics.getBoxFromSrcArea(t.box);i.fillStyle="white",i.fillRect(a.x,a.y,a.width,a.height)},drawBlackness:function(e){var t=e.args.base,i=this.clientGui.getContext(t.surface_id),a=wdi.graphics.getBoxFromSrcArea(t.box);i.fillStyle="black",i.fillRect(a.x,a.y,a.width,a.height)},drawTransparent:function(e){var t=e.args.base,i=t.surface_id,a=wdi.graphics.getBoxFromSrcArea(e.args.src_area),r=wdi.graphics.getBoxFromSrcArea(t.box),s=this.clientGui.getContext(i).getImageData(r.x,r.y,r.width,r.height);wdi.graphics.getImageFromSpice(e.args.image.imageDescriptor,e.args.image.data,this.clientGui,(function(t){if(t){t=wdi.graphics.getRect(a,t);for(var d=wdi.graphics.getDataFromImage(t).data,g=s.data,c=d.length-1,h=this.clientGui.getContext(i).createImageData(r.width,r.height),o=e.args.transparent_true_color;c>0;)h.data[c]=255,d[c-1]===o.b&&d[c-2]===o.g&&d[c-3]===o.r?(h.data[c-1]=g[c-1],h.data[c-2]=g[c-2],h.data[c-3]=g[c-3]):(h.data[c-1]=d[c-1],h.data[c-2]=d[c-2],h.data[c-3]=d[c-3]),c-=4;var n=wdi.graphics.getImageFromData(h);this.drawClip(n,r,this.clientGui.getContext(i))}else wdi.Debug.log("Unable to get image!")}),this)},drawText:function(e){var t=this.clientGui.getContext(e.args.base.surface_id),i=(e.args.base.box,e.args.base.clip),a=e.args,r=a.glyph_string,s=1===r.flags?1:2*r.flags;0!==a.back_mode&&wdi.graphics.drawBackText(this.clientGui,t,a),wdi.graphics.drawString(t,r,s,a.fore_brush,i.type,this)},invalPalettes:function(e){wdi.ImageCache.clearPalettes()},handleReset:function(e){}});wdi.DataLogger={testStartTime:0,testStopTime:0,networkStart:0,networkTotalTime:0,data:{},routeList:{},imageTypes:{},startTimes:[],init:function(){this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_CREATE]="drawCanvas",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_DESTROY]="removeCanvas",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY]="drawImage",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL]="drawFill",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND]="drawAlphaBlend",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_WHITENESS]="drawWhiteness",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLACKNESS]="drawBlackness",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT]="drawTransparent",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS]="drawCopyBits",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TEXT]="drawText",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_STROKE]="drawStroke",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ROP3]="drawRop3",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_INVERS]="drawInvers",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CREATE]="handleStreamCreate",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY]="handleStreamDestroy",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA]="handleStreamData",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CLIP]="handleStreamClip",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED]="handleStreamDataSized",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT]="handleStreamActiveReport",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND]="drawBlend",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_LIST]="invalList",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES]="invalPalettes",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_MARK]="displayMark",this.routeList[wdi.SpiceVars.SPICE_MSG_DISPLAY_RESET]="displayReset",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_BITMAP]="bitmap",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_QUIC]="quic",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_RESERVED]="reserved",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_PNG]="png",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_PLT]="lz_plt",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_LZ_RGB]="lz_rgb",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_GLZ_RGB]="glz_rgb",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE]="cache",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_SURFACE]="surface",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG]="jpeg",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS]="cache_lossless",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB]="zlib_glz_rgb",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_JPEG_ALPHA]="jpeg_alpha",this.imageTypes[wdi.SpiceImageType.SPICE_IMAGE_TYPE_CANVAS]="canvas"},setStartTime:function(t){this.startTimes.push(t)},getSpiceMessageType:function(t,e,i){var s=this.routeList[t.messageType];return"drawImage"===s&&(s+="_"+this.imageTypes[t.args.image.imageDescriptor.type]),(e||"")+s+(i||"")},setNetworkTimeStart:function(t){this.networkStart=this.networkStart||t||Date.now()},logNetworkTime:function(){this.networkStart&&(this.networkTotalTime+=Date.now()-this.networkStart,this.networkStart=0)},startTestSession:function(){this.clear(),wdi.logOperations=!0,this.testStartTime=Date.now()},stopTestSession:function(){this.testStopTime=Date.now(),wdi.logOperations=!1},log:function(t,e,i,s,a,S){var _,r=Date.now();_=i||this.getSpiceMessageType(t,a,S),this.data.hasOwnProperty(_)||(this.data[_]=[]),s&&(e=this.startTimes.shift()),this.data[_].push({start:e,end:r})},clear:function(){this.data={},this.testStartTime=0,this.testStopTime=0,this.networkTotalTime=0,this.networkStart=0},getData:function(){return this.data},getStats:function(){var t,e=this.networkTotalTime,i=0,s=e,a=this.testStopTime-this.testStartTime,S=this.data,_={},r="";for(var E in this.data)if(this.data.hasOwnProperty(E)){i+=(t=S[E]).length,_[E]=0;for(var T=0;T<t.length;T++)_[E]+=t[T].end-t[T].start;s+=_[E]}r+="Total operations by number:\n";for(var E in S)S.hasOwnProperty(E)&&(r+=E+": "+~~(S[E].length/i*100)+"% ("+S[E].length+")\n");for(E in r+="Total numOperations: "+i+"\n",r+="---------------------------------\n",r+="\n",r+="Total Operations by time:\n",_)_.hasOwnProperty(E)&&(r+=E+": "+~~(_[E]/a*100)+"% ("+_[E]+"ms)\n");var I=a-s;return r+="Idle: "+~~(I/a*100)+"% ("+I+"ms)\n",r+="Network: "+~~(e/a*100)+"% ("+e+"ms)\n","BEGIN OF PERFORMANCE STATS\n"+(r+="Total time: "+a+"ms \n")+"\nEND OF PERFORMANCE STATS\n"}},wdi.DataLogger.init();wdi.socketStatus={idle:0,prepared:1,connected:2,disconnected:3,failed:4},wdi.Socket=$.spcExtend(wdi.EventObject.prototype,{websocket:null,status:wdi.socketStatus.idle,binary:!1,connect:function(t){var e=this,s="base64";Modernizr.websocketsbinary&&(s="binary",this.binary=!0),this.websocket=new WebSocket(t,s),wdi.Debug.log("Socket: using protocol: "+s),this.binary&&(this.websocket.binaryType="arraybuffer"),this.status=wdi.socketStatus.prepared,this.websocket.onopen=function(){e.status=wdi.socketStatus.connected,e.fire("open")},this.websocket.onmessage=function(t){e.fire("message",t.data)},this.websocket.onclose=function(t){e.status=wdi.socketStatus.disconnected,console.warn("Spice Web Client: ",t.code,t.reason),e.disconnect(),e.fire("close",t)},this.websocket.onerror=function(t){e.status=wdi.socketStatus.failed,e.fire("error",t)}},setOnMessageCallback:function(t){this.websocket.onmessage=t},send:function(t){try{this.websocket.send(this.encode_message(t))}catch(t){this.status=wdi.socketStatus.failed,this.fire("error",t)}},disconnect:function(){this.websocket&&(this.websocket.onopen=function(){},this.websocket.onmessage=function(){},this.websocket.onclose=function(){},this.websocket.onerror=function(){},this.websocket.close(),this.status=wdi.socketStatus.idle,this.binary=!1,this.websocket=null)},setStatus:function(t){this.status=t,this.fire("status",t)},getStatus:function(){return this.status},encode_message:function(t){if(!this.binary)return Base64.encode(t);var e=t.length,s=new ArrayBuffer(e),n=new Uint8Array(s);return n.set(t),n}});wdi.ClusterNodeChooser=$.spcExtend(wdi.EventObject.prototype,{init:function(t){},setNodeList:function(t){this._nodeList=this._shuffle(t),this._nodeListLength=this._nodeList.length,this._currentIndex=0},getAnother:function(){return this._nodeList[this._currentIndex++%this._nodeListLength]},_shuffle:function(t){for(var e,n,i=t.length;i>0;)n=Math.floor(Math.random()*i),e=t[--i],t[i]=t[n],t[n]=e;return t}});wdi.SocketQueue=$.spcExtend(wdi.EventObject.prototype,{rQ:null,sQ:null,socket:null,init:function(t){this.superInit(),this.socket=t.socket||new wdi.Socket,this.rQ=t.rQ||new wdi.FixedQueue,this.sQ=t.sQ||new wdi.Queue,this.setup()},setup:function(){this.socket.addListener("open",(function(){this.fire("open")}),this),this.socket.addListener("message",(function(t){this.rQ.push(new Uint8Array(t)),this.fire("message")}),this),this.socket.addListener("close",(function(t){this.fire("close",t)}),this),this.socket.addListener("error",(function(t){this.fire("error",t)}),this)},getStatus:function(){return this.socket.getStatus()},connect:function(t){this.socket.connect(t)},disconnect:function(){wdi.Debug.log("socket Queue disconnect"),this.socket&&(this.socket.clearEvents(),this.socket.disconnect()),this.rQ=null,this.sQ=null,this.socket=null},send:function(t,s){if(void 0===s)var e=!0;else e=s;this.sQ&&0===this.sQ.getLength()&&e?this.socket.send(t):this.sQ&&(this.sQ.push(t),e&&this.flush())},flush:function(){var t=this.sQ.shift();this.socket.send(t)}});wdi.PacketController=$.spcExtend(wdi.EventObject.prototype,{sizeDefiner:null,packetExtractor:null,init:function(t){this.superInit(),this.sizeDefiner=t.sizeDefiner,this.packetExtractor=t.packetExtractor},dispose:function(){wdi.Debug.log("PacketTroller dispose"),this.clearEvents(),this.packetExtractor.dispose(),this.packetExtractor=null,this.sizeDefiner=null},getNextPacket:function(t){var e=this;wdi.logOperations&&wdi.DataLogger.setNetworkTimeStart();var i=this.sizeDefiner.getSize(t);this.packetExtractor.getBytes(i,(function(t){var i=this.sizeDefiner.getStatus();this.execute(new wdi.RawMessage({status:i,data:t})),e.getNextPacket(t)}),this)},execute:function(t){try{this.fire("chunkComplete",t)}catch(t){console.error("PacketTroller: ",t)}}});wdi.PacketExtractor=$.spcExtend(wdi.EventObject.prototype,{socketQ:null,numBytes:null,callback:null,scope:null,init:function(t){this.superInit(),this.socketQ=t.socketQ,this.setListener()},dispose:function(){this.clearEvents(),this.socketQ.disconnect(),this.socketQ=null,this.numBytes=null,this.callback=null,this.scope=null},setListener:function(){this.socketQ.addListener("message",(function(){wdi.logOperations&&wdi.DataLogger.setNetworkTimeStart(),this.getBytes(this.numBytes,this.callback,this.scope)}),this)},getBytes:function(t,s,e){var i,n=this.socketQ.rQ.getLength();(this.numBytes=t,this.callback=s,this.scope=e,null!==t&&n>=t)?(i=t?this.socketQ.rQ.shift(t):new Uint8Array(0),this.numBytes=null,this.callback=null,this.scope=null,s.call(e,i)):wdi.logOperations&&wdi.DataLogger.logNetworkTime()}});wdi.PacketReassembler=$.spcExtend(wdi.EventObject.prototype,{packetController:null,currentHeader:null,statusToString:null,sizeDefinerConstant:null,init:function(t){this.superInit(),this.packetController=t.packetController,this.sizeDefinerConstant=wdi.SizeDefiner.prototype,this.statusToString=[],this.statusToString[this.sizeDefinerConstant.STATUS_REPLY_BODY]="reply",this.statusToString[this.sizeDefinerConstant.STATUS_ERROR_CODE]="errorCode",this.statusToString[this.sizeDefinerConstant.STATUS_BODY]="spicePacket",this.setListeners()},dispose:function(){wdi.Debug.log("packetReassembler dispose"),this.clearEvents(),this.packetController.dispose(),this.packetController=null,this.currentHeader=null,this.statusToString=null,this.sizeDefinerConstant=null},start:function(){this.packetController.getNextPacket()},setListeners:function(){this.packetController.addListener("chunkComplete",(function(t){var e=t,s=e.status;switch(s){case this.sizeDefinerConstant.STATUS_HEADER:case this.sizeDefinerConstant.STATUS_REPLY:this.currentHeader=e;break;case this.sizeDefinerConstant.STATUS_REPLY_BODY:case this.sizeDefinerConstant.STATUS_BODY:var i=new Uint8Array(e.data.length+this.currentHeader.data.length);i.set(this.currentHeader.data),i.set(e.data,this.currentHeader.data.length),e.data=i,e.status=this.statusToString[s],this.fire("packetComplete",e);break;default:e.status=this.statusToString[s],this.fire("packetComplete",e)}}),this)}});wdi.ReassemblerFactory={getPacketReassembler:function(e){var t=this.getPacketExtractor(e),r=this.getSizeDefiner(),n=this.getPacketController(t,r);return new wdi.PacketReassembler({packetController:n})},getPacketExtractor:function(e){return new wdi.PacketExtractor({socketQ:e})},getSizeDefiner:function(){return new wdi.SizeDefiner},getPacketController:function(e,t){return new wdi.PacketController({packetExtractor:e,sizeDefiner:t})}};wdi.SizeDefiner=$.spcExtend(wdi.DomainObject,{ERROR_CODE_SIZE:4,status:null,STATUS_READY:0,STATUS_REPLY:1,STATUS_REPLY_BODY:2,STATUS_ERROR_CODE:3,STATUS_MESSAGE:4,STATUS_HEADER:5,STATUS_BODY:6,isHeader:!1,init:function(t){this.status=this.STATUS_READY},getSize:function(t){return this.STATUS_READY===this.status?(this.status++,wdi.SpiceLinkHeader.prototype.objectSize):this.STATUS_REPLY===this.status?(this.status++,this.getReplyBodySize(t)):this.STATUS_REPLY_BODY===this.status?(this.status++,this.ERROR_CODE_SIZE):this.STATUS_ERROR_CODE===this.status?(this.status++,this.isHeader=!0,6):this.isHeader?(this.isHeader=!1,this.getBodySizeFromArrayHeader(t)):(this.isHeader=!0,6)},getReplyBodySize:function(t){var e=wdi.GlobalPool.create("ViewQueue");e.setData(t);var i=(new wdi.SpiceLinkHeader).demarshall(e);return wdi.GlobalPool.discard("ViewQueue",e),i.size},getBodySizeFromArrayHeader:function(t){var e=wdi.GlobalPool.create("ViewQueue");e.setData(t);var i=(new wdi.SpiceDataHeader).demarshall(e);return wdi.GlobalPool.discard("ViewQueue",e),i.size},getStatus:function(){return this.status===this.STATUS_MESSAGE&&this.isHeader?this.STATUS_HEADER:this.status!==this.STATUS_MESSAGE||this.isHeader?this.status:this.STATUS_BODY}});wdi.PacketLinkFactory={extract:function(e,i){switch(e.type){case wdi.SpiceVars.SPICE_MSG_SET_ACK:return(new wdi.RedSetAck).demarshall(i);case wdi.SpiceVars.SPICE_MSG_PING:return(new wdi.RedPing).demarshall(i,e.size);case wdi.SpiceVars.SPICE_MSG_MIGRATE:return(new wdi.RedMigrate).demarshall(i);case wdi.SpiceVars.SPICE_MSG_MIGRATE_DATA:return(new wdi.RedMigrateData).demarshall(i,e.size);case wdi.SpiceVars.SPICE_MSG_WAIT_FOR_CHANNELS:return(new wdi.RedWaitForChannels).demarshall(i);case wdi.SpiceVars.SPICE_MSG_DISCONNECTING:return(new wdi.RedDisconnect).demarshall(i);case wdi.SpiceVars.SPICE_MSG_NOTIFY:return(new wdi.RedNotify).demarshall(i);case wdi.SpiceVars.SPICE_MSG_MAIN_MOUSE_MODE:return(new wdi.SpiceMouseMode).demarshall(i)}}},wdi.PacketLinkProcess={process:function(e,i,a){switch(e.type){case wdi.SpiceVars.SPICE_MSG_SET_ACK:var r=wdi.SpiceObject.numberTo32(i.generation);a.setAckWindow(i.window),a.sendObject(r,wdi.SpiceVars.SPICE_MSGC_ACK_SYNC);break;case wdi.SpiceVars.SPICE_MSG_PING:r=new wdi.RedPing({id:i.id,time:i.time}).marshall();a.sendObject(r,wdi.SpiceVars.SPICE_MSGC_PONG);break;case wdi.SpiceVars.SPICE_MSG_MAIN_MOUSE_MODE:a.fire("mouseMode",i.current_mode);break;case wdi.SpiceVars.SPICE_MSG_NOTIFY:a.fire("notify")}}};wdi.SpiceChannel=$.spcExtend(wdi.EventObject.prototype,{counter:0,ackWindow:0,connectionId:0,socketQ:null,packetReassembler:null,channel:1,codec:wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_MJPEG,proxy:null,token:null,init:function(e){this.superInit(),this.socketQ=e.socketQ||new wdi.SocketQueue,this.packetReassembler=e.packetReassembler||wdi.ReassemblerFactory.getPacketReassembler(this.socketQ),this.setListeners(),this.ackWindow=0},fireHandshakeTimeoutError:function(){var e=new Error("Handshake timeout");e.code=4200,wdi.Debug.error("Handshake timeout reached, raising error"),this.fire("error",e)},setListeners:function(){var e,i=this;this.packetReassembler.addListener("packetComplete",(function(t){var s=t;if("spicePacket"===s.status){wdi.Debug.log("packetComplete spicePacket"),wdi.logOperations&&(wdi.DataLogger.logNetworkTime(),e=Date.now());var a=this.getRawSpiceMessage(s.data);a&&(wdi.logOperations&&a.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY&&wdi.DataLogger.setStartTime(e),this.fire("message",a))}else if("reply"===s.status){wdi.Debug.log("packetComplete reply");var n=this.getRedLinkReplyBytes(s.data);this.send(n)}else if("errorCode"===s.status){wdi.Debug.log("packetComplete errorCode"),(n=this.getErrorCodeBytes(s.data))&&(this.send(n),this.channel,wdi.SpiceVars.SPICE_CHANNEL_DISPLAY),this.fire("channelConnected")}else i.fireHandshakeTimeoutError()}),this),this.socketQ.addListener("open",(function(){var e=this.getRedLinkMessBytes();this.send(e),this.proxy&&this.proxy.end()}),this),this.socketQ.addListener("close",(function(e){1===this.channel&&this.fire("error",e),this.socketQ.disconnect()}),this),this.socketQ.addListener("error",(function(e){this.fire("error",e),this.socketQ.disconnect()}),this)},changeCodec:function(e){this.sendObject([...wdi.SpiceObject.numberTo16(2),...wdi.SpiceObject.numberTo16(e),...wdi.SpiceObject.numberTo16(3)],wdi.SpiceVars.SPICE_MSGC_DISPLAY_PREFERRED_VIDEO_CODEC_TYPE),wdi.currentCodec=e;const{$console:i}=useNuxtApp();i.changeCodec(e),console.log(`codec changed: ${e}`)},connect:function(e,i,t,s){var a=wdi.Utils.generateWebSocketUrl(e.protocol,e.host,e.port,e.vmHost,e.vmPort,"spice",e.vmInfoToken,e.vmid);this.channel=i,this.connectionId=t||0,this.socketQ.connect(a),this.proxy=s,this.token=e.token,this.packetReassembler.start()},disconnect:function(){wdi.Debug.log("spicechannel disconnect"),this.counter=0,this.ackWindow=0,this.connectionId=0,this.socketQ.disconnect(),this.socketQ=null,this.packetReassembler.dispose(),this.packetReassembler=null,this.channel=1,this.proxy=null,this.token=null},send:function(e,i){this.socketQ.send(e,i)},sendObject:function(e,i,t){for(var s=0;s<e.length;s+=2048){var a=e.slice(s,s+2048),n=new wdi.SpiceDataHeader({type:i,size:a.length}).marshall();n=n.concat(a),this.send(n,t)}},arrayOfNumberToUint32:function(e){let i=0;for(let t of e)i|=1<<t;return i},setAckWindow:function(e){this.ackWindow=e,this.counter=0},getRawSpiceMessage:function(e){var i=wdi.GlobalPool.create("ViewQueue"),t=wdi.GlobalPool.create("ViewQueue"),s=new Uint8Array(e,0,wdi.SpiceDataHeader.prototype.objectSize);i.setData(s);var a=(new wdi.SpiceDataHeader).demarshall(i);wdi.GlobalPool.discard("ViewQueue",i);var n=e.subarray(wdi.SpiceDataHeader.prototype.objectSize);if(t.setData(n),this.counter++,this.ackWindow&&this.counter===this.ackWindow){this.counter=0;var c=new wdi.SpiceDataHeader({type:wdi.SpiceVars.SPICE_MSGC_ACK,size:0}).marshall();this.send(c)}var r=wdi.PacketLinkFactory.extract(a,t)||!1;if(r)return wdi.PacketLinkProcess.process(a,r,this),wdi.GlobalPool.discard("ViewQueue",t),!1;var o=wdi.GlobalPool.create("RawSpiceMessage");return o.set(a,t,this.channel),o},getRedLinkReplyBytes:function(e){if(this.token){var i=new wdi.ViewQueue;i.setData(e),i.eatBytes(wdi.SpiceLinkHeader.prototype.objectSize);var t=(new wdi.SpiceLinkReply).demarshall(i);const s=window.password||this.token;return wdi.SpiceObject.stringHexToBytes(RSA_public_encrypt(s,t.pub_key))}return wdi.SpiceObject.stringToBytesPadding("",128)},getRedLinkMessBytes:function(){var e=new wdi.SpiceLinkHeader({magic:1363428690,major_version:2,minor_version:2,size:26}).marshall(),i=new wdi.SpiceLinkMess({connection_id:this.connectionId,channel_type:this.channel,caps_offset:18,num_common_caps:1,num_channel_caps:1,common_caps:1<<wdi.SpiceVars.SPICE_COMMON_CAP_MINI_HEADER,channel_caps:this.arrayOfNumberToUint32([wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_SIZED_STREAM,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_STREAM_REPORT,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_MONITORS_CONFIG,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_MULTI_CODEC,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_MJPEG,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_VP8,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_H264,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_VP9,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_CODEC_H265,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_LZ4_COMPRESSION,wdi.SpiceDisplayCaps.SPICE_DISPLAY_CAP_PREF_COMPRESSION])}).marshall();return e.concat(i)},getErrorCodeBytes:function(e){var i=wdi.GlobalPool.create("ViewQueue");i.setData(e);var t=wdi.SpiceObject.bytesToInt32NoAllocate(i);wdi.GlobalPool.discard("ViewQueue",i);let s=this.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY?"display":"main";switch(this.channel){case wdi.SpiceVars.SPICE_CHANNEL_MAIN:s="main";break;case wdi.SpiceVars.SPICE_CHANNEL_DISPLAY:s="display";break;case wdi.SpiceVars.SPICE_CHANNEL_INPUTS:s="inputs";break;case wdi.SpiceVars.SPICE_CHANNEL_CURSOR:s="cursor";break;case wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK:s="playback";break;case wdi.SpiceVars.SPICE_CHANNEL_RECORD:s="record";break;case wdi.SpiceVars.SPICE_CHANNEL_TUNNEL:s="tunnel";break;case wdi.SpiceVars.SPICE_CHANNEL_SMARTCARD:s="smartcard";break;case wdi.SpiceVars.SPICE_CHANNEL_USBREDIR:s="usbredir"}if(7===t?console.log(`%c error code: 7; channel: ${s} (${this.channel})`,"color: red"):console.log("getErrorCodeBytes",`error code: ${t}`,`channel: ${s} (${this.channel})`),0===t){if(this.channel===wdi.SpiceVars.SPICE_CHANNEL_DISPLAY){var a=new wdi.SpiceDataHeader({type:wdi.SpiceVars.SPICE_MSGC_DISPLAY_INIT,size:14}).marshall(),n=new wdi.SpiceCDisplayInit({pixmap_cache_id:1,pixmap_cache_size:1,glz_dictionary_id:0,glz_dictionary_window_size:0}).marshall();return a.concat(n)}if(this.channel==wdi.SpiceVars.SPICE_CHANNEL_MAIN)return new wdi.SpiceDataHeader({type:wdi.SpiceVars.SPICE_MSGC_MAIN_ATTACH_CHANNELS,size:0}).marshall()}else{if(7!==t)throw new wdi.Exception({message:"Server refused client",errorCode:2});if(this.channel===wdi.SpiceVars.SPICE_CHANNEL_MAIN){const e=location.pathname.match(/id=(.+)/)[1];let i=window.sessionStorage.getItem(`password-${e}`);window.passwordInit&&(i=""),window.password=i||window.prompt("Enter the password"),window.password&&window.sessionStorage.setItem(`password-${e}`,window.password),window.passwordInit=!0}}}});wdi.BusConnection=$.spcExtend(wdi.EventObject.prototype,{ws:null,subscriptions:[],_busUser:null,_busPass:null,queue:"",binary:!1,init:function(s){this.superInit(),this.ws=s.websocket||new wdi.WebSocketWrapper,this.clusterNodeChooser=s.clusterNodeChooser||new wdi.ClusterNodeChooser,this.binary=s.binary||!1},connect:function(s){s.useBus?(this._vdiBusToken=s.vdiBusToken,s.busHostList||(wdi.Debug.warn("Deprecated: using old busHost & busPort params"),s.busHostList=[{host:s.busHost,port:s.busPort}]),this.clusterNodeChooser.setNodeList(s.busHostList),Modernizr.websocketsbinary&&(this.binary=!0),this._busUser=s.busUser,this._busPass=s.busPass,this._websockifyProtocol=s.protocol,this._websockifyHost=s.host,this._websockifyPort=s.port,this.subscriptions=s.busSubscriptions,this._connectToNextHost()):wdi.Debug.warn("Not using the bus")},_connectToNextHost:function(){var s=this.clusterNodeChooser.getAnother(),t=wdi.Utils.generateWebSocketUrl(this._websockifyProtocol,this._websockifyHost,this._websockifyPort,s.host,s.port,"raw",this._vdiBusToken),e="base64";this.binary&&(e="binary"),this.ws.connect(t,e),wdi.Debug.log("BusConnection: using protocol: "+e),this.binary&&this.ws.setBinaryType("arraybuffer"),this.setListeners()},disconnect:function(){this.ws.close(),this.queue="",this.subscriptions=[]},setListeners:function(){var s=this;this.ws.onOpen((function(t){s._send("CONNECT\nlogin:"+s._busUser+"\npasscode:"+s._busPass+"\n\n\0")})),this.ws.onMessage((function(t){var e,n;s.binary?(e=String.fromCharCode.apply(null,new Uint8Array(t.data)),e=decodeURIComponent(escape(e))):e=Base64.decodeStr(t.data);var i=e.split("\0");if(1==i.length)s.queue+=i[0];else{for(var o=0;o<i.length-1;o++)e=s.queue+i[o],n=s.parseMessage(e),s.fire("busMessage",n),s.queue="";s.queue=i[i.length-1]}})),this.ws.onClose((function(t){wdi.Debug.log("BusConnection CLOSED! connecting again in 1 second"),s.fire("error",t)})),this.ws.onError((function(s){wdi.Debug.error("BusConnection ERROR:",s)}))},parseMessage:function(s){try{var t=s.split("\n\n"),e=t[0].trim(),n=t[1].replace(/\x00/,"").trim();n=0!=n.length?JSON.parse(n):null;var i=(t=e.split("\n")).shift();e="{";for(var o=t.length,r=0;r<o;r++){var u=t[r].split(":")[0];e+='"'+u+'":"'+t[r].replace(u+":","")+'"',r!=o-1&&(e+=",")}return e+="}",{verb:i,header:JSON.parse(e),body:n}}catch(s){return wdi.Debug.error("Error parsing Bus Info: ",s),{verb:"ERROR"}}},setSubscriptions:function(){for(var s=this.subscriptions.length,t=0;t<s;t++)this.subscribe(this.subscriptions[t])},send:function(s){var t=this.subscriptions[0];this._send("SEND\ndestination:"+t+"\ncontent-type:text/plain\n\n"+JSON.stringify(s)+"\0")},subscribe:function(s){this._send("SUBSCRIBE\ndestination:"+s+"\n\n\0")},_send:function(s){this.binary?this.ws.send(s):this.ws.send(Base64.encodeStr(s))}});wdi.WebSocketWrapper=$.spcExtend({},{ws:{},onopen:null,onmessage:null,onclose:null,onerror:null,init:function(){},connect:function(n,o){this.ws=new WebSocket(n,o)},onOpen:function(n){this.ws.onopen=n},onMessage:function(n){this.ws.onmessage=n},onClose:function(n){this.ws.onclose=n},onError:function(n){this.ws.onerror=n},setBinaryType:function(n){this.ws.binaryType=n},close:function(){this.ws&&this.ws.close&&(this.ws.close(),this.ws.onopen=function(){},this.ws.onmessage=function(){},this.ws.onclose=function(){},this.ws.onerror=function(){},this.onopen=function(){},this.onmessage=function(){},this.onclose=function(){},this.onerror=function(){})},send:function(n){this.ws.send(n)}});wdi.ConnectionControl=$.spcExtend(wdi.EventObject.prototype,{socket:null,pendingTimeToConnectionLost:null,previousTimeOut:null,init:function(t){this.superInit(),this.socket=t.socket||new wdi.Socket},connect:function(t){var n=wdi.Utils.generateWebSocketUrl(t.protocol,t.host,t.port,null,null,"raw",t.heartbeatToken);this.socket.connect(n),this.pendingTimeToConnectionLost=t.heartbeatTimeout,wdi.Debug.log("ConnectionControl: connected"),this.setListeners()},disconnect:function(){wdi.Debug.log("Connection Control disconnect"),this.previousTimeOut&&clearTimeout(this.previousTimeOut),this.socket.disconnect(),this.socket=null,this.pendingTimeToConnectionLost=null,this.previousTimeOut=null},setListeners:function(){var t=this;this.socket.setOnMessageCallback((function(n){wdi.Debug.log("ConectionControl: beat"),clearTimeout(t.previousTimeOut),t.previousTimeOut=setTimeout((function(){wdi.Debug.log("ConnectionControl: firing connectionLost event"),t.fire("connectionLost",n)}),t.pendingTimeToConnectionLost)}))}});wdi.CheckActivity=$.spcExtend(wdi.EventObject.prototype,{init:function(t){this.superInit(),this.milliseconds=t||6e5,this.eventHandlers={keydown:this.resetActivity.bind(this),mousemove:this.resetActivity.bind(this),click:this.resetActivity.bind(this)},this.activityTimeout=this.createTimeout(),$(document).on(this.eventHandlers)},resetActivity:function(t){clearTimeout(this.activityTimeout),this.activityTimeout=this.createTimeout()},createTimeout:function(){var t=this;return setTimeout((function(){t.fire("activityLost")}),this.milliseconds)},dispose:function(){$(document).off(this.eventHandlers),clearTimeout(this.activityTimeout)}});wdi.Agent=$.spcExtend(wdi.EventObject.prototype,{clientTokens:null,serverTokens:10,app:null,clipboardEnabled:!0,windows:null,clipboard:null,DELAY_BETWEEN_GRAB_AND_CTRLV:30,init:function(e){this.superInit(),this.app=e.app,this.clipboard=new wdi.Clipboard},dispose:function(){this.clientTokens=null,this.serverTokens=10,this.app=null,this.clipboardContent=null,this.clipboardEnabled=!0,this.windows=null},sendInitMessage:function(){var e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_START,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.SpiceMsgMainAgentTokens({num_tokens:this.serverTokens})});this.app.spiceConnection.send(e);var n=1<<wdi.AgentCaps.VD_AGENT_CAP_MONITORS_CONFIG;this.clipboardEnabled&&(n|=1<<wdi.AgentCaps.VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);var s={type:wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES,opaque:0,data:new wdi.VDAgentAnnounceCapabilities({request:0,caps:n})};this.sendAgentPacket(s)},setResolution:function(e,n){e<800&&(e=800),n<600&&(n=600);var s={type:wdi.AgentMessageTypes.VD_AGENT_MONITORS_CONFIG,opaque:0,data:new wdi.VDAgentMonitorsConfig({num_of_monitors:1,flags:0,data:new wdi.VDAgentMonConfig({width:e,height:n,depth:32,x:0,y:0})})};this.sendAgentPacket(s)},setClientTokens:function(e){this.clientTokens=e},sendAgentPacket:function(e){this.clientTokens--;var n=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.VDAgentMessage({protocol:1,type:e.type,opaque:e.opaque,data:e.data})});this.app.spiceConnection.send(n)},sendServerTokens:function(){var e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_TOKEN,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.SpiceMsgMainAgentTokens({num_tokens:10})});this.app.spiceConnection.send(e),this.serverTokens=10},onAgentData:function(e){if(this.serverTokens--,0==this.serverTokens&&this.sendServerTokens(),e.type==wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES);else if(e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB){var n=this.clipboard.createRequest(e.clipboardType);this.sendAgentPacket(n)}else if(e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD)this.fire("clipBoardData",e.clipboardData);else if(e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST){n=this.clipboard.createContent();this.sendAgentPacket(n)}else e.type==wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_RELEASE||e.type==wdi.AgentMessageTypes.VD_AGENT_REPLY||(e.type==wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_TOKEN?this.clientTokens+=e.args.num_tokens:console.warn("unknown message received by agent",e))},setClipboard:function(e){this.clipboard.setContent(e);var n=this.clipboard.createGrab();this.sendAgentPacket(n)},disableClipboard:function(){this.clipboardEnabled=!1}});wdi.CodecH264={video:{},jmuxer:{},loadedVideo:{},queues:{},isReady:{},create:function(e){if(this.video[e])return;const t=document.createElement("video");t.id=`video${e}`,t.setAttribute("autoplay",""),this.video[e]=t,this.jmuxer[e]=new JMuxer({node:t,mode:"video",flushingTime:0,fps:60,onReady:()=>{this.isReady[e]=!0}})},addQueue:function(e,t){this.queues[e]||(this.queues[e]=[]),this.queues[e].push(t)},resetQueues:function(e){this.queues[e]=[]},feed:function(e,t){this._addListener(e),this.queues[e]?.length&&(this.queues[e].forEach((t=>{this.jmuxer[e].feed({video:t})})),this.resetQueues(e)),this.jmuxer[e].feed({video:t})},destroy:function(e){this._removeListener(e),this.video[e]?.remove(),this.video={},this.jmuxer={},this.loadedVideo={}},_addListener:function(e){this.video[e]?.removeEventListener("loadedmetadata",this.loadedVideo[e]),this.video[e].addEventListener("loadedmetadata",this.loadedVideo[e])},_removeListener:function(e){this.video[e]?.removeEventListener("loadedmetadata",this.loadedVideo[e])}},wdi.CodecVp8={decoders:{},create:function(e){this.decoders[e]=new vp8_decoder_ctx},destroy:function(){this.decoders={}},feed:function(e,t,i,d){const s=vp8_dixie_decode_frame(this.decoders[e],t,t.length);VPX_CODEC_OK===s&&this._I420toRGBA(this.decoders[e].ref_frames[0].img,i,d)},_I420toRGBA:function(e,t,i){const d=e.w,s=e.d_h,o=e.d_w;let n,r,u,a=t.createImageData(o,s),h=a.data;for(let t=0;t<s;t++)for(let i=0;i<o;i++){const a=e.planes[0][e.planes_off[0]+0+i+d*t],c=e.planes[1][e.planes_off[1]+0+(i>>1)+(d>>1)*(t>>1)],f=e.planes[2][e.planes_off[2]+0+(i>>1)+(d>>1)*(t>>1)];n=Math.round(a+1.13983*(f-128)),r=Math.round(a-.39465*(c-128)-.5806*(f-128)),u=Math.round(a+2.03211*(c-128));const m=4*((s-1-t)*o+i);h[m]=n,h[m+1]=r,h[m+2]=u,h[m+3]=255}t.putImageData(a,i.x,i.y)}},wdi.CodecH265={queue:{},configed:{},isReady:{},decoders:{},pendingFrames:{},underflow:{},baseTime:{},create:async function(e,t,i){const d={output:this._handleFrame.bind(this,e,t,i),error:e=>{console.log(e)}},s={codec:wdi.SpiceVideoCodecValue[wdi.currentCodec],codedWidth:640,codedHeight:480},{supported:o}=await VideoDecoder.isConfigSupported(s);o?(this.decoders[e]=new VideoDecoder(d),this.decoders[e].configure(s),this.isReady[e]=!0):(window.alert("H.265 codec is not supported in this browser. Please try a different codec or use another browser."),console.log("not supported"))},destroy:function(){this.queue={},this.configed={},this.isReady={},this.decoders={},this.pendingFrames={},this.underflow={},this.baseTime={}},addQueue:function(e,t){this.queues[e]||(this.queues[e]=[]),this.queues[e].push(t)},resetQueues:function(e){this.queues[e]=[]},setConfig:function(e,t){const i={codec:wdi.SpiceVideoCodecValue[wdi.currentCodec],codedWidth:t.width,codedHeight:t.height};this.decoders[e].configure(i),this.configed[e]=!0},decode:function(e,t){this.queue[e]?.length&&(this.queue[e].forEach((t=>{const i=new EncodedVideoChunk({type:"key",data:t,timestamp:performance.now()});this.decoders[e].decode(i)})),this.resetQueues(e));const i=new EncodedVideoChunk({type:"key",data:t,timestamp:performance.now()});this.decoders[e].decode(i)},_handleFrame:function(e,t,i,d){this.pendingFrames[e]||(this.pendingFrames[e]=[]),this.pendingFrames[e].push(d),void 0===this.underflow[e]&&(this.underflow[e]=!0),this.underflow[e]&&setTimeout(this._renderFrame.bind(this,e,t,i),0)},_renderFrame:async function(e,t,i){if(this.underflow[e]=0===this.pendingFrames[e].length,this.underflow[e])return;const d=this.pendingFrames[e].shift(),s=this._calculateTimeUntilNextFrame(d.timestamp,e);await new Promise((e=>{setTimeout(e,s)})),t.drawImage(d,i.x,i.y,i.width,i.height),d.close(),setTimeout(this._renderFrame.bind(this,e,t,i),0)},_calculateTimeUntilNextFrame:function(e,t){this.baseTime[t]||(this.baseTime[t]=performance.now());const i=performance.now()-this.baseTime[t];return Math.max(0,e/1e3-i)}};wdi.Clipboard=$.spcExtend(wdi.EventObject.prototype,{_blob:null,_type:null,getSpiceType:function(e){switch(e){case"text/plain":return wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT;case"image/png":return wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_IMAGE_PNG;default:throw new Error("Unsupported mime type "+e)}},getMimeType:function(e){switch(e){case wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT:return"text/plain";case wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_IMAGE_PNG:return"image/png";default:throw new Error("Unsupported spice type "+e)}},createGrab:function(){return{type:wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB,opaque:0,data:new wdi.VDAgentClipboardGrab({types:[this.getSpiceType(this._type)]})}},createRequest:function(e){return{type:wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST,opaque:0,data:new wdi.VDAgentClipboardRequest({type:e})}},createContent:function(){return{type:wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD,opaque:0,data:new wdi.VDAgentClipboard({type:this.getSpiceType(this._type),data:this._blob})}},setContent:function(e){this._type=e.type,this._blob=e.blob},getContent:function(){return{blob:this._blob,type:this._type}}});wdi.ClipboardDataParser=$.spcExtend(wdi.EventObject.prototype,{fileReader:null,init:function(e){this.fileReader=e.FileReader||FileReader},parse:function(e,t){var n=this,r=["image/png","text/plain"];function i(e,t){switch(e.kind){case"string":return function(e,t){var n=e.type;e.getAsString((function(e){return t({type:n,blob:e})}))}(e,t);case"file":return function(e,t){var r=e.type,i=e.getAsFile(),a=new n.fileReader;a.addEventListener("loadend",(function(){return t({type:r,blob:a.result})})),a.readAsArrayBuffer(i)}(e,t)}}var a=e.items;if(a)for(var l=0;l<r.length;l++)for(var f=r[l],s=0;s<a.length;s++){var o=a[s];if(o.type==f)return i(o,t)}else if(e.getData){f="text/plain";e.types.contains(f)&&t({type:f,blob:e.getData(f)})}}});wdi.LocalClipboard=$.spcExtend(wdi.EventObject.prototype,{init:function(o){this.clipboardContainer=$('<div style="position:absolute;top:-10000000px;"><textarea id="remoteClipboard" style="position:absolute;top:-10000000px;font-size: 20px;color:black;z-index: 100" rows="4" cols="50"></textarea></div>'),$("#vmw").prepend(this.clipboardContainer),this.clientGui=o.clientGui,this.eventHandlers={keydown:this.triggerCopyToClipboard.bind(this)},$(document).on(this.eventHandlers),this.delayCopyEvents={mousedown:this.copyToClipboard.bind(this),mouseup:this.copyToClipboard.bind(this),keydown:this.copyToClipboard.bind(this),keyup:this.copyToClipboard.bind(this)},$(document).on(this.delayCopyEvents)},updateClipboardBuffer:function(o){$("#remoteClipboard").val(o)},triggerCopyToClipboard:function(o){(function(o){var e=o.ctrlKey;return-1!=navigator.appVersion.indexOf("Mac")&&(e=o.metaKey),67===o.keyCode&&e})(o)&&(this.clipboardCopyDelay=Date.now()+1e3,o.preventDefault(),this.copyToClipboard(o))},copyToClipboard:function(o){if(this.clipboardCopyDelay&&!(this.clipboardCopyDelay<Date.now())){!function(o){$("#remoteClipboard").focus();try{var e=document.execCommand("copy");$("#remoteClipboard").blur(),$("#inputmanager").focus(),console.log("Result executeCommand",o.type,"-----",e)}catch(o){console.error(o)}}(o)}},dispose:function(){this.clipboardContainer.remove(),$(document).off(this.eventHandlers),$(document).off(this.delayCopyEvents)}});wdi.SpiceConnection=$.spcExtend(wdi.EventObject.prototype,{channels:null,connectionId:null,connectionInfo:null,runQ:null,token:null,connectionControl:null,init:function(n){this.superInit(),this.channels={},this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN]=n.mainChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_DISPLAY]=n.displayChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_INPUTS]=n.inputsChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_CURSOR]=n.cursorChannel||new wdi.SpiceChannel,this.channels[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK]=n.playbackChannel||new wdi.SpiceChannel,this.runQ=n.runQ||new wdi.RunQueue,this.connectionControl=n.connectionControl||new wdi.ConnectionControl,this.setup()},connect:function(n){this.connectionInfo=n,n.connectionControl&&this.connectionControl.connect(n),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].connect(this.connectionInfo,wdi.SpiceVars.SPICE_CHANNEL_MAIN)},disconnect:function(){for(var n in wdi.Debug.log("spiceConnection disconnect"),this.runQ.clear(),this.clearEvents(),this.channels)this.channels[n].disconnect(),this.channels[n].clearEvents(),this.channels[n]=null,delete this.channels[n];this.connectionControl.disconnect(),this.runQ=null,this.token=null,this.channels=null,this.connectionId=null,this.connectionInfo=null,this.connectionControl=null},send:function(n){var e=n.args.marshall();this.channels[n.channel]?this.channels[n.channel].sendObject(e,n.messageType):console.error("channel not available",n.channel)},setup:function(){this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("connectionId",this.onConnectionId,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("channelListAvailable",this.onChannelList,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("mouseMode",this.onMouseMode,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("initAgent",this.onInitAgent,this),this.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN].addListener("notify",this.onNotify,this),this.connectionControl.addListener("connectionLost",this.onDisconnect,this),this._setConnectedListeners();var n=null;for(var e in n=wdi.exceptionHandling?this.onChannelMessageExceptionHandled:this.processChannelMessage,this.channels)this.channels.hasOwnProperty(e)&&(this.channels[e].addListener("message",n,this),this.channels[e].addListener("status",this.onStatus,this),this.channels[e].addListener("error",this.onDisconnect,this))},_setConnectedListeners:function(){this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_MAIN),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_DISPLAY),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_INPUTS),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_CURSOR),this._setConnectedListener(wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK)},_setConnectedListener:function(n){this.channels[n].addListener("channelConnected",(function(){this.fire("channelConnected",n)}),this)},onDisconnect:function(n){this.fire("error",n)},onConnectionId:function(n){this.connectionId=n},onChannelList:function(n){this.connectChannels(n)},connectChannels:function(n){for(var e in this.channels)(e=parseInt(e,10))!=wdi.SpiceVars.SPICE_CHANNEL_MAIN&&-1!=n.indexOf(e)&&this.runQ.add((function(n,e){this.channels[e].connect(this.connectionInfo,e,this.connectionId,n)}),this,!1,e);this.runQ.process()},onInitAgent:function(n){var e=n;this.fire("initAgent",e)},onMouseMode:function(n){var e=n;this.fire("mouseMode",e)},onNotify:function(n){this.fire("notify")},onStatus:function(n){},onChannelMessageExceptionHandled:function(n){try{return this.processChannelMessage(n)}catch(n){wdi.Debug.error("SpiceConnection: Packet decodification error",n)}},processChannelMessage:function(n){var e=wdi.PacketFactory.extract(n);wdi.GlobalPool.discard("ViewQueue",n.body),wdi.GlobalPool.discard("RawSpiceMessage",n),e?this.fire("message",e):(wdi.Debug.log("Unknown packet "+n.channel+" "+n.header.type),wdi.Debug.log(n))}});wdi.SPICE_INPUT_MOTION_ACK_BUNCH=8,wdi.ClientGui=$.spcExtend(wdi.EventObject.prototype,{width:null,height:null,canvas:null,ack_wait:0,mouse_mode:0,mouse_status:0,eventLayer:null,counter:0,mainCanvas:0,firstTime:!0,clientOffsetX:0,clientOffsetY:0,magnifier:null,magnifierBackground:null,firstMove:!0,isMagnified:!0,isMouseDown:!1,soundStarted:!1,canvasMarginY:0,canvasMarginX:0,stuckKeysHandler:null,isKeyboardEnabled:!1,subCanvas:{},inputManager:null,clipboardEnabled:!0,layer:null,freezeClass:"freeze",app:{},init:function(e){this.time=Date.now(),this.canvas={},this.contexts={},this.superInit(),this.magnifier=window.$("<canvas/>").attr({width:150,height:150}).css({position:"absolute",left:"0px",top:"0px"}),this.stuckKeysHandler=e.stuckKeysHandler||new wdi.StuckKeysHandler,this.settings=e.settings||{},this.stuckKeysHandler.addListener("inputStuck",this._sendInput.bind(this),this),this.magnifierBackground=window.$("<img/>"),this.magnifierBackground.attr("src","/spice-console/resources/magnifier.png"),this.initSound(),this.inputManager=e.inputManager||new wdi.InputManager({stuckKeysHandler:this.stuckKeysHandler,window:$(window)}),this.inputManager.setCurrentWindow(window),this.clipBoardDataParser=e.clipBoardDataParser||new wdi.ClipboardDataParser({}),this.localClipboard=e.localClipboard||new wdi.LocalClipboard({clientGui:this}),this.app=e.app;var t=this;this.eventHandlers={hide:function(){t.stuckKeysHandler.releaseAllKeys()}},window.$(document).on(this.eventHandlers)},dispose:function(){wdi.Debug.log("Disposing ClientGui"),$(document).off(this.eventHandlers),this.unbindDOM(),this.removeAllCanvases(),this.inputManager.dispose(),this.stuckKeysHandler.dispose(),this.localClipboard.dispose(),this.width=null,this.height=null,this.canvas=null,this.ack_wait=0,this.mouse_mode=0,this.mouse_status=0,this.eventLayer=null,this.counter=0,this.mainCanvas=0,this.firstTime=!0,this.clientOffsetX=0,this.clientOffsetY=0,this.magnifier=null,this.magnifierBackground=null,this.firstMove=!0,this.isMagnified=!0,this.isMouseDown=!1,this.soundStarted=!1,this.canvasMarginY=0,this.canvasMarginX=0,this.stuckKeysHandler=null,this.subCanvas={},this.inputManager=null,this.clipboardEnabled=!0,this.layer=null,clearInterval(self.rightClickTimer),clearInterval(self.mouseDownTimer)},removeAllCanvases:function(){var e=this;Object.keys(this.canvas).forEach((function(t){$(e.canvas[t]).remove(),delete e.canvas[t],delete e.contexts[t]})),$(this.eventLayer).remove(),this.eventLayer=null},unbindDOM:function(){if(this.eventLayer){["touchstart","touchmove","touchend","mouseup","mousedown","mousemove","contextmenu","mousewheel"].forEach((function(e){$(this.eventLayer).unbind(e)}))}},freeze:function(){if(this.canvas[0]){var e=new Image,t=this.canvas[0],n=$(t);$(e).attr("style",n.attr("style")),$(e).attr("class",this.freezeClass),e.src=t.toDataURL("image/png"),n.parent().append($(e))}},cancelFreeze:function(){$("."+this.freezeClass).remove()},setLayer:function(e){this.layer=e},disableClipboard:function(){this.clipboardEnabled=!1},_sendInput:function(e){var t=e,n=t[0],i=t[1];this.fire("input",[n,i])},releaseAllKeys:function(){this.stuckKeysHandler.releaseAllKeys()},getContext:function(e){return this.contexts[e]},getCanvas:function(e){return this.canvas[e]},checkFeatures:function(){return!(!Modernizr.canvas||!Modernizr.websockets)||(alert("Your Browser is not compatible with WDI. Visit ... for a list of compatible browsers"),!1)},deleteSubCanvas:function(e){var t=this.subCanvas[e.hwnd];return this.subCanvas[e.hwnd]=null,t},moveSubCanvas:function(e){var t=this.subCanvas[e.hwnd];return t.info=e,this._fillSubCanvasFromWindow(e),t},resizeSubCanvas:function(e){var t=this.subCanvas[e.hwnd];return $([t.canvas,t.eventLayer]).attr({width:e.width,height:e.height}),t.info=e,this._fillSubCanvasFromWindow(e),t},_fillSubCanvasFromWindow:function(e){var t=parseInt(e.top,10),n=parseInt(e.left,10),i=parseInt(e.width,10),a=parseInt(e.height,10);this.fillSubCanvas({top:t,left:n,right:n+i,bottom:t+a})},createNewSubCanvas:function(e){var t=this.createEventLayer(e.hwnd+"_event",e.width,e.height);return this.subCanvas[e.hwnd]={canvas:$("<canvas/>").attr({width:e.width,height:e.height}).css({display:e.iconic?"none":"block"})[0],eventLayer:t,info:e,position:0},this.canvas[this.mainCanvas]&&this._fillSubCanvasFromWindow(e),[this.subCanvas[e.hwnd]]},fillSubCanvas:function(e){var t=this.canvas[this.mainCanvas],n=null;for(var i in this.subCanvas)if(null!=this.subCanvas[i]&&void 0!==this.subCanvas[i]&&this.subCanvas.hasOwnProperty(i))if(n=this.subCanvas[i].info,null!=e||null!=e){var a=parseInt(n.top,10),s=parseInt(n.left,10),o={top:a,left:s,right:s+parseInt(n.width,10),bottom:a+parseInt(n.height,10)};wdi.CollisionDetector.thereIsBoxCollision(o,e)&&this._doDrawSubCanvas(t,this.subCanvas[i],n)}else this._doDrawSubCanvas(t,this.subCanvas[i],n)},_doDrawSubCanvas:function(e,t,n){if(null!=this.canvas[this.mainCanvas]&&null!=this.canvas[this.mainCanvas]){var i=null;if(0===n.iconic){i=t.canvas.getContext("2d");var a=0,s=0,o=+n.width,r=+n.height,u=+n.left,l=+n.top;u<0&&(o+=u,a=-u,u=0),l<0&&(r+=l,s=-l,l=0);try{o=Math.max(1,Math.floor(o)),r=Math.max(1,Math.floor(r)),o>e.width&&(o=e.width),r>e.height&&(r=e.height),i.drawImage(e,u,l,o,r,a,s,o,r)}catch(e){wdi.Debug.error(e)}}}},removeCanvas:function(e){var t=e.args;t.surface_id===this.mainCanvas&&($(this.eventLayer).remove(),this.eventLayer=null),this.canvas[t.surface_id].keepAlive=!1,delete this.canvas[t.surface_id],delete this.contexts[t.surface_id]},drawCanvas:function(e){wdi.Debug.log("clientgui time: ",this.time);var t=e.args,n=wdi.GlobalPool.create("Canvas");if(n.keepAlive=!0,n.id="canvas_"+t.surface_id,n.width=t.width*this.pixelRatio,n.height=t.height*this.pixelRatio,n.style.position="absolute",n.style.top=this.canvasMarginY+"px",n.style.left=this.canvasMarginX+"px",n.style.width=t.width+"px",n.style.height=t.height+"px",this.canvas[t.surface_id]=n,this.contexts[t.surface_id]=n.getContext("2d"),t.flags&&!wdi.SeamlessIntegration){this.mainCanvas=t.surface_id,this.eventLayer=this.createEventLayer("eventLayer",t.width,t.height);var i=$(this.eventLayer).css({position:"absolute",top:this.canvasMarginY+"px",left:this.canvasMarginX+"px"})[0];this.layer?(this.layer.appendChild(n),this.layer.appendChild(i)):(document.body.appendChild(n),document.body.appendChild(i)),!this.isKeyboardEnabled&&this.enableKeyboard()}if(this.firstTime&&this.clipboardEnabled){var a=this,s=this.settings.PASTES_PER_SECOND||5,o=_.throttle((function(e){a.fire("paste",e)}),1e3/s);$(document).bind("paste",(function(e){a.clipBoardDataParser.parse(e.originalEvent.clipboardData,o)})),$(document).bind("copy",(function(e){a.app.sendShortcut(wdi.keyShortcutsHandled.CTRLC)})),this.firstTime=!1}t.flags&&this.fire("resolution",[this.canvas[t.surface_id].width,this.canvas[t.surface_id].height])},disableKeyboard:function(){var e=window.$(window.document);e.unbind("keydown",this.handleKey),e.unbind("keyup",this.handleKey),e.unbind("keypress",this.handleKey),this.inputManager.disable()},enableKeyboard:function(){var e=this,t=window.$(window.document);t.keydown([e],this.handleKey),t.keypress([e],this.handleKey),t.keyup([e],this.handleKey),this.inputManager.enable(),!this.isKeyboardEnabled&&(this.isKeyboardEnabled=!0)},setCanvasMargin:function(e){this.canvasMarginX=e.x,this.canvasMarginY=e.y},createEventLayer:function(e,t,n){var i=this,a=$("<canvas/>").css({cursor:"default",position:"absolute"}).attr({id:e,width:t,height:n});window.bowser.firefox&&a.attr("contentEditable",!0),a.bind("touchstart",(function(e){e.preventDefault();var t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],n=t.pageX,a=t.pageY;i.generateEvent.call(i,"mousemove",[n+i.clientOffsetX,a+i.clientOffsetY,i.mouse_status]),1===e.originalEvent.touches.length?(i.enabledTouchMove=!0,i.launchRightClick.call(i,n,a)):2===e.originalEvent.touches.length?(i.touchX=n,i.touchY=a,i.enabledTouchMove=!1):3===e.originalEvent.touches.length&&(i.touchY3=a,i.enabledTouchMove=!1)})),a.bind("touchmove",(function(e){var t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0],n=t.pageX,a=t.pageY;if(1===e.originalEvent.touches.length&&i.enabledTouchMove){i.isMagnified=!0,clearInterval(i.rightClickTimer),i.isMouseDown||(clearInterval(i.mouseDownTimer),i.launchMouseDown()),i.generateEvent.call(i,"mousemove",[n+i.clientOffsetX,a+i.clientOffsetY-80,i.mouse_status]);var s=$(this).offset(),o=n-s.left,r=a-s.top;i.firstMove&&($("body").append(i.magnifier),i.firstMove=!1);var u=o-75,l=r-160;i.magnifier.css({left:u,top:l});var h=i.magnifier[0].getContext("2d");h.clearRect(0,0,150,150),h.save(),h.beginPath(),h.arc(75,75,75,0,2*Math.PI,!1),h.clip(),h.drawImage(i.getCanvas(0),o-50,r-50-80,100,100,0,0,150,150),h.drawImage(i.magnifierBackground[0],0,0),h.restore()}else if(2===e.originalEvent.touches.length){var c=i.touchY-a;if(Math.abs(c)>10){var d=c>0?4:3;i.touchX=n,i.touchY=a,i.generateEvent.call(i,"mousedown",d),i.generateEvent.call(i,"mouseup",d)}}else if(3===e.originalEvent.touches.length){(c=i.touchY3-a)>100&&document.getElementById("hiddeninput").select()}e.preventDefault()})),a.bind("touchend",(function(e){if(i.enabledTouchMove){var t=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0];t.pageX,t.pageY;i.isMouseDown||i.generateEvent.call(i,"mousedown",0),i.isMouseDown=!1,i.generateEvent.call(i,"mouseup",0);$(this).offset();i.enabledTouchMove=!1,i.firstMove=!0,i.isMagnified&&i.magnifier.remove(),i.isMagnified=!1}clearInterval(i.rightClickTimer),clearInterval(i.mouseDownTimer)})),a.mouseup((function(e){var t=e.button;i.generateEvent.call(i,"mouseup",t),i.mouse_status=0,e.preventDefault()})),a.mousedown((function(e){var t=e.button;i.generateEvent.call(i,"mousedown",t),i.mouse_status=1,e.preventDefault()})),a.mousemove((function(e){var t=e.pageX,n=e.pageY;i.generateEvent.call(i,"mousemove",[(t+i.clientOffsetX-i.eventLayer.offsetLeft)*i.pixelRatio,(n+i.clientOffsetY-i.eventLayer.offsetTop)*i.pixelRatio,i.mouse_status]),e.preventDefault()})),a.bind("contextmenu",(function(e){return e.preventDefault(),!1}));var s=_.throttle((function(e,t){var n=t>0?3:4;return i.generateEvent.call(i,"mousedown",n),i.generateEvent.call(i,"mouseup",n),!1}),60);return a.bind("mousewheel",s),this.fire("eventLayerCreated",a[0]),wdi.VirtualMouse.setEventLayer(a[0],0,0,t,n,1),a[0]},launchRightClick:function(e,t){var n=this;this.rightClickTimer=setTimeout((function(){n.generateEvent.call(n,"mousedown",2),n.generateEvent.call(n,"mouseup",2),n.enabledTouchMove=!1}),400)},launchMouseDown:function(e,t){var n=this;this.mouseDownTimer=setTimeout((function(){n.isMouseDown=!0,n.generateEvent.call(n,"mousedown",0)}),1500)},showError:function(e){wdi.Debug.warn(e),$("<div/>",{id:"error"}).html(e).css({"background-color":"#ff4141"}).appendTo("body"),setTimeout("$('#error').remove()",2e3)},generateEvent:function(e,t){if("mousemove"===e||"joystick"===e)this.ack_wait<wdi.SPICE_INPUT_MOTION_ACK_BUNCH&&(this.ack_wait++,this.fire("input",[e,t]));else{if(e.indexOf("key")>-1){if(this.stuckKeysHandler.checkSpecialKey(e,t[0].keyCode),!this.shouldGenerateKeyEvents(t[0].keyCode))return;var n="keypress"===e?this.inputManager.getValue():"";"keypress"===e&&$("#inputmanager").val(""),n&&(t=this.inputManager.manageChar(n,t))}this.fire("input",[e,t])}},shouldGenerateKeyEvents:function(e){return!this.inputManager.isSpecialKey(e)},motion_ack:function(){this.ack_wait=0},setMouseMode:function(e){this.mouse_mode=e},handleKey:function(e){e.data[0].generateEvent.call(e.data[0],e.type,[e]),wdi.Keymap.isInKeymap(e.keyCode)&&"keypress"!==e.type&&e.preventDefault()},setClientOffset:function(e,t){this.clientOffsetX=e,this.clientOffsetY=t},setClipBoardData:function(e){navigator.clipboard.writeText(e)},setToLocalClipboard:function(e){this.localClipboard.updateClipboardBuffer(e.value)},getStuckKeysHandler:function(){return this.stuckKeysHandler},initSound:function(){var e=this;if(Modernizr.touch){var t=$("<button>Start</button>",{id:"startAudio"}).css({padding:"10px 25px",fontSize:"25px",fontFamily:"Verdana",cursor:"pointer",margin:"0 auto"}).click((function(){e.soundStarted=!0,e.fire("startAudio"),$("#soundButtonContainer").remove()})),n=$('<div id="messageContainer"><p>Click to start using your virtual session:</p></div>').css({color:"white",textAlign:"center",fontSize:"25px",fontFamily:"Verdana",marginTop:"75px"}),i=$("<div></div>",{id:"soundButtonContainer"});t.appendTo(n),n.appendTo(i),i.appendTo("body"),i.css({position:"absolute",zIndex:999999999,top:0,left:0,width:"100%",height:document.height,backgroundColor:"black"})}else this.soundStarted=!0,window.setTimeout((function(){e.fire("startAudio")}),100)}});wdi.PacketProcess=$.spcExtend(wdi.DomainObject,{processors:{},init:function(s){this.processors[wdi.SpiceVars.SPICE_CHANNEL_MAIN]=s.mainProcess||new wdi.MainProcess({app:s.app}),this.processors[wdi.SpiceVars.SPICE_CHANNEL_DISPLAY]=s.displayProcess||new wdi.DisplayPreProcess({clientGui:s.clientGui,disableMessageBuffering:s.disableMessageBuffering}),this.processors[wdi.SpiceVars.SPICE_CHANNEL_INPUTS]=s.inputsProcess||new wdi.InputProcess({clientGui:s.clientGui,spiceConnection:s.spiceConnection}),this.processors[wdi.SpiceVars.SPICE_CHANNEL_CURSOR]=s.cursorProcess||new wdi.CursorProcess,this.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK]=s.playbackProcess||new wdi.PlaybackProcess({app:s.app})},process:function(s){return wdi.exceptionHandling?this.processExceptionHandled(s):this.processPacket(s)},processExceptionHandled:function(s){try{return this.processPacket(s)}catch(s){wdi.Debug.error("PacketProcess: Error processing packet",s)}},processPacket:function(s){if(!s||!this.processors[s.channel])throw"Invalid channel or null message";this.processors[s.channel].process(s)},dispose:function(){wdi.Debug.log("Disposing PacketProcess all processors"),this.processors[wdi.SpiceVars.SPICE_CHANNEL_MAIN].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_DISPLAY].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_INPUTS].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_CURSOR].dispose(),this.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK].dispose(),this.processors={}}});wdi.PacketFilter={restoreContext:!1,start:null,dispose:function(){wdi.Debug.log("Disposing PacketFilter"),this.restoreContext=!1,this.start=null},filter:function(e,t,i,a){if(wdi.logOperations&&(this.start=Date.now()),wdi.graphicDebug&&wdi.graphicDebug.debugMode&&wdi.graphicDebug.printDebugMessageOnFilter(e,a),wdi.IntegrationBenchmark&&wdi.IntegrationBenchmark.benchmarking){var r=new Date;wdi.IntegrationBenchmark.setStartTime(r.getTime())}if(e.args.base&&e.args.base.clip.type===wdi.SpiceClipType.SPICE_CLIP_TYPE_RECTS){var n=a.getContext(e.args.base.surface_id);n.save(),n.beginPath();for(var s=e.args.base.clip.rects.rects,o=s.length;o--;){var g=wdi.graphics.getBoxFromSrcArea(s[o]);n.rect(g.x,g.y,g.width,g.height)}n.clip(),this.restoreContext=e.args.base.surface_id}t.call(i,e)},notifyEnd:function(e,t){!1!==this.restoreContext&&(t.getContext(this.restoreContext).restore(),this.restoreContext=!1);if(wdi.SeamlessIntegration){var i=null;e.args.base&&e.args.base.box&&(i=e.args.base.box),t.fillSubCanvas(i)}if(wdi.graphicDebug&&wdi.graphicDebug.debugMode&&wdi.graphicDebug.printDebugMessageOnNotifyEnd(e,t),wdi.IntegrationBenchmark&&wdi.IntegrationBenchmark.benchmarking){var a=new Date;wdi.IntegrationBenchmark.setEndTime(a.getTime())}wdi.GlobalPool.cleanPool("Canvas"),wdi.GlobalPool.cleanPool("Image"),wdi.logOperations&&wdi.DataLogger.log(e,this.start)}};wdi.PacketFactory={dispose:function(){wdi.Debug.log("Disposing PacketFactory")},extract:function(e){var a=null;switch(e.channel){case wdi.SpiceVars.SPICE_CHANNEL_DISPLAY:if(wdi.graphicDebug&&wdi.graphicDebug.debugMode)var S=JSON.stringify(e);switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_DISPLAY_MODE:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_MARK:a=(new wdi.SpiceDisplayMark).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_RESET:a=(new wdi.SpiceDisplayReset).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS:a=(new wdi.SpiceCopyBits).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_LIST:a=(new wdi.SpiceResourceList).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS:case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_PALETTE:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES:a=(new wdi.SpiceDisplayInvalidAllPalettes).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CREATE:a=(new wdi.SpiceStreamCreate).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA:a=(new wdi.SpiceStreamData).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_CLIP:a=(new wdi.SpiceStreamClip).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DATA_SIZED:a=(new wdi.SpiceStreamDataSized).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT:a=(new wdi.SpiceStreamActiveReport).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY:a=(new wdi.SpiceStreamDestroy).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_CURRENT_VIDEO_ENCODE_SETUP_RESPONSE:const S=(new wdi.CodecConfig).demarshall(e.body);(new wdi.SpiceChannel).changeCodec(S.codec);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_FILL:a=(new wdi.SpiceDrawFill).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_OPAQUE:break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_COPY:a=(new wdi.SpiceDrawCopy).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLEND:a=(new wdi.drawBlend).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_BLACKNESS:a=(new wdi.SpiceDrawBlackness).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_WHITENESS:a=(new wdi.SpiceDrawWhiteness).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_INVERS:a=(new wdi.SpiceDrawInvers).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ROP3:a=(new wdi.SpiceDrawRop3).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_STROKE:a=(new wdi.SpiceStroke).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TEXT:a=(new wdi.SpiceDrawText).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_TRANSPARENT:a=(new wdi.drawTransparent).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND:a=(new wdi.drawAlphaBlend).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_CREATE:a=(new wdi.SpiceSurface).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_DISPLAY_SURFACE_DESTROY:a=(new wdi.SpiceSurfaceDestroy).demarshall(e.body)}break;case wdi.SpiceVars.SPICE_CHANNEL_INPUTS:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK:a=new Object;break;case wdi.SpiceVars.SPICE_MSG_INPUTS_INIT:const S=new wdi.SpiceModifierData,i=S.demarshall(e.body);S.setModifierData(i.data);break;case wdi.SpiceVars.SPICE_MSG_INPUTS_KEY_MODIFIERS:const d=new wdi.SpiceModifierData,r=d.demarshall(e.body);d.setModifierData(r.data)}break;case wdi.SpiceVars.SPICE_CHANNEL_MAIN:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_MAIN_INIT:a=(new wdi.RedMainInit).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_DATA:a=(new wdi.VDAgentMessage).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_DISCONNECTED:a=(new wdi.SpiceMsgMainAgentDisconnected).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_CONNECTED:a=(new wdi.SpiceMsgMainAgentConnected).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_MULTI_MEDIA_TIME:a=(new wdi.MainMultiMediaTime).demarshall(e.body);break;case wdi.SpiceVars.SPICE_MSG_MAIN_CHANNELS_LIST:a=(new wdi.MainMChannelsList).demarshall(e.body)}break;case wdi.SpiceVars.SPICE_CHANNEL_CURSOR:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_CURSOR_INIT:a=(new wdi.RedCursorInit).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_CURSOR_SET:a=(new wdi.RedCursorSet).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_CURSOR_HIDE:a=(new wdi.RedCursorHide).demarshall(e.body,e.header.size)}break;case wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK:switch(e.header.type){case wdi.SpiceVars.SPICE_MSG_PLAYBACK_MODE:a=(new wdi.PlaybackMode).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_START:a=(new wdi.PlaybackStart).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_STOP:a=(new wdi.PlaybackStop).demarshall(e.body,e.header.size);break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_DATA:a=(new wdi.PlaybackData).demarshall(e.body,e.header.size)}}return a?(wdi.graphicDebug&&wdi.graphicDebug.debugMode&&S&&(a.originalData=S),new wdi.SpiceMessage({messageType:e.header.type,channel:e.channel,args:a})):(wdi.Debug.log(e.header.type,e.header.channel),!1)}};Application=$.spcExtend(wdi.DomainObject,{spiceConnection:null,clientGui:null,agent:null,externalCallback:null,keyboardEnabled:!0,packetProcess:null,inputProcess:null,multimediaTime:null,lastMultimediaTime:null,busConnection:null,busProcess:null,timeLapseDetector:null,connectionInfo:null,reconnecting:null,checkActivity:null,configs:null,init:function(e){this.disposed=!1,e?this.configs=e:e=this.configs||{},wdi.spiceClientPath=e.spiceClientPath||"",wdi.Debug.log("application init"),wdi.GlobalPool.init(),this.spiceConnection=e.spiceConnection||new wdi.SpiceConnection,this.clientGui=e.clientGui||new wdi.ClientGui({app:this}),this.agent=e.agent||new wdi.Agent({app:this}),this.inputProcess=e.inputProcess||new wdi.InputProcess({clientGui:this.clientGui,spiceConnection:this.spiceConnection}),this.packetProcess=e.packetProcess,this.busConnection=e.busConnection||new wdi.BusConnection,this.busProcess=e.busProcess||new wdi.BusProcess({clientGui:this.clientGui,busConnection:this.busConnection}),this.timeLapseDetector=e.timeLapseDetector||new wdi.TimeLapseDetector,this.checkActivity=e.checkActivity,this.setup(),e.supportHighDPI?(this.clientGui.pixelRatio=window.devicePixelRatio,this.pixelRatio=window.devicePixelRatio):(this.clientGui.pixelRatio=1,this.pixelRatio=1)},run:function(e){if(this.runParams=e,e.hasOwnProperty("seamlessDesktopIntegration")&&(wdi.SeamlessIntegration=e.seamlessDesktopIntegration),!this.packetProcess){var t=!1;!1===e.useWorkers&&(t=new wdi.DisplayProcess({clientGui:this.clientGui,disableMessageBuffering:e.disableMessageBuffering})),this.packetProcess=new wdi.PacketProcess({app:this,clientGui:this.clientGui,agent:this.agent,spiceConnection:this.spiceConnection,inputsProcess:this.inputProcess,displayProcess:t,disableMessageBuffering:e.disableMessageBuffering})}if(this.checkActivity||(this.checkActivity=new wdi.CheckActivity(e.checkActivityInterval),this.checkActivity.addListener("activityLost",this.onActivityLost,this)),window.vdiLoadTest?this.spiceConnection.addListener("message",this.onMessage,this):this.spiceConnection.addListener("message",this.packetProcess.process,this.packetProcess),this.busConnection.connect(e),this.timeLapseDetector.startTimer(),e.canvasMargin&&this.clientGui.setCanvasMargin(e.canvasMargin),e.disableClipboard&&(this.agent.disableClipboard(),this.clientGui.disableClipboard(),this.enableCtrlC(),this.enableCtrlV()),e.layer&&this.clientGui.setLayer(e.layer),this.clientGui.checkFeatures()){wdi.SeamlessIntegration&&this.disableKeyboard(),wdi.Keymap.loadKeyMap(e.layout,this.clientGui.getStuckKeysHandler()),this.setExternalCallback(e.callback,e.context);try{this.connect({host:e.host,port:e.port,protocol:e.protocol,vmHost:e.vmHost,vmPort:e.vmPort,vmid:e.vmid,vmInfoToken:e.vmInfoToken,busHost:e.busHost,token:e.token,connectionControl:e.connectionControl,heartbeatToken:e.heartbeatToken,heartbeatTimeout:e.heartbeatTimeout})}catch(e){this.executeExternalCallback("error",1)}this.clientGui.setClientOffset(e.clientOffset.x,e.clientOffset.y)}e.hasOwnProperty("externalClipboardHandling")&&(this.externalClipoardHandling=e.externalClipboardHandling)},end:function(){},setup:function(){this.spiceConnection.addListener("mouseMode",this.onMouseMode,this),this.spiceConnection.addListener("initAgent",this.onInitAgent,this),this.spiceConnection.addListener("error",this.onDisconnect,this),this.spiceConnection.addListener("channelConnected",this.onChannelConnected,this),this.clientGui.addListener("input",this.onClientInput,this),this.clientGui.addListener("resolution",this.onResolution,this),this.clientGui.addListener("paste",this.onPaste,this),this.clientGui.addListener("startAudio",this.onStartAudio,this),this.clientGui.addListener("eventLayerCreated",this.onEventLayerCreated,this),this.busProcess.addListener("windowCreated",this.onWindowCreated,this),this.busProcess.addListener("windowClosed",this.onWindowClosed,this),this.busProcess.addListener("windowMoved",this.onWindowMoved,this),this.busProcess.addListener("windowResized",this.onWindowResized,this),this.busProcess.addListener("windowFocused",this.onWindowFocused,this),this.busProcess.addListener("windowMinimized",this.onWindowMinimized,this),this.busProcess.addListener("windowRestored",this.onWindowRestored,this),this.busProcess.addListener("windowMaximized",this.onWindowMaximized,this),this.busProcess.addListener("busConnected",this.onBusConnected,this),this.busProcess.addListener("menuResponse",this.onMenuResponse,this),this.busProcess.addListener("networkDriveResponse",this.onNetworkDriveResponse,this),this.busProcess.addListener("wrongPathError",this.onWrongPathError,this),this.busProcess.addListener("applicationLaunchedSuccessfully",this.onApplicationLaunchedSuccessfully,this),this.busProcess.addListener("selectedText",this.onRemoteSelectedText,this),this.busProcess.addListener("copiedText",this.onRemoteCopiedText,this),this.agent.addListener("clipBoardData",this.onClipBoardData,this),this.busConnection.addListener("busMessage",this.onBusMessage,this),this.busConnection.addListener("error",this.onDisconnect,this),this.timeLapseDetector.addListener("timeLapseDetected",this.onTimeLapseDetected,this),this.busProcess.addListener("defaultTypeEvent",this.onDefaultTypeEvent,this)},onChannelConnected:function(e){e===wdi.SpiceVars.SPICE_CHANNEL_INPUTS&&this.clientGui.releaseAllKeys()},onDefaultTypeEvent:function(e){this.executeExternalCallback(e.event,e)},onNetworkDriveResponse:function(e){this.executeExternalCallback("networkDriveResponse",e)},onDisconnect:function(e){var t=e;this.executeExternalCallback("error",t)},onResolution:function(e){this.executeExternalCallback("resolution",e)},onClipBoardData:function(e){this.externalClipoardHandling?this.executeExternalCallback("clipboardEvent",e):this.clientGui.setClipBoardData(e)},onRemoteCopiedText:function(e){this.clientGui.setToLocalClipboard(e)},onRemoteSelectedText:function(e){this.clientGui.setToLocalClipboard(e)},onWindowMinimized:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowMinimized",e)},onWindowFocused:function(e){this.executeExternalCallback("windowFocused",e)},onWindowRestored:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowRestored",e)},onWindowMaximized:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowMaximized",e)},onWindowResized:function(e){var t=e;e=this.clientGui.resizeSubCanvas(t);this.executeExternalCallback("windowResized",e)},onWindowMoved:function(e){var t=e;e=this.clientGui.moveSubCanvas(t);this.executeExternalCallback("windowMoved",e)},onWindowClosed:function(e){var t=e;e=this.clientGui.deleteSubCanvas(t);this.executeExternalCallback("windowClosed",e)},onWindowCreated:function(e){var t=e;e=this.clientGui.createNewSubCanvas(t);this.executeExternalCallback("windowCreated",e)},onMenuResponse:function(e){var t=e;this.executeExternalCallback("menuResponse",t)},onClientInput:function(e){var t=e,i=t[0],n=t[1][0];this.inputProcess.isKeyboardShortcut(i,n)?this._sendCtrlKey(n.keyCode):this.inputProcess.send(t,i)},onMessage:function(e){var t=e;this.packetProcess.process(t);var i=this;window.checkResultsTimer&&clearTimeout(window.checkResultsTimer),window.checkResultsTimer=window.setTimeout((function(){i.executeExternalCallback("checkResults"),window.vdiLoadTest=!1}),5e3)},onBusConnected:function(e){wdi.SeamlessIntegration&&this.busProcess.requestWindowList()},onBusMessage:function(e){var t=e;this.busProcess.process(t)},onInitAgent:function(e){this.agent.setClientTokens(e),this.agent.sendInitMessage(this),this.reconnecting=!1,this.executeExternalCallback("ready",e)},onMouseMode:function(e){this.clientGui.setMouseMode(e)},onPaste:function(e){this.agent.setClipboard(e)},onStartAudio:function(){this.packetProcess.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK].startAudio()},onEventLayerCreated:function(e){this.executeExternalCallback("eventLayerCreated",e)},onTimeLapseDetected:function(e){var t=e;this.executeExternalCallback("timeLapseDetected",t)},connect:function(e){wdi.Debug.log("application connect"),this.connectionInfo=e;try{this.spiceConnection.connect(e)}catch(e){wdi.Debug.error("application connect error",e),this.clientGui.showError(e.message)}},reconnect:function(e){this.reconnecting=!0,e.freeze&&this.freeze(),this.dispose(),this.init(),this.run(this.runParams)},freeze:function(){this.clientGui.freeze()},cancelFreeze:function(){this.clientGui.cancelFreeze()},setReconnecting:function(e){this.reconnecting=e},getReconnecting:function(){return this.reconnecting},setExternalCallback:function(e,t){this.externalCallback=[e,t]},executeExternalCallback:function(e,t){this.externalCallback[0].call(this.externalCallback[1],e,t)},sendCommand:function(e,t){switch(e){case"close":this.busProcess.closeWindow(t.hwnd);break;case"move":this.busProcess.moveWindow(t.hwnd,t.x,t.y);break;case"minimize":this.busProcess.minimizeWindow(t.hwnd);break;case"maximize":this.busProcess.maximizeWindow(t.hwnd);break;case"restore":this.busProcess.restoreWindow(t.hwnd);break;case"focus":this.busProcess.focusWindow(t.hwnd);break;case"resize":this.busProcess.resizeWindow(t.hwnd,t.width,t.height);break;case"run":this.busProcess.executeCommand(t.cmd);break;case"setResolution":this.agent.setResolution(t.width,t.height);break;case"getMenu":this.busProcess.getMenu();break;case"reMountNetworkDrive":this.busProcess.reMountNetworkDrive(t.host,t.username,t.password);break;case"refreshFileSystem":this.busProcess.refreshFileSystem();break;default:this.busProcess.sendGenericMessage(e,t)}},enableKeyboard:function(){this.clientGui.enableKeyboard()},disableKeyboard:function(){this.clientGui.disableKeyboard()},enableCtrlC:function(){wdi.KeymapES.setCtrlKey(67,46),wdi.KeymapUS.setCtrlKey(67,46)},enableCtrlV:function(){wdi.KeymapES.setCtrlKey(86,47),wdi.KeymapUS.setCtrlKey(86,47)},disconnect:function(){this.busConnection.disconnect(),this.spiceConnection.disconnect()},setMultimediaTime:function(e){this.multimediaTime=e,this.lastMultimediaTime=Date.now()},sendShortcut:function(e){e===wdi.keyShortcutsHandled.CTRLV?this._sendCtrlKey(86):e===wdi.keyShortcutsHandled.CTRLC&&this._sendCtrlKey(67)},sendCtrlAltDelete:function(){this._sendCtrlKey(18,46)},_sendCtrlKey:function(e,t){this.inputProcess.send(["keydown",[{generated:!0,type:"keydown",keyCode:17,charCode:0}]],"keydown"),this.inputProcess.send(["keydown",[{generated:!0,type:"keydown",keyCode:e,charCode:0}]],"keydown"),t&&this.inputProcess.send(["keydown",[{generated:!0,type:"keydown",keyCode:t,charCode:0}]],"keydown"),this.inputProcess.send(["keyup",[{generated:!0,type:"keyup",keyCode:e,charCode:0}]],"keyup"),t&&this.inputProcess.send(["keyup",[{generated:!0,type:"keyup",keyCode:t,charCode:0}]],"keyup"),this.inputProcess.send(["keyup",[{generated:!0,type:"keyup",keyCode:17,charCode:0}]],"keyup")},dispose:function(){this.disposed=!0,wdi.Debug.log("application dispose"),wdi.ExecutionControl.runQ.clear(),wdi.ExecutionControl.currentProxy=null,wdi.ExecutionControl.sync=!0,this.disableKeyboard(),this.disconnect(),this.packetProcess.dispose(),this.clientGui.dispose(),this.busProcess.clearEvents(),this.busProcess.dispose(),this.busConnection.clearEvents(),this.agent.clearEvents(),this.agent.dispose(),this.timeLapseDetector.clearEvents(),this.timeLapseDetector.dispose(),this.checkActivity.dispose()},onWrongPathError:function(e){this.executeExternalCallback("wrongPathError",e)},onApplicationLaunchedSuccessfully:function(e){this.executeExternalCallback("applicationLaunchedSuccessfully",e)},getKeyboardHandler:function(){return this.clientGui.handleKey},getClientGui:function(){return this.clientGui},setCurrentWindow:function(e){this.clientGui.inputManager.setCurrentWindow(e)},onActivityLost:function(e){this.executeExternalCallback("activityLost",e)},resetActivity:function(){this.checkActivity.resetActivity()},toSpiceResolution:function(e){return{width:e.width*this.pixelRatio,height:e.height*this.pixelRatio,scaleFactor:this.pixelRatio}}}),window.Application=Application,Application.prototype.run=Application.prototype.run,Application.prototype.sendCommand=Application.prototype.sendCommand,Application.prototype.enableKeyboard=Application.prototype.enableKeyboard,Application.prototype.disableKeyboard=Application.prototype.disableKeyboard,Application.prototype.dispose=Application.prototype.dispose,Application.prototype.getKeyboardHandler=Application.prototype.getKeyboardHandler,Application.prototype.getClientGui=Application.prototype.getClientGui,Application.prototype.setCurrentWindow=Application.prototype.setCurrentWindow,Application.prototype.reconnect=Application.prototype.reconnect,Application.prototype.freeze=Application.prototype.freeze,Application.prototype.cancelFreeze=Application.prototype.cancelFreeze,Application.prototype.setReconnecting=Application.prototype.setReconnecting,Application.prototype.getReconnecting=Application.prototype.getReconnecting;wdi.VirtualMouse={eventLayers:[],mouseData:null,visible:null,lastLayer:null,hotspot:{x:0,y:0},lastMousePosition:{x:0,y:0,width:0,height:0},dispose:function(){wdi.Debug.log("Disposing VirtualMouse"),this.eventLayers=[],this.mouseData=null,this.visible=null,this.lastLayer=null,this.hotspot={x:0,y:0},this.lastMousePosition={x:0,y:0,width:0,height:0}},setHotspot:function(t,e){this.hotspot.x=t,this.hotspot.y=e},setEventLayer:function(t,e,s,i,o,n){this.eventLayers.push({layer:t,left:e,top:s,right:e+i,bottom:s+o,position:n})},removeEventLayer:function(t){for(var e=this.eventLayers.length,s=0;s<e;s++)this.eventLayers[s].layer.id===t.id&&(this.eventLayers[t.id]=void 0)},getEventLayer:function(t,e){for(var s=this.eventLayers.length,i=null,o=0;o<s;o++)if(t>=(i=this.eventLayers[o]).left&&t<=i.right&&e>=i.top&&e<=i.bottom)return i.layer},setMouse:function(t,e,s){for(var i=this.eventLayers.length,o=0;o<i;o++)this.eventLayers[o].layer.style.cursor="url("+t+") "+e+" "+s+", default"},hideMouse:function(){for(var t=this.eventLayers.length,e=0;e<t;e++)this.eventLayers[e].layer.style.cursor="none"}};wdi.ImageCache={images:{},cursor:{},palettes:{},dispose:function(){wdi.Debug.log("Disposing ImageCache"),this.images={},this.cursor={},this.palettes={}},getImageFrom:function(t,e){var i=wdi.GlobalPool.create("Canvas"),a=this.images[t.id.toString()];i.width=a.width,i.height=a.height,i.getContext("2d").putImageData(a,0,0),e(i)},isImageInCache:function(t){return t.id.toString()in this.images},delImage:function(t){delete this.images[t.toString()]},addImage:function(t,e){e.getContext?this.images[t.id.toString()]=e.getContext("2d").getImageData(0,0,2e3,e.height):this.images[t.id.toString()]=e},getCursorFrom:function(t){return this.cursor[t.header.unique.toString()]},addCursor:function(t,e){this.cursor[t.header.unique.toString()]=e},getPalette:function(t){return this.palettes[t.toString()]},addPalette:function(t,e){this.palettes[t.toString()]=e},clearPalettes:function(){this.palettes={}}};wdi.RasterOperation={dispose:function(){wdi.Debug.log("Disposing RasterOperation")},process:function(i,t,e){var a=null;return i&wdi.SpiceRopd.SPICE_ROPD_INVERS_SRC||i&wdi.SpiceRopd.SPICE_ROPD_INVERS_BRUSH?t=this.invert(t):i&wdi.SpiceRopd.SPICE_ROPD_INVERS_DEST&&(e=this.invert(e)),i&wdi.SpiceRopd.SPICE_ROPD_OP_PUT?t:(i&wdi.SpiceRopd.SPICE_ROPD_OP_OR?a=this.boolOp(t,e,"or"):i&wdi.SpiceRopd.SPICE_ROPD_OP_AND?a=this.boolOp(t,e,"and"):i&wdi.SpiceRopd.SPICE_ROPD_OP_XOR?a=this.boolOp(t,e,"xor"):i&wdi.SpiceRopd.SPICE_ROPD_OP_BLACKNESS?a=this.lightness(e,"b"):i&wdi.SpiceRopd.SPICE_ROPD_OP_WHITENESS?a=this.lightness(e):i&wdi.SpiceRopd.SPICE_ROPD_OP_INVERS&&(a=this.invert(e)),i&wdi.SpiceRopd.SPICE_ROPD_INVERS_RES?this.invert(a):a)},flip:function(i){return i=wdi.Flipper.flip(i)},invert:function(i){return i=$(i).pixastic("invert")[0]},lightness:function(i,t){t="b"===t?-100:100;return i=$(i).pixastic("hsl",{hue:30,saturation:20,lightness:t})[0]},boolOp:function(i,t,e){var a=wdi.graphics.getDataFromImage(i).data,o=wdi.graphics.getDataFromImage(t).data,p=a.length-1,d=wdi.graphics.getNewTmpCanvas(i.width,i.height),r=d.getContext("2d"),n=r.createImageData(i.width,i.height),s=n.data;if("or"===e)for(;p>0;)n.data[p]=255,s[p-1]=a[p-1]|o[p-1],s[p-2]=a[p-2]|o[p-2],s[p-3]=a[p-3]|o[p-3],p-=4;else if("and"===e)for(;p>0;)n.data[p]=255,s[p-1]=a[p-1]&o[p-1],s[p-2]=a[p-2]&o[p-2],s[p-3]=a[p-3]&o[p-3],p-=4;else if("xor"===e)for(;p>0;)n.data[p]=255,s[p-1]=a[p-1]^o[p-1],s[p-2]=a[p-2]^o[p-2],s[p-3]=a[p-3]^o[p-3],p-=4;return r.putImageData(n,0,0),d}};wdi.Stream={streams:{},dispose:function(){wdi.Debug.log("Disposing Stream"),this.streams={}},addStream:function(s,t){this.streams[s]=t},deleteStream:function(s){this.streams[s]=void 0},getStream:function(s){return this.streams[s]},clip:function(s,t){this.streams[s].clip=t},startTransition:function(s){this.streams[s].transiting=!0},endTransition:function(s){this.streams[s].transiting=!1},setReady:function(s){this.streams[s].ready=!0},addQueue:function(s,t){this.streams[s].queues||(this.streams[s].queues=[]),this.streams[s].queues.push(t)},resetQueues:function(s){this.streams[s].queues=[]}};wdi.InputManager=$.spcExtend(wdi.EventObject.prototype,{checkFocus:!1,input:null,window:null,stuckKeysHandler:null,init:function(t){this.time=Date.now(),wdi.Debug.log("inputmanager init: ",this.time),this.superInit(),this.input=t.input,this.window=t.window,this.stuckKeysHandler=t.stuckKeysHandler,this.$=t.jQuery||$,t.disableInput||(this.inputElement=this.$('<div style="position:absolute"><input type="text" id="inputmanager" autocomplete="off" value="_" style="opacity: 0; color: transparent"/></div>')),this.currentWindow=null,this.getClientSO(),this.tildeMarks=["´","`","^","¨"],this.lastChar=null,this.tildeReplacements={a:{0:"á",1:"à",2:"â",3:"ä"},e:{0:"é",1:"è",2:"ê",3:"ë"},i:{0:"í",1:"ì",2:"î",3:"ï"},o:{0:"ó",1:"ò",2:"ô",3:"ö"},u:{0:"ú",1:"ù",2:"û",3:"ü"},A:{0:"Á",1:"À",2:"Â",3:"Ä"},E:{0:"É",1:"È",2:"Ê",3:"Ë"},I:{0:"Í",1:"Ì",2:"Î",3:"Ï"},O:{0:"Ó",1:"Ò",2:"Ô",3:"Ö"},U:{0:"Ú",1:"Ù",2:"Û",3:"Ü"}}},getClientSO:function(){var t=window.navigator.platform.toLowerCase();t.indexOf("mac")>-1?this.clientSO="mac":t.indexOf("linux")?this.clientSO="linux":this.clientSO="windows"},setCurrentWindow:function(t){t=this.$(t),this.currentWindow&&(this.inputElement.remove(),this.currentWindow.unbind("blur")),this.$(t[0].document.getElementById("vmw")).prepend(this.inputElement),this.input=this.$(t[0].document.getElementById("inputmanager")),this.addListeners(t),this.currentWindow=t},dispose:function(){this.disposed=!0,this.inputElement.remove(),this.currentWindow.unbind("blur"),this.currentWindow.unbind("input"),this.inputElement=null,this.checkFocus=!1,this.input=null,this.window=null,this.stuckKeysHandler=null},addListeners:function(t){this._onBlur(t),this._onInput()},_onBlur:function(t){var i=this;t.on("blur",(function(t){i.checkFocus&&i.input.focus(),i.stuckKeysHandler.releaseSpecialKeysPressed()}))},_onInput:function(){var t=this;this.input.on("input",(function(i){t.input.val().length>1&&t.reset()}))},enable:function(){wdi.Debug.log("enable!!!!!!!!!! ",this.time),this.checkFocus=!0,this.input.select()},disable:function(){this.checkFocus=!1,this.input&&this.input.blur()},reset:function(){this.input.val("")},getValue:function(){var t=this.input.val();if(t&&this.reset(),"mac"===this.clientSO){if(this.tildeMarks.indexOf(this.lastChar)>-1&&this.tildeReplacements.hasOwnProperty(t))switch(this.lastChar){case this.tildeMarks[0]:t=this.tildeReplacements[t][0];break;case this.tildeMarks[1]:t=this.tildeReplacements[t][1];break;case this.tildeMarks[2]:t=this.tildeReplacements[t][2];break;case this.tildeMarks[3]:t=this.tildeReplacements[t][3]}t&&this.tildeMarks.indexOf(t)>-1?t!=this.lastChar?(this.lastChar=t,t=""):t===this.lastChar&&(this.lastChar=""):this.lastChar=t||this.lastChar}return t},manageChar:function(t,i){var e=[Object.create(i[0])];return e[0].type="inputmanager",e[0].charCode=t.charCodeAt(0),e},isSpecialKey:function(t){return-1!==[17].indexOf(t)}});wdi.BUS_TYPES={file:0,print:1,launchApplication:2,windowManagement:3,menu:5,networkDriveManagement:6,clipboard:9,generic:99,killApplicationDoNotUseInProductionEver:34423423},wdi.BusProcess=$.spcExtend(wdi.EventObject.prototype,{busConnection:null,clientGui:null,init:function(e){this.superInit(),this.clientGui=e.clientGui,this.busConnection=e.busConnection},dispose:function(){this.clientGui=null,this.busConnection=null},process:function(e){switch(e.verb){case"CONNECTED":this.busConnection.setSubscriptions(),this.fire("busConnected");break;case"MESSAGE":this.parseMessage(e.body);break;case"ERROR":console.error("Bus error");break;default:wdi.Debug.warn("Not implemented Stomp Verb: "+e.verb)}},parseMessage:function(e){switch(parseInt(e.type)){case wdi.BUS_TYPES.launchApplication:this.parseLaunchApplicationMessage(e);break;case wdi.BUS_TYPES.killApplicationDoNotUseInProductionEver:break;case wdi.BUS_TYPES.windowManagement:this.parseWindowManagementMessage(e);break;case wdi.BUS_TYPES.menu:this.handleMenuMessage(e);break;case wdi.BUS_TYPES.networkDriveManagement:this._handleNetworkDriveMessage(e);break;case wdi.BUS_TYPES.clipboard:this.handleClipboardMessage(e);break;default:this.fire("defaultTypeEvent",e)}},_handleNetworkDriveMessage:function(e){"reMountNetworkDrive"!=e.event&&this.fire("networkDriveResponse",e)},getMenu:function(){this.busConnection.send({type:wdi.BUS_TYPES.menu,value:!1,event:"request"})},handleMenuMessage:function(e){"response"==e.event&&this.fire("menuResponse",e)},handleClipboardMessage:function(e){"selectedText"!==e.event&&"copiedText"!==e.event||this.fire(e.event,e)},parseWindowManagementMessage:function(e){switch(e.event){case"windowList":case"windowCreated":case"windowClosed":case"windowMoved":case"windowResized":case"windowFocused":case"windowMinimized":case"windowRestored":case"windowMaximized":this.fire(e.event,e.value);break;default:wdi.Debug.info("Event '"+e.event+"' not implemented.")}},closeWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"closeWindow",hwnd:e}))},moveWindow:function(e,n,t){this.busConnection.send(this._constructWindowManagementMessage({event:"moveWindow",hwnd:e,left:n,top:t}))},minimizeWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"minimizeWindow",hwnd:e}))},maximizeWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"maximizeWindow",hwnd:e}))},restoreWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"restoreWindow",hwnd:e}))},focusWindow:function(e){this.busConnection.send(this._constructWindowManagementMessage({event:"focusWindow",hwnd:e}))},resizeWindow:function(e,n,t){this.busConnection.send(this._constructWindowManagementMessage({event:"resizeWindow",hwnd:e,width:n,height:t}))},requestWindowList:function(){this.busConnection.send(this._constructWindowManagementMessage({event:"getWindowList"}))},executeCommand:function(e){this.busConnection.send({type:wdi.BUS_TYPES.launchApplication,application:e})},refreshFileSystem:function(e){this.busConnection.send({type:wdi.BUS_TYPES.file,event:"refreshFileSystem",value:{}})},_constructGenericMessage:function(e,n){return{type:wdi.BUS_TYPES.generic,event:e,value:n||{}}},_constructWindowManagementMessage:function(e){if(void 0===e.event)throw new Error("You should pass an 'event' attribute in the object");var n={type:wdi.BUS_TYPES.windowManagement,event:e.event,value:{}};for(var t in e)"event"!=t&&e.hasOwnProperty(t)&&(n.value[t]=e[t]);return n},reMountNetworkDrive:function(e,n,t){this.busConnection.send({type:wdi.BUS_TYPES.networkDriveManagement,event:"reMountNetworkDrive",host:e,username:n,password:t})},parseLaunchApplicationMessage:function(e){switch(e.event){case"applicationLauncherWrongAppPathError":this.fire("wrongPathError",e);break;case"applicationLaunchedSuccessfully":this.fire("applicationLaunchedSuccessfully",e);break;default:wdi.Debug.info("Event '"+e.event+"' not implemented.")}},sendGenericMessage:function(e,n){this.busConnection.send(this._constructGenericMessage(e,n))}});wdi.DisplayProcess=$.spcExtend(wdi.EventObject.prototype,{runQ:null,packetFilter:null,init:function(i){this.runQ=i.runQ||wdi.ExecutionControl.runQ,this.packetFilter=i.packetFilter||wdi.PacketFilter,this.clientGui=i.clientGui,this.displayRouter=i.displayRouter||new wdi.DisplayRouter({clientGui:this.clientGui}),this.started=!1,this.waitingMessages=[],this.packetWorkerIdentifier=i.packetWorkerIdentifier||new wdi.PacketWorkerIdentifier,this.disableMessageBuffering=i.disableMessageBuffering},dispose:function(){wdi.Debug.log("Disposing DisplayProcess"),clearInterval(this.timer),this.timer=null,this.runQ=null,this.packetFilter.dispose(),this.packetFilter=null,this.clientGui=null,this.displayRouter.dispose(),this.displayRouter=null,this.packetWorkerIdentifier.dispose(),this.packetWorkerIdentifier=null,this.started=!1,this.waitingMessages=[]},process:function(i){if(this.disableMessageBuffering)this._process(i);else{var e=this;this.waitingMessages.push(i),this.started||(this.timer=setInterval((function(){e.flush()}),50),this.started=!0)}},flush:function(){if(0!==this.waitingMessages.length){var i,e=0;this.removeRedundantDraws();for(var t=this.waitingMessages.length;e<t;)i=this.waitingMessages[e],this._process(i),e++;this.waitingMessages=[]}},removeRedundantDraws:function(){if(!(this.waitingMessages.length<2)){for(var i,e,t,s,r,n,a,o,l,c,h=this.waitingMessages.length,u={},p=[],d=!1;h--;)if(r=(e=(i=this.waitingMessages[h]).args).base,s=e.rop_descriptor,d=!1,r){if(r.surface_id,a=r.box,n=r.surface_id,t=this.packetWorkerIdentifier.getImageProperties(i),u[n]||(u[n]=[]),(!t||t&&!(t.descriptor.flags&wdi.SpiceImageFlags.SPICE_IMAGE_FLAGS_CACHE_ME))&&0===n)for(l=0;l<u[n].length;l++)if((o=u[n][l]).bottom>=a.bottom&&o.top<=a.top&&o.left<=a.left&&o.right>=a.right){d=!0,p.push(h);break}if(!d&&i.messageType===wdi.SpiceVars.SPICE_MSG_DISPLAY_COPY_BITS)break;!d&&e.getMessageProperty("overWriteScreenArea",!1)&&0==r.clip.type&&s==wdi.SpiceRopd.SPICE_ROPD_OP_PUT&&u[n].push(r.box)}for(c=0;c<p.length;c++)this.waitingMessages.splice(p[c],1)}},_process:function(i){wdi.logOperations&&wdi.DataLogger.log(i,0,null,!0,"","_decode"),this.runQ.add((function(e){this.packetFilter.filter(i,(function(i){wdi.ExecutionControl.currentProxy=e,this.displayRouter.processPacket(i),this.postProcess()}),this,this.clientGui),wdi.ExecutionControl.sync&&e.end()}),this,(function(){this.processEnd(i,this.clientGui)})),this.runQ.process()},processEnd:function(i,e){this.packetFilter.notifyEnd(i,e)},postProcess:function(){}});wdi.DisplayPreProcess=$.spcExtend(wdi.EventObject.prototype,{displayProcess:null,queued:[],inProcess:[],idleConsumers:[],consumers:[],init:function(s){this.idleConsumers=[],this.superInit(),this.displayProcess=s.displayProcess||new wdi.DisplayProcess({clientGui:s.clientGui,disableMessageBuffering:s.disableMessageBuffering}),this.clientGui=s.clientGui,null!=s.numConsumers&&null!=s.numConsumers||(s.numConsumers=4);for(var e=s.numConsumers,i=0;i<e;i++){var n=new wdi.AsyncConsumer;this.consumers.push(n),this.idleConsumers.push(n),n.addListener("done",this.onConsumerDone,this)}},onConsumerDone:function(s){for(var e=this.inProcess[0],i=null;e&&1===e.state;){i=this.inProcess.shift();try{this.displayProcess.process(i.message)}catch(s){wdi.Debug.error("DisplayPreProcess error: ",s)}e=this.inProcess[0]}this.idleConsumers.push(s),this.queued.length>0&&this.executeConsumer()},process:function(s){this.addTask(s),this.executeConsumer()},addTask:function(s){this.queued.push({message:s,clientGui:this.clientGui})},getNextTask:function(){for(var s=this.queued.shift();void 0===s&&0!=this.queued.length;)s=this.queued.shift();return void 0!==s&&(s.state=0,this.inProcess.push(s),s)},executeConsumer:function(){if(this.idleConsumers.length>0){wdi.Debug.log("DisplayPreProcess: available workers: "+this.idleConsumers.length),wdi.Debug.log("DisplaypreProcess: pending tasks: "+this.queued.length);var s=this.idleConsumers.shift(),e=this.getNextTask();e&&s.consume(e)}},dispose:function(){wdi.Debug.log("displaypreprocess dispose ################ idleConsumers: ",this.idleConsumers.length),this.clearEvents(),this.clientGui=null,this.queued=[],this.inProcess=[],this.idleConsumers=[],this.displayProcess.dispose(),this.displayProcess=null,this.consumers.forEach((function(s){s.clearEvents(),s.dispose()})),this.consumers=[]}});wdi.InputProcess=$.spcExtend(wdi.EventObject.prototype,{clientGui:null,spiceConnection:null,capsLockPressed:!1,numLockPressed:!1,shiftPressed:!1,init:function(e){this.superInit(),this.clientGui=e.clientGui,this.spiceConnection=e.spiceConnection},dispose:function(){this.clearEvents(),this.clientGui=null,this.spiceConnection=null},process:function(e){if(e.messageType===wdi.SpiceVars.SPICE_MSG_INPUTS_MOUSE_MOTION_ACK)this.clientGui.motion_ack()},send:function(e,s){var i,n,c;if("mousemove"==s)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_POSITION,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMousePosition({x:e[1][0]+wdi.VirtualMouse.hotspot.x,y:e[1][1]+wdi.VirtualMouse.hotspot.y,buttons_state:e[1][2],display_id:0})}),this.spiceConnection.send(i);else if("mousedown"==s)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_PRESS,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMousePress({button_id:e[1]+1,buttons_state:1<<e[1]})}),this.spiceConnection.send(i);else if("mouseup"==s)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_RELEASE,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMousePress({button_id:e[1]+1,buttons_state:0})}),this.spiceConnection.send(i);else if("keydown"==s||"keypress"==s){n=wdi.Keymap.getScanCodes(e[1][0]);const t=e[1][0].originalEvent;if("keydown"==s&&20!==e[1][0].keyCode&&(!wdi.Keymap.isVirtualKeyboard&&t&&t.getModifierState&&wdi.Keymap.capsLock!==t.getModifierState("CapsLock")||wdi.Keymap.isVirtualKeyboard&&wdi.Keymap.isVirtualCapsLockOn!==wdi.Keymap.capsLock)){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([58,0,0])});this.capsLockPressed=!0,this.spiceConnection.send(e)}if("keydown"==s&&t&&t.getModifierState&&144!==e[1][0].keyCode&&wdi.Keymap.numLock!==t.getModifierState("NumLock")){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([69,0,0])});this.numLockPressed=!0,this.spiceConnection.send(e)}for(c=0;c<n.length;c++)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode(n[c])}),n[0]&&42===n[0][0]&&(this.shiftPressed=!0),this.spiceConnection.send(i)}else if("keyup"==s){if((n=wdi.Keymap.getScanCodes(e[1][0]))&&n[0]&&199===n[0][0]&&0===n[0][1]&&0===n[0][2]&&(n=[[224,199,0,0]]),this.capsLockPressed){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([186,0,0])});this.spiceConnection.send(e),this.capsLockPressed=!1}if(this.numLockPressed){const e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode([197,0,0])});this.spiceConnection.send(e),this.numLockPressed=!1}for(n[0]&&142===n[0][0]&&(this.shiftPressed=!1),c=0;c<n.length;c++)i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.SpiceScanCode(n[c])}),this.spiceConnection.send(i);this.clientGui.inputManager.input.val("_")}else"joystick"==s&&(i=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_INPUTS_MOUSE_MOTION,channel:wdi.SpiceVars.SPICE_CHANNEL_INPUTS,args:new wdi.RedcMouseMotion({x:e[1][0],y:e[1][1],buttons_state:0})}),this.spiceConnection.send(i))},isKeyboardShortcut:function(e,s){if("keydown"===e){var i=s.keyCode;return wdi.Keymap.controlPressed(i,e,s),wdi.Keymap.handledByCtrlKeyCode(e,i,!0)}}});wdi.CursorProcess=$.spcExtend(wdi.EventObject.prototype,{imageData:null,process:function(r){switch(r.messageType){case wdi.SpiceVars.SPICE_MSG_CURSOR_INIT:case wdi.SpiceVars.SPICE_MSG_CURSOR_SET:var e=this.extractCursor(r);e&&(wdi.VirtualMouse.setHotspot(0,0),wdi.VirtualMouse.setMouse(e.data,e.header.hot_spot_x,e.header.hot_spot_y));case wdi.SpiceVars.SPICE_MSG_CURSOR_HIDE:}},dispose:function(){this.clearEvents(),this.imageData=null},_toUrl:function(r){var e=$("<canvas/>").attr({width:r.width,height:r.height})[0];return e.getContext("2d").putImageData(r,0,0),e.toDataURL("image/png")},extractCursor:function(r){var e=r.args.cursor.flags,s=r.args.position,a=r.args.visible;if(1&e)return null;var i=null;if(e&wdi.SpiceCursorFlags.SPICE_CURSOR_FLAGS_FROM_CACHE)i=wdi.ImageCache.getCursorFrom(r.args.cursor);else switch(r.args.cursor.header.type){case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_ALPHA:i=this._toUrl(wdi.graphics.argbToImageData(r.args.cursor.data,r.args.cursor.header.width,r.args.cursor.header.height));break;case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_MONO:i=this._toUrl(wdi.graphics.monoToImageData(r.args.cursor.data,r.args.cursor.header.width,r.args.cursor.header.height));break;case 8:i=wdi.SpiceObject.bytesToString(r.args.cursor.data);case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR4:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR8:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR16:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR24:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_COLOR32:case wdi.SpiceCursorType.SPICE_CURSOR_TYPE_ENUM_END:}return i?(e&wdi.SpiceCursorFlags.SPICE_CURSOR_FLAGS_CACHE_ME&&wdi.ImageCache.addCursor(r.args.cursor,i),{data:i,position:s,visible:a,header:r.args.cursor.header}):null}});wdi.PlaybackProcess=$.spcExtend(wdi.EventObject.prototype,{_lastApp:null,started:!1,minBuffSize:32768,frequency:null,channels:null,audioContext:null,startTime:null,hasAudioSupport:!0,typedBuffer:null,position:null,init:function(t){this.app=t.app,this.audioContext=this.getAudioContext(),this.audioContext?this.hasAudioSupport=!0:(this.hasAudioSupport=!1,wdi.Debug.warn("The client browser does not support Web Audio API")),this.startTime=0,this.typedBuffer=new ArrayBuffer(34688),this.position=0},dispose:function(){this.clearEvents(),this._lastApp=null,this.started=!1,this.frequency=null,this.channels=null,this.audioContext=null,this.startTime=null,this.hasAudioSupport=!0,this.typedBuffer=null,this.position=null},getAudioContext:function(){try{return new AudioContext}catch(t){}try{return new webkitAudioContext}catch(t){}return!1},process:function(t){if(this.hasAudioSupport)switch(t.messageType){case wdi.SpiceVars.SPICE_MSG_PLAYBACK_MODE:break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_START:var e=t.args;this.channels=e.channels,this.frequency=e.frequency;break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_STOP:this.startTime=0;e=t.args;this.flush();break;case wdi.SpiceVars.SPICE_MSG_PLAYBACK_DATA:e=t.args;var i=t.args.multimedia_time;new Uint8Array(this.typedBuffer).set(e.data,this.position),this.position+=e.data.length,this._lastApp=this.app,this.position>=this.minBuffSize&&this.flush(i)}},flush:function(t){this.position>0&&(this.started&&this.playSound(this.typedBuffer,t),this.position=0,this.typedBuffer=new ArrayBuffer(34688))},playSound:function(t,e){if(2==this.channels)return this.playSoundStereo(t,e);for(var i=new Int16Array(t),s=new Array(this.channels),n=0;n<this.channels;n++)s[n]=new Float32Array(i.length/2);var a=0;for(n=0;n<i.length;){for(var r=0;r<this.channels;r++)s[r][a]=i[n++]/32768;a++}var h=this.audioContext.createBufferSource(),o=this.audioContext.createBuffer(this.channels,a,this.frequency);for(n=0;n<this.channels;n++)o.getChannelData(n).set(s[n]);this._play(h,o,e)},playSoundStereo:function(t,e){for(var i=new Int16Array(t),s=new Float32Array(i.length/2),n=new Float32Array(i.length/2),a=0,r=this.audioContext,h=i.length,o=0;o<h;)s[a]=i[o++]/32768,n[a]=i[o++]/32768,a++;var u=r.createBufferSource(),l=r.createBuffer(2,a,this.frequency);l.getChannelData(0).set(s),l.getChannelData(1).set(n),this._play(u,l,e)},_play:function(t,e,i){var s=0;i&&((s=i-(Date.now()-this.app.lastMultimediaTime+this.app.multimediaTime))<0&&(s=0));t.buffer=e,t.connect(this.audioContext.destination),t.start(this.startTime+s),this.startTime+=e.duration},startAudio:function(){this.started=!0,this.flush()}});wdi.MainProcess=$.spcExtend(wdi.EventObject.prototype,{init:function(e){this.superInit(),this.app=e.app,this.spiceConnection=e.app.spiceConnection,this.agent=e.app.agent},dispose:function(){this.clearEvents(),this.app=null,this.spiceConnection=null,this.agent=null},process:function(e){var i=this.spiceConnection.channels[wdi.SpiceVars.SPICE_CHANNEL_MAIN];switch(e.messageType){case wdi.SpiceVars.SPICE_MSG_MAIN_INIT:i.connectionId=e.args.session_id,i.fire("connectionId",i.connectionId),1==e.args.agent_connected&&i.fire("initAgent",e.args.agent_tokens),1==e.args.current_mouse_mode&&i.fire("mouseMode",e.args.current_mouse_mode),this.changeMouseMode();break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_DATA:var s=e.args;this.agent.onAgentData(s);break;case wdi.SpiceVars.SPICE_MSG_MAIN_AGENT_CONNECTED:i.fire("initAgent",e.args.agent_tokens),this.changeMouseMode();break;case wdi.SpiceVars.SPICE_MSG_MAIN_MULTI_MEDIA_TIME:this.app.multimediaTime=e.args.multimedia_time;break;case wdi.SpiceVars.SPICE_MSG_MAIN_CHANNELS_LIST:i.fire("channelListAvailable",e.args.channels)}},changeMouseMode:function(){var e=new wdi.SpiceMessage({messageType:wdi.SpiceVars.SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST,channel:wdi.SpiceVars.SPICE_CHANNEL_MAIN,args:new wdi.SpiceMouseModeRequest({request_mode:wdi.SpiceMouseModeTypes.SPICE_MOUSE_MODE_CLIENT})});this.spiceConnection.send(e)}});wdi.KeyEvent={isCtrlPressed:function(e){if(!e)throw new Error("isCtrlPressed: No event provided.");var r=e.ctrlKey;return-1!=navigator.platform.indexOf("Mac")&&(r=e.metaKey),r}};wdi.KeymapES=function(){var e={Backquote:[[5,0,0,0],[133,0,0,0]],Digit1:[[2,0,0,0],[130,0,0,0]],Digit2:[[3,0,0,0],[131,0,0,0]],Digit3:[[4,0,0,0],[132,0,0,0]],Digit4:[[5,0,0,0],[133,0,0,0]],Digit5:[[6,0,0,0],[134,0,0,0]],Digit6:[[7,0,0,0],[135,0,0,0]],Digit7:[[8,0,0,0],[136,0,0,0]],Digit8:[[9,0,0,0],[137,0,0,0]],Digit9:[[10,0,0,0],[138,0,0,0]],Digit0:[[11,0,0,0],[139,0,0,0]],Minus:[[53,0,0,0],[181,0,0,0]],Equal:[[11,0,0,0],[139,0,0,0]],KeyQ:[[16,0,0,0],[144,0,0,0]],KeyW:[[17,0,0,0],[145,0,0,0]],KeyE:[[18,0,0,0],[146,0,0,0]],KeyR:[[19,0,0,0],[147,0,0,0]],KeyT:[[20,0,0,0],[148,0,0,0]],KeyY:[[21,0,0,0],[149,0,0,0]],KeyU:[[22,0,0,0],[150,0,0,0]],KeyI:[[23,0,0,0],[151,0,0,0]],KeyO:[[24,0,0,0],[152,0,0,0]],KeyP:[[25,0,0,0],[153,0,0,0]],BracketLeft:[[26,0,0,0],[154,0,0,0]],BracketRight:[[27,0,0,0],[155,0,0,0]],Backslash:[[41,0,0,0],[169,0,0,0]],KeyA:[[30,0,0,0],[158,0,0,0]],KeyS:[[31,0,0,0],[159,0,0,0]],KeyD:[[32,0,0,0],[160,0,0,0]],KeyF:[[33,0,0,0],[161,0,0,0]],KeyG:[[34,0,0,0],[162,0,0,0]],KeyH:[[35,0,0,0],[163,0,0,0]],KeyJ:[[36,0,0,0],[164,0,0,0]],KeyK:[[37,0,0,0],[165,0,0,0]],KeyL:[[38,0,0,0],[166,0,0,0]],Semicolon:[[51,0,0,0],[179,0,0,0]],Quote:[[12,0,0,0],[140,0,0,0]],KeyZ:[[44,0,0,0],[172,0,0,0]],KeyX:[[45,0,0,0],[173,0,0,0]],KeyC:[[46,0,0,0],[174,0,0,0]],KeyV:[[47,0,0,0],[175,0,0,0]],KeyB:[[48,0,0,0],[176,0,0,0]],KeyN:[[49,0,0,0],[177,0,0,0]],KeyM:[[50,0,0,0],[178,0,0,0]],Comma:[[51,0,0,0],[179,0,0,0]],Period:[[52,0,0,0],[180,0,0,0]],Slash:[[53,0,0,0],[181,0,0,0]],Numpad0:[[11,0,0,0],[139,0,0,0]],Numpad1:[[2,0,0,0],[130,0,0,0]],Numpad2:[[3,0,0,0],[131,0,0,0]],Numpad3:[[4,0,0,0],[132,0,0,0]],Numpad4:[[5,0,0,0],[133,0,0,0]],Numpad5:[[6,0,0,0],[134,0,0,0]],Numpad6:[[7,0,0,0],[135,0,0,0]],Numpad7:[[8,0,0,0],[136,0,0,0]],Numpad8:[[9,0,0,0],[137,0,0,0]],Numpad9:[[10,0,0,0],[138,0,0,0]],NumpadDivide:[[53,0,0,0],[181,0,0,0]],NumpadMultiply:[[55,0,0,0],[183,0,0,0]],NumpadSubtract:[[74,0,0,0],[202,0,0,0]],NumpadAdd:[[78,0,0,0],[206,0,0,0]],NumpadDecimal:[[52,0,0,0],[180,0,0,0]]},t=[];t[27]=1,t[9]=15,t[20]=58,t[16]=42,t[91]=29,t[17]=29,t[32]=57,t[8]=14,t[13]=28,t[18]=56,t[92]=92,t[93]=93,t[38]=72,t[37]=75,t[40]=80,t[39]=77,t[45]=82,t[46]=83,t[36]=71,t[35]=79,t[33]=73,t[34]=81,t[144]=69,t[145]=70,t[112]=59,t[113]=60,t[114]=61,t[115]=62,t[116]=63,t[117]=64,t[118]=65,t[119]=66,t[120]=67,t[121]=68,t[122]=87,t[123]=88;var i=[];i[81]=16,i[87]=17,i[69]=18,i[82]=19,i[84]=20,i[89]=21,i[85]=22,i[73]=23,i[79]=24,i[80]=25,i[65]=30,i[83]=31,i[68]=32,i[70]=33,i[71]=34,i[72]=35,i[74]=36,i[75]=37,i[76]=38,i[90]=44,i[88]=45,i[67]=46,i[86]=47,i[66]=48,i[78]=49,i[77]=50;var a=[];a[9]=15;var u=[];return u[81]=16,u[87]=17,u[69]=18,u[82]=19,u[84]=20,u[89]=21,u[85]=22,u[73]=23,u[79]=24,u[80]=25,u[65]=30,u[83]=31,u[68]=32,u[70]=33,u[71]=34,u[72]=35,u[74]=36,u[75]=37,u[76]=38,u[90]=44,u[88]=45,u[86]=47,u[67]=46,u[66]=48,u[78]=49,u[77]=50,{getKeymap:function(){return t},getCtrlKeymap:function(){return i},getCtrlForbiddenKeymap:function(){return a},getReservedCtrlKeymap:function(){return u},getCharmap:function(){return e},setCtrlKey:function(e,t){i[e]=t}}}();wdi.scanCodeObjProvider=$.spcExtend(wdi.EventObject.prototype,{init:function(t){this.charObj=t},getPrefix:function(){return this.prefix},getSufix:function(){return this.suffix},setPrefix:function(t){},setSuffix:function(t){},getScanCode:function(){var t=[],i=this.charObj.main;return t=t.concat(i)}});wdi.ScanCodeObjModifier=$.spcExtend(wdi.EventObject.prototype,{SHIFTDOWN:[42,0,0,0],SHIFTUP:[170,0,0,0],init:function(n){this.scanCodeObjProvider=new wdi.scanCodeObjProvider(n),this.prefix=[],this.suffix=[]},removeShift:function(){return this.getScanCode()},containsShiftDown:function(){return!1},addShiftUp:function(){},addShiftDown:function(){},getScanCode:function(){return this.scanCodeObjProvider.getScanCode()},_removeKeyFromPart:function(n,t){return t.filter((function(t){return!_.isEqual(t,n)}))}});wdi.KeymapObjES=function(){var i={Backquote:{prefix:[],main:[[41,0,0,0],[169,0,0,0]],suffix:[]},Digit1:{prefix:[],main:[[2,0,0,0],[130,0,0,0]],suffix:[]},Digit2:{prefix:[],main:[[3,0,0,0],[131,0,0,0]],suffix:[]},Digit3:{prefix:[],main:[[4,0,0,0],[132,0,0,0]],suffix:[]},Digit4:{prefix:[],main:[[5,0,0,0],[133,0,0,0]],suffix:[]},Digit5:{prefix:[],main:[[6,0,0,0],[134,0,0,0]],suffix:[]},Digit6:{prefix:[],main:[[7,0,0,0],[135,0,0,0]],suffix:[]},Digit7:{prefix:[],main:[[8,0,0,0],[136,0,0,0]],suffix:[]},Digit8:{prefix:[],main:[[9,0,0,0],[137,0,0,0]],suffix:[]},Digit9:{prefix:[],main:[[10,0,0,0],[138,0,0,0]],suffix:[]},Digit0:{prefix:[],main:[[11,0,0,0],[139,0,0,0]],suffix:[]},Minus:{prefix:[],main:[[12,0,0,0],[140,0,0,0]],suffix:[]},Equal:{prefix:[],main:[[13,0,0,0],[141,0,0,0]],suffix:[]},KeyQ:{prefix:[],main:[[16,0,0,0],[144,0,0,0]],suffix:[]},KeyW:{prefix:[],main:[[17,0,0,0],[145,0,0,0]],suffix:[]},KeyE:{prefix:[],main:[[18,0,0,0],[146,0,0,0]],suffix:[]},KeyR:{prefix:[],main:[[19,0,0,0],[147,0,0,0]],suffix:[]},KeyT:{prefix:[],main:[[20,0,0,0],[148,0,0,0]],suffix:[]},KeyY:{prefix:[],main:[[21,0,0,0],[149,0,0,0]],suffix:[]},KeyU:{prefix:[],main:[[22,0,0,0],[150,0,0,0]],suffix:[]},KeyI:{prefix:[],main:[[23,0,0,0],[151,0,0,0]],suffix:[]},KeyO:{prefix:[],main:[[24,0,0,0],[152,0,0,0]],suffix:[]},KeyP:{prefix:[],main:[[25,0,0,0],[153,0,0,0]],suffix:[]},BracketLeft:{prefix:[],main:[[26,0,0,0],[154,0,0,0]],suffix:[]},BracketRight:{prefix:[],main:[[27,0,0,0],[155,0,0,0]],suffix:[]},Backslash:{prefix:[],main:[[43,0,0,0],[171,0,0,0]],suffix:[]},KeyA:{prefix:[],main:[[30,0,0,0],[158,0,0,0]],suffix:[]},KeyS:{prefix:[],main:[[31,0,0,0],[159,0,0,0]],suffix:[]},KeyD:{prefix:[],main:[[32,0,0,0],[160,0,0,0]],suffix:[]},KeyF:{prefix:[],main:[[33,0,0,0],[161,0,0,0]],suffix:[]},KeyG:{prefix:[],main:[[34,0,0,0],[162,0,0,0]],suffix:[]},KeyH:{prefix:[],main:[[35,0,0,0],[163,0,0,0]],suffix:[]},KeyJ:{prefix:[],main:[[36,0,0,0],[164,0,0,0]],suffix:[]},KeyK:{prefix:[],main:[[37,0,0,0],[165,0,0,0]],suffix:[]},KeyL:{prefix:[],main:[[38,0,0,0],[166,0,0,0]],suffix:[]},Semicolon:{prefix:[],main:[[39,0,0,0],[167,0,0,0]],suffix:[]},Quote:{prefix:[],main:[[40,0,0,0],[168,0,0,0]],suffix:[]},KeyZ:{prefix:[],main:[[44,0,0,0],[172,0,0,0]],suffix:[]},KeyX:{prefix:[],main:[[45,0,0,0],[173,0,0,0]],suffix:[]},KeyC:{prefix:[],main:[[46,0,0,0],[174,0,0,0]],suffix:[]},KeyV:{prefix:[],main:[[47,0,0,0],[175,0,0,0]],suffix:[]},KeyB:{prefix:[],main:[[48,0,0,0],[176,0,0,0]],suffix:[]},KeyN:{prefix:[],main:[[49,0,0,0],[177,0,0,0]],suffix:[]},KeyM:{prefix:[],main:[[50,0,0,0],[178,0,0,0]],suffix:[]},Comma:{prefix:[],main:[[51,0,0,0],[179,0,0,0]],suffix:[]},Period:{prefix:[],main:[[52,0,0,0],[180,0,0,0]],suffix:[]},Slash:{prefix:[],main:[[53,0,0,0],[181,0,0,0]],suffix:[]},Numpad0:{prefix:[],main:[[11,0,0,0],[139,0,0,0]],suffix:[]},Numpad1:{prefix:[],main:[[2,0,0,0],[130,0,0,0]],suffix:[]},Numpad2:{prefix:[],main:[[3,0,0,0],[131,0,0,0]],suffix:[]},Numpad3:{prefix:[],main:[[4,0,0,0],[132,0,0,0]],suffix:[]},Numpad4:{prefix:[],main:[[5,0,0,0],[133,0,0,0]],suffix:[]},Numpad5:{prefix:[],main:[[6,0,0,0],[134,0,0,0]],suffix:[]},Numpad6:{prefix:[],main:[[7,0,0,0],[135,0,0,0]],suffix:[]},Numpad7:{prefix:[],main:[[8,0,0,0],[136,0,0,0]],suffix:[]},Numpad8:{prefix:[],main:[[9,0,0,0],[137,0,0,0]],suffix:[]},Numpad9:{prefix:[],main:[[10,0,0,0],[138,0,0,0]],suffix:[]},NumpadDivide:{prefix:[],main:[[224,53,0,0],[0,0,0,0]],suffix:[]},NumpadMultiply:{prefix:[],main:[[55,0,0,0],[183,0,0,0]],suffix:[]},NumpadSubtract:{prefix:[],main:[[74,0,0,0],[202,0,0,0]],suffix:[]},NumpadAdd:{prefix:[],main:[[78,0,0,0],[206,0,0,0]],suffix:[]},NumpadDecimal:{prefix:[],main:[[83,0,0,0],[211,0,0,0]],suffix:[]}};return{getScanCode:function(i){return new wdi.scanCodeObjProvider(this.getCharmap()[i]).getScanCode()},getCharmap:function(){return i}}}();wdi.KeymapUS=function(){var e=[];e.Backquote=[[5,0,0,0],[133,0,0,0]],e.Digit1=[[2,0,0,0],[130,0,0,0]],e.Digit2=[[3,0,0,0],[131,0,0,0]],e.Digit3=[[4,0,0,0],[132,0,0,0]],e.Digit4=[[5,0,0,0],[133,0,0,0]],e.Digit5=[[6,0,0,0],[134,0,0,0]],e.Digit6=[[7,0,0,0],[135,0,0,0]],e.Digit7=[[8,0,0,0],[136,0,0,0]],e.Digit8=[[9,0,0,0],[137,0,0,0]],e.Digit9=[[10,0,0,0],[138,0,0,0]],e.Digit0=[[11,0,0,0],[139,0,0,0]],e.Minus=[[53,0,0,0],[181,0,0,0]],e.Equal=[[11,0,0,0],[139,0,0,0]],e.KeyQ=[[16,0,0,0],[144,0,0,0]],e.KeyW=[[17,0,0,0],[145,0,0,0]],e.KeyE=[[18,0,0,0],[146,0,0,0]],e.KeyR=[[19,0,0,0],[147,0,0,0]],e.KeyT=[[20,0,0,0],[148,0,0,0]],e.KeyY=[[21,0,0,0],[149,0,0,0]],e.KeyU=[[22,0,0,0],[150,0,0,0]],e.KeyI=[[23,0,0,0],[151,0,0,0]],e.KeyO=[[24,0,0,0],[152,0,0,0]],e.KeyP=[[25,0,0,0],[153,0,0,0]],e.BracketLeft=[[26,0,0,0],[154,0,0,0]],e.BracketRight=[[27,0,0,0],[155,0,0,0]],e.Backslash=[[41,0,0,0],[169,0,0,0]],e.KeyA=[[30,0,0,0],[158,0,0,0]],e.KeyS=[[31,0,0,0],[159,0,0,0]],e.KeyD=[[32,0,0,0],[160,0,0,0]],e.KeyF=[[33,0,0,0],[161,0,0,0]],e.KeyG=[[34,0,0,0],[162,0,0,0]],e.KeyH=[[35,0,0,0],[163,0,0,0]],e.KeyJ=[[36,0,0,0],[164,0,0,0]],e.KeyK=[[37,0,0,0],[165,0,0,0]],e.KeyL=[[38,0,0,0],[166,0,0,0]],e.Semicolon=[[51,0,0,0],[179,0,0,0]],e.Quote=[[12,0,0,0],[140,0,0,0]],e.KeyZ=[[44,0,0,0],[172,0,0,0]],e.KeyX=[[45,0,0,0],[173,0,0,0]],e.KeyC=[[46,0,0,0],[174,0,0,0]],e.KeyV=[[47,0,0,0],[175,0,0,0]],e.KeyB=[[48,0,0,0],[176,0,0,0]],e.KeyN=[[49,0,0,0],[177,0,0,0]],e.KeyM=[[50,0,0,0],[178,0,0,0]],e.Comma=[[51,0,0,0],[179,0,0,0]],e.Period=[[52,0,0,0],[180,0,0,0]],e.Slash=[[53,0,0,0],[181,0,0,0]],e.Numpad0=[[11,0,0,0],[139,0,0,0]],e.Numpad1=[[2,0,0,0],[130,0,0,0]],e.Numpad2=[[3,0,0,0],[131,0,0,0]],e.Numpad3=[[4,0,0,0],[132,0,0,0]],e.Numpad4=[[5,0,0,0],[133,0,0,0]],e.Numpad5=[[6,0,0,0],[134,0,0,0]],e.Numpad6=[[7,0,0,0],[135,0,0,0]],e.Numpad7=[[8,0,0,0],[136,0,0,0]],e.Numpad8=[[9,0,0,0],[137,0,0,0]],e.Numpad9=[[10,0,0,0],[138,0,0,0]],e.NumpadDivide=[[53,0,0,0],[181,0,0,0]],e.NumpadMultiply=[[55,0,0,0],[183,0,0,0]],e.NumpadSubtract=[[74,0,0,0],[202,0,0,0]],e.NumpadAdd=[[78,0,0,0],[206,0,0,0]],e.NumpadDecimal=[[52,0,0,0],[180,0,0,0]];var t=[];t[27]=1,t[9]=15,t[20]=58,t[16]=42,t[91]=29,t[17]=29,t[32]=57,t[8]=14,t[13]=28,t[18]=56,t[92]=92,t[93]=93,t[38]=72,t[37]=75,t[40]=80,t[39]=77,t[45]=82,t[46]=83,t[36]=71,t[35]=79,t[33]=73,t[34]=81,t[144]=69,t[145]=70,t[112]=59,t[113]=60,t[114]=61,t[115]=62,t[116]=63,t[117]=64,t[118]=65,t[119]=66,t[120]=67,t[121]=68,t[122]=87,t[123]=88;var a=[];a[65]=30,a[81]=16,a[87]=17,a[69]=18,a[82]=19,a[84]=20,a[89]=21,a[85]=22,a[73]=23,a[79]=24,a[80]=25,a[65]=30,a[83]=31,a[68]=32,a[70]=33,a[71]=34,a[72]=35,a[74]=36,a[75]=37,a[76]=38,a[90]=44,a[88]=45,a[67]=46,a[86]=47,a[66]=48,a[78]=49,a[77]=50;var i=[];i[9]=15;var u=[];return u[81]=16,u[87]=17,u[69]=18,u[82]=19,u[84]=20,u[89]=21,u[85]=22,u[73]=23,u[79]=24,u[80]=25,u[65]=30,u[83]=31,u[68]=32,u[70]=33,u[71]=34,u[72]=35,u[74]=36,u[75]=37,u[76]=38,u[88]=45,u[90]=44,u[86]=47,u[67]=46,u[66]=48,u[78]=49,u[77]=50,{getKeymap:function(){return t},getCtrlKeymap:function(){return a},getCtrlForbiddenKeymap:function(){return i},getReservedCtrlKeymap:function(){return u},getCharmap:function(){return e},setCtrlKey:function(e,t){a[e]=t}}}();wdi.keyShortcutsHandled={CTRLV:0,CTRLC:1},wdi.Keymap={keymap:{},ctrlKeymap:{},ctrlForbiddenKeymap:{},charmap:{},ctrlPressed:!1,capsLock:!1,numLock:!1,isVirtualKeyboard:!1,isVirtualCapsLockOn:!1,twoBytesScanCodes:[91,219,92,220,29,157,93,221,82,210,83,211,75,203,71,201,79,207,72,200,80,208,73,201,81,209,77,205,28,156],loadKeyMap:function(e,t){try{this.keymap=wdi["Keymap"+e.toUpperCase()].getKeymap(),this.ctrlKeymap=wdi["Keymap"+e.toUpperCase()].getCtrlKeymap(),this.ctrlForbiddenKeymap=wdi["Keymap"+e.toUpperCase()].getCtrlForbiddenKeymap(),this.reservedCtrlKeymap=wdi["Keymap"+e.toUpperCase()].getReservedCtrlKeymap(),this.charmap=wdi["KeymapObj"+e.toUpperCase()].getCharmap(),this.stuckKeysHandler=t}catch(e){this.keymap=wdi.KeymapES.getKeymap(),this.ctrlKeymap=wdi.KeymapES.getCtrlKeymap(),this.ctrlForbiddenKeymap=wdi.KeymapES.getCtrlForbiddenKeymap(),this.reservedCtrlKeymap=wdi.KeymapES.getReservedCtrlKeymap(),this.charmap=wdi.KeymapObjES.getCharmap(),this.stuckKeysHandler=t}},isInKeymap:function(e){return void 0!==this.keymap[e]},getScanCodes:function(e){return e.hasScanCode?e.scanCode:this.isForbiddenCombination(e)?[]:this.isGeneratedShortcut(e.type,e.keyCode,e.generated)?this.getScanCodeFromKeyCode(e.keyCode,e.type,this.ctrlKeymap,this.reservedCtrlKeymap):this.handledByCharmap(e.type)&&e.originalEvent?this.getScanCodesFromCharCode(e.originalEvent.code):this.handledByNormalKeyCode(e.type,e.keyCode)?this.getScanCodeFromKeyCode(e.keyCode,e.type,this.keymap):[]},getScanCodeFromKeyCode:function(e,t,r,i){this.controlPressed(e,t);var a=null;if(void 0===(a=e in r?r[e]:i[e]))return[];if(a<256){if("keydown"==t)return[this.makeKeymap(a)];if("keyup"==t)return[this.makeKeymap(128|a)]}else{if("keydown"==t)return[this.makeKeymap(224|a-256<<8)];if("keyup"==t)return[this.makeKeymap(32992|a-256<<8)]}return a},isForbiddenCombination:function(e){var t=e.keyCode,r=(e.type,this.ctrlForbiddenKeymap);return!!(wdi.KeyEvent.isCtrlPressed(e)&&r[t]&&r[t])},controlPressed:function(e,t,r){if(17===e&&(this.ctrlPressed="keydown"===t),!r)return!1;17!==e&&91!==e&&("keydown"===t?wdi.KeyEvent.isCtrlPressed(r)&&(this.ctrlPressed=!0):"keyup"===t&&(wdi.KeyEvent.isCtrlPressed(r)||(this.ctrlPressed=!1)))},handledByCtrlKeyCode:function(e,t,r){if(("keydown"===e||"keyup"===e||"keypress"===e)&&this.ctrlPressed){if("keypress"===e)return!0;if(this.ctrlKeymap[t])return!0;if(r&&this.reservedCtrlKeymap[t])return!0}return!1},isGeneratedShortcut:function(e,t,r){if(("keydown"===e||"keyup"===e||"keypress"===e)&&this.ctrlPressed){if("keypress"===e)return!0;if(this.ctrlKeymap[t])return!0;if(r&&this.reservedCtrlKeymap[t])return!0}return!1},handledByNormalKeyCode:function(e,t){return!("keydown"!==e&&"keyup"!==e||!this.keymap[t])},handledByCharmap:function(e){return"inputmanager"===e},getScanCodesFromCharCode:function(e){var t=this.charmap[e];return new wdi.ScanCodeObjModifier(t).getScanCode()},makeKeymap:function(e){return-1!=$.inArray(e,this.twoBytesScanCodes)?[224,e,0,0]:[e,0,0]}};const getURLParameter=e=>{const t=new RegExp(`${e}=([^&]+)`).exec(window.location.pathname);return t&&t[1]};let vmHost=window.location.hostname;"localhost"===vmHost&&(vmHost="10.10.101.107");const vmId=getURLParameter("id"),vmPort=window.config.public.PORT;function start(){wdi.graphicDebug=new wdi.GraphicDebug({debugMode:!1});let e,t,o=!1;$(window).resize((function(){app.sendCommand("setResolution",app.toSpiceResolution({width:$(window).width(),height:$(window).height()}))}));const n={callback:function(n,s){if("windowClosed"===n)$(s.canvas).remove(),$(s.eventLayer).remove();else if("windowMoved"===n)$(s.canvas).css({top:s.info.top+"px",left:s.info.left+"px"}),$(s.eventLayer).css({top:s.info.top+"px",left:s.info.left+"px"});else if("init"===n||"windowCreated"===n){let e=null,t=null,o=null;const n=$("body");for(let i in s){e=s[i];const a=2*e.position;t=$(e.canvas).css({zIndex:1e4-a-1,position:"absolute",top:e.info.top+"px",left:e.info.left+"px"}),o=$(e.eventLayer).css({top:e.info.top+"px",left:e.info.left+"px",zIndex:1e4-a}),n.append(t),n.append(o)}}else if("ready"===n){app.setReconnecting(!1),t?.clearTimeout&&(t(),t=!1);const e=$(window).width(),o=$(window).height();app.sendCommand("setResolution",app.toSpiceResolution({width:e,height:o})),wdi.IntegrationBenchmarkEnabled&&($("#integrationBenchmark").css({display:"inline"}),$("#launchWordButton").prop("disabled",!1))}else if("resolution"===n){const{0:e}=s,t=(window.innerWidth-e)/2;t>=0&&(document.getElementById("canvas_0").style.left=t+"px",document.getElementById("eventLayer").style.left=t+"px")}else"windowMinimized"===n?($(s.canvas).css({display:"none"}),$(s.eventLayer).css({display:"none"})):"windowMaximized"===n?($(s.canvas).css({top:s.info.top+"px",left:s.info.left+"px"}),$(s.eventLayer).css({top:s.info.top+"px",left:s.info.left+"px"})):"windowRestored"===n?($(s.canvas).css({display:"block"}),$(s.eventLayer).css({display:"block"}),$(s.canvas).css({top:s.info.top+"px",left:s.info.left+"px"}),$(s.eventLayer).css({top:s.info.top+"px",left:s.info.left+"px"})):"windowFocused"===n||("timeLapseDetected"===n?wdi.Debug.log("Detected time lapse of ",s,"seconds"):"error"===n&&(app.getReconnecting()||(e||(e=setTimeout((function(){console.log("cancelFreeze"),app.cancelFreeze()}),1e4)),t||(t=setTimeout((function(){console.log("cancel reconnection"),o=!0}),6e4))),setTimeout((function(){o||(console.log("Trying reconnect ",Date.now()),app.reconnect({freeze:!0}))}),1e3)))},context:this,host:vmHost,port:vmPort,protocol:"wss",token:"password",vmHost:vmHost,vmPort:vmPort,vmid:vmId,useBus:!1,busHost:"localhost",busPort:61613,busSubscriptions:["/topic/00000000-0000-0000-0000-000000000000"],busUser:"00000000-0000-0000-0000-000000000000",busPass:"potato",layout:"es",useWorkers:!0,seamlessDesktopIntegration:!1,connectionControl:!1,heartbeatToken:"heartbeat",heartbeatTimeout:4e3,externalClipboardHandling:!1,disableClipboard:!1,layer:document.getElementById("vmw"),disableMessageBuffering:!0,clientOffset:{x:0,y:0}};app.run(n)}window.app=new Application({supportHighDPI:!1}),$(document).ready(start);