@blackprint/code-generation
Advanced tools
Comparing version 0.1.0 to 0.1.1
/* Blackprint | ||
MIT Licensed */ | ||
!function(e,t){"use strict";t.exports&&t.exports!==globalThis&&Object.defineProperty(t.exports,"__esModule",{value:!0}),Blackprint.Code=class{constructor(e){this.iface=e,this.node=e.node}};let n=Blackprint.Code.handlers={};Blackprint.Code.registerHandler=function(t){null!=e.sf?.Obj?sf.Obj.set(n,t.languageId,t):n[t.languageId]=t,i.prototype[t.languageId]=t.entryPointNode},Blackprint.Code.prototype._generateFor=function(e,t,r,o,a,i){if(null==this[t])throw new Error(`The registered code for "${this.iface.namespace}" doesn't have handler for "${t}" languange`);let l=this[t](r),u={};return l.code&&(l.code=function(e){let t=(e=e.trim()).split("\n").pop().match(/^[\t ]+/m);return null==t||0!==t.index?e:e.replace(RegExp("^"+t[0],"gm"),"")}(l.code)),n[t].onNodeCodeGenerated(u,{codeClass:this.constructor,data:l,functionName:e,routes:r,ifaceIndex:o,iface:i,sharedData:a}),u};let r,o=Blackprint.Code.codesHandler??={};function a(e,t,a,i){let l={traceRoute:[],routeIn:null,routeOut:null},u=e.node.instance.ifaceList,p=n[t];a.currentRoute++;let s="",d=p.routeFunction||"";d=d.replace(/{{\+bp current_route_name }}/g,a.currentRoute);let c=[],f=a.variabels;for(;null!=e;){let n=e.namespace,_=r.get(e),g=u.indexOf(e);if(null==_){let t=o[n];if(null==t)throw new Error(`Code generation haven't been registered for: ${n}`);_=new t(e),r.set(e,_)}l.routeOut=e.node.routes.out?.input.iface;let $=e.namespace.replace(/\W/g,"_")+"_bp_INDEX___",m=a.nodeCode[n]??=[],h=_._generateFor($,t,l,g,a,e);if(null!=h.code){let e=m.indexOf(h.code);h.code.includes("{{+bp wrap_code_here }}")?d=h.code:(-1===e&&(e=m.length,m.push(h.code)),$=$.replace("_bp_INDEX___",e))}let b={codes:c,selfRun:""};if(p.generatePortsStorage({functionName:$,iface:e,ifaceIndex:g,ifaceList:u,variabels:f,selfRun:s,routeIndex:a.currentRoute,result:b,codeClass:o[n]}),p.generateExecutionTree({ifaceIndex:g,iface:e,routeIndex:a.currentRoute,functionName:$,codes:c,selfRun:s,result:b,codeClass:o[n],sharedData:a}),s+=b.selfRun,l.routeIn=e,l.traceRoute.push(e),i==(e=l.routeOut))break}return s+"\n"+d.replace("{{+bp wrap_code_here }}","\t"+c.join("\n\t"))}Blackprint.registerCode=function(e,t){if(!(t.prototype instanceof Blackprint.Code))throw new Error("Class must be instance of Blackprint.Code");null==t.routeRules&&(null==t.routeIn&&(t.routeIn=Blackprint.CodeRoute.MustHave),null==t.routeOut&&(t.routeOut=Blackprint.CodeRoute.Optional)),o[e]=t},Blackprint.Code.generateFrom=function(e,t,i){if(null==t)throw new Error("Target language is required to be specified on parameter 2");if(!i)throw new Error("Export name is required to be specified on parameter 3");if(r=new Map,null==n[t])throw new Error(`Code generation for '${t}' language is not implemented yet`);let l,u={nodeCode:{},nodes:[],variabels:new Map,currentRoute:0,exported:{}};if(e instanceof Blackprint.Engine)l=function(e,t,n){let r=Blackprint.CodeRoute,i=e.ifaceList.filter((e=>{let t=o[e.namespace],{routeIn:n}=t.routeRules?.(e)||t;if(n===r.Optional||n===r.None)return!0;if(n===r.MustHave){if(0===e.node.routes.in.length)throw new Error(`Node '${e.namespace}' must have input route`);return!1}throw new Error("Unrecognized CodeRoute configuration for: "+e.namespace)})),l=[];for(let e=0;e<i.length;e++)l.push(a(i[e],t,n));let u=n.nodeCode;for(let e in u){let t=u[e];for(let e=0;e<t.length;e++)t[e]=t[e].replace("_bp_INDEX___",e);u[e]=u[e].join("\n\n")}return l.join("\n\n")}(e,t,u);else{if(!(e instanceof Blackprint.Interface))throw new Error("First parameter must be instance of Engine or Interface");l=a(e,t,u,null)}return n[t].finalCodeResult(i,u,l)},Blackprint.CodeRoute={MustHave:"__MustHave",Optional:"__Optional",None:"__None"},Blackprint.CodeType={Callback:"__Callback",Wrapper:"__Wrapper",NotWrapped:"__NotWrapped"};class i extends Blackprint.Code{}i.routeIn=Blackprint.CodeRoute.Optional,i.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Event/Listen",i),Blackprint.Code.registerHandler({languageName:"JavaScript",languageId:"js",routeFunction:"function bp_route_{{+bp current_route_name }}(){\n{{+bp wrap_code_here }}\n}",entryPointNode(e){let t=this.iface.data.namespace.replace(/\W/g,"_");return{type:Blackprint.CodeType.Wrapper,name:t,begin:`exports.${t} = async function(Input){`,end:"}"}},generatePortsStorage({iface:e,ifaceIndex:t,ifaceList:n,variabels:r}){let o=[],a=[],{IInput:i,IOutput:l}=e.ref;if(null!=i)for(let t in i){let n=i[t].default,r=/(^[^a-zA-Z]|\W)/m.test(t)?JSON.stringify(t):t;if(null==n)o.push(`${r}: null`);else{let a=typeof n,l=i[t].feature;if(l===Blackprint.Port.Trigger)n=null;else if(l===Blackprint.Port.ArrayOf)n=[];else if("string"!==a&&"number"!==a&&"boolean"!==a)throw new Error(`Can't use default type of non-primitive type for "${t}" input port in "${e.namespace}"`);o.push(`${r}: ${JSON.stringify(n)}`)}}if(null!=l)for(let e in l){let t=/(^[^a-zA-Z]|\W)/m.test(e)?JSON.stringify(e):e,r=l[e],o=[],i=r.cables;for(let e=0;e<i.length;e++){let t=i[e].input;if(null==t)continue;let r=n.indexOf(t.iface),a=/(^[^a-zA-Z]|\W)/m.test(t.name)?JSON.stringify(t.name):t.name;a='"'===a.slice(0,1)?"["+a+"]":"."+a,o.push(`bp_input_${r+a}`)}r.type!==Function?(0!==o.length&&a.push(`set ${t}(val){ ${o.join("\n")} = val; }`),a.push(`get ${t}(){ return ${o[0]}; }`)):a.push(`${t}(){\n\t\t\t\t\t\t${o.join("();\t\n")}();\n\t\t\t\t\t}`.replace(/^ /gm,""))}r.has(t)||r.set(t,`let bp_input_${t} = {${o.join(", ")}}; let bp_output_${t} = {${a.join(", ")}};`)},onNodeCodeGenerated(e,{data:t,functionName:n,routes:r,iface:o,ifaceIndex:a,sharedData:i}){if(t.type===Blackprint.CodeType.Callback){if(e.code=`function ${n}(Input, Output, Route){\n\t${t.code.replace(/\n/g,"\n\t")}\n}`,e.selfRun=t.selfRun,e.selfRun&&this.constructor.routeIn===Blackprint.CodeRoute.MustHave)throw new Error("'selfRun' code can't be used for node that using \"CodeRoute.MustHave\" for input route")}else if(t.type===Blackprint.CodeType.Wrapper){let n="";if("BP/Event/Listen"===o.namespace){let e=o.output;for(let t in e){n=`\t// To trigger getter and setter\n\tfor(x in bp_output_${a})\n\t\tbp_output_${a}[x] = Input[x];\n\n`;break}}e.code=`${t.begin}\n${n}{{+bp wrap_code_here }}\n${t.end}`}else t.type===Blackprint.CodeType.NotWrapped?(i.nodeCodeNotWrapped??=new Map,i.nodeCodeNotWrapped.set(n,t.code)):e.code=`function ${n}(Input, Output){ ${t.code} }`;if("BP/Event/Listen"===o.namespace){(i.exported??={})[t.name]={iface:o,comment:o.comment||""}}},generateExecutionTree({ifaceIndex:e,iface:t,routeIndex:n,functionName:r,selfRun:o,result:a,codeClass:i,sharedData:l}){let u=`${i.isReturn?"return ":""}${i.isAsync?"await ":""}`;if(o)a.selfRun+=`${u}${r}(bp_input_${e}, bp_output_${e}, {Out(){ bp_route_${n}(); }});`;else if("event"!==t.type){if(l.nodeCodeNotWrapped?.has(r))return void a.codes.push(l.nodeCodeNotWrapped.get(r).replace(/\bInput\b/gm,`bp_input_${e}`).replace(/\bOutput\b/gm,`bp_output_${e}`));a.codes.push(`${u}${r}(bp_input_${e}, bp_output_${e});`.replace(/^ /gm,""))}},finalCodeResult(e,t,n){if(/(^[^a-zA-Z]|\W)/m.test(e))throw new Error("Export name is a invalid variable name for JavaScript");let r=`// Application module\nlet ${e} = (function(){`;r+="\n\tlet exports = {};",r+="\n\n\t// Data storages",r+=`\n\t${[...t.variabels.values()].join("\n\t")}`;let o=("// Node .update() functions\n"+((Object.values(t.nodeCode).join("\n").trim()||"// ...")+"\n\n\n// ==== Begin of exported execution tree as functions ==== \n"+n.trim()).trim()).replace(/\n/g,"\n\t"),a=t.exported,i="";for(let t in a){""!==i&&(i+="\n\n");let n=a[t],r=[],o=n.iface.output;for(let e in o){let t=o[e].cables,n="Any";0!==t.length&&(n=t[t.length-1].input?.type?.name||"Any"),r.push(`${e}: ${n},`)}r=0!==r.length?1===r.length?`{ ${r[0]} }`:`{\n\t${r.join("\n\t")}\n}`:"",i+=`- ${e}.${t}(${r})\n \t=> ${n.comment}`}return`/*\nThis code is automatically generated with Blackprint\n\nExported functions: \n${i}\n\n*/\n\n`+r+"\n\n\t"+o+"\n\n\treturn exports;\n})();"}}),Blackprint.Code.registerHandler({languageName:"Python",languageId:"python",routeFunction:"def bp_route_{{+bp current_route_name }}():\n{{+bp wrap_code_here }}\n",entryPointNode(e){let t=this.iface.data.namespace.replace(/\W/g,"_");return{type:Blackprint.CodeType.Wrapper,name:t,begin:`def ${t}(Input):`,end:""}},generatePortsStorage({iface:e,ifaceIndex:t,ifaceList:n,variabels:r}){let o=[],a=[],{IInput:i,IOutput:l}=e.ref;if(null!=i)for(let t in i){let n=i[t].default,r=/(^[^a-zA-Z]|\W)/m.test(t)?JSON.stringify(t):t;if(null==n)o.push(`"${r}": None`);else{let a=typeof n,l=i[t].feature;if(l===Blackprint.Port.Trigger)n=null;else if(l===Blackprint.Port.ArrayOf)n=[];else if("string"!==a&&"number"!==a&&"boolean"!==a)throw new Error(`Can't use default type of non-primitive type for "${t}" input port in "${e.namespace}"`);o.push(`"${r}": ${null!=n?JSON.stringify(n):"None"}`)}}if(null!=l)for(let e in l){let t=/(^[^a-zA-Z]|\W)/m.test(e)?JSON.stringify(e):e,r=l[e],o=[],i=[],u=r.cables;for(let e=0;e<u.length;e++){let t=u[e].input;if(null==t)continue;let a=n.indexOf(t.iface),l=JSON.stringify(t.name);r.type!==Function?(i.push(`set_(bp_input_${a}, ${l}, v)`),0===o.length&&o.push(`bp_input_${a}.get(${l})`)):o.push(`bp_input_${a}.call(${l})`)}if(r.type!==Function)a.push(`"${t}": [lambda: ${o[0]}, lambda v: (${i.join(",")})]`);else{let e=`bp_input_${targetIndex}.call(${propAccessName})`;a.push(`${t}(){\n\t\t\t\t\t\t# ToDo\n\t\t\t\t\t\t${e.join("()\t\n")}()\n\t\t\t\t\t}`.replace(/^ /gm,""))}}r.has(t)||r.set(t,`bp_input_${t} = {${o.join(", ")}}\nbp_output_${t} = DataStorage({${a.join(", ")}})`)},onNodeCodeGenerated(e,{data:t,functionName:n,routes:r,iface:o,ifaceIndex:a,sharedData:i}){if(t.type===Blackprint.CodeType.Callback){if(e.code=`def ${n}(Input, Output, Route):\n\t${t.code.replace(/\n/g,"\n\t")}\n`,e.selfRun=t.selfRun,e.selfRun&&this.constructor.routeIn===Blackprint.CodeRoute.MustHave)throw new Error("'selfRun' code can't be used for node that using \"CodeRoute.MustHave\" for input route")}else if(t.type===Blackprint.CodeType.Wrapper){let n="";if("BP/Event/Listen"===o.namespace){let e=o.output;for(let t in e){n=`\t# To trigger getter and setter\n\tfor x in bp_output_${a}:\n\t\tbp_output_${a}[x] = Input[x] if x in Input else None\n\n`;break}}e.code=`${t.begin}\n${n}{{+bp wrap_code_here }}\n${t.end}`}else t.type===Blackprint.CodeType.NotWrapped?(i.nodeCodeNotWrapped??=new Map,i.nodeCodeNotWrapped.set(n,t.code)):e.code=`def ${n}(Input, Output): \n\t${t.code}`;if("BP/Event/Listen"===o.namespace){(i.exported??={})[t.name]={iface:o,comment:o.comment||""}}},generateExecutionTree({ifaceIndex:e,iface:t,routeIndex:n,functionName:r,selfRun:o,result:a,codeClass:i,sharedData:l}){let u=`${i.isReturn?"return ":""}${i.isAsync?"await ":""}`;if(o)a.selfRun+=`${u}${r}(bp_input_${e}, bp_output_${e}, { "Out": lambda: bp_route_${n}() })`;else if("event"!==t.type){if(l.nodeCodeNotWrapped?.has(r))return void a.codes.push(l.nodeCodeNotWrapped.get(r).replace(/\bInput\b/gm,`bp_input_${e}`).replace(/\bOutput\b/gm,`bp_output_${e}`));a.codes.push(`${u}${r}(bp_input_${e}, bp_output_${e})`.replace(/^ /gm,""))}},finalCodeResult(e,t,n){if(/(^[^a-zA-Z]|\W)/m.test(e))throw new Error("Export name is a invalid variable name for Python");let r="";r+="# Data storages",r+='\nclass DataStorage(object):\n\tdef __init__(self, _data): self._data = _data\n\tdef __getitem__(self, key): return self._data[key][0]()\n\tdef __setitem__(self, key, val): self._data[key][1](val)\n\tdef __iter__(self): return iter(self._data.keys())\n\tdef __len__(self): return dict.__len__(self._data)\n\tdef __delitem__(self, key): dict.__delitem__(self._data, key)\n\tdef __contains__(self, x): return dict.__contains__(self._data, x)\n\tdef call(self, key, val): raise Exception("ToDo")\n\tdef get(self, key): return self._data[key][0]()\n\tdef keys(self): return self._data.keys()\n\tdef items(self): return self._data.items()\n\tdef values(self): return self._data.values()\n\ndef set_(obj, key, val): obj[key] = val',r+=`\n\n${[...t.variabels.values()].join("\n")}`;let o="# Node .update() functions\n"+((Object.values(t.nodeCode).join("\n").trim()||"# ...")+"\n\n\n# ==== Begin of exported execution tree as functions ==== \n"+n.trim()).trim(),a=t.exported,i="";for(let t in a){""!==i&&(i+="\n\n");let n=a[t],r=[],o=n.iface.output;for(let e in o){let t=o[e].cables,n="Any";0!==t.length&&(n=t[t.length-1].input?.type?.name||"Any"),r.push(`"${e}": ${n},`)}r=0!==r.length?1===r.length?`{ ${r[0]} }`:`{\n# \t${r.join("\n# \t")}\n# }`:"",i+=`# - ${e}.${t}(${r})\n# \t=> ${n.comment}`}return`# This code is automatically generated with Blackprint\n# \n# Exported functions: \n${i}\n# \n\n`+r+"\n\n"+o}})}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this,"undefined"!=typeof module?module:{exports:this}); | ||
!function(t,e){"use strict";e.exports&&e.exports!==globalThis&&Object.defineProperty(e.exports,"__esModule",{value:!0}),Blackprint.Code=class{constructor(t){this.iface=t,this.node=t.node}};let n=Blackprint.Code.handlers={};Blackprint.Code.registerHandler=function(e){null!=t.sf?.Obj?sf.Obj.set(n,e.languageId,e):n[e.languageId]=e,o.prototype[e.languageId]=e.internalNodes.environmentSet,p.prototype[e.languageId]=e.internalNodes.environmentGet,u.prototype[e.languageId]=e.internalNodes.variableGet,l.prototype[e.languageId]=e.internalNodes.variableSet,s.prototype[e.languageId]=e.internalNodes.function,c.prototype[e.languageId]=e.internalNodes.functionOutput,f.prototype[e.languageId]=e.internalNodes.functionInput,d.prototype[e.languageId]=e.internalNodes.functionVarOutput,m.prototype[e.languageId]=e.internalNodes.functionVarInput,_.prototype[e.languageId]=e.internalNodes.eventListen,h.prototype[e.languageId]=e.internalNodes.eventEmit},Blackprint.Code.prototype._generateInit=async function(t,e){if(null==this[t])throw new Error(`The registered code for "${this.iface.namespace}" doesn't have handler for "${t}" languange`);let n=this[t](e),a=Object.assign({},n);return n.code&&(n.code=function(t){let e=(t=t.trim()).split("\n").pop().match(/^[\t ]+/m);return null==e||0!==e.index?t:t.replace(RegExp("^"+e[0],"gm"),"")}(n.code)),a},Blackprint.Code.prototype._generateFor=async function(t,e,a,i,r,o,p){return await n[e].onNodeCodeGenerated(p,{codeClass:this.constructor,data:p,functionName:t,routes:a,ifaceIndex:i,iface:o,sharedData:r}),p};let a,i=Blackprint.Code.codesHandler??={};async function r(t,e,o,p,u){let l={traceRoute:[],routeIn:null,routeOut:null},s=t.node.instance.ifaceList,c=n[e];if(o._loopDetect??=new WeakSet,o._loopDetect.has(t))return"";o._loopDetect.add(t);for(let t=0;t<s.length;t++){let n=s[t],r=n.namespace,p=r;r.startsWith("BPI/F/")&&(p="BPI/F");let u=a.get(n);if(null==u){let t=i[p];if(null==t)throw new Error(`Code generation haven't been registered for: ${p}`);u=new t(n),u.sharedData=o,u.exportName=o.exportName,a.set(n,u)}let c=await u._generateInit(e,l);o.template.set(n,c)}let f=[];for(let t=0;t<s.length;t++){let n=s[t],i=o.template.get(n);await(i.onTemplateCached?.({sharedData:o}));let r=a.get(n),p=s.indexOf(n),u=n.namespace;if(await r._generateFor(u,e,l,p,o,n,i),"BP/FnVar/Input"===n.namespace||"BP/Fn/Input"===n.namespace){let t=n.output;for(let e in t){let n=t[e];if(n.type===Blackprint.Types.Trigger){let t=n.cables;for(let e=0;e<t.length;e++){let n=t[e].input?.iface;null!=n&&n.node.routes.noUpdate&&f.push(n)}break}}}}let d=[],m=t;for(;null!=m&&(d.push(m),m=m.node.routes.out?.input?.iface,p!=m););for(let t=0;t<f.length;t++)d.includes(f[t])||d.push(f[t]);return await async function t(){o.currentRoute++;let n=c.routeFunctionName.replace("{{+bp index }}",o.currentRoute+(null!=u?"_"+u:"_0")),a=(c.routeFunction||"").replace(/{{\+bp current_route_name }}/g,n),f="",m="",_="",h=[],$=o.variabels,g=o.routeIndexes??=new Map;for(let n=0;n<d.length;n++){let b=d[n];if(b.node.routes.in.length>1&&0!==n){let e=o.currentRoute+1+(null!=u?"_"+u:"_0");g.set(b,e),d=d.slice(n),""!==m&&(m+="\n"),m+=await t(),h.push(c.createRouteCall({routeIndex:e}));break}let v=b.namespace,B=v;v.startsWith("BPI/F/")&&(B="BPI/F");let y=b.namespace,N=s.indexOf(b);l.routeOut=b.node.routes.out?.input?.iface;let k=o.template.get(b),O=o.nodeCode[v]??=[];if(null!=k.code){let t=O.indexOf(k.code);k.code.includes("{{+bp wrap_code_here }}")?a=k.selfRun?k.code:a.replace("{{+bp wrap_code_here }}",k.code):-1===t&&k.type!==Blackprint.CodeType.NotWrapped&&(t=O.length,O.push(k.code))}let I=b.output,C=0,x={};for(let t in I){let n=I[t];if(n.isRoute){let a=n.cables[0]?.input?.iface;if(a){if(x[t]=C,g.has(a))continue;_+=await r(a,e,o,p,C++)}}}let F={codes:h,selfRun:""};if(await c.generatePortsStorage({functionName:y,iface:b,ifaceIndex:N,sharedData:o,ifaceList:s,variabels:$,selfRun:f,routeIndex:o.currentRoute,result:F,outRoutes:x,codeClass:i[B]}),await c.generateExecutionTree({ifaceIndex:N,iface:b,routeIndex:o.currentRoute,sharedData:o,functionName:y,codes:h,selfRun:f,result:F,outRoutes:x,codeClass:i[B],sharedData:o}),f+=F.selfRun,l.routeIn=b,l.traceRoute.push(b),p==b)break}m&&(m+="\n"),f&&(f+="\n"),_&&(_+="\n");let b=a.match(/^\s+(?={{\+bp wrap_code_here }})/m)?.[0]||"",v=h.join("\n"+b),B="";0!==v.trim().length&&(B=a.replace("{{+bp wrap_code_here }}",v));let y=m+f+_+B;return 0===y.trim().length?"":y}()}Blackprint.registerCode=function(t,e){if(!(e.prototype instanceof Blackprint.Code))throw new Error("Class must be instance of Blackprint.Code");null==e.routeRules&&(null==e.routeIn&&(e.routeIn=Blackprint.CodeRoute.MustHave),null==e.routeOut&&(e.routeOut=Blackprint.CodeRoute.Optional)),i[t]=e},Blackprint.Code.generateFrom=async function(t,e,o,p){if(null==e)throw new Error("Target language is required to be specified on parameter 2");if(null==o)throw new Error("Export name is required to be specified on parameter 3");if(a=new Map,null==n[e])throw new Error(`Code generation for '${e}' language is not implemented yet`);let u,l={nodeCode:p?.nodeCode||{},nodes:[],variabels:new Map,template:new Map,currentRoute:-1,exported:{},exportName:o,mainShared:p?.mainShared||p};if(p&&(p.lastSharedData=l),t instanceof Blackprint.Engine)l.instance=t,u=await async function(t,e,n){let a=Blackprint.CodeRoute,o=t.ifaceList.filter((t=>{let e=t.namespace;e.startsWith("BPI/F/")&&(e="BPI/F");let n=i[e];if(null==n)throw new Error(`Blackprint.Code haven't been registered for: ${e}`);let{routeIn:r}=n.routeRules?.(t)||n;if(r===a.Optional||r===a.None)return!0;if(r===a.MustHave){if(0===t.node.routes.in.length)throw new Error(`Node '${e}' must have input route`);return!1}throw new Error("Unrecognized CodeRoute configuration for: "+e)})),p=[];for(let t=0;t<o.length;t++){let a=await r(o[t],e,n);a.trim()&&p.push(a)}let u=n.nodeCode;for(let t in u)u[t]=u[t].join("\n\n");return p.join("\n\n")}(t,e,l);else{if(!(t instanceof Blackprint.Interface||null!=t.namespace))throw new Error("First parameter must be instance of Engine or Interface");{l.instance=t.node.instance;let n=null;u=await r(t,e,l,n)}}return await n[e].finalCodeResult(o,l,u)},Blackprint.Code.utils={},Blackprint.Code.utils.getFlatNamespace=function t(e,n={},a=""){for(let i in e)e[i].constructor===Object?t(e[i],n,a+i+"/"):n[a+i]=e[i];return n},Blackprint.Code.utils.createDummyFunction=async function(t,e){let n=new Blackprint.Engine;n.executionOrder.pause=!0,n.pendingRender=!0,n.functions=e.functions,n.variables=e.variables;let a=await n.createNode("BPI/F/"+t,{data:{pause:!0}});if(await new Promise((t=>setTimeout(t,50))),0===a.bpInstance.ifaceList.length)throw"Failed to import function instance on paused engine";return{iface:a,instance:n}},Blackprint.CodeRoute={MustHave:"__MustHave",Optional:"__Optional",None:"__None"},Blackprint.CodeType={Init:"__Init",Callback:"__Callback",Wrapper:"__Wrapper",NotWrapped:"__NotWrapped"};class o extends Blackprint.Code{}o.routeIn=Blackprint.CodeRoute.MustHave,o.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Env/Set",o);class p extends Blackprint.Code{}p.routeIn=Blackprint.CodeRoute.Optional,p.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Env/Get",p);class u extends Blackprint.Code{static routeRules(t){if(t.output.Val.type===Blackprint.Types.Trigger)return{routeIn:Blackprint.CodeRoute.None,routeOut:Blackprint.CodeRoute.None}}}u.routeIn=Blackprint.CodeRoute.Optional,u.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Var/Get",u);class l extends Blackprint.Code{static routeRules(t){if(t.input.Val.type===Blackprint.Types.Trigger)return{routeIn:Blackprint.CodeRoute.None,routeOut:Blackprint.CodeRoute.None}}}l.routeIn=Blackprint.CodeRoute.MustHave,l.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Var/Set",l);class s extends Blackprint.Code{}s.routeIn=Blackprint.CodeRoute.MustHave,s.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BPI/F",s);class c extends Blackprint.Code{}c.routeIn=Blackprint.CodeRoute.MustHave,c.routeOut=Blackprint.CodeRoute.None,Blackprint.registerCode("BP/Fn/Output",c);class f extends Blackprint.Code{}f.routeIn=Blackprint.CodeRoute.None,f.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Fn/Input",f);class d extends Blackprint.Code{static routeRules(t){if(t.output.Val.type===Blackprint.Types.Trigger)return{routeIn:Blackprint.CodeRoute.None,routeOut:Blackprint.CodeRoute.None}}}d.routeIn=Blackprint.CodeRoute.MustHave,d.routeOut=Blackprint.CodeRoute.Optional,Blackprint.registerCode("BP/FnVar/Output",d);class m extends Blackprint.Code{}m.routeIn=Blackprint.CodeRoute.None,m.routeOut=Blackprint.CodeRoute.None,Blackprint.registerCode("BP/FnVar/Input",m);class _ extends Blackprint.Code{}_.routeIn=Blackprint.CodeRoute.Optional,_.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Event/Listen",_);class h extends Blackprint.Code{}h.routeIn=Blackprint.CodeRoute.MustHave,h.routeOut=Blackprint.CodeRoute.MustHave,Blackprint.registerCode("BP/Event/Emit",h);let $="\n;;class BP_CustomEvent_ {\n\ton(eventName, func, options){\n\t\tif(this._event === void 0){\n\t\t\tObject.defineProperty(this, '_event', {\n\t\t\t\tenumerable: false,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue:{ }\n\t\t\t});\n\t\t}\n\t\tif(this._eventLen === void 0){\n\t\t\tObject.defineProperty(this, '_eventLen', {\n\t\t\t\tenumerable: false,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: 0\n\t\t\t});\n\t\t}\n\n\t\tif(func.constructor === Object){\n\t\t\tlet temp = options;\n\t\t\toptions = func;\n\t\t\tfunc = temp;\n\t\t}\n\n\t\tif(eventName.includes(' ')){\n\t\t\teventName = eventName.split(' ');\n\t\t\tfor (var i = 0; i < eventName.length; i++)\n\t\t\t\tthis.on(eventName[i], func, options);\n\n\t\t\treturn this;\n\t\t}\n\t\telse if(eventName === '*') eventName = '$_all'; // For optimize performance for JS\n\n\t\tlet eventList = this._event[eventName];\n\t\tif(eventList === void 0){\n\t\t\teventList = this._event[eventName] = [];\n\t\t\tthis._eventLen++;\n\t\t}\n\n\t\tif(options && options.slot !== void 0){\n\t\t\tfor (var i = 0; i < eventList.length; i++) {\n\t\t\t\tif(eventList[i].slot === options.slot){\n\t\t\t\t\teventList.splice(i, 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunc.slot = options.slot;\n\t\t}\n\n\t\teventList.push(func);\n\t\treturn this;\n\t}\n\n\tonce(eventName, func, options){\n\t\tif(func.constructor === Object){\n\t\t\tlet temp = options;\n\t\t\toptions = func;\n\t\t\tfunc = temp;\n\t\t}\n\n\t\tfunc.once = true;\n\t\tthis.on.apply(this, arguments);\n\t\treturn this;\n\t}\n\n\twaitOnce(eventName){\n\t\treturn new Promise(resolve => {\n\t\t\tresolve.once = true;\n\t\t\tthis.once(eventName, resolve);\n\t\t});\n\t}\n\n\toff(eventName, func, options){\n\t\tif(func !== void 0 && func.constructor === Object){\n\t\t\tlet temp = options;\n\t\t\toptions = func;\n\t\t\tfunc = temp;\n\t\t}\n\n\t\tif(eventName.includes(' ')){\n\t\t\teventName = eventName.split(' ');\n\t\t\tfor (var i = 0; i < eventName.length; i++)\n\t\t\t\tthis.off(eventName[i], func);\n\n\t\t\treturn this;\n\t\t}\n\t\telse if(eventName === '*') eventName = '$_all'; // For optimize performance for JS\n\n\t\tif(this._event === void 0 || this._event[eventName] === void 0)\n\t\t\treturn this;\n\n\t\tif(func === void 0){\n\t\t\tdelete this._event[eventName];\n\t\t\treturn this;\n\t\t}\n\t\telse{\n\t\t\tvar i = this._event[eventName].indexOf(func);\n\t\t\tif(i === -1) return this;\n\n\t\t\tthis._event[eventName].splice(i, 1);\n\t\t}\n\n\t\tif(this._event[eventName].length === 0){\n\t\t\tdelete this._event[eventName];\n\n\t\t\t// Small performance improvement by removing `_event`\n\t\t\tif(--this._eventLen <= 0) delete this._event;\n\t\t}\n\t\treturn this;\n\t}\n\n\temit(eventName, obj){\n\t\tif(this._event === void 0) return false;\n\n\t\tvar events = this._event[eventName];\n\t\tif(events === void 0 || events.length === 0){\n\t\t\tevents = this._event;\n\n\t\t\tif(this._event.$_all !== void 0 && eventName !== '$_all'){\n\t\t\t\tobj ??= {};\n\t\t\t\tobj.eventName = eventName;\n\t\t\t\treturn this.emit('$_all', obj);\n\t\t\t}\n\n\t\t\treturn hasFallback !== void 0;\n\t\t}\n\n\t\tfor (var i = 0; i < events.length; i++){\n\t\t\tvar ev = events[i];\n\t\t\tif(ev.once){\n\t\t\t\tdelete ev.once;\n\t\t\t\tevents.splice(i--, 1);\n\t\t\t}\n\n\t\t\tev(obj, eventName);\n\t\t}\n\n\t\tif(this._event.$_all !== void 0 && eventName !== '$_all'){\n\t\t\tobj ??= {};\n\t\t\tobj.eventName = eventName;\n\t\t\treturn this.emit('$_all', obj);\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\n;;class BP_Instance_ extends BP_CustomEvent_ {\n\tconstructor(config){\n\t\tsuper();\n\t\tthis.Environment = config.Environment || {};\n\t}\n}\n".replace(/;;/g,"");function g(t){let e=/(^[^a-zA-Z]|\W)/m.test(t)?JSON.stringify(t):t;return e='"'===e.slice(0,1)?"["+e+"]":"."+e,e}function b(t,e,n){let a=RegExp(`(?<=\\W)${e}(?=[\\.\\[])`,"mg");if(null!=t.code&&(t.code=t.code.replace(a,n)),null!=t.begin&&(t.begin=t.begin.replace(a,n)),null!=t.end&&(t.end=t.end.replace(a,n)),null!=t.init&&(t.init=t.init.replace(a,n)),null!=t.input){let e=t.input;for(let t in e)e[t]=e[t].replace(a,n)}if(null!=t.inputAlias){let e=t.inputAlias;for(let t in e)e[t]=e[t].replace(a,n)}if(null!=t.output){let e=t.output;for(let t in e)e[t]=e[t].replace(a,n)}if(null!=t.outputAlias){let e=t.outputAlias;for(let t in e)e[t]=e[t].replace(a,n)}}Blackprint.Code.registerHandler({languageName:"JavaScript",languageId:"js",routeFunction:"async function {{+bp current_route_name }}(){\n\t{{+bp wrap_code_here }}\n}",routeFunctionName:"bp_route_{{+bp index }}",routeFillEmpty:"/* Empty route */",internalNodes:{environmentGet(t){let e=this.iface.data.name,n=this.sharedData.mainShared?.exportName||"exports";return{type:Blackprint.CodeType.NotWrapped,name:e,code:"",outputAlias:{Val:`${n}.Environment.${e}`}}},environmentSet(t){let e=this.iface.data.name,n=this.sharedData.mainShared?.exportName||"exports";return{type:Blackprint.CodeType.NotWrapped,name:e,code:`${n}.Environment.${e} = Input.Val;`}},variableGet(t){let e=this.iface.data,n=e.name,a="",i=Blackprint.CodeType.NotWrapped;if(this.iface.output.Val.type===Blackprint.Types.Trigger){let t=this.iface.output.Val.cables.map((t=>{let e=t.input;return!!e&&`bp_input_${e.iface.i}.${e.name}(bp_input_${e.iface.i}, bp_output_${e.iface.i})`})).filter((t=>!!t));a=`bp_var${e.scope}["${n}"].push(() => { ${t.join("; ")} });`,i=Blackprint.CodeType.Init}return{type:i,name:n,code:"",init:a,outputAlias:{Val:`bp_var${e.scope}["${n}"]`}}},variableSet(t){let e=this.iface.data,n=e.name,a="",i={};return this.iface.input.Val.type===Blackprint.Types.Trigger?i.Val=`bp_callVars(bp_var${e.scope}["${n}"]);`:a=`bp_var${e.scope}["${n}"] = Input.Val;`,{type:Blackprint.CodeType.NotWrapped,name:n,code:a,inputAlias:i,input:{Val:`bp_callVars(bp_var${e.scope}["${n}"]);`}}},function(t){let e=this.iface.namespace.replace("BPI/F/",""),n=this.iface.node.instance.ifaceList.indexOf(this.iface);return{type:Blackprint.CodeType.NotWrapped,name:e,code:`await bp_func_${n}.call(bp_input_${n}, bp_output_${n});`}},functionOutput(t){let{namespace:e,input:n,node:a}=this.iface;function i(t){return`${a.instance.ifaceList.indexOf(t.iface)}${g(t.name)}`}return{type:Blackprint.CodeType.NotWrapped,name:e,code:"/* Unexpected FnOutput code, this need to be fixed */",onTemplateCached({sharedData:t}){let e=[];for(let a in n){let r=n[a],o=r.cables;if(0===o.length||r.type===Blackprint.Types.Trigger)continue;let p=g(a);if(r.feature===Blackprint.Port.ArrayOf){let n=[];for(let e=0;e<o.length;e++){let a=o[e].output,r=t.template.get(a.iface);null!=r.outputAlias?.[a.name]?n.push(r.outputAlias[a.name]):n.push(`bp_output_${i(a)}`)}e.push(`BpFnOutput${p} = [${n.join(",")}]`)}else{let n=o[0].output,a=t.template.get(n.iface),r="";r=null!=a.outputAlias?.[n.name]?a.outputAlias[n.name]:`bp_output_${i(n)}`,e.push(`BpFnOutput${p} = ${r}`)}this.code=`// <-- FnOutput\n${e.join("; ")};`}}}},functionInput(t){let e=this.iface.namespace;return{type:Blackprint.CodeType.NotWrapped,selfRun:!0,name:e,code:"// <-- FnInput"}},functionVarOutput(t){let e=this.iface.namespace,n=this.iface.data,a="";return a=this.iface.input.Val.type===Blackprint.Types.Trigger?"/* ToDo FnVarOut */":`BpFnOutput["${n.name}"] = Input.Val;`,{type:Blackprint.CodeType.NotWrapped,name:e,code:a,input:{Val:`BpFnOutput["${n.name}"]?.();`}}},functionVarInput(t){let e=this.iface.namespace,n=this.iface.data,a=this.node.instance,i=a.getNodes("BP/Fn/Input")[0].iface,r=a.ifaceList.indexOf(i),o="";return this.iface.output.Val.type===Blackprint.Types.Trigger&&(o="/* ToDo FnVarIn */"),{type:Blackprint.CodeType.NotWrapped,name:e,code:o,outputAlias:{Val:`bp_output_${r}["${n.name}"]`}}},eventListen(t){let e=this.iface.data.namespace,n=this.sharedData.mainShared?.exportName||"exports";return{type:Blackprint.CodeType.Wrapper,selfRun:!0,name:e,begin:`${n}.on("${e}", async function(Input){`,end:"});",input:{Reset:"/* 1 */",Off:"/* 1 */"}}},eventEmit(t){let e=this.iface.data.namespace,n=Object.keys(this.iface.input).map((t=>{let e,n=JSON.stringify(t);return e=/[^a-zA-Z]/.test(t)?`[${n}]`:`.${t}`,`${n}: Input${e}`})).join(", ");return{name:e,code:"",input:{Emit:`${this.sharedData.mainShared?.exportName||"exports"}.emit("${e}", { ${n} });`}}}},createRouteCall({routeIndex:t}){return this.routeFunctionName.replace("{{+bp index }}",t)+"();"},generatePortsStorage({iface:t,ifaceIndex:e,ifaceList:n,variabels:a,sharedData:i,routeIndex:r,outRoutes:o}){let p=[],u=[],l=!1,{IInput:s,IOutput:c}=t.ref,f=i.template.get(t);if("BP/Fn/Output"!==t.namespace&&"BP/Var/Get"!==t.namespace&&"BP/Env/Get"!==t.namespace){if(null!=s)for(let a in s){let r=s[a],{default:o,cables:u}=r,l=/(^[^a-zA-Z]|\W)/m.test(a)?JSON.stringify(a):a,c=[];for(let t=0;t<u.length;t++){let e=u[t].output;if(null==e||e.isRoute)continue;let a=i.template.get(e.iface);if(a.outputAlias){c.push({alias:a.outputAlias[e.name]});continue}let r=n.indexOf(e.iface),o=/(^[^a-zA-Z]|\W)/m.test(e.name)?JSON.stringify(e.name):e.name;o='"'===o.slice(0,1)?"["+o+"]":"."+o,c.push({index:r,prop:o})}if(null!=f.inputAlias?.[a])r.type===Blackprint.Types.Trigger?p.push(`async ${l}(v){ ${f.inputAlias[a]} }`):(p.push(`set ${l}(v){ ${f.inputAlias[a]} = v }`),p.push(`get ${l}(){ return ${f.inputAlias[a]} }`));else if(r.feature===Blackprint.Port.ArrayOf)p.push(`get ${l}(){ return [${c.map((t=>`bp_output_${t.index}${t.prop}`)).join(",")}] }`);else if(null==o){let t=c[0];t.alias?p.push(`get ${l}(){ return ${t.alias} }`):p.push(`get ${l}(){ return bp_output_${t.index}${t.prop} }`)}else{let n=typeof o,i=r.feature;if(i===Blackprint.Port.Trigger){if(o=f.input?.[a],t.namespace.startsWith("BPI/F/")&&(o=`bp_func_${e}.input[${JSON.stringify(a)}]();`),null==o)throw new Error(`${t.namespace}: Trigger callback haven't been registered for input port "${a}"`);p.push(`async ${l}(Input, Output){ ${o} }`);continue}if(i===Blackprint.Port.ArrayOf)o=[];else if("string"!==n&&"number"!==n&&"boolean"!==n)throw new Error(`Can't use default type of non-primitive type for "${a}" input port in "${t.namespace}"`);let u=c[0];null==u?p.push(`${l}: ${JSON.stringify(o)}`):u.alias?p.push(`get ${l}(){ return ${u.alias} }`):p.push(`get ${l}(){ return bp_output_${u.index}${u.prop} ?? ${JSON.stringify(o)} }`)}}if(null!=c&&!f.outputAlias)for(let t in c){let e=/(^[^a-zA-Z]|\W)/m.test(t)?JSON.stringify(t):t,a=c[t],p=[],l=a.cables;for(let t=0;t<l.length;t++){let e=l[t].input;if(null==e||e.isRoute)continue;let a=i.template.get(e.iface);if(a.inputAlias){p.push({alias:a.inputAlias[e.name]});continue}let r=n.indexOf(e.iface),o=g(e.name);p.push({index:r,prop:o,iface:e.iface})}if(a.type!==Blackprint.Types.Trigger){if(a.isRoute){let n,p=a.cables;for(let t=0;t<p.length&&(n=p[t].input?.iface,null==n);t++);if(n&&i.routeIndexes.has(n)){let t=i.routeIndexes.get(n);u.push(`get ${e}(){ return bp_route_${t}; }`);continue}if(null!=o[t]){u.push(`get ${e}(){ return bp_route_${r}_${o[t]}; }`);continue}u.push(`${e}(){ /* Empty */ }`);continue}if(null!=f.outputAlias?.[t]){u.push(`set ${e}(v){ ${f.outputAlias[t]} = v }`),u.push(`get ${e}(){ return ${f.outputAlias[t]} }`);continue}0!==p.length?u.push(`${e}: null`):(u.push(`set ${e}(v){}`),u.push(`get ${e}(){}`))}else{let n=p.map((e=>e.alias?e.alias:"BP/Fn/Output"===e.iface.namespace||"BP/FnVar/Output"===e.iface.namespace?`await BpFnOutput[${JSON.stringify(t)}]?.();`:"BP/Var/Set"===e.iface.namespace?"/* ToDo */":`await bp_input_${e.index+e.prop}(bp_input_${e.index}, bp_output_${e.index})`));u.push(`async ${e}(){ ${n.join("; ")} }`.replace(/^ /gm,""))}}if(!a.has(e)){"BP/Fn/Input"===t.namespace&&(i.mainShared.fnOutputVar=`bp_output_${e}`,l="{}");let n="";n=0!==p.length?`let bp_input_${e} = {${p.join(", ")}}; `:`let bp_input_${e} = null;`;let r="";l?n=`let bp_output_${e} = ${l};`:r=0!==u.length?`let bp_output_${e} = {${u.join(", ")}};`:`let bp_output_${e} = null;`;let o="";if(t.namespace.startsWith("BPI/F/")){o=`let bp_func_${e} = bp_func["${t.namespace.replace("BPI/F/","")}"]()`}(l||p.length||u.length)&&a.set(e,`${n}${r}${o}`)}}},onNodeCodeGenerated(t,{data:e,functionName:n,routes:a,iface:i,ifaceIndex:r,sharedData:o,codeClass:p}){let u=n.replace(/\W/g,"_"),l=""+(p.isAsync?"async ":"");if(e.module){null==o.moduleImports&&(o.moduleImportsCount=0,o.moduleImports={});let t=o.moduleImports,n=e.module;for(let a in n){let i=t[a];null==i&&(i=t[a]="bpim_"+o.moduleImportsCount++);let r=n[a];if(r.constructor===String){if(/\W/.test(r))throw new Error("Variable must be alphanumeric and underscore only");b(e,r,i)}}}if(e.type===Blackprint.CodeType.Callback){if(t.code=`${l}function ${u}(Input, Output, Route){\n\t${e.code.replace(/\n/g,"\n\t")}\n}`,t.selfRun=e.selfRun,t.selfRun&&this.constructor.routeIn===Blackprint.CodeRoute.MustHave)throw new Error("'selfRun' code can't be used for node that using \"CodeRoute.MustHave\" for input route")}else if(e.type===Blackprint.CodeType.Wrapper){let n="";"BP/Event/Listen"===i.namespace&&(n=`\tbp_output_${r} = Input;\n`),t.code=`${e.begin}\n${n}\t{{+bp wrap_code_here }}\n${e.end}`}else e.type===Blackprint.CodeType.NotWrapped?(o.nodeCodeNotWrapped??=new Map,o.nodeCodeNotWrapped.set(n+r,e.code)):e.type===Blackprint.CodeType.Init?(o.nodeCodeInit??=new Map,o.nodeCodeInit.set(n+r,e.init)):t.code=`${l}function ${u}(Input, Output){ ${e.code.replace(/\n/g,"\n\t")} }`;if("BP/Event/Listen"===i.namespace){(o.exported??={})[e.name]={iface:i,comment:i.comment||""}}},generateExecutionTree({ifaceIndex:t,iface:e,routeIndex:n,functionName:a,selfRun:i,result:r,codeClass:o,sharedData:p}){let u=a.replace(/\W/g,"_");a.startsWith("BPI/F/")&&(u=`bp_func_${t}.call`);let l=`${o.isReturn?"return ":""}${o.isAsync?"await ":""}`;if(i)r.selfRun+=`${l}${u}(bp_input_${t}, bp_output_${t}, {Out(){ bp_route_${n}(); }});`;else if("event"!==e.type){if(p.nodeCodeNotWrapped?.has(a+t)){let e=p.nodeCodeNotWrapped.get(a+t).replace(/\bInput\b/gm,`bp_input_${t}`).replace(/\bOutput\b/gm,`bp_output_${t}`).replace(/\n/g,"\n\t");return void(e.trim()&&r.codes.push(e))}if(p.nodeCodeInit?.has(a+t))return;r.codes.push(`${l}${u}(bp_input_${t}, bp_output_${t});`.replace(/^ /gm,""))}},async finalCodeResult(t,e,n){if(/(^[^a-zA-Z]|\W)/m.test(t))throw new Error("Export name is a invalid variable name for JavaScript");let a="";!1!==e.exportName&&(a+="\n// Node .update() functions\n"+(Object.values(e.nodeCode).join("\n").trim()||"// - This export has no shared function"),a+=`\n// Application module\nlet ${t} = await (async function(){`,a+="\n\tlet exports = new BP_Instance_({Environment: {}});\n\texports.variables = bp_var0;\n\texports.functions = bp_func;"),a+="\n\n\t// ==== Data storages ==== ";let i=e.variabels,r=e.instance.ifaceList;for(let[t,e]of i)e&&(a+=`\n\n\t// ${r[t].namespace}\n\t${e}`);let o=("\n// ==== Begin of exported execution tree as functions ==== \n"+n.trim()).replace(/\n/g,"\n\t"),p=e.exported,u="";for(let e in p){""!==u&&(u+="\n\n");let n=p[e],a=[],i=n.iface.output;for(let t in i){let e=i[t].cables,n="Any";0!==e.length&&(n=e[e.length-1].input?.type?.name||"Any"),a.push(`${t}: ${n},`)}a=0!==a.length?1===a.length?`{ ${a[0]} }`:`{\n\t${a.join("\n\t")}\n}`:"",u+=`- ${t}.on("${e}", ${a})\n \t=> ${n.comment}`}let l=[];if(null!=e.moduleImports){let t=e.moduleImports;for(let e in t)l.push(`let ${t[e]} = await import(${JSON.stringify(e)});`)}let s=`/*\nThis code is automatically generated with Blackprint\n\nAvailable Events: \n${u}\n\n*/\n${$}\n\n${l.join("\n")}\n;let bp_var0 = {}; let bp_svar2 = {}; let bp_func = {};\n;function bp_callVars(list){ for(let i=0; i < list.length; i++) list[i](); }\n`;if(null!=e.nodeCodeInit)for(let[t,n]of e.nodeCodeInit)o+="\n\t"+n.replace(/\n/g,"\n\t");if(!1===e.exportName){let t=[],n=Blackprint.Code.utils.getFlatNamespace(e.instance.variables);for(let e in n)n[e].type===Blackprint.Types.Trigger&&t.push(`bp_var1[${JSON.stringify(e)}] = [];`);let i=Blackprint.Code.utils.getFlatNamespace(e.instance.sharedVariables);for(let e in i)i[e].type===Blackprint.Types.Trigger&&t.push(`bp_var2[${JSON.stringify(e)}] = [];`);return t=0===t.length?"":"\n"+t.join("\n"),"\n\tlet bp_var1 = {};"+t+a+"\n\n\t"+o+"\n"}{let n=[],i=Blackprint.Code.utils.getFlatNamespace(e.instance.variables);for(let t in i)i[t].type===Blackprint.Types.Trigger&&n.push(`bp_var0[${JSON.stringify(t)}] = [];`);n="\n"+n.join("\n");let r=[],p=Blackprint.Code.utils.getFlatNamespace(e.instance.functions);for(let t in p){let n=await Blackprint.Code.utils.createDummyFunction(t,e.instance),a=n.iface.bpInstance,i=a.getNodes("BP/Fn/Input")[0],o={};e.functionTemplate=p[t];let u=await Blackprint.Code.generateFrom(i.iface,"js",!1,e);e.functionTemplate=null,[i,...a.getNodes("BP/FnVar/Input")].forEach((t=>{let e=t.iface.output;for(let n in e){let i=e[n];if(i.type!==Blackprint.Types.Trigger)continue;"BP/FnVar/Input"===t.iface.namespace&&(n=t.iface.data.name);let r=i.cables,p=o[n]??=[];for(let t=0;t<r.length;t++){let e=r[t];if(null==e.input)continue;let n=e.input.name;n=g(n);let i=a.ifaceList.indexOf(e.input.iface);p.push(`bp_input_${i}${n}(bp_input_${i}, bp_output_${i})`)}}})),n.instance.destroy(),o=Object.entries(o).map((([t,e])=>(/(^[^a-zA-Z]|\W)/m.test(t)&&(t=JSON.stringify(t)),`${t}(){ ${e.join("; ")} }`))).join(", "),r.push(`bp_svar2["${t}"] = {}; bp_func["${t}"] = function(){\n\tlet BpFnOutput = {};\n\tlet bp_var2 = bp_svar2["${t}"];${u}\n\tlet bp_input = { ${o} };let bp_output = BpFnOutput = {};\n\treturn {\n\t\tinput: bp_input,\n\t\toutput: bp_output,\n\t\tcall: async function(BpFnInput=bp_input, _BpFnOutput=bp_output){\n\t\t\tBpFnOutput = _BpFnOutput;\n\t\t\t${e.fnOutputVar} = BpFnInput;\n\t\t\tbp_route_0_0();\n\t\t\treturn BpFnOutput;\n\t\t}\n\t}\n}`)}return r="\n"+r.join("\n"),s+n+r+"\n\n"+a+"\n\t"+o+`\n\n\treturn exports;\n})();\n\nexport { ${t} };`}}});let v="\n;;class BP_DataStorage_(object):\n\tdef __init__(self, _data): self._data = _data\n\tdef __getitem__(self, key): return self._data[key][0]()\n\tdef __setitem__(self, key, val): self._data[key][1](val)\n\tdef __iter__(self): return iter(self._data.keys())\n\tdef __len__(self): return dict.__len__(self._data)\n\tdef __delitem__(self, key): dict.__delitem__(self._data, key)\n\tdef __contains__(self, x): return dict.__contains__(self._data, x)\n\tdef get(self, key): return self._data[key][0]()\n\tdef keys(self): return self._data.keys()\n\tdef items(self): return self._data.items()\n\tdef values(self): return self._data.values()\n\ndef BP_findFromList_(list, item):\n\ttry: return list.index(item)\n\texcept ValueError: return None\n\n;;class BP_EventEmitter_(object):\n\tdef __init__(this):\n\t\tthis._events = {}\n\t\tthis._once = {}\n\n\tdef on(this, eventName, func, once = False):\n\t\tif(' ' in eventName):\n\t\t\teventName = eventName.split(' ')\n\t\t\tfor val in eventName: this.on(val, func, once)\n\t\t\treturn\n\n\t\tif(once == False): events = this._events\n\t\telse: events = this._once\n\n\t\tif(eventName not in events): events[eventName] = []\n\t\tevents[eventName].append(func)\n\n\tdef once(this, eventName, func):\n\t\tthis.on(eventName, func, True)\n\n\tdef off(this, eventName, func = None):\n\t\tif(' ' in eventName):\n\t\t\teventName = eventName.split(' ')\n\t\t\tfor val in eventName: this.off(val, func)\n\t\t\treturn\n\n\t\tif(func == None):\n\t\t\tdel this._events[eventName]\n\t\t\tdel this._once[eventName]\n\t\t\treturn\n\n\t\tif(eventName in this._events):\n\t\t\t_events = this._events[eventName]\n\t\t\ti = BP_findFromList_(_events, func)\n\t\t\tif(i != None): _events.pop(i)\n\n\t\tif(eventName in this._once):\n\t\t\t_once = this._once[eventName]\n\t\t\ti = BP_findFromList_(_once, func)\n\t\t\tif(i != None): _once.pop(i)\n\n\tdef emit(this, eventName, data=None):\n\t\tevents = this._events\n\t\tonce = this._once\n\n\t\tif(eventName in events):\n\t\t\tevs = events[eventName]\n\t\t\tfor val in evs: val(data)\n\n\t\tif(eventName in once):\n\t\t\tevs = once[eventName]\n\t\t\tfor val in evs: val(data)\n\t\t\tdel once[eventName]\n\n;;class BP_Instance_(BP_EventEmitter_):\n\tdef __init__(self, config):\n\t\tBP_EventEmitter_.__init__(self)\n\t\tself.Environment = config['Environment'] or {}\n".replace(/;;/g,"");Blackprint.Code.registerHandler({languageName:"Python",languageId:"python",routeFunction:"def {{+bp current_route_name }}():\n\t{{+bp wrap_code_here }}",routeFunctionName:"bp_route_{{+bp index }}",routeFillEmpty:"pass # Empty route",internalNodes:{environmentGet(t){let e=this.iface.data.name,n=this.sharedData.mainShared?.exportName||this.sharedData.exportName;return{type:Blackprint.CodeType.NotWrapped,name:e,code:"",outputAlias:{Val:`${n}.Environment[${JSON.stringify(e)}]`}}},environmentSet(t){let e=this.iface.data.name,n=this.sharedData.mainShared?.exportName||this.sharedData.exportName;return{type:Blackprint.CodeType.NotWrapped,name:e,code:`${n}.Environment[${JSON.stringify(e)}] = Input["Val"]`}},variableGet(t){let e=this.iface.data,n=e.name,a="",i=Blackprint.CodeType.NotWrapped;if(this.iface.output.Val.type===Blackprint.Types.Trigger){let t=this.iface.output.Val.cables.map((t=>{let e=t.input;return!!e&&`bp_input_${e.iface.i}[${JSON.stringify(e.name)}]()`})).filter((t=>!!t));a=`bp_var${e.scope}["${n}"].append(lambda: (${t.join(", ")}))`,i=Blackprint.CodeType.Init}return{type:i,name:n,code:"",init:a,outputAlias:{Val:`bp_var${e.scope}[${JSON.stringify(n)}]`}}},variableSet(t){let e=this.iface.data,n=e.name,a="",i={};return this.iface.input.Val.type===Blackprint.Types.Trigger?i.Val=`bp_callVars(bp_var${e.scope}["${n}"])`:a=`bp_var${e.scope}[${JSON.stringify(n)}] = Input["Val"]`,{type:Blackprint.CodeType.NotWrapped,name:n,code:a,inputAlias:i,input:{Val:`bp_callVars(bp_var${e.scope}["${n}"])`}}},function(t){let e=this.iface.namespace.replace("BPI/F/",""),n=this.iface.node.instance.ifaceList.indexOf(this.iface);return{type:Blackprint.CodeType.NotWrapped,name:e,code:`bp_func_${n}["call"](bp_input_${n}, bp_output_${n})`}},functionOutput(t){let{namespace:e,input:n,node:a}=this.iface;function i(t){return`${a.instance.ifaceList.indexOf(t.iface)}[${JSON.stringify(t.name)}]`}return{type:Blackprint.CodeType.NotWrapped,name:e,code:"/* Unexpected FnOutput code, this need to be fixed */",onTemplateCached({sharedData:t}){let e=[];for(let a in n){let r=n[a],o=r.cables;if(0===o.length||r.type===Blackprint.Types.Trigger)continue;let p=`[${JSON.stringify(a)}]`;if(r.feature===Blackprint.Port.ArrayOf){let n=[];for(let e=0;e<o.length;e++){let a=o[e].output,r=t.template.get(a.iface);null!=r.outputAlias?.[a.name]?n.push(r.outputAlias[a.name]):n.push(`bp_output_${i(a)}`)}e.push(`BpFnOutput${p} = [${n.join(",")}]`)}else{let n=o[0].output,a=t.template.get(n.iface),r="";r=null!=a.outputAlias?.[n.name]?a.outputAlias[n.name]:`bp_output_${i(n)}`,e.push(`BpFnOutput${p} = ${r}`)}this.code=`# <-- FnOutput\n${e.join("; ")}`}}}},functionInput(t){let e=this.iface.namespace;return{type:Blackprint.CodeType.NotWrapped,selfRun:!0,name:e,code:"# <-- FnInput"}},functionVarOutput(t){let e=this.iface.namespace,n=this.iface.data,a="";return a=this.iface.input.Val.type===Blackprint.Types.Trigger?"/* ToDo FnVarOut */":`BpFnOutput["${n.name}"] = Input["Val"]`,{type:Blackprint.CodeType.NotWrapped,name:e,code:a,input:{Val:`BpFnOutput["${n.name}"]() if BpFnOutput["${n.name}"] != None else None`}}},functionVarInput(t){let e=this.iface.namespace,n=this.iface.data,a=this.node.instance,i=a.getNodes("BP/Fn/Input")[0].iface,r=a.ifaceList.indexOf(i),o="";return this.iface.output.Val.type===Blackprint.Types.Trigger&&(o="/* ToDo FnVarIn */"),{type:Blackprint.CodeType.NotWrapped,name:e,code:o,outputAlias:{Val:`bp_output_${r}["${n.name}"]`}}},eventListen(t){let e=this.iface.data.namespace,n=e,a=e.replace(/\W/g,"_"),i=this.sharedData.mainShared?.exportName||this.sharedData.exportName;return{type:Blackprint.CodeType.Wrapper,name:n,begin:`def ${a}(Input):`,end:`${i}.on("${e}", ${a})`,input:{Reset:"pass # 1",Off:"pass # 1"}}},eventEmit(t){let e=this.iface.data.namespace;return{name:e,code:"",input:{Emit:`${this.sharedData.mainShared?.exportName||this.sharedData.exportName}.emit("${e}", { ${Object.keys(this.iface.input).map((t=>{let e=JSON.stringify(t);return`${e}: Input[${e}]`})).join(", ")} })`}}}},createRouteCall({routeIndex:t}){return this.routeFunctionName.replace("{{+bp index }}",t)+"()"},generatePortsStorage({iface:t,ifaceIndex:e,ifaceList:n,variabels:a,sharedData:i,routeIndex:r,outRoutes:o}){let p=[],u=[],l=!1,{IInput:s,IOutput:c}=t.ref,f=i.template.get(t);if("BP/Fn/Output"===t.namespace||"BP/Var/Get"===t.namespace||"BP/Env/Get"===t.namespace)return;let d=[];if(null!=s)for(let a in s){let r=s[a],{default:o,cables:u}=r,l=JSON.stringify(a),c=a.replace(/\W/g,"_"),m=[];for(let t=0;t<u.length;t++){let e=u[t].output;if(null==e||e.isRoute)continue;let a=i.template.get(e.iface);if(a.outputAlias){m.push({alias:a.outputAlias[e.name]});continue}let r=n.indexOf(e.iface),o=JSON.stringify(e.name);m.push({index:r,prop:"["+o+"]"})}if(null!=f.inputAlias?.[a])r.type===Blackprint.Types.Trigger?p.push(`${l}: [lambda: ${f.inputAlias[a]}]`):(p.push(`set ${l}(v){ ${f.inputAlias[a]} = v }`),p.push(`get ${l}(){ return ${f.inputAlias[a]} }`));else if(r.feature===Blackprint.Port.ArrayOf)p.push(`${l}: [lambda: [${m.map((t=>`bp_output_${t.index}${t.prop}`)).join(",")}]]`);else if(null==o){let t=m[0];t.alias?p.push(`${l}: [lambda: ${t.alias}]`):p.push(`${l}: [lambda: bp_output_${t.index}${t.prop}]`)}else{let n=typeof o,i=r.feature;if(i===Blackprint.Port.Trigger){if(o=f.input?.[a],t.namespace.startsWith("BPI/F/")&&(o=`bp_func_${e}["input"][${JSON.stringify(a)}]()`),null==o)throw new Error(`${t.namespace}: Trigger callback haven't been registered for input port "${a}"`);let n=`inp_f_${c}${e}`;d.push(`def ${n}(Input, Output):\n\t${o}\ndef c_${n}(): ${n}(bp_input_${e}, bp_output_${e})`),p.push(`${l}: [lambda: c_${n}]`);continue}if(i===Blackprint.Port.ArrayOf)o=[];else if("string"!==n&&"number"!==n&&"boolean"!==n)throw new Error(`Can't use default type of non-primitive type for "${a}" input port in "${t.namespace}"`);o="boolean"===n?o?"True":"False":null!=o?JSON.stringify(o):"None";let u=m[0];null==u?p.push(`${l}: [lambda: ${o}]`):u.alias?p.push(`${l}: [lambda: ${u.alias}]`):p.push(`${l}: [lambda: bp_output_${u.index}${u.prop} if bp_output_${u.index}${u.prop} != None else ${o}]`)}}let m=[];if(null!=c&&!f.outputAlias)for(let t in c){let a=JSON.stringify(t),p=t.replace(/\W/g,"_"),l=c[t],s=[],d=l.cables;for(let t=0;t<d.length;t++){let e=d[t].input;if(null==e||e.isRoute)continue;let a=i.template.get(e.iface);if(a.inputAlias){s.push({alias:a.inputAlias[e.name]});continue}let r=n.indexOf(e.iface),o=JSON.stringify(e.name);o=`[${o}]`,s.push({index:r,prop:o,iface:e.iface})}if(l.type!==Blackprint.Types.Trigger){if(l.isRoute){let e,n=l.cables;for(let t=0;t<n.length&&(e=n[t].input?.iface,null==e);t++);if(e&&i.routeIndexes.has(e)){let t=i.routeIndexes.get(e);u.push(`${a}: [lambda: bp_route_${t}]`);continue}if(null!=o[t]){u.push(`${a}: [lambda: bp_route_${r}_${o[t]}]`);continue}u.push(`${a}: [lambda: bp__NOOP]`);continue}if(null!=f.outputAlias?.[t]){let n=`bp_output_${e}_${p}`;m.push(`def ${n}(v): ${f.outputAlias[t]} = v`),u.push(`${a}: [lambda: ${f.outputAlias[t]}, lambda v: ${n}(v)]`);continue}if(0===s.length)return void u.push(`${a}: [lambda: 0, lambda: 0]`);let n=`bp_data_${e}[${a}]`,c=`bp_output_${e}_${p}`;m.push(`def ${c}(v): ${n} = v`),u.push(`${a}: [lambda: ${n}, lambda v: ${c}(v)]`)}else{let n=s.map((e=>e.alias?e.alias:"BP/Fn/Output"===e.iface.namespace||"BP/FnVar/Output"===e.iface.namespace?`BpFnOutput[${JSON.stringify(t)}]() if BpFnOutput[${JSON.stringify(t)}] != None else None`:"BP/Var/Set"===e.iface.namespace?"/* ToDo */":`bp_input_${e.index+e.prop}()`)),i=`out_f_${p}${e}`;m.push(`def ${i}():\n\t${n.join("\n\t")}`),u.push(`${a}: [lambda: ${i}]`.replace(/^ /gm,""))}}if(d=d.join("\n").trim(),""!=d&&(d+="\n"),m=m.join("\n").trim(),""!=m&&(m+="\n"),!a.has(e)){"BP/Fn/Input"===t.namespace&&(i.mainShared.fnOutputVar=`bp_output_${e}`,l="{}");let n="";n=0!==p.length?`bp_input_${e} = BP_DataStorage_({${p.join(", ")}})`:`bp_input_${e} = None`,n&&(n+="\n");let r="";if(l)n=`bp_output_${e} = ${l}`;else if(0!==u.length){r=`bp_output_${e} = BP_DataStorage_({${u.join(", ")}})`,r+=`\nbp_data_${e} = {${Object.keys(c).map((t=>JSON.stringify(t)+":None")).join(", ")}}`}else r=`bp_output_${e} = None`;let o="";if(t.namespace.startsWith("BPI/F/")){o=`\nbp_func_${e} = bp_func["${t.namespace.replace("BPI/F/","")}"]()`}""==r&&(m=""),""==n&&(d=""),(l||p.length||u.length)&&a.set(e,`${d}${m}${n}${r}${o}`)}},onNodeCodeGenerated(t,{data:e,functionName:n,routes:a,iface:i,ifaceIndex:r,sharedData:o}){let p=n.replace(/\W/g,"_");if(e.module){null==o.moduleImports&&(o.moduleImportsCount=0,o.moduleImports={},o.moduleImportsMultiple={});let t=o.moduleImports,n=e.module;for(let a in n){let i=n[a];if(i.constructor===String){if(/\W/.test(i))throw new Error("Variable must be alphanumeric and underscore only");let n=t[a];null==n&&(n=t[a]="bpim_"+o.moduleImportsCount++),b(e,i,n)}else if(i.constructor===Object){let t=o.moduleImportsMultiple[a]??={};for(let n in i){if(/\W/.test(i[n]))throw new Error("Variable must be alphanumeric and underscore only");let a=t[n];null==a&&(a=t[n]="bpim_"+o.moduleImportsCount++),b(e,i[n],a)}}}}if(e.type===Blackprint.CodeType.Callback){if(t.code=`def ${p}(Input, Output, Route):\n\t${e.code.replace(/\n/g,"\n\t")}\n`,t.selfRun=e.selfRun,t.selfRun&&this.constructor.routeIn===Blackprint.CodeRoute.MustHave)throw new Error("'selfRun' code can't be used for node that using \"CodeRoute.MustHave\" for input route")}else if(e.type===Blackprint.CodeType.Wrapper){let n="";if("BP/Event/Listen"===i.namespace){let t=i.output;for(let e in t){n=`\t\t# To trigger getter and setter\n\t\tfor x in bp_output_${r}:\n\t\t\tbp_output_${r}[x] = Input[x] if x in Input else None\n\n`;break}}t.code=`${e.begin}\n${n}\t\t{{+bp wrap_code_here }}\n\t${e.end}`}else e.type===Blackprint.CodeType.NotWrapped?(o.nodeCodeNotWrapped??=new Map,o.nodeCodeNotWrapped.set(n+r,e.code)):e.type===Blackprint.CodeType.Init?(o.nodeCodeInit??=new Map,o.nodeCodeInit.set(n+r,e.init)):t.code=`def ${p}(Input, Output): \n\t${e.code.replace(/\n/g,"\n\t")}`;if("BP/Event/Listen"===i.namespace){(o.exported??={})[e.name]={iface:i,comment:i.comment||""}}},generateExecutionTree({ifaceIndex:t,iface:e,routeIndex:n,functionName:a,selfRun:i,result:r,codeClass:o,sharedData:p}){let u=a.replace(/\W/g,"_");a.startsWith("BPI/F/")&&(u=`bp_func_${t}["call"]`);let l=""+(o.isReturn?"return ":"");if(i)r.selfRun+=`${l}${u}(bp_input_${t}, bp_output_${t}, { "Out": lambda: bp_route_${n}() })`;else if("event"!==e.type){if(p.nodeCodeNotWrapped?.has(a+t)){let e=p.nodeCodeNotWrapped.get(a+t).replace(/\bInput\b/gm,`bp_input_${t}`).replace(/\bOutput\b/gm,`bp_output_${t}`).replace(/\n/g,"\n\t");return void(e.trim()&&r.codes.push(e))}if(p.nodeCodeInit?.has(a+t))return;r.codes.push(`${l}${u}(bp_input_${t}, bp_output_${t})`.replace(/^ /gm,""))}},async finalCodeResult(t,e,n){if(/(^[^a-zA-Z]|\W)/m.test(t))throw new Error("Export name is a invalid variable name for Python");let a="";!1!==e.exportName&&(a+=`\n\n# Application module\n${t} = BP_Instance_({"Environment":{}})\n${t}.variables = bp_var0\n${t}.functions = bp_func`,a+="\n\n# Node .update() functions\n"+(Object.values(e.nodeCode).join("\n").trim()||"# - This export has no shared function")),a+=t?"\n\ndef _mainInstance():":"\n",a+="\n\t# ==== Data storages ==== ";let i=e.variabels,r=e.instance.ifaceList;for(let[t,e]of i)e&&(e=e.split("\n").join("\n\t"),a+=`\n\n\t# ${r[t].namespace}\n\t${e}`);let o=("\n\t# ==== Begin of exported execution tree as functions ==== \n\t"+n.trim().split("\n").join("\n\t")).trim(),p=e.exported,u="";for(let e in p){""!==u&&(u+="\n\n");let n=p[e],a=[],i=n.iface.output;for(let t in i){let e=i[t].cables,n="Any";0!==e.length&&(n=e[e.length-1].input?.type?.name||"Any"),a.push(`"${t}": ${n},`)}a=0!==a.length?1===a.length?`{ ${a[0]} }`:`{\n# \t${a.join("\n# \t")}\n# }`:"",u+=`# - ${t}.on("${e}", ${a})\n# \t=> ${n.comment}`}let l=[];if(null!=e.moduleImports){let t=e.moduleImports;for(let e in t)l.push(`import ${e} as ${t[e]}`)}if(null!=e.moduleImportsMultiple){let t=e.moduleImportsMultiple;for(let e in t){let n=Object.entries(t[e]).map((t=>`${t[0]} as ${t[1]}`));l.push(`from ${e} import ${n.join(", ")}`)}}let s=`# This code is automatically generated with Blackprint\n# \n# Available Events: \n${u}\n# \n${v}\n\n${l.join("\n")}\nbp_var0 = {}; bp_svar2 = {}; bp_func = {};\ndef bp_callVars(list):\n\tfor x in list: x()\ndef bp__NOOP(): pass\n`;if(null!=e.nodeCodeInit)for(let[t,n]of e.nodeCodeInit)o+="\n\t"+n.replace(/\n/g,"\n\t");function c(t){return t===Boolean?"False":t===Number?"0":t===String?'""':"None"}if(!1===e.exportName){let t=[],n=Blackprint.Code.utils.getFlatNamespace(e.instance.variables);for(let e in n){let a=n[e].type;a===Blackprint.Types.Trigger?t.push(`bp_var1[${JSON.stringify(e)}] = []`):t.push(`bp_var1[${JSON.stringify(e)}] = ${c(a)}`)}let i=Blackprint.Code.utils.getFlatNamespace(e.instance.sharedVariables);for(let e in i){let n=i[e].type;n===Blackprint.Types.Trigger?t.push(`bp_var2[${JSON.stringify(e)}] = []`):t.push(`bp_var2[${JSON.stringify(e)}] = ${c(n)}`)}return t=0===t.length?"":"\n\t"+t.join("\n\t"),"\n\tbp_var1 = {}"+t+a+"\n\n\t"+o+"\n"}{let t=[],n=Blackprint.Code.utils.getFlatNamespace(e.instance.variables);for(let e in n){let a=n[e].type;a===Blackprint.Types.Trigger?t.push(`bp_var0[${JSON.stringify(e)}] = []`):t.push(`bp_var0[${JSON.stringify(e)}] = ${c(a)}`)}t="\n"+t.join("\n");let i=[],r=Blackprint.Code.utils.getFlatNamespace(e.instance.functions);for(let t in r){let n=await Blackprint.Code.utils.createDummyFunction(t,e.instance),a=n.iface.bpInstance,o=a.getNodes("BP/Fn/Input")[0],p={},u={};e.functionTemplate=r[t];let l=await Blackprint.Code.generateFrom(o.iface,"python",!1,e);e.functionTemplate=null,[o,...a.getNodes("BP/FnVar/Input")].forEach((t=>{let e=t.iface.output;for(let n in e){let i=e[n];if(i.type!==Blackprint.Types.Trigger)return void(u[n]??=!0);"BP/FnVar/Input"===t.iface.namespace&&(n=t.iface.data.name);let r=i.cables,o=p[n]??=[];for(let t=0;t<r.length;t++){let e=r[t];if(null==e.input)continue;let n=JSON.stringify(e.input.name),i=a.ifaceList.indexOf(e.input.iface);o.push(`bp_input_${i}[${n}]()`)}}})),p=Object.entries(p).map((([t,e])=>(/(^[^a-zA-Z]|\W)/m.test(t)&&(t=JSON.stringify(t)),`"${t}": lambda: (${e.join(", ")})`))).join(", "),u=Object.entries(u).map((([t,e])=>`${JSON.stringify(t)}: None`)).join(", ");let s=Object.keys(a.getNodes("BP/Fn/Output")[0].input).map((t=>`${JSON.stringify(t)}: None`)).join(", ");n.instance.destroy();let c=t.replace(/\W/g,"_");i.push(`bp_svar2["${t}"] = {}\ndef bpf_${c}():\n\tBpFnOutput = {}\n\tbp_var2 = bp_svar2["${t}"]${l}\n\tbp_input = { ${[p,u].join(", ")} }; bp_output = BpFnOutput = { ${s} }\n\tdef bp_instanceCall_(BpFnInput=bp_input, _BpFnOutput=bp_output):\n\t\tnonlocal BpFnOutput, ${e.fnOutputVar}\n\t\tBpFnOutput = _BpFnOutput\n\t\t${e.fnOutputVar} = BpFnInput\n\t\tbp_route_0_0()\n\t\treturn BpFnOutput\n\treturn {"input": bp_input, "output": bp_output, "call": bp_instanceCall_}\nbp_func["${t}"] = bpf_${c}`)}return i="\n"+i.join("\n"),s+t+i+"\n\n"+a+"\n\n\t"+o+"\n\tbp_route_0_0()\n\n_mainInstance()"}}})}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this,"undefined"!=typeof module?module:{exports:this}); | ||
//# sourceMappingURL=code-generation.min.js.map |
{ | ||
"name": "@blackprint/code-generation", | ||
"description": "Blackprint code generation library", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Blackprint", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
213182
347
1