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 • 12.7 kB
JavaScript
(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})}};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,{EnrichHandler:()=>x,EnrichedMathDocumentMixin:()=>m,EnrichedMathItemMixin:()=>u,enrichVisitor:()=>d});var i={};t.r(i),t.d(i,{Collapse:()=>C});var s={};t.r(s),t.d(s,{ComplexityVisitor:()=>O});var o={};t.r(o),t.d(o,{ComplexityHandler:()=>T,ComplexityMathDocumentMixin:()=>k,ComplexityMathItemMixin:()=>P});const r=("undefined"!=typeof window?window:t.g).MathJax._.components.global,l=(r.GLOBAL,r.isObject,r.combineConfig,r.combineDefaults),c=r.combineWithMathJax,n=(r.MathJax,MathJax._.core.MathItem),a=(n.protoItem,n.AbstractMathItem,n.STATE),p=n.newState,h=MathJax._.a11y["semantic-enrich"],d=h.enrichVisitor,u=h.EnrichedMathItemMixin,m=h.EnrichedMathDocumentMixin,x=h.EnrichHandler,y=MathJax._.core.MmlTree.MmlVisitor,f=(y.DATAMJX,y.MmlVisitor);class C{constructor(t){this.cutoff={identifier:3,number:3,text:10,infixop:15,relseq:15,multirel:15,fenced:18,bigop:20,integral:20,fraction:12,sqrt:9,root:12,vector:15,matrix:15,cases:15,superscript:9,subscript:9,subsup:9,punctuated:{endpunct:C.NOCOLLAPSE,startpunct:C.NOCOLLAPSE,value:12}},this.marker={identifier:"x",number:"#",text:"...",appl:{"limit function":"lim",value:"f()"},fraction:"/",sqrt:"\u221a",root:"\u221a",superscript:"\u25fd\u02d9",subscript:"\u25fd.",subsup:"\u25fd:",vector:{binomial:"(:)",determinant:"|:|",value:"\u27e8:\u27e9"},matrix:{squarematrix:"[::]",rowvector:"\u27e8\u22ef\u27e9",columnvector:"\u27e8\u22ee\u27e9",determinant:"|::|",value:"(::)"},cases:"{:",infixop:{addition:"+",subtraction:"\u2212",multiplication:"\u22c5",implicit:"\u22c5",value:"+"},punctuated:{text:"...",value:","}},this.collapse=new Map([["fenced",(t,e)=>((e=this.uncollapseChild(e,t,1))>this.cutoff.fenced&&"leftright"===t.attributes.get("data-semantic-role")&&(e=this.recordCollapse(t,e,this.getText(t.childNodes[0])+this.getText(t.childNodes[t.childNodes.length-1]))),e)],["appl",(t,e)=>{if(this.canUncollapse(t,2,2)){e=this.complexity.visitNode(t,!1);const i=this.marker.appl,s=i[t.attributes.get("data-semantic-role")]||i.value;e=this.recordCollapse(t,e,s)}return e}],["sqrt",(t,e)=>((e=this.uncollapseChild(e,t,0))>this.cutoff.sqrt&&(t.setProperty("collapse-variant",!0),e=this.recordCollapse(t,e,this.marker.sqrt)),e)],["root",(t,e)=>((e=this.uncollapseChild(e,t,0,2))>this.cutoff.sqrt&&(t.setProperty("collapse-variant",!0),e=this.recordCollapse(t,e,this.marker.sqrt)),e)],["enclose",(t,e)=>{if(1===this.splitAttribute(t,"children").length){const i=this.canUncollapse(t,1);if(i){const s=i.getProperty("collapse-marker");this.unrecordCollapse(i),e=this.recordCollapse(t,this.complexity.visitNode(t,!1),s)}}return e}],["bigop",(t,e)=>{if(e>this.cutoff.bigop||!t.isKind("mo")){const i=this.splitAttribute(t,"content").pop(),s=this.findChildText(t,i);e=this.recordCollapse(t,e,s)}return e}],["integral",(t,e)=>{if(e>this.cutoff.integral||!t.isKind("mo")){const i=this.splitAttribute(t,"content").pop(),s=this.findChildText(t,i);e=this.recordCollapse(t,e,s)}return e}],["relseq",(t,e)=>{if(e>this.cutoff.relseq){const i=this.splitAttribute(t,"content")[0],s=this.findChildText(t,i);e=this.recordCollapse(t,e,s)}return e}],["multirel",(t,e)=>{if(e>this.cutoff.relseq){const i=this.splitAttribute(t,"content")[0],s=this.findChildText(t,i)+"\u22ef";e=this.recordCollapse(t,e,s)}return e}],["superscript",(t,e)=>((e=this.uncollapseChild(e,t,0,2))>this.cutoff.superscript&&(e=this.recordCollapse(t,e,this.marker.superscript)),e)],["subscript",(t,e)=>((e=this.uncollapseChild(e,t,0,2))>this.cutoff.subscript&&(e=this.recordCollapse(t,e,this.marker.subscript)),e)],["subsup",(t,e)=>((e=this.uncollapseChild(e,t,0,3))>this.cutoff.subsup&&(e=this.recordCollapse(t,e,this.marker.subsup)),e)]]),this.idCount=0,this.complexity=t}check(t,e){const i=t.attributes.get("data-semantic-type");return this.collapse.has(i)?this.collapse.get(i).call(this,t,e):Object.hasOwn(this.cutoff,i)?this.defaultCheck(t,e,i):e}defaultCheck(t,e,i){const s=t.attributes.get("data-semantic-role"),o=this.cutoff[i];if(e>("number"==typeof o?o:o[s]||o.value)){const o=this.marker[i]||"??",r="string"==typeof o?o:o[s]||o.value;e=this.recordCollapse(t,e,r)}return e}recordCollapse(t,e,i){return i="\u25c2"+i+"\u25b8",t.setProperty("collapse-marker",i),t.setProperty("collapse-complexity",e),i.length*this.complexity.complexity.text}unrecordCollapse(t){const e=t.getProperty("collapse-complexity");null!=e&&(t.attributes.set("data-semantic-complexity",e),t.removeProperty("collapse-complexity"),t.removeProperty("collapse-marker"))}canUncollapse(t,e,i=1){if(this.splitAttribute(t,"children").length===i){const i=1===t.childNodes.length&&t.childNodes[0].isInferred?t.childNodes[0]:t;if(i&&i.childNodes[e]){const t=i.childNodes[e];if(t.getProperty("collapse-marker"))return t}}return null}uncollapseChild(t,e,i,s=1){const o=this.canUncollapse(e,i,s);return o&&(this.unrecordCollapse(o),o.parent!==e&&o.parent.attributes.set("data-semantic-complexity",void 0),t=this.complexity.visitNode(e,!1)),t}splitAttribute(t,e){return(t.attributes.get("data-semantic-"+e)||"").split(/,/)}getText(t){return t.isToken?t.getText():t.childNodes.map((t=>this.getText(t))).join("")}findChildText(t,e){const i=this.findChild(t,e);return this.getText(i.coreMO()||i)}findChild(t,e){if(!t||t.attributes.get("data-semantic-id")===e)return t;if(!t.isToken)for(const i of t.childNodes){const t=this.findChild(i,e);if(t)return t}return null}makeCollapse(t,e){let i=null;null===e?e=this.idCount:(i=this.idCount,this.idCount=e);const s=[];return t.walkTree((t=>{t.getProperty("collapse-marker")&&s.push(t)})),this.makeActions(s),null!==i&&(this.idCount=i),e}makeActions(t){for(const e of t)this.makeAction(e)}makeId(){return"mjx-collapse-"+this.idCount++}makeAction(t){t.isKind("math")&&(t=this.addMrow(t));const e=this.complexity.factory,i=t.getProperty("collapse-marker"),s=t.parent,o={"data-mjx-collapsed":!0};t.getProperty("collapse-variant")&&(o.mathvariant="-tex-variant");const r=e.create("maction",{actiontype:"toggle",selection:2,"data-collapsible":!0,id:this.makeId(),"data-semantic-complexity":t.attributes.get("data-semantic-complexity")},[e.create("mtext",o,[e.create("text").setText(i)])]);r.inheritAttributesFrom(t),t.attributes.set("data-semantic-complexity",t.getProperty("collapse-complexity")),t.removeProperty("collapse-marker"),t.removeProperty("collapse-complexity"),s.replaceChild(r,t),r.appendChild(t)}addMrow(t){const e=this.complexity.factory.create("mrow",null,t.childNodes[0].childNodes);t.childNodes[0].setChildren([e]);const i=t.attributes.getAllAttributes();for(const t of Object.keys(i))"data-semantic-"!==t.substring(0,14)&&"data-speech-"!==t.substring(0,12)&&"aria-"!==t.substring(0,5)&&"role"!==t||(e.attributes.set(t,i[t]),delete i[t]);return e.setProperty("collapse-marker",t.getProperty("collapse-marker")),e.setProperty("collapse-complexity",t.getProperty("collapse-complexity")),t.removeProperty("collapse-marker"),t.removeProperty("collapse-complexity"),e}}C.NOCOLLAPSE=1e7;const b=MathJax._.util.Options,g=(b.isObject,b.APPEND,b.REMOVE,b.OPTIONS,b.Expandable,b.expandable),v=(b.makeArray,b.keys,b.copy,b.insert,b.defaultOptions),M=b.userOptions,N=(b.selectOptions,b.selectOptionsFromKeys);b.separateOptions,b.lookup;class O extends f{constructor(t,e){super(t),this.complexity={text:.5,token:.5,child:1,script:.8,sqrt:2,subsup:2,underover:2,fraction:2,enclose:2,action:2,phantom:0,xml:2,glyph:2};const i=this.constructor;this.options=M(v({},i.OPTIONS),e),this.collapse=new this.options.Collapse(this),this.factory=t}visitTree(t,e){return super.visitTree(t,!0),this.options.makeCollapsible&&(e=this.collapse.makeCollapse(t,e)),e}visitNode(t,e){if(!t.attributes.get("data-semantic-complexity"))return super.visitNode(t,e)}visitDefault(t,e){let i;if(t.isToken){const e=t.getText();i=this.complexity.text*e.length+this.complexity.token}else i=this.childrenComplexity(t);return this.setComplexity(t,i,e)}visitMfracNode(t,e){const i=this.childrenComplexity(t)*this.complexity.script+this.complexity.fraction;return this.setComplexity(t,i,e)}visitMsqrtNode(t,e){const i=this.childrenComplexity(t)+this.complexity.sqrt;return this.setComplexity(t,i,e)}visitMrootNode(t,e){const i=this.childrenComplexity(t)+this.complexity.sqrt-(1-this.complexity.script)*this.getComplexity(t.childNodes[1]);return this.setComplexity(t,i,e)}visitMphantomNode(t,e){return this.setComplexity(t,this.complexity.phantom,e)}visitMsNode(t,e){const i=(t.attributes.get("lquote")+t.getText()+t.attributes.get("rquote")).length*this.complexity.text;return this.setComplexity(t,i,e)}visitMsubsupNode(t,e){super.visitDefault(t,!0);const i=t.childNodes[t.sub],s=t.childNodes[t.sup],o=t.childNodes[t.base];let r=Math.max(i?this.getComplexity(i):0,s?this.getComplexity(s):0)*this.complexity.script;return r+=this.complexity.child*((i?1:0)+(s?1:0)),r+=o?this.getComplexity(o)+this.complexity.child:0,r+=this.complexity.subsup,this.setComplexity(t,r,e)}visitMsubNode(t,e){return this.visitMsubsupNode(t,e)}visitMsupNode(t,e){return this.visitMsubsupNode(t,e)}visitMunderoverNode(t,e){super.visitDefault(t,!0);const i=t.childNodes[t.under],s=t.childNodes[t.over],o=t.childNodes[t.base];let r=Math.max(i?this.getComplexity(i):0,s?this.getComplexity(s):0)*this.complexity.script;return o&&(r=Math.max(this.getComplexity(o),r)),r+=this.complexity.child*((i?1:0)+(s?1:0)+(o?1:0)),r+=this.complexity.underover,this.setComplexity(t,r,e)}visitMunderNode(t,e){return this.visitMunderoverNode(t,e)}visitMoverNode(t,e){return this.visitMunderoverNode(t,e)}visitMencloseNode(t,e){const i=this.childrenComplexity(t)+this.complexity.enclose;return this.setComplexity(t,i,e)}visitMactionNode(t,e){this.childrenComplexity(t);const i=this.getComplexity(t.selected);return this.setComplexity(t,i,e)}visitMsemanticsNode(t,e){const i=t.childNodes[0];let s=0;return i&&(this.visitNode(i,!0),s=this.getComplexity(i)),this.setComplexity(t,s,e)}visitAnnotationNode(t,e){return this.setComplexity(t,this.complexity.xml,e)}visitAnnotation_xmlNode(t,e){return this.setComplexity(t,this.complexity.xml,e)}visitMglyphNode(t,e){return this.setComplexity(t,this.complexity.glyph,e)}getComplexity(t){const e=t.getProperty("collapsedComplexity");return null!=e?e:t.attributes.get("data-semantic-complexity")}setComplexity(t,e,i){return i&&(this.options.identifyCollapsible&&(e=this.collapse.check(t,e)),t.attributes.set("data-semantic-complexity",e)),e}childrenComplexity(t){super.visitDefault(t,!0);let e=0;for(const i of t.childNodes)e+=this.getComplexity(i);return t.childNodes.length>1&&(e+=t.childNodes.length*this.complexity.child),e}}function P(t,e){return class extends t{constructor(){super(...arguments),this.initialID=null}complexity(t,i=!1){this.state()>=a.COMPLEXITY||(this.isEscaped||!t.options.enableComplexity&&!i||(this.enrich(t,!0),e(this)),this.state(a.COMPLEXITY))}}}function k(t){var e;return(e=class extends t{constructor(...t){super(...t);const e=this.constructor.ProcessBits;e.has("complexity")||e.allocate("complexity");const i=N(this.options,this.options.ComplexityVisitor.OPTIONS);this.complexityVisitor=new this.options.ComplexityVisitor(this.mmlFactory,i);this.options.MathItem=P(this.options.MathItem,(t=>{t.initialID=this.complexityVisitor.visitTree(t.root,t.initialID)}))}complexity(){if(!this.processed.isSet("complexity")){if(this.options.enableComplexity)for(const t of this.math)t.complexity(this);this.processed.set("complexity")}return this}state(t,e=!1){return super.state(t,e),t<a.COMPLEXITY&&this.processed.clear("complexity"),this}}).OPTIONS=Object.assign(Object.assign(Object.assign({},t.OPTIONS),O.OPTIONS),{enableComplexity:!0,ComplexityVisitor:O,renderActions:g(Object.assign(Object.assign({},t.OPTIONS.renderActions),{complexity:[a.COMPLEXITY]}))}),e}function T(t,e=null){return!t.documentClass.prototype.enrich&&e&&(t=x(t,e)),t.documentClass=k(t.documentClass),t}O.OPTIONS={identifyCollapsible:!0,makeCollapsible:!0,Collapse:C},p("COMPLEXITY",40),MathJax.loader&&MathJax.loader.checkVersion("a11y/complexity","4.1.0","a11y"),c({_:{a11y:{complexity_ts:o,complexity:{collapse:i,visitor:s},"semantic-enrich":e}}}),MathJax.startup&&(MathJax.startup.extendHandler((t=>T(t))),l(MathJax.config,"options",MathJax.config["a11y/complexity"]||{}))})();