@salty-css/core 0.0.1-alpha.18 → 0.0.1-alpha.180

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.
Files changed (64) hide show
  1. package/.saltyrc.schema.json +48 -0
  2. package/README.md +143 -26
  3. package/bin/index.cjs +1 -8
  4. package/bin/index.js +2 -129
  5. package/bin/logger.d.ts +1 -0
  6. package/bin/main.cjs +11 -0
  7. package/bin/main.d.ts +1 -0
  8. package/bin/main.js +260 -0
  9. package/compiler/get-files.d.ts +3 -0
  10. package/compiler/index.cjs +1 -11
  11. package/compiler/index.d.ts +28 -4
  12. package/compiler/index.js +18 -172
  13. package/config/define-config.d.ts +1 -1
  14. package/config/index.cjs +1 -1
  15. package/config/index.d.ts +2 -1
  16. package/config/index.js +12 -2
  17. package/css/index.cjs +1 -1
  18. package/css/index.d.ts +4 -1
  19. package/css/index.js +121 -2
  20. package/css/keyframes.d.ts +22 -0
  21. package/css/media.d.ts +87 -0
  22. package/css/merge.d.ts +6 -0
  23. package/css/token.d.ts +1 -0
  24. package/{dash-case-DKzpenwY.cjs → dash-case-BJEkFEGQ.cjs} +1 -1
  25. package/{dash-case-DMQMcCO6.js → dash-case-DBThphLm.js} +2 -2
  26. package/factories/define-global-styles.d.ts +7 -0
  27. package/factories/define-templates.d.ts +10 -0
  28. package/factories/define-variables.d.ts +15 -0
  29. package/factories/index.cjs +1 -0
  30. package/factories/index.d.ts +3 -0
  31. package/factories/index.js +38 -0
  32. package/generator/index.cjs +1 -1
  33. package/generator/index.js +50 -35
  34. package/generator/parse-modifiers.d.ts +1 -1
  35. package/generator/parse-styles.d.ts +2 -2
  36. package/generator/parse-templates.d.ts +2 -0
  37. package/generator/style-generator.d.ts +8 -0
  38. package/index-9iO5zogY.js +403 -0
  39. package/index-neHUpjdt.cjs +29 -0
  40. package/merge-BVm9us1A.js +4 -0
  41. package/merge-DxGoJDHv.cjs +1 -0
  42. package/package.json +12 -2
  43. package/parse-styles-3zK35muR.cjs +7 -0
  44. package/parse-styles-DrLhKtqW.js +75 -0
  45. package/parse-templates-DRKlN-pP.js +27 -0
  46. package/parse-templates-VIvmVb52.cjs +2 -0
  47. package/react-vanilla-file-CCXbsjIb.js +18 -0
  48. package/react-vanilla-file-CG_WJLam.cjs +15 -0
  49. package/{salty.config-D9ANEDiH.js → salty.config-BhBY_oOk.js} +1 -0
  50. package/{salty.config-BupieCfE.cjs → salty.config-Dk6ZcCxI.cjs} +3 -2
  51. package/server/index.cjs +1 -0
  52. package/server/index.d.ts +1 -0
  53. package/server/index.js +12 -0
  54. package/server/should-restart.d.ts +1 -0
  55. package/templates/salty-reset.d.ts +2 -0
  56. package/types/cli-types.d.ts +10 -0
  57. package/{config → types}/config-types.d.ts +15 -5
  58. package/types/index.d.ts +46 -19
  59. package/util/dot-case.d.ts +1 -0
  60. package/util/index.cjs +1 -1
  61. package/util/index.js +1 -1
  62. package/util/module-type.d.ts +1 -0
  63. package/parse-templates-D4p3pgQR.js +0 -92
  64. package/parse-templates-W0YfTmOT.cjs +0 -8
