@salty-css/webpack 0.0.1-alpha.4 → 0.0.1-alpha.40
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 +77 -26
- package/index-BDOd3CmD.js +259 -0
- package/index-zWFfFoCI.cjs +18 -0
- package/index.cjs +1 -4
- package/index.d.ts +3 -7
- package/index.js +19 -98
- package/loader.cjs +1 -0
- package/loader.d.ts +7 -0
- package/loader.js +8 -0
- package/package.json +6 -1
package/README.md
CHANGED
@@ -1,15 +1,62 @@
|
|
1
|
-
# Salty
|
1
|
+
# Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
|
2
2
|
|
3
|
-
|
3
|
+
In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
|
4
4
|
|
5
|
-
|
5
|
+
## Features
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
- Build time compilation to achieve awesome runtime performance and minimal size
|
8
|
+
- Next.js, React Server Components, Vite and Webpack support
|
9
|
+
- Type safety with out of the box TypeScript and ESLint plugin
|
10
|
+
- Advanced CSS variables configuration to allow smooth token usage
|
11
|
+
- Style templates to create reusable styles easily
|
11
12
|
|
12
|
-
|
13
|
+
## Get started
|
14
|
+
|
15
|
+
### TL;DR
|
16
|
+
|
17
|
+
- Initialize: `npx salty-css init [directory]`
|
18
|
+
- Create component: `npx salty-css generate [filePath]`
|
19
|
+
- Build: `npx salty-css build [directory]`
|
20
|
+
|
21
|
+
### Quick way of using `salty-css` CLI
|
22
|
+
|
23
|
+
#### Initialize Salty CSS for a project
|
24
|
+
|
25
|
+
In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc` which contains some metadata for future CLI commands.
|
26
|
+
|
27
|
+
#### Create components
|
28
|
+
|
29
|
+
Components can be created with `npx salty-css generate [filePath]` which then creates a new Salty CSS component file to the specified path. Additional options like `--dir, --tag, --name and --className` are also supported. Read more about them with `npx salty-css generate --help`
|
30
|
+
|
31
|
+
#### Build / Compile Salty CSS
|
32
|
+
|
33
|
+
If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
|
34
|
+
|
35
|
+
#### Update Salty CSS packages
|
36
|
+
|
37
|
+
To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
|
38
|
+
|
39
|
+
### Manual work
|
40
|
+
|
41
|
+
#### React
|
42
|
+
|
43
|
+
1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
|
44
|
+
2. Create `salty.config.ts` to your app directory
|
45
|
+
|
46
|
+
#### Vite
|
47
|
+
|
48
|
+
1. First check the instructions for React
|
49
|
+
2. For Vite support install `npm i -D @salty-css/vite`
|
50
|
+
3. In `vite.config.ts` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
|
51
|
+
4. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
52
|
+
|
53
|
+
### Create components
|
54
|
+
|
55
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
56
|
+
|
57
|
+
## Code examples
|
58
|
+
|
59
|
+
### Basic usage example with Button
|
13
60
|
|
14
61
|
**Salty config**
|
15
62
|
|
@@ -54,8 +101,10 @@ export const IndexPage = () => {
|
|
54
101
|
import { styled } from '@salty-css/react/styled';
|
55
102
|
|
56
103
|
export const Wrapper = styled('div', {
|
57
|
-
|
58
|
-
|
104
|
+
base: {
|
105
|
+
display: 'block',
|
106
|
+
padding: '2vw',
|
107
|
+
},
|
59
108
|
});
|
60
109
|
```
|
61
110
|
|
@@ -65,22 +114,24 @@ export const Wrapper = styled('div', {
|
|
65
114
|
import { styled } from '@salty-css/react/styled';
|
66
115
|
|
67
116
|
export const Button = styled('button', {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
117
|
+
base: {
|
118
|
+
display: 'block',
|
119
|
+
padding: `0.6em 1.2em`,
|
120
|
+
border: '1px solid currentColor',
|
121
|
+
background: 'transparent',
|
122
|
+
color: 'currentColor/40',
|
123
|
+
cursor: 'pointer',
|
124
|
+
transition: '200ms',
|
125
|
+
textDecoration: 'none',
|
126
|
+
'&:hover': {
|
127
|
+
background: 'black',
|
128
|
+
borderColor: 'black',
|
129
|
+
color: 'white',
|
130
|
+
},
|
131
|
+
'&:disabled': {
|
132
|
+
opacity: 0.25,
|
133
|
+
pointerEvents: 'none',
|
134
|
+
},
|
84
135
|
},
|
85
136
|
variants: {
|
86
137
|
variant: {
|
@@ -0,0 +1,259 @@
|
|
1
|
+
import * as Z from "esbuild";
|
2
|
+
import { execSync as J } from "child_process";
|
3
|
+
import { join as p } from "path";
|
4
|
+
import { writeFileSync as x, readFileSync as I, existsSync as K, mkdirSync as E, statSync as q, readdirSync as G } from "fs";
|
5
|
+
import { writeFile as L } from "fs/promises";
|
6
|
+
const _ = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), U = (t, s) => {
|
7
|
+
let e = "", n;
|
8
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = _(n % 52) + e;
|
9
|
+
return e = _(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
|
10
|
+
}, X = (t, s) => {
|
11
|
+
let e = s.length;
|
12
|
+
for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
|
13
|
+
return t;
|
14
|
+
}, T = (t, s = 3) => {
|
15
|
+
const e = X(5381, JSON.stringify(t)) >>> 0;
|
16
|
+
return U(e, s);
|
17
|
+
};
|
18
|
+
function V(t) {
|
19
|
+
return t ? typeof t != "string" ? V(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
|
+
}
|
21
|
+
const Y = (t, s) => {
|
22
|
+
if (typeof t != "string") return { result: t };
|
23
|
+
if (!s) return { result: t };
|
24
|
+
const e = [];
|
25
|
+
return Object.values(s).forEach((n) => {
|
26
|
+
const { pattern: r, transform: u } = n;
|
27
|
+
t = t.replace(r, ($) => {
|
28
|
+
const { value: a, css: f } = u($);
|
29
|
+
return f && e.push(f), a;
|
30
|
+
});
|
31
|
+
}), { result: t, additionalCss: e };
|
32
|
+
}, B = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, N = (t, s, e, n) => {
|
33
|
+
if (!t) return "";
|
34
|
+
const r = [], u = Object.entries(t).reduce((a, [f, o]) => {
|
35
|
+
const i = f.trim();
|
36
|
+
if (typeof o == "function" && (o = o()), typeof o == "object") {
|
37
|
+
if (!o) return a;
|
38
|
+
if (i === "variants")
|
39
|
+
return Object.entries(o).forEach(([g, c]) => {
|
40
|
+
c && Object.entries(c).forEach(([m, l]) => {
|
41
|
+
if (!l) return;
|
42
|
+
const w = `${s}.${g}-${m}`, P = N(l, w);
|
43
|
+
r.push(P);
|
44
|
+
});
|
45
|
+
}), a;
|
46
|
+
if (i === "defaultVariants")
|
47
|
+
return a;
|
48
|
+
if (i === "compoundVariants")
|
49
|
+
return o.forEach((g) => {
|
50
|
+
const { css: c, ...m } = g, l = Object.entries(m).reduce((P, [D, O]) => `${P}.${D}-${O}`, s), w = N(c, l);
|
51
|
+
r.push(w);
|
52
|
+
}), a;
|
53
|
+
if (i.startsWith("@")) {
|
54
|
+
const g = N(o, s), c = `${i} {
|
55
|
+
${g.replace(`
|
56
|
+
`, `
|
57
|
+
`)}
|
58
|
+
}`;
|
59
|
+
return r.push(c), a;
|
60
|
+
}
|
61
|
+
const d = f.includes("&") ? i.replace("&", s) : i.startsWith(":") ? `${s}${i}` : `${s} ${i}`, C = N(o, d);
|
62
|
+
return r.push(C), a;
|
63
|
+
}
|
64
|
+
const y = i.startsWith("-") ? i : V(i), h = (d, C = ";") => a = `${a}${d}${C}`, b = (d) => h(`${y}:${d}`);
|
65
|
+
if (typeof o == "number") return b(o);
|
66
|
+
if (typeof o != "string")
|
67
|
+
if ("toString" in o) o = o.toString();
|
68
|
+
else return a;
|
69
|
+
const { modifiers: j } = {}, F = function* () {
|
70
|
+
yield B(o), yield Y(o, j);
|
71
|
+
}();
|
72
|
+
for (const { result: d, additionalCss: C = [] } of F)
|
73
|
+
o = d, C.forEach((g) => {
|
74
|
+
const c = N(g, "");
|
75
|
+
h(c, "");
|
76
|
+
});
|
77
|
+
return b(o);
|
78
|
+
}, "");
|
79
|
+
if (!u) return r.join(`
|
80
|
+
`);
|
81
|
+
if (!s) return u;
|
82
|
+
let $ = "";
|
83
|
+
return $ = `${s} { ${u} }`, [$, ...r].join(`
|
84
|
+
`);
|
85
|
+
}, H = (t, s = []) => {
|
86
|
+
if (!t) return "";
|
87
|
+
const e = [], n = {};
|
88
|
+
if (Object.entries(t).forEach(([r, u]) => {
|
89
|
+
if (typeof u == "object") {
|
90
|
+
if (!u) return;
|
91
|
+
const $ = r.trim(), a = H(u, [...s, $]);
|
92
|
+
e.push(a);
|
93
|
+
} else
|
94
|
+
n[r] = u;
|
95
|
+
}), Object.keys(n).length) {
|
96
|
+
const r = s.map(V).join("-"), u = N(n, `.${r}`);
|
97
|
+
e.push(u);
|
98
|
+
}
|
99
|
+
return e.join(`
|
100
|
+
`);
|
101
|
+
}, k = (t) => p(t, "./saltygen"), Q = ["salty", "css", "styles", "styled"], v = (t = []) => new RegExp(`\\.(${[...Q, ...t].join("|")})\\.`), A = (t, s = []) => v(s).test(t), tt = async (t) => {
|
102
|
+
const s = k(t), e = p(t, "salty.config.ts"), n = p(s, "salty.config.js");
|
103
|
+
await Z.build({
|
104
|
+
entryPoints: [e],
|
105
|
+
minify: !0,
|
106
|
+
treeShaking: !0,
|
107
|
+
bundle: !0,
|
108
|
+
outfile: n,
|
109
|
+
format: "esm",
|
110
|
+
external: ["react"]
|
111
|
+
});
|
112
|
+
const r = Date.now(), { config: u } = await import(`${n}?t=${r}`);
|
113
|
+
return u;
|
114
|
+
}, st = async (t) => {
|
115
|
+
const s = await tt(t), e = /* @__PURE__ */ new Set(), n = (g, c = []) => g ? Object.entries(g).flatMap(([m, l]) => {
|
116
|
+
if (!l) return;
|
117
|
+
if (typeof l == "object") return n(l, [...c, m]);
|
118
|
+
const w = [...c, m].join(".");
|
119
|
+
e.add(`"${w}"`);
|
120
|
+
const P = [...c.map(V), V(m)].join("-"), { result: D } = B(l);
|
121
|
+
return `--${P}: ${D};`;
|
122
|
+
}) : [], r = (g) => g ? Object.entries(g).flatMap(([c, m]) => {
|
123
|
+
const l = n(m);
|
124
|
+
return c === "base" ? l.join("") : `${c} { ${l.join("")} }`;
|
125
|
+
}) : [], u = (g) => g ? Object.entries(g).flatMap(([c, m]) => Object.entries(m).flatMap(([l, w]) => {
|
126
|
+
const P = n(w, [c]), D = `.${c}-${l}, [data-${c}="${l}"]`, O = P.join("");
|
127
|
+
return `${D} { ${O} }`;
|
128
|
+
})) : [], $ = n(s.variables), a = r(s.responsiveVariables), f = u(s.conditionalVariables), o = k(t), i = p(o, "css/variables.css"), y = `:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;
|
129
|
+
x(i, y);
|
130
|
+
const h = p(o, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
131
|
+
x(h, j);
|
132
|
+
const S = p(o, "css/global.css"), F = N(s.global, "");
|
133
|
+
x(S, F);
|
134
|
+
const d = p(o, "css/templates.css"), C = H(s.templates);
|
135
|
+
x(d, C);
|
136
|
+
}, R = async (t, s) => {
|
137
|
+
const e = T(t), n = p(s, "js", e + ".js");
|
138
|
+
await Z.build({
|
139
|
+
entryPoints: [t],
|
140
|
+
minify: !0,
|
141
|
+
treeShaking: !0,
|
142
|
+
bundle: !0,
|
143
|
+
outfile: n,
|
144
|
+
format: "esm",
|
145
|
+
target: ["es2022"],
|
146
|
+
keepNames: !0,
|
147
|
+
external: ["react"]
|
148
|
+
});
|
149
|
+
const r = Date.now();
|
150
|
+
return await import(`${n}?t=${r}`);
|
151
|
+
}, M = async (t) => {
|
152
|
+
const s = k(t), e = p(s, "salty.config.js"), { config: n } = await import(e);
|
153
|
+
return n;
|
154
|
+
}, it = async (t) => {
|
155
|
+
try {
|
156
|
+
const s = [], e = [], n = k(t), r = p(n, "index.css");
|
157
|
+
(() => {
|
158
|
+
K(n) && J("rm -rf " + n), E(n), E(p(n, "css")), E(p(n, "types"));
|
159
|
+
})(), await st(t);
|
160
|
+
const $ = await M(t);
|
161
|
+
async function a(y, h) {
|
162
|
+
const b = q(y);
|
163
|
+
if (b.isDirectory()) {
|
164
|
+
const j = G(y);
|
165
|
+
await Promise.all(j.map((S) => a(p(y, S), p(h, S))));
|
166
|
+
} else if (b.isFile() && A(y)) {
|
167
|
+
const S = await R(y, n), F = [];
|
168
|
+
Object.entries(S).forEach(([c, m]) => {
|
169
|
+
if (m.isKeyframes && m.css) {
|
170
|
+
const O = `${m.animationName}.css`, W = `css/${O}`, z = p(n, W);
|
171
|
+
s.push(O), x(z, m.css);
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
if (!m.generator) return;
|
175
|
+
const l = m.generator._withBuildContext({
|
176
|
+
name: c,
|
177
|
+
config: $
|
178
|
+
}), w = `${l.hash}-${l.priority}.css`;
|
179
|
+
e[l.priority] || (e[l.priority] = []), e[l.priority].push(w), F.push(w);
|
180
|
+
const P = `css/${w}`, D = p(n, P);
|
181
|
+
x(D, l.css);
|
182
|
+
});
|
183
|
+
const d = F.map((c) => `@import url('./${c}');`).join(`
|
184
|
+
`), C = T(y, 6), g = p(n, `css/${C}.css`);
|
185
|
+
x(g, d);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
await a(t, n);
|
189
|
+
const f = s.map((y) => `@import url('./css/${y}');`).join(`
|
190
|
+
`);
|
191
|
+
let i = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
192
|
+
|
193
|
+
${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
|
194
|
+
`)}
|
195
|
+
${f}`;
|
196
|
+
if ($.importStrategy !== "component") {
|
197
|
+
const y = e.flat().map((h) => `@import url('./css/${h}');`).join(`
|
198
|
+
`);
|
199
|
+
i += y;
|
200
|
+
}
|
201
|
+
x(r, i);
|
202
|
+
} catch (s) {
|
203
|
+
console.error(s);
|
204
|
+
}
|
205
|
+
}, ct = async (t, s) => {
|
206
|
+
try {
|
207
|
+
const e = [], n = p(t, "./saltygen"), r = p(n, "index.css");
|
208
|
+
if (A(s)) {
|
209
|
+
const $ = await M(t), a = await R(s, n);
|
210
|
+
Object.entries(a).forEach(([h, b]) => {
|
211
|
+
if (!b.generator) return;
|
212
|
+
const j = b.generator._withBuildContext({
|
213
|
+
name: h,
|
214
|
+
config: $
|
215
|
+
}), S = `${j.hash}-${j.priority}.css`, F = `css/${S}`, d = p(n, F);
|
216
|
+
e.push(S), x(d, j.css);
|
217
|
+
});
|
218
|
+
const f = I(r, "utf8").split(`
|
219
|
+
`), o = e.map((h) => `@import url('../saltygen/css/${h}');`), y = [.../* @__PURE__ */ new Set([...f, ...o])].join(`
|
220
|
+
`);
|
221
|
+
x(r, y);
|
222
|
+
}
|
223
|
+
} catch (e) {
|
224
|
+
console.error(e);
|
225
|
+
}
|
226
|
+
}, at = async (t, s) => {
|
227
|
+
try {
|
228
|
+
const e = p(t, "./saltygen");
|
229
|
+
if (A(s)) {
|
230
|
+
const r = I(s, "utf8");
|
231
|
+
r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await L(s, r);
|
232
|
+
const $ = await M(t), a = await R(s, e);
|
233
|
+
let f = r;
|
234
|
+
Object.entries(a).forEach(([i, y]) => {
|
235
|
+
var d;
|
236
|
+
if (y.isKeyframes || !y.generator) return;
|
237
|
+
const h = y.generator._withBuildContext({
|
238
|
+
name: i,
|
239
|
+
config: $
|
240
|
+
}), b = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
241
|
+
if (!b)
|
242
|
+
return console.error("Could not find the original declaration");
|
243
|
+
const j = (d = b.at(1)) == null ? void 0 : d.trim(), S = `${i} = styled(${j}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(h.props)});`, F = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`, "gm");
|
244
|
+
f = f.replace(F, S);
|
245
|
+
});
|
246
|
+
const o = T(s, 6);
|
247
|
+
return $.importStrategy === "component" && (f = `import '../../saltygen/css/${o}.css';
|
248
|
+
${f}`), f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
|
249
|
+
}
|
250
|
+
} catch (e) {
|
251
|
+
console.error("Error in minimizeFile", e);
|
252
|
+
}
|
253
|
+
};
|
254
|
+
export {
|
255
|
+
ct as a,
|
256
|
+
it as g,
|
257
|
+
at as m,
|
258
|
+
v as s
|
259
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";const H=require("esbuild"),W=require("child_process"),p=require("path"),$=require("fs"),J=require("fs/promises");function K(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(s,e,n.get?n:{enumerable:!0,get:()=>t[e]})}}return s.default=t,Object.freeze(s)}const M=K(H),R=t=>String.fromCharCode(t+(t>25?39:97)),G=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=R(n%52)+e;return e=R(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},L=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},V=(t,s=3)=>{const e=L(5381,JSON.stringify(t))>>>0;return G(e,s)};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,(s,e)=>(e>0?"-":"")+s.toLowerCase()):""}const U=(t,s)=>{if(typeof t!="string")return{result:t};if(!s)return{result:t};const e=[];return Object.values(s).forEach(n=>{const{pattern:r,transform:u}=n;t=t.replace(r,d=>{const{value:a,css:f}=u(d);return f&&e.push(f),a})}),{result:t,additionalCss:e}},q=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${N(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,s,e,n)=>{if(!t)return"";const r=[],u=Object.entries(t).reduce((a,[f,o])=>{const i=f.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return a;if(i==="variants")return Object.entries(o).forEach(([g,c])=>{c&&Object.entries(c).forEach(([m,l])=>{if(!l)return;const F=`${s}.${g}-${m}`,x=D(l,F);r.push(x)})}),a;if(i==="defaultVariants")return a;if(i==="compoundVariants")return o.forEach(g=>{const{css:c,...m}=g,l=Object.entries(m).reduce((x,[P,k])=>`${x}.${P}-${k}`,s),F=D(c,l);r.push(F)}),a;if(i.startsWith("@")){const g=D(o,s),c=`${i} {
|
2
|
+
${g.replace(`
|
3
|
+
`,`
|
4
|
+
`)}
|
5
|
+
}`;return r.push(c),a}const j=f.includes("&")?i.replace("&",s):i.startsWith(":")?`${s}${i}`:`${s} ${i}`,O=D(o,j);return r.push(O),a}const y=i.startsWith("-")?i:N(i),h=(j,O=";")=>a=`${a}${j}${O}`,b=j=>h(`${y}:${j}`);if(typeof o=="number")return b(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return a;const{modifiers:S}={},C=function*(){yield q(o),yield U(o,S)}();for(const{result:j,additionalCss:O=[]}of C)o=j,O.forEach(g=>{const c=D(g,"");h(c,"")});return b(o)},"");if(!u)return r.join(`
|
6
|
+
`);if(!s)return u;let d="";return d=`${s} { ${u} }`,[d,...r].join(`
|
7
|
+
`)},Z=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,u])=>{if(typeof u=="object"){if(!u)return;const d=r.trim(),a=Z(u,[...s,d]);e.push(a)}else n[r]=u}),Object.keys(n).length){const r=s.map(N).join("-"),u=D(n,`.${r}`);e.push(u)}return e.join(`
|
8
|
+
`)},E=t=>p.join(t,"./saltygen"),X=["salty","css","styles","styled"],z=(t=[])=>new RegExp(`\\.(${[...X,...t].join("|")})\\.`),T=(t,s=[])=>z(s).test(t),Y=async t=>{const s=E(t),e=p.join(t,"salty.config.ts"),n=p.join(s,"salty.config.js");await M.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:u}=await import(`${n}?t=${r}`);return u},Q=async t=>{const s=await Y(t),e=new Set,n=(g,c=[])=>g?Object.entries(g).flatMap(([m,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...c,m]);const F=[...c,m].join(".");e.add(`"${F}"`);const x=[...c.map(N),N(m)].join("-"),{result:P}=q(l);return`--${x}: ${P};`}):[],r=g=>g?Object.entries(g).flatMap(([c,m])=>{const l=n(m);return c==="base"?l.join(""):`${c} { ${l.join("")} }`}):[],u=g=>g?Object.entries(g).flatMap(([c,m])=>Object.entries(m).flatMap(([l,F])=>{const x=n(F,[c]),P=`.${c}-${l}, [data-${c}="${l}"]`,k=x.join("");return`${P} { ${k} }`})):[],d=n(s.variables),a=r(s.responsiveVariables),f=u(s.conditionalVariables),o=E(t),i=p.join(o,"css/variables.css"),y=`:root { ${d.join("")} ${a.join("")} } ${f.join("")}`;$.writeFileSync(i,y);const h=p.join(o,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...e].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;$.writeFileSync(h,S);const w=p.join(o,"css/global.css"),C=D(s.global,"");$.writeFileSync(w,C);const j=p.join(o,"css/templates.css"),O=Z(s.templates);$.writeFileSync(j,O)},_=async(t,s)=>{const e=V(t),n=p.join(s,"js",e+".js");await M.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const r=Date.now();return await import(`${n}?t=${r}`)},A=async t=>{const s=E(t),e=p.join(s,"salty.config.js"),{config:n}=await import(e);return n},v=async t=>{try{const s=[],e=[],n=E(t),r=p.join(n,"index.css");(()=>{$.existsSync(n)&&W.execSync("rm -rf "+n),$.mkdirSync(n),$.mkdirSync(p.join(n,"css")),$.mkdirSync(p.join(n,"types"))})(),await Q(t);const d=await A(t);async function a(y,h){const b=$.statSync(y);if(b.isDirectory()){const S=$.readdirSync(y);await Promise.all(S.map(w=>a(p.join(y,w),p.join(h,w))))}else if(b.isFile()&&T(y)){const w=await _(y,n),C=[];Object.entries(w).forEach(([c,m])=>{if(m.isKeyframes&&m.css){const k=`${m.animationName}.css`,I=`css/${k}`,B=p.join(n,I);s.push(k),$.writeFileSync(B,m.css);return}if(!m.generator)return;const l=m.generator._withBuildContext({name:c,config:d}),F=`${l.hash}-${l.priority}.css`;e[l.priority]||(e[l.priority]=[]),e[l.priority].push(F),C.push(F);const x=`css/${F}`,P=p.join(n,x);$.writeFileSync(P,l.css)});const j=C.map(c=>`@import url('./${c}');`).join(`
|
9
|
+
`),O=V(y,6),g=p.join(n,`css/${O}.css`);$.writeFileSync(g,j)}}await a(t,n);const f=s.map(y=>`@import url('./css/${y}');`).join(`
|
10
|
+
`);let i=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
11
|
+
|
12
|
+
${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
|
13
|
+
`)}
|
14
|
+
${f}`;if(d.importStrategy!=="component"){const y=e.flat().map(h=>`@import url('./css/${h}');`).join(`
|
15
|
+
`);i+=y}$.writeFileSync(r,i)}catch(s){console.error(s)}},tt=async(t,s)=>{try{const e=[],n=p.join(t,"./saltygen"),r=p.join(n,"index.css");if(T(s)){const d=await A(t),a=await _(s,n);Object.entries(a).forEach(([h,b])=>{if(!b.generator)return;const S=b.generator._withBuildContext({name:h,config:d}),w=`${S.hash}-${S.priority}.css`,C=`css/${w}`,j=p.join(n,C);e.push(w),$.writeFileSync(j,S.css)});const f=$.readFileSync(r,"utf8").split(`
|
16
|
+
`),o=e.map(h=>`@import url('../saltygen/css/${h}');`),y=[...new Set([...f,...o])].join(`
|
17
|
+
`);$.writeFileSync(r,y)}}catch(e){console.error(e)}},st=async(t,s)=>{try{const e=p.join(t,"./saltygen");if(T(s)){const r=$.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await J.writeFile(s,r);const d=await A(t),a=await _(s,e);let f=r;Object.entries(a).forEach(([i,y])=>{var j;if(y.isKeyframes||!y.generator)return;const h=y.generator._withBuildContext({name:i,config:d}),b=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!b)return console.error("Could not find the original declaration");const S=(j=b.at(1))==null?void 0:j.trim(),w=`${i} = styled(${S}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(h.props)});`,C=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`,"gm");f=f.replace(C,w)});const o=V(s,6);return d.importStrategy==="component"&&(f=`import '../../saltygen/css/${o}.css';
|
18
|
+
${f}`),f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(e){console.error("Error in minimizeFile",e)}};exports.generateCss=v;exports.generateFile=tt;exports.minimizeFile=st;exports.saltyFileRegExp=z;
|
package/index.cjs
CHANGED
@@ -1,4 +1 @@
|
|
1
|
-
"use strict";
|
2
|
-
`),h=t.map(c=>`@import url('../saltygen/css/${c}');`),l=[...new Set([...o,...h])].join(`
|
3
|
-
`);d.writeFileSync(r,l)}}catch(t){console.error(t)}},H=async(e,s)=>{try{const t=a.join(e,"./saltygen");if(C(s)){let r=d.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await q.writeFile(s,r);const y=await O(e),m=await N(s,t);let o=r;Object.entries(m).forEach(([i,l])=>{var b;if(l.isKeyframes){console.log("value",l);return}if(!l.generator)return;const c=l.generator._withBuildContext({name:i,config:y}),u=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!u)return console.error("Could not find the original declaration");const g=(b=u.at(1))==null?void 0:b.trim(),{element:p,variantKeys:w}=c.props,j=`${i} = styled(${g}, "${c.classNames}", "${c._callerName}", ${JSON.stringify(p)}, ${JSON.stringify(w)});`,D=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");o=o.replace(D,j)});const h=x(s,6);return y.importStrategy==="component"&&(o=`import '../../saltygen/css/${h}.css';
|
4
|
-
${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(t){console.error(t)}};async function J(){const{dir:e}=this.getOptions(),{resourcePath:s,hot:t}=this;return t&&await A(e,s),await H(e,s)}module.exports=J;
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-zWFfFoCI.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
|
package/index.d.ts
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
type WebpackLoaderThis = LoaderContext<SaltyLoaderOptions>;
|
6
|
-
export default function (this: WebpackLoaderThis): Promise<string | undefined>;
|
7
|
-
export {};
|
1
|
+
import { Configuration } from 'webpack';
|
2
|
+
export declare const saltyPlugin: (config: Configuration, dir: string, isServer?: boolean, cjs?: boolean) => void;
|
3
|
+
export default saltyPlugin;
|
package/index.js
CHANGED
@@ -1,103 +1,24 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return v(t, s);
|
18
|
-
};
|
19
|
-
p.createLogger({
|
20
|
-
level: "info",
|
21
|
-
format: p.format.combine(p.format.colorize(), p.format.cli()),
|
22
|
-
transports: [new p.transports.Console({})]
|
23
|
-
});
|
24
|
-
const A = (e) => a(e, "./saltygen"), H = ["salty", "css", "styles", "styled"], b = (e) => new RegExp(`\\.(${H.join("|")})\\.`).test(e), j = async (e, s) => {
|
25
|
-
const t = N(e), n = a(s, "js", t + ".js");
|
26
|
-
await O.build({
|
27
|
-
entryPoints: [e],
|
28
|
-
minify: !0,
|
29
|
-
treeShaking: !0,
|
30
|
-
bundle: !0,
|
31
|
-
outfile: n,
|
32
|
-
format: "esm",
|
33
|
-
target: ["es2022"],
|
34
|
-
keepNames: !0,
|
35
|
-
external: ["react"]
|
36
|
-
});
|
37
|
-
const r = Date.now();
|
38
|
-
return await import(`${n}?t=${r}`);
|
39
|
-
}, D = async (e) => {
|
40
|
-
const s = A(e), t = a(s, "salty-config.js"), { config: n } = await import(t);
|
41
|
-
return n;
|
42
|
-
}, J = async (e, s) => {
|
43
|
-
try {
|
44
|
-
const t = [], n = a(e, "./saltygen"), r = a(n, "index.css");
|
45
|
-
if (b(s)) {
|
46
|
-
const y = await D(e), d = await j(s, n);
|
47
|
-
Object.entries(d).forEach(([c, g]) => {
|
48
|
-
if (!g.generator) return;
|
49
|
-
const f = g.generator._withBuildContext({
|
50
|
-
name: c,
|
51
|
-
config: y
|
52
|
-
}), m = `${f.hash}-${f.priority}.css`, h = `css/${m}`, w = a(n, h);
|
53
|
-
t.push(m), F(w, f.css);
|
1
|
+
import { resolve as n } from "path";
|
2
|
+
import { s as u, g as i } from "./index-BDOd3CmD.js";
|
3
|
+
const g = (s, e, o = !1, r = !1) => {
|
4
|
+
var a, l, t;
|
5
|
+
(l = (a = s.module) == null ? void 0 : a.rules) == null || l.push({
|
6
|
+
test: u(),
|
7
|
+
use: [
|
8
|
+
{
|
9
|
+
loader: n(__dirname, r ? "./loader.cjs" : "./loader.js"),
|
10
|
+
options: { dir: e }
|
11
|
+
}
|
12
|
+
]
|
13
|
+
}), o || (t = s.plugins) == null || t.push({
|
14
|
+
apply: (p) => {
|
15
|
+
p.hooks.afterPlugins.tap({ name: "generateCss" }, async () => {
|
16
|
+
await i(e);
|
54
17
|
});
|
55
|
-
const o = C(r, "utf8").split(`
|
56
|
-
`), u = t.map((c) => `@import url('../saltygen/css/${c}');`), l = [.../* @__PURE__ */ new Set([...o, ...u])].join(`
|
57
|
-
`);
|
58
|
-
F(r, l);
|
59
18
|
}
|
60
|
-
}
|
61
|
-
console.error(t);
|
62
|
-
}
|
63
|
-
}, _ = async (e, s) => {
|
64
|
-
try {
|
65
|
-
const t = a(e, "./saltygen");
|
66
|
-
if (b(s)) {
|
67
|
-
let r = C(s, "utf8");
|
68
|
-
r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await P(s, r);
|
69
|
-
const y = await D(e), d = await j(s, t);
|
70
|
-
let o = r;
|
71
|
-
Object.entries(d).forEach(([i, l]) => {
|
72
|
-
var x;
|
73
|
-
if (l.isKeyframes) {
|
74
|
-
console.log("value", l);
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
if (!l.generator) return;
|
78
|
-
const c = l.generator._withBuildContext({
|
79
|
-
name: i,
|
80
|
-
config: y
|
81
|
-
}), g = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
82
|
-
if (!g)
|
83
|
-
return console.error("Could not find the original declaration");
|
84
|
-
const f = (x = g.at(1)) == null ? void 0 : x.trim(), { element: m, variantKeys: h } = c.props, w = `${i} = styled(${f}, "${c.classNames}", "${c._callerName}", ${JSON.stringify(m)}, ${JSON.stringify(
|
85
|
-
h
|
86
|
-
)});`, E = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
87
|
-
o = o.replace(E, w);
|
88
|
-
});
|
89
|
-
const u = N(s, 6);
|
90
|
-
return y.importStrategy === "component" && (o = `import '../../saltygen/css/${u}.css';
|
91
|
-
${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
92
|
-
}
|
93
|
-
} catch (t) {
|
94
|
-
console.error(t);
|
95
|
-
}
|
19
|
+
});
|
96
20
|
};
|
97
|
-
async function I() {
|
98
|
-
const { dir: e } = this.getOptions(), { resourcePath: s, hot: t } = this;
|
99
|
-
return t && await J(e, s), await _(e, s);
|
100
|
-
}
|
101
21
|
export {
|
102
|
-
|
22
|
+
g as default,
|
23
|
+
g as saltyPlugin
|
103
24
|
};
|
package/loader.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";const i=require("./index-zWFfFoCI.cjs");async function n(){const{dir:e}=this.getOptions(),{resourcePath:t}=this;return await i.generateFile(e,t),await i.minimizeFile(e,t)}module.exports=n;
|
package/loader.d.ts
ADDED
package/loader.js
ADDED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/webpack",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.40",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -19,6 +19,7 @@
|
|
19
19
|
"!**/*.tsbuildinfo"
|
20
20
|
],
|
21
21
|
"nx": {
|
22
|
+
"sourceRoot": "libs/webpack/src",
|
22
23
|
"name": "webpack"
|
23
24
|
},
|
24
25
|
"exports": {
|
@@ -26,5 +27,9 @@
|
|
26
27
|
"import": "./index.js",
|
27
28
|
"require": "./index.cjs"
|
28
29
|
}
|
30
|
+
},
|
31
|
+
"dependencies": {
|
32
|
+
"@salty-css/core": "^0.0.1-alpha.40",
|
33
|
+
"webpack": ">=5.x"
|
29
34
|
}
|
30
35
|
}
|