import{c as e}from"./hast-util-is-element-Djts9Lmg.js";import{f as t}from"./unist-util-find-after-DC3iJzYV.js";const n=/\n/g,r=/[\t ]+/g,o=e("br"),i=e(function(e){return"td"===e.tagName||"th"===e.tagName}),a=e("p"),s=e("tr"),p=e(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",function(e){return Boolean((e.properties||{}).hidden)},function(e){return"dialog"===e.tagName&&!(e.properties||{}).open}]),u=e(["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 c(e,t){const n=t||{},r="children"in e?e.children:[],i=u(e),a=d(e,{whitespace:n.whitespace||"normal"}),s=[];"text"!==e.type&&"comment"!==e.type||s.push(...l(e,{breakBefore:!0,breakAfter:!0}));let p=-1;for(;++p<r.length;)s.push(...h(r[p],e,{whitespace:a,breakBefore:p?void 0:i,breakAfter:p<r.length-1?o(r[p+1]):i}));const c=[];let f;for(p=-1;++p<s.length;){const e=s[p];"number"==typeof e?void 0!==f&&e>f&&(f=e):e&&(void 0!==f&&f>-1&&c.push("\n".repeat(f)||" "),f=-1,c.push(e))}return c.join("")}function h(e,n,r){return"element"===e.type?function(e,n,r){const c=d(e,r),l=e.children||[];let f,g,m=-1,b=[];if(p(e))return b;o(e)||s(e)&&t(n,e,s)?g="\n":a(e)?(f=2,g=2):u(e)&&(f=1,g=1);for(;++m<l.length;)b=b.concat(h(l[m],e,{whitespace:c,breakBefore:m?void 0:f,breakAfter:m<l.length-1?o(l[m+1]):g}));i(e)&&t(n,e,i)&&b.push("\t");f&&b.unshift(f);g&&b.push(g);return b}(e,n,r):"text"===e.type?"normal"===r.whitespace?l(e,r):function(e){return[String(e.value)]}(e):[]}function l(e,t){const r=String(e.value),o=[],i=[];let a=0;for(;a<=r.length;){n.lastIndex=a;const e=n.exec(r),i=e&&"index"in e?e.index:r.length;o.push(f(r.slice(a,i).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),0!==a||t.breakBefore,i!==r.length||t.breakAfter)),a=i+1}let s,p=-1;for(;++p<o.length;)8203===o[p].charCodeAt(o[p].length-1)||p<o.length-1&&8203===o[p+1].charCodeAt(0)?(i.push(o[p]),s=void 0):o[p]?("number"==typeof s&&i.push(s),i.push(o[p]),s=0):0!==p&&p!==o.length-1||i.push(0);return i}function f(e,t,n){const o=[];let i,a=0;for(;a<e.length;){r.lastIndex=a;const n=r.exec(e);i=n?n.index:e.length,a||i||!n||t||o.push(""),a!==i&&o.push(e.slice(a,i)),a=n?i+n[0].length:i}return a===i||n||o.push(""),o.join(" ")}function d(e,t){if("element"===e.type){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}export{c as t};
