"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../../../hast-util-is-element@3.0.0/node_modules/hast-util-is-element/lib/index.cjs.js"),f=require("../../../../unist-util-find-after@5.0.0/node_modules/unist-util-find-after/lib/index.cjs.js"),d=/\n/g,g=/[\t ]+/g,h=u.convertElement("br"),m=u.convertElement(j),A=u.convertElement("p"),x=u.convertElement("tr"),v=u.convertElement(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",B,N]),b=u.convertElement(["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 E(e,o){const l=o||{},n="children"in e?e.children:[],r=b(e),i=y(e,{whitespace:l.whitespace||"normal"}),t=[];(e.type==="text"||e.type==="comment")&&t.push(...k(e,{breakBefore:!0,breakAfter:!0}));let s=-1;for(;++s<n.length;)t.push(...w(n[s],e,{whitespace:i,breakBefore:s?void 0:r,breakAfter:s<n.length-1?h(n[s+1]):r}));const c=[];let a;for(s=-1;++s<t.length;){const p=t[s];typeof p=="number"?a!==void 0&&p>a&&(a=p):p&&(a!==void 0&&a>-1&&c.push(`
`.repeat(a)||" "),a=-1,c.push(p))}return c.join("")}function w(e,o,l){return e.type==="element"?T(e,o,l):e.type==="text"?l.whitespace==="normal"?k(e,l):C(e):[]}function T(e,o,l){const n=y(e,l),r=e.children||[];let i=-1,t=[];if(v(e))return t;let s,c;for(h(e)||x(e)&&f.findAfter(o,e,x)?c=`
`:A(e)?(s=2,c=2):b(e)&&(s=1,c=1);++i<r.length;)t=t.concat(w(r[i],e,{whitespace:n,breakBefore:i?void 0:s,breakAfter:i<r.length-1?h(r[i+1]):c}));return m(e)&&f.findAfter(o,e,m)&&t.push("	"),s&&t.unshift(s),c&&t.push(c),t}function k(e,o){const l=String(e.value),n=[],r=[];let i=0;for(;i<=l.length;){d.lastIndex=i;const c=d.exec(l),a=c&&"index"in c?c.index:l.length;n.push(S(l.slice(i,a).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,""),i===0?o.breakBefore:!0,a===l.length?o.breakAfter:!0)),i=a+1}let t=-1,s;for(;++t<n.length;)n[t].charCodeAt(n[t].length-1)===8203||t<n.length-1&&n[t+1].charCodeAt(0)===8203?(r.push(n[t]),s=void 0):n[t]?(typeof s=="number"&&r.push(s),r.push(n[t]),s=0):(t===0||t===n.length-1)&&r.push(0);return r}function C(e){return[String(e.value)]}function S(e,o,l){const n=[];let r=0,i;for(;r<e.length;){g.lastIndex=r;const t=g.exec(e);i=t?t.index:e.length,!r&&!i&&t&&!o&&n.push(""),r!==i&&n.push(e.slice(r,i)),r=t?i+t[0].length:i}return r!==i&&!l&&n.push(""),n.join(" ")}function y(e,o){if(e.type==="element"){const l=e.properties||{};switch(e.tagName){case"listing":case"plaintext":case"xmp":return"pre";case"nobr":return"nowrap";case"pre":return l.wrap?"pre-wrap":"pre";case"td":case"th":return l.noWrap?"nowrap":o.whitespace;case"textarea":return"pre-wrap"}}return o.whitespace}function B(e){return!!(e.properties||{}).hidden}function j(e){return e.tagName==="td"||e.tagName==="th"}function N(e){return e.tagName==="dialog"&&!(e.properties||{}).open}exports.toText=E;
//# sourceMappingURL=index.cjs.js.map
