@salty-css/core 0.0.1-alpha.281 → 0.0.1-alpha.283

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"),A=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),e=require("../index-CidX_d4J.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora"),ae=require("../should-restart-CFLKMt9i.cjs");var G=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,x=>{if(x)return P(x);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(),x=y.join(" ");await X(`npm install ${x}`),P.succeed(`Installed packages: ${C}`)},re=()=>A.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!re())return;await X(`./node_modules/.bin/prettier --write "${y}"`),e.logger.info(`Formatted ${y} with Prettier`)}catch(C){e.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function ce(){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:f}=await C[i],d=ne.render(f,a);return{fileName:i,content:d}},x=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:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await x()).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}`},H=i=>{const a=i==="."?"":i,f=process.cwd();return n.join(f,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 e.logError("Salty CSS project must be initialized in a directory with a package.json file.");e.logger.info("Initializing a new Salty-CSS project!");const{dir:f=i,cssFile:d,skipInstall:p}=this.opts();if(!f)return e.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 c=process.cwd(),r=H(f),q=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=q.map(async({fileName:t,content:u})=>{const l=n.join(r,t);if(await s.readFile(l,"utf-8").catch(()=>{})!==void 0){e.logger.debug("File already exists: "+l);return}const k=t.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),e.logger.info("Creating file: "+l),await s.writeFile(l,u),await S(l)});await Promise.all(m);const w=n.relative(c,r)||".",h=n.join(c,".saltyrc.json"),g=await s.readFile(h,"utf-8").catch(()=>{});if(g===void 0){e.logger.info("Creating file: "+h);const u=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,u),await S(h)}else{const t=JSON.parse(g),u=(t==null?void 0:t.projects)||[];if(u.findIndex(o=>o.dir===w)===-1){u.push({dir:w,framework:"react"}),t.projects=[...u];const o=JSON.stringify(t,null,2);o!==g&&(e.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(c,".gitignore"),T=await s.readFile(j,"utf-8").catch(()=>{});T!==void 0&&(T.includes("saltygen")||(e.logger.info("Edit file: "+j),await s.writeFile(j,T+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),A=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),e=require("../index-BYrtB4JM.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora"),ae=require("../should-restart-BFVRQc0_.cjs");var G=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,x=>{if(x)return P(x);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(),x=y.join(" ");await X(`npm install ${x}`),P.succeed(`Installed packages: ${C}`)},re=()=>A.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!re())return;await X(`./node_modules/.bin/prettier --write "${y}"`),e.logger.info(`Formatted ${y} with Prettier`)}catch(C){e.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function ce(){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:f}=await C[i],d=ne.render(f,a);return{fileName:i,content:d}},x=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:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await x()).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}`},H=i=>{const a=i==="."?"":i,f=process.cwd();return n.join(f,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 e.logError("Salty CSS project must be initialized in a directory with a package.json file.");e.logger.info("Initializing a new Salty-CSS project!");const{dir:f=i,cssFile:d,skipInstall:p}=this.opts();if(!f)return e.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 c=process.cwd(),r=H(f),q=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=q.map(async({fileName:t,content:u})=>{const l=n.join(r,t);if(await s.readFile(l,"utf-8").catch(()=>{})!==void 0){e.logger.debug("File already exists: "+l);return}const k=t.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),e.logger.info("Creating file: "+l),await s.writeFile(l,u),await S(l)});await Promise.all(m);const w=n.relative(c,r)||".",h=n.join(c,".saltyrc.json"),g=await s.readFile(h,"utf-8").catch(()=>{});if(g===void 0){e.logger.info("Creating file: "+h);const u=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,u),await S(h)}else{const t=JSON.parse(g),u=(t==null?void 0:t.projects)||[];if(u.findIndex(o=>o.dir===w)===-1){u.push({dir:w,framework:"react"}),t.projects=[...u];const o=JSON.stringify(t,null,2);o!==g&&(e.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(c,".gitignore"),T=await s.readFile(j,"utf-8").catch(()=>{});T!==void 0&&(T.includes("saltygen")||(e.logger.info("Edit file: "+j),await s.writeFile(j,T+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
package/bin/main.js CHANGED
@@ -3,11 +3,11 @@ import { existsSync as Q, watch as re } from "fs";
3
3
  import { mkdir as q, readFile as S, writeFile as C } from "fs/promises";
4
4
  import { join as a, relative as z, parse as ce, format as te } from "path";
5
5
  import { render as le } from "ejs";
6
- import { l as t, a as h, g as K, i as de, b as fe } from "../index-D3EUFKhD.js";
6
+ import { l as t, a as h, b as K, i as de, c as fe } from "../index-CR0k7PXM.js";
7
7
  import { p as pe } from "../pascal-case-BQpR5PdN.js";
8
8
  import { exec as ue } from "child_process";
9
9
  import ge from "ora";
