Comparing version 1.0.1 to 1.0.2
/*! | ||
* rete v1.0.1 | ||
* rete v1.0.2 | ||
* (c) 2019 Ni55aN | ||
* Released under the MIT license. | ||
*/ | ||
!function(t){"use strict";var s,e=Object.prototype,c=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",n=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag",a="object"==typeof module,u=t.regeneratorRuntime;if(u)a&&(module.exports=u);else{(u=t.regeneratorRuntime=a?module.exports:{}).wrap=b;var l="suspendedStart",p="suspendedYield",h="executing",y="completed",d={},f={};f[o]=function(){return this};var v=Object.getPrototypeOf,m=v&&v(v(L([])));m&&m!==e&&c.call(m,o)&&(f=m);var g=E.prototype=x.prototype=Object.create(f);k.prototype=g.constructor=E,E.constructor=k,E[i]=k.displayName="GeneratorFunction",u.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===k||"GeneratorFunction"===(e.displayName||e.name))},u.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,i in t||(t[i]="GeneratorFunction")),t.prototype=Object.create(g),t},u.awrap=function(t){return{__await:t}},O(j.prototype),j.prototype[n]=function(){return this},u.AsyncIterator=j,u.async=function(t,e,r,n){var o=new j(b(t,e,r,n));return u.isGeneratorFunction(e)?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(r){var n=[];for(var t in r)n.push(t);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},u.values=L,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&c.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=s)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=s),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=c.call(o,"catchLoc"),u=c.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,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&c.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(i)},complete:function(t,e){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&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=s),d}}}function b(t,e,r,n){var i,a,u,s,o=e&&e.prototype instanceof x?e:x,c=Object.create(o.prototype),f=new A(n||[]);return c._invoke=(i=t,a=r,u=f,s=l,function(t,e){if(s===h)throw new Error("Generator is already running");if(s===y){if("throw"===t)throw e;return T()}for(u.method=t,u.arg=e;;){var r=u.delegate;if(r){var n=_(r,u);if(n){if(n===d)continue;return n}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(s===l)throw s=y,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);s=h;var o=w(i,a,u);if("normal"===o.type){if(s=u.done?y:p,o.arg===d)continue;return{value:o.arg,done:u.done}}"throw"===o.type&&(s=y,u.method="throw",u.arg=o.arg)}}),c}function w(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function x(){}function k(){}function E(){}function O(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function j(s){var e;this._invoke=function(r,n){function t(){return new Promise(function(t,e){!function e(t,r,n,o){var i=w(s[t],s,r);if("throw"!==i.type){var a=i.arg,u=a.value;return u&&"object"==typeof u&&c.call(u,"__await")?Promise.resolve(u.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):Promise.resolve(u).then(function(t){a.value=t,n(a)},o)}o(i.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}}function _(t,e){var r=t.iterator[e.method];if(r===s){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=s,_(t,e),"throw"===e.method))return d;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var n=w(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,d;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=s),e.delegate=null,d):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function R(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function L(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(c.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=s,t.done=!0,t};return n.next=n}}return{next:T}}function T(){return{value:s,done:!0}}}(function(){return this}()||Function("return this")()),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.ReteEngine={})}(this,function(t){"use strict";var a="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},y=function(t){return function(){var u=t.apply(this,arguments);return new Promise(function(i,a){return function e(t,r){try{var n=u[t](r),o=n.value}catch(t){return void a(t)}if(!n.done)return Promise.resolve(o).then(function(t){e("next",t)},function(t){e("throw",t)});i(o)}("next")})}},h=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},d=function(){function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},v=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},m=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},g=function(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)},b=function(){function e(t){if(h(this,e),this.constructor===e)throw new TypeError("Can not construct abstract class.");this.name=t,this.data={},this.engine=null}return d(e,[{key:"worker",value:function(){}}]),e}(),n=function t(e){h(this,t),this.handlers=r({warn:[console.warn],error:[console.error]},e)},e=function(){function e(t){if(h(this,e),!(t instanceof n||t instanceof e))throw new TypeError('Value of argument "events" violates contract.\n\nExpected:\nEvents | Emitter\n\nGot:\n'+u(t));this.events=t instanceof e?t.events:t.handlers,this.silent=!1}return d(e,[{key:"on",value:function(t,e){var r=this;if("string"!=typeof t)throw new TypeError('Value of argument "names" violates contract.\n\nExpected:\nstring\n\nGot:\n'+u(t));if("function"!=typeof e)throw new TypeError('Value of argument "handler" violates contract.\n\nExpected:\n() => {}\n\nGot:\n'+u(e));return t.split(" ").forEach(function(t){if(!r.events[t])throw new Error("The event "+t+" does not exist");r.events[t].push(e)}),this}},{key:"trigger",value:function(t,r){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+u(t));if(!(t in this.events))throw new Error("The event "+t+" cannot be triggered");return this.events[t].reduce(function(t,e){return!1!==e(r)&&t},!0)}},{key:"bind",value:function(t){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+u(t));if(this.events[t])throw new Error("The event "+t+" is already bound");this.events[t]=[]}},{key:"exist",value:function(t){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+u(t));return Array.isArray(this.events[t])}}]),e}();function u(e,r){if(void 0===r&&(r=0),r+=1,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":a(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var n=u(e[0],r);return e.every(function(t){return u(t,r)===n})?n.trim()+"[]":"["+e.slice(0,15).map(function(t){return u(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 o=" ".repeat(r-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+u(e[t],r)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}var w=function(){function t(){h(this,t)}return d(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,e){var r="",n=t.split("@"),o=e.id.split("@");return this.isValidData(e)||(r+="Data is not suitable. "),t!==e.id&&(r+="IDs not equal. "),n[0]!==o[0]&&(r+="Names don't match. "),n[1]!==o[1]&&(r+="Versions don't match"),{success:""===r,msg:r}}}]),t}(),x=function(t){function n(t,e){h(this,n);var r=m(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));if(!w.isValidId(t))throw new Error("ID should be valid to name@0.1.0 format");return r.id=t,r.plugins=new Map,r}return v(n,e),d(n,[{key:"use",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(t.name&&this.plugins.has(t.name))throw new Error("Plugin "+t.name+" already in use");t.install(this,e),this.plugins.set(t.name,e)}}]),n}(),k=function(t){function e(){return h(this,e),m(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{componentregister:[]}))}return v(e,n),e}(),E=0,O=1,j=2,o=function(t){function r(t){if(h(this,r),"string"!=typeof t)throw new TypeError('Value of argument "id" violates contract.\n\nExpected:\nstring\n\nGot:\n'+_(t));var e=m(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,t,new k));return e.components=[],e.args=[],e.data=null,e.state=E,e.onAbort=function(){},e}var e,n,o,i,a,u,s,c,f,l,p;return v(r,x),d(r,[{key:"clone",value:function(){var e=new r(this.id);return this.components.map(function(t){return e.register(t)}),e}},{key:"register",value:function(t){if(!(t instanceof b))throw new TypeError('Value of argument "component" violates contract.\n\nExpected:\nComponent\n\nGot:\n'+_(t));this.components.push(t),this.trigger("componentregister",t)}},{key:"throwError",value:(p=y(regeneratorRuntime.mark(function t(e){var r=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:e,data:r}),this.processDone(),t.abrupt("return","error");case 5:case"end":return t.stop()}},t,this)})),function(t){return p.apply(this,arguments)})},{key:"extractInputNodes",value:function(r,n){return Object.keys(r.inputs).reduce(function(t,e){return[].concat(g(t),g((r.inputs[e].connections||[]).reduce(function(t,e){return[].concat(g(t),[n[e.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(e,r){if(r.some(function(t){return t===e}))return e;for(var n=0;n<r.length;n++)if(t(e,i.extractInputNodes(r[n],o)))return e;return null}(t,i.extractInputNodes(t,o))}).filter(function(t){return null!==t})}},{key:"processStart",value:function(){return this.state===E?(this.state=O,!0):(this.state===j||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!==j;return this.state=E,t||(this.onAbort(),this.onAbort=function(){}),t}},{key:"abort",value:(l=y(regeneratorRuntime.mark(function t(){var e=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){e.state===O?(e.state=j,e.onAbort=t):e.state===j?(e.onAbort(),e.onAbort=t):t()}));case 1:case"end":return t.stop()}},t,this)})),function(){return l.apply(this,arguments)})},{key:"lock",value:(f=y(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){e.unlockPool=e.unlockPool||[],e.busy&&!e.outputData?e.unlockPool.push(t):t(),e.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:(c=y(regeneratorRuntime.mark(function t(e){var r,n,o,i,a,u,s,c,f,l,p,h=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r={},!(s=Object.keys(e.inputs))||"function"!=typeof s[Symbol.iterator]&&!Array.isArray(s))throw new TypeError("Expected _Object$keys to be iterable, got "+_(s));t.next=4;break;case 4:o=!(n=!0),i=void 0,t.prev=7,a=s[Symbol.iterator]();case 9:if(n=(u=a.next()).done){t.next=20;break}return c=u.value,f=e.inputs[c],l=f.connections,t.next=15,Promise.all(l.map(function(){var e=y(regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=h.data.nodes[e.node],t.next=3,h.processNode(r);case 3:if(n=t.sent){t.next=8;break}h.abort(),t.next=9;break;case 8:return t.abrupt("return",n[e.output]);case 9:case"end":return t.stop()}},t,h)}));return function(t){return e.apply(this,arguments)}}()));case 15:p=t.sent,r[c]=p;case 17:n=!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,!n&&a.return&&a.return();case 29:if(t.prev=29,o)throw i;t.next=32;break;case 32:return t.finish(29);case 33:return t.finish(26);case 34:return t.abrupt("return",r);case 35:case"end":return t.stop()}},t,this,[[7,22,26,34],[27,,29,33]])})),function(t){return c.apply(this,arguments)})},{key:"processWorker",value:(s=y(regeneratorRuntime.mark(function t(e){var r,n,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.extractInputData(e);case 2:return r=t.sent,n=this.components.find(function(t){return t.name===e.name}),o={},t.prev=5,t.next=8,n.worker.apply(n,[e,r,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 s.apply(this,arguments)})},{key:"processNode",value:(u=y(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==j&&e){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,this.lock(e);case 4:return e.outputData||(e.outputData=this.processWorker(e)),this.unlock(e),t.abrupt("return",e.outputData);case 7:case"end":return t.stop()}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"forwardProcess",value:(a=y(regeneratorRuntime.mark(function t(n){var o=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state===j)return t.abrupt("return",null);t.next=2;break;case 2:return t.next=4,Promise.all(Object.keys(n.outputs).map(function(){var e=y(regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.outputs[e],t.next=3,Promise.all(r.connections.map(function(){var e=y(regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=o.data.nodes[e.node],t.next=3,o.processNode(r);case 3:return t.next=5,o.forwardProcess(r);case 5:case"end":return t.stop()}},t,o)}));return function(t){return e.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,o)}));return function(t){return e.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(e){return(e=Object.assign({},e)).nodes=Object.assign({},e.nodes),Object.keys(e.nodes).forEach(function(t){e.nodes[t]=Object.assign({},e.nodes[t])}),e}},{key:"validate",value:(i=y(regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((r=w.validate(this.id,e)).success){t.next=5;break}return t.next=4,this.throwError(r.msg);case 4:return t.abrupt("return",t.sent);case 5:if(0<(n=this.detectRecursions(e.nodes)).length)return t.next=9,this.throwError("Recursion detected",n);t.next=10;break;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=y(regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e){t.next=10;break}if(r=this.data.nodes[e]){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(r);case 8:return t.next=10,this.forwardProcess(r);case 10:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"processUnreachable",value:(n=y(regeneratorRuntime.mark(function t(){var e,r;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(e=t.t1.value,void 0===this.data.nodes[e].outputData)return r=this.data.nodes[e],t.next=7,this.processNode(r);t.next=9;break;case 7:return t.next=9,this.forwardProcess(r);case 9:t.next=1;break;case 11:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})},{key:"process",value:(e=y(regeneratorRuntime.mark(function t(e){for(var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length,o=Array(2<n?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e instanceof Object){t.next=2;break}throw new TypeError('Value of argument "data" violates contract.\n\nExpected:\nObject\n\nGot:\n'+_(e));case 2:if(null!=r&&"number"!=typeof r)throw new TypeError('Value of argument "startId" violates contract.\n\nExpected:\n?number\n\nGot:\n'+_(r));t.next=4;break;case 4:if(this.processStart()){t.next=6;break}return t.abrupt("return");case 6:if(this.validate(e)){t.next=8;break}return t.abrupt("return");case 8:return this.data=this.copy(e),this.args=o,t.next=12,this.processStartNode(r);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 e.apply(this,arguments)})}]),r}();function _(e,r){if(void 0===r&&(r=0),r+=1,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":a(e);if(Array.isArray(e)){if(0<e.length){if(4<r)return"[...]";var n=_(e[0],r);return e.every(function(t){return _(t,r)===n})?n.trim()+"[]":"["+e.slice(0,15).map(function(t){return _(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 o=" ".repeat(r-1),i=t.slice(0,15).map(function(t){return(/^([A-Z_$][A-Z0-9_$]*)$/i.test(t)?t:JSON.stringify(t))+": "+_(e[t],r)+";"}).join("\n "+o);return 15<=t.length&&(i+="\n "+o+"..."),e.constructor&&e.constructor.name&&"Object"!==e.constructor.name?e.constructor.name+" {\n "+o+i+"\n"+o+"}":"{\n "+o+i+"\n"+o+"}"}t.Component=b,t.Engine=o,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t){"use strict";var s,e=Object.prototype,c=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",n=r.asyncIterator||"@@asyncIterator",i=r.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 h="suspendedStart",l="suspendedYield",p="executing",d="completed",y={},f={};f[o]=function(){return this};var v=Object.getPrototypeOf,m=v&&v(v(N([])));m&&m!==e&&c.call(m,o)&&(f=m);var g=E.prototype=x.prototype=Object.create(f);k.prototype=g.constructor=E,E.constructor=k,E[i]=k.displayName="GeneratorFunction",u.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===k||"GeneratorFunction"===(e.displayName||e.name))},u.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,i in t||(t[i]="GeneratorFunction")),t.prototype=Object.create(g),t},u.awrap=function(t){return{__await:t}},O(j.prototype),j.prototype[n]=function(){return this},u.AsyncIterator=j,u.async=function(t,e,r,n){var o=new j(w(t,e,r,n));return u.isGeneratorFunction(e)?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(r){var n=[];for(var t in r)n.push(t);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},u.values=N,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&c.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=s)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=s),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=c.call(o,"catchLoc"),u=c.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,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&c.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(i)},complete:function(t,e){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&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:N(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=s),y}}}function w(t,e,r,n){var i,a,u,s,o=e&&e.prototype instanceof x?e:x,c=Object.create(o.prototype),f=new _(n||[]);return c._invoke=(i=t,a=r,u=f,s=h,function(t,e){if(s===p)throw new Error("Generator is already running");if(s===d){if("throw"===t)throw e;return A()}for(u.method=t,u.arg=e;;){var r=u.delegate;if(r){var n=R(r,u);if(n){if(n===y)continue;return n}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(s===h)throw s=d,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);s=p;var o=b(i,a,u);if("normal"===o.type){if(s=u.done?d:l,o.arg===y)continue;return{value:o.arg,done:u.done}}"throw"===o.type&&(s=d,u.method="throw",u.arg=o.arg)}}),c}function b(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function x(){}function k(){}function E(){}function O(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function j(s){var e;this._invoke=function(r,n){function t(){return new Promise(function(t,e){!function e(t,r,n,o){var i=b(s[t],s,r);if("throw"!==i.type){var a=i.arg,u=a.value;return u&&"object"==typeof u&&c.call(u,"__await")?Promise.resolve(u.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):Promise.resolve(u).then(function(t){a.value=t,n(a)},o)}o(i.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}}function R(t,e){var r=t.iterator[e.method];if(r===s){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=s,R(t,e),"throw"===e.method))return y;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var n=b(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,y;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=s),e.delegate=null,y):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function N(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(c.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=s,t.done=!0,t};return n.next=n}}return{next:A}}function A(){return{value:s,done:!0}}}(function(){return this}()||Function("return this")()),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.ReteEngine={})}(this,function(t){"use strict";function s(t,e,r,n,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}function p(u){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=u.apply(t,a);function o(t){s(n,e,r,o,i,"next",t)}function i(t){s(n,e,r,o,i,"throw",t)}o(void 0)})}}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function y(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}function v(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}function m(t){return(m=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function r(t,e){return(r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function g(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function w(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var e=function(){function e(t){if(d(this,e),this.constructor===e)throw new TypeError("Can not construct abstract class.");this.name=t,this.data={},this.engine=null}return y(e,[{key:"worker",value:function(){}}]),e}(),o=function t(e){d(this,t),this.handlers=function(o){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{},e=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(i).filter(function(t){return Object.getOwnPropertyDescriptor(i,t).enumerable}))),e.forEach(function(t){var e,r,n;e=o,n=i[r=t],r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n})}return o}({warn:[console.warn],error:[console.error]},e)},i=function(){function e(t){d(this,e),this.events=t instanceof e?t.events:t.handlers,this.silent=!1}return y(e,[{key:"on",value:function(t,e){var r=this;return t.split(" ").forEach(function(t){if(!r.events[t])throw new Error("The event ".concat(t," does not exist"));r.events[t].push(e)}),this}},{key:"trigger",value:function(t,r){if(!(t in this.events))throw new Error("The event ".concat(t," cannot be triggered"));return this.events[t].reduce(function(t,e){return!1!==e(r)&&t},!0)}},{key:"bind",value:function(t){if(this.events[t])throw new Error("The event ".concat(t," is already bound"));this.events[t]=[]}},{key:"exist",value:function(t){return Array.isArray(this.events[t])}}]),e}(),b=function(){function t(){d(this,t)}return y(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,e){var r="",n=t.split("@"),o=e.id.split("@");return this.isValidData(e)||(r+="Data is not suitable. "),t!==e.id&&(r+="IDs not equal. "),n[0]!==o[0]&&(r+="Names don't match. "),n[1]!==o[1]&&(r+="Versions don't match"),{success:""===r,msg:r}}}]),t}(),x=function(t){function n(t,e){var r;if(d(this,n),r=g(this,m(n).call(this,e)),!b.isValidId(t))throw new Error("ID should be valid to name@0.1.0 format");return r.id=t,r.plugins=new Map,r}return v(n,i),y(n,[{key:"use",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(t.name&&this.plugins.has(t.name))throw new Error("Plugin ".concat(t.name," already in use"));t.install(this,e),this.plugins.set(t.name,e)}}]),n}(),k=function(t){function e(){return d(this,e),g(this,m(e).call(this,{componentregister:[]}))}return v(e,o),e}(),E=0,O=1,j=2,a=function(t){function r(t){var e;return d(this,r),(e=g(this,m(r).call(this,t,new k))).components=[],e.args=[],e.data=null,e.state=E,e.onAbort=function(){},e}var e,n,o,i,a,u,s,c,f,h,l;return v(r,x),y(r,[{key:"clone",value:function(){var e=new r(this.id);return this.components.map(function(t){return e.register(t)}),e}},{key:"register",value:function(t){this.components.push(t),this.trigger("componentregister",t)}},{key:"throwError",value:(l=p(regeneratorRuntime.mark(function t(e){var r,n=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=1<n.length&&void 0!==n[1]?n[1]:null,t.next=3,this.abort();case 3:return this.trigger("error",{message:e,data:r}),this.processDone(),t.abrupt("return","error");case 6:case"end":return t.stop()}},t,this)})),function(t){return l.apply(this,arguments)})},{key:"extractInputNodes",value:function(r,n){return Object.keys(r.inputs).reduce(function(t,e){return[].concat(w(t),w((r.inputs[e].connections||[]).reduce(function(t,e){return[].concat(w(t),[n[e.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(e,r){if(r.some(function(t){return t===e}))return e;for(var n=0;n<r.length;n++)if(t(e,i.extractInputNodes(r[n],o)))return e;return null}(t,i.extractInputNodes(t,o))}).filter(function(t){return null!==t})}},{key:"processStart",value:function(){return this.state===E?(this.state=O,!0):(this.state===j||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!==j;return this.state=E,t||(this.onAbort(),this.onAbort=function(){}),t}},{key:"abort",value:(h=p(regeneratorRuntime.mark(function t(){var e=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){e.state===O?(e.state=j,e.onAbort=t):e.state===j?(e.onAbort(),e.onAbort=t):t()}));case 1:case"end":return t.stop()}},t,this)})),function(){return h.apply(this,arguments)})},{key:"lock",value:(f=p(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){e.unlockPool=e.unlockPool||[],e.busy&&!e.outputData?e.unlockPool.push(t):t(),e.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:(c=p(regeneratorRuntime.mark(function t(e){var r,n,o,i,a,u,s,c=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:r={},n=Object.keys(e.inputs),o=0;case 3:if(o<n.length)return i=n[o],a=e.inputs[i],u=a.connections,t.next=9,Promise.all(u.map(function(){var e=p(regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=c.data.nodes[e.node],t.next=3,c.processNode(r);case 3:if(n=t.sent){t.next=8;break}c.abort(),t.next=9;break;case 8:return t.abrupt("return",n[e.output]);case 9:case"end":return t.stop()}},t,this)}));return function(t){return e.apply(this,arguments)}}()));t.next=14;break;case 9:s=t.sent,r[i]=s;case 11:o++,t.next=3;break;case 14:return t.abrupt("return",r);case 15:case"end":return t.stop()}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"processWorker",value:(s=p(regeneratorRuntime.mark(function t(e){var r,n,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.extractInputData(e);case 2:return r=t.sent,n=this.components.find(function(t){return t.name===e.name}),o={},t.prev=5,t.next=8,n.worker.apply(n,[e,r,o].concat(w(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 s.apply(this,arguments)})},{key:"processNode",value:(u=p(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==j&&e){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,this.lock(e);case 4:return e.outputData||(e.outputData=this.processWorker(e)),this.unlock(e),t.abrupt("return",e.outputData);case 7:case"end":return t.stop()}},t,this)})),function(t){return u.apply(this,arguments)})},{key:"forwardProcess",value:(a=p(regeneratorRuntime.mark(function t(n){var o=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state===j)return t.abrupt("return",null);t.next=2;break;case 2:return t.next=4,Promise.all(Object.keys(n.outputs).map(function(){var e=p(regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.outputs[e],t.next=3,Promise.all(r.connections.map(function(){var e=p(regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=o.data.nodes[e.node],t.next=3,o.processNode(r);case 3:return t.next=5,o.forwardProcess(r);case 5:case"end":return t.stop()}},t,this)}));return function(t){return e.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,this)}));return function(t){return e.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(e){return(e=Object.assign({},e)).nodes=Object.assign({},e.nodes),Object.keys(e.nodes).forEach(function(t){e.nodes[t]=Object.assign({},e.nodes[t])}),e}},{key:"validate",value:(i=p(regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((r=b.validate(this.id,e)).success){t.next=5;break}return t.next=4,this.throwError(r.msg);case 4:return t.abrupt("return",t.sent);case 5:if(0<(n=this.detectRecursions(e.nodes)).length)return t.next=9,this.throwError("Recursion detected",n);t.next=10;break;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=p(regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e){t.next=10;break}if(r=this.data.nodes[e]){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(r);case 8:return t.next=10,this.forwardProcess(r);case 10:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"processUnreachable",value:(n=p(regeneratorRuntime.mark(function t(){var e,r;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(e=t.t1.value,void 0===this.data.nodes[e].outputData)return r=this.data.nodes[e],t.next=7,this.processNode(r);t.next=9;break;case 7:return t.next=9,this.forwardProcess(r);case 9:t.next=1;break;case 11:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})},{key:"process",value:(e=p(regeneratorRuntime.mark(function t(e){var r,n,o,i,a=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=1<a.length&&void 0!==a[1]?a[1]:null,this.processStart()){t.next=3;break}return t.abrupt("return");case 3:if(this.validate(e)){t.next=5;break}return t.abrupt("return");case 5:for(this.data=this.copy(e),n=a.length,o=new Array(2<n?n-2:0),i=2;i<n;i++)o[i-2]=a[i];return this.args=o,t.next=10,this.processStartNode(r);case 10:return t.next=12,this.processUnreachable();case 12:return t.abrupt("return",this.processDone()?"success":"aborted");case 13:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})}]),r}();t.Component=e,t.Engine=a,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=rete-engine.min.js.map |
/*! | ||
* rete v1.0.1 | ||
* rete v1.0.2 | ||
* (c) 2019 Ni55aN | ||
* Released under the MIT license. | ||
*/ | ||
!function(t){"use strict";var u,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,c=t.regeneratorRuntime;if(c)a&&(module.exports=c);else{(c=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",c.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return!!n&&(n===E||"GeneratorFunction"===(n.displayName||n.name))},c.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},c.awrap=function(t){return{__await:t}},O(j.prototype),j.prototype[r]=function(){return this},c.AsyncIterator=j,c.async=function(t,n,e,r){var o=new j(w(t,n,e,r));return c.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]"},c.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}},c.values=N,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(A),!t)for(var n in this)"t"===n.charAt(0)&&s.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=u)},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=u),!!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"),c=s.call(o,"finallyLoc");if(a&&c){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(!c)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=u),v}}}function w(t,n,e,r){var i,a,c,u,o=n&&n.prototype instanceof k?n:k,s=Object.create(o.prototype),f=new C(r||[]);return s._invoke=(i=t,a=e,c=f,u=l,function(t,n){if(u===p)throw new Error("Generator is already running");if(u===d){if("throw"===t)throw n;return S()}for(c.method=t,c.arg=n;;){var e=c.delegate;if(e){var r=_(e,c);if(r){if(r===v)continue;return r}}if("next"===c.method)c.sent=c._sent=c.arg;else if("throw"===c.method){if(u===l)throw u=d,c.arg;c.dispatchException(c.arg)}else"return"===c.method&&c.abrupt("return",c.arg);u=p;var o=b(i,a,c);if("normal"===o.type){if(u=c.done?d:h,o.arg===v)continue;return{value:o.arg,done:c.done}}"throw"===o.type&&(u=d,c.method="throw",c.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(u){var n;this._invoke=function(e,r){function t(){return new Promise(function(t,n){!function n(t,e,r,o){var i=b(u[t],u,e);if("throw"!==i.type){var a=i.arg,c=a.value;return c&&"object"==typeof c&&s.call(c,"__await")?Promise.resolve(c.__await).then(function(t){n("next",t,r,o)},function(t){n("throw",t,r,o)}):Promise.resolve(c).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===u){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=u,_(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=u),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=u,t.done=!0,t};return r.next=r}}return{next:S}}function S(){return{value:u,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 c="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 c=t.apply(this,arguments);return new Promise(function(i,a){return function n(t,e){try{var r=c[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}}(),u=function(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t},s=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},f=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,c=t[Symbol.iterator]();!(r=(a=c.next()).done)&&(e.push(a.value),!n||e.length!==n);r=!0);}catch(t){o=!0,i=t}finally{try{!r&&c.return&&c.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");if(!t)throw new Error("The key parameter is missing in super() of Control ");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}(),l=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":c(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 h=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'+b(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'+b(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'+b(t));return this===t||this.compatible.includes(t)}}]),e}();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":c(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 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'+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 h))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,l),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":c(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 h))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,l),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'+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 i))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":c(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 i))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 i))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:"update",value:function(){}},{key:"toJSON",value:function(){return{id:this.id,data:this.data,inputs:Array.from(this.inputs).reduce(function(t,n){var e=f(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=f(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":c(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 j=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:"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'+_(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 _(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":c(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=_(n[0],e);return n.every(function(t){return _(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return _(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))+": "+_(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(n){p(this,t),this.handlers=s({warn:[console.warn],error:[console.error]},n)},T=function(){function n(t){if(p(this,n),!(t instanceof e||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)}},{key:"bind",value:function(t){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+A(t));if(this.events[t])throw new Error("The event "+t+" is already bound");this.events[t]=[]}},{key:"exist",value:function(t){if("string"!=typeof t)throw new TypeError('Value of argument "name" violates contract.\n\nExpected:\nstring\n\nGot:\n'+A(t));return Array.isArray(this.events[t])}}]),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":c(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.plugins=new Map,e}return m(r,T),v(r,[{key:"use",value:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(t.name&&this.plugins.has(t.name))throw new Error("Plugin "+t.name+" already in use");t.install(this,n),this.plugins.set(t.name,n)}}]),r}(),S=function(t){function n(){return p(this,n),y(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,{componentregister:[]}))}return m(n,e),n}(),G=0,V=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 S));return n.components=[],n.args=[],n.data=null,n.state=G,n.onAbort=function(){},n}var n,r,o,i,a,c,u,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===G?(this.state=V,!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=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===V?(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,c,u,s,f,l,h,p=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e={},!(u=Object.keys(n.inputs))||"function"!=typeof u[Symbol.iterator]&&!Array.isArray(u))throw new TypeError("Expected _Object$keys to be iterable, got "+L(u));t.next=4;break;case 4:o=!(r=!0),i=void 0,t.prev=7,a=u[Symbol.iterator]();case 9:if(r=(c=a.next()).done){t.next=20;break}return s=c.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)throw i;t.next=32;break;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:(u=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 u.apply(this,arguments)})},{key:"processNode",value:(c=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 c.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)return t.abrupt("return",null);t.next=2;break;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)return t.next=9,this.throwError("Recursion detected",r);t.next=10;break;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)return e=this.data.nodes[n],t.next=7,this.processNode(e);t.next=9;break;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)throw new TypeError('Value of argument "startId" violates contract.\n\nExpected:\n?number\n\nGot:\n'+L(e));t.next=4;break;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":c(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:[],translatenode:[],nodetranslate:[],nodetranslated:[],nodedraged:[],selectnode:[],nodeselect:[],nodeselected:[],rendernode:[],rendersocket:[],rendercontrol:[],renderconnection:[],updateconnection:[],componentregister:[],keydown:[],keyup:[],translate:[],translated:[],zoom:[],zoomed:[],click:[],mousemove:[],contextmenu:[],import:[],export:[],process:[]}))}return m(n,e),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(t)}},{key:"move",value:function(t){if(this.mouseStart){t.preventDefault(),t.stopPropagation();var n=this.getCoords(t),e=f(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,t)}}},{key:"up",value:function(t){this.mouseStart&&(this.mouseStart=null,this.onDrag(t))}}]),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)),t.addEventListener("dblclick",this.dblclick.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.clientX)*e,o=(n.top-t.clientY)*e;this.onzoom(e,r,o,"wheel")}},{key:"touches",value:function(t){var n=[t.touches[0].clientX,t.touches[0].clientY],e=n[0],r=n[1],o=[t.touches[1].clientX,t.touches[1].clientY],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,c=(n.left-r)*a,u=(n.top-o)*a;this.onzoom(a,c,u,"touch")}this.distance=i}}},{key:"end",value:function(){this.distance=null}},{key:"dblclick",value:function(t){t.preventDefault();var n=this.el.getBoundingClientRect(),e=4*this.intensity,r=(n.left-t.clientX)*e,o=(n.top-t.clientY)*e;this.onzoom(e,r,o,"dblclick")}}]),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":c(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.container.addEventListener("touchmove",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=t instanceof TouchEvent?t.touches[0]:t,e=n.clientX,r=n.clientY,o=this.el.getBoundingClientRect(),i=e-o.left,a=r-o.top,c=this.transform.k;this.mouse={x:i/c,y:a/c},this.trigger("mousemove",s({},this.mouse))}},{key:"onStart",value:function(){this._startPosition=s({},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,r){this.zoom(this.transform.k*(1+t),n,e,r),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=arguments[3],o=this.transform.k,i={transform:this.transform,zoom:t,source:r};if(this.trigger("zoom",i)){var a=(o-i.zoom)/(o-t||1);this.transform.k=i.zoom||1,this.transform.x+=n*a,this.transform.y+=e*a,this.update(),this.trigger("zoomed",{source:r})}}},{key:"appendChild",value:function(t){this.el.appendChild(t)}},{key:"removeChild",value:function(t){this.el.removeChild(t)}}]),o}();var D=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}(),J=function(t){function c(t,n,e,r,o){var i;p(this,c);var a=y(this,(c.__proto__||Object.getPrototypeOf(c)).call(this,o));return a.el=t,a.type=n,a.io=e,a.node=r,a.trigger("rendersocket",(u(i={el:t},n,a.io),u(i,"socket",e.socket),i)),a}return m(c,T),v(c,[{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]}}]),c}(),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),function(){r.trigger("nodedraged",t)}),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 l))throw new TypeError('Value of argument "io" violates contract.\n\nExpected:\nIO\n\nGot:\n'+z(e));this.sockets.set(e,new J(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 D(t,n,this))}},{key:"getSocketPosition",value:function(t){return this.sockets.get(t).getPosition(this.node)}},{key:"onSelect",value:function(t){this.onStart(),this.trigger("selectnode",{node:this.node,accumulate:t.ctrlKey})}},{key:"onStart",value:function(){this._startPosition=[].concat(g(this.node.position))}},{key:"onTranslate",value:function(t,n){this.trigger("translatenode",{node:this.node,dx:t,dy:n})}},{key:"onDrag",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};if(this.trigger("nodetranslate",r)){var o=[].concat(g(e.position));e.position[0]=r.x,e.position[1]=r.y,this.update(),this.trigger("nodetranslated",{node:e,prev:o})}}},{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":c(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'+Y(n));if(!(e instanceof M))throw new TypeError('Value of argument "outputNode" violates contract.\n\nExpected:\nViewNode\n\nGot:\n'+Y(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.trigger("renderconnection",{el:o.el,connection:o.connection,points:o.getPoints()}),o}return m(i,T),v(i,[{key:"getPoints",value:function(){var t=this.outputNode.getSocketPosition(this.connection.output),n=f(t,2),e=n[0],r=n[1],o=this.inputNode.getSocketPosition(this.connection.input),i=f(o,2);return[e,r,i[0],i[1]]}},{key:"update",value:function(){this.trigger("updateconnection",{el:this.el,connection:this.connection,points:this.getPoints()})}}]),i}();function Y(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":c(n);if(Array.isArray(n)){if(0<n.length){if(4<e)return"[...]";var r=Y(n[0],e);return n.every(function(t){return Y(t,e)===r})?r.trim()+"[]":"["+n.slice(0,15).map(function(t){return Y(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))+": "+Y(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 W=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":c(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":c(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.list.push(t):this.list=[t]}},{key:"clear",value:function(){this.list=[]}},{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 e(t,n){if(p(this,e),"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 r=y(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,new R));return r.nodes=[],r.components=new Map,r.selected=new X,r.view=new W(n,r.components,r),window.addEventListener("keydown",function(t){return r.trigger("keydown",t)}),window.addEventListener("keyup",function(t){return r.trigger("keyup",t)}),r.on("selectnode",function(t){var n=t.node,e=t.accumulate;return r.selectNode(n,e)}),r.on("nodeselected",function(){return r.selected.each(function(t){return r.view.nodes.get(t).onStart()})}),r.on("translatenode",function(t){var n=t.dx,e=t.dy;return r.selected.each(function(t){return r.view.nodes.get(t).onDrag(n,e)})}),r}var n;return m(e,N),v(e,[{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 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 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 j))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 c,u=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 c={},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=u.getComponent(e.name),t.next=4,r.build(x.fromJSON(e));case 4:c[n]=t.sent,u.addNode(c[n]);case 6:case"end":return t.stop()}},t,u)}));return function(t){return n.apply(this,arguments)}}()));case 8:Object.keys(o.nodes).forEach(function(t){var n=o.nodes[t],a=c[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=c[n].inputs.get(t.input);u.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)})}]),e}();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":c(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:j,Control:r,NodeEditor:n,Emitter:T,Engine:t,Input:i,Node:x,Output:o,Socket:h}}); | ||
!function(t){"use strict";var u,e=Object.prototype,c=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag",s="object"==typeof module,a=t.regeneratorRuntime;if(a)s&&(module.exports=a);else{(a=t.regeneratorRuntime=s?module.exports:{}).wrap=k;var l="suspendedStart",d="suspendedYield",f="executing",p="completed",v={},h={};h[o]=function(){return this};var m=Object.getPrototypeOf,y=m&&m(m(L([])));y&&y!==e&&c.call(y,o)&&(h=y);var g=E.prototype=b.prototype=Object.create(h);x.prototype=g.constructor=E,E.constructor=x,E[i]=x.displayName="GeneratorFunction",a.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===x||"GeneratorFunction"===(e.displayName||e.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,i in t||(t[i]="GeneratorFunction")),t.prototype=Object.create(g),t},a.awrap=function(t){return{__await:t}},C(O.prototype),O.prototype[r]=function(){return this},a.AsyncIterator=O,a.async=function(t,e,n,r){var o=new O(k(t,e,n,r));return a.isGeneratorFunction(e)?o:o.next().then(function(t){return t.done?t.value:o.next()})},C(g),g[i]="Generator",g[o]=function(){return this},g.toString=function(){return"[object Generator]"},a.keys=function(n){var r=[];for(var t in n)r.push(t);return r.reverse(),function t(){for(;r.length;){var e=r.pop();if(e in n)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=L,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(R),!t)for(var e in this)"t"===e.charAt(0)&&c.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=u)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var r=this;function t(t,e){return i.type="throw",i.arg=n,r.next=t,e&&(r.method="next",r.arg=u),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var s=c.call(o,"catchLoc"),a=c.call(o,"finallyLoc");if(s&&a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&c.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(t,e){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&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),R(n),v}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;R(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:L(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=u),v}}}function k(t,e,n,r){var i,s,a,u,o=e&&e.prototype instanceof b?e:b,c=Object.create(o.prototype),h=new S(r||[]);return c._invoke=(i=t,s=n,a=h,u=l,function(t,e){if(u===f)throw new Error("Generator is already running");if(u===p){if("throw"===t)throw e;return j()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){var r=P(n,a);if(r){if(r===v)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(u===l)throw u=p,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);u=f;var o=w(i,s,a);if("normal"===o.type){if(u=a.done?p:d,o.arg===v)continue;return{value:o.arg,done:a.done}}"throw"===o.type&&(u=p,a.method="throw",a.arg=o.arg)}}),c}function w(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}function b(){}function x(){}function E(){}function C(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function O(u){var e;this._invoke=function(n,r){function t(){return new Promise(function(t,e){!function e(t,n,r,o){var i=w(u[t],u,n);if("throw"!==i.type){var s=i.arg,a=s.value;return a&&"object"==typeof a&&c.call(a,"__await")?Promise.resolve(a.__await).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):Promise.resolve(a).then(function(t){s.value=t,r(s)},o)}o(i.arg)}(n,r,t,e)})}return e=e?e.then(t,t):t()}}function P(t,e){var n=t.iterator[e.method];if(n===u){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=u,P(t,e),"throw"===e.method))return v;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var r=w(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,v;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=u),e.delegate=null,v):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}function N(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(N,this),this.reset(!0)}function L(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function t(){for(;++n<e.length;)if(c.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=u,t.done=!0,t};return r.next=r}}return{next:j}}function j(){return{value:u,done:!0}}}(function(){return this}()||Function("return this")()),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Rete={})}(this,function(t){"use strict";function u(t,e,n,r,o,i,s){try{var a=t[i](s),u=a.value}catch(t){return void n(t)}a.done?e(u):Promise.resolve(u).then(r,o)}function f(a){return function(){var t=this,s=arguments;return new Promise(function(e,n){var r=a.apply(t,s);function o(t){u(r,e,n,o,i,"next",t)}function i(t){u(r,e,n,o,i,"throw",t)}o(void 0)})}}function p(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function v(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(t){c(e,t,n[t])})}return e}function m(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}function y(t){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function g(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?i(t):e}function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var s,a=t[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function k(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var a=function(){function e(t){if(p(this,e),this.constructor===e)throw new TypeError("Can not construct abstract class.");this.name=t,this.data={},this.engine=null}return v(e,[{key:"worker",value:function(){}}]),e}(),e=function(){function e(t){if(p(this,e),this.constructor===e)throw new TypeError("Can not construct abstract class");if(!t)throw new Error("The key parameter is missing in super() of Control ");this.key=t,this.data={},this.parent=null}return v(e,[{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,e){this.getNode().data[t]=e}}]),e}(),l=function(){function n(t,e){p(this,n),this.output=t,this.input=e,this.data={},this.input.addConnection(this)}return v(n,[{key:"remove",value:function(){this.input.removeConnection(this),this.output.removeConnection(this)}}]),n}(),d=function(){function o(t,e,n,r){p(this,o),this.node=null,this.multipleConnections=r,this.connections=[],this.key=t,this.name=e,this.socket=n}return v(o,[{key:"removeConnection",value:function(t){this.connections.splice(this.connections.indexOf(t),1)}},{key:"removeConnections",value:function(){var e=this;this.connections.map(function(t){return e.removeConnection(t)})}}]),o}(),o=function(){function n(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};p(this,n),this.name=t,this.data=e,this.compatible=[]}return v(n,[{key:"combineWith",value:function(t){this.compatible.push(t)}},{key:"compatibleWith",value:function(t){return this===t||this.compatible.includes(t)}}]),n}(),w=function(t){function i(t,e,n){var r,o=3<arguments.length&&void 0!==arguments[3]&&arguments[3];return p(this,i),(r=g(this,y(i).call(this,t,e,n,o))).control=null,r}return m(i,d),v(i,[{key:"hasConnection",value:function(){return 0<this.connections.length}},{key:"addConnection",value:function(t){if(!this.multipleConnections&&this.hasConnection())throw new Error("Multiple connections not allowed");this.connections.push(t)}},{key:"addControl",value:function(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}(),b=function(t){function o(t,e,n){var r=!(3<arguments.length&&void 0!==arguments[3])||arguments[3];return p(this,o),g(this,y(o).call(this,t,e,n,r))}return m(o,d),v(o,[{key:"hasConnection",value:function(){return 0<this.connections.length}},{key:"connectTo",value:function(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 e=new l(this,t);return this.connections.push(e),e}},{key:"connectedTo",value:function(e){return this.connections.some(function(t){return t.input===e})}},{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}(),x=function(){function n(t){p(this,n),this.name=t,this.id=n.incrementId(),this.position=[0,0],this.inputs=new Map,this.outputs=new Map,this.controls=new Map,this.data={},this.meta={}}return v(n,[{key:"addControl",value:function(t){return(t.parent=this).controls.set(t.key,t),this}},{key:"removeControl",value:function(t){t.parent=null,this.controls.delete(t.key)}},{key:"addInput",value:function(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){t.removeConnections(),t.node=null,this.inputs.delete(t.key)}},{key:"addOutput",value:function(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){t.removeConnections(),t.node=null,this.outputs.delete(t.key)}},{key:"getConnections",value:function(){return[].concat(k(this.inputs.values()),k(this.outputs.values())).reduce(function(t,e){return[].concat(k(t),k(e.connections))},[])}},{key:"update",value:function(){}},{key:"toJSON",value:function(){return{id:this.id,data:this.data,inputs:Array.from(this.inputs).reduce(function(t,e){var n=s(e,2),r=n[0],o=n[1];return t[r]=o.toJSON(),t},{}),outputs:Array.from(this.outputs).reduce(function(t,e){var n=s(e,2),r=n[0],o=n[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){var e=new n(t.name);return e.id=t.id,e.data=t.data,e.position=t.position,e.name=t.name,n.latestId=Math.max(e.id,n.latestId),e}}]),n}(),E=function(t){function n(t){var e;if(p(this,n),(e=g(this,y(n).call(this,t))).constructor===n)throw new TypeError("Can not construct abstract class.");return e.editor=null,e.data={},e}var e,r,o;return m(n,a),v(n,[{key:"builder",value:(o=f(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:"build",value:(r=f(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.builder(e);case 2:return t.abrupt("return",e);case 3:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"createNode",value:(e=f(regeneratorRuntime.mark(function t(){var e,n,r=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=0<r.length&&void 0!==r[0]?r[0]:{},(n=new x(this.name)).data=e,t.next=5,this.build(n);case 5:return t.abrupt("return",n);case 6:case"end":return t.stop()}},t,this)})),function(){return e.apply(this,arguments)})}]),n}(),C=function t(e){p(this,t),this.handlers=h({warn:[console.warn],error:[console.error]},e)},O=function(){function e(t){p(this,e),this.events=t instanceof e?t.events:t.handlers,this.silent=!1}return v(e,[{key:"on",value:function(t,e){var n=this;return t.split(" ").forEach(function(t){if(!n.events[t])throw new Error("The event ".concat(t," does not exist"));n.events[t].push(e)}),this}},{key:"trigger",value:function(t,n){if(!(t in this.events))throw new Error("The event ".concat(t," cannot be triggered"));return this.events[t].reduce(function(t,e){return!1!==e(n)&&t},!0)}},{key:"bind",value:function(t){if(this.events[t])throw new Error("The event ".concat(t," is already bound"));this.events[t]=[]}},{key:"exist",value:function(t){return Array.isArray(this.events[t])}}]),e}(),P=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,e){var n="",r=t.split("@"),o=e.id.split("@");return this.isValidData(e)||(n+="Data is not suitable. "),t!==e.id&&(n+="IDs not equal. "),r[0]!==o[0]&&(n+="Names don't match. "),r[1]!==o[1]&&(n+="Versions don't match"),{success:""===n,msg:n}}}]),t}(),N=function(t){function r(t,e){var n;if(p(this,r),n=g(this,y(r).call(this,e)),!P.isValidId(t))throw new Error("ID should be valid to name@0.1.0 format");return n.id=t,n.plugins=new Map,n}return m(r,O),v(r,[{key:"use",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(t.name&&this.plugins.has(t.name))throw new Error("Plugin ".concat(t.name," already in use"));t.install(this,e),this.plugins.set(t.name,e)}}]),r}(),R=function(t){function e(){return p(this,e),g(this,y(e).call(this,{componentregister:[]}))}return m(e,C),e}(),S=0,L=1,j=2,_=function(t){function n(t){var e;return p(this,n),(e=g(this,y(n).call(this,t,new R))).components=[],e.args=[],e.data=null,e.state=S,e.onAbort=function(){},e}var e,r,o,i,s,a,u,c,h,l,d;return m(n,N),v(n,[{key:"clone",value:function(){var e=new n(this.id);return this.components.map(function(t){return e.register(t)}),e}},{key:"register",value:function(t){this.components.push(t),this.trigger("componentregister",t)}},{key:"throwError",value:(d=f(regeneratorRuntime.mark(function t(e){var n,r=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=1<r.length&&void 0!==r[1]?r[1]:null,t.next=3,this.abort();case 3:return this.trigger("error",{message:e,data:n}),this.processDone(),t.abrupt("return","error");case 6:case"end":return t.stop()}},t,this)})),function(t){return d.apply(this,arguments)})},{key:"extractInputNodes",value:function(n,r){return Object.keys(n.inputs).reduce(function(t,e){return[].concat(k(t),k((n.inputs[e].connections||[]).reduce(function(t,e){return[].concat(k(t),[r[e.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(e,n){if(n.some(function(t){return t===e}))return e;for(var r=0;r<n.length;r++)if(t(e,i.extractInputNodes(n[r],o)))return e;return null}(t,i.extractInputNodes(t,o))}).filter(function(t){return null!==t})}},{key:"processStart",value:function(){return this.state===S?(this.state=L,!0):(this.state===j||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!==j;return this.state=S,t||(this.onAbort(),this.onAbort=function(){}),t}},{key:"abort",value:(l=f(regeneratorRuntime.mark(function t(){var e=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){e.state===L?(e.state=j,e.onAbort=t):e.state===j?(e.onAbort(),e.onAbort=t):t()}));case 1:case"end":return t.stop()}},t,this)})),function(){return l.apply(this,arguments)})},{key:"lock",value:(h=f(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t){e.unlockPool=e.unlockPool||[],e.busy&&!e.outputData?e.unlockPool.push(t):t(),e.busy=!0}));case 1:case"end":return t.stop()}},t,this)})),function(t){return h.apply(this,arguments)})},{key:"unlock",value:function(t){t.unlockPool.forEach(function(t){return t()}),t.unlockPool=[],t.busy=!1}},{key:"extractInputData",value:(c=f(regeneratorRuntime.mark(function t(e){var n,r,o,i,s,a,u,c=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:n={},r=Object.keys(e.inputs),o=0;case 3:if(o<r.length)return i=r[o],s=e.inputs[i],a=s.connections,t.next=9,Promise.all(a.map(function(){var e=f(regeneratorRuntime.mark(function t(e){var n,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=c.data.nodes[e.node],t.next=3,c.processNode(n);case 3:if(r=t.sent){t.next=8;break}c.abort(),t.next=9;break;case 8:return t.abrupt("return",r[e.output]);case 9:case"end":return t.stop()}},t,this)}));return function(t){return e.apply(this,arguments)}}()));t.next=14;break;case 9:u=t.sent,n[i]=u;case 11:o++,t.next=3;break;case 14:return t.abrupt("return",n);case 15:case"end":return t.stop()}},t,this)})),function(t){return c.apply(this,arguments)})},{key:"processWorker",value:(u=f(regeneratorRuntime.mark(function t(e){var n,r,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.extractInputData(e);case 2:return n=t.sent,r=this.components.find(function(t){return t.name===e.name}),o={},t.prev=5,t.next=8,r.worker.apply(r,[e,n,o].concat(k(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 u.apply(this,arguments)})},{key:"processNode",value:(a=f(regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==j&&e){t.next=2;break}return t.abrupt("return",null);case 2:return t.next=4,this.lock(e);case 4:return e.outputData||(e.outputData=this.processWorker(e)),this.unlock(e),t.abrupt("return",e.outputData);case 7:case"end":return t.stop()}},t,this)})),function(t){return a.apply(this,arguments)})},{key:"forwardProcess",value:(s=f(regeneratorRuntime.mark(function t(r){var o=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state===j)return t.abrupt("return",null);t.next=2;break;case 2:return t.next=4,Promise.all(Object.keys(r.outputs).map(function(){var e=f(regeneratorRuntime.mark(function t(e){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.outputs[e],t.next=3,Promise.all(n.connections.map(function(){var e=f(regeneratorRuntime.mark(function t(e){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=o.data.nodes[e.node],t.next=3,o.processNode(n);case 3:return t.next=5,o.forwardProcess(n);case 5:case"end":return t.stop()}},t,this)}));return function(t){return e.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,this)}));return function(t){return e.apply(this,arguments)}}()));case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"copy",value:function(e){return(e=Object.assign({},e)).nodes=Object.assign({},e.nodes),Object.keys(e.nodes).forEach(function(t){e.nodes[t]=Object.assign({},e.nodes[t])}),e}},{key:"validate",value:(i=f(regeneratorRuntime.mark(function t(e){var n,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((n=P.validate(this.id,e)).success){t.next=5;break}return t.next=4,this.throwError(n.msg);case 4:return t.abrupt("return",t.sent);case 5:if(0<(r=this.detectRecursions(e.nodes)).length)return t.next=9,this.throwError("Recursion detected",r);t.next=10;break;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=f(regeneratorRuntime.mark(function t(e){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e){t.next=10;break}if(n=this.data.nodes[e]){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(n);case 8:return t.next=10,this.forwardProcess(n);case 10:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"processUnreachable",value:(r=f(regeneratorRuntime.mark(function t(){var e,n;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(e=t.t1.value,void 0===this.data.nodes[e].outputData)return n=this.data.nodes[e],t.next=7,this.processNode(n);t.next=9;break;case 7:return t.next=9,this.forwardProcess(n);case 9:t.next=1;break;case 11:case"end":return t.stop()}},t,this)})),function(){return r.apply(this,arguments)})},{key:"process",value:(e=f(regeneratorRuntime.mark(function t(e){var n,r,o,i,s=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=1<s.length&&void 0!==s[1]?s[1]:null,this.processStart()){t.next=3;break}return t.abrupt("return");case 3:if(this.validate(e)){t.next=5;break}return t.abrupt("return");case 5:for(this.data=this.copy(e),r=s.length,o=new Array(2<r?r-2:0),i=2;i<r;i++)o[i-2]=s[i];return this.args=o,t.next=10,this.processStartNode(n);case 10:return t.next=12,this.processUnreachable();case 12:return t.abrupt("return",this.processDone()?"success":"aborted");case 13:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})}]),n}(),I=function(t){function e(){return p(this,e),g(this,y(e).call(this,{nodecreate:[],nodecreated:[],noderemove:[],noderemoved:[],connectioncreate:[],connectioncreated:[],connectionremove:[],connectionremoved:[],translatenode:[],nodetranslate:[],nodetranslated:[],nodedraged:[],selectnode:[],nodeselect:[],nodeselected:[],rendernode:[],rendersocket:[],rendercontrol:[],renderconnection:[],updateconnection:[],componentregister:[],keydown:[],keyup:[],translate:[],translated:[],zoom:[],zoomed:[],click:[],mousemove:[],contextmenu:[],import:[],export:[],process:[]}))}return m(e,C),e}(),T=function(){function o(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:function(){},n=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=e,this.onStart=n,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 e=t.touches?t.touches[0]:t;return[e.pageX,e.pageY]}},{key:"down",value:function(t){t.stopPropagation(),this.mouseStart=this.getCoords(t),this.onStart(t)}},{key:"move",value:function(t){if(this.mouseStart){t.preventDefault(),t.stopPropagation();var e=s(this.getCoords(t),2),n=e[0],r=e[1],o=[n-this.mouseStart[0],r-this.mouseStart[1]],i=this.el.getBoundingClientRect().width/this.el.offsetWidth;this.onTranslate(o[0]/i,o[1]/i,t)}}},{key:"up",value:function(t){this.mouseStart&&(this.mouseStart=null,this.onDrag(t))}}]),o}(),D=function(){function o(t,e,n,r){p(this,o),this.el=e,this.intensity=n,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)),t.addEventListener("dblclick",this.dblclick.bind(this))}return v(o,[{key:"wheel",value:function(t){t.preventDefault();var e=this.el.getBoundingClientRect(),n=(t.wheelDelta?t.wheelDelta/120:-t.deltaY/3)*this.intensity,r=(e.left-t.clientX)*n,o=(e.top-t.clientY)*n;this.onzoom(n,r,o,"wheel")}},{key:"touches",value:function(t){var e=[t.touches[0].clientX,t.touches[0].clientY],n=e[0],r=e[1],o=[t.touches[1].clientX,t.touches[1].clientY],i=o[0],s=o[1];return{cx:(n+i)/2,cy:(r+s)/2,distance:Math.sqrt(Math.pow(n-i,2)+Math.pow(r-s,2))}}},{key:"move",value:function(t){if(!(t.touches.length<2)){var e=this.el.getBoundingClientRect(),n=this.touches(t),r=n.cx,o=n.cy,i=n.distance;if(null!==this.distance){var s=i/this.distance-1,a=(e.left-r)*s,u=(e.top-o)*s;this.onzoom(s,a,u,"touch")}this.distance=i}}},{key:"end",value:function(){this.distance=null}},{key:"dblclick",value:function(t){t.preventDefault();var e=this.el.getBoundingClientRect(),n=4*this.intensity,r=(e.left-t.clientX)*n,o=(e.top-t.clientY)*n;this.onzoom(n,r,o,"dblclick")}}]),o}(),A=function(t){function o(t,e){var n;p(this,o);var r=(n=g(this,y(o).call(this,e))).el=document.createElement("div");return n.container=t,n.transform={k:1,x:0,y:0},n.mouse={x:0,y:0},r.style.transformOrigin="0 0",n._startPosition=null,n._zoom=new D(t,r,.1,n.onZoom.bind(i(i(n)))),n._drag=new T(t,n.onTranslate.bind(i(i(n))),n.onStart.bind(i(i(n)))),n.container.addEventListener("mousemove",n.mousemove.bind(i(i(n)))),n.container.addEventListener("touchmove",n.mousemove.bind(i(i(n)))),n.update(),n}return m(o,O),v(o,[{key:"update",value:function(){var t=this.transform;this.el.style.transform="translate(".concat(t.x,"px, ").concat(t.y,"px) scale(").concat(t.k,")")}},{key:"mousemove",value:function(t){var e=t instanceof TouchEvent?t.touches[0]:t,n=e.clientX,r=e.clientY,o=this.el.getBoundingClientRect(),i=n-o.left,s=r-o.top,a=this.transform.k;this.mouse={x:i/a,y:s/a},this.trigger("mousemove",h({},this.mouse))}},{key:"onStart",value:function(){this._startPosition=h({},this.transform)}},{key:"onTranslate",value:function(t,e){this.translate(this._startPosition.x+t,this._startPosition.y+e)}},{key:"onZoom",value:function(t,e,n,r){this.zoom(this.transform.k*(1+t),e,n,r),this.update()}},{key:"translate",value:function(t,e){var n={transform:this.transform,x:t,y:e};this.trigger("translate",n)&&(this.transform.x=n.x,this.transform.y=n.y,this.update(),this.trigger("translated"))}},{key:"zoom",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,r=3<arguments.length?arguments[3]:void 0,o=this.transform.k,i={transform:this.transform,zoom:t,source:r};if(this.trigger("zoom",i)){var s=(o-i.zoom)/(o-t||1);this.transform.k=i.zoom||1,this.transform.x+=e*s,this.transform.y+=n*s,this.update(),this.trigger("zoomed",{source:r})}}},{key:"appendChild",value:function(t){this.el.appendChild(t)}},{key:"removeChild",value:function(t){this.el.removeChild(t)}}]),o}(),z=function(t){function o(t,e,n){var r;return p(this,o),(r=g(this,y(o).call(this,n))).trigger("rendercontrol",{el:t,control:e}),r}return m(o,O),o}(),M=function(t){function a(t,e,n,r,o){var i,s;return p(this,a),(s=g(this,y(a).call(this,o))).el=t,s.type=e,s.io=n,s.node=r,s.trigger("rendersocket",(c(i={el:t},e,s.io),c(i,"socket",n.socket),i)),s}return m(a,O),v(a,[{key:"getPosition",value:function(t){var e=t.position,n=this.el;return[e[0]+n.offsetLeft+n.offsetWidth/2,e[1]+n.offsetTop+n.offsetHeight/2]}}]),a}(),J=function(t){function o(t,e,n){var r;return p(this,o),(r=g(this,y(o).call(this,n))).node=t,r.component=e,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 T(r.el,r.onTranslate.bind(i(i(r))),r.onSelect.bind(i(i(r))),function(){r.trigger("nodedraged",t)}),r.trigger("rendernode",{el:r.el,node:t,component:e.data,bindSocket:r.bindSocket.bind(i(i(r))),bindControl:r.bindControl.bind(i(i(r)))}),r.update(),r}return m(o,O),v(o,[{key:"bindSocket",value:function(t,e,n){this.sockets.set(n,new M(t,e,n,this.node,this))}},{key:"bindControl",value:function(t,e){this.controls.set(e,new z(t,e,this))}},{key:"getSocketPosition",value:function(t){return this.sockets.get(t).getPosition(this.node)}},{key:"onSelect",value:function(t){this.onStart(),this.trigger("selectnode",{node:this.node,accumulate:t.ctrlKey})}},{key:"onStart",value:function(){this._startPosition=k(this.node.position)}},{key:"onTranslate",value:function(t,e){this.trigger("translatenode",{node:this.node,dx:t,dy:e})}},{key:"onDrag",value:function(t,e){var n=this._startPosition[0]+t,r=this._startPosition[1]+e;this.translate(n,r)}},{key:"translate",value:function(t,e){var n=this.node,r={node:n,x:t,y:e};if(this.trigger("nodetranslate",r)){var o=k(n.position);n.position[0]=r.x,n.position[1]=r.y,this.update(),this.trigger("nodetranslated",{node:n,prev:o})}}},{key:"update",value:function(){this.el.style.transform="translate(".concat(this.node.position[0],"px, ").concat(this.node.position[1],"px)")}},{key:"remove",value:function(){}}]),o}(),Y=function(t){function i(t,e,n,r){var o;return p(this,i),(o=g(this,y(i).call(this,r))).connection=t,o.inputNode=e,o.outputNode=n,o.el=document.createElement("div"),o.el.style.position="absolute",o.el.style.zIndex="-1",o.trigger("renderconnection",{el:o.el,connection:o.connection,points:o.getPoints()}),o}return m(i,O),v(i,[{key:"getPoints",value:function(){var t=s(this.outputNode.getSocketPosition(this.connection.output),2),e=t[0],n=t[1],r=s(this.inputNode.getSocketPosition(this.connection.input),2);return[e,n,r[0],r[1]]}},{key:"update",value:function(){this.trigger("updateconnection",{el:this.el,connection:this.connection,points:this.getPoints()})}}]),i}(),G=function(t){function o(t,e,n){var r;return p(this,o),(r=g(this,y(o).call(this,n))).container=t,r.components=e,r.container.style.overflow="hidden",r.nodes=new Map,r.connections=new Map,r.container.addEventListener("click",r.click.bind(i(i(r)))),r.container.addEventListener("contextmenu",function(t){return r.trigger("contextmenu",{e:t,view:i(i(r))})}),window.addEventListener("resize",r.resize.bind(i(i(r)))),r.on("nodetranslated",r.updateConnections.bind(i(i(r)))),r.area=new A(t,i(i(r))),r.container.appendChild(r.area.el),r}return m(o,O),v(o,[{key:"addNode",value:function(t){var e=new J(t,this.components.get(t.name),this);this.nodes.set(t,e),this.area.appendChild(e.el)}},{key:"removeNode",value:function(t){var e=this.nodes.get(t);this.nodes.delete(t),this.area.removeChild(e.el)}},{key:"addConnection",value:function(t){var e=this.nodes.get(t.input.node),n=this.nodes.get(t.output.node),r=new Y(t,e,n,this);this.connections.set(t,r),this.area.appendChild(r.el)}},{key:"removeConnection",value:function(t){var e=this.connections.get(t);this.connections.delete(t),this.area.removeChild(e.el)}},{key:"updateConnections",value:function(t){var e=this;t.node.getConnections().map(function(t){e.connections.get(t).update()})}},{key:"resize",value:function(){var t=this.container,e=t.parentElement.clientWidth,n=t.parentElement.clientHeight;t.style.width=e+"px",t.style.height=n+"px"}},{key:"click",value:function(t){var e=this.container;e===t.target&&this.trigger("click",{e:t,container:e})}}]),o}(),W=function(){function t(){p(this,t),this.list=[]}return v(t,[{key:"add",value:function(t){1<arguments.length&&void 0!==arguments[1]&&arguments[1]?this.contains(t)||this.list.push(t):this.list=[t]}},{key:"clear",value:function(){this.list=[]}},{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}(),F=function(t){function n(t,e){var r;return p(this,n),(r=g(this,y(n).call(this,t,new I))).nodes=[],r.components=new Map,r.selected=new W,r.view=new G(e,r.components,i(i(r))),window.addEventListener("keydown",function(t){return r.trigger("keydown",t)}),window.addEventListener("keyup",function(t){return r.trigger("keyup",t)}),r.on("selectnode",function(t){var e=t.node,n=t.accumulate;return r.selectNode(e,n)}),r.on("nodeselected",function(){return r.selected.each(function(t){return r.view.nodes.get(t).onStart()})}),r.on("translatenode",function(t){var e=t.dx,n=t.dy;return r.selected.each(function(t){return r.view.nodes.get(t).onDrag(e,n)})}),r}var e;return m(n,N),v(n,[{key:"addNode",value:function(t){this.trigger("nodecreate",t)&&(this.nodes.push(t),this.view.addNode(t),this.trigger("nodecreated",t))}},{key:"removeNode",value:function(t){var e=this;this.trigger("noderemove",t)&&(t.getConnections().forEach(function(t){return e.removeConnection(t)}),this.nodes.splice(this.nodes.indexOf(t),1),this.view.removeNode(t),this.trigger("noderemoved",t))}},{key:"connect",value:function(t,e){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(this.trigger("connectioncreate",{output:t,input:e}))try{var r=t.connectTo(e);r.data=n,this.view.addConnection(r),this.trigger("connectioncreated",r)}catch(t){this.trigger("warn",t)}}},{key:"removeConnection",value:function(t){this.trigger("connectionremove",t)&&(this.view.removeConnection(t),t.remove(),this.trigger("connectionremoved",t))}},{key:"selectNode",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(-1===this.nodes.indexOf(t))throw new Error("Node not exist in list");this.trigger("nodeselect",t)&&(this.selected.add(t,e),this.trigger("nodeselected",t))}},{key:"getComponent",value:function(t){var e=this.components.get(t);if(!e)throw"Component ".concat(t," not found");return e}},{key:"register",value:function(t){(t.editor=this).components.set(t.name,t),this.trigger("componentregister",t)}},{key:"clear",value:function(){var e=this;k(this.nodes).map(function(t){return e.removeNode(t)})}},{key:"toJSON",value:function(){var e={id:this.id,nodes:{}};return this.nodes.forEach(function(t){return e.nodes[t.id]=t.toJSON()}),this.trigger("export",e),e}},{key:"beforeImport",value:function(t){var e=P.validate(this.id,t);return e.success?(this.silent=!0,this.clear(),this.trigger("import",t),!0):(this.trigger("warn",e.msg),!1)}},{key:"afterImport",value:function(){return!(this.silent=!1)}},{key:"fromJSON",value:(e=f(regeneratorRuntime.mark(function t(o){var a,u=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.beforeImport(o)){t.next=2;break}return t.abrupt("return",!1);case 2:return a={},t.prev=3,t.next=6,Promise.all(Object.keys(o.nodes).map(function(){var e=f(regeneratorRuntime.mark(function t(e){var n,r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=o.nodes[e],r=u.getComponent(n.name),t.next=4,r.build(x.fromJSON(n));case 4:a[e]=t.sent,u.addNode(a[e]);case 6:case"end":return t.stop()}},t,this)}));return function(t){return e.apply(this,arguments)}}()));case 6:Object.keys(o.nodes).forEach(function(t){var e=o.nodes[t],s=a[t];Object.keys(e.outputs).forEach(function(i){e.outputs[i].connections.forEach(function(t){var e=t.node,n=t.data,r=s.outputs.get(i),o=a[e].inputs.get(t.input);u.connect(r,o,n)})})}),t.next=13;break;case 9:return t.prev=9,t.t0=t.catch(3),this.trigger("warn",t.t0),t.abrupt("return",!this.afterImport());case 13:return t.prev=13,t.abrupt("return",this.afterImport());case 16:case"end":return t.stop()}},t,this,[[3,9,13,16]])})),function(t){return e.apply(this,arguments)})}]),n}();t.Component=E,t.Control=e,t.Emitter=O,t.Engine=_,t.Input=w,t.Node=x,t.NodeEditor=F,t.Output=b,t.Socket=o,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=rete.min.js.map |
{ | ||
"name": "rete", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "JavaScript framework", | ||
"main": "build/rete.min.js", | ||
"module": "build/rete.debug.js", | ||
"module": "build/rete.esm.js", | ||
"types": "src/index.d.ts", | ||
@@ -37,3 +37,3 @@ "scripts": { | ||
"mocha": "^5.2.0", | ||
"rete-cli": "^0.2.0", | ||
"rete-cli": "^0.4.2", | ||
"rollup-copy-plugin": "0.0.1" | ||
@@ -40,0 +40,0 @@ }, |
@@ -1,21 +0,9 @@ | ||
import { Component } from './component'; | ||
import { Control } from './control'; | ||
import { Emitter } from './core/emitter'; | ||
import { Engine } from './engine/index'; | ||
import { Input } from './input'; | ||
import { Node } from './node'; | ||
import { NodeEditor } from './editor'; | ||
import { Output } from './output'; | ||
import { Socket } from './socket'; | ||
export default { | ||
Component, | ||
Control, | ||
NodeEditor, | ||
Emitter, | ||
Engine, | ||
Input, | ||
Node, | ||
Output, | ||
Socket | ||
} | ||
export { Component } from './component'; | ||
export { Control } from './control'; | ||
export { Emitter } from './core/emitter'; | ||
export { Engine } from './engine/index'; | ||
export { Input } from './input'; | ||
export { Node } from './node'; | ||
export { NodeEditor } from './editor'; | ||
export { Output } from './output'; | ||
export { Socket } from './socket'; |
@@ -72,3 +72,3 @@ import './utils/domReady'; | ||
assert.throws(() => editor.connect(n1.outputs.get('none'), n2.inputs.get('name')), Error, 'no output'); | ||
// assert.throws(() => editor.connect(n1.outputs.get('none'), n2.inputs.get('name')), Error, 'no output'); | ||
@@ -75,0 +75,0 @@ editor.connect(n1.outputs.get('name'), n2.inputs.get('name')); |
@@ -31,7 +31,7 @@ import './utils/domReady'; | ||
assert.doesNotThrow(createValidEngine, Error, 'valid'); | ||
assert.throws(() => { | ||
let eng = createValidEngine(); | ||
// assert.throws(() => { | ||
// let eng = createValidEngine(); | ||
eng.register({}) | ||
}, Error, 'object instead of component'); | ||
// eng.register({}) | ||
// }, Error, 'object instead of component'); | ||
assert.throws(() => new Rete.Engine('test@0.1'), Error, 'wrong id'); | ||
@@ -38,0 +38,0 @@ }); |
@@ -5,4 +5,4 @@ import assert from 'assert'; | ||
it('Socket arguments', () => { | ||
assert.throws(() => new Rete.Socket(), Error, 'null'); | ||
assert.throws(() => new Rete.Socket(345), Error, 'number'); | ||
// assert.throws(() => new Rete.Socket(), Error, 'null'); | ||
// assert.throws(() => new Rete.Socket(345), Error, 'number'); | ||
assert.doesNotThrow(() => new Rete.Socket('valid name'), Error, 'valid string'); | ||
@@ -9,0 +9,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
4899
397217
1