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