@salty-css/core 0.0.1-alpha.12 → 0.0.1-alpha.121

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 (48) hide show
  1. package/.saltyrc.schema.json +40 -0
  2. package/README.md +102 -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 -180
  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 +37 -18
  21. package/generator/parse-templates.d.ts +2 -0
  22. package/generator/style-generator.d.ts +14 -4
  23. package/index-84Wroia-.cjs +1 -0
  24. package/index-BDkjvMN9.js +302 -0
  25. package/index-D_732b92.js +4 -0
  26. package/index-RidXn8lG.cjs +21 -0
  27. package/package.json +20 -2
  28. package/parse-templates-BuKrl3n7.js +100 -0
  29. package/parse-templates-DIOn-gO_.cjs +8 -0
  30. package/pascal-case-BQpR5PdN.js +6 -0
  31. package/pascal-case-iWoaJWwT.cjs +1 -0
  32. package/react-styled-file-CGVf5n1B.js +11 -0
  33. package/react-styled-file-Dkubsz-U.cjs +8 -0
  34. package/react-vanilla-file-CCXbsjIb.js +18 -0
  35. package/react-vanilla-file-CG_WJLam.cjs +15 -0
  36. package/salty.config-BhBY_oOk.js +10 -0
  37. package/salty.config-Dk6ZcCxI.cjs +7 -0
  38. package/templates/salty-reset.d.ts +2 -0
  39. package/types/index.d.ts +48 -21
  40. package/util/camel-case.d.ts +1 -0
  41. package/util/dot-case.d.ts +1 -0
  42. package/util/index.cjs +1 -1
  43. package/util/index.d.ts +2 -0
  44. package/util/index.js +7 -15
  45. package/util/module-type.d.ts +1 -0
  46. package/util/pascal-case.d.ts +1 -0
  47. package/parse-templates-BOSK0Tb6.js +0 -90
  48. package/parse-templates-BY1Xai-_.cjs +0 -8
