@salty-css/webpack 0.0.1-alpha.72 → 0.0.1-alpha.73

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