@salty-css/webpack 0.0.1-alpha.201 → 0.0.1-alpha.202

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