@@ -0,0 +1,302 @@
1
+ import * as U from "esbuild";
2
+ import { execSync as nt } from "child_process";
3
+ import { t as H, d as O } from "./dash-case-DBThphLm.js";
4
+ import { join as o, parse as I } from "path";
5
+ import { existsSync as Z, writeFileSync as S, mkdirSync as J, readFileSync as V, statSync as ot, readdirSync as rt } from "fs";
6
+ import { readFile as at, writeFile as ct } from "fs/promises";
7
+ import { p as q, a as it, b as lt, c as pt } from "./parse-templates-BuKrl3n7.js";
8
+ import { createLogger as ft, format as W, transports as ut } from "winston";
9
+ const X = (t) => {
10
+ if (!t || t === "/") throw new Error("Could not find package.json file");
11
+ const e = o(t, "package.json");
12
+ return Z(e) ? e : X(o(t, ".."));
13
+ }, dt = async (t) => {
14
+ const e = X(t);
15
+ return await at(e, "utf-8").then(JSON.parse).catch(() => {
16
+ });
17
+ }, gt = async (t) => {
18
+ const e = await dt(t);
19
+ if (e)
20
+ return e.type;
21
+ };
22
+ let N;
23
+ const Y = async (t) => {
24
+ if (N) return N;
25
+ const e = await gt(t);
26
+ return e === "module" ? N = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (N = "cjs"), N || "esm";
27
+ }, B = ft({
28
+ level: "debug",
29
+ format: W.combine(W.colorize(), W.cli()),
30
+ transports: [new ut.Console({})]
31
+ }), Tt = (t) => {
32
+ B.error(t);
33
+ };
34
+ function Q(t) {
35
+ return t ? typeof t != "string" ? Q(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, a) => (a > 0 ? "." : "") + e.toLowerCase()) : "";
36
+ }
37
+ const mt = {
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 button line height */
69
+ button: {
70
+ lineHeight: "1em"
71
+ },
72
+ /** Improve form elements */
73
+ "input, optgroup, select, textarea": {
74
+ fontFamily: "inherit",
75
+ fontSize: "100%",
76
+ lineHeight: "1.15em"
77
+ }
78
+ }, A = {
79
+ externalModules: []
80
+ }, tt = (t) => {
81
+ if (A.externalModules.length > 0) return A.externalModules;
82
+ const e = o(t, "salty.config.ts"), s = V(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
83
+ if (!s) return [];
84
+ const r = s[1].split(",").map((l) => l.replace(/['"`]/g, "").trim());
85
+ return A.externalModules = r, r;
86
+ }, z = (t) => o(t, "./saltygen"), yt = ["salty", "css", "styles", "styled"], ht = (t = []) => new RegExp(`\\.(${[...yt, ...t].join("|")})\\.`), K = (t, e = []) => ht(e).test(t), bt = async (t) => {
87
+ const e = z(t), a = o(t, "salty.config.ts"), s = o(e, "salty.config.js"), r = await Y(t), l = tt(t);
88
+ await U.build({
89
+ entryPoints: [a],
90
+ minify: !0,
91
+ treeShaking: !0,
92
+ bundle: !0,
93
+ outfile: s,
94
+ format: r,
95
+ external: l
96
+ });
97
+ const y = Date.now(), { config: u } = await import(`${s}?t=${y}`);
98
+ return u;
99
+ }, $t = async (t) => {
100
+ const e = await bt(t), a = /* @__PURE__ */ new Set(), s = (d, p = []) => d ? Object.entries(d).flatMap(([g, i]) => {
101
+ if (!i) return;
102
+ if (typeof i == "object") return s(i, [...p, g]);
103
+ const $ = Q(g), v = O(g), E = [...p, $].join(".");
104
+ a.add(`"${E}"`);
105
+ const D = [...p.map(O), v].join("-"), { result: R } = pt(i);
106
+ return `--${D}: ${R};`;
107
+ }) : [], r = (d) => d ? Object.entries(d).flatMap(([p, g]) => {
108
+ const i = s(g);
109
+ return p === "base" ? i.join("") : `${p} { ${i.join("")} }`;
110
+ }) : [], l = (d) => d ? Object.entries(d).flatMap(([p, g]) => Object.entries(g).flatMap(([i, $]) => {
111
+ const v = s($, [p]), E = `.${p}-${i}, [data-${p}="${i}"]`, D = v.join("");
112
+ return `${E} { ${D} }`;
113
+ })) : [], y = s(e.variables), u = r(e.responsiveVariables), w = l(e.conditionalVariables), n = z(t), f = o(n, "css/_variables.css"), h = `:root { ${y.join("")} ${u.join("")} } ${w.join("")}`;
114
+ S(f, h);
115
+ const F = o(n, "css/_global.css"), b = q(e.global, "");
116
+ S(F, `@layer global { ${b} }`);
117
+ const c = o(n, "css/_reset.css"), j = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : mt, C = q(j, "");
118
+ S(c, `@layer reset { ${C} }`);
119
+ const P = o(n, "css/_templates.css"), k = it(e.templates), m = lt(e.templates);
120
+ S(P, k);
121
+ const T = o(n, "types/css-tokens.d.ts"), M = `
122
+ // Variable types
123
+ type VariableTokens = ${[...a].join("|")};
124
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
125
+
126
+ // Template types
127
+ type TemplateTokens = {
128
+ ${Object.entries(m).map(([d, p]) => `${d}?: ${p}`).join(`
129
+ `)}
130
+ }
131
+ `;
132
+ S(T, M);
133
+ }, G = async (t, e, a) => {
134
+ const s = H(e), r = o(a, "./temp");
135
+ Z(r) || J(r);
136
+ const l = I(e);
137
+ let y = V(e, "utf8");
138
+ y = y.replace(/styled\([^"'`{,]+,/g, "styled('div',");
139
+ const u = o(a, "js", s + ".js"), w = tt(t), n = await Y(t);
140
+ await U.build({
141
+ stdin: {
142
+ contents: y,
143
+ sourcefile: l.base,
144
+ resolveDir: l.dir,
145
+ loader: "tsx"
146
+ },
147
+ minify: !1,
148
+ treeShaking: !0,
149
+ bundle: !0,
150
+ outfile: u,
151
+ format: n,
152
+ target: ["node20"],
153
+ keepNames: !0,
154
+ external: w,
155
+ packages: "external"
156
+ });
157
+ const f = Date.now();
158
+ return await import(`${u}?t=${f}`);
159
+ }, L = async (t) => {
160
+ const e = z(t), a = o(e, "salty.config.js"), { config: s } = await import(a);
161
+ return s;
162
+ }, et = () => {
163
+ try {
164
+ return process.env.NODE_ENV === "production";
165
+ } catch {
166
+ return !1;
167
+ }
168
+ }, Pt = async (t, e = et()) => {
169
+ try {
170
+ e ? B.info("Generating CSS in production mode! 🔥") : B.info("Generating CSS in development mode! 🚀");
171
+ const a = [], s = [], r = z(t), l = o(r, "index.css");
172
+ (() => {
173
+ Z(r) && nt("rm -rf " + r), J(r), J(o(r, "css")), J(o(r, "types"));
174
+ })(), await $t(t);
175
+ const u = await L(t);
176
+ async function w(c, x) {
177
+ const j = ["node_modules", "saltygen"], C = ot(c);
178
+ if (C.isDirectory()) {
179
+ const P = rt(c);
180
+ if (j.some((m) => c.includes(m))) return;
181
+ await Promise.all(P.map((m) => w(o(c, m), o(x, m))));
182
+ } else if (C.isFile() && K(c)) {
183
+ const k = await G(t, c, r), m = [];
184
+ Object.entries(k).forEach(([g, i]) => {
185
+ if (i.isKeyframes && i.css) {
186
+ const D = `a_${i.animationName}.css`, R = `css/${D}`, st = o(r, R);
187
+ a.push(D), S(st, i.css);
188
+ return;
189
+ }
190
+ if (!i.generator) return;
191
+ const $ = i.generator._withBuildContext({
192
+ name: g,
193
+ config: u,
194
+ prod: e
195
+ });
196
+ s[$.priority] || (s[$.priority] = []), s[$.priority].push($.cssFileName), m.push($.cssFileName);
197
+ const v = `css/${$.cssFileName}`, E = o(r, v);
198
+ S(E, $.css);
199
+ });
200
+ const T = m.map((g) => `@import url('./${g}');`).join(`
201
+ `), _ = H(c, 6), M = I(c), d = O(M.name), p = o(r, `css/f_${d}-${_}.css`);
202
+ S(p, T);
203
+ }
204
+ }
205
+ await w(t, r);
206
+ const n = a.map((c) => `@import url('./css/${c}');`).join(`
207
+ `);
208
+ let b = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
209
+
210
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
211
+ try {
212
+ return V(o(r, "css", c), "utf8").length > 0;
213
+ } catch {
214
+ return !1;
215
+ }
216
+ }).map((c) => `@import url('./css/${c}');`).join(`
217
+ `)}
218
+ ${n}`;
219
+ if (u.importStrategy !== "component") {
220
+ const c = s.flat().map((x) => `@import url('./css/${x}');`).join(`
221
+ `);
222
+ b += c;
223
+ }
224
+ S(l, b);
225
+ } catch (a) {
226
+ console.error(a);
227
+ }
228
+ }, Dt = async (t, e) => {
229
+ try {
230
+ const a = [], s = o(t, "./saltygen"), r = o(s, "index.css");
231
+ if (K(e)) {
232
+ const y = await L(t), u = await G(t, e, s);
233
+ Object.entries(u).forEach(([F, b]) => {
234
+ if (!b.generator) return;
235
+ const c = b.generator._withBuildContext({
236
+ name: F,
237
+ config: y
238
+ }), x = `css/${c.cssFileName}`, j = o(s, x);
239
+ a.push(c.cssFileName), S(j, c.css);
240
+ });
241
+ const w = V(r, "utf8").split(`
242
+ `), n = a.map((F) => `@import url('../saltygen/css/${F}');`), h = [.../* @__PURE__ */ new Set([...w, ...n])].join(`
243
+ `);
244
+ S(r, h);
245
+ }
246
+ } catch (a) {
247
+ console.error(a);
248
+ }
249
+ }, Nt = async (t, e, a = et()) => {
250
+ try {
251
+ const s = o(t, "./saltygen");
252
+ if (K(e)) {
253
+ const l = V(e, "utf8");
254
+ l.replace(/^(?!export\s)const\s.*/gm, (f) => `export ${f}`) !== l && await ct(e, l);
255
+ const u = await L(t), w = await G(t, e, s);
256
+ let n = l;
257
+ if (Object.entries(w).forEach(([f, h]) => {
258
+ var g;
259
+ if (h.isKeyframes || !h.generator) return;
260
+ const F = h.generator._withBuildContext({
261
+ name: f,
262
+ config: u,
263
+ prod: a
264
+ }), b = new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(l);
265
+ if (!b) return console.error("Could not find the original declaration");
266
+ const c = (g = b.at(1)) == null ? void 0 : g.trim(), x = new RegExp(`\\s${f}[=\\s]+styled\\(`, "g").exec(n);
267
+ if (!x) return console.error("Could not find the original declaration");
268
+ const { index: j } = x;
269
+ let C = !1;
270
+ const P = setTimeout(() => C = !0, 5e3);
271
+ let k = 0, m = !1, T = 0;
272
+ for (; !m && !C; ) {
273
+ const i = n[j + k];
274
+ i === "(" && T++, i === ")" && T--, T === 0 && i === ")" && (m = !0), k > n.length && (C = !0), k++;
275
+ }
276
+ if (!C) clearTimeout(P);
277
+ else throw new Error("Failed to find the end of the styled call and timed out");
278
+ const _ = j + k, M = n.slice(j, _), d = n, p = ` ${f} = styled(${c}, "${F.classNames}", ${JSON.stringify(F.props)});`;
279
+ n = n.replace(M, p), d === n && console.error("Minimize file failed to change content", { name: f, tagName: c });
280
+ }), u.importStrategy === "component") {
281
+ const f = H(e, 6), h = I(e);
282
+ n = `import '../../saltygen/css/${`f_${O(h.name)}-${f}.css`}';
283
+ ${n}`;
284
+ }
285
+ return n = n.replace("{ styled }", "{ styledClient as styled }"), n = n.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), n;
286
+ }
287
+ } catch (s) {
288
+ console.error("Error in minimizeFile:", s);
289
+ }
290
+ };
291
+ export {
292
+ Tt as a,
293
+ ht as b,
294
+ $t as c,
295
+ G as d,
296
+ Dt as e,
297
+ Pt as g,
298
+ K as i,
299
+ B as l,
300
+ Nt as m,
301
+ yt as s
302
+ };
@@ -0,0 +1,4 @@
1
+ const t = "/* Empty */";
2
+ export {
3
+ t as default
4
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";const ne=require("esbuild"),oe=require("child_process"),P=require("./dash-case-BJEkFEGQ.cjs"),o=require("path"),c=require("fs"),Z=require("fs/promises"),O=require("./parse-templates-DIOn-gO_.cjs"),V=require("winston");var I=typeof document<"u"?document.currentScript:null;function re(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 K=re(ne),L=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:L(o.join(e,".."))},ie=async e=>{const t=L(e);return await Z.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ae=async e=>{const t=await ie(e);if(t)return t.type};let N;const U=async e=>{if(N)return N;const t=await ae(e);return t==="module"?N="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-RidXn8lG.cjs",document.baseURI).href).endsWith(".cjs"))&&(N="cjs"),N||"esm"},z=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]}),ce=e=>{z.error(e)};function G(e){return e?typeof e!="string"?G(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 le={"*, *::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"},button:{lineHeight:"1em"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},A={externalModules:[]},X=e=>{if(A.externalModules.length>0)return A.externalModules;const t=o.join(e,"salty.config.ts"),n=c.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const i=n[1].split(",").map(p=>p.replace(/['"`]/g,"").trim());return A.externalModules=i,i},J=e=>o.join(e,"./saltygen"),Y=["salty","css","styles","styled"],Q=(e=[])=>new RegExp(`\\.(${[...Y,...e].join("|")})\\.`),q=(e,t=[])=>Q(t).test(e),pe=async e=>{const t=J(e),s=o.join(e,"salty.config.ts"),n=o.join(t,"salty.config.js"),i=await U(e),p=X(e);await K.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:i,external:p});const h=Date.now(),{config:f}=await import(`${n}?t=${h}`);return f},ee=async e=>{const t=await pe(e),s=new Set,n=(g,u=[])=>g?Object.entries(g).flatMap(([y,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...u,y]);const j=G(y),E=P.dashCase(y),M=[...u,j].join(".");s.add(`"${M}"`);const _=[...u.map(P.dashCase),E].join("-"),{result:H}=O.parseValueTokens(l);return`--${_}: ${H};`}):[],i=g=>g?Object.entries(g).flatMap(([u,y])=>{const l=n(y);return u==="base"?l.join(""):`${u} { ${l.join("")} }`}):[],p=g=>g?Object.entries(g).flatMap(([u,y])=>Object.entries(y).flatMap(([l,j])=>{const E=n(j,[u]),M=`.${u}-${l}, [data-${u}="${l}"]`,_=E.join("");return`${M} { ${_} }`})):[],h=n(t.variables),f=i(t.responsiveVariables),F=p(t.conditionalVariables),r=J(e),d=o.join(r,"css/_variables.css"),S=`:root { ${h.join("")} ${f.join("")} } ${F.join("")}`;c.writeFileSync(d,S);const w=o.join(r,"css/_global.css"),b=O.parseStyles(t.global,"");c.writeFileSync(w,`@layer global { ${b} }`);const a=o.join(r,"css/_reset.css"),x=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:le,C=O.parseStyles(x,"");c.writeFileSync(a,`@layer reset { ${C} }`);const D=o.join(r,"css/_templates.css"),k=O.parseTemplates(t.templates),m=O.getTemplateTypes(t.templates);c.writeFileSync(D,k);const T=o.join(r,"types/css-tokens.d.ts"),v=`
2
+ // Variable types
3
+ type VariableTokens = ${[...s].join("|")};
4
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
5
+
6
+ // Template types
7
+ type TemplateTokens = {
8
+ ${Object.entries(m).map(([g,u])=>`${g}?: ${u}`).join(`
9
+ `)}
10
+ }
11
+ `;c.writeFileSync(T,v)},W=async(e,t,s)=>{const n=P.toHash(t),i=o.join(s,"./temp");c.existsSync(i)||c.mkdirSync(i);const p=o.parse(t);let h=c.readFileSync(t,"utf8");h=h.replace(/styled\([^"'`{,]+,/g,"styled('div',");const f=o.join(s,"js",n+".js"),F=X(e),r=await U(e);await K.build({stdin:{contents:h,sourcefile:p.base,resolveDir:p.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:f,format:r,target:["node20"],keepNames:!0,external:F,packages:"external"});const d=Date.now();return await import(`${f}?t=${d}`)},B=async e=>{const t=J(e),s=o.join(t,"salty.config.js"),{config:n}=await import(s);return n},te=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ue=async(e,t=te())=>{try{t?z.info("Generating CSS in production mode! 🔥"):z.info("Generating CSS in development mode! 🚀");const s=[],n=[],i=J(e),p=o.join(i,"index.css");(()=>{c.existsSync(i)&&oe.execSync("rm -rf "+i),c.mkdirSync(i),c.mkdirSync(o.join(i,"css")),c.mkdirSync(o.join(i,"types"))})(),await ee(e);const f=await B(e);async function F(a,$){const x=["node_modules","saltygen"],C=c.statSync(a);if(C.isDirectory()){const D=c.readdirSync(a);if(x.some(m=>a.includes(m)))return;await Promise.all(D.map(m=>F(o.join(a,m),o.join($,m))))}else if(C.isFile()&&q(a)){const k=await W(e,a,i),m=[];Object.entries(k).forEach(([y,l])=>{if(l.isKeyframes&&l.css){const _=`a_${l.animationName}.css`,H=`css/${_}`,se=o.join(i,H);s.push(_),c.writeFileSync(se,l.css);return}if(!l.generator)return;const j=l.generator._withBuildContext({name:y,config:f,prod:t});n[j.priority]||(n[j.priority]=[]),n[j.priority].push(j.cssFileName),m.push(j.cssFileName);const E=`css/${j.cssFileName}`,M=o.join(i,E);c.writeFileSync(M,j.css)});const T=m.map(y=>`@import url('./${y}');`).join(`
12
+ `),R=P.toHash(a,6),v=o.parse(a),g=P.dashCase(v.name),u=o.join(i,`css/f_${g}-${R}.css`);c.writeFileSync(u,T)}}await F(e,i);const r=s.map(a=>`@import url('./css/${a}');`).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(a=>{try{return c.readFileSync(o.join(i,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
16
+ `)}
17
+ ${r}`;if(f.importStrategy!=="component"){const a=n.flat().map($=>`@import url('./css/${$}');`).join(`
18
+ `);b+=a}c.writeFileSync(p,b)}catch(s){console.error(s)}},de=async(e,t)=>{try{const s=[],n=o.join(e,"./saltygen"),i=o.join(n,"index.css");if(q(t)){const h=await B(e),f=await W(e,t,n);Object.entries(f).forEach(([w,b])=>{if(!b.generator)return;const a=b.generator._withBuildContext({name:w,config:h}),$=`css/${a.cssFileName}`,x=o.join(n,$);s.push(a.cssFileName),c.writeFileSync(x,a.css)});const F=c.readFileSync(i,"utf8").split(`
19
+ `),r=s.map(w=>`@import url('../saltygen/css/${w}');`),S=[...new Set([...F,...r])].join(`
20
+ `);c.writeFileSync(i,S)}}catch(s){console.error(s)}},fe=async(e,t,s=te())=>{try{const n=o.join(e,"./saltygen");if(q(t)){const p=c.readFileSync(t,"utf8");p.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==p&&await Z.writeFile(t,p);const f=await B(e),F=await W(e,t,n);let r=p;if(Object.entries(F).forEach(([d,S])=>{var y;if(S.isKeyframes||!S.generator)return;const w=S.generator._withBuildContext({name:d,config:f,prod:s}),b=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(p);if(!b)return console.error("Could not find the original declaration");const a=(y=b.at(1))==null?void 0:y.trim(),$=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(r);if(!$)return console.error("Could not find the original declaration");const{index:x}=$;let C=!1;const D=setTimeout(()=>C=!0,5e3);let k=0,m=!1,T=0;for(;!m&&!C;){const l=r[x+k];l==="("&&T++,l===")"&&T--,T===0&&l===")"&&(m=!0),k>r.length&&(C=!0),k++}if(!C)clearTimeout(D);else throw new Error("Failed to find the end of the styled call and timed out");const R=x+k,v=r.slice(x,R),g=r,u=` ${d} = styled(${a}, "${w.classNames}", ${JSON.stringify(w.props)});`;r=r.replace(v,u),g===r&&console.error("Minimize file failed to change content",{name:d,tagName:a})}),f.importStrategy==="component"){const d=P.toHash(t,6),S=o.parse(t);r=`import '../../saltygen/css/${`f_${P.dashCase(S.name)}-${d}.css`}';
21
+ ${r}`}return r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=W;exports.generateConfigStyles=ee;exports.generateCss=ue;exports.generateFile=de;exports.isSaltyFile=q;exports.logError=ce;exports.logger=z;exports.minimizeFile=fe;exports.saltyFileExtensions=Y;exports.saltyFileRegExp=Q;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.12",
3
+ "version": "0.0.1-alpha.121",
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,100 @@
1
+ import { d as O } from "./dash-case-DBThphLm.js";
2
+ const N = (t, e) => {
3
+ if (typeof t != "string") return { result: t };
4
+ if (!e) return { result: t };
5
+ const s = [];
6
+ return Object.values(e).forEach((n) => {
7
+ const { pattern: o, transform: i } = n;
8
+ t = t.replace(o, (d) => {
9
+ const { value: c, css: j } = i(d);
10
+ return j && s.push(j), c;
11
+ });
12
+ }), { result: t, additionalCss: s };
13
+ }, P = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, a = (t, e, s, n) => {
14
+ if (!t) return "";
15
+ const o = [], i = Object.entries(t).reduce((c, [j, r]) => {
16
+ const f = j.trim();
17
+ if (typeof r == "function" && (r = r()), typeof r == "object") {
18
+ if (!r) return c;
19
+ if (f === "variants")
20
+ return Object.entries(r).forEach(([p, u]) => {
21
+ u && Object.entries(u).forEach(([m, b]) => {
22
+ if (!b) return;
23
+ const y = `${e}.${p}-${m}`, l = a(b, y, s);
24
+ o.push(l);
25
+ });
26
+ }), c;
27
+ if (f === "defaultVariants")
28
+ return c;
29
+ if (f === "compoundVariants")
30
+ return r.forEach((p) => {
31
+ const { css: u, ...m } = p, b = Object.entries(m).reduce((l, [w, W]) => `${l}.${w}-${W}`, e), y = a(u, b, s);
32
+ o.push(y);
33
+ }), c;
34
+ if (f.startsWith("@")) {
35
+ const p = a(r, e, s), u = `${f} {
36
+ ${p.replace(`
37
+ `, `
38
+ `)}
39
+ }`;
40
+ return o.push(u), c;
41
+ }
42
+ const $ = j.includes("&") ? f.replace("&", e) : f.startsWith(":") ? `${e}${f}` : `${e} ${f}`, h = a(r, $, s);
43
+ return o.push(h), c;
44
+ }
45
+ if (n != null && n.templates && n.templates[f]) {
46
+ const h = r.split(".").reduce((p, u) => p[u], n.templates[f]);
47
+ if (h) {
48
+ const p = a(h, "");
49
+ return `${c}${p}`;
50
+ }
51
+ return console.warn(`Template "${f}" with path of "${r}" was not found in config!`), c;
52
+ }
53
+ const S = f.startsWith("-") ? f : O(f), g = ($, h = ";") => c = `${c}${$}${h}`, T = ($) => g(`${S}:${$}`);
54
+ if (typeof r == "number") return T(r);
55
+ if (typeof r != "string")
56
+ if ("toString" in r) r = r.toString();
57
+ else return c;
58
+ const { modifiers: V } = n || {}, k = function* () {
59
+ yield P(r), yield N(r, V);
60
+ }();
61
+ for (const { result: $, additionalCss: h = [] } of k)
62
+ r = $, h.forEach((p) => {
63
+ const u = a(p, "");
64
+ g(u, "");
65
+ });
66
+ return T(r);
67
+ }, "");
68
+ if (!i) return o.join(`
69
+ `);
70
+ if (!e) return i;
71
+ let d = "";
72
+ return s !== void 0 ? d = `@layer l${s} { ${e} { ${i} } }` : d = `${e} { ${i} }`, [d, ...o].join(`
73
+ `);
74
+ }, _ = (t, e = []) => {
75
+ if (!t) return "";
76
+ const s = [], n = {};
77
+ if (Object.entries(t).forEach(([o, i]) => {
78
+ if (typeof i == "object") {
79
+ if (!i) return;
80
+ const d = o.trim(), c = _(i, [...e, d]);
81
+ s.push(c);
82
+ } else
83
+ n[o] = i;
84
+ }), Object.keys(n).length) {
85
+ const o = e.map(O).join("-"), i = a(n, `.${o}`);
86
+ s.push(i);
87
+ }
88
+ return s.join(`
89
+ `);
90
+ }, A = (t) => Object.keys(t), K = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = E(n).map((o) => `"${o}"`).join(" | ")), e), {}), E = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
91
+ const i = e ? `${e}.${n}` : n;
92
+ return typeof o == "object" ? E(o, i, s) : s.add(e);
93
+ }), [...s]) : [];
94
+ export {
95
+ _ as a,
96
+ K as b,
97
+ P as c,
98
+ A as g,
99
+ a as p
100
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";const T=require("./dash-case-BJEkFEGQ.cjs"),N=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const r=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:i}=n;t=t.replace(o,d=>{const{value:c,css:j}=i(d);return j&&r.push(j),c})}),{result:t,additionalCss:r}},S=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${T.dashCase(n[1].replaceAll(".","-"))})`)}:{result:t},a=(t,e,r,n)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((c,[j,s])=>{const p=j.trim();if(typeof s=="function"&&(s=s()),typeof s=="object"){if(!s)return c;if(p==="variants")return Object.entries(s).forEach(([f,u])=>{u&&Object.entries(u).forEach(([l,m])=>{if(!m)return;const y=`${e}.${f}-${l}`,b=a(m,y,r);o.push(b)})}),c;if(p==="defaultVariants")return c;if(p==="compoundVariants")return s.forEach(f=>{const{css:u,...l}=f,m=Object.entries(l).reduce((b,[q,K])=>`${b}.${q}-${K}`,e),y=a(u,m,r);o.push(y)}),c;if(p.startsWith("@")){const f=a(s,e,r),u=`${p} {
2
+ ${f.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return o.push(u),c}const $=j.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`,h=a(s,$,r);return o.push(h),c}if(n!=null&&n.templates&&n.templates[p]){const h=s.split(".").reduce((f,u)=>f[u],n.templates[p]);if(h){const f=a(h,"");return`${c}${f}`}return console.warn(`Template "${p}" with path of "${s}" was not found in config!`),c}const k=p.startsWith("-")?p:T.dashCase(p),O=($,h=";")=>c=`${c}${$}${h}`,g=$=>O(`${k}:${$}`);if(typeof s=="number")return g(s);if(typeof s!="string")if("toString"in s)s=s.toString();else return c;const{modifiers:w}=n||{},W=function*(){yield S(s),yield N(s,w)}();for(const{result:$,additionalCss:h=[]}of W)s=$,h.forEach(f=>{const u=a(f,"");O(u,"")});return g(s)},"");if(!i)return o.join(`
6
+ `);if(!e)return i;let d="";return r!==void 0?d=`@layer l${r} { ${e} { ${i} } }`:d=`${e} { ${i} }`,[d,...o].join(`
7
+ `)},E=(t,e=[])=>{if(!t)return"";const r=[],n={};if(Object.entries(t).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const d=o.trim(),c=E(i,[...e,d]);r.push(c)}else n[o]=i}),Object.keys(n).length){const o=e.map(T.dashCase).join("-"),i=a(n,`.${o}`);r.push(i)}return r.join(`
8
+ `)},P=t=>Object.keys(t),_=t=>Object.entries(t).reduce((e,[r,n])=>(typeof n=="object"&&(e[r]=V(n).map(o=>`"${o}"`).join(" | ")),e),{}),V=(t,e="",r=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?V(o,i,r):r.add(e)}),[...r]):[];exports.getTemplateKeys=P;exports.getTemplateTypes=_;exports.parseStyles=a;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;