@salty-css/vite 0.0.1-alpha.216 → 0.0.1-alpha.218
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.cjs +14 -14
- package/index.js +166 -166
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
"use strict";var Tt=Object.defineProperty;var Dt=(e,t,s)=>t in e?Tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var tt=(e,t,s)=>Dt(e,typeof t!="symbol"?t+"":t,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Et=require("esbuild"),Ot=require("child_process"),
|
1
|
+
"use strict";var Tt=Object.defineProperty;var Dt=(e,t,s)=>t in e?Tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var tt=(e,t,s)=>Dt(e,typeof t!="symbol"?t+"":t,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Et=require("esbuild"),Ot=require("child_process"),f=require("path"),d=require("fs"),st=require("fs/promises"),G=require("winston");var it=typeof document<"u"?document.currentScript:null;function Mt(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 gt=Mt(Et),yt=e=>String.fromCharCode(e+(e>25?39:97)),Rt=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=yt(n%52)+s;return s=yt(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Vt=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},v=(e,t=5)=>{const s=Vt(5381,JSON.stringify(e))>>>0;return Rt(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 At=e=>t=>{if(typeof t!="string"||!e)return;let s=t;const n=[];return Object.values(e).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,w=>{const{value:$,css:u}=a(w);return u&&n.push(u),$})}),{transformed:s,additionalCss:n}},wt=e=>t=>typeof t!="string"||!/\{[^{}]+\}/g.test(t)?void 0:{transformed:t.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${V(o[1].replaceAll(".","-"))})`)},Jt=wt(),vt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],zt=(e,t,s)=>vt.some(o=>typeof o=="string"?o===e:o.test(e))?`${t}px`:`${t}`,Wt=["Webkit","Moz","ms","O"],It=e=>e.startsWith("-")?e:Wt.some(t=>e.startsWith(t))?`-${V(e)}`:V(e),et=async(e,t="",s,n=!1)=>{if(!e)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(e).map(async([m,i])=>{const y=m.trim(),x=It(y),P=(N,M=";")=>`${x}:${N}${M}`;if(typeof i=="function"&&(i=i({scope:t,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return P(i.toString());if(y==="defaultVariants")return;if(y==="variants"){const j=Object.entries(i);for(const[D,l]of j){if(!l)return;const h=Object.entries(l);for(const[F,c]of h){if(!c)return;const S=`${t}.${D}-${F}`;(await et(c,S,s)).forEach(E=>o.add(E))}}return}if(y==="compoundVariants"){for(const j of i){const{css:D,...l}=j,h=Object.entries(l).reduce((c,[S,k])=>`${c}.${S}-${k}`,t);(await et(D,h,s)).forEach(c=>o.add(c))}return}if(y.startsWith("@")){const j=y,D=await K(i,t,s),l=`${j} { ${D} }`;o.add(l);return}const N=m.includes("&")?y.replace("&",t):y.startsWith(":")?`${t}${y}`:`${t} ${y}`;(await et(i,N,s)).forEach(j=>o.add(j));return}if(typeof i=="number"){const N=zt(x,i);return P(N)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${x}`);return P(i)}),{modifiers:w}={},$=[wt(),At(w)],p=(await Promise.all(a).then(m=>Promise.all(m.map(i=>$.reduce(async(y,x)=>{const P=await y;if(!P)return P;const R=await x(P);if(!R)return P;const{transformed:N,additionalCss:M}=R;let j="";if(M)for(const D of M)j+=await K(D,"");return`${j}${N}`},Promise.resolve(i)))))).filter(m=>m!==void 0).join(`
|
2
2
|
`);if(!p.trim())return Array.from(o);const b=t?`${t} {
|
3
3
|
${p}
|
4
4
|
}`:p;return o.has(b)?Array.from(o):[b,...o]},K=async(e,t,s,n=!1)=>(await et(e,t,s,n)).join(`
|
5
|
-
`),$t=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,r]of Object.entries(e))if(typeof r!="function")if(r&&typeof r=="object"){const
|
6
|
-
`)},Zt=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=bt(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},bt=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?bt(o,r,s):s.add(t)}),[...s]):[],St=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=
|
5
|
+
`),$t=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,r]of Object.entries(e))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),w=await $t(r,[...t,a]);s.push(w)}else n[o]=r;if(Object.keys(n).length){const o=t.map(V).join("-"),r="t_"+v(o,4),a=await K(n,`.${o}, .${r}`);s.push(a)}return s.join(`
|
6
|
+
`)},Zt=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=bt(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},bt=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?bt(o,r,s):s.add(t)}),[...s]):[],St=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=f.join(e,"package.json");return d.existsSync(t)?t:St(f.join(e,".."))},qt=async e=>{const t=St(e);return await st.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Ht=async e=>{const t=await qt(e);if(t)return t.type};let W;const jt=async e=>{if(W)return W;const t=await Ht(e);return t==="module"?W="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:it&&it.tagName.toUpperCase()==="SCRIPT"&&it.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(W="cjs"),W||"esm"},at=G.createLogger({level:"debug",format:G.format.combine(G.format.colorize(),G.format.cli()),transports:[new G.transports.Console({})]});function Ft(e){return e?typeof e!="string"?Ft(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 Lt={"*, *::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},{}),Bt=(...e)=>e.flat().reduce((t,s)=>({...t,...s._children}),{});class Gt{constructor(t){tt(this,"_path");this.params=t}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(t){return this._path=t,this}}class Kt{constructor(t){tt(this,"_path");tt(this,"templates",[]);this.params=t,Object.entries(t).forEach(([s,n])=>{this.templates.push(new Gt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(t=>[t.params.name,t]))}get isDefineTemplates(){return!0}_setPath(t){return this._path=t,this.templates.forEach(s=>s._setPath(t)),this}}const Ut=e=>new Kt(e),J={externalModules:[],rcFile:void 0,destDir:void 0},Ct=e=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},z=async e=>{if(J.destDir)return J.destDir;const t=await ct(e),s=f.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return J.destDir=s,s},Pt=["salty","css","styles","styled"],Qt=(e=[])=>new RegExp(`\\.(${[...Pt,...e].join("|")})\\.`),Z=(e,t=[])=>Qt(t).test(e),_t=async e=>{if(J.rcFile)return J.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=f.join(e,".saltyrc.json"),s=await st.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):_t(f.join(e,".."))},ct=async e=>{var n,o;const t=await _t(e),s=(n=t.projects)==null?void 0:n.find(r=>e.endsWith(r.dir||""));return s||((o=t.projects)==null?void 0:o.find(r=>r.dir===t.defaultProject))},Xt=async e=>{const t=await ct(e),s=await z(e),n=f.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=f.join(s,"salty.config.js"),r=await jt(e),a=Ct(n);await gt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const w=Date.now(),{config:$}=await import(`${o}?t=${w}`);return{config:$,path:o}},Yt=async(e,t)=>{var ut,dt;const s=await z(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async C=>{const{contents:_,outputFilePath:A}=await nt(e,C,s);Object.entries(_).forEach(([T,O])=>{O.isMedia?n.mediaQueries.push([T,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(`${T};;${A}`))})}));const{config:o,path:r}=await Xt(e),a={...o},w=new Set,$=(C,_=[])=>C?Object.entries(C).flatMap(([A,T])=>{if(!T)return;if(typeof T=="object")return $(T,[..._,A]);const O=Ft(A),ot=V(A),rt=[..._,O].join(".");w.add(`"${rt}"`);const Y=[..._.map(V),ot].join("-"),pt=Jt(T);return pt?`--${Y}: ${pt.transformed};`:`--${Y}: ${T};`}):[],u=C=>C?Object.entries(C).flatMap(([_,A])=>{const T=$(A);return _==="base"?T.join(""):`${_} { ${T.join("")} }`}):[],p=C=>C?Object.entries(C).flatMap(([_,A])=>Object.entries(A).flatMap(([T,O])=>{const ot=$(O,[_]),rt=`.${_}-${T}, [data-${_}="${T}"]`,Y=ot.join("");return`${rt} { ${Y} }`})):[],b=C=>({...C,responsive:void 0,conditional:void 0}),g=C=>n.variables.map(_=>C==="static"?b(_._current):_._current[C]),m=I(b(o.variables),g("static")),i=$(m),y=I((ut=o.variables)==null?void 0:ut.responsive,g("responsive")),x=u(y),P=I((dt=o.variables)==null?void 0:dt.conditional,g("conditional")),R=p(P),N=f.join(s,"css/_variables.css"),M=`:root { ${i.join("")} ${x.join("")} } ${R.join("")}`;d.writeFileSync(N,M),a.staticVariables=m;const j=f.join(s,"css/_global.css"),D=I(o.global,n.globalStyles),l=await K(D,"");d.writeFileSync(j,`@layer global { ${l} }`);const h=f.join(s,"css/_reset.css"),c=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Lt,S=await K(c,"");d.writeFileSync(h,`@layer reset { ${S} }`);const k=f.join(s,"css/_templates.css"),E=I(o.templates,n.templates),q=await $t(E),H=Zt(E);d.writeFileSync(k,`@layer templates { ${q} }`),a.templates=E;const L=o.templates?[Ut(o.templates)._setPath(`config;;${r}`)]:[],U=Bt(n.templates,L);a.templatePaths=Object.fromEntries(Object.entries(U).map(([C,_])=>[C,_._path]));const{mediaQueries:Q}=n;a.mediaQueries=Object.fromEntries(Q.map(([C,_])=>[`@${C}`,_]));const B=Q.map(([C])=>`'@${C}'`).join(" | "),X=f.join(s,"types/css-tokens.d.ts"),Nt=`
|
7
7
|
// Variable types
|
8
8
|
type VariableTokens = ${[...w].join("|")};
|
9
9
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -16,27 +16,27 @@
|
|
16
16
|
|
17
17
|
// Media query types
|
18
18
|
type MediaQueryKeys = ${B||"''"};
|
19
|
-
`;d.writeFileSync(X,Nt);const kt=
|
19
|
+
`;d.writeFileSync(X,Nt);const kt=f.join(s,"cache/config-cache.json");d.writeFileSync(kt,JSON.stringify(a,null,2))},mt=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 a=o.exec(e);if(a){const w=a.at(1);if(Pt.some(u=>w==null?void 0:w.includes(u)))return t}return"styled('div',"}),te=(e,t)=>{try{const s=d.readFileSync(f.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
20
|
|
21
21
|
${e}`:`globalThis.saltyConfig = {};
|
22
22
|
|
23
|
-
${e}`}catch{return e}},nt=async(e,t,s)=>{const n=v(t),o=
|
24
|
-
`),
|
23
|
+
${e}`}catch{return e}},nt=async(e,t,s)=>{const n=v(t),o=f.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=f.parse(t);let a=d.readFileSync(t,"utf8");a=mt(a),a=te(a,e);const w=f.join(s,"js",n+".js"),$=await ct(e),u=f.join(e,($==null?void 0:$.configDir)||"","salty.config.ts"),p=Ct(u),b=await jt(e);await gt.build({stdin:{contents:a,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:w,format:b,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:i=>{i.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},y=>{const x=d.readFileSync(y.path,"utf8");return{contents:mt(x),loader:"ts"}})}}]});const g=Date.now();return{contents:await import(`${w}?t=${g}`),outputFilePath:w}},ee=async e=>{const t=await z(e),s=f.join(t,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},lt=async e=>{const t=await ee(e),s=await z(e),n=f.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return I(r,t)},ft=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},se=async(e,t=ft(),s=!0)=>{try{const n=Date.now();t?at.info("Generating CSS in production mode! 🔥"):at.info("Generating CSS in development mode! 🚀");const o=[],r=[],a=await z(e),w=f.join(a,"index.css");s&&(()=>{d.existsSync(a)&&Ot.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(f.join(a,"css")),d.mkdirSync(f.join(a,"types")),d.mkdirSync(f.join(a,"js")),d.mkdirSync(f.join(a,"cache"))})();const u=new Set,p=new Set;async function b(l){const h=["node_modules","saltygen"],F=d.statSync(l);if(F.isDirectory()){const c=d.readdirSync(l);if(h.some(k=>l.includes(k)))return;await Promise.all(c.map(k=>b(f.join(l,k))))}else if(F.isFile()&&Z(l)){u.add(l);const S=d.readFileSync(l,"utf8");/define[\w\d]+\(/.test(S)&&p.add(l)}}await b(e),await Yt(e,p);const g={keyframes:[],components:[],classNames:[]};await Promise.all([...u].map(async l=>{const{contents:h}=await nt(e,l,a);Object.entries(h).forEach(([F,c])=>{c.isKeyframes?g.keyframes.push({value:c,src:l,name:F}):c.isClassName?g.classNames.push({...c,src:l,name:F}):c.generator&&g.components.push({...c,src:l,name:F})})}));const m=await lt(e);for(const l of g.keyframes){const{value:h}=l,F=`a_${h.animationName}.css`,c=`css/${F}`,S=f.join(a,c);o.push(F),d.writeFileSync(S,h.css)}const i={};for(const l of g.components){const{src:h,name:F}=l;i[h]||(i[h]=[]);const c=l.generator._withBuildContext({callerName:F,isProduction:t,config:m});r[c.priority]||(r[c.priority]=[]);const S=await c.css;if(!S)continue;r[c.priority].push(c.cssFileName);const k=`css/${c.cssFileName}`,E=f.join(a,k);d.writeFileSync(E,S),m.importStrategy==="component"&&i[h].push(c.cssFileName)}for(const l of g.classNames){const{src:h,name:F}=l;i[h]||(i[h]=[]);const c=l.generator._withBuildContext({callerName:F,isProduction:t,config:m}),S=await c.css;if(!S)continue;r[c.priority]||(r[c.priority]=[]),r[c.priority].push(c.cssFileName);const k=`css/${c.cssFileName}`,E=f.join(a,k);d.writeFileSync(E,S),m.importStrategy==="component"&&i[h].push(c.cssFileName)}m.importStrategy==="component"&&Object.entries(i).forEach(([l,h])=>{const F=h.map(q=>`@import url('./${q}');`).join(`
|
24
|
+
`),c=v(l,6),S=f.parse(l),k=V(S.name),E=f.join(a,`css/f_${k}-${c}.css`);d.writeFileSync(E,F||"/* Empty file */")});const y=o.map(l=>`@import url('./css/${l}');`).join(`
|
25
25
|
`);let N=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
26
26
|
|
27
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(
|
27
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return d.readFileSync(f.join(a,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
28
28
|
`)}
|
29
|
-
${
|
29
|
+
${y}`;if(m.importStrategy!=="component"){const l=r.reduce((h,F,c)=>{const S=F.reduce((H,L)=>{var X;const U=f.join(a,"css",L),Q=d.readFileSync(U,"utf8"),B=((X=/.*-([^-]+)-\d+.css/.exec(L))==null?void 0:X.at(1))||v(U,6);return H.includes(B)?H:`${H}
|
30
30
|
/*start:${B}-${L}*/
|
31
31
|
${Q}
|
32
32
|
/*end:${B}*/
|
33
|
-
`},""),k=`l_${
|
33
|
+
`},""),k=`l_${c}.css`,E=f.join(a,"css",k),q=`@layer l${c} { ${S}
|
34
34
|
}`;return d.writeFileSync(E,q),`${h}
|
35
|
-
@import url('./css/${k}');`},"");N+=
|
35
|
+
@import url('./css/${k}');`},"");N+=l}d.writeFileSync(w,N);const j=Date.now()-n,D=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";at.info(`Generated CSS in ${j}ms! ${D}`)}catch(n){console.error(n)}},ne=async(e,t,s=ft())=>{try{const n=await z(e);if(Z(t)){const r=[],a=await lt(e),{contents:w}=await nt(e,t,n);for(const[$,u]of Object.entries(w)){if(u.isKeyframes&&u.css){const y=`css/${`a_${u.animationName}.css`}`,x=f.join(n,y);d.writeFileSync(x,await u.css);return}if(u.isClassName){const i=u.generator._withBuildContext({callerName:$,isProduction:s,config:a}),y=await i.css;if(!y)continue;r[i.priority]||(r[i.priority]=[]),r[i.priority].push(i.cssFileName);const x=`css/${i.cssFileName}`,P=f.join(n,x);d.writeFileSync(P,y)}if(!u.generator)return;const p=u.generator._withBuildContext({callerName:$,isProduction:s,config:a}),b=await p.css;if(!b)continue;const g=`css/${p.cssFileName}`,m=f.join(n,g);d.writeFileSync(m,b),r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName)}if(a.importStrategy!=="component")r.forEach(($,u)=>{const p=`l_${u}.css`,b=f.join(n,"css",p);let g=d.readFileSync(b,"utf8");$.forEach(m=>{var P;const i=f.join(n,"css",m),y=((P=/.*-([^-]+)-\d+.css/.exec(m))==null?void 0:P.at(1))||v(i,6);if(!g.includes(y)){const R=d.readFileSync(i,"utf8"),N=`/*start:${y}-${m}*/
|
36
36
|
${R}
|
37
|
-
/*end:${
|
37
|
+
/*end:${y}*/
|
38
38
|
`;g=`${g.replace(/\}$/,"")}
|
39
39
|
${N}
|
40
|
-
}`}}),d.writeFileSync(b,g)});else{const $=r.flat().map(
|
41
|
-
`),
|
42
|
-
${
|
40
|
+
}`}}),d.writeFileSync(b,g)});else{const $=r.flat().map(m=>`@import url('./${m}');`).join(`
|
41
|
+
`),u=v(t,6),p=f.parse(t),b=V(p.name),g=f.join(n,`css/f_${b}-${u}.css`);d.writeFileSync(g,$||"/* Empty file */")}}}catch(n){console.error(n)}},oe=async(e,t,s=ft())=>{try{const n=await z(e);if(Z(t)){const r=d.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await st.writeFile(t,r);const w=await lt(e),{contents:$}=await nt(e,t,n);let u=r;if(Object.entries($).forEach(([p,b])=>{var c;if(b.isKeyframes||!b.generator)return;const g=b.generator._withBuildContext({callerName:p,isProduction:s,config:w}),m=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!m)return console.error("Could not find the original declaration");const i=(c=m.at(1))==null?void 0:c.trim(),y=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(u);if(!y)return console.error("Could not find the original declaration");const{index:x}=y;let P=!1;const R=setTimeout(()=>P=!0,5e3);let N=0,M=!1,j=0;for(;!M&&!P;){const S=u[x+N];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(M=!0),N>u.length&&(P=!0),N++}if(!P)clearTimeout(R);else throw new Error("Failed to find the end of the styled call and timed out");const D=x+N,l=u.slice(x,D),h=u,F=` ${p} = styled(${i}, "${g.classNames}", ${JSON.stringify(g.clientProps)});`;u=u.replace(l,F),h===u&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),w.importStrategy==="component"){const p=v(t,6),b=f.parse(t);u=`import '../../saltygen/css/${`f_${V(b.name)}-${p}.css`}';
|
42
|
+
${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(n){console.error("Error in minimizeFile:",n)}},ht=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!Z(e))return!1;const n=await st.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},xt=e=>({name:"stylegen",buildStart:()=>se(e),load:async t=>{if(Z(t))return await oe(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ht(t)&&s.restart()},watchChange:{handler:async t=>{Z(t)&&(await ht(t)||await ne(e,t))}}});exports.default=xt;exports.saltyPlugin=xt;
|
package/index.js
CHANGED
@@ -7,10 +7,10 @@ import { join as u, parse as nt } from "path";
|
|
7
7
|
import { existsSync as lt, mkdirSync as H, statSync as Mt, readdirSync as Rt, readFileSync as M, writeFileSync as k } from "fs";
|
8
8
|
import { readFile as ft, writeFile as At } from "fs/promises";
|
9
9
|
import { createLogger as Jt, format as at, transports as Wt } from "winston";
|
10
|
-
const
|
10
|
+
const gt = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), zt = (e, t) => {
|
11
11
|
let s = "", n;
|
12
|
-
for (n = Math.abs(e); n > 52; n = n / 52 | 0) s =
|
13
|
-
return s =
|
12
|
+
for (n = Math.abs(e); n > 52; n = n / 52 | 0) s = gt(n % 52) + s;
|
13
|
+
return s = gt(n % 52) + s, s.length < t ? s = s.padStart(t, "a") : s.length > t && (s = s.slice(-t)), s;
|
14
14
|
}, vt = (e, t) => {
|
15
15
|
let s = t.length;
|
16
16
|
for (; s; ) e = e * 33 ^ t.charCodeAt(--s);
|
@@ -27,10 +27,10 @@ const Zt = (e) => (t) => {
|
|
27
27
|
let s = t;
|
28
28
|
const n = [];
|
29
29
|
return Object.values(e).forEach((o) => {
|
30
|
-
const { pattern: r, transform:
|
31
|
-
s = s.replace(r, (
|
32
|
-
const { value: $, css:
|
33
|
-
return
|
30
|
+
const { pattern: r, transform: a } = o;
|
31
|
+
s = s.replace(r, (g) => {
|
32
|
+
const { value: $, css: f } = a(g);
|
33
|
+
return f && n.push(f), $;
|
34
34
|
});
|
35
35
|
}), { transformed: s, additionalCss: n };
|
36
36
|
}, Ct = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) }, Ht = Ct(), It = [
|
@@ -56,51 +56,51 @@ const Zt = (e) => (t) => {
|
|
56
56
|
/.*font-size.*/
|
57
57
|
], Bt = (e, t, s) => It.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Gt = ["Webkit", "Moz", "ms", "O"], Kt = (e) => e.startsWith("-") ? e : Gt.some((t) => e.startsWith(t)) ? `-${A(e)}` : A(e), st = async (e, t = "", s, n = !1) => {
|
58
58
|
if (!e) throw new Error("No styles provided to parseStyles function!");
|
59
|
-
const o = /* @__PURE__ */ new Set(),
|
59
|
+
const o = /* @__PURE__ */ new Set(), a = Object.entries(e).map(async ([m, i]) => {
|
60
60
|
const p = m.trim(), x = Kt(p), F = (N, V = ";") => `${x}:${N}${V}`;
|
61
|
-
if (typeof
|
62
|
-
if (!
|
63
|
-
if (
|
61
|
+
if (typeof i == "function" && (i = i({ scope: t, config: s })), i instanceof Promise && (i = await i), typeof i == "object") {
|
62
|
+
if (!i) return;
|
63
|
+
if (i.isColor) return F(i.toString());
|
64
64
|
if (p === "defaultVariants") return;
|
65
65
|
if (p === "variants") {
|
66
|
-
const C = Object.entries(
|
67
|
-
for (const [E,
|
68
|
-
if (!
|
69
|
-
const h = Object.entries(
|
70
|
-
for (const [S,
|
71
|
-
if (!
|
66
|
+
const C = Object.entries(i);
|
67
|
+
for (const [E, l] of C) {
|
68
|
+
if (!l) return;
|
69
|
+
const h = Object.entries(l);
|
70
|
+
for (const [S, c] of h) {
|
71
|
+
if (!c) return;
|
72
72
|
const b = `${t}.${E}-${S}`;
|
73
|
-
(await st(
|
73
|
+
(await st(c, b, s)).forEach((T) => o.add(T));
|
74
74
|
}
|
75
75
|
}
|
76
76
|
return;
|
77
77
|
}
|
78
78
|
if (p === "compoundVariants") {
|
79
|
-
for (const C of
|
80
|
-
const { css: E, ...
|
81
|
-
(await st(E, h, s)).forEach((
|
79
|
+
for (const C of i) {
|
80
|
+
const { css: E, ...l } = C, h = Object.entries(l).reduce((c, [b, _]) => `${c}.${b}-${_}`, t);
|
81
|
+
(await st(E, h, s)).forEach((c) => o.add(c));
|
82
82
|
}
|
83
83
|
return;
|
84
84
|
}
|
85
85
|
if (p.startsWith("@")) {
|
86
|
-
const C = p, E = await U(
|
87
|
-
o.add(
|
86
|
+
const C = p, E = await U(i, t, s), l = `${C} { ${E} }`;
|
87
|
+
o.add(l);
|
88
88
|
return;
|
89
89
|
}
|
90
90
|
const N = m.includes("&") ? p.replace("&", t) : p.startsWith(":") ? `${t}${p}` : `${t} ${p}`;
|
91
|
-
(await st(
|
91
|
+
(await st(i, N, s)).forEach((C) => o.add(C));
|
92
92
|
return;
|
93
93
|
}
|
94
|
-
if (typeof
|
95
|
-
const N = Bt(x,
|
94
|
+
if (typeof i == "number") {
|
95
|
+
const N = Bt(x, i);
|
96
96
|
return F(N);
|
97
97
|
}
|
98
|
-
if (typeof
|
99
|
-
if ("toString" in
|
98
|
+
if (typeof i != "string")
|
99
|
+
if ("toString" in i) i = i.toString();
|
100
100
|
else throw new Error(`Invalid value type for property ${x}`);
|
101
|
-
return F(
|
102
|
-
}), { modifiers:
|
103
|
-
m.map((
|
101
|
+
return F(i);
|
102
|
+
}), { modifiers: g } = {}, $ = [Ct(), Zt(g)], d = (await Promise.all(a).then((m) => Promise.all(
|
103
|
+
m.map((i) => $.reduce(async (p, x) => {
|
104
104
|
const F = await p;
|
105
105
|
if (!F) return F;
|
106
106
|
const R = await x(F);
|
@@ -111,7 +111,7 @@ const Zt = (e) => (t) => {
|
|
111
111
|
for (const E of V)
|
112
112
|
C += await U(E, "");
|
113
113
|
return `${C}${N}`;
|
114
|
-
}, Promise.resolve(
|
114
|
+
}, Promise.resolve(i)))
|
115
115
|
))).filter((m) => m !== void 0).join(`
|
116
116
|
`);
|
117
117
|
if (!d.trim()) return Array.from(o);
|
@@ -125,13 +125,13 @@ const Zt = (e) => (t) => {
|
|
125
125
|
const s = [], n = {};
|
126
126
|
for (const [o, r] of Object.entries(e))
|
127
127
|
if (typeof r != "function") if (r && typeof r == "object") {
|
128
|
-
const
|
129
|
-
s.push(
|
128
|
+
const a = o.trim(), g = await St(r, [...t, a]);
|
129
|
+
s.push(g);
|
130
130
|
} else
|
131
131
|
n[o] = r;
|
132
132
|
if (Object.keys(n).length) {
|
133
|
-
const o = t.map(A).join("-"), r = "t_" + z(o, 4),
|
134
|
-
s.push(
|
133
|
+
const o = t.map(A).join("-"), r = "t_" + z(o, 4), a = await U(n, `.${o}, .${r}`);
|
134
|
+
s.push(a);
|
135
135
|
}
|
136
136
|
return s.join(`
|
137
137
|
`);
|
@@ -279,7 +279,7 @@ const ee = (e) => new te(e), W = {
|
|
279
279
|
const t = await kt(e), s = (n = t.projects) == null ? void 0 : n.find((r) => e.endsWith(r.dir || ""));
|
280
280
|
return s || ((o = t.projects) == null ? void 0 : o.find((r) => r.dir === t.defaultProject));
|
281
281
|
}, ne = async (e) => {
|
282
|
-
const t = await ut(e), s = await v(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Pt(e),
|
282
|
+
const t = await ut(e), s = await v(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Pt(e), a = Nt(n);
|
283
283
|
await bt.build({
|
284
284
|
entryPoints: [n],
|
285
285
|
minify: !0,
|
@@ -287,9 +287,9 @@ const ee = (e) => new te(e), W = {
|
|
287
287
|
bundle: !0,
|
288
288
|
outfile: o,
|
289
289
|
format: r,
|
290
|
-
external:
|
290
|
+
external: a
|
291
291
|
});
|
292
|
-
const
|
292
|
+
const g = Date.now(), { config: $ } = await import(`${o}?t=${g}`);
|
293
293
|
return { config: $, path: o };
|
294
294
|
}, oe = async (e, t) => {
|
295
295
|
var mt, ht;
|
@@ -307,34 +307,34 @@ const ee = (e) => new te(e), W = {
|
|
307
307
|
});
|
308
308
|
})
|
309
309
|
);
|
310
|
-
const { config: o, path: r } = await ne(e),
|
310
|
+
const { config: o, path: r } = await ne(e), a = { ...o }, g = /* @__PURE__ */ new Set(), $ = (j, P = []) => j ? Object.entries(j).flatMap(([J, D]) => {
|
311
311
|
if (!D) return;
|
312
312
|
if (typeof D == "object") return $(D, [...P, J]);
|
313
313
|
const O = xt(J), rt = A(J), it = [...P, O].join(".");
|
314
|
-
|
315
|
-
const tt = [...P.map(A), rt].join("-"),
|
316
|
-
return
|
317
|
-
}) : [],
|
314
|
+
g.add(`"${it}"`);
|
315
|
+
const tt = [...P.map(A), rt].join("-"), yt = Ht(D);
|
316
|
+
return yt ? `--${tt}: ${yt.transformed};` : `--${tt}: ${D};`;
|
317
|
+
}) : [], f = (j) => j ? Object.entries(j).flatMap(([P, J]) => {
|
318
318
|
const D = $(J);
|
319
319
|
return P === "base" ? D.join("") : `${P} { ${D.join("")} }`;
|
320
320
|
}) : [], d = (j) => j ? Object.entries(j).flatMap(([P, J]) => Object.entries(J).flatMap(([D, O]) => {
|
321
321
|
const rt = $(O, [P]), it = `.${P}-${D}, [data-${P}="${D}"]`, tt = rt.join("");
|
322
322
|
return `${it} { ${tt} }`;
|
323
|
-
})) : [], w = (j) => ({ ...j, responsive: void 0, conditional: void 0 }),
|
324
|
-
k(N, V),
|
325
|
-
const C = u(s, "css/_global.css"), E = I(o.global, n.globalStyles),
|
326
|
-
k(C, `@layer global { ${
|
327
|
-
const h = u(s, "css/_reset.css"),
|
323
|
+
})) : [], w = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), y = (j) => n.variables.map((P) => j === "static" ? w(P._current) : P._current[j]), m = I(w(o.variables), y("static")), i = $(m), p = I((mt = o.variables) == null ? void 0 : mt.responsive, y("responsive")), x = f(p), F = I((ht = o.variables) == null ? void 0 : ht.conditional, y("conditional")), R = d(F), N = u(s, "css/_variables.css"), V = `:root { ${i.join("")} ${x.join("")} } ${R.join("")}`;
|
324
|
+
k(N, V), a.staticVariables = m;
|
325
|
+
const C = u(s, "css/_global.css"), E = I(o.global, n.globalStyles), l = await U(E, "");
|
326
|
+
k(C, `@layer global { ${l} }`);
|
327
|
+
const h = u(s, "css/_reset.css"), c = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : qt, b = await U(c, "");
|
328
328
|
k(h, `@layer reset { ${b} }`);
|
329
329
|
const _ = u(s, "css/_templates.css"), T = I(o.templates, n.templates), G = await St(T), K = Lt(T);
|
330
|
-
k(_, `@layer templates { ${G} }`),
|
330
|
+
k(_, `@layer templates { ${G} }`), a.templates = T;
|
331
331
|
const L = o.templates ? [ee(o.templates)._setPath(`config;;${r}`)] : [], q = Xt(n.templates, L);
|
332
|
-
|
332
|
+
a.templatePaths = Object.fromEntries(Object.entries(q).map(([j, P]) => [j, P._path]));
|
333
333
|
const { mediaQueries: X } = n;
|
334
|
-
|
334
|
+
a.mediaQueries = Object.fromEntries(X.map(([j, P]) => [`@${j}`, P]));
|
335
335
|
const Q = X.map(([j]) => `'@${j}'`).join(" | "), Y = u(s, "types/css-tokens.d.ts"), Dt = `
|
336
336
|
// Variable types
|
337
|
-
type VariableTokens = ${[...
|
337
|
+
type VariableTokens = ${[...g].join("|")};
|
338
338
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
339
339
|
|
340
340
|
// Template types
|
@@ -348,15 +348,15 @@ const ee = (e) => new te(e), W = {
|
|
348
348
|
`;
|
349
349
|
k(Y, Dt);
|
350
350
|
const Et = u(s, "cache/config-cache.json");
|
351
|
-
k(Et, JSON.stringify(
|
351
|
+
k(Et, JSON.stringify(a, null, 2));
|
352
352
|
}, $t = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
|
353
353
|
if (/^['"`]/.test(s)) return t;
|
354
354
|
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
355
355
|
if (!o.test(e)) return t;
|
356
|
-
const
|
357
|
-
if (
|
358
|
-
const
|
359
|
-
if (_t.some((
|
356
|
+
const a = o.exec(e);
|
357
|
+
if (a) {
|
358
|
+
const g = a.at(1);
|
359
|
+
if (_t.some((f) => g == null ? void 0 : g.includes(f))) return t;
|
360
360
|
}
|
361
361
|
return "styled('div',";
|
362
362
|
}), re = (e, t) => {
|
@@ -374,12 +374,12 @@ ${e}`;
|
|
374
374
|
const n = z(t), o = u(s, "./temp");
|
375
375
|
lt(o) || H(o);
|
376
376
|
const r = nt(t);
|
377
|
-
let
|
378
|
-
|
379
|
-
const
|
377
|
+
let a = M(t, "utf8");
|
378
|
+
a = $t(a), a = re(a, e);
|
379
|
+
const g = u(s, "js", n + ".js"), $ = await ut(e), f = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), d = Nt(f), w = await Pt(e);
|
380
380
|
await bt.build({
|
381
381
|
stdin: {
|
382
|
-
contents:
|
382
|
+
contents: a,
|
383
383
|
sourcefile: r.base,
|
384
384
|
resolveDir: r.dir,
|
385
385
|
loader: "tsx"
|
@@ -387,7 +387,7 @@ ${e}`;
|
|
387
387
|
minify: !1,
|
388
388
|
treeShaking: !0,
|
389
389
|
bundle: !0,
|
390
|
-
outfile:
|
390
|
+
outfile: g,
|
391
391
|
format: w,
|
392
392
|
target: ["node20"],
|
393
393
|
keepNames: !0,
|
@@ -396,8 +396,8 @@ ${e}`;
|
|
396
396
|
plugins: [
|
397
397
|
{
|
398
398
|
name: "test",
|
399
|
-
setup: (
|
400
|
-
|
399
|
+
setup: (i) => {
|
400
|
+
i.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (p) => {
|
401
401
|
const x = M(p.path, "utf8");
|
402
402
|
return { contents: $t(x), loader: "ts" };
|
403
403
|
});
|
@@ -405,8 +405,8 @@ ${e}`;
|
|
405
405
|
}
|
406
406
|
]
|
407
407
|
});
|
408
|
-
const
|
409
|
-
return { contents: await import(`${
|
408
|
+
const y = Date.now();
|
409
|
+
return { contents: await import(`${g}?t=${y}`), outputFilePath: g };
|
410
410
|
}, ie = async (e) => {
|
411
411
|
const t = await v(e), s = u(t, "cache/config-cache.json"), n = M(s, "utf8");
|
412
412
|
if (!n) throw new Error("Could not find config cache file");
|
@@ -424,119 +424,119 @@ ${e}`;
|
|
424
424
|
try {
|
425
425
|
const n = Date.now();
|
426
426
|
t ? ct.info("Generating CSS in production mode! 🔥") : ct.info("Generating CSS in development mode! 🚀");
|
427
|
-
const o = [], r = [],
|
427
|
+
const o = [], r = [], a = await v(e), g = u(a, "index.css");
|
428
428
|
s && (() => {
|
429
|
-
lt(
|
429
|
+
lt(a) && Vt("rm -rf " + a), H(a, { recursive: !0 }), H(u(a, "css")), H(u(a, "types")), H(u(a, "js")), H(u(a, "cache"));
|
430
430
|
})();
|
431
|
-
const
|
432
|
-
async function w(
|
433
|
-
const h = ["node_modules", "saltygen"], S = Mt(
|
431
|
+
const f = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
|
432
|
+
async function w(l) {
|
433
|
+
const h = ["node_modules", "saltygen"], S = Mt(l);
|
434
434
|
if (S.isDirectory()) {
|
435
|
-
const
|
436
|
-
if (h.some((_) =>
|
437
|
-
await Promise.all(
|
438
|
-
} else if (S.isFile() && B(
|
439
|
-
|
440
|
-
const b = M(
|
441
|
-
/define[\w\d]+\(/.test(b) && d.add(
|
435
|
+
const c = Rt(l);
|
436
|
+
if (h.some((_) => l.includes(_))) return;
|
437
|
+
await Promise.all(c.map((_) => w(u(l, _))));
|
438
|
+
} else if (S.isFile() && B(l)) {
|
439
|
+
f.add(l);
|
440
|
+
const b = M(l, "utf8");
|
441
|
+
/define[\w\d]+\(/.test(b) && d.add(l);
|
442
442
|
}
|
443
443
|
}
|
444
444
|
await w(e), await oe(e, d);
|
445
|
-
const
|
445
|
+
const y = {
|
446
446
|
keyframes: [],
|
447
447
|
components: [],
|
448
448
|
classNames: []
|
449
449
|
};
|
450
450
|
await Promise.all(
|
451
|
-
[...
|
452
|
-
const { contents: h } = await ot(e,
|
453
|
-
Object.entries(h).forEach(([S,
|
454
|
-
|
455
|
-
value:
|
456
|
-
src:
|
451
|
+
[...f].map(async (l) => {
|
452
|
+
const { contents: h } = await ot(e, l, a);
|
453
|
+
Object.entries(h).forEach(([S, c]) => {
|
454
|
+
c.isKeyframes ? y.keyframes.push({
|
455
|
+
value: c,
|
456
|
+
src: l,
|
457
457
|
name: S
|
458
|
-
}) :
|
459
|
-
...
|
460
|
-
src:
|
458
|
+
}) : c.isClassName ? y.classNames.push({
|
459
|
+
...c,
|
460
|
+
src: l,
|
461
461
|
name: S
|
462
|
-
}) :
|
463
|
-
...
|
464
|
-
src:
|
462
|
+
}) : c.generator && y.components.push({
|
463
|
+
...c,
|
464
|
+
src: l,
|
465
465
|
name: S
|
466
466
|
});
|
467
467
|
});
|
468
468
|
})
|
469
469
|
);
|
470
470
|
const m = await dt(e);
|
471
|
-
for (const
|
472
|
-
const { value: h } =
|
471
|
+
for (const l of y.keyframes) {
|
472
|
+
const { value: h } = l, S = `a_${h.animationName}.css`, c = `css/${S}`, b = u(a, c);
|
473
473
|
o.push(S), k(b, h.css);
|
474
474
|
}
|
475
|
-
const
|
476
|
-
for (const
|
477
|
-
const { src: h, name: S } =
|
478
|
-
|
479
|
-
const
|
475
|
+
const i = {};
|
476
|
+
for (const l of y.components) {
|
477
|
+
const { src: h, name: S } = l;
|
478
|
+
i[h] || (i[h] = []);
|
479
|
+
const c = l.generator._withBuildContext({
|
480
480
|
callerName: S,
|
481
481
|
isProduction: t,
|
482
482
|
config: m
|
483
483
|
});
|
484
|
-
r[
|
485
|
-
const b = await
|
484
|
+
r[c.priority] || (r[c.priority] = []);
|
485
|
+
const b = await c.css;
|
486
486
|
if (!b) continue;
|
487
|
-
r[
|
488
|
-
const _ = `css/${
|
489
|
-
k(T, b), m.importStrategy === "component" &&
|
487
|
+
r[c.priority].push(c.cssFileName);
|
488
|
+
const _ = `css/${c.cssFileName}`, T = u(a, _);
|
489
|
+
k(T, b), m.importStrategy === "component" && i[h].push(c.cssFileName);
|
490
490
|
}
|
491
|
-
for (const
|
492
|
-
const { src: h, name: S } =
|
493
|
-
|
494
|
-
const
|
491
|
+
for (const l of y.classNames) {
|
492
|
+
const { src: h, name: S } = l;
|
493
|
+
i[h] || (i[h] = []);
|
494
|
+
const c = l.generator._withBuildContext({
|
495
495
|
callerName: S,
|
496
496
|
isProduction: t,
|
497
497
|
config: m
|
498
|
-
}), b = await
|
498
|
+
}), b = await c.css;
|
499
499
|
if (!b) continue;
|
500
|
-
r[
|
501
|
-
const _ = `css/${
|
502
|
-
k(T, b), m.importStrategy === "component" &&
|
500
|
+
r[c.priority] || (r[c.priority] = []), r[c.priority].push(c.cssFileName);
|
501
|
+
const _ = `css/${c.cssFileName}`, T = u(a, _);
|
502
|
+
k(T, b), m.importStrategy === "component" && i[h].push(c.cssFileName);
|
503
503
|
}
|
504
|
-
m.importStrategy === "component" && Object.entries(
|
504
|
+
m.importStrategy === "component" && Object.entries(i).forEach(([l, h]) => {
|
505
505
|
const S = h.map((G) => `@import url('./${G}');`).join(`
|
506
|
-
`),
|
506
|
+
`), c = z(l, 6), b = nt(l), _ = A(b.name), T = u(a, `css/f_${_}-${c}.css`);
|
507
507
|
k(T, S || "/* Empty file */");
|
508
508
|
});
|
509
|
-
const p = o.map((
|
509
|
+
const p = o.map((l) => `@import url('./css/${l}');`).join(`
|
510
510
|
`);
|
511
511
|
let N = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
512
512
|
|
513
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((
|
513
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
514
514
|
try {
|
515
|
-
return M(u(
|
515
|
+
return M(u(a, "css", l), "utf8").length > 0;
|
516
516
|
} catch {
|
517
517
|
return !1;
|
518
518
|
}
|
519
|
-
}).map((
|
519
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
520
520
|
`)}
|
521
521
|
${p}`;
|
522
522
|
if (m.importStrategy !== "component") {
|
523
|
-
const
|
523
|
+
const l = r.reduce((h, S, c) => {
|
524
524
|
const b = S.reduce((K, L) => {
|
525
525
|
var Y;
|
526
|
-
const q = u(
|
526
|
+
const q = u(a, "css", L), X = M(q, "utf8"), Q = ((Y = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : Y.at(1)) || z(q, 6);
|
527
527
|
return K.includes(Q) ? K : `${K}
|
528
528
|
/*start:${Q}-${L}*/
|
529
529
|
${X}
|
530
530
|
/*end:${Q}*/
|
531
531
|
`;
|
532
|
-
}, ""), _ = `l_${
|
532
|
+
}, ""), _ = `l_${c}.css`, T = u(a, "css", _), G = `@layer l${c} { ${b}
|
533
533
|
}`;
|
534
534
|
return k(T, G), `${h}
|
535
535
|
@import url('./css/${_}');`;
|
536
536
|
}, "");
|
537
|
-
N +=
|
537
|
+
N += l;
|
538
538
|
}
|
539
|
-
k(
|
539
|
+
k(g, N);
|
540
540
|
const C = Date.now() - n, E = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
|
541
541
|
ct.info(`Generated CSS in ${C}ms! ${E}`);
|
542
542
|
} catch (n) {
|
@@ -546,56 +546,56 @@ ${X}
|
|
546
546
|
try {
|
547
547
|
const n = await v(e);
|
548
548
|
if (B(t)) {
|
549
|
-
const r = [],
|
550
|
-
for (const [$,
|
551
|
-
if (
|
552
|
-
const p = `css/${`a_${
|
553
|
-
k(x, await
|
549
|
+
const r = [], a = await dt(e), { contents: g } = await ot(e, t, n);
|
550
|
+
for (const [$, f] of Object.entries(g)) {
|
551
|
+
if (f.isKeyframes && f.css) {
|
552
|
+
const p = `css/${`a_${f.animationName}.css`}`, x = u(n, p);
|
553
|
+
k(x, await f.css);
|
554
554
|
return;
|
555
555
|
}
|
556
|
-
if (
|
557
|
-
const
|
556
|
+
if (f.isClassName) {
|
557
|
+
const i = f.generator._withBuildContext({
|
558
558
|
callerName: $,
|
559
559
|
isProduction: s,
|
560
|
-
config:
|
561
|
-
}), p = await
|
560
|
+
config: a
|
561
|
+
}), p = await i.css;
|
562
562
|
if (!p) continue;
|
563
|
-
r[
|
564
|
-
const x = `css/${
|
563
|
+
r[i.priority] || (r[i.priority] = []), r[i.priority].push(i.cssFileName);
|
564
|
+
const x = `css/${i.cssFileName}`, F = u(n, x);
|
565
565
|
k(F, p);
|
566
566
|
}
|
567
|
-
if (!
|
568
|
-
const d =
|
567
|
+
if (!f.generator) return;
|
568
|
+
const d = f.generator._withBuildContext({
|
569
569
|
callerName: $,
|
570
570
|
isProduction: s,
|
571
|
-
config:
|
571
|
+
config: a
|
572
572
|
}), w = await d.css;
|
573
573
|
if (!w) continue;
|
574
|
-
const
|
574
|
+
const y = `css/${d.cssFileName}`, m = u(n, y);
|
575
575
|
k(m, w), r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
|
576
576
|
}
|
577
|
-
if (
|
578
|
-
r.forEach(($,
|
579
|
-
const d = `l_${
|
580
|
-
let
|
577
|
+
if (a.importStrategy !== "component")
|
578
|
+
r.forEach(($, f) => {
|
579
|
+
const d = `l_${f}.css`, w = u(n, "css", d);
|
580
|
+
let y = M(w, "utf8");
|
581
581
|
$.forEach((m) => {
|
582
582
|
var F;
|
583
|
-
const
|
584
|
-
if (!
|
585
|
-
const R = M(
|
583
|
+
const i = u(n, "css", m), p = ((F = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : F.at(1)) || z(i, 6);
|
584
|
+
if (!y.includes(p)) {
|
585
|
+
const R = M(i, "utf8"), N = `/*start:${p}-${m}*/
|
586
586
|
${R}
|
587
587
|
/*end:${p}*/
|
588
588
|
`;
|
589
|
-
|
589
|
+
y = `${y.replace(/\}$/, "")}
|
590
590
|
${N}
|
591
591
|
}`;
|
592
592
|
}
|
593
|
-
}), k(w,
|
593
|
+
}), k(w, y);
|
594
594
|
});
|
595
595
|
else {
|
596
596
|
const $ = r.flat().map((m) => `@import url('./${m}');`).join(`
|
597
|
-
`),
|
598
|
-
k(
|
597
|
+
`), f = z(t, 6), d = nt(t), w = A(d.name), y = u(n, `css/f_${w}-${f}.css`);
|
598
|
+
k(y, $ || "/* Empty file */");
|
599
599
|
}
|
600
600
|
}
|
601
601
|
} catch (n) {
|
@@ -607,37 +607,37 @@ ${N}
|
|
607
607
|
if (B(t)) {
|
608
608
|
const r = M(t, "utf8");
|
609
609
|
r.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== r && await At(t, r);
|
610
|
-
const
|
611
|
-
let
|
610
|
+
const g = await dt(e), { contents: $ } = await ot(e, t, n);
|
611
|
+
let f = r;
|
612
612
|
if (Object.entries($).forEach(([d, w]) => {
|
613
|
-
var
|
613
|
+
var c;
|
614
614
|
if (w.isKeyframes || !w.generator) return;
|
615
|
-
const
|
615
|
+
const y = w.generator._withBuildContext({
|
616
616
|
callerName: d,
|
617
617
|
isProduction: s,
|
618
|
-
config:
|
618
|
+
config: g
|
619
619
|
}), m = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
620
620
|
if (!m) return console.error("Could not find the original declaration");
|
621
|
-
const
|
621
|
+
const i = (c = m.at(1)) == null ? void 0 : c.trim(), p = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(f);
|
622
622
|
if (!p) return console.error("Could not find the original declaration");
|
623
623
|
const { index: x } = p;
|
624
624
|
let F = !1;
|
625
625
|
const R = setTimeout(() => F = !0, 5e3);
|
626
626
|
let N = 0, V = !1, C = 0;
|
627
627
|
for (; !V && !F; ) {
|
628
|
-
const b =
|
629
|
-
b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (V = !0), N >
|
628
|
+
const b = f[x + N];
|
629
|
+
b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (V = !0), N > f.length && (F = !0), N++;
|
630
630
|
}
|
631
631
|
if (!F) clearTimeout(R);
|
632
632
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
633
|
-
const E = x + N,
|
634
|
-
|
635
|
-
}),
|
633
|
+
const E = x + N, l = f.slice(x, E), h = f, S = ` ${d} = styled(${i}, "${y.classNames}", ${JSON.stringify(y.clientProps)});`;
|
634
|
+
f = f.replace(l, S), h === f && console.error("Minimize file failed to change content", { name: d, tagName: i });
|
635
|
+
}), g.importStrategy === "component") {
|
636
636
|
const d = z(t, 6), w = nt(t);
|
637
|
-
|
638
|
-
${
|
637
|
+
f = `import '../../saltygen/css/${`f_${A(w.name)}-${d}.css`}';
|
638
|
+
${f}`;
|
639
639
|
}
|
640
|
-
return
|
640
|
+
return f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
|
641
641
|
}
|
642
642
|
} catch (n) {
|
643
643
|
console.error("Error in minimizeFile:", n);
|
@@ -648,7 +648,7 @@ ${l}`;
|
|
648
648
|
if (!B(e)) return !1;
|
649
649
|
const n = await ft(e, "utf-8");
|
650
650
|
return !!/.+define[A-Z]\w+/.test(n);
|
651
|
-
},
|
651
|
+
}, ge = (e) => ({
|
652
652
|
name: "stylegen",
|
653
653
|
buildStart: () => ae(e),
|
654
654
|
load: async (t) => {
|
@@ -665,6 +665,6 @@ ${l}`;
|
|
665
665
|
}
|
666
666
|
});
|
667
667
|
export {
|
668
|
-
|
669
|
-
|
668
|
+
ge as default,
|
669
|
+
ge as saltyPlugin
|
670
670
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/vite",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.218",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,6 +34,6 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.218"
|
38
38
|
}
|
39
39
|
}
|