@salty-css/core 0.0.1-alpha.40 → 0.0.1-alpha.41
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/compiler/index.cjs +8 -8
- package/compiler/index.js +104 -93
- package/package.json +1 -1
package/compiler/index.cjs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),
|
2
|
-
`),
|
3
|
-
`);let
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),H=require("child_process"),N=require("../dash-case-DKzpenwY.cjs"),i=require("path"),l=require("fs"),K=require("fs/promises"),V=require("../parse-templates-W0YfTmOT.cjs");function G(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const e=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(s,n,e.get?e:{enumerable:!0,get:()=>t[n]})}}return s.default=t,Object.freeze(s)}const _=G(I),O=t=>i.join(t,"./saltygen"),q=["salty","css","styles","styled"],M=(t=[])=>new RegExp(`\\.(${[...q,...t].join("|")})\\.`),E=(t,s=[])=>M(s).test(t),J=async t=>{const s=O(t),n=i.join(t,"salty.config.ts"),e=i.join(s,"salty.config.js");await _.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:"esm",external:["react"]});const p=Date.now(),{config:C}=await import(`${e}?t=${p}`);return C},z=async t=>{const s=await J(t),n=new Set,e=(f,y=[])=>f?Object.entries(f).flatMap(([a,r])=>{if(!r)return;if(typeof r=="object")return e(r,[...y,a]);const F=[...y,a].join(".");n.add(`"${F}"`);const x=[...y.map(N.dashCase),N.dashCase(a)].join("-"),{result:D}=V.parseValueTokens(r);return`--${x}: ${D};`}):[],p=f=>f?Object.entries(f).flatMap(([y,a])=>{const r=e(a);return y==="base"?r.join(""):`${y} { ${r.join("")} }`}):[],C=f=>f?Object.entries(f).flatMap(([y,a])=>Object.entries(a).flatMap(([r,F])=>{const x=e(F,[y]),D=`.${y}-${r}, [data-${y}="${r}"]`,P=x.join("");return`${D} { ${P} }`})):[],b=e(s.variables),w=p(s.responsiveVariables),o=C(s.conditionalVariables),S=O(t),u=i.join(S,"css/variables.css"),c=`:root { ${b.join("")} ${w.join("")} } ${o.join("")}`;l.writeFileSync(u,c);const g=i.join(S,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;l.writeFileSync(g,m);const d=i.join(S,"css/global.css"),h=V.parseStyles(s.global,"");l.writeFileSync(d,h);const j=i.join(S,"css/templates.css"),k=V.parseTemplates(s.templates);l.writeFileSync(j,k)},v=async(t,s)=>{const n=N.toHash(t),e=i.join(s,"js",n+".js");await _.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const p=Date.now();return await import(`${e}?t=${p}`)},R=async t=>{const s=O(t),n=i.join(s,"salty.config.js"),{config:e}=await import(n);return e},A=async t=>{try{const s=[],n=[],e=O(t),p=i.join(e,"index.css");(()=>{l.existsSync(e)&&H.execSync("rm -rf "+e),l.mkdirSync(e),l.mkdirSync(i.join(e,"css")),l.mkdirSync(i.join(e,"types"))})(),await z(t);const b=await R(t);async function w(c,g){const $=l.statSync(c);if($.isDirectory()){const m=l.readdirSync(c);await Promise.all(m.map(d=>w(i.join(c,d),i.join(g,d))))}else if($.isFile()&&E(c)){const d=await v(c,e),h=[];Object.entries(d).forEach(([y,a])=>{if(a.isKeyframes&&a.css){const P=`${a.animationName}.css`,T=`css/${P}`,B=i.join(e,T);s.push(P),l.writeFileSync(B,a.css);return}if(!a.generator)return;const r=a.generator._withBuildContext({name:y,config:b}),F=`${r.hash}-${r.priority}.css`;n[r.priority]||(n[r.priority]=[]),n[r.priority].push(F),h.push(F);const x=`css/${F}`,D=i.join(e,x);l.writeFileSync(D,r.css)});const j=h.map(y=>`@import url('./${y}');`).join(`
|
2
|
+
`),k=N.toHash(c,6),f=i.join(e,`css/${k}.css`);l.writeFileSync(f,j)}}await w(t,e);const o=s.map(c=>`@import url('./css/${c}');`).join(`
|
3
|
+
`);let u=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
4
4
|
|
5
5
|
${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
|
6
6
|
`)}
|
7
|
-
${
|
8
|
-
`);
|
9
|
-
`),
|
10
|
-
`);
|
11
|
-
${
|
7
|
+
${o}`;if(b.importStrategy!=="component"){const c=n.flat().map(g=>`@import url('./css/${g}');`).join(`
|
8
|
+
`);u+=c}l.writeFileSync(p,u)}catch(s){console.error(s)}},L=async(t,s)=>{try{const n=[],e=i.join(t,"./saltygen"),p=i.join(e,"index.css");if(E(s)){const b=await R(t),w=await v(s,e);Object.entries(w).forEach(([g,$])=>{if(!$.generator)return;const m=$.generator._withBuildContext({name:g,config:b}),d=`${m.hash}-${m.priority}.css`,h=`css/${d}`,j=i.join(e,h);n.push(d),l.writeFileSync(j,m.css)});const o=l.readFileSync(p,"utf8").split(`
|
9
|
+
`),S=n.map(g=>`@import url('../saltygen/css/${g}');`),c=[...new Set([...o,...S])].join(`
|
10
|
+
`);l.writeFileSync(p,c)}}catch(n){console.error(n)}},U=async(t,s)=>{try{const n=i.join(t,"./saltygen");if(E(s)){const p=l.readFileSync(s,"utf8");p.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==p&&await K.writeFile(s,p);const b=await R(t),w=await v(s,n);let o=p;Object.entries(w).forEach(([u,c])=>{var P;if(c.isKeyframes||!c.generator)return;const g=c.generator._withBuildContext({name:u,config:b}),$=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(p);if(!$)return console.error("Could not find the original declaration");const m=(P=$.at(1))==null?void 0:P.trim(),d=new RegExp(`${u}[=\\s]+styled\\(`,"g").exec(o);if(!d)return console.error("Could not find the original declaration");const{index:h}=d;let j=!1;const k=setTimeout(()=>j=!0,5e3);let f=0,y=!1,a=0;for(;!y&&!j;){const T=o[h+f];T==="("&&a++,T===")"&&a--,a===0&&T===")"&&(y=!0),f>o.length&&(j=!0),f++}if(!j)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const r=h+f,F=o.slice(h,r),x=o,D=`${u} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`;o=o.replace(F,D),x===o&&console.error("Minimize file failed to change content",{name:u,tagName:m})});const S=N.toHash(s,6);return b.importStrategy==="component"&&(o=`import '../../saltygen/css/${S}.css';
|
11
|
+
${o}`),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)}};exports.compileSaltyFile=v;exports.generateConfigStyles=z;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=E;exports.minimizeFile=U;exports.saltyFileExtensions=q;exports.saltyFileRegExp=M;
|
package/compiler/index.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import * as I from "esbuild";
|
2
2
|
import { execSync as z } from "child_process";
|
3
|
-
import { t as
|
4
|
-
import { join as
|
3
|
+
import { t as E, d as B } from "../dash-case-DMQMcCO6.js";
|
4
|
+
import { join as i } from "path";
|
5
5
|
import { writeFileSync as $, existsSync as H, mkdirSync as V, statSync as K, readdirSync as G, readFileSync as M } from "fs";
|
6
6
|
import { writeFile as J } from "fs/promises";
|
7
7
|
import { p as q, a as A, b as L } from "../parse-templates-D4p3pgQR.js";
|
8
|
-
const
|
9
|
-
const e =
|
8
|
+
const T = (s) => i(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W = (s = []) => new RegExp(`\\.(${[...U, ...s].join("|")})\\.`), v = (s, e = []) => W(e).test(s), X = async (s) => {
|
9
|
+
const e = T(s), n = i(s, "salty.config.ts"), t = i(e, "salty.config.js");
|
10
10
|
await I.build({
|
11
11
|
entryPoints: [n],
|
12
12
|
minify: !0,
|
@@ -16,32 +16,32 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
|
|
16
16
|
format: "esm",
|
17
17
|
external: ["react"]
|
18
18
|
});
|
19
|
-
const
|
20
|
-
return
|
19
|
+
const p = Date.now(), { config: x } = await import(`${t}?t=${p}`);
|
20
|
+
return x;
|
21
21
|
}, Y = async (s) => {
|
22
|
-
const e = await X(s), n = /* @__PURE__ */ new Set(), t = (
|
22
|
+
const e = await X(s), n = /* @__PURE__ */ new Set(), t = (f, l = []) => f ? Object.entries(f).flatMap(([a, r]) => {
|
23
23
|
if (!r) return;
|
24
|
-
if (typeof r == "object") return t(r, [...l,
|
25
|
-
const
|
26
|
-
n.add(`"${
|
27
|
-
const C = [...l.map(
|
24
|
+
if (typeof r == "object") return t(r, [...l, a]);
|
25
|
+
const S = [...l, a].join(".");
|
26
|
+
n.add(`"${S}"`);
|
27
|
+
const C = [...l.map(B), B(a)].join("-"), { result: D } = L(r);
|
28
28
|
return `--${C}: ${D};`;
|
29
|
-
}) : [],
|
30
|
-
const r = t(
|
29
|
+
}) : [], p = (f) => f ? Object.entries(f).flatMap(([l, a]) => {
|
30
|
+
const r = t(a);
|
31
31
|
return l === "base" ? r.join("") : `${l} { ${r.join("")} }`;
|
32
|
-
}) : [],
|
33
|
-
const C = t(
|
32
|
+
}) : [], x = (f) => f ? Object.entries(f).flatMap(([l, a]) => Object.entries(a).flatMap(([r, S]) => {
|
33
|
+
const C = t(S, [l]), D = `.${l}-${r}, [data-${l}="${r}"]`, P = C.join("");
|
34
34
|
return `${D} { ${P} }`;
|
35
|
-
})) : [],
|
36
|
-
$(
|
37
|
-
const
|
38
|
-
$(
|
39
|
-
const
|
40
|
-
$(
|
41
|
-
const
|
42
|
-
$(
|
43
|
-
},
|
44
|
-
const n =
|
35
|
+
})) : [], b = t(e.variables), j = p(e.responsiveVariables), o = x(e.conditionalVariables), w = T(s), y = i(w, "css/variables.css"), c = `:root { ${b.join("")} ${j.join("")} } ${o.join("")}`;
|
36
|
+
$(y, c);
|
37
|
+
const m = i(w, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
38
|
+
$(m, u);
|
39
|
+
const g = i(w, "css/global.css"), d = q(e.global, "");
|
40
|
+
$(g, d);
|
41
|
+
const h = i(w, "css/templates.css"), k = A(e.templates);
|
42
|
+
$(h, k);
|
43
|
+
}, O = async (s, e) => {
|
44
|
+
const n = E(s), t = i(e, "js", n + ".js");
|
45
45
|
await I.build({
|
46
46
|
entryPoints: [s],
|
47
47
|
minify: !0,
|
@@ -53,113 +53,124 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
|
|
53
53
|
keepNames: !0,
|
54
54
|
external: ["react"]
|
55
55
|
});
|
56
|
-
const
|
57
|
-
return await import(`${t}?t=${
|
58
|
-
},
|
59
|
-
const e =
|
56
|
+
const p = Date.now();
|
57
|
+
return await import(`${t}?t=${p}`);
|
58
|
+
}, R = async (s) => {
|
59
|
+
const e = T(s), n = i(e, "salty.config.js"), { config: t } = await import(n);
|
60
60
|
return t;
|
61
61
|
}, ot = async (s) => {
|
62
62
|
try {
|
63
|
-
const e = [], n = [], t =
|
63
|
+
const e = [], n = [], t = T(s), p = i(t, "index.css");
|
64
64
|
(() => {
|
65
|
-
H(t) && z("rm -rf " + t), V(t), V(
|
65
|
+
H(t) && z("rm -rf " + t), V(t), V(i(t, "css")), V(i(t, "types"));
|
66
66
|
})(), await Y(s);
|
67
|
-
const
|
68
|
-
async function
|
69
|
-
const
|
70
|
-
if (
|
71
|
-
const
|
72
|
-
await Promise.all(
|
73
|
-
} else if (
|
74
|
-
const
|
75
|
-
Object.entries(
|
76
|
-
if (
|
77
|
-
const P = `${
|
78
|
-
e.push(P), $(
|
67
|
+
const b = await R(s);
|
68
|
+
async function j(c, m) {
|
69
|
+
const F = K(c);
|
70
|
+
if (F.isDirectory()) {
|
71
|
+
const u = G(c);
|
72
|
+
await Promise.all(u.map((g) => j(i(c, g), i(m, g))));
|
73
|
+
} else if (F.isFile() && v(c)) {
|
74
|
+
const g = await O(c, t), d = [];
|
75
|
+
Object.entries(g).forEach(([l, a]) => {
|
76
|
+
if (a.isKeyframes && a.css) {
|
77
|
+
const P = `${a.animationName}.css`, N = `css/${P}`, _ = i(t, N);
|
78
|
+
e.push(P), $(_, a.css);
|
79
79
|
return;
|
80
80
|
}
|
81
|
-
if (!
|
82
|
-
const r =
|
81
|
+
if (!a.generator) return;
|
82
|
+
const r = a.generator._withBuildContext({
|
83
83
|
name: l,
|
84
|
-
config:
|
85
|
-
}),
|
86
|
-
n[r.priority] || (n[r.priority] = []), n[r.priority].push(
|
87
|
-
const C = `css/${
|
84
|
+
config: b
|
85
|
+
}), S = `${r.hash}-${r.priority}.css`;
|
86
|
+
n[r.priority] || (n[r.priority] = []), n[r.priority].push(S), d.push(S);
|
87
|
+
const C = `css/${S}`, D = i(t, C);
|
88
88
|
$(D, r.css);
|
89
89
|
});
|
90
|
-
const
|
91
|
-
`), k =
|
92
|
-
$(
|
90
|
+
const h = d.map((l) => `@import url('./${l}');`).join(`
|
91
|
+
`), k = E(c, 6), f = i(t, `css/${k}.css`);
|
92
|
+
$(f, h);
|
93
93
|
}
|
94
94
|
}
|
95
|
-
await
|
96
|
-
const
|
95
|
+
await j(s, t);
|
96
|
+
const o = e.map((c) => `@import url('./css/${c}');`).join(`
|
97
97
|
`);
|
98
|
-
let
|
98
|
+
let y = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
99
99
|
|
100
100
|
${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
|
101
101
|
`)}
|
102
|
-
${
|
103
|
-
if (
|
104
|
-
const
|
102
|
+
${o}`;
|
103
|
+
if (b.importStrategy !== "component") {
|
104
|
+
const c = n.flat().map((m) => `@import url('./css/${m}');`).join(`
|
105
105
|
`);
|
106
|
-
|
106
|
+
y += c;
|
107
107
|
}
|
108
|
-
$(
|
108
|
+
$(p, y);
|
109
109
|
} catch (e) {
|
110
110
|
console.error(e);
|
111
111
|
}
|
112
112
|
}, it = async (s, e) => {
|
113
113
|
try {
|
114
|
-
const n = [], t =
|
114
|
+
const n = [], t = i(s, "./saltygen"), p = i(t, "index.css");
|
115
115
|
if (v(e)) {
|
116
|
-
const
|
117
|
-
Object.entries(
|
118
|
-
if (!
|
119
|
-
const
|
120
|
-
name:
|
121
|
-
config:
|
122
|
-
}),
|
123
|
-
n.push(
|
116
|
+
const b = await R(s), j = await O(e, t);
|
117
|
+
Object.entries(j).forEach(([m, F]) => {
|
118
|
+
if (!F.generator) return;
|
119
|
+
const u = F.generator._withBuildContext({
|
120
|
+
name: m,
|
121
|
+
config: b
|
122
|
+
}), g = `${u.hash}-${u.priority}.css`, d = `css/${g}`, h = i(t, d);
|
123
|
+
n.push(g), $(h, u.css);
|
124
124
|
});
|
125
|
-
const
|
126
|
-
`),
|
125
|
+
const o = M(p, "utf8").split(`
|
126
|
+
`), w = n.map((m) => `@import url('../saltygen/css/${m}');`), c = [.../* @__PURE__ */ new Set([...o, ...w])].join(`
|
127
127
|
`);
|
128
|
-
$(
|
128
|
+
$(p, c);
|
129
129
|
}
|
130
130
|
} catch (n) {
|
131
131
|
console.error(n);
|
132
132
|
}
|
133
133
|
}, rt = async (s, e) => {
|
134
134
|
try {
|
135
|
-
const n =
|
135
|
+
const n = i(s, "./saltygen");
|
136
136
|
if (v(e)) {
|
137
|
-
const
|
138
|
-
|
139
|
-
const
|
140
|
-
let
|
141
|
-
Object.entries(
|
142
|
-
var
|
143
|
-
if (
|
144
|
-
const
|
145
|
-
name:
|
146
|
-
config:
|
147
|
-
}),
|
148
|
-
if (!
|
149
|
-
|
150
|
-
|
151
|
-
|
137
|
+
const p = M(e, "utf8");
|
138
|
+
p.replace(/^(?!export\s)const\s.*/gm, (y) => `export ${y}`) !== p && await J(e, p);
|
139
|
+
const b = await R(s), j = await O(e, n);
|
140
|
+
let o = p;
|
141
|
+
Object.entries(j).forEach(([y, c]) => {
|
142
|
+
var P;
|
143
|
+
if (c.isKeyframes || !c.generator) return;
|
144
|
+
const m = c.generator._withBuildContext({
|
145
|
+
name: y,
|
146
|
+
config: b
|
147
|
+
}), F = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(p);
|
148
|
+
if (!F) return console.error("Could not find the original declaration");
|
149
|
+
const u = (P = F.at(1)) == null ? void 0 : P.trim(), g = new RegExp(`${y}[=\\s]+styled\\(`, "g").exec(o);
|
150
|
+
if (!g) return console.error("Could not find the original declaration");
|
151
|
+
const { index: d } = g;
|
152
|
+
let h = !1;
|
153
|
+
const k = setTimeout(() => h = !0, 5e3);
|
154
|
+
let f = 0, l = !1, a = 0;
|
155
|
+
for (; !l && !h; ) {
|
156
|
+
const N = o[d + f];
|
157
|
+
N === "(" && a++, N === ")" && a--, a === 0 && N === ")" && (l = !0), f > o.length && (h = !0), f++;
|
158
|
+
}
|
159
|
+
if (!h) clearTimeout(k);
|
160
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
161
|
+
const r = d + f, S = o.slice(d, r), C = o, D = `${y} = styled(${u}, "${m.classNames}", "${m._callerName}", ${JSON.stringify(m.props)});`;
|
162
|
+
o = o.replace(S, D), C === o && console.error("Minimize file failed to change content", { name: y, tagName: u });
|
152
163
|
});
|
153
|
-
const
|
154
|
-
return
|
155
|
-
${
|
164
|
+
const w = E(e, 6);
|
165
|
+
return b.importStrategy === "component" && (o = `import '../../saltygen/css/${w}.css';
|
166
|
+
${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
156
167
|
}
|
157
168
|
} catch (n) {
|
158
|
-
console.error("Error in minimizeFile", n);
|
169
|
+
console.error("Error in minimizeFile:", n);
|
159
170
|
}
|
160
171
|
};
|
161
172
|
export {
|
162
|
-
|
173
|
+
O as compileSaltyFile,
|
163
174
|
Y as generateConfigStyles,
|
164
175
|
ot as generateCss,
|
165
176
|
it as generateFile,
|