@salty-css/webpack 0.0.1-alpha.216 → 0.0.1-alpha.218
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-C1yuKgNW.cjs → index-B-t5k40D.cjs} +12 -12
- package/{index-DblUSN58.js → index-C47SclTa.js} +173 -173
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/loader.cjs +1 -1
- package/loader.js +1 -1
- package/package.json +2 -2
@@ -1,9 +1,9 @@
|
|
1
|
-
"use strict";var kt=Object.defineProperty;var Dt=(e,t,s)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var Y=(e,t,s)=>Dt(e,typeof t!="symbol"?t+"":t,s);const Tt=require("esbuild"),Et=require("child_process"),
|
1
|
+
"use strict";var kt=Object.defineProperty;var Dt=(e,t,s)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var Y=(e,t,s)=>Dt(e,typeof t!="symbol"?t+"":t,s);const Tt=require("esbuild"),Et=require("child_process"),f=require("path"),d=require("fs"),at=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Ot(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ht=Ot(Tt),mt=e=>String.fromCharCode(e+(e>25?39:97)),Vt=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=mt(n%52)+s;return s=mt(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Mt=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},J=(e,t=5)=>{const s=Mt(5381,JSON.stringify(e))>>>0;return Vt(s,t)};function R(e){return e?typeof e!="string"?R(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const Rt=e=>t=>{if(typeof t!="string"||!e)return;let s=t;const n=[];return Object.values(e).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,w=>{const{value:$,css:u}=a(w);return u&&n.push(u),$})}),{transformed:s,additionalCss:n}},gt=e=>t=>typeof t!="string"||!/\{[^{}]+\}/g.test(t)?void 0:{transformed:t.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${R(o[1].replaceAll(".","-"))})`)},zt=gt(),At=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Jt=(e,t,s)=>At.some(o=>typeof o=="string"?o===e:o.test(e))?`${t}px`:`${t}`,Wt=["Webkit","Moz","ms","O"],vt=e=>e.startsWith("-")?e:Wt.some(t=>e.startsWith(t))?`-${R(e)}`:R(e),tt=async(e,t="",s,n=!1)=>{if(!e)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(e).map(async([y,i])=>{const m=y.trim(),N=vt(m),P=(_,V=";")=>`${N}:${_}${V}`;if(typeof i=="function"&&(i=i({scope:t,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return P(i.toString());if(m==="defaultVariants")return;if(m==="variants"){const S=Object.entries(i);for(const[T,l]of S){if(!l)return;const h=Object.entries(l);for(const[F,c]of h){if(!c)return;const j=`${t}.${T}-${F}`;(await tt(c,j,s)).forEach(E=>o.add(E))}}return}if(m==="compoundVariants"){for(const S of i){const{css:T,...l}=S,h=Object.entries(l).reduce((c,[j,k])=>`${c}.${j}-${k}`,t);(await tt(T,h,s)).forEach(c=>o.add(c))}return}if(m.startsWith("@")){const S=m,T=await G(i,t,s),l=`${S} { ${T} }`;o.add(l);return}const _=y.includes("&")?m.replace("&",t):m.startsWith(":")?`${t}${m}`:`${t} ${m}`;(await tt(i,_,s)).forEach(S=>o.add(S));return}if(typeof i=="number"){const _=Jt(N,i);return P(_)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${N}`);return P(i)}),{modifiers:w}={},$=[gt(),Rt(w)],p=(await Promise.all(a).then(y=>Promise.all(y.map(i=>$.reduce(async(m,N)=>{const P=await m;if(!P)return P;const M=await N(P);if(!M)return P;const{transformed:_,additionalCss:V}=M;let S="";if(V)for(const T of V)S+=await G(T,"");return`${S}${_}`},Promise.resolve(i)))))).filter(y=>y!==void 0).join(`
|
2
2
|
`);if(!p.trim())return Array.from(o);const b=t?`${t} {
|
3
3
|
${p}
|
4
4
|
}`:p;return o.has(b)?Array.from(o):[b,...o]},G=async(e,t,s,n=!1)=>(await tt(e,t,s,n)).join(`
|
5
|
-
`),wt=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,r]of Object.entries(e))if(typeof r!="function")if(r&&typeof r=="object"){const
|
6
|
-
`)},It=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=$t(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},$t=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(t)}),[...s]):[],bt=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=
|
5
|
+
`),wt=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,r]of Object.entries(e))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),w=await wt(r,[...t,a]);s.push(w)}else n[o]=r;if(Object.keys(n).length){const o=t.map(R).join("-"),r="t_"+J(o,4),a=await G(n,`.${o}, .${r}`);s.push(a)}return s.join(`
|
6
|
+
`)},It=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=$t(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},$t=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(t)}),[...s]):[],bt=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=f.join(e,"package.json");return d.existsSync(t)?t:bt(f.join(e,".."))},Zt=async e=>{const t=bt(e);return await at.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},qt=async e=>{const t=await Zt(e);if(t)return t.type};let v;const jt=async e=>{if(v)return v;const t=await qt(e);return t==="module"?v="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index-B-t5k40D.cjs",document.baseURI).href).endsWith(".cjs"))&&(v="cjs"),v||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function St(e){return e?typeof e!="string"?St(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Ht={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},I=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),Lt=(...e)=>e.flat().reduce((t,s)=>({...t,...s._children}),{});class Bt{constructor(t){Y(this,"_path");this.params=t}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(t){return this._path=t,this}}class Gt{constructor(t){Y(this,"_path");Y(this,"templates",[]);this.params=t,Object.entries(t).forEach(([s,n])=>{this.templates.push(new Bt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(t=>[t.params.name,t]))}get isDefineTemplates(){return!0}_setPath(t){return this._path=t,this.templates.forEach(s=>s._setPath(t)),this}}const Kt=e=>new Gt(e),A={externalModules:[],rcFile:void 0,destDir:void 0},Ft=e=>{if(A.externalModules.length>0)return A.externalModules;const s=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return A.externalModules=n,n},W=async e=>{if(A.destDir)return A.destDir;const t=await ct(e),s=f.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return A.destDir=s,s},Ct=["salty","css","styles","styled"],Pt=(e=[])=>new RegExp(`\\.(${[...Ct,...e].join("|")})\\.`),et=(e,t=[])=>Pt(t).test(e),xt=async e=>{if(A.rcFile)return A.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=f.join(e,".saltyrc.json"),s=await at.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(A.rcFile=s,s):xt(f.join(e,".."))},ct=async e=>{var n,o;const t=await xt(e),s=(n=t.projects)==null?void 0:n.find(r=>e.endsWith(r.dir||""));return s||((o=t.projects)==null?void 0:o.find(r=>r.dir===t.defaultProject))},Qt=async e=>{const t=await ct(e),s=await W(e),n=f.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=f.join(s,"salty.config.js"),r=await jt(e),a=Ft(n);await ht.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const w=Date.now(),{config:$}=await import(`${o}?t=${w}`);return{config:$,path:o}},Ut=async(e,t)=>{var ut,dt;const s=await W(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async C=>{const{contents:x,outputFilePath:z}=await st(e,C,s);Object.entries(x).forEach(([D,O])=>{O.isMedia?n.mediaQueries.push([D,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(`${D};;${z}`))})}));const{config:o,path:r}=await Qt(e),a={...o},w=new Set,$=(C,x=[])=>C?Object.entries(C).flatMap(([z,D])=>{if(!D)return;if(typeof D=="object")return $(D,[...x,z]);const O=St(z),nt=R(z),ot=[...x,O].join(".");w.add(`"${ot}"`);const X=[...x.map(R),nt].join("-"),pt=zt(D);return pt?`--${X}: ${pt.transformed};`:`--${X}: ${D};`}):[],u=C=>C?Object.entries(C).flatMap(([x,z])=>{const D=$(z);return x==="base"?D.join(""):`${x} { ${D.join("")} }`}):[],p=C=>C?Object.entries(C).flatMap(([x,z])=>Object.entries(z).flatMap(([D,O])=>{const nt=$(O,[x]),ot=`.${x}-${D}, [data-${x}="${D}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],b=C=>({...C,responsive:void 0,conditional:void 0}),g=C=>n.variables.map(x=>C==="static"?b(x._current):x._current[C]),y=I(b(o.variables),g("static")),i=$(y),m=I((ut=o.variables)==null?void 0:ut.responsive,g("responsive")),N=u(m),P=I((dt=o.variables)==null?void 0:dt.conditional,g("conditional")),M=p(P),_=f.join(s,"css/_variables.css"),V=`:root { ${i.join("")} ${N.join("")} } ${M.join("")}`;d.writeFileSync(_,V),a.staticVariables=y;const S=f.join(s,"css/_global.css"),T=I(o.global,n.globalStyles),l=await G(T,"");d.writeFileSync(S,`@layer global { ${l} }`);const h=f.join(s,"css/_reset.css"),c=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Ht,j=await G(c,"");d.writeFileSync(h,`@layer reset { ${j} }`);const k=f.join(s,"css/_templates.css"),E=I(o.templates,n.templates),Z=await wt(E),q=It(E);d.writeFileSync(k,`@layer templates { ${Z} }`),a.templates=E;const H=o.templates?[Kt(o.templates)._setPath(`config;;${r}`)]:[],K=Lt(n.templates,H);a.templatePaths=Object.fromEntries(Object.entries(K).map(([C,x])=>[C,x._path]));const{mediaQueries:Q}=n;a.mediaQueries=Object.fromEntries(Q.map(([C,x])=>[`@${C}`,x]));const L=Q.map(([C])=>`'@${C}'`).join(" | "),U=f.join(s,"types/css-tokens.d.ts"),Nt=`
|
7
7
|
// Variable types
|
8
8
|
type VariableTokens = ${[...w].join("|")};
|
9
9
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -16,27 +16,27 @@
|
|
16
16
|
|
17
17
|
// Media query types
|
18
18
|
type MediaQueryKeys = ${L||"''"};
|
19
|
-
`;d.writeFileSync(U,Nt);const _t=
|
19
|
+
`;d.writeFileSync(U,Nt);const _t=f.join(s,"cache/config-cache.json");d.writeFileSync(_t,JSON.stringify(a,null,2))},yt=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const a=o.exec(e);if(a){const w=a.at(1);if(Ct.some(u=>w==null?void 0:w.includes(u)))return t}return"styled('div',"}),Xt=(e,t)=>{try{const s=d.readFileSync(f.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
20
|
|
21
21
|
${e}`:`globalThis.saltyConfig = {};
|
22
22
|
|
23
|
-
${e}`}catch{return e}},st=async(e,t,s)=>{const n=J(t),o=
|
24
|
-
`),
|
23
|
+
${e}`}catch{return e}},st=async(e,t,s)=>{const n=J(t),o=f.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=f.parse(t);let a=d.readFileSync(t,"utf8");a=yt(a),a=Xt(a,e);const w=f.join(s,"js",n+".js"),$=await ct(e),u=f.join(e,($==null?void 0:$.configDir)||"","salty.config.ts"),p=Ft(u),b=await jt(e);await ht.build({stdin:{contents:a,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:w,format:b,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:i=>{i.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},m=>{const N=d.readFileSync(m.path,"utf8");return{contents:yt(N),loader:"ts"}})}}]});const g=Date.now();return{contents:await import(`${w}?t=${g}`),outputFilePath:w}},Yt=async e=>{const t=await W(e),s=f.join(t,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},lt=async e=>{const t=await Yt(e),s=await W(e),n=f.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return I(r,t)},ft=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},te=async(e,t=ft(),s=!0)=>{try{const n=Date.now();t?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],r=[],a=await W(e),w=f.join(a,"index.css");s&&(()=>{d.existsSync(a)&&Et.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(f.join(a,"css")),d.mkdirSync(f.join(a,"types")),d.mkdirSync(f.join(a,"js")),d.mkdirSync(f.join(a,"cache"))})();const u=new Set,p=new Set;async function b(l){const h=["node_modules","saltygen"],F=d.statSync(l);if(F.isDirectory()){const c=d.readdirSync(l);if(h.some(k=>l.includes(k)))return;await Promise.all(c.map(k=>b(f.join(l,k))))}else if(F.isFile()&&et(l)){u.add(l);const j=d.readFileSync(l,"utf8");/define[\w\d]+\(/.test(j)&&p.add(l)}}await b(e),await Ut(e,p);const g={keyframes:[],components:[],classNames:[]};await Promise.all([...u].map(async l=>{const{contents:h}=await st(e,l,a);Object.entries(h).forEach(([F,c])=>{c.isKeyframes?g.keyframes.push({value:c,src:l,name:F}):c.isClassName?g.classNames.push({...c,src:l,name:F}):c.generator&&g.components.push({...c,src:l,name:F})})}));const y=await lt(e);for(const l of g.keyframes){const{value:h}=l,F=`a_${h.animationName}.css`,c=`css/${F}`,j=f.join(a,c);o.push(F),d.writeFileSync(j,h.css)}const i={};for(const l of g.components){const{src:h,name:F}=l;i[h]||(i[h]=[]);const c=l.generator._withBuildContext({callerName:F,isProduction:t,config:y});r[c.priority]||(r[c.priority]=[]);const j=await c.css;if(!j)continue;r[c.priority].push(c.cssFileName);const k=`css/${c.cssFileName}`,E=f.join(a,k);d.writeFileSync(E,j),y.importStrategy==="component"&&i[h].push(c.cssFileName)}for(const l of g.classNames){const{src:h,name:F}=l;i[h]||(i[h]=[]);const c=l.generator._withBuildContext({callerName:F,isProduction:t,config:y}),j=await c.css;if(!j)continue;r[c.priority]||(r[c.priority]=[]),r[c.priority].push(c.cssFileName);const k=`css/${c.cssFileName}`,E=f.join(a,k);d.writeFileSync(E,j),y.importStrategy==="component"&&i[h].push(c.cssFileName)}y.importStrategy==="component"&&Object.entries(i).forEach(([l,h])=>{const F=h.map(Z=>`@import url('./${Z}');`).join(`
|
24
|
+
`),c=J(l,6),j=f.parse(l),k=R(j.name),E=f.join(a,`css/f_${k}-${c}.css`);d.writeFileSync(E,F||"/* Empty file */")});const m=o.map(l=>`@import url('./css/${l}');`).join(`
|
25
25
|
`);let _=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
26
26
|
|
27
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(
|
27
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return d.readFileSync(f.join(a,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
28
28
|
`)}
|
29
|
-
${m}`;if(y.importStrategy!=="component"){const
|
29
|
+
${m}`;if(y.importStrategy!=="component"){const l=r.reduce((h,F,c)=>{const j=F.reduce((q,H)=>{var U;const K=f.join(a,"css",H),Q=d.readFileSync(K,"utf8"),L=((U=/.*-([^-]+)-\d+.css/.exec(H))==null?void 0:U.at(1))||J(K,6);return q.includes(L)?q:`${q}
|
30
30
|
/*start:${L}-${H}*/
|
31
31
|
${Q}
|
32
32
|
/*end:${L}*/
|
33
|
-
`},""),k=`l_${
|
33
|
+
`},""),k=`l_${c}.css`,E=f.join(a,"css",k),Z=`@layer l${c} { ${j}
|
34
34
|
}`;return d.writeFileSync(E,Z),`${h}
|
35
|
-
@import url('./css/${k}');`},"");_+=
|
35
|
+
@import url('./css/${k}');`},"");_+=l}d.writeFileSync(w,_);const S=Date.now()-n,T=S<200?"🔥":S<500?"🚀":S<1e3?"🎉":S<2e3?"🚗":S<5e3?"🤔":"🥴";it.info(`Generated CSS in ${S}ms! ${T}`)}catch(n){console.error(n)}},ee=async(e,t,s=ft())=>{try{const n=await W(e);if(et(t)){const r=[],a=await lt(e),{contents:w}=await st(e,t,n);for(const[$,u]of Object.entries(w)){if(u.isKeyframes&&u.css){const m=`css/${`a_${u.animationName}.css`}`,N=f.join(n,m);d.writeFileSync(N,await u.css);return}if(u.isClassName){const i=u.generator._withBuildContext({callerName:$,isProduction:s,config:a}),m=await i.css;if(!m)continue;r[i.priority]||(r[i.priority]=[]),r[i.priority].push(i.cssFileName);const N=`css/${i.cssFileName}`,P=f.join(n,N);d.writeFileSync(P,m)}if(!u.generator)return;const p=u.generator._withBuildContext({callerName:$,isProduction:s,config:a}),b=await p.css;if(!b)continue;const g=`css/${p.cssFileName}`,y=f.join(n,g);d.writeFileSync(y,b),r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName)}if(a.importStrategy!=="component")r.forEach(($,u)=>{const p=`l_${u}.css`,b=f.join(n,"css",p);let g=d.readFileSync(b,"utf8");$.forEach(y=>{var P;const i=f.join(n,"css",y),m=((P=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:P.at(1))||J(i,6);if(!g.includes(m)){const M=d.readFileSync(i,"utf8"),_=`/*start:${m}-${y}*/
|
36
36
|
${M}
|
37
37
|
/*end:${m}*/
|
38
38
|
`;g=`${g.replace(/\}$/,"")}
|
39
39
|
${_}
|
40
40
|
}`}}),d.writeFileSync(b,g)});else{const $=r.flat().map(y=>`@import url('./${y}');`).join(`
|
41
|
-
`),
|
42
|
-
${
|
41
|
+
`),u=J(t,6),p=f.parse(t),b=R(p.name),g=f.join(n,`css/f_${b}-${u}.css`);d.writeFileSync(g,$||"/* Empty file */")}}}catch(n){console.error(n)}},se=async(e,t,s=ft())=>{try{const n=await W(e);if(et(t)){const r=d.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await at.writeFile(t,r);const w=await lt(e),{contents:$}=await st(e,t,n);let u=r;if(Object.entries($).forEach(([p,b])=>{var c;if(b.isKeyframes||!b.generator)return;const g=b.generator._withBuildContext({callerName:p,isProduction:s,config:w}),y=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!y)return console.error("Could not find the original declaration");const i=(c=y.at(1))==null?void 0:c.trim(),m=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(u);if(!m)return console.error("Could not find the original declaration");const{index:N}=m;let P=!1;const M=setTimeout(()=>P=!0,5e3);let _=0,V=!1,S=0;for(;!V&&!P;){const j=u[N+_];j==="("&&S++,j===")"&&S--,S===0&&j===")"&&(V=!0),_>u.length&&(P=!0),_++}if(!P)clearTimeout(M);else throw new Error("Failed to find the end of the styled call and timed out");const T=N+_,l=u.slice(N,T),h=u,F=` ${p} = styled(${i}, "${g.classNames}", ${JSON.stringify(g.clientProps)});`;u=u.replace(l,F),h===u&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),w.importStrategy==="component"){const p=J(t,6),b=f.parse(t);u=`import '../../saltygen/css/${`f_${R(b.name)}-${p}.css`}';
|
42
|
+
${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=te;exports.generateFile=ee;exports.isSaltyFile=et;exports.minimizeFile=se;exports.saltyFileRegExp=Pt;
|
@@ -27,10 +27,10 @@ const vt = (e) => (t) => {
|
|
27
27
|
let s = t;
|
28
28
|
const n = [];
|
29
29
|
return Object.values(e).forEach((o) => {
|
30
|
-
const { pattern: r, transform:
|
30
|
+
const { pattern: r, transform: a } = o;
|
31
31
|
s = s.replace(r, (y) => {
|
32
|
-
const { value: $, css:
|
33
|
-
return
|
32
|
+
const { value: $, css: f } = a(y);
|
33
|
+
return f && n.push(f), $;
|
34
34
|
});
|
35
35
|
}), { transformed: s, additionalCss: n };
|
36
36
|
}, wt = (e) => (t) => typeof t != "string" || !/\{[^{}]+\}/g.test(t) ? void 0 : { transformed: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) }, Zt = wt(), It = [
|
@@ -56,52 +56,52 @@ const vt = (e) => (t) => {
|
|
56
56
|
/.*font-size.*/
|
57
57
|
], Ht = (e, t, s) => It.some((o) => typeof o == "string" ? o === e : o.test(e)) ? `${t}px` : `${t}`, Bt = ["Webkit", "Moz", "ms", "O"], Gt = (e) => e.startsWith("-") ? e : Bt.some((t) => e.startsWith(t)) ? `-${A(e)}` : A(e), et = async (e, t = "", s, n = !1) => {
|
58
58
|
if (!e) throw new Error("No styles provided to parseStyles function!");
|
59
|
-
const o = /* @__PURE__ */ new Set(),
|
60
|
-
const
|
61
|
-
if (typeof
|
62
|
-
if (!
|
63
|
-
if (
|
64
|
-
if (
|
65
|
-
if (
|
66
|
-
const C = Object.entries(
|
67
|
-
for (const [E,
|
68
|
-
if (!
|
69
|
-
const h = Object.entries(
|
70
|
-
for (const [S,
|
71
|
-
if (!
|
59
|
+
const o = /* @__PURE__ */ new Set(), a = Object.entries(e).map(async ([m, i]) => {
|
60
|
+
const d = m.trim(), x = Gt(d), F = (N, V = ";") => `${x}:${N}${V}`;
|
61
|
+
if (typeof i == "function" && (i = i({ scope: t, config: s })), i instanceof Promise && (i = await i), typeof i == "object") {
|
62
|
+
if (!i) return;
|
63
|
+
if (i.isColor) return F(i.toString());
|
64
|
+
if (d === "defaultVariants") return;
|
65
|
+
if (d === "variants") {
|
66
|
+
const C = Object.entries(i);
|
67
|
+
for (const [E, l] of C) {
|
68
|
+
if (!l) return;
|
69
|
+
const h = Object.entries(l);
|
70
|
+
for (const [S, c] of h) {
|
71
|
+
if (!c) return;
|
72
72
|
const w = `${t}.${E}-${S}`;
|
73
|
-
(await et(
|
73
|
+
(await et(c, w, s)).forEach((T) => o.add(T));
|
74
74
|
}
|
75
75
|
}
|
76
76
|
return;
|
77
77
|
}
|
78
|
-
if (
|
79
|
-
for (const C of
|
80
|
-
const { css: E, ...
|
81
|
-
(await et(E, h, s)).forEach((
|
78
|
+
if (d === "compoundVariants") {
|
79
|
+
for (const C of i) {
|
80
|
+
const { css: E, ...l } = C, h = Object.entries(l).reduce((c, [w, _]) => `${c}.${w}-${_}`, t);
|
81
|
+
(await et(E, h, s)).forEach((c) => o.add(c));
|
82
82
|
}
|
83
83
|
return;
|
84
84
|
}
|
85
|
-
if (
|
86
|
-
const C =
|
87
|
-
o.add(
|
85
|
+
if (d.startsWith("@")) {
|
86
|
+
const C = d, E = await Q(i, t, s), l = `${C} { ${E} }`;
|
87
|
+
o.add(l);
|
88
88
|
return;
|
89
89
|
}
|
90
|
-
const N = m.includes("&") ?
|
91
|
-
(await et(
|
90
|
+
const N = m.includes("&") ? d.replace("&", t) : d.startsWith(":") ? `${t}${d}` : `${t} ${d}`;
|
91
|
+
(await et(i, N, s)).forEach((C) => o.add(C));
|
92
92
|
return;
|
93
93
|
}
|
94
|
-
if (typeof
|
95
|
-
const N = Ht(x,
|
94
|
+
if (typeof i == "number") {
|
95
|
+
const N = Ht(x, i);
|
96
96
|
return F(N);
|
97
97
|
}
|
98
|
-
if (typeof
|
99
|
-
if ("toString" in
|
98
|
+
if (typeof i != "string")
|
99
|
+
if ("toString" in i) i = i.toString();
|
100
100
|
else throw new Error(`Invalid value type for property ${x}`);
|
101
|
-
return F(
|
102
|
-
}), { modifiers: y } = {}, $ = [wt(), vt(y)],
|
103
|
-
m.map((
|
104
|
-
const F = await
|
101
|
+
return F(i);
|
102
|
+
}), { modifiers: y } = {}, $ = [wt(), vt(y)], p = (await Promise.all(a).then((m) => Promise.all(
|
103
|
+
m.map((i) => $.reduce(async (d, x) => {
|
104
|
+
const F = await d;
|
105
105
|
if (!F) return F;
|
106
106
|
const R = await x(F);
|
107
107
|
if (!R) return F;
|
@@ -111,13 +111,13 @@ const vt = (e) => (t) => {
|
|
111
111
|
for (const E of V)
|
112
112
|
C += await Q(E, "");
|
113
113
|
return `${C}${N}`;
|
114
|
-
}, Promise.resolve(
|
114
|
+
}, Promise.resolve(i)))
|
115
115
|
))).filter((m) => m !== void 0).join(`
|
116
116
|
`);
|
117
|
-
if (!
|
117
|
+
if (!p.trim()) return Array.from(o);
|
118
118
|
const b = t ? `${t} {
|
119
|
-
${
|
120
|
-
}` :
|
119
|
+
${p}
|
120
|
+
}` : p;
|
121
121
|
return o.has(b) ? Array.from(o) : [b, ...o];
|
122
122
|
}, Q = async (e, t, s, n = !1) => (await et(e, t, s, n)).join(`
|
123
123
|
`), Ct = async (e, t = []) => {
|
@@ -125,13 +125,13 @@ const vt = (e) => (t) => {
|
|
125
125
|
const s = [], n = {};
|
126
126
|
for (const [o, r] of Object.entries(e))
|
127
127
|
if (typeof r != "function") if (r && typeof r == "object") {
|
128
|
-
const
|
128
|
+
const a = o.trim(), y = await Ct(r, [...t, a]);
|
129
129
|
s.push(y);
|
130
130
|
} else
|
131
131
|
n[o] = r;
|
132
132
|
if (Object.keys(n).length) {
|
133
|
-
const o = t.map(A).join("-"), r = "t_" + z(o, 4),
|
134
|
-
s.push(
|
133
|
+
const o = t.map(A).join("-"), r = "t_" + z(o, 4), a = await Q(n, `.${o}, .${r}`);
|
134
|
+
s.push(a);
|
135
135
|
}
|
136
136
|
return s.join(`
|
137
137
|
`);
|
@@ -279,7 +279,7 @@ const te = (e) => new Yt(e), W = {
|
|
279
279
|
const t = await _t(e), s = (n = t.projects) == null ? void 0 : n.find((r) => e.endsWith(r.dir || ""));
|
280
280
|
return s || ((o = t.projects) == null ? void 0 : o.find((r) => r.dir === t.defaultProject));
|
281
281
|
}, se = async (e) => {
|
282
|
-
const t = await ft(e), s = await v(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Ft(e),
|
282
|
+
const t = await ft(e), s = await v(e), n = u(e, (t == null ? void 0 : t.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Ft(e), a = xt(n);
|
283
283
|
await $t.build({
|
284
284
|
entryPoints: [n],
|
285
285
|
minify: !0,
|
@@ -287,12 +287,12 @@ const te = (e) => new Yt(e), W = {
|
|
287
287
|
bundle: !0,
|
288
288
|
outfile: o,
|
289
289
|
format: r,
|
290
|
-
external:
|
290
|
+
external: a
|
291
291
|
});
|
292
292
|
const y = Date.now(), { config: $ } = await import(`${o}?t=${y}`);
|
293
293
|
return { config: $, path: o };
|
294
294
|
}, ne = async (e, t) => {
|
295
|
-
var
|
295
|
+
var dt, mt;
|
296
296
|
const s = await v(e), n = {
|
297
297
|
mediaQueries: [],
|
298
298
|
globalStyles: [],
|
@@ -307,31 +307,31 @@ const te = (e) => new Yt(e), W = {
|
|
307
307
|
});
|
308
308
|
})
|
309
309
|
);
|
310
|
-
const { config: o, path: r } = await se(e),
|
310
|
+
const { config: o, path: r } = await se(e), a = { ...o }, y = /* @__PURE__ */ new Set(), $ = (j, P = []) => j ? Object.entries(j).flatMap(([J, D]) => {
|
311
311
|
if (!D) return;
|
312
312
|
if (typeof D == "object") return $(D, [...P, J]);
|
313
313
|
const O = Pt(J), ot = A(J), rt = [...P, O].join(".");
|
314
314
|
y.add(`"${rt}"`);
|
315
315
|
const Y = [...P.map(A), ot].join("-"), ht = Zt(D);
|
316
316
|
return ht ? `--${Y}: ${ht.transformed};` : `--${Y}: ${D};`;
|
317
|
-
}) : [],
|
317
|
+
}) : [], f = (j) => j ? Object.entries(j).flatMap(([P, J]) => {
|
318
318
|
const D = $(J);
|
319
319
|
return P === "base" ? D.join("") : `${P} { ${D.join("")} }`;
|
320
|
-
}) : [],
|
320
|
+
}) : [], p = (j) => j ? Object.entries(j).flatMap(([P, J]) => Object.entries(J).flatMap(([D, O]) => {
|
321
321
|
const ot = $(O, [P]), rt = `.${P}-${D}, [data-${P}="${D}"]`, Y = ot.join("");
|
322
322
|
return `${rt} { ${Y} }`;
|
323
|
-
})) : [], b = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), g = (j) => n.variables.map((P) => j === "static" ? b(P._current) : P._current[j]), m = H(b(o.variables), g("static")),
|
324
|
-
k(N, V),
|
325
|
-
const C = u(s, "css/_global.css"), E = H(o.global, n.globalStyles),
|
326
|
-
k(C, `@layer global { ${
|
327
|
-
const h = u(s, "css/_reset.css"),
|
323
|
+
})) : [], b = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), g = (j) => n.variables.map((P) => j === "static" ? b(P._current) : P._current[j]), m = H(b(o.variables), g("static")), i = $(m), d = H((dt = o.variables) == null ? void 0 : dt.responsive, g("responsive")), x = f(d), F = H((mt = o.variables) == null ? void 0 : mt.conditional, g("conditional")), R = p(F), N = u(s, "css/_variables.css"), V = `:root { ${i.join("")} ${x.join("")} } ${R.join("")}`;
|
324
|
+
k(N, V), a.staticVariables = m;
|
325
|
+
const C = u(s, "css/_global.css"), E = H(o.global, n.globalStyles), l = await Q(E, "");
|
326
|
+
k(C, `@layer global { ${l} }`);
|
327
|
+
const h = u(s, "css/_reset.css"), c = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : qt, w = await Q(c, "");
|
328
328
|
k(h, `@layer reset { ${w} }`);
|
329
329
|
const _ = u(s, "css/_templates.css"), T = H(o.templates, n.templates), B = await Ct(T), G = Kt(T);
|
330
|
-
k(_, `@layer templates { ${B} }`),
|
330
|
+
k(_, `@layer templates { ${B} }`), a.templates = T;
|
331
331
|
const K = o.templates ? [te(o.templates)._setPath(`config;;${r}`)] : [], q = Ut(n.templates, K);
|
332
|
-
|
332
|
+
a.templatePaths = Object.fromEntries(Object.entries(q).map(([j, P]) => [j, P._path]));
|
333
333
|
const { mediaQueries: U } = n;
|
334
|
-
|
334
|
+
a.mediaQueries = Object.fromEntries(U.map(([j, P]) => [`@${j}`, P]));
|
335
335
|
const L = U.map(([j]) => `'@${j}'`).join(" | "), X = u(s, "types/css-tokens.d.ts"), kt = `
|
336
336
|
// Variable types
|
337
337
|
type VariableTokens = ${[...y].join("|")};
|
@@ -348,15 +348,15 @@ const te = (e) => new Yt(e), W = {
|
|
348
348
|
`;
|
349
349
|
k(X, kt);
|
350
350
|
const Dt = u(s, "cache/config-cache.json");
|
351
|
-
k(Dt, JSON.stringify(
|
351
|
+
k(Dt, JSON.stringify(a, null, 2));
|
352
352
|
}, yt = (e) => e.replace(/styled\(([^"'`{,]+),/g, (t, s) => {
|
353
353
|
if (/^['"`]/.test(s)) return t;
|
354
354
|
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
355
355
|
if (!o.test(e)) return t;
|
356
|
-
const
|
357
|
-
if (
|
358
|
-
const y =
|
359
|
-
if (Nt.some((
|
356
|
+
const a = o.exec(e);
|
357
|
+
if (a) {
|
358
|
+
const y = a.at(1);
|
359
|
+
if (Nt.some((f) => y == null ? void 0 : y.includes(f))) return t;
|
360
360
|
}
|
361
361
|
return "styled('div',";
|
362
362
|
}), oe = (e, t) => {
|
@@ -374,12 +374,12 @@ ${e}`;
|
|
374
374
|
const n = z(t), o = u(s, "./temp");
|
375
375
|
ct(o) || I(o);
|
376
376
|
const r = st(t);
|
377
|
-
let
|
378
|
-
|
379
|
-
const y = u(s, "js", n + ".js"), $ = await ft(e),
|
377
|
+
let a = M(t, "utf8");
|
378
|
+
a = yt(a), a = oe(a, e);
|
379
|
+
const y = u(s, "js", n + ".js"), $ = await ft(e), f = u(e, ($ == null ? void 0 : $.configDir) || "", "salty.config.ts"), p = xt(f), b = await Ft(e);
|
380
380
|
await $t.build({
|
381
381
|
stdin: {
|
382
|
-
contents:
|
382
|
+
contents: a,
|
383
383
|
sourcefile: r.base,
|
384
384
|
resolveDir: r.dir,
|
385
385
|
loader: "tsx"
|
@@ -391,14 +391,14 @@ ${e}`;
|
|
391
391
|
format: b,
|
392
392
|
target: ["node20"],
|
393
393
|
keepNames: !0,
|
394
|
-
external:
|
394
|
+
external: p,
|
395
395
|
packages: "external",
|
396
396
|
plugins: [
|
397
397
|
{
|
398
398
|
name: "test",
|
399
|
-
setup: (
|
400
|
-
|
401
|
-
const x = M(
|
399
|
+
setup: (i) => {
|
400
|
+
i.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (d) => {
|
401
|
+
const x = M(d.path, "utf8");
|
402
402
|
return { contents: yt(x), loader: "ts" };
|
403
403
|
});
|
404
404
|
}
|
@@ -414,127 +414,127 @@ ${e}`;
|
|
414
414
|
}, ut = async (e) => {
|
415
415
|
const t = await re(e), s = await v(e), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
|
416
416
|
return H(r, t);
|
417
|
-
},
|
417
|
+
}, pt = () => {
|
418
418
|
try {
|
419
419
|
return process.env.NODE_ENV === "production";
|
420
420
|
} catch {
|
421
421
|
return !1;
|
422
422
|
}
|
423
|
-
},
|
423
|
+
}, de = async (e, t = pt(), s = !0) => {
|
424
424
|
try {
|
425
425
|
const n = Date.now();
|
426
426
|
t ? at.info("Generating CSS in production mode! 🔥") : at.info("Generating CSS in development mode! 🚀");
|
427
|
-
const o = [], r = [],
|
427
|
+
const o = [], r = [], a = await v(e), y = u(a, "index.css");
|
428
428
|
s && (() => {
|
429
|
-
ct(
|
429
|
+
ct(a) && Ot("rm -rf " + a), I(a, { recursive: !0 }), I(u(a, "css")), I(u(a, "types")), I(u(a, "js")), I(u(a, "cache"));
|
430
430
|
})();
|
431
|
-
const
|
432
|
-
async function b(
|
433
|
-
const h = ["node_modules", "saltygen"], S = Vt(
|
431
|
+
const f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
|
432
|
+
async function b(l) {
|
433
|
+
const h = ["node_modules", "saltygen"], S = Vt(l);
|
434
434
|
if (S.isDirectory()) {
|
435
|
-
const
|
436
|
-
if (h.some((_) =>
|
437
|
-
await Promise.all(
|
438
|
-
} else if (S.isFile() && lt(
|
439
|
-
|
440
|
-
const w = M(
|
441
|
-
/define[\w\d]+\(/.test(w) &&
|
435
|
+
const c = Mt(l);
|
436
|
+
if (h.some((_) => l.includes(_))) return;
|
437
|
+
await Promise.all(c.map((_) => b(u(l, _))));
|
438
|
+
} else if (S.isFile() && lt(l)) {
|
439
|
+
f.add(l);
|
440
|
+
const w = M(l, "utf8");
|
441
|
+
/define[\w\d]+\(/.test(w) && p.add(l);
|
442
442
|
}
|
443
443
|
}
|
444
|
-
await b(e), await ne(e,
|
444
|
+
await b(e), await ne(e, p);
|
445
445
|
const g = {
|
446
446
|
keyframes: [],
|
447
447
|
components: [],
|
448
448
|
classNames: []
|
449
449
|
};
|
450
450
|
await Promise.all(
|
451
|
-
[...
|
452
|
-
const { contents: h } = await nt(e,
|
453
|
-
Object.entries(h).forEach(([S,
|
454
|
-
|
455
|
-
value:
|
456
|
-
src:
|
451
|
+
[...f].map(async (l) => {
|
452
|
+
const { contents: h } = await nt(e, l, a);
|
453
|
+
Object.entries(h).forEach(([S, c]) => {
|
454
|
+
c.isKeyframes ? g.keyframes.push({
|
455
|
+
value: c,
|
456
|
+
src: l,
|
457
457
|
name: S
|
458
|
-
}) :
|
459
|
-
...
|
460
|
-
src:
|
458
|
+
}) : c.isClassName ? g.classNames.push({
|
459
|
+
...c,
|
460
|
+
src: l,
|
461
461
|
name: S
|
462
|
-
}) :
|
463
|
-
...
|
464
|
-
src:
|
462
|
+
}) : c.generator && g.components.push({
|
463
|
+
...c,
|
464
|
+
src: l,
|
465
465
|
name: S
|
466
466
|
});
|
467
467
|
});
|
468
468
|
})
|
469
469
|
);
|
470
470
|
const m = await ut(e);
|
471
|
-
for (const
|
472
|
-
const { value: h } =
|
471
|
+
for (const l of g.keyframes) {
|
472
|
+
const { value: h } = l, S = `a_${h.animationName}.css`, c = `css/${S}`, w = u(a, c);
|
473
473
|
o.push(S), k(w, h.css);
|
474
474
|
}
|
475
|
-
const
|
476
|
-
for (const
|
477
|
-
const { src: h, name: S } =
|
478
|
-
|
479
|
-
const
|
475
|
+
const i = {};
|
476
|
+
for (const l of g.components) {
|
477
|
+
const { src: h, name: S } = l;
|
478
|
+
i[h] || (i[h] = []);
|
479
|
+
const c = l.generator._withBuildContext({
|
480
480
|
callerName: S,
|
481
481
|
isProduction: t,
|
482
482
|
config: m
|
483
483
|
});
|
484
|
-
r[
|
485
|
-
const w = await
|
484
|
+
r[c.priority] || (r[c.priority] = []);
|
485
|
+
const w = await c.css;
|
486
486
|
if (!w) continue;
|
487
|
-
r[
|
488
|
-
const _ = `css/${
|
489
|
-
k(T, w), m.importStrategy === "component" &&
|
487
|
+
r[c.priority].push(c.cssFileName);
|
488
|
+
const _ = `css/${c.cssFileName}`, T = u(a, _);
|
489
|
+
k(T, w), m.importStrategy === "component" && i[h].push(c.cssFileName);
|
490
490
|
}
|
491
|
-
for (const
|
492
|
-
const { src: h, name: S } =
|
493
|
-
|
494
|
-
const
|
491
|
+
for (const l of g.classNames) {
|
492
|
+
const { src: h, name: S } = l;
|
493
|
+
i[h] || (i[h] = []);
|
494
|
+
const c = l.generator._withBuildContext({
|
495
495
|
callerName: S,
|
496
496
|
isProduction: t,
|
497
497
|
config: m
|
498
|
-
}), w = await
|
498
|
+
}), w = await c.css;
|
499
499
|
if (!w) continue;
|
500
|
-
r[
|
501
|
-
const _ = `css/${
|
502
|
-
k(T, w), m.importStrategy === "component" &&
|
500
|
+
r[c.priority] || (r[c.priority] = []), r[c.priority].push(c.cssFileName);
|
501
|
+
const _ = `css/${c.cssFileName}`, T = u(a, _);
|
502
|
+
k(T, w), m.importStrategy === "component" && i[h].push(c.cssFileName);
|
503
503
|
}
|
504
|
-
m.importStrategy === "component" && Object.entries(
|
504
|
+
m.importStrategy === "component" && Object.entries(i).forEach(([l, h]) => {
|
505
505
|
const S = h.map((B) => `@import url('./${B}');`).join(`
|
506
|
-
`),
|
506
|
+
`), c = z(l, 6), w = st(l), _ = A(w.name), T = u(a, `css/f_${_}-${c}.css`);
|
507
507
|
k(T, S || "/* Empty file */");
|
508
508
|
});
|
509
|
-
const
|
509
|
+
const d = o.map((l) => `@import url('./css/${l}');`).join(`
|
510
510
|
`);
|
511
511
|
let N = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
512
512
|
|
513
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((
|
513
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
514
514
|
try {
|
515
|
-
return M(u(
|
515
|
+
return M(u(a, "css", l), "utf8").length > 0;
|
516
516
|
} catch {
|
517
517
|
return !1;
|
518
518
|
}
|
519
|
-
}).map((
|
519
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
520
520
|
`)}
|
521
|
-
${
|
521
|
+
${d}`;
|
522
522
|
if (m.importStrategy !== "component") {
|
523
|
-
const
|
523
|
+
const l = r.reduce((h, S, c) => {
|
524
524
|
const w = S.reduce((G, K) => {
|
525
525
|
var X;
|
526
|
-
const q = u(
|
526
|
+
const q = u(a, "css", K), U = M(q, "utf8"), L = ((X = /.*-([^-]+)-\d+.css/.exec(K)) == null ? void 0 : X.at(1)) || z(q, 6);
|
527
527
|
return G.includes(L) ? G : `${G}
|
528
528
|
/*start:${L}-${K}*/
|
529
529
|
${U}
|
530
530
|
/*end:${L}*/
|
531
531
|
`;
|
532
|
-
}, ""), _ = `l_${
|
532
|
+
}, ""), _ = `l_${c}.css`, T = u(a, "css", _), B = `@layer l${c} { ${w}
|
533
533
|
}`;
|
534
534
|
return k(T, B), `${h}
|
535
535
|
@import url('./css/${_}');`;
|
536
536
|
}, "");
|
537
|
-
N +=
|
537
|
+
N += l;
|
538
538
|
}
|
539
539
|
k(y, N);
|
540
540
|
const C = Date.now() - n, E = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
|
@@ -542,49 +542,49 @@ ${U}
|
|
542
542
|
} catch (n) {
|
543
543
|
console.error(n);
|
544
544
|
}
|
545
|
-
}, me = async (e, t, s =
|
545
|
+
}, me = async (e, t, s = pt()) => {
|
546
546
|
try {
|
547
547
|
const n = await v(e);
|
548
548
|
if (lt(t)) {
|
549
|
-
const r = [],
|
550
|
-
for (const [$,
|
551
|
-
if (
|
552
|
-
const
|
553
|
-
k(x, await
|
549
|
+
const r = [], a = await ut(e), { contents: y } = await nt(e, t, n);
|
550
|
+
for (const [$, f] of Object.entries(y)) {
|
551
|
+
if (f.isKeyframes && f.css) {
|
552
|
+
const d = `css/${`a_${f.animationName}.css`}`, x = u(n, d);
|
553
|
+
k(x, await f.css);
|
554
554
|
return;
|
555
555
|
}
|
556
|
-
if (
|
557
|
-
const
|
556
|
+
if (f.isClassName) {
|
557
|
+
const i = f.generator._withBuildContext({
|
558
558
|
callerName: $,
|
559
559
|
isProduction: s,
|
560
|
-
config:
|
561
|
-
}),
|
562
|
-
if (!
|
563
|
-
r[
|
564
|
-
const x = `css/${
|
565
|
-
k(F,
|
560
|
+
config: a
|
561
|
+
}), d = await i.css;
|
562
|
+
if (!d) continue;
|
563
|
+
r[i.priority] || (r[i.priority] = []), r[i.priority].push(i.cssFileName);
|
564
|
+
const x = `css/${i.cssFileName}`, F = u(n, x);
|
565
|
+
k(F, d);
|
566
566
|
}
|
567
|
-
if (!
|
568
|
-
const
|
567
|
+
if (!f.generator) return;
|
568
|
+
const p = f.generator._withBuildContext({
|
569
569
|
callerName: $,
|
570
570
|
isProduction: s,
|
571
|
-
config:
|
572
|
-
}), b = await
|
571
|
+
config: a
|
572
|
+
}), b = await p.css;
|
573
573
|
if (!b) continue;
|
574
|
-
const g = `css/${
|
575
|
-
k(m, b), r[
|
574
|
+
const g = `css/${p.cssFileName}`, m = u(n, g);
|
575
|
+
k(m, b), r[p.priority] || (r[p.priority] = []), r[p.priority].push(p.cssFileName);
|
576
576
|
}
|
577
|
-
if (
|
578
|
-
r.forEach(($,
|
579
|
-
const
|
577
|
+
if (a.importStrategy !== "component")
|
578
|
+
r.forEach(($, f) => {
|
579
|
+
const p = `l_${f}.css`, b = u(n, "css", p);
|
580
580
|
let g = M(b, "utf8");
|
581
581
|
$.forEach((m) => {
|
582
582
|
var F;
|
583
|
-
const
|
584
|
-
if (!g.includes(
|
585
|
-
const R = M(
|
583
|
+
const i = u(n, "css", m), d = ((F = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : F.at(1)) || z(i, 6);
|
584
|
+
if (!g.includes(d)) {
|
585
|
+
const R = M(i, "utf8"), N = `/*start:${d}-${m}*/
|
586
586
|
${R}
|
587
|
-
/*end:${
|
587
|
+
/*end:${d}*/
|
588
588
|
`;
|
589
589
|
g = `${g.replace(/\}$/, "")}
|
590
590
|
${N}
|
@@ -594,50 +594,50 @@ ${N}
|
|
594
594
|
});
|
595
595
|
else {
|
596
596
|
const $ = r.flat().map((m) => `@import url('./${m}');`).join(`
|
597
|
-
`),
|
597
|
+
`), f = z(t, 6), p = st(t), b = A(p.name), g = u(n, `css/f_${b}-${f}.css`);
|
598
598
|
k(g, $ || "/* Empty file */");
|
599
599
|
}
|
600
600
|
}
|
601
601
|
} catch (n) {
|
602
602
|
console.error(n);
|
603
603
|
}
|
604
|
-
}, he = async (e, t, s =
|
604
|
+
}, he = async (e, t, s = pt()) => {
|
605
605
|
try {
|
606
606
|
const n = await v(e);
|
607
607
|
if (lt(t)) {
|
608
608
|
const r = M(t, "utf8");
|
609
|
-
r.replace(/^(?!export\s)const\s.*/gm, (
|
609
|
+
r.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== r && await Rt(t, r);
|
610
610
|
const y = await ut(e), { contents: $ } = await nt(e, t, n);
|
611
|
-
let
|
612
|
-
if (Object.entries($).forEach(([
|
613
|
-
var
|
611
|
+
let f = r;
|
612
|
+
if (Object.entries($).forEach(([p, b]) => {
|
613
|
+
var c;
|
614
614
|
if (b.isKeyframes || !b.generator) return;
|
615
615
|
const g = b.generator._withBuildContext({
|
616
|
-
callerName:
|
616
|
+
callerName: p,
|
617
617
|
isProduction: s,
|
618
618
|
config: y
|
619
|
-
}), m = new RegExp(`\\s${
|
619
|
+
}), m = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
620
620
|
if (!m) return console.error("Could not find the original declaration");
|
621
|
-
const
|
622
|
-
if (!
|
623
|
-
const { index: x } =
|
621
|
+
const i = (c = m.at(1)) == null ? void 0 : c.trim(), d = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(f);
|
622
|
+
if (!d) return console.error("Could not find the original declaration");
|
623
|
+
const { index: x } = d;
|
624
624
|
let F = !1;
|
625
625
|
const R = setTimeout(() => F = !0, 5e3);
|
626
626
|
let N = 0, V = !1, C = 0;
|
627
627
|
for (; !V && !F; ) {
|
628
|
-
const w =
|
629
|
-
w === "(" && C++, w === ")" && C--, C === 0 && w === ")" && (V = !0), N >
|
628
|
+
const w = f[x + N];
|
629
|
+
w === "(" && C++, w === ")" && C--, C === 0 && w === ")" && (V = !0), N > f.length && (F = !0), N++;
|
630
630
|
}
|
631
631
|
if (!F) clearTimeout(R);
|
632
632
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
633
|
-
const E = x + N,
|
634
|
-
|
633
|
+
const E = x + N, l = f.slice(x, E), h = f, S = ` ${p} = styled(${i}, "${g.classNames}", ${JSON.stringify(g.clientProps)});`;
|
634
|
+
f = f.replace(l, S), h === f && console.error("Minimize file failed to change content", { name: p, tagName: i });
|
635
635
|
}), y.importStrategy === "component") {
|
636
|
-
const
|
637
|
-
|
638
|
-
${
|
636
|
+
const p = z(t, 6), b = st(t);
|
637
|
+
f = `import '../../saltygen/css/${`f_${A(b.name)}-${p}.css`}';
|
638
|
+
${f}`;
|
639
639
|
}
|
640
|
-
return
|
640
|
+
return f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
|
641
641
|
}
|
642
642
|
} catch (n) {
|
643
643
|
console.error("Error in minimizeFile:", n);
|
@@ -645,7 +645,7 @@ ${l}`;
|
|
645
645
|
};
|
646
646
|
export {
|
647
647
|
me as a,
|
648
|
-
|
648
|
+
de as g,
|
649
649
|
lt as i,
|
650
650
|
he as m,
|
651
651
|
ee as s
|
package/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-B-t5k40D.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var i,n,u;(n=(i=e.module)==null?void 0:i.rules)==null||n.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(u=e.plugins)==null||u.push({apply:f=>{let o=!1;f.hooks.beforeCompile.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
|
package/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { resolve as p } from "path";
|
2
|
-
import { i as f, s as d, g as u, a as y } from "./index-
|
2
|
+
import { i as f, s as d, g as u, a as y } from "./index-C47SclTa.js";
|
3
3
|
import { readFile as g } from "fs/promises";
|
4
4
|
import { watch as m } from "fs";
|
5
5
|
const w = async (s) => {
|
package/loader.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const i=require("./index-
|
1
|
+
"use strict";const i=require("./index-B-t5k40D.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
|
package/loader.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/webpack",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.218",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.218",
|
38
38
|
"webpack": ">=5.x"
|
39
39
|
}
|
40
40
|
}
|