12 lines
40 KiB
JavaScript
12 lines
40 KiB
JavaScript
/**
|
|
* copy-cat: Copyright SquidDev 2023
|
|
*
|
|
* - @squid-dev/cc-web-term: Copyright SquidDev (BSD-3-Clause)
|
|
* - preact: Copyright (MIT)
|
|
* - setimmediate: Copyright YuzuJS (MIT)
|
|
* - style-inject: Copyright EGOIST (MIT)
|
|
* - tslib: Copyright Microsoft Corp. (0BSD)
|
|
*
|
|
* @license
|
|
*/define(["require","exports"],function(e,t){"use strict";var r,n,i,s,o,l,a,h={},u=[],c=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,d=Array.isArray;function f(e,t){for(var r in t)e[r]=t[r];return e}function p(e){var t=e.parentNode;t&&t.removeChild(e)}function _(e,t,n){var i,s,o,l={};for(o in t)"key"==o?i=t[o]:"ref"==o?s=t[o]:l[o]=t[o];if(arguments.length>2&&(l.children=arguments.length>3?r.call(arguments,2):n),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===l[o]&&(l[o]=e.defaultProps[o]);return m(e,l,i,s,null)}function m(e,t,r,s,o){var l={type:e,props:t,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++i:o};return null==o&&null!=n.vnode&&n.vnode(l),l}function g(){return{current:null}}function v(e){return e.children}function y(e,t){this.props=e,this.context=t}function b(e,t){if(null==t)return e.__?b(e.__,e.__.__k.indexOf(e)+1):null;for(var r;t<e.__k.length;t++)if(null!=(r=e.__k[t])&&null!=r.__e)return r.__d||r.__e;return"function"==typeof e.type?b(e):null}function w(e){(!e.__d&&(e.__d=!0)&&s.push(e)&&!k.__r++||o!==n.debounceRendering)&&((o=n.debounceRendering)||l)(k)}function k(){var e,t,r,n,i,o,l,h,u;for(s.sort(a);e=s.shift();)e.__d&&(t=s.length,n=void 0,i=void 0,o=void 0,h=(l=(r=e).__v).__e,(u=r.__P)&&(n=[],i=[],(o=f({},l)).__v=l.__v+1,$(u,l,o,r.__n,void 0!==u.ownerSVGElement,null!=l.__h?[h]:null,n,null==h?b(l):h,l.__h,i),P(n,l,i),l.__e!=h&&function e(t){var r,n;if(null!=(t=t.__)&&null!=t.__c){for(t.__e=t.__c.base=null,r=0;r<t.__k.length;r++)if(null!=(n=t.__k[r])&&null!=n.__e){t.__e=t.__c.base=n.__e;break}return e(t)}}(l)),s.length>t&&s.sort(a));k.__r=0}function E(e,t,r,n,i,s,o,l,a,c,f){var p,_,g,y,w,k,E,x,D,F=0,z=n&&n.__k||u,P=z.length,A=P,K=t.length;for(r.__k=[],p=0;p<K;p++)null!=(y=r.__k[p]=null==(y=t[p])||"boolean"==typeof y||"function"==typeof y?null:"string"==typeof y||"number"==typeof y||"bigint"==typeof y?m(null,y,null,null,y):d(y)?m(v,{children:y},null,null,null):y.__b>0?m(y.type,y.props,y.key,y.ref?y.ref:null,y.__v):y)?(y.__=r,y.__b=r.__b+1,-1===(x=function(e,t,r,n){var i=e.key,s=e.type,o=r-1,l=r+1,a=t[r];if(null===a||a&&i==a.key&&s===a.type)return r;if(n>(null!=a?1:0))for(;o>=0||l<t.length;){if(o>=0){if((a=t[o])&&i==a.key&&s===a.type)return o;o--}if(l<t.length){if((a=t[l])&&i==a.key&&s===a.type)return l;l++}}return -1}(y,z,E=p+F,A))?g=h:(g=z[x]||h,z[x]=void 0,A--),$(e,y,g,i,s,o,l,a,c,f),w=y.__e,(_=y.ref)&&g.ref!=_&&(g.ref&&S(g.ref,null,y),f.push(_,y.__c||w,y)),null!=w&&(null==k&&(k=w),(D=g===h||null===g.__v)?-1==x&&F--:x!==E&&(x===E+1?F++:x>E?A>K-E?F+=x-E:F--:F=x<E&&x==E-1?x-E:0),E=p+F,"function"!=typeof y.type||x===E&&g.__k!==y.__k?"function"!=typeof y.type&&(x!==E||D)?a=C(e,w,a):void 0!==y.__d?(a=y.__d,y.__d=void 0):a=w.nextSibling:a=function e(t,r,n){for(var i,s=t.__k,o=0;s&&o<s.length;o++)(i=s[o])&&(i.__=t,r="function"==typeof i.type?e(i,r,n):C(n,i.__e,r));return r}(y,a,e),"function"==typeof r.type&&(r.__d=a))):(g=z[p])&&null==g.key&&g.__e&&(g.__e==a&&(g.__=n,a=b(g)),q(g,g,!1),z[p]=null);for(r.__e=k,p=P;p--;)null!=z[p]&&("function"==typeof r.type&&null!=z[p].__e&&z[p].__e==r.__d&&(r.__d=z[p].__e.nextSibling),q(z[p],z[p]))}function C(e,t,r){return null==r||r.parentNode!==e?e.insertBefore(t,null):t==r&&null!=t.parentNode||e.insertBefore(t,r),t.nextSibling}function x(e,t,r){"-"===t[0]?e.setProperty(t,null==r?"":r):e[t]=null==r?"":"number"!=typeof r||c.test(t)?r:r+"px"}function D(e,t,r,n,i){var s;e:if("style"===t){if("string"==typeof r)e.style.cssText=r;else{if("string"==typeof n&&(e.style.cssText=n=""),n)for(t in n)r&&t in r||x(e.style,t,"");if(r)for(t in r)n&&r[t]===n[t]||x(e.style,t,r[t])}}else if("o"===t[0]&&"n"===t[1])s=t!==(t=t.replace(/(PointerCapture)$|Capture$/,"$1")),t=t.toLowerCase() in e?t.toLowerCase().slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=r,r?n?r.u=n.u:(r.u=Date.now(),e.addEventListener(t,s?z:F,s)):e.removeEventListener(t,s?z:F,s);else if("dangerouslySetInnerHTML"!==t){if(i)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!==t&&"height"!==t&&"href"!==t&&"list"!==t&&"form"!==t&&"tabIndex"!==t&&"download"!==t&&"rowSpan"!==t&&"colSpan"!==t&&"role"!==t&&t in e)try{e[t]=null==r?"":r;break e}catch(e){}"function"==typeof r||(null==r||!1===r&&"-"!==t[4]?e.removeAttribute(t):e.setAttribute(t,r))}}function F(e){var t=this.l[e.type+!1];if(e.t){if(e.t<=t.u)return}else e.t=Date.now();return t(n.event?n.event(e):e)}function z(e){return this.l[e.type+!0](n.event?n.event(e):e)}function $(e,t,i,s,o,l,a,u,c,_){var m,g,w,k,C,x,F,z,$,P,S,q,K,L,M,W=t.type;if(void 0!==t.constructor)return null;null!=i.__h&&(c=i.__h,u=t.__e=i.__e,t.__h=null,l=[u]),(m=n.__b)&&m(t);e:if("function"==typeof W)try{if(z=t.props,$=(m=W.contextType)&&s[m.__c],P=m?$?$.props.value:m.__:s,i.__c?F=(g=t.__c=i.__c).__=g.__E:("prototype"in W&&W.prototype.render?t.__c=g=new W(z,P):(t.__c=g=new y(z,P),g.constructor=W,g.render=A),$&&$.sub(g),g.props=z,g.state||(g.state={}),g.context=P,g.__n=s,w=g.__d=!0,g.__h=[],g._sb=[]),null==g.__s&&(g.__s=g.state),null!=W.getDerivedStateFromProps&&(g.__s==g.state&&(g.__s=f({},g.__s)),f(g.__s,W.getDerivedStateFromProps(z,g.__s))),k=g.props,C=g.state,g.__v=t,w)null==W.getDerivedStateFromProps&&null!=g.componentWillMount&&g.componentWillMount(),null!=g.componentDidMount&&g.__h.push(g.componentDidMount);else{if(null==W.getDerivedStateFromProps&&z!==k&&null!=g.componentWillReceiveProps&&g.componentWillReceiveProps(z,P),!g.__e&&(null!=g.shouldComponentUpdate&&!1===g.shouldComponentUpdate(z,g.__s,P)||t.__v===i.__v)){for(t.__v!==i.__v&&(g.props=z,g.state=g.__s,g.__d=!1),t.__e=i.__e,t.__k=i.__k,t.__k.forEach(function(e){e&&(e.__=t)}),S=0;S<g._sb.length;S++)g.__h.push(g._sb[S]);g._sb=[],g.__h.length&&a.push(g);break e}null!=g.componentWillUpdate&&g.componentWillUpdate(z,g.__s,P),null!=g.componentDidUpdate&&g.__h.push(function(){g.componentDidUpdate(k,C,x)})}if(g.context=P,g.props=z,g.__P=e,g.__e=!1,q=n.__r,K=0,"prototype"in W&&W.prototype.render){for(g.state=g.__s,g.__d=!1,q&&q(t),m=g.render(g.props,g.state,g.context),L=0;L<g._sb.length;L++)g.__h.push(g._sb[L]);g._sb=[]}else do g.__d=!1,q&&q(t),m=g.render(g.props,g.state,g.context),g.state=g.__s;while(g.__d&&++K<25);g.state=g.__s,null!=g.getChildContext&&(s=f(f({},s),g.getChildContext())),w||null==g.getSnapshotBeforeUpdate||(x=g.getSnapshotBeforeUpdate(k,C)),E(e,d(M=null!=m&&m.type===v&&null==m.key?m.props.children:m)?M:[M],t,i,s,o,l,a,u,c,_),g.base=t.__e,t.__h=null,g.__h.length&&a.push(g),F&&(g.__E=g.__=null)}catch(e){t.__v=null,(c||null!=l)&&(t.__e=u,t.__h=!!c,l[l.indexOf(u)]=null),n.__e(e,t,i)}else null==l&&t.__v===i.__v?(t.__k=i.__k,t.__e=i.__e):t.__e=function(e,t,n,i,s,o,l,a,u){var c,f,_,m=n.props,g=t.props,v=t.type,y=0;if("svg"===v&&(s=!0),null!=o){for(;y<o.length;y++)if((c=o[y])&&"setAttribute"in c==!!v&&(v?c.localName===v:3===c.nodeType)){e=c,o[y]=null;break}}if(null==e){if(null===v)return document.createTextNode(g);e=s?document.createElementNS("http://www.w3.org/2000/svg",v):document.createElement(v,g.is&&g),o=null,a=!1}if(null===v)m===g||a&&e.data===g||(e.data=g);else{if(o=o&&r.call(e.childNodes),f=(m=n.props||h).dangerouslySetInnerHTML,_=g.dangerouslySetInnerHTML,!a){if(null!=o)for(m={},y=0;y<e.attributes.length;y++)m[e.attributes[y].name]=e.attributes[y].value;(_||f)&&(_&&(f&&_.__html==f.__html||_.__html===e.innerHTML)||(e.innerHTML=_&&_.__html||""))}if(function(e,t,r,n,i){var s;for(s in r)"children"===s||"key"===s||s in t||D(e,s,null,r[s],n);for(s in t)i&&"function"!=typeof t[s]||"children"===s||"key"===s||"value"===s||"checked"===s||r[s]===t[s]||D(e,s,t[s],r[s],n)}(e,g,m,s,a),_)t.__k=[];else if(E(e,d(y=t.props.children)?y:[y],t,n,i,s&&"foreignObject"!==v,o,l,o?o[0]:n.__k&&b(n,0),a,u),null!=o)for(y=o.length;y--;)null!=o[y]&&p(o[y]);a||("value"in g&&void 0!==(y=g.value)&&(y!==e.value||"progress"===v&&!y||"option"===v&&y!==m.value)&&D(e,"value",y,m.value,!1),"checked"in g&&void 0!==(y=g.checked)&&y!==e.checked&&D(e,"checked",y,m.checked,!1))}return e}(i.__e,t,i,s,o,l,a,c,_);(m=n.diffed)&&m(t)}function P(e,t,r){for(var i=0;i<r.length;i++)S(r[i],r[++i],r[++i]);n.__c&&n.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){n.__e(e,t.__v)}})}function S(e,t,r){try{"function"==typeof e?e(t):e.current=t}catch(e){n.__e(e,r)}}function q(e,t,r){var i,s;if(n.unmount&&n.unmount(e),(i=e.ref)&&(i.current&&i.current!==e.__e||S(i,null,t)),null!=(i=e.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){n.__e(e,t)}i.base=i.__P=null,e.__c=void 0}if(i=e.__k)for(s=0;s<i.length;s++)i[s]&&q(i[s],t,r||"function"!=typeof e.type);r||null==e.__e||p(e.__e),e.__=e.__e=e.__d=void 0}function A(e,t,r){return this.constructor(e,r)}function K(e,t,r,n){return new(r||(r=Promise))(function(i,s){function o(e){try{a(n.next(e))}catch(e){s(e)}}function l(e){try{a(n.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,l)}a((n=n.apply(e,t||[])).next())})}r=u.slice,n={__e:function(e,t,r,n){for(var i,s,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&null!=s.getDerivedStateFromError&&(i.setState(s.getDerivedStateFromError(e)),o=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(e,n||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},i=0,y.prototype.setState=function(e,t){var r;r=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=f({},this.state),"function"==typeof e&&(e=e(f({},r),this.props)),e&&f(r,e),null!=e&&this.__v&&(t&&this._sb.push(t),w(this))},y.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),w(this))},y.prototype.render=v,s=[],l="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,a=function(e,t){return e.__v.__b-t.__v.__b},k.__r=0,"function"==typeof SuppressedError&&SuppressedError;class L{constructor(){this.listeners=new Set}attach(e){this.listeners.add(e)}detach(e){this.listeners.delete(e)}signal(){for(let e of this.listeners)e()}}let M="file:"===window.location.protocol||"localhost"===window.location.hostname,W=M?e=>t=>console.log(`[${e}] ${t}`):()=>()=>0,N=W("GIF encoding"),T={workers:2,repeat:0,background:"#fff",quality:10,transparent:null,dither:!1},B={delay:500};class I{constructor(e){this.running=!1,this.frames=[],this.freeWorkers=[],this.activeWorkers=[],this.nextFrame=0,this.finishedFrames=0,this.globalPalette=!0,this.options=Object.assign(Object.assign({},T),e)}addFrame(e,t){let r;if(e instanceof ImageData)r=e.data;else if(e instanceof CanvasRenderingContext2D)r=this.getContextData(e);else throw Error("Invalid image");this.frames.push(Object.assign(Object.assign(Object.assign({},B),t),{transparent:this.options.transparent,data:r}))}render(){if(this.running)throw Error("Already rendering");this.running=!0,this.nextFrame=0,this.finishedFrames=0,this.imageParts=this.frames.map(()=>null);let e=this.spawnWorkers();if(!0===this.globalPalette)this.renderNextFrame();else for(let t=0;t<e;t++)this.renderNextFrame();this.onProgress&&this.onProgress(0)}abort(){for(;;){let e=this.activeWorkers.shift();if(null==e)break;N("Killing active worker"),e.terminate()}this.running=!1,this.onAbort&&this.onAbort()}spawnWorkers(){let e=Math.min(this.options.workers,this.frames.length);for(let t=this.freeWorkers.length;t<e;t++){N(`Spawning worker ${t}`);let e=new Worker("gif.worker-8b0d4d4953c887a3.js");e.onmessage=t=>(this.activeWorkers.splice(this.activeWorkers.indexOf(e),1),this.freeWorkers.push(e),this.frameFinished(t.data)),this.freeWorkers.push(e)}return e}frameFinished(e){if(!this.imageParts)throw Error("No image data!");if(N(`Frame ${e.index} finished - ${this.activeWorkers.length} active`),this.finishedFrames++,this.onProgress&&this.onProgress(this.finishedFrames/this.frames.length),this.imageParts[e.index]=e,!0===this.globalPalette&&(this.globalPalette=e.globalPalette,N("Global palette analyzed"),this.frames.length>2))for(let e=1;e<this.freeWorkers.length;e++)this.renderNextFrame();return this.imageParts.indexOf(null)>=0?this.renderNextFrame():this.finishRendering()}finishRendering(){if(!this.imageParts)throw Error("No image data!");let e=this.imageParts,t=0;for(let r of e)t+=(r.data.length-1)*r.pageSize+r.cursor;let r=e[this.frames.length-1];t+=r.pageSize-r.cursor,N(`Rendering finished - filesize ${Math.round(t/1e3)}kb`);let n=new Uint8Array(t),i=0;for(let t of e)for(let e=0;e<t.data.length;e++)n.set(t.data[e],i),i+=e===t.data.length-1?t.cursor:t.pageSize;this.onFinished&&this.onFinished(new Blob([n],{type:"image/gif"}))}renderNextFrame(){if(0===this.freeWorkers.length)throw Error("No free workers");if(this.nextFrame>=this.frames.length)return;let e=this.freeWorkers.shift(),t=this.getTask(this.nextFrame++);return N(`Starting frame ${t.index+1} of ${this.frames.length}`),this.activeWorkers.push(e),e.postMessage(t)}getContextData(e){return e.getImageData(0,0,this.options.width,this.options.height).data}getTask(e){let t=this.frames[e];return{index:e,data:t.data,last:e===this.frames.length-1,delay:t.delay,dispose:-1,transparent:t.transparent,width:this.options.width,height:this.options.height,quality:this.options.quality,dither:this.options.dither,globalPalette:this.globalPalette,repeat:this.options.repeat,canTransfer:!0}}}let O=(e,t)=>{let r=e.toString();return r.length>=t?r:"0".repeat(t-r.length)+r},U=(e,t,r)=>{if(!r)return;let n=document.createElement("a"),i=URL.createObjectURL(r),s=new Date;n.download=`${e}-${s.getFullYear()}-${O(s.getMonth()+1,2)}-${O(s.getDate(),2)}_${O(s.getHours(),2)}-${O(s.getMinutes(),2)}.${t}`,n.rel="noopener",n.href=i,setTimeout(()=>URL.revokeObjectURL(i),6e4),setTimeout(()=>{try{n.dispatchEvent(new MouseEvent("click"))}catch(t){let e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),n.dispatchEvent(e)}},0)};function R(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===r&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}let Y="L9KZzW_iconFont",Z="L9KZzW_terminalButton",X="L9KZzW_actionButton";R(".L9KZzW_actionButton{color:inherit;font-family:inherit;font-size:1em;line-height:inherit;cursor:pointer;background:0 0;border:none;margin:0;padding:0}.L9KZzW_actionButton.L9KZzW_disabled{cursor:initial;color:#888}.L9KZzW_iconFont{height:1em;overflow:visible}.L9KZzW_terminalView{justify-content:center;align-items:center;height:100%;display:flex;overflow-x:hidden}.L9KZzW_terminalCanvas{image-rendering:optimizespeed;image-rendering:-moz-crisp-edges;image-rendering:-webkit-optimize-contrast;image-rendering:-o-crisp-edges;image-rendering:optimize-contrast;-ms-interpolation-mode:nearest-neighbor;display:block}.L9KZzW_terminalBar{color:#000;fill:#000;background:#eee;font-size:.8em}.L9KZzW_terminalInfo,.L9KZzW_terminalButton{padding:3px;display:inline-block}.L9KZzW_terminalButtonsRight{float:right}.L9KZzW_terminalButton:hover{background:#ddd}.L9KZzW_terminalButton.L9KZzW_disabled:hover{background:0 0}.L9KZzW_terminalInput{z-index:-1000;opacity:0;position:absolute}.L9KZzW_terminalProgress{background:#333;height:2px}");let j=(e,t)=>{let r=_("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:null!=t?t:"0 0 1000 1000",class:Y},e);return()=>r},G="M857 650q0 87 -34 166t-91 137 -137 92 -166 34 -167 -34 -136 -92 -92 -137 -34 -166q0 -102 45 -191t126 -151q24 -18 54 -14t46 28q18 23 14 53t-28 47q-54 41 -84 101t-30 127q0 58 23 111t61 91 91 61 111 23 110 -23 92 -61 61 -91 22 -111q0 -68 -30 -127t-84 -101q-23 -18 -28 -47t14 -53q17 -24 47 -28t53 14q81 61 126 151t45 191zm-357 -429v358q0 29 -21 50t-50 21 -51 -21 -21 -50v-358q0 -29 21 -50t51 -21 50 21 21 50z",H="M1000 346v608q0 23 -22 32 -7 3 -14 3 -15 0 -25 -10l-225 -225v92q0 67 -47 114t-113 47h-393q-67 0 -114 -47t-47 -114v-392q0 -67 47 -114t114 -47h393q66 0 113 47t47 114v92l225 -225q10 -10 25 -10 7 0 14 2 22 10 22 33z",V=j(_("path",{d:"M679 686v-72q0 -14 -11 -25t-25 -10h-429q-14 0 -25 10t-10 25v72q0 14 10 25t25 10h429q14 0 25 -10t11 -25zm178 -36q0 117 -57 215t-156 156 -215 58 -216 -58 -155 -156 -58 -215 58 -215 155 -156 216 -58 215 58 156 156 57 215z"}),"0 200 870 870"),Q=j(_("path",{d:G})),J=j(_("path",{d:G,fill:"green"})),ee=j(_("path",{d:"M536 525q66 0 113 47t47 114 -47 113 -113 47 -114 -47 -47 -113 47 -114 114 -47zm393 -232q59 0 101 42t41 101v500q0 59 -41 101t-101 42h-786q-59 0 -101 -42t-42 -101v-500q0 -59 42 -101t101 -42h125l28 -76q11 -27 39 -47t58 -20h286q29 0 57 20t39 47l29 76h125zm-393 643q103 0 176 -74t74 -176 -74 -177 -176 -73 -177 73 -73 177 73 176 177 74z"}),"0 0 1100 1100"),et=j(_("path",{d:H}),"0 100 1000 1000"),er=j(_("path",{d:H,fill:"red"}),"0 100 1000 1000"),en=j(_("path",{d:"M421 261q0-7-5-13l-185-185 80-81q10-10 10-25t-10-25-25-11h-250q-15 0-25 11t-11 25v250q0 15 11 25t25 11 25-11l80-80 186 185q5 6 12 6t13-6l64-63q5-6 5-13z m436 482v-250q0-15-10-25t-26-11-25 11l-80 80-185-185q-6-6-13-6t-13 6l-64 64q-5 5-5 12t5 13l186 185-81 81q-10 10-10 25t10 25 25 11h250q15 0 26-11t10-25z"}),"0 -100 900 900"),ei=e=>{switch(e){case 0:return 1;case 1:return 3;case 2:return 2;default:return}},es=e=>(1&e)!=0?1:(2&e)!=0?2:(4&e)!=0?3:void 0,eo={Digit1:0,1:0,Digit2:1,2:1,Digit3:2,3:2,Digit4:3,4:3,Digit5:4,5:4,Digit6:5,6:5,Digit7:6,7:6,Digit8:7,8:7,Digit9:8,9:8,Digit0:9,0:9,Minus:10,"-":10,Equal:11,Backspace:12,Tab:13,KeyQ:30,Q:30,KeyW:36,W:36,KeyE:18,E:18,KeyR:31,R:31,KeyT:33,T:33,KeyY:38,Y:38,KeyU:34,U:34,KeyI:22,I:22,KeyO:28,O:28,KeyP:29,P:29,BracketLeft:40,"(":40,BracketRight:41,")":41,Enter:42,ControlLeft:43,Control:43,KeyA:14,A:14,KeyS:32,S:32,KeyD:17,D:17,KeyF:19,F:19,KeyG:20,G:20,KeyH:21,H:21,KeyJ:23,J:23,KeyK:24,K:24,KeyL:25,L:25,Semicolon:44,";":44,Quote:45,"'":45,Backquote:46,"`":46,ShiftLeft:47,Shift:47,IntlBackslash:48,KeyZ:39,Z:39,KeyX:37,X:37,KeyC:16,C:16,KeyV:35,V:35,KeyB:15,B:15,KeyN:27,N:27,KeyM:26,M:26,Comma:49,",":49,Period:50,".":50,Slash:51,"/":51,ShiftRight:52,NumpadMultiply:53,AltLeft:54,Alt:54,Space:55," ":55,CapsLock:56,F1:57,F2:58,F3:59,F4:60,F5:61,F6:62,F7:63,F8:64,F9:65,F10:66,NumLock:72,ScollLock:73,Numpad7:81,Numpad8:82,Numpad9:83,NumpadSubtract:84,Numpad4:78,Numpad5:79,Numpad6:80,NumpadAdd:85,Numpad1:75,Numpad2:76,Numpad3:77,Numpad0:74,NumpadDecimal:86,F11:67,F12:68,F13:69,F14:70,F15:71,KanaMode:87,Convert:88,NonConvert:89,IntlYen:90,NumpadEqual:91,Cirmcumflex:92,At:93,Colon:94,Underscore:95,Kanji:96,Stop:97,Ax:98,NumpadEnter:99,ControlRight:100,NumpadComma:101,NumpadDivide:102,AltRight:103,Pause:104,Home:105,ArrowUp:106,PageUp:107,ArrowLeft:108,ArrowRight:109,End:110,ArrowDown:111,PageDown:112,Insert:113,Delete:114},el=e=>eo[e],ea=[49,50,51,52,53,54,55,56,57,48,45,61,259,258,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,93,257,341,-1,39,96,340,92,44,46,47,344,-1,342,32,280,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,282,281,320,321,322,323,324,325,326,327,328,329,333,334,330,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,335,345,-1,331,346,284,268,265,266,263,262,269,264,267,260,261],eh=e=>{let t=ea[e];return t<0?void 0:t},eu={0:"rgb(240,240,240)",1:"rgb(242,178,51)",2:"rgb(229,127,216)",3:"rgb(153,178,242)",4:"rgb(222,222,108)",5:"rgb(127,204,25)",6:"rgb(242,178,204)",7:"rgb(76,76,76)",8:"rgb(153,153,153)",9:"rgb(76,153,178)",a:"rgb(178,102,229)",b:"rgb(37,49,146)",c:"rgb(127,102,76)",d:"rgb(87,166,78)",e:"rgb(204,76,76)",f:"rgb(0,0,0)"},ec={},ed=({image:e,paletteCache:t},r)=>{let n=t[r];if(n)return n;let i=document.createElement("canvas"),s=i.getContext("2d");return i.width=e.width,i.height=e.height,s.globalCompositeOperation="destination-atop",s.fillStyle=r,s.globalAlpha=1,s.fillRect(0,0,e.width,e.height),s.drawImage(e,0,0),t[r]=i,i},ef=e=>{let t=ec[e];if(t)return t;let r=new Image;r.src=e;let n=ec[e]={path:e,image:r,scale:1,margin:1,paletteCache:{}};return n.promise=new Promise(e=>{r.onload=()=>{for(let e in eu)Object.prototype.hasOwnProperty.call(eu,e)&&ed(n,eu[e]);n.scale=n.margin=r.width/256,n.promise=void 0,e(n)}}),n},ep=(e,t,r,n,i,s,o,l)=>{let a=6*i,h=9*i,u=t*a+4,c=r*h+4;0===t&&(u-=4,a+=4),t===s-1&&(a+=4),0===r&&(c-=4,h+=4),r===o-1&&(h+=4),e.beginPath(),e.rect(u,c,a,h),e.fillStyle=l[n]||l.f,e.fill()},e_=(e,t,r,n,i,s,o,l)=>{if(l.promise)return;let a=6*o,h=9*o,u=i.charCodeAt(0),c=6*l.scale,d=9*l.scale,f=l.margin+u%16*(c+2*l.margin),p=l.margin+Math.floor(u/16)*(d+2*l.margin);e.drawImage(ed(l,s[n]||s["0"]),f,p,c,d,t*a+4,r*h+4,6*o,9*o)},em=(e,t,r,n,i)=>{let s=t.sizeX,o=t.sizeY;for(let r=0;r<o;r++)for(let o=0;o<s;o++)ep(e,o,r,t.back[r].charAt(o),n,t.sizeX,t.sizeY,t.palette),e_(e,o,r,t.fore[r].charAt(o),t.text[r].charAt(o),t.palette,n,i);r&&t.cursorBlink&&t.cursorX>=0&&t.cursorX<s&&t.cursorY>=0&&t.cursorY<o&&e_(e,t.cursorX,t.cursorY,t.currentFore,"_",t.palette,n,i)},eg=(e,t,r,n,i,s)=>{e.beginPath(),e.rect(0,0,6*t*i+8,9*r*i+8),e.fillStyle=eu.b,e.fill();let o=Math.floor((t-n.length)/2),l=Math.floor((r-1)/2);for(let t=0;t<n.length;t++)e_(e,o+t,l,"0",n.charAt(t),eu,i,s)};var ev=window&&window.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,s){function o(e){try{a(n.next(e))}catch(e){s(e)}}function l(e){try{a(n.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,l)}a((n=n.apply(e,t||[])).next())})};let ey=W("Terminal"),eb=(e,t,r)=>e<t?t:e>r?r:e,ew=(e,t)=>null===e&&null===t?"Unlabeled computer":null===e?`${t}`:null===t?`Computer #${e}`:`${t} (Computer #${e})`;!function(e,t){if(!e.setImmediate){var r,n,i,s,o,l=1,a={},h=!1,u=e.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(e);(c=c&&c.setTimeout?c:e,"[object process]"===({}).toString.call(e.process))?o=function(e){process.nextTick(function(){f(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,r=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=r,t}}()?(r="setImmediate$"+Math.random()+"$",n=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(r)&&f(+t.data.slice(r.length))},e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),o=function(t){e.postMessage(r+t,"*")}):e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){f(e.data)},o=function(e){i.port2.postMessage(e)}):u&&"onreadystatechange"in u.createElement("script")?(s=u.documentElement,o=function(e){var t=u.createElement("script");t.onreadystatechange=function(){f(e),t.onreadystatechange=null,s.removeChild(t),t=null},s.appendChild(t)}):o=function(e){setTimeout(f,0,e)},c.setImmediate=function(e){"function"!=typeof e&&(e=Function(""+e));for(var t=Array(arguments.length-1),r=0;r<t.length;r++)t[r]=arguments[r+1];var n={callback:e,args:t};return a[l]=n,o(l),l++},c.clearImmediate=d}function d(e){delete a[e]}function f(e){if(h)setTimeout(f,0,e);else{var t=a[e];if(t){h=!0;try{!function(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(void 0,r)}}(t)}finally{d(e),h=!1}}}}}("undefined"==typeof self?"undefined"==typeof global?window:global:self);let ek=!1,eE=null,eC=(t,r)=>K(void 0,void 0,void 0,function*(){if(ek){if(!eE)throw Error("Failed to load computer (see previous errors for a possible reason");return eE(t)}let[n,{version:i,resources:s}]=yield Promise.all([new Promise((t,r)=>e(["./classes-64be3dee"],t,r)),new Promise((t,r)=>e(["./resources-e74d4ac3"],t,r))]);if(ek){if(!eE)throw Error("Failed to load computer (see previous errors for a possible reason");return eE(t)}ek=!0;let o=new TextEncoder;if(window.$javaCallbacks={config:r,setup:e=>eE=e,modVersion:i,listResources:()=>Object.keys(s),getResource:e=>new Int8Array(o.encode(s[e]))},n.main(),!eE)throw Error("Callbacks.setup was never called");return eE(t)}),ex="0123456789abcdef",eD=e=>{let t=e.lastIndexOf("/");return t<0?["",e]:[e.substring(0,t),e.substring(t+1)]},eF=(e,t)=>""===e?t:`${e}/${t}`,ez=new Int8Array(0),e$=new TextDecoder("UTF-8",{fatal:!1}),eP=new TextEncoder;class eS{constructor(e,t,r,n,i){this.exists=!0,this.persistance=e,this.path=t,this.children=r,this.contents=n,this.attributes=null!=i?i:{modification:0,creation:0}}static create(e,t,r){let n=Date.now(),i=new eS(e,t,r?[]:null,r?null:ez,{creation:n,modification:n});return i.save(),i}isDirectory(){return null!=this.children}getChildren(){if(null===this.children)throw Error("Not a directory");return this.children}setChildren(e){if(null===this.children)throw Error("Not a directory");this.children=e,this.semaphore&&this.semaphore.signal(),this.save()}getContents(){if(null!==this.contents)return this.contents;if(null!==this.children)throw Error("Not a file");return this.contents=this.persistance.getContents(this.path)}getStringContents(){return e$.decode(this.getContents())}setContents(e){if(null!==this.children)throw Error("Not a file");if(!this.exists)return{error:"File has been deleted",value:null};if(this.attributes.modification=Date.now(),"string"==typeof e){let t=eP.encode(e);this.contents=new Int8Array(t)}else this.contents=e instanceof Int8Array?e:new Int8Array(e);return this.save(),this.semaphore&&this.semaphore.signal(),{value:!0}}delete(){this.exists=!1,null===this.children?this.persistance.removeContents(this.path):this.persistance.removeChildren(this.path),this.persistance.removeAttributes(this.path),this.semaphore&&this.semaphore.signal()}save(){null!==this.children&&this.persistance.setChildren(this.path,this.children),null!==this.contents&&this.persistance.setContents(this.path,this.contents),this.persistance.setAttributes(this.path,this.attributes)}getSemaphore(){var e;return null!==(e=this.semaphore)&&void 0!==e?e:this.semaphore=new L}doesExist(){return this.exists}getAttributes(){let e=this.isDirectory();return Object.assign({directory:e,size:e?0:this.getContents().length},this.attributes)}}let eq="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",eA=new Uint8Array(256);for(let e=0;e<eq.length;e++)eA[eq.charCodeAt(e)]=e;let eK=e=>{let t=new Uint8Array(e),r=t.length,n="";for(let e=0;e<r;e+=3)n+=eq[t[e]>>2]+eq[(3&t[e])<<4|t[e+1]>>4]+eq[(15&t[e+1])<<2|t[e+2]>>6]+eq[63&t[e+2]];return r%3==2?n=n.substring(0,n.length-1)+"=":r%3==1&&(n=n.substring(0,n.length-2)+"=="),n},eL=e=>{let t=.75*e.length,r=e.length;e.endsWith("=")&&(t--,"="===e[e.length-2]&&t--);let n=new ArrayBuffer(t),i=new Uint8Array(n),s=0;for(let t=0;t<r;t+=4){let r=eA[e.charCodeAt(t)],n=eA[e.charCodeAt(t+1)],o=eA[e.charCodeAt(t+2)],l=eA[e.charCodeAt(t+3)];i[s++]=r<<2|n>>4,i[s++]=(15&n)<<4|o>>2,i[s++]=(3&o)<<6|63&l}return n},eM=!0,eW=e=>{if(!eM)return null;try{return localStorage.getItem(e)}catch(e){return console.error("Error reading from storage, disabling all further access.",e),eM=!1,null}},eN=(e,t)=>{if(eM)try{localStorage.setItem(e,t)}catch(e){console.error("Error writing to localStorage, disabling all further access.",e),eM=!1}},eT=e=>{if(eM)try{localStorage.removeItem(e)}catch(e){console.error("Error writing to storage, disabling all further access.",e),eM=!1}},eB=new Int8Array(0);t.B=function(e,t,i){var s,o,l,a;n.__&&n.__(e,t),o=(s="function"==typeof i)?null:i&&i.__k||t.__k,l=[],a=[],$(t,e=(!s&&i||t).__k=_(v,null,[e]),o||h,h,void 0!==t.ownerSVGElement,!s&&i?[i]:o?null:t.firstChild?r.call(t.childNodes):null,l,!s&&i?i:o?o.__e:t.firstChild,s,a),P(l,e,a)},t.ComputerAccess=class{constructor(e,t,r,n){this.filesystem=new Map,this.callbacks=[],this.removed=!1,this.persistance=e,this.terminal=t,this.semaphore=r,this.stateChanged=n,this.label=e.getLabel();let i=[""];for(;;){let t=i.pop();if(void 0===t)break;let r=e.getChildren(t),n=e.getAttributes(t);if(null!==r)for(let s of(this.filesystem.set(t,new eS(e,t,r,null,n)),r))i.push(eF(t,s));else""===t?this.filesystem.set("",new eS(e,"",[],null,n)):this.filesystem.set(t,new eS(e,t,null,null,n))}}getLabel(){return this.label}setState(e,t){this.label!==e&&(this.label=e,this.persistance.setLabel(e)),this.stateChanged(e,t)}updateTerminal(e,t,r,n,i,s){this.terminal.resize(e,t),this.terminal.cursorX=r,this.terminal.cursorY=n,this.terminal.cursorBlink=i,this.terminal.currentFore=ex.charAt(s)}setTerminalLine(e,t,r,n){this.terminal.text[e]=t,this.terminal.fore[e]=r,this.terminal.back[e]=n}setPaletteColour(e,t,r,n){this.terminal.palette[ex.charAt(e)]=`rgb(${255*t&255},${255*r&255},${255*n&255})`}flushTerminal(){this.semaphore.signal()}getEntry(e){var t;return null!==(t=this.filesystem.get(e))&&void 0!==t?t:null}createDirectory(e){let t=this.filesystem.get(e);if(t)return t.isDirectory()?{value:t}:{error:`/${e}: File exists`,value:null};{let[t,r]=eD(e),n=this.createDirectory(t);if(null===n.value)return n;let i=eS.create(this.persistance,e,!0);return n.value.setChildren([...n.value.getChildren(),r]),this.filesystem.set(e,i),{value:i}}}createFile(e){let t=this.filesystem.get(e);if(t)return t.isDirectory()?{error:`/${e}: Cannot write to directory`,value:null}:{value:t};{let[t,r]=eD(e),n=this.filesystem.get(t);if(null==n||!n.isDirectory())return{error:`/${e}: Access denied`,value:null};let i=eS.create(this.persistance,e,!1);return n.setChildren([...n.getChildren(),r]),this.filesystem.set(e,i),{value:i}}}deleteEntry(e){let t=this.filesystem.get(e);if(!t)return t;let[r,n]=eD(e),i=this.filesystem.get(r);i.setChildren(i.getChildren().filter(e=>e!==n));let s=[e];for(;;){let e=s.pop();if(void 0===e)break;let t=this.filesystem.get(e);if(t&&(this.filesystem.delete(e),t.delete(),t.isDirectory()))for(let r of t.getChildren())s.push(eF(e,r))}}start(e,t){eC(this,e).then(e=>{this.computer=e,this.removed&&e.dispose();let{width:r,height:n,label:i}=null!=t?t:{};for(let t of("number"==typeof r&&"number"==typeof n&&e.resize(r,n),"string"==typeof this.label?e.setLabel(this.label):"string"==typeof i&&e.setLabel(i),this.callbacks))t(e)}).catch(e=>console.error("Cannot start computer",e))}queueEvent(e,t){var r;null===(r=this.computer)||void 0===r||r.event(e,t)}keyDown(e,t){let r=eh(e);void 0!==r&&this.queueEvent("key",[r,t])}keyUp(e){let t=eh(e);void 0!==t&&this.queueEvent("key_up",[t])}turnOn(){var e;null===(e=this.computer)||void 0===e||e.turnOn()}shutdown(){var e;null===(e=this.computer)||void 0===e||e.shutdown()}reboot(){var e;null===(e=this.computer)||void 0===e||e.reboot()}dispose(){var e;this.removed=!0,null===(e=this.computer)||void 0===e||e.dispose()}transferFiles(e){var t;null===(t=this.computer)||void 0===t||t.transferFiles(e)}setPeripheral(e,t){this.computer?this.computer.setPeripheral(e,t):this.callbacks.push(r=>r.setPeripheral(e,t))}},t.Semaphore=L,t.StoragePersistence=class{constructor(e){this.prefix=`computer[${e}]`}getLabel(){return eW(`${this.prefix}.label`)}setLabel(e){null===e?eT(`${this.prefix}.label`):eN(`${this.prefix}.label`,e)}getContents(e){let t=eW(`${this.prefix}.files[${e}].b64`);return t?new Int8Array(eL(t)):eB}setContents(e,t){eN(`${this.prefix}.files[${e}].b64`,eK(t))}removeContents(e){eT(`${this.prefix}.files[${e}].b64`)}getChildren(e){let t=eW(`${this.prefix}.files[${e}].children`);if(null===t)return null;try{return JSON.parse(t)}catch(t){return console.error(`Error loading path "${e}"`),null}}setChildren(e,t){eN(`${this.prefix}.files[${e}].children`,JSON.stringify(t))}removeChildren(e){eT(`${this.prefix}.files[${e}].children`)}getAttributes(e){let t=eW(`${this.prefix}.files[${e}].attributes`);if(null===t)return null;try{return JSON.parse(t)}catch(t){return console.error(`Error loading attributes for "${e}"`),null}}setAttributes(e,t){eN(`${this.prefix}.files[${e}].attributes`,JSON.stringify(t))}removeAttributes(e){eT(`${this.prefix}.files[${e}].attributes`)}},t.Terminal=class extends y{constructor(e,t){super(e,t),this.canvasElem=g(),this.inputElem=g(),this.wrapperElem=g(),this.changed=!1,this.lastBlink=!1,this.mounted=!1,this.drawQueued=!1,this.lastX=-1,this.lastY=-1,this.gif=null,this.lastGifFrame=null,this.onResized=()=>{this.changed=!0,this.queueDraw()},this.onPaste=e=>{this.onEventDefault(e),this.paste(e.clipboardData)},this.onMouse=e=>{if(this.onEventDefault(e),!this.canvasElem||"mousemove"===e.type&&0===e.buttons)return;let{x:t,y:r}=this.convertMousePos(e);switch(e.type){case"mousedown":{let n=ei(e.button);n&&(this.props.computer.queueEvent("mouse_click",[n,t,r]),this.lastX=t,this.lastY=r);break}case"mouseup":{let n=ei(e.button);n&&(this.props.computer.queueEvent("mouse_up",[n,t,r]),this.lastX=t,this.lastY=r);break}case"mousemove":{let n=es(e.buttons);n&&(t!==this.lastX||r!==this.lastY)&&(this.props.computer.queueEvent("mouse_drag",[n,t,r]),this.lastX=t,this.lastY=r)}}},this.onMouseWheel=e=>{if(this.onEventDefault(e),!this.canvasElem)return;let{x:t,y:r}=this.convertMousePos(e);0!==e.deltaY&&this.props.computer.queueEvent("mouse_scroll",[Math.sign(e.deltaY),t,r])},this.onEventDefault=e=>{var t;e.preventDefault(),null===(t=this.inputElem.current)||void 0===t||t.focus()},this.onKey=e=>{if(!this.canvasElem||e.ctrlKey&&"KeyV"===e.code)return;let t=el(e.code);void 0===t&&(t=el(e.key)),void 0===t&&(t=el(e.key.toUpperCase())),(void 0!==t||1===e.key.length)&&this.onEventDefault(e),"keydown"===e.type?(void 0!==t&&this.props.computer.keyDown(t,e.repeat),e.altKey||e.ctrlKey||1!==e.key.length||this.props.computer.queueEvent("char",[e.key])):"keyup"===e.type&&void 0!==t&&this.props.computer.keyUp(t)},this.onInput=e=>{let t=e.target;this.onEventDefault(e);let r=t.value;r&&(t.value="",this.props.computer.queueEvent(1===r.length?"char":"paste",[r]))},this.onTerminate=e=>{this.onEventDefault(e),this.props.computer.queueEvent("terminate",[])},this.onChanged=()=>{this.changed=!0,this.queueDraw()},this.onPowerOff=e=>{this.onEventDefault(e),this.props.computer.shutdown()},this.onPowerOn=e=>{this.onEventDefault(e),this.props.computer.turnOn()},this.onScreenshot=e=>{var t;this.onEventDefault(e),this.canvasElem&&(null===(t=this.canvasElem.current)||void 0===t||t.toBlob(e=>U("computer","png",e),"image/png",1))},this.onRecord=e=>{if(this.onEventDefault(e),this.canvasElem)switch(this.state.recording){case 2:break;case 0:this.gif=new I({width:this.canvasElem.current.width,height:this.canvasElem.current.height,quality:10}),this.lastGifFrame=Date.now(),this.setState({recording:1});break;case 1:if(!this.gif){this.setState({recording:0});return}this.setState({recording:2}),this.addGifFrame(!0),this.gif.onFinished=e=>{this.setState({recording:0}),U("computer","gif",e)},this.gif.onProgress=e=>this.setState({progress:e}),this.gif.onAbort=()=>{this.setState({recording:0}),console.error("Rendering GIF failed")},this.gif.render(),this.gif=null,this.lastGifFrame=null}},this.makeFullscreen=e=>{var t;this.onEventDefault(e),null===(t=this.base)||void 0===t||t.requestFullscreen().catch(e=>{console.error("Cannot make full-screen",e)})},this.onDrop=e=>{if(this.onEventDefault(e),!e.dataTransfer)return;let t=[];if(e.dataTransfer.items){let r=e.dataTransfer.items;for(let e=0;e<r.length;e++){let n=r[e];"file"===n.kind&&t.push(n.getAsFile())}}else{let r=e.dataTransfer.files;for(let e=0;e<r.length;e++)t.push(r[e])}0!=t.length&&Promise.all(t.map(e=>ev(this,void 0,void 0,function*(){return{name:e.name,contents:yield e.arrayBuffer()}}))).then(e=>this.props.computer.transferFiles(e)).catch(e=>console.error("Error handling drop",e))},this.setState({recording:0,progress:0}),this.vdom=[_("canvas",{class:"L9KZzW_terminalCanvas",ref:this.canvasElem,onMouseDown:this.onMouse,onMouseUp:this.onMouse,onMouseMove:this.onMouse,onWheel:this.onMouseWheel,onContextMenu:this.onEventDefault,onDragOver:this.onEventDefault,onDrop:this.onDrop}),_("input",{type:"text",class:"L9KZzW_terminalInput",ref:this.inputElem,onPaste:this.onPaste,onKeyDown:this.onKey,onKeyUp:this.onKey,onInput:this.onInput})]}componentDidMount(){this.canvasContext=this.canvasElem.current.getContext("2d"),window.addEventListener("resize",this.onResized),this.props.changed.attach(this.onChanged),this.changed=!0,this.lastBlink=!1,this.mounted=!0,this.props.focused&&this.inputElem.current.focus(),this.queueDraw()}componentWillUnmount(){this.canvasContext=void 0,this.props.changed.detach(this.onChanged),window.removeEventListener("resize",this.onResized),this.lastBlink=!1,this.mounted=!1,this.drawQueued=!1}render({id:e,label:t,on:r},{recording:n,progress:i}){let s=2===n;return _("div",{class:"L9KZzW_terminalView"},_("div",{ref:this.wrapperElem},...this.vdom,_("div",{class:"L9KZzW_terminalBar"},_("button",{class:`${X} ${Z}`,type:"button",title:r?"Turn this computer off":"Turn this computer on",onClick:r?this.onPowerOff:this.onPowerOn},r?_(J,null):_(Q,null)),_("span",{class:"L9KZzW_terminalInfo"},ew(e,t)),_("span",{class:"L9KZzW_terminalButtonsRight"},_("button",{class:`${X} ${Z}`,type:"button",title:"Take a screenshot of the terminal.",onClick:this.onScreenshot},_(ee,null)),_("button",{class:`${X} ${Z} ${s?"disabled":""}`,type:"button",title:"Record the terminal to a GIF.",onClick:this.onRecord},1===n?_(er,null):_(et,null)),_("button",{class:`${X} ${Z}`,type:"button",title:"Make the terminal full-screen",onClick:this.makeFullscreen},_(en,null)),_("button",{class:`${X} ${Z}`,type:"button",title:"Send a `terminate' event to the computer.",onClick:this.onTerminate},_(V,null)))),_("div",{class:"L9KZzW_terminalProgress",style:`width: ${2===n?100*i:0}%`})))}componentDidUpdate(){var e;this.changed=!0,this.queueDraw(),this.props.focused&&(null===(e=this.inputElem.current)||void 0===e||e.focus())}queueDraw(){this.mounted&&!this.drawQueued&&(this.drawQueued=!0,window.requestAnimationFrame(e=>{this.drawQueued=!1,this.mounted&&(this.addGifFrame(),this.draw(e),this.props.terminal.cursorBlink&&this.queueDraw())}))}draw(e){if(!this.canvasElem||!this.canvasContext||!this.wrapperElem)return;let{terminal:t,font:r}=this.props,n=t.sizeX||51,i=t.sizeY||19,s=ef(r);if(s.promise){s.promise.then(()=>this.queueDraw());return}let o=Math.floor(e/400)%2==0,l=this.changed;if(!l&&(!t.cursorBlink||this.lastBlink===o||t.cursorX<0||t.cursorX>=n||t.cursorY<0||t.cursorY>=i))return;this.lastBlink=o,this.changed=!1;let a=this.canvasElem.current,h=this.wrapperElem.current,u=h.parentElement.clientWidth-8,c=h.parentElement.clientHeight-8-40,d=6*n,f=9*i,p=Math.max(1,Math.min(Math.floor(c/f),Math.floor(u/d))),_=this.canvasContext;if(!l){if(o)e_(_,t.cursorX,t.cursorY,t.currentFore,"_",t.palette,p,s);else{let e=t.cursorX,r=t.cursorY;ep(_,e,r,t.back[r].charAt(e),p,n,i,t.palette),e_(_,e,r,t.fore[r].charAt(e),t.text[r].charAt(e),t.palette,p,s)}return}let m=d*p+8,g=f*p+8;(a.height!==g||a.width!==m)&&(a.height=g,a.width=m,a.style.height=`${g}px`,h.style.width=a.style.width=`${m}px`),_.imageSmoothingEnabled=!1,0===t.sizeX&&0===t.sizeY?eg(_,n,i,"No terminal output",p,s):em(_,t,o,p,s)}paste(e){if(!e)return;let t=e.getData("text");t&&(t=(t=(t=t.replace(/[^\x20-\xFF]/gi,"")).replace(/[\r\n].*/,"")).substring(0,512))&&this.props.computer.queueEvent("paste",[t])}addGifFrame(e){if(!this.gif||!this.canvasContext)return;if(!this.lastGifFrame){console.error("Pushing a frame, but no previous frame!!");return}let t=Date.now();(e||!(t-this.lastGifFrame<50))&&(ey(`Adding frame for ${t-this.lastGifFrame} seconds`),this.gif.addFrame(this.canvasContext,{delay:t-this.lastGifFrame}),this.lastGifFrame=t)}convertMousePos(e){let t=this.canvasElem.current;if(!t)throw"impossible";let r=t.getBoundingClientRect(),n=eb(Math.floor((e.clientX-r.left-4)/(t.width-8)*this.props.terminal.sizeX)+1,1,this.props.terminal.sizeX),i=eb(Math.floor((e.clientY-r.top-4)/(t.height-8)*this.props.terminal.sizeY)+1,1,this.props.terminal.sizeY);return{x:n,y:i}}},t.TerminalData=class{constructor(){this.text=[],this.fore=[],this.back=[],this.palette=eu,this.currentFore="0",this.sizeX=0,this.sizeY=0,this.cursorX=0,this.cursorY=0,this.cursorBlink=!1}resize(e,t){this.sizeX=e,this.sizeY=t,this.text=Array(t),this.fore=Array(t),this.back=Array(t);let r="",n="",i="";for(let t=0;t<e;t++)r+=" ",n+=this.currentFore,i+="f";for(let e=0;e<t;e++)this.text[e]=r,this.fore[e]=n,this.back[e]=i}},t.VoidPersistence=class{getLabel(){return null}setLabel(){}getContents(){return eB}setContents(){}removeContents(){}getChildren(){return null}setChildren(){}removeChildren(){}getAttributes(){return null}setAttributes(){}removeAttributes(){}},t.__awaiter=K,t.actionButton=X,t.b=y,t.get=eW,t.iconFont=Y,t.joinName=eF,t.saveBlob=U,t.set=eN,t.splitName=eD,t.styleInject=R,t.termFont="term_font-7d20694439125422.png",t.termFontHd="term_font_hd-0506b6efe5f7feae.png",t.y=_});
|