@salty-css/core 0.0.1-alpha.206 → 0.0.1-alpha.208

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,38 @@
1
+ "use strict";const Ce=require("esbuild"),xe=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),oe=require("fs/promises"),X=require("./parse-styles-GZrbHhPa.cjs"),B=require("winston"),M=require("./css/merge.cjs");var ne=typeof document<"u"?document.currentScript:null;function Ne(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 pe=Ne(Ce),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[r,o]of Object.entries(e))if(typeof o!="function")if(o&&typeof o=="object"){const a=r.trim(),y=await ye(o,[...t,a]);s.push(y)}else n[r]=o;if(Object.keys(n).length){const r=t.map(D.dashCase).join("-"),o="t_"+D.toHash(r,4),a=await X.parseAndJoinStyles(n,`.${r}, .${o}`);s.push(a)}return s.join(`
2
+ `)},Pe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(r=>`"${r}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,r])=>{const o=t?`${t}.${n}`:n;return typeof r=="object"?me(r,o,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:ge(i.join(e,".."))},ke=async e=>{const t=ge(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},De=async e=>{const t=await ke(e);if(t)return t.type};let H;const he=async e=>{if(H)return H;const t=await De(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-BeL1bijz.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),_e=e=>{G.error(e)};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 Oe={"*, *::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"}},V={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(V.externalModules.length>0)return V.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await re(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},ie=["salty","css","styles","styled"],we=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),Y=(e,t=[])=>we(t).test(e),be=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):be(i.join(e,".."))},re=async e=>{var n,r;const t=await be(e),s=(n=t.projects)==null?void 0:n.find(o=>e.endsWith(o.dir||""));return s||((r=t.projects)==null?void 0:r.find(o=>o.dir===t.defaultProject))},Te=async e=>{const t=await re(e),s=await v(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),o=await he(e),a=je(n);await pe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:o,external:a});const y=Date.now(),{config:$}=await import(`${r}?t=${y}`);return $},Fe=async(e,t)=>{var le,fe;const s=await v(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async m=>{const{contents:b,outputFilePath:R}=await K(e,m,s);Object.entries(b).forEach(([k,O])=>{O.isMedia?n.mediaQueries.push([k,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(R))})}));const r=await Te(e),o={...r},a=new Set,y=(m,b=[])=>m?Object.entries(m).flatMap(([R,k])=>{if(!k)return;if(typeof k=="object")return y(k,[...b,R]);const O=Se(R),te=D.dashCase(R),se=[...b,O].join(".");a.add(`"${se}"`);const U=[...b.map(D.dashCase),te].join("-"),ue=X.parseVariableTokens(k);return ue?`--${U}: ${ue.transformed};`:`--${U}: ${k};`}):[],$=m=>m?Object.entries(m).flatMap(([b,R])=>{const k=y(R);return b==="base"?k.join(""):`${b} { ${k.join("")} }`}):[],l=m=>m?Object.entries(m).flatMap(([b,R])=>Object.entries(R).flatMap(([k,O])=>{const te=y(O,[b]),se=`.${b}-${k}, [data-${b}="${k}"]`,U=te.join("");return`${se} { ${U} }`})):[],d=m=>({...m,responsive:void 0,conditional:void 0}),g=m=>n.variables.map(b=>m==="static"?d(b._current):b._current[m]),p=M.mergeObjects(d(r.variables),g("static")),j=y(p),h=M.mergeObjects((le=r.variables)==null?void 0:le.responsive,g("responsive")),C=$(h),N=M.mergeObjects((fe=r.variables)==null?void 0:fe.conditional,g("conditional")),P=l(N),J=i.join(s,"css/_variables.css"),T=`:root { ${j.join("")} ${C.join("")} } ${P.join("")}`;c.writeFileSync(J,T),o.staticVariables=p;const q=i.join(s,"css/_global.css"),_=M.mergeObjects(r.global,n.globalStyles),I=await X.parseAndJoinStyles(_,"");c.writeFileSync(q,`@layer global { ${I} }`);const f=i.join(s,"css/_reset.css"),w=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:Oe,u=await X.parseAndJoinStyles(w,"");c.writeFileSync(f,`@layer reset { ${u} }`);const F=i.join(s,"css/_templates.css"),x=M.mergeObjects(r.templates,n.templates),E=await ye(x),W=Pe(x);c.writeFileSync(F,`@layer templates { ${E} }`),o.templates=x;const A=M.mergeFactories(n.templates);o.templatePaths=Object.fromEntries(Object.entries(A).map(([m,b])=>[m,b._path]));const{mediaQueries:z}=n;o.mediaQueries=Object.fromEntries(z.map(([m,b])=>[`@${m}`,b]));const L=z.map(([m])=>`'@${m}'`).join(" | "),ee=i.join(s,"types/css-tokens.d.ts"),Z=`
3
+ // Variable types
4
+ type VariableTokens = ${[...a].join("|")};
5
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
6
+
7
+ // Template types
8
+ type TemplateTokens = {
9
+ ${Object.entries(W).map(([m,b])=>`${m}?: ${b}`).join(`
10
+ `)}
11
+ }
12
+
13
+ // Media query types
14
+ type MediaQueryKeys = ${L||"''"};
15
+ `;c.writeFileSync(ee,Z);const $e=i.join(s,"cache/config-cache.json");c.writeFileSync($e,JSON.stringify(o,null,2))},de=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const a=r.exec(e);if(a){const y=a.at(1);if(ie.some(l=>y==null?void 0:y.includes(l)))return t}return"styled('div',"}),Ee=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
16
+
17
+ ${e}`:`globalThis.saltyConfig = {};
18
+
19
+ ${e}`}catch{return e}},K=async(e,t,s)=>{const n=D.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const o=i.parse(t);let a=c.readFileSync(t,"utf8");a=de(a),a=Ee(a,e);const y=i.join(s,"js",n+".js"),$=await re(e),l=i.join(e,($==null?void 0:$.configDir)||"","salty.config.ts"),d=je(l),g=await he(e);await pe.build({stdin:{contents:a,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},C=>{const N=c.readFileSync(C.path,"utf8");return{contents:de(N),loader:"ts"}})}}]});const p=Date.now();return{contents:await import(`${y}?t=${p}`),outputFilePath:y}},Re=async e=>{const t=await v(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await v(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:o}=await import(`${n}?t=${r}`);return M.mergeObjects(o,t)},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ve=async(e,t=ce(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const r=[],o=[],a=await v(e),y=i.join(a,"index.css");s&&(()=>{c.existsSync(a)&&xe.execSync("rm -rf "+a),c.mkdirSync(a,{recursive:!0}),c.mkdirSync(i.join(a,"css")),c.mkdirSync(i.join(a,"types")),c.mkdirSync(i.join(a,"js")),c.mkdirSync(i.join(a,"cache"))})();const l=new Set,d=new Set;async function g(f){const S=["node_modules","saltygen"],w=c.statSync(f);if(w.isDirectory()){const u=c.readdirSync(f);if(S.some(x=>f.includes(x)))return;await Promise.all(u.map(x=>g(i.join(f,x))))}else if(w.isFile()&&Y(f)){l.add(f);const F=c.readFileSync(f,"utf8");/define[\w\d]+\(/.test(F)&&d.add(f)}}await g(e),await Fe(e,d);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async f=>{const{contents:S}=await K(e,f,a);Object.entries(S).forEach(([w,u])=>{u.isKeyframes?p.keyframes.push({value:u,src:f,name:w}):u.isClassName?p.classNames.push({...u,src:f,name:w}):u.generator&&p.components.push({...u,src:f,name:w})})}));const j=await ae(e);for(const f of p.keyframes){const{value:S}=f,w=`a_${S.animationName}.css`,u=`css/${w}`,F=i.join(a,u);r.push(w),c.writeFileSync(F,S.css)}const h={};for(const f of p.components){const{src:S,name:w}=f,u=f.generator._withBuildContext({callerName:w,isProduction:t,config:j});o[u.priority]||(o[u.priority]=[]);const F=await u.css;if(!F)continue;o[u.priority].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=i.join(a,x);c.writeFileSync(E,F),j.importStrategy==="component"&&(h[S]?h[S].push(u.cssFileName):h[S]=[u.cssFileName])}for(const f of p.classNames){const{src:S,name:w}=f,u=f.generator._withBuildContext({callerName:w,isProduction:t,config:j}),F=await u.css;if(!F)continue;o[0].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=i.join(a,x);c.writeFileSync(E,F),j.importStrategy==="component"&&(h[S]?h[S].push(u.cssFileName):h[S]=[u.cssFileName])}j.importStrategy==="component"&&Object.entries(h).forEach(([f,S])=>{const w=S.map(W=>`@import url('./${W}');`).join(`
20
+ `),u=D.toHash(f,6),F=i.parse(f),x=D.dashCase(F.name),E=i.join(a,`css/f_${x}-${u}.css`);c.writeFileSync(E,w)});const C=r.map(f=>`@import url('./css/${f}');`).join(`
21
+ `);let T=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
22
+
23
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return c.readFileSync(i.join(a,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
24
+ `)}
25
+ ${C}`;if(j.importStrategy!=="component"){const f=o.reduce((S,w,u)=>{const F=w.reduce((A,z)=>{var Z;const L=i.join(a,"css",z),ee=c.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(z))==null?void 0:Z.at(1))||D.toHash(L,6);return A.includes(Q)?A:`${A}
26
+ /*start:${Q}-${z}*/
27
+ ${ee}
28
+ /*end:${Q}*/
29
+ `},""),x=`l_${u}.css`,E=i.join(a,"css",x),W=`@layer l${u} { ${F}
30
+ }`;return c.writeFileSync(E,W),`${S}
31
+ @import url('./css/${x}');`},"");T+=f}c.writeFileSync(y,T);const _=Date.now()-n,I=_<200?"🔥":_<500?"🚀":_<1e3?"🎉":_<2e3?"🚗":_<5e3?"🤔":"🥴";G.info(`Generated CSS in ${_}ms! ${I}`)}catch(n){console.error(n)}},Me=async(e,t,s=ce())=>{try{const n=await v(e);if(Y(t)){const o=[],a=await ae(e),{contents:y}=await K(e,t,n);for(const[$,l]of Object.entries(y)){if(l.isKeyframes&&l.css){const C=`css/${`a_${l.animationName}.css`}`,N=i.join(n,C);c.writeFileSync(N,await l.css);return}if(l.isClassName){const h=l.generator._withBuildContext({callerName:$,isProduction:s,config:a}),C=await h.css;if(!C)continue;o[0].push(h.cssFileName);const N=`css/${h.cssFileName}`,P=i.join(n,N);c.writeFileSync(P,C)}if(!l.generator)return;const d=l.generator._withBuildContext({callerName:$,isProduction:s,config:a}),g=await d.css;if(!g)continue;const p=`css/${d.cssFileName}`,j=i.join(n,p);c.writeFileSync(j,g),o[d.priority]||(o[d.priority]=[]),o[d.priority].push(d.cssFileName)}if(a.importStrategy!=="component")o.forEach(($,l)=>{const d=`l_${l}.css`,g=i.join(n,"css",d);let p=c.readFileSync(g,"utf8");$.forEach(j=>{var P;const h=i.join(n,"css",j),C=((P=/.*-([^-]+)-\d+.css/.exec(j))==null?void 0:P.at(1))||D.toHash(h,6);if(!p.includes(C)){const J=c.readFileSync(h,"utf8"),T=`/*start:${C}-${j}*/
32
+ ${J}
33
+ /*end:${C}*/
34
+ `;p=`${p.replace(/\}$/,"")}
35
+ ${T}
36
+ }`}}),c.writeFileSync(g,p)});else{const $=o.flat().map(j=>`@import url('./${j}');`).join(`
37
+ `),l=D.toHash(t,6),d=i.parse(t),g=D.dashCase(d.name),p=i.join(n,`css/f_${g}-${l}.css`);c.writeFileSync(p,$)}}}catch(n){console.error(n)}},ve=async(e,t,s=ce())=>{try{const n=await v(e);if(Y(t)){const o=c.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==o&&await oe.writeFile(t,o);const y=await ae(e),{contents:$}=await K(e,t,n);let l=o;if(Object.entries($).forEach(([d,g])=>{var u;if(g.isKeyframes||!g.generator)return;const p=g.generator._withBuildContext({callerName:d,isProduction:s,config:y}),j=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!j)return console.error("Could not find the original declaration");const h=(u=j.at(1))==null?void 0:u.trim(),C=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(l);if(!C)return console.error("Could not find the original declaration");const{index:N}=C;let P=!1;const J=setTimeout(()=>P=!0,5e3);let T=0,q=!1,_=0;for(;!q&&!P;){const F=l[N+T];F==="("&&_++,F===")"&&_--,_===0&&F===")"&&(q=!0),T>l.length&&(P=!0),T++}if(!P)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const I=N+T,f=l.slice(N,I),S=l,w=` ${d} = styled(${h}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;l=l.replace(f,w),S===l&&console.error("Minimize file failed to change content",{name:d,tagName:h})}),y.importStrategy==="component"){const d=D.toHash(t,6),g=i.parse(t);l=`import '../../saltygen/css/${`f_${D.dashCase(g.name)}-${d}.css`}';
38
+ ${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.compileSaltyFile=K;exports.generateConfigStyles=Fe;exports.generateCss=Ve;exports.generateFile=Me;exports.isSaltyFile=Y;exports.logError=_e;exports.logger=G;exports.minimizeFile=ve;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.206",
3
+ "version": "0.0.1-alpha.208",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -1,16 +1,16 @@
1
1
  import { d as V } from "./dash-case-DBThphLm.js";
2
- const A = (i) => (e) => {
2
+ const U = (i) => (e) => {
3
3
  if (typeof e != "string" || !i) return;
4
4
  let t = e;
5
5
  const f = [];
6
6
  return Object.values(i).forEach((n) => {
7
7
  const { pattern: y, transform: b } = n;
8
8
  t = t.replace(y, (P) => {
9
- const { value: j, css: E } = b(P);
10
- return E && f.push(E), j;
9
+ const { value: E, css: j } = b(P);
10
+ return j && f.push(j), E;
11
11
  });
12
12
  }), { transformed: t, additionalCss: f };
13
- }, z = (i) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) }, I = z(), M = [
13
+ }, z = (i) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) }, J = z(), M = [
14
14
  "top",
15
15
  "right",
16
16
  "bottom",
@@ -37,15 +37,15 @@ const A = (i) => (e) => {
37
37
  return `${e}${n}`;
38
38
  }
39
39
  return `${e}`;
40
- }, _ = ["Webkit", "Moz", "ms", "O"], q = (i) => i.startsWith("-") ? i : _.some((e) => i.startsWith(e)) ? `-${V(i)}` : V(i), l = async (i, e = "", t, f = !1) => {
40
+ }, _ = ["Webkit", "Moz", "ms", "O"], q = (i) => i.startsWith("-") ? i : _.some((e) => i.startsWith(e)) ? `-${V(i)}` : V(i), h = async (i, e = "", t, f = !1) => {
41
41
  if (!i) throw new Error("No styles provided to parseStyles function!");
42
- const n = /* @__PURE__ */ new Set(), b = Object.entries(i).map(async ([$, s]) => {
42
+ const n = /* @__PURE__ */ new Set(), b = Object.entries(i).map(async ([u, s]) => {
43
43
  var w;
44
- const r = $.trim(), h = q(r), c = (a, d = ";") => `${h}:${a}${d}`;
44
+ const r = u.trim(), $ = q(r), c = (a, d = ";") => `${$}:${a}${d}`;
45
45
  if (typeof s == "function" && (s = s({ scope: e, config: t })), s instanceof Promise && (s = await s), t != null && t.templates && t.templatePaths[r]) {
46
46
  const { default: a } = await import(t.templatePaths[r]);
47
47
  if (typeof a.params[r] == "function") {
48
- const d = await a.params[r](s), [o] = await l(d, "");
48
+ const d = await a.params[r](s), [o] = await h(d, "");
49
49
  return o;
50
50
  }
51
51
  }
@@ -53,7 +53,7 @@ const A = (i) => (e) => {
53
53
  if (f) return;
54
54
  const d = s.split(".").reduce((o, p) => o[p], t.templates[r]);
55
55
  if (d) {
56
- const [o] = await l(d, "");
56
+ const [o] = await h(d, "");
57
57
  return o;
58
58
  }
59
59
  console.warn(`Template "${r}" with path of "${s}" was not found in config!`);
@@ -65,46 +65,46 @@ const A = (i) => (e) => {
65
65
  if (r === "defaultVariants") return;
66
66
  if (r === "variants") {
67
67
  const o = Object.entries(s);
68
- for (const [p, u] of o) {
69
- if (!u) return;
70
- const C = Object.entries(u);
71
- for (const [W, m] of C) {
72
- if (!m) return;
73
- const T = `${e}.${p}-${W}`;
74
- (await l(m, T, t)).forEach((U) => n.add(U));
68
+ for (const [p, m] of o) {
69
+ if (!m) return;
70
+ const C = Object.entries(m);
71
+ for (const [A, l] of C) {
72
+ if (!l) return;
73
+ const T = `${e}.${p}-${A}`;
74
+ (await h(l, T, t)).forEach((S) => n.add(S));
75
75
  }
76
76
  }
77
77
  return;
78
78
  }
79
79
  if (r === "compoundVariants") {
80
80
  for (const o of s) {
81
- const { css: p, ...u } = o, C = Object.entries(u).reduce((m, [T, N]) => `${m}.${T}-${N}`, e);
82
- (await l(p, C, t)).forEach((m) => n.add(m));
81
+ const { css: p, ...m } = o, C = Object.entries(m).reduce((l, [T, N]) => `${l}.${T}-${N}`, e);
82
+ (await h(p, C, t)).forEach((l) => n.add(l));
83
83
  }
84
84
  return;
85
85
  }
86
86
  if (r.startsWith("@")) {
87
- const o = ((w = t == null ? void 0 : t.mediaQueries) == null ? void 0 : w[r]) || r, p = await k(s, e, t), u = `${o} { ${p} }`;
88
- n.add(u);
87
+ const o = ((w = t == null ? void 0 : t.mediaQueries) == null ? void 0 : w[r]) || r, p = await k(s, e, t), m = `${o} { ${p} }`;
88
+ n.add(m);
89
89
  return;
90
90
  }
91
- const a = $.includes("&") ? r.replace("&", e) : r.startsWith(":") ? `${e}${r}` : `${e} ${r}`;
92
- (await l(s, a, t)).forEach((o) => n.add(o));
91
+ const a = u.includes("&") ? r.replace("&", e) : r.startsWith(":") ? `${e}${r}` : `${e} ${r}`;
92
+ (await h(s, a, t)).forEach((o) => n.add(o));
93
93
  return;
94
94
  }
95
95
  if (typeof s == "number") {
96
- const a = Q(h, s, t);
96
+ const a = Q($, s, t);
97
97
  return c(a);
98
98
  }
99
99
  if (typeof s != "string")
100
100
  if ("toString" in s) s = s.toString();
101
- else throw new Error(`Invalid value type for property ${h}`);
101
+ else throw new Error(`Invalid value type for property ${$}`);
102
102
  return c(s);
103
- }), { modifiers: P } = t || {}, j = [z(), A(P)], x = (await Promise.all(b).then(($) => Promise.all(
104
- $.map((s) => j.reduce(async (r, h) => {
103
+ }), { modifiers: P } = t || {}, E = [z(), U(P)], x = (await Promise.all(b).then((u) => Promise.all(
104
+ u.map((s) => E.reduce(async (r, $) => {
105
105
  const c = await r;
106
106
  if (!c) return c;
107
- const O = await h(c);
107
+ const O = await $(c);
108
108
  if (!O) return c;
109
109
  const { transformed: w, additionalCss: a } = O;
110
110
  let d = "";
@@ -113,14 +113,16 @@ const A = (i) => (e) => {
113
113
  d += await k(o, "");
114
114
  return `${d}${w}`;
115
115
  }, Promise.resolve(s)))
116
- ))).join(`
117
- `);
118
- if (!x.trim()) return n;
119
- const S = e ? `${e} { ${x} }` : x;
120
- return n.add(S), n;
121
- }, k = async (i, e, t, f = !1) => [...await l(i, e, t, f)].join(`
116
+ ))).filter((u) => u !== void 0).join(`
117
+ `);
118
+ if (!x.trim()) return Array.from(n);
119
+ const W = e ? `${e} {
120
+ ${x}
121
+ }` : x;
122
+ return n.has(W) ? Array.from(n) : [W, ...n];
123
+ }, k = async (i, e, t, f = !1) => (await h(i, e, t, f)).join(`
122
124
  `);
123
125
  export {
124
- I as a,
126
+ J as a,
125
127
  k as p
126
128
  };
@@ -0,0 +1,5 @@
1
+ "use strict";const V=require("./dash-case-BJEkFEGQ.cjs"),U=a=>e=>{if(typeof e!="string"||!a)return;let t=e;const f=[];return Object.values(a).forEach(n=>{const{pattern:y,transform:b}=n;t=t.replace(y,P=>{const{value:E,css:j}=b(P);return j&&f.push(j),E})}),{transformed:t,additionalCss:f}},S=a=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V.dashCase(n[1].replaceAll(".","-"))})`)},q=S(),J=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],M=(a,e,t)=>{if(J.some(n=>typeof n=="string"?n===a:n.test(a))){const n=(t==null?void 0:t.defaultUnit)||"px";return`${e}${n}`}return`${e}`},Q=["Webkit","Moz","ms","O"],_=a=>a.startsWith("-")?a:Q.some(e=>a.startsWith(e))?`-${V.dashCase(a)}`:V.dashCase(a),h=async(a,e="",t,f=!1)=>{if(!a)throw new Error("No styles provided to parseStyles function!");const n=new Set,b=Object.entries(a).map(async([p,s])=>{var w;const r=p.trim(),$=_(r),c=(o,d=";")=>`${$}:${o}${d}`;if(typeof s=="function"&&(s=s({scope:e,config:t})),s instanceof Promise&&(s=await s),t!=null&&t.templates&&t.templatePaths[r]){const{default:o}=await import(t.templatePaths[r]);if(typeof o.params[r]=="function"){const d=await o.params[r](s),[i]=await h(d,"");return i}}if(t!=null&&t.templates&&t.templates[r]){if(f)return;const d=s.split(".").reduce((i,u)=>i[u],t.templates[r]);if(d){const[i]=await h(d,"");return i}console.warn(`Template "${r}" with path of "${s}" was not found in config!`);return}if(typeof s=="object"){if(!s)return;if(s.isColor)return c(s.toString());if(r==="defaultVariants")return;if(r==="variants"){const i=Object.entries(s);for(const[u,l]of i){if(!l)return;const O=Object.entries(l);for(const[k,m]of O){if(!m)return;const T=`${e}.${u}-${k}`;(await h(m,T,t)).forEach(z=>n.add(z))}}return}if(r==="compoundVariants"){for(const i of s){const{css:u,...l}=i,O=Object.entries(l).reduce((m,[T,N])=>`${m}.${T}-${N}`,e);(await h(u,O,t)).forEach(m=>n.add(m))}return}if(r.startsWith("@")){const i=((w=t==null?void 0:t.mediaQueries)==null?void 0:w[r])||r,u=await A(s,e,t),l=`${i} { ${u} }`;n.add(l);return}const o=p.includes("&")?r.replace("&",e):r.startsWith(":")?`${e}${r}`:`${e} ${r}`;(await h(s,o,t)).forEach(i=>n.add(i));return}if(typeof s=="number"){const o=M($,s,t);return c(o)}if(typeof s!="string")if("toString"in s)s=s.toString();else throw new Error(`Invalid value type for property ${$}`);return c(s)}),{modifiers:P}=t||{},E=[S(),U(P)],C=(await Promise.all(b).then(p=>Promise.all(p.map(s=>E.reduce(async(r,$)=>{const c=await r;if(!c)return c;const x=await $(c);if(!x)return c;const{transformed:w,additionalCss:o}=x;let d="";if(o)for(const i of o)d+=await A(i,"");return`${d}${w}`},Promise.resolve(s)))))).filter(p=>p!==void 0).join(`
2
+ `);if(!C.trim())return Array.from(n);const W=e?`${e} {
3
+ ${C}
4
+ }`:C;return n.has(W)?Array.from(n):[W,...n]},A=async(a,e,t,f=!1)=>(await h(a,e,t,f)).join(`
5
+ `);exports.parseAndJoinStyles=A;exports.parseVariableTokens=q;
@@ -9,5 +9,5 @@ import { CachedConfig, SaltyConfig } from '../types/config-types';
9
9
  * - First item is the main class with all the styles
10
10
  * - Rest of the items are child selectors or media queries etc.
11
11
  */
12
- export declare const parseStyles: <T extends object>(styles?: T, currentScope?: string, config?: (SaltyConfig & CachedConfig) | undefined, omitTemplates?: boolean) => Promise<Set<string>>;
12
+ export declare const parseStyles: <T extends object>(styles?: T, currentScope?: string, config?: (SaltyConfig & CachedConfig) | undefined, omitTemplates?: boolean) => Promise<string[]>;
13
13
  export declare const parseAndJoinStyles: <T extends object>(styles: T, currentClass: string, config?: (SaltyConfig & CachedConfig) | undefined, omitTemplates?: boolean) => Promise<string>;
package/server/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-BwBIR0y8.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-BeL1bijz.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
package/server/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile as r } from "fs/promises";
2
- import { i as e } from "../index-ED4VBH54.js";
2
+ import { i as e } from "../index-BUuBd_-i.js";
3
3
  const f = async (t) => {
4
4
  if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
5
5
  if (t.includes("salty.config")) return !0;
@@ -1,38 +0,0 @@
1
- "use strict";const Ce=require("esbuild"),xe=require("child_process"),P=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),a=require("fs"),oe=require("fs/promises"),X=require("./parse-styles-DKWtadpv.cjs"),B=require("winston"),M=require("./css/merge.cjs");var ne=typeof document<"u"?document.currentScript:null;function Ne(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 de=Ne(Ce),pe=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(),d=await pe(i,[...t,c]);s.push(d)}else n[o]=i;if(Object.keys(n).length){const o=t.map(P.dashCase).join("-"),i="t_"+P.toHash(o,4),c=await X.parseAndJoinStyles(n,`.${o}, .${i}`);s.push(c)}return s.join(`
2
- `)},ke=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=ye(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},ye=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?ye(o,i,s):s.add(t)}),[...s]):[],me=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return a.existsSync(t)?t:me(r.join(e,".."))},Pe=async e=>{const t=me(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},De=async e=>{const t=await Pe(e);if(t)return t.type};let z;const ge=async e=>{if(z)return z;const t=await De(e);return t==="module"?z="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-BwBIR0y8.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),_e=e=>{G.error(e)};function he(e){return e?typeof e!="string"?he(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 Oe={"*, *::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"}},V={externalModules:[],rcFile:void 0,destDir:void 0},Se=e=>{if(V.externalModules.length>0)return V.externalModules;const s=a.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await re(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},ie=["salty","css","styles","styled"],je=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),Y=(e,t=[])=>je(t).test(e),we=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=r.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):we(r.join(e,".."))},re=async e=>{var n,o;const t=await we(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))},Te=async e=>{const t=await re(e),s=await v(e),n=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=r.join(s,"salty.config.js"),i=await ge(e),c=Se(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:c});const d=Date.now(),{config:y}=await import(`${o}?t=${d}`);return y},be=async(e,t)=>{var ce,le;const s=await v(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async h=>{const{contents:F,outputFilePath:R}=await K(e,h,s);Object.entries(F).forEach(([k,_])=>{_.isMedia?n.mediaQueries.push([k,_]):_.isGlobalDefine?n.globalStyles.push(_):_.isDefineVariables?n.variables.push(_):_.isDefineTemplates&&n.templates.push(_._setPath(R))})}));const o=await Te(e),i={...o},c=new Set,d=(h,F=[])=>h?Object.entries(h).flatMap(([R,k])=>{if(!k)return;if(typeof k=="object")return d(k,[...F,R]);const _=he(R),te=P.dashCase(R),se=[...F,_].join(".");c.add(`"${se}"`);const U=[...F.map(P.dashCase),te].join("-"),fe=X.parseVariableTokens(k);return fe?`--${U}: ${fe.transformed};`:`--${U}: ${k};`}):[],y=h=>h?Object.entries(h).flatMap(([F,R])=>{const k=d(R);return F==="base"?k.join(""):`${F} { ${k.join("")} }`}):[],u=h=>h?Object.entries(h).flatMap(([F,R])=>Object.entries(R).flatMap(([k,_])=>{const te=d(_,[F]),se=`.${F}-${k}, [data-${F}="${k}"]`,U=te.join("");return`${se} { ${U} }`})):[],p=h=>({...h,responsive:void 0,conditional:void 0}),m=h=>n.variables.map(F=>h==="static"?p(F._current):F._current[h]),S=M.mergeObjects(p(o.variables),m("static")),w=d(S),g=M.mergeObjects((ce=o.variables)==null?void 0:ce.responsive,m("responsive")),x=y(g),N=M.mergeObjects((le=o.variables)==null?void 0:le.conditional,m("conditional")),O=u(N),J=r.join(s,"css/_variables.css"),T=`:root { ${w.join("")} ${x.join("")} } ${O.join("")}`;a.writeFileSync(J,T),i.staticVariables=S;const H=r.join(s,"css/_global.css"),D=M.mergeObjects(o.global,n.globalStyles),q=await X.parseAndJoinStyles(D,"");a.writeFileSync(H,`@layer global { ${q} }`);const l=r.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Oe,f=await X.parseAndJoinStyles(b,"");a.writeFileSync(l,`@layer reset { ${f} }`);const $=r.join(s,"css/_templates.css"),C=M.mergeObjects(o.templates,n.templates),E=await pe(C),I=ke(C);a.writeFileSync($,`@layer templates { ${E} }`),i.templates=C;const W=M.mergeFactories(n.templates);i.templatePaths=Object.fromEntries(Object.entries(W).map(([h,F])=>[h,F._path]));const{mediaQueries:A}=n;i.mediaQueries=Object.fromEntries(A.map(([h,F])=>[`@${h}`,F]));const L=A.map(([h])=>`'@${h}'`).join(" | "),ee=r.join(s,"types/css-tokens.d.ts"),Z=`
3
- // Variable types
4
- type VariableTokens = ${[...c].join("|")};
5
- type PropertyValueToken = \`{\${VariableTokens}}\`;
6
-
7
- // Template types
8
- type TemplateTokens = {
9
- ${Object.entries(I).map(([h,F])=>`${h}?: ${F}`).join(`
10
- `)}
11
- }
12
-
13
- // Media query types
14
- type MediaQueryKeys = ${L||"''"};
15
- `;a.writeFileSync(ee,Z);const $e=r.join(s,"cache/config-cache.json");a.writeFileSync($e,JSON.stringify(i,null,2))},ue=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 d=c.at(1);if(ie.some(u=>d==null?void 0:d.includes(u)))return t}return"styled('div',"}),Ee=(e,t)=>{try{const s=a.readFileSync(r.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
16
-
17
- ${e}`:`globalThis.saltyConfig = {};
18
-
19
- ${e}`}catch{return e}},K=async(e,t,s)=>{const n=P.toHash(t),o=r.join(s,"./temp");a.existsSync(o)||a.mkdirSync(o);const i=r.parse(t);let c=a.readFileSync(t,"utf8");c=ue(c),c=Ee(c,e);const d=r.join(s,"js",n+".js"),y=await re(e),u=r.join(e,(y==null?void 0:y.configDir)||"","salty.config.ts"),p=Se(u),m=await ge(e);await de.build({stdin:{contents:c,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:m,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:g=>{g.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},x=>{const N=a.readFileSync(x.path,"utf8");return{contents:ue(N),loader:"ts"}})}}]});const S=Date.now();return{contents:await import(`${d}?t=${S}`),outputFilePath:d}},Re=async e=>{const t=await v(e),s=r.join(t,"cache/config-cache.json"),n=a.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await v(e),n=r.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return M.mergeObjects(i,t)},Fe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ve=async(e,t=Fe(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const o=[],i=[],c=await v(e),d=r.join(c,"index.css");s&&(()=>{a.existsSync(c)&&xe.execSync("rm -rf "+c),a.mkdirSync(c,{recursive:!0}),a.mkdirSync(r.join(c,"css")),a.mkdirSync(r.join(c,"types")),a.mkdirSync(r.join(c,"js")),a.mkdirSync(r.join(c,"cache"))})();const u=new Set,p=new Set;async function m(l){const j=["node_modules","saltygen"],b=a.statSync(l);if(b.isDirectory()){const f=a.readdirSync(l);if(j.some(C=>l.includes(C)))return;await Promise.all(f.map(C=>m(r.join(l,C))))}else if(b.isFile()&&Y(l)){u.add(l);const $=a.readFileSync(l,"utf8");/define[\w\d]+\(/.test($)&&p.add(l)}}await m(e),await be(e,p);const S={keyframes:[],components:[],classNames:[]};await Promise.all([...u].map(async l=>{const{contents:j}=await K(e,l,c);Object.entries(j).forEach(([b,f])=>{f.isKeyframes?S.keyframes.push({value:f,src:l,name:b}):f.isClassName?S.classNames.push({...f,src:l,name:b}):f.generator&&S.components.push({...f,src:l,name:b})})}));const w=await ae(e);for(const l of S.keyframes){const{value:j}=l,b=`a_${j.animationName}.css`,f=`css/${b}`,$=r.join(c,f);o.push(b),a.writeFileSync($,j.css)}const g={};for(const l of S.components){const{src:j,name:b}=l,f=l.generator._withBuildContext({callerName:b,isProduction:t,config:w});i[f.priority]||(i[f.priority]=[]);const $=await f.css;if(!$)continue;i[f.priority].push(f.cssFileName);const C=`css/${f.cssFileName}`,E=r.join(c,C);a.writeFileSync(E,$),w.importStrategy==="component"&&(g[j]?g[j].push(f.cssFileName):g[j]=[f.cssFileName])}for(const l of S.classNames){const{src:j,name:b}=l,f=l.generator._withBuildContext({callerName:b,isProduction:t,config:w}),$=await f.css;if(!$)continue;i[0].push(f.cssFileName);const C=`css/${f.cssFileName}`,E=r.join(c,C);a.writeFileSync(E,$),w.importStrategy==="component"&&(g[j]?g[j].push(f.cssFileName):g[j]=[f.cssFileName])}w.importStrategy==="component"&&Object.entries(g).forEach(([l,j])=>{const b=j.map(I=>`@import url('./${I}');`).join(`
20
- `),f=P.toHash(l,6),$=r.parse(l),C=P.dashCase($.name),E=r.join(c,`css/f_${C}-${f}.css`);a.writeFileSync(E,b)});const x=o.map(l=>`@import url('./css/${l}');`).join(`
21
- `);let T=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
22
-
23
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return a.readFileSync(r.join(c,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
24
- `)}
25
- ${x}`;if(w.importStrategy!=="component"){const l=i.reduce((j,b,f)=>{const $=b.reduce((W,A)=>{var Z;const L=r.join(c,"css",A),ee=a.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:Z.at(1))||P.toHash(L,6);return W.includes(Q)?W:`${W}
26
- /*start:${Q}*/
27
- ${ee}
28
- /*end:${Q}*/
29
- `},""),C=`l_${f}.css`,E=r.join(c,"css",C),I=`@layer l${f} { ${$}
30
- }`;return a.writeFileSync(E,I),`${j}
31
- @import url('./css/${C}');`},"");T+=l}a.writeFileSync(d,T);const D=Date.now()-n,q=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";G.info(`Generated CSS in ${D}ms! ${q}`)}catch(n){console.error(n)}},Me=async(e,t)=>{try{const s=await v(e);if(Y(t)){const o=[],i=await ae(e),{contents:c}=await K(e,t,s);for(const[d,y]of Object.entries(c)){if(y.isKeyframes&&y.css){const g=`css/${`a_${y.animationName}.css`}`,x=r.join(s,g);a.writeFileSync(x,await y.css);return}if(y.isClassName){const w=y.generator._withBuildContext({name:d}),g=await w.css;if(!g)continue;o[0].push(w.cssFileName);const x=`css/${w.cssFileName}`,N=r.join(s,x);a.writeFileSync(N,g)}if(!y.generator)return;const u=y.generator._withBuildContext({name:d,config:i}),p=await u.css;if(!p)continue;const m=`css/${u.cssFileName}`,S=r.join(s,m);a.writeFileSync(S,p),o[u.priority]||(o[u.priority]=[]),o[u.priority].push(u.cssFileName)}if(i.importStrategy!=="component")o.forEach((d,y)=>{const u=`l_${y}.css`,p=r.join(s,"css",u);let m=a.readFileSync(p,"utf8");d.forEach(S=>{var N;const w=r.join(s,"css",S),g=((N=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:N.at(1))||P.toHash(w,6);if(!m.includes(g)){const O=a.readFileSync(w,"utf8"),J=`/*start:${g}*/
32
- ${O}
33
- /*end:${g}*/
34
- `;m=`${m.replace(/\}$/,"")}
35
- ${J}
36
- }`}}),a.writeFileSync(p,m)});else{const d=o.flat().map(S=>`@import url('./${S}');`).join(`
37
- `),y=P.toHash(t,6),u=r.parse(t),p=P.dashCase(u.name),m=r.join(s,`css/f_${p}-${y}.css`);a.writeFileSync(m,d)}}}catch(s){console.error(s)}},ve=async(e,t,s=Fe())=>{try{const n=await v(e);if(Y(t)){const i=a.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==i&&await oe.writeFile(t,i);const d=await ae(e),{contents:y}=await K(e,t,n);let u=i;if(Object.entries(y).forEach(([p,m])=>{var f;if(m.isKeyframes||!m.generator)return;const S=m.generator._withBuildContext({name:p,config:d,prod:s}),w=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!w)return console.error("Could not find the original declaration");const g=(f=w.at(1))==null?void 0:f.trim(),x=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(u);if(!x)return console.error("Could not find the original declaration");const{index:N}=x;let O=!1;const J=setTimeout(()=>O=!0,5e3);let T=0,H=!1,D=0;for(;!H&&!O;){const $=u[N+T];$==="("&&D++,$===")"&&D--,D===0&&$===")"&&(H=!0),T>u.length&&(O=!0),T++}if(!O)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const q=N+T,l=u.slice(N,q),j=u,b=` ${p} = styled(${g}, "${S.classNames}", ${JSON.stringify(S.clientProps)});`;u=u.replace(l,b),j===u&&console.error("Minimize file failed to change content",{name:p,tagName:g})}),d.importStrategy==="component"){const p=P.toHash(t,6),m=r.parse(t);u=`import '../../saltygen/css/${`f_${P.dashCase(m.name)}-${p}.css`}';
38
- ${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=K;exports.generateConfigStyles=be;exports.generateCss=Ve;exports.generateFile=Me;exports.isSaltyFile=Y;exports.logError=_e;exports.logger=G;exports.minimizeFile=ve;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=je;