@babsey/code-graph 0.4.0 → 0.4.1

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,7 +1,7 @@
1
- (function(c,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("mustache"),require("vue"),require("uuid"),require("@baklavajs/core"),require("@baklavajs/interface-types"),require("@baklavajs/engine"),require("@baklavajs/renderer-vue"),require("toposort"),require("@baklavajs/events"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","vue","uuid","@baklavajs/core","@baklavajs/interface-types","@baklavajs/engine","@baklavajs/renderer-vue","toposort","@baklavajs/events","@vueuse/core"],A):(c=typeof globalThis<"u"?globalThis:c||self,A(c["@babsey/code-graph"]={},c.mustache,c.vue,c.uuid,c["@baklavajs/core"],c["@baklavajs/interface-types"],c["@baklavajs/engine"],c["@baklavajs/renderer-vue"],c.toposort,c["@baklavajs/events"],c["@vueuse/core"]))})(this,(function(c,A,e,F,V,S,D,N,kt,$e,_t){"use strict";A.escape=o=>o;class de extends V.AbstractNode{state;isCodeNode=!0;name="";codeTemplate;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"a"}),this.codeTemplate=function(){return`${this.name}(${Pe(this.codeNodeInputs).join(", ")})`}}get code(){return this.graph.code}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get graph(){return super.graph}get idx(){return this.graph.nodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.graph.getNodesBySameVariableNames(this.state.variableName).filter(t=>!t.state.integrated).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.outputs._code?.value??""}set script(t){this.outputs._code&&(this.outputs._code.value=t),this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const a=this.getConnectedNodesByInterface(t,n);return a.length>0?a[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const a=this.graph.connections.filter(s=>s.from.name!=="_code").filter(s=>s.from.nodeId===this.id).map(s=>s.to.nodeId);a&&(n=n.concat(a))}if(t!=="outputs"){const a=this.graph.connections.filter(s=>s.from.name!=="_code").filter(s=>s.to.nodeId===this.id).map(s=>s.from.nodeId);a&&(n=n.concat(a))}return!n||n.length==0?[]:n.map(a=>this.graph.findNodeById(a))}getConnectedNodesByInterface(t,n){let a=[];if(n!=="outputs"&&this.inputs[t]){const s=this.graph.connections.filter(r=>r.to.id===this.inputs[t]?.id||r.from.id===this.inputs[t]?.id).map(r=>r.from.nodeId);s&&(a=a.concat(s))}if(n!=="inputs"&&this.outputs[t]){const s=this.graph.connections.filter(r=>r.from.id===this.outputs[t]?.id||r.from.id===this.outputs[t]?.id).map(r=>r.to.nodeId);s&&(a=a.concat(s))}return!a||a.length==0?[]:a.map(s=>this.graph.findNodeById(s))}registerCode(t){this.code=t}renderCode(t){return A.render(this.state.codeTemplate,t)}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.suffix})}updateOutputValues(t){Object.keys(this.outputs).forEach(n=>{n!=="_code"&&(t[n]=this.state.integrated?t._code:this.outputs[n].name)})}updateProps(t){this.state.props=t}}class Z extends de{calculate=(t,n)=>{const a={};return this.lockCode||(a._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(a),a};load(t){super.load(t),ue(this.graph,t)}save(){const t=super.save();return je(this.graph,t),t}}const Pe=(o,t=!0)=>{const n=[],a=Object.keys(o);return a.forEach(s=>{if(o[s]?.hidden)return;const l=t&&n.length<a.indexOf(s)?`${s}=`:"";n.push(`${l}{{ inputs.${s} }}`)}),n},ue=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const a=n;a.state&&(a.state.integrated=t.integrated,a.state.modules=t.modules,a.state.props=t.props),Object.entries(t.inputs).forEach(([s,r])=>{s!=="_code"&&a.inputs[s]&&(a.inputs[s].hidden=r.hidden)}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(a.outputs[s].hidden=r.hidden)})},je=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const a=n;a.state&&(t.integrated=a.state.integrated,t.modules=a.state.modules),Object.entries(t.inputs).forEach(([s,r])=>{s!=="_code"&&a.inputs[s]&&(r.hidden=a.inputs[s].hidden)}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(r.hidden=a.outputs[s].hidden)})},Ct=["title"],ee=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.value},e.toDisplayString(o.intf.name),9,Ct))}});class j extends V.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(ee)),this.state=e.reactive({optional:!1})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class W extends j{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(ee)),this.use(N.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const pe=new S.NodeInterfaceType("boolean"),Re=new S.NodeInterfaceType("dict"),he=new S.NodeInterfaceType("list"),G=new S.NodeInterfaceType("node"),te=new S.NodeInterfaceType("number"),ne=new S.NodeInterfaceType("string"),fe=new S.NodeInterfaceType("tuple"),Nt=o=>{new S.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(pe,Re,he,G,te,ne,fe)};class wt extends W{constructor(t,n){super(t,n),this.setComponent(e.markRaw(N.CheckboxInterfaceComponent)),this.use(S.setType,pe)}getValue=()=>this.value?"True":"False"}class Ge extends j{isCodeNodeOutput=!0;suffix="";constructor(t="",n=""){super(t,""),this.suffix=n,this.setComponent(e.markRaw(ee))}get codeValue(){return this.node?.outputs._code.value??""}get node(){const{graph:t}=N.useGraph();return t.value.findNodeById(this.nodeId)}}class me extends W{min;max;constructor(t,n,a,s){super(t,n),this.min=a,this.max=s,this.use(S.setType,te)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class Et extends me{component=e.markRaw(N.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class It extends W{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(S.setType,he)}getValue=()=>`[${this.value}]`}class vt extends me{component=e.markRaw(N.NumberInterfaceComponent)}class ge extends W{constructor(t,n){super(t,n),this.use(S.setType,ne)}getValue=()=>`"${this.value}"`}class Bt extends ge{component=e.markRaw(N.SelectInterfaceComponent);items;constructor(t,n,a){super(t,n),this.items=a}}class Tt extends me{component=e.markRaw(N.SliderInterfaceComponent);min;max;constructor(t,n,a,s){super(t,n,a,s),this.min=a,this.max=s}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const xt=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:a=>{t("update:modelValue",a)}})}}}),$=(o,t)=>{const n=o.__vccOpts||o;for(const[a,s]of t)n[a]=s;return n},Ot={style:{position:"relative"}},St={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},Mt=["placeholder","title"];function Vt(o,t,n,a,s,r){return e.openBlock(),e.createElementBlock("div",Ot,[e.createElementVNode("label",St,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,Mt),[[e.vModelText,o.v]])])}const Le=$(xt,[["render",Vt]]);class $t extends ge{component=e.markRaw(Le)}class Pt extends ge{component=e.markRaw(N.TextareaInputInterfaceComponent)}class jt extends W{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(S.setType,fe)}getValue=()=>`(${this.value})`}function Rt(o){return class extends Z{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate.call(this,{inputs:t,...n})),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(a=>{const s=n[a]();t==="input"?this.addInput(a,s):this.addOutput(a,s)})}}}class Ae extends Z{}function Gt(o){return class extends Ae{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate?.call(this,t,n)),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_code"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_code"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const a=t.inputs[n].value;let s;typeof a=="number"?s=new N.IntegerInterface(n,a).use(S.setType,te):s=new N.TextInputInterface(n,JSON.stringify(a)).use(S.setType,ne),s.use(N.displayInSidebar,!0),this.addInput(n,s)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const a=new Ge(n);this.addOutput(n,a)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}ue(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),a=o.onUpdate.call(this,t,n);this.updateInterfaces("input",a.inputs??{},a.forceUpdateInputs??[]),this.updateInterfaces("output",a.outputs??{},a.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const a={};for(const s of t)a[s]=n[s].value;return a}updateInterfaces(t,n,a){const s=t==="input"?this.staticInputKeys:this.staticOutputKeys,r=t==="input"?this.inputs:this.outputs;for(const l of Object.keys(r))s.includes(l)||n[l]&&!a.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(r[l])continue;const i=n[l]();t==="input"?this.addInput(l,i):this.addOutput(l,i)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(a=>{const s=n[a]();t==="input"?this.addInput(a,s):this.addOutput(a,s)})}}}const be="__baklava_SubgraphInputNode",ye="__baklava_SubgraphOutputNode";class De extends Z{graphInterfaceId;constructor(){super(),this.graphInterfaceId=F.v4()}onPlaced(){super.onPlaced(),this.initializeIo()}load(t){super.load(t),this.graphInterfaceId=t.graphInterfaceId}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}update(){}}class ke extends De{static isGraphInputNode(t){return t.type===be}type=be;inputs={name:new V.NodeInterface("Name","Input")};outputs={placeholder:new V.NodeInterface("Value",void 0)}}class _e extends De{static isGraphOutputNode(t){return t.type===ye}type=ye;inputs={name:new V.NodeInterface("Name","Output"),placeholder:new V.NodeInterface("Value",void 0)};outputs={output:new V.NodeInterface("Output",void 0).setHidden(!0)};calculate=({placeholder:t})=>({output:t})}const Lt=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function ze(o){return class extends de{type=V.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;update(){}onConnected(){}onUnconnected(){}calculate=async(n,a)=>{if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!a.engine||typeof a.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const s=a.engine.getInputValues(this.subgraph);for(const i of this.subgraph.inputs)s.set(i.nodeInterfaceId,n[i.id]);const r=await a.engine.runGraph(this.subgraph,s,a.globalValues);a.engine.pause(),D.applyResult(r,a.engine.editor),a.engine.resume();const l={};for(const i of this.subgraph.outputs)l[i.id]=r.get(i.nodeId)?.get("output");return l._calculationResults=r,this.lockCode||(l._code=this.renderCode({inputs:n,...a.globalValues})),this.updateOutputValues(l),l};load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.state.codeTemplate=`{{ #nodes }}{{ script }}
2
- {{ /nodes }}`,this.events.update.emit(null)}renderCode(n){return this.subgraph?this.subgraph.renderCode({nodes:this.subgraph.scriptedCodeNodes}):A.render(this.state.codeTemplate,n)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(a=>a.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(a=>a.id===n)||this.removeOutput(n);this.addInput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new V.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,a){const s=new j(n.name,void 0);return new Proxy(s,{get:(r,l)=>{if(Lt.includes(l)||l in r||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(r,l);let i;a?i=this.subgraph?.nodes.find(_=>ke.isGraphInputNode(_)&&_.graphInterfaceId===n.id)?.outputs.placeholder.id:i=this.subgraph?.nodes.find(_=>_e.isGraphOutputNode(_)&&_.graphInterfaceId===n.id)?.inputs.placeholder.id;const d=this.subgraph?.connections.find(m=>i===(a?m.from:m.to)?.id),p=a?d?.to:d?.from;if(p)return Reflect.get(p,l)}})}}}A.escape=o=>o;class oe{_id;_state;viewModel;constructor(){this._id=F.v4(),this._state=e.reactive({lockCode:!1,modules:{},script:"",template:""})}get engine(){return this.viewModel?.engine}get graph(){return this.viewModel?.editor.graph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.engine?.runOnce(null)}get modules(){const t=[];return this.graph?.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.state.modules[n])))):[]}get script(){return this.state.script}set script(t){this.state.script=t,this.engine?.runOnce(null)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}clear(){this.state.script=""}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}registerViewModel(t){this.viewModel=t}renderCode(t){this.state.script=A.render(this.state.template||"",t)}}class At extends oe{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>zo))}}class Dt extends oe{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>Ho))}}const zt=o=>{o.allowMultipleConnections=!0};class He extends D.BaseEngine{order=new Map;constructor(t){super(t)}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(t,n,a){this.order.has(t.id)||this.order.set(t.id,D.sortTopologically(t));const{calculationOrder:s,connectionsFromNode:r}=this.order.get(t.id),l=new Map;for(const i of s){const d={};Object.entries(i.inputs).forEach(([m,_])=>{d[m]=this.getInterfaceValue(n,_.id)}),i.isCodeNode&&(i.updateCodeTemplate(),i.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:d,node:i});let p;if(i.calculate){if(p=await i.calculate(d,{globalValues:a,engine:this}),r.has(i))for(const[m,_]of Object.entries(p))this.hooks.transferData.execute(p[m],_),r.get(i).forEach(f=>n.set(f.to.id,_))}else{p={};for(const[m,_]of Object.entries(i.outputs))p[m]=this.getInterfaceValue(n,_.id)}this.events.afterNodeCalculation.emit({outputValues:p,node:i}),l.set(i.id,new Map(Object.entries(p))),r.has(i)&&r.get(i).forEach(m=>{const _=Object.entries(i.outputs).find(([,v])=>v.id===m.from.id)?.[0];if(!_)throw new Error(`Could not find key for interface ${m.from.id}
1
+ (function(c,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("mustache"),require("vue"),require("uuid"),require("@baklavajs/core"),require("@baklavajs/interface-types"),require("@baklavajs/engine"),require("@baklavajs/renderer-vue"),require("toposort"),require("@baklavajs/events"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","mustache","vue","uuid","@baklavajs/core","@baklavajs/interface-types","@baklavajs/engine","@baklavajs/renderer-vue","toposort","@baklavajs/events","@vueuse/core"],A):(c=typeof globalThis<"u"?globalThis:c||self,A(c["@babsey/code-graph"]={},c.mustache,c.vue,c.uuid,c["@baklavajs/core"],c["@baklavajs/interface-types"],c["@baklavajs/engine"],c["@baklavajs/renderer-vue"],c.toposort,c["@baklavajs/events"],c["@vueuse/core"]))})(this,(function(c,A,e,F,V,S,D,N,kt,$e,_t){"use strict";A.escape=o=>o;class de extends V.AbstractNode{codeTemplate;isCodeNode=!0;mask=null;name="";state;inputs={};outputs={};constructor(){super(),this.initializeIo(),this.twoColumn=!0,this.state=e.reactive({codeTemplate:"",hidden:!1,integrated:!1,lockCode:!1,modules:[],props:null,script:"",variableName:"a"}),this.codeTemplate=function(){return`${this.name}(${Pe(this.codeNodeInputs).join(", ")})`}}get code(){return this.graph.code}get codeNodeInputs(){return Object.fromEntries(Object.entries(this.inputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get codeNodeOutputs(){return Object.fromEntries(Object.entries(this.outputs).filter(t=>t[1].isCodeNode&&t[1].type!="node"))}get graph(){return super.graph}get idx(){return this.graph.nodes.filter(t=>!t.state.integrated).indexOf(this)??-1}get idxByVariableNames(){return this.graph.getNodesBySameVariableNames(this.state.variableName).filter(t=>!t.state.integrated).indexOf(this)??-1}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.events.update.emit(null)}get optionalInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>t[1].optional))}get requiredInputs(){return Object.fromEntries(Object.entries(this.codeNodeInputs).filter(t=>!t[1].optional))}get script(){return this.outputs._code?.value??""}set script(t){this.outputs._code&&(this.outputs._code.value=t),this.events.update.emit(null)}get shortId(){return this.id.slice(0,6)}get subgraph(){}get variableName(){return this.state.variableName?this.state.variableName+(this.idxByVariableNames+1):""}getConnectedNodeByInterface(t,n){const a=this.getConnectedNodesByInterface(t,n);return a.length>0?a[0]:null}getConnectedNodes(t){let n=[];if(t!=="inputs"){const a=this.graph.connections.filter(s=>s.from.name!=="_code").filter(s=>s.from.nodeId===this.id).map(s=>s.to.nodeId);a&&(n=n.concat(a))}if(t!=="outputs"){const a=this.graph.connections.filter(s=>s.from.name!=="_code").filter(s=>s.to.nodeId===this.id).map(s=>s.from.nodeId);a&&(n=n.concat(a))}return!n||n.length==0?[]:n.map(a=>this.graph.findNodeById(a))}getConnectedNodesByInterface(t,n){let a=[];if(n!=="outputs"&&this.inputs[t]){const s=this.graph.connections.filter(r=>r.to.id===this.inputs[t]?.id||r.from.id===this.inputs[t]?.id).map(r=>r.from.nodeId);s&&(a=a.concat(s))}if(n!=="inputs"&&this.outputs[t]){const s=this.graph.connections.filter(r=>r.from.id===this.outputs[t]?.id||r.from.id===this.outputs[t]?.id).map(r=>r.to.nodeId);s&&(a=a.concat(s))}return!a||a.length==0?[]:a.map(s=>this.graph.findNodeById(s))}renderCode(t){return A.render(this.state.codeTemplate,t)}updateCodeTemplate(){this.state.codeTemplate=this.codeTemplate.call(this)}updateModules(t){if(t)this.state.modules=t;else if(this.type.includes(".")){const n=this.type.split(".");this.state.modules.push(n.slice(0,n.length-1).join("."))}}updateOutputNames(){Object.values(this.codeNodeOutputs).forEach(t=>{t.name=this.state.integrated?"":this.variableName+t.suffix})}updateOutputValues(t){Object.keys(this.outputs).forEach(n=>{n!=="_code"&&(t[n]=this.state.integrated?t._code:this.outputs[n].name)})}updateProps(t){this.state.props=t}}class Z extends de{calculate=(t,n)=>{const a={};return this.lockCode||(a._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(a),a};load(t){super.load(t),ue(this.graph,t)}save(){const t=super.save();return je(this.graph,t),t}}const Pe=(o,t=!0)=>{const n=[],a=Object.keys(o);return a.forEach(s=>{if(o[s]?.hidden)return;const l=t&&n.length<a.indexOf(s)?`${s}=`:"";n.push(`${l}{{ inputs.${s} }}`)}),n},ue=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const a=n;a.state&&(a.state.integrated=t.integrated,a.state.modules=t.modules,a.state.props=t.props),Object.entries(t.inputs).forEach(([s,r])=>{s!=="_code"&&a.inputs[s]&&(a.inputs[s].hidden=r.hidden)}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(a.outputs[s].hidden=r.hidden)})},je=(o,t)=>{if(!o)return;const n=o.findNodeById(t.id);if(!n||n.subgraph)return;const a=n;a.state&&(t.integrated=a.state.integrated,t.modules=a.state.modules),Object.entries(t.inputs).forEach(([s,r])=>{s!=="_code"&&a.inputs[s]&&(r.hidden=a.inputs[s].hidden)}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(r.hidden=a.outputs[s].hidden)})},Ct=["title"],ee=e.defineComponent({__name:"CodeNodeInterface",props:{intf:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",{title:o.intf.value},e.toDisplayString(o.intf.name),9,Ct))}});class j extends V.NodeInterface{isCodeNode=!0;code;state;type=null;constructor(t,n){super(t,n),this.setComponent(e.markRaw(ee)),this.state=e.reactive({optional:!1})}get optional(){return this.state.optional}get shortId(){return this.id.slice(0,6)}getValue=()=>`${this.value??"None"}`;setOptional(t){return this.state.optional=t,this.setHidden(t),this}}class W extends j{constructor(t="",n){super(t,n),this.setComponent(e.markRaw(ee)),this.use(N.displayInSidebar,!0)}get value(){return super.value}set value(t){super.value=t,this.name!=="_code"&&this.setHidden(!1)}}const pe=new S.NodeInterfaceType("boolean"),Re=new S.NodeInterfaceType("dict"),he=new S.NodeInterfaceType("list"),G=new S.NodeInterfaceType("node"),te=new S.NodeInterfaceType("number"),ne=new S.NodeInterfaceType("string"),fe=new S.NodeInterfaceType("tuple"),Nt=o=>{new S.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(pe,Re,he,G,te,ne,fe)};class wt extends W{constructor(t,n){super(t,n),this.setComponent(e.markRaw(N.CheckboxInterfaceComponent)),this.use(S.setType,pe)}getValue=()=>this.value?"True":"False"}class Ge extends j{isCodeNodeOutput=!0;suffix="";constructor(t="",n=""){super(t,""),this.suffix=n,this.setComponent(e.markRaw(ee))}get codeValue(){return this.node?.outputs._code.value??""}get node(){const{graph:t}=N.useGraph();return t.value.findNodeById(this.nodeId)}}class me extends W{min;max;constructor(t,n,a,s){super(t,n),this.min=a,this.max=s,this.use(S.setType,te)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class Et extends me{component=e.markRaw(N.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class It extends W{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(S.setType,he)}getValue=()=>`[${this.value}]`}class vt extends me{component=e.markRaw(N.NumberInterfaceComponent)}class ge extends W{constructor(t,n){super(t,n),this.use(S.setType,ne)}getValue=()=>`"${this.value}"`}class Bt extends ge{component=e.markRaw(N.SelectInterfaceComponent);items;constructor(t,n,a){super(t,n),this.items=a}}class Tt extends me{component=e.markRaw(N.SliderInterfaceComponent);min;max;constructor(t,n,a,s){super(t,n,a,s),this.min=a,this.max=s}getValue=()=>`${Math.round(this.value*1e3)/1e3}`}const xt=e.defineComponent({props:{intf:{type:Object,required:!0},modelValue:{type:String,required:!0}},emits:["update:modelValue"],setup(o,{emit:t}){return{v:e.computed({get:()=>o.modelValue,set:a=>{t("update:modelValue",a)}})}}}),$=(o,t)=>{const n=o.__vccOpts||o;for(const[a,s]of t)n[a]=s;return n},Ot={style:{position:"relative"}},St={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},Mt=["placeholder","title"];function Vt(o,t,n,a,s,r){return e.openBlock(),e.createElementBlock("div",Ot,[e.createElementVNode("label",St,e.toDisplayString(o.intf.name),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[0]||(t[0]=l=>o.v=l),type:"text",class:"baklava-input",placeholder:o.intf.name,title:o.intf.name},null,8,Mt),[[e.vModelText,o.v]])])}const Le=$(xt,[["render",Vt]]);class $t extends ge{component=e.markRaw(Le)}class Pt extends ge{component=e.markRaw(N.TextareaInputInterfaceComponent)}class jt extends W{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(S.setType,fe)}getValue=()=>`(${this.value})`}function Rt(o){return class extends Z{type=o.type;inputs={};outputs={};constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate.call(this,{inputs:t,...n})),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.variableName!=null&&(this.state.variableName=o.variableName),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),this.addInput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0))}onPlaced(){o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}executeFactory(t,n){Object.keys(n||{}).forEach(a=>{const s=n[a]();t==="input"?this.addInput(a,s):this.addOutput(a,s)})}}}class Ae extends Z{}function Gt(o){return class extends Ae{type=o.type;inputs={};outputs={};preventUpdate=!1;staticInputKeys=Object.keys(o.inputs??{});staticOutputKeys=Object.keys(o.outputs??{});constructor(){super(),this._title=o.title??o.type,this.executeFactory("input",o.inputs),this.executeFactory("output",o.outputs),o.calculate&&(this.calculate=(t,n)=>o.calculate?.call(this,t,n)),o.onCreate?.call(this),this.name=o.name??o.type,this.updateModules(o.modules),o.codeTemplate&&(this.codeTemplate=o.codeTemplate),o.variableName&&(this.state.variableName=o.variableName),this.addInput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}onPlaced(){this.events.update.subscribe(this,t=>{t&&(t.type==="input"&&this.staticInputKeys.includes(t.name)||t.type==="output"&&this.staticOutputKeys.includes(t.name))&&this.onUpdate()}),this.onUpdate(),o.onPlaced?.call(this)}onConnected(){o.onConnected?.call(this)}onDestroy(){o.onDestroy?.call(this)}onUnconnected(){o.onUnconnected?.call(this)}update(){o.update?.call(this)}load(t){this.preventUpdate=!0,this.hooks.beforeLoad.execute(t),this.id=t.id,this.title=t.title;for(const n of this.staticInputKeys)this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id,n!=="_code"&&(this.inputs[n].hidden=t.inputs[n].hidden);for(const n of this.staticOutputKeys)this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id,n!=="_code"&&(this.outputs[n].hidden=t.outputs[n].hidden);this.preventUpdate=!1,this.onUpdate(),this.preventUpdate=!0;for(const n of Object.keys(t.inputs))if(!this.staticInputKeys.includes(n)){if(!this.inputs[n]){const a=t.inputs[n].value;let s;typeof a=="number"?s=new N.IntegerInterface(n,a).use(S.setType,te):s=new N.TextInputInterface(n,JSON.stringify(a)).use(S.setType,ne),s.use(N.displayInSidebar,!0),this.addInput(n,s)}this.inputs[n]&&(this.inputs[n].load(t.inputs[n]),this.inputs[n].nodeId=this.id)}for(const n of Object.keys(t.outputs))if(!this.staticOutputKeys.includes(n)){if(!this.outputs[n]){const a=new Ge(n);this.addOutput(n,a)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}ue(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(this.preventUpdate)return;this.graph&&this.graph.activeTransactions++;const t=this.getStaticValues(this.staticInputKeys,this.inputs),n=this.getStaticValues(this.staticOutputKeys,this.outputs),a=o.onUpdate.call(this,t,n);this.updateInterfaces("input",a.inputs??{},a.forceUpdateInputs??[]),this.updateInterfaces("output",a.outputs??{},a.forceUpdateOutputs??[]),this.graph&&this.graph.activeTransactions--}getStaticValues(t,n){const a={};for(const s of t)a[s]=n[s].value;return a}updateInterfaces(t,n,a){const s=t==="input"?this.staticInputKeys:this.staticOutputKeys,r=t==="input"?this.inputs:this.outputs;for(const l of Object.keys(r))s.includes(l)||n[l]&&!a.includes(l)||(t==="input"?this.removeInput(l):this.removeOutput(l));for(const l of Object.keys(n)){if(r[l])continue;const i=n[l]();t==="input"?this.addInput(l,i):this.addOutput(l,i)}}updateProps(t){this.state.props=t,this.onUpdate()}executeFactory(t,n){Object.keys(n||{}).forEach(a=>{const s=n[a]();t==="input"?this.addInput(a,s):this.addOutput(a,s)})}}}A.escape=o=>o;class oe{_id;_state;viewModel;constructor(){this._id=F.v4(),this._state=e.reactive({lockCode:!1,modules:{},script:"",template:""})}get engine(){return this.viewModel?.engine}get graph(){return this.viewModel?.editor.graph}get id(){return this._id}get lockCode(){return this.state.lockCode}set lockCode(t){this.state.lockCode=t,this.engine?.runOnce(null)}get modules(){const t=[];return this.graph?.codeNodes.filter(n=>n.state.modules?.length>0).forEach(n=>t.push(...n.state.modules)),t?(t.sort(),Array.from(new Set(t.map(n=>this.state.modules[n])))):[]}get script(){return this.state.script}set script(t){this.state.script=t,this.engine?.runOnce(null)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}clear(){this.state.script=""}async loadTemplate(t){t.then(n=>{this._state.template=n.default??""})}registerViewModel(t){this.viewModel=t}renderCode(t){this.state.script=A.render(this.state.template||"",t)}}class Lt extends oe{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>zo))}}class At extends oe{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>Ho))}}const Dt=o=>{o.allowMultipleConnections=!0};class De extends D.BaseEngine{order=new Map;constructor(t){super(t)}start(){super.start(),this.recalculateOrder=!0,this.calculateWithoutData()}async runGraph(t,n,a){this.order.has(t.id)||this.order.set(t.id,D.sortTopologically(t));const{calculationOrder:s,connectionsFromNode:r}=this.order.get(t.id),l=new Map;for(const i of s){const d={};Object.entries(i.inputs).forEach(([m,_])=>{d[m]=this.getInterfaceValue(n,_.id)}),i.isCodeNode&&(i.updateCodeTemplate(),i.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:d,node:i});let p;if(i.calculate){if(p=await i.calculate(d,{globalValues:a,engine:this}),r.has(i))for(const[m,_]of Object.entries(p))this.hooks.transferData.execute(p[m],_),r.get(i).forEach(f=>n.set(f.to.id,_))}else{p={};for(const[m,_]of Object.entries(i.outputs))p[m]=this.getInterfaceValue(n,_.id)}this.events.afterNodeCalculation.emit({outputValues:p,node:i}),l.set(i.id,new Map(Object.entries(p))),r.has(i)&&r.get(i).forEach(m=>{const _=Object.entries(i.outputs).find(([,v])=>v.id===m.from.id)?.[0];if(!_)throw new Error(`Could not find key for interface ${m.from.id}
3
2
  This is likely an internal issue. Please report it on GitHub.`);const f=this.hooks.transferData.execute(p[_],m);m.to.allowMultipleConnections?n.has(m.to.id)?n.get(m.to.id).push(f):n.set(m.to.id,[f]):n.set(m.to.id,f)})}return l}async execute(t){this.recalculateOrder&&(this.order.clear(),this.recalculateOrder=!1);const n=this.getInputValues(this.editor.graph);return await this.runGraph(this.editor.graph,n,t)}getInputValues(t){const n=new Map;for(const a of t.nodes)Object.values(a.inputs).forEach(s=>{s.connectionCount===0&&n.set(s.id,s.getValue?s.getValue():s.value)}),a.calculate||Object.values(a.outputs).forEach(s=>{n.set(s.id,s.getValue?s.getValue():s.value)});return n}onChange(t){this.recalculateOrder=t||this.recalculateOrder,this.calculateWithoutData()}getInterfaceValue(t,n){if(!t.has(n))throw new Error(`Could not find value for interface ${n}
4
- This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const Ht={},Ut={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-check"};function Ft(o,t){return e.openBlock(),e.createElementBlock("svg",Ut,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M5 12l5 5l10 -10"},null,-1)])])}const Ue=$(Ht,[["render",Ft]]),qt={},Wt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function Yt(o,t){return e.openBlock(),e.createElementBlock("svg",Wt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const Fe=$(qt,[["render",Yt]]),Kt={},Xt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-copy"};function Jt(o,t){return e.openBlock(),e.createElementBlock("svg",Xt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z"},null,-1),e.createElementVNode("path",{d:"M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1"},null,-1)])])}const qe=$(Kt,[["render",Jt]]),Qt={},Zt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function en(o,t){return e.openBlock(),e.createElementBlock("svg",Zt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const We=$(Qt,[["render",en]]),tn={},nn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function on(o,t){return e.openBlock(),e.createElementBlock("svg",nn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Ye=$(tn,[["render",on]]),sn={},an={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function rn(o,t){return e.openBlock(),e.createElementBlock("svg",an,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Ke=$(sn,[["render",rn]]),ln={},cn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function dn(o,t){return e.openBlock(),e.createElementBlock("svg",cn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const Xe=$(ln,[["render",dn]]),un={},pn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function hn(o,t){return e.openBlock(),e.createElementBlock("svg",pn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Je=$(un,[["render",hn]]),fn={},mn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function gn(o,t){return e.openBlock(),e.createElementBlock("svg",mn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Qe=$(fn,[["render",gn]]),bn={},yn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-lock-code"};function kn(o,t){return e.openBlock(),e.createElementBlock("svg",yn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const Ce=$(bn,[["render",kn]]),_n={},Cn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-player-play"};function Nn(o,t){return e.openBlock(),e.createElementBlock("svg",Cn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const Ze=$(_n,[["render",Nn]]),wn={},En={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-plus"};function In(o,t){return e.openBlock(),e.createElementBlock("svg",En,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 5l0 14"},null,-1),e.createElementVNode("path",{d:"M5 12l14 0"},null,-1)])])}const et=$(wn,[["render",In]]),vn={},Bn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function Tn(o,t){return e.openBlock(),e.createElementBlock("svg",Bn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const tt=$(vn,[["render",Tn]]),xn={},On={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function Sn(o,t){return e.openBlock(),e.createElementBlock("svg",On,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const nt=$(xn,[["render",Sn]]),Mn={},Vn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function $n(o,t){return e.openBlock(),e.createElementBlock("svg",Vn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const ot=$(Mn,[["render",$n]]),Pn={},jn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function Rn(o,t){return e.openBlock(),e.createElementBlock("svg",jn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const st=$(Pn,[["render",Rn]]),Gn={},Ln={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-x"};function An(o,t){return e.openBlock(),e.createElementBlock("svg",Ln,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 6l-12 12"},null,-1),e.createElementVNode("path",{d:"M6 6l12 12"},null,-1)])])}const at=$(Gn,[["render",An]]),Ne="CLEAR_ALL",we="RUN_ENGINE",Ee="TOGGLE_MINIMAP",Ie="TOGGLE_PALETTE",rt=(o,t,n)=>{const a=n.zoomToFit.paddingLeft;t.registerCommand(Ie,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?a:50},canExecute:()=>!0}),t.registerCommand(Ne,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(Ee,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},it=o=>{const t={command:we,title:"Run",icon:e.computed(()=>Ze)},n={command:Ie,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Ye:Ke)},a={command:Ne,title:"Clear all",icon:e.computed(()=>st)},s={command:Ee,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?nt:tt)};o.toolbar.commands=[n,t,...N.DEFAULT_TOOLBAR_COMMANDS,a,s]},lt=(o,t)=>{t.registerCommand(we,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function ct(o){const t=Symbol("CodeEngineToken");o.engine=new He(o.editor),lt(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(N.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(N.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(N.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(N.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=F.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const a=o.displayedGraph.findNodeById(n.to.nodeId);a&&a.isCodeNode&&a.onConnected();const s=o.displayedGraph.findNodeById(n.from.nodeId);s&&s.isCodeNode&&s.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const a=o.displayedGraph.findNodeById(n.to.nodeId);a&&a.isCodeNode&&a.onUnconnected();const s=o.displayedGraph.findNodeById(n.from.nodeId);s&&s.isCodeNode&&s.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),D.applyResult(n,o.editor),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.code.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class K extends V.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return ve(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNodeAtCoordinates=(t,n={x:0,y:0},a)=>(this.addNode(t,a),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(a=>a.from.id===t.id&&a.to.id===n.id)}renderCode(t){return A.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(r=>t.includes(r.to.nodeId)&&t.includes(r.from.nodeId)).map(r=>[r.to.nodeId,r.from.nodeId]);t.reverse(),t=kt.array(t,n),t.reverse();const a=this.nodes.map(r=>r.id).filter(r=>!t.includes(r));t=[...t,...a];const s=t.map(r=>this.findNodeById(r));s&&(this.nodes=s)}catch{console.warn("Failed to sort nodes.")}}}const ve=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...ve(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},Dn=(o=0,t=100)=>({x:o*420,y:t}),zn=o=>{const t={...o.position};return t.x-=440,t.y+=50,t};function Hn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function Un(o,t){return Object.fromEntries(Object.entries(o).map(([n,a])=>[n,t(a)]))}class X extends V.GraphTemplate{static fromGraph(t,n){return new X(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,a=f=>{const v=F.v4();return n.set(f,v),v},s=f=>{const v=n.get(f);if(!v)throw new Error(`Unable to create graph from template: Could not map old id ${f} to new id`);return v},r=f=>Un(f,v=>({id:a(v.id),templateId:v.id,value:v.value})),l=this.nodes.map(f=>({...f,id:a(f.id),inputs:r(f.inputs),outputs:r(f.outputs)})),i=this.connections.map(f=>({id:a(f.id),from:s(f.from),to:s(f.to)})),d=this.inputs.map(f=>({id:f.id,name:f.name,nodeId:s(f.nodeId),nodeInterfaceId:s(f.nodeInterfaceId)})),p=this.outputs.map(f=>({id:f.id,name:f.name,nodeId:s(f.nodeId),nodeInterfaceId:s(f.nodeInterfaceId)})),m={id:F.v4(),nodes:l,connections:i,inputs:d,outputs:p};return t||(t=new K(this.editor)),t.load(m).forEach(f=>console.warn(f)),t.template=this,t}}const Fn=o=>!(o instanceof K);function dt(o,t){return{switchGraph:a=>{let s;if(Fn(a))s=new K(o.value),a.createGraph(s);else{if(a!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");s=a}t.value&&t.value!==o.value.graph&&t.value.destroy(),s.panning=s.panning??a.panning??{x:0,y:0},s.scaling=s.scaling??a.scaling??1,s.selectedNodes=s.selectedNodes??[],s.sidebar=s.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=s,s.code?.engine?.runOnce(null)}}}function qn(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var se={exports:{}};var Wn=se.exports,ut;function Yn(){return ut||(ut=1,(function(o,t){(function(a,s){o.exports=s()})(Wn,function(){return(function(){var n={686:(function(r,l,i){i.d(l,{default:function(){return x}});var d=i(279),p=i.n(d),m=i(370),_=i.n(m),f=i(817),v=i.n(f);function g(b){try{return document.execCommand(b)}catch{return!1}}var C=function(h){var k=v()(h);return g("cut"),k},u=C;function y(b){var h=document.documentElement.getAttribute("dir")==="rtl",k=document.createElement("textarea");k.style.fontSize="12pt",k.style.border="0",k.style.padding="0",k.style.margin="0",k.style.position="absolute",k.style[h?"right":"left"]="-9999px";var E=window.pageYOffset||document.documentElement.scrollTop;return k.style.top="".concat(E,"px"),k.setAttribute("readonly",""),k.value=b,k}var O=function(h,k){var E=y(h);k.container.appendChild(E);var I=v()(E);return g("copy"),E.remove(),I},T=function(h){var k=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},E="";return typeof h=="string"?E=O(h,k):h instanceof HTMLInputElement&&!["text","search","url","tel","password"].includes(h?.type)?E=O(h.value,k):(E=v()(h),g("copy")),E},M=T;function H(b){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?H=function(k){return typeof k}:H=function(k){return k&&typeof Symbol=="function"&&k.constructor===Symbol&&k!==Symbol.prototype?"symbol":typeof k},H(b)}var U=function(){var h=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},k=h.action,E=k===void 0?"copy":k,I=h.container,B=h.target,L=h.text;if(E!=="copy"&&E!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(B!==void 0)if(B&&H(B)==="object"&&B.nodeType===1){if(E==="copy"&&B.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(E==="cut"&&(B.hasAttribute("readonly")||B.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if(L)return M(L,{container:I});if(B)return E==="cut"?u(B):M(B,{container:I})},J=U;function z(b){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?z=function(k){return typeof k}:z=function(k){return k&&typeof Symbol=="function"&&k.constructor===Symbol&&k!==Symbol.prototype?"symbol":typeof k},z(b)}function w(b,h){if(!(b instanceof h))throw new TypeError("Cannot call a class as a function")}function P(b,h){for(var k=0;k<h.length;k++){var E=h[k];E.enumerable=E.enumerable||!1,E.configurable=!0,"value"in E&&(E.writable=!0),Object.defineProperty(b,E.key,E)}}function R(b,h,k){return h&&P(b.prototype,h),k&&P(b,k),b}function ae(b,h){if(typeof h!="function"&&h!==null)throw new TypeError("Super expression must either be null or a function");b.prototype=Object.create(h&&h.prototype,{constructor:{value:b,writable:!0,configurable:!0}}),h&&Q(b,h)}function Q(b,h){return Q=Object.setPrototypeOf||function(E,I){return E.__proto__=I,E},Q(b,h)}function Me(b){var h=Ve();return function(){var E=q(b),I;if(h){var B=q(this).constructor;I=Reflect.construct(E,arguments,B)}else I=E.apply(this,arguments);return re(this,I)}}function re(b,h){return h&&(z(h)==="object"||typeof h=="function")?h:ie(b)}function ie(b){if(b===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return b}function Ve(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function q(b){return q=Object.setPrototypeOf?Object.getPrototypeOf:function(k){return k.__proto__||Object.getPrototypeOf(k)},q(b)}function Y(b,h){var k="data-clipboard-".concat(b);if(h.hasAttribute(k))return h.getAttribute(k)}var le=(function(b){ae(k,b);var h=Me(k);function k(E,I){var B;return w(this,k),B=h.call(this),B.resolveOptions(I),B.listenClick(E),B}return R(k,[{key:"resolveOptions",value:function(){var I=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof I.action=="function"?I.action:this.defaultAction,this.target=typeof I.target=="function"?I.target:this.defaultTarget,this.text=typeof I.text=="function"?I.text:this.defaultText,this.container=z(I.container)==="object"?I.container:document.body}},{key:"listenClick",value:function(I){var B=this;this.listener=_()(I,"click",function(L){return B.onClick(L)})}},{key:"onClick",value:function(I){var B=I.delegateTarget||I.currentTarget,L=this.action(B)||"copy",ce=J({action:L,container:this.container,target:this.target(B),text:this.text(B)});this.emit(ce?"success":"error",{action:L,text:ce,trigger:B,clearSelection:function(){B&&B.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(I){return Y("action",I)}},{key:"defaultTarget",value:function(I){var B=Y("target",I);if(B)return document.querySelector(B)}},{key:"defaultText",value:function(I){return Y("text",I)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(I){var B=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return M(I,B)}},{key:"cut",value:function(I){return u(I)}},{key:"isSupported",value:function(){var I=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],B=typeof I=="string"?[I]:I,L=!!document.queryCommandSupported;return B.forEach(function(ce){L=L&&!!document.queryCommandSupported(ce)}),L}}]),k})(p()),x=le}),828:(function(r){var l=9;if(typeof Element<"u"&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}function d(p,m){for(;p&&p.nodeType!==l;){if(typeof p.matches=="function"&&p.matches(m))return p;p=p.parentNode}}r.exports=d}),438:(function(r,l,i){var d=i(828);function p(f,v,g,C,u){var y=_.apply(this,arguments);return f.addEventListener(g,y,u),{destroy:function(){f.removeEventListener(g,y,u)}}}function m(f,v,g,C,u){return typeof f.addEventListener=="function"?p.apply(null,arguments):typeof g=="function"?p.bind(null,document).apply(null,arguments):(typeof f=="string"&&(f=document.querySelectorAll(f)),Array.prototype.map.call(f,function(y){return p(y,v,g,C,u)}))}function _(f,v,g,C){return function(u){u.delegateTarget=d(u.target,v),u.delegateTarget&&C.call(f,u)}}r.exports=m}),879:(function(r,l){l.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},l.nodeList=function(i){var d=Object.prototype.toString.call(i);return i!==void 0&&(d==="[object NodeList]"||d==="[object HTMLCollection]")&&"length"in i&&(i.length===0||l.node(i[0]))},l.string=function(i){return typeof i=="string"||i instanceof String},l.fn=function(i){var d=Object.prototype.toString.call(i);return d==="[object Function]"}}),370:(function(r,l,i){var d=i(879),p=i(438);function m(g,C,u){if(!g&&!C&&!u)throw new Error("Missing required arguments");if(!d.string(C))throw new TypeError("Second argument must be a String");if(!d.fn(u))throw new TypeError("Third argument must be a Function");if(d.node(g))return _(g,C,u);if(d.nodeList(g))return f(g,C,u);if(d.string(g))return v(g,C,u);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function _(g,C,u){return g.addEventListener(C,u),{destroy:function(){g.removeEventListener(C,u)}}}function f(g,C,u){return Array.prototype.forEach.call(g,function(y){y.addEventListener(C,u)}),{destroy:function(){Array.prototype.forEach.call(g,function(y){y.removeEventListener(C,u)})}}}function v(g,C,u){return p(document.body,g,C,u)}r.exports=m}),817:(function(r){function l(i){var d;if(i.nodeName==="SELECT")i.focus(),d=i.value;else if(i.nodeName==="INPUT"||i.nodeName==="TEXTAREA"){var p=i.hasAttribute("readonly");p||i.setAttribute("readonly",""),i.select(),i.setSelectionRange(0,i.value.length),p||i.removeAttribute("readonly"),d=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var m=window.getSelection(),_=document.createRange();_.selectNodeContents(i),m.removeAllRanges(),m.addRange(_),d=m.toString()}return d}r.exports=l}),279:(function(r){function l(){}l.prototype={on:function(i,d,p){var m=this.e||(this.e={});return(m[i]||(m[i]=[])).push({fn:d,ctx:p}),this},once:function(i,d,p){var m=this;function _(){m.off(i,_),d.apply(p,arguments)}return _._=d,this.on(i,_,p)},emit:function(i){var d=[].slice.call(arguments,1),p=((this.e||(this.e={}))[i]||[]).slice(),m=0,_=p.length;for(m;m<_;m++)p[m].fn.apply(p[m].ctx,d);return this},off:function(i,d){var p=this.e||(this.e={}),m=p[i],_=[];if(m&&d)for(var f=0,v=m.length;f<v;f++)m[f].fn!==d&&m[f].fn._!==d&&_.push(m[f]);return _.length?p[i]=_:delete p[i],this}},r.exports=l,r.exports.TinyEmitter=l})},a={};function s(r){if(a[r])return a[r].exports;var l=a[r]={exports:{}};return n[r](l,l.exports,s),l.exports}return(function(){s.n=function(r){var l=r&&r.__esModule?function(){return r.default}:function(){return r};return s.d(l,{a:l}),l}})(),(function(){s.d=function(r,l){for(var i in l)s.o(l,i)&&!s.o(r,i)&&Object.defineProperty(r,i,{enumerable:!0,get:l[i]})}})(),(function(){s.o=function(r,l){return Object.prototype.hasOwnProperty.call(r,l)}})(),s(686)})().default})})(se)),se.exports}var Kn=Yn();const Xn=qn(Kn),Jn=o=>({toClipboard(t,n){return new Promise((a,s)=>{const r=document.createElement("button"),l=new Xn(r,{text:()=>t,action:()=>"copy",container:n!==void 0?n:document.body});l.on("success",i=>{l.destroy(),a(i)}),l.on("error",i=>{l.destroy(),s(i)}),document.body.appendChild(r),r.click(),document.body.removeChild(r)})}}),Qn={key:0,class:"baklava-button"},pt=e.defineComponent({__name:"CopyToClipboard",props:{text:String},setup(o){const{toClipboard:t}=Jn(),n=o,a=e.toRef(n,"text"),s=e.ref(!1),r=async()=>{try{await t(a.value),s.value=!0,setTimeout(()=>s.value=!1,1500),console.log("Copied to clipboard")}catch(l){console.error(l)}};return(l,i)=>(e.openBlock(),e.createElementBlock("div",null,[s.value?(e.openBlock(),e.createElementBlock("button",Qn,[e.createVNode(e.unref(Ue))])):(e.openBlock(),e.createElementBlock("button",{key:1,onClick:r,class:"baklava-button"},[e.createVNode(e.unref(qe))]))]))}}),Zn={class:"code-editor"},eo={class:"code-buttons"},to=e.defineComponent({__name:"CodeEditor",props:e.mergeModels({locked:{type:Boolean},extensions:{}},{modelValue:{required:!0,type:String},modelModifiers:{}}),emits:e.mergeModels(["update:locked"],["update:modelValue"]),setup(o,{emit:t}){const n=e.useModel(o,"modelValue"),a=t,s=r=>a("update:locked",r);return(r,l)=>{const i=e.resolveComponent("codemirror");return e.openBlock(),e.createElementBlock("div",Zn,[e.createElementVNode("div",eo,[o.locked?(e.openBlock(),e.createElementBlock("button",{key:0,class:"baklava-button",title:"The code is locked.",onClick:l[0]||(l[0]=d=>s(!1))},[e.createVNode(e.unref(Ce))])):e.createCommentVNode("",!0),e.createVNode(pt,{text:o.modelValue},null,8,["text"])]),e.createVNode(i,{modelValue:n.value,"onUpdate:modelValue":l[1]||(l[1]=d=>n.value=d),extensions:o.extensions,class:"codemirror",style:{height:"100%"},onKeydown:l[2]||(l[2]=d=>s(!0))},null,8,["modelValue","extensions"])])}}}),no=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),a=s=>s.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe&&n.value.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(s,r)=>{r&&r.unsubscribe(),s&&s.subscribe()}),(s,r)=>(e.openBlock(),e.createBlock(e.unref(N.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(mt))]),node:e.withCtx(l=>[e.createVNode(e.unref(ht),e.mergeProps(l,{onUpdate:i=>a(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(ft),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:i})=>[e.renderSlot(s.$slots,"sidebarCodeEditor",{node:i})]),_:3},16)]),_:3},8,["viewModel"]))}}),oo={class:"code-graph-info"},so=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",oo,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),ao=["id","data-node-type"],ro={class:"__title-label",style:{"flex-grow":"1"}},io={key:0},lo={class:"__menu",style:{display:"flex"}},co={class:"__outputs"},uo={key:0},po=["id","title"],ho={class:"__inputs"},fo={key:0},mo=["id","title"],ht=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=N.Components.ContextMenu,a=N.Components.NodeInterface,s=o,r=e.computed(()=>s.node),l=t,{viewModel:i}=N.useViewModel(),{graph:d,switchGraph:p}=N.useGraph(),m=e.ref(null),_=e.ref(!1),f=e.ref(""),v=e.ref(null),g=e.ref(!1);let C=0,u=0;const y=e.ref(!1),O=e.computed(()=>{const x=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return s.node.type.startsWith(V.GRAPH_NODE_TYPE_PREFIX)&&x.push({value:"editSubgraph",label:"Edit Subgraph"}),x}),T=e.computed(()=>({"--selected":s.selected,"--dragging":s.dragging,"--two-column":!!s.node.twoColumn,"--hidden":r.value.state?.hidden})),M=e.computed(()=>({"--reverse-y":s.node.reverseY??i.value.settings.nodes.reverseY})),H=e.computed(()=>({top:`${s.node.position?.y??0}px`,left:`${s.node.position?.x??0}px`,"--width":`${s.node.width??i.value.settings.nodes.defaultWidth}px`})),U=e.computed(()=>Object.values(s.node.inputs).filter(x=>!x.hidden)),J=e.computed(()=>Object.values(s.node.outputs).filter(x=>!x.hidden)),z=()=>{l("select")},w=x=>{s.selected||z(),l("start-drag",x)},P=()=>{y.value=!0},R=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId="",x.visible=!1},ae=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId=s.node.id,x.visible=!0},Q=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId=s.node.id},Me=async x=>{switch(x){case"edit":ae();break;case"delete":d.value.removeNode(s.node);break;case"rename":f.value=s.node.title,_.value=!0,await e.nextTick(),v.value?.focus();break;case"editSubgraph":p(s.node.template);break}},re=()=>{r.value.title=f.value,_.value=!1},ie=()=>{m.value&&i.value.hooks.renderNode.execute({node:s.node,el:m.value})},Ve=x=>{g.value=!0,C=s.node.width,u=x.clientX,x.preventDefault()},q=x=>{r.value.state&&(r.value.state.integrated=x,l("update"))},Y=x=>{if(!g.value)return;const b=x.clientX-u,h=C+b/d.value.scaling,k=i.value.settings.nodes.minWidth,E=i.value.settings.nodes.maxWidth;r.value.width=Math.max(k,Math.min(E,h))},le=()=>{g.value=!1};return e.onMounted(()=>{ie(),window.addEventListener("mousemove",Y),window.addEventListener("mouseup",le)}),e.onUpdated(ie),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",Y),window.removeEventListener("mouseup",le)}),(x,b)=>(e.openBlock(),e.createElementBlock("div",{id:r.value.id,ref_key:"el",ref:m,class:e.normalizeClass([T.value,"baklava-node"]),"data-node-type":r.value.type,style:e.normalizeStyle(H.value),onPointerdown:z},[e.unref(i).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Ve},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(w,["self","stop"]),onContextmenu:e.withModifiers(P,["prevent"])},[r.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(Be),{key:0,node:r.value,intf:r.value.inputs._code,title:r.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),_.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:v,"onUpdate:modelValue":b[4]||(b[4]=h=>f.value=h),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:re,onKeydown:e.withKeys(re,["enter"])},null,544)),[[e.vModelText,f.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",ro,[r.value.idx>-1?(e.openBlock(),e.createElementBlock("span",io,e.toDisplayString(r.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(r.value.title)+" "+e.toDisplayString(r.value.graph.shortId)+" "+e.toDisplayString(r.value.shortId),1)]),e.createElementVNode("div",lo,[r.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[r.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(Ce),{key:0,class:"--clickable mx-1",onClick:b[0]||(b[0]=h=>r.value.lockCode=!1)})):e.createCommentVNode("",!0),r.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(Fe),{key:1,class:"--clickable mx-1",onClick:b[1]||(b[1]=h=>q(!1))})):(e.openBlock(),e.createBlock(e.unref(ot),{key:2,class:"--clickable mx-1",onClick:b[2]||(b[2]=h=>q(!0))})),!e.unref(i).displayedGraph.sidebar.visible&&e.unref(i).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(Qe),{key:3,class:"--clickable mx-1",onClick:ae})):e.unref(i).displayedGraph.sidebar.visible&&e.unref(i).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(Xe),{key:4,class:"--clickable mx-1",onClick:Q})):(e.openBlock(),e.createBlock(e.unref(Je),{key:5,class:"--clickable mx-1",onClick:R}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(We),{class:"--clickable mx-1",onClick:P}),e.createVNode(e.unref(n),{modelValue:y.value,"onUpdate:modelValue":b[3]||(b[3]=h=>y.value=h),x:0,y:0,items:O.value,onClick:Me},null,8,["modelValue","items"])])],64)),r.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(Be),{key:3,node:r.value,intf:r.value.outputs._code,class:"--output",title:r.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",M.value]),onKeydown:b[5]||(b[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:b[6]||(b[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",co,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(J.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",uo,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --output --connected"},[...b[7]||(b[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,po)):e.createCommentVNode("",!0)])):e.renderSlot(x.$slots,"nodeInterface",{key:1,type:"output",node:r.value,intf:h},()=>[e.createVNode(e.unref(a),{node:r.value,intf:h,title:h.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",ho,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(U.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",fo,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --input --connected"},[...b[8]||(b[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,mo)):e.createCommentVNode("",!0)])):e.renderSlot(x.$slots,"nodeInterface",{key:1,node:r.value,intf:h,type:"input"},()=>[e.createVNode(e.unref(a),{node:r.value,intf:h,title:h.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,ao))}}),go=["id"],bo={class:"align-middle"},Be=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=N.useViewModel(),{hoveredOver:a,temporaryConnection:s}=N.useTemporaryConnection(),r=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),i=e.computed(()=>({"--connected":l.value})),d=()=>{a(t.intf)},p=()=>{a(void 0)},m=()=>{r.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:r.value})};return e.onMounted(m),e.onUpdated(m),(_,f)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:r,class:e.normalizeClass(["baklava-node-interface",i.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(s)?.from===o.intf}]),onPointerover:d,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",bo,[e.renderSlot(_.$slots,"default")])],10,go))}}),yo=["title"],ko={key:0,class:"__label"},Te=e.defineComponent({__name:"SidebarCheckbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(a,s)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:s[0]||(s[0]=r=>n("update:modelValue",!o.modelValue))},[s[1]||(s[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",ko,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,yo))}}),_o={class:"__header"},Co={class:"__node-name"},No={class:"__interfaces"},wo={class:"__inputs"},Eo={style:{display:"flex"}},Io={class:"__outputs"},vo={key:0,class:"__interface"},Bo={style:{display:"flex"}},ft=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=N.useViewModel(),{graph:n}=N.useGraph(),a=e.ref(null),s=e.toRef(t.value.settings.sidebar,"width"),r=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,i=0;const d=e.computed(()=>{const y=n.value.sidebar.nodeId;return n.value.nodes.find(O=>O.id===y)}),p=e.computed(()=>d.value),m=e.computed(()=>({width:`${s.value}px`})),_=e.computed(()=>p.value?Object.values(p.value.inputs).filter(y=>y.displayInSidebar&&y.component):[]),f=e.computed(()=>p.value?Object.values(p.value.outputs).filter(y=>y.displayInSidebar&&y.component):[]),v=()=>{n.value.sidebar.visible=!1},g=()=>{d.value?.events.update.emit(null)},C=y=>{l=s.value,i=y.clientX,window.addEventListener("mousemove",u),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",u)},{once:!0})},u=y=>{const O=a.value?.parentElement?.getBoundingClientRect().width??500,T=y.clientX-i;let M=l-T;M<300?M=300:M>.9*O&&(M=.9*O),s.value=M};return(y,O)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(m.value),ref_key:"el",ref:a},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:C},null,32)):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",_o,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:v},"×"),e.createElementVNode("div",Co,[e.createElementVNode("b",null,e.toDisplayString(d.value.title),1)])]),e.createElementVNode("div",No,[e.createElementVNode("div",wo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.value,T=>(e.openBlock(),e.createElementBlock("div",{key:T.id,class:"__interface"},[e.createElementVNode("div",Eo,[e.createVNode(Te,{modelValue:T.hidden,"onUpdate:modelValue":[M=>T.hidden=M,O[0]||(O[0]=()=>d.value?.events.update.emit(null))],disabled:!T.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(T.component),{modelValue:T.value,"onUpdate:modelValue":M=>T.value=M,node:d.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",Io,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",vo,[O[3]||(O[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":O[1]||(O[1]=T=>p.value.state.variableName=T),type:"text",class:"baklava-input",title:"Variable name",onBlur:g,onKeydown:e.withKeys(g,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,T=>(e.openBlock(),e.createElementBlock("div",{key:T.id,class:"__interface"},[e.createElementVNode("div",Bo,[e.createVNode(Te,{modelValue:T.hidden,"onUpdate:modelValue":[M=>T.hidden=M,O[2]||(O[2]=()=>d.value?.events.update.emit(null))],disabled:!T.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(T.component),{modelValue:T.value,"onUpdate:modelValue":M=>T.value=M,node:d.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(y.$slots,"codeEditor",{node:d.value})],64)):e.createCommentVNode("",!0)],6))}}),To={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},xo={key:0,style:{display:"flex","justify-content":"space-between"}},Oo=["onClick"],So={key:0,style:{margin:"auto 0","font-size":"12px"}},mt=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=N.Components.PaletteEntry,{viewModel:n}=N.useViewModel(),{x:a,y:s}=_t.usePointer(),{transform:r}=N.useTransform(),l=N.useNodeCategories(n),i=e.inject("editorEl"),d=e.ref(""),p=e.ref(null),m=()=>d.value?l.value.filter(g=>g.name.toLowerCase().includes(d.value.toLowerCase())||Object.values(g.nodeTypes).some(C=>C.title.toLowerCase().includes(d.value.toLowerCase()))):l.value,_=g=>d.value?Hn(g,C=>{const u=C[1];return u.category.includes(d.value.toLowerCase())||u.title?.toLowerCase().includes(d.value.toLowerCase())}):g,f=e.computed(()=>{if(!p.value||!i?.value)return{};const{left:g,top:C}=i.value.getBoundingClientRect();return{top:`${s.value-C}px`,left:`${a.value-g}px`}}),v=(g,C)=>{p.value={type:g,nodeInformation:C};const u=()=>{const y=e.reactive(new C.type);n.value.displayedGraph.addNode(y);const O=i.value.getBoundingClientRect(),[T,M]=r(a.value-O.left,s.value-O.top);y.position.x=T,y.position.y=M,p.value=null,document.removeEventListener("pointerup",u)};document.addEventListener("pointerup",u)};return(g,C)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:C[1]||(C[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",To,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[0]||(C[0]=u=>d.value=u),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:m},null,544),[[e.vModelText,d.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(m(),u=>(e.openBlock(),e.createElementBlock("section",{key:u.name},[u.name!=="default"?(e.openBlock(),e.createElementBlock("h3",xo,[e.createElementVNode("div",{onClick:y=>d.value=u.name,style:{cursor:"pointer"}},e.toDisplayString(u.name),9,Oo),Object.keys(_(u.nodeTypes)).length<Object.values(u.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",So," ( "+e.toDisplayString(Object.keys(_(u.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(u.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(u.nodeTypes),(y,O)=>(e.openBlock(),e.createBlock(e.unref(t),{key:O,type:O,title:y.title,onPointerdown:T=>v(O,y)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(f.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Mo={},Vo={class:"prependIcon"},$o={class:"appendIcon"};function Po(o,t){const n=e.resolveComponent("router-link");return e.openBlock(),e.createBlock(n,{class:"navItem"},{default:e.withCtx(()=>[e.createElementVNode("span",Vo,[e.renderSlot(o.$slots,"prependIcon")]),e.renderSlot(o.$slots,"default"),e.createElementVNode("span",$o,[e.renderSlot(o.$slots,"appendIcon")])]),_:3})}const xe=$(Mo,[["render",Po]]),jo={class:"navbar"},Ro=["onClick"],Go=e.defineComponent({__name:"NavBar",props:{viewModel:{},editorStates:{},routes:{}},emits:["click:remove"],setup(o,{emit:t}){const n=t,a=s=>{n("click:remove",s)};return(s,r)=>(e.openBlock(),e.createElementBlock("nav",jo,[e.renderSlot(s.$slots,"prepend"),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.editorStates,l=>(e.openBlock(),e.createBlock(xe,{key:l.graph.id,class:e.normalizeClass({active:l.graph.id===o.viewModel.displayedGraph.id}),to:{name:o.routes?.edit??"edit",params:{editorId:l.graph.id}}},{appendIcon:e.withCtx(()=>[e.createElementVNode("button",{class:"remove",onClick:e.withModifiers(i=>a(l.graph.id),["prevent"])},[e.createVNode(e.unref(at))],8,Ro)]),default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(l.graph.id.slice(0,6))+" ",1)]),_:2},1032,["class","to"]))),128)),e.renderSlot(s.$slots,"append",{},()=>[e.createVNode(xe,{to:{name:o.routes?.new??"new"},class:"navItem"},{default:e.withCtx(()=>[e.createVNode(e.unref(et),{class:"plus"})]),_:1},8,["to"])])]))}});class Oe extends ke{_title="Subgraph Input";inputs={_code:new j("","").use(S.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new j("","").use(S.setType,G).setHidden(!0),placeholder:new V.NodeInterface("Connection",void 0)}}class Se extends _e{_title="Subgraph Output";inputs={_code:new j("","").use(S.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Output").setPort(!1),placeholder:new V.NodeInterface("Connection",void 0)};outputs={_code:new j("","").use(S.setType,G).setHidden(!0),output:new V.NodeInterface("Output",void 0).setHidden(!0)}}const gt="CREATE_SUBGRAPH",bt=[V.GRAPH_INPUT_NODE_TYPE,V.GRAPH_OUTPUT_NODE_TYPE];function yt(o,t,n){const a=()=>o.value.selectedNodes.filter(r=>!bt.includes(r.type)).length>0,s=()=>{const{viewModel:r}=N.useViewModel(),l=o.value,i=o.value.editor;if(l.selectedNodes.length===0)return;const d=l.selectedNodes.filter(w=>!bt.includes(w.type)),p=d.flatMap(w=>Object.values(w.inputs)),m=d.flatMap(w=>Object.values(w.outputs)),_=l.connections.filter(w=>!m.includes(w.from)&&p.includes(w.to)),f=l.connections.filter(w=>m.includes(w.from)&&!p.includes(w.to)),v=l.connections.filter(w=>m.includes(w.from)&&p.includes(w.to)),g=d.map(w=>w.save()),C=v.map(w=>({id:w.id,from:w.from.id,to:w.to.id})),u=new Map,{xLeft:y,xRight:O,yTop:T}=Lo(d);for(const[w,P]of _.entries()){const R=new Oe;R.inputs.name.value=P.to.name,g.push({...R.save(),position:{x:O-r.value.settings.nodes.defaultWidth-100,y:T+w*200}}),C.push({id:F.v4(),from:R.outputs.placeholder.id,to:P.to.id}),u.set(P.to.id,R.graphInterfaceId)}for(const[w,P]of f.entries()){const R=new Se;R.inputs.name.value=P.from.name,g.push({...R.save(),position:{x:y+100,y:T+w*200}}),C.push({id:F.v4(),from:P.from.id,to:R.inputs.placeholder.id}),u.set(P.from.id,R.graphInterfaceId)}const M=e.reactive(new X({connections:C,nodes:g,inputs:[],outputs:[]},i));i.addGraphTemplate(M);const H=i.nodeTypes.get(V.getGraphNodeTypeString(M));if(!H)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const U=e.reactive(new H.type);l.addNode(U);const J=Math.round(d.map(w=>w.position.x).reduce((w,P)=>w+P,0)/d.length),z=Math.round(d.map(w=>w.position.y).reduce((w,P)=>w+P,0)/d.length);U.position.x=J,U.position.y=z,_.forEach(w=>{l.removeConnection(w),l.addConnection(w.from,U.inputs[u.get(w.to.id)])}),f.forEach(w=>{l.removeConnection(w),l.addConnection(U.outputs[u.get(w.from.id)],w.to)}),d.forEach(w=>l.removeNode(w)),l.activeTransactions--,t.canExecuteCommand(N.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(N.Commands.SAVE_SUBGRAPH_COMMAND),n(M),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(gt,{canExecute:a,execute:s})}function Lo(o){const t=o.reduce((s,r)=>{const l=r.position.x;return l<s?l:s},1/0),n=o.reduce((s,r)=>{const l=r.position.y;return l<s?l:s},1/0);return{xLeft:o.reduce((s,r)=>{const l=r.position.x+r.width;return l>s?l:s},-1/0),xRight:t,yTop:n}}class Ao extends V.Editor{code;graph;constructor(t){super(),this.code=t,this.graph=new K(this)}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=ze(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(a=>{const s=new X(a,this);this.addGraphTemplate(s)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(a=>console.warn(a)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}}function Do(o){const t=e.ref(o?.code??new oe),n=e.ref(o?.existingEditor??new Ao(t.value)),a=Symbol("ViewModelToken"),s=e.ref(null),r=e.shallowReadonly(s),{switchGraph:l}=dt(n,s),i=e.computed(()=>r.value&&r.value!==n.value.graph),d=e.reactive(N.DEFAULT_SETTINGS());d.nodes.defaultWidth=400;const p=N.useCommandHandler(),m=N.useHistory(r,p),_=N.useClipboard(r,n,p),f={renderNode:new $e.SequentialHook(null),renderInterface:new $e.SequentialHook(null)},v=e.reactive({clipboard:_,code:t,commandHandler:p,displayedGraph:r,editor:n,history:m,hooks:f,isSubgraph:i,settings:d,switchGraph:l});return t.value.registerViewModel(v),ct(v),N.registerDeleteNodesCommand(r,p),yt(r,p,l),N.registerSaveSubgraphCommand(r,p),N.registerSwitchToMainGraphCommand(r,p,l),N.registerSidebarCommands(r,p),N.registerZoomToFitCommands(r,p,d),rt(r,p,d),it(d),e.watch(n,(g,C)=>{C&&(C.events.registerGraph.unsubscribe(a),C.graphEvents.beforeAddNode.unsubscribe(a),g.nodeHooks.beforeLoad.unsubscribe(a),g.nodeHooks.afterSave.unsubscribe(a),g.graphTemplateHooks.beforeLoad.unsubscribe(a),g.graphTemplateHooks.afterSave.unsubscribe(a),g.graph.hooks.load.unsubscribe(a),g.graph.hooks.save.unsubscribe(a)),g&&(g.nodeHooks.beforeLoad.subscribe(a,(u,y)=>(y.position=u.position??{x:0,y:0},y.width=u.width??d.nodes.defaultWidth,y.twoColumn=u.twoColumn??!1,u)),g.nodeHooks.afterSave.subscribe(a,(u,y)=>(u.position=y.position,u.width=y.width,u.twoColumn=y.twoColumn,u)),g.graphTemplateHooks.beforeLoad.subscribe(a,(u,y)=>(y.panning=u.panning,y.scaling=u.scaling,u)),g.graphTemplateHooks.afterSave.subscribe(a,(u,y)=>(u.panning=y.panning,u.scaling=y.scaling,u)),g.graph.hooks.load.subscribe(a,(u,y)=>(y.panning=u.panning,y.scaling=u.scaling,u)),g.graph.hooks.save.subscribe(a,(u,y)=>(u.panning=y.panning,u.scaling=y.scaling,u)),g.graphEvents.beforeAddNode.subscribe(a,u=>N.setViewNodeProperties(u,{defaultWidth:d.nodes.defaultWidth})),n.value.registerNodeType(Oe,{category:"Subgraphs"}),n.value.registerNodeType(Se,{category:"Subgraphs"}),l(g.graph))},{immediate:!0}),v}const zo=Object.freeze(Object.defineProperty({__proto__:null,default:`{{ #modules }}
3
+ This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}}const zt={},Ht={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-check"};function Ut(o,t){return e.openBlock(),e.createElementBlock("svg",Ht,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M5 12l5 5l10 -10"},null,-1)])])}const ze=$(zt,[["render",Ut]]),Ft={},qt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-code-variable"};function Wt(o,t){return e.openBlock(),e.createElementBlock("svg",qt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M4 8m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"},null,-1)])])}const He=$(Ft,[["render",Wt]]),Yt={},Kt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-copy"};function Xt(o,t){return e.openBlock(),e.createElementBlock("svg",Kt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z"},null,-1),e.createElementVNode("path",{d:"M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1"},null,-1)])])}const Ue=$(Yt,[["render",Xt]]),Jt={},Qt={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-dots-vertical"};function Zt(o,t){return e.openBlock(),e.createElementBlock("svg",Qt,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1),e.createElementVNode("path",{d:"M12 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"},null,-1)])])}const Fe=$(Jt,[["render",Zt]]),en={},tn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-collapse"};function nn(o,t){return e.openBlock(),e.createElementBlock("svg",tn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-2.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const qe=$(en,[["render",nn]]),on={},sn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-left-expand"};function an(o,t){return e.openBlock(),e.createElementBlock("svg",sn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm0 2h-9v14h9a1 1 0 0 0 .993 -.883l.007 -.117v-12a1 1 0 0 0 -.883 -.993l-.117 -.007zm-4.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const We=$(on,[["render",an]]),rn={},ln={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right"};function cn(o,t){return e.openBlock(),e.createElementBlock("svg",ln,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M6 21a3 3 0 0 1 -3 -3v-12a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3zm8 -16h-8a1 1 0 0 0 -1 1v12a1 1 0 0 0 1 1h8z"},null,-1)])])}const Ye=$(rn,[["render",cn]]),dn={},un={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-collapse"};function pn(o,t){return e.openBlock(),e.createElementBlock("svg",un,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-5.387 4.21l.094 .083l2 2a1 1 0 0 1 .083 1.32l-.083 .094l-2 2a1 1 0 0 1 -1.497 -1.32l.083 -.094l1.292 -1.293l-1.292 -1.293a1 1 0 0 1 -.083 -1.32l.083 -.094a1 1 0 0 1 1.32 -.083z"},null,-1)])])}const Ke=$(dn,[["render",pn]]),hn={},fn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",class:"baklava-icon icon icon-tabler icons-tabler-filled icon-tabler-layout-sidebar-right-expand"};function mn(o,t){return e.openBlock(),e.createElementBlock("svg",fn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 3a3 3 0 0 1 2.995 2.824l.005 .176v12a3 3 0 0 1 -2.824 2.995l-.176 .005h-12a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-12a3 3 0 0 1 2.824 -2.995l.176 -.005h12zm-3 2h-9a1 1 0 0 0 -.993 .883l-.007 .117v12a1 1 0 0 0 .883 .993l.117 .007h9v-14zm-3.293 4.293a1 1 0 0 1 .083 1.32l-.083 .094l-1.292 1.293l1.292 1.293a1 1 0 0 1 .083 1.32l-.083 .094a1 1 0 0 1 -1.32 .083l-.094 -.083l-2 -2a1 1 0 0 1 -.083 -1.32l.083 -.094l2 -2a1 1 0 0 1 1.414 0z"},null,-1)])])}const Xe=$(hn,[["render",mn]]),gn={},bn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-lock-code"};function yn(o,t){return e.openBlock(),e.createElementBlock("svg",bn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11.5 21h-4.5a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2"></path><path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"></path><path d="M8 11v-4a4 4 0 1 1 8 0v4"></path><path d="M20 21l2 -2l-2 -2"></path><path d="M17 17l-2 2l2 2"></path>',6)])])}const be=$(gn,[["render",yn]]),kn={},_n={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-player-play"};function Cn(o,t){return e.openBlock(),e.createElementBlock("svg",_n,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M7 4v16l13 -8z"},null,-1)])])}const Je=$(kn,[["render",Cn]]),Nn={},wn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-plus"};function En(o,t){return e.openBlock(),e.createElementBlock("svg",wn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M12 5l0 14"},null,-1),e.createElementVNode("path",{d:"M5 12l14 0"},null,-1)])])}const Qe=$(Nn,[["render",En]]),In={},vn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema"};function Bn(o,t){return e.openBlock(),e.createElementBlock("svg",vn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 2h5v4h-5z"></path><path d="M15 10h5v4h-5z"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h5"></path><path d="M7.5 6v4"></path><path d="M7.5 14v4"></path>',8)])])}const Ze=$(In,[["render",Bn]]),Tn={},xn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-schema-off"};function On(o,t){return e.openBlock(),e.createElementBlock("svg",xn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 2h4v4m-4 0h-1v-1"></path><path d="M15 11v-1h5v4h-2"></path><path d="M5 18h5v4h-5z"></path><path d="M5 10h5v4h-5z"></path><path d="M10 12h2"></path><path d="M7.5 7.5v2.5"></path><path d="M7.5 14v4"></path><path d="M3 3l18 18"></path>',9)])])}const et=$(Tn,[["render",On]]),Sn={},Mn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-transition-bottom"};function Vn(o,t){return e.openBlock(),e.createElementBlock("svg",Mn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M21 18a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3"></path><path d="M3 3m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v0a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z"></path><path d="M12 9v8"></path><path d="M9 14l3 3l3 -3"></path>',5)])])}const tt=$(Sn,[["render",Vn]]),$n={},Pn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-trash-off"};function jn(o,t){return e.openBlock(),e.createElementBlock("svg",Pn,[...t[0]||(t[0]=[e.createStaticVNode('<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M4 7h3m4 0h9"></path><path d="M10 11l0 6"></path><path d="M14 14l0 3"></path><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l.077 -.923"></path><path d="M18.384 14.373l.616 -7.373"></path><path d="M9 5v-1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"></path>',8)])])}const nt=$($n,[["render",jn]]),Rn={},Gn={xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"baklava-icon icon icon-tabler icons-tabler-outline icon-tabler-x"};function Ln(o,t){return e.openBlock(),e.createElementBlock("svg",Gn,[...t[0]||(t[0]=[e.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},null,-1),e.createElementVNode("path",{d:"M18 6l-12 12"},null,-1),e.createElementVNode("path",{d:"M6 6l12 12"},null,-1)])])}const ot=$(Rn,[["render",Ln]]),ye="CLEAR_ALL",ke="RUN_ENGINE",_e="TOGGLE_MINIMAP",Ce="TOGGLE_PALETTE",st=(o,t,n)=>{const a=n.zoomToFit.paddingLeft;t.registerCommand(Ce,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?a:50},canExecute:()=>!0}),t.registerCommand(ye,{execute:()=>o.value.clear(),canExecute:()=>o.value.nodes.length>0}),t.registerCommand(_e,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},at=o=>{const t={command:ke,title:"Run",icon:e.computed(()=>Je)},n={command:Ce,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?qe:We)},a={command:ye,title:"Clear all",icon:e.computed(()=>nt)},s={command:_e,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?et:Ze)};o.toolbar.commands=[n,t,...N.DEFAULT_TOOLBAR_COMMANDS,a,s]},rt=(o,t)=>{t.registerCommand(ke,{execute:()=>o.runOnce(null),canExecute:()=>!0})};function it(o){const t=Symbol("CodeEngineToken");o.engine=new De(o.editor),rt(o.engine,o.commandHandler),o.loadEditor=n=>{o.engine?.pause(),o.displayedGraph.clear(),o.editor.load(n),o.commandHandler.executeCommand(N.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(N.Commands.CLEAR_HISTORY_COMMAND),o.engine?.resume(),o.engine?.runOnce(null)},o.newGraph=()=>{o.engine?.pause(),o.displayedGraph.clear(),o.commandHandler.executeCommand(N.Commands.CLEAR_CLIPBOARD_COMMAND),o.commandHandler.executeCommand(N.Commands.CLEAR_HISTORY_COMMAND),o.displayedGraph.id=F.v4(),o.engine?.resume(),o.engine?.runOnce(null)},o.subscribe=()=>{o.displayedGraph.events.addConnection.subscribe(t,n=>{const a=o.displayedGraph.findNodeById(n.to.nodeId);a&&a.isCodeNode&&a.onConnected();const s=o.displayedGraph.findNodeById(n.from.nodeId);s&&s.isCodeNode&&s.onConnected()}),o.displayedGraph.events.removeConnection.subscribe(t,n=>{const a=o.displayedGraph.findNodeById(n.to.nodeId);a&&a.isCodeNode&&a.onUnconnected();const s=o.displayedGraph.findNodeById(n.from.nodeId);s&&s.isCodeNode&&s.onUnconnected()}),o.engine?.events.beforeRun.subscribe(t,()=>{o.engine?.pause(),o.displayedGraph.sortNodes(),o.engine?.resume()}),o.engine?.events.afterRun.subscribe(t,n=>{o.engine?.pause(),D.applyResult(n,o.editor),o.code.state.lockCode||o.code.renderCode({nodes:o.editor.graph.scriptedCodeNodes,modules:o.editor.code.modules}),o.engine?.resume()})},o.unsubscribe=()=>{o.displayedGraph.events.addConnection.unsubscribe(t),o.displayedGraph.events.removeConnection.unsubscribe(t),o.engine?.events.beforeRun.unsubscribe(t),o.engine?.events.afterRun.unsubscribe(t)}}class K extends V.Graph{code=null;editor;_state=e.reactive({codeTemplate:"{{ #nodes }}{{ script }}{{ /nodes }}",lockCode:!1});constructor(t,n){super(t,n),this.editor=t,this.template=n,t.code&&(this.code=t.code)}get codeNodes(){return Ne(this)}get connections(){return super.connections}set connections(t){this._connections=t}get nodeIds(){return this.nodes.map(t=>t.id)}get nodes(){return super.nodes}set nodes(t){this._nodes=t}get scriptedCodeNodes(){return this.nodes.filter(t=>!t.state?.integrated)}get shortId(){return this.id.slice(0,6)}get state(){return this._state}get visibleNodes(){return this.nodes.filter(t=>!t.state?.hidden)}addNode(t,n){return t.state&&n&&(t.state.props=n),super.addNode(t)}addNodeAtCoordinates=(t,n={x:0,y:0},a)=>(this.addNode(t,a),t.position&&(t.position=n),t);addConnection(t,n){t?.name!=="_code"&&(t.hidden=!1),n?.name!=="_code"&&(n.hidden=!1),super.addConnection(t,n)}clear(){this.selectedNodes=[],this._nodes=[],this._connections=[]}findNodeByType(t){return this.nodes.find(n=>n.type===t)}getNodesBySameType(t){return this.nodes.filter(n=>n.type===t)}getNodesBySameVariableNames(t){return this.nodes.filter(n=>n.state?.variableName===t)}hasConnection(t,n){return this.connections.some(a=>a.from.id===t.id&&a.to.id===n.id)}renderCode(t){return A.render(this.state?.codeTemplate||"",t)}sortNodes(){if(!(this.nodes.length===0||this.connections.length===0))try{let t=this.nodeIds;const n=this.connections.filter(r=>t.includes(r.to.nodeId)&&t.includes(r.from.nodeId)).map(r=>[r.to.nodeId,r.from.nodeId]);t.reverse(),t=kt.array(t,n),t.reverse();const a=this.nodes.map(r=>r.id).filter(r=>!t.includes(r));t=[...t,...a];const s=t.map(r=>this.findNodeById(r));s&&(this.nodes=s)}catch{console.warn("Failed to sort nodes.")}}}const Ne=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...Ne(n.subgraph)):n.hasOwnProperty("isCodeNode")&&t.push(n))}),t},An=(o=0,t=100)=>({x:o*420,y:t}),Dn=o=>{const t={...o.position};return t.x-=440,t.y+=50,t},we="__baklava_SubgraphInputNode",Ee="__baklava_SubgraphOutputNode";class lt extends Z{graphInterfaceId;constructor(){super(),this.graphInterfaceId=F.v4()}onPlaced(){super.onPlaced(),this.initializeIo()}load(t){super.load(t),this.graphInterfaceId=t.graphInterfaceId}save(){return{...super.save(),graphInterfaceId:this.graphInterfaceId}}update(){}}class Ie extends lt{static isGraphInputNode(t){return t.type===we}type=we;inputs={name:new V.NodeInterface("Name","Input")};outputs={placeholder:new V.NodeInterface("Value",void 0)}}class ve extends lt{static isGraphOutputNode(t){return t.type===Ee}type=Ee;inputs={name:new V.NodeInterface("Name","Output"),placeholder:new V.NodeInterface("Value",void 0)};outputs={output:new V.NodeInterface("Output",void 0).setHidden(!0)};calculate=({placeholder:t})=>({output:t})}const zn=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function ct(o){return class extends de{type=V.getGraphNodeTypeString(o);get title(){return this._title}set title(n){this.template.name=n}inputs={};outputs={};template=o;subgraph;update(){}onConnected(){}onUnconnected(){}calculate=async(n,a)=>{if(!this.subgraph)throw new Error(`GraphNode ${this.id}: calculate called without subgraph being initialized`);if(!a.engine||typeof a.engine!="object")throw new Error(`GraphNode ${this.id}: calculate called but no engine provided in context`);const s=a.engine.getInputValues(this.subgraph);for(const i of this.subgraph.inputs)s.set(i.nodeInterfaceId,n[i.id]);const r=await a.engine.runGraph(this.subgraph,s,a.globalValues);a.engine.pause(),D.applyResult(r,a.engine.editor),a.engine.resume();const l={};for(const i of this.subgraph.outputs)l[i.id]=r.get(i.nodeId)?.get("output");return l._calculationResults=r,this.lockCode||(l._code=this.renderCode({inputs:n,...a.globalValues})),this.updateOutputValues(l),l};load(n){if(!this.subgraph)throw new Error("Cannot load a graph node without a graph");if(!this.template)throw new Error("Unable to load graph node without graph template");this.subgraph.load(n.graphState),super.load(n)}save(){if(!this.subgraph)throw new Error("Cannot save a graph node without a graph");return{...super.save(),graphState:this.subgraph.save()}}onPlaced(){this.template.events.updated.subscribe(this,()=>this.initialize()),this.template.events.nameChanged.subscribe(this,n=>{this._title=n}),this.initialize()}onDestroy(){this.template.events.updated.unsubscribe(this),this.template.events.nameChanged.unsubscribe(this),this.subgraph?.destroy()}initialize(){this.subgraph&&this.subgraph.destroy(),this.subgraph=this.template.createGraph(),this._title=this.template.name,this.updateInterfaces(),this.state.codeTemplate=`{{ #nodes }}{{ script }}
4
+ {{ /nodes }}`,this.events.update.emit(null)}renderCode(n){return this.subgraph?this.subgraph.renderCode({nodes:this.subgraph.scriptedCodeNodes}):A.render(this.state.codeTemplate,n)}updateInterfaces(){if(!this.subgraph)throw new Error("Trying to update interfaces without graph instance");for(const n of this.subgraph.inputs)n.id in this.inputs?this.inputs[n.id].name=n.name:this.addInput(n.id,this.createProxyInterface(n,!0));for(const n of Object.keys(this.inputs))this.subgraph.inputs.some(a=>a.id===n)||this.removeInput(n);for(const n of this.subgraph.outputs)n.id in this.outputs?this.outputs[n.id].name=n.name:this.addOutput(n.id,this.createProxyInterface(n,!1));for(const n of Object.keys(this.outputs))this.subgraph.outputs.some(a=>a.id===n)||this.removeOutput(n);this.addInput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("",[]).use(S.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new V.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,a){const s=new j(n.name,void 0);return new Proxy(s,{get:(r,l)=>{if(zn.includes(l)||l in r||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(r,l);let i;a?i=this.subgraph?.nodes.find(_=>Ie.isGraphInputNode(_)&&_.graphInterfaceId===n.id)?.outputs.placeholder.id:i=this.subgraph?.nodes.find(_=>ve.isGraphOutputNode(_)&&_.graphInterfaceId===n.id)?.inputs.placeholder.id;const d=this.subgraph?.connections.find(m=>i===(a?m.from:m.to)?.id),p=a?d?.to:d?.from;if(p)return Reflect.get(p,l)}})}}}function Hn(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function Un(o,t){return Object.fromEntries(Object.entries(o).map(([n,a])=>[n,t(a)]))}class X extends V.GraphTemplate{static fromGraph(t,n){return new X(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,a=f=>{const v=F.v4();return n.set(f,v),v},s=f=>{const v=n.get(f);if(!v)throw new Error(`Unable to create graph from template: Could not map old id ${f} to new id`);return v},r=f=>Un(f,v=>({id:a(v.id),templateId:v.id,value:v.value})),l=this.nodes.map(f=>({...f,id:a(f.id),inputs:r(f.inputs),outputs:r(f.outputs)})),i=this.connections.map(f=>({id:a(f.id),from:s(f.from),to:s(f.to)})),d=this.inputs.map(f=>({id:f.id,name:f.name,nodeId:s(f.nodeId),nodeInterfaceId:s(f.nodeInterfaceId)})),p=this.outputs.map(f=>({id:f.id,name:f.name,nodeId:s(f.nodeId),nodeInterfaceId:s(f.nodeInterfaceId)})),m={id:F.v4(),nodes:l,connections:i,inputs:d,outputs:p};return t||(t=new K(this.editor)),t.load(m).forEach(f=>console.warn(f)),t.template=this,t}}const Fn=o=>!(o instanceof K);function dt(o,t){return{switchGraph:a=>{let s;if(Fn(a))s=new K(o.value),a.createGraph(s);else{if(a!==o.value.graph)throw new Error("Can only switch using 'Graph' instance when it is the root graph. Otherwise a 'GraphTemplate' must be used.");s=a}t.value&&t.value!==o.value.graph&&t.value.destroy(),s.panning=s.panning??a.panning??{x:0,y:0},s.scaling=s.scaling??a.scaling??1,s.selectedNodes=s.selectedNodes??[],s.sidebar=s.sidebar??{visible:!1,nodeId:"",optionName:""},t.value=s,s.code?.engine?.runOnce(null)}}}function qn(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var se={exports:{}};var Wn=se.exports,ut;function Yn(){return ut||(ut=1,(function(o,t){(function(a,s){o.exports=s()})(Wn,function(){return(function(){var n={686:(function(r,l,i){i.d(l,{default:function(){return x}});var d=i(279),p=i.n(d),m=i(370),_=i.n(m),f=i(817),v=i.n(f);function g(b){try{return document.execCommand(b)}catch{return!1}}var C=function(h){var k=v()(h);return g("cut"),k},u=C;function y(b){var h=document.documentElement.getAttribute("dir")==="rtl",k=document.createElement("textarea");k.style.fontSize="12pt",k.style.border="0",k.style.padding="0",k.style.margin="0",k.style.position="absolute",k.style[h?"right":"left"]="-9999px";var E=window.pageYOffset||document.documentElement.scrollTop;return k.style.top="".concat(E,"px"),k.setAttribute("readonly",""),k.value=b,k}var O=function(h,k){var E=y(h);k.container.appendChild(E);var I=v()(E);return g("copy"),E.remove(),I},T=function(h){var k=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},E="";return typeof h=="string"?E=O(h,k):h instanceof HTMLInputElement&&!["text","search","url","tel","password"].includes(h?.type)?E=O(h.value,k):(E=v()(h),g("copy")),E},M=T;function H(b){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?H=function(k){return typeof k}:H=function(k){return k&&typeof Symbol=="function"&&k.constructor===Symbol&&k!==Symbol.prototype?"symbol":typeof k},H(b)}var U=function(){var h=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},k=h.action,E=k===void 0?"copy":k,I=h.container,B=h.target,L=h.text;if(E!=="copy"&&E!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(B!==void 0)if(B&&H(B)==="object"&&B.nodeType===1){if(E==="copy"&&B.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(E==="cut"&&(B.hasAttribute("readonly")||B.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if(L)return M(L,{container:I});if(B)return E==="cut"?u(B):M(B,{container:I})},J=U;function z(b){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?z=function(k){return typeof k}:z=function(k){return k&&typeof Symbol=="function"&&k.constructor===Symbol&&k!==Symbol.prototype?"symbol":typeof k},z(b)}function w(b,h){if(!(b instanceof h))throw new TypeError("Cannot call a class as a function")}function P(b,h){for(var k=0;k<h.length;k++){var E=h[k];E.enumerable=E.enumerable||!1,E.configurable=!0,"value"in E&&(E.writable=!0),Object.defineProperty(b,E.key,E)}}function R(b,h,k){return h&&P(b.prototype,h),k&&P(b,k),b}function ae(b,h){if(typeof h!="function"&&h!==null)throw new TypeError("Super expression must either be null or a function");b.prototype=Object.create(h&&h.prototype,{constructor:{value:b,writable:!0,configurable:!0}}),h&&Q(b,h)}function Q(b,h){return Q=Object.setPrototypeOf||function(E,I){return E.__proto__=I,E},Q(b,h)}function Me(b){var h=Ve();return function(){var E=q(b),I;if(h){var B=q(this).constructor;I=Reflect.construct(E,arguments,B)}else I=E.apply(this,arguments);return re(this,I)}}function re(b,h){return h&&(z(h)==="object"||typeof h=="function")?h:ie(b)}function ie(b){if(b===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return b}function Ve(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function q(b){return q=Object.setPrototypeOf?Object.getPrototypeOf:function(k){return k.__proto__||Object.getPrototypeOf(k)},q(b)}function Y(b,h){var k="data-clipboard-".concat(b);if(h.hasAttribute(k))return h.getAttribute(k)}var le=(function(b){ae(k,b);var h=Me(k);function k(E,I){var B;return w(this,k),B=h.call(this),B.resolveOptions(I),B.listenClick(E),B}return R(k,[{key:"resolveOptions",value:function(){var I=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof I.action=="function"?I.action:this.defaultAction,this.target=typeof I.target=="function"?I.target:this.defaultTarget,this.text=typeof I.text=="function"?I.text:this.defaultText,this.container=z(I.container)==="object"?I.container:document.body}},{key:"listenClick",value:function(I){var B=this;this.listener=_()(I,"click",function(L){return B.onClick(L)})}},{key:"onClick",value:function(I){var B=I.delegateTarget||I.currentTarget,L=this.action(B)||"copy",ce=J({action:L,container:this.container,target:this.target(B),text:this.text(B)});this.emit(ce?"success":"error",{action:L,text:ce,trigger:B,clearSelection:function(){B&&B.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(I){return Y("action",I)}},{key:"defaultTarget",value:function(I){var B=Y("target",I);if(B)return document.querySelector(B)}},{key:"defaultText",value:function(I){return Y("text",I)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(I){var B=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return M(I,B)}},{key:"cut",value:function(I){return u(I)}},{key:"isSupported",value:function(){var I=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],B=typeof I=="string"?[I]:I,L=!!document.queryCommandSupported;return B.forEach(function(ce){L=L&&!!document.queryCommandSupported(ce)}),L}}]),k})(p()),x=le}),828:(function(r){var l=9;if(typeof Element<"u"&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}function d(p,m){for(;p&&p.nodeType!==l;){if(typeof p.matches=="function"&&p.matches(m))return p;p=p.parentNode}}r.exports=d}),438:(function(r,l,i){var d=i(828);function p(f,v,g,C,u){var y=_.apply(this,arguments);return f.addEventListener(g,y,u),{destroy:function(){f.removeEventListener(g,y,u)}}}function m(f,v,g,C,u){return typeof f.addEventListener=="function"?p.apply(null,arguments):typeof g=="function"?p.bind(null,document).apply(null,arguments):(typeof f=="string"&&(f=document.querySelectorAll(f)),Array.prototype.map.call(f,function(y){return p(y,v,g,C,u)}))}function _(f,v,g,C){return function(u){u.delegateTarget=d(u.target,v),u.delegateTarget&&C.call(f,u)}}r.exports=m}),879:(function(r,l){l.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},l.nodeList=function(i){var d=Object.prototype.toString.call(i);return i!==void 0&&(d==="[object NodeList]"||d==="[object HTMLCollection]")&&"length"in i&&(i.length===0||l.node(i[0]))},l.string=function(i){return typeof i=="string"||i instanceof String},l.fn=function(i){var d=Object.prototype.toString.call(i);return d==="[object Function]"}}),370:(function(r,l,i){var d=i(879),p=i(438);function m(g,C,u){if(!g&&!C&&!u)throw new Error("Missing required arguments");if(!d.string(C))throw new TypeError("Second argument must be a String");if(!d.fn(u))throw new TypeError("Third argument must be a Function");if(d.node(g))return _(g,C,u);if(d.nodeList(g))return f(g,C,u);if(d.string(g))return v(g,C,u);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function _(g,C,u){return g.addEventListener(C,u),{destroy:function(){g.removeEventListener(C,u)}}}function f(g,C,u){return Array.prototype.forEach.call(g,function(y){y.addEventListener(C,u)}),{destroy:function(){Array.prototype.forEach.call(g,function(y){y.removeEventListener(C,u)})}}}function v(g,C,u){return p(document.body,g,C,u)}r.exports=m}),817:(function(r){function l(i){var d;if(i.nodeName==="SELECT")i.focus(),d=i.value;else if(i.nodeName==="INPUT"||i.nodeName==="TEXTAREA"){var p=i.hasAttribute("readonly");p||i.setAttribute("readonly",""),i.select(),i.setSelectionRange(0,i.value.length),p||i.removeAttribute("readonly"),d=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var m=window.getSelection(),_=document.createRange();_.selectNodeContents(i),m.removeAllRanges(),m.addRange(_),d=m.toString()}return d}r.exports=l}),279:(function(r){function l(){}l.prototype={on:function(i,d,p){var m=this.e||(this.e={});return(m[i]||(m[i]=[])).push({fn:d,ctx:p}),this},once:function(i,d,p){var m=this;function _(){m.off(i,_),d.apply(p,arguments)}return _._=d,this.on(i,_,p)},emit:function(i){var d=[].slice.call(arguments,1),p=((this.e||(this.e={}))[i]||[]).slice(),m=0,_=p.length;for(m;m<_;m++)p[m].fn.apply(p[m].ctx,d);return this},off:function(i,d){var p=this.e||(this.e={}),m=p[i],_=[];if(m&&d)for(var f=0,v=m.length;f<v;f++)m[f].fn!==d&&m[f].fn._!==d&&_.push(m[f]);return _.length?p[i]=_:delete p[i],this}},r.exports=l,r.exports.TinyEmitter=l})},a={};function s(r){if(a[r])return a[r].exports;var l=a[r]={exports:{}};return n[r](l,l.exports,s),l.exports}return(function(){s.n=function(r){var l=r&&r.__esModule?function(){return r.default}:function(){return r};return s.d(l,{a:l}),l}})(),(function(){s.d=function(r,l){for(var i in l)s.o(l,i)&&!s.o(r,i)&&Object.defineProperty(r,i,{enumerable:!0,get:l[i]})}})(),(function(){s.o=function(r,l){return Object.prototype.hasOwnProperty.call(r,l)}})(),s(686)})().default})})(se)),se.exports}var Kn=Yn();const Xn=qn(Kn),Jn=o=>({toClipboard(t,n){return new Promise((a,s)=>{const r=document.createElement("button"),l=new Xn(r,{text:()=>t,action:()=>"copy",container:n!==void 0?n:document.body});l.on("success",i=>{l.destroy(),a(i)}),l.on("error",i=>{l.destroy(),s(i)}),document.body.appendChild(r),r.click(),document.body.removeChild(r)})}}),Qn={key:0,class:"baklava-button"},pt=e.defineComponent({__name:"CopyToClipboard",props:{text:String},setup(o){const{toClipboard:t}=Jn(),n=o,a=e.toRef(n,"text"),s=e.ref(!1),r=async()=>{try{await t(a.value),s.value=!0,setTimeout(()=>s.value=!1,1500),console.log("Copied to clipboard")}catch(l){console.error(l)}};return(l,i)=>(e.openBlock(),e.createElementBlock("div",null,[s.value?(e.openBlock(),e.createElementBlock("button",Qn,[e.createVNode(e.unref(ze))])):(e.openBlock(),e.createElementBlock("button",{key:1,onClick:r,class:"baklava-button"},[e.createVNode(e.unref(Ue))]))]))}}),Zn={class:"code-editor"},eo={class:"code-buttons"},to=e.defineComponent({__name:"CodeEditor",props:e.mergeModels({locked:{type:Boolean},extensions:{}},{modelValue:{required:!0,type:String},modelModifiers:{}}),emits:e.mergeModels(["update:locked"],["update:modelValue"]),setup(o,{emit:t}){const n=e.useModel(o,"modelValue"),a=t,s=r=>a("update:locked",r);return(r,l)=>{const i=e.resolveComponent("codemirror");return e.openBlock(),e.createElementBlock("div",Zn,[e.createElementVNode("div",eo,[o.locked?(e.openBlock(),e.createElementBlock("button",{key:0,class:"baklava-button",title:"The code is locked.",onClick:l[0]||(l[0]=d=>s(!1))},[e.createVNode(e.unref(be))])):e.createCommentVNode("",!0),e.createVNode(pt,{text:o.modelValue},null,8,["text"])]),e.createVNode(i,{modelValue:n.value,"onUpdate:modelValue":l[1]||(l[1]=d=>n.value=d),extensions:o.extensions,class:"codemirror",style:{height:"100%"},onKeydown:l[2]||(l[2]=d=>s(!0))},null,8,["modelValue","extensions"])])}}}),no=e.defineComponent({__name:"CodeGraphEditor",props:{viewModel:{}},setup(o){const t=o,n=e.toRef(t,"viewModel"),a=s=>s.events.update.emit(null);return e.onMounted(()=>{n.value.subscribe&&n.value.subscribe(),n.value.engine?.start()}),e.onBeforeUnmount(()=>{n.value.unsubscribe&&n.value.unsubscribe(),n.value.engine?.stop()}),e.watch(n,(s,r)=>{r&&r.unsubscribe(),s&&s.subscribe()}),(s,r)=>(e.openBlock(),e.createBlock(e.unref(N.BaklavaEditor),{viewModel:n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(mt))]),node:e.withCtx(l=>[e.createVNode(e.unref(ht),e.mergeProps(l,{onUpdate:i=>a(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(ft),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:i})=>[e.renderSlot(s.$slots,"sidebarCodeEditor",{node:i})]),_:3},16)]),_:3},8,["viewModel"]))}}),oo={class:"code-graph-info"},so=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",oo,[e.createElementVNode("div",null,"Editor graph: "+e.toDisplayString(o.viewModel.editor.graph.shortId),1),e.createElementVNode("div",null,"Displayed graph: "+e.toDisplayString(o.viewModel.displayedGraph.shortId),1),e.createElementVNode("div",null,"Graphs: "+e.toDisplayString(o.viewModel.editor.graphIds),1),e.createElementVNode("div",null,"Graph templates: "+e.toDisplayString(o.viewModel.editor.graphTemplateIds),1),e.createElementVNode("div",null,"Engine status: "+e.toDisplayString(o.viewModel.engine?.status),1)]))}}),ao=["id","data-node-type"],ro={class:"__title-label",style:{"flex-grow":"1"}},io={key:0},lo={class:"__menu",style:{display:"flex"}},co={class:"__outputs"},uo={key:0},po=["id","title"],ho={class:"__inputs"},fo={key:0},mo=["id","title"],ht=e.defineComponent({__name:"CodeGraphNode",props:{node:{},selected:{type:Boolean,default:!1},dragging:{type:Boolean}},emits:["select","start-drag","update"],setup(o,{emit:t}){const n=N.Components.ContextMenu,a=N.Components.NodeInterface,s=o,r=e.computed(()=>s.node),l=t,{viewModel:i}=N.useViewModel(),{graph:d,switchGraph:p}=N.useGraph(),m=e.ref(null),_=e.ref(!1),f=e.ref(""),v=e.ref(null),g=e.ref(!1);let C=0,u=0;const y=e.ref(!1),O=e.computed(()=>{const x=[{value:"edit",label:"Edit"},{value:"rename",label:"Rename"},{value:"delete",label:"Delete"}];return s.node.type.startsWith(V.GRAPH_NODE_TYPE_PREFIX)&&x.push({value:"editSubgraph",label:"Edit Subgraph"}),x}),T=e.computed(()=>({"--selected":s.selected,"--dragging":s.dragging,"--two-column":!!s.node.twoColumn,"--hidden":r.value.state?.hidden})),M=e.computed(()=>({"--reverse-y":s.node.reverseY??i.value.settings.nodes.reverseY})),H=e.computed(()=>({top:`${s.node.position?.y??0}px`,left:`${s.node.position?.x??0}px`,"--width":`${s.node.width??i.value.settings.nodes.defaultWidth}px`})),U=e.computed(()=>Object.values(s.node.inputs).filter(x=>!x.hidden)),J=e.computed(()=>Object.values(s.node.outputs).filter(x=>!x.hidden)),z=()=>{l("select")},w=x=>{s.selected||z(),l("start-drag",x)},P=()=>{y.value=!0},R=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId="",x.visible=!1},ae=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId=s.node.id,x.visible=!0},Q=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId=s.node.id},Me=async x=>{switch(x){case"edit":ae();break;case"delete":d.value.removeNode(s.node);break;case"rename":f.value=s.node.title,_.value=!0,await e.nextTick(),v.value?.focus();break;case"editSubgraph":p(s.node.template);break}},re=()=>{r.value.title=f.value,_.value=!1},ie=()=>{m.value&&i.value.hooks.renderNode.execute({node:s.node,el:m.value})},Ve=x=>{g.value=!0,C=s.node.width,u=x.clientX,x.preventDefault()},q=x=>{r.value.state&&(r.value.state.integrated=x,l("update"))},Y=x=>{if(!g.value)return;const b=x.clientX-u,h=C+b/d.value.scaling,k=i.value.settings.nodes.minWidth,E=i.value.settings.nodes.maxWidth;r.value.width=Math.max(k,Math.min(E,h))},le=()=>{g.value=!1};return e.onMounted(()=>{ie(),window.addEventListener("mousemove",Y),window.addEventListener("mouseup",le)}),e.onUpdated(ie),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",Y),window.removeEventListener("mouseup",le)}),(x,b)=>(e.openBlock(),e.createElementBlock("div",{id:r.value.id,ref_key:"el",ref:m,class:e.normalizeClass([T.value,"baklava-node"]),"data-node-type":r.value.type,style:e.normalizeStyle(H.value),onPointerdown:z},[e.unref(i).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Ve},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(w,["self","stop"]),onContextmenu:e.withModifiers(P,["prevent"])},[r.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(Be),{key:0,node:r.value,intf:r.value.inputs._code,title:r.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["node","intf","title"])):e.createCommentVNode("",!0),_.value?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,ref_key:"renameInputEl",ref:v,"onUpdate:modelValue":b[4]||(b[4]=h=>f.value=h),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:re,onKeydown:e.withKeys(re,["enter"])},null,544)),[[e.vModelText,f.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",ro,[r.value.idx>-1?(e.openBlock(),e.createElementBlock("span",io,e.toDisplayString(r.value.idx+1)+" - ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(r.value.title)+" "+e.toDisplayString(r.value.graph.shortId)+" "+e.toDisplayString(r.value.shortId),1)]),e.createElementVNode("div",lo,[r.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[r.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(be),{key:0,class:"--clickable mx-1",onClick:b[0]||(b[0]=h=>r.value.lockCode=!1)})):e.createCommentVNode("",!0),r.value.state.integrated?(e.openBlock(),e.createBlock(e.unref(He),{key:1,class:"--clickable mx-1",onClick:b[1]||(b[1]=h=>q(!1))})):(e.openBlock(),e.createBlock(e.unref(tt),{key:2,class:"--clickable mx-1",onClick:b[2]||(b[2]=h=>q(!0))})),!e.unref(i).displayedGraph.sidebar.visible&&e.unref(i).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(Xe),{key:3,class:"--clickable mx-1",onClick:ae})):e.unref(i).displayedGraph.sidebar.visible&&e.unref(i).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(Ye),{key:4,class:"--clickable mx-1",onClick:Q})):(e.openBlock(),e.createBlock(e.unref(Ke),{key:5,class:"--clickable mx-1",onClick:R}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Fe),{class:"--clickable mx-1",onClick:P}),e.createVNode(e.unref(n),{modelValue:y.value,"onUpdate:modelValue":b[3]||(b[3]=h=>y.value=h),x:0,y:0,items:O.value,onClick:Me},null,8,["modelValue","items"])])],64)),r.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(Be),{key:3,node:r.value,intf:r.value.outputs._code,class:"--output",title:r.value.outputs._code.value,"data-interface-type":"node"},null,8,["node","intf","title"])):e.createCommentVNode("",!0)],32),e.createElementVNode("div",{class:e.normalizeClass(["__content",M.value]),onKeydown:b[5]||(b[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:b[6]||(b[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",co,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(J.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",uo,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --output --connected"},[...b[7]||(b[7]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,po)):e.createCommentVNode("",!0)])):e.renderSlot(x.$slots,"nodeInterface",{key:1,type:"output",node:r.value,intf:h},()=>[e.createVNode(e.unref(a),{node:r.value,intf:h,title:h.value},null,8,["node","intf","title"])])],64))),128))]),e.createElementVNode("div",ho,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(U.value,h=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:h.id},[r.value.state?.hidden?(e.openBlock(),e.createElementBlock("div",fo,[h.port?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.id,title:h.name,class:"baklava-node-interface --input --connected"},[...b[8]||(b[8]=[e.createElementVNode("div",{class:"__port"},null,-1)])],8,mo)):e.createCommentVNode("",!0)])):e.renderSlot(x.$slots,"nodeInterface",{key:1,node:r.value,intf:h,type:"input"},()=>[e.createVNode(e.unref(a),{node:r.value,intf:h,title:h.value},null,8,["node","intf","title"])])],64))),128))])],34)],46,ao))}}),go=["id"],bo={class:"align-middle"},Be=e.defineComponent({__name:"CodeGraphNodeInterface",props:{node:{},intf:{}},setup(o){const t=o,{viewModel:n}=N.useViewModel(),{hoveredOver:a,temporaryConnection:s}=N.useTemporaryConnection(),r=e.ref(null),l=e.computed(()=>t.intf.connectionCount>0),i=e.computed(()=>({"--connected":l.value})),d=()=>{a(t.intf)},p=()=>{a(void 0)},m=()=>{r.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:r.value})};return e.onMounted(m),e.onUpdated(m),(_,f)=>(e.openBlock(),e.createElementBlock("div",{id:o.intf.id,ref_key:"el",ref:r,class:e.normalizeClass(["baklava-node-interface",i.value])},[o.intf.port?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["__port",{"--selected":e.unref(s)?.from===o.intf}]),onPointerover:d,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",bo,[e.renderSlot(_.$slots,"default")])],10,go))}}),yo=["title"],ko={key:0,class:"__label"},Te=e.defineComponent({__name:"SidebarCheckbox",props:{disabled:{type:Boolean},inversed:{type:Boolean},modelValue:{type:Boolean},name:{}},emits:["update:modelValue"],setup(o,{emit:t}){const n=t;return(a,s)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["baklava-checkbox",{"--checked":o.inversed?!o.modelValue:o.modelValue,"--disabled":o.disabled}]),title:o.name,onClick:s[0]||(s[0]=r=>n("update:modelValue",!o.modelValue))},[s[1]||(s[1]=e.createElementVNode("div",{class:"__checkmark-container"},[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18"},[e.createElementVNode("path",{class:"__checkmark",d:"M 6 5 L 6 10 L 16 10",transform:"rotate(-45 10 10)"})])],-1)),o.name?(e.openBlock(),e.createElementBlock("div",ko,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,yo))}}),_o={class:"__header"},Co={class:"__node-name"},No={class:"__interfaces"},wo={class:"__inputs"},Eo={style:{display:"flex"}},Io={class:"__outputs"},vo={key:0,class:"__interface"},Bo={style:{display:"flex"}},ft=e.defineComponent({__name:"CodeGraphSidebar",setup(o){const{viewModel:t}=N.useViewModel(),{graph:n}=N.useGraph(),a=e.ref(null),s=e.toRef(t.value.settings.sidebar,"width"),r=e.computed(()=>t.value.settings.sidebar.resizable);let l=0,i=0;const d=e.computed(()=>{const y=n.value.sidebar.nodeId;return n.value.nodes.find(O=>O.id===y)}),p=e.computed(()=>d.value),m=e.computed(()=>({width:`${s.value}px`})),_=e.computed(()=>p.value?Object.values(p.value.inputs).filter(y=>y.displayInSidebar&&y.component):[]),f=e.computed(()=>p.value?Object.values(p.value.outputs).filter(y=>y.displayInSidebar&&y.component):[]),v=()=>{n.value.sidebar.visible=!1},g=()=>{d.value?.events.update.emit(null)},C=y=>{l=s.value,i=y.clientX,window.addEventListener("mousemove",u),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",u)},{once:!0})},u=y=>{const O=a.value?.parentElement?.getBoundingClientRect().width??500,T=y.clientX-i;let M=l-T;M<300?M=300:M>.9*O&&(M=.9*O),s.value=M};return(y,O)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(m.value),ref_key:"el",ref:a},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:C},null,32)):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",_o,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:v},"×"),e.createElementVNode("div",Co,[e.createElementVNode("b",null,e.toDisplayString(d.value.title),1)])]),e.createElementVNode("div",No,[e.createElementVNode("div",wo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_.value,T=>(e.openBlock(),e.createElementBlock("div",{key:T.id,class:"__interface"},[e.createElementVNode("div",Eo,[e.createVNode(Te,{modelValue:T.hidden,"onUpdate:modelValue":[M=>T.hidden=M,O[0]||(O[0]=()=>d.value?.events.update.emit(null))],disabled:!T.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(T.component),{modelValue:T.value,"onUpdate:modelValue":M=>T.value=M,node:d.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",Io,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",vo,[O[3]||(O[3]=e.createElementVNode("label",null,"Variable name",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":O[1]||(O[1]=T=>p.value.state.variableName=T),type:"text",class:"baklava-input",title:"Variable name",onBlur:g,onKeydown:e.withKeys(g,["enter"])},null,544),[[e.vModelText,p.value.state.variableName]])])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,T=>(e.openBlock(),e.createElementBlock("div",{key:T.id,class:"__interface"},[e.createElementVNode("div",Bo,[e.createVNode(Te,{modelValue:T.hidden,"onUpdate:modelValue":[M=>T.hidden=M,O[2]||(O[2]=()=>d.value?.events.update.emit(null))],disabled:!T.optional,inversed:"",style:{"padding-right":"8px"}},null,8,["modelValue","onUpdate:modelValue","disabled"]),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(T.component),{modelValue:T.value,"onUpdate:modelValue":M=>T.value=M,node:d.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(y.$slots,"codeEditor",{node:d.value})],64)):e.createCommentVNode("",!0)],6))}}),To={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},xo={key:0,style:{display:"flex","justify-content":"space-between"}},Oo=["onClick"],So={key:0,style:{margin:"auto 0","font-size":"12px"}},mt=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=N.Components.PaletteEntry,{viewModel:n}=N.useViewModel(),{x:a,y:s}=_t.usePointer(),{transform:r}=N.useTransform(),l=N.useNodeCategories(n),i=e.inject("editorEl"),d=e.ref(""),p=e.ref(null),m=()=>d.value?l.value.filter(g=>g.name.toLowerCase().includes(d.value.toLowerCase())||Object.values(g.nodeTypes).some(C=>C.title.toLowerCase().includes(d.value.toLowerCase()))):l.value,_=g=>d.value?Hn(g,C=>{const u=C[1];return u.category.includes(d.value.toLowerCase())||u.title?.toLowerCase().includes(d.value.toLowerCase())}):g,f=e.computed(()=>{if(!p.value||!i?.value)return{};const{left:g,top:C}=i.value.getBoundingClientRect();return{top:`${s.value-C}px`,left:`${a.value-g}px`}}),v=(g,C)=>{p.value={type:g,nodeInformation:C};const u=()=>{const y=e.reactive(new C.type);n.value.displayedGraph.addNode(y);const O=i.value.getBoundingClientRect(),[T,M]=r(a.value-O.left,s.value-O.top);y.position.x=T,y.position.y=M,p.value=null,document.removeEventListener("pointerup",u)};document.addEventListener("pointerup",u)};return(g,C)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:e.normalizeClass([{"--open":e.unref(n).settings.palette.enabled},"baklava-node-palette"]),onContextmenu:C[1]||(C[1]=e.withModifiers(()=>{},["stop","prevent"]))},[e.createElementVNode("div",To,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[0]||(C[0]=u=>d.value=u),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:m},null,544),[[e.vModelText,d.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(m(),u=>(e.openBlock(),e.createElementBlock("section",{key:u.name},[u.name!=="default"?(e.openBlock(),e.createElementBlock("h3",xo,[e.createElementVNode("div",{onClick:y=>d.value=u.name,style:{cursor:"pointer"}},e.toDisplayString(u.name),9,Oo),Object.keys(_(u.nodeTypes)).length<Object.values(u.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",So," ( "+e.toDisplayString(Object.keys(_(u.nodeTypes)).length)+" / "+e.toDisplayString(Object.values(u.nodeTypes).length)+" ) ",1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(_(u.nodeTypes),(y,O)=>(e.openBlock(),e.createBlock(e.unref(t),{key:O,type:O,title:y.title,onPointerdown:T=>v(O,y)},null,8,["type","title","onPointerdown"]))),128))]))),128))],34),e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"baklava-dragged-node",style:e.normalizeStyle(f.value)},[e.createVNode(e.unref(t),{type:p.value.type,title:p.value.nodeInformation.title},null,8,["type","title"])],4)):e.createCommentVNode("",!0)]),_:1})],64))}}),Mo={},Vo={class:"prependIcon"},$o={class:"appendIcon"};function Po(o,t){const n=e.resolveComponent("router-link");return e.openBlock(),e.createBlock(n,{class:"navItem"},{default:e.withCtx(()=>[e.createElementVNode("span",Vo,[e.renderSlot(o.$slots,"prependIcon")]),e.renderSlot(o.$slots,"default"),e.createElementVNode("span",$o,[e.renderSlot(o.$slots,"appendIcon")])]),_:3})}const xe=$(Mo,[["render",Po]]),jo={class:"navbar"},Ro=["onClick"],Go=e.defineComponent({__name:"NavBar",props:{viewModel:{},editorStates:{},routes:{}},emits:["click:remove"],setup(o,{emit:t}){const n=t,a=s=>{n("click:remove",s)};return(s,r)=>(e.openBlock(),e.createElementBlock("nav",jo,[e.renderSlot(s.$slots,"prepend"),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.editorStates,l=>(e.openBlock(),e.createBlock(xe,{key:l.graph.id,class:e.normalizeClass({active:l.graph.id===o.viewModel.displayedGraph.id}),to:{name:o.routes?.edit??"edit",params:{editorId:l.graph.id}}},{appendIcon:e.withCtx(()=>[e.createElementVNode("button",{class:"remove",onClick:e.withModifiers(i=>a(l.graph.id),["prevent"])},[e.createVNode(e.unref(ot))],8,Ro)]),default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(l.graph.id.slice(0,6))+" ",1)]),_:2},1032,["class","to"]))),128)),e.renderSlot(s.$slots,"append",{},()=>[e.createVNode(xe,{to:{name:o.routes?.new??"new"},class:"navItem"},{default:e.withCtx(()=>[e.createVNode(e.unref(Qe),{class:"plus"})]),_:1},8,["to"])])]))}});class Oe extends Ie{_title="Subgraph Input";inputs={_code:new j("","").use(S.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new j("","").use(S.setType,G).setHidden(!0),placeholder:new V.NodeInterface("Connection",void 0)}}class Se extends ve{_title="Subgraph Output";inputs={_code:new j("","").use(S.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Output").setPort(!1),placeholder:new V.NodeInterface("Connection",void 0)};outputs={_code:new j("","").use(S.setType,G).setHidden(!0),output:new V.NodeInterface("Output",void 0).setHidden(!0)}}const gt="CREATE_SUBGRAPH",bt=[V.GRAPH_INPUT_NODE_TYPE,V.GRAPH_OUTPUT_NODE_TYPE];function yt(o,t,n){const a=()=>o.value.selectedNodes.filter(r=>!bt.includes(r.type)).length>0,s=()=>{const{viewModel:r}=N.useViewModel(),l=o.value,i=o.value.editor;if(l.selectedNodes.length===0)return;const d=l.selectedNodes.filter(w=>!bt.includes(w.type)),p=d.flatMap(w=>Object.values(w.inputs)),m=d.flatMap(w=>Object.values(w.outputs)),_=l.connections.filter(w=>!m.includes(w.from)&&p.includes(w.to)),f=l.connections.filter(w=>m.includes(w.from)&&!p.includes(w.to)),v=l.connections.filter(w=>m.includes(w.from)&&p.includes(w.to)),g=d.map(w=>w.save()),C=v.map(w=>({id:w.id,from:w.from.id,to:w.to.id})),u=new Map,{xLeft:y,xRight:O,yTop:T}=Lo(d);for(const[w,P]of _.entries()){const R=new Oe;R.inputs.name.value=P.to.name,g.push({...R.save(),position:{x:O-r.value.settings.nodes.defaultWidth-100,y:T+w*200}}),C.push({id:F.v4(),from:R.outputs.placeholder.id,to:P.to.id}),u.set(P.to.id,R.graphInterfaceId)}for(const[w,P]of f.entries()){const R=new Se;R.inputs.name.value=P.from.name,g.push({...R.save(),position:{x:y+100,y:T+w*200}}),C.push({id:F.v4(),from:P.from.id,to:R.inputs.placeholder.id}),u.set(P.from.id,R.graphInterfaceId)}const M=e.reactive(new X({connections:C,nodes:g,inputs:[],outputs:[]},i));i.addGraphTemplate(M);const H=i.nodeTypes.get(V.getGraphNodeTypeString(M));if(!H)throw new Error("Unable to create subgraph: Could not find corresponding graph node type");l.activeTransactions++;const U=e.reactive(new H.type);l.addNode(U);const J=Math.round(d.map(w=>w.position.x).reduce((w,P)=>w+P,0)/d.length),z=Math.round(d.map(w=>w.position.y).reduce((w,P)=>w+P,0)/d.length);U.position.x=J,U.position.y=z,_.forEach(w=>{l.removeConnection(w),l.addConnection(w.from,U.inputs[u.get(w.to.id)])}),f.forEach(w=>{l.removeConnection(w),l.addConnection(U.outputs[u.get(w.from.id)],w.to)}),d.forEach(w=>l.removeNode(w)),l.activeTransactions--,t.canExecuteCommand(N.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(N.Commands.SAVE_SUBGRAPH_COMMAND),n(M),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(gt,{canExecute:a,execute:s})}function Lo(o){const t=o.reduce((s,r)=>{const l=r.position.x;return l<s?l:s},1/0),n=o.reduce((s,r)=>{const l=r.position.y;return l<s?l:s},1/0);return{xLeft:o.reduce((s,r)=>{const l=r.position.x+r.width;return l>s?l:s},-1/0),xRight:t,yTop:n}}class Ao extends V.Editor{code;graph;constructor(t){super(),this.code=t,this.graph=new K(this)}get graphIds(){const t=[];return this.graphs.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}get graphTemplateIds(){const t=[];return this.graphTemplates.forEach(n=>t.push(n.id)),t.map(n=>n.slice(0,6)).join(", ")}addGraphTemplate(t){if(this.events.beforeAddGraphTemplate.emit(t).prevented)return;this._graphTemplates.push(t),this.graphTemplateEvents.addTarget(t.events),this.graphTemplateHooks.addTarget(t.hooks);const n=ct(t);this.registerNodeType(n,{category:"Subgraphs",title:t.name}),this.events.addGraphTemplate.emit(t)}load(t){try{for(super._loading=!0,t=this.hooks.load.execute(t);this.graphTemplates.length>0;)this.removeGraphTemplate(this.graphTemplates[0]);t.graphTemplates.forEach(a=>{const s=new X(a,this);this.addGraphTemplate(s)});const n=this.graph.load(t.graph);return this.events.loaded.emit(),n.forEach(a=>console.warn(a)),n}finally{super._loading=!1}}registerCategoryModule(t,n){this.code.state.modules[t]=n}}function Do(o){const t=e.ref(o?.code??new oe),n=e.ref(o?.existingEditor??new Ao(t.value)),a=Symbol("ViewModelToken"),s=e.ref(null),r=e.shallowReadonly(s),{switchGraph:l}=dt(n,s),i=e.computed(()=>r.value&&r.value!==n.value.graph),d=e.reactive(N.DEFAULT_SETTINGS());d.nodes.defaultWidth=400;const p=N.useCommandHandler(),m=N.useHistory(r,p),_=N.useClipboard(r,n,p),f={renderNode:new $e.SequentialHook(null),renderInterface:new $e.SequentialHook(null)},v=e.reactive({clipboard:_,code:t,commandHandler:p,displayedGraph:r,editor:n,history:m,hooks:f,isSubgraph:i,settings:d,switchGraph:l});return t.value.registerViewModel(v),it(v),N.registerDeleteNodesCommand(r,p),yt(r,p,l),N.registerSaveSubgraphCommand(r,p),N.registerSwitchToMainGraphCommand(r,p,l),N.registerSidebarCommands(r,p),N.registerZoomToFitCommands(r,p,d),st(r,p,d),at(d),e.watch(n,(g,C)=>{C&&(C.events.registerGraph.unsubscribe(a),C.graphEvents.beforeAddNode.unsubscribe(a),g.nodeHooks.beforeLoad.unsubscribe(a),g.nodeHooks.afterSave.unsubscribe(a),g.graphTemplateHooks.beforeLoad.unsubscribe(a),g.graphTemplateHooks.afterSave.unsubscribe(a),g.graph.hooks.load.unsubscribe(a),g.graph.hooks.save.unsubscribe(a)),g&&(g.nodeHooks.beforeLoad.subscribe(a,(u,y)=>(y.position=u.position??{x:0,y:0},y.width=u.width??d.nodes.defaultWidth,y.twoColumn=u.twoColumn??!1,u)),g.nodeHooks.afterSave.subscribe(a,(u,y)=>(u.position=y.position,u.width=y.width,u.twoColumn=y.twoColumn,u)),g.graphTemplateHooks.beforeLoad.subscribe(a,(u,y)=>(y.panning=u.panning,y.scaling=u.scaling,u)),g.graphTemplateHooks.afterSave.subscribe(a,(u,y)=>(u.panning=y.panning,u.scaling=y.scaling,u)),g.graph.hooks.load.subscribe(a,(u,y)=>(y.panning=u.panning,y.scaling=u.scaling,u)),g.graph.hooks.save.subscribe(a,(u,y)=>(u.panning=y.panning,u.scaling=y.scaling,u)),g.graphEvents.beforeAddNode.subscribe(a,u=>N.setViewNodeProperties(u,{defaultWidth:d.nodes.defaultWidth})),n.value.registerNodeType(Oe,{category:"Subgraphs"}),n.value.registerNodeType(Se,{category:"Subgraphs"}),l(g.graph))},{immediate:!0}),v}const zo=Object.freeze(Object.defineProperty({__proto__:null,default:`{{ #modules }}
5
5
  {{ . }}
6
6
  {{ /modules }}
7
7
 
@@ -13,4 +13,4 @@ This is likely an internal issue. Please report it on GitHub.`);return t.get(n)}
13
13
 
14
14
  {{ #nodes }}
15
15
  {{ #commented }}// {{ /commented }}{{ #variableName }}var {{ variableName }} = {{ /variableName }}{{ script }};
16
- {{ /nodes }}`},Symbol.toStringTag,{value:"Module"}));c.AbstractCodeNode=de,c.CLEAR_ALL_COMMAND=Ne,c.CREATE_SUBGRAPH_COMMAND=gt,c.Check=Ue,c.CheckboxInterface=wt,c.Code=oe,c.CodeEditor=to,c.CodeEngine=He,c.CodeGraph=K,c.CodeGraphEditor=no,c.CodeGraphInfo=so,c.CodeGraphInputNode=ke,c.CodeGraphNode=ht,c.CodeGraphNodeInterface=Be,c.CodeGraphOutputNode=_e,c.CodeGraphSidebar=ft,c.CodeGraphTemplate=X,c.CodeNode=Z,c.CodeNodeInputInterface=W,c.CodeNodeInterface=j,c.CodeNodeInterfaceComponent=ee,c.CodeNodeOutputInterface=Ge,c.CodeNodePalette=mt,c.CodeVariable=Fe,c.Copy=qe,c.CopyToClipboard=pt,c.DotsVertical=We,c.DynamicCodeNode=Ae,c.GRAPH_INPUT_NODE_TYPE=be,c.GRAPH_OUTPUT_NODE_TYPE=ye,c.IntegerInterface=Et,c.JavascriptCode=Dt,c.LayoutSidebarLeftCollapse=Ye,c.LayoutSidebarLeftExpand=Ke,c.LayoutSidebarRight=Xe,c.LayoutSidebarRightCollapse=Je,c.LayoutSidebarRightExpand=Qe,c.ListInputInterface=It,c.LockCode=Ce,c.NavBar=Go,c.NavItem=xe,c.NumberInterface=vt,c.PlayerPlay=Ze,c.Plus=et,c.PythonCode=At,c.RUN_ENGINE_COMMAND=we,c.Schema=tt,c.SchemaOff=nt,c.SelectInterface=Bt,c.SidebarCheckbox=Te,c.SliderInterface=Tt,c.SubgraphInputNode=Oe,c.SubgraphOutputNode=Se,c.TOGGLE_MINIMAP_COMMAND=Ee,c.TOGGLE_PALETTE_COMMAND=Ie,c.TextInputInterface=$t,c.TextInputInterfaceComponent=Le,c.TextareaInputInterface=Pt,c.TransitionBottom=ot,c.TrashOff=st,c.TupleInputInterface=jt,c.X=at,c.addDefaultInterfaceTypes=Nt,c.allowMultipleConnections=zt,c.booleanType=pe,c.createCodeGraphNodeType=ze,c.defineCodeNode=Rt,c.defineDynamicCodeNode=Gt,c.dictType=Re,c.formatInputs=Pe,c.getCodeNodes=ve,c.getPositionAtColumn=Dn,c.getPositionBeforeNode=zn,c.listType=he,c.loadNodeState=ue,c.nodeType=G,c.numberType=te,c.registerCodeEngine=ct,c.registerCreateSubgraphCommand=yt,c.registerCustomCommands=rt,c.registerRunEngineCommands=lt,c.saveNodeState=je,c.stringType=ne,c.tupleType=fe,c.updateToolbarItems=it,c.useCodeGraph=Do,c.useSwitchCodeGraph=dt,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
16
+ {{ /nodes }}`},Symbol.toStringTag,{value:"Module"}));c.AbstractCodeNode=de,c.CLEAR_ALL_COMMAND=ye,c.CREATE_SUBGRAPH_COMMAND=gt,c.Check=ze,c.CheckboxInterface=wt,c.Code=oe,c.CodeEditor=to,c.CodeEngine=De,c.CodeGraph=K,c.CodeGraphEditor=no,c.CodeGraphInfo=so,c.CodeGraphInputNode=Ie,c.CodeGraphNode=ht,c.CodeGraphNodeInterface=Be,c.CodeGraphOutputNode=ve,c.CodeGraphSidebar=ft,c.CodeGraphTemplate=X,c.CodeNode=Z,c.CodeNodeInputInterface=W,c.CodeNodeInterface=j,c.CodeNodeInterfaceComponent=ee,c.CodeNodeOutputInterface=Ge,c.CodeNodePalette=mt,c.CodeVariable=He,c.Copy=Ue,c.CopyToClipboard=pt,c.DotsVertical=Fe,c.DynamicCodeNode=Ae,c.GRAPH_INPUT_NODE_TYPE=we,c.GRAPH_OUTPUT_NODE_TYPE=Ee,c.IntegerInterface=Et,c.JavascriptCode=At,c.LayoutSidebarLeftCollapse=qe,c.LayoutSidebarLeftExpand=We,c.LayoutSidebarRight=Ye,c.LayoutSidebarRightCollapse=Ke,c.LayoutSidebarRightExpand=Xe,c.ListInputInterface=It,c.LockCode=be,c.NavBar=Go,c.NavItem=xe,c.NumberInterface=vt,c.PlayerPlay=Je,c.Plus=Qe,c.PythonCode=Lt,c.RUN_ENGINE_COMMAND=ke,c.Schema=Ze,c.SchemaOff=et,c.SelectInterface=Bt,c.SidebarCheckbox=Te,c.SliderInterface=Tt,c.SubgraphInputNode=Oe,c.SubgraphOutputNode=Se,c.TOGGLE_MINIMAP_COMMAND=_e,c.TOGGLE_PALETTE_COMMAND=Ce,c.TextInputInterface=$t,c.TextInputInterfaceComponent=Le,c.TextareaInputInterface=Pt,c.TransitionBottom=tt,c.TrashOff=nt,c.TupleInputInterface=jt,c.X=ot,c.addDefaultInterfaceTypes=Nt,c.allowMultipleConnections=Dt,c.booleanType=pe,c.createCodeGraphNodeType=ct,c.defineCodeNode=Rt,c.defineDynamicCodeNode=Gt,c.dictType=Re,c.formatInputs=Pe,c.getCodeNodes=Ne,c.getPositionAtColumn=An,c.getPositionBeforeNode=Dn,c.listType=he,c.loadNodeState=ue,c.nodeType=G,c.numberType=te,c.registerCodeEngine=it,c.registerCreateSubgraphCommand=yt,c.registerCustomCommands=st,c.registerRunEngineCommands=rt,c.saveNodeState=je,c.stringType=ne,c.tupleType=fe,c.updateToolbarItems=at,c.useCodeGraph=Do,c.useSwitchCodeGraph=dt,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babsey/code-graph",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "author": "babsey <spreizer@web.de>",
5
5
  "license": "MIT",
6
6
  "type": "module",