@salty-css/webpack 0.0.1-alpha.256 → 0.0.1-alpha.258
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index-Cpurtg_y.js +706 -0
- package/index-DBDB_Jqo.cjs +46 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/loader.cjs +1 -1
- package/loader.js +1 -1
- package/package.json +2 -2
- package/index-28QHhcA7.cjs +0 -46
- package/index-CeHiGByG.js +0 -688
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";var Vt=Object.defineProperty;var Mt=(e,t,s)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var et=(e,t,s)=>Mt(e,typeof t!="symbol"?t+"":t,s);const zt=require("esbuild"),Rt=require("child_process"),c=require("path"),p=require("fs"),bt=require("fs/promises"),Z=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Wt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const jt=Wt(zt),$t=e=>String.fromCharCode(e+(e>25?39:97)),Jt=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},At=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},I=(e,t=5)=>{const s=At(5381,JSON.stringify(e))>>>0;return Jt(s,t)};function z(e){return e?typeof e!="string"?z(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const It=e=>t=>{if(typeof t!="string"||!e)return;let s=t;const n=[];return Object.values(e).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,d=>{const{value:g,css:y}=i(d);return y&&n.push(y),g})}),{transformed:s,additionalCss:n}},Ft=e=>t=>typeof t!="string"||!/\{[^{}]+\}/g.test(t)?void 0:{transformed:t.replace(/\{([^{}]+)\}/g,(...o)=>{const r=z(o[1].replaceAll(".","-"));return r.startsWith("-")?`-${r}`:`var(--${r})`})},qt=Ft(),Gt=e=>t=>{const{screenSize:s,axis:n="horizontal",minMultiplier:o=.5,maxMultiplier:r=1.5}=e,i=Math.round(t/s*1e4)/100,d=n==="vertical"?"vh":"vw",g=Math.round(o*t),y=Math.round(r*t);return`clamp(${g}px, ${i}${d}, ${y}px)`},Ht=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(e,t,s)=>{if(Ht.some(o=>typeof o=="string"?o===e:o.test(e))){const o="px";if(o.startsWith("viewport-clamp:"))try{const i=o.split(":")[1];return Gt({screenSize:parseInt(i)})(Number(t))}catch(i){throw console.error(i),new Error(`Invalid viewport-clamp value: ${o}`)}return`${t}${o}`}return`${t}`},Qt=["Webkit","Moz","ms","O"],Kt=e=>e.startsWith("-")?e:Qt.some(t=>e.startsWith(t))?`-${z(e)}`:z(e),st=async(e,t="",s,n=!1)=>{if(!e)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(e),i=async([m,u])=>{const $=m.trim().replace(/^\?+/g,""),P=Kt($),v=(k,W=";")=>`${P}:${k}${W}`,O={scope:t,config:s};if(typeof u=="function")return i([m,u(O)]);if(u instanceof Promise)return i([m,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return v(u.toString());if($==="defaultVariants")return;if($==="variants"){const N=Object.entries(u);for(const[V,f]of N){if(!f)continue;const S=Object.entries(f);for(const[F,a]of S){if(!a)continue;const C=`${t}.${V}-${F}`;(await st(a,C,s)).forEach(M=>o.add(M))}}return}if($==="compoundVariants"){for(const N of u){const{css:V,...f}=N,S=Object.entries(f).reduce((a,[C,x])=>`${a}.${C}-${x}`,t);(await st(V,S,s)).forEach(a=>o.add(a))}return}if($.startsWith("@")){const N=$,V=await X(u,t,s),f=`${N} { ${V} }`;o.add(f);return}const k=m.includes("&")?$.replaceAll("&",t):$.startsWith(":")?`${t}${$}`:`${t} ${$}`;(await st(u,k,s)).forEach(N=>o.add(N));return}if(typeof u=="number"){const k=Lt(P,u);return v(k)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return v(u)},d=r.map(i),{modifiers:g}={},y=[Ft(),It(g)],w=(await Promise.all(d).then(m=>Promise.all(m.map(u=>y.reduce(async($,P)=>{const v=await $;if(!v)return v;const O=await P(v);if(!O)return v;const{transformed:k,additionalCss:W}=O;let N="";if(W)for(const V of W)N+=await X(V,"");return`${N}${k}`},Promise.resolve(u)))))).filter(m=>m!==void 0).join(`
|
2
|
+
`);if(!w.trim())return Array.from(o);const h=t?`${t} {
|
3
|
+
${w}
|
4
|
+
}`:w;return o.has(h)?Array.from(o):[h,...o]},X=async(e,t,s,n=!1)=>(await st(e,t,s,n)).join(`
|
5
|
+
`),Ct=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,r]of Object.entries(e))if(typeof r!="function")if(r&&typeof r=="object"){const i=o.trim(),d=await Ct(r,[...t,i]);s.push(d)}else n[o]=r;if(Object.keys(n).length){const o=t.map(z).join("-"),r="t_"+I(o,4),i=await X(n,`.${o}, .${r}`);s.push(i)}return s.join(`
|
6
|
+
`)},Ut=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},Pt=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?Pt(o,r,s):s.add(t)}),[...s]):[],Nt=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=c.join(e,"package.json");return p.existsSync(t)?t:Nt(c.join(e,".."))},Bt=async e=>{const t=Nt(e);return await bt.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Zt=async e=>{const t=await Bt(e);if(t)return t.type};let G;const xt=async e=>{if(G)return G;const t=await Zt(e);return t==="module"?G="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index-DBDB_Jqo.cjs",document.baseURI).href).endsWith(".cjs"))&&(G="cjs"),G||"esm"},pt=Z.createLogger({level:"debug",format:Z.format.combine(Z.format.colorize(),Z.format.cli()),transports:[new Z.transports.Console({})]});function _t(e){return e?typeof e!="string"?_t(String(e)):e.replace(/[^\d\w]/g,"."):""}const Xt={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},H=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),Yt=(...e)=>e.flat().reduce((t,s)=>({...t,...s._children}),{});class te{constructor(t){et(this,"_path");this.params=t}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(t){return this._path=t,this}}class ee{constructor(t){et(this,"_path");et(this,"templates",[]);this.params=t,Object.entries(t).forEach(([s,n])=>{this.templates.push(new te({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(t=>[t.params.name,t]))}get isDefineTemplates(){return!0}_setPath(t){return this._path=t,this.templates.forEach(s=>s._setPath(t)),this}}const se=e=>new ee(e),ne=(e,t)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=ft.createSourceFile("temp.ts",e,ft.ScriptTarget.Latest,!0);function i(d){if(ft.isVariableDeclaration(d)&&d.name.getText()===t){const g=d.getStart(),y=d.getEnd();clearTimeout(o),s([g,y])}d.forEachChild(i)}i(r)}),R={externalModules:[],rcFile:void 0,destDir:void 0},vt=e=>{if(R.externalModules.length>0)return R.externalModules;const s=p.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return R.externalModules=n,n},q=async e=>{if(R.destDir)return R.destDir;const t=await mt(e),s=c.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},Tt=["salty","css","styles","styled"],kt=(e=[])=>new RegExp(`\\.(${[...Tt,...e].join("|")})\\.`),nt=(e,t=[])=>kt(t).test(e),Dt=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=c.join(e,".saltyrc.json"),s=await bt.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):Dt(c.join(e,".."))},mt=async e=>{var n,o;const t=await Dt(e),s=(n=t.projects)==null?void 0:n.find(r=>e.endsWith(r.dir||""));return s||((o=t.projects)==null?void 0:o.find(r=>r.dir===t.defaultProject))},oe=async e=>{const t=await mt(e),s=await q(e),n=c.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await xt(e),i=vt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const d=Date.now(),{config:g}=await import(`${o}?t=${d}`);return{config:g,path:o}},ie=async(e,t)=>{var ht,gt;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async j=>{const{contents:_,outputFilePath:U}=await ot(e,j,s);Object.entries(_).forEach(([D,T])=>{T.isMedia?n.mediaQueries.push([D,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${D};;${U}`))})}));const{config:o,path:r}=await oe(e),i={...o},{mediaQueries:d}=n;i.mediaQueries=Object.fromEntries(d.map(([j,_])=>[`@${j}`,_]));const g=d.map(([j])=>`'@${j}'`).join(" | "),y=new Set,l=async(j,_=[])=>{if(!j)return[];const U=Object.entries(j).map(async([T,A])=>{const B=async E=>{if(!E)return;if(E instanceof Promise)return await B(await E);if(typeof E=="function")return await B(await E());if(typeof E=="object")return await l(E,[..._,T]);const at=_t(T),ct=z(T),lt=[..._,at].join(".");y.add(`"${lt}"`);const tt=[..._.map(z),ct].join("-"),wt=qt(E);return wt?`--${tt}: ${wt.transformed};`:`--${tt}: ${E};`};return await B(A)});return(await Promise.all(U)).flat()},w=async j=>{if(!j)return[];const _=Object.entries(j).map(async([D,T])=>{const A=await l(T);return D==="base"?A.join(""):i.mediaQueries[D]?`${i.mediaQueries[D]} { ${A.join("")} }`:`${D} { ${A.join("")} }`});return(await Promise.all(_)).flat()},h=async j=>{if(!j)return[];const _=Object.entries(j).map(async([D,T])=>{const A=Object.entries(T).map(async([E,at])=>{const ct=await l(at,[D]),lt=`.${D}-${E}, [data-${D}="${E}"]`,tt=ct.join("");return`${lt} { ${tt} }`});return(await Promise.all(A)).flat()});return(await Promise.all(_)).flat()},b=j=>({...j,responsive:void 0,conditional:void 0}),m=j=>n.variables.map(_=>j==="static"?b(_._current):_._current[j]),u=H(b(o.variables),m("static")),$=await l(u),P=H((ht=o.variables)==null?void 0:ht.responsive,m("responsive")),v=await w(P),O=H((gt=o.variables)==null?void 0:gt.conditional,m("conditional")),k=await h(O),W=c.join(s,"css/_variables.css"),N=`:root { ${$.join("")} ${v.join("")} } ${k.join("")}`;p.writeFileSync(W,N),i.staticVariables=u;const V=c.join(s,"css/_global.css"),f=H(o.global,n.globalStyles),S=await X(f,"");p.writeFileSync(V,`@layer global { ${S} }`);const F=c.join(s,"css/_reset.css"),C=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Xt,x=await X(C,"");p.writeFileSync(F,`@layer reset { ${x} }`);const M=c.join(s,"css/_templates.css"),J=H(o.templates,n.templates),L=await Ct(J),Q=Ut(J);p.writeFileSync(M,`@layer templates { ${L} }`),i.templates=J;const Y=o.templates?[se(o.templates)._setPath(`config;;${r}`)]:[],it=Yt(n.templates,Y);i.templatePaths=Object.fromEntries(Object.entries(it).map(([j,_])=>[j,_._path]));const K=c.join(s,"types/css-tokens.d.ts"),Et=`
|
7
|
+
// Variable types
|
8
|
+
type VariableTokens = ${[...y].join("|")};
|
9
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
10
|
+
|
11
|
+
// Template types
|
12
|
+
type TemplateTokens = {
|
13
|
+
${Object.entries(Q).map(([j,_])=>`${j}?: ${_}`).join(`
|
14
|
+
`)}
|
15
|
+
}
|
16
|
+
|
17
|
+
// Media query types
|
18
|
+
type MediaQueryKeys = ${g||"''"};
|
19
|
+
`;p.writeFileSync(K,Et);const Ot=c.join(s,"cache/config-cache.json");p.writeFileSync(Ot,JSON.stringify(i,null,2))},St=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const i=o.exec(e);if(i){const d=i.at(1);if(Tt.some(y=>d==null?void 0:d.includes(y)))return t}return"styled('div',"}),re=(e,t)=>{try{const s=p.readFileSync(c.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
+
|
21
|
+
${e}`:`globalThis.saltyConfig = {};
|
22
|
+
|
23
|
+
${e}`}catch{return e}},ot=async(e,t,s)=>{const n=I(t),o=c.join(s,"./temp");p.existsSync(o)||p.mkdirSync(o);const r=c.parse(t);let i=p.readFileSync(t,"utf8");i=St(i),i=re(i,e);const d=c.join(s,"js",n+".js"),g=await mt(e),y=c.join(e,(g==null?void 0:g.configDir)||"","salty.config.ts"),l=vt(y),w=await xt(e);await jt.build({stdin:{contents:i,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:w,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:m=>{m.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const $=p.readFileSync(u.path,"utf8");return{contents:St($),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${d}?t=${h}`),outputFilePath:d}},ae=async e=>{const t=await q(e),s=c.join(t,"cache/config-cache.json"),n=p.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},dt=async e=>{const t=await ae(e),s=await q(e),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return H(r,t)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ce=async(e,t=yt(),s=!0)=>{try{const n=Date.now();t?pt.info("Generating CSS in production mode! 🔥"):pt.info("Generating CSS in development mode! 🚀");const o=[],r=[],i=await q(e),d=c.join(i,"index.css");s&&(()=>{p.existsSync(i)&&Rt.execSync("rm -rf "+i),p.mkdirSync(i,{recursive:!0}),p.mkdirSync(c.join(i,"css")),p.mkdirSync(c.join(i,"types")),p.mkdirSync(c.join(i,"js")),p.mkdirSync(c.join(i,"cache"))})();const y=new Set,l=new Set;async function w(f){const S=["node_modules","saltygen"],F=p.statSync(f);if(F.isDirectory()){const a=p.readdirSync(f);if(S.some(x=>f.includes(x)))return;await Promise.all(a.map(x=>w(c.join(f,x))))}else if(F.isFile()&&nt(f)){y.add(f);const C=p.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await w(e),await ie(e,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...y].map(async f=>{const{contents:S}=await ot(e,f,i);for(let[F,a]of Object.entries(S))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const b=await dt(e);for(const f of h.keyframes){const{value:S}=f,F=`a_${S.animationName}.css`,a=`css/${F}`,C=c.join(i,a);o.push(F),p.writeFileSync(C,S.css)}const m={};for(const f of h.components){const{src:S,name:F}=f;m[S]||(m[S]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:t,config:b});r[a.priority]||(r[a.priority]=[]);const C=await a.css;if(!C)continue;r[a.priority].push(a.cssFileName);const x=`css/${a.cssFileName}`,M=c.join(i,x);p.writeFileSync(M,C),b.importStrategy==="component"&&m[S].push(a.cssFileName)}for(const f of h.classNames){const{src:S,name:F}=f;m[S]||(m[S]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:t,config:b}),C=await a.css;if(!C)continue;r[a.priority]||(r[a.priority]=[]),r[a.priority].push(a.cssFileName);const x=`css/${a.cssFileName}`,M=c.join(i,x);p.writeFileSync(M,C),b.importStrategy==="component"&&m[S].push(a.cssFileName)}b.importStrategy==="component"&&Object.entries(m).forEach(([f,S])=>{const F=S.map(J=>`@import url('./${J}');`).join(`
|
24
|
+
`),a=I(f,6),C=c.parse(f),x=z(C.name),M=c.join(i,`css/f_${x}-${a}.css`);p.writeFileSync(M,F||"/* Empty file */")});const u=o.map(f=>`@import url('./css/${f}');`).join(`
|
25
|
+
`);let k=`/*!
|
26
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
27
|
+
* Do not edit this file directly
|
28
|
+
*/
|
29
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
30
|
+
|
31
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return p.readFileSync(c.join(i,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
32
|
+
`)}
|
33
|
+
${u}`;if(b.importStrategy!=="component"){const f=r.reduce((S,F,a)=>{const C=F.reduce((L,Q)=>{var rt;const Y=c.join(i,"css",Q),it=p.readFileSync(Y,"utf8"),K=((rt=/.*-([^-]+)-\d+.css/.exec(Q))==null?void 0:rt.at(1))||I(Y,6);return L.includes(K)?L:`${L}
|
34
|
+
/*start:${K}-${Q}*/
|
35
|
+
${it}
|
36
|
+
/*end:${K}*/
|
37
|
+
`},""),x=`l_${a}.css`,M=c.join(i,"css",x),J=`@layer l${a} { ${C}
|
38
|
+
}`;return p.writeFileSync(M,J),`${S}
|
39
|
+
@import url('./css/${x}');`},"");k+=f}p.writeFileSync(d,k);const N=Date.now()-n,V=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";pt.info(`Generated CSS in ${N}ms! ${V}`)}catch(n){console.error(n)}},le=async(e,t,s=yt())=>{try{const n=await q(e);if(nt(t)){const r=[],i=await dt(e),{contents:d}=await ot(e,t,n);for(const[g,y]of Object.entries(d)){if(y.isKeyframes&&y.css){const u=`css/${`a_${y.animationName}.css`}`,$=c.join(n,u);p.writeFileSync($,await y.css);continue}if(y.isClassName){const m=y.generator._withBuildContext({callerName:g,isProduction:s,config:i}),u=await m.css;if(!u)continue;r[m.priority]||(r[m.priority]=[]),r[m.priority].push(m.cssFileName);const $=`css/${m.cssFileName}`,P=c.join(n,$);p.writeFileSync(P,u);continue}if(!y.generator)continue;const l=y.generator._withBuildContext({callerName:g,isProduction:s,config:i}),w=await l.css;if(!w)continue;const h=`css/${l.cssFileName}`,b=c.join(n,h);p.writeFileSync(b,w),r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName)}if(i.importStrategy!=="component")r.forEach((g,y)=>{const l=`l_${y}.css`,w=c.join(n,"css",l);let h=p.readFileSync(w,"utf8");g.forEach(b=>{var P;const m=c.join(n,"css",b),u=((P=/.*-([^-]+)-\d+.css/.exec(b))==null?void 0:P.at(1))||I(m,6);if(!h.includes(u)){const v=p.readFileSync(m,"utf8"),O=`/*start:${u}-${b}*/
|
40
|
+
${v}
|
41
|
+
/*end:${u}*/
|
42
|
+
`;h=`${h.replace(/\}$/,"")}
|
43
|
+
${O}
|
44
|
+
}`}}),p.writeFileSync(w,h)});else{const g=r.flat().map(b=>`@import url('./${b}');`).join(`
|
45
|
+
`),y=I(t,6),l=c.parse(t),w=z(l.name),h=c.join(n,`css/f_${w}-${y}.css`);p.writeFileSync(h,g||"/* Empty file */")}}}catch(n){console.error(n)}},fe=async(e,t,s=yt())=>{var n,o;try{const r=await q(e);if(nt(t)){const d=p.readFileSync(t,"utf8"),g=await dt(e),{contents:y}=await ot(e,t,r);let l=d;for(const[w,h]of Object.entries(y)){if(h.isKeyframes||!h.generator)continue;const b=h.generator._withBuildContext({callerName:w,isProduction:s,config:g}),[m,u]=await ne(l,w),$=l.slice(m,u);if(h.isClassName){const P=l,v=` ${w} = className("${b.classNames}")`;l=l.replace($,v),P===l&&console.error("Minimize file failed to change content",{name:w})}if($.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec($))==null?void 0:n.at(1))==null?void 0:o.trim(),v=l,O=` ${w} = styled(${P}, "${b.classNames}", ${JSON.stringify(b.clientProps)})`;l=l.replace($,O),v===l&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(g.importStrategy==="component"){const w=I(t,6),h=c.parse(t);l=`import '../../saltygen/css/${`f_${z(h.name)}-${w}.css`}';
|
46
|
+
${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}};exports.generateCss=ce;exports.generateFile=le;exports.isSaltyFile=nt;exports.minimizeFile=fe;exports.saltyFileRegExp=kt;
|
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-DBDB_Jqo.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const r=await y.readFile(e,"utf-8");return!!(/.+define[A-Z]\w+/.test(r)||/.+keyframes\(.+/.test(r))},c=(e,s,l=!1,r=!1)=>{var i,n,u;(n=(i=e.module)==null?void 0:i.rules)==null||n.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,r?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(u=e.plugins)==null||u.push({apply:f=>{let o=!1;f.hooks.beforeCompile.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,a)=>{await p(a)?await t.generateCss(s,!1,!1):t.isSaltyFile(a)&&await t.generateFile(s,a)}))})}})};exports.default=c;exports.saltyPlugin=c;
|
package/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { resolve as p } from "path";
|
2
|
-
import { i as f, s as y, g as u, a as d } from "./index-
|
2
|
+
import { i as f, s as y, g as u, a as d } from "./index-Cpurtg_y.js";
|
3
3
|
import { readFile as g } from "fs/promises";
|
4
4
|
import { watch as m } from "fs";
|
5
5
|
const w = async (e) => {
|
package/loader.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const i=require("./index-
|
1
|
+
"use strict";const i=require("./index-DBDB_Jqo.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
|
package/loader.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/webpack",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.258",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.258",
|
38
38
|
"webpack": ">=5.x"
|
39
39
|
}
|
40
40
|
}
|
package/index-28QHhcA7.cjs
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";var Vt=Object.defineProperty;var Mt=(t,e,s)=>e in t?Vt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var et=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);const Rt=require("esbuild"),zt=require("child_process"),c=require("path"),p=require("fs"),St=require("fs/promises"),Z=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(Rt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function R(t){return t?typeof t!="string"?R(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:i,transform:r}=o;s=s.replace(i,y=>{const{value:$,css:m}=r(y);return m&&n.push(m),$})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>{const i=R(o[1].replaceAll(".","-"));return i.startsWith("-")?`-${i}`:`var(--${i})`})},It=Ft(),Gt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Ht=(t,e,s)=>Gt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Lt=["Webkit","Moz","ms","O"],Qt=t=>t.startsWith("-")?t:Lt.some(e=>t.startsWith(e))?`-${R(t)}`:R(t),st=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,i=Object.entries(t),r=async([d,u])=>{const w=d.trim().replace(/^\?+/g,""),P=Qt(w),T=(D,J=";")=>`${P}:${D}${J}`,O={scope:e,config:s};if(typeof u=="function")return r([d,u(O)]);if(u instanceof Promise)return r([d,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return T(u.toString());if(w==="defaultVariants")return;if(w==="variants"){const N=Object.entries(u);for(const[V,f]of N){if(!f)continue;const b=Object.entries(f);for(const[F,a]of b){if(!a)continue;const C=`${e}.${V}-${F}`;(await st(a,C,s)).forEach(M=>o.add(M))}}return}if(w==="compoundVariants"){for(const N of u){const{css:V,...f}=N,b=Object.entries(f).reduce((a,[C,_])=>`${a}.${C}-${_}`,e);(await st(V,b,s)).forEach(a=>o.add(a))}return}if(w.startsWith("@")){const N=w,V=await X(u,e,s),f=`${N} { ${V} }`;o.add(f);return}const D=d.includes("&")?w.replaceAll("&",e):w.startsWith(":")?`${e}${w}`:`${e} ${w}`;(await st(u,D,s)).forEach(N=>o.add(N));return}if(typeof u=="number"){const D=Ht(P,u);return T(D)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return T(u)},y=i.map(r),{modifiers:$}={},m=[Ft(),qt($)],g=(await Promise.all(y).then(d=>Promise.all(d.map(u=>m.reduce(async(w,P)=>{const T=await w;if(!T)return T;const O=await P(T);if(!O)return T;const{transformed:D,additionalCss:J}=O;let N="";if(J)for(const V of J)N+=await X(V,"");return`${N}${D}`},Promise.resolve(u)))))).filter(d=>d!==void 0).join(`
|
2
|
-
`);if(!g.trim())return Array.from(o);const h=e?`${e} {
|
3
|
-
${g}
|
4
|
-
}`:g;return o.has(h)?Array.from(o):[h,...o]},X=async(t,e,s,n=!1)=>(await st(t,e,s,n)).join(`
|
5
|
-
`),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,i]of Object.entries(t))if(typeof i!="function")if(i&&typeof i=="object"){const r=o.trim(),y=await Ct(i,[...e,r]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(R).join("-"),i="t_"+q(o,4),r=await X(n,`.${o}, .${i}`);s.push(r)}return s.join(`
|
6
|
-
`)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,i,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return p.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Bt=async t=>{const e=await Ut(t);if(e)return e.type};let G;const _t=async t=>{if(G)return G;const e=await Bt(t);return e==="module"?G="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index-28QHhcA7.cjs",document.baseURI).href).endsWith(".cjs"))&&(G="cjs"),G||"esm"},pt=Z.createLogger({level:"debug",format:Z.format.combine(Z.format.colorize(),Z.format.cli()),transports:[new Z.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Zt={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},H=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){et(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){et(this,"_path");et(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),i=ft.createSourceFile("temp.ts",t,ft.ScriptTarget.Latest,!0);function r(y){if(ft.isVariableDeclaration(y)&&y.name.getText()===e){const $=y.getStart(),m=y.getEnd();clearTimeout(o),s([$,m])}y.forEachChild(r)}r(i)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=p.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await dt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],Dt=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),nt=(t,e=[])=>Dt(e).test(t),vt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):vt(c.join(t,".."))},dt=async t=>{var n,o;const e=await vt(t),s=(n=e.projects)==null?void 0:n.find(i=>t.endsWith(i.dir||""));return s||((o=e.projects)==null?void 0:o.find(i=>i.dir===e.defaultProject))},ne=async t=>{const e=await dt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await _t(t),r=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:r});const y=Date.now(),{config:$}=await import(`${o}?t=${y}`);return{config:$,path:o}},oe=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:x,outputFilePath:U}=await ot(t,j,s);Object.entries(x).forEach(([v,k])=>{k.isMedia?n.mediaQueries.push([v,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${v};;${U}`))})}));const{config:o,path:i}=await ne(t),r={...o},{mediaQueries:y}=n;r.mediaQueries=Object.fromEntries(y.map(([j,x])=>[`@${j}`,x]));const $=y.map(([j])=>`'@${j}'`).join(" | "),m=new Set,l=async(j,x=[])=>{if(!j)return[];const U=Object.entries(j).map(async([k,A])=>{const B=async E=>{if(!E)return;if(E instanceof Promise)return await B(await E);if(typeof E=="function")return await B(await E());if(typeof E=="object")return await l(E,[...x,k]);const at=xt(k),ct=R(k),lt=[...x,at].join(".");m.add(`"${lt}"`);const tt=[...x.map(R),ct].join("-"),wt=It(E);return wt?`--${tt}: ${wt.transformed};`:`--${tt}: ${E};`};return await B(A)});return(await Promise.all(U)).flat()},g=async j=>{if(!j)return[];const x=Object.entries(j).map(async([v,k])=>{const A=await l(k);return v==="base"?A.join(""):r.mediaQueries[v]?`${r.mediaQueries[v]} { ${A.join("")} }`:`${v} { ${A.join("")} }`});return(await Promise.all(x)).flat()},h=async j=>{if(!j)return[];const x=Object.entries(j).map(async([v,k])=>{const A=Object.entries(k).map(async([E,at])=>{const ct=await l(at,[v]),lt=`.${v}-${E}, [data-${v}="${E}"]`,tt=ct.join("");return`${lt} { ${tt} }`});return(await Promise.all(A)).flat()});return(await Promise.all(x)).flat()},S=j=>({...j,responsive:void 0,conditional:void 0}),d=j=>n.variables.map(x=>j==="static"?S(x._current):x._current[j]),u=H(S(o.variables),d("static")),w=await l(u),P=H((ht=o.variables)==null?void 0:ht.responsive,d("responsive")),T=await g(P),O=H((gt=o.variables)==null?void 0:gt.conditional,d("conditional")),D=await h(O),J=c.join(s,"css/_variables.css"),N=`:root { ${w.join("")} ${T.join("")} } ${D.join("")}`;p.writeFileSync(J,N),r.staticVariables=u;const V=c.join(s,"css/_global.css"),f=H(o.global,n.globalStyles),b=await X(f,"");p.writeFileSync(V,`@layer global { ${b} }`);const F=c.join(s,"css/_reset.css"),C=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Zt,_=await X(C,"");p.writeFileSync(F,`@layer reset { ${_} }`);const M=c.join(s,"css/_templates.css"),W=H(o.templates,n.templates),L=await Ct(W),Q=Kt(W);p.writeFileSync(M,`@layer templates { ${L} }`),r.templates=W;const Y=o.templates?[ee(o.templates)._setPath(`config;;${i}`)]:[],it=Xt(n.templates,Y);r.templatePaths=Object.fromEntries(Object.entries(it).map(([j,x])=>[j,x._path]));const K=c.join(s,"types/css-tokens.d.ts"),Et=`
|
7
|
-
// Variable types
|
8
|
-
type VariableTokens = ${[...m].join("|")};
|
9
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
10
|
-
|
11
|
-
// Template types
|
12
|
-
type TemplateTokens = {
|
13
|
-
${Object.entries(Q).map(([j,x])=>`${j}?: ${x}`).join(`
|
14
|
-
`)}
|
15
|
-
}
|
16
|
-
|
17
|
-
// Media query types
|
18
|
-
type MediaQueryKeys = ${$||"''"};
|
19
|
-
`;p.writeFileSync(K,Et);const Ot=c.join(s,"cache/config-cache.json");p.writeFileSync(Ot,JSON.stringify(r,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const r=o.exec(t);if(r){const y=r.at(1);if(kt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),ie=(t,e)=>{try{const s=p.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
-
|
21
|
-
${t}`:`globalThis.saltyConfig = {};
|
22
|
-
|
23
|
-
${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");p.existsSync(o)||p.mkdirSync(o);const i=c.parse(e);let r=p.readFileSync(e,"utf8");r=bt(r),r=ie(r,t);const y=c.join(s,"js",n+".js"),$=await dt(t),m=c.join(t,($==null?void 0:$.configDir)||"","salty.config.ts"),l=Tt(m),g=await _t(t);await jt.build({stdin:{contents:r,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const w=p.readFileSync(u.path,"utf8");return{contents:bt(w),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},re=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=p.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await re(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return H(i,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?pt.info("Generating CSS in production mode! 🔥"):pt.info("Generating CSS in development mode! 🚀");const o=[],i=[],r=await I(t),y=c.join(r,"index.css");s&&(()=>{p.existsSync(r)&&zt.execSync("rm -rf "+r),p.mkdirSync(r,{recursive:!0}),p.mkdirSync(c.join(r,"css")),p.mkdirSync(c.join(r,"types")),p.mkdirSync(c.join(r,"js")),p.mkdirSync(c.join(r,"cache"))})();const m=new Set,l=new Set;async function g(f){const b=["node_modules","saltygen"],F=p.statSync(f);if(F.isDirectory()){const a=p.readdirSync(f);if(b.some(_=>f.includes(_)))return;await Promise.all(a.map(_=>g(c.join(f,_))))}else if(F.isFile()&&nt(f)){m.add(f);const C=p.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await g(t),await oe(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:b}=await ot(t,f,r);for(let[F,a]of Object.entries(b))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const S=await mt(t);for(const f of h.keyframes){const{value:b}=f,F=`a_${b.animationName}.css`,a=`css/${F}`,C=c.join(r,a);o.push(F),p.writeFileSync(C,b.css)}const d={};for(const f of h.components){const{src:b,name:F}=f;d[b]||(d[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S});i[a.priority]||(i[a.priority]=[]);const C=await a.css;if(!C)continue;i[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,M=c.join(r,_);p.writeFileSync(M,C),S.importStrategy==="component"&&d[b].push(a.cssFileName)}for(const f of h.classNames){const{src:b,name:F}=f;d[b]||(d[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S}),C=await a.css;if(!C)continue;i[a.priority]||(i[a.priority]=[]),i[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,M=c.join(r,_);p.writeFileSync(M,C),S.importStrategy==="component"&&d[b].push(a.cssFileName)}S.importStrategy==="component"&&Object.entries(d).forEach(([f,b])=>{const F=b.map(W=>`@import url('./${W}');`).join(`
|
24
|
-
`),a=q(f,6),C=c.parse(f),_=R(C.name),M=c.join(r,`css/f_${_}-${a}.css`);p.writeFileSync(M,F||"/* Empty file */")});const u=o.map(f=>`@import url('./css/${f}');`).join(`
|
25
|
-
`);let D=`/*!
|
26
|
-
* Generated with Salty CSS (https://salty-css.dev)
|
27
|
-
* Do not edit this file directly
|
28
|
-
*/
|
29
|
-
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
30
|
-
|
31
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return p.readFileSync(c.join(r,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
32
|
-
`)}
|
33
|
-
${u}`;if(S.importStrategy!=="component"){const f=i.reduce((b,F,a)=>{const C=F.reduce((L,Q)=>{var rt;const Y=c.join(r,"css",Q),it=p.readFileSync(Y,"utf8"),K=((rt=/.*-([^-]+)-\d+.css/.exec(Q))==null?void 0:rt.at(1))||q(Y,6);return L.includes(K)?L:`${L}
|
34
|
-
/*start:${K}-${Q}*/
|
35
|
-
${it}
|
36
|
-
/*end:${K}*/
|
37
|
-
`},""),_=`l_${a}.css`,M=c.join(r,"css",_),W=`@layer l${a} { ${C}
|
38
|
-
}`;return p.writeFileSync(M,W),`${b}
|
39
|
-
@import url('./css/${_}');`},"");D+=f}p.writeFileSync(y,D);const N=Date.now()-n,V=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";pt.info(`Generated CSS in ${N}ms! ${V}`)}catch(n){console.error(n)}},ce=async(t,e,s=yt())=>{try{const n=await I(t);if(nt(e)){const i=[],r=await mt(t),{contents:y}=await ot(t,e,n);for(const[$,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,w=c.join(n,u);p.writeFileSync(w,await m.css);continue}if(m.isClassName){const d=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),u=await d.css;if(!u)continue;i[d.priority]||(i[d.priority]=[]),i[d.priority].push(d.cssFileName);const w=`css/${d.cssFileName}`,P=c.join(n,w);p.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:$,isProduction:s,config:r}),g=await l.css;if(!g)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);p.writeFileSync(S,g),i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName)}if(r.importStrategy!=="component")i.forEach(($,m)=>{const l=`l_${m}.css`,g=c.join(n,"css",l);let h=p.readFileSync(g,"utf8");$.forEach(S=>{var P;const d=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(d,6);if(!h.includes(u)){const T=p.readFileSync(d,"utf8"),O=`/*start:${u}-${S}*/
|
40
|
-
${T}
|
41
|
-
/*end:${u}*/
|
42
|
-
`;h=`${h.replace(/\}$/,"")}
|
43
|
-
${O}
|
44
|
-
}`}}),p.writeFileSync(g,h)});else{const $=i.flat().map(S=>`@import url('./${S}');`).join(`
|
45
|
-
`),m=q(e,6),l=c.parse(e),g=R(l.name),h=c.join(n,`css/f_${g}-${m}.css`);p.writeFileSync(h,$||"/* Empty file */")}}}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{var n,o;try{const i=await I(t);if(nt(e)){const y=p.readFileSync(e,"utf8"),$=await mt(t),{contents:m}=await ot(t,e,i);let l=y;for(const[g,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:g,isProduction:s,config:$}),[d,u]=await se(l,g),w=l.slice(d,u);if(h.isClassName){const P=l,T=` ${g} = className("${S.classNames}")`;l=l.replace(w,T),P===l&&console.error("Minimize file failed to change content",{name:g})}if(w.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec(w))==null?void 0:n.at(1))==null?void 0:o.trim(),T=l,O=` ${g} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace(w,O),T===l&&console.error("Minimize file failed to change content",{name:g,tagName:P})}}if($.importStrategy==="component"){const g=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${R(h.name)}-${g}.css`}';
|
46
|
-
${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(i){console.error("Error in minimizeFile:",i)}};exports.generateCss=ae;exports.generateFile=ce;exports.isSaltyFile=nt;exports.minimizeFile=le;exports.saltyFileRegExp=Dt;
|