Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.8
/*! | ||
* rete v1.0.0-alpha.7 | ||
* rete v1.0.0-alpha.8 | ||
* (c) 2018 Ni55aN License | ||
@@ -4,0 +4,0 @@ * Released under the MIT license. |
/*! | ||
* rete v1.0.0-alpha.7 | ||
* rete v1.0.0-alpha.8 | ||
* (c) 2018 Ni55aN License | ||
* Released under the MIT license. | ||
*/ | ||
!function(t){"use strict";var c,n=Object.prototype,s=n.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},o=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",i=e.toStringTag||"@@toStringTag",a="object"==typeof module,u=t.regeneratorRuntime;if(u)a&&(module.exports=u);else{(u=t.regeneratorRuntime=a?module.exports:{}).wrap=w;var l="suspendedStart",h="suspendedYield",p="executing",d="completed",v={},f={};f[o]=function(){return this};var m=Object.getPrototypeOf,y=m&&m(m(C([])));y&&y!==n&&s.call(y,o)&&(f=y);var g=x.prototype=k.prototype=Object.create(f);E.prototype=g.constructor=x,x.constructor=E,x[i]=E.displayName="GeneratorFunction",u.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return!!n&&(n===E||"GeneratorFunction"===(n.displayName||n.name))},u.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,i in t||(t[i]="GeneratorFunction")),t.prototype=Object.create(g),t},u.awrap=function(t){return{__await:t}},O(j.prototype),j.prototype[r]=function(){return this},u.AsyncIterator=j,u.async=function(t,n,e,r){var o=new j(w(t,n,e,r));return u.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},O(g),g[i]="Generator",g[o]=function(){return this},g.toString=function(){return"[object Generator]"},u.keys=function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},u.values=C,N.prototype={constructor:N,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(A),!t)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=c),!!n}for(var n=this.tryEntries.length-1;0<=n;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),u=s.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,n){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=n&&n<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=n,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(t,n){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&n&&(this.next=n),v},finish:function(t){for(var n=this.tryEntries.length-1;0<=n;--n){var e=this.tryEntries[n];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),v}},catch:function(t){for(var n=this.tryEntries.length-1;0<=n;--n){var e=this.tryEntries[n];if(e.tryLoc===t){var r=e.completion;if("throw"===r.type){var o=r.arg;A(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,e){return this.delegate={iterator:C(t),resultName:n,nextLoc:e},"next"===this.method&&(this.arg=c),v}}}function w(t,n,e,r){var i,a,u,c,o=n&&n.prototype instanceof k?n:k,s=Object.create(o.prototype),f=new N(r||[]);return s._invoke=(i=t,a=e,u=f,c=l,function(t,n){if(c===p)throw new Error("Generator is already running");if(c===d){if("throw"===t)throw n;return V()}for(u.method=t,u.arg=n;;){var e=u.delegate;if(e){var r=_(e,u);if(r){if(r===v)continue;return r}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(c===l)throw c=d,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);c=p;var o=b(i,a,u);if("normal"===o.type){if(c=u.done?d:h,o.arg===v)continue;return{value:o.arg,done:u.done}}"throw"===o.type&&(c=d,u.method="throw",u.arg=o.arg)}}),s}function b(t,n,e){try{return{type:"normal",arg:t.call(n,e)}}catch(t){return{type:"throw",arg:t}}}function k(){}function E(){}function x(){}function O(t){["next","throw","return"].forEach(function(n){t[n]=function(t){return this._invoke(n,t)}})}function j(c){var n;this._invoke=function(e,r){function t(){return new Promise(function(t,n){!function n(t,e,r,o){var i=b(c[t],c,e);if("throw"!==i.type){var a=i.arg,u=a.value;return u&&"object"==typeof u&&s.call(u,"__await")?Promise.resolve(u.__await).then(function(t){n("next",t,r,o)},function(t){n("throw",t,r,o)}):Promise.resolve(u).then(function(t){a.value=t,r(a)},o)}o(i.arg)}(e,r,t,n)})}return n=n?n.then(t,t):t()}}function _(t,n){var e=t.iterator[n.method];if(e===c){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=c,_(t,n),"throw"===n.method))return v;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var r=b(e,t.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,v;var o=r.arg;return o?o.done?(n[t.resultName]=o.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=c),n.delegate=null,v):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function T(t){var n={tryLoc:t[0]};1 in t&&(n.catchLoc=t[1]),2 in t&&(n.finallyLoc=t[2],n.afterLoc=t[3]),this.tryEntries.push(n)}function A(t){var n=t.completion||{};n.type="normal",delete n.arg,t.completion=n}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function C(n){if(n){var t=n[o];if(t)return t.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length)){var e=-1,r=function t(){for(;++e<n.length;)if(s.call(n,e))return t.value=n[e],t.done=!1,t;return t.value=c,t.done=!0,t};return r.next=r}}return{next:V}}function V(){return{value:c,done:!0}}}(function(){return this}()||Function("return this")()),function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.Rete=n()}(this,function(){"use strict";var u="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},d=function(t){return function(){var u=t.apply(this,arguments);return new Promise(function(i,a){return function n(t,e){try{var r=u[t](e),o=r.value}catch(t){return void a(t)}if(!r.done)return Promise.resolve(o).then(function(t){n("next",t)},function(t){n("throw",t)});i(o)}("next")})}},p=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},v=function(){function r(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),t}}(),c=function(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t},e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},m=function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n)},y=function(t,n){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?t:n},s=function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,n){var e=[],r=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(e.push(a.value),!n||e.length!==n);r=!0);}catch(t){o=!0,i=t}finally{try{!r&&u.return&&u.return()}finally{if(o)throw i}}return e}(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},g=function(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);n<t.length;n++)e[n]=t[n];return e}return Array.from(t)},w=function(){function n(t){if(p(this,n),this.constructor===n)throw new TypeError("Can not construct abstract class.");this.name=t,this.data={},this.engine=null}return v(n,[{key:"worker",value:function(){}}]),n}(),r=function(){function t(){if(p(this,t),this.constructor===t)throw new TypeError("Can not construct abstract class.");this.data={},this.parent=null}return v(t,[{key:"getNode",value:function(){if(null===this.parent)throw new Error("Control isn't added to Node/Input");return this.parent instanceof E?this.parent:this.parent.node}},{key:"getData",value:function(t){return this.getNode().data[t]}},{key:"putData",value:function(t,n){this.getNode().data[t]=n}}]),t}(),a=function(){function e(t,n){p(this,e),this.output=t,this.input=n,this.data={},this.input.addConnection(this)}return v(e,[{key:"remove",value:function(){this.input.removeConnection(this),this.output.removeConnection(this)}}]),e}(),f=function(){function o(t,n,e,r){p(this,o),this.node=null,this.multipleConnections=r,this.connections=[],this.key=t,this.name=n,this.socket=e}return v(o,[{key:"removeConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+function n(e,r){void 0===r&&(r=0);r+=1;{if(null===e)return"null";if(void 0===e)return"void";if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return void 0===e?"undefined":u(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var o=n(e[0],r);return e.every(function(t){return n(t,r)===o})?o.trim()+"[]":"["+e.slice(0,15).map(function(t){return n(t,r)}).join(", ")+(15<=e.length?", ...":"")+"]"}return"Array"}var t=Object.keys(e);if(!t.length)return e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name:"Object";if(4<r)return"{...}";var i=" ".repeat(r-1),a=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+n(e[t],r)+";"}).join("\n "+i);return 15<=t.length&&(a+="\n "+i+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+i+a+"\n"+i+"}":"{\n "+i+a+"\n"+i+"}"}}(t));this.connections.splice(this.connections.indexOf(t),1)}},{key:"removeConnections",value:function(){var n=this;this.connections.map(function(t){return n.removeConnection(t)})}}]),o}();var l=function(){function e(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(p(this,e),"string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+h(t));this.name=t,this.data=n,this.compatible=[]}return v(e,[{key:"combineWith",value:function(t){if(!(t instanceof e))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+h(t));this.compatible.push(t)}},{key:"compatibleWith",value:function(t){if(!(t instanceof e))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+h(t));return this===t||this.compatible.includes(t)}}]),e}();function h(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=h(n[0],e);return n.every(function(t){return h(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return h(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+h(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var i=function(t){function i(t,n,e){var r=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(p(this,i),"string"!=typeof t)throw new TypeError('Value of argument "key" violates contract.\n\nExpected:\nstring\n\nGot:\n'+b(t));if("string"!=typeof n)throw new TypeError('Value of argument "title" violates contract.\n\nExpected:\nstring\n\nGot:\n'+b(n));if(!(e instanceof l))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+b(e));if("boolean"!=typeof r)throw new TypeError('Value of argument "multiConns" violates contract.\n\nExpected:\nboolean\n\nGot:\n'+b(r));var o=y(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t,n,e,r));return o.control=null,o}return m(i,f),v(i,[{key:"hasConnection",value:function(){return 0<this.connections.length}},{key:"addConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+b(t));if(!this.multipleConnections&&this.hasConnection())throw new Error("Multiple connections not allowed");this.connections.push(t)}},{key:"addControl",value:function(t){if(!(t instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+b(t));(this.control=t).parent=this}},{key:"showControl",value:function(){return!this.hasConnection()&&null!==this.control}},{key:"toJSON",value:function(){return{connections:this.connections.map(function(t){return{node:t.output.node.id,output:t.output.key,data:t.data}})}}}]),i}();function b(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=b(n[0],e);return n.every(function(t){return b(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return b(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+b(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var o=function(t){function o(t,n,e){var r=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];if(p(this,o),"string"!=typeof t)throw new TypeError('Value of argument "key" violates contract.\n\nExpected:\nstring\n\nGot:\n'+k(t));if("string"!=typeof n)throw new TypeError('Value of argument "title" violates contract.\n\nExpected:\nstring\n\nGot:\n'+k(n));if(!(e instanceof l))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+k(e));if("boolean"!=typeof r)throw new TypeError('Value of argument "multiConns" violates contract.\n\nExpected:\nboolean\n\nGot:\n'+k(r));return y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,e,r))}return m(o,f),v(o,[{key:"hasConnection",value:function(){return 0<this.connections.length}},{key:"connectTo",value:function(t){if(!(t instanceof i))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+k(t));if(!this.socket.compatibleWith(t.socket))throw new Error("Sockets not compatible");if(!t.multipleConnections&&t.hasConnection())throw new Error("Input already has one connection");if(!this.multipleConnections&&this.hasConnection())throw new Error("Output already has one connection");var n=new a(this,t);return this.connections.push(n),n}},{key:"connectedTo",value:function(n){if(!(n instanceof i))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+k(n));return this.connections.some(function(t){return t.input===n})}},{key:"toJSON",value:function(){return{connections:this.connections.map(function(t){return{node:t.input.node.id,input:t.input.key,data:t.data}})}}}]),o}();function k(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=k(n[0],e);return n.every(function(t){return k(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return k(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+k(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var E=function(){function e(t){if(p(this,e),"string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+x(t));this.name=t,this.id=e.incrementId(),this.position=[0,0],this.inputs=[],this.outputs=[],this.controls=[],this.data={},this.meta={}}return v(e,[{key:"addControl",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.controls.length;if(!(t instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+x(t));if(!(null==n||"number"==typeof n&&!isNaN(n)&&0<=n&&n<=255&&n===Math.floor(n)))throw new TypeError('Value of argument "index" violates contract.\n\nExpected:\n?uint8\n\nGot:\n'+x(n));return(t.parent=this).controls.splice(n,0,t),this}},{key:"removeControl",value:function(t){if(!(t instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+x(t));t.parent=null,this.controls.splice(this.controls.indexOf(t),1)}},{key:"addInput",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.inputs.length;if(!(t instanceof i))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+x(t));if(!(null==n||"number"==typeof n&&!isNaN(n)&&0<=n&&n<=255&&n===Math.floor(n)))throw new TypeError('Value of argument "index" violates contract.\n\nExpected:\n?uint8\n\nGot:\n'+x(n));if(null!==t.node)throw new Error("Input has already been added to the node");return(t.node=this).inputs.splice(n,0,t),this}},{key:"removeInput",value:function(t){if(!(t instanceof i))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+x(t));t.removeConnections(),t.node=null,this.inputs.splice(this.inputs.indexOf(t),1)}},{key:"addOutput",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.outputs.length;if(!(t instanceof o))throw new TypeError('Value of argument "output" violates contract.\n\nExpected:\nOutput\n\nGot:\n'+x(t));if(!(null==n||"number"==typeof n&&!isNaN(n)&&0<=n&&n<=255&&n===Math.floor(n)))throw new TypeError('Value of argument "index" violates contract.\n\nExpected:\n?uint8\n\nGot:\n'+x(n));if(null!==t.node)throw new Error("Output has already been added to the node");return(t.node=this).outputs.splice(n,0,t),this}},{key:"removeOutput",value:function(t){if(!(t instanceof o))throw new TypeError('Value of argument "output" violates contract.\n\nExpected:\nOutput\n\nGot:\n'+x(t));t.removeConnections(),t.node=null,this.outputs.splice(this.outputs.indexOf(t),1)}},{key:"getConnections",value:function(){return[].concat(g(this.inputs),g(this.outputs)).reduce(function(t,n){return[].concat(g(t),g(n.connections))},[])}},{key:"inputsWithVisibleControl",value:function(){return this.inputs.filter(function(t){return t.showControl()})}},{key:"toJSON",value:function(){return{id:this.id,data:this.data,inputs:this.inputs.reduce(function(t,n){return t[n.key]=n.toJSON(),t},{}),outputs:this.outputs.reduce(function(t,n){return t[n.key]=n.toJSON(),t},{}),position:this.position,name:this.name}}}],[{key:"incrementId",value:function(){return this.latestId?this.latestId++:this.latestId=1,this.latestId}},{key:"fromJSON",value:function(t){if(!(t instanceof Object))throw new TypeError('Value of argument "json" violates contract.\n\nExpected:\nObject\n\nGot:\n'+x(t));var n=new e(t.name);return n.id=t.id,n.data=t.data,n.position=t.position,n.name=t.name,e.latestId=Math.max(n.id,e.latestId),n}}]),e}();function x(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=x(n[0],e);return n.every(function(t){return x(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return x(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+x(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var O=function(t){function e(t){p(this,e);var n=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));if(n.constructor===e)throw new TypeError("Can not construct abstract class.");return n.editor=null,n.data={},n}var n,r,o;return m(e,w),v(e,[{key:"builder",value:(o=d(regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:case"end":return t.stop()}},t,this)})),function(){return o.apply(this,arguments)})},{key:"created",value:function(){}},{key:"destroyed",value:function(){}},{key:"build",value:(r=d(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n instanceof E){t.next=2;break}throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+j(n));case 2:return t.next=4,this.builder(n);case 4:return t.abrupt("return",n);case 5:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"createNode",value:(n=d(regeneratorRuntime.mark(function t(){var n,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(n=new E(this.name)).data=e,t.next=4,this.build(n);case 4:return t.abrupt("return",n);case 5:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})}]),e}();function j(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=j(n[0],e);return n.every(function(t){return j(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return j(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+j(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var _=function t(n){p(this,t),this.handlers=e({warn:[console.warn],error:[console.error]},n)},T=function(){function n(t){if(p(this,n),!(t instanceof _||t instanceof n))throw new TypeError('Value of argument "events" violates contract.\n\nExpected:\nEvents | Emitter\n\nGot:\n'+A(t));this.events=t instanceof n?t.events:t.handlers,this.silent=!1}return v(n,[{key:"on",value:function(t,n){var e=this;if("string"!=typeof t)throw new TypeError('Value of argument "names" violates contract.\n\nExpected:\nstring\n\nGot:\n'+A(t));if("function"!=typeof n)throw new TypeError('Value of argument "handler" violates contract.\n\nExpected:\n() => {}\n\nGot:\n'+A(n));return t.split(" ").forEach(function(t){if(!e.events[t])throw new Error("The event "+t+" does not exist");e.events[t].push(n)}),this}},{key:"trigger",value:function(t,e){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+A(t));if(!(t in this.events))throw new Error("The event "+t+" cannot be triggered");return this.events[t].reduce(function(t,n){return!1!==n(e)&&t},!0)}}]),n}();function A(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=A(n[0],e);return n.every(function(t){return A(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return A(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+A(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var N=function(){function t(){p(this,t)}return v(t,null,[{key:"isValidData",value:function(t){return"string"==typeof t.id&&this.isValidId(t.id)&&t.nodes instanceof Object&&!(t.nodes instanceof Array)}},{key:"isValidId",value:function(t){return/^[\w-]{3,}@[0-9]+\.[0-9]+\.[0-9]+$/.test(t)}},{key:"validate",value:function(t,n){var e="",r=t.split("@"),o=n.id.split("@");return this.isValidData(n)||(e+="Data is not suitable. "),t!==n.id&&(e+="IDs not equal. "),r[0]!==o[0]&&(e+="Names don't match. "),r[1]!==o[1]&&(e+="Versions don't match"),{success:""===e,msg:e}}}]),t}(),C=function(t){function r(t,n){p(this,r);var e=y(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,n));if(!N.isValidId(t))throw new Error("ID should be valid to name@0.1.0 format");return e.id=t,e}return m(r,T),v(r,[{key:"use",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};t.install(this,n)}}]),r}(),V=function(t){function n(){return p(this,n),y(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,{componentregister:[]}))}return m(n,_),n}(),G=0,S=1,L=2,t=function(t){function e(t){if(p(this,e),"string"!=typeof t)throw new TypeError('Value of argument "id" violates contract.\n\nExpected:\nstring\n\nGot:\n'+P(t));var n=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,new V));return n.components=[],n.args=[],n.data=null,n.state=G,n.onAbort=function(){},n}var n,r,o,i,a,u,c,s,f,l,h;return m(e,C),v(e,[{key:"clone",value:function(){var n=new e(this.id);return this.components.map(function(t){return n.register(t)}),n}},{key:"register",value:function(t){if(!(t instanceof w))throw new TypeError('Value of argument "component" violates contract.\n\nExpected:\nComponent\n\nGot:\n'+P(t));this.components.push(t),this.trigger("componentregister",t)}},{key:"throwError",value:(h=d(regeneratorRuntime.mark(function t(n){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.abort();case 2:return this.trigger("error",{message:n,data:e}),this.processDone(),t.abrupt("return","error");case 5:case"end":return t.stop()}},t,this)})),function(t){return h.apply(this,arguments)})},{key:"extractInputNodes",value:function(e,r){return Object.keys(e.inputs).reduce(function(t,n){return[].concat(g(t),g((e.inputs[n].connections||[]).reduce(function(t,n){return[].concat(g(t),[r[n.node]])},[])))},[])}},{key:"detectRecursions",value:function(o){var i=this,t=Object.keys(o).map(function(t){return o[t]});return t.map(function(t){return function t(n,e){if(e.some(function(t){return t===n}))return n;for(var r=0;r<e.length;r++)if(t(n,i.extractInputNodes(e[r],o)))return n;return null}(t,i.extractInputNodes(t,o))}).filter(function(t){return null!==t})}},{key:"processStart",value:function(){return this.state===G?(this.state=S,!0):(this.state===L||console.warn("The process is busy and has not been restarted.\n Use abort() to force it to complete"),!1)}},{key:"processDone",value:function(){var t=this.state!==L;return this.state=G,t||(this.onAbort(),this.onAbort=function(){}),t}},{key:"abort",value:(l=d(regeneratorRuntime.mark(function t(){var n=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){n.state===S?(n.state=L,n.onAbort=t):n.state===L?(n.onAbort(),n.onAbort=t):t()}));case 1:case"end":return t.stop()}},t,this)})),function(){return l.apply(this,arguments)})},{key:"lock",value:(f=d(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){n.unlockPool=n.unlockPool||[],n.busy&&!n.outputData?n.unlockPool.push(t):t(),n.busy=!0}));case 1:case"end":return t.stop()}},t,this)})),function(t){return f.apply(this,arguments)})},{key:"unlock",value:function(t){t.unlockPool.forEach(function(t){return t()}),t.unlockPool=[],t.busy=!1}},{key:"extractInputData",value:(s=d(regeneratorRuntime.mark(function t(n){var e,r,o,i,a,u,c,s,f,l,h,p=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e={},(c=Object.keys(n.inputs))&&("function"==typeof c[Symbol.iterator]||Array.isArray(c))){t.next=4;break}throw new TypeError("Expected _Object$keys to be iterable, got "+P(c));case 4:o=!(r=!0),i=void 0,t.prev=7,a=c[Symbol.iterator]();case 9:if(r=(u=a.next()).done){t.next=20;break}return s=u.value,f=n.inputs[s],l=f.connections,t.next=15,Promise.all(l.map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=p.data.nodes[n.node],t.next=3,p.processNode(e);case 3:if(r=t.sent){t.next=8;break}p.abort(),t.next=9;break;case 8:return t.abrupt("return",r[n.output]);case 9:case"end":return t.stop()}},t,p)}));return function(t){return n.apply(this,arguments)}}()));case 15:h=t.sent,e[s]=h;case 17:r=!0,t.next=9;break;case 20:t.next=26;break;case 22:t.prev=22,t.t0=t.catch(7),o=!0,i=t.t0;case 26:t.prev=26,t.prev=27,!r&&a.return&&a.return();case 29:if(t.prev=29,!o){t.next=32;break}throw i;case 32:return t.finish(29);case 33:return t.finish(26);case 34:return t.abrupt("return",e);case 35:case"end":return t.stop()}},t,this,[[7,22,26,34],[27,,29,33]])})),function(t){return s.apply(this,arguments)})},{key:"processWorker",value:(c=d(regeneratorRuntime.mark(function t(n){var e,r,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.extractInputData(n);case 2:return e=t.sent,r=this.components.find(function(t){return t.name===n.name}),o={},t.prev=5,t.next=8,r.worker.apply(r,[n,e,o].concat(g(this.args)));case 8:t.next=14;break;case 10:t.prev=10,t.t0=t.catch(5),this.abort(),this.trigger("warn",t.t0);case 14:return t.abrupt("return",o);case 15:case"end":return t.stop()}},t,this,[[5,10]])})),function(t){return c.apply(this,arguments)})},{key:"processNode",value:(u=d(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==L&&n){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,this.lock(n);case 4:return n.outputData||(n.outputData=this.processWorker(n)),this.unlock(n),t.abrupt("return",n.outputData);case 7:case"end":return t.stop()}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"forwardProcess",value:(a=d(regeneratorRuntime.mark(function t(r){var o=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==L){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,Promise.all(Object.keys(r.outputs).map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=r.outputs[n],t.next=3,Promise.all(e.connections.map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.data.nodes[n.node],t.next=3,o.processNode(e);case 3:return t.next=5,o.forwardProcess(e);case 5:case"end":return t.stop()}},t,o)}));return function(t){return n.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,o)}));return function(t){return n.apply(this,arguments)}}()));case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}},t,this)})),function(t){return a.apply(this,arguments)})},{key:"copy",value:function(n){return(n=Object.assign({},n)).nodes=Object.assign({},n.nodes),Object.keys(n.nodes).forEach(function(t){n.nodes[t]=Object.assign({},n.nodes[t])}),n}},{key:"validate",value:(i=d(regeneratorRuntime.mark(function t(n){var e,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((e=N.validate(this.id,n)).success){t.next=5;break}return t.next=4,this.throwError(e.msg);case 4:return t.abrupt("return",t.sent);case 5:if(!(0<(r=this.detectRecursions(n.nodes)).length)){t.next=10;break}return t.next=9,this.throwError("Recursion detected",r);case 9:return t.abrupt("return",t.sent);case 10:return t.abrupt("return",!0);case 11:case"end":return t.stop()}},t,this)})),function(t){return i.apply(this,arguments)})},{key:"processStartNode",value:(o=d(regeneratorRuntime.mark(function t(n){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!n){t.next=10;break}if(e=this.data.nodes[n]){t.next=6;break}return t.next=5,this.throwError("Node with such id not found");case 5:return t.abrupt("return",t.sent);case 6:return t.next=8,this.processNode(e);case 8:return t.next=10,this.forwardProcess(e);case 10:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"processUnreachable",value:(r=d(regeneratorRuntime.mark(function t(){var n,e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=regeneratorRuntime.keys(this.data.nodes);case 1:if((t.t1=t.t0()).done){t.next=11;break}if(n=t.t1.value,void 0!==this.data.nodes[n].outputData){t.next=9;break}return e=this.data.nodes[n],t.next=7,this.processNode(e);case 7:return t.next=9,this.forwardProcess(e);case 9:t.next=1;break;case 11:case"end":return t.stop()}},t,this)})),function(){return r.apply(this,arguments)})},{key:"process",value:(n=d(regeneratorRuntime.mark(function t(n){for(var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length,o=Array(2<r?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n instanceof Object){t.next=2;break}throw new TypeError('Value of argument "data" violates contract.\n\nExpected:\nObject\n\nGot:\n'+P(n));case 2:if(null==e||"number"==typeof e){t.next=4;break}throw new TypeError('Value of argument "startId" violates contract.\n\nExpected:\n?number\n\nGot:\n'+P(e));case 4:if(this.processStart()){t.next=6;break}return t.abrupt("return");case 6:if(this.validate(n)){t.next=8;break}return t.abrupt("return");case 8:return this.data=this.copy(n),this.args=o,t.next=12,this.processStartNode(e);case 12:return t.next=14,this.processUnreachable();case 14:return t.abrupt("return",this.processDone()?"success":"aborted");case 15:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})}]),e}();function P(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=P(n[0],e);return n.every(function(t){return P(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return P(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+P(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var R=function(t){function n(){return p(this,n),y(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,{nodecreate:[],nodecreated:[],noderemove:[],noderemoved:[],connectioncreate:[],connectioncreated:[],connectionremove:[],connectionremoved:[],nodetranslate:[],nodetranslated:[],selectnode:[],nodeselect:[],nodeselected:[],rendernode:[],rendersocket:[],rendercontrol:[],renderconnection:[],componentregister:[],keydown:[],keyup:[],translate:[],translated:[],zoom:[],zoomed:[],click:[],mousemove:[],contextmenu:[],import:[],export:[],process:[]}))}return m(n,_),n}(),$=function(){function o(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:function(){},e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:function(){},r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:function(){};p(this,o),this.mouseStart=null,this.el=t,this.onTranslate=n,this.onStart=e,this.onDrag=r,this.initEvents(t)}return v(o,[{key:"initEvents",value:function(t){t.addEventListener("mousedown",this.down.bind(this)),window.addEventListener("mousemove",this.move.bind(this)),window.addEventListener("mouseup",this.up.bind(this)),t.addEventListener("touchstart",this.down.bind(this)),window.addEventListener("touchmove",this.move.bind(this),{passive:!1}),window.addEventListener("touchend",this.up.bind(this))}},{key:"getCoords",value:function(t){var n=t.touches?t.touches[0]:t;return[n.pageX,n.pageY]}},{key:"down",value:function(t){t.stopPropagation(),this.mouseStart=this.getCoords(t),this.onStart()}},{key:"move",value:function(t){if(this.mouseStart){t.preventDefault(),t.stopPropagation();var n=this.getCoords(t),e=s(n,2),r=e[0],o=e[1],i=[r-this.mouseStart[0],o-this.mouseStart[1]],a=this.el.getBoundingClientRect().width/this.el.offsetWidth;this.mouseStart=[r,o],this.onTranslate(i[0]/a,i[1]/a)}}},{key:"up",value:function(){this.mouseStart=null,this.onDrag()}}]),o}(),I=function(){function o(t,n,e,r){p(this,o),this.el=n,this.intensity=e,this.onzoom=r,this.distance=null,t.addEventListener("wheel",this.wheel.bind(this)),t.addEventListener("touchmove",this.move.bind(this)),t.addEventListener("touchend",this.end.bind(this)),t.addEventListener("touchcancel",this.end.bind(this))}return v(o,[{key:"wheel",value:function(t){t.preventDefault();var n=this.el.getBoundingClientRect(),e=(t.wheelDelta?t.wheelDelta/120:-t.deltaY/3)*this.intensity,r=(n.left-t.pageX)*e,o=(n.top-t.pageY)*e;this.onzoom(e,r,o)}},{key:"touches",value:function(t){var n=[t.touches[0].pageX,t.touches[0].pageY],e=n[0],r=n[1],o=[t.touches[1].pageX,t.touches[1].pageY],i=o[0],a=o[1];return{cx:(e+i)/2,cy:(r+a)/2,distance:Math.sqrt(Math.pow(e-i,2)+Math.pow(r-a,2))}}},{key:"move",value:function(t){if(!(t.touches.length<2)){var n=this.el.getBoundingClientRect(),e=this.touches(t),r=e.cx,o=e.cy,i=e.distance;if(null!==this.distance){var a=i/this.distance-1,u=(n.left-r)*a,c=(n.top-o)*a;this.onzoom(a,u,c)}this.distance=i}}},{key:"end",value:function(){this.distance=null}}]),o}(),Z=function(t){function o(t,n){if(p(this,o),!(n instanceof T))throw new TypeError('Value of argument "emitter" violates contract.\n\nExpected:\nEmitter\n\nGot:\n'+function n(e,r){void 0===r&&(r=0);r+=1;{if(null===e)return"null";if(void 0===e)return"void";if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return void 0===e?"undefined":u(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var o=n(e[0],r);return e.every(function(t){return n(t,r)===o})?o.trim()+"[]":"["+e.slice(0,15).map(function(t){return n(t,r)}).join(", ")+(15<=e.length?", ...":"")+"]"}return"Array"}var t=Object.keys(e);if(!t.length)return e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name:"Object";if(4<r)return"{...}";var i=" ".repeat(r-1),a=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+n(e[t],r)+";"}).join("\n "+i);return 15<=t.length&&(a+="\n "+i+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+i+a+"\n"+i+"}":"{\n "+i+a+"\n"+i+"}"}}(n));var e=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,n)),r=e.el=document.createElement("div");return e.container=t,e.transform={k:1,x:0,y:0},e.mouse=[0,0],r.style.transformOrigin="0 0",e._zoom=new I(t,r,.1,e.onZoom.bind(e)),e._drag=new $(t,e.onTranslate.bind(e)),e.container.addEventListener("mousemove",e.mousemove.bind(e)),e.update(),e}return m(o,T),v(o,[{key:"update",value:function(){var t=this.transform;this.el.style.transform="translate("+t.x+"px, "+t.y+"px) scale("+t.k+")"}},{key:"mousemove",value:function(t){var n=this.el.getBoundingClientRect(),e=t.clientX-n.left,r=t.clientY-n.top,o=this.transform.k;this.trigger("mousemove",{x:e/o,y:r/o})}},{key:"onTranslate",value:function(t,n){this.translate(this.transform.x+t,this.transform.y+n)}},{key:"onZoom",value:function(t,n,e){this.zoom(this.transform.k*(1+t),n,e),this.update()}},{key:"translate",value:function(t,n){var e={transform:this.transform,x:t,y:n};this.trigger("translate",e)&&(this.transform.x=e.x,this.transform.y=e.y,this.update(),this.trigger("translated"))}},{key:"zoom",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,r=this.transform.k,o={transform:this.transform,zoom:t};if(this.trigger("zoom",o)){var i=(r-o.zoom)/(r-t||1);this.transform.k=o.zoom||1,this.transform.x+=n*i,this.transform.y+=e*i,this.update(),this.trigger("zoomed")}}},{key:"appendChild",value:function(t){this.el.appendChild(t)}},{key:"removeChild",value:function(t){this.el.removeChild(t)}}]),o}();var J=function(t){function o(t,n,e){p(this,o);var r=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.trigger("rendercontrol",{el:t,control:n}),r}return m(o,T),o}(),D=function(t){function u(t,n,e,r,o){var i;p(this,u);var a=y(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,o));return a.el=t,a.type=n,a.io=e,a.node=r,a.trigger("rendersocket",(c(i={el:t},n,a.io),c(i,"socket",e.socket),i)),a}return m(u,T),v(u,[{key:"getPosition",value:function(t){var n=t.position,e=this.el;return[n[0]+e.offsetLeft+e.offsetWidth/2,n[1]+e.offsetTop+e.offsetHeight/2]}}]),u}(),M=function(t){function o(t,n,e){p(this,o);var r=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.node=t,r.component=n,r.sockets=new Map,r.controls=new Map,r.el=document.createElement("div"),r.el.style.position="absolute",r.el.addEventListener("contextmenu",function(t){return r.trigger("contextmenu",{e:t,node:r.node})}),r.drag=new $(r.el,r.onTranslate.bind(r),r.onSelect.bind(r)),r.trigger("rendernode",{el:r.el,node:t,component:n.data,bindSocket:r.bindSocket.bind(r),bindControl:r.bindControl.bind(r)}),r.update(),r}return m(o,T),v(o,[{key:"bindSocket",value:function(t,n,e){if(!(t instanceof HTMLElement))throw new TypeError('Value of argument "el" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+z(t));if("string"!=typeof n)throw new TypeError('Value of argument "type" violates contract.\n\nExpected:\nstring\n\nGot:\n'+z(n));if(!(e instanceof f))throw new TypeError('Value of argument "io" violates contract.\n\nExpected:\nIO\n\nGot:\n'+z(e));this.sockets.set(e,new D(t,n,e,this.node,this))}},{key:"bindControl",value:function(t,n){if(!(t instanceof HTMLElement))throw new TypeError('Value of argument "el" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+z(t));if(!(n instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+z(n));this.controls.set(n,new J(t,n,this))}},{key:"getSocketPosition",value:function(t){return this.sockets.get(t).getPosition(this.node)}},{key:"onSelect",value:function(){this.trigger("selectnode",this.node)}},{key:"onTranslate",value:function(t,n){var e=this.node,r=e.position[0]+t,o=e.position[1]+n;this.trigger("nodetranslate",{node:e,x:r,y:o})&&(this.translate(r,o),this.trigger("nodetranslated",{node:e}))}},{key:"translate",value:function(t,n){this.node.position[0]=t,this.node.position[1]=n,this.update()}},{key:"update",value:function(){this.el.style.transform="translate("+this.node.position[0]+"px, "+this.node.position[1]+"px)"}},{key:"remove",value:function(){}}]),o}();function z(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=z(n[0],e);return n.every(function(t){return z(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return z(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+z(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var H=function(t){function i(t,n,e,r){if(p(this,i),!(n instanceof M))throw new TypeError('Value of argument "inputNode" violates contract.\n\nExpected:\nViewNode\n\nGot:\n'+W(n));if(!(e instanceof M))throw new TypeError('Value of argument "outputNode" violates contract.\n\nExpected:\nViewNode\n\nGot:\n'+W(e));var o=y(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,r));return o.connection=t,o.inputNode=n,o.outputNode=e,o.el=document.createElement("div"),o.el.style.position="absolute",o.el.style.zIndex="-1",o.update(),o}return m(i,T),v(i,[{key:"update",value:function(){var t=this.outputNode.getSocketPosition(this.connection.output),n=s(t,2),e=n[0],r=n[1],o=this.inputNode.getSocketPosition(this.connection.input),i=s(o,2),a=i[0],u=i[1];this.trigger("renderconnection",{el:this.el,connection:this.connection,x1:e,y1:r,x2:a,y2:u})}}]),i}();function W(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=W(n[0],e);return n.every(function(t){return W(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return W(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+W(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var Y=function(t){function o(t,n,e){if(p(this,o),!(t instanceof HTMLElement))throw new TypeError('Value of argument "container" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+F(t));if(!(n instanceof Object))throw new TypeError('Value of argument "components" violates contract.\n\nExpected:\nObject\n\nGot:\n'+F(n));if(!(e instanceof T))throw new TypeError('Value of argument "emitter" violates contract.\n\nExpected:\nEmitter\n\nGot:\n'+F(e));var r=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.container=t,r.components=n,r.container.style.overflow="hidden",r.nodes=new Map,r.connections=new Map,r.container.addEventListener("click",r.click.bind(r)),r.container.addEventListener("contextmenu",function(t){return r.trigger("contextmenu",{e:t,view:r})}),window.addEventListener("resize",r.resize.bind(r)),r.on("nodetranslated",r.updateConnections.bind(r)),r.area=new Z(t,r),r.container.appendChild(r.area.el),r}return m(o,T),v(o,[{key:"addNode",value:function(t){if(!(t instanceof E))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+F(t));var n=new M(t,this.components.get(t.name),this);this.nodes.set(t,n),this.area.appendChild(n.el)}},{key:"removeNode",value:function(t){if(!(t instanceof E))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+F(t));var n=this.nodes.get(t);this.nodes.delete(t),this.area.removeChild(n.el)}},{key:"addConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+F(t));var n=this.nodes.get(t.input.node),e=this.nodes.get(t.output.node),r=new H(t,n,e,this);this.connections.set(t,r),this.area.appendChild(r.el)}},{key:"removeConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+F(t));var n=this.connections.get(t);this.connections.delete(t),this.area.removeChild(n.el)}},{key:"updateConnections",value:function(t){var n=this;t.node.getConnections().map(function(t){n.connections.get(t).update()})}},{key:"resize",value:function(){var t=this.container,n=t.parentElement.clientWidth,e=t.parentElement.clientHeight;t.style.width=n+"px",t.style.height=e+"px"}},{key:"click",value:function(t){var n=this.container;n===t.target&&this.trigger("click",{e:t,container:n})}}]),o}();function F(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=F(n[0],e);return n.every(function(t){return F(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return F(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+F(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var X=function(){function t(){p(this,t),this.list=[]}return v(t,[{key:"add",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(!(t instanceof E))throw new TypeError('Value of argument "item" violates contract.\n\nExpected:\nNode\n\nGot:\n'+function n(e,r){void 0===r&&(r=0);r+=1;{if(null===e)return"null";if(void 0===e)return"void";if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return void 0===e?"undefined":u(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var o=n(e[0],r);return e.every(function(t){return n(t,r)===o})?o.trim()+"[]":"["+e.slice(0,15).map(function(t){return n(t,r)}).join(", ")+(15<=e.length?", ...":"")+"]"}return"Array"}var t=Object.keys(e);if(!t.length)return e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name:"Object";if(4<r)return"{...}";var i=" ".repeat(r-1),a=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+n(e[t],r)+";"}).join("\n "+i);return 15<=t.length&&(a+="\n "+i+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+i+a+"\n"+i+"}":"{\n "+i+a+"\n"+i+"}"}}(t));n?this.contains(t)?this.remove(t):this.list.push(t):this.list=[t]}},{key:"clear",value:function(){var n=this;this.each(function(t){n.remove(t)})}},{key:"remove",value:function(t){this.list.splice(this.list.indexOf(t),1)}},{key:"contains",value:function(t){return-1!==this.list.indexOf(t)}},{key:"each",value:function(t){this.list.forEach(t)}}]),t}();var n=function(t){function r(t,n){if(p(this,r),"string"!=typeof t)throw new TypeError('Value of argument "id" violates contract.\n\nExpected:\nstring\n\nGot:\n'+B(t));if(!(n instanceof HTMLElement))throw new TypeError('Value of argument "container" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+B(n));var e=y(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,new R));return e.nodes=[],e.components=new Map,e.selected=new X,e.view=new Y(n,e.components,e),window.addEventListener("keydown",function(t){return e.trigger("keydown",t)}),window.addEventListener("keyup",function(t){return e.trigger("keyup",t)}),e.on("nodecreated",function(t){return e.getComponent(t.name).created(t)}),e.on("noderemoved",function(t){return e.getComponent(t.name).destroyed(t)}),e.on("selectnode",function(t){return e.selectNode(t)}),e}var n;return m(r,C),v(r,[{key:"addNode",value:function(t){if(!(t instanceof E))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+B(t));this.trigger("nodecreate",t)&&(this.nodes.push(t),this.view.addNode(t),this.trigger("nodecreated",t))}},{key:"removeNode",value:function(t){var n=this;if(!(t instanceof E))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+B(t));this.trigger("noderemove",t)&&(t.getConnections().forEach(function(t){return n.removeConnection(t)}),this.nodes.splice(this.nodes.indexOf(t),1),this.view.removeNode(t),this.trigger("noderemoved",t))}},{key:"connect",value:function(t,n){var e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!(t instanceof o))throw new TypeError('Value of argument "output" violates contract.\n\nExpected:\nOutput\n\nGot:\n'+B(t));if(!(n instanceof i))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+B(n));if(this.trigger("connectioncreate",{output:t,input:n}))try{var r=t.connectTo(n);r.data=e,this.view.addConnection(r),this.trigger("connectioncreated",r)}catch(t){this.trigger("warn",t)}}},{key:"removeConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+B(t));this.trigger("connectionremove",t)&&(this.view.removeConnection(t),t.remove(),this.trigger("connectionremoved",t))}},{key:"selectNode",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(!(t instanceof E))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+B(t));if("boolean"!=typeof n)throw new TypeError('Value of argument "accumulate" violates contract.\n\nExpected:\nboolean\n\nGot:\n'+B(n));if(-1===this.nodes.indexOf(t))throw new Error("Node not exist in list");this.trigger("nodeselect",t)&&(this.selected.add(t,n),this.trigger("nodeselected",t))}},{key:"getComponent",value:function(t){var n=this.components.get(t);if(!n)throw"Component "+t+" not found";return n}},{key:"register",value:function(t){if(!(t instanceof O))throw new TypeError('Value of argument "component" violates contract.\n\nExpected:\nComponent\n\nGot:\n'+B(t));(t.editor=this).components.set(t.name,t),this.trigger("componentregister",t)}},{key:"clear",value:function(){var n=this;[].concat(g(this.nodes)).map(function(t){return n.removeNode(t)})}},{key:"toJSON",value:function(){var n={id:this.id,nodes:{}};return this.nodes.forEach(function(t){return n.nodes[t.id]=t.toJSON()}),this.trigger("export",n),n}},{key:"beforeImport",value:function(t){if(!(t instanceof Object))throw new TypeError('Value of argument "json" violates contract.\n\nExpected:\nObject\n\nGot:\n'+B(t));var n=N.validate(this.id,t);return n.success?(this.silent=!0,this.clear(),this.trigger("import",t),!0):(this.trigger("warn",n.msg),!1)}},{key:"afterImport",value:function(){return!(this.silent=!1)}},{key:"fromJSON",value:(n=d(regeneratorRuntime.mark(function t(o){var u,c=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(o instanceof Object){t.next=2;break}throw new TypeError('Value of argument "json" violates contract.\n\nExpected:\nObject\n\nGot:\n'+B(o));case 2:if(this.beforeImport(o)){t.next=4;break}return t.abrupt("return",!1);case 4:return u={},t.prev=5,t.next=8,Promise.all(Object.keys(o.nodes).map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.nodes[n],r=c.getComponent(e.name),t.next=4,r.build(E.fromJSON(e));case 4:u[n]=t.sent,c.addNode(u[n]);case 6:case"end":return t.stop()}},t,c)}));return function(t){return n.apply(this,arguments)}}()));case 8:Object.keys(o.nodes).forEach(function(t){var n=o.nodes[t],a=u[t];Object.keys(n.outputs).forEach(function(i){n.outputs[i].connections.forEach(function(n){var t=n.node,e=n.data,r=a.outputs.find(function(t){return t.key===i}),o=u[t].inputs.find(function(t){return t.key===n.input});c.connect(r,o,e)})})}),t.next=15;break;case 11:return t.prev=11,t.t0=t.catch(5),this.trigger("warn",t.t0),t.abrupt("return",!this.afterImport());case 15:return t.prev=15,t.abrupt("return",this.afterImport());case 18:case"end":return t.stop()}},t,this,[[5,11,15,18]])})),function(t){return n.apply(this,arguments)})}]),r}();function B(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=B(n[0],e);return n.every(function(t){return B(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return B(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+B(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}return{Component:O,Control:r,NodeEditor:n,Emitter:T,Engine:t,Input:i,Node:E,Output:o,Socket:l}}); | ||
!function(t){"use strict";var c,n=Object.prototype,s=n.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},o=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",i=e.toStringTag||"@@toStringTag",a="object"==typeof module,u=t.regeneratorRuntime;if(u)a&&(module.exports=u);else{(u=t.regeneratorRuntime=a?module.exports:{}).wrap=w;var l="suspendedStart",h="suspendedYield",p="executing",d="completed",v={},f={};f[o]=function(){return this};var m=Object.getPrototypeOf,y=m&&m(m(N([])));y&&y!==n&&s.call(y,o)&&(f=y);var g=x.prototype=k.prototype=Object.create(f);E.prototype=g.constructor=x,x.constructor=E,x[i]=E.displayName="GeneratorFunction",u.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return!!n&&(n===E||"GeneratorFunction"===(n.displayName||n.name))},u.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,i in t||(t[i]="GeneratorFunction")),t.prototype=Object.create(g),t},u.awrap=function(t){return{__await:t}},O(j.prototype),j.prototype[r]=function(){return this},u.AsyncIterator=j,u.async=function(t,n,e,r){var o=new j(w(t,n,e,r));return u.isGeneratorFunction(n)?o:o.next().then(function(t){return t.done?t.value:o.next()})},O(g),g[i]="Generator",g[o]=function(){return this},g.toString=function(){return"[object Generator]"},u.keys=function(e){var r=[];for(var t in e)r.push(t);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},u.values=N,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(A),!t)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=c),!!n}for(var n=this.tryEntries.length-1;0<=n;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),u=s.call(o,"finallyLoc");if(a&&u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,n){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.tryLoc<=this.prev&&s.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=n&&n<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=n,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(t,n){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&n&&(this.next=n),v},finish:function(t){for(var n=this.tryEntries.length-1;0<=n;--n){var e=this.tryEntries[n];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),v}},catch:function(t){for(var n=this.tryEntries.length-1;0<=n;--n){var e=this.tryEntries[n];if(e.tryLoc===t){var r=e.completion;if("throw"===r.type){var o=r.arg;A(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,e){return this.delegate={iterator:N(t),resultName:n,nextLoc:e},"next"===this.method&&(this.arg=c),v}}}function w(t,n,e,r){var i,a,u,c,o=n&&n.prototype instanceof k?n:k,s=Object.create(o.prototype),f=new C(r||[]);return s._invoke=(i=t,a=e,u=f,c=l,function(t,n){if(c===p)throw new Error("Generator is already running");if(c===d){if("throw"===t)throw n;return G()}for(u.method=t,u.arg=n;;){var e=u.delegate;if(e){var r=_(e,u);if(r){if(r===v)continue;return r}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(c===l)throw c=d,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);c=p;var o=b(i,a,u);if("normal"===o.type){if(c=u.done?d:h,o.arg===v)continue;return{value:o.arg,done:u.done}}"throw"===o.type&&(c=d,u.method="throw",u.arg=o.arg)}}),s}function b(t,n,e){try{return{type:"normal",arg:t.call(n,e)}}catch(t){return{type:"throw",arg:t}}}function k(){}function E(){}function x(){}function O(t){["next","throw","return"].forEach(function(n){t[n]=function(t){return this._invoke(n,t)}})}function j(c){var n;this._invoke=function(e,r){function t(){return new Promise(function(t,n){!function n(t,e,r,o){var i=b(c[t],c,e);if("throw"!==i.type){var a=i.arg,u=a.value;return u&&"object"==typeof u&&s.call(u,"__await")?Promise.resolve(u.__await).then(function(t){n("next",t,r,o)},function(t){n("throw",t,r,o)}):Promise.resolve(u).then(function(t){a.value=t,r(a)},o)}o(i.arg)}(e,r,t,n)})}return n=n?n.then(t,t):t()}}function _(t,n){var e=t.iterator[n.method];if(e===c){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=c,_(t,n),"throw"===n.method))return v;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var r=b(e,t.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,v;var o=r.arg;return o?o.done?(n[t.resultName]=o.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=c),n.delegate=null,v):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function T(t){var n={tryLoc:t[0]};1 in t&&(n.catchLoc=t[1]),2 in t&&(n.finallyLoc=t[2],n.afterLoc=t[3]),this.tryEntries.push(n)}function A(t){var n=t.completion||{};n.type="normal",delete n.arg,t.completion=n}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function N(n){if(n){var t=n[o];if(t)return t.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length)){var e=-1,r=function t(){for(;++e<n.length;)if(s.call(n,e))return t.value=n[e],t.done=!1,t;return t.value=c,t.done=!0,t};return r.next=r}}return{next:G}}function G(){return{value:c,done:!0}}}(function(){return this}()||Function("return this")()),function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.Rete=n()}(this,function(){"use strict";var u="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},d=function(t){return function(){var u=t.apply(this,arguments);return new Promise(function(i,a){return function n(t,e){try{var r=u[t](e),o=r.value}catch(t){return void a(t)}if(!r.done)return Promise.resolve(o).then(function(t){n("next",t)},function(t){n("throw",t)});i(o)}("next")})}},p=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},v=function(){function r(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),t}}(),c=function(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t},i=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},m=function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(t,n):t.__proto__=n)},y=function(t,n){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?t:n},s=function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,n){var e=[],r=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(e.push(a.value),!n||e.length!==n);r=!0);}catch(t){o=!0,i=t}finally{try{!r&&u.return&&u.return()}finally{if(o)throw i}}return e}(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},g=function(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);n<t.length;n++)e[n]=t[n];return e}return Array.from(t)},w=function(){function n(t){if(p(this,n),this.constructor===n)throw new TypeError("Can not construct abstract class.");this.name=t,this.data={},this.engine=null}return v(n,[{key:"worker",value:function(){}}]),n}(),r=function(){function n(t){if(p(this,n),this.constructor===n)throw new TypeError("Can not construct abstract class.");this.key=t,this.data={},this.parent=null}return v(n,[{key:"getNode",value:function(){if(null===this.parent)throw new Error("Control isn't added to Node/Input");return this.parent instanceof x?this.parent:this.parent.node}},{key:"getData",value:function(t){return this.getNode().data[t]}},{key:"putData",value:function(t,n){this.getNode().data[t]=n}}]),n}(),a=function(){function e(t,n){p(this,e),this.output=t,this.input=n,this.data={},this.input.addConnection(this)}return v(e,[{key:"remove",value:function(){this.input.removeConnection(this),this.output.removeConnection(this)}}]),e}(),f=function(){function o(t,n,e,r){p(this,o),this.node=null,this.multipleConnections=r,this.connections=[],this.key=t,this.name=n,this.socket=e}return v(o,[{key:"removeConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+function n(e,r){void 0===r&&(r=0);r+=1;{if(null===e)return"null";if(void 0===e)return"void";if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return void 0===e?"undefined":u(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var o=n(e[0],r);return e.every(function(t){return n(t,r)===o})?o.trim()+"[]":"["+e.slice(0,15).map(function(t){return n(t,r)}).join(", ")+(15<=e.length?", ...":"")+"]"}return"Array"}var t=Object.keys(e);if(!t.length)return e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name:"Object";if(4<r)return"{...}";var i=" ".repeat(r-1),a=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+n(e[t],r)+";"}).join("\n "+i);return 15<=t.length&&(a+="\n "+i+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+i+a+"\n"+i+"}":"{\n "+i+a+"\n"+i+"}"}}(t));this.connections.splice(this.connections.indexOf(t),1)}},{key:"removeConnections",value:function(){var n=this;this.connections.map(function(t){return n.removeConnection(t)})}}]),o}();var l=function(){function e(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(p(this,e),"string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+h(t));this.name=t,this.data=n,this.compatible=[]}return v(e,[{key:"combineWith",value:function(t){if(!(t instanceof e))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+h(t));this.compatible.push(t)}},{key:"compatibleWith",value:function(t){if(!(t instanceof e))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+h(t));return this===t||this.compatible.includes(t)}}]),e}();function h(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=h(n[0],e);return n.every(function(t){return h(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return h(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+h(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var b=function(t){function i(t,n,e){var r=3<arguments.length&&void 0!==arguments[3]&&arguments[3];if(p(this,i),"string"!=typeof t)throw new TypeError('Value of argument "key" violates contract.\n\nExpected:\nstring\n\nGot:\n'+k(t));if("string"!=typeof n)throw new TypeError('Value of argument "title" violates contract.\n\nExpected:\nstring\n\nGot:\n'+k(n));if(!(e instanceof l))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+k(e));if("boolean"!=typeof r)throw new TypeError('Value of argument "multiConns" violates contract.\n\nExpected:\nboolean\n\nGot:\n'+k(r));var o=y(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,t,n,e,r));return o.control=null,o}return m(i,f),v(i,[{key:"hasConnection",value:function(){return 0<this.connections.length}},{key:"addConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+k(t));if(!this.multipleConnections&&this.hasConnection())throw new Error("Multiple connections not allowed");this.connections.push(t)}},{key:"addControl",value:function(t){if(!(t instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+k(t));(this.control=t).parent=this}},{key:"showControl",value:function(){return!this.hasConnection()&&null!==this.control}},{key:"toJSON",value:function(){return{connections:this.connections.map(function(t){return{node:t.output.node.id,output:t.output.key,data:t.data}})}}}]),i}();function k(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=k(n[0],e);return n.every(function(t){return k(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return k(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+k(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var o=function(t){function o(t,n,e){var r=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];if(p(this,o),"string"!=typeof t)throw new TypeError('Value of argument "key" violates contract.\n\nExpected:\nstring\n\nGot:\n'+E(t));if("string"!=typeof n)throw new TypeError('Value of argument "title" violates contract.\n\nExpected:\nstring\n\nGot:\n'+E(n));if(!(e instanceof l))throw new TypeError('Value of argument "socket" violates contract.\n\nExpected:\nSocket\n\nGot:\n'+E(e));if("boolean"!=typeof r)throw new TypeError('Value of argument "multiConns" violates contract.\n\nExpected:\nboolean\n\nGot:\n'+E(r));return y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,t,n,e,r))}return m(o,f),v(o,[{key:"hasConnection",value:function(){return 0<this.connections.length}},{key:"connectTo",value:function(t){if(!(t instanceof b))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+E(t));if(!this.socket.compatibleWith(t.socket))throw new Error("Sockets not compatible");if(!t.multipleConnections&&t.hasConnection())throw new Error("Input already has one connection");if(!this.multipleConnections&&this.hasConnection())throw new Error("Output already has one connection");var n=new a(this,t);return this.connections.push(n),n}},{key:"connectedTo",value:function(n){if(!(n instanceof b))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+E(n));return this.connections.some(function(t){return t.input===n})}},{key:"toJSON",value:function(){return{connections:this.connections.map(function(t){return{node:t.input.node.id,input:t.input.key,data:t.data}})}}}]),o}();function E(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=E(n[0],e);return n.every(function(t){return E(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return E(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+E(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var x=function(){function e(t){if(p(this,e),"string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+O(t));this.name=t,this.id=e.incrementId(),this.position=[0,0],this.inputs=new Map,this.outputs=new Map,this.controls=new Map,this.data={},this.meta={}}return v(e,[{key:"addControl",value:function(t){if(!(t instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+O(t));return(t.parent=this).controls.set(t.key,t),this}},{key:"removeControl",value:function(t){if(!(t instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+O(t));t.parent=null,this.controls.delete(t.key)}},{key:"addInput",value:function(t){if(!(t instanceof b))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+O(t));if(null!==t.node)throw new Error("Input has already been added to the node");return(t.node=this).inputs.set(t.key,t),this}},{key:"removeInput",value:function(t){if(!(t instanceof b))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+O(t));t.removeConnections(),t.node=null,this.inputs.delete(t.key)}},{key:"addOutput",value:function(t){if(!(t instanceof o))throw new TypeError('Value of argument "output" violates contract.\n\nExpected:\nOutput\n\nGot:\n'+O(t));if(null!==t.node)throw new Error("Output has already been added to the node");return(t.node=this).outputs.set(t.key,t),this}},{key:"removeOutput",value:function(t){if(!(t instanceof o))throw new TypeError('Value of argument "output" violates contract.\n\nExpected:\nOutput\n\nGot:\n'+O(t));t.removeConnections(),t.node=null,this.outputs.delete(t.key)}},{key:"getConnections",value:function(){return[].concat(g(this.inputs.values()),g(this.outputs.values())).reduce(function(t,n){return[].concat(g(t),g(n.connections))},[])}},{key:"toJSON",value:function(){return{id:this.id,data:this.data,inputs:Array.from(this.inputs).reduce(function(t,n){var e=s(n,2),r=e[0],o=e[1];return t[r]=o.toJSON(),t},{}),outputs:Array.from(this.outputs).reduce(function(t,n){var e=s(n,2),r=e[0],o=e[1];return t[r]=o.toJSON(),t},{}),position:this.position,name:this.name}}}],[{key:"incrementId",value:function(){return this.latestId?this.latestId++:this.latestId=1,this.latestId}},{key:"fromJSON",value:function(t){if(!(t instanceof Object))throw new TypeError('Value of argument "json" violates contract.\n\nExpected:\nObject\n\nGot:\n'+O(t));var n=new e(t.name);return n.id=t.id,n.data=t.data,n.position=t.position,n.name=t.name,e.latestId=Math.max(n.id,e.latestId),n}}]),e}();function O(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=O(n[0],e);return n.every(function(t){return O(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return O(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+O(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var e=function(t){function e(t){p(this,e);var n=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));if(n.constructor===e)throw new TypeError("Can not construct abstract class.");return n.editor=null,n.data={},n}var n,r,o;return m(e,w),v(e,[{key:"builder",value:(o=d(regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:case"end":return t.stop()}},t,this)})),function(){return o.apply(this,arguments)})},{key:"created",value:function(){}},{key:"destroyed",value:function(){}},{key:"build",value:(r=d(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n instanceof x){t.next=2;break}throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+j(n));case 2:return t.next=4,this.builder(n);case 4:return t.abrupt("return",n);case 5:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"createNode",value:(n=d(regeneratorRuntime.mark(function t(){var n,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(n=new x(this.name)).data=e,t.next=4,this.build(n);case 4:return t.abrupt("return",n);case 5:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})}]),e}();function j(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=j(n[0],e);return n.every(function(t){return j(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return j(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+j(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var _=function t(n){p(this,t),this.handlers=i({warn:[console.warn],error:[console.error]},n)},T=function(){function n(t){if(p(this,n),!(t instanceof _||t instanceof n))throw new TypeError('Value of argument "events" violates contract.\n\nExpected:\nEvents | Emitter\n\nGot:\n'+A(t));this.events=t instanceof n?t.events:t.handlers,this.silent=!1}return v(n,[{key:"on",value:function(t,n){var e=this;if("string"!=typeof t)throw new TypeError('Value of argument "names" violates contract.\n\nExpected:\nstring\n\nGot:\n'+A(t));if("function"!=typeof n)throw new TypeError('Value of argument "handler" violates contract.\n\nExpected:\n() => {}\n\nGot:\n'+A(n));return t.split(" ").forEach(function(t){if(!e.events[t])throw new Error("The event "+t+" does not exist");e.events[t].push(n)}),this}},{key:"trigger",value:function(t,e){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+A(t));if(!(t in this.events))throw new Error("The event "+t+" cannot be triggered");return this.events[t].reduce(function(t,n){return!1!==n(e)&&t},!0)}}]),n}();function A(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=A(n[0],e);return n.every(function(t){return A(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return A(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+A(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var C=function(){function t(){p(this,t)}return v(t,null,[{key:"isValidData",value:function(t){return"string"==typeof t.id&&this.isValidId(t.id)&&t.nodes instanceof Object&&!(t.nodes instanceof Array)}},{key:"isValidId",value:function(t){return/^[\w-]{3,}@[0-9]+\.[0-9]+\.[0-9]+$/.test(t)}},{key:"validate",value:function(t,n){var e="",r=t.split("@"),o=n.id.split("@");return this.isValidData(n)||(e+="Data is not suitable. "),t!==n.id&&(e+="IDs not equal. "),r[0]!==o[0]&&(e+="Names don't match. "),r[1]!==o[1]&&(e+="Versions don't match"),{success:""===e,msg:e}}}]),t}(),N=function(t){function r(t,n){p(this,r);var e=y(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,n));if(!C.isValidId(t))throw new Error("ID should be valid to name@0.1.0 format");return e.id=t,e}return m(r,T),v(r,[{key:"use",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};t.install(this,n)}}]),r}(),G=function(t){function n(){return p(this,n),y(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,{componentregister:[]}))}return m(n,_),n}(),V=0,S=1,P=2,t=function(t){function e(t){if(p(this,e),"string"!=typeof t)throw new TypeError('Value of argument "id" violates contract.\n\nExpected:\nstring\n\nGot:\n'+L(t));var n=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,new G));return n.components=[],n.args=[],n.data=null,n.state=V,n.onAbort=function(){},n}var n,r,o,i,a,u,c,s,f,l,h;return m(e,N),v(e,[{key:"clone",value:function(){var n=new e(this.id);return this.components.map(function(t){return n.register(t)}),n}},{key:"register",value:function(t){if(!(t instanceof w))throw new TypeError('Value of argument "component" violates contract.\n\nExpected:\nComponent\n\nGot:\n'+L(t));this.components.push(t),this.trigger("componentregister",t)}},{key:"throwError",value:(h=d(regeneratorRuntime.mark(function t(n){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.abort();case 2:return this.trigger("error",{message:n,data:e}),this.processDone(),t.abrupt("return","error");case 5:case"end":return t.stop()}},t,this)})),function(t){return h.apply(this,arguments)})},{key:"extractInputNodes",value:function(e,r){return Object.keys(e.inputs).reduce(function(t,n){return[].concat(g(t),g((e.inputs[n].connections||[]).reduce(function(t,n){return[].concat(g(t),[r[n.node]])},[])))},[])}},{key:"detectRecursions",value:function(o){var i=this,t=Object.keys(o).map(function(t){return o[t]});return t.map(function(t){return function t(n,e){if(e.some(function(t){return t===n}))return n;for(var r=0;r<e.length;r++)if(t(n,i.extractInputNodes(e[r],o)))return n;return null}(t,i.extractInputNodes(t,o))}).filter(function(t){return null!==t})}},{key:"processStart",value:function(){return this.state===V?(this.state=S,!0):(this.state===P||console.warn("The process is busy and has not been restarted.\n Use abort() to force it to complete"),!1)}},{key:"processDone",value:function(){var t=this.state!==P;return this.state=V,t||(this.onAbort(),this.onAbort=function(){}),t}},{key:"abort",value:(l=d(regeneratorRuntime.mark(function t(){var n=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){n.state===S?(n.state=P,n.onAbort=t):n.state===P?(n.onAbort(),n.onAbort=t):t()}));case 1:case"end":return t.stop()}},t,this)})),function(){return l.apply(this,arguments)})},{key:"lock",value:(f=d(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){n.unlockPool=n.unlockPool||[],n.busy&&!n.outputData?n.unlockPool.push(t):t(),n.busy=!0}));case 1:case"end":return t.stop()}},t,this)})),function(t){return f.apply(this,arguments)})},{key:"unlock",value:function(t){t.unlockPool.forEach(function(t){return t()}),t.unlockPool=[],t.busy=!1}},{key:"extractInputData",value:(s=d(regeneratorRuntime.mark(function t(n){var e,r,o,i,a,u,c,s,f,l,h,p=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e={},(c=Object.keys(n.inputs))&&("function"==typeof c[Symbol.iterator]||Array.isArray(c))){t.next=4;break}throw new TypeError("Expected _Object$keys to be iterable, got "+L(c));case 4:o=!(r=!0),i=void 0,t.prev=7,a=c[Symbol.iterator]();case 9:if(r=(u=a.next()).done){t.next=20;break}return s=u.value,f=n.inputs[s],l=f.connections,t.next=15,Promise.all(l.map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=p.data.nodes[n.node],t.next=3,p.processNode(e);case 3:if(r=t.sent){t.next=8;break}p.abort(),t.next=9;break;case 8:return t.abrupt("return",r[n.output]);case 9:case"end":return t.stop()}},t,p)}));return function(t){return n.apply(this,arguments)}}()));case 15:h=t.sent,e[s]=h;case 17:r=!0,t.next=9;break;case 20:t.next=26;break;case 22:t.prev=22,t.t0=t.catch(7),o=!0,i=t.t0;case 26:t.prev=26,t.prev=27,!r&&a.return&&a.return();case 29:if(t.prev=29,!o){t.next=32;break}throw i;case 32:return t.finish(29);case 33:return t.finish(26);case 34:return t.abrupt("return",e);case 35:case"end":return t.stop()}},t,this,[[7,22,26,34],[27,,29,33]])})),function(t){return s.apply(this,arguments)})},{key:"processWorker",value:(c=d(regeneratorRuntime.mark(function t(n){var e,r,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.extractInputData(n);case 2:return e=t.sent,r=this.components.find(function(t){return t.name===n.name}),o={},t.prev=5,t.next=8,r.worker.apply(r,[n,e,o].concat(g(this.args)));case 8:t.next=14;break;case 10:t.prev=10,t.t0=t.catch(5),this.abort(),this.trigger("warn",t.t0);case 14:return t.abrupt("return",o);case 15:case"end":return t.stop()}},t,this,[[5,10]])})),function(t){return c.apply(this,arguments)})},{key:"processNode",value:(u=d(regeneratorRuntime.mark(function t(n){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==P&&n){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,this.lock(n);case 4:return n.outputData||(n.outputData=this.processWorker(n)),this.unlock(n),t.abrupt("return",n.outputData);case 7:case"end":return t.stop()}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"forwardProcess",value:(a=d(regeneratorRuntime.mark(function t(r){var o=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==P){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,Promise.all(Object.keys(r.outputs).map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=r.outputs[n],t.next=3,Promise.all(e.connections.map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.data.nodes[n.node],t.next=3,o.processNode(e);case 3:return t.next=5,o.forwardProcess(e);case 5:case"end":return t.stop()}},t,o)}));return function(t){return n.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,o)}));return function(t){return n.apply(this,arguments)}}()));case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}},t,this)})),function(t){return a.apply(this,arguments)})},{key:"copy",value:function(n){return(n=Object.assign({},n)).nodes=Object.assign({},n.nodes),Object.keys(n.nodes).forEach(function(t){n.nodes[t]=Object.assign({},n.nodes[t])}),n}},{key:"validate",value:(i=d(regeneratorRuntime.mark(function t(n){var e,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((e=C.validate(this.id,n)).success){t.next=5;break}return t.next=4,this.throwError(e.msg);case 4:return t.abrupt("return",t.sent);case 5:if(!(0<(r=this.detectRecursions(n.nodes)).length)){t.next=10;break}return t.next=9,this.throwError("Recursion detected",r);case 9:return t.abrupt("return",t.sent);case 10:return t.abrupt("return",!0);case 11:case"end":return t.stop()}},t,this)})),function(t){return i.apply(this,arguments)})},{key:"processStartNode",value:(o=d(regeneratorRuntime.mark(function t(n){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!n){t.next=10;break}if(e=this.data.nodes[n]){t.next=6;break}return t.next=5,this.throwError("Node with such id not found");case 5:return t.abrupt("return",t.sent);case 6:return t.next=8,this.processNode(e);case 8:return t.next=10,this.forwardProcess(e);case 10:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"processUnreachable",value:(r=d(regeneratorRuntime.mark(function t(){var n,e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=regeneratorRuntime.keys(this.data.nodes);case 1:if((t.t1=t.t0()).done){t.next=11;break}if(n=t.t1.value,void 0!==this.data.nodes[n].outputData){t.next=9;break}return e=this.data.nodes[n],t.next=7,this.processNode(e);case 7:return t.next=9,this.forwardProcess(e);case 9:t.next=1;break;case 11:case"end":return t.stop()}},t,this)})),function(){return r.apply(this,arguments)})},{key:"process",value:(n=d(regeneratorRuntime.mark(function t(n){for(var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length,o=Array(2<r?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n instanceof Object){t.next=2;break}throw new TypeError('Value of argument "data" violates contract.\n\nExpected:\nObject\n\nGot:\n'+L(n));case 2:if(null==e||"number"==typeof e){t.next=4;break}throw new TypeError('Value of argument "startId" violates contract.\n\nExpected:\n?number\n\nGot:\n'+L(e));case 4:if(this.processStart()){t.next=6;break}return t.abrupt("return");case 6:if(this.validate(n)){t.next=8;break}return t.abrupt("return");case 8:return this.data=this.copy(n),this.args=o,t.next=12,this.processStartNode(e);case 12:return t.next=14,this.processUnreachable();case 14:return t.abrupt("return",this.processDone()?"success":"aborted");case 15:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})}]),e}();function L(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=L(n[0],e);return n.every(function(t){return L(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return L(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+L(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var R=function(t){function n(){return p(this,n),y(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,{nodecreate:[],nodecreated:[],noderemove:[],noderemoved:[],connectioncreate:[],connectioncreated:[],connectionremove:[],connectionremoved:[],nodetranslate:[],nodetranslated:[],selectnode:[],nodeselect:[],nodeselected:[],rendernode:[],rendersocket:[],rendercontrol:[],renderconnection:[],componentregister:[],keydown:[],keyup:[],translate:[],translated:[],zoom:[],zoomed:[],click:[],mousemove:[],contextmenu:[],import:[],export:[],process:[]}))}return m(n,_),n}(),$=function(){function o(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:function(){},e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:function(){},r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:function(){};p(this,o),this.mouseStart=null,this.el=t,this.onTranslate=n,this.onStart=e,this.onDrag=r,this.initEvents(t)}return v(o,[{key:"initEvents",value:function(t){t.addEventListener("mousedown",this.down.bind(this)),window.addEventListener("mousemove",this.move.bind(this)),window.addEventListener("mouseup",this.up.bind(this)),t.addEventListener("touchstart",this.down.bind(this)),window.addEventListener("touchmove",this.move.bind(this),{passive:!1}),window.addEventListener("touchend",this.up.bind(this))}},{key:"getCoords",value:function(t){var n=t.touches?t.touches[0]:t;return[n.pageX,n.pageY]}},{key:"down",value:function(t){t.stopPropagation(),this.mouseStart=this.getCoords(t),this.onStart()}},{key:"move",value:function(t){if(this.mouseStart){t.preventDefault(),t.stopPropagation();var n=this.getCoords(t),e=s(n,2),r=e[0],o=e[1],i=[r-this.mouseStart[0],o-this.mouseStart[1]],a=this.el.getBoundingClientRect().width/this.el.offsetWidth;this.onTranslate(i[0]/a,i[1]/a)}}},{key:"up",value:function(){this.mouseStart=null,this.onDrag()}}]),o}(),I=function(){function o(t,n,e,r){p(this,o),this.el=n,this.intensity=e,this.onzoom=r,this.distance=null,t.addEventListener("wheel",this.wheel.bind(this)),t.addEventListener("touchmove",this.move.bind(this)),t.addEventListener("touchend",this.end.bind(this)),t.addEventListener("touchcancel",this.end.bind(this))}return v(o,[{key:"wheel",value:function(t){t.preventDefault();var n=this.el.getBoundingClientRect(),e=(t.wheelDelta?t.wheelDelta/120:-t.deltaY/3)*this.intensity,r=(n.left-t.pageX)*e,o=(n.top-t.pageY)*e;this.onzoom(e,r,o)}},{key:"touches",value:function(t){var n=[t.touches[0].pageX,t.touches[0].pageY],e=n[0],r=n[1],o=[t.touches[1].pageX,t.touches[1].pageY],i=o[0],a=o[1];return{cx:(e+i)/2,cy:(r+a)/2,distance:Math.sqrt(Math.pow(e-i,2)+Math.pow(r-a,2))}}},{key:"move",value:function(t){if(!(t.touches.length<2)){var n=this.el.getBoundingClientRect(),e=this.touches(t),r=e.cx,o=e.cy,i=e.distance;if(null!==this.distance){var a=i/this.distance-1,u=(n.left-r)*a,c=(n.top-o)*a;this.onzoom(a,u,c)}this.distance=i}}},{key:"end",value:function(){this.distance=null}}]),o}(),Z=function(t){function o(t,n){if(p(this,o),!(n instanceof T))throw new TypeError('Value of argument "emitter" violates contract.\n\nExpected:\nEmitter\n\nGot:\n'+function n(e,r){void 0===r&&(r=0);r+=1;{if(null===e)return"null";if(void 0===e)return"void";if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return void 0===e?"undefined":u(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var o=n(e[0],r);return e.every(function(t){return n(t,r)===o})?o.trim()+"[]":"["+e.slice(0,15).map(function(t){return n(t,r)}).join(", ")+(15<=e.length?", ...":"")+"]"}return"Array"}var t=Object.keys(e);if(!t.length)return e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name:"Object";if(4<r)return"{...}";var i=" ".repeat(r-1),a=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+n(e[t],r)+";"}).join("\n "+i);return 15<=t.length&&(a+="\n "+i+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+i+a+"\n"+i+"}":"{\n "+i+a+"\n"+i+"}"}}(n));var e=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,n)),r=e.el=document.createElement("div");return e.container=t,e.transform={k:1,x:0,y:0},e.mouse={x:0,y:0},r.style.transformOrigin="0 0",e._startPosition=null,e._zoom=new I(t,r,.1,e.onZoom.bind(e)),e._drag=new $(t,e.onTranslate.bind(e),e.onStart.bind(e)),e.container.addEventListener("mousemove",e.mousemove.bind(e)),e.update(),e}return m(o,T),v(o,[{key:"update",value:function(){var t=this.transform;this.el.style.transform="translate("+t.x+"px, "+t.y+"px) scale("+t.k+")"}},{key:"mousemove",value:function(t){var n=this.el.getBoundingClientRect(),e=t.clientX-n.left,r=t.clientY-n.top,o=this.transform.k;this.mouse={x:e/o,y:r/o},this.trigger("mousemove",i({},this.mouse))}},{key:"onStart",value:function(){this._startPosition=i({},this.transform)}},{key:"onTranslate",value:function(t,n){this.translate(this._startPosition.x+t,this._startPosition.y+n)}},{key:"onZoom",value:function(t,n,e){this.zoom(this.transform.k*(1+t),n,e),this.update()}},{key:"translate",value:function(t,n){var e={transform:this.transform,x:t,y:n};this.trigger("translate",e)&&(this.transform.x=e.x,this.transform.y=e.y,this.update(),this.trigger("translated"))}},{key:"zoom",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,r=this.transform.k,o={transform:this.transform,zoom:t};if(this.trigger("zoom",o)){var i=(r-o.zoom)/(r-t||1);this.transform.k=o.zoom||1,this.transform.x+=n*i,this.transform.y+=e*i,this.update(),this.trigger("zoomed")}}},{key:"appendChild",value:function(t){this.el.appendChild(t)}},{key:"removeChild",value:function(t){this.el.removeChild(t)}}]),o}();var J=function(t){function o(t,n,e){p(this,o);var r=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.trigger("rendercontrol",{el:t,control:n}),r}return m(o,T),o}(),D=function(t){function u(t,n,e,r,o){var i;p(this,u);var a=y(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,o));return a.el=t,a.type=n,a.io=e,a.node=r,a.trigger("rendersocket",(c(i={el:t},n,a.io),c(i,"socket",e.socket),i)),a}return m(u,T),v(u,[{key:"getPosition",value:function(t){var n=t.position,e=this.el;return[n[0]+e.offsetLeft+e.offsetWidth/2,n[1]+e.offsetTop+e.offsetHeight/2]}}]),u}(),M=function(t){function o(t,n,e){p(this,o);var r=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.node=t,r.component=n,r.sockets=new Map,r.controls=new Map,r.el=document.createElement("div"),r.el.style.position="absolute",r.el.addEventListener("contextmenu",function(t){return r.trigger("contextmenu",{e:t,node:r.node})}),r._startPosition=null,r._drag=new $(r.el,r.onTranslate.bind(r),r.onSelect.bind(r)),r.trigger("rendernode",{el:r.el,node:t,component:n.data,bindSocket:r.bindSocket.bind(r),bindControl:r.bindControl.bind(r)}),r.update(),r}return m(o,T),v(o,[{key:"bindSocket",value:function(t,n,e){if(!(t instanceof HTMLElement))throw new TypeError('Value of argument "el" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+z(t));if("string"!=typeof n)throw new TypeError('Value of argument "type" violates contract.\n\nExpected:\nstring\n\nGot:\n'+z(n));if(!(e instanceof f))throw new TypeError('Value of argument "io" violates contract.\n\nExpected:\nIO\n\nGot:\n'+z(e));this.sockets.set(e,new D(t,n,e,this.node,this))}},{key:"bindControl",value:function(t,n){if(!(t instanceof HTMLElement))throw new TypeError('Value of argument "el" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+z(t));if(!(n instanceof r))throw new TypeError('Value of argument "control" violates contract.\n\nExpected:\nControl\n\nGot:\n'+z(n));this.controls.set(n,new J(t,n,this))}},{key:"getSocketPosition",value:function(t){return this.sockets.get(t).getPosition(this.node)}},{key:"onSelect",value:function(){this._startPosition=[].concat(g(this.node.position)),this.trigger("selectnode",this.node)}},{key:"onTranslate",value:function(t,n){var e=this._startPosition[0]+t,r=this._startPosition[1]+n;this.translate(e,r)}},{key:"translate",value:function(t,n){var e=this.node,r={node:e,x:t,y:n};this.trigger("nodetranslate",r)&&(this.node.position[0]=r.x,this.node.position[1]=r.y,this.update(),this.trigger("nodetranslated",{node:e}))}},{key:"update",value:function(){this.el.style.transform="translate("+this.node.position[0]+"px, "+this.node.position[1]+"px)"}},{key:"remove",value:function(){}}]),o}();function z(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=z(n[0],e);return n.every(function(t){return z(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return z(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+z(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var H=function(t){function i(t,n,e,r){if(p(this,i),!(n instanceof M))throw new TypeError('Value of argument "inputNode" violates contract.\n\nExpected:\nViewNode\n\nGot:\n'+W(n));if(!(e instanceof M))throw new TypeError('Value of argument "outputNode" violates contract.\n\nExpected:\nViewNode\n\nGot:\n'+W(e));var o=y(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,r));return o.connection=t,o.inputNode=n,o.outputNode=e,o.el=document.createElement("div"),o.el.style.position="absolute",o.el.style.zIndex="-1",o.update(),o}return m(i,T),v(i,[{key:"update",value:function(){var t=this.outputNode.getSocketPosition(this.connection.output),n=s(t,2),e=n[0],r=n[1],o=this.inputNode.getSocketPosition(this.connection.input),i=s(o,2),a=i[0],u=i[1];this.trigger("renderconnection",{el:this.el,connection:this.connection,x1:e,y1:r,x2:a,y2:u})}}]),i}();function W(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=W(n[0],e);return n.every(function(t){return W(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return W(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+W(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var Y=function(t){function o(t,n,e){if(p(this,o),!(t instanceof HTMLElement))throw new TypeError('Value of argument "container" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+F(t));if(!(n instanceof Object))throw new TypeError('Value of argument "components" violates contract.\n\nExpected:\nObject\n\nGot:\n'+F(n));if(!(e instanceof T))throw new TypeError('Value of argument "emitter" violates contract.\n\nExpected:\nEmitter\n\nGot:\n'+F(e));var r=y(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.container=t,r.components=n,r.container.style.overflow="hidden",r.nodes=new Map,r.connections=new Map,r.container.addEventListener("click",r.click.bind(r)),r.container.addEventListener("contextmenu",function(t){return r.trigger("contextmenu",{e:t,view:r})}),window.addEventListener("resize",r.resize.bind(r)),r.on("nodetranslated",r.updateConnections.bind(r)),r.area=new Z(t,r),r.container.appendChild(r.area.el),r}return m(o,T),v(o,[{key:"addNode",value:function(t){if(!(t instanceof x))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+F(t));var n=new M(t,this.components.get(t.name),this);this.nodes.set(t,n),this.area.appendChild(n.el)}},{key:"removeNode",value:function(t){if(!(t instanceof x))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+F(t));var n=this.nodes.get(t);this.nodes.delete(t),this.area.removeChild(n.el)}},{key:"addConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+F(t));var n=this.nodes.get(t.input.node),e=this.nodes.get(t.output.node),r=new H(t,n,e,this);this.connections.set(t,r),this.area.appendChild(r.el)}},{key:"removeConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+F(t));var n=this.connections.get(t);this.connections.delete(t),this.area.removeChild(n.el)}},{key:"updateConnections",value:function(t){var n=this;t.node.getConnections().map(function(t){n.connections.get(t).update()})}},{key:"resize",value:function(){var t=this.container,n=t.parentElement.clientWidth,e=t.parentElement.clientHeight;t.style.width=n+"px",t.style.height=e+"px"}},{key:"click",value:function(t){var n=this.container;n===t.target&&this.trigger("click",{e:t,container:n})}}]),o}();function F(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=F(n[0],e);return n.every(function(t){return F(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return F(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+F(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var X=function(){function t(){p(this,t),this.list=[]}return v(t,[{key:"add",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(!(t instanceof x))throw new TypeError('Value of argument "item" violates contract.\n\nExpected:\nNode\n\nGot:\n'+function n(e,r){void 0===r&&(r=0);r+=1;{if(null===e)return"null";if(void 0===e)return"void";if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return void 0===e?"undefined":u(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var o=n(e[0],r);return e.every(function(t){return n(t,r)===o})?o.trim()+"[]":"["+e.slice(0,15).map(function(t){return n(t,r)}).join(", ")+(15<=e.length?", ...":"")+"]"}return"Array"}var t=Object.keys(e);if(!t.length)return e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name:"Object";if(4<r)return"{...}";var i=" ".repeat(r-1),a=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+n(e[t],r)+";"}).join("\n "+i);return 15<=t.length&&(a+="\n "+i+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+i+a+"\n"+i+"}":"{\n "+i+a+"\n"+i+"}"}}(t));n?this.contains(t)?this.remove(t):this.list.push(t):this.list=[t]}},{key:"clear",value:function(){var n=this;this.each(function(t){n.remove(t)})}},{key:"remove",value:function(t){this.list.splice(this.list.indexOf(t),1)}},{key:"contains",value:function(t){return-1!==this.list.indexOf(t)}},{key:"each",value:function(t){this.list.forEach(t)}}]),t}();var n=function(t){function r(t,n){if(p(this,r),"string"!=typeof t)throw new TypeError('Value of argument "id" violates contract.\n\nExpected:\nstring\n\nGot:\n'+B(t));if(!(n instanceof HTMLElement))throw new TypeError('Value of argument "container" violates contract.\n\nExpected:\nHTMLElement\n\nGot:\n'+B(n));var e=y(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,new R));return e.nodes=[],e.components=new Map,e.selected=new X,e.view=new Y(n,e.components,e),window.addEventListener("keydown",function(t){return e.trigger("keydown",t)}),window.addEventListener("keyup",function(t){return e.trigger("keyup",t)}),e.on("nodecreated",function(t){return e.getComponent(t.name).created(t)}),e.on("noderemoved",function(t){return e.getComponent(t.name).destroyed(t)}),e.on("selectnode",function(t){return e.selectNode(t)}),e}var n;return m(r,N),v(r,[{key:"addNode",value:function(t){if(!(t instanceof x))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+B(t));this.trigger("nodecreate",t)&&(this.nodes.push(t),this.view.addNode(t),this.trigger("nodecreated",t))}},{key:"removeNode",value:function(t){var n=this;if(!(t instanceof x))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+B(t));this.trigger("noderemove",t)&&(t.getConnections().forEach(function(t){return n.removeConnection(t)}),this.nodes.splice(this.nodes.indexOf(t),1),this.view.removeNode(t),this.trigger("noderemoved",t))}},{key:"connect",value:function(t,n){var e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(!(t instanceof o))throw new TypeError('Value of argument "output" violates contract.\n\nExpected:\nOutput\n\nGot:\n'+B(t));if(!(n instanceof b))throw new TypeError('Value of argument "input" violates contract.\n\nExpected:\nInput\n\nGot:\n'+B(n));if(this.trigger("connectioncreate",{output:t,input:n}))try{var r=t.connectTo(n);r.data=e,this.view.addConnection(r),this.trigger("connectioncreated",r)}catch(t){this.trigger("warn",t)}}},{key:"removeConnection",value:function(t){if(!(t instanceof a))throw new TypeError('Value of argument "connection" violates contract.\n\nExpected:\nConnection\n\nGot:\n'+B(t));this.trigger("connectionremove",t)&&(this.view.removeConnection(t),t.remove(),this.trigger("connectionremoved",t))}},{key:"selectNode",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(!(t instanceof x))throw new TypeError('Value of argument "node" violates contract.\n\nExpected:\nNode\n\nGot:\n'+B(t));if("boolean"!=typeof n)throw new TypeError('Value of argument "accumulate" violates contract.\n\nExpected:\nboolean\n\nGot:\n'+B(n));if(-1===this.nodes.indexOf(t))throw new Error("Node not exist in list");this.trigger("nodeselect",t)&&(this.selected.add(t,n),this.trigger("nodeselected",t))}},{key:"getComponent",value:function(t){var n=this.components.get(t);if(!n)throw"Component "+t+" not found";return n}},{key:"register",value:function(t){if(!(t instanceof e))throw new TypeError('Value of argument "component" violates contract.\n\nExpected:\nComponent\n\nGot:\n'+B(t));(t.editor=this).components.set(t.name,t),this.trigger("componentregister",t)}},{key:"clear",value:function(){var n=this;[].concat(g(this.nodes)).map(function(t){return n.removeNode(t)})}},{key:"toJSON",value:function(){var n={id:this.id,nodes:{}};return this.nodes.forEach(function(t){return n.nodes[t.id]=t.toJSON()}),this.trigger("export",n),n}},{key:"beforeImport",value:function(t){if(!(t instanceof Object))throw new TypeError('Value of argument "json" violates contract.\n\nExpected:\nObject\n\nGot:\n'+B(t));var n=C.validate(this.id,t);return n.success?(this.silent=!0,this.clear(),this.trigger("import",t),!0):(this.trigger("warn",n.msg),!1)}},{key:"afterImport",value:function(){return!(this.silent=!1)}},{key:"fromJSON",value:(n=d(regeneratorRuntime.mark(function t(o){var u,c=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(o instanceof Object){t.next=2;break}throw new TypeError('Value of argument "json" violates contract.\n\nExpected:\nObject\n\nGot:\n'+B(o));case 2:if(this.beforeImport(o)){t.next=4;break}return t.abrupt("return",!1);case 4:return u={},t.prev=5,t.next=8,Promise.all(Object.keys(o.nodes).map(function(){var n=d(regeneratorRuntime.mark(function t(n){var e,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.nodes[n],r=c.getComponent(e.name),t.next=4,r.build(x.fromJSON(e));case 4:u[n]=t.sent,c.addNode(u[n]);case 6:case"end":return t.stop()}},t,c)}));return function(t){return n.apply(this,arguments)}}()));case 8:Object.keys(o.nodes).forEach(function(t){var n=o.nodes[t],a=u[t];Object.keys(n.outputs).forEach(function(i){n.outputs[i].connections.forEach(function(t){var n=t.node,e=t.data,r=a.outputs.get(i),o=u[n].inputs.get(t.input);c.connect(r,o,e)})})}),t.next=15;break;case 11:return t.prev=11,t.t0=t.catch(5),this.trigger("warn",t.t0),t.abrupt("return",!this.afterImport());case 15:return t.prev=15,t.abrupt("return",this.afterImport());case 18:case"end":return t.stop()}},t,this,[[5,11,15,18]])})),function(t){return n.apply(this,arguments)})}]),r}();function B(n,e){if(void 0===e&&(e=0),e+=1,null===n)return"null";if(void 0===n)return"void";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)return void 0===n?"undefined":u(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=B(n[0],e);return n.every(function(t){return B(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return B(t,e)}).join(", ")+(15<=n.length?", ...":"")+"]"}return"Array"}var t=Object.keys(n);if(!t.length)return n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name:"Object";if(4<e)return"{...}";var o=" ".repeat(e-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+B(n[t],e)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),n.constructor&&n.constructor.name&&"Object"!==n.constructor.name?n.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}return{Component:e,Control:r,NodeEditor:n,Emitter:T,Engine:t,Input:b,Node:x,Output:o,Socket:l}}); | ||
//# sourceMappingURL=rete.min.js.map |
{ | ||
"name": "rete", | ||
"version": "1.0.0-alpha.7", | ||
"version": "1.0.0-alpha.8", | ||
"description": "JavaScript framework", | ||
@@ -5,0 +5,0 @@ "main": "build/rete.min.js", |
@@ -5,6 +5,7 @@ import { Node } from './node'; | ||
constructor() { | ||
constructor(key) { | ||
if (this.constructor === Control) | ||
throw new TypeError('Can not construct abstract class.'); | ||
this.key = key; | ||
this.data = {}; | ||
@@ -11,0 +12,0 @@ this.parent = null; |
@@ -154,4 +154,4 @@ import { Component } from './component'; | ||
var data = jsonConnection.data; | ||
var targetOutput = node.outputs.find(o => o.key === key); | ||
var targetInput = nodes[nodeId].inputs.find(i => i.key === jsonConnection.input); | ||
var targetOutput = node.outputs.get(key); | ||
var targetInput = nodes[nodeId].inputs.get(jsonConnection.input); | ||
@@ -158,0 +158,0 @@ this.connect(targetOutput, targetInput, data); |
@@ -124,3 +124,3 @@ import {Engine, Context, Events, Component as ComponentWorker, Emitter} from './engine/engine.d'; | ||
constructor(title, socket, multiConns); | ||
constructor(key, title, socket, multiConns); | ||
removeConnection(connection: Connection); | ||
@@ -132,3 +132,3 @@ } | ||
constructor(title: string, socket: Socket, multiConns?: boolean); | ||
constructor(key: string, title: string, socket: Socket, multiConns?: boolean); | ||
hasConnection(); | ||
@@ -143,3 +143,3 @@ addConnection(connection: Connection); | ||
constructor(title: string, socket: Socket, multiConns?: boolean) | ||
constructor(key: string, title: string, socket: Socket, multiConns?: boolean) | ||
hasConnection(); | ||
@@ -146,0 +146,0 @@ connectTo(input: Input); |
@@ -12,5 +12,5 @@ import { Control } from './control'; | ||
this.inputs = []; | ||
this.outputs = []; | ||
this.controls = []; | ||
this.inputs = new Map(); | ||
this.outputs = new Map(); | ||
this.controls = new Map(); | ||
this.data = {}; | ||
@@ -20,6 +20,6 @@ this.meta = {}; | ||
addControl(control: Control, index: ?uint8 = this.controls.length) { | ||
addControl(control: Control) { | ||
control.parent = this; | ||
this.controls.splice(index, 0, control); | ||
this.controls.set(control.key, control); | ||
return this; | ||
@@ -30,6 +30,7 @@ } | ||
control.parent = null; | ||
this.controls.splice(this.controls.indexOf(control), 1); | ||
this.controls.delete(control.key); | ||
} | ||
addInput(input: Input, index: ?uint8 = this.inputs.length) { | ||
addInput(input: Input) { | ||
if (input.node !== null) | ||
@@ -40,3 +41,3 @@ throw new Error('Input has already been added to the node'); | ||
this.inputs.splice(index, 0, input); | ||
this.inputs.set(input.key, input); | ||
return this; | ||
@@ -48,6 +49,7 @@ } | ||
input.node = null; | ||
this.inputs.splice(this.inputs.indexOf(input), 1); | ||
this.inputs.delete(input.key); | ||
} | ||
addOutput(output: Output, index: ?uint8 = this.outputs.length) { | ||
addOutput(output: Output) { | ||
if (output.node !== null) | ||
@@ -58,3 +60,3 @@ throw new Error('Output has already been added to the node'); | ||
this.outputs.splice(index, 0, output); | ||
this.outputs.set(output.key, output); | ||
return this; | ||
@@ -66,7 +68,8 @@ } | ||
output.node = null; | ||
this.outputs.splice(this.outputs.indexOf(output), 1); | ||
this.outputs.delete(output.key); | ||
} | ||
getConnections() { | ||
const ios = [...this.inputs, ...this.outputs]; | ||
const ios = [...this.inputs.values(), ...this.outputs.values()]; | ||
const connections = ios.reduce((arr, io) => { | ||
@@ -79,8 +82,2 @@ return [...arr, ...io.connections]; | ||
inputsWithVisibleControl() { | ||
return this.inputs.filter((input)=> { | ||
return input.showControl(); | ||
}); | ||
} | ||
static incrementId() { | ||
@@ -98,4 +95,4 @@ if (!this.latestId) | ||
'data': this.data, | ||
'inputs': this.inputs.reduce((obj, input) => (obj[input.key] = input.toJSON(), obj), {}), | ||
'outputs': this.outputs.reduce((obj, output) => (obj[output.key] = output.toJSON(), obj), {}), | ||
'inputs': Array.from(this.inputs).reduce((obj, [key, input]) => (obj[key] = input.toJSON(), obj), {}), | ||
'outputs': Array.from(this.outputs).reduce((obj, [key, output]) => (obj[key] = output.toJSON(), obj), {}), | ||
'position': this.position, | ||
@@ -102,0 +99,0 @@ 'name': this.name |
@@ -14,8 +14,9 @@ import { Drag } from './drag'; | ||
this.transform = { k: 1, x: 0, y: 0 }; | ||
this.mouse = [0, 0]; | ||
this.mouse = { x: 0, y: 0 } | ||
el.style.transformOrigin = '0 0'; | ||
this._startPosition = null; | ||
this._zoom = new Zoom(container, el, 0.1, this.onZoom.bind(this)); | ||
this._drag = new Drag(container, this.onTranslate.bind(this)); | ||
this._drag = new Drag(container, this.onTranslate.bind(this), this.onStart.bind(this)); | ||
this.container.addEventListener('mousemove', this.mousemove.bind(this)); | ||
@@ -37,8 +38,13 @@ | ||
const k = this.transform.k; | ||
this.mouse = { x: x / k, y: y / k }; | ||
this.trigger('mousemove', { ...this.mouse }); | ||
} | ||
this.trigger('mousemove', { x: x / k, y: y / k }); | ||
onStart() { | ||
this._startPosition = { ...this.transform }; | ||
} | ||
onTranslate(dx, dy) { | ||
this.translate(this.transform.x + dx, this.transform.y + dy) | ||
this.translate(this._startPosition.x + dx, this._startPosition.y + dy) | ||
} | ||
@@ -45,0 +51,0 @@ |
@@ -48,4 +48,2 @@ export class Drag { | ||
this.mouseStart = [x, y]; | ||
this.onTranslate(delta[0] / zoom, delta[1] / zoom); | ||
@@ -52,0 +50,0 @@ } |
@@ -21,4 +21,6 @@ import { Control } from '../control'; | ||
this.el.addEventListener('contextmenu', e => this.trigger('contextmenu', { e, node: this.node })); | ||
this.drag = new Drag(this.el, this.onTranslate.bind(this), this.onSelect.bind(this)); | ||
this._startPosition = null; | ||
this._drag = new Drag(this.el, this.onTranslate.bind(this), this.onSelect.bind(this)); | ||
this.trigger('rendernode', { | ||
@@ -31,3 +33,3 @@ el: this.el, | ||
}); | ||
this.update(); | ||
@@ -48,3 +50,4 @@ } | ||
onSelect() { | ||
onSelect() { | ||
this._startPosition = [...this.node.position]; | ||
this.trigger('selectnode', this.node); | ||
@@ -54,18 +57,19 @@ } | ||
onTranslate(dx, dy) { | ||
const node = this.node; | ||
const x = node.position[0] + dx; | ||
const y = node.position[1] + dy; | ||
const x = this._startPosition[0] + dx; | ||
const y = this._startPosition[1] + dy; | ||
if (!this.trigger('nodetranslate', { node, x, y })) return; | ||
this.translate(x, y); | ||
this.trigger('nodetranslated', { node }); | ||
} | ||
translate(x, y) { | ||
this.node.position[0] = x; | ||
this.node.position[1] = y; | ||
const node = this.node; | ||
const params = { node, x, y }; | ||
if (!this.trigger('nodetranslate', params)) return; | ||
this.node.position[0] = params.x; | ||
this.node.position[1] = params.y; | ||
this.update(); | ||
this.trigger('nodetranslated', { node }); | ||
} | ||
@@ -72,0 +76,0 @@ |
@@ -72,13 +72,13 @@ import './utils/domReady'; | ||
assert.throws(() => editor.connect(n1.outputs[1], n2.inputs[0]), Error, 'no output'); | ||
assert.throws(() => editor.connect(n1.outputs.get('none'), n2.inputs.get('name')), Error, 'no output'); | ||
editor.connect(n1.outputs[0], n2.inputs[0]); | ||
assert.equal(n1.outputs[0].connections.length, 1, 'one connection'); | ||
editor.connect(n1.outputs.get('name'), n2.inputs.get('name')); | ||
assert.equal(n1.outputs.get('name').connections.length, 1, 'one connection'); | ||
var connection = n1.outputs[0].connections[0]; | ||
var connection = n1.outputs.get('name').connections[0]; | ||
assert.doesNotThrow(() => editor.removeConnection(connection), Error, 'remove connection'); | ||
assert.equal(n1.outputs[0].connections.length, 0, 'no connections'); | ||
assert.equal(n1.outputs.get('name').connections.length, 0, 'no connections'); | ||
}); | ||
}) |
export function renderMock(editor) { | ||
editor.on('rendernode', ({ node, bindSocket, bindControl }) => { | ||
node.inputs.map(i => { | ||
Array.from(node.inputs.values()).map(i => { | ||
bindSocket(document.createElement('div'), 'input', i); | ||
}); | ||
node.outputs.map(o => { | ||
Array.from(node.outputs.values()).map(o => { | ||
bindSocket(document.createElement('div'), 'output', o); | ||
@@ -8,0 +8,0 @@ }); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1848
0
216614