@salty-css/core 0.0.1-alpha.217 → 0.0.1-alpha.218

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-B6M9WK93.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-BPohv4BZ.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
package/bin/main.js CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
3
3
  import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
4
4
  import { join as i, relative as z, parse as re, format as ee } from "path";
5
5
  import { render as ce } from "ejs";
6
- import { l as t, a as h, g as te } from "../index-B_bv7TCc.js";
6
+ import { l as t, a as h, g as te } from "../index-DVSBEd3f.js";
7
7
  import { p as le } from "../pascal-case-BQpR5PdN.js";
8
8
  import { exec as de } from "child_process";
9
9
  import fe from "ora";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-C6OYNcYI.cjs");const e=require("../index-B6M9WK93.cjs");require("../css/merge.cjs");require("../define-templates-Cunsb_Tr.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-C6OYNcYI.cjs");const e=require("../index-BPohv4BZ.cjs");require("../css/merge.cjs");require("../define-templates-Cunsb_Tr.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
package/compiler/index.js CHANGED
@@ -5,7 +5,7 @@ import "path";
5
5
  import "fs";
6
6
  import "fs/promises";
7
7
  import "../parse-styles-Cc_Ir3PV.js";
8
- import { d as g, c as F, g as y, e as x, i as S, m as c, s as f, b as C } from "../index-B_bv7TCc.js";
8
+ import { d as g, c as F, g as y, e as x, i as S, m as c, s as f, b as C } from "../index-DVSBEd3f.js";
9
9
  import "../css/merge.js";
10
10
  import "../define-templates-4A2yHcMF.js";
