@salty-css/vite 0.0.1-alpha.178 → 0.0.1-alpha.179

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