@salty-css/core 0.0.1-alpha.14 → 0.0.1-alpha.141

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.
Files changed (49) hide show
  1. package/.saltyrc.schema.json +40 -0
  2. package/README.md +143 -26
  3. package/bin/bin-util.d.ts +2 -0
  4. package/bin/index.cjs +2 -0
  5. package/bin/index.d.ts +2 -0
  6. package/bin/index.js +3 -0
  7. package/bin/logger.d.ts +2 -0
  8. package/bin/main.cjs +11 -0
  9. package/bin/main.d.ts +1 -0
  10. package/bin/main.js +260 -0
  11. package/bin/prettier.d.ts +1 -0
  12. package/compiler/get-files.d.ts +3 -0
  13. package/compiler/index.cjs +1 -11
  14. package/compiler/index.d.ts +4 -6
  15. package/compiler/index.js +16 -178
  16. package/config/config-types.d.ts +15 -5
  17. package/dash-case-BJEkFEGQ.cjs +1 -0
  18. package/dash-case-DBThphLm.js +19 -0
  19. package/generator/index.cjs +1 -1
  20. package/generator/index.js +51 -32
  21. package/generator/parse-styles.d.ts +1 -1
  22. package/generator/parse-templates.d.ts +2 -0
  23. package/generator/style-generator.d.ts +8 -0
  24. package/index-84Wroia-.cjs +1 -0
  25. package/index-C6kc7u48.js +349 -0
  26. package/index-D_732b92.js +4 -0
  27. package/index-FtLw6IR2.cjs +22 -0
  28. package/package.json +20 -2
  29. package/parse-templates-CgZo0YA1.js +97 -0
  30. package/parse-templates-DD4hQEpv.cjs +8 -0
  31. package/pascal-case-BQpR5PdN.js +6 -0
  32. package/pascal-case-iWoaJWwT.cjs +1 -0
  33. package/react-styled-file-CGVf5n1B.js +11 -0
  34. package/react-styled-file-Dkubsz-U.cjs +8 -0
  35. package/react-vanilla-file-CCXbsjIb.js +18 -0
  36. package/react-vanilla-file-CG_WJLam.cjs +15 -0
  37. package/salty.config-BhBY_oOk.js +10 -0
  38. package/salty.config-Dk6ZcCxI.cjs +7 -0
  39. package/templates/salty-reset.d.ts +2 -0
  40. package/types/index.d.ts +46 -19
  41. package/util/camel-case.d.ts +1 -0
  42. package/util/dot-case.d.ts +1 -0
  43. package/util/index.cjs +1 -1
  44. package/util/index.d.ts +2 -0
  45. package/util/index.js +7 -15
  46. package/util/module-type.d.ts +1 -0
  47. package/util/pascal-case.d.ts +1 -0
  48. package/parse-templates-BOSK0Tb6.js +0 -90
  49. package/parse-templates-BY1Xai-_.cjs +0 -8
