@salty-css/core 0.0.1-alpha.228 → 0.0.1-alpha.229
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 +1 -1
- package/bin/main.js +1 -1
- package/compiler/get-function-range.d.ts +1 -0
- package/compiler/index.cjs +1 -1
- package/compiler/index.js +9 -10
- package/index-CuYozIxT.js +507 -0
- package/index-q4N-TRZZ.cjs +38 -0
- package/package.json +2 -2
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/index-BR0X24-T.js +0 -496
- package/index-_XWMZNGO.cjs +0 -38
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-
|
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-q4N-TRZZ.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-
|
6
|
+
import { l as t, a as h, g as te } from "../index-CuYozIxT.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";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getFunctionRange: (contents: string, name: string) => Promise<[number, number]>;
|
package/compiler/index.cjs
CHANGED
@@ -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-
|
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-q4N-TRZZ.cjs");require("../css/merge.cjs");require("../define-templates-Cunsb_Tr.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.js
CHANGED
@@ -5,17 +5,16 @@ import "path";
|
|
5
5
|
import "fs";
|
6
6
|
import "fs/promises";
|
7
7
|
import "../parse-styles-Bo7fQ_SV.js";
|
8
|
-
import { d as
|
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-CuYozIxT.js";
|
9
9
|
import "../css/merge.js";
|
10
10
|
import "../define-templates-4A2yHcMF.js";
|
11
|
-
import "ts-morph";
|
12
11
|
export {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
21
20
|
};
|
@@ -0,0 +1,507 @@
|
|
1
|
+
import * as gt from "esbuild";
|
2
|
+
import { execSync as Dt } from "child_process";
|
3
|
+
import { d as H, t as R } from "./dash-case-DBThphLm.js";
|
4
|
+
import { join as c, parse as X } from "path";
|
5
|
+
import { existsSync as it, writeFileSync as C, mkdirSync as W, readFileSync as _, statSync as kt, readdirSync as Tt } from "fs";
|
6
|
+
import { readFile as ht } from "fs/promises";
|
7
|
+
import { p as at, a as _t } from "./parse-styles-Bo7fQ_SV.js";
|
8
|
+
import { createLogger as vt, format as nt, transports as Et } from "winston";
|
9
|
+
import { mergeObjects as G, mergeFactories as Vt } from "./css/merge.js";
|
10
|
+
import { d as Ot } from "./define-templates-4A2yHcMF.js";
|
11
|
+
import ot from "typescript";
|
12
|
+
const $t = async (t, e = []) => {
|
13
|
+
if (!t) return "";
|
14
|
+
const s = [], n = {};
|
15
|
+
for (const [o, a] of Object.entries(t))
|
16
|
+
if (typeof a != "function") if (a && typeof a == "object") {
|
17
|
+
const i = o.trim(), p = await $t(a, [...e, i]);
|
18
|
+
s.push(p);
|
19
|
+
} else
|
20
|
+
n[o] = a;
|
21
|
+
if (Object.keys(n).length) {
|
22
|
+
const o = e.map(H).join("-"), a = "t_" + R(o, 4), i = await at(n, `.${o}, .${a}`);
|
23
|
+
s.push(i);
|
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] = bt(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, bt = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
28
|
+
const a = e ? `${e}.${n}` : n;
|
29
|
+
return typeof o == "object" ? bt(o, a, s) : s.add(e);
|
30
|
+
}), [...s]) : [], wt = (t) => {
|
31
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
32
|
+
const e = c(t, "package.json");
|
33
|
+
return it(e) ? e : wt(c(t, ".."));
|
34
|
+
}, Rt = async (t) => {
|
35
|
+
const e = wt(t);
|
36
|
+
return await ht(e, "utf-8").then(JSON.parse).catch(() => {
|
37
|
+
});
|
38
|
+
}, Jt = async (t) => {
|
39
|
+
const e = await Rt(t);
|
40
|
+
if (e)
|
41
|
+
return e.type;
|
42
|
+
};
|
43
|
+
let z;
|
44
|
+
const St = async (t) => {
|
45
|
+
if (z) return z;
|
46
|
+
const e = await Jt(t);
|
47
|
+
return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
|
48
|
+
}, U = vt({
|
49
|
+
level: "debug",
|
50
|
+
format: nt.combine(nt.colorize(), nt.cli()),
|
51
|
+
transports: [new Et.Console({})]
|
52
|
+
}), ne = (t) => {
|
53
|
+
U.error(t);
|
54
|
+
};
|
55
|
+
function Ct(t) {
|
56
|
+
return t ? typeof t != "string" ? Ct(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
|
+
}, Wt = (t, e) => new Promise((s, n) => {
|
105
|
+
const o = setTimeout(() => {
|
106
|
+
n(new Error("Timeout"));
|
107
|
+
}, 100), a = ot.createSourceFile("temp.ts", t, ot.ScriptTarget.Latest, !0);
|
108
|
+
function i(p) {
|
109
|
+
if (ot.isVariableDeclaration(p) && p.name.getText() === e) {
|
110
|
+
const y = p.getStart(), m = p.getEnd();
|
111
|
+
clearTimeout(o), s([y, m]);
|
112
|
+
}
|
113
|
+
p.forEachChild(i);
|
114
|
+
}
|
115
|
+
i(a);
|
116
|
+
}), E = {
|
117
|
+
externalModules: [],
|
118
|
+
rcFile: void 0,
|
119
|
+
destDir: void 0
|
120
|
+
}, jt = (t) => {
|
121
|
+
if (E.externalModules.length > 0) return E.externalModules;
|
122
|
+
const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
123
|
+
if (!s) return [];
|
124
|
+
const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
|
125
|
+
return E.externalModules = n, n;
|
126
|
+
}, J = async (t) => {
|
127
|
+
if (E.destDir) return E.destDir;
|
128
|
+
const e = await rt(t), s = c(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
129
|
+
return E.destDir = s, s;
|
130
|
+
}, Ft = ["salty", "css", "styles", "styled"], Gt = (t = []) => new RegExp(`\\.(${[...Ft, ...t].join("|")})\\.`), ct = (t, e = []) => Gt(e).test(t), Nt = async (t) => {
|
131
|
+
if (E.rcFile) return E.rcFile;
|
132
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
133
|
+
const e = c(t, ".saltyrc.json"), s = await ht(e, "utf-8").then(JSON.parse).catch(() => {
|
134
|
+
});
|
135
|
+
return s ? (E.rcFile = s, s) : Nt(c(t, ".."));
|
136
|
+
}, rt = async (t) => {
|
137
|
+
var n, o;
|
138
|
+
const e = await Nt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
|
139
|
+
return s || ((o = e.projects) == null ? void 0 : o.find((a) => a.dir === e.defaultProject));
|
140
|
+
}, Ht = async (t) => {
|
141
|
+
const e = await rt(t), s = await J(t), n = c(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = c(s, "salty.config.js"), a = await St(t), i = jt(n);
|
142
|
+
await gt.build({
|
143
|
+
entryPoints: [n],
|
144
|
+
minify: !0,
|
145
|
+
treeShaking: !0,
|
146
|
+
bundle: !0,
|
147
|
+
outfile: o,
|
148
|
+
format: a,
|
149
|
+
external: i
|
150
|
+
});
|
151
|
+
const p = Date.now(), { config: y } = await import(`${o}?t=${p}`);
|
152
|
+
return { config: y, path: o };
|
153
|
+
}, It = async (t, e) => {
|
154
|
+
var pt, mt;
|
155
|
+
const s = await J(t), n = {
|
156
|
+
mediaQueries: [],
|
157
|
+
globalStyles: [],
|
158
|
+
variables: [],
|
159
|
+
templates: []
|
160
|
+
};
|
161
|
+
await Promise.all(
|
162
|
+
[...e].map(async ($) => {
|
163
|
+
const { contents: w, outputFilePath: v } = await Y(t, $, s);
|
164
|
+
Object.entries(w).forEach(([x, k]) => {
|
165
|
+
k.isMedia ? n.mediaQueries.push([x, k]) : k.isGlobalDefine ? n.globalStyles.push(k) : k.isDefineVariables ? n.variables.push(k) : k.isDefineTemplates && n.templates.push(k._setPath(`${x};;${v}`));
|
166
|
+
});
|
167
|
+
})
|
168
|
+
);
|
169
|
+
const { config: o, path: a } = await Ht(t), i = { ...o }, p = /* @__PURE__ */ new Set(), y = ($, w = []) => $ ? Object.entries($).flatMap(([v, x]) => {
|
170
|
+
if (!x) return;
|
171
|
+
if (typeof x == "object") return y(x, [...w, v]);
|
172
|
+
const k = Ct(v), et = H(v), st = [...w, k].join(".");
|
173
|
+
p.add(`"${st}"`);
|
174
|
+
const q = [...w.map(H), et].join("-"), dt = _t(x);
|
175
|
+
return dt ? `--${q}: ${dt.transformed};` : `--${q}: ${x};`;
|
176
|
+
}) : [], m = ($) => $ ? Object.entries($).flatMap(([w, v]) => {
|
177
|
+
const x = y(v);
|
178
|
+
return w === "base" ? x.join("") : `${w} { ${x.join("")} }`;
|
179
|
+
}) : [], r = ($) => $ ? Object.entries($).flatMap(([w, v]) => Object.entries(v).flatMap(([x, k]) => {
|
180
|
+
const et = y(k, [w]), st = `.${w}-${x}, [data-${w}="${x}"]`, q = et.join("");
|
181
|
+
return `${st} { ${q} }`;
|
182
|
+
})) : [], g = ($) => ({ ...$, responsive: void 0, conditional: void 0 }), u = ($) => n.variables.map((w) => $ === "static" ? g(w._current) : w._current[$]), h = G(g(o.variables), u("static")), d = y(h), j = G((pt = o.variables) == null ? void 0 : pt.responsive, u("responsive")), P = m(j), D = G((mt = o.variables) == null ? void 0 : mt.conditional, u("conditional")), V = r(D), O = c(s, "css/_variables.css"), ut = `:root { ${d.join("")} ${P.join("")} } ${V.join("")}`;
|
183
|
+
C(O, ut), i.staticVariables = h;
|
184
|
+
const M = c(s, "css/_global.css"), tt = G(o.global, n.globalStyles), f = await at(tt, "");
|
185
|
+
C(M, `@layer global { ${f} }`);
|
186
|
+
const b = c(s, "css/_reset.css"), l = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : zt, F = await at(l, "");
|
187
|
+
C(b, `@layer reset { ${F} }`);
|
188
|
+
const N = c(s, "css/_templates.css"), T = G(o.templates, n.templates), I = await $t(T), K = Mt(T);
|
189
|
+
C(N, `@layer templates { ${I} }`), i.templates = T;
|
190
|
+
const L = o.templates ? [Ot(o.templates)._setPath(`config;;${a}`)] : [], B = Vt(n.templates, L);
|
191
|
+
i.templatePaths = Object.fromEntries(Object.entries(B).map(([$, w]) => [$, w._path]));
|
192
|
+
const { mediaQueries: Q } = n;
|
193
|
+
i.mediaQueries = Object.fromEntries(Q.map(([$, w]) => [`@${$}`, w]));
|
194
|
+
const A = Q.map(([$]) => `'@${$}'`).join(" | "), Z = c(s, "types/css-tokens.d.ts"), Pt = `
|
195
|
+
// Variable types
|
196
|
+
type VariableTokens = ${[...p].join("|")};
|
197
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
198
|
+
|
199
|
+
// Template types
|
200
|
+
type TemplateTokens = {
|
201
|
+
${Object.entries(K).map(([$, w]) => `${$}?: ${w}`).join(`
|
202
|
+
`)}
|
203
|
+
}
|
204
|
+
|
205
|
+
// Media query types
|
206
|
+
type MediaQueryKeys = ${A || "''"};
|
207
|
+
`;
|
208
|
+
C(Z, Pt);
|
209
|
+
const xt = c(s, "cache/config-cache.json");
|
210
|
+
C(xt, JSON.stringify(i, null, 2));
|
211
|
+
}, yt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
212
|
+
if (/^['"`]/.test(s)) return e;
|
213
|
+
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
214
|
+
if (!o.test(t)) return e;
|
215
|
+
const i = o.exec(t);
|
216
|
+
if (i) {
|
217
|
+
const p = i.at(1);
|
218
|
+
if (Ft.some((m) => p == null ? void 0 : p.includes(m))) return e;
|
219
|
+
}
|
220
|
+
return "styled('div',";
|
221
|
+
}), Kt = (t, e) => {
|
222
|
+
try {
|
223
|
+
const s = _(c(e, "saltygen/cache/config-cache.json"), "utf8");
|
224
|
+
return s ? `globalThis.saltyConfig = ${s};
|
225
|
+
|
226
|
+
${t}` : `globalThis.saltyConfig = {};
|
227
|
+
|
228
|
+
${t}`;
|
229
|
+
} catch {
|
230
|
+
return t;
|
231
|
+
}
|
232
|
+
}, Y = async (t, e, s) => {
|
233
|
+
const n = R(e), o = c(s, "./temp");
|
234
|
+
it(o) || W(o);
|
235
|
+
const a = X(e);
|
236
|
+
let i = _(e, "utf8");
|
237
|
+
i = yt(i), i = Kt(i, t);
|
238
|
+
const p = c(s, "js", n + ".js"), y = await rt(t), m = c(t, (y == null ? void 0 : y.configDir) || "", "salty.config.ts"), r = jt(m), g = await St(t);
|
239
|
+
await gt.build({
|
240
|
+
stdin: {
|
241
|
+
contents: i,
|
242
|
+
sourcefile: a.base,
|
243
|
+
resolveDir: a.dir,
|
244
|
+
loader: "tsx"
|
245
|
+
},
|
246
|
+
minify: !1,
|
247
|
+
treeShaking: !0,
|
248
|
+
bundle: !0,
|
249
|
+
outfile: p,
|
250
|
+
format: g,
|
251
|
+
target: ["node20"],
|
252
|
+
keepNames: !0,
|
253
|
+
external: r,
|
254
|
+
packages: "external",
|
255
|
+
plugins: [
|
256
|
+
{
|
257
|
+
name: "test",
|
258
|
+
setup: (d) => {
|
259
|
+
d.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (j) => {
|
260
|
+
const P = _(j.path, "utf8");
|
261
|
+
return { contents: yt(P), loader: "ts" };
|
262
|
+
});
|
263
|
+
}
|
264
|
+
}
|
265
|
+
]
|
266
|
+
});
|
267
|
+
const u = Date.now();
|
268
|
+
return { contents: await import(`${p}?t=${u}`), outputFilePath: p };
|
269
|
+
}, Lt = async (t) => {
|
270
|
+
const e = await J(t), s = c(e, "cache/config-cache.json"), n = _(s, "utf8");
|
271
|
+
if (!n) throw new Error("Could not find config cache file");
|
272
|
+
return JSON.parse(n);
|
273
|
+
}, lt = async (t) => {
|
274
|
+
const e = await Lt(t), s = await J(t), n = c(s, "salty.config.js"), o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
|
275
|
+
return G(a, e);
|
276
|
+
}, ft = () => {
|
277
|
+
try {
|
278
|
+
return process.env.NODE_ENV === "production";
|
279
|
+
} catch {
|
280
|
+
return !1;
|
281
|
+
}
|
282
|
+
}, oe = async (t, e = ft(), s = !0) => {
|
283
|
+
try {
|
284
|
+
const n = Date.now();
|
285
|
+
e ? U.info("Generating CSS in production mode! 🔥") : U.info("Generating CSS in development mode! 🚀");
|
286
|
+
const o = [], a = [], i = await J(t), p = c(i, "index.css");
|
287
|
+
s && (() => {
|
288
|
+
it(i) && Dt("rm -rf " + i), W(i, { recursive: !0 }), W(c(i, "css")), W(c(i, "types")), W(c(i, "js")), W(c(i, "cache"));
|
289
|
+
})();
|
290
|
+
const m = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
291
|
+
async function g(f) {
|
292
|
+
const b = ["node_modules", "saltygen"], S = kt(f);
|
293
|
+
if (S.isDirectory()) {
|
294
|
+
const l = Tt(f);
|
295
|
+
if (b.some((N) => f.includes(N))) return;
|
296
|
+
await Promise.all(l.map((N) => g(c(f, N))));
|
297
|
+
} else if (S.isFile() && ct(f)) {
|
298
|
+
m.add(f);
|
299
|
+
const F = _(f, "utf8");
|
300
|
+
/define[\w\d]+\(/.test(F) && r.add(f);
|
301
|
+
}
|
302
|
+
}
|
303
|
+
await g(t), await It(t, r);
|
304
|
+
const u = {
|
305
|
+
keyframes: [],
|
306
|
+
components: [],
|
307
|
+
classNames: []
|
308
|
+
};
|
309
|
+
await Promise.all(
|
310
|
+
[...m].map(async (f) => {
|
311
|
+
const { contents: b } = await Y(t, f, i);
|
312
|
+
for (let [S, l] of Object.entries(b))
|
313
|
+
l instanceof Promise && (l = await l), l.isKeyframes ? u.keyframes.push({
|
314
|
+
value: l,
|
315
|
+
src: f,
|
316
|
+
name: S
|
317
|
+
}) : l.isClassName ? u.classNames.push({
|
318
|
+
...l,
|
319
|
+
src: f,
|
320
|
+
name: S
|
321
|
+
}) : l.generator && u.components.push({
|
322
|
+
...l,
|
323
|
+
src: f,
|
324
|
+
name: S
|
325
|
+
});
|
326
|
+
})
|
327
|
+
);
|
328
|
+
const h = await lt(t);
|
329
|
+
for (const f of u.keyframes) {
|
330
|
+
const { value: b } = f, S = `a_${b.animationName}.css`, l = `css/${S}`, F = c(i, l);
|
331
|
+
o.push(S), C(F, b.css);
|
332
|
+
}
|
333
|
+
const d = {};
|
334
|
+
for (const f of u.components) {
|
335
|
+
const { src: b, name: S } = f;
|
336
|
+
d[b] || (d[b] = []);
|
337
|
+
const l = f.generator._withBuildContext({
|
338
|
+
callerName: S,
|
339
|
+
isProduction: e,
|
340
|
+
config: h
|
341
|
+
});
|
342
|
+
a[l.priority] || (a[l.priority] = []);
|
343
|
+
const F = await l.css;
|
344
|
+
if (!F) continue;
|
345
|
+
a[l.priority].push(l.cssFileName);
|
346
|
+
const N = `css/${l.cssFileName}`, T = c(i, N);
|
347
|
+
C(T, F), h.importStrategy === "component" && d[b].push(l.cssFileName);
|
348
|
+
}
|
349
|
+
for (const f of u.classNames) {
|
350
|
+
const { src: b, name: S } = f;
|
351
|
+
d[b] || (d[b] = []);
|
352
|
+
const l = f.generator._withBuildContext({
|
353
|
+
callerName: S,
|
354
|
+
isProduction: e,
|
355
|
+
config: h
|
356
|
+
}), F = await l.css;
|
357
|
+
if (!F) continue;
|
358
|
+
a[l.priority] || (a[l.priority] = []), a[l.priority].push(l.cssFileName);
|
359
|
+
const N = `css/${l.cssFileName}`, T = c(i, N);
|
360
|
+
C(T, F), h.importStrategy === "component" && d[b].push(l.cssFileName);
|
361
|
+
}
|
362
|
+
h.importStrategy === "component" && Object.entries(d).forEach(([f, b]) => {
|
363
|
+
const S = b.map((I) => `@import url('./${I}');`).join(`
|
364
|
+
`), l = R(f, 6), F = X(f), N = H(F.name), T = c(i, `css/f_${N}-${l}.css`);
|
365
|
+
C(T, S || "/* Empty file */");
|
366
|
+
});
|
367
|
+
const j = o.map((f) => `@import url('./css/${f}');`).join(`
|
368
|
+
`);
|
369
|
+
let O = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
370
|
+
|
371
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) => {
|
372
|
+
try {
|
373
|
+
return _(c(i, "css", f), "utf8").length > 0;
|
374
|
+
} catch {
|
375
|
+
return !1;
|
376
|
+
}
|
377
|
+
}).map((f) => `@import url('./css/${f}');`).join(`
|
378
|
+
`)}
|
379
|
+
${j}`;
|
380
|
+
if (h.importStrategy !== "component") {
|
381
|
+
const f = a.reduce((b, S, l) => {
|
382
|
+
const F = S.reduce((K, L) => {
|
383
|
+
var Z;
|
384
|
+
const B = c(i, "css", L), Q = _(B, "utf8"), A = ((Z = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : Z.at(1)) || R(B, 6);
|
385
|
+
return K.includes(A) ? K : `${K}
|
386
|
+
/*start:${A}-${L}*/
|
387
|
+
${Q}
|
388
|
+
/*end:${A}*/
|
389
|
+
`;
|
390
|
+
}, ""), N = `l_${l}.css`, T = c(i, "css", N), I = `@layer l${l} { ${F}
|
391
|
+
}`;
|
392
|
+
return C(T, I), `${b}
|
393
|
+
@import url('./css/${N}');`;
|
394
|
+
}, "");
|
395
|
+
O += f;
|
396
|
+
}
|
397
|
+
C(p, O);
|
398
|
+
const M = Date.now() - n, tt = M < 200 ? "🔥" : M < 500 ? "🚀" : M < 1e3 ? "🎉" : M < 2e3 ? "🚗" : M < 5e3 ? "🤔" : "🥴";
|
399
|
+
U.info(`Generated CSS in ${M}ms! ${tt}`);
|
400
|
+
} catch (n) {
|
401
|
+
console.error(n);
|
402
|
+
}
|
403
|
+
}, ae = async (t, e, s = ft()) => {
|
404
|
+
try {
|
405
|
+
const n = await J(t);
|
406
|
+
if (ct(e)) {
|
407
|
+
const a = [], i = await lt(t), { contents: p } = await Y(t, e, n);
|
408
|
+
for (const [y, m] of Object.entries(p)) {
|
409
|
+
if (m.isKeyframes && m.css) {
|
410
|
+
const j = `css/${`a_${m.animationName}.css`}`, P = c(n, j);
|
411
|
+
C(P, await m.css);
|
412
|
+
return;
|
413
|
+
}
|
414
|
+
if (m.isClassName) {
|
415
|
+
const d = m.generator._withBuildContext({
|
416
|
+
callerName: y,
|
417
|
+
isProduction: s,
|
418
|
+
config: i
|
419
|
+
}), j = await d.css;
|
420
|
+
if (!j) continue;
|
421
|
+
a[d.priority] || (a[d.priority] = []), a[d.priority].push(d.cssFileName);
|
422
|
+
const P = `css/${d.cssFileName}`, D = c(n, P);
|
423
|
+
C(D, j);
|
424
|
+
}
|
425
|
+
if (!m.generator) return;
|
426
|
+
const r = m.generator._withBuildContext({
|
427
|
+
callerName: y,
|
428
|
+
isProduction: s,
|
429
|
+
config: i
|
430
|
+
}), g = await r.css;
|
431
|
+
if (!g) continue;
|
432
|
+
const u = `css/${r.cssFileName}`, h = c(n, u);
|
433
|
+
C(h, g), a[r.priority] || (a[r.priority] = []), a[r.priority].push(r.cssFileName);
|
434
|
+
}
|
435
|
+
if (i.importStrategy !== "component")
|
436
|
+
a.forEach((y, m) => {
|
437
|
+
const r = `l_${m}.css`, g = c(n, "css", r);
|
438
|
+
let u = _(g, "utf8");
|
439
|
+
y.forEach((h) => {
|
440
|
+
var D;
|
441
|
+
const d = c(n, "css", h), j = ((D = /.*-([^-]+)-\d+.css/.exec(h)) == null ? void 0 : D.at(1)) || R(d, 6);
|
442
|
+
if (!u.includes(j)) {
|
443
|
+
const V = _(d, "utf8"), O = `/*start:${j}-${h}*/
|
444
|
+
${V}
|
445
|
+
/*end:${j}*/
|
446
|
+
`;
|
447
|
+
u = `${u.replace(/\}$/, "")}
|
448
|
+
${O}
|
449
|
+
}`;
|
450
|
+
}
|
451
|
+
}), C(g, u);
|
452
|
+
});
|
453
|
+
else {
|
454
|
+
const y = a.flat().map((h) => `@import url('./${h}');`).join(`
|
455
|
+
`), m = R(e, 6), r = X(e), g = H(r.name), u = c(n, `css/f_${g}-${m}.css`);
|
456
|
+
C(u, y || "/* Empty file */");
|
457
|
+
}
|
458
|
+
}
|
459
|
+
} catch (n) {
|
460
|
+
console.error(n);
|
461
|
+
}
|
462
|
+
}, ie = async (t, e, s = ft()) => {
|
463
|
+
var n, o;
|
464
|
+
try {
|
465
|
+
const a = await J(t);
|
466
|
+
if (ct(e)) {
|
467
|
+
const p = _(e, "utf8"), y = await lt(t), { contents: m } = await Y(t, e, a);
|
468
|
+
let r = p;
|
469
|
+
for (const [g, u] of Object.entries(m)) {
|
470
|
+
if (u.isKeyframes || !u.generator) continue;
|
471
|
+
const h = u.generator._withBuildContext({
|
472
|
+
callerName: g,
|
473
|
+
isProduction: s,
|
474
|
+
config: y
|
475
|
+
}), [d, j] = await Wt(r, g), P = r.slice(d, j);
|
476
|
+
if (u.isClassName) {
|
477
|
+
const D = r, V = ` ${g} = className("${h.classNames}")`;
|
478
|
+
r = r.replace(P, V), D === r && console.error("Minimize file failed to change content", { name: g });
|
479
|
+
}
|
480
|
+
if (P.includes("styled")) {
|
481
|
+
const D = (o = (n = /styled\(([^,]+),/.exec(P)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), V = r, O = ` ${g} = styled(${D}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;
|
482
|
+
r = r.replace(P, O), V === r && console.error("Minimize file failed to change content", { name: g, tagName: D });
|
483
|
+
}
|
484
|
+
}
|
485
|
+
if (y.importStrategy === "component") {
|
486
|
+
const g = R(e, 6), u = X(e);
|
487
|
+
r = `import '../../saltygen/css/${`f_${H(u.name)}-${g}.css`}';
|
488
|
+
${r}`;
|
489
|
+
}
|
490
|
+
return r = r.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
|
491
|
+
}
|
492
|
+
} catch (a) {
|
493
|
+
console.error("Error in minimizeFile:", a);
|
494
|
+
}
|
495
|
+
};
|
496
|
+
export {
|
497
|
+
ne as a,
|
498
|
+
Gt as b,
|
499
|
+
It as c,
|
500
|
+
Y as d,
|
501
|
+
ae as e,
|
502
|
+
oe as g,
|
503
|
+
ct as i,
|
504
|
+
U as l,
|
505
|
+
ie as m,
|
506
|
+
Ft as s
|
507
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";const Pe=require("esbuild"),ke=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),c=require("path"),r=require("fs"),de=require("fs/promises"),U=require("./parse-styles-3N79AOBO.cjs"),L=require("winston"),R=require("./css/merge.cjs"),xe=require("./define-templates-Cunsb_Tr.cjs"),se=require("typescript");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 me=De(Pe),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,i]of Object.entries(e))if(typeof i!="function")if(i&&typeof i=="object"){const a=o.trim(),d=await ye(i,[...t,a]);s.push(d)}else n[o]=i;if(Object.keys(n).length){const o=t.map(D.dashCase).join("-"),i="t_"+D.toHash(o,4),a=await U.parseAndJoinStyles(n,`.${o}, .${i}`);s.push(a)}return s.join(`
|
2
|
+
`)},_e=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=ge(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},ge=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?ge(o,i,s):s.add(t)}),[...s]):[],he=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=c.join(e,"package.json");return r.existsSync(t)?t:he(c.join(e,".."))},Te=async e=>{const t=he(e);return await de.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Oe=async e=>{const t=await Te(e);if(t)return t.type};let z;const Se=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-q4N-TRZZ.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},A=L.createLogger({level:"debug",format:L.format.combine(L.format.colorize(),L.format.cli()),transports:[new L.transports.Console({})]}),ve=e=>{A.error(e)};function je(e){return e?typeof e!="string"?je(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"}},Ve=(e,t)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),i=se.createSourceFile("temp.ts",e,se.ScriptTarget.Latest,!0);function a(d){if(se.isVariableDeclaration(d)&&d.name.getText()===t){const g=d.getStart(),m=d.getEnd();clearTimeout(o),s([g,m])}d.forEachChild(a)}a(i)}),v={externalModules:[],rcFile:void 0,destDir:void 0},be=e=>{if(v.externalModules.length>0)return v.externalModules;const s=r.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},J=async e=>{if(v.destDir)return v.destDir;const t=await ie(e),s=c.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return v.destDir=s,s},oe=["salty","css","styles","styled"],we=(e=[])=>new RegExp(`\\.(${[...oe,...e].join("|")})\\.`),X=(e,t=[])=>we(t).test(e),$e=async e=>{if(v.rcFile)return v.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=c.join(e,".saltyrc.json"),s=await de.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):$e(c.join(e,".."))},ie=async e=>{var n,o;const t=await $e(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},Me=async e=>{const t=await ie(e),s=await J(e),n=c.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await Se(e),a=be(n);await me.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:a});const d=Date.now(),{config:g}=await import(`${o}?t=${d}`);return{config:g,path:o}},Fe=async(e,t)=>{var le,fe;const s=await J(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async j=>{const{contents:w,outputFilePath:O}=await G(e,j,s);Object.entries(w).forEach(([k,_])=>{_.isMedia?n.mediaQueries.push([k,_]):_.isGlobalDefine?n.globalStyles.push(_):_.isDefineVariables?n.variables.push(_):_.isDefineTemplates&&n.templates.push(_._setPath(`${k};;${O}`))})}));const{config:o,path:i}=await Me(e),a={...o},d=new Set,g=(j,w=[])=>j?Object.entries(j).flatMap(([O,k])=>{if(!k)return;if(typeof k=="object")return g(k,[...w,O]);const _=je(O),ee=D.dashCase(O),te=[...w,_].join(".");d.add(`"${te}"`);const Z=[...w.map(D.dashCase),ee].join("-"),ue=U.parseVariableTokens(k);return ue?`--${Z}: ${ue.transformed};`:`--${Z}: ${k};`}):[],m=j=>j?Object.entries(j).flatMap(([w,O])=>{const k=g(O);return w==="base"?k.join(""):`${w} { ${k.join("")} }`}):[],l=j=>j?Object.entries(j).flatMap(([w,O])=>Object.entries(O).flatMap(([k,_])=>{const ee=g(_,[w]),te=`.${w}-${k}, [data-${w}="${k}"]`,Z=ee.join("");return`${te} { ${Z} }`})):[],h=j=>({...j,responsive:void 0,conditional:void 0}),p=j=>n.variables.map(w=>j==="static"?h(w._current):w._current[j]),S=R.mergeObjects(h(o.variables),p("static")),y=g(S),F=R.mergeObjects((le=o.variables)==null?void 0:le.responsive,p("responsive")),P=m(F),x=R.mergeObjects((fe=o.variables)==null?void 0:fe.conditional,p("conditional")),E=l(x),V=c.join(s,"css/_variables.css"),re=`:root { ${y.join("")} ${P.join("")} } ${E.join("")}`;r.writeFileSync(V,re),a.staticVariables=S;const M=c.join(s,"css/_global.css"),Y=R.mergeObjects(o.global,n.globalStyles),u=await U.parseAndJoinStyles(Y,"");r.writeFileSync(M,`@layer global { ${u} }`);const b=c.join(s,"css/_reset.css"),f=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Ee,C=await U.parseAndJoinStyles(f,"");r.writeFileSync(b,`@layer reset { ${C} }`);const N=c.join(s,"css/_templates.css"),T=R.mergeObjects(o.templates,n.templates),q=await ye(T),H=_e(T);r.writeFileSync(N,`@layer templates { ${q} }`),a.templates=T;const W=o.templates?[xe.defineTemplates(o.templates)._setPath(`config;;${i}`)]:[],K=R.mergeFactories(n.templates,W);a.templatePaths=Object.fromEntries(Object.entries(K).map(([j,w])=>[j,w._path]));const{mediaQueries:B}=n;a.mediaQueries=Object.fromEntries(B.map(([j,w])=>[`@${j}`,w]));const I=B.map(([j])=>`'@${j}'`).join(" | "),Q=c.join(s,"types/css-tokens.d.ts"),Ce=`
|
3
|
+
// Variable types
|
4
|
+
type VariableTokens = ${[...d].join("|")};
|
5
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
+
|
7
|
+
// Template types
|
8
|
+
type TemplateTokens = {
|
9
|
+
${Object.entries(H).map(([j,w])=>`${j}?: ${w}`).join(`
|
10
|
+
`)}
|
11
|
+
}
|
12
|
+
|
13
|
+
// Media query types
|
14
|
+
type MediaQueryKeys = ${I||"''"};
|
15
|
+
`;r.writeFileSync(Q,Ce);const Ne=c.join(s,"cache/config-cache.json");r.writeFileSync(Ne,JSON.stringify(a,null,2))},pe=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const a=o.exec(e);if(a){const d=a.at(1);if(oe.some(m=>d==null?void 0:d.includes(m)))return t}return"styled('div',"}),Re=(e,t)=>{try{const s=r.readFileSync(c.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
+
|
17
|
+
${e}`:`globalThis.saltyConfig = {};
|
18
|
+
|
19
|
+
${e}`}catch{return e}},G=async(e,t,s)=>{const n=D.toHash(t),o=c.join(s,"./temp");r.existsSync(o)||r.mkdirSync(o);const i=c.parse(t);let a=r.readFileSync(t,"utf8");a=pe(a),a=Re(a,e);const d=c.join(s,"js",n+".js"),g=await ie(e),m=c.join(e,(g==null?void 0:g.configDir)||"","salty.config.ts"),l=be(m),h=await Se(e);await me.build({stdin:{contents:a,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:h,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:y=>{y.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},F=>{const P=r.readFileSync(F.path,"utf8");return{contents:pe(P),loader:"ts"}})}}]});const p=Date.now();return{contents:await import(`${d}?t=${p}`),outputFilePath:d}},Je=async e=>{const t=await J(e),s=c.join(t,"cache/config-cache.json"),n=r.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Je(e),s=await J(e),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return R.mergeObjects(i,t)},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ze=async(e,t=ce(),s=!0)=>{try{const n=Date.now();t?A.info("Generating CSS in production mode! 🔥"):A.info("Generating CSS in development mode! 🚀");const o=[],i=[],a=await J(e),d=c.join(a,"index.css");s&&(()=>{r.existsSync(a)&&ke.execSync("rm -rf "+a),r.mkdirSync(a,{recursive:!0}),r.mkdirSync(c.join(a,"css")),r.mkdirSync(c.join(a,"types")),r.mkdirSync(c.join(a,"js")),r.mkdirSync(c.join(a,"cache"))})();const m=new Set,l=new Set;async function h(u){const b=["node_modules","saltygen"],$=r.statSync(u);if($.isDirectory()){const f=r.readdirSync(u);if(b.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>h(c.join(u,N))))}else if($.isFile()&&X(u)){m.add(u);const C=r.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&l.add(u)}}await h(e),await Fe(e,l);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async u=>{const{contents:b}=await G(e,u,a);for(let[$,f]of Object.entries(b))f instanceof Promise&&(f=await f),f.isKeyframes?p.keyframes.push({value:f,src:u,name:$}):f.isClassName?p.classNames.push({...f,src:u,name:$}):f.generator&&p.components.push({...f,src:u,name:$})}));const S=await ae(e);for(const u of p.keyframes){const{value:b}=u,$=`a_${b.animationName}.css`,f=`css/${$}`,C=c.join(a,f);o.push($),r.writeFileSync(C,b.css)}const y={};for(const u of p.components){const{src:b,name:$}=u;y[b]||(y[b]=[]);const f=u.generator._withBuildContext({callerName:$,isProduction:t,config:S});i[f.priority]||(i[f.priority]=[]);const C=await f.css;if(!C)continue;i[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,T=c.join(a,N);r.writeFileSync(T,C),S.importStrategy==="component"&&y[b].push(f.cssFileName)}for(const u of p.classNames){const{src:b,name:$}=u;y[b]||(y[b]=[]);const f=u.generator._withBuildContext({callerName:$,isProduction:t,config:S}),C=await f.css;if(!C)continue;i[f.priority]||(i[f.priority]=[]),i[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,T=c.join(a,N);r.writeFileSync(T,C),S.importStrategy==="component"&&y[b].push(f.cssFileName)}S.importStrategy==="component"&&Object.entries(y).forEach(([u,b])=>{const $=b.map(q=>`@import url('./${q}');`).join(`
|
20
|
+
`),f=D.toHash(u,6),C=c.parse(u),N=D.dashCase(C.name),T=c.join(a,`css/f_${N}-${f}.css`);r.writeFileSync(T,$||"/* Empty file */")});const F=o.map(u=>`@import url('./css/${u}');`).join(`
|
21
|
+
`);let V=`@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 r.readFileSync(c.join(a,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
24
|
+
`)}
|
25
|
+
${F}`;if(S.importStrategy!=="component"){const u=i.reduce((b,$,f)=>{const C=$.reduce((H,W)=>{var Q;const K=c.join(a,"css",W),B=r.readFileSync(K,"utf8"),I=((Q=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:Q.at(1))||D.toHash(K,6);return H.includes(I)?H:`${H}
|
26
|
+
/*start:${I}-${W}*/
|
27
|
+
${B}
|
28
|
+
/*end:${I}*/
|
29
|
+
`},""),N=`l_${f}.css`,T=c.join(a,"css",N),q=`@layer l${f} { ${C}
|
30
|
+
}`;return r.writeFileSync(T,q),`${b}
|
31
|
+
@import url('./css/${N}');`},"");V+=u}r.writeFileSync(d,V);const M=Date.now()-n,Y=M<200?"🔥":M<500?"🚀":M<1e3?"🎉":M<2e3?"🚗":M<5e3?"🤔":"🥴";A.info(`Generated CSS in ${M}ms! ${Y}`)}catch(n){console.error(n)}},qe=async(e,t,s=ce())=>{try{const n=await J(e);if(X(t)){const i=[],a=await ae(e),{contents:d}=await G(e,t,n);for(const[g,m]of Object.entries(d)){if(m.isKeyframes&&m.css){const F=`css/${`a_${m.animationName}.css`}`,P=c.join(n,F);r.writeFileSync(P,await m.css);return}if(m.isClassName){const y=m.generator._withBuildContext({callerName:g,isProduction:s,config:a}),F=await y.css;if(!F)continue;i[y.priority]||(i[y.priority]=[]),i[y.priority].push(y.cssFileName);const P=`css/${y.cssFileName}`,x=c.join(n,P);r.writeFileSync(x,F)}if(!m.generator)return;const l=m.generator._withBuildContext({callerName:g,isProduction:s,config:a}),h=await l.css;if(!h)continue;const p=`css/${l.cssFileName}`,S=c.join(n,p);r.writeFileSync(S,h),i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName)}if(a.importStrategy!=="component")i.forEach((g,m)=>{const l=`l_${m}.css`,h=c.join(n,"css",l);let p=r.readFileSync(h,"utf8");g.forEach(S=>{var x;const y=c.join(n,"css",S),F=((x=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:x.at(1))||D.toHash(y,6);if(!p.includes(F)){const E=r.readFileSync(y,"utf8"),V=`/*start:${F}-${S}*/
|
32
|
+
${E}
|
33
|
+
/*end:${F}*/
|
34
|
+
`;p=`${p.replace(/\}$/,"")}
|
35
|
+
${V}
|
36
|
+
}`}}),r.writeFileSync(h,p)});else{const g=i.flat().map(S=>`@import url('./${S}');`).join(`
|
37
|
+
`),m=D.toHash(t,6),l=c.parse(t),h=D.dashCase(l.name),p=c.join(n,`css/f_${h}-${m}.css`);r.writeFileSync(p,g||"/* Empty file */")}}}catch(n){console.error(n)}},He=async(e,t,s=ce())=>{var n,o;try{const i=await J(e);if(X(t)){const d=r.readFileSync(t,"utf8"),g=await ae(e),{contents:m}=await G(e,t,i);let l=d;for(const[h,p]of Object.entries(m)){if(p.isKeyframes||!p.generator)continue;const S=p.generator._withBuildContext({callerName:h,isProduction:s,config:g}),[y,F]=await Ve(l,h),P=l.slice(y,F);if(p.isClassName){const x=l,E=` ${h} = className("${S.classNames}")`;l=l.replace(P,E),x===l&&console.error("Minimize file failed to change content",{name:h})}if(P.includes("styled")){const x=(o=(n=/styled\(([^,]+),/.exec(P))==null?void 0:n.at(1))==null?void 0:o.trim(),E=l,V=` ${h} = styled(${x}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace(P,V),E===l&&console.error("Minimize file failed to change content",{name:h,tagName:x})}}if(g.importStrategy==="component"){const h=D.toHash(t,6),p=c.parse(t);l=`import '../../saltygen/css/${`f_${D.dashCase(p.name)}-${h}.css`}';
|
38
|
+
${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(i){console.error("Error in minimizeFile:",i)}};exports.compileSaltyFile=G;exports.generateConfigStyles=Fe;exports.generateCss=ze;exports.generateFile=qe;exports.isSaltyFile=X;exports.logError=ve;exports.logger=A;exports.minimizeFile=He;exports.saltyFileExtensions=oe;exports.saltyFileRegExp=we;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/core",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.229",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"esbuild": ">=0.21.x",
|
36
36
|
"ora": ">=8.x",
|
37
37
|
"react": ">=18.x || >=19.x",
|
38
|
-
"
|
38
|
+
"typescript": ">=5.x",
|
39
39
|
"winston": ">=3.x"
|
40
40
|
},
|
41
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-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-q4N-TRZZ.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-
|
2
|
+
import { i as e } from "../index-CuYozIxT.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;
|
package/index-BR0X24-T.js
DELETED
@@ -1,496 +0,0 @@
|
|
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
|
-
};
|
package/index-_XWMZNGO.cjs
DELETED
@@ -1,38 +0,0 @@
|
|
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;
|