@salty-css/vite 0.0.1-alpha.203 → 0.0.1-alpha.205

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 +6 -6
  2. package/index.js +2 -3
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),c=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(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 mt=Dt(kt),dt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=dt(n%52)+s;return s=dt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Tt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},W=(t,e=5)=>{const s=Tt(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function M(t){return t?typeof t!="string"?M(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Et=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:i,transform:l}=o;s=s.replace(i,y=>{const{value:w,css:a}=l(y);return a&&n.push(a),w})}),{transformed:s,additionalCss:n}},gt=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},Mt=gt(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,vt=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:vt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),Y=async(t,e="",s)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const n=new Set,i=Object.entries(t).map(async([g,r])=>{const p=g.trim(),h=Jt(p),N=(P,T=";")=>`${h}:${P}${T}`;if(typeof r=="function"&&(r=r({scope:e,config:s})),r instanceof Promise&&(r=await r),typeof r=="object"){if(!r)return;if(r.isColor)return N(r.toString());if(p==="defaultVariants")return;if(p==="variants"){const F=Object.entries(r);for(const[D,x]of F){if(!x)return;const R=Object.entries(x);for(const[f,m]of R){if(!m)return;const b=`${e}.${D}-${f}`;(await Y(m,b,s)).forEach(C=>n.add(C))}}return}if(p==="compoundVariants"){for(const F of r){const{css:D,...x}=F,R=Object.entries(x).reduce((m,[b,u])=>`${m}.${b}-${u}`,e);(await Y(D,R,s)).forEach(m=>n.add(m))}return}if(p.startsWith("@")){const F=p,D=await G(r,e,s),x=`${F} { ${D} }`;n.add(x);return}const P=g.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`;(await Y(r,P,s)).forEach(F=>n.add(F));return}if(typeof r=="number"){const P=Vt(h,r);return N(P)}if(typeof r!="string")if("toString"in r)r=r.toString();else throw new Error(`Invalid value type for property ${h}`);return N(r)}),{modifiers:l}={},y=[gt(),Et(l)],a=(await Promise.all(i).then(g=>Promise.all(g.map(r=>y.reduce(async(p,h)=>{const N=await p;if(!N)return N;const _=await h(N);if(!_)return N;const{transformed:P,additionalCss:T}=_;let F="";if(T)for(const D of T)F+=await G(D,"");return`${F}${P}`},Promise.resolve(r)))))).join(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),c=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(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 mt=Dt(kt),dt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=dt(n%52)+s;return s=dt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Tt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},W=(t,e=5)=>{const s=Tt(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function M(t){return t?typeof t!="string"?M(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Et=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:i,transform:l}=o;s=s.replace(i,y=>{const{value:w,css:a}=l(y);return a&&n.push(a),w})}),{transformed:s,additionalCss:n}},gt=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},Mt=gt(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Jt=["Webkit","Moz","ms","O"],vt=t=>t.startsWith("-")?t:Jt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),Y=async(t,e="",s)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const n=new Set,i=Object.entries(t).map(async([g,r])=>{const p=g.trim(),h=vt(p),N=(P,T=";")=>`${h}:${P}${T}`;if(typeof r=="function"&&(r=r({scope:e,config:s})),r instanceof Promise&&(r=await r),typeof r=="object"){if(!r)return;if(r.isColor)return N(r.toString());if(p==="defaultVariants")return;if(p==="variants"){const F=Object.entries(r);for(const[D,x]of F){if(!x)return;const R=Object.entries(x);for(const[f,m]of R){if(!m)return;const b=`${e}.${D}-${f}`;(await Y(m,b,s)).forEach(C=>n.add(C))}}return}if(p==="compoundVariants"){for(const F of r){const{css:D,...x}=F,R=Object.entries(x).reduce((m,[b,u])=>`${m}.${b}-${u}`,e);(await Y(D,R,s)).forEach(m=>n.add(m))}return}if(p.startsWith("@")){const F=p,D=await G(r,e,s),x=`${F} { ${D} }`;n.add(x);return}const P=g.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`;(await Y(r,P,s)).forEach(F=>n.add(F));return}if(typeof r=="number"){const P=Vt(h,r);return N(P)}if(typeof r!="string")if("toString"in r)r=r.toString();else throw new Error(`Invalid value type for property ${h}`);return N(r)}),{modifiers:l}={},y=[gt(),Et(l)],a=(await Promise.all(i).then(g=>Promise.all(g.map(r=>y.reduce(async(p,h)=>{const N=await p;if(!N)return N;const _=await h(N);if(!_)return N;const{transformed:P,additionalCss:T}=_;let F="";if(T)for(const D of T)F+=await G(D,"");return`${F}${P}`},Promise.resolve(r)))))).join(`
2
2
  `);if(!a.trim())return n;const S=e?`${e} { ${a} }`:a;return n.add(S),n},G=async(t,e,s)=>[...await Y(t,e,s)].join(`
3
- `),ht=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,i]of Object.entries(t))if(typeof i=="function")console.log("Function found",o);else if(i&&typeof i=="object"){const l=o.trim(),y=await ht(i,[...e,l]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(M).join("-"),i=await G(n,`.${o}`);s.push(i)}return s.join(`
4
- `)},zt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=wt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},wt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?wt(o,i,s):s.add(e)}),[...s]):[],St=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:St(c.join(t,".."))},At=async t=>{const e=St(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await At(t);if(e)return e.type};let z;const bt=async t=>{if(z)return z;const e=await Wt(t);return e==="module"?z="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function $t(t){return t?typeof t!="string"?$t(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?".":"")+e.toLowerCase()):""}const It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},A=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),v={externalModules:[],rcFile:void 0,destDir:void 0},jt=t=>{if(v.externalModules.length>0)return v.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return v.externalModules=n,n},J=async t=>{if(v.destDir)return v.destDir;const e=await at(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return v.destDir=s,s},Ft=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ft,...t].join("|")})\\.`),I=(t,e=[])=>qt(e).test(t),Ct=async t=>{if(v.rcFile)return v.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):Ct(c.join(t,".."))},at=async t=>{var n,o;const e=await Ct(t),s=(n=e.projects)==null?void 0:n.find(i=>t.endsWith(i.dir||""));return s||((o=e.projects)==null?void 0:o.find(i=>i.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await J(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await bt(t),l=jt(n);await mt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:l});const y=Date.now(),{config:w}=await import(`${o}?t=${y}`);return w},Lt=async(t,e)=>{var lt,ft;const s=await J(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async $=>{const{contents:j,outputFilePath:V}=await et(t,$,s);Object.entries(j).forEach(([O,E])=>{E.isMedia?n.mediaQueries.push([O,E]):E.isGlobalDefine?n.globalStyles.push(E):E.isDefineVariables?n.variables.push(E):E.isDefineTemplates&&n.templates.push(E._setPath(V))})}));const o=await Ht(t),i={...o},l=new Set,y=($,j=[])=>$?Object.entries($).flatMap(([V,O])=>{if(!O)return;if(typeof O=="object")return y(O,[...j,V]);const E=$t(V),nt=M(V),ot=[...j,E].join(".");l.add(`"${ot}"`);const X=[...j.map(M),nt].join("-"),ut=Mt(O);return ut?`--${X}: ${ut.transformed};`:`--${X}: ${O};`}):[],w=$=>$?Object.entries($).flatMap(([j,V])=>{const O=y(V);return j==="base"?O.join(""):`${j} { ${O.join("")} }`}):[],a=$=>$?Object.entries($).flatMap(([j,V])=>Object.entries(V).flatMap(([O,E])=>{const nt=y(E,[j]),ot=`.${j}-${O}, [data-${j}="${O}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],S=$=>({...$,responsive:void 0,conditional:void 0}),g=$=>n.variables.map(j=>$==="static"?S(j._current):j._current[$]),r=A(S(o.variables),g("static")),p=y(r),h=A((lt=o.variables)==null?void 0:lt.responsive,g("responsive")),N=w(h),_=A((ft=o.variables)==null?void 0:ft.conditional,g("conditional")),P=a(_),T=c.join(s,"css/_variables.css"),F=`:root { ${p.join("")} ${N.join("")} } ${P.join("")}`;d.writeFileSync(T,F),i.staticVariables=r;const D=c.join(s,"css/_global.css"),x=A(o.global,n.globalStyles),R=await G(x,"");d.writeFileSync(D,`@layer global { ${R} }`);const f=c.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(b,"");d.writeFileSync(f,`@layer reset { ${u} }`);const C=c.join(s,"css/_templates.css"),k=A(o.templates,n.templates),Z=await ht(k),q=zt(k);d.writeFileSync(C,Z),i.templates=k;const H=Zt(n.templates);i.templatePaths=Object.fromEntries(Object.entries(H).map(([$,j])=>[$,j._path||"nope"]));const{mediaQueries:L}=n;i.mediaQueries=Object.fromEntries(L.map(([$,j])=>[`@${$}`,j]));const K=L.map(([$])=>`'@${$}'`).join(" | "),st=c.join(s,"types/css-tokens.d.ts"),Q=`
3
+ `),ht=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,i]of Object.entries(t))if(typeof i!="function")if(i&&typeof i=="object"){const l=o.trim(),y=await ht(i,[...e,l]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(M).join("-"),i=await G(n,`.${o}`);s.push(i)}return s.join(`
4
+ `)},zt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=wt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},wt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?wt(o,i,s):s.add(e)}),[...s]):[],St=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:St(c.join(t,".."))},At=async t=>{const e=St(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await At(t);if(e)return e.type};let z;const bt=async t=>{if(z)return z;const e=await Wt(t);return e==="module"?z="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function $t(t){return t?typeof t!="string"?$t(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?".":"")+e.toLowerCase()):""}const It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},A=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),J={externalModules:[],rcFile:void 0,destDir:void 0},jt=t=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},v=async t=>{if(J.destDir)return J.destDir;const e=await at(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return J.destDir=s,s},Ft=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ft,...t].join("|")})\\.`),I=(t,e=[])=>qt(e).test(t),Ct=async t=>{if(J.rcFile)return J.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Ct(c.join(t,".."))},at=async t=>{var n,o;const e=await Ct(t),s=(n=e.projects)==null?void 0:n.find(i=>t.endsWith(i.dir||""));return s||((o=e.projects)==null?void 0:o.find(i=>i.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await v(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),i=await bt(t),l=jt(n);await mt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:l});const y=Date.now(),{config:w}=await import(`${o}?t=${y}`);return w},Lt=async(t,e)=>{var lt,ft;const s=await v(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async $=>{const{contents:j,outputFilePath:V}=await et(t,$,s);Object.entries(j).forEach(([O,E])=>{E.isMedia?n.mediaQueries.push([O,E]):E.isGlobalDefine?n.globalStyles.push(E):E.isDefineVariables?n.variables.push(E):E.isDefineTemplates&&n.templates.push(E._setPath(V))})}));const o=await Ht(t),i={...o},l=new Set,y=($,j=[])=>$?Object.entries($).flatMap(([V,O])=>{if(!O)return;if(typeof O=="object")return y(O,[...j,V]);const E=$t(V),nt=M(V),ot=[...j,E].join(".");l.add(`"${ot}"`);const X=[...j.map(M),nt].join("-"),ut=Mt(O);return ut?`--${X}: ${ut.transformed};`:`--${X}: ${O};`}):[],w=$=>$?Object.entries($).flatMap(([j,V])=>{const O=y(V);return j==="base"?O.join(""):`${j} { ${O.join("")} }`}):[],a=$=>$?Object.entries($).flatMap(([j,V])=>Object.entries(V).flatMap(([O,E])=>{const nt=y(E,[j]),ot=`.${j}-${O}, [data-${j}="${O}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],S=$=>({...$,responsive:void 0,conditional:void 0}),g=$=>n.variables.map(j=>$==="static"?S(j._current):j._current[$]),r=A(S(o.variables),g("static")),p=y(r),h=A((lt=o.variables)==null?void 0:lt.responsive,g("responsive")),N=w(h),_=A((ft=o.variables)==null?void 0:ft.conditional,g("conditional")),P=a(_),T=c.join(s,"css/_variables.css"),F=`:root { ${p.join("")} ${N.join("")} } ${P.join("")}`;d.writeFileSync(T,F),i.staticVariables=r;const D=c.join(s,"css/_global.css"),x=A(o.global,n.globalStyles),R=await G(x,"");d.writeFileSync(D,`@layer global { ${R} }`);const f=c.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(b,"");d.writeFileSync(f,`@layer reset { ${u} }`);const C=c.join(s,"css/_templates.css"),k=A(o.templates,n.templates),Z=await ht(k),q=zt(k);d.writeFileSync(C,Z),i.templates=k;const H=Zt(n.templates);i.templatePaths=Object.fromEntries(Object.entries(H).map(([$,j])=>[$,j._path||"nope"]));const{mediaQueries:L}=n;i.mediaQueries=Object.fromEntries(L.map(([$,j])=>[`@${$}`,j]));const K=L.map(([$])=>`'@${$}'`).join(" | "),st=c.join(s,"types/css-tokens.d.ts"),Q=`
5
5
  // Variable types
6
6
  type VariableTokens = ${[...l].join("|")};
7
7
  type PropertyValueToken = \`{\${VariableTokens}}\`;
@@ -18,7 +18,7 @@
18
18
 
19
19
  ${t}`:`globalThis.saltyConfig = {};
20
20
 
21
- ${t}`}catch{return t}},et=async(t,e,s)=>{const n=W(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const i=c.parse(e);let l=d.readFileSync(e,"utf8");l=pt(l),l=Bt(l,t);const y=c.join(s,"js",n+".js"),w=await at(t),a=c.join(t,(w==null?void 0:w.configDir)||"","salty.config.ts"),S=jt(a),g=await bt(t);await mt.build({stdin:{contents:l,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:S,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},N=>{const _=d.readFileSync(N.path,"utf8");return{contents:pt(_),loader:"ts"}})}}]});const r=Date.now();return{contents:await import(`${y}?t=${r}`),outputFilePath:y}},Gt=async t=>{const e=await J(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ct=async t=>{const e=await Gt(t),s=await J(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return A(i,e)},xt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=xt(),s=!0)=>{try{const n=Date.now();e?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],i=[],l=await J(t),y=c.join(l,"index.css");s&&(()=>{d.existsSync(l)&&_t.execSync("rm -rf "+l),d.mkdirSync(l,{recursive:!0}),d.mkdirSync(c.join(l,"css")),d.mkdirSync(c.join(l,"types")),d.mkdirSync(c.join(l,"js")),d.mkdirSync(c.join(l,"cache"))})();const a=new Set,S=new Set;async function g(f){const m=["node_modules","saltygen"],b=d.statSync(f);if(b.isDirectory()){const u=d.readdirSync(f);if(m.some(k=>f.includes(k)))return;await Promise.all(u.map(k=>g(c.join(f,k))))}else if(b.isFile()&&I(f)){a.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&S.add(f)}}await g(t),await Lt(t,S);const r={keyframes:[],components:[],classNames:[]};await Promise.all([...a].map(async f=>{const{contents:m}=await et(t,f,l);Object.entries(m).forEach(([b,u])=>{u.isKeyframes?r.keyframes.push({value:u,src:f,name:b}):u.isClassName?r.classNames.push({...u,src:f,name:b}):u.generator&&r.components.push({...u,src:f,name:b})})}));const p=await ct(t);for(const f of r.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,u=`css/${b}`,C=c.join(l,u);o.push(b),d.writeFileSync(C,m.css)}const h={};for(const f of r.components){const{src:m,name:b}=f,u=f.generator._withBuildContext({callerName:b,isProduction:e,config:p});i[u.priority]||(i[u.priority]=[]),i[u.priority].push(u.cssFileName);const C=`css/${u.cssFileName}`,k=c.join(l,C);d.writeFileSync(k,await u.css),p.importStrategy==="component"&&(h[m]?h[m].push(u.cssFileName):h[m]=[u.cssFileName])}for(const f of r.classNames){const{src:m,name:b}=f,u=f.generator._withBuildContext({callerName:b,isProduction:e,config:p});i[0].push(u.cssFileName);const C=`css/${u.cssFileName}`,k=c.join(l,C);d.writeFileSync(k,await u.css),p.importStrategy==="component"&&(h[m]?h[m].push(u.cssFileName):h[m]=[u.cssFileName])}p.importStrategy==="component"&&Object.entries(h).forEach(([f,m])=>{const b=m.map(q=>`@import url('./${q}');`).join(`
21
+ ${t}`}catch{return t}},et=async(t,e,s)=>{const n=W(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const i=c.parse(e);let l=d.readFileSync(e,"utf8");l=pt(l),l=Bt(l,t);const y=c.join(s,"js",n+".js"),w=await at(t),a=c.join(t,(w==null?void 0:w.configDir)||"","salty.config.ts"),S=jt(a),g=await bt(t);await mt.build({stdin:{contents:l,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:S,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},N=>{const _=d.readFileSync(N.path,"utf8");return{contents:pt(_),loader:"ts"}})}}]});const r=Date.now();return{contents:await import(`${y}?t=${r}`),outputFilePath:y}},Gt=async t=>{const e=await v(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ct=async t=>{const e=await Gt(t),s=await v(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return A(i,e)},xt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=xt(),s=!0)=>{try{const n=Date.now();e?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],i=[],l=await v(t),y=c.join(l,"index.css");s&&(()=>{d.existsSync(l)&&_t.execSync("rm -rf "+l),d.mkdirSync(l,{recursive:!0}),d.mkdirSync(c.join(l,"css")),d.mkdirSync(c.join(l,"types")),d.mkdirSync(c.join(l,"js")),d.mkdirSync(c.join(l,"cache"))})();const a=new Set,S=new Set;async function g(f){const m=["node_modules","saltygen"],b=d.statSync(f);if(b.isDirectory()){const u=d.readdirSync(f);if(m.some(k=>f.includes(k)))return;await Promise.all(u.map(k=>g(c.join(f,k))))}else if(b.isFile()&&I(f)){a.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&S.add(f)}}await g(t),await Lt(t,S);const r={keyframes:[],components:[],classNames:[]};await Promise.all([...a].map(async f=>{const{contents:m}=await et(t,f,l);Object.entries(m).forEach(([b,u])=>{u.isKeyframes?r.keyframes.push({value:u,src:f,name:b}):u.isClassName?r.classNames.push({...u,src:f,name:b}):u.generator&&r.components.push({...u,src:f,name:b})})}));const p=await ct(t);for(const f of r.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,u=`css/${b}`,C=c.join(l,u);o.push(b),d.writeFileSync(C,m.css)}const h={};for(const f of r.components){const{src:m,name:b}=f,u=f.generator._withBuildContext({callerName:b,isProduction:e,config:p});i[u.priority]||(i[u.priority]=[]),i[u.priority].push(u.cssFileName);const C=`css/${u.cssFileName}`,k=c.join(l,C);d.writeFileSync(k,await u.css),p.importStrategy==="component"&&(h[m]?h[m].push(u.cssFileName):h[m]=[u.cssFileName])}for(const f of r.classNames){const{src:m,name:b}=f,u=f.generator._withBuildContext({callerName:b,isProduction:e,config:p});i[0].push(u.cssFileName);const C=`css/${u.cssFileName}`,k=c.join(l,C);d.writeFileSync(k,await u.css),p.importStrategy==="component"&&(h[m]?h[m].push(u.cssFileName):h[m]=[u.cssFileName])}p.importStrategy==="component"&&Object.entries(h).forEach(([f,m])=>{const b=m.map(q=>`@import url('./${q}');`).join(`
22
22
  `),u=W(f,6),C=c.parse(f),k=M(C.name),Z=c.join(l,`css/f_${k}-${u}.css`);d.writeFileSync(Z,b)});const N=o.map(f=>`@import url('./css/${f}');`).join(`
23
23
  `);let F=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
24
24
 
@@ -30,11 +30,11 @@ ${st}
30
30
  /*end:${U}*/
31
31
  `},""),k=`l_${u}.css`,Z=c.join(l,"css",k),q=`@layer l${u} { ${C}
32
32
  }`;return d.writeFileSync(Z,q),`${m}
33
- @import url('./css/${k}');`},"");F+=f}d.writeFileSync(y,F);const x=Date.now()-n,R=x<200?"🔥":x<500?"🚀":x<1e3?"🎉":x<2e3?"🚗":x<5e3?"🤔":"🥴";it.info(`Generated CSS in ${x}ms! ${R}`)}catch(n){console.error(n)}},Ut=async(t,e)=>{try{const s=await J(t);if(I(e)){const o=[],i=await ct(t),{contents:l}=await et(t,e,s);for(const[y,w]of Object.entries(l)){if(w.isKeyframes&&w.css){const p=`css/${`a_${w.animationName}.css`}`,h=c.join(s,p);d.writeFileSync(h,await w.css);return}if(w.isClassName){const r=w.factory._withBuildContext({name:y});o[0].push(r.cssFileName);const p=`css/${r.cssFileName}`,h=c.join(s,p);d.writeFileSync(h,await r.css)}if(!w.generator)return;const a=w.generator._withBuildContext({name:y,config:i}),S=`css/${a.cssFileName}`,g=c.join(s,S);d.writeFileSync(g,await a.css),o[a.priority]||(o[a.priority]=[]),o[a.priority].push(a.cssFileName)}if(i.importStrategy!=="component")o.forEach((y,w)=>{const a=`l_${w}.css`,S=c.join(s,"css",a);let g=d.readFileSync(S,"utf8");y.forEach(r=>{var _;const p=c.join(s,"css",r),h=((_=/.*-([^-]+)-\d+.css/.exec(r))==null?void 0:_.at(1))||W(p,6);if(!g.includes(h)){const P=d.readFileSync(p,"utf8"),T=`/*start:${h}*/
33
+ @import url('./css/${k}');`},"");F+=f}d.writeFileSync(y,F);const x=Date.now()-n,R=x<200?"🔥":x<500?"🚀":x<1e3?"🎉":x<2e3?"🚗":x<5e3?"🤔":"🥴";it.info(`Generated CSS in ${x}ms! ${R}`)}catch(n){console.error(n)}},Ut=async(t,e)=>{try{const s=await v(t);if(I(e)){const o=[],i=await ct(t),{contents:l}=await et(t,e,s);for(const[y,w]of Object.entries(l)){if(w.isKeyframes&&w.css){const p=`css/${`a_${w.animationName}.css`}`,h=c.join(s,p);d.writeFileSync(h,await w.css);return}if(w.isClassName){const r=w.factory._withBuildContext({name:y});o[0].push(r.cssFileName);const p=`css/${r.cssFileName}`,h=c.join(s,p);d.writeFileSync(h,await r.css)}if(!w.generator)return;const a=w.generator._withBuildContext({name:y,config:i}),S=`css/${a.cssFileName}`,g=c.join(s,S);d.writeFileSync(g,await a.css),o[a.priority]||(o[a.priority]=[]),o[a.priority].push(a.cssFileName)}if(i.importStrategy!=="component")o.forEach((y,w)=>{const a=`l_${w}.css`,S=c.join(s,"css",a);let g=d.readFileSync(S,"utf8");y.forEach(r=>{var _;const p=c.join(s,"css",r),h=((_=/.*-([^-]+)-\d+.css/.exec(r))==null?void 0:_.at(1))||W(p,6);if(!g.includes(h)){const P=d.readFileSync(p,"utf8"),T=`/*start:${h}*/
34
34
  ${P}
35
35
  /*end:${h}*/
36
36
  `;g=`${g.replace(/\}$/,"")}
37
37
  ${T}
38
38
  }`}}),d.writeFileSync(S,g)});else{const y=o.flat().map(r=>`@import url('./${r}');`).join(`
39
- `),w=W(e,6),a=c.parse(e),S=M(a.name),g=c.join(s,`css/f_${S}-${w}.css`);d.writeFileSync(g,y)}}}catch(s){console.error(s)}},Qt=async(t,e,s=xt())=>{try{const n=await J(t);if(I(e)){const i=d.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==i&&await tt.writeFile(e,i);const y=await ct(t),{contents:w}=await et(t,e,n);let a=i;if(Object.entries(w).forEach(([S,g])=>{var u;if(g.isKeyframes||!g.generator)return;const r=g.generator._withBuildContext({name:S,config:y,prod:s}),p=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!p)return console.error("Could not find the original declaration");const h=(u=p.at(1))==null?void 0:u.trim(),N=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(a);if(!N)return console.error("Could not find the original declaration");const{index:_}=N;let P=!1;const T=setTimeout(()=>P=!0,5e3);let F=0,D=!1,x=0;for(;!D&&!P;){const C=a[_+F];C==="("&&x++,C===")"&&x--,x===0&&C===")"&&(D=!0),F>a.length&&(P=!0),F++}if(!P)clearTimeout(T);else throw new Error("Failed to find the end of the styled call and timed out");const R=_+F,f=a.slice(_,R),m=a,b=` ${S} = styled(${h}, "${r.classNames}", ${JSON.stringify(r.clientProps)});`;a=a.replace(f,b),m===a&&console.error("Minimize file failed to change content",{name:S,tagName:h})}),y.importStrategy==="component"){const S=W(e,6),g=c.parse(e);a=`import '../../saltygen/css/${`f_${M(g.name)}-${S}.css`}';
39
+ `),w=W(e,6),a=c.parse(e),S=M(a.name),g=c.join(s,`css/f_${S}-${w}.css`);d.writeFileSync(g,y)}}}catch(s){console.error(s)}},Qt=async(t,e,s=xt())=>{try{const n=await v(t);if(I(e)){const i=d.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==i&&await tt.writeFile(e,i);const y=await ct(t),{contents:w}=await et(t,e,n);let a=i;if(Object.entries(w).forEach(([S,g])=>{var u;if(g.isKeyframes||!g.generator)return;const r=g.generator._withBuildContext({name:S,config:y,prod:s}),p=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!p)return console.error("Could not find the original declaration");const h=(u=p.at(1))==null?void 0:u.trim(),N=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(a);if(!N)return console.error("Could not find the original declaration");const{index:_}=N;let P=!1;const T=setTimeout(()=>P=!0,5e3);let F=0,D=!1,x=0;for(;!D&&!P;){const C=a[_+F];C==="("&&x++,C===")"&&x--,x===0&&C===")"&&(D=!0),F>a.length&&(P=!0),F++}if(!P)clearTimeout(T);else throw new Error("Failed to find the end of the styled call and timed out");const R=_+F,f=a.slice(_,R),m=a,b=` ${S} = styled(${h}, "${r.classNames}", ${JSON.stringify(r.clientProps)});`;a=a.replace(f,b),m===a&&console.error("Minimize file failed to change content",{name:S,tagName:h})}),y.importStrategy==="component"){const S=W(e,6),g=c.parse(e);a=`import '../../saltygen/css/${`f_${M(g.name)}-${S}.css`}';
40
40
  ${a}`}return a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(n){console.error("Error in minimizeFile:",n)}},yt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!I(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Nt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(I(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await yt(e)&&await s.restart()},watchChange:{handler:async e=>{I(e)&&(await yt(e)||await Ut(t,e))}}});exports.default=Nt;exports.saltyPlugin=Nt;
package/index.js CHANGED
@@ -119,8 +119,7 @@ const At = (t) => (e) => {
119
119
  if (!t) return "";
120
120
  const s = [], n = {};
121
121
  for (const [o, i] of Object.entries(t))
122
- if (typeof i == "function") console.log("Function found", o);
123
- else if (i && typeof i == "object") {
122
+ if (typeof i != "function") if (i && typeof i == "object") {
124
123
  const c = o.trim(), p = await bt(i, [...e, c]);
125
124
  s.push(p);
126
125
  } else
@@ -131,7 +130,7 @@ const At = (t) => (e) => {
131
130
  }
132
131
  return s.join(`
133
132
  `);
134
- }, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = Ct(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
133
+ }, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = Ct(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
135
134
  const i = e ? `${e}.${n}` : n;
136
135
  return typeof o == "object" ? Ct(o, i, s) : s.add(e);
137
136
  }), [...s]) : [], St = (t) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.203",
3
+ "version": "0.0.1-alpha.205",
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.203"
37
+ "@salty-css/core": "^0.0.1-alpha.205"
38
38
  }
39
39
  }