@salty-css/vite 0.0.1-alpha.102 → 0.0.1-alpha.103

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.
Files changed (3) hide show
  1. package/index.cjs +7 -7
  2. package/index.js +78 -78
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,18 +1,18 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ot=require("esbuild"),rt=require("child_process"),l=require("path"),f=require("fs"),Z=require("fs/promises"),V=require("winston");var R=typeof document<"u"?document.currentScript:null;function it(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const U=it(ot),B=t=>String.fromCharCode(t+(t>25?39:97)),ct=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=B(n%52)+s;return s=B(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},at=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=3)=>{const s=at(5381,JSON.stringify(t))>>>0;return ct(s,e)};function E(t){return t?typeof t!="string"?E(String(t)):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const lt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:r,transform:c}=n;t=t.replace(r,g=>{const{value:a,css:h}=c(g);return h&&s.push(h),a})}),{result:t,additionalCss:s}},G=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:t},O=(t,e,s,n)=>{if(!t)return"";const r=[],c=Object.entries(t).reduce((a,[h,o])=>{const y=h.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return a;if(y==="variants")return Object.entries(o).forEach(([p,i])=>{i&&Object.entries(i).forEach(([j,d])=>{if(!d)return;const P=`${e}.${p}-${j}`,k=O(d,P);r.push(k)})}),a;if(y==="defaultVariants")return a;if(y==="compoundVariants")return o.forEach(p=>{const{css:i,...j}=p,d=Object.entries(j).reduce((k,[$,x])=>`${k}.${$}-${x}`,e),P=O(i,d);r.push(P)}),a;if(y.startsWith("@")){const p=O(o,e),i=`${y} {
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ot=require("esbuild"),rt=require("child_process"),l=require("path"),f=require("fs"),L=require("fs/promises"),V=require("winston");var R=typeof document<"u"?document.currentScript:null;function it(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const U=it(ot),B=t=>String.fromCharCode(t+(t>25?39:97)),ct=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=B(n%52)+s;return s=B(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},at=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=3)=>{const s=at(5381,JSON.stringify(t))>>>0;return ct(s,e)};function E(t){return t?typeof t!="string"?E(String(t)):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const lt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:r,transform:c}=n;t=t.replace(r,g=>{const{value:a,css:h}=c(g);return h&&s.push(h),a})}),{result:t,additionalCss:s}},G=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:t},T=(t,e,s,n)=>{if(!t)return"";const r=[],c=Object.entries(t).reduce((a,[h,o])=>{const y=h.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return a;if(y==="variants")return Object.entries(o).forEach(([p,i])=>{i&&Object.entries(i).forEach(([j,d])=>{if(!d)return;const P=`${e}.${p}-${j}`,C=T(d,P);r.push(C)})}),a;if(y==="defaultVariants")return a;if(y==="compoundVariants")return o.forEach(p=>{const{css:i,...j}=p,d=Object.entries(j).reduce((C,[$,x])=>`${C}.${$}-${x}`,e),P=T(i,d);r.push(P)}),a;if(y.startsWith("@")){const p=T(o,e),i=`${y} {
2
2
  ${p.replace(`
3
3
  `,`
4
4
  `)}
5
- }`;return r.push(i),a}const m=h.includes("&")?y.replace("&",e):y.startsWith(":")?`${e}${y}`:`${e} ${y}`,S=O(o,m);return r.push(S),a}const b=y.startsWith("-")?y:E(y),w=(m,S=";")=>a=`${a}${m}${S}`,C=m=>w(`${b}:${m}`);if(typeof o=="number")return C(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return a;const{modifiers:u}={},D=function*(){yield G(o),yield lt(o,u)}();for(const{result:m,additionalCss:S=[]}of D)o=m,S.forEach(p=>{const i=O(p,"");w(i,"")});return C(o)},"");if(!c)return r.join(`
5
+ }`;return r.push(i),a}const m=h.includes("&")?y.replace("&",e):y.startsWith(":")?`${e}${y}`:`${e} ${y}`,S=T(o,m);return r.push(S),a}const b=y.startsWith("-")?y:E(y),w=(m,S=";")=>a=`${a}${m}${S}`,k=m=>w(`${b}:${m}`);if(typeof o=="number")return k(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return a;const{modifiers:u}={},O=function*(){yield G(o),yield lt(o,u)}();for(const{result:m,additionalCss:S=[]}of O)o=m,S.forEach(p=>{const i=T(p,"");w(i,"")});return k(o)},"");if(!c)return r.join(`
6
6
  `);if(!e)return c;let g="";return g=`${e} { ${c} }`,[g,...r].join(`
7
- `)},H=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,c])=>{if(typeof c=="object"){if(!c)return;const g=r.trim(),a=H(c,[...e,g]);s.push(a)}else n[r]=c}),Object.keys(n).length){const r=e.map(E).join("-"),c=O(n,`.${r}`);s.push(c)}return s.join(`
8
- `)},K=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return f.existsSync(e)?e:K(l.join(t,".."))},ut=async t=>{const e=K(t);return await Z.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},ft=async t=>{const e=await ut(t);if(e)return e.type};let M;const X=async t=>{if(M)return M;const e=await ft(t);return e==="module"?M="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(M="cjs"),M||"esm"},L=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]}),A={externalModules:[]},Y=t=>{if(A.externalModules.length>0)return A.externalModules;const e=l.join(t,"salty.config.ts"),n=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const r=n[1].split(",").map(c=>c.replace(/['"`]/g,"").trim());return A.externalModules=r,r},J=t=>l.join(t,"./saltygen"),pt=["salty","css","styles","styled"],dt=(t=[])=>new RegExp(`\\.(${[...pt,...t].join("|")})\\.`),_=(t,e=[])=>dt(e).test(t),yt=async t=>{const e=J(t),s=l.join(t,"salty.config.ts"),n=l.join(e,"salty.config.js"),r=await X(t),c=Y(t);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:r,external:c});const g=Date.now(),{config:a}=await import(`${n}?t=${g}`);return a},v=async t=>{const e=await yt(t),s=new Set,n=(p,i=[])=>p?Object.entries(p).flatMap(([j,d])=>{if(!d)return;if(typeof d=="object")return n(d,[...i,j]);const P=[...i,j].join(".");s.add(`"${P}"`);const k=[...i.map(E),E(j)].join("-"),{result:$}=G(d);return`--${k}: ${$};`}):[],r=p=>p?Object.entries(p).flatMap(([i,j])=>{const d=n(j);return i==="base"?d.join(""):`${i} { ${d.join("")} }`}):[],c=p=>p?Object.entries(p).flatMap(([i,j])=>Object.entries(j).flatMap(([d,P])=>{const k=n(P,[i]),$=`.${i}-${d}, [data-${i}="${d}"]`,x=k.join("");return`${$} { ${x} }`})):[],g=n(e.variables),a=r(e.responsiveVariables),h=c(e.conditionalVariables),o=J(t),y=l.join(o,"css/variables.css"),b=`:root { ${g.join("")} ${a.join("")} } ${h.join("")}`;f.writeFileSync(y,b);const w=l.join(o,"types/css-tokens.d.ts"),u=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;f.writeFileSync(w,u);const F=l.join(o,"css/global.css"),D=O(e.global,"");f.writeFileSync(F,D);const m=l.join(o,"css/templates.css"),S=H(e.templates);f.writeFileSync(m,S)},I=async(t,e,s)=>{const n=q(e),r=l.join(s,"./temp");f.existsSync(r)||f.mkdirSync(r);const c=l.parse(e);let g=f.readFileSync(e,"utf8");g=g.replace("styled(DynaLink","styled('div'");const a=l.join(s,"js",n+".js"),h=Y(t),o=await X(t);await U.build({stdin:{contents:g,sourcefile:c.base,resolveDir:c.dir,loader:"ts"},minify:!1,treeShaking:!0,bundle:!0,outfile:a,format:o,target:["node20"],keepNames:!0,external:h,packages:"external"});const y=Date.now();return await import(`${a}?t=${y}`)},W=async t=>{const e=J(t),s=l.join(e,"salty.config.js"),{config:n}=await import(s);return n},Q=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},gt=async(t,e=Q())=>{try{e?L.info("Generating CSS in production mode! 🔥"):L.info("Generating CSS in development mode! 🚀");const s=[],n=[],r=J(t),c=l.join(r,"index.css");(()=>{f.existsSync(r)&&rt.execSync("rm -rf "+r),f.mkdirSync(r),f.mkdirSync(l.join(r,"css")),f.mkdirSync(l.join(r,"types"))})(),await v(t);const a=await W(t);async function h(u,F){const D=["node_modules","saltygen"],m=f.statSync(u);if(m.isDirectory()){const S=f.readdirSync(u);if(D.some(i=>u.includes(i)))return;await Promise.all(S.map(i=>h(l.join(u,i),l.join(F,i))))}else if(m.isFile()&&_(u)){const p=await I(t,u,r),i=[];Object.entries(p).forEach(([k,$])=>{if($.isKeyframes&&$.css){const z=`${$.animationName}.css`,st=`css/${z}`,nt=l.join(r,st);s.push(z),f.writeFileSync(nt,$.css);return}if(!$.generator)return;const x=$.generator._withBuildContext({name:k,config:a,prod:e}),T=`${x.hash}-${x.priority}.css`;n[x.priority]||(n[x.priority]=[]),n[x.priority].push(T),i.push(T);const N=`css/${T}`,et=l.join(r,N);f.writeFileSync(et,x.css)});const j=i.map(k=>`@import url('./${k}');`).join(`
7
+ `)},H=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,c])=>{if(typeof c=="object"){if(!c)return;const g=r.trim(),a=H(c,[...e,g]);s.push(a)}else n[r]=c}),Object.keys(n).length){const r=e.map(E).join("-"),c=T(n,`.${r}`);s.push(c)}return s.join(`
8
+ `)},K=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return f.existsSync(e)?e:K(l.join(t,".."))},ut=async t=>{const e=K(t);return await L.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},ft=async t=>{const e=await ut(t);if(e)return e.type};let M;const X=async t=>{if(M)return M;const e=await ft(t);return e==="module"?M="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(M="cjs"),M||"esm"},Z=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]}),A={externalModules:[]},Y=t=>{if(A.externalModules.length>0)return A.externalModules;const e=l.join(t,"salty.config.ts"),n=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const r=n[1].split(",").map(c=>c.replace(/['"`]/g,"").trim());return A.externalModules=r,r},J=t=>l.join(t,"./saltygen"),pt=["salty","css","styles","styled"],dt=(t=[])=>new RegExp(`\\.(${[...pt,...t].join("|")})\\.`),_=(t,e=[])=>dt(e).test(t),yt=async t=>{const e=J(t),s=l.join(t,"salty.config.ts"),n=l.join(e,"salty.config.js"),r=await X(t),c=Y(t);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:r,external:c});const g=Date.now(),{config:a}=await import(`${n}?t=${g}`);return a},v=async t=>{const e=await yt(t),s=new Set,n=(p,i=[])=>p?Object.entries(p).flatMap(([j,d])=>{if(!d)return;if(typeof d=="object")return n(d,[...i,j]);const P=[...i,j].join(".");s.add(`"${P}"`);const C=[...i.map(E),E(j)].join("-"),{result:$}=G(d);return`--${C}: ${$};`}):[],r=p=>p?Object.entries(p).flatMap(([i,j])=>{const d=n(j);return i==="base"?d.join(""):`${i} { ${d.join("")} }`}):[],c=p=>p?Object.entries(p).flatMap(([i,j])=>Object.entries(j).flatMap(([d,P])=>{const C=n(P,[i]),$=`.${i}-${d}, [data-${i}="${d}"]`,x=C.join("");return`${$} { ${x} }`})):[],g=n(e.variables),a=r(e.responsiveVariables),h=c(e.conditionalVariables),o=J(t),y=l.join(o,"css/variables.css"),b=`:root { ${g.join("")} ${a.join("")} } ${h.join("")}`;f.writeFileSync(y,b);const w=l.join(o,"types/css-tokens.d.ts"),u=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;f.writeFileSync(w,u);const F=l.join(o,"css/global.css"),O=T(e.global,"");f.writeFileSync(F,O);const m=l.join(o,"css/templates.css"),S=H(e.templates);f.writeFileSync(m,S)},I=async(t,e,s)=>{const n=q(e),r=l.join(s,"./temp");f.existsSync(r)||f.mkdirSync(r);const c=l.parse(e);let g=f.readFileSync(e,"utf8");g=g.replace(/styled\([^"'`{,]+,/g,"styled('div'");const a=l.join(s,"js",n+".js"),h=Y(t),o=await X(t);await U.build({stdin:{contents:g,sourcefile:c.base,resolveDir:c.dir,loader:"ts"},minify:!1,treeShaking:!0,bundle:!0,outfile:a,format:o,target:["node20"],keepNames:!0,external:h,packages:"external"});const y=Date.now();return await import(`${a}?t=${y}`)},W=async t=>{const e=J(t),s=l.join(e,"salty.config.js"),{config:n}=await import(s);return n},Q=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},gt=async(t,e=Q())=>{try{e?Z.info("Generating CSS in production mode! 🔥"):Z.info("Generating CSS in development mode! 🚀");const s=[],n=[],r=J(t),c=l.join(r,"index.css");(()=>{f.existsSync(r)&&rt.execSync("rm -rf "+r),f.mkdirSync(r),f.mkdirSync(l.join(r,"css")),f.mkdirSync(l.join(r,"types"))})(),await v(t);const a=await W(t);async function h(u,F){const O=["node_modules","saltygen"],m=f.statSync(u);if(m.isDirectory()){const S=f.readdirSync(u);if(O.some(i=>u.includes(i)))return;await Promise.all(S.map(i=>h(l.join(u,i),l.join(F,i))))}else if(m.isFile()&&_(u)){const p=await I(t,u,r),i=[];Object.entries(p).forEach(([C,$])=>{if($.isKeyframes&&$.css){const z=`${$.animationName}.css`,st=`css/${z}`,nt=l.join(r,st);s.push(z),f.writeFileSync(nt,$.css);return}if(!$.generator)return;const x=$.generator._withBuildContext({name:C,config:a,prod:e}),D=`${x.hash}-${x.priority}.css`;n[x.priority]||(n[x.priority]=[]),n[x.priority].push(D),i.push(D);const N=`css/${D}`,et=l.join(r,N);f.writeFileSync(et,x.css)});const j=i.map(C=>`@import url('./${C}');`).join(`
9
9
  `),d=q(u,6),P=l.join(r,`css/${d}.css`);f.writeFileSync(P,j)}}await h(t,r);const o=s.map(u=>`@import url('./css/${u}');`).join(`
10
- `);let C=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
10
+ `);let k=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
11
 
12
12
  ${["variables.css","global.css","templates.css"].filter(u=>{try{return f.readFileSync(l.join(r,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
13
13
  `)}
