UNPKG

@visulima/packem

Version:

A fast and modern bundler for Node.js and TypeScript.

20 lines (19 loc) 24.2 kB
var ke=Object.defineProperty;var d=(e,t)=>ke(e,"name",{value:t,configurable:!0});import{fileURLToPath as Re}from"node:url";import Ee from"@csstools/postcss-slow-plugins";import{makeLegalIdentifier as q}from"@rollup/pluginutils";import{dirname as S,normalize as x,parse as Z,resolve as Ne,basename as I,isAbsolute as Ie,join as pe,relative as Ce}from"@visulima/path";import Ue from"postcss";import{r as F}from"../../../../../packem_shared/resolve-C7N_MxXM.mjs";import{f as K,d as De,e as A,p as Le,g as _e}from"../../../../../packem_shared/Mime-FoPIch-Y.mjs";import{H as L,m as D,D as Fe,F as se}from"../../../../../packem_shared/sourcemap-Crbje9In.mjs";import{n as re}from"../../../../../packem_shared/ensure-auto-modules-BU3xWEjl.mjs";import{extractICSS as Te,replaceSymbols as We,replaceValueSymbols as Ae}from"icss-utils";import{readFile as Me,readFileSync as le}from"@visulima/fs";import{isRelative as Be}from"@visulima/path/utils";import{isWhiteSpaceOrCommentNode as H,isSimpleBlockNode as Xe,SimpleBlockNode as Ge,parseListOfComponentValues as Je,isTokenNode as M,isFunctionNode as U,stringify as E}from"@csstools/css-parser-algorithms";import{isTokenOpenParen as He,TokenType as oe,tokenize as ze,isTokenString as B,isTokenURL as ne,isTokenIdent as Ve}from"@csstools/css-tokenizer";import{findMonorepoRoot as Qe,findPackageRoot as Ye}from"@visulima/package";import qe from"postcss-load-config";import Ze from"postcss-modules-extract-imports";import Ke from"postcss-modules-local-by-default";import et from"postcss-modules-scope";import tt from"postcss-modules-values";import z from"postcss-value-parser";var st=Object.defineProperty,rt=d((e,t)=>st(e,"name",{value:t,configurable:!0}),"e$3");const ot=rt((e,...t)=>{const s=K([e,"0iOXBLSx",...t].join(":")).slice(0,8);return q(`${e}_${s}`)},"default");var nt=Object.defineProperty,it=d((e,t)=>nt(e,"name",{value:t,configurable:!0}),"i$4");const at=it(async(e,t,s,n,o)=>{const r=F([e,`./${e}`],{baseDirs:[S(t)],caller:"ICSS loader",extensions:s}),i=await Me(r),{messages:p}=await n.process(i,{...o,from:r}),l={};for(const c of p)c.type==="icss"&&Object.assign(l,c.export);return l},"load");var ct=Object.defineProperty,pt=d((e,t)=>ct(e,"name",{value:t,configurable:!0}),"t$3");const lt=pt(async(e,t,s,n,o,r)=>{const i={};for await(const[p,l]of Object.entries(e)){const c=await t(p,s,n,o,r);for(const[a,f]of Object.entries(l))i[a]=c[f]}return i},"resolve");var ut=Object.defineProperty,ft=d((e,t)=>ut(e,"name",{value:t,configurable:!0}),"c$4");const X="styles-icss",mt=[".css",".pcss",".postcss",".sss"],ue=ft(e=>{const t=e?.load??at,s=e?.extensions??mt;return{async OnceExit(n,{result:o}){if(!n.source?.input.file)return;const r={...o.opts,map:void 0},{icssExports:i,icssImports:p}=Te(n),l=await lt(p,t,n.source.input.file,s,o.processor,r);We(n,l);for(const[c,a]of Object.entries(i))o.messages.push({export:{[c]:Ae(a,l)},plugin:X,type:"icss"});for(const c of Object.keys(p))o.messages.push({import:c,plugin:X,type:"icss-dependency"})},postcssPlugin:X}},"plugin");ue.postcss=!0;var dt=Object.defineProperty,ht=d((e,t)=>dt(e,"name",{value:t,configurable:!0}),"t$2");const V=ht((e,t,s,n)=>{const o=[];if(e!==void 0){let r="layer";e&&(r=`layer(${e})`),o.push(r)}return s!==void 0&&o.push(`supports(${s})`),n!==void 0&&o.push(`scope(${n})`),t!==void 0&&o.push(t),o.join(" ")},"formatImportPrelude");var gt=Object.defineProperty,vt=d((e,t)=>gt(e,"name",{value:t,configurable:!0}),"p$4");const yt=vt((e,t)=>{t.reverse();const s=t.pop();if(!s)return e;let n=`${e} ${V(s.layer,s.media,s.supports,s.scope)}`;for(const o of t)n=`'data:text/css;base64,${Buffer.from(`@import ${n}`).toString("base64")}' ${V(o.layer,o.media,o.supports,o.scope)}`;return n},"base64EncodedConditionalImport");var $t=Object.defineProperty,T=d((e,t)=>$t(e,"name",{value:t,configurable:!0}),"e$2");const bt=T(e=>e.type==="warning","isWarning"),Q=T(e=>e.type==="nodes","isNodesStatement"),_=T(e=>e.type==="import","isImportStatement"),wt=T(e=>e.type==="pre-import","isPreImportStatement");var St=Object.defineProperty,jt=d((e,t)=>St(e,"name",{value:t,configurable:!0}),"u$1");const Ot=jt((e,t)=>{e.statements.forEach((s,n)=>{if(bt(s)||wt(s)||s.conditions.length===0)return;if(_(s)){s.node.params=yt(s.fullUri,s.conditions);return}const{nodes:o}=s;if(o.length===0)return;const{parent:r}=o[0];if(!r)return;const i=[];for(const c of s.conditions){if(c.media!==void 0){const a=t({name:"media",params:c.media,source:s.importingNode?.source??r.source});i.push(a)}if(c.scope!==void 0){const a=t({name:"scope",params:c.scope,source:s.importingNode?.source??r.source});i.push(a)}if(c.supports!==void 0){const a=t({name:"supports",params:`(${c.supports})`,source:s.importingNode?.source??r.source});i.push(a)}if(c.layer!==void 0){const a=t({name:"layer",params:c.layer,source:s.importingNode?.source??r.source});i.push(a)}}const p=i[0];if(!p)return;for(let c=0;c<i.length-1;c++)i[c].append(i[c+1]);const l=i.at(-1);r.insertBefore(o[0],p),o.forEach(c=>{c.parent=void 0}),l.append(o),e.statements[n]={conditions:s.conditions,from:s.from,importingNode:s.importingNode,nodes:[p],type:"nodes"}})},"applyConditions");var Pt=Object.defineProperty,xt=d((e,t)=>Pt(e,"name",{value:t,configurable:!0}),"r$4");const kt=xt(e=>{e.statements.forEach((t,s)=>{if(s!==0)if(t.parent!==void 0){const{before:n}=t.parent.node.raws;Q(t)?t.nodes[0].raws.before=n:t.node.raws.before=n}else Q(t)&&(t.nodes[0].raws.before=t.nodes[0].raws.before??` `)})},"applyRaws");var Rt=Object.defineProperty,Et=d((e,t)=>Rt(e,"name",{value:t,configurable:!0}),"t$1");const Nt=Et((e,t)=>{t.nodes=[],e.charset&&(e.charset.parent=void 0,t.append(e.charset)),e.statements.forEach(s=>{_(s)?(s.node.parent=void 0,t.append(s.node)):Q(s)&&s.nodes.forEach(n=>{n.parent=void 0,t.append(n)})})},"applyStyles");var It=Object.defineProperty,Ct=d((e,t)=>It(e,"name",{value:t,configurable:!0}),"o$3");const Ut=Ct((e,t,s)=>{const n={baseDirs:[t],caller:"@import resolver",extensions:s},o=new URL(e,"file://").pathname,r=[o];return(Be(o)||o.startsWith("/"))&&r.push(`.${o}`),o.startsWith("/")&&r.push(o.slice(1)),F(r,n)},"importResolve");var Dt=Object.defineProperty,fe=d((e,t)=>Dt(e,"name",{value:t,configurable:!0}),"e$1");const Lt=/^data:text\/css(?:;(?:base64|plain))?,/i,_t=/^data:text\/css;base64,/i,Ft=/^data:text\/css;plain,/i,Y=fe(e=>e!==void 0&&Lt.test(e),"isValidDataURL"),Tt=fe(e=>_t.test(e)?Buffer.from(e.slice(21),"base64").toString():Ft.test(e)?decodeURIComponent(e.slice(20)):decodeURIComponent(e.slice(14)),"dataURLContents");var Wt=Object.defineProperty,At=d((e,t)=>Wt(e,"name",{value:t,configurable:!0}),"o$1");const Mt="css-noop",ee=At(()=>({postcssPlugin:Mt}),"noopPlugin");ee.postcss=!0;var Bt=Object.defineProperty,me=d((e,t)=>Bt(e,"name",{value:t,configurable:!0}),"a$3");const de=me(async(e,t,s,n,o,r)=>(r===void 0&&(r=0),n.length===0&&n.push(ee()),await e(n).process(t,{from:s,parser:o[r]}).catch(async i=>{if(r++,r===o.length)throw i;return await de(e,t,s,n,o,r)})),"runPostcss"),Xt=me(async(e,t,s,n,o)=>{const{plugins:r}=n,i=[];return e.opts.syntax?.parse&&i.push(e.opts.syntax.parse),e.opts.parser&&i.push(e.opts.parser),i.push(void 0),await de(o,t,s,r,i)},"processContent"),Gt=/^charset$/i,he=/^import$/i,Jt=/^url$/i,C=/^layer$/i,Ht=/^supports$/i,zt=/^scope$/i;var Vt=Object.defineProperty,te=d((e,t)=>Vt(e,"name",{value:t,configurable:!0}),"a$2");const Qt=te(e=>{for(let t=0;t<e.length;t++){const s=e[t];if(!H(s)&&Xe(s)&&He(s.startToken))return e}return[new Ge([oe.OpenParen,"(",-1,-1,void 0],[oe.CloseParen,")",-1,-1,void 0],e)]},"wrapInParenthesisIfNeeded"),ie=te(e=>{if(e.startsWith("#"))return"";if(!e.includes("#"))return e;try{const t=new URL(e,"http://example.com");return t.hash?e.slice(0,e.length-t.hash.length):e}catch{return e}},"stripHash"),Yt=te(e=>{const t=ze({css:e});if(t.length===2&&(B(t[0])||ne(t[0]))){let c=t[0][4].value;return c=ie(c),c?{fullUri:t[0][1],uri:c}:!1}const s=Je(t);let n="",o="",r,i,p,l;for(let c=0;c<s.length;c++){const a=s[c];if(!H(a)){if(M(a)&&(B(a.value)||ne(a.value))){if(n)return!1;n=a.value[4].value,o=a.value[1];continue}if(U(a)&&Jt.test(a.getName())){if(n)return!1;for(let f=0;f<a.value.length;f++){const u=a.value[f];if(!H(u)){if(!n&&M(u)&&B(u.value)){n=u.value[4].value,o=E([[a]]);continue}return!1}}continue}if(!n)return!1;if(M(a)&&Ve(a.value)&&C.test(a.value[4].value)){if(r!==void 0||p!==void 0)return!1;r="";continue}if(U(a)&&C.test(a.getName())){if(r!==void 0||p!==void 0)return!1;r=E([a.value]);continue}if(U(a)&&Ht.test(a.getName())){if(p!==void 0)return!1;p=E([a.value]);continue}if(U(a)&&zt.test(a.getName())){if(l!==void 0)return!1;l=E([Qt(a.value)]);continue}i=E([s.slice(c)]);break}}return n=ie(n),n?{fullUri:o,layer:r,media:i,scope:l,supports:p,uri:n}:!1},"parseAtImport");var qt=Object.defineProperty,k=d((e,t)=>qt(e,"name",{value:t,configurable:!0}),"l");const ge=k((e,t,s,n)=>{const o=[];let r=t;const i=e.length;for(r;r<i;r++){const p=e[r];if(o.push(p),e[r+1]?.type!=="comment")break}return[r,{conditions:[],from:n,importingNode:s,nodes:o,type:"nodes"}]},"consumeComments"),Zt=k((e,t,s,n,o)=>{const r=Yt(t.params);if(!r)return e.warn(`Invalid @import statement in '${t.toString()}'`,{node:t});const i={conditions:[...n],from:o,fullUri:r.fullUri,importingNode:s,node:t,type:"import",uri:r.uri};return(r.layer!==void 0||r.media!==void 0||r.supports!==void 0||r.scope!==void 0)&&i.conditions.push({layer:r.layer,media:r.media,scope:r.scope,supports:r.supports}),i},"parseImport"),Kt=k((e,t,s,n,o,r)=>{const i=[];let p=n;const l=t.length;for(p;p<l;p++){const c=t[p];if(c.type==="comment"){const[a,f]=ge(t,p,o,r);i.push(f),p=a;continue}if(c.type==="atrule"&&he.test(c.name)){i.push(Zt(e,c,o,s,r));continue}break}return[p-1,i]},"consumeImports"),es=k((e,t,s,n,o)=>{const r=[];let i=s;const p=e.length;for(i;i<p;i++){const l=e[i];r.push(l);const c=e[i+1];if(!(c&&c.type==="atrule"&&C.test(c.name)&&!c.nodes))break}return[i,{conditions:[...t],from:o,importingNode:n,nodes:r,type:"nodes"}]},"consumeLayers"),ts=k((e,t,s,n,o)=>{const r=[];let i=s;const p=e.length;for(i;i<p;i++){const l=e[i];if(l.type==="comment"){const[c,a]=ge(e,i,n,o);r.push(a),i=c;continue}if(l.type==="atrule"&&C.test(l.name)&&!l.nodes)if(t.length>0){r.push({conditions:[...t],from:o,importingNode:n,node:l,type:"pre-import"});continue}else{const[c,a]=es(e,t,i,n,o);r.push(a),i=c;continue}break}return[i-1,r]},"consumeBeforeImports"),ve=k((e,t,s,n,o)=>{const r={statements:[]};if(t.type==="document")return t.each(f=>{const u=ve(e,f,s,n,o);if(r.charset&&u.charset&&r.charset.params.toLowerCase()!==u.charset.params.toLowerCase())throw u.charset.error(`Incompatible @charset statements: ${u.charset.params} specified in ${u.charset.source?.input.file} ${r.charset.params} specified in ${r.charset.source?.input.file}`);!r.charset&&u.charset&&(r.charset=u.charset),r.statements.push(...u.statements)}),r;let i,p=[],l=[],c;for(let f=0;f<t.nodes.length;f++){const u=t.nodes[f];if(f===0&&u.type==="atrule"&&Gt.test(u.name)){i=u;continue}if(l.length===0&&(u.type==="comment"||u.type==="atrule"&&C.test(u.name)&&!u.nodes)){[f,p]=ts(t.nodes,n,f,s,o);continue}if(l.length===0&&u.type==="atrule"&&he.test(u.name)){[f,l]=Kt(e,t.nodes,n,f,s,o);continue}c={conditions:[...n],from:o,importingNode:s,nodes:t.nodes.slice(f),type:"nodes"};break}const a=[];return p.length>0&&a.push(...p),l.length>0&&a.push(...l),c&&a.push(c),{charset:i,statements:a}},"parseStylesheet");var ss=Object.defineProperty,W=d((e,t)=>ss(e,"name",{value:t,configurable:!0}),"h");const rs=/^(?:[a-z]+:)?\/\//i,os=W(e=>{if(rs.test(e))return!1;try{if(new URL(e,"https://example.com").search)return!1}catch{}return!0},"isProcessableURL"),ae=W(async(e,t,s,n,o,r)=>{const{conditions:i,from:p,node:l}=t,c=i.map(h=>V(h.layer,h.media,h.supports,h.scope)).join(":");if(n.skipDuplicates){if(o.importedFiles[s]?.[c])return{statements:[]};o.importedFiles[s]||(o.importedFiles[s]={}),o.importedFiles[s][c]=!0}if(p.includes(s))return{statements:[]};const a=await n.load(s,n);if(a.trim()===""&&n.warnOnEmpty)return e.warn(`${s} is empty`,{node:l}),{statements:[]};if(n.skipDuplicates&&o.hashFiles[a]?.[c])return{statements:[]};const f=await Xt(e,a,s,n,r),u=f.root;return n.debug&&u.append({text:s}),e.messages=[...e.messages,...f.messages],n.skipDuplicates&&(u.some(h=>h.type==="atrule"&&h.name==="import")||(o.hashFiles[a]||(o.hashFiles[a]={}),o.hashFiles[a][c]=!0)),await ye(n,e,u,o,l,i,[...p,s],r)},"loadImportContent"),ns=W(async(e,t,s,n,o)=>{if(Y(s.uri)){s.stylesheet=await ae(t,s,s.uri,e,n,o);return}if(Y(s.from.at(-1))){s.stylesheet={statements:[]},t.warn(`Unable to import '${s.uri}' from a stylesheet that is embedded in a data url`,{node:s.node});return}const r=s.node;let i;r.source?.input.file&&(i=r.source.input.file);const p=i?S(i):e.root;for(const[c,a]of Object.entries(e.alias))s.uri!==c&&!s.uri.startsWith(`${c}/`)||(s.uri=x(a)+s.uri.slice(c.length));let l;try{l=await e.resolve(s.uri,p,e.extensions,r)}catch{s.node.warn(t,`Unable to resolve "${s.uri}" from "${p}"`);return}t.messages.push({file:l,parent:i,plugin:"packem-postcss-import",type:"dependency"}),s.stylesheet=await ae(t,s,l,e,n,o)},"resolveImportId"),ye=W(async(e,t,s,n,o,r,i,p)=>{let{charset:l,statements:c}=ve(t,s,o,r,i);{const a=[];for await(const f of c)!_(f)||!os(f.uri)||e.filter&&!e.filter(f.uri)||a.push(ns(e,t,f,n,p));a.length>0&&await Promise.all(a)}for(let a=0;a<c.length;a++){const f=c[a];if(_(f)&&f.stylesheet){if(l&&f.stylesheet.charset&&l.params.toLowerCase()!==f.stylesheet.charset.params.toLowerCase())throw f.stylesheet.charset.error(`Incompatible @charset statements: ${f.stylesheet.charset.params} specified in ${f.stylesheet.charset.source?.input.file} ${l.params} specified in ${l.source?.input.file}`);!l&&f.stylesheet.charset&&(l=f.stylesheet.charset),c.splice(a,1,...f.stylesheet.statements),a--}}return{charset:l,statements:c}},"parseStyles");var is=Object.defineProperty,as=d((e,t)=>is(e,"name",{value:t,configurable:!0}),"r$2");const cs=as(e=>Y(e)?Tt(e):le(e),"loadContent");var ps=Object.defineProperty,ls=d((e,t)=>ps(e,"name",{value:t,configurable:!0}),"i");const us="css-import",fs=[".css",".pcss",".postcss",".sss"],$e=ls(e=>{const t={alias:e?.alias??{},extensions:e?.extensions??fs,load:cs,plugins:[],resolve:e?.resolve??Ut,skipDuplicates:!1,...e};return{async Once(s,{atRule:n,postcss:o,result:r}){const i={hashFiles:{},importedFiles:{}};if(s.source?.input.file&&(i.importedFiles[s.source.input.file]={}),!Array.isArray(t.plugins))throw new TypeError("plugins option must be an array");const p=await ye(t,r,s,i,void 0,[],[],o);kt(p),Ot(p,n),Nt(p,s)},postcssPlugin:us}},"plugin");$e.postcss=!0;var ms=Object.defineProperty,ds=d((e,t)=>ms(e,"name",{value:t,configurable:!0}),"p$1");let G;const hs=ds(async(e,t,s,n)=>{if(!n)return{file:"",options:{},plugins:[]};const{dir:o}=Z(e),r=n.path?Ne(n.path):o;let i;try{i=(await Qe(t)).path}catch{try{i=await Ye(t)}catch{}}try{let p;G?p=G:(p=await qe({cwd:t,env:s,...n.ctx},r,{stopDir:i}),G=p);const l={file:p.file,options:p.options,plugins:await De(p.plugins,t)};return l.options.parser&&(l.options.parser=await A(l.options.parser,"parser",t)),l.options.syntax&&(l.options.syntax=await A(l.options.syntax,"syntax",t)),l.options.stringifier&&(l.options.stringifier=await A(l.options.stringifier,"stringifier",t)),l}catch(p){if(p.message.includes("No PostCSS Config found in"))return{file:"",options:{},plugins:[]};throw p}},"loadConfig");var gs=Object.defineProperty,vs=d((e,t)=>gs(e,"name",{value:t,configurable:!0}),"n$2");const ys=vs((e="[name]_[local]_[hash:8]")=>(t,s,n)=>{const{base:o,dir:r,name:i}=Z(s),p=K(`${o}:${n}`),l=L.exec(e),c=l&&Number.parseInt(l[1],10);return q(e.replace("[dir]",I(r)).replace("[name]",i.replace(/\.module$/,"")).replace("[local]",t).replace(L,c?p.slice(0,c):p))},"generate");var $s=Object.defineProperty,bs=d((e,t)=>$s(e,"name",{value:t,configurable:!0}),"r$1");const ws=bs(e=>{const t={mode:"local",...e,generateScopedName:typeof e.generateScopedName=="function"?e.generateScopedName:ys(e.generateScopedName)};return[tt(),Ke({mode:t.mode}),Ze({failOnWrongOrder:t.failOnWrongOrder}),et({exportGlobals:t.exportGlobals,generateScopedName:t.generateScopedName})]},"default");var Ss=Object.defineProperty,js=d((e,t)=>Ss(e,"name",{value:t,configurable:!0}),"c$2");const Os=js((e,t,s)=>{const{base:n,dir:o,ext:r,name:i}=Z(t),p=K(`${n}:${Buffer.from(s).toString()}`),l=L.exec(e),c=l&&Number.parseInt(l[1],10);return e.replace("[dir]",I(o)).replace("[name]",i).replace("[extname]",r).replace(".[ext]",r).replace("[ext]",r.slice(1)).replace(L,c?p.slice(0,c):p.slice(0,8))},"default"),Ps=new Le(_e)._freeze();var xs=Object.defineProperty,ks=d((e,t)=>xs(e,"name",{value:t,configurable:!0}),"r");const Rs=ks((e,t)=>{const s=Ps.getType(e)??"application/octet-stream",n=Buffer.from(t).toString("base64");return`data:${s};base64,${n}`},"default");var Es=Object.defineProperty,Ns=d((e,t)=>Es(e,"name",{value:t,configurable:!0}),"a");const Is=Ns(async(e,t)=>{const s=new URL(e,"file://"),n=s.hash?s.hash.slice(1):"",o=e.split("?")[0]??"",r=[o];o.startsWith("/")&&r.push(`.${o}`),!o.startsWith("/")&&!o.startsWith(".")&&r.push(`./${o}`);const i=F(r,{baseDirs:t,caller:"URL resolver"}),p=new URLSearchParams(s.search).toString();return{from:i,source:le(i,{buffer:!0}),urlQuery:(p?`?${p}`:"")+(n?`#${n}`:"")}},"urlResolve");var Cs=Object.defineProperty,be=d((e,t)=>Cs(e,"name",{value:t,configurable:!0}),"n");const ce=/^url$/i,Us=/^(?:-webkit-)?image-set$/i,Ds=be(e=>/(?:url|(?:-webkit-)?image-set)\(/i.test(e.value),"isDeclWithUrl"),Ls=be((e,t)=>{e.walk(s=>{if(s.type==="function"){if(ce.test(s.value)){const{nodes:n}=s,[o]=n,r=o?.type==="string"?o.value:z.stringify(n);t(r.replaceAll(/^\s+|\s+$/g,""),o);return}if(Us.test(s.value))for(const n of s.nodes){if(n.type==="string"){t(n.value.replaceAll(/^\s+|\s+$/g,""),n);continue}if(n.type==="function"&&ce.test(n.value)){const{nodes:o}=n,[r]=o,i=r?.type==="string"?r.value:z.stringify(o);t(i.replaceAll(/^\s+|\s+$/g,""),r)}}}})},"walkUrls");var _s=Object.defineProperty,Fs=d((e,t)=>_s(e,"name",{value:t,configurable:!0}),"$");const J="packem-css-url",Ts="assets/[name]-[hash][extname]",Ws="assets/[name][extname]",As="./assets/",Ms=".",we=Fs(e=>{const t={alias:{},assetDir:Ms,inline:!1,resolve:Is,...e},s=t.hash??!0?typeof t.hash=="string"?t.hash:Ts:Ws;return{async Once(n,{result:o}){if(!n.source?.input.file)return;const{file:r}=n.source.input,i=D(n.source.input.map?.text??void 0).resolve(S(r)).toConsumer(),p=[],l=new Set(o.messages.filter(a=>a.type==="dependency").map(a=>a.file));n.walkDecls(a=>{if(!Ds(a))return;const f=z(a.value);Ls(f,(u,h)=>{for(const[y,v]of Object.entries(t.alias))u!==y&&!u.startsWith(`${y}/`)||(u=x(v)+u.slice(y.length));if(!h||u.length===0){a.warn(o,`Empty URL in \`${a.toString()}\``);return}if(Fe.test(u))return;if(!Ie(u))try{new URL(u);return}catch{}const b=new Set;if(a.source?.input.file&&l.has(a.source.input.file)&&b.add(S(a.source.input.file)),a.source?.start){const y=a.source.start,v=i?.originalPositionFor(y),w=v?.source&&S(v.source);w&&b.add(x(w))}b.add(S(r)),p.push({baseDirs:b,decl:a,node:h,parsed:f,url:u})})});const c=new Map;for await(const{baseDirs:a,decl:f,node:u,parsed:h,url:b}of p){let y;try{y||(y=await t.resolve(b,[...a]))}catch{}if(!y){f.warn(o,`Unresolved URL \`${b}\` in \`${f.toString()}\``);continue}const{from:v,source:w,urlQuery:m}=y;if(!(w instanceof Uint8Array)||typeof v!="string"){f.warn(o,`Incorrectly resolved URL \`${b}\` in \`${f.toString()}\``);continue}if(o.messages.push({file:v,plugin:J,type:"dependency"}),t.inline)u.type="string",u.value=Rs(v,w);else{const $=x(Os(s,v,w));let g=$;const j=se.test($);for(let O=1;c.has(g)&&c.get(g)!==v;O++)g=j?$.replace(se,`${String(O)}$1`):`${$}${String(O)}`;c.set(g,v);const R=typeof t.publicPath=="string"?t.publicPath+(/[/\\]$/.test(t.publicPath)?"":"/")+I(g):`${As}${I(g)}`;u.type="string",u.value=typeof t.publicPath=="function"?t.publicPath(u.value,R,r):R,m&&(u.value+=m),typeof t.assetDir=="string"?g=pe(t.assetDir,g):typeof t.assetDir=="function"&&(g=t.assetDir(v,g,r)),o.messages.push({plugin:J,source:w,to:g,type:"asset"})}f.value=h.toString()}},postcssPlugin:J}},"plugin");we.postcss=!0;var Bs=Object.defineProperty,Se=d((e,t)=>Bs(e,"name",{value:t,configurable:!0}),"j");const Xs=S(Re(import.meta.url));let N;const P="css",Gs=new Set([P]),Js=Se(e=>{const t=q(e);return Gs.has(t)?`_${t}`:t},"getClassNameDefault"),dr={alwaysProcess:!0,name:"postcss",async process({code:e,extracted:t,map:s}){const n=await hs(this.id,this.cwd,this.environment,this.options.config),o=[];let r=!1;typeof this.options.modules=="boolean"?r=this.options.modules:typeof this.options.modules=="object"&&(r=re(this.options.modules.include,this.id)),this.autoModules&&this.options.modules===void 0&&(r=re(this.autoModules,this.id));const i={},p=[],l={...n.options,...this.options,from:this.id,map:{annotation:!1,inline:!1,prev:D(s).relative(S(this.id)).toObject(),sourcesContent:this.sourceMap?this.sourceMap.content:!0},plugins:[],to:this.options.to??this.id};if(this.options.import&&o.push($e({debug:this.debug,extensions:this.extensions,plugins:[],root:this.cwd,warnOnEmpty:!0,...this.options.import})),this.options.url&&o.push(we({inline:!!this.inject,...this.options.url})),this.options.plugins&&o.push(...this.options.plugins),o.push(...n.plugins),r){const m=typeof this.options.modules=="object"?this.options.modules:{};o.push(...ws({failOnWrongOrder:!0,...m}),ue({extensions:this.extensions}))}o.length===0&&o.push(ee),this.debug&&o.push(Ee({ignore:["css-noop"]}));const c=await Ue(o).process(e,l);for(const m of c.messages)switch(m.type){case"asset":{this.assets.set(m.to,m.source);break}case"dependency":{this.deps.add(x(m.file));break}case"icss":{Object.assign(i,m.export);break}case"icss-dependency":{p.push(m.import);break}case"warning":{this.warn({message:m.text,plugin:m.plugin});break}}if(s=D(c.map.toJSON()).resolve(S(l.to)).toString(),!this.extract&&this.sourceMap){const m=D(s).modify($=>{$.file=void 0}).relative();this.sourceMap.transform&&m.modify(this.sourceMap.transform),s=m.toString(),c.css+=m.toCommentData()}const a=Se(m=>ot(m,I(this.id)),"saferId"),f=a("modules"),u=[`var ${P} = ${JSON.stringify(c.css)};`],h=[],b=[P];if(this.namedExports){this.dts&&h.push(`declare const ${P}: string;`);const m=typeof this.namedExports=="function"?this.namedExports:Js;for(const $ in i){const g=m($);$!==g&&this.warn(`Exported \`${$}\` as \`${g}\` in ${Ce(this.cwd,this.id)}`);const j=JSON.stringify(i[$]);u.push(`var ${g} = ${j};`),this.dts&&h.push(`declare const ${g}: ${j};`),b.push(g)}}if(this.extract&&(t={css:c.css,id:this.id,map:s}),this.inject)if(typeof this.inject=="function")u.push(this.inject(P,this.id,u),`var ${f} = ${JSON.stringify(i)};`);else{const{treeshakeable:m,...$}=typeof this.inject=="object"?this.inject:{},g=a("injector"),j=`${g}(${P},${JSON.stringify($)});`;if(N||(N=F(["./runtime/inject-css"],{baseDirs:[pe(Xs,"..","..")]}),N=`"${x(N)}"`),u.unshift(`import ${g} from ${N};`),m||u.push(`var ${f} = ${JSON.stringify(i)};`,j),m){u.push("var injected = false;");const R=`if (!injected) { injected = true; ${j} }`;if(i.inject)throw new Error("`inject` keyword is reserved when using `inject.treeshakeable` option");let O="";for(const[je,Oe]of Object.entries(i)){const Pe=JSON.stringify(je),xe=JSON.stringify(Oe);O+=`get ${Pe}() { ${R} return ${xe}; }, `}O+=`inject: function inject() { ${R} },`,u.push(`var ${f} = {${O}};`)}}!this.inject&&Object.keys(i).length>0&&u.push(`var ${f} = ${JSON.stringify(i)};`);const y=` export default ${r?f:P}; `;if(u.push(y),this.dts&&(r&&h.push(` interface ModulesExports { ${Object.keys(i).map(m=>` '${m}': string;`).join(` `)} } `,typeof this.inject=="object"&&this.inject.treeshakeable?"interface ModulesExports {inject:()=>void}":"",`declare const ${f}: ModulesExports;`),h.push(y)),this.namedExports){const m=`export { ${b.filter(Boolean).join(`, `)} };`;u.push(m),this.dts&&h.push(m)}const v=u.filter(Boolean).join(` `),w=h.length>0?h.filter(Boolean).join(` `):void 0;return this.emit?{code:c.css,map:s,meta:{icssDependencies:p,moduleContents:v,types:w}}:{code:v,extracted:t,map:s,meta:{types:w},moduleSideEffects:r||typeof this.inject=="object"&&this.inject.treeshakeable?!1:"no-treeshake"}}};export{dr as default};