-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmje.js
1 lines (1 loc) · 8.14 KB
/
mje.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mje=t():e.mje=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return e.toLowerCase()}function a(e,t){switch(r(t.tagName)){case"mrow":case"math":return t.children.length?(t.insertBefore(e,t.lastElementChild.nextSibling),!0):(t.appendChild(e),!0);default:return t.parentNode.insertBefore(e,t),!0}}function i(e,t,n){var a=t.parentNode;if(t.hasAttribute("editable"))return n||t;switch(r(t.tagName)){case"mrow":return i(e,a,t);case"math":return t}var o=t.nextElementSibling||a;return a.removeChild(t),o}function o(e,t){!function e(n){var a="mrow"===r(n.tagName)||"math"===r(n.tagName);if(a||t(n),n.children)for(var i=n.children.length,o=0;o<i;o++)e(n.children[o]);a&&t(n)}(e)}n.r(t);var l=0;var u=["mo","mi","mn","mspace"];function c(e){o(e,function(e){e.id||(e.id="mje-node".concat(l++))});var t=e.cloneNode(!0),n=function(){var e=MathJax.HTML.Element("mspace");return e.setAttribute("width","thinmathspace"),e};return o(t,function(e){var t=r(e.tagName);switch(t){case"mrow":case"math":if(!e.children.length){e.appendChild(MathJax.HTML.Element("mi",{className:"mje-placeholder"},["?"]));break}"math"!==t&&(e.appendChild(n()),e.insertBefore(n(),e.firstChild));break;default:-1===u.indexOf(t)&&(console.log(t),e.parentNode.insertBefore(n(),e.nextSibling))}}),t.outerHTML}var d={"*":"⋅","/":"÷","+":"+","-":"-","=":"=","<":"<",">":">","|":"|","%":"%",",":",",".":".",$:"$","(":"(",")":")","[":"[","]":"]","!":"!"};function s(e){var t={},n=[],a=null,i=null,l=function(e,n){if(e)return t.hasOwnProperty(n)||(t[n]=e.getBoundingClientRect()),t[n]};return o(e,function(e){var t=document.getElementById(e.id);if(t){var o,u,c=e.children.length,d=t.lastElementChild,s=e.parentNode,f=r(e.tagName),m=l(t,e.id),h={y:m.top,height:m.height,source:e,previous:a};switch(s&&"mrow"!==f&&(o=document.getElementById(s.id),u=l(o,s.id),h.y=u.top,h.height=o.clientHeight),i&&(i.next=e),r(f)){case"math":h.x=(c?m.width:0)+m.left;break;case"mrow":h.x=(c?m.width-d.clientWidth:0)+m.left;break;default:h.x=m.left}n.push(h),a=e,i=h}}),n}function f(e){if(!MathJax)throw new Error("mje: MathJax not found. Ensure that MathJax is loaded before calling mje.");var t={},n=MathJax.HTML.Element("math"),l=function(){var e=MathJax.HTML.Element("div",{className:"mje-wrapper"}),t=MathJax.HTML.Element("div",{className:"mje-container"}),n=MathJax.HTML.Element("div",{className:"mje-cursor hidden"}),r=MathJax.HTML.Element("input",{className:"mje-input"}),a=null,i=!1,o=!1,l=null,u={click:null,input:null,code:null,scroll:null},c=function(){i?(n.classList.remove("hidden"),t.classList.add("focused")):(n.classList.add("hidden"),t.classList.remove("focused"))},d=function(){r.value.length&&(u.input(r.value),r.value="")},s=function e(){i&&n.classList.toggle("hidden"),l=setTimeout(e,700)},f=function(){i&&(n.classList.remove("hidden"),clearTimeout(l),l=setTimeout(s,700))};return e.appendChild(t),e.appendChild(n),e.appendChild(r),document.addEventListener("click",function(){if(!o)return i=!1,r.blur(),c()}),t.addEventListener("click",function(e){i||u.scroll(),i=!0,u.click(e.clientX,e.clientY),r.focus(),c()}),t.addEventListener("mouseenter",function(){o=!0}),t.addEventListener("mouseleave",function(){o=!1}),r.addEventListener("blur",function(){return o?(r.focus(),c()):(i=!1,c())}),r.addEventListener("keydown",d),r.addEventListener("keyup",d),r.addEventListener("keydown",function(e){u.code(e.keyCode)}),window.addEventListener("scroll",function(){i&&u.scroll()}),l=setTimeout(s,700),{events:u,unblink:f,wrapper:function(){return e},value:function(e){return f(),new Promise(function(n){if(a)return a.Text(e,n);t.innerHTML=e;var i=function(){MathJax.Hub.Queue(["Typeset",MathJax.Hub,t,function(){a=MathJax.Hub.getAllJax(r)[0],n()}])};MathJax.isReady?i():MathJax.Hub.Register.StartupHook("End",function(){setTimeout(i,1e3)})})},draw:function(e){e&&(n.style.left="".concat(e.x,"px"),n.style.top="".concat(e.y,"px"),n.style.height="".concat(e.height,"px"),r.style.left="".concat(e.x,"px"),r.style.top="".concat(e.y,"px"))}}}(),u=n,f=null,m=null,h=!1,p=function(){f=m.find(function(e){return e.source===u}),l.draw(f)},M=function(e,t){return e&&(l.unblink(),u=e),t?l.value(c(t)).then(function(){m=s(t),p()}):p()},v=function(){if(!h)return!0;for(var e=u;e;){if(e.hasAttribute("editable"))return!0;e=e.parentNode}return!1};if(t.raw=function(){return n},t.path=function(){return m},t.right=function(){M(f.next)},t.left=function(){M(f.previous)},t.del=function(){v()&&M(i(n,u),n)},t.backspace=function(){v()&&M(function(e,t){var n=t.parentNode,a=t.previousElementSibling,o=r(t.tagName);switch(o){case"mrow":case"math":return t.lastElementChild?i(e,t.lastElementChild,t):"math"===o?t:i(e,n,t)}return a||"math"!==r(n.tagName)?(console.log("yey"),i(e,a||n,t)):t}(n,u),n)},t.number=function(e){v()&&(a(MathJax.HTML.Element("mn",null,[e]),u),M(null,n))},t.identifier=function(e){v()&&(a(MathJax.HTML.Element("mi",null,[e]),u),M(null,n))},t.operator=function(e){v()&&(a(MathJax.HTML.Element("mo",null,[e]),u),M(null,n))},t.frac=function(){if(v()){var e=MathJax.HTML.Element("mfrac"),t=MathJax.HTML.Element("mrow"),r=MathJax.HTML.Element("mrow");e.appendChild(t),e.appendChild(r),a(e,u),M(t,n)}},t.sqrt=function(){if(v()){var e=MathJax.HTML.Element("msqrt"),t=MathJax.HTML.Element("mrow");e.appendChild(t),a(e,u),M(t,n)}},t.root=function(){if(v()){var e=MathJax.HTML.Element("mroot"),t=MathJax.HTML.Element("mrow"),r=MathJax.HTML.Element("mrow");e.appendChild(t),e.appendChild(r),a(e,u),M(t,n)}},t.sup=function(){if(v()){var e=MathJax.HTML.Element("msup"),t=MathJax.HTML.Element("mrow"),r=MathJax.HTML.Element("mrow");e.appendChild(t),e.appendChild(r),a(e,u),M(t,n)}},t.sub=function(){if(v()){var e=MathJax.HTML.Element("msub"),t=MathJax.HTML.Element("mrow"),r=MathJax.HTML.Element("mrow");e.appendChild(t),e.appendChild(r),a(e,u),M(t,n)}},t.subsup=function(){if(v()){var e=MathJax.HTML.Element("msubsup"),t=MathJax.HTML.Element("mrow"),r=MathJax.HTML.Element("mrow"),i=MathJax.HTML.Element("mrow");e.appendChild(t),e.appendChild(r),e.appendChild(i),a(e,u),M(t,n)}},t.get=function(){var e=n.cloneNode(!0);return o(e,function(e){return e.removeAttribute("id")}),e.outerHTML},t.set=function(e){var t=(new DOMParser).parseFromString(e,"text/html");(n=t.body.firstElementChild).parentNode.removeChild(n),M(n,n)},t.readonly=function(e){h=e},l.events.click=function(e,t){var n=1/0,r=null,a=!0,i=!1,o=void 0;try{for(var l,c=m[Symbol.iterator]();!(a=(l=c.next()).done);a=!0){var d=l.value,s=d.x,f=d.y,h=f+d.height,p=Math.abs(s-e);f<=t&&t<=h&&n>p&&(n=p,r=d)}}catch(e){i=!0,o=e}finally{try{a||null==c.return||c.return()}finally{if(i)throw o}}r&&r.source!==u&&M(r.source)},l.events.input=function(e){return e.match(/\d/)?t.number(e):e.match(/[a-zA-Z]/)?t.identifier(e):d.hasOwnProperty(e)?t.operator(d[e]):void 0},l.events.code=function(e){switch(console.log(e),e){case 8:return t.backspace();case 37:return t.left();case 39:return t.right();case 46:return t.del()}},l.events.scroll=function(){console.log("recalculate"),m=s(n),M(u)},"string"==typeof e&&(e=document.querySelector(e)),!e||!e.parentNode)throw new Error("mje: target element not found.");return e.parentNode.replaceChild(l.wrapper(),e),MathJax.Hub.processSectionDelay=0,M(n,n),t}n.d(t,"default",function(){return f})}]).default});