@mathzetta/inlinemath 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,6 +90,15 @@ span.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-
90
90
  .mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }
91
91
  .mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }
92
92
  .mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }
93
+ /* around one line: inline, placed from the baseline like a typed bracket (0.25em below it, 0.75em above),
94
+ not stretched over the line box, which sits higher or lower in every font; the margins keep the widths */
95
+ .mv-fence-line > .mv-delim { position: static; display: inline-block; vertical-align: -0.25em; height: 1em; }
96
+ .mv-fence-line > svg.mv-delim-l { margin: 0 0.07em 0 0.03em; }
97
+ .mv-fence-line > svg.mv-delim-r { margin: 0 0.03em 0 0.07em; }
98
+ .mv-fence-line > span.mv-delim-l { margin: 0 0.08em 0 0.06em; }
99
+ .mv-fence-line > span.mv-delim-r { margin: 0 0.06em 0 0.08em; }
100
+ .mv-fence-line > .mv-delim.mv-vert.mv-delim-l { margin: 0 0.11em 0 0.07em; }
101
+ .mv-fence-line > .mv-delim.mv-vert.mv-delim-r { margin: 0 0.07em 0 0.11em; }
93
102
 
94
103
  /* ---- shapes ----------------------------------------------------------------- */
95
104
  .mv svg { overflow: visible; }
