// @bun
var{defineProperty:U,getOwnPropertyNames:I,getOwnPropertyDescriptor:N}=Object,S=Object.prototype.hasOwnProperty;function x(q){return this[q]}var d=(q)=>{var j=(P??=new WeakMap).get(q),K;if(j)return j;if(j=U({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var w of I(q))if(!S.call(j,w))U(j,w,{get:x.bind(q,w),enumerable:!(K=N(q,w))||K.enumerable})}return P.set(q,j),j},P;var L=(q)=>q;function v(q,j){this[q]=L.bind(null,j)}var c=(q,j)=>{for(var K in j)U(q,K,{get:j[K],enumerable:!0,configurable:!0,set:v.bind(j,K)})};var b=(q,j)=>()=>(q&&(j=q(q=0)),j);var m=import.meta.require;function C(q,j={}){let K={...A,...j};if(q.trim()==="")return`
`;let w=q;if(K.trimTrailingWhitespace)w=w.replace(/[ \t]+$/gm,"");if(w=u(w,K),w=f(w,K),w=h(w,K),K.trimTrailingWhitespace)w=w.replace(/[ \t]+$/gm,""),w=w.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(w=w.replace(/\r\n/g,`
`).replace(/\r/g,`
`),!w.endsWith(`
`))w+=`
`;return w}function a(q,j={}){let K={...A,...j};if(q.trim()==="")return`
`;let w=q;if(w=w.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(G,W,Y,X,Z)=>{let V=X.split(`
`),Q=V.filter(($)=>$.trim().length>0);if(Q.length===0)return G;let H=Math.min(...Q.map(($)=>{let F=$.match(/^( *)/);return F?F[1].length:0})),z=V.map(($)=>{if($.trim().length===0)return"";return $.substring(H)}).join(`
`),R=C(z,K).trimEnd().split(`
`).map(($)=>{if($.trim().length===0)return"";return W+$}).join(`
`);return`${W}\`\`\`${Y}
${R}
${W}\`\`\``}),K.trimTrailingWhitespace)w=w.replace(/[ \t]+$/gm,"");if(w=w.replace(/\r\n/g,`
`).replace(/\r/g,`
`),!w.endsWith(`
`))w+=`
`;return w}function T(q){let j=q,K=[],w="__PROTECTED_BLOCK_";return j=j.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(G)=>{let W=K.length;return K.push(G),`${w}${W}__`}),j=j.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
$1
`),j=j.replace(/(@end\w+)/g,`
$1
`),j=j.replace(/(@(?:else|elseif|empty)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
$1
`),j=j.replace(/(@(?:csrf|method|include|extends|yield|stack|vite|asset)(?:\([^)]*\))?)/g,`
$1
`),j=j.replace(/(?<=>)(<(?!\/)[^>]+>)/g,(G,W,Y,X)=>{let Z=X.substring(Y+G.length,Math.min(X.length,Y+G.length+20)),V=G.match(/<(\w+)/)?.[1];if(V&&Z.match(new RegExp(`^</${V}>`)))return G;return`
${G}`}),j=j.replace(/(>)(<\/)/g,(G,W,Y,X,Z)=>{let V=Z.substring(Math.max(0,X-50),X),H=Z.substring(X+G.length,Math.min(Z.length,X+G.length+20)).match(/^(\w+)>/)?.[1],z=V.match(/<(\w+)[^>]*$/)?.[1];if(z&&H&&z===H)return G;return`${W}
${Y}`}),j=j.replace(/(<\/[^>]+>)(?=<|$)/g,(G,W,Y,X)=>{let Z=X.substring(Math.max(0,Y-20),Y),V=G.match(/<\/(\w+)>/)?.[1],Q=new RegExp(`<${V}[^>]*>$`);if(V&&Z.match(Q))return G;return`${G}
`}),j=j.replace(new RegExp(`${w}(\\d+)__`,"g"),(G,W)=>{return K[Number.parseInt(W,10)]}),j=j.replace(/\n{2,}/g,`
`),j=j.split(`
`).map((G)=>G.trim()).join(`
`),j=j.replace(/^\n+/,"").replace(/\n+$/,""),j}function u(q,j){let w=T(q).split(`
`),G=[],W=0,Y=!1,X=j.useTabs?"\t":" ".repeat(j.indentSize);for(let Z=0;Z<w.length;Z++){let V=w[Z],Q=V.trim();if(Q===""){G.push("");continue}let H=Q.match(/<script\b/i),z=Q.match(/<\/script>/i);if(Y&&!z){G.push(V);continue}let J=Q===">";if(y(Q)&&!Q.startsWith("<")&&!Q.startsWith("@")){G.push(X.repeat(W)+Q);continue}let R=Q.startsWith("@end"),$=Q.startsWith("@else")||Q.startsWith("@elseif"),F=Q.startsWith("@")&&p(Q),B=Q.startsWith("<!DOCTYPE")||Q.startsWith("<!doctype"),k=Q.startsWith("<!--"),_=Q.startsWith("</"),E=Q.startsWith("<")&&!_&&!k&&!B,M=Q.includes("/>")||g(Q),O=y(Q);if(_||R)W=Math.max(0,W-1);let D=$?Math.max(0,W-1):W;if(J)G.push(V);else G.push(X.repeat(D)+Q);if(E&&!M&&!O&&!J||F)W++;if(H)Y=!0;if(z)Y=!1}return G.join(`
`)}function h(q,j){if(q=q.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(K,w,G)=>{let W=G.trim().replace(/\s+/g," ");return`@${w}(${W})`}),q=q.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(K,w,G)=>{if(G.trim()==="")return`@${w}`;return`@${w}(${G.trim()})`}),j.normalizeWhitespace)q=q.replace(/\{\{\s*([^}]+)\s*\}\}/g,(K,w)=>{return`{{ ${w.trim()} }}`}),q=q.replace(/\{!!\s*([^!]+)\s*!!\}/g,(K,w)=>{return`{!! ${w.trim()} !!}`});return q}function g(q){let j=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(q.includes("/>"))return!0;let K=q.match(/<(\w+)/);if(K){let w=K[1];return j.includes(w.toLowerCase())}return!1}function y(q){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(q)}function p(q){let j=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let K of j)if(q.startsWith(`@${K}`))return!q.includes(`@end${K}`);return!1}function f(q,j){if(!j.sortAttributes)return q;return q.replace(/<(\w+)([^>]*)>/g,(K,w,G)=>{if(!G.trim())return K;if(G.includes("<")||G.includes(`
`)||G.includes("@"))return K;let W=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Y=[],X;while((X=W.exec(G))!==null)Y.push({name:X[1],value:X[2]});Y.sort((V,Q)=>{if(V.name==="id")return-1;if(Q.name==="id")return 1;if(V.name==="class")return-1;if(Q.name==="class")return 1;return V.name.localeCompare(Q.name)});let Z=Y.map((V)=>V.value?`${V.name}=${V.value}`:V.name).join(" ");return`<${w}${Z?` ${Z}`:""}>`})}var A;var l=b(()=>{A={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0}});l();export{C as formatStxContent,a as formatMarkdownContent};
