@mathzetta/inlinemath 0.1.0 → 0.2.0
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.
- package/README.md +64 -20
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-Cz87Lt0N.js +2 -0
- package/dist/chunks/draw-Bev17BJJ.js +2 -0
- package/dist/chunks/edit-C65xXzo8.js +2 -0
- package/dist/chunks/edit-M68aRA5o.js +2 -0
- package/dist/chunks/{html-CvuSyhzk.js → html-BimAqn7x.js} +2 -2
- package/dist/chunks/html-CupluJSh.js +2 -0
- package/dist/chunks/lite-3Fb-OHbt.js +2 -0
- package/dist/inlinemath-cas.external.global.min.js +2 -2
- package/dist/inlinemath-cas.global.min.js +2 -2
- package/dist/inlinemath-lite-calc.global.min.js +2 -2
- package/dist/inlinemath-lite.external.global.min.js +2 -2
- package/dist/inlinemath-lite.global.min.js +2 -2
- package/dist/inlinemath.css +32 -1
- package/dist/inlinemath.external.global.min.js +2 -2
- package/dist/inlinemath.external.js +2 -2
- package/dist/inlinemath.global.min.js +2 -2
- package/dist/inlinemath.js +2 -2
- package/dist/lite-calc.js +2 -2
- package/dist/lite.external.js +2 -2
- package/dist/lite.js +2 -2
- package/dist/markdown.external.js +2 -2
- package/dist/markdown.js +2 -2
- package/inlinemath.css +32 -1
- package/package.json +3 -3
- package/src/cas.js +25 -15
- package/src/edit.js +96 -0
- package/src/glyphs.js +2 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +1 -1
- package/src/layout.js +55 -11
- package/src/markdown.d.ts +2 -2
- package/src/markdown.js +354 -39
- package/src/mathzetta.js +2 -1
- package/src/types.d.ts +77 -6
- package/src/variables.js +228 -0
- package/src/view.js +226 -6
- package/dist/chunks/calculate-BX9lJ7Ff.js +0 -2
- package/dist/chunks/draw-Cm4exbg7.js +0 -2
- package/dist/chunks/html-DWtfytjA.js +0 -2
- package/dist/chunks/lite-Bj_L6w2g.js +0 -2
package/dist/inlinemath.css
CHANGED
|
@@ -98,19 +98,42 @@ span.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-
|
|
|
98
98
|
/* ---- piecewise ------------------------------------------------------------- */
|
|
99
99
|
.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; }
|
|
100
100
|
.mv-case-value, .mv-case-cond { display: block; }
|
|
101
|
+
.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }
|
|
102
|
+
.mv-matrix-row { display: contents; }
|
|
103
|
+
.mv-matrix-cell { display: block; }
|
|
101
104
|
|
|
102
105
|
/* ---- decorations: \boxed \cancel \overline \vec … --------------------------- */
|
|
103
106
|
.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }
|
|
104
107
|
.mv-over { display: inline-block; border-top: 0.06em solid currentColor; padding-top: 0.08em; }
|
|
105
108
|
.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }
|
|
106
|
-
.mv-cancel { display: inline-block;
|
|
109
|
+
.mv-cancel { display: inline-block; position: relative; }
|
|
110
|
+
.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
|
|
107
111
|
.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }
|
|
108
112
|
.mv-accent-mark { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }
|
|
109
113
|
|
|
110
114
|
/* ---- interaction -------------------------------------------------------------- */
|
|
111
115
|
.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)); }
|
|
116
|
+
/* Windows high contrast (and other forced colours) drops backgrounds and shadows: outline a highlight instead */
|
|
117
|
+
@media (forced-colors: active) {
|
|
118
|
+
.mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }
|
|
119
|
+
}
|
|
112
120
|
.mv-clickable .mv-n { cursor: pointer; }
|
|
121
|
+
.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }
|
|
122
|
+
/* the box editing a part in place (view.editable, or a Markdown textbox variable) */
|
|
123
|
+
.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;
|
|
124
|
+
border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }
|
|
125
|
+
.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }
|
|
126
|
+
/* the live region a view announces steps through ({ announce: true }): read, never seen */
|
|
127
|
+
.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; }
|
|
113
128
|
.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }
|
|
129
|
+
/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */
|
|
130
|
+
.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }
|
|
131
|
+
.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }
|
|
132
|
+
/* while a part is ringed, the whole expression's ring steps back so the part is the one that stands out */
|
|
133
|
+
.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }
|
|
134
|
+
@media (forced-colors: active) {
|
|
135
|
+
.mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }
|
|
136
|
+
}
|
|
114
137
|
|
|
115
138
|
/* ---- steps (stepsHTML from '@mathzetta/inlinemath/cas') ---------------------------------------- */
|
|
116
139
|
.mv-steps { margin: 0; padding-left: 1.6em; }
|
|
@@ -125,3 +148,11 @@ span.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-
|
|
|
125
148
|
.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }
|
|
126
149
|
.mv-md-block { margin: 0.8em 0; }
|
|
127
150
|
.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }
|
|
151
|
+
/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */
|
|
152
|
+
.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }
|
|
153
|
+
.mv-md-assign { margin: 0 0.1em; }
|
|
154
|
+
.mv-md-input { font: inherit; font-size: 0.9em; }
|
|
155
|
+
input.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }
|
|
156
|
+
input.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }
|
|
157
|
+
input.mv-md-slider { vertical-align: middle; }
|
|
158
|
+
.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
var InlineMath=function(e,t,n,i){"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.015"},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 s(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 l=.8,a=.2,o=.25,c=.7,h="−",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","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod"},d={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},p={"±":"±","∪":"∪","∩":"∩",mod:"mod"},u=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],f={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},g=[...u,...Object.keys(f),"ln"],v={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},b={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},$={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},y={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},x=["boxed","overline","bar","underline","cancel",...Object.keys(y)],w={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,attributes:null,style:null},k=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),M=e=>+e.toFixed(3)+"em",L=(e,t=l,n=a)=>({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(l,...t.map(e=>e.h)),d:Math.max(a,...t.map(e=>e.d))}}function S(e,t={}){const n=new E({...w,...t}),r=n.render(e,{level:0}),s=`${n.p}${n.o.display?` ${n.p}-display`:""}`,l=function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):i.toSpeech(e)}catch{return null}}(e,n.o.label),a=null===l?r.html:r.html.replace(/^<span /,'<span aria-hidden="true" ');return{html:`<span class="${s}"${null===l?"":` role="math" aria-label="${k(l)}"`}>${a}</span>`,h:r.h,d:r.d}}class E{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=L(this.el(e,k(t)));return n.leaf={kind:e,content:k(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="${k(e.op)}"`);const r=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(r))"class"!==e&&"style"!==e&&(i+=` ${e}="${k(t)}"`);const s=[r.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),l=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(r.class?[r.class]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${l}"${s?` style="${k(s)}"`:""}${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){return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,h)))}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)?L(this.el("var",k(e[0]))+this.el("prime",k(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?L(this.el("ord","Δ")+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:r}=e,[s,l]=r,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1}),o=m[i]??(/^[a-z0-9]+$/i.test(i)?i:"other"),c=t=>this.wrap(e,["op",`op-${o}`],t),u=(t,i)=>n.needsBrackets(e,t,i)&&"/"!==t.op?this.fence(a(t)):a(t);if(g.includes(i)||"log"===i)return c(this.named(e,t));if(v[i])return c(C(this.word(v[i]),this.fence(this.list(r,t))));if(n.isCustomFunction(i))return c(this.custom(e,t));if(b[i])return c(this.fence(this.list(r,t),...b[i]));if(d[i]&&2===r.length)return c(C(u(s,"left"),this.rel(d[i]),u(l,"right")));if(p[i]&&2===r.length)return c(C(u(s,"left"),this.bin(p[i]),u(l,"right")));switch(i){case"+":return n.isMinusOneTimes(l)?c(C(u(s,"left"),this.bin(h),this.wrap(l,["op","op-mul"],this.render(l.args[1],t)))):"number"===l.type&&l.value.startsWith("-")?c(C(u(s,"left"),this.bin(h),this.wrap(l,["number"],this.text("num",l.value.slice(1))))):c(C(u(s,"left"),this.bin("+"),this.signed(l,u(l,"right"))));case"-":return c(C(u(s,"left"),this.bin(h),this.signed(l,u(l,"right"))));case"*":return c(this.product(e,t));case"/":return c(this.fraction(e,t));case"^":return c(this.power(e,t));case"_":return c(this.script(a(s,{forceParens:!0}),null,t,a(l,{level:t.level+1})));case"neg":return c(C(this.text("sign",h),n.unaryNeedsBrackets(i,s)?this.fence(a(s)):a(s,{before:t.before})));case"pm":return c(C(this.text("sign","±"),n.unaryNeedsBrackets(i,s)?this.fence(a(s)):a(s)));case"!":return c(C(n.unaryNeedsBrackets(i,s)?this.fence(a(s)):a(s,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(C(this.text("sign","¬"),n.unaryNeedsBrackets(i,s)?this.fence(a(s)):a(s)));case"pmod":return c(C(a(s),this.fence(C(this.word("mod"),this.text("space",""),a(l)))));case"sqrt":return c(this.radical(a(s)));case"root":return c(this.radical(a(l),this.render(s,{level:t.level+2})));case"abs":return c(this.fence(a(s),"|","|"));case"floor":return c(this.fence(a(s),"⌊","⌋"));case"ceil":return c(this.fence(a(s),"⌈","⌉"));case"loglog":return c(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(a(s))))));case"logloglog":return c(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(C(this.word("ln"),this.fence(a(s))))))));case"perm":return c(this.script(this.script(L(""),this.render(s,{level:t.level+1}),t),null,t,this.render(l,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(s),a(l),!1)));case"?:":return c(this.o.cases?this.cases(e,t):C(a(s),this.bin("?"),a(l),this.bin(":"),a(r[2])));case"sum":return c(C(r.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(C(r.map((e,t)=>t?[this.bin("·"),a(e)]:[a(e)]).flat()));case"der":return c(this.derivative(e,t));case"int":return c(this.integral(r,t));case"lim":return c(this.limit(r,t));case"\\sumidx":return c(this.bigOperator("sum",r,t));case"\\prodidx":return c(this.bigOperator("prod",r,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,r]=e.args;if(n.isMinusOneTimes(e))return C(this.text("sign",h),this.render(r,t));const s=n.bracketedSides(e),l=n.isImplicitProduct(i,r,s),a=function(e){for(;"op"===e.type;){if(g.includes(e.op)||"log"===e.op||v[e.op]||n.isCustomFunction(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(r),o=s.left?this.fence(this.render(i,t)):this.render(i,{...t,before:l&&!a}),c=s.right?this.fence(this.render(r,t)):this.render(r,{...t,before:t.before});return C(o,l?L(this.el(a?"fnspace":"times","")):this.bin("·"),c)}named(e,t,n=null){const{op:i,args:r}=e,s="log"===i?r[1]:r[0];let l;l=f[i]&&"power"===this.o.inverseTrig?this.script(this.word(f[i]),this.text("num","−1"),t):this.word(i),n&&(l=this.script(l,n,t)),"log"===i&&(l=this.script(l,null,t,this.render(r[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&z(s),o=this.render(s,{...t,forceParens:!1,before:!1});return C(l,a?C(L(this.el("fnspace","")),o):this.fence(o))}custom(e,t){const i=n.customName(e.op),r=e.args;if(x.includes(i)&&1===r.length)return this.decorate(i,this.render(r[0],t));return C(/^[A-Za-z]′*(⁻¹)?$/.test(i)?this.symbol(i):this.word(i),L(this.el("callgap","")),this.fence(this.list(r,t)))}decorate(e,t){switch(e){case"boxed":return L(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return L(this.el("cancel",t.html),t.h,t.d);case"underline":return L(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return L(this.el("over",t.html),t.h+.14,t.d);default:return L(this.el("accent",this.el("accent-mark",y[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,i]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&z(n,!0)&&z(i,!0)){const e=e=>"op"!==e.type||z(e)?this.render(e,t):this.fence(this.render(e,t));return C(e(n),this.text("ord","/"),e(i))}const r=t.level>0||t.inFraction||!this.o.display?.8:1,s={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,s),this.render(i,s),!0,r)}stack(e,t,n=!0,i=1){const r=e=>1===i?e.html:this.el("scaled",e.html,`font-size:${M(i)}`),s=n?.06:0,c=o+s/2+.1+Math.max(a,i*e.d),h=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",r(e))+this.el("denom",r(t)),`vertical-align:${M(c)}`);return L(h,c+Math.max(l,i*e.h),Math.max(l,i*t.h)+Math.max(a,i*t.d)+.1+s/2-o)}power(e,t){const[i,r]=e.args,s={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1},l=()=>this.render(r,s);if(this.o.trigPowers&&u.includes(i.op)&&O(r))return this.wrap(i,["op",`op-${i.op}`],this.named(i,t,l()));if("_"===i.op){const e=this.render(i.args[1],s);return this.wrap(i,["op","op-subscript"],this.script(this.render(i.args[0],{...t,forceParens:!0}),l(),t,e))}const a=n.needsBrackets(e,i,"left")||"number"===i.type&&i.value.startsWith("-")||"/"===i.op||g.includes(i.op)?this.fence(this.render(i,t)):this.render(i,{...t,forceParens:!0});return this.script(a,l(),t)}script(e,t,n,i=null,r=null){const s=n.level>0?.8:c,l=r?C(e,r):e;let a=t?Math.max(.42,e.h-.38,s*t.d+.12):0,o=i?Math.max(.2,e.d-.05,s*i.h-.45):0;if(t&&i){const e=.1-(a-s*t.d-(s*i.h-o));e>0&&(o+=e)}const h=e=>this.el("script",e.html,`font-size:${M(s)}`);if(t&&!i)return L(e.html+this.el("sup",t.html,`font-size:${M(s)};vertical-align:${M(a/s)}`),Math.max(l.h,a+s*t.h),Math.max(l.d,s*t.d-a));if(i&&!t)return L(l.html+this.el("sub",i.html,`font-size:${M(s)};vertical-align:${M(-o/s)}`),Math.max(l.h,s*i.h-o),Math.max(l.d,o+s*i.d));const m=a+s*t.h,d=o+s*i.d,p=this.el("subsup",h(t)+h(i),`vertical-align:${M(a)};height:${M(m+d)}`);return L(l.html+p,Math.max(l.h,m),Math.max(l.d,d))}radical(e,t=null){const n=Math.max(e.h,l)+.1+.06,i=Math.max(e.d,a),r=n+i,o=s("sqrt",`${this.p}-hook`,`height:${M(r)};width:${M(.5+.06*(r-1))};vertical-align:${M(-i)}`);let h="";if(t){const e=.8*c;h=this.el("rootindex",t.html,`font-size:${M(e)};vertical-align:${M((.55*r-i)/e)}`)}return L(this.el("sqrt",h+o+this.el("radicand",e.html)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,l)+Math.max(e.d,a),r=i>1.25,o=r?.1:0,c=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const l=n+(r?Math.min(.2,.05*(i-1)):0);return{html:s(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${M(l)}`),w:l+.1}}const l={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${l} delim-${t}`,""),w:"|"===e?.18:.3}},h=c(t,"l"),m=c(n,"r"),d=`padding:${M(o)} ${M(m.w)} ${M(o)} ${M(h.w)}`,p=L(this.el("fence",h.html+e.html+m.html,d),Math.max(e.h,l)+o,Math.max(e.d,a)+o);return p.fenced=!0,p}derivative(e,t){const{n:i,body:r,by:s,variable:l}=n.derivativeOrder(e),a={...t,level:t.level+1},o=()=>this.text("d","d"),c=()=>i>1?this.render({type:"number",value:String(i)},a):null,h={...t,inFraction:!0},m=C(o(),c()?this.script(this.render(s,h),c(),h):this.render(s,h)),d=e=>C(c()?this.script(o(),c(),h):o(),e||[]),p=t.level>0||t.inFraction||!this.o.display?.8:1;if(l)return this.stack(d(this.render(r,h)),m,!0,p);const u=n.bracketOp(r)&&n.precedenceOf(n.bracketOp(r))<100,[f,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],v=u?this.fence(this.render(r,t),f,g):this.render(r,t);return C(this.stack(d(),m,!0,p),v)}integral(e,t){const[i,r,s,l]=e,a=e=>this.render(e,t),o=e=>e?this.render(e,{...t,level:t.level+1}):null,c=()=>this.text("var",n.firstVariable(i)||"x");let h,m=null,d=null;switch(e.length){case 1:h=c();break;case 2:n.isVariable(r)?h=a(r):(h=c(),m=o(r));break;case 3:n.isVariable(r)?(h=a(r),m=o(s)):(h=c(),m=o(r),d=o(s));break;default:h=a(r),m=o(s),d=o(l)}const p=a(i),u=L(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return C(this.bigSign("int",p,m,d,t),p,u)}bigSign(e,t,n,i,r){const l=!this.o.display||r.level>0,a=Math.max(l?.6:.95,Math.max(t.h-o,t.d+o)+.12),h=s(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${M(2*a)};width:${M(l?.38:.5)};vertical-align:${M(o-a)}`);if(!n&&!i)return L(h,o+a,a-o);const m=c,d=i||L(""),p=n||L(""),u=o+a-m*d.h;p.d;const f=this.el("limits",this.el("script",d.html,`font-size:${M(m)}`)+this.el("script lower",p.html,`font-size:${M(m)}`),`vertical-align:${M(u)};height:${M(2*a)}`);return L(h+f,o+a,a-o)}limit(e,t){const[i,r,s,l]=e,a={...t,level:t.level+1},o=e=>this.render(e,a),c=()=>this.rel("→");let m;switch(e.length){case 1:return C(this.word("lim"),L(this.el("fnspace","")),this.render(i,t));case 2:{const e=n.firstVariable(i),t="number"===r.type||"symbol"===r.type&&r.value.includes("∞");m=e&&t?C(this.text("var",e),c(),o(r)):o(r);break}case 3:m=C(o(r),c(),o(s));break;default:{const e=n.firstLeaf(l).toLowerCase().startsWith("r")?"+":h;m=C(o(r),c(),this.script(o(s),this.wrap(l,["symbol"],this.text("ord",e)),a))}}return C(this.under(this.word("lim"),m,t),this.render(i,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):L(this.el("under",e.html+this.el("script",t.html,`font-size:${M(.7)}`)),e.h,Math.max(e.d,a)+.05+.7*(t.h+t.d))}bigOperator(e,t,n){const[i,r,l]=t,a={...n,level:n.level+1},h=r?this.render(r,a):null,m=l?this.render(l,a):null,d=this.render(i,n);if(!this.o.display||n.level>0){const t=.55,i=s(e,`${this.p}-bigsign`,`height:${M(2*t)};width:${M(.8)};vertical-align:${M(o-t)}`);return C(this.script(L(i,o+t,t-o),m,n,h),d)}const p=.68,u=c,f=s(e,`${this.p}-bigsign`,`height:${M(1.36)};width:${M("sum"===e?1:1.05)}`),g=m?1.01+u*m.d:o-p,v=e=>this.el("script",e.html,`font-size:${M(u)}`),b=this.el("bigop",(m?v(m):"")+f+(h?v(h):""),`vertical-align:${M(g)}`);return C(L(b,.93+(m?.08+u*(m.h+m.d):0),p-o+(h?.08+u*(h.h+h.d):0)),d)}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];n.push([this.render(i,t),this.word("otherwise")]);const r=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),s=r.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),l=o+s/2-r[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),c=L(this.el("cases",a,`vertical-align:${M(l)}`),o+s/2,s/2-o);return this.fence(c,"{","")}}function z(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!n.isMinusOneTimes(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||j(e)||"*"===e.op&&z(e,t)):z(e.args[0],!0)&&("neg"===e.op||z(e.args[1],!0)))}const j=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(n.GREEK[e.value])),O=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const T=e=>n.toPostfix(e).join(" ");function A(e,t){const i=new Set;B(e,t,i);const r=[];return n.walk(e,e=>{i.has(e)&&r.push(e)}),r}function B(e,t,i){if(null!=t)if(Array.isArray(t))t.forEach(t=>B(e,t,i));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const r=T(n.parseTree(t));return void n.walk(e,e=>{T(e)===r&&i.add(e)})}if(t.path){const n=P(e,t.path);return void(n&&i.add(n))}if(t.type){const r=T(t);n.walk(e,e=>{e!==t&&T(e)!==r||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 P(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 Z(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 q(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 N(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)return void 0===e.id?q(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function R(e,t){const{colors:n,highlight:i,scope:r,blocks:s,...l}=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(W(i))for(const n of A(e,t))a.set(n,`color:${i}`);const o=new Set(void 0===i?[]:A(e,i));if(!a.size&&!o.size)return l;const c=l.prefix||"mv";return{...l,style:e=>[a.get(e),l.style&&l.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...l.attributes?l.attributes(e):{}};return o.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}function W(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}function _(e,n={}){return N(e,{...n,blocks:n.blocks??t.calculateBlock})}function I(e,n={}){return function(e,t={}){const n=N(e,t);return S(n,R(n,t)).html}(e,{...n,blocks:n.blocks??t.calculateBlock})}class F{constructor(e,t,n={}){this.element=e,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.set(t)}set(e,{animate:t=!1,duration:n=600,easing:i="ease-in-out"}={}){const r=t&&this.tree?this.snapshot():null;return this.tree=_(e,this.options),this.element.innerHTML=S(this.tree,R(this.tree,this.options)).html,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),r&&this.morph(r,{duration:n,easing:i}),this}nodes(e){return A(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),r=A(this.tree,i)[0];t({node:r,id:i,path:Z(this.tree,i),element:n,event:e})};return this.element.addEventListener(e,n),this.handlers.push([e,n]),this.root.classList.add(`${this.p}-clickable`),()=>this.element.removeEventListener(e,n)}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=T(n);e.has(t)||e.set(t,[]),e.get(t).push(i.getBoundingClientRect())}"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=r=>{const s=this.elementOf(r),l=s&&e.get(T(r));if(l&&l.length){const e=l.shift(),i=s.getBoundingClientRect(),r=e.left-i.left,a=e.top-i.top,o=i.width?e.width/i.width:1,c=i.height?e.height/i.height:1;return void((Math.abs(r)+Math.abs(a)>.5||Math.abs(o-1)+Math.abs(c-1)>.01)&&s.animate([{transformOrigin:"0 0",transform:`translate(${r}px, ${a}px) scale(${o}, ${c})`},{transformOrigin:"0 0",transform:"none"}],{duration:t,easing:n}))}"op"===r.type?r.args.forEach(i):s&&s.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:t,easing:n})};i(this.tree)}}const H=new RegExp("(\\d+)","g");function V(e,{delimiters:t=["$$","$","\\[","\\("]}={}){const n=[];let i="",r=0;const s=String(e),l=e=>0===e||"\n"===s[e-1],a=(e,t,i)=>(n.push({source:e,display:t,raw:i}),`${n.length-1}`);for(;r<s.length;){if(l(r)){const e=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(s.slice(r));if(e){const t=e[2],n=new RegExp(`\\n {0,3}${"`"===t[0]?"`":"~"}{${t.length},}[ \\t]*(?=\\n|$)`),l=s.slice(r+e[0].length),o=n.exec(`\n${l}`),c=o?l.slice(0,Math.max(0,o.index-1)):l,h=e[0].length+(o?o.index-1+o[0].length:l.length),m=s.slice(r,r+h);"math"===e[3].trim()?i+=a(c,!0,m):i+=m,r+=h;continue}}const e=s[r];if("`"===e){const e=/^`+/.exec(s.slice(r))[0],t=s.indexOf(e,r+e.length);if(t>-1){i+=s.slice(r,t+e.length),r=t+e.length;continue}i+=e,r+=e.length;continue}if("\\"===e){const e=s.slice(r,r+2),n="\\["===e?"\\]":"\\("===e?"\\)":null;if(n&&t.includes(e)){const t=s.indexOf(n,r+2);if(t>-1){i+=a(s.slice(r+2,t),"\\["===e,s.slice(r,t+2)),r=t+2;continue}}i+=e,r+=2;continue}if("$"===e)if("$"===s[r+1]&&t.includes("$$")){const e=s.indexOf("$$",r+2);if(e>-1){i+=a(s.slice(r+2,e),!0,s.slice(r,e+2)),r=e+2;continue}}else if(t.includes("$")&&s[r+1]&&!/\s/.test(s[r+1])){const e=G(s,r+1);if(e>-1){i+=a(s.slice(r+1,e),!1,s.slice(r,e+1)),r=e+1;continue}}i+=e,r++}return{text:i,math:n}}function G(e,t){for(let n=t;n<e.length;n++){const t=e[n];if("\\"!==t){if("`"===t)return-1;if("\n"===t&&/^\n[ \t]*\n/.test(e.slice(n)))return-1;if("$"===t&&!/\s/.test(e[n-1])&&!/\d/.test(e[n+1]??"")&&"$"!==e[n+1])return n}else n++}return-1}const K=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),D=/^\s*([A-Za-zͰ-Ͽ](?:_\{?\w+\}?)?)\s*(?::=|=)\s*([^=<>≤≥]+)$/;function U(e,n,i){const{source:r,display:s}=e;try{const e=I(r,{...n.math,display:s,blocks:n.blocks,scope:i});return!1!==n.define&&function(e,n){const i=D.exec(e);if(!i||/\{\{/.test(i[2]))return;try{const e=t.calculate(i[2],n);"number"!=typeof e.value&&"bigint"!=typeof e.value||(n[i[1].replace(/[{}]/g,"")]=e.exact?e.text:e.value)}catch{}}(r,i),s?`<span class="mv-md-display">${e}</span>`:`<span class="mv-md-math">${e}</span>`}catch(t){return`<span class="mv-md-error" title="${K(t.message)}"><code>${K(e.raw)}</code></span>`}}const X=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,J=e=>X.test(e.trim())?K(e.trim()):"#";function Q(e,t,n){const i=[],r=e=>(i.push(e),`${i.length-1}`);let s=e;return s=s.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(e,t,i)=>r(`<code>${K(n(i.trim()))}</code>`)),s=s.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(e,t)=>r(K(t))),s=s.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(e,t)=>r(`<a href="${J(t)}">${K(t)}</a>`)),t.html&&(s=s.replace(/<\/?[A-Za-z][^>]*>/g,e=>r(e))),s=s.replace(/!\[([^\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,t,n,i)=>r(`<img src="${J(n)}" alt="${K(t)}"${i?` title="${K(i)}"`:""}>`)),s=s.replace(/\[([^\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,i,s,l)=>r(`<a href="${J(s)}"${l?` title="${K(l)}"`:""}>${Q(i,t,n)}</a>`)),s=K(s),s=s.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),s=s.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),s=s.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),s=s.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),s=s.replace(/( {2,}|\\)\n/g,"<br>\n"),s.replace(/(\d+)/g,(e,t)=>i[Number(t)])}const Y=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,ee=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,te=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;function ne(e,t,n){const i=[];let r=0;const s=e=>Q(e,t,n);for(;r<e.length;){const l=e[r];if(!l.trim()){r++;continue}const a=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(l);if(a){const t=[];for(r++;r<e.length&&!new RegExp(`^ {0,3}${"`"===a[1][0]?"`":"~"}{${a[1].length},}\\s*$`).test(e[r]);)t.push(e[r++]);r++;const s=a[2]?` class="language-${K(a[2])}"`:"";i.push(`<pre><code${s}>${K(n(t.join("\n")))}</code></pre>`);continue}const o=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/.exec(l);if(o){i.push(`<h${o[1].length}>${s(o[2])}</h${o[1].length}>`),r++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(l)){i.push("<hr>"),r++;continue}if(/^ {0,3}>/.test(l)){const s=[];for(;r<e.length&&e[r].trim()&&(/^ {0,3}>/.test(e[r])||s.length);)s.push(e[r].replace(/^ {0,3}> ?/,"")),r++;i.push(`<blockquote>\n${ne(s,t,n)}\n</blockquote>`);continue}const c=ee.exec(l);if(c){const s=/\d/.test(c[2]),l=s?parseInt(c[2],10):1,a=[];let o=!1;for(;r<e.length;){const t=ee.exec(e[r]);if(!t||/\d/.test(t[2])!==s)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(""),o=!0,r++;continue}void 0!==t&&ee.test(t)&&(o=!0);break}if(t.startsWith(" ".repeat(Math.min(n,4))))i.push(t.slice(Math.min(n,4)));else{if(ee.test(t)||Y.test(t))break;i.push(t)}r++}for(a.push(i);r<e.length&&!e[r].trim()&&void 0!==e[r+1]&&ee.test(e[r+1]);)r++}const h=s?"ol":"ul",m=a.map(e=>{let i=ne(e,t,n);return o||(i=i.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${i}</li>`});i.push(`<${h}${s&&1!==l?` start="${l}"`:""}>\n${m.join("\n")}\n</${h}>`);continue}if(l.includes("|")&&void 0!==e[r+1]&&te.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":""),a=(e,t,i)=>`<${e}${n[i]?` style="text-align:${n[i]}"`:""}>${s(t)}</${e}>`,o=t(l);r+=2;const c=[];for(;r<e.length&&e[r].trim()&&e[r].includes("|");)c.push(t(e[r++]));i.push(`<table>\n<thead><tr>${o.map((e,t)=>a("th",e,t)).join("")}</tr></thead>\n<tbody>\n${c.map(e=>`<tr>${o.map((t,n)=>a("td",e[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(l)){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();i.push(`<pre><code>${K(n(t.join("\n")))}</code></pre>`);continue}const h=[];for(;r<e.length&&e[r].trim()&&(!h.length||!Y.test(e[r])||/^ {0,3}[-=]+\s*$/.test(e[r]));){if(h.length&&/^ {0,3}(=+|-+)\s*$/.test(e[r])){const t="="===e[r].trim()[0]?1:2;i.push(`<h${t}>${s(h.join("\n"))}</h${t}>`),h.length=0,r++;break}h.push(e[r].replace(/^ {0,3}/,"")),r++}h.length&&i.push(`<p>${s(h.join("\n"))}</p>`)}return i.join("\n")}function ie(e,t={},n=e=>e){return ne(String(e).replace(/\r\n?/g,"\n").split("\n"),t,n)}function re(e,t={}){const{text:n,math:i}=V(e,t),r={...t.scope??{}},s=i.map(e=>U(e,t,r));return(t.render?t.render(n):ie(n,t,e=>e.replace(H,(e,t)=>i[Number(t)].raw))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(e,t)=>i[Number(t)].display?`<div class="mv-md-block">${s[Number(t)]}</div>`:e).replace(H,(e,t)=>s[Number(t)])}var se='/*\n * Inline Math stylesheet. Everything is under .mv; colours 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 colour\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 { 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-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-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\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\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; border-top: 0.06em solid currentColor; padding-top: 0.08em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; background: linear-gradient(to top right, transparent calc(50% - 0.04em), currentColor calc(50% - 0.03em), currentColor calc(50% + 0.03em), transparent calc(50% + 0.04em)); }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }\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.mv-clickable .mv-n { cursor: pointer; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\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 maths (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';const le=se;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=se,document.head.append(e)}return e.CSS=le,e.DEFAULTS=w,e.PATHS=r,e.View=F,e.extractMath=V,e.layout=S,e.markdownToHTML=re,e.nodeAt=P,e.numberTree=q,e.pathOf=Z,e.render=function(e,t,n={}){return new F(e,t,n)},e.renderMarkdown=ie,e.renderMarkdownInto=function(e,t,n={}){return e.innerHTML=re(t,n),e},e.select=A,e.signature=T,e.toHTML=I,e.treeOf=_,e}({},MathZetta,MathZetta,MathZetta);
|
|
1
|
+
/* Inline Math 0.2.0 — MIT licence; 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.015"},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","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},u={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},p={"±":"±","∪":"∪","∩":"∩",mod:"mod"},f=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],g={arcsin:"sin",arccos:"cos",arctan:"tan",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={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},$={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},w=["boxed","overline","bar","underline","cancel",...Object.keys($)],k={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},M=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),L=e=>+e.toFixed(3)+"em",E=(e,t=a,n=l)=>({html:e,h:t,d:n});function A(...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 S(e,t={}){const n=new C({...k,...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="${M(a)}"`}>${l}${o}</span>`,h:s.h,d:s.d}}class C{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=E(this.el(e,M(t)));return n.leaf={kind:e,content:M(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="${M(e.op)}"`);const s=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(s))"class"!==e&&"style"!==e&&(i+=` ${e}="${M(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.class]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${r?` style="${M(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){return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,d)))}symbol(e){return n.GREEK[e]&&(e=n.GREEK[e]),x[e]?this.text("ord",x[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)?E(this.el("var",M(e[0]))+this.el("prime",M(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?E(this.el("ord","Δ")+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}),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(A(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(y[i])return c(this.fence(this.list(s,t),...y[i]));if(u[i]&&2===s.length)return c(A(h(r,"left"),this.rel(u[i]),h(o,"right")));if(p[i]&&2===s.length)return c(A(h(r,"left"),this.bin(p[i]),h(o,"right")));switch(i){case"+":return n.isMinusOneTimes(o)?c(A(h(r,"left"),this.bin(d),this.wrap(o,["op","op-mul"],this.render(o.args[1],t)))):"number"===o.type&&o.value.startsWith("-")?c(A(h(r,"left"),this.bin(d),this.wrap(o,["number"],this.text("num",o.value.slice(1))))):c(A(h(r,"left"),this.bin("+"),this.signed(o,h(o,"right"))));case"-":return c(A(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"_":return c(this.script(a(r,{forceParens:!0}),null,t,a(o,{level:t.level+1})));case"neg":return c(A(this.text("sign",d),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r,{before:t.before})));case"pm":return c(A(this.text("sign","±"),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r)));case"!":return c(A(n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(A(this.text("sign","¬"),n.unaryNeedsBrackets(i,r)?this.fence(a(r)):a(r)));case"pmod":return c(A(a(r),this.fence(A(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(A(this.word("ln"),this.fence(A(this.word("ln"),this.fence(a(r))))));case"logloglog":return c(A(this.word("ln"),this.fence(A(this.word("ln"),this.fence(A(this.word("ln"),this.fence(a(r))))))));case"perm":return c(this.script(this.script(E(""),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):A(a(r),this.bin("?"),a(o),this.bin(":"),a(s[2])));case"sum":return c(A(s.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(A(s.map((e,t)=>t?[this.bin("·"),a(e)]:[a(e)]).flat()));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 A(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 A(this.text("sign",d),this.render(s,t));const r=n.bracketedSides(e),o=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}),c=r.right?this.fence(this.render(s,t)):this.render(s,{...t,before:t.before});return A(l,o?E(this.el(a?"fnspace":"times","")):this.bin("·"),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&&O(r),l=this.render(r,{...t,forceParens:!1,before:!1});return A(o,a?A(E(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const i=n.customName(e.op),s=e.args;if(w.includes(i)&&1===s.length)return this.decorate(i,this.render(s[0],t));return A(/^[A-Za-z]′*(⁻¹)?$/.test(i)?this.symbol(i):this.word(i),E(this.el("callgap","")),this.fence(this.list(s,t)))}decorate(e,t){switch(e){case"boxed":return E(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return E(this.el("cancel",t.html+o("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return E(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return E(this.el("over",t.html),t.h+.14,t.d);default:return E(this.el("accent",this.el("accent-mark",$[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,i]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&O(n,!0)&&O(i,!0)){const e=e=>"op"!==e.type||O(e)?this.render(e,t):this.fence(this.render(e,t));return A(e(n),this.text("ord","/"),e(i))}const s=t.level>0||t.inFraction||!this.o.display?.8:1,r={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,r),this.render(i,r),!0,s)}stack(e,t,n=!0,i=1){const s=e=>1===i?e.html:this.el("scaled",e.html,`font-size:${L(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:${L(o)}`);return E(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},o=()=>this.render(s,r);if(this.o.trigPowers&&f.includes(i.op)&&T(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)?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?A(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:${L(r)}`);if(t&&!i)return E(e.html+this.el("sup",t.html,`font-size:${L(r)};vertical-align:${L(a/r)}`),Math.max(o.h,a+r*t.h),Math.max(o.d,r*t.d-a));if(i&&!t)return E(o.html+this.el("sub",i.html,`font-size:${L(r)};vertical-align:${L(-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:${L(a)};height:${L(d+m)}`);return E(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=o("sqrt",`${this.p}-hook`,`height:${L(s)};width:${L(.5+.06*(s-1))};vertical-align:${L(-i)}`);let c="";if(t){const e=.8*h;c=this.el("rootindex",t.html,`font-size:${L(e)};vertical-align:${L((.55*s-i)/e)}`)}return E(this.el("sqrt",c+r+this.el("radicand",e.html)),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:${L(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:${L(r)} ${L(d.w)} ${L(r)} ${L(h.w)}`,u=E(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{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=A(l(),c()?this.script(this.render(r,h),c(),h):this.render(r,h)),m=e=>A(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 A(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=E(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return A(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:${L(2*a)};width:${L(r?.38:.5)};vertical-align:${L(c-a)}`);if(!n&&!i)return E(l,c+a,a-c);const d=h,m=i||E(""),u=n||E(""),p=c+a-d*m.h;u.d;const f=this.el("limits",this.el("script",m.html,`font-size:${L(d)}`)+this.el("script lower",u.html,`font-size:${L(d)}`),`vertical-align:${L(p)};height:${L(2*a)}`);return E(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 A(this.word("lim"),E(this.el("fnspace","")),this.render(i,t));case 2:{const e=n.firstVariable(i),t="number"===s.type||"symbol"===s.type&&s.value.includes("∞");h=e&&t?A(this.text("var",e),c(),l(s)):l(s);break}case 3:h=A(l(s),c(),l(r));break;default:{const e=n.firstLeaf(o).toLowerCase().startsWith("r")?"+":d;h=A(l(s),c(),this.script(l(r),this.wrap(o,["symbol"],this.text("ord",e)),a))}}return A(this.under(this.word("lim"),h,t),this.render(i,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):E(this.el("under",e.html+this.el("script",t.html,`font-size:${L(.7)}`)),e.h,Math.max(e.d,l)+.05+.7*(t.h+t.d))}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.render(i,n);if(!this.o.display||n.level>0){const t=.55,i=o(e,`${this.p}-bigsign`,`height:${L(2*t)};width:${L(.8)};vertical-align:${L(c-t)}`);return A(this.script(E(i,c+t,t-c),d,n,l),m)}const u=.68,p=h,f=o(e,`${this.p}-bigsign`,`height:${L(1.36)};width:${L("sum"===e?1:1.05)}`),g=d?1.01+p*d.d:c-u,v=e=>this.el("script",e.html,`font-size:${L(p)}`),b=this.el("bigop",(d?v(d):"")+f+(l?v(l):""),`vertical-align:${L(g)}`);return A(E(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"],E(i)).html:i}).join(""),m=t[0].length,u=E(this.el("matrix",d,`grid-template-columns:repeat(${m},auto);vertical-align:${L(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),A(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=E(this.el("cases",a,`vertical-align:${L(o)}`),c+r/2,r/2-c);return this.fence(l,"{","")}}function O(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("-")||z(e)||"*"===e.op&&O(e,t)):O(e.args[0],!0)&&("neg"===e.op||O(e.args[1],!0)))}const z=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(n.GREEK[e.value])),T=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const j=e=>n.toPostfix(e).join(" ");function N(e,t){const i=new Set;P(e,t,i);const s=[];return n.walk(e,e=>{i.has(e)&&s.push(e)}),s}function P(e,t,i){if(null!=t)if(Array.isArray(t))t.forEach(t=>P(e,t,i));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const s=j(n.parseTree(t));return void n.walk(e,e=>{j(e)===s&&i.add(e)})}if(t.path){const n=q(e,t.path);return void(n&&i.add(n))}if(t.type){const s=j(t);n.walk(e,e=>{e!==t&&j(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 q(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 B(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 R(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 Z(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)return void 0===e.id?R(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function F(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(_(i))for(const n of N(e,t))a.set(n,`color:${i}`);const l=new Set(void 0===i?[]:N(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 _(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}function W(e,n={}){return Z(e,{...n,blocks:n.blocks??t.calculateBlock})}function I(e,n={}){return function(e,t={}){const n=Z(e,t);return S(n,F(n,t)).html}(e,{...n,blocks:n.blocks??t.calculateBlock})}const D=Symbol.for("inlinemath.expressions"),H=new Set(["symbol","number"]);function V(e){return e?"symbol"===e.type?e.value:"op"===e.type&&"_"===e.op&&2===e.args.length&&"symbol"===e.args[0].type&&H.has(e.args[1].type)?`${e.args[0].value}_${e.args[1].value}`:null:null}function G(e){const{id:t,from:n,...i}=e;return i.args&&(i.args=i.args.map(G)),i}function K(e){const{id:t,...n}=e;return n.args&&(n.args=n.args.map(K)),n}function U(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)}function X(e,t){let n=!1;const i=new Set,s=e=>{const r=V(e);if(null!==r){if(!i.has(r)){const e=t(r);if(e){n=!0,i.add(r);const t={...s(G(e)),from:r};return i.delete(r),t}}return e}return e.args?{...e,args:e.args.map(s)}:e},r=s(e);return{tree:n?K(r):e,changed:n}}const Y="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",J=new RegExp(`^(${Y})\\s*\\.\\.\\s*(${Y})(?:\\s+step\\s+(${Y}))?(?:\\s*=\\s*(${Y}))?$`);function Q(e){const t=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(e);if(!t||/\]\s*,\s*\[/.test(t[1]))return null;const n=t[1].trim(),i=J.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 ee=Symbol("set on the page");class te{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(ee));n.set(e,{name:e,text:t,key:`page:${t}`,input:null}),this.owners.delete(ee),this.owners.set(ee,n)}return this.notify(null,e),this}clear(e){return void 0===e?(this.owners.clear(),this.chosen.clear()):(this.owners.get(ee)?.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 ne(){return new te}const ie=ne();function se(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 G(i(e,0))}function re(e,t,{parse:n,commit:i,cancel:s,label:r="Edit"}){const o=e.ownerDocument;if(!o||!o.body)return null;const a=o.defaultView,l=e.getBoundingClientRect(),c=o.createElement("input");c.type="text",c.className="mv-edit",c.value=t,c.spellcheck=!1,c.autocomplete="off",c.setAttribute("aria-label",r);const h=()=>{c.style.width=`${Math.max(4,c.value.length+2)}ch`},d=a.getComputedStyle(e);Object.assign(c.style,{position:"absolute",left:`${l.left+a.scrollX}px`,top:`${l.top+a.scrollY+l.height/2}px`,minWidth:`${Math.max(l.width,32)}px`,fontSize:d.fontSize}),h(),o.body.appendChild(c),a.getSelection?.()?.removeAllRanges(),c.focus(),c.select();let m=!1;const u=()=>{m=!0,c.remove()},p=e=>{if(m)return!0;if(!e||c.value===t)return u(),s&&s(),!0;let r;try{r=n(c.value)}catch(e){return c.setAttribute("aria-invalid","true"),c.title=e.message,!1}return u(),i(r,c.value),!0};return c.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),p(!0)),"Escape"===e.key&&(e.preventDefault(),p(!1))}),c.addEventListener("input",()=>{h(),c.removeAttribute("aria-invalid"),c.removeAttribute("title")}),c.addEventListener("blur",()=>{p(!0)||p(!1)}),c}class oe{constructor(e,t,n={}){this.element=e,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=ae(e,n.announce,this.p),this.set(t)}set(e,{animate:t=!1,duration:n=600,easing:i="ease-in-out"}={}){const s=le(t)&&this.tree?this.snapshot():null,r=void 0!==this.tree;return this.tree=W(e,this.options),this.element.innerHTML=S(this.tree,F(this.tree,this.options)).html,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(),s&&this.morph(s,{duration:n,easing:i}),r&&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 N(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=N(this.tree,i)[0];t({node:s,id:i,path:B(this.tree,i),element:n,event:e})};return this.element.addEventListener(e,n),this.handlers.push([e,n]),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)}}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.element.addEventListener("dblclick",e=>{const t=e.target.closest?.("[data-node]");t&&this.root.contains(t)&&(e.preventDefault(),this.edit(N(this.tree,Number(t.dataset.node))[0]))})),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=B(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 re(r,this.editing.toText(n),{label:o,parse:e=>W(e,this.options),commit:(e,n)=>{this.set(se(this.tree,s,e),{animate:!0});const i=q(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})}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||ae(this.element,!0,this.p),this.element.addEventListener("keydown",e=>this.key(e)))}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.neighbour(t,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":n=t?this.neighbour(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:B(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=B(this.tree,e.id);for(let e=t?t.length-1:-1;e>0;e--){const n=q(this.tree,t.slice(0,e));if(n&&this.elementOf(n))return n}return null}neighbour(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=j(n);e.has(t)||e.set(t,[]),e.get(t).push(i.getBoundingClientRect())}"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=s=>{const r=this.elementOf(s),o=r&&e.get(j(s));if(o&&o.length){const e=o.shift(),i=r.getBoundingClientRect(),s=e.left-i.left,a=e.top-i.top,l=i.width?e.width/i.width:1,c=i.height?e.height/i.height:1;return void((Math.abs(s)+Math.abs(a)>.5||Math.abs(l-1)+Math.abs(c-1)>.01)&&r.animate([{transformOrigin:"0 0",transform:`translate(${s}px, ${a}px) scale(${l}, ${c})`},{transformOrigin:"0 0",transform:"none"}],{duration:t,easing:n}))}"op"===s.type?s.args.forEach(i):r&&r.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:t,easing:n})};i(this.tree)}}function ae(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=document.createElement("span");return i.className=`${n}-sr-only`,i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),e.insertAdjacentElement("afterend",i),i}function le(e){return!!e&&("always"===e||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}const ce=new RegExp("(\\d+)","g");function he(e,{delimiters:t=["$$","$","\\[","\\("]}={}){const n=[];let i="",s=0;const r=String(e),o=e=>0===e||"\n"===r[e-1],a=(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(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),l=n.exec(`\n${o}`),c=l?o.slice(0,Math.max(0,l.index-1)):o,h=e[0].length+(l?l.index-1+l[0].length:o.length),d=r.slice(s,s+h);"math"===e[3].trim()?i+=a(c,!0,d):i+=d,s+=h;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=r.indexOf(n,s+2);if(t>-1){i+=a(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+=a(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])){const e=de(r,s+1);if(e>-1){i+=a(r.slice(s+1,e),!1,r.slice(s,e+1)),s=e+1;continue}}i+=e,s++}return{text:i,math:n}}function de(e,t){for(let n=t;n<e.length;n++){const t=e[n];if("\\"!==t){if("`"===t)return-1;if("\n"===t&&/^\n[ \t]*\n/.test(e.slice(n)))return-1;if("$"===t&&!/\s/.test(e[n-1])&&!/\d/.test(e[n+1]??"")&&"$"!==e[n+1])return n}else n++}return-1}const me=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),ue=/^\s*([A-Za-z\u0370-\u03ff](?:_\{?\w+\}?)?)\s*=\s*([^=<>≤≥]+)$/;function pe(e,i,s,r){const{text:o,math:a}=he(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=()=>{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=g({});for(const e of l.keys()){const t=s(e);if(t)try{i[e]=n.toPostfix(X(t,t=>t===e?null:s(t)).tree)}catch{}}d[D]=i},g=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=W(c(i),e)}catch{}t.set(n,s)}return t.get(n)}};f();const v=a.map((e,n)=>{const{source:s,display:r}=e,o=r?"mv-md-display":"mv-md-math",a=(e,t="")=>`<span class="${o}${t}" data-mv-md="${n}">${e}</span>`;try{const o={...i.math,display:r,blocks:i.blocks,scope:d},v=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:V(W(o))}catch{}return null!==l&&a?{hidden:n,lhs:o,name:l,rhs:a,input:Q(a)}:r}(s);if(v&&v.error)throw new Error(v.error);if(v){const{name:t,input:i,hidden:s}=v,r=i?{name:t,text:i.default,input:i,key:`input:${JSON.stringify(i)}`}:{name:t,text:v.rhs,input:null,key:`expr:${v.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="${me(i)}" aria-label="${me(i)}"`;if("dropdown"===n.kind)return`<select ${s}>${n.options.map(e=>`<option value="${me(e)}"${e===t?" selected":""}>${me(e)}</option>`).join("")}</select>`;return"slider"===n.kind?`<input type="range" ${s} min="${n.min}" max="${n.max}" step="${n.step}" value="${me(t)}"><output class="mv-md-output" data-mv-out="${me(i)}">${me(t)}</output>`:`<input type="text" ${s} value="${me(t)}" size="${Math.max(4,t.length+1)}" spellcheck="false" autocomplete="off">`}(r,c(r));h=s?e:`${I(v.lhs,o)}<span class="mv-md-assign" aria-hidden="true">≔</span>${e}`,u.add(n)}else{const e=X(W(v.rhs,o),g(o)).tree;if(!s){const t=R({type:"op",op:"=",args:[G(W(v.lhs)),void 0===e.id?e:G(e)]});p[n]=t,h=function(e){return e.replace('<span class="mv-rel">=</span>','<span class="mv-rel mv-rel-def">≔</span>').replace(/(aria-label="[^"]*?) equals /,"$1 is defined as ").replace("<mo>=</mo>","<mo>≔</mo>")}(I(t,o))}}return l.delete(t),l.set(t,r),m.set(t,r),f(),s&&!i?"":a(h,i?" mv-md-input-def":"")}const{tree:b,changed:y}=X(W(s,o),g(o));y&&R(b),p[n]=b;const x=I(b,o);return!y&&!1!==i.define&&function(e,n,i){const s=ue.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}(s,h,l)&&f(),a(x)}catch(t){return`<span class="mv-md-error" data-mv-md="${n}" title="${me(t.message)}"><code>${me(e.raw)}</code></span>`}});return{text:o,math:a,drawn:v,defs:m,inputs:u,trees:p}}const fe=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,ge=e=>fe.test(e.trim())?me(e.trim()):"#";function ve(e,t,n){const i=[],s=e=>(i.push(e),`${i.length-1}`);let r=e;return r=r.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(e,t,i)=>s(`<code>${me(n(i.trim()))}</code>`)),r=r.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(e,t)=>s(me(t))),r=r.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(e,t)=>s(`<a href="${ge(t)}">${me(t)}</a>`)),t.html&&(r=r.replace(/<\/?[A-Za-z][^>]*>/g,e=>s(e))),r=r.replace(/!\[([^\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,t,n,i)=>s(`<img src="${ge(n)}" alt="${me(t)}"${i?` title="${me(i)}"`:""}>`)),r=r.replace(/\[([^\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,i,r,o)=>s(`<a href="${ge(r)}"${o?` title="${me(o)}"`:""}>${ve(i,t,n)}</a>`)),r=me(r),r=r.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),r=r.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),r=r.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),r=r.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),r=r.replace(/( {2,}|\\)\n/g,"<br>\n"),r.replace(/(\d+)/g,(e,t)=>i[Number(t)])}const be=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,ye=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,xe=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;function $e(e,t,n){const i=[];let s=0;const r=e=>ve(e,t,n);for(;s<e.length;){const o=e[s];if(!o.trim()){s++;continue}const a=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(o);if(a){const t=[];for(s++;s<e.length&&!new RegExp(`^ {0,3}${"`"===a[1][0]?"`":"~"}{${a[1].length},}\\s*$`).test(e[s]);)t.push(e[s++]);s++;const r=a[2]?` class="language-${me(a[2])}"`:"";i.push(`<pre><code${r}>${me(n(t.join("\n")))}</code></pre>`);continue}const l=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/.exec(o);if(l){i.push(`<h${l[1].length}>${r(l[2])}</h${l[1].length}>`),s++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(o)){i.push("<hr>"),s++;continue}if(/^ {0,3}>/.test(o)){const r=[];for(;s<e.length&&e[s].trim()&&(/^ {0,3}>/.test(e[s])||r.length);)r.push(e[s].replace(/^ {0,3}> ?/,"")),s++;i.push(`<blockquote>\n${$e(r,t,n)}\n</blockquote>`);continue}const c=ye.exec(o);if(c){const r=/\d/.test(c[2]),o=r?parseInt(c[2],10):1,a=[];let l=!1;for(;s<e.length;){const t=ye.exec(e[s]);if(!t||/\d/.test(t[2])!==r)break;const n=t[0].length,i=[e[s].slice(n)];for(s++;s<e.length;){const t=e[s];if(!t.trim()){const t=e[s+1];if(void 0!==t&&t.startsWith(" ".repeat(Math.min(n,4)))&&t.trim()){i.push(""),l=!0,s++;continue}void 0!==t&&ye.test(t)&&(l=!0);break}if(t.startsWith(" ".repeat(Math.min(n,4))))i.push(t.slice(Math.min(n,4)));else{if(ye.test(t)||be.test(t))break;i.push(t)}s++}for(a.push(i);s<e.length&&!e[s].trim()&&void 0!==e[s+1]&&ye.test(e[s+1]);)s++}const h=r?"ol":"ul",d=a.map(e=>{let i=$e(e,t,n);return l||(i=i.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${i}</li>`});i.push(`<${h}${r&&1!==o?` start="${o}"`:""}>\n${d.join("\n")}\n</${h}>`);continue}if(o.includes("|")&&void 0!==e[s+1]&&xe.test(e[s+1])&&e[s+1].includes("-")){const t=e=>e.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(e=>e.trim()),n=t(e[s+1]).map(e=>e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":e.startsWith(":")?"left":""),a=(e,t,i)=>`<${e}${n[i]?` style="text-align:${n[i]}"`:""}>${r(t)}</${e}>`,l=t(o);s+=2;const c=[];for(;s<e.length&&e[s].trim()&&e[s].includes("|");)c.push(t(e[s++]));i.push(`<table>\n<thead><tr>${l.map((e,t)=>a("th",e,t)).join("")}</tr></thead>\n<tbody>\n${c.map(e=>`<tr>${l.map((t,n)=>a("td",e[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(o)){const t=[];for(;s<e.length&&(/^( {4}|\t)/.test(e[s])||!e[s].trim());)t.push(e[s++].replace(/^( {4}|\t)/,""));for(;t.length&&!t[t.length-1].trim();)t.pop();i.push(`<pre><code>${me(n(t.join("\n")))}</code></pre>`);continue}const h=[];for(;s<e.length&&e[s].trim()&&(!h.length||!be.test(e[s])||/^ {0,3}[-=]+\s*$/.test(e[s]));){if(h.length&&/^ {0,3}(=+|-+)\s*$/.test(e[s])){const t="="===e[s].trim()[0]?1:2;i.push(`<h${t}>${r(h.join("\n"))}</h${t}>`),h.length=0,s++;break}h.push(e[s].replace(/^ {0,3}/,"")),s++}h.length&&i.push(`<p>${r(h.join("\n"))}</p>`)}return i.join("\n")}function we(e,t={},n=e=>e){return $e(String(e).replace(/\r\n?/g,"\n").split("\n"),t,n)}function ke({text:e,math:t,drawn:n},i){return(i.render?i.render(e):we(e,i,e=>e.replace(ce,(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(ce,(e,t)=>n[Number(t)]).replace(/<p>\s*<\/p>\n?/g,"")}const Me=new WeakMap,Le=new Set;function Ee(){for(const e of Le)e.connected()&&!e.element.isConnected&&e.stop(!0)}var Ae='/*\n * Inline Math stylesheet. Everything is under .mv; colours 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 colour\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 { 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-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-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\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; border-top: 0.06em solid currentColor; padding-top: 0.08em; }\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; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }\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 colours) 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 maths (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 Se=Ae;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Ae,document.head.append(e)}return Object.defineProperty(e,"toText",{enumerable:!0,get:function(){return s.toText}}),e.CSS=Se,e.DEFAULTS=k,e.PATHS=r,e.View=oe,e.createVariables=ne,e.extractMath=he,e.layout=S,e.markdownToHTML=function(e,t={}){return ke(pe(e,t,t.variables||null),t)},e.nodeAt=q,e.numberTree=R,e.pathOf=B,e.render=function(e,t,n={}){return new oe(e,t,n)},e.renderMarkdown=we,e.renderMarkdownInto=function(e,t,n={}){const i=void 0===n.variables?ie:n.variables||null;Ee();const s=Me.get(e);s&&s.stop(s.store!==i);let r=pe(t,n,i,e);if(e.innerHTML=ke(r,n),!i)return Me.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{W(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=B(c,h)||[];let m=null;for(let e=d.length;e>=0&&!m;e--){const t=q(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=>W(e),h=q(c,d);return void re(o,a(U(h,l)),{label:`Edit ${t}`,parse:e=>W(e,{blocks:n.blocks}),commit:e=>{const n=se(U(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,Ee(),(()=>{const s=pe(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),Le.delete(d),Me.delete(e),t&&i.own(e,null)}const d={element:e,store:i,stop:h,connected:()=>o};return Le.add(d),Me.set(e,d),e},e.select=N,e.shouldAnimate=le,e.signature=j,e.toHTML=I,e.treeOf=W,e.variables=ie,e}({},MathZetta,MathZetta,MathZetta,MathZetta);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
import{t}from"./chunks/html-
|
|
1
|
+
/* Inline Math 0.2.0 — MIT licence; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate with an import map */
|
|
2
|
+
import{t}from"./chunks/html-BimAqn7x.js";export{a as toHTML}from"./chunks/html-BimAqn7x.js";import{l as e,b as s,s as i,p as r,c as o,d as h}from"./chunks/draw-Bev17BJJ.js";export{D as DEFAULTS,P as PATHS,n as numberTree}from"./chunks/draw-Bev17BJJ.js";import"mathzetta";import{toAudioSpeech as l,toSpeechSegments as c}from"mathzetta/speech";import{o as u,r as d}from"./chunks/edit-C65xXzo8.js";import"mathzetta/calculate";class f{constructor(t,e,s={}){this.element=t,this.options=s,this.p=s.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=m(t,s.announce,this.p),this.set(e)}set(i,{animate:r=!1,duration:n=600,easing:o="ease-in-out"}={}){const h=p(r)&&this.tree?this.snapshot():null,a=void 0!==this.tree;return this.tree=t(i,this.options),this.element.innerHTML=e(this.tree,s(this.tree,this.options)).html,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(),h&&this.morph(h,{duration:n,easing:o}),a&&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 s=()=>{t.textContent=e};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(s)):setTimeout(s,50),this}nodes(t){return i(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 s=t=>{const s=t.target.closest?.("[data-node]");if(!s||!this.root.contains(s))return;const n=Number(s.dataset.node),o=i(this.tree,n)[0];e({node:o,id:n,path:r(this.tree,n),element:s,event:t})};return this.element.addEventListener(t,s),this.handlers.push([t,s]),this.root.classList.add(`${this.p}-clickable`),"click"===t&&(this.clicks.push(e),this.keyboard()),()=>{this.element.removeEventListener(t,s),this.clicks=this.clicks.filter(t=>t!==e)}}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.element.addEventListener("dblclick",t=>{const e=t.target.closest?.("[data-node]");e&&this.root.contains(e)&&(t.preventDefault(),this.edit(i(this.tree,Number(e.dataset.node))[0]))})),this}edit(e=this.tree,{returnFocus:s=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const i="object"==typeof e&&e&&e.type?e:this.nodes(e)[0];if(!i)return null;const n=r(this.tree,i.id)||[],h=this.elementOf(i)||this.root;let a="Edit";try{a=`Edit ${l(i)}`}catch{}const c=()=>{s&&this.root.focus&&this.root.focus()};return u(h,this.editing.toText(i),{label:a,parse:e=>t(e,this.options),commit:(t,e)=>{this.set(d(this.tree,n,t),{animate:!0});const i=o(this.tree,n);s&&i&&this.focusPart(i===this.tree?null:i),c(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:n,part:e})},cancel:c})}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.element.addEventListener("keydown",t=>this.key(t)))}key(t){if(!this.root||!this.root.contains(t.target))return;const e=this.active;let s;switch(t.key){case"ArrowDown":s=e?this.partsOf(e)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":s=e?this.outerOf(e):void 0;break;case"ArrowRight":s=e?this.neighbour(e,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":s=e?this.neighbour(e,-1):void 0;break;case"Home":case"Escape":s=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 s=e||this.tree,i=this.elementOf(s)||this.root,n={node:s,id:s.id,path:r(this.tree,s.id),element:i,event:t};for(const t of this.clicks)t(n);return}default:return}t.preventDefault(),void 0!==s&&this.focusPart(s)}focusPart(t){const e=`${this.p}-focus`;this.root.querySelectorAll(`.${e}`).forEach(t=>t.classList.remove(e)),this.active=t;const s=t&&this.elementOf(t);s&&s.classList.add(e);let i="";try{i=t?l(t):this.spoken()}catch{i=""}return this.say(this.partsLive,i),this}partsOf(t){const e=[],s=t=>{this.elementOf(t)?e.push(t):"op"===t.type&&t.args.forEach(s)};return t&&"op"===t.type&&t.args.forEach(s),e}outerOf(t){const e=r(this.tree,t.id);for(let t=e?e.length-1:-1;t>0;t--){const s=o(this.tree,e.slice(0,t));if(s&&this.elementOf(s))return s}return null}neighbour(t,e){const s=this.partsOf(this.outerOf(t)||this.tree),i=s.indexOf(t);return i<0?void 0:s[i+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=s=>{const i=this.elementOf(s);if(i){const e=h(s);t.has(e)||t.set(e,[]),t.get(e).push(i.getBoundingClientRect())}"op"===s.type&&s.args.forEach(e)};return e(this.tree),t}morph(t,{duration:e,easing:s}){if("undefined"==typeof Element||!Element.prototype.animate)return;const i=r=>{const n=this.elementOf(r),o=n&&t.get(h(r));if(o&&o.length){const t=o.shift(),i=n.getBoundingClientRect(),r=t.left-i.left,h=t.top-i.top,a=i.width?t.width/i.width:1,l=i.height?t.height/i.height:1;return void((Math.abs(r)+Math.abs(h)>.5||Math.abs(a-1)+Math.abs(l-1)>.01)&&n.animate([{transformOrigin:"0 0",transform:`translate(${r}px, ${h}px) scale(${a}, ${l})`},{transformOrigin:"0 0",transform:"none"}],{duration:e,easing:s}))}"op"===r.type?r.args.forEach(i):n&&n.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:e,easing:s})};i(this.tree)}}function m(t,e,s){if(!e)return null;if("object"==typeof e&&1===e.nodeType)return e;if("undefined"==typeof document||!t.insertAdjacentElement)return null;const i=document.createElement("span");return i.className=`${s}-sr-only`,i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),t.insertAdjacentElement("afterend",i),i}function p(t){return!!t&&("always"===t||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}function g(t,e,s={}){return new f(t,e,s)}export{f as View,e as layout,o as nodeAt,r as pathOf,g as render,i as select,p as shouldAnimate,h as signature,t as treeOf};
|