@salty-css/webpack 0.0.1-alpha.105 → 0.0.1-alpha.107

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