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 • 6.52 kB
JavaScript
(()=>{"use strict";var t={d:(e,s)=>{for(var a in s)t.o(s,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:s[a]})}};t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),t.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),t.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var e={};t.r(e),t.d(e,{LAZYID:()=>c,LazyHandler:()=>d,LazyList:()=>h,LazyMathDocumentMixin:()=>z,LazyMathItemMixin:()=>u});const s=("undefined"!=typeof window?window:t.g).MathJax._.components.global,a=(s.GLOBAL,s.isObject,s.combineConfig,s.combineDefaults,s.combineWithMathJax),i=(s.MathJax,MathJax._.core.MathItem),r=(i.protoItem,i.AbstractMathItem,i.STATE),n=i.newState,l=MathJax._.util.Retries,o=l.handleRetriesFor;l.retryAfter;var y=function(t,e,s,a){return new(s||(s=Promise))((function(i,r){function n(t){try{o(a.next(t))}catch(t){r(t)}}function l(t){try{o(a.throw(t))}catch(t){r(t)}}function o(t){var e;t.done?i(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(n,l)}o((a=a.apply(t,e||[])).next())}))};class h{constructor(){this.id=0,this.items=new Map}add(t){const e=String(this.id++);return this.items.set(e,t),e}get(t){return this.items.get(t)}delete(t){return this.items.delete(t)}}n("LAZYALWAYS",r.FINDMATH+3);const c="data-mjx-lazy";function u(t){return class extends t{constructor(...t){super(...t),this.lazyCompile=!0,this.lazyTypeset=!0,this.lazyTex=!1,this.attachSpeech=t=>{var e;this.state()>=r.ATTACHSPEECH||(this.lazyTypeset||null===(e=super.attachSpeech)||void 0===e||e.call(this,t),this.state(r.ATTACHSPEECH))},this.end.node||(this.lazyCompile=this.lazyTypeset=!1)}compile(t){this.lazyCompile?this.state()<r.COMPILED&&(this.lazyTex="TeX"===this.inputJax.name,this.root=t.mmlFactory.create("math"),this.state(r.COMPILED)):super.compile(t)}state(t=null,e=!1){return null!==e&&super.state(t,e),super.state()}typeset(t){if(this.lazyTypeset){if(this.state()<r.TYPESET){const e=t.adaptor;if(!this.lazyMarker){const s=t.lazyList.add(this);this.lazyMarker=e.node("mjx-lazy",{[c]:s}),this.typesetRoot=e.node("mjx-container",{},[this.lazyMarker])}this.state(r.TYPESET)}}else super.typeset(t)}updateDocument(t){super.updateDocument(t),this.lazyTypeset&&t.lazyObserver.observe(this.lazyMarker)}}}function z(t){var e;return(e=class extends t{constructor(...t){super(...t),this.lazyAlwaysContainers=null,this.lazyAlwaysIndex=0,this.lazyPromise=Promise.resolve(),this.lazyIdle=!1,this.lazySet=new Set,this.options.MathItem=u(this.options.MathItem);const e=this.constructor.ProcessBits;e.has("lazyAlways")||e.allocate("lazyAlways"),this.lazyObserver=new IntersectionObserver(this.lazyObserve.bind(this),{rootMargin:this.options.lazyMargin}),this.lazyList=new h;const s=this.lazyHandleSet.bind(this);if(this.lazyProcessSet=window&&window.requestIdleCallback?()=>window.requestIdleCallback(s):()=>setTimeout(s,10),window){let t=!1;const e=()=>{t||this.lazyTypesetAll(),t=!0};window.matchMedia("print").addListener(e),window.addEventListener("beforeprint",e)}}lazyAlways(){if(this.lazyAlwaysContainers&&!this.processed.isSet("lazyAlways")){for(const t of this.math){const e=t;e.lazyTypeset&&this.lazyIsAlways(e)&&(e.lazyCompile=e.lazyTypeset=!1)}this.processed.set("lazyAlways")}}lazyIsAlways(t){if(t.state()<r.LAZYALWAYS){t.state(r.LAZYALWAYS);const e=t.start.node,s=this.adaptor,a=this.lazyAlwaysIndex,i=this.lazyAlwaysContainers.length;do{const t=this.lazyAlwaysContainers[this.lazyAlwaysIndex];if(s.contains(t,e))return!0;++this.lazyAlwaysIndex>=i&&(this.lazyAlwaysIndex=0)}while(this.lazyAlwaysIndex!==a)}return!1}state(t,e=!1){return super.state(t,e),t<r.LAZYALWAYS&&this.processed.clear("lazyAlways"),this}lazyTypesetAll(){return y(this,void 0,void 0,(function*(){let t=r.LAST;for(const e of this.math){const s=e;(s.lazyCompile||s.lazyTypeset)&&(s.lazyCompile?(s.state(r.COMPILED-1),t=r.COMPILED):(s.state(r.TYPESET-1),r.TYPESET<t&&(t=r.TYPESET)),s.lazyCompile=s.lazyTypeset=!1,s.lazyMarker&&this.lazyObserver.unobserve(s.lazyMarker))}if(t===r.LAST)return Promise.resolve();this.state(t-1,null);const e=this.outputJax.options.fontCache;return e&&(this.outputJax.options.fontCache="none"),this.reset(),o((()=>this.render())).then((()=>{e&&(this.outputJax.options.fontCache=e)}))}))}lazyObserve(t){for(const e of t){const t=this.adaptor.getAttribute(e.target,c);this.lazyList.get(t)&&(e.isIntersecting?(this.lazySet.add(t),this.lazyIdle||(this.lazyIdle=!0,this.lazyProcessSet())):this.lazySet.delete(t))}}lazyHandleSet(){const t=this.lazySet;this.lazySet=new Set,this.lazyPromise=this.lazyPromise.then((()=>{let e=this.compileEarlierItems(t)?r.COMPILED:r.TYPESET;return e=this.resetStates(t,e),this.state(e-1,null),o((()=>{this.render(),this.lazyIdle=!1}))}))}resetStates(t,e){for(const s of t.values()){const t=this.lazyList.get(s);t.lazyCompile?(t.state(r.COMPILED-1),e=r.COMPILED):Object.hasOwn(t.metrics,"em")?t.state(r.TYPESET-1):(t.state(r.METRICS-1),e=r.METRICS),t.lazyCompile=t.lazyTypeset=!1,t.lazyMarker&&this.lazyObserver.unobserve(t.lazyMarker)}return e}compileEarlierItems(t){const e=this.earliestTex(t);if(!e)return!1;let s=!1;for(const t of this.math){const a=t;if(a===e||!(null==a?void 0:a.lazyCompile)||!a.lazyTex)break;a.lazyCompile=!1,a.lazyMarker&&this.lazyObserver.unobserve(a.lazyMarker),a.state(r.COMPILED-1),s=!0}return s}earliestTex(t){let e=null,s=null;for(const a of t.values()){const t=this.lazyList.get(a);t.lazyTex&&((null===e||parseInt(a)<e)&&(e=parseInt(a),s=t))}return s}clearMathItemsWithin(t){const e=super.clearMathItemsWithin(t);for(const t of e){const e=t.lazyMarker;e&&(this.lazyObserver.unobserve(e),this.lazyList.delete(this.adaptor.getAttribute(e,c)))}return e}render(){const t=this.options.lazyAlwaysTypeset;return this.lazyAlwaysContainers=t?this.adaptor.getElements(Array.isArray(t)?t:[t],this.document):null,this.lazyAlwaysIndex=0,super.render(),this}}).OPTIONS=Object.assign(Object.assign({},t.OPTIONS),{lazyMargin:"500px",lazyAlwaysTypeset:null,renderActions:Object.assign(Object.assign({},t.OPTIONS.renderActions),{lazyAlways:[r.LAZYALWAYS,"lazyAlways","",!1]})}),e}function d(t){return"undefined"!=typeof IntersectionObserver&&(t.documentClass=z(t.documentClass)),t}MathJax.loader&&MathJax.loader.checkVersion("ui/lazy","4.1.0","ui"),a({_:{ui:{lazy:{LazyHandler:e}}}}),MathJax.startup&&MathJax.startup.extendHandler((t=>d(t)))})();