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