@salty-css/webpack 0.0.1-alpha.21 → 0.0.1-alpha.210
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 +143 -26
- package/index-C3XjWftB.js +605 -0
- package/index-DkYpiTkg.cjs +42 -0
- package/index.cjs +1 -15
- package/index.d.ts +2 -1
- package/index.js +25 -215
- package/loader.cjs +1 -0
- package/loader.js +8 -0
- package/package.json +9 -4
package/README.md
CHANGED
@@ -1,15 +1,132 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
# Salty CSS - CSS-in-JS library that is kinda sweet
|
4
4
|
|
5
|
-
|
5
|
+
Is there anything saltier than CSS in frontend web development? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
|
6
6
|
|
7
|
-
|
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
|
+
## Features
|
11
8
|
|
12
|
-
|
9
|
+
- Build time compilation to achieve awesome runtime performance and minimal size
|
10
|
+
- Next.js, React Server Components, Vite and Webpack support
|
11
|
+
- Type safety with out of the box TypeScript and ESLint plugin
|
12
|
+
- Advanced CSS variables configuration to allow smooth token usage
|
13
|
+
- Style templates to create reusable styles easily
|
14
|
+
|
15
|
+
## Get started
|
16
|
+
|
17
|
+
Fastest way to get started with any framework is `npx salty-css init [directory]` command
|
18
|
+
|
19
|
+
- Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
|
20
|
+
- React + Vite → [React + Vite guide](#react--vite) + [React example code](#code-examples)
|
21
|
+
- React + Webpack → Guide coming soon
|
22
|
+
|
23
|
+
## Useful commands
|
24
|
+
|
25
|
+
- Create component: `npx salty-css generate [filePath]`
|
26
|
+
- Build: `npx salty-css build [directory]`
|
27
|
+
- Update Salty CSS packages: `npx salty-css up`
|
28
|
+
|
29
|
+
## Salty CSS styled function
|
30
|
+
|
31
|
+
```ts
|
32
|
+
// components/wrapper.css.ts
|
33
|
+
import { styled } from '@salty-css/react/styled';
|
34
|
+
|
35
|
+
// Define a component with styled function. First argument is the component name or existing component to extend and second argument is the object containing the styles and other options
|
36
|
+
export const Component = styled('div', {
|
37
|
+
className: 'wrapper', // Define custom class name that will be included for this component
|
38
|
+
element: 'section', // Define the html element that will be rendered for this component, overrides the first 'div' argument
|
39
|
+
base: {
|
40
|
+
// 👉 Add your CSS-in-JS base styles here! 👈
|
41
|
+
},
|
42
|
+
variants: {
|
43
|
+
// Define conditional styles that will be applied to the component based on the variant prop values
|
44
|
+
},
|
45
|
+
compoundVariants: [
|
46
|
+
// Define conditional styles that will be applied to the component based on the combination of variant prop values
|
47
|
+
],
|
48
|
+
defaultVariants: {
|
49
|
+
// Set default variant prop values
|
50
|
+
},
|
51
|
+
defaultProps: {
|
52
|
+
// Add additional default props for the component (eg, id and other html element attributes)
|
53
|
+
},
|
54
|
+
passProps: true, // Pass variant props to the rendered element / parent component (default: false)
|
55
|
+
});
|
56
|
+
```
|
57
|
+
|
58
|
+
## Salty CSS CLI
|
59
|
+
|
60
|
+
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
61
|
+
|
62
|
+
- Initialize project → `npx salty-css init [directory]` - Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
|
63
|
+
- Generate component → `npx salty-css update [version]` - Update @salty-css packages in your repository. Default version is "latest". Additional options like `--dir`, `--tag`, `--name` and `--className` are also supported.
|
64
|
+
- Build files → `npx salty-css build [directory]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
|
65
|
+
|
66
|
+
## Usage
|
67
|
+
|
68
|
+
### Next.js
|
69
|
+
|
70
|
+

|
71
|
+
|
72
|
+
Salty CSS provides Next.js App & Pages router support with full React Server Components support.
|
73
|
+
|
74
|
+
### Add Salty CSS to Next.js
|
75
|
+
|
76
|
+
1. In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
77
|
+
2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
|
78
|
+
3. Import your component for example to `page.tsx` and see it working!
|
79
|
+
|
80
|
+
And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
|
81
|
+
|
82
|
+
#### Manual configuration
|
83
|
+
|
84
|
+
1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
|
85
|
+
2. Create `salty.config.ts` to your app directory
|
86
|
+
3. Add Salty CSS plugin to next.js config
|
87
|
+
|
88
|
+
- **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);`
|
89
|
+
- **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);`
|
90
|
+
|
91
|
+
4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
|
92
|
+
5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
93
|
+
6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
94
|
+
|
95
|
+
[Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
### React + Vite
|
100
|
+
|
101
|
+

|
102
|
+
|
103
|
+
### Add Salty CSS to your React + Vite app
|
104
|
+
|
105
|
+
1. In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
106
|
+
2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
|
107
|
+
3. Import your component for example to `main.tsx` and see it working!
|
108
|
+
|
109
|
+
And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
|
110
|
+
|
111
|
+
#### Manual configuration
|
112
|
+
|
113
|
+
1. For Vite support install `npm i @salty-css/vite @salty-css/core`
|
114
|
+
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
|
115
|
+
3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
116
|
+
4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
117
|
+
5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
118
|
+
|
119
|
+
[Check out react example code](#code-examples)
|
120
|
+
|
121
|
+
---
|
122
|
+
|
123
|
+
### Create components
|
124
|
+
|
125
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
126
|
+
|
127
|
+
## Code examples
|
128
|
+
|
129
|
+
### Basic usage example with Button
|
13
130
|
|
14
131
|
**Salty config**
|
15
132
|
|
@@ -31,23 +148,6 @@ export const config = defineConfig({
|
|
31
148
|
});
|
32
149
|
```
|
33
150
|
|
34
|
-
**Your React component file**
|
35
|
-
|
36
|
-
```tsx
|
37
|
-
import { Wrapper } from '../components/wrapper/wrapper.css';
|
38
|
-
import { Button } from '../components/button/button.css';
|
39
|
-
|
40
|
-
export const IndexPage = () => {
|
41
|
-
return (
|
42
|
-
<Wrapper>
|
43
|
-
<Button variant="solid" onClick={() => alert('It is a button.')}>
|
44
|
-
Outlined
|
45
|
-
</Button>
|
46
|
-
</Wrapper>
|
47
|
-
);
|
48
|
-
};
|
49
|
-
```
|
50
|
-
|
51
151
|
**Wrapper** (`components/wrapper/wrapper.css.ts`)
|
52
152
|
|
53
153
|
```tsx
|
@@ -72,7 +172,7 @@ export const Button = styled('button', {
|
|
72
172
|
padding: `0.6em 1.2em`,
|
73
173
|
border: '1px solid currentColor',
|
74
174
|
background: 'transparent',
|
75
|
-
color: 'currentColor
|
175
|
+
color: 'currentColor',
|
76
176
|
cursor: 'pointer',
|
77
177
|
transition: '200ms',
|
78
178
|
textDecoration: 'none',
|
@@ -108,4 +208,21 @@ export const Button = styled('button', {
|
|
108
208
|
});
|
109
209
|
```
|
110
210
|
|
211
|
+
**Your React component file**
|
212
|
+
|
213
|
+
```tsx
|
214
|
+
import { Wrapper } from '../components/wrapper/wrapper.css';
|
215
|
+
import { Button } from '../components/button/button.css';
|
216
|
+
|
217
|
+
export const IndexPage = () => {
|
218
|
+
return (
|
219
|
+
<Wrapper>
|
220
|
+
<Button variant="solid" onClick={() => alert('It is a button.')}>
|
221
|
+
Outlined
|
222
|
+
</Button>
|
223
|
+
</Wrapper>
|
224
|
+
);
|
225
|
+
};
|
226
|
+
```
|
227
|
+
|
111
228
|
More examples coming soon
|
@@ -0,0 +1,605 @@
|
|
1
|
+
import * as yt from "esbuild";
|
2
|
+
import { execSync as Dt } from "child_process";
|
3
|
+
import { join as u, parse as tt } from "path";
|
4
|
+
import { existsSync as at, writeFileSync as D, readFileSync as M, mkdirSync as H, statSync as Et, readdirSync as _t } from "fs";
|
5
|
+
import { readFile as $t, writeFile as Tt } from "fs/promises";
|
6
|
+
import { createLogger as Ot, format as rt, transports as Vt } from "winston";
|
7
|
+
const gt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Mt = (t, e) => {
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = gt(n % 52) + s;
|
10
|
+
return s = gt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, Rt = (t, e) => {
|
12
|
+
let s = e.length;
|
13
|
+
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
|
+
return t;
|
15
|
+
}, z = (t, e = 5) => {
|
16
|
+
const s = Rt(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return Mt(s, e);
|
18
|
+
};
|
19
|
+
function A(t) {
|
20
|
+
return t ? typeof t != "string" ? A(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
|
21
|
+
}
|
22
|
+
const At = (t) => (e) => {
|
23
|
+
if (typeof e != "string" || !t) return;
|
24
|
+
let s = e;
|
25
|
+
const n = [];
|
26
|
+
return Object.values(t).forEach((o) => {
|
27
|
+
const { pattern: r, transform: a } = o;
|
28
|
+
s = s.replace(r, (g) => {
|
29
|
+
const { value: j, css: l } = a(g);
|
30
|
+
return l && n.push(l), j;
|
31
|
+
});
|
32
|
+
}), { transformed: s, additionalCss: n };
|
33
|
+
}, bt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) }, Jt = bt(), Wt = [
|
34
|
+
"top",
|
35
|
+
"right",
|
36
|
+
"bottom",
|
37
|
+
"left",
|
38
|
+
"min-width",
|
39
|
+
/.*width.*/,
|
40
|
+
/^[^line]*height.*/,
|
41
|
+
// Exclude line-height
|
42
|
+
/padding.*/,
|
43
|
+
/margin.*/,
|
44
|
+
/border.*/,
|
45
|
+
/inset.*/,
|
46
|
+
/.*radius.*/,
|
47
|
+
/.*spacing.*/,
|
48
|
+
/.*gap.*/,
|
49
|
+
/.*indent.*/,
|
50
|
+
/.*offset.*/,
|
51
|
+
/.*size.*/,
|
52
|
+
/.*thickness.*/,
|
53
|
+
/.*font-size.*/
|
54
|
+
], zt = (t, e, s) => Wt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, vt = ["Webkit", "Moz", "ms", "O"], Zt = (t) => t.startsWith("-") ? t : vt.some((e) => t.startsWith(e)) ? `-${A(t)}` : A(t), Y = async (t, e = "", s, n = !1) => {
|
55
|
+
if (!t) throw new Error("No styles provided to parseStyles function!");
|
56
|
+
const o = /* @__PURE__ */ new Set(), a = Object.entries(t).map(async ([m, i]) => {
|
57
|
+
const p = m.trim(), N = Zt(p), F = (k, O = ";") => `${N}:${k}${O}`;
|
58
|
+
if (typeof i == "function" && (i = i({ scope: e, config: s })), i instanceof Promise && (i = await i), typeof i == "object") {
|
59
|
+
if (!i) return;
|
60
|
+
if (i.isColor) return F(i.toString());
|
61
|
+
if (p === "defaultVariants") return;
|
62
|
+
if (p === "variants") {
|
63
|
+
const C = Object.entries(i);
|
64
|
+
for (const [_, c] of C) {
|
65
|
+
if (!c) return;
|
66
|
+
const h = Object.entries(c);
|
67
|
+
for (const [b, f] of h) {
|
68
|
+
if (!f) return;
|
69
|
+
const w = `${e}.${_}-${b}`;
|
70
|
+
(await Y(f, w, s)).forEach((V) => o.add(V));
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
if (p === "compoundVariants") {
|
76
|
+
for (const C of i) {
|
77
|
+
const { css: _, ...c } = C, h = Object.entries(c).reduce((f, [w, P]) => `${f}.${w}-${P}`, e);
|
78
|
+
(await Y(_, h, s)).forEach((f) => o.add(f));
|
79
|
+
}
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
if (p.startsWith("@")) {
|
83
|
+
const C = p, _ = await L(i, e, s), c = `${C} { ${_} }`;
|
84
|
+
o.add(c);
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
const k = m.includes("&") ? p.replace("&", e) : p.startsWith(":") ? `${e}${p}` : `${e} ${p}`;
|
88
|
+
(await Y(i, k, s)).forEach((C) => o.add(C));
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
if (typeof i == "number") {
|
92
|
+
const k = zt(N, i);
|
93
|
+
return F(k);
|
94
|
+
}
|
95
|
+
if (typeof i != "string")
|
96
|
+
if ("toString" in i) i = i.toString();
|
97
|
+
else throw new Error(`Invalid value type for property ${N}`);
|
98
|
+
return F(i);
|
99
|
+
}), { modifiers: g } = {}, j = [bt(), At(g)], d = (await Promise.all(a).then((m) => Promise.all(
|
100
|
+
m.map((i) => j.reduce(async (p, N) => {
|
101
|
+
const F = await p;
|
102
|
+
if (!F) return F;
|
103
|
+
const R = await N(F);
|
104
|
+
if (!R) return F;
|
105
|
+
const { transformed: k, additionalCss: O } = R;
|
106
|
+
let C = "";
|
107
|
+
if (O)
|
108
|
+
for (const _ of O)
|
109
|
+
C += await L(_, "");
|
110
|
+
return `${C}${k}`;
|
111
|
+
}, Promise.resolve(i)))
|
112
|
+
))).filter((m) => m !== void 0).join(`
|
113
|
+
`);
|
114
|
+
if (!d.trim()) return Array.from(o);
|
115
|
+
const y = e ? `${e} {
|
116
|
+
${d}
|
117
|
+
}` : d;
|
118
|
+
return o.has(y) ? Array.from(o) : [y, ...o];
|
119
|
+
}, L = async (t, e, s, n = !1) => (await Y(t, e, s, n)).join(`
|
120
|
+
`), wt = async (t, e = []) => {
|
121
|
+
if (!t) return "";
|
122
|
+
const s = [], n = {};
|
123
|
+
for (const [o, r] of Object.entries(t))
|
124
|
+
if (typeof r != "function") if (r && typeof r == "object") {
|
125
|
+
const a = o.trim(), g = await wt(r, [...e, a]);
|
126
|
+
s.push(g);
|
127
|
+
} else
|
128
|
+
n[o] = r;
|
129
|
+
if (Object.keys(n).length) {
|
130
|
+
const o = e.map(A).join("-"), r = "t_" + z(o, 4), a = await L(n, `.${o}, .${r}`);
|
131
|
+
s.push(a);
|
132
|
+
}
|
133
|
+
return s.join(`
|
134
|
+
`);
|
135
|
+
}, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = Ct(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
136
|
+
const r = e ? `${e}.${n}` : n;
|
137
|
+
return typeof o == "object" ? Ct(o, r, s) : s.add(e);
|
138
|
+
}), [...s]) : [], St = (t) => {
|
139
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
140
|
+
const e = u(t, "package.json");
|
141
|
+
return at(e) ? e : St(u(t, ".."));
|
142
|
+
}, Ht = async (t) => {
|
143
|
+
const e = St(t);
|
144
|
+
return await $t(e, "utf-8").then(JSON.parse).catch(() => {
|
145
|
+
});
|
146
|
+
}, Bt = async (t) => {
|
147
|
+
const e = await Ht(t);
|
148
|
+
if (e)
|
149
|
+
return e.type;
|
150
|
+
};
|
151
|
+
let I;
|
152
|
+
const jt = async (t) => {
|
153
|
+
if (I) return I;
|
154
|
+
const e = await Bt(t);
|
155
|
+
return e === "module" ? I = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (I = "cjs"), I || "esm";
|
156
|
+
}, it = Ot({
|
157
|
+
level: "debug",
|
158
|
+
format: rt.combine(rt.colorize(), rt.cli()),
|
159
|
+
transports: [new Vt.Console({})]
|
160
|
+
});
|
161
|
+
function Ft(t) {
|
162
|
+
return t ? typeof t != "string" ? Ft(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
163
|
+
}
|
164
|
+
const Gt = {
|
165
|
+
/** Set box model to border-box */
|
166
|
+
"*, *::before, *::after": {
|
167
|
+
boxSizing: "border-box"
|
168
|
+
},
|
169
|
+
/** Remove default margin and padding */
|
170
|
+
"*": {
|
171
|
+
margin: 0
|
172
|
+
},
|
173
|
+
/** Remove adjust font properties */
|
174
|
+
html: {
|
175
|
+
lineHeight: 1.15,
|
176
|
+
textSizeAdjust: "100%",
|
177
|
+
WebkitFontSmoothing: "antialiased"
|
178
|
+
},
|
179
|
+
/** Make media elements responsive */
|
180
|
+
"img, picture, video, canvas, svg": {
|
181
|
+
display: "block",
|
182
|
+
maxWidth: "100%"
|
183
|
+
},
|
184
|
+
/** Avoid overflow of text */
|
185
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
186
|
+
overflowWrap: "break-word"
|
187
|
+
},
|
188
|
+
/** Improve text wrapping */
|
189
|
+
p: {
|
190
|
+
textWrap: "pretty"
|
191
|
+
},
|
192
|
+
"h1, h2, h3, h4, h5, h6": {
|
193
|
+
textWrap: "balance"
|
194
|
+
},
|
195
|
+
/** Improve link color */
|
196
|
+
a: {
|
197
|
+
color: "currentColor"
|
198
|
+
},
|
199
|
+
/** Improve button line height */
|
200
|
+
button: {
|
201
|
+
lineHeight: "1em",
|
202
|
+
color: "currentColor"
|
203
|
+
},
|
204
|
+
/** Improve form elements */
|
205
|
+
"input, optgroup, select, textarea": {
|
206
|
+
fontFamily: "inherit",
|
207
|
+
fontSize: "100%",
|
208
|
+
lineHeight: "1.15em"
|
209
|
+
}
|
210
|
+
}, B = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), Kt = (...t) => t.flat().reduce((e, s) => ({ ...e, ...s._children }), {}), W = {
|
211
|
+
externalModules: [],
|
212
|
+
rcFile: void 0,
|
213
|
+
destDir: void 0
|
214
|
+
}, xt = (t) => {
|
215
|
+
if (W.externalModules.length > 0) return W.externalModules;
|
216
|
+
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
217
|
+
if (!s) return [];
|
218
|
+
const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
|
219
|
+
return W.externalModules = n, n;
|
220
|
+
}, v = async (t) => {
|
221
|
+
if (W.destDir) return W.destDir;
|
222
|
+
const e = await lt(t), s = u(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
223
|
+
return W.destDir = s, s;
|
224
|
+
}, Pt = ["salty", "css", "styles", "styled"], Lt = (t = []) => new RegExp(`\\.(${[...Pt, ...t].join("|")})\\.`), ct = (t, e = []) => Lt(e).test(t), Nt = async (t) => {
|
225
|
+
if (W.rcFile) return W.rcFile;
|
226
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
227
|
+
const e = u(t, ".saltyrc.json"), s = await $t(e, "utf-8").then(JSON.parse).catch(() => {
|
228
|
+
});
|
229
|
+
return s ? (W.rcFile = s, s) : Nt(u(t, ".."));
|
230
|
+
}, lt = async (t) => {
|
231
|
+
var n, o;
|
232
|
+
const e = await Nt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
|
233
|
+
return s || ((o = e.projects) == null ? void 0 : o.find((r) => r.dir === e.defaultProject));
|
234
|
+
}, Qt = async (t) => {
|
235
|
+
const e = await lt(t), s = await v(t), n = u(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await jt(t), a = xt(n);
|
236
|
+
await yt.build({
|
237
|
+
entryPoints: [n],
|
238
|
+
minify: !0,
|
239
|
+
treeShaking: !0,
|
240
|
+
bundle: !0,
|
241
|
+
outfile: o,
|
242
|
+
format: r,
|
243
|
+
external: a
|
244
|
+
});
|
245
|
+
const g = Date.now(), { config: j } = await import(`${o}?t=${g}`);
|
246
|
+
return j;
|
247
|
+
}, qt = async (t, e) => {
|
248
|
+
var dt, pt;
|
249
|
+
const s = await v(t), n = {
|
250
|
+
mediaQueries: [],
|
251
|
+
globalStyles: [],
|
252
|
+
variables: [],
|
253
|
+
templates: []
|
254
|
+
};
|
255
|
+
await Promise.all(
|
256
|
+
[...e].map(async (S) => {
|
257
|
+
const { contents: x, outputFilePath: J } = await et(t, S, s);
|
258
|
+
Object.entries(x).forEach(([E, T]) => {
|
259
|
+
T.isMedia ? n.mediaQueries.push([E, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(`${E};;${J}`));
|
260
|
+
});
|
261
|
+
})
|
262
|
+
);
|
263
|
+
const o = await Qt(t), r = { ...o }, a = /* @__PURE__ */ new Set(), g = (S, x = []) => S ? Object.entries(S).flatMap(([J, E]) => {
|
264
|
+
if (!E) return;
|
265
|
+
if (typeof E == "object") return g(E, [...x, J]);
|
266
|
+
const T = Ft(J), nt = A(J), ot = [...x, T].join(".");
|
267
|
+
a.add(`"${ot}"`);
|
268
|
+
const X = [...x.map(A), nt].join("-"), mt = Jt(E);
|
269
|
+
return mt ? `--${X}: ${mt.transformed};` : `--${X}: ${E};`;
|
270
|
+
}) : [], j = (S) => S ? Object.entries(S).flatMap(([x, J]) => {
|
271
|
+
const E = g(J);
|
272
|
+
return x === "base" ? E.join("") : `${x} { ${E.join("")} }`;
|
273
|
+
}) : [], l = (S) => S ? Object.entries(S).flatMap(([x, J]) => Object.entries(J).flatMap(([E, T]) => {
|
274
|
+
const nt = g(T, [x]), ot = `.${x}-${E}, [data-${x}="${E}"]`, X = nt.join("");
|
275
|
+
return `${ot} { ${X} }`;
|
276
|
+
})) : [], d = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), y = (S) => n.variables.map((x) => S === "static" ? d(x._current) : x._current[S]), $ = B(d(o.variables), y("static")), m = g($), i = B((dt = o.variables) == null ? void 0 : dt.responsive, y("responsive")), p = j(i), N = B((pt = o.variables) == null ? void 0 : pt.conditional, y("conditional")), F = l(N), R = u(s, "css/_variables.css"), k = `:root { ${m.join("")} ${p.join("")} } ${F.join("")}`;
|
277
|
+
D(R, k), r.staticVariables = $;
|
278
|
+
const O = u(s, "css/_global.css"), C = B(o.global, n.globalStyles), _ = await L(C, "");
|
279
|
+
D(O, `@layer global { ${_} }`);
|
280
|
+
const c = u(s, "css/_reset.css"), b = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Gt, f = await L(b, "");
|
281
|
+
D(c, `@layer reset { ${f} }`);
|
282
|
+
const w = u(s, "css/_templates.css"), P = B(o.templates, n.templates), V = await wt(P), G = It(P);
|
283
|
+
D(w, `@layer templates { ${V} }`), r.templates = P;
|
284
|
+
const K = Kt(n.templates);
|
285
|
+
r.templatePaths = Object.fromEntries(Object.entries(K).map(([S, x]) => [S, x._path]));
|
286
|
+
const { mediaQueries: Z } = n;
|
287
|
+
r.mediaQueries = Object.fromEntries(Z.map(([S, x]) => [`@${S}`, x]));
|
288
|
+
const Q = Z.map(([S]) => `'@${S}'`).join(" | "), st = u(s, "types/css-tokens.d.ts"), U = `
|
289
|
+
// Variable types
|
290
|
+
type VariableTokens = ${[...a].join("|")};
|
291
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
292
|
+
|
293
|
+
// Template types
|
294
|
+
type TemplateTokens = {
|
295
|
+
${Object.entries(G).map(([S, x]) => `${S}?: ${x}`).join(`
|
296
|
+
`)}
|
297
|
+
}
|
298
|
+
|
299
|
+
// Media query types
|
300
|
+
type MediaQueryKeys = ${Q || "''"};
|
301
|
+
`;
|
302
|
+
D(st, U);
|
303
|
+
const kt = u(s, "cache/config-cache.json");
|
304
|
+
D(kt, JSON.stringify(r, null, 2));
|
305
|
+
}, ht = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
306
|
+
if (/^['"`]/.test(s)) return e;
|
307
|
+
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
308
|
+
if (!o.test(t)) return e;
|
309
|
+
const a = o.exec(t);
|
310
|
+
if (a) {
|
311
|
+
const g = a.at(1);
|
312
|
+
if (Pt.some((l) => g == null ? void 0 : g.includes(l))) return e;
|
313
|
+
}
|
314
|
+
return "styled('div',";
|
315
|
+
}), Ut = (t, e) => {
|
316
|
+
try {
|
317
|
+
const s = M(u(e, "saltygen/cache/config-cache.json"), "utf8");
|
318
|
+
return s ? `globalThis.saltyConfig = ${s};
|
319
|
+
|
320
|
+
${t}` : `globalThis.saltyConfig = {};
|
321
|
+
|
322
|
+
${t}`;
|
323
|
+
} catch {
|
324
|
+
return t;
|
325
|
+
}
|
326
|
+
}, et = async (t, e, s) => {
|
327
|
+
const n = z(e), o = u(s, "./temp");
|
328
|
+
at(o) || H(o);
|
329
|
+
const r = tt(e);
|
330
|
+
let a = M(e, "utf8");
|
331
|
+
a = ht(a), a = Ut(a, t);
|
332
|
+
const g = u(s, "js", n + ".js"), j = await lt(t), l = u(t, (j == null ? void 0 : j.configDir) || "", "salty.config.ts"), d = xt(l), y = await jt(t);
|
333
|
+
await yt.build({
|
334
|
+
stdin: {
|
335
|
+
contents: a,
|
336
|
+
sourcefile: r.base,
|
337
|
+
resolveDir: r.dir,
|
338
|
+
loader: "tsx"
|
339
|
+
},
|
340
|
+
minify: !1,
|
341
|
+
treeShaking: !0,
|
342
|
+
bundle: !0,
|
343
|
+
outfile: g,
|
344
|
+
format: y,
|
345
|
+
target: ["node20"],
|
346
|
+
keepNames: !0,
|
347
|
+
external: d,
|
348
|
+
packages: "external",
|
349
|
+
plugins: [
|
350
|
+
{
|
351
|
+
name: "test",
|
352
|
+
setup: (i) => {
|
353
|
+
i.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (p) => {
|
354
|
+
const N = M(p.path, "utf8");
|
355
|
+
return { contents: ht(N), loader: "ts" };
|
356
|
+
});
|
357
|
+
}
|
358
|
+
}
|
359
|
+
]
|
360
|
+
});
|
361
|
+
const $ = Date.now();
|
362
|
+
return { contents: await import(`${g}?t=${$}`), outputFilePath: g };
|
363
|
+
}, Xt = async (t) => {
|
364
|
+
const e = await v(t), s = u(e, "cache/config-cache.json"), n = M(s, "utf8");
|
365
|
+
if (!n) throw new Error("Could not find config cache file");
|
366
|
+
return JSON.parse(n);
|
367
|
+
}, ft = async (t) => {
|
368
|
+
const e = await Xt(t), s = await v(t), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
|
369
|
+
return B(r, e);
|
370
|
+
}, ut = () => {
|
371
|
+
try {
|
372
|
+
return process.env.NODE_ENV === "production";
|
373
|
+
} catch {
|
374
|
+
return !1;
|
375
|
+
}
|
376
|
+
}, oe = async (t, e = ut(), s = !0) => {
|
377
|
+
try {
|
378
|
+
const n = Date.now();
|
379
|
+
e ? it.info("Generating CSS in production mode! 🔥") : it.info("Generating CSS in development mode! 🚀");
|
380
|
+
const o = [], r = [], a = await v(t), g = u(a, "index.css");
|
381
|
+
s && (() => {
|
382
|
+
at(a) && Dt("rm -rf " + a), H(a, { recursive: !0 }), H(u(a, "css")), H(u(a, "types")), H(u(a, "js")), H(u(a, "cache"));
|
383
|
+
})();
|
384
|
+
const l = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
|
385
|
+
async function y(c) {
|
386
|
+
const h = ["node_modules", "saltygen"], b = Et(c);
|
387
|
+
if (b.isDirectory()) {
|
388
|
+
const f = _t(c);
|
389
|
+
if (h.some((P) => c.includes(P))) return;
|
390
|
+
await Promise.all(f.map((P) => y(u(c, P))));
|
391
|
+
} else if (b.isFile() && ct(c)) {
|
392
|
+
l.add(c);
|
393
|
+
const w = M(c, "utf8");
|
394
|
+
/define[\w\d]+\(/.test(w) && d.add(c);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
await y(t), await qt(t, d);
|
398
|
+
const $ = {
|
399
|
+
keyframes: [],
|
400
|
+
components: [],
|
401
|
+
classNames: []
|
402
|
+
};
|
403
|
+
await Promise.all(
|
404
|
+
[...l].map(async (c) => {
|
405
|
+
const { contents: h } = await et(t, c, a);
|
406
|
+
Object.entries(h).forEach(([b, f]) => {
|
407
|
+
f.isKeyframes ? $.keyframes.push({
|
408
|
+
value: f,
|
409
|
+
src: c,
|
410
|
+
name: b
|
411
|
+
}) : f.isClassName ? $.classNames.push({
|
412
|
+
...f,
|
413
|
+
src: c,
|
414
|
+
name: b
|
415
|
+
}) : f.generator && $.components.push({
|
416
|
+
...f,
|
417
|
+
src: c,
|
418
|
+
name: b
|
419
|
+
});
|
420
|
+
});
|
421
|
+
})
|
422
|
+
);
|
423
|
+
const m = await ft(t);
|
424
|
+
for (const c of $.keyframes) {
|
425
|
+
const { value: h } = c, b = `a_${h.animationName}.css`, f = `css/${b}`, w = u(a, f);
|
426
|
+
o.push(b), D(w, h.css);
|
427
|
+
}
|
428
|
+
const i = {};
|
429
|
+
for (const c of $.components) {
|
430
|
+
const { src: h, name: b } = c;
|
431
|
+
i[h] || (i[h] = []);
|
432
|
+
const f = c.generator._withBuildContext({
|
433
|
+
callerName: b,
|
434
|
+
isProduction: e,
|
435
|
+
config: m
|
436
|
+
});
|
437
|
+
r[f.priority] || (r[f.priority] = []);
|
438
|
+
const w = await f.css;
|
439
|
+
if (!w) continue;
|
440
|
+
r[f.priority].push(f.cssFileName);
|
441
|
+
const P = `css/${f.cssFileName}`, V = u(a, P);
|
442
|
+
D(V, w), m.importStrategy === "component" && i[h].push(f.cssFileName);
|
443
|
+
}
|
444
|
+
for (const c of $.classNames) {
|
445
|
+
const { src: h, name: b } = c;
|
446
|
+
i[h] || (i[h] = []);
|
447
|
+
const f = c.generator._withBuildContext({
|
448
|
+
callerName: b,
|
449
|
+
isProduction: e,
|
450
|
+
config: m
|
451
|
+
}), w = await f.css;
|
452
|
+
if (!w) continue;
|
453
|
+
r[0].push(f.cssFileName);
|
454
|
+
const P = `css/${f.cssFileName}`, V = u(a, P);
|
455
|
+
D(V, w), m.importStrategy === "component" && i[h].push(f.cssFileName);
|
456
|
+
}
|
457
|
+
m.importStrategy === "component" && Object.entries(i).forEach(([c, h]) => {
|
458
|
+
const b = h.map((G) => `@import url('./${G}');`).join(`
|
459
|
+
`), f = z(c, 6), w = tt(c), P = A(w.name), V = u(a, `css/f_${P}-${f}.css`);
|
460
|
+
D(V, b || "/* Empty file */");
|
461
|
+
});
|
462
|
+
const p = o.map((c) => `@import url('./css/${c}');`).join(`
|
463
|
+
`);
|
464
|
+
let k = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
465
|
+
|
466
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
|
467
|
+
try {
|
468
|
+
return M(u(a, "css", c), "utf8").length > 0;
|
469
|
+
} catch {
|
470
|
+
return !1;
|
471
|
+
}
|
472
|
+
}).map((c) => `@import url('./css/${c}');`).join(`
|
473
|
+
`)}
|
474
|
+
${p}`;
|
475
|
+
if (m.importStrategy !== "component") {
|
476
|
+
const c = r.reduce((h, b, f) => {
|
477
|
+
const w = b.reduce((K, Z) => {
|
478
|
+
var U;
|
479
|
+
const Q = u(a, "css", Z), st = M(Q, "utf8"), q = ((U = /.*-([^-]+)-\d+.css/.exec(Z)) == null ? void 0 : U.at(1)) || z(Q, 6);
|
480
|
+
return K.includes(q) ? K : `${K}
|
481
|
+
/*start:${q}-${Z}*/
|
482
|
+
${st}
|
483
|
+
/*end:${q}*/
|
484
|
+
`;
|
485
|
+
}, ""), P = `l_${f}.css`, V = u(a, "css", P), G = `@layer l${f} { ${w}
|
486
|
+
}`;
|
487
|
+
return D(V, G), `${h}
|
488
|
+
@import url('./css/${P}');`;
|
489
|
+
}, "");
|
490
|
+
k += c;
|
491
|
+
}
|
492
|
+
D(g, k);
|
493
|
+
const C = Date.now() - n, _ = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
|
494
|
+
it.info(`Generated CSS in ${C}ms! ${_}`);
|
495
|
+
} catch (n) {
|
496
|
+
console.error(n);
|
497
|
+
}
|
498
|
+
}, re = async (t, e, s = ut()) => {
|
499
|
+
try {
|
500
|
+
const n = await v(t);
|
501
|
+
if (ct(e)) {
|
502
|
+
const r = [], a = await ft(t), { contents: g } = await et(t, e, n);
|
503
|
+
for (const [j, l] of Object.entries(g)) {
|
504
|
+
if (l.isKeyframes && l.css) {
|
505
|
+
const p = `css/${`a_${l.animationName}.css`}`, N = u(n, p);
|
506
|
+
D(N, await l.css);
|
507
|
+
return;
|
508
|
+
}
|
509
|
+
if (l.isClassName) {
|
510
|
+
const i = l.generator._withBuildContext({
|
511
|
+
callerName: j,
|
512
|
+
isProduction: s,
|
513
|
+
config: a
|
514
|
+
}), p = await i.css;
|
515
|
+
if (!p) continue;
|
516
|
+
r[0].push(i.cssFileName);
|
517
|
+
const N = `css/${i.cssFileName}`, F = u(n, N);
|
518
|
+
D(F, p);
|
519
|
+
}
|
520
|
+
if (!l.generator) return;
|
521
|
+
const d = l.generator._withBuildContext({
|
522
|
+
callerName: j,
|
523
|
+
isProduction: s,
|
524
|
+
config: a
|
525
|
+
}), y = await d.css;
|
526
|
+
if (!y) continue;
|
527
|
+
const $ = `css/${d.cssFileName}`, m = u(n, $);
|
528
|
+
D(m, y), r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
|
529
|
+
}
|
530
|
+
if (a.importStrategy !== "component")
|
531
|
+
r.forEach((j, l) => {
|
532
|
+
const d = `l_${l}.css`, y = u(n, "css", d);
|
533
|
+
let $ = M(y, "utf8");
|
534
|
+
j.forEach((m) => {
|
535
|
+
var F;
|
536
|
+
const i = u(n, "css", m), p = ((F = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : F.at(1)) || z(i, 6);
|
537
|
+
if (!$.includes(p)) {
|
538
|
+
const R = M(i, "utf8"), k = `/*start:${p}-${m}*/
|
539
|
+
${R}
|
540
|
+
/*end:${p}*/
|
541
|
+
`;
|
542
|
+
$ = `${$.replace(/\}$/, "")}
|
543
|
+
${k}
|
544
|
+
}`;
|
545
|
+
}
|
546
|
+
}), D(y, $);
|
547
|
+
});
|
548
|
+
else {
|
549
|
+
const j = r.flat().map((m) => `@import url('./${m}');`).join(`
|
550
|
+
`), l = z(e, 6), d = tt(e), y = A(d.name), $ = u(n, `css/f_${y}-${l}.css`);
|
551
|
+
D($, j || "/* Empty file */");
|
552
|
+
}
|
553
|
+
}
|
554
|
+
} catch (n) {
|
555
|
+
console.error(n);
|
556
|
+
}
|
557
|
+
}, ie = async (t, e, s = ut()) => {
|
558
|
+
try {
|
559
|
+
const n = await v(t);
|
560
|
+
if (ct(e)) {
|
561
|
+
const r = M(e, "utf8");
|
562
|
+
r.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== r && await Tt(e, r);
|
563
|
+
const g = await ft(t), { contents: j } = await et(t, e, n);
|
564
|
+
let l = r;
|
565
|
+
if (Object.entries(j).forEach(([d, y]) => {
|
566
|
+
var f;
|
567
|
+
if (y.isKeyframes || !y.generator) return;
|
568
|
+
const $ = y.generator._withBuildContext({
|
569
|
+
callerName: d,
|
570
|
+
isProduction: s,
|
571
|
+
config: g
|
572
|
+
}), m = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
573
|
+
if (!m) return console.error("Could not find the original declaration");
|
574
|
+
const i = (f = m.at(1)) == null ? void 0 : f.trim(), p = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(l);
|
575
|
+
if (!p) return console.error("Could not find the original declaration");
|
576
|
+
const { index: N } = p;
|
577
|
+
let F = !1;
|
578
|
+
const R = setTimeout(() => F = !0, 5e3);
|
579
|
+
let k = 0, O = !1, C = 0;
|
580
|
+
for (; !O && !F; ) {
|
581
|
+
const w = l[N + k];
|
582
|
+
w === "(" && C++, w === ")" && C--, C === 0 && w === ")" && (O = !0), k > l.length && (F = !0), k++;
|
583
|
+
}
|
584
|
+
if (!F) clearTimeout(R);
|
585
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
586
|
+
const _ = N + k, c = l.slice(N, _), h = l, b = ` ${d} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;
|
587
|
+
l = l.replace(c, b), h === l && console.error("Minimize file failed to change content", { name: d, tagName: i });
|
588
|
+
}), g.importStrategy === "component") {
|
589
|
+
const d = z(e, 6), y = tt(e);
|
590
|
+
l = `import '../../saltygen/css/${`f_${A(y.name)}-${d}.css`}';
|
591
|
+
${l}`;
|
592
|
+
}
|
593
|
+
return l = l.replace("{ styled }", "{ styledClient as styled }"), l = l.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), l;
|
594
|
+
}
|
595
|
+
} catch (n) {
|
596
|
+
console.error("Error in minimizeFile:", n);
|
597
|
+
}
|
598
|
+
};
|
599
|
+
export {
|
600
|
+
re as a,
|
601
|
+
oe as g,
|
602
|
+
ct as i,
|
603
|
+
ie as m,
|
604
|
+
Lt as s
|
605
|
+
};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";const Ne=require("esbuild"),ke=require("child_process"),l=require("path"),d=require("fs"),ie=require("fs/promises"),L=require("winston");var oe=typeof document<"u"?document.currentScript:null;function _e(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ye=_e(Ne),pe=e=>String.fromCharCode(e+(e>25?39:97)),De=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=pe(n%52)+s;return s=pe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Ee=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},J=(e,t=5)=>{const s=Ee(5381,JSON.stringify(e))>>>0;return De(s,t)};function R(e){return e?typeof e!="string"?R(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const Oe=e=>t=>{if(typeof t!="string"||!e)return;let s=t;const n=[];return Object.values(e).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,g=>{const{value:C,css:f}=a(g);return f&&n.push(f),C})}),{transformed:s,additionalCss:n}},ge=e=>t=>typeof t!="string"||!/\{[^{}]+\}/g.test(t)?void 0:{transformed:t.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${R(o[1].replaceAll(".","-"))})`)},Te=ge(),Ve=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Me=(e,t,s)=>Ve.some(o=>typeof o=="string"?o===e:o.test(e))?`${t}px`:`${t}`,Re=["Webkit","Moz","ms","O"],ze=e=>e.startsWith("-")?e:Re.some(t=>e.startsWith(t))?`-${R(e)}`:R(e),X=async(e,t="",s,n=!1)=>{if(!e)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(e).map(async([y,i])=>{const m=y.trim(),k=ze(m),x=(_,T=";")=>`${k}:${_}${T}`;if(typeof i=="function"&&(i=i({scope:t,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return x(i.toString());if(m==="defaultVariants")return;if(m==="variants"){const j=Object.entries(i);for(const[E,c]of j){if(!c)return;const h=Object.entries(c);for(const[b,u]of h){if(!u)return;const S=`${t}.${E}-${b}`;(await X(u,S,s)).forEach(V=>o.add(V))}}return}if(m==="compoundVariants"){for(const j of i){const{css:E,...c}=j,h=Object.entries(c).reduce((u,[S,N])=>`${u}.${S}-${N}`,t);(await X(E,h,s)).forEach(u=>o.add(u))}return}if(m.startsWith("@")){const j=m,E=await B(i,t,s),c=`${j} { ${E} }`;o.add(c);return}const _=y.includes("&")?m.replace("&",t):m.startsWith(":")?`${t}${m}`:`${t} ${m}`;(await X(i,_,s)).forEach(j=>o.add(j));return}if(typeof i=="number"){const _=Me(k,i);return x(_)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${k}`);return x(i)}),{modifiers:g}={},C=[ge(),Oe(g)],p=(await Promise.all(a).then(y=>Promise.all(y.map(i=>C.reduce(async(m,k)=>{const x=await m;if(!x)return x;const M=await k(x);if(!M)return x;const{transformed:_,additionalCss:T}=M;let j="";if(T)for(const E of T)j+=await B(E,"");return`${j}${_}`},Promise.resolve(i)))))).filter(y=>y!==void 0).join(`
|
2
|
+
`);if(!p.trim())return Array.from(o);const w=t?`${t} {
|
3
|
+
${p}
|
4
|
+
}`:p;return o.has(w)?Array.from(o):[w,...o]},B=async(e,t,s,n=!1)=>(await X(e,t,s,n)).join(`
|
5
|
+
`),he=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,r]of Object.entries(e))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),g=await he(r,[...t,a]);s.push(g)}else n[o]=r;if(Object.keys(n).length){const o=t.map(R).join("-"),r="t_"+J(o,4),a=await B(n,`.${o}, .${r}`);s.push(a)}return s.join(`
|
6
|
+
`)},Ae=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=we(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},we=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const r=t?`${t}.${n}`:n;return typeof o=="object"?we(o,r,s):s.add(t)}),[...s]):[],$e=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return d.existsSync(t)?t:$e(l.join(e,".."))},Je=async e=>{const t=$e(e);return await ie.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},We=async e=>{const t=await Je(e);if(t)return t.type};let I;const be=async e=>{if(I)return I;const t=await We(e);return t==="module"?I="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:oe&&oe.tagName.toUpperCase()==="SCRIPT"&&oe.src||new URL("index-DkYpiTkg.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},re=L.createLogger({level:"debug",format:L.format.combine(L.format.colorize(),L.format.cli()),transports:[new L.transports.Console({})]});function Se(e){return e?typeof e!="string"?Se(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const ve={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),Ie=(...e)=>e.flat().reduce((t,s)=>({...t,...s._children}),{}),A={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(A.externalModules.length>0)return A.externalModules;const s=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return A.externalModules=n,n},W=async e=>{if(A.destDir)return A.destDir;const t=await ae(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return A.destDir=s,s},Fe=["salty","css","styles","styled"],Ce=(e=[])=>new RegExp(`\\.(${[...Fe,...e].join("|")})\\.`),Y=(e,t=[])=>Ce(t).test(e),xe=async e=>{if(A.rcFile)return A.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await ie.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(A.rcFile=s,s):xe(l.join(e,".."))},ae=async e=>{var n,o;const t=await xe(e),s=(n=t.projects)==null?void 0:n.find(r=>e.endsWith(r.dir||""));return s||((o=t.projects)==null?void 0:o.find(r=>r.dir===t.defaultProject))},Ze=async e=>{const t=await ae(e),s=await W(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),r=await be(e),a=je(n);await ye.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const g=Date.now(),{config:C}=await import(`${o}?t=${g}`);return C},qe=async(e,t)=>{var fe,ue;const s=await W(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async F=>{const{contents:P,outputFilePath:z}=await ee(e,F,s);Object.entries(P).forEach(([D,O])=>{O.isMedia?n.mediaQueries.push([D,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(`${D};;${z}`))})}));const o=await Ze(e),r={...o},a=new Set,g=(F,P=[])=>F?Object.entries(F).flatMap(([z,D])=>{if(!D)return;if(typeof D=="object")return g(D,[...P,z]);const O=Se(z),se=R(z),ne=[...P,O].join(".");a.add(`"${ne}"`);const U=[...P.map(R),se].join("-"),de=Te(D);return de?`--${U}: ${de.transformed};`:`--${U}: ${D};`}):[],C=F=>F?Object.entries(F).flatMap(([P,z])=>{const D=g(z);return P==="base"?D.join(""):`${P} { ${D.join("")} }`}):[],f=F=>F?Object.entries(F).flatMap(([P,z])=>Object.entries(z).flatMap(([D,O])=>{const se=g(O,[P]),ne=`.${P}-${D}, [data-${P}="${D}"]`,U=se.join("");return`${ne} { ${U} }`})):[],p=F=>({...F,responsive:void 0,conditional:void 0}),w=F=>n.variables.map(P=>F==="static"?p(P._current):P._current[F]),$=Z(p(o.variables),w("static")),y=g($),i=Z((fe=o.variables)==null?void 0:fe.responsive,w("responsive")),m=C(i),k=Z((ue=o.variables)==null?void 0:ue.conditional,w("conditional")),x=f(k),M=l.join(s,"css/_variables.css"),_=`:root { ${y.join("")} ${m.join("")} } ${x.join("")}`;d.writeFileSync(M,_),r.staticVariables=$;const T=l.join(s,"css/_global.css"),j=Z(o.global,n.globalStyles),E=await B(j,"");d.writeFileSync(T,`@layer global { ${E} }`);const c=l.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:ve,u=await B(b,"");d.writeFileSync(c,`@layer reset { ${u} }`);const S=l.join(s,"css/_templates.css"),N=Z(o.templates,n.templates),V=await he(N),q=Ae(N);d.writeFileSync(S,`@layer templates { ${V} }`),r.templates=N;const H=Ie(n.templates);r.templatePaths=Object.fromEntries(Object.entries(H).map(([F,P])=>[F,P._path]));const{mediaQueries:v}=n;r.mediaQueries=Object.fromEntries(v.map(([F,P])=>[`@${F}`,P]));const G=v.map(([F])=>`'@${F}'`).join(" | "),te=l.join(s,"types/css-tokens.d.ts"),Q=`
|
7
|
+
// Variable types
|
8
|
+
type VariableTokens = ${[...a].join("|")};
|
9
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
10
|
+
|
11
|
+
// Template types
|
12
|
+
type TemplateTokens = {
|
13
|
+
${Object.entries(q).map(([F,P])=>`${F}?: ${P}`).join(`
|
14
|
+
`)}
|
15
|
+
}
|
16
|
+
|
17
|
+
// Media query types
|
18
|
+
type MediaQueryKeys = ${G||"''"};
|
19
|
+
`;d.writeFileSync(te,Q);const Pe=l.join(s,"cache/config-cache.json");d.writeFileSync(Pe,JSON.stringify(r,null,2))},me=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const a=o.exec(e);if(a){const g=a.at(1);if(Fe.some(f=>g==null?void 0:g.includes(f)))return t}return"styled('div',"}),He=(e,t)=>{try{const s=d.readFileSync(l.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
+
|
21
|
+
${e}`:`globalThis.saltyConfig = {};
|
22
|
+
|
23
|
+
${e}`}catch{return e}},ee=async(e,t,s)=>{const n=J(t),o=l.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=l.parse(t);let a=d.readFileSync(t,"utf8");a=me(a),a=He(a,e);const g=l.join(s,"js",n+".js"),C=await ae(e),f=l.join(e,(C==null?void 0:C.configDir)||"","salty.config.ts"),p=je(f),w=await be(e);await ye.build({stdin:{contents:a,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:g,format:w,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:i=>{i.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},m=>{const k=d.readFileSync(m.path,"utf8");return{contents:me(k),loader:"ts"}})}}]});const $=Date.now();return{contents:await import(`${g}?t=${$}`),outputFilePath:g}},Le=async e=>{const t=await W(e),s=l.join(t,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ce=async e=>{const t=await Le(e),s=await W(e),n=l.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return Z(r,t)},le=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Be=async(e,t=le(),s=!0)=>{try{const n=Date.now();t?re.info("Generating CSS in production mode! 🔥"):re.info("Generating CSS in development mode! 🚀");const o=[],r=[],a=await W(e),g=l.join(a,"index.css");s&&(()=>{d.existsSync(a)&&ke.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(l.join(a,"css")),d.mkdirSync(l.join(a,"types")),d.mkdirSync(l.join(a,"js")),d.mkdirSync(l.join(a,"cache"))})();const f=new Set,p=new Set;async function w(c){const h=["node_modules","saltygen"],b=d.statSync(c);if(b.isDirectory()){const u=d.readdirSync(c);if(h.some(N=>c.includes(N)))return;await Promise.all(u.map(N=>w(l.join(c,N))))}else if(b.isFile()&&Y(c)){f.add(c);const S=d.readFileSync(c,"utf8");/define[\w\d]+\(/.test(S)&&p.add(c)}}await w(e),await qe(e,p);const $={keyframes:[],components:[],classNames:[]};await Promise.all([...f].map(async c=>{const{contents:h}=await ee(e,c,a);Object.entries(h).forEach(([b,u])=>{u.isKeyframes?$.keyframes.push({value:u,src:c,name:b}):u.isClassName?$.classNames.push({...u,src:c,name:b}):u.generator&&$.components.push({...u,src:c,name:b})})}));const y=await ce(e);for(const c of $.keyframes){const{value:h}=c,b=`a_${h.animationName}.css`,u=`css/${b}`,S=l.join(a,u);o.push(b),d.writeFileSync(S,h.css)}const i={};for(const c of $.components){const{src:h,name:b}=c;i[h]||(i[h]=[]);const u=c.generator._withBuildContext({callerName:b,isProduction:t,config:y});r[u.priority]||(r[u.priority]=[]);const S=await u.css;if(!S)continue;r[u.priority].push(u.cssFileName);const N=`css/${u.cssFileName}`,V=l.join(a,N);d.writeFileSync(V,S),y.importStrategy==="component"&&i[h].push(u.cssFileName)}for(const c of $.classNames){const{src:h,name:b}=c;i[h]||(i[h]=[]);const u=c.generator._withBuildContext({callerName:b,isProduction:t,config:y}),S=await u.css;if(!S)continue;r[0].push(u.cssFileName);const N=`css/${u.cssFileName}`,V=l.join(a,N);d.writeFileSync(V,S),y.importStrategy==="component"&&i[h].push(u.cssFileName)}y.importStrategy==="component"&&Object.entries(i).forEach(([c,h])=>{const b=h.map(q=>`@import url('./${q}');`).join(`
|
24
|
+
`),u=J(c,6),S=l.parse(c),N=R(S.name),V=l.join(a,`css/f_${N}-${u}.css`);d.writeFileSync(V,b||"/* Empty file */")});const m=o.map(c=>`@import url('./css/${c}');`).join(`
|
25
|
+
`);let _=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
26
|
+
|
27
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return d.readFileSync(l.join(a,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
|
28
|
+
`)}
|
29
|
+
${m}`;if(y.importStrategy!=="component"){const c=r.reduce((h,b,u)=>{const S=b.reduce((H,v)=>{var Q;const G=l.join(a,"css",v),te=d.readFileSync(G,"utf8"),K=((Q=/.*-([^-]+)-\d+.css/.exec(v))==null?void 0:Q.at(1))||J(G,6);return H.includes(K)?H:`${H}
|
30
|
+
/*start:${K}-${v}*/
|
31
|
+
${te}
|
32
|
+
/*end:${K}*/
|
33
|
+
`},""),N=`l_${u}.css`,V=l.join(a,"css",N),q=`@layer l${u} { ${S}
|
34
|
+
}`;return d.writeFileSync(V,q),`${h}
|
35
|
+
@import url('./css/${N}');`},"");_+=c}d.writeFileSync(g,_);const j=Date.now()-n,E=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";re.info(`Generated CSS in ${j}ms! ${E}`)}catch(n){console.error(n)}},Ge=async(e,t,s=le())=>{try{const n=await W(e);if(Y(t)){const r=[],a=await ce(e),{contents:g}=await ee(e,t,n);for(const[C,f]of Object.entries(g)){if(f.isKeyframes&&f.css){const m=`css/${`a_${f.animationName}.css`}`,k=l.join(n,m);d.writeFileSync(k,await f.css);return}if(f.isClassName){const i=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),m=await i.css;if(!m)continue;r[0].push(i.cssFileName);const k=`css/${i.cssFileName}`,x=l.join(n,k);d.writeFileSync(x,m)}if(!f.generator)return;const p=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),w=await p.css;if(!w)continue;const $=`css/${p.cssFileName}`,y=l.join(n,$);d.writeFileSync(y,w),r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName)}if(a.importStrategy!=="component")r.forEach((C,f)=>{const p=`l_${f}.css`,w=l.join(n,"css",p);let $=d.readFileSync(w,"utf8");C.forEach(y=>{var x;const i=l.join(n,"css",y),m=((x=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:x.at(1))||J(i,6);if(!$.includes(m)){const M=d.readFileSync(i,"utf8"),_=`/*start:${m}-${y}*/
|
36
|
+
${M}
|
37
|
+
/*end:${m}*/
|
38
|
+
`;$=`${$.replace(/\}$/,"")}
|
39
|
+
${_}
|
40
|
+
}`}}),d.writeFileSync(w,$)});else{const C=r.flat().map(y=>`@import url('./${y}');`).join(`
|
41
|
+
`),f=J(t,6),p=l.parse(t),w=R(p.name),$=l.join(n,`css/f_${w}-${f}.css`);d.writeFileSync($,C||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=le())=>{try{const n=await W(e);if(Y(t)){const r=d.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await ie.writeFile(t,r);const g=await ce(e),{contents:C}=await ee(e,t,n);let f=r;if(Object.entries(C).forEach(([p,w])=>{var u;if(w.isKeyframes||!w.generator)return;const $=w.generator._withBuildContext({callerName:p,isProduction:s,config:g}),y=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!y)return console.error("Could not find the original declaration");const i=(u=y.at(1))==null?void 0:u.trim(),m=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(f);if(!m)return console.error("Could not find the original declaration");const{index:k}=m;let x=!1;const M=setTimeout(()=>x=!0,5e3);let _=0,T=!1,j=0;for(;!T&&!x;){const S=f[k+_];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(T=!0),_>f.length&&(x=!0),_++}if(!x)clearTimeout(M);else throw new Error("Failed to find the end of the styled call and timed out");const E=k+_,c=f.slice(k,E),h=f,b=` ${p} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;f=f.replace(c,b),h===f&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),g.importStrategy==="component"){const p=J(t,6),w=l.parse(t);f=`import '../../saltygen/css/${`f_${R(w.name)}-${p}.css`}';
|
42
|
+
${f}`}return f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=Be;exports.generateFile=Ge;exports.isSaltyFile=Y;exports.minimizeFile=Ke;exports.saltyFileRegExp=Ce;
|
package/index.cjs
CHANGED
@@ -1,15 +1 @@
|
|
1
|
-
"use strict";Object.
|
2
|
-
${f.replace(`
|
3
|
-
`,`
|
4
|
-
`)}
|
5
|
-
}`;return r.push(i),l}const j=$.includes("&")?y.replace("&",s):y.startsWith(":")?`${s}${y}`:`${s} ${y}`,d=k(o,j);return r.push(d),l}const g=y.startsWith("-")?y:V(y),w=(j,d=";")=>l=`${l}${j}${d}`,O=j=>w(`${g}:${j}`);if(typeof o=="number")return O(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return l;const{modifiers:C}={},D=function*(){yield M(o),yield G(o,C)}();for(const{result:j,additionalCss:d=[]}of D)o=j,d.forEach(f=>{const i=k(f,"");w(i,"")});return O(o)},"");if(!a)return r.join(`
|
6
|
-
`);if(!s)return a;let b="";return b=`${s} { ${a} }`,[b,...r].join(`
|
7
|
-
`)},_=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,a])=>{if(typeof a=="object"){if(!a)return;const b=r.trim(),l=_(a,[...s,b]);e.push(l)}else n[r]=a}),Object.keys(n).length){const r=s.map(V).join("-"),a=k(n,`.${r}`);e.push(a)}return e.join(`
|
8
|
-
`)},N=t=>u.join(t,"./saltygen"),J=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[...J,...t].join("|")})\\.`),K=(t,s=[])=>q(s).test(t),L=async t=>{const s=N(t),e=u.join(t,"salty.config.ts"),n=u.join(s,"salty.config.js");await x.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:a}=await import(`${n}?t=${r}`);return a},U=async t=>{const s=await L(t),e=new Set,n=(f,i=[])=>f?Object.entries(f).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return n(c,[...i,p]);const h=[...i,p].join(".");e.add(`"${h}"`);const S=[...i.map(V),V(p)].join("-"),{result:P}=M(c);return`--${S}: ${P};`}):[],r=f=>f?Object.entries(f).flatMap(([i,p])=>{const c=n(p);return i==="base"?c.join(""):`${i} { ${c.join("")} }`}):[],a=f=>f?Object.entries(f).flatMap(([i,p])=>Object.entries(p).flatMap(([c,h])=>{const S=n(h,[i]),P=`.${i}-${c}, [data-${i}="${c}"]`,T=S.join("");return`${P} { ${T} }`})):[],b=n(s.variables),l=r(s.responsiveVariables),$=a(s.conditionalVariables),o=N(t),y=u.join(o,"css/variables.css"),g=`:root { ${b.join("")} ${l.join("")} } ${$.join("")}`;m.writeFileSync(y,g);const w=u.join(o,"types/css-tokens.d.ts"),C=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(w,C);const F=u.join(o,"css/global.css"),D=k(s.global,"");m.writeFileSync(F,D);const j=u.join(o,"css/templates.css"),d=_(s.templates);m.writeFileSync(j,d)},X=async(t,s)=>{const e=A(t),n=u.join(s,"js",e+".js");await x.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}`)},Y=async t=>{const s=N(t),e=u.join(s,"salty.config.js"),{config:n}=await import(e);return n},Q=async t=>{try{const s=[],e=[],n=N(t),r=u.join(n,"index.css");(()=>{m.existsSync(n)&&W.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await U(t);const b=await Y(t);async function l(g,w){const O=m.statSync(g);if(O.isDirectory()){const C=m.readdirSync(g);await Promise.all(C.map(F=>l(u.join(g,F),u.join(w,F))))}else if(O.isFile()&&K(g)){const F=await X(g,n),D=[];Object.entries(F).forEach(([i,p])=>{if(p.isKeyframes&&p.css){const T=`${p.animationName}.css`,Z=`css/${T}`,R=u.join(n,Z);s.push(T),m.writeFileSync(R,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:i,config:b}),h=`${c.hash}-${c.priority}.css`;e[c.priority]||(e[c.priority]=[]),e[c.priority].push(h),D.push(h);const S=`css/${h}`,P=u.join(n,S);m.writeFileSync(P,c.css)});const j=D.map(i=>`@import url('./${i}');`).join(`
|
9
|
-
`),d=A(g,6),f=u.join(n,`css/${d}.css`);m.writeFileSync(f,j)}}await l(t,n);const $=s.map(g=>`@import url('./css/${g}');`).join(`
|
10
|
-
`);let y=`@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
|
-
${$}`;if(b.importStrategy!=="component"){const g=e.flat().map(w=>`@import url('./css/${w}');`).join(`
|
15
|
-
`);y+=g}m.writeFileSync(r,y)}catch(s){console.error(s)}},v=(t,s)=>{var e,n,r;(n=(e=t.module)==null?void 0:e.rules)==null||n.push({test:q(),use:[{loader:u.resolve("./loader.js"),options:{dir:s}}]}),(r=t.plugins)==null||r.push({apply:a=>{a.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await Q(s)})}})};exports.saltyPlugin=v;
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("path"),t=require("./index-DkYpiTkg.cjs"),y=require("fs/promises"),g=require("fs"),p=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!t.isSaltyFile(e))return!1;const a=await y.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(a)},c=(e,s,l=!1,a=!1)=>{var n,u,i;(u=(n=e.module)==null?void 0:n.rules)==null||u.push({test:t.saltyFileRegExp(),use:[{loader:d.resolve(__dirname,a?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),l||(i=e.plugins)==null||i.push({apply:f=>{let o=!1;f.hooks.watchRun.tapPromise({name:"generateCss"},async()=>{o||(o=!0,await t.generateCss(s),g.watch(s,{recursive:!0},async(h,r)=>{await p(r)?await t.generateCss(s,!1,!1):t.isSaltyFile(r)&&await t.generateFile(s,r)}))})}})};exports.default=c;exports.saltyPlugin=c;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,225 +1,35 @@
|
|
1
|
-
import {
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
const e = L(5381, JSON.stringify(t)) >>> 0;
|
16
|
-
return K(e, s);
|
17
|
-
};
|
18
|
-
function T(t) {
|
19
|
-
return t ? typeof t != "string" ? T(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 z = (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: a } = n;
|
27
|
-
t = t.replace(r, (g) => {
|
28
|
-
const { value: l, css: b } = a(g);
|
29
|
-
return b && e.push(b), l;
|
30
|
-
});
|
31
|
-
}), { result: t, additionalCss: e };
|
32
|
-
}, Z = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${T(n[1].replaceAll(".", "-"))})`) } : { result: t }, k = (t, s, e, n) => {
|
33
|
-
if (!t) return "";
|
34
|
-
const r = [], a = Object.entries(t).reduce((l, [b, o]) => {
|
35
|
-
const u = b.trim();
|
36
|
-
if (typeof o == "function" && (o = o()), typeof o == "object") {
|
37
|
-
if (!o) return l;
|
38
|
-
if (u === "variants")
|
39
|
-
return Object.entries(o).forEach(([f, i]) => {
|
40
|
-
i && Object.entries(i).forEach(([p, c]) => {
|
41
|
-
if (!c) return;
|
42
|
-
const h = `${s}.${f}-${p}`, j = k(c, h);
|
43
|
-
r.push(j);
|
44
|
-
});
|
45
|
-
}), l;
|
46
|
-
if (u === "defaultVariants")
|
47
|
-
return l;
|
48
|
-
if (u === "compoundVariants")
|
49
|
-
return o.forEach((f) => {
|
50
|
-
const { css: i, ...p } = f, c = Object.entries(p).reduce((j, [C, O]) => `${j}.${C}-${O}`, s), h = k(i, c);
|
51
|
-
r.push(h);
|
52
|
-
}), l;
|
53
|
-
if (u.startsWith("@")) {
|
54
|
-
const f = k(o, s), i = `${u} {
|
55
|
-
${f.replace(`
|
56
|
-
`, `
|
57
|
-
`)}
|
58
|
-
}`;
|
59
|
-
return r.push(i), l;
|
60
|
-
}
|
61
|
-
const $ = b.includes("&") ? u.replace("&", s) : u.startsWith(":") ? `${s}${u}` : `${s} ${u}`, d = k(o, $);
|
62
|
-
return r.push(d), l;
|
63
|
-
}
|
64
|
-
const y = u.startsWith("-") ? u : T(u), S = ($, d = ";") => l = `${l}${$}${d}`, D = ($) => S(`${y}:${$}`);
|
65
|
-
if (typeof o == "number") return D(o);
|
66
|
-
if (typeof o != "string")
|
67
|
-
if ("toString" in o) o = o.toString();
|
68
|
-
else return l;
|
69
|
-
const { modifiers: F } = {}, V = function* () {
|
70
|
-
yield Z(o), yield z(o, F);
|
71
|
-
}();
|
72
|
-
for (const { result: $, additionalCss: d = [] } of V)
|
73
|
-
o = $, d.forEach((f) => {
|
74
|
-
const i = k(f, "");
|
75
|
-
S(i, "");
|
76
|
-
});
|
77
|
-
return D(o);
|
78
|
-
}, "");
|
79
|
-
if (!a) return r.join(`
|
80
|
-
`);
|
81
|
-
if (!s) return a;
|
82
|
-
let g = "";
|
83
|
-
return g = `${s} { ${a} }`, [g, ...r].join(`
|
84
|
-
`);
|
85
|
-
}, R = (t, s = []) => {
|
86
|
-
if (!t) return "";
|
87
|
-
const e = [], n = {};
|
88
|
-
if (Object.entries(t).forEach(([r, a]) => {
|
89
|
-
if (typeof a == "object") {
|
90
|
-
if (!a) return;
|
91
|
-
const g = r.trim(), l = R(a, [...s, g]);
|
92
|
-
e.push(l);
|
93
|
-
} else
|
94
|
-
n[r] = a;
|
95
|
-
}), Object.keys(n).length) {
|
96
|
-
const r = s.map(T).join("-"), a = k(n, `.${r}`);
|
97
|
-
e.push(a);
|
98
|
-
}
|
99
|
-
return e.join(`
|
100
|
-
`);
|
101
|
-
}, N = (t) => m(t, "./saltygen"), U = ["salty", "css", "styles", "styled"], I = (t = []) => new RegExp(`\\.(${[...U, ...t].join("|")})\\.`), X = (t, s = []) => I(s).test(t), Y = async (t) => {
|
102
|
-
const s = N(t), e = m(t, "salty.config.ts"), n = m(s, "salty.config.js");
|
103
|
-
await A.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: a } = await import(`${n}?t=${r}`);
|
113
|
-
return a;
|
114
|
-
}, Q = async (t) => {
|
115
|
-
const s = await Y(t), e = /* @__PURE__ */ new Set(), n = (f, i = []) => f ? Object.entries(f).flatMap(([p, c]) => {
|
116
|
-
if (!c) return;
|
117
|
-
if (typeof c == "object") return n(c, [...i, p]);
|
118
|
-
const h = [...i, p].join(".");
|
119
|
-
e.add(`"${h}"`);
|
120
|
-
const j = [...i.map(T), T(p)].join("-"), { result: C } = Z(c);
|
121
|
-
return `--${j}: ${C};`;
|
122
|
-
}) : [], r = (f) => f ? Object.entries(f).flatMap(([i, p]) => {
|
123
|
-
const c = n(p);
|
124
|
-
return i === "base" ? c.join("") : `${i} { ${c.join("")} }`;
|
125
|
-
}) : [], a = (f) => f ? Object.entries(f).flatMap(([i, p]) => Object.entries(p).flatMap(([c, h]) => {
|
126
|
-
const j = n(h, [i]), C = `.${i}-${c}, [data-${i}="${c}"]`, O = j.join("");
|
127
|
-
return `${C} { ${O} }`;
|
128
|
-
})) : [], g = n(s.variables), l = r(s.responsiveVariables), b = a(s.conditionalVariables), o = N(t), u = m(o, "css/variables.css"), y = `:root { ${g.join("")} ${l.join("")} } ${b.join("")}`;
|
129
|
-
w(u, y);
|
130
|
-
const S = m(o, "types/css-tokens.d.ts"), F = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
131
|
-
w(S, F);
|
132
|
-
const P = m(o, "css/global.css"), V = k(s.global, "");
|
133
|
-
w(P, V);
|
134
|
-
const $ = m(o, "css/templates.css"), d = R(s.templates);
|
135
|
-
w($, d);
|
136
|
-
}, v = async (t, s) => {
|
137
|
-
const e = M(t), n = m(s, "js", e + ".js");
|
138
|
-
await A.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
|
-
}, tt = async (t) => {
|
152
|
-
const s = N(t), e = m(s, "salty.config.js"), { config: n } = await import(e);
|
153
|
-
return n;
|
154
|
-
}, st = async (t) => {
|
155
|
-
try {
|
156
|
-
const s = [], e = [], n = N(t), r = m(n, "index.css");
|
157
|
-
(() => {
|
158
|
-
B(n) && q("rm -rf " + n), x(n), x(m(n, "css")), x(m(n, "types"));
|
159
|
-
})(), await Q(t);
|
160
|
-
const g = await tt(t);
|
161
|
-
async function l(y, S) {
|
162
|
-
const D = G(y);
|
163
|
-
if (D.isDirectory()) {
|
164
|
-
const F = J(y);
|
165
|
-
await Promise.all(F.map((P) => l(m(y, P), m(S, P))));
|
166
|
-
} else if (D.isFile() && X(y)) {
|
167
|
-
const P = await v(y, n), V = [];
|
168
|
-
Object.entries(P).forEach(([i, p]) => {
|
169
|
-
if (p.isKeyframes && p.css) {
|
170
|
-
const O = `${p.animationName}.css`, W = `css/${O}`, _ = m(n, W);
|
171
|
-
s.push(O), w(_, p.css);
|
172
|
-
return;
|
173
|
-
}
|
174
|
-
if (!p.generator) return;
|
175
|
-
const c = p.generator._withBuildContext({
|
176
|
-
name: i,
|
177
|
-
config: g
|
178
|
-
}), h = `${c.hash}-${c.priority}.css`;
|
179
|
-
e[c.priority] || (e[c.priority] = []), e[c.priority].push(h), V.push(h);
|
180
|
-
const j = `css/${h}`, C = m(n, j);
|
181
|
-
w(C, c.css);
|
182
|
-
});
|
183
|
-
const $ = V.map((i) => `@import url('./${i}');`).join(`
|
184
|
-
`), d = M(y, 6), f = m(n, `css/${d}.css`);
|
185
|
-
w(f, $);
|
186
|
-
}
|
187
|
-
}
|
188
|
-
await l(t, n);
|
189
|
-
const b = s.map((y) => `@import url('./css/${y}');`).join(`
|
190
|
-
`);
|
191
|
-
let u = `@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
|
-
${b}`;
|
196
|
-
if (g.importStrategy !== "component") {
|
197
|
-
const y = e.flat().map((S) => `@import url('./css/${S}');`).join(`
|
198
|
-
`);
|
199
|
-
u += y;
|
200
|
-
}
|
201
|
-
w(r, u);
|
202
|
-
} catch (s) {
|
203
|
-
console.error(s);
|
204
|
-
}
|
205
|
-
}, it = (t, s) => {
|
206
|
-
var e, n, r;
|
207
|
-
(n = (e = t.module) == null ? void 0 : e.rules) == null || n.push({
|
208
|
-
test: I(),
|
1
|
+
import { resolve as d } from "path";
|
2
|
+
import { i as f, s as p, g as u, a as y } from "./index-C3XjWftB.js";
|
3
|
+
import { readFile as g } from "fs/promises";
|
4
|
+
import { watch as m } from "fs";
|
5
|
+
const w = async (s) => {
|
6
|
+
if (!s || s.includes("node_modules") || s.includes("saltygen")) return !1;
|
7
|
+
if (s.includes("salty.config")) return !0;
|
8
|
+
if (!f(s)) return !1;
|
9
|
+
const t = await g(s, "utf-8");
|
10
|
+
return !!/.+define[A-Z]\w+/.test(t);
|
11
|
+
}, j = (s, e, r = !1, t = !1) => {
|
12
|
+
var l, o, n;
|
13
|
+
(o = (l = s.module) == null ? void 0 : l.rules) == null || o.push({
|
14
|
+
test: p(),
|
209
15
|
use: [
|
210
16
|
{
|
211
|
-
loader:
|
212
|
-
options: { dir:
|
17
|
+
loader: d(__dirname, t ? "./loader.cjs" : "./loader.js"),
|
18
|
+
options: { dir: e }
|
213
19
|
}
|
214
20
|
]
|
215
|
-
}),
|
216
|
-
apply: (
|
217
|
-
|
218
|
-
|
21
|
+
}), r || (n = s.plugins) == null || n.push({
|
22
|
+
apply: (c) => {
|
23
|
+
let i = !1;
|
24
|
+
c.hooks.watchRun.tapPromise({ name: "generateCss" }, async () => {
|
25
|
+
i || (i = !0, await u(e), m(e, { recursive: !0 }, async (h, a) => {
|
26
|
+
await w(a) ? await u(e, !1, !1) : f(a) && await y(e, a);
|
27
|
+
}));
|
219
28
|
});
|
220
29
|
}
|
221
30
|
});
|
222
31
|
};
|
223
32
|
export {
|
224
|
-
|
33
|
+
j as default,
|
34
|
+
j as saltyPlugin
|
225
35
|
};
|
package/loader.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";const i=require("./index-DkYpiTkg.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.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.210",
|
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
|
-
"
|
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
|
},
|
@@ -28,8 +33,8 @@
|
|
28
33
|
"require": "./index.cjs"
|
29
34
|
}
|
30
35
|
},
|
31
|
-
"
|
32
|
-
"@salty-css/core": "^0.0.1-alpha.
|
36
|
+
"dependencies": {
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.210",
|
33
38
|
"webpack": ">=5.x"
|
34
39
|
}
|
35
40
|
}
|