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

10 lines
5.1 KiB
JavaScript
Raw Normal View History

2020-09-06 06:32:10 +00:00
System.register([],(function(e,t){"use strict";return{execute:function(){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
*
*/e("default",{name:"mathjax",init:function init(e){var a=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var n,o,r,i,l,s,c,h,m,d,u,x;return regeneratorRuntime.wrap((function _callee2$(p){for(;;)switch(p.prev=p.next){case 0:return u=function _saveMath(){var e=n("#mathjax_code_textarea").val();MathJax.Hub.queue.Push(["Text",c,"\\displaystyle{"+e+"}"]),MathJax.Hub.queue.Push((function(){var e=n(".MathJax_SVG"),t=n(e.html());t.find("use").each((function(){var e=n(this).attr("href")?n(this).attr("href").slice(1):n(this).attr("xlink:href").slice(1),t=n("#"+e).clone().removeAttr("id"),a=n(this).attr("x"),o=n(this).attr("y"),r=n(this).attr("transform");r&&(a||o)?t.attr("transform",r+" translate("+a+","+o+")"):r?t.attr("transform",r):(a||o)&&t.attr("transform","translate("+a+","+o+")"),n(this).replaceWith(t)})),t.removeAttr("style"),t.attr("xmlns","http://www.w3.org/2000/svg"),l.importSvgString(n("<div>").append(t.clone()).html(),!0),l.ungroupSelectedElement(),l.moveSelectedElements(h,m,!0)}))},n=e.$,o=a,p.next=5,t.import("./locale/".concat(o.curPrefs.lang,".js"));case 5:return r=p.sent,i=r.default,l=o.canvas,"mathjax/MathJax.min.js?config=TeX-AMS-MML_SVG.js",s=o.uiStrings,d=!1,n.extend(s,{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"}}),x=[{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(l.setMode("mathjax"),!1!==d){e.next=17;break}return n('<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(),n("#mathjax_container").draggable({cancel:"button,fieldset",containment:"window"}),n("#tool_mathjax_cancel").prepend(n.getSvgIcon("cancel",!0)).on("click touched",(function(){n("#mathjax").hide()})),n("#tool_mathjax_save").prepend(n.getSvgIcon("ok",!0)).on("click touched",(function(){u(),n("#mathjax").hide()})),n("body").addClass("tex2jax_ignore"),e.prev=7,e.next=10,t.import("mathjax/MathJax.min.js?config=TeX-AMS-MML_SVG.js");case 10:MathJax.Hub.queue.Push((function(){c=MathJax.Hub.getAllJax("#mathjax_creator")[0],console.log(c),d=!0,console.log("MathJax Loaded")})),e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("Failed loading MathJax."),n.alert("Failed loading MathJax. You will not be able to change the mathematics.");case 17:case"end":return e.stop()}}),_callee,null,[[7,13]])})))()}}}],p.abrupt("return",{name:i.name,svgicons:"mathjax-icons.xml",buttons:i.buttons.map((function(e,t){return Object.assign(x[t],e)})),mouseDown:function mouseDown(){if("mathjax"===l.getMode())return{started:!0}},mouseUp:function mouseUp(e){if("mathjax"===l.getMode()){var t=l.getZoom();return h=e.mouse_x/t,m=e.mouse_y/t,n("#mathjax").show(),{started:!1}}},callback:function callback(){n("<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_cont