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