From dd7a468ef9d678ebb639dbdefc37f8533610bf81 Mon Sep 17 00:00:00 2001 From: Jazza-231 Date: Sat, 2 Mar 2024 16:40:15 +0800 Subject: [PATCH] ver and library (need help) --- addons/math-in-inputs/addon.json | 2 +- libraries/README.md | 1 + libraries/thirdparty/cs/eval-expr.min.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 libraries/thirdparty/cs/eval-expr.min.js diff --git a/addons/math-in-inputs/addon.json b/addons/math-in-inputs/addon.json index e341c91883..c76a5ee37f 100644 --- a/addons/math-in-inputs/addon.json +++ b/addons/math-in-inputs/addon.json @@ -2,7 +2,7 @@ "name": "Mathematical expressions in number inputs", "description": "Evaluates mathematical expressions (e.g. 2+4*3) in number inputs in the editor automatically.", "tags": ["editor", "codeEditor", "recommended"], - "versionAdded": "1.36.0", + "versionAdded": "1.37.0", "dynamicEnable": true, "dynamicDisable": true, "userscripts": [ diff --git a/libraries/README.md b/libraries/README.md index 0bd927e7cd..48a7e8061d 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -15,5 +15,6 @@ Third-party libraries included are: - [Fuse.js 6.6.2](https://unpkg.com/fuse.js@6.6.2/dist/fuse.esm.min.js) (Apache-2.0) - [idb 7.1.1](https://unpkg.com/idb@7.1.1/build/umd.js) (ISC) - [Sortable.js 1.15.0](https://unpkg.com/sortablejs@1.15.0/Sortable.min.js) (MIT) +- [expr-eval 2.0.2](https://unpkg.com/expr-eval@2.0.2/dist/bundle.min.js) (MIT) Note that these libraries are either from official release websites or from unpkg (which distributes the content uploaded to NPM as-is). diff --git a/libraries/thirdparty/cs/eval-expr.min.js b/libraries/thirdparty/cs/eval-expr.min.js new file mode 100644 index 0000000000..5b08515d5e --- /dev/null +++ b/libraries/thirdparty/cs/eval-expr.min.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).exprEval={})}(this,function(t){"use strict";var y="INUMBER",x="IOP1",w="IOP2",d="IOP3",g="IVAR",M="IVARNAME",E="IFUNCALL",m="IFUNDEF",A="IEXPR",b="IEXPREVAL",k="IMEMBER",O="IENDSTATEMENT",T="IARRAY";function C(t,e){this.type=t,this.value=null!=e?e:0}function c(t){return new C(x,t)}function f(t){return new C(w,t)}function l(t){return new C(d,t)}function N(t,i,o){var e,r,s,n,a,p,h=[];if(I(t))return P(t,o);for(var u=t.length,c=0;c=this.expression.length?this.newToken(n,"EOF"):this.isWhitespace()||this.isComment()?this.next():this.isRadixInteger()||this.isNumber()||this.isOperator()||this.isString()||this.isParen()||this.isBracket()||this.isComma()||this.isSemicolon()||this.isNamedOp()||this.isConst()||this.isName()?this.current:void this.parseError('Unknown character "'+this.expression.charAt(this.pos)+'"')},B.prototype.isString=function(){var t=!1,e=this.pos,r=this.expression.charAt(e);if("'"===r||'"'===r)for(var s=this.expression.indexOf(r,e+1);0<=s&&this.pos=this.expression.length));)e=this.expression.charAt(this.pos);return t};var V=/^[0-9a-f]{4}$/i;function _(t,e,r){this.parser=t,this.tokens=e,this.current=null,this.nextToken=null,this.next(),this.savedCurrent=null,this.savedNextToken=null,this.allowMemberAccess=!1!==r.allowMemberAccess}B.prototype.unescape=function(t){var e=t.indexOf("\\");if(e<0)return t;for(var r=t.substring(0,e);0<=e;){var s=t.charAt(++e);switch(s){case"'":r+="'";break;case'"':r+='"';break;case"\\":r+="\\";break;case"/":r+="/";break;case"b":r+="\b";break;case"f":r+="\f";break;case"n":r+="\n";break;case"r":r+="\r";break;case"t":r+="\t";break;case"u":var n=t.substring(e+1,e+5);V.test(n)||this.parseError("Illegal escape sequence: \\u"+n),r+=String.fromCharCode(parseInt(n,16)),e+=4;break;default:throw this.parseError('Illegal escape sequence: "\\'+s+'"')}++e;var i=t.indexOf("\\",e);r+=t.substring(e,i<0?t.length:i),e=i}return r},B.prototype.isComment=function(){return"/"===this.expression.charAt(this.pos)&&"*"===this.expression.charAt(this.pos+1)&&(this.pos=this.expression.indexOf("*/",this.pos)+2,1===this.pos&&(this.pos=this.expression.length),!0)},B.prototype.isRadixInteger=function(){var t,e,r=this.pos;if(r>=this.expression.length-2||"0"!==this.expression.charAt(r))return!1;if(++r,"x"===this.expression.charAt(r))t=16,e=/^[0-9a-f]$/i,++r;else{if("b"!==this.expression.charAt(r))return!1;t=2,e=/^[01]$/i,++r}for(var s=!1,n=r;r"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,">="),this.pos++):this.current=this.newToken(h,">");else if("<"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,"<="),this.pos++):this.current=this.newToken(h,"<");else if("|"===e){if("|"!==this.expression.charAt(this.pos+1))return!1;this.current=this.newToken(h,"||"),this.pos++}else if("="===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,"=="),this.pos++):this.current=this.newToken(h,e);else{if("!"!==e)return!1;"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,"!="),this.pos++):this.current=this.newToken(h,e)}return this.pos++,!!this.isOperatorEnabled(this.current.value)||(this.pos=t,!1)},B.prototype.isOperatorEnabled=function(t){return this.parser.isOperatorEnabled(t)},B.prototype.getCoordinates=function(){for(var t,e=0,r=-1;e++,t=this.pos-r,0<=(r=this.expression.indexOf("\n",r+1))&&r=",">","in"];_.prototype.parseComparison=function(t){for(this.parseAddSub(t);this.accept(h,r);){var e=this.current;this.parseAddSub(t),t.push(f(e.value))}};var $=["+","-","||"];_.prototype.parseAddSub=function(t){for(this.parseTerm(t);this.accept(h,$);){var e=this.current;this.parseTerm(t),t.push(f(e.value))}};var D=["*","/","%"];function e(t,e){return Number(t)+Number(e)}function G(t,e){return t-e}function J(t,e){return t*e}function W(t,e){return t/e}function X(t,e){return t%e}function Y(t,e){return Array.isArray(t)&&Array.isArray(e)?t.concat(e):""+t+e}function K(t,e){return t===e}function z(t,e){return t!==e}function H(t,e){return e":H,"<":Q,">=":Z,"<=":tt,and:et,or:rt,in:st,"=":At,"[":bt},this.ternaryOps={"?":Et},this.functions={random:vt,fac:yt,min:Ot,max:kt,hypot:Math.hypot||Mt,pyt:Math.hypot||Mt,pow:Math.pow,atan2:Math.atan2,if:Et,gamma:dt,roundTo:mt,map:Tt,fold:Ct,filter:Nt,indexOf:St,join:It},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}qt.prototype.parse=function(t){var e=[],r=new _(this,new B(this,t),{allowMemberAccess:this.options.allowMemberAccess});return r.parseExpression(e),r.expect(n,"EOF"),new s(e,this)},qt.prototype.evaluate=function(t,e){return this.parse(t).evaluate(e)};var Bt=new qt;qt.parse=function(t){return Bt.parse(t)},qt.evaluate=function(t,e){return Bt.parse(t).evaluate(e)};var Vt={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"remainder","^":"power","!":"factorial","<":"comparison",">":"comparison","<=":"comparison",">=":"comparison","==":"comparison","!=":"comparison","||":"concatenate",and:"logical",or:"logical",not:"logical","?":"conditional",":":"conditional","=":"assignment","[":"array","()=":"fndef"};qt.prototype.isOperatorEnabled=function(t){var e=function(t){return Vt.hasOwnProperty(t)?Vt[t]:t}(t),r=this.options.operators||{};return!(e in r&&!r[e])};var _t={Parser:qt,Expression:s};t.Expression=s,t.Parser=qt,t.default=_t,Object.defineProperty(t,"__esModule",{value:!0})}); \ No newline at end of file