import{aL as y,aM as M,aN as D,aO as _,aP as K,aQ as b,aR as R}from"./index-BUHGIoA-.js";function V(e,t){return O(e,{})||{type:"root",children:[]}}function O(e,t){const n=H(e,t);return n&&t.afterTransform&&t.afterTransform(e,n),n}function H(e,t){switch(e.nodeType){case 1:return U(e,t);case 3:return q(e);case 8:return Q(e);case 9:return k(e,t);case 10:return W();case 11:return k(e,t);default:return}}function k(e,t){return{type:"root",children:S(e,t)}}function W(){return{type:"doctype"}}function q(e){return{type:"text",value:e.nodeValue||""}}function Q(e){return{type:"comment",value:e.nodeValue||""}}function U(e,t){const n=e.namespaceURI,i=n===y.svg?M:D,r=n===y.html?e.tagName.toLowerCase():e.tagName,c=n===y.html&&r==="template"?e.content:e,o=e.getAttributeNames(),s={};let a=-1;for(;++a<o.length;)s[o[a]]=e.getAttribute(o[a])||"";return i(r,s,S(c,t))}function S(e,t){const n=e.childNodes,i=[];let r=-1;for(;++r<n.length;){const c=O(n[r],t);c!==void 0&&i.push(c)}return i}new DOMParser;function X(e,t){const n=Y(e);return V(n)}function Y(e){const t=document.createElement("template");return t.innerHTML=e,t.content}const E=(function(e,t,n){const i=_(n);if(!e||!e.type||!e.children)throw new Error("Expected parent node");if(typeof t=="number"){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if(t=e.children.indexOf(t),t<0)throw new Error("Expected child node or index");for(;++t<e.children.length;)if(i(e.children[t],t,e))return e.children[t]}),p=(function(e){if(e==null)return G;if(typeof e=="string")return z(e);if(typeof e=="object")return $(e);if(typeof e=="function")return x(e);throw new Error("Expected function, string, or array as `test`")});function $(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=p(e[n]);return x(i);function i(...r){let c=-1;for(;++c<t.length;)if(t[c].apply(this,r))return!0;return!1}}function z(e){return x(t);function t(n){return n.tagName===e}}function x(e){return t;function t(n,i,r){return!!(J(n)&&e.call(this,n,typeof i=="number"?i:void 0,r||void 0))}}function G(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function J(e){return e!==null&&typeof e=="object"&&"type"in e&&"tagName"in e}const A=/\n/g,T=/[\t ]+/g,w=p("br"),C=p(ce),Z=p("p"),I=p("tr"),ee=p(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",ie,se]),v=p(["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"]);function te(e,t){const n=t||{},i="children"in e?e.children:[],r=v(e),c=j(e,{whitespace:n.whitespace||"normal"}),o=[];(e.type==="text"||e.type==="comment")&&o.push(...F(e,{breakBefore:!0,breakAfter:!0}));let s=-1;for(;++s<i.length;)o.push(...B(i[s],e,{whitespace:c,breakBefore:s?void 0:r,breakAfter:s<i.length-1?w(i[s+1]):r}));const a=[];let l;for(s=-1;++s<o.length;){const u=o[s];typeof u=="number"?l!==void 0&&u>l&&(l=u):u&&(l!==void 0&&l>-1&&a.push(`
`.repeat(l)||" "),l=-1,a.push(u))}return a.join("")}function B(e,t,n){return e.type==="element"?ne(e,t,n):e.type==="text"?n.whitespace==="normal"?F(e,n):re(e):[]}function ne(e,t,n){const i=j(e,n),r=e.children||[];let c=-1,o=[];if(ee(e))return o;let s,a;for(w(e)||I(e)&&E(t,e,I)?a=`
`:Z(e)?(s=2,a=2):v(e)&&(s=1,a=1);++c<r.length;)o=o.concat(B(r[c],e,{whitespace:i,breakBefore:c?void 0:s,breakAfter:c<r.length-1?w(r[c+1]):a}));return C(e)&&E(t,e,C)&&o.push("	"),s&&o.unshift(s),a&&o.push(a),o}function F(e,t){const n=String(e.value),i=[],r=[];let c=0;for(;c<=n.length;){A.lastIndex=c;const a=A.exec(n),l=a&&"index"in a?a.index:n.length;i.push(oe(n.slice(c,l).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),c===0?t.breakBefore:!0,l===n.length?t.breakAfter:!0)),c=l+1}let o=-1,s;for(;++o<i.length;)i[o].charCodeAt(i[o].length-1)===8203||o<i.length-1&&i[o+1].charCodeAt(0)===8203?(r.push(i[o]),s=void 0):i[o]?(typeof s=="number"&&r.push(s),r.push(i[o]),s=0):(o===0||o===i.length-1)&&r.push(0);return r}function re(e){return[String(e.value)]}function oe(e,t,n){const i=[];let r=0,c;for(;r<e.length;){T.lastIndex=r;const o=T.exec(e);c=o?o.index:e.length,!r&&!c&&o&&!t&&i.push(""),r!==c&&i.push(e.slice(r,c)),r=o?c+o[0].length:c}return r!==c&&!n&&i.push(""),i.join(" ")}function j(e,t){if(e.type==="element"){const n=e.properties||{};switch(e.tagName){case"listing":case"plaintext":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return n.wrap?"pre-wrap":"pre";case"td":case"th":return n.noWrap?"nowrap":t.whitespace;case"textarea":return"pre-wrap"}}return t.whitespace}function ie(e){return!!(e.properties||{}).hidden}function ce(e){return e.tagName==="td"||e.tagName==="th"}function se(e){return e.tagName==="dialog"&&!(e.properties||{}).open}const ae={},le=[];function fe(e){const t=e||ae;return function(n,i){K(n,"element",function(r,c){const o=Array.isArray(r.properties.className)?r.properties.className:le,s=o.includes("language-math"),a=o.includes("math-display"),l=o.includes("math-inline");let u=a;if(!s&&!a&&!l)return;let f=c[c.length-1],d=r;if(r.tagName==="code"&&s&&f&&f.type==="element"&&f.tagName==="pre"&&(d=f,f=c[c.length-2],u=!0),!f)return;const m=te(d,{whitespace:"pre"});let h;try{h=b.renderToString(m,{...t,displayMode:u,throwOnError:!0})}catch(g){const N=g,P=N.name.toLowerCase();i.message("Could not render math with KaTeX",{ancestors:[...c,r],cause:N,place:r.position,ruleId:P,source:"rehype-katex"});try{h=b.renderToString(m,{...t,displayMode:u,strict:"ignore",throwOnError:!1})}catch{h=[{type:"element",tagName:"span",properties:{className:["katex-error"],style:"color:"+(t.errorColor||"#cc0000"),title:String(g)},children:[{type:"text",value:m}]}]}}typeof h=="string"&&(h=X(h).children);const L=f.children.indexOf(d);return f.children.splice(L,1,...h),R})}}export{fe as default};
