@salty-css/core 0.0.1-alpha.247 → 0.0.1-alpha.249
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 +8 -8
- package/bin/main.cjs +1 -1
- package/bin/main.js +2 -2
- package/compiler/index.cjs +1 -1
- package/compiler/index.js +1 -1
- package/{index-B8uXjJ2F.js → index-B_V_O1Qg.js} +161 -155
- package/index-CelIwoBr.cjs +42 -0
- package/package.json +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/{should-restart-WiLKWZdo.cjs → should-restart-DJb3U4c8.cjs} +1 -1
- package/{should-restart-BgsyWPgo.js → should-restart-eXCtNI8U.js} +1 -1
- package/types/config-types.d.ts +2 -2
- package/types/index.d.ts +2 -2
- package/index-vWQ_NojW.cjs +0 -38
package/README.md
CHANGED
@@ -64,6 +64,14 @@ To get help with problems, [Join Salty CSS Discord server](https://discord.gg/R6
|
|
64
64
|
- [defineViewportClamp](#viewport-clamp) - create CSS clamp functions that are based on user's viewport and can calculate relative values easily
|
65
65
|
- [color](#color-function) - transform any valid color code or variable to be darker, lighter etc. easily (uses [color library by Qix-](https://github.com/Qix-/color))
|
66
66
|
|
67
|
+
### Salty CSS CLI
|
68
|
+
|
69
|
+
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
70
|
+
|
71
|
+
- 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.
|
72
|
+
- 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.
|
73
|
+
- Build files → `npx salty-css build [directory/filename]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
|
74
|
+
|
67
75
|
## Styled function
|
68
76
|
|
69
77
|
Styled function is the main way to use Salty CSS within React. Styled function creates a React component that then can be used anywhere in your app. All styled functions must be created in `.css.ts` or `.css.tsx` files
|
@@ -375,14 +383,6 @@ import { color } from '@salty-css/core/helpers';
|
|
375
383
|
export const Wrapper = styled('span', { base: { backgroundColor: color('#000').alpha(0.5) } });
|
376
384
|
```
|
377
385
|
|
378
|
-
## Salty CSS CLI
|
379
|
-
|
380
|
-
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
381
|
-
|
382
|
-
- 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.
|
383
|
-
- 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.
|
384
|
-
- 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
|
385
|
-
|
386
386
|
## Usage
|
387
387
|
|
388
388
|
### Next.js
|
package/bin/main.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),A=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),e=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),A=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),e=require("../index-CelIwoBr.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora"),ae=require("../should-restart-DJb3U4c8.cjs");var G=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,x=>{if(x)return P(x);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),x=y.join(" ");await X(`npm install ${x}`),P.succeed(`Installed packages: ${C}`)},re=()=>A.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!re())return;await X(`./node_modules/.bin/prettier --write "${y}"`),e.logger.info(`Formatted ${y} with Prettier`)}catch(C){e.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function ce(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:f}=await C[i],d=ne.render(f,a);return{fileName:i,content:d}},x=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await x()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},H=i=>{const a=i==="."?"":i,f=process.cwd();return n.join(f,a)};y.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(i="."){if(!await N().catch(()=>{}))return e.logError("Salty CSS project must be initialized in a directory with a package.json file.");e.logger.info("Initializing a new Salty-CSS project!");const{dir:f=i,cssFile:d,skipInstall:p}=this.opts();if(!f)return e.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const c=process.cwd(),r=H(f),q=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=q.map(async({fileName:t,content:u})=>{const l=n.join(r,t);if(await s.readFile(l,"utf-8").catch(()=>{})!==void 0){e.logger.debug("File already exists: "+l);return}const k=t.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),e.logger.info("Creating file: "+l),await s.writeFile(l,u),await S(l)});await Promise.all(m);const w=n.relative(c,r)||".",h=n.join(c,".saltyrc.json"),g=await s.readFile(h,"utf-8").catch(()=>{});if(g===void 0){e.logger.info("Creating file: "+h);const u=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",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.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,u),await S(h)}else{const t=JSON.parse(g),u=(t==null?void 0:t.projects)||[];if(u.findIndex(o=>o.dir===w)===-1){u.push({dir:w,framework:"react"}),t.projects=[...u];const o=JSON.stringify(t,null,2);o!==g&&(e.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(c,".gitignore"),T=await s.readFile(j,"utf-8").catch(()=>{});T!==void 0&&(T.includes("saltygen")||(e.logger.info("Edit file: "+j),await s.writeFile(j,T+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
package/bin/main.js
CHANGED
@@ -3,11 +3,11 @@ import { existsSync as Q, watch as re } from "fs";
|
|
3
3
|
import { mkdir as q, readFile as S, writeFile as C } from "fs/promises";
|
4
4
|
import { join as a, relative as z, parse as ce, format as te } from "path";
|
5
5
|
import { render as le } from "ejs";
|
6
|
-
import { l as t, a as h, g as K, i as de, b as fe } from "../index-
|
6
|
+
import { l as t, a as h, g as K, i as de, b as fe } from "../index-B_V_O1Qg.js";
|
7
7
|
import { p as pe } from "../pascal-case-BQpR5PdN.js";
|
8
8
|
import { exec as ue } from "child_process";
|
9
9
|
import ge from "ora";
|
10
|
-
import { c as ye } from "../should-restart-
|
10
|
+
import { c as ye } from "../should-restart-eXCtNI8U.js";
|
11
11
|
const ne = (g) => new Promise((P, x) => {
|
12
12
|
ue(g, ($) => {
|
13
13
|
if ($) return x($);
|
package/compiler/index.cjs
CHANGED
@@ -1 +1 @@
|
|
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-CXclnoUS.cjs");const e=require("../index-
|
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-CXclnoUS.cjs");const e=require("../index-CelIwoBr.cjs");require("../css/merge.cjs");require("../define-templates-Cunsb_Tr.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;
|
package/compiler/index.js
CHANGED
@@ -5,7 +5,7 @@ import "path";
|
|
5
5
|
import "fs";
|
6
6
|
import "fs/promises";
|
7
7
|
import "../parse-styles-DZ-LjC9e.js";
|
8
|
-
import { e as g, d as F, g as y, b as x, i as S, m as c, s as f, c as C } from "../index-
|
8
|
+
import { e as g, d as F, g as y, b as x, i as S, m as c, s as f, c as C } from "../index-B_V_O1Qg.js";
|
9
9
|
import "../css/merge.js";
|
10
10
|
import "../define-templates-4A2yHcMF.js";
|
11
11
|
export {
|
@@ -1,61 +1,61 @@
|
|
1
|
-
import * as
|
2
|
-
import { execSync as
|
3
|
-
import { d as K, t as
|
1
|
+
import * as St from "esbuild";
|
2
|
+
import { execSync as vt } from "child_process";
|
3
|
+
import { d as K, t as J } from "./dash-case-DBThphLm.js";
|
4
4
|
import { join as r, parse as tt } from "path";
|
5
|
-
import { existsSync as
|
6
|
-
import { readFile as
|
7
|
-
import { p as
|
8
|
-
import { createLogger as
|
9
|
-
import { mergeObjects as I, mergeFactories as
|
10
|
-
import { d as
|
11
|
-
import
|
12
|
-
const
|
5
|
+
import { existsSync as ut, writeFileSync as j, mkdirSync as H, readFileSync as _, statSync as Et, readdirSync as Ot } from "fs";
|
6
|
+
import { readFile as Ct } from "fs/promises";
|
7
|
+
import { p as ft, a as Mt } from "./parse-styles-DZ-LjC9e.js";
|
8
|
+
import { createLogger as Rt, format as rt, transports as Jt } from "winston";
|
9
|
+
import { mergeObjects as I, mergeFactories as zt } from "./css/merge.js";
|
10
|
+
import { d as Wt } from "./define-templates-4A2yHcMF.js";
|
11
|
+
import lt from "typescript";
|
12
|
+
const jt = async (t, e = []) => {
|
13
13
|
if (!t) return "";
|
14
14
|
const s = [], n = {};
|
15
15
|
for (const [o, i] of Object.entries(t))
|
16
16
|
if (typeof i != "function") if (i && typeof i == "object") {
|
17
|
-
const a = o.trim(), m = await
|
17
|
+
const a = o.trim(), m = await jt(i, [...e, a]);
|
18
18
|
s.push(m);
|
19
19
|
} else
|
20
20
|
n[o] = i;
|
21
21
|
if (Object.keys(n).length) {
|
22
|
-
const o = e.map(K).join("-"), i = "t_" +
|
22
|
+
const o = e.map(K).join("-"), i = "t_" + J(o, 4), a = await ft(n, `.${o}, .${i}`);
|
23
23
|
s.push(a);
|
24
24
|
}
|
25
25
|
return s.join(`
|
26
26
|
`);
|
27
|
-
},
|
27
|
+
}, Gt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = Ft(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, Ft = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
28
28
|
const i = e ? `${e}.${n}` : n;
|
29
|
-
return typeof o == "object" ?
|
30
|
-
}), [...s]) : [],
|
29
|
+
return typeof o == "object" ? Ft(o, i, s) : s.add(e);
|
30
|
+
}), [...s]) : [], Pt = (t) => {
|
31
31
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
32
32
|
const e = r(t, "package.json");
|
33
|
-
return
|
34
|
-
}, Gt = async (t) => {
|
35
|
-
const e = Ft(t);
|
36
|
-
return await St(e, "utf-8").then(JSON.parse).catch(() => {
|
37
|
-
});
|
33
|
+
return ut(e) ? e : Pt(r(t, ".."));
|
38
34
|
}, Ht = async (t) => {
|
39
|
-
const e =
|
35
|
+
const e = Pt(t);
|
36
|
+
return await Ct(e, "utf-8").then(JSON.parse).catch(() => {
|
37
|
+
});
|
38
|
+
}, It = async (t) => {
|
39
|
+
const e = await Ht(t);
|
40
40
|
if (e)
|
41
41
|
return e.type;
|
42
42
|
};
|
43
43
|
let G;
|
44
|
-
const
|
44
|
+
const Nt = async (t) => {
|
45
45
|
if (G) return G;
|
46
|
-
const e = await
|
46
|
+
const e = await It(t);
|
47
47
|
return e === "module" ? G = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (G = "cjs"), G || "esm";
|
48
|
-
}, Z =
|
48
|
+
}, Z = Rt({
|
49
49
|
level: "debug",
|
50
|
-
format:
|
51
|
-
transports: [new
|
50
|
+
format: rt.combine(rt.colorize(), rt.cli()),
|
51
|
+
transports: [new Jt.Console({})]
|
52
52
|
}), ce = (t) => {
|
53
53
|
Z.error(t);
|
54
54
|
};
|
55
|
-
function
|
56
|
-
return t ? typeof t != "string" ?
|
55
|
+
function xt(t) {
|
56
|
+
return t ? typeof t != "string" ? xt(String(t)) : t.replace(/[^\d\w]/g, ".") : "";
|
57
57
|
}
|
58
|
-
const
|
58
|
+
const Kt = {
|
59
59
|
/** Set box model to border-box */
|
60
60
|
"*, *::before, *::after": {
|
61
61
|
boxSizing: "border-box"
|
@@ -101,45 +101,45 @@ const It = {
|
|
101
101
|
fontSize: "100%",
|
102
102
|
lineHeight: "1.15em"
|
103
103
|
}
|
104
|
-
},
|
104
|
+
}, Qt = (t, e) => new Promise((s, n) => {
|
105
105
|
const o = setTimeout(() => {
|
106
106
|
n(new Error("Timeout"));
|
107
|
-
}, 100), i =
|
107
|
+
}, 100), i = lt.createSourceFile("temp.ts", t, lt.ScriptTarget.Latest, !0);
|
108
108
|
function a(m) {
|
109
|
-
if (
|
109
|
+
if (lt.isVariableDeclaration(m) && m.name.getText() === e) {
|
110
110
|
const w = m.getStart(), p = m.getEnd();
|
111
111
|
clearTimeout(o), s([w, p]);
|
112
112
|
}
|
113
113
|
m.forEachChild(a);
|
114
114
|
}
|
115
115
|
a(i);
|
116
|
-
}),
|
116
|
+
}), v = {
|
117
117
|
externalModules: [],
|
118
118
|
rcFile: void 0,
|
119
119
|
destDir: void 0
|
120
|
-
},
|
121
|
-
if (
|
120
|
+
}, Dt = (t) => {
|
121
|
+
if (v.externalModules.length > 0) return v.externalModules;
|
122
122
|
const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
123
123
|
if (!s) return [];
|
124
124
|
const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
|
125
|
-
return
|
126
|
-
},
|
127
|
-
if (
|
128
|
-
const e = await
|
129
|
-
return
|
130
|
-
},
|
131
|
-
if (
|
125
|
+
return v.externalModules = n, n;
|
126
|
+
}, z = async (t) => {
|
127
|
+
if (v.destDir) return v.destDir;
|
128
|
+
const e = await pt(t), s = r(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
129
|
+
return v.destDir = s, s;
|
130
|
+
}, kt = ["salty", "css", "styles", "styled"], Bt = (t = []) => new RegExp(`\\.(${[...kt, ...t].join("|")})\\.`), mt = (t, e = []) => Bt(e).test(t), Tt = async (t) => {
|
131
|
+
if (v.rcFile) return v.rcFile;
|
132
132
|
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
133
|
-
const e = r(t, ".saltyrc.json"), s = await
|
133
|
+
const e = r(t, ".saltyrc.json"), s = await Ct(e, "utf-8").then(JSON.parse).catch(() => {
|
134
134
|
});
|
135
|
-
return s ? (
|
136
|
-
},
|
135
|
+
return s ? (v.rcFile = s, s) : Tt(r(t, ".."));
|
136
|
+
}, pt = async (t) => {
|
137
137
|
var n, o;
|
138
|
-
const e = await
|
138
|
+
const e = await Tt(t), s = (n = e.projects) == null ? void 0 : n.find((i) => t.endsWith(i.dir || ""));
|
139
139
|
return s || ((o = e.projects) == null ? void 0 : o.find((i) => i.dir === e.defaultProject));
|
140
|
-
},
|
141
|
-
const e = await
|
142
|
-
await
|
140
|
+
}, Lt = async (t) => {
|
141
|
+
const e = await pt(t), s = await z(t), n = r(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = r(s, "salty.config.js"), i = await Nt(t), a = Dt(n);
|
142
|
+
await St.build({
|
143
143
|
entryPoints: [n],
|
144
144
|
minify: !0,
|
145
145
|
treeShaking: !0,
|
@@ -150,9 +150,9 @@ const It = {
|
|
150
150
|
});
|
151
151
|
const m = Date.now(), { config: w } = await import(`${o}?t=${m}`);
|
152
152
|
return { config: w, path: o };
|
153
|
-
},
|
154
|
-
var
|
155
|
-
const s = await
|
153
|
+
}, qt = async (t, e) => {
|
154
|
+
var ht, wt;
|
155
|
+
const s = await z(t), n = {
|
156
156
|
mediaQueries: [],
|
157
157
|
globalStyles: [],
|
158
158
|
variables: [],
|
@@ -161,84 +161,84 @@ const It = {
|
|
161
161
|
await Promise.all(
|
162
162
|
[...e].map(async (h) => {
|
163
163
|
const { contents: S, outputFilePath: q } = await et(t, h, s);
|
164
|
-
Object.entries(S).forEach(([k,
|
165
|
-
|
164
|
+
Object.entries(S).forEach(([k, P]) => {
|
165
|
+
P.isMedia ? n.mediaQueries.push([k, P]) : P.isGlobalDefine ? n.globalStyles.push(P) : P.isDefineVariables ? n.variables.push(P) : P.isDefineTemplates && n.templates.push(P._setPath(`${k};;${q}`));
|
166
166
|
});
|
167
167
|
})
|
168
168
|
);
|
169
|
-
const { config: o, path: i } = await
|
169
|
+
const { config: o, path: i } = await Lt(t), a = { ...o }, { mediaQueries: m } = n;
|
170
170
|
a.mediaQueries = Object.fromEntries(m.map(([h, S]) => [`@${h}`, S]));
|
171
171
|
const w = m.map(([h]) => `'@${h}'`).join(" | "), p = /* @__PURE__ */ new Set(), c = async (h, S = []) => {
|
172
172
|
if (!h) return [];
|
173
|
-
const q = Object.entries(h).map(async ([
|
173
|
+
const q = Object.entries(h).map(async ([P, R]) => {
|
174
174
|
const A = async (T) => {
|
175
175
|
if (!T) return;
|
176
176
|
if (T instanceof Promise) return await A(await T);
|
177
177
|
if (typeof T == "function") return await A(await T());
|
178
|
-
if (typeof T == "object") return await c(T, [...S,
|
179
|
-
const
|
180
|
-
p.add(`"${
|
181
|
-
const Y = [...S.map(K),
|
182
|
-
return
|
178
|
+
if (typeof T == "object") return await c(T, [...S, P]);
|
179
|
+
const at = xt(P), it = K(P), ct = [...S, at].join(".");
|
180
|
+
p.add(`"${ct}"`);
|
181
|
+
const Y = [...S.map(K), it].join("-"), $t = Mt(T);
|
182
|
+
return $t ? `--${Y}: ${$t.transformed};` : `--${Y}: ${T};`;
|
183
183
|
};
|
184
|
-
return await A(
|
184
|
+
return await A(R);
|
185
185
|
});
|
186
186
|
return (await Promise.all(q)).flat();
|
187
187
|
}, y = async (h) => {
|
188
188
|
if (!h) return [];
|
189
|
-
const S = Object.entries(h).map(async ([k,
|
190
|
-
const
|
191
|
-
return k === "base" ?
|
189
|
+
const S = Object.entries(h).map(async ([k, P]) => {
|
190
|
+
const R = await c(P);
|
191
|
+
return k === "base" ? R.join("") : a.mediaQueries[k] ? `${a.mediaQueries[k]} { ${R.join("")} }` : `${k} { ${R.join("")} }`;
|
192
192
|
});
|
193
193
|
return (await Promise.all(S)).flat();
|
194
194
|
}, d = async (h) => {
|
195
195
|
if (!h) return [];
|
196
|
-
const S = Object.entries(h).map(async ([k,
|
197
|
-
const
|
198
|
-
const
|
199
|
-
return `${
|
196
|
+
const S = Object.entries(h).map(async ([k, P]) => {
|
197
|
+
const R = Object.entries(P).map(async ([T, at]) => {
|
198
|
+
const it = await c(at, [k]), ct = `.${k}-${T}, [data-${k}="${T}"]`, Y = it.join("");
|
199
|
+
return `${ct} { ${Y} }`;
|
200
200
|
});
|
201
|
-
return (await Promise.all(
|
201
|
+
return (await Promise.all(R)).flat();
|
202
202
|
});
|
203
203
|
return (await Promise.all(S)).flat();
|
204
|
-
}, g = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), u = (h) => n.variables.map((S) => h === "static" ? g(S._current) : S._current[h]), C = I(g(o.variables), u("static")), x = await c(C), D = I((
|
205
|
-
j(
|
206
|
-
const
|
207
|
-
j(
|
208
|
-
const
|
209
|
-
j(
|
210
|
-
const
|
211
|
-
j(
|
212
|
-
const
|
213
|
-
a.templatePaths = Object.fromEntries(Object.entries(
|
214
|
-
const
|
204
|
+
}, g = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), u = (h) => n.variables.map((S) => h === "static" ? g(S._current) : S._current[h]), C = I(g(o.variables), u("static")), x = await c(C), D = I((ht = o.variables) == null ? void 0 : ht.responsive, u("responsive")), E = await y(D), W = I((wt = o.variables) == null ? void 0 : wt.conditional, u("conditional")), U = await d(W), gt = r(s, "css/_variables.css"), O = `:root { ${x.join("")} ${E.join("")} } ${U.join("")}`;
|
205
|
+
j(gt, O), a.staticVariables = C;
|
206
|
+
const st = r(s, "css/_global.css"), f = I(o.global, n.globalStyles), $ = await ft(f, "");
|
207
|
+
j(st, `@layer global { ${$} }`);
|
208
|
+
const b = r(s, "css/_reset.css"), F = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, N = await ft(F, "");
|
209
|
+
j(b, `@layer reset { ${N} }`);
|
210
|
+
const V = r(s, "css/_templates.css"), M = I(o.templates, n.templates), Q = await jt(M), B = Gt(M);
|
211
|
+
j(V, `@layer templates { ${Q} }`), a.templates = M;
|
212
|
+
const X = o.templates ? [Wt(o.templates)._setPath(`config;;${i}`)] : [], nt = zt(n.templates, X);
|
213
|
+
a.templatePaths = Object.fromEntries(Object.entries(nt).map(([h, S]) => [h, S._path]));
|
214
|
+
const L = r(s, "types/css-tokens.d.ts"), _t = `
|
215
215
|
// Variable types
|
216
216
|
type VariableTokens = ${[...p].join("|")};
|
217
217
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
218
218
|
|
219
219
|
// Template types
|
220
220
|
type TemplateTokens = {
|
221
|
-
${Object.entries(
|
221
|
+
${Object.entries(B).map(([h, S]) => `${h}?: ${S}`).join(`
|
222
222
|
`)}
|
223
223
|
}
|
224
224
|
|
225
225
|
// Media query types
|
226
226
|
type MediaQueryKeys = ${w || "''"};
|
227
227
|
`;
|
228
|
-
j(
|
229
|
-
const
|
230
|
-
j(
|
231
|
-
},
|
228
|
+
j(L, _t);
|
229
|
+
const Vt = r(s, "cache/config-cache.json");
|
230
|
+
j(Vt, JSON.stringify(a, null, 2));
|
231
|
+
}, bt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
232
232
|
if (/^['"`]/.test(s)) return e;
|
233
233
|
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
234
234
|
if (!o.test(t)) return e;
|
235
235
|
const a = o.exec(t);
|
236
236
|
if (a) {
|
237
237
|
const m = a.at(1);
|
238
|
-
if (
|
238
|
+
if (kt.some((p) => m == null ? void 0 : m.includes(p))) return e;
|
239
239
|
}
|
240
240
|
return "styled('div',";
|
241
|
-
}),
|
241
|
+
}), At = (t, e) => {
|
242
242
|
try {
|
243
243
|
const s = _(r(e, "saltygen/cache/config-cache.json"), "utf8");
|
244
244
|
return s ? `globalThis.saltyConfig = ${s};
|
@@ -250,13 +250,13 @@ ${t}`;
|
|
250
250
|
return t;
|
251
251
|
}
|
252
252
|
}, et = async (t, e, s) => {
|
253
|
-
const n =
|
254
|
-
|
253
|
+
const n = J(e), o = r(s, "./temp");
|
254
|
+
ut(o) || H(o);
|
255
255
|
const i = tt(e);
|
256
256
|
let a = _(e, "utf8");
|
257
|
-
a =
|
258
|
-
const m = r(s, "js", n + ".js"), w = await
|
259
|
-
await
|
257
|
+
a = bt(a), a = At(a, t);
|
258
|
+
const m = r(s, "js", n + ".js"), w = await pt(t), p = r(t, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), c = Dt(p), y = await Nt(t);
|
259
|
+
await St.build({
|
260
260
|
stdin: {
|
261
261
|
contents: a,
|
262
262
|
sourcefile: i.base,
|
@@ -278,7 +278,7 @@ ${t}`;
|
|
278
278
|
setup: (u) => {
|
279
279
|
u.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (C) => {
|
280
280
|
const x = _(C.path, "utf8");
|
281
|
-
return { contents:
|
281
|
+
return { contents: bt(x), loader: "ts" };
|
282
282
|
});
|
283
283
|
}
|
284
284
|
}
|
@@ -286,41 +286,41 @@ ${t}`;
|
|
286
286
|
});
|
287
287
|
const d = Date.now();
|
288
288
|
return { contents: await import(`${m}?t=${d}`), outputFilePath: m };
|
289
|
-
},
|
290
|
-
const e = await
|
289
|
+
}, Ut = async (t) => {
|
290
|
+
const e = await z(t), s = r(e, "cache/config-cache.json"), n = _(s, "utf8");
|
291
291
|
if (!n) throw new Error("Could not find config cache file");
|
292
292
|
return JSON.parse(n);
|
293
|
-
},
|
294
|
-
const e = await
|
293
|
+
}, dt = async (t) => {
|
294
|
+
const e = await Ut(t), s = await z(t), n = r(s, "salty.config.js"), o = Date.now(), { config: i } = await import(`${n}?t=${o}`);
|
295
295
|
return I(i, e);
|
296
|
-
},
|
296
|
+
}, yt = () => {
|
297
297
|
try {
|
298
298
|
return process.env.NODE_ENV === "production";
|
299
299
|
} catch {
|
300
300
|
return !1;
|
301
301
|
}
|
302
|
-
}, re = async (t, e =
|
302
|
+
}, re = async (t, e = yt(), s = !0) => {
|
303
303
|
try {
|
304
304
|
const n = Date.now();
|
305
305
|
e ? Z.info("Generating CSS in production mode! 🔥") : Z.info("Generating CSS in development mode! 🚀");
|
306
|
-
const o = [], i = [], a = await
|
306
|
+
const o = [], i = [], a = await z(t), m = r(a, "index.css");
|
307
307
|
s && (() => {
|
308
|
-
|
308
|
+
ut(a) && vt("rm -rf " + a), H(a, { recursive: !0 }), H(r(a, "css")), H(r(a, "types")), H(r(a, "js")), H(r(a, "cache"));
|
309
309
|
})();
|
310
310
|
const p = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
|
311
311
|
async function y(f) {
|
312
312
|
const $ = ["node_modules", "saltygen"], b = Et(f);
|
313
313
|
if (b.isDirectory()) {
|
314
|
-
const l =
|
314
|
+
const l = Ot(f);
|
315
315
|
if ($.some((N) => f.includes(N))) return;
|
316
316
|
await Promise.all(l.map((N) => y(r(f, N))));
|
317
|
-
} else if (b.isFile() &&
|
317
|
+
} else if (b.isFile() && mt(f)) {
|
318
318
|
p.add(f);
|
319
|
-
const
|
320
|
-
/define[\w\d]+\(/.test(
|
319
|
+
const F = _(f, "utf8");
|
320
|
+
/define[\w\d]+\(/.test(F) && c.add(f);
|
321
321
|
}
|
322
322
|
}
|
323
|
-
await y(t), await
|
323
|
+
await y(t), await qt(t, c);
|
324
324
|
const d = {
|
325
325
|
keyframes: [],
|
326
326
|
components: [],
|
@@ -345,10 +345,10 @@ ${t}`;
|
|
345
345
|
});
|
346
346
|
})
|
347
347
|
);
|
348
|
-
const g = await
|
348
|
+
const g = await dt(t);
|
349
349
|
for (const f of d.keyframes) {
|
350
|
-
const { value: $ } = f, b = `a_${$.animationName}.css`, l = `css/${b}`,
|
351
|
-
o.push(b), j(
|
350
|
+
const { value: $ } = f, b = `a_${$.animationName}.css`, l = `css/${b}`, F = r(a, l);
|
351
|
+
o.push(b), j(F, $.css);
|
352
352
|
}
|
353
353
|
const u = {};
|
354
354
|
for (const f of d.components) {
|
@@ -360,11 +360,11 @@ ${t}`;
|
|
360
360
|
config: g
|
361
361
|
});
|
362
362
|
i[l.priority] || (i[l.priority] = []);
|
363
|
-
const
|
364
|
-
if (!
|
363
|
+
const F = await l.css;
|
364
|
+
if (!F) continue;
|
365
365
|
i[l.priority].push(l.cssFileName);
|
366
366
|
const N = `css/${l.cssFileName}`, V = r(a, N);
|
367
|
-
j(V,
|
367
|
+
j(V, F), g.importStrategy === "component" && u[$].push(l.cssFileName);
|
368
368
|
}
|
369
369
|
for (const f of d.classNames) {
|
370
370
|
const { src: $, name: b } = f;
|
@@ -373,20 +373,24 @@ ${t}`;
|
|
373
373
|
callerName: b,
|
374
374
|
isProduction: e,
|
375
375
|
config: g
|
376
|
-
}),
|
377
|
-
if (!
|
376
|
+
}), F = await l.css;
|
377
|
+
if (!F) continue;
|
378
378
|
i[l.priority] || (i[l.priority] = []), i[l.priority].push(l.cssFileName);
|
379
379
|
const N = `css/${l.cssFileName}`, V = r(a, N);
|
380
|
-
j(V,
|
380
|
+
j(V, F), g.importStrategy === "component" && u[$].push(l.cssFileName);
|
381
381
|
}
|
382
382
|
g.importStrategy === "component" && Object.entries(u).forEach(([f, $]) => {
|
383
|
-
const b = $.map((
|
384
|
-
`), l =
|
383
|
+
const b = $.map((M) => `@import url('./${M}');`).join(`
|
384
|
+
`), l = J(f, 6), F = tt(f), N = K(F.name), V = r(a, `css/f_${N}-${l}.css`);
|
385
385
|
j(V, b || "/* Empty file */");
|
386
386
|
});
|
387
387
|
const C = o.map((f) => `@import url('./css/${f}');`).join(`
|
388
388
|
`);
|
389
|
-
let
|
389
|
+
let U = `/*!
|
390
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
391
|
+
* Do not edit this file directly
|
392
|
+
*/
|
393
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
390
394
|
|
391
395
|
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) => {
|
392
396
|
try {
|
@@ -394,37 +398,39 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((f) =
|
|
394
398
|
} catch {
|
395
399
|
return !1;
|
396
400
|
}
|
397
|
-
}).map((f) => `@import url('./css/${f}');`).join(
|
398
|
-
`
|
401
|
+
}).map((f) => `@import url('./css/${f}');`).join(
|
402
|
+
`
|
403
|
+
`
|
404
|
+
)}
|
399
405
|
${C}`;
|
400
406
|
if (g.importStrategy !== "component") {
|
401
407
|
const f = i.reduce(($, b, l) => {
|
402
|
-
const
|
403
|
-
var
|
404
|
-
const
|
405
|
-
return
|
408
|
+
const F = b.reduce((Q, B) => {
|
409
|
+
var ot;
|
410
|
+
const X = r(a, "css", B), nt = _(X, "utf8"), L = ((ot = /.*-([^-]+)-\d+.css/.exec(B)) == null ? void 0 : ot.at(1)) || J(X, 6);
|
411
|
+
return Q.includes(L) ? Q : `${Q}
|
406
412
|
/*start:${L}-${B}*/
|
407
413
|
${nt}
|
408
414
|
/*end:${L}*/
|
409
415
|
`;
|
410
|
-
}, ""), N = `l_${l}.css`, V = r(a, "css", N),
|
416
|
+
}, ""), N = `l_${l}.css`, V = r(a, "css", N), M = `@layer l${l} { ${F}
|
411
417
|
}`;
|
412
|
-
return j(V,
|
418
|
+
return j(V, M), `${$}
|
413
419
|
@import url('./css/${N}');`;
|
414
420
|
}, "");
|
415
|
-
|
421
|
+
U += f;
|
416
422
|
}
|
417
|
-
j(m,
|
418
|
-
const
|
419
|
-
Z.info(`Generated CSS in ${
|
423
|
+
j(m, U);
|
424
|
+
const O = Date.now() - n, st = O < 200 ? "🔥" : O < 500 ? "🚀" : O < 1e3 ? "🎉" : O < 2e3 ? "🚗" : O < 5e3 ? "🤔" : "🥴";
|
425
|
+
Z.info(`Generated CSS in ${O}ms! ${st}`);
|
420
426
|
} catch (n) {
|
421
427
|
console.error(n);
|
422
428
|
}
|
423
|
-
}, le = async (t, e, s =
|
429
|
+
}, le = async (t, e, s = yt()) => {
|
424
430
|
try {
|
425
|
-
const n = await
|
426
|
-
if (
|
427
|
-
const i = [], a = await
|
431
|
+
const n = await z(t);
|
432
|
+
if (mt(e)) {
|
433
|
+
const i = [], a = await dt(t), { contents: m } = await et(t, e, n);
|
428
434
|
for (const [w, p] of Object.entries(m)) {
|
429
435
|
if (p.isKeyframes && p.css) {
|
430
436
|
const C = `css/${`a_${p.animationName}.css`}`, x = r(n, C);
|
@@ -459,33 +465,33 @@ ${nt}
|
|
459
465
|
let d = _(y, "utf8");
|
460
466
|
w.forEach((g) => {
|
461
467
|
var D;
|
462
|
-
const u = r(n, "css", g), C = ((D = /.*-([^-]+)-\d+.css/.exec(g)) == null ? void 0 : D.at(1)) ||
|
468
|
+
const u = r(n, "css", g), C = ((D = /.*-([^-]+)-\d+.css/.exec(g)) == null ? void 0 : D.at(1)) || J(u, 6);
|
463
469
|
if (!d.includes(C)) {
|
464
|
-
const
|
465
|
-
${
|
470
|
+
const E = _(u, "utf8"), W = `/*start:${C}-${g}*/
|
471
|
+
${E}
|
466
472
|
/*end:${C}*/
|
467
473
|
`;
|
468
474
|
d = `${d.replace(/\}$/, "")}
|
469
|
-
${
|
475
|
+
${W}
|
470
476
|
}`;
|
471
477
|
}
|
472
478
|
}), j(y, d);
|
473
479
|
});
|
474
480
|
else {
|
475
481
|
const w = i.flat().map((g) => `@import url('./${g}');`).join(`
|
476
|
-
`), p =
|
482
|
+
`), p = J(e, 6), c = tt(e), y = K(c.name), d = r(n, `css/f_${y}-${p}.css`);
|
477
483
|
j(d, w || "/* Empty file */");
|
478
484
|
}
|
479
485
|
}
|
480
486
|
} catch (n) {
|
481
487
|
console.error(n);
|
482
488
|
}
|
483
|
-
}, fe = async (t, e, s =
|
489
|
+
}, fe = async (t, e, s = yt()) => {
|
484
490
|
var n, o;
|
485
491
|
try {
|
486
|
-
const i = await
|
487
|
-
if (
|
488
|
-
const m = _(e, "utf8"), w = await
|
492
|
+
const i = await z(t);
|
493
|
+
if (mt(e)) {
|
494
|
+
const m = _(e, "utf8"), w = await dt(t), { contents: p } = await et(t, e, i);
|
489
495
|
let c = m;
|
490
496
|
for (const [y, d] of Object.entries(p)) {
|
491
497
|
if (d.isKeyframes || !d.generator) continue;
|
@@ -493,18 +499,18 @@ ${O}
|
|
493
499
|
callerName: y,
|
494
500
|
isProduction: s,
|
495
501
|
config: w
|
496
|
-
}), [u, C] = await
|
502
|
+
}), [u, C] = await Qt(c, y), x = c.slice(u, C);
|
497
503
|
if (d.isClassName) {
|
498
|
-
const D = c,
|
499
|
-
c = c.replace(x,
|
504
|
+
const D = c, E = ` ${y} = className("${g.classNames}")`;
|
505
|
+
c = c.replace(x, E), D === c && console.error("Minimize file failed to change content", { name: y });
|
500
506
|
}
|
501
507
|
if (x.includes("styled")) {
|
502
|
-
const D = (o = (n = /styled\(([^,]+),/.exec(x)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(),
|
503
|
-
c = c.replace(x,
|
508
|
+
const D = (o = (n = /styled\(([^,]+),/.exec(x)) == null ? void 0 : n.at(1)) == null ? void 0 : o.trim(), E = c, W = ` ${y} = styled(${D}, "${g.classNames}", ${JSON.stringify(g.clientProps)})`;
|
509
|
+
c = c.replace(x, W), E === c && console.error("Minimize file failed to change content", { name: y, tagName: D });
|
504
510
|
}
|
505
511
|
}
|
506
512
|
if (w.importStrategy === "component") {
|
507
|
-
const y =
|
513
|
+
const y = J(e, 6), d = tt(e);
|
508
514
|
c = `import '../../saltygen/css/${`f_${K(d.name)}-${y}.css`}';
|
509
515
|
${c}`;
|
510
516
|
}
|
@@ -517,12 +523,12 @@ ${c}`;
|
|
517
523
|
export {
|
518
524
|
ce as a,
|
519
525
|
le as b,
|
520
|
-
|
521
|
-
|
526
|
+
Bt as c,
|
527
|
+
qt as d,
|
522
528
|
et as e,
|
523
529
|
re as g,
|
524
|
-
|
530
|
+
mt as i,
|
525
531
|
Z as l,
|
526
532
|
fe as m,
|
527
|
-
|
533
|
+
kt as s
|
528
534
|
};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";const Te=require("esbuild"),Oe=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),c=require("path"),l=require("fs"),we=require("fs/promises"),Z=require("./parse-styles-CXclnoUS.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),ce=require("typescript");var re=typeof document<"u"?document.currentScript:null;function Ve(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 Se=Ve(Te),je=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,a]of Object.entries(e))if(typeof a!="function")if(a&&typeof a=="object"){const i=o.trim(),d=await je(a,[...t,i]);s.push(d)}else n[o]=a;if(Object.keys(n).length){const o=t.map(D.dashCase).join("-"),a="t_"+D.toHash(o,4),i=await Z.parseAndJoinStyles(n,`.${o}, .${a}`);s.push(i)}return s.join(`
|
2
|
+
`)},ve=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=be(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},be=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const a=t?`${t}.${n}`:n;return typeof o=="object"?be(o,a,s):s.add(t)}),[...s]):[],$e=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=c.join(e,"package.json");return l.existsSync(t)?t:$e(c.join(e,".."))},Re=async e=>{const t=$e(e);return await we.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Me=async e=>{const t=await Re(e);if(t)return t.type};let H;const Fe=async e=>{if(H)return H;const t=await Me(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:re&&re.tagName.toUpperCase()==="SCRIPT"&&re.src||new URL("index-CelIwoBr.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),Je=e=>{B.error(e)};function Ce(e){return e?typeof e!="string"?Ce(String(e)):e.replace(/[^\d\w]/g,"."):""}const ze={"*, *::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"}},qe=(e,t)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),a=ce.createSourceFile("temp.ts",e,ce.ScriptTarget.Latest,!0);function i(d){if(ce.isVariableDeclaration(d)&&d.name.getText()===t){const S=d.getStart(),m=d.getEnd();clearTimeout(o),s([S,m])}d.forEachChild(i)}i(a)}),E={externalModules:[],rcFile:void 0,destDir:void 0},Pe=e=>{if(E.externalModules.length>0)return E.externalModules;const s=l.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return E.externalModules=n,n},z=async e=>{if(E.destDir)return E.destDir;const t=await fe(e),s=c.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},le=["salty","css","styles","styled"],Ne=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),ee=(e,t=[])=>Ne(t).test(e),xe=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=c.join(e,".saltyrc.json"),s=await we.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):xe(c.join(e,".."))},fe=async e=>{var n,o;const t=await xe(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((o=t.projects)==null?void 0:o.find(a=>a.dir===t.defaultProject))},He=async e=>{const t=await fe(e),s=await z(e),n=c.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),a=await Fe(e),i=Pe(n);await Se.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:a,external:i});const d=Date.now(),{config:S}=await import(`${o}?t=${d}`);return{config:S,path:o}},ke=async(e,t)=>{var me,ye;const s=await z(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:$,outputFilePath:K}=await U(e,w,s);Object.entries($).forEach(([_,P])=>{P.isMedia?n.mediaQueries.push([_,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${_};;${K}`))})}));const{config:o,path:a}=await He(e),i={...o},{mediaQueries:d}=n;i.mediaQueries=Object.fromEntries(d.map(([w,$])=>[`@${w}`,$]));const S=d.map(([w])=>`'@${w}'`).join(" | "),m=new Set,r=async(w,$=[])=>{if(!w)return[];const K=Object.entries(w).map(async([P,M])=>{const L=async T=>{if(!T)return;if(T instanceof Promise)return await L(await T);if(typeof T=="function")return await L(await T());if(typeof T=="object")return await r(T,[...$,P]);const oe=Ce(P),ie=D.dashCase(P),ae=[...$,oe].join(".");m.add(`"${ae}"`);const Y=[...$.map(D.dashCase),ie].join("-"),ge=Z.parseVariableTokens(T);return ge?`--${Y}: ${ge.transformed};`:`--${Y}: ${T};`};return await L(M)});return(await Promise.all(K)).flat()},g=async w=>{if(!w)return[];const $=Object.entries(w).map(async([_,P])=>{const M=await r(P);return _==="base"?M.join(""):i.mediaQueries[_]?`${i.mediaQueries[_]} { ${M.join("")} }`:`${_} { ${M.join("")} }`});return(await Promise.all($)).flat()},y=async w=>{if(!w)return[];const $=Object.entries(w).map(async([_,P])=>{const M=Object.entries(P).map(async([T,oe])=>{const ie=await r(oe,[_]),ae=`.${_}-${T}, [data-${_}="${T}"]`,Y=ie.join("");return`${ae} { ${Y} }`});return(await Promise.all(M)).flat()});return(await Promise.all($)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),p=w=>n.variables.map($=>w==="static"?h($._current):$._current[w]),F=J.mergeObjects(h(o.variables),p("static")),x=await r(F),k=J.mergeObjects((me=o.variables)==null?void 0:me.responsive,p("responsive")),V=await g(k),q=J.mergeObjects((ye=o.variables)==null?void 0:ye.conditional,p("conditional")),A=await y(q),de=c.join(s,"css/_variables.css"),v=`:root { ${x.join("")} ${V.join("")} } ${A.join("")}`;l.writeFileSync(de,v),i.staticVariables=F;const te=c.join(s,"css/_global.css"),u=J.mergeObjects(o.global,n.globalStyles),j=await Z.parseAndJoinStyles(u,"");l.writeFileSync(te,`@layer global { ${j} }`);const b=c.join(s,"css/_reset.css"),C=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:ze,N=await Z.parseAndJoinStyles(C,"");l.writeFileSync(b,`@layer reset { ${N} }`);const O=c.join(s,"css/_templates.css"),R=J.mergeObjects(o.templates,n.templates),W=await je(R),I=ve(R);l.writeFileSync(O,`@layer templates { ${W} }`),i.templates=R;const X=o.templates?[Ee.defineTemplates(o.templates)._setPath(`config;;${a}`)]:[],se=J.mergeFactories(n.templates,X);i.templatePaths=Object.fromEntries(Object.entries(se).map(([w,$])=>[w,$._path]));const G=c.join(s,"types/css-tokens.d.ts"),De=`
|
3
|
+
// Variable types
|
4
|
+
type VariableTokens = ${[...m].join("|")};
|
5
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
+
|
7
|
+
// Template types
|
8
|
+
type TemplateTokens = {
|
9
|
+
${Object.entries(I).map(([w,$])=>`${w}?: ${$}`).join(`
|
10
|
+
`)}
|
11
|
+
}
|
12
|
+
|
13
|
+
// Media query types
|
14
|
+
type MediaQueryKeys = ${S||"''"};
|
15
|
+
`;l.writeFileSync(G,De);const _e=c.join(s,"cache/config-cache.json");l.writeFileSync(_e,JSON.stringify(i,null,2))},he=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 i=o.exec(e);if(i){const d=i.at(1);if(le.some(m=>d==null?void 0:d.includes(m)))return t}return"styled('div',"}),We=(e,t)=>{try{const s=l.readFileSync(c.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
+
|
17
|
+
${e}`:`globalThis.saltyConfig = {};
|
18
|
+
|
19
|
+
${e}`}catch{return e}},U=async(e,t,s)=>{const n=D.toHash(t),o=c.join(s,"./temp");l.existsSync(o)||l.mkdirSync(o);const a=c.parse(t);let i=l.readFileSync(t,"utf8");i=he(i),i=We(i,e);const d=c.join(s,"js",n+".js"),S=await fe(e),m=c.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),r=Pe(m),g=await Fe(e);await Se.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:g,target:["node20"],keepNames:!0,external:r,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},F=>{const x=l.readFileSync(F.path,"utf8");return{contents:he(x),loader:"ts"}})}}]});const y=Date.now();return{contents:await import(`${d}?t=${y}`),outputFilePath:d}},Ie=async e=>{const t=await z(e),s=c.join(t,"cache/config-cache.json"),n=l.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ue=async e=>{const t=await Ie(e),s=await z(e),n=c.join(s,"salty.config.js"),o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return J.mergeObjects(a,t)},pe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ge=async(e,t=pe(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const o=[],a=[],i=await z(e),d=c.join(i,"index.css");s&&(()=>{l.existsSync(i)&&Oe.execSync("rm -rf "+i),l.mkdirSync(i,{recursive:!0}),l.mkdirSync(c.join(i,"css")),l.mkdirSync(c.join(i,"types")),l.mkdirSync(c.join(i,"js")),l.mkdirSync(c.join(i,"cache"))})();const m=new Set,r=new Set;async function g(u){const j=["node_modules","saltygen"],b=l.statSync(u);if(b.isDirectory()){const f=l.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(c.join(u,N))))}else if(b.isFile()&&ee(u)){m.add(u);const C=l.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&r.add(u)}}await g(e),await ke(e,r);const y={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async u=>{const{contents:j}=await U(e,u,i);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?y.keyframes.push({value:f,src:u,name:b}):f.isClassName?y.classNames.push({...f,src:u,name:b}):f.generator&&y.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of y.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=c.join(i,f);o.push(b),l.writeFileSync(C,j.css)}const p={};for(const u of y.components){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});a[f.priority]||(a[f.priority]=[]);const C=await f.css;if(!C)continue;a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=c.join(i,N);l.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}for(const u of y.classNames){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;a[f.priority]||(a[f.priority]=[]),a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=c.join(i,N);l.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([u,j])=>{const b=j.map(R=>`@import url('./${R}');`).join(`
|
20
|
+
`),f=D.toHash(u,6),C=c.parse(u),N=D.dashCase(C.name),O=c.join(i,`css/f_${N}-${f}.css`);l.writeFileSync(O,b||"/* Empty file */")});const F=o.map(u=>`@import url('./css/${u}');`).join(`
|
21
|
+
`);let A=`/*!
|
22
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
23
|
+
* Do not edit this file directly
|
24
|
+
*/
|
25
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
26
|
+
|
27
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return l.readFileSync(c.join(i,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
28
|
+
`)}
|
29
|
+
${F}`;if(h.importStrategy!=="component"){const u=a.reduce((j,b,f)=>{const C=b.reduce((W,I)=>{var ne;const X=c.join(i,"css",I),se=l.readFileSync(X,"utf8"),G=((ne=/.*-([^-]+)-\d+.css/.exec(I))==null?void 0:ne.at(1))||D.toHash(X,6);return W.includes(G)?W:`${W}
|
30
|
+
/*start:${G}-${I}*/
|
31
|
+
${se}
|
32
|
+
/*end:${G}*/
|
33
|
+
`},""),N=`l_${f}.css`,O=c.join(i,"css",N),R=`@layer l${f} { ${C}
|
34
|
+
}`;return l.writeFileSync(O,R),`${j}
|
35
|
+
@import url('./css/${N}');`},"");A+=u}l.writeFileSync(d,A);const v=Date.now()-n,te=v<200?"🔥":v<500?"🚀":v<1e3?"🎉":v<2e3?"🚗":v<5e3?"🤔":"🥴";B.info(`Generated CSS in ${v}ms! ${te}`)}catch(n){console.error(n)}},Ke=async(e,t,s=pe())=>{try{const n=await z(e);if(ee(t)){const a=[],i=await ue(e),{contents:d}=await U(e,t,n);for(const[S,m]of Object.entries(d)){if(m.isKeyframes&&m.css){const F=`css/${`a_${m.animationName}.css`}`,x=c.join(n,F);l.writeFileSync(x,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:S,isProduction:s,config:i}),F=await p.css;if(!F)continue;a[p.priority]||(a[p.priority]=[]),a[p.priority].push(p.cssFileName);const x=`css/${p.cssFileName}`,k=c.join(n,x);l.writeFileSync(k,F);continue}if(!m.generator)continue;const r=m.generator._withBuildContext({callerName:S,isProduction:s,config:i}),g=await r.css;if(!g)continue;const y=`css/${r.cssFileName}`,h=c.join(n,y);l.writeFileSync(h,g),a[r.priority]||(a[r.priority]=[]),a[r.priority].push(r.cssFileName)}if(i.importStrategy!=="component")a.forEach((S,m)=>{const r=`l_${m}.css`,g=c.join(n,"css",r);let y=l.readFileSync(g,"utf8");S.forEach(h=>{var k;const p=c.join(n,"css",h),F=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||D.toHash(p,6);if(!y.includes(F)){const V=l.readFileSync(p,"utf8"),q=`/*start:${F}-${h}*/
|
36
|
+
${V}
|
37
|
+
/*end:${F}*/
|
38
|
+
`;y=`${y.replace(/\}$/,"")}
|
39
|
+
${q}
|
40
|
+
}`}}),l.writeFileSync(g,y)});else{const S=a.flat().map(h=>`@import url('./${h}');`).join(`
|
41
|
+
`),m=D.toHash(t,6),r=c.parse(t),g=D.dashCase(r.name),y=c.join(n,`css/f_${g}-${m}.css`);l.writeFileSync(y,S||"/* Empty file */")}}}catch(n){console.error(n)}},Le=async(e,t,s=pe())=>{var n,o;try{const a=await z(e);if(ee(t)){const d=l.readFileSync(t,"utf8"),S=await ue(e),{contents:m}=await U(e,t,a);let r=d;for(const[g,y]of Object.entries(m)){if(y.isKeyframes||!y.generator)continue;const h=y.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[p,F]=await qe(r,g),x=r.slice(p,F);if(y.isClassName){const k=r,V=` ${g} = className("${h.classNames}")`;r=r.replace(x,V),k===r&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const k=(o=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:o.trim(),V=r,q=` ${g} = styled(${k}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;r=r.replace(x,q),V===r&&console.error("Minimize file failed to change content",{name:g,tagName:k})}}if(S.importStrategy==="component"){const g=D.toHash(t,6),y=c.parse(t);r=`import '../../saltygen/css/${`f_${D.dashCase(y.name)}-${g}.css`}';
|
42
|
+
${r}`}return r=r.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(a){console.error("Error in minimizeFile:",a)}};exports.compileSaltyFile=U;exports.generateConfigStyles=ke;exports.generateCss=Ge;exports.generateFile=Ke;exports.isSaltyFile=ee;exports.logError=Je;exports.logger=B;exports.minimizeFile=Le;exports.saltyFileExtensions=le;exports.saltyFileRegExp=Ne;
|
package/package.json
CHANGED
package/server/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-DJb3U4c8.cjs");exports.checkShouldRestart=e.checkShouldRestart;
|
package/server/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const s=require("fs/promises"),r=require("./index-
|
1
|
+
"use strict";const s=require("fs/promises"),r=require("./index-CelIwoBr.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!(/.+define[A-Z]\w+/.test(e)||/.+keyframes\(.+/.test(e))};exports.checkShouldRestart=i;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { readFile as r } from "fs/promises";
|
2
|
-
import { i as e } from "./index-
|
2
|
+
import { i as e } from "./index-B_V_O1Qg.js";
|
3
3
|
const f = async (t) => {
|
4
4
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
5
5
|
if (t.includes("salty.config")) return !0;
|
package/types/config-types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { BaseStyles, CssStyles } from '../types';
|
2
2
|
import { OrString } from '../types/util-types';
|
3
|
-
export type GlobalStyles = Record<string,
|
3
|
+
export type GlobalStyles = Record<string, BaseStyles>;
|
4
4
|
export type CssVariableTokensObject = Record<string, unknown>;
|
5
5
|
export interface CssResponsiveVariables {
|
6
6
|
[key: string]: CssVariableTokensObject;
|
package/types/index.d.ts
CHANGED
@@ -82,13 +82,13 @@ export interface GeneratorOptions {
|
|
82
82
|
defaultProps?: Record<PropertyKey, unknown>;
|
83
83
|
priority?: number;
|
84
84
|
}
|
85
|
-
interface
|
85
|
+
export interface BaseStyles extends CssProperties, CssStyles, CssPseudos, TemplateTokens, MediaQueryStyles {
|
86
86
|
}
|
87
87
|
type Pseudos = CSS.Pseudos | `&${CSS.Pseudos}`;
|
88
88
|
type CssPseudos = {
|
89
89
|
[P in Pseudos]?: CssStyles;
|
90
90
|
};
|
91
91
|
export interface StyledParams extends GeneratorOptions, Variants {
|
92
|
-
base?:
|
92
|
+
base?: BaseStyles;
|
93
93
|
}
|
94
94
|
export {};
|
package/index-vWQ_NojW.cjs
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";const _e=require("esbuild"),Te=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),c=require("path"),l=require("fs"),he=require("fs/promises"),Z=require("./parse-styles-CXclnoUS.cjs"),Q=require("winston"),z=require("./css/merge.cjs"),Oe=require("./define-templates-Cunsb_Tr.cjs"),ae=require("typescript");var ce=typeof document<"u"?document.currentScript:null;function Ee(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 we=Ee(_e),Se=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,a]of Object.entries(e))if(typeof a!="function")if(a&&typeof a=="object"){const i=o.trim(),d=await Se(a,[...t,i]);s.push(d)}else n[o]=a;if(Object.keys(n).length){const o=t.map(D.dashCase).join("-"),a="t_"+D.toHash(o,4),i=await Z.parseAndJoinStyles(n,`.${o}, .${a}`);s.push(i)}return s.join(`
|
2
|
-
`)},Ve=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=je(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},je=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const a=t?`${t}.${n}`:n;return typeof o=="object"?je(o,a,s):s.add(t)}),[...s]):[],be=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=c.join(e,"package.json");return l.existsSync(t)?t:be(c.join(e,".."))},ve=async e=>{const t=be(e);return await he.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Re=async e=>{const t=await ve(e);if(t)return t.type};let H;const $e=async e=>{if(H)return H;const t=await Re(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ce&&ce.tagName.toUpperCase()==="SCRIPT"&&ce.src||new URL("index-vWQ_NojW.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),Me=e=>{B.error(e)};function Fe(e){return e?typeof e!="string"?Fe(String(e)):e.replace(/[^\d\w]/g,"."):""}const Je={"*, *::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"}},ze=(e,t)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),a=ae.createSourceFile("temp.ts",e,ae.ScriptTarget.Latest,!0);function i(d){if(ae.isVariableDeclaration(d)&&d.name.getText()===t){const S=d.getStart(),m=d.getEnd();clearTimeout(o),s([S,m])}d.forEachChild(i)}i(a)}),E={externalModules:[],rcFile:void 0,destDir:void 0},Ce=e=>{if(E.externalModules.length>0)return E.externalModules;const s=l.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return E.externalModules=n,n},q=async e=>{if(E.destDir)return E.destDir;const t=await le(e),s=c.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},re=["salty","css","styles","styled"],Pe=(e=[])=>new RegExp(`\\.(${[...re,...e].join("|")})\\.`),ee=(e,t=[])=>Pe(t).test(e),Ne=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=c.join(e,".saltyrc.json"),s=await he.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):Ne(c.join(e,".."))},le=async e=>{var n,o;const t=await Ne(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((o=t.projects)==null?void 0:o.find(a=>a.dir===t.defaultProject))},qe=async e=>{const t=await le(e),s=await q(e),n=c.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),a=await $e(e),i=Ce(n);await we.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:a,external:i});const d=Date.now(),{config:S}=await import(`${o}?t=${d}`);return{config:S,path:o}},ke=async(e,t)=>{var de,me;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:$,outputFilePath:K}=await U(e,w,s);Object.entries($).forEach(([_,C])=>{C.isMedia?n.mediaQueries.push([_,C]):C.isGlobalDefine?n.globalStyles.push(C):C.isDefineVariables?n.variables.push(C):C.isDefineTemplates&&n.templates.push(C._setPath(`${_};;${K}`))})}));const{config:o,path:a}=await qe(e),i={...o},{mediaQueries:d}=n;i.mediaQueries=Object.fromEntries(d.map(([w,$])=>[`@${w}`,$]));const S=d.map(([w])=>`'@${w}'`).join(" | "),m=new Set,r=async(w,$=[])=>{if(!w)return[];const K=Object.entries(w).map(async([C,J])=>{const L=async T=>{if(!T)return;if(T instanceof Promise)return await L(await T);if(typeof T=="function")return await L(await T());if(typeof T=="object")return await r(T,[...$,C]);const ne=Fe(C),oe=D.dashCase(C),ie=[...$,ne].join(".");m.add(`"${ie}"`);const Y=[...$.map(D.dashCase),oe].join("-"),ye=Z.parseVariableTokens(T);return ye?`--${Y}: ${ye.transformed};`:`--${Y}: ${T};`};return await L(J)});return(await Promise.all(K)).flat()},g=async w=>{if(!w)return[];const $=Object.entries(w).map(async([_,C])=>{const J=await r(C);return _==="base"?J.join(""):i.mediaQueries[_]?`${i.mediaQueries[_]} { ${J.join("")} }`:`${_} { ${J.join("")} }`});return(await Promise.all($)).flat()},y=async w=>{if(!w)return[];const $=Object.entries(w).map(async([_,C])=>{const J=Object.entries(C).map(async([T,ne])=>{const oe=await r(ne,[_]),ie=`.${_}-${T}, [data-${_}="${T}"]`,Y=oe.join("");return`${ie} { ${Y} }`});return(await Promise.all(J)).flat()});return(await Promise.all($)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),p=w=>n.variables.map($=>w==="static"?h($._current):$._current[w]),F=z.mergeObjects(h(o.variables),p("static")),k=await r(F),x=z.mergeObjects((de=o.variables)==null?void 0:de.responsive,p("responsive")),V=await g(x),v=z.mergeObjects((me=o.variables)==null?void 0:me.conditional,p("conditional")),pe=await y(v),R=c.join(s,"css/_variables.css"),te=`:root { ${k.join("")} ${V.join("")} } ${pe.join("")}`;l.writeFileSync(R,te),i.staticVariables=F;const u=c.join(s,"css/_global.css"),j=z.mergeObjects(o.global,n.globalStyles),b=await Z.parseAndJoinStyles(j,"");l.writeFileSync(u,`@layer global { ${b} }`);const f=c.join(s,"css/_reset.css"),N=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Je,O=await Z.parseAndJoinStyles(N,"");l.writeFileSync(f,`@layer reset { ${O} }`);const W=c.join(s,"css/_templates.css"),M=z.mergeObjects(o.templates,n.templates),I=await Se(M),A=Ve(M);l.writeFileSync(W,`@layer templates { ${I} }`),i.templates=M;const se=o.templates?[Oe.defineTemplates(o.templates)._setPath(`config;;${a}`)]:[],G=z.mergeFactories(n.templates,se);i.templatePaths=Object.fromEntries(Object.entries(G).map(([w,$])=>[w,$._path]));const X=c.join(s,"types/css-tokens.d.ts"),xe=`
|
3
|
-
// Variable types
|
4
|
-
type VariableTokens = ${[...m].join("|")};
|
5
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
-
|
7
|
-
// Template types
|
8
|
-
type TemplateTokens = {
|
9
|
-
${Object.entries(A).map(([w,$])=>`${w}?: ${$}`).join(`
|
10
|
-
`)}
|
11
|
-
}
|
12
|
-
|
13
|
-
// Media query types
|
14
|
-
type MediaQueryKeys = ${S||"''"};
|
15
|
-
`;l.writeFileSync(X,xe);const De=c.join(s,"cache/config-cache.json");l.writeFileSync(De,JSON.stringify(i,null,2))},ge=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 i=o.exec(e);if(i){const d=i.at(1);if(re.some(m=>d==null?void 0:d.includes(m)))return t}return"styled('div',"}),He=(e,t)=>{try{const s=l.readFileSync(c.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
-
|
17
|
-
${e}`:`globalThis.saltyConfig = {};
|
18
|
-
|
19
|
-
${e}`}catch{return e}},U=async(e,t,s)=>{const n=D.toHash(t),o=c.join(s,"./temp");l.existsSync(o)||l.mkdirSync(o);const a=c.parse(t);let i=l.readFileSync(t,"utf8");i=ge(i),i=He(i,e);const d=c.join(s,"js",n+".js"),S=await le(e),m=c.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),r=Ce(m),g=await $e(e);await we.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:g,target:["node20"],keepNames:!0,external:r,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},F=>{const k=l.readFileSync(F.path,"utf8");return{contents:ge(k),loader:"ts"}})}}]});const y=Date.now();return{contents:await import(`${d}?t=${y}`),outputFilePath:d}},We=async e=>{const t=await q(e),s=c.join(t,"cache/config-cache.json"),n=l.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},fe=async e=>{const t=await We(e),s=await q(e),n=c.join(s,"salty.config.js"),o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return z.mergeObjects(a,t)},ue=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ie=async(e,t=ue(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const o=[],a=[],i=await q(e),d=c.join(i,"index.css");s&&(()=>{l.existsSync(i)&&Te.execSync("rm -rf "+i),l.mkdirSync(i,{recursive:!0}),l.mkdirSync(c.join(i,"css")),l.mkdirSync(c.join(i,"types")),l.mkdirSync(c.join(i,"js")),l.mkdirSync(c.join(i,"cache"))})();const m=new Set,r=new Set;async function g(u){const j=["node_modules","saltygen"],b=l.statSync(u);if(b.isDirectory()){const f=l.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(c.join(u,N))))}else if(b.isFile()&&ee(u)){m.add(u);const P=l.readFileSync(u,"utf8");/define[\w\d]+\(/.test(P)&&r.add(u)}}await g(e),await ke(e,r);const y={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async u=>{const{contents:j}=await U(e,u,i);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?y.keyframes.push({value:f,src:u,name:b}):f.isClassName?y.classNames.push({...f,src:u,name:b}):f.generator&&y.components.push({...f,src:u,name:b})}));const h=await fe(e);for(const u of y.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,P=c.join(i,f);o.push(b),l.writeFileSync(P,j.css)}const p={};for(const u of y.components){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});a[f.priority]||(a[f.priority]=[]);const P=await f.css;if(!P)continue;a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=c.join(i,N);l.writeFileSync(O,P),h.importStrategy==="component"&&p[j].push(f.cssFileName)}for(const u of y.classNames){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),P=await f.css;if(!P)continue;a[f.priority]||(a[f.priority]=[]),a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=c.join(i,N);l.writeFileSync(O,P),h.importStrategy==="component"&&p[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([u,j])=>{const b=j.map(W=>`@import url('./${W}');`).join(`
|
20
|
-
`),f=D.toHash(u,6),P=c.parse(u),N=D.dashCase(P.name),O=c.join(i,`css/f_${N}-${f}.css`);l.writeFileSync(O,b||"/* Empty file */")});const F=o.map(u=>`@import url('./css/${u}');`).join(`
|
21
|
-
`);let v=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
22
|
-
|
23
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return l.readFileSync(c.join(i,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
24
|
-
`)}
|
25
|
-
${F}`;if(h.importStrategy!=="component"){const u=a.reduce((j,b,f)=>{const P=b.reduce((M,I)=>{var X;const A=c.join(i,"css",I),se=l.readFileSync(A,"utf8"),G=((X=/.*-([^-]+)-\d+.css/.exec(I))==null?void 0:X.at(1))||D.toHash(A,6);return M.includes(G)?M:`${M}
|
26
|
-
/*start:${G}-${I}*/
|
27
|
-
${se}
|
28
|
-
/*end:${G}*/
|
29
|
-
`},""),N=`l_${f}.css`,O=c.join(i,"css",N),W=`@layer l${f} { ${P}
|
30
|
-
}`;return l.writeFileSync(O,W),`${j}
|
31
|
-
@import url('./css/${N}');`},"");v+=u}l.writeFileSync(d,v);const R=Date.now()-n,te=R<200?"🔥":R<500?"🚀":R<1e3?"🎉":R<2e3?"🚗":R<5e3?"🤔":"🥴";B.info(`Generated CSS in ${R}ms! ${te}`)}catch(n){console.error(n)}},Ge=async(e,t,s=ue())=>{try{const n=await q(e);if(ee(t)){const a=[],i=await fe(e),{contents:d}=await U(e,t,n);for(const[S,m]of Object.entries(d)){if(m.isKeyframes&&m.css){const F=`css/${`a_${m.animationName}.css`}`,k=c.join(n,F);l.writeFileSync(k,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:S,isProduction:s,config:i}),F=await p.css;if(!F)continue;a[p.priority]||(a[p.priority]=[]),a[p.priority].push(p.cssFileName);const k=`css/${p.cssFileName}`,x=c.join(n,k);l.writeFileSync(x,F);continue}if(!m.generator)continue;const r=m.generator._withBuildContext({callerName:S,isProduction:s,config:i}),g=await r.css;if(!g)continue;const y=`css/${r.cssFileName}`,h=c.join(n,y);l.writeFileSync(h,g),a[r.priority]||(a[r.priority]=[]),a[r.priority].push(r.cssFileName)}if(i.importStrategy!=="component")a.forEach((S,m)=>{const r=`l_${m}.css`,g=c.join(n,"css",r);let y=l.readFileSync(g,"utf8");S.forEach(h=>{var x;const p=c.join(n,"css",h),F=((x=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:x.at(1))||D.toHash(p,6);if(!y.includes(F)){const V=l.readFileSync(p,"utf8"),v=`/*start:${F}-${h}*/
|
32
|
-
${V}
|
33
|
-
/*end:${F}*/
|
34
|
-
`;y=`${y.replace(/\}$/,"")}
|
35
|
-
${v}
|
36
|
-
}`}}),l.writeFileSync(g,y)});else{const S=a.flat().map(h=>`@import url('./${h}');`).join(`
|
37
|
-
`),m=D.toHash(t,6),r=c.parse(t),g=D.dashCase(r.name),y=c.join(n,`css/f_${g}-${m}.css`);l.writeFileSync(y,S||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=ue())=>{var n,o;try{const a=await q(e);if(ee(t)){const d=l.readFileSync(t,"utf8"),S=await fe(e),{contents:m}=await U(e,t,a);let r=d;for(const[g,y]of Object.entries(m)){if(y.isKeyframes||!y.generator)continue;const h=y.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[p,F]=await ze(r,g),k=r.slice(p,F);if(y.isClassName){const x=r,V=` ${g} = className("${h.classNames}")`;r=r.replace(k,V),x===r&&console.error("Minimize file failed to change content",{name:g})}if(k.includes("styled")){const x=(o=(n=/styled\(([^,]+),/.exec(k))==null?void 0:n.at(1))==null?void 0:o.trim(),V=r,v=` ${g} = styled(${x}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;r=r.replace(k,v),V===r&&console.error("Minimize file failed to change content",{name:g,tagName:x})}}if(S.importStrategy==="component"){const g=D.toHash(t,6),y=c.parse(t);r=`import '../../saltygen/css/${`f_${D.dashCase(y.name)}-${g}.css`}';
|
38
|
-
${r}`}return r=r.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(a){console.error("Error in minimizeFile:",a)}};exports.compileSaltyFile=U;exports.generateConfigStyles=ke;exports.generateCss=Ie;exports.generateFile=Ge;exports.isSaltyFile=ee;exports.logError=Me;exports.logger=B;exports.minimizeFile=Ke;exports.saltyFileExtensions=re;exports.saltyFileRegExp=Pe;
|