@salty-css/vite 0.0.1-alpha.189 → 0.0.1-alpha.190

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 +16 -16
  2. package/index.js +178 -177
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1,37 +1,37 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const $e=require("esbuild"),be=require("child_process"),l=require("path"),u=require("fs"),K=require("fs/promises"),q=require("winston");var v=typeof document<"u"?document.currentScript:null;function we(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ce=we($e),oe=e=>String.fromCharCode(e+(e>25?39:97)),Fe=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=oe(n%52)+s;return s=oe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Ce=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},z=(e,t=5)=>{const s=Ce(5381,JSON.stringify(e))>>>0;return Fe(s,t)};function M(e){return e?typeof e!="string"?M(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const xe=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:i,transform:a}=n;e=e.replace(i,c=>{const{value:d,css:r}=a(c);return r&&s.push(r),d})}),{result:e,additionalCss:s}},ae=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},R=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((c,[d,r])=>{const o=d.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return c;if(o==="variants")return Object.entries(r).forEach(([_,b])=>{b&&Object.entries(b).forEach(([O,f])=>{if(!f)return;const w=`${t}.${_}-${O}`,S=R(f,w);n.push(S)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(_=>{const{css:b,...O}=_,f=Object.entries(O).reduce((S,[j,p])=>`${S}.${j}-${p}`,t),w=R(b,f);n.push(w)}),c;if(o.startsWith("@")){const _=R(r,t),b=`${o} {
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const $e=require("esbuild"),be=require("child_process"),l=require("path"),u=require("fs"),K=require("fs/promises"),q=require("winston");var v=typeof document<"u"?document.currentScript:null;function we(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ce=we($e),oe=e=>String.fromCharCode(e+(e>25?39:97)),Fe=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=oe(n%52)+s;return s=oe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Ce=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},z=(e,t=5)=>{const s=Ce(5381,JSON.stringify(e))>>>0;return Fe(s,t)};function M(e){return e?typeof e!="string"?M(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const Ne=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:i,transform:a}=n;e=e.replace(i,c=>{const{value:p,css:r}=a(c);return r&&s.push(r),p})}),{result:e,additionalCss:s}},ae=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},R=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((c,[p,r])=>{const o=p.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return c;if(o==="variants")return Object.entries(r).forEach(([_,$])=>{$&&Object.entries($).forEach(([O,f])=>{if(!f)return;const m=`${t}.${_}-${O}`,b=R(f,m);n.push(b)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(_=>{const{css:$,...O}=_,f=Object.entries(O).reduce((b,[d,x])=>`${b}.${d}-${x}`,t),m=R($,f);n.push(m)}),c;if(o.startsWith("@")){const _=R(r,t),$=`${o} {
2
2
  ${_.replace(`
3
3
  `,`
4
4
  `)}
5
- }`;return n.push(b),c}const C=d.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,N=R(r,C);return n.push(N),c}const m=o.startsWith("-")?o:M(o),h=(C,N=";")=>c=`${c}${C}${N}`,y=C=>h(`${m}:${C}`);if(typeof r=="number")return y(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:$}={},D=function*(){yield ae(r),yield xe(r,$)}();for(const{result:C,additionalCss:N=[]}of D)r=C,N.forEach(_=>{const b=R(_,"");h(b,"")});return y(r)},"");return i?t?[`${t} { ${i} }`,...n].join(`
5
+ }`;return n.push($),c}const F=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,N=R(r,F);return n.push(N),c}const h=o.startsWith("-")?o:M(o),y=(F,N=";")=>c=`${c}${F}${N}`,g=F=>y(`${h}:${F}`);if(typeof r=="number")return g(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:j}={},D=function*(){yield ae(r),yield Ne(r,j)}();for(const{result:F,additionalCss:N=[]}of D)r=F,N.forEach(_=>{const $=R(_,"");y($,"")});return g(r)},"");return i?t?[`${t} { ${i} }`,...n].join(`
6
6
  `):i:n.join(`
7
- `)},le=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,a])=>{if(typeof a=="object"){if(!a)return;const c=i.trim(),d=le(a,[...t,c]);s.push(d)}else n[i]=a}),Object.keys(n).length){const i=t.map(M).join("-"),a=R(n,`.${i}`);s.push(a)}return s.join(`
8
- `)},Ne=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=fe(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},fe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?fe(i,a,s):s.add(t)}),[...s]):[],ue=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ue(l.join(e,".."))},ke=async e=>{const t=ue(e);return await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Pe=async e=>{const t=await ke(e);if(t)return t.type};let A;const de=async e=>{if(A)return A;const t=await Pe(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ee=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]});function pe(e){return e?typeof e!="string"?pe(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const _e={"*, *::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"}},W=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ye=e=>{if(E.externalModules.length>0)return E.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return E.externalModules=n,n},J=async e=>{if(E.destDir)return E.destDir;const t=await te(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},ge=["salty","css","styles","styled"],De=(e=[])=>new RegExp(`\\.(${[...ge,...e].join("|")})\\.`),Z=(e,t=[])=>De(t).test(e),he=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):he(l.join(e,".."))},te=async e=>{var n,i;const t=await he(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((i=t.projects)==null?void 0:i.find(a=>a.dir===t.defaultProject))},Te=async e=>{const t=await te(e),s=await J(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=l.join(s,"salty.config.js"),a=await de(e),c=ye(n);await ce.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:a,external:c});const d=Date.now(),{config:r}=await import(`${i}?t=${d}`);return r},Oe=async(e,t)=>{var H,G;const s=await Te(e),n={...s},i=new Set,a=(x,k=[])=>x?Object.entries(x).flatMap(([V,T])=>{if(!T)return;if(typeof T=="object")return a(T,[...k,V]);const U=pe(V),Q=M(V),X=[...k,U].join(".");i.add(`"${X}"`);const Y=[...k.map(M),Q].join("-"),{result:je}=ae(T);return`--${Y}: ${je};`}):[],c=x=>x?Object.entries(x).flatMap(([k,V])=>{const T=a(V);return k==="base"?T.join(""):`${k} { ${T.join("")} }`}):[],d=x=>x?Object.entries(x).flatMap(([k,V])=>Object.entries(V).flatMap(([T,U])=>{const Q=a(U,[k]),X=`.${k}-${T}, [data-${k}="${T}"]`,Y=Q.join("");return`${X} { ${Y} }`})):[],r=x=>({...x,responsive:void 0,conditional:void 0}),o=x=>t.variables.map(k=>x==="static"?r(k._current):k._current[x]),m=a(W(r(s.variables),o("static"))),h=c(W((H=s.variables)==null?void 0:H.responsive,o("responsive"))),y=d(W((G=s.variables)==null?void 0:G.conditional,o("conditional"))),$=await J(e),P=l.join($,"css/_variables.css"),D=`:root { ${m.join("")} ${h.join("")} } ${y.join("")}`;u.writeFileSync(P,D);const C=l.join($,"css/_global.css"),N=W(s.global,t.globalStyles),_=R(N,"");u.writeFileSync(C,`@layer global { ${_} }`);const b=l.join($,"css/_reset.css"),f=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:_e,w=R(f,"");u.writeFileSync(b,`@layer reset { ${w} }`);const S=l.join($,"css/_templates.css"),j=W(s.templates,t.templates),p=le(j),F=Ne(j);u.writeFileSync(S,p),n.templates=j;const g=l.join($,"types/css-tokens.d.ts"),I=`
7
+ `)},le=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,a])=>{if(typeof a=="object"){if(!a)return;const c=i.trim(),p=le(a,[...t,c]);s.push(p)}else n[i]=a}),Object.keys(n).length){const i=t.map(M).join("-"),a=R(n,`.${i}`);s.push(a)}return s.join(`
8
+ `)},xe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=fe(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},fe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?fe(i,a,s):s.add(t)}),[...s]):[],ue=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ue(l.join(e,".."))},ke=async e=>{const t=ue(e);return await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Pe=async e=>{const t=await ke(e);if(t)return t.type};let A;const de=async e=>{if(A)return A;const t=await Pe(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ee=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]});function pe(e){return e?typeof e!="string"?pe(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const _e={"*, *::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"}},W=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ye=e=>{if(E.externalModules.length>0)return E.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return E.externalModules=n,n},J=async e=>{if(E.destDir)return E.destDir;const t=await te(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},ge=["salty","css","styles","styled"],De=(e=[])=>new RegExp(`\\.(${[...ge,...e].join("|")})\\.`),Z=(e,t=[])=>De(t).test(e),he=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):he(l.join(e,".."))},te=async e=>{var n,i;const t=await he(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((i=t.projects)==null?void 0:i.find(a=>a.dir===t.defaultProject))},Te=async e=>{const t=await te(e),s=await J(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=l.join(s,"salty.config.js"),a=await de(e),c=ye(n);await ce.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:a,external:c});const p=Date.now(),{config:r}=await import(`${i}?t=${p}`);return r},Oe=async(e,t)=>{var H,G;const s=await Te(e),n={...s},i=new Set,a=(C,k=[])=>C?Object.entries(C).flatMap(([V,T])=>{if(!T)return;if(typeof T=="object")return a(T,[...k,V]);const U=pe(V),Q=M(V),X=[...k,U].join(".");i.add(`"${X}"`);const Y=[...k.map(M),Q].join("-"),{result:je}=ae(T);return`--${Y}: ${je};`}):[],c=C=>C?Object.entries(C).flatMap(([k,V])=>{const T=a(V);return k==="base"?T.join(""):`${k} { ${T.join("")} }`}):[],p=C=>C?Object.entries(C).flatMap(([k,V])=>Object.entries(V).flatMap(([T,U])=>{const Q=a(U,[k]),X=`.${k}-${T}, [data-${k}="${T}"]`,Y=Q.join("");return`${X} { ${Y} }`})):[],r=C=>({...C,responsive:void 0,conditional:void 0}),o=C=>t.variables.map(k=>C==="static"?r(k._current):k._current[C]),h=a(W(r(s.variables),o("static"))),y=c(W((H=s.variables)==null?void 0:H.responsive,o("responsive"))),g=p(W((G=s.variables)==null?void 0:G.conditional,o("conditional"))),j=await J(e),P=l.join(j,"css/_variables.css"),D=`:root { ${h.join("")} ${y.join("")} } ${g.join("")}`;u.writeFileSync(P,D);const F=l.join(j,"css/_global.css"),N=W(s.global,t.globalStyles),_=R(N,"");u.writeFileSync(F,`@layer global { ${_} }`);const $=l.join(j,"css/_reset.css"),f=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:_e,m=R(f,"");u.writeFileSync($,`@layer reset { ${m} }`);const b=l.join(j,"css/_templates.css"),d=W(s.templates,t.templates),x=le(d),w=xe(d);u.writeFileSync(b,x),n.templates=d;const S=l.join(j,"types/css-tokens.d.ts"),I=`
9
9
  // Variable types
10
10
  type VariableTokens = ${[...i].join("|")};
11
11
  type PropertyValueToken = \`{\${VariableTokens}}\`;
12
12
 
13
13
  // Template types
14
14
  type TemplateTokens = {
15
- ${Object.entries(F).map(([x,k])=>`${x}?: ${k}`).join(`
15
+ ${Object.entries(w).map(([C,k])=>`${C}?: ${k}`).join(`
16
16
  `)}
17
17
  }
18
- `;u.writeFileSync(g,I);const B=l.join($,"cache/config-cache.json");u.writeFileSync(B,JSON.stringify(n,null,2))},re=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const c=i.exec(e);if(c){const d=c.at(1);if(ge.some(o=>d==null?void 0:d.includes(o)))return t}return"styled('div',"}),se=async(e,t,s)=>{const n=z(t),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const a=l.parse(t);let c=u.readFileSync(t,"utf8");c=re(c);const d=l.join(s,"js",n+".js"),r=await te(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),m=ye(o),h=await de(e);await ce.build({stdin:{contents:c,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:h,target:["node20"],keepNames:!0,external:m,packages:"external",plugins:[{name:"test",setup:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},D=>{const C=u.readFileSync(D.path,"utf8");return{contents:re(C),loader:"ts"}})}}]});const y=Date.now();return await import(`${d}?t=${y}`)},Ee=async e=>{const t=await J(e),s=l.join(t,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ne=async e=>{const t=await Ee(e),s=await J(e),n=l.join(s,"salty.config.js"),i=Date.now(),{config:a}=await import(`${n}?t=${i}`);return W(a,t)},me=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Me=async(e,t=me(),s=!0)=>{try{const n=Date.now();t?ee.info("Generating CSS in production mode! 🔥"):ee.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(e),d=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&be.execSync("rm -rf "+c),u.mkdirSync(c,{recursive:!0}),u.mkdirSync(l.join(c,"css")),u.mkdirSync(l.join(c,"types")),u.mkdirSync(l.join(c,"js")),u.mkdirSync(l.join(c,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],templates:[],components:[],classNames:[]};async function m(f){const w=["node_modules","saltygen"],S=u.statSync(f);if(S.isDirectory()){const j=u.readdirSync(f);if(w.some(F=>f.includes(F)))return;await Promise.all(j.map(F=>m(l.join(f,F))))}else if(S.isFile()&&Z(f)){const p=await se(e,f,c);Object.entries(p).forEach(([F,g])=>{g.isKeyframes?o.keyframes.push({value:g,src:f,name:F}):g.isMedia?o.mediaQueries.push(g):g.isGlobalDefine?o.globalStyles.push(g):g.isDefineVariables?o.variables.push(g):g.isDefineTemplates?o.templates.push(g):g.isClassName?o.classNames.push({value:g.factory,src:f,name:F}):g.generator&&o.components.push({value:g.generator,src:f,name:F})})}}await m(e),await Oe(e,o);const h=await ne(e);for(const f of o.keyframes){const{value:w}=f,S=`a_${w.animationName}.css`,j=`css/${S}`,p=l.join(c,j);i.push(S),u.writeFileSync(p,w.css)}const y={};for(const f of o.components){const{value:w,name:S,src:j}=f,p=w._withBuildContext({name:S,config:h,prod:t});a[p.priority]||(a[p.priority]=[]),a[p.priority].push(p.cssFileName);const F=`css/${p.cssFileName}`,g=l.join(c,F);u.writeFileSync(g,p.css),h.importStrategy==="component"&&(y[j]?y[j].push(p.cssFileName):y[j]=[p.cssFileName])}for(const f of o.classNames){const{value:w,src:S,name:j}=f,p=w._withBuildContext({name:j,prod:t});a[0].push(p.cssFileName);const F=`css/${p.cssFileName}`,g=l.join(c,F);u.writeFileSync(g,p.css),h.importStrategy==="component"&&(y[S]?y[S].push(p.cssFileName):y[S]=[p.cssFileName])}h.importStrategy==="component"&&Object.entries(y).forEach(([f,w])=>{const S=w.map(L=>`@import url('./${L}');`).join(`
19
- `),j=z(f,6),p=l.parse(f),F=M(p.name),g=l.join(c,`css/f_${F}-${j}.css`);u.writeFileSync(g,S)});const $=i.map(f=>`@import url('./css/${f}');`).join(`
18
+ `;u.writeFileSync(S,I);const B=l.join(j,"cache/config-cache.json");u.writeFileSync(B,JSON.stringify(n,null,2))},re=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const c=i.exec(e);if(c){const p=c.at(1);if(ge.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),se=async(e,t,s)=>{const n=z(t),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const a=l.parse(t);let c=u.readFileSync(t,"utf8");c=re(c);const p=l.join(s,"js",n+".js"),r=await te(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),h=ye(o),y=await de(e);await ce.build({stdin:{contents:c,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:y,target:["node20"],keepNames:!0,external:h,packages:"external",plugins:[{name:"test",setup:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},D=>{const F=u.readFileSync(D.path,"utf8");return{contents:re(F),loader:"ts"}})}}]});const g=Date.now();return await import(`${p}?t=${g}`)},Ee=async e=>{const t=await J(e),s=l.join(t,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ne=async e=>{const t=await Ee(e),s=await J(e),n=l.join(s,"salty.config.js"),i=Date.now(),{config:a}=await import(`${n}?t=${i}`);return W(a,t)},me=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Me=async(e,t=me(),s=!0)=>{try{const n=Date.now();t?ee.info("Generating CSS in production mode! 🔥"):ee.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(e),p=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&be.execSync("rm -rf "+c),u.mkdirSync(c,{recursive:!0}),u.mkdirSync(l.join(c,"css")),u.mkdirSync(l.join(c,"types")),u.mkdirSync(l.join(c,"js")),u.mkdirSync(l.join(c,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],templates:[],components:[],classNames:[]};async function h(f){const m=["node_modules","saltygen"],b=u.statSync(f);if(b.isDirectory()){const d=u.readdirSync(f);if(m.some(w=>f.includes(w)))return;await Promise.all(d.map(w=>h(l.join(f,w))))}else if(b.isFile()&&Z(f)){const x=await se(e,f,c);Object.entries(x).forEach(([w,S])=>{S.isKeyframes?o.keyframes.push({value:S,src:f,name:w}):S.isMedia?o.mediaQueries.push(S):S.isGlobalDefine?o.globalStyles.push(S):S.isDefineVariables?o.variables.push(S):S.isDefineTemplates?o.templates.push(S):S.isClassName?o.classNames.push({...S,src:f,name:w}):S.generator&&o.components.push({...S,src:f,name:w})})}}await h(e),await Oe(e,o);const y=await ne(e);for(const f of o.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,d=`css/${b}`,x=l.join(c,d);i.push(b),u.writeFileSync(x,m.css)}const g={};for(const f of o.components){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:t,config:y});a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const x=`css/${d.cssFileName}`,w=l.join(c,x);u.writeFileSync(w,d.css),y.importStrategy==="component"&&(g[m]?g[m].push(d.cssFileName):g[m]=[d.cssFileName])}for(const f of o.classNames){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:t,config:y});a[0].push(d.cssFileName);const x=`css/${d.cssFileName}`,w=l.join(c,x);u.writeFileSync(w,d.css),y.importStrategy==="component"&&(g[m]?g[m].push(d.cssFileName):g[m]=[d.cssFileName])}y.importStrategy==="component"&&Object.entries(g).forEach(([f,m])=>{const b=m.map(L=>`@import url('./${L}');`).join(`
19
+ `),d=z(f,6),x=l.parse(f),w=M(x.name),S=l.join(c,`css/f_${w}-${d}.css`);u.writeFileSync(S,b)});const j=i.map(f=>`@import url('./css/${f}');`).join(`
20
20
  `);let N=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
21
 
22
22
  ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(c,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
23
23
  `)}
24
- ${$}`;if(h.importStrategy!=="component"){const f=a.reduce((w,S,j)=>{const p=S.reduce((I,B)=>{var k;const H=l.join(c,"css",B),G=u.readFileSync(H,"utf8"),x=((k=/.*-([^-]+)-\d+.css/.exec(B))==null?void 0:k.at(1))||z(H,6);return I.includes(x)?I:`${I}
25
- /*start:${x}*/
24
+ ${j}`;if(y.importStrategy!=="component"){const f=a.reduce((m,b,d)=>{const x=b.reduce((I,B)=>{var k;const H=l.join(c,"css",B),G=u.readFileSync(H,"utf8"),C=((k=/.*-([^-]+)-\d+.css/.exec(B))==null?void 0:k.at(1))||z(H,6);return I.includes(C)?I:`${I}
25
+ /*start:${C}*/
26
26
  ${G}
27
- /*end:${x}*/
28
- `},""),F=`l_${j}.css`,g=l.join(c,"css",F),L=`@layer l${j} { ${p}
29
- }`;return u.writeFileSync(g,L),`${w}
30
- @import url('./css/${F}');`},"");N+=f}u.writeFileSync(d,N);const b=Date.now()-n,O=b<200?"🔥":b<500?"🚀":b<1e3?"🎉":b<2e3?"🚗":b<5e3?"🤔":"🥴";ee.info(`Generated CSS in ${b}ms! ${O}`)}catch(n){console.error(n)}},Re=async(e,t)=>{try{const s=await J(e);if(Z(t)){const i=[],a=await ne(e),c=await se(e,t,s);if(Object.entries(c).forEach(([d,r])=>{if(r.isKeyframes&&r.css){const $=`css/${`a_${r.animationName}.css`}`,P=l.join(s,$);u.writeFileSync(P,r.css);return}if(r.isClassName){const y=r.factory._withBuildContext({name:d});i[0].push(y.cssFileName);const $=`css/${y.cssFileName}`,P=l.join(s,$);u.writeFileSync(P,y.css)}if(!r.generator)return;const o=r.generator._withBuildContext({name:d,config:a}),m=`css/${o.cssFileName}`,h=l.join(s,m);u.writeFileSync(h,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),a.importStrategy!=="component")i.forEach((d,r)=>{const o=`l_${r}.css`,m=l.join(s,"css",o);let h=u.readFileSync(m,"utf8");d.forEach(y=>{var C;const $=l.join(s,"css",y),P=((C=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:C.at(1))||z($,6);if(!h.includes(P)){const N=u.readFileSync($,"utf8"),_=`/*start:${P}*/
27
+ /*end:${C}*/
28
+ `},""),w=`l_${d}.css`,S=l.join(c,"css",w),L=`@layer l${d} { ${x}
29
+ }`;return u.writeFileSync(S,L),`${m}
30
+ @import url('./css/${w}');`},"");N+=f}u.writeFileSync(p,N);const $=Date.now()-n,O=$<200?"🔥":$<500?"🚀":$<1e3?"🎉":$<2e3?"🚗":$<5e3?"🤔":"🥴";ee.info(`Generated CSS in ${$}ms! ${O}`)}catch(n){console.error(n)}},Re=async(e,t)=>{try{const s=await J(e);if(Z(t)){const i=[],a=await ne(e),c=await se(e,t,s);if(Object.entries(c).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const j=`css/${`a_${r.animationName}.css`}`,P=l.join(s,j);u.writeFileSync(P,r.css);return}if(r.isClassName){const g=r.factory._withBuildContext({name:p});i[0].push(g.cssFileName);const j=`css/${g.cssFileName}`,P=l.join(s,j);u.writeFileSync(P,g.css)}if(!r.generator)return;const o=r.generator._withBuildContext({name:p,config:a}),h=`css/${o.cssFileName}`,y=l.join(s,h);u.writeFileSync(y,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),a.importStrategy!=="component")i.forEach((p,r)=>{const o=`l_${r}.css`,h=l.join(s,"css",o);let y=u.readFileSync(h,"utf8");p.forEach(g=>{var F;const j=l.join(s,"css",g),P=((F=/.*-([^-]+)-\d+.css/.exec(g))==null?void 0:F.at(1))||z(j,6);if(!y.includes(P)){const N=u.readFileSync(j,"utf8"),_=`/*start:${P}*/
31
31
  ${N}
32
32
  /*end:${P}*/
33
- `;h=`${h.replace(/\}$/,"")}
33
+ `;y=`${y.replace(/\}$/,"")}
34
34
  ${_}
35
- }`}}),u.writeFileSync(m,h)});else{const d=i.flat().map(y=>`@import url('./${y}');`).join(`
36
- `),r=z(t,6),o=l.parse(t),m=M(o.name),h=l.join(s,`css/f_${m}-${r}.css`);u.writeFileSync(h,d)}}}catch(s){console.error(s)}},Ve=async(e,t,s=me())=>{try{const n=await J(e);if(Z(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,m=>`export ${m}`)!==a&&await K.writeFile(t,a);const d=await ne(e),r=await se(e,t,n);let o=a;if(Object.entries(r).forEach(([m,h])=>{var F;if(h.isKeyframes||!h.generator)return;const y=h.generator._withBuildContext({name:m,config:d,prod:s}),$=new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const P=(F=$.at(1))==null?void 0:F.trim(),D=new RegExp(`\\s${m}[=\\s]+styled\\(`,"g").exec(o);if(!D)return console.error("Could not find the original declaration");const{index:C}=D;let N=!1;const _=setTimeout(()=>N=!0,5e3);let b=0,O=!1,f=0;for(;!O&&!N;){const g=o[C+b];g==="("&&f++,g===")"&&f--,f===0&&g===")"&&(O=!0),b>o.length&&(N=!0),b++}if(!N)clearTimeout(_);else throw new Error("Failed to find the end of the styled call and timed out");const w=C+b,S=o.slice(C,w),j=o,p=` ${m} = styled(${P}, "${y.classNames}", ${JSON.stringify(y.props)});`;o=o.replace(S,p),j===o&&console.error("Minimize file failed to change content",{name:m,tagName:P})}),d.importStrategy==="component"){const m=z(t,6),h=l.parse(t);o=`import '../../saltygen/css/${`f_${M(h.name)}-${m}.css`}';
35
+ }`}}),u.writeFileSync(h,y)});else{const p=i.flat().map(g=>`@import url('./${g}');`).join(`
36
+ `),r=z(t,6),o=l.parse(t),h=M(o.name),y=l.join(s,`css/f_${h}-${r}.css`);u.writeFileSync(y,p)}}}catch(s){console.error(s)}},Ve=async(e,t,s=me())=>{try{const n=await J(e);if(Z(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,h=>`export ${h}`)!==a&&await K.writeFile(t,a);const p=await ne(e),r=await se(e,t,n);let o=a;if(Object.entries(r).forEach(([h,y])=>{var w;if(y.isKeyframes||!y.generator)return;const g=y.generator._withBuildContext({name:h,config:p,prod:s}),j=new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!j)return console.error("Could not find the original declaration");const P=(w=j.at(1))==null?void 0:w.trim(),D=new RegExp(`\\s${h}[=\\s]+styled\\(`,"g").exec(o);if(!D)return console.error("Could not find the original declaration");const{index:F}=D;let N=!1;const _=setTimeout(()=>N=!0,5e3);let $=0,O=!1,f=0;for(;!O&&!N;){const S=o[F+$];S==="("&&f++,S===")"&&f--,f===0&&S===")"&&(O=!0),$>o.length&&(N=!0),$++}if(!N)clearTimeout(_);else throw new Error("Failed to find the end of the styled call and timed out");const m=F+$,b=o.slice(F,m),d=o,x=` ${h} = styled(${P}, "${g.classNames}", ${JSON.stringify(g.clientProps)});`;o=o.replace(b,x),d===o&&console.error("Minimize file failed to change content",{name:h,tagName:P})}),p.importStrategy==="component"){const h=z(t,6),y=l.parse(t);o=`import '../../saltygen/css/${`f_${M(y.name)}-${h}.css`}';
37
37
  ${o}`}return 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)}},ie=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!Z(e))return!1;const n=await K.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Se=e=>({name:"stylegen",buildStart:()=>Me(e),load:async t=>{if(Z(t))return await Ve(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ie(t)&&await s.restart()},watchChange:{handler:async t=>{Z(t)&&(await ie(t)||await Re(e,t))}}});exports.default=Se;exports.saltyPlugin=Se;
package/index.js CHANGED
@@ -2,19 +2,19 @@ import * as ft from "esbuild";
2
2
  import { execSync as Ct } from "child_process";
3
3
  import { join as f, parse as Q } from "path";
4
4
  import { existsSync as st, mkdirSync as z, statSync as jt, readdirSync as Ft, writeFileSync as k, readFileSync as V } from "fs";
5
- import { readFile as nt, writeFile as xt } from "fs/promises";
6
- import { createLogger as Nt, format as tt, transports as kt } from "winston";
7
- const ct = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Dt = (t, e) => {
5
+ import { readFile as nt, writeFile as Nt } from "fs/promises";
6
+ import { createLogger as xt, format as tt, transports as kt } from "winston";
7
+ const ct = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Pt = (t, e) => {
8
8
  let s = "", n;
9
9
  for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = ct(n % 52) + s;
10
10
  return s = ct(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, Pt = (t, e) => {
11
+ }, Dt = (t, e) => {
12
12
  let s = e.length;
13
13
  for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
14
  return t;
15
15
  }, H = (t, e = 5) => {
16
- const s = Pt(5381, JSON.stringify(t)) >>> 0;
17
- return Dt(s, e);
16
+ const s = Dt(5381, JSON.stringify(t)) >>> 0;
17
+ return Pt(s, e);
18
18
  };
19
19
  function M(t) {
20
20
  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()) : "";
@@ -26,56 +26,56 @@ const Et = (t, e) => {
26
26
  return Object.values(e).forEach((n) => {
27
27
  const { pattern: i, transform: a } = n;
28
28
  t = t.replace(i, (c) => {
29
- const { value: u, css: r } = a(c);
30
- return r && s.push(r), u;
29
+ const { value: p, css: r } = a(c);
30
+ return r && s.push(r), p;
31
31
  });
32
32
  }), { result: t, additionalCss: s };
33
33
  }, ut = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${M(n[1].replaceAll(".", "-"))})`) } : { result: t }, R = (t, e, s) => {
34
34
  if (!t) return "";
35
- const n = [], i = Object.entries(t).reduce((c, [u, r]) => {
36
- const o = u.trim();
35
+ const n = [], i = Object.entries(t).reduce((c, [p, r]) => {
36
+ const o = p.trim();
37
37
  if (typeof r == "function" && (r = r()), typeof r == "object") {
38
38
  if (!r) return c;
39
39
  if (o === "variants")
40
- return Object.entries(r).forEach(([P, w]) => {
41
- w && Object.entries(w).forEach(([T, l]) => {
40
+ return Object.entries(r).forEach(([D, b]) => {
41
+ b && Object.entries(b).forEach(([T, l]) => {
42
42
  if (!l) return;
43
- const S = `${e}.${P}-${T}`, y = R(l, S);
44
- n.push(y);
43
+ const m = `${e}.${D}-${T}`, w = R(l, m);
44
+ n.push(w);
45
45
  });
46
46
  }), c;
47
47
  if (o === "defaultVariants")
48
48
  return c;
49
49
  if (o === "compoundVariants")
50
- return r.forEach((P) => {
51
- const { css: w, ...T } = P, l = Object.entries(T).reduce((y, [$, p]) => `${y}.${$}-${p}`, e), S = R(w, l);
52
- n.push(S);
50
+ return r.forEach((D) => {
51
+ const { css: b, ...T } = D, l = Object.entries(T).reduce((w, [u, N]) => `${w}.${u}-${N}`, e), m = R(b, l);
52
+ n.push(m);
53
53
  }), c;
54
54
  if (o.startsWith("@")) {
55
- const P = R(r, e), w = `${o} {
56
- ${P.replace(`
55
+ const D = R(r, e), b = `${o} {
56
+ ${D.replace(`
57
57
  `, `
58
58
  `)}
59
59
  }`;
60
- return n.push(w), c;
60
+ return n.push(b), c;
61
61
  }
62
- const j = u.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, x = R(r, j);
63
- return n.push(x), c;
62
+ const C = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, F = R(r, C);
63
+ return n.push(F), c;
64
64
  }
65
- const m = o.startsWith("-") ? o : M(o), h = (j, x = ";") => c = `${c}${j}${x}`, d = (j) => h(`${m}:${j}`);
66
- if (typeof r == "number") return d(r);
65
+ const h = o.startsWith("-") ? o : M(o), d = (C, F = ";") => c = `${c}${C}${F}`, g = (C) => d(`${h}:${C}`);
66
+ if (typeof r == "number") return g(r);
67
67
  if (typeof r != "string")
68
68
  if ("toString" in r) r = r.toString();
69
69
  else return c;
70
- const { modifiers: b } = {}, E = function* () {
71
- yield ut(r), yield Et(r, b);
70
+ const { modifiers: $ } = {}, E = function* () {
71
+ yield ut(r), yield Et(r, $);
72
72
  }();
73
- for (const { result: j, additionalCss: x = [] } of E)
74
- r = j, x.forEach((P) => {
75
- const w = R(P, "");
76
- h(w, "");
73
+ for (const { result: C, additionalCss: F = [] } of E)
74
+ r = C, F.forEach((D) => {
75
+ const b = R(D, "");
76
+ d(b, "");
77
77
  });
78
- return d(r);
78
+ return g(r);
79
79
  }, "");
80
80
  return i ? e ? [`${e} { ${i} }`, ...n].join(`
81
81
  `) : i : n.join(`
@@ -86,8 +86,8 @@ const Et = (t, e) => {
86
86
  if (Object.entries(t).forEach(([i, a]) => {
87
87
  if (typeof a == "object") {
88
88
  if (!a) return;
89
- const c = i.trim(), u = pt(a, [...e, c]);
90
- s.push(u);
89
+ const c = i.trim(), p = pt(a, [...e, c]);
90
+ s.push(p);
91
91
  } else
92
92
  n[i] = a;
93
93
  }), Object.keys(n).length) {
@@ -117,7 +117,7 @@ const ht = async (t) => {
117
117
  if (W) return W;
118
118
  const e = await Ot(t);
119
119
  return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
120
- }, et = Nt({
120
+ }, et = xt({
121
121
  level: "debug",
122
122
  format: tt.combine(tt.colorize(), tt.cli()),
123
123
  transports: [new kt.Console({})]
@@ -206,44 +206,44 @@ const Vt = {
206
206
  format: a,
207
207
  external: c
208
208
  });
209
- const u = Date.now(), { config: r } = await import(`${i}?t=${u}`);
209
+ const p = Date.now(), { config: r } = await import(`${i}?t=${p}`);
210
210
  return r;
211
211
  }, Jt = async (t, e) => {
212
212
  var G, q;
213
- const s = await Rt(t), n = { ...s }, i = /* @__PURE__ */ new Set(), a = (F, N = []) => F ? Object.entries(F).flatMap(([J, _]) => {
213
+ const s = await Rt(t), n = { ...s }, i = /* @__PURE__ */ new Set(), a = (j, x = []) => j ? Object.entries(j).flatMap(([J, _]) => {
214
214
  if (!_) return;
215
- if (typeof _ == "object") return a(_, [...N, J]);
216
- const U = mt(J), X = M(J), Y = [...N, U].join(".");
215
+ if (typeof _ == "object") return a(_, [...x, J]);
216
+ const U = mt(J), X = M(J), Y = [...x, U].join(".");
217
217
  i.add(`"${Y}"`);
218
- const v = [...N.map(M), X].join("-"), { result: St } = ut(_);
218
+ const v = [...x.map(M), X].join("-"), { result: St } = ut(_);
219
219
  return `--${v}: ${St};`;
220
- }) : [], c = (F) => F ? Object.entries(F).flatMap(([N, J]) => {
220
+ }) : [], c = (j) => j ? Object.entries(j).flatMap(([x, J]) => {
221
221
  const _ = a(J);
222
- return N === "base" ? _.join("") : `${N} { ${_.join("")} }`;
223
- }) : [], u = (F) => F ? Object.entries(F).flatMap(([N, J]) => Object.entries(J).flatMap(([_, U]) => {
224
- const X = a(U, [N]), Y = `.${N}-${_}, [data-${N}="${_}"]`, v = X.join("");
222
+ return x === "base" ? _.join("") : `${x} { ${_.join("")} }`;
223
+ }) : [], p = (j) => j ? Object.entries(j).flatMap(([x, J]) => Object.entries(J).flatMap(([_, U]) => {
224
+ const X = a(U, [x]), Y = `.${x}-${_}, [data-${x}="${_}"]`, v = X.join("");
225
225
  return `${Y} { ${v} }`;
226
- })) : [], r = (F) => ({ ...F, responsive: void 0, conditional: void 0 }), o = (F) => e.variables.map((N) => F === "static" ? r(N._current) : N._current[F]), m = a(Z(r(s.variables), o("static"))), h = c(Z((G = s.variables) == null ? void 0 : G.responsive, o("responsive"))), d = u(Z((q = s.variables) == null ? void 0 : q.conditional, o("conditional"))), b = await A(t), D = f(b, "css/_variables.css"), E = `:root { ${m.join("")} ${h.join("")} } ${d.join("")}`;
227
- k(D, E);
228
- const j = f(b, "css/_global.css"), x = Z(s.global, e.globalStyles), P = R(x, "");
229
- k(j, `@layer global { ${P} }`);
230
- const w = f(b, "css/_reset.css"), l = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Vt, S = R(l, "");
231
- k(w, `@layer reset { ${S} }`);
232
- const y = f(b, "css/_templates.css"), $ = Z(s.templates, e.templates), p = pt($), C = _t($);
233
- k(y, p), n.templates = $;
234
- const g = f(b, "types/css-tokens.d.ts"), B = `
226
+ })) : [], r = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), o = (j) => e.variables.map((x) => j === "static" ? r(x._current) : x._current[j]), h = a(Z(r(s.variables), o("static"))), d = c(Z((G = s.variables) == null ? void 0 : G.responsive, o("responsive"))), g = p(Z((q = s.variables) == null ? void 0 : q.conditional, o("conditional"))), $ = await A(t), P = f($, "css/_variables.css"), E = `:root { ${h.join("")} ${d.join("")} } ${g.join("")}`;
227
+ k(P, E);
228
+ const C = f($, "css/_global.css"), F = Z(s.global, e.globalStyles), D = R(F, "");
229
+ k(C, `@layer global { ${D} }`);
230
+ const b = f($, "css/_reset.css"), l = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Vt, m = R(l, "");
231
+ k(b, `@layer reset { ${m} }`);
232
+ const w = f($, "css/_templates.css"), u = Z(s.templates, e.templates), N = pt(u), S = _t(u);
233
+ k(w, N), n.templates = u;
234
+ const y = f($, "types/css-tokens.d.ts"), B = `
235
235
  // Variable types
236
236
  type VariableTokens = ${[...i].join("|")};
237
237
  type PropertyValueToken = \`{\${VariableTokens}}\`;
238
238
 
239
239
  // Template types
240
240
  type TemplateTokens = {
241
- ${Object.entries(C).map(([F, N]) => `${F}?: ${N}`).join(`
241
+ ${Object.entries(S).map(([j, x]) => `${j}?: ${x}`).join(`
242
242
  `)}
243
243
  }
244
244
  `;
245
- k(g, B);
246
- const K = f(b, "cache/config-cache.json");
245
+ k(y, B);
246
+ const K = f($, "cache/config-cache.json");
247
247
  k(K, JSON.stringify(n, null, 2));
248
248
  }, at = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
249
249
  if (/^['"`]/.test(s)) return e;
@@ -251,8 +251,8 @@ const Vt = {
251
251
  if (!i.test(t)) return e;
252
252
  const c = i.exec(t);
253
253
  if (c) {
254
- const u = c.at(1);
255
- if ($t.some((o) => u == null ? void 0 : u.includes(o))) return e;
254
+ const p = c.at(1);
255
+ if ($t.some((o) => p == null ? void 0 : p.includes(o))) return e;
256
256
  }
257
257
  return "styled('div',";
258
258
  }), rt = async (t, e, s) => {
@@ -261,7 +261,7 @@ const Vt = {
261
261
  const a = Q(e);
262
262
  let c = V(e, "utf8");
263
263
  c = at(c);
264
- const u = f(s, "js", n + ".js"), r = await ot(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), m = yt(o), h = await ht(t);
264
+ const p = f(s, "js", n + ".js"), r = await ot(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), h = yt(o), d = await ht(t);
265
265
  await ft.build({
266
266
  stdin: {
267
267
  contents: c,
@@ -272,26 +272,26 @@ const Vt = {
272
272
  minify: !1,
273
273
  treeShaking: !0,
274
274
  bundle: !0,
275
- outfile: u,
276
- format: h,
275
+ outfile: p,
276
+ format: d,
277
277
  target: ["node20"],
278
278
  keepNames: !0,
279
- external: m,
279
+ external: h,
280
280
  packages: "external",
281
281
  plugins: [
282
282
  {
283
283
  name: "test",
284
- setup: (D) => {
285
- D.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (E) => {
286
- const j = V(E.path, "utf8");
287
- return { contents: at(j), loader: "ts" };
284
+ setup: (P) => {
285
+ P.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (E) => {
286
+ const C = V(E.path, "utf8");
287
+ return { contents: at(C), loader: "ts" };
288
288
  });
289
289
  }
290
290
  }
291
291
  ]
292
292
  });
293
- const d = Date.now();
294
- return await import(`${u}?t=${d}`);
293
+ const g = Date.now();
294
+ return await import(`${p}?t=${g}`);
295
295
  }, At = async (t) => {
296
296
  const e = await A(t), s = f(e, "cache/config-cache.json"), n = V(s, "utf8");
297
297
  if (!n) throw new Error("Could not find config cache file");
@@ -309,7 +309,7 @@ const Vt = {
309
309
  try {
310
310
  const n = Date.now();
311
311
  e ? et.info("Generating CSS in production mode! 🔥") : et.info("Generating CSS in development mode! 🚀");
312
- const i = [], a = [], c = await A(t), u = f(c, "index.css");
312
+ const i = [], a = [], c = await A(t), p = f(c, "index.css");
313
313
  s && (() => {
314
314
  st(c) && Ct("rm -rf " + c), z(c, { recursive: !0 }), z(f(c, "css")), z(f(c, "types")), z(f(c, "js")), z(f(c, "cache"));
315
315
  })();
@@ -322,65 +322,66 @@ const Vt = {
322
322
  components: [],
323
323
  classNames: []
324
324
  };
325
- async function m(l) {
326
- const S = ["node_modules", "saltygen"], y = jt(l);
327
- if (y.isDirectory()) {
328
- const $ = Ft(l);
329
- if (S.some((C) => l.includes(C))) return;
330
- await Promise.all($.map((C) => m(f(l, C))));
331
- } else if (y.isFile() && I(l)) {
332
- const p = await rt(t, l, c);
333
- Object.entries(p).forEach(([C, g]) => {
334
- g.isKeyframes ? o.keyframes.push({
335
- value: g,
325
+ async function h(l) {
326
+ const m = ["node_modules", "saltygen"], w = jt(l);
327
+ if (w.isDirectory()) {
328
+ const u = Ft(l);
329
+ if (m.some((S) => l.includes(S))) return;
330
+ await Promise.all(u.map((S) => h(f(l, S))));
331
+ } else if (w.isFile() && I(l)) {
332
+ const N = await rt(t, l, c);
333
+ Object.entries(N).forEach(([S, y]) => {
334
+ y.isKeyframes ? o.keyframes.push({
335
+ value: y,
336
336
  src: l,
337
- name: C
338
- }) : g.isMedia ? o.mediaQueries.push(g) : g.isGlobalDefine ? o.globalStyles.push(g) : g.isDefineVariables ? o.variables.push(g) : g.isDefineTemplates ? o.templates.push(g) : g.isClassName ? o.classNames.push({
339
- value: g.factory,
337
+ name: S
338
+ }) : y.isMedia ? o.mediaQueries.push(y) : y.isGlobalDefine ? o.globalStyles.push(y) : y.isDefineVariables ? o.variables.push(y) : y.isDefineTemplates ? o.templates.push(y) : y.isClassName ? o.classNames.push({
339
+ ...y,
340
340
  src: l,
341
- name: C
342
- }) : g.generator && o.components.push({
343
- value: g.generator,
341
+ name: S
342
+ }) : y.generator && o.components.push({
343
+ ...y,
344
344
  src: l,
345
- name: C
345
+ name: S
346
346
  });
347
347
  });
348
348
  }
349
349
  }
350
- await m(t), await Jt(t, o);
351
- const h = await it(t);
350
+ await h(t), await Jt(t, o);
351
+ const d = await it(t);
352
352
  for (const l of o.keyframes) {
353
- const { value: S } = l, y = `a_${S.animationName}.css`, $ = `css/${y}`, p = f(c, $);
354
- i.push(y), k(p, S.css);
353
+ const { value: m } = l, w = `a_${m.animationName}.css`, u = `css/${w}`, N = f(c, u);
354
+ i.push(w), k(N, m.css);
355
355
  }
356
- const d = {};
356
+ const g = {};
357
357
  for (const l of o.components) {
358
- const { value: S, name: y, src: $ } = l, p = S._withBuildContext({
359
- name: y,
360
- config: h,
361
- prod: e
358
+ const { src: m, name: w } = l, u = l.generator._withBuildContext({
359
+ callerName: w,
360
+ isProduction: e,
361
+ config: d
362
362
  });
363
- a[p.priority] || (a[p.priority] = []), a[p.priority].push(p.cssFileName);
364
- const C = `css/${p.cssFileName}`, g = f(c, C);
365
- k(g, p.css), h.importStrategy === "component" && (d[$] ? d[$].push(p.cssFileName) : d[$] = [p.cssFileName]);
363
+ a[u.priority] || (a[u.priority] = []), a[u.priority].push(u.cssFileName);
364
+ const N = `css/${u.cssFileName}`, S = f(c, N);
365
+ k(S, u.css), d.importStrategy === "component" && (g[m] ? g[m].push(u.cssFileName) : g[m] = [u.cssFileName]);
366
366
  }
367
367
  for (const l of o.classNames) {
368
- const { value: S, src: y, name: $ } = l, p = S._withBuildContext({
369
- name: $,
370
- prod: e
368
+ const { src: m, name: w } = l, u = l.generator._withBuildContext({
369
+ callerName: w,
370
+ isProduction: e,
371
+ config: d
371
372
  });
372
- a[0].push(p.cssFileName);
373
- const C = `css/${p.cssFileName}`, g = f(c, C);
374
- k(g, p.css), h.importStrategy === "component" && (d[y] ? d[y].push(p.cssFileName) : d[y] = [p.cssFileName]);
373
+ a[0].push(u.cssFileName);
374
+ const N = `css/${u.cssFileName}`, S = f(c, N);
375
+ k(S, u.css), d.importStrategy === "component" && (g[m] ? g[m].push(u.cssFileName) : g[m] = [u.cssFileName]);
375
376
  }
376
- h.importStrategy === "component" && Object.entries(d).forEach(([l, S]) => {
377
- const y = S.map((L) => `@import url('./${L}');`).join(`
378
- `), $ = H(l, 6), p = Q(l), C = M(p.name), g = f(c, `css/f_${C}-${$}.css`);
379
- k(g, y);
377
+ d.importStrategy === "component" && Object.entries(g).forEach(([l, m]) => {
378
+ const w = m.map((L) => `@import url('./${L}');`).join(`
379
+ `), u = H(l, 6), N = Q(l), S = M(N.name), y = f(c, `css/f_${S}-${u}.css`);
380
+ k(y, w);
380
381
  });
381
- const b = i.map((l) => `@import url('./css/${l}');`).join(`
382
+ const $ = i.map((l) => `@import url('./css/${l}');`).join(`
382
383
  `);
383
- let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
384
+ let F = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
384
385
 
385
386
  ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
386
387
  try {
@@ -390,27 +391,27 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) =
390
391
  }
391
392
  }).map((l) => `@import url('./css/${l}');`).join(`
392
393
  `)}
393
- ${b}`;
394
- if (h.importStrategy !== "component") {
395
- const l = a.reduce((S, y, $) => {
396
- const p = y.reduce((B, K) => {
397
- var N;
398
- const G = f(c, "css", K), q = V(G, "utf8"), F = ((N = /.*-([^-]+)-\d+.css/.exec(K)) == null ? void 0 : N.at(1)) || H(G, 6);
399
- return B.includes(F) ? B : `${B}
400
- /*start:${F}*/
394
+ ${$}`;
395
+ if (d.importStrategy !== "component") {
396
+ const l = a.reduce((m, w, u) => {
397
+ const N = w.reduce((B, K) => {
398
+ var x;
399
+ const G = f(c, "css", K), q = V(G, "utf8"), j = ((x = /.*-([^-]+)-\d+.css/.exec(K)) == null ? void 0 : x.at(1)) || H(G, 6);
400
+ return B.includes(j) ? B : `${B}
401
+ /*start:${j}*/
401
402
  ${q}
402
- /*end:${F}*/
403
+ /*end:${j}*/
403
404
  `;
404
- }, ""), C = `l_${$}.css`, g = f(c, "css", C), L = `@layer l${$} { ${p}
405
+ }, ""), S = `l_${u}.css`, y = f(c, "css", S), L = `@layer l${u} { ${N}
405
406
  }`;
406
- return k(g, L), `${S}
407
- @import url('./css/${C}');`;
407
+ return k(y, L), `${m}
408
+ @import url('./css/${S}');`;
408
409
  }, "");
409
- x += l;
410
+ F += l;
410
411
  }
411
- k(u, x);
412
- const w = Date.now() - n, T = w < 200 ? "🔥" : w < 500 ? "🚀" : w < 1e3 ? "🎉" : w < 2e3 ? "🚗" : w < 5e3 ? "🤔" : "🥴";
413
- et.info(`Generated CSS in ${w}ms! ${T}`);
412
+ k(p, F);
413
+ const b = Date.now() - n, T = b < 200 ? "🔥" : b < 500 ? "🚀" : b < 1e3 ? "🎉" : b < 2e3 ? "🚗" : b < 5e3 ? "🤔" : "🥴";
414
+ et.info(`Generated CSS in ${b}ms! ${T}`);
414
415
  } catch (n) {
415
416
  console.error(n);
416
417
  }
@@ -419,48 +420,48 @@ ${q}
419
420
  const s = await A(t);
420
421
  if (I(e)) {
421
422
  const i = [], a = await it(t), c = await rt(t, e, s);
422
- if (Object.entries(c).forEach(([u, r]) => {
423
+ if (Object.entries(c).forEach(([p, r]) => {
423
424
  if (r.isKeyframes && r.css) {
424
- const b = `css/${`a_${r.animationName}.css`}`, D = f(s, b);
425
- k(D, r.css);
425
+ const $ = `css/${`a_${r.animationName}.css`}`, P = f(s, $);
426
+ k(P, r.css);
426
427
  return;
427
428
  }
428
429
  if (r.isClassName) {
429
- const d = r.factory._withBuildContext({
430
- name: u
430
+ const g = r.factory._withBuildContext({
431
+ name: p
431
432
  });
432
- i[0].push(d.cssFileName);
433
- const b = `css/${d.cssFileName}`, D = f(s, b);
434
- k(D, d.css);
433
+ i[0].push(g.cssFileName);
434
+ const $ = `css/${g.cssFileName}`, P = f(s, $);
435
+ k(P, g.css);
435
436
  }
436
437
  if (!r.generator) return;
437
438
  const o = r.generator._withBuildContext({
438
- name: u,
439
+ name: p,
439
440
  config: a
440
- }), m = `css/${o.cssFileName}`, h = f(s, m);
441
- k(h, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
441
+ }), h = `css/${o.cssFileName}`, d = f(s, h);
442
+ k(d, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
442
443
  }), a.importStrategy !== "component")
443
- i.forEach((u, r) => {
444
- const o = `l_${r}.css`, m = f(s, "css", o);
445
- let h = V(m, "utf8");
446
- u.forEach((d) => {
447
- var j;
448
- const b = f(s, "css", d), D = ((j = /.*-([^-]+)-\d+.css/.exec(d)) == null ? void 0 : j.at(1)) || H(b, 6);
449
- if (!h.includes(D)) {
450
- const x = V(b, "utf8"), P = `/*start:${D}*/
451
- ${x}
452
- /*end:${D}*/
444
+ i.forEach((p, r) => {
445
+ const o = `l_${r}.css`, h = f(s, "css", o);
446
+ let d = V(h, "utf8");
447
+ p.forEach((g) => {
448
+ var C;
449
+ const $ = f(s, "css", g), P = ((C = /.*-([^-]+)-\d+.css/.exec(g)) == null ? void 0 : C.at(1)) || H($, 6);
450
+ if (!d.includes(P)) {
451
+ const F = V($, "utf8"), D = `/*start:${P}*/
452
+ ${F}
453
+ /*end:${P}*/
453
454
  `;
454
- h = `${h.replace(/\}$/, "")}
455
- ${P}
455
+ d = `${d.replace(/\}$/, "")}
456
+ ${D}
456
457
  }`;
457
458
  }
458
- }), k(m, h);
459
+ }), k(h, d);
459
460
  });
460
461
  else {
461
- const u = i.flat().map((d) => `@import url('./${d}');`).join(`
462
- `), r = H(e, 6), o = Q(e), m = M(o.name), h = f(s, `css/f_${m}-${r}.css`);
463
- k(h, u);
462
+ const p = i.flat().map((g) => `@import url('./${g}');`).join(`
463
+ `), r = H(e, 6), o = Q(e), h = M(o.name), d = f(s, `css/f_${h}-${r}.css`);
464
+ k(d, p);
464
465
  }
465
466
  }
466
467
  } catch (s) {
@@ -471,35 +472,35 @@ ${P}
471
472
  const n = await A(t);
472
473
  if (I(e)) {
473
474
  const a = V(e, "utf8");
474
- a.replace(/^(?!export\s)const\s.*/gm, (m) => `export ${m}`) !== a && await xt(e, a);
475
- const u = await it(t), r = await rt(t, e, n);
475
+ a.replace(/^(?!export\s)const\s.*/gm, (h) => `export ${h}`) !== a && await Nt(e, a);
476
+ const p = await it(t), r = await rt(t, e, n);
476
477
  let o = a;
477
- if (Object.entries(r).forEach(([m, h]) => {
478
- var C;
479
- if (h.isKeyframes || !h.generator) return;
480
- const d = h.generator._withBuildContext({
481
- name: m,
482
- config: u,
478
+ if (Object.entries(r).forEach(([h, d]) => {
479
+ var S;
480
+ if (d.isKeyframes || !d.generator) return;
481
+ const g = d.generator._withBuildContext({
482
+ name: h,
483
+ config: p,
483
484
  prod: s
484
- }), b = new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
485
- if (!b) return console.error("Could not find the original declaration");
486
- const D = (C = b.at(1)) == null ? void 0 : C.trim(), E = new RegExp(`\\s${m}[=\\s]+styled\\(`, "g").exec(o);
485
+ }), $ = new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
486
+ if (!$) return console.error("Could not find the original declaration");
487
+ const P = (S = $.at(1)) == null ? void 0 : S.trim(), E = new RegExp(`\\s${h}[=\\s]+styled\\(`, "g").exec(o);
487
488
  if (!E) return console.error("Could not find the original declaration");
488
- const { index: j } = E;
489
- let x = !1;
490
- const P = setTimeout(() => x = !0, 5e3);
491
- let w = 0, T = !1, l = 0;
492
- for (; !T && !x; ) {
493
- const g = o[j + w];
494
- g === "(" && l++, g === ")" && l--, l === 0 && g === ")" && (T = !0), w > o.length && (x = !0), w++;
489
+ const { index: C } = E;
490
+ let F = !1;
491
+ const D = setTimeout(() => F = !0, 5e3);
492
+ let b = 0, T = !1, l = 0;
493
+ for (; !T && !F; ) {
494
+ const y = o[C + b];
495
+ y === "(" && l++, y === ")" && l--, l === 0 && y === ")" && (T = !0), b > o.length && (F = !0), b++;
495
496
  }
496
- if (!x) clearTimeout(P);
497
+ if (!F) clearTimeout(D);
497
498
  else throw new Error("Failed to find the end of the styled call and timed out");
498
- const S = j + w, y = o.slice(j, S), $ = o, p = ` ${m} = styled(${D}, "${d.classNames}", ${JSON.stringify(d.props)});`;
499
- o = o.replace(y, p), $ === o && console.error("Minimize file failed to change content", { name: m, tagName: D });
500
- }), u.importStrategy === "component") {
501
- const m = H(e, 6), h = Q(e);
502
- o = `import '../../saltygen/css/${`f_${M(h.name)}-${m}.css`}';
499
+ const m = C + b, w = o.slice(C, m), u = o, N = ` ${h} = styled(${P}, "${g.classNames}", ${JSON.stringify(g.clientProps)});`;
500
+ o = o.replace(w, N), u === o && console.error("Minimize file failed to change content", { name: h, tagName: P });
501
+ }), p.importStrategy === "component") {
502
+ const h = H(e, 6), d = Q(e);
503
+ o = `import '../../saltygen/css/${`f_${M(d.name)}-${h}.css`}';
503
504
  ${o}`;
504
505
  }
505
506
  return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.189",
3
+ "version": "0.0.1-alpha.190",
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.189"
37
+ "@salty-css/core": "^0.0.1-alpha.190"
38
38
  }
39
39
  }