globalThis.document;const t=1,e=2,a=3,n=4,s=5;let i,h,o=[],l=t,r="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js";function flush_typesets(){if(!o.length)return;const t=[],e=[];o.forEach((function(a){const n=globalThis.document.createElement("script"),s=globalThis.document.createElement("div");n.type=a[1]?"math/tex; mode=display":"math/tex",n.text=a[0],s.style.position="fixed",s.style.top=0,s.style.left="99999px",s.appendChild(n),globalThis.document.body.appendChild(s),t.push(n),e.push([s,a[2]])})),o=[],l=n,i.Queue(["Typeset",i,t]),i.Queue((function(){h||function getStyleNode(){const t=globalThis.document.querySelectorAll("style"),e=Array.prototype.filter.call(t,(function(t){return t.sheet&&t.sheet.cssRules.length>100&&".mjx-chtml"===t.sheet.cssRules[0].selectorText}));h=e[0]}(),e.forEach((function(t){const e=t[0],a="SPAN"===e.firstElementChild.tagName?e.firstElementChild:null;t[1](a,h),globalThis.document.body.removeChild(e)})),l=a,flush_typesets()}))}function load_library(){l=e,globalThis.MathJax={skipStartupTypeset:!0,showMathMenu:!1,jax:["input/TeX","output/CommonHTML"],TeX:{extensions:["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]},AuthorInit(){i=globalThis.MathJax.Hub,i.Register.StartupHook("End",(function(){l=a,flush_typesets()}))}};var t=globalThis.document.createElement("script");t.type="text/javascript",t.src=r,t.async=!0,t.onerror=function(){console.warn("Error loading MathJax library "+r),l=s,o=[]},globalThis.document.head.appendChild(t)}class LrnMathController extends HTMLElement{connectedCallback(){this.hasAttribute("src")&&(r=this.getAttribute("src")),this.hasAttribute("lazy")||load_library()}typeset(e,n,i){l!==s&&(o.push([e,n,i]),l===t?load_library():l===a&&flush_typesets())}}const c="lrn-math-controller",d={childList:!0,characterData:!0,attributes:!0,subtree:!0};let u;class LrnMath extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._private={check:"",observer:new MutationObserver((()=>{this.updateMath()}))},this._private.observer.observe(this,d)}static get tag(){return"lrn-math"}haxHooks(){return{editModeChanged:"haxeditModeChanged",activeElementChanged:"haxactiveElementChanged"}}haxactiveElementChanged(t,e){e&&(this._haxstate=e)}haxeditModeChanged(t){this._haxstate=t}connectedCallback(){!function check_handler(t){u||(u=globalThis.document.querySelector(c)||globalThis.document.createElement(c),!globalThis.document.contains(u)&&globalThis.document&&globalThis.document.head&&globalThis.document.head.appendChild(u),setTimeout((()=>{t.refresh()}),0))}(this),setTimeout((()=>{this._haxstate&&this.innerHTML?this.mathtext=this.innerHTML:this.updateMath()}),0)}updateMath(){const t=this.shadowRoot,e=this.textContent.trim(),a="display"===this.getAttribute("mode"),n=(a?"D":"I")+e;this._private&&n!==this._private.check&&(this.shadowRoot.innerHTML="",this._private.check=n,e.length&&u&&u.typeset(e,a,(function(e,a){t.appendChild(a.cloneNode(!0)),t.appendChild(e)})))}get mathtext(){return this.getAttribute("mathtext")}set mathtext(t){this.setAttribute("mathtext",t)}static get observedAttributes(){return["mathtext"]}attributeChangedCallback(t,e,a){if("mathtext"===t)""!==a&&null!==a?(clearTimeout(this._typingTimeout),this._typingTimeout=setTimeout((()=>{const t=globalThis.document.createElement("span");t.innerText=a,this.innerHTML="",this.appendChild(t)}),300)):this.updateMath()}static get haxProperties(){return{canScale:!1,canEditSource:!0,gizmo:{title:"Math",description:"Present math in a nice looking way.",icon:"hax:pi",color:"grey",tags:["Instructional","math","mathjax","mathml","latex","mathml"],handles:[{type:"math",math:"mathText"},{type:"inline",text:"mathText"}],meta:{author:"HAXTheWeb core team",inlineOnly:!0}},settings:{inline:[],configure:[{property:"mathtext",title:"Math",description:"Enter equation as MathML",inputMethod:"textarea"}],advanced:[]}}}refresh(){let t=globalThis.document.createElement("lrn-math");this.parentNode.insertBefore(t,this),t.innerHTML=this.innerHTML,this.remove()}}customElements.define("lrn-math",LrnMath);export{LrnMath};customElements.define("lrn-math-controller",LrnMathController);export{LrnMathController};