/**
* XTerminal - v2.2.2
* @author Henry Hale
* @license MIT
* @url https://github.com/henryhale/xterminal#readme
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).XTerminal=e()}(this,function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,s=!0,a=!1;return{s:function(){r=r.call(e)},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,u=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw u}}}}function c(t,e,n){return(e=y(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function f(){return f="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var r=function(t,e){for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=p(t)););return t}(t,e);if(r){var i=Object.getOwnPropertyDescriptor(r,e);return i.get?i.get.call(arguments.length<3?t:n):i.value}},f.apply(null,arguments)}function p(t){return p=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},p(t)}function v(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&d(t,e)}function h(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(h=function(){return!!t})()}function d(t,e){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},d(t,e)}function y(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function m(t){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},m(t)}function b(t){var e="function"==typeof Map?new Map:void 0;return b=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return function(t,e,n){if(h())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,e);var i=new(t.bind.apply(t,r));return n&&d(i,n.prototype),i}(t,arguments,p(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),d(n,t)},b(t)}var g=new WeakMap,w=function(){return a(function t(){r(this,t),o(this,g,void 0),c(this,"isDisposed",void 0),this.isDisposed=!1,u(g,this,[])},[{key:"register",value:function(t){this.isDisposed?null==t||t.dispose():i(g,this).push(t)}},{key:"dispose",value:function(){this.isDisposed||(this.isDisposed=!0,i(g,this).forEach(function(t){return null==t?void 0:t.dispose()}))}}])}(),k=new WeakMap,O=function(t){function e(){var t;return r(this,e),o(t=n(this,e),k,void 0),u(k,t,{stack:[],store:new Map}),t.register({dispose:function(){return i(k,t).store.clear()}}),t}return v(e,t),a(e,[{key:"on",value:function(t,e){var n,r=i(k,this).store;r.has(t)?null===(n=r.get(t))||void 0===n||n.add(e):r.set(t,new Set([e]))}},{key:"once",value:function(t,e){var n,r=this,o=function(){for(var n=arguments.length,i=new Array(n),u=0;u1?r-1:0),u=1;u0&&void 0!==arguments[0]?arguments[0]:[];r(this,t),c(this,"store",void 0),c(this,"ptr",void 0),this.store=S(e)?e:[],this.ptr=-1},[{key:"size",get:function(){return this.store.length}},{key:"list",get:function(){return[].slice.call(this.store).reverse()}},{key:"add",value:function(t){t&&t!==this.store[0]&&this.store.unshift(t),this.ptr=-1}},{key:"previous",value:function(){return this.ptr++,this.ptr>=this.size&&(this.ptr=this.size-1),this.store[this.ptr]||""}},{key:"next",value:function(){return this.ptr--,this.ptr<=-1&&(this.ptr=-1),this.store[this.ptr]||""}},{key:"clear",value:function(){this.store.splice(0)}}])}(),A=" ",M="xt",j="xt-inactive",C="xt-cursor",L="xt-stdout",P="xt-stdin";function H(t){t&&t.scrollTo(0,t.scrollHeight)}function D(t,e){var n=document.createElement(t);return E(e)?(null!=e&&e.id&&(n.id=e.id||""),null!=e&&e.class&&(n.className=e.class||""),null!=e&&e.content&&n.appendChild(document.createTextNode(e.content||"")),null!=e&&e.html&&null!=e&&e.isSafe?n.innerHTML=e.html:null==e||!e.html||null!=e&&e.isSafe||(n.textContent=e.html),S(null==e?void 0:e.children)&&e.children.forEach(function(t){return n.append(t)}),E(null==e?void 0:e.props)&&Object.entries(e.props).forEach(function(t){return n.setAttribute(t[0],t[1])}),n):n}function I(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(/(\n)|(\n\r)|(\r\n)/g,"
").replace(/\s{2}/g,A.repeat(2)).replace(/\t/g,A.repeat(4))}var K=function(){return a(function t(e){r(this,t),c(this,"el",void 0),c(this,"console",void 0),c(this,"lastOutput",void 0),c(this,"onoutput",void 0);var n=function(t){var e=D("span"),n=D("div",{class:L,children:[e]});return t.appendChild(n),{outputBox:n,consoleBox:e}}(e),i=n.outputBox,o=n.consoleBox;this.el=i,this.console=o},[{key:"write",value:function(t,e){this.lastOutput=D("span",{html:I(t),isSafe:!0}),this.console.appendChild(this.lastOutput),T(this.onoutput)&&this.onoutput(),T(e)&&e()}},{key:"writeSafe",value:function(t,e){this.lastOutput=D("span",{content:I(t),isSafe:!1}),this.console.appendChild(this.lastOutput),T(this.onoutput)&&this.onoutput(),T(e)&&e()}},{key:"clear",value:function(){this.console&&(this.console.innerHTML="")}},{key:"clearLast",value:function(){var t;this.lastOutput&&(null===(t=this.lastOutput.parentNode)||void 0===t||t.removeChild(this.lastOutput));this.lastOutput=void 0}}])}(),F="Enter";function _(t,e,n,r){t.addEventListener(e,n,r);var i=!1;return{dispose:function(){i||(t.removeEventListener(e,n,r),i=!0)}}}var R,B=0;function z(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;ru?o=u:o<0&&(o=0),void(n.value=o);var t,e,n,r,o,u},u=N(o),s=N(function(){i.data.value=i.buffer=i.el.value});return W(o),i.register(_(i.el,"blur",function(){return i.isFocused.value=!1})),i.register(_(i.el,"focus",function(){return i.isFocused.value=!0},!1)),i.register(_(i.el,"keyup",function(){return i.isActive.value&&u()},!1)),i.register(_(i.el,"input",function(){s(),u()})),i.register(_(i.el,"keydown",function(t){t.stopImmediatePropagation();var e=i.data.value;t.key===F&&(i.el&&(i.el.value=""),i.data.value="",i.buffer="",i.showInput.value=!0),i.isActive.value&&T(i.onkeypress)&&(i.onkeypress({key:t.key,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,value:e,cancel:function(){t.preventDefault(),t.stopPropagation()}}),u())})),i}return v(e,t),a(e,[{key:"blur",value:function(){this.el&&this.el.blur()}},{key:"focus",value:function(){this.el&&this.el.focus()}},{key:"pause",value:function(){this.isActive.value=!1}},{key:"resume",value:function(){this.isActive.value=!0}},{key:"setValue",value:function(t){t=t||this.buffer,this.el&&(this.el.value=t),this.data.value=t}},{key:"clear",value:function(){this.buffer="",this.data.value="",this.el.value=""}},{key:"pipe",value:function(t){var e,n=this,r=D("span"),i=D("span",{class:C,html:A,isSafe:!0}),o=D("span");null===(e=t.el)||void 0===e||e.append(r,i,o),W(function(){var t=n.ptr.value,e=n.data.value;if(!n.isActive.value||!n.showInput.value)return r.textContent="",i.innerHTML=A,void(o.textContent="");r.textContent=e.substring(0,t),i.innerHTML=e.substring(t,t+1).trim()||A,o.textContent=e.substring(t+1)})}}])}(w);function q(t,e){var n,r,i=D("div",{class:M,props:{tabindex:0}}),o=new x,u=new K(i),s=new X(i),a={input:s,output:u,history:o,completer:function(t){return t}};return s.pipe(u),u.onoutput=function(){return H(i)},t.register(_(i,"keydown",function(t){s.focus(),z(function(){s.el.dispatchEvent(new KeyboardEvent("keydown",t)),s.el.dispatchEvent(new KeyboardEvent("input",t))})})),t.register(_(i,"focus",function(){return s.isFocused.value=!0})),t.register(_(i,"blur",function(){return s.isFocused.value=!1})),n=window||{},r=navigator||{},("ontouchstart"in n||r.maxTouchPoints)&&/Mobi/.test(r.userAgent)&&t.register(_(i,"click",s.focus.bind(s))),e.appendChild(i),s.onkeypress=function(e){e.key==F?(e.cancel(),o.add(e.value),u.writeSafe(e.value+"\n"),t.emit("data",e.value)):"Tab"==e.key?(e.cancel(),T(a.completer)&&s.setValue(a.completer(e.value))):"ArrowDown"==e.key?(e.cancel(),s.setValue(o.next())):"ArrowUp"==e.key?(e.cancel(),s.setValue(o.previous())):t.emit("keypress",e),H(i)},W(function(){s.isFocused.value?i.classList.remove(j):i.classList.add(j)}),a}var U=function(t){function e(t){var i;return r(this,e),(i=n(this,e,[t="[x] "+t])).name="XTerminalError",i}return v(e,t),a(e)}(b(Error)),$=new WeakMap,G=function(t){function e(t){var i;return r(this,e),o(i=n(this,e),$,void 0),c(i,"isMounted",void 0),i.isMounted=!1,t&&null!=t&&t.target&&i.mount(t.target),i}return v(e,t),a(e,[{key:"focus",value:function(){i($,this).input.focus()}},{key:"blur",value:function(){i($,this).input.blur()}},{key:"pause",value:function(){i($,this).input.pause(),this.emit("pause")}},{key:"resume",value:function(){i($,this).input.resume(),this.emit("resume")}},{key:"setInput",value:function(t){i($,this).input.setValue(t)}},{key:"clearInput",value:function(){i($,this).input.clear()}},{key:"write",value:function(t,e){i($,this).output.write(""+t,e)}},{key:"writeln",value:function(t,e){i($,this).output.write(t+"\n",e)}},{key:"writeSafe",value:function(t,e){i($,this).output.writeSafe(""+t,e)}},{key:"writelnSafe",value:function(t,e){i($,this).output.writeSafe(t+"\n",e)}},{key:"clear",value:function(){i($,this).output.clear(),this.emit("clear")}},{key:"clearLast",value:function(){i($,this).output.clearLast()}},{key:"history",get:function(){return i($,this).history.list||[]},set:function(t){var e=this;t.forEach(function(t){return i($,e).history.add(t)})}},{key:"clearHistory",value:function(){i($,this).history.clear()}},{key:"setCompleter",value:function(t){T(t)&&(i($,this).completer=t)}},{key:"mount",value:function(t){if(!this.isMounted){if(t&&"string"==typeof t&&(t=document.querySelector(t)),!(t instanceof HTMLElement))throw new U("mount: A parent HTMLElement (target) is required");!t.isConnected&&console&&console.warn("'mount' was called on an HTMLElement (target) that is not attached to DOM."),t.innerHTML="",u($,this,q(this,t)),this.isMounted=!0}}},{key:"dispose",value:function(){var t,n,r,o;(n="dispose",r=this,"function"==typeof(o=f(p(e.prototype),n,r))?function(t){return o.apply(r,t)}:o)([]);var u=i($,this);u.history.clear(),u.completer=void 0,u.input.dispose();var s=u.output.el.parentNode;null==s||null===(t=s.parentNode)||void 0===t||t.removeChild(s),this.isMounted=!1}}],[{key:"version",get:function(){return"2.2.2"}},{key:"XEventEmitter",get:function(){return O}},{key:"escapeHTML",value:function(t){return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=document.createElement("span");return e.textContent=t,e.innerHTML}(t)}}])}(O);return G});