"use strict";const h=require("path");function S(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function W(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}),r}function F(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var d={exports:{}};const I={},k=Object.freeze(Object.defineProperty({__proto__:null,default:I},Symbol.toStringTag,{value:"Module"})),M=W(k);var j=typeof process<"u"&&process.pid?process.pid.toString(36):"",v="";if(typeof __webpack_require__!="function"&&typeof F<"u"){var $="",_=M;if(_.networkInterfaces)var w=_.networkInterfaces();if(w){e:for(let e in w){const t=w[e],r=t.length;for(var p=0;pt?e:t+1}var D=d.exports;const z=S(D),f={tailwindClassNames:new Set},B=e=>{for(const t of e){if(t==="")continue;const r=t.replace(/\\/gi,"");if(r.startsWith("[")){const n=[...r.matchAll(/(\[.+?\]:.+?):/g)],[[s,o=r]]=[...n.length>0?n:[[]]];f.tailwindClassNames.add(o),f.tailwindClassNames.add(t)}else{const[n]=[...r.matchAll(/^([a-z]+):/g)];if(n&&n[1]){const s=new RegExp(`(${n[1]}:.+):${n[1]}`,"gi"),[o]=[...r.matchAll(s)];o&&o[1]&&f.tailwindClassNames.add(o[1])}f.tailwindClassNames.add(r)}}},G=()=>f.tailwindClassNames,i=e=>e.replace(/"/g,"").replace(/'/g,""),Q=(e,t)=>e.startsWith("'")&&e.endsWith("'")?`'${t}-${i(e)}'`:e.startsWith('"')&&e.endsWith('"')?`"${t}-${i(e)}"`:e.endsWith('"')?`${t}-${i(e)}"`:e.endsWith("'")?`${t}-${i(e)}'`:e.startsWith('"')?`"${t}-${i(e)}`:e.startsWith("'")?`'${t}-${i(e)}`:`${t}-${e}`,R=(e,t)=>G().has(i(e))?Q(e,t):e,N=({c:e,classIdentifier:t,id:r})=>{const n=new RegExp(`${t}: "(.+?)"`,"gi"),s=e.matchAll(n);for(const[o,c]of s)e=e.replace(o,`${t}: "${c.split(" ").map(a=>R(a,r)).join(" ")}"`);return e},C=({c:e,classIdentifier:t,id:r})=>{const n=new RegExp(`${t}: \`(.+?)\``,"gi"),s=e.matchAll(n);for(const[o,c]of s)e=e.replace(o,`${t}: \`${c.split(" ").map(a=>R(a,r)).join(" ")}\``);return e},E=e=>t=>{const r=/className/g;if(t.match(r)){let s=t.replace(/className: "/g,`className: "${e} `).replace(/className: `/g,`className: \`${e} `);return s=N({c:s,id:e,classIdentifier:"className"}),s=C({c:s,id:e,classIdentifier:"className"}),{code:s,map:null}}else return{code:t,map:null}},b=e=>t=>{const r=/class/g;if(t.match(r)){let s=t.replace(/class: "/g,`class: "${e} `).replace(/class="/g,`class="${e} `);return s=N({c:s,id:e,classIdentifier:"class"}),s=C({c:s,id:e,classIdentifier:"class"}),{code:s,map:null}}else return{code:t,map:null}},T=new Set(["blockquote","dl","dd","h1","h2","h3","h4","h5","h6","hr","figure","p","pr","ol","ul","img","svg","video","canvas","audio","iframe","embed","object"]),H=e=>t=>q({id:e,regex:r=>new RegExp(`"${r}", {(?:.|\\s)+?}\\)`,"g"),innerRegex:r=>new RegExp(`"${r}", ({(?:.|\\s)+?})+?`,"i"),classText:"className",replace:{from:()=>", {",to:()=>`, { className: "${e}",`},appendClassFn:E})(t),L=e=>t=>q({id:e,regex:r=>new RegExp(`<${r}(?:.|\\s)*?>[^<]*`,"g"),innerRegex:r=>new RegExp(`<${r}(?:.|\\s)*?>`,"i"),classText:"class",replace:{from:r=>`<${r}`,to:r=>`<${r} class="${e}"`},appendClassFn:b})(t),q=({id:e,regex:t,innerRegex:r,classText:n,replace:{from:s,to:o},appendClassFn:c})=>a=>{let l=a;for(const m of T){const P=[...l.matchAll(t(m))].map(u=>u[0]);for(const u of P){const[A]=[...l.match(r(m))??[]];if(A.includes(n)){const O=c(e)(u);l=l.replace(u,O.code)}else l=l.replace(u,u.replace(s(m),o(m)))}}return{code:l,map:null}},J=()=>{try{const e=require(h.join(process.cwd(),"postcss.config.js"));return y(e)}catch{}try{const e=require(h.join(process.cwd(),"postcss.config.cjs"));return y(e)}catch{}try{const e=require(h.join(process.cwd(),"postcss.config.json"));return y(e)}catch{}return{plugins:{tailwindcss:{},autoprefixer:{}}}},K=e=>Object.keys(e.plugins),y=e=>e.default?e.default():e,U=e=>e.split(new RegExp("(?(e=e.trim(),t instanceof RegExp?!!t.exec(e):typeof t=="string"?e===t:Array.isArray(t)?t.some(r=>r instanceof RegExp?r.exec(e):e===r):e===t),X=({prefix:e,ignore:t})=>{const r=e.replace(".","");return{postcssPlugin:"prefix-tailwind-classes",Root(n){n.walkRules(s=>{if(!s.selectors)return!1;s.selectors=s.selectors.map(o=>{if(o.indexOf(".")!==0)return T.has(o)?o+"."+r:o;var c=U(o);return B(c),c.map(a=>V(a,t)||a.trim().length===0?a:`${r}-${a}`).join(".")})})}}},x=z("d"),Y=e=>t=>({code:E(e)(H(e)(t).code).code,map:null}),Z=e=>t=>({code:b(e)(L(e)(t).code).code,map:null}),ee=({react:e=!1,ignore:t=[]}={})=>({name:"vite-plugin-scope-tailwind",config:r=>{var o,c;const n=((c=(o=r.css)==null?void 0:o.postcss)==null?void 0:c.plugins)??[],s=J();return{css:{postcss:{plugins:[...n,...K(s).map(a=>require(h.join(process.cwd(),"node_modules",a))),X({prefix:x,ignore:t})]}}}},transform:e?Y(x):Z(x)});module.exports=ee; //# sourceMappingURL=index.cjs.map