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