@salty-css/webpack 0.0.1-alpha.128 → 0.0.1-alpha.129

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