@salty-css/core 0.0.1-alpha.100 → 0.0.1-alpha.102

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 ee=require("commander"),G=require("fs"),s=require("fs/promises"),i=require("path"),te=require("ejs"),t=require("../index-BKoD9apd.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),ne=require("child_process"),se=require("ora");var z=typeof document<"u"?document.currentScript:null;const Q=p=>new Promise((w,j)=>{ne.exec(p,k=>{if(k)return j(k);w()})}),N=async(...p)=>{const w=p.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),j=se(`Installing packages: ${w}`).start(),k=p.join(" ");await Q(`npm install ${k}`),j.succeed(`Installed packages: ${w}`)},oe=()=>G.existsSync(i.join(process.cwd(),"node_modules",".bin","prettier"));async function h(p){try{if(!oe())return;await Q(`./node_modules/.bin/prettier --write "${p}"`),t.logger.info(`Formatted ${p} with Prettier`)}catch(w){t.logger.error(`Error formatting ${p} with Prettier:`,w)}}async function ae(){const p=new ee.Command;p.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const w={"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"))},j=async(n,l)=>{const{default:d}=await w[n],u=te.render(d,l);return{fileName:n,content:u}},k=async()=>{const n=i.join(process.cwd(),".saltyrc.json");return await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>({}))},b=i.join(process.cwd(),"package.json"),D=async(n=b)=>{const l=await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>{});if(!l)throw"Could not read package.json file!";return l},X=async(n,l=b)=>{typeof n=="object"&&(n=JSON.stringify(n,null,2)),await s.writeFile(l,n)},B=async()=>{const n=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 D(n)},V=await(async()=>(await k()).defaultProject)(),$=await B(),q={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}`},U=n=>{const l=n==="."?"":n,d=process.cwd();return i.join(d,l)};p.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(n="."){if(!await D().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:d=n,cssFile:u,skipInstall:y}=this.opts();if(!d)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");y||await N(q.core,q.react);const f=process.cwd(),r=U(d),E=await Promise.all([j("salty.config.ts"),j("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=E.map(async({fileName:e,content:g})=>{const a=i.join(r,e);if(await s.readFile(a,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+a);return}const P=e.split("/").slice(0,-1).join("/");P&&await s.mkdir(i.join(r,P),{recursive:!0}),t.logger.info("Creating file: "+a),await s.writeFile(a,g),await h(a)});await Promise.all(m);const x=i.relative(f,r)||".",S=i.join(f,".saltyrc.json"),c=await s.readFile(S,"utf-8").catch(()=>{});if(c===void 0){t.logger.info("Creating file: "+S);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:x,projects:[{dir:x,framework:"react"}]},null,2);await s.writeFile(S,g),await h(S)}else{const e=JSON.parse(c),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===x)===-1){g.push({dir:x,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==c&&(t.logger.info("Edit file: "+S),await s.writeFile(S,o),await h(S))}}const C=i.join(f,".gitignore"),L=await s.readFile(C,"utf-8").catch(()=>{});L!==void 0&&(L.includes("saltygen")||(t.logger.info("Edit file: "+C),await s.writeFile(C,L+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("commander"),G=require("fs"),s=require("fs/promises"),i=require("path"),te=require("ejs"),t=require("../index-Dg0uHtov.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),ne=require("child_process"),se=require("ora");var z=typeof document<"u"?document.currentScript:null;const Q=p=>new Promise((w,j)=>{ne.exec(p,k=>{if(k)return j(k);w()})}),N=async(...p)=>{const w=p.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),j=se(`Installing packages: ${w}`).start(),k=p.join(" ");await Q(`npm install ${k}`),j.succeed(`Installed packages: ${w}`)},oe=()=>G.existsSync(i.join(process.cwd(),"node_modules",".bin","prettier"));async function h(p){try{if(!oe())return;await Q(`./node_modules/.bin/prettier --write "${p}"`),t.logger.info(`Formatted ${p} with Prettier`)}catch(w){t.logger.error(`Error formatting ${p} with Prettier:`,w)}}async function ae(){const p=new ee.Command;p.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const w={"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"))},j=async(n,l)=>{const{default:d}=await w[n],u=te.render(d,l);return{fileName:n,content:u}},k=async()=>{const n=i.join(process.cwd(),".saltyrc.json");return await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>({}))},b=i.join(process.cwd(),"package.json"),D=async(n=b)=>{const l=await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>{});if(!l)throw"Could not read package.json file!";return l},X=async(n,l=b)=>{typeof n=="object"&&(n=JSON.stringify(n,null,2)),await s.writeFile(l,n)},B=async()=>{const n=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 D(n)},V=await(async()=>(await k()).defaultProject)(),$=await B(),q={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}`},U=n=>{const l=n==="."?"":n,d=process.cwd();return i.join(d,l)};p.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(n="."){if(!await D().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:d=n,cssFile:u,skipInstall:y}=this.opts();if(!d)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");y||await N(q.core,q.react);const f=process.cwd(),r=U(d),E=await Promise.all([j("salty.config.ts"),j("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=E.map(async({fileName:e,content:g})=>{const a=i.join(r,e);if(await s.readFile(a,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+a);return}const P=e.split("/").slice(0,-1).join("/");P&&await s.mkdir(i.join(r,P),{recursive:!0}),t.logger.info("Creating file: "+a),await s.writeFile(a,g),await h(a)});await Promise.all(m);const x=i.relative(f,r)||".",S=i.join(f,".saltyrc.json"),c=await s.readFile(S,"utf-8").catch(()=>{});if(c===void 0){t.logger.info("Creating file: "+S);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:x,projects:[{dir:x,framework:"react"}]},null,2);await s.writeFile(S,g),await h(S)}else{const e=JSON.parse(c),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===x)===-1){g.push({dir:x,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==c&&(t.logger.info("Edit file: "+S),await s.writeFile(S,o),await h(S))}}const C=i.join(f,".gitignore"),L=await s.readFile(C,"utf-8").catch(()=>{});L!==void 0&&(L.includes("saltygen")||(t.logger.info("Edit file: "+C),await s.writeFile(C,L+`
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 V, readFile as m, writeFile as h } from "fs/promises";
4
4
  import { join as i, relative as z, parse as ot, format as Z } from "path";
