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