UNPKG

equation-editor-cah

Version:

Provides a modal dialog for editing math functions.

1 lines 31.7 kB
class EquationEditorDlg{constructor(idOfTriggerElement){this.dlg=jQuery('<div class="modal fade" role="dialog"> <div id=editor-modal-dialog-div'+idOfTriggerElement+' class="modal-dialog modal-sm"> <div class="modal-content"> <div class="modal-header" style="padding:5px 20px;"> <button id="equationEditorCloseButton" type="button" class="close btn-close" data-dismiss="modal" data-bs-dismiss="modal">&times;</button> <div style="margin-left:-9px; margin-top:6px"> <button id=degRad'+idOfTriggerElement+'>Deg</button> <label class="modal-title" style="position:absolute; left: 20%; right:20%; text-align:center; font-size: 18px;"> Equation editor</label> </div> </div> <div class="modal-body" style="padding:10px 20px;"> <div class="row" style="padding-left:6px; padding-right:6px;"> <div class="col"> <div id="editor-screen-col" class="editor-screen" style="width:100%"></div> <div class="editor-screen_operator" style="position:absolute; left:95%; top:2px; width:10%; height:50%"></div><div style="position:absolute; top:35px; left:95%; height:20px" class="editor-screen_operator_bracket"></div> </div> </div> <div class="row"> <div class="col"> <div class="editor-keys"> <button id="open_curly" type="button" class="operator equation_editor_button" value="{">{</button> <button id="close_curly" type="button" class="operator equation_editor_button" value="}">}</button> <button id="less_than" type="button" class="operator equation_editor_button" value="<"><</button> <button id="f" type="button" class="operator equation_editor_button" value="f">f</button> <button id="x" type="button" class="operator equation_editor_button" value="x">x</button> <button id="y" type="button" class="operator equation_editor_button" value="y">y</button> <button type="button" class="operator equation_editor_button" value="hyp">hyp</button> <button type="button" class="operator equation_editor_button" value="2nd"><img id="secondFunctionImg" class="editor_image_no_select"></button> <button type="button" class="operator equation_editor_button" value="pi"><img id="piImg" class="editor_image_no_select"></button> <button type="button" class="operator equation_editor_button" value="e">e</button> <button id="clear" type="button" class="operator equation_editor_button" value="C">C</button> <button type="button" class="operator equation_editor_button" value="backSpace"><img id="backSpaceImg" class="editor_image_no_select"></button> <button id="sin" type="button" class="operator equation_editor_button" value="sin">sin</button> <button type="button" class="operator equation_editor_button" value="^2"><img id="xSquareImg" class="editor_image_no_select"></button> <button type="button" class="operator equation_editor_button" value="1/x">1/x</button> <button type="button" class="operator equation_editor_button" value="=">=</button> <button type="button" class="operator equation_editor_button" value="abs">|x|</button> <button type="button" class="operator equation_editor_button" value="+/-">+/-</button> <button id="cos" type="button" class="operator equation_editor_button" value="cos">cos</button> <button type="button" class="operator equation_editor_button" value="sqrt"><img id="squareRootImg" class="editor_image_no_select"></button> <button type="button" class="operator equation_editor_button" value="+">+</button> <button type="button" class="operator equation_editor_button" value="-">-</button> <button type="button" class="operator equation_editor_button" value="*">&times;</button> <button type="button" class="operator equation_editor_button" value="/">&divide;</button> <button id="tan" type="button" class="operator equation_editor_button" value="tan">tan</button> <button type="button" class="operator equation_editor_button" value="^"><img id="xToPowYImg" class="editor_image_no_select"></button> <button type="button" class="numberButton" value="7">7</button> <button type="button" class="numberButton" value="8">8</button> <button type="button" class="numberButton" value="9">9</button> <button type="button" class="operator equation_editor_button" value="(">(</button> <button id="sec" type="button" class="operator equation_editor_button" value="sec">sec</button> <button type="button" class="operator equation_editor_button" value="10^"><img id="tenToPowXImg" class="editor_image_no_select"></button> <button type="button" class="numberButton" value="4">4</button> <button type="button" class="numberButton" value="5">5</button> <button type="button" class="numberButton" value="6">6</button> <button type="button" class="operator equation_editor_button" value=")">)</button> <button id="csc" type="button" class="operator equation_editor_button" value="csc">csc</button> <button type="button" class="operator equation_editor_button" value="log10">log</button> <button type="button" class="numberButton" value="1">1</button> <button type="button" class="numberButton" value="2">2</button> <button type="button" class="numberButton" value="3">3</button> <button id="cot" type="button" class="operator equation_editor_button" value="cot">cot</button> <button type="button" class="operator equation_editor_button" value="log">ln</button> <button type="button" class="numberButton" value="0">0</button> <button type="button" style="font-weight:bold" class="decimal numberButton" value=".">.</button> <button type="button" class="all-clear" value="all-clear">AC</button> <button id="equationEditorEnter" type="button" class="enter_button operator equation_editor_button" value="enter"><img id="enterImg" class="editor_image_no_select" class="editor_image_no_select"></button> </div> </div> </div> </div> </div> </div></div>')}}class Replacement{static config={angles:"deg"};static originalFunctionMap={};static restore(){if(void 0!==Replacement.originalFunctionMap.sin){let replacements={};const fns1=["sin","cos","tan","sec","cot","csc"];fns1.forEach((function(name){const fnNumber=Replacement.originalFunctionMap[name];replacements[name]=math.typed(name,{number:fnNumber,"Array | Matrix":function(x){return math.map(x,fnNumber)}})}));const fns2=["asin","acos","atan","atan2","acot","acsc","asec"];fns2.forEach((function(name){const fnNumber=Replacement.originalFunctionMap[name];replacements[name]=math.typed(name,{number:fnNumber,"Array | Matrix":function(x){return math.map(x,fnNumber)}})})),math.import(replacements,{override:!0}),Replacement.originalFunctionMap={}}}static replace(){if(void 0===Replacement.originalFunctionMap.sin){let replacements={};const fns1=["sin","cos","tan","sec","cot","csc"];fns1.forEach((function(name){const fn=math[name];Replacement.originalFunctionMap[name]=fn;const fnNumber=function(x){switch(Replacement.config.angles){case"deg":return fn(x/360*2*Math.PI);case"grad":return fn(x/400*2*Math.PI);default:return fn(x)}};replacements[name]=math.typed(name,{number:fnNumber,"Array | Matrix":function(x){return math.map(x,fnNumber)}})}));const fns2=["asin","acos","atan","atan2","acot","acsc","asec"];fns2.forEach((function(name){const fn=math[name];Replacement.originalFunctionMap[name]=fn;const fnNumber=function(x){const result=fn(x);if("number"==typeof result)switch(Replacement.config.angles){case"deg":return result/2/Math.PI*360;case"grad":return result/2/Math.PI*400;default:return result}return result};replacements[name]=math.typed(name,{number:fnNumber,"Array | Matrix":function(x){return math.map(x,fnNumber)}})})),math.import(replacements,{override:!0})}}}class EquationEditor{constructor(idOfTriggerElement,options){const self=this,parser=new AsciiMathParser,dlg=new EquationEditorDlg(idOfTriggerElement).dlg,config_angles="deg";let bracket=0,displayOperator,editorScreenOperatorBracket;const hideAlphas=!(!options||null==options.hideAlphas)&&options.hideAlphas,parenthesis=options&&null!=options.parenthesis?options.parenthesis:"auto",implicit=options&&null!=options.implicit?options.implicit:"hide",title=options&&null!=options.title?options.title:"Equation editor",screenColor=options&&null!=options.screenColor?options.screenColor:"#252525",screenTextColor=options&&null!=options.screenTextColor?options.screenTextColor:"#fff",operatorButtonTextColor=options&&null!=options.operatorButtonTextColor?options.operatorButtonTextColor:"#337cac",prettyOnly=!(!options||null==options.prettyOnly)&&options.prettyOnly,validOnly=!(!options||null==options.validOnly)&&options.validOnly,initializeWithLastValue=!(!options||null==options.initializeWithLastValue)&&options.initializeWithLastValue,singleCharacterSymbol=!options||null==options.singleCharacterSymbol||options.singleCharacterSymbol,extendTrigFunctions=!options||null==options.extendTrigFunctions||options.extendTrigFunctions,bigDialog=!(!options||null==options.bigDialog)&&options.bigDialog,simplifyOutput=!(!options||null==options.simplifyOutput)&&options.simplifyOutput,endPoint="https://unpkg.com/equation-editor-cah/",defaultButtonImages={secondFunctionImg:endPoint+"img/secondFunction.png",piImg:endPoint+"img/Pi-symbol.png",backSpaceImg:endPoint+"img/backSpace.png",xSquareImg:endPoint+"img/xSquare.png",squareRootImg:endPoint+"img/squareRoot.png",xToPowYImg:endPoint+"img/xToPowY.png",tenToPowXImg:endPoint+"img/tenToPowX.png",enterImg:endPoint+"img/enter.png"};let buttonImages=defaultButtonImages,open_curly,close_curly,less_than,f,x,y;options&&options.buttonImages&&(options.buttonImages.secondFunctionImg&&(buttonImages.secondFunctionImg=options.buttonImages.secondFunctionImg),options.buttonImages.piImg&&(buttonImages.piImg=options.buttonImages.piImg),options.buttonImages.backSpaceImg&&(buttonImages.backSpaceImg=options.buttonImages.backSpaceImg),options.buttonImages.xSquareImg&&(buttonImages.xSquareImg=options.buttonImages.xSquareImg),options.buttonImages.squareRootImg&&(buttonImages.squareRootImg=options.buttonImages.squareRootImg),options.buttonImages.xToPowYImg&&(buttonImages.xToPowYImg=options.buttonImages.xToPowYImg),options.buttonImages.tenToPowXImg&&(buttonImages.tenToPowXImg=options.buttonImages.tenToPowXImg),options.buttonImages.enterImg&&(buttonImages.enterImg=options.buttonImages.enterImg));let firstTrigger=!0;function disableEnterButton(disable){jQuery("#equationEditorEnter").attr("title",disable?"Button disabled because entry is not a valid function":""),disable?(jQuery("#equationEditorEnter").addClass("enter_button_disabled"),jQuery("#equationEditorEnter").attr("title","Button disabled because entry is not a valid function")):(jQuery("#equationEditorEnter").removeClass("enter_button_disabled"),jQuery("#equationEditorEnter").attr("title","")),jQuery("#equationEditorEnter").attr("disabled",disable)}if(extendTrigFunctions&&Replacement.replace(),idOfTriggerElement){let trigger;jQuery("#"+idOfTriggerElement).attr("data-toggle","modal"),jQuery("#"+idOfTriggerElement).on("click",(function(){if(extendTrigFunctions?Replacement.replace():(Replacement.restore(),options.degreeRadianMode="radian"),jQuery("body").append(dlg),displayOperator=jQuery(document.querySelector(".editor-screen_operator")),editorScreenOperatorBracket=jQuery(document.querySelector(".editor-screen_operator_bracket")),options&&void 0!==options.degreeRadianMode?(jQuery("#degRad"+idOfTriggerElement).hide(),Replacement.config.angles=options.degreeRadianMode.substring(0,3).toLowerCase(),"gra"===Replacement.config.angles&&(Replacement.config.angles+="d")):Replacement.config.angles=jQuery("#degRad"+idOfTriggerElement).text().toLowerCase(),open_curly=document.getElementById("open_curly"),close_curly=document.getElementById("close_curly"),less_than=document.getElementById("less_than"),f=document.getElementById("f"),x=document.getElementById("x"),y=document.getElementById("y"),firstTrigger){dlg.modal||console.warn("Did not find the Bootstrap dependency. Make sure that the CDN https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js or alternative is properly included."),window.MathJax||console.warn("Did not find the MathJax dependency. Make sure that the CDN https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js or alternative is properly included."),window.math||console.warn("Did not find the MathJs dependency. Make sure that the CDN https://unpkg.com/mathjs@10.0.0/lib/browser/math.js or alternative is properly included.");const imgIds=["secondFunctionImg","piImg","backSpaceImg","xSquareImg","squareRootImg","xToPowYImg","tenToPowXImg","enterImg"];for(let i=0;i<imgIds.length;i++){const src=buttonImages[imgIds[i]];src.includes(".")?document.getElementById(imgIds[i]).src=src:document.getElementById(imgIds[i]).parentElement.innerText=src}let m_version=parseInt(jQuery.fn.tooltip.Constructor.VERSION),m_version_css=0,links=jQuery("head").find("link");for(let i=0;i<links.length;i++)if(links[i].href.includes("bootstrap.min.css")||links[i].href.includes("bootstrap.css"))for(let n=0;n<links[i].href.length;n++){let version=parseInt(links[i].href[n]);if("number"==typeof version&&Number.isInteger(version)&&"."==links[i].href[n+1]){m_version_css=version;break}}if(m_version||console.warn("Did not find the Bootstrap dependency. Make sure that the CDN https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.js or alternative is properly included."),m_version_css||console.warn("Did not find the Bootstrap dependency. Make sure that the CDN https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css or alternative is properly included."),m_version_css>0&&m_version>0&&m_version_css!==m_version&&console.warn(`Bootstrap css and js has major vesions ${m_version_css} and ${m_version} respectively.`),m_version>=4){let buttonKeys=document.getElementsByClassName("equation_editor_button");for(let i=0;i<buttonKeys.length;i++)buttonKeys[i].style.fontSize="1rem";document.getElementsByClassName("modal-body")[0].style.padding="10px 5px";let header=document.getElementsByClassName("modal-header")[0],children=header.children;m_version>4&&(children[0].innerHTML=""),jQuery(children[1]).remove();const elem=jQuery('<h5 class="modal-title" />');header.insertBefore(elem[0],children[0]),elem.css("fontWeight","normal"),document.getElementById("editor-screen-col").style.fontSize="1.1rem",document.getElementsByClassName("editor-screen_operator")[0].style.fontSize="1.1rem",4==m_version&&(document.getElementsByClassName("editor-screen_operator")[0].style.top="-6px"),document.getElementsByClassName("editor-screen_operator_bracket")[0].style.fontSize="0.6rem",4==m_version&&(document.getElementsByClassName("editor-screen_operator_bracket")[0].style.top="24px")}if("#337cac"!==operatorButtonTextColor){let buttonKeys=document.getElementsByClassName("equation_editor_button");for(let i=0;i<buttonKeys.length;i++)buttonKeys[i].style.color=operatorButtonTextColor}bigDialog&&(jQuery("#editor-modal-dialog-div"+idOfTriggerElement).removeClass("modal-sm"),jQuery("#editor-modal-dialog-div"+idOfTriggerElement).addClass("modal-md")),displayOperator.hide(),editorScreenOperatorBracket.hide(),firstTrigger=!1,hideAlphas&&doHideAlphas(),document.getElementsByClassName("modal-title")[0].innerHTML=title;const display=jQuery(document.querySelector(".editor-screen"));display.css("background-color",screenColor),display.css("color",screenTextColor),validOnly&&disableEnterButton(!0),jQuery("#degRad"+idOfTriggerElement).on("click",(function(){const txt=jQuery(this).text();"Deg"===txt&&(jQuery(this).text("Rad"),Replacement.config.angles="rad"),"Rad"===txt&&(jQuery(this).text("Grad"),Replacement.config.angles="grad"),"Grad"===txt&&(jQuery(this).text("Deg"),Replacement.config.angles="deg"),jQuery(window).trigger("equationEditorAngleModeChanged",Replacement.config.angles)})),function(){const keys=document.querySelector(".editor-keys");keys.addEventListener("click",event=>{const{target:target}=event;let{value:value}=target;if(target.matches("button")){switch(value){case"{":case"}":case"<":case"f":case"x":case"y":case"g":case"h":case"a":case"b":case"c":case",":case"=":case"abs":case"e":case"pi":case"+":case"-":case"*":case"/":case"(":case")":case"^2":case"10^":case"sqrt":case"log":case"log10":handleOperator(value);break;case"sin":case"cos":case"tan":case"sec":case"csc":case"cot":handleOperator(value);break;case"asin":case"acos":case"atan":case"asec":case"acsc":case"acot":handleOperator(value);break;case"sinh":case"cosh":case"tanh":case"sech":case"csch":case"coth":case"asinh":case"acosh":case"atanh":case"asech":case"acsch":case"acoth":handleOperator(value,!1);break;case"^":if(!editor.displayValue.length)return;handleOperator(value);break;case".":inputDecimal(value);break;case"C":case"all-clear":editor.resetEditor=!0,resetEditor();break;case"+/-":negate();break;case"1/x":reciprocal();break;case"backSpace":backSpace();break;case"enter":return void enter();case"CE":if(!removeLastOperand())return clear.value="C",void(clear.innerText="C");break;case"2nd":toggle2nd();break;case"hyp":toggleHyp();break;default:Number.isInteger(parseFloat(value))&&inputDigit(value)}updateDisplay()}})}()}resetEditor(),dlg.modal("show")}))}dlg.on("hidden.bs.modal",(function(){resetEditor(),dlg.detach()}));const editor={displayValue:"",resetEditor:!1,lastOperandRemove:!1,secondFunction:!1,hypFunction:!1,operator:null,backSpaced:!1,charRemoveByBackspace:""},keywords=["unaryMinus","sqrt","asinh","acosh","atanh","acoth","asech","acsch","asin","acos","atan","acot","asec","acsc","sinh","cosh","tanh","coth","sech","csch","sin","cos","tan","sec","csc","cot","ln","log","log2","log3","log4","log5","log6","log7","log8","log9","log10","deg","pi","PI","e","E","abs"];function containsKeyword(str){for(var i=0;i<keywords.length;i++)if(-1!=str.indexOf(keywords[i]))return keywords[i];return null}function inputDigit(digit){editor.displayValue.length&&isAlpha(editor.displayValue[editor.displayValue.length-1])&&(editor.displayValue+="*"),editor.displayValue+=digit,editor.operator=null}function inputDecimal(dot){editor.displayValue.length&&isAlpha(editor.displayValue[editor.displayValue.length-1])&&(editor.displayValue+="*"),getLastOperand().length?getLastOperand().includes(dot)||(editor.displayValue+=dot):editor.displayValue+="0."}function isAlpha(ch){return/^[A-Z]$/i.test(ch)}function isNumber(value){let val;return"number"==typeof parseFloat(value)&&isFinite(value)}let keywordsPurged=[];function purgeKeywords(){keywordsPurged=[];let index=-1;keywords.forEach((function(keyword){for(index=editor.displayValue.indexOf(keyword);-1!=index;)editor.displayValue=editor.displayValue.replace(keyword,`~${index}~`),keywordsPurged.push({keyword:keyword,id:`~${index}~`}),index=editor.displayValue.indexOf(keyword)}))}function replaceKeywords(){for(let i=0;i<keywordsPurged.length;i++)editor.displayValue=editor.displayValue.replace(keywordsPurged[i].id,keywordsPurged[i].keyword)}function insertProductSymbol(){if(singleCharacterSymbol){if(editor.displayValue.length<2||"*"===editor.displayValue[editor.displayValue.length-1])return;purgeKeywords();let displayVal=editor.displayValue;editor.displayValue=displayVal[0];for(let i=1;i<displayVal.length;i++)isAlpha(displayVal[i])&&isAlpha(displayVal[i-1])&&(editor.displayValue+="*"),editor.displayValue+=displayVal[i];replaceKeywords()}}function getLastOperand(){let arr=editor.displayValue,res=[];function makeOperand(){let oprand="";for(let i=res.length-1;i>-1;i--)oprand+=res[i];return editor.operator&&editor.operator.length>1&&(editor.operator.length>1||(oprand=editor.operator+oprand)),oprand}if(isNumber(arr[arr.length-1])||"."==arr[arr.length-1]&&arr.length-2>=0&&isNumber(arr[arr.length-2]))for(let i=arr.length-1;i>-1;i--){if(isAlpha(arr[i])||"^"==arr[i]&&"^2"!=editor.operator||"+"==arr[i]||"-"==arr[i]||"*"==arr[i]||"/"==arr[i]||")"==arr[i]||"("==arr[i]){if("^"==arr[i+1]&&(isAlpha(arr[i])&&res.push(arr[i]),")"==arr[i])){let bracket=0;for(let n=i;n>-1;n--){if(")"==arr[n]&&bracket++,"("==arr[n]&&bracket--,0==bracket)return res.push("("),makeOperand();res.push(arr[n])}}return makeOperand()}res.push(arr[i])}if(isAlpha(arr[arr.length-1])){let keyword=[];for(let n=arr.length-1;n>-1&&isAlpha(arr[n]);n--)keyword.push(arr[n]);if(keyword.length>1)for(let j=0;j<keyword.length;j++)res.push(keyword[j]);else res.push(arr[arr.length-1]);return makeOperand()}if(")"==arr[arr.length-1]){let bracket=0;for(let i=arr.length-1;i>-1;i--){if(")"==arr[i]&&bracket++,"("==arr[i]&&bracket--,0==bracket){if(res.push("("),i<arr.length-1){let keyword=[];for(let n=i-1;n>-1&&isAlpha(arr[n]);n--)keyword.push(arr[n]);if(keyword.length>1)for(let j=0;j<keyword.length;j++)res.push(keyword[j])}return makeOperand()}res.push(arr[i])}}return makeOperand()}function removeLastOperand(){let lastOperand=getLastOperand();if(!lastOperand.length)return!1;for(let i=0;i<lastOperand.length;i++)"("==lastOperand[i]&&bracket--,")"==lastOperand[i]&&bracket++;return bracket?editorScreenOperatorBracket[0].innerHTML="("+bracket:(editorScreenOperatorBracket[0].innerHTML="",editorScreenOperatorBracket.hide()),editor.displayValue=editor.displayValue.replaceLast(lastOperand,""),editor.lastOperandRemove=!0,!0}function negate(){let oprnd=getLastOperand();oprnd.length&&(editor.displayValue=editor.displayValue.replaceLast(oprnd,`-${oprnd}`))}function reciprocal(){var oprnd=getLastOperand();oprnd.length&&("("==oprnd[0]&&"("==editor.displayValue[0]?editor.displayValue=editor.displayValue.replaceLast(oprnd,"1/"+oprnd):oprnd==editor.displayValue?editor.displayValue=editor.displayValue.replaceLast(oprnd,"1/("+oprnd+")"):editor.displayValue=editor.displayValue.replaceLast(oprnd,"(1/"+oprnd+")"))}function handleOperator(nextOperator){const{firstOperand:firstOperand,displayValue:displayValue,operator:operator}=editor;"pi"==nextOperator&&editor.displayValue.length&&"("!==editor.displayValue[editor.displayValue.length-1]&&"*"!==editor.displayValue[editor.displayValue.length-1]&&(editor.displayValue+="*"),"pi"==operator&&1==nextOperator.length&&isAlpha(nextOperator)&&(editor.displayValue+="*");let ops=["+","-","/","*"],lastChar;if(editor.displayValue.length&&(lastChar=editor.displayValue[editor.displayValue.length-1],ops.includes(lastChar)&&ops.includes(nextOperator)))editor.displayValue=editor.displayValue.replaceLast(lastChar,nextOperator);else if(""!=editor.displayValue||"+"!=nextOperator&&"-"!=nextOperator&&"/"!=nextOperator&&"*"!=nextOperator||(editor.displayValue="0"),"^2"!=nextOperator||""!=editor.displayValue&&"+"!=lastChar&&"-"!=lastChar&&"/"!=lastChar&&"*"!=lastChar){if(!("sqrt"!=nextOperator&&"abs"!=nextOperator&&"10^"!=nextOperator&&"sin"!=nextOperator&&"cos"!=nextOperator&&"tan"!=nextOperator&&"sec"!=nextOperator&&"csc"!=nextOperator&&"cot"!=nextOperator&&"asin"!=nextOperator&&"acos"!=nextOperator&&"atan"!=nextOperator&&"asec"!=nextOperator&&"acsc"!=nextOperator&&"acot"!=nextOperator&&"sinh"!=nextOperator&&"cosh"!=nextOperator&&"tanh"!=nextOperator&&"sech"!=nextOperator&&"csch"!=nextOperator&&"coth"!=nextOperator&&"asinh"!=nextOperator&&"acosh"!=nextOperator&&"atanh"!=nextOperator&&"asech"!=nextOperator&&"acsch"!=nextOperator&&"acoth"!=nextOperator&&"log"!=nextOperator&&"log10"!=nextOperator||""===editor.displayValue&&"+"===lastChar&&"-"===lastChar&&"/"===lastChar&&"*"===lastChar)){var oprnd=getLastOperand();if(!oprnd.length)return;return oprnd==editor.displayValue||")"==editor.displayValue[editor.displayValue.length-oprnd.length-1]||"("==editor.displayValue[editor.displayValue.length-oprnd.length-1]?editor.displayValue=editor.displayValue.replaceLast(oprnd,nextOperator+"("+oprnd+")"):isAlpha(editor.displayValue[editor.displayValue.length-oprnd.length-1])?editor.displayValue=editor.displayValue.replaceLast(oprnd,"*"+nextOperator+"("+oprnd+")"):editor.displayValue=editor.displayValue.replaceLast(oprnd,"("+nextOperator+"("+oprnd+"))"),void(editor.operator=nextOperator)}editor.displayValue+=nextOperator,editor.operator=nextOperator}}function enter(){simplifyOutput?jQuery(`#${idOfTriggerElement}`).trigger("equationEdited",[math.simplify(editor.displayValue).toString(),editor.latex,idOfTriggerElement]):jQuery(`#${idOfTriggerElement}`).trigger("equationEdited",[editor.displayValue,editor.latex,idOfTriggerElement]),dlg.modal("hide")}function resetEditor(){editor.resetEditor||!initializeWithLastValue?(editor.resetEditor=!1,editor.displayValue="",editor.lastOperandRemove=!1,editor.operator=null,editor.backSpaced=!1,document.querySelector(".editor-screen").innerHTML="",editorScreenOperatorBracket[0].innerHTML="",editorScreenOperatorBracket.hide(),bracket=0,displayOperator.hide(),jQuery("#editor-screen-col").css("width","100%"),displayOperator[0].innerHTML=""):updateDisplay()}function toggleHyp(){editor.hypFunction=!editor.hypFunction;const sin=document.getElementById("sin"),cos=document.getElementById("cos"),tan=document.getElementById("tan"),sec=document.getElementById("sec"),csc=document.getElementById("csc"),cot=document.getElementById("cot");editor.hypFunction?editor.secondFunction?(sin.value="asinh",sin.innerText=sin.value,cos.value="acosh",cos.innerText=cos.value,tan.value="atanh",tan.innerText=tan.value,sec.value="asech",sec.innerText=sec.value,csc.value="acsch",csc.innerText=csc.value,cot.value="acoth",cot.innerText=cot.value):(sin.value="sinh",sin.innerText=sin.value,cos.value="cosh",cos.innerText=cos.value,tan.value="tanh",tan.innerText=tan.value,sec.value="sech",sec.innerText=sec.value,csc.value="csch",csc.innerText=csc.value,cot.value="coth",cot.innerText=cot.value):editor.secondFunction?(sin.value="asin",sin.innerText=sin.value,cos.value="acos",cos.innerText=cos.value,tan.value="atan",tan.innerText=tan.value,sec.value="asec",sec.innerText=sec.value,csc.value="acsc",csc.innerText=csc.value,cot.value="acot",cot.innerText=cot.value):(sin.value="sin",sin.innerText=sin.value,cos.value="cos",cos.innerText=cos.value,tan.value="tan",tan.innerText=tan.value,sec.value="sec",sec.innerText=sec.value,csc.value="csc",csc.innerText=csc.value,cot.value="cot",cot.innerText=cot.value)}function doHideAlphas(){jQuery(open_curly).hide(),jQuery(close_curly).hide(),jQuery(less_than).hide(),jQuery(f).hide(),jQuery(x).hide(),jQuery(y).hide(),jQuery("#equationEditorEnter").removeClass("enter_button"),jQuery("#equationEditorEnter").addClass("enter_button_no_alphas")}function doShowAlphas(){jQuery(open_curly).show(),jQuery(close_curly).show(),jQuery(less_than).show(),jQuery(f).show(),jQuery(x).show(),jQuery(y).show(),jQuery("#equationEditorEnter").addClass("enter_button"),jQuery("#equationEditorEnter").removeClass("enter_button_no_alphas")}function toggle2nd(){editor.secondFunction=!editor.secondFunction;const sin=document.getElementById("sin"),cos=document.getElementById("cos"),tan=document.getElementById("tan"),sec=document.getElementById("sec"),csc=document.getElementById("csc"),cot=document.getElementById("cot");editor.secondFunction?(open_curly.value=open_curly.value="g",open_curly.innerText=open_curly.value,close_curly.value=close_curly.value="h",close_curly.innerText=close_curly.value,less_than.value=less_than.value="a",less_than.innerText=less_than.value,f.value=f.value="b",f.innerText=f.value,x.value=x.value="c",x.innerText=x.value,y.value=y.value=",",y.innerText=y.value,editor.hypFunction?(sin.value="asinh",sin.innerText=sin.value,cos.value="acosh",cos.innerText=cos.value,tan.value="atanh",tan.innerText=tan.value,sec.value="asech",sec.innerText=sec.value,csc.value="acsch",csc.innerText=csc.value,cot.value="acoth",cot.innerText=cot.value):(sin.value="asin",sin.innerText=sin.value,cos.value="acos",cos.innerText=cos.value,tan.value="atan",tan.innerText=tan.value,sec.value="asec",sec.innerText=sec.value,csc.value="acsc",csc.innerText=csc.value,cot.value="acot",cot.innerText=cot.value)):(open_curly.value=open_curly.value="{",open_curly.innerText=open_curly.value,close_curly.value=close_curly.value="}",close_curly.innerText=close_curly.value,less_than.value=less_than.value="<",less_than.innerText=less_than.value,f.value=f.value="f",f.innerText=f.value,x.value=x.value="x",x.innerText=x.value,y.value=y.value="y",y.innerText=y.value,editor.hypFunction?(sin.value="sinh",sin.innerText=sin.value,cos.value="cosh",cos.innerText=cos.value,tan.value="tanh",tan.innerText=tan.value,sec.value="sech",sec.innerText=sec.value,csc.value="csch",csc.innerText=csc.value,cot.value="coth",cot.innerText=cot.value):(sin.value="sin",sin.innerText=sin.value,cos.value="cos",cos.innerText=cos.value,tan.value="tan",tan.innerText=tan.value,sec.value="sec",sec.innerText=sec.value,csc.value="csc",csc.innerText=csc.value,cot.value="cot",cot.innerText=cot.value))}function backSpace(){if(editor.displayValue.length){const c=editor.displayValue[editor.displayValue.length-1];if(")"==c||"+"==c||"-"==c||"*"==c||"/"==c)return;editor.charRemoveByBackspace=c,editor.displayValue=editor.displayValue.substring(0,editor.displayValue.length-1),editor.backSpaced=!0}}String.prototype.replaceLast=function(search,replace){let lastIndex=this.lastIndexOf(search),beginString,endString;return-1===lastIndex?this:this.substring(0,lastIndex)+replace+this.substring(lastIndex+search.length)},jQuery(`#${idOfTriggerElement}`).bind("equationEditorInitialize",(function(e,equation){function isAlpha(ch){return(ch=ch.toLowerCase().charCodeAt(0))>96&&ch<122}function getOperand(exp,indexOfKeyword){let operand="",lBracket=0;for(let i=indexOfKeyword+1;i<exp.length&&("+"!=exp[i]&&"-"!=exp[i]&&"*"!=exp[i]&&"/"!=exp[i]);i++)if("("!=exp[i]){if(")"!=exp[i])operand+=exp[i];else if(operand+=")",lBracket--,0==lBracket)break}else operand+="(",lBracket++;return operand}editor.displayValue=equation=equation.replace(/\s/g,"");let last_index=equation.lastIndexOf("^");if(-1!==last_index){let operand=getOperand(equation,last_index);"("!==operand[0]?editor.operator="^"+operand:editor.operator=")"}}));const mj=function(tex){return MathJax.tex2svg(tex,{em:16,ex:6,display:!1})};function updateDisplay(){insertProductSymbol();const display=document.querySelector(".editor-screen"),clear=document.getElementById("clear");if(editor.displayValue.length){if(editor.lastOperandRemove?clear&&(clear.value="C",clear.innerText="C"):clear&&(clear.value="CE",clear.innerText="CE"),"."==editor.displayValue[editor.displayValue.length-1])return void(display.innerHTML=editor.displayValue);try{editor.latex=parser.parse(editor.displayValue);let val=mj(editor.latex);displayOperator.hide(),editorScreenOperatorBracket.hide(),bracket=0,jQuery("#editor-screen-col").css("width","100%"),displayOperator[0].innerHTML="",display.innerHTML="",display.appendChild(val),validOnly&&disableEnterButton(!1)}catch(err){console.log(err.message)}}else display.innerHTML="",clear.value="C",clear.innerText="C",editor.lastOperandRemove=!1,editorScreenOperatorBracket[0].innerHTML="",editorScreenOperatorBracket.hide(),displayOperator[0].innerHTML="",displayOperator.hide(),jQuery("#editor-screen-col").css("width","100%"),bracket=0;editor.backSpaced=!1}jQuery("#"+idOfTriggerElement).click(),jQuery("#equationEditorCloseButton").click(),jQuery("#equationEditorCloseButton").click()}}"undefined"!=typeof exports&&(exports.EquationEditor=EquationEditor);