@codraft/core
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Codraft=e():t.Codraft=e()}(window,(function(){return function(t){var e={};function n(a){if(e[a])return e[a].exports;var o=e[a]={i:a,l:!1,exports:{}};return t[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,a){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(a,o,function(e){return t[e]}.bind(null,o));return a},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/dist/",n(n.s=5)}([function(t,e,n){var a=n(1);a.prototype.formulaEval=function(){"use strict";for(var t,e,n,a=[],o=this.value,s=0;s<o.length;s++)1===o[s].type||3===o[s].type?a.push({value:3===o[s].type?o[s].show:o[s].value,type:1}):13===o[s].type?a.push({value:o[s].show,type:1}):0===o[s].type?a[a.length-1]={value:o[s].show+("-"!=o[s].show?"(":"")+a[a.length-1].value+("-"!=o[s].show?")":""),type:0}:7===o[s].type?a[a.length-1]={value:(1!=a[a.length-1].type?"(":"")+a[a.length-1].value+(1!=a[a.length-1].type?")":"")+o[s].show,type:7}:10===o[s].type?(t=a.pop(),e=a.pop(),"P"===o[s].show||"C"===o[s].show?a.push({value:"<sup>"+e.value+"</sup>"+o[s].show+"<sub>"+t.value+"</sub>",type:10}):a.push({value:(1!=e.type?"(":"")+e.value+(1!=e.type?")":"")+"<sup>"+t.value+"</sup>",type:1})):2===o[s].type||9===o[s].type?(t=a.pop(),e=a.pop(),a.push({value:(1!=e.type?"(":"")+e.value+(1!=e.type?")":"")+o[s].show+(1!=t.type?"(":"")+t.value+(1!=t.type?")":""),type:o[s].type})):12===o[s].type&&(t=a.pop(),e=a.pop(),n=a.pop(),a.push({value:o[s].show+"("+n.value+","+e.value+","+t.value+")",type:12}));return a[0].value},t.exports=a},function(t,e,n){var a=n(2);a.prototype.postfixEval=function(t){"use strict";(t=t||{}).PI=Math.PI,t.E=Math.E;for(var e,n,o,s=[],r=this.value,u=void 0!==t.n,i=0;i<r.length;i++)1===r[i].type?s.push({value:r[i].value,type:1}):3===r[i].type?s.push({value:t[r[i].value],type:1}):0===r[i].type||7===r[i].type?void 0===s[s.length-1].type?s[s.length-1].value.push(r[i]):s[s.length-1].value=r[i].value(s[s.length-1].value):8===r[i].type?(e=s.pop(),n=s.pop(),s.push({type:1,value:r[i].value(n.value,e.value)})):10===r[i].type?(e=s.pop(),void 0===(n=s.pop()).type?(n.value=n.concat(e),n.value.push(r[i]),s.push(n)):void 0===e.type?(e.unshift(n),e.push(r[i]),s.push(e)):s.push({type:1,value:r[i].value(n.value,e.value)})):2===r[i].type||9===r[i].type?(e=s.pop(),void 0===(n=s.pop()).type?((n=n.concat(e)).push(r[i]),s.push(n)):void 0===e.type?(e.unshift(n),e.push(r[i]),s.push(e)):s.push({type:1,value:r[i].value(n.value,e.value)})):12===r[i].type?(void 0!==(e=s.pop()).type&&(e=[e]),n=s.pop(),o=s.pop(),s.push({type:1,value:r[i].value(o.value,n.value,new a(e))})):13===r[i].type&&(u?s.push({value:t[r[i].value],type:3}):s.push([r[i]]));if(s.length>1)throw new a.Exception("Uncaught Syntax error");return s[0].value>1e15?"Infinity":parseFloat(s[0].value.toFixed(15))},a.eval=function(t,e,n){return void 0===e?this.lex(t).toPostfix().postfixEval():void 0===n?void 0!==e.length?this.lex(t,e).toPostfix().postfixEval():this.lex(t).toPostfix().postfixEval(e):this.lex(t,e).toPostfix().postfixEval(n)},t.exports=a},function(t,e,n){var a=n(3);a.prototype.toPostfix=function(){"use strict";for(var t,e,n,o,s,r=[],u=[{value:"(",type:4,pre:0}],i=this.value,h=1;h<i.length;h++)if(1===i[h].type||3===i[h].type||13===i[h].type)1===i[h].type&&(i[h].value=Number(i[h].value)),r.push(i[h]);else if(4===i[h].type)u.push(i[h]);else if(5===i[h].type)for(;4!==(e=u.pop()).type;)r.push(e);else if(11===i[h].type){for(;4!==(e=u.pop()).type;)r.push(e);u.push(e)}else{o=(t=i[h]).pre,n=(s=u[u.length-1]).pre;var p="Math.pow"==s.value&&"Math.pow"==t.value;if(o>n)u.push(t);else{for(;n>=o&&!p||p&&o<n;)e=u.pop(),s=u[u.length-1],r.push(e),n=s.pre,p="Math.pow"==t.value&&"Math.pow"==s.value;u.push(t)}}return new a(r)},t.exports=a},function(t,e,n){"use strict";var a=n(4);function o(t,e){for(var n=0;n<t.length;n++)t[n]+=e;return t}var s=["sin","cos","tan","pi","(",")","P","C"," ","asin","acos","atan","7","8","9","int","cosh","acosh","ln","^","root","4","5","6","/","!","tanh","atanh","Mod","1","2","3","*","sinh","asinh","e","log","0",".","+","-",",","Sigma","n","Pi","pow","&"],r=["sin","cos","tan","π","(",")","P","C"," ","asin","acos","atan","7","8","9","Int","cosh","acosh"," ln","^","root","4","5","6","÷","!","tanh","atanh"," Mod ","1","2","3","×","sinh","asinh","e"," log","0",".","+","-",",","Σ","n","Π","pow","&"],u=[a.math.sin,a.math.cos,a.math.tan,"PI","(",")",a.math.P,a.math.C," ".anchor,a.math.asin,a.math.acos,a.math.atan,"7","8","9",Math.floor,a.math.cosh,a.math.acosh,Math.log,Math.pow,Math.sqrt,"4","5","6",a.math.div,a.math.fact,a.math.tanh,a.math.atanh,a.math.mod,"1","2","3",a.math.mul,a.math.sinh,a.math.asinh,"E",a.math.log,"0",".",a.math.add,a.math.sub,",",a.math.sigma,"n",a.math.Pi,Math.pow,a.math.and],i={0:11,1:0,2:3,3:0,4:0,5:0,6:0,7:11,8:11,9:1,10:10,11:0,12:11,13:0,14:-1},h=[0,0,0,3,4,5,10,10,14,0,0,0,1,1,1,0,0,0,0,10,0,1,1,1,2,7,0,0,2,1,1,1,2,0,0,3,0,1,6,9,9,11,12,13,12,8,9],p={0:!0,1:!0,3:!0,4:!0,6:!0,8:!0,9:!0,12:!0,13:!0,14:!0},l={0:!0,1:!0,2:!0,3:!0,4:!0,5:!0,6:!0,7:!0,8:!0,9:!0,10:!0,11:!0,12:!0,13:!0},c={0:!0,3:!0,4:!0,8:!0,12:!0,13:!0},f={},v={0:!0,1:!0,3:!0,4:!0,6:!0,8:!0,12:!0,13:!0},d={1:!0},y=[[],["1","2","3","7","8","9","4","5","6","+","-","*","/","(",")","^","!","P","C","e","0",".",",","n"," ","&"],["pi","ln","Pi"],["sin","cos","tan","Del","int","Mod","log","pow"],["asin","acos","atan","cosh","root","tanh","sinh"],["acosh","atanh","asinh","Sigma"]];function m(t,e,n,a){for(var o=0;o<a;o++)if(t[n+o]!==e[o])return!1;return!0}a.addToken=function(t){for(var e=0;e<t.length;e++){var n=t[e].token.length,a=-1;y[n]=y[n]||[];for(var o=0;o<y[n].length;o++)if(t[e].token===y[n][o]){a=s.indexOf(y[n][o]);break}-1===a?(s.push(t[e].token),h.push(t[e].type),y.length<=t[e].token.length&&(y[t[e].token.length]=[]),y[t[e].token.length].push(t[e].token),u.push(t[e].value),r.push(t[e].show)):(s[a]=t[e].token,h[a]=t[e].type,u[a]=t[e].value,r[a]=t[e].show)}},a.lex=function(t,e){var n,g={value:a.math.changeSign,type:0,pre:21,show:"-"},w={value:")",show:")",type:5,pre:0},_={value:"(",type:4,pre:0,show:"("},x=[_],M=[],b=t,P=p,E=0,C=f,S="";void 0!==e&&a.addToken(e);var k={},D=function(t){for(var e,n,o,p=[],l=t.length,c=0;c<l;c++)if(!(c<l-1&&" "===t[c]&&" "===t[c+1])){for(e="",n=t.length-c>y.length-2?y.length-1:t.length-c;n>0;n--)if(void 0!==y[n])for(o=0;o<y[n].length;o++)m(t,y[n][o],c,n)&&(e=y[n][o],o=y[n].length,n=0);if(c+=e.length-1,""===e)throw new a.Exception("Can't understand after "+t.slice(c));var f=s.indexOf(e);p.push({index:f,token:e,type:h[f],eval:u[f],precedence:i[h[f]],show:r[f]})}return p}(b);for(n=0;n<D.length;n++){var O=D[n];if(14!==O.type){var j,I=O.token,R=O.type,N=O.eval,T=O.precedence,B=O.show,F=x[x.length-1];for(j=M.length;j--&&0===M[j];)if(-1!==[0,2,3,4,5,9,11,12,13].indexOf(R)){if(!0!==P[R])throw new a.Exception(I+" is not allowed after "+S);x.push(w),P=l,C=v,M.pop()}if(!0!==P[R])throw new a.Exception(I+" is not allowed after "+S);if(!0===C[R]&&(R=2,N=a.math.mul,B="×",T=3,n-=1),k={value:N,type:R,pre:T,show:B},0===R)P=p,C=f,o(M,2),x.push(k),4!==D[n+1].type&&(x.push(_),M.push(2));else if(1===R)1===F.type?(F.value+=N,o(M,1)):x.push(k),P=l,C=c;else if(2===R)P=p,C=f,o(M,2),x.push(k);else if(3===R)x.push(k),P=l,C=v;else if(4===R)o(M,1),E++,P=p,C=f,x.push(k);else if(5===R){if(!E)throw new a.Exception("Closing parenthesis are more than opening one, wait What!!!");E--,P=l,C=v,x.push(k),o(M,1)}else if(6===R){if(F.hasDec)throw new a.Exception("Two decimals are not allowed in one number");1!==F.type&&(F={value:0,type:1,pre:0},x.push(F)),P=d,o(M,1),C=f,F.value+=N,F.hasDec=!0}else 7===R&&(P=l,C=v,o(M,1),x.push(k));8===R?(P=p,C=f,o(M,4),x.push(k),4!==D[n+1].type&&(x.push(_),M.push(4))):9===R?(9===F.type?F.value===a.math.add?(F.value=N,F.show=B,o(M,1)):F.value===a.math.sub&&"-"===B&&(F.value=a.math.add,F.show="+",o(M,1)):5!==F.type&&7!==F.type&&1!==F.type&&3!==F.type&&13!==F.type?"-"===I&&(P=p,C=f,o(M,2).push(2),x.push(g),x.push(_)):(x.push(k),o(M,2)),P=p,C=f):10===R?(P=p,C=f,o(M,2),x.push(k)):11===R?(P=p,C=f,x.push(k)):12===R?(P=p,C=f,o(M,6),x.push(k),4!==D[n+1].type&&(x.push(_),M.push(6))):13===R&&(P=l,C=v,x.push(k)),o(M,-1),S=I}else if(n>0&&n<D.length-1&&1===D[n+1].type&&(1===D[n-1].type||6===D[n-1].type))throw new a.Exception("Unexpected Space")}for(j=M.length;j--;)x.push(w);if(!0!==P[5])throw new a.Exception("complete the expression");for(;E--;)x.push(w);return x.push(w),new a(x)},t.exports=a},function(t,e,n){"use strict";var a=function(t){this.value=t};a.math={isDegree:!0,acos:function(t){return a.math.isDegree?180/Math.PI*Math.acos(t):Math.acos(t)},add:function(t,e){return t+e},asin:function(t){return a.math.isDegree?180/Math.PI*Math.asin(t):Math.asin(t)},atan:function(t){return a.math.isDegree?180/Math.PI*Math.atan(t):Math.atan(t)},acosh:function(t){return Math.log(t+Math.sqrt(t*t-1))},asinh:function(t){return Math.log(t+Math.sqrt(t*t+1))},atanh:function(t){return Math.log((1+t)/(1-t))},C:function(t,e){var n=1,o=t-e,s=e;s<o&&(s=o,o=e);for(var r=s+1;r<=t;r++)n*=r;return n/a.math.fact(o)},changeSign:function(t){return-t},cos:function(t){return a.math.isDegree&&(t=a.math.toRadian(t)),Math.cos(t)},cosh:function(t){return(Math.pow(Math.E,t)+Math.pow(Math.E,-1*t))/2},div:function(t,e){return t/e},fact:function(t){if(t%1!=0)return"NaN";for(var e=1,n=2;n<=t;n++)e*=n;return e},inverse:function(t){return 1/t},log:function(t){return Math.log(t)/Math.log(10)},mod:function(t,e){return t%e},mul:function(t,e){return t*e},P:function(t,e){for(var n=1,a=Math.floor(t)-Math.floor(e)+1;a<=Math.floor(t);a++)n*=a;return n},Pi:function(t,e,n){for(var a=1,o=t;o<=e;o++)a*=Number(n.postfixEval({n:o}));return a},pow10x:function(t){for(var e=1;t--;)e*=10;return e},sigma:function(t,e,n){for(var a=0,o=t;o<=e;o++)a+=Number(n.postfixEval({n:o}));return a},sin:function(t){return a.math.isDegree&&(t=a.math.toRadian(t)),Math.sin(t)},sinh:function(t){return(Math.pow(Math.E,t)-Math.pow(Math.E,-1*t))/2},sub:function(t,e){return t-e},tan:function(t){return a.math.isDegree&&(t=a.math.toRadian(t)),Math.tan(t)},tanh:function(t){return a.sinha(t)/a.cosha(t)},toRadian:function(t){return t*Math.PI/180},and:function(t,e){return t&e}},a.Exception=function(t){this.message=t},t.exports=a},function(t,e,n){"use strict";n.r(e),n.d(e,"Runner",(function(){return s}));var a=n(0),o=n.n(a);class s{constructor(t,e,n,a,o=!1){this.__events=t,this.__conditions=e,this.__actions=n,this.__boxes=a.boxes,this.__usedCommands=a.used_commands,this.__isDebug=o,this.__commandHashMap=s.CreateHashMap([...this.__events,...this.__conditions,...this.__actions])}static CreateHashMap(t){const e=new Map;return t.forEach(t=>e.set(t.id,t)),e}static ParseVariables(t,e,n,a=!1){const o={};for(const r in t)o[r]=s.ParseVariable(t[r],e,n,a);return o}static ParseVariable(t,e,n,a=!1){const s=t.replace(/{{3}\s*(.*?)\s*}{3}/gim,(t,e)=>{let a=t;return e in n&&(a=n[e]),"string"!=typeof a&&(a=JSON.stringify(a)),a}).replace(/{{2}\s*(.*?)\s*}{2}/gim,(t,a)=>{let o=null;return a in e?o=e[a]:a in n&&(o=n[a]),"string"!=typeof o&&(o=JSON.stringify(o)),o});let r;try{r=o.a.eval(s)}catch(t){try{r=JSON.parse(s)}catch(t){r=s,a&&console.error(t)}}return r}static RunCommand(t,e,n,a=!1){return new Promise((o,r)=>{const u=s.ParseVariables(e,n.local,n.global,a);t.fn.call(u,n,o,r)})}static RunCommandAsync(t,e,n,a,o,r=!1){const u=s.ParseVariables(e,n.local,n.global,r);t.fn.call(u,n,a,o)}static FindBox(t,e){var n;return null!==(n=t.find(t=>t.id===e))&&void 0!==n?n:null}async __runCommand(t,e){var n;const{command_id:a,variables:o}=t,r=null!==(n=this.__commandHashMap.get(a))&&void 0!==n?n:null;if(null!==r)return await s.RunCommand(r,o,e,this.__isDebug);throw new Error(`The '${a}' command not exists.`)}__runCommandAsync(t,e,n,a){var o;const{command_id:r,variables:u}=t,i=null!==(o=this.__commandHashMap.get(r))&&void 0!==o?o:null;if(null===i)throw new Error(`The '${r}' command not exists.`);s.RunCommandAsync(i,u,e,n,a,this.__isDebug)}__runCommands(t,e){return new Promise(async(n,a)=>{let o=!1;for(const n of t){if(o)return;await new Promise((t,a)=>this.__runCommand(n,e).then(t).catch(a)).catch(()=>{o=!0,a()})}n()})}__recursiveBox(t,e){const n=t.next_box_ids.filter(t=>s.FindBox(this.__boxes,t)).map(t=>s.FindBox(this.__boxes,t));this.__runCommands(t.conditions,e).then(()=>this.__runCommands(t.actions,e)).then(()=>{n.forEach(t=>this.__recursiveBox(t,e))})}__attachEvent(){this.__boxes.forEach(t=>{t.events.forEach(e=>{this.__runCommandAsync(e,{event:null,local:{},global:globalThis},e=>this.__recursiveBox(t,e),t=>console.error(t))})})}init(){this.__attachEvent()}}}])})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Codraft=e():t.Codraft=e()}(window,(function(){return function(t){var e={};function n(a){if(e[a])return e[a].exports;var o=e[a]={i:a,l:!1,exports:{}};return t[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,a){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(a,o,function(e){return t[e]}.bind(null,o));return a},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/dist/",n(n.s=5)}([function(t,e,n){var a=n(1);a.prototype.formulaEval=function(){"use strict";for(var t,e,n,a=[],o=this.value,s=0;s<o.length;s++)1===o[s].type||3===o[s].type?a.push({value:3===o[s].type?o[s].show:o[s].value,type:1}):13===o[s].type?a.push({value:o[s].show,type:1}):0===o[s].type?a[a.length-1]={value:o[s].show+("-"!=o[s].show?"(":"")+a[a.length-1].value+("-"!=o[s].show?")":""),type:0}:7===o[s].type?a[a.length-1]={value:(1!=a[a.length-1].type?"(":"")+a[a.length-1].value+(1!=a[a.length-1].type?")":"")+o[s].show,type:7}:10===o[s].type?(t=a.pop(),e=a.pop(),"P"===o[s].show||"C"===o[s].show?a.push({value:"<sup>"+e.value+"</sup>"+o[s].show+"<sub>"+t.value+"</sub>",type:10}):a.push({value:(1!=e.type?"(":"")+e.value+(1!=e.type?")":"")+"<sup>"+t.value+"</sup>",type:1})):2===o[s].type||9===o[s].type?(t=a.pop(),e=a.pop(),a.push({value:(1!=e.type?"(":"")+e.value+(1!=e.type?")":"")+o[s].show+(1!=t.type?"(":"")+t.value+(1!=t.type?")":""),type:o[s].type})):12===o[s].type&&(t=a.pop(),e=a.pop(),n=a.pop(),a.push({value:o[s].show+"("+n.value+","+e.value+","+t.value+")",type:12}));return a[0].value},t.exports=a},function(t,e,n){var a=n(2);a.prototype.postfixEval=function(t){"use strict";(t=t||{}).PI=Math.PI,t.E=Math.E;for(var e,n,o,s=[],r=this.value,u=void 0!==t.n,i=0;i<r.length;i++)1===r[i].type?s.push({value:r[i].value,type:1}):3===r[i].type?s.push({value:t[r[i].value],type:1}):0===r[i].type||7===r[i].type?void 0===s[s.length-1].type?s[s.length-1].value.push(r[i]):s[s.length-1].value=r[i].value(s[s.length-1].value):8===r[i].type?(e=s.pop(),n=s.pop(),s.push({type:1,value:r[i].value(n.value,e.value)})):10===r[i].type?(e=s.pop(),void 0===(n=s.pop()).type?(n.value=n.concat(e),n.value.push(r[i]),s.push(n)):void 0===e.type?(e.unshift(n),e.push(r[i]),s.push(e)):s.push({type:1,value:r[i].value(n.value,e.value)})):2===r[i].type||9===r[i].type?(e=s.pop(),void 0===(n=s.pop()).type?((n=n.concat(e)).push(r[i]),s.push(n)):void 0===e.type?(e.unshift(n),e.push(r[i]),s.push(e)):s.push({type:1,value:r[i].value(n.value,e.value)})):12===r[i].type?(void 0!==(e=s.pop()).type&&(e=[e]),n=s.pop(),o=s.pop(),s.push({type:1,value:r[i].value(o.value,n.value,new a(e))})):13===r[i].type&&(u?s.push({value:t[r[i].value],type:3}):s.push([r[i]]));if(s.length>1)throw new a.Exception("Uncaught Syntax error");return s[0].value>1e15?"Infinity":parseFloat(s[0].value.toFixed(15))},a.eval=function(t,e,n){return void 0===e?this.lex(t).toPostfix().postfixEval():void 0===n?void 0!==e.length?this.lex(t,e).toPostfix().postfixEval():this.lex(t).toPostfix().postfixEval(e):this.lex(t,e).toPostfix().postfixEval(n)},t.exports=a},function(t,e,n){var a=n(3);a.prototype.toPostfix=function(){"use strict";for(var t,e,n,o,s,r=[],u=[{value:"(",type:4,pre:0}],i=this.value,h=1;h<i.length;h++)if(1===i[h].type||3===i[h].type||13===i[h].type)1===i[h].type&&(i[h].value=Number(i[h].value)),r.push(i[h]);else if(4===i[h].type)u.push(i[h]);else if(5===i[h].type)for(;4!==(e=u.pop()).type;)r.push(e);else if(11===i[h].type){for(;4!==(e=u.pop()).type;)r.push(e);u.push(e)}else{o=(t=i[h]).pre,n=(s=u[u.length-1]).pre;var p="Math.pow"==s.value&&"Math.pow"==t.value;if(o>n)u.push(t);else{for(;n>=o&&!p||p&&o<n;)e=u.pop(),s=u[u.length-1],r.push(e),n=s.pre,p="Math.pow"==t.value&&"Math.pow"==s.value;u.push(t)}}return new a(r)},t.exports=a},function(t,e,n){"use strict";var a=n(4);function o(t,e){for(var n=0;n<t.length;n++)t[n]+=e;return t}var s=["sin","cos","tan","pi","(",")","P","C"," ","asin","acos","atan","7","8","9","int","cosh","acosh","ln","^","root","4","5","6","/","!","tanh","atanh","Mod","1","2","3","*","sinh","asinh","e","log","0",".","+","-",",","Sigma","n","Pi","pow","&"],r=["sin","cos","tan","π","(",")","P","C"," ","asin","acos","atan","7","8","9","Int","cosh","acosh"," ln","^","root","4","5","6","÷","!","tanh","atanh"," Mod ","1","2","3","×","sinh","asinh","e"," log","0",".","+","-",",","Σ","n","Π","pow","&"],u=[a.math.sin,a.math.cos,a.math.tan,"PI","(",")",a.math.P,a.math.C," ".anchor,a.math.asin,a.math.acos,a.math.atan,"7","8","9",Math.floor,a.math.cosh,a.math.acosh,Math.log,Math.pow,Math.sqrt,"4","5","6",a.math.div,a.math.fact,a.math.tanh,a.math.atanh,a.math.mod,"1","2","3",a.math.mul,a.math.sinh,a.math.asinh,"E",a.math.log,"0",".",a.math.add,a.math.sub,",",a.math.sigma,"n",a.math.Pi,Math.pow,a.math.and],i={0:11,1:0,2:3,3:0,4:0,5:0,6:0,7:11,8:11,9:1,10:10,11:0,12:11,13:0,14:-1},h=[0,0,0,3,4,5,10,10,14,0,0,0,1,1,1,0,0,0,0,10,0,1,1,1,2,7,0,0,2,1,1,1,2,0,0,3,0,1,6,9,9,11,12,13,12,8,9],p={0:!0,1:!0,3:!0,4:!0,6:!0,8:!0,9:!0,12:!0,13:!0,14:!0},l={0:!0,1:!0,2:!0,3:!0,4:!0,5:!0,6:!0,7:!0,8:!0,9:!0,10:!0,11:!0,12:!0,13:!0},c={0:!0,3:!0,4:!0,8:!0,12:!0,13:!0},f={},v={0:!0,1:!0,3:!0,4:!0,6:!0,8:!0,12:!0,13:!0},d={1:!0},m=[[],["1","2","3","7","8","9","4","5","6","+","-","*","/","(",")","^","!","P","C","e","0",".",",","n"," ","&"],["pi","ln","Pi"],["sin","cos","tan","Del","int","Mod","log","pow"],["asin","acos","atan","cosh","root","tanh","sinh"],["acosh","atanh","asinh","Sigma"]];function y(t,e,n,a){for(var o=0;o<a;o++)if(t[n+o]!==e[o])return!1;return!0}a.addToken=function(t){for(var e=0;e<t.length;e++){var n=t[e].token.length,a=-1;m[n]=m[n]||[];for(var o=0;o<m[n].length;o++)if(t[e].token===m[n][o]){a=s.indexOf(m[n][o]);break}-1===a?(s.push(t[e].token),h.push(t[e].type),m.length<=t[e].token.length&&(m[t[e].token.length]=[]),m[t[e].token.length].push(t[e].token),u.push(t[e].value),r.push(t[e].show)):(s[a]=t[e].token,h[a]=t[e].type,u[a]=t[e].value,r[a]=t[e].show)}},a.lex=function(t,e){var n,g={value:a.math.changeSign,type:0,pre:21,show:"-"},w={value:")",show:")",type:5,pre:0},_={value:"(",type:4,pre:0,show:"("},x=[_],M=[],b=t,P=p,E=0,C=f,S="";void 0!==e&&a.addToken(e);var D={},k=function(t){for(var e,n,o,p=[],l=t.length,c=0;c<l;c++)if(!(c<l-1&&" "===t[c]&&" "===t[c+1])){for(e="",n=t.length-c>m.length-2?m.length-1:t.length-c;n>0;n--)if(void 0!==m[n])for(o=0;o<m[n].length;o++)y(t,m[n][o],c,n)&&(e=m[n][o],o=m[n].length,n=0);if(c+=e.length-1,""===e)throw new a.Exception("Can't understand after "+t.slice(c));var f=s.indexOf(e);p.push({index:f,token:e,type:h[f],eval:u[f],precedence:i[h[f]],show:r[f]})}return p}(b);for(n=0;n<k.length;n++){var O=k[n];if(14!==O.type){var j,I=O.token,R=O.type,N=O.eval,T=O.precedence,B=O.show,F=x[x.length-1];for(j=M.length;j--&&0===M[j];)if(-1!==[0,2,3,4,5,9,11,12,13].indexOf(R)){if(!0!==P[R])throw new a.Exception(I+" is not allowed after "+S);x.push(w),P=l,C=v,M.pop()}if(!0!==P[R])throw new a.Exception(I+" is not allowed after "+S);if(!0===C[R]&&(R=2,N=a.math.mul,B="×",T=3,n-=1),D={value:N,type:R,pre:T,show:B},0===R)P=p,C=f,o(M,2),x.push(D),4!==k[n+1].type&&(x.push(_),M.push(2));else if(1===R)1===F.type?(F.value+=N,o(M,1)):x.push(D),P=l,C=c;else if(2===R)P=p,C=f,o(M,2),x.push(D);else if(3===R)x.push(D),P=l,C=v;else if(4===R)o(M,1),E++,P=p,C=f,x.push(D);else if(5===R){if(!E)throw new a.Exception("Closing parenthesis are more than opening one, wait What!!!");E--,P=l,C=v,x.push(D),o(M,1)}else if(6===R){if(F.hasDec)throw new a.Exception("Two decimals are not allowed in one number");1!==F.type&&(F={value:0,type:1,pre:0},x.push(F)),P=d,o(M,1),C=f,F.value+=N,F.hasDec=!0}else 7===R&&(P=l,C=v,o(M,1),x.push(D));8===R?(P=p,C=f,o(M,4),x.push(D),4!==k[n+1].type&&(x.push(_),M.push(4))):9===R?(9===F.type?F.value===a.math.add?(F.value=N,F.show=B,o(M,1)):F.value===a.math.sub&&"-"===B&&(F.value=a.math.add,F.show="+",o(M,1)):5!==F.type&&7!==F.type&&1!==F.type&&3!==F.type&&13!==F.type?"-"===I&&(P=p,C=f,o(M,2).push(2),x.push(g),x.push(_)):(x.push(D),o(M,2)),P=p,C=f):10===R?(P=p,C=f,o(M,2),x.push(D)):11===R?(P=p,C=f,x.push(D)):12===R?(P=p,C=f,o(M,6),x.push(D),4!==k[n+1].type&&(x.push(_),M.push(6))):13===R&&(P=l,C=v,x.push(D)),o(M,-1),S=I}else if(n>0&&n<k.length-1&&1===k[n+1].type&&(1===k[n-1].type||6===k[n-1].type))throw new a.Exception("Unexpected Space")}for(j=M.length;j--;)x.push(w);if(!0!==P[5])throw new a.Exception("complete the expression");for(;E--;)x.push(w);return x.push(w),new a(x)},t.exports=a},function(t,e,n){"use strict";var a=function(t){this.value=t};a.math={isDegree:!0,acos:function(t){return a.math.isDegree?180/Math.PI*Math.acos(t):Math.acos(t)},add:function(t,e){return t+e},asin:function(t){return a.math.isDegree?180/Math.PI*Math.asin(t):Math.asin(t)},atan:function(t){return a.math.isDegree?180/Math.PI*Math.atan(t):Math.atan(t)},acosh:function(t){return Math.log(t+Math.sqrt(t*t-1))},asinh:function(t){return Math.log(t+Math.sqrt(t*t+1))},atanh:function(t){return Math.log((1+t)/(1-t))},C:function(t,e){var n=1,o=t-e,s=e;s<o&&(s=o,o=e);for(var r=s+1;r<=t;r++)n*=r;return n/a.math.fact(o)},changeSign:function(t){return-t},cos:function(t){return a.math.isDegree&&(t=a.math.toRadian(t)),Math.cos(t)},cosh:function(t){return(Math.pow(Math.E,t)+Math.pow(Math.E,-1*t))/2},div:function(t,e){return t/e},fact:function(t){if(t%1!=0)return"NaN";for(var e=1,n=2;n<=t;n++)e*=n;return e},inverse:function(t){return 1/t},log:function(t){return Math.log(t)/Math.log(10)},mod:function(t,e){return t%e},mul:function(t,e){return t*e},P:function(t,e){for(var n=1,a=Math.floor(t)-Math.floor(e)+1;a<=Math.floor(t);a++)n*=a;return n},Pi:function(t,e,n){for(var a=1,o=t;o<=e;o++)a*=Number(n.postfixEval({n:o}));return a},pow10x:function(t){for(var e=1;t--;)e*=10;return e},sigma:function(t,e,n){for(var a=0,o=t;o<=e;o++)a+=Number(n.postfixEval({n:o}));return a},sin:function(t){return a.math.isDegree&&(t=a.math.toRadian(t)),Math.sin(t)},sinh:function(t){return(Math.pow(Math.E,t)-Math.pow(Math.E,-1*t))/2},sub:function(t,e){return t-e},tan:function(t){return a.math.isDegree&&(t=a.math.toRadian(t)),Math.tan(t)},tanh:function(t){return a.sinha(t)/a.cosha(t)},toRadian:function(t){return t*Math.PI/180},and:function(t,e){return t&e}},a.Exception=function(t){this.message=t},t.exports=a},function(t,e,n){"use strict";n.r(e),n.d(e,"Runner",(function(){return s}));var a=n(0),o=n.n(a);class s{constructor(t,e,n,a,o=!1){this.__events=t,this.__conditions=e,this.__actions=n,this.__boxes=a.boxes,this.__usedCommands=a.used_commands,this.__isDebug=o,this.__commandHashMap=s.CreateHashMap([...this.__events,...this.__conditions,...this.__actions])}static CreateHashMap(t){const e=new Map;return t.forEach(t=>e.set(t.id,t)),e}static ParseVariables(t,e,n,a=!1){const o={};for(const r in t)o[r]=s.ParseVariable(t[r],e,n,a);return o}static ParseVariable(t,e,n,a=!1){const s=t.replace(/{{3}\s*(.*?)\s*}{3}/gim,(t,e)=>{let a=t;return e in n&&(a=n[e]),"string"!=typeof a&&(a=JSON.stringify(a)),a}).replace(/{{2}\s*(.*?)\s*}{2}/gim,(t,a)=>{let o=null;return a in e?o=e[a]:a in n&&(o=n[a]),"string"!=typeof o&&(o=JSON.stringify(o)),o});let r;try{r=o.a.eval(s)}catch(t){try{r=JSON.parse(s)}catch(t){r=s}}return r}static RunCommand(t,e,n,a=!1){return new Promise((o,r)=>{const u=s.ParseVariables(e,n.local,n.global,a);t.fn.call(u,n,o,r)})}static RunCommandAsync(t,e,n,a,o,r=!1){const u=s.ParseVariables(e,n.local,n.global,r);t.fn.call(u,n,a,o)}static FindBox(t,e){var n;return null!==(n=t.find(t=>t.id===e))&&void 0!==n?n:null}async __runCommand(t,e){var n;const{command_id:a,variables:o}=t,r=null!==(n=this.__commandHashMap.get(a))&&void 0!==n?n:null;if(null!==r)return await s.RunCommand(r,o,e,this.__isDebug);throw new Error(`The '${a}' command not exists.`)}__runCommandAsync(t,e,n,a){var o;const{command_id:r,variables:u}=t,i=null!==(o=this.__commandHashMap.get(r))&&void 0!==o?o:null;if(null===i)throw new Error(`The '${r}' command not exists.`);s.RunCommandAsync(i,u,e,n,a,this.__isDebug)}__runCommands(t,e){return new Promise(async(n,a)=>{let o=!1;for(const n of t){if(o)return;await new Promise((t,a)=>this.__runCommand(n,e).then(t).catch(a)).catch(t=>{o=!0;a({format:n,data:e,reason:t})})}n()}).catch(t=>{this.__isDebug&&console.error(t)})}__recursiveBox(t,e){const n=t.next_box_ids.filter(t=>s.FindBox(this.__boxes,t)).map(t=>s.FindBox(this.__boxes,t));this.__runCommands(t.conditions,e).then(()=>this.__runCommands(t.actions,e)).then(()=>{n.forEach(t=>this.__recursiveBox(t,e))})}__attachEvent(){this.__boxes.forEach(t=>{t.events.forEach(e=>{this.__runCommandAsync(e,{event:null,local:{},global:globalThis},e=>this.__recursiveBox(t,e),t=>console.error(t))})})}init(){this.__attachEvent()}}}])})); |
{ | ||
"name": "@codraft/core", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Codraft parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/core/src/index.js", |
18148