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