@salty-css/vite 0.0.1-alpha.187 → 0.0.1-alpha.188

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 +22 -22
  2. package/index.js +260 -260
  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 me=require("esbuild"),Se=require("child_process"),l=require("path"),u=require("fs"),B=require("fs/promises"),L=require("winston");var Q=typeof document<"u"?document.currentScript:null;function be(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 oe=be(me),te=e=>String.fromCharCode(e+(e>25?39:97)),je=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=te(n%52)+s;return s=te(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},$e=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},Z=(e,t=5)=>{const s=$e(5381,JSON.stringify(e))>>>0;return je(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 we=(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}},re=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(([D,b])=>{b&&Object.entries(b).forEach(([O,f])=>{if(!f)return;const j=`${t}.${D}-${O}`,S=R(f,j);n.push(S)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(D=>{const{css:b,...O}=D,f=Object.entries(O).reduce((S,[$,y])=>`${S}.${$}-${y}`,t),j=R(b,f);n.push(j)}),c;if(o.startsWith("@")){const D=R(r,t),b=`${o} {
2
- ${D.replace(`
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} {
2
+ ${_.replace(`
3
3
  `,`
4
4
  `)}
5
- }`;return n.push(b),c}const F=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,C=R(r,F);return n.push(C),c}const m=o.startsWith("-")?o:M(o),g=(F,C=";")=>c=`${c}${F}${C}`,d=F=>g(`${m}:${F}`);if(typeof r=="number")return d(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:N}={},T=function*(){yield re(r),yield we(r,N)}();for(const{result:F,additionalCss:C=[]}of T)r=F,C.forEach(D=>{const b=R(D,"");g(b,"")});return d(r)},"");return i?t?[`${t} { ${i} }`,...n].join(`
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(`
6
6
  `):i:n.join(`
7
- `)},ie=(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=ie(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
- `)},Fe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ce(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},ce=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?ce(i,a,s):s.add(t)}),[...s]):[],ae=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:ae(l.join(e,".."))},Ce=async e=>{const t=ae(e);return await B.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Ne=async e=>{const t=await Ce(e);if(t)return t.type};let W;const le=async e=>{if(W)return W;const t=await Ne(e);return t==="module"?W="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Q&&Q.tagName.toUpperCase()==="SCRIPT"&&Q.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(W="cjs"),W||"esm"},X=L.createLogger({level:"debug",format:L.format.combine(L.format.colorize(),L.format.cli()),transports:[new L.transports.Console({})]});function fe(e){return e?typeof e!="string"?fe(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={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},z=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),V={externalModules:[],rcFile:void 0,destDir:void 0},ue=e=>{if(V.externalModules.length>0)return V.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 V.externalModules=n,n},J=async e=>{if(V.destDir)return V.destDir;const t=await Y(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},de=["salty","css","styles","styled"],ke=(e=[])=>new RegExp(`\\.(${[...de,...e].join("|")})\\.`),I=(e,t=[])=>ke(t).test(e),pe=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await B.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):pe(l.join(e,".."))},Y=async e=>{var n,i;const t=await pe(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))},Pe=async e=>{const t=await Y(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 le(e),c=ue(n);await oe.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},De=async(e,t)=>{const s=await Pe(e),n={...s},i=new Set,a=(P,k=[])=>P?Object.entries(P).flatMap(([E,_])=>{if(!_)return;if(typeof _=="object")return a(_,[...k,E]);const A=fe(E),G=M(E),K=[...k,A].join(".");i.add(`"${K}"`);const U=[...k.map(M),G].join("-"),{result:he}=re(_);return`--${U}: ${he};`}):[],c=P=>P?Object.entries(P).flatMap(([k,E])=>{const _=a(E);return k==="base"?_.join(""):`${k} { ${_.join("")} }`}):[],p=P=>P?Object.entries(P).flatMap(([k,E])=>Object.entries(E).flatMap(([_,A])=>{const G=a(A,[k]),K=`.${k}-${_}, [data-${k}="${_}"]`,U=G.join("");return`${K} { ${U} }`})):[],r=P=>t.variables.map(k=>k._current[P]),o=a(z(s.variables,r("variables"))),m=c(z(s.responsiveVariables,r("responsiveVariables"))),g=p(z(s.conditionalVariables,r("conditionalVariables"))),d=await J(e),N=l.join(d,"css/_variables.css"),x=`:root { ${o.join("")} ${m.join("")} } ${g.join("")}`;u.writeFileSync(N,x);const T=l.join(d,"css/_global.css"),F=z(s.global,t.globalStyles),C=R(F,"");u.writeFileSync(T,`@layer global { ${C} }`);const D=l.join(d,"css/_reset.css"),O=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:xe,f=R(O,"");u.writeFileSync(D,`@layer reset { ${f} }`);const j=l.join(d,"css/_templates.css"),S=z(s.templates,t.templates),$=ie(S),y=Fe(S);u.writeFileSync(j,$),n.templates=S;const w=l.join(d,"types/css-tokens.d.ts"),H=`
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=`
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(y).map(([P,k])=>`${P}?: ${k}`).join(`
15
+ ${Object.entries(F).map(([x,k])=>`${x}?: ${k}`).join(`
16
16
  `)}
17
17
  }
18
- `;u.writeFileSync(w,H);const q=l.join(d,"cache/config-cache.json");u.writeFileSync(q,JSON.stringify(n,null,2))},se=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(de.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),v=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=se(c);const p=l.join(s,"js",n+".js"),r=await Y(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),m=ue(o),g=await le(e);await oe.build({stdin:{contents:c,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:g,target:["node20"],keepNames:!0,external:m,packages:"external",plugins:[{name:"test",setup:x=>{x.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const F=u.readFileSync(T.path,"utf8");return{contents:se(F),loader:"ts"}})}}]});const d=Date.now();return await import(`${p}?t=${d}`)},_e=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)},ee=async e=>{const t=await _e(e),s=await J(e),n=l.join(s,"salty.config.js"),i=Date.now(),{config:a}=await import(`${n}?t=${i}`);return z(a,t)},ye=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Te=async(e,t=ye(),s=!0)=>{try{const n=Date.now();t?X.info("Generating CSS in production mode! 🔥"):X.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(e),p=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&Se.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 j=["node_modules","saltygen"],S=u.statSync(f);if(S.isDirectory()){const $=u.readdirSync(f);if(j.some(w=>f.includes(w)))return;await Promise.all($.map(w=>m(l.join(f,w))))}else if(S.isFile()&&I(f)){const y=await v(e,f,c);Object.entries(y).forEach(([w,h])=>{h.isKeyframes?o.keyframes.push({value:h,src:f,name:w}):h.isMedia?o.mediaQueries.push(h):h.isGlobalDefine?o.globalStyles.push(h):h.isDefineVariables?o.variables.push(h):h.isDefineTemplates?o.templates.push(h):h.isClassName?o.classNames.push({value:h.factory,src:f,name:w}):h.generator&&o.components.push({value:h.generator,src:f,name:w})})}}await m(e),await De(e,o);const g=await ee(e);for(const f of o.keyframes){const{value:j}=f,S=`a_${j.animationName}.css`,$=`css/${S}`,y=l.join(c,$);i.push(S),u.writeFileSync(y,j.css)}const d={};for(const f of o.components){const{value:j,name:S,src:$}=f,y=j._withBuildContext({name:S,config:g,prod:t});a[y.priority]||(a[y.priority]=[]),a[y.priority].push(y.cssFileName);const w=`css/${y.cssFileName}`,h=l.join(c,w);u.writeFileSync(h,y.css),g.importStrategy==="component"&&(d[$]?d[$].push(y.cssFileName):d[$]=[y.cssFileName])}for(const f of o.classNames){const{value:j,src:S,name:$}=f,y=j._withBuildContext({name:$,prod:t});a[0].push(y.cssFileName);const w=`css/${y.cssFileName}`,h=l.join(c,w);u.writeFileSync(h,y.css),g.importStrategy==="component"&&(d[S]?d[S].push(y.cssFileName):d[S]=[y.cssFileName])}g.importStrategy==="component"&&Object.entries(d).forEach(([f,j])=>{const S=j.map(H=>`@import url('./${H}');`).join(`
19
- `),$=Z(f,6),y=l.parse(f),w=M(y.name),h=l.join(c,`css/f_${w}-${$}.css`);u.writeFileSync(h,S)});const N=i.map(f=>`@import url('./css/${f}');`).join(`
20
- `);let C=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
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(`
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
- ${N}`;if(g.importStrategy!=="component"){const f=a.reduce((j,S,$)=>{const y=S.reduce((q,P)=>{var A;const k=l.join(c,"css",P),E=u.readFileSync(k,"utf8"),_=((A=/.*-([^-]+)-\d+.css/.exec(P))==null?void 0:A.at(1))||Z(k,6);return q.includes(_)?q:`${q}
25
- /*start:${_}*/
26
- ${E}
27
- /*end:${_}*/
28
- `},""),w=`l_${$}.css`,h=l.join(c,"css",w),H=`@layer l${$} { ${y}
29
- }`;return u.writeFileSync(h,H),`${j}
30
- @import url('./css/${w}');`},"");C+=f}u.writeFileSync(p,C);const b=Date.now()-n,O=b<200?"🔥":b<500?"🚀":b<1e3?"🎉":b<2e3?"🚗":b<5e3?"🤔":"🥴";X.info(`Generated CSS in ${b}ms! ${O}`)}catch(n){console.error(n)}},Oe=async(e,t)=>{try{const s=await J(e);if(I(t)){const i=[],a=await ee(e),c=await v(e,t,s);if(Object.entries(c).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const N=`css/${`a_${r.animationName}.css`}`,x=l.join(s,N);u.writeFileSync(x,r.css);return}if(r.isClassName){console.log("found className value",r);const d=r.factory._withBuildContext({name:p});i[0].push(d.cssFileName);const N=`css/${d.cssFileName}`,x=l.join(s,N);u.writeFileSync(x,d.css),console.log(x,d.css)}if(!r.generator)return;const o=r.generator._withBuildContext({name:p,config:a}),m=`css/${o.cssFileName}`,g=l.join(s,m);u.writeFileSync(g,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),console.log(i),a.importStrategy!=="component")i.forEach((p,r)=>{const o=`l_${r}.css`,m=l.join(s,"css",o);let g=u.readFileSync(m,"utf8");p.forEach(d=>{var F;const N=l.join(s,"css",d),x=((F=/.*-([^-]+)-\d+.css/.exec(d))==null?void 0:F.at(1))||Z(N,6);if(!g.includes(x)){const C=u.readFileSync(N,"utf8"),D=`/*start:${x}*/
31
- ${C}
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}*/
26
+ ${G}
32
27
  /*end:${x}*/
33
- `;g=`${g.replace(/\}$/,"")}
34
- ${D}
35
- }`}}),u.writeFileSync(m,g)});else{const p=i.flat().map(d=>`@import url('./${d}');`).join(`
36
- `),r=Z(t,6),o=l.parse(t),m=M(o.name),g=l.join(s,`css/f_${m}-${r}.css`);u.writeFileSync(g,p)}}}catch(s){console.error(s)}},Ee=async(e,t,s=ye())=>{try{const n=await J(e);if(I(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,m=>`export ${m}`)!==a&&await B.writeFile(t,a);const p=await ee(e),r=await v(e,t,n);let o=a;if(Object.entries(r).forEach(([m,g])=>{var w;if(g.isKeyframes||!g.generator)return;const d=g.generator._withBuildContext({name:m,config:p,prod:s}),N=new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!N)return console.error("Could not find the original declaration");const x=(w=N.at(1))==null?void 0:w.trim(),T=new RegExp(`\\s${m}[=\\s]+styled\\(`,"g").exec(o);if(!T)return console.error("Could not find the original declaration");const{index:F}=T;let C=!1;const D=setTimeout(()=>C=!0,5e3);let b=0,O=!1,f=0;for(;!O&&!C;){const h=o[F+b];h==="("&&f++,h===")"&&f--,f===0&&h===")"&&(O=!0),b>o.length&&(C=!0),b++}if(!C)clearTimeout(D);else throw new Error("Failed to find the end of the styled call and timed out");const j=F+b,S=o.slice(F,j),$=o,y=` ${m} = styled(${x}, "${d.classNames}", ${JSON.stringify(d.props)});`;o=o.replace(S,y),$===o&&console.error("Minimize file failed to change content",{name:m,tagName:x})}),p.importStrategy==="component"){const m=Z(t,6),g=l.parse(t);o=`import '../../saltygen/css/${`f_${M(g.name)}-${m}.css`}';
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)}},ne=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!I(e))return!1;const n=await B.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},ge=e=>({name:"stylegen",buildStart:()=>Te(e),load:async t=>{if(I(t))return await Ee(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ne(t)&&await s.restart()},watchChange:{handler:async t=>{I(t)&&(await ne(t)||await Oe(e,t))}}});exports.default=ge;exports.saltyPlugin=ge;
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}*/
31
+ ${N}
32
+ /*end:${P}*/
33
+ `;h=`${h.replace(/\}$/,"")}
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`}';
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
@@ -1,46 +1,46 @@
1
- import * as ct from "esbuild";
2
- import { execSync as bt } from "child_process";
3
- import { join as f, parse as K } from "path";
4
- import { existsSync as v, mkdirSync as Z, statSync as wt, readdirSync as St, writeFileSync as k, readFileSync as M } from "fs";
5
- import { readFile as tt, writeFile as Ct } from "fs/promises";
6
- import { createLogger as jt, format as X, transports as Ft } from "winston";
7
- const ot = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Nt = (t, e) => {
1
+ import * as ft from "esbuild";
2
+ import { execSync as Ct } from "child_process";
3
+ import { join as f, parse as Q } from "path";
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) => {
8
8
  let s = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = ot(n % 52) + s;
10
- return s = ot(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
- }, xt = (t, e) => {
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = ct(n % 52) + s;
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) => {
12
12
  let s = e.length;
13
13
  for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
14
  return t;
15
- }, I = (t, e = 5) => {
16
- const s = xt(5381, JSON.stringify(t)) >>> 0;
17
- return Nt(s, e);
15
+ }, H = (t, e = 5) => {
16
+ const s = Pt(5381, JSON.stringify(t)) >>> 0;
17
+ return Dt(s, e);
18
18
  };
19
- function R(t) {
20
- return t ? typeof t != "string" ? R(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
19
+ function M(t) {
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()) : "";
21
21
  }
22
- const kt = (t, e) => {
22
+ const Et = (t, e) => {
23
23
  if (typeof t != "string") return { result: t };
24
24
  if (!e) return { result: t };
25
25
  const s = [];
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: p, css: r } = a(c);
30
- return r && s.push(r), p;
29
+ const { value: u, css: r } = a(c);
30
+ return r && s.push(r), u;
31
31
  });
32
32
  }), { result: t, additionalCss: s };
33
- }, at = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${R(n[1].replaceAll(".", "-"))})`) } : { result: t }, J = (t, e, s) => {
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, [p, r]) => {
36
- const o = p.trim();
35
+ const n = [], i = Object.entries(t).reduce((c, [u, r]) => {
36
+ const o = u.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, $]) => {
41
- $ && Object.entries($).forEach(([_, l]) => {
40
+ return Object.entries(r).forEach(([P, w]) => {
41
+ w && Object.entries(w).forEach(([T, l]) => {
42
42
  if (!l) return;
43
- const b = `${e}.${P}-${_}`, y = J(l, b);
43
+ const S = `${e}.${P}-${T}`, y = R(l, S);
44
44
  n.push(y);
45
45
  });
46
46
  }), c;
@@ -48,84 +48,84 @@ const kt = (t, e) => {
48
48
  return c;
49
49
  if (o === "compoundVariants")
50
50
  return r.forEach((P) => {
51
- const { css: $, ..._ } = P, l = Object.entries(_).reduce((y, [w, d]) => `${y}.${w}-${d}`, e), b = J($, l);
52
- n.push(b);
51
+ const { css: w, ...T } = P, l = Object.entries(T).reduce((y, [$, p]) => `${y}.${$}-${p}`, e), S = R(w, l);
52
+ n.push(S);
53
53
  }), c;
54
54
  if (o.startsWith("@")) {
55
- const P = J(r, e), $ = `${o} {
55
+ const P = R(r, e), w = `${o} {
56
56
  ${P.replace(`
57
57
  `, `
58
58
  `)}
59
59
  }`;
60
- return n.push($), c;
60
+ return n.push(w), c;
61
61
  }
62
- const C = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, j = J(r, C);
63
- return n.push(j), c;
62
+ const j = u.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, x = R(r, j);
63
+ return n.push(x), c;
64
64
  }
65
- const m = o.startsWith("-") ? o : R(o), g = (C, j = ";") => c = `${c}${C}${j}`, u = (C) => g(`${m}:${C}`);
66
- if (typeof r == "number") return u(r);
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);
67
67
  if (typeof r != "string")
68
68
  if ("toString" in r) r = r.toString();
69
69
  else return c;
70
- const { modifiers: F } = {}, T = function* () {
71
- yield at(r), yield kt(r, F);
70
+ const { modifiers: b } = {}, E = function* () {
71
+ yield ut(r), yield Et(r, b);
72
72
  }();
73
- for (const { result: C, additionalCss: j = [] } of T)
74
- r = C, j.forEach((P) => {
75
- const $ = J(P, "");
76
- g($, "");
73
+ for (const { result: j, additionalCss: x = [] } of E)
74
+ r = j, x.forEach((P) => {
75
+ const w = R(P, "");
76
+ h(w, "");
77
77
  });
78
- return u(r);
78
+ return d(r);
79
79
  }, "");
80
80
  return i ? e ? [`${e} { ${i} }`, ...n].join(`
81
81
  `) : i : n.join(`
82
82
  `);
83
- }, lt = (t, e = []) => {
83
+ }, pt = (t, e = []) => {
84
84
  if (!t) return "";
85
85
  const s = [], n = {};
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(), p = lt(a, [...e, c]);
90
- s.push(p);
89
+ const c = i.trim(), u = pt(a, [...e, c]);
90
+ s.push(u);
91
91
  } else
92
92
  n[i] = a;
93
93
  }), Object.keys(n).length) {
94
- const i = e.map(R).join("-"), a = J(n, `.${i}`);
94
+ const i = e.map(M).join("-"), a = R(n, `.${i}`);
95
95
  s.push(a);
96
96
  }
97
97
  return s.join(`
98
98
  `);
99
- }, Dt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ft(n).map((i) => `"${i}"`).join(" | ")), e), {}) : {}, ft = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
99
+ }, _t = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = dt(n).map((i) => `"${i}"`).join(" | ")), e), {}) : {}, dt = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
100
100
  const a = e ? `${e}.${n}` : n;
101
- return typeof i == "object" ? ft(i, a, s) : s.add(e);
102
- }), [...s]) : [], ut = (t) => {
101
+ return typeof i == "object" ? dt(i, a, s) : s.add(e);
102
+ }), [...s]) : [], gt = (t) => {
103
103
  if (!t || t === "/") throw new Error("Could not find package.json file");
104
104
  const e = f(t, "package.json");
105
- return v(e) ? e : ut(f(t, ".."));
106
- }, Pt = async (t) => {
107
- const e = ut(t);
108
- return await tt(e, "utf-8").then(JSON.parse).catch(() => {
105
+ return st(e) ? e : gt(f(t, ".."));
106
+ }, Tt = async (t) => {
107
+ const e = gt(t);
108
+ return await nt(e, "utf-8").then(JSON.parse).catch(() => {
109
109
  });
110
- }, Et = async (t) => {
111
- const e = await Pt(t);
110
+ }, Ot = async (t) => {
111
+ const e = await Tt(t);
112
112
  if (e)
113
113
  return e.type;
114
114
  };
115
- let z;
116
- const pt = async (t) => {
117
- if (z) return z;
118
- const e = await Et(t);
119
- return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
120
- }, Y = jt({
115
+ let W;
116
+ const ht = async (t) => {
117
+ if (W) return W;
118
+ const e = await Ot(t);
119
+ return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
120
+ }, et = Nt({
121
121
  level: "debug",
122
- format: X.combine(X.colorize(), X.cli()),
123
- transports: [new Ft.Console({})]
122
+ format: tt.combine(tt.colorize(), tt.cli()),
123
+ transports: [new kt.Console({})]
124
124
  });
125
- function dt(t) {
126
- return t ? typeof t != "string" ? dt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
125
+ function mt(t) {
126
+ return t ? typeof t != "string" ? mt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
127
127
  }
128
- const Tt = {
128
+ const Vt = {
129
129
  /** Set box model to border-box */
130
130
  "*, *::before, *::after": {
131
131
  boxSizing: "border-box"
@@ -171,33 +171,33 @@ const Tt = {
171
171
  fontSize: "100%",
172
172
  lineHeight: "1.15em"
173
173
  }
174
- }, H = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), V = {
174
+ }, Z = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), O = {
175
175
  externalModules: [],
176
176
  rcFile: void 0,
177
177
  destDir: void 0
178
- }, gt = (t) => {
179
- if (V.externalModules.length > 0) return V.externalModules;
180
- const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
178
+ }, yt = (t) => {
179
+ if (O.externalModules.length > 0) return O.externalModules;
180
+ const s = V(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
181
181
  if (!s) return [];
182
182
  const n = s[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
183
- return V.externalModules = n, n;
183
+ return O.externalModules = n, n;
184
184
  }, A = async (t) => {
185
- if (V.destDir) return V.destDir;
186
- const e = await et(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
187
- return V.destDir = s, s;
188
- }, ht = ["salty", "css", "styles", "styled"], _t = (t = []) => new RegExp(`\\.(${[...ht, ...t].join("|")})\\.`), B = (t, e = []) => _t(e).test(t), mt = async (t) => {
189
- if (V.rcFile) return V.rcFile;
185
+ if (O.destDir) return O.destDir;
186
+ const e = await ot(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
187
+ return O.destDir = s, s;
188
+ }, $t = ["salty", "css", "styles", "styled"], Mt = (t = []) => new RegExp(`\\.(${[...$t, ...t].join("|")})\\.`), I = (t, e = []) => Mt(e).test(t), bt = async (t) => {
189
+ if (O.rcFile) return O.rcFile;
190
190
  if (t === "/") throw new Error("Could not find .saltyrc.json file");
191
- const e = f(t, ".saltyrc.json"), s = await tt(e, "utf-8").then(JSON.parse).catch(() => {
191
+ const e = f(t, ".saltyrc.json"), s = await nt(e, "utf-8").then(JSON.parse).catch(() => {
192
192
  });
193
- return s ? (V.rcFile = s, s) : mt(f(t, ".."));
194
- }, et = async (t) => {
193
+ return s ? (O.rcFile = s, s) : bt(f(t, ".."));
194
+ }, ot = async (t) => {
195
195
  var n, i;
196
- const e = await mt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
196
+ const e = await bt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
197
197
  return s || ((i = e.projects) == null ? void 0 : i.find((a) => a.dir === e.defaultProject));
198
- }, Ot = async (t) => {
199
- const e = await et(t), s = await A(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), i = f(s, "salty.config.js"), a = await pt(t), c = gt(n);
200
- await ct.build({
198
+ }, Rt = async (t) => {
199
+ const e = await ot(t), s = await A(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), i = f(s, "salty.config.js"), a = await ht(t), c = yt(n);
200
+ await ft.build({
201
201
  entryPoints: [n],
202
202
  minify: !0,
203
203
  treeShaking: !0,
@@ -206,62 +206,63 @@ const Tt = {
206
206
  format: a,
207
207
  external: c
208
208
  });
209
- const p = Date.now(), { config: r } = await import(`${i}?t=${p}`);
209
+ const u = Date.now(), { config: r } = await import(`${i}?t=${u}`);
210
210
  return r;
211
- }, Vt = async (t, e) => {
212
- const s = await Ot(t), n = { ...s }, i = /* @__PURE__ */ new Set(), a = (D, x = []) => D ? Object.entries(D).flatMap(([O, E]) => {
213
- if (!E) return;
214
- if (typeof E == "object") return a(E, [...x, O]);
215
- const W = dt(O), q = R(O), Q = [...x, W].join(".");
216
- i.add(`"${Q}"`);
217
- const U = [...x.map(R), q].join("-"), { result: $t } = at(E);
218
- return `--${U}: ${$t};`;
219
- }) : [], c = (D) => D ? Object.entries(D).flatMap(([x, O]) => {
220
- const E = a(O);
221
- return x === "base" ? E.join("") : `${x} { ${E.join("")} }`;
222
- }) : [], p = (D) => D ? Object.entries(D).flatMap(([x, O]) => Object.entries(O).flatMap(([E, W]) => {
223
- const q = a(W, [x]), Q = `.${x}-${E}, [data-${x}="${E}"]`, U = q.join("");
224
- return `${Q} { ${U} }`;
225
- })) : [], r = (D) => e.variables.map((x) => x._current[D]), o = a(H(s.variables, r("variables"))), m = c(H(s.responsiveVariables, r("responsiveVariables"))), g = p(H(s.conditionalVariables, r("conditionalVariables"))), u = await A(t), F = f(u, "css/_variables.css"), N = `:root { ${o.join("")} ${m.join("")} } ${g.join("")}`;
226
- k(F, N);
227
- const T = f(u, "css/_global.css"), C = H(s.global, e.globalStyles), j = J(C, "");
228
- k(T, `@layer global { ${j} }`);
229
- const P = f(u, "css/_reset.css"), _ = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Tt, l = J(_, "");
230
- k(P, `@layer reset { ${l} }`);
231
- const b = f(u, "css/_templates.css"), y = H(s.templates, e.templates), w = lt(y), d = Dt(y);
232
- k(b, w), n.templates = y;
233
- const S = f(u, "types/css-tokens.d.ts"), G = `
211
+ }, Jt = async (t, e) => {
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, _]) => {
214
+ if (!_) return;
215
+ if (typeof _ == "object") return a(_, [...N, J]);
216
+ const U = mt(J), X = M(J), Y = [...N, U].join(".");
217
+ i.add(`"${Y}"`);
218
+ const v = [...N.map(M), X].join("-"), { result: St } = ut(_);
219
+ return `--${v}: ${St};`;
220
+ }) : [], c = (F) => F ? Object.entries(F).flatMap(([N, J]) => {
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("");
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 = `
234
235
  // Variable types
235
236
  type VariableTokens = ${[...i].join("|")};
236
237
  type PropertyValueToken = \`{\${VariableTokens}}\`;
237
238
 
238
239
  // Template types
239
240
  type TemplateTokens = {
240
- ${Object.entries(d).map(([D, x]) => `${D}?: ${x}`).join(`
241
+ ${Object.entries(C).map(([F, N]) => `${F}?: ${N}`).join(`
241
242
  `)}
242
243
  }
243
244
  `;
244
- k(S, G);
245
- const L = f(u, "cache/config-cache.json");
246
- k(L, JSON.stringify(n, null, 2));
247
- }, rt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
245
+ k(g, B);
246
+ const K = f(b, "cache/config-cache.json");
247
+ k(K, JSON.stringify(n, null, 2));
248
+ }, at = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
248
249
  if (/^['"`]/.test(s)) return e;
249
250
  const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
250
251
  if (!i.test(t)) return e;
251
252
  const c = i.exec(t);
252
253
  if (c) {
253
- const p = c.at(1);
254
- if (ht.some((o) => p == null ? void 0 : p.includes(o))) return e;
254
+ const u = c.at(1);
255
+ if ($t.some((o) => u == null ? void 0 : u.includes(o))) return e;
255
256
  }
256
257
  return "styled('div',";
257
- }), st = async (t, e, s) => {
258
- const n = I(e), i = f(s, "./temp");
259
- v(i) || Z(i);
260
- const a = K(e);
261
- let c = M(e, "utf8");
262
- c = rt(c);
263
- const p = f(s, "js", n + ".js"), r = await et(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), m = gt(o), g = await pt(t);
264
- await ct.build({
258
+ }), rt = async (t, e, s) => {
259
+ const n = H(e), i = f(s, "./temp");
260
+ st(i) || z(i);
261
+ const a = Q(e);
262
+ let c = V(e, "utf8");
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);
265
+ await ft.build({
265
266
  stdin: {
266
267
  contents: c,
267
268
  sourcefile: a.base,
@@ -271,8 +272,8 @@ const Tt = {
271
272
  minify: !1,
272
273
  treeShaking: !0,
273
274
  bundle: !0,
274
- outfile: p,
275
- format: g,
275
+ outfile: u,
276
+ format: h,
276
277
  target: ["node20"],
277
278
  keepNames: !0,
278
279
  external: m,
@@ -280,37 +281,37 @@ const Tt = {
280
281
  plugins: [
281
282
  {
282
283
  name: "test",
283
- setup: (N) => {
284
- N.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
285
- const C = M(T.path, "utf8");
286
- return { contents: rt(C), loader: "ts" };
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" };
287
288
  });
288
289
  }
289
290
  }
290
291
  ]
291
292
  });
292
- const u = Date.now();
293
- return await import(`${p}?t=${u}`);
294
- }, Mt = async (t) => {
295
- const e = await A(t), s = f(e, "cache/config-cache.json"), n = M(s, "utf8");
293
+ const d = Date.now();
294
+ return await import(`${u}?t=${d}`);
295
+ }, At = async (t) => {
296
+ const e = await A(t), s = f(e, "cache/config-cache.json"), n = V(s, "utf8");
296
297
  if (!n) throw new Error("Could not find config cache file");
297
298
  return JSON.parse(n);
298
- }, nt = async (t) => {
299
- const e = await Mt(t), s = await A(t), n = f(s, "salty.config.js"), i = Date.now(), { config: a } = await import(`${n}?t=${i}`);
300
- return H(a, e);
301
- }, yt = () => {
299
+ }, it = async (t) => {
300
+ const e = await At(t), s = await A(t), n = f(s, "salty.config.js"), i = Date.now(), { config: a } = await import(`${n}?t=${i}`);
301
+ return Z(a, e);
302
+ }, wt = () => {
302
303
  try {
303
304
  return process.env.NODE_ENV === "production";
304
305
  } catch {
305
306
  return !1;
306
307
  }
307
- }, Rt = async (t, e = yt(), s = !0) => {
308
+ }, Wt = async (t, e = wt(), s = !0) => {
308
309
  try {
309
310
  const n = Date.now();
310
- e ? Y.info("Generating CSS in production mode! 🔥") : Y.info("Generating CSS in development mode! 🚀");
311
- const i = [], a = [], c = await A(t), p = f(c, "index.css");
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
313
  s && (() => {
313
- v(c) && bt("rm -rf " + c), Z(c, { recursive: !0 }), Z(f(c, "css")), Z(f(c, "types")), Z(f(c, "js")), Z(f(c, "cache"));
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"));
314
315
  })();
315
316
  const o = {
316
317
  keyframes: [],
@@ -322,184 +323,183 @@ const Tt = {
322
323
  classNames: []
323
324
  };
324
325
  async function m(l) {
325
- const b = ["node_modules", "saltygen"], y = wt(l);
326
+ const S = ["node_modules", "saltygen"], y = jt(l);
326
327
  if (y.isDirectory()) {
327
- const w = St(l);
328
- if (b.some((S) => l.includes(S))) return;
329
- await Promise.all(w.map((S) => m(f(l, S))));
330
- } else if (y.isFile() && B(l)) {
331
- const d = await st(t, l, c);
332
- Object.entries(d).forEach(([S, h]) => {
333
- h.isKeyframes ? o.keyframes.push({
334
- value: h,
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,
335
336
  src: l,
336
- name: S
337
- }) : h.isMedia ? o.mediaQueries.push(h) : h.isGlobalDefine ? o.globalStyles.push(h) : h.isDefineVariables ? o.variables.push(h) : h.isDefineTemplates ? o.templates.push(h) : h.isClassName ? o.classNames.push({
338
- value: h.factory,
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,
339
340
  src: l,
340
- name: S
341
- }) : h.generator && o.components.push({
342
- value: h.generator,
341
+ name: C
342
+ }) : g.generator && o.components.push({
343
+ value: g.generator,
343
344
  src: l,
344
- name: S
345
+ name: C
345
346
  });
346
347
  });
347
348
  }
348
349
  }
349
- await m(t), await Vt(t, o);
350
- const g = await nt(t);
350
+ await m(t), await Jt(t, o);
351
+ const h = await it(t);
351
352
  for (const l of o.keyframes) {
352
- const { value: b } = l, y = `a_${b.animationName}.css`, w = `css/${y}`, d = f(c, w);
353
- i.push(y), k(d, b.css);
353
+ const { value: S } = l, y = `a_${S.animationName}.css`, $ = `css/${y}`, p = f(c, $);
354
+ i.push(y), k(p, S.css);
354
355
  }
355
- const u = {};
356
+ const d = {};
356
357
  for (const l of o.components) {
357
- const { value: b, name: y, src: w } = l, d = b._withBuildContext({
358
+ const { value: S, name: y, src: $ } = l, p = S._withBuildContext({
358
359
  name: y,
359
- config: g,
360
+ config: h,
360
361
  prod: e
361
362
  });
362
- a[d.priority] || (a[d.priority] = []), a[d.priority].push(d.cssFileName);
363
- const S = `css/${d.cssFileName}`, h = f(c, S);
364
- k(h, d.css), g.importStrategy === "component" && (u[w] ? u[w].push(d.cssFileName) : u[w] = [d.cssFileName]);
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]);
365
366
  }
366
367
  for (const l of o.classNames) {
367
- const { value: b, src: y, name: w } = l, d = b._withBuildContext({
368
- name: w,
368
+ const { value: S, src: y, name: $ } = l, p = S._withBuildContext({
369
+ name: $,
369
370
  prod: e
370
371
  });
371
- a[0].push(d.cssFileName);
372
- const S = `css/${d.cssFileName}`, h = f(c, S);
373
- k(h, d.css), g.importStrategy === "component" && (u[y] ? u[y].push(d.cssFileName) : u[y] = [d.cssFileName]);
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]);
374
375
  }
375
- g.importStrategy === "component" && Object.entries(u).forEach(([l, b]) => {
376
- const y = b.map((G) => `@import url('./${G}');`).join(`
377
- `), w = I(l, 6), d = K(l), S = R(d.name), h = f(c, `css/f_${S}-${w}.css`);
378
- k(h, y);
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);
379
380
  });
380
- const F = i.map((l) => `@import url('./css/${l}');`).join(`
381
+ const b = i.map((l) => `@import url('./css/${l}');`).join(`
381
382
  `);
382
- let j = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
383
+ let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
383
384
 
384
385
  ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
385
386
  try {
386
- return M(f(c, "css", l), "utf8").length > 0;
387
+ return V(f(c, "css", l), "utf8").length > 0;
387
388
  } catch {
388
389
  return !1;
389
390
  }
390
391
  }).map((l) => `@import url('./css/${l}');`).join(`
391
392
  `)}
392
- ${F}`;
393
- if (g.importStrategy !== "component") {
394
- const l = a.reduce((b, y, w) => {
395
- const d = y.reduce((L, D) => {
396
- var W;
397
- const x = f(c, "css", D), O = M(x, "utf8"), E = ((W = /.*-([^-]+)-\d+.css/.exec(D)) == null ? void 0 : W.at(1)) || I(x, 6);
398
- return L.includes(E) ? L : `${L}
399
- /*start:${E}*/
400
- ${O}
401
- /*end:${E}*/
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}*/
401
+ ${q}
402
+ /*end:${F}*/
402
403
  `;
403
- }, ""), S = `l_${w}.css`, h = f(c, "css", S), G = `@layer l${w} { ${d}
404
+ }, ""), C = `l_${$}.css`, g = f(c, "css", C), L = `@layer l${$} { ${p}
404
405
  }`;
405
- return k(h, G), `${b}
406
- @import url('./css/${S}');`;
406
+ return k(g, L), `${S}
407
+ @import url('./css/${C}');`;
407
408
  }, "");
408
- j += l;
409
+ x += l;
409
410
  }
410
- k(p, j);
411
- const $ = Date.now() - n, _ = $ < 200 ? "🔥" : $ < 500 ? "🚀" : $ < 1e3 ? "🎉" : $ < 2e3 ? "🚗" : $ < 5e3 ? "🤔" : "🥴";
412
- Y.info(`Generated CSS in ${$}ms! ${_}`);
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}`);
413
414
  } catch (n) {
414
415
  console.error(n);
415
416
  }
416
- }, Jt = async (t, e) => {
417
+ }, zt = async (t, e) => {
417
418
  try {
418
419
  const s = await A(t);
419
- if (B(e)) {
420
- const i = [], a = await nt(t), c = await st(t, e, s);
421
- if (Object.entries(c).forEach(([p, r]) => {
420
+ if (I(e)) {
421
+ const i = [], a = await it(t), c = await rt(t, e, s);
422
+ if (Object.entries(c).forEach(([u, r]) => {
422
423
  if (r.isKeyframes && r.css) {
423
- const F = `css/${`a_${r.animationName}.css`}`, N = f(s, F);
424
- k(N, r.css);
424
+ const b = `css/${`a_${r.animationName}.css`}`, D = f(s, b);
425
+ k(D, r.css);
425
426
  return;
426
427
  }
427
428
  if (r.isClassName) {
428
- console.log("found className value", r);
429
- const u = r.factory._withBuildContext({
430
- name: p
429
+ const d = r.factory._withBuildContext({
430
+ name: u
431
431
  });
432
- i[0].push(u.cssFileName);
433
- const F = `css/${u.cssFileName}`, N = f(s, F);
434
- k(N, u.css), console.log(N, u.css);
432
+ i[0].push(d.cssFileName);
433
+ const b = `css/${d.cssFileName}`, D = f(s, b);
434
+ k(D, d.css);
435
435
  }
436
436
  if (!r.generator) return;
437
437
  const o = r.generator._withBuildContext({
438
- name: p,
438
+ name: u,
439
439
  config: a
440
- }), m = `css/${o.cssFileName}`, g = f(s, m);
441
- k(g, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
442
- }), console.log(i), a.importStrategy !== "component")
443
- i.forEach((p, r) => {
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);
442
+ }), a.importStrategy !== "component")
443
+ i.forEach((u, r) => {
444
444
  const o = `l_${r}.css`, m = f(s, "css", o);
445
- let g = M(m, "utf8");
446
- p.forEach((u) => {
447
- var C;
448
- const F = f(s, "css", u), N = ((C = /.*-([^-]+)-\d+.css/.exec(u)) == null ? void 0 : C.at(1)) || I(F, 6);
449
- if (!g.includes(N)) {
450
- const j = M(F, "utf8"), P = `/*start:${N}*/
451
- ${j}
452
- /*end:${N}*/
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}*/
453
453
  `;
454
- g = `${g.replace(/\}$/, "")}
454
+ h = `${h.replace(/\}$/, "")}
455
455
  ${P}
456
456
  }`;
457
457
  }
458
- }), k(m, g);
458
+ }), k(m, h);
459
459
  });
460
460
  else {
461
- const p = i.flat().map((u) => `@import url('./${u}');`).join(`
462
- `), r = I(e, 6), o = K(e), m = R(o.name), g = f(s, `css/f_${m}-${r}.css`);
463
- k(g, p);
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);
464
464
  }
465
465
  }
466
466
  } catch (s) {
467
467
  console.error(s);
468
468
  }
469
- }, At = async (t, e, s = yt()) => {
469
+ }, Zt = async (t, e, s = wt()) => {
470
470
  try {
471
471
  const n = await A(t);
472
- if (B(e)) {
473
- const a = M(e, "utf8");
474
- a.replace(/^(?!export\s)const\s.*/gm, (m) => `export ${m}`) !== a && await Ct(e, a);
475
- const p = await nt(t), r = await st(t, e, n);
472
+ if (I(e)) {
473
+ 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);
476
476
  let o = a;
477
- if (Object.entries(r).forEach(([m, g]) => {
478
- var S;
479
- if (g.isKeyframes || !g.generator) return;
480
- const u = g.generator._withBuildContext({
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
481
  name: m,
482
- config: p,
482
+ config: u,
483
483
  prod: s
484
- }), F = new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
485
- if (!F) return console.error("Could not find the original declaration");
486
- const N = (S = F.at(1)) == null ? void 0 : S.trim(), T = new RegExp(`\\s${m}[=\\s]+styled\\(`, "g").exec(o);
487
- if (!T) return console.error("Could not find the original declaration");
488
- const { index: C } = T;
489
- let j = !1;
490
- const P = setTimeout(() => j = !0, 5e3);
491
- let $ = 0, _ = !1, l = 0;
492
- for (; !_ && !j; ) {
493
- const h = o[C + $];
494
- h === "(" && l++, h === ")" && l--, l === 0 && h === ")" && (_ = !0), $ > o.length && (j = !0), $++;
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);
487
+ 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++;
495
495
  }
496
- if (!j) clearTimeout(P);
496
+ if (!x) clearTimeout(P);
497
497
  else throw new Error("Failed to find the end of the styled call and timed out");
498
- const b = C + $, y = o.slice(C, b), w = o, d = ` ${m} = styled(${N}, "${u.classNames}", ${JSON.stringify(u.props)});`;
499
- o = o.replace(y, d), w === o && console.error("Minimize file failed to change content", { name: m, tagName: N });
500
- }), p.importStrategy === "component") {
501
- const m = I(e, 6), g = K(e);
502
- o = `import '../../saltygen/css/${`f_${R(g.name)}-${m}.css`}';
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`}';
503
503
  ${o}`;
504
504
  }
505
505
  return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
@@ -507,29 +507,29 @@ ${o}`;
507
507
  } catch (n) {
508
508
  console.error("Error in minimizeFile:", n);
509
509
  }
510
- }, it = async (t) => {
510
+ }, lt = async (t) => {
511
511
  if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
512
512
  if (t.includes("salty.config")) return !0;
513
- if (!B(t)) return !1;
514
- const n = await tt(t, "utf-8");
513
+ if (!I(t)) return !1;
514
+ const n = await nt(t, "utf-8");
515
515
  return !!/.+define[A-Z]\w+/.test(n);
516
- }, Bt = (t) => ({
516
+ }, Kt = (t) => ({
517
517
  name: "stylegen",
518
- buildStart: () => Rt(t),
518
+ buildStart: () => Wt(t),
519
519
  load: async (e) => {
520
- if (B(e))
521
- return await At(t, e);
520
+ if (I(e))
521
+ return await Zt(t, e);
522
522
  },
523
523
  handleHotUpdate: async ({ file: e, server: s }) => {
524
- await it(e) && await s.restart();
524
+ await lt(e) && await s.restart();
525
525
  },
526
526
  watchChange: {
527
527
  handler: async (e) => {
528
- B(e) && (await it(e) || await Jt(t, e));
528
+ I(e) && (await lt(e) || await zt(t, e));
529
529
  }
530
530
  }
531
531
  });
532
532
  export {
533
- Bt as default,
534
- Bt as saltyPlugin
533
+ Kt as default,
534
+ Kt as saltyPlugin
535
535
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.187",
3
+ "version": "0.0.1-alpha.188",
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.187"
37
+ "@salty-css/core": "^0.0.1-alpha.188"
38
38
  }
39
39
  }