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