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

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/bin/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-neHUpjdt.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,v)=>{se.exec(y,F=>{if(F)return v(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),v=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),v.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){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"))},v=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=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:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).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}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,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 t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.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 g=process.cwd(),r=R(l),T=await Promise.all([v("salty.config.ts"),v("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:f})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,f),await S(c)});await Promise.all(m);const w=n.relative(g,r)||".",h=n.join(g,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const f=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,f),await S(h)}else{const e=JSON.parse(d),f=(e==null?void 0:e.projects)||[];if(f.findIndex(o=>o.dir===w)===-1){f.push({dir:w,framework:"react"}),e.projects=[...f];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(g,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-zPXqhZf1.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,v)=>{se.exec(y,F=>{if(F)return v(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),v=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),v.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){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"))},v=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=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:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).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}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,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 t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.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 g=process.cwd(),r=R(l),T=await Promise.all([v("salty.config.ts"),v("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:f})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,f),await S(c)});await Promise.all(m);const w=n.relative(g,r)||".",h=n.join(g,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const f=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,f),await S(h)}else{const e=JSON.parse(d),f=(e==null?void 0:e.projects)||[];if(f.findIndex(o=>o.dir===w)===-1){f.push({dir:w,framework:"react"}),e.projects=[...f];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(g,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
package/bin/main.js CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
3
3
  import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
4
4
  import { join as i, relative as z, parse as rt, format as tt } from "path";
5
5
  import { render as ct } from "ejs";
6
- import { l as e, a as h, g as et } from "../index-9iO5zogY.js";
6
+ import { l as e, a as h, g as et } from "../index-BjclEscx.js";
7
7
  import { p as lt } from "../pascal-case-BQpR5PdN.js";
8
8
  import { exec as dt } from "child_process";
9
9
  import ft from "ora";
@@ -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-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
+ "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-zPXqhZf1.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;
package/compiler/index.js CHANGED
@@ -6,7 +6,7 @@ import "fs";
6
6
  import "fs/promises";
7
7
  import "../parse-styles-DrLhKtqW.js";
8
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";
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-BjclEscx.js";
10
10
  import "../merge-BVm9us1A.js";
11
11
  export {
12
12
  g as compileSaltyFile,
package/css/merge.d.ts CHANGED
@@ -2,5 +2,5 @@ import { CSSinJS } from '../types';
2
2
  interface StyleFactory {
3
3
  _current: Record<string, any>;
4
4
  }
5
- export declare const mergeStyles: <T extends StyleFactory | CSSinJS>(...styles: T[]) => {};
5
+ export declare const mergeStyles: <T extends StyleFactory | CSSinJS>(...styles: T[]) => T;
6
6
  export {};
@@ -2,12 +2,12 @@ import * as ot from "esbuild";
2
2
  import { execSync as mt } from "child_process";
3
3
  import { t as H, d as K } from "./dash-case-DBThphLm.js";
4
4
  import { join as o, parse as q } from "path";
5
- import { existsSync as U, writeFileSync as x, mkdirSync as R, readFileSync as v, statSync as gt, readdirSync as yt } from "fs";
5
+ import { existsSync as U, writeFileSync as x, mkdirSync as z, readFileSync as v, statSync as gt, readdirSync as yt } from "fs";
6
6
  import { readFile as rt, writeFile as ht } from "fs/promises";
7
7
  import { p as st, a as bt } from "./parse-styles-DrLhKtqW.js";
8
- import { p as $t, a as St } from "./parse-templates-DRKlN-pP.js";
9
- import { createLogger as wt, format as Q, transports as Ct } from "winston";
10
- import { m as G } from "./merge-BVm9us1A.js";
8
+ import { p as $t, a as wt } from "./parse-templates-DRKlN-pP.js";
9
+ import { createLogger as St, format as Q, transports as Ct } from "winston";
10
+ import { m as W } from "./merge-BVm9us1A.js";
11
11
  const at = (t) => {
12
12
  if (!t || t === "/") throw new Error("Could not find package.json file");
13
13
  const e = o(t, "package.json");
@@ -21,16 +21,16 @@ const at = (t) => {
21
21
  if (e)
22
22
  return e.type;
23
23
  };
24
- let J;
24
+ let R;
25
25
  const it = async (t) => {
26
- if (J) return J;
26
+ if (R) return R;
27
27
  const e = await xt(t);
28
- return e === "module" ? J = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (J = "cjs"), J || "esm";
29
- }, B = wt({
28
+ return e === "module" ? R = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (R = "cjs"), R || "esm";
29
+ }, B = St({
30
30
  level: "debug",
31
31
  format: Q.combine(Q.colorize(), Q.cli()),
32
32
  transports: [new Ct.Console({})]
33
- }), Rt = (t) => {
33
+ }), zt = (t) => {
34
34
  B.error(t);
35
35
  };
36
36
  function ct(t) {
@@ -92,7 +92,7 @@ const jt = {
92
92
  if (!s) return [];
93
93
  const c = s[1].split(",").map((l) => l.replace(/['"`]/g, "").trim());
94
94
  return E.externalModules = c, c;
95
- }, z = async (t) => {
95
+ }, _ = async (t) => {
96
96
  if (E.destDir) return E.destDir;
97
97
  const e = await Y(t), s = o(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
98
98
  return E.destDir = s, s;
@@ -104,81 +104,79 @@ const jt = {
104
104
  return s ? (E.rcFile = s, s) : pt(o(t, ".."));
105
105
  }, Y = async (t) => {
106
106
  var c, l;
107
- const e = await pt(t), s = (c = e.projects) == null ? void 0 : c.find((i) => t.endsWith(i.dir || ""));
108
- return s || ((l = e.projects) == null ? void 0 : l.find((i) => i.dir === e.defaultProject));
107
+ const e = await pt(t), s = (c = e.projects) == null ? void 0 : c.find((r) => t.endsWith(r.dir || ""));
108
+ return s || ((l = e.projects) == null ? void 0 : l.find((r) => r.dir === e.defaultProject));
109
109
  }, Dt = async (t) => {
110
- const e = await Y(t), s = await z(t), c = o(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), l = o(s, "salty.config.js"), i = await it(t), r = lt(c);
110
+ const e = await Y(t), s = await _(t), c = o(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), l = o(s, "salty.config.js"), r = await it(t), a = lt(c);
111
111
  await ot.build({
112
112
  entryPoints: [c],
113
113
  minify: !0,
114
114
  treeShaking: !0,
115
115
  bundle: !0,
116
116
  outfile: l,
117
- format: i,
118
- external: r
117
+ format: r,
118
+ external: a
119
119
  });
120
120
  const y = Date.now(), { config: p } = await import(`${l}?t=${y}`);
121
121
  return p;
122
122
  }, Nt = async (t, e) => {
123
- const s = await Dt(t), c = { ...s }, l = /* @__PURE__ */ new Set(), i = (C, S = []) => C ? Object.entries(C).flatMap(([T, F]) => {
123
+ const s = await Dt(t), c = { ...s }, l = /* @__PURE__ */ new Set(), r = (C, w = []) => C ? Object.entries(C).flatMap(([T, F]) => {
124
124
  if (!F) return;
125
- if (typeof F == "object") return i(F, [...S, T]);
126
- const O = ct(T), L = K(T), Z = [...S, O].join(".");
125
+ if (typeof F == "object") return r(F, [...w, T]);
126
+ const J = ct(T), L = K(T), Z = [...w, J].join(".");
127
127
  l.add(`"${Z}"`);
128
- const A = [...S.map(K), L].join("-"), { result: ut } = bt(F);
128
+ const A = [...w.map(K), L].join("-"), { result: ut } = bt(F);
129
129
  return `--${A}: ${ut};`;
130
- }) : [], r = (C) => C ? Object.entries(C).flatMap(([S, T]) => {
131
- const F = i(T);
132
- return S === "base" ? F.join("") : `${S} { ${F.join("")} }`;
133
- }) : [], y = (C) => C ? Object.entries(C).flatMap(([S, T]) => Object.entries(T).flatMap(([F, O]) => {
134
- const L = i(O, [S]), Z = `.${S}-${F}, [data-${S}="${F}"]`, A = L.join("");
130
+ }) : [], a = (C) => C ? Object.entries(C).flatMap(([w, T]) => {
131
+ const F = r(T);
132
+ return w === "base" ? F.join("") : `${w} { ${F.join("")} }`;
133
+ }) : [], y = (C) => C ? Object.entries(C).flatMap(([w, T]) => Object.entries(T).flatMap(([F, J]) => {
134
+ const L = r(J, [w]), Z = `.${w}-${F}, [data-${w}="${F}"]`, A = L.join("");
135
135
  return `${Z} { ${A} }`;
136
- })) : [], p = (C) => e.variables.map((S) => S._current[C]), n = i(G(s.variables, p("variables"))), d = r(G(s.responsiveVariables, p("responsiveVariables"))), u = y(G(s.conditionalVariables, p("conditionalVariables"))), m = await z(t), j = o(m, "css/_variables.css"), k = `:root { ${n.join("")} ${d.join("")} } ${u.join("")}`;
136
+ })) : [], p = (C) => e.variables.map((w) => w._current[C]), n = r(W(s.variables, p("variables"))), d = a(W(s.responsiveVariables, p("responsiveVariables"))), u = y(W(s.conditionalVariables, p("conditionalVariables"))), m = await _(t), j = o(m, "css/_variables.css"), k = `:root { ${n.join("")} ${d.join("")} } ${u.join("")}`;
137
137
  x(j, k);
138
- const V = o(m, "css/_global.css"), P = G(s.global, e.globalStyles), D = st(P, "");
138
+ const V = o(m, "css/_global.css"), P = W(s.global, e.globalStyles), D = st(P, "");
139
139
  x(V, `@layer global { ${D} }`);
140
- const _ = o(m, "css/_reset.css"), M = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : jt, a = st(M, "");
141
- x(_, `@layer reset { ${a} }`);
142
- const w = o(m, "css/_templates.css"), h = G(s.templates, e.templates);
143
- console.log("all", h);
144
- const $ = $t(h), g = St(h);
145
- x(w, $), c.templates = h;
146
- const b = o(m, "types/css-tokens.d.ts"), W = `
140
+ const M = o(m, "css/_reset.css"), O = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : jt, i = st(O, "");
141
+ x(M, `@layer reset { ${i} }`);
142
+ const S = o(m, "css/_templates.css"), b = W(s.templates, e.templates), $ = $t(b), g = wt(b);
143
+ x(S, $), c.templates = b;
144
+ const h = o(m, "types/css-tokens.d.ts"), I = `
147
145
  // Variable types
148
146
  type VariableTokens = ${[...l].join("|")};
149
147
  type PropertyValueToken = \`{\${VariableTokens}}\`;
150
148
 
151
149
  // Template types
152
150
  type TemplateTokens = {
153
- ${Object.entries(g).map(([C, S]) => `${C}?: ${S}`).join(`
151
+ ${Object.entries(g).map(([C, w]) => `${C}?: ${w}`).join(`
154
152
  `)}
155
153
  }
156
154
  `;
157
- x(b, W);
158
- const I = o(m, "cache/config-cache.json");
159
- x(I, JSON.stringify(c, null, 2));
155
+ x(h, I);
156
+ const G = o(m, "cache/config-cache.json");
157
+ x(G, JSON.stringify(c, null, 2));
160
158
  }, nt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
161
159
  if (/^['"`]/.test(s)) return e;
162
160
  const l = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
163
161
  if (!l.test(t)) return e;
164
- const r = l.exec(t);
165
- if (r) {
166
- const y = r.at(1);
162
+ const a = l.exec(t);
163
+ if (a) {
164
+ const y = a.at(1);
167
165
  if (ft.some((n) => y == null ? void 0 : y.includes(n))) return e;
168
166
  }
169
167
  return "styled('div',";
170
168
  }), tt = async (t, e, s) => {
171
169
  const c = H(e), l = o(s, "./temp");
172
- U(l) || R(l);
173
- const i = q(e);
174
- let r = v(e, "utf8");
175
- r = nt(r);
170
+ U(l) || z(l);
171
+ const r = q(e);
172
+ let a = v(e, "utf8");
173
+ a = nt(a);
176
174
  const y = o(s, "js", c + ".js"), p = await Y(t), n = o(t, (p == null ? void 0 : p.configDir) || "", "salty.config.ts"), d = lt(n), u = await it(t);
177
175
  await ot.build({
178
176
  stdin: {
179
- contents: r,
180
- sourcefile: i.base,
181
- resolveDir: i.dir,
177
+ contents: a,
178
+ sourcefile: r.base,
179
+ resolveDir: r.dir,
182
180
  loader: "tsx"
183
181
  },
184
182
  minify: !1,
@@ -204,23 +202,26 @@ const jt = {
204
202
  });
205
203
  const m = Date.now();
206
204
  return await import(`${y}?t=${m}`);
207
- }, et = async (t) => {
208
- const e = await z(t), s = o(e, "cache/config-cache.json"), c = v(s, "utf8");
205
+ }, Pt = async (t) => {
206
+ const e = await _(t), s = o(e, "cache/config-cache.json"), c = v(s, "utf8");
209
207
  if (!c) throw new Error("Could not find config cache file");
210
208
  return JSON.parse(c);
209
+ }, et = async (t) => {
210
+ const e = await Pt(t), s = await _(t), c = o(s, "salty.config.js"), l = Date.now(), { config: r } = await import(`${c}?t=${l}`);
211
+ return W(r, e);
211
212
  }, dt = () => {
212
213
  try {
213
214
  return process.env.NODE_ENV === "production";
214
215
  } catch {
215
216
  return !1;
216
217
  }
217
- }, zt = async (t, e = dt(), s = !0) => {
218
+ }, Wt = async (t, e = dt(), s = !0) => {
218
219
  try {
219
220
  const c = Date.now();
220
221
  e ? B.info("Generating CSS in production mode! 🔥") : B.info("Generating CSS in development mode! 🚀");
221
- const l = [], i = [], r = await z(t), y = o(r, "index.css");
222
+ const l = [], r = [], a = await _(t), y = o(a, "index.css");
222
223
  s && (() => {
223
- U(r) && mt("rm -rf " + r), R(r, { recursive: !0 }), R(o(r, "css")), R(o(r, "types")), R(o(r, "js")), R(o(r, "cache"));
224
+ U(a) && mt("rm -rf " + a), z(a, { recursive: !0 }), z(o(a, "css")), z(o(a, "types")), z(o(a, "js")), z(o(a, "cache"));
224
225
  })();
225
226
  const n = {
226
227
  keyframes: [],
@@ -230,91 +231,91 @@ const jt = {
230
231
  components: [],
231
232
  templates: []
232
233
  };
233
- async function d(a) {
234
- const w = ["node_modules", "saltygen"], h = gt(a);
235
- if (h.isDirectory()) {
236
- const $ = yt(a);
237
- if (w.some((b) => a.includes(b))) return;
238
- await Promise.all($.map((b) => d(o(a, b))));
239
- } else if (h.isFile() && X(a)) {
240
- const g = await tt(t, a, r);
241
- Object.entries(g).forEach(([b, f]) => {
234
+ async function d(i) {
235
+ const S = ["node_modules", "saltygen"], b = gt(i);
236
+ if (b.isDirectory()) {
237
+ const $ = yt(i);
238
+ if (S.some((h) => i.includes(h))) return;
239
+ await Promise.all($.map((h) => d(o(i, h))));
240
+ } else if (b.isFile() && X(i)) {
241
+ const g = await tt(t, i, a);
242
+ Object.entries(g).forEach(([h, f]) => {
242
243
  f.isKeyframes ? n.keyframes.push({
243
244
  value: f,
244
- src: a,
245
- name: b
245
+ src: i,
246
+ name: h
246
247
  }) : f.isMedia ? n.mediaQueries.push(f) : f.isGlobalDefine ? n.globalStyles.push(f) : f.isDefineVariables ? n.variables.push(f) : f.isDefineTemplates ? n.templates.push(f) : f.generator && n.components.push({
247
248
  value: f.generator,
248
- src: a,
249
- name: b
249
+ src: i,
250
+ name: h
250
251
  });
251
252
  });
252
253
  }
253
254
  }
254
255
  await d(t), await Nt(t, n);
255
256
  const u = await et(t);
256
- for (const a of n.keyframes) {
257
- const { value: w } = a, h = `a_${w.animationName}.css`, $ = `css/${h}`, g = o(r, $);
258
- l.push(h), x(g, w.css);
257
+ for (const i of n.keyframes) {
258
+ const { value: S } = i, b = `a_${S.animationName}.css`, $ = `css/${b}`, g = o(a, $);
259
+ l.push(b), x(g, S.css);
259
260
  }
260
261
  const m = {};
261
- for (const a of n.components) {
262
- const { value: w, name: h, src: $ } = a, g = w._withBuildContext({
263
- name: h,
262
+ for (const i of n.components) {
263
+ const { value: S, name: b, src: $ } = i, g = S._withBuildContext({
264
+ name: b,
264
265
  config: u,
265
266
  prod: e
266
267
  });
267
- i[g.priority] || (i[g.priority] = []), i[g.priority].push(g.cssFileName), u.importStrategy === "component" && (m[$] ? m[$].push(g.cssFileName) : m[$] = [g.cssFileName]);
268
- const b = `css/${g.cssFileName}`, f = o(r, b);
268
+ r[g.priority] || (r[g.priority] = []), r[g.priority].push(g.cssFileName), u.importStrategy === "component" && (m[$] ? m[$].push(g.cssFileName) : m[$] = [g.cssFileName]);
269
+ const h = `css/${g.cssFileName}`, f = o(a, h);
269
270
  x(f, g.css);
270
271
  }
271
- u.importStrategy === "component" && Object.entries(m).forEach(([a, w]) => {
272
- const h = w.map((W) => `@import url('./${W}');`).join(`
273
- `), $ = H(a, 6), g = q(a), b = K(g.name), f = o(r, `css/f_${b}-${$}.css`);
274
- x(f, h);
272
+ u.importStrategy === "component" && Object.entries(m).forEach(([i, S]) => {
273
+ const b = S.map((I) => `@import url('./${I}');`).join(`
274
+ `), $ = H(i, 6), g = q(i), h = K(g.name), f = o(a, `css/f_${h}-${$}.css`);
275
+ x(f, b);
275
276
  });
276
- const j = l.map((a) => `@import url('./css/${a}');`).join(`
277
+ const j = l.map((i) => `@import url('./css/${i}');`).join(`
277
278
  `);
278
279
  let D = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
279
280
 
280
- ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
281
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((i) => {
281
282
  try {
282
- return v(o(r, "css", a), "utf8").length > 0;
283
+ return v(o(a, "css", i), "utf8").length > 0;
283
284
  } catch {
284
285
  return !1;
285
286
  }
286
- }).map((a) => `@import url('./css/${a}');`).join(`
287
+ }).map((i) => `@import url('./css/${i}');`).join(`
287
288
  `)}
288
289
  ${j}`;
289
290
  if (u.importStrategy !== "component") {
290
- const a = i.reduce((w, h, $) => {
291
- const g = h.reduce((I, C) => {
292
- var O;
293
- const S = o(r, "css", C), T = v(S, "utf8"), F = ((O = /.*-([^-]+)-\d+.css/.exec(C)) == null ? void 0 : O.at(1)) || H(S, 6);
294
- return I.includes(F) ? I : `${I}
291
+ const i = r.reduce((S, b, $) => {
292
+ const g = b.reduce((G, C) => {
293
+ var J;
294
+ const w = o(a, "css", C), T = v(w, "utf8"), F = ((J = /.*-([^-]+)-\d+.css/.exec(C)) == null ? void 0 : J.at(1)) || H(w, 6);
295
+ return G.includes(F) ? G : `${G}
295
296
  /*start:${F}*/
296
297
  ${T}
297
298
  /*end:${F}*/
298
299
  `;
299
- }, ""), b = `l_${$}.css`, f = o(r, "css", b), W = `@layer l${$} { ${g}
300
+ }, ""), h = `l_${$}.css`, f = o(a, "css", h), I = `@layer l${$} { ${g}
300
301
  }`;
301
- return x(f, W), `${w}
302
- @import url('./css/${b}');`;
302
+ return x(f, I), `${S}
303
+ @import url('./css/${h}');`;
303
304
  }, "");
304
- D += a;
305
+ D += i;
305
306
  }
306
307
  x(y, D);
307
- const N = Date.now() - c, M = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
308
- B.info(`Generated CSS in ${N}ms! ${M}`);
308
+ const N = Date.now() - c, O = N < 200 ? "🔥" : N < 500 ? "🚀" : N < 1e3 ? "🎉" : N < 2e3 ? "🚗" : N < 5e3 ? "🤔" : "🥴";
309
+ B.info(`Generated CSS in ${N}ms! ${O}`);
309
310
  } catch (c) {
310
311
  console.error(c);
311
312
  }
312
- }, Wt = async (t, e) => {
313
+ }, It = async (t, e) => {
313
314
  try {
314
- const s = await z(t);
315
+ const s = await _(t);
315
316
  if (X(e)) {
316
- const l = [], i = await et(t), r = await tt(t, e, s);
317
- Object.entries(r).forEach(([y, p]) => {
317
+ const l = [], r = await et(t), a = await tt(t, e, s);
318
+ Object.entries(a).forEach(([y, p]) => {
318
319
  if (p.isKeyframes && p.css) {
319
320
  const j = `css/${`a_${p.animationName}.css`}`, k = o(s, j);
320
321
  x(k, p.css);
@@ -323,22 +324,22 @@ ${T}
323
324
  if (!p.generator) return;
324
325
  const n = p.generator._withBuildContext({
325
326
  name: y,
326
- config: i
327
+ config: r
327
328
  }), d = `css/${n.cssFileName}`, u = o(s, d);
328
329
  x(u, n.css), l[n.priority] || (l[n.priority] = []), l[n.priority].push(n.cssFileName);
329
- }), i.importStrategy !== "component" && l.forEach((y, p) => {
330
+ }), r.importStrategy !== "component" && l.forEach((y, p) => {
330
331
  const n = `l_${p}.css`, d = o(s, "css", n);
331
332
  let u = v(d, "utf8");
332
333
  y.forEach((m) => {
333
334
  var P;
334
335
  const j = o(s, "css", m), k = ((P = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : P.at(1)) || H(j, 6);
335
336
  if (!u.includes(k)) {
336
- const D = v(j, "utf8"), _ = `/*start:${k}*/
337
+ const D = v(j, "utf8"), M = `/*start:${k}*/
337
338
  ${D}
338
339
  /*end:${k}*/
339
340
  `;
340
341
  u = `${u.replace(/\}$/, "")}
341
- ${_}
342
+ ${M}
342
343
  }`;
343
344
  }
344
345
  }), x(d, u);
@@ -347,37 +348,37 @@ ${_}
347
348
  } catch (s) {
348
349
  console.error(s);
349
350
  }
350
- }, It = async (t, e, s = dt()) => {
351
+ }, Gt = async (t, e, s = dt()) => {
351
352
  try {
352
- const c = await z(t);
353
+ const c = await _(t);
353
354
  if (X(e)) {
354
- const i = v(e, "utf8");
355
- i.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== i && await ht(e, i);
355
+ const r = v(e, "utf8");
356
+ r.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== r && await ht(e, r);
356
357
  const y = await et(t), p = await tt(t, e, c);
357
- let n = i;
358
+ let n = r;
358
359
  if (Object.entries(p).forEach(([d, u]) => {
359
- var b;
360
+ var h;
360
361
  if (u.isKeyframes || !u.generator) return;
361
362
  const m = u.generator._withBuildContext({
362
363
  name: d,
363
364
  config: y,
364
365
  prod: s
365
- }), j = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
366
+ }), j = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
366
367
  if (!j) return console.error("Could not find the original declaration");
367
- const k = (b = j.at(1)) == null ? void 0 : b.trim(), V = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(n);
368
+ const k = (h = j.at(1)) == null ? void 0 : h.trim(), V = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(n);
368
369
  if (!V) return console.error("Could not find the original declaration");
369
370
  const { index: P } = V;
370
371
  let D = !1;
371
- const _ = setTimeout(() => D = !0, 5e3);
372
- let N = 0, M = !1, a = 0;
373
- for (; !M && !D; ) {
372
+ const M = setTimeout(() => D = !0, 5e3);
373
+ let N = 0, O = !1, i = 0;
374
+ for (; !O && !D; ) {
374
375
  const f = n[P + N];
375
- f === "(" && a++, f === ")" && a--, a === 0 && f === ")" && (M = !0), N > n.length && (D = !0), N++;
376
+ f === "(" && i++, f === ")" && i--, i === 0 && f === ")" && (O = !0), N > n.length && (D = !0), N++;
376
377
  }
377
- if (!D) clearTimeout(_);
378
+ if (!D) clearTimeout(M);
378
379
  else throw new Error("Failed to find the end of the styled call and timed out");
379
- const w = P + N, h = n.slice(P, w), $ = n, g = ` ${d} = styled(${k}, "${m.classNames}", ${JSON.stringify(m.props)});`;
380
- n = n.replace(h, g), $ === n && console.error("Minimize file failed to change content", { name: d, tagName: k });
380
+ const S = P + N, b = n.slice(P, S), $ = n, g = ` ${d} = styled(${k}, "${m.classNames}", ${JSON.stringify(m.props)});`;
381
+ n = n.replace(b, g), $ === n && console.error("Minimize file failed to change content", { name: d, tagName: k });
381
382
  }), y.importStrategy === "component") {
382
383
  const d = H(e, 6), u = q(e);
383
384
  n = `import '../../saltygen/css/${`f_${K(u.name)}-${d}.css`}';
@@ -390,14 +391,14 @@ ${n}`;
390
391
  }
391
392
  };
392
393
  export {
393
- Rt as a,
394
+ zt as a,
394
395
  kt as b,
395
396
  Nt as c,
396
397
  tt as d,
397
- Wt as e,
398
- zt as g,
398
+ It as e,
399
+ Wt as g,
399
400
  X as i,
400
401
  B as l,
401
- It as m,
402
+ Gt as m,
402
403
  ft as s
403
404
  };
@@ -0,0 +1,29 @@
1
+ "use strict";const ue=require("esbuild"),ye=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),o=require("path"),i=require("fs"),Q=require("fs/promises"),A=require("./parse-styles-3zK35muR.cjs"),te=require("./parse-templates-VIvmVb52.cjs"),I=require("winston"),z=require("./merge-DxGoJDHv.cjs");var U=typeof document<"u"?document.currentScript:null;function ge(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ne=ge(ue),oe=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return i.existsSync(t)?t:oe(o.join(e,".."))},me=async e=>{const t=oe(e);return await Q.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},he=async e=>{const t=await me(e);if(t)return t.type};let J;const ie=async e=>{if(J)return J;const t=await he(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:U&&U.tagName.toUpperCase()==="SCRIPT"&&U.src||new URL("index-zPXqhZf1.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},W=I.createLogger({level:"debug",format:I.format.combine(I.format.colorize(),I.format.cli()),transports:[new I.transports.Console({})]}),Se=e=>{W.error(e)};function re(e){return e?typeof e!="string"?re(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const be={"*, *::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"}},E={externalModules:[],rcFile:void 0,destDir:void 0},ce=e=>{if(E.externalModules.length>0)return E.externalModules;const s=i.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const r=s[1].split(",").map(f=>f.replace(/['"`]/g,"").trim());return E.externalModules=r,r},M=async e=>{if(E.destDir)return E.destDir;const t=await Y(e),s=o.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},X=["salty","css","styles","styled"],ae=(e=[])=>new RegExp(`\\.(${[...X,...e].join("|")})\\.`),G=(e,t=[])=>ae(t).test(e),le=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=o.join(e,".saltyrc.json"),s=await Q.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):le(o.join(e,".."))},Y=async e=>{var r,f;const t=await le(e),s=(r=t.projects)==null?void 0:r.find(c=>e.endsWith(c.dir||""));return s||((f=t.projects)==null?void 0:f.find(c=>c.dir===t.defaultProject))},we=async e=>{const t=await Y(e),s=await M(e),r=o.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),f=o.join(s,"salty.config.js"),c=await ie(e),a=ce(r);await ne.build({entryPoints:[r],minify:!0,treeShaking:!0,bundle:!0,outfile:f,format:c,external:a});const h=Date.now(),{config:p}=await import(`${f}?t=${h}`);return p},fe=async(e,t)=>{const s=await we(e),r={...s},f=new Set,c=($,j=[])=>$?Object.entries($).flatMap(([T,C])=>{if(!C)return;if(typeof C=="object")return c(C,[...j,T]);const R=re(T),B=_.dashCase(T),K=[...j,R].join(".");f.add(`"${K}"`);const Z=[...j.map(_.dashCase),B].join("-"),{result:pe}=A.parseValueTokens(C);return`--${Z}: ${pe};`}):[],a=$=>$?Object.entries($).flatMap(([j,T])=>{const C=c(T);return j==="base"?C.join(""):`${j} { ${C.join("")} }`}):[],h=$=>$?Object.entries($).flatMap(([j,T])=>Object.entries(T).flatMap(([C,R])=>{const B=c(R,[j]),K=`.${j}-${C}, [data-${j}="${C}"]`,Z=B.join("");return`${K} { ${Z} }`})):[],p=$=>t.variables.map(j=>j._current[$]),n=c(z.mergeStyles(s.variables,p("variables"))),u=a(z.mergeStyles(s.responsiveVariables,p("responsiveVariables"))),y=h(z.mergeStyles(s.conditionalVariables,p("conditionalVariables"))),g=await M(e),x=o.join(g,"css/_variables.css"),k=`:root { ${n.join("")} ${u.join("")} } ${y.join("")}`;i.writeFileSync(x,k);const v=o.join(g,"css/_global.css"),P=z.mergeStyles(s.global,t.globalStyles),D=A.parseStyles(P,"");i.writeFileSync(v,`@layer global { ${D} }`);const O=o.join(g,"css/_reset.css"),V=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:be,l=A.parseStyles(V,"");i.writeFileSync(O,`@layer reset { ${l} }`);const F=o.join(g,"css/_templates.css"),b=z.mergeStyles(s.templates,t.templates),w=te.parseTemplates(b),m=te.getTemplateTypes(b);i.writeFileSync(F,w),r.templates=b;const S=o.join(g,"types/css-tokens.d.ts"),q=`
2
+ // Variable types
3
+ type VariableTokens = ${[...f].join("|")};
4
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
5
+
6
+ // Template types
7
+ type TemplateTokens = {
8
+ ${Object.entries(m).map(([$,j])=>`${$}?: ${j}`).join(`
9
+ `)}
10
+ }
11
+ `;i.writeFileSync(S,q);const H=o.join(g,"cache/config-cache.json");i.writeFileSync(H,JSON.stringify(r,null,2))},se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const f=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!f.test(e))return t;const a=f.exec(e);if(a){const h=a.at(1);if(X.some(n=>h==null?void 0:h.includes(n)))return t}return"styled('div',"}),L=async(e,t,s)=>{const r=_.toHash(t),f=o.join(s,"./temp");i.existsSync(f)||i.mkdirSync(f);const c=o.parse(t);let a=i.readFileSync(t,"utf8");a=se(a);const h=o.join(s,"js",r+".js"),p=await Y(e),n=o.join(e,(p==null?void 0:p.configDir)||"","salty.config.ts"),u=ce(n),y=await ie(e);await ne.build({stdin:{contents:a,sourcefile:c.base,resolveDir:c.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:h,format:y,target:["node20"],keepNames:!0,external:u,packages:"external",plugins:[{name:"test",setup:k=>{k.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},v=>{const P=i.readFileSync(v.path,"utf8");return{contents:se(P),loader:"ts"}})}}]});const g=Date.now();return await import(`${h}?t=${g}`)},je=async e=>{const t=await M(e),s=o.join(t,"cache/config-cache.json"),r=i.readFileSync(s,"utf8");if(!r)throw new Error("Could not find config cache file");return JSON.parse(r)},ee=async e=>{const t=await je(e),s=await M(e),r=o.join(s,"salty.config.js"),f=Date.now(),{config:c}=await import(`${r}?t=${f}`);return z.mergeStyles(c,t)},de=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Fe=async(e,t=de(),s=!0)=>{try{const r=Date.now();t?W.info("Generating CSS in production mode! 🔥"):W.info("Generating CSS in development mode! 🚀");const f=[],c=[],a=await M(e),h=o.join(a,"index.css");s&&(()=>{i.existsSync(a)&&ye.execSync("rm -rf "+a),i.mkdirSync(a,{recursive:!0}),i.mkdirSync(o.join(a,"css")),i.mkdirSync(o.join(a,"types")),i.mkdirSync(o.join(a,"js")),i.mkdirSync(o.join(a,"cache"))})();const n={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function u(l){const F=["node_modules","saltygen"],b=i.statSync(l);if(b.isDirectory()){const w=i.readdirSync(l);if(F.some(S=>l.includes(S)))return;await Promise.all(w.map(S=>u(o.join(l,S))))}else if(b.isFile()&&G(l)){const m=await L(e,l,a);Object.entries(m).forEach(([S,d])=>{d.isKeyframes?n.keyframes.push({value:d,src:l,name:S}):d.isMedia?n.mediaQueries.push(d):d.isGlobalDefine?n.globalStyles.push(d):d.isDefineVariables?n.variables.push(d):d.isDefineTemplates?n.templates.push(d):d.generator&&n.components.push({value:d.generator,src:l,name:S})})}}await u(e),await fe(e,n);const y=await ee(e);for(const l of n.keyframes){const{value:F}=l,b=`a_${F.animationName}.css`,w=`css/${b}`,m=o.join(a,w);f.push(b),i.writeFileSync(m,F.css)}const g={};for(const l of n.components){const{value:F,name:b,src:w}=l,m=F._withBuildContext({name:b,config:y,prod:t});c[m.priority]||(c[m.priority]=[]),c[m.priority].push(m.cssFileName),y.importStrategy==="component"&&(g[w]?g[w].push(m.cssFileName):g[w]=[m.cssFileName]);const S=`css/${m.cssFileName}`,d=o.join(a,S);i.writeFileSync(d,m.css)}y.importStrategy==="component"&&Object.entries(g).forEach(([l,F])=>{const b=F.map(q=>`@import url('./${q}');`).join(`
12
+ `),w=_.toHash(l,6),m=o.parse(l),S=_.dashCase(m.name),d=o.join(a,`css/f_${S}-${w}.css`);i.writeFileSync(d,b)});const x=f.map(l=>`@import url('./css/${l}');`).join(`
13
+ `);let D=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
14
+
15
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return i.readFileSync(o.join(a,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
16
+ `)}
17
+ ${x}`;if(y.importStrategy!=="component"){const l=c.reduce((F,b,w)=>{const m=b.reduce((H,$)=>{var R;const j=o.join(a,"css",$),T=i.readFileSync(j,"utf8"),C=((R=/.*-([^-]+)-\d+.css/.exec($))==null?void 0:R.at(1))||_.toHash(j,6);return H.includes(C)?H:`${H}
18
+ /*start:${C}*/
19
+ ${T}
20
+ /*end:${C}*/
21
+ `},""),S=`l_${w}.css`,d=o.join(a,"css",S),q=`@layer l${w} { ${m}
22
+ }`;return i.writeFileSync(d,q),`${F}
23
+ @import url('./css/${S}');`},"");D+=l}i.writeFileSync(h,D);const N=Date.now()-r,V=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";W.info(`Generated CSS in ${N}ms! ${V}`)}catch(r){console.error(r)}},$e=async(e,t)=>{try{const s=await M(e);if(G(t)){const f=[],c=await ee(e),a=await L(e,t,s);Object.entries(a).forEach(([h,p])=>{if(p.isKeyframes&&p.css){const x=`css/${`a_${p.animationName}.css`}`,k=o.join(s,x);i.writeFileSync(k,p.css);return}if(!p.generator)return;const n=p.generator._withBuildContext({name:h,config:c}),u=`css/${n.cssFileName}`,y=o.join(s,u);i.writeFileSync(y,n.css),f[n.priority]||(f[n.priority]=[]),f[n.priority].push(n.cssFileName)}),c.importStrategy!=="component"&&f.forEach((h,p)=>{const n=`l_${p}.css`,u=o.join(s,"css",n);let y=i.readFileSync(u,"utf8");h.forEach(g=>{var P;const x=o.join(s,"css",g),k=((P=/.*-([^-]+)-\d+.css/.exec(g))==null?void 0:P.at(1))||_.toHash(x,6);if(!y.includes(k)){const D=i.readFileSync(x,"utf8"),O=`/*start:${k}*/
24
+ ${D}
25
+ /*end:${k}*/
26
+ `;y=`${y.replace(/\}$/,"")}
27
+ ${O}
28
+ }`}}),i.writeFileSync(u,y)})}}catch(s){console.error(s)}},Ce=async(e,t,s=de())=>{try{const r=await M(e);if(G(t)){const c=i.readFileSync(t,"utf8");c.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==c&&await Q.writeFile(t,c);const h=await ee(e),p=await L(e,t,r);let n=c;if(Object.entries(p).forEach(([u,y])=>{var S;if(y.isKeyframes||!y.generator)return;const g=y.generator._withBuildContext({name:u,config:h,prod:s}),x=new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(c);if(!x)return console.error("Could not find the original declaration");const k=(S=x.at(1))==null?void 0:S.trim(),v=new RegExp(`\\s${u}[=\\s]+styled\\(`,"g").exec(n);if(!v)return console.error("Could not find the original declaration");const{index:P}=v;let D=!1;const O=setTimeout(()=>D=!0,5e3);let N=0,V=!1,l=0;for(;!V&&!D;){const d=n[P+N];d==="("&&l++,d===")"&&l--,l===0&&d===")"&&(V=!0),N>n.length&&(D=!0),N++}if(!D)clearTimeout(O);else throw new Error("Failed to find the end of the styled call and timed out");const F=P+N,b=n.slice(P,F),w=n,m=` ${u} = styled(${k}, "${g.classNames}", ${JSON.stringify(g.props)});`;n=n.replace(b,m),w===n&&console.error("Minimize file failed to change content",{name:u,tagName:k})}),h.importStrategy==="component"){const u=_.toHash(t,6),y=o.parse(t);n=`import '../../saltygen/css/${`f_${_.dashCase(y.name)}-${u}.css`}';
29
+ ${n}`}return n=n.replace("{ styled }","{ styledClient as styled }"),n=n.replace("@salty-css/react/styled","@salty-css/react/styled-client"),n}}catch(r){console.error("Error in minimizeFile:",r)}};exports.compileSaltyFile=L;exports.generateConfigStyles=fe;exports.generateCss=Fe;exports.generateFile=$e;exports.isSaltyFile=G;exports.logError=Se;exports.logger=W;exports.minimizeFile=Ce;exports.saltyFileExtensions=X;exports.saltyFileRegExp=ae;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.180",
3
+ "version": "0.0.1-alpha.181",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
package/server/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-neHUpjdt.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)};exports.checkShouldRestart=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-zPXqhZf1.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)};exports.checkShouldRestart=i;
package/server/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile as r } from "fs/promises";
2
- import { i as e } from "../index-9iO5zogY.js";
2
+ import { i as e } from "../index-BjclEscx.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;
@@ -1,29 +0,0 @@
1
- "use strict";const ue=require("esbuild"),ye=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),o=require("path"),r=require("fs"),Q=require("fs/promises"),A=require("./parse-styles-3zK35muR.cjs"),te=require("./parse-templates-VIvmVb52.cjs"),H=require("winston"),I=require("./merge-DxGoJDHv.cjs");var U=typeof document<"u"?document.currentScript:null;function ge(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ne=ge(ue),oe=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=o.join(e,"package.json");return r.existsSync(t)?t:oe(o.join(e,".."))},me=async e=>{const t=oe(e);return await Q.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},he=async e=>{const t=await me(e);if(t)return t.type};let R;const re=async e=>{if(R)return R;const t=await he(e);return t==="module"?R="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:U&&U.tagName.toUpperCase()==="SCRIPT"&&U.src||new URL("index-neHUpjdt.cjs",document.baseURI).href).endsWith(".cjs"))&&(R="cjs"),R||"esm"},W=H.createLogger({level:"debug",format:H.format.combine(H.format.colorize(),H.format.cli()),transports:[new H.transports.Console({})]}),Se=e=>{W.error(e)};function ie(e){return e?typeof e!="string"?ie(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const be={"*, *::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"}},E={externalModules:[],rcFile:void 0,destDir:void 0},ae=e=>{if(E.externalModules.length>0)return E.externalModules;const s=r.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const i=s[1].split(",").map(f=>f.replace(/['"`]/g,"").trim());return E.externalModules=i,i},J=async e=>{if(E.destDir)return E.destDir;const t=await Y(e),s=o.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},X=["salty","css","styles","styled"],ce=(e=[])=>new RegExp(`\\.(${[...X,...e].join("|")})\\.`),G=(e,t=[])=>ce(t).test(e),le=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=o.join(e,".saltyrc.json"),s=await Q.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):le(o.join(e,".."))},Y=async e=>{var i,f;const t=await le(e),s=(i=t.projects)==null?void 0:i.find(l=>e.endsWith(l.dir||""));return s||((f=t.projects)==null?void 0:f.find(l=>l.dir===t.defaultProject))},je=async e=>{const t=await Y(e),s=await J(e),i=o.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),f=o.join(s,"salty.config.js"),l=await re(e),a=ae(i);await ne.build({entryPoints:[i],minify:!0,treeShaking:!0,bundle:!0,outfile:f,format:l,external:a});const h=Date.now(),{config:p}=await import(`${f}?t=${h}`);return p},fe=async(e,t)=>{const s=await je(e),i={...s},f=new Set,l=($,w=[])=>$?Object.entries($).flatMap(([T,C])=>{if(!C)return;if(typeof C=="object")return l(C,[...w,T]);const V=ie(T),B=_.dashCase(T),K=[...w,V].join(".");f.add(`"${K}"`);const Z=[...w.map(_.dashCase),B].join("-"),{result:pe}=A.parseValueTokens(C);return`--${Z}: ${pe};`}):[],a=$=>$?Object.entries($).flatMap(([w,T])=>{const C=l(T);return w==="base"?C.join(""):`${w} { ${C.join("")} }`}):[],h=$=>$?Object.entries($).flatMap(([w,T])=>Object.entries(T).flatMap(([C,V])=>{const B=l(V,[w]),K=`.${w}-${C}, [data-${w}="${C}"]`,Z=B.join("");return`${K} { ${Z} }`})):[],p=$=>t.variables.map(w=>w._current[$]),n=l(I.mergeStyles(s.variables,p("variables"))),u=a(I.mergeStyles(s.responsiveVariables,p("responsiveVariables"))),y=h(I.mergeStyles(s.conditionalVariables,p("conditionalVariables"))),g=await J(e),x=o.join(g,"css/_variables.css"),k=`:root { ${n.join("")} ${u.join("")} } ${y.join("")}`;r.writeFileSync(x,k);const v=o.join(g,"css/_global.css"),P=I.mergeStyles(s.global,t.globalStyles),D=A.parseStyles(P,"");r.writeFileSync(v,`@layer global { ${D} }`);const M=o.join(g,"css/_reset.css"),O=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:be,c=A.parseStyles(O,"");r.writeFileSync(M,`@layer reset { ${c} }`);const F=o.join(g,"css/_templates.css"),S=I.mergeStyles(s.templates,t.templates);console.log("all",S);const j=te.parseTemplates(S),m=te.getTemplateTypes(S);r.writeFileSync(F,j),i.templates=S;const b=o.join(g,"types/css-tokens.d.ts"),z=`
2
- // Variable types
3
- type VariableTokens = ${[...f].join("|")};
4
- type PropertyValueToken = \`{\${VariableTokens}}\`;
5
-
6
- // Template types
7
- type TemplateTokens = {
8
- ${Object.entries(m).map(([$,w])=>`${$}?: ${w}`).join(`
9
- `)}
10
- }
11
- `;r.writeFileSync(b,z);const q=o.join(g,"cache/config-cache.json");r.writeFileSync(q,JSON.stringify(i,null,2))},se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const f=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!f.test(e))return t;const a=f.exec(e);if(a){const h=a.at(1);if(X.some(n=>h==null?void 0:h.includes(n)))return t}return"styled('div',"}),L=async(e,t,s)=>{const i=_.toHash(t),f=o.join(s,"./temp");r.existsSync(f)||r.mkdirSync(f);const l=o.parse(t);let a=r.readFileSync(t,"utf8");a=se(a);const h=o.join(s,"js",i+".js"),p=await Y(e),n=o.join(e,(p==null?void 0:p.configDir)||"","salty.config.ts"),u=ae(n),y=await re(e);await ne.build({stdin:{contents:a,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:h,format:y,target:["node20"],keepNames:!0,external:u,packages:"external",plugins:[{name:"test",setup:k=>{k.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},v=>{const P=r.readFileSync(v.path,"utf8");return{contents:se(P),loader:"ts"}})}}]});const g=Date.now();return await import(`${h}?t=${g}`)},ee=async e=>{const t=await J(e),s=o.join(t,"cache/config-cache.json"),i=r.readFileSync(s,"utf8");if(!i)throw new Error("Could not find config cache file");return JSON.parse(i)},de=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},we=async(e,t=de(),s=!0)=>{try{const i=Date.now();t?W.info("Generating CSS in production mode! 🔥"):W.info("Generating CSS in development mode! 🚀");const f=[],l=[],a=await J(e),h=o.join(a,"index.css");s&&(()=>{r.existsSync(a)&&ye.execSync("rm -rf "+a),r.mkdirSync(a,{recursive:!0}),r.mkdirSync(o.join(a,"css")),r.mkdirSync(o.join(a,"types")),r.mkdirSync(o.join(a,"js")),r.mkdirSync(o.join(a,"cache"))})();const n={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function u(c){const F=["node_modules","saltygen"],S=r.statSync(c);if(S.isDirectory()){const j=r.readdirSync(c);if(F.some(b=>c.includes(b)))return;await Promise.all(j.map(b=>u(o.join(c,b))))}else if(S.isFile()&&G(c)){const m=await L(e,c,a);Object.entries(m).forEach(([b,d])=>{d.isKeyframes?n.keyframes.push({value:d,src:c,name:b}):d.isMedia?n.mediaQueries.push(d):d.isGlobalDefine?n.globalStyles.push(d):d.isDefineVariables?n.variables.push(d):d.isDefineTemplates?n.templates.push(d):d.generator&&n.components.push({value:d.generator,src:c,name:b})})}}await u(e),await fe(e,n);const y=await ee(e);for(const c of n.keyframes){const{value:F}=c,S=`a_${F.animationName}.css`,j=`css/${S}`,m=o.join(a,j);f.push(S),r.writeFileSync(m,F.css)}const g={};for(const c of n.components){const{value:F,name:S,src:j}=c,m=F._withBuildContext({name:S,config:y,prod:t});l[m.priority]||(l[m.priority]=[]),l[m.priority].push(m.cssFileName),y.importStrategy==="component"&&(g[j]?g[j].push(m.cssFileName):g[j]=[m.cssFileName]);const b=`css/${m.cssFileName}`,d=o.join(a,b);r.writeFileSync(d,m.css)}y.importStrategy==="component"&&Object.entries(g).forEach(([c,F])=>{const S=F.map(z=>`@import url('./${z}');`).join(`
12
- `),j=_.toHash(c,6),m=o.parse(c),b=_.dashCase(m.name),d=o.join(a,`css/f_${b}-${j}.css`);r.writeFileSync(d,S)});const x=f.map(c=>`@import url('./css/${c}');`).join(`
13
- `);let D=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
14
-
15
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return r.readFileSync(o.join(a,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
16
- `)}
17
- ${x}`;if(y.importStrategy!=="component"){const c=l.reduce((F,S,j)=>{const m=S.reduce((q,$)=>{var V;const w=o.join(a,"css",$),T=r.readFileSync(w,"utf8"),C=((V=/.*-([^-]+)-\d+.css/.exec($))==null?void 0:V.at(1))||_.toHash(w,6);return q.includes(C)?q:`${q}
18
- /*start:${C}*/
19
- ${T}
20
- /*end:${C}*/
21
- `},""),b=`l_${j}.css`,d=o.join(a,"css",b),z=`@layer l${j} { ${m}
22
- }`;return r.writeFileSync(d,z),`${F}
23
- @import url('./css/${b}');`},"");D+=c}r.writeFileSync(h,D);const N=Date.now()-i,O=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";W.info(`Generated CSS in ${N}ms! ${O}`)}catch(i){console.error(i)}},Fe=async(e,t)=>{try{const s=await J(e);if(G(t)){const f=[],l=await ee(e),a=await L(e,t,s);Object.entries(a).forEach(([h,p])=>{if(p.isKeyframes&&p.css){const x=`css/${`a_${p.animationName}.css`}`,k=o.join(s,x);r.writeFileSync(k,p.css);return}if(!p.generator)return;const n=p.generator._withBuildContext({name:h,config:l}),u=`css/${n.cssFileName}`,y=o.join(s,u);r.writeFileSync(y,n.css),f[n.priority]||(f[n.priority]=[]),f[n.priority].push(n.cssFileName)}),l.importStrategy!=="component"&&f.forEach((h,p)=>{const n=`l_${p}.css`,u=o.join(s,"css",n);let y=r.readFileSync(u,"utf8");h.forEach(g=>{var P;const x=o.join(s,"css",g),k=((P=/.*-([^-]+)-\d+.css/.exec(g))==null?void 0:P.at(1))||_.toHash(x,6);if(!y.includes(k)){const D=r.readFileSync(x,"utf8"),M=`/*start:${k}*/
24
- ${D}
25
- /*end:${k}*/
26
- `;y=`${y.replace(/\}$/,"")}
27
- ${M}
28
- }`}}),r.writeFileSync(u,y)})}}catch(s){console.error(s)}},$e=async(e,t,s=de())=>{try{const i=await J(e);if(G(t)){const l=r.readFileSync(t,"utf8");l.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==l&&await Q.writeFile(t,l);const h=await ee(e),p=await L(e,t,i);let n=l;if(Object.entries(p).forEach(([u,y])=>{var b;if(y.isKeyframes||!y.generator)return;const g=y.generator._withBuildContext({name:u,config:h,prod:s}),x=new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(l);if(!x)return console.error("Could not find the original declaration");const k=(b=x.at(1))==null?void 0:b.trim(),v=new RegExp(`\\s${u}[=\\s]+styled\\(`,"g").exec(n);if(!v)return console.error("Could not find the original declaration");const{index:P}=v;let D=!1;const M=setTimeout(()=>D=!0,5e3);let N=0,O=!1,c=0;for(;!O&&!D;){const d=n[P+N];d==="("&&c++,d===")"&&c--,c===0&&d===")"&&(O=!0),N>n.length&&(D=!0),N++}if(!D)clearTimeout(M);else throw new Error("Failed to find the end of the styled call and timed out");const F=P+N,S=n.slice(P,F),j=n,m=` ${u} = styled(${k}, "${g.classNames}", ${JSON.stringify(g.props)});`;n=n.replace(S,m),j===n&&console.error("Minimize file failed to change content",{name:u,tagName:k})}),h.importStrategy==="component"){const u=_.toHash(t,6),y=o.parse(t);n=`import '../../saltygen/css/${`f_${_.dashCase(y.name)}-${u}.css`}';
29
- ${n}`}return n=n.replace("{ styled }","{ styledClient as styled }"),n=n.replace("@salty-css/react/styled","@salty-css/react/styled-client"),n}}catch(i){console.error("Error in minimizeFile:",i)}};exports.compileSaltyFile=L;exports.generateConfigStyles=fe;exports.generateCss=we;exports.generateFile=Fe;exports.isSaltyFile=G;exports.logError=Se;exports.logger=W;exports.minimizeFile=$e;exports.saltyFileExtensions=X;exports.saltyFileRegExp=ce;