@salty-css/vite 0.0.1-alpha.201 → 0.0.1-alpha.203
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 -346
- 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},W=(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}`,vt=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:vt.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=Jt(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={};for(const[o,i]of Object.entries(t))if(typeof i=="function")console.log("Function found",o);else if(i&&typeof i=="object"){const l=o.trim(),y=await ht(i,[...e,l]);s.push(y)}else n[o]=i;if(Object.keys(n).length){const o=e.map(M).join("-"),i=await G(n,`.${o}`);s.push(i)}return s.join(`
|
4
|
+
`)},zt=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,".."))},At=async t=>{const e=St(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await At(t);if(e)return e.type};let z;const bt=async t=>{if(z)return z;const e=await Wt(t);return e==="module"?z="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"))&&(z="cjs"),z||"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"}},A=(...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}),{}),v={externalModules:[],rcFile:void 0,destDir:void 0},jt=t=>{if(v.externalModules.length>0)return v.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 v.externalModules=n,n},J=async t=>{if(v.destDir)return v.destDir;const e=await at(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return v.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(v.rcFile)return v.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?(v.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 J(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 J(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=A(S(o.variables),g("static")),p=y(r),h=A((lt=o.variables)==null?void 0:lt.responsive,g("responsive")),N=w(h),_=A((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=A(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=A(o.templates,n.templates),Z=await ht(k),q=zt(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=W(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 J(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 J(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return A(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 J(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=W(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))||W(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 J(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))||W(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=W(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 J(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=W(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 v, 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
|
+
}, H = (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,116 @@ 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
|
+
], vt = (t, e, s) => zt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, Zt = ["Webkit", "Moz", "ms", "O"], Ht = (t) => t.startsWith("-") ? t : Zt.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 = Ht(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 = vt(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
|
-
|
112
|
-
if (typeof
|
113
|
-
|
114
|
-
const
|
115
|
-
s.push(
|
121
|
+
for (const [o, i] of Object.entries(t))
|
122
|
+
if (typeof i == "function") console.log("Function found", o);
|
123
|
+
else if (i && typeof i == "object") {
|
124
|
+
const c = o.trim(), p = await bt(i, [...e, c]);
|
125
|
+
s.push(p);
|
116
126
|
} else
|
117
|
-
n[o] =
|
118
|
-
|
119
|
-
const o = e.map(
|
120
|
-
s.push(
|
127
|
+
n[o] = i;
|
128
|
+
if (Object.keys(n).length) {
|
129
|
+
const o = e.map(M).join("-"), i = await Q(n, `.${o}`);
|
130
|
+
s.push(i);
|
121
131
|
}
|
122
132
|
return s.join(`
|
123
133
|
`);
|
124
|
-
},
|
125
|
-
const
|
126
|
-
return typeof o == "object" ?
|
127
|
-
}), [...s]) : [],
|
134
|
+
}, It = (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]) => {
|
135
|
+
const i = e ? `${e}.${n}` : n;
|
136
|
+
return typeof o == "object" ? Ct(o, i, s) : s.add(e);
|
137
|
+
}), [...s]) : [], St = (t) => {
|
128
138
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
129
|
-
const e =
|
130
|
-
return
|
131
|
-
},
|
132
|
-
const e =
|
133
|
-
return await
|
139
|
+
const e = u(t, "package.json");
|
140
|
+
return ct(e) ? e : St(u(t, ".."));
|
141
|
+
}, Bt = async (t) => {
|
142
|
+
const e = St(t);
|
143
|
+
return await lt(e, "utf-8").then(JSON.parse).catch(() => {
|
134
144
|
});
|
135
|
-
},
|
136
|
-
const e = await
|
145
|
+
}, Gt = async (t) => {
|
146
|
+
const e = await Bt(t);
|
137
147
|
if (e)
|
138
148
|
return e.type;
|
139
149
|
};
|
140
|
-
let
|
141
|
-
const
|
142
|
-
if (
|
143
|
-
const e = await
|
144
|
-
return e === "module" ?
|
145
|
-
},
|
150
|
+
let z;
|
151
|
+
const jt = async (t) => {
|
152
|
+
if (z) return z;
|
153
|
+
const e = await Gt(t);
|
154
|
+
return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
|
155
|
+
}, at = Vt({
|
146
156
|
level: "debug",
|
147
|
-
format:
|
148
|
-
transports: [new
|
157
|
+
format: it.combine(it.colorize(), it.cli()),
|
158
|
+
transports: [new Mt.Console({})]
|
149
159
|
});
|
150
|
-
function
|
151
|
-
return t ? typeof t != "string" ?
|
160
|
+
function Ft(t) {
|
161
|
+
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
162
|
}
|
153
|
-
const
|
163
|
+
const Kt = {
|
154
164
|
/** Set box model to border-box */
|
155
165
|
"*, *::before, *::after": {
|
156
166
|
boxSizing: "border-box"
|
@@ -196,112 +206,116 @@ const Bt = {
|
|
196
206
|
fontSize: "100%",
|
197
207
|
lineHeight: "1.15em"
|
198
208
|
}
|
199
|
-
},
|
209
|
+
}, Z = (...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
210
|
externalModules: [],
|
201
211
|
rcFile: void 0,
|
202
212
|
destDir: void 0
|
203
|
-
},
|
204
|
-
if (
|
205
|
-
const s =
|
213
|
+
}, xt = (t) => {
|
214
|
+
if (A.externalModules.length > 0) return A.externalModules;
|
215
|
+
const s = V(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
206
216
|
if (!s) return [];
|
207
217
|
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 (
|
218
|
+
return A.externalModules = n, n;
|
219
|
+
}, W = async (t) => {
|
220
|
+
if (A.destDir) return A.destDir;
|
221
|
+
const e = await ft(t), s = u(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
222
|
+
return A.destDir = s, s;
|
223
|
+
}, Nt = ["salty", "css", "styles", "styled"], Qt = (t = []) => new RegExp(`\\.(${[...Nt, ...t].join("|")})\\.`), I = (t, e = []) => Qt(e).test(t), Pt = async (t) => {
|
224
|
+
if (A.rcFile) return A.rcFile;
|
215
225
|
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
216
|
-
const e =
|
226
|
+
const e = u(t, ".saltyrc.json"), s = await lt(e, "utf-8").then(JSON.parse).catch(() => {
|
217
227
|
});
|
218
|
-
return s ? (
|
219
|
-
},
|
228
|
+
return s ? (A.rcFile = s, s) : Pt(u(t, ".."));
|
229
|
+
}, ft = async (t) => {
|
220
230
|
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
|
231
|
+
const e = await Pt(t), s = (n = e.projects) == null ? void 0 : n.find((i) => t.endsWith(i.dir || ""));
|
232
|
+
return s || ((o = e.projects) == null ? void 0 : o.find((i) => i.dir === e.defaultProject));
|
233
|
+
}, Ut = async (t) => {
|
234
|
+
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);
|
235
|
+
await $t.build({
|
226
236
|
entryPoints: [n],
|
227
237
|
minify: !0,
|
228
238
|
treeShaking: !0,
|
229
239
|
bundle: !0,
|
230
240
|
outfile: o,
|
231
|
-
format:
|
232
|
-
external:
|
241
|
+
format: i,
|
242
|
+
external: c
|
233
243
|
});
|
234
|
-
const
|
235
|
-
return
|
236
|
-
},
|
237
|
-
var
|
238
|
-
const s = await
|
244
|
+
const p = Date.now(), { config: y } = await import(`${o}?t=${p}`);
|
245
|
+
return y;
|
246
|
+
}, qt = async (t, e) => {
|
247
|
+
var dt, pt;
|
248
|
+
const s = await W(t), n = {
|
239
249
|
mediaQueries: [],
|
240
250
|
globalStyles: [],
|
241
251
|
variables: [],
|
242
252
|
templates: []
|
243
253
|
};
|
244
254
|
await Promise.all(
|
245
|
-
[...e].map(async (
|
246
|
-
const C = await
|
247
|
-
Object.entries(C).forEach(([
|
248
|
-
|
255
|
+
[...e].map(async (b) => {
|
256
|
+
const { contents: C, outputFilePath: J } = await st(t, b, s);
|
257
|
+
Object.entries(C).forEach(([E, O]) => {
|
258
|
+
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
259
|
});
|
250
260
|
})
|
251
261
|
);
|
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
|
-
|
262
|
+
const o = await Ut(t), i = { ...o }, c = /* @__PURE__ */ new Set(), p = (b, C = []) => b ? Object.entries(b).flatMap(([J, E]) => {
|
263
|
+
if (!E) return;
|
264
|
+
if (typeof E == "object") return p(E, [...C, J]);
|
265
|
+
const O = Ft(J), ot = M(J), rt = [...C, O].join(".");
|
266
|
+
c.add(`"${rt}"`);
|
267
|
+
const Y = [...C.map(M), ot].join("-"), mt = Wt(E);
|
268
|
+
return mt ? `--${Y}: ${mt.transformed};` : `--${Y}: ${E};`;
|
269
|
+
}) : [], y = (b) => b ? Object.entries(b).flatMap(([C, J]) => {
|
270
|
+
const E = p(J);
|
271
|
+
return C === "base" ? E.join("") : `${C} { ${E.join("")} }`;
|
272
|
+
}) : [], a = (b) => b ? Object.entries(b).flatMap(([C, J]) => Object.entries(J).flatMap(([E, O]) => {
|
273
|
+
const ot = p(O, [C]), rt = `.${C}-${E}, [data-${C}="${E}"]`, Y = ot.join("");
|
274
|
+
return `${rt} { ${Y} }`;
|
275
|
+
})) : [], $ = (b) => ({ ...b, responsive: void 0, conditional: void 0 }), g = (b) => n.variables.map((C) => b === "static" ? $(C._current) : C._current[b]), r = Z($(o.variables), g("static")), d = p(r), h = Z((dt = o.variables) == null ? void 0 : dt.responsive, g("responsive")), x = y(h), D = Z((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("")}`;
|
276
|
+
k(T, S), i.staticVariables = r;
|
277
|
+
const _ = u(s, "css/_global.css"), F = Z(o.global, n.globalStyles), R = await Q(F, "");
|
278
|
+
k(_, `@layer global { ${R} }`);
|
279
|
+
const l = u(s, "css/_reset.css"), w = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, f = await Q(w, "");
|
280
|
+
k(l, `@layer reset { ${f} }`);
|
281
|
+
const j = u(s, "css/_templates.css"), P = Z(o.templates, n.templates), B = await bt(P), G = It(P);
|
282
|
+
k(j, B), i.templates = P;
|
283
|
+
const K = Lt(n.templates);
|
284
|
+
i.templatePaths = Object.fromEntries(
|
285
|
+
Object.entries(K).map(([b, C]) => [b, C._path || "nope"])
|
286
|
+
);
|
287
|
+
const { mediaQueries: L } = n;
|
288
|
+
i.mediaQueries = Object.fromEntries(L.map(([b, C]) => [`@${b}`, C]));
|
289
|
+
const U = L.map(([b]) => `'@${b}'`).join(" | "), nt = u(s, "types/css-tokens.d.ts"), X = `
|
276
290
|
// Variable types
|
277
|
-
type VariableTokens = ${[...
|
291
|
+
type VariableTokens = ${[...c].join("|")};
|
278
292
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
279
293
|
|
280
294
|
// Template types
|
281
295
|
type TemplateTokens = {
|
282
|
-
${Object.entries(
|
296
|
+
${Object.entries(G).map(([b, C]) => `${b}?: ${C}`).join(`
|
283
297
|
`)}
|
284
298
|
}
|
285
299
|
|
286
300
|
// Media query types
|
287
301
|
type MediaQueryKeys = ${U || "''"};
|
288
302
|
`;
|
289
|
-
k(
|
290
|
-
const
|
291
|
-
k(
|
292
|
-
},
|
303
|
+
k(nt, X);
|
304
|
+
const Dt = u(s, "cache/config-cache.json");
|
305
|
+
k(Dt, JSON.stringify(i, null, 2));
|
306
|
+
}, ht = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
293
307
|
if (/^['"`]/.test(s)) return e;
|
294
308
|
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
295
309
|
if (!o.test(t)) return e;
|
296
|
-
const
|
297
|
-
if (
|
298
|
-
const
|
299
|
-
if (
|
310
|
+
const c = o.exec(t);
|
311
|
+
if (c) {
|
312
|
+
const p = c.at(1);
|
313
|
+
if (Nt.some((a) => p == null ? void 0 : p.includes(a))) return e;
|
300
314
|
}
|
301
315
|
return "styled('div',";
|
302
|
-
}),
|
316
|
+
}), Xt = (t, e) => {
|
303
317
|
try {
|
304
|
-
const s =
|
318
|
+
const s = V(u(e, "saltygen/cache/config-cache.json"), "utf8");
|
305
319
|
return s ? `globalThis.saltyConfig = ${s};
|
306
320
|
|
307
321
|
${t}` : `globalThis.saltyConfig = {};
|
@@ -310,286 +324,287 @@ ${t}`;
|
|
310
324
|
} catch {
|
311
325
|
return t;
|
312
326
|
}
|
313
|
-
},
|
314
|
-
const n =
|
315
|
-
|
316
|
-
const
|
317
|
-
let
|
318
|
-
|
319
|
-
const
|
320
|
-
await
|
327
|
+
}, st = async (t, e, s) => {
|
328
|
+
const n = H(e), o = u(s, "./temp");
|
329
|
+
ct(o) || v(o);
|
330
|
+
const i = et(e);
|
331
|
+
let c = V(e, "utf8");
|
332
|
+
c = ht(c), c = Xt(c, t);
|
333
|
+
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);
|
334
|
+
await $t.build({
|
321
335
|
stdin: {
|
322
|
-
contents:
|
323
|
-
sourcefile:
|
324
|
-
resolveDir:
|
336
|
+
contents: c,
|
337
|
+
sourcefile: i.base,
|
338
|
+
resolveDir: i.dir,
|
325
339
|
loader: "tsx"
|
326
340
|
},
|
327
341
|
minify: !1,
|
328
342
|
treeShaking: !0,
|
329
343
|
bundle: !0,
|
330
|
-
outfile:
|
331
|
-
format:
|
344
|
+
outfile: p,
|
345
|
+
format: g,
|
332
346
|
target: ["node20"],
|
333
347
|
keepNames: !0,
|
334
|
-
external:
|
348
|
+
external: $,
|
335
349
|
packages: "external",
|
336
350
|
plugins: [
|
337
351
|
{
|
338
352
|
name: "test",
|
339
|
-
setup: (
|
340
|
-
|
341
|
-
const
|
342
|
-
return { contents:
|
353
|
+
setup: (h) => {
|
354
|
+
h.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (x) => {
|
355
|
+
const D = V(x.path, "utf8");
|
356
|
+
return { contents: ht(D), loader: "ts" };
|
343
357
|
});
|
344
358
|
}
|
345
359
|
}
|
346
360
|
]
|
347
361
|
});
|
348
|
-
const
|
349
|
-
return await import(`${
|
350
|
-
},
|
351
|
-
const e = await
|
362
|
+
const r = Date.now();
|
363
|
+
return { contents: await import(`${p}?t=${r}`), outputFilePath: p };
|
364
|
+
}, Yt = async (t) => {
|
365
|
+
const e = await W(t), s = u(e, "cache/config-cache.json"), n = V(s, "utf8");
|
352
366
|
if (!n) throw new Error("Could not find config cache file");
|
353
367
|
return JSON.parse(n);
|
354
|
-
},
|
355
|
-
const e = await
|
356
|
-
return
|
357
|
-
},
|
368
|
+
}, ut = async (t) => {
|
369
|
+
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}`);
|
370
|
+
return Z(i, e);
|
371
|
+
}, kt = () => {
|
358
372
|
try {
|
359
373
|
return process.env.NODE_ENV === "production";
|
360
374
|
} catch {
|
361
375
|
return !1;
|
362
376
|
}
|
363
|
-
},
|
377
|
+
}, te = async (t, e = kt(), s = !0) => {
|
364
378
|
try {
|
365
379
|
const n = Date.now();
|
366
|
-
e ?
|
367
|
-
const o = [],
|
380
|
+
e ? at.info("Generating CSS in production mode! 🔥") : at.info("Generating CSS in development mode! 🚀");
|
381
|
+
const o = [], i = [], c = await W(t), p = u(c, "index.css");
|
368
382
|
s && (() => {
|
369
|
-
|
383
|
+
ct(c) && _t("rm -rf " + c), v(c, { recursive: !0 }), v(u(c, "css")), v(u(c, "types")), v(u(c, "js")), v(u(c, "cache"));
|
370
384
|
})();
|
371
|
-
const
|
372
|
-
async function
|
373
|
-
const m = ["node_modules", "saltygen"],
|
374
|
-
if (
|
375
|
-
const
|
385
|
+
const a = /* @__PURE__ */ new Set(), $ = /* @__PURE__ */ new Set();
|
386
|
+
async function g(l) {
|
387
|
+
const m = ["node_modules", "saltygen"], w = Et(l);
|
388
|
+
if (w.isDirectory()) {
|
389
|
+
const f = Tt(l);
|
376
390
|
if (m.some((P) => l.includes(P))) return;
|
377
|
-
await Promise.all(
|
378
|
-
} else if (
|
379
|
-
|
380
|
-
const
|
381
|
-
/define[\w\d]+\(/.test(
|
391
|
+
await Promise.all(f.map((P) => g(u(l, P))));
|
392
|
+
} else if (w.isFile() && I(l)) {
|
393
|
+
a.add(l);
|
394
|
+
const j = V(l, "utf8");
|
395
|
+
/define[\w\d]+\(/.test(j) && $.add(l);
|
382
396
|
}
|
383
397
|
}
|
384
|
-
await
|
385
|
-
const
|
398
|
+
await g(t), await qt(t, $);
|
399
|
+
const r = {
|
386
400
|
keyframes: [],
|
387
401
|
components: [],
|
388
402
|
classNames: []
|
389
403
|
};
|
390
404
|
await Promise.all(
|
391
|
-
[...
|
392
|
-
const m = await
|
393
|
-
Object.entries(m).forEach(([
|
394
|
-
|
395
|
-
value:
|
405
|
+
[...a].map(async (l) => {
|
406
|
+
const { contents: m } = await st(t, l, c);
|
407
|
+
Object.entries(m).forEach(([w, f]) => {
|
408
|
+
f.isKeyframes ? r.keyframes.push({
|
409
|
+
value: f,
|
396
410
|
src: l,
|
397
|
-
name:
|
398
|
-
}) :
|
399
|
-
...
|
411
|
+
name: w
|
412
|
+
}) : f.isClassName ? r.classNames.push({
|
413
|
+
...f,
|
400
414
|
src: l,
|
401
|
-
name:
|
402
|
-
}) :
|
403
|
-
...
|
415
|
+
name: w
|
416
|
+
}) : f.generator && r.components.push({
|
417
|
+
...f,
|
404
418
|
src: l,
|
405
|
-
name:
|
419
|
+
name: w
|
406
420
|
});
|
407
421
|
});
|
408
422
|
})
|
409
423
|
);
|
410
|
-
const
|
411
|
-
for (const l of
|
412
|
-
const { value: m } = l,
|
413
|
-
o.push(
|
424
|
+
const d = await ut(t);
|
425
|
+
for (const l of r.keyframes) {
|
426
|
+
const { value: m } = l, w = `a_${m.animationName}.css`, f = `css/${w}`, j = u(c, f);
|
427
|
+
o.push(w), k(j, m.css);
|
414
428
|
}
|
415
|
-
const
|
416
|
-
for (const l of
|
417
|
-
const { src: m, name:
|
418
|
-
callerName:
|
429
|
+
const h = {};
|
430
|
+
for (const l of r.components) {
|
431
|
+
const { src: m, name: w } = l, f = l.generator._withBuildContext({
|
432
|
+
callerName: w,
|
419
433
|
isProduction: e,
|
420
|
-
config:
|
434
|
+
config: d
|
421
435
|
});
|
422
|
-
|
423
|
-
const
|
424
|
-
k(P,
|
436
|
+
i[f.priority] || (i[f.priority] = []), i[f.priority].push(f.cssFileName);
|
437
|
+
const j = `css/${f.cssFileName}`, P = u(c, j);
|
438
|
+
k(P, await f.css), d.importStrategy === "component" && (h[m] ? h[m].push(f.cssFileName) : h[m] = [f.cssFileName]);
|
425
439
|
}
|
426
|
-
for (const l of
|
427
|
-
const { src: m, name:
|
428
|
-
callerName:
|
440
|
+
for (const l of r.classNames) {
|
441
|
+
const { src: m, name: w } = l, f = l.generator._withBuildContext({
|
442
|
+
callerName: w,
|
429
443
|
isProduction: e,
|
430
|
-
config:
|
444
|
+
config: d
|
431
445
|
});
|
432
|
-
|
433
|
-
const
|
434
|
-
k(P,
|
446
|
+
i[0].push(f.cssFileName);
|
447
|
+
const j = `css/${f.cssFileName}`, P = u(c, j);
|
448
|
+
k(P, await f.css), d.importStrategy === "component" && (h[m] ? h[m].push(f.cssFileName) : h[m] = [f.cssFileName]);
|
435
449
|
}
|
436
|
-
|
437
|
-
const
|
438
|
-
`),
|
439
|
-
k(
|
450
|
+
d.importStrategy === "component" && Object.entries(h).forEach(([l, m]) => {
|
451
|
+
const w = m.map((G) => `@import url('./${G}');`).join(`
|
452
|
+
`), f = H(l, 6), j = et(l), P = M(j.name), B = u(c, `css/f_${P}-${f}.css`);
|
453
|
+
k(B, w);
|
440
454
|
});
|
441
|
-
const
|
455
|
+
const x = o.map((l) => `@import url('./css/${l}');`).join(`
|
442
456
|
`);
|
443
|
-
let
|
457
|
+
let S = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
444
458
|
|
445
459
|
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
446
460
|
try {
|
447
|
-
return
|
461
|
+
return V(u(c, "css", l), "utf8").length > 0;
|
448
462
|
} catch {
|
449
463
|
return !1;
|
450
464
|
}
|
451
465
|
}).map((l) => `@import url('./css/${l}');`).join(`
|
452
466
|
`)}
|
453
|
-
${
|
454
|
-
if (
|
455
|
-
const l =
|
456
|
-
const
|
467
|
+
${x}`;
|
468
|
+
if (d.importStrategy !== "component") {
|
469
|
+
const l = i.reduce((m, w, f) => {
|
470
|
+
const j = w.reduce((K, L) => {
|
457
471
|
var X;
|
458
|
-
const
|
459
|
-
return
|
460
|
-
/*start:${
|
461
|
-
${
|
462
|
-
/*end:${
|
472
|
+
const U = u(c, "css", L), nt = V(U, "utf8"), q = ((X = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : X.at(1)) || H(U, 6);
|
473
|
+
return K.includes(q) ? K : `${K}
|
474
|
+
/*start:${q}*/
|
475
|
+
${nt}
|
476
|
+
/*end:${q}*/
|
463
477
|
`;
|
464
|
-
}, ""), P = `l_${
|
478
|
+
}, ""), P = `l_${f}.css`, B = u(c, "css", P), G = `@layer l${f} { ${j}
|
465
479
|
}`;
|
466
|
-
return k(
|
480
|
+
return k(B, G), `${m}
|
467
481
|
@import url('./css/${P}');`;
|
468
482
|
}, "");
|
469
|
-
|
483
|
+
S += l;
|
470
484
|
}
|
471
|
-
k(
|
472
|
-
const
|
473
|
-
|
485
|
+
k(p, S);
|
486
|
+
const F = Date.now() - n, R = F < 200 ? "🔥" : F < 500 ? "🚀" : F < 1e3 ? "🎉" : F < 2e3 ? "🚗" : F < 5e3 ? "🤔" : "🥴";
|
487
|
+
at.info(`Generated CSS in ${F}ms! ${R}`);
|
474
488
|
} catch (n) {
|
475
489
|
console.error(n);
|
476
490
|
}
|
477
|
-
},
|
491
|
+
}, ee = async (t, e) => {
|
478
492
|
try {
|
479
|
-
const s = await
|
480
|
-
if (
|
481
|
-
const o = [],
|
482
|
-
|
483
|
-
if (
|
484
|
-
const
|
485
|
-
k(
|
493
|
+
const s = await W(t);
|
494
|
+
if (I(e)) {
|
495
|
+
const o = [], i = await ut(t), { contents: c } = await st(t, e, s);
|
496
|
+
for (const [p, y] of Object.entries(c)) {
|
497
|
+
if (y.isKeyframes && y.css) {
|
498
|
+
const d = `css/${`a_${y.animationName}.css`}`, h = u(s, d);
|
499
|
+
k(h, await y.css);
|
486
500
|
return;
|
487
501
|
}
|
488
|
-
if (
|
489
|
-
const
|
490
|
-
name:
|
502
|
+
if (y.isClassName) {
|
503
|
+
const r = y.factory._withBuildContext({
|
504
|
+
name: p
|
491
505
|
});
|
492
|
-
o[0].push(
|
493
|
-
const
|
494
|
-
k(
|
506
|
+
o[0].push(r.cssFileName);
|
507
|
+
const d = `css/${r.cssFileName}`, h = u(s, d);
|
508
|
+
k(h, await r.css);
|
495
509
|
}
|
496
|
-
if (!
|
497
|
-
const
|
498
|
-
name:
|
499
|
-
config:
|
500
|
-
}),
|
501
|
-
k(
|
502
|
-
}
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
510
|
+
if (!y.generator) return;
|
511
|
+
const a = y.generator._withBuildContext({
|
512
|
+
name: p,
|
513
|
+
config: i
|
514
|
+
}), $ = `css/${a.cssFileName}`, g = u(s, $);
|
515
|
+
k(g, await a.css), o[a.priority] || (o[a.priority] = []), o[a.priority].push(a.cssFileName);
|
516
|
+
}
|
517
|
+
if (i.importStrategy !== "component")
|
518
|
+
o.forEach((p, y) => {
|
519
|
+
const a = `l_${y}.css`, $ = u(s, "css", a);
|
520
|
+
let g = V($, "utf8");
|
521
|
+
p.forEach((r) => {
|
522
|
+
var D;
|
523
|
+
const d = u(s, "css", r), h = ((D = /.*-([^-]+)-\d+.css/.exec(r)) == null ? void 0 : D.at(1)) || H(d, 6);
|
524
|
+
if (!g.includes(h)) {
|
525
|
+
const N = V(d, "utf8"), T = `/*start:${h}*/
|
526
|
+
${N}
|
527
|
+
/*end:${h}*/
|
513
528
|
`;
|
514
|
-
|
515
|
-
${
|
529
|
+
g = `${g.replace(/\}$/, "")}
|
530
|
+
${T}
|
516
531
|
}`;
|
517
532
|
}
|
518
|
-
}), k(g
|
533
|
+
}), k($, g);
|
519
534
|
});
|
520
535
|
else {
|
521
|
-
const
|
522
|
-
`),
|
523
|
-
k(
|
536
|
+
const p = o.flat().map((r) => `@import url('./${r}');`).join(`
|
537
|
+
`), y = H(e, 6), a = et(e), $ = M(a.name), g = u(s, `css/f_${$}-${y}.css`);
|
538
|
+
k(g, p);
|
524
539
|
}
|
525
540
|
}
|
526
541
|
} catch (s) {
|
527
542
|
console.error(s);
|
528
543
|
}
|
529
|
-
},
|
544
|
+
}, se = async (t, e, s = kt()) => {
|
530
545
|
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:
|
546
|
+
const n = await W(t);
|
547
|
+
if (I(e)) {
|
548
|
+
const i = V(e, "utf8");
|
549
|
+
i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await Ot(e, i);
|
550
|
+
const p = await ut(t), { contents: y } = await st(t, e, n);
|
551
|
+
let a = i;
|
552
|
+
if (Object.entries(y).forEach(([$, g]) => {
|
553
|
+
var f;
|
554
|
+
if (g.isKeyframes || !g.generator) return;
|
555
|
+
const r = g.generator._withBuildContext({
|
556
|
+
name: $,
|
557
|
+
config: p,
|
543
558
|
prod: s
|
544
|
-
}),
|
545
|
-
if (!
|
546
|
-
const
|
547
|
-
if (!
|
548
|
-
const { index:
|
549
|
-
let
|
550
|
-
const
|
551
|
-
let
|
552
|
-
for (; !
|
553
|
-
const
|
554
|
-
|
559
|
+
}), d = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
|
560
|
+
if (!d) return console.error("Could not find the original declaration");
|
561
|
+
const h = (f = d.at(1)) == null ? void 0 : f.trim(), x = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(a);
|
562
|
+
if (!x) return console.error("Could not find the original declaration");
|
563
|
+
const { index: D } = x;
|
564
|
+
let N = !1;
|
565
|
+
const T = setTimeout(() => N = !0, 5e3);
|
566
|
+
let S = 0, _ = !1, F = 0;
|
567
|
+
for (; !_ && !N; ) {
|
568
|
+
const j = a[D + S];
|
569
|
+
j === "(" && F++, j === ")" && F--, F === 0 && j === ")" && (_ = !0), S > a.length && (N = !0), S++;
|
555
570
|
}
|
556
|
-
if (!
|
571
|
+
if (!N) clearTimeout(T);
|
557
572
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
558
|
-
const
|
559
|
-
|
560
|
-
}),
|
561
|
-
const
|
562
|
-
|
563
|
-
${
|
573
|
+
const R = D + S, l = a.slice(D, R), m = a, w = ` ${$} = styled(${h}, "${r.classNames}", ${JSON.stringify(r.clientProps)});`;
|
574
|
+
a = a.replace(l, w), m === a && console.error("Minimize file failed to change content", { name: $, tagName: h });
|
575
|
+
}), p.importStrategy === "component") {
|
576
|
+
const $ = H(e, 6), g = et(e);
|
577
|
+
a = `import '../../saltygen/css/${`f_${M(g.name)}-${$}.css`}';
|
578
|
+
${a}`;
|
564
579
|
}
|
565
|
-
return
|
580
|
+
return a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
|
566
581
|
}
|
567
582
|
} catch (n) {
|
568
583
|
console.error("Error in minimizeFile:", n);
|
569
584
|
}
|
570
|
-
},
|
585
|
+
}, yt = async (t) => {
|
571
586
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
572
587
|
if (t.includes("salty.config")) return !0;
|
573
|
-
if (!
|
574
|
-
const n = await
|
588
|
+
if (!I(t)) return !1;
|
589
|
+
const n = await lt(t, "utf-8");
|
575
590
|
return !!/.+define[A-Z]\w+/.test(n);
|
576
|
-
},
|
591
|
+
}, ce = (t) => ({
|
577
592
|
name: "stylegen",
|
578
|
-
buildStart: () =>
|
593
|
+
buildStart: () => te(t),
|
579
594
|
load: async (e) => {
|
580
|
-
if (
|
581
|
-
return await
|
595
|
+
if (I(e))
|
596
|
+
return await se(t, e);
|
582
597
|
},
|
583
598
|
handleHotUpdate: async ({ file: e, server: s }) => {
|
584
|
-
await
|
599
|
+
await yt(e) && await s.restart();
|
585
600
|
},
|
586
601
|
watchChange: {
|
587
602
|
handler: async (e) => {
|
588
|
-
|
603
|
+
I(e) && (await yt(e) || await ee(t, e));
|
589
604
|
}
|
590
605
|
}
|
591
606
|
});
|
592
607
|
export {
|
593
|
-
|
594
|
-
|
608
|
+
ce as default,
|
609
|
+
ce as saltyPlugin
|
595
610
|
};
|
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.203",
|
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.203"
|
38
38
|
}
|
39
39
|
}
|