10
- import { c as ye } from "../should-restart-mZFoFAt4.js";
10
+ import { c as ye } from "../should-restart-CR-ZEYLq.js";
11
11
  const ne = (g) => new Promise((P, x) => {
12
12
  ue(g, ($) => {
13
13
  if ($) return x($);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("fs/promises"),t=require("path");var e=typeof document<"u"?document.currentScript:null;const r=new URL(".",typeof document>"u"?require("url").pathToFileURL(__filename).href:e&&e.tagName.toUpperCase()==="SCRIPT"&&e.src||new URL("cache/resolve-dynamic-config-cache.cjs",document.baseURI).href).pathname,i=async()=>{const c=t.join(r,"config-cache.json"),n=await o.readFile(c,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)};exports.resolveDynamicConfigCache=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("fs/promises"),r=require("path"),i=require("../index-BYrtB4JM.cjs"),t=async()=>{const c=i.getCorePackageRoot(),e=r.join(c,"config-cache.json");console.log(`Resolving dynamic config cache from ${e}`);const o=await n.readFile(e,"utf8");if(!o)throw new Error("Could not find config cache file");return JSON.parse(o)};exports.resolveDynamicConfigCache=t;
@@ -1,10 +1,13 @@
1
- import { readFile as e } from "fs/promises";
1
+ import { readFile as n } from "fs/promises";
2
2
  import { join as r } from "path";
3
- const t = new URL(".", import.meta.url).pathname, a = async () => {
4
- const n = r(t, "config-cache.json"), o = await e(n, "utf8");
5
- if (!o) throw new Error("Could not find config cache file");
6
- return JSON.parse(o);
3
+ import { g as t } from "../index-CR0k7PXM.js";
4
+ const s = async () => {
5
+ const e = t(), o = r(e, "config-cache.json");
6
+ console.log(`Resolving dynamic config cache from ${o}`);
7
+ const c = await n(o, "utf8");
8
+ if (!c) throw new Error("Could not find config cache file");
9
+ return JSON.parse(c);
7
10
  };
8
11
  export {
9
- a as resolveDynamicConfigCache
12
+ s as resolveDynamicConfigCache
10
13
  };
@@ -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-Bdgw_4ME.cjs");require("../parsers/index.cjs");const e=require("../index-CidX_d4J.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-Bdgw_4ME.cjs");require("../parsers/index.cjs");const e=require("../index-BYrtB4JM.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.getCorePackageRoot=e.getCorePackageRoot;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
@@ -1,3 +1,4 @@
1
+ export declare const getCorePackageRoot: () => string;
1
2
  export declare const saltyFileExtensions: string[];
2
3
  export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
3
4
  export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
package/compiler/index.js CHANGED
@@ -6,16 +6,17 @@ import "fs";
6
6
  import "fs/promises";
7
7
  import "../parse-styles-C1E6ETeH.js";
8
8
  import "../parsers/index.js";
9
- import { e as F, d as y, g as x, b as S, i as c, m as f, s as C, c as E } from "../index-D3EUFKhD.js";
9
+ import { f as F, e as y, b as c, c as f, g as x, i as C, m as S, s as E, d as R } from "../index-CR0k7PXM.js";
10
10
  import "../css/merge.js";
11
11
  import "../define-templates-4A2yHcMF.js";
12
12
  export {
13
13
  F as compileSaltyFile,
14
14
  y as generateConfigStyles,
15
- x as generateCss,
16
- S as generateFile,
17
- c as isSaltyFile,
18
- f as minimizeFile,
19
- C as saltyFileExtensions,
20
- E as saltyFileRegExp
15
+ c as generateCss,
16
+ f as generateFile,
17
+ x as getCorePackageRoot,
18
+ C as isSaltyFile,
19
+ S as minimizeFile,
20
+ E as saltyFileExtensions,
21
+ R as saltyFileRegExp
21
22
  };
@@ -0,0 +1,41 @@
1
+ "use strict";const Re=require("esbuild"),ve=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),be=require("fs/promises"),ce=require("./parse-styles-Bdgw_4ME.cjs"),Se=require("./parsers/index.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),re=require("typescript");var I=typeof document<"u"?document.currentScript:null;function Ve(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 Fe=Ve(Re),$e=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:$e(i.join(e,".."))},Me=async e=>{const t=$e(e);return await be.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Je=async e=>{const t=await Me(e);if(t)return t.type};let H;const Ce=async e=>{if(H)return H;const t=await Je(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-BYrtB4JM.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),qe=e=>{B.error(e)};function Pe(e){return e?typeof e!="string"?Pe(String(e)):e.replace(/[^\d\w]/g,"."):""}const ze={"*, *::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"}},He=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=re.createSourceFile("temp.ts",e,re.ScriptTarget.Latest,!0);function o(y){if(re.isVariableDeclaration(y)&&y.name.getText()===t){const S=y.getStart(),d=y.getEnd();clearTimeout(r),s([S,d])}y.forEachChild(o)}o(l)}),Ne=()=>{let{pathname:e}=new URL(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-BYrtB4JM.cjs",document.baseURI).href);for(;/core\/?(src\/)?$/.test(e)===!1;)e=i.join(e,"../");return e},R={externalModules:[],rcFile:void 0,destDir:void 0},xe=e=>{if(R.externalModules.length>0)return R.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 R.externalModules=n,n},q=async e=>{if(R.destDir)return R.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},le=["salty","css","styles","styled"],ke=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),ee=(e,t=[])=>ke(t).test(e),De=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await be.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):De(i.join(e,".."))},fe=async e=>{var n,r;const t=await De(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},Ie=async e=>{const t=await fe(e),s=await q(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await Ce(e),o=xe(n);await Fe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:S}=await import(`${r}?t=${y}`);return{config:S,path:r}},Te=async(e,t)=>{var ge,he;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:F,outputFilePath:G}=await A(e,w,s);Object.entries(F).forEach(([D,P])=>{P.isMedia?n.mediaQueries.push([D,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${D};;${G}`))})}));const{config:r,path:l}=await Ie(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([w,F])=>[`@${w}`,F]));const S=y.map(([w])=>`'@${w}'`).join(" | "),d=new Set,a=async(w,F=[])=>{if(!w)return[];const G=Object.entries(w).map(async([P,M])=>{const K=async T=>{if(!T)return;if(T instanceof Promise)return await K(await T);if(typeof T=="function")return await K(await T());if(typeof T=="object")return await a(T,[...F,P]);const oe=Pe(P),ie=_.dashCase(P),ae=[...F,oe].join(".");d.add(`"${ae}"`);const Z=[...F.map(_.dashCase),ie].join("-"),we=ce.parseVariableTokens(T);return we?`--${Z}: ${we.transformed};`:`--${Z}: ${T};`};return await K(M)});return(await Promise.all(G)).flat()},g=async w=>{if(!w)return[];const F=Object.entries(w).map(async([D,P])=>{const M=await a(P);return D==="base"?M.join(""):o.mediaQueries[D]?`${o.mediaQueries[D]} { ${M.join("")} }`:`${D} { ${M.join("")} }`});return(await Promise.all(F)).flat()},m=async w=>{if(!w)return[];const F=Object.entries(w).map(async([D,P])=>{const M=Object.entries(P).map(async([T,oe])=>{const ie=await a(oe,[D]),ae=`.${D}-${T}, [data-${D}="${T}"]`,Z=ie.join("");return`${ae} { ${Z} }`});return(await Promise.all(M)).flat()});return(await Promise.all(F)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),p=w=>n.variables.map(F=>w==="static"?h(F._current):F._current[w]),$=J.mergeObjects(h(r.variables),p("static")),x=await a($),k=J.mergeObjects((ge=r.variables)==null?void 0:ge.responsive,p("responsive")),v=await g(k),z=J.mergeObjects((he=r.variables)==null?void 0:he.conditional,p("conditional")),X=await m(z),de=i.join(s,"css/_variables.css"),E=`:root { ${x.join("")} ${v.join("")} } ${X.join("")}`;c.writeFileSync(de,E),o.staticVariables=$;const te=i.join(s,"css/_global.css"),u=J.mergeObjects(r.global,n.globalStyles),j=await ce.parseAndJoinStyles(u,"");c.writeFileSync(te,`@layer global { ${j} }`);const b=i.join(s,"css/_reset.css"),C=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:ze,N=await ce.parseAndJoinStyles(C,"");c.writeFileSync(b,`@layer reset { ${N} }`);const O=i.join(s,"css/_templates.css"),V=J.mergeObjects(r.templates,n.templates),L=await Se.parseTemplates(V),W=Se.getTemplateTypes(V);c.writeFileSync(O,`@layer templates { ${L} }`),o.templates=V;const Y=r.templates?[Ee.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],se=J.mergeFactories(n.templates,Y);o.templatePaths=Object.fromEntries(Object.entries(se).map(([w,F])=>[w,F._path]));const U=i.join(s,"types/css-tokens.d.ts"),_e=`
2
+ // Variable types
3
+ type VariableTokens = ${[...d].join("|")};
4
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
5
+
6
+ // Template types
7
+ type TemplateTokens = {
8
+ ${Object.entries(W).map(([w,F])=>`${w}?: ${F}`).join(`
9
+ `)}
10
+ }
11
+
12
+ // Media query types
13
+ type MediaQueryKeys = ${S||"''"};
14
+ `;c.writeFileSync(U,_e);const Oe=i.join(s,"cache/config-cache.json");c.writeFileSync(Oe,JSON.stringify(o,null,2));const me=Ne();console.log("corePackageRoot",me);const ye=i.join(me,"cache/config-cache.json");console.log("Config cache secondary path",ye),c.writeFileSync(ye,JSON.stringify(o,null,2))},je=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 o=r.exec(e);if(o){const y=o.at(1);if(le.some(d=>y==null?void 0:y.includes(d)))return t}return"styled('div',"}),Le=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
15
+
16
+ ${e}`:`globalThis.saltyConfig = {};
17
+
18
+ ${e}`}catch{return e}},A=async(e,t,s)=>{const n=_.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=je(o),o=Le(o,e);const y=i.join(s,"js",n+".js"),S=await fe(e),d=i.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),a=xe(d),g=await Ce(e);await Fe.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},$=>{const x=c.readFileSync($.path,"utf8");return{contents:je(x),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},We=async e=>{const t=await q(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)},ue=async e=>{const t=await We(e),s=await q(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return J.mergeObjects(l,t)},pe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ue=async(e,t=pe(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await q(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&ve.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const d=new Set,a=new Set;async function g(u){const j=["node_modules","saltygen"],b=c.statSync(u);if(b.isDirectory()){const f=c.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(i.join(u,N))))}else if(b.isFile()&&ee(u)){d.add(u);const C=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&a.add(u)}}await g(e),await Te(e,a);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...d].map(async u=>{const{contents:j}=await A(e,u,o);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:b}):f.isClassName?m.classNames.push({...f,src:u,name:b}):f.generator&&m.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of m.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=i.join(o,f);r.push(b),c.writeFileSync(C,j.css)}const p={};for(const u of m.components){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});l[f.priority]||(l[f.priority]=[]);const C=await f.css;if(!C)continue;l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}for(const u of m.classNames){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;l[f.priority]||(l[f.priority]=[]),l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([u,j])=>{const b=j.map(V=>`@import url('./${V}');`).join(`
19
+ `),f=_.toHash(u,6),C=i.parse(u),N=_.dashCase(C.name),O=i.join(o,`css/f_${N}-${f}.css`);c.writeFileSync(O,b||"/* Empty file */")});const $=r.map(u=>`@import url('./css/${u}');`).join(`
20
+ `);let X=`/*!
21
+ * Generated with Salty CSS (https://salty-css.dev)
22
+ * Do not edit this file directly
23
+ */
24
+ @layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
25
+
26
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return c.readFileSync(i.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
27
+ `)}
28
+ ${$}`;if(h.importStrategy!=="component"){const u=l.reduce((j,b,f)=>{const C=b.reduce((L,W)=>{var ne;const Y=i.join(o,"css",W),se=c.readFileSync(Y,"utf8"),U=((ne=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:ne.at(1))||_.toHash(Y,6);return L.includes(U)?L:`${L}
29
+ /*start:${U}-${W}*/
30
+ ${se}
31
+ /*end:${U}*/
32
+ `},""),N=`l_${f}.css`,O=i.join(o,"css",N),V=`@layer l${f} { ${C}
33
+ }`;return c.writeFileSync(O,V),`${j}
34
+ @import url('./css/${N}');`},"");X+=u}c.writeFileSync(y,X);const E=Date.now()-n,te=E<200?"🔥":E<500?"🚀":E<1e3?"🎉":E<2e3?"🚗":E<5e3?"🤔":"🥴";B.info(`Generated CSS in ${E}ms! ${te}`)}catch(n){console.error(n)}},Ge=async(e,t,s=pe())=>{try{const n=await q(e);if(ee(t)){const l=[],o=await ue(e),{contents:y}=await A(e,t,n);for(const[S,d]of Object.entries(y)){if(d.isKeyframes&&d.css){const $=`css/${`a_${d.animationName}.css`}`,x=i.join(n,$);c.writeFileSync(x,await d.css);continue}if(d.isClassName){const p=d.generator._withBuildContext({callerName:S,isProduction:s,config:o}),$=await p.css;if(!$)continue;l[p.priority]||(l[p.priority]=[]),l[p.priority].push(p.cssFileName);const x=`css/${p.cssFileName}`,k=i.join(n,x);c.writeFileSync(k,$);continue}if(!d.generator)continue;const a=d.generator._withBuildContext({callerName:S,isProduction:s,config:o}),g=await a.css;if(!g)continue;const m=`css/${a.cssFileName}`,h=i.join(n,m);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((S,d)=>{const a=`l_${d}.css`,g=i.join(n,"css",a);let m=c.readFileSync(g,"utf8");S.forEach(h=>{var k;const p=i.join(n,"css",h),$=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||_.toHash(p,6);if(!m.includes($)){const v=c.readFileSync(p,"utf8"),z=`/*start:${$}-${h}*/
35
+ ${v}
36
+ /*end:${$}*/
37
+ `;m=`${m.replace(/\}$/,"")}
38
+ ${z}
39
+ }`}}),c.writeFileSync(g,m)});else{const S=l.flat().map(h=>`@import url('./${h}');`).join(`
40
+ `),d=_.toHash(t,6),a=i.parse(t),g=_.dashCase(a.name),m=i.join(n,`css/f_${g}-${d}.css`);c.writeFileSync(m,S||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=pe())=>{var n,r;try{const l=await q(e);if(ee(t)){const y=c.readFileSync(t,"utf8"),S=await ue(e),{contents:d}=await A(e,t,l);let a=y;for(const[g,m]of Object.entries(d)){if(m.isKeyframes||!m.generator)continue;const h=m.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[p,$]=await He(a,g),x=a.slice(p,$);if(m.isClassName){const k=a,v=` ${g} = className("${h.classNames}")`;a=a.replace(x,v),k===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const k=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),v=a,z=` ${g} = styled(${k}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,z),v===a&&console.error("Minimize file failed to change content",{name:g,tagName:k})}}if(S.importStrategy==="component"){const g=_.toHash(t,6),m=i.parse(t);a=`import '../../saltygen/css/${`f_${_.dashCase(m.name)}-${g}.css`}';
41
+ ${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=A;exports.generateConfigStyles=Te;exports.generateCss=Ue;exports.generateFile=Ge;exports.getCorePackageRoot=Ne;exports.isSaltyFile=ee;exports.logError=qe;exports.logger=B;exports.minimizeFile=Ke;exports.saltyFileExtensions=le;exports.saltyFileRegExp=ke;
@@ -1,22 +1,22 @@
1
- import * as St from "esbuild";
1
+ import * as Ft from "esbuild";
2
2
  import { execSync as vt } from "child_process";
3
3
  import { t as I, d as U } from "./dash-case-DBThphLm.js";
4
4
  import { join as i, parse as tt } from "path";
5
5
  import { existsSync as ft, writeFileSync as C, mkdirSync as G, readFileSync as _, statSync as Et, readdirSync as Ot } from "fs";
6
- import { readFile as Ct } from "fs/promises";
7
- import { p as $t, a as Mt } from "./parse-styles-C1E6ETeH.js";
8
- import { parseTemplates as Rt, getTemplateTypes as Jt } from "./parsers/index.js";
6
+ import { readFile as Pt } from "fs/promises";
7
+ import { p as St, a as Rt } from "./parse-styles-C1E6ETeH.js";
8
+ import { parseTemplates as Mt, getTemplateTypes as Jt } from "./parsers/index.js";
9
9
  import { createLogger as zt, format as rt, transports as Wt } from "winston";
10
10
  import { mergeObjects as H, mergeFactories as Gt } from "./css/merge.js";
11
11
  import { d as Ht } from "./define-templates-4A2yHcMF.js";
12
12
  import lt from "typescript";
13
- const Ft = (t) => {
13
+ const jt = (t) => {
14
14
  if (!t || t === "/") throw new Error("Could not find package.json file");
15
15
  const e = i(t, "package.json");
16
- return ft(e) ? e : Ft(i(t, ".."));
16
+ return ft(e) ? e : jt(i(t, ".."));
17
17
  }, It = async (t) => {
18
- const e = Ft(t);
19
- return await Ct(e, "utf-8").then(JSON.parse).catch(() => {
18
+ const e = jt(t);
19
+ return await Pt(e, "utf-8").then(JSON.parse).catch(() => {
20
20
  });
21
21
  }, Kt = async (t) => {
22
22
  const e = await It(t);
@@ -24,7 +24,7 @@ const Ft = (t) => {
24
24
  return e.type;
25
25
  };
26
26
  let W;
27
- const Pt = async (t) => {
27
+ const Nt = async (t) => {
28
28
  if (W) return W;
29
29
  const e = await Kt(t);
30
30
  return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
@@ -35,8 +35,8 @@ const Pt = async (t) => {
35
35
  }), fe = (t) => {
36
36
  Z.error(t);
37
37
  };
38
- function jt(t) {
39
- return t ? typeof t != "string" ? jt(String(t)) : t.replace(/[^\d\w]/g, ".") : "";
38
+ function xt(t) {
39
+ return t ? typeof t != "string" ? xt(String(t)) : t.replace(/[^\d\w]/g, ".") : "";
40
40
  }
41
41
  const Qt = {
42
42
  /** Set box model to border-box */
@@ -96,11 +96,16 @@ const Qt = {
96
96
  d.forEachChild(o);
97
97
  }
98
98
  o(r);
99
- }), Bt = () => (console.log("dirname", import.meta.url), new URL(import.meta.url).pathname), v = {
99
+ }), Bt = () => {
100
+ let { pathname: t } = new URL(import.meta.url);
101
+ for (; /core\/?(src\/)?$/.test(t) === !1; )
102
+ t = i(t, "../");
103
+ return t;
104
+ }, v = {
100
105
  externalModules: [],
101
106
  rcFile: void 0,
102
107
  destDir: void 0
103
- }, Nt = (t) => {
108
+ }, kt = (t) => {
104
109
  if (v.externalModules.length > 0) return v.externalModules;
105
110
  const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
106
111
  if (!s) return [];
@@ -110,19 +115,19 @@ const Qt = {
110
115
  if (v.destDir) return v.destDir;
111
116
  const e = await pt(t), s = i(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
112
117
  return v.destDir = s, s;
113
- }, xt = ["salty", "css", "styles", "styled"], qt = (t = []) => new RegExp(`\\.(${[...xt, ...t].join("|")})\\.`), mt = (t, e = []) => qt(e).test(t), Dt = async (t) => {
118
+ }, Dt = ["salty", "css", "styles", "styled"], qt = (t = []) => new RegExp(`\\.(${[...Dt, ...t].join("|")})\\.`), mt = (t, e = []) => qt(e).test(t), Tt = async (t) => {
114
119
  if (v.rcFile) return v.rcFile;
115
120
  if (t === "/") throw new Error("Could not find .saltyrc.json file");
116
- const e = i(t, ".saltyrc.json"), s = await Ct(e, "utf-8").then(JSON.parse).catch(() => {
121
+ const e = i(t, ".saltyrc.json"), s = await Pt(e, "utf-8").then(JSON.parse).catch(() => {
117
122
  });
118
- return s ? (v.rcFile = s, s) : Dt(i(t, ".."));
123
+ return s ? (v.rcFile = s, s) : Tt(i(t, ".."));
119
124
  }, pt = async (t) => {
120
125
  var n, c;
121
- const e = await Dt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
126
+ const e = await Tt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
122
127
  return s || ((c = e.projects) == null ? void 0 : c.find((r) => r.dir === e.defaultProject));
123
128
  }, Ut = async (t) => {
124
- const e = await pt(t), s = await J(t), n = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = i(s, "salty.config.js"), r = await Pt(t), o = Nt(n);
125
- await St.build({
129
+ const e = await pt(t), s = await J(t), n = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = i(s, "salty.config.js"), r = await Nt(t), o = kt(n);
130
+ await Ft.build({
126
131
  entryPoints: [n],
127
132
  minify: !0,
128
133
  treeShaking: !0,
@@ -134,7 +139,7 @@ const Qt = {
134
139
  const d = Date.now(), { config: w } = await import(`${c}?t=${d}`);
135
140
  return { config: w, path: c };
136
141
  }, At = async (t, e) => {
137
- var gt, ht;
142
+ var wt, $t;
138
143
  const s = await J(t), n = {
139
144
  mediaQueries: [],
140
145
  globalStyles: [],
@@ -144,8 +149,8 @@ const Qt = {
144
149
  await Promise.all(
145
150
  [...e].map(async (h) => {
146
151
  const { contents: S, outputFilePath: B } = await et(t, h, s);
147
- Object.entries(S).forEach(([k, j]) => {
148
- j.isMedia ? n.mediaQueries.push([k, j]) : j.isGlobalDefine ? n.globalStyles.push(j) : j.isDefineVariables ? n.variables.push(j) : j.isDefineTemplates && n.templates.push(j._setPath(`${k};;${B}`));
152
+ Object.entries(S).forEach(([D, j]) => {
153
+ j.isMedia ? n.mediaQueries.push([D, j]) : j.isGlobalDefine ? n.globalStyles.push(j) : j.isDefineVariables ? n.variables.push(j) : j.isDefineTemplates && n.templates.push(j._setPath(`${D};;${B}`));
149
154
  });
150
155
  })
151
156
  );
@@ -153,48 +158,48 @@ const Qt = {
153
158
  o.mediaQueries = Object.fromEntries(d.map(([h, S]) => [`@${h}`, S]));
154
159
  const w = d.map(([h]) => `'@${h}'`).join(" | "), p = /* @__PURE__ */ new Set(), a = async (h, S = []) => {
155
160
  if (!h) return [];
156
- const B = Object.entries(h).map(async ([j, R]) => {
161
+ const B = Object.entries(h).map(async ([j, M]) => {
157
162
  const q = async (T) => {
158
163
  if (!T) return;
159
164
  if (T instanceof Promise) return await q(await T);
160
165
  if (typeof T == "function") return await q(await T());
161
166
  if (typeof T == "object") return await a(T, [...S, j]);
162
- const at = jt(j), it = U(j), ct = [...S, at].join(".");
167
+ const at = xt(j), it = U(j), ct = [...S, at].join(".");
163
168
  p.add(`"${ct}"`);
164
- const Y = [...S.map(U), it].join("-"), wt = Mt(T);
165
- return wt ? `--${Y}: ${wt.transformed};` : `--${Y}: ${T};`;
169
+ const Y = [...S.map(U), it].join("-"), bt = Rt(T);
170
+ return bt ? `--${Y}: ${bt.transformed};` : `--${Y}: ${T};`;
166
171
  };
167
- return await q(R);
172
+ return await q(M);
168
173
  });
169
174
  return (await Promise.all(B)).flat();
170
- }, y = async (h) => {
175
+ }, g = async (h) => {
171
176
  if (!h) return [];
172
- const S = Object.entries(h).map(async ([k, j]) => {
173
- const R = await a(j);
174
- return k === "base" ? R.join("") : o.mediaQueries[k] ? `${o.mediaQueries[k]} { ${R.join("")} }` : `${k} { ${R.join("")} }`;
177
+ const S = Object.entries(h).map(async ([D, j]) => {
178
+ const M = await a(j);
179
+ return D === "base" ? M.join("") : o.mediaQueries[D] ? `${o.mediaQueries[D]} { ${M.join("")} }` : `${D} { ${M.join("")} }`;
175
180
  });
176
181
  return (await Promise.all(S)).flat();
177
182
  }, u = async (h) => {
178
183
  if (!h) return [];
179
- const S = Object.entries(h).map(async ([k, j]) => {
180
- const R = Object.entries(j).map(async ([T, at]) => {
181
- const it = await a(at, [k]), ct = `.${k}-${T}, [data-${k}="${T}"]`, Y = it.join("");
184
+ const S = Object.entries(h).map(async ([D, j]) => {
185
+ const M = Object.entries(j).map(async ([T, at]) => {
186
+ const it = await a(at, [D]), ct = `.${D}-${T}, [data-${D}="${T}"]`, Y = it.join("");
182
187
  return `${ct} { ${Y} }`;
183
188
  });
184
- return (await Promise.all(R)).flat();
189
+ return (await Promise.all(M)).flat();
185
190
  });
186
191
  return (await Promise.all(S)).flat();
187
- }, g = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), m = (h) => n.variables.map((S) => h === "static" ? g(S._current) : S._current[h]), F = H(g(c.variables), m("static")), x = await a(F), D = H((gt = c.variables) == null ? void 0 : gt.responsive, m("responsive")), E = await y(D), z = H((ht = c.variables) == null ? void 0 : ht.conditional, m("conditional")), A = await u(z), yt = i(s, "css/_variables.css"), O = `:root { ${x.join("")} ${E.join("")} } ${A.join("")}`;
188
- C(yt, O), o.staticVariables = F;
189
- const st = i(s, "css/_global.css"), f = H(c.global, n.globalStyles), $ = await $t(f, "");
192
+ }, y = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), m = (h) => n.variables.map((S) => h === "static" ? y(S._current) : S._current[h]), F = H(y(c.variables), m("static")), x = await a(F), k = H((wt = c.variables) == null ? void 0 : wt.responsive, m("responsive")), E = await g(k), z = H(($t = c.variables) == null ? void 0 : $t.conditional, m("conditional")), A = await u(z), gt = i(s, "css/_variables.css"), O = `:root { ${x.join("")} ${E.join("")} } ${A.join("")}`;
193
+ C(gt, O), o.staticVariables = F;
194
+ const st = i(s, "css/_global.css"), f = H(c.global, n.globalStyles), $ = await St(f, "");
190
195
  C(st, `@layer global { ${$} }`);
191
- const b = i(s, "css/_reset.css"), P = c.reset === "none" ? {} : typeof c.reset == "object" ? c.reset : Qt, N = await $t(P, "");
196
+ const b = i(s, "css/_reset.css"), P = c.reset === "none" ? {} : typeof c.reset == "object" ? c.reset : Qt, N = await St(P, "");
192
197
  C(b, `@layer reset { ${N} }`);
193
- const V = i(s, "css/_templates.css"), M = H(c.templates, n.templates), K = await Rt(M), Q = Jt(M);
194
- C(V, `@layer templates { ${K} }`), o.templates = M;
198
+ const V = i(s, "css/_templates.css"), R = H(c.templates, n.templates), K = await Mt(R), Q = Jt(R);
199
+ C(V, `@layer templates { ${K} }`), o.templates = R;
195
200
  const X = c.templates ? [Ht(c.templates)._setPath(`config;;${r}`)] : [], nt = Gt(n.templates, X);
196
201
  o.templatePaths = Object.fromEntries(Object.entries(nt).map(([h, S]) => [h, S._path]));
197
- const L = i(s, "types/css-tokens.d.ts"), kt = `
202
+ const L = i(s, "types/css-tokens.d.ts"), _t = `
198
203
  // Variable types
199
204
  type VariableTokens = ${[...p].join("|")};
200
205
  type PropertyValueToken = \`{\${VariableTokens}}\`;
@@ -208,19 +213,21 @@ const Qt = {
208
213
  // Media query types
209
214
  type MediaQueryKeys = ${w || "''"};
210
215
  `;
211
- C(L, kt);
212
- const Tt = i(s, "cache/config-cache.json");
213
- C(Tt, JSON.stringify(o, null, 2));
214
- const _t = Bt(), Vt = i(_t, "../cache/config-cache.json");
216
+ C(L, _t);
217
+ const Vt = i(s, "cache/config-cache.json");
215
218
  C(Vt, JSON.stringify(o, null, 2));
216
- }, bt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
219
+ const yt = Bt();
220
+ console.log("corePackageRoot", yt);
221
+ const ht = i(yt, "cache/config-cache.json");
222
+ console.log("Config cache secondary path", ht), C(ht, JSON.stringify(o, null, 2));
223
+ }, Ct = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
217
224
  if (/^['"`]/.test(s)) return e;
218
225
  const c = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
219
226
  if (!c.test(t)) return e;
220
227
  const o = c.exec(t);
221
228
  if (o) {
222
229
  const d = o.at(1);
223
- if (xt.some((p) => d == null ? void 0 : d.includes(p))) return e;
230
+ if (Dt.some((p) => d == null ? void 0 : d.includes(p))) return e;
224
231
  }
225
232
  return "styled('div',";
226
233
  }), Xt = (t, e) => {
@@ -239,9 +246,9 @@ ${t}`;
239
246
  ft(c) || G(c);
240
247
  const r = tt(e);
241
248
  let o = _(e, "utf8");
242
- o = bt(o), o = Xt(o, t);
243
- const d = i(s, "js", n + ".js"), w = await pt(t), p = i(t, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), a = Nt(p), y = await Pt(t);
244
- await St.build({
249
+ o = Ct(o), o = Xt(o, t);
250
+ const d = i(s, "js", n + ".js"), w = await pt(t), p = i(t, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), a = kt(p), g = await Nt(t);
251
+ await Ft.build({
245
252
  stdin: {
246
253
  contents: o,
247
254
  sourcefile: r.base,
@@ -252,7 +259,7 @@ ${t}`;
252
259
  treeShaking: !0,
253
260
  bundle: !0,
254
261
  outfile: d,
255
- format: y,
262
+ format: g,
256
263
  target: ["node20"],
257
264
  keepNames: !0,
258
265
  external: a,
@@ -263,7 +270,7 @@ ${t}`;
263
270
  setup: (m) => {
264
271
  m.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (F) => {
265
272
  const x = _(F.path, "utf8");
266
- return { contents: bt(x), loader: "ts" };
273
+ return { contents: Ct(x), loader: "ts" };
267
274
  });
268
275
  }
269
276
  }
@@ -293,19 +300,19 @@ ${t}`;
293
300
  ft(o) && vt("rm -rf " + o), G(o, { recursive: !0 }), G(i(o, "css")), G(i(o, "types")), G(i(o, "js")), G(i(o, "cache"));
294
301
  })();
