@salty-css/webpack 0.0.1-alpha.7 → 0.0.1-alpha.70

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 CHANGED
@@ -1,15 +1,90 @@
1
- # Salty Css
1
+ # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
2
2
 
3
- ## Basic usage example with Button
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
- ### Initial requirements
5
+ ## Features
6
6
 
7
- 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty-config.ts` to the root of your project
9
- 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
- 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
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
- ### Code examples
13
+ ## Get started
14
+
15
+ - Initialize: `npx salty-css init [directory]`
16
+ - Create component: `npx salty-css generate [filePath]`
17
+ - Build: `npx salty-css build [directory]`
18
+
19
+ ### Packages
20
+
21
+ Note: Fastest way to get started with any framework is [npx salty-css init [directory]](#initialize-salty-css-for-a-project) command
22
+
23
+ - [Next.js](#nextjs) → `npm install @salty-css/next` + [Next.js install guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
24
+ - [React](#react) → `npm install @salty-css/react` + [React install guide](#react) + [React example code](#code-examples)
25
+ - [Vite](#vite) → `npm install @salty-css/vite` + [(Vite install guide)](#vite)
26
+ - [Webpack](https://www.npmjs.com/package/@salty-css/webpack) → `npm install @salty-css/webpack` + Guide coming soon
27
+ - [ESLint](https://www.npmjs.com/package/@salty-css/eslint-plugin-core) → `npm install @salty-css/eslint-plugin-core` + Guide coming soon
28
+ - [Core](https://www.npmjs.com/package/@salty-css/react) → `npm install @salty-css/core` (This package contains code for internal use)
29
+
30
+ ### Add Salty CSS to your project with `salty-css` CLI
31
+
32
+ #### Initialize Salty CSS for a project
33
+
34
+ In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory, detects framework in use (current support for vite and next.js) 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.
35
+
36
+ #### Create components
37
+
38
+ 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`
39
+
40
+ #### Build / Compile Salty CSS
41
+
42
+ 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.
43
+
44
+ #### Update Salty CSS packages
45
+
46
+ To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
47
+
48
+ ### Manual work
49
+
50
+ #### Next.js
51
+
52
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
53
+ 2. Create `salty.config.ts` to your app directory
54
+ 3. Add Salty CSS plugin to next.js config
55
+
56
+ - **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
57
+ - **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
58
+
59
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
60
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
61
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
62
+
63
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
64
+
65
+ #### React
66
+
67
+ 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
68
+ 2. Create `salty.config.ts` to your app directory
69
+ 3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack)
70
+
71
+ [Check out react example code](#code-examples)
72
+
73
+ #### Vite
74
+
75
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
76
+ 2. In `vite.config` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
77
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
78
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
79
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
80
+
81
+ ### Create components
82
+
83
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
84
+
85
+ ## Code examples
86
+
87
+ ### Basic usage example with Button
13
88
 
14
89
  **Salty config**
15
90
 
@@ -54,8 +129,10 @@ export const IndexPage = () => {
54
129
  import { styled } from '@salty-css/react/styled';
55
130
 
56
131
  export const Wrapper = styled('div', {
57
- display: 'block',
58
- padding: '2vw',
132
+ base: {
133
+ display: 'block',
134
+ padding: '2vw',
135
+ },
59
136
  });
60
137
  ```
61
138
 
@@ -65,22 +142,24 @@ export const Wrapper = styled('div', {
65
142
  import { styled } from '@salty-css/react/styled';
66
143
 
67
144
  export const Button = styled('button', {
68
- display: 'block',
69
- padding: `0.6em 1.2em`,
70
- border: '1px solid currentColor',
71
- background: 'transparent',
72
- color: 'currentColor/40',
73
- cursor: 'pointer',
74
- transition: '200ms',
75
- textDecoration: 'none',
76
- '&:hover': {
77
- background: 'black',
78
- borderColor: 'black',
79
- color: 'white',
80
- },
81
- '&:disabled': {
82
- opacity: 0.25,
83
- pointerEvents: 'none',
145
+ base: {
146
+ display: 'block',
147
+ padding: `0.6em 1.2em`,
148
+ border: '1px solid currentColor',
149
+ background: 'transparent',
150
+ color: 'currentColor/40',
151
+ cursor: 'pointer',
152
+ transition: '200ms',
153
+ textDecoration: 'none',
154
+ '&:hover': {
155
+ background: 'black',
156
+ borderColor: 'black',
157
+ color: 'white',
158
+ },
159
+ '&:disabled': {
160
+ opacity: 0.25,
161
+ pointerEvents: 'none',
162
+ },
84
163
  },
85
164
  variants: {
86
165
  variant: {
@@ -0,0 +1,285 @@
1
+ import * as z from "esbuild";
2
+ import { execSync as X } from "child_process";
3
+ import { join as g } from "path";
4
+ import { writeFileSync as P, readFileSync as N, existsSync as Y, mkdirSync as V, statSync as Q, readdirSync as v } from "fs";
5
+ import { writeFile as tt } from "fs/promises";
6
+ const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), st = (t, s) => {
7
+ let e = "", n;
8
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = Z(n % 52) + e;
9
+ return e = Z(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
10
+ }, et = (t, s) => {
11
+ let e = s.length;
12
+ for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
13
+ return t;
14
+ }, R = (t, s = 3) => {
15
+ const e = et(5381, JSON.stringify(t)) >>> 0;
16
+ return st(e, s);
17
+ };
18
+ function E(t) {
19
+ return t ? typeof t != "string" ? E(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 nt = (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: o, transform: u } = n;
27
+ t = t.replace(o, (y) => {
28
+ const { value: a, css: c } = u(y);
29
+ return c && e.push(c), a;
30
+ });
31
+ }), { result: t, additionalCss: e };
32
+ }, H = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${E(n[1].replaceAll(".", "-"))})`) } : { result: t }, T = (t, s, e, n) => {
33
+ if (!t) return "";
34
+ const o = [], u = Object.entries(t).reduce((a, [c, r]) => {
35
+ const f = c.trim();
36
+ if (typeof r == "function" && (r = r()), typeof r == "object") {
37
+ if (!r) return a;
38
+ if (f === "variants")
39
+ return Object.entries(r).forEach(([i, p]) => {
40
+ p && Object.entries(p).forEach(([h, m]) => {
41
+ if (!m) return;
42
+ const w = `${s}.${i}-${h}`, $ = T(m, w);
43
+ o.push($);
44
+ });
45
+ }), a;
46
+ if (f === "defaultVariants")
47
+ return a;
48
+ if (f === "compoundVariants")
49
+ return r.forEach((i) => {
50
+ const { css: p, ...h } = i, m = Object.entries(h).reduce(($, [S, D]) => `${$}.${S}-${D}`, s), w = T(p, m);
51
+ o.push(w);
52
+ }), a;
53
+ if (f.startsWith("@")) {
54
+ const i = T(r, s), p = `${f} {
55
+ ${i.replace(`
56
+ `, `
57
+ `)}
58
+ }`;
59
+ return o.push(p), a;
60
+ }
61
+ const d = c.includes("&") ? f.replace("&", s) : f.startsWith(":") ? `${s}${f}` : `${s} ${f}`, F = T(r, d);
62
+ return o.push(F), a;
63
+ }
64
+ const C = f.startsWith("-") ? f : E(f), b = (d, F = ";") => a = `${a}${d}${F}`, l = (d) => b(`${C}:${d}`);
65
+ if (typeof r == "number") return l(r);
66
+ if (typeof r != "string")
67
+ if ("toString" in r) r = r.toString();
68
+ else return a;
69
+ const { modifiers: j } = {}, x = function* () {
70
+ yield H(r), yield nt(r, j);
71
+ }();
72
+ for (const { result: d, additionalCss: F = [] } of x)
73
+ r = d, F.forEach((i) => {
74
+ const p = T(i, "");
75
+ b(p, "");
76
+ });
77
+ return l(r);
78
+ }, "");
79
+ if (!u) return o.join(`
80
+ `);
81
+ if (!s) return u;
82
+ let y = "";
83
+ return y = `${s} { ${u} }`, [y, ...o].join(`
84
+ `);
85
+ }, J = (t, s = []) => {
86
+ if (!t) return "";
87
+ const e = [], n = {};
88
+ if (Object.entries(t).forEach(([o, u]) => {
89
+ if (typeof u == "object") {
90
+ if (!u) return;
91
+ const y = o.trim(), a = J(u, [...s, y]);
92
+ e.push(a);
93
+ } else
94
+ n[o] = u;
95
+ }), Object.keys(n).length) {
96
+ const o = s.map(E).join("-"), u = T(n, `.${o}`);
97
+ e.push(u);
98
+ }
99
+ return e.join(`
100
+ `);
101
+ }, K = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", A = {
102
+ externalModules: []
103
+ }, q = (t) => {
104
+ if (A.externalModules.length > 0) return A.externalModules;
105
+ const s = g(t, "salty.config.ts"), n = N(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
106
+ if (!n) return [];
107
+ const o = n[1].split(",").map((u) => u.replace(/['"`]/g, "").trim());
108
+ return A.externalModules = o, o;
109
+ }, O = (t) => g(t, "./saltygen"), ot = ["salty", "css", "styles", "styled"], rt = (t = []) => new RegExp(`\\.(${[...ot, ...t].join("|")})\\.`), _ = (t, s = []) => rt(s).test(t), it = async (t) => {
110
+ const s = O(t), e = g(t, "salty.config.ts"), n = g(s, "salty.config.js"), o = K(), u = q(t);
111
+ await z.build({
112
+ entryPoints: [e],
113
+ minify: !0,
114
+ treeShaking: !0,
115
+ bundle: !0,
116
+ outfile: n,
117
+ format: o,
118
+ external: u
119
+ });
120
+ const y = Date.now(), { config: a } = await import(`${n}?t=${y}`);
121
+ return a;
122
+ }, ct = async (t) => {
123
+ const s = await it(t), e = /* @__PURE__ */ new Set(), n = (i, p = []) => i ? Object.entries(i).flatMap(([h, m]) => {
124
+ if (!m) return;
125
+ if (typeof m == "object") return n(m, [...p, h]);
126
+ const w = [...p, h].join(".");
127
+ e.add(`"${w}"`);
128
+ const $ = [...p.map(E), E(h)].join("-"), { result: S } = H(m);
129
+ return `--${$}: ${S};`;
130
+ }) : [], o = (i) => i ? Object.entries(i).flatMap(([p, h]) => {
131
+ const m = n(h);
132
+ return p === "base" ? m.join("") : `${p} { ${m.join("")} }`;
133
+ }) : [], u = (i) => i ? Object.entries(i).flatMap(([p, h]) => Object.entries(h).flatMap(([m, w]) => {
134
+ const $ = n(w, [p]), S = `.${p}-${m}, [data-${p}="${m}"]`, D = $.join("");
135
+ return `${S} { ${D} }`;
136
+ })) : [], y = n(s.variables), a = o(s.responsiveVariables), c = u(s.conditionalVariables), r = O(t), f = g(r, "css/variables.css"), C = `:root { ${y.join("")} ${a.join("")} } ${c.join("")}`;
137
+ P(f, C);
138
+ const b = g(r, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
139
+ P(b, j);
140
+ const k = g(r, "css/global.css"), x = T(s.global, "");
141
+ P(k, x);
142
+ const d = g(r, "css/templates.css"), F = J(s.templates);
143
+ P(d, F);
144
+ }, W = async (t, s, e) => {
145
+ const n = R(s), o = g(e, "js", n + ".js"), u = K(), y = q(t);
146
+ await z.build({
147
+ entryPoints: [s],
148
+ minify: !0,
149
+ treeShaking: !0,
150
+ bundle: !0,
151
+ outfile: o,
152
+ format: u,
153
+ target: ["es2022"],
154
+ keepNames: !0,
155
+ external: y
156
+ });
157
+ const a = Date.now();
158
+ return await import(`${o}?t=${a}`);
159
+ }, B = async (t) => {
160
+ const s = O(t), e = g(s, "salty.config.js"), { config: n } = await import(e);
161
+ return n;
162
+ }, ut = async (t) => {
163
+ try {
164
+ const s = [], e = [], n = O(t), o = g(n, "index.css");
165
+ (() => {
166
+ Y(n) && X("rm -rf " + n), V(n), V(g(n, "css")), V(g(n, "types"));
167
+ })(), await ct(t);
168
+ const y = await B(t);
169
+ async function a(l, j) {
170
+ const k = ["node_modules", "saltygen"], x = Q(l);
171
+ if (x.isDirectory()) {
172
+ const d = v(l);
173
+ if (k.some((i) => l.includes(i))) return;
174
+ await Promise.all(d.map((i) => a(g(l, i), g(j, i))));
175
+ } else if (x.isFile() && _(l)) {
176
+ const F = await W(t, l, n), i = [];
177
+ Object.entries(F).forEach(([w, $]) => {
178
+ if ($.isKeyframes && $.css) {
179
+ const I = `${$.animationName}.css`, L = `css/${I}`, U = g(n, L);
180
+ s.push(I), P(U, $.css);
181
+ return;
182
+ }
183
+ if (!$.generator) return;
184
+ const S = $.generator._withBuildContext({
185
+ name: w,
186
+ config: y
187
+ }), D = `${S.hash}-${S.priority}.css`;
188
+ e[S.priority] || (e[S.priority] = []), e[S.priority].push(D), i.push(D);
189
+ const M = `css/${D}`, G = g(n, M);
190
+ P(G, S.css);
191
+ });
192
+ const p = i.map((w) => `@import url('./${w}');`).join(`
193
+ `), h = R(l, 6), m = g(n, `css/${h}.css`);
194
+ P(m, p);
195
+ }
196
+ }
197
+ await a(t, n);
198
+ const c = s.map((l) => `@import url('./css/${l}');`).join(`
199
+ `);
200
+ let b = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
201
+
202
+ ${["variables.css", "global.css", "templates.css"].filter((l) => {
203
+ try {
204
+ return N(g(n, "css", l), "utf8").length > 0;
205
+ } catch {
206
+ return !1;
207
+ }
208
+ }).map((l) => `@import url('./css/${l}');`).join(`
209
+ `)}
210
+ ${c}`;
211
+ if (y.importStrategy !== "component") {
212
+ const l = e.flat().map((j) => `@import url('./css/${j}');`).join(`
213
+ `);
214
+ b += l;
215
+ }
216
+ P(o, b);
217
+ } catch (s) {
218
+ console.error(s);
219
+ }
220
+ }, gt = async (t, s) => {
221
+ try {
222
+ const e = [], n = g(t, "./saltygen"), o = g(n, "index.css");
223
+ if (_(s)) {
224
+ const y = await B(t), a = await W(t, s, n);
225
+ Object.entries(a).forEach(([b, l]) => {
226
+ if (!l.generator) return;
227
+ const j = l.generator._withBuildContext({
228
+ name: b,
229
+ config: y
230
+ }), k = `${j.hash}-${j.priority}.css`, x = `css/${k}`, d = g(n, x);
231
+ e.push(k), P(d, j.css);
232
+ });
233
+ const c = N(o, "utf8").split(`
234
+ `), r = e.map((b) => `@import url('../saltygen/css/${b}');`), C = [.../* @__PURE__ */ new Set([...c, ...r])].join(`
235
+ `);
236
+ P(o, C);
237
+ }
238
+ } catch (e) {
239
+ console.error(e);
240
+ }
241
+ }, yt = async (t, s) => {
242
+ try {
243
+ const e = g(t, "./saltygen");
244
+ if (_(s)) {
245
+ const o = N(s, "utf8");
246
+ o.replace(/^(?!export\s)const\s.*/gm, (f) => `export ${f}`) !== o && await tt(s, o);
247
+ const y = await B(t), a = await W(t, s, e);
248
+ let c = o;
249
+ Object.entries(a).forEach(([f, C]) => {
250
+ var D;
251
+ if (C.isKeyframes || !C.generator) return;
252
+ const b = C.generator._withBuildContext({
253
+ name: f,
254
+ config: y
255
+ }), l = new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
256
+ if (!l) return console.error("Could not find the original declaration");
257
+ const j = (D = l.at(1)) == null ? void 0 : D.trim(), k = new RegExp(`\\s${f}[=\\s]+styled\\(`, "g").exec(c);
258
+ if (!k) return console.error("Could not find the original declaration");
259
+ const { index: x } = k;
260
+ let d = !1;
261
+ const F = setTimeout(() => d = !0, 5e3);
262
+ let i = 0, p = !1, h = 0;
263
+ for (; !p && !d; ) {
264
+ const M = c[x + i];
265
+ M === "(" && h++, M === ")" && h--, h === 0 && M === ")" && (p = !0), i > c.length && (d = !0), i++;
266
+ }
267
+ if (!d) clearTimeout(F);
268
+ else throw new Error("Failed to find the end of the styled call and timed out");
269
+ const m = x + i, w = c.slice(x, m), $ = c, S = ` ${f} = styled(${j}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
270
+ c = c.replace(w, S), $ === c && console.error("Minimize file failed to change content", { name: f, tagName: j });
271
+ });
272
+ const r = R(s, 6);
273
+ return y.importStrategy === "component" && (c = `import '../../saltygen/css/${r}.css';
274
+ ${c}`), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
275
+ }
276
+ } catch (e) {
277
+ console.error("Error in minimizeFile:", e);
278
+ }
279
+ };
280
+ export {
281
+ gt as a,
282
+ ut as g,
283
+ yt as m,
284
+ rt as s
285
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";const X=require("esbuild"),Y=require("child_process"),d=require("path"),g=require("fs"),Q=require("fs/promises");var M=typeof document<"u"?document.currentScript:null;function v(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 z=v(X),W=t=>String.fromCharCode(t+(t>25?39:97)),tt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=W(n%52)+s;return s=W(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},et=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},_=(t,e=3)=>{const s=et(5381,JSON.stringify(t))>>>0;return tt(s,e)};function O(t){return t?typeof t!="string"?O(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 st=(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:p}=n;t=t.replace(o,y=>{const{value:a,css:c}=p(y);return c&&s.push(c),a})}),{result:t,additionalCss:s}},B=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${O(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,e,s,n)=>{if(!t)return"";const o=[],p=Object.entries(t).reduce((a,[c,r])=>{const f=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(f==="variants")return Object.entries(r).forEach(([i,u])=>{u&&Object.entries(u).forEach(([$,h])=>{if(!h)return;const w=`${e}.${i}-${$}`,j=D(h,w);o.push(j)})}),a;if(f==="defaultVariants")return a;if(f==="compoundVariants")return r.forEach(i=>{const{css:u,...$}=i,h=Object.entries($).reduce((j,[F,T])=>`${j}.${F}-${T}`,e),w=D(u,h);o.push(w)}),a;if(f.startsWith("@")){const i=D(r,e),u=`${f} {
2
+ ${i.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return o.push(u),a}const m=c.includes("&")?f.replace("&",e):f.startsWith(":")?`${e}${f}`:`${e} ${f}`,C=D(r,m);return o.push(C),a}const k=f.startsWith("-")?f:O(f),b=(m,C=";")=>a=`${a}${m}${C}`,l=m=>b(`${k}:${m}`);if(typeof r=="number")return l(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:S}={},x=function*(){yield B(r),yield st(r,S)}();for(const{result:m,additionalCss:C=[]}of x)r=m,C.forEach(i=>{const u=D(i,"");b(u,"")});return l(r)},"");if(!p)return o.join(`
6
+ `);if(!e)return p;let y="";return y=`${e} { ${p} }`,[y,...o].join(`
7
+ `)},Z=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,p])=>{if(typeof p=="object"){if(!p)return;const y=o.trim(),a=Z(p,[...e,y]);s.push(a)}else n[o]=p}),Object.keys(n).length){const o=e.map(O).join("-"),p=D(n,`.${o}`);s.push(p)}return s.join(`
8
+ `)},U=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:M&&M.tagName.toUpperCase()==="SCRIPT"&&M.src||new URL("index-mf-G0Xfj.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",V={externalModules:[]},H=t=>{if(V.externalModules.length>0)return V.externalModules;const e=d.join(t,"salty.config.ts"),n=g.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(p=>p.replace(/['"`]/g,"").trim());return V.externalModules=o,o},N=t=>d.join(t,"./saltygen"),nt=["salty","css","styles","styled"],L=(t=[])=>new RegExp(`\\.(${[...nt,...t].join("|")})\\.`),R=(t,e=[])=>L(e).test(t),ot=async t=>{const e=N(t),s=d.join(t,"salty.config.ts"),n=d.join(e,"salty.config.js"),o=U(),p=H(t);await z.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:p});const y=Date.now(),{config:a}=await import(`${n}?t=${y}`);return a},rt=async t=>{const e=await ot(t),s=new Set,n=(i,u=[])=>i?Object.entries(i).flatMap(([$,h])=>{if(!h)return;if(typeof h=="object")return n(h,[...u,$]);const w=[...u,$].join(".");s.add(`"${w}"`);const j=[...u.map(O),O($)].join("-"),{result:F}=B(h);return`--${j}: ${F};`}):[],o=i=>i?Object.entries(i).flatMap(([u,$])=>{const h=n($);return u==="base"?h.join(""):`${u} { ${h.join("")} }`}):[],p=i=>i?Object.entries(i).flatMap(([u,$])=>Object.entries($).flatMap(([h,w])=>{const j=n(w,[u]),F=`.${u}-${h}, [data-${u}="${h}"]`,T=j.join("");return`${F} { ${T} }`})):[],y=n(e.variables),a=o(e.responsiveVariables),c=p(e.conditionalVariables),r=N(t),f=d.join(r,"css/variables.css"),k=`:root { ${y.join("")} ${a.join("")} } ${c.join("")}`;g.writeFileSync(f,k);const b=d.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;g.writeFileSync(b,S);const P=d.join(r,"css/global.css"),x=D(e.global,"");g.writeFileSync(P,x);const m=d.join(r,"css/templates.css"),C=Z(e.templates);g.writeFileSync(m,C)},A=async(t,e,s)=>{const n=_(e),o=d.join(s,"js",n+".js"),p=U(),y=H(t);await z.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:p,target:["es2022"],keepNames:!0,external:y});const a=Date.now();return await import(`${o}?t=${a}`)},q=async t=>{const e=N(t),s=d.join(e,"salty.config.js"),{config:n}=await import(s);return n},it=async t=>{try{const e=[],s=[],n=N(t),o=d.join(n,"index.css");(()=>{g.existsSync(n)&&Y.execSync("rm -rf "+n),g.mkdirSync(n),g.mkdirSync(d.join(n,"css")),g.mkdirSync(d.join(n,"types"))})(),await rt(t);const y=await q(t);async function a(l,S){const P=["node_modules","saltygen"],x=g.statSync(l);if(x.isDirectory()){const m=g.readdirSync(l);if(P.some(i=>l.includes(i)))return;await Promise.all(m.map(i=>a(d.join(l,i),d.join(S,i))))}else if(x.isFile()&&R(l)){const C=await A(t,l,n),i=[];Object.entries(C).forEach(([w,j])=>{if(j.isKeyframes&&j.css){const I=`${j.animationName}.css`,K=`css/${I}`,G=d.join(n,K);e.push(I),g.writeFileSync(G,j.css);return}if(!j.generator)return;const F=j.generator._withBuildContext({name:w,config:y}),T=`${F.hash}-${F.priority}.css`;s[F.priority]||(s[F.priority]=[]),s[F.priority].push(T),i.push(T);const E=`css/${T}`,J=d.join(n,E);g.writeFileSync(J,F.css)});const u=i.map(w=>`@import url('./${w}');`).join(`
9
+ `),$=_(l,6),h=d.join(n,`css/${$}.css`);g.writeFileSync(h,u)}}await a(t,n);const c=e.map(l=>`@import url('./css/${l}');`).join(`
10
+ `);let b=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
+
12
+ ${["variables.css","global.css","templates.css"].filter(l=>{try{return g.readFileSync(d.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
13
+ `)}
14
+ ${c}`;if(y.importStrategy!=="component"){const l=s.flat().map(S=>`@import url('./css/${S}');`).join(`
15
+ `);b+=l}g.writeFileSync(o,b)}catch(e){console.error(e)}},ct=async(t,e)=>{try{const s=[],n=d.join(t,"./saltygen"),o=d.join(n,"index.css");if(R(e)){const y=await q(t),a=await A(t,e,n);Object.entries(a).forEach(([b,l])=>{if(!l.generator)return;const S=l.generator._withBuildContext({name:b,config:y}),P=`${S.hash}-${S.priority}.css`,x=`css/${P}`,m=d.join(n,x);s.push(P),g.writeFileSync(m,S.css)});const c=g.readFileSync(o,"utf8").split(`
16
+ `),r=s.map(b=>`@import url('../saltygen/css/${b}');`),k=[...new Set([...c,...r])].join(`
17
+ `);g.writeFileSync(o,k)}}catch(s){console.error(s)}},at=async(t,e)=>{try{const s=d.join(t,"./saltygen");if(R(e)){const o=g.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==o&&await Q.writeFile(e,o);const y=await q(t),a=await A(t,e,s);let c=o;Object.entries(a).forEach(([f,k])=>{var T;if(k.isKeyframes||!k.generator)return;const b=k.generator._withBuildContext({name:f,config:y}),l=new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!l)return console.error("Could not find the original declaration");const S=(T=l.at(1))==null?void 0:T.trim(),P=new RegExp(`\\s${f}[=\\s]+styled\\(`,"g").exec(c);if(!P)return console.error("Could not find the original declaration");const{index:x}=P;let m=!1;const C=setTimeout(()=>m=!0,5e3);let i=0,u=!1,$=0;for(;!u&&!m;){const E=c[x+i];E==="("&&$++,E===")"&&$--,$===0&&E===")"&&(u=!0),i>c.length&&(m=!0),i++}if(!m)clearTimeout(C);else throw new Error("Failed to find the end of the styled call and timed out");const h=x+i,w=c.slice(x,h),j=c,F=` ${f} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(w,F),j===c&&console.error("Minimize file failed to change content",{name:f,tagName:S})});const r=_(e,6);return y.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)}};exports.generateCss=it;exports.generateFile=ct;exports.minimizeFile=at;exports.saltyFileRegExp=L;
package/index.cjs CHANGED
@@ -1,4 +1 @@
1
- "use strict";const _=require("esbuild"),P=require("winston");require("child_process");const a=require("path"),d=require("fs"),q=require("fs/promises");function S(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return s.default=e,Object.freeze(s)}const E=S(_),f=S(P),F=e=>String.fromCharCode(e+(e>25?39:97)),v=(e,s)=>{let t="",n;for(n=Math.abs(e);n>52;n=n/52|0)t=F(n%52)+t;return t=F(n%52)+t,t.length<s?t=t.padStart(s,"a"):t.length>s&&(t=t.slice(-s)),t},R=(e,s)=>{let t=s.length;for(;t;)e=e*33^s.charCodeAt(--t);return e},x=(e,s=3)=>{const t=R(5381,JSON.stringify(e))>>>0;return v(t,s)};f.createLogger({level:"info",format:f.format.combine(f.format.colorize(),f.format.cli()),transports:[new f.transports.Console({})]});const k=e=>a.join(e,"./saltygen"),z=["salty","css","styles","styled"],C=e=>new RegExp(`\\.(${z.join("|")})\\.`).test(e),N=async(e,s)=>{const t=x(e),n=a.join(s,"js",t+".js");await E.build({entryPoints:[e],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}`)},O=async e=>{const s=k(e),t=a.join(s,"salty-config.js"),{config:n}=await import(t);return n},A=async(e,s)=>{try{const t=[],n=a.join(e,"./saltygen"),r=a.join(n,"index.css");if(C(s)){const y=await O(e),m=await N(s,n);Object.entries(m).forEach(([c,u])=>{if(!u.generator)return;const g=u.generator._withBuildContext({name:c,config:y}),p=`${g.hash}-${g.priority}.css`,w=`css/${p}`,j=a.join(n,w);t.push(p),d.writeFileSync(j,g.css)});const o=d.readFileSync(r,"utf8").split(`
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-mf-G0Xfj.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 { LoaderContext } from 'webpack';
2
- interface SaltyLoaderOptions {
3
- dir: string;
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 * as O from "esbuild";
2
- import * as p from "winston";
3
- import "child_process";
4
- import { join as a } from "path";
5
- import { writeFileSync as F, readFileSync as C } from "fs";
6
- import { writeFile as P } from "fs/promises";
7
- const S = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), v = (e, s) => {
8
- let t = "", n;
9
- for (n = Math.abs(e); n > 52; n = n / 52 | 0) t = S(n % 52) + t;
10
- return t = S(n % 52) + t, t.length < s ? t = t.padStart(s, "a") : t.length > s && (t = t.slice(-s)), t;
11
- }, R = (e, s) => {
12
- let t = s.length;
13
- for (; t; ) e = e * 33 ^ s.charCodeAt(--t);
14
- return e;
15
- }, N = (e, s = 3) => {
16
- const t = R(5381, JSON.stringify(e)) >>> 0;
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-6sT6Zv96.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
- } catch (t) {
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
- I as default
22
+ g as default,
23
+ g as saltyPlugin
103
24
  };
package/loader.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const i=require("./index-mf-G0Xfj.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
@@ -0,0 +1,7 @@
1
+ import { LoaderContext } from 'webpack';
2
+ interface SaltyLoaderOptions {
3
+ dir: string;
4
+ }
5
+ type WebpackLoaderThis = LoaderContext<SaltyLoaderOptions>;
6
+ export default function (this: WebpackLoaderThis): Promise<string | undefined>;
7
+ export {};
package/loader.js ADDED
@@ -0,0 +1,8 @@
1
+ import { a as e, m as i } from "./index-6sT6Zv96.js";
2
+ async function s() {
3
+ const { dir: t } = this.getOptions(), { resourcePath: a } = this;
4
+ return await e(t, a), await i(t, a);
5
+ }
6
+ export {
7
+ s as default
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.7",
3
+ "version": "0.0.1-alpha.70",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -10,7 +10,12 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "homepage": "https://github.com/margarita-form/salty-css",
13
+ "description": "Webpack plugin for Salty CSS",
14
+ "homepage": "https://salty-css.dev/",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/margarita-form/salty-css.git"
18
+ },
14
19
  "bugs": {
15
20
  "url": "https://github.com/margarita-form/salty-css/issues"
16
21
  },
@@ -19,6 +24,7 @@
19
24
  "!**/*.tsbuildinfo"
20
25
  ],
21
26
  "nx": {
27
+ "sourceRoot": "libs/webpack/src",
22
28
  "name": "webpack"
23
29
  },
24
30
  "exports": {
@@ -26,5 +32,9 @@
26
32
  "import": "./index.js",
27
33
  "require": "./index.cjs"
28
34
  }
35
+ },
36
+ "dependencies": {
37
+ "@salty-css/core": "^0.0.1-alpha.70",
38
+ "webpack": ">=5.x"
29
39
  }
30
40
  }