@fluxscape/react-runtime 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(React,ReactDOM){"use strict";function _interopNamespaceDefault(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}function _mergeNamespaces(e,t){for(var n=0;n<t.length;n++){const o=t[n];if(typeof o!="string"&&!Array.isArray(o)){for(const r in o)if(r!=="default"&&!(r in e)){const s=Object.getOwnPropertyDescriptor(o,r);s&&Object.defineProperty(e,r,s.get?s:{enumerable:!0,get:()=>o[r]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}const React__namespace=_interopNamespaceDefault(React);class CloudFile{constructor({name:t,url:n}){this.name=t,this.url=n}getUrl(){return this.url}getName(){return this.name}toString(){return this.url}}var R=typeof Reflect=="object"?Reflect:null,ReflectApply=R&&typeof R.apply=="function"?R.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},ReflectOwnKeys;R&&typeof R.ownKeys=="function"?ReflectOwnKeys=R.ownKeys:Object.getOwnPropertySymbols?ReflectOwnKeys=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ReflectOwnKeys=function(e){return Object.getOwnPropertyNames(e)};function ProcessEmitWarning(e){console&&console.warn&&console.warn(e)}var NumberIsNaN=Number.isNaN||function(e){return e!==e};function EventEmitter$2(){EventEmitter$2.init.call(this)}EventEmitter$2.EventEmitter=EventEmitter$2,EventEmitter$2.prototype._events=void 0,EventEmitter$2.prototype._eventsCount=0,EventEmitter$2.prototype._maxListeners=void 0;var defaultMaxListeners=10;function checkListener(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(EventEmitter$2,"defaultMaxListeners",{enumerable:!0,get(){return defaultMaxListeners},set(e){if(typeof e!="number"||e<0||NumberIsNaN(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");defaultMaxListeners=e}}),EventEmitter$2.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},EventEmitter$2.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||NumberIsNaN(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function _getMaxListeners(e){return e._maxListeners===void 0?EventEmitter$2.defaultMaxListeners:e._maxListeners}EventEmitter$2.prototype.getMaxListeners=function(){return _getMaxListeners(this)},EventEmitter$2.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var o=e==="error",r=this._events;if(r!==void 0)o=o&&r.error===void 0;else if(!o)return!1;if(o){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=r[e];if(l===void 0)return!1;if(typeof l=="function")ReflectApply(l,this,t);else for(var u=l.length,d=arrayClone(l,u),n=0;n<u;++n)ReflectApply(d[n],this,t);return!0};function _addListener(e,t,n,o){var r,s,a;if(checkListener(n),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),a=s[t]),a===void 0)a=s[t]=n,++e._eventsCount;else if(typeof a=="function"?a=s[t]=o?[n,a]:[a,n]:o?a.unshift(n):a.push(n),r=_getMaxListeners(e),r>0&&a.length>r&&!a.warned){a.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=a.length,ProcessEmitWarning(l)}return e}EventEmitter$2.prototype.addListener=function(e,t){return _addListener(this,e,t,!1)},EventEmitter$2.prototype.on=EventEmitter$2.prototype.addListener,EventEmitter$2.prototype.prependListener=function(e,t){return _addListener(this,e,t,!0)};function onceWrapper(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function _onceWrap(e,t,n){var o={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=onceWrapper.bind(o);return r.listener=n,o.wrapFn=r,r}EventEmitter$2.prototype.once=function(e,t){return checkListener(t),this.on(e,_onceWrap(this,e,t)),this},EventEmitter$2.prototype.prependOnceListener=function(e,t){return checkListener(t),this.prependListener(e,_onceWrap(this,e,t)),this},EventEmitter$2.prototype.removeListener=function(e,t){var n,o,r,s,a;if(checkListener(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){a=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():spliceOne(n,r),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this},EventEmitter$2.prototype.off=EventEmitter$2.prototype.removeListener,EventEmitter$2.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var r=Object.keys(n),s;for(o=0;o<r.length;++o)s=r[o],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(o=t.length-1;o>=0;o--)this.removeListener(e,t[o]);return this};function _listeners(e,t,n){var o=e._events;if(o===void 0)return[];var r=o[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?unwrapListeners(r):arrayClone(r,r.length)}EventEmitter$2.prototype.listeners=function(e){return _listeners(this,e,!0)},EventEmitter$2.prototype.rawListeners=function(e){return _listeners(this,e,!1)},EventEmitter$2.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):listenerCount.call(e,t)},EventEmitter$2.prototype.listenerCount=listenerCount;function listenerCount(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}EventEmitter$2.prototype.eventNames=function(){return this._eventsCount>0?ReflectOwnKeys(this._events):[]};function arrayClone(e,t){for(var n=new Array(t),o=0;o<t;++o)n[o]=e[o];return n}function spliceOne(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function unwrapListeners(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function NodeRegister(e){this._constructors={},this.context=e}NodeRegister.prototype.register=function(e){var t=e.metadata.name;this._constructors[t]=e},NodeRegister.prototype.createNode=function(e,t,n){if(this._constructors.hasOwnProperty(e)===!1)throw new Error("Unknown node type with name "+e);return this._constructors[e](this.context,t,n)},NodeRegister.prototype.getNodeMetadata=function(e){if(this._constructors.hasOwnProperty(e)===!1)throw new Error("Unknown node type with name "+e);return this._constructors[e].metadata},NodeRegister.prototype.hasNode=function(e){return this._constructors.hasOwnProperty(e)},NodeRegister.prototype.getInputType=function(e,t){const n=this.getNodeMetadata(e);return n.inputs[t]&&n.inputs[t].type};function Timer$2(e,t){this.duration=t.duration||0,this._isRunning=!1,this._hasCalledOnStart=!1,this.scheduler=e,this.repeatCount=1,this.delay=0;for(var n in t)this[n]=t[n]}Timer$2.prototype.start=function(){return this._isRunning&&this.stop(),this.scheduler.scheduleTimer(this),this},Timer$2.prototype.stop=function(){this.scheduler.stopTimer(this),this._hasCalledOnStart=!1,this._isRunning=!1,this._wasStopped=!0},Timer$2.prototype.isRunning=function(){return this._isRunning},Timer$2.prototype.durationLeft=function(){return this._durationLeft};function TimerScheduler(e){this.requestFrame=e,this.runningTimers=[],this.newTimers=[]}TimerScheduler.prototype.createTimer=function(e){return new Timer$2(this,e)},TimerScheduler.prototype.scheduleTimer=function(e){this.newTimers.indexOf(e)===-1&&(e.repeatCount===0&&(e.repeatCount=1e5),this.newTimers.push(e),this.requestFrame())},TimerScheduler.prototype.stopTimer=function(e){var t;e._isRunning?(t=this.runningTimers.indexOf(e),t!==-1&&this.runningTimers.splice(t,1),e.onStop&&!e._wasStopped&&e.onStop()):(t=this.newTimers.indexOf(e),t!==-1&&this.newTimers.splice(t,1))},TimerScheduler.prototype.runTimers=function(e){var t=[],n=[],o=[],r,s=this.runningTimers.length,a;for(r=0;r<s;++r)o[r]=this.runningTimers[r];for(r=0;r<s;++r)if(a=o[r],a&&e>=a._start){a._hasCalledOnStart===!1&&a.onStart&&(a.onStart(),a._hasCalledOnStart=!0);var l;a.duration>0?l=(e-a._start)/(a.duration*a.repeatCount):l=1,a._durationLeft=a.duration*(1-l);var u=l*a.repeatCount-Math.floor(l*a.repeatCount);l>=1&&(u=1),a.onRunning&&a.onRunning(u),l<1&&a._isRunning?t.push(a):a._wasStopped||n.push(a)}else t.push(a);for(this.runningTimers=t,r=0;r<n.length;++r)n[r]._isRunning=!1,n[r]._hasCalledOnStart=!1,n[r].onFinish&&n[r].onFinish();if(this.newTimers.length>0){for(r=0;r<this.newTimers.length;++r)a=this.newTimers[r],a._start=e+a.delay,a._isRunning=!0,a._wasStopped=!1,this.runningTimers.push(a),a.delay===0&&(a.onStart&&(a.onStart(),a._hasCalledOnStart=!0),a.onRunning&&a.onRunning(0));this.newTimers.length=0}},TimerScheduler.prototype.hasPendingTimers=function(){return this.runningTimers.length>0||this.newTimers.length>0};class Variants{constructor({graphModel:t,getNodeScope:n}){this.getNodeScope=n,t&&(this.graphModel=t,t.on("variantUpdated",o=>this.onVariantUpdated(o)))}getVariant(t,n){if(this.graphModel)return this.graphModel.getVariant(t,n)}onVariantUpdated(t){const n=this.getNodeScope();if(!n)return;const o=n.getNodesWithTypeRecursive(t.typename).filter(r=>r.variant?r.variant.name===t.name:r.model&&r.model.variant===t.name);for(const r of o)r.setVariant(t)}}function OutputProperty(e){if(!e.owner)throw new Error("Owner must be set");this.getter=e.getter,this.connections=[],this.owner=e.owner,this.name=e.name,this.onFirstConnectionAdded=e.onFirstConnectionAdded,this.onLastConnectionRemoved=e.onLastConnectionRemoved,this._id=void 0}Object.defineProperties(OutputProperty.prototype,{value:{get(){return this.getter.call(this.owner)}},id:{get(){return this._id||(this._id=this.owner.id+this.name),this._id}},registerConnection:{value(e,t){this.connections.push({node:e,inputPortName:t}),this.connections.length===1&&this.onFirstConnectionAdded&&this.onFirstConnectionAdded.call(this.owner)}},deregisterConnection:{value(e,t){for(var n=0;n<this.connections.length;n++){var o=this.connections[n];if(o.node===e&&o.inputPortName===t){this.connections.splice(n,1);break}}this.connections.length===0&&this.onLastConnectionRemoved&&this.onLastConnectionRemoved.call(this.owner)}},flagDependeesDirty:{value(e){for(var t=0,n=this.connections.length;t<n;t++)this.connections[t].node.flagDirty()}},sendValue:{value(e){this._lastUpdateIteration!==this.owner._updatedAtIteration?(this._lastUpdateIteration=this.owner._updatedAtIteration,this.valuesSendThisIteration=0):this.valuesSendThisIteration++,this.valuesSendThisIteration>500&&(this.owner._cyclicLoop=!0);for(var t=0,n=this.connections.length;t<n;t++){var o=this.connections[t];o.node._setValueFromConnection(o.inputPortName,e)}}},hasConnections:{value(){return this.connections.length>0}}});function Node(e,t){this.id=t,this.context=e,this._dirty=!1,this._inputs={},this._inputValues={},this._outputs={},this._inputConnections={},this._outputList=[],this._isUpdating=!1,this._inputValuesQueue={},this._afterInputsHaveUpdatedCallbacks=[],this._internal={},this._signalsSentThisUpdate={},this._deleted=!1,this._deleteListeners=[],this._isFirstUpdate=!0,this._valuesFromConnections={},this.updateOnDirtyFlagging=!0}Node.prototype.getInputValue=function(e){return this._inputValues[e]},Node.prototype.registerInput=function(e,t){if(this.hasInput(e))throw new Error("Input property "+e+" already registered");if(this._inputs[e]=t,t.type&&t.type.units){const n=t.type.defaultUnit||t.type.units[0];this._inputValues[e]={value:t.default,type:n}}else t.hasOwnProperty("default")&&(this._inputValues[e]=t.default)},Node.prototype.deregisterInput=function(e){if(this.hasInput(e)===!1)throw new Error("Input property "+e+" doesn't exist");delete this._inputs[e],delete this._inputValues[e]},Node.prototype.registerInputs=function(e){for(const t in e)this.registerInput(t,e[t])},Node.prototype.getInput=function(e){if(this.hasInput(e)===!1){console.log("Node "+this.name+": Invalid input property "+e);return}return this._inputs[e]},Node.prototype.hasInput=function(e){return e in this._inputs},Node.prototype.registerInputIfNeeded=function(){},Node.prototype.setInputValue=function(name,value){const input=this.getInput(name);if(!input){console.log("node doesn't have input",name);return}const currentInputValue=this._inputValues[name];if(isNaN(value)===!1&&currentInputValue&&currentInputValue.unit){const e=Object.assign({},currentInputValue);e.value=value,value=e}if(this._inputValues[name]=value,input.type==="color"&&this.context&&this.context.styles)value=this.context.styles.resolveColor(value);else if(input.type==="array"&&typeof value=="string")try{value=eval(value),this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"invalid-array-"+name)}catch(e){value=[],console.log(e),this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"invalid-array-"+name,{showGlobally:!0,message:"Invalid array<br>"+e.toString()})}input.set.call(this,value)},Node.prototype.hasOutput=function(e){return e in this._outputs},Node.prototype.registerOutput=function(e,t){if(this.hasOutput(e))throw new Error("Output property "+e+" already registered");const n=new OutputProperty({owner:this,getter:t.get||t.getter,name:e,onFirstConnectionAdded:t.onFirstConnectionAdded,onLastConnectionRemoved:t.onLastConnectionRemoved});this._outputs[e]=n,this._outputList.push(n)},Node.prototype.deregisterOutput=function(e){if(this.hasOutput(e)===!1)throw new Error("Output property "+e+" isn't registered");const t=this._outputs[e];if(t.hasConnections())throw new Error("Output property "+e+" has connections and can't be removed");delete this._outputs[e];var n=this._outputList.indexOf(t);this._outputList.splice(n,1)},Node.prototype.registerOutputs=function(e){for(var t in e)this.registerOutput(t,e[t])},Node.prototype.registerOutputIfNeeded=function(){},Node.prototype.getOutput=function(e){if(this.hasOutput(e)===!1)throw new Error("Node "+this.name+" doesn't have a port named "+e);return this._outputs[e]},Node.prototype.connectInput=function(e,t,n){if(this.hasInput(e)===!1)throw new Error("Invalid connection, input doesn't exist. Trying to connect from "+t.name+" output "+n+" to "+this.name+" input "+e);var o=t.getOutput(n);if(o.registerConnection(this,e),this._inputConnections[e]||(this._inputConnections[e]=[]),this._inputConnections[e].push(o),t._signalsSentThisUpdate[n])this._setValueFromConnection(e,!0),this._setValueFromConnection(e,!1);else{var r=o.value;r!==void 0&&(this._setValueFromConnection(e,r),this.context&&this.context.connectionSentValue(o,o.value))}this.flagDirty()},Node.prototype.removeInputConnection=function(e,t,n){if(!this._inputConnections[e])throw new Error("Node removeInputConnection: Input doesn't exist");const o=this._inputConnections[e];for(let r=0;r<o.length;r++){const s=o[r];if(s.owner.id===t&&s.name===n){o.splice(r,1),s.owner.getOutput(n).deregisterConnection(this,e);break}}o.length===0&&delete this._valuesFromConnections[e]},Node.prototype.isInputConnected=function(e){return this._inputConnections.hasOwnProperty(e)?this._inputConnections[e].some(t=>t.owner.name!=="Component Inputs"?!0:t.owner.nodeScope.componentOwner.isInputConnected(t.name)):!1},Node.prototype.update=function(){if(this._isUpdating||this._dirty===!1)return;this._updatedAtIteration!==this.context.updateIteration&&(this._updatedAtIteration=this.context.updateIteration,this._updateIteration=0,this._cyclicLoop&&(this._cyclicLoop=!1)),this._isUpdating=!0;const e=100;try{for(;this._dirty&&!this._cyclicLoop;){this._updateDependencies(),this._dirty=!1;const t=Object.keys(this._inputValuesQueue);let n=!0;for(;n&&!this._cyclicLoop;){n=!1;for(let r=0;r<t.length;r++){const s=t[r],a=this._inputValuesQueue[s];a.length>0&&(this.setInputValue(s,a.shift()),a.length>0&&(n=!0))}const o=this._afterInputsHaveUpdatedCallbacks;this._afterInputsHaveUpdatedCallbacks=[];for(let r=0;r<o.length;r++)o[r].call(this)}this._updateIteration++,this._updateIteration>=e&&(this._cyclicLoop=!0)}}catch(t){throw this._isUpdating=!1,t}this._cyclicLoop&&(this.context.scheduleNextFrame(()=>{this.context.nodeIsDirty(this)}),this.context.editorConnection&&!this._cyclicWarningSent&&this.context.isWarningTypeEnabled("cyclicLoops")&&(this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"cyclic-loop",{showGlobally:!0,message:"Cyclic loop detected"}),this._cyclicWarningSent=!0,console.log("cycle detected",{id:this.id,name:this.name,component:this.nodeScope.componentOwner.name}))),this._isFirstUpdate=!1,this._isUpdating=!1},Node.prototype._updateDependencies=function(){for(var e in this._inputConnections)for(var t=this._inputConnections[e],n=0;n<t.length;++n)t[n].owner.update()},Node.prototype.flagDirty=function(){this._dirty||(this._dirty=!0,this.updateOnDirtyFlagging&&this._performDirtyUpdate())},Node.prototype._performDirtyUpdate=function(){this.context&&this.context.nodeIsDirty(this);for(var e=0;e<this._outputList.length;++e)this._outputList[e].flagDependeesDirty()},Node.prototype.sendValue=function(e,t){if(this.hasOutput(e)===!1){console.log("Error: Node",this.name,"doesn't have a output named",e);return}if(t===void 0)return;const n=this.getOutput(e);n.sendValue(t),this.context&&this.context.connectionSentValue(n,t)},Node.prototype.flagOutputDirty=function(e){const t=this.getOutput(e);this.sendValue(e,t.value)},Node.prototype.flagAllOutputsDirty=function(){for(const e of this._outputList)this.sendValue(e.name,e.value)},Node.prototype.sendSignalOnOutput=function(e){if(this.hasOutput(e)===!1){console.log("Error: Node",this.name,"doesn't have a output named",e);return}const t=this.getOutput(e);t.sendValue(!0),t.sendValue(!1),this._signalsSentThisUpdate[e]=!0,this.scheduleAfterInputsHaveUpdated(function(){this._signalsSentThisUpdate[e]=!1}),this.context&&this.context.connectionSentSignal(t)},Node.prototype._setValueFromConnection=function(e,t){this._valuesFromConnections[e]=t,this.queueInput(e,t)},Node.prototype._hasInputBeenSetFromAConnection=function(e){return this._valuesFromConnections.hasOwnProperty(e)},Node.prototype.queueInput=function(e,t){if(this._inputValuesQueue[e]||(this._inputValuesQueue[e]=[]),this._isFirstUpdate){const n=this._inputValuesQueue[e][0];n===!0||(n instanceof Object&&n.unit&&!(t instanceof Object)&&(t={value:t,unit:n.unit}),this._inputValuesQueue[e].length=0)}this._inputValuesQueue[e].push(t),this.flagDirty()},Node.prototype.scheduleAfterInputsHaveUpdated=function(e){this._afterInputsHaveUpdatedCallbacks.push(e),this.flagDirty()},Node.prototype.setNodeModel=function(e){this.model=e,e.on("parameterUpdated",this._onNodeModelParameterUpdated,this),e.on("variantUpdated",this._onNodeModelVariantUpdated,this),e.on("inputPortRemoved",t=>{this.hasInput(t.name)&&this.deregisterInput(t.name)},this),e.on("outputPortRemoved",t=>{this.hasOutput(t.name)&&this.deregisterOutput(t.name)},this)},Node.prototype.addDeleteListener=function(e){this._deleteListeners.push(e)},Node.prototype._onNodeDeleted=function(){this.model&&(this.model.removeListenersWithRef(this),this.model=void 0),this._deleted=!0;for(const e of this._deleteListeners)e.call(this)},Node.prototype._onNodeModelParameterUpdated=function(e){if(this.registerInputIfNeeded(e.name),e.value!==void 0)if(e.state){if(!this._getVisualStates){console.log("Node has nos visual states, but got a parameter for state",e.state);return}this._getVisualStates().indexOf(e.state)!==-1&&this.queueInput(e.name,e.value)}else this.queueInput(e.name,e.value);else{let t;const n=this.variant;e.state?n&&n.stateParameters.hasOwnProperty(e.state)&&n.stateParameters[e.state].hasOwnProperty(e.name)?t=n.stateParameters[e.state][e.name]:this.model.parameters.hasOwnProperty(e.name)?t=this.model.parameters[e.name]:n&&n.parameters.hasOwnProperty(e.name)&&(t=n.parameters[e.name]):n&&n.parameters.hasOwnProperty(e.name)&&(t=n.parameters[e.name]),t===void 0&&(t=this.context.getDefaultValueForInput(this.model.type,e.name),this._resetReactVirtualDOM&&this._resetReactVirtualDOM()),this.queueInput(e.name,t)}},Node.prototype._onNodeModelVariantUpdated=function(e){this.setVariant(e)};function guid$1(){function e(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function NodeScope(e,t){this.context=e,this.nodes={},this.componentOwner=t,this.componentInstanceChildren={}}function verifyData(e,t){t.forEach(function(n){if(!e[n])throw new Error("Missing "+n)})}NodeScope.prototype.addConnection=function(e){try{verifyData(e,["sourceId","sourcePort","targetId","targetPort"])}catch(o){throw new Error("Error in connection: "+o.message)}try{var t=this.getNodeWithId(e.sourceId),n=this.getNodeWithId(e.targetId);n.registerInputIfNeeded(e.targetPort),t.registerOutputIfNeeded(e.sourcePort),n.connectInput(e.targetPort,t,e.sourcePort)}catch(o){console.error(o.message)}},NodeScope.prototype.setNodeParameters=function(e,t){const n=this.context.variants.getVariant(t.type,t.variant);if(n)e.setVariant(n);else{const s=t.parameters;var o=Object.keys(s);if(this.context.nodeRegister.hasNode(e.name)){var r=this.context.nodeRegister.getNodeMetadata(e.name);o.sort(function(a,l){var u=r.inputs[a],d=r.inputs[l];return(d?d.inputPriority:0)-(u?u.inputPriority:0)})}o.forEach(a=>{e.registerInputIfNeeded(a),e.hasInput(a)!==!1&&e.queueInput(a,s[a])})}},NodeScope.prototype.createNodeFromModel=async function(e,t){if(e.type==="Component Children"){if(e.parent){var n=this.getNodeWithId(e.parent.id);this.componentOwner.setChildRoot(n)}return}var o;try{o=await this.createNode(e.type,e.id),o.updateOnDirtyFlagging=t!==!1,o.setNodeModel(e)}catch(r){console.error(r.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("nodescope")&&this.context.editorConnection.sendWarning(this.componentOwner.name,e.id,"nodelibrary-unknown-node",{message:r.message,showGlobally:!0});return}return e.variant&&o.setVariant&&o.setVariant(e.variant),this.setNodeParameters(o,e),e.parent&&this.insertNodeInTree(o,e),o},NodeScope.prototype.insertNodeInTree=function(e,t){var n=this.getNodeWithId(t.parent.id),o=t.parent.children.indexOf(t);if(!n.addChild)throw new Error("Node "+n.id+" of type "+n.constructor.name+" can't have children");n.addChild(e,o)},NodeScope.prototype.getNodeWithId=function(e){if(this.nodes.hasOwnProperty(e)===!1)throw new Error("Unknown node id "+e);return this.nodes[e]},NodeScope.prototype.hasNodeWithId=function(e){return this.nodes.hasOwnProperty(e)},NodeScope.prototype.createPrimitiveNode=function(e,t,n){if(t||(t=guid$1()),this.nodes.hasOwnProperty(t))throw Error("duplicate id "+t);const o=this.context.nodeRegister.createNode(e,t,this);if(n)for(const r in n)o[r]=n[r];return this.nodes[t]=o,o},NodeScope.prototype.createNode=async function(e,t,n){if(t||(t=guid$1()),this.nodes.hasOwnProperty(t))throw Error("duplicate id "+t);let o;if(this.context.nodeRegister.hasNode(e)){if(o=this.context.nodeRegister.createNode(e,t,this),n)for(const r in n)o[r]=n[r]}else o=await this.context.createComponentInstanceNode(e,t,this,n),this.componentInstanceChildren[t]=o;return this.nodes[t]=o,o},NodeScope.prototype.getNodesWithIdRecursive=function(e){function t(o,r,s){o.nodes.hasOwnProperty(r)&&s.push(o.nodes[r]);var a=Object.keys(o.nodes).filter(function(l){return o.nodes[l]instanceof ComponentInstanceNode});a.forEach(function(l){t(o.nodes[l].nodeScope,r,s)})}var n=[];return t(this,e,n),n},NodeScope.prototype.getNodesWithType=function(e){var t=this,n=Object.keys(this.nodes).filter(function(o){return t.nodes[o].name===e});return n.map(function(o){return t.nodes[o]})},NodeScope.prototype.getNodesWithTypeRecursive=function(e){var t=this;function n(){o=o.concat(t.getNodesWithType(e));var r=Object.keys(t.nodes).filter(function(s){return t.nodes[s]instanceof ComponentInstanceNode});r.forEach(function(s){var a=t.nodes[s].nodeScope.getNodesWithTypeRecursive(e);o=o.concat(a)})}var o=[];return n(),o},NodeScope.prototype.getAllNodesRecursive=function(){let e=[];return(()=>{e=e.concat(Object.values(this.nodes));var t=Object.keys(this.nodes).filter(n=>this.nodes[n]instanceof ComponentInstanceNode);t.forEach(n=>{var o=this.nodes[n].nodeScope.getAllNodesRecursive();e=e.concat(o)})})(),e},NodeScope.prototype.getAllNodesWithVariantRecursive=function(e){return this.getAllNodesRecursive().filter(t=>t.variant===e)},NodeScope.prototype.onNodeModelRemoved=function(e){var t=this.getNodeWithId(e.id);if(e.parent){var n=this.getNodeWithId(e.parent.id);n.removeChild(t)}t._onNodeDeleted(),delete this.nodes[t.id],delete this.componentInstanceChildren[t.id]},NodeScope.prototype.removeConnection=function(e){var t=this.getNodeWithId(e.targetId);t.removeInputConnection(e.targetPort,e.sourceId,e.sourcePort)},NodeScope.prototype.setComponentModel=async function(e){this.componentModel=e;const t=[];for(const o of e.getAllNodes()){const r=await this.createNodeFromModel(o,!1);r&&t.push(r)}e.getAllConnections().forEach(o=>this.addConnection(o)),t.forEach(o=>o.updateOnDirtyFlagging=!0),t.forEach(o=>{o._dirty&&o._performDirtyUpdate()}),e.on("connectionAdded",o=>this.addConnection(o),this),e.on("connectionRemoved",this.removeConnection,this),e.on("nodeAdded",this.createNodeFromModel,this);var n=this;e.on("nodeParentWillBeRemoved",function(o){if(o.type==="Component Children"){o.parent&&this.componentOwner.setChildRoot(null);return}const r=n.getNodeWithId(o.id);r.parent&&r.parent.removeChild(r)},this),e.on("nodeParentUpdated",function(o){if(o.type==="Component Children"){var r=this.getNodeWithId(o.parent.id);this.componentOwner.setChildRoot(r)}else{var s=n.getNodeWithId(o.id);n.insertNodeInTree(s,o)}},this),e.on("nodeRemoved",function(o){o.type!=="Component Children"&&n.onNodeModelRemoved(o)},this);for(const o in this.nodes){const r=this.nodes[o];r.nodeScopeDidInitialize&&r.nodeScopeDidInitialize()}},NodeScope.prototype.reset=function(){this.componentModel&&(this.componentModel.removeListenersWithRef(this),this.componentModel=void 0),Object.keys(this.nodes).forEach(e=>{this.nodes.hasOwnProperty(e)&&this.deleteNode(this.nodes[e])})},NodeScope.prototype.deleteNode=function(e){if(this.nodes.hasOwnProperty(e.id)===!1){console.error("Node doesn't belong to this scope",e.id,e.name);return}if(e.parent&&e.parent.removeChild(e),e.getChildren&&e.getChildren().forEach(t=>{e.removeChild(t),(t.parentNodeScope||t.nodeScope).deleteNode(t)}),this.componentModel){const t=this.componentModel.getConnectionsFrom(e.id),n=this.componentModel.getConnectionsTo(e.id);t.concat(n).forEach(o=>{this.nodes.hasOwnProperty(o.targetId)&&this.nodes.hasOwnProperty(o.sourceId)&&this.removeConnection(o)})}e._onNodeDeleted(),delete this.nodes[e.id],delete this.componentInstanceChildren[e.id]},NodeScope.prototype.sendEventFromThisScope=function(e,t,n,o,r){if(o)for(var s=this.getNodesWithType("Event Receiver").filter(function(g){return g.getChannelName()===e}),a=0;a<s.length;a++){var l=s[a].handleEvent(t);if(l)return!0}if(n==="parent"&&this.componentOwner.parentNodeScope){const g=this.componentOwner.parent?this.componentOwner.parent.nodeScope:this.componentOwner.parentNodeScope;if(!g)return;g.sendEventFromThisScope(e,t,n,!0)}else if(n==="children"){var u=this.nodes;for(var d in u){var h=u[d].children;h&&h.forEach(g=>{if(g.name&&this.context.hasComponentModelWithName(g.name)){var b=g.nodeScope.sendEventFromThisScope(e,t,n,!0);if(b)return!0}})}}else if(n==="siblings"){let g;if(this.componentOwner.parent?g=this.componentOwner.parent.nodeScope:g=this.componentOwner.parentNodeScope,!g)return;var u=g.nodes;for(var d in u){var h=u[d].children;if(h){var f=h.filter(A=>A.name&&this.context.hasComponentModelWithName(A.name)&&A.nodeScope!==this);f.forEach(A=>{var v=A.nodeScope.sendEventFromThisScope(e,t,null,!0);if(v)return!0})}}}return!1};let componentIdCounter=0;function ComponentInstanceNode(e,t,n){Node.call(this,e,t),this.nodeScope=new NodeScope(e,this),this.parentNodeScope=n,this._internal.childRoot=null,this._internal.componentOutputValues={},this._internal.componentOutputs=[],this._internal.componentInputs=[],this._internal.inputValues={},this._internal.roots=[],this._internal.instanceId="__$ndl_componentInstaceId"+componentIdCounter,this.nodeScope.modelScope=n?n.modelScope:void 0,componentIdCounter++}ComponentInstanceNode.prototype=Object.create(Node.prototype,{setComponentModel:{value:async function(e){this.componentModel=e;var t=this;await this.nodeScope.setComponentModel(e),this._internal.componentInputs=this.nodeScope.getNodesWithType("Component Inputs"),this._internal.componentOutputs=this.nodeScope.getNodesWithType("Component Outputs"),Object.values(e.getInputPorts()).forEach(this.registerComponentInputPort.bind(this)),Object.values(e.getOutputPorts()).forEach(this.registerComponentOutputPort.bind(this));const n=e.roots||[];this._internal.roots=n.map(o=>this.nodeScope.getNodeWithId(o)),e.on("rootAdded",o=>{this._internal.roots.push(this.nodeScope.getNodeWithId(o)),this.forceUpdate()},this),e.on("rootRemoved",function(o){const r=this._internal.roots.findIndex(s=>s.id===o);r!==-1&&this._internal.roots.splice(r,1),this.forceUpdate()},this),e.on("inputPortAdded",this.registerComponentInputPort.bind(this),this),e.on("outputPortAdded",this.registerComponentOutputPort.bind(this),this),e.on("inputPortRemoved",function(o){t.hasInput(o.name)&&t.deregisterInput(o.name)},this),e.on("outputPortRemoved",function(o){this.hasOutput(o.name)&&t.deregisterOutput(o.name)},this),e.on("nodeAdded",function(o){o.type==="Component Inputs"?t._internal.componentInputs.push(t.nodeScope.getNodeWithId(o.id)):o.type==="Component Outputs"&&t._internal.componentOutputs.push(t.nodeScope.getNodeWithId(o.id))},this),e.on("nodeRemoved",function(o){function r(s,a){return s.filter(l=>l.id!==a)}o.type==="Component Inputs"?t._internal.componentInputs=r(t._internal.componentInputs,o.id):o.type==="Component Outputs"&&(t._internal.componentOutputs=r(t._internal.componentOutputs,o.id))},this),e.on("renamed",function(o){t.name=o.newName},this)}},_onNodeDeleted:{value(){this.componentModel&&(this.componentModel.removeListenersWithRef(this),this.componentModel=void 0),this.nodeScope.reset(),Node.prototype._onNodeDeleted.call(this)}},registerComponentInputPort:{value(e){this.registerInput(e.name,{set(t){this._internal.inputValues[e.name]=t,this._internal.componentInputs.forEach(function(n){n.registerOutputIfNeeded(e.name),n.flagOutputDirty(e.name)})}})}},registerComponentOutputPort:{value(e){this.registerOutput(e.name,{getter(){return this._internal.componentOutputValues[e.name]}})}},setOutputFromComponentOutput:{value(e,t){this.hasOutput(e)!==!1&&(this._internal.creatorCallbacks&&this._internal.creatorCallbacks.onOutputChanged&&this._internal.creatorCallbacks.onOutputChanged(e,t,this._internal.componentOutputValues[e]),this._internal.componentOutputValues[e]=t,this.flagOutputDirty(e))}},setChildRoot:{value(e){const t=this._internal.childRoot,n=e;if(this._internal.childRoot=n,this.model&&this.model.children){const o=this.parentNodeScope,r=this.model.children.filter(s=>s.type!=="Component Children").map(s=>o.getNodeWithId(s.id));if(t)for(let s=0;s<r.length;s++)t.isChild(r[s])&&t.removeChild(r[s]);if(n)for(let s=0;s<r.length;s++){const a=r[s],l=a.model.parent.children.indexOf(a.model);this.addChild(a,l)}}}},getChildRootIndex:{value(){if(!this._internal.childRoot||!this._internal.childRoot.model||!this._internal.childRoot.model.children)return 0;for(var e=this._internal.childRoot.model.children,t=0;t<e.length;t++)if(e[t].type==="Component Children")return t;return 0}},getChildRoot:{value(){return this._internal.childRoot?this._internal.childRoot:null}},getRoots:{value(){return this._internal.roots}},triggerDidMount:{value(){this._internal.roots.forEach(e=>{e.triggerDidMount&&e.triggerDidMount()})}},render:{value(){return this._internal.roots.length===0?null:this._internal.roots[0].render()}},setChildIndex:{value(e){this.getRoots().forEach(t=>t.setChildIndex&&t.setChildIndex(e))}},addChild:{value(e,t){this.getChildRoot().addChild(e,t+this.getChildRootIndex())}},removeChild:{value(e){this.getChildRoot().removeChild(e)}},getChildren:{value(e){const t=this.getChildRoot();return t?t.getChildren():[]}},isChild:{value(e){return this.getChildRoot()?this.getChildRoot().isChild(e):!1}},contains:{value(e){return this.getRoots().some(t=>t.contains&&t.contains(e))}},_performDirtyUpdate:{value(){Node.prototype._performDirtyUpdate.call(this);for(var e=this._internal.componentInputs,t=0,n=e.length;t<n;t++)e[t].flagDirty();this._internal.componentOutputs.forEach(function(o){o.flagDirty()})}},getRef:{value(){const e=this._internal.roots[0];return e?e.getRef():void 0}},update:{value(){Node.prototype.update.call(this),this._internal.componentOutputs.forEach(function(e){e.update()})}},forceUpdate:{value(){this.parent&&(this.parent.cachedChildren=void 0,this.parent.forceUpdate())}},getInstanceId:{value(){return this._internal.instanceId}}}),ComponentInstanceNode.prototype.constructor=ComponentInstanceNode;function NodeContext(e){e=e||{},e.runningInEditor=e.hasOwnProperty("runningInEditor")?e.runningInEditor:!1,this._dirtyNodes=[],this.callbacksAfterUpdate=[],this.graphModel=e.graphModel,this.platform=e.platform,this.eventEmitter=new EventEmitter$2,this.eventEmitter.setMaxListeners(1e6),this.eventSenderEmitter=new EventEmitter$2,this.eventSenderEmitter.setMaxListeners(1e6),this.globalValues={},this.globalsEventEmitter=new EventEmitter$2,this.globalsEventEmitter.setMaxListeners(1e6),this.runningInEditor=e.runningInEditor,this.currentFrameTime=0,this.frameNumber=0,this.updateIteration=0,this.nodeRegister=new NodeRegister(this),this.timerScheduler=new TimerScheduler(this.scheduleUpdate.bind(this)),this.componentModels={},this.debugInspectorsEnabled=!1,this.connectionsToPulse={},this.connectionsToPulseChanged=!1,this.debugInspectors={},this.connectionPulsingCallbackScheduled=!1,this.editorConnection=e.editorConnection,this.rootComponent=void 0,this._outputHistory={},this._signalHistory={},this.warningTypes={},this.bundleFetchesInFlight=new Map,this.variants=new Variants({graphModel:this.graphModel,getNodeScope:()=>this.rootComponent?this.rootComponent.nodeScope:null}),this.editorConnection&&(this.editorConnection.on("debugInspectorsUpdated",t=>{this.onDebugInspectorsUpdated(t)}),this.editorConnection.on("getConnectionValue",({clientId:t,connectionId:n})=>{if(this.editorConnection.clientId!==t)return;const o=this._outputHistory[n];this.editorConnection.sendConnectionValue(n,o?o.value:void 0)}))}NodeContext.prototype.setRootComponent=function(e){this.rootComponent=e},NodeContext.prototype.getCurrentTime=function(){return this.platform.getCurrentTime()},NodeContext.prototype.onDebugInspectorsUpdated=function(e){this.debugInspectorsEnabled&&(e=e.map(t=>{if(t.type==="connection"){const n=t.connection;t.id=n.fromId+n.fromProperty}else t.type==="node"&&(t.id=t.nodeId);return t}),this.debugInspectors={},e.forEach(t=>this.debugInspectors[t.id]=t),this.sendDebugInspectorValues())},NodeContext.prototype.updateDirtyNodes=function(){var e,t,n=!0,o=0;for(this.updateIteration++,this.isUpdating=!0;n&&o<10;){var r=this._dirtyNodes;for(this._dirtyNodes=[],e=0,t=r.length;e<t;++e)try{r[e]._deleted||r[e].update()}catch(a){console.error(a,a.stack)}var s=this.callbacksAfterUpdate;for(this.callbacksAfterUpdate=[],e=0,t=s.length;e<t;e++)try{s[e]()}catch(a){console.error(a)}n=this.callbacksAfterUpdate.length>0||this._dirtyNodes.length>0,o++}this.isUpdating=!1},NodeContext.prototype.update=function(){this.frameNumber++,this.updateDirtyNodes(),this.timerScheduler.hasPendingTimers()&&(this.scheduleUpdate(),this.timerScheduler.runTimers(this.currentFrameTime)),this.debugInspectorsEnabled&&this.sendDebugInspectorValues()},NodeContext.prototype.reset=function(){this.eventEmitter.emit("applicationDataReloaded");var e=this.eventEmitter;["frameStart","frameEnd"].forEach(function(t){e.removeAllListeners(t)}),this.globalValues={},this._dirtyNodes.length=0,this.callbacksAfterUpdate.length=0,this.timerScheduler.runningTimers=[],this.timerScheduler.newTimers=[],this.rootComponent=void 0,this.clearDebugInspectors()},NodeContext.prototype.nodeIsDirty=function(e){this._dirtyNodes.push(e),this.scheduleUpdate()},NodeContext.prototype.scheduleUpdate=function(){this.eventEmitter.emit("scheduleUpdate")},NodeContext.prototype.scheduleAfterUpdate=function(e){this.callbacksAfterUpdate.push(e),this.scheduleUpdate()},NodeContext.prototype.scheduleNextFrame=function(e){this.eventEmitter.once("frameStart",e),this.scheduleUpdate()},NodeContext.prototype.setGlobalValue=function(e,t){this.globalValues[e]=t,this.globalsEventEmitter.emit(e)},NodeContext.prototype.getGlobalValue=function(e){return this.globalValues[e]},NodeContext.prototype.registerComponentModel=function(e){if(this.componentModels.hasOwnProperty(e.name))throw new Error("Duplicate component name "+e.name);this.componentModels[e.name]=e;var t=this;e.on("renamed",function(n){delete t.componentModels[n.oldName],t.componentModels[n.newName]=e},this)},NodeContext.prototype.deregisterComponentModel=function(e){this.componentModels.hasOwnProperty(e.name)&&(this.componentModels[e.name].removeListenersWithRef(this),delete this.componentModels[e.name])},NodeContext.prototype.fetchComponentBundle=async function(e){const t=async n=>{let o=`${Noodl.Env.BaseUrl||"/"}noodl_bundles/${n}.json`;const r=await fetch(o);if(r.status===404)throw new Error("Component not found "+n);const s=await r.json();for(const a of s)this.graphModel.hasComponentWithName(a.name)===!1&&await this.graphModel.importComponentFromEditorData(a)};if(this.bundleFetchesInFlight.has(e))await this.bundleFetchesInFlight.get(e);else{const n=t(e);this.bundleFetchesInFlight.set(e,n),await n}},NodeContext.prototype.getComponentModel=async function(e){if(!e)throw new Error("Component instance must have a name");if(this.componentModels.hasOwnProperty(e)===!1){const t=this.graphModel.getBundleContainingComponent(e);if(!t)throw new Error("Can't find component model for "+e);for(const n of this.graphModel.getBundleDependencies(t))this.fetchComponentBundle(n);await this.fetchComponentBundle(t)}return this.componentModels[e]},NodeContext.prototype.hasComponentModelWithName=function(e){return this.componentModels.hasOwnProperty(e)},NodeContext.prototype.createComponentInstanceNode=async function(e,t,n,o){var r=new ComponentInstanceNode(this,t,n);r.name=e;for(const a in o)r[a]=o[a];const s=await this.getComponentModel(e);return await r.setComponentModel(s),r},NodeContext.prototype._formatConnectionValue=function(e){if(typeof e=="object"&&e&&e.constructor&&e.constructor.name==="Node")e="<Node> "+e.name;else if(typeof e=="object"&&typeof window<"u"&&e instanceof HTMLElement)e=`DOM Node <${e.tagName}>`;else{if(typeof e=="string"&&!e.startsWith("[Signal]"))return'"'+e+'"';if(Number.isNaN(e))return"NaN"}return e},NodeContext.prototype.connectionSentValue=function(e,t){if(!this.editorConnection||!this.editorConnection.isConnected()||!this.debugInspectorsEnabled)return;const n=this.getCurrentTime();if(this._outputHistory[e.id]={value:t,timestamp:n},this.connectionsToPulse.hasOwnProperty(e.id)){this.connectionsToPulse[e.id].timestamp=n;return}const o=[];e.connections.forEach(r=>{o.push(e.owner.id+e.name+r.node.id+r.inputPortName)}),this.connectionsToPulse[e.id]={timestamp:n,connections:o},this.connectionsToPulseChanged=!0,this.connectionPulsingCallbackScheduled===!1&&(this.connectionPulsingCallbackScheduled=!0,setTimeout(this.clearOldConnectionPulsing.bind(this),100))},NodeContext.prototype.connectionSentSignal=function(e){const t=e.id;this._signalHistory.hasOwnProperty(t)||(this._signalHistory[t]={count:0}),this._signalHistory[t].count++,this.connectionSentValue(e,"[Signal] Trigger count "+this._signalHistory[t].count)},NodeContext.prototype.clearDebugInspectors=function(){this.debugInspectors={},this.connectionsToPulse={},this.editorConnection.sendPulsingConnections(this.connectionsToPulse)},NodeContext.prototype.clearOldConnectionPulsing=function(){this.connectionPulsingCallbackScheduled=!1;var e=this.getCurrentTime(),t=this,n=Object.keys(this.connectionsToPulse);n.forEach(function(o){var r=t.connectionsToPulse[o];e-r.timestamp>100&&(t.connectionsToPulseChanged=!0,delete t.connectionsToPulse[o])}),this.connectionsToPulseChanged&&(this.connectionsToPulseChanged=!1,this.editorConnection.sendPulsingConnections(this.connectionsToPulse)),Object.keys(this.connectionsToPulse).length>0&&(this.connectionPulsingCallbackScheduled=!0,setTimeout(this.clearOldConnectionPulsing.bind(this),500))},NodeContext.prototype._getDebugInspectorValueForNode=function(e){if(!this.rootComponent)return;const t=this.rootComponent.nodeScope.getNodesWithIdRecursive(e),n=t[t.length-1];if(n&&n.getInspectInfo){const o=n.getInspectInfo();if(o!==void 0)return{type:"node",id:e,value:o}}},NodeContext.prototype.sendDebugInspectorValues=function(){const e=[];for(const t in this.debugInspectors){const n=this.debugInspectors[t];if(n.type==="connection"&&this._outputHistory.hasOwnProperty(t)){const o=this._outputHistory[t].value;e.push({type:"connection",id:t,value:this._formatConnectionValue(o)})}else if(n.type==="node"){const o=this._getDebugInspectorValueForNode(t);o&&e.push(o)}}e.length>0&&this.editorConnection.sendDebugInspectorValues(e),this.connectionsToPulseChanged&&(this.connectionsToPulseChanged=!1,this.editorConnection.sendPulsingConnections(this.connectionsToPulse))},NodeContext.prototype.setDebugInspectorsEnabled=function(e){this.debugInspectorsEnabled=e,this.editorConnection.debugInspectorsEnabled=e,e&&this.sendDebugInspectorValues()},NodeContext.prototype.sendGlobalEventFromEventSender=function(e,t){this.eventSenderEmitter.emit(e,t)},NodeContext.prototype.setPopupCallbacks=function({onShow:e,onClose:t}){this.onShowPopup=e,this.onClosePopup=t},NodeContext.prototype.showPopup=async function(e,t,n){if(!this.onShowPopup)return;const o=this.rootComponent.nodeScope,r=await o.createNode(e);for(const d in t)r.setInputValue(d,t[d]);r.popupParent=n?.senderNode||null;const s=o.createPrimitiveNode("Group");s.setInputValue("flexDirection","node"),s.setInputValue("cssClassName","noodl-popup");const a=this.graphModel.getSettings().bodyScroll;s.setInputValue("position",a?"fixed":"absolute");var l=r.nodeScope.getNodesWithType("NavigationClosePopup");if(l&&l.length>0)for(var u=0;u<l.length;u++)l[u]._setCloseCallback((d,h)=>{this.scheduleNextFrame(()=>{o.hasNodeWithId(s.id)&&(this.onClosePopup(s),o.deleteNode(s),n&&n.onClosePopup&&n.onClosePopup(d,h))})});this.onShowPopup(s),requestAnimationFrame(()=>{s.addChild(r)})},NodeContext.prototype.setWarningTypes=function(e){Object.assign(this.warningTypes,e)},NodeContext.prototype.isWarningTypeEnabled=function(e){return this.warningTypes.hasOwnProperty(e)?!!this.warningTypes[e]:!0},NodeContext.prototype.getDefaultValueForInput=function(e,t){if(this.nodeRegister.hasNode(e)===!1)return;const n=this.nodeRegister.getNodeMetadata(e).inputs[t];if(n)return n.type.defaultUnit?{value:n.default,unit:n.type.defaultUnit}:n.default};function EventSender$2(){this.listeners={},this.listenersWithRefs={}}EventSender$2.prototype.on=function(e,t,n){n?(this.listenersWithRefs.hasOwnProperty(e)||(this.listenersWithRefs[e]=new Map),this.listenersWithRefs[e].get(n)||this.listenersWithRefs[e].set(n,[]),this.listenersWithRefs[e].get(n).push(t)):(this.listeners.hasOwnProperty(e)||(this.listeners[e]=[]),this.listeners[e].push(t))},EventSender$2.prototype.removeListenersWithRef=function(e){Object.keys(this.listenersWithRefs).forEach(t=>{const n=this.listenersWithRefs[t];n.has(e)&&n.delete(e)})},EventSender$2.prototype.removeAllListeners=function(e){e?(delete this.listeners[e],delete this.listenersWithRefs[e]):(this.listeners={},this.listenersWithRefs={})},EventSender$2.prototype.emit=async function(e,t){const n=this.listeners[e];if(n)for(let r=0;r<n.length;r++){const s=n[r];await Promise.resolve(s.call(null,t))}const o=this.listenersWithRefs[e];if(o)for(const[r,s]of o)for(const a of s)await Promise.resolve(a.call(r,t))};function Services(){}Services.events=new EventEmitter$2;class ActiveWarnings{constructor(){this.currentWarnings=new Map}setWarning(t,n,o){if(this.currentWarnings.has(t)){const r=this.currentWarnings.get(t);return r[n]===o?!1:(r[n]=o,!0)}else return this.currentWarnings.set(t,{[n]:o}),!0}clearWarning(t,n){const o=this.currentWarnings.get(t);return!o||!o[n]?!1:(delete o[n],Object.keys(o).length===0&&delete this.currentWarnings.delete(t),!0)}clearWarnings(t){return this.currentWarnings.has(t)===!1?!1:(this.currentWarnings.delete(t),!0)}}function EditorConnection(e){var t=e||{};EventSender$2.call(this),this.runtimeType=t.runtimeType,this.platform=t.platform,this.ws=t.platform&&t.platform.webSocketClass||(typeof WebSocket<"u"?WebSocket:void 0),this.wsOptions=t.platform&&t.platform.webSocketOptions||void 0,this.reconnectOnClose=!0,this.enableDebugger=!1,this.lastSendTimestamp=0,this.sendQueue=[],this.sendTimer=void 0,this.activeWarnings=new ActiveWarnings}EditorConnection.prototype=Object.create(EventSender$2.prototype),EditorConnection.prototype.constructor=EditorConnection,EditorConnection.prototype.isRunningLocally=function(){var e=this.platform.isRunningLocally&&this.platform.isRunningLocally()||typeof document<"u"&&(document.location.hostname==="localhost"||document.location.hostname==="127.0.0.1");return e},EditorConnection.prototype.connect=function(e){this.socket=this.wsOptions?new this.ws(e,this.wsOptions):new this.ws(e);var t=this;this.socket.addEventListener("open",function(){t.clientId=guid$1(),t.socket.send(JSON.stringify({cmd:"register",type:"viewer",clientId:t.clientId})),t.emit("connected")}),this.socket.addEventListener("close",function(n){t.reconnectOnClose&&t.reconnect(e),console.log("Editor connection closed",n.code,n.reason),t.emit("connectionClosed")}),this.socket.addEventListener("error",function(n){console.log("Editor connection error, trying to reconnect")}),this.socket.addEventListener("message",async n=>{const o=typeof n.data=="string"?n.data:await n.data.text(),r=JSON.parse(o);let s;r.cmd==="registered"||(r.cmd==="export"?(s=JSON.parse(r.content),r.type==="full"&&r.target===this.clientId&&t.emit("exportDataFull",s)):r.cmd==="hoverStart"?t.emit("hoverStart",r.content.id):r.cmd==="hoverEnd"?t.emit("hoverEnd",r.content.id):r.cmd==="refresh"?t.emit("reload"):r.cmd==="debugInspectors"?this.debugInspectorsEnabled&&(s=JSON.parse(r.content),t.emit("debugInspectorsUpdated",s.inspectors)):r.cmd==="debuggingEnabled"?t.isRunningLocally()&&(s=JSON.parse(r.content),t.emit("debuggingEnabledChanged",s.enabled)):r.cmd==="getConnectionValue"?t.isRunningLocally()&&(s=JSON.parse(r.content),await t.emit("getConnectionValue",{clientId:s.clientId,connectionId:s.connectionId})):r.cmd==="modelUpdate"?await t.emit("modelUpdate",r.content):r.cmd==="publish"?Services.pubsub.routeMessage(r):r.cmd==="noodlModules"?t.emit("noodlModules",JSON.parse(r.content)):r.cmd==="mqttUpdate"?t.emit("mqttUpdate",r.content):r.cmd==="activeComponentChanged"?t.emit("activeComponentChanged",r.component):console.log("Command not implemented",r))})},EditorConnection.prototype.reconnect=function(e){var t=this;setTimeout(function(){t.connect(e)},2e3)},EditorConnection.prototype.isConnected=function(){return this.socket!==void 0&&this.socket.readyState===this.ws.OPEN};const getCircularReplacer=()=>{const e=new WeakSet;return(t,n)=>{if(typeof n=="object"&&n!==null){if(e.has(n))return"[Circular]";e.add(n)}return n}};EditorConnection.prototype.send=function(e){const t=this.platform.getCurrentTime(),n=t-this.lastSendTimestamp,o=r=>{try{this.socket.send(JSON.stringify(r))}catch(s){if(s.message&&s.message.startsWith("Converting circular"))try{this.socket.send(JSON.stringify(r,getCircularReplacer()))}catch(a){console.log("failed to send message to editor",r,a)}else console.log("failed to send message to editor",r,s)}};n<200||this.sendTimer||!this.isConnected()?(this.sendQueue.push(e),this.sendTimer||(this.sendTimer=setTimeout(()=>{if(this.isConnected()===!1)return;const r=50;for(let s=0;s<this.sendQueue.length;s+=r){const a=this.sendQueue.slice(s,s+r);o(a)}this.sendQueue=[],this.sendTimer=void 0,this.lastSendTimestamp=this.platform.getCurrentTime()},100))):(this.lastSendTimestamp=t,o(e))},EditorConnection.prototype.sendInspectId=function(e){this.send({cmd:"select",type:"viewer",content:JSON.stringify({id:e})})},EditorConnection.prototype.sendSelectComponent=function(e){this.send({cmd:"select",type:"viewer",content:JSON.stringify({componentName:e})})},EditorConnection.prototype.sendPulsingConnections=function(e){var t=[];Object.keys(e).forEach(function(n){var o=e[n];t=t.concat(o.connections)}),this.send({cmd:"connectiondebugpulse",type:"viewer",content:JSON.stringify({connectionsToPulse:t})})},EditorConnection.prototype.sendDebugInspectorValues=function(e){this.send({cmd:"debuginspectorvalues",type:"viewer",content:{inspectors:e}})},EditorConnection.prototype.sendConnectionValue=function(e,t){this.send({cmd:"connectionValue",type:"viewer",content:{connectionId:e,value:t}})};const dynamicPortsHash={};function _detectRename(e,t){if(!(!e||!t)&&e.length===t.length){for(var n={},o=0;o<e.length;o++){if(t.indexOf(e[o])===-1){if(n.before)return;n.before=e[o]}if(e.indexOf(t[o])===-1){if(n.after)return;n.after=t[o]}}return n.before&&n.after?n:void 0}}EditorConnection.prototype.sendDynamicPorts=function(e,t,n){var o=JSON.stringify(t);if(dynamicPortsHash[e]!==o){if(dynamicPortsHash[e]&&t&&n&&n.detectRenamed){var r=Array.isArray(n.detectRenamed)?n.detectRenamed:[n.detectRenamed],s=[];r.forEach(a=>{var l=JSON.parse(dynamicPortsHash[e]),u=[].concat(t);a.prefix&&(l=l.filter(h=>h.name.startsWith(a.prefix)),u=u.filter(h=>h.name.startsWith(a.prefix))),a.plug&&(l=l.filter(h=>h.plug===a.plug),u=u.filter(h=>h.plug===a.plug)),u=u.map(h=>h.name.substring((a.prefix||"").length)),l=l.map(h=>h.name.substring((a.prefix||"").length));var d=_detectRename(l,u);d&&s.push({plug:a.plug,patterns:[(a.prefix||"")+"{{*}}"],before:d.before,after:d.after})}),s.length>0&&(n.renamed=s),delete n.detectRenamed}dynamicPortsHash[e]=o,this.send({cmd:"instanceports",type:"viewer",content:JSON.stringify({nodeid:e,ports:t,options:n})})}},EditorConnection.prototype.sendWarning=function(e,t,n,o){this.activeWarnings.setWarning(t,n,o)&&this.send({cmd:"showwarning",type:"viewer",content:JSON.stringify({componentName:e,nodeId:t,key:n,warning:o})})},EditorConnection.prototype.clearWarning=function(e,t,n){this.activeWarnings.clearWarning(t,n)&&this.send({cmd:"showwarning",type:"viewer",content:JSON.stringify({componentName:e,nodeId:t,key:n,warning:void 0})})},EditorConnection.prototype.clearWarnings=function(e,t){this.activeWarnings.clearWarnings(t)&&this.send({cmd:"clearwarnings",type:"viewer",content:JSON.stringify({componentName:e,nodeId:t})})},EditorConnection.prototype.sendPatches=function(e){this.send({cmd:"patchproject",type:"viewer",content:JSON.stringify(e)})},EditorConnection.prototype.requestFullExport=function(){this.send({cmd:"register",type:"viewer"})},EditorConnection.prototype.requestNoodlModules=function(){this.send({cmd:"getNoodlModules",type:"viewer"})};var serviceRequests={};EditorConnection.prototype.sendServiceRequest=function(e,t){e.token=guid$1(),e.clientId=this.clientId,serviceRequests[e.token]=t,this.send(e)},EditorConnection.prototype.close=function(){this.reconnectOnClose=!1,this.isConnected()!==!1&&this.socket.close()},EditorConnection.prototype.sendNodeLibrary=function(e){this.send({cmd:"nodelibrary",type:"viewer",runtimeType:this.runtimeType,content:e,clientId:this.clientId})},EditorConnection.prototype.sendComponentMetadata=function(e,t,n){this.send({cmd:"componentMetadata",type:"viewer",content:JSON.stringify({componentName:e,key:t,data:n})})},EditorConnection.prototype.sendProjectMetadata=function(e,t){this.send({cmd:"projectMetadata",type:"viewer",content:JSON.stringify({key:e,data:t})})};function formatDynamicPorts(e){const t=[];for(const n of e.dynamicports)if(n.ports||n.template||n.port||n.channelPort)t.push(n);else if(n.inputs||n.outputs){const o=[];if(n.inputs)for(const s of n.inputs)o.push(formatPort(s,e.inputs[s],"input"));if(n.outputs)for(const s of n.outputs)o.push(formatPort(s,e.outputs[s],"output"));const r={name:n.name||"conditionalports/basic",condition:n.condition,ports:o};t.push(r)}return t}function formatPort(e,t,n){var o={name:e,type:t.type,plug:n};return t.group&&(o.group=t.group),t.displayName&&(o.displayName=t.displayName),t.description&&(o.description=t.description),t.editorName&&(o.editorName=t.editorName),t.default!==void 0&&(o.default=t.default),t.hasOwnProperty("index")&&(o.index=t.index),t.tooltip&&(o.tooltip=t.tooltip),t.tab&&(o.tab=t.tab),t.popout&&(o.popout=t.popout),t.allowVisualStates&&(o.allowVisualStates=t.allowVisualStates),o}function generateNodeLibrary(e){var t={typecasts:[{from:"string",to:["number","boolean","image","color","enum","textStyle","dimension","array","object"]},{from:"boolean",to:["number","string","signal"]},{from:"number",to:["boolean","string","dimension"]},{from:"date",to:["string"]},{from:"signal",to:["boolean","number"]},{from:"image",to:[]},{from:"cloudfile",to:["string","image"]},{from:"color",to:[]},{from:"enum",to:[]},{from:"object",to:[]},{from:"domelement",to:[]},{from:"reference",to:[]},{from:"font",to:[]},{from:"textStyle",to:["string"]},{from:"collection",to:["array"]},{from:"array",to:["collection"]}],dynamicports:[{type:"conditionalports",name:"basic"},{type:"expand",name:"basic"}],colors:{nodes:{component:{base:"#643D8B",baseHighlighted:"#79559b",header:"#4E2877",headerHighlighted:"#643d8b",outline:"#4E2877",outlineHighlighted:"#b58900",text:"#dbd0e4"},visual:{base:"#315272",baseHighlighted:"#4d6784",header:"#173E5D",headerHighlighted:"#315272",outline:"#173E5D",outlineHighlighted:"#b58900",text:"#cfd5de"},data:{base:"#465524",baseHighlighted:"#5b6a37",header:"#314110",headerHighlighted:"#465524",outline:"#314110",outlineHighlighted:"#b58900",text:"#d2d6c5"},javascript:{base:"#7E3660",baseHighlighted:"#944e74",header:"#67214B",headerHighlighted:"#7e3660",outline:"#67214B",outlineHighlighted:"#d57bab",text:"#e4cfd9"},default:{base:"#4C4F59",baseHighlighted:"#62656e",header:"#373B45",headerHighlighted:"#4c4f59",outline:"#373B45",outlineHighlighted:"#b58900",text:"#d3d4d6"}},connections:{signal:{normal:"#006f82",highlighted:"#7ec2cf",pulsing:"#ffffff"},default:{normal:"#875d00",highlighted:"#e5ae32",pulsing:"#ffffff"}}},nodetypes:[{name:"Component Children",shortDesc:"This node is a placeholder for where children of this component will be inserted.",docs:"https://docs.noodl.net/nodes/component-utilities/component-children",color:"component",allowAsChild:!0,category:"Visual",haveComponentChildren:["Visual"]}]},n=Object.keys(e._constructors);n.forEach(function(s){var a=e._constructors[s].metadata,l={name:s,searchTags:a.searchTags};t.nodetypes.push(l),a.version&&(l.version=a.version),a.displayNodeName&&(l.displayNodeName=a.displayNodeName),a.nodeDoubleClickAction&&(l.nodeDoubleClickAction=a.nodeDoubleClickAction),a.shortDesc&&(l.shortDesc=a.shortDesc),a.module&&(l.module=a.module),a.deprecated&&(l.deprecated=!0),a.haveComponentPorts&&(l.haveComponentPorts=!0),a.category==="Visual"&&(l.allowAsChild=!0,l.allowAsExportRoot=!0,l.color="visual"),a.allowAsExportRoot!==void 0&&(l.allowAsExportRoot=a.allowAsExportRoot),a.allowChildren&&(l.allowChildrenWithCategory=["Visual"],l.color="visual"),a.allowChildrenWithCategory&&(l.allowChildrenWithCategory=a.allowChildrenWithCategory),a.singleton&&(l.singleton=!0),a.allowAsChild&&(l.allowAsChild=!0),a.docs&&(l.docs=a.docs),a.shortDocs?l.shortDocs=a.shortDocs:a.docs&&a.docs.indexOf("https://docs.noodl.net")===0&&(l.shortDocs=a.docs.replace("/#","")+"-short.md"),l.category=a.category,a.panels&&(l.panels=a.panels),a.usePortAsLabel&&(l.usePortAsLabel=a.usePortAsLabel,l.portLabelTruncationMode=a.portLabelTruncationMode),a.color&&(l.color=a.color),a.dynamicports&&(l.dynamicports=formatDynamicPorts(a)),a.exportDynamicPorts&&(l.exportDynamicPorts=a.exportDynamicPorts),a.visualStates&&(l.visualStates=a.visualStates),a.useVariants&&(l.useVariants=a.useVariants),a.connectionPanel&&(l.connectionPanel=a.connectionPanel),l.ports=[];var u=l.dynamicports||[],d={},h={};u.filter(g=>g.channelPort!==void 0).forEach(g=>{h[g.channelPort.plug+"/"+g.channelPort.name]=!0}),u.length&&(l.dynamicports=u),Object.keys(a.inputs).forEach(function(g){if(!(d.hasOwnProperty("input/"+g)||h.hasOwnProperty("input/"+g))){var b=a.inputs[g];b.exportToEditor!==!1&&l.ports.push(formatPort(g,b,"input"))}});function f(g,b){var _={name:g,type:b.type,plug:"output"};b.group&&(_.group=b.group),b.displayName&&(_.displayName=b.displayName),b.editorName&&(_.editorName=b.editorName),b.hasOwnProperty("index")&&(_.index=b.index),l.ports.push(_)}Object.keys(a.outputs).forEach(function(g){if(!(d.hasOwnProperty("output/"+g)||h.hasOwnProperty("output/"+g))){var b=a.outputs[g];f(g,b)}})});const o=[{name:"UI Elements",description:"Buttons, inputs, containers, media",type:"visual",subCategories:[{name:"Basic Elements",items:["Group","net.noodl.visual.columns","Text","Image","Video","Circle","net.noodl.visual.icon"]},{name:"UI Controls",items:["net.noodl.controls.button","net.noodl.controls.checkbox","net.noodl.controls.options","net.noodl.controls.radiobutton","Radio Button Group","net.noodl.controls.range","net.noodl.controls.textinput"]}]},{name:"Navigation & Popups",description:"Page routing, navigation, popups",type:"logic",subCategories:[{name:"Navigation",items:["Router","RouterNavigate","PageInputs","net.noodl.externallink","PageStackNavigateToPath"]},{name:"Component Stack",items:["Page Stack","PageStackNavigate","PageStackNavigateBack"]},{name:"Popups",items:["NavigationShowPopup","NavigationClosePopup"]}]},{name:"Logic & Utilities",description:"Logic, events, string manipulation",type:"logic",subCategories:[{name:"General Utils",items:["States","Value Changed","Timer","Color Blend","Number Remapper","Counter","Drag","net.noodl.animatetovalue"]},{name:"Logic",items:["Boolean To String","Switch","And","Or","Condition","Inverter"]},{name:"Events",items:["Event Sender","Event Receiver"]},{name:"String Manipulation",items:["Substring","String Mapper","String Format","Date To String","Unique Id"]},{name:"System",items:["Screen Resolution","Open File Picker"]},{name:"Variables",items:["String","Boolean","Color","Number"]}]},{name:"Component Utilities",description:"Component inputs, outputs & object",type:"component",subCategories:[{name:"",items:["Component Inputs","Component Outputs","Component Children","net.noodl.ComponentObject","net.noodl.ParentComponentObject","net.noodl.SetComponentObjectProperties","net.noodl.SetParentComponentObjectProperties"]}]},{name:"Read & Write Data",description:"Arrays, objects, cloud data",type:"data",subCategories:[{name:"",items:["RunTasks","For Each","For Each Actions","Model2","SetModelProperties","NewModel","Set Variable","Variable2"]},{name:"Array",items:["Collection2","CollectionNew","CollectionRemove","CollectionClear","CollectionInsert","Filter Collection","Map Collection","Static Data"]},{name:"Cloud Data",items:["DbModel2","NewDbModelProperties","FilterDBModels","SetDbModelProperties","DbCollection2","DeleteDbModelProperties","AddDbModelRelation","RemoveDbModelRelation","Cloud File","Upload File","CloudFunction2","DbConfig"]},{name:"User",items:["net.noodl.user.LogIn","net.noodl.user.LogOut","net.noodl.user.SignUp","net.noodl.user.User","net.noodl.user.SetUserProperties","net.noodl.user.VerifyEmail","net.noodl.user.SendEmailVerification","net.noodl.user.ResetPassword","net.noodl.user.RequestPasswordReset"]},{name:"External Data",items:["REST2"]}]},{name:"Custom Code",description:"Custom JavaScript and CSS",type:"javascript",subCategories:[{name:"",items:["Expression","JavaScriptFunction","Javascript2","CSS Definition"]}]},{name:"Cloud Functions",description:"Nodes to be used in cloud functions",type:"data",subCategories:[{name:"",items:["noodl.cloud.request","noodl.cloud.response"]},{name:"Cloud Data",items:["noodl.cloud.aggregate"]}]}];t.nodeIndex={coreNodes:o};const r=[];return n.forEach(s=>{e._constructors[s].metadata.module&&r.push(s)}),r.length&&(t.nodeIndex.moduleNodes=[{name:"",items:r}]),t}function addModuleSettings(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.settings&&o.settings.forEach(function(r){e.ports.push(r)})}}function generateProjectSettings(e,t){const n={dynamicports:[],ports:[]};return addModuleSettings(n,t),n}function NodeModel(e,t){EventSender$2.call(this),this.id=e,this.type=t,this.inputs=[],this.outputs=[],this.children=[],this.parameters={},this.inputPorts={},this.outputPorts={}}NodeModel.prototype=Object.create(EventSender$2.prototype),NodeModel.prototype.setParameter=function(e,t,n){n?(this.stateParameters||(this.stateParameters={}),this.stateParameters[n]||(this.stateParameters[n]={}),t===void 0?delete this.stateParameters[n][e]:this.stateParameters[n][e]=t):t===void 0?delete this.parameters[e]:this.parameters[e]=t,this.emit("parameterUpdated",{name:e,value:t,state:n})},NodeModel.prototype.setParameters=function(e){Object.keys(e).forEach(t=>{this.setParameter(t,e[t])})},NodeModel.prototype.setStateParameters=function(e){this.stateParameters=e},NodeModel.prototype.setStateTransitions=function(e){this.stateTransitions=e},NodeModel.prototype.setStateTransitionParamter=function(e,t,n){this.stateTransitions||(this.stateTransitions={}),t?this.stateTransitions[n][e]=t:delete this.stateTransitions[n][e]},NodeModel.prototype.setDefaultStateTransition=function(e,t){this.defaultStateTransitions||(this.defaultStateTransitions={}),this.defaultStateTransitions[t]=e},NodeModel.prototype.addInputPort=function(e){this.inputPorts[e.name]=e,this.emit("inputPortAdded",e)},NodeModel.prototype.getInputPort=function(e){return this.inputPorts[e]},NodeModel.prototype.getInputPorts=function(){return this.inputPorts},NodeModel.prototype.removeInputPortWithName=function(e){if(this.inputPorts.hasOwnProperty(e)){var t=this.inputPorts[e];delete this.inputPorts[e],this.emit("inputPortRemoved",t)}},NodeModel.prototype.updateInputPortTypes=function(e){var t=!1;for(var n in e)this.inputPorts[n]!==void 0&&(this.inputPorts[n].type=e[n].type,t=!0);t&&this.emit("inputPortTypesUpdated")},NodeModel.prototype.addOutputPort=function(e){this.outputPorts[e.name]=e,this.emit("outputPortAdded",e)},NodeModel.prototype.getOutputPort=function(e){return this.outputPorts[e]},NodeModel.prototype.getOutputPorts=function(){return this.outputPorts},NodeModel.prototype.removeOutputPortWithName=function(e){if(this.outputPorts.hasOwnProperty(e)){var t=this.outputPorts[e];delete this.outputPorts[e],this.emit("outputPortRemoved",t)}},NodeModel.prototype.updateOutputPortTypes=function(e){var t=!1;for(var n in e)this.outputPorts[n]!==void 0&&(this.outputPorts[n].type=e[n].type,t=!0);t&&this.emit("outputPortTypesUpdated")},NodeModel.prototype.addChild=function(e,t){e.parent=this,t===void 0?this.children.push(e):this.children.splice(t,0,e),this.emit("childAdded",e)},NodeModel.prototype.removeChild=function(e){e.parent=void 0;var t=this.children.indexOf(e);this.children.splice(t,1),this.emit("childRemoved",e)},NodeModel.prototype.reset=function(){this.removeAllListeners()},NodeModel.prototype.setVariant=function(e){this.variant=e,this.emit("variantUpdated",e)},NodeModel.createFromExportData=function(e){var t=new NodeModel(e.id,e.type);if(e.parameters&&t.setParameters(e.parameters),e.stateParameters&&t.setStateParameters(e.stateParameters),e.stateTransitions&&t.setStateTransitions(e.stateTransitions),e.defaultStateTransitions)for(const n in e.defaultStateTransitions)t.setDefaultStateTransition(e.defaultStateTransitions[n],n);return e.ports&&e.ports.forEach(function(n){n.plug==="outputs"&&(n.plug="output"),(n.plug==="input"||n.plug==="input/output")&&t.addInputPort(n),(n.plug==="output"||n.plug==="input/output")&&t.addOutputPort(n)}),e.variant&&t.setVariant(e.variant),t};function ComponentModel(e){EventSender$2.call(this),this.name=e,this.nodes=[],this.connections=[],this.roots=[],this.inputPorts={},this.outputPorts={},this.metadata={}}ComponentModel.prototype=Object.create(EventSender$2.prototype),ComponentModel.prototype.addNode=async function(e){e.component=this,this.nodes[e.id]=e,await this.emit("nodeAdded",e)},ComponentModel.prototype.hasNodeWithId=function(e){return this.getNodeWithId(e)!==void 0},ComponentModel.prototype.getNodeWithId=function(e){return this.nodes[e]},ComponentModel.prototype.getAllNodes=function(){return Object.values(this.nodes)},ComponentModel.prototype.getNodesWithType=function(e){var t=[],n=this;return Object.keys(this.nodes).forEach(function(o){var r=n.nodes[o];r.type===e&&t.push(r)}),t},ComponentModel.prototype.addConnection=function(e){if(this.connections.push(e),this.emit("connectionAdded",e),e.targetId){const t=this.getNodeWithId(e.targetId);t&&t.emit("inputConnectionAdded",e)}},ComponentModel.prototype.removeConnection=function(e){const t=this.connections.findIndex(n=>n.sourceId===e.sourceId&&n.sourcePort===e.sourcePort&&n.targetId===e.targetId&&n.targetPort===e.targetPort);if(t===-1){console.log("Connection doesn't exist",e);return}if(this.connections.splice(t,1),this.emit("connectionRemoved",e),e.targetId){const n=this.getNodeWithId(e.targetId);n&&n.emit("inputConnectionRemoved",e)}},ComponentModel.prototype.getConnectionsFromPort=function(e,t){return this.connections.filter(function(n){return n.sourceId===e&&n.sourcePort===t})},ComponentModel.prototype.getConnectionsToPort=function(e,t){return this.connections.filter(function(n){return n.targetId===e&&n.targetPort===t})},ComponentModel.prototype.getConnectionsFrom=function(e){return this.connections.filter(function(t){return t.sourceId===e})},ComponentModel.prototype.getConnectionsTo=function(e){return this.connections.filter(function(t){return t.targetId===e})},ComponentModel.prototype.addRootId=function(e){this.roots.indexOf(e)===-1&&(this.roots.push(e),this.emit("rootAdded",e))},ComponentModel.prototype.removeRootId=function(e){const t=this.roots.indexOf(e);t!==-1&&(this.roots.splice(t,1),this.emit("rootRemoved",e))},ComponentModel.prototype.getRoots=function(){return this.roots},ComponentModel.prototype.removeNodeWithId=async function(e){const t=this.getNodeWithId(e);if(!t)return console.warn("ERROR: Attempted to remove non-existing node with ID:",e),!1;for(;t.children.length>0;){const o=t.children[0];await this.removeNodeWithId(o.id)||t.children.shift()}const n=this.getConnectionsTo(e).concat(this.getConnectionsFrom(e));for(let o=0;o<n.length;o++)this.removeConnection(n[o]);return this.setNodeParent(t,null),this.roots.indexOf(t.id)!==-1&&this.removeRootId(t.id),await this.emit("nodeRemoved",t),t.removeAllListeners(),delete this.nodes[e],await this.emit("nodeWasRemoved",t),!0},ComponentModel.prototype.getAllConnections=function(){return this.connections},ComponentModel.prototype.getInputPorts=function(){return this.inputPorts},ComponentModel.prototype.getOutputPorts=function(){return this.outputPorts},ComponentModel.prototype.addInputPort=function(e){this.inputPorts[e.name]=e,this.emit("inputPortAdded",e)},ComponentModel.prototype.addOutputPort=function(e){this.outputPorts[e.name]=e,this.emit("outputPortAdded",e)},ComponentModel.prototype.removeOutputPortWithName=function(e){if(this.outputPorts.hasOwnProperty(e)){var t=this.outputPorts[e];delete this.outputPorts[e],this.emit("outputPortRemoved",t)}},ComponentModel.prototype.removeInputPortWithName=function(e){if(this.inputPorts.hasOwnProperty(e)){var t=this.inputPorts[e];delete this.inputPorts[e],this.emit("inputPortRemoved",t)}},ComponentModel.prototype.updateInputPortTypes=function(e){var t=!1;for(var n in e)this.inputPorts[n]!==void 0&&(this.inputPorts[n].type=e[n].type,t=!0);t&&this.emit("inputPortTypesUpdated")},ComponentModel.prototype.updateOutputPortTypes=function(e){var t=!1;for(var n in e)this.outputPorts[n]!==void 0&&(this.outputPorts[n].type=e[n].type,t=!0);t&&this.emit("outputPortTypesUpdated")},ComponentModel.prototype.renameInputPortOnNodeWithId=function(e,t,n){var o=this.getConnectionsToPort(e,t);o.forEach(this.removeConnection.bind(this));var r=this.getNodeWithId(e),s={...r.getInputPort(t)};s&&(r.removeInputPortWithName(t),s.name=n,r.addInputPort(s)),o.forEach(function(a){a.targetPort=n}),o.forEach(this.addConnection.bind(this))},ComponentModel.prototype.renameOutputPortOnNodeWithId=function(e,t,n){var o=this.getConnectionsFromPort(e,t);o.forEach(this.removeConnection.bind(this));var r=this.getNodeWithId(e),s={...r.getOutputPort(t)};r.removeOutputPortWithName(t),s.name=n,r.addOutputPort(s),o.forEach(function(a){a.sourcePort=n}),o.forEach(this.addConnection.bind(this))},ComponentModel.prototype.setNodeParent=function(e,t,n){this.roots.indexOf(e.id)!==-1&&this.removeRootId(e.id),e.parent&&(this.emit("nodeParentWillBeRemoved",e),e.parent.removeChild(e)),e.emit("parentUpdated",t),t&&(t.addChild(e,n),this.emit("nodeParentUpdated",e))},ComponentModel.prototype.importEditorNodeData=async function(e,t,n){var o=NodeModel.createFromExportData(e);if(await this.addNode(o),t&&this.setNodeParent(o,this.getNodeWithId(t),n),e.children)for(let r=0;r<e.children.length;r++){const s=e.children[r];await this.importEditorNodeData(s,o.id,r)}},ComponentModel.prototype.reset=async function(){for(;this.roots.length;)await this.removeNodeWithId(this.roots[0]);for(const e of this.nodes)this.hasNodeWithId(e)&&await this.removeNodeWithId(e);if(this.nodes.length>0)throw new Error("Not all nodes were removed during a reset");if(this.connections.length>0)throw new Error("Not all connections were removed during a reset")},ComponentModel.prototype.rename=function(e){var t=this.name;this.name=e,this.emit("renamed",{oldName:t,newName:e})},ComponentModel.prototype.setMetadata=function(e,t){this.metadata[e]=t},ComponentModel.prototype.getMetadata=function(e){return e?this.metadata[e]:this.metadata},ComponentModel.createFromExportData=async function(e){var t=new ComponentModel(e.name);if(e.metadata)for(const n in e.metadata)t.setMetadata(n,e.metadata[n]);if(e.ports&&e.ports.forEach(function(n){(n.plug==="input"||n.plug==="input/output")&&t.addInputPort(n),(n.plug==="output"||n.plug==="input/output")&&t.addOutputPort(n)}),e.nodes)for(const n of e.nodes)await t.importEditorNodeData(n);return e.connections&&e.connections.forEach(n=>t.addConnection(n)),e.roots&&e.roots.forEach(n=>t.addRootId(n)),t};function GraphModel(){EventSender$2.call(this),this.components={},this.settings={},this.metadata={}}GraphModel.prototype=Object.create(EventSender$2.prototype),GraphModel.prototype.importComponentFromEditorData=async function(e){var t=await ComponentModel.createFromExportData(e);this.addComponent(t)},GraphModel.prototype.getBundleContainingComponent=function(e){return this.componentToBundleMap.get(e)},GraphModel.prototype.getBundlesContainingSheet=function(e){const t=new Set;for(const n of this.componentToBundleMap.keys()){const o=n.indexOf("/#")!==0;(o&&e==="Default"||!o&&n.indexOf("/#"+e)===0)&&t.add(this.componentToBundleMap.get(n))}return Array.from(t)},GraphModel.prototype.getBundleDependencies=function(e){const t=new Set,n=o=>{const r=this.componentIndex[o];for(const s of r.dependencies)t.has(s)||(t.add(s),n(s))};return n(e),Array.from(t)},GraphModel.prototype.importEditorData=async function(e){this.componentIndex=e.componentIndex,this.routerIndex=e.routerIndex,this.componentToBundleMap=new Map;for(const t in e.componentIndex){const n=e.componentIndex[t];for(const o of n.components)this.componentToBundleMap.set(o,t)}this.variants=e.variants||[],e.settings&&this.setSettings(e.settings),e.metadata&&this.setAllMetaData(e.metadata);for(const t of e.components)await this.importComponentFromEditorData(t);this.setRootComponentName(e.rootComponent)},GraphModel.prototype.setRootComponentName=function(e){this.rootComponent=e,this.emit("rootComponentNameUpdated",e)},GraphModel.prototype.getNodesWithType=function(e){for(var t=[],n=Object.keys(this.components),o=0;o<n.length;o++){var r=this.components[n[o]];t=t.concat(r.getNodesWithType(e))}return t},GraphModel.prototype.getComponentWithName=function(e){return this.components[e]},GraphModel.prototype.hasComponentWithName=function(e){return!!this.components[e]},GraphModel.prototype.getAllComponents=function(){return Object.keys(this.components).map(e=>this.components[e])},GraphModel.prototype.getAllNodes=function(){for(var e=[],t=Object.keys(this.components),n=0;n<t.length;n++){var o=this.components[t[n]];e=e.concat(o.getAllNodes())}return e},GraphModel.prototype.addComponent=function(e){this.components[e.name]=e,this.getNodesWithType(e.name).forEach(this._addComponentPorts.bind(this)),e.getAllNodes().forEach(this._onNodeAdded.bind(this)),e.on("nodeAdded",this._onNodeAdded.bind(this),this),e.on("nodeRemoved",this._onNodeRemoved.bind(this),this),e.on("nodeWasRemoved",this._onNodeWasRemoved.bind(this),this),this.emit("componentAdded",e)},GraphModel.prototype.removeComponentWithName=async function(e){if(this.components.hasOwnProperty(e)===!1){console.error("GraphModel: Component with name "+e+" not in graph");return}var t=this.components[e];await t.reset(),t.removeAllListeners(),delete this.components[t.name],this.emit("componentRemoved",t)},GraphModel.prototype.renameComponent=function(e,t){if(this.components.hasOwnProperty(e)===!1){console.error("GraphModel: Component with name "+e+" not in graph");return}this.getNodesWithType(e).forEach(function(o){o.type=t});var n=this.components[e];n.rename(t),delete this.components[e],this.components[t]=n,this.emit("componentRenamed",n)},GraphModel.prototype._addComponentPorts=function(e){if(this.components.hasOwnProperty(e.type)){var t=this.components[e.type];const n=t.getInputPorts(),o=t.getOutputPorts();Object.keys(n).forEach(r=>{e.addInputPort(n[r])}),Object.keys(o).forEach(r=>{e.addOutputPort(o[r])})}},GraphModel.prototype._onNodeAdded=function(e){this._addComponentPorts(e),this.emit("nodeAdded",e),this.emit("nodeAdded."+e.type,e)},GraphModel.prototype._onNodeRemoved=function(e){this.emit("nodeRemoved",e),this.emit("nodeRemoved."+e.type,e)},GraphModel.prototype._onNodeWasRemoved=function(e){this.emit("nodeWasRemoved",e),this.emit("nodeWasRemoved."+e.type,e)},GraphModel.prototype.reset=async function(){for(const e of Object.keys(this.components))await this.removeComponentWithName(e);this.setSettings({})},GraphModel.prototype.isEmpty=function(){return Object.keys(this.components).length===0},GraphModel.prototype.setSettings=function(e){this.settings=e,this.emit("projectSettingsChanged",e)},GraphModel.prototype.getSettings=function(){return this.settings},GraphModel.prototype.setAllMetaData=function(e){for(const t in e)this.setMetaData(t,e[t])},GraphModel.prototype.setMetaData=function(e,t){this.metadata[e]&&JSON.stringify(this.metadata[e])===JSON.stringify(t)||(this.metadata[e]=t,this.emit("metadataChanged",{key:e,data:t}),this.emit("metadataChanged."+e,t))},GraphModel.prototype.getMetaData=function(e){return e?this.metadata[e]:this.metadata},GraphModel.prototype.getVariants=function(){return this.variants||[]},GraphModel.prototype.getVariant=function(e,t){return this.variants.find(n=>n.name===t&&n.typename===e)},GraphModel.prototype.updateVariant=function(e){const t=this.variants.findIndex(n=>n.name===e.name&&n.typename===e.typename);t!==-1&&this.variants.splice(t,1),this.variants.push(e),this.emit("variantUpdated",e)},GraphModel.prototype.updateVariantParameter=function(e,t,n,o,r){const s=this.getVariant(t,e);if(!s){console.log("updateVariantParameter: can't find variant",e,t);return}r?(s.stateParameters.hasOwnProperty(r)||(s.stateParameters[r]={}),o===void 0?delete s.stateParameters[r][n]:s.stateParameters[r][n]=o):o===void 0?delete s.parameters[n]:s.parameters[n]=o,this.emit("variantUpdated",s)},GraphModel.prototype.updateVariantDefaultStateTransition=function(e,t,n,o){const r=this.getVariant(t,e);r&&(r.defaultStateTransitions[o]=n,this.emit("variantUpdated",r))},GraphModel.prototype.updateVariantStateTransition=function(e){const{variantTypeName:t,variantName:n,state:o,parameterName:r,curve:s}=e,a=this.getVariant(t,n);a&&(a.stateTransitions[o]||(a.stateTransitions[o]={}),a.stateTransitions[o][r]=s)},GraphModel.prototype.deleteVariant=function(e,t){const n=this.variants.findIndex(o=>o.name===t&&o.typename===e);n!==-1&&this.variants.splice(n,1)};function createSetter(e){var t=!1;return function(n){n=!!n,n&&t===!1&&e.valueChangedToTrue.call(this),t=n}}const EdgeTriggeredInput=Object.freeze(Object.defineProperty({__proto__:null,createSetter},Symbol.toStringTag,{value:"Module"}));function createNodeConstructor(e){const t=class extends Node{constructor(n,o){super(n,o)}getInspectInfo(){return e.getInspectInfo?.()??void 0}nodeScopeDidInitialize(){return e.nodeScopeDidInitialize?.()??void 0}};return e.prototypeExtensions&&Object.defineProperties(t.prototype,e.prototypeExtensions),Object.defineProperty(t.prototype,"name",{value:e.name}),t}function registerInput(e,t,n,o){if(e.hasOwnProperty(n))throw new Error("Input property "+n+" already registered");!o.set&&!o.valueChangedToTrue&&(o.set=()=>{}),o.set&&(e[n]={set:o.set},["color","textStyle","array"].forEach(r=>{o.type&&(o.type===r||o.type.name===r)&&(e[n].type=r)})),o.setUnitType&&(e[n].setUnitType=o.setUnitType),t.inputs[n]={displayName:o.displayName,editorName:o.editorName,group:o.group,type:o.type,default:o.default,index:o.index,exportToEditor:o.hasOwnProperty("exportToEditor")?o.exportToEditor:!0,inputPriority:o.inputPriority||0,tooltip:o.tooltip,tab:o.tab,popout:o.popout,allowVisualStates:o.allowVisualStates,nodeDoubleClickAction:o.nodeDoubleClickAction},o.valueChangedToTrue&&(t.inputs[n].type={name:"signal",allowConnectionsOnly:!0})}function registerInputs(e,t,n){Object.keys(n).forEach(function(o){registerInput(e,t,o,n[o])})}function registerNumberedInputs(e,t){for(const n of Object.keys(t))registerNumberedInput(e,n,t[n])}function registerNumberedInput(e,t,n){const o=e.registerInputIfNeeded;e.registerInputIfNeeded=function(r){if(o&&o.call(e,r),e.hasInput(r)||!r.startsWith(t))return;const s=Number(r.slice(t.length+1));e.registerInput(r,{type:n.type,set:n.createSetter.call(e,s)})}}function registerOutputsMetadata(e,t){Object.keys(t).forEach(function(n){var o=t[n];e.outputs[n]={displayName:o.displayName,editorName:o.editorName,group:o.group,type:o.type,index:o.index,exportToEditor:o.hasOwnProperty("exportToEditor")?o.exportToEditor:!0}})}function initializeDefaultValues(e,t){Object.keys(t).forEach(n=>{const o=t[n].default;o!==void 0&&(t[n].type.defaultUnit?e[n]={unit:t[n].type.defaultUnit,value:o}:e[n]=o)})}function defineNode(e){if(!e.category)throw new Error("Node must have a category");if(!e.name)throw new Error("Node must have a name");const t={inputs:{},outputs:{},category:e.category,dynamicports:e.dynamicports,exportDynamicPorts:e.exportDynamicPorts,useVariants:e.useVariants,allowChildren:e.allowChildren,allowChildrenWithCategory:e.allowChildrenWithCategory,singleton:e.singleton,connectionPanel:e.connectionPanel,allowAsChild:e.allowAsChild,visualStates:e.visualStates,panels:e.panels,color:e.color,usePortAsLabel:e.usePortAsLabel,portLabelTruncationMode:e.portLabelTruncationMode,name:e.name,displayNodeName:e.displayNodeName||e.displayName,deprecated:e.deprecated,haveComponentPorts:e.haveComponentPorts,version:e.version,module:e.module,docs:e.docs,allowAsExportRoot:e.allowAsExportRoot,nodeDoubleClickAction:e.nodeDoubleClickAction,searchTags:e.searchTags};e._internal=e._internal||{},e.prototypeExtensions=e.methods||e.prototypeExtensions||{},e.inputs=e.inputs||{},e.outputs=e.outputs||{},e.initialize=e.initialize||function(){};let n={};registerInputs(n,t,e.inputs),registerOutputsMetadata(t,e.outputs),Object.keys(e.prototypeExtensions).forEach(function(s){e.prototypeExtensions[s].value||(e.prototypeExtensions[s]={value:e.prototypeExtensions[s]})});const o=createNodeConstructor({name:e.name,getInspectInfo:e.getInspectInfo,nodeScopeDidInitialize:e.nodeScopeDidInitialize,prototypeExtensions:e.prototypeExtensions}),r=function(s,a,l){const u=new o(s,a);return u._inputs=Object.create(n),Object.keys(e.inputs).forEach(function(d){var h=e.inputs[d];h.valueChangedToTrue&&(u._inputs[d]={set:createSetter({valueChangedToTrue:h.valueChangedToTrue})})}),Object.keys(e.outputs).forEach(function(d){var h=e.outputs[d];h.type==="signal"?u.registerOutput(d,{getter(){}}):u.registerOutput(d,h)}),e.numberedInputs&&registerNumberedInputs(u,e.numberedInputs),u.nodeScope=l,initializeDefaultValues(u._inputValues,t.inputs),e.initialize.call(u),u};return r.metadata=t,e.numberedInputs&&registerSetupFunctionForNumberedInputs(r,e.name,e.numberedInputs),r}function registerSetupFunctionForNumberedInputs(e,t,n){const o=Object.keys(n);o.length&&(e.setupNumberedInputDynamicPorts=function(r,s){const a=r.editorConnection;if(!a||!a.isRunningLocally())return;function l(d,h,f){const g=d.component.getConnectionsTo(d.id).map(A=>A.targetPort),b=Object.keys(d.parameters).concat(g).filter(A=>A.startsWith(h+" ")),_=(b.length?1+Math.max(...b.map(A=>Number(A.slice(h.length+1)))):0)+1,T=[];for(let A=0;A<_;A++){const v={name:h+" "+A,displayName:(f.displayPrefix||h)+" "+A,type:f.type,plug:"input",group:f.group};f.hasOwnProperty("index")&&(v.index=f.index+A),T.push(v)}return T}function u(d){const h=o.map(f=>l(d,f,n[f])).flat();a.sendDynamicPorts(d.id,h)}s.on("nodeAdded."+t,d=>{u(d),d.on("parameterUpdated",()=>{u(d)}),d.on("inputConnectionAdded",()=>{u(d)}),d.on("inputConnectionRemoved",()=>{u(d)})})})}function extend$4(e,t){for(var n in t)if(n==="initialize"&&e.initialize){var o=e.initialize;e.initialize=function(){o.call(this),t.initialize.call(this)}}else t[n]&&t[n].constructor===Object?e[n]=extend$4(e[n]||{},t[n]):t[n]&&t[n].constructor===Array&&e[n]&&e[n].constructor==Array?e[n]=e[n].concat(t[n]):e[n]=t[n];return e}function difference$1(e,t){const n=new Set(t);return e.filter(o=>!n.has(o))}async function handleEvent(e,t,n){function o(l,u){var d={},h={};u.forEach(function(v){v&&v.plug==="outputs"&&(v.plug="output"),(v.plug==="input"||v.plug==="input/output")&&(d[v.name]=v),(v.plug==="output"||v.plug==="input/output")&&(h[v.name]=v)});var f=Object.keys(l.getInputPorts()),g=difference$1(f,Object.keys(d)),b=difference$1(Object.keys(d),f);l.updateInputPortTypes(d),g.forEach(l.removeInputPortWithName.bind(l)),b.forEach(function(v){l.addInputPort(d[v]),l.parameters&&l.parameters.hasOwnProperty(v)&&r(e.rootComponent.nodeScope,l,v,l.parameters[v])}),l.updateOutputPortTypes(h);var _=Object.keys(l.getOutputPorts()),T=difference$1(_,Object.keys(h)),A=difference$1(Object.keys(h),_);T.forEach(l.removeOutputPortWithName.bind(l)),A.forEach(function(v){l.addOutputPort(h[v])})}function r(l,u,d,h){var f=l.getNodesWithIdRecursive(u.id);f.forEach(function(g){g.queueInput(d,h)})}var s;if(!(n.componentName&&(s=t.getComponentWithName(n.componentName),!s))){n.port&&n.port.plug==="outputs"&&(n.port.plug="output");var a={nodeAdded(l){s.importEditorNodeData(l.model,l.parentId,l.childIndex)},nodeRemoved:async function(l){s.hasNodeWithId(l.model.id)&&await s.removeNodeWithId(l.model.id)},connectionAdded(l){s.addConnection(l.model)},connectionRemoved(l){s.removeConnection(l.model);var u=s.getNodeWithId(l.model.targetId);if(s.getConnectionsToPort(u.id,l.model.targetId).length===0){var d=u.parameters[l.model.targetPort];d===void 0&&(d=e.getDefaultValueForInput(u.type,l.model.targetPort)),r(e.rootComponent.nodeScope,u,l.model.targetPort,d)}},parameterChanged(l){const u=s.getNodeWithId(l.nodeId);if(u===void 0){console.log("parameterChanged: Unknown node id",l);return}if(l.parameters){const d=new Set(Object.keys(l.parameters).concat(Object.keys(l.oldParameters)));for(const h of d)u.setParameter(h,l.parameters[h])}l.parameterName&&u.setParameter(l.parameterName,l.parameterValue,l.state)},nodeAttached(l){s.setNodeParent(s.getNodeWithId(l.nodeId),s.getNodeWithId(l.parentId),l.childIndex)},nodeDetached(l){s.setNodeParent(s.getNodeWithId(l.nodeId),null),s.addRootId(l.nodeId)},componentAdded(l){t.importComponentFromEditorData(l.model)},componentRemoved:async function(l){await t.removeComponentWithName(l.componentName)},rootAdded(l){s.addRootId(l.nodeId)},portAdded(l){var u=s.getNodeWithId(l.nodeId);(l.port.plug==="input"||l.port.plug==="input/output")&&(u.addInputPort(l.port),u.parameters.hasOwnProperty(l.port)&&r(e.rootComponent.nodeScope,u,l.port,u.parameters[l.port])),(l.port.plug==="output"||l.port.plug==="input/output")&&u.addOutputPort(l.port)},portRemoved(l){var u=s.getNodeWithId(l.nodeId);(l.port.plug==="input"||l.port.plug==="input/output")&&u.removeInputPortWithName(l.port.name),(l.port.plug==="output"||l.port.plug==="input/output")&&u.removeOutputPortWithName(l.port.name)},nodePortRenamed(l){(l.port.plug==="input"||l.port.plug==="input/output")&&s.renameInputPortOnNodeWithId(l.nodeId,l.oldName,l.port.name),(l.port.plug==="output"||l.port.plug==="input/output")&&s.renameOutputPortOnNodeWithId(l.nodeId,l.oldName,l.port.name);var u=s.getNodeWithId(l.nodeId);u.type==="Component Inputs"?(s.addInputPort(l.port),t.getNodesWithType(s.name).forEach(function(d){d.component.renameInputPortOnNodeWithId(d.id,l.oldName,l.port.name)}),s.removeInputPortWithName(l.oldName)):u.type==="Component Outputs"&&(s.addOutputPort(l.port),t.getNodesWithType(s.name).forEach(function(d){d.component.renameOutputPortOnNodeWithId(d.id,l.oldName,l.port.name)}),s.removeOutputPortWithName(l.oldName))},componentPortsUpdated(l){o(s,l.ports)},instancePortsChanged(l){if(s.hasNodeWithId(l.nodeId)){var u=s.getNodeWithId(l.nodeId);o(u,l.ports)}},componentRenamed(l){t.renameComponent(l.oldName,l.newName)},settingsChanged(l){t.setSettings(l.settings)},metadataChanged(l){t.setMetaData(l.key,l.data)},componentMetadataChanged(l){const u=t.getComponentWithName(l.componentName);u&&u.setMetadata(l.key,l.data)},variantParametersChanged(l){if(l.variant)t.updateVariant(l.variant);else if(t.updateVariantParameter(l.variantName,l.variantTypeName,l.parameterName,l.parameterValue,l.state),l.parameterValue===void 0){const u=t.getVariant(l.variantTypeName,l.variantName);e.rootComponent.nodeScope.getAllNodesWithVariantRecursive(u).forEach(d=>{d.queueInput(l.parameterName,d.getParameter(l.parameterName))})}},variantDeleted(l){t.deleteVariant(l.variantTypeName,l.variantName)},variantChanged(l){const u=s.getNodeWithId(l.nodeId),d=t.getVariant(u.type,l.variantName);u.setVariant(d)},variantRenamed(l){const u=t.getVariant(l.variantTypeName,l.oldVariantName);u&&(u.name=u.variantName)},defaultStateTransitionChanged(l){s.getNodeWithId(l.nodeId).setDefaultStateTransition(l.curve,l.state)},stateTransitionsChanged(l){const u=s.getNodeWithId(l.nodeId);l.parameterName&&u.setStateTransitionParamter(l.parameterName,l.curve,l.state)},variantDefaultStateTransitionChanged(l){t.updateVariantDefaultStateTransition(l.variantName,l.variantTypeName,l.curve,l.state)},variantStateTransitionsChanged(l){t.updateVariantStateTransition(l)},routerIndexChanged(l){t.routerIndex=l.data}};a.hasOwnProperty(n.type)?(await a[n.type](n),e.scheduleUpdate()):console.log("Unknown event",n)}}async function asyncPool(e,t,n){const o=[],r=[];for(const s of t){const a=Promise.resolve().then(()=>n(s,t));if(o.push(a),e<=t.length){const l=a.then(()=>r.splice(r.indexOf(l),1));r.push(l),r.length>=e&&await Promise.race(r)}}return Promise.all(o)}const ComponentInputs={node:{name:"Component Inputs",shortDesc:"This node is used to define the inputs of a component.",docs:"https://docs.noodl.net/nodes/component-utilities/component-inputs",panels:[{name:"PortEditor",context:["select","connectFrom"],title:"Inputs",plug:"output",type:{name:"*"},canArrangeInGroups:!0},{name:"PropertyEditor",hidden:!0}],getInspectInfo(){return{type:"value",value:this.nodeScope.componentOwner._internal.inputValues}},color:"component",haveComponentPorts:!0,category:"Component Utilities",methods:{registerOutputIfNeeded(e){this.hasOutput(e)||this.registerOutput(e,{getter(){return this.nodeScope.componentOwner._internal.inputValues[e]}})},_updateDependencies(){this.nodeScope.componentOwner.update()}}}},ComponentOutputs={node:{category:"Component Utilities",name:"Component Outputs",shortDesc:"This node is used to define the outputs of a component.",docs:"https://docs.noodl.net/nodes/component-utilities/component-outputs",panels:[{name:"PortEditor",context:["select","connectTo"],title:"Outputs",plug:"input",type:{name:"*"},canArrangeInGroups:!0},{name:"PropertyEditor",hidden:!0}],color:"component",haveComponentPorts:!0,prototypeExtensions:{registerInputIfNeeded(e){this.hasInput(e)||this.registerInput(e,{set(t){this.nodeScope.componentOwner.setOutputFromComponentOutput(e,t)}})}}}};function Model(e,t){this.id=e,this.data=t}const models=Model._models={},proxies={},_modelProxyHandler={get(e,t,n){return typeof e[t]=="function"?e[t].bind(e):t in e?Reflect.get(e,t,n):e.get(t)},set(e,t,n){if(t==="_class")e._class=n;else{if(t==="id")return console.log(`Noodl.Object warning: id is readonly (Id is ${e.id}, trying to set to ${n})`),!0;e.set(t,n)}return!0},ownKeys(e){return Reflect.ownKeys(e.data)},getOwnPropertyDescriptor(e,t){return Object.getOwnPropertyDescriptor(e.data,t)}};Model.get=function(e){return e===void 0&&(e=Model.guid()),models[e]||(models[e]=new Model(e,{}),proxies[e]=new Proxy(models[e],_modelProxyHandler)),proxies[e]},Model.create=function(e){var t=e||{},n=Model.get(t.id);for(var o in t)o!=="id"&&n.set(o,t[o]);return n},Model.exists=function(e){return models[e]!==void 0},Model.instanceOf=function(e){return e instanceof Model||e.target instanceof Model};function _randomString(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let o=0;o<e;++o)n+=t[Math.floor((1+Math.random())*65536)%t.length];return n}Model.guid=function e(){return _randomString(10)},Model.prototype.on=function(e,t){this.listeners||(this.listeners={}),this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)},Model.prototype.off=function(e,t){if(this.listeners&&this.listeners[e]){var n=this.listeners[e].indexOf(t);n!==-1&&this.listeners[e].splice(n,1)}},Model.prototype.notify=function(e,t){if(this.listeners&&this.listeners[e])for(var n=this.listeners[e].slice(),o=0;o<n.length;o++)n[o](t)},Model.prototype.setAll=function(e){for(var t in e)if(t!=="id"&&this.data[t]!==e[t]){var n=this.data[t];this.data[t]=e[t],this.notify("change",{name:t,value:e[t],old:n})}},Model.prototype.fill=function(e=null){for(const t in this.data){if(t==="id")continue;const n=this.data[t];this.data[t]=e,this.notify("change",{name:t,value:this.data[t],old:n})}},Model.prototype.set=function(e,t,n){if(n&&n.resolve&&e.indexOf(".")!==-1){const s=e.split(".");let a=this;for(let l=0;l<s.length-1;l++){const u=a.get(s[l]);if(Model.instanceOf(u))a=u;else return}a.set(s[s.length-1],t);return}const o=n&&n.forceChange,r=this.data[e];this.data[e]=t,(o||r!==t)&&(!n||!n.silent)&&this.notify("change",{name:e,value:t,old:r})},Model.prototype.getId=function(){return this.id},Model.prototype.get=function(e,t){if(t&&t.resolve&&e.indexOf(".")!==-1){const n=e.split(".");let o=this;for(let r=0;r<n.length-1;r++){const s=o.get(n[r]);if(Model.instanceOf(s))o=s;else return}return o.get(n[n.length-1])}return this.data[e]},Model.prototype.toJSON=function(){return Object.assign({},this.data,{id:this.id})},Model.Scope=function(){this.models={},this.proxies={}},Model.Scope.prototype.get=function(e){return e===void 0&&(e=Model.guid()),this.models[e]||(this.models[e]=new Model(e,{}),this.proxies[e]=new Proxy(this.models[e],_modelProxyHandler)),this.proxies[e]},Model.Scope.prototype.create=function(e){var t=e||{},n=this.get(t.id);for(var o in t)o!=="id"&&n.set(o,t[o]);return n},Model.Scope.prototype.exists=function(e){return this.models[e]!==void 0},Model.Scope.prototype.instanceOf=function(e){return e instanceof Model||e.target instanceof Model},Model.Scope.prototype.guid=function e(){return _randomString(10)},Model.Scope.prototype.reset=function(){this.models={},this.proxies={},delete this._cloudStore};function sendSignalOnInput(e,t){e.queueInput(t,!0),e.queueInput(t,!1)}const RunTasksDefinition={name:"RunTasks",displayNodeName:"Run Tasks",docs:"https://docs.noodl.net/nodes/data/run-tasks",color:"data",category:"Data",initialize(){this._internal.queuedOperations=[],this._internal.state="idle",this._internal.maxRunningTasks=10,this._internal.activeTasks=new Map},inputs:{items:{group:"Data",displayName:"Items",type:"array",set(e){e&&e!==this._internal.items&&(this._internal.items=e)}},stopOnFailure:{group:"General",displayName:"Stop On Failure",type:"boolean",default:!1,set(e){this._internal.stopOnFailure=e}},maxRunningTasks:{group:"General",displayName:"Max Running Tasks",type:"number",default:10,set(e){this._internal.maxRunningTasks=e}},taskTemplate:{type:"component",displayName:"Template",group:"General",set(e){this._internal.template=e}},run:{group:"General",displayName:"Do",type:"signal",valueChangedToTrue(){this.scheduleRun()}},abort:{group:"General",displayName:"Abort",type:"signal",valueChangedToTrue(){this.scheduleAbort()}}},outputs:{success:{type:"signal",group:"Events",displayName:"Success"},failure:{type:"signal",group:"Events",displayName:"Failure"},done:{type:"signal",group:"Events",displayName:"Done"},aborted:{type:"signal",group:"Events",displayName:"Aborted"}},methods:{scheduleRun(){var e=this._internal;e.hasScheduledRun||(e.hasScheduledRun=!0,this.scheduleAfterInputsHaveUpdated(()=>{this._queueOperation(()=>{e.hasScheduledRun=!1,this.run()})}))},scheduleAbort(){var e=this._internal;e.hasScheduledAbort||(e.hasScheduledAbort=!0,this.scheduleAfterInputsHaveUpdated(()=>{this._queueOperation(()=>{e.hasScheduledAbort=!1,this.abort()})}))},async createTaskComponent(e){const t=this._internal,n=(this.nodeScope.modelScope||Model).create(e);var o=await this.nodeScope.createNode(t.template,guid$1(),{_forEachModel:n,_forEachNode:this});const r=o.isInputConnected.bind(o);o.isInputConnected=a=>a==="Do"?!0:r(a),o.hasInput("Id")&&o.setInputValue("Id",n.getId()),o.hasInput("id")&&o.setInputValue("id",n.getId());for(var s in o._inputs)n.data[s]!==void 0&&o.setInputValue(s,n.data[s]);return o._internal.creatorCallbacks={onOutputChanged:(a,l,u)=>{(u===!1||u===void 0)&&l===!0&&this.itemOutputSignalTriggered(a,n,o)}},o},async startTask(e){const t=this._internal;try{const n=await this.createTaskComponent(e);t.runningTasks++,sendSignalOnInput(n,"Do"),t.activeTasks.set(n.id,n)}catch(n){console.log(n)}},async run(){const e=this._internal;if(this.context.editorConnection&&(e.state!=="idle"?this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks",{message:"Cannot start when not in idle mode"}):e.template?e.items?this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks"):this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks",{message:"No items array provided."}):this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks",{message:"No task template specified."})),e.state==="idle"&&e.template&&e.items){e.state="running",e.numTasks=e.items.length,e.failedTasks=0,e.completedTasks=0,e.queuedTasks=[].concat(e.items),e.runningTasks=0,e.items.length===0&&(this.sendSignalOnOutput("success"),e.state="idle");for(let t=0;t<Math.min(e.maxRunningTasks,e.queuedTasks.length);t++){const n=e.queuedTasks.shift();if(!n)break;this.startTask(n)}}},abort(){const e=this._internal;e.state="aborted"},itemOutputSignalTriggered(e,t,n){const o=this._internal;if(o.state==="idle")return;const r=()=>{if(o.state==="aborted"){this.sendSignalOnOutput("aborted"),o.state="idle";return}if(o.completedTasks===o.numTasks)o.failedTasks===0?this.sendSignalOnOutput("success"):this.sendSignalOnOutput("failure"),this.sendSignalOnOutput("done"),o.state="idle";else if(o.stopOnFailure)if(o.failedTasks===0){o.runningTasks++;const s=o.queuedTasks.shift();s&&this.startTask(s)}else this.sendSignalOnOutput("failure"),this.sendSignalOnOutput("aborted");else{o.runningTasks++;const s=o.queuedTasks.shift();s&&this.startTask(s)}};e==="Success"?(o.completedTasks++,o.runningTasks--,r()):e==="Failure"&&(o.completedTasks++,o.failedTasks++,o.runningTasks--,r()),o.activeTasks.delete(n.id),this.nodeScope.deleteNode(n)},_queueOperation(e){this._internal.queuedOperations.push(e),this._runQueueOperations()},async _runQueueOperations(){if(!this.runningOperations){for(this.runningOperations=!0;this._internal.queuedOperations.length;)await this._internal.queuedOperations.shift()();this.runningOperations=!1}}},_deleteAllTasks(){for(const e of this._internal.activeTasks)this.nodeScope.deleteNode(e);this._internal.activeTasks.clear()},_onNodeDeleted(){Node.prototype._onNodeDeleted.call(this),this._deleteAllTasks()}},RunTasks={node:RunTasksDefinition},defaultRequestScript=`//Add custom code to setup the request object before the request
1
+ (function(React,ReactDOM){"use strict";function _interopNamespaceDefault(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}function _mergeNamespaces(e,t){for(var n=0;n<t.length;n++){const o=t[n];if(typeof o!="string"&&!Array.isArray(o)){for(const r in o)if(r!=="default"&&!(r in e)){const s=Object.getOwnPropertyDescriptor(o,r);s&&Object.defineProperty(e,r,s.get?s:{enumerable:!0,get:()=>o[r]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}const React__namespace=_interopNamespaceDefault(React);class CloudFile{constructor({name:t,url:n}){this.name=t,this.url=n}getUrl(){return this.url}getName(){return this.name}toString(){return this.url}}var R=typeof Reflect=="object"?Reflect:null,ReflectApply=R&&typeof R.apply=="function"?R.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},ReflectOwnKeys;R&&typeof R.ownKeys=="function"?ReflectOwnKeys=R.ownKeys:Object.getOwnPropertySymbols?ReflectOwnKeys=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ReflectOwnKeys=function(e){return Object.getOwnPropertyNames(e)};function ProcessEmitWarning(e){console&&console.warn&&console.warn(e)}var NumberIsNaN=Number.isNaN||function(e){return e!==e};function EventEmitter$2(){EventEmitter$2.init.call(this)}EventEmitter$2.EventEmitter=EventEmitter$2,EventEmitter$2.prototype._events=void 0,EventEmitter$2.prototype._eventsCount=0,EventEmitter$2.prototype._maxListeners=void 0;var defaultMaxListeners=10;function checkListener(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(EventEmitter$2,"defaultMaxListeners",{enumerable:!0,get(){return defaultMaxListeners},set(e){if(typeof e!="number"||e<0||NumberIsNaN(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");defaultMaxListeners=e}}),EventEmitter$2.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},EventEmitter$2.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||NumberIsNaN(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function _getMaxListeners(e){return e._maxListeners===void 0?EventEmitter$2.defaultMaxListeners:e._maxListeners}EventEmitter$2.prototype.getMaxListeners=function(){return _getMaxListeners(this)},EventEmitter$2.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var o=e==="error",r=this._events;if(r!==void 0)o=o&&r.error===void 0;else if(!o)return!1;if(o){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=r[e];if(l===void 0)return!1;if(typeof l=="function")ReflectApply(l,this,t);else for(var u=l.length,d=arrayClone(l,u),n=0;n<u;++n)ReflectApply(d[n],this,t);return!0};function _addListener(e,t,n,o){var r,s,a;if(checkListener(n),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),a=s[t]),a===void 0)a=s[t]=n,++e._eventsCount;else if(typeof a=="function"?a=s[t]=o?[n,a]:[a,n]:o?a.unshift(n):a.push(n),r=_getMaxListeners(e),r>0&&a.length>r&&!a.warned){a.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=a.length,ProcessEmitWarning(l)}return e}EventEmitter$2.prototype.addListener=function(e,t){return _addListener(this,e,t,!1)},EventEmitter$2.prototype.on=EventEmitter$2.prototype.addListener,EventEmitter$2.prototype.prependListener=function(e,t){return _addListener(this,e,t,!0)};function onceWrapper(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function _onceWrap(e,t,n){var o={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=onceWrapper.bind(o);return r.listener=n,o.wrapFn=r,r}EventEmitter$2.prototype.once=function(e,t){return checkListener(t),this.on(e,_onceWrap(this,e,t)),this},EventEmitter$2.prototype.prependOnceListener=function(e,t){return checkListener(t),this.prependListener(e,_onceWrap(this,e,t)),this},EventEmitter$2.prototype.removeListener=function(e,t){var n,o,r,s,a;if(checkListener(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){a=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():spliceOne(n,r),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this},EventEmitter$2.prototype.off=EventEmitter$2.prototype.removeListener,EventEmitter$2.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var r=Object.keys(n),s;for(o=0;o<r.length;++o)s=r[o],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(o=t.length-1;o>=0;o--)this.removeListener(e,t[o]);return this};function _listeners(e,t,n){var o=e._events;if(o===void 0)return[];var r=o[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?unwrapListeners(r):arrayClone(r,r.length)}EventEmitter$2.prototype.listeners=function(e){return _listeners(this,e,!0)},EventEmitter$2.prototype.rawListeners=function(e){return _listeners(this,e,!1)},EventEmitter$2.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):listenerCount.call(e,t)},EventEmitter$2.prototype.listenerCount=listenerCount;function listenerCount(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}EventEmitter$2.prototype.eventNames=function(){return this._eventsCount>0?ReflectOwnKeys(this._events):[]};function arrayClone(e,t){for(var n=new Array(t),o=0;o<t;++o)n[o]=e[o];return n}function spliceOne(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function unwrapListeners(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function NodeRegister(e){this._constructors={},this.context=e}NodeRegister.prototype.register=function(e){var t=e.metadata.name;this._constructors[t]=e},NodeRegister.prototype.createNode=function(e,t,n){if(this._constructors.hasOwnProperty(e)===!1)throw new Error("Unknown node type with name "+e);return this._constructors[e](this.context,t,n)},NodeRegister.prototype.getNodeMetadata=function(e){if(this._constructors.hasOwnProperty(e)===!1)throw new Error("Unknown node type with name "+e);return this._constructors[e].metadata},NodeRegister.prototype.hasNode=function(e){return this._constructors.hasOwnProperty(e)},NodeRegister.prototype.getInputType=function(e,t){const n=this.getNodeMetadata(e);return n.inputs[t]&&n.inputs[t].type};function Timer$2(e,t){this.duration=t.duration||0,this._isRunning=!1,this._hasCalledOnStart=!1,this.scheduler=e,this.repeatCount=1,this.delay=0;for(var n in t)this[n]=t[n]}Timer$2.prototype.start=function(){return this._isRunning&&this.stop(),this.scheduler.scheduleTimer(this),this},Timer$2.prototype.stop=function(){this.scheduler.stopTimer(this),this._hasCalledOnStart=!1,this._isRunning=!1,this._wasStopped=!0},Timer$2.prototype.isRunning=function(){return this._isRunning},Timer$2.prototype.durationLeft=function(){return this._durationLeft};function TimerScheduler(e){this.requestFrame=e,this.runningTimers=[],this.newTimers=[]}TimerScheduler.prototype.createTimer=function(e){return new Timer$2(this,e)},TimerScheduler.prototype.scheduleTimer=function(e){this.newTimers.indexOf(e)===-1&&(e.repeatCount===0&&(e.repeatCount=1e5),this.newTimers.push(e),this.requestFrame())},TimerScheduler.prototype.stopTimer=function(e){var t;e._isRunning?(t=this.runningTimers.indexOf(e),t!==-1&&this.runningTimers.splice(t,1),e.onStop&&!e._wasStopped&&e.onStop()):(t=this.newTimers.indexOf(e),t!==-1&&this.newTimers.splice(t,1))},TimerScheduler.prototype.runTimers=function(e){var t=[],n=[],o=[],r,s=this.runningTimers.length,a;for(r=0;r<s;++r)o[r]=this.runningTimers[r];for(r=0;r<s;++r)if(a=o[r],a&&e>=a._start){a._hasCalledOnStart===!1&&a.onStart&&(a.onStart(),a._hasCalledOnStart=!0);var l;a.duration>0?l=(e-a._start)/(a.duration*a.repeatCount):l=1,a._durationLeft=a.duration*(1-l);var u=l*a.repeatCount-Math.floor(l*a.repeatCount);l>=1&&(u=1),a.onRunning&&a.onRunning(u),l<1&&a._isRunning?t.push(a):a._wasStopped||n.push(a)}else t.push(a);for(this.runningTimers=t,r=0;r<n.length;++r)n[r]._isRunning=!1,n[r]._hasCalledOnStart=!1,n[r].onFinish&&n[r].onFinish();if(this.newTimers.length>0){for(r=0;r<this.newTimers.length;++r)a=this.newTimers[r],a._start=e+a.delay,a._isRunning=!0,a._wasStopped=!1,this.runningTimers.push(a),a.delay===0&&(a.onStart&&(a.onStart(),a._hasCalledOnStart=!0),a.onRunning&&a.onRunning(0));this.newTimers.length=0}},TimerScheduler.prototype.hasPendingTimers=function(){return this.runningTimers.length>0||this.newTimers.length>0};class Variants{constructor({graphModel:t,getNodeScope:n}){this.getNodeScope=n,t&&(this.graphModel=t,t.on("variantUpdated",o=>this.onVariantUpdated(o)))}getVariant(t,n){if(this.graphModel)return this.graphModel.getVariant(t,n)}onVariantUpdated(t){const n=this.getNodeScope();if(!n)return;const o=n.getNodesWithTypeRecursive(t.typename).filter(r=>r.variant?r.variant.name===t.name:r.model&&r.model.variant===t.name);for(const r of o)r.setVariant(t)}}function OutputProperty(e){if(!e.owner)throw new Error("Owner must be set");this.getter=e.getter,this.connections=[],this.owner=e.owner,this.name=e.name,this.onFirstConnectionAdded=e.onFirstConnectionAdded,this.onLastConnectionRemoved=e.onLastConnectionRemoved,this._id=void 0}Object.defineProperties(OutputProperty.prototype,{value:{get(){return this.getter.call(this.owner)}},id:{get(){return this._id||(this._id=this.owner.id+this.name),this._id}},registerConnection:{value(e,t){this.connections.push({node:e,inputPortName:t}),this.connections.length===1&&this.onFirstConnectionAdded&&this.onFirstConnectionAdded.call(this.owner)}},deregisterConnection:{value(e,t){for(var n=0;n<this.connections.length;n++){var o=this.connections[n];if(o.node===e&&o.inputPortName===t){this.connections.splice(n,1);break}}this.connections.length===0&&this.onLastConnectionRemoved&&this.onLastConnectionRemoved.call(this.owner)}},flagDependeesDirty:{value(e){for(var t=0,n=this.connections.length;t<n;t++)this.connections[t].node.flagDirty()}},sendValue:{value(e){this._lastUpdateIteration!==this.owner._updatedAtIteration?(this._lastUpdateIteration=this.owner._updatedAtIteration,this.valuesSendThisIteration=0):this.valuesSendThisIteration++,this.valuesSendThisIteration>500&&(this.owner._cyclicLoop=!0);for(var t=0,n=this.connections.length;t<n;t++){var o=this.connections[t];o.node._setValueFromConnection(o.inputPortName,e)}}},hasConnections:{value(){return this.connections.length>0}}});function Node(e,t){this.id=t,this.context=e,this._dirty=!1,this._inputs={},this._inputValues={},this._outputs={},this._inputConnections={},this._outputList=[],this._isUpdating=!1,this._inputValuesQueue={},this._afterInputsHaveUpdatedCallbacks=[],this._internal={},this._signalsSentThisUpdate={},this._deleted=!1,this._deleteListeners=[],this._isFirstUpdate=!0,this._valuesFromConnections={},this.updateOnDirtyFlagging=!0}Node.prototype.getInputValue=function(e){return this._inputValues[e]},Node.prototype.registerInput=function(e,t){if(this.hasInput(e))throw new Error("Input property "+e+" already registered");if(this._inputs[e]=t,t.type&&t.type.units){const n=t.type.defaultUnit||t.type.units[0];this._inputValues[e]={value:t.default,type:n}}else t.hasOwnProperty("default")&&(this._inputValues[e]=t.default)},Node.prototype.deregisterInput=function(e){if(this.hasInput(e)===!1)throw new Error("Input property "+e+" doesn't exist");delete this._inputs[e],delete this._inputValues[e]},Node.prototype.registerInputs=function(e){for(const t in e)this.registerInput(t,e[t])},Node.prototype.getInput=function(e){if(this.hasInput(e)===!1){console.log("Node "+this.name+": Invalid input property "+e);return}return this._inputs[e]},Node.prototype.hasInput=function(e){return e in this._inputs},Node.prototype.registerInputIfNeeded=function(){},Node.prototype.setInputValue=function(name,value){const input=this.getInput(name);if(!input){console.log("node doesn't have input",name);return}const currentInputValue=this._inputValues[name];if(isNaN(value)===!1&&currentInputValue&&currentInputValue.unit){const e=Object.assign({},currentInputValue);e.value=value,value=e}if(this._inputValues[name]=value,input.type==="color"&&this.context&&this.context.styles)value=this.context.styles.resolveColor(value);else if(input.type==="array"&&typeof value=="string")try{value=eval(value),this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"invalid-array-"+name)}catch(e){value=[],console.log(e),this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"invalid-array-"+name,{showGlobally:!0,message:"Invalid array<br>"+e.toString()})}input.set.call(this,value)},Node.prototype.hasOutput=function(e){return e in this._outputs},Node.prototype.registerOutput=function(e,t){if(this.hasOutput(e))throw new Error("Output property "+e+" already registered");const n=new OutputProperty({owner:this,getter:t.get||t.getter,name:e,onFirstConnectionAdded:t.onFirstConnectionAdded,onLastConnectionRemoved:t.onLastConnectionRemoved});this._outputs[e]=n,this._outputList.push(n)},Node.prototype.deregisterOutput=function(e){if(this.hasOutput(e)===!1)throw new Error("Output property "+e+" isn't registered");const t=this._outputs[e];if(t.hasConnections())throw new Error("Output property "+e+" has connections and can't be removed");delete this._outputs[e];var n=this._outputList.indexOf(t);this._outputList.splice(n,1)},Node.prototype.registerOutputs=function(e){for(var t in e)this.registerOutput(t,e[t])},Node.prototype.registerOutputIfNeeded=function(){},Node.prototype.getOutput=function(e){if(this.hasOutput(e)===!1)throw new Error("Node "+this.name+" doesn't have a port named "+e);return this._outputs[e]},Node.prototype.connectInput=function(e,t,n){if(this.hasInput(e)===!1)throw new Error("Invalid connection, input doesn't exist. Trying to connect from "+t.name+" output "+n+" to "+this.name+" input "+e);var o=t.getOutput(n);if(o.registerConnection(this,e),this._inputConnections[e]||(this._inputConnections[e]=[]),this._inputConnections[e].push(o),t._signalsSentThisUpdate[n])this._setValueFromConnection(e,!0),this._setValueFromConnection(e,!1);else{var r=o.value;r!==void 0&&(this._setValueFromConnection(e,r),this.context&&this.context.connectionSentValue(o,o.value))}this.flagDirty()},Node.prototype.removeInputConnection=function(e,t,n){if(!this._inputConnections[e])throw new Error("Node removeInputConnection: Input doesn't exist");const o=this._inputConnections[e];for(let r=0;r<o.length;r++){const s=o[r];if(s.owner.id===t&&s.name===n){o.splice(r,1),s.owner.getOutput(n).deregisterConnection(this,e);break}}o.length===0&&delete this._valuesFromConnections[e]},Node.prototype.isInputConnected=function(e){return this._inputConnections.hasOwnProperty(e)?this._inputConnections[e].some(t=>t.owner.name!=="Component Inputs"?!0:t.owner.nodeScope.componentOwner.isInputConnected(t.name)):!1},Node.prototype.update=function(){if(this._isUpdating||this._dirty===!1)return;this._updatedAtIteration!==this.context.updateIteration&&(this._updatedAtIteration=this.context.updateIteration,this._updateIteration=0,this._cyclicLoop&&(this._cyclicLoop=!1)),this._isUpdating=!0;const e=100;try{for(;this._dirty&&!this._cyclicLoop;){this._updateDependencies(),this._dirty=!1;const t=Object.keys(this._inputValuesQueue);let n=!0;for(;n&&!this._cyclicLoop;){n=!1;for(let r=0;r<t.length;r++){const s=t[r],a=this._inputValuesQueue[s];a.length>0&&(this.setInputValue(s,a.shift()),a.length>0&&(n=!0))}const o=this._afterInputsHaveUpdatedCallbacks;this._afterInputsHaveUpdatedCallbacks=[];for(let r=0;r<o.length;r++)o[r].call(this)}this._updateIteration++,this._updateIteration>=e&&(this._cyclicLoop=!0)}}catch(t){throw this._isUpdating=!1,t}this._cyclicLoop&&(this.context.scheduleNextFrame(()=>{this.context.nodeIsDirty(this)}),this.context.editorConnection&&!this._cyclicWarningSent&&this.context.isWarningTypeEnabled("cyclicLoops")&&(this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"cyclic-loop",{showGlobally:!0,message:"Cyclic loop detected"}),this._cyclicWarningSent=!0,console.log("cycle detected",{id:this.id,name:this.name,component:this.nodeScope.componentOwner.name}))),this._isFirstUpdate=!1,this._isUpdating=!1},Node.prototype._updateDependencies=function(){for(var e in this._inputConnections)for(var t=this._inputConnections[e],n=0;n<t.length;++n)t[n].owner.update()},Node.prototype.flagDirty=function(){this._dirty||(this._dirty=!0,this.updateOnDirtyFlagging&&this._performDirtyUpdate())},Node.prototype._performDirtyUpdate=function(){this.context&&this.context.nodeIsDirty(this);for(var e=0;e<this._outputList.length;++e)this._outputList[e].flagDependeesDirty()},Node.prototype.sendValue=function(e,t){if(this.hasOutput(e)===!1){console.log("Error: Node",this.name,"doesn't have a output named",e);return}if(t===void 0)return;const n=this.getOutput(e);n.sendValue(t),this.context&&this.context.connectionSentValue(n,t)},Node.prototype.flagOutputDirty=function(e){const t=this.getOutput(e);this.sendValue(e,t.value)},Node.prototype.flagAllOutputsDirty=function(){for(const e of this._outputList)this.sendValue(e.name,e.value)},Node.prototype.sendSignalOnOutput=function(e){if(this.hasOutput(e)===!1){console.log("Error: Node",this.name,"doesn't have a output named",e);return}const t=this.getOutput(e);t.sendValue(!0),t.sendValue(!1),this._signalsSentThisUpdate[e]=!0,this.scheduleAfterInputsHaveUpdated(function(){this._signalsSentThisUpdate[e]=!1}),this.context&&this.context.connectionSentSignal(t)},Node.prototype._setValueFromConnection=function(e,t){this._valuesFromConnections[e]=t,this.queueInput(e,t)},Node.prototype._hasInputBeenSetFromAConnection=function(e){return this._valuesFromConnections.hasOwnProperty(e)},Node.prototype.queueInput=function(e,t){if(this._inputValuesQueue[e]||(this._inputValuesQueue[e]=[]),this._isFirstUpdate){const n=this._inputValuesQueue[e][0];n===!0||(n instanceof Object&&n.unit&&!(t instanceof Object)&&(t={value:t,unit:n.unit}),this._inputValuesQueue[e].length=0)}this._inputValuesQueue[e].push(t),this.flagDirty()},Node.prototype.scheduleAfterInputsHaveUpdated=function(e){this._afterInputsHaveUpdatedCallbacks.push(e),this.flagDirty()},Node.prototype.setNodeModel=function(e){this.model=e,e.on("parameterUpdated",this._onNodeModelParameterUpdated,this),e.on("variantUpdated",this._onNodeModelVariantUpdated,this),e.on("inputPortRemoved",t=>{this.hasInput(t.name)&&this.deregisterInput(t.name)},this),e.on("outputPortRemoved",t=>{this.hasOutput(t.name)&&this.deregisterOutput(t.name)},this)},Node.prototype.addDeleteListener=function(e){this._deleteListeners.push(e)},Node.prototype._onNodeDeleted=function(){this.model&&(this.model.removeListenersWithRef(this),this.model=void 0),this._deleted=!0;for(const e of this._deleteListeners)e.call(this)},Node.prototype._onNodeModelParameterUpdated=function(e){if(this.registerInputIfNeeded(e.name),e.value!==void 0)if(e.state){if(!this._getVisualStates){console.log("Node has nos visual states, but got a parameter for state",e.state);return}this._getVisualStates().indexOf(e.state)!==-1&&this.queueInput(e.name,e.value)}else this.queueInput(e.name,e.value);else{let t;const n=this.variant;e.state?n&&n.stateParameters.hasOwnProperty(e.state)&&n.stateParameters[e.state].hasOwnProperty(e.name)?t=n.stateParameters[e.state][e.name]:this.model.parameters.hasOwnProperty(e.name)?t=this.model.parameters[e.name]:n&&n.parameters.hasOwnProperty(e.name)&&(t=n.parameters[e.name]):n&&n.parameters.hasOwnProperty(e.name)&&(t=n.parameters[e.name]),t===void 0&&(t=this.context.getDefaultValueForInput(this.model.type,e.name),this._resetReactVirtualDOM&&this._resetReactVirtualDOM()),this.queueInput(e.name,t)}},Node.prototype._onNodeModelVariantUpdated=function(e){this.setVariant(e)};function guid$1(){function e(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function NodeScope(e,t){this.context=e,this.nodes={},this.componentOwner=t,this.componentInstanceChildren={}}function verifyData(e,t){t.forEach(function(n){if(!e[n])throw new Error("Missing "+n)})}NodeScope.prototype.addConnection=function(e){try{verifyData(e,["sourceId","sourcePort","targetId","targetPort"])}catch(o){throw new Error("Error in connection: "+o.message)}try{var t=this.getNodeWithId(e.sourceId),n=this.getNodeWithId(e.targetId);n.registerInputIfNeeded(e.targetPort),t.registerOutputIfNeeded(e.sourcePort),n.connectInput(e.targetPort,t,e.sourcePort)}catch(o){console.error(o.message)}},NodeScope.prototype.setNodeParameters=function(e,t){const n=this.context.variants.getVariant(t.type,t.variant);if(n)e.setVariant(n);else{const s=t.parameters;var o=Object.keys(s);if(this.context.nodeRegister.hasNode(e.name)){var r=this.context.nodeRegister.getNodeMetadata(e.name);o.sort(function(a,l){var u=r.inputs[a],d=r.inputs[l];return(d?d.inputPriority:0)-(u?u.inputPriority:0)})}o.forEach(a=>{e.registerInputIfNeeded(a),e.hasInput(a)!==!1&&e.queueInput(a,s[a])})}},NodeScope.prototype.createNodeFromModel=async function(e,t){if(e.type==="Component Children"){if(e.parent){var n=this.getNodeWithId(e.parent.id);this.componentOwner.setChildRoot(n)}return}var o;try{o=await this.createNode(e.type,e.id),o.updateOnDirtyFlagging=t!==!1,o.setNodeModel(e)}catch(r){console.error(r.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("nodescope")&&this.context.editorConnection.sendWarning(this.componentOwner.name,e.id,"nodelibrary-unknown-node",{message:r.message,showGlobally:!0});return}return e.variant&&o.setVariant&&o.setVariant(e.variant),this.setNodeParameters(o,e),e.parent&&this.insertNodeInTree(o,e),o},NodeScope.prototype.insertNodeInTree=function(e,t){var n=this.getNodeWithId(t.parent.id),o=t.parent.children.indexOf(t);if(!n.addChild)throw new Error("Node "+n.id+" of type "+n.constructor.name+" can't have children");n.addChild(e,o)},NodeScope.prototype.getNodeWithId=function(e){if(this.nodes.hasOwnProperty(e)===!1)throw new Error("Unknown node id "+e);return this.nodes[e]},NodeScope.prototype.hasNodeWithId=function(e){return this.nodes.hasOwnProperty(e)},NodeScope.prototype.createPrimitiveNode=function(e,t,n){if(t||(t=guid$1()),this.nodes.hasOwnProperty(t))throw Error("duplicate id "+t);const o=this.context.nodeRegister.createNode(e,t,this);if(n)for(const r in n)o[r]=n[r];return this.nodes[t]=o,o},NodeScope.prototype.createNode=async function(e,t,n){if(t||(t=guid$1()),this.nodes.hasOwnProperty(t))throw Error("duplicate id "+t);let o;if(this.context.nodeRegister.hasNode(e)){if(o=this.context.nodeRegister.createNode(e,t,this),n)for(const r in n)o[r]=n[r]}else o=await this.context.createComponentInstanceNode(e,t,this,n),this.componentInstanceChildren[t]=o;return this.nodes[t]=o,o},NodeScope.prototype.getNodesWithIdRecursive=function(e){function t(o,r,s){o.nodes.hasOwnProperty(r)&&s.push(o.nodes[r]);var a=Object.keys(o.nodes).filter(function(l){return o.nodes[l]instanceof ComponentInstanceNode});a.forEach(function(l){t(o.nodes[l].nodeScope,r,s)})}var n=[];return t(this,e,n),n},NodeScope.prototype.getNodesWithType=function(e){var t=this,n=Object.keys(this.nodes).filter(function(o){return t.nodes[o].name===e});return n.map(function(o){return t.nodes[o]})},NodeScope.prototype.getNodesWithTypeRecursive=function(e){var t=this;function n(){o=o.concat(t.getNodesWithType(e));var r=Object.keys(t.nodes).filter(function(s){return t.nodes[s]instanceof ComponentInstanceNode});r.forEach(function(s){var a=t.nodes[s].nodeScope.getNodesWithTypeRecursive(e);o=o.concat(a)})}var o=[];return n(),o},NodeScope.prototype.getAllNodesRecursive=function(){let e=[];return(()=>{e=e.concat(Object.values(this.nodes));var t=Object.keys(this.nodes).filter(n=>this.nodes[n]instanceof ComponentInstanceNode);t.forEach(n=>{var o=this.nodes[n].nodeScope.getAllNodesRecursive();e=e.concat(o)})})(),e},NodeScope.prototype.getAllNodesWithVariantRecursive=function(e){return this.getAllNodesRecursive().filter(t=>t.variant===e)},NodeScope.prototype.onNodeModelRemoved=function(e){var t=this.getNodeWithId(e.id);if(e.parent){var n=this.getNodeWithId(e.parent.id);n.removeChild(t)}t._onNodeDeleted(),delete this.nodes[t.id],delete this.componentInstanceChildren[t.id]},NodeScope.prototype.removeConnection=function(e){var t=this.getNodeWithId(e.targetId);t.removeInputConnection(e.targetPort,e.sourceId,e.sourcePort)},NodeScope.prototype.setComponentModel=async function(e){this.componentModel=e;const t=[];for(const o of e.getAllNodes()){const r=await this.createNodeFromModel(o,!1);r&&t.push(r)}e.getAllConnections().forEach(o=>this.addConnection(o)),t.forEach(o=>o.updateOnDirtyFlagging=!0),t.forEach(o=>{o._dirty&&o._performDirtyUpdate()}),e.on("connectionAdded",o=>this.addConnection(o),this),e.on("connectionRemoved",this.removeConnection,this),e.on("nodeAdded",this.createNodeFromModel,this);var n=this;e.on("nodeParentWillBeRemoved",function(o){if(o.type==="Component Children"){o.parent&&this.componentOwner.setChildRoot(null);return}const r=n.getNodeWithId(o.id);r.parent&&r.parent.removeChild(r)},this),e.on("nodeParentUpdated",function(o){if(o.type==="Component Children"){var r=this.getNodeWithId(o.parent.id);this.componentOwner.setChildRoot(r)}else{var s=n.getNodeWithId(o.id);n.insertNodeInTree(s,o)}},this),e.on("nodeRemoved",function(o){o.type!=="Component Children"&&n.onNodeModelRemoved(o)},this);for(const o in this.nodes){const r=this.nodes[o];r.nodeScopeDidInitialize&&r.nodeScopeDidInitialize()}},NodeScope.prototype.reset=function(){this.componentModel&&(this.componentModel.removeListenersWithRef(this),this.componentModel=void 0),Object.keys(this.nodes).forEach(e=>{this.nodes.hasOwnProperty(e)&&this.deleteNode(this.nodes[e])})},NodeScope.prototype.deleteNode=function(e){if(this.nodes.hasOwnProperty(e.id)===!1){console.error("Node doesn't belong to this scope",e.id,e.name);return}if(e.parent&&e.parent.removeChild(e),e.getChildren&&e.getChildren().forEach(t=>{e.removeChild(t),(t.parentNodeScope||t.nodeScope).deleteNode(t)}),this.componentModel){const t=this.componentModel.getConnectionsFrom(e.id),n=this.componentModel.getConnectionsTo(e.id);t.concat(n).forEach(o=>{this.nodes.hasOwnProperty(o.targetId)&&this.nodes.hasOwnProperty(o.sourceId)&&this.removeConnection(o)})}e._onNodeDeleted(),delete this.nodes[e.id],delete this.componentInstanceChildren[e.id]},NodeScope.prototype.sendEventFromThisScope=function(e,t,n,o,r){if(o)for(var s=this.getNodesWithType("Event Receiver").filter(function(g){return g.getChannelName()===e}),a=0;a<s.length;a++){var l=s[a].handleEvent(t);if(l)return!0}if(n==="parent"&&this.componentOwner.parentNodeScope){const g=this.componentOwner.parent?this.componentOwner.parent.nodeScope:this.componentOwner.parentNodeScope;if(!g)return;g.sendEventFromThisScope(e,t,n,!0)}else if(n==="children"){var u=this.nodes;for(var d in u){var h=u[d].children;h&&h.forEach(g=>{if(g.name&&this.context.hasComponentModelWithName(g.name)){var b=g.nodeScope.sendEventFromThisScope(e,t,n,!0);if(b)return!0}})}}else if(n==="siblings"){let g;if(this.componentOwner.parent?g=this.componentOwner.parent.nodeScope:g=this.componentOwner.parentNodeScope,!g)return;var u=g.nodes;for(var d in u){var h=u[d].children;if(h){var f=h.filter(A=>A.name&&this.context.hasComponentModelWithName(A.name)&&A.nodeScope!==this);f.forEach(A=>{var v=A.nodeScope.sendEventFromThisScope(e,t,null,!0);if(v)return!0})}}}return!1};let componentIdCounter=0;function ComponentInstanceNode(e,t,n){Node.call(this,e,t),this.nodeScope=new NodeScope(e,this),this.parentNodeScope=n,this._internal.childRoot=null,this._internal.componentOutputValues={},this._internal.componentOutputs=[],this._internal.componentInputs=[],this._internal.inputValues={},this._internal.roots=[],this._internal.instanceId="__$ndl_componentInstaceId"+componentIdCounter,this.nodeScope.modelScope=n?n.modelScope:void 0,componentIdCounter++}ComponentInstanceNode.prototype=Object.create(Node.prototype,{setComponentModel:{value:async function(e){this.componentModel=e;var t=this;await this.nodeScope.setComponentModel(e),this._internal.componentInputs=this.nodeScope.getNodesWithType("Component Inputs"),this._internal.componentOutputs=this.nodeScope.getNodesWithType("Component Outputs"),Object.values(e.getInputPorts()).forEach(this.registerComponentInputPort.bind(this)),Object.values(e.getOutputPorts()).forEach(this.registerComponentOutputPort.bind(this));const n=e.roots||[];this._internal.roots=n.map(o=>this.nodeScope.getNodeWithId(o)),e.on("rootAdded",o=>{this._internal.roots.push(this.nodeScope.getNodeWithId(o)),this.forceUpdate()},this),e.on("rootRemoved",function(o){const r=this._internal.roots.findIndex(s=>s.id===o);r!==-1&&this._internal.roots.splice(r,1),this.forceUpdate()},this),e.on("inputPortAdded",this.registerComponentInputPort.bind(this),this),e.on("outputPortAdded",this.registerComponentOutputPort.bind(this),this),e.on("inputPortRemoved",function(o){t.hasInput(o.name)&&t.deregisterInput(o.name)},this),e.on("outputPortRemoved",function(o){this.hasOutput(o.name)&&t.deregisterOutput(o.name)},this),e.on("nodeAdded",function(o){o.type==="Component Inputs"?t._internal.componentInputs.push(t.nodeScope.getNodeWithId(o.id)):o.type==="Component Outputs"&&t._internal.componentOutputs.push(t.nodeScope.getNodeWithId(o.id))},this),e.on("nodeRemoved",function(o){function r(s,a){return s.filter(l=>l.id!==a)}o.type==="Component Inputs"?t._internal.componentInputs=r(t._internal.componentInputs,o.id):o.type==="Component Outputs"&&(t._internal.componentOutputs=r(t._internal.componentOutputs,o.id))},this),e.on("renamed",function(o){t.name=o.newName},this)}},_onNodeDeleted:{value(){this.componentModel&&(this.componentModel.removeListenersWithRef(this),this.componentModel=void 0),this.nodeScope.reset(),Node.prototype._onNodeDeleted.call(this)}},registerComponentInputPort:{value(e){this.registerInput(e.name,{set(t){this._internal.inputValues[e.name]=t,this._internal.componentInputs.forEach(function(n){n.registerOutputIfNeeded(e.name),n.flagOutputDirty(e.name)})}})}},registerComponentOutputPort:{value(e){this.registerOutput(e.name,{getter(){return this._internal.componentOutputValues[e.name]}})}},setOutputFromComponentOutput:{value(e,t){this.hasOutput(e)!==!1&&(this._internal.creatorCallbacks&&this._internal.creatorCallbacks.onOutputChanged&&this._internal.creatorCallbacks.onOutputChanged(e,t,this._internal.componentOutputValues[e]),this._internal.componentOutputValues[e]=t,this.flagOutputDirty(e))}},setChildRoot:{value(e){const t=this._internal.childRoot,n=e;if(this._internal.childRoot=n,this.model&&this.model.children){const o=this.parentNodeScope,r=this.model.children.filter(s=>s.type!=="Component Children").map(s=>o.getNodeWithId(s.id));if(t)for(let s=0;s<r.length;s++)t.isChild(r[s])&&t.removeChild(r[s]);if(n)for(let s=0;s<r.length;s++){const a=r[s],l=a.model.parent.children.indexOf(a.model);this.addChild(a,l)}}}},getChildRootIndex:{value(){if(!this._internal.childRoot||!this._internal.childRoot.model||!this._internal.childRoot.model.children)return 0;for(var e=this._internal.childRoot.model.children,t=0;t<e.length;t++)if(e[t].type==="Component Children")return t;return 0}},getChildRoot:{value(){return this._internal.childRoot?this._internal.childRoot:null}},getRoots:{value(){return this._internal.roots}},triggerDidMount:{value(){this._internal.roots.forEach(e=>{e.triggerDidMount&&e.triggerDidMount()})}},render:{value(){return this._internal.roots.length===0?null:this._internal.roots[0].render()}},setChildIndex:{value(e){this.getRoots().forEach(t=>t.setChildIndex&&t.setChildIndex(e))}},addChild:{value(e,t){this.getChildRoot().addChild(e,t+this.getChildRootIndex())}},removeChild:{value(e){this.getChildRoot().removeChild(e)}},getChildren:{value(e){const t=this.getChildRoot();return t?t.getChildren():[]}},isChild:{value(e){return this.getChildRoot()?this.getChildRoot().isChild(e):!1}},contains:{value(e){return this.getRoots().some(t=>t.contains&&t.contains(e))}},_performDirtyUpdate:{value(){Node.prototype._performDirtyUpdate.call(this);for(var e=this._internal.componentInputs,t=0,n=e.length;t<n;t++)e[t].flagDirty();this._internal.componentOutputs.forEach(function(o){o.flagDirty()})}},getRef:{value(){const e=this._internal.roots[0];return e?e.getRef():void 0}},update:{value(){Node.prototype.update.call(this),this._internal.componentOutputs.forEach(function(e){e.update()})}},forceUpdate:{value(){this.parent&&(this.parent.cachedChildren=void 0,this.parent.forceUpdate())}},getInstanceId:{value(){return this._internal.instanceId}}}),ComponentInstanceNode.prototype.constructor=ComponentInstanceNode;function NodeContext(e){e=e||{},e.runningInEditor=e.hasOwnProperty("runningInEditor")?e.runningInEditor:!1,this._dirtyNodes=[],this.callbacksAfterUpdate=[],this.graphModel=e.graphModel,this.platform=e.platform,this.eventEmitter=new EventEmitter$2,this.eventEmitter.setMaxListeners(1e6),this.eventSenderEmitter=new EventEmitter$2,this.eventSenderEmitter.setMaxListeners(1e6),this.globalValues={},this.globalsEventEmitter=new EventEmitter$2,this.globalsEventEmitter.setMaxListeners(1e6),this.runningInEditor=e.runningInEditor,this.currentFrameTime=0,this.frameNumber=0,this.updateIteration=0,this.nodeRegister=new NodeRegister(this),this.timerScheduler=new TimerScheduler(this.scheduleUpdate.bind(this)),this.componentModels={},this.debugInspectorsEnabled=!1,this.connectionsToPulse={},this.connectionsToPulseChanged=!1,this.debugInspectors={},this.connectionPulsingCallbackScheduled=!1,this.editorConnection=e.editorConnection,this.rootComponent=void 0,this._outputHistory={},this._signalHistory={},this.warningTypes={},this.bundleFetchesInFlight=new Map,this.variants=new Variants({graphModel:this.graphModel,getNodeScope:()=>this.rootComponent?this.rootComponent.nodeScope:null}),this.editorConnection&&(this.editorConnection.on("debugInspectorsUpdated",t=>{this.onDebugInspectorsUpdated(t)}),this.editorConnection.on("getConnectionValue",({clientId:t,connectionId:n})=>{if(this.editorConnection.clientId!==t)return;const o=this._outputHistory[n];this.editorConnection.sendConnectionValue(n,o?o.value:void 0)}))}NodeContext.prototype.setRootComponent=function(e){this.rootComponent=e},NodeContext.prototype.getCurrentTime=function(){return this.platform.getCurrentTime()},NodeContext.prototype.onDebugInspectorsUpdated=function(e){this.debugInspectorsEnabled&&(e=e.map(t=>{if(t.type==="connection"){const n=t.connection;t.id=n.fromId+n.fromProperty}else t.type==="node"&&(t.id=t.nodeId);return t}),this.debugInspectors={},e.forEach(t=>this.debugInspectors[t.id]=t),this.sendDebugInspectorValues())},NodeContext.prototype.updateDirtyNodes=function(){var e,t,n=!0,o=0;for(this.updateIteration++,this.isUpdating=!0;n&&o<10;){var r=this._dirtyNodes;for(this._dirtyNodes=[],e=0,t=r.length;e<t;++e)try{r[e]._deleted||r[e].update()}catch(a){console.error(a,a.stack)}var s=this.callbacksAfterUpdate;for(this.callbacksAfterUpdate=[],e=0,t=s.length;e<t;e++)try{s[e]()}catch(a){console.error(a)}n=this.callbacksAfterUpdate.length>0||this._dirtyNodes.length>0,o++}this.isUpdating=!1},NodeContext.prototype.update=function(){this.frameNumber++,this.updateDirtyNodes(),this.timerScheduler.hasPendingTimers()&&(this.scheduleUpdate(),this.timerScheduler.runTimers(this.currentFrameTime)),this.debugInspectorsEnabled&&this.sendDebugInspectorValues()},NodeContext.prototype.reset=function(){this.eventEmitter.emit("applicationDataReloaded");var e=this.eventEmitter;["frameStart","frameEnd"].forEach(function(t){e.removeAllListeners(t)}),this.globalValues={},this._dirtyNodes.length=0,this.callbacksAfterUpdate.length=0,this.timerScheduler.runningTimers=[],this.timerScheduler.newTimers=[],this.rootComponent=void 0,this.clearDebugInspectors()},NodeContext.prototype.nodeIsDirty=function(e){this._dirtyNodes.push(e),this.scheduleUpdate()},NodeContext.prototype.scheduleUpdate=function(){this.eventEmitter.emit("scheduleUpdate")},NodeContext.prototype.scheduleAfterUpdate=function(e){this.callbacksAfterUpdate.push(e),this.scheduleUpdate()},NodeContext.prototype.scheduleNextFrame=function(e){this.eventEmitter.once("frameStart",e),this.scheduleUpdate()},NodeContext.prototype.setGlobalValue=function(e,t){this.globalValues[e]=t,this.globalsEventEmitter.emit(e)},NodeContext.prototype.getGlobalValue=function(e){return this.globalValues[e]},NodeContext.prototype.registerComponentModel=function(e){if(this.componentModels.hasOwnProperty(e.name))throw new Error("Duplicate component name "+e.name);this.componentModels[e.name]=e;var t=this;e.on("renamed",function(n){delete t.componentModels[n.oldName],t.componentModels[n.newName]=e},this)},NodeContext.prototype.deregisterComponentModel=function(e){this.componentModels.hasOwnProperty(e.name)&&(this.componentModels[e.name].removeListenersWithRef(this),delete this.componentModels[e.name])},NodeContext.prototype.fetchComponentBundle=async function(e){const t=async n=>{let o=`${Noodl.Env.BaseUrl||"/"}noodl_bundles/${n}.json`;const r=await fetch(o);if(r.status===404)throw new Error("Component not found "+n);const s=await r.json();for(const a of s)this.graphModel.hasComponentWithName(a.name)===!1&&await this.graphModel.importComponentFromEditorData(a)};if(this.bundleFetchesInFlight.has(e))await this.bundleFetchesInFlight.get(e);else{const n=t(e);this.bundleFetchesInFlight.set(e,n),await n}},NodeContext.prototype.getComponentModel=async function(e){if(!e)throw new Error("Component instance must have a name");if(this.componentModels.hasOwnProperty(e)===!1){const t=this.graphModel.getBundleContainingComponent(e);if(!t)throw new Error("Can't find component model for "+e);for(const n of this.graphModel.getBundleDependencies(t))this.fetchComponentBundle(n);await this.fetchComponentBundle(t)}return this.componentModels[e]},NodeContext.prototype.hasComponentModelWithName=function(e){return this.componentModels.hasOwnProperty(e)},NodeContext.prototype.createComponentInstanceNode=async function(e,t,n,o){var r=new ComponentInstanceNode(this,t,n);r.name=e;for(const a in o)r[a]=o[a];const s=await this.getComponentModel(e);return await r.setComponentModel(s),r},NodeContext.prototype._formatConnectionValue=function(e){if(typeof e=="object"&&e&&e.constructor&&e.constructor.name==="Node")e="<Node> "+e.name;else if(typeof e=="object"&&typeof window<"u"&&e instanceof HTMLElement)e=`DOM Node <${e.tagName}>`;else{if(typeof e=="string"&&!e.startsWith("[Signal]"))return'"'+e+'"';if(Number.isNaN(e))return"NaN"}return e},NodeContext.prototype.connectionSentValue=function(e,t){if(!this.editorConnection||!this.editorConnection.isConnected()||!this.debugInspectorsEnabled)return;const n=this.getCurrentTime();if(this._outputHistory[e.id]={value:t,timestamp:n},this.connectionsToPulse.hasOwnProperty(e.id)){this.connectionsToPulse[e.id].timestamp=n;return}const o=[];e.connections.forEach(r=>{o.push(e.owner.id+e.name+r.node.id+r.inputPortName)}),this.connectionsToPulse[e.id]={timestamp:n,connections:o},this.connectionsToPulseChanged=!0,this.connectionPulsingCallbackScheduled===!1&&(this.connectionPulsingCallbackScheduled=!0,setTimeout(this.clearOldConnectionPulsing.bind(this),100))},NodeContext.prototype.connectionSentSignal=function(e){const t=e.id;this._signalHistory.hasOwnProperty(t)||(this._signalHistory[t]={count:0}),this._signalHistory[t].count++,this.connectionSentValue(e,"[Signal] Trigger count "+this._signalHistory[t].count)},NodeContext.prototype.clearDebugInspectors=function(){this.debugInspectors={},this.connectionsToPulse={},this.editorConnection.sendPulsingConnections(this.connectionsToPulse)},NodeContext.prototype.clearOldConnectionPulsing=function(){this.connectionPulsingCallbackScheduled=!1;var e=this.getCurrentTime(),t=this,n=Object.keys(this.connectionsToPulse);n.forEach(function(o){var r=t.connectionsToPulse[o];e-r.timestamp>100&&(t.connectionsToPulseChanged=!0,delete t.connectionsToPulse[o])}),this.connectionsToPulseChanged&&(this.connectionsToPulseChanged=!1,this.editorConnection.sendPulsingConnections(this.connectionsToPulse)),Object.keys(this.connectionsToPulse).length>0&&(this.connectionPulsingCallbackScheduled=!0,setTimeout(this.clearOldConnectionPulsing.bind(this),500))},NodeContext.prototype._getDebugInspectorValueForNode=function(e){if(!this.rootComponent)return;const t=this.rootComponent.nodeScope.getNodesWithIdRecursive(e),n=t[t.length-1];if(n&&n.getInspectInfo){const o=n.getInspectInfo();if(o!==void 0)return{type:"node",id:e,value:o}}},NodeContext.prototype.sendDebugInspectorValues=function(){const e=[];for(const t in this.debugInspectors){const n=this.debugInspectors[t];if(n.type==="connection"&&this._outputHistory.hasOwnProperty(t)){const o=this._outputHistory[t].value;e.push({type:"connection",id:t,value:this._formatConnectionValue(o)})}else if(n.type==="node"){const o=this._getDebugInspectorValueForNode(t);o&&e.push(o)}}e.length>0&&this.editorConnection.sendDebugInspectorValues(e),this.connectionsToPulseChanged&&(this.connectionsToPulseChanged=!1,this.editorConnection.sendPulsingConnections(this.connectionsToPulse))},NodeContext.prototype.setDebugInspectorsEnabled=function(e){this.debugInspectorsEnabled=e,this.editorConnection.debugInspectorsEnabled=e,e&&this.sendDebugInspectorValues()},NodeContext.prototype.sendGlobalEventFromEventSender=function(e,t){this.eventSenderEmitter.emit(e,t)},NodeContext.prototype.setPopupCallbacks=function({onShow:e,onClose:t}){this.onShowPopup=e,this.onClosePopup=t},NodeContext.prototype.showPopup=async function(e,t,n){if(!this.onShowPopup)return;const o=this.rootComponent.nodeScope,r=await o.createNode(e);for(const d in t)r.setInputValue(d,t[d]);r.popupParent=n?.senderNode||null;const s=o.createPrimitiveNode("Group");s.setInputValue("flexDirection","node"),s.setInputValue("cssClassName","noodl-popup");const a=this.graphModel.getSettings().bodyScroll;s.setInputValue("position",a?"fixed":"absolute");var l=r.nodeScope.getNodesWithType("NavigationClosePopup");if(l&&l.length>0)for(var u=0;u<l.length;u++)l[u]._setCloseCallback((d,h)=>{this.scheduleNextFrame(()=>{o.hasNodeWithId(s.id)&&(this.onClosePopup(s),o.deleteNode(s),n&&n.onClosePopup&&n.onClosePopup(d,h))})});this.onShowPopup(s),requestAnimationFrame(()=>{s.addChild(r)})},NodeContext.prototype.setWarningTypes=function(e){Object.assign(this.warningTypes,e)},NodeContext.prototype.isWarningTypeEnabled=function(e){return this.warningTypes.hasOwnProperty(e)?!!this.warningTypes[e]:!0},NodeContext.prototype.getDefaultValueForInput=function(e,t){if(this.nodeRegister.hasNode(e)===!1)return;const n=this.nodeRegister.getNodeMetadata(e).inputs[t];if(n)return n.type.defaultUnit?{value:n.default,unit:n.type.defaultUnit}:n.default};function EventSender$2(){this.listeners={},this.listenersWithRefs={}}EventSender$2.prototype.on=function(e,t,n){n?(this.listenersWithRefs.hasOwnProperty(e)||(this.listenersWithRefs[e]=new Map),this.listenersWithRefs[e].get(n)||this.listenersWithRefs[e].set(n,[]),this.listenersWithRefs[e].get(n).push(t)):(this.listeners.hasOwnProperty(e)||(this.listeners[e]=[]),this.listeners[e].push(t))},EventSender$2.prototype.removeListenersWithRef=function(e){Object.keys(this.listenersWithRefs).forEach(t=>{const n=this.listenersWithRefs[t];n.has(e)&&n.delete(e)})},EventSender$2.prototype.removeAllListeners=function(e){e?(delete this.listeners[e],delete this.listenersWithRefs[e]):(this.listeners={},this.listenersWithRefs={})},EventSender$2.prototype.emit=async function(e,t){const n=this.listeners[e];if(n)for(let r=0;r<n.length;r++){const s=n[r];await Promise.resolve(s.call(null,t))}const o=this.listenersWithRefs[e];if(o)for(const[r,s]of o)for(const a of s)await Promise.resolve(a.call(r,t))};function Services(){}Services.events=new EventEmitter$2;class ActiveWarnings{constructor(){this.currentWarnings=new Map}setWarning(t,n,o){if(this.currentWarnings.has(t)){const r=this.currentWarnings.get(t);return r[n]===o?!1:(r[n]=o,!0)}else return this.currentWarnings.set(t,{[n]:o}),!0}clearWarning(t,n){const o=this.currentWarnings.get(t);return!o||!o[n]?!1:(delete o[n],Object.keys(o).length===0&&delete this.currentWarnings.delete(t),!0)}clearWarnings(t){return this.currentWarnings.has(t)===!1?!1:(this.currentWarnings.delete(t),!0)}}function EditorConnection(e){var t=e||{};EventSender$2.call(this),this.runtimeType=t.runtimeType,this.platform=t.platform,this.ws=t.platform&&t.platform.webSocketClass||(typeof WebSocket<"u"?WebSocket:void 0),this.wsOptions=t.platform&&t.platform.webSocketOptions||void 0,this.reconnectOnClose=!0,this.enableDebugger=!1,this.lastSendTimestamp=0,this.sendQueue=[],this.sendTimer=void 0,this.activeWarnings=new ActiveWarnings}EditorConnection.prototype=Object.create(EventSender$2.prototype),EditorConnection.prototype.constructor=EditorConnection,EditorConnection.prototype.isRunningLocally=function(){var e=this.platform.isRunningLocally&&this.platform.isRunningLocally()||typeof document<"u"&&(document.location.hostname==="localhost"||document.location.hostname==="127.0.0.1");return e},EditorConnection.prototype.connect=function(e){this.socket=this.wsOptions?new this.ws(e,this.wsOptions):new this.ws(e);var t=this;this.socket.addEventListener("open",function(){t.clientId=guid$1(),t.socket.send(JSON.stringify({cmd:"register",type:"viewer",clientId:t.clientId})),t.emit("connected")}),this.socket.addEventListener("close",function(n){t.reconnectOnClose&&t.reconnect(e),console.log("Editor connection closed",n.code,n.reason),t.emit("connectionClosed")}),this.socket.addEventListener("error",function(n){console.log("Editor connection error, trying to reconnect")}),this.socket.addEventListener("message",async n=>{const o=typeof n.data=="string"?n.data:await n.data.text(),r=JSON.parse(o);let s;r.cmd==="registered"||(r.cmd==="export"?(s=JSON.parse(r.content),r.type==="full"&&r.target===this.clientId&&t.emit("exportDataFull",s)):r.cmd==="hoverStart"?t.emit("hoverStart",r.content.id):r.cmd==="hoverEnd"?t.emit("hoverEnd",r.content.id):r.cmd==="refresh"?t.emit("reload"):r.cmd==="debugInspectors"?this.debugInspectorsEnabled&&(s=JSON.parse(r.content),t.emit("debugInspectorsUpdated",s.inspectors)):r.cmd==="debuggingEnabled"?t.isRunningLocally()&&(s=JSON.parse(r.content),t.emit("debuggingEnabledChanged",s.enabled)):r.cmd==="getConnectionValue"?t.isRunningLocally()&&(s=JSON.parse(r.content),await t.emit("getConnectionValue",{clientId:s.clientId,connectionId:s.connectionId})):r.cmd==="modelUpdate"?await t.emit("modelUpdate",r.content):r.cmd==="publish"?Services.pubsub.routeMessage(r):r.cmd==="noodlModules"?t.emit("noodlModules",JSON.parse(r.content)):r.cmd==="mqttUpdate"?t.emit("mqttUpdate",r.content):r.cmd==="activeComponentChanged"?t.emit("activeComponentChanged",r.component):console.log("Command not implemented",r))})},EditorConnection.prototype.reconnect=function(e){var t=this;setTimeout(function(){t.connect(e)},2e3)},EditorConnection.prototype.isConnected=function(){return this.socket!==void 0&&this.socket.readyState===this.ws.OPEN};const getCircularReplacer=()=>{const e=new WeakSet;return(t,n)=>{if(typeof n=="object"&&n!==null){if(e.has(n))return"[Circular]";e.add(n)}return n}};EditorConnection.prototype.send=function(e){const t=this.platform.getCurrentTime(),n=t-this.lastSendTimestamp,o=r=>{try{this.socket.send(JSON.stringify(r))}catch(s){if(s.message&&s.message.startsWith("Converting circular"))try{this.socket.send(JSON.stringify(r,getCircularReplacer()))}catch(a){console.log("failed to send message to editor",r,a)}else console.log("failed to send message to editor",r,s)}};n<200||this.sendTimer||!this.isConnected()?(this.sendQueue.push(e),this.sendTimer||(this.sendTimer=setTimeout(()=>{if(this.isConnected()===!1)return;const r=50;for(let s=0;s<this.sendQueue.length;s+=r){const a=this.sendQueue.slice(s,s+r);o(a)}this.sendQueue=[],this.sendTimer=void 0,this.lastSendTimestamp=this.platform.getCurrentTime()},100))):(this.lastSendTimestamp=t,o(e))},EditorConnection.prototype.sendInspectId=function(e){this.send({cmd:"select",type:"viewer",content:JSON.stringify({id:e})})},EditorConnection.prototype.sendSelectComponent=function(e){this.send({cmd:"select",type:"viewer",content:JSON.stringify({componentName:e})})},EditorConnection.prototype.sendPulsingConnections=function(e){var t=[];Object.keys(e).forEach(function(n){var o=e[n];t=t.concat(o.connections)}),this.send({cmd:"connectiondebugpulse",type:"viewer",content:JSON.stringify({connectionsToPulse:t})})},EditorConnection.prototype.sendDebugInspectorValues=function(e){this.send({cmd:"debuginspectorvalues",type:"viewer",content:{inspectors:e}})},EditorConnection.prototype.sendConnectionValue=function(e,t){this.send({cmd:"connectionValue",type:"viewer",content:{connectionId:e,value:t}})};const dynamicPortsHash={};function _detectRename(e,t){if(!(!e||!t)&&e.length===t.length){for(var n={},o=0;o<e.length;o++){if(t.indexOf(e[o])===-1){if(n.before)return;n.before=e[o]}if(e.indexOf(t[o])===-1){if(n.after)return;n.after=t[o]}}return n.before&&n.after?n:void 0}}EditorConnection.prototype.sendDynamicPorts=function(e,t,n){var o=JSON.stringify(t);if(dynamicPortsHash[e]!==o){if(dynamicPortsHash[e]&&t&&n&&n.detectRenamed){var r=Array.isArray(n.detectRenamed)?n.detectRenamed:[n.detectRenamed],s=[];r.forEach(a=>{var l=JSON.parse(dynamicPortsHash[e]),u=[].concat(t);a.prefix&&(l=l.filter(h=>h.name.startsWith(a.prefix)),u=u.filter(h=>h.name.startsWith(a.prefix))),a.plug&&(l=l.filter(h=>h.plug===a.plug),u=u.filter(h=>h.plug===a.plug)),u=u.map(h=>h.name.substring((a.prefix||"").length)),l=l.map(h=>h.name.substring((a.prefix||"").length));var d=_detectRename(l,u);d&&s.push({plug:a.plug,patterns:[(a.prefix||"")+"{{*}}"],before:d.before,after:d.after})}),s.length>0&&(n.renamed=s),delete n.detectRenamed}dynamicPortsHash[e]=o,this.send({cmd:"instanceports",type:"viewer",content:JSON.stringify({nodeid:e,ports:t,options:n})})}},EditorConnection.prototype.sendWarning=function(e,t,n,o){this.activeWarnings.setWarning(t,n,o)&&this.send({cmd:"showwarning",type:"viewer",content:JSON.stringify({componentName:e,nodeId:t,key:n,warning:o})})},EditorConnection.prototype.clearWarning=function(e,t,n){this.activeWarnings.clearWarning(t,n)&&this.send({cmd:"showwarning",type:"viewer",content:JSON.stringify({componentName:e,nodeId:t,key:n,warning:void 0})})},EditorConnection.prototype.clearWarnings=function(e,t){this.activeWarnings.clearWarnings(t)&&this.send({cmd:"clearwarnings",type:"viewer",content:JSON.stringify({componentName:e,nodeId:t})})},EditorConnection.prototype.sendPatches=function(e){this.send({cmd:"patchproject",type:"viewer",content:JSON.stringify(e)})},EditorConnection.prototype.requestFullExport=function(){this.send({cmd:"register",type:"viewer"})},EditorConnection.prototype.requestNoodlModules=function(){this.send({cmd:"getNoodlModules",type:"viewer"})};var serviceRequests={};EditorConnection.prototype.sendServiceRequest=function(e,t){e.token=guid$1(),e.clientId=this.clientId,serviceRequests[e.token]=t,this.send(e)},EditorConnection.prototype.close=function(){this.reconnectOnClose=!1,this.isConnected()!==!1&&this.socket.close()},EditorConnection.prototype.sendNodeLibrary=function(e){this.send({cmd:"nodelibrary",type:"viewer",runtimeType:this.runtimeType,content:e,clientId:this.clientId})},EditorConnection.prototype.sendComponentMetadata=function(e,t,n){this.send({cmd:"componentMetadata",type:"viewer",content:JSON.stringify({componentName:e,key:t,data:n})})},EditorConnection.prototype.sendProjectMetadata=function(e,t){this.send({cmd:"projectMetadata",type:"viewer",content:JSON.stringify({key:e,data:t})})};function formatDynamicPorts(e){const t=[];for(const n of e.dynamicports)if(n.ports||n.template||n.port||n.channelPort)t.push(n);else if(n.inputs||n.outputs){const o=[];if(n.inputs)for(const s of n.inputs)o.push(formatPort(s,e.inputs[s],"input"));if(n.outputs)for(const s of n.outputs)o.push(formatPort(s,e.outputs[s],"output"));const r={name:n.name||"conditionalports/basic",condition:n.condition,ports:o};t.push(r)}return t}function formatPort(e,t,n){var o={name:e,type:t.type,plug:n};return t.group&&(o.group=t.group),t.displayName&&(o.displayName=t.displayName),t.description&&(o.description=t.description),t.editorName&&(o.editorName=t.editorName),t.default!==void 0&&(o.default=t.default),t.hasOwnProperty("index")&&(o.index=t.index),t.tooltip&&(o.tooltip=t.tooltip),t.tab&&(o.tab=t.tab),t.popout&&(o.popout=t.popout),t.allowVisualStates&&(o.allowVisualStates=t.allowVisualStates),o}function generateNodeLibrary(e){var t={typecasts:[{from:"string",to:["number","boolean","image","color","enum","textStyle","dimension","array","object"]},{from:"boolean",to:["number","string","signal"]},{from:"number",to:["boolean","string","dimension"]},{from:"date",to:["string"]},{from:"signal",to:["boolean","number"]},{from:"image",to:[]},{from:"cloudfile",to:["string","image"]},{from:"color",to:[]},{from:"enum",to:[]},{from:"object",to:[]},{from:"domelement",to:[]},{from:"reference",to:[]},{from:"font",to:[]},{from:"textStyle",to:["string"]},{from:"collection",to:["array"]},{from:"array",to:["collection"]}],dynamicports:[{type:"conditionalports",name:"basic"},{type:"expand",name:"basic"}],colors:{nodes:{component:{base:"#643D8B",baseHighlighted:"#79559b",header:"#4E2877",headerHighlighted:"#643d8b",outline:"#4E2877",outlineHighlighted:"#b58900",text:"#dbd0e4"},visual:{base:"#315272",baseHighlighted:"#4d6784",header:"#173E5D",headerHighlighted:"#315272",outline:"#173E5D",outlineHighlighted:"#b58900",text:"#cfd5de"},data:{base:"#465524",baseHighlighted:"#5b6a37",header:"#314110",headerHighlighted:"#465524",outline:"#314110",outlineHighlighted:"#b58900",text:"#d2d6c5"},javascript:{base:"#7E3660",baseHighlighted:"#944e74",header:"#67214B",headerHighlighted:"#7e3660",outline:"#67214B",outlineHighlighted:"#d57bab",text:"#e4cfd9"},default:{base:"#4C4F59",baseHighlighted:"#62656e",header:"#373B45",headerHighlighted:"#4c4f59",outline:"#373B45",outlineHighlighted:"#b58900",text:"#d3d4d6"}},connections:{signal:{normal:"#006f82",highlighted:"#7ec2cf",pulsing:"#ffffff"},default:{normal:"#875d00",highlighted:"#e5ae32",pulsing:"#ffffff"}}},nodetypes:[{name:"Component Children",shortDesc:"This node is a placeholder for where children of this component will be inserted.",docs:"https://docs.noodl.net/nodes/component-utilities/component-children",color:"component",allowAsChild:!0,category:"Visual",haveComponentChildren:["Visual"]}]},n=Object.keys(e._constructors);n.forEach(function(s){var a=e._constructors[s].metadata,l={name:s,searchTags:a.searchTags};t.nodetypes.push(l),a.version&&(l.version=a.version),a.displayNodeName&&(l.displayNodeName=a.displayNodeName),a.nodeDoubleClickAction&&(l.nodeDoubleClickAction=a.nodeDoubleClickAction),a.shortDesc&&(l.shortDesc=a.shortDesc),a.module&&(l.module=a.module),a.deprecated&&(l.deprecated=!0),a.haveComponentPorts&&(l.haveComponentPorts=!0),a.category==="Visual"&&(l.allowAsChild=!0,l.allowAsExportRoot=!0,l.color="visual"),a.allowAsExportRoot!==void 0&&(l.allowAsExportRoot=a.allowAsExportRoot),a.allowChildren&&(l.allowChildrenWithCategory=["Visual"],l.color="visual"),a.allowChildrenWithCategory&&(l.allowChildrenWithCategory=a.allowChildrenWithCategory),a.singleton&&(l.singleton=!0),a.allowAsChild&&(l.allowAsChild=!0),a.docs&&(l.docs=a.docs),a.shortDocs?l.shortDocs=a.shortDocs:a.docs&&a.docs.indexOf("https://docs.noodl.net")===0&&(l.shortDocs=a.docs.replace("/#","")+"-short.md"),l.category=a.category,a.panels&&(l.panels=a.panels),a.usePortAsLabel&&(l.usePortAsLabel=a.usePortAsLabel,l.portLabelTruncationMode=a.portLabelTruncationMode),a.color&&(l.color=a.color),a.dynamicports&&(l.dynamicports=formatDynamicPorts(a)),a.exportDynamicPorts&&(l.exportDynamicPorts=a.exportDynamicPorts),a.visualStates&&(l.visualStates=a.visualStates),a.useVariants&&(l.useVariants=a.useVariants),a.connectionPanel&&(l.connectionPanel=a.connectionPanel),l.ports=[];var u=l.dynamicports||[],d={},h={};u.filter(g=>g.channelPort!==void 0).forEach(g=>{h[g.channelPort.plug+"/"+g.channelPort.name]=!0}),u.length&&(l.dynamicports=u),Object.keys(a.inputs).forEach(function(g){if(!(d.hasOwnProperty("input/"+g)||h.hasOwnProperty("input/"+g))){var b=a.inputs[g];b.exportToEditor!==!1&&l.ports.push(formatPort(g,b,"input"))}});function f(g,b){var _={name:g,type:b.type,plug:"output"};b.group&&(_.group=b.group),b.displayName&&(_.displayName=b.displayName),b.editorName&&(_.editorName=b.editorName),b.hasOwnProperty("index")&&(_.index=b.index),l.ports.push(_)}Object.keys(a.outputs).forEach(function(g){if(!(d.hasOwnProperty("output/"+g)||h.hasOwnProperty("output/"+g))){var b=a.outputs[g];f(g,b)}})});const o=[{name:"UI Elements",description:"Buttons, inputs, containers, media",type:"visual",subCategories:[{name:"Basic Elements",items:["Group","net.noodl.visual.columns","Text","Image","Video","Circle","net.noodl.visual.icon"]},{name:"UI Controls",items:["net.noodl.controls.button","net.noodl.controls.checkbox","net.noodl.controls.options","net.noodl.controls.radiobutton","Radio Button Group","net.noodl.controls.range","net.noodl.controls.textinput"]}]},{name:"Navigation & Popups",description:"Page routing, navigation, popups",type:"logic",subCategories:[{name:"Navigation",items:["Router","RouterNavigate","PageInputs","net.noodl.externallink","PageStackNavigateToPath"]},{name:"Component Stack",items:["Page Stack","PageStackNavigate","PageStackNavigateBack"]},{name:"Popups",items:["NavigationShowPopup","NavigationClosePopup"]}]},{name:"Logic & Utilities",description:"Logic, events, string manipulation",type:"logic",subCategories:[{name:"General Utils",items:["States","Value Changed","Timer","Color Blend","Number Remapper","Counter","Drag","net.noodl.animatetovalue"]},{name:"Logic",items:["Boolean To String","Switch","And","Or","Condition","Inverter"]},{name:"Events",items:["Event Sender","Event Receiver"]},{name:"String Manipulation",items:["Substring","String Mapper","String Format","Date To String","Unique Id"]},{name:"System",items:["Screen Resolution","Open File Picker"]},{name:"Variables",items:["String","Boolean","Color","Number"]}]},{name:"Component Utilities",description:"Component inputs, outputs & object",type:"component",subCategories:[{name:"",items:["Component Inputs","Component Outputs","Component Children","net.noodl.ComponentObject","net.noodl.ParentComponentObject","net.noodl.SetComponentObjectProperties","net.noodl.SetParentComponentObjectProperties"]}]},{name:"Read & Write Data",description:"Arrays, objects, cloud data",type:"data",subCategories:[{name:"",items:["RunTasks","For Each","For Each Actions","Model2","SetModelProperties","NewModel","Set Variable","Variable2"]},{name:"Array",items:["Collection2","CollectionNew","CollectionRemove","CollectionClear","CollectionInsert","Filter Collection","Map Collection","Static Data"]},{name:"Cloud Data",items:["DbModel2","NewDbModelProperties","FilterDBModels","SetDbModelProperties","DbCollection2","DeleteDbModelProperties","AddDbModelRelation","RemoveDbModelRelation","Cloud File","Upload File","CloudFunction2","DbConfig"]},{name:"User",items:["net.noodl.user.LogIn","net.noodl.user.LogOut","net.noodl.user.SignUp","net.noodl.user.User","net.noodl.user.SetUserProperties","net.noodl.user.VerifyEmail","net.noodl.user.SendEmailVerification","net.noodl.user.ResetPassword","net.noodl.user.RequestPasswordReset"]},{name:"External Data",items:["REST2"]}]},{name:"Custom Code",description:"Custom JavaScript and CSS",type:"javascript",subCategories:[{name:"",items:["Expression","JavaScriptFunction","Javascript2","CSS Definition"]}]},{name:"Cloud Functions",description:"Nodes to be used in cloud functions",type:"data",subCategories:[{name:"",items:["noodl.cloud.request","noodl.cloud.response"]},{name:"Cloud Data",items:["noodl.cloud.aggregate"]}]}];t.nodeIndex={coreNodes:o};const r=[];return n.forEach(s=>{e._constructors[s].metadata.module&&r.push(s)}),r.length&&(t.nodeIndex.moduleNodes=[{name:"",items:r}]),t}function addModuleSettings(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.settings&&o.settings.forEach(function(r){e.ports.push(r)})}}function generateProjectSettings(e,t){const n={dynamicports:[],ports:[]};return addModuleSettings(n,t),n}function NodeModel(e,t){EventSender$2.call(this),this.id=e,this.type=t,this.inputs=[],this.outputs=[],this.children=[],this.parameters={},this.inputPorts={},this.outputPorts={}}NodeModel.prototype=Object.create(EventSender$2.prototype),NodeModel.prototype.setParameter=function(e,t,n){n?(this.stateParameters||(this.stateParameters={}),this.stateParameters[n]||(this.stateParameters[n]={}),t===void 0?delete this.stateParameters[n][e]:this.stateParameters[n][e]=t):t===void 0?delete this.parameters[e]:this.parameters[e]=t,this.emit("parameterUpdated",{name:e,value:t,state:n})},NodeModel.prototype.setParameters=function(e){Object.keys(e).forEach(t=>{this.setParameter(t,e[t])})},NodeModel.prototype.setStateParameters=function(e){this.stateParameters=e},NodeModel.prototype.setStateTransitions=function(e){this.stateTransitions=e},NodeModel.prototype.setStateTransitionParamter=function(e,t,n){this.stateTransitions||(this.stateTransitions={}),t?this.stateTransitions[n][e]=t:delete this.stateTransitions[n][e]},NodeModel.prototype.setDefaultStateTransition=function(e,t){this.defaultStateTransitions||(this.defaultStateTransitions={}),this.defaultStateTransitions[t]=e},NodeModel.prototype.addInputPort=function(e){this.inputPorts[e.name]=e,this.emit("inputPortAdded",e)},NodeModel.prototype.getInputPort=function(e){return this.inputPorts[e]},NodeModel.prototype.getInputPorts=function(){return this.inputPorts},NodeModel.prototype.removeInputPortWithName=function(e){if(this.inputPorts.hasOwnProperty(e)){var t=this.inputPorts[e];delete this.inputPorts[e],this.emit("inputPortRemoved",t)}},NodeModel.prototype.updateInputPortTypes=function(e){var t=!1;for(var n in e)this.inputPorts[n]!==void 0&&(this.inputPorts[n].type=e[n].type,t=!0);t&&this.emit("inputPortTypesUpdated")},NodeModel.prototype.addOutputPort=function(e){this.outputPorts[e.name]=e,this.emit("outputPortAdded",e)},NodeModel.prototype.getOutputPort=function(e){return this.outputPorts[e]},NodeModel.prototype.getOutputPorts=function(){return this.outputPorts},NodeModel.prototype.removeOutputPortWithName=function(e){if(this.outputPorts.hasOwnProperty(e)){var t=this.outputPorts[e];delete this.outputPorts[e],this.emit("outputPortRemoved",t)}},NodeModel.prototype.updateOutputPortTypes=function(e){var t=!1;for(var n in e)this.outputPorts[n]!==void 0&&(this.outputPorts[n].type=e[n].type,t=!0);t&&this.emit("outputPortTypesUpdated")},NodeModel.prototype.addChild=function(e,t){e.parent=this,t===void 0?this.children.push(e):this.children.splice(t,0,e),this.emit("childAdded",e)},NodeModel.prototype.removeChild=function(e){e.parent=void 0;var t=this.children.indexOf(e);this.children.splice(t,1),this.emit("childRemoved",e)},NodeModel.prototype.reset=function(){this.removeAllListeners()},NodeModel.prototype.setVariant=function(e){this.variant=e,this.emit("variantUpdated",e)},NodeModel.createFromExportData=function(e){var t=new NodeModel(e.id,e.type);if(e.parameters&&t.setParameters(e.parameters),e.stateParameters&&t.setStateParameters(e.stateParameters),e.stateTransitions&&t.setStateTransitions(e.stateTransitions),e.defaultStateTransitions)for(const n in e.defaultStateTransitions)t.setDefaultStateTransition(e.defaultStateTransitions[n],n);return e.ports&&e.ports.forEach(function(n){n.plug==="outputs"&&(n.plug="output"),(n.plug==="input"||n.plug==="input/output")&&t.addInputPort(n),(n.plug==="output"||n.plug==="input/output")&&t.addOutputPort(n)}),e.variant&&t.setVariant(e.variant),t};function ComponentModel(e){EventSender$2.call(this),this.name=e,this.nodes=[],this.connections=[],this.roots=[],this.inputPorts={},this.outputPorts={},this.metadata={}}ComponentModel.prototype=Object.create(EventSender$2.prototype),ComponentModel.prototype.addNode=async function(e){e.component=this,this.nodes[e.id]=e,await this.emit("nodeAdded",e)},ComponentModel.prototype.hasNodeWithId=function(e){return this.getNodeWithId(e)!==void 0},ComponentModel.prototype.getNodeWithId=function(e){return this.nodes[e]},ComponentModel.prototype.getAllNodes=function(){return Object.values(this.nodes)},ComponentModel.prototype.getNodesWithType=function(e){var t=[],n=this;return Object.keys(this.nodes).forEach(function(o){var r=n.nodes[o];r.type===e&&t.push(r)}),t},ComponentModel.prototype.addConnection=function(e){if(this.connections.push(e),this.emit("connectionAdded",e),e.targetId){const t=this.getNodeWithId(e.targetId);t&&t.emit("inputConnectionAdded",e)}},ComponentModel.prototype.removeConnection=function(e){const t=this.connections.findIndex(n=>n.sourceId===e.sourceId&&n.sourcePort===e.sourcePort&&n.targetId===e.targetId&&n.targetPort===e.targetPort);if(t===-1){console.log("Connection doesn't exist",e);return}if(this.connections.splice(t,1),this.emit("connectionRemoved",e),e.targetId){const n=this.getNodeWithId(e.targetId);n&&n.emit("inputConnectionRemoved",e)}},ComponentModel.prototype.getConnectionsFromPort=function(e,t){return this.connections.filter(function(n){return n.sourceId===e&&n.sourcePort===t})},ComponentModel.prototype.getConnectionsToPort=function(e,t){return this.connections.filter(function(n){return n.targetId===e&&n.targetPort===t})},ComponentModel.prototype.getConnectionsFrom=function(e){return this.connections.filter(function(t){return t.sourceId===e})},ComponentModel.prototype.getConnectionsTo=function(e){return this.connections.filter(function(t){return t.targetId===e})},ComponentModel.prototype.addRootId=function(e){this.roots.indexOf(e)===-1&&(this.roots.push(e),this.emit("rootAdded",e))},ComponentModel.prototype.removeRootId=function(e){const t=this.roots.indexOf(e);t!==-1&&(this.roots.splice(t,1),this.emit("rootRemoved",e))},ComponentModel.prototype.getRoots=function(){return this.roots},ComponentModel.prototype.removeNodeWithId=async function(e){const t=this.getNodeWithId(e);if(!t)return console.warn("ERROR: Attempted to remove non-existing node with ID:",e),!1;for(;t.children.length>0;){const o=t.children[0];await this.removeNodeWithId(o.id)||t.children.shift()}const n=this.getConnectionsTo(e).concat(this.getConnectionsFrom(e));for(let o=0;o<n.length;o++)this.removeConnection(n[o]);return this.setNodeParent(t,null),this.roots.indexOf(t.id)!==-1&&this.removeRootId(t.id),await this.emit("nodeRemoved",t),t.removeAllListeners(),delete this.nodes[e],await this.emit("nodeWasRemoved",t),!0},ComponentModel.prototype.getAllConnections=function(){return this.connections},ComponentModel.prototype.getInputPorts=function(){return this.inputPorts},ComponentModel.prototype.getOutputPorts=function(){return this.outputPorts},ComponentModel.prototype.addInputPort=function(e){this.inputPorts[e.name]=e,this.emit("inputPortAdded",e)},ComponentModel.prototype.addOutputPort=function(e){this.outputPorts[e.name]=e,this.emit("outputPortAdded",e)},ComponentModel.prototype.removeOutputPortWithName=function(e){if(this.outputPorts.hasOwnProperty(e)){var t=this.outputPorts[e];delete this.outputPorts[e],this.emit("outputPortRemoved",t)}},ComponentModel.prototype.removeInputPortWithName=function(e){if(this.inputPorts.hasOwnProperty(e)){var t=this.inputPorts[e];delete this.inputPorts[e],this.emit("inputPortRemoved",t)}},ComponentModel.prototype.updateInputPortTypes=function(e){var t=!1;for(var n in e)this.inputPorts[n]!==void 0&&(this.inputPorts[n].type=e[n].type,t=!0);t&&this.emit("inputPortTypesUpdated")},ComponentModel.prototype.updateOutputPortTypes=function(e){var t=!1;for(var n in e)this.outputPorts[n]!==void 0&&(this.outputPorts[n].type=e[n].type,t=!0);t&&this.emit("outputPortTypesUpdated")},ComponentModel.prototype.renameInputPortOnNodeWithId=function(e,t,n){var o=this.getConnectionsToPort(e,t);o.forEach(this.removeConnection.bind(this));var r=this.getNodeWithId(e),s={...r.getInputPort(t)};s&&(r.removeInputPortWithName(t),s.name=n,r.addInputPort(s)),o.forEach(function(a){a.targetPort=n}),o.forEach(this.addConnection.bind(this))},ComponentModel.prototype.renameOutputPortOnNodeWithId=function(e,t,n){var o=this.getConnectionsFromPort(e,t);o.forEach(this.removeConnection.bind(this));var r=this.getNodeWithId(e),s={...r.getOutputPort(t)};r.removeOutputPortWithName(t),s.name=n,r.addOutputPort(s),o.forEach(function(a){a.sourcePort=n}),o.forEach(this.addConnection.bind(this))},ComponentModel.prototype.setNodeParent=function(e,t,n){this.roots.indexOf(e.id)!==-1&&this.removeRootId(e.id),e.parent&&(this.emit("nodeParentWillBeRemoved",e),e.parent.removeChild(e)),e.emit("parentUpdated",t),t&&(t.addChild(e,n),this.emit("nodeParentUpdated",e))},ComponentModel.prototype.importEditorNodeData=async function(e,t,n){var o=NodeModel.createFromExportData(e);if(await this.addNode(o),t&&this.setNodeParent(o,this.getNodeWithId(t),n),e.children)for(let r=0;r<e.children.length;r++){const s=e.children[r];await this.importEditorNodeData(s,o.id,r)}},ComponentModel.prototype.reset=async function(){for(;this.roots.length;)await this.removeNodeWithId(this.roots[0]);for(const e of this.nodes)this.hasNodeWithId(e)&&await this.removeNodeWithId(e);if(this.nodes.length>0)throw new Error("Not all nodes were removed during a reset");if(this.connections.length>0)throw new Error("Not all connections were removed during a reset")},ComponentModel.prototype.rename=function(e){var t=this.name;this.name=e,this.emit("renamed",{oldName:t,newName:e})},ComponentModel.prototype.setMetadata=function(e,t){this.metadata[e]=t},ComponentModel.prototype.getMetadata=function(e){return e?this.metadata[e]:this.metadata},ComponentModel.createFromExportData=async function(e){var t=new ComponentModel(e.name);if(e.metadata)for(const n in e.metadata)t.setMetadata(n,e.metadata[n]);if(e.ports&&e.ports.forEach(function(n){(n.plug==="input"||n.plug==="input/output")&&t.addInputPort(n),(n.plug==="output"||n.plug==="input/output")&&t.addOutputPort(n)}),e.nodes)for(const n of e.nodes)await t.importEditorNodeData(n);return e.connections&&e.connections.forEach(n=>t.addConnection(n)),e.roots&&e.roots.forEach(n=>t.addRootId(n)),t};function GraphModel(){EventSender$2.call(this),this.components={},this.settings={},this.metadata={}}GraphModel.prototype=Object.create(EventSender$2.prototype),GraphModel.prototype.importComponentFromEditorData=async function(e){var t=await ComponentModel.createFromExportData(e);this.addComponent(t)},GraphModel.prototype.getBundleContainingComponent=function(e){return this.componentToBundleMap.get(e)},GraphModel.prototype.getBundlesContainingSheet=function(e){const t=new Set;for(const n of this.componentToBundleMap.keys()){const o=n.indexOf("/#")!==0;(o&&e==="Default"||!o&&n.indexOf("/#"+e)===0)&&t.add(this.componentToBundleMap.get(n))}return Array.from(t)},GraphModel.prototype.getBundleDependencies=function(e){const t=new Set,n=o=>{const r=this.componentIndex[o];for(const s of r.dependencies)t.has(s)||(t.add(s),n(s))};return n(e),Array.from(t)},GraphModel.prototype.importEditorData=async function(e){this.componentIndex=e.componentIndex,this.routerIndex=e.routerIndex,this.componentToBundleMap=new Map;for(const t in e.componentIndex){const n=e.componentIndex[t];for(const o of n.components)this.componentToBundleMap.set(o,t)}this.variants=e.variants||[],e.settings&&this.setSettings(e.settings),e.metadata&&this.setAllMetaData(e.metadata);for(const t of e.components)await this.importComponentFromEditorData(t);this.setRootComponentName(e.rootComponent)},GraphModel.prototype.setRootComponentName=function(e){this.rootComponent=e,this.emit("rootComponentNameUpdated",e)},GraphModel.prototype.getNodesWithType=function(e){for(var t=[],n=Object.keys(this.components),o=0;o<n.length;o++){var r=this.components[n[o]];t=t.concat(r.getNodesWithType(e))}return t},GraphModel.prototype.getComponentWithName=function(e){return this.components[e]},GraphModel.prototype.hasComponentWithName=function(e){return!!this.components[e]},GraphModel.prototype.getAllComponents=function(){return Object.keys(this.components).map(e=>this.components[e])},GraphModel.prototype.getAllNodes=function(){for(var e=[],t=Object.keys(this.components),n=0;n<t.length;n++){var o=this.components[t[n]];e=e.concat(o.getAllNodes())}return e},GraphModel.prototype.addComponent=function(e){this.components[e.name]=e,this.getNodesWithType(e.name).forEach(this._addComponentPorts.bind(this)),e.getAllNodes().forEach(this._onNodeAdded.bind(this)),e.on("nodeAdded",this._onNodeAdded.bind(this),this),e.on("nodeRemoved",this._onNodeRemoved.bind(this),this),e.on("nodeWasRemoved",this._onNodeWasRemoved.bind(this),this),this.emit("componentAdded",e)},GraphModel.prototype.removeComponentWithName=async function(e){if(this.components.hasOwnProperty(e)===!1){console.error("GraphModel: Component with name "+e+" not in graph");return}var t=this.components[e];await t.reset(),t.removeAllListeners(),delete this.components[t.name],this.emit("componentRemoved",t)},GraphModel.prototype.renameComponent=function(e,t){if(this.components.hasOwnProperty(e)===!1){console.error("GraphModel: Component with name "+e+" not in graph");return}this.getNodesWithType(e).forEach(function(o){o.type=t});var n=this.components[e];n.rename(t),delete this.components[e],this.components[t]=n,this.emit("componentRenamed",n)},GraphModel.prototype._addComponentPorts=function(e){if(this.components.hasOwnProperty(e.type)){var t=this.components[e.type];const n=t.getInputPorts(),o=t.getOutputPorts();Object.keys(n).forEach(r=>{e.addInputPort(n[r])}),Object.keys(o).forEach(r=>{e.addOutputPort(o[r])})}},GraphModel.prototype._onNodeAdded=function(e){this._addComponentPorts(e),this.emit("nodeAdded",e),this.emit("nodeAdded."+e.type,e)},GraphModel.prototype._onNodeRemoved=function(e){this.emit("nodeRemoved",e),this.emit("nodeRemoved."+e.type,e)},GraphModel.prototype._onNodeWasRemoved=function(e){this.emit("nodeWasRemoved",e),this.emit("nodeWasRemoved."+e.type,e)},GraphModel.prototype.reset=async function(){for(const e of Object.keys(this.components))await this.removeComponentWithName(e);this.setSettings({})},GraphModel.prototype.isEmpty=function(){return Object.keys(this.components).length===0},GraphModel.prototype.setSettings=function(e){this.settings=e,this.emit("projectSettingsChanged",e)},GraphModel.prototype.getSettings=function(){return this.settings},GraphModel.prototype.setAllMetaData=function(e){for(const t in e)this.setMetaData(t,e[t])},GraphModel.prototype.setMetaData=function(e,t){this.metadata[e]&&JSON.stringify(this.metadata[e])===JSON.stringify(t)||(this.metadata[e]=t,this.emit("metadataChanged",{key:e,data:t}),this.emit("metadataChanged."+e,t))},GraphModel.prototype.getMetaData=function(e){return e?this.metadata[e]:this.metadata},GraphModel.prototype.getVariants=function(){return this.variants||[]},GraphModel.prototype.getVariant=function(e,t){return this.variants.find(n=>n.name===t&&n.typename===e)},GraphModel.prototype.updateVariant=function(e){const t=this.variants.findIndex(n=>n.name===e.name&&n.typename===e.typename);t!==-1&&this.variants.splice(t,1),this.variants.push(e),this.emit("variantUpdated",e)},GraphModel.prototype.updateVariantParameter=function(e,t,n,o,r){const s=this.getVariant(t,e);if(!s){console.log("updateVariantParameter: can't find variant",e,t);return}r?(s.stateParameters.hasOwnProperty(r)||(s.stateParameters[r]={}),o===void 0?delete s.stateParameters[r][n]:s.stateParameters[r][n]=o):o===void 0?delete s.parameters[n]:s.parameters[n]=o,this.emit("variantUpdated",s)},GraphModel.prototype.updateVariantDefaultStateTransition=function(e,t,n,o){const r=this.getVariant(t,e);r&&(r.defaultStateTransitions[o]=n,this.emit("variantUpdated",r))},GraphModel.prototype.updateVariantStateTransition=function(e){const{variantTypeName:t,variantName:n,state:o,parameterName:r,curve:s}=e,a=this.getVariant(t,n);a&&(a.stateTransitions[o]||(a.stateTransitions[o]={}),a.stateTransitions[o][r]=s)},GraphModel.prototype.deleteVariant=function(e,t){const n=this.variants.findIndex(o=>o.name===t&&o.typename===e);n!==-1&&this.variants.splice(n,1)};function createSetter(e){var t=!1;return function(n){n=!!n,n&&t===!1&&e.valueChangedToTrue.call(this),t=n}}const EdgeTriggeredInput=Object.freeze(Object.defineProperty({__proto__:null,createSetter},Symbol.toStringTag,{value:"Module"}));function createNodeConstructor(e){const t=class extends Node{constructor(n,o){super(n,o)}getInspectInfo(){return e.getInspectInfo?.call(this)??void 0}nodeScopeDidInitialize(){return e.nodeScopeDidInitialize?.call(this)??void 0}};return e.prototypeExtensions&&Object.defineProperties(t.prototype,e.prototypeExtensions),Object.defineProperty(t.prototype,"name",{value:e.name}),t}function registerInput(e,t,n,o){if(e.hasOwnProperty(n))throw new Error("Input property "+n+" already registered");!o.set&&!o.valueChangedToTrue&&(o.set=()=>{}),o.set&&(e[n]={set:o.set},["color","textStyle","array"].forEach(r=>{o.type&&(o.type===r||o.type.name===r)&&(e[n].type=r)})),o.setUnitType&&(e[n].setUnitType=o.setUnitType),t.inputs[n]={displayName:o.displayName,editorName:o.editorName,group:o.group,type:o.type,default:o.default,index:o.index,exportToEditor:o.hasOwnProperty("exportToEditor")?o.exportToEditor:!0,inputPriority:o.inputPriority||0,tooltip:o.tooltip,tab:o.tab,popout:o.popout,allowVisualStates:o.allowVisualStates,nodeDoubleClickAction:o.nodeDoubleClickAction},o.valueChangedToTrue&&(t.inputs[n].type={name:"signal",allowConnectionsOnly:!0})}function registerInputs(e,t,n){Object.keys(n).forEach(function(o){registerInput(e,t,o,n[o])})}function registerNumberedInputs(e,t){for(const n of Object.keys(t))registerNumberedInput(e,n,t[n])}function registerNumberedInput(e,t,n){const o=e.registerInputIfNeeded;e.registerInputIfNeeded=function(r){if(o&&o.call(e,r),e.hasInput(r)||!r.startsWith(t))return;const s=Number(r.slice(t.length+1));e.registerInput(r,{type:n.type,set:n.createSetter.call(e,s)})}}function registerOutputsMetadata(e,t){Object.keys(t).forEach(function(n){var o=t[n];e.outputs[n]={displayName:o.displayName,editorName:o.editorName,group:o.group,type:o.type,index:o.index,exportToEditor:o.hasOwnProperty("exportToEditor")?o.exportToEditor:!0}})}function initializeDefaultValues(e,t){Object.keys(t).forEach(n=>{const o=t[n].default;o!==void 0&&(t[n].type.defaultUnit?e[n]={unit:t[n].type.defaultUnit,value:o}:e[n]=o)})}function defineNode(e){if(!e.category)throw new Error("Node must have a category");if(!e.name)throw new Error("Node must have a name");const t={inputs:{},outputs:{},category:e.category,dynamicports:e.dynamicports,exportDynamicPorts:e.exportDynamicPorts,useVariants:e.useVariants,allowChildren:e.allowChildren,allowChildrenWithCategory:e.allowChildrenWithCategory,singleton:e.singleton,connectionPanel:e.connectionPanel,allowAsChild:e.allowAsChild,visualStates:e.visualStates,panels:e.panels,color:e.color,usePortAsLabel:e.usePortAsLabel,portLabelTruncationMode:e.portLabelTruncationMode,name:e.name,displayNodeName:e.displayNodeName||e.displayName,deprecated:e.deprecated,haveComponentPorts:e.haveComponentPorts,version:e.version,module:e.module,docs:e.docs,allowAsExportRoot:e.allowAsExportRoot,nodeDoubleClickAction:e.nodeDoubleClickAction,searchTags:e.searchTags};e._internal=e._internal||{},e.prototypeExtensions=e.methods||e.prototypeExtensions||{},e.inputs=e.inputs||{},e.outputs=e.outputs||{},e.initialize=e.initialize||function(){};let n={};registerInputs(n,t,e.inputs),registerOutputsMetadata(t,e.outputs),Object.keys(e.prototypeExtensions).forEach(function(s){e.prototypeExtensions[s].value||(e.prototypeExtensions[s]={value:e.prototypeExtensions[s]})});const o=createNodeConstructor({name:e.name,getInspectInfo:e.getInspectInfo,nodeScopeDidInitialize:e.nodeScopeDidInitialize,prototypeExtensions:e.prototypeExtensions}),r=function(s,a,l){const u=new o(s,a);return u._inputs=Object.create(n),Object.keys(e.inputs).forEach(function(d){var h=e.inputs[d];h.valueChangedToTrue&&(u._inputs[d]={set:createSetter({valueChangedToTrue:h.valueChangedToTrue})})}),Object.keys(e.outputs).forEach(function(d){var h=e.outputs[d];h.type==="signal"?u.registerOutput(d,{getter(){}}):u.registerOutput(d,h)}),e.numberedInputs&&registerNumberedInputs(u,e.numberedInputs),u.nodeScope=l,initializeDefaultValues(u._inputValues,t.inputs),e.initialize.call(u),u};return r.metadata=t,e.numberedInputs&&registerSetupFunctionForNumberedInputs(r,e.name,e.numberedInputs),r}function registerSetupFunctionForNumberedInputs(e,t,n){const o=Object.keys(n);o.length&&(e.setupNumberedInputDynamicPorts=function(r,s){const a=r.editorConnection;if(!a||!a.isRunningLocally())return;function l(d,h,f){const g=d.component.getConnectionsTo(d.id).map(A=>A.targetPort),b=Object.keys(d.parameters).concat(g).filter(A=>A.startsWith(h+" ")),_=(b.length?1+Math.max(...b.map(A=>Number(A.slice(h.length+1)))):0)+1,T=[];for(let A=0;A<_;A++){const v={name:h+" "+A,displayName:(f.displayPrefix||h)+" "+A,type:f.type,plug:"input",group:f.group};f.hasOwnProperty("index")&&(v.index=f.index+A),T.push(v)}return T}function u(d){const h=o.map(f=>l(d,f,n[f])).flat();a.sendDynamicPorts(d.id,h)}s.on("nodeAdded."+t,d=>{u(d),d.on("parameterUpdated",()=>{u(d)}),d.on("inputConnectionAdded",()=>{u(d)}),d.on("inputConnectionRemoved",()=>{u(d)})})})}function extend$4(e,t){for(var n in t)if(n==="initialize"&&e.initialize){var o=e.initialize;e.initialize=function(){o.call(this),t.initialize.call(this)}}else t[n]&&t[n].constructor===Object?e[n]=extend$4(e[n]||{},t[n]):t[n]&&t[n].constructor===Array&&e[n]&&e[n].constructor==Array?e[n]=e[n].concat(t[n]):e[n]=t[n];return e}function difference$1(e,t){const n=new Set(t);return e.filter(o=>!n.has(o))}async function handleEvent(e,t,n){function o(l,u){var d={},h={};u.forEach(function(v){v&&v.plug==="outputs"&&(v.plug="output"),(v.plug==="input"||v.plug==="input/output")&&(d[v.name]=v),(v.plug==="output"||v.plug==="input/output")&&(h[v.name]=v)});var f=Object.keys(l.getInputPorts()),g=difference$1(f,Object.keys(d)),b=difference$1(Object.keys(d),f);l.updateInputPortTypes(d),g.forEach(l.removeInputPortWithName.bind(l)),b.forEach(function(v){l.addInputPort(d[v]),l.parameters&&l.parameters.hasOwnProperty(v)&&r(e.rootComponent.nodeScope,l,v,l.parameters[v])}),l.updateOutputPortTypes(h);var _=Object.keys(l.getOutputPorts()),T=difference$1(_,Object.keys(h)),A=difference$1(Object.keys(h),_);T.forEach(l.removeOutputPortWithName.bind(l)),A.forEach(function(v){l.addOutputPort(h[v])})}function r(l,u,d,h){var f=l.getNodesWithIdRecursive(u.id);f.forEach(function(g){g.queueInput(d,h)})}var s;if(!(n.componentName&&(s=t.getComponentWithName(n.componentName),!s))){n.port&&n.port.plug==="outputs"&&(n.port.plug="output");var a={nodeAdded(l){s.importEditorNodeData(l.model,l.parentId,l.childIndex)},nodeRemoved:async function(l){s.hasNodeWithId(l.model.id)&&await s.removeNodeWithId(l.model.id)},connectionAdded(l){s.addConnection(l.model)},connectionRemoved(l){s.removeConnection(l.model);var u=s.getNodeWithId(l.model.targetId);if(s.getConnectionsToPort(u.id,l.model.targetId).length===0){var d=u.parameters[l.model.targetPort];d===void 0&&(d=e.getDefaultValueForInput(u.type,l.model.targetPort)),r(e.rootComponent.nodeScope,u,l.model.targetPort,d)}},parameterChanged(l){const u=s.getNodeWithId(l.nodeId);if(u===void 0){console.log("parameterChanged: Unknown node id",l);return}if(l.parameters){const d=new Set(Object.keys(l.parameters).concat(Object.keys(l.oldParameters)));for(const h of d)u.setParameter(h,l.parameters[h])}l.parameterName&&u.setParameter(l.parameterName,l.parameterValue,l.state)},nodeAttached(l){s.setNodeParent(s.getNodeWithId(l.nodeId),s.getNodeWithId(l.parentId),l.childIndex)},nodeDetached(l){s.setNodeParent(s.getNodeWithId(l.nodeId),null),s.addRootId(l.nodeId)},componentAdded(l){t.importComponentFromEditorData(l.model)},componentRemoved:async function(l){await t.removeComponentWithName(l.componentName)},rootAdded(l){s.addRootId(l.nodeId)},portAdded(l){var u=s.getNodeWithId(l.nodeId);(l.port.plug==="input"||l.port.plug==="input/output")&&(u.addInputPort(l.port),u.parameters.hasOwnProperty(l.port)&&r(e.rootComponent.nodeScope,u,l.port,u.parameters[l.port])),(l.port.plug==="output"||l.port.plug==="input/output")&&u.addOutputPort(l.port)},portRemoved(l){var u=s.getNodeWithId(l.nodeId);(l.port.plug==="input"||l.port.plug==="input/output")&&u.removeInputPortWithName(l.port.name),(l.port.plug==="output"||l.port.plug==="input/output")&&u.removeOutputPortWithName(l.port.name)},nodePortRenamed(l){(l.port.plug==="input"||l.port.plug==="input/output")&&s.renameInputPortOnNodeWithId(l.nodeId,l.oldName,l.port.name),(l.port.plug==="output"||l.port.plug==="input/output")&&s.renameOutputPortOnNodeWithId(l.nodeId,l.oldName,l.port.name);var u=s.getNodeWithId(l.nodeId);u.type==="Component Inputs"?(s.addInputPort(l.port),t.getNodesWithType(s.name).forEach(function(d){d.component.renameInputPortOnNodeWithId(d.id,l.oldName,l.port.name)}),s.removeInputPortWithName(l.oldName)):u.type==="Component Outputs"&&(s.addOutputPort(l.port),t.getNodesWithType(s.name).forEach(function(d){d.component.renameOutputPortOnNodeWithId(d.id,l.oldName,l.port.name)}),s.removeOutputPortWithName(l.oldName))},componentPortsUpdated(l){o(s,l.ports)},instancePortsChanged(l){if(s.hasNodeWithId(l.nodeId)){var u=s.getNodeWithId(l.nodeId);o(u,l.ports)}},componentRenamed(l){t.renameComponent(l.oldName,l.newName)},settingsChanged(l){t.setSettings(l.settings)},metadataChanged(l){t.setMetaData(l.key,l.data)},componentMetadataChanged(l){const u=t.getComponentWithName(l.componentName);u&&u.setMetadata(l.key,l.data)},variantParametersChanged(l){if(l.variant)t.updateVariant(l.variant);else if(t.updateVariantParameter(l.variantName,l.variantTypeName,l.parameterName,l.parameterValue,l.state),l.parameterValue===void 0){const u=t.getVariant(l.variantTypeName,l.variantName);e.rootComponent.nodeScope.getAllNodesWithVariantRecursive(u).forEach(d=>{d.queueInput(l.parameterName,d.getParameter(l.parameterName))})}},variantDeleted(l){t.deleteVariant(l.variantTypeName,l.variantName)},variantChanged(l){const u=s.getNodeWithId(l.nodeId),d=t.getVariant(u.type,l.variantName);u.setVariant(d)},variantRenamed(l){const u=t.getVariant(l.variantTypeName,l.oldVariantName);u&&(u.name=u.variantName)},defaultStateTransitionChanged(l){s.getNodeWithId(l.nodeId).setDefaultStateTransition(l.curve,l.state)},stateTransitionsChanged(l){const u=s.getNodeWithId(l.nodeId);l.parameterName&&u.setStateTransitionParamter(l.parameterName,l.curve,l.state)},variantDefaultStateTransitionChanged(l){t.updateVariantDefaultStateTransition(l.variantName,l.variantTypeName,l.curve,l.state)},variantStateTransitionsChanged(l){t.updateVariantStateTransition(l)},routerIndexChanged(l){t.routerIndex=l.data}};a.hasOwnProperty(n.type)?(await a[n.type](n),e.scheduleUpdate()):console.log("Unknown event",n)}}async function asyncPool(e,t,n){const o=[],r=[];for(const s of t){const a=Promise.resolve().then(()=>n(s,t));if(o.push(a),e<=t.length){const l=a.then(()=>r.splice(r.indexOf(l),1));r.push(l),r.length>=e&&await Promise.race(r)}}return Promise.all(o)}const ComponentInputs={node:{name:"Component Inputs",shortDesc:"This node is used to define the inputs of a component.",docs:"https://docs.noodl.net/nodes/component-utilities/component-inputs",panels:[{name:"PortEditor",context:["select","connectFrom"],title:"Inputs",plug:"output",type:{name:"*"},canArrangeInGroups:!0},{name:"PropertyEditor",hidden:!0}],getInspectInfo(){return{type:"value",value:this.nodeScope.componentOwner._internal.inputValues}},color:"component",haveComponentPorts:!0,category:"Component Utilities",methods:{registerOutputIfNeeded(e){this.hasOutput(e)||this.registerOutput(e,{getter(){return this.nodeScope.componentOwner._internal.inputValues[e]}})},_updateDependencies(){this.nodeScope.componentOwner.update()}}}},ComponentOutputs={node:{category:"Component Utilities",name:"Component Outputs",shortDesc:"This node is used to define the outputs of a component.",docs:"https://docs.noodl.net/nodes/component-utilities/component-outputs",panels:[{name:"PortEditor",context:["select","connectTo"],title:"Outputs",plug:"input",type:{name:"*"},canArrangeInGroups:!0},{name:"PropertyEditor",hidden:!0}],color:"component",haveComponentPorts:!0,prototypeExtensions:{registerInputIfNeeded(e){this.hasInput(e)||this.registerInput(e,{set(t){this.nodeScope.componentOwner.setOutputFromComponentOutput(e,t)}})}}}};function Model(e,t){this.id=e,this.data=t}const models=Model._models={},proxies={},_modelProxyHandler={get(e,t,n){return typeof e[t]=="function"?e[t].bind(e):t in e?Reflect.get(e,t,n):e.get(t)},set(e,t,n){if(t==="_class")e._class=n;else{if(t==="id")return console.log(`Noodl.Object warning: id is readonly (Id is ${e.id}, trying to set to ${n})`),!0;e.set(t,n)}return!0},ownKeys(e){return Reflect.ownKeys(e.data)},getOwnPropertyDescriptor(e,t){return Object.getOwnPropertyDescriptor(e.data,t)}};Model.get=function(e){return e===void 0&&(e=Model.guid()),models[e]||(models[e]=new Model(e,{}),proxies[e]=new Proxy(models[e],_modelProxyHandler)),proxies[e]},Model.create=function(e){var t=e||{},n=Model.get(t.id);for(var o in t)o!=="id"&&n.set(o,t[o]);return n},Model.exists=function(e){return models[e]!==void 0},Model.instanceOf=function(e){return e instanceof Model||e.target instanceof Model};function _randomString(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let o=0;o<e;++o)n+=t[Math.floor((1+Math.random())*65536)%t.length];return n}Model.guid=function e(){return _randomString(10)},Model.prototype.on=function(e,t){this.listeners||(this.listeners={}),this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)},Model.prototype.off=function(e,t){if(this.listeners&&this.listeners[e]){var n=this.listeners[e].indexOf(t);n!==-1&&this.listeners[e].splice(n,1)}},Model.prototype.notify=function(e,t){if(this.listeners&&this.listeners[e])for(var n=this.listeners[e].slice(),o=0;o<n.length;o++)n[o](t)},Model.prototype.setAll=function(e){for(var t in e)if(t!=="id"&&this.data[t]!==e[t]){var n=this.data[t];this.data[t]=e[t],this.notify("change",{name:t,value:e[t],old:n})}},Model.prototype.fill=function(e=null){for(const t in this.data){if(t==="id")continue;const n=this.data[t];this.data[t]=e,this.notify("change",{name:t,value:this.data[t],old:n})}},Model.prototype.set=function(e,t,n){if(n&&n.resolve&&e.indexOf(".")!==-1){const s=e.split(".");let a=this;for(let l=0;l<s.length-1;l++){const u=a.get(s[l]);if(Model.instanceOf(u))a=u;else return}a.set(s[s.length-1],t);return}const o=n&&n.forceChange,r=this.data[e];this.data[e]=t,(o||r!==t)&&(!n||!n.silent)&&this.notify("change",{name:e,value:t,old:r})},Model.prototype.getId=function(){return this.id},Model.prototype.get=function(e,t){if(t&&t.resolve&&e.indexOf(".")!==-1){const n=e.split(".");let o=this;for(let r=0;r<n.length-1;r++){const s=o.get(n[r]);if(Model.instanceOf(s))o=s;else return}return o.get(n[n.length-1])}return this.data[e]},Model.prototype.toJSON=function(){return Object.assign({},this.data,{id:this.id})},Model.Scope=function(){this.models={},this.proxies={}},Model.Scope.prototype.get=function(e){return e===void 0&&(e=Model.guid()),this.models[e]||(this.models[e]=new Model(e,{}),this.proxies[e]=new Proxy(this.models[e],_modelProxyHandler)),this.proxies[e]},Model.Scope.prototype.create=function(e){var t=e||{},n=this.get(t.id);for(var o in t)o!=="id"&&n.set(o,t[o]);return n},Model.Scope.prototype.exists=function(e){return this.models[e]!==void 0},Model.Scope.prototype.instanceOf=function(e){return e instanceof Model||e.target instanceof Model},Model.Scope.prototype.guid=function e(){return _randomString(10)},Model.Scope.prototype.reset=function(){this.models={},this.proxies={},delete this._cloudStore};function sendSignalOnInput(e,t){e.queueInput(t,!0),e.queueInput(t,!1)}const RunTasksDefinition={name:"RunTasks",displayNodeName:"Run Tasks",docs:"https://docs.noodl.net/nodes/data/run-tasks",color:"data",category:"Data",initialize(){this._internal.queuedOperations=[],this._internal.state="idle",this._internal.maxRunningTasks=10,this._internal.activeTasks=new Map},inputs:{items:{group:"Data",displayName:"Items",type:"array",set(e){e&&e!==this._internal.items&&(this._internal.items=e)}},stopOnFailure:{group:"General",displayName:"Stop On Failure",type:"boolean",default:!1,set(e){this._internal.stopOnFailure=e}},maxRunningTasks:{group:"General",displayName:"Max Running Tasks",type:"number",default:10,set(e){this._internal.maxRunningTasks=e}},taskTemplate:{type:"component",displayName:"Template",group:"General",set(e){this._internal.template=e}},run:{group:"General",displayName:"Do",type:"signal",valueChangedToTrue(){this.scheduleRun()}},abort:{group:"General",displayName:"Abort",type:"signal",valueChangedToTrue(){this.scheduleAbort()}}},outputs:{success:{type:"signal",group:"Events",displayName:"Success"},failure:{type:"signal",group:"Events",displayName:"Failure"},done:{type:"signal",group:"Events",displayName:"Done"},aborted:{type:"signal",group:"Events",displayName:"Aborted"}},methods:{scheduleRun(){var e=this._internal;e.hasScheduledRun||(e.hasScheduledRun=!0,this.scheduleAfterInputsHaveUpdated(()=>{this._queueOperation(()=>{e.hasScheduledRun=!1,this.run()})}))},scheduleAbort(){var e=this._internal;e.hasScheduledAbort||(e.hasScheduledAbort=!0,this.scheduleAfterInputsHaveUpdated(()=>{this._queueOperation(()=>{e.hasScheduledAbort=!1,this.abort()})}))},async createTaskComponent(e){const t=this._internal,n=(this.nodeScope.modelScope||Model).create(e);var o=await this.nodeScope.createNode(t.template,guid$1(),{_forEachModel:n,_forEachNode:this});const r=o.isInputConnected.bind(o);o.isInputConnected=a=>a==="Do"?!0:r(a),o.hasInput("Id")&&o.setInputValue("Id",n.getId()),o.hasInput("id")&&o.setInputValue("id",n.getId());for(var s in o._inputs)n.data[s]!==void 0&&o.setInputValue(s,n.data[s]);return o._internal.creatorCallbacks={onOutputChanged:(a,l,u)=>{(u===!1||u===void 0)&&l===!0&&this.itemOutputSignalTriggered(a,n,o)}},o},async startTask(e){const t=this._internal;try{const n=await this.createTaskComponent(e);t.runningTasks++,sendSignalOnInput(n,"Do"),t.activeTasks.set(n.id,n)}catch(n){console.log(n)}},async run(){const e=this._internal;if(this.context.editorConnection&&(e.state!=="idle"?this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks",{message:"Cannot start when not in idle mode"}):e.template?e.items?this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks"):this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks",{message:"No items array provided."}):this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"run-tasks",{message:"No task template specified."})),e.state==="idle"&&e.template&&e.items){e.state="running",e.numTasks=e.items.length,e.failedTasks=0,e.completedTasks=0,e.queuedTasks=[].concat(e.items),e.runningTasks=0,e.items.length===0&&(this.sendSignalOnOutput("success"),e.state="idle");for(let t=0;t<Math.min(e.maxRunningTasks,e.queuedTasks.length);t++){const n=e.queuedTasks.shift();if(!n)break;this.startTask(n)}}},abort(){const e=this._internal;e.state="aborted"},itemOutputSignalTriggered(e,t,n){const o=this._internal;if(o.state==="idle")return;const r=()=>{if(o.state==="aborted"){this.sendSignalOnOutput("aborted"),o.state="idle";return}if(o.completedTasks===o.numTasks)o.failedTasks===0?this.sendSignalOnOutput("success"):this.sendSignalOnOutput("failure"),this.sendSignalOnOutput("done"),o.state="idle";else if(o.stopOnFailure)if(o.failedTasks===0){o.runningTasks++;const s=o.queuedTasks.shift();s&&this.startTask(s)}else this.sendSignalOnOutput("failure"),this.sendSignalOnOutput("aborted");else{o.runningTasks++;const s=o.queuedTasks.shift();s&&this.startTask(s)}};e==="Success"?(o.completedTasks++,o.runningTasks--,r()):e==="Failure"&&(o.completedTasks++,o.failedTasks++,o.runningTasks--,r()),o.activeTasks.delete(n.id),this.nodeScope.deleteNode(n)},_queueOperation(e){this._internal.queuedOperations.push(e),this._runQueueOperations()},async _runQueueOperations(){if(!this.runningOperations){for(this.runningOperations=!0;this._internal.queuedOperations.length;)await this._internal.queuedOperations.shift()();this.runningOperations=!1}}},_deleteAllTasks(){for(const e of this._internal.activeTasks)this.nodeScope.deleteNode(e);this._internal.activeTasks.clear()},_onNodeDeleted(){Node.prototype._onNodeDeleted.call(this),this._deleteAllTasks()}},RunTasks={node:RunTasksDefinition},defaultRequestScript=`//Add custom code to setup the request object before the request
2
2
  //is made.
3
3
  //
4
4
  //*Request.resource contains the resource path of the request.
@@ -169,7 +169,7 @@ map({
169
169
  background: ${t.trackColor};
170
170
  border: none;
171
171
  }
172
- `}function Range(e){const[t,n]=React.useState(e.value);React.useEffect(()=>{n(e.value)},[]),React.useEffect(()=>{n(e.value)},[e.value]);var o={...e.style};Layout.size(o,e),Layout.align(o,e);const r={id:e.id,min:e.min,max:e.max,step:e.step,style:o};Utils.updateStylesForClass("ndl-controls-range-"+e._nodeId,e,_styleTemplate);let s="ndl-controls-range-"+e._nodeId+" ndl-controls-range";return e.className&&(s=s+" "+e.className),React.createElement("input",{className:s,...Utils.controlEvents(e),type:"range",...r,value:t,disabled:!e.enabled,onChange:a=>{n(a.target.value),e.valueChanged&&e.valueChanged(a.target.value)}})}var RangeNode={name:"Range",docs:"https://docs.noodl.net/nodes/visual/range",allowChildren:!1,noodlNodeAsProp:!0,initialize(){this.props.sizeMode="explicit",this.props.id=this._internal.controlId="input-"+guid(),this.props.enabled=this._internal.enabled=!0,this._internal.value=this.props.value=this.props.min,this.props._nodeId=this.id,this.props.valueChanged=e=>{e=typeof e=="string"?parseFloat(e):e;const t=this._internal.value!==e;this._internal.value=e,this._updateValuePercent(e),t&&(this.flagOutputDirty("value"),this.sendSignalOnOutput("onChange"))},this.props.valueChanged(this.props.value),this.outputPropValues.hoverState=this.outputPropValues.focusState=this.outputPropValues.pressedState=!1},getReactComponent(){return Range},inputs:{enabled:{type:"boolean",displayName:"Enabled",group:"General",default:!0,set:function(e){e=!!e;const t=e!==this._internal.enabled;this.props.enabled=this._internal.enabled=e,t&&(this.forceUpdate(),this.flagOutputDirty("enabled"))}},value:{type:"string",displayName:"Value",group:"General",set:function(e){const t=e!==this._internal.value;this.props.value=this._internal.value=e,this._updateValuePercent(e),t&&(this.forceUpdate(),this.flagOutputDirty("value"))}}},outputs:{controlId:{type:"string",displayName:"Control Id",group:"General",getter:function(){return this._internal.controlId}},enabled:{type:"boolean",displayName:"Enabled",group:"States",getter:function(){return this._internal.enabled}},value:{type:"number",displayName:"Value",group:"States",getter:function(){return this._internal.value}},valuePercent:{type:"number",displayName:"Value Percent",group:"States",getter:function(){return this._internal.valuePercent}},onChange:{type:"signal",displayName:"Changed",group:"Events"}},inputProps:{min:{type:"number",displayName:"Min",group:"General",default:0},max:{type:"number",displayName:"Max",group:"General",default:100},step:{type:"number",displayName:"Step",group:"General",default:1},width:{index:11,group:"Dimensions",displayName:"Width",type:{name:"number",units:["%","px","vw"],defaultUnit:"%"},default:100},height:{index:12,group:"Dimensions",displayName:"Height",type:{name:"number",units:["%","px","vh"],defaultUnit:"%"},default:100},thumbWidth:{group:"Thumb Style",displayName:"Width",type:{name:"number",units:["px","vw","%"],defaultUnit:"px",allowEditOnly:!0},default:16},thumbHeight:{group:"Thumb Style",displayName:"Height",type:{name:"number",units:["px","vh","%"],defaultUnit:"px",allowEditOnly:!0},default:16},thumbRadius:{group:"Thumb Style",displayName:"Radius",type:{name:"number",units:["px","%"],defaultUnit:"px",allowEditOnly:!0},default:8},thumbColor:{group:"Thumb Style",displayName:"Color",type:{name:"color",allowEditOnly:!0},default:"#000000"},trackHeight:{group:"Track Style",displayName:"Height",type:{name:"number",units:["px","vh","%"],defaultUnit:"px",allowEditOnly:!0},default:6},trackColor:{group:"Track Style",displayName:"Color",type:{name:"color",allowEditOnly:!0},default:"#f0f0f0"}},inputCss:{backgroundColor:{index:201,displayName:"Background Color",group:"Style",type:"color"},borderRadius:{index:202,displayName:"Border Radius",group:"Style",type:{name:"number",units:["px"],defaultUnit:"px"},default:1,applyDefault:!1},borderStyle:{index:203,displayName:"Border Style",group:"Style",type:{name:"enum",enums:[{label:"None",value:"none"},{label:"Solid",value:"solid"},{label:"Dotted",value:"dotted"},{label:"Dashed",value:"dashed"}]},default:"none",applyDefault:!1},borderWidth:{index:204,displayName:"Border Width",group:"Style",type:{name:"number",units:["px"],defaultUnit:"px"},default:1,applyDefault:!1},borderColor:{index:205,displayName:"Border Color",group:"Style",type:"color",default:"#000000"}},outputProps:{},methods:{_updateValuePercent(e){const t=this.props.min,n=this.props.max,o=Math.floor((e-t)/(n-t)*100),r=this._internal.valuePercentChanged!==o;this._internal.valuePercent=o,r&&this.flagOutputDirty("valuePercent")}}};NodeSharedPortDefinitions.addAlignInputs(RangeNode),NodeSharedPortDefinitions.addTransformInputs(RangeNode),NodeSharedPortDefinitions.addMarginInputs(RangeNode),NodeSharedPortDefinitions.addSharedVisualInputs(RangeNode),Utils.addControlEventsAndStates(RangeNode),RangeNode=createNodeFromReactComponent(RangeNode);const RangeOld=RangeNode;function preventGlobalFocusChange(e){e.stopPropagation(),window.removeEventListener("click",preventGlobalFocusChange,!0)}class TextFieldComponent extends React.Component{constructor(t){super(t),this.state={value:t.startValue},this.ref=React.createRef()}setText(t){this.setState({value:t}),this.props.onTextChanged&&this.props.onTextChanged(t)}componentDidMount(){this.ref.current.noodlNode=this.props.noodlNode,this.setText(this.props.startValue)}render(){const t={...this.props.textStyle,...this.props.style};Layout.size(t,this.props),Layout.align(t,this.props),t.opacity===0&&(t.pointerEvents="none");const n=this.props,o={id:n.id,value:this.state.value,...Utils.controlEvents(n),disabled:!n.enabled,style:t,className:n.className,placeholder:n.placeholder,onChange:r=>this.onChange(r)};return this.props.type!=="textArea"?React.createElement("input",{ref:this.ref,type:this.props.type,...o,onKeyDown:r=>this.onKeyDown(r),onMouseDown:()=>window.addEventListener("click",preventGlobalFocusChange,!0)}):(o.style.resize="none",React.createElement("textarea",{ref:this.ref,...o,onKeyDown:r=>this.onKeyDown(r)}))}onKeyDown(t){(t.key==="Enter"||t.which===13)&&this.props.onEnter&&this.props.onEnter()}onChange(t){const n=t.target.value;this.setText(n)}focus(){this.ref.current&&this.ref.current.focus()}blur(){this.ref.current&&this.ref.current.blur()}}const TextInput={name:"Text Input",docs:"https://docs.noodl.net/nodes/visual/text-input",allowChildren:!1,noodlNodeAsProp:!0,getReactComponent(){return TextFieldComponent},defaultCss:{outline:"none",borderStyle:"solid",padding:0},initialize(){this.props.startValue="",this.props.id=this._internal.controlId="input-"+guid(),this.props.enabled=this._internal.enabled=!0,this.outputPropValues.hoverState=this.outputPropValues.focusState=this.outputPropValues.pressedState=!1},inputProps:{type:{displayName:"Type",group:"Text",index:19,type:{name:"enum",enums:[{label:"Text",value:"text"},{label:"Text Area",value:"textArea"},{label:"Email",value:"email"},{label:"Number",value:"number"},{label:"Password",value:"password"},{label:"URL",value:"url"}]},default:"text"},placeholder:{index:22,group:"Text",displayName:"Placeholder",default:"Type here...",type:{name:"string"}},boxShadowEnabled:{index:250,group:"Box Shadow",displayName:"Shadow Enabled",type:"boolean",default:!1},boxShadowOffsetX:{index:251,group:"Box Shadow",displayName:"Offset X",default:0,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowOffsetY:{index:252,group:"Box Shadow",displayName:"Offset Y",default:0,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowBlurRadius:{index:253,group:"Box Shadow",displayName:"Blur Radius",default:5,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowSpreadRadius:{index:254,group:"Box Shadow",displayName:"Spread Radius",default:2,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowInset:{index:255,group:"Box Shadow",displayName:"Inset",type:"boolean",default:!1},boxShadowColor:{index:256,group:"Box Shadow",displayName:"Shadow Color",type:"color",default:"rgba(0,0,0,0.2)"}},inputs:{enabled:{type:"boolean",displayName:"Enabled",group:"General",default:!0,set:function(e){e=!!e;const t=e!==this._internal.enabled;this.props.enabled=this._internal.enabled=e,t&&(this.forceUpdate(),this.flagOutputDirty("enabled"))}},set:{group:"Actions",displayName:"Set",type:"signal",valueChangedToTrue(){this.scheduleAfterInputsHaveUpdated(()=>{this.setText(this._internal.text)})}},startValue:{index:18,displayName:"Text",type:"string",group:"Text",set(e){this._internal.text!==e&&(this._internal.text=e,this.isInputConnected("set")===!1&&this.setText(e))}},textStyle:{index:19,type:"textStyle",group:"Text",displayName:"Text Style",default:"None",set(e){this.props.textStyle=this.context.styles.getTextStyle(e),this.forceUpdate()}},fontFamily:{index:20,type:"font",group:"Text",displayName:"Font Family",set(e){if(e){let t=e;t.split(".").length>1&&(t=t.replace(/\.[^/.]+$/,""),t=t.split("/").pop()),this.setStyle({fontFamily:t})}else this.removeStyle(["fontFamily"]);this.props.textStyle&&this.forceUpdate()}},clear:{type:"signal",group:"Actions",displayName:"Clear",valueChangedToTrue(){this.setText("")}},focus:{type:"signal",group:"Actions",displayName:"Focus",valueChangedToTrue(){this.context.setNodeFocused(this,!0)}},blur:{type:"signal",group:"Actions",displayName:"Blur",valueChangedToTrue(){this.context.setNodeFocused(this,!1)}}},inputCss:{fontSize:{index:21,group:"Text",displayName:"Font Size",type:{name:"number",units:["px"],defaultUnit:"px"},onChange(){this.props.textStyle&&this.forceUpdate()}},color:{index:99,type:"color",displayName:"Font Color",group:"Style"},backgroundColor:{index:100,displayName:"Background Color",group:"Style",type:"color",default:"transparent"},borderColor:{index:101,displayName:"Border Color",group:"Style",type:"color",default:"black"},borderWidth:{index:102,displayName:"Border Width",group:"Style",type:{name:"number",units:["px"],defaultUnit:"px"},default:0}},outputs:{controlId:{type:"string",displayName:"Control Id",group:"General",getter:function(){return this._internal.controlId}},enabled:{type:"boolean",displayName:"Enabled",group:"States",getter:function(){return this._internal.enabled}}},outputProps:{onTextChanged:{group:"Value",displayName:"Text",type:"string"},onEnter:{group:"Events",displayName:"On Enter",type:"signal"}},dynamicports:[{condition:"boxShadowEnabled = true",inputs:["boxShadowOffsetX","boxShadowOffsetY","boxShadowInset","boxShadowBlurRadius","boxShadowSpreadRadius","boxShadowColor"]}],methods:{_focus(){this.innerReactComponentRef&&this.innerReactComponentRef.focus()},_blur(){this.innerReactComponentRef&&this.innerReactComponentRef.blur()},setText(e){this.props.startValue=e,this.innerReactComponentRef?this.innerReactComponentRef.setText(e):this.outputPropValues.onTextChanged!==e&&(this.outputPropValues.onTextChanged=e,this.flagOutputDirty("onTextChanged"))}}};NodeSharedPortDefinitions.addDimensions(TextInput,{defaultSizeMode:"contentSize",contentLabel:"Text"}),NodeSharedPortDefinitions.addAlignInputs(TextInput),NodeSharedPortDefinitions.addTransformInputs(TextInput),NodeSharedPortDefinitions.addPaddingInputs(TextInput),NodeSharedPortDefinitions.addMarginInputs(TextInput),NodeSharedPortDefinitions.addSharedVisualInputs(TextInput),Utils.addControlEventsAndStates(TextInput);const definition=createNodeFromReactComponent(TextInput);definition.setup=function(e,t){t.on("nodeAdded.Text Input",function(n){n.parameters.fontFamily&&n.parameters.fontFamily.split(".").length>1&&FontLoader.instance.loadFont(n.parameters.fontFamily),n.on("parameterUpdated",function(o){o.name==="fontFamily"&&o.value&&o.value.split(".").length>1&&FontLoader.instance.loadFont(o.value)})})};const Switch={name:"Switch",docs:"https://docs.noodl.net/nodes/logic/switch",category:"Logic",initialize(){this._internal.state=!1,this._internal.initialized=!1},getInspectInfo(){return this._internal.state},inputs:{on:{displayName:"On",group:"Change State",valueChangedToTrue(){this._internal.state!==!0&&(this._internal.state=!0,this.flagOutputDirty("state"),this.emitSignals())}},off:{displayName:"Off",group:"Change State",valueChangedToTrue(){this._internal.state!==!1&&(this._internal.state=!1,this.flagOutputDirty("state"),this.emitSignals())}},flip:{displayName:"Flip",group:"Change State",valueChangedToTrue(){this._internal.state=!this._internal.state,this.flagOutputDirty("state"),this.emitSignals()}},onFromStart:{type:"boolean",displayName:"State",group:"General",default:!1,set(e){this._internal.state=!!e,this.flagOutputDirty("state"),this.emitSignals()}}},outputs:{state:{type:"boolean",displayName:"Current State",getter(){return this._internal.state}},switched:{displayName:"Switched",type:"signal",group:"Signals"},switchedToOn:{displayName:"Switched To On",type:"signal",group:"Signals"},switchedToOff:{displayName:"Switched To Off",type:"signal",group:"Signals"}},prototypeExtensions:{emitSignals(){this._internal.state===!0?this.sendSignalOnOutput("switchedToOn"):this.sendSignalOnOutput("switchedToOff"),this.sendSignalOnOutput("switched")}}},Switch$1={node:Switch},Timer={name:"Timer",docs:"https://docs.noodl.net/nodes/utilities/delay",displayName:"Delay",category:"Utilities",nodeDoubleClickAction:{focusPort:"duration"},initialize:function(){var e=this;this._internal._animation=this.context.timerScheduler.createTimer({duration:0,onStart:function(){e.sendSignalOnOutput("timerStarted")},onFinish:function(){e.sendSignalOnOutput("timerFinished")}}),this.addDeleteListener(()=>{this._internal._animation.stop()})},getInspectInfo(){return this._internal._animation.isRunning()?Math.floor(this._internal._animation.durationLeft()/10)/100+" seconds":"Not running"},inputs:{start:{displayName:"Start",valueChangedToTrue:function(){this._internal._animation._isRunning===!1&&this._internal._animation.start()}},restart:{displayName:"Restart",valueChangedToTrue:function(){this._internal._animation.start()}},duration:{type:"number",displayName:"Duration",default:0,set:function(e){this._internal._animation.duration=e}},startDelay:{type:"number",displayName:"Start Delay",default:0,set:function(e){this._internal._animation.delay=e}},stop:{displayName:"Stop",valueChangedToTrue:function(){this._internal._animation.stop()}}},outputs:{timerStarted:{type:"signal",displayName:"Started"},timerFinished:{type:"signal",displayName:"Finished"}}},Timer$1={node:Timer},Color={node:createDefinition({name:"Color",docs:"https://docs.noodl.net/nodes/data/color",startValue:"#f1f2f4",nodeDoubleClickAction:{focusPort:"value"},type:{name:"color"},cast:function(e){return e}})},EventSender={name:"Event Sender",docs:"https://docs.noodl.net/nodes/events/send-event",displayNodeName:"Send Event",category:"Events",usePortAsLabel:"channelName",color:"component",exportDynamicPorts:!0,initialize:function(){this._internal.inputValues={},this._internal.channelName="",this._internal.propagation="global"},inputs:{sendEvent:{displayName:"Send",valueChangedToTrue:function(){var e=this;this.scheduleAfterInputsHaveUpdated(function(){e._internal.propagation==="global"?e.context.sendGlobalEventFromEventSender(e._internal.channelName,e._internal.inputValues):e.nodeScope.sendEventFromThisScope(e._internal.channelName,e._internal.inputValues,e._internal.propagation)})}},channelName:{type:{name:"string",allowEditOnly:!0,identifierOf:"EventChannelName",identifierDisplayName:"Event Channels"},default:"",group:"Settings",displayName:"Channel Name",set:function(e){this._internal.channelName=e,this._internal.inputValues._channelName=e}},propagation:{type:{name:"enum",enums:[{value:"global",label:"Global"},{value:"parent",label:"Parent"},{value:"children",label:"Children"},{value:"siblings",label:"Siblings"}]},default:"global",group:"Settings",displayName:"Send to",set:function(e){this._internal.propagation=e}},payload:{type:{name:"stringlist",allowEditOnly:!0},group:"Payload"}},prototypeExtensions:{registerInputIfNeeded:{value:function(e){if(!this.hasInput(e)){var t=this;this.registerInput(e,{set:function(n){t._internal.inputValues[e]=n}})}}}}};function updatePorts$a(e,t,n){var o=[],r=t.payload;if(r){r=r.split(",");for(const s of r)o.push({type:{name:"*",allowConnectionsOnly:!0},plug:"input",group:"Payload",name:s,displayName:s})}n.sendDynamicPorts(e,o,{detectRenamed:{plug:"input"}})}const EventSender$1={node:EventSender,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.Event Sender",function(n){updatePorts$a(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",function(o){updatePorts$a(n.id,n.parameters,e.editorConnection)})})}},EventReceiver={name:"Event Receiver",docs:"https://docs.noodl.net/nodes/events/receive-event",displayNodeName:"Receive Event",category:"Events",usePortAsLabel:"channelName",color:"component",initialize:function(){var e=this._internal;e.outputValues={},e.outputNames=[],e.eventReceived=!1,e._isEnabled=!0,e.channelName=""},inputs:{enabled:{displayName:"Enabled",type:"boolean",default:!0,set:function(e){this._internal._isEnabled=!!e}},consume:{displayName:"Consume",type:{name:"enum",enums:[{label:"Never",value:"never"},{label:"Always",value:"always"}]},default:"never",set:function(e){this._internal.consume=e}},channelName:{type:{name:"string",identifierOf:"EventChannelName"},displayName:"Channel",set:function(e){this._internal.onEventReceivedCallback&&(this.context.eventSenderEmitter.removeListener(this._internal.channelName,this._internal.onEventReceivedCallback),this._internal.onEventReceivedCallback=null),this._internal.channelName=e,this.registerListenersForChannel(e)}}},outputs:{eventReceived:{displayName:"Received",type:"signal"}},prototypeExtensions:{registerOutputIfNeeded:function(e){if(!this.hasOutput(e)){var t=this;this._internal.outputNames.push(e),this.registerOutput(e,{getter:function(){return t._internal.outputValues[e]}})}},handleEvent:function(e){if(this._internal._isEnabled!==!1){this.sendSignalOnOutput("eventReceived");for(var t in e)this.hasOutput(t)&&(this._internal.outputValues[t]=e[t],this.flagOutputDirty(t));return this._internal.consume==="always"}},onEventReceived:function(e){this.handleEvent(e)},_onNodeDeleted:function(){if(Node.prototype._onNodeDeleted.call(this),this._internal.onEventReceivedCallback){var e=this.context.eventSenderEmitter;e.removeListener(this._internal.channelName,this._internal.onEventReceivedCallback)}},registerListenersForChannel:function(e){var t=this.context.eventSenderEmitter;this._internal.onEventReceivedCallback=this.onEventReceived.bind(this),t.on(e,this._internal.onEventReceivedCallback);var n=this;this.context.eventEmitter.once("applicationDataReloaded",function(){n._internal.onEventReceivedCallback&&t.removeListener(e,n._internal.onEventReceivedCallback)})},getChannelName:function(){return this._internal.channelName}}},EventReceiver$1={node:EventReceiver,setup:function(e,t){if(!e.editorConnection||!e.editorConnection.isRunningLocally())return;function n(o){var r=o.parameters.channelName;function s(){var l=t.getNodesWithType("Event Sender"),u=l.filter(g=>g.parameters.channelName===r),d={};u.forEach(g=>{const b=g.parameters.payload?g.parameters.payload.split(","):[];for(let _ of b)d[_]=!0});var h=[];for(var f in d)h.push({name:f,type:"*",plug:"output",displayName:f});e.editorConnection.sendDynamicPorts(o.id,h,{detectRenamed:{plug:"output"}})}s(),o.on("parameterUpdated",function(l){l.name==="channelName"&&(r=l.value,s())});function a(l){l.on("inputPortAdded",function(u){s()}),l.on("inputPortRemoved",function(u){s()}),l.on("parameterUpdated",function(u){u.name==="channelName"&&s()})}t.getNodesWithType("Event Sender").forEach(a),t.on("nodeAdded.Event Sender",a),t.on("nodeRemoved.Event Sender",l=>{s()})}t.on("editorImportComplete",()=>{t.on("nodeAdded.Event Receiver",o=>n(o)),t.getNodesWithType("Event Receiver").forEach(o=>n(o))})}},ScreenResolution={name:"Screen Resolution",docs:"https://docs.noodl.net/nodes/utilities/screen-resolution",category:"Utilities",initialize(){typeof window>"u"||(window.addEventListener("resize",()=>{this._viewportSizeChanged()}),this._viewportSizeChanged())},getInspectInfo(){return this._internal.width+" x "+this._internal.height},outputs:{width:{type:"number",displayName:"Width",get(){return this._internal.width}},height:{type:"number",displayName:"Height",get(){return this._internal.height}},aspectRatio:{type:"number",displayName:"Aspect Ratio",get(){return this._internal.width/this._internal.height}}},methods:{_viewportSizeChanged(){this._internal.width=window.innerWidth,this._internal.height=window.innerHeight,this.flagAllOutputsDirty()}}},ScreenResolution$1={node:ScreenResolution},defaultCode="";var Javascript={name:"Javascript2",docs:"https://docs.noodl.net/nodes/javascript/script",displayNodeName:"Script",category:"CustomCode",color:"javascript",nodeDoubleClickAction:{focusPort:"Code"},searchTags:["javascript"],exportDynamicPorts:!0,initialize:function(){var e=this._internal;e.inputValues={},e.outputValues={},e.outputProperties={},e.runScheduled=!1,e.setupScheduled=!1,e.runNextFrameScheduled=!1,e.isWaitingForExternalFileToLoad=!1,e.useExternalFile=!1,e.runFunction=void 0,e.destroyFunction=void 0,e.setupFunction=void 0,e.hasParsedCode=!1,e.changedInputs={},e.signalScheduled={},e.killed=!1,e.inputQueue=[];var t=this;e.userFunctionScope={createComponent(n){return n&&n.length>0&&n[0]!=="/"&&(n="/"+n),t.nodeScope.createNode(n,guid())},deleteComponent(n){t.nodeScope.deleteNode(n)},flagOutputDirty:function(n){if(!n)throw new Error("Output port name must be specified");t.flagOutputDirty(n)},runNextFrame:function(){e.runNextFrameScheduled||(e.runNextFrameScheduled=!0,t.context.scheduleNextFrame(function(){e.runNextFrameScheduled=!1,e.killed||scheduleRun.call(t)}))},sendSignalOnOutput:function(n){t.sendSignalOnOutput(n)}},e.onFrameStart=onFrameStart.bind(this)},dynamicports:[{condition:"useExternalFile = no OR useExternalFile NOT SET",inputs:["code"]},{condition:"useExternalFile = yes",inputs:["externalFile"]}],inputs:{scriptInputs:{type:{name:"proplist",allowEditOnly:!0},group:"Script Inputs",set:function(e){}},scriptOutputs:{type:{name:"proplist",allowEditOnly:!0},group:"Script Outputs",set:function(e){}},useExternalFile:{type:{name:"enum",enums:[{value:"yes",label:"Yes"},{value:"no",label:"No"}],allowEditOnly:!0},default:"no",displayName:"Use External File",group:"Code",set:function(e){this._internal.isWaitingForExternalFileToLoad=e==="yes",this._internal.useExternalFile=e==="yes"}},code:{displayName:"Code",group:"Code",type:{name:"string",allowEditOnly:!0,codeeditor:"javascript"},default:defaultCode,set:function(e){if(e){var t=this;this.scheduleAfterInputsHaveUpdated(function(){if(this._internal.useExternalFile===!1){this._callDestroyFunction();var n=JavascriptNodeParser.createFromCode(e,{node:this});t._onCodeParsed(n)}})}}},externalFile:{displayName:"File Path",group:"Code",type:{name:"source",allowEditOnly:!0},set:function(e){if(this._internal.useExternalFile!==!1){var t=this;JavascriptNodeParser.createFromURL(e,function(n){t._internal.isWaitingForExternalFileToLoad=!1,t._onCodeParsed(n)},{node:this})}}}},prototypeExtensions:{_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this._internal.killed=!0,this._callDestroyFunction()},update:function(){this._internal.isWaitingForExternalFileToLoad===!0?this._dirty=!1:Node.prototype.update.call(this)},_onCodeParsed:function(e){const t=this.context.editorConnection;if(t)for(const n of["js-destroy-waring","js-run-waring","js-setup-waring"])t.clearWarning(this.nodeScope.componentOwner.name,this.id,n);if(!e.error){if(Object.keys(this.model.inputPorts).forEach(n=>{const o=this.model.inputPorts[n].type;(o==="color"||o.name==="color")&&(this._internal.inputValues[n]=void 0,this.hasInput(n)?this.getInput(n).type="color":this.registerInput(n,{type:"color",set:userInputSetter$4.bind(this,n)}))}),Object.keys(this.model.outputPorts).forEach(n=>{this.registerOutputIfNeeded(n)}),this._internal.setupFunction=e.setup,this._internal.runFunction=e.change,this._internal.destroyFunction=e.destroy,this._internal.definedObject=e.definedObject,this._internal.setupFunction&&scheduleSetup.call(this),this._internal.runFunction&&scheduleRun.call(this),this._internal.hasParsedCode=!0,this._internal.inputQueue){for(const{name:n,value:o}of this._internal.inputQueue)this.setInputValue(n,o);this._internal.inputQueue=void 0}e.apis.Node.Inputs=this._internal.inputValues,e.apis.Node.Outputs=this._internal.outputProperties}},registerInputIfNeeded:function(e){this.hasInput(e)||(this._internal.inputValues[e]=void 0,this.registerInput(e,{set:userInputSetter$4.bind(this,e)}))},registerOutputIfNeeded:function(e){if(this.hasOutput(e))return;var t=this;const n=_typename(this.model.outputPorts[e].type)==="signal";Object.defineProperty(this._internal.outputProperties,e,{set:function(o){n||(t._internal.outputValues[e]=o,t.flagOutputDirty(e))},get:function(){return n?()=>{t.hasOutput(e)&&t.sendSignalOnOutput(e)}:t._internal.outputValues[e]}}),this.registerOutput(e,{getter:userOutputGetter$3.bind(this,e)})},_callRunFunction:function(){var e=this._internal;if(!(!e.runFunction||e.killed))try{e.runFunction.call(e.userFunctionScope,e.inputValues,e.outputProperties,e.changedInputs)}catch(t){logJavaScriptNodeError(t),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-run-waring",{showGlobally:!0,message:"<strong>run</strong>: "+t.message})}},_callSignalFunction:function(e){var t=this._internal;if(!(!t.definedObject||t.killed)&&!(!t.definedObject[e]||typeof t.definedObject[e]!="function"))try{t.definedObject[e].call(t.userFunctionScope,t.inputValues,t.outputProperties)}catch(n){console.log("Error in JS node signal function code.",Object.getPrototypeOf(n).constructor.name+": "+n.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-run-waring",{showGlobally:!0,message:"<strong>run</strong>: "+n.message})}},_callDestroyFunction:function(){var e=this._internal;if(e.destroyFunction)try{e.destroyFunction.call(e.userFunctionScope,e.inputValues,e.outputProperties)}catch(t){console.log("Error in JS node destroy code.",Object.getPrototypeOf(t).constructor.name+": "+t.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-destroy-waring",{showGlobally:!0,message:"<strong>setup</strong>: "+t.message})}},_callSetupFunction:function(){var e=this._internal;if(!(!e.setupFunction||e.killed))try{e.setupFunction.call(e.userFunctionScope,e.inputValues,e.outputProperties)}catch(t){console.log("Error in JS node setup code.",Object.getPrototypeOf(t).constructor.name+": "+t.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-setup-waring",{showGlobally:!0,message:"<strong>setup</strong>: "+t.message})}}}};function scheduleSetup(){this._internal.setupScheduled||(this._internal.setupScheduled=!0,this.scheduleAfterInputsHaveUpdated(function(){this._internal.killed||(this._callSetupFunction(),this._internal.setupScheduled=!1)}))}function scheduleRun(){this._internal.runScheduled||this._internal.killed||(this._internal.runScheduled=!0,this.scheduleAfterInputsHaveUpdated(function(){this._internal.killed||(this._callRunFunction(),this._internal.changedInputs={},this._internal.runScheduled=!1)}))}function scheduleSignal(e){this._internal.signalScheduled[e]||this._internal.killed||(this._internal.signalScheduled[e]=!0,this.scheduleAfterInputsHaveUpdated(function(){this._internal.killed||(this._callSignalFunction(e),this._internal.signalScheduled[e]=!1)}))}function onFrameStart(){this._internal.runNextFrame=!1,scheduleRun.call(this)}function _typename(e){return typeof e=="object"?e.name:e}function userInputSetter$4(e,t){this._internal.hasParsedCode===!0?this.model.inputPorts[e]!==void 0&&_typename(this.model.inputPorts[e].type)==="signal"?this._internal.definedObject&&typeof this._internal.definedObject[e]=="function"&&t&&scheduleSignal.call(this,e):(this._internal.inputValues[e]=t,this._internal.changedInputs[e]=!0,scheduleRun.call(this)):this._internal.inputQueue.push({name:e,value:t})}function userOutputGetter$3(e){return this._internal.outputValues[e]}function _parseAndSourceJavascript(e,t,n){var o=t.editorConnection;if(!e.parameters)return;function r(){for(const u of["js-parse-waring","js-destroy-waring","js-run-waring","js-setup-waring"])o.clearWarning(e.component.name,e.id,u)}function s(u){u.error?o.sendWarning(e.component.name,e.id,"js-parse-waring",{showGlobally:!0,message:u.error}):r(),n(u.getPorts())}if(e.parameters.externalFile&&e.parameters.useExternalFile==="yes"){var a=e.parameters.externalFile;JavascriptNodeParser.createFromURL(a,s)}else if(e.parameters.code){var l=JavascriptNodeParser.createFromCode(e.parameters.code);s(l)}else r(),n([])}const JavaScript={node:Javascript,setup:function(e,t){if(!e.editorConnection||!e.editorConnection.isRunningLocally())return;function n(o){function r(){var s=[];const a=[{value:"string",label:"String"},{value:"boolean",label:"Boolean"},{value:"number",label:"Number"},{value:"object",label:"Object"},{value:"array",label:"Array"}],l=[{value:"string",label:"String"},{value:"boolean",label:"Boolean"},{value:"number",label:"Number"},{value:"object",label:"Object"},{value:"array",label:"Array"},{value:"signal",label:"Signal"}];o.parameters.scriptOutputs!==void 0&&o.parameters.scriptOutputs.length>0&&o.parameters.scriptOutputs.forEach(u=>{s.push({name:"outtype-"+u.label,displayName:"Type",plug:"input",type:{name:"enum",enums:l,allowEditOnly:!0},default:"string",parent:"scriptOutputs",parentItemId:u.id}),s.push({name:u.label,plug:"output",type:o.parameters["outtype-"+u.label]||"*",group:"Outputs"})}),o.parameters.scriptInputs!==void 0&&o.parameters.scriptInputs.length>0&&o.parameters.scriptInputs.forEach(u=>{s.push({name:"intype-"+u.label,displayName:"Type",plug:"input",type:{name:"enum",enums:a,allowEditOnly:!0},default:"string",parent:"scriptInputs",parentItemId:u.id}),s.push({name:u.label,plug:"input",type:o.parameters["intype-"+u.label]||"string",group:"Inputs"})}),_parseAndSourceJavascript(o,e,function(u){u.forEach(d=>{s.find(h=>h.name===d.name&&h.plug===d.plug)||s.push(d)}),e.editorConnection.sendDynamicPorts(o.id,s)})}r(),o.on("parameterUpdated",function(s){r()})}t.on("editorImportComplete",()=>{t.on("nodeAdded.Javascript2",function(o){n(o)});for(const o of t.getNodesWithType("Javascript2"))n(o)})}},NumberRemapperNode={name:"Number Remapper",docs:"https://docs.noodl.net/nodes/math/number-remapper",category:"Math",initialize:function(){var e=this._internal;e._currentInputValue=0,e._remappedValue=0,e._minInputValue=0,e._maxInputValue=0,e._minOutputValue=0,e._maxOutputValue=1,e._clampOutput=!0},getInspectInfo(){return this._internal._remappedValue},inputs:{inputValue:{group:"Value to Remap",type:{name:"number",allowConnectionOnly:!0},default:0,displayName:"Input Value",set:function(e){this._internal._currentInputValue=e,this._calculateNewOutputValue()}},minInputValue:{group:"Input Parameters",type:{name:"number"},default:0,displayName:"Input Minimum",set:function(e){this._internal._minInputValue=e,this._calculateNewOutputValue()}},maxInputValue:{group:"Input Parameters",type:{name:"number"},default:0,displayName:"Input Maximum",set:function(e){this._internal._maxInputValue=e,this._calculateNewOutputValue()}},minOutputValue:{group:"Output Parameters",type:{name:"number"},default:0,displayName:"Output Minimum",set:function(e){this._internal._minOutputValue=e,this._calculateNewOutputValue()}},maxOutputValue:{group:"Output Parameters",type:{name:"number"},default:1,displayName:"Output Maximum",set:function(e){this._internal._maxOutputValue=e,this._calculateNewOutputValue()}},clamp:{group:"Output Parameters",type:{name:"boolean",allowEditOnly:!0},default:!0,displayName:"Clamp Output",set:function(e){this._internal._clampOutput=!!e,this._calculateNewOutputValue()}}},outputs:{remappedValue:{type:"number",displayName:"Remapped Value",group:"Outputs",getter:function(){return this._internal._remappedValue}}},prototypeExtensions:{_calculateNewOutputValue:{value:function(){var e,t=this._internal;t._maxInputValue===t._minInputValue?e=0:e=(t._currentInputValue-t._minInputValue)/(t._maxInputValue-t._minInputValue),t._clampOutput&&(e=Math.max(0,Math.min(1,e))),t._remappedValue=t._minOutputValue+e*(t._maxOutputValue-t._minOutputValue),this.flagOutputDirty("remappedValue")}}}},NumberRemapper={node:NumberRemapperNode},ValueChangedNode={name:"Value Changed",docs:"https://docs.noodl.net/nodes/logic/value-changed",category:"Logic",initialize:function(){this._internal.lastValue=void 0,this._internal.changeCount=0},getInspectInfo(){return this._internal.changeCount?"Triggered "+this._internal.changeCount+(this._internal.changeCount===1?" time":" times"):"Not triggered"},inputs:{value:{type:"*",displayName:"Input",set:function(e){this._internal.lastValue!==e&&(this._internal.changeCount++,this.sendSignalOnOutput("valueChanged"),this._internal.lastValue=e)}}},outputs:{valueChanged:{type:"signal",displayName:"Value Changed"}}},ValueChanged={node:ValueChangedNode},defaultDuration$3=300,previousStates={},previousValues={};function setRGBA(e,t){if(t==="transparent"||!t){e[3]=0;return}const n=(t.length-1)/2;for(let o=0;o<n;++o){const r=1+o*2;e[o]=parseInt(t.substring(r,r+2),16)}}function componentToHex$1(e){var t=e.toString(16);return t.length==1?"0"+t:t}function rgbaToHex(e){return"#"+componentToHex$1(e[0])+componentToHex$1(e[1])+componentToHex$1(e[2])+componentToHex$1(e[3])}const StatesNode={name:"States",docs:"https://docs.noodl.net/nodes/utilities/logic/states",shortDesc:"Define states with values and this node can interpolate between these values when the state is changed.",category:"Animation",initialize:function(){var e=this,t=this._internal;t.useTransitions=!0,t.currentValues={},t.stateParameters={},t.stateParameterTypes={},t.startValues={},t.bezierEaseCurves={},t.transitionFuncs={},t.valuesAreInitialised=!1,t.animation=this.context.timerScheduler.createTimer({duration:defaultDuration$3,ease:EaseCurves.easeOut,onStart:function(){t.values;var n=t.startValues,o=t.stateParameters,r=t.stateParameterTypes,s="value-"+t.state+"-";this.targetValues={},this.startValues={},this.valueTypes={};for(var a in this.transitionCurves)r["type-"+a]==="number"||r["type-"+a]===void 0?(this.valueTypes[a]="number",this.startValues[a]=n[a],this.targetValues[a]=o[s+a]||0):r["type-"+a]==="color"&&(this.valueTypes[a]="color",this.startValues[a]=[0,0,0,255],setRGBA(this.startValues[a],e.context.styles.resolveColor(n[a]||"#000000")),this.targetValues[a]=[0,0,0,255],setRGBA(this.targetValues[a],e.context.styles.resolveColor(o[s+a]||"#000000")))},onRunning:function(n){var o=n*this.duration,r=t.currentValues,s=[0,0,0,255];for(var a in this.transitionCurves){var l=this.transitionCurves[a];if(o<l.delay)r[a]=this.startValues[a];else if(o>=l.delay+l.dur)r[a]=this.valueTypes[a]==="color"?rgbaToHex(this.targetValues[a]):this.targetValues[a];else{var u=t.transitionFuncs[a].get((o-l.delay)/l.dur);if(this.valueTypes[a]==="number")r[a]=EaseCurves.linear(Number(this.startValues[a]),Number(this.targetValues[a]),u);else if(this.valueTypes[a]==="color"){let d=this.startValues[a],h=this.targetValues[a];s[0]=Math.floor(EaseCurves.linear(d[0],h[0],u)),s[1]=Math.floor(EaseCurves.linear(d[1],h[1],u)),s[2]=Math.floor(EaseCurves.linear(d[2],h[2],u)),s[3]=Math.floor(EaseCurves.linear(d[3],h[3],u)),r[a]=rgbaToHex(s)}}e.flagOutputDirty(a)}},onFinish:function(){var n="reached-"+t.state;e.hasOutput(n)&&e.sendSignalOnOutput(n)}})},getInspectInfo(){return`Current state: ${this._internal.state}`},inputs:{states:{type:{name:"stringlist",allowEditOnly:!0},displayName:"States",group:"States",set:function(e){if(this._internal.states=e?e.split(","):[],this._internal.states.length>0){var t=this;t._internal.state||this.scheduleGoToState(t._internal.startState||t._internal.states[0])}}},values:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Values",group:"Values",set:function(e){var t=this._internal;t.values=e.split(",");for(var n in t.values)this.registerOutputIfNeeded(t.values[n])}},toggle:{group:"Go to state",displayName:"Toggle",valueChangedToTrue:function(){var e=this._internal;if(e.states){var t=e.states.indexOf(e.state),n=(t+1)%e.states.length;this.scheduleGoToState(e.states[n])}}},useTransitions:{type:"boolean",displayName:"Use Transitions",group:"General",default:!0,set:function(e){var t=this._internal;t.useTransitions=e}}},outputs:{currentState:{type:"string",displayName:"State",group:"Current State",getter:function(){return this._internal.state}},stateChanged:{type:"signal",displayName:"State Changed",group:"Current State"}},prototypeExtensions:{registerOutputIfNeeded:function(e){var t=this._internal;this.hasOutput(e)||this.registerOutput(e,{getter:function(){return t.currentValues[e]}})},registerInputIfNeeded:function(e){var t=this,n=this._internal;if(!this.hasInput(e)){if(e.indexOf("to-")===0){var o=e.substring(3);this.registerInput(e,{set:createSetter({valueChangedToTrue:function(){this.scheduleGoToState(o)}})})}else if(e==="startState")this.registerInput(e,{set:function(a){this._internal.startState=a,this.scheduleGoToState(a)}});else if(e==="currentState")this.registerInput(e,{set:this.scheduleGoToState.bind(this)});else if(e.indexOf("type-")===0)this.registerInput(e,{set:function(a){n.stateParameterTypes[e]=a}});else if(e.indexOf("value-")===0){var r=e.split("-"),o=r[1],s=r[2];this.registerInput(e,{set:function(l){n.stateParameters[e]=l,n.state===o&&(n.currentValues[s]=l,t.flagOutputDirty(s))}})}else if(e.search(/duration-/g)===0)this.registerInput(e,{set:function(a){n.stateParameters[e]=a}});else if(e.search(/transition/g)===0){var o=e.substring(11);this.registerInput(e,{set:function(l){n.stateParameters[e]=l}})}}},setCurrentState:function(e){this.scheduleGoToState(e)},jumpToState:function(e){var t=this._internal;if(t.states&&(e||(e=t.states[0]),t.state!==e)){t.animation.stop();var n="value-"+e+"-";for(var o in t.values){var r=t.values[o];t.currentValues[r]=t.stateParameters[n+r]||0,this.flagOutputDirty(r)}t.state=e,this.flagOutputDirty("currentState"),t.valuesAreInitialised&&this.sendSignalOnOutput("stateChanged"),t.valuesAreInitialised=!0,this.updateAtStatePorts()}},scheduleGoToState:function(e){var t=this;this._internal.goToState=e,!this.hasScheduledGoToState&&(this.hasScheduledGoToState=!0,this.scheduleAfterInputsHaveUpdated(function(){t.hasScheduledGoToState=!1,t.goToState(t._internal.goToState)}))},goToState:function(e){var t=this._internal;if(t.states&&(e||(e=t.states[0]),t.state!==e))if(!t.valuesAreInitialised)this.jumpToState(e);else{var n=0,o=0,r={};for(var s in t.values){var a=t.values[s];t.startValues[a]=t.currentValues[a];const h=t.stateParameterTypes["type-"+a];if(h==="boolean"){var l=t.stateParameters["value-"+e+"-"+a];t.currentValues[a]=l===void 0?!1:!!l,this.flagOutputDirty(a)}else if(h==="string"||h==="textStyle")t.currentValues[a]=t.stateParameters["value-"+e+"-"+a],this.flagOutputDirty(a);else{var u=t.stateParameters["transition-"+e+"-"+a];u||(u=t.stateParameters["transitiondef-"+e]||{curve:[0,0,.58,1],dur:300,delay:0}),u.dur===0&&u.delay===0||!t.useTransitions?(t.currentValues[a]=t.stateParameters["value-"+e+"-"+a],this.flagOutputDirty(a)):(t.transitionFuncs[a]=BezierEasing(u.curve),r[a]=u,n=Math.min(n,u.delay),o=Math.max(o,u.dur+u.delay))}}if((o>0||n>0)&&(t.animation.transitionCurves=r,t.animation.duration=o,t.animation.delay=n,t.animation.start()),t.state=e,this.flagOutputDirty("currentState"),this.sendSignalOnOutput("stateChanged"),this.updateAtStatePorts(),o==0&&n==0){var d="reached-"+t.state;this.hasOutput(d)&&this.sendSignalOnOutput(d)}}},updateAtStatePorts:function(){var e=this._internal,t=e.states;for(var n in t){var o=t[n],r="at-"+o;e.currentValues[r]=e.state===o,this.hasOutput(r)&&this.flagOutputDirty(r)}}}};function detectRename$1(e,t){if(!(!e||!t)&&e.length===t.length){for(var n={},o=0;o<e.length;o++){if(t.indexOf(e[o])===-1){if(n.before)return;n.before=e[o]}if(e.indexOf(t[o])===-1){if(n.after)return;n.after=t[o]}}return n.before&&n.after?n:void 0}}function updatePorts$9(e,t,n){var o=t.states,r=t.values,s=[];r=r?r.split(","):void 0;for(var a in r){var l=r[a];s.push({type:{name:t["type-"+l]||"number",allowConnectionsOnly:!0},plug:"output",group:"Values",name:l}),s.push({type:{name:"enum",enums:[{label:"Number",value:"number"},{label:"String",value:"string"},{label:"Boolean",value:"boolean"},{label:"Color",value:"color"},{label:"Text Style",value:"textStyle"}],allowEditOnly:!0},default:"number",plug:"input",group:"Types",displayName:l,name:"type-"+l})}o=o?o.split(","):void 0,o&&o.forEach(function(f){r&&r.forEach(function(g){s.push({plug:"input",type:t["type-"+g]||"number",group:f+" Values",name:"value-"+f+"-"+g,displayName:g,editorName:f+"|"+g})}),r&&t.useTransitions!==!1&&(s.push({plug:"input",type:"curve",displayName:"Default",default:{curve:[0,0,.58,1],dur:300,delay:0},group:f+" Transitions",name:"transitiondef-"+f}),r.forEach(function(g){(t["type-"+g]===void 0||t["type-"+g]==="number"||t["type-"+g]==="color")&&s.push({plug:"input",type:{name:"curve"},default:t["transitiondef-"+f]||{curve:[0,0,.58,1],dur:300,delay:0},group:f+" Transitions",name:"transition-"+f+"-"+g,displayName:g,editorName:"Transition "+f+"|"+g})})),s.push({plug:"input",type:{name:"signal",allowConnectionsOnly:!0},displayName:"To "+f,name:"to-"+f,group:"Go to state"}),s.push({plug:"output",type:"boolean",displayName:"At "+f,name:"at-"+f,group:"Current state"}),s.push({plug:"output",type:"signal",displayName:"Has Reached "+f,name:"reached-"+f,group:"Current state"})}),o&&s.push({plug:"input",type:{name:"enum",enums:o},group:"States",displayName:"State",name:"currentState",default:t.startState||o[0]});var u=detectRename$1(previousStates[e],o);previousStates[e]=o;var d=detectRename$1(previousValues[e],r);previousValues[e]=r;let h;u?(h={plug:"input",before:u.before,after:u.after,patterns:["transition-{{*}}","to-{{*}}","at-{{*}}","reached-{{*}}"]},r&&r.forEach(function(f){h.patterns.push("value-{{*}}-"+f)})):d&&(h=[{plug:"output",before:d.before,after:d.after,patterns:["{{*}}"]},{plug:"input",before:d.before,after:d.after,patterns:["type-{{*}}"]},{plug:"input",before:d.before,after:d.after,patterns:o?o.map(function(f){return"value-"+f+"-{{*}}"}):void 0}]),n.sendDynamicPorts(e,s,{renamed:h})}const States={node:StatesNode,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.States",function(n){n.parameters.states&&updatePorts$9(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",function(o){(o.name==="useTransitions"||o.name==="states"||o.name==="values"||o.name.startsWith("transition")||o.name.startsWith("type-"))&&updatePorts$9(n.id,n.parameters,e.editorConnection)})})}},ForEachActionsDefinition={name:"For Each Actions",docs:"https://docs.noodl.net/nodes/ui-controls/repeater-item",displayNodeName:"Repeater Item",category:"Data",color:"data",inputs:{removeCompleted:{type:{name:"boolean",allowConnectionsOnly:!0},displayName:"Remove Completed",group:"Events",valueChangedToTrue:function(){this._internal.removeCompletedCallback&&this._internal.removeCompletedCallback()}}},outputs:{added:{type:"signal",displayName:"Added",group:"Events"},tryRemove:{type:"signal",displayName:"Try Remove",group:"Events"},itemId:{type:"string",displayName:"Item Id",group:"General",get(){return this.getItemId()}}},prototypeExtensions:{getItemId(){const e=this.nodeScope.componentOwner._forEachModel;return e&&e.getId()},signalAdded:function(){this.sendSignalOnOutput("added")},tryRemove:function(e){this.getOutput("tryRemove").hasConnections()?(this._internal.removeCompletedCallback=e,this.sendSignalOnOutput("tryRemove")):this.scheduleAfterInputsHaveUpdated(function(){e()})},itemActionTriggered(e){this.scheduleAfterInputsHaveUpdated(()=>{const t=this.getItemId();this.nodeScope.componentOwner._forEachNode.signalItemAction(e,t,this._internal.actionParameters||{})})},setItemActionParameter(e){this._internal.actionParameters||(this._internal.actionParameters={}),this._internal.actionParameters[e]=e},registerInputIfNeeded:function(e){if(!this.hasInput(e)){if(e.startsWith("itemAction-"))return this.registerInput(e,{set:createSetter({valueChangedToTrue:this.itemActionTriggered.bind(this,e)})});if(e.startsWith("itemActionParameter-"))return this.registerInput(e,{set:this.setItemActionParameter.bind(this,e)})}}}},ForEachActions={node:ForEachActionsDefinition,setup:function(e,t){!e.editorConnection||e.editorConnection.isRunningLocally()}};function clamp(e,t,n){return Math.max(e,Math.min(t,n))}function setRGB(e,t){for(var n=0;n<3;++n){var o=1+n*2;e[n]=parseInt(t.substring(o,o+2),16)}}function componentToHex(e){var t=e.toString(16);return t.length==1?"0"+t:t}function rgbToHex(e){return"#"+componentToHex(e[0])+componentToHex(e[1])+componentToHex(e[2])}let rgb0=[0,0,0],rgb1=[0,0,0],rgb2=[0,0,0];const ColorBlendNode={name:"Color Blend",docs:"https://docs.noodl.net/nodes/utilities/color-blend",shortDesc:"Given any number of input colors this node can interpolate between these and give the result color as output.",category:"Interpolation",getInspectInfo(){return[{type:"color",value:this._internal.resultColor}]},initialize(){const e=this._internal;e.resultColor="#000000",e.blendValue=0,e.colors=[]},numberedInputs:{color:{type:"color",displayPrefix:"Color",createSetter(e){return function(t){this._internal.colors[e]=t,this.updateColor()}}}},inputs:{blendValue:{type:"number",displayName:"Blend Value",default:0,set:function(e){this._internal.blendValue=e,this.updateColor()}}},outputs:{result:{type:"color",displayName:"Result",getter:function(){return this._internal.resultColor}}},methods:{updateColor(){var e=this._internal.colors;if(e.length===0)return;function t(s){return e[s]?e[s]:"#000000"}var n=clamp(0,e.length-1,this._internal.blendValue),o=Math.floor(n),r=n-o;r===0?this._internal.resultColor=t(o):(setRGB(rgb0,t(o)),setRGB(rgb1,t(o+1)),rgb2[0]=Math.floor(EaseCurves.linear(rgb0[0],rgb1[0],r)),rgb2[1]=Math.floor(EaseCurves.linear(rgb0[1],rgb1[1],r)),rgb2[2]=Math.floor(EaseCurves.linear(rgb0[2],rgb1[2],r)),this._internal.resultColor=rgbToHex(rgb2)),this.flagOutputDirty("result")}}},ColorBlend={node:ColorBlendNode},defaultDuration$2=300,AnimateToValue={name:"net.noodl.animatetovalue",docs:"https://docs.noodl.net/nodes/logic/animate-to-value",displayName:"Animate To Value",shortDesc:"This node can interpolate smooothely from the current value to a target value.",category:"Animation",initialize:function(){var e=this,t=this._internal;t.currentNumber=0,t.numberInitialized=!1,t.animationStarted=!1,t.setCurrentNumberEnabled=!1,t.overrideValue=0,t._animation=this.context.timerScheduler.createTimer({duration:defaultDuration$2,startValue:0,endValue:0,ease:EaseCurves.easeOut,onStart:function(){t.animationStarted=!0},onRunning:function(n){t.currentNumber=this.ease(this.startValue,this.endValue,n),e.flagOutputDirty("currentValue")},onFinish:function(){e.sendSignalOnOutput("atTargetValue")}})},getInspectInfo(){return this._internal.currentNumber},inputs:{targetValue:{type:{name:"number"},displayName:"Target Value",group:"Target Value",default:void 0,set:function(e){if(e===!0?e=1:e===!1&&(e=0),e=Number(e),!isNaN(e)){var t=this._internal;if(t.numberInitialized===!1){t.currentNumber=e,t.numberInitialized=!0,t._animation.endValue=e,this.flagOutputDirty("currentValue");return}else if(e===t._animation.endValue)return;t._animation.startValue=t.currentNumber,t._animation.endValue=e,t._animation.start()}}},duration:{type:"number",group:"Parameters",displayName:"Duration",default:defaultDuration$2,set:function(e){this._internal._animation.duration=e}},delay:{type:"number",group:"Parameters",displayName:"Delay",default:0,set:function(e){this._internal._animation.delay=e}},easingCurve:{type:{name:"enum",enums:[{value:"easeOut",label:"Ease Out"},{value:"easeIn",label:"Ease In"},{value:"linear",label:"Linear"},{value:"easeInOut",label:"Ease In Out"}]},default:"easeOut",displayName:"Easing Curve",group:"Parameters",set:function(e){this._internal._animation.ease=EaseCurves[e]}}},outputs:{currentValue:{type:"number",displayName:"Current Value",group:"Current State",getter:function(){return this._internal.currentNumber}},atTargetValue:{type:"signal",displayName:"At Target Value",group:"Signals"}}},AnimateToValue$1={node:AnimateToValue},ComponentObject={name:"net.noodl.ComponentObject",displayNodeName:"Component Object",category:"Component Utilities",color:"component",docs:"https://docs.noodl.net/nodes/component-utilities/component-object",initialize:function(){this._internal.inputValues={},this._internal.dirtyValues={},this._internal.onModelChangedCallback=t=>{this.isInputConnected("fetch")===!1&&(this.hasOutput("value-"+t.name)&&this.flagOutputDirty("value-"+t.name),this.hasOutput("changed-"+t.name)&&this.sendSignalOnOutput("changed-"+t.name),this.sendSignalOnOutput("changed"))};const e=Model.get("componentState"+this.nodeScope.componentOwner.getInstanceId());this._internal.model=e,e.on("change",this._internal.onModelChangedCallback)},getInspectInfo(){return{type:"value",value:this._internal.model.data}},inputs:{properties:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Properties",group:"Properties",set(e){}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue(){this.scheduleFetch()}}},outputs:{changed:{type:"signal",displayName:"Changed",group:"Events"},fetched:{type:"signal",displayName:"Fetched",group:"Events"}},methods:{scheduleStore(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var e=this._internal;this.scheduleAfterInputsHaveUpdated(()=>{this.hasScheduledStore=!1;for(var t in e.dirtyValues)e.model.set(t,e.inputValues[t],{resolve:!0});e.dirtyValues={}})}},scheduleFetch(){this.hasScheduledFetch||(this.hasScheduledFetch=!0,this.scheduleAfterInputsHaveUpdated(()=>{this.hasScheduledFetch=!1,this.fetch()}))},fetch(){for(var e in this._internal.model.data)this.hasOutput("value-"+e)&&(this.flagOutputDirty("value-"+e),this.hasOutput("changed-"+e)&&this.sendSignalOnOutput("changed-"+e));this.sendSignalOnOutput("fetched")},_onNodeDeleted(){Node.prototype._onNodeDeleted.call(this),this._internal.model.off("change",this._internal.onModelChangedCallback)},registerOutputIfNeeded(e){if(this.hasOutput(e))return;const t=e.split("-"),n=t[t.length-1];this.registerOutput(e,{get(){return this._internal.model.get(n,{resolve:!0})}})},registerInputIfNeeded:function(e){if(!this.hasInput(e)&&e.startsWith("value-")){const t=e.substring(6);this.registerInput(e,{set(n){this._internal.inputValues[t]=n,this._internal.dirtyValues[t]=!0,this.scheduleStore()}})}}}};function updatePorts$8(e,t,n){const o=[];if(t.properties){var r=t.properties.split(",");for(var s in r){var a=r[s];o.push({type:{name:"*",allowConnectionsOnly:!0},plug:"input/output",group:"Properties",name:"value-"+a,displayName:a}),o.push({type:"signal",plug:"output",group:"Changed Events",displayName:a+" Changed",name:"changed-"+a})}}n.sendDynamicPorts(e,o,{detectRenamed:{plug:"input/output"}})}const ComponentObject$1={node:ComponentObject,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.net.noodl.ComponentObject",n=>{updatePorts$8(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",o=>{o.name==="properties"&&updatePorts$8(n.id,n.parameters,e.editorConnection)})})}},graphEventEmitter$1=new eventsExports.EventEmitter;graphEventEmitter$1.setMaxListeners(1e6);const ParentComponentObject={name:"net.noodl.ParentComponentObject",displayNodeName:"Parent Component Object",category:"Component Utilities",color:"component",docs:"https://docs.noodl.net/nodes/component-utilities/parent-component-object",initialize(){this._internal.inputValues={},this._internal.onModelChangedCallback=e=>{this.isInputConnected("fetch")===!1&&(this.hasOutput("value-"+e.name)&&this.flagOutputDirty("value-"+e.name),this.hasOutput("changed-"+e.name)&&this.sendSignalOnOutput("changed-"+e.name),this.sendSignalOnOutput("changed"))},this.onComponentStateNodesChanged=()=>{const e=this.findParentComponentStateModelId();this._internal.modelId!==e&&(this._internal.modelId=e,this.isInputConnected("fetch")===!1&&this.setModelId(this._internal.modelId))},graphEventEmitter$1.on("componentStateNodesChanged",this.onComponentStateNodesChanged),this.updateComponentState()},nodeScopeDidInitialize(){this._internal&&!this._internal.modelId&&this.context.scheduleAfterUpdate(()=>{this.updateComponentState()})},getInspectInfo(){if(!this._internal.model)return"No parent component state found";const t=[{type:"text",value:this._internal.parentComponentName}],n=this._internal.model.data;return t.concat(Object.keys(n).map(o=>({type:"text",value:o+": "+n[o]})))},inputs:{properties:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Properties",group:"Properties",set(e){}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue:function(){this.setModelId(this._internal.modelId)}}},outputs:{changed:{type:"signal",displayName:"Changed",group:"Events"},fetched:{type:"signal",displayName:"Fetched",group:"Events"}},methods:{updateComponentState(){this._internal.modelId=this.findParentComponentStateModelId(),this.isInputConnected("fetch")===!1&&this.setModelId(this._internal.modelId)},findParentComponentStateModelId(){function e(n){let o;if(n.getRoots().length>0){const r=n.getRoots()[0];r.getVisualParentNode?r.getVisualParentNode()&&(o=r.getVisualParentNode().nodeScope.componentOwner):r.parentNodeScope&&(o=n.parentNodeScope.componentOwner)}else n.parentNodeScope&&(o=n.parentNodeScope.componentOwner);if(o&&o.nodeScope&&o.nodeScope.componentOwner!==n)return o.nodeScope.getNodesWithType("net.noodl.ComponentObject").length>0?o:e(o)}const t=e(this.nodeScope.componentOwner);if(t)return this._internal.parentComponentName=t.name,"componentState"+t.getInstanceId()},setModelId(e){if(this._internal.model&&this._internal.model.off("change",this._internal.onModelChangedCallback),this._internal.model=void 0,!e)return;const t=Model.get(e);this._internal.model=t,t.on("change",this._internal.onModelChangedCallback);for(var n in t.data)this.hasOutput("value-"+n)&&this.flagOutputDirty("value-"+n),this.hasOutput("changed-"+n)&&this.sendSignalOnOutput("changed-"+n);this.sendSignalOnOutput("changed"),this.sendSignalOnOutput("fetched")},scheduleStore(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var e=this._internal;this.scheduleAfterInputsHaveUpdated(()=>{if(this.hasScheduledStore=!1,!!e.model)for(var t in e.inputValues)e.model.set(t,e.inputValues[t],{resolve:!0})})}},_onNodeDeleted(){Node.prototype._onNodeDeleted.call(this),graphEventEmitter$1.off("componentStateNodesChanged",this.onComponentStateNodesChanged),this._internal.model&&this._internal.model.off("change",this._internal.onModelChangedCallback)},registerOutputIfNeeded(e){if(this.hasOutput(e))return;const t=e.substring(6);this.registerOutput(e,{get(){if(this._internal.model)return this._internal.model.get(t,{resolve:!0})}})},registerInputIfNeeded:function(e){if(!this.hasInput(e)&&e.startsWith("value-")){const t=e.substring(6);this.registerInput(e,{set(n){this._internal.inputValues[t]=n,this.scheduleStore()}})}}}};function updatePorts$7(e,t,n){const o=[];var r=t.properties&&t.properties.split(",");for(var s in r){var a=r[s];o.push({type:{name:"*",allowConnectionsOnly:!0},plug:"input/output",group:"Properties",name:"value-"+a,displayName:a}),o.push({type:"signal",plug:"output",group:"Changed Events",displayName:a+" Changed",name:"changed-"+a})}n.sendDynamicPorts(e,o,{detectRenamed:{plug:"input/output"}})}const ParentComponentObject$1={node:ParentComponentObject,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||(t.on("nodeAdded.net.noodl.ParentComponentObject",n=>{updatePorts$7(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",o=>{updatePorts$7(n.id,n.parameters,e.editorConnection)})}),t.on("nodeAdded.net.noodl.ComponentObject",n=>{setTimeout(()=>{graphEventEmitter$1.emit("componentStateNodesChanged")},0)}),t.on("nodeRemoved.net.noodl.ComponentObject",n=>{setTimeout(()=>{graphEventEmitter$1.emit("componentStateNodesChanged")})}))}};function extendSetComponentObjectProperties(e){const t={name:e.name,displayNodeName:e.displayName,category:"Component Utilities",color:"component",docs:e.docs,initialize:function(){this._internal.inputValues={}},inputs:{properties:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Properties",group:"Properties",set(o){}},store:{type:"signal",group:"Actions",displayName:"Do",valueChangedToTrue(){this.scheduleStore()}}},outputs:{stored:{type:"signal",group:"Events",displayName:"Done"}},methods:{getComponentObjectId:e.getComponentObjectId,scheduleStore(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var o=this._internal;this.scheduleAfterInputsHaveUpdated(()=>{const r=Model.get(this.getComponentObjectId());this.hasScheduledStore=!1;const a=(this.model.parameters.properties||"").split(","),l=Object.keys(o.inputValues).filter(u=>a.indexOf(u)!==-1);for(const u of l)r.set(u,o.inputValues[u],{resolve:!0});this.sendSignalOnOutput("stored")})}},registerInputIfNeeded:function(o){if(!this.hasInput(o))if(o.startsWith("prop-")){const r=o.substring(5);this.registerInput(o,{set(s){this._internal.inputValues[r]=s}})}else o.startsWith("type-")&&this.registerInput(o,{set(r){}})}}};function n(o,r,s){var a=[];const l=[{label:"String",value:"string"},{label:"Boolean",value:"boolean"},{label:"Number",value:"number"},{label:"Date",value:"date"},{label:"Array",value:"array"},{label:"Object",value:"object"},{label:"Any",value:"*"}];var u=r.properties;if(u){u=u?u.split(","):void 0;for(var d in u){var h=u[d];a.push({type:{name:r["type-"+h]===void 0?"*":r["type-"+h]},plug:"input",group:"Property Values",displayName:h,name:"prop-"+h}),a.push({type:{name:"enum",enums:l,allowEditOnly:!0},plug:"input",group:"Property Types",displayName:h,default:"*",name:"type-"+h})}}s.sendDynamicPorts(o,a,{detectRenamed:{plug:"input"}})}return{node:t,setup:function(o,r){!o.editorConnection||!o.editorConnection.isRunningLocally()||r.on("nodeAdded."+e.name,s=>{n(s.id,s.parameters,o.editorConnection),s.on("parameterUpdated",a=>{(a.name==="properties"||a.name.startsWith("type-"))&&n(s.id,s.parameters,o.editorConnection)})})}}}const Base={extendSetComponentObjectProperties},SetComponentObjectProperties=Base.extendSetComponentObjectProperties({name:"net.noodl.SetComponentObjectProperties",displayName:"Set Component Object Properties",docs:"https://docs.noodl.net/nodes/component-utilities/set-component-object-properties",getComponentObjectId:function(){return"componentState"+this.nodeScope.componentOwner.getInstanceId()}}),SetParentComponentObjectProperties=Base.extendSetComponentObjectProperties({name:"net.noodl.SetParentComponentObjectProperties",displayName:"Set Parent Component Object Properties",docs:"https://docs.noodl.net/nodes/component-utilities/set-parent-component-object-properties",getComponentObjectId:function(){function e(n){let o;if(n.getRoots().length>0){const r=n.getRoots()[0];r.getVisualParentNode?r.getVisualParentNode()&&(o=r.getVisualParentNode().nodeScope.componentOwner):r.parentNodeScope&&(o=n.parentNodeScope.componentOwner)}else n.parentNodeScope&&(o=n.parentNodeScope.componentOwner);if(o&&o.nodeScope&&o.nodeScope.componentOwner!==n)return o.nodeScope.getNodesWithType("net.noodl.ComponentObject").length>0?o:e(o)}const t=e(this.nodeScope.componentOwner);if(t)return this._internal.parentComponentName=t.name,"componentState"+t.getInstanceId()}}),VariableNodeDefinition$1={name:"Variable2",displayNodeName:"Variable",docs:"https://docs.noodl.net/nodes/data/variable/variable-node",category:"Data",usePortAsLabel:"name",color:"data",initialize:function(){var e=this,t=this._internal;this._internal.onModelChangedCallback=function(n){!e.isInputConnected("fetch")&&n.name===t.name&&(e.sendSignalOnOutput("changed"),e.flagOutputDirty("value"))},t.variablesModel=Model.get("--ndl--global-variables"),t.variablesModel.on("change",this._internal.onModelChangedCallback)},getInspectInfo(){return this._internal.name?this._internal.variablesModel.get(this._internal.name):"[No value set]"},outputs:{name:{type:"string",displayName:"Name",group:"General",getter:function(){return this._internal.name}},changed:{type:"signal",displayName:"Changed",group:"Events"},fetched:{type:"signal",displayName:"Fetched",group:"Events"},value:{type:"*",displayName:"Value",group:"General",getter:function(){var e=this._internal;if(e.name)return e.variablesModel.get(e.name)}}},inputs:{name:{type:{name:"string",identifierOf:"VariableName",identifierDisplayName:"Variable names"},displayName:"Name",group:"General",set:function(e){this.isInputConnected("fetch")===!1?this.setVariableName(e):(this._internal.name=e,this.flagOutputDirty("name"))}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue:function(){this.setVariableName(this._internal.name)}},value:{type:"*",displayName:"Value",group:"General",set:function(e){this._internal.value=e,this.scheduleStore()}}},prototypeExtensions:{scheduleStore:function(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var e=this._internal;this.scheduleAfterInputsHaveUpdated(function(){this.hasScheduledStore=!1,e.variablesModel.set(e.name,e.value)})}},setVariableName:function(e){this._internal.name=e,this.flagOutputDirty("name"),this.flagOutputDirty("value"),this.sendSignalOnOutput("fetched")},_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this._internal.variablesModel.off("change",this._internal.onModelChangedCallback)}}},VariableNode2={node:VariableNodeDefinition$1},SetVariableNodeDefinition={name:"Set Variable",docs:"https://docs.noodl.net/nodes/data/variable/set-variable",category:"Data",usePortAsLabel:"name",color:"data",initialize:function(){const e=this._internal;e.variablesModel=Model.get("--ndl--global-variables")},getInspectInfo(){return this._internal.name?this._internal.variablesModel.get(this._internal.name):"[No value set]"},outputs:{done:{type:"signal",displayName:"Done",group:"Events"}},inputs:{name:{type:{name:"string",identifierOf:"VariableName",identifierDisplayName:"Variable names"},displayName:"Name",group:"General",set:function(e){this._internal.name=e}},setWith:{type:{name:"enum",enums:[{label:"String",value:"string"},{label:"Boolean",value:"boolean"},{label:"Number",value:"number"},{label:"Empty string",value:"emptyString"},{label:"Date",value:"date"},{label:"Object",value:"object"},{label:"Array",value:"array"},{label:"Any",value:"*"}],allowEditOnly:!0},displayName:"Set as",default:"*",group:"General",set:function(e){this._internal.setWith=e}},do:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){this.scheduleStore()}}},methods:{setValue:function(e){this._internal.value=e},scheduleStore:function(){if(this.hasScheduledStore)return;this.hasScheduledStore=!0;const e=this._internal;this.scheduleAfterInputsHaveUpdated(function(){this.hasScheduledStore=!1;let t=e.setWith==="emptyString"?"":e.value;e.setWith==="object"&&typeof t=="string"&&(t=Model.get(t)),e.setWith==="array"&&typeof t=="string"&&(t=Collection.get(t)),e.setWith==="boolean"&&(t=!!t),e.variablesModel.set(e.name,t,{forceChange:!0}),this.sendSignalOnOutput("done")})},registerInputIfNeeded:function(e){this.hasInput(e)||e==="value"&&this.registerInput(e,{set:this.setValue.bind(this)})}}},SetVariableNode={node:SetVariableNodeDefinition,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.Set Variable",function(n){function o(){var r=[];n.parameters.setWith==="emptyString"||r.push({type:n.parameters.setWith!==void 0?n.parameters.setWith:"*",plug:"input",group:"General",name:"value",displayName:"Value"}),e.editorConnection.sendDynamicPorts(n.id,r)}o(),n.on("parameterUpdated",function(r){o()})})}};var CollectionNode$2={name:"Collection2",docs:"https://docs.noodl.net/nodes/data/array/array-node",displayNodeName:"Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",usePortAsLabel:"collectionId",color:"data",initialize:function(){var e=this,t=!1;this._internal.collectionChangedCallback=function(){e.isInputConnected("fetch")!==!0&&(t||(t=!0,e.scheduleAfterInputsHaveUpdated(function(){e.sendSignalOnOutput("changed"),e.flagOutputDirty("firstItemId"),e.flagOutputDirty("count"),t=!1})))},this._internal.sourceCollectionChangedCallback=function(){e.isInputConnected("store")!==!0&&e.scheduleCopyItems()}},getInspectInfo(){const e=this._internal.collection;return e?[{type:"text",value:"Id: "+e.getId()},{type:"value",value:e.items}]:{type:"text",value:"[No Array]"}},inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this._internal.collectionId=e,this.isInputConnected("fetch")===!1?this.setCollectionID(e):this.flagOutputDirty("id")}},items:{type:"array",group:"General",displayName:"Items",set:function(e){var t=this;e!==void 0&&e!==this._internal.collection&&(this._internal.pendingSourceCollection=e,this.isInputConnected("store")===!1&&this.scheduleAfterInputsHaveUpdated(function(){t.setSourceCollection(e)}))}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue:function(){this.scheduleSetCollection()}}},outputs:{id:{type:"string",displayName:"Id",group:"General",getter:function(){return this._internal.collection?this._internal.collection.getId():this._internal.collectionId}},items:{type:"array",displayName:"Items",group:"General",getter:function(){return this._internal.collection}},firstItemId:{type:"string",displayName:"First Item Id",group:"General",getter:function(){if(this._internal.collection){var e=this._internal.collection.get(0);if(e!==void 0)return e.getId()}}},count:{type:"number",displayName:"Count",group:"General",getter:function(){return this._internal.collection?this._internal.collection.size():0}},changed:{group:"Events",type:"signal",displayName:"Changed"},fetched:{group:"Events",type:"signal",displayName:"Fetched"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection&&this._internal.collection.off("change",this._internal.collectionChangedCallback),this._internal.collection=e,this.flagOutputDirty("id"),e.on("change",this._internal.collectionChangedCallback),this.flagOutputDirty("items"),this.flagOutputDirty("firstItemId"),this.flagOutputDirty("count")},setSourceCollection:function(e){var t=this._internal;t.sourceCollection&&t.sourceCollection instanceof Collection&&t.sourceCollection.off("change",t.sourceCollectionChangedCallback),t.sourceCollection=e,t.sourceCollection instanceof Collection&&t.sourceCollection.on("change",t.sourceCollectionChangedCallback),this._copySourceItems()},scheduleSetCollection:function(){var e=this;this.hasScheduledSetCollection||(this.hasScheduledSetCollection=!0,this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledSetCollection=!1,e.setCollectionID(e._internal.collectionId),e.sendSignalOnOutput("fetched")}))},scheduleStore:function(){var e=this;if(!this.hasScheduledStore){this.hasScheduledStore=!0;var t=this._internal;this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledStore=!1,e.setSourceCollection(t.pendingSourceCollection)})}},_copySourceItems:function(){var e=this._internal;e.collection===void 0&&this.isInputConnected("fetch")===!1&&this.setCollection(Collection.get()),e.collection&&e.collection.set(e.sourceCollection)},scheduleCopyItems:function(){var e=this;this._internal,!this.hasScheduledCopyItems&&(this.hasScheduledCopyItems=!0,this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledCopyItems=!1,e._copySourceItems()}))},_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this._internal.collection&&this._internal.collection.off("change",this._internal.collectionChangedCallback)}}};const CollectionNode2={node:CollectionNode$2};var CollectionInsertNode={name:"CollectionInsert",docs:"https://docs.noodl.net/nodes/data/array/insert-into-array",displayNodeName:"Insert Object Into Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",usePortAsLabel:"collectionId",color:"data",initialize:function(){},inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Array Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this.setCollectionID(e)}},modifyId:{type:{name:"string",allowConnectionsOnly:!0},displayName:"Object Id",group:"Modify",set:function(e){this._internal.modifyId=e}},add:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){var e=this,t=this._internal;this.scheduleAfterInputsHaveUpdated(function(){if(this.context.editorConnection&&this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"insert-warning"),t.modifyId===void 0){this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"insert-warning",{showGlobally:!0,message:"No Object Id specified"});return}if(t.collection===void 0){this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"insert-warning",{showGlobally:!0,message:"No Array Id specified"});return}var n=Model.get(t.modifyId);t.collection.add(n),e.sendSignalOnOutput("modified")})}}},outputs:{modified:{group:"Events",type:"signal",displayName:"Done"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e}}};const CollectionNodeInsert={node:CollectionInsertNode};var CollectionRemoveNode={name:"CollectionRemove",docs:"https://docs.noodl.net/nodes/data/array/remove-from-array",displayNodeName:"Remove Object From Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",usePortAsLabel:"collectionId",color:"data",initialize:function(){},inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Array Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this.setCollectionID(e)}},modifyId:{type:{name:"string",allowConnectionsOnly:!0},displayName:"Object Id",group:"Modify",set:function(e){this._internal.modifyId=e}},remove:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){var e=this,t=this._internal;this.scheduleAfterInputsHaveUpdated(function(){if(t.modifyId!==void 0&&t.collection!==void 0){var n=Model.get(t.modifyId);t.collection.remove(n),e.sendSignalOnOutput("modified")}})}}},outputs:{modified:{group:"Events",type:"signal",displayName:"Done"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e}}};const CollectionNodeRemove={node:CollectionRemoveNode},CollectionClearNode={name:"CollectionClear",docs:"https://docs.noodl.net/nodes/data/array/clear-array",displayNodeName:"Clear Array",category:"Data",usePortAsLabel:"collectionId",color:"data",inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Array Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this.setCollectionID(e)}},clear:{displayName:"Do",group:"Actions",valueChangedToTrue(){this.scheduleAfterInputsHaveUpdated(()=>{this._internal.collection.set([]),this.sendSignalOnOutput("modified")})}}},outputs:{modified:{group:"Events",type:"signal",displayName:"Done"}},methods:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e}}},CollectionNodeClear={node:CollectionClearNode};var CollectionNewNode={name:"CollectionNew",docs:"https://docs.noodl.net/nodes/data/array/create-new-array",displayNodeName:"Create New Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",color:"data",initialize:function(){},inputs:{new:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){this.scheduleNew()}},items:{type:"array",group:"General",displayName:"Items",set:function(e){this._internal.sourceCollection=e}}},outputs:{id:{type:"string",displayName:"Id",group:"General",getter:function(){return this._internal.collection?this._internal.collection.getId():this._internal.collectionId}},created:{group:"Events",type:"signal",displayName:"Done"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e,this.flagOutputDirty("id")},scheduleNew:function(){var e=this;this.hasScheduledNew||(this.hasScheduledNew=!0,this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledNew=!1;const t=Collection.get();this._internal.sourceCollection!==void 0&&t.set(this._internal.sourceCollection),e.setCollection(t),e.sendSignalOnOutput("created")}))}}};const CollectionNodeNew={node:CollectionNewNode};function applyFilter(e,t){for(var n in t){var o=t[n];if(o.$neq!==void 0){if(e[n]==o.$neq)return!1}else{if(e[n]===void 0)return!1;if(o.$eq!==void 0&&e[n]!=o.$eq)return!1;if(o.$gt!==void 0&&!(e[n]>o.$gt))return!1;if(o.$lt!==void 0&&!(e[n]<o.$lt))return!1;if(o.$gte!==void 0&&!(e[n]>=o.$gte))return!1;if(o.$lte!==void 0&&!(e[n]<=o.$lte))return!1;if(o.$regex!==void 0){var r=e[n]+"",s=new RegExp(o.$regex,o.$case!==!0?"i":void 0);if(!s.test(r))return!1}}}return!0}function sorter(e,t){e instanceof Model&&(e=e.data),t instanceof Model&&(t=t.data);for(var n in this){var o=e[n],r=t[n];if(o!==r)return typeof o=="string"&&typeof r=="string"?this[n]===1?o>r?1:-1:o>r?-1:1:typeof o=="number"&&typeof r=="number"?this[n]===1?o-r:r-o:this[n]===1?o>r?1:-1:o>r?-1:1}return 0}var FilterCollectionNode={name:"Filter Collection",docs:"https://docs.noodl.net/nodes/data/array/array-filter",displayNodeName:"Array Filter",shortDesc:"Filter, sort and limit array",category:"Data",color:"data",initialize:function(){var e=this;this._internal.collectionChangedCallback=function(){e.isInputConnected("filter")!==!0&&e.scheduleFilter()},this._internal.enabled=!0,this._internal.filterSettings={}},getInspectInfo(){const e=this._internal.filteredCollection;return e?[{type:"text",value:"Id: "+e.getId()},{type:"value",value:e.items}]:{type:"text",value:"[Not executed yet]"}},inputs:{items:{type:"array",displayName:"Items",group:"General",set(e){this.bindCollection(e),this.isInputConnected("filter")===!1&&this.scheduleFilter()}},enabled:{type:"boolean",group:"General",displayName:"Enabled",default:!0,set:function(e){this._internal.enabled=e,this.isInputConnected("filter")===!1&&this.scheduleFilter()}},filter:{type:"signal",group:"Actions",displayName:"Filter",valueChangedToTrue:function(){this.scheduleFilter()}}},outputs:{items:{type:"array",displayName:"Items",group:"General",getter:function(){return this._internal.filteredCollection}},firstItemId:{type:"string",displayName:"First Item Id",group:"General",getter:function(){if(this._internal.filteredCollection!==void 0){const e=this._internal.filteredCollection.get(0);if(e!==void 0)return e.getId()}}},count:{type:"number",displayName:"Count",group:"General",getter:function(){return this._internal.filteredCollection?this._internal.filteredCollection.size():0}},modified:{group:"Events",type:"signal",displayName:"Filtered"}},prototypeExtensions:{unbindCurrentCollection:function(){var e=this._internal.collection;e&&(e.off("change",this._internal.collectionChangedCallback),this._internal.collection=void 0)},bindCollection:function(e){this.unbindCurrentCollection(),this._internal.collection=e,e&&e.on("change",this._internal.collectionChangedCallback)},_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this.unbindCurrentCollection()},getFilter:function(){const e=this._internal.filterSettings,t=["case"];if(e.filterFilter){const o=e.filterFilter.split(",");var n={};return o.forEach(function(r){var s="$"+(e["filterFilterOp-"+r]||"eq");n[r]={},n[r][s]=e["filterFilterValue-"+r],t.forEach(a=>{var l=e["filterFilterOption-"+a+"-"+r];l&&(n[r]["$"+a]=l)})}),n}},getSort:function(){const e=this._internal.filterSettings;if(e.filterSort){const n=e.filterSort.split(",");var t={};return n.forEach(function(o){t[o]=e["filterSort-"+o]==="descending"?-1:1}),t}},getLimit:function(){const e=this._internal.filterSettings;if(e.filterEnableLimit)return e.filterLimit||10},getSkip:function(){const e=this._internal.filterSettings;if(e.filterEnableLimit)return e.filterSkip||0},scheduleFilter:function(){this.collectionChangedScheduled||(this.collectionChangedScheduled=!0,this.scheduleAfterInputsHaveUpdated(()=>{if(this.collectionChangedScheduled=!1,!!this._internal.collection){var e=[].concat(this._internal.collection.items);if(this._internal.enabled){var t=this.getFilter();t&&(e=e.filter(s=>applyFilter(s.data,t)));var n=this.getSort();n&&e.sort(sorter.bind(n));var o=this.getSkip();o&&(e=e.slice(o,e.length));var r=this.getLimit();r&&(e=e.slice(0,r))}this._internal.filteredCollection=Collection.create(e),this.sendSignalOnOutput("modified"),this.flagOutputDirty("firstItemId"),this.flagOutputDirty("items"),this.flagOutputDirty("count")}}))},registerInputIfNeeded:function(e){this.hasInput(e)||this.registerInput(e,{set:userInputSetter$3.bind(this,e)})}}};function userInputSetter$3(e,t){this._internal.filterSettings[e]=t,this.isInputConnected("filter")===!1&&this.scheduleFilter()}function updatePorts$6(e,t,n,o){var r=[];r.push({type:"boolean",plug:"input",group:"Limit",name:"filterEnableLimit",displayName:"Use limit"}),t.filterEnableLimit&&(r.push({type:"number",default:10,plug:"input",group:"Limit",name:"filterLimit",displayName:"Limit"}),r.push({type:"number",default:0,plug:"input",group:"Limit",name:"filterSkip",displayName:"Skip"})),r.push({type:{name:"stringlist",allowEditOnly:!0},plug:"input",group:"Filter",name:"filterFilter",displayName:"Filter"}),r.push({type:{name:"stringlist",allowEditOnly:!0},plug:"input",group:"Sort",name:"filterSort",displayName:"Sort"});const s={string:[{value:"eq",label:"Equals"},{value:"neq",label:"Not Equals"},{value:"regex",label:"Matches RegEx"}],boolean:[{value:"eq",label:"Equals"},{value:"neq",label:"Not Equals"}],number:[{value:"eq",label:"Equals"},{value:"neq",label:"Not Equals"},{value:"lt",label:"Less than"},{value:"gt",label:"Greater than"},{value:"gte",label:"Greater than or equal"},{value:"lte",label:"Less than or equal"}]};if(t.filterFilter){var a=t.filterFilter.split(",");a.forEach(l=>{r.push({type:{name:"enum",enums:[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"}]},default:"string",plug:"input",group:l+" filter",displayName:"Type",editorName:l+" filter | Type",name:"filterFilterType-"+l});var u=t["filterFilterType-"+l];r.push({type:{name:"enum",enums:s[u||"string"]},default:"eq",plug:"input",group:l+" filter",displayName:"Op",editorName:l+" filter| Op",name:"filterFilterOp-"+l}),t["filterFilterOp-"+l]==="regex"&&r.push({type:"boolean",default:!1,plug:"input",group:l+" filter",displayName:"Case sensitive",editorName:l+" filter| Case",name:"filterFilterOption-case-"+l}),r.push({type:u||"string",plug:"input",group:l+" filter",displayName:"Value",editorName:l+" Filter Value",name:"filterFilterValue-"+l})})}if(t.filterSort){var a=t.filterSort.split(",");a.forEach(u=>{r.push({type:{name:"enum",enums:[{value:"ascending",label:"Ascending"},{value:"descending",label:"Descending"}]},default:"ascending",plug:"input",group:u+" sort",displayName:"Sort",editorName:u+" sorting",name:"filterSort-"+u})})}n.sendDynamicPorts(e,r)}const FilterCollectionNode$1={node:FilterCollectionNode,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.Filter Collection",function(n){updatePorts$6(n.id,n.parameters,e.editorConnection,t.getMetaData("dbCollections")),n.on("parameterUpdated",function(o){o.name.startsWith("filter")&&updatePorts$6(n.id,n.parameters,e.editorConnection,t.getMetaData("dbCollections"))}),t.on("metadataChanged.dbCollections",function(o){updatePorts$6(n.id,n.parameters,e.editorConnection)})})}};function CSVToArray(e,t){t=t||",";for(var n=new RegExp("(\\"+t+'|\\r?\\n|\\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^"\\'+t+"\\r\\n]*))","gi"),o=[[]],r=null,s;(r=n.exec(e))&&s!==n.lastIndex;){s=n.lastIndex;var a=r[1];a.length&&a!==t&&o.push([]);var l;r[2]?l=r[2].replace(new RegExp('""',"g"),'"'):l=r[3],o[o.length-1].push(l)}return o}var CSVNode={name:"Static Data",docs:"https://docs.noodl.net/nodes/data/array/static-array",displayNodeName:"Static Array",shortDesc:"Store static data to populate a Collection with items.",category:"Data",color:"data",nodeDoubleClickAction:[{focusPort:"JSON"},{focusPort:"CSV"}],getInspectInfo(){if(this._internal.collection)return[{type:"value",value:this._internal.collection.items}]},dynamicports:[{name:"conditionalports/extended",condition:"type = csv OR type NOT SET",inputs:["csv"]},{name:"conditionalports/extended",condition:"type = json",inputs:["json"]}],inputs:{type:{type:{name:"enum",enums:[{label:"CSV",value:"csv"},{label:"JSON",value:"json"}],allowEditOnly:!0},displayName:"Type",group:"General",default:"csv",set:function(e){this._internal.type=e}},csv:{type:{name:"string",codeeditor:"text",allowEditOnly:!0},displayName:"CSV",group:"General",set:function(e){this._internal.csv=e,this.scheduleParseData()}},json:{type:{name:"string",codeeditor:"json",allowEditOnly:!0},displayName:"JSON",group:"General",set:function(e){this._internal.json=e,this.scheduleParseData()}}},outputs:{items:{type:"array",displayName:"Items",group:"General",getter:function(){return this._internal.collection}},count:{type:"number",displayName:"Count",group:"General",get(){return this._internal.collection?this._internal.collection.size():0}}},methods:{scheduleParseData:function(){var e=this._internal;e.hasScheduledParseData||(e.hasScheduledParseData=!0,this.scheduleAfterInputsHaveUpdated(this.parseData.bind(this)))},parseData:function(){var e=this._internal;if(e.hasScheduledParseData=!1,e.collection=Collection.get(),e.type===void 0||e.type==="csv"){for(var t=CSVToArray(e.csv),n=[],o=t[0],r=1;r<t.length;r++){for(var s=t[r],a={},l=0;l<o.length;l++)a[o[l]]=s[l];n.push(a)}e.collection.set(n),this.flagOutputDirty("items"),this.flagOutputDirty("count")}else if(e.type==="json"){this.context.editorConnection&&this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"json-parse-warning");try{const u=JSON.parse(e.json);e.collection.set(u),this.flagOutputDirty("items"),this.flagOutputDirty("count")}catch(u){this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"json-parse-warning",{showGlobally:!0,message:u.message})}}}}};const StaticData={node:CSVNode},defaultMapCode=`map({
172
+ `}function Range(e){const[t,n]=React.useState(e.value);React.useEffect(()=>{n(e.value)},[]),React.useEffect(()=>{n(e.value)},[e.value]);var o={...e.style};Layout.size(o,e),Layout.align(o,e);const r={id:e.id,min:e.min,max:e.max,step:e.step,style:o};Utils.updateStylesForClass("ndl-controls-range-"+e._nodeId,e,_styleTemplate);let s="ndl-controls-range-"+e._nodeId+" ndl-controls-range";return e.className&&(s=s+" "+e.className),React.createElement("input",{className:s,...Utils.controlEvents(e),type:"range",...r,value:t,disabled:!e.enabled,onChange:a=>{n(a.target.value),e.valueChanged&&e.valueChanged(a.target.value)}})}var RangeNode={name:"Range",docs:"https://docs.noodl.net/nodes/visual/range",allowChildren:!1,noodlNodeAsProp:!0,initialize(){this.props.sizeMode="explicit",this.props.id=this._internal.controlId="input-"+guid(),this.props.enabled=this._internal.enabled=!0,this._internal.value=this.props.value=this.props.min,this.props._nodeId=this.id,this.props.valueChanged=e=>{e=typeof e=="string"?parseFloat(e):e;const t=this._internal.value!==e;this._internal.value=e,this._updateValuePercent(e),t&&(this.flagOutputDirty("value"),this.sendSignalOnOutput("onChange"))},this.props.valueChanged(this.props.value),this.outputPropValues.hoverState=this.outputPropValues.focusState=this.outputPropValues.pressedState=!1},getReactComponent(){return Range},inputs:{enabled:{type:"boolean",displayName:"Enabled",group:"General",default:!0,set:function(e){e=!!e;const t=e!==this._internal.enabled;this.props.enabled=this._internal.enabled=e,t&&(this.forceUpdate(),this.flagOutputDirty("enabled"))}},value:{type:"string",displayName:"Value",group:"General",set:function(e){const t=e!==this._internal.value;this.props.value=this._internal.value=e,this._updateValuePercent(e),t&&(this.forceUpdate(),this.flagOutputDirty("value"))}}},outputs:{controlId:{type:"string",displayName:"Control Id",group:"General",getter:function(){return this._internal.controlId}},enabled:{type:"boolean",displayName:"Enabled",group:"States",getter:function(){return this._internal.enabled}},value:{type:"number",displayName:"Value",group:"States",getter:function(){return this._internal.value}},valuePercent:{type:"number",displayName:"Value Percent",group:"States",getter:function(){return this._internal.valuePercent}},onChange:{type:"signal",displayName:"Changed",group:"Events"}},inputProps:{min:{type:"number",displayName:"Min",group:"General",default:0},max:{type:"number",displayName:"Max",group:"General",default:100},step:{type:"number",displayName:"Step",group:"General",default:1},width:{index:11,group:"Dimensions",displayName:"Width",type:{name:"number",units:["%","px","vw"],defaultUnit:"%"},default:100},height:{index:12,group:"Dimensions",displayName:"Height",type:{name:"number",units:["%","px","vh"],defaultUnit:"%"},default:100},thumbWidth:{group:"Thumb Style",displayName:"Width",type:{name:"number",units:["px","vw","%"],defaultUnit:"px",allowEditOnly:!0},default:16},thumbHeight:{group:"Thumb Style",displayName:"Height",type:{name:"number",units:["px","vh","%"],defaultUnit:"px",allowEditOnly:!0},default:16},thumbRadius:{group:"Thumb Style",displayName:"Radius",type:{name:"number",units:["px","%"],defaultUnit:"px",allowEditOnly:!0},default:8},thumbColor:{group:"Thumb Style",displayName:"Color",type:{name:"color",allowEditOnly:!0},default:"#000000"},trackHeight:{group:"Track Style",displayName:"Height",type:{name:"number",units:["px","vh","%"],defaultUnit:"px",allowEditOnly:!0},default:6},trackColor:{group:"Track Style",displayName:"Color",type:{name:"color",allowEditOnly:!0},default:"#f0f0f0"}},inputCss:{backgroundColor:{index:201,displayName:"Background Color",group:"Style",type:"color"},borderRadius:{index:202,displayName:"Border Radius",group:"Style",type:{name:"number",units:["px"],defaultUnit:"px"},default:1,applyDefault:!1},borderStyle:{index:203,displayName:"Border Style",group:"Style",type:{name:"enum",enums:[{label:"None",value:"none"},{label:"Solid",value:"solid"},{label:"Dotted",value:"dotted"},{label:"Dashed",value:"dashed"}]},default:"none",applyDefault:!1},borderWidth:{index:204,displayName:"Border Width",group:"Style",type:{name:"number",units:["px"],defaultUnit:"px"},default:1,applyDefault:!1},borderColor:{index:205,displayName:"Border Color",group:"Style",type:"color",default:"#000000"}},outputProps:{},methods:{_updateValuePercent(e){const t=this.props.min,n=this.props.max,o=Math.floor((e-t)/(n-t)*100),r=this._internal.valuePercentChanged!==o;this._internal.valuePercent=o,r&&this.flagOutputDirty("valuePercent")}}};NodeSharedPortDefinitions.addAlignInputs(RangeNode),NodeSharedPortDefinitions.addTransformInputs(RangeNode),NodeSharedPortDefinitions.addMarginInputs(RangeNode),NodeSharedPortDefinitions.addSharedVisualInputs(RangeNode),Utils.addControlEventsAndStates(RangeNode),RangeNode=createNodeFromReactComponent(RangeNode);const RangeOld=RangeNode;function preventGlobalFocusChange(e){e.stopPropagation(),window.removeEventListener("click",preventGlobalFocusChange,!0)}class TextFieldComponent extends React.Component{constructor(t){super(t),this.state={value:t.startValue},this.ref=React.createRef()}setText(t){this.setState({value:t}),this.props.onTextChanged&&this.props.onTextChanged(t)}componentDidMount(){this.ref.current.noodlNode=this.props.noodlNode,this.setText(this.props.startValue)}render(){const t={...this.props.textStyle,...this.props.style};Layout.size(t,this.props),Layout.align(t,this.props),t.opacity===0&&(t.pointerEvents="none");const n=this.props,o={id:n.id,value:this.state.value,...Utils.controlEvents(n),disabled:!n.enabled,style:t,className:n.className,placeholder:n.placeholder,onChange:r=>this.onChange(r)};return this.props.type!=="textArea"?React.createElement("input",{ref:this.ref,type:this.props.type,...o,onKeyDown:r=>this.onKeyDown(r),onMouseDown:()=>window.addEventListener("click",preventGlobalFocusChange,!0)}):(o.style.resize="none",React.createElement("textarea",{ref:this.ref,...o,onKeyDown:r=>this.onKeyDown(r)}))}onKeyDown(t){(t.key==="Enter"||t.which===13)&&this.props.onEnter&&this.props.onEnter()}onChange(t){const n=t.target.value;this.setText(n)}focus(){this.ref.current&&this.ref.current.focus()}blur(){this.ref.current&&this.ref.current.blur()}}const TextInput={name:"Text Input",docs:"https://docs.noodl.net/nodes/visual/text-input",allowChildren:!1,noodlNodeAsProp:!0,getReactComponent(){return TextFieldComponent},defaultCss:{outline:"none",borderStyle:"solid",padding:0},initialize(){this.props.startValue="",this.props.id=this._internal.controlId="input-"+guid(),this.props.enabled=this._internal.enabled=!0,this.outputPropValues.hoverState=this.outputPropValues.focusState=this.outputPropValues.pressedState=!1},inputProps:{type:{displayName:"Type",group:"Text",index:19,type:{name:"enum",enums:[{label:"Text",value:"text"},{label:"Text Area",value:"textArea"},{label:"Email",value:"email"},{label:"Number",value:"number"},{label:"Password",value:"password"},{label:"URL",value:"url"}]},default:"text"},placeholder:{index:22,group:"Text",displayName:"Placeholder",default:"Type here...",type:{name:"string"}},boxShadowEnabled:{index:250,group:"Box Shadow",displayName:"Shadow Enabled",type:"boolean",default:!1},boxShadowOffsetX:{index:251,group:"Box Shadow",displayName:"Offset X",default:0,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowOffsetY:{index:252,group:"Box Shadow",displayName:"Offset Y",default:0,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowBlurRadius:{index:253,group:"Box Shadow",displayName:"Blur Radius",default:5,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowSpreadRadius:{index:254,group:"Box Shadow",displayName:"Spread Radius",default:2,type:{name:"number",units:["px"],defaultUnit:"px"}},boxShadowInset:{index:255,group:"Box Shadow",displayName:"Inset",type:"boolean",default:!1},boxShadowColor:{index:256,group:"Box Shadow",displayName:"Shadow Color",type:"color",default:"rgba(0,0,0,0.2)"}},inputs:{enabled:{type:"boolean",displayName:"Enabled",group:"General",default:!0,set:function(e){e=!!e;const t=e!==this._internal.enabled;this.props.enabled=this._internal.enabled=e,t&&(this.forceUpdate(),this.flagOutputDirty("enabled"))}},set:{group:"Actions",displayName:"Set",type:"signal",valueChangedToTrue(){this.scheduleAfterInputsHaveUpdated(()=>{this.setText(this._internal.text)})}},startValue:{index:18,displayName:"Text",type:"string",group:"Text",set(e){this._internal.text!==e&&(this._internal.text=e,this.isInputConnected("set")===!1&&this.setText(e))}},textStyle:{index:19,type:"textStyle",group:"Text",displayName:"Text Style",default:"None",set(e){this.props.textStyle=this.context.styles.getTextStyle(e),this.forceUpdate()}},fontFamily:{index:20,type:"font",group:"Text",displayName:"Font Family",set(e){if(e){let t=e;t.split(".").length>1&&(t=t.replace(/\.[^/.]+$/,""),t=t.split("/").pop()),this.setStyle({fontFamily:t})}else this.removeStyle(["fontFamily"]);this.props.textStyle&&this.forceUpdate()}},clear:{type:"signal",group:"Actions",displayName:"Clear",valueChangedToTrue(){this.setText("")}},focus:{type:"signal",group:"Actions",displayName:"Focus",valueChangedToTrue(){this.context.setNodeFocused(this,!0)}},blur:{type:"signal",group:"Actions",displayName:"Blur",valueChangedToTrue(){this.context.setNodeFocused(this,!1)}}},inputCss:{fontSize:{index:21,group:"Text",displayName:"Font Size",type:{name:"number",units:["px"],defaultUnit:"px"},onChange(){this.props.textStyle&&this.forceUpdate()}},color:{index:99,type:"color",displayName:"Font Color",group:"Style"},backgroundColor:{index:100,displayName:"Background Color",group:"Style",type:"color",default:"transparent"},borderColor:{index:101,displayName:"Border Color",group:"Style",type:"color",default:"black"},borderWidth:{index:102,displayName:"Border Width",group:"Style",type:{name:"number",units:["px"],defaultUnit:"px"},default:0}},outputs:{controlId:{type:"string",displayName:"Control Id",group:"General",getter:function(){return this._internal.controlId}},enabled:{type:"boolean",displayName:"Enabled",group:"States",getter:function(){return this._internal.enabled}}},outputProps:{onTextChanged:{group:"Value",displayName:"Text",type:"string"},onEnter:{group:"Events",displayName:"On Enter",type:"signal"}},dynamicports:[{condition:"boxShadowEnabled = true",inputs:["boxShadowOffsetX","boxShadowOffsetY","boxShadowInset","boxShadowBlurRadius","boxShadowSpreadRadius","boxShadowColor"]}],methods:{_focus(){this.innerReactComponentRef&&this.innerReactComponentRef.focus()},_blur(){this.innerReactComponentRef&&this.innerReactComponentRef.blur()},setText(e){this.props.startValue=e,this.innerReactComponentRef?this.innerReactComponentRef.setText(e):this.outputPropValues.onTextChanged!==e&&(this.outputPropValues.onTextChanged=e,this.flagOutputDirty("onTextChanged"))}}};NodeSharedPortDefinitions.addDimensions(TextInput,{defaultSizeMode:"contentSize",contentLabel:"Text"}),NodeSharedPortDefinitions.addAlignInputs(TextInput),NodeSharedPortDefinitions.addTransformInputs(TextInput),NodeSharedPortDefinitions.addPaddingInputs(TextInput),NodeSharedPortDefinitions.addMarginInputs(TextInput),NodeSharedPortDefinitions.addSharedVisualInputs(TextInput),Utils.addControlEventsAndStates(TextInput);const definition=createNodeFromReactComponent(TextInput);definition.setup=function(e,t){t.on("nodeAdded.Text Input",function(n){n.parameters.fontFamily&&n.parameters.fontFamily.split(".").length>1&&FontLoader.instance.loadFont(n.parameters.fontFamily),n.on("parameterUpdated",function(o){o.name==="fontFamily"&&o.value&&o.value.split(".").length>1&&FontLoader.instance.loadFont(o.value)})})};const Switch={name:"Switch",docs:"https://docs.noodl.net/nodes/logic/switch",category:"Logic",initialize(){this._internal.state=!1,this._internal.initialized=!1},getInspectInfo(){return this._internal.state},inputs:{on:{displayName:"On",group:"Change State",valueChangedToTrue(){this._internal.state!==!0&&(this._internal.state=!0,this.flagOutputDirty("state"),this.emitSignals())}},off:{displayName:"Off",group:"Change State",valueChangedToTrue(){this._internal.state!==!1&&(this._internal.state=!1,this.flagOutputDirty("state"),this.emitSignals())}},flip:{displayName:"Flip",group:"Change State",valueChangedToTrue(){this._internal.state=!this._internal.state,this.flagOutputDirty("state"),this.emitSignals()}},onFromStart:{type:"boolean",displayName:"State",group:"General",default:!1,set(e){this._internal.state=!!e,this.flagOutputDirty("state"),this.emitSignals()}}},outputs:{state:{type:"boolean",displayName:"Current State",getter(){return this._internal.state}},switched:{displayName:"Switched",type:"signal",group:"Signals"},switchedToOn:{displayName:"Switched To On",type:"signal",group:"Signals"},switchedToOff:{displayName:"Switched To Off",type:"signal",group:"Signals"}},prototypeExtensions:{emitSignals(){this._internal.state===!0?this.sendSignalOnOutput("switchedToOn"):this.sendSignalOnOutput("switchedToOff"),this.sendSignalOnOutput("switched")}}},Switch$1={node:Switch},Timer={name:"Timer",docs:"https://docs.noodl.net/nodes/utilities/delay",displayName:"Delay",category:"Utilities",nodeDoubleClickAction:{focusPort:"duration"},initialize:function(){var e=this;this._internal._animation=this.context.timerScheduler.createTimer({duration:0,onStart:function(){e.sendSignalOnOutput("timerStarted")},onFinish:function(){e.sendSignalOnOutput("timerFinished")}}),this.addDeleteListener(()=>{this._internal._animation.stop()})},getInspectInfo(){return this._internal._animation.isRunning()?Math.floor(this._internal._animation.durationLeft()/10)/100+" seconds":"Not running"},inputs:{start:{displayName:"Start",valueChangedToTrue:function(){this._internal._animation._isRunning===!1&&this._internal._animation.start()}},restart:{displayName:"Restart",valueChangedToTrue:function(){this._internal._animation.start()}},duration:{type:"number",displayName:"Duration",default:0,set:function(e){this._internal._animation.duration=e}},startDelay:{type:"number",displayName:"Start Delay",default:0,set:function(e){this._internal._animation.delay=e}},stop:{displayName:"Stop",valueChangedToTrue:function(){this._internal._animation.stop()}}},outputs:{timerStarted:{type:"signal",displayName:"Started"},timerFinished:{type:"signal",displayName:"Finished"}}},Timer$1={node:Timer},Color={node:createDefinition({name:"Color",docs:"https://docs.noodl.net/nodes/data/color",startValue:"#f1f2f4",nodeDoubleClickAction:{focusPort:"value"},type:{name:"color"},cast:function(e){return e}})},EventSender={name:"Event Sender",docs:"https://docs.noodl.net/nodes/events/send-event",displayNodeName:"Send Event",category:"Events",usePortAsLabel:"channelName",color:"component",exportDynamicPorts:!0,initialize:function(){this._internal.inputValues={},this._internal.channelName="",this._internal.propagation="global"},inputs:{sendEvent:{displayName:"Send",valueChangedToTrue:function(){var e=this;this.scheduleAfterInputsHaveUpdated(function(){e._internal.propagation==="global"?e.context.sendGlobalEventFromEventSender(e._internal.channelName,e._internal.inputValues):e.nodeScope.sendEventFromThisScope(e._internal.channelName,e._internal.inputValues,e._internal.propagation)})}},channelName:{type:{name:"string",allowEditOnly:!0,identifierOf:"EventChannelName",identifierDisplayName:"Event Channels"},default:"",group:"Settings",displayName:"Channel Name",set:function(e){this._internal.channelName=e,this._internal.inputValues._channelName=e}},propagation:{type:{name:"enum",enums:[{value:"global",label:"Global"},{value:"parent",label:"Parent"},{value:"children",label:"Children"},{value:"siblings",label:"Siblings"}]},default:"global",group:"Settings",displayName:"Send to",set:function(e){this._internal.propagation=e}},payload:{type:{name:"stringlist",allowEditOnly:!0},group:"Payload"}},prototypeExtensions:{registerInputIfNeeded:{value:function(e){if(!this.hasInput(e)){var t=this;this.registerInput(e,{set:function(n){t._internal.inputValues[e]=n}})}}}}};function updatePorts$a(e,t,n){var o=[],r=t.payload;if(r){r=r.split(",");for(const s of r)o.push({type:{name:"*",allowConnectionsOnly:!0},plug:"input",group:"Payload",name:s,displayName:s})}n.sendDynamicPorts(e,o,{detectRenamed:{plug:"input"}})}const EventSender$1={node:EventSender,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.Event Sender",function(n){updatePorts$a(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",function(o){updatePorts$a(n.id,n.parameters,e.editorConnection)})})}},EventReceiver={name:"Event Receiver",docs:"https://docs.noodl.net/nodes/events/receive-event",displayNodeName:"Receive Event",category:"Events",usePortAsLabel:"channelName",color:"component",initialize:function(){var e=this._internal;e.outputValues={},e.outputNames=[],e.eventReceived=!1,e._isEnabled=!0,e.channelName=""},inputs:{enabled:{displayName:"Enabled",type:"boolean",default:!0,set:function(e){this._internal._isEnabled=!!e}},consume:{displayName:"Consume",type:{name:"enum",enums:[{label:"Never",value:"never"},{label:"Always",value:"always"}]},default:"never",set:function(e){this._internal.consume=e}},channelName:{type:{name:"string",identifierOf:"EventChannelName"},displayName:"Channel",set:function(e){this._internal.onEventReceivedCallback&&(this.context.eventSenderEmitter.removeListener(this._internal.channelName,this._internal.onEventReceivedCallback),this._internal.onEventReceivedCallback=null),this._internal.channelName=e,this.registerListenersForChannel(e)}}},outputs:{eventReceived:{displayName:"Received",type:"signal"}},prototypeExtensions:{registerOutputIfNeeded:function(e){if(!this.hasOutput(e)){var t=this;this._internal.outputNames.push(e),this.registerOutput(e,{getter:function(){return t._internal.outputValues[e]}})}},handleEvent:function(e){if(this._internal._isEnabled!==!1){this.sendSignalOnOutput("eventReceived");for(var t in e)this.hasOutput(t)&&(this._internal.outputValues[t]=e[t],this.flagOutputDirty(t));return this._internal.consume==="always"}},onEventReceived:function(e){this.handleEvent(e)},_onNodeDeleted:function(){if(Node.prototype._onNodeDeleted.call(this),this._internal.onEventReceivedCallback){var e=this.context.eventSenderEmitter;e.removeListener(this._internal.channelName,this._internal.onEventReceivedCallback)}},registerListenersForChannel:function(e){var t=this.context.eventSenderEmitter;this._internal.onEventReceivedCallback=this.onEventReceived.bind(this),t.on(e,this._internal.onEventReceivedCallback);var n=this;this.context.eventEmitter.once("applicationDataReloaded",function(){n._internal.onEventReceivedCallback&&t.removeListener(e,n._internal.onEventReceivedCallback)})},getChannelName:function(){return this._internal.channelName}}},EventReceiver$1={node:EventReceiver,setup:function(e,t){if(!e.editorConnection||!e.editorConnection.isRunningLocally())return;function n(o){var r=o.parameters.channelName;function s(){var l=t.getNodesWithType("Event Sender"),u=l.filter(g=>g.parameters.channelName===r),d={};u.forEach(g=>{const b=g.parameters.payload?g.parameters.payload.split(","):[];for(let _ of b)d[_]=!0});var h=[];for(var f in d)h.push({name:f,type:"*",plug:"output",displayName:f});e.editorConnection.sendDynamicPorts(o.id,h,{detectRenamed:{plug:"output"}})}s(),o.on("parameterUpdated",function(l){l.name==="channelName"&&(r=l.value,s())});function a(l){l.on("inputPortAdded",function(u){s()}),l.on("inputPortRemoved",function(u){s()}),l.on("parameterUpdated",function(u){u.name==="channelName"&&s()})}t.getNodesWithType("Event Sender").forEach(a),t.on("nodeAdded.Event Sender",a),t.on("nodeRemoved.Event Sender",l=>{s()})}t.on("editorImportComplete",()=>{t.on("nodeAdded.Event Receiver",o=>n(o)),t.getNodesWithType("Event Receiver").forEach(o=>n(o))})}},ScreenResolution={name:"Screen Resolution",docs:"https://docs.noodl.net/nodes/utilities/screen-resolution",category:"Utilities",initialize(){typeof window>"u"||(window.addEventListener("resize",()=>{this._viewportSizeChanged()}),this._viewportSizeChanged())},getInspectInfo(){return this._internal.width+" x "+this._internal.height},outputs:{width:{type:"number",displayName:"Width",get(){return this._internal.width}},height:{type:"number",displayName:"Height",get(){return this._internal.height}},aspectRatio:{type:"number",displayName:"Aspect Ratio",get(){return this._internal.width/this._internal.height}}},methods:{_viewportSizeChanged(){this._internal.width=window.innerWidth,this._internal.height=window.innerHeight,this.flagAllOutputsDirty()}}},ScreenResolution$1={node:ScreenResolution},defaultCode="";var Javascript={name:"Javascript2",docs:"https://docs.noodl.net/nodes/javascript/script",displayNodeName:"Script",category:"CustomCode",color:"javascript",nodeDoubleClickAction:{focusPort:"Code"},searchTags:["javascript"],exportDynamicPorts:!0,initialize:function(){var e=this._internal;e.inputValues={},e.outputValues={},e.outputProperties={},e.runScheduled=!1,e.setupScheduled=!1,e.runNextFrameScheduled=!1,e.isWaitingForExternalFileToLoad=!1,e.useExternalFile=!1,e.runFunction=void 0,e.destroyFunction=void 0,e.setupFunction=void 0,e.hasParsedCode=!1,e.changedInputs={},e.signalScheduled={},e.killed=!1,e.inputQueue=[];var t=this;e.userFunctionScope={createComponent(n){return n&&n.length>0&&n[0]!=="/"&&(n="/"+n),t.nodeScope.createNode(n,guid())},deleteComponent(n){t.nodeScope.deleteNode(n)},flagOutputDirty:function(n){if(!n)throw new Error("Output port name must be specified");t.flagOutputDirty(n)},runNextFrame:function(){e.runNextFrameScheduled||(e.runNextFrameScheduled=!0,t.context.scheduleNextFrame(function(){e.runNextFrameScheduled=!1,e.killed||scheduleRun.call(t)}))},sendSignalOnOutput:function(n){t.sendSignalOnOutput(n)}},e.onFrameStart=onFrameStart.bind(this)},dynamicports:[{condition:"useExternalFile = no OR useExternalFile NOT SET",inputs:["code"]},{condition:"useExternalFile = yes",inputs:["externalFile"]}],inputs:{scriptInputs:{type:{name:"proplist",allowEditOnly:!0},group:"Script Inputs",set:function(e){}},scriptOutputs:{type:{name:"proplist",allowEditOnly:!0},group:"Script Outputs",set:function(e){}},useExternalFile:{type:{name:"enum",enums:[{value:"yes",label:"Yes"},{value:"no",label:"No"}],allowEditOnly:!0},default:"no",displayName:"Use External File",group:"Code",set:function(e){this._internal.isWaitingForExternalFileToLoad=e==="yes",this._internal.useExternalFile=e==="yes"}},code:{displayName:"Code",group:"Code",type:{name:"string",allowEditOnly:!0,codeeditor:"javascript"},default:defaultCode,set:function(e){if(e){var t=this;this.scheduleAfterInputsHaveUpdated(function(){if(this._internal.useExternalFile===!1){this._callDestroyFunction();var n=JavascriptNodeParser.createFromCode(e,{node:this});t._onCodeParsed(n)}})}}},externalFile:{displayName:"File Path",group:"Code",type:{name:"source",allowEditOnly:!0},set:function(e){if(this._internal.useExternalFile!==!1){var t=this;JavascriptNodeParser.createFromURL(e,function(n){t._internal.isWaitingForExternalFileToLoad=!1,t._onCodeParsed(n)},{node:this})}}}},prototypeExtensions:{_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this._internal.killed=!0,this._callDestroyFunction()},update:function(){this._internal.isWaitingForExternalFileToLoad===!0?this._dirty=!1:Node.prototype.update.call(this)},_onCodeParsed:function(e){const t=this.context.editorConnection;if(t)for(const n of["js-destroy-waring","js-run-waring","js-setup-waring"])t.clearWarning(this.nodeScope.componentOwner.name,this.id,n);if(!e.error){if(Object.keys(this.model.inputPorts).forEach(n=>{const o=this.model.inputPorts[n].type;o&&(o==="color"||o.name==="color")&&(this._internal.inputValues[n]=void 0,this.hasInput(n)?this.getInput(n).type="color":this.registerInput(n,{type:"color",set:userInputSetter$4.bind(this,n)}))}),Object.keys(this.model.outputPorts).forEach(n=>{this.registerOutputIfNeeded(n)}),this._internal.setupFunction=e.setup,this._internal.runFunction=e.change,this._internal.destroyFunction=e.destroy,this._internal.definedObject=e.definedObject,this._internal.setupFunction&&scheduleSetup.call(this),this._internal.runFunction&&scheduleRun.call(this),this._internal.hasParsedCode=!0,this._internal.inputQueue){for(const{name:n,value:o}of this._internal.inputQueue)this.setInputValue(n,o);this._internal.inputQueue=void 0}e.apis.Node.Inputs=this._internal.inputValues,e.apis.Node.Outputs=this._internal.outputProperties}},registerInputIfNeeded:function(e){this.hasInput(e)||(this._internal.inputValues[e]=void 0,this.registerInput(e,{set:userInputSetter$4.bind(this,e)}))},registerOutputIfNeeded:function(e){if(this.hasOutput(e))return;var t=this;const n=_typename(this.model.outputPorts[e].type)==="signal";Object.defineProperty(this._internal.outputProperties,e,{set:function(o){n||(t._internal.outputValues[e]=o,t.flagOutputDirty(e))},get:function(){return n?()=>{t.hasOutput(e)&&t.sendSignalOnOutput(e)}:t._internal.outputValues[e]}}),this.registerOutput(e,{getter:userOutputGetter$3.bind(this,e)})},_callRunFunction:function(){var e=this._internal;if(!(!e.runFunction||e.killed))try{e.runFunction.call(e.userFunctionScope,e.inputValues,e.outputProperties,e.changedInputs)}catch(t){logJavaScriptNodeError(t),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-run-waring",{showGlobally:!0,message:"<strong>run</strong>: "+t.message})}},_callSignalFunction:function(e){var t=this._internal;if(!(!t.definedObject||t.killed)&&!(!t.definedObject[e]||typeof t.definedObject[e]!="function"))try{t.definedObject[e].call(t.userFunctionScope,t.inputValues,t.outputProperties)}catch(n){console.log("Error in JS node signal function code.",Object.getPrototypeOf(n).constructor.name+": "+n.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-run-waring",{showGlobally:!0,message:"<strong>run</strong>: "+n.message})}},_callDestroyFunction:function(){var e=this._internal;if(e.destroyFunction)try{e.destroyFunction.call(e.userFunctionScope,e.inputValues,e.outputProperties)}catch(t){console.log("Error in JS node destroy code.",Object.getPrototypeOf(t).constructor.name+": "+t.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-destroy-waring",{showGlobally:!0,message:"<strong>setup</strong>: "+t.message})}},_callSetupFunction:function(){var e=this._internal;if(!(!e.setupFunction||e.killed))try{e.setupFunction.call(e.userFunctionScope,e.inputValues,e.outputProperties)}catch(t){console.log("Error in JS node setup code.",Object.getPrototypeOf(t).constructor.name+": "+t.message),this.context.editorConnection&&this.context.isWarningTypeEnabled("javascriptExecution")&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"js-setup-waring",{showGlobally:!0,message:"<strong>setup</strong>: "+t.message})}}}};function scheduleSetup(){this._internal.setupScheduled||(this._internal.setupScheduled=!0,this.scheduleAfterInputsHaveUpdated(function(){this._internal.killed||(this._callSetupFunction(),this._internal.setupScheduled=!1)}))}function scheduleRun(){this._internal.runScheduled||this._internal.killed||(this._internal.runScheduled=!0,this.scheduleAfterInputsHaveUpdated(function(){this._internal.killed||(this._callRunFunction(),this._internal.changedInputs={},this._internal.runScheduled=!1)}))}function scheduleSignal(e){this._internal.signalScheduled[e]||this._internal.killed||(this._internal.signalScheduled[e]=!0,this.scheduleAfterInputsHaveUpdated(function(){this._internal.killed||(this._callSignalFunction(e),this._internal.signalScheduled[e]=!1)}))}function onFrameStart(){this._internal.runNextFrame=!1,scheduleRun.call(this)}function _typename(e){return typeof e=="object"?e.name:e}function userInputSetter$4(e,t){this._internal.hasParsedCode===!0?this.model.inputPorts[e]!==void 0&&_typename(this.model.inputPorts[e].type)==="signal"?this._internal.definedObject&&typeof this._internal.definedObject[e]=="function"&&t&&scheduleSignal.call(this,e):(this._internal.inputValues[e]=t,this._internal.changedInputs[e]=!0,scheduleRun.call(this)):this._internal.inputQueue.push({name:e,value:t})}function userOutputGetter$3(e){return this._internal.outputValues[e]}function _parseAndSourceJavascript(e,t,n){var o=t.editorConnection;if(!e.parameters)return;function r(){for(const u of["js-parse-waring","js-destroy-waring","js-run-waring","js-setup-waring"])o.clearWarning(e.component.name,e.id,u)}function s(u){u.error?o.sendWarning(e.component.name,e.id,"js-parse-waring",{showGlobally:!0,message:u.error}):r(),n(u.getPorts())}if(e.parameters.externalFile&&e.parameters.useExternalFile==="yes"){var a=e.parameters.externalFile;JavascriptNodeParser.createFromURL(a,s)}else if(e.parameters.code){var l=JavascriptNodeParser.createFromCode(e.parameters.code);s(l)}else r(),n([])}const JavaScript={node:Javascript,setup:function(e,t){if(!e.editorConnection||!e.editorConnection.isRunningLocally())return;function n(o){function r(){var s=[];const a=[{value:"string",label:"String"},{value:"boolean",label:"Boolean"},{value:"number",label:"Number"},{value:"object",label:"Object"},{value:"array",label:"Array"}],l=[{value:"string",label:"String"},{value:"boolean",label:"Boolean"},{value:"number",label:"Number"},{value:"object",label:"Object"},{value:"array",label:"Array"},{value:"signal",label:"Signal"}];o.parameters.scriptOutputs!==void 0&&o.parameters.scriptOutputs.length>0&&o.parameters.scriptOutputs.forEach(u=>{s.push({name:"outtype-"+u.label,displayName:"Type",plug:"input",type:{name:"enum",enums:l,allowEditOnly:!0},default:"string",parent:"scriptOutputs",parentItemId:u.id}),s.push({name:u.label,plug:"output",type:o.parameters["outtype-"+u.label]||"*",group:"Outputs"})}),o.parameters.scriptInputs!==void 0&&o.parameters.scriptInputs.length>0&&o.parameters.scriptInputs.forEach(u=>{s.push({name:"intype-"+u.label,displayName:"Type",plug:"input",type:{name:"enum",enums:a,allowEditOnly:!0},default:"string",parent:"scriptInputs",parentItemId:u.id}),s.push({name:u.label,plug:"input",type:o.parameters["intype-"+u.label]||"string",group:"Inputs"})}),_parseAndSourceJavascript(o,e,function(u){u.forEach(d=>{s.find(h=>h.name===d.name&&h.plug===d.plug)||s.push(d)}),e.editorConnection.sendDynamicPorts(o.id,s)})}r(),o.on("parameterUpdated",function(s){r()})}t.on("editorImportComplete",()=>{t.on("nodeAdded.Javascript2",function(o){n(o)});for(const o of t.getNodesWithType("Javascript2"))n(o)})}},NumberRemapperNode={name:"Number Remapper",docs:"https://docs.noodl.net/nodes/math/number-remapper",category:"Math",initialize:function(){var e=this._internal;e._currentInputValue=0,e._remappedValue=0,e._minInputValue=0,e._maxInputValue=0,e._minOutputValue=0,e._maxOutputValue=1,e._clampOutput=!0},getInspectInfo(){return this._internal._remappedValue},inputs:{inputValue:{group:"Value to Remap",type:{name:"number",allowConnectionOnly:!0},default:0,displayName:"Input Value",set:function(e){this._internal._currentInputValue=e,this._calculateNewOutputValue()}},minInputValue:{group:"Input Parameters",type:{name:"number"},default:0,displayName:"Input Minimum",set:function(e){this._internal._minInputValue=e,this._calculateNewOutputValue()}},maxInputValue:{group:"Input Parameters",type:{name:"number"},default:0,displayName:"Input Maximum",set:function(e){this._internal._maxInputValue=e,this._calculateNewOutputValue()}},minOutputValue:{group:"Output Parameters",type:{name:"number"},default:0,displayName:"Output Minimum",set:function(e){this._internal._minOutputValue=e,this._calculateNewOutputValue()}},maxOutputValue:{group:"Output Parameters",type:{name:"number"},default:1,displayName:"Output Maximum",set:function(e){this._internal._maxOutputValue=e,this._calculateNewOutputValue()}},clamp:{group:"Output Parameters",type:{name:"boolean",allowEditOnly:!0},default:!0,displayName:"Clamp Output",set:function(e){this._internal._clampOutput=!!e,this._calculateNewOutputValue()}}},outputs:{remappedValue:{type:"number",displayName:"Remapped Value",group:"Outputs",getter:function(){return this._internal._remappedValue}}},prototypeExtensions:{_calculateNewOutputValue:{value:function(){var e,t=this._internal;t._maxInputValue===t._minInputValue?e=0:e=(t._currentInputValue-t._minInputValue)/(t._maxInputValue-t._minInputValue),t._clampOutput&&(e=Math.max(0,Math.min(1,e))),t._remappedValue=t._minOutputValue+e*(t._maxOutputValue-t._minOutputValue),this.flagOutputDirty("remappedValue")}}}},NumberRemapper={node:NumberRemapperNode},ValueChangedNode={name:"Value Changed",docs:"https://docs.noodl.net/nodes/logic/value-changed",category:"Logic",initialize:function(){this._internal.lastValue=void 0,this._internal.changeCount=0},getInspectInfo(){return this._internal.changeCount?"Triggered "+this._internal.changeCount+(this._internal.changeCount===1?" time":" times"):"Not triggered"},inputs:{value:{type:"*",displayName:"Input",set:function(e){this._internal.lastValue!==e&&(this._internal.changeCount++,this.sendSignalOnOutput("valueChanged"),this._internal.lastValue=e)}}},outputs:{valueChanged:{type:"signal",displayName:"Value Changed"}}},ValueChanged={node:ValueChangedNode},defaultDuration$3=300,previousStates={},previousValues={};function setRGBA(e,t){if(t==="transparent"||!t){e[3]=0;return}const n=(t.length-1)/2;for(let o=0;o<n;++o){const r=1+o*2;e[o]=parseInt(t.substring(r,r+2),16)}}function componentToHex$1(e){var t=e.toString(16);return t.length==1?"0"+t:t}function rgbaToHex(e){return"#"+componentToHex$1(e[0])+componentToHex$1(e[1])+componentToHex$1(e[2])+componentToHex$1(e[3])}const StatesNode={name:"States",docs:"https://docs.noodl.net/nodes/utilities/logic/states",shortDesc:"Define states with values and this node can interpolate between these values when the state is changed.",category:"Animation",initialize:function(){var e=this,t=this._internal;t.useTransitions=!0,t.currentValues={},t.stateParameters={},t.stateParameterTypes={},t.startValues={},t.bezierEaseCurves={},t.transitionFuncs={},t.valuesAreInitialised=!1,t.animation=this.context.timerScheduler.createTimer({duration:defaultDuration$3,ease:EaseCurves.easeOut,onStart:function(){t.values;var n=t.startValues,o=t.stateParameters,r=t.stateParameterTypes,s="value-"+t.state+"-";this.targetValues={},this.startValues={},this.valueTypes={};for(var a in this.transitionCurves)r["type-"+a]==="number"||r["type-"+a]===void 0?(this.valueTypes[a]="number",this.startValues[a]=n[a],this.targetValues[a]=o[s+a]||0):r["type-"+a]==="color"&&(this.valueTypes[a]="color",this.startValues[a]=[0,0,0,255],setRGBA(this.startValues[a],e.context.styles.resolveColor(n[a]||"#000000")),this.targetValues[a]=[0,0,0,255],setRGBA(this.targetValues[a],e.context.styles.resolveColor(o[s+a]||"#000000")))},onRunning:function(n){var o=n*this.duration,r=t.currentValues,s=[0,0,0,255];for(var a in this.transitionCurves){var l=this.transitionCurves[a];if(o<l.delay)r[a]=this.startValues[a];else if(o>=l.delay+l.dur)r[a]=this.valueTypes[a]==="color"?rgbaToHex(this.targetValues[a]):this.targetValues[a];else{var u=t.transitionFuncs[a].get((o-l.delay)/l.dur);if(this.valueTypes[a]==="number")r[a]=EaseCurves.linear(Number(this.startValues[a]),Number(this.targetValues[a]),u);else if(this.valueTypes[a]==="color"){let d=this.startValues[a],h=this.targetValues[a];s[0]=Math.floor(EaseCurves.linear(d[0],h[0],u)),s[1]=Math.floor(EaseCurves.linear(d[1],h[1],u)),s[2]=Math.floor(EaseCurves.linear(d[2],h[2],u)),s[3]=Math.floor(EaseCurves.linear(d[3],h[3],u)),r[a]=rgbaToHex(s)}}e.flagOutputDirty(a)}},onFinish:function(){var n="reached-"+t.state;e.hasOutput(n)&&e.sendSignalOnOutput(n)}})},getInspectInfo(){return`Current state: ${this._internal.state}`},inputs:{states:{type:{name:"stringlist",allowEditOnly:!0},displayName:"States",group:"States",set:function(e){if(this._internal.states=e?e.split(","):[],this._internal.states.length>0){var t=this;t._internal.state||this.scheduleGoToState(t._internal.startState||t._internal.states[0])}}},values:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Values",group:"Values",set:function(e){var t=this._internal;t.values=e.split(",");for(var n in t.values)this.registerOutputIfNeeded(t.values[n])}},toggle:{group:"Go to state",displayName:"Toggle",valueChangedToTrue:function(){var e=this._internal;if(e.states){var t=e.states.indexOf(e.state),n=(t+1)%e.states.length;this.scheduleGoToState(e.states[n])}}},useTransitions:{type:"boolean",displayName:"Use Transitions",group:"General",default:!0,set:function(e){var t=this._internal;t.useTransitions=e}}},outputs:{currentState:{type:"string",displayName:"State",group:"Current State",getter:function(){return this._internal.state}},stateChanged:{type:"signal",displayName:"State Changed",group:"Current State"}},prototypeExtensions:{registerOutputIfNeeded:function(e){var t=this._internal;this.hasOutput(e)||this.registerOutput(e,{getter:function(){return t.currentValues[e]}})},registerInputIfNeeded:function(e){var t=this,n=this._internal;if(!this.hasInput(e)){if(e.indexOf("to-")===0){var o=e.substring(3);this.registerInput(e,{set:createSetter({valueChangedToTrue:function(){this.scheduleGoToState(o)}})})}else if(e==="startState")this.registerInput(e,{set:function(a){this._internal.startState=a,this.scheduleGoToState(a)}});else if(e==="currentState")this.registerInput(e,{set:this.scheduleGoToState.bind(this)});else if(e.indexOf("type-")===0)this.registerInput(e,{set:function(a){n.stateParameterTypes[e]=a}});else if(e.indexOf("value-")===0){var r=e.split("-"),o=r[1],s=r[2];this.registerInput(e,{set:function(l){n.stateParameters[e]=l,n.state===o&&(n.currentValues[s]=l,t.flagOutputDirty(s))}})}else if(e.search(/duration-/g)===0)this.registerInput(e,{set:function(a){n.stateParameters[e]=a}});else if(e.search(/transition/g)===0){var o=e.substring(11);this.registerInput(e,{set:function(l){n.stateParameters[e]=l}})}}},setCurrentState:function(e){this.scheduleGoToState(e)},jumpToState:function(e){var t=this._internal;if(t.states&&(e||(e=t.states[0]),t.state!==e)){t.animation.stop();var n="value-"+e+"-";for(var o in t.values){var r=t.values[o];t.currentValues[r]=t.stateParameters[n+r]||0,this.flagOutputDirty(r)}t.state=e,this.flagOutputDirty("currentState"),t.valuesAreInitialised&&this.sendSignalOnOutput("stateChanged"),t.valuesAreInitialised=!0,this.updateAtStatePorts()}},scheduleGoToState:function(e){var t=this;this._internal.goToState=e,!this.hasScheduledGoToState&&(this.hasScheduledGoToState=!0,this.scheduleAfterInputsHaveUpdated(function(){t.hasScheduledGoToState=!1,t.goToState(t._internal.goToState)}))},goToState:function(e){var t=this._internal;if(t.states&&(e||(e=t.states[0]),t.state!==e))if(!t.valuesAreInitialised)this.jumpToState(e);else{var n=0,o=0,r={};for(var s in t.values){var a=t.values[s];t.startValues[a]=t.currentValues[a];const h=t.stateParameterTypes["type-"+a];if(h==="boolean"){var l=t.stateParameters["value-"+e+"-"+a];t.currentValues[a]=l===void 0?!1:!!l,this.flagOutputDirty(a)}else if(h==="string"||h==="textStyle")t.currentValues[a]=t.stateParameters["value-"+e+"-"+a],this.flagOutputDirty(a);else{var u=t.stateParameters["transition-"+e+"-"+a];u||(u=t.stateParameters["transitiondef-"+e]||{curve:[0,0,.58,1],dur:300,delay:0}),u.dur===0&&u.delay===0||!t.useTransitions?(t.currentValues[a]=t.stateParameters["value-"+e+"-"+a],this.flagOutputDirty(a)):(t.transitionFuncs[a]=BezierEasing(u.curve),r[a]=u,n=Math.min(n,u.delay),o=Math.max(o,u.dur+u.delay))}}if((o>0||n>0)&&(t.animation.transitionCurves=r,t.animation.duration=o,t.animation.delay=n,t.animation.start()),t.state=e,this.flagOutputDirty("currentState"),this.sendSignalOnOutput("stateChanged"),this.updateAtStatePorts(),o==0&&n==0){var d="reached-"+t.state;this.hasOutput(d)&&this.sendSignalOnOutput(d)}}},updateAtStatePorts:function(){var e=this._internal,t=e.states;for(var n in t){var o=t[n],r="at-"+o;e.currentValues[r]=e.state===o,this.hasOutput(r)&&this.flagOutputDirty(r)}}}};function detectRename$1(e,t){if(!(!e||!t)&&e.length===t.length){for(var n={},o=0;o<e.length;o++){if(t.indexOf(e[o])===-1){if(n.before)return;n.before=e[o]}if(e.indexOf(t[o])===-1){if(n.after)return;n.after=t[o]}}return n.before&&n.after?n:void 0}}function updatePorts$9(e,t,n){var o=t.states,r=t.values,s=[];r=r?r.split(","):void 0;for(var a in r){var l=r[a];s.push({type:{name:t["type-"+l]||"number",allowConnectionsOnly:!0},plug:"output",group:"Values",name:l}),s.push({type:{name:"enum",enums:[{label:"Number",value:"number"},{label:"String",value:"string"},{label:"Boolean",value:"boolean"},{label:"Color",value:"color"},{label:"Text Style",value:"textStyle"}],allowEditOnly:!0},default:"number",plug:"input",group:"Types",displayName:l,name:"type-"+l})}o=o?o.split(","):void 0,o&&o.forEach(function(f){r&&r.forEach(function(g){s.push({plug:"input",type:t["type-"+g]||"number",group:f+" Values",name:"value-"+f+"-"+g,displayName:g,editorName:f+"|"+g})}),r&&t.useTransitions!==!1&&(s.push({plug:"input",type:"curve",displayName:"Default",default:{curve:[0,0,.58,1],dur:300,delay:0},group:f+" Transitions",name:"transitiondef-"+f}),r.forEach(function(g){(t["type-"+g]===void 0||t["type-"+g]==="number"||t["type-"+g]==="color")&&s.push({plug:"input",type:{name:"curve"},default:t["transitiondef-"+f]||{curve:[0,0,.58,1],dur:300,delay:0},group:f+" Transitions",name:"transition-"+f+"-"+g,displayName:g,editorName:"Transition "+f+"|"+g})})),s.push({plug:"input",type:{name:"signal",allowConnectionsOnly:!0},displayName:"To "+f,name:"to-"+f,group:"Go to state"}),s.push({plug:"output",type:"boolean",displayName:"At "+f,name:"at-"+f,group:"Current state"}),s.push({plug:"output",type:"signal",displayName:"Has Reached "+f,name:"reached-"+f,group:"Current state"})}),o&&s.push({plug:"input",type:{name:"enum",enums:o},group:"States",displayName:"State",name:"currentState",default:t.startState||o[0]});var u=detectRename$1(previousStates[e],o);previousStates[e]=o;var d=detectRename$1(previousValues[e],r);previousValues[e]=r;let h;u?(h={plug:"input",before:u.before,after:u.after,patterns:["transition-{{*}}","to-{{*}}","at-{{*}}","reached-{{*}}"]},r&&r.forEach(function(f){h.patterns.push("value-{{*}}-"+f)})):d&&(h=[{plug:"output",before:d.before,after:d.after,patterns:["{{*}}"]},{plug:"input",before:d.before,after:d.after,patterns:["type-{{*}}"]},{plug:"input",before:d.before,after:d.after,patterns:o?o.map(function(f){return"value-"+f+"-{{*}}"}):void 0}]),n.sendDynamicPorts(e,s,{renamed:h})}const States={node:StatesNode,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.States",function(n){n.parameters.states&&updatePorts$9(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",function(o){(o.name==="useTransitions"||o.name==="states"||o.name==="values"||o.name.startsWith("transition")||o.name.startsWith("type-"))&&updatePorts$9(n.id,n.parameters,e.editorConnection)})})}},ForEachActionsDefinition={name:"For Each Actions",docs:"https://docs.noodl.net/nodes/ui-controls/repeater-item",displayNodeName:"Repeater Item",category:"Data",color:"data",inputs:{removeCompleted:{type:{name:"boolean",allowConnectionsOnly:!0},displayName:"Remove Completed",group:"Events",valueChangedToTrue:function(){this._internal.removeCompletedCallback&&this._internal.removeCompletedCallback()}}},outputs:{added:{type:"signal",displayName:"Added",group:"Events"},tryRemove:{type:"signal",displayName:"Try Remove",group:"Events"},itemId:{type:"string",displayName:"Item Id",group:"General",get(){return this.getItemId()}}},prototypeExtensions:{getItemId(){const e=this.nodeScope.componentOwner._forEachModel;return e&&e.getId()},signalAdded:function(){this.sendSignalOnOutput("added")},tryRemove:function(e){this.getOutput("tryRemove").hasConnections()?(this._internal.removeCompletedCallback=e,this.sendSignalOnOutput("tryRemove")):this.scheduleAfterInputsHaveUpdated(function(){e()})},itemActionTriggered(e){this.scheduleAfterInputsHaveUpdated(()=>{const t=this.getItemId();this.nodeScope.componentOwner._forEachNode.signalItemAction(e,t,this._internal.actionParameters||{})})},setItemActionParameter(e){this._internal.actionParameters||(this._internal.actionParameters={}),this._internal.actionParameters[e]=e},registerInputIfNeeded:function(e){if(!this.hasInput(e)){if(e.startsWith("itemAction-"))return this.registerInput(e,{set:createSetter({valueChangedToTrue:this.itemActionTriggered.bind(this,e)})});if(e.startsWith("itemActionParameter-"))return this.registerInput(e,{set:this.setItemActionParameter.bind(this,e)})}}}},ForEachActions={node:ForEachActionsDefinition,setup:function(e,t){!e.editorConnection||e.editorConnection.isRunningLocally()}};function clamp(e,t,n){return Math.max(e,Math.min(t,n))}function setRGB(e,t){for(var n=0;n<3;++n){var o=1+n*2;e[n]=parseInt(t.substring(o,o+2),16)}}function componentToHex(e){var t=e.toString(16);return t.length==1?"0"+t:t}function rgbToHex(e){return"#"+componentToHex(e[0])+componentToHex(e[1])+componentToHex(e[2])}let rgb0=[0,0,0],rgb1=[0,0,0],rgb2=[0,0,0];const ColorBlendNode={name:"Color Blend",docs:"https://docs.noodl.net/nodes/utilities/color-blend",shortDesc:"Given any number of input colors this node can interpolate between these and give the result color as output.",category:"Interpolation",getInspectInfo(){return[{type:"color",value:this._internal.resultColor}]},initialize(){const e=this._internal;e.resultColor="#000000",e.blendValue=0,e.colors=[]},numberedInputs:{color:{type:"color",displayPrefix:"Color",createSetter(e){return function(t){this._internal.colors[e]=t,this.updateColor()}}}},inputs:{blendValue:{type:"number",displayName:"Blend Value",default:0,set:function(e){this._internal.blendValue=e,this.updateColor()}}},outputs:{result:{type:"color",displayName:"Result",getter:function(){return this._internal.resultColor}}},methods:{updateColor(){var e=this._internal.colors;if(e.length===0)return;function t(s){return e[s]?e[s]:"#000000"}var n=clamp(0,e.length-1,this._internal.blendValue),o=Math.floor(n),r=n-o;r===0?this._internal.resultColor=t(o):(setRGB(rgb0,t(o)),setRGB(rgb1,t(o+1)),rgb2[0]=Math.floor(EaseCurves.linear(rgb0[0],rgb1[0],r)),rgb2[1]=Math.floor(EaseCurves.linear(rgb0[1],rgb1[1],r)),rgb2[2]=Math.floor(EaseCurves.linear(rgb0[2],rgb1[2],r)),this._internal.resultColor=rgbToHex(rgb2)),this.flagOutputDirty("result")}}},ColorBlend={node:ColorBlendNode},defaultDuration$2=300,AnimateToValue={name:"net.noodl.animatetovalue",docs:"https://docs.noodl.net/nodes/logic/animate-to-value",displayName:"Animate To Value",shortDesc:"This node can interpolate smooothely from the current value to a target value.",category:"Animation",initialize:function(){var e=this,t=this._internal;t.currentNumber=0,t.numberInitialized=!1,t.animationStarted=!1,t.setCurrentNumberEnabled=!1,t.overrideValue=0,t._animation=this.context.timerScheduler.createTimer({duration:defaultDuration$2,startValue:0,endValue:0,ease:EaseCurves.easeOut,onStart:function(){t.animationStarted=!0},onRunning:function(n){t.currentNumber=this.ease(this.startValue,this.endValue,n),e.flagOutputDirty("currentValue")},onFinish:function(){e.sendSignalOnOutput("atTargetValue")}})},getInspectInfo(){return this._internal.currentNumber},inputs:{targetValue:{type:{name:"number"},displayName:"Target Value",group:"Target Value",default:void 0,set:function(e){if(e===!0?e=1:e===!1&&(e=0),e=Number(e),!isNaN(e)){var t=this._internal;if(t.numberInitialized===!1){t.currentNumber=e,t.numberInitialized=!0,t._animation.endValue=e,this.flagOutputDirty("currentValue");return}else if(e===t._animation.endValue)return;t._animation.startValue=t.currentNumber,t._animation.endValue=e,t._animation.start()}}},duration:{type:"number",group:"Parameters",displayName:"Duration",default:defaultDuration$2,set:function(e){this._internal._animation.duration=e}},delay:{type:"number",group:"Parameters",displayName:"Delay",default:0,set:function(e){this._internal._animation.delay=e}},easingCurve:{type:{name:"enum",enums:[{value:"easeOut",label:"Ease Out"},{value:"easeIn",label:"Ease In"},{value:"linear",label:"Linear"},{value:"easeInOut",label:"Ease In Out"}]},default:"easeOut",displayName:"Easing Curve",group:"Parameters",set:function(e){this._internal._animation.ease=EaseCurves[e]}}},outputs:{currentValue:{type:"number",displayName:"Current Value",group:"Current State",getter:function(){return this._internal.currentNumber}},atTargetValue:{type:"signal",displayName:"At Target Value",group:"Signals"}}},AnimateToValue$1={node:AnimateToValue},ComponentObject={name:"net.noodl.ComponentObject",displayNodeName:"Component Object",category:"Component Utilities",color:"component",docs:"https://docs.noodl.net/nodes/component-utilities/component-object",initialize:function(){this._internal.inputValues={},this._internal.dirtyValues={},this._internal.onModelChangedCallback=t=>{this.isInputConnected("fetch")===!1&&(this.hasOutput("value-"+t.name)&&this.flagOutputDirty("value-"+t.name),this.hasOutput("changed-"+t.name)&&this.sendSignalOnOutput("changed-"+t.name),this.sendSignalOnOutput("changed"))};const e=Model.get("componentState"+this.nodeScope.componentOwner.getInstanceId());this._internal.model=e,e.on("change",this._internal.onModelChangedCallback)},getInspectInfo(){return{type:"value",value:this._internal.model.data}},inputs:{properties:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Properties",group:"Properties",set(e){}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue(){this.scheduleFetch()}}},outputs:{changed:{type:"signal",displayName:"Changed",group:"Events"},fetched:{type:"signal",displayName:"Fetched",group:"Events"}},methods:{scheduleStore(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var e=this._internal;this.scheduleAfterInputsHaveUpdated(()=>{this.hasScheduledStore=!1;for(var t in e.dirtyValues)e.model.set(t,e.inputValues[t],{resolve:!0});e.dirtyValues={}})}},scheduleFetch(){this.hasScheduledFetch||(this.hasScheduledFetch=!0,this.scheduleAfterInputsHaveUpdated(()=>{this.hasScheduledFetch=!1,this.fetch()}))},fetch(){for(var e in this._internal.model.data)this.hasOutput("value-"+e)&&(this.flagOutputDirty("value-"+e),this.hasOutput("changed-"+e)&&this.sendSignalOnOutput("changed-"+e));this.sendSignalOnOutput("fetched")},_onNodeDeleted(){Node.prototype._onNodeDeleted.call(this),this._internal.model.off("change",this._internal.onModelChangedCallback)},registerOutputIfNeeded(e){if(this.hasOutput(e))return;const t=e.split("-"),n=t[t.length-1];this.registerOutput(e,{get(){return this._internal.model.get(n,{resolve:!0})}})},registerInputIfNeeded:function(e){if(!this.hasInput(e)&&e.startsWith("value-")){const t=e.substring(6);this.registerInput(e,{set(n){this._internal.inputValues[t]=n,this._internal.dirtyValues[t]=!0,this.scheduleStore()}})}}}};function updatePorts$8(e,t,n){const o=[];if(t.properties){var r=t.properties.split(",");for(var s in r){var a=r[s];o.push({type:{name:"*",allowConnectionsOnly:!0},plug:"input/output",group:"Properties",name:"value-"+a,displayName:a}),o.push({type:"signal",plug:"output",group:"Changed Events",displayName:a+" Changed",name:"changed-"+a})}}n.sendDynamicPorts(e,o,{detectRenamed:{plug:"input/output"}})}const ComponentObject$1={node:ComponentObject,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.net.noodl.ComponentObject",n=>{updatePorts$8(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",o=>{o.name==="properties"&&updatePorts$8(n.id,n.parameters,e.editorConnection)})})}},graphEventEmitter$1=new eventsExports.EventEmitter;graphEventEmitter$1.setMaxListeners(1e6);const ParentComponentObject={name:"net.noodl.ParentComponentObject",displayNodeName:"Parent Component Object",category:"Component Utilities",color:"component",docs:"https://docs.noodl.net/nodes/component-utilities/parent-component-object",initialize(){this._internal.inputValues={},this._internal.onModelChangedCallback=e=>{this.isInputConnected("fetch")===!1&&(this.hasOutput("value-"+e.name)&&this.flagOutputDirty("value-"+e.name),this.hasOutput("changed-"+e.name)&&this.sendSignalOnOutput("changed-"+e.name),this.sendSignalOnOutput("changed"))},this.onComponentStateNodesChanged=()=>{const e=this.findParentComponentStateModelId();this._internal.modelId!==e&&(this._internal.modelId=e,this.isInputConnected("fetch")===!1&&this.setModelId(this._internal.modelId))},graphEventEmitter$1.on("componentStateNodesChanged",this.onComponentStateNodesChanged),this.updateComponentState()},nodeScopeDidInitialize(){this._internal&&!this._internal.modelId&&this.context.scheduleAfterUpdate(()=>{this.updateComponentState()})},getInspectInfo(){if(!this._internal.model)return"No parent component state found";const t=[{type:"text",value:this._internal.parentComponentName}],n=this._internal.model.data;return t.concat(Object.keys(n).map(o=>({type:"text",value:o+": "+n[o]})))},inputs:{properties:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Properties",group:"Properties",set(e){}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue:function(){this.setModelId(this._internal.modelId)}}},outputs:{changed:{type:"signal",displayName:"Changed",group:"Events"},fetched:{type:"signal",displayName:"Fetched",group:"Events"}},methods:{updateComponentState(){this._internal.modelId=this.findParentComponentStateModelId(),this.isInputConnected("fetch")===!1&&this.setModelId(this._internal.modelId)},findParentComponentStateModelId(){function e(n){let o;if(n.getRoots().length>0){const r=n.getRoots()[0];r.getVisualParentNode?r.getVisualParentNode()&&(o=r.getVisualParentNode().nodeScope.componentOwner):r.parentNodeScope&&(o=n.parentNodeScope.componentOwner)}else n.parentNodeScope&&(o=n.parentNodeScope.componentOwner);if(o&&o.nodeScope&&o.nodeScope.componentOwner!==n)return o.nodeScope.getNodesWithType("net.noodl.ComponentObject").length>0?o:e(o)}const t=e(this.nodeScope.componentOwner);if(t)return this._internal.parentComponentName=t.name,"componentState"+t.getInstanceId()},setModelId(e){if(this._internal.model&&this._internal.model.off("change",this._internal.onModelChangedCallback),this._internal.model=void 0,!e)return;const t=Model.get(e);this._internal.model=t,t.on("change",this._internal.onModelChangedCallback);for(var n in t.data)this.hasOutput("value-"+n)&&this.flagOutputDirty("value-"+n),this.hasOutput("changed-"+n)&&this.sendSignalOnOutput("changed-"+n);this.sendSignalOnOutput("changed"),this.sendSignalOnOutput("fetched")},scheduleStore(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var e=this._internal;this.scheduleAfterInputsHaveUpdated(()=>{if(this.hasScheduledStore=!1,!!e.model)for(var t in e.inputValues)e.model.set(t,e.inputValues[t],{resolve:!0})})}},_onNodeDeleted(){Node.prototype._onNodeDeleted.call(this),graphEventEmitter$1.off("componentStateNodesChanged",this.onComponentStateNodesChanged),this._internal.model&&this._internal.model.off("change",this._internal.onModelChangedCallback)},registerOutputIfNeeded(e){if(this.hasOutput(e))return;const t=e.substring(6);this.registerOutput(e,{get(){if(this._internal.model)return this._internal.model.get(t,{resolve:!0})}})},registerInputIfNeeded:function(e){if(!this.hasInput(e)&&e.startsWith("value-")){const t=e.substring(6);this.registerInput(e,{set(n){this._internal.inputValues[t]=n,this.scheduleStore()}})}}}};function updatePorts$7(e,t,n){const o=[];var r=t.properties&&t.properties.split(",");for(var s in r){var a=r[s];o.push({type:{name:"*",allowConnectionsOnly:!0},plug:"input/output",group:"Properties",name:"value-"+a,displayName:a}),o.push({type:"signal",plug:"output",group:"Changed Events",displayName:a+" Changed",name:"changed-"+a})}n.sendDynamicPorts(e,o,{detectRenamed:{plug:"input/output"}})}const ParentComponentObject$1={node:ParentComponentObject,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||(t.on("nodeAdded.net.noodl.ParentComponentObject",n=>{updatePorts$7(n.id,n.parameters,e.editorConnection),n.on("parameterUpdated",o=>{updatePorts$7(n.id,n.parameters,e.editorConnection)})}),t.on("nodeAdded.net.noodl.ComponentObject",n=>{setTimeout(()=>{graphEventEmitter$1.emit("componentStateNodesChanged")},0)}),t.on("nodeRemoved.net.noodl.ComponentObject",n=>{setTimeout(()=>{graphEventEmitter$1.emit("componentStateNodesChanged")})}))}};function extendSetComponentObjectProperties(e){const t={name:e.name,displayNodeName:e.displayName,category:"Component Utilities",color:"component",docs:e.docs,initialize:function(){this._internal.inputValues={}},inputs:{properties:{type:{name:"stringlist",allowEditOnly:!0},displayName:"Properties",group:"Properties",set(o){}},store:{type:"signal",group:"Actions",displayName:"Do",valueChangedToTrue(){this.scheduleStore()}}},outputs:{stored:{type:"signal",group:"Events",displayName:"Done"}},methods:{getComponentObjectId:e.getComponentObjectId,scheduleStore(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var o=this._internal;this.scheduleAfterInputsHaveUpdated(()=>{const r=Model.get(this.getComponentObjectId());this.hasScheduledStore=!1;const a=(this.model.parameters.properties||"").split(","),l=Object.keys(o.inputValues).filter(u=>a.indexOf(u)!==-1);for(const u of l)r.set(u,o.inputValues[u],{resolve:!0});this.sendSignalOnOutput("stored")})}},registerInputIfNeeded:function(o){if(!this.hasInput(o))if(o.startsWith("prop-")){const r=o.substring(5);this.registerInput(o,{set(s){this._internal.inputValues[r]=s}})}else o.startsWith("type-")&&this.registerInput(o,{set(r){}})}}};function n(o,r,s){var a=[];const l=[{label:"String",value:"string"},{label:"Boolean",value:"boolean"},{label:"Number",value:"number"},{label:"Date",value:"date"},{label:"Array",value:"array"},{label:"Object",value:"object"},{label:"Any",value:"*"}];var u=r.properties;if(u){u=u?u.split(","):void 0;for(var d in u){var h=u[d];a.push({type:{name:r["type-"+h]===void 0?"*":r["type-"+h]},plug:"input",group:"Property Values",displayName:h,name:"prop-"+h}),a.push({type:{name:"enum",enums:l,allowEditOnly:!0},plug:"input",group:"Property Types",displayName:h,default:"*",name:"type-"+h})}}s.sendDynamicPorts(o,a,{detectRenamed:{plug:"input"}})}return{node:t,setup:function(o,r){!o.editorConnection||!o.editorConnection.isRunningLocally()||r.on("nodeAdded."+e.name,s=>{n(s.id,s.parameters,o.editorConnection),s.on("parameterUpdated",a=>{(a.name==="properties"||a.name.startsWith("type-"))&&n(s.id,s.parameters,o.editorConnection)})})}}}const Base={extendSetComponentObjectProperties},SetComponentObjectProperties=Base.extendSetComponentObjectProperties({name:"net.noodl.SetComponentObjectProperties",displayName:"Set Component Object Properties",docs:"https://docs.noodl.net/nodes/component-utilities/set-component-object-properties",getComponentObjectId:function(){return"componentState"+this.nodeScope.componentOwner.getInstanceId()}}),SetParentComponentObjectProperties=Base.extendSetComponentObjectProperties({name:"net.noodl.SetParentComponentObjectProperties",displayName:"Set Parent Component Object Properties",docs:"https://docs.noodl.net/nodes/component-utilities/set-parent-component-object-properties",getComponentObjectId:function(){function e(n){let o;if(n.getRoots().length>0){const r=n.getRoots()[0];r.getVisualParentNode?r.getVisualParentNode()&&(o=r.getVisualParentNode().nodeScope.componentOwner):r.parentNodeScope&&(o=n.parentNodeScope.componentOwner)}else n.parentNodeScope&&(o=n.parentNodeScope.componentOwner);if(o&&o.nodeScope&&o.nodeScope.componentOwner!==n)return o.nodeScope.getNodesWithType("net.noodl.ComponentObject").length>0?o:e(o)}const t=e(this.nodeScope.componentOwner);if(t)return this._internal.parentComponentName=t.name,"componentState"+t.getInstanceId()}}),VariableNodeDefinition$1={name:"Variable2",displayNodeName:"Variable",docs:"https://docs.noodl.net/nodes/data/variable/variable-node",category:"Data",usePortAsLabel:"name",color:"data",initialize:function(){var e=this,t=this._internal;this._internal.onModelChangedCallback=function(n){!e.isInputConnected("fetch")&&n.name===t.name&&(e.sendSignalOnOutput("changed"),e.flagOutputDirty("value"))},t.variablesModel=Model.get("--ndl--global-variables"),t.variablesModel.on("change",this._internal.onModelChangedCallback)},getInspectInfo(){return this._internal.name?this._internal.variablesModel.get(this._internal.name):"[No value set]"},outputs:{name:{type:"string",displayName:"Name",group:"General",getter:function(){return this._internal.name}},changed:{type:"signal",displayName:"Changed",group:"Events"},fetched:{type:"signal",displayName:"Fetched",group:"Events"},value:{type:"*",displayName:"Value",group:"General",getter:function(){var e=this._internal;if(e.name)return e.variablesModel.get(e.name)}}},inputs:{name:{type:{name:"string",identifierOf:"VariableName",identifierDisplayName:"Variable names"},displayName:"Name",group:"General",set:function(e){this.isInputConnected("fetch")===!1?this.setVariableName(e):(this._internal.name=e,this.flagOutputDirty("name"))}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue:function(){this.setVariableName(this._internal.name)}},value:{type:"*",displayName:"Value",group:"General",set:function(e){this._internal.value=e,this.scheduleStore()}}},prototypeExtensions:{scheduleStore:function(){if(!this.hasScheduledStore){this.hasScheduledStore=!0;var e=this._internal;this.scheduleAfterInputsHaveUpdated(function(){this.hasScheduledStore=!1,e.variablesModel.set(e.name,e.value)})}},setVariableName:function(e){this._internal.name=e,this.flagOutputDirty("name"),this.flagOutputDirty("value"),this.sendSignalOnOutput("fetched")},_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this._internal.variablesModel.off("change",this._internal.onModelChangedCallback)}}},VariableNode2={node:VariableNodeDefinition$1},SetVariableNodeDefinition={name:"Set Variable",docs:"https://docs.noodl.net/nodes/data/variable/set-variable",category:"Data",usePortAsLabel:"name",color:"data",initialize:function(){const e=this._internal;e.variablesModel=Model.get("--ndl--global-variables")},getInspectInfo(){return this._internal.name?this._internal.variablesModel.get(this._internal.name):"[No value set]"},outputs:{done:{type:"signal",displayName:"Done",group:"Events"}},inputs:{name:{type:{name:"string",identifierOf:"VariableName",identifierDisplayName:"Variable names"},displayName:"Name",group:"General",set:function(e){this._internal.name=e}},setWith:{type:{name:"enum",enums:[{label:"String",value:"string"},{label:"Boolean",value:"boolean"},{label:"Number",value:"number"},{label:"Empty string",value:"emptyString"},{label:"Date",value:"date"},{label:"Object",value:"object"},{label:"Array",value:"array"},{label:"Any",value:"*"}],allowEditOnly:!0},displayName:"Set as",default:"*",group:"General",set:function(e){this._internal.setWith=e}},do:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){this.scheduleStore()}}},methods:{setValue:function(e){this._internal.value=e},scheduleStore:function(){if(this.hasScheduledStore)return;this.hasScheduledStore=!0;const e=this._internal;this.scheduleAfterInputsHaveUpdated(function(){this.hasScheduledStore=!1;let t=e.setWith==="emptyString"?"":e.value;e.setWith==="object"&&typeof t=="string"&&(t=Model.get(t)),e.setWith==="array"&&typeof t=="string"&&(t=Collection.get(t)),e.setWith==="boolean"&&(t=!!t),e.variablesModel.set(e.name,t,{forceChange:!0}),this.sendSignalOnOutput("done")})},registerInputIfNeeded:function(e){this.hasInput(e)||e==="value"&&this.registerInput(e,{set:this.setValue.bind(this)})}}},SetVariableNode={node:SetVariableNodeDefinition,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.Set Variable",function(n){function o(){var r=[];n.parameters.setWith==="emptyString"||r.push({type:n.parameters.setWith!==void 0?n.parameters.setWith:"*",plug:"input",group:"General",name:"value",displayName:"Value"}),e.editorConnection.sendDynamicPorts(n.id,r)}o(),n.on("parameterUpdated",function(r){o()})})}};var CollectionNode$2={name:"Collection2",docs:"https://docs.noodl.net/nodes/data/array/array-node",displayNodeName:"Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",usePortAsLabel:"collectionId",color:"data",initialize:function(){var e=this,t=!1;this._internal.collectionChangedCallback=function(){e.isInputConnected("fetch")!==!0&&(t||(t=!0,e.scheduleAfterInputsHaveUpdated(function(){e.sendSignalOnOutput("changed"),e.flagOutputDirty("firstItemId"),e.flagOutputDirty("count"),t=!1})))},this._internal.sourceCollectionChangedCallback=function(){e.isInputConnected("store")!==!0&&e.scheduleCopyItems()}},getInspectInfo(){const e=this._internal.collection;return e?[{type:"text",value:"Id: "+e.getId()},{type:"value",value:e.items}]:{type:"text",value:"[No Array]"}},inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this._internal.collectionId=e,this.isInputConnected("fetch")===!1?this.setCollectionID(e):this.flagOutputDirty("id")}},items:{type:"array",group:"General",displayName:"Items",set:function(e){var t=this;e!==void 0&&e!==this._internal.collection&&(this._internal.pendingSourceCollection=e,this.isInputConnected("store")===!1&&this.scheduleAfterInputsHaveUpdated(function(){t.setSourceCollection(e)}))}},fetch:{displayName:"Fetch",group:"Actions",valueChangedToTrue:function(){this.scheduleSetCollection()}}},outputs:{id:{type:"string",displayName:"Id",group:"General",getter:function(){return this._internal.collection?this._internal.collection.getId():this._internal.collectionId}},items:{type:"array",displayName:"Items",group:"General",getter:function(){return this._internal.collection}},firstItemId:{type:"string",displayName:"First Item Id",group:"General",getter:function(){if(this._internal.collection){var e=this._internal.collection.get(0);if(e!==void 0)return e.getId()}}},count:{type:"number",displayName:"Count",group:"General",getter:function(){return this._internal.collection?this._internal.collection.size():0}},changed:{group:"Events",type:"signal",displayName:"Changed"},fetched:{group:"Events",type:"signal",displayName:"Fetched"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection&&this._internal.collection.off("change",this._internal.collectionChangedCallback),this._internal.collection=e,this.flagOutputDirty("id"),e.on("change",this._internal.collectionChangedCallback),this.flagOutputDirty("items"),this.flagOutputDirty("firstItemId"),this.flagOutputDirty("count")},setSourceCollection:function(e){var t=this._internal;t.sourceCollection&&t.sourceCollection instanceof Collection&&t.sourceCollection.off("change",t.sourceCollectionChangedCallback),t.sourceCollection=e,t.sourceCollection instanceof Collection&&t.sourceCollection.on("change",t.sourceCollectionChangedCallback),this._copySourceItems()},scheduleSetCollection:function(){var e=this;this.hasScheduledSetCollection||(this.hasScheduledSetCollection=!0,this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledSetCollection=!1,e.setCollectionID(e._internal.collectionId),e.sendSignalOnOutput("fetched")}))},scheduleStore:function(){var e=this;if(!this.hasScheduledStore){this.hasScheduledStore=!0;var t=this._internal;this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledStore=!1,e.setSourceCollection(t.pendingSourceCollection)})}},_copySourceItems:function(){var e=this._internal;e.collection===void 0&&this.isInputConnected("fetch")===!1&&this.setCollection(Collection.get()),e.collection&&e.collection.set(e.sourceCollection)},scheduleCopyItems:function(){var e=this;this._internal,!this.hasScheduledCopyItems&&(this.hasScheduledCopyItems=!0,this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledCopyItems=!1,e._copySourceItems()}))},_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this._internal.collection&&this._internal.collection.off("change",this._internal.collectionChangedCallback)}}};const CollectionNode2={node:CollectionNode$2};var CollectionInsertNode={name:"CollectionInsert",docs:"https://docs.noodl.net/nodes/data/array/insert-into-array",displayNodeName:"Insert Object Into Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",usePortAsLabel:"collectionId",color:"data",initialize:function(){},inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Array Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this.setCollectionID(e)}},modifyId:{type:{name:"string",allowConnectionsOnly:!0},displayName:"Object Id",group:"Modify",set:function(e){this._internal.modifyId=e}},add:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){var e=this,t=this._internal;this.scheduleAfterInputsHaveUpdated(function(){if(this.context.editorConnection&&this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"insert-warning"),t.modifyId===void 0){this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"insert-warning",{showGlobally:!0,message:"No Object Id specified"});return}if(t.collection===void 0){this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"insert-warning",{showGlobally:!0,message:"No Array Id specified"});return}var n=Model.get(t.modifyId);t.collection.add(n),e.sendSignalOnOutput("modified")})}}},outputs:{modified:{group:"Events",type:"signal",displayName:"Done"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e}}};const CollectionNodeInsert={node:CollectionInsertNode};var CollectionRemoveNode={name:"CollectionRemove",docs:"https://docs.noodl.net/nodes/data/array/remove-from-array",displayNodeName:"Remove Object From Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",usePortAsLabel:"collectionId",color:"data",initialize:function(){},inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Array Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this.setCollectionID(e)}},modifyId:{type:{name:"string",allowConnectionsOnly:!0},displayName:"Object Id",group:"Modify",set:function(e){this._internal.modifyId=e}},remove:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){var e=this,t=this._internal;this.scheduleAfterInputsHaveUpdated(function(){if(t.modifyId!==void 0&&t.collection!==void 0){var n=Model.get(t.modifyId);t.collection.remove(n),e.sendSignalOnOutput("modified")}})}}},outputs:{modified:{group:"Events",type:"signal",displayName:"Done"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e}}};const CollectionNodeRemove={node:CollectionRemoveNode},CollectionClearNode={name:"CollectionClear",docs:"https://docs.noodl.net/nodes/data/array/clear-array",displayNodeName:"Clear Array",category:"Data",usePortAsLabel:"collectionId",color:"data",inputs:{collectionId:{type:{name:"string",identifierOf:"CollectionName",identifierDisplayName:"Array Ids"},displayName:"Array Id",group:"General",set:function(e){e instanceof Collection&&(e=e.getId()),this.setCollectionID(e)}},clear:{displayName:"Do",group:"Actions",valueChangedToTrue(){this.scheduleAfterInputsHaveUpdated(()=>{this._internal.collection.set([]),this.sendSignalOnOutput("modified")})}}},outputs:{modified:{group:"Events",type:"signal",displayName:"Done"}},methods:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e}}},CollectionNodeClear={node:CollectionClearNode};var CollectionNewNode={name:"CollectionNew",docs:"https://docs.noodl.net/nodes/data/array/create-new-array",displayNodeName:"Create New Array",shortDesc:"A collection of models, mainly used together with a For Each Node.",category:"Data",color:"data",initialize:function(){},inputs:{new:{displayName:"Do",group:"Actions",valueChangedToTrue:function(){this.scheduleNew()}},items:{type:"array",group:"General",displayName:"Items",set:function(e){this._internal.sourceCollection=e}}},outputs:{id:{type:"string",displayName:"Id",group:"General",getter:function(){return this._internal.collection?this._internal.collection.getId():this._internal.collectionId}},created:{group:"Events",type:"signal",displayName:"Done"}},prototypeExtensions:{setCollectionID:function(e){this.setCollection(Collection.get(e))},setCollection:function(e){this._internal.collection=e,this.flagOutputDirty("id")},scheduleNew:function(){var e=this;this.hasScheduledNew||(this.hasScheduledNew=!0,this.scheduleAfterInputsHaveUpdated(function(){e.hasScheduledNew=!1;const t=Collection.get();this._internal.sourceCollection!==void 0&&t.set(this._internal.sourceCollection),e.setCollection(t),e.sendSignalOnOutput("created")}))}}};const CollectionNodeNew={node:CollectionNewNode};function applyFilter(e,t){for(var n in t){var o=t[n];if(o.$neq!==void 0){if(e[n]==o.$neq)return!1}else{if(e[n]===void 0)return!1;if(o.$eq!==void 0&&e[n]!=o.$eq)return!1;if(o.$gt!==void 0&&!(e[n]>o.$gt))return!1;if(o.$lt!==void 0&&!(e[n]<o.$lt))return!1;if(o.$gte!==void 0&&!(e[n]>=o.$gte))return!1;if(o.$lte!==void 0&&!(e[n]<=o.$lte))return!1;if(o.$regex!==void 0){var r=e[n]+"",s=new RegExp(o.$regex,o.$case!==!0?"i":void 0);if(!s.test(r))return!1}}}return!0}function sorter(e,t){e instanceof Model&&(e=e.data),t instanceof Model&&(t=t.data);for(var n in this){var o=e[n],r=t[n];if(o!==r)return typeof o=="string"&&typeof r=="string"?this[n]===1?o>r?1:-1:o>r?-1:1:typeof o=="number"&&typeof r=="number"?this[n]===1?o-r:r-o:this[n]===1?o>r?1:-1:o>r?-1:1}return 0}var FilterCollectionNode={name:"Filter Collection",docs:"https://docs.noodl.net/nodes/data/array/array-filter",displayNodeName:"Array Filter",shortDesc:"Filter, sort and limit array",category:"Data",color:"data",initialize:function(){var e=this;this._internal.collectionChangedCallback=function(){e.isInputConnected("filter")!==!0&&e.scheduleFilter()},this._internal.enabled=!0,this._internal.filterSettings={}},getInspectInfo(){const e=this._internal.filteredCollection;return e?[{type:"text",value:"Id: "+e.getId()},{type:"value",value:e.items}]:{type:"text",value:"[Not executed yet]"}},inputs:{items:{type:"array",displayName:"Items",group:"General",set(e){this.bindCollection(e),this.isInputConnected("filter")===!1&&this.scheduleFilter()}},enabled:{type:"boolean",group:"General",displayName:"Enabled",default:!0,set:function(e){this._internal.enabled=e,this.isInputConnected("filter")===!1&&this.scheduleFilter()}},filter:{type:"signal",group:"Actions",displayName:"Filter",valueChangedToTrue:function(){this.scheduleFilter()}}},outputs:{items:{type:"array",displayName:"Items",group:"General",getter:function(){return this._internal.filteredCollection}},firstItemId:{type:"string",displayName:"First Item Id",group:"General",getter:function(){if(this._internal.filteredCollection!==void 0){const e=this._internal.filteredCollection.get(0);if(e!==void 0)return e.getId()}}},count:{type:"number",displayName:"Count",group:"General",getter:function(){return this._internal.filteredCollection?this._internal.filteredCollection.size():0}},modified:{group:"Events",type:"signal",displayName:"Filtered"}},prototypeExtensions:{unbindCurrentCollection:function(){var e=this._internal.collection;e&&(e.off("change",this._internal.collectionChangedCallback),this._internal.collection=void 0)},bindCollection:function(e){this.unbindCurrentCollection(),this._internal.collection=e,e&&e.on("change",this._internal.collectionChangedCallback)},_onNodeDeleted:function(){Node.prototype._onNodeDeleted.call(this),this.unbindCurrentCollection()},getFilter:function(){const e=this._internal.filterSettings,t=["case"];if(e.filterFilter){const o=e.filterFilter.split(",");var n={};return o.forEach(function(r){var s="$"+(e["filterFilterOp-"+r]||"eq");n[r]={},n[r][s]=e["filterFilterValue-"+r],t.forEach(a=>{var l=e["filterFilterOption-"+a+"-"+r];l&&(n[r]["$"+a]=l)})}),n}},getSort:function(){const e=this._internal.filterSettings;if(e.filterSort){const n=e.filterSort.split(",");var t={};return n.forEach(function(o){t[o]=e["filterSort-"+o]==="descending"?-1:1}),t}},getLimit:function(){const e=this._internal.filterSettings;if(e.filterEnableLimit)return e.filterLimit||10},getSkip:function(){const e=this._internal.filterSettings;if(e.filterEnableLimit)return e.filterSkip||0},scheduleFilter:function(){this.collectionChangedScheduled||(this.collectionChangedScheduled=!0,this.scheduleAfterInputsHaveUpdated(()=>{if(this.collectionChangedScheduled=!1,!!this._internal.collection){var e=[].concat(this._internal.collection.items);if(this._internal.enabled){var t=this.getFilter();t&&(e=e.filter(s=>applyFilter(s.data,t)));var n=this.getSort();n&&e.sort(sorter.bind(n));var o=this.getSkip();o&&(e=e.slice(o,e.length));var r=this.getLimit();r&&(e=e.slice(0,r))}this._internal.filteredCollection=Collection.create(e),this.sendSignalOnOutput("modified"),this.flagOutputDirty("firstItemId"),this.flagOutputDirty("items"),this.flagOutputDirty("count")}}))},registerInputIfNeeded:function(e){this.hasInput(e)||this.registerInput(e,{set:userInputSetter$3.bind(this,e)})}}};function userInputSetter$3(e,t){this._internal.filterSettings[e]=t,this.isInputConnected("filter")===!1&&this.scheduleFilter()}function updatePorts$6(e,t,n,o){var r=[];r.push({type:"boolean",plug:"input",group:"Limit",name:"filterEnableLimit",displayName:"Use limit"}),t.filterEnableLimit&&(r.push({type:"number",default:10,plug:"input",group:"Limit",name:"filterLimit",displayName:"Limit"}),r.push({type:"number",default:0,plug:"input",group:"Limit",name:"filterSkip",displayName:"Skip"})),r.push({type:{name:"stringlist",allowEditOnly:!0},plug:"input",group:"Filter",name:"filterFilter",displayName:"Filter"}),r.push({type:{name:"stringlist",allowEditOnly:!0},plug:"input",group:"Sort",name:"filterSort",displayName:"Sort"});const s={string:[{value:"eq",label:"Equals"},{value:"neq",label:"Not Equals"},{value:"regex",label:"Matches RegEx"}],boolean:[{value:"eq",label:"Equals"},{value:"neq",label:"Not Equals"}],number:[{value:"eq",label:"Equals"},{value:"neq",label:"Not Equals"},{value:"lt",label:"Less than"},{value:"gt",label:"Greater than"},{value:"gte",label:"Greater than or equal"},{value:"lte",label:"Less than or equal"}]};if(t.filterFilter){var a=t.filterFilter.split(",");a.forEach(l=>{r.push({type:{name:"enum",enums:[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"}]},default:"string",plug:"input",group:l+" filter",displayName:"Type",editorName:l+" filter | Type",name:"filterFilterType-"+l});var u=t["filterFilterType-"+l];r.push({type:{name:"enum",enums:s[u||"string"]},default:"eq",plug:"input",group:l+" filter",displayName:"Op",editorName:l+" filter| Op",name:"filterFilterOp-"+l}),t["filterFilterOp-"+l]==="regex"&&r.push({type:"boolean",default:!1,plug:"input",group:l+" filter",displayName:"Case sensitive",editorName:l+" filter| Case",name:"filterFilterOption-case-"+l}),r.push({type:u||"string",plug:"input",group:l+" filter",displayName:"Value",editorName:l+" Filter Value",name:"filterFilterValue-"+l})})}if(t.filterSort){var a=t.filterSort.split(",");a.forEach(u=>{r.push({type:{name:"enum",enums:[{value:"ascending",label:"Ascending"},{value:"descending",label:"Descending"}]},default:"ascending",plug:"input",group:u+" sort",displayName:"Sort",editorName:u+" sorting",name:"filterSort-"+u})})}n.sendDynamicPorts(e,r)}const FilterCollectionNode$1={node:FilterCollectionNode,setup:function(e,t){!e.editorConnection||!e.editorConnection.isRunningLocally()||t.on("nodeAdded.Filter Collection",function(n){updatePorts$6(n.id,n.parameters,e.editorConnection,t.getMetaData("dbCollections")),n.on("parameterUpdated",function(o){o.name.startsWith("filter")&&updatePorts$6(n.id,n.parameters,e.editorConnection,t.getMetaData("dbCollections"))}),t.on("metadataChanged.dbCollections",function(o){updatePorts$6(n.id,n.parameters,e.editorConnection)})})}};function CSVToArray(e,t){t=t||",";for(var n=new RegExp("(\\"+t+'|\\r?\\n|\\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^"\\'+t+"\\r\\n]*))","gi"),o=[[]],r=null,s;(r=n.exec(e))&&s!==n.lastIndex;){s=n.lastIndex;var a=r[1];a.length&&a!==t&&o.push([]);var l;r[2]?l=r[2].replace(new RegExp('""',"g"),'"'):l=r[3],o[o.length-1].push(l)}return o}var CSVNode={name:"Static Data",docs:"https://docs.noodl.net/nodes/data/array/static-array",displayNodeName:"Static Array",shortDesc:"Store static data to populate a Collection with items.",category:"Data",color:"data",nodeDoubleClickAction:[{focusPort:"JSON"},{focusPort:"CSV"}],getInspectInfo(){if(this._internal.collection)return[{type:"value",value:this._internal.collection.items}]},dynamicports:[{name:"conditionalports/extended",condition:"type = csv OR type NOT SET",inputs:["csv"]},{name:"conditionalports/extended",condition:"type = json",inputs:["json"]}],inputs:{type:{type:{name:"enum",enums:[{label:"CSV",value:"csv"},{label:"JSON",value:"json"}],allowEditOnly:!0},displayName:"Type",group:"General",default:"csv",set:function(e){this._internal.type=e}},csv:{type:{name:"string",codeeditor:"text",allowEditOnly:!0},displayName:"CSV",group:"General",set:function(e){this._internal.csv=e,this.scheduleParseData()}},json:{type:{name:"string",codeeditor:"json",allowEditOnly:!0},displayName:"JSON",group:"General",set:function(e){this._internal.json=e,this.scheduleParseData()}}},outputs:{items:{type:"array",displayName:"Items",group:"General",getter:function(){return this._internal.collection}},count:{type:"number",displayName:"Count",group:"General",get(){return this._internal.collection?this._internal.collection.size():0}}},methods:{scheduleParseData:function(){var e=this._internal;e.hasScheduledParseData||(e.hasScheduledParseData=!0,this.scheduleAfterInputsHaveUpdated(this.parseData.bind(this)))},parseData:function(){var e=this._internal;if(e.hasScheduledParseData=!1,e.collection=Collection.get(),e.type===void 0||e.type==="csv"){for(var t=CSVToArray(e.csv),n=[],o=t[0],r=1;r<t.length;r++){for(var s=t[r],a={},l=0;l<o.length;l++)a[o[l]]=s[l];n.push(a)}e.collection.set(n),this.flagOutputDirty("items"),this.flagOutputDirty("count")}else if(e.type==="json"){this.context.editorConnection&&this.context.editorConnection.clearWarning(this.nodeScope.componentOwner.name,this.id,"json-parse-warning");try{const u=JSON.parse(e.json);e.collection.set(u),this.flagOutputDirty("items"),this.flagOutputDirty("count")}catch(u){this.context.editorConnection&&this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name,this.id,"json-parse-warning",{showGlobally:!0,message:u.message})}}}}};const StaticData={node:CSVNode},defaultMapCode=`map({
173
173
  // Here you add mappings between the input object and the mapped output object.
174
174
  //myOutputProp: 'inputProp',
175
175
  //anotherProperty: function(object) { return object.get('someProperty') + ' ' + object.get('otherProp') }