295
302
  const p = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
296
- async function y(f) {
303
+ async function g(f) {
297
304
  const $ = ["node_modules", "saltygen"], b = Et(f);
298
305
  if (b.isDirectory()) {
299
306
  const l = Ot(f);
300
307
  if ($.some((N) => f.includes(N))) return;
301
- await Promise.all(l.map((N) => y(i(f, N))));
308
+ await Promise.all(l.map((N) => g(i(f, N))));
302
309
  } else if (b.isFile() && mt(f)) {
303
310
  p.add(f);
304
311
  const P = _(f, "utf8");
305
312
  /define[\w\d]+\(/.test(P) && a.add(f);
306
313
  }
307
314
  }
308
- await y(t), await At(t, a);
315
+ await g(t), await At(t, a);
309
316
  const u = {
310
317
  keyframes: [],
311
318
  components: [],
@@ -330,7 +337,7 @@ ${t}`;
330
337
  });
331
338
  })
332
339
  );
333
- const g = await ut(t);
340
+ const y = await ut(t);
334
341
  for (const f of u.keyframes) {
335
342
  const { value: $ } = f, b = `a_${$.animationName}.css`, l = `css/${b}`, P = i(o, l);
336
343
  c.push(b), C(P, $.css);
@@ -342,14 +349,14 @@ ${t}`;
342
349
  const l = f.generator._withBuildContext({
343
350
  callerName: b,
344
351
  isProduction: e,
345
- config: g
352
+ config: y
346
353
  });
347
354
  r[l.priority] || (r[l.priority] = []);
348
355
  const P = await l.css;
349
356
  if (!P) continue;
350
357
  r[l.priority].push(l.cssFileName);
351
358
  const N = `css/${l.cssFileName}`, V = i(o, N);
352
- C(V, P), g.importStrategy === "component" && m[$].push(l.cssFileName);
359
+ C(V, P), y.importStrategy === "component" && m[$].push(l.cssFileName);
353
360
  }
354
361
  for (const f of u.classNames) {
355
362
  const { src: $, name: b } = f;
@@ -357,15 +364,15 @@ ${t}`;
357
364
  const l = f.generator._withBuildContext({
358
365
  callerName: b,
359
366
  isProduction: e,
360
- config: g
367
+ config: y
361
368
  }), P = await l.css;
362
369
  if (!P) continue;
363
370
  r[l.priority] || (r[l.priority] = []), r[l.priority].push(l.cssFileName);
364
371
  const N = `css/${l.cssFileName}`, V = i(o, N);
365
- C(V, P), g.importStrategy === "component" && m[$].push(l.cssFileName);
372
+ C(V, P), y.importStrategy === "component" && m[$].push(l.cssFileName);
366
373
  }
367
- g.importStrategy === "component" && Object.entries(m).forEach(([f, $]) => {
368
- const b = $.map((M) => `@import url('./${M}');`).join(`
374
+ y.importStrategy === "component" && Object.entries(m).forEach(([f, $]) => {
375
+ const b = $.map((R) => `@import url('./${R}');`).join(`
369
376
  `), l = I(f, 6), P = tt(f), N = U(P.name), V = i(o, `css/f_${N}-${l}.css`);
370
377
  C(V, b || "/* Empty file */");
371
378
  });
@@ -388,7 +395,7 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) =
388
395
  `
389
396
  )}
390
397
  ${F}`;
391
- if (g.importStrategy !== "component") {
398
+ if (y.importStrategy !== "component") {
392
399
  const f = r.reduce(($, b, l) => {
393
400
  const P = b.reduce((K, Q) => {
394
401
  var ot;
@@ -398,9 +405,9 @@ ${F}`;
398
405
  ${nt}
399
406
  /*end:${L}*/
400
407
  `;
401
- }, ""), N = `l_${l}.css`, V = i(o, "css", N), M = `@layer l${l} { ${P}
408
+ }, ""), N = `l_${l}.css`, V = i(o, "css", N), R = `@layer l${l} { ${P}
402
409
  }`;
403
- return C(V, M), `${$}
410
+ return C(V, R), `${$}
404
411
  @import url('./css/${N}');`;
405
412
  }, "");
406
413
  A += f;
@@ -430,8 +437,8 @@ ${nt}
430
437
  }), F = await m.css;
431
438
  if (!F) continue;
432
439
  r[m.priority] || (r[m.priority] = []), r[m.priority].push(m.cssFileName);
433
- const x = `css/${m.cssFileName}`, D = i(n, x);
434
- C(D, F);
440
+ const x = `css/${m.cssFileName}`, k = i(n, x);
441
+ C(k, F);
435
442
  continue;
436
443
  }
437
444
  if (!p.generator) continue;
@@ -439,20 +446,20 @@ ${nt}
439
446
  callerName: w,
440
447
  isProduction: s,
441
448
  config: o
442
- }), y = await a.css;
443
- if (!y) continue;
444
- const u = `css/${a.cssFileName}`, g = i(n, u);
445
- C(g, y), r[a.priority] || (r[a.priority] = []), r[a.priority].push(a.cssFileName);
449
+ }), g = await a.css;
450
+ if (!g) continue;
451
+ const u = `css/${a.cssFileName}`, y = i(n, u);
452
+ C(y, g), r[a.priority] || (r[a.priority] = []), r[a.priority].push(a.cssFileName);
446
453
  }
