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

10 lines
110 KiB
JavaScript
Raw Normal View History

System.register([],(function(t){"use strict";return{execute:function(){var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}var check=function(t){return t&&t.Math==Math&&t},n=check("object"==typeof globalThis&&globalThis)||check("object"==typeof window&&window)||check("object"==typeof self&&self)||check("object"==typeof e&&e)||Function("return this")(),fails=function(t){try{return!!t()}catch(t){return!0}},r=!fails((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),i={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,s={f:o&&!i.call({1:2},1)?function propertyIsEnumerable(t){var e=o(this,t);return!!e&&e.enumerable}:i},createPropertyDescriptor=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},u={}.toString,classofRaw=function(t){return u.call(t).slice(8,-1)},l="".split,h=fails((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==classofRaw(t)?l.call(t,""):Object(t)}:Object,requireObjectCoercible=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},toIndexedObject=function(t){return h(requireObjectCoercible(t))},isObject=function(t){return"object"==typeof t?null!==t:"function"==typeof t},toPrimitive=function(t,e){if(!isObject(t))return t;var n,r;if(e&&"function"==typeof(n=t.toString)&&!isObject(r=n.call(t)))return r;if("function"==typeof(n=t.valueOf)&&!isObject(r=n.call(t)))return r;if(!e&&"function"==typeof(n=t.toString)&&!isObject(r=n.call(t)))return r;throw TypeError("Can't convert object to primitive value")},f={}.hasOwnProperty,has=function(t,e){return f.call(t,e)},p=n.document,d=isObject(p)&&isObject(p.createElement),documentCreateElement=function(t){return d?p.createElement(t):{}},m=!r&&!fails((function(){return 7!=Object.defineProperty(documentCreateElement("div"),"a",{get:function(){return 7}}).a})),v=Object.getOwnPropertyDescriptor,x={f:r?v:function getOwnPropertyDescriptor(t,e){if(t=toIndexedObject(t),e=toPrimitive(e,!0),m)try{return v(t,e)}catch(t){}if(has(t,e))return createPropertyDescriptor(!s.f.call(t,e),t[e])}},anObject=function(t){if(!isObject(t))throw TypeError(String(t)+" is not an object");return t},y=Object.defineProperty,S={f:r?y:function defineProperty(t,e,n){if(anObject(t),e=toPrimitive(e,!0),anObject(n),m)try{return y(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},M=r?function(t,e,n){return S.f(t,e,createPropertyDescriptor(1,n))}:function(t,e,n){return t[e]=n,t},setGlobal=function(t,e){try{M(n,t,e)}catch(r){n[t]=e}return e},w="__core-js_shared__",E=n[w]||setGlobal(w,{}),J=Function.toString;"function"!=typeof E.inspectSource&&(E.inspectSource=function(t){return J.call(t)});var T,P,k,A=E.inspectSource,C=n.WeakMap,j="function"==typeof C&&/native code/.test(A(C)),I=createCommonjsModule((function(t){(t.exports=function(t,e){return E[t]||(E[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),O=0,R=Math.random(),uid=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++O+R).toString(36)},L=I("keys"),sharedKey=function(t){return L[t]||(L[t]=uid(t))},D={},H=n.WeakMap;if(j){var U=new H,N=U.get,B=U.has,q=U.set;T=function(t,e){return q.call(U,t,e),e},P=function(t){return N.call(U,t)||{}},k=function(t){return B.call(U,t)}}else{var G=sharedKey("state");D[G]=!0,T=function(t,e){return M(t,G,e),e},P=function(t){return has(t,G)?t[G]:{}},k=function(t){return has(t,G)}}var z,$={set:T,get:P,has:k,enforce:function(t){return k(t)?P(t):T(t,{})},getterFor:function(t){return function(e){var n;if(!isObject(e)||(n=P(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return n}}},V=cr
2020-09-06 06:32:10 +00:00
/**
2020-09-08 23:35:47 +00:00
* @file ext-mathjax.js
*
* @license MIT
*
* @copyright 2013 Jo Segaert
*
*/t("default",{name:"mathjax",init:function init(t){var e=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var n,r,i,o,s,u,l,h,f,p,d,m;return regeneratorRuntime.wrap((function _callee2$(v){for(;;)switch(v.prev=v.next){case 0:return d=function _saveMath(){var t=n("#mathjax_code_textarea").val();MathJax.Hub.queue.Push(["Text",l,"\\displaystyle{"+t+"}"]),MathJax.Hub.queue.Push((function(){var t=n(".MathJax_SVG"),e=n(t.html());e.find("use").each((function(){var t=n(this).attr("href")?n(this).attr("href").slice(1):n(this).attr("xlink:href").slice(1),e=n("#"+t).clone().removeAttr("id"),r=n(this).attr("x"),i=n(this).attr("y"),o=n(this).attr("transform");o&&(r||i)?e.attr("transform",o+" translate("+r+","+i+")"):o?e.attr("transform",o):(r||i)&&e.attr("transform","translate("+r+","+i+")"),n(this).replaceWith(e)})),e.removeAttr("style"),e.attr("xmlns","http://www.w3.org/2000/svg"),s.importSvgString(n("<div>").append(e.clone()).html(),!0),s.ungroupSelectedElement(),s.moveSelectedElements(h,f,!0)}))},n=t.$,r=e,v.next=5,__variableDynamicImportRuntime0__("./locale/".concat(r.curPrefs.lang,".js"));case 5:return i=v.sent,o=i.default,s=r.canvas,u=r.uiStrings,p=!1,n.extend(u,{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"}}),m=[{id:"tool_mathjax",type:"mode",icon:"mathjax.png",events:{click:function click(){return _asyncToGenerator(regeneratorRuntime.mark((function _callee(){return regeneratorRuntime.wrap((function _callee$(t){for(;;)switch(t.prev=t.next){case 0:if(s.setMode("mathjax"),!1!==p){t.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(){d(),n("#mathjax").hide()})),n("body").addClass("tex2jax_ignore"),t.prev=7,t.next=10,Promise.resolve().then((function(){return No}));case 10:MathJax.Hub.queue.Push((function(){l=MathJax.Hub.getAllJax("#mathjax_creator")[0],console.log(l),p=!0,console.log("MathJax Loaded")})),t.next=17;break;case 13:t.prev=13,t.t0=t.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 t.stop()}}),_callee,null,[[7,13]])})))()}}}],v.abrupt("return",{name:o.name,svgicons:"mathjax-icons.xml",buttons:o.buttons.map((function(t,e){return Object.assign(m[e],t)})),mouseDown:function mouseDown(){if("mathjax"===s.getMode())return{started:!0}},mouseUp:function mouseUp(t){if("mathjax"===s.getMode()){var e=s.getZoom();return h=t.mouse_x/e,f=t.mouse_y/e,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_container {position: absolute;top: 50px;paddin