@salty-css/webpack 0.0.1-alpha.205 → 0.0.1-alpha.207

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.
@@ -0,0 +1,40 @@
1
+ "use strict";const xe=require("esbuild"),ke=require("child_process"),a=require("path"),d=require("fs"),re=require("fs/promises"),L=require("winston");var oe=typeof document<"u"?document.currentScript:null;function _e(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 ye=_e(xe),pe=e=>String.fromCharCode(e+(e>25?39:97)),De=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=pe(n%52)+s;return s=pe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Oe=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},W=(e,t=5)=>{const s=Oe(5381,JSON.stringify(e))>>>0;return De(s,t)};function M(e){return e?typeof e!="string"?M(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 Te=e=>t=>{if(typeof t!="string"||!e)return;let s=t;const n=[];return Object.values(e).forEach(o=>{const{pattern:i,transform:c}=o;s=s.replace(i,h=>{const{value:F,css:l}=c(h);return l&&n.push(l),F})}),{transformed:s,additionalCss:n}},ge=e=>t=>typeof t!="string"||!/\{[^{}]+\}/g.test(t)?void 0:{transformed:t.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},Ee=ge(),Ve=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Me=(e,t,s)=>Ve.some(o=>typeof o=="string"?o===e:o.test(e))?`${t}px`:`${t}`,Re=["Webkit","Moz","ms","O"],ze=e=>e.startsWith("-")?e:Re.some(t=>e.startsWith(t))?`-${M(e)}`:M(e),X=async(e,t="",s,n=!1)=>{if(!e)throw new Error("No styles provided to parseStyles function!");const o=new Set,c=Object.entries(e).map(async([y,r])=>{const p=y.trim(),b=ze(p),C=(O,_=";")=>`${b}:${O}${_}`;if(typeof r=="function"&&(r=r({scope:t,config:s})),r instanceof Promise&&(r=await r),typeof r=="object"){if(!r)return;if(r.isColor)return C(r.toString());if(p==="defaultVariants")return;if(p==="variants"){const D=Object.entries(r);for(const[P,E]of D){if(!E)return;const f=Object.entries(E);for(const[w,g]of f){if(!g)return;const u=`${t}.${P}-${w}`;(await X(g,u,s)).forEach(x=>o.add(x))}}return}if(p==="compoundVariants"){for(const D of r){const{css:P,...E}=D,f=Object.entries(E).reduce((g,[u,S])=>`${g}.${u}-${S}`,t);(await X(P,f,s)).forEach(g=>o.add(g))}return}if(p.startsWith("@")){const D=p,P=await B(r,t,s),E=`${D} { ${P} }`;o.add(E);return}const O=y.includes("&")?p.replace("&",t):p.startsWith(":")?`${t}${p}`:`${t} ${p}`;(await X(r,O,s)).forEach(D=>o.add(D));return}if(typeof r=="number"){const O=Me(b,r);return C(O)}if(typeof r!="string")if("toString"in r)r=r.toString();else throw new Error(`Invalid value type for property ${b}`);return C(r)}),{modifiers:h}={},F=[ge(),Te(h)],m=(await Promise.all(c).then(y=>Promise.all(y.map(r=>F.reduce(async(p,b)=>{const C=await p;if(!C)return C;const k=await b(C);if(!k)return C;const{transformed:O,additionalCss:_}=k;let D="";if(_)for(const P of _)D+=await B(P,"");return`${D}${O}`},Promise.resolve(r)))))).join(`
2
+ `);if(!m.trim())return o;const $=t?`${t} { ${m} }`:m;return o.add($),o},B=async(e,t,s,n=!1)=>[...await X(e,t,s,n)].join(`
3
+ `),he=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,i]of Object.entries(e))if(typeof i!="function")if(i&&typeof i=="object"){const c=o.trim(),h=await he(i,[...t,c]);s.push(h)}else n[o]=i;if(Object.keys(n).length){const o=t.map(M).join("-"),i="t_"+W(o,4),c=await B(n,`.${o}, .${i}`);s.push(c)}return s.join(`
4
+ `)},Je=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=we(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},we=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?we(o,i,s):s.add(t)}),[...s]):[],$e=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return d.existsSync(t)?t:$e(a.join(e,".."))},We=async e=>{const t=$e(e);return await re.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Ae=async e=>{const t=await We(e);if(t)return t.type};let I;const be=async e=>{if(I)return I;const t=await Ae(e);return t==="module"?I="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:oe&&oe.tagName.toUpperCase()==="SCRIPT"&&oe.src||new URL("index-C2eoLLSc.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},ie=L.createLogger({level:"debug",format:L.format.combine(L.format.colorize(),L.format.cli()),transports:[new L.transports.Console({})]});function Se(e){return e?typeof e!="string"?Se(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 ve={"*, *::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"}},Z=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),Ie=(...e)=>e.flat().reduce((t,s)=>({...t,...s._children}),{}),J={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},A=async e=>{if(J.destDir)return J.destDir;const t=await ce(e),s=a.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return J.destDir=s,s},Fe=["salty","css","styles","styled"],Ce=(e=[])=>new RegExp(`\\.(${[...Fe,...e].join("|")})\\.`),Y=(e,t=[])=>Ce(t).test(e),Ne=async e=>{if(J.rcFile)return J.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=a.join(e,".saltyrc.json"),s=await re.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Ne(a.join(e,".."))},ce=async e=>{var n,o;const t=await Ne(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},Ze=async e=>{const t=await ce(e),s=await A(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=a.join(s,"salty.config.js"),i=await be(e),c=je(n);await ye.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:c});const h=Date.now(),{config:F}=await import(`${o}?t=${h}`);return F},qe=async(e,t)=>{var fe,ue;const s=await A(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async j=>{const{contents:N,outputFilePath:z}=await ee(e,j,s);Object.entries(N).forEach(([T,V])=>{V.isMedia?n.mediaQueries.push([T,V]):V.isGlobalDefine?n.globalStyles.push(V):V.isDefineVariables?n.variables.push(V):V.isDefineTemplates&&n.templates.push(V._setPath(z))})}));const o=await Ze(e),i={...o},c=new Set,h=(j,N=[])=>j?Object.entries(j).flatMap(([z,T])=>{if(!T)return;if(typeof T=="object")return h(T,[...N,z]);const V=Se(z),se=M(z),ne=[...N,V].join(".");c.add(`"${ne}"`);const U=[...N.map(M),se].join("-"),de=Ee(T);return de?`--${U}: ${de.transformed};`:`--${U}: ${T};`}):[],F=j=>j?Object.entries(j).flatMap(([N,z])=>{const T=h(z);return N==="base"?T.join(""):`${N} { ${T.join("")} }`}):[],l=j=>j?Object.entries(j).flatMap(([N,z])=>Object.entries(z).flatMap(([T,V])=>{const se=h(V,[N]),ne=`.${N}-${T}, [data-${N}="${T}"]`,U=se.join("");return`${ne} { ${U} }`})):[],m=j=>({...j,responsive:void 0,conditional:void 0}),$=j=>n.variables.map(N=>j==="static"?m(N._current):N._current[j]),y=Z(m(o.variables),$("static")),r=h(y),p=Z((fe=o.variables)==null?void 0:fe.responsive,$("responsive")),b=F(p),C=Z((ue=o.variables)==null?void 0:ue.conditional,$("conditional")),k=l(C),O=a.join(s,"css/_variables.css"),_=`:root { ${r.join("")} ${b.join("")} } ${k.join("")}`;d.writeFileSync(O,_),i.staticVariables=y;const D=a.join(s,"css/_global.css"),P=Z(o.global,n.globalStyles),E=await B(P,"");d.writeFileSync(D,`@layer global { ${E} }`);const f=a.join(s,"css/_reset.css"),g=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:ve,u=await B(g,"");d.writeFileSync(f,`@layer reset { ${u} }`);const S=a.join(s,"css/_templates.css"),x=Z(o.templates,n.templates),R=await he(x),q=Je(x);d.writeFileSync(S,`@layer templates { ${R} }`),i.templates=x;const H=Ie(n.templates);i.templatePaths=Object.fromEntries(Object.entries(H).map(([j,N])=>[j,N._path]));const{mediaQueries:v}=n;i.mediaQueries=Object.fromEntries(v.map(([j,N])=>[`@${j}`,N]));const G=v.map(([j])=>`'@${j}'`).join(" | "),te=a.join(s,"types/css-tokens.d.ts"),Q=`
5
+ // Variable types
6
+ type VariableTokens = ${[...c].join("|")};
7
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
8
+
9
+ // Template types
10
+ type TemplateTokens = {
11
+ ${Object.entries(q).map(([j,N])=>`${j}?: ${N}`).join(`
12
+ `)}
13
+ }
14
+
15
+ // Media query types
16
+ type MediaQueryKeys = ${G||"''"};
17
+ `;d.writeFileSync(te,Q);const Pe=a.join(s,"cache/config-cache.json");d.writeFileSync(Pe,JSON.stringify(i,null,2))},me=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 c=o.exec(e);if(c){const h=c.at(1);if(Fe.some(l=>h==null?void 0:h.includes(l)))return t}return"styled('div',"}),He=(e,t)=>{try{const s=d.readFileSync(a.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
18
+
19
+ ${e}`:`globalThis.saltyConfig = {};
20
+
21
+ ${e}`}catch{return e}},ee=async(e,t,s)=>{const n=W(t),o=a.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const i=a.parse(t);let c=d.readFileSync(t,"utf8");c=me(c),c=He(c,e);const h=a.join(s,"js",n+".js"),F=await ce(e),l=a.join(e,(F==null?void 0:F.configDir)||"","salty.config.ts"),m=je(l),$=await be(e);await ye.build({stdin:{contents:c,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:h,format:$,target:["node20"],keepNames:!0,external:m,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},b=>{const C=d.readFileSync(b.path,"utf8");return{contents:me(C),loader:"ts"}})}}]});const y=Date.now();return{contents:await import(`${h}?t=${y}`),outputFilePath:h}},Le=async e=>{const t=await A(e),s=a.join(t,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Le(e),s=await A(e),n=a.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return Z(i,t)},le=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Be=async(e,t=le(),s=!0)=>{try{const n=Date.now();t?ie.info("Generating CSS in production mode! 🔥"):ie.info("Generating CSS in development mode! 🚀");const o=[],i=[],c=await A(e),h=a.join(c,"index.css");s&&(()=>{d.existsSync(c)&&ke.execSync("rm -rf "+c),d.mkdirSync(c,{recursive:!0}),d.mkdirSync(a.join(c,"css")),d.mkdirSync(a.join(c,"types")),d.mkdirSync(a.join(c,"js")),d.mkdirSync(a.join(c,"cache"))})();const l=new Set,m=new Set;async function $(f){const w=["node_modules","saltygen"],g=d.statSync(f);if(g.isDirectory()){const u=d.readdirSync(f);if(w.some(x=>f.includes(x)))return;await Promise.all(u.map(x=>$(a.join(f,x))))}else if(g.isFile()&&Y(f)){l.add(f);const S=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(S)&&m.add(f)}}await $(e),await qe(e,m);const y={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async f=>{const{contents:w}=await ee(e,f,c);Object.entries(w).forEach(([g,u])=>{u.isKeyframes?y.keyframes.push({value:u,src:f,name:g}):u.isClassName?y.classNames.push({...u,src:f,name:g}):u.generator&&y.components.push({...u,src:f,name:g})})}));const r=await ae(e);for(const f of y.keyframes){const{value:w}=f,g=`a_${w.animationName}.css`,u=`css/${g}`,S=a.join(c,u);o.push(g),d.writeFileSync(S,w.css)}const p={};for(const f of y.components){const{src:w,name:g}=f,u=f.generator._withBuildContext({callerName:g,isProduction:t,config:r});i[u.priority]||(i[u.priority]=[]);const S=await u.css;if(!S)continue;i[u.priority].push(u.cssFileName);const x=`css/${u.cssFileName}`,R=a.join(c,x);d.writeFileSync(R,S),r.importStrategy==="component"&&(p[w]?p[w].push(u.cssFileName):p[w]=[u.cssFileName])}for(const f of y.classNames){const{src:w,name:g}=f,u=f.generator._withBuildContext({callerName:g,isProduction:t,config:r}),S=await u.css;if(!S)continue;i[0].push(u.cssFileName);const x=`css/${u.cssFileName}`,R=a.join(c,x);d.writeFileSync(R,S),r.importStrategy==="component"&&(p[w]?p[w].push(u.cssFileName):p[w]=[u.cssFileName])}r.importStrategy==="component"&&Object.entries(p).forEach(([f,w])=>{const g=w.map(q=>`@import url('./${q}');`).join(`
22
+ `),u=W(f,6),S=a.parse(f),x=M(S.name),R=a.join(c,`css/f_${x}-${u}.css`);d.writeFileSync(R,g)});const b=o.map(f=>`@import url('./css/${f}');`).join(`
23
+ `);let _=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
24
+
25
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(a.join(c,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
26
+ `)}
27
+ ${b}`;if(r.importStrategy!=="component"){const f=i.reduce((w,g,u)=>{const S=g.reduce((H,v)=>{var Q;const G=a.join(c,"css",v),te=d.readFileSync(G,"utf8"),K=((Q=/.*-([^-]+)-\d+.css/.exec(v))==null?void 0:Q.at(1))||W(G,6);return H.includes(K)?H:`${H}
28
+ /*start:${K}-${v}*/
29
+ ${te}
30
+ /*end:${K}*/
31
+ `},""),x=`l_${u}.css`,R=a.join(c,"css",x),q=`@layer l${u} { ${S}
32
+ }`;return d.writeFileSync(R,q),`${w}
33
+ @import url('./css/${x}');`},"");_+=f}d.writeFileSync(h,_);const P=Date.now()-n,E=P<200?"🔥":P<500?"🚀":P<1e3?"🎉":P<2e3?"🚗":P<5e3?"🤔":"🥴";ie.info(`Generated CSS in ${P}ms! ${E}`)}catch(n){console.error(n)}},Ge=async(e,t,s=le())=>{try{const n=await A(e);if(Y(t)){const i=[],c=await ae(e),{contents:h}=await ee(e,t,n);for(const[F,l]of Object.entries(h)){if(l.isKeyframes&&l.css){const b=`css/${`a_${l.animationName}.css`}`,C=a.join(n,b);d.writeFileSync(C,await l.css);return}if(l.isClassName){const p=l.generator._withBuildContext({callerName:F,isProduction:s,config:c}),b=await p.css;if(!b)continue;i[0].push(p.cssFileName);const C=`css/${p.cssFileName}`,k=a.join(n,C);d.writeFileSync(k,b)}if(!l.generator)return;const m=l.generator._withBuildContext({callerName:F,isProduction:s,config:c}),$=await m.css;if(!$)continue;const y=`css/${m.cssFileName}`,r=a.join(n,y);d.writeFileSync(r,$),i[m.priority]||(i[m.priority]=[]),i[m.priority].push(m.cssFileName)}if(c.importStrategy!=="component")i.forEach((F,l)=>{const m=`l_${l}.css`,$=a.join(n,"css",m);let y=d.readFileSync($,"utf8");F.forEach(r=>{var k;const p=a.join(n,"css",r),b=((k=/.*-([^-]+)-\d+.css/.exec(r))==null?void 0:k.at(1))||W(p,6);if(!y.includes(b)){const O=d.readFileSync(p,"utf8"),_=`/*start:${b}-${r}*/
34
+ ${O}
35
+ /*end:${b}*/
36
+ `;y=`${y.replace(/\}$/,"")}
37
+ ${_}
38
+ }`}}),d.writeFileSync($,y)});else{const F=i.flat().map(r=>`@import url('./${r}');`).join(`
39
+ `),l=W(t,6),m=a.parse(t),$=M(m.name),y=a.join(n,`css/f_${$}-${l}.css`);d.writeFileSync(y,F)}}}catch(n){console.error(n)}},Ke=async(e,t,s=le())=>{try{const n=await A(e);if(Y(t)){const i=d.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,m=>`export ${m}`)!==i&&await re.writeFile(t,i);const h=await ae(e),{contents:F}=await ee(e,t,n);let l=i;if(Object.entries(F).forEach(([m,$])=>{var u;if($.isKeyframes||!$.generator)return;const y=$.generator._withBuildContext({callerName:m,isProduction:s,config:h}),r=new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!r)return console.error("Could not find the original declaration");const p=(u=r.at(1))==null?void 0:u.trim(),b=new RegExp(`\\s${m}[=\\s]+styled\\(`,"g").exec(l);if(!b)return console.error("Could not find the original declaration");const{index:C}=b;let k=!1;const O=setTimeout(()=>k=!0,5e3);let _=0,D=!1,P=0;for(;!D&&!k;){const S=l[C+_];S==="("&&P++,S===")"&&P--,P===0&&S===")"&&(D=!0),_>l.length&&(k=!0),_++}if(!k)clearTimeout(O);else throw new Error("Failed to find the end of the styled call and timed out");const E=C+_,f=l.slice(C,E),w=l,g=` ${m} = styled(${p}, "${y.classNames}", ${JSON.stringify(y.clientProps)});`;l=l.replace(f,g),w===l&&console.error("Minimize file failed to change content",{name:m,tagName:p})}),h.importStrategy==="component"){const m=W(t,6),$=a.parse(t);l=`import '../../saltygen/css/${`f_${M($.name)}-${m}.css`}';
40
+ ${l}`}return l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=Be;exports.generateFile=Ge;exports.isSaltyFile=Y;exports.minimizeFile=Ke;exports.saltyFileRegExp=Ce;
@@ -0,0 +1,599 @@
1
+ import * as yt from "esbuild";
2
+ import { execSync as Dt } from "child_process";
3
+ import { join as u, parse as tt } from "path";
4
+ import { existsSync as at, writeFileSync as D, readFileSync as M, mkdirSync as H, statSync as _t, readdirSync as Et } from "fs";
5
+ import { readFile as $t, writeFile as Tt } from "fs/promises";
6
+ import { createLogger as Ot, format as rt, transports as Vt } from "winston";
7
+ const gt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Mt = (t, e) => {
8
+ let s = "", n;
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = gt(n % 52) + s;
10
+ return s = gt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, Rt = (t, e) => {
12
+ let s = e.length;
13
+ for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
+ return t;
15
+ }, A = (t, e = 5) => {
16
+ const s = Rt(5381, JSON.stringify(t)) >>> 0;
17
+ return Mt(s, e);
18
+ };
19
+ function R(t) {
20
+ 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()) : "";
21
+ }
22
+ const Jt = (t) => (e) => {
23
+ if (typeof e != "string" || !t) return;
24
+ let s = e;
25
+ const n = [];
26
+ return Object.values(t).forEach((o) => {
27
+ const { pattern: r, transform: a } = o;
28
+ s = s.replace(r, (h) => {
29
+ const { value: S, css: c } = a(h);
30
+ return c && n.push(c), S;
31
+ });
32
+ }), { transformed: s, additionalCss: n };
33
+ }, bt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${R(o[1].replaceAll(".", "-"))})`) }, Wt = bt(), zt = [
34
+ "top",
35
+ "right",
36
+ "bottom",
37
+ "left",
38
+ "min-width",
39
+ /.*width.*/,
40
+ /^[^line]*height.*/,
41
+ // Exclude line-height
42
+ /padding.*/,
43
+ /margin.*/,
44
+ /border.*/,
45
+ /inset.*/,
46
+ /.*radius.*/,
47
+ /.*spacing.*/,
48
+ /.*gap.*/,
49
+ /.*indent.*/,
50
+ /.*offset.*/,
51
+ /.*size.*/,
52
+ /.*thickness.*/,
53
+ /.*font-size.*/
54
+ ], At = (t, e, s) => zt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, vt = ["Webkit", "Moz", "ms", "O"], Zt = (t) => t.startsWith("-") ? t : vt.some((e) => t.startsWith(e)) ? `-${R(t)}` : R(t), Y = async (t, e = "", s, n = !1) => {
55
+ if (!t) throw new Error("No styles provided to parseStyles function!");
56
+ const o = /* @__PURE__ */ new Set(), a = Object.entries(t).map(async ([m, i]) => {
57
+ const d = m.trim(), b = Zt(d), j = (E, k = ";") => `${b}:${E}${k}`;
58
+ if (typeof i == "function" && (i = i({ scope: e, config: s })), i instanceof Promise && (i = await i), typeof i == "object") {
59
+ if (!i) return;
60
+ if (i.isColor) return j(i.toString());
61
+ if (d === "defaultVariants") return;
62
+ if (d === "variants") {
63
+ const _ = Object.entries(i);
64
+ for (const [N, O] of _) {
65
+ if (!O) return;
66
+ const l = Object.entries(O);
67
+ for (const [y, g] of l) {
68
+ if (!g) return;
69
+ const f = `${e}.${N}-${y}`;
70
+ (await Y(g, f, s)).forEach((P) => o.add(P));
71
+ }
72
+ }
73
+ return;
74
+ }
75
+ if (d === "compoundVariants") {
76
+ for (const _ of i) {
77
+ const { css: N, ...O } = _, l = Object.entries(O).reduce((g, [f, w]) => `${g}.${f}-${w}`, e);
78
+ (await Y(N, l, s)).forEach((g) => o.add(g));
79
+ }
80
+ return;
81
+ }
82
+ if (d.startsWith("@")) {
83
+ const _ = d, N = await L(i, e, s), O = `${_} { ${N} }`;
84
+ o.add(O);
85
+ return;
86
+ }
87
+ const E = m.includes("&") ? d.replace("&", e) : d.startsWith(":") ? `${e}${d}` : `${e} ${d}`;
88
+ (await Y(i, E, s)).forEach((_) => o.add(_));
89
+ return;
90
+ }
91
+ if (typeof i == "number") {
92
+ const E = At(b, i);
93
+ return j(E);
94
+ }
95
+ if (typeof i != "string")
96
+ if ("toString" in i) i = i.toString();
97
+ else throw new Error(`Invalid value type for property ${b}`);
98
+ return j(i);
99
+ }), { modifiers: h } = {}, S = [bt(), Jt(h)], p = (await Promise.all(a).then((m) => Promise.all(
100
+ m.map((i) => S.reduce(async (d, b) => {
101
+ const j = await d;
102
+ if (!j) return j;
103
+ const x = await b(j);
104
+ if (!x) return j;
105
+ const { transformed: E, additionalCss: k } = x;
106
+ let _ = "";
107
+ if (k)
108
+ for (const N of k)
109
+ _ += await L(N, "");
110
+ return `${_}${E}`;
111
+ }, Promise.resolve(i)))
112
+ ))).join(`
113
+ `);
114
+ if (!p.trim()) return o;
115
+ const $ = e ? `${e} { ${p} }` : p;
116
+ return o.add($), o;
117
+ }, L = async (t, e, s, n = !1) => [...await Y(t, e, s, n)].join(`
118
+ `), wt = async (t, e = []) => {
119
+ if (!t) return "";
120
+ const s = [], n = {};
121
+ for (const [o, r] of Object.entries(t))
122
+ if (typeof r != "function") if (r && typeof r == "object") {
123
+ const a = o.trim(), h = await wt(r, [...e, a]);
124
+ s.push(h);
125
+ } else
126
+ n[o] = r;
127
+ if (Object.keys(n).length) {
128
+ const o = e.map(R).join("-"), r = "t_" + A(o, 4), a = await L(n, `.${o}, .${r}`);
129
+ s.push(a);
130
+ }
131
+ return s.join(`
132
+ `);
133
+ }, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = Ct(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
134
+ const r = e ? `${e}.${n}` : n;
135
+ return typeof o == "object" ? Ct(o, r, s) : s.add(e);
136
+ }), [...s]) : [], St = (t) => {
137
+ if (!t || t === "/") throw new Error("Could not find package.json file");
138
+ const e = u(t, "package.json");
139
+ return at(e) ? e : St(u(t, ".."));
140
+ }, Ht = async (t) => {
141
+ const e = St(t);
142
+ return await $t(e, "utf-8").then(JSON.parse).catch(() => {
143
+ });
144
+ }, Bt = async (t) => {
145
+ const e = await Ht(t);
146
+ if (e)
147
+ return e.type;
148
+ };
149
+ let I;
150
+ const jt = async (t) => {
151
+ if (I) return I;
152
+ const e = await Bt(t);
153
+ return e === "module" ? I = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (I = "cjs"), I || "esm";
154
+ }, it = Ot({
155
+ level: "debug",
156
+ format: rt.combine(rt.colorize(), rt.cli()),
157
+ transports: [new Vt.Console({})]
158
+ });
159
+ function Ft(t) {
160
+ return t ? typeof t != "string" ? Ft(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
161
+ }
162
+ const Gt = {
163
+ /** Set box model to border-box */
164
+ "*, *::before, *::after": {
165
+ boxSizing: "border-box"
166
+ },
167
+ /** Remove default margin and padding */
168
+ "*": {
169
+ margin: 0
170
+ },
171
+ /** Remove adjust font properties */
172
+ html: {
173
+ lineHeight: 1.15,
174
+ textSizeAdjust: "100%",
175
+ WebkitFontSmoothing: "antialiased"
176
+ },
177
+ /** Make media elements responsive */
178
+ "img, picture, video, canvas, svg": {
179
+ display: "block",
180
+ maxWidth: "100%"
181
+ },
182
+ /** Avoid overflow of text */
183
+ "p, h1, h2, h3, h4, h5, h6": {
184
+ overflowWrap: "break-word"
185
+ },
186
+ /** Improve text wrapping */
187
+ p: {
188
+ textWrap: "pretty"
189
+ },
190
+ "h1, h2, h3, h4, h5, h6": {
191
+ textWrap: "balance"
192
+ },
193
+ /** Improve link color */
194
+ a: {
195
+ color: "currentColor"
196
+ },
197
+ /** Improve button line height */
198
+ button: {
199
+ lineHeight: "1em",
200
+ color: "currentColor"
201
+ },
202
+ /** Improve form elements */
203
+ "input, optgroup, select, textarea": {
204
+ fontFamily: "inherit",
205
+ fontSize: "100%",
206
+ lineHeight: "1.15em"
207
+ }
208
+ }, B = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), Kt = (...t) => t.flat().reduce((e, s) => ({ ...e, ...s._children }), {}), z = {
209
+ externalModules: [],
210
+ rcFile: void 0,
211
+ destDir: void 0
212
+ }, Nt = (t) => {
213
+ if (z.externalModules.length > 0) return z.externalModules;
214
+ const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
215
+ if (!s) return [];
216
+ const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
217
+ return z.externalModules = n, n;
218
+ }, v = async (t) => {
219
+ if (z.destDir) return z.destDir;
220
+ const e = await lt(t), s = u(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
221
+ return z.destDir = s, s;
222
+ }, Pt = ["salty", "css", "styles", "styled"], Lt = (t = []) => new RegExp(`\\.(${[...Pt, ...t].join("|")})\\.`), ct = (t, e = []) => Lt(e).test(t), xt = async (t) => {
223
+ if (z.rcFile) return z.rcFile;
224
+ if (t === "/") throw new Error("Could not find .saltyrc.json file");
225
+ const e = u(t, ".saltyrc.json"), s = await $t(e, "utf-8").then(JSON.parse).catch(() => {
226
+ });
227
+ return s ? (z.rcFile = s, s) : xt(u(t, ".."));
228
+ }, lt = async (t) => {
229
+ var n, o;
230
+ const e = await xt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
231
+ return s || ((o = e.projects) == null ? void 0 : o.find((r) => r.dir === e.defaultProject));
232
+ }, Qt = async (t) => {
233
+ const e = await lt(t), s = await v(t), n = u(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await jt(t), a = Nt(n);
234
+ await yt.build({
235
+ entryPoints: [n],
236
+ minify: !0,
237
+ treeShaking: !0,
238
+ bundle: !0,
239
+ outfile: o,
240
+ format: r,
241
+ external: a
242
+ });
243
+ const h = Date.now(), { config: S } = await import(`${o}?t=${h}`);
244
+ return S;
245
+ }, qt = async (t, e) => {
246
+ var dt, pt;
247
+ const s = await v(t), n = {
248
+ mediaQueries: [],
249
+ globalStyles: [],
250
+ variables: [],
251
+ templates: []
252
+ };
253
+ await Promise.all(
254
+ [...e].map(async (C) => {
255
+ const { contents: F, outputFilePath: W } = await et(t, C, s);
256
+ Object.entries(F).forEach(([T, V]) => {
257
+ V.isMedia ? n.mediaQueries.push([T, V]) : V.isGlobalDefine ? n.globalStyles.push(V) : V.isDefineVariables ? n.variables.push(V) : V.isDefineTemplates && n.templates.push(V._setPath(W));
258
+ });
259
+ })
260
+ );
261
+ const o = await Qt(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (C, F = []) => C ? Object.entries(C).flatMap(([W, T]) => {
262
+ if (!T) return;
263
+ if (typeof T == "object") return h(T, [...F, W]);
264
+ const V = Ft(W), nt = R(W), ot = [...F, V].join(".");
265
+ a.add(`"${ot}"`);
266
+ const X = [...F.map(R), nt].join("-"), mt = Wt(T);
267
+ return mt ? `--${X}: ${mt.transformed};` : `--${X}: ${T};`;
268
+ }) : [], S = (C) => C ? Object.entries(C).flatMap(([F, W]) => {
269
+ const T = h(W);
270
+ return F === "base" ? T.join("") : `${F} { ${T.join("")} }`;
271
+ }) : [], c = (C) => C ? Object.entries(C).flatMap(([F, W]) => Object.entries(W).flatMap(([T, V]) => {
272
+ const nt = h(V, [F]), ot = `.${F}-${T}, [data-${F}="${T}"]`, X = nt.join("");
273
+ return `${ot} { ${X} }`;
274
+ })) : [], p = (C) => ({ ...C, responsive: void 0, conditional: void 0 }), $ = (C) => n.variables.map((F) => C === "static" ? p(F._current) : F._current[C]), m = B(p(o.variables), $("static")), i = h(m), d = B((dt = o.variables) == null ? void 0 : dt.responsive, $("responsive")), b = S(d), j = B((pt = o.variables) == null ? void 0 : pt.conditional, $("conditional")), x = c(j), E = u(s, "css/_variables.css"), k = `:root { ${i.join("")} ${b.join("")} } ${x.join("")}`;
275
+ D(E, k), r.staticVariables = m;
276
+ const _ = u(s, "css/_global.css"), N = B(o.global, n.globalStyles), O = await L(N, "");
277
+ D(_, `@layer global { ${O} }`);
278
+ const l = u(s, "css/_reset.css"), g = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Gt, f = await L(g, "");
279
+ D(l, `@layer reset { ${f} }`);
280
+ const w = u(s, "css/_templates.css"), P = B(o.templates, n.templates), J = await wt(P), G = It(P);
281
+ D(w, `@layer templates { ${J} }`), r.templates = P;
282
+ const K = Kt(n.templates);
283
+ r.templatePaths = Object.fromEntries(Object.entries(K).map(([C, F]) => [C, F._path]));
284
+ const { mediaQueries: Z } = n;
285
+ r.mediaQueries = Object.fromEntries(Z.map(([C, F]) => [`@${C}`, F]));
286
+ const Q = Z.map(([C]) => `'@${C}'`).join(" | "), st = u(s, "types/css-tokens.d.ts"), U = `
287
+ // Variable types
288
+ type VariableTokens = ${[...a].join("|")};
289
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
290
+
291
+ // Template types
292
+ type TemplateTokens = {
293
+ ${Object.entries(G).map(([C, F]) => `${C}?: ${F}`).join(`
294
+ `)}
295
+ }
296
+
297
+ // Media query types
298
+ type MediaQueryKeys = ${Q || "''"};
299
+ `;
300
+ D(st, U);
301
+ const kt = u(s, "cache/config-cache.json");
302
+ D(kt, JSON.stringify(r, null, 2));
303
+ }, ht = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
304
+ if (/^['"`]/.test(s)) return e;
305
+ const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
306
+ if (!o.test(t)) return e;
307
+ const a = o.exec(t);
308
+ if (a) {
309
+ const h = a.at(1);
310
+ if (Pt.some((c) => h == null ? void 0 : h.includes(c))) return e;
311
+ }
312
+ return "styled('div',";
313
+ }), Ut = (t, e) => {
314
+ try {
315
+ const s = M(u(e, "saltygen/cache/config-cache.json"), "utf8");
316
+ return s ? `globalThis.saltyConfig = ${s};
317
+
318
+ ${t}` : `globalThis.saltyConfig = {};
319
+
320
+ ${t}`;
321
+ } catch {
322
+ return t;
323
+ }
324
+ }, et = async (t, e, s) => {
325
+ const n = A(e), o = u(s, "./temp");
326
+ at(o) || H(o);
327
+ const r = tt(e);
328
+ let a = M(e, "utf8");
329
+ a = ht(a), a = Ut(a, t);
330
+ const h = u(s, "js", n + ".js"), S = await lt(t), c = u(t, (S == null ? void 0 : S.configDir) || "", "salty.config.ts"), p = Nt(c), $ = await jt(t);
331
+ await yt.build({
332
+ stdin: {
333
+ contents: a,
334
+ sourcefile: r.base,
335
+ resolveDir: r.dir,
336
+ loader: "tsx"
337
+ },
338
+ minify: !1,
339
+ treeShaking: !0,
340
+ bundle: !0,
341
+ outfile: h,
342
+ format: $,
343
+ target: ["node20"],
344
+ keepNames: !0,
345
+ external: p,
346
+ packages: "external",
347
+ plugins: [
348
+ {
349
+ name: "test",
350
+ setup: (d) => {
351
+ d.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (b) => {
352
+ const j = M(b.path, "utf8");
353
+ return { contents: ht(j), loader: "ts" };
354
+ });
355
+ }
356
+ }
357
+ ]
358
+ });
359
+ const m = Date.now();
360
+ return { contents: await import(`${h}?t=${m}`), outputFilePath: h };
361
+ }, Xt = async (t) => {
362
+ const e = await v(t), s = u(e, "cache/config-cache.json"), n = M(s, "utf8");
363
+ if (!n) throw new Error("Could not find config cache file");
364
+ return JSON.parse(n);
365
+ }, ft = async (t) => {
366
+ const e = await Xt(t), s = await v(t), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
367
+ return B(r, e);
368
+ }, ut = () => {
369
+ try {
370
+ return process.env.NODE_ENV === "production";
371
+ } catch {
372
+ return !1;
373
+ }
374
+ }, oe = async (t, e = ut(), s = !0) => {
375
+ try {
376
+ const n = Date.now();
377
+ e ? it.info("Generating CSS in production mode! 🔥") : it.info("Generating CSS in development mode! 🚀");
378
+ const o = [], r = [], a = await v(t), h = u(a, "index.css");
379
+ s && (() => {
380
+ at(a) && Dt("rm -rf " + a), H(a, { recursive: !0 }), H(u(a, "css")), H(u(a, "types")), H(u(a, "js")), H(u(a, "cache"));
381
+ })();
382
+ const c = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
383
+ async function $(l) {
384
+ const y = ["node_modules", "saltygen"], g = _t(l);
385
+ if (g.isDirectory()) {
386
+ const f = Et(l);
387
+ if (y.some((P) => l.includes(P))) return;
388
+ await Promise.all(f.map((P) => $(u(l, P))));
389
+ } else if (g.isFile() && ct(l)) {
390
+ c.add(l);
391
+ const w = M(l, "utf8");
392
+ /define[\w\d]+\(/.test(w) && p.add(l);
393
+ }
394
+ }
395
+ await $(t), await qt(t, p);
396
+ const m = {
397
+ keyframes: [],
398
+ components: [],
399
+ classNames: []
400
+ };
401
+ await Promise.all(
402
+ [...c].map(async (l) => {
403
+ const { contents: y } = await et(t, l, a);
404
+ Object.entries(y).forEach(([g, f]) => {
405
+ f.isKeyframes ? m.keyframes.push({
406
+ value: f,
407
+ src: l,
408
+ name: g
409
+ }) : f.isClassName ? m.classNames.push({
410
+ ...f,
411
+ src: l,
412
+ name: g
413
+ }) : f.generator && m.components.push({
414
+ ...f,
415
+ src: l,
416
+ name: g
417
+ });
418
+ });
419
+ })
420
+ );
421
+ const i = await ft(t);
422
+ for (const l of m.keyframes) {
423
+ const { value: y } = l, g = `a_${y.animationName}.css`, f = `css/${g}`, w = u(a, f);
424
+ o.push(g), D(w, y.css);
425
+ }
426
+ const d = {};
427
+ for (const l of m.components) {
428
+ const { src: y, name: g } = l, f = l.generator._withBuildContext({
429
+ callerName: g,
430
+ isProduction: e,
431
+ config: i
432
+ });
433
+ r[f.priority] || (r[f.priority] = []);
434
+ const w = await f.css;
435
+ if (!w) continue;
436
+ r[f.priority].push(f.cssFileName);
437
+ const P = `css/${f.cssFileName}`, J = u(a, P);
438
+ D(J, w), i.importStrategy === "component" && (d[y] ? d[y].push(f.cssFileName) : d[y] = [f.cssFileName]);
439
+ }
440
+ for (const l of m.classNames) {
441
+ const { src: y, name: g } = l, f = l.generator._withBuildContext({
442
+ callerName: g,
443
+ isProduction: e,
444
+ config: i
445
+ }), w = await f.css;
446
+ if (!w) continue;
447
+ r[0].push(f.cssFileName);
448
+ const P = `css/${f.cssFileName}`, J = u(a, P);
449
+ D(J, w), i.importStrategy === "component" && (d[y] ? d[y].push(f.cssFileName) : d[y] = [f.cssFileName]);
450
+ }
451
+ i.importStrategy === "component" && Object.entries(d).forEach(([l, y]) => {
452
+ const g = y.map((G) => `@import url('./${G}');`).join(`
453
+ `), f = A(l, 6), w = tt(l), P = R(w.name), J = u(a, `css/f_${P}-${f}.css`);
454
+ D(J, g);
455
+ });
456
+ const b = o.map((l) => `@import url('./css/${l}');`).join(`
457
+ `);
458
+ let k = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
459
+
460
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
461
+ try {
462
+ return M(u(a, "css", l), "utf8").length > 0;
463
+ } catch {
464
+ return !1;
465
+ }
466
+ }).map((l) => `@import url('./css/${l}');`).join(`
467
+ `)}
468
+ ${b}`;
469
+ if (i.importStrategy !== "component") {
470
+ const l = r.reduce((y, g, f) => {
471
+ const w = g.reduce((K, Z) => {
472
+ var U;
473
+ const Q = u(a, "css", Z), st = M(Q, "utf8"), q = ((U = /.*-([^-]+)-\d+.css/.exec(Z)) == null ? void 0 : U.at(1)) || A(Q, 6);
474
+ return K.includes(q) ? K : `${K}
475
+ /*start:${q}-${Z}*/
476
+ ${st}
477
+ /*end:${q}*/
478
+ `;
479
+ }, ""), P = `l_${f}.css`, J = u(a, "css", P), G = `@layer l${f} { ${w}
480
+ }`;
481
+ return D(J, G), `${y}
482
+ @import url('./css/${P}');`;
483
+ }, "");
484
+ k += l;
485
+ }
486
+ D(h, k);
487
+ const N = Date.now() - n, O = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
488
+ it.info(`Generated CSS in ${N}ms! ${O}`);
489
+ } catch (n) {
490
+ console.error(n);
491
+ }
492
+ }, re = async (t, e, s = ut()) => {
493
+ try {
494
+ const n = await v(t);
495
+ if (ct(e)) {
496
+ const r = [], a = await ft(t), { contents: h } = await et(t, e, n);
497
+ for (const [S, c] of Object.entries(h)) {
498
+ if (c.isKeyframes && c.css) {
499
+ const b = `css/${`a_${c.animationName}.css`}`, j = u(n, b);
500
+ D(j, await c.css);
501
+ return;
502
+ }
503
+ if (c.isClassName) {
504
+ const d = c.generator._withBuildContext({
505
+ callerName: S,
506
+ isProduction: s,
507
+ config: a
508
+ }), b = await d.css;
509
+ if (!b) continue;
510
+ r[0].push(d.cssFileName);
511
+ const j = `css/${d.cssFileName}`, x = u(n, j);
512
+ D(x, b);
513
+ }
514
+ if (!c.generator) return;
515
+ const p = c.generator._withBuildContext({
516
+ callerName: S,
517
+ isProduction: s,
518
+ config: a
519
+ }), $ = await p.css;
520
+ if (!$) continue;
521
+ const m = `css/${p.cssFileName}`, i = u(n, m);
522
+ D(i, $), r[p.priority] || (r[p.priority] = []), r[p.priority].push(p.cssFileName);
523
+ }
524
+ if (a.importStrategy !== "component")
525
+ r.forEach((S, c) => {
526
+ const p = `l_${c}.css`, $ = u(n, "css", p);
527
+ let m = M($, "utf8");
528
+ S.forEach((i) => {
529
+ var x;
530
+ const d = u(n, "css", i), b = ((x = /.*-([^-]+)-\d+.css/.exec(i)) == null ? void 0 : x.at(1)) || A(d, 6);
531
+ if (!m.includes(b)) {
532
+ const E = M(d, "utf8"), k = `/*start:${b}-${i}*/
533
+ ${E}
534
+ /*end:${b}*/
535
+ `;
536
+ m = `${m.replace(/\}$/, "")}
537
+ ${k}
538
+ }`;
539
+ }
540
+ }), D($, m);
541
+ });
542
+ else {
543
+ const S = r.flat().map((i) => `@import url('./${i}');`).join(`
544
+ `), c = A(e, 6), p = tt(e), $ = R(p.name), m = u(n, `css/f_${$}-${c}.css`);
545
+ D(m, S);
546
+ }
547
+ }
548
+ } catch (n) {
549
+ console.error(n);
550
+ }
551
+ }, ie = async (t, e, s = ut()) => {
552
+ try {
553
+ const n = await v(t);
554
+ if (ct(e)) {
555
+ const r = M(e, "utf8");
556
+ r.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== r && await Tt(e, r);
557
+ const h = await ft(t), { contents: S } = await et(t, e, n);
558
+ let c = r;
559
+ if (Object.entries(S).forEach(([p, $]) => {
560
+ var f;
561
+ if ($.isKeyframes || !$.generator) return;
562
+ const m = $.generator._withBuildContext({
563
+ callerName: p,
564
+ isProduction: s,
565
+ config: h
566
+ }), i = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
567
+ if (!i) return console.error("Could not find the original declaration");
568
+ const d = (f = i.at(1)) == null ? void 0 : f.trim(), b = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(c);
569
+ if (!b) return console.error("Could not find the original declaration");
570
+ const { index: j } = b;
571
+ let x = !1;
572
+ const E = setTimeout(() => x = !0, 5e3);
573
+ let k = 0, _ = !1, N = 0;
574
+ for (; !_ && !x; ) {
575
+ const w = c[j + k];
576
+ w === "(" && N++, w === ")" && N--, N === 0 && w === ")" && (_ = !0), k > c.length && (x = !0), k++;
577
+ }
578
+ if (!x) clearTimeout(E);
579
+ else throw new Error("Failed to find the end of the styled call and timed out");
580
+ const O = j + k, l = c.slice(j, O), y = c, g = ` ${p} = styled(${d}, "${m.classNames}", ${JSON.stringify(m.clientProps)});`;
581
+ c = c.replace(l, g), y === c && console.error("Minimize file failed to change content", { name: p, tagName: d });
582
+ }), h.importStrategy === "component") {
583
+ const p = A(e, 6), $ = tt(e);
584
+ c = `import '../../saltygen/css/${`f_${R($.name)}-${p}.css`}';
585
+ ${c}`;
586
+ }
587
+ return c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
588
+ }
589
+ } catch (n) {
590
+ console.error("Error in minimizeFile:", n);
591
+ }
592
+ };
593
+ export {
594
+ re as a,
595
+ oe as g,
596
+ ct as i,
597
+ ie as m,
598
+ Lt as s
599
+ };
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-DJ94M3fE.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 a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var n,u,i;(u=(n=e.module)==null?void 0:n.rules)==null||u.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(i=e.plugins)==null||i.push({apply:f=>{let o=!1;f.hooks.watchRun.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-C2eoLLSc.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 a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var n,u,i;(u=(n=e.module)==null?void 0:n.rules)==null||u.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(i=e.plugins)==null||i.push({apply:f=>{let o=!1;f.hooks.watchRun.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;