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