@@ -0,0 +1,349 @@
1
+ import * as Y from "esbuild";
2
+ import { execSync as lt } from "child_process";
3
+ import { t as B, d as z } from "./dash-case-DBThphLm.js";
4
+ import { join as r, parse as H } from "path";
5
+ import { existsSync as K, writeFileSync as w, mkdirSync as J, readFileSync as V, statSync as pt, readdirSync as ft } from "fs";
6
+ import { readFile as dt, writeFile as ut } from "fs/promises";
7
+ import { p as U, a as gt, b as mt, c as yt } from "./parse-templates-CgZo0YA1.js";
8
+ import { createLogger as ht, format as I, transports as $t } from "winston";
9
+ const Q = (t) => {
10
+ if (!t || t === "/") throw new Error("Could not find package.json file");
11
+ const e = r(t, "package.json");
12
+ return K(e) ? e : Q(r(t, ".."));
13
+ }, bt = async (t) => {
14
+ const e = Q(t);
15
+ return await dt(e, "utf-8").then(JSON.parse).catch(() => {
16
+ });
17
+ }, St = async (t) => {
18
+ const e = await bt(t);
19
+ if (e)
20
+ return e.type;
21
+ };
22
+ let R;
23
+ const tt = async (t) => {
24
+ if (R) return R;
25
+ const e = await St(t);
26
+ return e === "module" ? R = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (R = "cjs"), R || "esm";
27
+ }, O = ht({
28
+ level: "debug",
29
+ format: I.combine(I.colorize(), I.cli()),
30
+ transports: [new $t.Console({})]
31
+ }), Mt = (t) => {
32
+ O.error(t);
33
+ };
34
+ function et(t) {
35
+ return t ? typeof t != "string" ? et(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, n) => (n > 0 ? "." : "") + e.toLowerCase()) : "";
36
+ }
37
+ const wt = {
38
+ /** Set box model to border-box */
39
+ "*, *::before, *::after": {
40
+ boxSizing: "border-box"
41
+ },
42
+ /** Remove default margin and padding */
43
+ "*": {
44
+ margin: 0
45
+ },
46
+ /** Remove adjust font properties */
47
+ html: {
48
+ lineHeight: 1.15,
49
+ textSizeAdjust: "100%",
50
+ WebkitFontSmoothing: "antialiased"
51
+ },
52
+ /** Make media elements responsive */
53
+ "img, picture, video, canvas, svg": {
54
+ display: "block",
55
+ maxWidth: "100%"
56
+ },
57
+ /** Avoid overflow of text */
58
+ "p, h1, h2, h3, h4, h5, h6": {
59
+ overflowWrap: "break-word"
60
+ },
61
+ /** Improve text wrapping */
62
+ p: {
63
+ textWrap: "pretty"
64
+ },
65
+ "h1, h2, h3, h4, h5, h6": {
66
+ textWrap: "balance"
67
+ },
68
+ /** Improve link color */
69
+ a: {
70
+ color: "currentColor"
71
+ },
72
+ /** Improve button line height */
73
+ button: {
74
+ lineHeight: "1em",
75
+ color: "currentColor"
76
+ },
77
+ /** Improve form elements */
78
+ "input, optgroup, select, textarea": {
79
+ fontFamily: "inherit",
80
+ fontSize: "100%",
81
+ lineHeight: "1.15em"
82
+ }
83
+ }, A = {
84
+ externalModules: []
85
+ }, st = (t) => {
86
+ if (A.externalModules.length > 0) return A.externalModules;
87
+ const e = r(t, "salty.config.ts"), a = V(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
88
+ if (!a) return [];
89
+ const c = a[1].split(",").map((s) => s.replace(/['"`]/g, "").trim());
90
+ return A.externalModules = c, c;
91
+ }, W = (t) => r(t, "./saltygen"), nt = ["salty", "css", "styles", "styled"], xt = (t = []) => new RegExp(`\\.(${[...nt, ...t].join("|")})\\.`), L = (t, e = []) => xt(e).test(t), Ct = async (t) => {
92
+ const e = W(t), n = r(t, "salty.config.ts"), a = r(e, "salty.config.js"), c = await tt(t), s = st(t);
93
+ await Y.build({
94
+ entryPoints: [n],
95
+ minify: !0,
96
+ treeShaking: !0,
97
+ bundle: !0,
98
+ outfile: a,
99
+ format: c,
100
+ external: s
101
+ });
102
+ const d = Date.now(), { config: u } = await import(`${a}?t=${d}`);
103
+ return u;
104
+ }, Ft = async (t) => {
105
+ const e = await Ct(t), n = /* @__PURE__ */ new Set(), a = (l, p = []) => l ? Object.entries(l).flatMap(([h, f]) => {
106
+ if (!f) return;
107
+ if (typeof f == "object") return a(f, [...p, h]);
108
+ const M = et(h), v = z(h), _ = [...p, M].join(".");
109
+ n.add(`"${_}"`);
110
+ const j = [...p.map(z), v].join("-"), { result: T } = yt(f);
111
+ return `--${j}: ${T};`;
112
+ }) : [], c = (l) => l ? Object.entries(l).flatMap(([p, h]) => {
113
+ const f = a(h);
114
+ return p === "base" ? f.join("") : `${p} { ${f.join("")} }`;
115
+ }) : [], s = (l) => l ? Object.entries(l).flatMap(([p, h]) => Object.entries(h).flatMap(([f, M]) => {
116
+ const v = a(M, [p]), _ = `.${p}-${f}, [data-${p}="${f}"]`, j = v.join("");
117
+ return `${_} { ${j} }`;
118
+ })) : [], d = a(e.variables), u = c(e.responsiveVariables), $ = s(e.conditionalVariables), o = W(t), g = r(o, "css/_variables.css"), C = `:root { ${d.join("")} ${u.join("")} } ${$.join("")}`;
119
+ w(g, C);
120
+ const x = r(o, "css/_global.css"), m = U(e.global, "");
121
+ w(x, `@layer global { ${m} }`);
122
+ const b = r(o, "css/_reset.css"), y = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : wt, k = U(y, "");
123
+ w(b, `@layer reset { ${k} }`);
124
+ const i = r(o, "css/_templates.css"), S = gt(e.templates), D = mt(e.templates);
125
+ w(i, S);
126
+ const F = r(o, "types/css-tokens.d.ts"), N = `
127
+ // Variable types
128
+ type VariableTokens = ${[...n].join("|")};
129
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
130
+
131
+ // Template types
132
+ type TemplateTokens = {
133
+ ${Object.entries(D).map(([l, p]) => `${l}?: ${p}`).join(`
134
+ `)}
135
+ }
136
+ `;
137
+ w(F, N);
138
+ }, X = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, n) => {
139
+ const a = /^['"`]/.test(n);
140
+ if (a && console.log("String tag", n), a) return e;
141
+ const c = new RegExp(`import[^;]*${n}[,\\s{][^;]*from\\s?([^{};]+);`), s = c.test(t);
142
+ if (s || console.log("Not imported", n), !s) return e;
143
+ const d = c.exec(t);
144
+ if (d) {
145
+ const u = d.at(1), $ = nt.some((o) => u == null ? void 0 : u.includes(o));
146
+ if ($ && console.log("Salty import for", n, `"${d.at(0)}"`), $) return e;
147
+ }
148
+ return console.log("Replacing", n), "styled('div',";
149
+ }), Z = async (t, e, n) => {
150
+ console.log({ sourceFilePath: e });
151
+ const a = B(e), c = r(n, "./temp");
152
+ K(c) || J(c);
153
+ const s = H(e);
154
+ let d = V(e, "utf8");
155
+ d = X(d);
156
+ const u = r(n, "js", a + ".js"), $ = st(t), o = await tt(t);
157
+ await Y.build({
158
+ stdin: {
159
+ contents: d,
160
+ sourcefile: s.base,
161
+ resolveDir: s.dir,
162
+ loader: "tsx"
163
+ },
164
+ minify: !1,
165
+ treeShaking: !0,
166
+ bundle: !0,
167
+ outfile: u,
168
+ format: o,
169
+ target: ["node20"],
170
+ keepNames: !0,
171
+ external: $,
172
+ packages: "external",
173
+ plugins: [
174
+ {
175
+ name: "test",
176
+ setup: (x) => {
177
+ x.onLoad({ filter: /.*.css.ts/ }, (m) => {
178
+ console.log("Loading", {
179
+ sourceFilePath: e,
180
+ args: m
181
+ });
182
+ const b = V(m.path, "utf8");
183
+ return { contents: X(b), loader: "ts" };
184
+ });
185
+ }
186
+ }
187
+ ]
188
+ });
189
+ const g = Date.now();
190
+ return await import(`${u}?t=${g}`);
191
+ }, G = async (t) => {
192
+ const e = W(t), n = r(e, "salty.config.js"), a = Date.now(), { config: c } = await import(`${n}?t=${a}`);
193
+ return c;
194
+ }, ot = () => {
195
+ try {
196
+ return process.env.NODE_ENV === "production";
197
+ } catch {
198
+ return !1;
199
+ }
200
+ }, _t = async (t, e = ot()) => {
201
+ try {
202
+ const n = Date.now();
203
+ e ? O.info("Generating CSS in production mode! 🔥") : O.info("Generating CSS in development mode! 🚀");
204
+ const a = [], c = [], s = W(t), d = r(s, "index.css");
205
+ (() => {
206
+ K(s) && lt("rm -rf " + s), J(s), J(r(s, "css")), J(r(s, "types"));
207
+ })(), await Ft(t);
208
+ const $ = await G(t);
209
+ async function o(i, S) {
210
+ const D = ["node_modules", "saltygen"], F = pt(i);
211
+ if (F.isDirectory()) {
212
+ const E = ft(i);
213
+ if (D.some((l) => i.includes(l))) return;
214
+ await Promise.all(E.map((l) => o(r(i, l), r(S, l))));
215
+ } else if (F.isFile() && L(i)) {
216
+ const N = await Z(t, i, s), l = [];
217
+ Object.entries(N).forEach(([_, j]) => {
218
+ if (j.isKeyframes && j.css) {
219
+ const q = `a_${j.animationName}.css`, ct = `css/${q}`, it = r(s, ct);
220
+ a.push(q), w(it, j.css);
221
+ return;
222
+ }
223
+ if (!j.generator) return;
224
+ const T = j.generator._withBuildContext({
225
+ name: _,
226
+ config: $,
227
+ prod: e
228
+ });
229
+ c[T.priority] || (c[T.priority] = []), c[T.priority].push(T.cssFileName), l.push(T.cssFileName);
230
+ const rt = `css/${T.cssFileName}`, at = r(s, rt);
231
+ w(at, T.css);
232
+ });
233
+ const p = l.map((_) => `@import url('./${_}');`).join(`
234
+ `), h = B(i, 6), f = H(i), M = z(f.name), v = r(s, `css/f_${M}-${h}.css`);
235
+ w(v, p);
236
+ }
237
+ }
238
+ await o(t, s);
239
+ const g = a.map((i) => `@import url('./css/${i}');`).join(`
240
+ `);
241
+ let b = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
242
+
243
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) => {
244
+ try {
245
+ return V(r(s, "css", i), "utf8").length > 0;
246
+ } catch {
247
+ return !1;
248
+ }
249
+ }).map((i) => `@import url('./css/${i}');`).join(`
250
+ `)}
251
+ ${g}`;
252
+ if ($.importStrategy !== "component") {
253
+ const i = c.reduce((S, D, F) => {
254
+ const E = D.reduce((h, f) => {
255
+ const M = V(r(s, "css", f), "utf8");
256
+ return `${h}
257
+ ${M}`;
258
+ }, ""), N = `l_${F}.css`, l = r(s, "css", N), p = `@layer l${F} { ${E} }`;
259
+ return w(l, p), `${S}
260
+ @import url('./css/${N}');`;
261
+ }, "");
262
+ b += i;
263
+ }
264
+ w(d, b);
265
+ const y = Date.now() - n, k = y < 200 ? "🔥" : y < 500 ? "🚀" : y < 1e3 ? "🎉" : y < 2e3 ? "🚗" : y < 5e3 ? "🤔" : "🥴";
266
+ O.info(`Generated CSS in ${y}ms! ${k}`);
267
+ } catch (n) {
268
+ console.error(n);
269
+ }
270
+ }, Vt = async (t, e) => {
271
+ try {
272
+ const n = [], a = r(t, "./saltygen"), c = r(a, "index.css");
273
+ if (L(e)) {
274
+ const d = await G(t), u = await Z(t, e, a);
275
+ Object.entries(u).forEach(([x, m]) => {
276
+ if (m.isKeyframes && m.css) {
277
+ const i = `css/${`a_${m.animationName}.css`}`, S = r(a, i);
278
+ w(S, m.css);
279
+ return;
280
+ }
281
+ if (!m.generator) return;
282
+ const b = m.generator._withBuildContext({
283
+ name: x,
284
+ config: d
285
+ }), P = `css/${b.cssFileName}`, y = r(a, P);
286
+ n.push(b.cssFileName), w(y, b.css);
287
+ });
288
+ const $ = V(c, "utf8").split(`
289
+ `), o = n.map((x) => `@import url('../saltygen/css/${x}');`), C = [.../* @__PURE__ */ new Set([...$, ...o])].join(`
290
+ `);
291
+ w(c, C);
292
+ }
293
+ } catch (n) {
294
+ console.error(n);
295
+ }
296
+ }, Rt = async (t, e, n = ot()) => {
297
+ try {
298
+ const a = r(t, "./saltygen");
299
+ if (L(e)) {
300
+ const s = V(e, "utf8");
301
+ s.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== s && await ut(e, s);
302
+ const u = await G(t), $ = await Z(t, e, a);
303
+ let o = s;
304
+ if (Object.entries($).forEach(([g, C]) => {
305
+ var h;
306
+ if (C.isKeyframes || !C.generator) return;
307
+ const x = C.generator._withBuildContext({
308
+ name: g,
309
+ config: u,
310
+ prod: n
311
+ }), m = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(s);
312
+ if (!m) return console.error("Could not find the original declaration");
313
+ const b = (h = m.at(1)) == null ? void 0 : h.trim(), P = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
314
+ if (!P) return console.error("Could not find the original declaration");
315
+ const { index: y } = P;
316
+ let k = !1;
317
+ const i = setTimeout(() => k = !0, 5e3);
318
+ let S = 0, D = !1, F = 0;
319
+ for (; !D && !k; ) {
320
+ const f = o[y + S];
321
+ f === "(" && F++, f === ")" && F--, F === 0 && f === ")" && (D = !0), S > o.length && (k = !0), S++;
322
+ }
323
+ if (!k) clearTimeout(i);
324
+ else throw new Error("Failed to find the end of the styled call and timed out");
325
+ const E = y + S, N = o.slice(y, E), l = o, p = ` ${g} = styled(${b}, "${x.classNames}", ${JSON.stringify(x.props)});`;
326
+ o = o.replace(N, p), l === o && console.error("Minimize file failed to change content", { name: g, tagName: b });
327
+ }), u.importStrategy === "component") {
328
+ const g = B(e, 6), C = H(e);
329
+ o = `import '../../saltygen/css/${`f_${z(C.name)}-${g}.css`}';
330
+ ${o}`;
331
+ }
332
+ return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
333
+ }
334
+ } catch (a) {
335
+ console.error("Error in minimizeFile:", a);
336
+ }
337
+ };
338
+ export {
339
+ Mt as a,
340
+ xt as b,
341
+ Ft as c,
342
+ Z as d,
343
+ Vt as e,
344
+ _t as g,
345
+ L as i,
346
+ O as l,
347
+ Rt as m,
348
+ nt as s
349
+ };
@@ -0,0 +1,4 @@
1
+ const t = "/* Empty */";
2
+ export {
3
+ t as default
4
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";const ae=require("esbuild"),le=require("child_process"),R=require("./dash-case-BJEkFEGQ.cjs"),o=require("path"),c=require("fs"),G=require("fs/promises"),v=require("./parse-templates-DD4hQEpv.cjs"),z=require("winston");var H=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 r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const U=de(ae),X=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return c.existsSync(t)?t:X(o.join(e,".."))},pe=async e=>{const t=X(e);return await G.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ue=async e=>{const t=await pe(e);if(t)return t.type};let O;const Y=async e=>{if(O)return O;const t=await ue(e);return t==="module"?O="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:H&&H.tagName.toUpperCase()==="SCRIPT"&&H.src||new URL("index-FtLw6IR2.cjs",document.baseURI).href).endsWith(".cjs"))&&(O="cjs"),O||"esm"},J=z.createLogger({level:"debug",format:z.format.combine(z.format.colorize(),z.format.cli()),transports:[new z.transports.Console({})]}),fe=e=>{J.error(e)};function Q(e){return e?typeof e!="string"?Q(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 ge={"*, *::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"}},L={externalModules:[]},ee=e=>{if(L.externalModules.length>0)return L.externalModules;const t=o.join(e,"salty.config.ts"),r=c.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!r)return[];const a=r[1].split(",").map(n=>n.replace(/['"`]/g,"").trim());return L.externalModules=a,a},q=e=>o.join(e,"./saltygen"),A=["salty","css","styles","styled"],te=(e=[])=>new RegExp(`\\.(${[...A,...e].join("|")})\\.`),I=(e,t=[])=>te(t).test(e),ye=async e=>{const t=q(e),s=o.join(e,"salty.config.ts"),r=o.join(t,"salty.config.js"),a=await Y(e),n=ee(e);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:a,external:n});const f=Date.now(),{config:g}=await import(`${r}?t=${f}`);return g},se=async e=>{const t=await ye(e),s=new Set,r=(d,p=[])=>d?Object.entries(d).flatMap(([S,u])=>{if(!u)return;if(typeof u=="object")return r(u,[...p,S]);const E=Q(S),V=R.dashCase(S),M=[...p,E].join(".");s.add(`"${M}"`);const x=[...p.map(R.dashCase),V].join("-"),{result:N}=v.parseValueTokens(u);return`--${x}: ${N};`}):[],a=d=>d?Object.entries(d).flatMap(([p,S])=>{const u=r(S);return p==="base"?u.join(""):`${p} { ${u.join("")} }`}):[],n=d=>d?Object.entries(d).flatMap(([p,S])=>Object.entries(S).flatMap(([u,E])=>{const V=r(E,[p]),M=`.${p}-${u}, [data-${p}="${u}"]`,x=V.join("");return`${M} { ${x} }`})):[],f=r(t.variables),g=a(t.responsiveVariables),j=n(t.conditionalVariables),i=q(e),y=o.join(i,"css/_variables.css"),F=`:root { ${f.join("")} ${g.join("")} } ${j.join("")}`;c.writeFileSync(y,F);const w=o.join(i,"css/_global.css"),m=v.parseStyles(t.global,"");c.writeFileSync(w,`@layer global { ${m} }`);const b=o.join(i,"css/_reset.css"),h=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:ge,k=v.parseStyles(h,"");c.writeFileSync(b,`@layer reset { ${k} }`);const l=o.join(i,"css/_templates.css"),$=v.parseTemplates(t.templates),D=v.getTemplateTypes(t.templates);c.writeFileSync(l,$);const C=o.join(i,"types/css-tokens.d.ts"),T=`
2
+ // Variable types
3
+ type VariableTokens = ${[...s].join("|")};
4
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
5
+
6
+ // Template types
7
+ type TemplateTokens = {
8
+ ${Object.entries(D).map(([d,p])=>`${d}?: ${p}`).join(`
9
+ `)}
10
+ }
11
+ `;c.writeFileSync(C,T)},Z=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{const r=/^['"`]/.test(s);if(r&&console.log("String tag",s),r)return t;const a=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`),n=a.test(e);if(n||console.log("Not imported",s),!n)return t;const f=a.exec(e);if(f){const g=f.at(1),j=A.some(i=>g==null?void 0:g.includes(i));if(j&&console.log("Salty import for",s,`"${f.at(0)}"`),j)return t}return console.log("Replacing",s),"styled('div',"}),W=async(e,t,s)=>{console.log({sourceFilePath:t});const r=R.toHash(t),a=o.join(s,"./temp");c.existsSync(a)||c.mkdirSync(a);const n=o.parse(t);let f=c.readFileSync(t,"utf8");f=Z(f);const g=o.join(s,"js",r+".js"),j=ee(e),i=await Y(e);await U.build({stdin:{contents:f,sourcefile:n.base,resolveDir:n.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:g,format:i,target:["node20"],keepNames:!0,external:j,packages:"external",plugins:[{name:"test",setup:w=>{w.onLoad({filter:/.*.css.ts/},m=>{console.log("Loading",{sourceFilePath:t,args:m});const b=c.readFileSync(m.path,"utf8");return{contents:Z(b),loader:"ts"}})}}]});const y=Date.now();return await import(`${g}?t=${y}`)},B=async e=>{const t=q(e),s=o.join(t,"salty.config.js"),r=Date.now(),{config:a}=await import(`${s}?t=${r}`);return a},ne=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},me=async(e,t=ne())=>{try{const s=Date.now();t?J.info("Generating CSS in production mode! 🔥"):J.info("Generating CSS in development mode! 🚀");const r=[],a=[],n=q(e),f=o.join(n,"index.css");(()=>{c.existsSync(n)&&le.execSync("rm -rf "+n),c.mkdirSync(n),c.mkdirSync(o.join(n,"css")),c.mkdirSync(o.join(n,"types"))})(),await se(e);const j=await B(e);async function i(l,$){const D=["node_modules","saltygen"],C=c.statSync(l);if(C.isDirectory()){const _=c.readdirSync(l);if(D.some(d=>l.includes(d)))return;await Promise.all(_.map(d=>i(o.join(l,d),o.join($,d))))}else if(C.isFile()&&I(l)){const T=await W(e,l,n),d=[];Object.entries(T).forEach(([M,x])=>{if(x.isKeyframes&&x.css){const K=`a_${x.animationName}.css`,ie=`css/${K}`,ce=o.join(n,ie);r.push(K),c.writeFileSync(ce,x.css);return}if(!x.generator)return;const N=x.generator._withBuildContext({name:M,config:j,prod:t});a[N.priority]||(a[N.priority]=[]),a[N.priority].push(N.cssFileName),d.push(N.cssFileName);const oe=`css/${N.cssFileName}`,re=o.join(n,oe);c.writeFileSync(re,N.css)});const p=d.map(M=>`@import url('./${M}');`).join(`
12
+ `),S=R.toHash(l,6),u=o.parse(l),E=R.dashCase(u.name),V=o.join(n,`css/f_${E}-${S}.css`);c.writeFileSync(V,p)}}await i(e,n);const y=r.map(l=>`@import url('./css/${l}');`).join(`
13
+ `);let b=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
14
+
15
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return c.readFileSync(o.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
16
+ `)}
17
+ ${y}`;if(j.importStrategy!=="component"){const l=a.reduce(($,D,C)=>{const _=D.reduce((S,u)=>{const E=c.readFileSync(o.join(n,"css",u),"utf8");return`${S}
18
+ ${E}`},""),T=`l_${C}.css`,d=o.join(n,"css",T),p=`@layer l${C} { ${_} }`;return c.writeFileSync(d,p),`${$}
19
+ @import url('./css/${T}');`},"");b+=l}c.writeFileSync(f,b);const h=Date.now()-s,k=h<200?"🔥":h<500?"🚀":h<1e3?"🎉":h<2e3?"🚗":h<5e3?"🤔":"🥴";J.info(`Generated CSS in ${h}ms! ${k}`)}catch(s){console.error(s)}},he=async(e,t)=>{try{const s=[],r=o.join(e,"./saltygen"),a=o.join(r,"index.css");if(I(t)){const f=await B(e),g=await W(e,t,r);Object.entries(g).forEach(([w,m])=>{if(m.isKeyframes&&m.css){const l=`css/${`a_${m.animationName}.css`}`,$=o.join(r,l);c.writeFileSync($,m.css);return}if(!m.generator)return;const b=m.generator._withBuildContext({name:w,config:f}),P=`css/${b.cssFileName}`,h=o.join(r,P);s.push(b.cssFileName),c.writeFileSync(h,b.css)});const j=c.readFileSync(a,"utf8").split(`
20
+ `),i=s.map(w=>`@import url('../saltygen/css/${w}');`),F=[...new Set([...j,...i])].join(`
21
+ `);c.writeFileSync(a,F)}}catch(s){console.error(s)}},Se=async(e,t,s=ne())=>{try{const r=o.join(e,"./saltygen");if(I(t)){const n=c.readFileSync(t,"utf8");n.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==n&&await G.writeFile(t,n);const g=await B(e),j=await W(e,t,r);let i=n;if(Object.entries(j).forEach(([y,F])=>{var S;if(F.isKeyframes||!F.generator)return;const w=F.generator._withBuildContext({name:y,config:g,prod:s}),m=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(n);if(!m)return console.error("Could not find the original declaration");const b=(S=m.at(1))==null?void 0:S.trim(),P=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(i);if(!P)return console.error("Could not find the original declaration");const{index:h}=P;let k=!1;const l=setTimeout(()=>k=!0,5e3);let $=0,D=!1,C=0;for(;!D&&!k;){const u=i[h+$];u==="("&&C++,u===")"&&C--,C===0&&u===")"&&(D=!0),$>i.length&&(k=!0),$++}if(!k)clearTimeout(l);else throw new Error("Failed to find the end of the styled call and timed out");const _=h+$,T=i.slice(h,_),d=i,p=` ${y} = styled(${b}, "${w.classNames}", ${JSON.stringify(w.props)});`;i=i.replace(T,p),d===i&&console.error("Minimize file failed to change content",{name:y,tagName:b})}),g.importStrategy==="component"){const y=R.toHash(t,6),F=o.parse(t);i=`import '../../saltygen/css/${`f_${R.dashCase(F.name)}-${y}.css`}';
22
+ ${i}`}return i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(r){console.error("Error in minimizeFile:",r)}};exports.compileSaltyFile=W;exports.generateConfigStyles=se;exports.generateCss=me;exports.generateFile=he;exports.isSaltyFile=I;exports.logError=fe;exports.logger=J;exports.minimizeFile=Se;exports.saltyFileExtensions=A;exports.saltyFileRegExp=te;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.14",
3
+ "version": "0.0.1-alpha.141",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -10,7 +10,12 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "homepage": "https://github.com/margarita-form/salty-css",
13
+ "description": "Core library for Salty CSS. Will be used by other Salty CSS libraries and plugins.",
14
+ "homepage": "https://salty-css.dev/",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/margarita-form/salty-css.git"
18
+ },
14
19
  "bugs": {
15
20
  "url": "https://github.com/margarita-form/salty-css/issues"
16
21
  },
@@ -23,11 +28,18 @@
23
28
  "name": "core"
24
29
  },
25
30
  "peerDependencies": {
31
+ "commander": ">=12.x",
32
+ "ejs": ">=3.x",
26
33
  "esbuild": ">=0.21.x",
34
+ "ora": ">=8.x",
27
35
  "react": ">=18.x || >=19.x",
28
36
  "winston": ">=3.x"
29
37
  },
30
38
  "exports": {
39
+ "./bin/main": {
40
+ "import": "./bin/main.js",
41
+ "require": "./bin/main.cjs"
42
+ },
31
43
  "./compiler": {
32
44
  "import": "./compiler/index.js",
33
45
  "require": "./compiler/index.cjs"
@@ -52,5 +64,11 @@
52
64
  "import": "./util/index.js",
53
65
  "require": "./util/index.cjs"
54
66
  }
67
+ },
68
+ "bin": {
69
+ "salty": "./bin/index.js",
70
+ "salty-css": "./bin/index.js",
71
+ "salty-css-cjs": "./bin/index.cjs",
72
+ "@salty-css/core": "./bin/index.js"
55
73
  }
56
74
  }
@@ -0,0 +1,97 @@
1
+ import { d as l } from "./dash-case-DBThphLm.js";
2
+ const W = (t, s) => {
3
+ if (typeof t != "string") return { result: t };
4
+ if (!s) return { result: t };
5
+ const r = [];
6
+ return Object.values(s).forEach((n) => {
7
+ const { pattern: o, transform: p } = n;
8
+ t = t.replace(o, (i) => {
9
+ const { value: d, css: e } = p(i);
10
+ return e && r.push(e), d;
11
+ });
12
+ }), { result: t, additionalCss: r };
13
+ }, N = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${l(n[1].replaceAll(".", "-"))})`) } : { result: t }, a = (t, s, r) => {
14
+ if (!t) return "";
15
+ const n = [], o = Object.entries(t).reduce((i, [d, e]) => {
16
+ const c = d.trim();
17
+ if (typeof e == "function" && (e = e()), typeof e == "object") {
18
+ if (!e) return i;
19
+ if (c === "variants")
20
+ return Object.entries(e).forEach(([f, u]) => {
21
+ u && Object.entries(u).forEach(([y, j]) => {
22
+ if (!j) return;
23
+ const b = `${s}.${f}-${y}`, m = a(j, b, r);
24
+ n.push(m);
25
+ });
26
+ }), i;
27
+ if (c === "defaultVariants")
28
+ return i;
29
+ if (c === "compoundVariants")
30
+ return e.forEach((f) => {
31
+ const { css: u, ...y } = f, j = Object.entries(y).reduce((m, [k, w]) => `${m}.${k}-${w}`, s), b = a(u, j, r);
32
+ n.push(b);
33
+ }), i;
34
+ if (c.startsWith("@")) {
35
+ const f = a(e, s, r), u = `${c} {
36
+ ${f.replace(`
37
+ `, `
38
+ `)}
39
+ }`;
40
+ return n.push(u), i;
41
+ }
42
+ const $ = d.includes("&") ? c.replace("&", s) : c.startsWith(":") ? `${s}${c}` : `${s} ${c}`, h = a(e, $, r);
43
+ return n.push(h), i;
44
+ }
45
+ if (r != null && r.templates && r.templates[c]) {
46
+ const h = e.split(".").reduce((f, u) => f[u], r.templates[c]);
47
+ if (h) {
48
+ const f = a(h, "");
49
+ return `${i}${f}`;
50
+ }
51
+ return console.warn(`Template "${c}" with path of "${e}" was not found in config!`), i;
52
+ }
53
+ const S = c.startsWith("-") ? c : l(c), O = ($, h = ";") => i = `${i}${$}${h}`, T = ($) => O(`${S}:${$}`);
54
+ if (typeof e == "number") return T(e);
55
+ if (typeof e != "string")
56
+ if ("toString" in e) e = e.toString();
57
+ else return i;
58
+ const { modifiers: V } = r || {}, g = function* () {
59
+ yield N(e), yield W(e, V);
60
+ }();
61
+ for (const { result: $, additionalCss: h = [] } of g)
62
+ e = $, h.forEach((f) => {
63
+ const u = a(f, "");
64
+ O(u, "");
65
+ });
66
+ return T(e);
67
+ }, "");
68
+ return o ? s ? [`${s} { ${o} }`, ...n].join(`
69
+ `) : o : n.join(`
70
+ `);
71
+ }, P = (t, s = []) => {
72
+ if (!t) return "";
73
+ const r = [], n = {};
74
+ if (Object.entries(t).forEach(([o, p]) => {
75
+ if (typeof p == "object") {
76
+ if (!p) return;
77
+ const i = o.trim(), d = P(p, [...s, i]);
78
+ r.push(d);
79
+ } else
80
+ n[o] = p;
81
+ }), Object.keys(n).length) {
82
+ const o = s.map(l).join("-"), p = a(n, `.${o}`);
83
+ r.push(p);
84
+ }
85
+ return r.join(`
86
+ `);
87
+ }, x = (t) => Object.keys(t), A = (t) => Object.entries(t).reduce((s, [r, n]) => (typeof n == "object" && (s[r] = E(n).map((o) => `"${o}"`).join(" | ")), s), {}), E = (t, s = "", r = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
88
+ const p = s ? `${s}.${n}` : n;
89
+ return typeof o == "object" ? E(o, p, r) : r.add(s);
90
+ }), [...r]) : [];
91
+ export {
92
+ P as a,
93
+ A as b,
94
+ N as c,
95
+ x as g,
96
+ a as p
97
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";const b=require("./dash-case-BJEkFEGQ.cjs"),K=(t,s)=>{if(typeof t!="string")return{result:t};if(!s)return{result:t};const e=[];return Object.values(s).forEach(n=>{const{pattern:o,transform:p}=n;t=t.replace(o,i=>{const{value:d,css:r}=p(i);return r&&e.push(r),d})}),{result:t,additionalCss:e}},S=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${b.dashCase(n[1].replaceAll(".","-"))})`)}:{result:t},h=(t,s,e)=>{if(!t)return"";const n=[],o=Object.entries(t).reduce((i,[d,r])=>{const c=d.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return i;if(c==="variants")return Object.entries(r).forEach(([f,u])=>{u&&Object.entries(u).forEach(([l,y])=>{if(!y)return;const j=`${s}.${f}-${l}`,m=h(y,j,e);n.push(m)})}),i;if(c==="defaultVariants")return i;if(c==="compoundVariants")return r.forEach(f=>{const{css:u,...l}=f,y=Object.entries(l).reduce((m,[W,q])=>`${m}.${W}-${q}`,s),j=h(u,y,e);n.push(j)}),i;if(c.startsWith("@")){const f=h(r,s,e),u=`${c} {
2
+ ${f.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return n.push(u),i}const a=d.includes("&")?c.replace("&",s):c.startsWith(":")?`${s}${c}`:`${s} ${c}`,$=h(r,a,e);return n.push($),i}if(e!=null&&e.templates&&e.templates[c]){const $=r.split(".").reduce((f,u)=>f[u],e.templates[c]);if($){const f=h($,"");return`${i}${f}`}return console.warn(`Template "${c}" with path of "${r}" was not found in config!`),i}const g=c.startsWith("-")?c:b.dashCase(c),T=(a,$=";")=>i=`${i}${a}${$}`,O=a=>T(`${g}:${a}`);if(typeof r=="number")return O(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return i;const{modifiers:k}=e||{},w=function*(){yield S(r),yield K(r,k)}();for(const{result:a,additionalCss:$=[]}of w)r=a,$.forEach(f=>{const u=h(f,"");T(u,"")});return O(r)},"");return o?s?[`${s} { ${o} }`,...n].join(`
6
+ `):o:n.join(`
7
+ `)},E=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([o,p])=>{if(typeof p=="object"){if(!p)return;const i=o.trim(),d=E(p,[...s,i]);e.push(d)}else n[o]=p}),Object.keys(n).length){const o=s.map(b.dashCase).join("-"),p=h(n,`.${o}`);e.push(p)}return e.join(`
8
+ `)},N=t=>Object.keys(t),P=t=>Object.entries(t).reduce((s,[e,n])=>(typeof n=="object"&&(s[e]=V(n).map(o=>`"${o}"`).join(" | ")),s),{}),V=(t,s="",e=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const p=s?`${s}.${n}`:n;return typeof o=="object"?V(o,p,e):e.add(s)}),[...e]):[];exports.getTemplateKeys=N;exports.getTemplateTypes=P;exports.parseStyles=h;exports.parseTemplates=E;exports.parseValueTokens=S;
@@ -0,0 +1,6 @@
1
+ function p(e) {
2
+ return e ? typeof e != "string" ? p(String(e)) : e.replace(/\s/g, "-").replace(/[-_]([a-z0-9])/g, (a) => a[1].toUpperCase()).replace(/^[a-z]/, (a) => a.toUpperCase()) : "";
3
+ }
4
+ export {
5
+ p
6
+ };
@@ -0,0 +1 @@
1
+ "use strict";function r(e){return e?typeof e!="string"?r(String(e)):e.replace(/\s/g,"-").replace(/[-_]([a-z0-9])/g,a=>a[1].toUpperCase()).replace(/^[a-z]/,a=>a.toUpperCase()):""}exports.pascalCase=r;
@@ -0,0 +1,11 @@
1
+ const e = `import { styled } from "@salty-css/react/styled";
2
+
3
+ export const <%- name %> = styled('<%- tag %>', {
4
+ <% if(className) { %>className: '<%- className %>',<% } %>
5
+ base: {
6
+ // Add your styles here
7
+ }
8
+ })`;
9
+ export {
10
+ e as default
11
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { styled } from "@salty-css/react/styled";
2
+
3
+ export const <%- name %> = styled('<%- tag %>', {
4
+ <% if(className) { %>className: '<%- className %>',<% } %>
5
+ base: {
6
+ // Add your styles here
7
+ }
8
+ })`;exports.default=e;
@@ -0,0 +1,18 @@
1
+ const n = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
2
+
3
+ interface <%- componentName %>Props {
4
+ text?: string;
5
+ }
6
+
7
+ export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName %>Props) => {
8
+ return (
9
+ <<%- styledComponentName %>>
10
+ {text}
11
+ </<%- styledComponentName %>>
12
+ );
13
+ };
14
+
15
+ export default <%- componentName %>;`;
16
+ export {
17
+ n as default
18
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { <%- styledComponentName %> } from "./<%- fileName %>.css";
2
+
3
+ interface <%- componentName %>Props {
4
+ text?: string;
5
+ }
6
+
7
+ export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName %>Props) => {
8
+ return (
9
+ <<%- styledComponentName %>>
10
+ {text}
11
+ </<%- styledComponentName %>>
12
+ );
13
+ };
14
+
15
+ export default <%- componentName %>;`;exports.default=e;
@@ -0,0 +1,10 @@
1
+ const n = `import { defineConfig } from '@salty-css/core/config';
2
+
3
+ export const config = defineConfig({
4
+ // Add your custom config here
5
+ externalModules: ['react', 'react-dom']
6
+ });
7
+ `;
8
+ export {
9
+ n as default
10
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { defineConfig } from '@salty-css/core/config';
2
+
3
+ export const config = defineConfig({
4
+ // Add your custom config here
5
+ externalModules: ['react', 'react-dom']
6
+ });
7
+ `;exports.default=e;
@@ -0,0 +1,2 @@
1
+ import { GlobalStyles } from '../config/config-types';
2
+ export declare const saltyReset: GlobalStyles;