@@ -1,2 +1,2 @@
1
- /* Inline Math 0.4.0 — MIT license; MathZetta not included: load a MathZetta <script> (mathzetta.min.js or mathzetta.maths-display.min.js) first */
2
- var InlineMath=function(e,t,n,i,s){"use strict";const r={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function o(e,t,n=""){const i=r[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${i.fill?`<path d="${i.fill}" fill="currentColor"/>`:`<path d="${i.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const a=.8,l=.2,c=.25,h=.7,d="−",m={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","\\implies":"implies","\\iff":"iff","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},u={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},p={"±":"±","∪":"∪","∩":"∩",mod:"mod"},f=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],g={arcsin:"sin",arccos:"cos",arctan:"tan",arcsec:"sec",arccsc:"csc",arccot:"cot",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},v=[...f,...Object.keys(g),"ln","det"],b={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},y={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},x=["int","lim","\\sumidx","\\prodidx"],$={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},w={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},k=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,L=e=>"symbol"===e?.type&&k.test(n.GREEK[e.value]??e.value),M=["boxed","overline","bar","underline","cancel",...Object.keys(w)],E={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},S=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),A=e=>+e.toFixed(3)+"em",O=(e,t=a,n=l)=>({html:e,h:t,d:n});function C(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(a,...t.map(e=>e.h)),d:Math.max(l,...t.map(e=>e.d))}}function z(e,t={}){const n=new j({...E,...t}),s=n.render(e,{level:0}),r=`${n.p}${n.o.display?` ${n.p}-display`:""}`,o="function"==typeof n.o.mathml?function(e,t,n,i){try{return String(e(t)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${i?' display="block"':""}>`)}catch{return""}}(n.o.mathml,e,n.p,n.o.display):"",a=o?null:function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):i.toAudioSpeech(e)}catch{return null}}(e,n.o.label),l=null!==a||o?s.html.replace(/^<span /,'<span aria-hidden="true" '):s.html;return{html:`<span class="${r}"${null===a?"":` role="math" aria-label="${S(a)}"`}>${l}${o}</span>`,h:s.h,d:s.d}}class j{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",i=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${i}>${t}</span>`}text(e,t){const n=O(this.el(e,S(t)));return n.leaf={kind:e,content:S(t)},n}bin(e){return this.text("bin",e)}rel(e){return this.text("rel",e)}punct(e){return this.text("punct",e)}word(e){return this.text("word",e)}wrap(e,t,n){let i="";void 0!==e.id&&(i+=` data-node="${e.id}"`),"op"===e.type&&(i+=` data-op="${S(e.op)}"`);const s=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(s))"class"!==e&&"style"!==e&&/^[A-Za-z_:][\w:.-]*$/.test(e)&&(i+=` ${e}="${S(t)}"`);const r=[s.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),o=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(s.class?[S(s.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${r?` style="${S(r)}"`:""}${i}>${a}</span>`,h:n.h,d:n.d}}render(e,t){return"number"===e.type?this.number(e):"string"===e.type?this.wrap(e,["text"],this.text("text",e.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===e.type?this.wrap(e,["symbol"],this.symbol(e.value)):this.operation(e,t)}number(e){const t=/^(-?\d*\.)(\d*)\.\.$/.exec(e.value);if(t){const[,n,i]=t;let s=1;for(let e=1;2*e<=i.length;e++)if(i.slice(-e)===i.slice(-2*e,-e)){s=e;break}let r=i;for(;r.endsWith(i.slice(-s))&&r.length>=s;)r=r.slice(0,-s);const o=this.text("num",(n+r).replace(/^-/,d)),a=this.text("num",i.slice(-s));return this.wrap(e,["number"],C(o,O(this.el("over",a.html),a.h+.14,a.d)))}return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,d)))}symbol(e){return n.GREEK[e]&&(e=n.GREEK[e]),$[e]?this.text("ord",$[e]):"\\+"===e||"\\-"===e?this.text("ord",e[1]):"-∞"===e?this.text("ord","−∞"):/^[A-Za-z]$/.test(e)||/^[α-ω]$/.test(e)?this.text("var",e):/^[A-Za-z]′+$/.test(e)?O(this.el("var",S(e[0]))+this.el("prime",S(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?O(this.el("ord","Δ")+this.el("var",e[1])):/^d[A-Za-zα-ω]$/.test(e)?O(this.el("ord","d")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:i,args:s}=e,[r,o]=s,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1,leftFactor:!1}),l=m[i]??(/^[a-z0-9]+$/i.test(i)?i:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,i)=>n.needsBrackets(e,t,i)&&"/"!==t.op?this.fence(a(t)):a(t);if(v.includes(i)||"log"===i)return c(this.named(e,t));if(b[i])return c(C(this.word(b[i]),this.fence(this.list(s,t))));if(n.isCustomFunction(i))return c(this.custom(e,t));const f=n.matrixRows(e);if(f)return c(this.matrix(e,f,t));if("{}"===i&&!s.length)return c(this.text("op","∅"));if(y[i])return c(this.fence(this.list(s,t),...y[i]));if(("|"===i||"&"===i)&&s.length>=2&&s.every(N)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===i?a(e):this.fence(a(e));return c(C(s.map((t,n)=>n?[this.text("conj","|"===i?"or":"and"),e(t)]:[e(t)]).flat()))}if(u[i]&&2===s.length)return c(C(h(r,"left"),this.rel(u[i]),h(o,"right")));if(p[i]&&2===s.length)return c(C(h(r,"left"),this.bin(p[i]),h(o,"right")));switch(i){case"+":if(n.isMinusOneTimes(o)){const e=o.args[1],t=n.needsBrackets({op:"-"},e,"right")?this.fence(a(e)):a(e);return c(C(h(r,"left"),this.bin(d),this.wrap(o,["op","op-mul"],t)))}return"number"===o.type&&o.value.startsWith("-")?c(C(h(r,"left"),this.bin(d),this.wrap(o,["number"],this.text("num",o.value.slice(1))))):c(C(h(r,"left"),this.bin("+"),this.signed(o,h(o,"right"))));case"-":return c(C(h(r,"left"),this.bin(d),this.signed(o,h(o,"right"))));case"*":return c(this.product(e,t));case"/":return c(this.fraction(e,t));case"^":return c(this.power(e,t));case"_":{const e=n.bracketOp(r)&&n.precedenceOf(n.bracketOp(r))<100;return c(this.script(e?this.fence(a(r)):a(r,{forceParens:!0}),null,t,a(o,{level:t.level+1})))}case"neg":return c(C(this.text("sign",d),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r,{before:t.before})));case"pm":return c(C(this.text("sign","±"),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r)));case"!":return c(C(n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(C(this.text("sign","¬"),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r)));case"pmod":return c(C(a(r),this.fence(C(this.word("mod"),this.text("space",""),a(o)))));case"sqrt":return c(this.radical(a(r)));case"root":return c(this.radical(a(o),this.render(r,{level:t.level+2})));case"abs":return c(this.fence(a(r),"|","|"));case"floor":return c(this.fence(a(r),"⌊","⌋"));case"ceil":return c(this.fence(a(r),"⌈","⌉"));case"loglog":return c(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(a(r))))));case"logloglog":return c(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(a(r))))))));case"perm":return c(this.script(this.script(O(""),this.render(r,{level:t.level+1}),t),null,t,this.render(o,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(r),a(o),!1)));case"?:":return c(this.o.cases?this.cases(e,t):C(a(r),this.bin("?"),a(o),this.bin(":"),a(s[2])));case"sum":case"prod":{const e={op:"sum"===i?"+":"*"},t=(t,i)=>n.needsBrackets(e,t,i?"right":"left")?this.fence(a(t)):a(t);return c(C(s.map((e,n)=>n?[this.bin("sum"===i?"+":"·"),t(e,n)]:[t(e,n)]).flat()))}case"setbuilder":return c(this.fence(C(a(r),this.bin("|"),a(o)),"{","}"));case"evaluated":{const e=e=>this.render(e,{...t,level:t.level+1});return c(this.script(this.fence(a(r),"[","]"),e(s[3]),t,e(s[2])))}case"der":return c(this.derivative(e,t));case"int":return c(this.integral(s,t));case"lim":return c(this.limit(s,t));case"\\sumidx":return c(this.bigOperator("sum",s,t));case"\\prodidx":return c(this.bigOperator("prod",s,t))}throw new Error(`Inline Math cannot draw '${i}'`)}signed(e,t){return("number"===e.type?e.value.startsWith("-"):"neg"===e.op||"pm"===e.op)&&!t.fenced?this.fence(t):t}list(e,t){return C(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[i,s]=e.args;if(n.isMinusOneTimes(e))return C(this.text("sign",d),n.unaryNeedsBrackets("neg",s)?this.fence(this.render(s,t)):this.render(s,t));const r=n.bracketedSides(e);x.includes(i.op)&&(r.left=!0);const o=!e.written&&n.isImplicitProduct(i,s,r),a=function(e){for(;"op"===e.type;){if(v.includes(e.op)||"log"===e.op||b[e.op]||n.isCustomFunction(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(s),l=r.left?this.fence(this.render(i,t)):this.render(i,{...t,before:o&&!a,leftFactor:!0}),c=r.right?this.fence(this.render(s,t)):this.render(s,{...t,before:t.before});return C(l,o?O(this.el(a?"fnspace":"times","")):this.bin("cross"===e.written?"×":"·"),c)}named(e,t,n=null){const{op:i,args:s}=e,r="log"===i?s[1]:s[0];let o;o=g[i]&&"power"===this.o.inverseTrig?this.script(this.word(g[i]),this.text("num","−1"),t):this.word(i),n&&(o=this.script(o,n,t)),"log"===i&&(o=this.script(o,null,t,this.render(s[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&_(r),l=this.render(r,{...t,forceParens:!1,before:!1});return C(o,a?C(O(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const i=n.customName(e.op),s=e.args;if(M.includes(i)&&1===s.length)return this.decorate(i,this.render(s[0],t),s[0]);return C(/^[A-Za-z]′*(⁻¹)?$/.test(i)?this.symbol(i):this.word(i),O(this.el("callgap","")),this.fence(this.list(s,t)))}decorate(e,t,n){switch(e){case"boxed":return O(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return O(this.el("cancel",t.html+o("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return O(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return O(this.el("over"+(L(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const i=L(n);return O(this.el("accent"+(i?" accent-low":""),this.el(`accent-mark accent-${e}`,w[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[i,s]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&_(i,!0)&&_(s,!0)){const e={...t,leftFactor:!1},r=(t,i)=>"op"!==t.type||_(t)&&(!i||"*"!==t.op||n.isMinusOneTimes(t))?this.render(t,e):this.fence(this.render(t,e)),o=C("op"===i.type&&"neg"===i.op?this.render(i,e):r(i,!1),this.text("ord","/"),r(s,!0));return t.leftFactor?this.fence(o):o}const r=t.level>0||t.inFraction||!this.o.display?.8:1,o={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(i,o),this.render(s,o),!0,r)}stack(e,t,n=!0,i=1){const s=e=>1===i?e.html:this.el("scaled",e.html,`font-size:${A(i)}`),r=n?.06:0,o=c+r/2+.1+Math.max(l,i*e.d),h=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",s(e))+this.el("denom",s(t)),`vertical-align:${A(o)}`);return O(h,o+Math.max(a,i*e.h),Math.max(a,i*t.h)+Math.max(l,i*t.d)+.1+r/2-c)}power(e,t){const[i,s]=e.args,r={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},o=()=>this.render(s,r);if(this.o.trigPowers&&f.includes(i.op)&&q(s))return this.wrap(i,["op",`op-${i.op}`],this.named(i,t,o()));if("_"===i.op){const e=this.render(i.args[1],r);return this.wrap(i,["op","op-subscript"],this.script(this.render(i.args[0],{...t,forceParens:!0}),o(),t,e))}const a=n.needsBrackets(e,i,"left")||"number"===i.type&&i.value.startsWith("-")||"/"===i.op||v.includes(i.op)||x.includes(i.op)?this.fence(this.render(i,t)):this.render(i,{...t,forceParens:!0});return this.script(a,o(),t)}script(e,t,n,i=null,s=null){const r=n.level>0?.8:h,o=s?C(e,s):e;let a=t?Math.max(.42,e.h-.38,r*t.d+.12):0,l=i?Math.max(.2,e.d-.05,r*i.h-.45):0;if(t&&i){const e=.1-(a-r*t.d-(r*i.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${A(r)}`);if(t&&!i)return O(e.html+this.el("sup",t.html,`font-size:${A(r)};vertical-align:${A(a/r)}`),Math.max(o.h,a+r*t.h),Math.max(o.d,r*t.d-a));if(i&&!t)return O(o.html+this.el("sub",i.html,`font-size:${A(r)};vertical-align:${A(-l/r)}`),Math.max(o.h,r*i.h-l),Math.max(o.d,l+r*i.d));const d=a+r*t.h,m=l+r*i.d,u=this.el("subsup",c(t)+c(i),`vertical-align:${A(a)};height:${A(d+m)}`);return O(o.html+u,Math.max(o.h,d),Math.max(o.d,m))}radical(e,t=null){const n=Math.max(e.h,a)+.1+.06,i=Math.max(e.d,l),s=n+i,r=.5+.06*(s-1),c=o("sqrt",`${this.p}-hook`,`width:${A(r)};left:${A(-r)}`);let d="";if(t){const e=.8*h;d=this.el("rootindex",t.html,`font-size:${A(e)};vertical-align:${A((.55*s-i)/e)}`)}return O(this.el("sqrt",d+this.el("radicand",c+e.html,`margin-left:${A(r+.05)}`)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,a)+Math.max(e.d,l),s=i>1.25,r=s?.1:0,c=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const r=n+(s?Math.min(.2,.05*(i-1)):0);return{html:o(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${A(r)}`),w:r+.1}}const r={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${r} delim-${t}`,""),w:"|"===e?.18:.3}},h=c(t,"l"),d=c(n,"r"),m=`padding:${A(r)} ${A(d.w)} ${A(r)} ${A(h.w)}`,u=O(this.el("fence",h.html+e.html+d.html,m),Math.max(e.h,a)+r,Math.max(e.d,l)+r);return u.fenced=!0,u}derivative(e,t){const i=this.leibniz(e,t),{by:s,at:r}=n.derivativeOrder(e);if(!r)return i;const o=e.args[1],a=this.render({...o,args:[{...s,id:void 0},r]},{...t,level:t.level+1});return this.script(this.fence(i,"","|"),null,t,a)}leibniz(e,t){const{n:i,body:s,by:r,variable:o}=n.derivativeOrder(e),a={...t,level:t.level+1},l=()=>this.text("d","d"),c=()=>i>1?this.render({type:"number",value:String(i)},a):null,h={...t,inFraction:!0},d=C(l(),c()?this.script(this.render(r,h),c(),h):this.render(r,h)),m=e=>C(c()?this.script(l(),c(),h):l(),e||[]),u=t.level>0||t.inFraction||!this.o.display?.8:1;if(o)return this.stack(m(this.render(s,h)),d,!0,u);const p=n.bracketOp(s)&&n.precedenceOf(n.bracketOp(s))<100,[f,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],v=p?this.fence(this.render(s,t),f,g):this.render(s,t);return C(this.stack(m(),d,!0,u),v)}integral(e,t){const[i,s,r,o]=e,a=e=>this.render(e,t),l=e=>e?this.render(e,{...t,level:t.level+1}):null,c=()=>this.text("var",n.firstVariable(i)||"x");let h,d=null,m=null;switch(e.length){case 1:h=c();break;case 2:n.isVariable(s)?h=a(s):(h=c(),d=l(s));break;case 3:n.isVariable(s)?(h=a(s),d=l(r)):(h=c(),d=l(s),m=l(r));break;default:h=a(s),d=l(r),m=l(o)}const u=a(i),p=O(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return C(this.bigSign("int",u,d,m,t),u,p)}bigSign(e,t,n,i,s){const r=!this.o.display||s.level>0,a=Math.max(r?.6:.95,Math.max(t.h-c,t.d+c)+.12),l=o(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${A(2*a)};width:${A(r?.38:.5)};vertical-align:${A(c-a)}`);if(!n&&!i)return O(l,c+a,a-c);const d=h,m=i||O(""),u=n||O(""),p=c+a-d*m.h;u.d;const f=this.el("limits",this.el("script",m.html,`font-size:${A(d)}`)+this.el("script lower",u.html,`font-size:${A(d)}`),`vertical-align:${A(p)};height:${A(2*a)}`);return O(l+f,c+a,a-c)}limit(e,t){const[i,s,r,o]=e,a={...t,level:t.level+1},l=e=>this.render(e,a),c=()=>this.rel("→");let h;switch(e.length){case 1:return C(this.word("lim"),O(this.el("fnspace","")),this.body(i,t));case 2:{const e=n.firstVariable(i),t="number"===s.type||"symbol"===s.type&&s.value.includes("∞");h=e&&t?C(this.text("var",e),c(),l(s)):l(s);break}case 3:h=C(l(s),c(),l(r));break;default:{const e=n.firstLeaf(o).toLowerCase().startsWith("r")?"+":d;h=C(l(s),c(),this.script(l(r),this.wrap(o,["symbol"],this.text("ord",e)),a))}}return C(this.under(this.word("lim"),h,t),this.body(i,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):O(this.el("under",e.html+this.el("script",t.html,`font-size:${A(.7)}`)),e.h,Math.max(e.d,l)+.05+.7*(t.h+t.d))}body(e,t){const i=n.bracketOp(e);return i&&n.precedenceOf(i)<n.precedenceOf("*")?this.fence(this.render(e,t)):this.render(e,t)}bigOperator(e,t,n){const[i,s,r]=t,a={...n,level:n.level+1},l=s?this.render(s,a):null,d=r?this.render(r,a):null,m=this.body(i,n);if(!this.o.display||n.level>0){const t=.55,i=o(e,`${this.p}-bigsign`,`height:${A(2*t)};width:${A(.8)};vertical-align:${A(c-t)}`);return C(this.script(O(i,c+t,t-c),d,n,l),m)}const u=.68,p=h,f=o(e,`${this.p}-bigsign`,`height:${A(1.36)};width:${A("sum"===e?1:1.05)}`),g=d?1.01+p*d.d:c-u,v=e=>this.el("script",e.html,`font-size:${A(p)}`),b=this.el("bigop",(d?v(d):"")+f+(l?v(l):""),`vertical-align:${A(g)}`);return C(O(b,.93+(d?.08+p*(d.h+d.d):0),u-c+(l?.08+p*(l.h+l.d):0)),m)}matrix(e,t,i){const s=t.map(e=>e.map(e=>this.render(e,i))),r=s.map(e=>({h:Math.max(a,...e.map(e=>e.h)),d:Math.max(l,...e.map(e=>e.d))})),o=r.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),h=c+o/2-r[0].h,d=s.map((t,n)=>{const i=t.map(e=>this.el("matrix-cell",e.html)).join(""),s=e.args[n];return s&&"op"===s.type&&"[]"===s.op?this.wrap(s,["op","op-list","matrix-row"],O(i)).html:i}).join(""),m=t[0].length,u=O(this.el("matrix",d,`grid-template-columns:repeat(${m},auto);vertical-align:${A(h)}`),c+o/2,o/2-c),[p,f]=n.MATRICES[e.op]??["[","]"];return this.fence(u,p,f)}cases(e,t){const n=[];let i=e;for(;"op"===i.type&&"?:"===i.op;)n.push([this.render(i.args[1],t),C(this.word("if"),this.text("space",""),this.render(i.args[0],t))]),i=i.args[2];"symbol"===i.type&&"unchanged"===i.value||n.push([this.render(i,t),this.word("otherwise")]);const s=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),r=s.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),o=c+r/2-s[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=O(this.el("cases",a,`vertical-align:${A(o)}`),c+r/2,r/2-c);return this.fence(l,"{","")}}function _(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||n.matrixRows(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!n.isMinusOneTimes(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||B(e)||"*"===e.op&&_(e,t)):_(e.args[0],!0)&&("neg"===e.op||_(e.args[1],!0)))}const T=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],N=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&T.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(N)),B=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(n.GREEK[e.value])),q=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[m,u,p,g,b,y,$,w])Object.setPrototypeOf(e,null);function P(e){const{id:t,from:n,...i}=e;return i.args&&(i.args=i.args.map(P)),i}const F=e=>n.toPostfix(e).join(" ");function R(e,t){const i=new Set;Z(e,t,i);const s=[];return n.walk(e,e=>{i.has(e)&&s.push(e)}),s}function Z(e,t,i){if(null!=t)if(Array.isArray(t))t.forEach(t=>Z(e,t,i));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const s=F(n.parseTree(t));return void n.walk(e,e=>{F(e)===s&&i.add(e)})}if(t.path){const n=W(e,t.path);return void(n&&i.add(n))}if(t.type){const s=F(t);n.walk(e,e=>{e!==t&&F(e)!==s||i.add(e)})}}else n.walk(e,(e,n)=>{t(e,n)&&i.add(e)});else n.walk(e,e=>{e.id===t&&i.add(e)})}function W(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}function I(e,t){const n=[],i=e=>{if(e.id===t)return!0;if("op"!==e.type)return!1;for(let t=0;t<e.args.length;t++){if(n.push(t),i(e.args[t]))return!0;n.pop()}return!1};return i(e)?n:null}function D(e){let t=0;const i=e=>{"op"===e.type&&(e.args.forEach(i),n.operator(e.op)?.arity===n.VARIADIC&&t++),e.id=t++};return i(e),e}function H(e,t={}){const{blocks:i}=t;if("string"==typeof e)return n.parseTree(e,i?{blocks:e=>i(e,t.scope)}:{});if(Array.isArray(e))return n.fromPostfix(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return n.walk(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),D(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function V(e,t){const{colors:n,highlight:i,scope:s,blocks:r,...o}=t,a=new Map;for(const[t,i]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(G(i))for(const n of R(e,t))a.set(n,`color:${i}`);const l=new Set(void 0===i?[]:R(e,i));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}function G(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}function K(e,n={}){return H(e,{...n,blocks:n.blocks??t.calculateBlock})}function X(e,n={}){return function(e,t={}){const n=H(e,t);return z(n,V(n,t)).html}(e,{...n,blocks:n.blocks??t.calculateBlock})}function U(e,t,n){const i=(e,s)=>s===t.length?n:{...e,args:e.args.map((e,n)=>n===t[s]?i(e,s+1):e)};return P(i(e,0))}function Y(e,t,{parse:n,commit:i,cancel:s,label:r="Edit",prefix:o="mv"}){const a=e.ownerDocument;if(!a||!a.body)return null;const l=a.defaultView,c=e.getBoundingClientRect(),h=a.createElement("input");h.type="text",h.className=`${o}-edit`,h.value=t,h.spellcheck=!1,h.autocomplete="off",h.setAttribute("aria-label",r);const d=()=>{h.style.width=`${Math.max(4,h.value.length+2)}ch`},m=l.getComputedStyle(e);Object.assign(h.style,{position:"absolute",left:`${c.left+l.scrollX}px`,top:`${c.top+l.scrollY+c.height/2}px`,minWidth:`${Math.max(c.width,32)}px`,fontSize:m.fontSize}),d(),a.body.appendChild(h),l.getSelection?.()?.removeAllRanges(),h.focus(),h.select();let u=!1;const p=()=>{u=!0,h.remove()};h.cancelEdit=()=>{u||(p(),s&&s())};const f=e=>{if(u)return!0;if(!e||h.value===t)return p(),s&&s(),!0;let r;try{r=n(h.value)}catch(e){return h.setAttribute("aria-invalid","true"),h.title=e.message,!1}return p(),i(r,h.value),!0};return h.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),f(!0)),"Escape"===e.key&&(e.preventDefault(),f(!1))}),h.addEventListener("input",()=>{d(),h.removeAttribute("aria-invalid"),h.removeAttribute("title")}),h.addEventListener("blur",()=>{f(!0)||f(!1)}),h}class J{constructor(e,t,n={}){this.element=e,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=Q(e,n.announce,this.p),this.set(t)}set(e,{animate:t=!1,duration:n=600,easing:i="ease-in-out"}={}){const s=K(e,this.options),{html:r}=z(s,V(s,this.options));if(this.editor){const e=this.editor;this.editor=null,e.cancelEdit?.()}const o=ee(t)&&this.tree?this.snapshot():null,a=void 0!==this.tree;return this.tree=s,this.element.innerHTML=r,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),o&&this.morph(o,{duration:n,easing:i}),a&&this.live&&this.announce(this.spoken()),this}spoken(){const e=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(e)return e;try{return i.toAudioSpeech(this.tree)}catch{return""}}announce(e){return this.say(this.live,e)}say(e,t){if(!e)return this;e.textContent="";const n=()=>{e.textContent=t};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(n)):setTimeout(n,50),this}nodes(e){return R(this.tree,e)}elements(e){return this.nodes(e).map(e=>this.elementOf(e)).filter(Boolean)}elementOf(e){return void 0===e.id?null:this.root.querySelector(`[data-node="${e.id}"]`)}highlight(e,t=`${this.p}-hl`){return this.elements(e).forEach(e=>e.classList.add(t)),this}unhighlight(e=null,t=`${this.p}-hl`){return(null===e?this.root.querySelectorAll(`.${t}`):this.elements(e)).forEach(e=>e.classList.remove(t)),this}color(e,t){return this.elements(e).forEach(e=>{e.style.color=t||""}),this}on(e,t){const n=e=>{const n=e.target.closest?.("[data-node]");if(!n||!this.root.contains(n))return;const i=Number(n.dataset.node),s=R(this.tree,i)[0];t({node:s,id:i,path:I(this.tree,i),element:n,event:e})};this.element.addEventListener(e,n);const i=[e,n];return this.handlers.push(i),this.root.classList.add(`${this.p}-clickable`),"click"===e&&(this.clicks.push(t),this.keyboard()),()=>{this.element.removeEventListener(e,n),this.clicks=this.clicks.filter(e=>e!==t),this.handlers=this.handlers.filter(e=>e!==i),!this.handlers.length&&this.root&&this.root.classList.remove(`${this.p}-clickable`)}}destroy(){if(this.editor){const e=this.editor;this.editor=null,e.cancelEdit?.()}for(const[e,t]of this.handlers)this.element.removeEventListener(e,t);this.handlers=[],this.clicks=[],this.keyListener&&this.element.removeEventListener("keydown",this.keyListener),this.editListener&&this.element.removeEventListener("dblclick",this.editListener),this.keyListener=this.editListener=null,this.keysOn=this.editOn=!1;for(const e of new Set([this.live,this.partsLive]))e&&"view"===e.dataset?.mvMadeBy&&e.remove();return this.live=this.partsLive=null,this}editable({toText:e,onEdit:t}={}){if("function"!=typeof e)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:e,onEdit:t},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.editListener=e=>{const t=e.target.closest?.("[data-node]");t&&this.root.contains(t)&&(e.preventDefault(),this.edit(R(this.tree,Number(t.dataset.node))[0]))},this.element.addEventListener("dblclick",this.editListener)),this}edit(e=this.tree,{returnFocus:t=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const n="object"==typeof e&&e&&e.type?e:this.nodes(e)[0];if(!n)return null;const s=I(this.tree,n.id)||[],r=this.elementOf(n)||this.root;let o="Edit";try{o=`Edit ${i.toAudioSpeech(n)}`}catch{}const a=()=>{t&&this.root.focus&&this.root.focus()};return this.editor=Y(r,this.editing.toText(n),{label:o,prefix:this.p,parse:e=>K(e,this.options),commit:(e,n)=>{this.set(U(this.tree,s,e),{animate:!0});const i=W(this.tree,s);t&&i&&this.focusPart(i===this.tree?null:i),a(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:s,part:n})},cancel:a}),this.editor}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||Q(this.element,!0,this.p),this.keyListener=e=>this.key(e),this.element.addEventListener("keydown",this.keyListener))}key(e){if(!this.root||!this.root.contains(e.target))return;const t=this.active;let n;switch(e.key){case"ArrowDown":n=t?this.partsOf(t)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":n=t?this.outerOf(t):void 0;break;case"ArrowRight":n=t?this.neighbor(t,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":n=t?this.neighbor(t,-1):void 0;break;case"Home":case"Escape":n=null;break;case"F2":if(!this.editing)return;return e.preventDefault(),void this.edit(t||this.tree,{returnFocus:!0});case"Enter":case" ":{e.preventDefault();const n=t||this.tree,i=this.elementOf(n)||this.root,s={node:n,id:n.id,path:I(this.tree,n.id),element:i,event:e};for(const e of this.clicks)e(s);return}default:return}e.preventDefault(),void 0!==n&&this.focusPart(n)}focusPart(e){const t=`${this.p}-focus`;this.root.querySelectorAll(`.${t}`).forEach(e=>e.classList.remove(t)),this.active=e;const n=e&&this.elementOf(e);n&&n.classList.add(t);let s="";try{s=e?i.toAudioSpeech(e):this.spoken()}catch{s=""}return this.say(this.partsLive,s),this}partsOf(e){const t=[],n=e=>{this.elementOf(e)?t.push(e):"op"===e.type&&e.args.forEach(n)};return e&&"op"===e.type&&e.args.forEach(n),t}outerOf(e){const t=I(this.tree,e.id);for(let e=t?t.length-1:-1;e>0;e--){const n=W(this.tree,t.slice(0,e));if(n&&this.elementOf(n))return n}return null}neighbor(e,t){const n=this.partsOf(this.outerOf(e)||this.tree),i=n.indexOf(e);return i<0?void 0:n[i+t]}segments(e={}){return i.toSpeechSegments(this.tree,e)}showSegment(e,t=`${this.p}-hl`){return this.unhighlight(null,t),e&&void 0!==e.id&&this.highlight(e.id,t),this}snapshot(){const e=new Map,t=n=>{const i=this.elementOf(n);if(i){const t=F(n);e.has(t)||e.set(t,[]),e.get(t).push({rect:i.getBoundingClientRect(),node:n,sig:t})}"op"===n.type&&n.args.forEach(t)};return t(this.tree),e}morph(e,{duration:t,easing:n}){if("undefined"==typeof Element||!Element.prototype.animate)return;const i=t=>{if("op"===t.type)for(const n of t.args){const t=e.get(F(n)),s=t?t.findIndex(e=>e.node===n):-1;s>-1&&t.splice(s,1),i(n)}},s=r=>{const o=this.elementOf(r),a=o&&e.get(F(r));if(a&&a.length){const{rect:e,node:s}=a.shift();i(s);const r=o.getBoundingClientRect(),l=e.left-r.left,c=e.top-r.top,h=r.width?e.width/r.width:1,d=r.height?e.height/r.height:1;return void((Math.abs(l)+Math.abs(c)>.5||Math.abs(h-1)+Math.abs(d-1)>.01)&&o.animate([{transformOrigin:"0 0",transform:`translate(${l}px, ${c}px) scale(${h}, ${d})`},{transformOrigin:"0 0",transform:"none"}],{duration:t,easing:n}))}"op"===r.type?r.args.forEach(s):o&&o.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:t,easing:n})};s(this.tree)}}function Q(e,t,n){if(!t)return null;if("object"==typeof t&&1===t.nodeType)return t;if("undefined"==typeof document||!e.insertAdjacentElement)return null;const i=e.nextElementSibling;if(i&&"view"===i.dataset?.mvMadeBy&&i.classList.contains(`${n}-sr-only`))return i;const s=document.createElement("span");return s.dataset.mvMadeBy="view",s.className=`${n}-sr-only`,s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","true"),e.insertAdjacentElement("afterend",s),s}function ee(e){return!!e&&("always"===e||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}const te=Symbol.for("inlinemath.expressions"),ne=new Set(["symbol","number"]);function ie(e){return e?"symbol"===e.type?e.value:"op"===e.type&&"_"===e.op&&2===e.args.length&&"symbol"===e.args[0].type&&ne.has(e.args[1].type)?`${e.args[0].value}_${e.args[1].value}`:null:null}function se(e){const{id:t,...n}=e;return n.args&&(n.args=n.args.map(se)),n}function re(e,t){const n=(e,i)=>{if(!i&&void 0!==e.from)return t(e.from);const{id:s,from:r,...o}=e;return o.args&&(o.args=o.args.map(e=>n(e,!1))),o};return n(e,!0)}const oe=new Set;function ae(e,t){let i=!1;const s=new Set,r=(e,o=oe)=>{const a=ie(e);if(null!==a){if(!s.has(a)&&!o.has(a)){const e=t(a);if(e){i=!0,s.add(a);const t={...r(P(e)),from:a};return s.delete(a),t}}return e}if(e.args){const t=function(e){const[t,i]=e.args,s=e=>e&&"symbol"===e.type?e.value:null;switch(e.op){case"der":return"="===i?.op?s(i.args[0])&&{name:s(i.args[0]),where:e=>0===e,index:1}:s(i)&&{name:s(i),where:e=>e<=1};case"int":{const r=s(i)??(3===e.args.length||1===e.args.length?n.firstVariable(t)||"x":null);return r&&{name:r,where:e=>0===e||1===e&&s(i)===r}}case"lim":return"→"===i?.op&&s(i.args[0])&&{name:s(i.args[0]),where:e=>0===e,index:1};case"\\sumidx":case"\\prodidx":return("="===i?.op||"∈"===i?.op)&&s(i.args[0])&&{name:s(i.args[0]),where:e=>0===e,index:1};default:return null}}(e);if(!t)return{...e,args:e.args.map(e=>r(e,o))};const i=new Set([...o,t.name]);return{...e,args:e.args.map((e,n)=>n===t.index?{...e,args:e.args.map((e,t)=>r(e,0===t?i:o))}:r(e,t.where(n)?i:o))}}return e},o=r(e);return{tree:i?se(o):e,changed:i}}const le="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",ce=new RegExp(`^(${le})\\s*\\.\\.\\s*(${le})(?:\\s+step\\s+(${le}))?(?:\\s*=\\s*(${le}))?$`);function he(e){const t=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(e);if(!t||/\]\s*,\s*\[/.test(t[1]))return null;const n=t[1].trim(),i=ce.exec(n);if(i){const e=Number(i[1]),t=Number(i[2]);if(!(t>e))return null;const n=void 0!==i[3]?Number(i[3]):Number.isInteger(e)&&Number.isInteger(t)?1:(t-e)/100;if(!(n>0))return null;const s=void 0!==i[4]?Math.min(t,Math.max(e,Number(i[4]))):e;return{kind:"slider",min:e,max:t,step:n,default:String(s)}}if(n.includes("|")){const e=n.split("|").map(e=>e.trim()).filter(Boolean);if(e.length)return{kind:"dropdown",options:e,default:e[0]}}return{kind:"textbox",default:n}}const de=Symbol("set on the page");class me{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(e){const t=new Map;for(const[n,i]of this.owners)if(n!==e)for(const[e,n]of i)t.delete(e),t.set(e,n);return t}textOf(e){const t=this.chosen.get(e.name);return t&&t.key===e.key?t.text:e.text}get(e){const t=this.definitions().get(e);return t?this.textOf(t):void 0}names(){return[...this.definitions().keys()]}set(e,t){t=String(t);const n=this.definitions().get(e);if(n&&n.input){const i=this.chosen.get(e);if(i&&i.key===n.key&&i.text===t)return this;this.chosen.set(e,{key:n.key,text:t})}else{const n=new Map(this.owners.get(de));n.set(e,{name:e,text:t,key:`page:${t}`,input:null}),this.owners.delete(de),this.owners.set(de,n)}return this.notify(null,e),this}clear(e){return void 0===e?(this.owners.clear(),this.chosen.clear()):(this.owners.get(de)?.delete(e),this.chosen.delete(e)),this.notify(null,e),this}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}own(e,t){const n=this.owners.get(e);var i,s;(i=n,s=t,(i?.size??0)===(s?.size??0)&&[...i??[]].every(([e,t])=>s?.get(e)?.key===t.key))?t&&this.owners.set(e,t):(t&&t.size?this.owners.set(e,t):this.owners.delete(e),this.notify(e))}notify(e,t){for(const n of[...this.listeners])n(e,t)}}function ue(){return new me}const pe=ue(),fe=new RegExp("(\\d+)","g");function ge(e,{delimiters:t=["$$","$","\\[","\\("]}={}){const n=[];let i="",s=0;const r=String(e).replace(/[\uE000-\uE003]/g,"�"),o=e=>0===e||"\n"===r[e-1],a=function(e){const t=new Map,n=e=>/^( {4}|\t)/.test(e);let i=0,s=!0,r=!1,o=-1;for(const a of e.split("\n")){const e=!a.trim();o>-1&&!e&&!n(a)&&(t.set(o,i-1),o=-1),o<0&&!e&&n(a)&&s&&!r&&(o=i),e||n(a)||(r=Ee.test(a)||r&&/^\s/.test(a)),s=e,i+=a.length+1}o>-1&&t.set(o,e.length);return t}(r);let l=-1;const c=new Set,h=(e,t,i)=>(n.push({source:e,display:t,raw:i,start:s,end:s+i.length}),`${n.length-1}`);for(;s<r.length;){if(a.has(s)){i+=r.slice(s,a.get(s)),s=a.get(s);continue}if(o(s)){const e=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(r.slice(s));if(e){const t=e[2],n=new RegExp(`\\n {0,3}${"`"===t[0]?"`":"~"}{${t.length},}[ \\t]*(?=\\n|$)`),o=r.slice(s+e[0].length),a=n.exec(`\n${o}`),l=a?o.slice(0,Math.max(0,a.index-1)):o,c=e[0].length+(a?a.index-1+a[0].length:o.length),d=r.slice(s,s+c);"math"===e[3].trim()?i+=h(l,!0,d):i+=d,s+=c;continue}}const e=r[s];if("`"===e){const e=/^`+/.exec(r.slice(s))[0],t=r.indexOf(e,s+e.length);if(t>-1){i+=r.slice(s,t+e.length),s=t+e.length;continue}i+=e,s+=e.length;continue}if("\\"===e){const e=r.slice(s,s+2),n="\\["===e?"\\]":"\\("===e?"\\)":null;if(n&&t.includes(e)){const t=c.has(n)?-1:r.indexOf(n,s+2);if(t<0&&c.add(n),t>-1){i+=h(r.slice(s+2,t),"\\["===e,r.slice(s,t+2)),s=t+2;continue}}i+=e,s+=2;continue}if("$"===e)if("$"===r[s+1]&&t.includes("$$")){const e=r.indexOf("$$",s+2);if(e>-1){i+=h(r.slice(s+2,e),!0,r.slice(s,e+2)),s=e+2;continue}}else if(t.includes("$")&&r[s+1]&&!/\s/.test(r[s+1])&&s+1>=l){const{end:e,stop:t}=ve(r,s+1);if(e>-1){i+=h(r.slice(s+1,e),!1,r.slice(s,e+1)),s=e+1;continue}l=t}i+=e,s++}return{text:i,math:n}}function ve(e,t){for(let n=t;n<e.length;n++){const t=e[n];if("\\"!==t){if("`"===t)return{end:-1,stop:n};if("\n"===t&&/^\n[ \t]*\n/.test(e.slice(n,n+64)))return{end:-1,stop:n};if("$"===t&&!/\s/.test(e[n-1])&&!/\d/.test(e[n+1]??"")&&"$"!==e[n+1])return{end:n,stop:n}}else n++}return{end:-1,stop:e.length}}const be=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ye=/^\s*([A-Za-z\u0370-\u03ff](?:_\{?\w+\}?)?)\s*=\s*([^=<>≤≥]+)$/;function xe(e,i,s,r){const{text:o,math:a}=ge(e,i),l=s?s.definitions(r):new Map,c=e=>s?s.textOf(e):e.text,h={...i.scope??{}},d={},m=new Map,u=new Set,p=[],f=e=>{const t=new Map;return n=>{const i=l.get(n);if(!i)return null;if(!t.has(n)){let s=null;try{s=K(c(i),e)}catch{}t.set(n,s)}return t.get(n)}};let g=!0;const v=a.map((e,s)=>{const{source:r,display:o}=e;g&&r.includes("{{")&&((()=>{for(const e of Object.keys(d))delete d[e];Object.assign(d,h);for(const e of l.keys())delete d[e];let e=[...l.values()];for(;e.length;){const n=e.filter(e=>{try{const n=t.calculate(c(e),d);if("number"==typeof n.value||"bigint"==typeof n.value||Array.isArray(n.value))return d[e.name]=n.exact?n.text:n.value,!1}catch{}return!0});if(n.length===e.length)break;e=n}const i={},s=f({});for(const e of l.keys()){const t=s(e);if(t)try{i[e]=n.toPostfix(ae(t,t=>t===e?null:s(t)).tree)}catch{}}d[te]=i})(),g=!1);const a=o?"mv-md-display":"mv-md-math",v=(e,t="")=>`<span class="${a}${t}" data-mv-md="${s}">${e}</span>`;try{const n={...i.math,display:o,blocks:i.blocks,scope:d},a=function(e){let t=e.trim();const n=t.startsWith("_");n&&(t=t.slice(1).trimStart());let i=t.indexOf(":="),s=2;i<0&&n&&(i=t.search(/(?<![<>!≤≥=])=(?!=)/),s=1);const r=n?{error:"a hidden $_…$ saves a variable: $_A := 2+2$"}:null;if(i<=0)return r;const o=t.slice(0,i).trim(),a=t.slice(i+s).trim();let l=null;try{l=/\{\{/.test(o)?null:ie(K(o))}catch{}return null!==l&&a?{hidden:n,lhs:o,name:l,rhs:a,input:he(a)}:r}(r);if(a&&a.error)throw new Error(a.error);if(a){const{name:t,input:i,hidden:r}=a,o=i?{name:t,text:i.default,input:i,key:`input:${JSON.stringify(i)}`}:{name:t,text:a.rhs,input:null,key:`expr:${a.rhs}`,start:e.start,end:e.end};let h="";if(i){const e=function(e,t){const{input:n,name:i}=e,s=`class="mv-md-input mv-md-${n.kind}" data-mv-var="${be(i)}" aria-label="${be(i)}"`;if("dropdown"===n.kind)return`<select ${s}>${n.options.map(e=>`<option value="${be(e)}"${e===t?" selected":""}>${be(e)}</option>`).join("")}</select>`;return"slider"===n.kind?`<input type="range" ${s} min="${n.min}" max="${n.max}" step="${n.step}" value="${be(t)}"><output class="mv-md-output" data-mv-out="${be(i)}">${be(t)}</output>`:`<input type="text" ${s} value="${be(t)}" size="${Math.max(4,t.length+1)}" spellcheck="false" autocomplete="off">`}(o,c(o));h=r?e:`${X(a.lhs,n)}<span class="mv-md-assign" aria-hidden="true">≔</span>${e}`,u.add(s)}else{const e=ae(K(a.rhs,n),f(n)).tree;if(!r){const t=D({type:"op",op:"=",args:[P(K(a.lhs)),void 0===e.id?e:P(e)]});p[s]=t,h=function(e,t="mv"){return e.replace(`<span class="${t}-rel">=</span>`,`<span class="${t}-rel ${t}-rel-def">≔</span>`).replace(/(aria-label="[^"]*?) equals /,"$1 is defined as ").replace("<mo>=</mo>","<mo>≔</mo>")}(X(t,n),n.prefix)}}return l.delete(t),l.set(t,o),m.set(t,o),g=!0,r&&!i?"":v(h,i?" mv-md-input-def":"")}const{tree:b,changed:y}=ae(K(r,n),f(n));y&&D(b),p[s]=b;const x=X(b,n);return!y&&!1!==i.define&&function(e,n,i){const s=ye.exec(e);if(!s||/\{\{/.test(s[2]))return!1;const r=s[1].replace(/[{}]/g,"");if(i.has(r))return!1;try{const e=t.calculate(s[2],n);if("number"==typeof e.value||"bigint"==typeof e.value||Array.isArray(e.value))return n[r]=e.exact?e.text:e.value,!0}catch{}return!1}(r,h,l)&&(g=!0),v(x)}catch(t){return`<span class="mv-md-error" data-mv-md="${s}" title="${be(t.message)}"><code>${be(e.raw)}</code></span>`}});return{text:o,math:a,drawn:v,defs:m,inputs:u,trees:p}}const $e=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,we=e=>$e.test(e.trim())?be(e.trim()):"#",ke=/\uE002(\d+)\uE003/g;function Le(e,t,n,i=[]){const s=e=>(i.push(e),`${i.length-1}`),r=e=>(e=>e.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"))(n(e).replace(ke,(e,t)=>(i[Number(t)]??"").replace(/<[^>]*>/g,"")));let o=e;o=o.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(e,t,i)=>s(`<code>${be(n(i.trim()))}</code>`)),o=o.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(e,t)=>s(be(t))),o=o.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(e,t)=>s(`<a href="${we(t)}">${be(t)}</a>`)),t.html&&(o=o.replace(/<\/?[A-Za-z][^>]*>/g,e=>s(e))),o=o.replace(/!\[([^\[\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,t,n,i)=>s(`<img src="${we(r(n))}" alt="${be(r(t))}"${i?` title="${be(r(i))}"`:""}>`)),o=o.replace(/\[([^\[\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,o,a,l)=>s(`<a href="${we(r(a))}"${l?` title="${be(r(l))}"`:""}>${Le(o,t,n,i)}</a>`)),o=o.replace(/&(?!#\d{1,7};|#x[0-9a-f]{1,6};|[a-z][a-z0-9]{1,31};)/gi,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),o=o.replace(/(\*\*\*|___)(?=\S)([\s\S]*?\S)\1/g,"<strong><em>$2</em></strong>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*\*|__)(?![*_])([\s\S]*?\S)(\*|_)(?![*_])/g,"<em><strong>$2</strong>$4</em>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*|_)(?![*_])([\s\S]*?\S)(\*\*|__)(?![*_])/g,"<strong><em>$2</em>$4</strong>"),o=o.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),o=o.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),o=o.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),o=o.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),o=o.replace(/( {2,}|\\)\n/g,"<br>\n");for(let e=0;e<8&&/\uE002\d+\uE003/.test(o);e++)o=o.replace(ke,(e,t)=>i[Number(t)]??"");return o}const Me=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,Ee=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,Se=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,Ae=e=>Me.test(e)&&!/^ {0,3}[-=]+\s*$/.test(e)&&!/^ {0,3}(?!1[.)])\d{1,9}[.)]\s/.test(e);function Oe(e){const t=e.trim();let n=t.length;for(;n>0&&"#"===t[n-1];)n--;return n===t.length?t:0===n?"":/[ \t]/.test(t[n-1])?t.slice(0,n).trimEnd():t}function Ce(e,t,n,i=0){const s=[];let r=0;const o=e=>Le(e,t,n);if(i>100)return`<p>${o(e.join("\n"))}</p>`;for(;r<e.length;){const a=e[r];if(!a.trim()){r++;continue}const l=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(a);if(l){const t=[];for(r++;r<e.length&&!new RegExp(`^ {0,3}${"`"===l[1][0]?"`":"~"}{${l[1].length},}\\s*$`).test(e[r]);)t.push(e[r++]);r++;const i=l[2]?` class="language-${be(l[2])}"`:"";s.push(`<pre><code${i}>${be(n(t.join("\n")))}</code></pre>`);continue}const c=/^ {0,3}(#{1,6})[ \t]+/.exec(a);if(c){s.push(`<h${c[1].length}>${o(Oe(a.slice(c[0].length)))}</h${c[1].length}>`),r++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(a)){s.push("<hr>"),r++;continue}if(/^ {0,3}>/.test(a)){const o=[];for(;r<e.length&&e[r].trim()&&(/^ {0,3}>/.test(e[r])||o.length);)o.push(e[r].replace(/^ {0,3}> ?/,"")),r++;s.push(`<blockquote>\n${Ce(o,t,n,i+1)}\n</blockquote>`);continue}const h=Ee.exec(a);if(h){const o=/\d/.test(h[2]),a=o?parseInt(h[2],10):1,l=[];let c=!1;for(;r<e.length;){const t=Ee.exec(e[r]);if(!t||/\d/.test(t[2])!==o)break;const n=t[0].length,i=[e[r].slice(n)];for(r++;r<e.length;){const t=e[r];if(!t.trim()){const t=e[r+1];if(void 0!==t&&t.startsWith(" ".repeat(Math.min(n,4)))&&t.trim()){i.push(""),c=!0,r++;continue}void 0!==t&&Ee.test(t)&&(c=!0);break}if(t.startsWith(" ".repeat(Math.min(n,4))))i.push(t.slice(Math.min(n,4)));else{if(Ee.test(t)||Me.test(t))break;i.push(t)}r++}for(l.push(i);r<e.length&&!e[r].trim()&&void 0!==e[r+1]&&Ee.test(e[r+1]);)r++}const d=o?"ol":"ul",m=l.map(e=>{let s=Ce(e,t,n,i+1);return c||(s=s.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${s}</li>`});s.push(`<${d}${o&&1!==a?` start="${a}"`:""}>\n${m.join("\n")}\n</${d}>`);continue}if(a.includes("|")&&void 0!==e[r+1]&&Se.test(e[r+1])&&e[r+1].includes("-")){const t=e=>e.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(e=>e.trim()),n=t(e[r+1]).map(e=>e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":e.startsWith(":")?"left":""),i=(e,t,i)=>`<${e}${n[i]?` style="text-align:${n[i]}"`:""}>${o(t)}</${e}>`,l=t(a);r+=2;const c=[];for(;r<e.length&&e[r].trim()&&e[r].includes("|");)c.push(t(e[r++]));s.push(`<table>\n<thead><tr>${l.map((e,t)=>i("th",e,t)).join("")}</tr></thead>\n<tbody>\n${c.map(e=>`<tr>${l.map((t,n)=>i("td",e[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(a)){const t=[];for(;r<e.length&&(/^( {4}|\t)/.test(e[r])||!e[r].trim());)t.push(e[r++].replace(/^( {4}|\t)/,""));for(;t.length&&!t[t.length-1].trim();)t.pop();s.push(`<pre><code>${be(n(t.join("\n")))}</code></pre>`);continue}const d=[];for(;r<e.length&&e[r].trim()&&(!d.length||!Ae(e[r]));){if(d.length&&/^ {0,3}(=+|-+)\s*$/.test(e[r])){const t="="===e[r].trim()[0]?1:2;s.push(`<h${t}>${o(d.join("\n"))}</h${t}>`),d.length=0,r++;break}d.push(e[r].replace(/^ {0,3}/,"")),r++}d.length&&s.push(`<p>${o(d.join("\n"))}</p>`)}return s.join("\n")}function ze(e,t={},n=e=>e){return Ce(String(e).replace(/\r\n?/g,"\n").replace(/[\uE002\uE003]/g,"�").split("\n"),t,n)}function je({text:e,math:t,drawn:n},i){return(i.render?i.render(e):ze(e,i,e=>e.replace(fe,(e,n)=>t[Number(n)]?.raw??""))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(e,i)=>t[Number(i)].display&&n[Number(i)]?`<div class="mv-md-block">${n[Number(i)]}</div>`:e).replace(fe,(e,t)=>n[Number(t)]??"").replace(/<p>\s*<\/p>\n?/g,"")}const _e=new WeakMap,Te=new Set;function Ne(){for(const e of Te)e.connected()&&!e.element.isConnected&&e.stop(!0)}var Be='/*\n * Inline Math stylesheet. Everything is under .mv; colors are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight color\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d, .mv-conj { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-conj { margin: 0 0.6em; } /* x = 2 or x = 3 */\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-radicand { display: inline-block; position: relative; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n/* the hook, in the radicand\'s left margin (layout.js sets its width and that margin): from the bar\'s center\n (just below the middle of the 0.06em border above the box) to the bottom of what it holds, so the tip always meets the bar */\n.mv-hook { position: absolute; top: -0.02em; height: calc(100% + 0.02em); overflow: visible; } /* a hair below the center: never above the bar */\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }\n.mv-matrix-row { display: contents; }\n.mv-matrix-cell { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; position: relative; padding-top: 0.14em; }\n.mv-over::before { content: \'\'; position: absolute; left: 0; right: 0; top: 0.21em; border-top: 0.06em solid currentColor; } /* metric */\n.mv-over-low::before { top: 0.48em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; position: relative; }\n.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: -0.27em; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; } /* metric: measured over F, h, A */\n/* ˆ ˜ ˙ ¨ are spacing marks that sit high in their em: full size, pulled down onto the letter */\n.mv-accent-hat, .mv-accent-widehat, .mv-accent-tilde, .mv-accent-dot, .mv-accent-ddot { font-size: 1em; line-height: 1; top: 0.02em; }\n/* over an italic letter the mark leans with it, right of the box\'s center */\n.mv-accent:has(> .mv-var) > .mv-accent-mark { transform: translateX(0.1em); }\n/* a letter with no ascender (x, u, α; layout.js adds -low): the mark comes down to its top */\n.mv-accent-low > .mv-accent-mark { top: 0.08em; }\n.mv-accent-low > .mv-accent-hat, .mv-accent-low > .mv-accent-widehat, .mv-accent-low > .mv-accent-tilde, .mv-accent-low > .mv-accent-dot, .mv-accent-low > .mv-accent-ddot { top: 0.31em; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n/* Windows high contrast (and other forced colors) drops backgrounds and shadows: outline a highlight instead */\n@media (forced-colors: active) {\n .mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }\n}\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the box editing a part in place (view.editable, or a Markdown textbox variable) */\n.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;\n border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }\n.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }\n/* the live region a view announces steps through ({ announce: true }): read, never seen */\n.mv-sr-only, .mv-sr-math { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */\n.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }\n.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }\n/* while a part is ringed, the whole expression\'s ring steps back so the part is the one that stands out */\n.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }\n@media (forced-colors: active) {\n .mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }\n}\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with math (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */\n.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }\n.mv-md-assign { margin: 0 0.1em; }\n.mv-md-input { font: inherit; font-size: 0.9em; }\ninput.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }\ninput.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }\ninput.mv-md-slider { vertical-align: middle; }\n.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }\n';const qe=Be;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Be,document.head.append(e)}return Object.defineProperty(e,"toText",{enumerable:!0,get:function(){return s.toText}}),e.CSS=qe,e.DEFAULTS=E,e.PATHS=r,e.View=J,e.createVariables=ue,e.extractMath=ge,e.layout=z,e.markdownToHTML=function(e,t={}){return je(xe(e,t,t.variables||null),t)},e.nodeAt=W,e.numberTree=D,e.pathOf=I,e.render=function(e,t,n={}){return new J(e,t,n)},e.renderMarkdown=ze,e.renderMarkdownInto=function(e,t,n={}){const i=void 0===n.variables?pe:n.variables||null;Ne();const s=_e.get(e);s&&s.stop(s.store!==i);let r=xe(t,n,i,e);if(e.innerHTML=je(r,n),!i)return _e.delete(e),e;i.own(e,r.defs);let o=e.isConnected;const a=t=>{const s=t.target,r=s&&s.dataset&&s.dataset.mvVar;if(void 0!==r&&e.contains(s)){if("text"===s.type)try{K(s.value,{blocks:n.blocks,scope:{}}),s.removeAttribute("aria-invalid")}catch{return void s.setAttribute("aria-invalid","true")}i.set(r,s.value)}},l=s=>{const o=s.target.closest?.("[data-node]"),a=o&&o.closest("[data-mv-md]");if(!a||!e.contains(a))return;const l=Number(a.dataset.mvMd),c=r.trees[l];if(!c)return;const h=Number(o.dataset.node),d=I(c,h)||[];let m=null;for(let e=d.length;e>=0&&!m;e--){const t=W(c,d.slice(0,e));t&&void 0!==t.from&&(m={node:t,depth:e})}const u=m&&i.definitions().get(m.node.from);if(u&&u.input&&"textbox"===u.input.kind){s.preventDefault();const t=u.name,r=e.ownerDocument.querySelector(`[data-mv-var="${CSS.escape(t)}"]`),a=n.editable&&n.editable.toText;if(!a)return void(r&&(r.focus(),r.select()));const l=e=>K(e),h=W(c,d);return void Y(o,a(re(h,l)),{label:`Edit ${t}`,parse:e=>K(e,{blocks:n.blocks}),commit:e=>{const n=U(re(m.node,l),d.slice(m.depth),e);i.set(t,a(n))}})}const p=u&&r.defs.get(u.name),f=p&&p.key===u.key&&void 0!==p.start?{...r.math[l],start:p.start,end:p.end,raw:t.slice(p.start,p.end)}:r.math[l];e.dispatchEvent(new CustomEvent("inlinemath:select",{bubbles:!0,detail:{index:l,start:f.start,end:f.end,raw:f.raw,source:f.source,id:h,path:d}}))};e.addEventListener("input",a),e.addEventListener("change",a),e.addEventListener("dblclick",l);const c=i.subscribe(s=>{s!==e&&(e.isConnected?(o=!0,Ne(),(()=>{const s=xe(t,n,i,e);s.drawn.forEach((t,n)=>{if(t===r.drawn[n]||s.inputs.has(n))return;const i=e.querySelector(`[data-mv-md="${n}"]`);i&&(i.outerHTML=t)});for(const t of e.querySelectorAll("[data-mv-var], [data-mv-out]")){const e=s.defs.get(t.dataset.mvVar??t.dataset.mvOut);if(!e)continue;const n=i.textOf(e);void 0!==t.dataset.mvOut?t.textContent=n:t.value!==n&&t!==t.ownerDocument?.activeElement&&(t.value=n)}r=s})()):o&&h(!0))});function h(t){c(),e.removeEventListener("input",a),e.removeEventListener("change",a),e.removeEventListener("dblclick",l),Te.delete(d),_e.delete(e),t&&i.own(e,null)}const d={element:e,store:i,stop:h,connected:()=>o};return Te.add(d),_e.set(e,d),e},e.select=R,e.shouldAnimate=ee,e.signature=F,e.toHTML=X,e.treeOf=K,e.variables=pe,e}({},MathZetta,MathZetta,MathZetta,MathZetta);
1
+ /* Inline Math 0.4.2 — MIT license; MathZetta not included: load a MathZetta <script> (mathzetta.min.js or mathzetta.maths-display.min.js) first */
2
+ var InlineMath=function(e,t,n,i,s){"use strict";const r={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function o(e,t,n=""){const i=r[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${i.fill?`<path d="${i.fill}" fill="currentColor"/>`:`<path d="${i.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const a=.8,l=.2,c=.25,h=.7,d="−",m={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","\\implies":"implies","\\iff":"iff","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},u={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},p={"±":"±","∪":"∪","∩":"∩",mod:"mod"},f=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],g={arcsin:"sin",arccos:"cos",arctan:"tan",arcsec:"sec",arccsc:"csc",arccot:"cot",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},v=[...f,...Object.keys(g),"ln","det"],b={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},y={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},x=["int","lim","\\sumidx","\\prodidx"],$={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},w={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},k=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,L=e=>"symbol"===e?.type&&k.test(n.GREEK[e.value]??e.value),M=["boxed","overline","bar","underline","cancel",...Object.keys(w)],E={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},S=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),A=e=>+e.toFixed(3)+"em",O=(e,t=a,n=l)=>({html:e,h:t,d:n});function C(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(a,...t.map(e=>e.h)),d:Math.max(l,...t.map(e=>e.d))}}function z(e,t={}){const n=new j({...E,...t}),s=n.render(e,{level:0}),r=`${n.p}${n.o.display?` ${n.p}-display`:""}`,o="function"==typeof n.o.mathml?function(e,t,n,i){try{return String(e(t)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${i?' display="block"':""}>`)}catch{return""}}(n.o.mathml,e,n.p,n.o.display):"",a=o?null:function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):i.toAudioSpeech(e)}catch{return null}}(e,n.o.label),l=null!==a||o?s.html.replace(/^<span /,'<span aria-hidden="true" '):s.html;return{html:`<span class="${r}"${null===a?"":` role="math" aria-label="${S(a)}"`}>${l}${o}</span>`,h:s.h,d:s.d}}class j{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",i=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${i}>${t}</span>`}text(e,t){const n=O(this.el(e,S(t)));return n.leaf={kind:e,content:S(t)},n}bin(e){return this.text("bin",e)}rel(e){return this.text("rel",e)}punct(e){return this.text("punct",e)}word(e){return this.text("word",e)}wrap(e,t,n){let i="";void 0!==e.id&&(i+=` data-node="${e.id}"`),"op"===e.type&&(i+=` data-op="${S(e.op)}"`);const s=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(s))"class"!==e&&"style"!==e&&/^[A-Za-z_:][\w:.-]*$/.test(e)&&(i+=` ${e}="${S(t)}"`);const r=[s.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),o=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(s.class?[S(s.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${r?` style="${S(r)}"`:""}${i}>${a}</span>`,h:n.h,d:n.d}}render(e,t){return"number"===e.type?this.number(e):"string"===e.type?this.wrap(e,["text"],this.text("text",e.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===e.type?this.wrap(e,["symbol"],this.symbol(e.value)):this.operation(e,t)}number(e){const t=/^(-?\d*\.)(\d*)\.\.$/.exec(e.value);if(t){const[,n,i]=t;let s=1;for(let e=1;2*e<=i.length;e++)if(i.slice(-e)===i.slice(-2*e,-e)){s=e;break}let r=i;for(;r.endsWith(i.slice(-s))&&r.length>=s;)r=r.slice(0,-s);const o=this.text("num",(n+r).replace(/^-/,d)),a=this.text("num",i.slice(-s));return this.wrap(e,["number"],C(o,O(this.el("over",a.html),a.h+.14,a.d)))}return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,d)))}symbol(e){return n.GREEK[e]&&(e=n.GREEK[e]),$[e]?this.text("ord",$[e]):"\\+"===e||"\\-"===e?this.text("ord",e[1]):"-∞"===e?this.text("ord","−∞"):/^[A-Za-z]$/.test(e)||/^[α-ω]$/.test(e)?this.text("var",e):/^[A-Za-z]′+$/.test(e)?O(this.el("var",S(e[0]))+this.el("prime",S(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?O(this.el("ord","Δ")+this.el("var",e[1])):/^d[A-Za-zα-ω]$/.test(e)?O(this.el("ord","d")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:i,args:s}=e,[r,o]=s,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1,leftFactor:!1}),l=m[i]??(/^[a-z0-9]+$/i.test(i)?i:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,i)=>n.needsBrackets(e,t,i)&&"/"!==t.op?this.fence(a(t)):a(t);if(v.includes(i)||"log"===i)return c(this.named(e,t));if(b[i])return c(C(this.word(b[i]),this.fence(this.list(s,t))));if(n.isCustomFunction(i))return c(this.custom(e,t));const f=n.matrixRows(e);if(f)return c(this.matrix(e,f,t));if("{}"===i&&!s.length)return c(this.text("op","∅"));if(y[i])return c(this.fence(this.list(s,t),...y[i]));if(("|"===i||"&"===i)&&s.length>=2&&s.every(N)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===i?a(e):this.fence(a(e));return c(C(s.map((t,n)=>n?[this.text("conj","|"===i?"or":"and"),e(t)]:[e(t)]).flat()))}if(u[i]&&2===s.length)return c(C(h(r,"left"),this.rel(u[i]),h(o,"right")));if(p[i]&&2===s.length)return c(C(h(r,"left"),this.bin(p[i]),h(o,"right")));switch(i){case"+":if(n.isMinusOneTimes(o)){const e=o.args[1],t=n.needsBrackets({op:"-"},e,"right")?this.fence(a(e)):a(e);return c(C(h(r,"left"),this.bin(d),this.wrap(o,["op","op-mul"],t)))}return"number"===o.type&&o.value.startsWith("-")?c(C(h(r,"left"),this.bin(d),this.wrap(o,["number"],this.text("num",o.value.slice(1))))):c(C(h(r,"left"),this.bin("+"),this.signed(o,h(o,"right"))));case"-":return c(C(h(r,"left"),this.bin(d),this.signed(o,h(o,"right"))));case"*":return c(this.product(e,t));case"/":return c(this.fraction(e,t));case"^":return c(this.power(e,t));case"_":{const e=n.bracketOp(r)&&n.precedenceOf(n.bracketOp(r))<100;return c(this.script(e?this.fence(a(r)):a(r,{forceParens:!0}),null,t,a(o,{level:t.level+1})))}case"neg":return c(C(this.text("sign",d),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r,{before:t.before})));case"pm":return c(C(this.text("sign","±"),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r)));case"!":return c(C(n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(C(this.text("sign","¬"),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r)));case"pmod":return c(C(a(r),this.fence(C(this.word("mod"),this.text("space",""),a(o)))));case"sqrt":return c(this.radical(a(r)));case"root":return c(this.radical(a(o),this.render(r,{level:t.level+2})));case"abs":return c(this.fence(a(r),"|","|"));case"floor":return c(this.fence(a(r),"⌊","⌋"));case"ceil":return c(this.fence(a(r),"⌈","⌉"));case"loglog":return c(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(a(r))))));case"logloglog":return c(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(a(r))))))));case"perm":return c(this.script(this.script(O(""),this.render(r,{level:t.level+1}),t),null,t,this.render(o,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(r),a(o),!1)));case"?:":return c(this.o.cases?this.cases(e,t):C(a(r),this.bin("?"),a(o),this.bin(":"),a(s[2])));case"sum":case"prod":{const e={op:"sum"===i?"+":"*"},t=(t,i)=>n.needsBrackets(e,t,i?"right":"left")?this.fence(a(t)):a(t);return c(C(s.map((e,n)=>n?[this.bin("sum"===i?"+":"·"),t(e,n)]:[t(e,n)]).flat()))}case"setbuilder":return c(this.fence(C(a(r),this.bin("|"),a(o)),"{","}"));case"evaluated":{const e=e=>this.render(e,{...t,level:t.level+1});return c(this.script(this.fence(a(r),"[","]"),e(s[3]),t,e(s[2])))}case"der":return c(this.derivative(e,t));case"int":return c(this.integral(s,t));case"lim":return c(this.limit(s,t));case"\\sumidx":return c(this.bigOperator("sum",s,t));case"\\prodidx":return c(this.bigOperator("prod",s,t))}throw new Error(`Inline Math cannot draw '${i}'`)}signed(e,t){return("number"===e.type?e.value.startsWith("-"):"neg"===e.op||"pm"===e.op)&&!t.fenced?this.fence(t):t}list(e,t){return C(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[i,s]=e.args;if(n.isMinusOneTimes(e))return C(this.text("sign",d),n.unaryNeedsBrackets("neg",s)?this.fence(this.render(s,t)):this.render(s,t));const r=n.bracketedSides(e);x.includes(i.op)&&(r.left=!0);const o=!e.written&&n.isImplicitProduct(i,s,r),a=function(e){for(;"op"===e.type;){if(v.includes(e.op)||"log"===e.op||b[e.op]||n.isCustomFunction(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(s),l=r.left?this.fence(this.render(i,t)):this.render(i,{...t,before:o&&!a,leftFactor:!0}),c=r.right?this.fence(this.render(s,t)):this.render(s,{...t,before:t.before});return C(l,o?O(this.el(a?"fnspace":"times","")):this.bin("cross"===e.written?"×":"·"),c)}named(e,t,n=null){const{op:i,args:s}=e,r="log"===i?s[1]:s[0];let o;o=g[i]&&"power"===this.o.inverseTrig?this.script(this.word(g[i]),this.text("num","−1"),t):this.word(i),n&&(o=this.script(o,n,t)),"log"===i&&(o=this.script(o,null,t,this.render(s[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&_(r),l=this.render(r,{...t,forceParens:!1,before:!1});return C(o,a?C(O(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const i=n.customName(e.op),s=e.args;if(M.includes(i)&&1===s.length)return this.decorate(i,this.render(s[0],t),s[0]);return C(/^[A-Za-z]′*(⁻¹)?$/.test(i)?this.symbol(i):this.word(i),O(this.el("callgap","")),this.fence(this.list(s,t)))}decorate(e,t,n){switch(e){case"boxed":return O(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return O(this.el("cancel",t.html+o("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return O(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return O(this.el("over"+(L(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const i=L(n);return O(this.el("accent"+(i?" accent-low":""),this.el(`accent-mark accent-${e}`,w[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[i,s]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&_(i,!0)&&_(s,!0)){const e={...t,leftFactor:!1},r=(t,i)=>"op"!==t.type||_(t)&&(!i||"*"!==t.op||n.isMinusOneTimes(t))?this.render(t,e):this.fence(this.render(t,e)),o=C("op"===i.type&&"neg"===i.op?this.render(i,e):r(i,!1),this.text("ord","/"),r(s,!0));return t.leftFactor?this.fence(o):o}const r=t.level>0||t.inFraction||!this.o.display?.8:1,o={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(i,o),this.render(s,o),!0,r)}stack(e,t,n=!0,i=1){const s=e=>1===i?e.html:this.el("scaled",e.html,`font-size:${A(i)}`),r=n?.06:0,o=c+r/2+.1+Math.max(l,i*e.d),h=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",s(e))+this.el("denom",s(t)),`vertical-align:${A(o)}`);return O(h,o+Math.max(a,i*e.h),Math.max(a,i*t.h)+Math.max(l,i*t.d)+.1+r/2-c)}power(e,t){const[i,s]=e.args,r={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},o=()=>this.render(s,r);if(this.o.trigPowers&&f.includes(i.op)&&q(s))return this.wrap(i,["op",`op-${i.op}`],this.named(i,t,o()));if("_"===i.op){const e=this.render(i.args[1],r);return this.wrap(i,["op","op-subscript"],this.script(this.render(i.args[0],{...t,forceParens:!0}),o(),t,e))}const a=n.needsBrackets(e,i,"left")||"number"===i.type&&i.value.startsWith("-")||"/"===i.op||v.includes(i.op)||x.includes(i.op)?this.fence(this.render(i,t)):this.render(i,{...t,forceParens:!0});return this.script(a,o(),t)}script(e,t,n,i=null,s=null){const r=n.level>0?.8:h,o=s?C(e,s):e;let a=t?Math.max(.42,e.h-.38,r*t.d+.12):0,l=i?Math.max(.2,e.d-.05,r*i.h-.45):0;if(t&&i){const e=.1-(a-r*t.d-(r*i.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${A(r)}`);if(t&&!i)return O(e.html+this.el("sup",t.html,`font-size:${A(r)};vertical-align:${A(a/r)}`),Math.max(o.h,a+r*t.h),Math.max(o.d,r*t.d-a));if(i&&!t)return O(o.html+this.el("sub",i.html,`font-size:${A(r)};vertical-align:${A(-l/r)}`),Math.max(o.h,r*i.h-l),Math.max(o.d,l+r*i.d));const d=a+r*t.h,m=l+r*i.d,u=this.el("subsup",c(t)+c(i),`vertical-align:${A(a)};height:${A(d+m)}`);return O(o.html+u,Math.max(o.h,d),Math.max(o.d,m))}radical(e,t=null){const n=Math.max(e.h,a)+.1+.06,i=Math.max(e.d,l),s=n+i,r=.5+.06*(s-1),c=o("sqrt",`${this.p}-hook`,`width:${A(r)};left:${A(-r)}`);let d="";if(t){const e=.8*h;d=this.el("rootindex",t.html,`font-size:${A(e)};vertical-align:${A((.55*s-i)/e)}`)}return O(this.el("sqrt",d+this.el("radicand",c+e.html,`margin-left:${A(r+.05)}`)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,a)+Math.max(e.d,l),s=i>1.25,r=s?.1:0,c=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const r=n+(s?Math.min(.2,.05*(i-1)):0);return{html:o(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${A(r)}`),w:r+.1}}const r={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${r} delim-${t}`,""),w:"|"===e?.18:.3}},h=c(t,"l"),d=c(n,"r");if(!s){const t=O(this.el("fence fence-line",h.html+e.html+d.html),Math.max(e.h,a),Math.max(e.d,l));return t.fenced=!0,t}const m=`padding:${A(r)} ${A(d.w)} ${A(r)} ${A(h.w)}`,u=O(this.el("fence",h.html+e.html+d.html,m),Math.max(e.h,a)+r,Math.max(e.d,l)+r);return u.fenced=!0,u}derivative(e,t){const i=this.leibniz(e,t),{by:s,at:r}=n.derivativeOrder(e);if(!r)return i;const o=e.args[1],a=this.render({...o,args:[{...s,id:void 0},r]},{...t,level:t.level+1});return this.script(this.fence(i,"","|"),null,t,a)}leibniz(e,t){const{n:i,body:s,by:r,variable:o}=n.derivativeOrder(e),a={...t,level:t.level+1},l=()=>this.text("d","d"),c=()=>i>1?this.render({type:"number",value:String(i)},a):null,h={...t,inFraction:!0},d=C(l(),c()?this.script(this.render(r,h),c(),h):this.render(r,h)),m=e=>C(c()?this.script(l(),c(),h):l(),e||[]),u=t.level>0||t.inFraction||!this.o.display?.8:1;if(o)return this.stack(m(this.render(s,h)),d,!0,u);const p=n.bracketOp(s)&&n.precedenceOf(n.bracketOp(s))<100,[f,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],v=p?this.fence(this.render(s,t),f,g):this.render(s,t);return C(this.stack(m(),d,!0,u),v)}integral(e,t){const[i,s,r,o]=e,a=e=>this.render(e,t),l=e=>e?this.render(e,{...t,level:t.level+1}):null,c=()=>this.text("var",n.firstVariable(i)||"x");let h,d=null,m=null;switch(e.length){case 1:h=c();break;case 2:n.isVariable(s)?h=a(s):(h=c(),d=l(s));break;case 3:n.isVariable(s)?(h=a(s),d=l(r)):(h=c(),d=l(s),m=l(r));break;default:h=a(s),d=l(r),m=l(o)}const u=a(i),p=O(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return C(this.bigSign("int",u,d,m,t),u,p)}bigSign(e,t,n,i,s){const r=!this.o.display||s.level>0,a=Math.max(r?.6:.95,Math.max(t.h-c,t.d+c)+.12),l=o(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${A(2*a)};width:${A(r?.38:.5)};vertical-align:${A(c-a)}`);if(!n&&!i)return O(l,c+a,a-c);const d=h,m=i||O(""),u=n||O(""),p=c+a-d*m.h;u.d;const f=this.el("limits",this.el("script",m.html,`font-size:${A(d)}`)+this.el("script lower",u.html,`font-size:${A(d)}`),`vertical-align:${A(p)};height:${A(2*a)}`);return O(l+f,c+a,a-c)}limit(e,t){const[i,s,r,o]=e,a={...t,level:t.level+1},l=e=>this.render(e,a),c=()=>this.rel("→");let h;switch(e.length){case 1:return C(this.word("lim"),O(this.el("fnspace","")),this.body(i,t));case 2:{const e=n.firstVariable(i),t="number"===s.type||"symbol"===s.type&&s.value.includes("∞");h=e&&t?C(this.text("var",e),c(),l(s)):l(s);break}case 3:h=C(l(s),c(),l(r));break;default:{const e=n.firstLeaf(o).toLowerCase().startsWith("r")?"+":d;h=C(l(s),c(),this.script(l(r),this.wrap(o,["symbol"],this.text("ord",e)),a))}}return C(this.under(this.word("lim"),h,t),this.body(i,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):O(this.el("under",e.html+this.el("script",t.html,`font-size:${A(.7)}`)),e.h,Math.max(e.d,l)+.05+.7*(t.h+t.d))}body(e,t){const i=n.bracketOp(e);return i&&n.precedenceOf(i)<n.precedenceOf("*")?this.fence(this.render(e,t)):this.render(e,t)}bigOperator(e,t,n){const[i,s,r]=t,a={...n,level:n.level+1},l=s?this.render(s,a):null,d=r?this.render(r,a):null,m=this.body(i,n);if(!this.o.display||n.level>0){const t=.55,i=o(e,`${this.p}-bigsign`,`height:${A(2*t)};width:${A(.8)};vertical-align:${A(c-t)}`);return C(this.script(O(i,c+t,t-c),d,n,l),m)}const u=.68,p=h,f=o(e,`${this.p}-bigsign`,`height:${A(1.36)};width:${A("sum"===e?1:1.05)}`),g=d?1.01+p*d.d:c-u,v=e=>this.el("script",e.html,`font-size:${A(p)}`),b=this.el("bigop",(d?v(d):"")+f+(l?v(l):""),`vertical-align:${A(g)}`);return C(O(b,.93+(d?.08+p*(d.h+d.d):0),u-c+(l?.08+p*(l.h+l.d):0)),m)}matrix(e,t,i){const s=t.map(e=>e.map(e=>this.render(e,i))),r=s.map(e=>({h:Math.max(a,...e.map(e=>e.h)),d:Math.max(l,...e.map(e=>e.d))})),o=r.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),h=c+o/2-r[0].h,d=s.map((t,n)=>{const i=t.map(e=>this.el("matrix-cell",e.html)).join(""),s=e.args[n];return s&&"op"===s.type&&"[]"===s.op?this.wrap(s,["op","op-list","matrix-row"],O(i)).html:i}).join(""),m=t[0].length,u=O(this.el("matrix",d,`grid-template-columns:repeat(${m},auto);vertical-align:${A(h)}`),c+o/2,o/2-c),[p,f]=n.MATRICES[e.op]??["[","]"];return this.fence(u,p,f)}cases(e,t){const n=[];let i=e;for(;"op"===i.type&&"?:"===i.op;)n.push([this.render(i.args[1],t),C(this.word("if"),this.text("space",""),this.render(i.args[0],t))]),i=i.args[2];"symbol"===i.type&&"unchanged"===i.value||n.push([this.render(i,t),this.word("otherwise")]);const s=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),r=s.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),o=c+r/2-s[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=O(this.el("cases",a,`vertical-align:${A(o)}`),c+r/2,r/2-c);return this.fence(l,"{","")}}function _(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||n.matrixRows(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!n.isMinusOneTimes(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||B(e)||"*"===e.op&&_(e,t)):_(e.args[0],!0)&&("neg"===e.op||_(e.args[1],!0)))}const T=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],N=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&T.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(N)),B=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(n.GREEK[e.value])),q=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[m,u,p,g,b,y,$,w])Object.setPrototypeOf(e,null);function P(e){const{id:t,from:n,...i}=e;return i.args&&(i.args=i.args.map(P)),i}const F=e=>n.toPostfix(e).join(" ");function R(e,t){const i=new Set;Z(e,t,i);const s=[];return n.walk(e,e=>{i.has(e)&&s.push(e)}),s}function Z(e,t,i){if(null!=t)if(Array.isArray(t))t.forEach(t=>Z(e,t,i));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const s=F(n.parseTree(t));return void n.walk(e,e=>{F(e)===s&&i.add(e)})}if(t.path){const n=W(e,t.path);return void(n&&i.add(n))}if(t.type){const s=F(t);n.walk(e,e=>{e!==t&&F(e)!==s||i.add(e)})}}else n.walk(e,(e,n)=>{t(e,n)&&i.add(e)});else n.walk(e,e=>{e.id===t&&i.add(e)})}function W(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}function I(e,t){const n=[],i=e=>{if(e.id===t)return!0;if("op"!==e.type)return!1;for(let t=0;t<e.args.length;t++){if(n.push(t),i(e.args[t]))return!0;n.pop()}return!1};return i(e)?n:null}function D(e){let t=0;const i=e=>{"op"===e.type&&(e.args.forEach(i),n.operator(e.op)?.arity===n.VARIADIC&&t++),e.id=t++};return i(e),e}function H(e,t={}){const{blocks:i}=t;if("string"==typeof e)return n.parseTree(e,i?{blocks:e=>i(e,t.scope)}:{});if(Array.isArray(e))return n.fromPostfix(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return n.walk(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),D(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function V(e,t){const{colors:n,highlight:i,scope:s,blocks:r,...o}=t,a=new Map;for(const[t,i]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(G(i))for(const n of R(e,t))a.set(n,`color:${i}`);const l=new Set(void 0===i?[]:R(e,i));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}function G(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}function K(e,n={}){return H(e,{...n,blocks:n.blocks??t.calculateBlock})}function X(e,n={}){return function(e,t={}){const n=H(e,t);return z(n,V(n,t)).html}(e,{...n,blocks:n.blocks??t.calculateBlock})}function U(e,t,n){const i=(e,s)=>s===t.length?n:{...e,args:e.args.map((e,n)=>n===t[s]?i(e,s+1):e)};return P(i(e,0))}function Y(e,t,{parse:n,commit:i,cancel:s,label:r="Edit",prefix:o="mv"}){const a=e.ownerDocument;if(!a||!a.body)return null;const l=a.defaultView,c=e.getBoundingClientRect(),h=a.createElement("input");h.type="text",h.className=`${o}-edit`,h.value=t,h.spellcheck=!1,h.autocomplete="off",h.setAttribute("aria-label",r);const d=()=>{h.style.width=`${Math.max(4,h.value.length+2)}ch`},m=l.getComputedStyle(e);Object.assign(h.style,{position:"absolute",left:`${c.left+l.scrollX}px`,top:`${c.top+l.scrollY+c.height/2}px`,minWidth:`${Math.max(c.width,32)}px`,fontSize:m.fontSize}),d(),a.body.appendChild(h),l.getSelection?.()?.removeAllRanges(),h.focus(),h.select();let u=!1;const p=()=>{u=!0,h.remove()};h.cancelEdit=()=>{u||(p(),s&&s())};const f=e=>{if(u)return!0;if(!e||h.value===t)return p(),s&&s(),!0;let r;try{r=n(h.value)}catch(e){return h.setAttribute("aria-invalid","true"),h.title=e.message,!1}return p(),i(r,h.value),!0};return h.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),f(!0)),"Escape"===e.key&&(e.preventDefault(),f(!1))}),h.addEventListener("input",()=>{d(),h.removeAttribute("aria-invalid"),h.removeAttribute("title")}),h.addEventListener("blur",()=>{f(!0)||f(!1)}),h}class J{constructor(e,t,n={}){this.element=e,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=Q(e,n.announce,this.p),this.set(t)}set(e,{animate:t=!1,duration:n=600,easing:i="ease-in-out"}={}){const s=K(e,this.options),{html:r}=z(s,V(s,this.options));if(this.editor){const e=this.editor;this.editor=null,e.cancelEdit?.()}const o=ee(t)&&this.tree?this.snapshot():null,a=void 0!==this.tree;return this.tree=s,this.element.innerHTML=r,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),o&&this.morph(o,{duration:n,easing:i}),a&&this.live&&this.announce(this.spoken()),this}spoken(){const e=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(e)return e;try{return i.toAudioSpeech(this.tree)}catch{return""}}announce(e){return this.say(this.live,e)}say(e,t){if(!e)return this;e.textContent="";const n=()=>{e.textContent=t};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(n)):setTimeout(n,50),this}nodes(e){return R(this.tree,e)}elements(e){return this.nodes(e).map(e=>this.elementOf(e)).filter(Boolean)}elementOf(e){return void 0===e.id?null:this.root.querySelector(`[data-node="${e.id}"]`)}highlight(e,t=`${this.p}-hl`){return this.elements(e).forEach(e=>e.classList.add(t)),this}unhighlight(e=null,t=`${this.p}-hl`){return(null===e?this.root.querySelectorAll(`.${t}`):this.elements(e)).forEach(e=>e.classList.remove(t)),this}color(e,t){return this.elements(e).forEach(e=>{e.style.color=t||""}),this}on(e,t){const n=e=>{const n=e.target.closest?.("[data-node]");if(!n||!this.root.contains(n))return;const i=Number(n.dataset.node),s=R(this.tree,i)[0];t({node:s,id:i,path:I(this.tree,i),element:n,event:e})};this.element.addEventListener(e,n);const i=[e,n];return this.handlers.push(i),this.root.classList.add(`${this.p}-clickable`),"click"===e&&(this.clicks.push(t),this.keyboard()),()=>{this.element.removeEventListener(e,n),this.clicks=this.clicks.filter(e=>e!==t),this.handlers=this.handlers.filter(e=>e!==i),!this.handlers.length&&this.root&&this.root.classList.remove(`${this.p}-clickable`)}}destroy(){if(this.editor){const e=this.editor;this.editor=null,e.cancelEdit?.()}for(const[e,t]of this.handlers)this.element.removeEventListener(e,t);this.handlers=[],this.clicks=[],this.keyListener&&this.element.removeEventListener("keydown",this.keyListener),this.editListener&&this.element.removeEventListener("dblclick",this.editListener),this.keyListener=this.editListener=null,this.keysOn=this.editOn=!1;for(const e of new Set([this.live,this.partsLive]))e&&"view"===e.dataset?.mvMadeBy&&e.remove();return this.live=this.partsLive=null,this}editable({toText:e,onEdit:t}={}){if("function"!=typeof e)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:e,onEdit:t},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.editListener=e=>{const t=e.target.closest?.("[data-node]");t&&this.root.contains(t)&&(e.preventDefault(),this.edit(R(this.tree,Number(t.dataset.node))[0]))},this.element.addEventListener("dblclick",this.editListener)),this}edit(e=this.tree,{returnFocus:t=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const n="object"==typeof e&&e&&e.type?e:this.nodes(e)[0];if(!n)return null;const s=I(this.tree,n.id)||[],r=this.elementOf(n)||this.root;let o="Edit";try{o=`Edit ${i.toAudioSpeech(n)}`}catch{}const a=()=>{t&&this.root.focus&&this.root.focus()};return this.editor=Y(r,this.editing.toText(n),{label:o,prefix:this.p,parse:e=>K(e,this.options),commit:(e,n)=>{this.set(U(this.tree,s,e),{animate:!0});const i=W(this.tree,s);t&&i&&this.focusPart(i===this.tree?null:i),a(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:s,part:n})},cancel:a}),this.editor}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||Q(this.element,!0,this.p),this.keyListener=e=>this.key(e),this.element.addEventListener("keydown",this.keyListener))}key(e){if(!this.root||!this.root.contains(e.target))return;const t=this.active;let n;switch(e.key){case"ArrowDown":n=t?this.partsOf(t)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":n=t?this.outerOf(t):void 0;break;case"ArrowRight":n=t?this.neighbor(t,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":n=t?this.neighbor(t,-1):void 0;break;case"Home":case"Escape":n=null;break;case"F2":if(!this.editing)return;return e.preventDefault(),void this.edit(t||this.tree,{returnFocus:!0});case"Enter":case" ":{e.preventDefault();const n=t||this.tree,i=this.elementOf(n)||this.root,s={node:n,id:n.id,path:I(this.tree,n.id),element:i,event:e};for(const e of this.clicks)e(s);return}default:return}e.preventDefault(),void 0!==n&&this.focusPart(n)}focusPart(e){const t=`${this.p}-focus`;this.root.querySelectorAll(`.${t}`).forEach(e=>e.classList.remove(t)),this.active=e;const n=e&&this.elementOf(e);n&&n.classList.add(t);let s="";try{s=e?i.toAudioSpeech(e):this.spoken()}catch{s=""}return this.say(this.partsLive,s),this}partsOf(e){const t=[],n=e=>{this.elementOf(e)?t.push(e):"op"===e.type&&e.args.forEach(n)};return e&&"op"===e.type&&e.args.forEach(n),t}outerOf(e){const t=I(this.tree,e.id);for(let e=t?t.length-1:-1;e>0;e--){const n=W(this.tree,t.slice(0,e));if(n&&this.elementOf(n))return n}return null}neighbor(e,t){const n=this.partsOf(this.outerOf(e)||this.tree),i=n.indexOf(e);return i<0?void 0:n[i+t]}segments(e={}){return i.toSpeechSegments(this.tree,e)}showSegment(e,t=`${this.p}-hl`){return this.unhighlight(null,t),e&&void 0!==e.id&&this.highlight(e.id,t),this}snapshot(){const e=new Map,t=n=>{const i=this.elementOf(n);if(i){const t=F(n);e.has(t)||e.set(t,[]),e.get(t).push({rect:i.getBoundingClientRect(),node:n,sig:t})}"op"===n.type&&n.args.forEach(t)};return t(this.tree),e}morph(e,{duration:t,easing:n}){if("undefined"==typeof Element||!Element.prototype.animate)return;const i=t=>{if("op"===t.type)for(const n of t.args){const t=e.get(F(n)),s=t?t.findIndex(e=>e.node===n):-1;s>-1&&t.splice(s,1),i(n)}},s=r=>{const o=this.elementOf(r),a=o&&e.get(F(r));if(a&&a.length){const{rect:e,node:s}=a.shift();i(s);const r=o.getBoundingClientRect(),l=e.left-r.left,c=e.top-r.top,h=r.width?e.width/r.width:1,d=r.height?e.height/r.height:1;return void((Math.abs(l)+Math.abs(c)>.5||Math.abs(h-1)+Math.abs(d-1)>.01)&&o.animate([{transformOrigin:"0 0",transform:`translate(${l}px, ${c}px) scale(${h}, ${d})`},{transformOrigin:"0 0",transform:"none"}],{duration:t,easing:n}))}"op"===r.type?r.args.forEach(s):o&&o.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:t,easing:n})};s(this.tree)}}function Q(e,t,n){if(!t)return null;if("object"==typeof t&&1===t.nodeType)return t;if("undefined"==typeof document||!e.insertAdjacentElement)return null;const i=e.nextElementSibling;if(i&&"view"===i.dataset?.mvMadeBy&&i.classList.contains(`${n}-sr-only`))return i;const s=document.createElement("span");return s.dataset.mvMadeBy="view",s.className=`${n}-sr-only`,s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","true"),e.insertAdjacentElement("afterend",s),s}function ee(e){return!!e&&("always"===e||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}const te=Symbol.for("inlinemath.expressions"),ne=new Set(["symbol","number"]);function ie(e){return e?"symbol"===e.type?e.value:"op"===e.type&&"_"===e.op&&2===e.args.length&&"symbol"===e.args[0].type&&ne.has(e.args[1].type)?`${e.args[0].value}_${e.args[1].value}`:null:null}function se(e){const{id:t,...n}=e;return n.args&&(n.args=n.args.map(se)),n}function re(e,t){const n=(e,i)=>{if(!i&&void 0!==e.from)return t(e.from);const{id:s,from:r,...o}=e;return o.args&&(o.args=o.args.map(e=>n(e,!1))),o};return n(e,!0)}const oe=new Set;function ae(e,t){let i=!1;const s=new Set,r=(e,o=oe)=>{const a=ie(e);if(null!==a){if(!s.has(a)&&!o.has(a)){const e=t(a);if(e){i=!0,s.add(a);const t={...r(P(e)),from:a};return s.delete(a),t}}return e}if(e.args){const t=function(e){const[t,i]=e.args,s=e=>e&&"symbol"===e.type?e.value:null;switch(e.op){case"der":return"="===i?.op?s(i.args[0])&&{name:s(i.args[0]),where:e=>0===e,index:1}:s(i)&&{name:s(i),where:e=>e<=1};case"int":{const r=s(i)??(3===e.args.length||1===e.args.length?n.firstVariable(t)||"x":null);return r&&{name:r,where:e=>0===e||1===e&&s(i)===r}}case"lim":return"→"===i?.op&&s(i.args[0])&&{name:s(i.args[0]),where:e=>0===e,index:1};case"\\sumidx":case"\\prodidx":return("="===i?.op||"∈"===i?.op)&&s(i.args[0])&&{name:s(i.args[0]),where:e=>0===e,index:1};default:return null}}(e);if(!t)return{...e,args:e.args.map(e=>r(e,o))};const i=new Set([...o,t.name]);return{...e,args:e.args.map((e,n)=>n===t.index?{...e,args:e.args.map((e,t)=>r(e,0===t?i:o))}:r(e,t.where(n)?i:o))}}return e},o=r(e);return{tree:i?se(o):e,changed:i}}const le="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",ce=new RegExp(`^(${le})\\s*\\.\\.\\s*(${le})(?:\\s+step\\s+(${le}))?(?:\\s*=\\s*(${le}))?$`);function he(e){const t=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(e);if(!t||/\]\s*,\s*\[/.test(t[1]))return null;const n=t[1].trim(),i=ce.exec(n);if(i){const e=Number(i[1]),t=Number(i[2]);if(!(t>e))return null;const n=void 0!==i[3]?Number(i[3]):Number.isInteger(e)&&Number.isInteger(t)?1:(t-e)/100;if(!(n>0))return null;const s=void 0!==i[4]?Math.min(t,Math.max(e,Number(i[4]))):e;return{kind:"slider",min:e,max:t,step:n,default:String(s)}}if(n.includes("|")){const e=n.split("|").map(e=>e.trim()).filter(Boolean);if(e.length)return{kind:"dropdown",options:e,default:e[0]}}return{kind:"textbox",default:n}}const de=Symbol("set on the page");class me{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(e){const t=new Map;for(const[n,i]of this.owners)if(n!==e)for(const[e,n]of i)t.delete(e),t.set(e,n);return t}textOf(e){const t=this.chosen.get(e.name);return t&&t.key===e.key?t.text:e.text}get(e){const t=this.definitions().get(e);return t?this.textOf(t):void 0}names(){return[...this.definitions().keys()]}set(e,t){t=String(t);const n=this.definitions().get(e);if(n&&n.input){const i=this.chosen.get(e);if(i&&i.key===n.key&&i.text===t)return this;this.chosen.set(e,{key:n.key,text:t})}else{const n=new Map(this.owners.get(de));n.set(e,{name:e,text:t,key:`page:${t}`,input:null}),this.owners.delete(de),this.owners.set(de,n)}return this.notify(null,e),this}clear(e){return void 0===e?(this.owners.clear(),this.chosen.clear()):(this.owners.get(de)?.delete(e),this.chosen.delete(e)),this.notify(null,e),this}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}own(e,t){const n=this.owners.get(e);var i,s;(i=n,s=t,(i?.size??0)===(s?.size??0)&&[...i??[]].every(([e,t])=>s?.get(e)?.key===t.key))?t&&this.owners.set(e,t):(t&&t.size?this.owners.set(e,t):this.owners.delete(e),this.notify(e))}notify(e,t){for(const n of[...this.listeners])n(e,t)}}function ue(){return new me}const pe=ue(),fe=new RegExp("(\\d+)","g");function ge(e,{delimiters:t=["$$","$","\\[","\\("]}={}){const n=[];let i="",s=0;const r=String(e).replace(/[\uE000-\uE003]/g,"�"),o=e=>0===e||"\n"===r[e-1],a=function(e){const t=new Map,n=e=>/^( {4}|\t)/.test(e);let i=0,s=!0,r=!1,o=-1;for(const a of e.split("\n")){const e=!a.trim();o>-1&&!e&&!n(a)&&(t.set(o,i-1),o=-1),o<0&&!e&&n(a)&&s&&!r&&(o=i),e||n(a)||(r=Ee.test(a)||r&&/^\s/.test(a)),s=e,i+=a.length+1}o>-1&&t.set(o,e.length);return t}(r);let l=-1;const c=new Set,h=(e,t,i)=>(n.push({source:e,display:t,raw:i,start:s,end:s+i.length}),`${n.length-1}`);for(;s<r.length;){if(a.has(s)){i+=r.slice(s,a.get(s)),s=a.get(s);continue}if(o(s)){const e=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(r.slice(s));if(e){const t=e[2],n=new RegExp(`\\n {0,3}${"`"===t[0]?"`":"~"}{${t.length},}[ \\t]*(?=\\n|$)`),o=r.slice(s+e[0].length),a=n.exec(`\n${o}`),l=a?o.slice(0,Math.max(0,a.index-1)):o,c=e[0].length+(a?a.index-1+a[0].length:o.length),d=r.slice(s,s+c);"math"===e[3].trim()?i+=h(l,!0,d):i+=d,s+=c;continue}}const e=r[s];if("`"===e){const e=/^`+/.exec(r.slice(s))[0],t=r.indexOf(e,s+e.length);if(t>-1){i+=r.slice(s,t+e.length),s=t+e.length;continue}i+=e,s+=e.length;continue}if("\\"===e){const e=r.slice(s,s+2),n="\\["===e?"\\]":"\\("===e?"\\)":null;if(n&&t.includes(e)){const t=c.has(n)?-1:r.indexOf(n,s+2);if(t<0&&c.add(n),t>-1){i+=h(r.slice(s+2,t),"\\["===e,r.slice(s,t+2)),s=t+2;continue}}i+=e,s+=2;continue}if("$"===e)if("$"===r[s+1]&&t.includes("$$")){const e=r.indexOf("$$",s+2);if(e>-1){i+=h(r.slice(s+2,e),!0,r.slice(s,e+2)),s=e+2;continue}}else if(t.includes("$")&&r[s+1]&&!/\s/.test(r[s+1])&&s+1>=l){const{end:e,stop:t}=ve(r,s+1);if(e>-1){i+=h(r.slice(s+1,e),!1,r.slice(s,e+1)),s=e+1;continue}l=t}i+=e,s++}return{text:i,math:n}}function ve(e,t){for(let n=t;n<e.length;n++){const t=e[n];if("\\"!==t){if("`"===t)return{end:-1,stop:n};if("\n"===t&&/^\n[ \t]*\n/.test(e.slice(n,n+64)))return{end:-1,stop:n};if("$"===t&&!/\s/.test(e[n-1])&&!/\d/.test(e[n+1]??"")&&"$"!==e[n+1])return{end:n,stop:n}}else n++}return{end:-1,stop:e.length}}const be=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ye=/^\s*([A-Za-z\u0370-\u03ff](?:_\{?\w+\}?)?)\s*=\s*([^=<>≤≥]+)$/;function xe(e,i,s,r){const{text:o,math:a}=ge(e,i),l=s?s.definitions(r):new Map,c=e=>s?s.textOf(e):e.text,h={...i.scope??{}},d={},m=new Map,u=new Set,p=[],f=e=>{const t=new Map;return n=>{const i=l.get(n);if(!i)return null;if(!t.has(n)){let s=null;try{s=K(c(i),e)}catch{}t.set(n,s)}return t.get(n)}};let g=!0;const v=a.map((e,s)=>{const{source:r,display:o}=e;g&&r.includes("{{")&&((()=>{for(const e of Object.keys(d))delete d[e];Object.assign(d,h);for(const e of l.keys())delete d[e];let e=[...l.values()];for(;e.length;){const n=e.filter(e=>{try{const n=t.calculate(c(e),d);if("number"==typeof n.value||"bigint"==typeof n.value||Array.isArray(n.value))return d[e.name]=n.exact?n.text:n.value,!1}catch{}return!0});if(n.length===e.length)break;e=n}const i={},s=f({});for(const e of l.keys()){const t=s(e);if(t)try{i[e]=n.toPostfix(ae(t,t=>t===e?null:s(t)).tree)}catch{}}d[te]=i})(),g=!1);const a=o?"mv-md-display":"mv-md-math",v=(e,t="")=>`<span class="${a}${t}" data-mv-md="${s}">${e}</span>`;try{const n={...i.math,display:o,blocks:i.blocks,scope:d},a=function(e){let t=e.trim();const n=t.startsWith("_");n&&(t=t.slice(1).trimStart());let i=t.indexOf(":="),s=2;i<0&&n&&(i=t.search(/(?<![<>!≤≥=])=(?!=)/),s=1);const r=n?{error:"a hidden $_…$ saves a variable: $_A := 2+2$"}:null;if(i<=0)return r;const o=t.slice(0,i).trim(),a=t.slice(i+s).trim();let l=null;try{l=/\{\{/.test(o)?null:ie(K(o))}catch{}return null!==l&&a?{hidden:n,lhs:o,name:l,rhs:a,input:he(a)}:r}(r);if(a&&a.error)throw new Error(a.error);if(a){const{name:t,input:i,hidden:r}=a,o=i?{name:t,text:i.default,input:i,key:`input:${JSON.stringify(i)}`}:{name:t,text:a.rhs,input:null,key:`expr:${a.rhs}`,start:e.start,end:e.end};let h="";if(i){const e=function(e,t){const{input:n,name:i}=e,s=`class="mv-md-input mv-md-${n.kind}" data-mv-var="${be(i)}" aria-label="${be(i)}"`;if("dropdown"===n.kind)return`<select ${s}>${n.options.map(e=>`<option value="${be(e)}"${e===t?" selected":""}>${be(e)}</option>`).join("")}</select>`;return"slider"===n.kind?`<input type="range" ${s} min="${n.min}" max="${n.max}" step="${n.step}" value="${be(t)}"><output class="mv-md-output" data-mv-out="${be(i)}">${be(t)}</output>`:`<input type="text" ${s} value="${be(t)}" size="${Math.max(4,t.length+1)}" spellcheck="false" autocomplete="off">`}(o,c(o));h=r?e:`${X(a.lhs,n)}<span class="mv-md-assign" aria-hidden="true">≔</span>${e}`,u.add(s)}else{const e=ae(K(a.rhs,n),f(n)).tree;if(!r){const t=D({type:"op",op:"=",args:[P(K(a.lhs)),void 0===e.id?e:P(e)]});p[s]=t,h=function(e,t="mv"){return e.replace(`<span class="${t}-rel">=</span>`,`<span class="${t}-rel ${t}-rel-def">≔</span>`).replace(/(aria-label="[^"]*?) equals /,"$1 is defined as ").replace("<mo>=</mo>","<mo>≔</mo>")}(X(t,n),n.prefix)}}return l.delete(t),l.set(t,o),m.set(t,o),g=!0,r&&!i?"":v(h,i?" mv-md-input-def":"")}const{tree:b,changed:y}=ae(K(r,n),f(n));y&&D(b),p[s]=b;const x=X(b,n);return!y&&!1!==i.define&&function(e,n,i){const s=ye.exec(e);if(!s||/\{\{/.test(s[2]))return!1;const r=s[1].replace(/[{}]/g,"");if(i.has(r))return!1;try{const e=t.calculate(s[2],n);if("number"==typeof e.value||"bigint"==typeof e.value||Array.isArray(e.value))return n[r]=e.exact?e.text:e.value,!0}catch{}return!1}(r,h,l)&&(g=!0),v(x)}catch(t){return`<span class="mv-md-error" data-mv-md="${s}" title="${be(t.message)}"><code>${be(e.raw)}</code></span>`}});return{text:o,math:a,drawn:v,defs:m,inputs:u,trees:p}}const $e=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,we=e=>$e.test(e.trim())?be(e.trim()):"#",ke=/\uE002(\d+)\uE003/g;function Le(e,t,n,i=[]){const s=e=>(i.push(e),`${i.length-1}`),r=e=>(e=>e.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&"))(n(e).replace(ke,(e,t)=>(i[Number(t)]??"").replace(/<[^>]*>/g,"")));let o=e;o=o.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(e,t,i)=>s(`<code>${be(n(i.trim()))}</code>`)),o=o.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(e,t)=>s(be(t))),o=o.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(e,t)=>s(`<a href="${we(t)}">${be(t)}</a>`)),t.html&&(o=o.replace(/<\/?[A-Za-z][^>]*>/g,e=>s(e))),o=o.replace(/!\[([^\[\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,t,n,i)=>s(`<img src="${we(r(n))}" alt="${be(r(t))}"${i?` title="${be(r(i))}"`:""}>`)),o=o.replace(/\[([^\[\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,o,a,l)=>s(`<a href="${we(r(a))}"${l?` title="${be(r(l))}"`:""}>${Le(o,t,n,i)}</a>`)),o=o.replace(/&(?!#\d{1,7};|#x[0-9a-f]{1,6};|[a-z][a-z0-9]{1,31};)/gi,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),o=o.replace(/(\*\*\*|___)(?=\S)([\s\S]*?\S)\1/g,"<strong><em>$2</em></strong>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*\*|__)(?![*_])([\s\S]*?\S)(\*|_)(?![*_])/g,"<em><strong>$2</strong>$4</em>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*|_)(?![*_])([\s\S]*?\S)(\*\*|__)(?![*_])/g,"<strong><em>$2</em>$4</strong>"),o=o.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),o=o.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),o=o.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),o=o.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),o=o.replace(/( {2,}|\\)\n/g,"<br>\n");for(let e=0;e<8&&/\uE002\d+\uE003/.test(o);e++)o=o.replace(ke,(e,t)=>i[Number(t)]??"");return o}const Me=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,Ee=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,Se=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,Ae=e=>Me.test(e)&&!/^ {0,3}[-=]+\s*$/.test(e)&&!/^ {0,3}(?!1[.)])\d{1,9}[.)]\s/.test(e);function Oe(e){const t=e.trim();let n=t.length;for(;n>0&&"#"===t[n-1];)n--;return n===t.length?t:0===n?"":/[ \t]/.test(t[n-1])?t.slice(0,n).trimEnd():t}function Ce(e,t,n,i=0){const s=[];let r=0;const o=e=>Le(e,t,n);if(i>100)return`<p>${o(e.join("\n"))}</p>`;for(;r<e.length;){const a=e[r];if(!a.trim()){r++;continue}const l=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(a);if(l){const t=[];for(r++;r<e.length&&!new RegExp(`^ {0,3}${"`"===l[1][0]?"`":"~"}{${l[1].length},}\\s*$`).test(e[r]);)t.push(e[r++]);r++;const i=l[2]?` class="language-${be(l[2])}"`:"";s.push(`<pre><code${i}>${be(n(t.join("\n")))}</code></pre>`);continue}const c=/^ {0,3}(#{1,6})[ \t]+/.exec(a);if(c){s.push(`<h${c[1].length}>${o(Oe(a.slice(c[0].length)))}</h${c[1].length}>`),r++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(a)){s.push("<hr>"),r++;continue}if(/^ {0,3}>/.test(a)){const o=[];for(;r<e.length&&e[r].trim()&&(/^ {0,3}>/.test(e[r])||o.length);)o.push(e[r].replace(/^ {0,3}> ?/,"")),r++;s.push(`<blockquote>\n${Ce(o,t,n,i+1)}\n</blockquote>`);continue}const h=Ee.exec(a);if(h){const o=/\d/.test(h[2]),a=o?parseInt(h[2],10):1,l=[];let c=!1;for(;r<e.length;){const t=Ee.exec(e[r]);if(!t||/\d/.test(t[2])!==o)break;const n=t[0].length,i=[e[r].slice(n)];for(r++;r<e.length;){const t=e[r];if(!t.trim()){const t=e[r+1];if(void 0!==t&&t.startsWith(" ".repeat(Math.min(n,4)))&&t.trim()){i.push(""),c=!0,r++;continue}void 0!==t&&Ee.test(t)&&(c=!0);break}if(t.startsWith(" ".repeat(Math.min(n,4))))i.push(t.slice(Math.min(n,4)));else{if(Ee.test(t)||Me.test(t))break;i.push(t)}r++}for(l.push(i);r<e.length&&!e[r].trim()&&void 0!==e[r+1]&&Ee.test(e[r+1]);)r++}const d=o?"ol":"ul",m=l.map(e=>{let s=Ce(e,t,n,i+1);return c||(s=s.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${s}</li>`});s.push(`<${d}${o&&1!==a?` start="${a}"`:""}>\n${m.join("\n")}\n</${d}>`);continue}if(a.includes("|")&&void 0!==e[r+1]&&Se.test(e[r+1])&&e[r+1].includes("-")){const t=e=>e.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(e=>e.trim()),n=t(e[r+1]).map(e=>e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":e.startsWith(":")?"left":""),i=(e,t,i)=>`<${e}${n[i]?` style="text-align:${n[i]}"`:""}>${o(t)}</${e}>`,l=t(a);r+=2;const c=[];for(;r<e.length&&e[r].trim()&&e[r].includes("|");)c.push(t(e[r++]));s.push(`<table>\n<thead><tr>${l.map((e,t)=>i("th",e,t)).join("")}</tr></thead>\n<tbody>\n${c.map(e=>`<tr>${l.map((t,n)=>i("td",e[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(a)){const t=[];for(;r<e.length&&(/^( {4}|\t)/.test(e[r])||!e[r].trim());)t.push(e[r++].replace(/^( {4}|\t)/,""));for(;t.length&&!t[t.length-1].trim();)t.pop();s.push(`<pre><code>${be(n(t.join("\n")))}</code></pre>`);continue}const d=[];for(;r<e.length&&e[r].trim()&&(!d.length||!Ae(e[r]));){if(d.length&&/^ {0,3}(=+|-+)\s*$/.test(e[r])){const t="="===e[r].trim()[0]?1:2;s.push(`<h${t}>${o(d.join("\n"))}</h${t}>`),d.length=0,r++;break}d.push(e[r].replace(/^ {0,3}/,"")),r++}d.length&&s.push(`<p>${o(d.join("\n"))}</p>`)}return s.join("\n")}function ze(e,t={},n=e=>e){return Ce(String(e).replace(/\r\n?/g,"\n").replace(/[\uE002\uE003]/g,"�").split("\n"),t,n)}function je({text:e,math:t,drawn:n},i){return(i.render?i.render(e):ze(e,i,e=>e.replace(fe,(e,n)=>t[Number(n)]?.raw??""))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(e,i)=>t[Number(i)].display&&n[Number(i)]?`<div class="mv-md-block">${n[Number(i)]}</div>`:e).replace(fe,(e,t)=>n[Number(t)]??"").replace(/<p>\s*<\/p>\n?/g,"")}const _e=new WeakMap,Te=new Set;function Ne(){for(const e of Te)e.connected()&&!e.element.isConnected&&e.stop(!0)}var Be='/*\n * Inline Math stylesheet. Everything is under .mv; colors are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight color\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d, .mv-conj { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-conj { margin: 0 0.6em; } /* x = 2 or x = 3 */\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-radicand { display: inline-block; position: relative; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n/* the hook, in the radicand\'s left margin (layout.js sets its width and that margin): from the bar\'s center\n (just below the middle of the 0.06em border above the box) to the bottom of what it holds, so the tip always meets the bar */\n.mv-hook { position: absolute; top: -0.02em; height: calc(100% + 0.02em); overflow: visible; } /* a hair below the center: never above the bar */\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n/* around one line: inline, placed from the baseline like a typed bracket (0.25em below it, 0.75em above),\n not stretched over the line box, which sits higher or lower in every font; the margins keep the widths */\n.mv-fence-line > .mv-delim { position: static; display: inline-block; vertical-align: -0.25em; height: 1em; }\n.mv-fence-line > svg.mv-delim-l { margin: 0 0.07em 0 0.03em; }\n.mv-fence-line > svg.mv-delim-r { margin: 0 0.03em 0 0.07em; }\n.mv-fence-line > span.mv-delim-l { margin: 0 0.08em 0 0.06em; }\n.mv-fence-line > span.mv-delim-r { margin: 0 0.06em 0 0.08em; }\n.mv-fence-line > .mv-delim.mv-vert.mv-delim-l { margin: 0 0.11em 0 0.07em; }\n.mv-fence-line > .mv-delim.mv-vert.mv-delim-r { margin: 0 0.07em 0 0.11em; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }\n.mv-matrix-row { display: contents; }\n.mv-matrix-cell { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; position: relative; padding-top: 0.14em; }\n.mv-over::before { content: \'\'; position: absolute; left: 0; right: 0; top: 0.21em; border-top: 0.06em solid currentColor; } /* metric */\n.mv-over-low::before { top: 0.48em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; position: relative; }\n.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: -0.27em; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; } /* metric: measured over F, h, A */\n/* ˆ ˜ ˙ ¨ are spacing marks that sit high in their em: full size, pulled down onto the letter */\n.mv-accent-hat, .mv-accent-widehat, .mv-accent-tilde, .mv-accent-dot, .mv-accent-ddot { font-size: 1em; line-height: 1; top: 0.02em; }\n/* over an italic letter the mark leans with it, right of the box\'s center */\n.mv-accent:has(> .mv-var) > .mv-accent-mark { transform: translateX(0.1em); }\n/* a letter with no ascender (x, u, α; layout.js adds -low): the mark comes down to its top */\n.mv-accent-low > .mv-accent-mark { top: 0.08em; }\n.mv-accent-low > .mv-accent-hat, .mv-accent-low > .mv-accent-widehat, .mv-accent-low > .mv-accent-tilde, .mv-accent-low > .mv-accent-dot, .mv-accent-low > .mv-accent-ddot { top: 0.31em; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n/* Windows high contrast (and other forced colors) drops backgrounds and shadows: outline a highlight instead */\n@media (forced-colors: active) {\n .mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }\n}\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the box editing a part in place (view.editable, or a Markdown textbox variable) */\n.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;\n border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }\n.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }\n/* the live region a view announces steps through ({ announce: true }): read, never seen */\n.mv-sr-only, .mv-sr-math { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */\n.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }\n.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }\n/* while a part is ringed, the whole expression\'s ring steps back so the part is the one that stands out */\n.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }\n@media (forced-colors: active) {\n .mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }\n}\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with math (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */\n.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }\n.mv-md-assign { margin: 0 0.1em; }\n.mv-md-input { font: inherit; font-size: 0.9em; }\ninput.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }\ninput.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }\ninput.mv-md-slider { vertical-align: middle; }\n.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }\n';const qe=Be;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Be,document.head.append(e)}return Object.defineProperty(e,"toText",{enumerable:!0,get:function(){return s.toText}}),e.CSS=qe,e.DEFAULTS=E,e.PATHS=r,e.View=J,e.createVariables=ue,e.extractMath=ge,e.layout=z,e.markdownToHTML=function(e,t={}){return je(xe(e,t,t.variables||null),t)},e.nodeAt=W,e.numberTree=D,e.pathOf=I,e.render=function(e,t,n={}){return new J(e,t,n)},e.renderMarkdown=ze,e.renderMarkdownInto=function(e,t,n={}){const i=void 0===n.variables?pe:n.variables||null;Ne();const s=_e.get(e);s&&s.stop(s.store!==i);let r=xe(t,n,i,e);if(e.innerHTML=je(r,n),!i)return _e.delete(e),e;i.own(e,r.defs);let o=e.isConnected;const a=t=>{const s=t.target,r=s&&s.dataset&&s.dataset.mvVar;if(void 0!==r&&e.contains(s)){if("text"===s.type)try{K(s.value,{blocks:n.blocks,scope:{}}),s.removeAttribute("aria-invalid")}catch{return void s.setAttribute("aria-invalid","true")}i.set(r,s.value)}},l=s=>{const o=s.target.closest?.("[data-node]"),a=o&&o.closest("[data-mv-md]");if(!a||!e.contains(a))return;const l=Number(a.dataset.mvMd),c=r.trees[l];if(!c)return;const h=Number(o.dataset.node),d=I(c,h)||[];let m=null;for(let e=d.length;e>=0&&!m;e--){const t=W(c,d.slice(0,e));t&&void 0!==t.from&&(m={node:t,depth:e})}const u=m&&i.definitions().get(m.node.from);if(u&&u.input&&"textbox"===u.input.kind){s.preventDefault();const t=u.name,r=e.ownerDocument.querySelector(`[data-mv-var="${CSS.escape(t)}"]`),a=n.editable&&n.editable.toText;if(!a)return void(r&&(r.focus(),r.select()));const l=e=>K(e),h=W(c,d);return void Y(o,a(re(h,l)),{label:`Edit ${t}`,parse:e=>K(e,{blocks:n.blocks}),commit:e=>{const n=U(re(m.node,l),d.slice(m.depth),e);i.set(t,a(n))}})}const p=u&&r.defs.get(u.name),f=p&&p.key===u.key&&void 0!==p.start?{...r.math[l],start:p.start,end:p.end,raw:t.slice(p.start,p.end)}:r.math[l];e.dispatchEvent(new CustomEvent("inlinemath:select",{bubbles:!0,detail:{index:l,start:f.start,end:f.end,raw:f.raw,source:f.source,id:h,path:d}}))};e.addEventListener("input",a),e.addEventListener("change",a),e.addEventListener("dblclick",l);const c=i.subscribe(s=>{s!==e&&(e.isConnected?(o=!0,Ne(),(()=>{const s=xe(t,n,i,e);s.drawn.forEach((t,n)=>{if(t===r.drawn[n]||s.inputs.has(n))return;const i=e.querySelector(`[data-mv-md="${n}"]`);i&&(i.outerHTML=t)});for(const t of e.querySelectorAll("[data-mv-var], [data-mv-out]")){const e=s.defs.get(t.dataset.mvVar??t.dataset.mvOut);if(!e)continue;const n=i.textOf(e);void 0!==t.dataset.mvOut?t.textContent=n:t.value!==n&&t!==t.ownerDocument?.activeElement&&(t.value=n)}r=s})()):o&&h(!0))});function h(t){c(),e.removeEventListener("input",a),e.removeEventListener("change",a),e.removeEventListener("dblclick",l),Te.delete(d),_e.delete(e),t&&i.own(e,null)}const d={element:e,store:i,stop:h,connected:()=>o};return Te.add(d),_e.set(e,d),e},e.select=R,e.shouldAnimate=ee,e.signature=F,e.toHTML=X,e.treeOf=K,e.variables=pe,e}({},MathZetta,MathZetta,MathZetta,MathZetta);
@@ -1,2 +1,2 @@
1
- /* Inline Math 0.4.0 — MIT license; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate (and mathzetta/text, for cas.external.js) with an import map */
2
- import{t}from"./chunks/html-6HJlblNm.js";export{a as toHTML}from"./chunks/html-6HJlblNm.js";import{l as e,b as i,s,p as r,c as o,d as h}from"./chunks/draw-Bw547gEd.js";export{D as DEFAULTS,P as PATHS,n as numberTree}from"./chunks/draw-Bw547gEd.js";import"mathzetta";import{toAudioSpeech as l,toSpeechSegments as c}from"mathzetta/speech";import{o as d,r as u}from"./chunks/edit-CCe3uoyk.js";import"mathzetta/calculate";class f{constructor(t,e,i={}){this.element=t,this.options=i,this.p=i.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=m(t,i.announce,this.p),this.set(e)}set(s,{animate:r=!1,duration:n=600,easing:o="ease-in-out"}={}){const h=t(s,this.options),{html:a}=e(h,i(h,this.options));if(this.editor){const t=this.editor;this.editor=null,t.cancelEdit?.()}const l=p(r)&&this.tree?this.snapshot():null,c=void 0!==this.tree;return this.tree=h,this.element.innerHTML=a,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),l&&this.morph(l,{duration:n,easing:o}),c&&this.live&&this.announce(this.spoken()),this}spoken(){const t=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(t)return t;try{return l(this.tree)}catch{return""}}announce(t){return this.say(this.live,t)}say(t,e){if(!t)return this;t.textContent="";const i=()=>{t.textContent=e};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(i)):setTimeout(i,50),this}nodes(t){return s(this.tree,t)}elements(t){return this.nodes(t).map(t=>this.elementOf(t)).filter(Boolean)}elementOf(t){return void 0===t.id?null:this.root.querySelector(`[data-node="${t.id}"]`)}highlight(t,e=`${this.p}-hl`){return this.elements(t).forEach(t=>t.classList.add(e)),this}unhighlight(t=null,e=`${this.p}-hl`){return(null===t?this.root.querySelectorAll(`.${e}`):this.elements(t)).forEach(t=>t.classList.remove(e)),this}color(t,e){return this.elements(t).forEach(t=>{t.style.color=e||""}),this}on(t,e){const i=t=>{const i=t.target.closest?.("[data-node]");if(!i||!this.root.contains(i))return;const n=Number(i.dataset.node),o=s(this.tree,n)[0];e({node:o,id:n,path:r(this.tree,n),element:i,event:t})};this.element.addEventListener(t,i);const n=[t,i];return this.handlers.push(n),this.root.classList.add(`${this.p}-clickable`),"click"===t&&(this.clicks.push(e),this.keyboard()),()=>{this.element.removeEventListener(t,i),this.clicks=this.clicks.filter(t=>t!==e),this.handlers=this.handlers.filter(t=>t!==n),!this.handlers.length&&this.root&&this.root.classList.remove(`${this.p}-clickable`)}}destroy(){if(this.editor){const t=this.editor;this.editor=null,t.cancelEdit?.()}for(const[t,e]of this.handlers)this.element.removeEventListener(t,e);this.handlers=[],this.clicks=[],this.keyListener&&this.element.removeEventListener("keydown",this.keyListener),this.editListener&&this.element.removeEventListener("dblclick",this.editListener),this.keyListener=this.editListener=null,this.keysOn=this.editOn=!1;for(const t of new Set([this.live,this.partsLive]))t&&"view"===t.dataset?.mvMadeBy&&t.remove();return this.live=this.partsLive=null,this}editable({toText:t,onEdit:e}={}){if("function"!=typeof t)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:t,onEdit:e},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.editListener=t=>{const e=t.target.closest?.("[data-node]");e&&this.root.contains(e)&&(t.preventDefault(),this.edit(s(this.tree,Number(e.dataset.node))[0]))},this.element.addEventListener("dblclick",this.editListener)),this}edit(e=this.tree,{returnFocus:i=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const s="object"==typeof e&&e&&e.type?e:this.nodes(e)[0];if(!s)return null;const n=r(this.tree,s.id)||[],h=this.elementOf(s)||this.root;let a="Edit";try{a=`Edit ${l(s)}`}catch{}const c=()=>{i&&this.root.focus&&this.root.focus()};return this.editor=d(h,this.editing.toText(s),{label:a,prefix:this.p,parse:e=>t(e,this.options),commit:(t,e)=>{this.set(u(this.tree,n,t),{animate:!0});const s=o(this.tree,n);i&&s&&this.focusPart(s===this.tree?null:s),c(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:n,part:e})},cancel:c}),this.editor}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||m(this.element,!0,this.p),this.keyListener=t=>this.key(t),this.element.addEventListener("keydown",this.keyListener))}key(t){if(!this.root||!this.root.contains(t.target))return;const e=this.active;let i;switch(t.key){case"ArrowDown":i=e?this.partsOf(e)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":i=e?this.outerOf(e):void 0;break;case"ArrowRight":i=e?this.neighbor(e,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":i=e?this.neighbor(e,-1):void 0;break;case"Home":case"Escape":i=null;break;case"F2":if(!this.editing)return;return t.preventDefault(),void this.edit(e||this.tree,{returnFocus:!0});case"Enter":case" ":{t.preventDefault();const i=e||this.tree,s=this.elementOf(i)||this.root,n={node:i,id:i.id,path:r(this.tree,i.id),element:s,event:t};for(const t of this.clicks)t(n);return}default:return}t.preventDefault(),void 0!==i&&this.focusPart(i)}focusPart(t){const e=`${this.p}-focus`;this.root.querySelectorAll(`.${e}`).forEach(t=>t.classList.remove(e)),this.active=t;const i=t&&this.elementOf(t);i&&i.classList.add(e);let s="";try{s=t?l(t):this.spoken()}catch{s=""}return this.say(this.partsLive,s),this}partsOf(t){const e=[],i=t=>{this.elementOf(t)?e.push(t):"op"===t.type&&t.args.forEach(i)};return t&&"op"===t.type&&t.args.forEach(i),e}outerOf(t){const e=r(this.tree,t.id);for(let t=e?e.length-1:-1;t>0;t--){const i=o(this.tree,e.slice(0,t));if(i&&this.elementOf(i))return i}return null}neighbor(t,e){const i=this.partsOf(this.outerOf(t)||this.tree),s=i.indexOf(t);return s<0?void 0:i[s+e]}segments(t={}){return c(this.tree,t)}showSegment(t,e=`${this.p}-hl`){return this.unhighlight(null,e),t&&void 0!==t.id&&this.highlight(t.id,e),this}snapshot(){const t=new Map,e=i=>{const s=this.elementOf(i);if(s){const e=h(i);t.has(e)||t.set(e,[]),t.get(e).push({rect:s.getBoundingClientRect(),node:i,sig:e})}"op"===i.type&&i.args.forEach(e)};return e(this.tree),t}morph(t,{duration:e,easing:i}){if("undefined"==typeof Element||!Element.prototype.animate)return;const s=e=>{if("op"===e.type)for(const i of e.args){const e=t.get(h(i)),r=e?e.findIndex(t=>t.node===i):-1;r>-1&&e.splice(r,1),s(i)}},r=n=>{const o=this.elementOf(n),a=o&&t.get(h(n));if(a&&a.length){const{rect:t,node:r}=a.shift();s(r);const n=o.getBoundingClientRect(),h=t.left-n.left,l=t.top-n.top,c=n.width?t.width/n.width:1,d=n.height?t.height/n.height:1;return void((Math.abs(h)+Math.abs(l)>.5||Math.abs(c-1)+Math.abs(d-1)>.01)&&o.animate([{transformOrigin:"0 0",transform:`translate(${h}px, ${l}px) scale(${c}, ${d})`},{transformOrigin:"0 0",transform:"none"}],{duration:e,easing:i}))}"op"===n.type?n.args.forEach(r):o&&o.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:e,easing:i})};r(this.tree)}}function m(t,e,i){if(!e)return null;if("object"==typeof e&&1===e.nodeType)return e;if("undefined"==typeof document||!t.insertAdjacentElement)return null;const s=t.nextElementSibling;if(s&&"view"===s.dataset?.mvMadeBy&&s.classList.contains(`${i}-sr-only`))return s;const r=document.createElement("span");return r.dataset.mvMadeBy="view",r.className=`${i}-sr-only`,r.setAttribute("aria-live","polite"),r.setAttribute("aria-atomic","true"),t.insertAdjacentElement("afterend",r),r}function p(t){return!!t&&("always"===t||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}function g(t,e,i={}){return new f(t,e,i)}export{f as View,e as layout,o as nodeAt,r as pathOf,g as render,s as select,p as shouldAnimate,h as signature,t as treeOf};
1
+ /* Inline Math 0.4.2 — MIT license; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate (and mathzetta/text, for cas.external.js) with an import map */
2
+ import{t}from"./chunks/html-ItSMWpG6.js";export{a as toHTML}from"./chunks/html-ItSMWpG6.js";import{l as e,b as i,s,p as r,c as o,d as h}from"./chunks/draw-BlziYtHI.js";export{D as DEFAULTS,P as PATHS,n as numberTree}from"./chunks/draw-BlziYtHI.js";import"mathzetta";import{toAudioSpeech as l,toSpeechSegments as c}from"mathzetta/speech";import{o as d,r as u}from"./chunks/edit-Bc3TgjS_.js";import"mathzetta/calculate";class f{constructor(t,e,i={}){this.element=t,this.options=i,this.p=i.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=m(t,i.announce,this.p),this.set(e)}set(s,{animate:r=!1,duration:n=600,easing:o="ease-in-out"}={}){const h=t(s,this.options),{html:a}=e(h,i(h,this.options));if(this.editor){const t=this.editor;this.editor=null,t.cancelEdit?.()}const l=p(r)&&this.tree?this.snapshot():null,c=void 0!==this.tree;return this.tree=h,this.element.innerHTML=a,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),l&&this.morph(l,{duration:n,easing:o}),c&&this.live&&this.announce(this.spoken()),this}spoken(){const t=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(t)return t;try{return l(this.tree)}catch{return""}}announce(t){return this.say(this.live,t)}say(t,e){if(!t)return this;t.textContent="";const i=()=>{t.textContent=e};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(i)):setTimeout(i,50),this}nodes(t){return s(this.tree,t)}elements(t){return this.nodes(t).map(t=>this.elementOf(t)).filter(Boolean)}elementOf(t){return void 0===t.id?null:this.root.querySelector(`[data-node="${t.id}"]`)}highlight(t,e=`${this.p}-hl`){return this.elements(t).forEach(t=>t.classList.add(e)),this}unhighlight(t=null,e=`${this.p}-hl`){return(null===t?this.root.querySelectorAll(`.${e}`):this.elements(t)).forEach(t=>t.classList.remove(e)),this}color(t,e){return this.elements(t).forEach(t=>{t.style.color=e||""}),this}on(t,e){const i=t=>{const i=t.target.closest?.("[data-node]");if(!i||!this.root.contains(i))return;const n=Number(i.dataset.node),o=s(this.tree,n)[0];e({node:o,id:n,path:r(this.tree,n),element:i,event:t})};this.element.addEventListener(t,i);const n=[t,i];return this.handlers.push(n),this.root.classList.add(`${this.p}-clickable`),"click"===t&&(this.clicks.push(e),this.keyboard()),()=>{this.element.removeEventListener(t,i),this.clicks=this.clicks.filter(t=>t!==e),this.handlers=this.handlers.filter(t=>t!==n),!this.handlers.length&&this.root&&this.root.classList.remove(`${this.p}-clickable`)}}destroy(){if(this.editor){const t=this.editor;this.editor=null,t.cancelEdit?.()}for(const[t,e]of this.handlers)this.element.removeEventListener(t,e);this.handlers=[],this.clicks=[],this.keyListener&&this.element.removeEventListener("keydown",this.keyListener),this.editListener&&this.element.removeEventListener("dblclick",this.editListener),this.keyListener=this.editListener=null,this.keysOn=this.editOn=!1;for(const t of new Set([this.live,this.partsLive]))t&&"view"===t.dataset?.mvMadeBy&&t.remove();return this.live=this.partsLive=null,this}editable({toText:t,onEdit:e}={}){if("function"!=typeof t)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:t,onEdit:e},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.editListener=t=>{const e=t.target.closest?.("[data-node]");e&&this.root.contains(e)&&(t.preventDefault(),this.edit(s(this.tree,Number(e.dataset.node))[0]))},this.element.addEventListener("dblclick",this.editListener)),this}edit(e=this.tree,{returnFocus:i=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const s="object"==typeof e&&e&&e.type?e:this.nodes(e)[0];if(!s)return null;const n=r(this.tree,s.id)||[],h=this.elementOf(s)||this.root;let a="Edit";try{a=`Edit ${l(s)}`}catch{}const c=()=>{i&&this.root.focus&&this.root.focus()};return this.editor=d(h,this.editing.toText(s),{label:a,prefix:this.p,parse:e=>t(e,this.options),commit:(t,e)=>{this.set(u(this.tree,n,t),{animate:!0});const s=o(this.tree,n);i&&s&&this.focusPart(s===this.tree?null:s),c(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:n,part:e})},cancel:c}),this.editor}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||m(this.element,!0,this.p),this.keyListener=t=>this.key(t),this.element.addEventListener("keydown",this.keyListener))}key(t){if(!this.root||!this.root.contains(t.target))return;const e=this.active;let i;switch(t.key){case"ArrowDown":i=e?this.partsOf(e)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":i=e?this.outerOf(e):void 0;break;case"ArrowRight":i=e?this.neighbor(e,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":i=e?this.neighbor(e,-1):void 0;break;case"Home":case"Escape":i=null;break;case"F2":if(!this.editing)return;return t.preventDefault(),void this.edit(e||this.tree,{returnFocus:!0});case"Enter":case" ":{t.preventDefault();const i=e||this.tree,s=this.elementOf(i)||this.root,n={node:i,id:i.id,path:r(this.tree,i.id),element:s,event:t};for(const t of this.clicks)t(n);return}default:return}t.preventDefault(),void 0!==i&&this.focusPart(i)}focusPart(t){const e=`${this.p}-focus`;this.root.querySelectorAll(`.${e}`).forEach(t=>t.classList.remove(e)),this.active=t;const i=t&&this.elementOf(t);i&&i.classList.add(e);let s="";try{s=t?l(t):this.spoken()}catch{s=""}return this.say(this.partsLive,s),this}partsOf(t){const e=[],i=t=>{this.elementOf(t)?e.push(t):"op"===t.type&&t.args.forEach(i)};return t&&"op"===t.type&&t.args.forEach(i),e}outerOf(t){const e=r(this.tree,t.id);for(let t=e?e.length-1:-1;t>0;t--){const i=o(this.tree,e.slice(0,t));if(i&&this.elementOf(i))return i}return null}neighbor(t,e){const i=this.partsOf(this.outerOf(t)||this.tree),s=i.indexOf(t);return s<0?void 0:i[s+e]}segments(t={}){return c(this.tree,t)}showSegment(t,e=`${this.p}-hl`){return this.unhighlight(null,e),t&&void 0!==t.id&&this.highlight(t.id,e),this}snapshot(){const t=new Map,e=i=>{const s=this.elementOf(i);if(s){const e=h(i);t.has(e)||t.set(e,[]),t.get(e).push({rect:s.getBoundingClientRect(),node:i,sig:e})}"op"===i.type&&i.args.forEach(e)};return e(this.tree),t}morph(t,{duration:e,easing:i}){if("undefined"==typeof Element||!Element.prototype.animate)return;const s=e=>{if("op"===e.type)for(const i of e.args){const e=t.get(h(i)),r=e?e.findIndex(t=>t.node===i):-1;r>-1&&e.splice(r,1),s(i)}},r=n=>{const o=this.elementOf(n),a=o&&t.get(h(n));if(a&&a.length){const{rect:t,node:r}=a.shift();s(r);const n=o.getBoundingClientRect(),h=t.left-n.left,l=t.top-n.top,c=n.width?t.width/n.width:1,d=n.height?t.height/n.height:1;return void((Math.abs(h)+Math.abs(l)>.5||Math.abs(c-1)+Math.abs(d-1)>.01)&&o.animate([{transformOrigin:"0 0",transform:`translate(${h}px, ${l}px) scale(${c}, ${d})`},{transformOrigin:"0 0",transform:"none"}],{duration:e,easing:i}))}"op"===n.type?n.args.forEach(r):o&&o.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:e,easing:i})};r(this.tree)}}function m(t,e,i){if(!e)return null;if("object"==typeof e&&1===e.nodeType)return e;if("undefined"==typeof document||!t.insertAdjacentElement)return null;const s=t.nextElementSibling;if(s&&"view"===s.dataset?.mvMadeBy&&s.classList.contains(`${i}-sr-only`))return s;const r=document.createElement("span");return r.dataset.mvMadeBy="view",r.className=`${i}-sr-only`,r.setAttribute("aria-live","polite"),r.setAttribute("aria-atomic","true"),t.insertAdjacentElement("afterend",r),r}function p(t){return!!t&&("always"===t||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}function g(t,e,i={}){return new f(t,e,i)}export{f as View,e as layout,o as nodeAt,r as pathOf,g as render,s as select,p as shouldAnimate,h as signature,t as treeOf};