@salty-css/webpack 0.0.1-alpha.178 → 0.0.1-alpha.179

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