@salty-css/webpack 0.0.1-alpha.6 → 0.0.1-alpha.60

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