@salty-css/vite 0.0.1-alpha.244 → 0.0.1-alpha.245

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 -2
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var Rt=Object.defineProperty;var Mt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const vt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),dt=require("fs/promises"),B=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function Jt(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 jt=Jt(vt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(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=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function v(t){return t?typeof t!="string"?v(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 qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,y=>{const{value:b,css:m}=i(y);return m&&n.push(m),b})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${v(o[1].replaceAll(".","-"))})`)},It=Ft(),Ht=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Ht.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Gt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${v(t)}`:v(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(t),i=async([p,u])=>{const $=p.trim(),P=Gt($),x=(M,k=";")=>`${P}:${M}${k}`,O={scope:e,config:s};if(typeof u=="function")return i([p,u(O)]);if(u instanceof Promise)return i([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return x(u.toString());if($==="defaultVariants")return;if($==="variants"){const D=Object.entries(u);for(const[a,g]of D){if(!g)continue;const j=Object.entries(g);for(const[f,C]of j){if(!C)continue;const N=`${e}.${a}-${f}`;(await nt(C,N,s)).forEach(J=>o.add(J))}}return}if($==="compoundVariants"){for(const D of u){const{css:a,...g}=D,j=Object.entries(g).reduce((C,[N,E])=>`${C}.${N}-${E}`,e);(await nt(a,j,s)).forEach(C=>o.add(C))}return}if($.startsWith("@")){const D=$,a=await X(u,e,s),g=`${D} { ${a} }`;o.add(g);return}const M=p.includes("&")?$.replace("&",e):$.startsWith(":")?`${e}${$}`:`${e} ${$}`;(await nt(u,M,s)).forEach(D=>o.add(D));return}if(typeof u=="number"){const M=Lt(P,u);return x(M)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return x(u)},y=r.map(i),{modifiers:b}={},m=[Ft(),qt(b)],w=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async($,P)=>{const x=await $;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:M,additionalCss:k}=O;let D="";if(k)for(const a of k)D+=await X(a,"");return`${D}${M}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
1
+ "use strict";var Rt=Object.defineProperty;var vt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>vt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Mt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),dt=require("fs/promises"),B=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function Jt(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 jt=Jt(Mt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(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=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(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 qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,y=>{const{value:b,css:m}=i(y);return m&&n.push(m),b})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${M(o[1].replaceAll(".","-"))})`)},It=Ft(),Ht=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Ht.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Gt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${M(t)}`:M(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(t),i=async([p,u])=>{const $=p.trim(),P=Gt($),x=(v,k=";")=>`${P}:${v}${k}`,O={scope:e,config:s};if(typeof u=="function")return i([p,u(O)]);if(u instanceof Promise)return i([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return x(u.toString());if($==="defaultVariants")return;if($==="variants"){const D=Object.entries(u);for(const[a,g]of D){if(!g)continue;const j=Object.entries(g);for(const[f,C]of j){if(!C)continue;const N=`${e}.${a}-${f}`;(await nt(C,N,s)).forEach(J=>o.add(J))}}return}if($==="compoundVariants"){for(const D of u){const{css:a,...g}=D,j=Object.entries(g).reduce((C,[N,E])=>`${C}.${N}-${E}`,e);(await nt(a,j,s)).forEach(C=>o.add(C))}return}if($.startsWith("@")){const D=$,a=await X(u,e,s),g=`${D} { ${a} }`;o.add(g);return}const v=p.includes("&")?$.replace("&",e):$.startsWith(":")?`${e}${$}`:`${e} ${$}`;(await nt(u,v,s)).forEach(D=>o.add(D));return}if(typeof u=="number"){const v=Lt(P,u);return x(v)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return x(u)},y=r.map(i),{modifiers:b}={},m=[Ft(),qt(b)],w=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async($,P)=>{const x=await $;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:v,additionalCss:k}=O;let D="";if(k)for(const a of k)D+=await X(a,"");return`${D}${v}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
2
2
  `);if(!w.trim())return Array.from(o);const h=e?`${e} {
3
3
  ${w}
4
4
  }`:w;return o.has(h)?Array.from(o):[h,...o]},X=async(t,e,s,n=!1)=>(await nt(t,e,s,n)).join(`
5
- `),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const i=o.trim(),y=await Ct(r,[...e,i]);s.push(y)}else n[o]=r;if(Object.keys(n).length){const o=e.map(v).join("-"),r="t_"+q(o,4),i=await X(n,`.${o}, .${r}`);s.push(i)}return s.join(`
6
- `)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,r,s):s.add(e)}),[...s]):[],Nt=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:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Zt=async t=>{const e=await Ut(t);if(e)return e.type};let H;const _t=async t=>{if(H)return H;const e=await Zt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},ut=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Bt={"*, *::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"}},L=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=lt.createSourceFile("temp.ts",t,lt.ScriptTarget.Latest,!0);function i(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===e){const b=y.getStart(),m=y.getEnd();clearTimeout(o),s([b,m])}y.forEachChild(i)}i(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.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 z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],ne=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),Q=(t,e=[])=>ne(e).test(t),Dt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(t,".."))},pt=async t=>{var n,o;const e=await Dt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},oe=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await _t(t),i=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const y=Date.now(),{config:b}=await import(`${o}?t=${y}`);return{config:b,path:o}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:_,outputFilePath:U}=await ot(t,F,s);Object.entries(_).forEach(([V,T])=>{T.isMedia?n.mediaQueries.push([V,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${V};;${U}`))})}));const{config:o,path:r}=await oe(t),i={...o},{mediaQueries:y}=n;i.mediaQueries=Object.fromEntries(y.map(([F,_])=>[`@${F}`,_]));const b=y.map(([F])=>`'@${F}'`).join(" | "),m=new Set,l=async(F,_=[])=>{if(!F)return[];const U=Object.entries(F).map(async([T,A])=>{const Z=async R=>{if(!R)return;if(R instanceof Promise)return await Z(await R);if(typeof R=="function")return await Z(await R());if(typeof R=="object")return await l(R,[..._,T]);const rt=xt(T),at=v(T),ct=[..._,rt].join(".");m.add(`"${ct}"`);const et=[..._.map(v),at].join("-"),wt=It(R);return wt?`--${et}: ${wt.transformed};`:`--${et}: ${R};`};return await Z(A)});return(await Promise.all(U)).flat()},w=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=await l(T);return V==="base"?A.join(""):i.mediaQueries[V]?`${i.mediaQueries[V]} { ${A.join("")} }`:`${V} { ${A.join("")} }`});return(await Promise.all(_)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=Object.entries(T).map(async([R,rt])=>{const at=await l(rt,[V]),ct=`.${V}-${R}, [data-${V}="${R}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(_)).flat()},S=F=>({...F,responsive:void 0,conditional:void 0}),p=F=>n.variables.map(_=>F==="static"?S(_._current):_._current[F]),u=L(S(o.variables),p("static")),$=await l(u),P=L((ht=o.variables)==null?void 0:ht.responsive,p("responsive")),x=await w(P),O=L((gt=o.variables)==null?void 0:gt.conditional,p("conditional")),M=await h(O),k=c.join(s,"css/_variables.css"),D=`:root { ${$.join("")} ${x.join("")} } ${M.join("")}`;d.writeFileSync(k,D),i.staticVariables=u;const a=c.join(s,"css/_global.css"),g=L(o.global,n.globalStyles),j=await X(g,"");d.writeFileSync(a,`@layer global { ${j} }`);const f=c.join(s,"css/_reset.css"),N=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Bt,E=await X(N,"");d.writeFileSync(f,`@layer reset { ${E} }`);const J=c.join(s,"css/_templates.css"),W=L(o.templates,n.templates),G=await Ct(W),Y=Kt(W);d.writeFileSync(J,`@layer templates { ${G} }`),i.templates=W;const it=o.templates?[ee(o.templates)._setPath(`config;;${r}`)]:[],K=Xt(n.templates,it);i.templatePaths=Object.fromEntries(Object.entries(K).map(([F,_])=>[F,_._path]));const tt=c.join(s,"types/css-tokens.d.ts"),Et=`
5
+ `),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const i=o.trim(),y=await Ct(r,[...e,i]);s.push(y)}else n[o]=r;if(Object.keys(n).length){const o=e.map(M).join("-"),r="t_"+q(o,4),i=await X(n,`.${o}, .${r}`);s.push(i)}return s.join(`
6
+ `)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,r,s):s.add(e)}),[...s]):[],Nt=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:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Zt=async t=>{const e=await Ut(t);if(e)return e.type};let H;const _t=async t=>{if(H)return H;const e=await Zt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},ut=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Bt={"*, *::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"}},L=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=lt.createSourceFile("temp.ts",t,lt.ScriptTarget.Latest,!0);function i(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===e){const b=y.getStart(),m=y.getEnd();clearTimeout(o),s([b,m])}y.forEachChild(i)}i(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.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 z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],ne=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),Q=(t,e=[])=>ne(e).test(t),Dt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(t,".."))},pt=async t=>{var n,o;const e=await Dt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},oe=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await _t(t),i=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const y=Date.now(),{config:b}=await import(`${o}?t=${y}`);return{config:b,path:o}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:_,outputFilePath:U}=await ot(t,F,s);Object.entries(_).forEach(([V,T])=>{T.isMedia?n.mediaQueries.push([V,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${V};;${U}`))})}));const{config:o,path:r}=await oe(t),i={...o},{mediaQueries:y}=n;i.mediaQueries=Object.fromEntries(y.map(([F,_])=>[`@${F}`,_]));const b=y.map(([F])=>`'@${F}'`).join(" | "),m=new Set,l=async(F,_=[])=>{if(!F)return[];const U=Object.entries(F).map(async([T,A])=>{const Z=async R=>{if(!R)return;if(R instanceof Promise)return await Z(await R);if(typeof R=="function")return await Z(await R());if(typeof R=="object")return await l(R,[..._,T]);const rt=xt(T),at=M(T),ct=[..._,rt].join(".");m.add(`"${ct}"`);const et=[..._.map(M),at].join("-"),wt=It(R);return wt?`--${et}: ${wt.transformed};`:`--${et}: ${R};`};return await Z(A)});return(await Promise.all(U)).flat()},w=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=await l(T);return V==="base"?A.join(""):i.mediaQueries[V]?`${i.mediaQueries[V]} { ${A.join("")} }`:`${V} { ${A.join("")} }`});return(await Promise.all(_)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=Object.entries(T).map(async([R,rt])=>{const at=await l(rt,[V]),ct=`.${V}-${R}, [data-${V}="${R}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(_)).flat()},S=F=>({...F,responsive:void 0,conditional:void 0}),p=F=>n.variables.map(_=>F==="static"?S(_._current):_._current[F]),u=L(S(o.variables),p("static")),$=await l(u),P=L((ht=o.variables)==null?void 0:ht.responsive,p("responsive")),x=await w(P),O=L((gt=o.variables)==null?void 0:gt.conditional,p("conditional")),v=await h(O),k=c.join(s,"css/_variables.css"),D=`:root { ${$.join("")} ${x.join("")} } ${v.join("")}`;d.writeFileSync(k,D),i.staticVariables=u;const a=c.join(s,"css/_global.css"),g=L(o.global,n.globalStyles),j=await X(g,"");d.writeFileSync(a,`@layer global { ${j} }`);const f=c.join(s,"css/_reset.css"),N=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Bt,E=await X(N,"");d.writeFileSync(f,`@layer reset { ${E} }`);const J=c.join(s,"css/_templates.css"),W=L(o.templates,n.templates),G=await Ct(W),Y=Kt(W);d.writeFileSync(J,`@layer templates { ${G} }`),i.templates=W;const it=o.templates?[ee(o.templates)._setPath(`config;;${r}`)]:[],K=Xt(n.templates,it);i.templatePaths=Object.fromEntries(Object.entries(K).map(([F,_])=>[F,_._path]));const tt=c.join(s,"types/css-tokens.d.ts"),Et=`
7
7
  // Variable types
8
8
  type VariableTokens = ${[...m].join("|")};
9
9
  type PropertyValueToken = \`{\${VariableTokens}}\`;
@@ -21,7 +21,7 @@
21
21
  ${t}`:`globalThis.saltyConfig = {};
22
22
 
23
23
  ${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=c.parse(e);let i=d.readFileSync(e,"utf8");i=bt(i),i=re(i,t);const y=c.join(s,"js",n+".js"),b=await pt(t),m=c.join(t,(b==null?void 0:b.configDir)||"","salty.config.ts"),l=Tt(m),w=await _t(t);await jt.build({stdin:{contents:i,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:w,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const $=d.readFileSync(u.path,"utf8");return{contents:bt($),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},ae=async t=>{const e=await I(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)},mt=async t=>{const e=await ae(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return L(r,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ce=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?ut.info("Generating CSS in production mode! 🔥"):ut.info("Generating CSS in development mode! 🚀");const o=[],r=[],i=await I(t),y=c.join(i,"index.css");s&&(()=>{d.existsSync(i)&&zt.execSync("rm -rf "+i),d.mkdirSync(i,{recursive:!0}),d.mkdirSync(c.join(i,"css")),d.mkdirSync(c.join(i,"types")),d.mkdirSync(c.join(i,"js")),d.mkdirSync(c.join(i,"cache"))})();const m=new Set,l=new Set;async function w(a){const g=["node_modules","saltygen"],j=d.statSync(a);if(j.isDirectory()){const f=d.readdirSync(a);if(g.some(N=>a.includes(N)))return;await Promise.all(f.map(N=>w(c.join(a,N))))}else if(j.isFile()&&Q(a)){m.add(a);const C=d.readFileSync(a,"utf8");/define[\w\d]+\(/.test(C)&&l.add(a)}}await w(t),await ie(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async a=>{const{contents:g}=await ot(t,a,i);for(let[j,f]of Object.entries(g))f instanceof Promise&&(f=await f),f.isKeyframes?h.keyframes.push({value:f,src:a,name:j}):f.isClassName?h.classNames.push({...f,src:a,name:j}):f.generator&&h.components.push({...f,src:a,name:j})}));const S=await mt(t);for(const a of h.keyframes){const{value:g}=a,j=`a_${g.animationName}.css`,f=`css/${j}`,C=c.join(i,f);o.push(j),d.writeFileSync(C,g.css)}const p={};for(const a of h.components){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S});r[f.priority]||(r[f.priority]=[]);const C=await f.css;if(!C)continue;r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}for(const a of h.classNames){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S}),C=await f.css;if(!C)continue;r[f.priority]||(r[f.priority]=[]),r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([a,g])=>{const j=g.map(J=>`@import url('./${J}');`).join(`
24
- `),f=q(a,6),C=c.parse(a),N=v(C.name),E=c.join(i,`css/f_${N}-${f}.css`);d.writeFileSync(E,j||"/* Empty file */")});const u=o.map(a=>`@import url('./css/${a}');`).join(`
24
+ `),f=q(a,6),C=c.parse(a),N=M(C.name),E=c.join(i,`css/f_${N}-${f}.css`);d.writeFileSync(E,j||"/* Empty file */")});const u=o.map(a=>`@import url('./css/${a}');`).join(`
25
25
  `);let O=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
26
26
 
27
27
  ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return d.readFileSync(c.join(i,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
@@ -38,5 +38,5 @@ ${x}
38
38
  `;h=`${h.replace(/\}$/,"")}
39
39
  ${O}
40
40
  }`}}),d.writeFileSync(w,h)});else{const b=r.flat().map(S=>`@import url('./${S}');`).join(`
41
- `),m=q(e,6),l=c.parse(e),w=v(l.name),h=c.join(n,`css/f_${w}-${m}.css`);d.writeFileSync(h,b||"/* Empty file */")}}}catch(n){console.error(n)}},fe=async(t,e,s=yt())=>{var n,o;try{const r=await I(t);if(Q(e)){const y=d.readFileSync(e,"utf8"),b=await mt(t),{contents:m}=await ot(t,e,r);let l=y;for(const[w,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:w,isProduction:s,config:b}),[p,u]=await se(l,w),$=l.slice(p,u);if(h.isClassName){const P=l,x=` ${w} = className("${S.classNames}")`;l=l.replace($,x),P===l&&console.error("Minimize file failed to change content",{name:w})}if($.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec($))==null?void 0:n.at(1))==null?void 0:o.trim(),x=l,O=` ${w} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace($,O),x===l&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(b.importStrategy==="component"){const w=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${v(h.name)}-${w}.css`}';
42
- ${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}},St=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Q(t))return!1;const n=await dt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Ot=t=>({name:"stylegen",buildStart:()=>ce(t),load:async e=>{if(Q(e))return await fe(t,e)},handleHotUpdate:async({file:e,server:s})=>{await St(e)&&s.restart()},watchChange:{handler:async e=>{Q(e)&&(await St(e)||await le(t,e))}}});exports.default=Ot;exports.saltyPlugin=Ot;
41
+ `),m=q(e,6),l=c.parse(e),w=M(l.name),h=c.join(n,`css/f_${w}-${m}.css`);d.writeFileSync(h,b||"/* Empty file */")}}}catch(n){console.error(n)}},fe=async(t,e,s=yt())=>{var n,o;try{const r=await I(t);if(Q(e)){const y=d.readFileSync(e,"utf8"),b=await mt(t),{contents:m}=await ot(t,e,r);let l=y;for(const[w,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:w,isProduction:s,config:b}),[p,u]=await se(l,w),$=l.slice(p,u);if(h.isClassName){const P=l,x=` ${w} = className("${S.classNames}")`;l=l.replace($,x),P===l&&console.error("Minimize file failed to change content",{name:w})}if($.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec($))==null?void 0:n.at(1))==null?void 0:o.trim(),x=l,O=` ${w} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace($,O),x===l&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(b.importStrategy==="component"){const w=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${M(h.name)}-${w}.css`}';
42
+ ${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}},St=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Q(t))return!1;const n=await dt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Ot=t=>({name:"stylegen",buildStart:()=>ce(t),load:async e=>{if(Q(e))return await fe(t,e)},handleHotUpdate:async({file:e,server:s})=>{await St(e)&&s.restart()},watchChange:{handler:async(e,s)=>{Q(e)&&s.event!=="delete"&&(await St(e)||await le(t,e))}}});exports.default=Ot;exports.saltyPlugin=Ot;
package/index.js CHANGED
@@ -686,8 +686,8 @@ ${c}`;
686
686
  await Ft(t) && s.restart();
687
687
  },
688
688
  watchChange: {
689
- handler: async (t) => {
690
- Z(t) && (await Ft(t) || await de(e, t));
689
+ handler: async (t, s) => {
690
+ Z(t) && s.event !== "delete" && (await Ft(t) || await de(e, t));
691
691
  }
692
692
  }
693
693
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.244",
3
+ "version": "0.0.1-alpha.245",
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.244"
37
+ "@salty-css/core": "^0.0.1-alpha.245"
38
38
  }
39
39
  }