@salty-css/vite 0.0.1-alpha.84 → 0.0.1-alpha.85
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 +14 -14
- package/index.js +231 -219
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const nt=require("esbuild"),ot=require("child_process"),u=require("path"),y=require("fs"),Z=require("fs/promises"),E=require("winston");var J=typeof document<"u"?document.currentScript:null;function rt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,o.get?o:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const L=rt(nt),z=t=>String.fromCharCode(t+(t>25?39:97)),it=(t,e)=>{let s="",o;for(o=Math.abs(t);o>52;o=o/52|0)s=z(o%52)+s;return s=z(o%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},ct=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},A=(t,e=3)=>{const s=ct(5381,JSON.stringify(t))>>>0;return it(s,e)};function N(t){return t?typeof t!="string"?N(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 at=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(o=>{const{pattern:n,transform:f}=o;t=t.replace(n,h=>{const{value:a,css:c}=f(h);return c&&s.push(c),a})}),{result:t,additionalCss:s}},U=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${N(o[1].replaceAll(".","-"))})`)}:{result:t},M=(t,e,s,o)=>{if(!t)return"";const n=[],f=Object.entries(t).reduce((a,[c,r])=>{const p=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(p==="variants")return Object.entries(r).forEach(([d,i])=>{i&&Object.entries(i).forEach(([j,m])=>{if(!m)return;const P=`${e}.${d}-${j}`,w=M(m,P);n.push(w)})}),a;if(p==="defaultVariants")return a;if(p==="compoundVariants")return r.forEach(d=>{const{css:i,...j}=d,m=Object.entries(j).reduce((w,[$,F])=>`${w}.${$}-${F}`,e),P=M(i,m);n.push(P)}),a;if(p.startsWith("@")){const d=M(r,e),i=`${p} {
|
2
|
+
${d.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return
|
6
|
-
`);if(!e)return
|
7
|
-
`)},
|
8
|
-
`)},H=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=u.join(t,"package.json");return
|
9
|
-
`),
|
10
|
-
`);let
|
5
|
+
}`;return n.push(i),a}const g=c.includes("&")?p.replace("&",e):p.startsWith(":")?`${e}${p}`:`${e} ${p}`,k=M(r,g);return n.push(k),a}const O=p.startsWith("-")?p:N(p),b=(g,k=";")=>a=`${a}${g}${k}`,C=g=>b(`${O}:${g}`);if(typeof r=="number")return C(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:l}={},x=function*(){yield U(r),yield at(r,l)}();for(const{result:g,additionalCss:k=[]}of x)r=g,k.forEach(d=>{const i=M(d,"");b(i,"")});return C(r)},"");if(!f)return n.join(`
|
6
|
+
`);if(!e)return f;let h="";return h=`${e} { ${f} }`,[h,...n].join(`
|
7
|
+
`)},G=(t,e=[])=>{if(!t)return"";const s=[],o={};if(Object.entries(t).forEach(([n,f])=>{if(typeof f=="object"){if(!f)return;const h=n.trim(),a=G(f,[...e,h]);s.push(a)}else o[n]=f}),Object.keys(o).length){const n=e.map(N).join("-"),f=M(o,`.${n}`);s.push(f)}return s.join(`
|
8
|
+
`)},H=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=u.join(t,"package.json");return y.existsSync(e)?e:H(u.join(t,".."))},lt=async t=>{const e=H(t);return await Z.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},ut=async t=>{const e=await lt(t);if(e)return e.type};let D;const K=async t=>{if(D)return D;const e=await ut(t);return e==="module"?D="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(D="cjs"),D||"esm"},B=E.createLogger({level:"debug",format:E.format.combine(E.format.colorize(),E.format.cli()),transports:[new E.transports.Console({})]}),R={externalModules:[]},X=t=>{if(R.externalModules.length>0)return R.externalModules;const e=u.join(t,"salty.config.ts"),o=y.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!o)return[];const n=o[1].split(",").map(f=>f.replace(/['"`]/g,"").trim());return R.externalModules=n,n},_=t=>u.join(t,"./saltygen"),ft=["salty","css","styles","styled"],pt=(t=[])=>new RegExp(`\\.(${[...ft,...t].join("|")})\\.`),V=(t,e=[])=>pt(e).test(t),dt=async t=>{const e=_(t),s=u.join(t,"salty.config.ts"),o=u.join(e,"salty.config.js"),n=await K(t),f=X(t);await L.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:n,external:f});const h=Date.now(),{config:a}=await import(`${o}?t=${h}`);return a},Y=async t=>{const e=await dt(t),s=new Set,o=(d,i=[])=>d?Object.entries(d).flatMap(([j,m])=>{if(!m)return;if(typeof m=="object")return o(m,[...i,j]);const P=[...i,j].join(".");s.add(`"${P}"`);const w=[...i.map(N),N(j)].join("-"),{result:$}=U(m);return`--${w}: ${$};`}):[],n=d=>d?Object.entries(d).flatMap(([i,j])=>{const m=o(j);return i==="base"?m.join(""):`${i} { ${m.join("")} }`}):[],f=d=>d?Object.entries(d).flatMap(([i,j])=>Object.entries(j).flatMap(([m,P])=>{const w=o(P,[i]),$=`.${i}-${m}, [data-${i}="${m}"]`,F=w.join("");return`${$} { ${F} }`})):[],h=o(e.variables),a=n(e.responsiveVariables),c=f(e.conditionalVariables),r=_(t),p=u.join(r,"css/variables.css"),O=`:root { ${h.join("")} ${a.join("")} } ${c.join("")}`;y.writeFileSync(p,O);const b=u.join(r,"types/css-tokens.d.ts"),l=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;y.writeFileSync(b,l);const S=u.join(r,"css/global.css"),x=M(e.global,"");y.writeFileSync(S,x);const g=u.join(r,"css/templates.css"),k=G(e.templates);y.writeFileSync(g,k)},q=async(t,e,s)=>{const o=A(e),n=u.join(s,"js",o+".js"),f=await K(t),h=X(t);await L.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:f,target:["es2022"],keepNames:!0,external:h});const a=Date.now();return await import(`${n}?t=${a}`)},I=async t=>{const e=_(t),s=u.join(e,"salty.config.js"),{config:o}=await import(s);return o},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},gt=async(t,e=yt())=>{try{e?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const s=[],o=[],n=_(t),f=u.join(n,"index.css");(()=>{y.existsSync(n)&&ot.execSync("rm -rf "+n),y.mkdirSync(n),y.mkdirSync(u.join(n,"css")),y.mkdirSync(u.join(n,"types"))})(),await Y(t);const a=await I(t);async function c(l,S){const x=["node_modules","saltygen"],g=y.statSync(l);if(g.isDirectory()){const k=y.readdirSync(l);if(x.some(i=>l.includes(i)))return;await Promise.all(k.map(i=>c(u.join(l,i),u.join(S,i))))}else if(g.isFile()&&V(l)){const d=await q(t,l,n),i=[];Object.entries(d).forEach(([w,$])=>{if($.isKeyframes&&$.css){const W=`${$.animationName}.css`,et=`css/${W}`,st=u.join(n,et);s.push(W),y.writeFileSync(st,$.css);return}if(!$.generator)return;const F=$.generator._withBuildContext({name:w,config:a}),T=`${F.hash}-${F.priority}.css`;o[F.priority]||(o[F.priority]=[]),o[F.priority].push(T),i.push(T);const v=`css/${T}`,tt=u.join(n,v);y.writeFileSync(tt,F.css)});const j=i.map(w=>`@import url('./${w}');`).join(`
|
9
|
+
`),m=A(l,6),P=u.join(n,`css/${m}.css`);y.writeFileSync(P,j)}}await c(t,n);const r=s.map(l=>`@import url('./css/${l}');`).join(`
|
10
|
+
`);let C=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
11
11
|
|
12
|
-
${["variables.css","global.css","templates.css"].filter(l=>{try{return
|
12
|
+
${["variables.css","global.css","templates.css"].filter(l=>{try{return y.readFileSync(u.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
13
13
|
`)}
|
14
|
-
${
|
15
|
-
`);
|
16
|
-
`),r=s.map(b=>`@import url('../saltygen/css/${b}');`),
|
17
|
-
`);
|
18
|
-
${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}},
|
14
|
+
${r}`;if(a.importStrategy!=="component"){const l=o.flat().map(S=>`@import url('./css/${S}');`).join(`
|
15
|
+
`);C+=l}y.writeFileSync(f,C)}catch(s){console.error(s)}},mt=async(t,e)=>{try{const s=[],o=u.join(t,"./saltygen"),n=u.join(o,"index.css");if(V(e)){const h=await I(t),a=await q(t,e,o);Object.entries(a).forEach(([b,C])=>{if(!C.generator)return;const l=C.generator._withBuildContext({name:b,config:h}),S=`${l.hash}-${l.priority}.css`,x=`css/${S}`,g=u.join(o,x);s.push(S),y.writeFileSync(g,l.css)});const c=y.readFileSync(n,"utf8").split(`
|
16
|
+
`),r=s.map(b=>`@import url('../saltygen/css/${b}');`),O=[...new Set([...c,...r])].join(`
|
17
|
+
`);y.writeFileSync(n,O)}}catch(s){console.error(s)}},ht=async(t,e)=>{try{const s=u.join(t,"./saltygen");if(V(e)){const n=y.readFileSync(e,"utf8");n.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==n&&await Z.writeFile(e,n);const h=await I(t),a=await q(t,e,s);let c=n;Object.entries(a).forEach(([p,O])=>{var F;if(O.isKeyframes||!O.generator)return;const b=O.generator._withBuildContext({name:p,config:h}),C=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(n);if(!C)return console.error("Could not find the original declaration");const l=(F=C.at(1))==null?void 0:F.trim(),S=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(c);if(!S)return console.error("Could not find the original declaration");const{index:x}=S;let g=!1;const k=setTimeout(()=>g=!0,5e3);let d=0,i=!1,j=0;for(;!i&&!g;){const T=c[x+d];T==="("&&j++,T===")"&&j--,j===0&&T===")"&&(i=!0),d>c.length&&(g=!0),d++}if(!g)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const m=x+d,P=c.slice(x,m),w=c,$=` ${p} = styled(${l}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(P,$),w===c&&console.error("Minimize file failed to change content",{name:p,tagName:l})});const r=A(e,6);return h.importStrategy==="component"&&(c=`import '../../saltygen/css/${r}.css';
|
18
|
+
${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}},Q=t=>({name:"stylegen",buildStart:()=>gt(t),load:async e=>{if(V(e))return await ht(t,e)},watchChange:{handler:async e=>{V(e)&&await mt(t,e),e.includes("salty.config")&&await Y(t)}}});exports.default=Q;exports.saltyPlugin=Q;
|
package/index.js
CHANGED
@@ -1,221 +1,233 @@
|
|
1
|
-
import * as
|
2
|
-
import { execSync as
|
1
|
+
import * as H from "esbuild";
|
2
|
+
import { execSync as nt } from "child_process";
|
3
3
|
import { join as f } from "path";
|
4
|
-
import { existsSync as
|
5
|
-
import { readFile as
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
import { existsSync as K, writeFileSync as E, mkdirSync as A, statSync as ot, readdirSync as rt, readFileSync as V } from "fs";
|
5
|
+
import { readFile as ct, writeFile as it } from "fs/promises";
|
6
|
+
import { createLogger as at, format as _, transports as lt } from "winston";
|
7
|
+
const z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), ft = (t, e) => {
|
8
|
+
let s = "", o;
|
9
|
+
for (o = Math.abs(t); o > 52; o = o / 52 | 0) s = z(o % 52) + s;
|
10
|
+
return s = z(o % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, ut = (t, e) => {
|
12
|
+
let s = e.length;
|
13
|
+
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
13
14
|
return t;
|
14
|
-
},
|
15
|
-
const
|
16
|
-
return
|
15
|
+
}, W = (t, e = 3) => {
|
16
|
+
const s = ut(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return ft(s, e);
|
17
18
|
};
|
18
|
-
function
|
19
|
-
return t ? typeof t != "string" ?
|
19
|
+
function T(t) {
|
20
|
+
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()) : "";
|
20
21
|
}
|
21
|
-
const
|
22
|
+
const pt = (t, e) => {
|
22
23
|
if (typeof t != "string") return { result: t };
|
23
|
-
if (!
|
24
|
-
const
|
25
|
-
return Object.values(
|
26
|
-
const { pattern:
|
27
|
-
t = t.replace(
|
28
|
-
const { value: a, css: i } =
|
29
|
-
return i &&
|
24
|
+
if (!e) return { result: t };
|
25
|
+
const s = [];
|
26
|
+
return Object.values(e).forEach((o) => {
|
27
|
+
const { pattern: n, transform: u } = o;
|
28
|
+
t = t.replace(n, (m) => {
|
29
|
+
const { value: a, css: i } = u(m);
|
30
|
+
return i && s.push(i), a;
|
30
31
|
});
|
31
|
-
}), { result: t, additionalCss:
|
32
|
-
},
|
32
|
+
}), { result: t, additionalCss: s };
|
33
|
+
}, L = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...o) => `var(--${T(o[1].replaceAll(".", "-"))})`) } : { result: t }, M = (t, e, s, o) => {
|
33
34
|
if (!t) return "";
|
34
|
-
const
|
35
|
-
const
|
35
|
+
const n = [], u = Object.entries(t).reduce((a, [i, r]) => {
|
36
|
+
const p = i.trim();
|
36
37
|
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
37
38
|
if (!r) return a;
|
38
|
-
if (
|
39
|
-
return Object.entries(r).forEach(([
|
40
|
-
|
41
|
-
if (!
|
42
|
-
const
|
43
|
-
|
39
|
+
if (p === "variants")
|
40
|
+
return Object.entries(r).forEach(([g, c]) => {
|
41
|
+
c && Object.entries(c).forEach(([h, d]) => {
|
42
|
+
if (!d) return;
|
43
|
+
const x = `${e}.${g}-${h}`, S = M(d, x);
|
44
|
+
n.push(S);
|
44
45
|
});
|
45
46
|
}), a;
|
46
|
-
if (
|
47
|
+
if (p === "defaultVariants")
|
47
48
|
return a;
|
48
|
-
if (
|
49
|
-
return r.forEach((
|
50
|
-
const { css:
|
51
|
-
|
49
|
+
if (p === "compoundVariants")
|
50
|
+
return r.forEach((g) => {
|
51
|
+
const { css: c, ...h } = g, d = Object.entries(h).reduce((S, [$, j]) => `${S}.${$}-${j}`, e), x = M(c, d);
|
52
|
+
n.push(x);
|
52
53
|
}), a;
|
53
|
-
if (
|
54
|
-
const
|
55
|
-
${
|
54
|
+
if (p.startsWith("@")) {
|
55
|
+
const g = M(r, e), c = `${p} {
|
56
|
+
${g.replace(`
|
56
57
|
`, `
|
57
58
|
`)}
|
58
59
|
}`;
|
59
|
-
return
|
60
|
+
return n.push(c), a;
|
60
61
|
}
|
61
|
-
const
|
62
|
-
return
|
62
|
+
const y = i.includes("&") ? p.replace("&", e) : p.startsWith(":") ? `${e}${p}` : `${e} ${p}`, C = M(r, y);
|
63
|
+
return n.push(C), a;
|
63
64
|
}
|
64
|
-
const
|
65
|
-
if (typeof r == "number") return
|
65
|
+
const P = p.startsWith("-") ? p : T(p), b = (y, C = ";") => a = `${a}${y}${C}`, F = (y) => b(`${P}:${y}`);
|
66
|
+
if (typeof r == "number") return F(r);
|
66
67
|
if (typeof r != "string")
|
67
68
|
if ("toString" in r) r = r.toString();
|
68
69
|
else return a;
|
69
|
-
const { modifiers:
|
70
|
-
yield
|
70
|
+
const { modifiers: l } = {}, k = function* () {
|
71
|
+
yield L(r), yield pt(r, l);
|
71
72
|
}();
|
72
|
-
for (const { result:
|
73
|
-
r =
|
74
|
-
const
|
75
|
-
b(
|
73
|
+
for (const { result: y, additionalCss: C = [] } of k)
|
74
|
+
r = y, C.forEach((g) => {
|
75
|
+
const c = M(g, "");
|
76
|
+
b(c, "");
|
76
77
|
});
|
77
|
-
return
|
78
|
+
return F(r);
|
78
79
|
}, "");
|
79
|
-
if (!
|
80
|
+
if (!u) return n.join(`
|
80
81
|
`);
|
81
|
-
if (!
|
82
|
-
let
|
83
|
-
return
|
82
|
+
if (!e) return u;
|
83
|
+
let m = "";
|
84
|
+
return m = `${e} { ${u} }`, [m, ...n].join(`
|
84
85
|
`);
|
85
|
-
}, q = (t,
|
86
|
+
}, q = (t, e = []) => {
|
86
87
|
if (!t) return "";
|
87
|
-
const
|
88
|
-
if (Object.entries(t).forEach(([
|
89
|
-
if (typeof
|
90
|
-
if (!
|
91
|
-
const
|
92
|
-
|
88
|
+
const s = [], o = {};
|
89
|
+
if (Object.entries(t).forEach(([n, u]) => {
|
90
|
+
if (typeof u == "object") {
|
91
|
+
if (!u) return;
|
92
|
+
const m = n.trim(), a = q(u, [...e, m]);
|
93
|
+
s.push(a);
|
93
94
|
} else
|
94
|
-
n
|
95
|
-
}), Object.keys(
|
96
|
-
const
|
97
|
-
|
95
|
+
o[n] = u;
|
96
|
+
}), Object.keys(o).length) {
|
97
|
+
const n = e.map(T).join("-"), u = M(o, `.${n}`);
|
98
|
+
s.push(u);
|
98
99
|
}
|
99
|
-
return
|
100
|
+
return s.join(`
|
100
101
|
`);
|
101
|
-
},
|
102
|
+
}, U = (t) => {
|
102
103
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
103
|
-
const
|
104
|
-
return
|
105
|
-
},
|
106
|
-
const
|
107
|
-
return await
|
104
|
+
const e = f(t, "package.json");
|
105
|
+
return K(e) ? e : U(f(t, ".."));
|
106
|
+
}, gt = async (t) => {
|
107
|
+
const e = U(t);
|
108
|
+
return await ct(e, "utf-8").then(JSON.parse).catch(() => {
|
108
109
|
});
|
109
|
-
},
|
110
|
-
const
|
111
|
-
if (
|
112
|
-
return
|
110
|
+
}, yt = async (t) => {
|
111
|
+
const e = await gt(t);
|
112
|
+
if (e)
|
113
|
+
return e.type;
|
113
114
|
};
|
114
|
-
let
|
115
|
-
const
|
116
|
-
if (
|
117
|
-
const
|
118
|
-
return
|
119
|
-
},
|
115
|
+
let N;
|
116
|
+
const X = async (t) => {
|
117
|
+
if (N) return N;
|
118
|
+
const e = await yt(t);
|
119
|
+
return e === "module" ? N = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (N = "cjs"), N || "esm";
|
120
|
+
}, G = at({
|
121
|
+
level: "debug",
|
122
|
+
format: _.combine(_.colorize(), _.cli()),
|
123
|
+
transports: [new lt.Console({})]
|
124
|
+
}), R = {
|
120
125
|
externalModules: []
|
121
|
-
},
|
126
|
+
}, Y = (t) => {
|
122
127
|
if (R.externalModules.length > 0) return R.externalModules;
|
123
|
-
const
|
124
|
-
if (!
|
125
|
-
const
|
126
|
-
return R.externalModules =
|
127
|
-
}, J = (t) => f(t, "./saltygen"),
|
128
|
-
const
|
129
|
-
await
|
130
|
-
entryPoints: [
|
128
|
+
const e = f(t, "salty.config.ts"), o = V(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
129
|
+
if (!o) return [];
|
130
|
+
const n = o[1].split(",").map((u) => u.replace(/['"`]/g, "").trim());
|
131
|
+
return R.externalModules = n, n;
|
132
|
+
}, J = (t) => f(t, "./saltygen"), dt = ["salty", "css", "styles", "styled"], mt = (t = []) => new RegExp(`\\.(${[...dt, ...t].join("|")})\\.`), O = (t, e = []) => mt(e).test(t), ht = async (t) => {
|
133
|
+
const e = J(t), s = f(t, "salty.config.ts"), o = f(e, "salty.config.js"), n = await X(t), u = Y(t);
|
134
|
+
await H.build({
|
135
|
+
entryPoints: [s],
|
131
136
|
minify: !0,
|
132
137
|
treeShaking: !0,
|
133
138
|
bundle: !0,
|
134
|
-
outfile:
|
135
|
-
format:
|
136
|
-
external:
|
139
|
+
outfile: o,
|
140
|
+
format: n,
|
141
|
+
external: u
|
137
142
|
});
|
138
|
-
const
|
143
|
+
const m = Date.now(), { config: a } = await import(`${o}?t=${m}`);
|
139
144
|
return a;
|
140
|
-
},
|
141
|
-
const
|
142
|
-
if (!
|
143
|
-
if (typeof
|
144
|
-
const
|
145
|
-
|
146
|
-
const
|
147
|
-
return `--${
|
148
|
-
}) : [],
|
149
|
-
const
|
150
|
-
return
|
151
|
-
}) : [],
|
152
|
-
const
|
153
|
-
return `${
|
154
|
-
})) : [],
|
155
|
-
|
156
|
-
const b = f(r, "types/css-tokens.d.ts"),
|
157
|
-
|
158
|
-
const
|
159
|
-
|
160
|
-
const
|
161
|
-
|
162
|
-
},
|
163
|
-
const
|
164
|
-
await
|
165
|
-
entryPoints: [
|
145
|
+
}, Q = async (t) => {
|
146
|
+
const e = await ht(t), s = /* @__PURE__ */ new Set(), o = (g, c = []) => g ? Object.entries(g).flatMap(([h, d]) => {
|
147
|
+
if (!d) return;
|
148
|
+
if (typeof d == "object") return o(d, [...c, h]);
|
149
|
+
const x = [...c, h].join(".");
|
150
|
+
s.add(`"${x}"`);
|
151
|
+
const S = [...c.map(T), T(h)].join("-"), { result: $ } = L(d);
|
152
|
+
return `--${S}: ${$};`;
|
153
|
+
}) : [], n = (g) => g ? Object.entries(g).flatMap(([c, h]) => {
|
154
|
+
const d = o(h);
|
155
|
+
return c === "base" ? d.join("") : `${c} { ${d.join("")} }`;
|
156
|
+
}) : [], u = (g) => g ? Object.entries(g).flatMap(([c, h]) => Object.entries(h).flatMap(([d, x]) => {
|
157
|
+
const S = o(x, [c]), $ = `.${c}-${d}, [data-${c}="${d}"]`, j = S.join("");
|
158
|
+
return `${$} { ${j} }`;
|
159
|
+
})) : [], m = o(e.variables), a = n(e.responsiveVariables), i = u(e.conditionalVariables), r = J(t), p = f(r, "css/variables.css"), P = `:root { ${m.join("")} ${a.join("")} } ${i.join("")}`;
|
160
|
+
E(p, P);
|
161
|
+
const b = f(r, "types/css-tokens.d.ts"), l = `type VariableTokens = ${[...s].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
162
|
+
E(b, l);
|
163
|
+
const w = f(r, "css/global.css"), k = M(e.global, "");
|
164
|
+
E(w, k);
|
165
|
+
const y = f(r, "css/templates.css"), C = q(e.templates);
|
166
|
+
E(y, C);
|
167
|
+
}, B = async (t, e, s) => {
|
168
|
+
const o = W(e), n = f(s, "js", o + ".js"), u = await X(t), m = Y(t);
|
169
|
+
await H.build({
|
170
|
+
entryPoints: [e],
|
166
171
|
minify: !0,
|
167
172
|
treeShaking: !0,
|
168
173
|
bundle: !0,
|
169
|
-
outfile:
|
170
|
-
format:
|
174
|
+
outfile: n,
|
175
|
+
format: u,
|
171
176
|
target: ["es2022"],
|
172
177
|
keepNames: !0,
|
173
|
-
external:
|
178
|
+
external: m
|
174
179
|
});
|
175
180
|
const a = Date.now();
|
176
|
-
return await import(`${
|
177
|
-
},
|
178
|
-
const
|
179
|
-
return
|
180
|
-
},
|
181
|
+
return await import(`${n}?t=${a}`);
|
182
|
+
}, I = async (t) => {
|
183
|
+
const e = J(t), s = f(e, "salty.config.js"), { config: o } = await import(s);
|
184
|
+
return o;
|
185
|
+
}, $t = () => {
|
186
|
+
try {
|
187
|
+
return process.env.NODE_ENV === "production";
|
188
|
+
} catch {
|
189
|
+
return !1;
|
190
|
+
}
|
191
|
+
}, bt = async (t, e = $t()) => {
|
181
192
|
try {
|
182
|
-
|
193
|
+
e ? G.info("Generating CSS in production mode! 🔥") : G.info("Generating CSS in development mode! 🚀");
|
194
|
+
const s = [], o = [], n = J(t), u = f(n, "index.css");
|
183
195
|
(() => {
|
184
|
-
|
185
|
-
})(), await
|
186
|
-
const
|
187
|
-
async function
|
188
|
-
const
|
189
|
-
if (
|
190
|
-
const
|
191
|
-
if (
|
192
|
-
await Promise.all(
|
193
|
-
} else if (
|
194
|
-
const
|
195
|
-
Object.entries(
|
196
|
+
K(n) && nt("rm -rf " + n), A(n), A(f(n, "css")), A(f(n, "types"));
|
197
|
+
})(), await Q(t);
|
198
|
+
const a = await I(t);
|
199
|
+
async function i(l, w) {
|
200
|
+
const k = ["node_modules", "saltygen"], y = ot(l);
|
201
|
+
if (y.isDirectory()) {
|
202
|
+
const C = rt(l);
|
203
|
+
if (k.some((c) => l.includes(c))) return;
|
204
|
+
await Promise.all(C.map((c) => i(f(l, c), f(w, c))));
|
205
|
+
} else if (y.isFile() && O(l)) {
|
206
|
+
const g = await B(t, l, n), c = [];
|
207
|
+
Object.entries(g).forEach(([S, $]) => {
|
196
208
|
if ($.isKeyframes && $.css) {
|
197
|
-
const
|
198
|
-
s.push(
|
209
|
+
const Z = `${$.animationName}.css`, et = `css/${Z}`, st = f(n, et);
|
210
|
+
s.push(Z), E(st, $.css);
|
199
211
|
return;
|
200
212
|
}
|
201
213
|
if (!$.generator) return;
|
202
214
|
const j = $.generator._withBuildContext({
|
203
215
|
name: S,
|
204
|
-
config:
|
205
|
-
}),
|
206
|
-
|
207
|
-
const
|
208
|
-
|
216
|
+
config: a
|
217
|
+
}), D = `${j.hash}-${j.priority}.css`;
|
218
|
+
o[j.priority] || (o[j.priority] = []), o[j.priority].push(D), c.push(D);
|
219
|
+
const v = `css/${D}`, tt = f(n, v);
|
220
|
+
E(tt, j.css);
|
209
221
|
});
|
210
|
-
const
|
211
|
-
`),
|
212
|
-
|
222
|
+
const h = c.map((S) => `@import url('./${S}');`).join(`
|
223
|
+
`), d = W(l, 6), x = f(n, `css/${d}.css`);
|
224
|
+
E(x, h);
|
213
225
|
}
|
214
226
|
}
|
215
|
-
await
|
216
|
-
const
|
227
|
+
await i(t, n);
|
228
|
+
const r = s.map((l) => `@import url('./css/${l}');`).join(`
|
217
229
|
`);
|
218
|
-
let
|
230
|
+
let F = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
219
231
|
|
220
232
|
${["variables.css", "global.css", "templates.css"].filter((l) => {
|
221
233
|
try {
|
@@ -225,89 +237,89 @@ ${["variables.css", "global.css", "templates.css"].filter((l) => {
|
|
225
237
|
}
|
226
238
|
}).map((l) => `@import url('./css/${l}');`).join(`
|
227
239
|
`)}
|
228
|
-
${
|
229
|
-
if (
|
230
|
-
const l =
|
240
|
+
${r}`;
|
241
|
+
if (a.importStrategy !== "component") {
|
242
|
+
const l = o.flat().map((w) => `@import url('./css/${w}');`).join(`
|
231
243
|
`);
|
232
|
-
|
244
|
+
F += l;
|
233
245
|
}
|
234
|
-
|
246
|
+
E(u, F);
|
235
247
|
} catch (s) {
|
236
248
|
console.error(s);
|
237
249
|
}
|
238
|
-
},
|
250
|
+
}, wt = async (t, e) => {
|
239
251
|
try {
|
240
|
-
const
|
241
|
-
if (O(
|
242
|
-
const
|
243
|
-
Object.entries(a).forEach(([b,
|
244
|
-
if (!
|
245
|
-
const
|
252
|
+
const s = [], o = f(t, "./saltygen"), n = f(o, "index.css");
|
253
|
+
if (O(e)) {
|
254
|
+
const m = await I(t), a = await B(t, e, o);
|
255
|
+
Object.entries(a).forEach(([b, F]) => {
|
256
|
+
if (!F.generator) return;
|
257
|
+
const l = F.generator._withBuildContext({
|
246
258
|
name: b,
|
247
|
-
config:
|
248
|
-
}),
|
249
|
-
|
259
|
+
config: m
|
260
|
+
}), w = `${l.hash}-${l.priority}.css`, k = `css/${w}`, y = f(o, k);
|
261
|
+
s.push(w), E(y, l.css);
|
250
262
|
});
|
251
|
-
const i = V(
|
252
|
-
`), r =
|
263
|
+
const i = V(n, "utf8").split(`
|
264
|
+
`), r = s.map((b) => `@import url('../saltygen/css/${b}');`), P = [.../* @__PURE__ */ new Set([...i, ...r])].join(`
|
253
265
|
`);
|
254
|
-
|
266
|
+
E(n, P);
|
255
267
|
}
|
256
|
-
} catch (
|
257
|
-
console.error(
|
268
|
+
} catch (s) {
|
269
|
+
console.error(s);
|
258
270
|
}
|
259
|
-
},
|
271
|
+
}, St = async (t, e) => {
|
260
272
|
try {
|
261
|
-
const
|
262
|
-
if (O(
|
263
|
-
const
|
264
|
-
|
265
|
-
const
|
266
|
-
let i =
|
267
|
-
Object.entries(a).forEach(([
|
268
|
-
var
|
269
|
-
if (
|
270
|
-
const b =
|
271
|
-
name:
|
272
|
-
config:
|
273
|
-
}),
|
274
|
-
if (!
|
275
|
-
const
|
276
|
-
if (!
|
277
|
-
const { index:
|
278
|
-
let
|
279
|
-
const
|
280
|
-
let
|
281
|
-
for (; !
|
282
|
-
const
|
283
|
-
|
273
|
+
const s = f(t, "./saltygen");
|
274
|
+
if (O(e)) {
|
275
|
+
const n = V(e, "utf8");
|
276
|
+
n.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== n && await it(e, n);
|
277
|
+
const m = await I(t), a = await B(t, e, s);
|
278
|
+
let i = n;
|
279
|
+
Object.entries(a).forEach(([p, P]) => {
|
280
|
+
var j;
|
281
|
+
if (P.isKeyframes || !P.generator) return;
|
282
|
+
const b = P.generator._withBuildContext({
|
283
|
+
name: p,
|
284
|
+
config: m
|
285
|
+
}), F = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(n);
|
286
|
+
if (!F) return console.error("Could not find the original declaration");
|
287
|
+
const l = (j = F.at(1)) == null ? void 0 : j.trim(), w = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(i);
|
288
|
+
if (!w) return console.error("Could not find the original declaration");
|
289
|
+
const { index: k } = w;
|
290
|
+
let y = !1;
|
291
|
+
const C = setTimeout(() => y = !0, 5e3);
|
292
|
+
let g = 0, c = !1, h = 0;
|
293
|
+
for (; !c && !y; ) {
|
294
|
+
const D = i[k + g];
|
295
|
+
D === "(" && h++, D === ")" && h--, h === 0 && D === ")" && (c = !0), g > i.length && (y = !0), g++;
|
284
296
|
}
|
285
|
-
if (!
|
297
|
+
if (!y) clearTimeout(C);
|
286
298
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
287
|
-
const
|
288
|
-
i = i.replace(
|
299
|
+
const d = k + g, x = i.slice(k, d), S = i, $ = ` ${p} = styled(${l}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
|
300
|
+
i = i.replace(x, $), S === i && console.error("Minimize file failed to change content", { name: p, tagName: l });
|
289
301
|
});
|
290
|
-
const r =
|
291
|
-
return
|
302
|
+
const r = W(e, 6);
|
303
|
+
return m.importStrategy === "component" && (i = `import '../../saltygen/css/${r}.css';
|
292
304
|
${i}`), i = i.replace("{ styled }", "{ styledClient as styled }"), i = i.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), i;
|
293
305
|
}
|
294
|
-
} catch (
|
295
|
-
console.error("Error in minimizeFile:",
|
306
|
+
} catch (s) {
|
307
|
+
console.error("Error in minimizeFile:", s);
|
296
308
|
}
|
297
|
-
},
|
309
|
+
}, Pt = (t) => ({
|
298
310
|
name: "stylegen",
|
299
|
-
buildStart: () =>
|
300
|
-
load: async (
|
301
|
-
if (O(
|
302
|
-
return await
|
311
|
+
buildStart: () => bt(t),
|
312
|
+
load: async (e) => {
|
313
|
+
if (O(e))
|
314
|
+
return await St(t, e);
|
303
315
|
},
|
304
316
|
watchChange: {
|
305
|
-
handler: async (
|
306
|
-
O(
|
317
|
+
handler: async (e) => {
|
318
|
+
O(e) && await wt(t, e), e.includes("salty.config") && await Q(t);
|
307
319
|
}
|
308
320
|
}
|
309
321
|
});
|
310
322
|
export {
|
311
|
-
|
312
|
-
|
323
|
+
Pt as default,
|
324
|
+
Pt as saltyPlugin
|
313
325
|
};
|
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.85",
|
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.85"
|
38
38
|
}
|
39
39
|
}
|