cirsim
Version:
Cirsim Circuit Simulator
2 lines • 365 kB
JavaScript
/*! For license information please see cirsim.min.js.LICENSE.txt */
(()=>{var t,e,i={396:(t,e,i)=>{"use strict";i(664);const n=function(t){var e=this.constructor;return this.then((function(i){return e.resolve(t()).then((function(){return i}))}),(function(i){return e.resolve(t()).then((function(){return e.reject(i)}))}))};const o=function(t){return new this((function(e,i){if(!t||void 0===t.length)return i(new TypeError(typeof t+" "+t+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var n=Array.prototype.slice.call(t);if(0===n.length)return e([]);var o=n.length;function r(t,i){if(i&&("object"==typeof i||"function"==typeof i)){var s=i.then;if("function"==typeof s)return void s.call(i,(function(e){r(t,e)}),(function(i){n[t]={status:"rejected",reason:i},0==--o&&e(n)}))}n[t]={status:"fulfilled",value:i},0==--o&&e(n)}for(var s=0;s<n.length;s++)r(s,n[s])}))};var r=setTimeout;function s(t){return Boolean(t&&void 0!==t.length)}function a(){}function c(t){if(!(this instanceof c))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],f(t,this)}function l(t,e){for(;3===t._state;)t=t._value;0!==t._state?(t._handled=!0,c._immediateFn((function(){var i=1===t._state?e.onFulfilled:e.onRejected;if(null!==i){var n;try{n=i(t._value)}catch(t){return void h(e.promise,t)}u(e.promise,n)}else(1===t._state?u:h)(e.promise,t._value)}))):t._deferreds.push(e)}function u(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var i=e.then;if(e instanceof c)return t._state=3,t._value=e,void d(t);if("function"==typeof i)return void f((n=i,o=e,function(){n.apply(o,arguments)}),t)}t._state=1,t._value=e,d(t)}catch(e){h(t,e)}var n,o}function h(t,e){t._state=2,t._value=e,d(t)}function d(t){2===t._state&&0===t._deferreds.length&&c._immediateFn((function(){t._handled||c._unhandledRejectionFn(t._value)}));for(var e=0,i=t._deferreds.length;e<i;e++)l(t,t._deferreds[e]);t._deferreds=null}function p(t,e,i){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=i}function f(t,e){var i=!1;try{t((function(t){i||(i=!0,u(e,t))}),(function(t){i||(i=!0,h(e,t))}))}catch(t){if(i)return;i=!0,h(e,t)}}c.prototype.catch=function(t){return this.then(null,t)},c.prototype.then=function(t,e){var i=new this.constructor(a);return l(this,new p(t,e,i)),i},c.prototype.finally=n,c.all=function(t){return new c((function(e,i){if(!s(t))return i(new TypeError("Promise.all accepts an array"));var n=Array.prototype.slice.call(t);if(0===n.length)return e([]);var o=n.length;function r(t,s){try{if(s&&("object"==typeof s||"function"==typeof s)){var a=s.then;if("function"==typeof a)return void a.call(s,(function(e){r(t,e)}),i)}n[t]=s,0==--o&&e(n)}catch(t){i(t)}}for(var a=0;a<n.length;a++)r(a,n[a])}))},c.allSettled=o,c.resolve=function(t){return t&&"object"==typeof t&&t.constructor===c?t:new c((function(e){e(t)}))},c.reject=function(t){return new c((function(e,i){i(t)}))},c.race=function(t){return new c((function(e,i){if(!s(t))return i(new TypeError("Promise.race accepts an array"));for(var n=0,o=t.length;n<o;n++)c.resolve(t[n]).then(e,i)}))},c._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){r(t,0)},c._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};const v=c;var m=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==i.g)return i.g;throw new Error("unable to locate global object")}();"function"!=typeof m.Promise?m.Promise=v:m.Promise.prototype.finally?m.Promise.allSettled||(m.Promise.allSettled=o):m.Promise.prototype.finally=n;i(224),i(384);function y(t,e){t.classList.add("resizer");let i=e.grabSize,n=e.handle;"bar"===n?(t.style.resize="none",t.style.borderBottom=i+"px solid #18453B"):"handle"===n?t.style.resize="vertical":"none"===n||(t.style.resize="none",t.style.borderBottom=n);let o=!1,r=!1,s=null;const a=t.getBoundingClientRect();let c=a.height,l=a.width,u=getComputedStyle(t).minHeight;u=u.substr(0,u.length-2);let h=getComputedStyle(t).minWidth;h=h.substr(0,h.length-2);let d,p,f,v,m=null,y=null,g=null;function b(){m=null;const i=20*e.maxSpeed/1e3;if(null!==g){const e=+c;let n=g-e;Math.abs(n)>i?(n=n<0?-i:i,c=e+n,t.style.height=c+"px"):(c=g,t.style.height=c+"px",g=null)}if(null!==y){const e=+l;let n=y-e;Math.abs(n)>i?(n=n<0?-i:i,l=e+n,t.style.width=l+"px"):(l=y,t.style.width=l+"px",y=null)}null===g&&null===y||(m=setTimeout(b,20))}let A=null;function w(e,i){d=e,p=i;t.getBoundingClientRect();l=+t.clientWidth,f=l,c=+t.clientHeight,v=c,y=null,g=null}function x(e,i){let n=i-p,o=null,r=null;if("horizontal"!==A&&"both"!==A||(o=f+(e-d),o<h&&(o=h)),"vertical"===A||"both"===A){t.offsetHeight;r=v+n,r<u&&(r=u)}y=o,g=r,null===m&&b()}function k(t){const e=t.pageX,i=t.pageY;A=M(e,i,!1),null!==A&&(t.stopPropagation(),t.preventDefault(),w(e,i),O(),z(),o=!0,document.addEventListener("mousemove",I,!1),document.addEventListener("mouseup",C,!1))}function I(t){t.stopPropagation(),t.preventDefault(),1===t.buttons?x(t.pageX,t.pageY):B()}function C(t){B()}function T(t){const e=t.touches[0].pageX,i=t.touches[0].pageY;A=M(e,i,!0),null!==A&&(t.stopPropagation(),t.preventDefault(),w(e,i),O(),z(),r=!0,document.addEventListener("touchmove",E),document.addEventListener("touchend",S),document.addEventListener("touchcancel",S))}function E(t){t.stopPropagation();x(t.touches[0].pageX,t.touches[0].pageY)}function S(t){B()}function O(){if(!e.useMask)return;j();let t=document.querySelector("body");s=document.createElement("div"),s.style.position="fixed",s.style.left=0,s.style.top=0,s.style.width="100%",s.style.height="100%",s.style.backgroundColor="transparent",s.style.zIndex=1e4,s.style.opacity=.5,s.style.cursor="pointer",t.appendChild(s)}function B(){null!==m&&(clearTimeout(m),m=null),z(),j()}function z(){o&&(document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",C),o=!1),r&&(document.removeEventListener("touchmove",E),document.removeEventListener("touchend",S),document.removeEventListener("touchcancel",S),r=!1)}function j(){if(null!==s){document.querySelector("body").removeChild(s),s=null}}function M(n,o,r){let s=t.getBoundingClientRect();const a=r?10:0;let c=o>=s.bottom+window.pageYOffset-i-a,l=n>=s.right+window.pageXOffset-i-a;if("both"===e.resize){if(c&&l)return"both";if(c)return"vertical";if(l)return"horizontal"}return"both"!==e.resize&&"vertical"!==e.resize||!c?"both"!==e.resize&&"horizontal"!==e.resize||!l?null:"horizontal":"vertical"}let R=0;function L(e){null!==M(e.pageX,e.pageY,!1)?2!==R&&(t.style.cursor="pointer",R=2):1!==R&&(t.style.cursor="text",R=1)}t.addEventListener("mousedown",k),t.addEventListener("touchstart",T),t.addEventListener("mousemove",L)}function g(t){for(var e in t=t||{},this.resize="vertical",this.handle="bar",this.grabSize=10,this.maxSpeed=1e3,this.useMask=!0,t)if(t.hasOwnProperty(e)){if(!this.hasOwnProperty(e))throw new Error("Invalid option "+e);this[e]=t[e]}}const b=function(t,e){if(e=new g(e),"string"==typeof t)for(var i=document.querySelectorAll(t),n=0;n<i.length;n++)new y(i[n],e);else t.nodeType&&new y(t,e)};var A=function(){this.circuit=null,this.x=0,this.y=0,this.moveX=0,this.moveY=0,this.selectedStyle="#ff0000",this.unselectedStyle="#000000"};A.prototype.copyFrom=function(t){this.x=t.x,this.y=t.y,this.moveX=t.moveX,this.moveY=t.moveY},A.prototype.single=function(){return!1},A.prototype.selectStyle=function(t,e){return e.selection.isSelected(this)?(t.strokeStyle=this.selectedStyle,t.fillStyle=this.selectedStyle,!0):(t.strokeStyle=this.unselectedStyle,t.fillStyle=this.unselectedStyle,!1)},A.prototype.grab=function(){this.moveX=this.x,this.moveY=this.y},A.prototype.move=function(t,e){this.moveX+=t,this.moveY+=e,this.x=this.moveX,this.y=this.moveY,null!==this.circuit&&this.circuit.snapIt(this)},A.prototype.place=function(t,e){this.moveX=t,this.moveY=e,this.x=this.moveX,this.y=this.moveY,null!==this.circuit&&this.circuit.snapIt(this)},A.prototype.delete=function(){},A.prototype.drop=function(){},A.prototype.spawn=function(t,e){return null};var w=function(){};w.toHex=function(t,e){for(var i=Number(t).toString(16);i.length<e;)i="0"+i;return i},w.toBinary=function(t,e){for(var i=Number(t).toString(2);i.length<e;)i="0"+i;return i},w.inArray=function(t,e){for(var i=0;i<e.length;i++)if(e[i].toLowerCase()===t.toLowerCase())return!0;return!1};var x=function(t,e){this.x=t,this.y=e};x.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y);this.x/=t,this.y/=t},x.normalize=function(t){var e=Math.sqrt(t.x*t.x+t.y*t.y);return new x(t.x/e,t.y/e)},x.rotate=function(t,e){var i=Math.sin(e),n=Math.cos(e);return new x(n*t.x-i*t.y,i*t.x+n*t.y)},x.distanceToLine=function(t,e,i,n){return 0==e?Math.abs((i*t.y+n)/i):0==i?Math.abs((e*t.x+n)/e):Math.abs(e*t.x+i*t.y+n)/Math.sqrt(e*e+i*i)},x.distanceToLineP2=function(t,e,i){return x.distanceToLine(t,e.y-i.y,i.x-e.x,e.x*i.y-i.x*e.y)},x.nearestOnLine=function(t,e,i,n){return 0==e?{x:t.x,y:-n/i}:0==i?{x:-n/e,y:t.y}:{x:(i*(i*t.x-e*t.y)-e*n)/(e*e+i*i),y:(e*(-i*t.x+e*t.y)-i*n)/(e*e+i*i)}},x.nearestOnLineP2=function(t,e,i){return x.nearestOnLine(t,e.y-i.y,i.x-e.x,e.x*i.y-i.x*e.y)},x.computeT=function(t,e,i){var n=i.x-e.x,o=i.y-e.y;return Math.abs(n)>Math.abs(o)?(t.x-e.x)/n:(t.y-e.y)/o},x.distance=function(t,e){return Math.sqrt((e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y))},x.distanceToLineSegment=function(t,e,i){var n=x.nearestOnLineP2(t,e,i),o=x.computeT(n,e,i);if(o>=0&&o<=1)return{d:x.distance(t,n),p:n};var r=x.distance(t,e),s=x.distance(t,i);return r<s?{d:r,p:e}:{d:s,p:i}};var k=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;this.left=t,this.top=e,this.right=i,this.bottom=n};k.prototype.setRightBottom=function(t,e){this.right=t,this.bottom=e},k.prototype.normalize=function(){if(this.left>this.right){var t=this.left;this.left=this.right,this.right=t}if(this.top>this.bottom){var e=this.top;this.top=this.bottom,this.bottom=e}},k.prototype.isEmpty=function(){return this.left>=this.right||this.top>=this.bottom},k.prototype.contains=function(t,e){return t>=this.left&&t<=this.right&&e>=this.top&&e<=this.bottom},k.prototype.expand=function(t){t.left<this.left&&(this.left=t.left),t.right>this.right&&(this.right=t.right),t.top<this.top&&(this.top=t.top),t.bottom>this.bottom&&(this.bottom=t.bottom)},k.prototype.expandXY=function(t,e){t<this.left&&(this.left=t),t>this.right&&(this.right=t),e<this.top&&(this.top=e),e>this.bottom&&(this.bottom=e)};var I=function(t,e,i,n,o,r){this.component=t,this.x=e,this.y=i,this.len=void 0!==n?n:16,this.index=void 0,this.name=o,this.inv=r,this.value=void 0,this.touchRange=8,this.bus=!1,this.reference=null,this.clock=!1};function C(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!i){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return T(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return T(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},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 r,s=!0,a=!1;return{s:function(){i=i.call(t)},n:function(){var t=i.next();return s=t.done,t},e:function(t){a=!0,r=t},f:function(){try{s||null==i.return||i.return()}finally{if(a)throw r}}}}function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}I.prototype.orientation="w",I.prototype.single=function(){return!0},I.prototype.copyFrom=function(t){this.x=t.x,this.y=t.y,this.len=t.len,this.index=t.index,this.name=t.name,this.inv=t.inv,this.value=t.value,this.touchRange=t.touchRange,this.bus=t.bus,this.reference=t.reference},I.prototype.get=function(){return this.value},I.prototype.getAsString=function(){return function t(e){if(Array.isArray(e)){var i="";return e.forEach((function(e){i=t(e)+i})),i}return void 0===e?"?":e?"1":"0"}(this.value)},I.parseBusValue=function(t){for(var e=[],i=t.length-1;i>=0;i--){switch(t.substr(i,1)){case"0":e.push(!1);break;case"1":e.push(!0);break;case"?":e.push(void 0);break;default:return null}}return e},I.busValueToDecimal=function(t,e){if(void 0===t)return null;var i=0,n=1;for(var o in t){if(void 0===t[o])return null;t[o]&&(i+=n),n*=2}return void 0!==e&&(i%=e),i},I.prototype.touch=function(t,e){var i=this.getLoc(),n=this.touchRange;return t>=i.x-n&&t<=i.x+n&&e>=i.y-n&&e<=i.y+n},I.prototype.getLoc=function(){switch(this.orientation){case"w":return new x(this.component.x+this.x-this.len,this.component.y+this.y);case"n":return new x(this.component.x+this.x,this.component.y+this.y-this.len);case"s":return new x(this.component.x+this.x,this.component.y+this.y+this.len);case"e":return new x(this.component.x+this.x+this.len,this.component.y+this.y)}},I.prototype.draw=function(t,e){var i=this.component.x+this.x,n=this.component.y+this.y;switch(this.bus?t.lineWidth=2:t.lineWidth=1,this.orientation){case"e":if(t.beginPath(),t.moveTo(i,n+.5),t.lineTo(i+this.len,n+.5),t.fillRect(i+this.len-1,n-1,3,3),this.component.circuit.circuits.model.main.options.showOutputStates){t.font="11px Times",t.textAlign="left";var o=this.getAsString();o.length>8&&(o=parseInt(o,2),o=isNaN(o)?"?":w.toHex(o,4)),t.fillText(o,i+5,n-2)}void 0!==this.name&&(t.font="12px Times",t.textAlign="right",t.fillText(this.name,i-3,n+3)),t.stroke();break;case"w":if(t.beginPath(),t.moveTo(i,n+.5),t.lineTo(i-this.len,n+.5),t.fillRect(i-this.len-1,n-1,3,3),this.clock){var r=7;t.moveTo(i,n-r),t.lineTo(i+r,n),t.lineTo(i,n+r)}void 0!==this.name&&(t.font="12px Times",t.textAlign="left",t.fillText(this.name,i+2,n+3)),t.stroke();break;case"n":if(t.beginPath(),t.moveTo(i+.5,n),t.lineTo(i+.5,n-this.len),t.fillRect(i-1,n-this.len-1,3,3),this.clock){r=7;t.moveTo(i-r,n),t.lineTo(i,n+r),t.lineTo(i+r,n)}t.stroke(),void 0!==this.name&&(n+=this.clock?12+r:12,t.font="12px Times",t.textAlign="center",t.fillText(this.name,i,n));break;case"s":if(t.beginPath(),t.moveTo(i+.5,n),t.lineTo(i+.5,n+this.len),t.fillRect(i-1,n+this.len-1,3,3),this.clock){r=7;t.moveTo(i-r,n),t.lineTo(i,n-r),t.lineTo(i+r,n)}t.stroke(),void 0!==this.name&&(n-=this.clock?6+r:6,t.font="12px Times",t.textAlign="center",t.fillText(this.name,i,n))}t.lineWidth=1},I.prototype.autoLen=function(){switch(this.orientation){case"s":for(this.len=8*Math.floor(this.y/8)+8-this.y;this.len<12;)this.len+=8}},I.prototype.bounds=function(){var t=this.component.x+this.x,e=this.component.y+this.y,i=new k(t,e,t,e);switch(this.orientation){case"e":i.expandXY(t+this.len,e);break;case"w":i.expandXY(t-this.len,e);break;case"n":i.expandXY(t,e-this.len);break;case"s":i.expandXY(t,e+this.len)}return i};var E=function(t,e,i,n,o,r){I.call(this,t,e,i,n,o,r),this.to=[],this.orientation="e"};(E.prototype=Object.create(I.prototype)).constructor=E,E.prototype.clone=function(){var t=new E(this.component,this.x,this.y,this.len,this.name,this.inv);return t.orientation=this.orientation,t.copyFrom(this),t},E.prototype.set=function(t){var e=!0;if(Array.isArray(t)){if(Array.isArray(this.value)&&t.length===this.value.length)for(var i in e=!1,t)if(t[i]!==this.value[i]){e=!0;break}}else e=this.value!==t;if(e){this.value=t;for(var n=0;n<this.to.length;n++){var o=this.to[n].to;null!==o&&o.set()}}},E.prototype.setAsString=function(t){if(this.bus)this.set(I.parseBusValue(t));else switch(t){default:this.set(!1);break;case"1":this.set(!0);break;case"?":this.set(void 0)}},E.prototype.get=function(){return this.value},E.prototype.draw=function(t,e){I.prototype.draw.call(this,t,e),this.bus?t.lineWidth=2:t.lineWidth=1;for(var i=0;i<this.to.length;i++)this.to[i].draw(t,e);t.lineWidth=1},E.prototype.add=function(t){this.to.push(t)},E.prototype.remove=function(t){var e=[];this.to.forEach((function(i){i!==t&&e.push(i)})),this.to=e},E.prototype.clear=function(){this.to.forEach((function(t){t.delete(this)})),this.to=[]},E.prototype.touchConnections=function(t,e){for(var i=0;i<this.to.length;i++){var n=this.to[i].touch(t,e);if(null!=n)return n}return null},E.prototype.selectRect=function(t,e){for(var i=0;i<this.to.length;i++)this.to[i].selectRect(t,e)},E.prototype.bounds=function(){var t,e=I.prototype.bounds.call(this),i=C(this.to);try{for(i.s();!(t=i.n()).done;){var n=t.value;e.expand(n.bounds())}}catch(t){i.e(t)}finally{i.f()}return e};var S=function(t,e,i,n,o,r){I.call(this,t,e,i,n,o,r),this.from=[],this.orientation="w"};(S.prototype=Object.create(I.prototype)).constructor=S,S.prototype.clone=function(){var t=new S(this.component,this.x,this.y,this.len,this.name,this.inv);return t.orientation=this.orientation,t.copyFrom(this),t},S.prototype.set=function(){var t=this.from.length>0&&null!==this.from[0].from?this.from[0].from.value:void 0;this.value!==t&&(this.value=t,this.component.pending())},S.prototype.testAsString=function(t){this.component.testAsString(t,this)},S.prototype.setConnection=function(t){this.from.forEach((function(t){t.delete(this)})),t.to=this,this.from=[t],this.set()},S.prototype.clear=function(){this.from.forEach((function(t){t.delete(this)})),this.from=[]},S.prototype.add=function(t){this.from.push(t)},S.prototype.remove=function(t){var e=[];this.from.forEach((function(i){i!==t&&e.push(i)})),this.from=e},S.prototype.draw=function(t,e){I.prototype.draw.call(this,t,e);for(var i=0;i<this.from.length;i++)null===this.from[i].from&&this.from[i].draw(t,e)},S.prototype.bounds=function(){return I.prototype.bounds.call(this)};var O=function(t,e,i,n,o,r){E.call(this,t,e,i,n,o,r)};(O.prototype=Object.create(E.prototype)).constructor=O,O.prototype.draw=function(t,e){var i=this.component.x+this.x,n=this.component.y+this.y;t.beginPath(),t.arc(i+4+.5,n,4,0,2*Math.PI),t.moveTo(i+8,n+.5),t.lineTo(i+this.len,n+.5),t.fillRect(i+this.len-1,n-1,3,3),this.component.circuit.circuits.model.main.options.showOutputStates&&(t.font="11px Times",t.fillText(void 0===this.value?"?":this.value?"1":"0",i+7+8,n-2)),t.stroke(),void 0!==this.name&&(t.font="12px Times",t.textAlign="right",t.fillText(this.name,i-3,n+3),this.inv&&(n-=8,t.beginPath(),t.moveTo(i-3,n),t.lineTo(i-13,n),t.stroke()));for(var o=0;o<this.to.length;o++)this.to[o].draw(t,e)},O.prototype.set=function(t){void 0===t?E.prototype.set.call(this,t):E.prototype.set.call(this,!t)};var B=function(t,e){A.call(this),this.connection=null,void 0!==t&&(this.x=t,this.moveX=t),void 0!==e&&(this.y=e,this.moveY=e)};function z(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!i){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return j(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return j(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},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 r,s=!0,a=!1;return{s:function(){i=i.call(t)},n:function(){var t=i.next();return s=t.done,t},e:function(t){a=!0,r=t},f:function(){try{s||null==i.return||i.return()}finally{if(a)throw r}}}}function j(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}(B.prototype=Object.create(A.prototype)).constructor=B,B.prototype.touchRange=12,B.prototype.size=4,B.prototype.clone=function(){var t=new B;return t.copyFrom(this),t},B.prototype.draw=function(t,e){e.selection.isSelected(this)&&(this.selectStyle(t,e),t.beginPath(),t.arc(this.x,this.y,this.size,0,2*Math.PI),t.fill())},B.prototype.touch=function(t,e){return Math.abs(t-this.x)+Math.abs(e-this.y)<=this.touchRange},B.prototype.delete=function(t){this.connection.removeBend(this)},B.prototype.save=function(){return{x:this.x,y:this.y}};var M=function(t,e,i){if(A.call(this),this.touchRange=8,this.bends=[],null!==t){if(this.circuit=t.component.circuit,this.from=t,this.from.add(this),null===e){var n=t.getLoc();this.x=n.x,this.y=n.y}}else this.from=null;if(void 0===e&&console.log(this),null!==e){if(this.circuit=e.component.circuit,this.to=e,this.to.add(this),null===t){n=e.getLoc();this.x=n.x,this.y=n.y}!0!==i&&e.set()}else this.to=null};(M.prototype=Object.create(A.prototype)).constructor=M,M.prototype.clone=function(){if(null===this.from||null===this.to)return null;var t=this.from.component.prev,e=this.to.component.prev,i=this.from.index,n=this.to.index;void 0===e.ins[n]&&console.log(this);for(var o=new M(t.outs[i],e.ins[n],!0),r=0;r<this.bends.length;r++){var s=this.bends[r].clone();o.addBend(s)}return o},M.prototype.delete=function(t){var e=this.to;null!==this.to&&this.to!==t&&this.to.remove(this),null!==this.from&&this.from!==t&&this.from.remove(this),null!==e&&e.set()},M.prototype.removeBend=function(t){var e=[];this.bends.forEach((function(i){i!==t&&e.push(i)})),this.bends=e},M.prototype.getCircuit=function(){return null!==this.from?this.from.component.circuit:null!==this.to?this.to.component.circuit:null},M.prototype.drop=function(){if(null!==this.from&&null===this.to){var t=this.from.component.circuit.touchIn(this.x,this.y);null!==t&&this.from.bus===t.bus?t.setConnection(this):this.from.remove(this)}else if(null===this.from&&null!==this.to){var e=this.to.component.circuit.touchOut(this.x,this.y);null!==e&&this.to.bus===e.bus?(this.to.clear(),this.to.from=[this],this.from=e,e.add(this),this.to.set()):this.to.remove(this)}},M.prototype.draw=function(t,e){if(this.selectStyle(t,e),t.beginPath(),null!==this.from){var i=this.from.getLoc();t.moveTo(i.x+.5,i.y+.5)}else t.moveTo(this.x+.5,this.y+.5);for(var n=0;n<this.bends.length;n++){var o=this.bends[n];t.lineTo(o.x+.5,o.y+.5)}if(null!==this.to){i=this.to.getLoc();t.lineTo(i.x+.5,i.y+.5)}else t.lineTo(this.x+.5,this.y+.5);t.stroke();for(n=0;n<this.bends.length;n++)this.bends[n].draw(t,e)},M.prototype.bounds=function(){var t=null;if(null!==this.from){var e=this.from.getLoc();t=new k(e.x,e.y,e.x,e.y)}else t=new k(this.x,this.y,this.x,this.y);var i,n=z(this.bends);try{for(n.s();!(i=n.n()).done;){var o=i.value;t.expandXY(o.x,o.y)}}catch(t){n.e(t)}finally{n.f()}if(null!==this.to){var r=this.to.getLoc();t.expandXY(r.x,r.y)}else t.expandXY(this.x,this.y);return t},M.prototype.touch=function(t,e){for(var i=null!==this.from?this.from:new x(t,e),n=null!==this.to?this.to:new x(t,e),o=0;o<this.bends.length;o++){var r=this.bends[o];if(r.touch(t,e))return r}var s=i.getLoc();for(o=0;o<this.bends.length;o++){var a=this.bends[o];if(x.distanceToLineSegment({x:t,y:e},s,a).d<=this.touchRange)return this;s=a}return x.distanceToLineSegment({x:t,y:e},s,n.getLoc()).d<=this.touchRange?this:null},M.prototype.selectRect=function(t,e){for(var i=0;i<this.bends.length;i++){var n=this.bends[i];t.contains(n.x,n.y)&&e.push(n)}},M.prototype.spawn=function(t,e){if(null!==this.to&&null!==this.from){for(var i=0,n=1e10,o=this.from.getLoc(),r=0;r<this.bends.length;r++){var s=this.bends[r];(a=x.distanceToLineSegment({x:t,y:e},o,s)).d<=n&&(i=r,n=a.d),o=s}var a;(a=x.distanceToLineSegment({x:t,y:e},o,this.to.getLoc())).d<=n&&(i=r,n=a.d);var c=new B;return i<this.bends.length?this.insertBend(i,c):this.addBend(c),c.place(t,e),c}return null},M.prototype.insertBend=function(t,e){e.connection=this,e.circuit=this.circuit,this.bends.splice(t,0,e)},M.prototype.addBend=function(t){t.connection=this,t.circuit=this.circuit,this.bends.push(t)},M.prototype.save=function(){if(null===this.from||null===this.to)return null;for(var t=this.from.component,e=this.to.component,i=this.from.index,n=this.to.index,o=[],r=0;r<this.bends.length;r++){var s=this.bends[r];o.push(s.save())}return{from:t.id,out:i,to:e.id,in:n,bends:o}},M.prototype.load=function(t){var e=this;t.bends.forEach((function(t){var i=new B(t.x,t.y);e.addBend(i)}))};var R=function(){};R.unique=1,R.uniqueId=function(){return R.unique++},R.uniqueName=function(){return"cirsim-id-"+R.unique++};const L=R;function N(t){return(N="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})(t)}function D(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!i){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return P(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return P(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},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 r,s=!0,a=!1;return{s:function(){i=i.call(t)},n:function(){var t=i.next();return s=t.done,t},e:function(t){a=!0,r=t},f:function(){try{s||null==i.return||i.return()}finally{if(a)throw r}}}}function P(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}var U=function(){};U.isVisible=function(t){return!!(t.offsetWidth||t.offsetHeight||t.getClientRects().length)},U.addClass=function(t,e){t.classList?t.classList.add(e):t.className+=" "+e},U.addClasses=function(t,e){null!=e&&e.split(" ").forEach((function(e){U.addClass(t,e)}))},U.removeClass=function(t,e){var i=new RegExp("\\b"+e+"\\b","g");t.className=t.className.replace(i,"")},U.createClassedDiv=function(t,e){var i=document.createElement("div");return U.addClass(i,t),void 0!==e&&U.addContent(i,e),i},U.addContent=function(t,e){U.isString(e)?t.innerHTML+=e:U.isElement(e)&&t.appendChild(e)},U.isString=function(t){return"string"==typeof t||!!t&&"object"===N(t)&&"[object String]"===Object.prototype.toString.call(t)},U.isElement=function(t){return null!=t&&void 0!==t.nodeValue},U.offset=function(t){var e=t.getBoundingClientRect();return{left:e.left+t.scrollLeft+window.pageXOffset,top:e.top+t.scrollTop+window.pageYOffset}},U.child=function(t,e){var i,n=D(t.childNodes);try{for(n.s();!(i=n.n()).done;){var o=i.value;if(o.tagName===e)return o}}catch(t){n.e(t)}finally{n.f()}return null};var q=i(25),H=i.n(q);const F=function(t){for(var e in t=t||{},this.title="Dialog Box",this.addClass=null,this.resize="none",this.grabSize=4,this.titleBarButtons=null,this.titleBarAddClass=null,this.buttons=null,this.content=null,this.modal=!0,this.parent=null,this.form=!0,t)if(t.hasOwnProperty(e)){if(!this.hasOwnProperty(e))throw new Error("Invalid option "+e);this[e]=t[e]}},_=function(){};_.addClass=function(t,e){t.classList?t.classList.add(e):t.className+=" "+e},_.addClasses=function(t,e){null!=e&&e.split(" ").forEach((e=>{_.addClass(t,e)}))},_.createClassedDiv=function(t,e){let i=document.createElement("div");return _.addClass(i,t),_.addContent(i,e),i},_.addContent=function(t,e){_.isString(e)?t.innerHTML+=e:_.isElement(e)&&t.appendChild(e)},_.isString=function(t){return"string"==typeof t||!!t&&"object"==typeof t&&"[object String]"===Object.prototype.toString.call(t)},_.isElement=function(t){return null!=t&&void 0!==t.nodeValue};const Q=_;function X(t,e){let i,n,o,r,s=t.options,a=!1,c=!1;function l(e,i){let n=document.createElement("button");e.appendChild(n),Q.addClass(n,"dialog-cl-tb-button"),n.innerHTML='<span class="icons-cl icons-cl-close">',n.onclick=e=>{e.preventDefault(),void 0!==i&&void 0!==i.click?i.click():t.close()}}function u(e,s){let a=o+(e-i),c=r+(s-n);t.div.style.left=a+"px",t.div.style.top=c+"px"}function h(e){i=e.pageX,n=e.pageY;let s=t.div.getBoundingClientRect();o=s.left,r=s.top,y(),a=!0,document.addEventListener("mousemove",d),document.addEventListener("mouseup",p)}function d(t){1===t.buttons?u(t.pageX,t.pageY):y()}function p(t){y()}function f(e){e.stopPropagation(),e.preventDefault(),i=e.touches[0].pageX,n=e.touches[0].pageY;let s=t.div.getBoundingClientRect();o=s.left,r=s.top,y(),c=!0,document.addEventListener("touchmove",v),document.addEventListener("touchend",m),document.addEventListener("touchcancel",m)}function v(t){t.stopPropagation(),u(t.touches[0].pageX,t.touches[0].pageY)}function m(t){y()}function y(){a&&(document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",p),a=!1),c&&(document.removeEventListener("touchmove",v),document.removeEventListener("touchend",m),document.removeEventListener("touchcancel",m),c=!1)}(()=>{let i=`<h1>${s.title}</h1>`,n=Q.createClassedDiv("dialog-cl-top",i);Q.addClasses(n,s.titleBarAddClass),e.appendChild(n),null===s.titleBarButtons?l(n):s.titleBarButtons.forEach((e=>{"close"===e.type?l(n,e):"custom"===e.type&&function(e,i){let n=document.createElement("button");e.appendChild(n),Q.addClass(n,"dialog-cl-tb-button"),n.innerHTML=i.contents,n.onclick=e=>{e.preventDefault(),void 0!==i&&void 0!==i.click?i.click():t.close()}}(n,e)}));let o=n.querySelector("h1");o.addEventListener("mousedown",h),o.addEventListener("touchstart",f)})()}const W=function(t,e){let i=t.options,n=document.createElement("div");n.classList.add("dialog-cl-body"),Q.addContent(n,i.content),e.appendChild(n),this.div=n};const Y=function(t,e){let i=t.options;(()=>{let n=Q.createClassedDiv("cl-dialog-bottom");e.appendChild(n),null===i.buttons?function(e,i){let n=document.createElement("button");n.type="submit",e.appendChild(n),n.innerHTML="Ok",n.onclick=e=>{e.preventDefault(),void 0!==i&&void 0!==i.click?i.click(t):t.close()},n.focus()}(n):i.buttons.forEach((e=>{!function(e,i){let n=document.createElement("button");n.type="submit",e.appendChild(n),n.innerHTML=i.contents,n.onclick=e=>{e.preventDefault(),void 0!==i&&void 0!==i.click&&i.click(t)},void 0!==i.class&&n.classList.add(i.class);!0===i.focus&&n.focus()}(n,e)}))})(),this.default=function(){i.buttons.forEach((e=>{!0===e.default&&void 0!==e.click&&e.click(t)}))}},J=function(t){let e=t.options,i=null;if(e.modal){let e=document.querySelector("body");i=Q.createClassedDiv("mask"),i.style.position="fixed",i.style.left=0,i.style.top=0,i.style.width="100%",i.style.height="100%",i.style.backgroundColor="transparent",i.style.zIndex=t.zIndex-1,e.appendChild(i)}this.remove=function(){if(null!==i){document.querySelector("body").removeChild(i),i=null}}};let V=function(t){t=new F(t),this.options=t;let e=null,i=null,n=null,o=null;Object.defineProperties(this,{form:{get:function(){return o}}});const r=t=>{27===t.keyCode&&(t.preventDefault(),t.stopPropagation(),this.close())};let s=e=>{if("none"!==t.resize){let i={resize:t.resize,handle:"none",grabSize:t.grabSize};new b(e,i)}};function a(t){return t+"px"}const c=(t,e)=>{let i,n;null===e?(i=window.innerWidth,n=window.innerHeight):(i=e.offsetWidth,n=e.offsetHeight);let o=n/2-t.offsetHeight/2;o<10&&(o=10);let r=i/2-t.offsetWidth/2;r<0&&(r=0),t.style.left=a(r),t.style.top=a(o)};(()=>{V.zIndex+=2,this.zIndex=V.zIndex;let a=Q.createClassedDiv("dialog-cl");Q.addClasses(a,t.addClass),this.div=a,a.style.zIndex=this.zIndex,document.querySelector("body").appendChild(a),s(a);let l=a;t.form&&(o=document.createElement("form"),a.appendChild(o),l=o),new X(this,l),e=new W(this,l),!1!==t.buttons&&(n=new Y(this,l)),i=new J(this),c(a,t.parent),document.addEventListener("keydown",r,!0)})(),this.addContent=function(t){Q.addContent(e.div,t)},this.close=function(){i.remove(),this.div.parentNode.removeChild(this.div),document.removeEventListener("keydown",r,!0)},this.default=function(){null!==n&&n.default()}};V.zIndex=1e4;const G=V;let K=function(t,e,i,n,o){let r=[{contents:"Ok",click:function(t){void 0!==n&&n(),t.close()},focus:!0}];i===K.OKCANCEL&&(r=[{contents:"Ok",click:function(t){void 0!==n&&n(),t.close()},focus:!0},{contents:"Cancel",click:function(t){void 0!==o&&o(),t.close()}}]);new G({title:t,content:'<div class="message-cl"><p>'+e+"</p></div>",buttons:r})};K.OK=0,K.OKCANCEL=1;const Z=K;i(627),i(307);G.MessageBox=Z;const $=G;var tt=function(t){this.classes=void 0!==t?"cirsim "+t:"cirsim",this.buttonOk="Ok",this.buttonCancel="Cancel",this.resize="none;",this.titleBarButtons=null};tt.prototype.contents=function(t,e){this.html=t,this.title=e},tt.prototype.open=function(){var t=this,e=document.createElement("form"),i=U.createClassedDiv("cirsim-dlg-content");e.appendChild(i);var n="".concat(this.html,'<p class="error"></p>\n<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">');i.innerHTML=n,this.element=i;var o=[];null!==this.buttonOk&&o.push({contents:"Ok",click:function(e){t.ok()},focus:!0,class:"cs-ok"}),null!==this.buttonCancel&&o.push({contents:"Cancel",click:function(t){t.close()},class:"cs-cancel"});var r=new $({addClass:this.classes,title:this.title,content:e,buttons:o,resize:this.resize,titleBarButtons:this.titleBarButtons});this.dialog=r,this.onOpen(),this.close=function(){r.close()},e.addEventListener("submit",(function(e){e.preventDefault(),t.ok()})),this.buttonOk=function(){return this.dialog.div.querySelector("button.cs-ok")}},tt.prototype.ok=function(){this.close()},tt.prototype.error=function(t){void 0!==t&&(this.element.querySelector(".error").innerHTML=t)},tt.prototype.cancel=function(){},tt.prototype.onOpen=function(){},tt.prototype.sanitize=function(t){return H().sanitize(t)},tt.prototype.uniqueId=function(){return R.uniqueName()};var et=function(t,e){var i=this;tt.call(this,"component"),this.resize="both";var n=null,o="",r=function(){},s=function(){return null},a=function(){return null};this.open=function(){var s="";"help"in t.constructor&&(s+='<a class="helper">help</a>'),"description"in t.constructor&&(s+='<div class="description">',s+=t.constructor.description+"</div>");var a="";if(null!==t.naming)a=t.naming;else if(null!==t.prefix)for(var c=1;;c++){if(a=t.prefix+c,null===t.circuit.getComponentByNaming(a))break}var l="";null!==t.prefix&&(l+='<div class="control1 center gap"><label for="'+(n=R.uniqueName())+'">Name: </label><input type="text" name="'+n+'" id="'+n+'" value="'+a+'" spellcheck="false" class="compname text ui-widget-content ui-corner-all"></div>'),l+=o+s,i.contents(l,"Cirsim Component Properties"),tt.prototype.open.call(i),r(),null!==n&&document.getElementById(n).select();var u=i.element.querySelector("a.helper");null!==u&&u.addEventListener("click",(function(i){i.preventDefault();var n=t.constructor.help;e.menu.helpMenu.componentHelp(n)}))},this.ok=function(){var o="";if(null!==t.prefix){var r=document.getElementById(n);if(0!==(o=r.value.replace(/^\s+|\s+$/gm,"")).length){var c=t.circuit.getComponentByNaming(o);if(null!==c&&c!==t)return U.addClass(r,"cirsim-error"),void i.error("Name already exists")}U.removeClass(r,"cirsim-error"),o=i.sanitize(o)}var l=s();null===l?(e.backup(),null!==t.prefix&&(t.naming=o.length>0?o:null),a(),i.close(),e.currentView().draw()):i.error(l)},this.extra=function(t,e,i){o=t,s=e,a=i},this.extraCreate=function(t){r=t}};function it(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!i){if(Array.isArray(t)||(i=function(t,e){if(!t)return;if("string"==typeof t)return nt(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return nt(t,e)}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},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 r,s=!0,a=!1;return{s:function(){i=i.call(t)},n:function(){var t=i.next();return s=t.done,t},e:function(t){a=!0,r=t},f:function(){try{s||null==i.return||i.return()}finally{if(a)throw r}}}}function nt(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}(et.prototype=Object.create(tt.prototype)).constructor=et;var ot=function(){A.call(this);var t=null;Object.defineProperty(this,"circuit",{get:function(){return t},set:function(e){t=e}}),this.height=10,this.width=10,this.prev=null,this.id="",this.circuit=null,this.naming=null,this.ins=[],this.outs=[]};(ot.prototype=Object.create(A.prototype)).constructor=ot,ot.prototype.prefix="U",ot.prototype.nameRequired=!1,ot.prototype.delay=11,ot.prototype.brand=function(){this.id="c"+ ++ot.maxId},ot.maxId=1e3,ot.prototype.copyFrom=function(t){this.height=t.height,this.width=t.width,this.prev=t.prev,this.naming=t.naming,this.id=t.id,t.prev=this,A.prototype.copyFrom.call(this,t);for(var e=0;e<this.ins.length;e++)this.ins[e].copyFrom(t.ins[e]);for(var i=0;i<this.outs.length;i++)this.outs[i].copyFrom(t.outs[i])},ot.prototype.drop=function(){this.x<this.width/2&&(this.x=this.width/2),this.y<this.height/2&&(this.y=this.height/2)},ot.prototype.grab=function(){A.prototype.grab.call(this),this.circuit.moveToFront(this)},ot.prototype.mouseUp=function(){},ot.prototype.added=function(t){if(this.circuit=t,null===this.naming&&this.nameRequired)for(var e=1;;e++){var i=void 0;if(i="*"===this.prefix.charAt(0)?e<=26?"ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(e-1):this.prefix.charAt(1)+(e-26):this.prefix+e,null===this.circuit.getComponentByNaming(i)){this.naming=i;break}}},ot.prototype.addIn=function(t,e,i,n){var o=new S(this,t,e,i,n);return o.index=this.ins.length,this.ins.push(o),o},ot.prototype.addOut=function(t,e,i,n,o){var r=new E(this,t,e,i,n,o);return r.index=this.outs.length,this.outs.push(r),r},ot.prototype.addOutInv=function(t,e,i,n,o){var r=new O(this,t,e,i,n,o);return r.index=this.outs.length,this.outs.push(r),r},ot.prototype.touch=function(t,e){var i=this.touchOut(t,e);if(null!==i)return new M(i,null);if(null!==(i=this.touchIn(t,e)))return new M(null,i);if(t>=this.x-this.width/2&&t<=this.x+this.width/2&&e>=this.y-this.height/2&&e<=this.y+this.height/2)return this;for(var n=0;n<this.outs.length;n++){var o=this.outs[n].touchConnections(t,e);if(null!==o)return o}return null},ot.prototype.touchOut=function(t,e){for(var i=0;i<this.outs.length;i++)if(this.outs[i].touch(t,e))return this.outs[i];return null},ot.prototype.touchIn=function(t,e){for(var i=0;i<this.ins.length;i++)if(this.ins[i].touch(t,e))return this.ins[i];return null},ot.prototype.inRect=function(t,e){t.contains(this.x,this.y)&&e.push(this),this.outs.forEach((function(i){i.selectRect(t,e)}))},ot.prototype.delete=function(){for(var t=0;t<this.ins.length;t++)this.ins[t].clear();for(t=0;t<this.outs.length;t++)this.outs[t].clear();this.circuit.delete(this)},ot.prototype.bounds=function(){var t,e=new k(this.x-this.width/2,this.y-this.height/2,this.x+this.width/2,this.y+this.height/2),i=it(this.ins);try{for(i.s();!(t=i.n()).done;){var n=t.value;e.expand(n.bounds())}}catch(t){i.e(t)}finally{i.f()}var o,r=it(this.outs);try{for(r.s();!(o=r.n()).done;){var s=o.value;e.expand(s.bounds())}}catch(t){r.e(t)}finally{r.f()}return e},ot.prototype.draw=function(t,e){this.selectStyle(t,e),this.drawBox(t),this.drawName(t,0,3),this.drawIO(t,e)},ot.prototype.drawIO=function(t,e){for(var i=0;i<this.ins.length;i++)this.selectStyle(t,e),this.ins[i].draw(t,e);for(i=0;i<this.outs.length;i++)this.selectStyle(t,e),this.outs[i].draw(t,e)},ot.prototype.save=function(){var t=this.constructor.type,e=this.naming;return null!==e&&(e=e.replace(/'/g,"`")),{id:this.id,x:this.x,y:this.y,name:e,type:t}},ot.prototype.load=function(t){this.id=this.sanitize(t.id);var e=+this.id.substr(1);e>ot.maxId&&(ot.maxId=e),this.x=+t.x,this.y=+t.y,this.moveX=this.x,this.moveY=this.y;var i=t.name;this.naming=null!==i?this.sanitize(i).replace(/`/g,"'"):null},ot.prototype.saveConnections=function(){for(var t=[],e=0;e<this.outs.length;e++)for(var i=this.outs[e],n=0;n<i.to.length;n++){var o=i.to[n].save();null!==o&&t.push(o)}return t},ot.prototype.properties=function(t){new et(this,t).open()},ot.prototype.advance=function(t){return!1},ot.prototype.pending=function(){for(var t=.1*this.delay,e=[],i=0;i<this.ins.length;i++)e.push(this.ins[i].value);null!==this.circuit.circuits&&this.circuit.circuits.simulation.queue(this,t,e)},ot.prototype.getSimulation=function(){return null!==this.circuit?this.circuit.circuits.simulation:null},ot.prototype.getDelay=function(){return this.delay},ot.prototype.compute=function(t){},ot.prototype.newTab=function(){},ot.prototype.drawName=function(t,e,i,n){null!==this.naming&&(t.beginPath(),t.font=void 0!==n?n:"14px Times",t.textAlign="center",t.fillText(this.naming,this.x+e,this.y+i),t.stroke())},ot.prototype.drawText=function(t,e,i,n,o){t.beginPath(),t.font=void 0!==o?o:"14px Times",t.textAlign="center",t.fillText(e,this.x+i,this.y+n),t.stroke()},ot.prototype.drawBox=function(t,e){if("none"!==e){var i=t.fillStyle;t.fillStyle=void 0!==e?e:"#ffffff",t.fillRect(this.x-this.width/2-.5,this.y-this.height/2-.5,this.width,this.height),t.fillStyle=i}t.beginPath(),t.rect(this.x-this.width/2-.5,this.y-this.height/2-.5,this.width,this.height),t.stroke()},ot.prototype.drawTrap=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=20);var n=this.x-this.width/2-.5,o=this.x+this.width/2+.5,r=this.y-this.height/2-.5,s=this.y+this.height/2+.5;t.fillStyle="#ffffff",t.beginPath(),t.moveTo(n,r+e),t.lineTo(n,s-e),t.lineTo(o,s-i),t.lineTo(o,r+i),t.lineTo(n,r+e),t.fill(),t.beginPath(),t.moveTo(n,r+e),t.lineTo(n,s-e),t.lineTo(o,s-i),t.lineTo(o,r+i),t.lineTo(n,r+e),t.stroke()},ot.prototype.command=function(t){if(!("string"==typeof t||t instanceof String)||"type:"!==t.substr(0,5))return null;var e=t.substr(5);if(e!==this.constructor.type){var i=this.circuit.circuits.model.main.components.get(e);return i=null!==i?i.label:e,{ok:!1,msg:"Component "+this.naming+" should be type <strong>"+i+"</strong> but is <strong>"+this.constructor.label+"</strong>"}}return{ok:!0}},ot.prototype.setAsString=function(t){},ot.prototype.testAsString=function(t,e){console.log(t)},ot.prototype.jaggedLine=function(t,e,i,n,o,r){var s=Math.round(e+(n-e)*r)+.5;i+=.5,o+=.5,t.moveTo(e,i),t.lineTo(s,i),t.lineTo(s,o),t.lineTo(n,o),t.stroke()},ot.prototype.sanitize=function(t){return H().sanitize(t)},ot.prototype.update=function(){};var rt=function(t,e){var i=e.options;this.html=function(){var t="",e=i.getAPI("save"),o=i.getAPI("open");if(null!==o&&void 0===o.name&&(t+='<li><a class="file-open"><span class="icons-cl icons-cl-folder-open"></span>Open...</a></li>'),null!==e&&(t+='<li><a class="file-save"><span class="icons-cl icons-cl-disk"></span>Save</a></li>'),null!==e&&void 0===e.name&&(t+='<li><a class="file-saveas"><span class="icons-cl icons-cl-disk"></span>Save As...</a></li>'),i.loadMenu.length>0){t+=n(t);for(var r=0;r<i.loadMenu.length;r++){t+='<li><a class="cs-file-load-menu" data-index="'+r+'"><span class="icons-cl icons-cl-arrowthickstop-1-n"></span>'+i.loadMenu[r].name+"</a></li>"}}return"none"!==i.export&&(t+=n(t),"both"!==i.export&&"import"!==i.export||(t+='<li><a class="cs-file-import"><span class="icons-cl icons-cl-arrowthickstop-1-n"></span>Import</a></li>'),"both"!==i.export&&"export"!==i.export||(t+='<li><a class="cs-file-export"><span class="icons-cl icons-cl-arrowthickstop-1-s"></span>Export</a></li>')),i.exportPNG&&(t+='<li><a class="cs-file-export-png"><span class="icons-cl icons-cl-arrowthickstop-1-s"></span>Export PNG</a></li>'),i.imports.length>0&&(t+=n(t)+'<li><a class="cs-file-import-tab"><span class="icons-cl icons-cl-arrowthickstop-1-s"></span>Import Tab</a></li>'),null!==i.exit&&(t.length>0&&(t+='<li class="menu-divider"> </li>'),t+='<li><a class="file-exit">Exit</a></li>'),""!==t?'<li><a>File</a><ul class="file-menu">'+t+"</ul></li>":""};var n=function(t){return t.length>0?'<li class="menu-divider"> </li>':""};this.activate=function(){t.click(".cs-file-import",(function(){e.import()})),t.click(".cs-file-export",(function(){e.export()})),t.click(".cs-file-load-menu",(function(t){var n=t.target.dataset.index;e.load(i.loadMenu[n].json)})),t.click(".cs-file-export-png",(function(t){e.currentView().exportPNG()})),t.click(".file-saveas",(function(){e.saveAs()})),t.click(".file-save",(function(){e.save()})),t.click(".file-open",(function(){e.open()})),t.click(".cs-file-import-tab",(function(){e.importTab()})),t.click(".file-exit",(function(){null!==i.exit&&(window.location.href=i.exit)}))},this.opening=function(){var i=!1,n=e.currentView().circuit;if(null!==n)for(var o=n.name,r=0;r<e.options.imports.length;r++){if(e.options.imports[r].into===o){i=!0;break}}t.enable(".cs-file-import-tab",i)}},st=function(t,e){this.html=function(){return'<li><a>Edit</a><ul class="edit-menu"><li><a class="edit-undo"><span class="icons-cl icons-cl-arrowreturnthick-1-w"></span>Undo</a></li><li><a class="edit-delete"><span class="icons-cl icons-cl-trash"></span>Delete</a></li><li class="menu-divider"> </li><li><a class="edit-properties">Properties</a></li></ul></li>'},this.activate=function(){t.click(".edit-delete",(function(t){console.log("delete"),e.backup(),e.currentView().delete()})),t.click(".edit-undo",(function(t){e.undo()})),t.click(".edit-properties",(function(t){1===e.currentView().selection.selection.length&&e.currentView().selection.selection[0]instanceof ot&&e.currentView().selection.selection[0].properties(e)})),document.addEventListener("keydown",(function(i){"Delete"===i.key?(t.closeAll(),e.backup(),e.currentView().delete()):"z"!==i.key||!i.ctrlKey||i.altKey||i.shiftKey||(t.closeAll(),e.undo())}))}},at=function(t){tt.call(this);var e;this.open=function(){e=this.uniqueId();var t='<div class="control1 center"><label for="'.concat(e,'">New tab name: </label>\n<input class="tabname" type="text" id="').concat(e,'" spellcheck="false"></div>\n<p>Enter the name for the new tab.</p>');this.contents(t,"New Tab"),tt.prototype.open.call(this),document.getElementById(e).select()},this.ok=function(){var i=document.getElementById(e).value;if(i=i.replace(/^\s+|\s+$/gm,""),(i=this.sanitize(i)).length<1)return this.error("Must provide a tab name"),void document.getElementById(e).select();if(i.length>8)return this.error("Name must be no longer than 8 characters"),void document.getElementById(e).select();var n=t.validateName(i);if(null!==n)return this.error(n),void document.getElementById(e).select();t.add(i),this.close()}};(at.prototype=Object.create(tt.prototype)).constructor=at;var ct=function(t,e,i){tt.call(this),this.open=function(i,n){this.contents(e,t),!0!==n&&(this.buttonCancel=null),this.ok=function(){void 0!==i&&i(),this.close()},tt.prototype.open.call(this)}};(ct.prototype=Object.create(tt.prototype)).constructor=ct;var lt=function(t){tt.call(this);var e;this.open=function(){var i=t.currentCircuit(),n=i.getName(),o=i.stats();e=this.uniqueId();var r='\n<div class="control1 center"><label for="'.concat(e,'">Tab name: </label>\n<input class="tabname" type="text" id="').concat(e,'" value="').concat(n,'" spellcheck="false" ').concat("main"===n?"disabled":"","></div>");r+="main"===n?'<p class="center"><em>The main tab cannot be renamed.</em></p>':"<p>This page presents information for the currently selected tab. Enter a new name to rename the tab.</p>",r+="<table>\n<tr><th>Property</th><th>Value</th></tr>\n<tr><td>Components</td><td>".concat(o.numComponents,"</td></tr>\n<tr><td>Connections</td><td>").concat(o.numConnections,"</td></tr>\n<tr><td>Width</td><td>").concat(o.width," pixels</td></tr>\n<tr><td>Height</td><td>").concat(o.height," pixels</td></tr>\n</table>"),this.contents(r,"New Tab"),tt.prototype.open.call(this),document.getElementById(e).select()},this.ok=function(){var i=t.currentCircuit();if("main"!==i.getName()){var n=document.getElementById(e).value;if(n=n.replace(/^\s+|\s+$/gm,""),(n=this.sanitize(n)).length<1)return this.error("Must provide a tab name"),void document.getElementById(e).select();if(n.length>8)return this.error("Name must be no longer than 8 characters"),void document.getElementById(e).select();var o=t.validateName(n,i);if(null!==o)return this.error(o),void document.getElementById(e).select();n!==i.getName()&&t.rename(n),this.close()}else this.close()}};(lt.prototype=Object.create(tt.prototype)).constructor=lt;var ut=function(t,e){this.html=function(){return'<li><a>Tabs</a>\n<ul class="tabs-menu">\n<li><a class="tabs-properties"><span class="icons-cl icons-cl-wrench"></span>Properties...</a></li>\n<li><a class="tabs-add"><span class="icons-cl icons-cl-play"></span>Add...</a></li>\n<li><a class="tabs-delete"><span class="icons-cl icons-cl-close"></span>Delete...</a></li>\n<li><a class="tabs-left"><span class="icons-cl icons-cl-arrowthick-1-w"></span>Move Left</a></li>\n<li><a class="tabs-right"><span class="icons-cl icons-cl-arrowthick-1-e"></span>Move Right</a></li>\n</ul>\n</li>'};this.activate=function(){t.click(".tabs-add",(function(){new at(e.tabs).open()})),t.click(".tabs-delete",(function(){var t;null!==(t=e.tabs.currentCircuit())&&new ct("Are you sure?",'<p class="large">Are you sure you want to delete the tab <em>'+t.getName()+"</em>?</p>",200).open((function(){e.tabs.delActive()}),!0)})),t.click(".tabs-properties",(function(){new lt(e.tabs).open()})),t.click(".tabs-left",(function(){var t=e.tabs;e.model.circuits.moveLeft(t.active)&&t.sync()})),t.click(".tabs-right",(function(){var t=e.tabs;e.model.circuits.moveRight(t.active)&&t.sync()}))},this.opening=funct