svgedit/dist/editor/extensions/ext-mathjax/ext-mathjax.js

11 lines
5.0 KiB
JavaScript
Raw Normal View History

2020-09-06 06:32:10 +00:00
function asyncGeneratorStep(e,t,a,n,o,r,i){try{var l=e[r](i),s=l.value}catch(e){return void a(e)}l.done?t(s):Promise.resolve(s).then(n,o)}function _asyncToGenerator(e){return function(){var t=this,a=arguments;return new Promise((function(n,o){var r=e.apply(t,a);function _next(e){asyncGeneratorStep(r,n,o,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(r,n,o,_next,_throw,"throw",e)}_next(void 0)}))}}
/**
* @file ext-mathjax.js
*
* @license MIT
*
* @copyright 2013 Jo Segaert
*
*/var e={name:"mathjax",init:function init(e){var t=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var a,n,o,r,i,l,s,c,h,m,d,u;return regeneratorRuntime.wrap((function _callee2$(x){for(;;)switch(x.prev=x.next){case 0:return d=function _saveMath(){var e=a("#mathjax_code_textarea").val();MathJax.Hub.queue.Push(["Text",s,"\\displaystyle{"+e+"}"]),MathJax.Hub.queue.Push((function(){var e=a(".MathJax_SVG"),t=a(e.html());t.find("use").each((function(){var e=a(this).attr("href")?a(this).attr("href").slice(1):a(this).attr("xlink:href").slice(1),t=a("#"+e).clone().removeAttr("id"),n=a(this).attr("x"),o=a(this).attr("y"),r=a(this).attr("transform");r&&(n||o)?t.attr("transform",r+" translate("+n+","+o+")"):r?t.attr("transform",r):(n||o)&&t.attr("transform","translate("+n+","+o+")"),a(this).replaceWith(t)})),t.removeAttr("style"),t.attr("xmlns","http://www.w3.org/2000/svg"),i.importSvgString(a("<div>").append(t.clone()).html(),!0),i.ungroupSelectedElement(),i.moveSelectedElements(c,h,!0)}))},a=e.$,n=t,x.next=5,import("./locale/".concat(n.curPrefs.lang,".js"));case 5:return o=x.sent,r=o.default,i=n.canvas,"mathjax/MathJax.min.js?config=TeX-AMS-MML_SVG.js",l=n.uiStrings,m=!1,a.extend(l,{mathjax:{embed_svg:"Save as mathematics",embed_mathml:"Save as figure",svg_save_warning:"The math will be transformed into a figure is manipulatable like everything else. You will not be able to manipulate the TeX-code anymore.",mathml_save_warning:"Advised. The math will be saved as a figure.",title:"Mathematics code editor"}}),u=[{id:"tool_mathjax",type:"mode",icon:"mathjax.png",events:{click:function click(){return _asyncToGenerator(regeneratorRuntime.mark((function _callee(){return regeneratorRuntime.wrap((function _callee$(e){for(;;)switch(e.prev=e.next){case 0:if(i.setMode("mathjax"),!1!==m){e.next=17;break}return a('<div id="mathjax">\x3c!-- Here is where MathJax creates the math --\x3e<div id="mathjax_creator" class="tex2jax_process" style="display:none">$${}$$</div><div id="mathjax_overlay"></div><div id="mathjax_container"><div id="tool_mathjax_back" class="toolbar_button"><button id="tool_mathjax_save">OK</button><button id="tool_mathjax_cancel">Cancel</button></div><fieldset><legend id="mathjax_legend">Mathematics Editor</legend><label><span id="mathjax_explication">Please type your mathematics in <a href="https://en.wikipedia.org/wiki/Help:Displaying_a_formula" target="_blank">TeX</a> code.</span></label><textarea id="mathjax_code_textarea" spellcheck="false"></textarea></fieldset></div></div>').insertAfter("#svg_prefs").hide(),a("#mathjax_container").draggable({cancel:"button,fieldset",containment:"window"}),a("#tool_mathjax_cancel").prepend(a.getSvgIcon("cancel",!0)).on("click touched",(function(){a("#mathjax").hide()})),a("#tool_mathjax_save").prepend(a.getSvgIcon("ok",!0)).on("click touched",(function(){d(),a("#mathjax").hide()})),a("body").addClass("tex2jax_ignore"),e.prev=7,e.next=10,import("mathjax/MathJax.min.js?config=TeX-AMS-MML_SVG.js");case 10:MathJax.Hub.queue.Push((function(){s=MathJax.Hub.getAllJax("#mathjax_creator")[0],console.log(s),m=!0,console.log("MathJax Loaded")})),e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("Failed loading MathJax."),a.alert("Failed loading MathJax. You will not be able to change the mathematics.");case 17:case"end":return e.stop()}}),_callee,null,[[7,13]])})))()}}}],x.abrupt("return",{name:r.name,svgicons:"mathjax-icons.xml",buttons:r.buttons.map((function(e,t){return Object.assign(u[t],e)})),mouseDown:function mouseDown(){if("mathjax"===i.getMode())return{started:!0}},mouseUp:function mouseUp(e){if("mathjax"===i.getMode()){var t=i.getZoom();return c=e.mouse_x/t,h=e.mouse_y/t,a("#mathjax").show(),{started:!1}}},callback:function callback(){a("<style>").text("#mathjax fieldset{padding: 5px;margin: 5px;border: 1px solid #DDD;}#mathjax label{display: block;margin: .5em;}#mathjax legend {max-width:195px;}#mathjax_overlay {position: absolute;top: 0;left: 0;right: 0;bottom: 0;background-color: black;opacity: 0.6;z-index: 20000;}#mathjax_container {position:
//# sourceMappingURL=ext-mathjax.js.map