14
14
  ${o}`;if(a.importStrategy!=="component"){const u=n.flat().map(F=>`@import url('./css/${F}');`).join(`
15
- `);C+=u}f.writeFileSync(c,C)}catch(s){console.error(s)}},mt=async(t,e)=>{try{const s=[],n=l.join(t,"./saltygen"),r=l.join(n,"index.css");if(_(e)){const g=await W(t),a=await I(t,e,n);Object.entries(a).forEach(([w,C])=>{if(!C.generator)return;const u=C.generator._withBuildContext({name:w,config:g}),F=`${u.hash}-${u.priority}.css`,D=`css/${F}`,m=l.join(n,D);s.push(F),f.writeFileSync(m,u.css)});const h=f.readFileSync(r,"utf8").split(`
15
+ `);k+=u}f.writeFileSync(c,k)}catch(s){console.error(s)}},mt=async(t,e)=>{try{const s=[],n=l.join(t,"./saltygen"),r=l.join(n,"index.css");if(_(e)){const g=await W(t),a=await I(t,e,n);Object.entries(a).forEach(([w,k])=>{if(!k.generator)return;const u=k.generator._withBuildContext({name:w,config:g}),F=`${u.hash}-${u.priority}.css`,O=`css/${F}`,m=l.join(n,O);s.push(F),f.writeFileSync(m,u.css)});const h=f.readFileSync(r,"utf8").split(`
16
16
  `),o=s.map(w=>`@import url('../saltygen/css/${w}');`),b=[...new Set([...h,...o])].join(`
