@logicflow/engine 0.1.0 → 0.1.2

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/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Engine={})}(this,(function(exports){"use strict";function __awaiter(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}var ErrorCode,WarningCode;"function"==typeof SuppressedError&&SuppressedError,exports.ErrorCode=void 0,ErrorCode=exports.ErrorCode||(exports.ErrorCode={}),ErrorCode[ErrorCode.NONE_START_NODE=1e3]="NONE_START_NODE",ErrorCode[ErrorCode.NONE_NODE_ID=1001]="NONE_NODE_ID",ErrorCode[ErrorCode.NO_DOCUMENT_BODY=2001]="NO_DOCUMENT_BODY",exports.WarningCode=void 0,WarningCode=exports.WarningCode||(exports.WarningCode={}),WarningCode[WarningCode.NONE_START_NODE_IN_DATA=2e3]="NONE_START_NODE_IN_DATA",WarningCode[WarningCode.START_NODE_INCOMING=2001]="START_NODE_INCOMING",WarningCode[WarningCode.EXPRESSION_EXEC_ERROR=3e3]="EXPRESSION_EXEC_ERROR";const errorMsgMapCn={[exports.ErrorCode.NONE_START_NODE]:"未找到入度为0的节点",[exports.ErrorCode.NONE_NODE_ID]:"流程数据中存在没有此节点",[exports.ErrorCode.NO_DOCUMENT_BODY]:"找不到document.body, 请在DOM加载完成后再执行"},warningMsgMapCn={[exports.WarningCode.NONE_START_NODE_IN_DATA]:"初始化数据中未找到入度为0的节点",[exports.WarningCode.START_NODE_INCOMING]:"开始节点不允许被连入",[exports.WarningCode.EXPRESSION_EXEC_ERROR]:"表达式执行异常"},getErrorMsg=e=>`error[${e}]: ${errorMsgMapCn[e]}`,getWarningMsg=e=>`warning[${e}]: ${warningMsgMapCn[e]}`,BASE_START_NODE="start",EVENT_INSTANCE_COMPLETE="instance:complete",EVENT_INSTANCE_INTERRUPTED="instance:interrupted",EVENT_INSTANCE_ERROR="instance:error";var FlowStatus,ActionStatus;function parseHexToInt(e){return!e.match(/[^a-f0-9]/i)?parseInt(e,16):NaN}function validateAndParseHex(e,t,n){const r=parseHexToInt(e);if(Number.isNaN(r)||void 0!==n&&n!==e.length)throw new SyntaxError(t+": "+e);return r}function parseHexadecimalCode(e){const t=validateAndParseHex(e,"Malformed Hexadecimal",2);return String.fromCharCode(t)}function parseUnicodeCode(e,t){const n=validateAndParseHex(e,"Malformed Unicode",4);if(void 0!==t){const e=validateAndParseHex(t,"Malformed Unicode",4);return String.fromCharCode(n,e)}return String.fromCharCode(n)}function isCurlyBraced(e){return"{"===e.charAt(0)&&"}"===e.charAt(e.length-1)}function parseUnicodeCodePointCode(e){if(!isCurlyBraced(e))throw new SyntaxError("Malformed Unicode: +"+e);const t=validateAndParseHex(e.slice(1,-1),"Malformed Unicode");try{return String.fromCodePoint(t)}catch(e){throw e instanceof RangeError?new SyntaxError("Code Point Limit:"+t):e}}exports.FlowStatus=void 0,FlowStatus=exports.FlowStatus||(exports.FlowStatus={}),FlowStatus.COMPLETED="completed",FlowStatus.INTERRUPTED="interrupted",FlowStatus.RUNNING="running",FlowStatus.PENDING="pending",FlowStatus.ERROR="error",exports.ActionStatus=void 0,ActionStatus=exports.ActionStatus||(exports.ActionStatus={}),ActionStatus.SUCCESS="success",ActionStatus.ERROR="error",ActionStatus.INTERRUPTED="interrupted";const singleCharacterEscapes=new Map([["b","\b"],["f","\f"],["n","\n"],["r","\r"],["t","\t"],["v","\v"],["0","\0"]]);function parseSingleCharacterCode(e){return singleCharacterEscapes.get(e)||e}const escapeMatch=/\\(?:(\\)|x([\s\S]{0,2})|u(\{[^}]*\}?)|u([\s\S]{4})\\u([^{][\s\S]{0,3})|u([\s\S]{0,4})|([0-3]?[0-7]{1,2})|([\s\S])|$)/g;function unraw(e){return e.replace(escapeMatch,(function(e,t,n,r,i,o,s,a,c){if(void 0!==t)return"\\";if(void 0!==n)return parseHexadecimalCode(n);if(void 0!==r)return parseUnicodeCodePointCode(r);if(void 0!==i)return parseUnicodeCode(i,o);if(void 0!==s)return parseUnicodeCode(s);if("0"===a)return"\0";if(void 0!==a)throw new SyntaxError("Octal Deprecation: "+a);if(void 0!==c)return parseSingleCharacterCode(c);throw new SyntaxError("End of string")}))}function createLisp(e){return[e.op,e.a,e.b]}let lispTypes=new Map;class ParseError extends Error{constructor(e,t){super(e+": "+t.substring(0,40)),this.code=t}}const inlineIfElse=/^:/,elseIf=/^else(?![\w\$])/,ifElse=/^if(?![\w\$])/,space=/^\s/;let expectTypes={splitter:{types:{opHigh:/^(\/|\*\*|\*(?!\*)|\%)(?!\=)/,op:/^(\+(?!(\+))|\-(?!(\-)))(?!\=)/,comparitor:/^(<=|>=|<(?!<)|>(?!>)|!==|!=(?!\=)|===|==)/,boolOp:/^(&&|\|\||instanceof(?![\w\$])|in(?![\w\$]))/,bitwise:/^(&(?!&)|\|(?!\|)|\^|<<|>>(?!>)|>>>)(?!\=)/},next:["modifier","value","prop","incrementerBefore"]},inlineIf:{types:{inlineIf:/^\?(?!\.(?!\d))/},next:["expEnd"]},assignment:{types:{assignModify:/^(\-=|\+=|\/=|\*\*=|\*=|%=|\^=|\&=|\|=|>>>=|>>=|<<=)/,assign:/^(=)(?!=)/},next:["modifier","value","prop","incrementerBefore"]},incrementerBefore:{types:{incrementerBefore:/^(\+\+|\-\-)/},next:["prop"]},expEdge:{types:{call:/^(\?\.)?[\(]/,incrementerAfter:/^(\+\+|\-\-)/},next:["splitter","expEdge","dot","inlineIf","expEnd"]},modifier:{types:{not:/^!/,inverse:/^~/,negative:/^\-(?!\-)/,positive:/^\+(?!\+)/,typeof:/^typeof(?![\w\$])/,delete:/^delete(?![\w\$])/},next:["modifier","value","prop","incrementerBefore"]},dot:{types:{arrayProp:/^(\?\.)?\[/,dot:/^(\?)?\.(?=\s*[a-zA-Z\$\_])/},next:["splitter","assignment","expEdge","dot","inlineIf","expEnd"]},prop:{types:{prop:/^[a-zA-Z\$\_][a-zA-Z\d\$\_]*/},next:["splitter","assignment","expEdge","dot","inlineIf","expEnd"]},value:{types:{createObject:/^\{/,createArray:/^\[/,number:/^(0x[\da-f]+(_[\da-f]+)*|(\d+(_\d+)*(\.\d+(_\d+)*)?|\.\d+(_\d+)*))(e[\+\-]?\d+(_\d+)*)?(n)?(?!\d)/i,string:/^"(\d+)"/,literal:/^`(\d+)`/,regex:/^\/(\d+)\/r(?![\w\$])/,boolean:/^(true|false)(?![\w\$])/,null:/^null(?![\w\$])/,und:/^undefined(?![\w\$])/,arrowFunctionSingle:/^(async\s+)?([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*=>\s*({)?/,arrowFunction:/^(async\s*)?\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*=>\s*({)?/,inlineFunction:/^(async\s+)?function(\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)?\s*\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*{/,group:/^\(/,NaN:/^NaN(?![\w\$])/,Infinity:/^Infinity(?![\w\$])/,void:/^void(?![\w\$])\s*/,await:/^await(?![\w\$])\s*/,new:/^new(?![\w\$])\s*/},next:["splitter","expEdge","dot","inlineIf","expEnd"]},initialize:{types:{initialize:/^(var|let|const)\s+([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*(=)?/,return:/^return(?![\w\$])/,throw:/^throw(?![\w\$])\s*/},next:["modifier","value","prop","incrementerBefore","expEnd"]},spreadObject:{types:{spreadObject:/^\.\.\./},next:["value","prop"]},spreadArray:{types:{spreadArray:/^\.\.\./},next:["value","prop"]},expEnd:{types:{},next:[]},expFunction:{types:{function:/^(async\s+)?function(\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*{/},next:["expEdge","expEnd"]},expSingle:{types:{for:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*for\s*\(/,do:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*do(?![\w\$])\s*(\{)?/,while:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*while\s*\(/,loopAction:/^(break|continue)(?![\w\$])\s*([a-zA-Z\$\_][\w\$]*)?/,if:/^((([a-zA-Z\$\_][\w\$]*)\s*:)?\s*)if\s*\(/,try:/^try\s*{/,block:/^{/,switch:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*switch\s*\(/},next:["expEnd"]}},closings={"(":")","[":"]","{":"}","'":"'",'"':'"',"`":"`"};function testMultiple(e,t){let n;for(let r=0;r<t.length;r++){if(n=t[r].exec(e),n)break}return n}class CodeString{constructor(e){this.ref={str:""},e instanceof CodeString?(this.ref=e.ref,this.start=e.start,this.end=e.end):(this.ref.str=e,this.start=0,this.end=e.length)}substring(e,t){if(!this.length)return this;(e=this.start+e)<0&&(e=0),e>this.end&&(e=this.end),(t=void 0===t?this.end:this.start+t)<0&&(t=0),t>this.end&&(t=this.end);const n=new CodeString(this);return n.start=e,n.end=t,n}get length(){const e=this.end-this.start;return e<0?0:e}char(e){if(this.start!==this.end)return this.ref.str[this.start+e]}toString(){return this.ref.str.substring(this.start,this.end)}trimStart(){const e=/^\s+/.exec(this.toString()),t=new CodeString(this);return e&&(t.start+=e[0].length),t}slice(e,t){return e<0&&(e=this.end-this.start+e),e<0&&(e=0),void 0===t&&(t=this.end-this.start),t<0&&(t=this.end-this.start+t),t<0&&(t=0),this.substring(e,t)}trim(){const e=this.trimStart(),t=/\s+$/.exec(e.toString());return t&&(e.end-=t[0].length),e}valueOf(){return this.toString()}}const emptyString=new CodeString(""),okFirstChars=/^[\+\-~ !]/,aNumber=expectTypes.value.types.number,wordReg=/^((if|for|else|while|do|function)(?![\w\$])|[\w\$]+)/,semiColon=/^;/,insertedSemicolons=new WeakMap,quoteCache=new WeakMap;function restOfExp(e,t,n,r,i,o,s={}){if(!t.length)return t;s.words=s.words||[];let a=!0;const c=(n=n||[]).includes(semiColon);c&&(n=n.filter((e=>e!==semiColon)));const l=insertedSemicolons.get(t.ref)||[],d=quoteCache.get(t.ref)||new Map;if(quoteCache.set(t.ref,d),r&&d.has(t.start-1))return t.substring(0,d.get(t.start-1)-t.start);let p,u=!1,f=!1,h="",g=!1,y=!1;for(p=0;p<t.length&&!f;p++){let x=t.char(p);if('"'===r||"'"===r||"`"===r){if("`"!==r||"$"!==x||"{"!==t.char(p+1)||u){if(x===r&&!u)return t.substring(0,p)}else{p+=restOfExp(e,t.substring(p+2),[],"{").length+2}u=!u&&"\\"===x}else if(closings[x]){if(!y&&l[p+t.start]){if(y=!0,c)break;p--,h=";";continue}if(g&&"{"===x&&(g=!1),x===i){f=!0;break}{let n=restOfExp(e,t.substring(p+1),[],x);if(d.set(n.start-1,n.end),p+=n.length+1,a=!1,o){let e;(e=testMultiple(t.substring(p).toString(),o))&&(s.regRes=e,f=!0)}}}else if(r){if(x===closings[r])return t.substring(0,p)}else{let e,r,i=t.substring(p).toString();if(o){let e;if(e=testMultiple(i,o)){s.regRes=e,p++,f=!0;break}}if(r=aNumber.exec(i))p+=r[0].length-1,i=t.substring(p).toString();else if(h!=x){let r;if(";"===x||l[p+t.start]&&!a&&!y){if(c)r=[";"];else if(l[p+t.start]){y=!0,p--,h=";";continue}x=i=";"}else y=!1;r||(r=testMultiple(i,n)),r&&(f=!0),!f&&(e=wordReg.exec(i))&&(g=!0,e[0].length>1&&(s.words.push(e[1]),s.lastAnyWord=e[1],e[2]&&(s.lastWord=e[2])),e[0].length>2&&(p+=e[0].length-2))}if(a&&(okFirstChars.test(i)?f=!1:a=!1),f)break}h=x}if(r)throw new SyntaxError("Unclosed '"+r+"'");return s&&(s.oneliner=g),t.substring(0,p)}restOfExp.next=["splitter","expEnd","inlineIf"];const startingExecpted=["initialize","expSingle","expFunction","value","modifier","prop","incrementerBefore","expEnd"],setLispType=(e,t)=>{e.forEach((e=>{lispTypes.set(e,t)}))},closingsCreate={createArray:/^\]/,createObject:/^\}/,group:/^\)/,arrayProp:/^\]/,call:/^\)/},typesCreate={createArray:12,createObject:22,group:23,arrayProp:19,call:5,prop:1,"?prop":20,"?call":21};setLispType(["createArray","createObject","group","arrayProp","call"],((e,t,n,r,i,o)=>{let s=emptyString,a=[],c=!1,l=r[0].length;const d=l;for(;l<n.length&&!c;)s=restOfExp(e,n.substring(l),[closingsCreate[t],/^,/]),l+=s.length,s.trim().length&&a.push(s),","!==n.char(l)?c=!0:l++;const p=["value","modifier","prop","incrementerBefore","expEnd"];let u,f;switch(t){case"group":case"arrayProp":u=lispifyExpr(e,n.substring(d,l));break;case"call":case"createArray":u=a.map((t=>lispify(e,t,[...p,"spreadArray"])));break;case"createObject":u=a.map((t=>{let n;t=t.trimStart();let r="";if(f=expectTypes.expFunction.types.function.exec("function "+t),f)r=f[2].trimStart(),n=lispify(e,new CodeString("function "+t.toString().replace(r,"")));else{let i=restOfExp(e,t,[/^:/]);r=lispify(e,i,[...p,"spreadObject"]),1===r[0]&&(r=r[2]),n=lispify(e,t.substring(i.length+1))}return createLisp({op:6,a:r,b:n})}))}let h="arrayProp"===t?r[1]?20:1:"call"===t?r[1]?21:5:typesCreate[t];o.lispTree=lispify(e,n.substring(l+1),expectTypes[i].next,createLisp({op:h,a:o.lispTree,b:u}))}));const modifierTypes={inverse:64,not:24,positive:59,negative:58,typeof:60,delete:61};setLispType(["inverse","not","negative","positive","typeof","delete"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(r[0].length),[/^([^\s\.\?\w\$]|\?[^\.])/]);o.lispTree=lispify(e,n.substring(s.length+r[0].length),restOfExp.next,createLisp({op:modifierTypes[t],a:o.lispTree,b:lispify(e,s,expectTypes[i].next)}))}));const incrementTypes={"++$":25,"--$":27,"$++":26,"$--":28};setLispType(["incrementerBefore"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(2),[/^[^\s\.\w\$]/]);o.lispTree=lispify(e,n.substring(s.length+2),restOfExp.next,createLisp({op:incrementTypes[r[0]+"$"],a:lispify(e,s,expectTypes[i].next),b:0}))})),setLispType(["incrementerAfter"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:incrementTypes["$"+r[0]],a:o.lispTree,b:0}))}));const adderTypes={"&&":29,"||":30,instanceof:62,in:63,"=":9,"-=":65,"+=":66,"/=":67,"**=":68,"*=":69,"%=":70,"^=":71,"&=":72,"|=":73,">>>=":74,"<<=":76,">>=":75};setLispType(["assign","assignModify","boolOp"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:adderTypes[r[0]],a:o.lispTree,b:lispify(e,n.substring(r[0].length),expectTypes[i].next)})}));const opTypes={"&":77,"|":78,"^":79,"<<":80,">>":81,">>>":82,"<=":54,">=":55,"<":56,">":57,"!==":31,"!=":53,"===":32,"==":52,"+":33,"-":47,"/":48,"**":49,"*":50,"%":51};function extractIfElse(e,t){let n,r,i=0,o=t.substring(0,0),s=emptyString,a=!0,c={};for(;(o=restOfExp(e,t.substring(o.end-t.start),[elseIf,ifElse,semiColon],void 0,void 0,void 0,c)).length||a;){a=!1;const l=t.substring(o.end-t.start).toString();if(l.startsWith("if"))o.end++,i++;else if(l.startsWith("else"))n=t.substring(0,o.end-t.start),o.end++,i--,i||o.end--;else{if(!(r=/^;?\s*else(?![\w\$])/.exec(l))){n=s.length?n:t.substring(0,o.end-t.start);break}n=t.substring(0,o.end-t.start),o.end+=r[0].length-1,i--,i||(o.end-=r[0].length-1)}if(!i){s=extractIfElse(e,t.substring(o.end-t.start+/^;?\s*else(?![\w\$])/.exec(l)?.[0].length)).all;break}c={}}return n=n||t.substring(0,o.end-t.start),{all:t.substring(0,Math.max(n.end,s.end)-t.start),true:n,false:s}}setLispType(["opHigh","op","comparitor","bitwise"],((e,t,n,r,i,o)=>{const s=[expectTypes.inlineIf.types.inlineIf,inlineIfElse];switch(t){case"opHigh":s.push(expectTypes.splitter.types.opHigh);case"op":s.push(expectTypes.splitter.types.op);case"comparitor":s.push(expectTypes.splitter.types.comparitor);case"bitwise":s.push(expectTypes.splitter.types.bitwise),s.push(expectTypes.splitter.types.boolOp)}let a=restOfExp(e,n.substring(r[0].length),s);o.lispTree=lispify(e,n.substring(a.length+r[0].length),restOfExp.next,createLisp({op:opTypes[r[0]],a:o.lispTree,b:lispify(e,a,expectTypes[i].next)}))})),setLispType(["inlineIf"],((e,t,n,r,i,o)=>{let s=!1,a=n.substring(0,0),c=1;for(;!s&&a.length<n.length;)a.end=restOfExp(e,n.substring(a.length+1),[expectTypes.inlineIf.types.inlineIf,inlineIfElse]).end,"?"===n.char(a.length)?c++:c--,c||(s=!0);a.start=n.start+1,o.lispTree=createLisp({op:15,a:o.lispTree,b:createLisp({op:16,a:lispifyExpr(e,a),b:lispifyExpr(e,n.substring(r[0].length+a.length+1))})})})),setLispType(["if"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(r[0].length),[],"(");const a=extractIfElse(e,n.substring(r[1].length));/^\s*\{/.exec(n.substring(r[0].length+s.length+1).toString());const c=r[0].length-r[1].length+s.length+1;let l=a.true.substring(c),d=a.false;s=s.trim(),l=l.trim(),d=d.trim(),"{"===l.char(0)&&(l=l.slice(1,-1)),"{"===d.char(0)&&(d=d.slice(1,-1)),o.lispTree=createLisp({op:13,a:lispifyExpr(e,s),b:createLisp({op:14,a:lispifyBlock(l,e),b:lispifyBlock(d,e)})})})),setLispType(["switch"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[],"(");let a=n.toString().indexOf("{",r[0].length+s.length+1);if(-1===a)throw new SyntaxError("Invalid switch");let c,l=insertSemicolons(e,restOfExp(e,n.substring(a+1),[],"{"));const d=/^\s*(case\s|default)\s*/;let p=[],u=!1;for(;c=d.exec(l.toString());){if("default"===c[1]){if(u)throw new SyntaxError("Only one default switch case allowed");u=!0}let t=restOfExp(e,l.substring(c[0].length),[/^:/]),n=emptyString,r=a=c[0].length+t.length+1,i=/^\s*\{/.exec(l.substring(r).toString()),o=[];if(i)r+=i[0].length,n=restOfExp(e,l.substring(r),[],"{"),r+=n.length+1,o=lispifyBlock(n,e);else{let t=restOfExp(e,l.substring(r),[d]);if(t.trim().length){for(;(n=restOfExp(e,l.substring(r),[semiColon])).length&&(r+=n.length+(";"===l.char(r+n.length)?1:0),!d.test(l.substring(r).toString())););o=lispifyBlock(l.substring(a,n.end-l.start),e)}else o=[],r+=t.length}l=l.substring(r),p.push(createLisp({op:41,a:"default"===c[1]?void 0:lispifyExpr(e,t),b:o}))}o.lispTree=createLisp({op:40,a:lispifyExpr(e,s),b:p})})),setLispType(["dot","prop"],((e,t,n,r,i,o)=>{let s=r[0],a=r[0].length,c="prop";if("dot"===t){r[1]&&(c="?prop");let e=n.substring(r[0].length).toString().match(expectTypes.prop.types.prop);if(!e||!e.length)throw new SyntaxError("Hanging dot");s=e[0],a=s.length+r[0].length}o.lispTree=lispify(e,n.substring(a),expectTypes[i].next,createLisp({op:typesCreate[c],a:o.lispTree,b:s}))})),setLispType(["spreadArray","spreadObject"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:"spreadArray"===t?18:17,a:0,b:lispify(e,n.substring(r[0].length),expectTypes[i].next)})})),setLispType(["return","throw"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:"return"===t?8:46,a:0,b:lispifyExpr(e,n.substring(r[0].length))})})),setLispType(["number","boolean","null","und","NaN","Infinity"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:"number"===t?r[10]?83:7:35,a:0,b:r[10]?r[1]:r[0]}))})),setLispType(["string","literal","regex"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:"string"===t?2:"literal"===t?84:85,a:0,b:r[1]}))})),setLispType(["initialize"],((e,t,n,r,i,o)=>{const s="var"===r[1]?34:"let"===r[1]?3:4;r[3]?o.lispTree=createLisp({op:s,a:r[2],b:lispify(e,n.substring(r[0].length),expectTypes[i].next)}):o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:s,a:r[2],b:0}))})),setLispType(["function","inlineFunction","arrowFunction","arrowFunctionSingle"],((e,t,n,r,i,o)=>{const s="function"!==t&&"inlineFunction"!==t,a=s&&!r[r.length-1],c=s?2:3,l=r[1]?88:0,d=r[c]?r[c].replace(/\s+/g,"").split(/,/g):[];s||d.unshift((r[2]||"").trimStart());let p=!1;d.forEach((e=>{if(p)throw new SyntaxError("Rest parameter must be last formal parameter");e.startsWith("...")&&(p=!0)})),d.unshift(l);const u=restOfExp(e,n.substring(r[0].length),a?[/^[,\)\}\]]/,semiColon]:[/^}/]),f=a?"return "+u:u.toString();o.lispTree=lispify(e,n.substring(r[0].length+f.length+1),expectTypes[i].next,createLisp({op:s?11:"function"===t?37:10,a:d,b:e.eager?lispifyFunction(new CodeString(f),e):f}))}));const iteratorRegex=/^((let|var|const)\s+)?\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s+(in|of)(?![\w\$])/;setLispType(["for","do","while"],((e,t,n,r,i,o)=>{let s,a,c,l=0,d=88,p=[],u=0,f=88,h=88;switch(t){case"while":l=n.toString().indexOf("(")+1;let t=restOfExp(e,n.substring(l),[],"(");a=lispifyReturnExpr(e,t),c=restOfExp(e,n.substring(l+t.length+1)).trim(),"{"===c[0]&&(c=c.slice(1,-1));break;case"for":l=n.toString().indexOf("(")+1;let i,o=[],g=emptyString;for(let t=0;t<3&&(g=restOfExp(e,n.substring(l),[/^[;\)]/]),o.push(g.trim()),l+=g.length+1,")"!==n.char(l-1));t++);if(1===o.length&&(i=iteratorRegex.exec(o[0].toString())))"of"===i[4]?(s=lispifyReturnExpr(e,o[0].substring(i[0].length)),p=[ofStart2,ofStart3],a=ofCondition,h=ofStep,u=lispify(e,new CodeString((i[1]||"let ")+i[3]+" = $$next.value"),["initialize"])):(s=lispifyReturnExpr(e,o[0].substring(i[0].length)),p=[inStart2,inStart3],h=inStep,a=inCondition,u=lispify(e,new CodeString((i[1]||"let ")+i[3]+" = $$keys[$$keyIndex]"),["initialize"]));else{if(3!==o.length)throw new SyntaxError("Invalid for loop definition");d=lispifyExpr(e,o.shift(),startingExecpted),a=lispifyReturnExpr(e,o.shift()),h=lispifyExpr(e,o.shift())}c=restOfExp(e,n.substring(l)).trim(),"{"===c[0]&&(c=c.slice(1,-1));break;case"do":f=0;const y=!!r[3];c=restOfExp(e,n.substring(r[0].length),y?[/^\}/]:[semiColon]),a=lispifyReturnExpr(e,restOfExp(e,n.substring(n.toString().indexOf("(",r[0].length+c.length)+1),[],"("))}const g=[f,p,s,d,h,a,u];o.lispTree=createLisp({op:38,a:g,b:lispifyBlock(c,e)})})),setLispType(["block"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:42,a:lispifyBlock(restOfExp(e,n.substring(1),[],"{"),e),b:0})})),setLispType(["loopAction"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:86,a:r[1],b:0})}));const catchReg=/^\s*(catch\s*(\(\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\))?|finally)\s*\{/;setLispType(["try"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[],"{");let a,c,l=catchReg.exec(n.substring(r[0].length+s.length+1).toString()),d="",p=0;l[1].startsWith("catch")?(l=catchReg.exec(n.substring(r[0].length+s.length+1).toString()),d=l[2],c=restOfExp(e,n.substring(r[0].length+s.length+1+l[0].length),[],"{"),p=r[0].length+s.length+1+l[0].length+c.length+1,(l=catchReg.exec(n.substring(p).toString()))&&l[1].startsWith("finally")&&(a=restOfExp(e,n.substring(p+l[0].length),[],"{"))):a=restOfExp(e,n.substring(r[0].length+s.length+1+l[0].length),[],"{");const u=[d,lispifyBlock(insertSemicolons(e,c||emptyString),e),lispifyBlock(insertSemicolons(e,a||emptyString),e)];o.lispTree=createLisp({op:39,a:lispifyBlock(insertSemicolons(e,s),e),b:u})})),setLispType(["void","await"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[/^([^\s\.\?\w\$]|\?[^\.])/]);o.lispTree=lispify(e,n.substring(r[0].length+s.length),expectTypes[i].next,createLisp({op:"void"===t?87:44,a:lispify(e,s),b:0}))})),setLispType(["new"],((e,t,n,r,i,o)=>{let s=r[0].length;const a=restOfExp(e,n.substring(s),[],void 0,"(");s+=a.length+1;const c=[];if("("===n.char(s-1)){const t=restOfExp(e,n.substring(s),[],"(");let r;s+=t.length+1;let i=0;for(;(r=restOfExp(e,t.substring(i),[/^,/])).length;)i+=r.length+1,c.push(r.trim())}o.lispTree=lispify(e,n.substring(s),expectTypes.expEdge.next,createLisp({op:45,a:lispify(e,a,expectTypes.initialize.next),b:c.map((t=>lispify(e,t,expectTypes.initialize.next)))}))}));const ofStart2=lispify(void 0,new CodeString("let $$iterator = $$obj[Symbol.iterator]()"),["initialize"]),ofStart3=lispify(void 0,new CodeString("let $$next = $$iterator.next()"),["initialize"]),ofCondition=lispify(void 0,new CodeString("return !$$next.done"),["initialize"]),ofStep=lispify(void 0,new CodeString("$$next = $$iterator.next()")),inStart2=lispify(void 0,new CodeString("let $$keys = Object.keys($$obj)"),["initialize"]),inStart3=lispify(void 0,new CodeString("let $$keyIndex = 0"),["initialize"]),inStep=lispify(void 0,new CodeString("$$keyIndex++")),inCondition=lispify(void 0,new CodeString("return $$keyIndex < $$keys.length"),["initialize"]);var lastType;function lispify(e,t,n,r,i=!1){if(r=r||[0,0,0],n=n||expectTypes.initialize.next,void 0===t)return r;const o=(t=t.trimStart()).toString();if(!t.length&&!n.includes("expEnd"))throw new SyntaxError("Unexpected end of expression");if(!t.length)return r;let s,a={lispTree:r};for(let r of n)if("expEnd"!==r){for(let n in expectTypes[r].types)if("expEnd"!==n&&(s=expectTypes[r].types[n].exec(o))){lastType=n;try{lispTypes.get(n)(e,n,t,s,r,a)}catch(e){if(i&&e instanceof SyntaxError)throw new ParseError(e.message,o);throw e}break}if(s)break}if(!s&&t.length){if(t.char(0),i)throw new ParseError(`Unexpected token after ${lastType}: ${t.char(0)}`,o);throw new SyntaxError(`Unexpected token after ${lastType}: ${t.char(0)}`)}return a.lispTree}const startingExpectedWithoutSingle=startingExecpted.filter((e=>"expSingle"!==e));function lispifyExpr(e,t,n){if(!t.trimStart().length)return;let r,i=[],o=0;if((n=n||expectTypes.initialize.next).includes("expSingle")&&testMultiple(t.toString(),Object.values(expectTypes.expSingle.types)))return lispify(e,t,["expSingle"],void 0,!0);for(n===startingExecpted&&(n=startingExpectedWithoutSingle);(r=restOfExp(e,t.substring(o),[/^,/])).length;)i.push(r.trimStart()),o+=r.length+1;if(1===i.length)return lispify(e,t,n,void 0,!0);if(n.includes("initialize")){let r=expectTypes.initialize.types.initialize.exec(i[0].toString());if(r)return createLisp({op:42,a:i.map(((t,n)=>lispify(e,n?new CodeString(r[1]+" "+t):t,["initialize"],void 0,!0))),b:0});if(expectTypes.initialize.types.return.exec(i[0].toString()))return lispify(e,t,n,void 0,!0)}const s=i.map(((t,r)=>lispify(e,t,n,void 0,!0)));return createLisp({op:43,a:s,b:0})}function lispifyReturnExpr(e,t){return createLisp({op:8,a:0,b:lispifyExpr(e,t)})}function lispifyBlock(e,t,n=!1){if(!(e=insertSemicolons(t,e)).trim().length)return[];let r,i=[],o=0,s=0,a={},c=!1,l=!1;for(;(r=restOfExp(t,e.substring(o),[semiColon],void 0,void 0,void 0,a)).length&&(l=e.char(o+r.length)&&";"!==e.char(o+r.length),o+=r.length+(l?0:1),/^\s*else(?![\w\$])/.test(e.substring(o).toString())||a.words.includes("do")&&/^\s*while(?![\w\$])/.test(e.substring(o).toString())?c=!0:(c=!1,i.push(e.substring(s,o-(l?0:1))),s=o),a={},!n););return c&&i.push(e.substring(s,o-(l?0:1))),i.map((e=>e.trimStart())).filter((e=>e.length)).map(((e,n)=>lispifyExpr(t,e.trimStart(),startingExecpted)))}function lispifyFunction(e,t,n=!1){if(!e.trim().length)return[];const r=lispifyBlock(e,t,n);let i=[];return hoist(r,i),i.concat(r)}function isLisp(e){return Array.isArray(e)&&"number"==typeof e[0]&&0!==e[0]&&88!==e[0]}function hoist(e,t){if(isLisp(e)){const[n,r,i]=e;if(39===n||13===n||38===n||40===n)hoist(r,t),hoist(i,t);else if(34===n)t.push(createLisp({op:34,a:r,b:0}));else if(37===n&&r[1])return t.push(e),!0}else if(Array.isArray(e)){const n=[];for(let r of e)hoist(r,t)||n.push(r);n.length!==e.length&&(e.length=0,e.push(...n))}return!1}const closingsNoInsertion=/^(\})\s*(catch|finally|else|while|instanceof)(?![\w\$])/,colonsRegex=/^((([\w\$\]\)\"\'\`]|\+\+|\-\-)\s*\r?\n\s*([\w\$\+\-\!~]))|(\}\s*[\w\$\!~\+\-\{\(\"\'\`]))/;function insertSemicolons(e,t){let n=t,r=emptyString,i={};const o=insertedSemicolons.get(t.ref)||new Array(t.ref.str.length);for(;(r=restOfExp(e,n,[],void 0,void 0,[colonsRegex],i)).length;){let e=!1,t=r,s=r.length;if(i.regRes){e=!0;const[,,o,,,a]=i.regRes;if(s="++"===i.regRes[3]||"--"===i.regRes[3]?r.length+1:r.length,t=n.substring(0,s),a){let t=closingsNoInsertion.exec(n.substring(r.length-1).toString());t?e="while"===t[2]&&"do"!==i.lastWord:"function"===i.lastWord&&"}"===i.regRes[5][0]&&"("===i.regRes[5].slice(-1)&&(e=!1)}else o&&("if"!==i.lastWord&&"while"!==i.lastWord&&"for"!==i.lastWord&&"else"!==i.lastWord||(e=!1))}e&&(o[t.end]=!0),n=n.substring(s),i={}}return insertedSemicolons.set(t.ref,o),t}function checkRegex(e){let t=1,n=!1,r=!1,i=!1;for(;t<e.length&&!r&&!i;)r="/"===e[t]&&!n,n="\\"===e[t]&&!n,i="\n"===e[t],t++;let o=e.substring(t);if(i=i||!r||/^\s*\d/.test(o),i)return null;let s=/^[a-z]*/.exec(o);return/^\s+[\w\$]/.test(e.substring(t+s[0].length))?null:{regex:e.substring(1,t-1),flags:s&&s[0]||"",length:t+(s&&s[0].length||0)}}const notDivide=/(typeof|delete|instanceof|return|in|of|throw|new|void|do|if)$/,possibleDivide=/^([\w\$\]\)]|\+\+|\-\-)[\s\/]/;function extractConstants(e,t,n=""){let r,i,o=[],s=!1,a="",c=-1,l=[],d="";const p=[],u=[];let f;for(var h=0;h<t.length;h++)if(d=t[h],a)d===a&&("*"===a&&"/"===t[h+1]?(a="",h++):"\n"===a&&(a=""));else{if(s){s=!1,o.push(d);continue}if(r)if("`"===r&&"$"===d&&"{"===t[h+1]){let n=extractConstants(e,t.substring(h+2),"{");l.push(n.str),o.push("${",l.length-1,"}"),h+=n.length+2}else if(r===d){if("`"===r){const t=createLisp({op:36,a:unraw(o.join("")),b:[]});t.tempJsStrings=l,e.literals.push(t),p.push("`",e.literals.length-1,"`")}else e.strings.push(unraw(o.join(""))),p.push('"',e.strings.length-1,'"');r=null,o=[]}else o.push(d);else{if("'"===d||'"'===d||"`"===d)l=[],r=d;else{if(closings[n]===d&&!u.length)return{str:p.join(""),length:h};closings[d]?(u.push(d),p.push(d)):closings[u[u.length-1]]===d?(u.pop(),p.push(d)):"/"!==d||"*"!==t[h+1]&&"/"!==t[h+1]?"/"===d&&!f&&(i=checkRegex(t.substring(h)))?(e.regexes.push(i),p.push("/",e.regexes.length-1,"/r"),h+=i.length-1):p.push(d):(a="*"===t[h+1]?"*":"\n",c=h)}f&&space.test(d)||(f=possibleDivide.exec(t.substring(h)))&&notDivide.test(t.substring(0,h+f[1].length))&&(f=null)}s=r&&"\\"===d}if(a&&"*"===a)throw new SyntaxError(`Unclosed comment '/*': ${t.substring(c)}`);return{str:p.join(""),length:h}}function parse$2(e,t=!1,n=!1){if("string"!=typeof e)throw new ParseError(`Cannot parse ${e}`,e);let r=" "+e;const i={strings:[],literals:[],regexes:[],eager:t};r=extractConstants(i,r).str;for(let e of i.literals)e[2]=e.tempJsStrings.map((e=>lispifyExpr(i,new CodeString(e)))),delete e.tempJsStrings;return{tree:lispifyFunction(new CodeString(r),i,n),constants:i}}class ExecReturn{constructor(e,t,n,r=!1,i=!1){this.auditReport=e,this.result=t,this.returned=n,this.breakLoop=r,this.continueLoop=i}}class Prop{constructor(e,t,n=!1,r=!1,i=!1){this.context=e,this.prop=t,this.isConst=n,this.isGlobal=r,this.isVariable=i}get(e){if(void 0===this.context)throw new ReferenceError(`${this.prop} is not defined`);return e.getSubscriptions.forEach((e=>e(this.context,this.prop))),this.context[this.prop]}}const optional={},reservedWords=new Set(["instanceof","typeof","return","try","catch","if","finally","else","in","of","var","let","const","for","delete","false","true","while","do","break","continue","new","function","async","await","switch","case"]);var VarType;function keysOnly(e){const t=Object.assign({},e);for(let e in t)t[e]=!0;return t}!function(e){e.let="let",e.const="const",e.var="var"}(VarType||(VarType={}));class Scope{constructor(e,t={},n){this.const={},this.let={},this.var={};const r=void 0!==n||null===e;this.parent=e,this.allVars=t,this.let=r?this.let:keysOnly(t),this.var=r?keysOnly(t):this.var,this.globals=null===e?keysOnly(t):{},this.functionThis=n}get(e,t=!1){if("this"===e&&void 0!==this.functionThis)return new Prop({this:this.functionThis},e,!0,!1,!0);if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");if(null===this.parent||!t||void 0!==this.functionThis){if(this.globals.hasOwnProperty(e))return new Prop(this.functionThis,e,!1,!0,!0);if(e in this.allVars&&(!(e in{})||this.allVars.hasOwnProperty(e)))return new Prop(this.allVars,e,this.const.hasOwnProperty(e),this.globals.hasOwnProperty(e),!0);if(null===this.parent)return new Prop(void 0,e)}return this.parent.get(e,t)}set(e,t){if("this"===e)throw new SyntaxError('"this" cannot be assigned');if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");let n=this.get(e);if(void 0===n.context)throw new ReferenceError(`Variable '${e}' was not declared.`);if(n.isConst)throw new TypeError(`Cannot assign to const variable '${e}'`);if(n.isGlobal)throw new SandboxError(`Cannot override global variable '${e}'`);return n.context[n.prop]=t,n}declare(e,t=null,n=void 0,r=!1){if("this"===e)throw new SyntaxError('"this" cannot be declared');if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");if("var"===t&&void 0===this.functionThis&&null!==this.parent)return this.parent.declare(e,t,n,r);if((!this[t].hasOwnProperty(e)||"const"===t||this.globals.hasOwnProperty(e))&&e in this.allVars)throw new SandboxError(`Identifier '${e}' has already been declared`);return r&&(this.globals[e]=!0),this[t][e]=!0,this.allVars[e]=n,new Prop(this.allVars,e,this.const.hasOwnProperty(e),r)}}class LocalScope{}class SandboxError extends Error{}let currentTicks;function sandboxFunction(e,t){return function(...n){let r=parse$2(n.pop()||"");return createFunction(n,r.tree,t||currentTicks,{...e,constants:r.constants,tree:r.tree},void 0,"anonymous")}}function generateArgs(e,t){const n={};return e.forEach(((e,r)=>{e.startsWith("...")?n[e.substring(3)]=t.slice(r):n[e]=t[r]})),n}const sandboxedFunctions=new WeakSet;function createFunction(e,t,n,r,i,o){if(r.ctx.options.forbidFunctionCreation)throw new SandboxError("Function creation is forbidden");let s;return s=void 0===o?(...o)=>{const s=generateArgs(e,o);return executeTree(n,r,t,void 0===i?[]:[new Scope(i,s)]).result}:function(...o){const s=generateArgs(e,o);return executeTree(n,r,t,void 0===i?[]:[new Scope(i,s,this)]).result},r.registerSandboxFunction(s),sandboxedFunctions.add(s),s}function createFunctionAsync(e,t,n,r,i,o){if(r.ctx.options.forbidFunctionCreation)throw new SandboxError("Function creation is forbidden");if(!r.ctx.prototypeWhitelist?.has(Promise.prototype))throw new SandboxError("Async/await not permitted");let s;return s=void 0===o?async(...o)=>{const s=generateArgs(e,o);return(await executeTreeAsync(n,r,t,void 0===i?[]:[new Scope(i,s)])).result}:async function(...o){const s=generateArgs(e,o);return(await executeTreeAsync(n,r,t,void 0===i?[]:[new Scope(i,s,this)])).result},r.registerSandboxFunction(s),sandboxedFunctions.add(s),s}function sandboxedEval(e){return function(t){return e(t)()}}function sandboxedSetTimeout(e){return function(t,...n){return"string"!=typeof t?setTimeout(t,...n):setTimeout(e(t),...n)}}function sandboxedSetInterval(e){return function(t,...n){return"string"!=typeof t?setInterval(t,...n):setInterval(e(t),...n)}}function assignCheck(e,t,n="assign"){if(void 0===e.context)throw new ReferenceError(`Cannot ${n} value to undefined.`);if("object"!=typeof e.context&&"function"!=typeof e.context)throw new SyntaxError(`Cannot ${n} value to a primitive.`);if(e.isConst)throw new TypeError(`Cannot set value to const variable '${e.prop}'`);if(e.isGlobal)throw new SandboxError(`Cannot ${n} property '${e.prop}' of a global object`);if("function"==typeof e.context[e.prop]&&!e.context.hasOwnProperty(e.prop))throw new SandboxError(`Override prototype property '${e.prop}' not allowed`);"delete"===n?e.context.hasOwnProperty(e.prop)&&(t.changeSubscriptions.get(e.context)?.forEach((t=>t({type:"delete",prop:e.prop}))),t.changeSubscriptionsGlobal.get(e.context)?.forEach((t=>t({type:"delete",prop:e.prop})))):e.context.hasOwnProperty(e.prop)?(t.setSubscriptions.get(e.context)?.get(e.prop)?.forEach((e=>e({type:"replace"}))),t.setSubscriptionsGlobal.get(e.context)?.get(e.prop)?.forEach((e=>e({type:"replace"})))):(t.changeSubscriptions.get(e.context)?.forEach((t=>t({type:"create",prop:e.prop}))),t.changeSubscriptionsGlobal.get(e.context)?.forEach((t=>t({type:"create",prop:e.prop}))))}const arrayChange=new Set([[].push,[].pop,[].shift,[].unshift,[].splice,[].reverse,[].sort,[].copyWithin]);class KeyVal{constructor(e,t){this.key=e,this.val=t}}class SpreadObject{constructor(e){this.item=e}}class SpreadArray{constructor(e){this.item=e}}class If{constructor(e,t){this.t=e,this.f=t}}const literalRegex=/(\$\$)*(\$)?\${(\d+)}/g,ops=new Map;function addOps(e,t){ops.set(e,t)}function valueOrProp(e,t){return e instanceof Prop?e.get(t):e!==optional?e:void 0}function execMany(e,t,n,r,i,o,s){t===execSync?_execManySync(e,n,r,i,o,s):_execManyAsync(e,n,r,i,o,s).catch(r)}function _execManySync(e,t,n,r,i,o){let s=[];for(let a=0;a<t.length;a++){let c;try{c=syncDone((n=>execSync(e,t[a],r,i,n,o))).result}catch(e){return void n(e)}if(c instanceof ExecReturn&&(c.returned||c.breakLoop||c.continueLoop))return void n(void 0,c);if(isLisp(t[a])&&8===t[a][0])return void n(void 0,new ExecReturn(i.ctx.auditReport,c,!0));s.push(c)}n(void 0,s)}async function _execManyAsync(e,t,n,r,i,o){let s=[];for(let a=0;a<t.length;a++){let c;try{let n;c=!0===(n=asyncDone((n=>execAsync(e,t[a],r,i,n,o)))).isInstant?n.instant:(await n.p).result}catch(e){return void n(e)}if(c instanceof ExecReturn&&(c.returned||c.breakLoop||c.continueLoop))return void n(void 0,c);if(isLisp(t[a])&&8===t[a][0])return void n(void 0,new ExecReturn(i.ctx.auditReport,c,!0));s.push(c)}n(void 0,s)}function asyncDone(e){let t,n=!1;const r=new Promise(((r,i)=>{e(((e,o)=>{e?i(e):(n=!0,t=o,r({result:o}))}))}));return{isInstant:n,instant:t,p:r}}function syncDone(e){let t,n;if(e(((e,r)=>{n=e,t=r})),n)throw n;return{result:t}}async function execAsync(e,t,n,r,i,o){let s=i;const a=new Promise((e=>{s=(t,n)=>{i(t,n),e()}}));if(_execNoneRecurse(e,t,n,r,s,!0,o));else if(isLisp(t)){let i,a=t[0];try{let s;i=!0===(s=asyncDone((i=>execAsync(e,t[1],n,r,i,o)))).isInstant?s.instant:(await s.p).result}catch(e){return void s(e)}let c,l=i;try{l=i instanceof Prop?i.get(r):i}catch(e){return void s(e)}if(20===a||21===a){if(null==l)return void s(void 0,optional);a=20===a?1:5}if(l===optional){if(1===a||5===a)return void s(void 0,l);l=void 0}try{let i;c=!0===(i=asyncDone((i=>execAsync(e,t[2],n,r,i,o)))).isInstant?i.instant:(await i.p).result}catch(e){return void s(e)}let d=c;try{d=c instanceof Prop?c.get(r):c}catch(e){return void s(e)}if(d===optional&&(d=void 0),ops.has(a))try{ops.get(a)(execAsync,s,e,l,d,i,r,n,c,o)}catch(e){s(e)}else s(new SyntaxError("Unknown operator: "+a))}await a}function execSync(e,t,n,r,i,o){if(_execNoneRecurse(e,t,n,r,i,!1,o));else if(isLisp(t)){let s,a=t[0];try{s=syncDone((i=>execSync(e,t[1],n,r,i,o))).result}catch(e){return void i(e)}let c,l=s;try{l=s instanceof Prop?s.get(r):s}catch(e){return void i(e)}if(20===a||21===a){if(null==l)return void i(void 0,optional);a=20===a?1:5}if(l===optional){if(1===a||5===a)return void i(void 0,l);l=void 0}try{c=syncDone((i=>execSync(e,t[2],n,r,i,o))).result}catch(e){return void i(e)}let d=c;try{d=c instanceof Prop?c.get(r):c}catch(e){return void i(e)}if(d===optional&&(d=void 0),ops.has(a))try{ops.get(a)(execSync,i,e,l,d,s,r,n,c,o)}catch(e){i(e)}else i(new SyntaxError("Unknown operator: "+a))}}addOps(1,((e,t,n,r,i,o,s,a)=>{if(null===r)throw new TypeError(`Cannot get property ${i} of null`);const c=typeof r;if("undefined"===c&&void 0===o){let e=a.get(i);if(e.context===s.ctx.sandboxGlobal){s.ctx.options.audit&&s.ctx.auditReport.globalsAccess.add(i);const e=s.ctx.globalsWhitelist.has(s.ctx.sandboxGlobal[i])?s.evals.get(s.ctx.sandboxGlobal[i]):void 0;if(e)return void t(void 0,e)}return e.context&&e.context[i]===globalThis?void t(void 0,s.ctx.globalScope.get("this")):void t(void 0,e)}if(void 0===r)throw new SandboxError("Cannot get property '"+i+"' of undefined");if("object"!==c)"number"===c?r=new Number(r):"string"===c?r=new String(r):"boolean"===c&&(r=new Boolean(r));else if(void 0===r.hasOwnProperty)return void t(void 0,new Prop(void 0,i));const l="function"===c;let d=l||!(r.hasOwnProperty(i)||"number"==typeof i);if(s.ctx.options.audit&&d&&"string"==typeof i){let e=Object.getPrototypeOf(r);do{e.hasOwnProperty(i)&&(s.ctx.auditReport.prototypeAccess[e.constructor.name]||(s.ctx.auditReport.prototypeAccess[e.constructor.name]=new Set),s.ctx.auditReport.prototypeAccess[e.constructor.name].add(i))}while(e=Object.getPrototypeOf(e))}if(d)if(l){if(!["name","length","constructor"].includes(i)&&r.hasOwnProperty(i)){const e=s.ctx.prototypeWhitelist.get(r.prototype),n=s.ctx.options.prototypeReplacements.get(r);if(n)return void t(void 0,new Prop(n(r,!0),i));if(!e||e.size&&!e.has(i))throw new SandboxError(`Static method or property access not permitted: ${r.name}.${i}`)}}else if("constructor"!==i){let e=r;for(;e=Object.getPrototypeOf(e);)if(e.hasOwnProperty(i)){const n=s.ctx.prototypeWhitelist.get(e),o=s.ctx.options.prototypeReplacements.get(e.constuctor);if(o)return void t(void 0,new Prop(o(r,!1),i));if(n&&(!n.size||n.has(i)))break;throw new SandboxError(`Method or property access not permitted: ${e.constructor.name}.${i}`)}}if(s.evals.has(r[i]))return void t(void 0,s.evals.get(r[i]));if(r[i]===globalThis)return void t(void 0,s.ctx.globalScope.get("this"));let p=o.isGlobal||l&&!sandboxedFunctions.has(r)||s.ctx.globalsWhitelist.has(r);t(void 0,new Prop(r,i,!1,p))})),addOps(5,((e,t,n,r,i,o,s,a)=>{if(s.ctx.options.forbidFunctionCalls)throw new SandboxError("Function invocations are not allowed");if("function"!=typeof r)throw new TypeError(`${"symbol"==typeof o.prop?"Symbol":o.prop} is not a function`);const c=i.map((e=>e instanceof SpreadArray?[...e.item]:[e])).flat().map((e=>valueOrProp(e,s)));if("function"!=typeof o){if(o.context[o.prop]===JSON.stringify&&s.getSubscriptions.size){const e=new Set,t=n=>{if(n&&"object"==typeof n&&!e.has(n)){e.add(n);for(let e in n)s.getSubscriptions.forEach((t=>t(n,e))),t(n[e])}};t(c[0])}if(o.context instanceof Array&&arrayChange.has(o.context[o.prop])&&(s.changeSubscriptions.get(o.context)||s.changeSubscriptionsGlobal.get(o.context))){let e,t=!1;if("push"===o.prop)e={type:"push",added:c},t=!!c.length;else if("pop"===o.prop)e={type:"pop",removed:o.context.slice(-1)},t=!!e.removed.length;else if("shift"===o.prop)e={type:"shift",removed:o.context.slice(0,1)},t=!!e.removed.length;else if("unshift"===o.prop)e={type:"unshift",added:c},t=!!c.length;else if("splice"===o.prop)e={type:"splice",startIndex:c[0],deleteCount:void 0===c[1]?o.context.length:c[1],added:c.slice(2),removed:o.context.slice(c[0],void 0===c[1]?void 0:c[0]+c[1])},t=!!e.added.length||!!e.removed.length;else if("reverse"===o.prop||"sort"===o.prop)e={type:o.prop},t=!!o.context.length;else if("copyWithin"===o.prop){let n=void 0===c[2]?o.context.length-c[1]:Math.min(o.context.length,c[2]-c[1]);e={type:"copyWithin",startIndex:c[0],endIndex:c[0]+n,added:o.context.slice(c[1],c[1]+n),removed:o.context.slice(c[0],c[0]+n)},t=!!e.added.length||!!e.removed.length}t&&(s.changeSubscriptions.get(o.context)?.forEach((t=>t(e))),s.changeSubscriptionsGlobal.get(o.context)?.forEach((t=>t(e))))}o.get(s),t(void 0,o.context[o.prop](...c))}else t(void 0,o(...c))})),addOps(22,((e,t,n,r,i,o,s,a)=>{let c={};for(let e of i)e.key instanceof SpreadObject?c={...c,...e.key.item}:c[e.key]=e.val;t(void 0,c)})),addOps(6,((e,t,n,r,i)=>t(void 0,new KeyVal(r,i)))),addOps(12,((e,t,n,r,i,o,s,a)=>{t(void 0,i.map((e=>e instanceof SpreadArray?[...e.item]:[e])).flat().map((e=>valueOrProp(e,s))))})),addOps(23,((e,t,n,r,i)=>t(void 0,i))),addOps(35,((e,t,n,r,i)=>{switch(i){case"true":return t(void 0,!0);case"false":return t(void 0,!1);case"null":return t(void 0,null);case"undefined":return t(void 0,void 0);case"NaN":return t(void 0,NaN);case"Infinity":return t(void 0,1/0)}t(new Error("Unknown symbol: "+i))})),addOps(7,((e,t,n,r,i)=>t(void 0,Number(i)))),addOps(83,((e,t,n,r,i)=>t(void 0,BigInt(i)))),addOps(2,((e,t,n,r,i,o,s)=>t(void 0,s.constants.strings[parseInt(i)]))),addOps(85,((e,t,n,r,i,o,s)=>{const a=s.constants.regexes[parseInt(i)];if(!s.ctx.globalsWhitelist.has(RegExp))throw new SandboxError("Regex not permitted");t(void 0,new RegExp(a.regex,a.flags))})),addOps(84,((e,t,n,r,i,o,s,a)=>{let c=s.constants.literals[parseInt(i)];const[,l,d]=c;let p,u=[],f=[];for(;p=literalRegex.exec(l);)p[2]||(u.push(d[parseInt(p[3],10)]),f.push(p[3]));e(n,u,a,s,((e,n)=>{const r={};if(e)t(e);else{for(let e in f){const t=f[e];r[t]=n[e]}t(void 0,l.replace(/(\\\\)*(\\)?\${(\d+)}/g,((e,t,n,i)=>{if(n)return e;return(t||"")+`${valueOrProp(r[i],s)}`})))}}))})),addOps(18,((e,t,n,r,i,o,s,a)=>{t(void 0,new SpreadArray(i))})),addOps(17,((e,t,n,r,i,o,s,a)=>{t(void 0,new SpreadObject(i))})),addOps(24,((e,t,n,r,i)=>t(void 0,!i))),addOps(64,((e,t,n,r,i)=>t(void 0,~i))),addOps(25,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,++o.context[o.prop])})),addOps(26,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]++)})),addOps(27,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,--o.context[o.prop])})),addOps(28,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]--)})),addOps(9,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]=i)})),addOps(66,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]+=i)})),addOps(65,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]-=i)})),addOps(67,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]/=i)})),addOps(69,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]*=i)})),addOps(68,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]**=i)})),addOps(70,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]%=i)})),addOps(71,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]^=i)})),addOps(72,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]&=i)})),addOps(73,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]|=i)})),addOps(76,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]<<=i)})),addOps(75,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]>>=i)})),addOps(74,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]>>=i)})),addOps(57,((e,t,n,r,i)=>t(void 0,r>i))),addOps(56,((e,t,n,r,i)=>t(void 0,r<i))),addOps(55,((e,t,n,r,i)=>t(void 0,r>=i))),addOps(54,((e,t,n,r,i)=>t(void 0,r<=i))),addOps(52,((e,t,n,r,i)=>t(void 0,r==i))),addOps(32,((e,t,n,r,i)=>t(void 0,r===i))),addOps(53,((e,t,n,r,i)=>t(void 0,r!=i))),addOps(31,((e,t,n,r,i)=>t(void 0,r!==i))),addOps(29,((e,t,n,r,i)=>t(void 0,r&&i))),addOps(30,((e,t,n,r,i)=>t(void 0,r||i))),addOps(77,((e,t,n,r,i)=>t(void 0,r&i))),addOps(78,((e,t,n,r,i)=>t(void 0,r|i))),addOps(33,((e,t,n,r,i)=>t(void 0,r+i))),addOps(47,((e,t,n,r,i)=>t(void 0,r-i))),addOps(59,((e,t,n,r,i)=>t(void 0,+i))),addOps(58,((e,t,n,r,i)=>t(void 0,-i))),addOps(48,((e,t,n,r,i)=>t(void 0,r/i))),addOps(79,((e,t,n,r,i)=>t(void 0,r^i))),addOps(50,((e,t,n,r,i)=>t(void 0,r*i))),addOps(51,((e,t,n,r,i)=>t(void 0,r%i))),addOps(80,((e,t,n,r,i)=>t(void 0,r<<i))),addOps(81,((e,t,n,r,i)=>t(void 0,r>>i))),addOps(82,((e,t,n,r,i)=>t(void 0,r>>>i))),addOps(60,((e,t,n,r,i,o,s,a)=>{e(n,i,a,s,((e,n)=>{t(void 0,typeof valueOrProp(n,s))}))})),addOps(62,((e,t,n,r,i)=>t(void 0,r instanceof i))),addOps(63,((e,t,n,r,i)=>t(void 0,r in i))),addOps(61,((e,t,n,r,i,o,s,a,c)=>{void 0!==c.context?(assignCheck(c,s,"delete"),c.isVariable?t(void 0,!1):t(void 0,delete c.context[c.prop])):t(void 0,!0)})),addOps(8,((e,t,n,r,i,o,s)=>t(void 0,i))),addOps(34,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.var,i))})),addOps(3,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.let,i,c&&c.isGlobal))})),addOps(4,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.const,i))})),addOps(11,((e,t,n,r,i,o,s,a)=>{r=[...r],("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants)),r.shift()?t(void 0,createFunctionAsync(r,i,n,s,a)):t(void 0,createFunction(r,i,n,s,a))})),addOps(37,((e,t,n,r,i,o,s,a)=>{("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants));let c,l=r.shift(),d=r.shift();c=88===l?createFunctionAsync(r,i,n,s,a,d):createFunction(r,i,n,s,a,d),d&&a.declare(d,VarType.var,c),t(void 0,c)})),addOps(10,((e,t,n,r,i,o,s,a)=>{("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants));let c,l=r.shift(),d=r.shift();d&&(a=new Scope(a,{})),c=88===l?createFunctionAsync(r,i,n,s,a,d):createFunction(r,i,n,s,a,d),d&&a.declare(d,VarType.let,c),t(void 0,c)})),addOps(38,((e,t,n,r,i,o,s,a)=>{const[c,l,d,p,u,f,h]=r;let g=!0;const y=new Scope(a,{});let x={$$obj:void 0};const v=new Scope(y,x);if(e===execAsync)(async()=>{let r;for(r=asyncDone((t=>e(n,p,y,s,t))),x.$$obj=!0===(r=asyncDone((t=>e(n,d,y,s,t)))).isInstant?r.instant:(await r.p).result,r=asyncDone((t=>e(n,l,v,s,t))),c&&(g=!0===(r=asyncDone((t=>e(n,f,v,s,t)))).isInstant?r.instant:(await r.p).result);g;){let o={};r=asyncDone((t=>e(n,h,new Scope(v,o),s,t))),!0===r.isInstant?r.instant:(await r.p).result;let a=await executeTreeAsync(n,s,i,[new Scope(y,o)],"loop");if(a instanceof ExecReturn&&a.returned)return void t(void 0,a);if(a instanceof ExecReturn&&a.breakLoop)break;r=asyncDone((t=>e(n,u,v,s,t))),g=!0===(r=asyncDone((t=>e(n,f,v,s,t)))).isInstant?r.instant:(await r.p).result}t()})().catch(t);else{for(syncDone((t=>e(n,p,y,s,t))),x.$$obj=syncDone((t=>e(n,d,y,s,t))).result,syncDone((t=>e(n,l,v,s,t))),c&&(g=syncDone((t=>e(n,f,v,s,t))).result);g;){let r={};syncDone((t=>e(n,h,new Scope(v,r),s,t)));let o=executeTree(n,s,i,[new Scope(y,r)],"loop");if(o instanceof ExecReturn&&o.returned)return void t(void 0,o);if(o instanceof ExecReturn&&o.breakLoop)break;syncDone((t=>e(n,u,v,s,t))),g=syncDone((t=>e(n,f,v,s,t))).result}t()}})),addOps(86,((e,t,n,r,i,o,s,a,c,l)=>{if("switch"===l&&"continue"===r||!l)throw new SandboxError("Illegal "+r+" statement");t(void 0,new ExecReturn(s.ctx.auditReport,void 0,!1,"break"===r,"continue"===r))})),addOps(13,((e,t,n,r,i,o,s,a,c,l)=>{e(n,valueOrProp(r,s)?i.t:i.f,a,s,t)})),addOps(15,((e,t,n,r,i,o,s,a)=>{e(n,valueOrProp(r,s)?i.t:i.f,a,s,t)})),addOps(16,((e,t,n,r,i)=>t(void 0,new If(r,i)))),addOps(14,((e,t,n,r,i)=>t(void 0,new If(r,i)))),addOps(40,((e,t,n,r,i,o,s,a)=>{e(n,r,a,s,((r,o)=>{if(r)t(r);else if(o=valueOrProp(o,s),e===execSync){let r,c=!1;for(let l of i)if(c||(c=!l[1]||o===valueOrProp(syncDone((t=>e(n,l[1],a,s,t))).result,s))){if(!l[2])continue;if(r=executeTree(n,s,l[2],[a],"switch"),r.breakLoop)break;if(r.returned)return void t(void 0,r);if(!l[1])break}t()}else(async()=>{let r,c=!1;for(let l of i){let i;if(c||(c=!l[1]||o===valueOrProp(!0===(i=asyncDone((t=>e(n,l[1],a,s,t)))).isInstant?i.instant:(await i.p).result,s))){if(!l[2])continue;if(r=await executeTreeAsync(n,s,l[2],[a],"switch"),r.breakLoop)break;if(r.returned)return void t(void 0,r);if(!l[1])break}}t()})().catch(t)}))})),addOps(39,((e,t,n,r,i,o,s,a,c,l)=>{const[d,p,u]=i;executeTreeWithDone(e,((r,i)=>{executeTreeWithDone(e,(o=>{o?t(o):r?executeTreeWithDone(e,t,n,s,p,[new Scope(a)],l):t(void 0,i)}),n,s,u,[new Scope(a,{})])}),n,s,r,[new Scope(a)],l)})),addOps(87,((e,t,n,r)=>{t()})),addOps(45,((e,t,n,r,i,o,s)=>{if(!s.ctx.globalsWhitelist.has(r)&&!sandboxedFunctions.has(r))throw new SandboxError(`Object construction not allowed: ${r.constructor.name}`);t(void 0,new r(...i))})),addOps(46,((e,t,n,r,i)=>{t(i)})),addOps(43,((e,t,n,r)=>t(void 0,r.pop()))),addOps(0,((e,t,n,r)=>t()));const unexecTypes=new Set([11,37,10,38,39,40,14,16,60]);function _execNoneRecurse(e,t,n,r,i,o,s){const a=o?execAsync:execSync;if(!(r.ctx.options.executionQuota<=e.ticks)||"function"==typeof r.ctx.options.onExecutionQuotaReached&&r.ctx.options.onExecutionQuotaReached(e,n,r,t)){if(e.ticks++,currentTicks=e,t instanceof Prop)try{i(void 0,t.get(r))}catch(e){i(e)}else if(t===optional)i();else if(Array.isArray(t)&&!isLisp(t))0===t[0]?i():execMany(e,a,t,i,n,r,s);else if(isLisp(t))if(42===t[0])execMany(e,a,t[1],i,n,r,s);else if(44===t[0])o?r.ctx.prototypeWhitelist?.has(Promise.prototype)?execAsync(e,t[1],n,r,(async(e,t)=>{if(e)i(e);else try{i(void 0,await valueOrProp(t,r))}catch(e){i(e)}}),s).catch(i):i(new SandboxError("Async/await is not permitted")):i(new SandboxError("Illegal use of 'await', must be inside async function"));else{if(!unexecTypes.has(t[0]))return!1;try{ops.get(t[0])(a,i,e,t[1],t[2],t,r,n,void 0,s)}catch(e){i(e)}}else i(void 0,t);return!0}i(new SandboxError("Execution quota exceeded"))}function executeTree(e,t,n,r=[],i){return syncDone((o=>executeTreeWithDone(execSync,o,e,t,n,r,i))).result}async function executeTreeAsync(e,t,n,r=[],i){let o;return!0===(o=asyncDone((o=>executeTreeWithDone(execAsync,o,e,t,n,r,i)))).isInstant?o.instant:(await o.p).result}function executeTreeWithDone(e,t,n,r,i,o=[],s){if(!i)return void t();if(!(i instanceof Array))throw new SyntaxError("Bad execution tree");let a,c=r.ctx.globalScope;for(;a=o.shift();)"object"==typeof a&&(c=a instanceof Scope?a:new Scope(c,a,a instanceof LocalScope?void 0:null));r.ctx.options.audit&&!r.ctx.auditReport&&(r.ctx.auditReport={globalsAccess:new Set,prototypeAccess:{}}),e===execSync?_executeWithDoneSync(t,n,r,i,c,s):_executeWithDoneAsync(t,n,r,i,c,s).catch(t)}function _executeWithDoneSync(e,t,n,r,i,o){if(!(r instanceof Array))throw new SyntaxError("Bad execution tree");let s=0;for(s=0;s<r.length;s++){let a,c;const l=r[s];try{execSync(t,l,i,n,((e,t)=>{c=e,a=t}),o)}catch(e){c=e}if(c)return void e(c);if(a instanceof ExecReturn)return void e(void 0,a);if(isLisp(l)&&8===l[0])return void e(void 0,new ExecReturn(n.ctx.auditReport,a,!0))}e(void 0,new ExecReturn(n.ctx.auditReport,void 0,!1))}async function _executeWithDoneAsync(e,t,n,r,i,o){if(!(r instanceof Array))throw new SyntaxError("Bad execution tree");let s=0;for(s=0;s<r.length;s++){let a,c;const l=r[s];try{await execAsync(t,l,i,n,((e,t)=>{c=e,a=t}),o)}catch(e){c=e}if(c)return void e(c);if(a instanceof ExecReturn)return void e(void 0,a);if(isLisp(l)&&8===l[0])return void e(void 0,new ExecReturn(n.ctx.auditReport,a,!0))}e(void 0,new ExecReturn(n.ctx.auditReport,void 0,!1))}class SandboxGlobal{constructor(e){if(e===globalThis)return globalThis;for(let t in e)this[t]=e[t]}}class ExecContext{constructor(e,t,n,r,i,o,s,a,c,l){this.ctx=e,this.constants=t,this.tree=n,this.getSubscriptions=r,this.setSubscriptions=i,this.changeSubscriptions=o,this.setSubscriptionsGlobal=s,this.changeSubscriptionsGlobal=a,this.evals=c,this.registerSandboxFunction=l}}function subscribeSet(e,t,n,r){const i=r.setSubscriptions.get(e)||new Map;r.setSubscriptions.set(e,i);const o=i.get(t)||new Set;let s;return i.set(t,o),o.add(n),e&&e[t]&&"object"==typeof e[t]&&(s=r.changeSubscriptions.get(e[t])||new Set,s.add(n),r.changeSubscriptions.set(e[t],s)),{unsubscribe:()=>{o.delete(n),s?.delete(n)}}}class Sandbox{constructor(e){this.setSubscriptions=new WeakMap,this.changeSubscriptions=new WeakMap,this.sandboxFunctions=new WeakMap,e=Object.assign({audit:!1,forbidFunctionCalls:!1,forbidFunctionCreation:!1,globals:Sandbox.SAFE_GLOBALS,prototypeWhitelist:Sandbox.SAFE_PROTOTYPES,prototypeReplacements:new Map},e||{});const t=new SandboxGlobal(e.globals);this.context={sandbox:this,globalsWhitelist:new Set(Object.values(e.globals)),prototypeWhitelist:new Map([...e.prototypeWhitelist].map((e=>[e[0].prototype,e[1]]))),options:e,globalScope:new Scope(null,e.globals,t),sandboxGlobal:t},this.context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()),new Set)}static get SAFE_GLOBALS(){return{Function:Function,console:{debug:console.debug,error:console.error,info:console.info,log:console.log,table:console.table,warn:console.warn},isFinite:isFinite,isNaN:isNaN,parseFloat:parseFloat,parseInt:parseInt,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape,Boolean:Boolean,Number:Number,BigInt:BigInt,String:String,Object:Object,Array:Array,Symbol:Symbol,Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array,Map:Map,Set:Set,WeakMap:WeakMap,WeakSet:WeakSet,Promise:Promise,Intl:Intl,JSON:JSON,Math:Math,Date:Date,RegExp:RegExp}}static get SAFE_PROTOTYPES(){let e=[SandboxGlobal,Function,Boolean,Number,BigInt,String,Date,Error,Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Map,Set,WeakMap,WeakSet,Promise,Symbol,Date,RegExp],t=new Map;return e.forEach((e=>{t.set(e,new Set)})),t.set(Object,new Set(["entries","fromEntries","getOwnPropertyNames","is","keys","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf","values"])),t}subscribeGet(e,t){return t.getSubscriptions.add(e),{unsubscribe:()=>t.getSubscriptions.delete(e)}}subscribeSet(e,t,n,r){return subscribeSet(e,t,n,r)}subscribeSetGlobal(e,t,n){return subscribeSet(e,t,n,this)}static audit(e,t=[]){const n={};for(let e of Object.getOwnPropertyNames(globalThis))n[e]=globalThis[e];const r=new Sandbox({globals:n,audit:!0});return r.executeTree(r.createContext(r.context,parse$2(e)),t)}static parse(e){return parse$2(e)}createContext(context,executionTree){const evals=new Map,execContext=new ExecContext(context,executionTree.constants,executionTree.tree,new Set,new WeakMap,new WeakMap,this.setSubscriptions,this.changeSubscriptions,evals,(e=>this.sandboxFunctions.set(e,execContext))),func=sandboxFunction(execContext);return evals.set(Function,func),evals.set(eval,sandboxedEval(func)),evals.set(setTimeout,sandboxedSetTimeout(func)),evals.set(setInterval,sandboxedSetInterval(func)),execContext}getContext(e){return this.sandboxFunctions.get(e)}executeTree(e,t=[]){return executeTree({ticks:BigInt(0)},e,e.tree,t)}executeTreeAsync(e,t=[]){return executeTreeAsync({ticks:BigInt(0)},e,e.tree,t)}compile(e,t=!1){const n=parse$2(e,t);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTree(t,[...e]).result}}}compileAsync(e,t=!1){const n=parse$2(e,t);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTreeAsync(t,[...e]).then((e=>e.result))}}}compileExpression(e,t=!1){const n=parse$2(e,t,!0);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTree(t,[...e]).result}}}compileExpressionAsync(e,t=!1){const n=parse$2(e,t,!0);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTreeAsync(t,[...e]).then((e=>e.result))}}}}const runInBrowserContext=(e,...t)=>__awaiter(void 0,[e,...t],void 0,(function*(e,t={}){try{const n=(new Sandbox).compile(e);return yield n(t).run()}catch(e){console.log("runInBrowserContext error ---\x3e>>",e)}})),getExpressionResult=(e,t)=>__awaiter(void 0,void 0,void 0,(function*(){return yield runInBrowserContext(e,t)}));class BaseNode{constructor({nodeConfig:e,context:t,globalData:n}){const{outgoing:r,incoming:i,id:o,type:s,properties:a}=e;this.baseType="base",this.outgoing=r,this.incoming=i,this.nodeId=o,this.type=s,this.properties=a,this.context=t,this.globalData=n}action(e){return __awaiter(this,void 0,void 0,(function*(){console.log("action param ---\x3e>>",e)}))}onResume(e){return __awaiter(this,void 0,void 0,(function*(){console.log("onResume params ---\x3e>>",e)}))}isPass(e){return __awaiter(this,void 0,void 0,(function*(){if(!e)return!0;const{conditionExpression:t}=e;if(!t)return!0;try{return yield getExpressionResult(`\n const isPassResult = (${t})\n return isPassResult\n `,Object.assign({},this.globalData))}catch(e){return!1}}))}getOutgoing(){return __awaiter(this,void 0,void 0,(function*(){const e=[],t=[];for(const e of this.outgoing){const{properties:n}=e;t.push(this.isPass(n))}return(yield Promise.all(t)).forEach(((t,n)=>{const r=this.outgoing[n];r.result=t,e.push(r)})),e}))}execute(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n}=e,r=yield this.action({nodeId:this.nodeId,executionId:t,actionId:n}),i=r?r.status:"success";if(i===exports.ActionStatus.SUCCESS){const i=yield this.getOutgoing(),o=r?r.detail:{};e.next({status:exports.ActionStatus.SUCCESS,detail:o,nodeId:this.nodeId,nodeType:this.type,properties:this.properties,executionId:t,actionId:n,outgoing:i})}return{status:i,detail:null==r?void 0:r.detail,executionId:t,actionId:n,nodeId:this.nodeId,nodeType:this.type,properties:this.properties,outgoing:[]}}))}resume(e){return __awaiter(this,void 0,void 0,(function*(){const t=yield this.getOutgoing();yield this.onResume({executionId:e.executionId,actionId:e.actionId,nodeId:e.nodeId,data:e.data}),e.next({executionId:e.executionId,actionId:e.actionId,nodeId:this.nodeId,nodeType:this.type,properties:this.properties,outgoing:t,status:exports.ActionStatus.SUCCESS})}))}}BaseNode.nodeTypeName="BaseNode";class StartNode extends BaseNode{constructor(){super(...arguments),this.baseType="start"}}StartNode.nodeTypeName="StartNode";class TaskNode extends BaseNode{constructor(){super(...arguments),this.baseType="task"}}TaskNode.nodeTypeName="TaskNode";class EventEmitter{constructor(){this._events={}}on(e,t,n){e=e.trim(),this._events[e]||(this._events[e]=[]),this._events[e].push({callback:t,once:!!n})}off(e,t){if(e||(this._events={}),t){const n=this._events[e]||[];let{length:r}=n;for(let e=0;e<r;e++)n[e].callback===t&&(n.splice(e,1),r--,e--);0===n.length&&delete this._events[e]}else delete this._events[e]}emit(e,t){(n=>{let{length:r}=n;for(let i=0;i<r;i++){if(!n[i])continue;const{callback:o,once:s}=n[i];s&&(n.splice(i,1),0===n.length&&delete this._events[e],r--,i--),o.apply(this,[t])}})(this._events[e]||[])}getEvents(){return this._events}}const isInBrowser="object"==typeof window&&window.window===window,isInNodeJS="object"==typeof global&&global.global===global,globalScope=isInBrowser?window:"object"==typeof self&&self.self===self?self:isInNodeJS?global:"object"==typeof globalThis?globalThis:{eval:()=>{}};if(!globalScope.sessionStorage){const e={data:{},setItem(t,n){e.data[t]=n},getItem:t=>e.data[t],removeItem(t){delete e.data[t]},clear(){e.data={}}};globalScope.sessionStorage=e}var storage={setItem(e,t){"object"==typeof t&&(t=JSON.stringify(t)),globalScope.sessionStorage.setItem(e,t)},getItem(e){const t=globalScope.sessionStorage.getItem(e);try{return JSON.parse(t)}catch(e){return t}},removeItem(e){globalScope.sessionStorage.removeItem(e)},clear(){globalScope.sessionStorage.clear()}};function getAugmentedNamespace(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];return n.push.apply(n,arguments),new(Function.bind.apply(t,n))}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}var dist={},v1$1={},rng$1={},_polyfillNode_crypto={},_polyfillNode_crypto$1=Object.freeze({__proto__:null,default:_polyfillNode_crypto}),require$$0=getAugmentedNamespace(_polyfillNode_crypto$1);Object.defineProperty(rng$1,"__esModule",{value:!0}),rng$1.default=rng;var _crypto$2=_interopRequireDefault$b(require$$0);function _interopRequireDefault$b(e){return e&&e.__esModule?e:{default:e}}const rnds8Pool=new Uint8Array(256);let poolPtr=rnds8Pool.length;function rng(){return poolPtr>rnds8Pool.length-16&&(_crypto$2.default.randomFillSync(rnds8Pool),poolPtr=0),rnds8Pool.slice(poolPtr,poolPtr+=16)}var stringify$1={},validate$1={},regex={};Object.defineProperty(regex,"__esModule",{value:!0}),regex.default=void 0;var _default$c=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;regex.default=_default$c,Object.defineProperty(validate$1,"__esModule",{value:!0}),validate$1.default=void 0;var _regex=_interopRequireDefault$a(regex);function _interopRequireDefault$a(e){return e&&e.__esModule?e:{default:e}}function validate(e){return"string"==typeof e&&_regex.default.test(e)}var _default$b=validate;validate$1.default=_default$b,Object.defineProperty(stringify$1,"__esModule",{value:!0}),stringify$1.default=void 0;var _validate$2=_interopRequireDefault$9(validate$1);function _interopRequireDefault$9(e){return e&&e.__esModule?e:{default:e}}const byteToHex=[];for(let e=0;e<256;++e)byteToHex.push((e+256).toString(16).substr(1));function stringify(e,t=0){const n=(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase();if(!(0,_validate$2.default)(n))throw TypeError("Stringified UUID is invalid");return n}var _default$a=stringify;stringify$1.default=_default$a,Object.defineProperty(v1$1,"__esModule",{value:!0}),v1$1.default=void 0;var _rng$1=_interopRequireDefault$8(rng$1),_stringify$2=_interopRequireDefault$8(stringify$1);function _interopRequireDefault$8(e){return e&&e.__esModule?e:{default:e}}let _nodeId,_clockseq,_lastMSecs=0,_lastNSecs=0;function v1(e,t,n){let r=t&&n||0;const i=t||new Array(16);let o=(e=e||{}).node||_nodeId,s=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==o||null==s){const t=e.random||(e.rng||_rng$1.default)();null==o&&(o=_nodeId=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==s&&(s=_clockseq=16383&(t[6]<<8|t[7]))}let a=void 0!==e.msecs?e.msecs:Date.now(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1;const l=a-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||a>_lastMSecs)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=a,_lastNSecs=c,_clockseq=s,a+=122192928e5;const d=(1e4*(268435455&a)+c)%4294967296;i[r++]=d>>>24&255,i[r++]=d>>>16&255,i[r++]=d>>>8&255,i[r++]=255&d;const p=a/4294967296*1e4&268435455;i[r++]=p>>>8&255,i[r++]=255&p,i[r++]=p>>>24&15|16,i[r++]=p>>>16&255,i[r++]=s>>>8|128,i[r++]=255&s;for(let e=0;e<6;++e)i[r+e]=o[e];return t||(0,_stringify$2.default)(i)}var _default$9=v1;v1$1.default=_default$9;var v3$1={},v35={},parse$1={};Object.defineProperty(parse$1,"__esModule",{value:!0}),parse$1.default=void 0;var _validate$1=_interopRequireDefault$7(validate$1);function _interopRequireDefault$7(e){return e&&e.__esModule?e:{default:e}}function parse(e){if(!(0,_validate$1.default)(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}var _default$8=parse;parse$1.default=_default$8,Object.defineProperty(v35,"__esModule",{value:!0}),v35.default=_default$7,v35.URL=v35.DNS=void 0;var _stringify$1=_interopRequireDefault$6(stringify$1),_parse=_interopRequireDefault$6(parse$1);function _interopRequireDefault$6(e){return e&&e.__esModule?e:{default:e}}function stringToBytes(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}const DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8";v35.DNS=DNS;const URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function _default$7(e,t,n){function r(e,r,i,o){if("string"==typeof e&&(e=stringToBytes(e)),"string"==typeof r&&(r=(0,_parse.default)(r)),16!==r.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let s=new Uint8Array(16+e.length);if(s.set(r),s.set(e,r.length),s=n(s),s[6]=15&s[6]|t,s[8]=63&s[8]|128,i){o=o||0;for(let e=0;e<16;++e)i[o+e]=s[e];return i}return(0,_stringify$1.default)(s)}try{r.name=e}catch(e){}return r.DNS=DNS,r.URL=URL,r}v35.URL=URL;var md5$1={};Object.defineProperty(md5$1,"__esModule",{value:!0}),md5$1.default=void 0;var _crypto$1=_interopRequireDefault$5(require$$0);function _interopRequireDefault$5(e){return e&&e.__esModule?e:{default:e}}function md5(e){return Array.isArray(e)?e=Buffer.from(e):"string"==typeof e&&(e=Buffer.from(e,"utf8")),_crypto$1.default.createHash("md5").update(e).digest()}var _default$6=md5;md5$1.default=_default$6,Object.defineProperty(v3$1,"__esModule",{value:!0}),v3$1.default=void 0;var _v$1=_interopRequireDefault$4(v35),_md=_interopRequireDefault$4(md5$1);function _interopRequireDefault$4(e){return e&&e.__esModule?e:{default:e}}const v3=(0,_v$1.default)("v3",48,_md.default);var _default$5=v3;v3$1.default=_default$5;var v4$1={};Object.defineProperty(v4$1,"__esModule",{value:!0}),v4$1.default=void 0;var _rng=_interopRequireDefault$3(rng$1),_stringify=_interopRequireDefault$3(stringify$1);function _interopRequireDefault$3(e){return e&&e.__esModule?e:{default:e}}function v4(e,t,n){const r=(e=e||{}).random||(e.rng||_rng.default)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return(0,_stringify.default)(r)}var _default$4=v4;v4$1.default=_default$4;var v5$1={},sha1$1={};Object.defineProperty(sha1$1,"__esModule",{value:!0}),sha1$1.default=void 0;var _crypto=_interopRequireDefault$2(require$$0);function _interopRequireDefault$2(e){return e&&e.__esModule?e:{default:e}}function sha1(e){return Array.isArray(e)?e=Buffer.from(e):"string"==typeof e&&(e=Buffer.from(e,"utf8")),_crypto.default.createHash("sha1").update(e).digest()}var _default$3=sha1;sha1$1.default=_default$3,Object.defineProperty(v5$1,"__esModule",{value:!0}),v5$1.default=void 0;var _v=_interopRequireDefault$1(v35),_sha=_interopRequireDefault$1(sha1$1);function _interopRequireDefault$1(e){return e&&e.__esModule?e:{default:e}}const v5=(0,_v.default)("v5",80,_sha.default);var _default$2=v5;v5$1.default=_default$2;var nil={};Object.defineProperty(nil,"__esModule",{value:!0}),nil.default=void 0;var _default$1="00000000-0000-0000-0000-000000000000";nil.default=_default$1;var version$1={};Object.defineProperty(version$1,"__esModule",{value:!0}),version$1.default=void 0;var _validate=_interopRequireDefault(validate$1);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function version(e){if(!(0,_validate.default)(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}var _default=version;version$1.default=_default,function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"v1",{enumerable:!0,get:function(){return t.default}}),Object.defineProperty(e,"v3",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"v4",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"v5",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(e,"NIL",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(e,"version",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(e,"validate",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return l.default}});var t=d(v1$1),n=d(v3$1),r=d(v4$1),i=d(v5$1),o=d(nil),s=d(version$1),a=d(validate$1),c=d(stringify$1),l=d(parse$1);function d(e){return e&&e.__esModule?e:{default:e}}}(dist);const createExecId=()=>`exec-${dist.v4()}`,createActionId=()=>`action-${dist.v4()}`,createEngineId=()=>`engine-${dist.v4()}`;class Scheduler extends EventEmitter{constructor(e){super(),this.nodeQueueMap=new Map,this.actionRunningMap=new Map,this.flowModel=e.flowModel,this.recorder=e.recorder}addAction(e){const{executionId:t}=e;this.nodeQueueMap.has(t)||this.nodeQueueMap.set(t,[]);const n=this.nodeQueueMap.get(t);n&&n.push(e),console.log("this.nodeQueueMap---\x3e>>",this.nodeQueueMap)}pushActionToRunningMap(e){var t;const{executionId:n,actionId:r}=e;if(!this.actionRunningMap.has(n)){const e=new Map;this.actionRunningMap.set(n,e)}r&&(null===(t=this.actionRunningMap.get(n))||void 0===t||t.set(r,e))}removeActionFromRunningMap(e){const{executionId:t,actionId:n}=e;if(!n)return;const r=this.actionRunningMap.get(t);r&&r.delete(n)}saveActionResult(e){var t;null===(t=this.recorder)||void 0===t||t.addActionRecord(Object.assign({timestamp:Date.now()},e))}hasRunningAction(e){const t=this.actionRunningMap.get(e);return!!t&&(0!==t.size||(this.actionRunningMap.delete(e),!1))}run(e){const t=this.nodeQueueMap.get(e.executionId);for(;null==t?void 0:t.length;){const e=t.pop(),n=createActionId(),r=Object.assign(Object.assign({},e),{actionId:n});this.pushActionToRunningMap(r),this.exec(r)}this.hasRunningAction(e.executionId)||this.emit(EVENT_INSTANCE_COMPLETE,Object.assign(Object.assign({},e),{status:exports.FlowStatus.COMPLETED}))}next(e){e.outgoing&&e.outgoing.length>0&&e.outgoing.forEach((t=>{t.result&&this.addAction({executionId:e.executionId,nodeId:t.target})})),this.saveActionResult(e),this.removeActionFromRunningMap(e),this.run(e)}resume(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n,nodeId:r}=e;this.pushActionToRunningMap({executionId:t,actionId:n,nodeId:r});const i=this.flowModel.createAction(r);yield null==i?void 0:i.resume(Object.assign(Object.assign({},e),{next:this.next.bind(this)}))}))}interrupted(e){this.emit(EVENT_INSTANCE_INTERRUPTED,e)}error(e){this.emit(EVENT_INSTANCE_ERROR,e)}exec(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n,nodeId:r}=e,i=this.flowModel.createAction(r),o=yield null==i?void 0:i.execute({executionId:t,actionId:n,nodeId:r,next:this.next.bind(this)});if(o){const{nodeType:i,properties:s,outgoing:a,status:c,detail:l}=o,d={executionId:t,actionId:n,nodeId:r,nodeType:i,properties:s,outgoing:a,status:c,detail:l};(null==o?void 0:o.status)===exports.FlowStatus.INTERRUPTED&&(this.interrupted(o),this.saveActionResult(d),this.removeActionFromRunningMap(e)),(null==o?void 0:o.status)===exports.FlowStatus.ERROR&&(this.error(o),this.saveActionResult(d),this.removeActionFromRunningMap(e))}}))}}class FlowModel{constructor({nodeModelMap:e,recorder:t,context:n={},globalData:r={},startNodeType:i="StartNode"}){this.nodeConfigMap=new Map,this.startNodes=[],this.globalData={},this.nodeModelMap=e,this.executeList=[],this.executingInstance=null,this.context=n,this.globalData=r,this.startNodeType=i,this.isRunning=!1,this.scheduler=new Scheduler({flowModel:this,recorder:t}),this.scheduler.on(EVENT_INSTANCE_COMPLETE,(e=>{this.onExecuteFinished(e)})),this.scheduler.on(EVENT_INSTANCE_INTERRUPTED,(e=>{this.onExecuteFinished(e)})),this.scheduler.on(EVENT_INSTANCE_ERROR,(e=>{this.onExecuteFinished(e)}))}load(e){const{nodes:t=[],edges:n=[]}=e;t.forEach((e=>{if(this.nodeModelMap.has(e.type)){const t={id:e.id,type:e.type,properties:e.properties,incoming:[],outgoing:[]};this.nodeConfigMap.set(e.id,t),e.type===this.startNodeType&&this.startNodes.push(t)}else console.warn(`未识别的节点类型:${e.type}`)})),n.forEach((e=>{const t=this.nodeConfigMap.get(e.sourceNodeId),n=this.nodeConfigMap.get(e.targetNodeId);t&&t.outgoing.push({id:e.id,properties:e.properties,target:e.targetNodeId}),n&&n.type!==this.startNodeType&&n.incoming.push({id:e.id,properties:e.properties,source:e.sourceNodeId})}))}createExecution(e){var t;if(this.executeList.push(e),e.actionId&&e.nodeId&&e.executionId)return void this.scheduler.resume({executionId:e.executionId,actionId:e.actionId,nodeId:e.nodeId,data:e.data});const n=createExecId();if(e.executionId=n,null==e?void 0:e.nodeId){const n=this.nodeConfigMap.get(e.nodeId);if(!n)return void(null===(t=null==e?void 0:e.onError)||void 0===t||t.call(e,new Error(`${getErrorMsg(exports.ErrorCode.NONE_NODE_ID)}(${e.nodeId})`)));this.startNodes=[n]}this.startNodes.forEach((e=>{this.scheduler.addAction({executionId:n,nodeId:e.id})})),this.scheduler.run({executionId:n})}execute(e){return __awaiter(this,void 0,void 0,(function*(){this.createExecution(e)}))}resume(e){return __awaiter(this,void 0,void 0,(function*(){this.createExecution(e)}))}createAction(e){const t=this.nodeConfigMap.get(e);if(t){const e=this.nodeModelMap.get(t.type);if(!e)throw new Error("该 NodeModel 不存在,抛出异常");return new e({nodeConfig:t,globalData:this.globalData,context:this.context})}}setStartNodeType(e){this.startNodeType=e}updateGlobalData(e){return this.globalData=Object.assign(Object.assign({},this.globalData),e),this.globalData}onExecuteFinished(e){const t=this.executeList.findIndex((t=>t.executionId===e.executionId));if(t>-1){const{callback:n}=this.executeList[t];this.executeList.splice(t,1),null==n||n(e)}}}const MAX_RECORDER=100,MAX_INSTANCE=100,LOGICFLOW_ENGINE_INSTANCES="LOGICFLOW_ENGINE_INSTANCES";class Recorder{constructor({instanceId:e}){this.instanceId=e,this.maxRecorder=MAX_RECORDER;const t=this.getItem(LOGICFLOW_ENGINE_INSTANCES)||[];if(-1===t.indexOf(e)&&t.push(e),t.length>MAX_INSTANCE){const e=t.shift();this.clearInstance(e)}this.setItem(LOGICFLOW_ENGINE_INSTANCES,t)}setMaxRecorderNumber(e){this.maxRecorder=e}setItem(e,t){try{storage.setItem(e,t)}catch(n){console.error("Ops, something wrong with storage.setItem !!!"),storage.clear(),storage.setItem(e,t)}}getItem(e){return storage.getItem(e)}getExecutionActions(e){return __awaiter(this,void 0,void 0,(function*(){return this.getItem(e)}))}getExecutionList(){return __awaiter(this,void 0,void 0,(function*(){return this.getItem(this.instanceId)||[]}))}addExecution(e){const t=this.getItem(this.instanceId)||[];if(t.length>=this.maxRecorder){const e=t.shift();this.popExecution(e)}t.push(e),this.setItem(this.instanceId,t)}popExecution(e){(this.getItem(e)||[]).forEach((e=>{storage.removeItem(e)})),storage.removeItem(e)}pushActionToExecution(e,t){const n=this.getItem(e)||[];n.push(t),this.setItem(e,n)}addActionRecord(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n}=e;(yield this.getExecutionActions(t))||this.addExecution(t),this.pushActionToExecution(t,n),this.setItem(n,e)}))}getActionRecord(e){return __awaiter(this,void 0,void 0,(function*(){return this.getItem(e)}))}clear(){this.clearInstance(this.instanceId)}clearInstance(e){(this.getItem(e)||[]).forEach((e=>{storage.removeItem(e);(this.getItem(e)||[]).forEach((e=>{storage.removeItem(e)}))})),storage.removeItem(e)}}class Engine{constructor(e){this.nodeModelMap=new Map,this.instanceId=createEngineId(),(null==e?void 0:e.debug)&&(this.recorder=new Recorder({instanceId:this.instanceId})),this.register({type:StartNode.nodeTypeName,model:StartNode}),this.register({type:TaskNode.nodeTypeName,model:TaskNode}),this.context=(null==e?void 0:e.context)||{}}register(e){this.nodeModelMap.set(e.type,e.model)}setCustomRecorder(e){this.recorder=e}load({graphData:e,startNodeType:t="StartNode",globalData:n={}}){this.graphData=e;const r=new FlowModel({nodeModelMap:this.nodeModelMap,recorder:this.recorder,context:this.context,globalData:n,startNodeType:t});return r.load(e),this.flowModel=r,r}execute(e){return __awaiter(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var r;let i=e;e||(i={}),null===(r=this.flowModel)||void 0===r||r.execute(Object.assign(Object.assign({},i),{callback:e=>{t(e)},onError:e=>{n(e)}}))}))}))}resume(e){return __awaiter(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var r;null===(r=this.flowModel)||void 0===r||r.resume(Object.assign(Object.assign({},e),{callback:e=>{t(e)},onError:e=>{n(e)}}))}))}))}getExecutionList(){return __awaiter(this,void 0,void 0,(function*(){var e;return yield null===(e=this.recorder)||void 0===e?void 0:e.getExecutionList()}))}getExecutionRecord(e){return __awaiter(this,void 0,void 0,(function*(){var t,n;const r=yield null===(t=this.recorder)||void 0===t?void 0:t.getExecutionActions(e);if(!r)return null;const i=[];for(let e=0;e<(null==r?void 0:r.length);e++){const t=r[e];this.recorder&&i.push(null===(n=this.recorder)||void 0===n?void 0:n.getActionRecord(t))}return Promise.all(i)}))}destroy(){var e;null===(e=this.recorder)||void 0===e||e.clear()}getGlobalData(){var e;return null===(e=this.flowModel)||void 0===e?void 0:e.globalData}setGlobalData(e){this.flowModel&&(this.flowModel.globalData=e)}updateGlobalData(e){this.flowModel&&Object.assign(this.flowModel.globalData,e)}}exports.BASE_START_NODE=BASE_START_NODE,exports.BaseNode=BaseNode,exports.EVENT_INSTANCE_COMPLETE=EVENT_INSTANCE_COMPLETE,exports.EVENT_INSTANCE_ERROR=EVENT_INSTANCE_ERROR,exports.EVENT_INSTANCE_INTERRUPTED=EVENT_INSTANCE_INTERRUPTED,exports.Engine=Engine,exports.Recorder=Recorder,exports.StartNode=StartNode,exports.TaskNode=TaskNode,exports.default=Engine,exports.getErrorMsg=getErrorMsg,exports.getWarningMsg=getWarningMsg,Object.defineProperty(exports,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Engine={})}(this,(function(exports){"use strict";function __awaiter(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}var ErrorCode,WarningCode;"function"==typeof SuppressedError&&SuppressedError,exports.ErrorCode=void 0,ErrorCode=exports.ErrorCode||(exports.ErrorCode={}),ErrorCode[ErrorCode.NONE_START_NODE=1e3]="NONE_START_NODE",ErrorCode[ErrorCode.NONE_NODE_ID=1001]="NONE_NODE_ID",ErrorCode[ErrorCode.NO_DOCUMENT_BODY=2001]="NO_DOCUMENT_BODY",exports.WarningCode=void 0,WarningCode=exports.WarningCode||(exports.WarningCode={}),WarningCode[WarningCode.NONE_START_NODE_IN_DATA=2e3]="NONE_START_NODE_IN_DATA",WarningCode[WarningCode.START_NODE_INCOMING=2001]="START_NODE_INCOMING",WarningCode[WarningCode.EXPRESSION_EXEC_ERROR=3e3]="EXPRESSION_EXEC_ERROR";const errorMsgMapCn={[exports.ErrorCode.NONE_START_NODE]:"未找到入度为0的节点",[exports.ErrorCode.NONE_NODE_ID]:"流程数据中存在没有此节点",[exports.ErrorCode.NO_DOCUMENT_BODY]:"找不到document.body, 请在DOM加载完成后再执行"},warningMsgMapCn={[exports.WarningCode.NONE_START_NODE_IN_DATA]:"初始化数据中未找到入度为0的节点",[exports.WarningCode.START_NODE_INCOMING]:"开始节点不允许被连入",[exports.WarningCode.EXPRESSION_EXEC_ERROR]:"表达式执行异常"},getErrorMsg=e=>`error[${e}]: ${errorMsgMapCn[e]}`,getWarningMsg=e=>`warning[${e}]: ${warningMsgMapCn[e]}`,BASE_START_NODE="start",EVENT_INSTANCE_COMPLETE="instance:complete",EVENT_INSTANCE_INTERRUPTED="instance:interrupted",EVENT_INSTANCE_ERROR="instance:error";var FlowStatus,ActionStatus;function parseHexToInt(e){return!e.match(/[^a-f0-9]/i)?parseInt(e,16):NaN}function validateAndParseHex(e,t,n){const r=parseHexToInt(e);if(Number.isNaN(r)||void 0!==n&&n!==e.length)throw new SyntaxError(t+": "+e);return r}function parseHexadecimalCode(e){const t=validateAndParseHex(e,"Malformed Hexadecimal",2);return String.fromCharCode(t)}function parseUnicodeCode(e,t){const n=validateAndParseHex(e,"Malformed Unicode",4);if(void 0!==t){const e=validateAndParseHex(t,"Malformed Unicode",4);return String.fromCharCode(n,e)}return String.fromCharCode(n)}function isCurlyBraced(e){return"{"===e.charAt(0)&&"}"===e.charAt(e.length-1)}function parseUnicodeCodePointCode(e){if(!isCurlyBraced(e))throw new SyntaxError("Malformed Unicode: +"+e);const t=validateAndParseHex(e.slice(1,-1),"Malformed Unicode");try{return String.fromCodePoint(t)}catch(e){throw e instanceof RangeError?new SyntaxError("Code Point Limit:"+t):e}}exports.FlowStatus=void 0,FlowStatus=exports.FlowStatus||(exports.FlowStatus={}),FlowStatus.COMPLETED="completed",FlowStatus.INTERRUPTED="interrupted",FlowStatus.RUNNING="running",FlowStatus.PENDING="pending",FlowStatus.ERROR="error",exports.ActionStatus=void 0,ActionStatus=exports.ActionStatus||(exports.ActionStatus={}),ActionStatus.SUCCESS="success",ActionStatus.ERROR="error",ActionStatus.INTERRUPTED="interrupted";const singleCharacterEscapes=new Map([["b","\b"],["f","\f"],["n","\n"],["r","\r"],["t","\t"],["v","\v"],["0","\0"]]);function parseSingleCharacterCode(e){return singleCharacterEscapes.get(e)||e}const escapeMatch=/\\(?:(\\)|x([\s\S]{0,2})|u(\{[^}]*\}?)|u([\s\S]{4})\\u([^{][\s\S]{0,3})|u([\s\S]{0,4})|([0-3]?[0-7]{1,2})|([\s\S])|$)/g;function unraw(e){return e.replace(escapeMatch,(function(e,t,n,r,i,o,s,a,c){if(void 0!==t)return"\\";if(void 0!==n)return parseHexadecimalCode(n);if(void 0!==r)return parseUnicodeCodePointCode(r);if(void 0!==i)return parseUnicodeCode(i,o);if(void 0!==s)return parseUnicodeCode(s);if("0"===a)return"\0";if(void 0!==a)throw new SyntaxError("Octal Deprecation: "+a);if(void 0!==c)return parseSingleCharacterCode(c);throw new SyntaxError("End of string")}))}function createLisp(e){return[e.op,e.a,e.b]}let lispTypes=new Map;class ParseError extends Error{constructor(e,t){super(e+": "+t.substring(0,40)),this.code=t}}const inlineIfElse=/^:/,elseIf=/^else(?![\w\$])/,ifElse=/^if(?![\w\$])/,space=/^\s/;let expectTypes={splitter:{types:{opHigh:/^(\/|\*\*|\*(?!\*)|\%)(?!\=)/,op:/^(\+(?!(\+))|\-(?!(\-)))(?!\=)/,comparitor:/^(<=|>=|<(?!<)|>(?!>)|!==|!=(?!\=)|===|==)/,boolOp:/^(&&|\|\||instanceof(?![\w\$])|in(?![\w\$]))/,bitwise:/^(&(?!&)|\|(?!\|)|\^|<<|>>(?!>)|>>>)(?!\=)/},next:["modifier","value","prop","incrementerBefore"]},inlineIf:{types:{inlineIf:/^\?(?!\.(?!\d))/},next:["expEnd"]},assignment:{types:{assignModify:/^(\-=|\+=|\/=|\*\*=|\*=|%=|\^=|\&=|\|=|>>>=|>>=|<<=)/,assign:/^(=)(?!=)/},next:["modifier","value","prop","incrementerBefore"]},incrementerBefore:{types:{incrementerBefore:/^(\+\+|\-\-)/},next:["prop"]},expEdge:{types:{call:/^(\?\.)?[\(]/,incrementerAfter:/^(\+\+|\-\-)/},next:["splitter","expEdge","dot","inlineIf","expEnd"]},modifier:{types:{not:/^!/,inverse:/^~/,negative:/^\-(?!\-)/,positive:/^\+(?!\+)/,typeof:/^typeof(?![\w\$])/,delete:/^delete(?![\w\$])/},next:["modifier","value","prop","incrementerBefore"]},dot:{types:{arrayProp:/^(\?\.)?\[/,dot:/^(\?)?\.(?=\s*[a-zA-Z\$\_])/},next:["splitter","assignment","expEdge","dot","inlineIf","expEnd"]},prop:{types:{prop:/^[a-zA-Z\$\_][a-zA-Z\d\$\_]*/},next:["splitter","assignment","expEdge","dot","inlineIf","expEnd"]},value:{types:{createObject:/^\{/,createArray:/^\[/,number:/^(0x[\da-f]+(_[\da-f]+)*|(\d+(_\d+)*(\.\d+(_\d+)*)?|\.\d+(_\d+)*))(e[\+\-]?\d+(_\d+)*)?(n)?(?!\d)/i,string:/^"(\d+)"/,literal:/^`(\d+)`/,regex:/^\/(\d+)\/r(?![\w\$])/,boolean:/^(true|false)(?![\w\$])/,null:/^null(?![\w\$])/,und:/^undefined(?![\w\$])/,arrowFunctionSingle:/^(async\s+)?([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*=>\s*({)?/,arrowFunction:/^(async\s*)?\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*=>\s*({)?/,inlineFunction:/^(async\s+)?function(\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)?\s*\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*{/,group:/^\(/,NaN:/^NaN(?![\w\$])/,Infinity:/^Infinity(?![\w\$])/,void:/^void(?![\w\$])\s*/,await:/^await(?![\w\$])\s*/,new:/^new(?![\w\$])\s*/},next:["splitter","expEdge","dot","inlineIf","expEnd"]},initialize:{types:{initialize:/^(var|let|const)\s+([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*(=)?/,return:/^return(?![\w\$])/,throw:/^throw(?![\w\$])\s*/},next:["modifier","value","prop","incrementerBefore","expEnd"]},spreadObject:{types:{spreadObject:/^\.\.\./},next:["value","prop"]},spreadArray:{types:{spreadArray:/^\.\.\./},next:["value","prop"]},expEnd:{types:{},next:[]},expFunction:{types:{function:/^(async\s+)?function(\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*{/},next:["expEdge","expEnd"]},expSingle:{types:{for:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*for\s*\(/,do:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*do(?![\w\$])\s*(\{)?/,while:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*while\s*\(/,loopAction:/^(break|continue)(?![\w\$])\s*([a-zA-Z\$\_][\w\$]*)?/,if:/^((([a-zA-Z\$\_][\w\$]*)\s*:)?\s*)if\s*\(/,try:/^try\s*{/,block:/^{/,switch:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*switch\s*\(/},next:["expEnd"]}},closings={"(":")","[":"]","{":"}","'":"'",'"':'"',"`":"`"};function testMultiple(e,t){let n;for(let r=0;r<t.length;r++){if(n=t[r].exec(e),n)break}return n}class CodeString{constructor(e){this.ref={str:""},e instanceof CodeString?(this.ref=e.ref,this.start=e.start,this.end=e.end):(this.ref.str=e,this.start=0,this.end=e.length)}substring(e,t){if(!this.length)return this;(e=this.start+e)<0&&(e=0),e>this.end&&(e=this.end),(t=void 0===t?this.end:this.start+t)<0&&(t=0),t>this.end&&(t=this.end);const n=new CodeString(this);return n.start=e,n.end=t,n}get length(){const e=this.end-this.start;return e<0?0:e}char(e){if(this.start!==this.end)return this.ref.str[this.start+e]}toString(){return this.ref.str.substring(this.start,this.end)}trimStart(){const e=/^\s+/.exec(this.toString()),t=new CodeString(this);return e&&(t.start+=e[0].length),t}slice(e,t){return e<0&&(e=this.end-this.start+e),e<0&&(e=0),void 0===t&&(t=this.end-this.start),t<0&&(t=this.end-this.start+t),t<0&&(t=0),this.substring(e,t)}trim(){const e=this.trimStart(),t=/\s+$/.exec(e.toString());return t&&(e.end-=t[0].length),e}valueOf(){return this.toString()}}const emptyString=new CodeString(""),okFirstChars=/^[\+\-~ !]/,aNumber=expectTypes.value.types.number,wordReg=/^((if|for|else|while|do|function)(?![\w\$])|[\w\$]+)/,semiColon=/^;/,insertedSemicolons=new WeakMap,quoteCache=new WeakMap;function restOfExp(e,t,n,r,i,o,s={}){if(!t.length)return t;s.words=s.words||[];let a=!0;const c=(n=n||[]).includes(semiColon);c&&(n=n.filter((e=>e!==semiColon)));const l=insertedSemicolons.get(t.ref)||[],d=quoteCache.get(t.ref)||new Map;if(quoteCache.set(t.ref,d),r&&d.has(t.start-1))return t.substring(0,d.get(t.start-1)-t.start);let p,u=!1,f=!1,h="",g=!1,y=!1;for(p=0;p<t.length&&!f;p++){let x=t.char(p);if('"'===r||"'"===r||"`"===r){if("`"!==r||"$"!==x||"{"!==t.char(p+1)||u){if(x===r&&!u)return t.substring(0,p)}else{p+=restOfExp(e,t.substring(p+2),[],"{").length+2}u=!u&&"\\"===x}else if(closings[x]){if(!y&&l[p+t.start]){if(y=!0,c)break;p--,h=";";continue}if(g&&"{"===x&&(g=!1),x===i){f=!0;break}{let n=restOfExp(e,t.substring(p+1),[],x);if(d.set(n.start-1,n.end),p+=n.length+1,a=!1,o){let e;(e=testMultiple(t.substring(p).toString(),o))&&(s.regRes=e,f=!0)}}}else if(r){if(x===closings[r])return t.substring(0,p)}else{let e,r,i=t.substring(p).toString();if(o){let e;if(e=testMultiple(i,o)){s.regRes=e,p++,f=!0;break}}if(r=aNumber.exec(i))p+=r[0].length-1,i=t.substring(p).toString();else if(h!=x){let r;if(";"===x||l[p+t.start]&&!a&&!y){if(c)r=[";"];else if(l[p+t.start]){y=!0,p--,h=";";continue}x=i=";"}else y=!1;r||(r=testMultiple(i,n)),r&&(f=!0),!f&&(e=wordReg.exec(i))&&(g=!0,e[0].length>1&&(s.words.push(e[1]),s.lastAnyWord=e[1],e[2]&&(s.lastWord=e[2])),e[0].length>2&&(p+=e[0].length-2))}if(a&&(okFirstChars.test(i)?f=!1:a=!1),f)break}h=x}if(r)throw new SyntaxError("Unclosed '"+r+"'");return s&&(s.oneliner=g),t.substring(0,p)}restOfExp.next=["splitter","expEnd","inlineIf"];const startingExecpted=["initialize","expSingle","expFunction","value","modifier","prop","incrementerBefore","expEnd"],setLispType=(e,t)=>{e.forEach((e=>{lispTypes.set(e,t)}))},closingsCreate={createArray:/^\]/,createObject:/^\}/,group:/^\)/,arrayProp:/^\]/,call:/^\)/},typesCreate={createArray:12,createObject:22,group:23,arrayProp:19,call:5,prop:1,"?prop":20,"?call":21};setLispType(["createArray","createObject","group","arrayProp","call"],((e,t,n,r,i,o)=>{let s=emptyString,a=[],c=!1,l=r[0].length;const d=l;for(;l<n.length&&!c;)s=restOfExp(e,n.substring(l),[closingsCreate[t],/^,/]),l+=s.length,s.trim().length&&a.push(s),","!==n.char(l)?c=!0:l++;const p=["value","modifier","prop","incrementerBefore","expEnd"];let u,f;switch(t){case"group":case"arrayProp":u=lispifyExpr(e,n.substring(d,l));break;case"call":case"createArray":u=a.map((t=>lispify(e,t,[...p,"spreadArray"])));break;case"createObject":u=a.map((t=>{let n;t=t.trimStart();let r="";if(f=expectTypes.expFunction.types.function.exec("function "+t),f)r=f[2].trimStart(),n=lispify(e,new CodeString("function "+t.toString().replace(r,"")));else{let i=restOfExp(e,t,[/^:/]);r=lispify(e,i,[...p,"spreadObject"]),1===r[0]&&(r=r[2]),n=lispify(e,t.substring(i.length+1))}return createLisp({op:6,a:r,b:n})}))}let h="arrayProp"===t?r[1]?20:1:"call"===t?r[1]?21:5:typesCreate[t];o.lispTree=lispify(e,n.substring(l+1),expectTypes[i].next,createLisp({op:h,a:o.lispTree,b:u}))}));const modifierTypes={inverse:64,not:24,positive:59,negative:58,typeof:60,delete:61};setLispType(["inverse","not","negative","positive","typeof","delete"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(r[0].length),[/^([^\s\.\?\w\$]|\?[^\.])/]);o.lispTree=lispify(e,n.substring(s.length+r[0].length),restOfExp.next,createLisp({op:modifierTypes[t],a:o.lispTree,b:lispify(e,s,expectTypes[i].next)}))}));const incrementTypes={"++$":25,"--$":27,"$++":26,"$--":28};setLispType(["incrementerBefore"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(2),[/^[^\s\.\w\$]/]);o.lispTree=lispify(e,n.substring(s.length+2),restOfExp.next,createLisp({op:incrementTypes[r[0]+"$"],a:lispify(e,s,expectTypes[i].next),b:0}))})),setLispType(["incrementerAfter"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:incrementTypes["$"+r[0]],a:o.lispTree,b:0}))}));const adderTypes={"&&":29,"||":30,instanceof:62,in:63,"=":9,"-=":65,"+=":66,"/=":67,"**=":68,"*=":69,"%=":70,"^=":71,"&=":72,"|=":73,">>>=":74,"<<=":76,">>=":75};setLispType(["assign","assignModify","boolOp"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:adderTypes[r[0]],a:o.lispTree,b:lispify(e,n.substring(r[0].length),expectTypes[i].next)})}));const opTypes={"&":77,"|":78,"^":79,"<<":80,">>":81,">>>":82,"<=":54,">=":55,"<":56,">":57,"!==":31,"!=":53,"===":32,"==":52,"+":33,"-":47,"/":48,"**":49,"*":50,"%":51};function extractIfElse(e,t){let n,r,i=0,o=t.substring(0,0),s=emptyString,a=!0,c={};for(;(o=restOfExp(e,t.substring(o.end-t.start),[elseIf,ifElse,semiColon],void 0,void 0,void 0,c)).length||a;){a=!1;const l=t.substring(o.end-t.start).toString();if(l.startsWith("if"))o.end++,i++;else if(l.startsWith("else"))n=t.substring(0,o.end-t.start),o.end++,i--,i||o.end--;else{if(!(r=/^;?\s*else(?![\w\$])/.exec(l))){n=s.length?n:t.substring(0,o.end-t.start);break}n=t.substring(0,o.end-t.start),o.end+=r[0].length-1,i--,i||(o.end-=r[0].length-1)}if(!i){s=extractIfElse(e,t.substring(o.end-t.start+/^;?\s*else(?![\w\$])/.exec(l)?.[0].length)).all;break}c={}}return n=n||t.substring(0,o.end-t.start),{all:t.substring(0,Math.max(n.end,s.end)-t.start),true:n,false:s}}setLispType(["opHigh","op","comparitor","bitwise"],((e,t,n,r,i,o)=>{const s=[expectTypes.inlineIf.types.inlineIf,inlineIfElse];switch(t){case"opHigh":s.push(expectTypes.splitter.types.opHigh);case"op":s.push(expectTypes.splitter.types.op);case"comparitor":s.push(expectTypes.splitter.types.comparitor);case"bitwise":s.push(expectTypes.splitter.types.bitwise),s.push(expectTypes.splitter.types.boolOp)}let a=restOfExp(e,n.substring(r[0].length),s);o.lispTree=lispify(e,n.substring(a.length+r[0].length),restOfExp.next,createLisp({op:opTypes[r[0]],a:o.lispTree,b:lispify(e,a,expectTypes[i].next)}))})),setLispType(["inlineIf"],((e,t,n,r,i,o)=>{let s=!1,a=n.substring(0,0),c=1;for(;!s&&a.length<n.length;)a.end=restOfExp(e,n.substring(a.length+1),[expectTypes.inlineIf.types.inlineIf,inlineIfElse]).end,"?"===n.char(a.length)?c++:c--,c||(s=!0);a.start=n.start+1,o.lispTree=createLisp({op:15,a:o.lispTree,b:createLisp({op:16,a:lispifyExpr(e,a),b:lispifyExpr(e,n.substring(r[0].length+a.length+1))})})})),setLispType(["if"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(r[0].length),[],"(");const a=extractIfElse(e,n.substring(r[1].length));/^\s*\{/.exec(n.substring(r[0].length+s.length+1).toString());const c=r[0].length-r[1].length+s.length+1;let l=a.true.substring(c),d=a.false;s=s.trim(),l=l.trim(),d=d.trim(),"{"===l.char(0)&&(l=l.slice(1,-1)),"{"===d.char(0)&&(d=d.slice(1,-1)),o.lispTree=createLisp({op:13,a:lispifyExpr(e,s),b:createLisp({op:14,a:lispifyBlock(l,e),b:lispifyBlock(d,e)})})})),setLispType(["switch"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[],"(");let a=n.toString().indexOf("{",r[0].length+s.length+1);if(-1===a)throw new SyntaxError("Invalid switch");let c,l=insertSemicolons(e,restOfExp(e,n.substring(a+1),[],"{"));const d=/^\s*(case\s|default)\s*/;let p=[],u=!1;for(;c=d.exec(l.toString());){if("default"===c[1]){if(u)throw new SyntaxError("Only one default switch case allowed");u=!0}let t=restOfExp(e,l.substring(c[0].length),[/^:/]),n=emptyString,r=a=c[0].length+t.length+1,i=/^\s*\{/.exec(l.substring(r).toString()),o=[];if(i)r+=i[0].length,n=restOfExp(e,l.substring(r),[],"{"),r+=n.length+1,o=lispifyBlock(n,e);else{let t=restOfExp(e,l.substring(r),[d]);if(t.trim().length){for(;(n=restOfExp(e,l.substring(r),[semiColon])).length&&(r+=n.length+(";"===l.char(r+n.length)?1:0),!d.test(l.substring(r).toString())););o=lispifyBlock(l.substring(a,n.end-l.start),e)}else o=[],r+=t.length}l=l.substring(r),p.push(createLisp({op:41,a:"default"===c[1]?void 0:lispifyExpr(e,t),b:o}))}o.lispTree=createLisp({op:40,a:lispifyExpr(e,s),b:p})})),setLispType(["dot","prop"],((e,t,n,r,i,o)=>{let s=r[0],a=r[0].length,c="prop";if("dot"===t){r[1]&&(c="?prop");let e=n.substring(r[0].length).toString().match(expectTypes.prop.types.prop);if(!e||!e.length)throw new SyntaxError("Hanging dot");s=e[0],a=s.length+r[0].length}o.lispTree=lispify(e,n.substring(a),expectTypes[i].next,createLisp({op:typesCreate[c],a:o.lispTree,b:s}))})),setLispType(["spreadArray","spreadObject"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:"spreadArray"===t?18:17,a:0,b:lispify(e,n.substring(r[0].length),expectTypes[i].next)})})),setLispType(["return","throw"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:"return"===t?8:46,a:0,b:lispifyExpr(e,n.substring(r[0].length))})})),setLispType(["number","boolean","null","und","NaN","Infinity"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:"number"===t?r[10]?83:7:35,a:0,b:r[10]?r[1]:r[0]}))})),setLispType(["string","literal","regex"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:"string"===t?2:"literal"===t?84:85,a:0,b:r[1]}))})),setLispType(["initialize"],((e,t,n,r,i,o)=>{const s="var"===r[1]?34:"let"===r[1]?3:4;r[3]?o.lispTree=createLisp({op:s,a:r[2],b:lispify(e,n.substring(r[0].length),expectTypes[i].next)}):o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:s,a:r[2],b:0}))})),setLispType(["function","inlineFunction","arrowFunction","arrowFunctionSingle"],((e,t,n,r,i,o)=>{const s="function"!==t&&"inlineFunction"!==t,a=s&&!r[r.length-1],c=s?2:3,l=r[1]?88:0,d=r[c]?r[c].replace(/\s+/g,"").split(/,/g):[];s||d.unshift((r[2]||"").trimStart());let p=!1;d.forEach((e=>{if(p)throw new SyntaxError("Rest parameter must be last formal parameter");e.startsWith("...")&&(p=!0)})),d.unshift(l);const u=restOfExp(e,n.substring(r[0].length),a?[/^[,\)\}\]]/,semiColon]:[/^}/]),f=a?"return "+u:u.toString();o.lispTree=lispify(e,n.substring(r[0].length+f.length+1),expectTypes[i].next,createLisp({op:s?11:"function"===t?37:10,a:d,b:e.eager?lispifyFunction(new CodeString(f),e):f}))}));const iteratorRegex=/^((let|var|const)\s+)?\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s+(in|of)(?![\w\$])/;setLispType(["for","do","while"],((e,t,n,r,i,o)=>{let s,a,c,l=0,d=88,p=[],u=0,f=88,h=88;switch(t){case"while":l=n.toString().indexOf("(")+1;let t=restOfExp(e,n.substring(l),[],"(");a=lispifyReturnExpr(e,t),c=restOfExp(e,n.substring(l+t.length+1)).trim(),"{"===c[0]&&(c=c.slice(1,-1));break;case"for":l=n.toString().indexOf("(")+1;let i,o=[],g=emptyString;for(let t=0;t<3&&(g=restOfExp(e,n.substring(l),[/^[;\)]/]),o.push(g.trim()),l+=g.length+1,")"!==n.char(l-1));t++);if(1===o.length&&(i=iteratorRegex.exec(o[0].toString())))"of"===i[4]?(s=lispifyReturnExpr(e,o[0].substring(i[0].length)),p=[ofStart2,ofStart3],a=ofCondition,h=ofStep,u=lispify(e,new CodeString((i[1]||"let ")+i[3]+" = $$next.value"),["initialize"])):(s=lispifyReturnExpr(e,o[0].substring(i[0].length)),p=[inStart2,inStart3],h=inStep,a=inCondition,u=lispify(e,new CodeString((i[1]||"let ")+i[3]+" = $$keys[$$keyIndex]"),["initialize"]));else{if(3!==o.length)throw new SyntaxError("Invalid for loop definition");d=lispifyExpr(e,o.shift(),startingExecpted),a=lispifyReturnExpr(e,o.shift()),h=lispifyExpr(e,o.shift())}c=restOfExp(e,n.substring(l)).trim(),"{"===c[0]&&(c=c.slice(1,-1));break;case"do":f=0;const y=!!r[3];c=restOfExp(e,n.substring(r[0].length),y?[/^\}/]:[semiColon]),a=lispifyReturnExpr(e,restOfExp(e,n.substring(n.toString().indexOf("(",r[0].length+c.length)+1),[],"("))}const g=[f,p,s,d,h,a,u];o.lispTree=createLisp({op:38,a:g,b:lispifyBlock(c,e)})})),setLispType(["block"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:42,a:lispifyBlock(restOfExp(e,n.substring(1),[],"{"),e),b:0})})),setLispType(["loopAction"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:86,a:r[1],b:0})}));const catchReg=/^\s*(catch\s*(\(\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\))?|finally)\s*\{/;setLispType(["try"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[],"{");let a,c,l=catchReg.exec(n.substring(r[0].length+s.length+1).toString()),d="",p=0;l[1].startsWith("catch")?(l=catchReg.exec(n.substring(r[0].length+s.length+1).toString()),d=l[2],c=restOfExp(e,n.substring(r[0].length+s.length+1+l[0].length),[],"{"),p=r[0].length+s.length+1+l[0].length+c.length+1,(l=catchReg.exec(n.substring(p).toString()))&&l[1].startsWith("finally")&&(a=restOfExp(e,n.substring(p+l[0].length),[],"{"))):a=restOfExp(e,n.substring(r[0].length+s.length+1+l[0].length),[],"{");const u=[d,lispifyBlock(insertSemicolons(e,c||emptyString),e),lispifyBlock(insertSemicolons(e,a||emptyString),e)];o.lispTree=createLisp({op:39,a:lispifyBlock(insertSemicolons(e,s),e),b:u})})),setLispType(["void","await"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[/^([^\s\.\?\w\$]|\?[^\.])/]);o.lispTree=lispify(e,n.substring(r[0].length+s.length),expectTypes[i].next,createLisp({op:"void"===t?87:44,a:lispify(e,s),b:0}))})),setLispType(["new"],((e,t,n,r,i,o)=>{let s=r[0].length;const a=restOfExp(e,n.substring(s),[],void 0,"(");s+=a.length+1;const c=[];if("("===n.char(s-1)){const t=restOfExp(e,n.substring(s),[],"(");let r;s+=t.length+1;let i=0;for(;(r=restOfExp(e,t.substring(i),[/^,/])).length;)i+=r.length+1,c.push(r.trim())}o.lispTree=lispify(e,n.substring(s),expectTypes.expEdge.next,createLisp({op:45,a:lispify(e,a,expectTypes.initialize.next),b:c.map((t=>lispify(e,t,expectTypes.initialize.next)))}))}));const ofStart2=lispify(void 0,new CodeString("let $$iterator = $$obj[Symbol.iterator]()"),["initialize"]),ofStart3=lispify(void 0,new CodeString("let $$next = $$iterator.next()"),["initialize"]),ofCondition=lispify(void 0,new CodeString("return !$$next.done"),["initialize"]),ofStep=lispify(void 0,new CodeString("$$next = $$iterator.next()")),inStart2=lispify(void 0,new CodeString("let $$keys = Object.keys($$obj)"),["initialize"]),inStart3=lispify(void 0,new CodeString("let $$keyIndex = 0"),["initialize"]),inStep=lispify(void 0,new CodeString("$$keyIndex++")),inCondition=lispify(void 0,new CodeString("return $$keyIndex < $$keys.length"),["initialize"]);var lastType;function lispify(e,t,n,r,i=!1){if(r=r||[0,0,0],n=n||expectTypes.initialize.next,void 0===t)return r;const o=(t=t.trimStart()).toString();if(!t.length&&!n.includes("expEnd"))throw new SyntaxError("Unexpected end of expression");if(!t.length)return r;let s,a={lispTree:r};for(let r of n)if("expEnd"!==r){for(let n in expectTypes[r].types)if("expEnd"!==n&&(s=expectTypes[r].types[n].exec(o))){lastType=n;try{lispTypes.get(n)(e,n,t,s,r,a)}catch(e){if(i&&e instanceof SyntaxError)throw new ParseError(e.message,o);throw e}break}if(s)break}if(!s&&t.length){if(t.char(0),i)throw new ParseError(`Unexpected token after ${lastType}: ${t.char(0)}`,o);throw new SyntaxError(`Unexpected token after ${lastType}: ${t.char(0)}`)}return a.lispTree}const startingExpectedWithoutSingle=startingExecpted.filter((e=>"expSingle"!==e));function lispifyExpr(e,t,n){if(!t.trimStart().length)return;let r,i=[],o=0;if((n=n||expectTypes.initialize.next).includes("expSingle")&&testMultiple(t.toString(),Object.values(expectTypes.expSingle.types)))return lispify(e,t,["expSingle"],void 0,!0);for(n===startingExecpted&&(n=startingExpectedWithoutSingle);(r=restOfExp(e,t.substring(o),[/^,/])).length;)i.push(r.trimStart()),o+=r.length+1;if(1===i.length)return lispify(e,t,n,void 0,!0);if(n.includes("initialize")){let r=expectTypes.initialize.types.initialize.exec(i[0].toString());if(r)return createLisp({op:42,a:i.map(((t,n)=>lispify(e,n?new CodeString(r[1]+" "+t):t,["initialize"],void 0,!0))),b:0});if(expectTypes.initialize.types.return.exec(i[0].toString()))return lispify(e,t,n,void 0,!0)}const s=i.map(((t,r)=>lispify(e,t,n,void 0,!0)));return createLisp({op:43,a:s,b:0})}function lispifyReturnExpr(e,t){return createLisp({op:8,a:0,b:lispifyExpr(e,t)})}function lispifyBlock(e,t,n=!1){if(!(e=insertSemicolons(t,e)).trim().length)return[];let r,i=[],o=0,s=0,a={},c=!1,l=!1;for(;(r=restOfExp(t,e.substring(o),[semiColon],void 0,void 0,void 0,a)).length&&(l=e.char(o+r.length)&&";"!==e.char(o+r.length),o+=r.length+(l?0:1),/^\s*else(?![\w\$])/.test(e.substring(o).toString())||a.words.includes("do")&&/^\s*while(?![\w\$])/.test(e.substring(o).toString())?c=!0:(c=!1,i.push(e.substring(s,o-(l?0:1))),s=o),a={},!n););return c&&i.push(e.substring(s,o-(l?0:1))),i.map((e=>e.trimStart())).filter((e=>e.length)).map(((e,n)=>lispifyExpr(t,e.trimStart(),startingExecpted)))}function lispifyFunction(e,t,n=!1){if(!e.trim().length)return[];const r=lispifyBlock(e,t,n);let i=[];return hoist(r,i),i.concat(r)}function isLisp(e){return Array.isArray(e)&&"number"==typeof e[0]&&0!==e[0]&&88!==e[0]}function hoist(e,t){if(isLisp(e)){const[n,r,i]=e;if(39===n||13===n||38===n||40===n)hoist(r,t),hoist(i,t);else if(34===n)t.push(createLisp({op:34,a:r,b:0}));else if(37===n&&r[1])return t.push(e),!0}else if(Array.isArray(e)){const n=[];for(let r of e)hoist(r,t)||n.push(r);n.length!==e.length&&(e.length=0,e.push(...n))}return!1}const closingsNoInsertion=/^(\})\s*(catch|finally|else|while|instanceof)(?![\w\$])/,colonsRegex=/^((([\w\$\]\)\"\'\`]|\+\+|\-\-)\s*\r?\n\s*([\w\$\+\-\!~]))|(\}\s*[\w\$\!~\+\-\{\(\"\'\`]))/;function insertSemicolons(e,t){let n=t,r=emptyString,i={};const o=insertedSemicolons.get(t.ref)||new Array(t.ref.str.length);for(;(r=restOfExp(e,n,[],void 0,void 0,[colonsRegex],i)).length;){let e=!1,t=r,s=r.length;if(i.regRes){e=!0;const[,,o,,,a]=i.regRes;if(s="++"===i.regRes[3]||"--"===i.regRes[3]?r.length+1:r.length,t=n.substring(0,s),a){let t=closingsNoInsertion.exec(n.substring(r.length-1).toString());t?e="while"===t[2]&&"do"!==i.lastWord:"function"===i.lastWord&&"}"===i.regRes[5][0]&&"("===i.regRes[5].slice(-1)&&(e=!1)}else o&&("if"!==i.lastWord&&"while"!==i.lastWord&&"for"!==i.lastWord&&"else"!==i.lastWord||(e=!1))}e&&(o[t.end]=!0),n=n.substring(s),i={}}return insertedSemicolons.set(t.ref,o),t}function checkRegex(e){let t=1,n=!1,r=!1,i=!1;for(;t<e.length&&!r&&!i;)r="/"===e[t]&&!n,n="\\"===e[t]&&!n,i="\n"===e[t],t++;let o=e.substring(t);if(i=i||!r||/^\s*\d/.test(o),i)return null;let s=/^[a-z]*/.exec(o);return/^\s+[\w\$]/.test(e.substring(t+s[0].length))?null:{regex:e.substring(1,t-1),flags:s&&s[0]||"",length:t+(s&&s[0].length||0)}}const notDivide=/(typeof|delete|instanceof|return|in|of|throw|new|void|do|if)$/,possibleDivide=/^([\w\$\]\)]|\+\+|\-\-)[\s\/]/;function extractConstants(e,t,n=""){let r,i,o=[],s=!1,a="",c=-1,l=[],d="";const p=[],u=[];let f;for(var h=0;h<t.length;h++)if(d=t[h],a)d===a&&("*"===a&&"/"===t[h+1]?(a="",h++):"\n"===a&&(a=""));else{if(s){s=!1,o.push(d);continue}if(r)if("`"===r&&"$"===d&&"{"===t[h+1]){let n=extractConstants(e,t.substring(h+2),"{");l.push(n.str),o.push("${",l.length-1,"}"),h+=n.length+2}else if(r===d){if("`"===r){const t=createLisp({op:36,a:unraw(o.join("")),b:[]});t.tempJsStrings=l,e.literals.push(t),p.push("`",e.literals.length-1,"`")}else e.strings.push(unraw(o.join(""))),p.push('"',e.strings.length-1,'"');r=null,o=[]}else o.push(d);else{if("'"===d||'"'===d||"`"===d)l=[],r=d;else{if(closings[n]===d&&!u.length)return{str:p.join(""),length:h};closings[d]?(u.push(d),p.push(d)):closings[u[u.length-1]]===d?(u.pop(),p.push(d)):"/"!==d||"*"!==t[h+1]&&"/"!==t[h+1]?"/"===d&&!f&&(i=checkRegex(t.substring(h)))?(e.regexes.push(i),p.push("/",e.regexes.length-1,"/r"),h+=i.length-1):p.push(d):(a="*"===t[h+1]?"*":"\n",c=h)}f&&space.test(d)||(f=possibleDivide.exec(t.substring(h)))&&notDivide.test(t.substring(0,h+f[1].length))&&(f=null)}s=r&&"\\"===d}if(a&&"*"===a)throw new SyntaxError(`Unclosed comment '/*': ${t.substring(c)}`);return{str:p.join(""),length:h}}function parse$2(e,t=!1,n=!1){if("string"!=typeof e)throw new ParseError(`Cannot parse ${e}`,e);let r=" "+e;const i={strings:[],literals:[],regexes:[],eager:t};r=extractConstants(i,r).str;for(let e of i.literals)e[2]=e.tempJsStrings.map((e=>lispifyExpr(i,new CodeString(e)))),delete e.tempJsStrings;return{tree:lispifyFunction(new CodeString(r),i,n),constants:i}}class ExecReturn{constructor(e,t,n,r=!1,i=!1){this.auditReport=e,this.result=t,this.returned=n,this.breakLoop=r,this.continueLoop=i}}class Prop{constructor(e,t,n=!1,r=!1,i=!1){this.context=e,this.prop=t,this.isConst=n,this.isGlobal=r,this.isVariable=i}get(e){if(void 0===this.context)throw new ReferenceError(`${this.prop} is not defined`);return e.getSubscriptions.forEach((e=>e(this.context,this.prop))),this.context[this.prop]}}const optional={},reservedWords=new Set(["instanceof","typeof","return","try","catch","if","finally","else","in","of","var","let","const","for","delete","false","true","while","do","break","continue","new","function","async","await","switch","case"]);var VarType;function keysOnly(e){const t=Object.assign({},e);for(let e in t)t[e]=!0;return t}!function(e){e.let="let",e.const="const",e.var="var"}(VarType||(VarType={}));class Scope{constructor(e,t={},n){this.const={},this.let={},this.var={};const r=void 0!==n||null===e;this.parent=e,this.allVars=t,this.let=r?this.let:keysOnly(t),this.var=r?keysOnly(t):this.var,this.globals=null===e?keysOnly(t):{},this.functionThis=n}get(e,t=!1){if("this"===e&&void 0!==this.functionThis)return new Prop({this:this.functionThis},e,!0,!1,!0);if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");if(null===this.parent||!t||void 0!==this.functionThis){if(this.globals.hasOwnProperty(e))return new Prop(this.functionThis,e,!1,!0,!0);if(e in this.allVars&&(!(e in{})||this.allVars.hasOwnProperty(e)))return new Prop(this.allVars,e,this.const.hasOwnProperty(e),this.globals.hasOwnProperty(e),!0);if(null===this.parent)return new Prop(void 0,e)}return this.parent.get(e,t)}set(e,t){if("this"===e)throw new SyntaxError('"this" cannot be assigned');if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");let n=this.get(e);if(void 0===n.context)throw new ReferenceError(`Variable '${e}' was not declared.`);if(n.isConst)throw new TypeError(`Cannot assign to const variable '${e}'`);if(n.isGlobal)throw new SandboxError(`Cannot override global variable '${e}'`);return n.context[n.prop]=t,n}declare(e,t=null,n=void 0,r=!1){if("this"===e)throw new SyntaxError('"this" cannot be declared');if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");if("var"===t&&void 0===this.functionThis&&null!==this.parent)return this.parent.declare(e,t,n,r);if((!this[t].hasOwnProperty(e)||"const"===t||this.globals.hasOwnProperty(e))&&e in this.allVars)throw new SandboxError(`Identifier '${e}' has already been declared`);return r&&(this.globals[e]=!0),this[t][e]=!0,this.allVars[e]=n,new Prop(this.allVars,e,this.const.hasOwnProperty(e),r)}}class LocalScope{}class SandboxError extends Error{}let currentTicks;function sandboxFunction(e,t){return function(...t){let n=parse$2(t.pop()||"");return createFunction(t,n.tree,currentTicks,{...e,constants:n.constants,tree:n.tree},void 0,"anonymous")}}function generateArgs(e,t){const n={};return e.forEach(((e,r)=>{e.startsWith("...")?n[e.substring(3)]=t.slice(r):n[e]=t[r]})),n}const sandboxedFunctions=new WeakSet;function createFunction(e,t,n,r,i,o){if(r.ctx.options.forbidFunctionCreation)throw new SandboxError("Function creation is forbidden");let s;return s=void 0===o?(...o)=>{const s=generateArgs(e,o);return executeTree(n,r,t,void 0===i?[]:[new Scope(i,s)]).result}:function(...o){const s=generateArgs(e,o);return executeTree(n,r,t,void 0===i?[]:[new Scope(i,s,this)]).result},r.registerSandboxFunction(s),sandboxedFunctions.add(s),s}function createFunctionAsync(e,t,n,r,i,o){if(r.ctx.options.forbidFunctionCreation)throw new SandboxError("Function creation is forbidden");if(!r.ctx.prototypeWhitelist?.has(Promise.prototype))throw new SandboxError("Async/await not permitted");let s;return s=void 0===o?async(...o)=>{const s=generateArgs(e,o);return(await executeTreeAsync(n,r,t,void 0===i?[]:[new Scope(i,s)])).result}:async function(...o){const s=generateArgs(e,o);return(await executeTreeAsync(n,r,t,void 0===i?[]:[new Scope(i,s,this)])).result},r.registerSandboxFunction(s),sandboxedFunctions.add(s),s}function sandboxedEval(e){return function(t){return e(t)()}}function sandboxedSetTimeout(e){return function(t,...n){return"string"!=typeof t?setTimeout(t,...n):setTimeout(e(t),...n)}}function sandboxedSetInterval(e){return function(t,...n){return"string"!=typeof t?setInterval(t,...n):setInterval(e(t),...n)}}function assignCheck(e,t,n="assign"){if(void 0===e.context)throw new ReferenceError(`Cannot ${n} value to undefined.`);if("object"!=typeof e.context&&"function"!=typeof e.context)throw new SyntaxError(`Cannot ${n} value to a primitive.`);if(e.isConst)throw new TypeError(`Cannot set value to const variable '${e.prop}'`);if(e.isGlobal)throw new SandboxError(`Cannot ${n} property '${e.prop}' of a global object`);if("function"==typeof e.context[e.prop]&&!e.context.hasOwnProperty(e.prop))throw new SandboxError(`Override prototype property '${e.prop}' not allowed`);"delete"===n?e.context.hasOwnProperty(e.prop)&&(t.changeSubscriptions.get(e.context)?.forEach((t=>t({type:"delete",prop:e.prop}))),t.changeSubscriptionsGlobal.get(e.context)?.forEach((t=>t({type:"delete",prop:e.prop})))):e.context.hasOwnProperty(e.prop)?(t.setSubscriptions.get(e.context)?.get(e.prop)?.forEach((e=>e({type:"replace"}))),t.setSubscriptionsGlobal.get(e.context)?.get(e.prop)?.forEach((e=>e({type:"replace"})))):(t.changeSubscriptions.get(e.context)?.forEach((t=>t({type:"create",prop:e.prop}))),t.changeSubscriptionsGlobal.get(e.context)?.forEach((t=>t({type:"create",prop:e.prop}))))}const arrayChange=new Set([[].push,[].pop,[].shift,[].unshift,[].splice,[].reverse,[].sort,[].copyWithin]);class KeyVal{constructor(e,t){this.key=e,this.val=t}}class SpreadObject{constructor(e){this.item=e}}class SpreadArray{constructor(e){this.item=e}}class If{constructor(e,t){this.t=e,this.f=t}}const literalRegex=/(\$\$)*(\$)?\${(\d+)}/g,ops=new Map;function addOps(e,t){ops.set(e,t)}function valueOrProp(e,t){return e instanceof Prop?e.get(t):e!==optional?e:void 0}function execMany(e,t,n,r,i,o,s){t===execSync?_execManySync(e,n,r,i,o,s):_execManyAsync(e,n,r,i,o,s).catch(r)}function _execManySync(e,t,n,r,i,o){let s=[];for(let a=0;a<t.length;a++){let c;try{c=syncDone((n=>execSync(e,t[a],r,i,n,o))).result}catch(e){return void n(e)}if(c instanceof ExecReturn&&(c.returned||c.breakLoop||c.continueLoop))return void n(void 0,c);if(isLisp(t[a])&&8===t[a][0])return void n(void 0,new ExecReturn(i.ctx.auditReport,c,!0));s.push(c)}n(void 0,s)}async function _execManyAsync(e,t,n,r,i,o){let s=[];for(let a=0;a<t.length;a++){let c;try{let n;c=!0===(n=asyncDone((n=>execAsync(e,t[a],r,i,n,o)))).isInstant?n.instant:(await n.p).result}catch(e){return void n(e)}if(c instanceof ExecReturn&&(c.returned||c.breakLoop||c.continueLoop))return void n(void 0,c);if(isLisp(t[a])&&8===t[a][0])return void n(void 0,new ExecReturn(i.ctx.auditReport,c,!0));s.push(c)}n(void 0,s)}function asyncDone(e){let t,n=!1;const r=new Promise(((r,i)=>{e(((e,o)=>{e?i(e):(n=!0,t=o,r({result:o}))}))}));return{isInstant:n,instant:t,p:r}}function syncDone(e){let t,n;if(e(((e,r)=>{n=e,t=r})),n)throw n;return{result:t}}async function execAsync(e,t,n,r,i,o){let s=i;const a=new Promise((e=>{s=(t,n)=>{i(t,n),e()}}));if(_execNoneRecurse(e,t,n,r,s,!0,o));else if(isLisp(t)){let i,a=t[0];try{let s;i=!0===(s=asyncDone((i=>execAsync(e,t[1],n,r,i,o)))).isInstant?s.instant:(await s.p).result}catch(e){return void s(e)}let c,l=i;try{l=i instanceof Prop?i.get(r):i}catch(e){return void s(e)}if(20===a||21===a){if(null==l)return void s(void 0,optional);a=20===a?1:5}if(l===optional){if(1===a||5===a)return void s(void 0,l);l=void 0}try{let i;c=!0===(i=asyncDone((i=>execAsync(e,t[2],n,r,i,o)))).isInstant?i.instant:(await i.p).result}catch(e){return void s(e)}let d=c;try{d=c instanceof Prop?c.get(r):c}catch(e){return void s(e)}if(d===optional&&(d=void 0),ops.has(a))try{ops.get(a)(execAsync,s,e,l,d,i,r,n,c,o)}catch(e){s(e)}else s(new SyntaxError("Unknown operator: "+a))}await a}function execSync(e,t,n,r,i,o){if(_execNoneRecurse(e,t,n,r,i,!1,o));else if(isLisp(t)){let s,a=t[0];try{s=syncDone((i=>execSync(e,t[1],n,r,i,o))).result}catch(e){return void i(e)}let c,l=s;try{l=s instanceof Prop?s.get(r):s}catch(e){return void i(e)}if(20===a||21===a){if(null==l)return void i(void 0,optional);a=20===a?1:5}if(l===optional){if(1===a||5===a)return void i(void 0,l);l=void 0}try{c=syncDone((i=>execSync(e,t[2],n,r,i,o))).result}catch(e){return void i(e)}let d=c;try{d=c instanceof Prop?c.get(r):c}catch(e){return void i(e)}if(d===optional&&(d=void 0),ops.has(a))try{ops.get(a)(execSync,i,e,l,d,s,r,n,c,o)}catch(e){i(e)}else i(new SyntaxError("Unknown operator: "+a))}}addOps(1,((e,t,n,r,i,o,s,a)=>{if(null===r)throw new TypeError(`Cannot get property ${i} of null`);const c=typeof r;if("undefined"===c&&void 0===o){let e=a.get(i);if(e.context===s.ctx.sandboxGlobal){s.ctx.options.audit&&s.ctx.auditReport.globalsAccess.add(i);const e=s.ctx.globalsWhitelist.has(s.ctx.sandboxGlobal[i])?s.evals.get(s.ctx.sandboxGlobal[i]):void 0;if(e)return void t(void 0,e)}return e.context&&e.context[i]===globalThis?void t(void 0,s.ctx.globalScope.get("this")):void t(void 0,e)}if(void 0===r)throw new SandboxError("Cannot get property '"+i+"' of undefined");if("object"!==c)"number"===c?r=new Number(r):"string"===c?r=new String(r):"boolean"===c&&(r=new Boolean(r));else if(void 0===r.hasOwnProperty)return void t(void 0,new Prop(void 0,i));const l="function"===c;let d=l||!(r.hasOwnProperty(i)||"number"==typeof i);if(s.ctx.options.audit&&d&&"string"==typeof i){let e=Object.getPrototypeOf(r);do{e.hasOwnProperty(i)&&(s.ctx.auditReport.prototypeAccess[e.constructor.name]||(s.ctx.auditReport.prototypeAccess[e.constructor.name]=new Set),s.ctx.auditReport.prototypeAccess[e.constructor.name].add(i))}while(e=Object.getPrototypeOf(e))}if(d)if(l){if(!["name","length","constructor"].includes(i)&&r.hasOwnProperty(i)){const e=s.ctx.prototypeWhitelist.get(r.prototype),n=s.ctx.options.prototypeReplacements.get(r);if(n)return void t(void 0,new Prop(n(r,!0),i));if(!e||e.size&&!e.has(i))throw new SandboxError(`Static method or property access not permitted: ${r.name}.${i}`)}}else if("constructor"!==i){let e=r;for(;e=Object.getPrototypeOf(e);)if(e.hasOwnProperty(i)){const n=s.ctx.prototypeWhitelist.get(e),o=s.ctx.options.prototypeReplacements.get(e.constuctor);if(o)return void t(void 0,new Prop(o(r,!1),i));if(n&&(!n.size||n.has(i)))break;throw new SandboxError(`Method or property access not permitted: ${e.constructor.name}.${i}`)}}if(s.evals.has(r[i]))return void t(void 0,s.evals.get(r[i]));if(r[i]===globalThis)return void t(void 0,s.ctx.globalScope.get("this"));let p=o.isGlobal||l&&!sandboxedFunctions.has(r)||s.ctx.globalsWhitelist.has(r);t(void 0,new Prop(r,i,!1,p))})),addOps(5,((e,t,n,r,i,o,s,a)=>{if(s.ctx.options.forbidFunctionCalls)throw new SandboxError("Function invocations are not allowed");if("function"!=typeof r)throw new TypeError(`${"symbol"==typeof o.prop?"Symbol":o.prop} is not a function`);const c=i.map((e=>e instanceof SpreadArray?[...e.item]:[e])).flat().map((e=>valueOrProp(e,s)));if("function"!=typeof o){if(o.context[o.prop]===JSON.stringify&&s.getSubscriptions.size){const e=new Set,t=n=>{if(n&&"object"==typeof n&&!e.has(n)){e.add(n);for(let e in n)s.getSubscriptions.forEach((t=>t(n,e))),t(n[e])}};t(c[0])}if(o.context instanceof Array&&arrayChange.has(o.context[o.prop])&&(s.changeSubscriptions.get(o.context)||s.changeSubscriptionsGlobal.get(o.context))){let e,t=!1;if("push"===o.prop)e={type:"push",added:c},t=!!c.length;else if("pop"===o.prop)e={type:"pop",removed:o.context.slice(-1)},t=!!e.removed.length;else if("shift"===o.prop)e={type:"shift",removed:o.context.slice(0,1)},t=!!e.removed.length;else if("unshift"===o.prop)e={type:"unshift",added:c},t=!!c.length;else if("splice"===o.prop)e={type:"splice",startIndex:c[0],deleteCount:void 0===c[1]?o.context.length:c[1],added:c.slice(2),removed:o.context.slice(c[0],void 0===c[1]?void 0:c[0]+c[1])},t=!!e.added.length||!!e.removed.length;else if("reverse"===o.prop||"sort"===o.prop)e={type:o.prop},t=!!o.context.length;else if("copyWithin"===o.prop){let n=void 0===c[2]?o.context.length-c[1]:Math.min(o.context.length,c[2]-c[1]);e={type:"copyWithin",startIndex:c[0],endIndex:c[0]+n,added:o.context.slice(c[1],c[1]+n),removed:o.context.slice(c[0],c[0]+n)},t=!!e.added.length||!!e.removed.length}t&&(s.changeSubscriptions.get(o.context)?.forEach((t=>t(e))),s.changeSubscriptionsGlobal.get(o.context)?.forEach((t=>t(e))))}o.get(s),t(void 0,o.context[o.prop](...c))}else t(void 0,o(...c))})),addOps(22,((e,t,n,r,i,o,s,a)=>{let c={};for(let e of i)e.key instanceof SpreadObject?c={...c,...e.key.item}:c[e.key]=e.val;t(void 0,c)})),addOps(6,((e,t,n,r,i)=>t(void 0,new KeyVal(r,i)))),addOps(12,((e,t,n,r,i,o,s,a)=>{t(void 0,i.map((e=>e instanceof SpreadArray?[...e.item]:[e])).flat().map((e=>valueOrProp(e,s))))})),addOps(23,((e,t,n,r,i)=>t(void 0,i))),addOps(35,((e,t,n,r,i)=>{switch(i){case"true":return t(void 0,!0);case"false":return t(void 0,!1);case"null":return t(void 0,null);case"undefined":return t(void 0,void 0);case"NaN":return t(void 0,NaN);case"Infinity":return t(void 0,1/0)}t(new Error("Unknown symbol: "+i))})),addOps(7,((e,t,n,r,i)=>t(void 0,Number(i)))),addOps(83,((e,t,n,r,i)=>t(void 0,BigInt(i)))),addOps(2,((e,t,n,r,i,o,s)=>t(void 0,s.constants.strings[parseInt(i)]))),addOps(85,((e,t,n,r,i,o,s)=>{const a=s.constants.regexes[parseInt(i)];if(!s.ctx.globalsWhitelist.has(RegExp))throw new SandboxError("Regex not permitted");t(void 0,new RegExp(a.regex,a.flags))})),addOps(84,((e,t,n,r,i,o,s,a)=>{let c=s.constants.literals[parseInt(i)];const[,l,d]=c;let p,u=[],f=[];for(;p=literalRegex.exec(l);)p[2]||(u.push(d[parseInt(p[3],10)]),f.push(p[3]));e(n,u,a,s,((e,n)=>{const r={};if(e)t(e);else{for(let e in f){const t=f[e];r[t]=n[e]}t(void 0,l.replace(/(\\\\)*(\\)?\${(\d+)}/g,((e,t,n,i)=>{if(n)return e;return(t||"")+`${valueOrProp(r[i],s)}`})))}}))})),addOps(18,((e,t,n,r,i,o,s,a)=>{t(void 0,new SpreadArray(i))})),addOps(17,((e,t,n,r,i,o,s,a)=>{t(void 0,new SpreadObject(i))})),addOps(24,((e,t,n,r,i)=>t(void 0,!i))),addOps(64,((e,t,n,r,i)=>t(void 0,~i))),addOps(25,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,++o.context[o.prop])})),addOps(26,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]++)})),addOps(27,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,--o.context[o.prop])})),addOps(28,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]--)})),addOps(9,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]=i)})),addOps(66,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]+=i)})),addOps(65,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]-=i)})),addOps(67,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]/=i)})),addOps(69,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]*=i)})),addOps(68,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]**=i)})),addOps(70,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]%=i)})),addOps(71,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]^=i)})),addOps(72,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]&=i)})),addOps(73,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]|=i)})),addOps(76,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]<<=i)})),addOps(75,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]>>=i)})),addOps(74,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]>>=i)})),addOps(57,((e,t,n,r,i)=>t(void 0,r>i))),addOps(56,((e,t,n,r,i)=>t(void 0,r<i))),addOps(55,((e,t,n,r,i)=>t(void 0,r>=i))),addOps(54,((e,t,n,r,i)=>t(void 0,r<=i))),addOps(52,((e,t,n,r,i)=>t(void 0,r==i))),addOps(32,((e,t,n,r,i)=>t(void 0,r===i))),addOps(53,((e,t,n,r,i)=>t(void 0,r!=i))),addOps(31,((e,t,n,r,i)=>t(void 0,r!==i))),addOps(29,((e,t,n,r,i)=>t(void 0,r&&i))),addOps(30,((e,t,n,r,i)=>t(void 0,r||i))),addOps(77,((e,t,n,r,i)=>t(void 0,r&i))),addOps(78,((e,t,n,r,i)=>t(void 0,r|i))),addOps(33,((e,t,n,r,i)=>t(void 0,r+i))),addOps(47,((e,t,n,r,i)=>t(void 0,r-i))),addOps(59,((e,t,n,r,i)=>t(void 0,+i))),addOps(58,((e,t,n,r,i)=>t(void 0,-i))),addOps(48,((e,t,n,r,i)=>t(void 0,r/i))),addOps(79,((e,t,n,r,i)=>t(void 0,r^i))),addOps(50,((e,t,n,r,i)=>t(void 0,r*i))),addOps(51,((e,t,n,r,i)=>t(void 0,r%i))),addOps(80,((e,t,n,r,i)=>t(void 0,r<<i))),addOps(81,((e,t,n,r,i)=>t(void 0,r>>i))),addOps(82,((e,t,n,r,i)=>t(void 0,r>>>i))),addOps(60,((e,t,n,r,i,o,s,a)=>{e(n,i,a,s,((e,n)=>{t(void 0,typeof valueOrProp(n,s))}))})),addOps(62,((e,t,n,r,i)=>t(void 0,r instanceof i))),addOps(63,((e,t,n,r,i)=>t(void 0,r in i))),addOps(61,((e,t,n,r,i,o,s,a,c)=>{void 0!==c.context?(assignCheck(c,s,"delete"),c.isVariable?t(void 0,!1):t(void 0,delete c.context[c.prop])):t(void 0,!0)})),addOps(8,((e,t,n,r,i,o,s)=>t(void 0,i))),addOps(34,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.var,i))})),addOps(3,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.let,i,c&&c.isGlobal))})),addOps(4,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.const,i))})),addOps(11,((e,t,n,r,i,o,s,a)=>{r=[...r],("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants)),r.shift()?t(void 0,createFunctionAsync(r,i,n,s,a)):t(void 0,createFunction(r,i,n,s,a))})),addOps(37,((e,t,n,r,i,o,s,a)=>{("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants));let c,l=r.shift(),d=r.shift();c=88===l?createFunctionAsync(r,i,n,s,a,d):createFunction(r,i,n,s,a,d),d&&a.declare(d,VarType.var,c),t(void 0,c)})),addOps(10,((e,t,n,r,i,o,s,a)=>{("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants));let c,l=r.shift(),d=r.shift();d&&(a=new Scope(a,{})),c=88===l?createFunctionAsync(r,i,n,s,a,d):createFunction(r,i,n,s,a,d),d&&a.declare(d,VarType.let,c),t(void 0,c)})),addOps(38,((e,t,n,r,i,o,s,a)=>{const[c,l,d,p,u,f,h]=r;let g=!0;const y=new Scope(a,{});let x={$$obj:void 0};const v=new Scope(y,x);if(e===execAsync)(async()=>{let r;for(r=asyncDone((t=>e(n,p,y,s,t))),x.$$obj=!0===(r=asyncDone((t=>e(n,d,y,s,t)))).isInstant?r.instant:(await r.p).result,r=asyncDone((t=>e(n,l,v,s,t))),c&&(g=!0===(r=asyncDone((t=>e(n,f,v,s,t)))).isInstant?r.instant:(await r.p).result);g;){let o={};r=asyncDone((t=>e(n,h,new Scope(v,o),s,t))),!0===r.isInstant?r.instant:(await r.p).result;let a=await executeTreeAsync(n,s,i,[new Scope(y,o)],"loop");if(a instanceof ExecReturn&&a.returned)return void t(void 0,a);if(a instanceof ExecReturn&&a.breakLoop)break;r=asyncDone((t=>e(n,u,v,s,t))),g=!0===(r=asyncDone((t=>e(n,f,v,s,t)))).isInstant?r.instant:(await r.p).result}t()})().catch(t);else{for(syncDone((t=>e(n,p,y,s,t))),x.$$obj=syncDone((t=>e(n,d,y,s,t))).result,syncDone((t=>e(n,l,v,s,t))),c&&(g=syncDone((t=>e(n,f,v,s,t))).result);g;){let r={};syncDone((t=>e(n,h,new Scope(v,r),s,t)));let o=executeTree(n,s,i,[new Scope(y,r)],"loop");if(o instanceof ExecReturn&&o.returned)return void t(void 0,o);if(o instanceof ExecReturn&&o.breakLoop)break;syncDone((t=>e(n,u,v,s,t))),g=syncDone((t=>e(n,f,v,s,t))).result}t()}})),addOps(86,((e,t,n,r,i,o,s,a,c,l)=>{if("switch"===l&&"continue"===r||!l)throw new SandboxError("Illegal "+r+" statement");t(void 0,new ExecReturn(s.ctx.auditReport,void 0,!1,"break"===r,"continue"===r))})),addOps(13,((e,t,n,r,i,o,s,a,c,l)=>{e(n,valueOrProp(r,s)?i.t:i.f,a,s,t)})),addOps(15,((e,t,n,r,i,o,s,a)=>{e(n,valueOrProp(r,s)?i.t:i.f,a,s,t)})),addOps(16,((e,t,n,r,i)=>t(void 0,new If(r,i)))),addOps(14,((e,t,n,r,i)=>t(void 0,new If(r,i)))),addOps(40,((e,t,n,r,i,o,s,a)=>{e(n,r,a,s,((r,o)=>{if(r)t(r);else if(o=valueOrProp(o,s),e===execSync){let r,c=!1;for(let l of i)if(c||(c=!l[1]||o===valueOrProp(syncDone((t=>e(n,l[1],a,s,t))).result,s))){if(!l[2])continue;if(r=executeTree(n,s,l[2],[a],"switch"),r.breakLoop)break;if(r.returned)return void t(void 0,r);if(!l[1])break}t()}else(async()=>{let r,c=!1;for(let l of i){let i;if(c||(c=!l[1]||o===valueOrProp(!0===(i=asyncDone((t=>e(n,l[1],a,s,t)))).isInstant?i.instant:(await i.p).result,s))){if(!l[2])continue;if(r=await executeTreeAsync(n,s,l[2],[a],"switch"),r.breakLoop)break;if(r.returned)return void t(void 0,r);if(!l[1])break}}t()})().catch(t)}))})),addOps(39,((e,t,n,r,i,o,s,a,c,l)=>{const[d,p,u]=i;executeTreeWithDone(e,((r,i)=>{executeTreeWithDone(e,(o=>{o?t(o):r?executeTreeWithDone(e,t,n,s,p,[new Scope(a)],l):t(void 0,i)}),n,s,u,[new Scope(a,{})])}),n,s,r,[new Scope(a)],l)})),addOps(87,((e,t,n,r)=>{t()})),addOps(45,((e,t,n,r,i,o,s)=>{if(!s.ctx.globalsWhitelist.has(r)&&!sandboxedFunctions.has(r))throw new SandboxError(`Object construction not allowed: ${r.constructor.name}`);t(void 0,new r(...i))})),addOps(46,((e,t,n,r,i)=>{t(i)})),addOps(43,((e,t,n,r)=>t(void 0,r.pop()))),addOps(0,((e,t,n,r)=>t()));const unexecTypes=new Set([11,37,10,38,39,40,14,16,60]);function _execNoneRecurse(e,t,n,r,i,o,s){const a=o?execAsync:execSync;if(!(r.ctx.options.executionQuota<=e.ticks)||"function"==typeof r.ctx.options.onExecutionQuotaReached&&r.ctx.options.onExecutionQuotaReached(e,n,r,t)){if(e.ticks++,currentTicks=e,t instanceof Prop)try{i(void 0,t.get(r))}catch(e){i(e)}else if(t===optional)i();else if(Array.isArray(t)&&!isLisp(t))0===t[0]?i():execMany(e,a,t,i,n,r,s);else if(isLisp(t))if(42===t[0])execMany(e,a,t[1],i,n,r,s);else if(44===t[0])o?r.ctx.prototypeWhitelist?.has(Promise.prototype)?execAsync(e,t[1],n,r,(async(e,t)=>{if(e)i(e);else try{i(void 0,await valueOrProp(t,r))}catch(e){i(e)}}),s).catch(i):i(new SandboxError("Async/await is not permitted")):i(new SandboxError("Illegal use of 'await', must be inside async function"));else{if(!unexecTypes.has(t[0]))return!1;try{ops.get(t[0])(a,i,e,t[1],t[2],t,r,n,void 0,s)}catch(e){i(e)}}else i(void 0,t);return!0}i(new SandboxError("Execution quota exceeded"))}function executeTree(e,t,n,r=[],i){return syncDone((o=>executeTreeWithDone(execSync,o,e,t,n,r,i))).result}async function executeTreeAsync(e,t,n,r=[],i){let o;return!0===(o=asyncDone((o=>executeTreeWithDone(execAsync,o,e,t,n,r,i)))).isInstant?o.instant:(await o.p).result}function executeTreeWithDone(e,t,n,r,i,o=[],s){if(!i)return void t();if(!(i instanceof Array))throw new SyntaxError("Bad execution tree");let a,c=r.ctx.globalScope;for(;a=o.shift();)"object"==typeof a&&(c=a instanceof Scope?a:new Scope(c,a,a instanceof LocalScope?void 0:null));r.ctx.options.audit&&!r.ctx.auditReport&&(r.ctx.auditReport={globalsAccess:new Set,prototypeAccess:{}}),e===execSync?_executeWithDoneSync(t,n,r,i,c,s):_executeWithDoneAsync(t,n,r,i,c,s).catch(t)}function _executeWithDoneSync(e,t,n,r,i,o){if(!(r instanceof Array))throw new SyntaxError("Bad execution tree");let s=0;for(s=0;s<r.length;s++){let a,c;const l=r[s];try{execSync(t,l,i,n,((e,t)=>{c=e,a=t}),o)}catch(e){c=e}if(c)return void e(c);if(a instanceof ExecReturn)return void e(void 0,a);if(isLisp(l)&&8===l[0])return void e(void 0,new ExecReturn(n.ctx.auditReport,a,!0))}e(void 0,new ExecReturn(n.ctx.auditReport,void 0,!1))}async function _executeWithDoneAsync(e,t,n,r,i,o){if(!(r instanceof Array))throw new SyntaxError("Bad execution tree");let s=0;for(s=0;s<r.length;s++){let a,c;const l=r[s];try{await execAsync(t,l,i,n,((e,t)=>{c=e,a=t}),o)}catch(e){c=e}if(c)return void e(c);if(a instanceof ExecReturn)return void e(void 0,a);if(isLisp(l)&&8===l[0])return void e(void 0,new ExecReturn(n.ctx.auditReport,a,!0))}e(void 0,new ExecReturn(n.ctx.auditReport,void 0,!1))}class SandboxGlobal{constructor(e){if(e===globalThis)return globalThis;for(let t in e)this[t]=e[t]}}class ExecContext{constructor(e,t,n,r,i,o,s,a,c,l){this.ctx=e,this.constants=t,this.tree=n,this.getSubscriptions=r,this.setSubscriptions=i,this.changeSubscriptions=o,this.setSubscriptionsGlobal=s,this.changeSubscriptionsGlobal=a,this.evals=c,this.registerSandboxFunction=l}}function subscribeSet(e,t,n,r){const i=r.setSubscriptions.get(e)||new Map;r.setSubscriptions.set(e,i);const o=i.get(t)||new Set;let s;return i.set(t,o),o.add(n),e&&e[t]&&"object"==typeof e[t]&&(s=r.changeSubscriptions.get(e[t])||new Set,s.add(n),r.changeSubscriptions.set(e[t],s)),{unsubscribe:()=>{o.delete(n),s?.delete(n)}}}class Sandbox{constructor(e){this.setSubscriptions=new WeakMap,this.changeSubscriptions=new WeakMap,this.sandboxFunctions=new WeakMap,e=Object.assign({audit:!1,forbidFunctionCalls:!1,forbidFunctionCreation:!1,globals:Sandbox.SAFE_GLOBALS,prototypeWhitelist:Sandbox.SAFE_PROTOTYPES,prototypeReplacements:new Map},e||{});const t=new SandboxGlobal(e.globals);this.context={sandbox:this,globalsWhitelist:new Set(Object.values(e.globals)),prototypeWhitelist:new Map([...e.prototypeWhitelist].map((e=>[e[0].prototype,e[1]]))),options:e,globalScope:new Scope(null,e.globals,t),sandboxGlobal:t},this.context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()),new Set)}static get SAFE_GLOBALS(){return{Function:Function,console:{debug:console.debug,error:console.error,info:console.info,log:console.log,table:console.table,warn:console.warn},isFinite:isFinite,isNaN:isNaN,parseFloat:parseFloat,parseInt:parseInt,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape,Boolean:Boolean,Number:Number,BigInt:BigInt,String:String,Object:Object,Array:Array,Symbol:Symbol,Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array,Map:Map,Set:Set,WeakMap:WeakMap,WeakSet:WeakSet,Promise:Promise,Intl:Intl,JSON:JSON,Math:Math,Date:Date,RegExp:RegExp}}static get SAFE_PROTOTYPES(){let e=[SandboxGlobal,Function,Boolean,Number,BigInt,String,Date,Error,Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Map,Set,WeakMap,WeakSet,Promise,Symbol,Date,RegExp],t=new Map;return e.forEach((e=>{t.set(e,new Set)})),t.set(Object,new Set(["entries","fromEntries","getOwnPropertyNames","is","keys","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf","values"])),t}subscribeGet(e,t){return t.getSubscriptions.add(e),{unsubscribe:()=>t.getSubscriptions.delete(e)}}subscribeSet(e,t,n,r){return subscribeSet(e,t,n,r)}subscribeSetGlobal(e,t,n){return subscribeSet(e,t,n,this)}static audit(e,t=[]){const n={};for(let e of Object.getOwnPropertyNames(globalThis))n[e]=globalThis[e];const r=new Sandbox({globals:n,audit:!0});return r.executeTree(r.createContext(r.context,parse$2(e)),t)}static parse(e){return parse$2(e)}createContext(context,executionTree){const evals=new Map,execContext=new ExecContext(context,executionTree.constants,executionTree.tree,new Set,new WeakMap,new WeakMap,this.setSubscriptions,this.changeSubscriptions,evals,(e=>this.sandboxFunctions.set(e,execContext))),func=sandboxFunction(execContext);return evals.set(Function,func),evals.set(eval,sandboxedEval(func)),evals.set(setTimeout,sandboxedSetTimeout(func)),evals.set(setInterval,sandboxedSetInterval(func)),execContext}getContext(e){return this.sandboxFunctions.get(e)}executeTree(e,t=[]){return executeTree({ticks:BigInt(0)},e,e.tree,t)}executeTreeAsync(e,t=[]){return executeTreeAsync({ticks:BigInt(0)},e,e.tree,t)}compile(e,t=!1){const n=parse$2(e,t);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTree(t,[...e]).result}}}compileAsync(e,t=!1){const n=parse$2(e,t);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTreeAsync(t,[...e]).then((e=>e.result))}}}compileExpression(e,t=!1){const n=parse$2(e,t,!0);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTree(t,[...e]).result}}}compileExpressionAsync(e,t=!1){const n=parse$2(e,t,!0);return(...e)=>{const t=this.createContext(this.context,n);return{context:t,run:()=>this.executeTreeAsync(t,[...e]).then((e=>e.result))}}}}const runInBrowserContext=(e,...t)=>__awaiter(void 0,[e,...t],void 0,(function*(e,t={}){try{const n=(new Sandbox).compile(e);return yield n(t).run()}catch(e){}})),getExpressionResult=(e,t)=>__awaiter(void 0,void 0,void 0,(function*(){return yield runInBrowserContext(e,t)}));class BaseNode{constructor({nodeConfig:e,context:t,globalData:n}){const{outgoing:r,incoming:i,id:o,type:s,properties:a}=e;this.baseType="base",this.outgoing=r,this.incoming=i,this.nodeId=o,this.type=s,this.properties=a,this.context=t,this.globalData=n}action(e){return __awaiter(this,void 0,void 0,(function*(){}))}onResume(e){return __awaiter(this,void 0,void 0,(function*(){}))}isPass(e){return __awaiter(this,void 0,void 0,(function*(){if(!e)return!0;const{conditionExpression:t}=e;if(!t)return!0;try{return yield getExpressionResult(`\n const isPassResult = (${t})\n return isPassResult\n `,Object.assign({},this.globalData))}catch(e){return!1}}))}getOutgoing(){return __awaiter(this,void 0,void 0,(function*(){const e=[],t=[];for(const e of this.outgoing){const{properties:n}=e;t.push(this.isPass(n))}return(yield Promise.all(t)).forEach(((t,n)=>{const r=this.outgoing[n];r.result=t,e.push(r)})),e}))}execute(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n}=e,r=yield this.action({nodeId:this.nodeId,executionId:t,actionId:n}),i=r?r.status:"success";if(i===exports.ActionStatus.SUCCESS){const i=yield this.getOutgoing(),o=r?r.detail:{};e.next({status:exports.ActionStatus.SUCCESS,detail:o,nodeId:this.nodeId,nodeType:this.type,properties:this.properties,executionId:t,actionId:n,outgoing:i})}return{status:i,detail:null==r?void 0:r.detail,executionId:t,actionId:n,nodeId:this.nodeId,nodeType:this.type,properties:this.properties,outgoing:[]}}))}resume(e){return __awaiter(this,void 0,void 0,(function*(){const t=yield this.getOutgoing();yield this.onResume({executionId:e.executionId,actionId:e.actionId,nodeId:e.nodeId,data:e.data}),e.next({executionId:e.executionId,actionId:e.actionId,nodeId:this.nodeId,nodeType:this.type,properties:this.properties,outgoing:t,status:exports.ActionStatus.SUCCESS})}))}}BaseNode.nodeTypeName="BaseNode";class StartNode extends BaseNode{constructor(){super(...arguments),this.baseType="start"}}StartNode.nodeTypeName="StartNode";class TaskNode extends BaseNode{constructor(){super(...arguments),this.baseType="task"}}TaskNode.nodeTypeName="TaskNode";class EventEmitter{constructor(){this._events={}}on(e,t,n){e=e.trim(),this._events[e]||(this._events[e]=[]),this._events[e].push({callback:t,once:!!n})}off(e,t){if(e||(this._events={}),t){const n=this._events[e]||[];let{length:r}=n;for(let e=0;e<r;e++)n[e].callback===t&&(n.splice(e,1),r--,e--);0===n.length&&delete this._events[e]}else delete this._events[e]}emit(e,t){(n=>{let{length:r}=n;for(let i=0;i<r;i++){if(!n[i])continue;const{callback:o,once:s}=n[i];s&&(n.splice(i,1),0===n.length&&delete this._events[e],r--,i--),o.apply(this,[t])}})(this._events[e]||[])}getEvents(){return this._events}}const isInBrowser="object"==typeof window&&window.window===window,isInNodeJS="object"==typeof global&&global.global===global,globalScope=isInBrowser?window:"object"==typeof self&&self.self===self?self:isInNodeJS?global:"object"==typeof globalThis?globalThis:{eval:()=>{}};if(!globalScope.sessionStorage){const e={data:{},setItem(t,n){e.data[t]=n},getItem:t=>e.data[t],removeItem(t){delete e.data[t]},clear(){e.data={}}};globalScope.sessionStorage=e}var storage={setItem(e,t){"object"==typeof t&&(t=JSON.stringify(t)),globalScope.sessionStorage.setItem(e,t)},getItem(e){const t=globalScope.sessionStorage.getItem(e);try{return JSON.parse(t)}catch(e){return t}},removeItem(e){globalScope.sessionStorage.removeItem(e)},clear(){globalScope.sessionStorage.clear()}};function getAugmentedNamespace(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];return n.push.apply(n,arguments),new(Function.bind.apply(t,n))}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}var dist={},v1$1={},rng$1={},_polyfillNode_crypto={},_polyfillNode_crypto$1=Object.freeze({__proto__:null,default:_polyfillNode_crypto}),require$$0=getAugmentedNamespace(_polyfillNode_crypto$1);Object.defineProperty(rng$1,"__esModule",{value:!0}),rng$1.default=rng;var _crypto$2=_interopRequireDefault$b(require$$0);function _interopRequireDefault$b(e){return e&&e.__esModule?e:{default:e}}const rnds8Pool=new Uint8Array(256);let poolPtr=rnds8Pool.length;function rng(){return poolPtr>rnds8Pool.length-16&&(_crypto$2.default.randomFillSync(rnds8Pool),poolPtr=0),rnds8Pool.slice(poolPtr,poolPtr+=16)}var stringify$1={},validate$1={},regex={};Object.defineProperty(regex,"__esModule",{value:!0}),regex.default=void 0;var _default$c=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;regex.default=_default$c,Object.defineProperty(validate$1,"__esModule",{value:!0}),validate$1.default=void 0;var _regex=_interopRequireDefault$a(regex);function _interopRequireDefault$a(e){return e&&e.__esModule?e:{default:e}}function validate(e){return"string"==typeof e&&_regex.default.test(e)}var _default$b=validate;validate$1.default=_default$b,Object.defineProperty(stringify$1,"__esModule",{value:!0}),stringify$1.default=void 0;var _validate$2=_interopRequireDefault$9(validate$1);function _interopRequireDefault$9(e){return e&&e.__esModule?e:{default:e}}const byteToHex=[];for(let e=0;e<256;++e)byteToHex.push((e+256).toString(16).substr(1));function stringify(e,t=0){const n=(byteToHex[e[t+0]]+byteToHex[e[t+1]]+byteToHex[e[t+2]]+byteToHex[e[t+3]]+"-"+byteToHex[e[t+4]]+byteToHex[e[t+5]]+"-"+byteToHex[e[t+6]]+byteToHex[e[t+7]]+"-"+byteToHex[e[t+8]]+byteToHex[e[t+9]]+"-"+byteToHex[e[t+10]]+byteToHex[e[t+11]]+byteToHex[e[t+12]]+byteToHex[e[t+13]]+byteToHex[e[t+14]]+byteToHex[e[t+15]]).toLowerCase();if(!(0,_validate$2.default)(n))throw TypeError("Stringified UUID is invalid");return n}var _default$a=stringify;stringify$1.default=_default$a,Object.defineProperty(v1$1,"__esModule",{value:!0}),v1$1.default=void 0;var _rng$1=_interopRequireDefault$8(rng$1),_stringify$2=_interopRequireDefault$8(stringify$1);function _interopRequireDefault$8(e){return e&&e.__esModule?e:{default:e}}let _nodeId,_clockseq,_lastMSecs=0,_lastNSecs=0;function v1(e,t,n){let r=t&&n||0;const i=t||new Array(16);let o=(e=e||{}).node||_nodeId,s=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==o||null==s){const t=e.random||(e.rng||_rng$1.default)();null==o&&(o=_nodeId=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==s&&(s=_clockseq=16383&(t[6]<<8|t[7]))}let a=void 0!==e.msecs?e.msecs:Date.now(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1;const l=a-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||a>_lastMSecs)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=a,_lastNSecs=c,_clockseq=s,a+=122192928e5;const d=(1e4*(268435455&a)+c)%4294967296;i[r++]=d>>>24&255,i[r++]=d>>>16&255,i[r++]=d>>>8&255,i[r++]=255&d;const p=a/4294967296*1e4&268435455;i[r++]=p>>>8&255,i[r++]=255&p,i[r++]=p>>>24&15|16,i[r++]=p>>>16&255,i[r++]=s>>>8|128,i[r++]=255&s;for(let e=0;e<6;++e)i[r+e]=o[e];return t||(0,_stringify$2.default)(i)}var _default$9=v1;v1$1.default=_default$9;var v3$1={},v35={},parse$1={};Object.defineProperty(parse$1,"__esModule",{value:!0}),parse$1.default=void 0;var _validate$1=_interopRequireDefault$7(validate$1);function _interopRequireDefault$7(e){return e&&e.__esModule?e:{default:e}}function parse(e){if(!(0,_validate$1.default)(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}var _default$8=parse;parse$1.default=_default$8,Object.defineProperty(v35,"__esModule",{value:!0}),v35.default=_default$7,v35.URL=v35.DNS=void 0;var _stringify$1=_interopRequireDefault$6(stringify$1),_parse=_interopRequireDefault$6(parse$1);function _interopRequireDefault$6(e){return e&&e.__esModule?e:{default:e}}function stringToBytes(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}const DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8";v35.DNS=DNS;const URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function _default$7(e,t,n){function r(e,r,i,o){if("string"==typeof e&&(e=stringToBytes(e)),"string"==typeof r&&(r=(0,_parse.default)(r)),16!==r.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let s=new Uint8Array(16+e.length);if(s.set(r),s.set(e,r.length),s=n(s),s[6]=15&s[6]|t,s[8]=63&s[8]|128,i){o=o||0;for(let e=0;e<16;++e)i[o+e]=s[e];return i}return(0,_stringify$1.default)(s)}try{r.name=e}catch(e){}return r.DNS=DNS,r.URL=URL,r}v35.URL=URL;var md5$1={};Object.defineProperty(md5$1,"__esModule",{value:!0}),md5$1.default=void 0;var _crypto$1=_interopRequireDefault$5(require$$0);function _interopRequireDefault$5(e){return e&&e.__esModule?e:{default:e}}function md5(e){return Array.isArray(e)?e=Buffer.from(e):"string"==typeof e&&(e=Buffer.from(e,"utf8")),_crypto$1.default.createHash("md5").update(e).digest()}var _default$6=md5;md5$1.default=_default$6,Object.defineProperty(v3$1,"__esModule",{value:!0}),v3$1.default=void 0;var _v$1=_interopRequireDefault$4(v35),_md=_interopRequireDefault$4(md5$1);function _interopRequireDefault$4(e){return e&&e.__esModule?e:{default:e}}const v3=(0,_v$1.default)("v3",48,_md.default);var _default$5=v3;v3$1.default=_default$5;var v4$1={};Object.defineProperty(v4$1,"__esModule",{value:!0}),v4$1.default=void 0;var _rng=_interopRequireDefault$3(rng$1),_stringify=_interopRequireDefault$3(stringify$1);function _interopRequireDefault$3(e){return e&&e.__esModule?e:{default:e}}function v4(e,t,n){const r=(e=e||{}).random||(e.rng||_rng.default)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return(0,_stringify.default)(r)}var _default$4=v4;v4$1.default=_default$4;var v5$1={},sha1$1={};Object.defineProperty(sha1$1,"__esModule",{value:!0}),sha1$1.default=void 0;var _crypto=_interopRequireDefault$2(require$$0);function _interopRequireDefault$2(e){return e&&e.__esModule?e:{default:e}}function sha1(e){return Array.isArray(e)?e=Buffer.from(e):"string"==typeof e&&(e=Buffer.from(e,"utf8")),_crypto.default.createHash("sha1").update(e).digest()}var _default$3=sha1;sha1$1.default=_default$3,Object.defineProperty(v5$1,"__esModule",{value:!0}),v5$1.default=void 0;var _v=_interopRequireDefault$1(v35),_sha=_interopRequireDefault$1(sha1$1);function _interopRequireDefault$1(e){return e&&e.__esModule?e:{default:e}}const v5=(0,_v.default)("v5",80,_sha.default);var _default$2=v5;v5$1.default=_default$2;var nil={};Object.defineProperty(nil,"__esModule",{value:!0}),nil.default=void 0;var _default$1="00000000-0000-0000-0000-000000000000";nil.default=_default$1;var version$1={};Object.defineProperty(version$1,"__esModule",{value:!0}),version$1.default=void 0;var _validate=_interopRequireDefault(validate$1);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function version(e){if(!(0,_validate.default)(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}var _default=version;version$1.default=_default,function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"v1",{enumerable:!0,get:function(){return t.default}}),Object.defineProperty(e,"v3",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"v4",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"v5",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(e,"NIL",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(e,"version",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(e,"validate",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return l.default}});var t=d(v1$1),n=d(v3$1),r=d(v4$1),i=d(v5$1),o=d(nil),s=d(version$1),a=d(validate$1),c=d(stringify$1),l=d(parse$1);function d(e){return e&&e.__esModule?e:{default:e}}}(dist);const createExecId=()=>`exec-${dist.v4()}`,createActionId=()=>`action-${dist.v4()}`,createEngineId=()=>`engine-${dist.v4()}`;class Scheduler extends EventEmitter{constructor(e){super(),this.nodeQueueMap=new Map,this.actionRunningMap=new Map,this.flowModel=e.flowModel,this.recorder=e.recorder}addAction(e){const{executionId:t}=e;this.nodeQueueMap.has(t)||this.nodeQueueMap.set(t,[]);const n=this.nodeQueueMap.get(t);n&&n.push(e)}pushActionToRunningMap(e){var t;const{executionId:n,actionId:r}=e;if(!this.actionRunningMap.has(n)){const e=new Map;this.actionRunningMap.set(n,e)}r&&(null===(t=this.actionRunningMap.get(n))||void 0===t||t.set(r,e))}removeActionFromRunningMap(e){const{executionId:t,actionId:n}=e;if(!n)return;const r=this.actionRunningMap.get(t);r&&r.delete(n)}saveActionResult(e){var t;null===(t=this.recorder)||void 0===t||t.addActionRecord(Object.assign({timestamp:Date.now()},e))}hasRunningAction(e){const t=this.actionRunningMap.get(e);return!!t&&(0!==t.size||(this.actionRunningMap.delete(e),!1))}run(e){const t=this.nodeQueueMap.get(e.executionId);for(;null==t?void 0:t.length;){const e=t.pop(),n=createActionId(),r=Object.assign(Object.assign({},e),{actionId:n});this.pushActionToRunningMap(r),this.exec(r)}this.hasRunningAction(e.executionId)||this.emit(EVENT_INSTANCE_COMPLETE,Object.assign(Object.assign({},e),{status:exports.FlowStatus.COMPLETED}))}next(e){e.outgoing&&e.outgoing.length>0&&e.outgoing.forEach((t=>{t.result&&this.addAction({executionId:e.executionId,nodeId:t.target})})),this.saveActionResult(e),this.removeActionFromRunningMap(e),this.run(e)}resume(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n,nodeId:r}=e;this.pushActionToRunningMap({executionId:t,actionId:n,nodeId:r});const i=this.flowModel.createAction(r);yield null==i?void 0:i.resume(Object.assign(Object.assign({},e),{next:this.next.bind(this)}))}))}interrupted(e){this.emit(EVENT_INSTANCE_INTERRUPTED,e)}error(e){this.emit(EVENT_INSTANCE_ERROR,e)}exec(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n,nodeId:r}=e,i=this.flowModel.createAction(r),o=yield null==i?void 0:i.execute({executionId:t,actionId:n,nodeId:r,next:this.next.bind(this)});if(o){const{nodeType:i,properties:s,outgoing:a,status:c,detail:l}=o,d={executionId:t,actionId:n,nodeId:r,nodeType:i,properties:s,outgoing:a,status:c,detail:l};(null==o?void 0:o.status)===exports.FlowStatus.INTERRUPTED&&(this.interrupted(o),this.saveActionResult(d),this.removeActionFromRunningMap(e)),(null==o?void 0:o.status)===exports.FlowStatus.ERROR&&(this.error(o),this.saveActionResult(d),this.removeActionFromRunningMap(e))}}))}}class FlowModel{constructor({nodeModelMap:e,recorder:t,context:n={},globalData:r={},startNodeType:i="StartNode"}){this.nodeConfigMap=new Map,this.startNodes=[],this.globalData={},this.nodeModelMap=e,this.executeList=[],this.executingInstance=null,this.context=n,this.globalData=r,this.startNodeType=i,this.isRunning=!1,this.scheduler=new Scheduler({flowModel:this,recorder:t}),this.scheduler.on(EVENT_INSTANCE_COMPLETE,(e=>{this.onExecuteFinished(e)})),this.scheduler.on(EVENT_INSTANCE_INTERRUPTED,(e=>{this.onExecuteFinished(e)})),this.scheduler.on(EVENT_INSTANCE_ERROR,(e=>{this.onExecuteFinished(e)}))}load(e){const{nodes:t=[],edges:n=[]}=e;t.forEach((e=>{if(this.nodeModelMap.has(e.type)){const t={id:e.id,type:e.type,properties:e.properties,incoming:[],outgoing:[]};this.nodeConfigMap.set(e.id,t),e.type===this.startNodeType&&this.startNodes.push(t)}})),n.forEach((e=>{const t=this.nodeConfigMap.get(e.sourceNodeId),n=this.nodeConfigMap.get(e.targetNodeId);t&&t.outgoing.push({id:e.id,properties:e.properties,target:e.targetNodeId}),n&&n.type!==this.startNodeType&&n.incoming.push({id:e.id,properties:e.properties,source:e.sourceNodeId})}))}createExecution(e){var t;if(this.executeList.push(e),e.actionId&&e.nodeId&&e.executionId)return void this.scheduler.resume({executionId:e.executionId,actionId:e.actionId,nodeId:e.nodeId,data:e.data});const n=createExecId();if(e.executionId=n,null==e?void 0:e.nodeId){const n=this.nodeConfigMap.get(e.nodeId);if(!n)return void(null===(t=null==e?void 0:e.onError)||void 0===t||t.call(e,new Error(`${getErrorMsg(exports.ErrorCode.NONE_NODE_ID)}(${e.nodeId})`)));this.startNodes=[n]}this.startNodes.forEach((e=>{this.scheduler.addAction({executionId:n,nodeId:e.id})})),this.scheduler.run({executionId:n})}execute(e){return __awaiter(this,void 0,void 0,(function*(){this.createExecution(e)}))}resume(e){return __awaiter(this,void 0,void 0,(function*(){this.createExecution(e)}))}createAction(e){const t=this.nodeConfigMap.get(e);if(t){const e=this.nodeModelMap.get(t.type);if(!e)throw new Error("该 NodeModel 不存在,抛出异常");return new e({nodeConfig:t,globalData:this.globalData,context:this.context})}}setStartNodeType(e){this.startNodeType=e}updateGlobalData(e){return this.globalData=Object.assign(Object.assign({},this.globalData),e),this.globalData}onExecuteFinished(e){const t=this.executeList.findIndex((t=>t.executionId===e.executionId));if(t>-1){const{callback:n}=this.executeList[t];this.executeList.splice(t,1),null==n||n(e)}}}const MAX_RECORDER=100,MAX_INSTANCE=100,LOGICFLOW_ENGINE_INSTANCES="LOGICFLOW_ENGINE_INSTANCES";class Recorder{constructor({instanceId:e}){this.instanceId=e,this.maxRecorder=MAX_RECORDER;const t=this.getItem(LOGICFLOW_ENGINE_INSTANCES)||[];if(-1===t.indexOf(e)&&t.push(e),t.length>MAX_INSTANCE){const e=t.shift();this.clearInstance(e)}this.setItem(LOGICFLOW_ENGINE_INSTANCES,t)}setMaxRecorderNumber(e){this.maxRecorder=e}setItem(e,t){try{storage.setItem(e,t)}catch(n){storage.clear(),storage.setItem(e,t)}}getItem(e){return storage.getItem(e)}getExecutionActions(e){return __awaiter(this,void 0,void 0,(function*(){return this.getItem(e)}))}getExecutionList(){return __awaiter(this,void 0,void 0,(function*(){return this.getItem(this.instanceId)||[]}))}addExecution(e){const t=this.getItem(this.instanceId)||[];if(t.length>=this.maxRecorder){const e=t.shift();this.popExecution(e)}t.push(e),this.setItem(this.instanceId,t)}popExecution(e){(this.getItem(e)||[]).forEach((e=>{storage.removeItem(e)})),storage.removeItem(e)}pushActionToExecution(e,t){const n=this.getItem(e)||[];n.push(t),this.setItem(e,n)}addActionRecord(e){return __awaiter(this,void 0,void 0,(function*(){const{executionId:t,actionId:n}=e;(yield this.getExecutionActions(t))||this.addExecution(t),this.pushActionToExecution(t,n),this.setItem(n,e)}))}getActionRecord(e){return __awaiter(this,void 0,void 0,(function*(){return this.getItem(e)}))}clear(){this.clearInstance(this.instanceId)}clearInstance(e){(this.getItem(e)||[]).forEach((e=>{storage.removeItem(e);(this.getItem(e)||[]).forEach((e=>{storage.removeItem(e)}))})),storage.removeItem(e)}}class Engine{constructor(e){this.nodeModelMap=new Map,this.instanceId=createEngineId(),(null==e?void 0:e.debug)&&(this.recorder=new Recorder({instanceId:this.instanceId})),this.register({type:StartNode.nodeTypeName,model:StartNode}),this.register({type:TaskNode.nodeTypeName,model:TaskNode}),this.context=(null==e?void 0:e.context)||{}}register(e){this.nodeModelMap.set(e.type,e.model)}setCustomRecorder(e){this.recorder=e}load({graphData:e,startNodeType:t="StartNode",globalData:n={}}){this.graphData=e;const r=new FlowModel({nodeModelMap:this.nodeModelMap,recorder:this.recorder,context:this.context,globalData:n,startNodeType:t});return r.load(e),this.flowModel=r,r}execute(e){return __awaiter(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var r;let i=e;e||(i={}),null===(r=this.flowModel)||void 0===r||r.execute(Object.assign(Object.assign({},i),{callback:e=>{t(e)},onError:e=>{n(e)}}))}))}))}resume(e){return __awaiter(this,void 0,void 0,(function*(){return new Promise(((t,n)=>{var r;null===(r=this.flowModel)||void 0===r||r.resume(Object.assign(Object.assign({},e),{callback:e=>{t(e)},onError:e=>{n(e)}}))}))}))}getExecutionList(){return __awaiter(this,void 0,void 0,(function*(){var e;return yield null===(e=this.recorder)||void 0===e?void 0:e.getExecutionList()}))}getExecutionRecord(e){return __awaiter(this,void 0,void 0,(function*(){var t,n;const r=yield null===(t=this.recorder)||void 0===t?void 0:t.getExecutionActions(e);if(!r)return null;const i=[];for(let e=0;e<(null==r?void 0:r.length);e++){const t=r[e];this.recorder&&i.push(null===(n=this.recorder)||void 0===n?void 0:n.getActionRecord(t))}return Promise.all(i)}))}destroy(){var e;null===(e=this.recorder)||void 0===e||e.clear()}getGlobalData(){var e;return null===(e=this.flowModel)||void 0===e?void 0:e.globalData}setGlobalData(e){this.flowModel&&(this.flowModel.globalData=e)}updateGlobalData(e){this.flowModel&&Object.assign(this.flowModel.globalData,e)}}exports.BASE_START_NODE=BASE_START_NODE,exports.BaseNode=BaseNode,exports.EVENT_INSTANCE_COMPLETE=EVENT_INSTANCE_COMPLETE,exports.EVENT_INSTANCE_ERROR=EVENT_INSTANCE_ERROR,exports.EVENT_INSTANCE_INTERRUPTED=EVENT_INSTANCE_INTERRUPTED,exports.Engine=Engine,exports.Recorder=Recorder,exports.StartNode=StartNode,exports.TaskNode=TaskNode,exports.default=Engine,exports.getErrorMsg=getErrorMsg,exports.getWarningMsg=getWarningMsg,Object.defineProperty(exports,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=index.min.js.map