@salty-css/core 0.0.1-alpha.114 → 0.0.1-alpha.116
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/README.md +49 -48
- package/bin/main.cjs +6 -6
- package/bin/main.js +125 -125
- package/compiler/index.cjs +1 -1
- package/compiler/index.js +3 -3
- package/{dash-case-DKzpenwY.cjs → dash-case-8PdMJjFC.cjs} +1 -1
- package/{dash-case-DMQMcCO6.js → dash-case-D_tXuO4I.js} +1 -1
- package/generator/index.cjs +1 -1
- package/generator/index.js +27 -26
- package/index-V5AY9k9D.js +257 -0
- package/index-eyW1pjj1.cjs +21 -0
- package/package.json +1 -1
- package/{parse-templates-BNINfXOG.js → parse-templates-D1FebDfR.js} +30 -30
- package/{parse-templates-C1-wQz7G.cjs → parse-templates-lpgqU05M.cjs} +1 -1
- package/types/index.d.ts +15 -5
- package/util/dot-case.d.ts +1 -0
- package/util/index.cjs +1 -1
- package/util/index.js +1 -1
- package/index-BYjQglAA.js +0 -253
- package/index-Cj4Em07G.cjs +0 -21
@@ -0,0 +1,257 @@
|
|
1
|
+
import * as G from "esbuild";
|
2
|
+
import { execSync as tt } from "child_process";
|
3
|
+
import { t as A, d as K } from "./dash-case-D_tXuO4I.js";
|
4
|
+
import { join as r, parse as et } from "path";
|
5
|
+
import { existsSync as B, writeFileSync as x, mkdirSync as N, readFileSync as V, statSync as st, readdirSync as nt } from "fs";
|
6
|
+
import { readFile as ot, writeFile as rt } from "fs/promises";
|
7
|
+
import { p as at, a as ct, b as it, c as lt } from "./parse-templates-D1FebDfR.js";
|
8
|
+
import { createLogger as pt, format as J, transports as ft } from "winston";
|
9
|
+
const W = (t) => {
|
10
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
11
|
+
const e = r(t, "package.json");
|
12
|
+
return B(e) ? e : W(r(t, ".."));
|
13
|
+
}, ut = async (t) => {
|
14
|
+
const e = W(t);
|
15
|
+
return await ot(e, "utf-8").then(JSON.parse).catch(() => {
|
16
|
+
});
|
17
|
+
}, dt = async (t) => {
|
18
|
+
const e = await ut(t);
|
19
|
+
if (e)
|
20
|
+
return e.type;
|
21
|
+
};
|
22
|
+
let E;
|
23
|
+
const H = async (t) => {
|
24
|
+
if (E) return E;
|
25
|
+
const e = await dt(t);
|
26
|
+
return e === "module" ? E = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (E = "cjs"), E || "esm";
|
27
|
+
}, R = pt({
|
28
|
+
level: "debug",
|
29
|
+
format: J.combine(J.colorize(), J.cli()),
|
30
|
+
transports: [new ft.Console({})]
|
31
|
+
}), Ft = (t) => {
|
32
|
+
R.error(t);
|
33
|
+
};
|
34
|
+
function L(t) {
|
35
|
+
return t ? typeof t != "string" ? L(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, a) => (a > 0 ? "." : "") + e.toLowerCase()) : "";
|
36
|
+
}
|
37
|
+
const O = {
|
38
|
+
externalModules: []
|
39
|
+
}, q = (t) => {
|
40
|
+
if (O.externalModules.length > 0) return O.externalModules;
|
41
|
+
const e = r(t, "salty.config.ts"), s = V(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
42
|
+
if (!s) return [];
|
43
|
+
const n = s[1].split(",").map((l) => l.replace(/['"`]/g, "").trim());
|
44
|
+
return O.externalModules = n, n;
|
45
|
+
}, v = (t) => r(t, "./saltygen"), gt = ["salty", "css", "styles", "styled"], mt = (t = []) => new RegExp(`\\.(${[...gt, ...t].join("|")})\\.`), I = (t, e = []) => mt(e).test(t), yt = async (t) => {
|
46
|
+
const e = v(t), a = r(t, "salty.config.ts"), s = r(e, "salty.config.js"), n = await H(t), l = q(t);
|
47
|
+
await G.build({
|
48
|
+
entryPoints: [a],
|
49
|
+
minify: !0,
|
50
|
+
treeShaking: !0,
|
51
|
+
bundle: !0,
|
52
|
+
outfile: s,
|
53
|
+
format: n,
|
54
|
+
external: l
|
55
|
+
});
|
56
|
+
const b = Date.now(), { config: f } = await import(`${s}?t=${b}`);
|
57
|
+
return f;
|
58
|
+
}, ht = async (t) => {
|
59
|
+
const e = await yt(t), a = /* @__PURE__ */ new Set(), s = (i, p = []) => i ? Object.entries(i).flatMap(([g, u]) => {
|
60
|
+
if (!u) return;
|
61
|
+
if (typeof u == "object") return s(u, [...p, g]);
|
62
|
+
const F = L(g), y = K(g), h = [...p, F].join(".");
|
63
|
+
a.add(`"${h}"`);
|
64
|
+
const j = [...p.map(K), y].join("-"), { result: P } = lt(u);
|
65
|
+
return `--${j}: ${P};`;
|
66
|
+
}) : [], n = (i) => i ? Object.entries(i).flatMap(([p, g]) => {
|
67
|
+
const u = s(g);
|
68
|
+
return p === "base" ? u.join("") : `${p} { ${u.join("")} }`;
|
69
|
+
}) : [], l = (i) => i ? Object.entries(i).flatMap(([p, g]) => Object.entries(g).flatMap(([u, F]) => {
|
70
|
+
const y = s(F, [p]), h = `.${p}-${u}, [data-${p}="${u}"]`, j = y.join("");
|
71
|
+
return `${h} { ${j} }`;
|
72
|
+
})) : [], b = s(e.variables), f = n(e.responsiveVariables), $ = l(e.conditionalVariables), o = v(t), D = r(o, "css/variables.css"), d = `:root { ${b.join("")} ${f.join("")} } ${$.join("")}`;
|
73
|
+
x(D, d);
|
74
|
+
const w = r(o, "css/global.css"), S = at(e.global, "");
|
75
|
+
x(w, S);
|
76
|
+
const c = r(o, "css/templates.css"), m = ct(e.templates), k = it(e.templates);
|
77
|
+
x(c, m);
|
78
|
+
const C = r(o, "types/css-tokens.d.ts"), M = `
|
79
|
+
// Variable types
|
80
|
+
type VariableTokens = ${[...a].join("|")};
|
81
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
82
|
+
|
83
|
+
// Template types
|
84
|
+
type TemplateTokens = {
|
85
|
+
${Object.entries(k).map(([i, p]) => `${i}?: ${p}`).join(`
|
86
|
+
`)}
|
87
|
+
}
|
88
|
+
`;
|
89
|
+
x(C, M);
|
90
|
+
}, Z = async (t, e, a) => {
|
91
|
+
const s = A(e), n = r(a, "./temp");
|
92
|
+
B(n) || N(n);
|
93
|
+
const l = et(e);
|
94
|
+
let b = V(e, "utf8");
|
95
|
+
b = b.replace(/styled\([^"'`{,]+,/g, "styled('div',");
|
96
|
+
const f = r(a, "js", s + ".js"), $ = q(t), o = await H(t);
|
97
|
+
await G.build({
|
98
|
+
stdin: {
|
99
|
+
contents: b,
|
100
|
+
sourcefile: l.base,
|
101
|
+
resolveDir: l.dir,
|
102
|
+
loader: "tsx"
|
103
|
+
},
|
104
|
+
minify: !1,
|
105
|
+
treeShaking: !0,
|
106
|
+
bundle: !0,
|
107
|
+
outfile: f,
|
108
|
+
format: o,
|
109
|
+
target: ["node20"],
|
110
|
+
keepNames: !0,
|
111
|
+
external: $,
|
112
|
+
packages: "external"
|
113
|
+
});
|
114
|
+
const D = Date.now();
|
115
|
+
return await import(`${f}?t=${D}`);
|
116
|
+
}, _ = async (t) => {
|
117
|
+
const e = v(t), a = r(e, "salty.config.js"), { config: s } = await import(a);
|
118
|
+
return s;
|
119
|
+
}, U = () => {
|
120
|
+
try {
|
121
|
+
return process.env.NODE_ENV === "production";
|
122
|
+
} catch {
|
123
|
+
return !1;
|
124
|
+
}
|
125
|
+
}, kt = async (t, e = U()) => {
|
126
|
+
try {
|
127
|
+
e ? R.info("Generating CSS in production mode! 🔥") : R.info("Generating CSS in development mode! 🚀");
|
128
|
+
const a = [], s = [], n = v(t), l = r(n, "index.css");
|
129
|
+
(() => {
|
130
|
+
B(n) && tt("rm -rf " + n), N(n), N(r(n, "css")), N(r(n, "types"));
|
131
|
+
})(), await ht(t);
|
132
|
+
const f = await _(t);
|
133
|
+
async function $(c, m) {
|
134
|
+
const k = ["node_modules", "saltygen"], C = st(c);
|
135
|
+
if (C.isDirectory()) {
|
136
|
+
const T = nt(c);
|
137
|
+
if (k.some((i) => c.includes(i))) return;
|
138
|
+
await Promise.all(T.map((i) => $(r(c, i), r(m, i))));
|
139
|
+
} else if (C.isFile() && I(c)) {
|
140
|
+
const M = await Z(t, c, n), i = [];
|
141
|
+
Object.entries(M).forEach(([F, y]) => {
|
142
|
+
if (y.isKeyframes && y.css) {
|
143
|
+
const z = `${y.animationName}.css`, Y = `css/${z}`, Q = r(n, Y);
|
144
|
+
a.push(z), x(Q, y.css);
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
if (!y.generator) return;
|
148
|
+
const h = y.generator._withBuildContext({
|
149
|
+
name: F,
|
150
|
+
config: f,
|
151
|
+
prod: e
|
152
|
+
}), j = `${h.hash}-${h.priority}.css`;
|
153
|
+
s[h.priority] || (s[h.priority] = []), s[h.priority].push(j), i.push(j);
|
154
|
+
const P = `css/${j}`, X = r(n, P);
|
155
|
+
x(X, h.css);
|
156
|
+
});
|
157
|
+
const p = i.map((F) => `@import url('./${F}');`).join(`
|
158
|
+
`), g = A(c, 6), u = r(n, `css/${g}.css`);
|
159
|
+
x(u, p);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
await $(t, n);
|
163
|
+
const o = a.map((c) => `@import url('./css/${c}');`).join(`
|
164
|
+
`);
|
165
|
+
let S = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
166
|
+
|
167
|
+
${["variables.css", "global.css", "templates.css"].filter((c) => {
|
168
|
+
try {
|
169
|
+
return V(r(n, "css", c), "utf8").length > 0;
|
170
|
+
} catch {
|
171
|
+
return !1;
|
172
|
+
}
|
173
|
+
}).map((c) => `@import url('./css/${c}');`).join(`
|
174
|
+
`)}
|
175
|
+
${o}`;
|
176
|
+
if (f.importStrategy !== "component") {
|
177
|
+
const c = s.flat().map((m) => `@import url('./css/${m}');`).join(`
|
178
|
+
`);
|
179
|
+
S += c;
|
180
|
+
}
|
181
|
+
x(l, S);
|
182
|
+
} catch (a) {
|
183
|
+
console.error(a);
|
184
|
+
}
|
185
|
+
}, Tt = async (t, e) => {
|
186
|
+
try {
|
187
|
+
const a = [], s = r(t, "./saltygen"), n = r(s, "index.css");
|
188
|
+
if (I(e)) {
|
189
|
+
const b = await _(t), f = await Z(t, e, s);
|
190
|
+
Object.entries(f).forEach(([w, S]) => {
|
191
|
+
if (!S.generator) return;
|
192
|
+
const c = S.generator._withBuildContext({
|
193
|
+
name: w,
|
194
|
+
config: b
|
195
|
+
}), m = `${c.hash}-${c.priority}.css`, k = `css/${m}`, C = r(s, k);
|
196
|
+
a.push(m), x(C, c.css);
|
197
|
+
});
|
198
|
+
const $ = V(n, "utf8").split(`
|
199
|
+
`), o = a.map((w) => `@import url('../saltygen/css/${w}');`), d = [.../* @__PURE__ */ new Set([...$, ...o])].join(`
|
200
|
+
`);
|
201
|
+
x(n, d);
|
202
|
+
}
|
203
|
+
} catch (a) {
|
204
|
+
console.error(a);
|
205
|
+
}
|
206
|
+
}, Dt = async (t, e, a = U()) => {
|
207
|
+
try {
|
208
|
+
const s = r(t, "./saltygen");
|
209
|
+
if (I(e)) {
|
210
|
+
const l = V(e, "utf8");
|
211
|
+
l.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== l && await rt(e, l);
|
212
|
+
const f = await _(t), $ = await Z(t, e, s);
|
213
|
+
let o = l;
|
214
|
+
Object.entries($).forEach(([d, w]) => {
|
215
|
+
var j;
|
216
|
+
if (w.isKeyframes || !w.generator) return;
|
217
|
+
const S = w.generator._withBuildContext({
|
218
|
+
name: d,
|
219
|
+
config: f,
|
220
|
+
prod: a
|
221
|
+
}), c = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(l);
|
222
|
+
if (!c) return console.error("Could not find the original declaration");
|
223
|
+
const m = (j = c.at(1)) == null ? void 0 : j.trim(), k = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(o);
|
224
|
+
if (!k) return console.error("Could not find the original declaration");
|
225
|
+
const { index: C } = k;
|
226
|
+
let T = !1;
|
227
|
+
const M = setTimeout(() => T = !0, 5e3);
|
228
|
+
let i = 0, p = !1, g = 0;
|
229
|
+
for (; !p && !T; ) {
|
230
|
+
const P = o[C + i];
|
231
|
+
P === "(" && g++, P === ")" && g--, g === 0 && P === ")" && (p = !0), i > o.length && (T = !0), i++;
|
232
|
+
}
|
233
|
+
if (!T) clearTimeout(M);
|
234
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
235
|
+
const u = C + i, F = o.slice(C, u), y = o, h = ` ${d} = styled(${m}, "${S.classNames}", ${JSON.stringify(S.props)});`;
|
236
|
+
o = o.replace(F, h), y === o && console.error("Minimize file failed to change content", { name: d, tagName: m });
|
237
|
+
});
|
238
|
+
const D = A(e, 6);
|
239
|
+
return f.importStrategy === "component" && (o = `import '../../saltygen/css/${D}.css';
|
240
|
+
${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
241
|
+
}
|
242
|
+
} catch (s) {
|
243
|
+
console.error("Error in minimizeFile:", s);
|
244
|
+
}
|
245
|
+
};
|
246
|
+
export {
|
247
|
+
Ft as a,
|
248
|
+
mt as b,
|
249
|
+
ht as c,
|
250
|
+
Z as d,
|
251
|
+
Tt as e,
|
252
|
+
kt as g,
|
253
|
+
I as i,
|
254
|
+
R as l,
|
255
|
+
Dt as m,
|
256
|
+
gt as s
|
257
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";const se=require("esbuild"),ne=require("child_process"),O=require("./dash-case-8PdMJjFC.cjs"),o=require("path"),a=require("fs"),B=require("fs/promises"),V=require("./parse-templates-lpgqU05M.cjs"),N=require("winston");var q=typeof document<"u"?document.currentScript:null;function oe(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const Z=oe(se),H=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return a.existsSync(t)?t:H(o.join(e,".."))},ie=async e=>{const t=H(e);return await B.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},re=async e=>{const t=await ie(e);if(t)return t.type};let M;const K=async e=>{if(M)return M;const t=await re(e);return t==="module"?M="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:q&&q.tagName.toUpperCase()==="SCRIPT"&&q.src||new URL("index-eyW1pjj1.cjs",document.baseURI).href).endsWith(".cjs"))&&(M="cjs"),M||"esm"},v=N.createLogger({level:"debug",format:N.format.combine(N.format.colorize(),N.format.cli()),transports:[new N.transports.Console({})]}),ce=e=>{v.error(e)};function L(e){return e?typeof e!="string"?L(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const I={externalModules:[]},U=e=>{if(I.externalModules.length>0)return I.externalModules;const t=o.join(e,"salty.config.ts"),n=a.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const i=n[1].split(",").map(u=>u.replace(/['"`]/g,"").trim());return I.externalModules=i,i},R=e=>o.join(e,"./saltygen"),G=["salty","css","styles","styled"],W=(e=[])=>new RegExp(`\\.(${[...G,...e].join("|")})\\.`),_=(e,t=[])=>W(t).test(e),ae=async e=>{const t=R(e),s=o.join(e,"salty.config.ts"),n=o.join(t,"salty.config.js"),i=await K(e),u=U(e);await Z.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:i,external:u});const S=Date.now(),{config:f}=await import(`${n}?t=${S}`);return f},X=async e=>{const t=await ae(e),s=new Set,n=(l,p=[])=>l?Object.entries(l).flatMap(([y,d])=>{if(!d)return;if(typeof d=="object")return n(d,[...p,y]);const x=L(y),h=O.dashCase(y),j=[...p,x].join(".");s.add(`"${j}"`);const C=[...p.map(O.dashCase),h].join("-"),{result:D}=V.parseValueTokens(d);return`--${C}: ${D};`}):[],i=l=>l?Object.entries(l).flatMap(([p,y])=>{const d=n(y);return p==="base"?d.join(""):`${p} { ${d.join("")} }`}):[],u=l=>l?Object.entries(l).flatMap(([p,y])=>Object.entries(y).flatMap(([d,x])=>{const h=n(x,[p]),j=`.${p}-${d}, [data-${p}="${d}"]`,C=h.join("");return`${j} { ${C} }`})):[],S=n(t.variables),f=i(t.responsiveVariables),b=u(t.conditionalVariables),r=R(e),P=o.join(r,"css/variables.css"),g=`:root { ${S.join("")} ${f.join("")} } ${b.join("")}`;a.writeFileSync(P,g);const w=o.join(r,"css/global.css"),F=V.parseStyles(t.global,"");a.writeFileSync(w,F);const c=o.join(r,"css/templates.css"),m=V.parseTemplates(t.templates),k=V.getTemplateTypes(t.templates);a.writeFileSync(c,m);const $=o.join(r,"types/css-tokens.d.ts"),E=`
|
2
|
+
// Variable types
|
3
|
+
type VariableTokens = ${[...s].join("|")};
|
4
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
+
|
6
|
+
// Template types
|
7
|
+
type TemplateTokens = {
|
8
|
+
${Object.entries(k).map(([l,p])=>`${l}?: ${p}`).join(`
|
9
|
+
`)}
|
10
|
+
}
|
11
|
+
`;a.writeFileSync($,E)},J=async(e,t,s)=>{const n=O.toHash(t),i=o.join(s,"./temp");a.existsSync(i)||a.mkdirSync(i);const u=o.parse(t);let S=a.readFileSync(t,"utf8");S=S.replace(/styled\([^"'`{,]+,/g,"styled('div',");const f=o.join(s,"js",n+".js"),b=U(e),r=await K(e);await Z.build({stdin:{contents:S,sourcefile:u.base,resolveDir:u.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:f,format:r,target:["node20"],keepNames:!0,external:b,packages:"external"});const P=Date.now();return await import(`${f}?t=${P}`)},z=async e=>{const t=R(e),s=o.join(t,"salty.config.js"),{config:n}=await import(s);return n},Y=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},le=async(e,t=Y())=>{try{t?v.info("Generating CSS in production mode! 🔥"):v.info("Generating CSS in development mode! 🚀");const s=[],n=[],i=R(e),u=o.join(i,"index.css");(()=>{a.existsSync(i)&&ne.execSync("rm -rf "+i),a.mkdirSync(i),a.mkdirSync(o.join(i,"css")),a.mkdirSync(o.join(i,"types"))})(),await X(e);const f=await z(e);async function b(c,m){const k=["node_modules","saltygen"],$=a.statSync(c);if($.isDirectory()){const T=a.readdirSync(c);if(k.some(l=>c.includes(l)))return;await Promise.all(T.map(l=>b(o.join(c,l),o.join(m,l))))}else if($.isFile()&&_(c)){const E=await J(e,c,i),l=[];Object.entries(E).forEach(([x,h])=>{if(h.isKeyframes&&h.css){const A=`${h.animationName}.css`,ee=`css/${A}`,te=o.join(i,ee);s.push(A),a.writeFileSync(te,h.css);return}if(!h.generator)return;const j=h.generator._withBuildContext({name:x,config:f,prod:t}),C=`${j.hash}-${j.priority}.css`;n[j.priority]||(n[j.priority]=[]),n[j.priority].push(C),l.push(C);const D=`css/${C}`,Q=o.join(i,D);a.writeFileSync(Q,j.css)});const p=l.map(x=>`@import url('./${x}');`).join(`
|
12
|
+
`),y=O.toHash(c,6),d=o.join(i,`css/${y}.css`);a.writeFileSync(d,p)}}await b(e,i);const r=s.map(c=>`@import url('./css/${c}');`).join(`
|
13
|
+
`);let F=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
14
|
+
|
15
|
+
${["variables.css","global.css","templates.css"].filter(c=>{try{return a.readFileSync(o.join(i,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
|
16
|
+
`)}
|
17
|
+
${r}`;if(f.importStrategy!=="component"){const c=n.flat().map(m=>`@import url('./css/${m}');`).join(`
|
18
|
+
`);F+=c}a.writeFileSync(u,F)}catch(s){console.error(s)}},ue=async(e,t)=>{try{const s=[],n=o.join(e,"./saltygen"),i=o.join(n,"index.css");if(_(t)){const S=await z(e),f=await J(e,t,n);Object.entries(f).forEach(([w,F])=>{if(!F.generator)return;const c=F.generator._withBuildContext({name:w,config:S}),m=`${c.hash}-${c.priority}.css`,k=`css/${m}`,$=o.join(n,k);s.push(m),a.writeFileSync($,c.css)});const b=a.readFileSync(i,"utf8").split(`
|
19
|
+
`),r=s.map(w=>`@import url('../saltygen/css/${w}');`),g=[...new Set([...b,...r])].join(`
|
20
|
+
`);a.writeFileSync(i,g)}}catch(s){console.error(s)}},pe=async(e,t,s=Y())=>{try{const n=o.join(e,"./saltygen");if(_(t)){const u=a.readFileSync(t,"utf8");u.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==u&&await B.writeFile(t,u);const f=await z(e),b=await J(e,t,n);let r=u;Object.entries(b).forEach(([g,w])=>{var C;if(w.isKeyframes||!w.generator)return;const F=w.generator._withBuildContext({name:g,config:f,prod:s}),c=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(u);if(!c)return console.error("Could not find the original declaration");const m=(C=c.at(1))==null?void 0:C.trim(),k=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(r);if(!k)return console.error("Could not find the original declaration");const{index:$}=k;let T=!1;const E=setTimeout(()=>T=!0,5e3);let l=0,p=!1,y=0;for(;!p&&!T;){const D=r[$+l];D==="("&&y++,D===")"&&y--,y===0&&D===")"&&(p=!0),l>r.length&&(T=!0),l++}if(!T)clearTimeout(E);else throw new Error("Failed to find the end of the styled call and timed out");const d=$+l,x=r.slice($,d),h=r,j=` ${g} = styled(${m}, "${F.classNames}", ${JSON.stringify(F.props)});`;r=r.replace(x,j),h===r&&console.error("Minimize file failed to change content",{name:g,tagName:m})});const P=O.toHash(t,6);return f.importStrategy==="component"&&(r=`import '../../saltygen/css/${P}.css';
|
21
|
+
${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=J;exports.generateConfigStyles=X;exports.generateCss=le;exports.generateFile=ue;exports.isSaltyFile=_;exports.logError=ce;exports.logger=v;exports.minimizeFile=pe;exports.saltyFileExtensions=G;exports.saltyFileRegExp=W;
|
package/package.json
CHANGED
@@ -1,95 +1,95 @@
|
|
1
|
-
import { d as O } from "./dash-case-
|
2
|
-
const N = (t,
|
1
|
+
import { d as O } from "./dash-case-D_tXuO4I.js";
|
2
|
+
const N = (t, e) => {
|
3
3
|
if (typeof t != "string") return { result: t };
|
4
|
-
if (!
|
4
|
+
if (!e) return { result: t };
|
5
5
|
const s = [];
|
6
|
-
return Object.values(
|
6
|
+
return Object.values(e).forEach((n) => {
|
7
7
|
const { pattern: o, transform: i } = n;
|
8
8
|
t = t.replace(o, (d) => {
|
9
9
|
const { value: c, css: j } = i(d);
|
10
10
|
return j && s.push(j), c;
|
11
11
|
});
|
12
12
|
}), { result: t, additionalCss: s };
|
13
|
-
}, P = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, a = (t,
|
13
|
+
}, P = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, a = (t, e, s, n) => {
|
14
14
|
if (!t) return "";
|
15
|
-
const o = [], i = Object.entries(t).reduce((c, [j,
|
15
|
+
const o = [], i = Object.entries(t).reduce((c, [j, r]) => {
|
16
16
|
const f = j.trim();
|
17
|
-
if (typeof
|
18
|
-
if (!
|
17
|
+
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
18
|
+
if (!r) return c;
|
19
19
|
if (f === "variants")
|
20
|
-
return Object.entries(
|
20
|
+
return Object.entries(r).forEach(([p, u]) => {
|
21
21
|
u && Object.entries(u).forEach(([m, b]) => {
|
22
22
|
if (!b) return;
|
23
|
-
const y = `${
|
23
|
+
const y = `${e}.${p}-${m}`, l = a(b, y, s);
|
24
24
|
o.push(l);
|
25
25
|
});
|
26
26
|
}), c;
|
27
27
|
if (f === "defaultVariants")
|
28
28
|
return c;
|
29
29
|
if (f === "compoundVariants")
|
30
|
-
return
|
31
|
-
const { css: u, ...m } = p, b = Object.entries(m).reduce((l, [w, W]) => `${l}.${w}-${W}`,
|
30
|
+
return r.forEach((p) => {
|
31
|
+
const { css: u, ...m } = p, b = Object.entries(m).reduce((l, [w, W]) => `${l}.${w}-${W}`, e), y = a(u, b, s);
|
32
32
|
o.push(y);
|
33
33
|
}), c;
|
34
34
|
if (f.startsWith("@")) {
|
35
|
-
const p = a(
|
35
|
+
const p = a(r, e, s), u = `${f} {
|
36
36
|
${p.replace(`
|
37
37
|
`, `
|
38
38
|
`)}
|
39
39
|
}`;
|
40
40
|
return o.push(u), c;
|
41
41
|
}
|
42
|
-
const $ = j.includes("&") ? f.replace("&",
|
42
|
+
const $ = j.includes("&") ? f.replace("&", e) : f.startsWith(":") ? `${e}${f}` : `${e} ${f}`, h = a(r, $, s);
|
43
43
|
return o.push(h), c;
|
44
44
|
}
|
45
45
|
if (n != null && n.templates && n.templates[f]) {
|
46
|
-
const h =
|
46
|
+
const h = r.split(".").reduce((p, u) => p[u], n.templates[f]);
|
47
47
|
if (h) {
|
48
48
|
const p = a(h, "");
|
49
49
|
return `${c}${p}`;
|
50
50
|
}
|
51
|
-
return console.warn(`Template "${f}" with path of "${
|
51
|
+
return console.warn(`Template "${f}" with path of "${r}" was not found in config!`), c;
|
52
52
|
}
|
53
53
|
const S = f.startsWith("-") ? f : O(f), g = ($, h = ";") => c = `${c}${$}${h}`, T = ($) => g(`${S}:${$}`);
|
54
|
-
if (typeof
|
55
|
-
if (typeof
|
56
|
-
if ("toString" in
|
54
|
+
if (typeof r == "number") return T(r);
|
55
|
+
if (typeof r != "string")
|
56
|
+
if ("toString" in r) r = r.toString();
|
57
57
|
else return c;
|
58
58
|
const { modifiers: V } = n || {}, k = function* () {
|
59
|
-
yield P(
|
59
|
+
yield P(r), yield N(r, V);
|
60
60
|
}();
|
61
61
|
for (const { result: $, additionalCss: h = [] } of k)
|
62
|
-
|
62
|
+
r = $, h.forEach((p) => {
|
63
63
|
const u = a(p, "");
|
64
64
|
g(u, "");
|
65
65
|
});
|
66
|
-
return T(
|
66
|
+
return T(r);
|
67
67
|
}, "");
|
68
68
|
if (!i) return o.join(`
|
69
69
|
`);
|
70
|
-
if (!
|
70
|
+
if (!e) return i;
|
71
71
|
let d = "";
|
72
|
-
return s !== void 0 ? d = `@layer l${s} { ${
|
72
|
+
return s !== void 0 ? d = `@layer l${s} { ${e} { ${i} } }` : d = `${e} { ${i} }`, [d, ...o].join(`
|
73
73
|
`);
|
74
|
-
}, _ = (t,
|
74
|
+
}, _ = (t, e = []) => {
|
75
75
|
if (!t) return "";
|
76
76
|
const s = [], n = {};
|
77
77
|
if (Object.entries(t).forEach(([o, i]) => {
|
78
78
|
if (typeof i == "object") {
|
79
79
|
if (!i) return;
|
80
|
-
const d = o.trim(), c = _(i, [...
|
80
|
+
const d = o.trim(), c = _(i, [...e, d]);
|
81
81
|
s.push(c);
|
82
82
|
} else
|
83
83
|
n[o] = i;
|
84
84
|
}), Object.keys(n).length) {
|
85
|
-
const o =
|
85
|
+
const o = e.map(O).join("-"), i = a(n, `.${o}`);
|
86
86
|
s.push(i);
|
87
87
|
}
|
88
88
|
return s.join(`
|
89
89
|
`);
|
90
|
-
}, A = (t) => Object.keys(t), K = (t) => Object.entries(t).reduce((
|
91
|
-
const i =
|
92
|
-
return typeof o == "object" ? E(o, i, s) : s.add(
|
90
|
+
}, A = (t) => Object.keys(t), K = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = E(n).map((o) => `"${o}"`).join(" | ")), e), {}), E = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
91
|
+
const i = e ? `${e}.${n}` : n;
|
92
|
+
return typeof o == "object" ? E(o, i, s) : s.add(e);
|
93
93
|
}), [...s]) : [];
|
94
94
|
export {
|
95
95
|
_ as a,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";const T=require("./dash-case-
|
1
|
+
"use strict";const T=require("./dash-case-8PdMJjFC.cjs"),N=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const r=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:i}=n;t=t.replace(o,d=>{const{value:c,css:j}=i(d);return j&&r.push(j),c})}),{result:t,additionalCss:r}},S=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${T.dashCase(n[1].replaceAll(".","-"))})`)}:{result:t},a=(t,e,r,n)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((c,[j,s])=>{const p=j.trim();if(typeof s=="function"&&(s=s()),typeof s=="object"){if(!s)return c;if(p==="variants")return Object.entries(s).forEach(([f,u])=>{u&&Object.entries(u).forEach(([l,m])=>{if(!m)return;const y=`${e}.${f}-${l}`,b=a(m,y,r);o.push(b)})}),c;if(p==="defaultVariants")return c;if(p==="compoundVariants")return s.forEach(f=>{const{css:u,...l}=f,m=Object.entries(l).reduce((b,[q,K])=>`${b}.${q}-${K}`,e),y=a(u,m,r);o.push(y)}),c;if(p.startsWith("@")){const f=a(s,e,r),u=`${p} {
|
2
2
|
${f.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
package/types/index.d.ts
CHANGED
@@ -26,12 +26,13 @@ type CssProperties = {
|
|
26
26
|
};
|
27
27
|
type CssPropertyKeys = keyof CssProperties;
|
28
28
|
export type StyleValue<K extends string> = K extends CssPropertyKeys ? CssProperties[K] : never;
|
29
|
-
type InvalidVariantKeys = '';
|
29
|
+
type InvalidVariantKeys = '' | 'css';
|
30
30
|
type VariantOptions = {
|
31
31
|
[key in InvalidVariantKeys]?: never;
|
32
32
|
};
|
33
33
|
export type CompoundVariant = {
|
34
|
-
[key: PropertyKey]:
|
34
|
+
[key: PropertyKey]: string | boolean | undefined;
|
35
|
+
} | {
|
35
36
|
css: CssStyles;
|
36
37
|
};
|
37
38
|
type Variants = {
|
@@ -46,10 +47,19 @@ type Variants = {
|
|
46
47
|
compoundVariants?: CompoundVariant[];
|
47
48
|
};
|
48
49
|
type BooleanVariantValue = 'true' | 'false' | boolean;
|
49
|
-
type VariantPropValue<T> = T extends 'true' ? BooleanVariantValue : T extends 'false' ? BooleanVariantValue : T;
|
50
|
-
|
51
|
-
[
|
50
|
+
type VariantPropValue<T> = T extends 'true' ? BooleanVariantValue : T extends 'false' ? BooleanVariantValue : T extends boolean ? BooleanVariantValue : T | '';
|
51
|
+
type PickType<T, K extends AllKeys<T>> = T extends {
|
52
|
+
[k in K]?: any;
|
53
|
+
} ? T[K] : undefined;
|
54
|
+
type AllKeys<T> = T extends any ? keyof T : never;
|
55
|
+
export type Merge<T> = {
|
56
|
+
[k in AllKeys<T>]?: PickType<T, k>;
|
52
57
|
};
|
58
|
+
export type VariantProps<STYLES extends StyledParams, B = STYLES['variants'] extends undefined ? object : STYLES['variants'], C = STYLES['compoundVariants'] extends CompoundVariant[] ? Merge<STYLES['compoundVariants'][number]> : object> = Merge<{
|
59
|
+
[K in keyof B]?: K extends 'css' ? never : VariantPropValue<keyof B[K]>;
|
60
|
+
} | {
|
61
|
+
[K in keyof C]?: K extends 'css' ? never : VariantPropValue<C[K]>;
|
62
|
+
}>;
|
53
63
|
type CssValuePropKey = `props-${string}`;
|
54
64
|
export type ValueProps = {
|
55
65
|
[key: CssValuePropKey]: string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function dotCase(str: PropertyKey): string;
|
package/util/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../dash-case-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../dash-case-8PdMJjFC.cjs"),t=require("../pascal-case-iWoaJWwT.cjs");function s(e){return e?typeof e!="string"?s(String(e)):e.replace(/\s/g,"-").replace(/-([a-z])/g,r=>r[1].toUpperCase()):""}exports.dashCase=a.dashCase;exports.toHash=a.toHash;exports.pascalCase=t.pascalCase;exports.camelCase=s;
|
package/util/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { d as o, t as s } from "../dash-case-
|
1
|
+
import { d as o, t as s } from "../dash-case-D_tXuO4I.js";
|
2
2
|
import { p as f } from "../pascal-case-BQpR5PdN.js";
|
3
3
|
function r(e) {
|
4
4
|
return e ? typeof e != "string" ? r(String(e)) : e.replace(/\s/g, "-").replace(/-([a-z])/g, (a) => a[1].toUpperCase()) : "";
|