presentationmaker_js/public/presentationmaker.js

1 line
25 KiB
JavaScript
Raw Permalink Normal View History

(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{PresentationMaker:()=>P});var i=Object.defineProperty,s=(t,e,s)=>(((t,e,s)=>{e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s);const r={PI:Math.PI,E:Math.E,LN2:Math.LN2,LN10:Math.LN10,LOG2E:Math.LOG2E,LOG10E:Math.LOG10E,SQRT1_2:Math.SQRT1_2,SQRT2:Math.SQRT2};class n{static createOperatorExpression(t,e,i){if("^"===t)return new c(e,i);if("*"===t||"/"===t)return new l(t,e,i);if("+"===t||"-"===t)return new h(t,e,i);throw new Error(`Unknown operator: ${t}`)}evaluate(t={}){throw new Error("Empty Expression - Must be defined in child classes")}toString(){return""}}class o extends n{constructor(t){if(super(),s(this,"innerExpression"),this.innerExpression=t,!(this.innerExpression instanceof n))throw new Error("No inner expression given for bracket expression")}evaluate(t={}){return this.innerExpression.evaluate(t)}toString(){return`(${this.innerExpression.toString()})`}}class a extends n{constructor(t){if(super(),s(this,"value"),this.value=Number(t),isNaN(this.value))throw new Error("Cannot parse number: "+t)}evaluate(){return this.value}toString(){return String(this.value)}}class h extends n{constructor(t,e,i){if(super(),s(this,"operator"),s(this,"left"),s(this,"right"),!["+","-"].includes(t))throw new Error(`Operator not allowed in Plus/Minus expression: ${t}`);this.operator=t,this.left=e,this.right=i}evaluate(t={}){if("+"===this.operator)return this.left.evaluate(t)+this.right.evaluate(t);if("-"===this.operator)return this.left.evaluate(t)-this.right.evaluate(t);throw new Error("Unknown operator for PlusMinus expression")}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class l extends n{constructor(t,e,i){if(super(),s(this,"operator"),s(this,"left"),s(this,"right"),!["*","/"].includes(t))throw new Error(`Operator not allowed in Multiply/Division expression: ${t}`);this.operator=t,this.left=e,this.right=i}evaluate(t={}){if("*"===this.operator)return this.left.evaluate(t)*this.right.evaluate(t);if("/"===this.operator)return this.left.evaluate(t)/this.right.evaluate(t);throw new Error("Unknown operator for MultDiv expression")}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class c extends n{constructor(t,e){super(),s(this,"base"),s(this,"exponent"),this.base=t,this.exponent=e}evaluate(t={}){return Math.pow(this.base.evaluate(t),this.exponent.evaluate(t))}toString(){return`${this.base.toString()}^${this.exponent.toString()}`}}class u extends n{constructor(t,e,i=null){super(),s(this,"fn"),s(this,"varPath"),s(this,"argumentExpressions"),s(this,"formulaObject"),s(this,"blacklisted"),this.fn=null!=t?t:"",this.varPath=this.fn.split("."),this.argumentExpressions=e||[],this.formulaObject=i,this.blacklisted=void 0}evaluate(t={}){var e;t=t||{};const i=this.argumentExpressions.map((e=>e.evaluate(t)));try{let e=p(t,this.varPath,this.fn);if(e instanceof Function)return e.apply(this,i)}catch(t){}let s;try{s=p(null!=(e=this.formulaObject)?e:{},this.varPath,this.fn)}catch(t){}if(this.formulaObject&&s instanceof Function){if(this.isBlacklisted())throw new Error("Blacklisted function called: "+this.fn);return s.apply(this.formulaObject,i)}try{const t=p(Math,this.varPath,this.fn);if(t instanceof Function)return t.apply(this,i)}catch(t){}throw new Error("Function not found: "+this.fn)}toString(){return`${this.fn}(${this.argumentExpressions.map((t=>t.toString())).join(", ")})`}isBlacklisted(){return void 0===this.blacklisted&&(this.blacklisted=m.functionBlacklist.includes(this.formulaObject?this.formulaObject[this.fn]:null)),this.blacklisted}}function p(t,e,i){let s=t;for(let t of e){if("object"!=typeof s)throw new Error(`Cannot evaluate ${t}, property not found