package/bin/main.js ADDED
@@ -0,0 +1,260 @@
1
+ import { Command as ot } from "commander";
2
+ import { existsSync as K } from "fs";
3
+ import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
4
+ import { join as i, relative as z, parse as rt, format as tt } from "path";
5
+ import { render as ct } from "ejs";
6
+ import { l as e, a as h, g as et } from "../index-9iO5zogY.js";
7
+ import { p as lt } from "../pascal-case-BQpR5PdN.js";
8
+ import { exec as dt } from "child_process";
9
+ import ft from "ora";
10
+ const st = (u) => new Promise((v, k) => {
11
+ dt(u, (F) => {
12
+ if (F) return k(F);
13
+ v();
14
+ });
15
+ }), E = async (...u) => {
16
+ const v = u.map((J) => J.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), k = ft(`Installing packages: ${v}`).start(), F = u.join(" ");
17
+ await st(`npm install ${F}`), k.succeed(`Installed packages: ${v}`);
18
+ }, pt = () => K(i(process.cwd(), "node_modules", ".bin", "prettier"));
19
+ async function j(u) {
20
+ try {
21
+ if (!pt()) return;
22
+ await st(`./node_modules/.bin/prettier --write "${u}"`), e.info(`Formatted ${u} with Prettier`);
23
+ } catch (v) {
24
+ e.error(`Error formatting ${u} with Prettier:`, v);
25
+ }
26
+ }
27
+ async function kt() {
28
+ const u = new ot();
29
+ u.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
30
+ const v = {
31
+ // Core files
32
+ "salty.config.ts": import("../salty.config-BhBY_oOk.js"),
33
+ "saltygen/index.css": import("../index-D_732b92.js"),
34
+ // React
35
+ "react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js"),
36
+ "react/react-vanilla-file.ts": import("../react-vanilla-file-CCXbsjIb.js")
37
+ }, k = async (s, a) => {
38
+ const { default: c } = await v[s], g = ct(c, a);
39
+ return { fileName: s, content: g };
40
+ }, F = async () => {
41
+ const s = i(process.cwd(), ".saltyrc.json");
42
+ return await C(s, "utf-8").then(JSON.parse).catch(() => ({}));
43
+ }, J = i(process.cwd(), "package.json"), O = async (s = J) => {
44
+ const a = await C(s, "utf-8").then(JSON.parse).catch(() => {
45
+ });
46
+ if (!a) throw "Could not read package.json file!";
47
+ return a;
48
+ }, nt = async (s, a = J) => {
49
+ typeof s == "object" && (s = JSON.stringify(s, null, 2)), await w(a, s);
50
+ }, Q = async () => {
51
+ const s = new URL("../package.json", import.meta.url);
52
+ return O(s);
53
+ }, X = await (async () => (await F()).defaultProject)(), N = await Q(), A = {
54
+ core: `@salty-css/core@${N.version}`,
55
+ react: `@salty-css/react@${N.version}`,
56
+ eslintConfigCore: `@salty-css/eslint-config-core@${N.version}`,
57
+ vite: `@salty-css/vite@${N.version}`,
58
+ next: `@salty-css/next@${N.version}`
59
+ }, G = (s) => {
60
+ const a = s === "." ? "" : s, c = process.cwd();
61
+ return i(c, a);
62
+ };
63
+ u.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").action(async function(s = ".") {
64
+ if (!await O().catch(() => {
65
+ })) return h("Salty CSS project must be initialized in a directory with a package.json file.");
66
+ e.info("Initializing a new Salty-CSS project!");
67
+ const { dir: c = s, cssFile: g, skipInstall: p } = this.opts();
68
+ if (!c) return h("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
69
+ p || await E(A.core, A.react);
70
+ const d = process.cwd(), o = G(c), H = await Promise.all([k("salty.config.ts"), k("saltygen/index.css")]);
71
+ await q(o, { recursive: !0 });
72
+ const y = H.map(async ({ fileName: t, content: f }) => {
73
+ const r = i(o, t);
74
+ if (await C(r, "utf-8").catch(() => {
75
+ }) !== void 0) {
76
+ e.debug("File already exists: " + r);
77
+ return;
78
+ }
79
+ const b = t.split("/").slice(0, -1).join("/");
80
+ b && await q(i(o, b), { recursive: !0 }), e.info("Creating file: " + r), await w(r, f), await j(r);
81
+ });
82
+ await Promise.all(y);
83
+ const S = z(d, o) || ".", m = i(d, ".saltyrc.json"), l = await C(m, "utf-8").catch(() => {
84
+ });
85
+ if (l === void 0) {
86
+ e.info("Creating file: " + m);
87
+ const f = JSON.stringify({
88
+ $schema: "./node_modules/@salty-css/core/.saltyrc.schema.json",
89
+ info: "This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",
90
+ defaultProject: S,
91
+ projects: [
92
+ {
93
+ dir: S,
94
+ framework: "react"
95
+ }
96
+ ]
97
+ }, null, 2);
98
+ await w(m, f), await j(m);
99
+ } else {
100
+ const t = JSON.parse(l), f = (t == null ? void 0 : t.projects) || [];
101
+ if (f.findIndex((n) => n.dir === S) === -1) {
102
+ f.push({ dir: S, framework: "react" }), t.projects = [...f];
103
+ const n = JSON.stringify(t, null, 2);
104
+ n !== l && (e.info("Edit file: " + m), await w(m, n), await j(m));
105
+ }
106
+ }
107
+ const P = i(d, ".gitignore"), U = await C(P, "utf-8").catch(() => {
108
+ });
109
+ U !== void 0 && (U.includes("saltygen") || (e.info("Edit file: " + P), await w(P, U + `
110
+
111
+ # Salty-CSS
112
+ saltygen
113
+ `)));
114
+ const $ = ["src", "public", "assets", "styles", "css", "app"], M = ["styles", "css", "app", "pages"], B = ["index", "styles", "main", "app", "global", "globals"], R = [".css", ".scss", ".sass"], D = await (async () => {
115
+ if (g) return g;
116
+ for (const t of $)
117
+ for (const f of B)
118
+ for (const r of R) {
119
+ const n = i(o, t, f + r);
120
+ if (await C(n, "utf-8").catch(() => {
121
+ }) !== void 0) return z(o, n);
122
+ for (const T of M) {
123
+ const L = i(o, t, T, f + r);
124
+ if (await C(L, "utf-8").catch(() => {
125
+ }) !== void 0) return z(o, L);
126
+ }
127
+ }
128
+ })();
129
+ if (D) {
130
+ const t = i(o, D), f = await C(t, "utf-8").catch(() => {
131
+ });
132
+ if (f !== void 0 && !f.includes("saltygen")) {
133
+ const n = i(t, ".."), T = `@import '${z(n, i(o, "saltygen/index.css"))}';`;
134
+ e.info("Adding global import statement to CSS file: " + t), await w(t, T + `
135
+ ` + f), await j(t);
136
+ }
137
+ } else
138
+ e.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
139
+ const it = {
140
+ projectJs: i(o, "eslint.config.js"),
141
+ rootJs: i(d, "eslint.config.js"),
142
+ projectMjs: i(o, "eslint.config.mjs"),
143
+ rootMjs: i(d, "eslint.config.mjs"),
144
+ projectJson: i(o, ".eslintrc.json"),
145
+ rootJson: i(d, ".eslintrc.json")
146
+ }, x = Object.values(it).find((t) => K(t));
147
+ if (x) {
148
+ p || await E(A.eslintConfigCore);
149
+ const t = await C(x, "utf-8").catch(() => {
150
+ });
151
+ if (!t) return h("Could not read ESLint config file.");
152
+ if (!t.includes("salty-css"))
153
+ if (e.info("Edit file: " + x), x.endsWith("js")) {
154
+ let n = `import saltyCss from "@salty-css/eslint-config-core/flat";
155
+ ${t}`;
156
+ t.includes("typescript-eslint") ? n.includes(".config(") ? n = n.replace(".config(", ".config(saltyCss,") : e.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.") : n.includes("export default [") ? n = n.replace("export default [", "export default [ saltyCss,") : n.includes("eslintConfig = [") ? n = n.replace("eslintConfig = [", "eslintConfig = [ saltyCss,") : e.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."), await w(x, n), await j(x);
157
+ } else {
158
+ const r = JSON.parse(t);
159
+ r.extends || (r.extends = []), r.extends.push("@salty-css/core");
160
+ const n = JSON.stringify(r, null, 2);
161
+ await w(x, n), await j(x);
162
+ }
163
+ }
164
+ const _ = i(o, "vite.config.ts"), V = await C(_, "utf-8").catch(() => {
165
+ });
166
+ if (V !== void 0 && !V.includes("saltyPlugin")) {
167
+ e.info("Edit file: " + _);
168
+ const f = `import { saltyPlugin } from '@salty-css/vite';
169
+ `, n = V.replace(/(plugins: \[)/, `$1
170
+ saltyPlugin(__dirname),`);
171
+ p || await E(`-D ${A.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await w(_, f + n), await j(_);
172
+ }
173
+ const W = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => i(o, t)).find((t) => K(t));
174
+ if (W) {
175
+ let t = await C(W, "utf-8").catch(() => {
176
+ });
177
+ if (t !== void 0 && !t.includes("withSaltyCss")) {
178
+ let r = !1;
179
+ /\splugins([^=]*)=[^[]\[/.test(t) && !r && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (L, I) => ` plugins${I}= [withSaltyCss,`), r = !0);
180
+ const b = t.includes("module.exports"), T = b ? `const { withSaltyCss } = require('@salty-css/next');
181
+ ` : `import { withSaltyCss } from '@salty-css/next';
182
+ `;
183
+ b && !r ? (t = t.replace(/module.exports = ([^;]+)/, (L, I) => `module.exports = withSaltyCss(${I})`), r = !0) : r || (t = t.replace(/export default ([^;]+)/, (L, I) => `export default withSaltyCss(${I})`)), p || await E(`-D ${A.next}`), e.info("Adding Salty-CSS plugin to Next.js config..."), await w(W, T + t), await j(W);
184
+ }
185
+ }
186
+ const at = await O().catch(() => h("Could not read package.json file.")).then((t) => (t.scripts || (t.scripts = {}), t.scripts.prepare ? t.scripts.prepare.includes("salty-css") || (e.info("Edit file: " + J), t.scripts.prepare = t.scripts.prepare + " && npx salty-css build") : (e.info("Edit file: " + J), t.scripts.prepare = "npx salty-css build"), t));
187
+ await nt(at), e.info("Running the build to generate initial CSS..."), await et(o), e.info("🎉 Salty CSS project initialized successfully!"), e.info("Next steps:"), e.info("1. Configure variables and templates in `salty.config.ts`"), e.info("2. Create a new component with `npx salty-css generate [component-name]`"), e.info("3. Run `npx salty-css build` to generate the CSS"), e.info("4. Read about the features in the documentation: https://salty-css.dev"), e.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
188
+ }), u.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").action(async function(s = X) {
189
+ e.info("Building the Salty-CSS project...");
190
+ const { dir: a = s } = this.opts();
191
+ if (!a) return h("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
192
+ const c = G(a);
193
+ await et(c);
194
+ }), u.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>", "File to generate.").option("-d, --dir <dir>", "Project directory to generate the file in.").option("-t, --tag <tag>", "HTML tag of the component.", "div").option("-n, --name <name>", "Name of the component.").option("-c, --className <className>", "CSS class of the component.").option("-r, --reactComponent", "Generate a React component as well.").action(async function(s, a = X) {
195
+ const { file: c = s, dir: g = a, tag: p, name: d, className: o, reactComponent: H = !1 } = this.opts();
196
+ if (!c) return h("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
197
+ if (!g) return h("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
198
+ const y = G(g), S = c.split("/").slice(0, -1).join("/");
199
+ S && await q(i(y, S), { recursive: !0 });
200
+ const m = i(y, c), l = rt(m);
201
+ l.ext || (l.ext = ".ts"), l.name.endsWith(".css") || (l.name = l.name + ".css"), l.base = l.name + l.ext;
202
+ const P = tt(l);
203
+ if (await C(P, "utf-8").catch(() => {
204
+ }) !== void 0) {
205
+ e.error("File already exists:", P);
206
+ return;
207
+ }
208
+ let $ = lt(d || l.base.replace(/\.css\.\w+$/, ""));
209
+ if (H) {
210
+ const B = $ + "Component";
211
+ $ = $ + "Wrapper";
212
+ const R = l.base.replace(/\.css\.\w+$/, ""), { content: Z } = await k("react/react-vanilla-file.ts", { tag: p, componentName: B, styledComponentName: $, className: o, fileName: R });
213
+ l.name = R.replace(/\.css$/, ""), l.ext = ".tsx", l.base = l.name + l.ext;
214
+ const D = tt(l);
215
+ e.info("Generating a new file: " + D), await w(D, Z), await j(D);
216
+ }
217
+ const { content: M } = await k("react/react-styled-file.ts", { tag: p, name: $, className: o });
218
+ e.info("Generating a new file: " + P), await w(P, M), await j(P);
219
+ });
220
+ const Y = async () => {
221
+ const s = i(process.cwd(), "package.json"), a = await O(s).catch((p) => h(p));
222
+ if (!a) return h("Could not read package.json file.");
223
+ const c = { ...a.dependencies, ...a.devDependencies }, g = Object.entries(c).filter(([p]) => p === "salty-css" || p.startsWith("@salty-css/"));
224
+ return g.length ? g : h(
225
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + s
226
+ );
227
+ };
228
+ u.command("update [version]").alias("up").description("Update Salty-CSS packages to the latest or specified version.").option("-v, --version <version>", "Version to update to.").option("--legacy-peer-deps <legacyPeerDeps>", "Use legacy peer dependencies (not recommended).", !1).action(async function(s = "latest") {
229
+ const { legacyPeerDeps: a, version: c = s } = this.opts(), g = await Y();
230
+ if (!g) return h("Could not update Salty-CSS packages as any were found in package.json.");
231
+ const p = g.map(([y]) => c === "@" ? `${y}@${N.version}` : `${y}@${c.replace(/^@/, "")}`);
232
+ a ? (e.warn("Using legacy peer dependencies to update packages."), await E(...p, "--legacy-peer-deps")) : await E(...p);
233
+ const d = await Y();
234
+ if (!d) return h("Something went wrong while reading the updated packages.");
235
+ const o = d.reduce((y, [S, m]) => (y[m] || (y[m] = []), y[m].push(S), y), {});
236
+ if (Object.keys(o).length === 1) {
237
+ const S = Object.keys(o)[0].replace(/^\^/, "");
238
+ e.info(`Updated to all Salty CSS packages successfully to ${S}`);
239
+ } else
240
+ for (const [y, S] of Object.entries(o)) {
241
+ const m = y.replace(/^\^/, "");
242
+ e.info(`Updated to ${m}: ${S.join(", ")}`);
243
+ }
244
+ }), u.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
245
+ const s = await Q();
246
+ e.info("CLI is running: " + s.version);
247
+ const a = i(process.cwd(), "package.json"), c = await O(a).catch((d) => h(d));
248
+ if (!c) return;
249
+ const g = { ...c.dependencies, ...c.devDependencies }, p = Object.keys(g).filter((d) => d === "salty-css" || d.startsWith("@salty-css/"));
250
+ if (!p.length)
251
+ return h(
252
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + a
253
+ );
254
+ for (const d of p)
255
+ e.info(`${d}: ${g[d]}`);
256
+ }), u.parseAsync(process.argv);
257
+ }
258
+ export {
259
+ kt as main
260
+ };
@@ -0,0 +1,3 @@
1
+ export declare const getSaltyRcPath: (dirname: string) => string;
2
+ export declare const getPackageJsonPath: (dirname: string) => string;
3
+ export declare const getPackageJson: (dirname: string) => Promise<any>;
@@ -1,11 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("esbuild"),B=require("child_process"),P=require("../dash-case-DKzpenwY.cjs"),o=require("path"),r=require("fs"),K=require("fs/promises"),V=require("../parse-templates-W0YfTmOT.cjs");function G(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const R=G(z),N=t=>o.join(t,"./saltygen"),_=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[..._,...t].join("|")})\\.`),O=(t,e=[])=>q(e).test(t),J=async t=>{const e=N(t),n=o.join(t,"salty.config.ts"),s=o.join(e,"salty.config.js");await R.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",external:["react"]});const a=Date.now(),{config:w}=await import(`${s}?t=${a}`);return w},M=async t=>{const e=await J(t),n=new Set,s=(d,y=[])=>d?Object.entries(d).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return s(c,[...y,p]);const C=[...y,p].join(".");n.add(`"${C}"`);const x=[...y.map(P.dashCase),P.dashCase(p)].join("-"),{result:D}=V.parseValueTokens(c);return`--${x}: ${D};`}):[],a=d=>d?Object.entries(d).flatMap(([y,p])=>{const c=s(p);return y==="base"?c.join(""):`${y} { ${c.join("")} }`}):[],w=d=>d?Object.entries(d).flatMap(([y,p])=>Object.entries(p).flatMap(([c,C])=>{const x=s(C,[y]),D=`.${y}-${c}, [data-${y}="${c}"]`,k=x.join("");return`${D} { ${k} }`})):[],j=s(e.variables),S=a(e.responsiveVariables),l=w(e.conditionalVariables),b=N(t),f=o.join(b,"css/variables.css"),i=`:root { ${j.join("")} ${S.join("")} } ${l.join("")}`;r.writeFileSync(f,i);const g=o.join(b,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,m);const u=o.join(b,"css/global.css"),h=V.parseStyles(e.global,"");r.writeFileSync(u,h);const F=o.join(b,"css/templates.css"),v=V.parseTemplates(e.templates);r.writeFileSync(F,v)},T=async(t,e)=>{const n=P.toHash(t),s=o.join(e,"js",n+".js");await R.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${s}?t=${a}`)},E=async t=>{const e=N(t),n=o.join(e,"salty.config.js"),{config:s}=await import(n);return s},A=async t=>{try{const e=[],n=[],s=N(t),a=o.join(s,"index.css");(()=>{r.existsSync(s)&&B.execSync("rm -rf "+s),r.mkdirSync(s),r.mkdirSync(o.join(s,"css")),r.mkdirSync(o.join(s,"types"))})(),await M(t);const j=await E(t);async function S(i,g){const $=r.statSync(i);if($.isDirectory()){const m=r.readdirSync(i);await Promise.all(m.map(u=>S(o.join(i,u),o.join(g,u))))}else if($.isFile()&&O(i)){const u=await T(i,s),h=[];Object.entries(u).forEach(([y,p])=>{if(p.isKeyframes&&p.css){const k=`${p.animationName}.css`,H=`css/${k}`,I=o.join(s,H);e.push(k),r.writeFileSync(I,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:y,config:j}),C=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(C),h.push(C);const x=`css/${C}`,D=o.join(s,x);r.writeFileSync(D,c.css)});const F=h.map(y=>`@import url('./${y}');`).join(`
2
- `),v=P.toHash(i,6),d=o.join(s,`css/${v}.css`);r.writeFileSync(d,F)}}await S(t,s);const l=e.map(i=>`@import url('./css/${i}');`).join(`
3
- `);let f=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
4
-
5
- ${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
6
- `)}
7
- ${l}`;if(j.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
8
- `);f+=i}r.writeFileSync(a,f)}catch(e){console.error(e)}},L=async(t,e)=>{try{const n=[],s=o.join(t,"./saltygen"),a=o.join(s,"index.css");if(O(e)){const j=await E(t),S=await T(e,s);Object.entries(S).forEach(([g,$])=>{if(!$.generator)return;const m=$.generator._withBuildContext({name:g,config:j}),u=`${m.hash}-${m.priority}.css`,h=`css/${u}`,F=o.join(s,h);n.push(u),r.writeFileSync(F,m.css)});const l=r.readFileSync(a,"utf8").split(`
9
- `),b=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...b])].join(`
10
- `);r.writeFileSync(a,i)}}catch(n){console.error(n)}},U=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(O(e)){const a=r.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await K.writeFile(e,a);const j=await E(t),S=await T(e,n);let l=a;Object.entries(S).forEach(([f,i])=>{var F;if(i.isKeyframes){console.log("value",i);return}if(!i.generator)return;const g=i.generator._withBuildContext({name:f,config:j}),$=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const m=(F=$.at(1))==null?void 0:F.trim(),u=`${f} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`,h=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");l=l.replace(h,u)});const b=P.toHash(e,6);return j.importStrategy==="component"&&(l=`import '../../saltygen/css/${b}.css';
11
- ${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error(n)}};exports.compileSaltyFile=T;exports.generateConfigStyles=M;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=O;exports.minimizeFile=U;exports.saltyFileExtensions=_;exports.saltyFileRegExp=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-3zK35muR.cjs");require("../parse-templates-VIvmVb52.cjs");const e=require("../index-neHUpjdt.cjs");require("../merge-DxGoJDHv.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
@@ -1,16 +1,40 @@
1
1
  import { StyleComponentGenerator } from '../generator/style-generator';
2
+ import { MediaQueryFactory } from '../css/media';
3
+ import { GlobalStylesFactory, TemplatesFactory, VariablesFactory } from '../factories';
4
+ interface GeneratorResult<V extends object> {
5
+ value: V;
6
+ src: string;
7
+ name: string;
8
+ }
9
+ interface GenerationResults {
10
+ components: GeneratorResult<StyleComponentGenerator>[];
11
+ keyframes: GeneratorResult<{
12
+ animationName: string;
13
+ css: string;
14
+ }>[];
15
+ mediaQueries: MediaQueryFactory[];
16
+ globalStyles: GlobalStylesFactory[];
17
+ variables: VariablesFactory[];
18
+ templates: TemplatesFactory[];
19
+ }
2
20
  export declare const saltyFileExtensions: string[];
3
21
  export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
4
22
  export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
5
- export declare const generateConfigStyles: (dirname: string) => Promise<void>;
6
- export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
23
+ export declare const generateConfigStyles: (dirname: string, generationResults: GenerationResults) => Promise<void>;
24
+ export declare const compileSaltyFile: (dirname: string, sourceFilePath: string, outputDirectory: string) => Promise<{
7
25
  [key: string]: {
8
26
  generator: StyleComponentGenerator;
27
+ isMedia?: boolean;
28
+ isGlobalDefine?: boolean;
29
+ isDefineVariables?: boolean;
30
+ isDefineTemplates?: boolean;
9
31
  isKeyframes?: boolean;
10
32
  animationName?: string;
11
33
  css?: string;
34
+ styles?: any;
12
35
  };
13
36
  }>;
14
- export declare const generateCss: (dirname: string) => Promise<void>;
37
+ export declare const generateCss: (dirname: string, prod?: boolean, clean?: boolean) => Promise<void>;
15
38
  export declare const generateFile: (dirname: string, file: string) => Promise<void>;
16
- export declare const minimizeFile: (dirname: string, file: string) => Promise<string | undefined>;
39
+ export declare const minimizeFile: (dirname: string, file: string, prod?: boolean) => Promise<string | undefined>;
40
+ export {};
package/compiler/index.js CHANGED
@@ -1,174 +1,20 @@
1
- import * as I from "esbuild";
2
- import { execSync as H } from "child_process";
3
- import { t as T, d as R } from "../dash-case-DMQMcCO6.js";
4
- import { join as o } from "path";
5
- import { writeFileSync as $, existsSync as K, mkdirSync as V, statSync as z, readdirSync as G, readFileSync as M } from "fs";
6
- import { writeFile as J } from "fs/promises";
7
- import { p as q, a as A, b as L } from "../parse-templates-D4p3pgQR.js";
8
- const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W = (s = []) => new RegExp(`\\.(${[...U, ...s].join("|")})\\.`), v = (s, e = []) => W(e).test(s), X = async (s) => {
9
- const e = N(s), n = o(s, "salty.config.ts"), t = o(e, "salty.config.js");
10
- await I.build({
11
- entryPoints: [n],
12
- minify: !0,
13
- treeShaking: !0,
14
- bundle: !0,
15
- outfile: t,
16
- format: "esm",
17
- external: ["react"]
18
- });
19
- const c = Date.now(), { config: S } = await import(`${t}?t=${c}`);
20
- return S;
21
- }, Y = async (s) => {
22
- const e = await X(s), n = /* @__PURE__ */ new Set(), t = (u, l = []) => u ? Object.entries(u).flatMap(([p, r]) => {
23
- if (!r) return;
24
- if (typeof r == "object") return t(r, [...l, p]);
25
- const x = [...l, p].join(".");
26
- n.add(`"${x}"`);
27
- const C = [...l.map(R), R(p)].join("-"), { result: D } = L(r);
28
- return `--${C}: ${D};`;
29
- }) : [], c = (u) => u ? Object.entries(u).flatMap(([l, p]) => {
30
- const r = t(p);
31
- return l === "base" ? r.join("") : `${l} { ${r.join("")} }`;
32
- }) : [], S = (u) => u ? Object.entries(u).flatMap(([l, p]) => Object.entries(p).flatMap(([r, x]) => {
33
- const C = t(x, [l]), D = `.${l}-${r}, [data-${l}="${r}"]`, P = C.join("");
34
- return `${D} { ${P} }`;
35
- })) : [], d = t(e.variables), w = c(e.responsiveVariables), a = S(e.conditionalVariables), b = N(s), f = o(b, "css/variables.css"), i = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
36
- $(f, i);
37
- const y = o(b, "types/css-tokens.d.ts"), m = `type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
38
- $(y, m);
39
- const g = o(b, "css/global.css"), F = q(e.global, "");
40
- $(g, F);
41
- const j = o(b, "css/templates.css"), k = A(e.templates);
42
- $(j, k);
43
- }, E = async (s, e) => {
44
- const n = T(s), t = o(e, "js", n + ".js");
45
- await I.build({
46
- entryPoints: [s],
47
- minify: !0,
48
- treeShaking: !0,
49
- bundle: !0,
50
- outfile: t,
51
- format: "esm",
52
- target: ["es2022"],
53
- keepNames: !0,
54
- external: ["react"]
55
- });
56
- const c = Date.now();
57
- return await import(`${t}?t=${c}`);
58
- }, O = async (s) => {
59
- const e = N(s), n = o(e, "salty.config.js"), { config: t } = await import(n);
60
- return t;
61
- }, ot = async (s) => {
62
- try {
63
- const e = [], n = [], t = N(s), c = o(t, "index.css");
64
- (() => {
65
- K(t) && H("rm -rf " + t), V(t), V(o(t, "css")), V(o(t, "types"));
66
- })(), await Y(s);
67
- const d = await O(s);
68
- async function w(i, y) {
69
- const h = z(i);
70
- if (h.isDirectory()) {
71
- const m = G(i);
72
- await Promise.all(m.map((g) => w(o(i, g), o(y, g))));
73
- } else if (h.isFile() && v(i)) {
74
- const g = await E(i, t), F = [];
75
- Object.entries(g).forEach(([l, p]) => {
76
- if (p.isKeyframes && p.css) {
77
- const P = `${p.animationName}.css`, _ = `css/${P}`, B = o(t, _);
78
- e.push(P), $(B, p.css);
79
- return;
80
- }
81
- if (!p.generator) return;
82
- const r = p.generator._withBuildContext({
83
- name: l,
84
- config: d
85
- }), x = `${r.hash}-${r.priority}.css`;
86
- n[r.priority] || (n[r.priority] = []), n[r.priority].push(x), F.push(x);
87
- const C = `css/${x}`, D = o(t, C);
88
- $(D, r.css);
89
- });
90
- const j = F.map((l) => `@import url('./${l}');`).join(`
91
- `), k = T(i, 6), u = o(t, `css/${k}.css`);
92
- $(u, j);
93
- }
94
- }
95
- await w(s, t);
96
- const a = e.map((i) => `@import url('./css/${i}');`).join(`
97
- `);
98
- let f = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
99
-
100
- ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
101
- `)}
102
- ${a}`;
103
- if (d.importStrategy !== "component") {
104
- const i = n.flat().map((y) => `@import url('./css/${y}');`).join(`
105
- `);
106
- f += i;
107
- }
108
- $(c, f);
109
- } catch (e) {
110
- console.error(e);
111
- }
112
- }, it = async (s, e) => {
113
- try {
114
- const n = [], t = o(s, "./saltygen"), c = o(t, "index.css");
115
- if (v(e)) {
116
- const d = await O(s), w = await E(e, t);
117
- Object.entries(w).forEach(([y, h]) => {
118
- if (!h.generator) return;
119
- const m = h.generator._withBuildContext({
120
- name: y,
121
- config: d
122
- }), g = `${m.hash}-${m.priority}.css`, F = `css/${g}`, j = o(t, F);
123
- n.push(g), $(j, m.css);
124
- });
125
- const a = M(c, "utf8").split(`
126
- `), b = n.map((y) => `@import url('../saltygen/css/${y}');`), i = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
127
- `);
128
- $(c, i);
129
- }
130
- } catch (n) {
131
- console.error(n);
132
- }
133
- }, rt = async (s, e) => {
134
- try {
135
- const n = o(s, "./saltygen");
136
- if (v(e)) {
137
- const c = M(e, "utf8");
138
- c.replace(/^(?!export\s)const\s.*/gm, (f) => `export ${f}`) !== c && await J(e, c);
139
- const d = await O(s), w = await E(e, n);
140
- let a = c;
141
- Object.entries(w).forEach(([f, i]) => {
142
- var j;
143
- if (i.isKeyframes) {
144
- console.log("value", i);
145
- return;
146
- }
147
- if (!i.generator) return;
148
- const y = i.generator._withBuildContext({
149
- name: f,
150
- config: d
151
- }), h = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
152
- if (!h)
153
- return console.error("Could not find the original declaration");
154
- const m = (j = h.at(1)) == null ? void 0 : j.trim(), g = `${f} = styled(${m}, "${y.classNames}", "${y._callerName}", ${JSON.stringify(y.props)});`, F = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
155
- a = a.replace(F, g);
156
- });
157
- const b = T(e, 6);
158
- return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
159
- ${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
160
- }
161
- } catch (n) {
162
- console.error(n);
163
- }
164
- };
1
+ import "esbuild";
2
+ import "child_process";
3
+ import "../dash-case-DBThphLm.js";
4
+ import "path";
5
+ import "fs";
6
+ import "fs/promises";
7
+ import "../parse-styles-DrLhKtqW.js";
8
+ import "../parse-templates-DRKlN-pP.js";
9
+ import { d as g, c as F, g as y, e as x, i as S, m as c, s as f, b as C } from "../index-9iO5zogY.js";
10
+ import "../merge-BVm9us1A.js";
165
11
  export {
166
- E as compileSaltyFile,
167
- Y as generateConfigStyles,
168
- ot as generateCss,
169
- it as generateFile,
170
- v as isSaltyFile,
171
- rt as minimizeFile,
172
- U as saltyFileExtensions,
173
- W as saltyFileRegExp
12
+ g as compileSaltyFile,
13
+ F as generateConfigStyles,
14
+ y as generateCss,
15
+ x as generateFile,
16
+ S as isSaltyFile,
17
+ c as minimizeFile,
18
+ f as saltyFileExtensions,
19
+ C as saltyFileRegExp
174
20
  };
@@ -1,2 +1,2 @@
1
- import { SaltyConfig } from './config-types';
1
+ import { SaltyConfig } from '../types/config-types';
2
2
  export declare const defineConfig: <T extends SaltyConfig>(config: T) => T;
package/config/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=e=>e;exports.defineConfig=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../factories/index.cjs"),i=a=>a;exports.GlobalStylesFactory=e.GlobalStylesFactory;exports.TemplatesFactory=e.TemplatesFactory;exports.VariablesFactory=e.VariablesFactory;exports.defineConditionalVariables=e.defineConditionalVariables;exports.defineGlobalStyles=e.defineGlobalStyles;exports.defineResponsiveVariables=e.defineResponsiveVariables;exports.defineStaticVariables=e.defineStaticVariables;exports.defineTemplates=e.defineTemplates;exports.defineVariables=e.defineVariables;exports.defineConfig=i;
package/config/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './config-types';
2
1
  export * from './define-config';
2
+ export * from '../factories';
3
+ export * from '../types/config-types';
package/config/index.js CHANGED
@@ -1,4 +1,14 @@
1
- const n = (e) => e;
1
+ import { GlobalStylesFactory as t, TemplatesFactory as n, VariablesFactory as o, defineConditionalVariables as r, defineGlobalStyles as s, defineResponsiveVariables as f, defineStaticVariables as d, defineTemplates as b, defineVariables as c } from "../factories/index.js";
2
+ const a = (e) => e;
2
3
  export {
3
- n as defineConfig
4
+ t as GlobalStylesFactory,
5
+ n as TemplatesFactory,
6
+ o as VariablesFactory,
7
+ r as defineConditionalVariables,
8
+ a as defineConfig,
9
+ s as defineGlobalStyles,
10
+ f as defineResponsiveVariables,
11
+ d as defineStaticVariables,
12
+ b as defineTemplates,
13
+ c as defineVariables
4
14
  };
package/css/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=e=>`{${e}}`;exports.token=t;
1
+ "use strict";var v=Object.defineProperty;var C=(n,e,t)=>e in n?v(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var g=(n,e,t)=>C(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../parse-styles-3zK35muR.cjs"),w=require("../dash-case-BJEkFEGQ.cjs"),j=require("../merge-DxGoJDHv.cjs"),k=({animationName:n,params:e,appendInitialStyles:t,...s})=>{const u=n||w.toHash(s),c=(o={})=>{const{duration:r="500ms",easing:a="ease-in-out",delay:h="0s",iterationCount:$="1",direction:x="normal",fillMode:f="forwards",playState:y="running"}={...e,...o},l=`${u} ${r} ${a} ${h} ${$} ${x} ${f} ${y}`;if(!t)return l;const m=s.from||s["0%"];if(!m)return l;const S=p.parseStyles(m,"");return`${l};${S}`},d=Object.entries(s).reduce((o,[r,a])=>{if(!a)return o;const h=p.parseStyles(a,""),$=typeof r=="number"?`${r}%`:r;return`${o}${$}{${h}}`},""),b=`@keyframes ${u} {${d}}`;return Object.assign(c,{toString:c,isKeyframes:!0,animationName:u,css:b,keyframes:s}),c};class i{constructor(e="@media"){g(this,"next",e=>{const t=new String(e);return Object.assign(t,{get isMedia(){return!0},get and(){return new i(`${e} and`)},get or(){return new i(`${e},`)}}),t});this.base=e}custom(e){return this.next(`${this.base} ${e}`)}minWidth(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (min-width: ${t})`;return this.next(s)}maxWidth(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (max-width: ${t})`;return this.next(s)}minHeight(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (min-height: ${t})`;return this.next(s)}maxHeight(e){const t=typeof e=="number"?`${e}px`:e,s=`${this.base} (max-height: ${t})`;return this.next(s)}get portrait(){const e=`${this.base} (orientation: portrait)`;return this.next(e)}get landscape(){const e=`${this.base} (orientation: landscape)`;return this.next(e)}prefersColorScheme(e){const t=`${this.base} (prefers-color-scheme: ${e})`;return this.next(t)}get dark(){return this.prefersColorScheme("dark")}get light(){return this.prefersColorScheme("light")}get print(){const e=`${this.base} print`;return this.next(e)}get screen(){const e=`${this.base} screen`;return this.next(e)}get speech(){const e=`${this.base} speech`;return this.next(e)}get all(){const e=`${this.base} all`;return this.next(e)}get not(){const e=`${this.base} not`;return this.next(e)}get reducedMotion(){const e=`${this.base} (prefers-reduced-motion: reduce)`;return this.next(e)}}const M=new i,O=n=>`{${n}}`;exports.mergeStyles=j.mergeStyles;exports.MediaQueryFactory=i;exports.keyframes=k;exports.media=M;exports.token=O;
package/css/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export declare const token: <T extends VariableTokens>(token: T) => string;
1
+ export * from './keyframes';
2
+ export * from './media';
3
+ export * from './token';
4
+ export * from './merge';