447
454
  if (o.importStrategy !== "component")
448
455
  r.forEach((w, p) => {
449
- const a = `l_${p}.css`, y = i(n, "css", a);
450
- let u = _(y, "utf8");
451
- w.forEach((g) => {
452
- var D;
453
- const m = i(n, "css", g), F = ((D = /.*-([^-]+)-\d+.css/.exec(g)) == null ? void 0 : D.at(1)) || I(m, 6);
456
+ const a = `l_${p}.css`, g = i(n, "css", a);
457
+ let u = _(g, "utf8");
458
+ w.forEach((y) => {
459
+ var k;
460
+ const m = i(n, "css", y), F = ((k = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : k.at(1)) || I(m, 6);
454
461
  if (!u.includes(F)) {
455
- const E = _(m, "utf8"), z = `/*start:${F}-${g}*/
462
+ const E = _(m, "utf8"), z = `/*start:${F}-${y}*/
456
463
  ${E}
457
464
  /*end:${F}*/
458
465
  `;
@@ -460,11 +467,11 @@ ${E}
460
467
  ${z}
461
468
  }`;
462
469
  }
463
- }), C(y, u);
470
+ }), C(g, u);
464
471
  });
465
472
  else {
466
- const w = r.flat().map((g) => `@import url('./${g}');`).join(`
467
- `), p = I(e, 6), a = tt(e), y = U(a.name), u = i(n, `css/f_${y}-${p}.css`);
473
+ const w = r.flat().map((y) => `@import url('./${y}');`).join(`
474
+ `), p = I(e, 6), a = tt(e), g = U(a.name), u = i(n, `css/f_${g}-${p}.css`);
468
475
  C(u, w || "/* Empty file */");
469
476
  }
470
477
  }