17
- `);f.writeFileSync(r,b)}}catch(s){console.error(s)}},ht=async(t,e,s=Q())=>{try{const n=l.join(t,"./saltygen");if(_(e)){const c=f.readFileSync(e,"utf8");c.replace(/^(?!export\s)const\s.*/gm,b=>`export ${b}`)!==c&&await Z.writeFile(e,c);const a=await W(t),h=await I(t,e,n);let o=c;Object.entries(h).forEach(([b,w])=>{var T;if(w.isKeyframes||!w.generator)return;const C=w.generator._withBuildContext({name:b,config:a,prod:s}),u=new RegExp(`\\s${b}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(c);if(!u)return console.error("Could not find the original declaration");const F=(T=u.at(1))==null?void 0:T.trim(),D=new RegExp(`\\s${b}[=\\s]+styled\\(`,"g").exec(o);if(!D)return console.error("Could not find the original declaration");const{index:m}=D;let S=!1;const p=setTimeout(()=>S=!0,5e3);let i=0,j=!1,d=0;for(;!j&&!S;){const N=o[m+i];N==="("&&d++,N===")"&&d--,d===0&&N===")"&&(j=!0),i>o.length&&(S=!0),i++}if(!S)clearTimeout(p);else throw new Error("Failed to find the end of the styled call and timed out");const P=m+i,k=o.slice(m,P),$=o,x=` ${b} = styled(${F}, "${C.classNames}", ${JSON.stringify(C.props)});`;o=o.replace(k,x),$===o&&console.error("Minimize file failed to change content",{name:b,tagName:F})});const y=q(e,6);return a.importStrategy==="component"&&(o=`import '../../saltygen/css/${y}.css';
17
+ `);f.writeFileSync(r,b)}}catch(s){console.error(s)}},ht=async(t,e,s=Q())=>{try{const n=l.join(t,"./saltygen");if(_(e)){const c=f.readFileSync(e,"utf8");c.replace(/^(?!export\s)const\s.*/gm,b=>`export ${b}`)!==c&&await L.writeFile(e,c);const a=await W(t),h=await I(t,e,n);let o=c;Object.entries(h).forEach(([b,w])=>{var D;if(w.isKeyframes||!w.generator)return;const k=w.generator._withBuildContext({name:b,config:a,prod:s}),u=new RegExp(`\\s${b}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(c);if(!u)return console.error("Could not find the original declaration");const F=(D=u.at(1))==null?void 0:D.trim(),O=new RegExp(`\\s${b}[=\\s]+styled\\(`,"g").exec(o);if(!O)return console.error("Could not find the original declaration");const{index:m}=O;let S=!1;const p=setTimeout(()=>S=!0,5e3);let i=0,j=!1,d=0;for(;!j&&!S;){const N=o[m+i];N==="("&&d++,N===")"&&d--,d===0&&N===")"&&(j=!0),i>o.length&&(S=!0),i++}if(!S)clearTimeout(p);else throw new Error("Failed to find the end of the styled call and timed out");const P=m+i,C=o.slice(m,P),$=o,x=` ${b} = styled(${F}, "${k.classNames}", ${JSON.stringify(k.props)});`;o=o.replace(C,x),$===o&&console.error("Minimize file failed to change content",{name:b,tagName:F})});const y=q(e,6);return a.importStrategy==="component"&&(o=`import '../../saltygen/css/${y}.css';
18
18
  ${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}},tt=t=>({name:"stylegen",buildStart:()=>gt(t),load:async e=>{if(_(e))return await ht(t,e)},watchChange:{handler:async e=>{_(e)&&await mt(t,e),e.includes("salty.config")&&await v(t)}}});exports.default=tt;exports.saltyPlugin=tt;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import * as K from "esbuild";
1
+ import * as L from "esbuild";
2
2
  import { execSync as ot } from "child_process";
3
3
  import { join as f, parse as rt } from "path";
4
- import { existsSync as B, writeFileSync as P, mkdirSync as A, statSync as it, readdirSync as ct, readFileSync as J } from "fs";
4
+ import { existsSync as B, writeFileSync as D, mkdirSync as A, statSync as ct, readdirSync as it, readFileSync as J } from "fs";
5
5
  import { readFile as at, writeFile as lt } from "fs/promises";
6
6
  import { createLogger as ft, format as _, transports as pt } from "winston";
7
7
  const H = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), ut = (t, e) => {
@@ -24,21 +24,21 @@ const dt = (t, e) => {
24
24
  if (!e) return { result: t };
25
25
  const s = [];
26
26
  return Object.values(e).forEach((o) => {
27
- const { pattern: r, transform: c } = o;
27
+ const { pattern: r, transform: i } = o;
28
28
  t = t.replace(r, (d) => {
29
- const { value: a, css: m } = c(d);
29
+ const { value: a, css: m } = i(d);
30
30
  return m && s.push(m), a;
31
31
  });
32
32
  }), { result: t, additionalCss: s };
33
33
  }, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${N(o[1].replaceAll(".", "-"))})`) } : { result: t }, E = (t, e, s, o) => {
34
34
  if (!t) return "";
35
- const r = [], c = Object.entries(t).reduce((a, [m, n]) => {
35
+ const r = [], i = Object.entries(t).reduce((a, [m, n]) => {
36
36
  const g = m.trim();
37
37
  if (typeof n == "function" && (n = n()), typeof n == "object") {
38
38
  if (!n) return a;
39
39
  if (g === "variants")
40
- return Object.entries(n).forEach(([p, i]) => {
41
- i && Object.entries(i).forEach(([h, u]) => {
40
+ return Object.entries(n).forEach(([p, c]) => {
41
+ c && Object.entries(c).forEach(([h, u]) => {
42
42
  if (!u) return;
43
43
  const x = `${e}.${p}-${h}`, F = E(u, x);
44
44
  r.push(F);
@@ -48,16 +48,16 @@ const dt = (t, e) => {
48
48
  return a;
49
49
  if (g === "compoundVariants")
50
50
  return n.forEach((p) => {
51
- const { css: i, ...h } = p, u = Object.entries(h).reduce((F, [w, k]) => `${F}.${w}-${k}`, e), x = E(i, u);
51
+ const { css: c, ...h } = p, u = Object.entries(h).reduce((F, [w, k]) => `${F}.${w}-${k}`, e), x = E(c, u);
52
52
  r.push(x);
53
53
  }), a;
54
54
  if (g.startsWith("@")) {
55
- const p = E(n, e), i = `${g} {
55
+ const p = E(n, e), c = `${g} {
56
56
  ${p.replace(`
57
57
  `, `
58
58
  `)}
59
59
  }`;
60
- return r.push(i), a;
60
+ return r.push(c), a;
61
61
  }
62
62
  const y = m.includes("&") ? g.replace("&", e) : g.startsWith(":") ? `${e}${g}` : `${e} ${g}`, b = E(n, y);
63
63
  return r.push(b), a;
@@ -67,35 +67,35 @@ const dt = (t, e) => {
67
67
  if (typeof n != "string")
68
68
  if ("toString" in n) n = n.toString();
69
69
  else return a;
70
- const { modifiers: l } = {}, D = function* () {
70
+ const { modifiers: l } = {}, P = function* () {
71
71
  yield q(n), yield dt(n, l);
72
72
  }();
73
- for (const { result: y, additionalCss: b = [] } of D)
73
+ for (const { result: y, additionalCss: b = [] } of P)
74
74
  n = y, b.forEach((p) => {
75
- const i = E(p, "");
76
- S(i, "");
75
+ const c = E(p, "");
76
+ S(c, "");
77
77
  });
78
78
  return C(n);
79
79
  }, "");
80
- if (!c) return r.join(`
80
+ if (!i) return r.join(`
81
81
  `);
82
- if (!e) return c;
82
+ if (!e) return i;
83
83
  let d = "";
84
- return d = `${e} { ${c} }`, [d, ...r].join(`
84
+ return d = `${e} { ${i} }`, [d, ...r].join(`
85
85
  `);
86
86
  }, U = (t, e = []) => {
87
87
  if (!t) return "";
88
88
  const s = [], o = {};
89
- if (Object.entries(t).forEach(([r, c]) => {
90
- if (typeof c == "object") {
91
- if (!c) return;
92
- const d = r.trim(), a = U(c, [...e, d]);
89
+ if (Object.entries(t).forEach(([r, i]) => {
90
+ if (typeof i == "object") {
91
+ if (!i) return;
92
+ const d = r.trim(), a = U(i, [...e, d]);
93
93
  s.push(a);
94
94
  } else
95
- o[r] = c;
95
+ o[r] = i;
96
96
  }), Object.keys(o).length) {
97
- const r = e.map(N).join("-"), c = E(o, `.${r}`);
98
- s.push(c);
97
+ const r = e.map(N).join("-"), i = E(o, `.${r}`);
98
+ s.push(i);
99
99
  }
100
100
  return s.join(`
101
101
  `);
@@ -117,7 +117,7 @@ const Y = async (t) => {
117
117
  if (T) return T;
118
118
  const e = await mt(t);
119
119
  return e === "module" ? T = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (T = "cjs"), T || "esm";
120
- }, L = ft({
120
+ }, K = ft({
121
121
  level: "debug",
122
122
  format: _.combine(_.colorize(), _.cli()),
123
123
  transports: [new pt.Console({})]
@@ -127,55 +127,55 @@ const Y = async (t) => {
127
127
  if (W.externalModules.length > 0) return W.externalModules;
128
128
  const e = f(t, "salty.config.ts"), o = J(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
129
129
  if (!o) return [];
130
- const r = o[1].split(",").map((c) => c.replace(/['"`]/g, "").trim());
130
+ const r = o[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
131
131
  return W.externalModules = r, r;
132
132
  }, R = (t) => f(t, "./saltygen"), ht = ["salty", "css", "styles", "styled"], $t = (t = []) => new RegExp(`\\.(${[...ht, ...t].join("|")})\\.`), V = (t, e = []) => $t(e).test(t), bt = async (t) => {
133
- const e = R(t), s = f(t, "salty.config.ts"), o = f(e, "salty.config.js"), r = await Y(t), c = Q(t);
134
- await K.build({
133
+ const e = R(t), s = f(t, "salty.config.ts"), o = f(e, "salty.config.js"), r = await Y(t), i = Q(t);
134
+ await L.build({
135
135
  entryPoints: [s],
136
136
  minify: !0,
137
137
  treeShaking: !0,
138
138
  bundle: !0,
139
139
  outfile: o,
140
140
  format: r,
141
- external: c
141
+ external: i
142
142
  });
143
143
  const d = Date.now(), { config: a } = await import(`${o}?t=${d}`);
144
144
  return a;
145
145
  }, v = async (t) => {
146
- const e = await bt(t), s = /* @__PURE__ */ new Set(), o = (p, i = []) => p ? Object.entries(p).flatMap(([h, u]) => {
146
+ const e = await bt(t), s = /* @__PURE__ */ new Set(), o = (p, c = []) => p ? Object.entries(p).flatMap(([h, u]) => {
147
147
  if (!u) return;
148
- if (typeof u == "object") return o(u, [...i, h]);
149
- const x = [...i, h].join(".");
148
+ if (typeof u == "object") return o(u, [...c, h]);
149
+ const x = [...c, h].join(".");
150
150
  s.add(`"${x}"`);
151
- const F = [...i.map(N), N(h)].join("-"), { result: w } = q(u);
151
+ const F = [...c.map(N), N(h)].join("-"), { result: w } = q(u);
152
152
  return `--${F}: ${w};`;
153
- }) : [], r = (p) => p ? Object.entries(p).flatMap(([i, h]) => {
153
+ }) : [], r = (p) => p ? Object.entries(p).flatMap(([c, h]) => {
154
154
  const u = o(h);
155
- return i === "base" ? u.join("") : `${i} { ${u.join("")} }`;
156
- }) : [], c = (p) => p ? Object.entries(p).flatMap(([i, h]) => Object.entries(h).flatMap(([u, x]) => {
157
- const F = o(x, [i]), w = `.${i}-${u}, [data-${i}="${u}"]`, k = F.join("");
155
+ return c === "base" ? u.join("") : `${c} { ${u.join("")} }`;
156
+ }) : [], i = (p) => p ? Object.entries(p).flatMap(([c, h]) => Object.entries(h).flatMap(([u, x]) => {
157
+ const F = o(x, [c]), w = `.${c}-${u}, [data-${c}="${u}"]`, k = F.join("");
158
158
  return `${w} { ${k} }`;
159
- })) : [], d = o(e.variables), a = r(e.responsiveVariables), m = c(e.conditionalVariables), n = R(t), g = f(n, "css/variables.css"), $ = `:root { ${d.join("")} ${a.join("")} } ${m.join("")}`;
160
- P(g, $);
159
+ })) : [], d = o(e.variables), a = r(e.responsiveVariables), m = i(e.conditionalVariables), n = R(t), g = f(n, "css/variables.css"), $ = `:root { ${d.join("")} ${a.join("")} } ${m.join("")}`;
160
+ D(g, $);
161
161
  const S = f(n, "types/css-tokens.d.ts"), l = `type VariableTokens = ${[...s].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
162
- P(S, l);
163
- const j = f(n, "css/global.css"), D = E(e.global, "");
164
- P(j, D);
162
+ D(S, l);
163
+ const j = f(n, "css/global.css"), P = E(e.global, "");
164
+ D(j, P);
165
165
  const y = f(n, "css/templates.css"), b = U(e.templates);
166
- P(y, b);
166
+ D(y, b);
167
167
  }, Z = async (t, e, s) => {
168
168
  const o = I(e), r = f(s, "./temp");
169
169
  B(r) || A(r);
170
- const c = rt(e);
170
+ const i = rt(e);
171
171
  let d = J(e, "utf8");
172
- d = d.replace("styled(DynaLink", "styled('div'");
172
+ d = d.replace(/styled\([^"'`{,]+,/g, "styled('div'");
173
173
  const a = f(s, "js", o + ".js"), m = Q(t), n = await Y(t);
174
- await K.build({
174
+ await L.build({
175
175
  stdin: {
176
176
  contents: d,
177
- sourcefile: c.base,
178
- resolveDir: c.dir,
177
+ sourcefile: i.base,
178
+ resolveDir: i.dir,
179
179
  loader: "ts"
180
180
  },
181
181
  minify: !1,
@@ -201,24 +201,24 @@ const Y = async (t) => {
201
201
  }
202
202
  }, wt = async (t, e = tt()) => {
203
203
  try {
204
- e ? L.info("Generating CSS in production mode! 🔥") : L.info("Generating CSS in development mode! 🚀");
205
- const s = [], o = [], r = R(t), c = f(r, "index.css");
204
+ e ? K.info("Generating CSS in production mode! 🔥") : K.info("Generating CSS in development mode! 🚀");
205
+ const s = [], o = [], r = R(t), i = f(r, "index.css");
206
206
  (() => {
207
207
  B(r) && ot("rm -rf " + r), A(r), A(f(r, "css")), A(f(r, "types"));
208
208
  })(), await v(t);
209
209
  const a = await z(t);
210
210
  async function m(l, j) {
211
- const D = ["node_modules", "saltygen"], y = it(l);
211
+ const P = ["node_modules", "saltygen"], y = ct(l);
212
212
  if (y.isDirectory()) {
213
- const b = ct(l);
214
- if (D.some((i) => l.includes(i))) return;
215
- await Promise.all(b.map((i) => m(f(l, i), f(j, i))));
213
+ const b = it(l);
214
+ if (P.some((c) => l.includes(c))) return;
215
+ await Promise.all(b.map((c) => m(f(l, c), f(j, c))));
216
216
  } else if (y.isFile() && V(l)) {
217
- const p = await Z(t, l, r), i = [];
217
+ const p = await Z(t, l, r), c = [];
218
218
  Object.entries(p).forEach(([F, w]) => {
219
219
  if (w.isKeyframes && w.css) {
220
220
  const G = `${w.animationName}.css`, st = `css/${G}`, nt = f(r, st);
221
- s.push(G), P(nt, w.css);
221
+ s.push(G), D(nt, w.css);
222
222
  return;
223
223
  }
224
224
  if (!w.generator) return;
@@ -227,13 +227,13 @@ const Y = async (t) => {
227
227
  config: a,
228
228
  prod: e
229
229
  }), M = `${k.hash}-${k.priority}.css`;
230
- o[k.priority] || (o[k.priority] = []), o[k.priority].push(M), i.push(M);
230
+ o[k.priority] || (o[k.priority] = []), o[k.priority].push(M), c.push(M);
231
231
  const O = `css/${M}`, et = f(r, O);
232
- P(et, k.css);
232
+ D(et, k.css);
233
233
  });
234
- const h = i.map((F) => `@import url('./${F}');`).join(`
234
+ const h = c.map((F) => `@import url('./${F}');`).join(`
235
235
  `), u = I(l, 6), x = f(r, `css/${u}.css`);
236
- P(x, h);
236
+ D(x, h);
237
237
  }
238
238
  }
239
239
  await m(t, r);
@@ -255,7 +255,7 @@ ${n}`;
255
255
  `);
256
256
  C += l;
257
257
  }
258
- P(c, C);
258
+ D(i, C);
259
259
  } catch (s) {
260
260
  console.error(s);
261
261
  }
@@ -269,13 +269,13 @@ ${n}`;
269
269
  const l = C.generator._withBuildContext({
270
270
  name: S,
271
271
  config: d
272
- }), j = `${l.hash}-${l.priority}.css`, D = `css/${j}`, y = f(o, D);
273
- s.push(j), P(y, l.css);
272
+ }), j = `${l.hash}-${l.priority}.css`, P = `css/${j}`, y = f(o, P);
273
+ s.push(j), D(y, l.css);
274
274
  });
275
275
  const m = J(r, "utf8").split(`
276
276
  `), n = s.map((S) => `@import url('../saltygen/css/${S}');`), $ = [.../* @__PURE__ */ new Set([...m, ...n])].join(`
277
277
  `);
278
- P(r, $);
278
+ D(r, $);
279
279
  }
280
280
  } catch (s) {
281
281
  console.error(s);
@@ -284,10 +284,10 @@ ${n}`;
284
284
  try {
285
285
  const o = f(t, "./saltygen");
286
286
  if (V(e)) {
287
- const c = J(e, "utf8");
288
- c.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== c && await lt(e, c);
287
+ const i = J(e, "utf8");
288
+ i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await lt(e, i);
289
289
  const a = await z(t), m = await Z(t, e, o);
290
- let n = c;
290
+ let n = i;
291
291
  Object.entries(m).forEach(([$, S]) => {
292
292
  var M;
293
293
  if (S.isKeyframes || !S.generator) return;
@@ -295,21 +295,21 @@ ${n}`;
295
295
  name: $,
296
296
  config: a,
297
297
  prod: s
298
- }), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
298
+ }), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
299
299
  if (!l) return console.error("Could not find the original declaration");
300
- const j = (M = l.at(1)) == null ? void 0 : M.trim(), D = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(n);
301
- if (!D) return console.error("Could not find the original declaration");
302
- const { index: y } = D;
300
+ const j = (M = l.at(1)) == null ? void 0 : M.trim(), P = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(n);
301
+ if (!P) return console.error("Could not find the original declaration");
302
+ const { index: y } = P;
303
303
  let b = !1;
304
304
  const p = setTimeout(() => b = !0, 5e3);
305
- let i = 0, h = !1, u = 0;
305
+ let c = 0, h = !1, u = 0;
306
306
  for (; !h && !b; ) {
307
- const O = n[y + i];
308
- O === "(" && u++, O === ")" && u--, u === 0 && O === ")" && (h = !0), i > n.length && (b = !0), i++;
307
+ const O = n[y + c];
308
+ O === "(" && u++, O === ")" && u--, u === 0 && O === ")" && (h = !0), c > n.length && (b = !0), c++;
309
309
  }
310
310
  if (!b) clearTimeout(p);
311
311
  else throw new Error("Failed to find the end of the styled call and timed out");
312
- const x = y + i, F = n.slice(y, x), w = n, k = ` ${$} = styled(${j}, "${C.classNames}", ${JSON.stringify(C.props)});`;
312
+ const x = y + c, F = n.slice(y, x), w = n, k = ` ${$} = styled(${j}, "${C.classNames}", ${JSON.stringify(C.props)});`;
313
313
  n = n.replace(F, k), w === n && console.error("Minimize file failed to change content", { name: $, tagName: j });
314
314
  });
315
315
  const g = I(e, 6);
@@ -319,7 +319,7 @@ ${n}`), n = n.replace("{ styled }", "{ styledClient as styled }"), n = n.replace
319
319
  } catch (o) {
320
320
  console.error("Error in minimizeFile:", o);
321
321
  }
322
- }, Pt = (t) => ({
322
+ }, Dt = (t) => ({
323
323
  name: "stylegen",
324
324
  buildStart: () => wt(t),
325
325
  load: async (e) => {
@@ -333,6 +333,6 @@ ${n}`), n = n.replace("{ styled }", "{ styledClient as styled }"), n = n.replace
333
333
  }
334
334
  });
335
335
  export {
336
- Pt as default,
337
- Pt as saltyPlugin
336
+ Dt as default,
337
+ Dt as saltyPlugin
338
338
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.102",
3
+ "version": "0.0.1-alpha.103",
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.102"
37
+ "@salty-css/core": "^0.0.1-alpha.103"
38
38
  }
39
39
  }