mathjax
Version:
Beautiful and accessible math in all browsers. MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all browsers. This package includes the packaged components (install mathjax-full to get the source
1 lines • 13.6 kB
JavaScript
(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{LiteElement:()=>y});var n={};t.r(n),t.d(n,{LiteDocument:()=>g});var r={};t.r(r),t.d(r,{LiteComment:()=>x,LiteText:()=>w});var s={};t.r(s),t.d(s,{LiteList:()=>k});var i={};t.r(i),t.d(i,{LiteParser:()=>j,PATTERNS:()=>$});var o={};t.r(o),t.d(o,{LiteWindow:()=>z});var a={};t.r(a),t.d(a,{LiteAdaptor:()=>N,LiteBase:()=>I,liteAdaptor:()=>B});const l=("undefined"!=typeof window?window:global).MathJax._.components.global,c=(l.GLOBAL,l.isObject,l.combineConfig,l.combineDefaults,l.combineWithMathJax),u=(l.MathJax,MathJax._.core.DOMAdaptor.AbstractDOMAdaptor),h=MathJax._.util.Options,d=(h.isObject,h.APPEND,h.REMOVE,h.OPTIONS,h.Expandable,h.expandable,h.makeArray,h.keys,h.copy,h.insert,h.defaultOptions),p=h.userOptions,m=(h.selectOptions,h.selectOptionsFromKeys,h.separateOptions,h.lookup,MathJax._.util.AsyncLoad.asyncLoad);var f=function(t,e,n,r){return new(n||(n=Promise))((function(s,i){function o(t){try{l(r.next(t))}catch(t){i(t)}}function a(t){try{l(r.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))};const b={badCSS:!0,badSizes:!0};class y{constructor(t,e={},n=[]){this.kind=t,this.attributes=Object.assign({},e),this.children=[...n];for(const t of this.children)t.parent=this;this.styles=null}}class g{get kind(){return"#document"}constructor(t=null){this.defaultView=null,this.root=new y("html",{},[this.head=new y("head"),this.body=new y("body")]),this.type="",this.defaultView=t}}class w{get kind(){return"#text"}constructor(t=""){this.value=t}}class x extends w{get kind(){return"#comment"}}class k{constructor(t){this.nodes=[],this.nodes=[...t]}append(t){this.nodes.push(t)}[Symbol.iterator](){let t=0;return{next(){return t===this.nodes.length?{value:null,done:!0}:{value:this.nodes[t++],done:!1}}}}}const v=MathJax._.util.Entities,A=(v.options,v.entities,v.add,v.remove,v.translate),S=(v.numeric,"[ \\n]+"),C="[ \\n]*",O="[A-Za-z][^\0-\x1f \"'>/=\x7f-\x9f]*",L="[^\0-\x1f \"'>/=\x7f-\x9f]+",M=`${L}(?:${C}=${C}${`(?:'[^']*'|"[^"]*"|${S})`})?`,T=`(${L})(?:${C}=${C}${`(?:'([^']*)'|"([^"]*)"|(${S}))`})?`,$={tag:new RegExp(`(<(?:${O}(?:${S}${M})*${C}/?|/${O}|!--[^]*?--|![^]*?)(?:>|$))`,"u"),attr:new RegExp(M,"u"),attrsplit:new RegExp(T,"u")};class j{parseFromString(t,e="text/html",n=null){const r=n.createDocument();let s=n.body(r);const i=t.replace(/<\?.*?\?>/g,"").split($.tag);for(;i.length;){const t=i.shift(),e=i.shift();t&&this.addText(n,s,t),e&&">"===e.charAt(e.length-1)&&("!"===e.charAt(1)?this.addComment(n,s,e):s="/"===e.charAt(1)?this.closeTag(n,s,e):this.openTag(n,s,e,i))}return this.checkDocument(n,r),r}addText(t,e,n){return n=A(n),t.append(e,t.text(n))}addComment(t,e,n){return t.append(e,new x(n))}closeTag(t,e,n){const r=n.slice(2,n.length-1).toLowerCase();for(;t.parent(e)&&t.kind(e)!==r;)e=t.parent(e);return t.parent(e)}openTag(t,e,n,r){const s=this.constructor.PCDATA,i=this.constructor.SELF_CLOSING,o=n.match(/<(.*?)[\s\n>/]/)[1].toLowerCase(),a=t.node(o),l=n.replace(/^<.*?[\s\n>]/,"").split($.attrsplit);return(l.pop().match(/>$/)||l.length<5)&&(this.addAttributes(t,a,l),t.append(e,a),i[o]||n.match(/\/>$/)||(s[o]?this.handlePCDATA(t,a,o,r):e=a)),e}addAttributes(t,e,n){for(;n.length;){const[,r,s,i,o]=n.splice(0,5),a=A(s||i||o||"");t.setAttribute(e,r,a)}}handlePCDATA(t,e,n,r){const s=[],i="</"+n+">";let o="";for(;r.length&&o!==i;)s.push(o),s.push(r.shift()),o=r.shift();t.append(e,t.text(s.join("")))}checkDocument(t,e){const n=this.getOnlyChild(t,t.body(e));if(n){for(const r of t.childNodes(t.body(e))){if(r===n)break;r instanceof x&&r.value.match(/^<!DOCTYPE/)&&(e.type=r.value)}switch(t.kind(n)){case"html":for(const r of n.children)switch(t.kind(r)){case"head":e.head=r;break;case"body":e.body=r}e.root=n,t.remove(n),t.parent(e.body)!==n&&t.append(n,e.body),t.parent(e.head)!==n&&t.insert(e.head,e.body);break;case"head":e.head=t.replace(n,e.head);break;case"body":e.body=t.replace(n,e.body)}}}getOnlyChild(t,e){let n=null;for(const r of t.childNodes(e))if(r instanceof y){if(n)return null;n=r}return n}serialize(t,e,n=!1){const r=this.constructor.SELF_CLOSING,s=t.kind(e),i=this.allAttributes(t,e,n).map((t=>t.name+'="'+this.protectAttribute(t.value,n)+'"')).join(" "),o=this.serializeInner(t,e,n);return`<${s}`+(i?" "+i:"")+(n&&!o||r[s]?n?"/>":">":`>${o}</${s}>`)}serializeInner(t,e,n=!1){const r=this.constructor.PCDATA;return Object.hasOwn(r,e.kind)?t.childNodes(e).map((e=>t.value(e))).join(""):t.childNodes(e).map((e=>{const r=t.kind(e);return"#text"===r?this.protectHTML(t.value(e)):"#comment"===r?e.value:this.serialize(t,e,n)})).join("")}allAttributes(t,e,n){const r=t.allAttributes(e);if(!n)return r;const s=t.kind(e),i=this.constructor.XMLNS;if(!Object.hasOwn(i,s))return r;for(const{name:t}of r)if("xmlns"===t)return r;return r.push({name:"xmlns",value:i[s]}),r}protectAttribute(t,e){return"string"!=typeof t&&(t=String(t)),t=t.replace(/&/g,"&").replace(/"/g,"""),e&&(t=t.replace(/</g,"<").replace(/>/g,">")),t}protectHTML(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}}j.SELF_CLOSING={area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},j.PCDATA={option:!0,textarea:!0,fieldset:!0,title:!0,style:!0,script:!0},j.XMLNS={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML",html:"http://www.w3.org/1999/xhtml"};class z{constructor(){this.DOMParser=j,this.NodeList=k,this.HTMLCollection=k,this.HTMLElement=y,this.DocumentFragment=k,this.Document=g,this.document=new g(this)}}const P=MathJax._.util.Styles,D=(P.TRBL,P.WSC,P.Styles);var E=function(t,e,n,r){return new(n||(n=Promise))((function(s,i){function o(t){try{l(r.next(t))}catch(t){i(t)}}function a(t){try{l(r.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))};class I extends u{constructor(){super(),this.parser=new j,this.window=new z}parse(t,e){return this.parser.parseFromString(t,e,this)}create(t,e=null){return new y(t)}text(t){return new w(t)}comment(t){return new x(t)}createDocument(){return new g}head(t=this.document){return t.head}body(t=this.document){return t.body}root(t=this.document){return t.root}doctype(t=this.document){return t.type}tags(t,e,n=null,r=null){let s=[];const i=[];if(n)return i;let o=t;for(;o;){const t=o.kind;if("#text"!==t&&"#comment"!==t){if(t===e&&(i.push(o),i.length===r))return i;o.children.length&&(s=o.children.concat(s))}o=s.shift()}return i}elementById(t,e){let n=[],r=t;for(;r;){if("#text"!==r.kind&&"#comment"!==r.kind){if(r.attributes.id===e)return r;r.children.length&&(n=r.children.concat(n))}r=n.shift()}return null}elementsByClass(t,e,n=null){let r=[];const s=[];let i=t;for(;i;){if("#text"!==i.kind&&"#comment"!==i.kind){if((i.attributes.class||"").trim().split(/ +/).includes(e)&&(s.push(i),s.length===n))return s;i.children.length&&(r=i.children.concat(r))}i=r.shift()}return s}elementsByAttribute(t,e,n,r=null){let s=[];const i=[];let o=t;for(;o;){if("#text"!==o.kind&&"#comment"!==o.kind){if(o.attributes[e]===n&&(i.push(o),i.length===r))return i;o.children.length&&(s=o.children.concat(s))}o=s.shift()}return i}getElements(t,e){let n=[];const r=this.body(e);for(const e of t)if("string"==typeof e)if("#"===e.charAt(0)){const t=this.elementById(r,e.slice(1));t&&n.push(t)}else if("."===e.charAt(0))n=n.concat(this.elementsByClass(r,e.slice(1)));else if(e.match(/^[-a-z][-a-z0-9]*$/i))n=n.concat(this.tags(r,e));else{const t=e.match(/^\[(.*?)="(.*?)"\]$/);t&&(n=n.concat(this.elementsByAttribute(r,t[1],t[2])))}else Array.isArray(e)?n=n.concat(e):e instanceof this.window.NodeList||e instanceof this.window.HTMLCollection?n=n.concat(e.nodes):n.push(e);return n}getElement(t,e=this.document){if(e instanceof g&&(e=this.body(e)),"#"===t.charAt(0))return this.elementById(e,t.slice(1));if("."===t.charAt(0))return this.elementsByClass(e,t.slice(1),1)[0];if(t.match(/^[-a-z][-a-z0-9]*$/i))return this.tags(e,t,null,1)[0];const n=t.match(/^\[(.*?)="(.*?)"\]$/);return n?this.elementsByAttribute(e,n[1],n[2],1)[0]:null}contains(t,e){for(;e&&e!==t;)e=this.parent(e);return!!e}parent(t){return t.parent}childIndex(t){return t.parent?t.parent.children.findIndex((e=>e===t)):-1}append(t,e){return e.parent&&this.remove(e),t.children.push(e),e.parent=t,e}insert(t,e){if(t.parent&&this.remove(t),e&&e.parent){const n=this.childIndex(e);e.parent.children.splice(n,0,t),t.parent=e.parent}}remove(t){const e=this.childIndex(t);return e>=0&&t.parent.children.splice(e,1),t.parent=null,t}replace(t,e){const n=this.childIndex(e);return n>=0&&(e.parent.children[n]=t,t.parent=e.parent,e.parent=null),e}clone(t,e=!0){const n=new y(t.kind);return n.attributes=Object.assign({},t.attributes),n.children=e?t.children.map((t=>{if("#text"===t.kind)return new w(t.value);if("#comment"===t.kind)return new x(t.value);{const e=this.clone(t);return e.parent=n,e}})):[],n}split(t,e){const n=new w(t.value.slice(e));return t.value=t.value.slice(0,e),t.parent.children.splice(this.childIndex(t)+1,0,n),n.parent=t.parent,n}next(t){const e=t.parent;if(!e)return null;const n=this.childIndex(t)+1;return n>=0&&n<e.children.length?e.children[n]:null}previous(t){const e=t.parent;if(!e)return null;const n=this.childIndex(t)-1;return n>=0?e.children[n]:null}firstChild(t){return t.children[0]}lastChild(t){return t.children[t.children.length-1]}childNodes(t){return[...t.children]}childNode(t,e){return t.children[e]}kind(t){return t.kind}value(t){return"#text"===t.kind?t.value:"#comment"===t.kind?t.value.replace(/^<!(--)?((?:.|\n)*)\1>$/,"$2"):""}textContent(t){return t.children.reduce(((t,e)=>t+("#text"===e.kind?e.value:"#comment"===e.kind?"":this.textContent(e))),"")}innerHTML(t){return this.parser.serializeInner(this,t)}outerHTML(t){return this.parser.serialize(this,t)}serializeXML(t){return this.parser.serialize(this,t,!0)}setAttribute(t,e,n,r=null){"string"!=typeof n&&(n=String(n)),r&&(e=r.replace(/.*\//,"")+":"+e.replace(/^.*:/,"")),t.attributes[e]=n,"style"===e&&(t.styles=null)}getAttribute(t,e){return t.attributes[e]}removeAttribute(t,e){delete t.attributes[e]}hasAttribute(t,e){return Object.hasOwn(t.attributes,e)}allAttributes(t){const e=t.attributes,n=[];for(const t of Object.keys(e))n.push({name:t,value:e[t]});return n}addClass(t,e){const n=t.attributes.class,r=(null==n?void 0:n.split(/ /))||[];r.includes(e)||(r.push(e),t.attributes.class=r.join(" "))}removeClass(t,e){const n=t.attributes.class,r=(null==n?void 0:n.split(/ /))||[],s=r.indexOf(e);s>=0&&(r.splice(s,1),t.attributes.class=r.join(" "))}hasClass(t,e){return(t.attributes.class||"").split(/ /).includes(e)}setStyle(t,e,n){t.styles||(t.styles=new D(this.getAttribute(t,"style"))),t.styles.set(e,n),t.attributes.style=t.styles.cssText}getStyle(t,e){if(!t.styles){const e=this.getAttribute(t,"style");if(!e)return"";t.styles=new D(e)}return t.styles.get(e)}allStyles(t){return this.getAttribute(t,"style")}insertRules(t,e){t.children=[this.text(this.textContent(t)+"\n\n"+e.join("\n\n"))]}fontSize(t){return 0}fontFamily(t){return""}nodeSize(t,e=1,n=null){return[0,0]}nodeBBox(t){return{left:0,right:0,top:0,bottom:0}}createWorker(){return E(this,void 0,void 0,(function*(){return null}))}}class N extends(function(t,e={}){var n;return e=p(d({},b),e),n=class extends t{constructor(...t){super(t[0]),this.canMeasureNodes=!1;const e=this.constructor;this.options=p(d({},e.OPTIONS),t[1])}fontSize(t){return e.badCSS?this.options.fontSize:super.fontSize(t)}fontFamily(t){return e.badCSS?this.options.fontFamily:super.fontFamily(t)}nodeSize(t,r=1,s=null){if(!e.badSizes)return super.nodeSize(t,r,s);const i=this.textContent(t),o=Array.from(i.replace(n.cjkPattern,"")).length;return[(Array.from(i).length-o)*this.options.cjkCharWidth+o*this.options.unknownCharWidth,this.options.unknownCharHeight]}nodeBBox(t){return e.badSizes?{left:0,right:0,top:0,bottom:0}:super.nodeBBox(t)}createWorker(t,e){return f(this,void 0,void 0,(function*(){const{Worker:n}=yield m("node:worker_threads");const{path:r,maps:s}=e,i=`${r}/${e.worker}`,o=new class{constructor(t,e={}){this.worker=new n(t,e)}addEventListener(t,e){this.worker.on(t,e)}postMessage(t){this.worker.postMessage({data:t})}terminate(){this.worker.terminate()}}(i,{type:"module",workerData:{maps:s}});return o.addEventListener("message",t),o}))}},n.OPTIONS=Object.assign(Object.assign({},e.badCSS?{fontSize:16,fontFamily:"Times"}:{}),e.badSizes?{cjkCharWidth:1,unknownCharWidth:.6,unknownCharHeight:.8}:{}),n.cjkPattern=new RegExp(["[","\u1100-\u115f","\u2329\u232a","\u2e80-\u303e","\u3040-\u3247","\u3250-\u4dbf","\u4e00-\ua4c6","\ua960-\ua97c","\uac00-\ud7a3","\uf900-\ufaff","\ufe10-\ufe19","\ufe30-\ufe6b","\uff01-\uff60\uffe0-\uffe6","\u{1b000}-\u{1b001}","\u{1f200}-\u{1f251}","\u{20000}-\u{3fffd}","]"].join(""),"gu"),n}(I)){}function B(t=null){return new N(null,t)}MathJax.loader&&MathJax.loader.checkVersion("adaptors/liteDOM","4.0.0","adaptors"),c({_:{adaptors:{liteAdaptor:a,lite:{Document:n,Element:e,List:s,Parser:i,Text:r,Window:o}}}}),MathJax.startup&&(MathJax.startup.registerConstructor("liteAdaptor",B),MathJax.startup.useAdaptor("liteAdaptor",!0))})();