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