rete
Version:
JavaScript framework
8 lines (7 loc) • 18.5 kB
JavaScript
/*!
* rete v2.0.5
* (c) 2025 Vitaliy Stoliarov
* Released under the MIT license.
* */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Rete={})}(this,(function(t){"use strict";function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function n(t,e,n,r,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void n(t)}u.done?e(c):Promise.resolve(c).then(r,o)}function r(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function u(t){n(a,o,i,u,c,"next",t)}function c(t){n(a,o,i,u,c,"throw",t)}u(void 0)}))}}function o(t,e,n){return e=f(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,h()?Reflect.construct(e,n||[],f(t).constructor):e.apply(t,n))}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(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,y(r.key),r)}}function u(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t,n){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){r&&(t=r);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){c=!0,a=t},f:function(){try{u||null==r.return||r.return()}finally{if(c)throw a}}}}function s(t,e,n){return(e=y(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function f(t){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},f(t)}function l(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&d(t,e)}function h(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(h=function(){return!!t})()}function p(){p=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function f(t,e,n,r){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),u=new N(r||[]);return o(a,"_invoke",{value:_(t,n,u)}),a}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",d="suspendedYield",y="executing",v="completed",b={};function m(){}function w(){}function g(){}var x={};s(x,a,(function(){return this}));var k=Object.getPrototypeOf,O=k&&k(k(I([])));O&&O!==n&&r.call(O,a)&&(x=O);var E=g.prototype=m.prototype=Object.create(x);function j(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function n(o,i,a,u){var c=l(t[o],t,i);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return i=i?i.then(o,o):o()}})}function _(e,n,r){var o=h;return function(i,a){if(o===y)throw Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(r.method=i,r.arg=a;;){var u=r.delegate;if(u){var c=L(u,r);if(c){if(c===b)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===h)throw o=v,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=y;var s=l(e,n,r);if("normal"===s.type){if(o=r.done?v:d,s.arg===b)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(o=v,r.method="throw",r.arg=s.arg)}}}function L(e,n){var r=n.method,o=e.iterator[r];if(o===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,L(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),b;var i=l(o,e.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,b;var a=i.arg;return a?a.done?(n[e.resultName]=a.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,b):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,b)}function S(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 C(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function I(e){if(e||""===e){var n=e[a];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function n(){for(;++o<e.length;)if(r.call(e,o))return n.value=e[o],n.done=!1,n;return n.value=t,n.done=!0,n};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return w.prototype=g,o(E,"constructor",{value:g,configurable:!0}),o(g,"constructor",{value:w,configurable:!0}),w.displayName=s(g,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(E),t},e.awrap=function(t){return{__await:t}},j(P.prototype),s(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,n,r,o,i){void 0===i&&(i=Promise);var a=new P(f(t,n,r,o),i);return e.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(E),s(E,c,"Generator"),s(E,a,(function(){return this})),s(E,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=I,N.prototype={constructor:N,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(C),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},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 n=this;function o(r,o){return u.type="throw",u.arg=e,n.next=r,o&&(n.method="next",n.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,b):this.complete(a)},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),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),C(n),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;C(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:I(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),b}},e}function d(t,e){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},d(t,e)}function y(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var v=function(){return u((function t(){i(this,t),s(this,"pipes",[])}),[{key:"addPipe",value:function(t){this.pipes.push(t)}},{key:"emit",value:(t=r(p().mark((function t(e){var n,r,o,i;return p().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=e,r=c(this.pipes),t.prev=2,r.s();case 4:if((o=r.n()).done){t.next=13;break}return i=o.value,t.next=8,i(n);case 8:if(void 0!==(n=t.sent)){t.next=11;break}return t.abrupt("return");case 11:t.next=4;break;case 13:t.next=18;break;case 15:t.prev=15,t.t0=t.catch(2),r.e(t.t0);case 18:return t.prev=18,r.f(),t.finish(18);case 21:return t.abrupt("return",n);case 22:case"end":return t.stop()}}),t,this,[[2,15,18,21]])}))),function(e){return t.apply(this,arguments)})}]);var t}(),b=function(){function t(e){i(this,t),s(this,"signal",new v),this.name=e}return u(t,[{key:"addPipe",value:function(t){this.signal.addPipe(t)}},{key:"use",value:function(e){if(!(e instanceof t))throw new Error("cannot use non-Scope instance");return e.setParent(this),this.addPipe((function(t){return e.signal.emit(t)})),{debug:function(t){}}}},{key:"setParent",value:function(t){this.parent=t}},{key:"emit",value:function(t){return this.signal.emit(t)}},{key:"hasParent",value:function(){return Boolean(this.parent)}},{key:"parentScope",value:function(t){if(!this.parent)throw new Error("cannot find parent");if(t&&this.parent instanceof t)return this.parent;if(t)throw new Error("actual parent is not instance of type");return this.parent}}])}(),m=function(t){function e(){var t;return i(this,e),s(t=o(this,e,["NodeEditor"]),"nodes",[]),s(t,"connections",[]),t}return l(e,t),u(e,[{key:"getNode",value:function(t){return this.nodes.find((function(e){return e.id===t}))}},{key:"getNodes",value:function(){return this.nodes.slice()}},{key:"getConnections",value:function(){return this.connections.slice()}},{key:"getConnection",value:function(t){return this.connections.find((function(e){return e.id===t}))}},{key:"addNode",value:(d=r(p().mark((function t(e){return p().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.getNode(e.id)){t.next=2;break}throw new Error("node has already been added");case 2:return t.next=4,this.emit({type:"nodecreate",data:e});case 4:if(t.sent){t.next=6;break}return t.abrupt("return",!1);case 6:return this.nodes.push(e),t.next=9,this.emit({type:"nodecreated",data:e});case 9:return t.abrupt("return",!0);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return d.apply(this,arguments)})},{key:"addConnection",value:(h=r(p().mark((function t(e){return p().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.getConnection(e.id)){t.next=2;break}throw new Error("connection has already been added");case 2:return t.next=4,this.emit({type:"connectioncreate",data:e});case 4:if(t.sent){t.next=6;break}return t.abrupt("return",!1);case 6:return this.connections.push(e),t.next=9,this.emit({type:"connectioncreated",data:e});case 9:return t.abrupt("return",!0);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return h.apply(this,arguments)})},{key:"removeNode",value:(f=r(p().mark((function t(e){var n,r;return p().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=this.nodes.find((function(t){return t.id===e}))){t.next=3;break}throw new Error("cannot find node");case 3:return t.next=5,this.emit({type:"noderemove",data:n});case 5:if(t.sent){t.next=7;break}return t.abrupt("return",!1);case 7:return r=this.nodes.indexOf(n),this.nodes.splice(r,1),t.next=11,this.emit({type:"noderemoved",data:n});case 11:return t.abrupt("return",!0);case 12:case"end":return t.stop()}}),t,this)}))),function(t){return f.apply(this,arguments)})},{key:"removeConnection",value:(a=r(p().mark((function t(e){var n,r;return p().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=this.connections.find((function(t){return t.id===e}))){t.next=3;break}throw new Error("cannot find connection");case 3:return t.next=5,this.emit({type:"connectionremove",data:n});case 5:if(t.sent){t.next=7;break}return t.abrupt("return",!1);case 7:return r=this.connections.indexOf(n),this.connections.splice(r,1),t.next=11,this.emit({type:"connectionremoved",data:n});case 11:return t.abrupt("return",!0);case 12:case"end":return t.stop()}}),t,this)}))),function(t){return a.apply(this,arguments)})},{key:"clear",value:(n=r(p().mark((function t(){var e,n,r,o,i,a;return p().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.emit({type:"clear"});case 2:if(t.sent){t.next=6;break}return t.next=5,this.emit({type:"clearcancelled"});case 5:return t.abrupt("return",!1);case 6:e=c(this.connections.slice()),t.prev=7,e.s();case 9:if((n=e.n()).done){t.next=15;break}return r=n.value,t.next=13,this.removeConnection(r.id);case 13:t.next=9;break;case 15:t.next=20;break;case 17:t.prev=17,t.t0=t.catch(7),e.e(t.t0);case 20:return t.prev=20,e.f(),t.finish(20);case 23:o=c(this.nodes.slice()),t.prev=24,o.s();case 26:if((i=o.n()).done){t.next=32;break}return a=i.value,t.next=30,this.removeNode(a.id);case 30:t.next=26;break;case 32:t.next=37;break;case 34:t.prev=34,t.t1=t.catch(24),o.e(t.t1);case 37:return t.prev=37,o.f(),t.finish(37);case 40:return t.next=42,this.emit({type:"cleared"});case 42:return t.abrupt("return",!0);case 43:case"end":return t.stop()}}),t,this,[[7,17,20,23],[24,34,37,40]])}))),function(){return n.apply(this,arguments)})}]);var n,a,f,h,d}(b),w=globalThis.crypto;function g(){if("randomBytes"in w)return w.randomBytes(8).toString("hex");var t=w.getRandomValues(new Uint8Array(8));return Array.from(t).map((function(t){return t.toString(16).padStart(2,"0")})).join("")}var x=u((function t(e){i(this,t),this.name=e})),k=u((function t(e,n,r){i(this,t),this.socket=e,this.label=n,this.multipleConnections=r,this.id=g()})),O=function(t){function e(t,n,r){var a;return i(this,e),s(a=o(this,e,[t,n,r]),"control",null),s(a,"showControl",!0),a.socket=t,a.label=n,a.multipleConnections=r,a}return l(e,t),u(e,[{key:"addControl",value:function(t){if(this.control)throw new Error("control already added for this input");this.control=t}},{key:"removeControl",value:function(){this.control=null}}])}(k),E=function(t){function e(t,n,r){return i(this,e),o(this,e,[t,n,!1!==r])}return l(e,t),u(e)}(k),j=u((function t(){i(this,t),this.id=g()})),P=function(t){function e(t,n){var r,a;return i(this,e),(a=o(this,e)).type=t,a.options=n,a.id=g(),a.readonly=null!==(r=null==n?void 0:n.readonly)&&void 0!==r&&r,void 0!==(null==n?void 0:n.initial)&&(a.value=n.initial),a}return l(e,t),u(e,[{key:"setValue",value:function(t){var e;this.value=t,null!==(e=this.options)&&void 0!==e&&e.change&&this.options.change(t)}}])}(j),_=function(){return u((function t(e){i(this,t),s(this,"inputs",{}),s(this,"outputs",{}),s(this,"controls",{}),this.label=e,this.id=g()}),[{key:"hasInput",value:function(t){return Object.prototype.hasOwnProperty.call(this.inputs,t)}},{key:"addInput",value:function(t,e){if(this.hasInput(t))throw new Error("input with key '".concat(String(t),"' already added"));Object.defineProperty(this.inputs,t,{value:e,enumerable:!0,configurable:!0})}},{key:"removeInput",value:function(t){delete this.inputs[t]}},{key:"hasOutput",value:function(t){return Object.prototype.hasOwnProperty.call(this.outputs,t)}},{key:"addOutput",value:function(t,e){if(this.hasOutput(t))throw new Error("output with key '".concat(String(t),"' already added"));Object.defineProperty(this.outputs,t,{value:e,enumerable:!0,configurable:!0})}},{key:"removeOutput",value:function(t){delete this.outputs[t]}},{key:"hasControl",value:function(t){return Object.prototype.hasOwnProperty.call(this.controls,t)}},{key:"addControl",value:function(t,e){if(this.hasControl(t))throw new Error("control with key '".concat(String(t),"' already added"));Object.defineProperty(this.controls,t,{value:e,enumerable:!0,configurable:!0})}},{key:"removeControl",value:function(t){delete this.controls[t]}}])}(),L=u((function t(e,n,r,o){if(i(this,t),this.sourceOutput=n,this.targetInput=o,!e.outputs[n])throw new Error("source node doesn't have output with a key ".concat(String(n)));if(!r.inputs[o])throw new Error("target node doesn't have input with a key ".concat(String(o)));this.id=g(),this.source=e.id,this.target=r.id})),S=Object.freeze({__proto__:null,Socket:x,Port:k,Input:O,Output:E,Control:j,InputControl:P,Node:_,Connection:L});t.ClassicPreset=S,t.NodeEditor=m,t.Scope=b,t.Signal=v,t.getUID=g,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=rete.min.js.map