@babsey/code-graph 0.4.4 → 0.5.0
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.
- package/dist/code-graph.js +410 -380
- package/dist/code-graph.umd.cjs +4 -4
- package/package.json +1 -1
package/dist/code-graph.umd.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(d,P){typeof exports=="object"&&typeof module<"u"?P(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"],P):(d=typeof globalThis<"u"?globalThis:d||self,P(d["@babsey/code-graph"]={},d.mustache,d.vue,d.uuid,d["@baklavajs/core"],d["@baklavajs/interface-types"],d["@baklavajs/engine"],d["@baklavajs/renderer-vue"],d.toposort,d["@baklavajs/events"],d["@vueuse/core"]))})(this,(function(d,P,e,F,V,M,D,N,It,je,vt){"use strict";P.escape=o=>o;class le 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:""}),this.codeTemplate=function(){return`${this.name}(${Ae(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 P.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}updateInputValues(t){const n=Object.keys(this.inputs);Object.keys(t).forEach(a=>{!n.includes(a)||!this.inputs[a]||(this.inputs[a].value=t[a],this.inputs[a].setHidden(!1))})}}class Z extends le{calculate=(t,n)=>{const a={};return this.lockCode||(a._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(a),a};load(t){super.load(t),de(this.graph,t)}save(){const t=super.save();return Ge(this.graph,t),t}}const Ae=(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},de=(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)})},Ge=(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])=>{if(s!=="_code"&&a.inputs[s]){const l=a.inputs[s];r.hidden=l.hidden,l.component?.__name&&(r.component=l.component.__name)}}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(r.hidden=a.outputs[s].hidden)})},Le=(o,t)=>{switch(o){case"CheckBoxInterface":return new De(t.id,t.value);case"IntegerInterface":return new ge(t.id,t.value,t.min,t.max);case"NumberInterface":return new He(t.id,t.value,t.min,t.max);case"SelectInterface":return new Ue(t.id,t.value,t.items);default:return new ye(t.id,t.value)}},Bt=["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,Bt))}});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 Y 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 ce=new M.NodeInterfaceType("boolean"),Pe=new M.NodeInterfaceType("dict"),ue=new M.NodeInterfaceType("list"),G=new M.NodeInterfaceType("node"),pe=new M.NodeInterfaceType("number"),he=new M.NodeInterfaceType("string"),me=new M.NodeInterfaceType("tuple"),Tt=o=>{new M.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(ce,Pe,ue,G,pe,he,me)};class De extends Y{constructor(t,n){super(t,n),this.setComponent(e.markRaw(N.CheckboxInterfaceComponent)),this.use(M.setType,ce)}getValue=()=>this.value?"True":"False"}class ze 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 fe extends Y{min;max;constructor(t,n,a,s){super(t,n),this.min=a,this.max=s,this.use(M.setType,pe)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class ge extends fe{component=e.markRaw(N.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class xt extends Y{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(M.setType,ue)}getValue=()=>`[${this.value}]`}class He extends fe{component=e.markRaw(N.NumberInterfaceComponent)}class be extends Y{constructor(t,n){super(t,n),this.use(M.setType,he)}getValue=()=>`"${this.value}"`}class Ue extends be{component=e.markRaw(N.SelectInterfaceComponent);items;constructor(t,n,a){super(t,n),this.items=a}}class Ot extends fe{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 St=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},Mt={style:{position:"relative"}},Vt={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},$t=["placeholder","title"];function Rt(o,t,n,a,s,r){return e.openBlock(),e.createElementBlock("div",Mt,[e.createElementVNode("label",Vt,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,$t),[[e.vModelText,o.v]])])}const Fe=$(St,[["render",Rt]]);class ye extends be{component=e.markRaw(Fe)}class jt extends be{component=e.markRaw(N.TextareaInputInterfaceComponent)}class At extends Y{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(M.setType,me)}getValue=()=>`(${this.value})`}function Gt(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("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("_code",[]).use(M.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 qe extends Z{}function Lt(o){return class extends qe{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("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("_code",[]).use(M.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)||!t.inputs[n])){if(!this.inputs[n]){const a=t.inputs[n],s=a.value;let r;a.component?r=Le(a.component,{...a,id:n}):typeof s=="number"?r=new ge(n,s):r=new ye(n,JSON.stringify(s)),r.use(N.displayInSidebar,!0),r.setOptional(a.optional??!1),r.setHidden(a.hidden??!1),this.addInput(n,r)}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)||!t.outputs[n])){if(!this.outputs[n]){const a=new ze(n);this.addOutput(n,a)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}de(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)})}}}P.escape=o=>o;class te{_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=P.render(this.state.template||"",t??{})}}class Pt extends te{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>Ho))}}class Dt extends te{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>Uo))}}const zt=o=>{o.allowMultipleConnections=!0};class Ye 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 c={};Object.entries(i.inputs).forEach(([f,_])=>{c[f]=this.getInterfaceValue(n,_.id)}),i.isCodeNode&&(i.updateCodeTemplate(),i.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:c,node:i});let p;if(i.calculate){if(p=await i.calculate(c,{globalValues:a,engine:this}),r.has(i))for(const[f,_]of Object.entries(p))this.hooks.transferData.execute(p[f],_),r.get(i).forEach(m=>n.set(m.to.id,_))}else{p={};for(const[f,_]of Object.entries(i.outputs))p[f]=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(f=>{const _=Object.entries(i.outputs).find(([,v])=>v.id===f.from.id)?.[0];if(!_)throw new Error(`Could not find key for interface ${f.from.id}
|
|
1
|
+
(function(d,P){typeof exports=="object"&&typeof module<"u"?P(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"],P):(d=typeof globalThis<"u"?globalThis:d||self,P(d["@babsey/code-graph"]={},d.mustache,d.vue,d.uuid,d["@baklavajs/core"],d["@baklavajs/interface-types"],d["@baklavajs/engine"],d["@baklavajs/renderer-vue"],d.toposort,d["@baklavajs/events"],d["@vueuse/core"]))})(this,(function(d,P,e,F,V,M,D,N,It,Re,vt){"use strict";P.escape=o=>o;class le 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:""}),this.codeTemplate=function(){return`${this.name}(${je(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.getNodesByVariableName(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))}remove(){this.graph?.removeNode(this)}renderCode(t){return P.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}updateInputValues(t){const n=Object.keys(this.inputs);Object.keys(t).forEach(a=>{!n.includes(a)||!this.inputs[a]||(this.inputs[a].value=t[a],this.inputs[a].setHidden(!1))})}}class Z extends le{calculate=(t,n)=>{const a={};return this.lockCode||(a._code=this.renderCode({inputs:t,...n})),this.updateOutputValues(a),a};load(t){super.load(t),de(this.graph,t),this.afterLoaded()}save(){const t=super.save();return Ge(this.graph,t),t}}const je=(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},de=(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.props=t.props),Object.entries(t.inputs).forEach(([s,r])=>{s!=="_code"&&a.inputs[s]&&(a.inputs[s].hidden=r.hidden,a.inputs[s].state.optional=r.optional)}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(a.outputs[s].hidden=r.hidden,a.outputs[s].state.optional=r.optional)})},Ge=(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,a.state.props&&(t.props=a.state.props)),Object.entries(t.inputs).forEach(([s,r])=>{if(s!=="_code"&&a.inputs[s]){const l=a.inputs[s];r.hidden=l.hidden,r.optional=l.state.optional,l.component?.__name&&(r.component=l.component.__name)}}),Object.entries(t.outputs).forEach(([s,r])=>{s!=="_code"&&a.outputs[s]&&(r.hidden=a.outputs[s].hidden)})},Ae=(o,t)=>{switch(o){case"CheckBoxInterface":return new De(t.id,t.value);case"IntegerInterface":return new ge(t.id,t.value,t.min,t.max);case"NumberInterface":return new He(t.id,t.value,t.min,t.max);case"SelectInterface":return new Ue(t.id,t.value,t.items);default:return new ye(t.id,t.value)}},Bt=["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,Bt))}});class R 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 Y extends R{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 ce=new M.NodeInterfaceType("boolean"),Pe=new M.NodeInterfaceType("dict"),ue=new M.NodeInterfaceType("list"),G=new M.NodeInterfaceType("node"),pe=new M.NodeInterfaceType("number"),he=new M.NodeInterfaceType("string"),me=new M.NodeInterfaceType("tuple"),Tt=o=>{new M.BaklavaInterfaceTypes(o.editor,{viewPlugin:o}).addTypes(ce,Pe,ue,G,pe,he,me)};class De extends Y{constructor(t,n){super(t,n),this.setComponent(e.markRaw(N.CheckboxInterfaceComponent)),this.use(M.setType,ce)}getValue=()=>this.value?"True":"False"}class ze extends R{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 fe extends Y{min;max;constructor(t,n,a,s){super(t,n),this.min=a,this.max=s,this.use(M.setType,pe)}validate(t){return(this.min===void 0||t>=this.min)&&(this.max===void 0||t<=this.max)}}class ge extends fe{component=e.markRaw(N.IntegerInterfaceComponent);validate(t){return Number.isInteger(t)&&super.validate(t)}}class xt extends Y{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(M.setType,ue)}getValue=()=>`[${this.value}]`}class He extends fe{component=e.markRaw(N.NumberInterfaceComponent)}class be extends Y{constructor(t,n){super(t,n),this.use(M.setType,he)}getValue=()=>`"${this.value}"`}class Ue extends be{component=e.markRaw(N.SelectInterfaceComponent);items;constructor(t,n,a){super(t,n),this.items=a}}class Ot extends fe{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 St=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},Mt={style:{position:"relative"}},Vt={style:{"font-size":"12px",padding:"0 6px",position:"absolute",top:"-8px","background-color":"var(--baklava-node-color-background)"}},$t=["placeholder","title"];function Lt(o,t,n,a,s,r){return e.openBlock(),e.createElementBlock("div",Mt,[e.createElementVNode("label",Vt,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,$t),[[e.vModelText,o.v]])])}const Fe=$(St,[["render",Lt]]);class ye extends be{component=e.markRaw(Fe)}class Rt extends be{component=e.markRaw(N.TextareaInputInterfaceComponent)}class jt extends Y{constructor(t="",n=""){super(t,n),this.setComponent(e.markRaw(N.TextInputInterfaceComponent)),this.use(M.setType,me)}getValue=()=>`(${this.value})`}function Gt(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 R("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new R("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0))}afterGraphLoaded(){o.afterGraphLoaded?.call(this)}afterLoaded(){o.afterLoaded?.call(this)}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 qe extends Z{}function At(o){return class extends qe{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 R("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new R("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.staticInputKeys.push("_code"),this.staticOutputKeys.push("_code")}afterGraphLoaded(){o.afterGraphLoaded?.call(this)}afterLoaded(){o.afterLoaded?.call(this)}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)||!t.inputs[n])){if(!this.inputs[n]){const a=t.inputs[n],s=a.value;let r;a.component?r=Ae(a.component,{...a,id:n}):typeof s=="number"?r=new ge(n,s):r=new ye(n,JSON.stringify(s)),r.use(N.displayInSidebar,!0),r.setOptional(a.optional??!1),r.setHidden(a.hidden??!1),this.addInput(n,r)}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)||!t.outputs[n])){if(!this.outputs[n]){const a=new ze(n);this.addOutput(n,a)}this.outputs[n]&&(this.outputs[n].load(t.outputs[n]),this.outputs[n].nodeId=this.id)}de(this.graph,t),this.preventUpdate=!1,this.events.loaded.emit(this)}onUpdate(){if(!o.onUpdate||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}updateInputInterfaces(t,n){this.updateInterfaces("input",t,n)}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)})}}}P.escape=o=>o;class te{_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=P.render(this.state.template||"",t??{})}}class Pt extends te{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>Ho))}}class Dt extends te{constructor(){super(),this.loadTemplate(Promise.resolve().then(()=>Uo))}}const zt=o=>{o.allowMultipleConnections=!0};class Ye 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 c={};Object.entries(i.inputs).forEach(([f,_])=>{c[f]=this.getInterfaceValue(n,_.id)}),i.isCodeNode&&(i.updateCodeTemplate(),i.updateOutputNames()),this.events.beforeNodeCalculation.emit({inputValues:c,node:i});let p;if(i.calculate){if(p=await i.calculate(c,{globalValues:a,engine:this}),r.has(i))for(const[f,_]of Object.entries(p))this.hooks.transferData.execute(p[f],_),r.get(i).forEach(m=>n.set(m.to.id,_))}else{p={};for(const[f,_]of Object.entries(i.outputs))p[f]=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(f=>{const _=Object.entries(i.outputs).find(([,v])=>v.id===f.from.id)?.[0];if(!_)throw new Error(`Could not find key for interface ${f.from.id}
|
|
2
2
|
This is likely an internal issue. Please report it on GitHub.`);const m=this.hooks.transferData.execute(p[_],f);_!=="_code"&&(f.to.allowMultipleConnections?n.has(f.to.id)?n.get(f.to.id).push(m):n.set(f.to.id,[m]):n.set(f.to.id,m))})}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}
|
|
3
|
-
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 We=$(Ht,[["render",Ft]]),qt={},Yt={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",Yt,[...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 Ke=$(qt,[["render",Wt]]),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 Xe=$(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 Je=$(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 Qe=$(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 Ze=$(sn,[["render",rn]]),ln={},dn={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",dn,[...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 et=$(ln,[["render",cn]]),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 tt=$(un,[["render",hn]]),mn={},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 gn(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 nt=$(mn,[["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 ke=$(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 ot=$(_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 st=$(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 at=$(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 rt=$(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 it=$(Mn,[["render",$n]]),Rn={},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 An(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 lt=$(Rn,[["render",An]]),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 Pn(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 dt=$(Gn,[["render",Pn]]),_e="CLEAR_ALL",Ce="RUN_ENGINE",Ne="TOGGLE_MINIMAP",we="TOGGLE_PALETTE",ct=(o,t,n)=>{const a=n.zoomToFit.paddingLeft;t.registerCommand(we,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?a:50},canExecute:()=>!0}),t.registerCommand(_e,{execute:()=>{t.executeCommand(N.Commands.CLEAR_CLIPBOARD_COMMAND),t.executeCommand(N.Commands.CLEAR_HISTORY_COMMAND),o.value.clear(),o.value.editor.code.clear()},canExecute:()=>o.value.nodes.length>0}),t.registerCommand(Ne,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},ut=o=>{const t={command:Ce,title:"Run",icon:e.computed(()=>ot)},n={command:we,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Qe:Ze)},a={command:_e,title:"Clear all",icon:e.computed(()=>lt)},s={command:Ne,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?rt:at)};o.toolbar.commands=[n,t,...N.DEFAULT_TOOLBAR_COMMANDS,a,s]},pt=(o,t,n)=>{n.registerCommand(Ce,{execute:()=>t.runOnce(null),canExecute:()=>o.nodes.length>0})};function ht(o){const t=Symbol("CodeEngineToken");o.engine=new Ye(o.editor),pt(o.editor.graph,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 Ee(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&&t?.name!=="_code"&&(t.hidden=!1),n&&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 P.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=It.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 Ee=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...Ee(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},Ie="__baklava_SubgraphInputNode",ve="__baklava_SubgraphOutputNode";class mt 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 Be extends mt{static isGraphInputNode(t){return t.type===Ie}type=Ie;inputs={name:new V.NodeInterface("Name","Input")};outputs={placeholder:new V.NodeInterface("Value",void 0)}}class Te extends mt{static isGraphOutputNode(t){return t.type===ve}type=ve;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 Hn=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function ft(o){return class extends le{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}):P.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("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new j("_code",[]).use(M.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(Hn.includes(l)||l in r||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(r,l);let i;a?i=this.subgraph?.nodes.find(_=>Be.isGraphInputNode(_)&&_.graphInterfaceId===n.id)?.outputs.placeholder.id:i=this.subgraph?.nodes.find(_=>Te.isGraphOutputNode(_)&&_.graphInterfaceId===n.id)?.inputs.placeholder.id;const c=this.subgraph?.connections.find(f=>i===(a?f.from:f.to)?.id),p=a?c?.to:c?.from;if(p)return Reflect.get(p,l)}})}}}function Un(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function Fn(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=m=>{const v=F.v4();return n.set(m,v),v},s=m=>{const v=n.get(m);if(!v)throw new Error(`Unable to create graph from template: Could not map old id ${m} to new id`);return v},r=m=>Fn(m,v=>({id:a(v.id),templateId:v.id,value:v.value})),l=this.nodes.map(m=>({...m,id:a(m.id),inputs:r(m.inputs),outputs:r(m.outputs)})),i=this.connections.map(m=>({id:a(m.id),from:s(m.from),to:s(m.to)})),c=this.inputs.map(m=>({id:m.id,name:m.name,nodeId:s(m.nodeId),nodeInterfaceId:s(m.nodeInterfaceId)})),p=this.outputs.map(m=>({id:m.id,name:m.name,nodeId:s(m.nodeId),nodeInterfaceId:s(m.nodeInterfaceId)})),f={id:F.v4(),nodes:l,connections:i,inputs:c,outputs:p};return t||(t=new K(this.editor)),t.load(f).forEach(m=>console.warn(m)),t.template=this,t}}const qn=o=>!(o instanceof K);function gt(o,t){return{switchGraph:a=>{let s;if(qn(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 Yn(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var ne={exports:{}};var Wn=ne.exports,bt;function Kn(){return bt||(bt=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 c=i(279),p=i.n(c),f=i(370),_=i.n(f),m=i(817),v=i.n(m);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},S=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 S(L,{container:I});if(B)return E==="cut"?u(B):S(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 R(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 A(b,h,k){return h&&R(b.prototype,h),k&&R(b,k),b}function oe(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 $e(b){var h=Re();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 se(this,I)}}function se(b,h){return h&&(z(h)==="object"||typeof h=="function")?h:ae(b)}function ae(b){if(b===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return b}function Re(){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 W(b,h){var k="data-clipboard-".concat(b);if(h.hasAttribute(k))return h.getAttribute(k)}var re=(function(b){oe(k,b);var h=$e(k);function k(E,I){var B;return w(this,k),B=h.call(this),B.resolveOptions(I),B.listenClick(E),B}return A(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",ie=J({action:L,container:this.container,target:this.target(B),text:this.text(B)});this.emit(ie?"success":"error",{action:L,text:ie,trigger:B,clearSelection:function(){B&&B.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(I){return W("action",I)}},{key:"defaultTarget",value:function(I){var B=W("target",I);if(B)return document.querySelector(B)}},{key:"defaultText",value:function(I){return W("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 S(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(ie){L=L&&!!document.queryCommandSupported(ie)}),L}}]),k})(p()),x=re}),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 c(p,f){for(;p&&p.nodeType!==l;){if(typeof p.matches=="function"&&p.matches(f))return p;p=p.parentNode}}r.exports=c}),438:(function(r,l,i){var c=i(828);function p(m,v,g,C,u){var y=_.apply(this,arguments);return m.addEventListener(g,y,u),{destroy:function(){m.removeEventListener(g,y,u)}}}function f(m,v,g,C,u){return typeof m.addEventListener=="function"?p.apply(null,arguments):typeof g=="function"?p.bind(null,document).apply(null,arguments):(typeof m=="string"&&(m=document.querySelectorAll(m)),Array.prototype.map.call(m,function(y){return p(y,v,g,C,u)}))}function _(m,v,g,C){return function(u){u.delegateTarget=c(u.target,v),u.delegateTarget&&C.call(m,u)}}r.exports=f}),879:(function(r,l){l.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},l.nodeList=function(i){var c=Object.prototype.toString.call(i);return i!==void 0&&(c==="[object NodeList]"||c==="[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 c=Object.prototype.toString.call(i);return c==="[object Function]"}}),370:(function(r,l,i){var c=i(879),p=i(438);function f(g,C,u){if(!g&&!C&&!u)throw new Error("Missing required arguments");if(!c.string(C))throw new TypeError("Second argument must be a String");if(!c.fn(u))throw new TypeError("Third argument must be a Function");if(c.node(g))return _(g,C,u);if(c.nodeList(g))return m(g,C,u);if(c.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 m(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=f}),817:(function(r){function l(i){var c;if(i.nodeName==="SELECT")i.focus(),c=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"),c=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var f=window.getSelection(),_=document.createRange();_.selectNodeContents(i),f.removeAllRanges(),f.addRange(_),c=f.toString()}return c}r.exports=l}),279:(function(r){function l(){}l.prototype={on:function(i,c,p){var f=this.e||(this.e={});return(f[i]||(f[i]=[])).push({fn:c,ctx:p}),this},once:function(i,c,p){var f=this;function _(){f.off(i,_),c.apply(p,arguments)}return _._=c,this.on(i,_,p)},emit:function(i){var c=[].slice.call(arguments,1),p=((this.e||(this.e={}))[i]||[]).slice(),f=0,_=p.length;for(f;f<_;f++)p[f].fn.apply(p[f].ctx,c);return this},off:function(i,c){var p=this.e||(this.e={}),f=p[i],_=[];if(f&&c)for(var m=0,v=f.length;m<v;m++)f[m].fn!==c&&f[m].fn._!==c&&_.push(f[m]);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})})(ne)),ne.exports}var Xn=Kn();const Jn=Yn(Xn),Qn=o=>({toClipboard(t,n){return new Promise((a,s)=>{const r=document.createElement("button"),l=new Jn(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)})}}),Zn={key:0,class:"baklava-button"},yt=e.defineComponent({__name:"CopyToClipboard",props:{text:String},setup(o){const{toClipboard:t}=Qn(),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",Zn,[e.createVNode(e.unref(We))])):(e.openBlock(),e.createElementBlock("button",{key:1,onClick:r,class:"baklava-button"},[e.createVNode(e.unref(Xe))]))]))}}),eo={class:"code-editor"},to={class:"code-buttons"},no=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",eo,[e.createElementVNode("div",to,[o.locked?(e.openBlock(),e.createElementBlock("button",{key:0,class:"baklava-button",title:"The code is locked.",onClick:l[0]||(l[0]=c=>s(!1))},[e.createVNode(e.unref(ke))])):e.createCommentVNode("",!0),e.createVNode(yt,{text:o.modelValue},null,8,["text"])]),e.createVNode(i,{modelValue:n.value,"onUpdate:modelValue":l[1]||(l[1]=c=>n.value=c),extensions:o.extensions,class:"codemirror",style:{height:"100%"},onKeydown:l[2]||(l[2]=c=>s(!0))},null,8,["modelValue","extensions"])])}}}),oo=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.onMounted),e.onBeforeUnmount(n.value.onBeforeUnmount),e.watch(n,(s,r)=>{r&&r.onBeforeUnmount(),s&&s.onMounted()}),(s,r)=>(e.openBlock(),e.createBlock(e.unref(N.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Ct))]),node:e.withCtx(l=>[e.createVNode(e.unref(kt),e.mergeProps(l,{onUpdate:i=>a(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(_t),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:i})=>[e.renderSlot(s.$slots,"sidebarCodeEditor",{node:i})]),_:3},16)]),_:3},8,["view-model"]))}}),so={class:"code-graph-info"},ao=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",so,[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)]))}}),ro=["data-node-type","id"],io={class:"__title-label",style:{"flex-grow":"1"}},lo={key:0},co={class:"__menu",style:{display:"flex"}},uo={class:"__outputs"},po={key:0},ho=["id","title"],mo={class:"__inputs"},fo={key:0},go=["id","title"],kt=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:c,switchGraph:p}=N.useGraph(),f=e.ref(null),_=e.ref(!1),m=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})),S=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)},R=()=>{y.value=!0},A=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId="",x.visible=!1},oe=()=>{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},$e=async x=>{switch(x){case"edit":oe();break;case"delete":c.value.removeNode(s.node);break;case"rename":m.value=s.node.title,_.value=!0,await e.nextTick(),v.value?.focus();break;case"editSubgraph":p(s.node.template);break}},se=()=>{r.value.title=m.value,_.value=!1},ae=()=>{f.value&&i.value.hooks.renderNode.execute({node:s.node,el:f.value})},Re=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"))},W=x=>{if(!g.value)return;const b=x.clientX-u,h=C+b/c.value.scaling,k=i.value.settings.nodes.minWidth,E=i.value.settings.nodes.maxWidth;r.value.width=Math.max(k,Math.min(E,h))},re=()=>{g.value=!1};return e.onMounted(()=>{ae(),window.addEventListener("mousemove",W),window.addEventListener("mouseup",re)}),e.onUpdated(ae),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",W),window.removeEventListener("mouseup",re)}),(x,b)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([T.value,"baklava-node"]),"data-node-type":r.value.type,id:r.value.id,style:e.normalizeStyle(H.value),ref_key:"el",ref:f,onPointerdown:z},[e.unref(i).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Re},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(w,["self","stop"]),onContextmenu:e.withModifiers(R,["prevent"])},[r.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(xe),{key:0,intf:r.value.inputs._code,node:r.value,title:r.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["intf","node","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=>m.value=h),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:se,onKeydown:e.withKeys(se,["enter"])},null,544)),[[e.vModelText,m.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",io,[r.value.idx>-1?(e.openBlock(),e.createElementBlock("span",lo,e.toDisplayString(r.value.idx+1)+" > ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(r.value.title),1)]),e.createElementVNode("div",co,[r.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[r.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(ke),{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(Ke),{key:1,class:"--clickable mx-1",onClick:b[1]||(b[1]=h=>q(!1))})):(e.openBlock(),e.createBlock(e.unref(it),{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(nt),{key:3,class:"--clickable mx-1",onClick:oe})):e.unref(i).displayedGraph.sidebar.visible&&e.unref(i).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(et),{key:4,class:"--clickable mx-1",onClick:Q})):(e.openBlock(),e.createBlock(e.unref(tt),{key:5,class:"--clickable mx-1",onClick:A}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Je),{class:"--clickable mx-1",onClick:R}),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:$e},null,8,["modelValue","items"])])],64)),r.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(xe),{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",S.value]),onKeydown:b[5]||(b[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:b[6]||(b[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",uo,[(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",po,[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,ho)):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",mo,[(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,go)):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,ro))}}),bo=["id"],yo={class:"align-middle"},xe=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})),c=()=>{a(t.intf)},p=()=>{a(void 0)},f=()=>{r.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:r.value})};return e.onMounted(f),e.onUpdated(f),(_,m)=>(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([{"--selected":e.unref(s)?.from===o.intf},"__port"]),onPointerover:c,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",yo,[e.renderSlot(_.$slots,"default")])],10,bo))}}),ko=["title"],_o={key:0,class:"__label"},Oe=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",_o,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,ko))}}),Co={class:"__header"},No={class:"__node-name"},wo={class:"__interfaces"},Eo={class:"__inputs"},Io={style:{display:"flex"}},vo={class:"__outputs"},Bo={key:0,class:"__interface"},To={style:{display:"flex"}},_t=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 c=e.computed(()=>{const y=n.value.sidebar.nodeId;return n.value.nodes.find(O=>O.id===y)}),p=e.computed(()=>c.value),f=e.computed(()=>({width:`${s.value}px`})),_=e.computed(()=>p.value?Object.values(p.value.inputs).filter(y=>y.displayInSidebar&&y.component):[]),m=e.computed(()=>p.value?Object.values(p.value.outputs).filter(y=>y.displayInSidebar&&y.component):[]),v=()=>{n.value.sidebar.visible=!1},g=()=>{c.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 S=l-T;S<300?S=300:S>.9*O&&(S=.9*O),s.value=S};return(y,O)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(f.value),ref_key:"el",ref:a},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:C},null,32)):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Co,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:v},"×"),e.createElementVNode("div",No,[e.createElementVNode("b",null,e.toDisplayString(c.value.title),1)])]),e.createElementVNode("div",wo,[e.createElementVNode("div",Eo,[(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",Io,[e.createVNode(Oe,{modelValue:T.hidden,"onUpdate:modelValue":[S=>T.hidden=S,O[0]||(O[0]=()=>c.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":S=>T.value=S,node:c.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",vo,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",Bo,[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(m.value,T=>(e.openBlock(),e.createElementBlock("div",{key:T.id,class:"__interface"},[e.createElementVNode("div",To,[e.createVNode(Oe,{modelValue:T.hidden,"onUpdate:modelValue":[S=>T.hidden=S,O[2]||(O[2]=()=>c.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":S=>T.value=S,node:c.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(y.$slots,"codeEditor",{node:c.value})],64)):e.createCommentVNode("",!0)],6))}}),xo={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Oo={key:0,style:{display:"flex","justify-content":"space-between"}},So=["onClick"],Mo={key:0,style:{margin:"auto 0","font-size":"12px"}},Ct=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=N.Components.PaletteEntry,{viewModel:n}=N.useViewModel(),{x:a,y:s}=vt.usePointer(),{transform:r}=N.useTransform(),l=N.useNodeCategories(n),i=e.inject("editorEl"),c=e.ref(""),p=e.ref(null),f=()=>c.value?l.value.filter(g=>g.name.toLowerCase().includes(c.value.toLowerCase())||Object.values(g.nodeTypes).some(C=>C.title.toLowerCase().includes(c.value.toLowerCase()))):l.value,_=g=>c.value?Un(g,C=>{const u=C[1];return u.category.includes(c.value.toLowerCase())||u.title?.toLowerCase().includes(c.value.toLowerCase())}):g,m=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,S]=r(a.value-O.left,s.value-O.top);y.position.x=T,y.position.y=S,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",xo,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[0]||(C[0]=u=>c.value=u),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:f},null,544),[[e.vModelText,c.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f(),u=>(e.openBlock(),e.createElementBlock("section",{key:u.name},[u.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Oo,[e.createElementVNode("div",{onClick:y=>c.value=u.name,style:{cursor:"pointer"}},e.toDisplayString(u.name),9,So),Object.keys(_(u.nodeTypes)).length<Object.values(u.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Mo," ( "+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,title:y.title,type:O,onPointerdown:T=>v(O,y)},null,8,["title","type","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(m.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))}}),Vo={},$o={class:"prependIcon"},Ro={class:"appendIcon"};function jo(o,t){const n=e.resolveComponent("router-link");return e.openBlock(),e.createBlock(n,{class:"navItem"},{default:e.withCtx(()=>[e.createElementVNode("span",$o,[e.renderSlot(o.$slots,"prependIcon")]),e.renderSlot(o.$slots,"default"),e.createElementVNode("span",Ro,[e.renderSlot(o.$slots,"appendIcon")])]),_:3})}const Se=$(Vo,[["render",jo]]),Ao={class:"navbar"},Go=["onClick"],Lo=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",Ao,[e.renderSlot(s.$slots,"prepend"),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.editorStates,l=>(e.openBlock(),e.createBlock(Se,{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(dt))],8,Go)]),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(Se,{to:{name:o.routes?.new??"new"},class:"navItem"},{default:e.withCtx(()=>[e.createVNode(e.unref(st),{class:"plus"})]),_:1},8,["to"])])]))}});class Me extends Be{_title="Subgraph Input";inputs={_code:new j("_code","").use(M.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new j("_code","").use(M.setType,G).setHidden(!0),placeholder:new V.NodeInterface("Connection",void 0)}}class Ve extends Te{_title="Subgraph Output";inputs={_code:new j("_code","").use(M.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Output").setPort(!1),placeholder:new V.NodeInterface("Connection",void 0)};outputs={_code:new j("_code","").use(M.setType,G).setHidden(!0),output:new V.NodeInterface("Output",void 0).setHidden(!0)}}const Nt="CREATE_SUBGRAPH",wt=[V.GRAPH_INPUT_NODE_TYPE,V.GRAPH_OUTPUT_NODE_TYPE];function Et(o,t,n){const a=()=>o.value.selectedNodes.filter(r=>!wt.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 c=l.selectedNodes.filter(w=>!wt.includes(w.type)),p=c.flatMap(w=>Object.values(w.inputs)),f=c.flatMap(w=>Object.values(w.outputs)),_=l.connections.filter(w=>!f.includes(w.from)&&p.includes(w.to)),m=l.connections.filter(w=>f.includes(w.from)&&!p.includes(w.to)),v=l.connections.filter(w=>f.includes(w.from)&&p.includes(w.to)),g=c.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}=Po(c);for(const[w,R]of _.entries()){const A=new Me;A.inputs.name.value=R.to.name,g.push({...A.save(),position:{x:O-r.value.settings.nodes.defaultWidth-100,y:T+w*200}}),C.push({id:F.v4(),from:A.outputs.placeholder.id,to:R.to.id}),u.set(R.to.id,A.graphInterfaceId)}for(const[w,R]of m.entries()){const A=new Ve;A.inputs.name.value=R.from.name,g.push({...A.save(),position:{x:y+100,y:T+w*200}}),C.push({id:F.v4(),from:R.from.id,to:A.inputs.placeholder.id}),u.set(R.from.id,A.graphInterfaceId)}const S=e.reactive(new X({connections:C,nodes:g,inputs:[],outputs:[]},i));i.addGraphTemplate(S);const H=i.nodeTypes.get(V.getGraphNodeTypeString(S));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(c.map(w=>w.position.x).reduce((w,R)=>w+R,0)/c.length),z=Math.round(c.map(w=>w.position.y).reduce((w,R)=>w+R,0)/c.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)])}),m.forEach(w=>{l.removeConnection(w),l.addConnection(U.outputs[u.get(w.from.id)],w.to)}),c.forEach(w=>l.removeNode(w)),l.activeTransactions--,t.canExecuteCommand(N.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(N.Commands.SAVE_SUBGRAPH_COMMAND),n(S),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(Nt,{canExecute:a,execute:s})}function Po(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 Do 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=ft(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 zo(o){const t=e.ref(o?.code??new te),n=e.ref(o?.existingEditor??new Do(t.value)),a=Symbol("ViewModelToken"),s=e.ref(null),r=e.shallowReadonly(s),{switchGraph:l}=gt(n,s),i=e.computed(()=>r.value&&r.value!==n.value.graph),c=e.reactive(N.DEFAULT_SETTINGS());c.nodes.defaultWidth=400;const p=N.useCommandHandler(),f=N.useHistory(r,p),_=N.useClipboard(r,n,p),m={renderNode:new je.SequentialHook(null),renderInterface:new je.SequentialHook(null)},v=e.reactive({clipboard:_,code:t,commandHandler:p,displayedGraph:r,editor:n,history:f,hooks:m,isSubgraph:i,onBeforeUnmount:()=>{},onMounted:()=>{},settings:c,switchGraph:l});return t.value.registerViewModel(v),ht(v),N.registerDeleteNodesCommand(r,p),Et(r,p,l),N.registerSaveSubgraphCommand(r,p),N.registerSwitchToMainGraphCommand(r,p,l),N.registerSidebarCommands(r,p),N.registerZoomToFitCommands(r,p,c),ct(r,p,c),ut(c),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??c.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:c.nodes.defaultWidth})),n.value.registerNodeType(Me,{category:"Subgraphs"}),n.value.registerNodeType(Ve,{category:"Subgraphs"}),l(g.graph))},{immediate:!0}),v}const Ho=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 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 We=$(Ht,[["render",Ft]]),qt={},Yt={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",Yt,[...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 Xe=$(qt,[["render",Wt]]),Xt={},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 Jt(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 Ke=$(Xt,[["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 Je=$(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 Qe=$(tn,[["render",on]]),an={},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 rn(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 Ze=$(an,[["render",rn]]),ln={},dn={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",dn,[...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 et=$(ln,[["render",cn]]),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 tt=$(un,[["render",hn]]),mn={},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 gn(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 nt=$(mn,[["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 ke=$(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 ot=$(_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 at=$(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 st=$(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 rt=$(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 it=$(Mn,[["render",$n]]),Ln={},Rn={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",Rn,[...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 lt=$(Ln,[["render",jn]]),Gn={},An={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 Pn(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 6l-12 12"},null,-1),e.createElementVNode("path",{d:"M6 6l12 12"},null,-1)])])}const dt=$(Gn,[["render",Pn]]),_e="CLEAR_ALL",Ce="RUN_ENGINE",Ne="TOGGLE_MINIMAP",we="TOGGLE_PALETTE",ct=(o,t,n)=>{const a=n.zoomToFit.paddingLeft;t.registerCommand(we,{execute:()=>{n.palette.enabled=!n.palette.enabled,n.zoomToFit.paddingLeft=n.palette.enabled?a:50},canExecute:()=>!0}),t.registerCommand(_e,{execute:()=>{t.executeCommand(N.Commands.CLEAR_CLIPBOARD_COMMAND),t.executeCommand(N.Commands.CLEAR_HISTORY_COMMAND),o.value.clear(),o.value.editor.code.clear()},canExecute:()=>o.value.nodes.length>0}),t.registerCommand(Ne,{execute:()=>n.enableMinimap=!n.enableMinimap,canExecute:()=>o.value.nodes.length>1})},ut=o=>{const t={command:Ce,title:"Run",icon:e.computed(()=>ot)},n={command:we,title:"Toggle palette",icon:e.computed(()=>o.palette.enabled?Qe:Ze)},a={command:_e,title:"Clear all",icon:e.computed(()=>lt)},s={command:Ne,title:"Toggle minimap",icon:e.computed(()=>o.enableMinimap?rt:st)};o.toolbar.commands=[n,t,...N.DEFAULT_TOOLBAR_COMMANDS,a,s]},pt=(o,t,n)=>{n.registerCommand(Ce,{execute:()=>t.runOnce(null),canExecute:()=>o.nodes.length>0})};function ht(o){const t=Symbol("CodeEngineToken");o.engine=new Ye(o.editor),pt(o.editor.graph,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 X 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 Ee(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&&t?.name!=="_code"&&(t.hidden=!1),n&&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)}getNodesByType(t){return this.nodes.filter(n=>n.type===t)}getNodesByVariableName(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)}load(t){const n=super.load(t);return this.nodes.forEach(a=>a.afterGraphLoaded()),n}renderCode(t){return P.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=It.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 Ee=o=>{const t=[];return o.nodes.length===0||o.nodes.forEach(n=>{n&&(n.hasOwnProperty("subgraph")?t.push(...Ee(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},Ie="__baklava_SubgraphInputNode",ve="__baklava_SubgraphOutputNode";class mt 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 Be extends mt{static isGraphInputNode(t){return t.type===Ie}type=Ie;inputs={name:new V.NodeInterface("Name","Input")};outputs={placeholder:new V.NodeInterface("Value",void 0)}}class Te extends mt{static isGraphOutputNode(t){return t.type===ve}type=ve;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 Hn=["component","connectionCount","events","hidden","hooks","id","isCodeNode","isInput","name","nodeId","port","templateId","value"];function ft(o){return class extends le{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}):P.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 R("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_code",new R("_code",[]).use(M.setType,G).use(D.allowMultipleConnections).setHidden(!0)),this.addOutput("_calculationResults",new V.NodeInterface("_calculationResults",void 0).setHidden(!0))}createProxyInterface(n,a){const s=new R(n.name,void 0);return new Proxy(s,{get:(r,l)=>{if(Hn.includes(l)||l in r||typeof l=="string"&&l.startsWith("__v_"))return Reflect.get(r,l);let i;a?i=this.subgraph?.nodes.find(_=>Be.isGraphInputNode(_)&&_.graphInterfaceId===n.id)?.outputs.placeholder.id:i=this.subgraph?.nodes.find(_=>Te.isGraphOutputNode(_)&&_.graphInterfaceId===n.id)?.inputs.placeholder.id;const c=this.subgraph?.connections.find(f=>i===(a?f.from:f.to)?.id),p=a?c?.to:c?.from;if(p)return Reflect.get(p,l)}})}}}function Un(o,t){return Object.fromEntries(Object.entries(o).filter(t))}function Fn(o,t){return Object.fromEntries(Object.entries(o).map(([n,a])=>[n,t(a)]))}class K extends V.GraphTemplate{static fromGraph(t,n){return new K(t.save(),n)}constructor(t,n){super(t,n)}get shortId(){return this.id.slice(0,6)}createGraph(t){const n=new Map,a=m=>{const v=F.v4();return n.set(m,v),v},s=m=>{const v=n.get(m);if(!v)throw new Error(`Unable to create graph from template: Could not map old id ${m} to new id`);return v},r=m=>Fn(m,v=>({id:a(v.id),templateId:v.id,value:v.value})),l=this.nodes.map(m=>({...m,id:a(m.id),inputs:r(m.inputs),outputs:r(m.outputs)})),i=this.connections.map(m=>({id:a(m.id),from:s(m.from),to:s(m.to)})),c=this.inputs.map(m=>({id:m.id,name:m.name,nodeId:s(m.nodeId),nodeInterfaceId:s(m.nodeInterfaceId)})),p=this.outputs.map(m=>({id:m.id,name:m.name,nodeId:s(m.nodeId),nodeInterfaceId:s(m.nodeInterfaceId)})),f={id:F.v4(),nodes:l,connections:i,inputs:c,outputs:p};return t||(t=new X(this.editor)),t.load(f).forEach(m=>console.warn(m)),t.template=this,t}}const qn=o=>!(o instanceof X);function gt(o,t){return{switchGraph:a=>{let s;if(qn(a))s=new X(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 Yn(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var ne={exports:{}};var Wn=ne.exports,bt;function Xn(){return bt||(bt=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 c=i(279),p=i.n(c),f=i(370),_=i.n(f),m=i(817),v=i.n(m);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},S=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,A=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(A)return S(A,{container:I});if(B)return E==="cut"?u(B):S(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 L(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 j(b,h,k){return h&&L(b.prototype,h),k&&L(b,k),b}function oe(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 $e(b){var h=Le();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 ae(this,I)}}function ae(b,h){return h&&(z(h)==="object"||typeof h=="function")?h:se(b)}function se(b){if(b===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return b}function Le(){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 W(b,h){var k="data-clipboard-".concat(b);if(h.hasAttribute(k))return h.getAttribute(k)}var re=(function(b){oe(k,b);var h=$e(k);function k(E,I){var B;return w(this,k),B=h.call(this),B.resolveOptions(I),B.listenClick(E),B}return j(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(A){return B.onClick(A)})}},{key:"onClick",value:function(I){var B=I.delegateTarget||I.currentTarget,A=this.action(B)||"copy",ie=J({action:A,container:this.container,target:this.target(B),text:this.text(B)});this.emit(ie?"success":"error",{action:A,text:ie,trigger:B,clearSelection:function(){B&&B.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(I){return W("action",I)}},{key:"defaultTarget",value:function(I){var B=W("target",I);if(B)return document.querySelector(B)}},{key:"defaultText",value:function(I){return W("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 S(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,A=!!document.queryCommandSupported;return B.forEach(function(ie){A=A&&!!document.queryCommandSupported(ie)}),A}}]),k})(p()),x=re}),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 c(p,f){for(;p&&p.nodeType!==l;){if(typeof p.matches=="function"&&p.matches(f))return p;p=p.parentNode}}r.exports=c}),438:(function(r,l,i){var c=i(828);function p(m,v,g,C,u){var y=_.apply(this,arguments);return m.addEventListener(g,y,u),{destroy:function(){m.removeEventListener(g,y,u)}}}function f(m,v,g,C,u){return typeof m.addEventListener=="function"?p.apply(null,arguments):typeof g=="function"?p.bind(null,document).apply(null,arguments):(typeof m=="string"&&(m=document.querySelectorAll(m)),Array.prototype.map.call(m,function(y){return p(y,v,g,C,u)}))}function _(m,v,g,C){return function(u){u.delegateTarget=c(u.target,v),u.delegateTarget&&C.call(m,u)}}r.exports=f}),879:(function(r,l){l.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},l.nodeList=function(i){var c=Object.prototype.toString.call(i);return i!==void 0&&(c==="[object NodeList]"||c==="[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 c=Object.prototype.toString.call(i);return c==="[object Function]"}}),370:(function(r,l,i){var c=i(879),p=i(438);function f(g,C,u){if(!g&&!C&&!u)throw new Error("Missing required arguments");if(!c.string(C))throw new TypeError("Second argument must be a String");if(!c.fn(u))throw new TypeError("Third argument must be a Function");if(c.node(g))return _(g,C,u);if(c.nodeList(g))return m(g,C,u);if(c.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 m(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=f}),817:(function(r){function l(i){var c;if(i.nodeName==="SELECT")i.focus(),c=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"),c=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var f=window.getSelection(),_=document.createRange();_.selectNodeContents(i),f.removeAllRanges(),f.addRange(_),c=f.toString()}return c}r.exports=l}),279:(function(r){function l(){}l.prototype={on:function(i,c,p){var f=this.e||(this.e={});return(f[i]||(f[i]=[])).push({fn:c,ctx:p}),this},once:function(i,c,p){var f=this;function _(){f.off(i,_),c.apply(p,arguments)}return _._=c,this.on(i,_,p)},emit:function(i){var c=[].slice.call(arguments,1),p=((this.e||(this.e={}))[i]||[]).slice(),f=0,_=p.length;for(f;f<_;f++)p[f].fn.apply(p[f].ctx,c);return this},off:function(i,c){var p=this.e||(this.e={}),f=p[i],_=[];if(f&&c)for(var m=0,v=f.length;m<v;m++)f[m].fn!==c&&f[m].fn._!==c&&_.push(f[m]);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})})(ne)),ne.exports}var Kn=Xn();const Jn=Yn(Kn),Qn=o=>({toClipboard(t,n){return new Promise((a,s)=>{const r=document.createElement("button"),l=new Jn(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)})}}),Zn={key:0,class:"baklava-button"},yt=e.defineComponent({__name:"CopyToClipboard",props:{text:String},setup(o){const{toClipboard:t}=Qn(),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",Zn,[e.createVNode(e.unref(We))])):(e.openBlock(),e.createElementBlock("button",{key:1,onClick:r,class:"baklava-button"},[e.createVNode(e.unref(Ke))]))]))}}),eo={class:"code-editor"},to={class:"code-buttons"},no=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",eo,[e.createElementVNode("div",to,[o.locked?(e.openBlock(),e.createElementBlock("button",{key:0,class:"baklava-button",title:"The code is locked.",onClick:l[0]||(l[0]=c=>s(!1))},[e.createVNode(e.unref(ke))])):e.createCommentVNode("",!0),e.createVNode(yt,{text:o.modelValue},null,8,["text"])]),e.createVNode(i,{modelValue:n.value,"onUpdate:modelValue":l[1]||(l[1]=c=>n.value=c),extensions:o.extensions,class:"codemirror",style:{height:"100%"},onKeydown:l[2]||(l[2]=c=>s(!0))},null,8,["modelValue","extensions"])])}}}),oo=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.onMounted),e.onBeforeUnmount(n.value.onBeforeUnmount),e.watch(n,(s,r)=>{r&&r.onBeforeUnmount(),s&&s.onMounted()}),(s,r)=>(e.openBlock(),e.createBlock(e.unref(N.BaklavaEditor),{"view-model":n.value},{palette:e.withCtx(()=>[e.createVNode(e.unref(Ct))]),node:e.withCtx(l=>[e.createVNode(e.unref(kt),e.mergeProps(l,{onUpdate:i=>a(l.node)}),null,16,["onUpdate"])]),sidebar:e.withCtx(l=>[e.createVNode(e.unref(_t),e.normalizeProps(e.guardReactiveProps(l)),{codeEditor:e.withCtx(({node:i})=>[e.renderSlot(s.$slots,"sidebarCodeEditor",{node:i})]),_:3},16)]),_:3},8,["view-model"]))}}),ao={class:"code-graph-info"},so=e.defineComponent({__name:"CodeGraphInfo",props:{viewModel:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",ao,[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)]))}}),ro=["data-node-type","id"],io={class:"__title-label",style:{"flex-grow":"1"}},lo={key:0},co={class:"__menu",style:{display:"flex"}},uo={class:"__outputs"},po={key:0},ho=["id","title"],mo={class:"__inputs"},fo={key:0},go=["id","title"],kt=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:c,switchGraph:p}=N.useGraph(),f=e.ref(null),_=e.ref(!1),m=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})),S=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)},L=()=>{y.value=!0},j=()=>{const x=i.value.displayedGraph.sidebar;x.nodeId="",x.visible=!1},oe=()=>{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},$e=async x=>{switch(x){case"edit":oe();break;case"delete":c.value.removeNode(s.node);break;case"rename":m.value=s.node.title,_.value=!0,await e.nextTick(),v.value?.focus();break;case"editSubgraph":p(s.node.template);break}},ae=()=>{r.value.title=m.value,_.value=!1},se=()=>{f.value&&i.value.hooks.renderNode.execute({node:s.node,el:f.value})},Le=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"))},W=x=>{if(!g.value)return;const b=x.clientX-u,h=C+b/c.value.scaling,k=i.value.settings.nodes.minWidth,E=i.value.settings.nodes.maxWidth;r.value.width=Math.max(k,Math.min(E,h))},re=()=>{g.value=!1};return e.onMounted(()=>{se(),window.addEventListener("mousemove",W),window.addEventListener("mouseup",re)}),e.onUpdated(se),e.onBeforeUnmount(()=>{window.removeEventListener("mousemove",W),window.removeEventListener("mouseup",re)}),(x,b)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([T.value,"baklava-node"]),"data-node-type":r.value.type,id:r.value.id,style:e.normalizeStyle(H.value),ref_key:"el",ref:f,onPointerdown:z},[e.unref(i).settings.nodes.resizable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resize-handle",onMousedown:Le},null,32)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"__title",onPointerdown:e.withModifiers(w,["self","stop"]),onContextmenu:e.withModifiers(L,["prevent"])},[r.value.inputs._code?(e.openBlock(),e.createBlock(e.unref(xe),{key:0,intf:r.value.inputs._code,node:r.value,title:r.value.inputs._code.value,class:"--input","data-interface-type":"node",style:{"flex-grow":"0"}},null,8,["intf","node","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=>m.value=h),class:"baklava-input",placeholder:"Node Name",style:{"flex-grow":"1"},type:"text",onBlur:ae,onKeydown:e.withKeys(ae,["enter"])},null,544)),[[e.vModelText,m.value]]):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",io,[r.value.idx>-1?(e.openBlock(),e.createElementBlock("span",lo,e.toDisplayString(r.value.idx+1)+" > ",1)):e.createCommentVNode("",!0),e.createTextVNode(e.toDisplayString(r.value.title),1)]),e.createElementVNode("div",co,[r.value.isCodeNode?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[r.value.state.lockCode?(e.openBlock(),e.createBlock(e.unref(ke),{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(Xe),{key:1,class:"--clickable mx-1",onClick:b[1]||(b[1]=h=>q(!1))})):(e.openBlock(),e.createBlock(e.unref(it),{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(nt),{key:3,class:"--clickable mx-1",onClick:oe})):e.unref(i).displayedGraph.sidebar.visible&&e.unref(i).displayedGraph.sidebar.nodeId!==r.value.id?(e.openBlock(),e.createBlock(e.unref(et),{key:4,class:"--clickable mx-1",onClick:Q})):(e.openBlock(),e.createBlock(e.unref(tt),{key:5,class:"--clickable mx-1",onClick:j}))],64)):e.createCommentVNode("",!0),e.createVNode(e.unref(Je),{class:"--clickable mx-1",onClick:L}),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:$e},null,8,["modelValue","items"])])],64)),r.value.outputs._code?(e.openBlock(),e.createBlock(e.unref(xe),{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",S.value]),onKeydown:b[5]||(b[5]=e.withKeys(e.withModifiers(()=>{},["stop"]),["delete"])),onContextmenu:b[6]||(b[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("div",uo,[(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",po,[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,ho)):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",mo,[(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,go)):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,ro))}}),bo=["id"],yo={class:"align-middle"},xe=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})),c=()=>{a(t.intf)},p=()=>{a(void 0)},f=()=>{r.value&&n.value.hooks.renderInterface.execute({intf:t.intf,el:r.value})};return e.onMounted(f),e.onUpdated(f),(_,m)=>(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([{"--selected":e.unref(s)?.from===o.intf},"__port"]),onPointerover:c,onPointerout:p},null,34)):e.createCommentVNode("",!0),e.createElementVNode("span",yo,[e.renderSlot(_.$slots,"default")])],10,bo))}}),ko=["title"],_o={key:0,class:"__label"},Oe=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",_o,e.toDisplayString(o.name),1)):e.createCommentVNode("",!0)],10,ko))}}),Co={class:"__header"},No={class:"__node-name"},wo={class:"__interfaces"},Eo={class:"__inputs"},Io={style:{display:"flex"}},vo={class:"__outputs"},Bo={key:0,class:"__interface"},To={style:{display:"flex"}},_t=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 c=e.computed(()=>{const y=n.value.sidebar.nodeId;return n.value.nodes.find(O=>O.id===y)}),p=e.computed(()=>c.value),f=e.computed(()=>({width:`${s.value}px`})),_=e.computed(()=>p.value?Object.values(p.value.inputs).filter(y=>y.displayInSidebar&&y.component):[]),m=e.computed(()=>p.value?Object.values(p.value.outputs).filter(y=>y.displayInSidebar&&y.component):[]),v=()=>{n.value.sidebar.visible=!1},g=()=>{c.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 S=l-T;S<300?S=300:S>.9*O&&(S=.9*O),s.value=S};return(y,O)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([{"--open":e.unref(n).sidebar.visible},"baklava-sidebar"]),style:e.normalizeStyle(f.value),ref_key:"el",ref:a},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"__resizer",onMousedown:C},null,32)):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("div",Co,[e.createElementVNode("button",{tabindex:"-1",class:"__close",onClick:v},"×"),e.createElementVNode("div",No,[e.createElementVNode("b",null,e.toDisplayString(c.value.title),1)])]),e.createElementVNode("div",wo,[e.createElementVNode("div",Eo,[(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",Io,[e.createVNode(Oe,{modelValue:T.hidden,"onUpdate:modelValue":[S=>T.hidden=S,O[0]||(O[0]=()=>c.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":S=>T.value=S,node:c.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))]),e.createElementVNode("div",vo,[p.value&&p.value.state?(e.openBlock(),e.createElementBlock("div",Bo,[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(m.value,T=>(e.openBlock(),e.createElementBlock("div",{key:T.id,class:"__interface"},[e.createElementVNode("div",To,[e.createVNode(Oe,{modelValue:T.hidden,"onUpdate:modelValue":[S=>T.hidden=S,O[2]||(O[2]=()=>c.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":S=>T.value=S,node:c.value,intf:T,style:{width:"100%"}},null,8,["modelValue","onUpdate:modelValue","node","intf"]))])]))),128))])]),e.renderSlot(y.$slots,"codeEditor",{node:c.value})],64)):e.createCommentVNode("",!0)],6))}}),xo={class:"baklava-node --palette",style:{"margin-top":"-20px","margin-bottom":"20px"}},Oo={key:0,style:{display:"flex","justify-content":"space-between"}},So=["onClick"],Mo={key:0,style:{margin:"auto 0","font-size":"12px"}},Ct=e.defineComponent({__name:"CodeNodePalette",setup(o){const t=N.Components.PaletteEntry,{viewModel:n}=N.useViewModel(),{x:a,y:s}=vt.usePointer(),{transform:r}=N.useTransform(),l=N.useNodeCategories(n),i=e.inject("editorEl"),c=e.ref(""),p=e.ref(null),f=()=>c.value?l.value.filter(g=>g.name.toLowerCase().includes(c.value.toLowerCase())||Object.values(g.nodeTypes).some(C=>C.title.toLowerCase().includes(c.value.toLowerCase()))):l.value,_=g=>c.value?Un(g,C=>{const u=C[1];return u.category.includes(c.value.toLowerCase())||u.title?.toLowerCase().includes(c.value.toLowerCase())}):g,m=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,S]=r(a.value-O.left,s.value-O.top);y.position.x=T,y.position.y=S,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",xo,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[0]||(C[0]=u=>c.value=u),type:"text",class:"baklava-input",title:"Filter nodes",onKeyup:f},null,544),[[e.vModelText,c.value]])]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f(),u=>(e.openBlock(),e.createElementBlock("section",{key:u.name},[u.name!=="default"?(e.openBlock(),e.createElementBlock("h3",Oo,[e.createElementVNode("div",{onClick:y=>c.value=u.name,style:{cursor:"pointer"}},e.toDisplayString(u.name),9,So),Object.keys(_(u.nodeTypes)).length<Object.values(u.nodeTypes).length?(e.openBlock(),e.createElementBlock("div",Mo," ( "+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,title:y.title,type:O,onPointerdown:T=>v(O,y)},null,8,["title","type","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(m.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))}}),Vo={},$o={class:"prependIcon"},Lo={class:"appendIcon"};function Ro(o,t){const n=e.resolveComponent("router-link");return e.openBlock(),e.createBlock(n,{class:"navItem"},{default:e.withCtx(()=>[e.createElementVNode("span",$o,[e.renderSlot(o.$slots,"prependIcon")]),e.renderSlot(o.$slots,"default"),e.createElementVNode("span",Lo,[e.renderSlot(o.$slots,"appendIcon")])]),_:3})}const Se=$(Vo,[["render",Ro]]),jo={class:"navbar"},Go=["onClick"],Ao=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(Se,{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(dt))],8,Go)]),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(Se,{to:{name:o.routes?.new??"new"},class:"navItem"},{default:e.withCtx(()=>[e.createVNode(e.unref(at),{class:"plus"})]),_:1},8,["to"])])]))}});class Me extends Be{_title="Subgraph Input";inputs={_code:new R("_code","").use(M.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Input").setPort(!1)};outputs={_code:new R("_code","").use(M.setType,G).setHidden(!0),placeholder:new V.NodeInterface("Connection",void 0)}}class Ve extends Te{_title="Subgraph Output";inputs={_code:new R("_code","").use(M.setType,G).setHidden(!0),name:new N.TextInputInterface("Name","Output").setPort(!1),placeholder:new V.NodeInterface("Connection",void 0)};outputs={_code:new R("_code","").use(M.setType,G).setHidden(!0),output:new V.NodeInterface("Output",void 0).setHidden(!0)}}const Nt="CREATE_SUBGRAPH",wt=[V.GRAPH_INPUT_NODE_TYPE,V.GRAPH_OUTPUT_NODE_TYPE];function Et(o,t,n){const a=()=>o.value.selectedNodes.filter(r=>!wt.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 c=l.selectedNodes.filter(w=>!wt.includes(w.type)),p=c.flatMap(w=>Object.values(w.inputs)),f=c.flatMap(w=>Object.values(w.outputs)),_=l.connections.filter(w=>!f.includes(w.from)&&p.includes(w.to)),m=l.connections.filter(w=>f.includes(w.from)&&!p.includes(w.to)),v=l.connections.filter(w=>f.includes(w.from)&&p.includes(w.to)),g=c.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}=Po(c);for(const[w,L]of _.entries()){const j=new Me;j.inputs.name.value=L.to.name,g.push({...j.save(),position:{x:O-r.value.settings.nodes.defaultWidth-100,y:T+w*200}}),C.push({id:F.v4(),from:j.outputs.placeholder.id,to:L.to.id}),u.set(L.to.id,j.graphInterfaceId)}for(const[w,L]of m.entries()){const j=new Ve;j.inputs.name.value=L.from.name,g.push({...j.save(),position:{x:y+100,y:T+w*200}}),C.push({id:F.v4(),from:L.from.id,to:j.inputs.placeholder.id}),u.set(L.from.id,j.graphInterfaceId)}const S=e.reactive(new K({connections:C,nodes:g,inputs:[],outputs:[]},i));i.addGraphTemplate(S);const H=i.nodeTypes.get(V.getGraphNodeTypeString(S));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(c.map(w=>w.position.x).reduce((w,L)=>w+L,0)/c.length),z=Math.round(c.map(w=>w.position.y).reduce((w,L)=>w+L,0)/c.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)])}),m.forEach(w=>{l.removeConnection(w),l.addConnection(U.outputs[u.get(w.from.id)],w.to)}),c.forEach(w=>l.removeNode(w)),l.activeTransactions--,t.canExecuteCommand(N.Commands.SAVE_SUBGRAPH_COMMAND)&&t.executeCommand(N.Commands.SAVE_SUBGRAPH_COMMAND),n(S),o.value.panning={...l.panning},o.value.scaling=l.scaling};t.registerCommand(Nt,{canExecute:a,execute:s})}function Po(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 Do extends V.Editor{code;graph;constructor(t){super(),this.code=t,this.graph=new X(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=ft(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 K(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 zo(o){const t=e.ref(o?.code??new te),n=e.ref(o?.existingEditor??new Do(t.value)),a=Symbol("ViewModelToken"),s=e.ref(null),r=e.shallowReadonly(s),{switchGraph:l}=gt(n,s),i=e.computed(()=>r.value&&r.value!==n.value.graph),c=e.reactive(N.DEFAULT_SETTINGS());c.nodes.defaultWidth=400;const p=N.useCommandHandler(),f=N.useHistory(r,p),_=N.useClipboard(r,n,p),m={renderNode:new Re.SequentialHook(null),renderInterface:new Re.SequentialHook(null)},v=e.reactive({clipboard:_,code:t,commandHandler:p,displayedGraph:r,editor:n,history:f,hooks:m,isSubgraph:i,onBeforeUnmount:()=>{},onMounted:()=>{},settings:c,switchGraph:l});return t.value.registerViewModel(v),ht(v),N.registerDeleteNodesCommand(r,p),Et(r,p,l),N.registerSaveSubgraphCommand(r,p),N.registerSwitchToMainGraphCommand(r,p,l),N.registerSidebarCommands(r,p),N.registerZoomToFitCommands(r,p,c),ct(r,p,c),ut(c),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??c.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:c.nodes.defaultWidth})),n.value.registerNodeType(Me,{category:"Subgraphs"}),n.value.registerNodeType(Ve,{category:"Subgraphs"}),l(g.graph))},{immediate:!0}),v}const Ho=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"}));d.AbstractCodeNode=le,d.CLEAR_ALL_COMMAND=_e,d.CREATE_SUBGRAPH_COMMAND=Nt,d.Check=We,d.CheckboxInterface=De,d.Code=te,d.CodeEditor=no,d.CodeEngine=Ye,d.CodeGraph=
|
|
16
|
+
{{ /nodes }}`},Symbol.toStringTag,{value:"Module"}));d.AbstractCodeNode=le,d.CLEAR_ALL_COMMAND=_e,d.CREATE_SUBGRAPH_COMMAND=Nt,d.Check=We,d.CheckboxInterface=De,d.Code=te,d.CodeEditor=no,d.CodeEngine=Ye,d.CodeGraph=X,d.CodeGraphEditor=oo,d.CodeGraphInfo=so,d.CodeGraphInputNode=Be,d.CodeGraphNode=kt,d.CodeGraphNodeInterface=xe,d.CodeGraphOutputNode=Te,d.CodeGraphSidebar=_t,d.CodeGraphTemplate=K,d.CodeNode=Z,d.CodeNodeInputInterface=Y,d.CodeNodeInterface=R,d.CodeNodeInterfaceComponent=ee,d.CodeNodeOutputInterface=ze,d.CodeNodePalette=Ct,d.CodeVariable=Xe,d.Copy=Ke,d.CopyToClipboard=yt,d.DotsVertical=Je,d.DynamicCodeNode=qe,d.GRAPH_INPUT_NODE_TYPE=Ie,d.GRAPH_OUTPUT_NODE_TYPE=ve,d.IntegerInterface=ge,d.JavascriptCode=Dt,d.LayoutSidebarLeftCollapse=Qe,d.LayoutSidebarLeftExpand=Ze,d.LayoutSidebarRight=et,d.LayoutSidebarRightCollapse=tt,d.LayoutSidebarRightExpand=nt,d.ListInputInterface=xt,d.LockCode=ke,d.NavBar=Ao,d.NavItem=Se,d.NumberInterface=He,d.PlayerPlay=ot,d.Plus=at,d.PythonCode=Pt,d.RUN_ENGINE_COMMAND=Ce,d.Schema=st,d.SchemaOff=rt,d.SelectInterface=Ue,d.SidebarCheckbox=Oe,d.SliderInterface=Ot,d.SubgraphInputNode=Me,d.SubgraphOutputNode=Ve,d.TOGGLE_MINIMAP_COMMAND=Ne,d.TOGGLE_PALETTE_COMMAND=we,d.TextInputInterface=ye,d.TextInputInterfaceComponent=Fe,d.TextareaInputInterface=Rt,d.TransitionBottom=it,d.TrashOff=lt,d.TupleInputInterface=jt,d.X=dt,d.addDefaultInterfaceTypes=Tt,d.allowMultipleConnections=zt,d.booleanType=ce,d.createCodeGraphNodeType=ft,d.createInterface=Ae,d.defineCodeNode=Gt,d.defineDynamicCodeNode=At,d.dictType=Pe,d.formatInputs=je,d.getCodeNodes=Ee,d.getPositionAtColumn=Dn,d.getPositionBeforeNode=zn,d.listType=ue,d.loadNodeState=de,d.nodeType=G,d.numberType=pe,d.registerCodeEngine=ht,d.registerCreateSubgraphCommand=Et,d.registerCustomCommands=ct,d.registerRunEngineCommands=pt,d.saveNodeState=Ge,d.stringType=he,d.tupleType=me,d.updateToolbarItems=ut,d.useCodeGraph=zo,d.useSwitchCodeGraph=gt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|