5
5
  import { render as rt } from "ejs";
6
- import { l as e, a as S, g as tt } from "../index-BGaLvshf.js";
6
+ import { l as e, a as S, g as tt } from "../index-F3NHLX_N.js";
7
7
  import { p as ct } from "../pascal-case-BQpR5PdN.js";
8
8
  import { exec as lt } from "child_process";
9
9
  import dt from "ora";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-DKzpenwY.cjs");require("path");require("fs");require("fs/promises");require("../parse-templates-DVK3iZIl.cjs");const e=require("../index-BKoD9apd.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-DKzpenwY.cjs");require("path");require("fs");require("fs/promises");require("../parse-templates-DVK3iZIl.cjs");const e=require("../index-Dg0uHtov.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-templates-DUUSaubj.js";
8
- import { d as p, c as n, g, e as F, i as y, m as x, s as S, b as c } from "../index-BGaLvshf.js";
8
+ import { d as p, c as n, g, e as F, i as y, m as x, s as S, b as c } from "../index-F3NHLX_N.js";
9
9
  export {
10
10
  p as compileSaltyFile,
11
11
  n as generateConfigStyles,
@@ -0,0 +1,11 @@
1
+ "use strict";const te=require("esbuild"),se=require("child_process"),N=require("./dash-case-DKzpenwY.cjs"),o=require("path"),a=require("fs"),H=require("fs/promises"),J=require("./parse-templates-DVK3iZIl.cjs"),M=require("winston");var q=typeof document<"u"?document.currentScript:null;function ne(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const L=ne(te),U=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return a.existsSync(t)?t:U(o.join(e,".."))},oe=async e=>{const t=U(e);return await H.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ie=async e=>{const t=await oe(e);if(t)return t.type};let v;const G=async e=>{if(v)return v;const t=await ie(e);return t==="module"?v="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:q&&q.tagName.toUpperCase()==="SCRIPT"&&q.src||new URL("index-Dg0uHtov.cjs",document.baseURI).href).endsWith(".cjs"))&&(v="cjs"),v||"esm"},O=M.createLogger({level:"debug",format:M.format.combine(M.format.colorize(),M.format.cli()),transports:[new M.transports.Console({})]}),re=e=>{O.error(e)},I={externalModules:[]},W=e=>{if(I.externalModules.length>0)return I.externalModules;const t=o.join(e,"salty.config.ts"),s=a.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const i=s[1].split(",").map(u=>u.replace(/['"`]/g,"").trim());return I.externalModules=i,i},V=e=>o.join(e,"./saltygen"),K=["salty","css","styles","styled"],A=(e=[])=>new RegExp(`\\.(${[...K,...e].join("|")})\\.`),R=(e,t=[])=>A(t).test(e),ce=async e=>{const t=V(e),n=o.join(e,"salty.config.ts"),s=o.join(t,"salty.config.js"),i=await G(e),u=W(e);await L.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:i,external:u});const j=Date.now(),{config:f}=await import(`${s}?t=${j}`);return f},X=async e=>{const t=await ce(e),n=new Set,s=(g,l=[])=>g?Object.entries(g).flatMap(([m,p])=>{if(!p)return;if(typeof p=="object")return s(p,[...l,m]);const P=[...l,m].join(".");n.add(`"${P}"`);const x=[...l.map(N.dashCase),N.dashCase(m)].join("-"),{result:h}=J.parseValueTokens(p);return`--${x}: ${h};`}):[],i=g=>g?Object.entries(g).flatMap(([l,m])=>{const p=s(m);return l==="base"?p.join(""):`${l} { ${p.join("")} }`}):[],u=g=>g?Object.entries(g).flatMap(([l,m])=>Object.entries(m).flatMap(([p,P])=>{const x=s(P,[l]),h=`.${l}-${p}, [data-${l}="${p}"]`,F=x.join("");return`${h} { ${F} }`})):[],j=s(t.variables),f=i(t.responsiveVariables),S=u(t.conditionalVariables),r=V(e),D=o.join(r,"css/variables.css"),d=`:root { ${j.join("")} ${f.join("")} } ${S.join("")}`;a.writeFileSync(D,d);const w=o.join(r,"types/css-tokens.d.ts"),c=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;a.writeFileSync(w,c);const y=o.join(r,"css/global.css"),k=J.parseStyles(t.global,"");a.writeFileSync(y,k);const b=o.join(r,"css/templates.css"),C=J.parseTemplates(t.templates);a.writeFileSync(b,C)},_=async(e,t,n)=>{const s=N.toHash(t),i=o.join(n,"./temp");a.existsSync(i)||a.mkdirSync(i);const u=o.parse(t);let j=a.readFileSync(t,"utf8");j=j.replace("styled(DynaLink","styled('div'");const f=o.join(n,"js",s+".js"),S=W(e),r=await G(e);await L.build({stdin:{contents:j,sourcefile:u.base,resolveDir:u.dir,loader:"ts"},minify:!1,treeShaking:!0,bundle:!0,outfile:f,format:r,target:["node20"],keepNames:!0,external:S,packages:"external"});const D=Date.now();return await import(`${f}?t=${D}`)},z=async e=>{const t=V(e),n=o.join(t,"salty.config.js"),{config:s}=await import(n);return s},Y=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(e,t=Y())=>{try{t?O.info("Generating CSS in production mode! 🔥"):O.info("Generating CSS in development mode! 🚀");const n=[],s=[],i=V(e),u=o.join(i,"index.css");(()=>{a.existsSync(i)&&se.execSync("rm -rf "+i),a.mkdirSync(i),a.mkdirSync(o.join(i,"css")),a.mkdirSync(o.join(i,"types"))})(),await X(e);const f=await z(e);async function S(c,y){const k=["node_modules","saltygen"],b=a.statSync(c);if(b.isDirectory()){const C=a.readdirSync(c);if(k.some(l=>c.includes(l)))return;await Promise.all(C.map(l=>S(o.join(c,l),o.join(y,l))))}else if(b.isFile()&&R(c)){const g=await _(e,c,i),l=[];Object.entries(g).forEach(([x,h])=>{if(h.isKeyframes&&h.css){const B=`${h.animationName}.css`,Q=`css/${B}`,ee=o.join(i,Q);n.push(B),a.writeFileSync(ee,h.css);return}if(!h.generator)return;const F=h.generator._withBuildContext({name:x,config:f,prod:t}),T=`${F.hash}-${F.priority}.css`;s[F.priority]||(s[F.priority]=[]),s[F.priority].push(T),l.push(T);const E=`css/${T}`,Z=o.join(i,E);a.writeFileSync(Z,F.css)});const m=l.map(x=>`@import url('./${x}');`).join(`
2
+ `),p=N.toHash(c,6),P=o.join(i,`css/${p}.css`);a.writeFileSync(P,m)}}await S(e,i);const r=n.map(c=>`@import url('./css/${c}');`).join(`
3
+ `);let $=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
4
+
5
+ ${["variables.css","global.css","templates.css"].filter(c=>{try{return a.readFileSync(o.join(i,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
6
+ `)}
7
+ ${r}`;if(f.importStrategy!=="component"){const c=s.flat().map(y=>`@import url('./css/${y}');`).join(`
8
+ `);$+=c}a.writeFileSync(u,$)}catch(n){console.error(n)}},le=async(e,t)=>{try{const n=[],s=o.join(e,"./saltygen"),i=o.join(s,"index.css");if(R(t)){const j=await z(e),f=await _(e,t,s);Object.entries(f).forEach(([w,$])=>{if(!$.generator)return;const c=$.generator._withBuildContext({name:w,config:j}),y=`${c.hash}-${c.priority}.css`,k=`css/${y}`,b=o.join(s,k);n.push(y),a.writeFileSync(b,c.css)});const S=a.readFileSync(i,"utf8").split(`
9
+ `),r=n.map(w=>`@import url('../saltygen/css/${w}');`),d=[...new Set([...S,...r])].join(`
10
+ `);a.writeFileSync(i,d)}}catch(n){console.error(n)}},ue=async(e,t,n=Y())=>{try{const s=o.join(e,"./saltygen");if(R(t)){const u=a.readFileSync(t,"utf8");u.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==u&&await H.writeFile(t,u);const f=await z(e),S=await _(e,t,s);let r=u;Object.entries(S).forEach(([d,w])=>{var T;if(w.isKeyframes||!w.generator)return;const $=w.generator._withBuildContext({name:d,config:f,prod:n}),c=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(u);if(!c)return console.error("Could not find the original declaration");const y=(T=c.at(1))==null?void 0:T.trim(),k=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(r);if(!k)return console.error("Could not find the original declaration");const{index:b}=k;let C=!1;const g=setTimeout(()=>C=!0,5e3);let l=0,m=!1,p=0;for(;!m&&!C;){const E=r[b+l];E==="("&&p++,E===")"&&p--,p===0&&E===")"&&(m=!0),l>r.length&&(C=!0),l++}if(!C)clearTimeout(g);else throw new Error("Failed to find the end of the styled call and timed out");const P=b+l,x=r.slice(b,P),h=r,F=` ${d} = styled(${y}, "${$.classNames}", ${JSON.stringify($.props)});`;r=r.replace(x,F),h===r&&console.error("Minimize file failed to change content",{name:d,tagName:y})});const D=N.toHash(t,6);return f.importStrategy==="component"&&(r=`import '../../saltygen/css/${D}.css';
11
+ ${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(s){console.error("Error in minimizeFile:",s)}};exports.compileSaltyFile=_;exports.generateConfigStyles=X;exports.generateCss=ae;exports.generateFile=le;exports.isSaltyFile=R;exports.logError=re;exports.logger=O;exports.minimizeFile=ue;exports.saltyFileExtensions=K;exports.saltyFileRegExp=A;
@@ -0,0 +1,243 @@
1
+ import * as K from "esbuild";
2
+ import { execSync as Q } from "child_process";
3
+ import { t as B, d as H } from "./dash-case-DMQMcCO6.js";
4
+ import { join as r, parse as tt } from "path";
5
+ import { existsSync as I, writeFileSync as C, mkdirSync as N, readFileSync as E, statSync as st, readdirSync as et } from "fs";
6
+ import { readFile as nt, writeFile as ot } from "fs/promises";
7
+ import { p as rt, a as at, b as ct } from "./parse-templates-DUUSaubj.js";
8
+ import { createLogger as it, format as J, transports as lt } from "winston";
9
+ const L = (t) => {
10
+ if (!t || t === "/") throw new Error("Could not find package.json file");
11
+ const s = r(t, "package.json");
12
+ return I(s) ? s : L(r(t, ".."));
13
+ }, pt = async (t) => {
14
+ const s = L(t);
15
+ return await nt(s, "utf-8").then(JSON.parse).catch(() => {
16
+ });
17
+ }, ft = async (t) => {
18
+ const s = await pt(t);
19
+ if (s)
20
+ return s.type;
21
+ };
22
+ let T;
23
+ const q = async (t) => {
24
+ if (T) return T;
25
+ const s = await ft(t);
26
+ return s === "module" ? T = "esm" : (s === "commonjs" || import.meta.url.endsWith(".cjs")) && (T = "cjs"), T || "esm";
27
+ }, R = it({
28
+ level: "debug",
29
+ format: J.combine(J.colorize(), J.cli()),
30
+ transports: [new lt.Console({})]
31
+ }), xt = (t) => {
32
+ R.error(t);
33
+ }, O = {
34
+ externalModules: []
35
+ }, A = (t) => {
36
+ if (O.externalModules.length > 0) return O.externalModules;
37
+ const s = r(t, "salty.config.ts"), e = E(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
38
+ if (!e) return [];
39
+ const n = e[1].split(",").map((l) => l.replace(/['"`]/g, "").trim());
40
+ return O.externalModules = n, n;
41
+ }, V = (t) => r(t, "./saltygen"), ut = ["salty", "css", "styles", "styled"], gt = (t = []) => new RegExp(`\\.(${[...ut, ...t].join("|")})\\.`), _ = (t, s = []) => gt(s).test(t), dt = async (t) => {
42
+ const s = V(t), c = r(t, "salty.config.ts"), e = r(s, "salty.config.js"), n = await q(t), l = A(t);
43
+ await K.build({
44
+ entryPoints: [c],
45
+ minify: !0,
46
+ treeShaking: !0,
47
+ bundle: !0,
48
+ outfile: e,
49
+ format: n,
50
+ external: l
51
+ });
52
+ const h = Date.now(), { config: f } = await import(`${e}?t=${h}`);
53
+ return f;
54
+ }, mt = async (t) => {
55
+ const s = await dt(t), c = /* @__PURE__ */ new Set(), e = (g, i = []) => g ? Object.entries(g).flatMap(([m, p]) => {
56
+ if (!p) return;
57
+ if (typeof p == "object") return e(p, [...i, m]);
58
+ const P = [...i, m].join(".");
59
+ c.add(`"${P}"`);
60
+ const j = [...i.map(H), H(m)].join("-"), { result: y } = ct(p);
61
+ return `--${j}: ${y};`;
62
+ }) : [], n = (g) => g ? Object.entries(g).flatMap(([i, m]) => {
63
+ const p = e(m);
64
+ return i === "base" ? p.join("") : `${i} { ${p.join("")} }`;
65
+ }) : [], l = (g) => g ? Object.entries(g).flatMap(([i, m]) => Object.entries(m).flatMap(([p, P]) => {
66
+ const j = e(P, [i]), y = `.${i}-${p}, [data-${i}="${p}"]`, S = j.join("");
67
+ return `${y} { ${S} }`;
68
+ })) : [], h = e(s.variables), f = n(s.responsiveVariables), b = l(s.conditionalVariables), o = V(t), D = r(o, "css/variables.css"), u = `:root { ${h.join("")} ${f.join("")} } ${b.join("")}`;
69
+ C(D, u);
70
+ const $ = r(o, "types/css-tokens.d.ts"), a = `type VariableTokens = ${[...c].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
71
+ C($, a);
72
+ const d = r(o, "css/global.css"), k = rt(s.global, "");
73
+ C(d, k);
74
+ const w = r(o, "css/templates.css"), F = at(s.templates);
75
+ C(w, F);
76
+ }, z = async (t, s, c) => {
77
+ const e = B(s), n = r(c, "./temp");
78
+ I(n) || N(n);
79
+ const l = tt(s);
80
+ let h = E(s, "utf8");
81
+ h = h.replace("styled(DynaLink", "styled('div'");
82
+ const f = r(c, "js", e + ".js"), b = A(t), o = await q(t);
83
+ await K.build({
84
+ stdin: {
85
+ contents: h,
86
+ sourcefile: l.base,
87
+ resolveDir: l.dir,
88
+ loader: "ts"
89
+ },
90
+ minify: !1,
91
+ treeShaking: !0,
92
+ bundle: !0,
93
+ outfile: f,
94
+ format: o,
95
+ target: ["node20"],
96
+ keepNames: !0,
97
+ external: b,
98
+ packages: "external"
99
+ });
100
+ const D = Date.now();
101
+ return await import(`${f}?t=${D}`);
102
+ }, G = async (t) => {
103
+ const s = V(t), c = r(s, "salty.config.js"), { config: e } = await import(c);
104
+ return e;
105
+ }, U = () => {
106
+ try {
107
+ return process.env.NODE_ENV === "production";
108
+ } catch {
109
+ return !1;
110
+ }
111
+ }, Ft = async (t, s = U()) => {
112
+ try {
113
+ s ? R.info("Generating CSS in production mode! 🔥") : R.info("Generating CSS in development mode! 🚀");
114
+ const c = [], e = [], n = V(t), l = r(n, "index.css");
115
+ (() => {
116
+ I(n) && Q("rm -rf " + n), N(n), N(r(n, "css")), N(r(n, "types"));
117
+ })(), await mt(t);
118
+ const f = await G(t);
119
+ async function b(a, d) {
120
+ const k = ["node_modules", "saltygen"], w = st(a);
121
+ if (w.isDirectory()) {
122
+ const F = et(a);
123
+ if (k.some((i) => a.includes(i))) return;
124
+ await Promise.all(F.map((i) => b(r(a, i), r(d, i))));
125
+ } else if (w.isFile() && _(a)) {
126
+ const g = await z(t, a, n), i = [];
127
+ Object.entries(g).forEach(([j, y]) => {
128
+ if (y.isKeyframes && y.css) {
129
+ const W = `${y.animationName}.css`, Y = `css/${W}`, Z = r(n, Y);
130
+ c.push(W), C(Z, y.css);
131
+ return;
132
+ }
133
+ if (!y.generator) return;
134
+ const S = y.generator._withBuildContext({
135
+ name: j,
136
+ config: f,
137
+ prod: s
138
+ }), M = `${S.hash}-${S.priority}.css`;
139
+ e[S.priority] || (e[S.priority] = []), e[S.priority].push(M), i.push(M);
140
+ const v = `css/${M}`, X = r(n, v);
141
+ C(X, S.css);
142
+ });
143
+ const m = i.map((j) => `@import url('./${j}');`).join(`
144
+ `), p = B(a, 6), P = r(n, `css/${p}.css`);
145
+ C(P, m);
146
+ }
147
+ }
148
+ await b(t, n);
149
+ const o = c.map((a) => `@import url('./css/${a}');`).join(`
150
+ `);
151
+ let x = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
152
+
153
+ ${["variables.css", "global.css", "templates.css"].filter((a) => {
154
+ try {
155
+ return E(r(n, "css", a), "utf8").length > 0;
156
+ } catch {
157
+ return !1;
158
+ }
159
+ }).map((a) => `@import url('./css/${a}');`).join(`
160
+ `)}
161
+ ${o}`;
162
+ if (f.importStrategy !== "component") {
163
+ const a = e.flat().map((d) => `@import url('./css/${d}');`).join(`
164
+ `);
165
+ x += a;
166
+ }
167
+ C(l, x);
168
+ } catch (c) {
169
+ console.error(c);
170
+ }
171
+ }, jt = async (t, s) => {
172
+ try {
173
+ const c = [], e = r(t, "./saltygen"), n = r(e, "index.css");
174
+ if (_(s)) {
175
+ const h = await G(t), f = await z(t, s, e);
176
+ Object.entries(f).forEach(([$, x]) => {
177
+ if (!x.generator) return;
178
+ const a = x.generator._withBuildContext({
179
+ name: $,
180
+ config: h
181
+ }), d = `${a.hash}-${a.priority}.css`, k = `css/${d}`, w = r(e, k);
182
+ c.push(d), C(w, a.css);
183
+ });
184
+ const b = E(n, "utf8").split(`
185
+ `), o = c.map(($) => `@import url('../saltygen/css/${$}');`), u = [.../* @__PURE__ */ new Set([...b, ...o])].join(`
186
+ `);
187
+ C(n, u);
188
+ }
189
+ } catch (c) {
190
+ console.error(c);
191
+ }
192
+ }, kt = async (t, s, c = U()) => {
193
+ try {
194
+ const e = r(t, "./saltygen");
195
+ if (_(s)) {
196
+ const l = E(s, "utf8");
197
+ l.replace(/^(?!export\s)const\s.*/gm, (u) => `export ${u}`) !== l && await ot(s, l);
198
+ const f = await G(t), b = await z(t, s, e);
199
+ let o = l;
200
+ Object.entries(b).forEach(([u, $]) => {
201
+ var M;
202
+ if ($.isKeyframes || !$.generator) return;
203
+ const x = $.generator._withBuildContext({
204
+ name: u,
205
+ config: f,
206
+ prod: c
207
+ }), a = new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(l);
208
+ if (!a) return console.error("Could not find the original declaration");
209
+ const d = (M = a.at(1)) == null ? void 0 : M.trim(), k = new RegExp(`\\s${u}[=\\s]+styled\\(`, "g").exec(o);
210
+ if (!k) return console.error("Could not find the original declaration");
211
+ const { index: w } = k;
212
+ let F = !1;
213
+ const g = setTimeout(() => F = !0, 5e3);
214
+ let i = 0, m = !1, p = 0;
215
+ for (; !m && !F; ) {
216
+ const v = o[w + i];
217
+ v === "(" && p++, v === ")" && p--, p === 0 && v === ")" && (m = !0), i > o.length && (F = !0), i++;
218
+ }
219
+ if (!F) clearTimeout(g);
220
+ else throw new Error("Failed to find the end of the styled call and timed out");
221
+ const P = w + i, j = o.slice(w, P), y = o, S = ` ${u} = styled(${d}, "${x.classNames}", ${JSON.stringify(x.props)});`;
222
+ o = o.replace(j, S), y === o && console.error("Minimize file failed to change content", { name: u, tagName: d });
223
+ });
224
+ const D = B(s, 6);
225
+ return f.importStrategy === "component" && (o = `import '../../saltygen/css/${D}.css';
226
+ ${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
227
+ }
228
+ } catch (e) {
229
+ console.error("Error in minimizeFile:", e);
230
+ }
231
+ };
232
+ export {
233
+ xt as a,
234
+ gt as b,
235
+ mt as c,
236
+ z as d,
237
+ jt as e,
238
+ Ft as g,
239
+ _ as i,
240
+ R as l,
241
+ kt as m,
242
+ ut as s
243
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.100",
3
+ "version": "0.0.1-alpha.102",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
package/index-BGaLvshf.js DELETED
@@ -1,232 +0,0 @@
1
- import * as H from "esbuild";
2
- import { execSync as Q } from "child_process";
3
- import { t as B, d as W } from "./dash-case-DMQMcCO6.js";
4
- import { join as o } from "path";
5
- import { existsSync as K, writeFileSync as w, mkdirSync as V, statSync as tt, readdirSync as st, readFileSync as v } from "fs";
6
- import { readFile as et, writeFile as nt } from "fs/promises";
7
- import { p as ot, a as rt, b as ct } from "./parse-templates-DUUSaubj.js";
8
- import { createLogger as at, format as J, transports as it } from "winston";
9
- const L = (t) => {
10
- if (!t || t === "/") throw new Error("Could not find package.json file");
11
- const s = o(t, "package.json");
12
- return K(s) ? s : L(o(t, ".."));
13
- }, lt = async (t) => {
14
- const s = L(t);
15
- return await et(s, "utf-8").then(JSON.parse).catch(() => {
16
- });
17
- }, pt = async (t) => {
18
- const s = await lt(t);
19
- if (s)
20
- return s.type;
21
- };
22
- let M;
23
- const q = async (t) => {
24
- if (M) return M;
25
- const s = await pt(t);
26
- return s === "module" ? M = "esm" : (s === "commonjs" || import.meta.url.endsWith(".cjs")) && (M = "cjs"), M || "esm";
27
- }, R = at({
28
- level: "debug",
29
- format: J.combine(J.colorize(), J.cli()),
30
- transports: [new it.Console({})]
31
- }), Ct = (t) => {
32
- R.error(t);
33
- }, O = {
34
- externalModules: []
35
- }, A = (t) => {
36
- if (O.externalModules.length > 0) return O.externalModules;
37
- const s = o(t, "salty.config.ts"), e = v(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
38
- if (!e) return [];
39
- const n = e[1].split(",").map((l) => l.replace(/['"`]/g, "").trim());
40
- return O.externalModules = n, n;
41
- }, N = (t) => o(t, "./saltygen"), ft = ["salty", "css", "styles", "styled"], ut = (t = []) => new RegExp(`\\.(${[...ft, ...t].join("|")})\\.`), I = (t, s = []) => ut(s).test(t), gt = async (t) => {
42
- const s = N(t), i = o(t, "salty.config.ts"), e = o(s, "salty.config.js"), n = await q(t), l = A(t);
43
- await H.build({
44
- entryPoints: [i],
45
- minify: !0,
46
- treeShaking: !0,
47
- bundle: !0,
48
- outfile: e,
49
- format: n,
50
- external: l
51
- });
52
- const S = Date.now(), { config: f } = await import(`${e}?t=${S}`);
53
- return f;
54
- }, dt = async (t) => {
55
- const s = await gt(t), i = /* @__PURE__ */ new Set(), e = (u, a = []) => u ? Object.entries(u).flatMap(([m, p]) => {
56
- if (!p) return;
57
- if (typeof p == "object") return e(p, [...a, m]);
58
- const P = [...a, m].join(".");
59
- i.add(`"${P}"`);
60
- const x = [...a.map(W), W(m)].join("-"), { result: y } = ct(p);
61
- return `--${x}: ${y};`;
62
- }) : [], n = (u) => u ? Object.entries(u).flatMap(([a, m]) => {
63
- const p = e(m);
64
- return a === "base" ? p.join("") : `${a} { ${p.join("")} }`;
65
- }) : [], l = (u) => u ? Object.entries(u).flatMap(([a, m]) => Object.entries(m).flatMap(([p, P]) => {
66
- const x = e(P, [a]), y = `.${a}-${p}, [data-${a}="${p}"]`, b = x.join("");
67
- return `${y} { ${b} }`;
68
- })) : [], S = e(s.variables), f = n(s.responsiveVariables), C = l(s.conditionalVariables), r = N(t), T = o(r, "css/variables.css"), g = `:root { ${S.join("")} ${f.join("")} } ${C.join("")}`;
69
- w(T, g);
70
- const h = o(r, "types/css-tokens.d.ts"), c = `type VariableTokens = ${[...i].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
71
- w(h, c);
72
- const d = o(r, "css/global.css"), k = ot(s.global, "");
73
- w(d, k);
74
- const $ = o(r, "css/templates.css"), j = rt(s.templates);
75
- w($, j);
76
- }, _ = async (t, s, i) => {
77
- const e = B(s), n = o(i, "js", e + ".js"), l = await q(t), S = A(t);
78
- await H.build({
79
- entryPoints: [s],
80
- minify: !0,
81
- treeShaking: !0,
82
- bundle: !0,
83
- outfile: n,
84
- format: l,
85
- target: ["es2022"],
86
- keepNames: !0,
87
- external: S
88
- });
89
- const f = Date.now();
90
- return await import(`${n}?t=${f}`);
91
- }, z = async (t) => {
92
- const s = N(t), i = o(s, "salty.config.js"), { config: e } = await import(i);
93
- return e;
94
- }, U = () => {
95
- try {
96
- return process.env.NODE_ENV === "production";
97
- } catch {
98
- return !1;
99
- }
100
- }, Ft = async (t, s = U()) => {
101
- try {
102
- s ? R.info("Generating CSS in production mode! 🔥") : R.info("Generating CSS in development mode! 🚀");
103
- const i = [], e = [], n = N(t), l = o(n, "index.css");
104
- (() => {
105
- K(n) && Q("rm -rf " + n), V(n), V(o(n, "css")), V(o(n, "types"));
106
- })(), await dt(t);
107
- const f = await z(t);
108
- async function C(c, d) {
109
- const k = ["node_modules", "saltygen"], $ = tt(c);
110
- if ($.isDirectory()) {
111
- const j = st(c);
112
- if (k.some((a) => c.includes(a))) return;
113
- await Promise.all(j.map((a) => C(o(c, a), o(d, a))));
114
- } else if ($.isFile() && I(c)) {
115
- const u = await _(t, c, n), a = [];
116
- Object.entries(u).forEach(([x, y]) => {
117
- if (y.isKeyframes && y.css) {
118
- const G = `${y.animationName}.css`, Y = `css/${G}`, Z = o(n, Y);
119
- i.push(G), w(Z, y.css);
120
- return;
121
- }
122
- if (!y.generator) return;
123
- const b = y.generator._withBuildContext({
124
- name: x,
125
- config: f,
126
- prod: s
127
- }), D = `${b.hash}-${b.priority}.css`;
128
- e[b.priority] || (e[b.priority] = []), e[b.priority].push(D), a.push(D);
129
- const E = `css/${D}`, X = o(n, E);
130
- w(X, b.css);
131
- });
132
- const m = a.map((x) => `@import url('./${x}');`).join(`
133
- `), p = B(c, 6), P = o(n, `css/${p}.css`);
134
- w(P, m);
135
- }
136
- }
137
- await C(t, n);
138
- const r = i.map((c) => `@import url('./css/${c}');`).join(`
139
- `);
140
- let F = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
141
-
142
- ${["variables.css", "global.css", "templates.css"].filter((c) => {
143
- try {
144
- return v(o(n, "css", c), "utf8").length > 0;
145
- } catch {
146
- return !1;
147
- }
148
- }).map((c) => `@import url('./css/${c}');`).join(`
149
- `)}
150
- ${r}`;
151
- if (f.importStrategy !== "component") {
152
- const c = e.flat().map((d) => `@import url('./css/${d}');`).join(`
153
- `);
154
- F += c;
155
- }
156
- w(l, F);
157
- } catch (i) {
158
- console.error(i);
159
- }
160
- }, jt = async (t, s) => {
161
- try {
162
- const i = [], e = o(t, "./saltygen"), n = o(e, "index.css");
163
- if (I(s)) {
164
- const S = await z(t), f = await _(t, s, e);
165
- Object.entries(f).forEach(([h, F]) => {
166
- if (!F.generator) return;
167
- const c = F.generator._withBuildContext({
168
- name: h,
169
- config: S
170
- }), d = `${c.hash}-${c.priority}.css`, k = `css/${d}`, $ = o(e, k);
171
- i.push(d), w($, c.css);
172
- });
173
- const C = v(n, "utf8").split(`
174
- `), r = i.map((h) => `@import url('../saltygen/css/${h}');`), g = [.../* @__PURE__ */ new Set([...C, ...r])].join(`
175
- `);
176
- w(n, g);
177
- }
178
- } catch (i) {
179
- console.error(i);
180
- }
181
- }, xt = async (t, s, i = U()) => {
182
- try {
183
- const e = o(t, "./saltygen");
184
- if (I(s)) {
185
- const l = v(s, "utf8");
186
- l.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== l && await nt(s, l);
187
- const f = await z(t), C = await _(t, s, e);
188
- let r = l;
189
- Object.entries(C).forEach(([g, h]) => {
190
- var D;
191
- if (h.isKeyframes || !h.generator) return;
192
- const F = h.generator._withBuildContext({
193
- name: g,
194
- config: f,
195
- prod: i
196
- }), c = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(l);
197
- if (!c) return console.error("Could not find the original declaration");
198
- const d = (D = c.at(1)) == null ? void 0 : D.trim(), k = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(r);
199
- if (!k) return console.error("Could not find the original declaration");
200
- const { index: $ } = k;
201
- let j = !1;
202
- const u = setTimeout(() => j = !0, 5e3);
203
- let a = 0, m = !1, p = 0;
204
- for (; !m && !j; ) {
205
- const E = r[$ + a];
206
- E === "(" && p++, E === ")" && p--, p === 0 && E === ")" && (m = !0), a > r.length && (j = !0), a++;
207
- }
208
- if (!j) clearTimeout(u);
209
- else throw new Error("Failed to find the end of the styled call and timed out");
210
- const P = $ + a, x = r.slice($, P), y = r, b = ` ${g} = styled(${d}, "${F.classNames}", ${JSON.stringify(F.props)});`;
211
- r = r.replace(x, b), y === r && console.error("Minimize file failed to change content", { name: g, tagName: d });
212
- });
213
- const T = B(s, 6);
214
- return f.importStrategy === "component" && (r = `import '../../saltygen/css/${T}.css';
215
- ${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
216
- }
217
- } catch (e) {
218
- console.error("Error in minimizeFile:", e);
219
- }
220
- };
221
- export {
222
- Ct as a,
223
- ut as b,
224
- dt as c,
225
- _ as d,
226
- jt as e,
227
- Ft as g,
228
- I as i,
229
- R as l,
230
- xt as m,
231
- ft as s
232
- };
@@ -1,11 +0,0 @@
1
- "use strict";const te=require("esbuild"),se=require("child_process"),N=require("./dash-case-DKzpenwY.cjs"),i=require("path"),l=require("fs"),H=require("fs/promises"),J=require("./parse-templates-DVK3iZIl.cjs"),v=require("winston");var q=typeof document<"u"?document.currentScript:null;function ne(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const U=ne(te),G=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return l.existsSync(t)?t:G(i.join(e,".."))},oe=async e=>{const t=G(e);return await H.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ie=async e=>{const t=await oe(e);if(t)return t.type};let T;const L=async e=>{if(T)return T;const t=await ie(e);return t==="module"?T="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:q&&q.tagName.toUpperCase()==="SCRIPT"&&q.src||new URL("index-BKoD9apd.cjs",document.baseURI).href).endsWith(".cjs"))&&(T="cjs"),T||"esm"},O=v.createLogger({level:"debug",format:v.format.combine(v.format.colorize(),v.format.cli()),transports:[new v.transports.Console({})]}),re=e=>{O.error(e)},I={externalModules:[]},W=e=>{if(I.externalModules.length>0)return I.externalModules;const t=i.join(e,"salty.config.ts"),s=l.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const o=s[1].split(",").map(u=>u.replace(/['"`]/g,"").trim());return I.externalModules=o,o},V=e=>i.join(e,"./saltygen"),K=["salty","css","styles","styled"],A=(e=[])=>new RegExp(`\\.(${[...K,...e].join("|")})\\.`),R=(e,t=[])=>A(t).test(e),ce=async e=>{const t=V(e),n=i.join(e,"salty.config.ts"),s=i.join(t,"salty.config.js"),o=await L(e),u=W(e);await U.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:o,external:u});const b=Date.now(),{config:p}=await import(`${s}?t=${b}`);return p},X=async e=>{const t=await ce(e),n=new Set,s=(g,a=[])=>g?Object.entries(g).flatMap(([m,f])=>{if(!f)return;if(typeof f=="object")return s(f,[...a,m]);const P=[...a,m].join(".");n.add(`"${P}"`);const x=[...a.map(N.dashCase),N.dashCase(m)].join("-"),{result:h}=J.parseValueTokens(f);return`--${x}: ${h};`}):[],o=g=>g?Object.entries(g).flatMap(([a,m])=>{const f=s(m);return a==="base"?f.join(""):`${a} { ${f.join("")} }`}):[],u=g=>g?Object.entries(g).flatMap(([a,m])=>Object.entries(m).flatMap(([f,P])=>{const x=s(P,[a]),h=`.${a}-${f}, [data-${a}="${f}"]`,w=x.join("");return`${h} { ${w} }`})):[],b=s(t.variables),p=o(t.responsiveVariables),F=u(t.conditionalVariables),r=V(e),E=i.join(r,"css/variables.css"),d=`:root { ${b.join("")} ${p.join("")} } ${F.join("")}`;l.writeFileSync(E,d);const j=i.join(r,"types/css-tokens.d.ts"),c=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;l.writeFileSync(j,c);const y=i.join(r,"css/global.css"),k=J.parseStyles(t.global,"");l.writeFileSync(y,k);const S=i.join(r,"css/templates.css"),C=J.parseTemplates(t.templates);l.writeFileSync(S,C)},_=async(e,t,n)=>{const s=N.toHash(t),o=i.join(n,"js",s+".js"),u=await L(e),b=W(e);await U.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:u,target:["es2022"],keepNames:!0,external:b});const p=Date.now();return await import(`${o}?t=${p}`)},z=async e=>{const t=V(e),n=i.join(t,"salty.config.js"),{config:s}=await import(n);return s},Y=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(e,t=Y())=>{try{t?O.info("Generating CSS in production mode! 🔥"):O.info("Generating CSS in development mode! 🚀");const n=[],s=[],o=V(e),u=i.join(o,"index.css");(()=>{l.existsSync(o)&&se.execSync("rm -rf "+o),l.mkdirSync(o),l.mkdirSync(i.join(o,"css")),l.mkdirSync(i.join(o,"types"))})(),await X(e);const p=await z(e);async function F(c,y){const k=["node_modules","saltygen"],S=l.statSync(c);if(S.isDirectory()){const C=l.readdirSync(c);if(k.some(a=>c.includes(a)))return;await Promise.all(C.map(a=>F(i.join(c,a),i.join(y,a))))}else if(S.isFile()&&R(c)){const g=await _(e,c,o),a=[];Object.entries(g).forEach(([x,h])=>{if(h.isKeyframes&&h.css){const B=`${h.animationName}.css`,Q=`css/${B}`,ee=i.join(o,Q);n.push(B),l.writeFileSync(ee,h.css);return}if(!h.generator)return;const w=h.generator._withBuildContext({name:x,config:p,prod:t}),D=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(D),a.push(D);const M=`css/${D}`,Z=i.join(o,M);l.writeFileSync(Z,w.css)});const m=a.map(x=>`@import url('./${x}');`).join(`
2
- `),f=N.toHash(c,6),P=i.join(o,`css/${f}.css`);l.writeFileSync(P,m)}}await F(e,o);const r=n.map(c=>`@import url('./css/${c}');`).join(`
3
- `);let $=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
4
-
5
- ${["variables.css","global.css","templates.css"].filter(c=>{try{return l.readFileSync(i.join(o,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
6
- `)}
7
- ${r}`;if(p.importStrategy!=="component"){const c=s.flat().map(y=>`@import url('./css/${y}');`).join(`
8
- `);$+=c}l.writeFileSync(u,$)}catch(n){console.error(n)}},le=async(e,t)=>{try{const n=[],s=i.join(e,"./saltygen"),o=i.join(s,"index.css");if(R(t)){const b=await z(e),p=await _(e,t,s);Object.entries(p).forEach(([j,$])=>{if(!$.generator)return;const c=$.generator._withBuildContext({name:j,config:b}),y=`${c.hash}-${c.priority}.css`,k=`css/${y}`,S=i.join(s,k);n.push(y),l.writeFileSync(S,c.css)});const F=l.readFileSync(o,"utf8").split(`
9
- `),r=n.map(j=>`@import url('../saltygen/css/${j}');`),d=[...new Set([...F,...r])].join(`
10
- `);l.writeFileSync(o,d)}}catch(n){console.error(n)}},ue=async(e,t,n=Y())=>{try{const s=i.join(e,"./saltygen");if(R(t)){const u=l.readFileSync(t,"utf8");u.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==u&&await H.writeFile(t,u);const p=await z(e),F=await _(e,t,s);let r=u;Object.entries(F).forEach(([d,j])=>{var D;if(j.isKeyframes||!j.generator)return;const $=j.generator._withBuildContext({name:d,config:p,prod:n}),c=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(u);if(!c)return console.error("Could not find the original declaration");const y=(D=c.at(1))==null?void 0:D.trim(),k=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(r);if(!k)return console.error("Could not find the original declaration");const{index:S}=k;let C=!1;const g=setTimeout(()=>C=!0,5e3);let a=0,m=!1,f=0;for(;!m&&!C;){const M=r[S+a];M==="("&&f++,M===")"&&f--,f===0&&M===")"&&(m=!0),a>r.length&&(C=!0),a++}if(!C)clearTimeout(g);else throw new Error("Failed to find the end of the styled call and timed out");const P=S+a,x=r.slice(S,P),h=r,w=` ${d} = styled(${y}, "${$.classNames}", ${JSON.stringify($.props)});`;r=r.replace(x,w),h===r&&console.error("Minimize file failed to change content",{name:d,tagName:y})});const E=N.toHash(t,6);return p.importStrategy==="component"&&(r=`import '../../saltygen/css/${E}.css';
11
- ${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(s){console.error("Error in minimizeFile:",s)}};exports.compileSaltyFile=_;exports.generateConfigStyles=X;exports.generateCss=ae;exports.generateFile=le;exports.isSaltyFile=R;exports.logError=re;exports.logger=O;exports.minimizeFile=ue;exports.saltyFileExtensions=K;exports.saltyFileRegExp=A;