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