Files
svgedit/dist/editor/extensions/ext-mathjax.js
2020-09-04 22:34:30 +02:00

12 lines
6.0 KiB
JavaScript

function _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,a;function resume(t,a){try{var n=e[t](a),r=n.value,o=r instanceof _AwaitValue;Promise.resolve(o?r.wrapped:r).then((function(e){o?resume("return"===t?"return":"next",e):settle(n.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,n){switch(e){case"return":t.resolve({value:n,done:!0});break;case"throw":t.reject(n);break;default:t.resolve({value:n,done:!1})}(t=t.next)?resume(t.key,t.arg):a=null}this._invoke=function send(e,n){return new Promise((function(r,o){var i={key:e,arg:n,resolve:r,reject:o,next:null};a?a=a.next=i:(t=a=i,resume(e,n))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,a,n,r,o,i){try{var s=e[o](i),l=s.value}catch(e){return void a(e)}s.done?t(l):Promise.resolve(l).then(n,r)}function _asyncToGenerator(e){return function(){var t=this,a=arguments;return new Promise((function(n,r){var o=e.apply(t,a);function _next(e){asyncGeneratorStep(o,n,r,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(o,n,r,_next,_throw,"throw",e)}_next(void 0)}))}}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},_AsyncGenerator.prototype.throw=function(e){return this._invoke("throw",e)},_AsyncGenerator.prototype.return=function(e){return this._invoke("return",e)};
/**
* @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,r,o,i,s,l,c,u,h,m,d;return regeneratorRuntime.wrap((function _callee2$(x){for(;;)switch(x.prev=x.next){case 0:return m=function _saveMath(){var e=a("#mathjax_code_textarea").val();MathJax.Hub.queue.Push(["Text",l,"\\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"),r=a(this).attr("y"),o=a(this).attr("transform");o&&(n||r)?t.attr("transform",o+" translate("+n+","+r+")"):o?t.attr("transform",o):(n||r)&&t.attr("transform","translate("+n+","+r+")"),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,u,!0)}))},a=e.$,n=e.importLocale,x.next=4,n();case 4:return r=x.sent,i=(o=t).canvas,"mathjax/MathJax.min.js?config=TeX-AMS-MML_SVG.js",s=o.uiStrings,h=!1,a.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"}}),d=[{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!==h){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(){m(),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(){l=MathJax.Hub.getAllJax("#mathjax_creator")[0],console.log(l),h=!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(d[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,u=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: absolute;top: 50px;padding: 10px;background-color: #B0B0B0;border: 1px outset #777;opacity: 1.0;font-family: Verdana, Helvetica, sans-serif;font-size: .8em;z-index: 20001;}#tool_mathjax_back {margin-left: 1em;overflow: auto;}#mathjax_legend{font-weight: bold;font-size:1.1em;}#mathjax_code_textarea {\\nmargin: 5px .7em;overflow: hidden;width: 416px;display: block;height: 100px;}").appendTo("head")}});case 12:case"end":return x.stop()}}),_callee2)})))()}};export default e;
//# sourceMappingURL=ext-mathjax.js.map