@salty-css/core 0.0.1-alpha.226 → 0.0.1-alpha.228

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/README.md CHANGED
@@ -19,7 +19,7 @@ Is there anything saltier than CSS in frontend web development? Salty CSS is bui
19
19
  Fastest way to get started with any framework is
20
20
 
21
21
  ```bash
22
- npx salty-css init [directory]
22
+ npx salty-css init
23
23
  ```
24
24
 
25
25
  Other guides:
@@ -40,6 +40,10 @@ Other guides:
40
40
  2. Salty CSS components created with styled function can extend non Salty CSS components (`export const CustomLink = styled(NextJSLink, { ... });`) but those components must take in `className` prop for styles to apply.
41
41
  3. Among common types like `string` and `number`, CSS-in-JS properties in Salty CSS do support `functions` and `promises` as values (`styled('span', { base: { color: async () => 'red' } });`) but running asynchronous tasks or importing heavy 3rd party libraries into `*.css.ts` or `*.css.tsx` files can cause longer build times.
42
42
 
43
+ ## Get support
44
+
45
+ To get help with problems, [Join Salty CSS Discord server](https://discord.gg/R6kr4KxMhP).
46
+
43
47
  ## API
44
48
 
45
49
  ### Component styling
package/bin/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-CNuRN2e-.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-_XWMZNGO.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
package/bin/main.js CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
3
3
  import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
4
4
  import { join as i, relative as z, parse as re, format as ee } from "path";
5
5
  import { render as ce } from "ejs";
6
- import { l as t, a as h, g as te } from "../index-ClF7lS_W.js";
6
+ import { l as t, a as h, g as te } from "../index-BR0X24-T.js";
7
7
  import { p as le } from "../pascal-case-BQpR5PdN.js";
8
8
  import { exec as de } from "child_process";
9
9
  import fe from "ora";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-3N79AOBO.cjs");const e=require("../index-CNuRN2e-.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-3N79AOBO.cjs");const e=require("../index-_XWMZNGO.cjs");require("../css/merge.cjs");require("../define-templates-Cunsb_Tr.cjs");require("ts-morph");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,16 +5,17 @@ import "path";
5
5
  import "fs";
6
6
  import "fs/promises";
7
7
  import "../parse-styles-Bo7fQ_SV.js";
8
- import { d as g, c as F, g as y, e as x, i as S, m as c, s as f, b as C } from "../index-ClF7lS_W.js";
8
+ import { d as F, c as y, g as x, e as S, i as c, m as f, s as C, b as E } from "../index-BR0X24-T.js";
9
9
  import "../css/merge.js";
10
10
  import "../define-templates-4A2yHcMF.js";
11
+ import "ts-morph";
11
12
  export {
12
- g as compileSaltyFile,
13
- F as generateConfigStyles,
14
- y as generateCss,
15
- x as generateFile,
16
- S as isSaltyFile,
17
- c as minimizeFile,
18
- f as saltyFileExtensions,
19
- C as saltyFileRegExp
13
+ F as compileSaltyFile,
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
20
21
  };
@@ -0,0 +1,496 @@
1
+ import * as yt from "esbuild";
2
+ import { execSync as xt } from "child_process";
3
+ import { d as I, t as R } from "./dash-case-DBThphLm.js";
4
+ import { join as r, parse as tt } from "path";
5
+ import { existsSync as it, writeFileSync as C, mkdirSync as G, readFileSync as E, statSync as Dt, readdirSync as kt } from "fs";
6
+ import { readFile as gt } from "fs/promises";
7
+ import { p as at, a as _t } from "./parse-styles-Bo7fQ_SV.js";
8
+ import { createLogger as Tt, format as ot, transports as Et } from "winston";
9
+ import { mergeObjects as H, mergeFactories as Ot } from "./css/merge.js";
10
+ import { d as Vt } from "./define-templates-4A2yHcMF.js";
11
+ import { Project as vt } from "ts-morph";
12
+ const ht = async (t, e = []) => {
13
+ if (!t) return "";
14
+ const s = [], n = {};
15
+ for (const [o, i] of Object.entries(t))
16
+ if (typeof i != "function") if (i && typeof i == "object") {
17
+ const a = o.trim(), b = await ht(i, [...e, a]);
18
+ s.push(b);
19
+ } else
20
+ n[o] = i;
21
+ if (Object.keys(n).length) {
22
+ const o = e.map(I).join("-"), i = "t_" + R(o, 4), a = await at(n, `.${o}, .${i}`);
23
+ s.push(a);
24
+ }
25
+ return s.join(`
26
+ `);
27
+ }, Mt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = $t(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, $t = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
28
+ const i = e ? `${e}.${n}` : n;
29
+ return typeof o == "object" ? $t(o, i, s) : s.add(e);
30
+ }), [...s]) : [], bt = (t) => {
31
+ if (!t || t === "/") throw new Error("Could not find package.json file");
32
+ const e = r(t, "package.json");
33
+ return it(e) ? e : bt(r(t, ".."));
34
+ }, Jt = async (t) => {
35
+ const e = bt(t);
36
+ return await gt(e, "utf-8").then(JSON.parse).catch(() => {
37
+ });
38
+ }, Rt = async (t) => {
39
+ const e = await Jt(t);
40
+ if (e)
41
+ return e.type;
42
+ };
43
+ let W;
44
+ const wt = async (t) => {
45
+ if (W) return W;
46
+ const e = await Rt(t);
47
+ return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
48
+ }, Y = Tt({
49
+ level: "debug",
50
+ format: ot.combine(ot.colorize(), ot.cli()),
51
+ transports: [new Et.Console({})]
52
+ }), se = (t) => {
53
+ Y.error(t);
54
+ };
55
+ function St(t) {
56
+ return t ? typeof t != "string" ? St(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
57
+ }
58
+ const zt = {
59
+ /** Set box model to border-box */
60
+ "*, *::before, *::after": {
61
+ boxSizing: "border-box"
62
+ },
63
+ /** Remove default margin and padding */
64
+ "*": {
65
+ margin: 0
66
+ },
67
+ /** Remove adjust font properties */
68
+ html: {
69
+ lineHeight: 1.15,
70
+ textSizeAdjust: "100%",
71
+ WebkitFontSmoothing: "antialiased"
72
+ },
73
+ /** Make media elements responsive */
74
+ "img, picture, video, canvas, svg": {
75
+ display: "block",
76
+ maxWidth: "100%"
77
+ },
78
+ /** Avoid overflow of text */
79
+ "p, h1, h2, h3, h4, h5, h6": {
80
+ overflowWrap: "break-word"
81
+ },
82
+ /** Improve text wrapping */
83
+ p: {
84
+ textWrap: "pretty"
85
+ },
86
+ "h1, h2, h3, h4, h5, h6": {
87
+ textWrap: "balance"
88
+ },
89
+ /** Improve link color */
90
+ a: {
91
+ color: "currentColor"
92
+ },
93
+ /** Improve button line height */
94
+ button: {
95
+ lineHeight: "1em",
96
+ color: "currentColor"
97
+ },
98
+ /** Improve form elements */
99
+ "input, optgroup, select, textarea": {
100
+ fontFamily: "inherit",
101
+ fontSize: "100%",
102
+ lineHeight: "1.15em"
103
+ }
104
+ }, v = {
105
+ externalModules: [],
106
+ rcFile: void 0,
107
+ destDir: void 0
108
+ }, Ct = (t) => {
109
+ if (v.externalModules.length > 0) return v.externalModules;
110
+ const s = E(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
111
+ if (!s) return [];
112
+ const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
113
+ return v.externalModules = n, n;
114
+ }, z = async (t) => {
115
+ if (v.destDir) return v.destDir;
116
+ const e = await rt(t), s = r(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
117
+ return v.destDir = s, s;
118
+ }, jt = ["salty", "css", "styles", "styled"], Wt = (t = []) => new RegExp(`\\.(${[...jt, ...t].join("|")})\\.`), ct = (t, e = []) => Wt(e).test(t), Ft = async (t) => {
119
+ if (v.rcFile) return v.rcFile;
120
+ if (t === "/") throw new Error("Could not find .saltyrc.json file");
121
+ const e = r(t, ".saltyrc.json"), s = await gt(e, "utf-8").then(JSON.parse).catch(() => {
122
+ });
123
+ return s ? (v.rcFile = s, s) : Ft(r(t, ".."));
124
+ }, rt = async (t) => {
125
+ var n, o;
126
+ const e = await Ft(t), s = (n = e.projects) == null ? void 0 : n.find((i) => t.endsWith(i.dir || ""));
127
+ return s || ((o = e.projects) == null ? void 0 : o.find((i) => i.dir === e.defaultProject));
128
+ }, Gt = async (t) => {
129
+ const e = await rt(t), s = await z(t), n = r(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = r(s, "salty.config.js"), i = await wt(t), a = Ct(n);
130
+ await yt.build({
131
+ entryPoints: [n],
132
+ minify: !0,
133
+ treeShaking: !0,
134
+ bundle: !0,
135
+ outfile: o,
136
+ format: i,
137
+ external: a
138
+ });
139
+ const b = Date.now(), { config: c } = await import(`${o}?t=${b}`);
140
+ return { config: c, path: o };
141
+ }, Ht = async (t, e) => {
142
+ var pt, ut;
143
+ const s = await z(t), n = {
144
+ mediaQueries: [],
145
+ globalStyles: [],
146
+ variables: [],
147
+ templates: []
148
+ };
149
+ await Promise.all(
150
+ [...e].map(async (y) => {
151
+ const { contents: $, outputFilePath: V } = await et(t, y, s);
152
+ Object.entries($).forEach(([P, k]) => {
153
+ k.isMedia ? n.mediaQueries.push([P, k]) : k.isGlobalDefine ? n.globalStyles.push(k) : k.isDefineVariables ? n.variables.push(k) : k.isDefineTemplates && n.templates.push(k._setPath(`${P};;${V}`));
154
+ });
155
+ })
156
+ );
157
+ const { config: o, path: i } = await Gt(t), a = { ...o }, b = /* @__PURE__ */ new Set(), c = (y, $ = []) => y ? Object.entries(y).flatMap(([V, P]) => {
158
+ if (!P) return;
159
+ if (typeof P == "object") return c(P, [...$, V]);
160
+ const k = St(V), st = I(V), nt = [...$, k].join(".");
161
+ b.add(`"${nt}"`);
162
+ const X = [...$.map(I), st].join("-"), mt = _t(P);
163
+ return mt ? `--${X}: ${mt.transformed};` : `--${X}: ${P};`;
164
+ }) : [], p = (y) => y ? Object.entries(y).flatMap(([$, V]) => {
165
+ const P = c(V);
166
+ return $ === "base" ? P.join("") : `${$} { ${P.join("")} }`;
167
+ }) : [], m = (y) => y ? Object.entries(y).flatMap(([$, V]) => Object.entries(V).flatMap(([P, k]) => {
168
+ const st = c(k, [$]), nt = `.${$}-${P}, [data-${$}="${P}"]`, X = st.join("");
169
+ return `${nt} { ${X} }`;
170
+ })) : [], S = (y) => ({ ...y, responsive: void 0, conditional: void 0 }), d = (y) => n.variables.map(($) => y === "static" ? S($._current) : $._current[y]), g = H(S(o.variables), d("static")), u = c(g), j = H((pt = o.variables) == null ? void 0 : pt.responsive, d("responsive")), _ = p(j), x = H((ut = o.variables) == null ? void 0 : ut.conditional, d("conditional")), M = m(x), O = r(s, "css/_variables.css"), J = `:root { ${u.join("")} ${_.join("")} } ${M.join("")}`;
171
+ C(O, J), a.staticVariables = g;
172
+ const D = r(s, "css/_global.css"), K = H(o.global, n.globalStyles), f = await at(K, "");
173
+ C(D, `@layer global { ${f} }`);
174
+ const h = r(s, "css/_reset.css"), l = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : zt, F = await at(l, "");
175
+ C(h, `@layer reset { ${F} }`);
176
+ const N = r(s, "css/_templates.css"), T = H(o.templates, n.templates), A = await ht(T), B = Mt(T);
177
+ C(N, `@layer templates { ${A} }`), a.templates = T;
178
+ const L = o.templates ? [Vt(o.templates)._setPath(`config;;${i}`)] : [], Z = Ot(n.templates, L);
179
+ a.templatePaths = Object.fromEntries(Object.entries(Z).map(([y, $]) => [y, $._path]));
180
+ const { mediaQueries: q } = n;
181
+ a.mediaQueries = Object.fromEntries(q.map(([y, $]) => [`@${y}`, $]));
182
+ const Q = q.map(([y]) => `'@${y}'`).join(" | "), U = r(s, "types/css-tokens.d.ts"), Nt = `
183
+ // Variable types
184
+ type VariableTokens = ${[...b].join("|")};
185
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
186
+
187
+ // Template types
188
+ type TemplateTokens = {
189
+ ${Object.entries(B).map(([y, $]) => `${y}?: ${$}`).join(`
190
+ `)}
191
+ }
192
+
193
+ // Media query types
194
+ type MediaQueryKeys = ${Q || "''"};
195
+ `;
196
+ C(U, Nt);
197
+ const Pt = r(s, "cache/config-cache.json");
198
+ C(Pt, JSON.stringify(a, null, 2));
199
+ }, dt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
200
+ if (/^['"`]/.test(s)) return e;
201
+ const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
202
+ if (!o.test(t)) return e;
203
+ const a = o.exec(t);
204
+ if (a) {
205
+ const b = a.at(1);
206
+ if (jt.some((p) => b == null ? void 0 : b.includes(p))) return e;
207
+ }
208
+ return "styled('div',";
209
+ }), It = (t, e) => {
210
+ try {
211
+ const s = E(r(e, "saltygen/cache/config-cache.json"), "utf8");
212
+ return s ? `globalThis.saltyConfig = ${s};
213
+
214
+ ${t}` : `globalThis.saltyConfig = {};
215
+
216
+ ${t}`;
217
+ } catch {
218
+ return t;
219
+ }
220
+ }, et = async (t, e, s) => {
221
+ const n = R(e), o = r(s, "./temp");
222
+ it(o) || G(o);
223
+ const i = tt(e);
224
+ let a = E(e, "utf8");
225
+ a = dt(a), a = It(a, t);
226
+ const b = r(s, "js", n + ".js"), c = await rt(t), p = r(t, (c == null ? void 0 : c.configDir) || "", "salty.config.ts"), m = Ct(p), S = await wt(t);
227
+ await yt.build({
228
+ stdin: {
229
+ contents: a,
230
+ sourcefile: i.base,
231
+ resolveDir: i.dir,
232
+ loader: "tsx"
233
+ },
234
+ minify: !1,
235
+ treeShaking: !0,
236
+ bundle: !0,
237
+ outfile: b,
238
+ format: S,
239
+ target: ["node20"],
240
+ keepNames: !0,
241
+ external: m,
242
+ packages: "external",
243
+ plugins: [
244
+ {
245
+ name: "test",
246
+ setup: (u) => {
247
+ u.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (j) => {
248
+ const _ = E(j.path, "utf8");
249
+ return { contents: dt(_), loader: "ts" };
250
+ });
251
+ }
252
+ }
253
+ ]
254
+ });
255
+ const d = Date.now();
256
+ return { contents: await import(`${b}?t=${d}`), outputFilePath: b };
257
+ }, Kt = async (t) => {
258
+ const e = await z(t), s = r(e, "cache/config-cache.json"), n = E(s, "utf8");
259
+ if (!n) throw new Error("Could not find config cache file");
260
+ return JSON.parse(n);
261
+ }, lt = async (t) => {
262
+ const e = await Kt(t), s = await z(t), n = r(s, "salty.config.js"), o = Date.now(), { config: i } = await import(`${n}?t=${o}`);
263
+ return H(i, e);
264
+ }, ft = () => {
265
+ try {
266
+ return process.env.NODE_ENV === "production";
267
+ } catch {
268
+ return !1;
269
+ }
270
+ }, ne = async (t, e = ft(), s = !0) => {
271
+ try {
272
+ const n = Date.now();
273
+ e ? Y.info("Generating CSS in production mode! 🔥") : Y.info("Generating CSS in development mode! 🚀");
274
+ const o = [], i = [], a = await z(t), b = r(a, "index.css");
275
+ s && (() => {
276
+ it(a) && xt("rm -rf " + a), G(a, { recursive: !0 }), G(r(a, "css")), G(r(a, "types")), G(r(a, "js")), G(r(a, "cache"));
277
+ })();
278
+ const p = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Set();
279
+ async function S(f) {
280
+ const h = ["node_modules", "saltygen"], w = Dt(f);
281
+ if (w.isDirectory()) {
282
+ const l = kt(f);
283
+ if (h.some((N) => f.includes(N))) return;
284
+ await Promise.all(l.map((N) => S(r(f, N))));
285
+ } else if (w.isFile() && ct(f)) {
286
+ p.add(f);
287
+ const F = E(f, "utf8");
288
+ /define[\w\d]+\(/.test(F) && m.add(f);
289
+ }
290
+ }
291
+ await S(t), await Ht(t, m);
292
+ const d = {
293
+ keyframes: [],
294
+ components: [],
295
+ classNames: []
296
+ };
297
+ await Promise.all(
298
+ [...p].map(async (f) => {
299
+ const { contents: h } = await et(t, f, a);
300
+ for (let [w, l] of Object.entries(h))
301
+ l instanceof Promise && (l = await l), l.isKeyframes ? d.keyframes.push({
302
+ value: l,
303
+ src: f,
304
+ name: w
305
+ }) : l.isClassName ? d.classNames.push({
306
+ ...l,
307
+ src: f,
308
+ name: w
309
+ }) : l.generator && d.components.push({
310
+ ...l,
311
+ src: f,
312
+ name: w
313
+ });
314
+ })
315
+ );
316
+ const g = await lt(t);
317
+ for (const f of d.keyframes) {
318
+ const { value: h } = f, w = `a_${h.animationName}.css`, l = `css/${w}`, F = r(a, l);
319
+ o.push(w), C(F, h.css);
320
+ }
321
+ const u = {};
322
+ for (const f of d.components) {
323
+ const { src: h, name: w } = f;
324
+ u[h] || (u[h] = []);
325
+ const l = f.generator._withBuildContext({
326
+ callerName: w,
327
+ isProduction: e,
328
+ config: g
329
+ });
330
+ i[l.priority] || (i[l.priority] = []);
331
+ const F = await l.css;
332
+ if (!F) continue;
333
+ i[l.priority].push(l.cssFileName);
334
+ const N = `css/${l.cssFileName}`, T = r(a, N);
335
+ C(T, F), g.importStrategy === "component" && u[h].push(l.cssFileName);
336
+ }
337
+ for (const f of d.classNames) {
338
+ const { src: h, name: w } = f;
339
+ u[h] || (u[h] = []);
340
+ const l = f.generator._withBuildContext({
341
+ callerName: w,
342
+ isProduction: e,
343
+ config: g
344
+ }), F = await l.css;
345
+ if (!F) continue;
346
+ i[l.priority] || (i[l.priority] = []), i[l.priority].push(l.cssFileName);
347
+ const N = `css/${l.cssFileName}`, T = r(a, N);
348
+ C(T, F), g.importStrategy === "component" && u[h].push(l.cssFileName);
349
+ }
350
+ g.importStrategy === "component" && Object.entries(u).forEach(([f, h]) => {
351
+ const w = h.map((A) => `@import url('./${A}');`).join(`
352
+ `), l = R(f, 6), F = tt(f), N = I(F.name), T = r(a, `css/f_${N}-${l}.css`);
353
+ C(T, w || "/* Empty file */");
354
+ });
355
+ const j = o.map((f) => `@import url('./css/${f}');`).join(`
356
+ `);
357
+ let O = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
358
+
359
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) => {
360
+ try {
361
+ return E(r(a, "css", f), "utf8").length > 0;
362
+ } catch {
363
+ return !1;
364
+ }
365
+ }).map((f) => `@import url('./css/${f}');`).join(`
366
+ `)}
367
+ ${j}`;
368
+ if (g.importStrategy !== "component") {
369
+ const f = i.reduce((h, w, l) => {
370
+ const F = w.reduce((B, L) => {
371
+ var U;
372
+ const Z = r(a, "css", L), q = E(Z, "utf8"), Q = ((U = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : U.at(1)) || R(Z, 6);
373
+ return B.includes(Q) ? B : `${B}
374
+ /*start:${Q}-${L}*/
375
+ ${q}
376
+ /*end:${Q}*/
377
+ `;
378
+ }, ""), N = `l_${l}.css`, T = r(a, "css", N), A = `@layer l${l} { ${F}
379
+ }`;
380
+ return C(T, A), `${h}
381
+ @import url('./css/${N}');`;
382
+ }, "");
383
+ O += f;
384
+ }
385
+ C(b, O);
386
+ const D = Date.now() - n, K = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
387
+ Y.info(`Generated CSS in ${D}ms! ${K}`);
388
+ } catch (n) {
389
+ console.error(n);
390
+ }
391
+ }, oe = async (t, e, s = ft()) => {
392
+ try {
393
+ const n = await z(t);
394
+ if (ct(e)) {
395
+ const i = [], a = await lt(t), { contents: b } = await et(t, e, n);
396
+ for (const [c, p] of Object.entries(b)) {
397
+ if (p.isKeyframes && p.css) {
398
+ const j = `css/${`a_${p.animationName}.css`}`, _ = r(n, j);
399
+ C(_, await p.css);
400
+ return;
401
+ }
402
+ if (p.isClassName) {
403
+ const u = p.generator._withBuildContext({
404
+ callerName: c,
405
+ isProduction: s,
406
+ config: a
407
+ }), j = await u.css;
408
+ if (!j) continue;
409
+ i[u.priority] || (i[u.priority] = []), i[u.priority].push(u.cssFileName);
410
+ const _ = `css/${u.cssFileName}`, x = r(n, _);
411
+ C(x, j);
412
+ }
413
+ if (!p.generator) return;
414
+ const m = p.generator._withBuildContext({
415
+ callerName: c,
416
+ isProduction: s,
417
+ config: a
418
+ }), S = await m.css;
419
+ if (!S) continue;
420
+ const d = `css/${m.cssFileName}`, g = r(n, d);
421
+ C(g, S), i[m.priority] || (i[m.priority] = []), i[m.priority].push(m.cssFileName);
422
+ }
423
+ if (a.importStrategy !== "component")
424
+ i.forEach((c, p) => {
425
+ const m = `l_${p}.css`, S = r(n, "css", m);
426
+ let d = E(S, "utf8");
427
+ c.forEach((g) => {
428
+ var x;
429
+ const u = r(n, "css", g), j = ((x = /.*-([^-]+)-\d+.css/.exec(g)) == null ? void 0 : x.at(1)) || R(u, 6);
430
+ if (!d.includes(j)) {
431
+ const M = E(u, "utf8"), O = `/*start:${j}-${g}*/
432
+ ${M}
433
+ /*end:${j}*/
434
+ `;
435
+ d = `${d.replace(/\}$/, "")}
436
+ ${O}
437
+ }`;
438
+ }
439
+ }), C(S, d);
440
+ });
441
+ else {
442
+ const c = i.flat().map((g) => `@import url('./${g}');`).join(`
443
+ `), p = R(e, 6), m = tt(e), S = I(m.name), d = r(n, `css/f_${S}-${p}.css`);
444
+ C(d, c || "/* Empty file */");
445
+ }
446
+ }
447
+ } catch (n) {
448
+ console.error(n);
449
+ }
450
+ }, ae = async (t, e, s = ft()) => {
451
+ try {
452
+ const n = await z(t);
453
+ if (ct(e)) {
454
+ const i = E(e, "utf8"), a = await lt(t), { contents: b } = await et(t, e, n);
455
+ let c = i;
456
+ if (Object.entries(b).forEach(([p, m]) => {
457
+ var M, O;
458
+ if (m.isKeyframes) return;
459
+ const g = new vt({}).createSourceFile("temp.ts", c).getVariableDeclarationOrThrow(p);
460
+ if (!m.generator) return;
461
+ const u = m.generator._withBuildContext({
462
+ callerName: p,
463
+ isProduction: s,
464
+ config: a
465
+ }), j = g.getStart(), _ = g.getEnd(), x = c.slice(j, _);
466
+ if (m.isClassName) {
467
+ const J = c, D = ` ${p} = className("${u.classNames}")`;
468
+ c = c.replace(x, D), J === c && console.error("Minimize file failed to change content", { name: p });
469
+ }
470
+ if (x.includes("styled")) {
471
+ const J = (O = (M = /styled\(([^,]+),/.exec(x)) == null ? void 0 : M.at(1)) == null ? void 0 : O.trim(), D = c, K = ` ${p} = styled(${J}, "${u.classNames}", ${JSON.stringify(u.clientProps)})`;
472
+ c = c.replace(x, K), D === c && console.error("Minimize file failed to change content", { name: p, tagName: J });
473
+ }
474
+ }), a.importStrategy === "component") {
475
+ const p = R(e, 6), m = tt(e);
476
+ c = `import '../../saltygen/css/${`f_${I(m.name)}-${p}.css`}';
477
+ ${c}`;
478
+ }
479
+ return c = c.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
480
+ }
481
+ } catch (n) {
482
+ console.error("Error in minimizeFile:", n);
483
+ }
484
+ };
485
+ export {
486
+ se as a,
487
+ Wt as b,
488
+ Ht as c,
489
+ et as d,
490
+ oe as e,
491
+ ne as g,
492
+ ct as i,
493
+ Y as l,
494
+ ae as m,
495
+ jt as s
496
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";const Ne=require("esbuild"),Pe=require("child_process"),x=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),l=require("fs"),pe=require("fs/promises"),Y=require("./parse-styles-3N79AOBO.cjs"),K=require("winston"),J=require("./css/merge.cjs"),ke=require("./define-templates-Cunsb_Tr.cjs"),xe=require("ts-morph");var ne=typeof document<"u"?document.currentScript:null;function De(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const de=De(Ne),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,a]of Object.entries(e))if(typeof a!="function")if(a&&typeof a=="object"){const i=o.trim(),b=await ye(a,[...t,i]);s.push(b)}else n[o]=a;if(Object.keys(n).length){const o=t.map(x.dashCase).join("-"),a="t_"+x.toHash(o,4),i=await Y.parseAndJoinStyles(n,`.${o}, .${a}`);s.push(i)}return s.join(`
2
+ `)},_e=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const a=t?`${t}.${n}`:n;return typeof o=="object"?me(o,a,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return l.existsSync(t)?t:ge(r.join(e,".."))},Oe=async e=>{const t=ge(e);return await pe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Te=async e=>{const t=await Oe(e);if(t)return t.type};let q;const he=async e=>{if(q)return q;const t=await Te(e);return t==="module"?q="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-_XWMZNGO.cjs",document.baseURI).href).endsWith(".cjs"))&&(q="cjs"),q||"esm"},L=K.createLogger({level:"debug",format:K.format.combine(K.format.colorize(),K.format.cli()),transports:[new K.transports.Console({})]}),Ee=e=>{L.error(e)};function Se(e){return e?typeof e!="string"?Se(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const ve={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},V={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(V.externalModules.length>0)return V.externalModules;const s=l.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return V.externalModules=n,n},z=async e=>{if(V.destDir)return V.destDir;const t=await ie(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},oe=["salty","css","styles","styled"],be=(e=[])=>new RegExp(`\\.(${[...oe,...e].join("|")})\\.`),ee=(e,t=[])=>be(t).test(e),we=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=r.join(e,".saltyrc.json"),s=await pe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):we(r.join(e,".."))},ie=async e=>{var n,o;const t=await we(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((o=t.projects)==null?void 0:o.find(a=>a.dir===t.defaultProject))},Ve=async e=>{const t=await ie(e),s=await z(e),n=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=r.join(s,"salty.config.js"),a=await he(e),i=je(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:a,external:i});const b=Date.now(),{config:c}=await import(`${o}?t=${b}`);return{config:c,path:o}},$e=async(e,t)=>{var ce,le;const s=await z(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async g=>{const{contents:j,outputFilePath:v}=await B(e,g,s);Object.entries(j).forEach(([P,_])=>{_.isMedia?n.mediaQueries.push([P,_]):_.isGlobalDefine?n.globalStyles.push(_):_.isDefineVariables?n.variables.push(_):_.isDefineTemplates&&n.templates.push(_._setPath(`${P};;${v}`))})}));const{config:o,path:a}=await Ve(e),i={...o},b=new Set,c=(g,j=[])=>g?Object.entries(g).flatMap(([v,P])=>{if(!P)return;if(typeof P=="object")return c(P,[...j,v]);const _=Se(v),te=x.dashCase(v),se=[...j,_].join(".");b.add(`"${se}"`);const X=[...j.map(x.dashCase),te].join("-"),fe=Y.parseVariableTokens(P);return fe?`--${X}: ${fe.transformed};`:`--${X}: ${P};`}):[],p=g=>g?Object.entries(g).flatMap(([j,v])=>{const P=c(v);return j==="base"?P.join(""):`${j} { ${P.join("")} }`}):[],y=g=>g?Object.entries(g).flatMap(([j,v])=>Object.entries(v).flatMap(([P,_])=>{const te=c(_,[j]),se=`.${j}-${P}, [data-${j}="${P}"]`,X=te.join("");return`${se} { ${X} }`})):[],$=g=>({...g,responsive:void 0,conditional:void 0}),m=g=>n.variables.map(j=>g==="static"?$(j._current):j._current[g]),h=J.mergeObjects($(o.variables),m("static")),d=c(h),F=J.mergeObjects((ce=o.variables)==null?void 0:ce.responsive,m("responsive")),O=p(F),k=J.mergeObjects((le=o.variables)==null?void 0:le.conditional,m("conditional")),M=y(k),E=r.join(s,"css/_variables.css"),R=`:root { ${d.join("")} ${O.join("")} } ${M.join("")}`;l.writeFileSync(E,R),i.staticVariables=h;const D=r.join(s,"css/_global.css"),H=J.mergeObjects(o.global,n.globalStyles),u=await Y.parseAndJoinStyles(H,"");l.writeFileSync(D,`@layer global { ${u} }`);const S=r.join(s,"css/_reset.css"),f=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:ve,C=await Y.parseAndJoinStyles(f,"");l.writeFileSync(S,`@layer reset { ${C} }`);const N=r.join(s,"css/_templates.css"),T=J.mergeObjects(o.templates,n.templates),W=await ye(T),I=_e(T);l.writeFileSync(N,`@layer templates { ${W} }`),i.templates=T;const A=o.templates?[ke.defineTemplates(o.templates)._setPath(`config;;${a}`)]:[],Q=J.mergeFactories(n.templates,A);i.templatePaths=Object.fromEntries(Object.entries(Q).map(([g,j])=>[g,j._path]));const{mediaQueries:Z}=n;i.mediaQueries=Object.fromEntries(Z.map(([g,j])=>[`@${g}`,j]));const G=Z.map(([g])=>`'@${g}'`).join(" | "),U=r.join(s,"types/css-tokens.d.ts"),Fe=`
3
+ // Variable types
4
+ type VariableTokens = ${[...b].join("|")};
5
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
6
+
7
+ // Template types
8
+ type TemplateTokens = {
9
+ ${Object.entries(I).map(([g,j])=>`${g}?: ${j}`).join(`
10
+ `)}
11
+ }
12
+
13
+ // Media query types
14
+ type MediaQueryKeys = ${G||"''"};
15
+ `;l.writeFileSync(U,Fe);const Ce=r.join(s,"cache/config-cache.json");l.writeFileSync(Ce,JSON.stringify(i,null,2))},ue=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const i=o.exec(e);if(i){const b=i.at(1);if(oe.some(p=>b==null?void 0:b.includes(p)))return t}return"styled('div',"}),Me=(e,t)=>{try{const s=l.readFileSync(r.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
16
+
17
+ ${e}`:`globalThis.saltyConfig = {};
18
+
19
+ ${e}`}catch{return e}},B=async(e,t,s)=>{const n=x.toHash(t),o=r.join(s,"./temp");l.existsSync(o)||l.mkdirSync(o);const a=r.parse(t);let i=l.readFileSync(t,"utf8");i=ue(i),i=Me(i,e);const b=r.join(s,"js",n+".js"),c=await ie(e),p=r.join(e,(c==null?void 0:c.configDir)||"","salty.config.ts"),y=je(p),$=await he(e);await de.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:b,format:$,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},F=>{const O=l.readFileSync(F.path,"utf8");return{contents:ue(O),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${b}?t=${m}`),outputFilePath:b}},Re=async e=>{const t=await z(e),s=r.join(t,"cache/config-cache.json"),n=l.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await z(e),n=r.join(s,"salty.config.js"),o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return J.mergeObjects(a,t)},re=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Je=async(e,t=re(),s=!0)=>{try{const n=Date.now();t?L.info("Generating CSS in production mode! 🔥"):L.info("Generating CSS in development mode! 🚀");const o=[],a=[],i=await z(e),b=r.join(i,"index.css");s&&(()=>{l.existsSync(i)&&Pe.execSync("rm -rf "+i),l.mkdirSync(i,{recursive:!0}),l.mkdirSync(r.join(i,"css")),l.mkdirSync(r.join(i,"types")),l.mkdirSync(r.join(i,"js")),l.mkdirSync(r.join(i,"cache"))})();const p=new Set,y=new Set;async function $(u){const S=["node_modules","saltygen"],w=l.statSync(u);if(w.isDirectory()){const f=l.readdirSync(u);if(S.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>$(r.join(u,N))))}else if(w.isFile()&&ee(u)){p.add(u);const C=l.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&y.add(u)}}await $(e),await $e(e,y);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...p].map(async u=>{const{contents:S}=await B(e,u,i);for(let[w,f]of Object.entries(S))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:w}):f.isClassName?m.classNames.push({...f,src:u,name:w}):f.generator&&m.components.push({...f,src:u,name:w})}));const h=await ae(e);for(const u of m.keyframes){const{value:S}=u,w=`a_${S.animationName}.css`,f=`css/${w}`,C=r.join(i,f);o.push(w),l.writeFileSync(C,S.css)}const d={};for(const u of m.components){const{src:S,name:w}=u;d[S]||(d[S]=[]);const f=u.generator._withBuildContext({callerName:w,isProduction:t,config:h});a[f.priority]||(a[f.priority]=[]);const C=await f.css;if(!C)continue;a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,T=r.join(i,N);l.writeFileSync(T,C),h.importStrategy==="component"&&d[S].push(f.cssFileName)}for(const u of m.classNames){const{src:S,name:w}=u;d[S]||(d[S]=[]);const f=u.generator._withBuildContext({callerName:w,isProduction:t,config:h}),C=await f.css;if(!C)continue;a[f.priority]||(a[f.priority]=[]),a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,T=r.join(i,N);l.writeFileSync(T,C),h.importStrategy==="component"&&d[S].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(d).forEach(([u,S])=>{const w=S.map(W=>`@import url('./${W}');`).join(`
20
+ `),f=x.toHash(u,6),C=r.parse(u),N=x.dashCase(C.name),T=r.join(i,`css/f_${N}-${f}.css`);l.writeFileSync(T,w||"/* Empty file */")});const F=o.map(u=>`@import url('./css/${u}');`).join(`
21
+ `);let E=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
22
+
23
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return l.readFileSync(r.join(i,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
24
+ `)}
25
+ ${F}`;if(h.importStrategy!=="component"){const u=a.reduce((S,w,f)=>{const C=w.reduce((I,A)=>{var U;const Q=r.join(i,"css",A),Z=l.readFileSync(Q,"utf8"),G=((U=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:U.at(1))||x.toHash(Q,6);return I.includes(G)?I:`${I}
26
+ /*start:${G}-${A}*/
27
+ ${Z}
28
+ /*end:${G}*/
29
+ `},""),N=`l_${f}.css`,T=r.join(i,"css",N),W=`@layer l${f} { ${C}
30
+ }`;return l.writeFileSync(T,W),`${S}
31
+ @import url('./css/${N}');`},"");E+=u}l.writeFileSync(b,E);const D=Date.now()-n,H=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";L.info(`Generated CSS in ${D}ms! ${H}`)}catch(n){console.error(n)}},ze=async(e,t,s=re())=>{try{const n=await z(e);if(ee(t)){const a=[],i=await ae(e),{contents:b}=await B(e,t,n);for(const[c,p]of Object.entries(b)){if(p.isKeyframes&&p.css){const F=`css/${`a_${p.animationName}.css`}`,O=r.join(n,F);l.writeFileSync(O,await p.css);return}if(p.isClassName){const d=p.generator._withBuildContext({callerName:c,isProduction:s,config:i}),F=await d.css;if(!F)continue;a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const O=`css/${d.cssFileName}`,k=r.join(n,O);l.writeFileSync(k,F)}if(!p.generator)return;const y=p.generator._withBuildContext({callerName:c,isProduction:s,config:i}),$=await y.css;if(!$)continue;const m=`css/${y.cssFileName}`,h=r.join(n,m);l.writeFileSync(h,$),a[y.priority]||(a[y.priority]=[]),a[y.priority].push(y.cssFileName)}if(i.importStrategy!=="component")a.forEach((c,p)=>{const y=`l_${p}.css`,$=r.join(n,"css",y);let m=l.readFileSync($,"utf8");c.forEach(h=>{var k;const d=r.join(n,"css",h),F=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||x.toHash(d,6);if(!m.includes(F)){const M=l.readFileSync(d,"utf8"),E=`/*start:${F}-${h}*/
32
+ ${M}
33
+ /*end:${F}*/
34
+ `;m=`${m.replace(/\}$/,"")}
35
+ ${E}
36
+ }`}}),l.writeFileSync($,m)});else{const c=a.flat().map(h=>`@import url('./${h}');`).join(`
37
+ `),p=x.toHash(t,6),y=r.parse(t),$=x.dashCase(y.name),m=r.join(n,`css/f_${$}-${p}.css`);l.writeFileSync(m,c||"/* Empty file */")}}}catch(n){console.error(n)}},qe=async(e,t,s=re())=>{try{const n=await z(e);if(ee(t)){const a=l.readFileSync(t,"utf8"),i=await ae(e),{contents:b}=await B(e,t,n);let c=a;if(Object.entries(b).forEach(([p,y])=>{var M,E;if(y.isKeyframes)return;const h=new xe.Project({}).createSourceFile("temp.ts",c).getVariableDeclarationOrThrow(p);if(!y.generator)return;const d=y.generator._withBuildContext({callerName:p,isProduction:s,config:i}),F=h.getStart(),O=h.getEnd(),k=c.slice(F,O);if(y.isClassName){const R=c,D=` ${p} = className("${d.classNames}")`;c=c.replace(k,D),R===c&&console.error("Minimize file failed to change content",{name:p})}if(k.includes("styled")){const R=(E=(M=/styled\(([^,]+),/.exec(k))==null?void 0:M.at(1))==null?void 0:E.trim(),D=c,H=` ${p} = styled(${R}, "${d.classNames}", ${JSON.stringify(d.clientProps)})`;c=c.replace(k,H),D===c&&console.error("Minimize file failed to change content",{name:p,tagName:R})}}),i.importStrategy==="component"){const p=x.toHash(t,6),y=r.parse(t);c=`import '../../saltygen/css/${`f_${x.dashCase(y.name)}-${p}.css`}';
38
+ ${c}`}return c=c.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=B;exports.generateConfigStyles=$e;exports.generateCss=Je;exports.generateFile=ze;exports.isSaltyFile=ee;exports.logError=Ee;exports.logger=L;exports.minimizeFile=qe;exports.saltyFileExtensions=oe;exports.saltyFileRegExp=be;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.226",
3
+ "version": "0.0.1-alpha.228",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "esbuild": ">=0.21.x",
36
36
  "ora": ">=8.x",
37
37
  "react": ">=18.x || >=19.x",
38
+ "ts-morph": ">=25.0.1",
38
39
  "winston": ">=3.x"
39
40
  },
40
41
  "exports": {
package/server/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-CNuRN2e-.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-_XWMZNGO.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
package/server/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile as r } from "fs/promises";
2
- import { i as e } from "../index-ClF7lS_W.js";
2
+ import { i as e } from "../index-BR0X24-T.js";
3
3
  const f = async (t) => {
4
4
  if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
5
5
  if (t.includes("salty.config")) return !0;
@@ -1,38 +0,0 @@
1
- "use strict";const xe=require("esbuild"),Pe=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),l=require("fs"),oe=require("fs/promises"),Y=require("./parse-styles-3N79AOBO.cjs"),G=require("winston"),V=require("./css/merge.cjs"),Ne=require("./define-templates-Cunsb_Tr.cjs");var ne=typeof document<"u"?document.currentScript:null;function ke(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const pe=ke(xe),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[i,o]of Object.entries(e))if(typeof o!="function")if(o&&typeof o=="object"){const a=i.trim(),S=await ye(o,[...t,a]);s.push(S)}else n[i]=o;if(Object.keys(n).length){const i=t.map(_.dashCase).join("-"),o="t_"+_.toHash(i,4),a=await Y.parseAndJoinStyles(n,`.${i}, .${o}`);s.push(a)}return s.join(`
2
- `)},_e=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const o=t?`${t}.${n}`:n;return typeof i=="object"?me(i,o,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return l.existsSync(t)?t:ge(r.join(e,".."))},De=async e=>{const t=ge(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Oe=async e=>{const t=await De(e);if(t)return t.type};let z;const he=async e=>{if(z)return z;const t=await Oe(e);return t==="module"?z="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-CNuRN2e-.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},K=G.createLogger({level:"debug",format:G.format.combine(G.format.colorize(),G.format.cli()),transports:[new G.transports.Console({})]}),Te=e=>{K.error(e)};function Se(e){return e?typeof e!="string"?Se(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Ee={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},R={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(R.externalModules.length>0)return R.externalModules;const s=l.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return R.externalModules=n,n},M=async e=>{if(R.destDir)return R.destDir;const t=await ae(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},ie=["salty","css","styles","styled"],we=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),ee=(e,t=[])=>we(t).test(e),be=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=r.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):be(r.join(e,".."))},ae=async e=>{var n,i;const t=await be(e),s=(n=t.projects)==null?void 0:n.find(o=>e.endsWith(o.dir||""));return s||((i=t.projects)==null?void 0:i.find(o=>o.dir===t.defaultProject))},ve=async e=>{const t=await ae(e),s=await M(e),n=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=r.join(s,"salty.config.js"),o=await he(e),a=je(n);await pe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:o,external:a});const S=Date.now(),{config:j}=await import(`${i}?t=${S}`);return{config:j,path:i}},$e=async(e,t)=>{var le,fe;const s=await M(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async g=>{const{contents:b,outputFilePath:v}=await L(e,g,s);Object.entries(b).forEach(([P,O])=>{O.isMedia?n.mediaQueries.push([P,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(`${P};;${v}`))})}));const{config:i,path:o}=await ve(e),a={...i},S=new Set,j=(g,b=[])=>g?Object.entries(g).flatMap(([v,P])=>{if(!P)return;if(typeof P=="object")return j(P,[...b,v]);const O=Se(v),te=_.dashCase(v),se=[...b,O].join(".");S.add(`"${se}"`);const X=[...b.map(_.dashCase),te].join("-"),ue=Y.parseVariableTokens(P);return ue?`--${X}: ${ue.transformed};`:`--${X}: ${P};`}):[],f=g=>g?Object.entries(g).flatMap(([b,v])=>{const P=j(v);return b==="base"?P.join(""):`${b} { ${P.join("")} }`}):[],d=g=>g?Object.entries(g).flatMap(([b,v])=>Object.entries(v).flatMap(([P,O])=>{const te=j(O,[b]),se=`.${b}-${P}, [data-${b}="${P}"]`,X=te.join("");return`${se} { ${X} }`})):[],w=g=>({...g,responsive:void 0,conditional:void 0}),p=g=>n.variables.map(b=>g==="static"?w(b._current):b._current[g]),h=V.mergeObjects(w(i.variables),p("static")),y=j(h),C=V.mergeObjects((le=i.variables)==null?void 0:le.responsive,p("responsive")),N=f(C),k=V.mergeObjects((fe=i.variables)==null?void 0:fe.conditional,p("conditional")),J=d(k),T=r.join(s,"css/_variables.css"),H=`:root { ${y.join("")} ${N.join("")} } ${J.join("")}`;l.writeFileSync(T,H),a.staticVariables=h;const D=r.join(s,"css/_global.css"),q=V.mergeObjects(i.global,n.globalStyles),u=await Y.parseAndJoinStyles(q,"");l.writeFileSync(D,`@layer global { ${u} }`);const m=r.join(s,"css/_reset.css"),c=i.reset==="none"?{}:typeof i.reset=="object"?i.reset:Ee,F=await Y.parseAndJoinStyles(c,"");l.writeFileSync(m,`@layer reset { ${F} }`);const x=r.join(s,"css/_templates.css"),E=V.mergeObjects(i.templates,n.templates),I=await ye(E),W=_e(E);l.writeFileSync(x,`@layer templates { ${I} }`),a.templates=E;const A=i.templates?[Ne.defineTemplates(i.templates)._setPath(`config;;${o}`)]:[],Q=V.mergeFactories(n.templates,A);a.templatePaths=Object.fromEntries(Object.entries(Q).map(([g,b])=>[g,b._path]));const{mediaQueries:Z}=n;a.mediaQueries=Object.fromEntries(Z.map(([g,b])=>[`@${g}`,b]));const B=Z.map(([g])=>`'@${g}'`).join(" | "),U=r.join(s,"types/css-tokens.d.ts"),Fe=`
3
- // Variable types
4
- type VariableTokens = ${[...S].join("|")};
5
- type PropertyValueToken = \`{\${VariableTokens}}\`;
6
-
7
- // Template types
8
- type TemplateTokens = {
9
- ${Object.entries(W).map(([g,b])=>`${g}?: ${b}`).join(`
10
- `)}
11
- }
12
-
13
- // Media query types
14
- type MediaQueryKeys = ${B||"''"};
15
- `;l.writeFileSync(U,Fe);const Ce=r.join(s,"cache/config-cache.json");l.writeFileSync(Ce,JSON.stringify(a,null,2))},de=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const a=i.exec(e);if(a){const S=a.at(1);if(ie.some(f=>S==null?void 0:S.includes(f)))return t}return"styled('div',"}),Re=(e,t)=>{try{const s=l.readFileSync(r.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
16
-
17
- ${e}`:`globalThis.saltyConfig = {};
18
-
19
- ${e}`}catch{return e}},L=async(e,t,s)=>{const n=_.toHash(t),i=r.join(s,"./temp");l.existsSync(i)||l.mkdirSync(i);const o=r.parse(t);let a=l.readFileSync(t,"utf8");a=de(a),a=Re(a,e);const S=r.join(s,"js",n+".js"),j=await ae(e),f=r.join(e,(j==null?void 0:j.configDir)||"","salty.config.ts"),d=je(f),w=await he(e);await pe.build({stdin:{contents:a,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:S,format:w,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:y=>{y.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},C=>{const N=l.readFileSync(C.path,"utf8");return{contents:de(N),loader:"ts"}})}}]});const p=Date.now();return{contents:await import(`${S}?t=${p}`),outputFilePath:S}},Ve=async e=>{const t=await M(e),s=r.join(t,"cache/config-cache.json"),n=l.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},re=async e=>{const t=await Ve(e),s=await M(e),n=r.join(s,"salty.config.js"),i=Date.now(),{config:o}=await import(`${n}?t=${i}`);return V.mergeObjects(o,t)},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Me=async(e,t=ce(),s=!0)=>{try{const n=Date.now();t?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const i=[],o=[],a=await M(e),S=r.join(a,"index.css");s&&(()=>{l.existsSync(a)&&Pe.execSync("rm -rf "+a),l.mkdirSync(a,{recursive:!0}),l.mkdirSync(r.join(a,"css")),l.mkdirSync(r.join(a,"types")),l.mkdirSync(r.join(a,"js")),l.mkdirSync(r.join(a,"cache"))})();const f=new Set,d=new Set;async function w(u){const m=["node_modules","saltygen"],$=l.statSync(u);if($.isDirectory()){const c=l.readdirSync(u);if(m.some(x=>u.includes(x)))return;await Promise.all(c.map(x=>w(r.join(u,x))))}else if($.isFile()&&ee(u)){f.add(u);const F=l.readFileSync(u,"utf8");/define[\w\d]+\(/.test(F)&&d.add(u)}}await w(e),await $e(e,d);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...f].map(async u=>{const{contents:m}=await L(e,u,a);for(let[$,c]of Object.entries(m))c instanceof Promise&&(c=await c),c.isKeyframes?p.keyframes.push({value:c,src:u,name:$}):c.isClassName?p.classNames.push({...c,src:u,name:$}):c.generator&&p.components.push({...c,src:u,name:$})}));const h=await re(e);for(const u of p.keyframes){const{value:m}=u,$=`a_${m.animationName}.css`,c=`css/${$}`,F=r.join(a,c);i.push($),l.writeFileSync(F,m.css)}const y={};for(const u of p.components){const{src:m,name:$}=u;y[m]||(y[m]=[]);const c=u.generator._withBuildContext({callerName:$,isProduction:t,config:h});o[c.priority]||(o[c.priority]=[]);const F=await c.css;if(!F)continue;o[c.priority].push(c.cssFileName);const x=`css/${c.cssFileName}`,E=r.join(a,x);l.writeFileSync(E,F),h.importStrategy==="component"&&y[m].push(c.cssFileName)}for(const u of p.classNames){const{src:m,name:$}=u;y[m]||(y[m]=[]);const c=u.generator._withBuildContext({callerName:$,isProduction:t,config:h}),F=await c.css;if(!F)continue;o[c.priority]||(o[c.priority]=[]),o[c.priority].push(c.cssFileName);const x=`css/${c.cssFileName}`,E=r.join(a,x);l.writeFileSync(E,F),h.importStrategy==="component"&&y[m].push(c.cssFileName)}h.importStrategy==="component"&&Object.entries(y).forEach(([u,m])=>{const $=m.map(I=>`@import url('./${I}');`).join(`
20
- `),c=_.toHash(u,6),F=r.parse(u),x=_.dashCase(F.name),E=r.join(a,`css/f_${x}-${c}.css`);l.writeFileSync(E,$||"/* Empty file */")});const C=i.map(u=>`@import url('./css/${u}');`).join(`
21
- `);let T=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
22
-
23
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return l.readFileSync(r.join(a,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
24
- `)}
25
- ${C}`;if(h.importStrategy!=="component"){const u=o.reduce((m,$,c)=>{const F=$.reduce((W,A)=>{var U;const Q=r.join(a,"css",A),Z=l.readFileSync(Q,"utf8"),B=((U=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:U.at(1))||_.toHash(Q,6);return W.includes(B)?W:`${W}
26
- /*start:${B}-${A}*/
27
- ${Z}
28
- /*end:${B}*/
29
- `},""),x=`l_${c}.css`,E=r.join(a,"css",x),I=`@layer l${c} { ${F}
30
- }`;return l.writeFileSync(E,I),`${m}
31
- @import url('./css/${x}');`},"");T+=u}l.writeFileSync(S,T);const D=Date.now()-n,q=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";K.info(`Generated CSS in ${D}ms! ${q}`)}catch(n){console.error(n)}},Je=async(e,t,s=ce())=>{try{const n=await M(e);if(ee(t)){const o=[],a=await re(e),{contents:S}=await L(e,t,n);for(const[j,f]of Object.entries(S)){if(f.isKeyframes&&f.css){const C=`css/${`a_${f.animationName}.css`}`,N=r.join(n,C);l.writeFileSync(N,await f.css);return}if(f.isClassName){const y=f.generator._withBuildContext({callerName:j,isProduction:s,config:a}),C=await y.css;if(!C)continue;o[y.priority]||(o[y.priority]=[]),o[y.priority].push(y.cssFileName);const N=`css/${y.cssFileName}`,k=r.join(n,N);l.writeFileSync(k,C)}if(!f.generator)return;const d=f.generator._withBuildContext({callerName:j,isProduction:s,config:a}),w=await d.css;if(!w)continue;const p=`css/${d.cssFileName}`,h=r.join(n,p);l.writeFileSync(h,w),o[d.priority]||(o[d.priority]=[]),o[d.priority].push(d.cssFileName)}if(a.importStrategy!=="component")o.forEach((j,f)=>{const d=`l_${f}.css`,w=r.join(n,"css",d);let p=l.readFileSync(w,"utf8");j.forEach(h=>{var k;const y=r.join(n,"css",h),C=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||_.toHash(y,6);if(!p.includes(C)){const J=l.readFileSync(y,"utf8"),T=`/*start:${C}-${h}*/
32
- ${J}
33
- /*end:${C}*/
34
- `;p=`${p.replace(/\}$/,"")}
35
- ${T}
36
- }`}}),l.writeFileSync(w,p)});else{const j=o.flat().map(h=>`@import url('./${h}');`).join(`
37
- `),f=_.toHash(t,6),d=r.parse(t),w=_.dashCase(d.name),p=r.join(n,`css/f_${w}-${f}.css`);l.writeFileSync(p,j||"/* Empty file */")}}}catch(n){console.error(n)}},ze=async(e,t,s=ce())=>{try{const n=await M(e);if(ee(t)){const o=l.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==o&&await oe.writeFile(t,o);const S=await re(e),{contents:j}=await L(e,t,n);let f=o;if(Object.entries(j).forEach(([d,w])=>{var c;if(w.isKeyframes||!w.generator)return;const p=w.generator._withBuildContext({callerName:d,isProduction:s,config:S}),h=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!h)return console.error("Could not find the original declaration");const y=(c=h.at(1))==null?void 0:c.trim(),C=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(f);if(!C)return console.error("Could not find the original declaration");const{index:N}=C;let k=!1;const J=setTimeout(()=>k=!0,5e3);let T=0,H=!1,D=0;for(;!H&&!k;){const F=f[N+T];F==="("&&D++,F===")"&&D--,D===0&&F===")"&&(H=!0),T>f.length&&(k=!0),T++}if(!k)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const q=N+T,u=f.slice(N,q),m=f,$=` ${d} = styled(${y}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;f=f.replace(u,$),m===f&&console.error("Minimize file failed to change content",{name:d,tagName:y})}),S.importStrategy==="component"){const d=_.toHash(t,6),w=r.parse(t);f=`import '../../saltygen/css/${`f_${_.dashCase(w.name)}-${d}.css`}';
38
- ${f}`}return f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=L;exports.generateConfigStyles=$e;exports.generateCss=Me;exports.generateFile=Je;exports.isSaltyFile=ee;exports.logError=Te;exports.logger=K;exports.minimizeFile=ze;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;
package/index-ClF7lS_W.js DELETED
@@ -1,502 +0,0 @@
1
- import * as gt from "esbuild";
2
- import { execSync as Nt } from "child_process";
3
- import { d as B, t as M } from "./dash-case-DBThphLm.js";
4
- import { join as c, parse as tt } from "path";
5
- import { existsSync as it, writeFileSync as F, mkdirSync as W, readFileSync as v, statSync as kt, readdirSync as Dt } from "fs";
6
- import { readFile as yt, writeFile as _t } from "fs/promises";
7
- import { p as at, a as Tt } from "./parse-styles-Bo7fQ_SV.js";
8
- import { createLogger as Et, format as ot, transports as vt } from "winston";
9
- import { mergeObjects as I, mergeFactories as Ot } from "./css/merge.js";
10
- import { d as Vt } from "./define-templates-4A2yHcMF.js";
11
- const ht = async (t, e = []) => {
12
- if (!t) return "";
13
- const s = [], n = {};
14
- for (const [a, o] of Object.entries(t))
15
- if (typeof o != "function") if (o && typeof o == "object") {
16
- const i = a.trim(), h = await ht(o, [...e, i]);
17
- s.push(h);
18
- } else
19
- n[a] = o;
20
- if (Object.keys(n).length) {
21
- const a = e.map(B).join("-"), o = "t_" + M(a, 4), i = await at(n, `.${a}, .${o}`);
22
- s.push(i);
23
- }
24
- return s.join(`
25
- `);
26
- }, Mt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = $t(n).map((a) => `"${a}"`).join(" | ")), e), {}) : {}, $t = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, a]) => {
27
- const o = e ? `${e}.${n}` : n;
28
- return typeof a == "object" ? $t(a, o, s) : s.add(e);
29
- }), [...s]) : [], bt = (t) => {
30
- if (!t || t === "/") throw new Error("Could not find package.json file");
31
- const e = c(t, "package.json");
32
- return it(e) ? e : bt(c(t, ".."));
33
- }, Rt = async (t) => {
34
- const e = bt(t);
35
- return await yt(e, "utf-8").then(JSON.parse).catch(() => {
36
- });
37
- }, Jt = async (t) => {
38
- const e = await Rt(t);
39
- if (e)
40
- return e.type;
41
- };
42
- let z;
43
- const wt = async (t) => {
44
- if (z) return z;
45
- const e = await Jt(t);
46
- return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
47
- }, Y = Et({
48
- level: "debug",
49
- format: ot.combine(ot.colorize(), ot.cli()),
50
- transports: [new vt.Console({})]
51
- }), ee = (t) => {
52
- Y.error(t);
53
- };
54
- function St(t) {
55
- return t ? typeof t != "string" ? St(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
56
- }
57
- const zt = {
58
- /** Set box model to border-box */
59
- "*, *::before, *::after": {
60
- boxSizing: "border-box"
61
- },
62
- /** Remove default margin and padding */
63
- "*": {
64
- margin: 0
65
- },
66
- /** Remove adjust font properties */
67
- html: {
68
- lineHeight: 1.15,
69
- textSizeAdjust: "100%",
70
- WebkitFontSmoothing: "antialiased"
71
- },
72
- /** Make media elements responsive */
73
- "img, picture, video, canvas, svg": {
74
- display: "block",
75
- maxWidth: "100%"
76
- },
77
- /** Avoid overflow of text */
78
- "p, h1, h2, h3, h4, h5, h6": {
79
- overflowWrap: "break-word"
80
- },
81
- /** Improve text wrapping */
82
- p: {
83
- textWrap: "pretty"
84
- },
85
- "h1, h2, h3, h4, h5, h6": {
86
- textWrap: "balance"
87
- },
88
- /** Improve link color */
89
- a: {
90
- color: "currentColor"
91
- },
92
- /** Improve button line height */
93
- button: {
94
- lineHeight: "1em",
95
- color: "currentColor"
96
- },
97
- /** Improve form elements */
98
- "input, optgroup, select, textarea": {
99
- fontFamily: "inherit",
100
- fontSize: "100%",
101
- lineHeight: "1.15em"
102
- }
103
- }, V = {
104
- externalModules: [],
105
- rcFile: void 0,
106
- destDir: void 0
107
- }, Ct = (t) => {
108
- if (V.externalModules.length > 0) return V.externalModules;
109
- const s = v(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
110
- if (!s) return [];
111
- const n = s[1].split(",").map((a) => a.replace(/['"`]/g, "").trim());
112
- return V.externalModules = n, n;
113
- }, R = async (t) => {
114
- if (V.destDir) return V.destDir;
115
- const e = await ct(t), s = c(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
116
- return V.destDir = s, s;
117
- }, jt = ["salty", "css", "styles", "styled"], Wt = (t = []) => new RegExp(`\\.(${[...jt, ...t].join("|")})\\.`), rt = (t, e = []) => Wt(e).test(t), Ft = async (t) => {
118
- if (V.rcFile) return V.rcFile;
119
- if (t === "/") throw new Error("Could not find .saltyrc.json file");
120
- const e = c(t, ".saltyrc.json"), s = await yt(e, "utf-8").then(JSON.parse).catch(() => {
121
- });
122
- return s ? (V.rcFile = s, s) : Ft(c(t, ".."));
123
- }, ct = async (t) => {
124
- var n, a;
125
- const e = await Ft(t), s = (n = e.projects) == null ? void 0 : n.find((o) => t.endsWith(o.dir || ""));
126
- return s || ((a = e.projects) == null ? void 0 : a.find((o) => o.dir === e.defaultProject));
127
- }, It = async (t) => {
128
- const e = await ct(t), s = await R(t), n = c(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), a = c(s, "salty.config.js"), o = await wt(t), i = Ct(n);
129
- await gt.build({
130
- entryPoints: [n],
131
- minify: !0,
132
- treeShaking: !0,
133
- bundle: !0,
134
- outfile: a,
135
- format: o,
136
- external: i
137
- });
138
- const h = Date.now(), { config: $ } = await import(`${a}?t=${h}`);
139
- return { config: $, path: a };
140
- }, Bt = async (t, e) => {
141
- var pt, ut;
142
- const s = await R(t), n = {
143
- mediaQueries: [],
144
- globalStyles: [],
145
- variables: [],
146
- templates: []
147
- };
148
- await Promise.all(
149
- [...e].map(async (g) => {
150
- const { contents: w, outputFilePath: O } = await et(t, g, s);
151
- Object.entries(w).forEach(([x, _]) => {
152
- _.isMedia ? n.mediaQueries.push([x, _]) : _.isGlobalDefine ? n.globalStyles.push(_) : _.isDefineVariables ? n.variables.push(_) : _.isDefineTemplates && n.templates.push(_._setPath(`${x};;${O}`));
153
- });
154
- })
155
- );
156
- const { config: a, path: o } = await It(t), i = { ...a }, h = /* @__PURE__ */ new Set(), $ = (g, w = []) => g ? Object.entries(g).flatMap(([O, x]) => {
157
- if (!x) return;
158
- if (typeof x == "object") return $(x, [...w, O]);
159
- const _ = St(O), st = B(O), nt = [...w, _].join(".");
160
- h.add(`"${nt}"`);
161
- const X = [...w.map(B), st].join("-"), dt = Tt(x);
162
- return dt ? `--${X}: ${dt.transformed};` : `--${X}: ${x};`;
163
- }) : [], l = (g) => g ? Object.entries(g).flatMap(([w, O]) => {
164
- const x = $(O);
165
- return w === "base" ? x.join("") : `${w} { ${x.join("")} }`;
166
- }) : [], p = (g) => g ? Object.entries(g).flatMap(([w, O]) => Object.entries(O).flatMap(([x, _]) => {
167
- const st = $(_, [w]), nt = `.${w}-${x}, [data-${w}="${x}"]`, X = st.join("");
168
- return `${nt} { ${X} }`;
169
- })) : [], b = (g) => ({ ...g, responsive: void 0, conditional: void 0 }), u = (g) => n.variables.map((w) => g === "static" ? b(w._current) : w._current[g]), y = I(b(a.variables), u("static")), d = $(y), j = I((pt = a.variables) == null ? void 0 : pt.responsive, u("responsive")), N = l(j), k = I((ut = a.variables) == null ? void 0 : ut.conditional, u("conditional")), J = p(k), T = c(s, "css/_variables.css"), G = `:root { ${d.join("")} ${N.join("")} } ${J.join("")}`;
170
- F(T, G), i.staticVariables = y;
171
- const D = c(s, "css/_global.css"), H = I(a.global, n.globalStyles), f = await at(H, "");
172
- F(D, `@layer global { ${f} }`);
173
- const m = c(s, "css/_reset.css"), r = a.reset === "none" ? {} : typeof a.reset == "object" ? a.reset : zt, C = await at(r, "");
174
- F(m, `@layer reset { ${C} }`);
175
- const P = c(s, "css/_templates.css"), E = I(a.templates, n.templates), K = await ht(E), A = Mt(E);
176
- F(P, `@layer templates { ${K} }`), i.templates = E;
177
- const L = a.templates ? [Vt(a.templates)._setPath(`config;;${o}`)] : [], Z = Ot(n.templates, L);
178
- i.templatePaths = Object.fromEntries(Object.entries(Z).map(([g, w]) => [g, w._path]));
179
- const { mediaQueries: q } = n;
180
- i.mediaQueries = Object.fromEntries(q.map(([g, w]) => [`@${g}`, w]));
181
- const Q = q.map(([g]) => `'@${g}'`).join(" | "), U = c(s, "types/css-tokens.d.ts"), Pt = `
182
- // Variable types
183
- type VariableTokens = ${[...h].join("|")};
184
- type PropertyValueToken = \`{\${VariableTokens}}\`;
185
-
186
- // Template types
187
- type TemplateTokens = {
188
- ${Object.entries(A).map(([g, w]) => `${g}?: ${w}`).join(`
189
- `)}
190
- }
191
-
192
- // Media query types
193
- type MediaQueryKeys = ${Q || "''"};
194
- `;
195
- F(U, Pt);
196
- const xt = c(s, "cache/config-cache.json");
197
- F(xt, JSON.stringify(i, null, 2));
198
- }, mt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
199
- if (/^['"`]/.test(s)) return e;
200
- const a = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
201
- if (!a.test(t)) return e;
202
- const i = a.exec(t);
203
- if (i) {
204
- const h = i.at(1);
205
- if (jt.some((l) => h == null ? void 0 : h.includes(l))) return e;
206
- }
207
- return "styled('div',";
208
- }), Gt = (t, e) => {
209
- try {
210
- const s = v(c(e, "saltygen/cache/config-cache.json"), "utf8");
211
- return s ? `globalThis.saltyConfig = ${s};
212
-
213
- ${t}` : `globalThis.saltyConfig = {};
214
-
215
- ${t}`;
216
- } catch {
217
- return t;
218
- }
219
- }, et = async (t, e, s) => {
220
- const n = M(e), a = c(s, "./temp");
221
- it(a) || W(a);
222
- const o = tt(e);
223
- let i = v(e, "utf8");
224
- i = mt(i), i = Gt(i, t);
225
- const h = c(s, "js", n + ".js"), $ = await ct(t), l = c(t, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), p = Ct(l), b = await wt(t);
226
- await gt.build({
227
- stdin: {
228
- contents: i,
229
- sourcefile: o.base,
230
- resolveDir: o.dir,
231
- loader: "tsx"
232
- },
233
- minify: !1,
234
- treeShaking: !0,
235
- bundle: !0,
236
- outfile: h,
237
- format: b,
238
- target: ["node20"],
239
- keepNames: !0,
240
- external: p,
241
- packages: "external",
242
- plugins: [
243
- {
244
- name: "test",
245
- setup: (d) => {
246
- d.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (j) => {
247
- const N = v(j.path, "utf8");
248
- return { contents: mt(N), loader: "ts" };
249
- });
250
- }
251
- }
252
- ]
253
- });
254
- const u = Date.now();
255
- return { contents: await import(`${h}?t=${u}`), outputFilePath: h };
256
- }, Ht = async (t) => {
257
- const e = await R(t), s = c(e, "cache/config-cache.json"), n = v(s, "utf8");
258
- if (!n) throw new Error("Could not find config cache file");
259
- return JSON.parse(n);
260
- }, lt = async (t) => {
261
- const e = await Ht(t), s = await R(t), n = c(s, "salty.config.js"), a = Date.now(), { config: o } = await import(`${n}?t=${a}`);
262
- return I(o, e);
263
- }, ft = () => {
264
- try {
265
- return process.env.NODE_ENV === "production";
266
- } catch {
267
- return !1;
268
- }
269
- }, se = async (t, e = ft(), s = !0) => {
270
- try {
271
- const n = Date.now();
272
- e ? Y.info("Generating CSS in production mode! 🔥") : Y.info("Generating CSS in development mode! 🚀");
273
- const a = [], o = [], i = await R(t), h = c(i, "index.css");
274
- s && (() => {
275
- it(i) && Nt("rm -rf " + i), W(i, { recursive: !0 }), W(c(i, "css")), W(c(i, "types")), W(c(i, "js")), W(c(i, "cache"));
276
- })();
277
- const l = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
278
- async function b(f) {
279
- const m = ["node_modules", "saltygen"], S = kt(f);
280
- if (S.isDirectory()) {
281
- const r = Dt(f);
282
- if (m.some((P) => f.includes(P))) return;
283
- await Promise.all(r.map((P) => b(c(f, P))));
284
- } else if (S.isFile() && rt(f)) {
285
- l.add(f);
286
- const C = v(f, "utf8");
287
- /define[\w\d]+\(/.test(C) && p.add(f);
288
- }
289
- }
290
- await b(t), await Bt(t, p);
291
- const u = {
292
- keyframes: [],
293
- components: [],
294
- classNames: []
295
- };
296
- await Promise.all(
297
- [...l].map(async (f) => {
298
- const { contents: m } = await et(t, f, i);
299
- for (let [S, r] of Object.entries(m))
300
- r instanceof Promise && (r = await r), r.isKeyframes ? u.keyframes.push({
301
- value: r,
302
- src: f,
303
- name: S
304
- }) : r.isClassName ? u.classNames.push({
305
- ...r,
306
- src: f,
307
- name: S
308
- }) : r.generator && u.components.push({
309
- ...r,
310
- src: f,
311
- name: S
312
- });
313
- })
314
- );
315
- const y = await lt(t);
316
- for (const f of u.keyframes) {
317
- const { value: m } = f, S = `a_${m.animationName}.css`, r = `css/${S}`, C = c(i, r);
318
- a.push(S), F(C, m.css);
319
- }
320
- const d = {};
321
- for (const f of u.components) {
322
- const { src: m, name: S } = f;
323
- d[m] || (d[m] = []);
324
- const r = f.generator._withBuildContext({
325
- callerName: S,
326
- isProduction: e,
327
- config: y
328
- });
329
- o[r.priority] || (o[r.priority] = []);
330
- const C = await r.css;
331
- if (!C) continue;
332
- o[r.priority].push(r.cssFileName);
333
- const P = `css/${r.cssFileName}`, E = c(i, P);
334
- F(E, C), y.importStrategy === "component" && d[m].push(r.cssFileName);
335
- }
336
- for (const f of u.classNames) {
337
- const { src: m, name: S } = f;
338
- d[m] || (d[m] = []);
339
- const r = f.generator._withBuildContext({
340
- callerName: S,
341
- isProduction: e,
342
- config: y
343
- }), C = await r.css;
344
- if (!C) continue;
345
- o[r.priority] || (o[r.priority] = []), o[r.priority].push(r.cssFileName);
346
- const P = `css/${r.cssFileName}`, E = c(i, P);
347
- F(E, C), y.importStrategy === "component" && d[m].push(r.cssFileName);
348
- }
349
- y.importStrategy === "component" && Object.entries(d).forEach(([f, m]) => {
350
- const S = m.map((K) => `@import url('./${K}');`).join(`
351
- `), r = M(f, 6), C = tt(f), P = B(C.name), E = c(i, `css/f_${P}-${r}.css`);
352
- F(E, S || "/* Empty file */");
353
- });
354
- const j = a.map((f) => `@import url('./css/${f}');`).join(`
355
- `);
356
- let T = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
357
-
358
- ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) => {
359
- try {
360
- return v(c(i, "css", f), "utf8").length > 0;
361
- } catch {
362
- return !1;
363
- }
364
- }).map((f) => `@import url('./css/${f}');`).join(`
365
- `)}
366
- ${j}`;
367
- if (y.importStrategy !== "component") {
368
- const f = o.reduce((m, S, r) => {
369
- const C = S.reduce((A, L) => {
370
- var U;
371
- const Z = c(i, "css", L), q = v(Z, "utf8"), Q = ((U = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : U.at(1)) || M(Z, 6);
372
- return A.includes(Q) ? A : `${A}
373
- /*start:${Q}-${L}*/
374
- ${q}
375
- /*end:${Q}*/
376
- `;
377
- }, ""), P = `l_${r}.css`, E = c(i, "css", P), K = `@layer l${r} { ${C}
378
- }`;
379
- return F(E, K), `${m}
380
- @import url('./css/${P}');`;
381
- }, "");
382
- T += f;
383
- }
384
- F(h, T);
385
- const D = Date.now() - n, H = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
386
- Y.info(`Generated CSS in ${D}ms! ${H}`);
387
- } catch (n) {
388
- console.error(n);
389
- }
390
- }, ne = async (t, e, s = ft()) => {
391
- try {
392
- const n = await R(t);
393
- if (rt(e)) {
394
- const o = [], i = await lt(t), { contents: h } = await et(t, e, n);
395
- for (const [$, l] of Object.entries(h)) {
396
- if (l.isKeyframes && l.css) {
397
- const j = `css/${`a_${l.animationName}.css`}`, N = c(n, j);
398
- F(N, await l.css);
399
- return;
400
- }
401
- if (l.isClassName) {
402
- const d = l.generator._withBuildContext({
403
- callerName: $,
404
- isProduction: s,
405
- config: i
406
- }), j = await d.css;
407
- if (!j) continue;
408
- o[d.priority] || (o[d.priority] = []), o[d.priority].push(d.cssFileName);
409
- const N = `css/${d.cssFileName}`, k = c(n, N);
410
- F(k, j);
411
- }
412
- if (!l.generator) return;
413
- const p = l.generator._withBuildContext({
414
- callerName: $,
415
- isProduction: s,
416
- config: i
417
- }), b = await p.css;
418
- if (!b) continue;
419
- const u = `css/${p.cssFileName}`, y = c(n, u);
420
- F(y, b), o[p.priority] || (o[p.priority] = []), o[p.priority].push(p.cssFileName);
421
- }
422
- if (i.importStrategy !== "component")
423
- o.forEach(($, l) => {
424
- const p = `l_${l}.css`, b = c(n, "css", p);
425
- let u = v(b, "utf8");
426
- $.forEach((y) => {
427
- var k;
428
- const d = c(n, "css", y), j = ((k = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : k.at(1)) || M(d, 6);
429
- if (!u.includes(j)) {
430
- const J = v(d, "utf8"), T = `/*start:${j}-${y}*/
431
- ${J}
432
- /*end:${j}*/
433
- `;
434
- u = `${u.replace(/\}$/, "")}
435
- ${T}
436
- }`;
437
- }
438
- }), F(b, u);
439
- });
440
- else {
441
- const $ = o.flat().map((y) => `@import url('./${y}');`).join(`
442
- `), l = M(e, 6), p = tt(e), b = B(p.name), u = c(n, `css/f_${b}-${l}.css`);
443
- F(u, $ || "/* Empty file */");
444
- }
445
- }
446
- } catch (n) {
447
- console.error(n);
448
- }
449
- }, oe = async (t, e, s = ft()) => {
450
- try {
451
- const n = await R(t);
452
- if (rt(e)) {
453
- const o = v(e, "utf8");
454
- o.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== o && await _t(e, o);
455
- const h = await lt(t), { contents: $ } = await et(t, e, n);
456
- let l = o;
457
- if (Object.entries($).forEach(([p, b]) => {
458
- var r;
459
- if (b.isKeyframes || !b.generator) return;
460
- const u = b.generator._withBuildContext({
461
- callerName: p,
462
- isProduction: s,
463
- config: h
464
- }), y = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
465
- if (!y) return console.error("Could not find the original declaration");
466
- const d = (r = y.at(1)) == null ? void 0 : r.trim(), j = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(l);
467
- if (!j) return console.error("Could not find the original declaration");
468
- const { index: N } = j;
469
- let k = !1;
470
- const J = setTimeout(() => k = !0, 5e3);
471
- let T = 0, G = !1, D = 0;
472
- for (; !G && !k; ) {
473
- const C = l[N + T];
474
- C === "(" && D++, C === ")" && D--, D === 0 && C === ")" && (G = !0), T > l.length && (k = !0), T++;
475
- }
476
- if (!k) clearTimeout(J);
477
- else throw new Error("Failed to find the end of the styled call and timed out");
478
- const H = N + T, f = l.slice(N, H), m = l, S = ` ${p} = styled(${d}, "${u.classNames}", ${JSON.stringify(u.clientProps)});`;
479
- l = l.replace(f, S), m === l && console.error("Minimize file failed to change content", { name: p, tagName: d });
480
- }), h.importStrategy === "component") {
481
- const p = M(e, 6), b = tt(e);
482
- l = `import '../../saltygen/css/${`f_${B(b.name)}-${p}.css`}';
483
- ${l}`;
484
- }
485
- return l = l.replace("{ styled }", "{ styledClient as styled }"), l = l.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), l;
486
- }
487
- } catch (n) {
488
- console.error("Error in minimizeFile:", n);
489
- }
490
- };
491
- export {
492
- ee as a,
493
- Wt as b,
494
- Bt as c,
495
- et as d,
496
- ne as e,
497
- se as g,
498
- rt as i,
499
- Y as l,
500
- oe as m,
501
- jt as s
502
- };