@salty-css/webpack 0.0.1-alpha.117 → 0.0.1-alpha.119

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.
@@ -0,0 +1,388 @@
1
+ import * as X from "esbuild";
2
+ import { execSync as rt } from "child_process";
3
+ import { join as a, parse as it } from "path";
4
+ import { existsSync as B, writeFileSync as F, readFileSync as W, mkdirSync as R, statSync as ct, readdirSync as at } from "fs";
5
+ import { readFile as lt, writeFile as ft } from "fs/promises";
6
+ import { createLogger as pt, format as _, transports as ut } from "winston";
7
+ const q = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), gt = (t, e) => {
8
+ let s = "", n;
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = q(n % 52) + s;
10
+ return s = q(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, dt = (t, e) => {
12
+ let s = e.length;
13
+ for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
+ return t;
15
+ }, I = (t, e = 3) => {
16
+ const s = dt(5381, JSON.stringify(t)) >>> 0;
17
+ return gt(s, e);
18
+ };
19
+ function N(t) {
20
+ return t ? typeof t != "string" ? N(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
21
+ }
22
+ const yt = (t, e) => {
23
+ if (typeof t != "string") return { result: t };
24
+ if (!e) return { result: t };
25
+ const s = [];
26
+ return Object.values(e).forEach((n) => {
27
+ const { pattern: r, transform: i } = n;
28
+ t = t.replace(r, (d) => {
29
+ const { value: c, css: b } = i(d);
30
+ return b && s.push(b), c;
31
+ });
32
+ }), { result: t, additionalCss: s };
33
+ }, Y = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${N(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s, n) => {
34
+ if (!t) return "";
35
+ const r = [], i = Object.entries(t).reduce((c, [b, o]) => {
36
+ const u = b.trim();
37
+ if (typeof o == "function" && (o = o()), typeof o == "object") {
38
+ if (!o) return c;
39
+ if (u === "variants")
40
+ return Object.entries(o).forEach(([j, f]) => {
41
+ f && Object.entries(f).forEach(([P, C]) => {
42
+ if (!C) return;
43
+ const E = `${e}.${j}-${P}`, g = O(C, E);
44
+ r.push(g);
45
+ });
46
+ }), c;
47
+ if (u === "defaultVariants")
48
+ return c;
49
+ if (u === "compoundVariants")
50
+ return o.forEach((j) => {
51
+ const { css: f, ...P } = j, C = Object.entries(P).reduce((g, [p, h]) => `${g}.${p}-${h}`, e), E = O(f, C);
52
+ r.push(E);
53
+ }), c;
54
+ if (u.startsWith("@")) {
55
+ const j = O(o, e), f = `${u} {
56
+ ${j.replace(`
57
+ `, `
58
+ `)}
59
+ }`;
60
+ return r.push(f), c;
61
+ }
62
+ const y = b.includes("&") ? u.replace("&", e) : u.startsWith(":") ? `${e}${u}` : `${e} ${u}`, S = O(o, y);
63
+ return r.push(S), c;
64
+ }
65
+ const $ = u.startsWith("-") ? u : N(u), w = (y, S = ";") => c = `${c}${y}${S}`, x = (y) => w(`${$}:${y}`);
66
+ if (typeof o == "number") return x(o);
67
+ if (typeof o != "string")
68
+ if ("toString" in o) o = o.toString();
69
+ else return c;
70
+ const { modifiers: l } = {}, T = function* () {
71
+ yield Y(o), yield yt(o, l);
72
+ }();
73
+ for (const { result: y, additionalCss: S = [] } of T)
74
+ o = y, S.forEach((j) => {
75
+ const f = O(j, "");
76
+ w(f, "");
77
+ });
78
+ return x(o);
79
+ }, "");
80
+ if (!i) return r.join(`
81
+ `);
82
+ if (!e) return i;
83
+ let d = "";
84
+ return d = `${e} { ${i} }`, [d, ...r].join(`
85
+ `);
86
+ }, Q = (t, e = []) => {
87
+ if (!t) return "";
88
+ const s = [], n = {};
89
+ if (Object.entries(t).forEach(([r, i]) => {
90
+ if (typeof i == "object") {
91
+ if (!i) return;
92
+ const d = r.trim(), c = Q(i, [...e, d]);
93
+ s.push(c);
94
+ } else
95
+ n[r] = i;
96
+ }), Object.keys(n).length) {
97
+ const r = e.map(N).join("-"), i = O(n, `.${r}`);
98
+ s.push(i);
99
+ }
100
+ return s.join(`
101
+ `);
102
+ }, ht = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = v(n).map((r) => `"${r}"`).join(" | ")), e), {}), v = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, r]) => {
103
+ const i = e ? `${e}.${n}` : n;
104
+ return typeof r == "object" ? v(r, i, s) : s.add(e);
105
+ }), [...s]) : [], tt = (t) => {
106
+ if (!t || t === "/") throw new Error("Could not find package.json file");
107
+ const e = a(t, "package.json");
108
+ return B(e) ? e : tt(a(t, ".."));
109
+ }, mt = async (t) => {
110
+ const e = tt(t);
111
+ return await lt(e, "utf-8").then(JSON.parse).catch(() => {
112
+ });
113
+ }, bt = async (t) => {
114
+ const e = await mt(t);
115
+ if (e)
116
+ return e.type;
117
+ };
118
+ let M;
119
+ const et = async (t) => {
120
+ if (M) return M;
121
+ const e = await bt(t);
122
+ return e === "module" ? M = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (M = "cjs"), M || "esm";
123
+ }, U = pt({
124
+ level: "debug",
125
+ format: _.combine(_.colorize(), _.cli()),
126
+ transports: [new ut.Console({})]
127
+ });
128
+ function st(t) {
129
+ return t ? typeof t != "string" ? st(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
130
+ }
131
+ const $t = {
132
+ /** Set box model to border-box */
133
+ "*, *::before, *::after": {
134
+ boxSizing: "border-box"
135
+ },
136
+ /** Remove default margin and padding */
137
+ "*": {
138
+ margin: 0
139
+ },
140
+ /** Remove adjust font properties */
141
+ html: {
142
+ lineHeight: 1.15,
143
+ textSizeAdjust: "100%",
144
+ WebkitFontSmoothing: "antialiased"
145
+ },
146
+ /** Make media elements responsive */
147
+ "img, picture, video, canvas, svg": {
148
+ display: "block",
149
+ maxWidth: "100%"
150
+ },
151
+ /** Avoid overflow of text */
152
+ "p, h1, h2, h3, h4, h5, h6": {
153
+ overflowWrap: "break-word"
154
+ },
155
+ /** Improve text wrapping */
156
+ p: {
157
+ textWrap: "pretty"
158
+ },
159
+ "h1, h2, h3, h4, h5, h6": {
160
+ textWrap: "balance"
161
+ },
162
+ /** Improve button line height */
163
+ button: {
164
+ lineHeight: "1em"
165
+ },
166
+ /** Improve form elements */
167
+ "input, optgroup, select, textarea": {
168
+ fontFamily: "inherit",
169
+ fontSize: "100%",
170
+ lineHeight: "1.15em"
171
+ }
172
+ }, H = {
173
+ externalModules: []
174
+ }, nt = (t) => {
175
+ if (H.externalModules.length > 0) return H.externalModules;
176
+ const e = a(t, "salty.config.ts"), n = W(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
177
+ if (!n) return [];
178
+ const r = n[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
179
+ return H.externalModules = r, r;
180
+ }, Z = (t) => a(t, "./saltygen"), St = ["salty", "css", "styles", "styled"], jt = (t = []) => new RegExp(`\\.(${[...St, ...t].join("|")})\\.`), K = (t, e = []) => jt(e).test(t), wt = async (t) => {
181
+ const e = Z(t), s = a(t, "salty.config.ts"), n = a(e, "salty.config.js"), r = await et(t), i = nt(t);
182
+ await X.build({
183
+ entryPoints: [s],
184
+ minify: !0,
185
+ treeShaking: !0,
186
+ bundle: !0,
187
+ outfile: n,
188
+ format: r,
189
+ external: i
190
+ });
191
+ const d = Date.now(), { config: c } = await import(`${n}?t=${d}`);
192
+ return c;
193
+ }, xt = async (t) => {
194
+ const e = await wt(t), s = /* @__PURE__ */ new Set(), n = (g, p = []) => g ? Object.entries(g).flatMap(([h, m]) => {
195
+ if (!m) return;
196
+ if (typeof m == "object") return n(m, [...p, h]);
197
+ const D = st(h), A = N(h), V = [...p, D].join(".");
198
+ s.add(`"${V}"`);
199
+ const J = [...p.map(N), A].join("-"), { result: z } = Y(m);
200
+ return `--${J}: ${z};`;
201
+ }) : [], r = (g) => g ? Object.entries(g).flatMap(([p, h]) => {
202
+ const m = n(h);
203
+ return p === "base" ? m.join("") : `${p} { ${m.join("")} }`;
204
+ }) : [], i = (g) => g ? Object.entries(g).flatMap(([p, h]) => Object.entries(h).flatMap(([m, D]) => {
205
+ const A = n(D, [p]), V = `.${p}-${m}, [data-${p}="${m}"]`, J = A.join("");
206
+ return `${V} { ${J} }`;
207
+ })) : [], d = n(e.variables), c = r(e.responsiveVariables), b = i(e.conditionalVariables), o = Z(t), u = a(o, "css/variables.css"), $ = `:root { ${d.join("")} ${c.join("")} } ${b.join("")}`;
208
+ F(u, $);
209
+ const w = a(o, "css/global.css"), x = O(e.global, "");
210
+ F(w, `@layer global { ${x} }`);
211
+ const l = a(o, "css/reset.css"), T = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : $t, y = O(T, "");
212
+ F(l, `@layer reset { ${y} }`);
213
+ const S = a(o, "css/templates.css"), j = Q(e.templates), f = ht(e.templates);
214
+ F(S, j);
215
+ const P = a(o, "types/css-tokens.d.ts"), E = `
216
+ // Variable types
217
+ type VariableTokens = ${[...s].join("|")};
218
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
219
+
220
+ // Template types
221
+ type TemplateTokens = {
222
+ ${Object.entries(f).map(([g, p]) => `${g}?: ${p}`).join(`
223
+ `)}
224
+ }
225
+ `;
226
+ F(P, E);
227
+ }, G = async (t, e, s) => {
228
+ const n = I(e), r = a(s, "./temp");
229
+ B(r) || R(r);
230
+ const i = it(e);
231
+ let d = W(e, "utf8");
232
+ d = d.replace(/styled\([^"'`{,]+,/g, "styled('div',");
233
+ const c = a(s, "js", n + ".js"), b = nt(t), o = await et(t);
234
+ await X.build({
235
+ stdin: {
236
+ contents: d,
237
+ sourcefile: i.base,
238
+ resolveDir: i.dir,
239
+ loader: "tsx"
240
+ },
241
+ minify: !1,
242
+ treeShaking: !0,
243
+ bundle: !0,
244
+ outfile: c,
245
+ format: o,
246
+ target: ["node20"],
247
+ keepNames: !0,
248
+ external: b,
249
+ packages: "external"
250
+ });
251
+ const u = Date.now();
252
+ return await import(`${c}?t=${u}`);
253
+ }, L = async (t) => {
254
+ const e = Z(t), s = a(e, "salty.config.js"), { config: n } = await import(s);
255
+ return n;
256
+ }, ot = () => {
257
+ try {
258
+ return process.env.NODE_ENV === "production";
259
+ } catch {
260
+ return !1;
261
+ }
262
+ }, Et = async (t, e = ot()) => {
263
+ try {
264
+ e ? U.info("Generating CSS in production mode! 🔥") : U.info("Generating CSS in development mode! 🚀");
265
+ const s = [], n = [], r = Z(t), i = a(r, "index.css");
266
+ (() => {
267
+ B(r) && rt("rm -rf " + r), R(r), R(a(r, "css")), R(a(r, "types"));
268
+ })(), await xt(t);
269
+ const c = await L(t);
270
+ async function b(l, k) {
271
+ const T = ["node_modules", "saltygen"], y = ct(l);
272
+ if (y.isDirectory()) {
273
+ const S = at(l);
274
+ if (T.some((f) => l.includes(f))) return;
275
+ await Promise.all(S.map((f) => b(a(l, f), a(k, f))));
276
+ } else if (y.isFile() && K(l)) {
277
+ const j = await G(t, l, r), f = [];
278
+ Object.entries(j).forEach(([g, p]) => {
279
+ if (p.isKeyframes && p.css) {
280
+ const V = `${p.animationName}.css`, J = `css/${V}`, z = a(r, J);
281
+ s.push(V), F(z, p.css);
282
+ return;
283
+ }
284
+ if (!p.generator) return;
285
+ const h = p.generator._withBuildContext({
286
+ name: g,
287
+ config: c,
288
+ prod: e
289
+ }), m = `${h.hash}-${h.priority}.css`;
290
+ n[h.priority] || (n[h.priority] = []), n[h.priority].push(m), f.push(m);
291
+ const D = `css/${m}`, A = a(r, D);
292
+ F(A, h.css);
293
+ });
294
+ const P = f.map((g) => `@import url('./${g}');`).join(`
295
+ `), C = I(l, 6), E = a(r, `css/${C}.css`);
296
+ F(E, P);
297
+ }
298
+ }
299
+ await b(t, r);
300
+ const o = s.map((l) => `@import url('./css/${l}');`).join(`
301
+ `);
302
+ let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
303
+
304
+ ${["variables.css", "reset.css", "global.css", "templates.css"].filter((l) => {
305
+ try {
306
+ return W(a(r, "css", l), "utf8").length > 0;
307
+ } catch {
308
+ return !1;
309
+ }
310
+ }).map((l) => `@import url('./css/${l}');`).join(`
311
+ `)}
312
+ ${o}`;
313
+ if (c.importStrategy !== "component") {
314
+ const l = n.flat().map((k) => `@import url('./css/${k}');`).join(`
315
+ `);
316
+ x += l;
317
+ }
318
+ F(i, x);
319
+ } catch (s) {
320
+ console.error(s);
321
+ }
322
+ }, Dt = async (t, e) => {
323
+ try {
324
+ const s = [], n = a(t, "./saltygen"), r = a(n, "index.css");
325
+ if (K(e)) {
326
+ const d = await L(t), c = await G(t, e, n);
327
+ Object.entries(c).forEach(([w, x]) => {
328
+ if (!x.generator) return;
329
+ const l = x.generator._withBuildContext({
330
+ name: w,
331
+ config: d
332
+ }), k = `${l.hash}-${l.priority}.css`, T = `css/${k}`, y = a(n, T);
333
+ s.push(k), F(y, l.css);
334
+ });
335
+ const b = W(r, "utf8").split(`
336
+ `), o = s.map((w) => `@import url('../saltygen/css/${w}');`), $ = [.../* @__PURE__ */ new Set([...b, ...o])].join(`
337
+ `);
338
+ F(r, $);
339
+ }
340
+ } catch (s) {
341
+ console.error(s);
342
+ }
343
+ }, Ot = async (t, e, s = ot()) => {
344
+ try {
345
+ const n = a(t, "./saltygen");
346
+ if (K(e)) {
347
+ const i = W(e, "utf8");
348
+ i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await ft(e, i);
349
+ const c = await L(t), b = await G(t, e, n);
350
+ let o = i;
351
+ Object.entries(b).forEach(([$, w]) => {
352
+ var m;
353
+ if (w.isKeyframes || !w.generator) return;
354
+ const x = w.generator._withBuildContext({
355
+ name: $,
356
+ config: c,
357
+ prod: s
358
+ }), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
359
+ if (!l) return console.error("Could not find the original declaration");
360
+ const k = (m = l.at(1)) == null ? void 0 : m.trim(), T = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(o);
361
+ if (!T) return console.error("Could not find the original declaration");
362
+ const { index: y } = T;
363
+ let S = !1;
364
+ const j = setTimeout(() => S = !0, 5e3);
365
+ let f = 0, P = !1, C = 0;
366
+ for (; !P && !S; ) {
367
+ const D = o[y + f];
368
+ D === "(" && C++, D === ")" && C--, C === 0 && D === ")" && (P = !0), f > o.length && (S = !0), f++;
369
+ }
370
+ if (!S) clearTimeout(j);
371
+ else throw new Error("Failed to find the end of the styled call and timed out");
372
+ const E = y + f, g = o.slice(y, E), p = o, h = ` ${$} = styled(${k}, "${x.classNames}", ${JSON.stringify(x.props)});`;
373
+ o = o.replace(g, h), p === o && console.error("Minimize file failed to change content", { name: $, tagName: k });
374
+ });
375
+ const u = I(e, 6);
376
+ return c.importStrategy === "component" && (o = `import '../../saltygen/css/${u}.css';
377
+ ${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
378
+ }
379
+ } catch (n) {
380
+ console.error("Error in minimizeFile:", n);
381
+ }
382
+ };
383
+ export {
384
+ Dt as a,
385
+ Et as g,
386
+ Ot as m,
387
+ jt as s
388
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";const rt=require("esbuild"),it=require("child_process"),a=require("path"),f=require("fs"),U=require("fs/promises"),_=require("winston");var Z=typeof document<"u"?document.currentScript:null;function ct(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const G=ct(rt),L=t=>String.fromCharCode(t+(t>25?39:97)),at=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=L(n%52)+s;return s=L(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},lt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=3)=>{const s=lt(5381,JSON.stringify(t))>>>0;return at(s,e)};function V(t){return t?typeof t!="string"?V(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const ft=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:r,transform:i}=n;t=t.replace(r,y=>{const{value:c,css:j}=i(y);return j&&s.push(j),c})}),{result:t,additionalCss:s}},X=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V(n[1].replaceAll(".","-"))})`)}:{result:t},E=(t,e,s,n)=>{if(!t)return"";const r=[],i=Object.entries(t).reduce((c,[j,o])=>{const d=j.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return c;if(d==="variants")return Object.entries(o).forEach(([w,u])=>{u&&Object.entries(u).forEach(([P,C])=>{if(!C)return;const O=`${e}.${w}-${P}`,g=E(C,O);r.push(g)})}),c;if(d==="defaultVariants")return c;if(d==="compoundVariants")return o.forEach(w=>{const{css:u,...P}=w,C=Object.entries(P).reduce((g,[p,m])=>`${g}.${p}-${m}`,e),O=E(u,C);r.push(O)}),c;if(d.startsWith("@")){const w=E(o,e),u=`${d} {
2
+ ${w.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return r.push(u),c}const h=j.includes("&")?d.replace("&",e):d.startsWith(":")?`${e}${d}`:`${e} ${d}`,$=E(o,h);return r.push($),c}const S=d.startsWith("-")?d:V(d),F=(h,$=";")=>c=`${c}${h}${$}`,x=h=>F(`${S}:${h}`);if(typeof o=="number")return x(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return c;const{modifiers:l}={},T=function*(){yield X(o),yield ft(o,l)}();for(const{result:h,additionalCss:$=[]}of T)o=h,$.forEach(w=>{const u=E(w,"");F(u,"")});return x(o)},"");if(!i)return r.join(`
6
+ `);if(!e)return i;let y="";return y=`${e} { ${i} }`,[y,...r].join(`
7
+ `)},Y=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,i])=>{if(typeof i=="object"){if(!i)return;const y=r.trim(),c=Y(i,[...e,y]);s.push(c)}else n[r]=i}),Object.keys(n).length){const r=e.map(V).join("-"),i=E(n,`.${r}`);s.push(i)}return s.join(`
8
+ `)},ut=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=Q(n).map(r=>`"${r}"`).join(" | ")),e),{}),Q=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,r])=>{const i=e?`${e}.${n}`:n;return typeof r=="object"?Q(r,i,s):s.add(e)}),[...s]):[],v=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=a.join(t,"package.json");return f.existsSync(e)?e:v(a.join(t,".."))},pt=async t=>{const e=v(t);return await U.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},dt=async t=>{const e=await pt(t);if(e)return e.type};let N;const tt=async t=>{if(N)return N;const e=await dt(t);return e==="module"?N="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Z&&Z.tagName.toUpperCase()==="SCRIPT"&&Z.src||new URL("index-BysiENYs.cjs",document.baseURI).href).endsWith(".cjs"))&&(N="cjs"),N||"esm"},K=_.createLogger({level:"debug",format:_.format.combine(_.format.colorize(),_.format.cli()),transports:[new _.transports.Console({})]});function et(t){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,s)=>(s>0?".":"")+e.toLowerCase()):""}const gt={"*, *::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"}},z={externalModules:[]},st=t=>{if(z.externalModules.length>0)return z.externalModules;const e=a.join(t,"salty.config.ts"),n=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const r=n[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return z.externalModules=r,r},J=t=>a.join(t,"./saltygen"),yt=["salty","css","styles","styled"],nt=(t=[])=>new RegExp(`\\.(${[...yt,...t].join("|")})\\.`),I=(t,e=[])=>nt(e).test(t),ht=async t=>{const e=J(t),s=a.join(t,"salty.config.ts"),n=a.join(e,"salty.config.js"),r=await tt(t),i=st(t);await G.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:r,external:i});const y=Date.now(),{config:c}=await import(`${n}?t=${y}`);return c},mt=async t=>{const e=await ht(t),s=new Set,n=(g,p=[])=>g?Object.entries(g).flatMap(([m,b])=>{if(!b)return;if(typeof b=="object")return n(b,[...p,m]);const D=et(m),A=V(m),M=[...p,D].join(".");s.add(`"${M}"`);const R=[...p.map(V),A].join("-"),{result:W}=X(b);return`--${R}: ${W};`}):[],r=g=>g?Object.entries(g).flatMap(([p,m])=>{const b=n(m);return p==="base"?b.join(""):`${p} { ${b.join("")} }`}):[],i=g=>g?Object.entries(g).flatMap(([p,m])=>Object.entries(m).flatMap(([b,D])=>{const A=n(D,[p]),M=`.${p}-${b}, [data-${p}="${b}"]`,R=A.join("");return`${M} { ${R} }`})):[],y=n(e.variables),c=r(e.responsiveVariables),j=i(e.conditionalVariables),o=J(t),d=a.join(o,"css/variables.css"),S=`:root { ${y.join("")} ${c.join("")} } ${j.join("")}`;f.writeFileSync(d,S);const F=a.join(o,"css/global.css"),x=E(e.global,"");f.writeFileSync(F,`@layer global { ${x} }`);const l=a.join(o,"css/reset.css"),T=e.reset==="none"?{}:typeof e.reset=="object"?e.reset:gt,h=E(T,"");f.writeFileSync(l,`@layer reset { ${h} }`);const $=a.join(o,"css/templates.css"),w=Y(e.templates),u=ut(e.templates);f.writeFileSync($,w);const P=a.join(o,"types/css-tokens.d.ts"),O=`
9
+ // Variable types
10
+ type VariableTokens = ${[...s].join("|")};
11
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
12
+
13
+ // Template types
14
+ type TemplateTokens = {
15
+ ${Object.entries(u).map(([g,p])=>`${g}?: ${p}`).join(`
16
+ `)}
17
+ }
18
+ `;f.writeFileSync(P,O)},H=async(t,e,s)=>{const n=q(e),r=a.join(s,"./temp");f.existsSync(r)||f.mkdirSync(r);const i=a.parse(e);let y=f.readFileSync(e,"utf8");y=y.replace(/styled\([^"'`{,]+,/g,"styled('div',");const c=a.join(s,"js",n+".js"),j=st(t),o=await tt(t);await G.build({stdin:{contents:y,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:c,format:o,target:["node20"],keepNames:!0,external:j,packages:"external"});const d=Date.now();return await import(`${c}?t=${d}`)},B=async t=>{const e=J(t),s=a.join(e,"salty.config.js"),{config:n}=await import(s);return n},ot=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},bt=async(t,e=ot())=>{try{e?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const s=[],n=[],r=J(t),i=a.join(r,"index.css");(()=>{f.existsSync(r)&&it.execSync("rm -rf "+r),f.mkdirSync(r),f.mkdirSync(a.join(r,"css")),f.mkdirSync(a.join(r,"types"))})(),await mt(t);const c=await B(t);async function j(l,k){const T=["node_modules","saltygen"],h=f.statSync(l);if(h.isDirectory()){const $=f.readdirSync(l);if(T.some(u=>l.includes(u)))return;await Promise.all($.map(u=>j(a.join(l,u),a.join(k,u))))}else if(h.isFile()&&I(l)){const w=await H(t,l,r),u=[];Object.entries(w).forEach(([g,p])=>{if(p.isKeyframes&&p.css){const M=`${p.animationName}.css`,R=`css/${M}`,W=a.join(r,R);s.push(M),f.writeFileSync(W,p.css);return}if(!p.generator)return;const m=p.generator._withBuildContext({name:g,config:c,prod:e}),b=`${m.hash}-${m.priority}.css`;n[m.priority]||(n[m.priority]=[]),n[m.priority].push(b),u.push(b);const D=`css/${b}`,A=a.join(r,D);f.writeFileSync(A,m.css)});const P=u.map(g=>`@import url('./${g}');`).join(`
19
+ `),C=q(l,6),O=a.join(r,`css/${C}.css`);f.writeFileSync(O,P)}}await j(t,r);const o=s.map(l=>`@import url('./css/${l}');`).join(`
20
+ `);let x=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+
22
+ ${["variables.css","reset.css","global.css","templates.css"].filter(l=>{try{return f.readFileSync(a.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
23
+ `)}
24
+ ${o}`;if(c.importStrategy!=="component"){const l=n.flat().map(k=>`@import url('./css/${k}');`).join(`
25
+ `);x+=l}f.writeFileSync(i,x)}catch(s){console.error(s)}},jt=async(t,e)=>{try{const s=[],n=a.join(t,"./saltygen"),r=a.join(n,"index.css");if(I(e)){const y=await B(t),c=await H(t,e,n);Object.entries(c).forEach(([F,x])=>{if(!x.generator)return;const l=x.generator._withBuildContext({name:F,config:y}),k=`${l.hash}-${l.priority}.css`,T=`css/${k}`,h=a.join(n,T);s.push(k),f.writeFileSync(h,l.css)});const j=f.readFileSync(r,"utf8").split(`
26
+ `),o=s.map(F=>`@import url('../saltygen/css/${F}');`),S=[...new Set([...j,...o])].join(`
27
+ `);f.writeFileSync(r,S)}}catch(s){console.error(s)}},St=async(t,e,s=ot())=>{try{const n=a.join(t,"./saltygen");if(I(e)){const i=f.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==i&&await U.writeFile(e,i);const c=await B(t),j=await H(t,e,n);let o=i;Object.entries(j).forEach(([S,F])=>{var b;if(F.isKeyframes||!F.generator)return;const x=F.generator._withBuildContext({name:S,config:c,prod:s}),l=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!l)return console.error("Could not find the original declaration");const k=(b=l.at(1))==null?void 0:b.trim(),T=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(o);if(!T)return console.error("Could not find the original declaration");const{index:h}=T;let $=!1;const w=setTimeout(()=>$=!0,5e3);let u=0,P=!1,C=0;for(;!P&&!$;){const D=o[h+u];D==="("&&C++,D===")"&&C--,C===0&&D===")"&&(P=!0),u>o.length&&($=!0),u++}if(!$)clearTimeout(w);else throw new Error("Failed to find the end of the styled call and timed out");const O=h+u,g=o.slice(h,O),p=o,m=` ${S} = styled(${k}, "${x.classNames}", ${JSON.stringify(x.props)});`;o=o.replace(g,m),p===o&&console.error("Minimize file failed to change content",{name:S,tagName:k})});const d=q(e,6);return c.importStrategy==="component"&&(o=`import '../../saltygen/css/${d}.css';
28
+ ${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=bt;exports.generateFile=jt;exports.minimizeFile=St;exports.saltyFileRegExp=nt;
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-55a7q00M.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-BysiENYs.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolve as n } from "path";
2
- import { s as u, g as i } from "./index-BVNy6_ZE.js";
2
+ import { s as u, g as i } from "./index-7hxQ_ONX.js";
3
3
  const g = (s, e, o = !1, r = !1) => {
4
4
  var a, l, t;
5
5
  (l = (a = s.module) == null ? void 0 : a.rules) == null || l.push({
package/loader.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const i=require("./index-55a7q00M.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
1
+ "use strict";const i=require("./index-BysiENYs.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
package/loader.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, m as i } from "./index-BVNy6_ZE.js";
1
+ import { a as e, m as i } from "./index-7hxQ_ONX.js";
2
2
  async function s() {
3
3
  const { dir: t } = this.getOptions(), { resourcePath: a } = this;
4
4
  return await e(t, a), await i(t, a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.117",
3
+ "version": "0.0.1-alpha.119",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "^0.0.1-alpha.117",
37
+ "@salty-css/core": "^0.0.1-alpha.119",
38
38
  "webpack": ">=5.x"
39
39
  }
40
40
  }
@@ -1,28 +0,0 @@
1
- "use strict";const rt=require("esbuild"),it=require("child_process"),l=require("path"),u=require("fs"),L=require("fs/promises"),V=require("winston");var _=typeof document<"u"?document.currentScript:null;function ct(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const K=ct(rt),W=t=>String.fromCharCode(t+(t>25?39:97)),at=(t,e)=>{let n="",s;for(s=Math.abs(t);s>52;s=s/52|0)n=W(s%52)+n;return n=W(s%52)+n,n.length<e?n=n.padStart(e,"a"):n.length>e&&(n=n.slice(-e)),n},lt=(t,e)=>{let n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return t},R=(t,e=3)=>{const n=lt(5381,JSON.stringify(t))>>>0;return at(n,e)};function N(t){return t?typeof t!="string"?N(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,n)=>(n>0?"-":"")+e.toLowerCase()):""}const ft=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const n=[];return Object.values(e).forEach(s=>{const{pattern:o,transform:i}=s;t=t.replace(o,g=>{const{value:a,css:j}=i(g);return j&&n.push(j),a})}),{result:t,additionalCss:n}},U=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...s)=>`var(--${N(s[1].replaceAll(".","-"))})`)}:{result:t},E=(t,e,n,s)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((a,[j,r])=>{const d=j.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(d==="variants")return Object.entries(r).forEach(([S,c])=>{c&&Object.entries(c).forEach(([p,m])=>{if(!m)return;const h=`${e}.${S}-${p}`,T=E(m,h);o.push(T)})}),a;if(d==="defaultVariants")return a;if(d==="compoundVariants")return r.forEach(S=>{const{css:c,...p}=S,m=Object.entries(p).reduce((T,[w,F])=>`${T}.${w}-${F}`,e),h=E(c,m);o.push(h)}),a;if(d.startsWith("@")){const S=E(r,e),c=`${d} {
2
- ${S.replace(`
3
- `,`
4
- `)}
5
- }`;return o.push(c),a}const y=j.includes("&")?d.replace("&",e):d.startsWith(":")?`${e}${d}`:`${e} ${d}`,b=E(r,y);return o.push(b),a}const $=d.startsWith("-")?d:N(d),C=(y,b=";")=>a=`${a}${y}${b}`,k=y=>C(`${$}:${y}`);if(typeof r=="number")return k(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:f}={},P=function*(){yield U(r),yield ft(r,f)}();for(const{result:y,additionalCss:b=[]}of P)r=y,b.forEach(S=>{const c=E(S,"");C(c,"")});return k(r)},"");if(!i)return o.join(`
6
- `);if(!e)return i;let g="";return g=`${e} { ${i} }`,[g,...o].join(`
7
- `)},G=(t,e=[])=>{if(!t)return"";const n=[],s={};if(Object.entries(t).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const g=o.trim(),a=G(i,[...e,g]);n.push(a)}else s[o]=i}),Object.keys(s).length){const o=e.map(N).join("-"),i=E(s,`.${o}`);n.push(i)}return n.join(`
8
- `)},ut=t=>Object.entries(t).reduce((e,[n,s])=>(typeof s=="object"&&(e[n]=H(s).map(o=>`"${o}"`).join(" | ")),e),{}),H=(t,e="",n=new Set)=>t?(Object.entries(t).forEach(([s,o])=>{const i=e?`${e}.${s}`:s;return typeof o=="object"?H(o,i,n):n.add(e)}),[...n]):[],X=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return u.existsSync(e)?e:X(l.join(t,".."))},pt=async t=>{const e=X(t);return await L.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},dt=async t=>{const e=await pt(t);if(e)return e.type};let M;const Y=async t=>{if(M)return M;const e=await dt(t);return e==="module"?M="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index-55a7q00M.cjs",document.baseURI).href).endsWith(".cjs"))&&(M="cjs"),M||"esm"},B=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]});function Q(t){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,n)=>(n>0?".":"")+e.toLowerCase()):""}const J={externalModules:[]},v=t=>{if(J.externalModules.length>0)return J.externalModules;const e=l.join(t,"salty.config.ts"),s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const o=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return J.externalModules=o,o},A=t=>l.join(t,"./saltygen"),gt=["salty","css","styles","styled"],tt=(t=[])=>new RegExp(`\\.(${[...gt,...t].join("|")})\\.`),Z=(t,e=[])=>tt(e).test(t),yt=async t=>{const e=A(t),n=l.join(t,"salty.config.ts"),s=l.join(e,"salty.config.js"),o=await Y(t),i=v(t);await K.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:o,external:i});const g=Date.now(),{config:a}=await import(`${s}?t=${g}`);return a},mt=async t=>{const e=await yt(t),n=new Set,s=(c,p=[])=>c?Object.entries(c).flatMap(([m,h])=>{if(!h)return;if(typeof h=="object")return s(h,[...p,m]);const T=Q(m),w=N(m),F=[...p,T].join(".");n.add(`"${F}"`);const O=[...p.map(N),w].join("-"),{result:D}=U(h);return`--${O}: ${D};`}):[],o=c=>c?Object.entries(c).flatMap(([p,m])=>{const h=s(m);return p==="base"?h.join(""):`${p} { ${h.join("")} }`}):[],i=c=>c?Object.entries(c).flatMap(([p,m])=>Object.entries(m).flatMap(([h,T])=>{const w=s(T,[p]),F=`.${p}-${h}, [data-${p}="${h}"]`,O=w.join("");return`${F} { ${O} }`})):[],g=s(e.variables),a=o(e.responsiveVariables),j=i(e.conditionalVariables),r=A(t),d=l.join(r,"css/variables.css"),$=`:root { ${g.join("")} ${a.join("")} } ${j.join("")}`;u.writeFileSync(d,$);const C=l.join(r,"css/global.css"),k=E(e.global,"");u.writeFileSync(C,k);const f=l.join(r,"css/templates.css"),x=G(e.templates),P=ut(e.templates);u.writeFileSync(f,x);const y=l.join(r,"types/css-tokens.d.ts"),S=`
9
- // Variable types
10
- type VariableTokens = ${[...n].join("|")};
11
- type PropertyValueToken = \`{\${VariableTokens}}\`;
12
-
13
- // Template types
14
- type TemplateTokens = {
15
- ${Object.entries(P).map(([c,p])=>`${c}?: ${p}`).join(`
16
- `)}
17
- }
18
- `;u.writeFileSync(y,S)},q=async(t,e,n)=>{const s=R(e),o=l.join(n,"./temp");u.existsSync(o)||u.mkdirSync(o);const i=l.parse(e);let g=u.readFileSync(e,"utf8");g=g.replace(/styled\([^"'`{,]+,/g,"styled('div',");const a=l.join(n,"js",s+".js"),j=v(t),r=await Y(t);await K.build({stdin:{contents:g,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:a,format:r,target:["node20"],keepNames:!0,external:j,packages:"external"});const d=Date.now();return await import(`${a}?t=${d}`)},I=async t=>{const e=A(t),n=l.join(e,"salty.config.js"),{config:s}=await import(n);return s},et=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ht=async(t,e=et())=>{try{e?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const n=[],s=[],o=A(t),i=l.join(o,"index.css");(()=>{u.existsSync(o)&&it.execSync("rm -rf "+o),u.mkdirSync(o),u.mkdirSync(l.join(o,"css")),u.mkdirSync(l.join(o,"types"))})(),await mt(t);const a=await I(t);async function j(f,x){const P=["node_modules","saltygen"],y=u.statSync(f);if(y.isDirectory()){const b=u.readdirSync(f);if(P.some(c=>f.includes(c)))return;await Promise.all(b.map(c=>j(l.join(f,c),l.join(x,c))))}else if(y.isFile()&&Z(f)){const S=await q(t,f,o),c=[];Object.entries(S).forEach(([T,w])=>{if(w.isKeyframes&&w.css){const z=`${w.animationName}.css`,st=`css/${z}`,ot=l.join(o,st);n.push(z),u.writeFileSync(ot,w.css);return}if(!w.generator)return;const F=w.generator._withBuildContext({name:T,config:a,prod:e}),O=`${F.hash}-${F.priority}.css`;s[F.priority]||(s[F.priority]=[]),s[F.priority].push(O),c.push(O);const D=`css/${O}`,nt=l.join(o,D);u.writeFileSync(nt,F.css)});const p=c.map(T=>`@import url('./${T}');`).join(`
19
- `),m=R(f,6),h=l.join(o,`css/${m}.css`);u.writeFileSync(h,p)}}await j(t,o);const r=n.map(f=>`@import url('./css/${f}');`).join(`
20
- `);let k=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
-
22
- ${["variables.css","global.css","templates.css"].filter(f=>{try{return u.readFileSync(l.join(o,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
23
- `)}
24
- ${r}`;if(a.importStrategy!=="component"){const f=s.flat().map(x=>`@import url('./css/${x}');`).join(`
25
- `);k+=f}u.writeFileSync(i,k)}catch(n){console.error(n)}},jt=async(t,e)=>{try{const n=[],s=l.join(t,"./saltygen"),o=l.join(s,"index.css");if(Z(e)){const g=await I(t),a=await q(t,e,s);Object.entries(a).forEach(([C,k])=>{if(!k.generator)return;const f=k.generator._withBuildContext({name:C,config:g}),x=`${f.hash}-${f.priority}.css`,P=`css/${x}`,y=l.join(s,P);n.push(x),u.writeFileSync(y,f.css)});const j=u.readFileSync(o,"utf8").split(`
26
- `),r=n.map(C=>`@import url('../saltygen/css/${C}');`),$=[...new Set([...j,...r])].join(`
27
- `);u.writeFileSync(o,$)}}catch(n){console.error(n)}},$t=async(t,e,n=et())=>{try{const s=l.join(t,"./saltygen");if(Z(e)){const i=u.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,$=>`export ${$}`)!==i&&await L.writeFile(e,i);const a=await I(t),j=await q(t,e,s);let r=i;Object.entries(j).forEach(([$,C])=>{var O;if(C.isKeyframes||!C.generator)return;const k=C.generator._withBuildContext({name:$,config:a,prod:n}),f=new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!f)return console.error("Could not find the original declaration");const x=(O=f.at(1))==null?void 0:O.trim(),P=new RegExp(`\\s${$}[=\\s]+styled\\(`,"g").exec(r);if(!P)return console.error("Could not find the original declaration");const{index:y}=P;let b=!1;const S=setTimeout(()=>b=!0,5e3);let c=0,p=!1,m=0;for(;!p&&!b;){const D=r[y+c];D==="("&&m++,D===")"&&m--,m===0&&D===")"&&(p=!0),c>r.length&&(b=!0),c++}if(!b)clearTimeout(S);else throw new Error("Failed to find the end of the styled call and timed out");const h=y+c,T=r.slice(y,h),w=r,F=` ${$} = styled(${x}, "${k.classNames}", ${JSON.stringify(k.props)});`;r=r.replace(T,F),w===r&&console.error("Minimize file failed to change content",{name:$,tagName:x})});const d=R(e,6);return a.importStrategy==="component"&&(r=`import '../../saltygen/css/${d}.css';
28
- ${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(s){console.error("Error in minimizeFile:",s)}};exports.generateCss=ht;exports.generateFile=jt;exports.minimizeFile=$t;exports.saltyFileRegExp=tt;
package/index-BVNy6_ZE.js DELETED
@@ -1,345 +0,0 @@
1
- import * as L from "esbuild";
2
- import { execSync as rt } from "child_process";
3
- import { join as f, parse as it } from "path";
4
- import { existsSync as _, writeFileSync as E, readFileSync as N, mkdirSync as A, statSync as ct, readdirSync as at } from "fs";
5
- import { readFile as lt, writeFile as ft } from "fs/promises";
6
- import { createLogger as pt, format as Z, transports as ut } from "winston";
7
- const G = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), gt = (t, e) => {
8
- let s = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = G(n % 52) + s;
10
- return s = G(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, dt = (t, e) => {
12
- let s = e.length;
13
- for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
- return t;
15
- }, W = (t, e = 3) => {
16
- const s = dt(5381, JSON.stringify(t)) >>> 0;
17
- return gt(s, e);
18
- };
19
- function M(t) {
20
- return t ? typeof t != "string" ? M(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
21
- }
22
- const yt = (t, e) => {
23
- if (typeof t != "string") return { result: t };
24
- if (!e) return { result: t };
25
- const s = [];
26
- return Object.values(e).forEach((n) => {
27
- const { pattern: o, transform: i } = n;
28
- t = t.replace(o, (g) => {
29
- const { value: a, css: h } = i(g);
30
- return h && s.push(h), a;
31
- });
32
- }), { result: t, additionalCss: s };
33
- }, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${M(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s, n) => {
34
- if (!t) return "";
35
- const o = [], i = Object.entries(t).reduce((a, [h, r]) => {
36
- const u = h.trim();
37
- if (typeof r == "function" && (r = r()), typeof r == "object") {
38
- if (!r) return a;
39
- if (u === "variants")
40
- return Object.entries(r).forEach(([j, c]) => {
41
- c && Object.entries(c).forEach(([p, y]) => {
42
- if (!y) return;
43
- const m = `${e}.${j}-${p}`, F = O(y, m);
44
- o.push(F);
45
- });
46
- }), a;
47
- if (u === "defaultVariants")
48
- return a;
49
- if (u === "compoundVariants")
50
- return r.forEach((j) => {
51
- const { css: c, ...p } = j, y = Object.entries(p).reduce((F, [w, S]) => `${F}.${w}-${S}`, e), m = O(c, y);
52
- o.push(m);
53
- }), a;
54
- if (u.startsWith("@")) {
55
- const j = O(r, e), c = `${u} {
56
- ${j.replace(`
57
- `, `
58
- `)}
59
- }`;
60
- return o.push(c), a;
61
- }
62
- const d = h.includes("&") ? u.replace("&", e) : u.startsWith(":") ? `${e}${u}` : `${e} ${u}`, b = O(r, d);
63
- return o.push(b), a;
64
- }
65
- const $ = u.startsWith("-") ? u : M(u), C = (d, b = ";") => a = `${a}${d}${b}`, k = (d) => C(`${$}:${d}`);
66
- if (typeof r == "number") return k(r);
67
- if (typeof r != "string")
68
- if ("toString" in r) r = r.toString();
69
- else return a;
70
- const { modifiers: l } = {}, T = function* () {
71
- yield q(r), yield yt(r, l);
72
- }();
73
- for (const { result: d, additionalCss: b = [] } of T)
74
- r = d, b.forEach((j) => {
75
- const c = O(j, "");
76
- C(c, "");
77
- });
78
- return k(r);
79
- }, "");
80
- if (!i) return o.join(`
81
- `);
82
- if (!e) return i;
83
- let g = "";
84
- return g = `${e} { ${i} }`, [g, ...o].join(`
85
- `);
86
- }, U = (t, e = []) => {
87
- if (!t) return "";
88
- const s = [], n = {};
89
- if (Object.entries(t).forEach(([o, i]) => {
90
- if (typeof i == "object") {
91
- if (!i) return;
92
- const g = o.trim(), a = U(i, [...e, g]);
93
- s.push(a);
94
- } else
95
- n[o] = i;
96
- }), Object.keys(n).length) {
97
- const o = e.map(M).join("-"), i = O(n, `.${o}`);
98
- s.push(i);
99
- }
100
- return s.join(`
101
- `);
102
- }, mt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = X(n).map((o) => `"${o}"`).join(" | ")), e), {}), X = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
103
- const i = e ? `${e}.${n}` : n;
104
- return typeof o == "object" ? X(o, i, s) : s.add(e);
105
- }), [...s]) : [], Y = (t) => {
106
- if (!t || t === "/") throw new Error("Could not find package.json file");
107
- const e = f(t, "package.json");
108
- return _(e) ? e : Y(f(t, ".."));
109
- }, ht = async (t) => {
110
- const e = Y(t);
111
- return await lt(e, "utf-8").then(JSON.parse).catch(() => {
112
- });
113
- }, $t = async (t) => {
114
- const e = await ht(t);
115
- if (e)
116
- return e.type;
117
- };
118
- let V;
119
- const Q = async (t) => {
120
- if (V) return V;
121
- const e = await $t(t);
122
- return e === "module" ? V = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (V = "cjs"), V || "esm";
123
- }, H = pt({
124
- level: "debug",
125
- format: Z.combine(Z.colorize(), Z.cli()),
126
- transports: [new ut.Console({})]
127
- });
128
- function v(t) {
129
- return t ? typeof t != "string" ? v(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
130
- }
131
- const R = {
132
- externalModules: []
133
- }, tt = (t) => {
134
- if (R.externalModules.length > 0) return R.externalModules;
135
- const e = f(t, "salty.config.ts"), n = N(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
136
- if (!n) return [];
137
- const o = n[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
138
- return R.externalModules = o, o;
139
- }, J = (t) => f(t, "./saltygen"), bt = ["salty", "css", "styles", "styled"], jt = (t = []) => new RegExp(`\\.(${[...bt, ...t].join("|")})\\.`), B = (t, e = []) => jt(e).test(t), wt = async (t) => {
140
- const e = J(t), s = f(t, "salty.config.ts"), n = f(e, "salty.config.js"), o = await Q(t), i = tt(t);
141
- await L.build({
142
- entryPoints: [s],
143
- minify: !0,
144
- treeShaking: !0,
145
- bundle: !0,
146
- outfile: n,
147
- format: o,
148
- external: i
149
- });
150
- const g = Date.now(), { config: a } = await import(`${n}?t=${g}`);
151
- return a;
152
- }, St = async (t) => {
153
- const e = await wt(t), s = /* @__PURE__ */ new Set(), n = (c, p = []) => c ? Object.entries(c).flatMap(([y, m]) => {
154
- if (!m) return;
155
- if (typeof m == "object") return n(m, [...p, y]);
156
- const F = v(y), w = M(y), S = [...p, F].join(".");
157
- s.add(`"${S}"`);
158
- const P = [...p.map(M), w].join("-"), { result: D } = q(m);
159
- return `--${P}: ${D};`;
160
- }) : [], o = (c) => c ? Object.entries(c).flatMap(([p, y]) => {
161
- const m = n(y);
162
- return p === "base" ? m.join("") : `${p} { ${m.join("")} }`;
163
- }) : [], i = (c) => c ? Object.entries(c).flatMap(([p, y]) => Object.entries(y).flatMap(([m, F]) => {
164
- const w = n(F, [p]), S = `.${p}-${m}, [data-${p}="${m}"]`, P = w.join("");
165
- return `${S} { ${P} }`;
166
- })) : [], g = n(e.variables), a = o(e.responsiveVariables), h = i(e.conditionalVariables), r = J(t), u = f(r, "css/variables.css"), $ = `:root { ${g.join("")} ${a.join("")} } ${h.join("")}`;
167
- E(u, $);
168
- const C = f(r, "css/global.css"), k = O(e.global, "");
169
- E(C, k);
170
- const l = f(r, "css/templates.css"), x = U(e.templates), T = mt(e.templates);
171
- E(l, x);
172
- const d = f(r, "types/css-tokens.d.ts"), j = `
173
- // Variable types
174
- type VariableTokens = ${[...s].join("|")};
175
- type PropertyValueToken = \`{\${VariableTokens}}\`;
176
-
177
- // Template types
178
- type TemplateTokens = {
179
- ${Object.entries(T).map(([c, p]) => `${c}?: ${p}`).join(`
180
- `)}
181
- }
182
- `;
183
- E(d, j);
184
- }, I = async (t, e, s) => {
185
- const n = W(e), o = f(s, "./temp");
186
- _(o) || A(o);
187
- const i = it(e);
188
- let g = N(e, "utf8");
189
- g = g.replace(/styled\([^"'`{,]+,/g, "styled('div',");
190
- const a = f(s, "js", n + ".js"), h = tt(t), r = await Q(t);
191
- await L.build({
192
- stdin: {
193
- contents: g,
194
- sourcefile: i.base,
195
- resolveDir: i.dir,
196
- loader: "tsx"
197
- },
198
- minify: !1,
199
- treeShaking: !0,
200
- bundle: !0,
201
- outfile: a,
202
- format: r,
203
- target: ["node20"],
204
- keepNames: !0,
205
- external: h,
206
- packages: "external"
207
- });
208
- const u = Date.now();
209
- return await import(`${a}?t=${u}`);
210
- }, z = async (t) => {
211
- const e = J(t), s = f(e, "salty.config.js"), { config: n } = await import(s);
212
- return n;
213
- }, et = () => {
214
- try {
215
- return process.env.NODE_ENV === "production";
216
- } catch {
217
- return !1;
218
- }
219
- }, Pt = async (t, e = et()) => {
220
- try {
221
- e ? H.info("Generating CSS in production mode! 🔥") : H.info("Generating CSS in development mode! 🚀");
222
- const s = [], n = [], o = J(t), i = f(o, "index.css");
223
- (() => {
224
- _(o) && rt("rm -rf " + o), A(o), A(f(o, "css")), A(f(o, "types"));
225
- })(), await St(t);
226
- const a = await z(t);
227
- async function h(l, x) {
228
- const T = ["node_modules", "saltygen"], d = ct(l);
229
- if (d.isDirectory()) {
230
- const b = at(l);
231
- if (T.some((c) => l.includes(c))) return;
232
- await Promise.all(b.map((c) => h(f(l, c), f(x, c))));
233
- } else if (d.isFile() && B(l)) {
234
- const j = await I(t, l, o), c = [];
235
- Object.entries(j).forEach(([F, w]) => {
236
- if (w.isKeyframes && w.css) {
237
- const K = `${w.animationName}.css`, nt = `css/${K}`, ot = f(o, nt);
238
- s.push(K), E(ot, w.css);
239
- return;
240
- }
241
- if (!w.generator) return;
242
- const S = w.generator._withBuildContext({
243
- name: F,
244
- config: a,
245
- prod: e
246
- }), P = `${S.hash}-${S.priority}.css`;
247
- n[S.priority] || (n[S.priority] = []), n[S.priority].push(P), c.push(P);
248
- const D = `css/${P}`, st = f(o, D);
249
- E(st, S.css);
250
- });
251
- const p = c.map((F) => `@import url('./${F}');`).join(`
252
- `), y = W(l, 6), m = f(o, `css/${y}.css`);
253
- E(m, p);
254
- }
255
- }
256
- await h(t, o);
257
- const r = s.map((l) => `@import url('./css/${l}');`).join(`
258
- `);
259
- let k = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
260
-
261
- ${["variables.css", "global.css", "templates.css"].filter((l) => {
262
- try {
263
- return N(f(o, "css", l), "utf8").length > 0;
264
- } catch {
265
- return !1;
266
- }
267
- }).map((l) => `@import url('./css/${l}');`).join(`
268
- `)}
269
- ${r}`;
270
- if (a.importStrategy !== "component") {
271
- const l = n.flat().map((x) => `@import url('./css/${x}');`).join(`
272
- `);
273
- k += l;
274
- }
275
- E(i, k);
276
- } catch (s) {
277
- console.error(s);
278
- }
279
- }, Et = async (t, e) => {
280
- try {
281
- const s = [], n = f(t, "./saltygen"), o = f(n, "index.css");
282
- if (B(e)) {
283
- const g = await z(t), a = await I(t, e, n);
284
- Object.entries(a).forEach(([C, k]) => {
285
- if (!k.generator) return;
286
- const l = k.generator._withBuildContext({
287
- name: C,
288
- config: g
289
- }), x = `${l.hash}-${l.priority}.css`, T = `css/${x}`, d = f(n, T);
290
- s.push(x), E(d, l.css);
291
- });
292
- const h = N(o, "utf8").split(`
293
- `), r = s.map((C) => `@import url('../saltygen/css/${C}');`), $ = [.../* @__PURE__ */ new Set([...h, ...r])].join(`
294
- `);
295
- E(o, $);
296
- }
297
- } catch (s) {
298
- console.error(s);
299
- }
300
- }, Dt = async (t, e, s = et()) => {
301
- try {
302
- const n = f(t, "./saltygen");
303
- if (B(e)) {
304
- const i = N(e, "utf8");
305
- i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await ft(e, i);
306
- const a = await z(t), h = await I(t, e, n);
307
- let r = i;
308
- Object.entries(h).forEach(([$, C]) => {
309
- var P;
310
- if (C.isKeyframes || !C.generator) return;
311
- const k = C.generator._withBuildContext({
312
- name: $,
313
- config: a,
314
- prod: s
315
- }), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
316
- if (!l) return console.error("Could not find the original declaration");
317
- const x = (P = l.at(1)) == null ? void 0 : P.trim(), T = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
318
- if (!T) return console.error("Could not find the original declaration");
319
- const { index: d } = T;
320
- let b = !1;
321
- const j = setTimeout(() => b = !0, 5e3);
322
- let c = 0, p = !1, y = 0;
323
- for (; !p && !b; ) {
324
- const D = r[d + c];
325
- D === "(" && y++, D === ")" && y--, y === 0 && D === ")" && (p = !0), c > r.length && (b = !0), c++;
326
- }
327
- if (!b) clearTimeout(j);
328
- else throw new Error("Failed to find the end of the styled call and timed out");
329
- const m = d + c, F = r.slice(d, m), w = r, S = ` ${$} = styled(${x}, "${k.classNames}", ${JSON.stringify(k.props)});`;
330
- r = r.replace(F, S), w === r && console.error("Minimize file failed to change content", { name: $, tagName: x });
331
- });
332
- const u = W(e, 6);
333
- return a.importStrategy === "component" && (r = `import '../../saltygen/css/${u}.css';
334
- ${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
335
- }
336
- } catch (n) {
337
- console.error("Error in minimizeFile:", n);
338
- }
339
- };
340
- export {
341
- Et as a,
342
- Pt as g,
343
- Dt as m,
344
- jt as s
345
- };