@salty-css/vite 0.0.1-alpha.143 → 0.0.1-alpha.145
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 +20 -21
- package/index.js +196 -197
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,37 +1,36 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const pt=require("esbuild"),dt=require("child_process"),
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const pt=require("esbuild"),dt=require("child_process"),a=require("path"),f=require("fs"),X=require("fs/promises"),J=require("winston");var Z=typeof document<"u"?document.currentScript:null;function yt(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 Y=yt(pt),U=t=>String.fromCharCode(t+(t>25?39:97)),gt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=U(n%52)+s;return s=U(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},mt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},W=(t,e=5)=>{const s=mt(5381,JSON.stringify(t))>>>0;return gt(s,e)};function V(t){return t?typeof t!="string"?V(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const ht=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:i,transform:r}=n;t=t.replace(i,u=>{const{value:p,css:c}=r(u);return c&&s.push(c),p})}),{result:t,additionalCss:s}},Q=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V(n[1].replaceAll(".","-"))})`)}:{result:t},M=(t,e,s)=>{if(!t)return"";const n=[],i=Object.entries(t).reduce((u,[p,c])=>{const o=p.trim();if(typeof c=="function"&&(c=c()),typeof c=="object"){if(!c)return u;if(o==="variants")return Object.entries(c).forEach(([l,m])=>{m&&Object.entries(m).forEach(([N,w])=>{if(!w)return;const T=`${e}.${l}-${N}`,k=M(w,T);n.push(k)})}),u;if(o==="defaultVariants")return u;if(o==="compoundVariants")return c.forEach(l=>{const{css:m,...N}=l,w=Object.entries(N).reduce((k,[d,h])=>`${k}.${d}-${h}`,e),T=M(m,w);n.push(T)}),u;if(o.startsWith("@")){const l=M(c,e),m=`${o} {
|
2
|
+
${l.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return n.push(m),
|
5
|
+
}`;return n.push(m),u}const y=p.includes("&")?o.replace("&",e):o.startsWith(":")?`${e}${o}`:`${e} ${o}`,j=M(c,y);return n.push(j),u}const g=o.startsWith("-")?o:V(o),$=(y,j=";")=>u=`${u}${y}${j}`,C=y=>$(`${g}:${y}`);if(typeof c=="number")return C(c);if(typeof c!="string")if("toString"in c)c=c.toString();else return u;const{modifiers:x}={},D=function*(){yield Q(c),yield ht(c,x)}();for(const{result:y,additionalCss:j=[]}of D)c=y,j.forEach(l=>{const m=M(l,"");$(m,"")});return C(c)},"");return i?e?[`${e} { ${i} }`,...n].join(`
|
6
6
|
`):i:n.join(`
|
7
|
-
`)},v=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([i,
|
8
|
-
`)},$t=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=tt(n).map(i=>`"${i}"`).join(" | ")),e),{}),tt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const
|
7
|
+
`)},v=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([i,r])=>{if(typeof r=="object"){if(!r)return;const u=i.trim(),p=v(r,[...e,u]);s.push(p)}else n[i]=r}),Object.keys(n).length){const i=e.map(V).join("-"),r=M(n,`.${i}`);s.push(r)}return s.join(`
|
8
|
+
`)},$t=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=tt(n).map(i=>`"${i}"`).join(" | ")),e),{}),tt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const r=e?`${e}.${n}`:n;return typeof i=="object"?tt(i,r,s):s.add(e)}),[...s]):[],et=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=a.join(t,"package.json");return f.existsSync(e)?e:et(a.join(t,".."))},St=async t=>{const e=et(t);return await X.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},bt=async t=>{const e=await St(t);if(e)return e.type};let A;const st=async t=>{if(A)return A;const e=await bt(t);return e==="module"?A="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Z&&Z.tagName.toUpperCase()==="SCRIPT"&&Z.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},H=J.createLogger({level:"debug",format:J.format.combine(J.format.colorize(),J.format.cli()),transports:[new J.transports.Console({})]});function nt(t){return t?typeof t!="string"?nt(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 jt={"*, *::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"}},q={externalModules:[]},ot=t=>{if(q.externalModules.length>0)return q.externalModules;const e=a.join(t,"salty.config.ts"),n=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const i=n[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return q.externalModules=i,i},I=t=>a.join(t,"./saltygen"),rt=["salty","css","styles","styled"],wt=(t=[])=>new RegExp(`\\.(${[...rt,...t].join("|")})\\.`),z=(t,e=[])=>wt(e).test(t),Ft=async t=>{const e=I(t),s=a.join(t,"salty.config.ts"),n=a.join(e,"salty.config.js"),i=await st(t),r=ot(t);await Y.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:i,external:r});const u=Date.now(),{config:p}=await import(`${n}?t=${u}`);return p},Ct=async t=>{const e=await Ft(t),s=new Set,n=(d,h=[])=>d?Object.entries(d).flatMap(([F,S])=>{if(!S)return;if(typeof S=="object")return n(S,[...h,F]);const E=nt(F),R=V(F),_=[...h,E].join(".");s.add(`"${_}"`);const P=[...h.map(V),R].join("-"),{result:O}=Q(S);return`--${P}: ${O};`}):[],i=d=>d?Object.entries(d).flatMap(([h,F])=>{const S=n(F);return h==="base"?S.join(""):`${h} { ${S.join("")} }`}):[],r=d=>d?Object.entries(d).flatMap(([h,F])=>Object.entries(F).flatMap(([S,E])=>{const R=n(E,[h]),_=`.${h}-${S}, [data-${h}="${S}"]`,P=R.join("");return`${_} { ${P} }`})):[],u=n(e.variables),p=i(e.responsiveVariables),c=r(e.conditionalVariables),o=I(t),g=a.join(o,"css/_variables.css"),$=`:root { ${u.join("")} ${p.join("")} } ${c.join("")}`;f.writeFileSync(g,$);const C=a.join(o,"css/_global.css"),x=M(e.global,"");f.writeFileSync(C,`@layer global { ${x} }`);const b=a.join(o,"css/_reset.css"),y=e.reset==="none"?{}:typeof e.reset=="object"?e.reset:jt,j=M(y,"");f.writeFileSync(b,`@layer reset { ${j} }`);const l=a.join(o,"css/_templates.css"),m=v(e.templates),N=$t(e.templates);f.writeFileSync(l,m);const w=a.join(o,"types/css-tokens.d.ts"),k=`
|
9
9
|
// Variable types
|
10
10
|
type VariableTokens = ${[...s].join("|")};
|
11
11
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
12
|
|
13
13
|
// Template types
|
14
14
|
type TemplateTokens = {
|
15
|
-
${Object.entries(
|
15
|
+
${Object.entries(N).map(([d,h])=>`${d}?: ${h}`).join(`
|
16
16
|
`)}
|
17
17
|
}
|
18
|
-
`;
|
19
|
-
`),
|
20
|
-
`);let
|
18
|
+
`;f.writeFileSync(w,k)},G=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(t))return e;const u=i.exec(t);if(u){const p=u.at(1);if(rt.some(o=>p==null?void 0:p.includes(o)))return e}return"styled('div',"}),L=async(t,e,s)=>{const n=W(e),i=a.join(s,"./temp");f.existsSync(i)||f.mkdirSync(i);const r=a.parse(e);let u=f.readFileSync(e,"utf8");u=G(u);const p=a.join(s,"js",n+".js"),c=ot(t),o=await st(t);await Y.build({stdin:{contents:u,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:o,target:["node20"],keepNames:!0,external:c,packages:"external",plugins:[{name:"test",setup:C=>{C.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},x=>{const b=f.readFileSync(x.path,"utf8");return{contents:G(b),loader:"ts"}})}}]});const g=Date.now();return await import(`${p}?t=${g}`)},B=async t=>{const e=I(t),s=a.join(e,"salty.config.js"),n=Date.now(),{config:i}=await import(`${s}?t=${n}`);return i},it=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},xt=async(t,e=it())=>{try{const s=Date.now();e?H.info("Generating CSS in production mode! 🔥"):H.info("Generating CSS in development mode! 🚀");const n=[],i=[],r=I(t),u=a.join(r,"index.css");(()=>{f.existsSync(r)&&dt.execSync("rm -rf "+r),f.mkdirSync(r),f.mkdirSync(a.join(r,"css")),f.mkdirSync(a.join(r,"types"))})(),await Ct(t);const c=await B(t);async function o(l,m){const N=["node_modules","saltygen"],w=f.statSync(l);if(w.isDirectory()){const T=f.readdirSync(l);if(N.some(d=>l.includes(d)))return;await Promise.all(T.map(d=>o(a.join(l,d),a.join(m,d))))}else if(w.isFile()&&z(l)){const k=await L(t,l,r),d=[];Object.entries(k).forEach(([_,P])=>{if(P.isKeyframes&&P.css){const K=`a_${P.animationName}.css`,ft=`css/${K}`,ut=a.join(r,ft);n.push(K),f.writeFileSync(ut,P.css);return}if(!P.generator)return;const O=P.generator._withBuildContext({name:_,config:c,prod:e});i[O.priority]||(i[O.priority]=[]),i[O.priority].push(O.cssFileName),d.push(O.cssFileName);const at=`css/${O.cssFileName}`,lt=a.join(r,at);f.writeFileSync(lt,O.css)});const h=d.map(_=>`@import url('./${_}');`).join(`
|
19
|
+
`),F=W(l,6),S=a.parse(l),E=V(S.name),R=a.join(r,`css/f_${E}-${F}.css`);f.writeFileSync(R,h)}}await o(t,r);const g=n.map(l=>`@import url('./css/${l}');`).join(`
|
20
|
+
`);let b=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
21
|
|
22
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(
|
22
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return f.readFileSync(a.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
23
23
|
`)}
|
24
|
-
${
|
24
|
+
${g}`;if(c.importStrategy!=="component"){const l=i.reduce((m,N,w)=>{const T=N.reduce((F,S)=>{var P;const E=a.join(r,"css",S),R=f.readFileSync(E,"utf8"),_=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||W(E,6);return F.includes(_)?F:`${F}
|
25
25
|
/*start:${_}*/
|
26
26
|
${R}
|
27
27
|
/*end:${_}*/
|
28
|
-
`},""),
|
29
|
-
}`;return
|
30
|
-
@import url('./css/${
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
${x}
|
36
|
-
}`}
|
37
|
-
${r}`}return r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(n){console.error("Error in minimizeFile:",n)}},ct=t=>({name:"stylegen",buildStart:()=>xt(t),load:async e=>{if(z(e))return await Pt(t,e)},handleHotUpdate:async({file:e,server:s})=>{e.includes("salty.config")&&await s.restart()},watchChange:{handler:async e=>{z(e)&&await kt(t,e)}}});exports.default=ct;exports.saltyPlugin=ct;
|
28
|
+
`},""),k=`l_${w}.css`,d=a.join(r,"css",k),h=`@layer l${w} { ${T}
|
29
|
+
}`;return f.writeFileSync(d,h),`${m}
|
30
|
+
@import url('./css/${k}');`},"");b+=l}f.writeFileSync(u,b);const y=Date.now()-s,j=y<200?"🔥":y<500?"🚀":y<1e3?"🎉":y<2e3?"🚗":y<5e3?"🤔":"🥴";H.info(`Generated CSS in ${y}ms! ${j}`)}catch(s){console.error(s)}},kt=async(t,e)=>{try{const s=a.join(t,"./saltygen");if(z(e)){const i=[],r=await B(t),u=await L(t,e,s);Object.entries(u).forEach(([p,c])=>{if(c.isKeyframes&&c.css){const x=`css/${`a_${c.animationName}.css`}`,b=a.join(s,x);f.writeFileSync(b,c.css);return}if(!c.generator)return;const o=c.generator._withBuildContext({name:p,config:r}),g=`css/${o.cssFileName}`,$=a.join(s,g);f.writeFileSync($,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),r.importStrategy!=="component"&&i.forEach((p,c)=>{const o=`l_${c}.css`,g=a.join(s,"css",o);let $=f.readFileSync(g,"utf8");p.forEach(C=>{var y;const x=a.join(s,"css",C),b=((y=/.*-([^-]+)-\d+.css/.exec(C))==null?void 0:y.at(1))||W(x,6);if(!$.includes(b)){const j=f.readFileSync(x,"utf8"),l=`/*start:${b}*/
|
31
|
+
${j}
|
32
|
+
/*end:${b}*/
|
33
|
+
`;$=`${$.replace(/\}$/,"")}
|
34
|
+
${l}
|
35
|
+
}`}}),f.writeFileSync(g,$)})}}catch(s){console.error(s)}},Pt=async(t,e,s=it())=>{try{const n=a.join(t,"./saltygen");if(z(e)){const r=f.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==r&&await X.writeFile(e,r);const p=await B(t),c=await L(t,e,n);let o=r;if(Object.entries(c).forEach(([g,$])=>{var F;if($.isKeyframes||!$.generator)return;const C=$.generator._withBuildContext({name:g,config:p,prod:s}),x=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!x)return console.error("Could not find the original declaration");const b=(F=x.at(1))==null?void 0:F.trim(),D=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(o);if(!D)return console.error("Could not find the original declaration");const{index:y}=D;let j=!1;const l=setTimeout(()=>j=!0,5e3);let m=0,N=!1,w=0;for(;!N&&!j;){const S=o[y+m];S==="("&&w++,S===")"&&w--,w===0&&S===")"&&(N=!0),m>o.length&&(j=!0),m++}if(!j)clearTimeout(l);else throw new Error("Failed to find the end of the styled call and timed out");const T=y+m,k=o.slice(y,T),d=o,h=` ${g} = styled(${b}, "${C.classNames}", ${JSON.stringify(C.props)});`;o=o.replace(k,h),d===o&&console.error("Minimize file failed to change content",{name:g,tagName:b})}),p.importStrategy==="component"){const g=W(e,6),$=a.parse(e);o=`import '../../saltygen/css/${`f_${V($.name)}-${g}.css`}';
|
36
|
+
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}},ct=t=>({name:"stylegen",buildStart:()=>xt(t),load:async e=>{if(z(e))return await Pt(t,e)},handleHotUpdate:async({file:e,server:s})=>{e.includes("salty.config")&&await s.restart()},watchChange:{handler:async e=>{z(e)&&await kt(t,e)}}});exports.default=ct;exports.saltyPlugin=ct;
|
package/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as v from "esbuild";
|
2
2
|
import { execSync as dt } from "child_process";
|
3
3
|
import { join as a, parse as K } from "path";
|
4
|
-
import { existsSync as G, mkdirSync as
|
4
|
+
import { existsSync as G, mkdirSync as Z, statSync as gt, readdirSync as yt, writeFileSync as N, readFileSync as M } from "fs";
|
5
5
|
import { readFile as mt, writeFile as ht } from "fs/promises";
|
6
6
|
import { createLogger as $t, format as I, transports as bt } from "winston";
|
7
7
|
const Y = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), St = (t, e) => {
|
@@ -24,58 +24,58 @@ const jt = (t, e) => {
|
|
24
24
|
if (!e) return { result: t };
|
25
25
|
const s = [];
|
26
26
|
return Object.values(e).forEach((n) => {
|
27
|
-
const { pattern: i, transform:
|
28
|
-
t = t.replace(i, (
|
29
|
-
const { value:
|
30
|
-
return c && s.push(c),
|
27
|
+
const { pattern: i, transform: r } = n;
|
28
|
+
t = t.replace(i, (f) => {
|
29
|
+
const { value: p, css: c } = r(f);
|
30
|
+
return c && s.push(c), p;
|
31
31
|
});
|
32
32
|
}), { result: t, additionalCss: s };
|
33
|
-
}, tt = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${A(n[1].replaceAll(".", "-"))})`) } : { result: t },
|
33
|
+
}, tt = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${A(n[1].replaceAll(".", "-"))})`) } : { result: t }, _ = (t, e, s) => {
|
34
34
|
if (!t) return "";
|
35
|
-
const n = [], i = Object.entries(t).reduce((
|
36
|
-
const
|
35
|
+
const n = [], i = Object.entries(t).reduce((f, [p, c]) => {
|
36
|
+
const o = p.trim();
|
37
37
|
if (typeof c == "function" && (c = c()), typeof c == "object") {
|
38
|
-
if (!c) return
|
39
|
-
if (
|
40
|
-
return Object.entries(c).forEach(([
|
41
|
-
y && Object.entries(y).forEach(([
|
42
|
-
if (!
|
43
|
-
const T = `${e}.${
|
44
|
-
n.push(
|
38
|
+
if (!c) return f;
|
39
|
+
if (o === "variants")
|
40
|
+
return Object.entries(c).forEach(([l, y]) => {
|
41
|
+
y && Object.entries(y).forEach(([P, w]) => {
|
42
|
+
if (!w) return;
|
43
|
+
const T = `${e}.${l}-${P}`, C = _(w, T);
|
44
|
+
n.push(C);
|
45
45
|
});
|
46
|
-
}),
|
47
|
-
if (
|
48
|
-
return
|
49
|
-
if (
|
50
|
-
return c.forEach((
|
51
|
-
const { css: y, ...
|
46
|
+
}), f;
|
47
|
+
if (o === "defaultVariants")
|
48
|
+
return f;
|
49
|
+
if (o === "compoundVariants")
|
50
|
+
return c.forEach((l) => {
|
51
|
+
const { css: y, ...P } = l, w = Object.entries(P).reduce((C, [u, m]) => `${C}.${u}-${m}`, e), T = _(y, w);
|
52
52
|
n.push(T);
|
53
|
-
}),
|
54
|
-
if (
|
55
|
-
const
|
56
|
-
${
|
53
|
+
}), f;
|
54
|
+
if (o.startsWith("@")) {
|
55
|
+
const l = _(c, e), y = `${o} {
|
56
|
+
${l.replace(`
|
57
57
|
`, `
|
58
58
|
`)}
|
59
59
|
}`;
|
60
|
-
return n.push(y),
|
60
|
+
return n.push(y), f;
|
61
61
|
}
|
62
|
-
const
|
63
|
-
return n.push(S),
|
62
|
+
const d = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, S = _(c, d);
|
63
|
+
return n.push(S), f;
|
64
64
|
}
|
65
|
-
const
|
66
|
-
if (typeof c == "number") return
|
65
|
+
const g = o.startsWith("-") ? o : A(o), h = (d, S = ";") => f = `${f}${d}${S}`, F = (d) => h(`${g}:${d}`);
|
66
|
+
if (typeof c == "number") return F(c);
|
67
67
|
if (typeof c != "string")
|
68
68
|
if ("toString" in c) c = c.toString();
|
69
|
-
else return
|
70
|
-
const { modifiers:
|
71
|
-
yield tt(c), yield jt(c,
|
69
|
+
else return f;
|
70
|
+
const { modifiers: x } = {}, O = function* () {
|
71
|
+
yield tt(c), yield jt(c, x);
|
72
72
|
}();
|
73
|
-
for (const { result:
|
74
|
-
c =
|
75
|
-
const y =
|
76
|
-
|
73
|
+
for (const { result: d, additionalCss: S = [] } of O)
|
74
|
+
c = d, S.forEach((l) => {
|
75
|
+
const y = _(l, "");
|
76
|
+
h(y, "");
|
77
77
|
});
|
78
|
-
return
|
78
|
+
return F(c);
|
79
79
|
}, "");
|
80
80
|
return i ? e ? [`${e} { ${i} }`, ...n].join(`
|
81
81
|
`) : i : n.join(`
|
@@ -83,39 +83,39 @@ const jt = (t, e) => {
|
|
83
83
|
}, et = (t, e = []) => {
|
84
84
|
if (!t) return "";
|
85
85
|
const s = [], n = {};
|
86
|
-
if (Object.entries(t).forEach(([i,
|
87
|
-
if (typeof
|
88
|
-
if (!
|
89
|
-
const
|
90
|
-
s.push(
|
86
|
+
if (Object.entries(t).forEach(([i, r]) => {
|
87
|
+
if (typeof r == "object") {
|
88
|
+
if (!r) return;
|
89
|
+
const f = i.trim(), p = et(r, [...e, f]);
|
90
|
+
s.push(p);
|
91
91
|
} else
|
92
|
-
n[i] =
|
92
|
+
n[i] = r;
|
93
93
|
}), Object.keys(n).length) {
|
94
|
-
const i = e.map(A).join("-"),
|
95
|
-
s.push(
|
94
|
+
const i = e.map(A).join("-"), r = _(n, `.${i}`);
|
95
|
+
s.push(r);
|
96
96
|
}
|
97
97
|
return s.join(`
|
98
98
|
`);
|
99
99
|
}, Ft = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = st(n).map((i) => `"${i}"`).join(" | ")), e), {}), st = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
|
100
|
-
const
|
101
|
-
return typeof i == "object" ? st(i,
|
100
|
+
const r = e ? `${e}.${n}` : n;
|
101
|
+
return typeof i == "object" ? st(i, r, s) : s.add(e);
|
102
102
|
}), [...s]) : [], nt = (t) => {
|
103
103
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
104
|
const e = a(t, "package.json");
|
105
105
|
return G(e) ? e : nt(a(t, ".."));
|
106
|
-
},
|
106
|
+
}, xt = async (t) => {
|
107
107
|
const e = nt(t);
|
108
108
|
return await mt(e, "utf-8").then(JSON.parse).catch(() => {
|
109
109
|
});
|
110
|
-
},
|
111
|
-
const e = await
|
110
|
+
}, Ct = async (t) => {
|
111
|
+
const e = await xt(t);
|
112
112
|
if (e)
|
113
113
|
return e.type;
|
114
114
|
};
|
115
115
|
let J;
|
116
116
|
const ot = async (t) => {
|
117
117
|
if (J) return J;
|
118
|
-
const e = await
|
118
|
+
const e = await Ct(t);
|
119
119
|
return e === "module" ? J = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (J = "cjs"), J || "esm";
|
120
120
|
}, L = $t({
|
121
121
|
level: "debug",
|
@@ -175,12 +175,12 @@ const kt = {
|
|
175
175
|
externalModules: []
|
176
176
|
}, it = (t) => {
|
177
177
|
if (B.externalModules.length > 0) return B.externalModules;
|
178
|
-
const e = a(t, "salty.config.ts"), n =
|
178
|
+
const e = a(t, "salty.config.ts"), n = M(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
179
179
|
if (!n) return [];
|
180
|
-
const i = n[1].split(",").map((
|
180
|
+
const i = n[1].split(",").map((r) => r.replace(/['"`]/g, "").trim());
|
181
181
|
return B.externalModules = i, i;
|
182
|
-
},
|
183
|
-
const e =
|
182
|
+
}, H = (t) => a(t, "./saltygen"), ct = ["salty", "css", "styles", "styled"], Nt = (t = []) => new RegExp(`\\.(${[...ct, ...t].join("|")})\\.`), z = (t, e = []) => Nt(e).test(t), Pt = async (t) => {
|
183
|
+
const e = H(t), s = a(t, "salty.config.ts"), n = a(e, "salty.config.js"), i = await ot(t), r = it(t);
|
184
184
|
await v.build({
|
185
185
|
entryPoints: [s],
|
186
186
|
minify: !0,
|
@@ -188,73 +188,73 @@ const kt = {
|
|
188
188
|
bundle: !0,
|
189
189
|
outfile: n,
|
190
190
|
format: i,
|
191
|
-
external:
|
191
|
+
external: r
|
192
192
|
});
|
193
|
-
const
|
194
|
-
return
|
193
|
+
const f = Date.now(), { config: p } = await import(`${n}?t=${f}`);
|
194
|
+
return p;
|
195
195
|
}, Tt = async (t) => {
|
196
|
-
const e = await Pt(t), s = /* @__PURE__ */ new Set(), n = (
|
196
|
+
const e = await Pt(t), s = /* @__PURE__ */ new Set(), n = (u, m = []) => u ? Object.entries(u).flatMap(([j, $]) => {
|
197
197
|
if (!$) return;
|
198
|
-
if (typeof $ == "object") return n($, [...
|
199
|
-
const
|
198
|
+
if (typeof $ == "object") return n($, [...m, j]);
|
199
|
+
const V = rt(j), R = A(j), E = [...m, V].join(".");
|
200
200
|
s.add(`"${E}"`);
|
201
|
-
const
|
202
|
-
return `--${
|
203
|
-
}) : [], i = (
|
204
|
-
const $ = n(
|
205
|
-
return
|
206
|
-
}) : [],
|
207
|
-
const R = n(
|
208
|
-
return `${E} { ${
|
209
|
-
})) : [],
|
210
|
-
|
211
|
-
const
|
212
|
-
|
213
|
-
const
|
214
|
-
|
215
|
-
const
|
216
|
-
|
217
|
-
const
|
201
|
+
const k = [...m.map(A), R].join("-"), { result: D } = tt($);
|
202
|
+
return `--${k}: ${D};`;
|
203
|
+
}) : [], i = (u) => u ? Object.entries(u).flatMap(([m, j]) => {
|
204
|
+
const $ = n(j);
|
205
|
+
return m === "base" ? $.join("") : `${m} { ${$.join("")} }`;
|
206
|
+
}) : [], r = (u) => u ? Object.entries(u).flatMap(([m, j]) => Object.entries(j).flatMap(([$, V]) => {
|
207
|
+
const R = n(V, [m]), E = `.${m}-${$}, [data-${m}="${$}"]`, k = R.join("");
|
208
|
+
return `${E} { ${k} }`;
|
209
|
+
})) : [], f = n(e.variables), p = i(e.responsiveVariables), c = r(e.conditionalVariables), o = H(t), g = a(o, "css/_variables.css"), h = `:root { ${f.join("")} ${p.join("")} } ${c.join("")}`;
|
210
|
+
N(g, h);
|
211
|
+
const F = a(o, "css/_global.css"), x = _(e.global, "");
|
212
|
+
N(F, `@layer global { ${x} }`);
|
213
|
+
const b = a(o, "css/_reset.css"), d = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : kt, S = _(d, "");
|
214
|
+
N(b, `@layer reset { ${S} }`);
|
215
|
+
const l = a(o, "css/_templates.css"), y = et(e.templates), P = Ft(e.templates);
|
216
|
+
N(l, y);
|
217
|
+
const w = a(o, "types/css-tokens.d.ts"), C = `
|
218
218
|
// Variable types
|
219
219
|
type VariableTokens = ${[...s].join("|")};
|
220
220
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
221
221
|
|
222
222
|
// Template types
|
223
223
|
type TemplateTokens = {
|
224
|
-
${Object.entries(
|
224
|
+
${Object.entries(P).map(([u, m]) => `${u}?: ${m}`).join(`
|
225
225
|
`)}
|
226
226
|
}
|
227
227
|
`;
|
228
|
-
|
228
|
+
N(w, C);
|
229
229
|
}, Q = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
230
230
|
if (/^['"`]/.test(s)) return e;
|
231
231
|
const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
232
232
|
if (!i.test(t)) return e;
|
233
|
-
const
|
234
|
-
if (
|
235
|
-
const
|
236
|
-
if (ct.some((
|
233
|
+
const f = i.exec(t);
|
234
|
+
if (f) {
|
235
|
+
const p = f.at(1);
|
236
|
+
if (ct.some((o) => p == null ? void 0 : p.includes(o))) return e;
|
237
237
|
}
|
238
238
|
return "styled('div',";
|
239
239
|
}), q = async (t, e, s) => {
|
240
240
|
const n = W(e), i = a(s, "./temp");
|
241
|
-
G(i) ||
|
242
|
-
const
|
243
|
-
let
|
244
|
-
|
245
|
-
const
|
241
|
+
G(i) || Z(i);
|
242
|
+
const r = K(e);
|
243
|
+
let f = M(e, "utf8");
|
244
|
+
f = Q(f);
|
245
|
+
const p = a(s, "js", n + ".js"), c = it(t), o = await ot(t);
|
246
246
|
await v.build({
|
247
247
|
stdin: {
|
248
|
-
contents:
|
249
|
-
sourcefile:
|
250
|
-
resolveDir:
|
248
|
+
contents: f,
|
249
|
+
sourcefile: r.base,
|
250
|
+
resolveDir: r.dir,
|
251
251
|
loader: "tsx"
|
252
252
|
},
|
253
253
|
minify: !1,
|
254
254
|
treeShaking: !0,
|
255
255
|
bundle: !0,
|
256
|
-
outfile:
|
257
|
-
format:
|
256
|
+
outfile: p,
|
257
|
+
format: o,
|
258
258
|
target: ["node20"],
|
259
259
|
keepNames: !0,
|
260
260
|
external: c,
|
@@ -262,19 +262,19 @@ const kt = {
|
|
262
262
|
plugins: [
|
263
263
|
{
|
264
264
|
name: "test",
|
265
|
-
setup: (
|
266
|
-
|
267
|
-
const
|
268
|
-
return { contents: Q(
|
265
|
+
setup: (F) => {
|
266
|
+
F.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (x) => {
|
267
|
+
const b = M(x.path, "utf8");
|
268
|
+
return { contents: Q(b), loader: "ts" };
|
269
269
|
});
|
270
270
|
}
|
271
271
|
}
|
272
272
|
]
|
273
273
|
});
|
274
|
-
const
|
275
|
-
return await import(`${
|
274
|
+
const g = Date.now();
|
275
|
+
return await import(`${p}?t=${g}`);
|
276
276
|
}, U = async (t) => {
|
277
|
-
const e =
|
277
|
+
const e = H(t), s = a(e, "salty.config.js"), n = Date.now(), { config: i } = await import(`${s}?t=${n}`);
|
278
278
|
return i;
|
279
279
|
}, at = () => {
|
280
280
|
try {
|
@@ -286,111 +286,110 @@ const kt = {
|
|
286
286
|
try {
|
287
287
|
const s = Date.now();
|
288
288
|
e ? L.info("Generating CSS in production mode! 🔥") : L.info("Generating CSS in development mode! 🚀");
|
289
|
-
const n = [], i = [],
|
289
|
+
const n = [], i = [], r = H(t), f = a(r, "index.css");
|
290
290
|
(() => {
|
291
|
-
G(
|
291
|
+
G(r) && dt("rm -rf " + r), Z(r), Z(a(r, "css")), Z(a(r, "types"));
|
292
292
|
})(), await Tt(t);
|
293
293
|
const c = await U(t);
|
294
|
-
async function
|
295
|
-
const
|
296
|
-
if (
|
297
|
-
const T = yt(
|
298
|
-
if (
|
299
|
-
await Promise.all(T.map((
|
300
|
-
} else if (
|
301
|
-
const
|
302
|
-
Object.entries(
|
303
|
-
if (
|
304
|
-
const X = `a_${
|
305
|
-
n.push(X),
|
294
|
+
async function o(l, y) {
|
295
|
+
const P = ["node_modules", "saltygen"], w = gt(l);
|
296
|
+
if (w.isDirectory()) {
|
297
|
+
const T = yt(l);
|
298
|
+
if (P.some((u) => l.includes(u))) return;
|
299
|
+
await Promise.all(T.map((u) => o(a(l, u), a(y, u))));
|
300
|
+
} else if (w.isFile() && z(l)) {
|
301
|
+
const C = await q(t, l, r), u = [];
|
302
|
+
Object.entries(C).forEach(([E, k]) => {
|
303
|
+
if (k.isKeyframes && k.css) {
|
304
|
+
const X = `a_${k.animationName}.css`, pt = `css/${X}`, ut = a(r, pt);
|
305
|
+
n.push(X), N(ut, k.css);
|
306
306
|
return;
|
307
307
|
}
|
308
|
-
if (!
|
309
|
-
const
|
308
|
+
if (!k.generator) return;
|
309
|
+
const D = k.generator._withBuildContext({
|
310
310
|
name: E,
|
311
311
|
config: c,
|
312
312
|
prod: e
|
313
313
|
});
|
314
|
-
i[
|
315
|
-
const lt = `css/${
|
316
|
-
|
314
|
+
i[D.priority] || (i[D.priority] = []), i[D.priority].push(D.cssFileName), u.push(D.cssFileName);
|
315
|
+
const lt = `css/${D.cssFileName}`, ft = a(r, lt);
|
316
|
+
N(ft, D.css);
|
317
317
|
});
|
318
|
-
const
|
319
|
-
`),
|
320
|
-
|
318
|
+
const m = u.map((E) => `@import url('./${E}');`).join(`
|
319
|
+
`), j = W(l, 6), $ = K(l), V = A($.name), R = a(r, `css/f_${V}-${j}.css`);
|
320
|
+
N(R, m);
|
321
321
|
}
|
322
322
|
}
|
323
|
-
await
|
324
|
-
const
|
323
|
+
await o(t, r);
|
324
|
+
const g = n.map((l) => `@import url('./css/${l}');`).join(`
|
325
325
|
`);
|
326
|
-
let
|
326
|
+
let b = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
327
327
|
|
328
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((
|
328
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
329
329
|
try {
|
330
|
-
return
|
330
|
+
return M(a(r, "css", l), "utf8").length > 0;
|
331
331
|
} catch {
|
332
332
|
return !1;
|
333
333
|
}
|
334
|
-
}).map((
|
334
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
335
335
|
`)}
|
336
|
-
${
|
336
|
+
${g}`;
|
337
337
|
if (c.importStrategy !== "component") {
|
338
|
-
const
|
339
|
-
const T =
|
340
|
-
|
341
|
-
|
338
|
+
const l = i.reduce((y, P, w) => {
|
339
|
+
const T = P.reduce((j, $) => {
|
340
|
+
var k;
|
341
|
+
const V = a(r, "css", $), R = M(V, "utf8"), E = ((k = /.*-([^-]+)-\d+.css/.exec($)) == null ? void 0 : k.at(1)) || W(V, 6);
|
342
|
+
return j.includes(E) ? j : `${j}
|
342
343
|
/*start:${E}*/
|
343
344
|
${R}
|
344
345
|
/*end:${E}*/
|
345
346
|
`;
|
346
|
-
}, ""),
|
347
|
+
}, ""), C = `l_${w}.css`, u = a(r, "css", C), m = `@layer l${w} { ${T}
|
347
348
|
}`;
|
348
|
-
return
|
349
|
-
@import url('./css/${
|
349
|
+
return N(u, m), `${y}
|
350
|
+
@import url('./css/${C}');`;
|
350
351
|
}, "");
|
351
|
-
|
352
|
+
b += l;
|
352
353
|
}
|
353
|
-
|
354
|
-
const
|
355
|
-
L.info(`Generated CSS in ${
|
354
|
+
N(f, b);
|
355
|
+
const d = Date.now() - s, S = d < 200 ? "🔥" : d < 500 ? "🚀" : d < 1e3 ? "🎉" : d < 2e3 ? "🚗" : d < 5e3 ? "🤔" : "🥴";
|
356
|
+
L.info(`Generated CSS in ${d}ms! ${S}`);
|
356
357
|
} catch (s) {
|
357
358
|
console.error(s);
|
358
359
|
}
|
359
360
|
}, Dt = async (t, e) => {
|
360
361
|
try {
|
361
|
-
const s = a(t, "./saltygen")
|
362
|
+
const s = a(t, "./saltygen");
|
362
363
|
if (z(e)) {
|
363
|
-
const
|
364
|
-
Object.entries(
|
365
|
-
if (
|
366
|
-
const
|
367
|
-
|
364
|
+
const i = [], r = await U(t), f = await q(t, e, s);
|
365
|
+
Object.entries(f).forEach(([p, c]) => {
|
366
|
+
if (c.isKeyframes && c.css) {
|
367
|
+
const x = `css/${`a_${c.animationName}.css`}`, b = a(s, x);
|
368
|
+
N(b, c.css);
|
368
369
|
return;
|
369
370
|
}
|
370
|
-
if (!
|
371
|
-
const
|
372
|
-
name:
|
373
|
-
config:
|
374
|
-
}),
|
375
|
-
|
376
|
-
})
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
${f}
|
387
|
-
/*end:${y}*/
|
371
|
+
if (!c.generator) return;
|
372
|
+
const o = c.generator._withBuildContext({
|
373
|
+
name: p,
|
374
|
+
config: r
|
375
|
+
}), g = `css/${o.cssFileName}`, h = a(s, g);
|
376
|
+
N(h, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
|
377
|
+
}), r.importStrategy !== "component" && i.forEach((p, c) => {
|
378
|
+
const o = `l_${c}.css`, g = a(s, "css", o);
|
379
|
+
let h = M(g, "utf8");
|
380
|
+
p.forEach((F) => {
|
381
|
+
var d;
|
382
|
+
const x = a(s, "css", F), b = ((d = /.*-([^-]+)-\d+.css/.exec(F)) == null ? void 0 : d.at(1)) || W(x, 6);
|
383
|
+
if (!h.includes(b)) {
|
384
|
+
const S = M(x, "utf8"), l = `/*start:${b}*/
|
385
|
+
${S}
|
386
|
+
/*end:${b}*/
|
388
387
|
`;
|
389
|
-
|
390
|
-
${
|
388
|
+
h = `${h.replace(/\}$/, "")}
|
389
|
+
${l}
|
391
390
|
}`;
|
392
391
|
}
|
393
|
-
}),
|
392
|
+
}), N(g, h);
|
394
393
|
});
|
395
394
|
}
|
396
395
|
} catch (s) {
|
@@ -400,39 +399,39 @@ ${C}
|
|
400
399
|
try {
|
401
400
|
const n = a(t, "./saltygen");
|
402
401
|
if (z(e)) {
|
403
|
-
const
|
404
|
-
|
405
|
-
const
|
406
|
-
let
|
407
|
-
if (Object.entries(c).forEach(([
|
408
|
-
var
|
409
|
-
if (
|
410
|
-
const
|
411
|
-
name:
|
412
|
-
config:
|
402
|
+
const r = M(e, "utf8");
|
403
|
+
r.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== r && await ht(e, r);
|
404
|
+
const p = await U(t), c = await q(t, e, n);
|
405
|
+
let o = r;
|
406
|
+
if (Object.entries(c).forEach(([g, h]) => {
|
407
|
+
var j;
|
408
|
+
if (h.isKeyframes || !h.generator) return;
|
409
|
+
const F = h.generator._withBuildContext({
|
410
|
+
name: g,
|
411
|
+
config: p,
|
413
412
|
prod: s
|
414
|
-
}),
|
415
|
-
if (!
|
416
|
-
const
|
417
|
-
if (!
|
418
|
-
const { index:
|
413
|
+
}), x = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
414
|
+
if (!x) return console.error("Could not find the original declaration");
|
415
|
+
const b = (j = x.at(1)) == null ? void 0 : j.trim(), O = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
|
416
|
+
if (!O) return console.error("Could not find the original declaration");
|
417
|
+
const { index: d } = O;
|
419
418
|
let S = !1;
|
420
|
-
const
|
421
|
-
let y = 0,
|
422
|
-
for (; !
|
423
|
-
const $ =
|
424
|
-
$ === "(" &&
|
419
|
+
const l = setTimeout(() => S = !0, 5e3);
|
420
|
+
let y = 0, P = !1, w = 0;
|
421
|
+
for (; !P && !S; ) {
|
422
|
+
const $ = o[d + y];
|
423
|
+
$ === "(" && w++, $ === ")" && w--, w === 0 && $ === ")" && (P = !0), y > o.length && (S = !0), y++;
|
425
424
|
}
|
426
|
-
if (!S) clearTimeout(
|
425
|
+
if (!S) clearTimeout(l);
|
427
426
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
428
|
-
const T =
|
429
|
-
|
430
|
-
}),
|
431
|
-
const
|
432
|
-
|
433
|
-
${
|
427
|
+
const T = d + y, C = o.slice(d, T), u = o, m = ` ${g} = styled(${b}, "${F.classNames}", ${JSON.stringify(F.props)});`;
|
428
|
+
o = o.replace(C, m), u === o && console.error("Minimize file failed to change content", { name: g, tagName: b });
|
429
|
+
}), p.importStrategy === "component") {
|
430
|
+
const g = W(e, 6), h = K(e);
|
431
|
+
o = `import '../../saltygen/css/${`f_${A(h.name)}-${g}.css`}';
|
432
|
+
${o}`;
|
434
433
|
}
|
435
|
-
return
|
434
|
+
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
436
435
|
}
|
437
436
|
} catch (n) {
|
438
437
|
console.error("Error in minimizeFile:", n);
|
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.145",
|
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.145"
|
38
38
|
}
|
39
39
|
}
|