11
11
  export {
@@ -0,0 +1,38 @@
1
+ "use strict";const xe=require("esbuild"),Pe=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),a=require("path"),c=require("fs"),oe=require("fs/promises"),Y=require("./parse-styles-C6OYNcYI.cjs"),G=require("winston"),M=require("./css/merge.cjs"),Ne=require("./define-templates-Cunsb_Tr.cjs");var ne=typeof document<"u"?document.currentScript:null;function ke(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=ke(xe),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[i,o]of Object.entries(e))if(typeof o!="function")if(o&&typeof o=="object"){const r=i.trim(),S=await ye(o,[...t,r]);s.push(S)}else n[i]=o;if(Object.keys(n).length){const i=t.map(_.dashCase).join("-"),o="t_"+_.toHash(i,4),r=await Y.parseAndJoinStyles(n,`.${i}, .${o}`);s.push(r)}return s.join(`
2
+ `)},_e=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const o=t?`${t}.${n}`:n;return typeof i=="object"?me(i,o,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return c.existsSync(t)?t:ge(a.join(e,".."))},De=async e=>{const t=ge(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Oe=async e=>{const t=await De(e);if(t)return t.type};let z;const he=async e=>{if(z)return z;const t=await Oe(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-BPohv4BZ.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},K=G.createLogger({level:"debug",format:G.format.combine(G.format.colorize(),G.format.cli()),transports:[new G.transports.Console({})]}),Te=e=>{K.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 Ee={"*, *::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(i=>i.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await re(e),s=a.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("|")})\\.`),ee=(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=a.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):be(a.join(e,".."))},re=async e=>{var n,i;const t=await be(e),s=(n=t.projects)==null?void 0:n.find(o=>e.endsWith(o.dir||""));return s||((i=t.projects)==null?void 0:i.find(o=>o.dir===t.defaultProject))},Re=async e=>{const t=await re(e),s=await v(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=a.join(s,"salty.config.js"),o=await he(e),r=je(n);await pe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:o,external:r});const S=Date.now(),{config:j}=await import(`${i}?t=${S}`);return{config:j,path:i}},$e=async(e,t)=>{var le,fe;const s=await v(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async g=>{const{contents:b,outputFilePath:R}=await L(e,g,s);Object.entries(b).forEach(([P,O])=>{O.isMedia?n.mediaQueries.push([P,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(`${P};;${R}`))})}));const{config:i,path:o}=await Re(e),r={...i},S=new Set,j=(g,b=[])=>g?Object.entries(g).flatMap(([R,P])=>{if(!P)return;if(typeof P=="object")return j(P,[...b,R]);const O=Se(R),te=_.dashCase(R),se=[...b,O].join(".");S.add(`"${se}"`);const X=[...b.map(_.dashCase),te].join("-"),ue=Y.parseVariableTokens(P);return ue?`--${X}: ${ue.transformed};`:`--${X}: ${P};`}):[],l=g=>g?Object.entries(g).flatMap(([b,R])=>{const P=j(R);return b==="base"?P.join(""):`${b} { ${P.join("")} }`}):[],d=g=>g?Object.entries(g).flatMap(([b,R])=>Object.entries(R).flatMap(([P,O])=>{const te=j(O,[b]),se=`.${b}-${P}, [data-${b}="${P}"]`,X=te.join("");return`${se} { ${X} }`})):[],w=g=>({...g,responsive:void 0,conditional:void 0}),p=g=>n.variables.map(b=>g==="static"?w(b._current):b._current[g]),h=M.mergeObjects(w(i.variables),p("static")),y=j(h),C=M.mergeObjects((le=i.variables)==null?void 0:le.responsive,p("responsive")),N=l(C),k=M.mergeObjects((fe=i.variables)==null?void 0:fe.conditional,p("conditional")),J=d(k),T=a.join(s,"css/_variables.css"),H=`:root { ${y.join("")} ${N.join("")} } ${J.join("")}`;c.writeFileSync(T,H),r.staticVariables=h;const D=a.join(s,"css/_global.css"),q=M.mergeObjects(i.global,n.globalStyles),u=await Y.parseAndJoinStyles(q,"");c.writeFileSync(D,`@layer global { ${u} }`);const m=a.join(s,"css/_reset.css"),f=i.reset==="none"?{}:typeof i.reset=="object"?i.reset:Ee,F=await Y.parseAndJoinStyles(f,"");c.writeFileSync(m,`@layer reset { ${F} }`);const x=a.join(s,"css/_templates.css"),E=M.mergeObjects(i.templates,n.templates),I=await ye(E),W=_e(E);c.writeFileSync(x,`@layer templates { ${I} }`),r.templates=E;const A=i.templates?[Ne.defineTemplates(i.templates)._setPath(`config;;${o}`)]:[],Q=M.mergeFactories(n.templates,A);r.templatePaths=Object.fromEntries(Object.entries(Q).map(([g,b])=>[g,b._path]));const{mediaQueries:Z}=n;r.mediaQueries=Object.fromEntries(Z.map(([g,b])=>[`@${g}`,b]));const B=Z.map(([g])=>`'@${g}'`).join(" | "),U=a.join(s,"types/css-tokens.d.ts"),Fe=`
3
+ // Variable types
4
+ type VariableTokens = ${[...S].join("|")};
5
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
6
+
7
+ // Template types
8
+ type TemplateTokens = {
9
+ ${Object.entries(W).map(([g,b])=>`${g}?: ${b}`).join(`
10
+ `)}
11
+ }
12
+
13
+ // Media query types
14
+ type MediaQueryKeys = ${B||"''"};
15
+ `;c.writeFileSync(U,Fe);const Ce=a.join(s,"cache/config-cache.json");c.writeFileSync(Ce,JSON.stringify(r,null,2))},de=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const r=i.exec(e);if(r){const S=r.at(1);if(ie.some(l=>S==null?void 0:S.includes(l)))return t}return"styled('div',"}),Ve=(e,t)=>{try{const s=c.readFileSync(a.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
16
+
17
+ ${e}`:`globalThis.saltyConfig = {};
18
+
19
+ ${e}`}catch{return e}},L=async(e,t,s)=>{const n=_.toHash(t),i=a.join(s,"./temp");c.existsSync(i)||c.mkdirSync(i);const o=a.parse(t);let r=c.readFileSync(t,"utf8");r=de(r),r=Ve(r,e);const S=a.join(s,"js",n+".js"),j=await re(e),l=a.join(e,(j==null?void 0:j.configDir)||"","salty.config.ts"),d=je(l),w=await he(e);await pe.build({stdin:{contents:r,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:S,format:w,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:y=>{y.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(`${S}?t=${p}`),outputFilePath:S}},Me=async e=>{const t=await v(e),s=a.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 Me(e),s=await v(e),n=a.join(s,"salty.config.js"),i=Date.now(),{config:o}=await import(`${n}?t=${i}`);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?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const i=[],o=[],r=await v(e),S=a.join(r,"index.css");s&&(()=>{c.existsSync(r)&&Pe.execSync("rm -rf "+r),c.mkdirSync(r,{recursive:!0}),c.mkdirSync(a.join(r,"css")),c.mkdirSync(a.join(r,"types")),c.mkdirSync(a.join(r,"js")),c.mkdirSync(a.join(r,"cache"))})();const l=new Set,d=new Set;async function w(u){const m=["node_modules","saltygen"],$=c.statSync(u);if($.isDirectory()){const f=c.readdirSync(u);if(m.some(x=>u.includes(x)))return;await Promise.all(f.map(x=>w(a.join(u,x))))}else if($.isFile()&&ee(u)){l.add(u);const F=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(F)&&d.add(u)}}await w(e),await $e(e,d);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async u=>{const{contents:m}=await L(e,u,r);Object.entries(m).forEach(([$,f])=>{f.isKeyframes?p.keyframes.push({value:f,src:u,name:$}):f.isClassName?p.classNames.push({...f,src:u,name:$}):f.generator&&p.components.push({...f,src:u,name:$})})}));const h=await ae(e);for(const u of p.keyframes){const{value:m}=u,$=`a_${m.animationName}.css`,f=`css/${$}`,F=a.join(r,f);i.push($),c.writeFileSync(F,m.css)}const y={};for(const u of p.components){const{src:m,name:$}=u;y[m]||(y[m]=[]);const f=u.generator._withBuildContext({callerName:$,isProduction:t,config:h});o[f.priority]||(o[f.priority]=[]);const F=await f.css;if(!F)continue;o[f.priority].push(f.cssFileName);const x=`css/${f.cssFileName}`,E=a.join(r,x);c.writeFileSync(E,F),h.importStrategy==="component"&&y[m].push(f.cssFileName)}for(const u of p.classNames){const{src:m,name:$}=u;y[m]||(y[m]=[]);const f=u.generator._withBuildContext({callerName:$,isProduction:t,config:h}),F=await f.css;if(!F)continue;o[f.priority]||(o[f.priority]=[]),o[f.priority].push(f.cssFileName);const x=`css/${f.cssFileName}`,E=a.join(r,x);c.writeFileSync(E,F),h.importStrategy==="component"&&y[m].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(y).forEach(([u,m])=>{const $=m.map(I=>`@import url('./${I}');`).join(`
20
+ `),f=_.toHash(u,6),F=a.parse(u),x=_.dashCase(F.name),E=a.join(r,`css/f_${x}-${f}.css`);c.writeFileSync(E,$||"/* Empty file */")});const C=i.map(u=>`@import url('./css/${u}');`).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(u=>{try{return c.readFileSync(a.join(r,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
24
+ `)}
25
+ ${C}`;if(h.importStrategy!=="component"){const u=o.reduce((m,$,f)=>{const F=$.reduce((W,A)=>{var U;const Q=a.join(r,"css",A),Z=c.readFileSync(Q,"utf8"),B=((U=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:U.at(1))||_.toHash(Q,6);return W.includes(B)?W:`${W}
26
+ /*start:${B}-${A}*/
27
+ ${Z}
28
+ /*end:${B}*/
29
+ `},""),x=`l_${f}.css`,E=a.join(r,"css",x),I=`@layer l${f} { ${F}
30
+ }`;return c.writeFileSync(E,I),`${m}
31
+ @import url('./css/${x}');`},"");T+=u}c.writeFileSync(S,T);const D=Date.now()-n,q=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";K.info(`Generated CSS in ${D}ms! ${q}`)}catch(n){console.error(n)}},Je=async(e,t,s=ce())=>{try{const n=await v(e);if(ee(t)){const o=[],r=await ae(e),{contents:S}=await L(e,t,n);for(const[j,l]of Object.entries(S)){if(l.isKeyframes&&l.css){const C=`css/${`a_${l.animationName}.css`}`,N=a.join(n,C);c.writeFileSync(N,await l.css);return}if(l.isClassName){const y=l.generator._withBuildContext({callerName:j,isProduction:s,config:r}),C=await y.css;if(!C)continue;o[y.priority]||(o[y.priority]=[]),o[y.priority].push(y.cssFileName);const N=`css/${y.cssFileName}`,k=a.join(n,N);c.writeFileSync(k,C)}if(!l.generator)return;const d=l.generator._withBuildContext({callerName:j,isProduction:s,config:r}),w=await d.css;if(!w)continue;const p=`css/${d.cssFileName}`,h=a.join(n,p);c.writeFileSync(h,w),o[d.priority]||(o[d.priority]=[]),o[d.priority].push(d.cssFileName)}if(r.importStrategy!=="component")o.forEach((j,l)=>{const d=`l_${l}.css`,w=a.join(n,"css",d);let p=c.readFileSync(w,"utf8");j.forEach(h=>{var k;const y=a.join(n,"css",h),C=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||_.toHash(y,6);if(!p.includes(C)){const J=c.readFileSync(y,"utf8"),T=`/*start:${C}-${h}*/
32
+ ${J}
33
+ /*end:${C}*/
34
+ `;p=`${p.replace(/\}$/,"")}
35
+ ${T}
36
+ }`}}),c.writeFileSync(w,p)});else{const j=o.flat().map(h=>`@import url('./${h}');`).join(`
37
+ `),l=_.toHash(t,6),d=a.parse(t),w=_.dashCase(d.name),p=a.join(n,`css/f_${w}-${l}.css`);c.writeFileSync(p,j||"/* Empty file */")}}}catch(n){console.error(n)}},ze=async(e,t,s=ce())=>{try{const n=await v(e);if(ee(t)){const o=c.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==o&&await oe.writeFile(t,o);const S=await ae(e),{contents:j}=await L(e,t,n);let l=o;if(Object.entries(j).forEach(([d,w])=>{var f;if(w.isKeyframes||!w.generator)return;const p=w.generator._withBuildContext({callerName:d,isProduction:s,config:S}),h=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!h)return console.error("Could not find the original declaration");const y=(f=h.at(1))==null?void 0:f.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 k=!1;const J=setTimeout(()=>k=!0,5e3);let T=0,H=!1,D=0;for(;!H&&!k;){const F=l[N+T];F==="("&&D++,F===")"&&D--,D===0&&F===")"&&(H=!0),T>l.length&&(k=!0),T++}if(!k)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const q=N+T,u=l.slice(N,q),m=l,$=` ${d} = styled(${y}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;l=l.replace(u,$),m===l&&console.error("Minimize file failed to change content",{name:d,tagName:y})}),S.importStrategy==="component"){const d=_.toHash(t,6),w=a.parse(t);l=`import '../../saltygen/css/${`f_${_.dashCase(w.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=L;exports.generateConfigStyles=$e;exports.generateCss=ve;exports.generateFile=Je;exports.isSaltyFile=ee;exports.logError=Te;exports.logger=K;exports.minimizeFile=ze;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;
@@ -11,21 +11,21 @@ import { d as Mt } from "./define-templates-4A2yHcMF.js";
11
11
  const ht = async (t, e = []) => {
12
12
  if (!t) return "";
13
13
  const s = [], n = {};
14
- for (const [o, a] of Object.entries(t))
15
- if (typeof a != "function") if (a && typeof a == "object") {
16
- const i = o.trim(), h = await ht(a, [...e, i]);
14
+ for (const [a, o] of Object.entries(t))
15
+ if (typeof o != "function") if (o && typeof o == "object") {
16
+ const i = a.trim(), h = await ht(o, [...e, i]);
17
17
  s.push(h);
18
18
  } else
19
- n[o] = a;
19
+ n[a] = o;
20
20
  if (Object.keys(n).length) {
21
- const o = e.map(B).join("-"), a = "t_" + v(o, 4), i = await at(n, `.${o}, .${a}`);
21
+ const a = e.map(B).join("-"), o = "t_" + v(a, 4), i = await at(n, `.${a}, .${o}`);
22
22
  s.push(i);
23
23
  }
24
24
  return s.join(`
25
25
  `);
26
- }, vt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = $t(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, $t = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
27
- const a = e ? `${e}.${n}` : n;
28
- return typeof o == "object" ? $t(o, a, s) : s.add(e);
26
+ }, vt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = $t(n).map((a) => `"${a}"`).join(" | ")), e), {}) : {}, $t = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, a]) => {
27
+ const o = e ? `${e}.${n}` : n;
28
+ return typeof a == "object" ? $t(a, o, s) : s.add(e);
29
29
  }), [...s]) : [], bt = (t) => {
30
30
  if (!t || t === "/") throw new Error("Could not find package.json file");
31
31
  const e = r(t, "package.json");
@@ -108,7 +108,7 @@ const zt = {
108
108
  if (M.externalModules.length > 0) return M.externalModules;
109
109
  const s = O(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
110
110
  if (!s) return [];
111
- const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
111
+ const n = s[1].split(",").map((a) => a.replace(/['"`]/g, "").trim());
112
112
  return M.externalModules = n, n;
113
113
  }, R = async (t) => {
114
114
  if (M.destDir) return M.destDir;
@@ -121,22 +121,22 @@ const zt = {
121
121
  });
122
122
  return s ? (M.rcFile = s, s) : Ft(r(t, ".."));
123
123
  }, ct = async (t) => {
124
- var n, o;
125
- const e = await Ft(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
126
- return s || ((o = e.projects) == null ? void 0 : o.find((a) => a.dir === e.defaultProject));
124
+ var n, a;
125
+ const e = await Ft(t), s = (n = e.projects) == null ? void 0 : n.find((o) => t.endsWith(o.dir || ""));
126
+ return s || ((a = e.projects) == null ? void 0 : a.find((o) => o.dir === e.defaultProject));
127
127
  }, It = async (t) => {
128
- const e = await ct(t), s = await R(t), n = r(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = r(s, "salty.config.js"), a = await wt(t), i = Ct(n);
128
+ const e = await ct(t), s = await R(t), n = r(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), a = r(s, "salty.config.js"), o = await wt(t), i = Ct(n);
129
129
  await gt.build({
130
130
  entryPoints: [n],
131
131
  minify: !0,
132
132
  treeShaking: !0,
133
133
  bundle: !0,
134
- outfile: o,
135
- format: a,
134
+ outfile: a,
135
+ format: o,
136
136
  external: i
137
137
  });
138
- const h = Date.now(), { config: $ } = await import(`${o}?t=${h}`);
139
- return { config: $, path: o };
138
+ const h = Date.now(), { config: $ } = await import(`${a}?t=${h}`);
139
+ return { config: $, path: a };
140
140
  }, Bt = async (t, e) => {
141
141
  var pt, ut;
142
142
  const s = await R(t), n = {
@@ -146,46 +146,46 @@ const zt = {
146
146
  templates: []
147
147
  };
148
148
  await Promise.all(
149
- [...e].map(async (m) => {
150
- const { contents: w, outputFilePath: V } = await et(t, m, s);
149
+ [...e].map(async (g) => {
150
+ const { contents: w, outputFilePath: V } = await et(t, g, s);
151
151
  Object.entries(w).forEach(([N, _]) => {
152
152
  _.isMedia ? n.mediaQueries.push([N, _]) : _.isGlobalDefine ? n.globalStyles.push(_) : _.isDefineVariables ? n.variables.push(_) : _.isDefineTemplates && n.templates.push(_._setPath(`${N};;${V}`));
153
153
  });
154
154
  })
155
155
  );
156
- const { config: o, path: a } = await It(t), i = { ...o }, h = /* @__PURE__ */ new Set(), $ = (m, w = []) => m ? Object.entries(m).flatMap(([V, N]) => {
156
+ const { config: a, path: o } = await It(t), i = { ...a }, h = /* @__PURE__ */ new Set(), $ = (g, w = []) => g ? Object.entries(g).flatMap(([V, N]) => {
157
157
  if (!N) return;
158
158
  if (typeof N == "object") return $(N, [...w, V]);
159
159
  const _ = St(V), st = B(V), nt = [...w, _].join(".");
160
160
  h.add(`"${nt}"`);
161
161
  const X = [...w.map(B), st].join("-"), dt = Tt(N);
162
162
  return dt ? `--${X}: ${dt.transformed};` : `--${X}: ${N};`;
163
- }) : [], c = (m) => m ? Object.entries(m).flatMap(([w, V]) => {
163
+ }) : [], c = (g) => g ? Object.entries(g).flatMap(([w, V]) => {
164
164
  const N = $(V);
165
165
  return w === "base" ? N.join("") : `${w} { ${N.join("")} }`;
166
- }) : [], p = (m) => m ? Object.entries(m).flatMap(([w, V]) => Object.entries(V).flatMap(([N, _]) => {
166
+ }) : [], p = (g) => g ? Object.entries(g).flatMap(([w, V]) => Object.entries(V).flatMap(([N, _]) => {
167
167
  const st = $(_, [w]), nt = `.${w}-${N}, [data-${w}="${N}"]`, X = st.join("");
168
168
  return `${nt} { ${X} }`;
169
- })) : [], b = (m) => ({ ...m, responsive: void 0, conditional: void 0 }), u = (m) => n.variables.map((w) => m === "static" ? b(w._current) : w._current[m]), g = I(b(o.variables), u("static")), y = $(g), j = I((pt = o.variables) == null ? void 0 : pt.responsive, u("responsive")), P = c(j), k = I((ut = o.variables) == null ? void 0 : ut.conditional, u("conditional")), J = p(k), T = r(s, "css/_variables.css"), G = `:root { ${y.join("")} ${P.join("")} } ${J.join("")}`;
170
- F(T, G), i.staticVariables = g;
171
- const D = r(s, "css/_global.css"), H = I(o.global, n.globalStyles), l = await at(H, "");
172
- F(D, `@layer global { ${l} }`);
173
- const d = r(s, "css/_reset.css"), f = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : zt, C = await at(f, "");
174
- F(d, `@layer reset { ${C} }`);
175
- const x = r(s, "css/_templates.css"), E = I(o.templates, n.templates), K = await ht(E), A = vt(E);
169
+ })) : [], b = (g) => ({ ...g, responsive: void 0, conditional: void 0 }), u = (g) => n.variables.map((w) => g === "static" ? b(w._current) : w._current[g]), y = I(b(a.variables), u("static")), d = $(y), j = I((pt = a.variables) == null ? void 0 : pt.responsive, u("responsive")), P = c(j), k = I((ut = a.variables) == null ? void 0 : ut.conditional, u("conditional")), J = p(k), T = r(s, "css/_variables.css"), G = `:root { ${d.join("")} ${P.join("")} } ${J.join("")}`;
170
+ F(T, G), i.staticVariables = y;
171
+ const D = r(s, "css/_global.css"), H = I(a.global, n.globalStyles), f = await at(H, "");
172
+ F(D, `@layer global { ${f} }`);
173
+ const m = r(s, "css/_reset.css"), l = a.reset === "none" ? {} : typeof a.reset == "object" ? a.reset : zt, C = await at(l, "");
174
+ F(m, `@layer reset { ${C} }`);
175
+ const x = r(s, "css/_templates.css"), E = I(a.templates, n.templates), K = await ht(E), A = vt(E);
176
176
  F(x, `@layer templates { ${K} }`), i.templates = E;
177
- const L = o.templates ? [Mt(o.templates)._setPath(`config;;${a}`)] : [], Z = Vt(n.templates, L);
178
- i.templatePaths = Object.fromEntries(Object.entries(Z).map(([m, w]) => [m, w._path]));
177
+ const L = a.templates ? [Mt(a.templates)._setPath(`config;;${o}`)] : [], Z = Vt(n.templates, L);
178
+ i.templatePaths = Object.fromEntries(Object.entries(Z).map(([g, w]) => [g, w._path]));
179
179
  const { mediaQueries: q } = n;
180
- i.mediaQueries = Object.fromEntries(q.map(([m, w]) => [`@${m}`, w]));
181
- const Q = q.map(([m]) => `'@${m}'`).join(" | "), U = r(s, "types/css-tokens.d.ts"), xt = `
180
+ i.mediaQueries = Object.fromEntries(q.map(([g, w]) => [`@${g}`, w]));
181
+ const Q = q.map(([g]) => `'@${g}'`).join(" | "), U = r(s, "types/css-tokens.d.ts"), xt = `
182
182
  // Variable types
183
183
  type VariableTokens = ${[...h].join("|")};
184
184
  type PropertyValueToken = \`{\${VariableTokens}}\`;
185
185
 
186
186
  // Template types
187
187
  type TemplateTokens = {
188
- ${Object.entries(A).map(([m, w]) => `${m}?: ${w}`).join(`
188
+ ${Object.entries(A).map(([g, w]) => `${g}?: ${w}`).join(`
189
189
  `)}
190
190
  }
191
191
 
@@ -197,9 +197,9 @@ const zt = {
197
197
  F(Nt, JSON.stringify(i, null, 2));
198
198
  }, mt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
199
199
  if (/^['"`]/.test(s)) return e;
200
- const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
201
- if (!o.test(t)) return e;
202
- const i = o.exec(t);
200
+ const a = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
201
+ if (!a.test(t)) return e;
202
+ const i = a.exec(t);
203
203
  if (i) {
204
204
  const h = i.at(1);
205
205
  if (jt.some((c) => h == null ? void 0 : h.includes(c))) return e;
@@ -217,17 +217,17 @@ ${t}`;
217
217
  return t;
218
218
  }
219
219
  }, et = async (t, e, s) => {
220
- const n = v(e), o = r(s, "./temp");
221
- it(o) || W(o);
222
- const a = tt(e);
220
+ const n = v(e), a = r(s, "./temp");
221
+ it(a) || W(a);
222
+ const o = tt(e);
223
223
  let i = O(e, "utf8");
224
224
  i = mt(i), i = Gt(i, t);
225
225
  const h = r(s, "js", n + ".js"), $ = await ct(t), c = r(t, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), p = Ct(c), b = await wt(t);
226
226
  await gt.build({
227
227
  stdin: {
228
228
  contents: i,
229
- sourcefile: a.base,
230
- resolveDir: a.dir,
229
+ sourcefile: o.base,
230
+ resolveDir: o.dir,
231
231
  loader: "tsx"
232
232
  },
233
233
  minify: !1,
@@ -242,8 +242,8 @@ ${t}`;
242
242
  plugins: [
243
243
  {
244
244
  name: "test",
245
- setup: (y) => {
246
- y.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (j) => {
245
+ setup: (d) => {
246
+ d.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (j) => {
247
247
  const P = O(j.path, "utf8");
248
248
  return { contents: mt(P), loader: "ts" };
249
249
  });
@@ -258,8 +258,8 @@ ${t}`;
258
258
  if (!n) throw new Error("Could not find config cache file");
259
259
  return JSON.parse(n);
260
260
  }, lt = async (t) => {
261
- const e = await Ht(t), s = await R(t), n = r(s, "salty.config.js"), o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
262
- return I(a, e);
261
+ const e = await Ht(t), s = await R(t), n = r(s, "salty.config.js"), a = Date.now(), { config: o } = await import(`${n}?t=${a}`);
262
+ return I(o, e);
263
263
  }, ft = () => {
264
264
  try {
265
265
  return process.env.NODE_ENV === "production";
@@ -270,21 +270,21 @@ ${t}`;
270
270
  try {
271
271
  const n = Date.now();
272
272
  e ? Y.info("Generating CSS in production mode! 🔥") : Y.info("Generating CSS in development mode! 🚀");
273
- const o = [], a = [], i = await R(t), h = r(i, "index.css");
273
+ const a = [], o = [], i = await R(t), h = r(i, "index.css");
274
274
  s && (() => {
275
275
  it(i) && Pt("rm -rf " + i), W(i, { recursive: !0 }), W(r(i, "css")), W(r(i, "types")), W(r(i, "js")), W(r(i, "cache"));
276
276
  })();
277
277
  const c = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
278
- async function b(l) {
279
- const d = ["node_modules", "saltygen"], S = kt(l);
278
+ async function b(f) {
279
+ const m = ["node_modules", "saltygen"], S = kt(f);
280
280
  if (S.isDirectory()) {
281
- const f = Dt(l);
282
- if (d.some((x) => l.includes(x))) return;
283
- await Promise.all(f.map((x) => b(r(l, x))));
284
- } else if (S.isFile() && rt(l)) {
285
- c.add(l);
286
- const C = O(l, "utf8");
287
- /define[\w\d]+\(/.test(C) && p.add(l);
281
+ const l = Dt(f);
282
+ if (m.some((x) => f.includes(x))) return;
283
+ await Promise.all(l.map((x) => b(r(f, x))));
284
+ } else if (S.isFile() && rt(f)) {
285
+ c.add(f);
286
+ const C = O(f, "utf8");
287
+ /define[\w\d]+\(/.test(C) && p.add(f);
288
288
  }
289
289
  }
290
290
  await b(t), await Bt(t, p);
@@ -294,79 +294,79 @@ ${t}`;
294
294
  classNames: []
295
295
  };
296
296
  await Promise.all(
297
- [...c].map(async (l) => {
298
- const { contents: d } = await et(t, l, i);
299
- Object.entries(d).forEach(([S, f]) => {
300
- f.isKeyframes ? u.keyframes.push({
301
- value: f,
302
- src: l,
297
+ [...c].map(async (f) => {
298
+ const { contents: m } = await et(t, f, i);
299
+ Object.entries(m).forEach(([S, l]) => {
300
+ l.isKeyframes ? u.keyframes.push({
301
+ value: l,
302
+ src: f,
303
303
  name: S
304
- }) : f.isClassName ? u.classNames.push({
305
- ...f,
306
- src: l,
304
+ }) : l.isClassName ? u.classNames.push({
305
+ ...l,
306
+ src: f,
307
307
  name: S
308
- }) : f.generator && u.components.push({
309
- ...f,
310
- src: l,
308
+ }) : l.generator && u.components.push({
309
+ ...l,
310
+ src: f,
311
311
  name: S
312
312
  });
313
313
  });
314
314
  })
315
315
  );
316
- const g = await lt(t);
317
- for (const l of u.keyframes) {
318
- const { value: d } = l, S = `a_${d.animationName}.css`, f = `css/${S}`, C = r(i, f);
319
- o.push(S), F(C, d.css);
316
+ const y = await lt(t);
317
+ for (const f of u.keyframes) {
318
+ const { value: m } = f, S = `a_${m.animationName}.css`, l = `css/${S}`, C = r(i, l);
319
+ a.push(S), F(C, m.css);
320
320
  }
321
- const y = {};
322
- for (const l of u.components) {
323
- const { src: d, name: S } = l;
324
- y[d] || (y[d] = []);
325
- const f = l.generator._withBuildContext({
321
+ const d = {};
322
+ for (const f of u.components) {
323
+ const { src: m, name: S } = f;
324
+ d[m] || (d[m] = []);
325
+ const l = f.generator._withBuildContext({
326
326
  callerName: S,
327
327
  isProduction: e,
328
- config: g
328
+ config: y
329
329
  });
330
- a[f.priority] || (a[f.priority] = []);
331
- const C = await f.css;
330
+ o[l.priority] || (o[l.priority] = []);
331
+ const C = await l.css;
332
332
  if (!C) continue;
333
- a[f.priority].push(f.cssFileName);
334
- const x = `css/${f.cssFileName}`, E = r(i, x);
335
- F(E, C), g.importStrategy === "component" && y[d].push(f.cssFileName);
333
+ o[l.priority].push(l.cssFileName);
334
+ const x = `css/${l.cssFileName}`, E = r(i, x);
335
+ F(E, C), y.importStrategy === "component" && d[m].push(l.cssFileName);
336
336
  }
337
- for (const l of u.classNames) {
338
- const { src: d, name: S } = l;
339
- y[d] || (y[d] = []);
340
- const f = l.generator._withBuildContext({
337
+ for (const f of u.classNames) {
338
+ const { src: m, name: S } = f;
339
+ d[m] || (d[m] = []);
340
+ const l = f.generator._withBuildContext({
341
341
  callerName: S,
342
342
  isProduction: e,
343
- config: g
344
- }), C = await f.css;
343
+ config: y
344
+ }), C = await l.css;
345
345
  if (!C) continue;
346
- a[0].push(f.cssFileName);
347
- const x = `css/${f.cssFileName}`, E = r(i, x);
348
- F(E, C), g.importStrategy === "component" && y[d].push(f.cssFileName);
346
+ o[l.priority] || (o[l.priority] = []), o[l.priority].push(l.cssFileName);
347
+ const x = `css/${l.cssFileName}`, E = r(i, x);
348
+ F(E, C), y.importStrategy === "component" && d[m].push(l.cssFileName);
349
349
  }
350
- g.importStrategy === "component" && Object.entries(y).forEach(([l, d]) => {
351
- const S = d.map((K) => `@import url('./${K}');`).join(`
352
- `), f = v(l, 6), C = tt(l), x = B(C.name), E = r(i, `css/f_${x}-${f}.css`);
350
+ y.importStrategy === "component" && Object.entries(d).forEach(([f, m]) => {
351
+ const S = m.map((K) => `@import url('./${K}');`).join(`
352
+ `), l = v(f, 6), C = tt(f), x = B(C.name), E = r(i, `css/f_${x}-${l}.css`);
353
353
  F(E, S || "/* Empty file */");
354
354
  });
355
- const j = o.map((l) => `@import url('./css/${l}');`).join(`
355
+ const j = a.map((f) => `@import url('./css/${f}');`).join(`
356
356
  `);
357
357
  let T = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
358
358
 
359
- ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
359
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) => {
360
360
  try {
361
- return O(r(i, "css", l), "utf8").length > 0;
361
+ return O(r(i, "css", f), "utf8").length > 0;
362
362
  } catch {
363
363
  return !1;
364
364
  }
365
- }).map((l) => `@import url('./css/${l}');`).join(`
365
+ }).map((f) => `@import url('./css/${f}');`).join(`
366
366
  `)}
367
367
  ${j}`;
368
- if (g.importStrategy !== "component") {
369
- const l = a.reduce((d, S, f) => {
368
+ if (y.importStrategy !== "component") {
369
+ const f = o.reduce((m, S, l) => {
370
370
  const C = S.reduce((A, L) => {
371
371
  var U;
372
372
  const Z = r(i, "css", L), q = O(Z, "utf8"), Q = ((U = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : U.at(1)) || v(Z, 6);
@@ -375,12 +375,12 @@ ${j}`;
375
375
  ${q}
376
376
  /*end:${Q}*/
377
377
  `;
378
- }, ""), x = `l_${f}.css`, E = r(i, "css", x), K = `@layer l${f} { ${C}
378
+ }, ""), x = `l_${l}.css`, E = r(i, "css", x), K = `@layer l${l} { ${C}
379
379
  }`;
380
- return F(E, K), `${d}
380
+ return F(E, K), `${m}
381
381
  @import url('./css/${x}');`;
382
382
  }, "");
383
- T += l;
383
+ T += f;
384
384
  }
385
385
  F(h, T);
386
386
  const D = Date.now() - n, H = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
@@ -392,7 +392,7 @@ ${q}
392
392
  try {
393
393
  const n = await R(t);
394
394
  if (rt(e)) {
395
- const a = [], i = await lt(t), { contents: h } = await et(t, e, n);
395
+ const o = [], i = await lt(t), { contents: h } = await et(t, e, n);
396
396
  for (const [$, c] of Object.entries(h)) {
397
397
  if (c.isKeyframes && c.css) {
398
398
  const j = `css/${`a_${c.animationName}.css`}`, P = r(n, j);
@@ -400,14 +400,14 @@ ${q}
400
400
  return;
401
401
  }
402
402
  if (c.isClassName) {
403
- const y = c.generator._withBuildContext({
403
+ const d = c.generator._withBuildContext({
404
404
  callerName: $,
405
405
  isProduction: s,
406
406
  config: i
407
- }), j = await y.css;
407
+ }), j = await d.css;
408
408
  if (!j) continue;
409
- a[0].push(y.cssFileName);
410
- const P = `css/${y.cssFileName}`, k = r(n, P);
409
+ o[d.priority] || (o[d.priority] = []), o[d.priority].push(d.cssFileName);
410
+ const P = `css/${d.cssFileName}`, k = r(n, P);
411
411
  F(k, j);
412
412
  }
413
413
  if (!c.generator) return;
@@ -417,18 +417,18 @@ ${q}
417
417
  config: i
418
418
  }), b = await p.css;
419
419
  if (!b) continue;
420
- const u = `css/${p.cssFileName}`, g = r(n, u);
421
- F(g, b), a[p.priority] || (a[p.priority] = []), a[p.priority].push(p.cssFileName);
420
+ const u = `css/${p.cssFileName}`, y = r(n, u);
421
+ F(y, b), o[p.priority] || (o[p.priority] = []), o[p.priority].push(p.cssFileName);
422
422
  }
423
423
  if (i.importStrategy !== "component")
424
- a.forEach(($, c) => {
424
+ o.forEach(($, c) => {
425
425
  const p = `l_${c}.css`, b = r(n, "css", p);
426
426
  let u = O(b, "utf8");
427
- $.forEach((g) => {
427
+ $.forEach((y) => {
428
428
  var k;
429
- const y = r(n, "css", g), j = ((k = /.*-([^-]+)-\d+.css/.exec(g)) == null ? void 0 : k.at(1)) || v(y, 6);
429
+ const d = r(n, "css", y), j = ((k = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : k.at(1)) || v(d, 6);
430
430
  if (!u.includes(j)) {
431
- const J = O(y, "utf8"), T = `/*start:${j}-${g}*/
431
+ const J = O(d, "utf8"), T = `/*start:${j}-${y}*/
432
432
  ${J}
433
433
  /*end:${j}*/
434
434
  `;
@@ -439,7 +439,7 @@ ${T}
439
439
  }), F(b, u);
440
440
  });
441
441
  else {
442
- const $ = a.flat().map((g) => `@import url('./${g}');`).join(`
442
+ const $ = o.flat().map((y) => `@import url('./${y}');`).join(`
443
443
  `), c = v(e, 6), p = tt(e), b = B(p.name), u = r(n, `css/f_${b}-${c}.css`);
444
444
  F(u, $ || "/* Empty file */");
445
445
  }
@@ -451,20 +451,20 @@ ${T}
451
451
  try {
452
452
  const n = await R(t);
453
453
  if (rt(e)) {
454
- const a = O(e, "utf8");
455
- a.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== a && await _t(e, a);
454
+ const o = O(e, "utf8");
455
+ o.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== o && await _t(e, o);
456
456
  const h = await lt(t), { contents: $ } = await et(t, e, n);
457
- let c = a;
457
+ let c = o;
458
458
  if (Object.entries($).forEach(([p, b]) => {
459
- var f;
459
+ var l;
460
460
  if (b.isKeyframes || !b.generator) return;
461
461
  const u = b.generator._withBuildContext({
462
462
  callerName: p,
463
463
  isProduction: s,
464
464
  config: h
465
- }), g = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
466
- if (!g) return console.error("Could not find the original declaration");
467
- const y = (f = g.at(1)) == null ? void 0 : f.trim(), j = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(c);
465
+ }), y = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
466
+ if (!y) return console.error("Could not find the original declaration");
467
+ const d = (l = y.at(1)) == null ? void 0 : l.trim(), j = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(c);
468
468
  if (!j) return console.error("Could not find the original declaration");
469
469
  const { index: P } = j;
470
470
  let k = !1;
@@ -476,8 +476,8 @@ ${T}
476
476
  }
477
477
  if (!k) clearTimeout(J);
478
478
  else throw new Error("Failed to find the end of the styled call and timed out");
479
- const H = P + T, l = c.slice(P, H), d = c, S = ` ${p} = styled(${y}, "${u.classNames}", ${JSON.stringify(u.clientProps)});`;
480
- c = c.replace(l, S), d === c && console.error("Minimize file failed to change content", { name: p, tagName: y });
479
+ const H = P + T, f = c.slice(P, H), m = c, S = ` ${p} = styled(${d}, "${u.classNames}", ${JSON.stringify(u.clientProps)});`;
480
+ c = c.replace(f, S), m === c && console.error("Minimize file failed to change content", { name: p, tagName: d });
481
481
  }), h.importStrategy === "component") {
482
482
  const p = v(e, 6), b = tt(e);
483
483
  c = `import '../../saltygen/css/${`f_${B(b.name)}-${p}.css`}';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.217",
3
+ "version": "0.0.1-alpha.218",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
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-B6M9WK93.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-BPohv4BZ.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-B_bv7TCc.js";
2
+ import { i as e } from "../index-DVSBEd3f.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 xe=require("esbuild"),Pe=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),c=require("fs"),oe=require("fs/promises"),Y=require("./parse-styles-C6OYNcYI.cjs"),G=require("winston"),M=require("./css/merge.cjs"),Ne=require("./define-templates-Cunsb_Tr.cjs");var ne=typeof document<"u"?document.currentScript:null;function ke(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=ke(xe),ye=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 a=o.trim(),S=await ye(i,[...t,a]);s.push(S)}else n[o]=i;if(Object.keys(n).length){const o=t.map(_.dashCase).join("-"),i="t_"+_.toHash(o,4),a=await Y.parseAndJoinStyles(n,`.${o}, .${i}`);s.push(a)}return s.join(`
2
- `)},_e=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?me(o,i,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return c.existsSync(t)?t:ge(r.join(e,".."))},De=async e=>{const t=ge(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Oe=async e=>{const t=await De(e);if(t)return t.type};let z;const he=async e=>{if(z)return z;const t=await Oe(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-B6M9WK93.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},K=G.createLogger({level:"debug",format:G.format.combine(G.format.colorize(),G.format.cli()),transports:[new G.transports.Console({})]}),Te=e=>{K.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 Ee={"*, *::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(o=>o.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await ae(e),s=r.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("|")})\\.`),ee=(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=r.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):be(r.join(e,".."))},ae=async e=>{var n,o;const t=await be(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))},Re=async e=>{const t=await ae(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 he(e),a=je(n);await pe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:a});const S=Date.now(),{config:j}=await import(`${o}?t=${S}`);return{config:j,path:o}},$e=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 L(e,m,s);Object.entries(b).forEach(([P,O])=>{O.isMedia?n.mediaQueries.push([P,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(`${P};;${R}`))})}));const{config:o,path:i}=await Re(e),a={...o},S=new Set,j=(m,b=[])=>m?Object.entries(m).flatMap(([R,P])=>{if(!P)return;if(typeof P=="object")return j(P,[...b,R]);const O=Se(R),te=_.dashCase(R),se=[...b,O].join(".");S.add(`"${se}"`);const X=[...b.map(_.dashCase),te].join("-"),ue=Y.parseVariableTokens(P);return ue?`--${X}: ${ue.transformed};`:`--${X}: ${P};`}):[],l=m=>m?Object.entries(m).flatMap(([b,R])=>{const P=j(R);return b==="base"?P.join(""):`${b} { ${P.join("")} }`}):[],d=m=>m?Object.entries(m).flatMap(([b,R])=>Object.entries(R).flatMap(([P,O])=>{const te=j(O,[b]),se=`.${b}-${P}, [data-${b}="${P}"]`,X=te.join("");return`${se} { ${X} }`})):[],w=m=>({...m,responsive:void 0,conditional:void 0}),p=m=>n.variables.map(b=>m==="static"?w(b._current):b._current[m]),g=M.mergeObjects(w(o.variables),p("static")),h=j(g),C=M.mergeObjects((le=o.variables)==null?void 0:le.responsive,p("responsive")),N=l(C),k=M.mergeObjects((fe=o.variables)==null?void 0:fe.conditional,p("conditional")),J=d(k),T=r.join(s,"css/_variables.css"),H=`:root { ${h.join("")} ${N.join("")} } ${J.join("")}`;c.writeFileSync(T,H),a.staticVariables=g;const D=r.join(s,"css/_global.css"),q=M.mergeObjects(o.global,n.globalStyles),f=await Y.parseAndJoinStyles(q,"");c.writeFileSync(D,`@layer global { ${f} }`);const y=r.join(s,"css/_reset.css"),u=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Ee,F=await Y.parseAndJoinStyles(u,"");c.writeFileSync(y,`@layer reset { ${F} }`);const x=r.join(s,"css/_templates.css"),E=M.mergeObjects(o.templates,n.templates),I=await ye(E),W=_e(E);c.writeFileSync(x,`@layer templates { ${I} }`),a.templates=E;const A=o.templates?[Ne.defineTemplates(o.templates)._setPath(`config;;${i}`)]:[],Q=M.mergeFactories(n.templates,A);a.templatePaths=Object.fromEntries(Object.entries(Q).map(([m,b])=>[m,b._path]));const{mediaQueries:Z}=n;a.mediaQueries=Object.fromEntries(Z.map(([m,b])=>[`@${m}`,b]));const B=Z.map(([m])=>`'@${m}'`).join(" | "),U=r.join(s,"types/css-tokens.d.ts"),Fe=`
3
- // Variable types
4
- type VariableTokens = ${[...S].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 = ${B||"''"};
15
- `;c.writeFileSync(U,Fe);const Ce=r.join(s,"cache/config-cache.json");c.writeFileSync(Ce,JSON.stringify(a,null,2))},de=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 a=o.exec(e);if(a){const S=a.at(1);if(ie.some(l=>S==null?void 0:S.includes(l)))return t}return"styled('div',"}),Ve=(e,t)=>{try{const s=c.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}},L=async(e,t,s)=>{const n=_.toHash(t),o=r.join(s,"./temp");c.existsSync(o)||c.mkdirSync(o);const i=r.parse(t);let a=c.readFileSync(t,"utf8");a=de(a),a=Ve(a,e);const S=r.join(s,"js",n+".js"),j=await ae(e),l=r.join(e,(j==null?void 0:j.configDir)||"","salty.config.ts"),d=je(l),w=await he(e);await pe.build({stdin:{contents:a,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:S,format:w,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(`${S}?t=${p}`),outputFilePath:S}},Me=async e=>{const t=await v(e),s=r.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)},re=async e=>{const t=await Me(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)},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ve=async(e,t=ce(),s=!0)=>{try{const n=Date.now();t?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const o=[],i=[],a=await v(e),S=r.join(a,"index.css");s&&(()=>{c.existsSync(a)&&Pe.execSync("rm -rf "+a),c.mkdirSync(a,{recursive:!0}),c.mkdirSync(r.join(a,"css")),c.mkdirSync(r.join(a,"types")),c.mkdirSync(r.join(a,"js")),c.mkdirSync(r.join(a,"cache"))})();const l=new Set,d=new Set;async function w(f){const y=["node_modules","saltygen"],$=c.statSync(f);if($.isDirectory()){const u=c.readdirSync(f);if(y.some(x=>f.includes(x)))return;await Promise.all(u.map(x=>w(r.join(f,x))))}else if($.isFile()&&ee(f)){l.add(f);const F=c.readFileSync(f,"utf8");/define[\w\d]+\(/.test(F)&&d.add(f)}}await w(e),await $e(e,d);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async f=>{const{contents:y}=await L(e,f,a);Object.entries(y).forEach(([$,u])=>{u.isKeyframes?p.keyframes.push({value:u,src:f,name:$}):u.isClassName?p.classNames.push({...u,src:f,name:$}):u.generator&&p.components.push({...u,src:f,name:$})})}));const g=await re(e);for(const f of p.keyframes){const{value:y}=f,$=`a_${y.animationName}.css`,u=`css/${$}`,F=r.join(a,u);o.push($),c.writeFileSync(F,y.css)}const h={};for(const f of p.components){const{src:y,name:$}=f;h[y]||(h[y]=[]);const u=f.generator._withBuildContext({callerName:$,isProduction:t,config:g});i[u.priority]||(i[u.priority]=[]);const F=await u.css;if(!F)continue;i[u.priority].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=r.join(a,x);c.writeFileSync(E,F),g.importStrategy==="component"&&h[y].push(u.cssFileName)}for(const f of p.classNames){const{src:y,name:$}=f;h[y]||(h[y]=[]);const u=f.generator._withBuildContext({callerName:$,isProduction:t,config:g}),F=await u.css;if(!F)continue;i[0].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=r.join(a,x);c.writeFileSync(E,F),g.importStrategy==="component"&&h[y].push(u.cssFileName)}g.importStrategy==="component"&&Object.entries(h).forEach(([f,y])=>{const $=y.map(I=>`@import url('./${I}');`).join(`
20
- `),u=_.toHash(f,6),F=r.parse(f),x=_.dashCase(F.name),E=r.join(a,`css/f_${x}-${u}.css`);c.writeFileSync(E,$||"/* Empty file */")});const C=o.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(r.join(a,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
24
- `)}
25
- ${C}`;if(g.importStrategy!=="component"){const f=i.reduce((y,$,u)=>{const F=$.reduce((W,A)=>{var U;const Q=r.join(a,"css",A),Z=c.readFileSync(Q,"utf8"),B=((U=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:U.at(1))||_.toHash(Q,6);return W.includes(B)?W:`${W}
26
- /*start:${B}-${A}*/
27
- ${Z}
28
- /*end:${B}*/
29
- `},""),x=`l_${u}.css`,E=r.join(a,"css",x),I=`@layer l${u} { ${F}
30
- }`;return c.writeFileSync(E,I),`${y}
31
- @import url('./css/${x}');`},"");T+=f}c.writeFileSync(S,T);const D=Date.now()-n,q=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";K.info(`Generated CSS in ${D}ms! ${q}`)}catch(n){console.error(n)}},Je=async(e,t,s=ce())=>{try{const n=await v(e);if(ee(t)){const i=[],a=await re(e),{contents:S}=await L(e,t,n);for(const[j,l]of Object.entries(S)){if(l.isKeyframes&&l.css){const C=`css/${`a_${l.animationName}.css`}`,N=r.join(n,C);c.writeFileSync(N,await l.css);return}if(l.isClassName){const h=l.generator._withBuildContext({callerName:j,isProduction:s,config:a}),C=await h.css;if(!C)continue;i[0].push(h.cssFileName);const N=`css/${h.cssFileName}`,k=r.join(n,N);c.writeFileSync(k,C)}if(!l.generator)return;const d=l.generator._withBuildContext({callerName:j,isProduction:s,config:a}),w=await d.css;if(!w)continue;const p=`css/${d.cssFileName}`,g=r.join(n,p);c.writeFileSync(g,w),i[d.priority]||(i[d.priority]=[]),i[d.priority].push(d.cssFileName)}if(a.importStrategy!=="component")i.forEach((j,l)=>{const d=`l_${l}.css`,w=r.join(n,"css",d);let p=c.readFileSync(w,"utf8");j.forEach(g=>{var k;const h=r.join(n,"css",g),C=((k=/.*-([^-]+)-\d+.css/.exec(g))==null?void 0:k.at(1))||_.toHash(h,6);if(!p.includes(C)){const J=c.readFileSync(h,"utf8"),T=`/*start:${C}-${g}*/
32
- ${J}
33
- /*end:${C}*/
34
- `;p=`${p.replace(/\}$/,"")}
35
- ${T}
36
- }`}}),c.writeFileSync(w,p)});else{const j=i.flat().map(g=>`@import url('./${g}');`).join(`
37
- `),l=_.toHash(t,6),d=r.parse(t),w=_.dashCase(d.name),p=r.join(n,`css/f_${w}-${l}.css`);c.writeFileSync(p,j||"/* Empty file */")}}}catch(n){console.error(n)}},ze=async(e,t,s=ce())=>{try{const n=await v(e);if(ee(t)){const i=c.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==i&&await oe.writeFile(t,i);const S=await re(e),{contents:j}=await L(e,t,n);let l=i;if(Object.entries(j).forEach(([d,w])=>{var u;if(w.isKeyframes||!w.generator)return;const p=w.generator._withBuildContext({callerName:d,isProduction:s,config:S}),g=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!g)return console.error("Could not find the original declaration");const h=(u=g.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 k=!1;const J=setTimeout(()=>k=!0,5e3);let T=0,H=!1,D=0;for(;!H&&!k;){const F=l[N+T];F==="("&&D++,F===")"&&D--,D===0&&F===")"&&(H=!0),T>l.length&&(k=!0),T++}if(!k)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const q=N+T,f=l.slice(N,q),y=l,$=` ${d} = styled(${h}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;l=l.replace(f,$),y===l&&console.error("Minimize file failed to change content",{name:d,tagName:h})}),S.importStrategy==="component"){const d=_.toHash(t,6),w=r.parse(t);l=`import '../../saltygen/css/${`f_${_.dashCase(w.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=L;exports.generateConfigStyles=$e;exports.generateCss=ve;exports.generateFile=Je;exports.isSaltyFile=ee;exports.logError=Te;exports.logger=K;exports.minimizeFile=ze;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;