import{D as W,O as X,_ as G,g as J,h as b,k as Q,n as Y,t as k,u as w}from"./micromark-factory-space-Dx_STMJD.js";import{c as S}from"./katex-Di-siZEY.js";function Z(e,n){return C(e,n||{})||{type:"root",children:[]}}function C(e,n){let a=ee(e,n);return a&&n.afterTransform&&n.afterTransform(e,a),a}function ee(e,n){switch(e.nodeType){case 1:return ae(e,n);case 3:return ne(e);case 8:return re(e);case 9:return A(e,n);case 10:return te();case 11:return A(e,n);default:return}}function A(e,n){return{type:"root",children:P(e,n)}}function te(){return{type:"doctype"}}function ne(e){return{type:"text",value:e.nodeValue||""}}function re(e){return{type:"comment",value:e.nodeValue||""}}function ae(e,n){let a=e.namespaceURI,t=a===b.svg?G:J,r=a===b.html?e.tagName.toLowerCase():e.tagName,l=a===b.html&&r==="template"?e.content:e,i=e.getAttributeNames(),s={},o=-1;for(;++o<i.length;)s[i[o]]=e.getAttribute(i[o])||"";return t(r,s,P(l,n))}function P(e,n){let a=e.childNodes,t=[],r=-1;for(;++r<a.length;){let l=C(a[r],n);l!==void 0&&t.push(l)}return t}var ie=new DOMParser;function oe(e,n){return Z(n!=null&&n.fragment?le(e):ie.parseFromString(e,"text/html"))}function le(e){let n=document.createElement("template");return n.innerHTML=e,n.content}const D=(function(e,n,a){let t=Q(a);if(!e||!e.type||!e.children)throw Error("Expected parent node");if(typeof n=="number"){if(n<0||n===1/0)throw Error("Expected positive finite number as index")}else if(n=e.children.indexOf(n),n<0)throw Error("Expected child node or index");for(;++n<e.children.length;)if(t(e.children[n],n,e))return e.children[n]}),v=(function(e){if(e==null)return se;if(typeof e=="string")return ce(e);if(typeof e=="object")return ue(e);if(typeof e=="function")return T(e);throw Error("Expected function, string, or array as `test`")});function ue(e){let n=[],a=-1;for(;++a<e.length;)n[a]=v(e[a]);return T(t);function t(...r){let l=-1;for(;++l<n.length;)if(n[l].apply(this,r))return!0;return!1}}function ce(e){return T(n);function n(a){return a.tagName===e}}function T(e){return n;function n(a,t,r){return!!(he(a)&&e.call(this,a,typeof t=="number"?t:void 0,r||void 0))}}function se(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function he(e){return typeof e=="object"&&!!e&&"type"in e&&"tagName"in e}var q=/\n/g,I=/[\t ]+/g,E=v("br"),B=v(we),pe=v("p"),z=v("tr"),fe=v(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",ye,ve]),O=v("address.article.aside.blockquote.body.caption.center.dd.dialog.dir.dl.dt.div.figure.figcaption.footer.form,.h1.h2.h3.h4.h5.h6.header.hgroup.hr.html.legend.li.listing.main.menu.nav.ol.p.plaintext.pre.section.ul.xmp".split("."));function me(e,n){let a=n||{},t="children"in e?e.children:[],r=O(e),l=L(e,{whitespace:a.whitespace||"normal",breakBefore:!1,breakAfter:!1}),i=[];(e.type==="text"||e.type==="comment")&&i.push(...V(e,{whitespace:l,breakBefore:!0,breakAfter:!0}));let s=-1;for(;++s<t.length;)i.push(...j(t[s],e,{whitespace:l,breakBefore:s?void 0:r,breakAfter:s<t.length-1?E(t[s+1]):r}));let o=[],h;for(s=-1;++s<i.length;){let p=i[s];typeof p=="number"?h!==void 0&&p>h&&(h=p):p&&(h!==void 0&&h>-1&&o.push(`
`.repeat(h)||" "),h=-1,o.push(p))}return o.join("")}function j(e,n,a){return e.type==="element"?de(e,n,a):e.type==="text"?a.whitespace==="normal"?V(e,a):ge(e):[]}function de(e,n,a){let t=L(e,a),r=e.children||[],l=-1,i=[];if(fe(e))return i;let s,o;for(E(e)||z(e)&&D(n,e,z)?o=`
`:pe(e)?(s=2,o=2):O(e)&&(s=1,o=1);++l<r.length;)i=i.concat(j(r[l],e,{whitespace:t,breakBefore:l?void 0:s,breakAfter:l<r.length-1?E(r[l+1]):o}));return B(e)&&D(n,e,B)&&i.push("	"),s&&i.unshift(s),o&&i.push(o),i}function V(e,n){let a=String(e.value),t=[],r=[],l=0;for(;l<=a.length;){q.lastIndex=l;let o=q.exec(a),h=o&&"index"in o?o.index:a.length;t.push(xe(a.slice(l,h).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),l===0?n.breakBefore:!0,h===a.length?n.breakAfter:!0)),l=h+1}let i=-1,s;for(;++i<t.length;)t[i].charCodeAt(t[i].length-1)===8203||i<t.length-1&&t[i+1].charCodeAt(0)===8203?(r.push(t[i]),s=void 0):t[i]?(typeof s=="number"&&r.push(s),r.push(t[i]),s=0):(i===0||i===t.length-1)&&r.push(0);return r}function ge(e){return[String(e.value)]}function xe(e,n,a){let t=[],r=0,l;for(;r<e.length;){I.lastIndex=r;let i=I.exec(e);l=i?i.index:e.length,!r&&!l&&i&&!n&&t.push(""),r!==l&&t.push(e.slice(r,l)),r=i?l+i[0].length:l}return r!==l&&!a&&t.push(""),t.join(" ")}function L(e,n){if(e.type==="element"){let a=e.properties||{};switch(e.tagName){case"listing":case"plaintext":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return a.wrap?"pre-wrap":"pre";case"td":case"th":return a.noWrap?"nowrap":n.whitespace;case"textarea":return"pre-wrap";default:}}return n.whitespace}function ye(e){return!!(e.properties||{}).hidden}function we(e){return e.tagName==="td"||e.tagName==="th"}function ve(e){return e.tagName==="dialog"&&!(e.properties||{}).open}var Fe={},ke=[];function be(e){let n=e||Fe;return function(a,t){X(a,"element",function(r,l){let i=Array.isArray(r.properties.className)?r.properties.className:ke,s=i.includes("language-math"),o=i.includes("math-display"),h=i.includes("math-inline"),p=o;if(!s&&!o&&!h)return;let f=l[l.length-1],d=r;if(r.tagName==="code"&&s&&f&&f.type==="element"&&f.tagName==="pre"&&(d=f,f=l[l.length-2],p=!0),!f)return;let m=me(d,{whitespace:"pre"}),c;try{c=S.renderToString(m,{...n,displayMode:p,throwOnError:!0})}catch(y){let F=y,u=F.name.toLowerCase();t.message("Could not render math with KaTeX",{ancestors:[...l,r],cause:F,place:r.position,ruleId:u,source:"rehype-katex"});try{c=S.renderToString(m,{...n,displayMode:p,strict:"ignore",throwOnError:!1})}catch{c=[{type:"element",tagName:"span",properties:{className:["katex-error"],style:"color:"+(n.errorColor||"#cc0000"),title:String(y)},children:[{type:"text",value:m}]}]}}typeof c=="string"&&(c=oe(c,{fragment:!0}).children);let x=f.children.indexOf(d);return f.children.splice(x,1,...c),W})}}function Te(){return{enter:{mathFlow:e,mathFlowFenceMeta:n,mathText:l},exit:{mathFlow:r,mathFlowFence:t,mathFlowFenceMeta:a,mathFlowValue:s,mathText:i,mathTextData:s}};function e(o){this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[{type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]}]}},o)}function n(){this.buffer()}function a(){let o=this.resume(),h=this.stack[this.stack.length-1];h.type,h.meta=o}function t(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function r(o){let h=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),p=this.stack[this.stack.length-1];p.type,this.exit(o),p.value=h;let f=p.data.hChildren[0];f.type,f.tagName,f.children.push({type:"text",value:h}),this.data.mathFlowInside=void 0}function l(o){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},o),this.buffer()}function i(o){let h=this.resume(),p=this.stack[this.stack.length-1];p.type,this.exit(o),p.value=h,p.data.hChildren.push({type:"text",value:h})}function s(o){this.config.enter.data.call(this,o),this.config.exit.data.call(this,o)}}function Ee(e){let n=(e||{}).singleDollarTextMath;return n??(n=!0),t.peek=r,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:`
`,inConstruct:"mathFlowMeta"},{character:"$",after:n?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:a,inlineMath:t}};function a(l,i,s,o){let h=l.value||"",p=s.createTracker(o),f="$".repeat(Math.max(Y(h,"$")+1,2)),d=s.enter("mathFlow"),m=p.move(f);if(l.meta){let c=s.enter("mathFlowMeta");m+=p.move(s.safe(l.meta,{after:`
`,before:m,encode:["$"],...p.current()})),c()}return m+=p.move(`
`),h&&(m+=p.move(h+`
`)),m+=p.move(f),d(),m}function t(l,i,s){let o=l.value||"",h=1;for(n||h++;RegExp("(^|[^$])"+"\\$".repeat(h)+"([^$]|$)").test(o);)h++;let p="$".repeat(h);/[^ \r\n]/.test(o)&&(/^[ \r\n]/.test(o)&&/[ \r\n]$/.test(o)||/^\$|\$$/.test(o))&&(o=" "+o+" ");let f=-1;for(;++f<s.unsafe.length;){let d=s.unsafe[f];if(!d.atBreak)continue;let m=s.compilePattern(d),c;for(;c=m.exec(o);){let x=c.index;o.codePointAt(x)===10&&o.codePointAt(x-1)===13&&x--,o=o.slice(0,x)+" "+o.slice(c.index+1)}}return p+o+p}function r(){return"$"}}const Ne={tokenize:Me,concrete:!0,name:"mathFlow"};var R={tokenize:$e,partial:!0};function Me(e,n,a){let t=this,r=t.events[t.events.length-1],l=r&&r[1].type==="linePrefix"?r[2].sliceSerialize(r[1],!0).length:0,i=0;return s;function s(u){return e.enter("mathFlow"),e.enter("mathFlowFence"),e.enter("mathFlowFenceSequence"),o(u)}function o(u){return u===36?(e.consume(u),i++,o):i<2?a(u):(e.exit("mathFlowFenceSequence"),k(e,h,"whitespace")(u))}function h(u){return u===null||w(u)?f(u):(e.enter("mathFlowFenceMeta"),e.enter("chunkString",{contentType:"string"}),p(u))}function p(u){return u===null||w(u)?(e.exit("chunkString"),e.exit("mathFlowFenceMeta"),f(u)):u===36?a(u):(e.consume(u),p)}function f(u){return e.exit("mathFlowFence"),t.interrupt?n(u):e.attempt(R,d,y)(u)}function d(u){return e.attempt({tokenize:F,partial:!0},y,m)(u)}function m(u){return(l?k(e,c,"linePrefix",l+1):c)(u)}function c(u){return u===null?y(u):w(u)?e.attempt(R,d,y)(u):(e.enter("mathFlowValue"),x(u))}function x(u){return u===null||w(u)?(e.exit("mathFlowValue"),c(u)):(e.consume(u),x)}function y(u){return e.exit("mathFlow"),n(u)}function F(u,H,N){let M=0;return k(u,K,"linePrefix",t.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function K(g){return u.enter("mathFlowFence"),u.enter("mathFlowFenceSequence"),$(g)}function $(g){return g===36?(M++,u.consume(g),$):M<i?N(g):(u.exit("mathFlowFenceSequence"),k(u,U,"whitespace")(g))}function U(g){return g===null||w(g)?(u.exit("mathFlowFence"),H(g)):N(g)}}}function $e(e,n,a){let t=this;return r;function r(i){return i===null?n(i):(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),l)}function l(i){return t.parser.lazy[t.now().line]?a(i):n(i)}}function Se(e){let n=(e||{}).singleDollarTextMath;return n??(n=!0),{tokenize:a,resolve:Ce,previous:Ae,name:"mathText"};function a(t,r,l){let i=0,s,o;return h;function h(c){return t.enter("mathText"),t.enter("mathTextSequence"),p(c)}function p(c){return c===36?(t.consume(c),i++,p):i<2&&!n?l(c):(t.exit("mathTextSequence"),f(c))}function f(c){return c===null?l(c):c===36?(o=t.enter("mathTextSequence"),s=0,m(c)):c===32?(t.enter("space"),t.consume(c),t.exit("space"),f):w(c)?(t.enter("lineEnding"),t.consume(c),t.exit("lineEnding"),f):(t.enter("mathTextData"),d(c))}function d(c){return c===null||c===32||c===36||w(c)?(t.exit("mathTextData"),f(c)):(t.consume(c),d)}function m(c){return c===36?(t.consume(c),s++,m):s===i?(t.exit("mathTextSequence"),t.exit("mathText"),r(c)):(o.type="mathTextData",d(c))}}}function Ce(e){let n=e.length-4,a=3,t,r;if((e[a][1].type==="lineEnding"||e[a][1].type==="space")&&(e[n][1].type==="lineEnding"||e[n][1].type==="space")){for(t=a;++t<n;)if(e[t][1].type==="mathTextData"){e[n][1].type="mathTextPadding",e[a][1].type="mathTextPadding",a+=2,n-=2;break}}for(t=a-1,n++;++t<=n;)r===void 0?t!==n&&e[t][1].type!=="lineEnding"&&(r=t):(t===n||e[t][1].type==="lineEnding")&&(e[r][1].type="mathTextData",t!==r+2&&(e[r][1].end=e[t-1][1].end,e.splice(r+2,t-r-2),n-=t-r-2,t=r+2),r=void 0);return e}function Ae(e){return e!==36||this.events[this.events.length-1][1].type==="characterEscape"}function Pe(e){return{flow:{36:Ne},text:{36:Se(e)}}}var De={};function qe(e){let n=this,a=e||De,t=n.data(),r=t.micromarkExtensions||(t.micromarkExtensions=[]),l=t.fromMarkdownExtensions||(t.fromMarkdownExtensions=[]),i=t.toMarkdownExtensions||(t.toMarkdownExtensions=[]);r.push(Pe(a)),l.push(Te()),i.push(Ee(a))}function _(e={}){return{name:"katex",type:"math",remarkPlugin:[qe,{singleDollarTextMath:e.singleDollarTextMath??!1}],rehypePlugin:[be,{errorColor:e.errorColor??"var(--color-muted-foreground)"}],getStyles(){return"katex/dist/katex.min.css"}}}var Ie=_();export{_ as createMathPlugin,Ie as math};