@@ -478,25 +485,25 @@ ${z}
478
485
  if (mt(e)) {
479
486
  const d = _(e, "utf8"), w = await ut(t), { contents: p } = await et(t, e, r);
480
487
  let a = d;
481
- for (const [y, u] of Object.entries(p)) {
488
+ for (const [g, u] of Object.entries(p)) {
482
489
  if (u.isKeyframes || !u.generator) continue;
483
- const g = u.generator._withBuildContext({
484
- callerName: y,
490
+ const y = u.generator._withBuildContext({
491
+ callerName: g,
485
492
  isProduction: s,
486
493
  config: w
487
- }), [m, F] = await Lt(a, y), x = a.slice(m, F);
494
+ }), [m, F] = await Lt(a, g), x = a.slice(m, F);
488
495
  if (u.isClassName) {
489
- const D = a, E = ` ${y} = className("${g.classNames}")`;
490
- a = a.replace(x, E), D === a && console.error("Minimize file failed to change content", { name: y });
496
+ const k = a, E = ` ${g} = className("${y.classNames}")`;
497
+ a = a.replace(x, E), k === a && console.error("Minimize file failed to change content", { name: g });
491
498
  }
492
499
  if (x.includes("styled")) {
493
- const D = (c = (n = /styled\(([^,]+),/.exec(x)) == null ? void 0 : n.at(1)) == null ? void 0 : c.trim(), E = a, z = ` ${y} = styled(${D}, "${g.classNames}", ${JSON.stringify(g.clientProps)})`;
494
- a = a.replace(x, z), E === a && console.error("Minimize file failed to change content", { name: y, tagName: D });
500
+ const k = (c = (n = /styled\(([^,]+),/.exec(x)) == null ? void 0 : n.at(1)) == null ? void 0 : c.trim(), E = a, z = ` ${g} = styled(${k}, "${y.classNames}", ${JSON.stringify(y.clientProps)})`;
501
+ a = a.replace(x, z), E === a && console.error("Minimize file failed to change content", { name: g, tagName: k });
495
502
  }
496
503
  }
497
504
  if (w.importStrategy === "component") {
498
- const y = I(e, 6), u = tt(e);
499
- a = `import '../../saltygen/css/${`f_${U(u.name)}-${y}.css`}';
505
+ const g = I(e, 6), u = tt(e);
506
+ a = `import '../../saltygen/css/${`f_${U(u.name)}-${g}.css`}';
500
507
  ${a}`;
501
508
  }
502
509
  return a = a.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
@@ -507,13 +514,14 @@ ${a}`;
507
514
  };
508
515
  export {
509
516
  fe as a,
510
- pe as b,
511
- qt as c,
512
- At as d,
513
- et as e,
514
- me as g,
517
+ me as b,
518
+ pe as c,
519
+ qt as d,
520
+ At as e,
521
+ et as f,
522
+ Bt as g,
515
523
  mt as i,
516
524
  Z as l,
517
525
  ue as m,
518
- xt as s
526
+ Dt as s
519
527
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.281",
3
+ "version": "0.0.1-alpha.283",
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 e=require("../should-restart-CFLKMt9i.cjs");exports.checkShouldRestart=e.checkShouldRestart;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-BFVRQc0_.cjs");exports.checkShouldRestart=e.checkShouldRestart;
package/server/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as o } from "../should-restart-mZFoFAt4.js";
1
+ import { c as o } from "../should-restart-CR-ZEYLq.js";
2
2
  export {
3
3
  o as checkShouldRestart
4
4
  };
@@ -1 +1 @@
1
- "use strict";const s=require("fs/promises"),r=require("./index-CidX_d4J.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)||/.+keyframes\(.+/.test(e))};exports.checkShouldRestart=i;
1
+ "use strict";const s=require("fs/promises"),r=require("./index-BYrtB4JM.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)||/.+keyframes\(.+/.test(e))};exports.checkShouldRestart=i;
@@ -1,5 +1,5 @@
1
1
  import { readFile as r } from "fs/promises";
2
- import { i as e } from "./index-D3EUFKhD.js";
2
+ import { i as e } from "./index-CR0k7PXM.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,41 +0,0 @@
1
- "use strict";const Oe=require("esbuild"),Re=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),Se=require("fs/promises"),ce=require("./parse-styles-Bdgw_4ME.cjs"),he=require("./parsers/index.cjs"),Q=require("winston"),q=require("./css/merge.cjs"),ve=require("./define-templates-Cunsb_Tr.cjs"),re=require("typescript");var R=typeof document<"u"?document.currentScript:null;function Ee(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 je=Ee(Oe),be=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:be(i.join(e,".."))},Ve=async e=>{const t=be(e);return await Se.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Me=async e=>{const t=await Ve(e);if(t)return t.type};let U;const Fe=async e=>{if(U)return U;const t=await Me(e);return t==="module"?U="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index-CidX_d4J.cjs",document.baseURI).href).endsWith(".cjs"))&&(U="cjs"),U||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),Je=e=>{B.error(e)};function $e(e){return e?typeof e!="string"?$e(String(e)):e.replace(/[^\d\w]/g,"."):""}const qe={"*, *::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"}},ze=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=re.createSourceFile("temp.ts",e,re.ScriptTarget.Latest,!0);function o(y){if(re.isVariableDeclaration(y)&&y.name.getText()===t){const S=y.getStart(),p=y.getEnd();clearTimeout(r),s([S,p])}y.forEachChild(o)}o(l)}),Ie=()=>(console.log("dirname",typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index-CidX_d4J.cjs",document.baseURI).href),new URL(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index-CidX_d4J.cjs",document.baseURI).href).pathname),v={externalModules:[],rcFile:void 0,destDir:void 0},Ce=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},z=async e=>{if(v.destDir)return v.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return v.destDir=s,s},le=["salty","css","styles","styled"],Pe=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),ee=(e,t=[])=>Pe(t).test(e),Ne=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 Se.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):Ne(i.join(e,".."))},fe=async e=>{var n,r;const t=await Ne(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},Ue=async e=>{const t=await fe(e),s=await z(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await Fe(e),o=Ce(n);await je.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:S}=await import(`${r}?t=${y}`);return{config:S,path:r}},xe=async(e,t)=>{var me,ye;const s=await z(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:F,outputFilePath:G}=await A(e,w,s);Object.entries(F).forEach(([T,P])=>{P.isMedia?n.mediaQueries.push([T,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${T};;${G}`))})}));const{config:r,path:l}=await Ue(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([w,F])=>[`@${w}`,F]));const S=y.map(([w])=>`'@${w}'`).join(" | "),p=new Set,a=async(w,F=[])=>{if(!w)return[];const G=Object.entries(w).map(async([P,J])=>{const K=async k=>{if(!k)return;if(k instanceof Promise)return await K(await k);if(typeof k=="function")return await K(await k());if(typeof k=="object")return await a(k,[...F,P]);const oe=$e(P),ie=D.dashCase(P),ae=[...F,oe].join(".");p.add(`"${ae}"`);const Z=[...F.map(D.dashCase),ie].join("-"),ge=ce.parseVariableTokens(k);return ge?`--${Z}: ${ge.transformed};`:`--${Z}: ${k};`};return await K(J)});return(await Promise.all(G)).flat()},g=async w=>{if(!w)return[];const F=Object.entries(w).map(async([T,P])=>{const J=await a(P);return T==="base"?J.join(""):o.mediaQueries[T]?`${o.mediaQueries[T]} { ${J.join("")} }`:`${T} { ${J.join("")} }`});return(await Promise.all(F)).flat()},m=async w=>{if(!w)return[];const F=Object.entries(w).map(async([T,P])=>{const J=Object.entries(P).map(async([k,oe])=>{const ie=await a(oe,[T]),ae=`.${T}-${k}, [data-${T}="${k}"]`,Z=ie.join("");return`${ae} { ${Z} }`});return(await Promise.all(J)).flat()});return(await Promise.all(F)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),d=w=>n.variables.map(F=>w==="static"?h(F._current):F._current[w]),$=q.mergeObjects(h(r.variables),d("static")),x=await a($),_=q.mergeObjects((me=r.variables)==null?void 0:me.responsive,d("responsive")),E=await g(_),I=q.mergeObjects((ye=r.variables)==null?void 0:ye.conditional,d("conditional")),X=await m(I),pe=i.join(s,"css/_variables.css"),V=`:root { ${x.join("")} ${E.join("")} } ${X.join("")}`;c.writeFileSync(pe,V),o.staticVariables=$;const te=i.join(s,"css/_global.css"),u=q.mergeObjects(r.global,n.globalStyles),j=await ce.parseAndJoinStyles(u,"");c.writeFileSync(te,`@layer global { ${j} }`);const b=i.join(s,"css/_reset.css"),C=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:qe,N=await ce.parseAndJoinStyles(C,"");c.writeFileSync(b,`@layer reset { ${N} }`);const O=i.join(s,"css/_templates.css"),M=q.mergeObjects(r.templates,n.templates),H=await he.parseTemplates(M),L=he.getTemplateTypes(M);c.writeFileSync(O,`@layer templates { ${H} }`),o.templates=M;const Y=r.templates?[ve.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],se=q.mergeFactories(n.templates,Y);o.templatePaths=Object.fromEntries(Object.entries(se).map(([w,F])=>[w,F._path]));const W=i.join(s,"types/css-tokens.d.ts"),_e=`
2
- // Variable types
3
- type VariableTokens = ${[...p].join("|")};
4
- type PropertyValueToken = \`{\${VariableTokens}}\`;
5
-
6
- // Template types
7
- type TemplateTokens = {
8
- ${Object.entries(L).map(([w,F])=>`${w}?: ${F}`).join(`
9
- `)}
10
- }
11
-
12
- // Media query types
13
- type MediaQueryKeys = ${S||"''"};
14
- `;c.writeFileSync(W,_e);const Te=i.join(s,"cache/config-cache.json");c.writeFileSync(Te,JSON.stringify(o,null,2));const ke=Ie(),De=i.join(ke,"../cache/config-cache.json");c.writeFileSync(De,JSON.stringify(o,null,2))},we=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 o=r.exec(e);if(o){const y=o.at(1);if(le.some(p=>y==null?void 0:y.includes(p)))return t}return"styled('div',"}),He=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
15
-
16
- ${e}`:`globalThis.saltyConfig = {};
17
-
18
- ${e}`}catch{return e}},A=async(e,t,s)=>{const n=D.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=we(o),o=He(o,e);const y=i.join(s,"js",n+".js"),S=await fe(e),p=i.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),a=Ce(p),g=await Fe(e);await je.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},$=>{const x=c.readFileSync($.path,"utf8");return{contents:we(x),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},Le=async e=>{const t=await z(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)},ue=async e=>{const t=await Le(e),s=await z(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return q.mergeObjects(l,t)},de=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},We=async(e,t=de(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await z(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&Re.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const p=new Set,a=new Set;async function g(u){const j=["node_modules","saltygen"],b=c.statSync(u);if(b.isDirectory()){const f=c.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(i.join(u,N))))}else if(b.isFile()&&ee(u)){p.add(u);const C=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&a.add(u)}}await g(e),await xe(e,a);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...p].map(async u=>{const{contents:j}=await A(e,u,o);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:b}):f.isClassName?m.classNames.push({...f,src:u,name:b}):f.generator&&m.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of m.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=i.join(o,f);r.push(b),c.writeFileSync(C,j.css)}const d={};for(const u of m.components){const{src:j,name:b}=u;d[j]||(d[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});l[f.priority]||(l[f.priority]=[]);const C=await f.css;if(!C)continue;l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&d[j].push(f.cssFileName)}for(const u of m.classNames){const{src:j,name:b}=u;d[j]||(d[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;l[f.priority]||(l[f.priority]=[]),l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&d[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(d).forEach(([u,j])=>{const b=j.map(M=>`@import url('./${M}');`).join(`
19
- `),f=D.toHash(u,6),C=i.parse(u),N=D.dashCase(C.name),O=i.join(o,`css/f_${N}-${f}.css`);c.writeFileSync(O,b||"/* Empty file */")});const $=r.map(u=>`@import url('./css/${u}');`).join(`
20
- `);let X=`/*!
21
- * Generated with Salty CSS (https://salty-css.dev)
22
- * Do not edit this file directly
23
- */
24
- @layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
25
-
26
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return c.readFileSync(i.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
27
- `)}
28
- ${$}`;if(h.importStrategy!=="component"){const u=l.reduce((j,b,f)=>{const C=b.reduce((H,L)=>{var ne;const Y=i.join(o,"css",L),se=c.readFileSync(Y,"utf8"),W=((ne=/.*-([^-]+)-\d+.css/.exec(L))==null?void 0:ne.at(1))||D.toHash(Y,6);return H.includes(W)?H:`${H}
29
- /*start:${W}-${L}*/
30
- ${se}
31
- /*end:${W}*/
32
- `},""),N=`l_${f}.css`,O=i.join(o,"css",N),M=`@layer l${f} { ${C}
33
- }`;return c.writeFileSync(O,M),`${j}
34
- @import url('./css/${N}');`},"");X+=u}c.writeFileSync(y,X);const V=Date.now()-n,te=V<200?"🔥":V<500?"🚀":V<1e3?"🎉":V<2e3?"🚗":V<5e3?"🤔":"🥴";B.info(`Generated CSS in ${V}ms! ${te}`)}catch(n){console.error(n)}},Ge=async(e,t,s=de())=>{try{const n=await z(e);if(ee(t)){const l=[],o=await ue(e),{contents:y}=await A(e,t,n);for(const[S,p]of Object.entries(y)){if(p.isKeyframes&&p.css){const $=`css/${`a_${p.animationName}.css`}`,x=i.join(n,$);c.writeFileSync(x,await p.css);continue}if(p.isClassName){const d=p.generator._withBuildContext({callerName:S,isProduction:s,config:o}),$=await d.css;if(!$)continue;l[d.priority]||(l[d.priority]=[]),l[d.priority].push(d.cssFileName);const x=`css/${d.cssFileName}`,_=i.join(n,x);c.writeFileSync(_,$);continue}if(!p.generator)continue;const a=p.generator._withBuildContext({callerName:S,isProduction:s,config:o}),g=await a.css;if(!g)continue;const m=`css/${a.cssFileName}`,h=i.join(n,m);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((S,p)=>{const a=`l_${p}.css`,g=i.join(n,"css",a);let m=c.readFileSync(g,"utf8");S.forEach(h=>{var _;const d=i.join(n,"css",h),$=((_=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:_.at(1))||D.toHash(d,6);if(!m.includes($)){const E=c.readFileSync(d,"utf8"),I=`/*start:${$}-${h}*/
35
- ${E}
36
- /*end:${$}*/
37
- `;m=`${m.replace(/\}$/,"")}
38
- ${I}
39
- }`}}),c.writeFileSync(g,m)});else{const S=l.flat().map(h=>`@import url('./${h}');`).join(`
40
- `),p=D.toHash(t,6),a=i.parse(t),g=D.dashCase(a.name),m=i.join(n,`css/f_${g}-${p}.css`);c.writeFileSync(m,S||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=de())=>{var n,r;try{const l=await z(e);if(ee(t)){const y=c.readFileSync(t,"utf8"),S=await ue(e),{contents:p}=await A(e,t,l);let a=y;for(const[g,m]of Object.entries(p)){if(m.isKeyframes||!m.generator)continue;const h=m.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[d,$]=await ze(a,g),x=a.slice(d,$);if(m.isClassName){const _=a,E=` ${g} = className("${h.classNames}")`;a=a.replace(x,E),_===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const _=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),E=a,I=` ${g} = styled(${_}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,I),E===a&&console.error("Minimize file failed to change content",{name:g,tagName:_})}}if(S.importStrategy==="component"){const g=D.toHash(t,6),m=i.parse(t);a=`import '../../saltygen/css/${`f_${D.dashCase(m.name)}-${g}.css`}';
41
- ${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=A;exports.generateConfigStyles=xe;exports.generateCss=We;exports.generateFile=Ge;exports.isSaltyFile=ee;exports.logError=Je;exports.logger=B;exports.minimizeFile=Ke;exports.saltyFileExtensions=le;exports.saltyFileRegExp=Pe;