@salty-css/vite 0.0.1-alpha.209 → 0.0.1-alpha.210
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.
- package/index.cjs +4 -4
- package/index.js +23 -23
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),l=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const gt=Dt(kt),pt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=pt(n%52)+s;return s=pt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Et=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},v=(t,e=5)=>{const s=Et(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function V(t){return t?typeof t!="string"?V(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Tt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,g=>{const{value:C,css:f}=a(g);return f&&n.push(f),C})}),{transformed:s,additionalCss:n}},ht=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${V(o[1].replaceAll(".","-"))})`)},Mt=ht(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,At=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:At.some(e=>t.startsWith(e))?`-${V(t)}`:V(t),Y=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(t).map(async([m,i])=>{const y=m.trim(),k=Jt(y),P=(_,T=";")=>`${k}:${_}${T}`;if(typeof i=="function"&&(i=i({scope:e,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return P(i.toString());if(y==="defaultVariants")return;if(y==="variants"){const j=Object.entries(i);for(const[
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),l=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const gt=Dt(kt),pt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=pt(n%52)+s;return s=pt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Et=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},v=(t,e=5)=>{const s=Et(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function V(t){return t?typeof t!="string"?V(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const Tt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,g=>{const{value:C,css:f}=a(g);return f&&n.push(f),C})}),{transformed:s,additionalCss:n}},ht=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${V(o[1].replaceAll(".","-"))})`)},Mt=ht(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,At=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:At.some(e=>t.startsWith(e))?`-${V(t)}`:V(t),Y=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(t).map(async([m,i])=>{const y=m.trim(),k=Jt(y),P=(_,T=";")=>`${k}:${_}${T}`;if(typeof i=="function"&&(i=i({scope:e,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return P(i.toString());if(y==="defaultVariants")return;if(y==="variants"){const j=Object.entries(i);for(const[O,c]of j){if(!c)return;const h=Object.entries(c);for(const[b,u]of h){if(!u)return;const S=`${e}.${O}-${b}`;(await Y(u,S,s)).forEach(M=>o.add(M))}}return}if(y==="compoundVariants"){for(const j of i){const{css:O,...c}=j,h=Object.entries(c).reduce((u,[S,N])=>`${u}.${S}-${N}`,e);(await Y(O,h,s)).forEach(u=>o.add(u))}return}if(y.startsWith("@")){const j=y,O=await G(i,e,s),c=`${j} { ${O} }`;o.add(c);return}const _=m.includes("&")?y.replace("&",e):y.startsWith(":")?`${e}${y}`:`${e} ${y}`;(await Y(i,_,s)).forEach(j=>o.add(j));return}if(typeof i=="number"){const _=Vt(k,i);return P(_)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${k}`);return P(i)}),{modifiers:g}={},C=[ht(),Tt(g)],p=(await Promise.all(a).then(m=>Promise.all(m.map(i=>C.reduce(async(y,k)=>{const P=await y;if(!P)return P;const R=await k(P);if(!R)return P;const{transformed:_,additionalCss:T}=R;let j="";if(T)for(const O of T)j+=await G(O,"");return`${j}${_}`},Promise.resolve(i)))))).filter(m=>m!==void 0).join(`
|
2
2
|
`);if(!p.trim())return Array.from(o);const w=e?`${e} {
|
3
3
|
${p}
|
4
4
|
}`:p;return o.has(w)?Array.from(o):[w,...o]},G=async(t,e,s,n=!1)=>(await Y(t,e,s,n)).join(`
|
5
5
|
`),wt=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),g=await wt(r,[...e,a]);s.push(g)}else n[o]=r;if(Object.keys(n).length){const o=e.map(V).join("-"),r="t_"+v(o,4),a=await G(n,`.${o}, .${r}`);s.push(a)}return s.join(`
|
6
|
-
`)},vt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=$t(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},$t=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(e)}),[...s]):[],bt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return d.existsSync(e)?e:bt(l.join(t,".."))},zt=async t=>{const e=bt(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await zt(t);if(e)return e.type};let I;const St=async t=>{if(I)return I;const e=await Wt(t);return e==="module"?I="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function jt(t){return t?typeof t!="string"?jt(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?".":"")+e.toLowerCase()):""}const It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),J={externalModules:[],rcFile:void 0,destDir:void 0},Ft=t=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},z=async t=>{if(J.destDir)return J.destDir;const e=await at(t),s=l.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return J.destDir=s,s},Ct=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ct,...t].join("|")})\\.`),q=(t,e=[])=>qt(e).test(t),Pt=async t=>{if(J.rcFile)return J.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=l.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Pt(l.join(t,".."))},at=async t=>{var n,o;const e=await Pt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await z(t),n=l.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),r=await St(t),a=Ft(n);await gt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const g=Date.now(),{config:C}=await import(`${o}?t=${g}`);return C},Lt=async(t,e)=>{var ft,ut;const s=await z(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:x,outputFilePath:A}=await et(t,F,s);Object.entries(x).forEach(([
|
6
|
+
`)},vt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=$t(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},$t=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(e)}),[...s]):[],bt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return d.existsSync(e)?e:bt(l.join(t,".."))},zt=async t=>{const e=bt(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await zt(t);if(e)return e.type};let I;const St=async t=>{if(I)return I;const e=await Wt(t);return e==="module"?I="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function jt(t){return t?typeof t!="string"?jt(String(t)):t.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?".":"")+e.toLowerCase()):""}const It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),J={externalModules:[],rcFile:void 0,destDir:void 0},Ft=t=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},z=async t=>{if(J.destDir)return J.destDir;const e=await at(t),s=l.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return J.destDir=s,s},Ct=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ct,...t].join("|")})\\.`),q=(t,e=[])=>qt(e).test(t),Pt=async t=>{if(J.rcFile)return J.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=l.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Pt(l.join(t,".."))},at=async t=>{var n,o;const e=await Pt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await z(t),n=l.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),r=await St(t),a=Ft(n);await gt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const g=Date.now(),{config:C}=await import(`${o}?t=${g}`);return C},Lt=async(t,e)=>{var ft,ut;const s=await z(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:x,outputFilePath:A}=await et(t,F,s);Object.entries(x).forEach(([D,E])=>{E.isMedia?n.mediaQueries.push([D,E]):E.isGlobalDefine?n.globalStyles.push(E):E.isDefineVariables?n.variables.push(E):E.isDefineTemplates&&n.templates.push(E._setPath(`${D};;${A}`))})}));const o=await Ht(t),r={...o},a=new Set,g=(F,x=[])=>F?Object.entries(F).flatMap(([A,D])=>{if(!D)return;if(typeof D=="object")return g(D,[...x,A]);const E=jt(A),nt=V(A),ot=[...x,E].join(".");a.add(`"${ot}"`);const X=[...x.map(V),nt].join("-"),dt=Mt(D);return dt?`--${X}: ${dt.transformed};`:`--${X}: ${D};`}):[],C=F=>F?Object.entries(F).flatMap(([x,A])=>{const D=g(A);return x==="base"?D.join(""):`${x} { ${D.join("")} }`}):[],f=F=>F?Object.entries(F).flatMap(([x,A])=>Object.entries(A).flatMap(([D,E])=>{const nt=g(E,[x]),ot=`.${x}-${D}, [data-${x}="${D}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],p=F=>({...F,responsive:void 0,conditional:void 0}),w=F=>n.variables.map(x=>F==="static"?p(x._current):x._current[F]),$=Z(p(o.variables),w("static")),m=g($),i=Z((ft=o.variables)==null?void 0:ft.responsive,w("responsive")),y=C(i),k=Z((ut=o.variables)==null?void 0:ut.conditional,w("conditional")),P=f(k),R=l.join(s,"css/_variables.css"),_=`:root { ${m.join("")} ${y.join("")} } ${P.join("")}`;d.writeFileSync(R,_),r.staticVariables=$;const T=l.join(s,"css/_global.css"),j=Z(o.global,n.globalStyles),O=await G(j,"");d.writeFileSync(T,`@layer global { ${O} }`);const c=l.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(b,"");d.writeFileSync(c,`@layer reset { ${u} }`);const S=l.join(s,"css/_templates.css"),N=Z(o.templates,n.templates),M=await wt(N),H=vt(N);d.writeFileSync(S,`@layer templates { ${M} }`),r.templates=N;const L=Zt(n.templates);r.templatePaths=Object.fromEntries(Object.entries(L).map(([F,x])=>[F,x._path]));const{mediaQueries:W}=n;r.mediaQueries=Object.fromEntries(W.map(([F,x])=>[`@${F}`,x]));const K=W.map(([F])=>`'@${F}'`).join(" | "),st=l.join(s,"types/css-tokens.d.ts"),Q=`
|
7
7
|
// Variable types
|
8
8
|
type VariableTokens = ${[...a].join("|")};
|
9
9
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -32,11 +32,11 @@ ${st}
|
|
32
32
|
/*end:${U}*/
|
33
33
|
`},""),N=`l_${u}.css`,M=l.join(a,"css",N),H=`@layer l${u} { ${S}
|
34
34
|
}`;return d.writeFileSync(M,H),`${h}
|
35
|
-
@import url('./css/${N}');`},"");_+=c}d.writeFileSync(g,_);const j=Date.now()-n,
|
35
|
+
@import url('./css/${N}');`},"");_+=c}d.writeFileSync(g,_);const j=Date.now()-n,O=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";it.info(`Generated CSS in ${j}ms! ${O}`)}catch(n){console.error(n)}},Ut=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=[],a=await ct(t),{contents:g}=await et(t,e,n);for(const[C,f]of Object.entries(g)){if(f.isKeyframes&&f.css){const y=`css/${`a_${f.animationName}.css`}`,k=l.join(n,y);d.writeFileSync(k,await f.css);return}if(f.isClassName){const i=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),y=await i.css;if(!y)continue;r[0].push(i.cssFileName);const k=`css/${i.cssFileName}`,P=l.join(n,k);d.writeFileSync(P,y)}if(!f.generator)return;const p=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),w=await p.css;if(!w)continue;const $=`css/${p.cssFileName}`,m=l.join(n,$);d.writeFileSync(m,w),r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName)}if(a.importStrategy!=="component")r.forEach((C,f)=>{const p=`l_${f}.css`,w=l.join(n,"css",p);let $=d.readFileSync(w,"utf8");C.forEach(m=>{var P;const i=l.join(n,"css",m),y=((P=/.*-([^-]+)-\d+.css/.exec(m))==null?void 0:P.at(1))||v(i,6);if(!$.includes(y)){const R=d.readFileSync(i,"utf8"),_=`/*start:${y}-${m}*/
|
36
36
|
${R}
|
37
37
|
/*end:${y}*/
|
38
38
|
`;$=`${$.replace(/\}$/,"")}
|
39
39
|
${_}
|
40
40
|
}`}}),d.writeFileSync(w,$)});else{const C=r.flat().map(m=>`@import url('./${m}');`).join(`
|
41
|
-
`),f=v(e,6),p=l.parse(e),w=V(p.name),$=l.join(n,`css/f_${w}-${f}.css`);d.writeFileSync($,C||"/* Empty file */")}}}catch(n){console.error(n)}},Qt=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=d.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await tt.writeFile(e,r);const g=await ct(t),{contents:C}=await et(t,e,n);let f=r;if(Object.entries(C).forEach(([p,w])=>{var u;if(w.isKeyframes||!w.generator)return;const $=w.generator._withBuildContext({callerName:p,isProduction:s,config:g}),m=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!m)return console.error("Could not find the original declaration");const i=(u=m.at(1))==null?void 0:u.trim(),y=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(f);if(!y)return console.error("Could not find the original declaration");const{index:k}=y;let P=!1;const R=setTimeout(()=>P=!0,5e3);let _=0,T=!1,j=0;for(;!T&&!P;){const S=f[k+_];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(T=!0),_>f.length&&(P=!0),_++}if(!P)clearTimeout(R);else throw new Error("Failed to find the end of the styled call and timed out");const
|
41
|
+
`),f=v(e,6),p=l.parse(e),w=V(p.name),$=l.join(n,`css/f_${w}-${f}.css`);d.writeFileSync($,C||"/* Empty file */")}}}catch(n){console.error(n)}},Qt=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=d.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await tt.writeFile(e,r);const g=await ct(t),{contents:C}=await et(t,e,n);let f=r;if(Object.entries(C).forEach(([p,w])=>{var u;if(w.isKeyframes||!w.generator)return;const $=w.generator._withBuildContext({callerName:p,isProduction:s,config:g}),m=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!m)return console.error("Could not find the original declaration");const i=(u=m.at(1))==null?void 0:u.trim(),y=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(f);if(!y)return console.error("Could not find the original declaration");const{index:k}=y;let P=!1;const R=setTimeout(()=>P=!0,5e3);let _=0,T=!1,j=0;for(;!T&&!P;){const S=f[k+_];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(T=!0),_>f.length&&(P=!0),_++}if(!P)clearTimeout(R);else throw new Error("Failed to find the end of the styled call and timed out");const O=k+_,c=f.slice(k,O),h=f,b=` ${p} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;f=f.replace(c,b),h===f&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),g.importStrategy==="component"){const p=v(e,6),w=l.parse(e);f=`import '../../saltygen/css/${`f_${V(w.name)}-${p}.css`}';
|
42
42
|
${f}`}return f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(n){console.error("Error in minimizeFile:",n)}},mt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!q(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},xt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(q(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await mt(e)&&await s.restart()},watchChange:{handler:async e=>{q(e)&&(await mt(e)||await Ut(t,e))}}});exports.default=xt;exports.saltyPlugin=xt;
|
package/index.js
CHANGED
@@ -61,12 +61,12 @@ const Jt = (t) => (e) => {
|
|
61
61
|
if (p === "defaultVariants") return;
|
62
62
|
if (p === "variants") {
|
63
63
|
const C = Object.entries(i);
|
64
|
-
for (const [
|
64
|
+
for (const [E, c] of C) {
|
65
65
|
if (!c) return;
|
66
66
|
const y = Object.entries(c);
|
67
67
|
for (const [w, f] of y) {
|
68
68
|
if (!f) return;
|
69
|
-
const b = `${e}.${
|
69
|
+
const b = `${e}.${E}-${w}`;
|
70
70
|
(await tt(f, b, s)).forEach((V) => o.add(V));
|
71
71
|
}
|
72
72
|
}
|
@@ -74,13 +74,13 @@ const Jt = (t) => (e) => {
|
|
74
74
|
}
|
75
75
|
if (p === "compoundVariants") {
|
76
76
|
for (const C of i) {
|
77
|
-
const { css:
|
78
|
-
(await tt(
|
77
|
+
const { css: E, ...c } = C, y = Object.entries(c).reduce((f, [b, N]) => `${f}.${b}-${N}`, e);
|
78
|
+
(await tt(E, y, s)).forEach((f) => o.add(f));
|
79
79
|
}
|
80
80
|
return;
|
81
81
|
}
|
82
82
|
if (p.startsWith("@")) {
|
83
|
-
const C = p,
|
83
|
+
const C = p, E = await Q(i, e, s), c = `${C} { ${E} }`;
|
84
84
|
o.add(c);
|
85
85
|
return;
|
86
86
|
}
|
@@ -105,8 +105,8 @@ const Jt = (t) => (e) => {
|
|
105
105
|
const { transformed: k, additionalCss: O } = R;
|
106
106
|
let C = "";
|
107
107
|
if (O)
|
108
|
-
for (const
|
109
|
-
C += await Q(
|
108
|
+
for (const E of O)
|
109
|
+
C += await Q(E, "");
|
110
110
|
return `${C}${k}`;
|
111
111
|
}, Promise.resolve(i)))
|
112
112
|
))).filter((m) => m !== void 0).join(`
|
@@ -255,28 +255,28 @@ const Kt = {
|
|
255
255
|
await Promise.all(
|
256
256
|
[...e].map(async (S) => {
|
257
257
|
const { contents: x, outputFilePath: J } = await st(t, S, s);
|
258
|
-
Object.entries(x).forEach(([
|
259
|
-
T.isMedia ? n.mediaQueries.push([
|
258
|
+
Object.entries(x).forEach(([_, T]) => {
|
259
|
+
T.isMedia ? n.mediaQueries.push([_, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(`${_};;${J}`));
|
260
260
|
});
|
261
261
|
})
|
262
262
|
);
|
263
|
-
const o = await Ut(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (S, x = []) => S ? Object.entries(S).flatMap(([J,
|
264
|
-
if (!
|
265
|
-
if (typeof
|
263
|
+
const o = await Ut(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (S, x = []) => S ? Object.entries(S).flatMap(([J, _]) => {
|
264
|
+
if (!_) return;
|
265
|
+
if (typeof _ == "object") return h(_, [...x, J]);
|
266
266
|
const T = xt(J), ot = A(J), rt = [...x, T].join(".");
|
267
267
|
a.add(`"${rt}"`);
|
268
|
-
const Y = [...x.map(A), ot].join("-"), ht = Wt(
|
269
|
-
return ht ? `--${Y}: ${ht.transformed};` : `--${Y}: ${
|
268
|
+
const Y = [...x.map(A), ot].join("-"), ht = Wt(_);
|
269
|
+
return ht ? `--${Y}: ${ht.transformed};` : `--${Y}: ${_};`;
|
270
270
|
}) : [], j = (S) => S ? Object.entries(S).flatMap(([x, J]) => {
|
271
|
-
const
|
272
|
-
return x === "base" ?
|
273
|
-
}) : [], l = (S) => S ? Object.entries(S).flatMap(([x, J]) => Object.entries(J).flatMap(([
|
274
|
-
const ot = h(T, [x]), rt = `.${x}-${
|
271
|
+
const _ = h(J);
|
272
|
+
return x === "base" ? _.join("") : `${x} { ${_.join("")} }`;
|
273
|
+
}) : [], l = (S) => S ? Object.entries(S).flatMap(([x, J]) => Object.entries(J).flatMap(([_, T]) => {
|
274
|
+
const ot = h(T, [x]), rt = `.${x}-${_}, [data-${x}="${_}"]`, Y = ot.join("");
|
275
275
|
return `${rt} { ${Y} }`;
|
276
276
|
})) : [], d = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), g = (S) => n.variables.map((x) => S === "static" ? d(x._current) : x._current[S]), $ = B(d(o.variables), g("static")), m = h($), i = B((pt = o.variables) == null ? void 0 : pt.responsive, g("responsive")), p = j(i), P = B((mt = o.variables) == null ? void 0 : mt.conditional, g("conditional")), F = l(P), R = u(s, "css/_variables.css"), k = `:root { ${m.join("")} ${p.join("")} } ${F.join("")}`;
|
277
277
|
D(R, k), r.staticVariables = $;
|
278
|
-
const O = u(s, "css/_global.css"), C = B(o.global, n.globalStyles),
|
279
|
-
D(O, `@layer global { ${
|
278
|
+
const O = u(s, "css/_global.css"), C = B(o.global, n.globalStyles), E = await Q(C, "");
|
279
|
+
D(O, `@layer global { ${E} }`);
|
280
280
|
const c = u(s, "css/_reset.css"), w = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, f = await Q(w, "");
|
281
281
|
D(c, `@layer reset { ${f} }`);
|
282
282
|
const b = u(s, "css/_templates.css"), N = B(o.templates, n.templates), V = await Ct(N), K = It(N);
|
@@ -490,8 +490,8 @@ ${nt}
|
|
490
490
|
k += c;
|
491
491
|
}
|
492
492
|
D(h, k);
|
493
|
-
const C = Date.now() - n,
|
494
|
-
at.info(`Generated CSS in ${C}ms! ${
|
493
|
+
const C = Date.now() - n, E = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
|
494
|
+
at.info(`Generated CSS in ${C}ms! ${E}`);
|
495
495
|
} catch (n) {
|
496
496
|
console.error(n);
|
497
497
|
}
|
@@ -583,7 +583,7 @@ ${k}
|
|
583
583
|
}
|
584
584
|
if (!F) clearTimeout(R);
|
585
585
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
586
|
-
const
|
586
|
+
const E = P + k, c = l.slice(P, E), y = l, w = ` ${d} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;
|
587
587
|
l = l.replace(c, w), y === l && console.error("Minimize file failed to change content", { name: d, tagName: i });
|
588
588
|
}), h.importStrategy === "component") {
|
589
589
|
const d = z(e, 6), g = et(e);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/vite",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.210",
|
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.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.210"
|
38
38
|
}
|
39
39
|
}
|