@salty-css/webpack 0.0.1-alpha.57 → 0.0.1-alpha.59

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,277 @@
1
+ import * as Z from "esbuild";
2
+ import { execSync as L } from "child_process";
3
+ import { join as u } from "path";
4
+ import { writeFileSync as T, readFileSync as M, existsSync as U, mkdirSync as V, statSync as X, readdirSync as Y } from "fs";
5
+ import { writeFile as Q } from "fs/promises";
6
+ const I = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), v = (t, s) => {
7
+ let e = "", n;
8
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = I(n % 52) + e;
9
+ return e = I(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
10
+ }, tt = (t, s) => {
11
+ let e = s.length;
12
+ for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
13
+ return t;
14
+ }, A = (t, s = 3) => {
15
+ const e = tt(5381, JSON.stringify(t)) >>> 0;
16
+ return v(e, s);
17
+ };
18
+ function E(t) {
19
+ return t ? typeof t != "string" ? E(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
20
+ }
21
+ const st = (t, s) => {
22
+ if (typeof t != "string") return { result: t };
23
+ if (!s) return { result: t };
24
+ const e = [];
25
+ return Object.values(s).forEach((n) => {
26
+ const { pattern: o, transform: y } = n;
27
+ t = t.replace(o, (g) => {
28
+ const { value: p, css: c } = y(g);
29
+ return c && e.push(c), p;
30
+ });
31
+ }), { result: t, additionalCss: e };
32
+ }, z = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${E(n[1].replaceAll(".", "-"))})`) } : { result: t }, P = (t, s, e, n) => {
33
+ if (!t) return "";
34
+ const o = [], y = Object.entries(t).reduce((p, [c, r]) => {
35
+ const l = c.trim();
36
+ if (typeof r == "function" && (r = r()), typeof r == "object") {
37
+ if (!r) return p;
38
+ if (l === "variants")
39
+ return Object.entries(r).forEach(([i, f]) => {
40
+ f && Object.entries(f).forEach(([h, d]) => {
41
+ if (!d) return;
42
+ const w = `${s}.${i}-${h}`, $ = P(d, w);
43
+ o.push($);
44
+ });
45
+ }), p;
46
+ if (l === "defaultVariants")
47
+ return p;
48
+ if (l === "compoundVariants")
49
+ return r.forEach((i) => {
50
+ const { css: f, ...h } = i, d = Object.entries(h).reduce(($, [S, D]) => `${$}.${S}-${D}`, s), w = P(f, d);
51
+ o.push(w);
52
+ }), p;
53
+ if (l.startsWith("@")) {
54
+ const i = P(r, s), f = `${l} {
55
+ ${i.replace(`
56
+ `, `
57
+ `)}
58
+ }`;
59
+ return o.push(f), p;
60
+ }
61
+ const m = c.includes("&") ? l.replace("&", s) : l.startsWith(":") ? `${s}${l}` : `${s} ${l}`, C = P(r, m);
62
+ return o.push(C), p;
63
+ }
64
+ const k = l.startsWith("-") ? l : E(l), b = (m, C = ";") => p = `${p}${m}${C}`, a = (m) => b(`${k}:${m}`);
65
+ if (typeof r == "number") return a(r);
66
+ if (typeof r != "string")
67
+ if ("toString" in r) r = r.toString();
68
+ else return p;
69
+ const { modifiers: j } = {}, F = function* () {
70
+ yield z(r), yield st(r, j);
71
+ }();
72
+ for (const { result: m, additionalCss: C = [] } of F)
73
+ r = m, C.forEach((i) => {
74
+ const f = P(i, "");
75
+ b(f, "");
76
+ });
77
+ return a(r);
78
+ }, "");
79
+ if (!y) return o.join(`
80
+ `);
81
+ if (!s) return y;
82
+ let g = "";
83
+ return g = `${s} { ${y} }`, [g, ...o].join(`
84
+ `);
85
+ }, H = (t, s = []) => {
86
+ if (!t) return "";
87
+ const e = [], n = {};
88
+ if (Object.entries(t).forEach(([o, y]) => {
89
+ if (typeof y == "object") {
90
+ if (!y) return;
91
+ const g = o.trim(), p = H(y, [...s, g]);
92
+ e.push(p);
93
+ } else
94
+ n[o] = y;
95
+ }), Object.keys(n).length) {
96
+ const o = s.map(E).join("-"), y = P(n, `.${o}`);
97
+ e.push(y);
98
+ }
99
+ return e.join(`
100
+ `);
101
+ }, J = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", O = (t) => u(t, "./saltygen"), et = ["salty", "css", "styles", "styled"], nt = (t = []) => new RegExp(`\\.(${[...et, ...t].join("|")})\\.`), R = (t, s = []) => nt(s).test(t), ot = async (t) => {
102
+ const s = O(t), e = u(t, "salty.config.ts"), n = u(s, "salty.config.js"), o = J();
103
+ console.log("Module type:", o), await Z.build({
104
+ entryPoints: [e],
105
+ minify: !0,
106
+ treeShaking: !0,
107
+ bundle: !0,
108
+ outfile: n,
109
+ format: o
110
+ // external: ['react'],
111
+ });
112
+ const y = Date.now(), { config: g } = await import(`${n}?t=${y}`);
113
+ return g;
114
+ }, rt = async (t) => {
115
+ const s = await ot(t), e = /* @__PURE__ */ new Set(), n = (i, f = []) => i ? Object.entries(i).flatMap(([h, d]) => {
116
+ if (!d) return;
117
+ if (typeof d == "object") return n(d, [...f, h]);
118
+ const w = [...f, h].join(".");
119
+ e.add(`"${w}"`);
120
+ const $ = [...f.map(E), E(h)].join("-"), { result: S } = z(d);
121
+ return `--${$}: ${S};`;
122
+ }) : [], o = (i) => i ? Object.entries(i).flatMap(([f, h]) => {
123
+ const d = n(h);
124
+ return f === "base" ? d.join("") : `${f} { ${d.join("")} }`;
125
+ }) : [], y = (i) => i ? Object.entries(i).flatMap(([f, h]) => Object.entries(h).flatMap(([d, w]) => {
126
+ const $ = n(w, [f]), S = `.${f}-${d}, [data-${f}="${d}"]`, D = $.join("");
127
+ return `${S} { ${D} }`;
128
+ })) : [], g = n(s.variables), p = o(s.responsiveVariables), c = y(s.conditionalVariables), r = O(t), l = u(r, "css/variables.css"), k = `:root { ${g.join("")} ${p.join("")} } ${c.join("")}`;
129
+ T(l, k);
130
+ const b = u(r, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
131
+ T(b, j);
132
+ const x = u(r, "css/global.css"), F = P(s.global, "");
133
+ T(x, F);
134
+ const m = u(r, "css/templates.css"), C = H(s.templates);
135
+ T(m, C);
136
+ }, _ = async (t, s) => {
137
+ const e = A(t), n = u(s, "js", e + ".js"), o = J();
138
+ console.log("Module type:", o), await Z.build({
139
+ entryPoints: [t],
140
+ minify: !0,
141
+ treeShaking: !0,
142
+ bundle: !0,
143
+ outfile: n,
144
+ format: o,
145
+ target: ["es2022"],
146
+ keepNames: !0
147
+ // external: ['react'],
148
+ });
149
+ const y = Date.now();
150
+ return await import(`${n}?t=${y}`);
151
+ }, W = async (t) => {
152
+ const s = O(t), e = u(s, "salty.config.js"), { config: n } = await import(e);
153
+ return n;
154
+ }, ft = async (t) => {
155
+ try {
156
+ const s = [], e = [], n = O(t), o = u(n, "index.css");
157
+ (() => {
158
+ U(n) && L("rm -rf " + n), V(n), V(u(n, "css")), V(u(n, "types"));
159
+ })(), await rt(t);
160
+ const g = await W(t);
161
+ async function p(a, j) {
162
+ const x = ["node_modules", "saltygen"], F = X(a);
163
+ if (F.isDirectory()) {
164
+ const m = Y(a);
165
+ if (x.some((i) => a.includes(i))) return;
166
+ await Promise.all(m.map((i) => p(u(a, i), u(j, i))));
167
+ } else if (F.isFile() && R(a)) {
168
+ const C = await _(a, n), i = [];
169
+ Object.entries(C).forEach(([w, $]) => {
170
+ if ($.isKeyframes && $.css) {
171
+ const B = `${$.animationName}.css`, q = `css/${B}`, G = u(n, q);
172
+ s.push(B), T(G, $.css);
173
+ return;
174
+ }
175
+ if (!$.generator) return;
176
+ const S = $.generator._withBuildContext({
177
+ name: w,
178
+ config: g
179
+ }), D = `${S.hash}-${S.priority}.css`;
180
+ e[S.priority] || (e[S.priority] = []), e[S.priority].push(D), i.push(D);
181
+ const N = `css/${D}`, K = u(n, N);
182
+ T(K, S.css);
183
+ });
184
+ const f = i.map((w) => `@import url('./${w}');`).join(`
185
+ `), h = A(a, 6), d = u(n, `css/${h}.css`);
186
+ T(d, f);
187
+ }
188
+ }
189
+ await p(t, n);
190
+ const c = s.map((a) => `@import url('./css/${a}');`).join(`
191
+ `);
192
+ let b = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
193
+
194
+ ${["variables.css", "global.css", "templates.css"].filter((a) => {
195
+ try {
196
+ return M(u(n, "css", a), "utf8").length > 0;
197
+ } catch {
198
+ return !1;
199
+ }
200
+ }).map((a) => `@import url('./css/${a}');`).join(`
201
+ `)}
202
+ ${c}`;
203
+ if (g.importStrategy !== "component") {
204
+ const a = e.flat().map((j) => `@import url('./css/${j}');`).join(`
205
+ `);
206
+ b += a;
207
+ }
208
+ T(o, b);
209
+ } catch (s) {
210
+ console.error(s);
211
+ }
212
+ }, pt = async (t, s) => {
213
+ try {
214
+ const e = [], n = u(t, "./saltygen"), o = u(n, "index.css");
215
+ if (R(s)) {
216
+ const g = await W(t), p = await _(s, n);
217
+ Object.entries(p).forEach(([b, a]) => {
218
+ if (!a.generator) return;
219
+ const j = a.generator._withBuildContext({
220
+ name: b,
221
+ config: g
222
+ }), x = `${j.hash}-${j.priority}.css`, F = `css/${x}`, m = u(n, F);
223
+ e.push(x), T(m, j.css);
224
+ });
225
+ const c = M(o, "utf8").split(`
226
+ `), r = e.map((b) => `@import url('../saltygen/css/${b}');`), k = [.../* @__PURE__ */ new Set([...c, ...r])].join(`
227
+ `);
228
+ T(o, k);
229
+ }
230
+ } catch (e) {
231
+ console.error(e);
232
+ }
233
+ }, ut = async (t, s) => {
234
+ try {
235
+ const e = u(t, "./saltygen");
236
+ if (R(s)) {
237
+ const o = M(s, "utf8");
238
+ o.replace(/^(?!export\s)const\s.*/gm, (l) => `export ${l}`) !== o && await Q(s, o);
239
+ const g = await W(t), p = await _(s, e);
240
+ let c = o;
241
+ Object.entries(p).forEach(([l, k]) => {
242
+ var D;
243
+ if (k.isKeyframes || !k.generator) return;
244
+ const b = k.generator._withBuildContext({
245
+ name: l,
246
+ config: g
247
+ }), a = new RegExp(`\\s${l}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
248
+ if (!a) return console.error("Could not find the original declaration");
249
+ const j = (D = a.at(1)) == null ? void 0 : D.trim(), x = new RegExp(`\\s${l}[=\\s]+styled\\(`, "g").exec(c);
250
+ if (!x) return console.error("Could not find the original declaration");
251
+ const { index: F } = x;
252
+ let m = !1;
253
+ const C = setTimeout(() => m = !0, 5e3);
254
+ let i = 0, f = !1, h = 0;
255
+ for (; !f && !m; ) {
256
+ const N = c[F + i];
257
+ N === "(" && h++, N === ")" && h--, h === 0 && N === ")" && (f = !0), i > c.length && (m = !0), i++;
258
+ }
259
+ if (!m) clearTimeout(C);
260
+ else throw new Error("Failed to find the end of the styled call and timed out");
261
+ const d = F + i, w = c.slice(F, d), $ = c, S = ` ${l} = styled(${j}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
262
+ c = c.replace(w, S), $ === c && console.error("Minimize file failed to change content", { name: l, tagName: j });
263
+ });
264
+ const r = A(s, 6);
265
+ return g.importStrategy === "component" && (c = `import '../../saltygen/css/${r}.css';
266
+ ${c}`), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
267
+ }
268
+ } catch (e) {
269
+ console.error("Error in minimizeFile:", e);
270
+ }
271
+ };
272
+ export {
273
+ pt as a,
274
+ ft as g,
275
+ ut as m,
276
+ nt as s
277
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";const K=require("esbuild"),G=require("child_process"),p=require("path"),h=require("fs"),X=require("fs/promises");var V=typeof document<"u"?document.currentScript:null;function Y(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 W=Y(K),I=t=>String.fromCharCode(t+(t>25?39:97)),Q=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=I(n%52)+s;return s=I(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},v=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},_=(t,e=3)=>{const s=v(5381,JSON.stringify(t))>>>0;return Q(s,e)};function P(t){return t?typeof t!="string"?P(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 tt=(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:y}=n;t=t.replace(o,d=>{const{value:u,css:c}=y(d);return c&&s.push(c),u})}),{result:t,additionalCss:s}},z=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${P(n[1].replaceAll(".","-"))})`)}:{result:t},O=(t,e,s,n)=>{if(!t)return"";const o=[],y=Object.entries(t).reduce((u,[c,r])=>{const l=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return u;if(l==="variants")return Object.entries(r).forEach(([i,f])=>{f&&Object.entries(f).forEach(([$,m])=>{if(!m)return;const F=`${e}.${i}-${$}`,j=O(m,F);o.push(j)})}),u;if(l==="defaultVariants")return u;if(l==="compoundVariants")return r.forEach(i=>{const{css:f,...$}=i,m=Object.entries($).reduce((j,[w,D])=>`${j}.${w}-${D}`,e),F=O(f,m);o.push(F)}),u;if(l.startsWith("@")){const i=O(r,e),f=`${l} {
2
+ ${i.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return o.push(f),u}const g=c.includes("&")?l.replace("&",e):l.startsWith(":")?`${e}${l}`:`${e} ${l}`,k=O(r,g);return o.push(k),u}const T=l.startsWith("-")?l:P(l),b=(g,k=";")=>u=`${u}${g}${k}`,a=g=>b(`${T}:${g}`);if(typeof r=="number")return a(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return u;const{modifiers:S}={},C=function*(){yield z(r),yield tt(r,S)}();for(const{result:g,additionalCss:k=[]}of C)r=g,k.forEach(i=>{const f=O(i,"");b(f,"")});return a(r)},"");if(!y)return o.join(`
6
+ `);if(!e)return y;let d="";return d=`${e} { ${y} }`,[d,...o].join(`
7
+ `)},B=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,y])=>{if(typeof y=="object"){if(!y)return;const d=o.trim(),u=B(y,[...e,d]);s.push(u)}else n[o]=y}),Object.keys(n).length){const o=e.map(P).join("-"),y=O(n,`.${o}`);s.push(y)}return s.join(`
8
+ `)},Z=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:V&&V.tagName.toUpperCase()==="SCRIPT"&&V.src||new URL("index-DjRQPC8x.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",E=t=>p.join(t,"./saltygen"),et=["salty","css","styles","styled"],U=(t=[])=>new RegExp(`\\.(${[...et,...t].join("|")})\\.`),R=(t,e=[])=>U(e).test(t),st=async t=>{const e=E(t),s=p.join(t,"salty.config.ts"),n=p.join(e,"salty.config.js"),o=Z();console.log("Module type:",o),await W.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o});const y=Date.now(),{config:d}=await import(`${n}?t=${y}`);return d},nt=async t=>{const e=await st(t),s=new Set,n=(i,f=[])=>i?Object.entries(i).flatMap(([$,m])=>{if(!m)return;if(typeof m=="object")return n(m,[...f,$]);const F=[...f,$].join(".");s.add(`"${F}"`);const j=[...f.map(P),P($)].join("-"),{result:w}=z(m);return`--${j}: ${w};`}):[],o=i=>i?Object.entries(i).flatMap(([f,$])=>{const m=n($);return f==="base"?m.join(""):`${f} { ${m.join("")} }`}):[],y=i=>i?Object.entries(i).flatMap(([f,$])=>Object.entries($).flatMap(([m,F])=>{const j=n(F,[f]),w=`.${f}-${m}, [data-${f}="${m}"]`,D=j.join("");return`${w} { ${D} }`})):[],d=n(e.variables),u=o(e.responsiveVariables),c=y(e.conditionalVariables),r=E(t),l=p.join(r,"css/variables.css"),T=`:root { ${d.join("")} ${u.join("")} } ${c.join("")}`;h.writeFileSync(l,T);const b=p.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;h.writeFileSync(b,S);const x=p.join(r,"css/global.css"),C=O(e.global,"");h.writeFileSync(x,C);const g=p.join(r,"css/templates.css"),k=B(e.templates);h.writeFileSync(g,k)},M=async(t,e)=>{const s=_(t),n=p.join(e,"js",s+".js"),o=Z();console.log("Module type:",o),await W.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,target:["es2022"],keepNames:!0});const y=Date.now();return await import(`${n}?t=${y}`)},A=async t=>{const e=E(t),s=p.join(e,"salty.config.js"),{config:n}=await import(s);return n},ot=async t=>{try{const e=[],s=[],n=E(t),o=p.join(n,"index.css");(()=>{h.existsSync(n)&&G.execSync("rm -rf "+n),h.mkdirSync(n),h.mkdirSync(p.join(n,"css")),h.mkdirSync(p.join(n,"types"))})(),await nt(t);const d=await A(t);async function u(a,S){const x=["node_modules","saltygen"],C=h.statSync(a);if(C.isDirectory()){const g=h.readdirSync(a);if(x.some(i=>a.includes(i)))return;await Promise.all(g.map(i=>u(p.join(a,i),p.join(S,i))))}else if(C.isFile()&&R(a)){const k=await M(a,n),i=[];Object.entries(k).forEach(([F,j])=>{if(j.isKeyframes&&j.css){const q=`${j.animationName}.css`,L=`css/${q}`,J=p.join(n,L);e.push(q),h.writeFileSync(J,j.css);return}if(!j.generator)return;const w=j.generator._withBuildContext({name:F,config:d}),D=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(D),i.push(D);const N=`css/${D}`,H=p.join(n,N);h.writeFileSync(H,w.css)});const f=i.map(F=>`@import url('./${F}');`).join(`
9
+ `),$=_(a,6),m=p.join(n,`css/${$}.css`);h.writeFileSync(m,f)}}await u(t,n);const c=e.map(a=>`@import url('./css/${a}');`).join(`
10
+ `);let b=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
+
12
+ ${["variables.css","global.css","templates.css"].filter(a=>{try{return h.readFileSync(p.join(n,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
13
+ `)}
14
+ ${c}`;if(d.importStrategy!=="component"){const a=s.flat().map(S=>`@import url('./css/${S}');`).join(`
15
+ `);b+=a}h.writeFileSync(o,b)}catch(e){console.error(e)}},rt=async(t,e)=>{try{const s=[],n=p.join(t,"./saltygen"),o=p.join(n,"index.css");if(R(e)){const d=await A(t),u=await M(e,n);Object.entries(u).forEach(([b,a])=>{if(!a.generator)return;const S=a.generator._withBuildContext({name:b,config:d}),x=`${S.hash}-${S.priority}.css`,C=`css/${x}`,g=p.join(n,C);s.push(x),h.writeFileSync(g,S.css)});const c=h.readFileSync(o,"utf8").split(`
16
+ `),r=s.map(b=>`@import url('../saltygen/css/${b}');`),T=[...new Set([...c,...r])].join(`
17
+ `);h.writeFileSync(o,T)}}catch(s){console.error(s)}},it=async(t,e)=>{try{const s=p.join(t,"./saltygen");if(R(e)){const o=h.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,l=>`export ${l}`)!==o&&await X.writeFile(e,o);const d=await A(t),u=await M(e,s);let c=o;Object.entries(u).forEach(([l,T])=>{var D;if(T.isKeyframes||!T.generator)return;const b=T.generator._withBuildContext({name:l,config:d}),a=new RegExp(`\\s${l}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!a)return console.error("Could not find the original declaration");const S=(D=a.at(1))==null?void 0:D.trim(),x=new RegExp(`\\s${l}[=\\s]+styled\\(`,"g").exec(c);if(!x)return console.error("Could not find the original declaration");const{index:C}=x;let g=!1;const k=setTimeout(()=>g=!0,5e3);let i=0,f=!1,$=0;for(;!f&&!g;){const N=c[C+i];N==="("&&$++,N===")"&&$--,$===0&&N===")"&&(f=!0),i>c.length&&(g=!0),i++}if(!g)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const m=C+i,F=c.slice(C,m),j=c,w=` ${l} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(F,w),j===c&&console.error("Minimize file failed to change content",{name:l,tagName:S})});const r=_(e,6);return d.importStrategy==="component"&&(c=`import '../../saltygen/css/${r}.css';
18
+ ${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}};exports.generateCss=ot;exports.generateFile=rt;exports.minimizeFile=it;exports.saltyFileRegExp=U;
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-DhU0Pd7j.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-DjRQPC8x.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-DWyV4v3e.js";
2
+ import { s as u, g as i } from "./index-DTnJCqDC.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-DhU0Pd7j.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-DjRQPC8x.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-DWyV4v3e.js";
1
+ import { a as e, m as i } from "./index-DTnJCqDC.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.57",
3
+ "version": "0.0.1-alpha.59",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@salty-css/core": "^0.0.1-alpha.57",
32
+ "@salty-css/core": "^0.0.1-alpha.59",
33
33
  "webpack": ">=5.x"
34
34
  }
35
35
  }
package/index-DWyV4v3e.js DELETED
@@ -1,277 +0,0 @@
1
- import * as Z from "esbuild";
2
- import { execSync as G } from "child_process";
3
- import { join as u } from "path";
4
- import { writeFileSync as P, readFileSync as A, existsSync as L, mkdirSync as V, statSync as U, readdirSync as X } from "fs";
5
- import { writeFile as Y } from "fs/promises";
6
- const W = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Q = (t, s) => {
7
- let e = "", n;
8
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = W(n % 52) + e;
9
- return e = W(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
10
- }, v = (t, s) => {
11
- let e = s.length;
12
- for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
13
- return t;
14
- }, M = (t, s = 3) => {
15
- const e = v(5381, JSON.stringify(t)) >>> 0;
16
- return Q(e, s);
17
- };
18
- function N(t) {
19
- return t ? typeof t != "string" ? N(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
20
- }
21
- const tt = (t, s) => {
22
- if (typeof t != "string") return { result: t };
23
- if (!s) return { result: t };
24
- const e = [];
25
- return Object.values(s).forEach((n) => {
26
- const { pattern: r, transform: g } = n;
27
- t = t.replace(r, (h) => {
28
- const { value: p, css: c } = g(h);
29
- return c && e.push(c), p;
30
- });
31
- }), { result: t, additionalCss: e };
32
- }, z = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${N(n[1].replaceAll(".", "-"))})`) } : { result: t }, E = (t, s, e, n) => {
33
- if (!t) return "";
34
- const r = [], g = Object.entries(t).reduce((p, [c, o]) => {
35
- const l = c.trim();
36
- if (typeof o == "function" && (o = o()), typeof o == "object") {
37
- if (!o) return p;
38
- if (l === "variants")
39
- return Object.entries(o).forEach(([i, f]) => {
40
- f && Object.entries(f).forEach(([d, m]) => {
41
- if (!m) return;
42
- const w = `${s}.${i}-${d}`, $ = E(m, w);
43
- r.push($);
44
- });
45
- }), p;
46
- if (l === "defaultVariants")
47
- return p;
48
- if (l === "compoundVariants")
49
- return o.forEach((i) => {
50
- const { css: f, ...d } = i, m = Object.entries(d).reduce(($, [j, D]) => `${$}.${j}-${D}`, s), w = E(f, m);
51
- r.push(w);
52
- }), p;
53
- if (l.startsWith("@")) {
54
- const i = E(o, s), f = `${l} {
55
- ${i.replace(`
56
- `, `
57
- `)}
58
- }`;
59
- return r.push(f), p;
60
- }
61
- const y = c.includes("&") ? l.replace("&", s) : l.startsWith(":") ? `${s}${l}` : `${s} ${l}`, C = E(o, y);
62
- return r.push(C), p;
63
- }
64
- const x = l.startsWith("-") ? l : N(l), b = (y, C = ";") => p = `${p}${y}${C}`, a = (y) => b(`${x}:${y}`);
65
- if (typeof o == "number") return a(o);
66
- if (typeof o != "string")
67
- if ("toString" in o) o = o.toString();
68
- else return p;
69
- const { modifiers: S } = {}, F = function* () {
70
- yield z(o), yield tt(o, S);
71
- }();
72
- for (const { result: y, additionalCss: C = [] } of F)
73
- o = y, C.forEach((i) => {
74
- const f = E(i, "");
75
- b(f, "");
76
- });
77
- return a(o);
78
- }, "");
79
- if (!g) return r.join(`
80
- `);
81
- if (!s) return g;
82
- let h = "";
83
- return h = `${s} { ${g} }`, [h, ...r].join(`
84
- `);
85
- }, H = (t, s = []) => {
86
- if (!t) return "";
87
- const e = [], n = {};
88
- if (Object.entries(t).forEach(([r, g]) => {
89
- if (typeof g == "object") {
90
- if (!g) return;
91
- const h = r.trim(), p = H(g, [...s, h]);
92
- e.push(p);
93
- } else
94
- n[r] = g;
95
- }), Object.keys(n).length) {
96
- const r = s.map(N).join("-"), g = E(n, `.${r}`);
97
- e.push(g);
98
- }
99
- return e.join(`
100
- `);
101
- }, T = (t) => u(t, "./saltygen"), st = ["salty", "css", "styles", "styled"], et = (t = []) => new RegExp(`\\.(${[...st, ...t].join("|")})\\.`), R = (t, s = []) => et(s).test(t), nt = async (t) => {
102
- const s = T(t), e = u(t, "salty.config.ts"), n = u(s, "salty.config.js");
103
- await Z.build({
104
- entryPoints: [e],
105
- minify: !0,
106
- treeShaking: !0,
107
- bundle: !0,
108
- outfile: n,
109
- format: "esm",
110
- external: ["react"]
111
- });
112
- const r = Date.now(), { config: g } = await import(`${n}?t=${r}`);
113
- return g;
114
- }, rt = async (t) => {
115
- const s = await nt(t), e = /* @__PURE__ */ new Set(), n = (i, f = []) => i ? Object.entries(i).flatMap(([d, m]) => {
116
- if (!m) return;
117
- if (typeof m == "object") return n(m, [...f, d]);
118
- const w = [...f, d].join(".");
119
- e.add(`"${w}"`);
120
- const $ = [...f.map(N), N(d)].join("-"), { result: j } = z(m);
121
- return `--${$}: ${j};`;
122
- }) : [], r = (i) => i ? Object.entries(i).flatMap(([f, d]) => {
123
- const m = n(d);
124
- return f === "base" ? m.join("") : `${f} { ${m.join("")} }`;
125
- }) : [], g = (i) => i ? Object.entries(i).flatMap(([f, d]) => Object.entries(d).flatMap(([m, w]) => {
126
- const $ = n(w, [f]), j = `.${f}-${m}, [data-${f}="${m}"]`, D = $.join("");
127
- return `${j} { ${D} }`;
128
- })) : [], h = n(s.variables), p = r(s.responsiveVariables), c = g(s.conditionalVariables), o = T(t), l = u(o, "css/variables.css"), x = `:root { ${h.join("")} ${p.join("")} } ${c.join("")}`;
129
- P(l, x);
130
- const b = u(o, "types/css-tokens.d.ts"), S = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
131
- P(b, S);
132
- const k = u(o, "css/global.css"), F = E(s.global, "");
133
- P(k, F);
134
- const y = u(o, "css/templates.css"), C = H(s.templates);
135
- P(y, C);
136
- }, _ = async (t, s) => {
137
- const e = M(t), n = u(s, "js", e + ".js");
138
- await Z.build({
139
- entryPoints: [t],
140
- minify: !0,
141
- treeShaking: !0,
142
- bundle: !0,
143
- outfile: n,
144
- format: "esm",
145
- target: ["es2022"],
146
- keepNames: !0,
147
- external: ["react"]
148
- });
149
- const r = Date.now();
150
- return await import(`${n}?t=${r}`);
151
- }, B = async (t) => {
152
- const s = T(t), e = u(s, "salty.config.js"), { config: n } = await import(e);
153
- return n;
154
- }, lt = async (t) => {
155
- try {
156
- const s = [], e = [], n = T(t), r = u(n, "index.css");
157
- (() => {
158
- L(n) && G("rm -rf " + n), V(n), V(u(n, "css")), V(u(n, "types"));
159
- })(), await rt(t);
160
- const h = await B(t);
161
- async function p(a, S) {
162
- const k = ["node_modules", "saltygen"], F = U(a);
163
- if (F.isDirectory()) {
164
- const y = X(a);
165
- if (k.some((i) => a.includes(i))) return;
166
- await Promise.all(y.map((i) => p(u(a, i), u(S, i))));
167
- } else if (F.isFile() && R(a)) {
168
- const C = await _(a, n), i = [];
169
- Object.entries(C).forEach(([w, $]) => {
170
- if ($.isKeyframes && $.css) {
171
- const I = `${$.animationName}.css`, K = `css/${I}`, q = u(n, K);
172
- s.push(I), P(q, $.css);
173
- return;
174
- }
175
- if (!$.generator) return;
176
- const j = $.generator._withBuildContext({
177
- name: w,
178
- config: h
179
- }), D = `${j.hash}-${j.priority}.css`;
180
- e[j.priority] || (e[j.priority] = []), e[j.priority].push(D), i.push(D);
181
- const O = `css/${D}`, J = u(n, O);
182
- P(J, j.css);
183
- });
184
- const f = i.map((w) => `@import url('./${w}');`).join(`
185
- `), d = M(a, 6), m = u(n, `css/${d}.css`);
186
- P(m, f);
187
- }
188
- }
189
- await p(t, n);
190
- const c = s.map((a) => `@import url('./css/${a}');`).join(`
191
- `);
192
- let b = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
193
-
194
- ${["variables.css", "global.css", "templates.css"].filter((a) => {
195
- try {
196
- return A(u(n, "css", a), "utf8").length > 0;
197
- } catch {
198
- return !1;
199
- }
200
- }).map((a) => `@import url('./css/${a}');`).join(`
201
- `)}
202
- ${c}`;
203
- if (h.importStrategy !== "component") {
204
- const a = e.flat().map((S) => `@import url('./css/${S}');`).join(`
205
- `);
206
- b += a;
207
- }
208
- P(r, b);
209
- } catch (s) {
210
- console.error(s);
211
- }
212
- }, ft = async (t, s) => {
213
- try {
214
- const e = [], n = u(t, "./saltygen"), r = u(n, "index.css");
215
- if (R(s)) {
216
- const h = await B(t), p = await _(s, n);
217
- Object.entries(p).forEach(([b, a]) => {
218
- if (!a.generator) return;
219
- const S = a.generator._withBuildContext({
220
- name: b,
221
- config: h
222
- }), k = `${S.hash}-${S.priority}.css`, F = `css/${k}`, y = u(n, F);
223
- e.push(k), P(y, S.css);
224
- });
225
- const c = A(r, "utf8").split(`
226
- `), o = e.map((b) => `@import url('../saltygen/css/${b}');`), x = [.../* @__PURE__ */ new Set([...c, ...o])].join(`
227
- `);
228
- P(r, x);
229
- }
230
- } catch (e) {
231
- console.error(e);
232
- }
233
- }, pt = async (t, s) => {
234
- try {
235
- const e = u(t, "./saltygen");
236
- if (R(s)) {
237
- const r = A(s, "utf8");
238
- r.replace(/^(?!export\s)const\s.*/gm, (l) => `export ${l}`) !== r && await Y(s, r);
239
- const h = await B(t), p = await _(s, e);
240
- let c = r;
241
- Object.entries(p).forEach(([l, x]) => {
242
- var D;
243
- if (x.isKeyframes || !x.generator) return;
244
- const b = x.generator._withBuildContext({
245
- name: l,
246
- config: h
247
- }), a = new RegExp(`\\s${l}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
248
- if (!a) return console.error("Could not find the original declaration");
249
- const S = (D = a.at(1)) == null ? void 0 : D.trim(), k = new RegExp(`\\s${l}[=\\s]+styled\\(`, "g").exec(c);
250
- if (!k) return console.error("Could not find the original declaration");
251
- const { index: F } = k;
252
- let y = !1;
253
- const C = setTimeout(() => y = !0, 5e3);
254
- let i = 0, f = !1, d = 0;
255
- for (; !f && !y; ) {
256
- const O = c[F + i];
257
- O === "(" && d++, O === ")" && d--, d === 0 && O === ")" && (f = !0), i > c.length && (y = !0), i++;
258
- }
259
- if (!y) clearTimeout(C);
260
- else throw new Error("Failed to find the end of the styled call and timed out");
261
- const m = F + i, w = c.slice(F, m), $ = c, j = ` ${l} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
262
- c = c.replace(w, j), $ === c && console.error("Minimize file failed to change content", { name: l, tagName: S });
263
- });
264
- const o = M(s, 6);
265
- return h.importStrategy === "component" && (c = `import '../../saltygen/css/${o}.css';
266
- ${c}`), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
267
- }
268
- } catch (e) {
269
- console.error("Error in minimizeFile:", e);
270
- }
271
- };
272
- export {
273
- ft as a,
274
- lt as g,
275
- pt as m,
276
- et as s
277
- };
@@ -1,18 +0,0 @@
1
- "use strict";const K=require("esbuild"),G=require("child_process"),u=require("path"),m=require("fs"),L=require("fs/promises");function U(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 z=U(K),q=t=>String.fromCharCode(t+(t>25?39:97)),X=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=q(n%52)+s;return s=q(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Y=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},V=(t,e=3)=>{const s=Y(5381,JSON.stringify(t))>>>0;return X(s,e)};function E(t){return t?typeof t!="string"?E(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 Q=(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:y}=n;t=t.replace(r,$=>{const{value:p,css:c}=y($);return c&&s.push(c),p})}),{result:t,additionalCss:s}},B=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:t},P=(t,e,s,n)=>{if(!t)return"";const r=[],y=Object.entries(t).reduce((p,[c,o])=>{const l=c.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return p;if(l==="variants")return Object.entries(o).forEach(([i,f])=>{f&&Object.entries(f).forEach(([h,d])=>{if(!d)return;const F=`${e}.${i}-${h}`,b=P(d,F);r.push(b)})}),p;if(l==="defaultVariants")return p;if(l==="compoundVariants")return o.forEach(i=>{const{css:f,...h}=i,d=Object.entries(h).reduce((b,[w,O])=>`${b}.${w}-${O}`,e),F=P(f,d);r.push(F)}),p;if(l.startsWith("@")){const i=P(o,e),f=`${l} {
2
- ${i.replace(`
3
- `,`
4
- `)}
5
- }`;return r.push(f),p}const g=c.includes("&")?l.replace("&",e):l.startsWith(":")?`${e}${l}`:`${e} ${l}`,k=P(o,g);return r.push(k),p}const x=l.startsWith("-")?l:E(l),j=(g,k=";")=>p=`${p}${g}${k}`,a=g=>j(`${x}:${g}`);if(typeof o=="number")return a(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return p;const{modifiers:S}={},C=function*(){yield B(o),yield Q(o,S)}();for(const{result:g,additionalCss:k=[]}of C)o=g,k.forEach(i=>{const f=P(i,"");j(f,"")});return a(o)},"");if(!y)return r.join(`
6
- `);if(!e)return y;let $="";return $=`${e} { ${y} }`,[$,...r].join(`
7
- `)},I=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,y])=>{if(typeof y=="object"){if(!y)return;const $=r.trim(),p=I(y,[...e,$]);s.push(p)}else n[r]=y}),Object.keys(n).length){const r=e.map(E).join("-"),y=P(n,`.${r}`);s.push(y)}return s.join(`
8
- `)},T=t=>u.join(t,"./saltygen"),v=["salty","css","styles","styled"],W=(t=[])=>new RegExp(`\\.(${[...v,...t].join("|")})\\.`),_=(t,e=[])=>W(e).test(t),tt=async t=>{const e=T(t),s=u.join(t,"salty.config.ts"),n=u.join(e,"salty.config.js");await z.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:y}=await import(`${n}?t=${r}`);return y},et=async t=>{const e=await tt(t),s=new Set,n=(i,f=[])=>i?Object.entries(i).flatMap(([h,d])=>{if(!d)return;if(typeof d=="object")return n(d,[...f,h]);const F=[...f,h].join(".");s.add(`"${F}"`);const b=[...f.map(E),E(h)].join("-"),{result:w}=B(d);return`--${b}: ${w};`}):[],r=i=>i?Object.entries(i).flatMap(([f,h])=>{const d=n(h);return f==="base"?d.join(""):`${f} { ${d.join("")} }`}):[],y=i=>i?Object.entries(i).flatMap(([f,h])=>Object.entries(h).flatMap(([d,F])=>{const b=n(F,[f]),w=`.${f}-${d}, [data-${f}="${d}"]`,O=b.join("");return`${w} { ${O} }`})):[],$=n(e.variables),p=r(e.responsiveVariables),c=y(e.conditionalVariables),o=T(t),l=u.join(o,"css/variables.css"),x=`:root { ${$.join("")} ${p.join("")} } ${c.join("")}`;m.writeFileSync(l,x);const j=u.join(o,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(j,S);const D=u.join(o,"css/global.css"),C=P(e.global,"");m.writeFileSync(D,C);const g=u.join(o,"css/templates.css"),k=I(e.templates);m.writeFileSync(g,k)},A=async(t,e)=>{const s=V(t),n=u.join(e,"js",s+".js");await z.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const r=Date.now();return await import(`${n}?t=${r}`)},M=async t=>{const e=T(t),s=u.join(e,"salty.config.js"),{config:n}=await import(s);return n},st=async t=>{try{const e=[],s=[],n=T(t),r=u.join(n,"index.css");(()=>{m.existsSync(n)&&G.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await et(t);const $=await M(t);async function p(a,S){const D=["node_modules","saltygen"],C=m.statSync(a);if(C.isDirectory()){const g=m.readdirSync(a);if(D.some(i=>a.includes(i)))return;await Promise.all(g.map(i=>p(u.join(a,i),u.join(S,i))))}else if(C.isFile()&&_(a)){const k=await A(a,n),i=[];Object.entries(k).forEach(([F,b])=>{if(b.isKeyframes&&b.css){const R=`${b.animationName}.css`,H=`css/${R}`,J=u.join(n,H);e.push(R),m.writeFileSync(J,b.css);return}if(!b.generator)return;const w=b.generator._withBuildContext({name:F,config:$}),O=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(O),i.push(O);const N=`css/${O}`,Z=u.join(n,N);m.writeFileSync(Z,w.css)});const f=i.map(F=>`@import url('./${F}');`).join(`
9
- `),h=V(a,6),d=u.join(n,`css/${h}.css`);m.writeFileSync(d,f)}}await p(t,n);const c=e.map(a=>`@import url('./css/${a}');`).join(`
10
- `);let j=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
-
12
- ${["variables.css","global.css","templates.css"].filter(a=>{try{return m.readFileSync(u.join(n,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
13
- `)}
14
- ${c}`;if($.importStrategy!=="component"){const a=s.flat().map(S=>`@import url('./css/${S}');`).join(`
15
- `);j+=a}m.writeFileSync(r,j)}catch(e){console.error(e)}},nt=async(t,e)=>{try{const s=[],n=u.join(t,"./saltygen"),r=u.join(n,"index.css");if(_(e)){const $=await M(t),p=await A(e,n);Object.entries(p).forEach(([j,a])=>{if(!a.generator)return;const S=a.generator._withBuildContext({name:j,config:$}),D=`${S.hash}-${S.priority}.css`,C=`css/${D}`,g=u.join(n,C);s.push(D),m.writeFileSync(g,S.css)});const c=m.readFileSync(r,"utf8").split(`
16
- `),o=s.map(j=>`@import url('../saltygen/css/${j}');`),x=[...new Set([...c,...o])].join(`
17
- `);m.writeFileSync(r,x)}}catch(s){console.error(s)}},rt=async(t,e)=>{try{const s=u.join(t,"./saltygen");if(_(e)){const r=m.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,l=>`export ${l}`)!==r&&await L.writeFile(e,r);const $=await M(t),p=await A(e,s);let c=r;Object.entries(p).forEach(([l,x])=>{var O;if(x.isKeyframes||!x.generator)return;const j=x.generator._withBuildContext({name:l,config:$}),a=new RegExp(`\\s${l}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!a)return console.error("Could not find the original declaration");const S=(O=a.at(1))==null?void 0:O.trim(),D=new RegExp(`\\s${l}[=\\s]+styled\\(`,"g").exec(c);if(!D)return console.error("Could not find the original declaration");const{index:C}=D;let g=!1;const k=setTimeout(()=>g=!0,5e3);let i=0,f=!1,h=0;for(;!f&&!g;){const N=c[C+i];N==="("&&h++,N===")"&&h--,h===0&&N===")"&&(f=!0),i>c.length&&(g=!0),i++}if(!g)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const d=C+i,F=c.slice(C,d),b=c,w=` ${l} = styled(${S}, "${j.classNames}", "${j._callerName}", ${JSON.stringify(j.props)});`;c=c.replace(F,w),b===c&&console.error("Minimize file failed to change content",{name:l,tagName:S})});const o=V(e,6);return $.importStrategy==="component"&&(c=`import '../../saltygen/css/${o}.css';
18
- ${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}};exports.generateCss=st;exports.generateFile=nt;exports.minimizeFile=rt;exports.saltyFileRegExp=W;