// @bun
var{defineProperty:Z,getOwnPropertyNames:K,getOwnPropertyDescriptor:W}=Object,B=Object.prototype.hasOwnProperty;function A(j){return this[j]}var g=(j)=>{var q=(b??=new WeakMap).get(j),F;if(q)return q;if(q=Z({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var z of K(j))if(!B.call(q,z))Z(q,z,{get:A.bind(j,z),enumerable:!(F=W(j,z))||F.enumerable})}return b.set(j,q),q},b;var D=(j)=>j;function T(j,q){this[j]=D.bind(null,q)}var P=(j,q)=>{for(var F in q)Z(j,F,{get:q[F],enumerable:!0,configurable:!0,set:T.bind(q,F)})};var S=(j,q)=>()=>(j&&(q=j(j=0)),q);var k=import.meta.require;function N(j,q=""){let F=`${j}${q}`,z=0;for(let G=0;G<F.length;G++){let J=F.charCodeAt(G);z=(z<<5)-z+J,z=z&z}return`stx-${Math.abs(z).toString(36)}`}function M(j,q,F={}){let{prefix:z="",preserveHost:G=!0,scopeKeyframes:J=!0,scopeCustomProperties:E=!1}=F;if(!j.trim())return"";let U=_(j),Q=[],O=new Map;if(J)for(let L of U){let V=L.selector.match(/@keyframes\s+([a-z_-][a-z0-9_-]*)/i);if(V){let X=V[1],Y=`${q}_${X}`;O.set(X,Y)}}for(let L of U){let V=w(L,q,z,G,O,E);Q.push(V)}return Q.join(`

`)}function _(j){let q=[],F=j.replace(/\/\*[\s\S]*?\*\//g,""),z=0,G="",J=!1,E="";for(let U=0;U<F.length;U++){let Q=F[U];if(Q==="@"&&z===0)J=!0;if(Q==="{")z++;else if(Q==="}"){if(z--,z===0){if(J){E+=Q;let O=E.match(/@([a-z-]+)\s*([^{]*)\{([\s\S]*)\}/i);if(O){let[,L,V,X]=O;if(L==="keyframes")q.push({selector:`@keyframes ${V.trim()}`,declarations:X.trim()});else if(L==="media"||L==="supports"||L==="container"){let Y=_(X);q.push({selector:`@${L} ${V.trim()}`,declarations:Y.map(($)=>`${$.selector} { ${$.declarations} }`).join(`
`)})}else q.push({selector:`@${L} ${V.trim()}`,declarations:X.trim()})}E="",J=!1}else if(G.trim()){G+=Q;let O=G.match(/([^{]+)\{([^}]*)\}/);if(O)q.push({selector:O[1].trim(),declarations:O[2].trim()});G=""}continue}}if(J)E+=Q;else G+=Q}return q}function w(j,q,F,z,G,J){let{selector:E,declarations:U}=j;if(E.startsWith("@")){if(E.startsWith("@keyframes")){let L=E.replace("@keyframes ","").trim();return`@keyframes ${G.get(L)||L} { ${U} }`}if(E.startsWith("@media")||E.startsWith("@supports")||E.startsWith("@container")){let V=_(`x { ${U} }`.replace(/x \{ /,"").replace(/ \}$/,"")).map((X)=>w(X,q,F,z,G,J)).join(`
  `);return`${E} {
  ${V}
}`}return`${E} { ${U} }`}let Q=H(E,q,F,z),O=U;for(let[L,V]of G)O=O.replace(new RegExp(`\\b${L}\\b`,"g"),V);if(J)O=O.replace(/--([a-z-]+)/gi,`--${q}-$1`);return`${Q} { ${O} }`}function H(j,q,F,z){let G=j.split(",").map((E)=>E.trim()),J=[];for(let E of G){if(E.startsWith(":host")){if(z)J.push(E);else{let Q=E.replace(/:host(\([^)]*\))?/,`.${q}$1`);J.push(Q)}continue}if(E.includes("::slotted")){J.push(E);continue}if(E===":root"){J.push(`:root .${q}`);continue}let U=F?`${F} .${q}`:`.${q}`;J.push(`${U} ${E}`)}return J.join(", ")}function C(j){let q=j.match(/<style\b[^>]*>([\s\S]*?)<\/style>/i),F=q?q[1]:"",z=q?j.replace(/<style\b[^>]*>[\s\S]*?<\/style>/i,""):j;return{css:F,templateWithoutStyle:z}}function I(j,q,F="head"){if(!q.trim())return j;let z=`<style data-stx-scoped>
${q}
</style>`;switch(F){case"head":if(j.includes("</head>"))return j.replace("</head>",`${z}
</head>`);return z+j;case"body-start":if(j.includes("<body"))return j.replace(/(<body[^>]*>)/,`$1
${z}`);return z+j;case"body-end":{let G=j.lastIndexOf("</body>");if(G!==-1)return j.slice(0,G)+z+`
`+j.slice(G);return j+z}default:return j}}function f(j){return j.trim()}export{M as scopeCss,I as injectScopedCss,f as generateShadowDomCss,N as generateComponentId,C as extractStyleFromTemplate};
