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