@kbach/react 0.5.32 → 0.5.33

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.
@@ -3384,9 +3384,8 @@ function formatKbachCSS(tokenCSS, theme) {
3384
3384
  const allRaw = [...tokenCSS.values()].filter(Boolean).join("\n");
3385
3385
  const colorVars = buildColorVarMap(theme, allRaw);
3386
3386
  function applyVars(css) {
3387
- for (const [val, varName] of colorVars) {
3387
+ for (const [val, varName] of colorVars)
3388
3388
  css = css.split(val).join(`var(${varName})`);
3389
- }
3390
3389
  return css;
3391
3390
  }
3392
3391
  const groups = new Map(GROUP_ORDER.map((g) => [g, []]));
@@ -3399,17 +3398,13 @@ function formatKbachCSS(tokenCSS, theme) {
3399
3398
  const out = ["/* Generated by Kbach \u2014 do not edit */"];
3400
3399
  if (colorVars.size > 0) {
3401
3400
  out.push("\n:root {");
3402
- for (const [val, varName] of colorVars) {
3403
- out.push(` ${varName}: ${val};`);
3404
- }
3401
+ for (const [val, varName] of colorVars) out.push(` ${varName}: ${val};`);
3405
3402
  out.push("}");
3406
3403
  }
3407
3404
  const globalCSS = buildThemeGlobal(theme);
3408
- if (globalCSS) {
3409
- out.push(`
3405
+ if (globalCSS) out.push(`
3410
3406
  /* Global */
3411
3407
  ${globalCSS}`);
3412
- }
3413
3408
  for (const label of GROUP_ORDER) {
3414
3409
  const items = groups.get(label) ?? [];
3415
3410
  if (!items.length) continue;
@@ -3459,7 +3454,6 @@ function toNumericScreens(screens) {
3459
3454
  }
3460
3455
  return out;
3461
3456
  }
3462
- var normPath = (p) => p.split("\\").join("/");
3463
3457
  function scanDir(dir, onFile) {
3464
3458
  try {
3465
3459
  for (const entry of (0, import_fs.readdirSync)(dir)) {
@@ -3468,7 +3462,7 @@ function scanDir(dir, onFile) {
3468
3462
  try {
3469
3463
  const st = (0, import_fs.statSync)(full);
3470
3464
  if (st.isDirectory()) scanDir(full, onFile);
3471
- else if (/\.(tsx?|jsx?)$/.test(entry)) onFile((0, import_fs.readFileSync)(full, "utf-8"), normPath(full));
3465
+ else if (/\.(tsx?|jsx?)$/.test(entry)) onFile((0, import_fs.readFileSync)(full, "utf-8"));
3472
3466
  } catch {
3473
3467
  }
3474
3468
  }
@@ -3488,37 +3482,20 @@ function extractClassStrings(code) {
3488
3482
  function kbach(userConfig) {
3489
3483
  const cfg = buildConfig(userConfig ?? {});
3490
3484
  const screens = toNumericScreens(cfg.theme.screens ?? {});
3491
- const fileTokens = /* @__PURE__ */ new Map();
3492
- const tokenCSS = /* @__PURE__ */ new Map();
3493
3485
  let root = process.cwd();
3494
3486
  let mainCSSFile = null;
3495
- function extractTokensFromCode(code) {
3496
- const tokens = /* @__PURE__ */ new Set();
3497
- for (const cls of extractClassStrings(code))
3498
- for (const token of cls.split(/\s+/).filter(Boolean))
3499
- tokens.add(token);
3500
- return tokens;
3501
- }
3502
- function rebuildTokenCSS() {
3503
- const live = /* @__PURE__ */ new Set();
3504
- for (const tokens of fileTokens.values())
3505
- for (const t of tokens) live.add(t);
3506
- let changed = false;
3507
- for (const token of tokenCSS.keys()) {
3508
- if (!live.has(token)) {
3509
- tokenCSS.delete(token);
3510
- changed = true;
3511
- }
3487
+ function generateCSS() {
3488
+ const tokenCSS = /* @__PURE__ */ new Map();
3489
+ for (const dir of ["src", "app", "pages", "components", "views", "layouts"]) {
3490
+ scanDir((0, import_path.join)(root, dir), (code) => {
3491
+ for (const cls of extractClassStrings(code))
3492
+ for (const token of cls.split(/\s+/).filter(Boolean))
3493
+ if (!tokenCSS.has(token)) {
3494
+ const css = generateClassCSS(token, cfg.theme, cfg.darkMode, screens);
3495
+ tokenCSS.set(token, css);
3496
+ }
3497
+ });
3512
3498
  }
3513
- for (const token of live) {
3514
- if (!tokenCSS.has(token)) {
3515
- tokenCSS.set(token, generateClassCSS(token, cfg.theme, cfg.darkMode, screens));
3516
- changed = true;
3517
- }
3518
- }
3519
- return changed;
3520
- }
3521
- function getFormattedCSS() {
3522
3499
  return formatKbachCSS(tokenCSS, cfg.theme);
3523
3500
  }
3524
3501
  return {
@@ -3528,19 +3505,12 @@ function kbach(userConfig) {
3528
3505
  root = resolved.root;
3529
3506
  },
3530
3507
  buildStart() {
3531
- for (const dir of ["src", "app", "pages", "components", "views", "layouts"])
3532
- scanDir((0, import_path.join)(root, dir), (code, filePath) => fileTokens.set(filePath, extractTokensFromCode(code)));
3533
- rebuildTokenCSS();
3534
3508
  mainCSSFile = findMainCSSFile(root);
3535
- if (mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
3509
+ if (mainCSSFile) writeKbachToFile(mainCSSFile, generateCSS());
3536
3510
  },
3537
3511
  handleHotUpdate({ file }) {
3538
3512
  if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
3539
- try {
3540
- fileTokens.set(normPath(file), extractTokensFromCode((0, import_fs.readFileSync)(file, "utf-8")));
3541
- if (rebuildTokenCSS() && mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
3542
- } catch {
3543
- }
3513
+ if (mainCSSFile) writeKbachToFile(mainCSSFile, generateCSS());
3544
3514
  }
3545
3515
  };
3546
3516
  }
@@ -43,9 +43,8 @@ function formatKbachCSS(tokenCSS, theme) {
43
43
  const allRaw = [...tokenCSS.values()].filter(Boolean).join("\n");
44
44
  const colorVars = buildColorVarMap(theme, allRaw);
45
45
  function applyVars(css) {
46
- for (const [val, varName] of colorVars) {
46
+ for (const [val, varName] of colorVars)
47
47
  css = css.split(val).join(`var(${varName})`);
48
- }
49
48
  return css;
50
49
  }
51
50
  const groups = new Map(GROUP_ORDER.map((g) => [g, []]));
@@ -58,17 +57,13 @@ function formatKbachCSS(tokenCSS, theme) {
58
57
  const out = ["/* Generated by Kbach \u2014 do not edit */"];
59
58
  if (colorVars.size > 0) {
60
59
  out.push("\n:root {");
61
- for (const [val, varName] of colorVars) {
62
- out.push(` ${varName}: ${val};`);
63
- }
60
+ for (const [val, varName] of colorVars) out.push(` ${varName}: ${val};`);
64
61
  out.push("}");
65
62
  }
66
63
  const globalCSS = buildThemeGlobal(theme);
67
- if (globalCSS) {
68
- out.push(`
64
+ if (globalCSS) out.push(`
69
65
  /* Global */
70
66
  ${globalCSS}`);
71
- }
72
67
  for (const label of GROUP_ORDER) {
73
68
  const items = groups.get(label) ?? [];
74
69
  if (!items.length) continue;
@@ -118,7 +113,6 @@ function toNumericScreens(screens) {
118
113
  }
119
114
  return out;
120
115
  }
121
- var normPath = (p) => p.split("\\").join("/");
122
116
  function scanDir(dir, onFile) {
123
117
  try {
124
118
  for (const entry of readdirSync(dir)) {
@@ -127,7 +121,7 @@ function scanDir(dir, onFile) {
127
121
  try {
128
122
  const st = statSync(full);
129
123
  if (st.isDirectory()) scanDir(full, onFile);
130
- else if (/\.(tsx?|jsx?)$/.test(entry)) onFile(readFileSync(full, "utf-8"), normPath(full));
124
+ else if (/\.(tsx?|jsx?)$/.test(entry)) onFile(readFileSync(full, "utf-8"));
131
125
  } catch {
132
126
  }
133
127
  }
@@ -147,37 +141,20 @@ function extractClassStrings(code) {
147
141
  function kbach(userConfig) {
148
142
  const cfg = buildConfig(userConfig ?? {});
149
143
  const screens = toNumericScreens(cfg.theme.screens ?? {});
150
- const fileTokens = /* @__PURE__ */ new Map();
151
- const tokenCSS = /* @__PURE__ */ new Map();
152
144
  let root = process.cwd();
153
145
  let mainCSSFile = null;
154
- function extractTokensFromCode(code) {
155
- const tokens = /* @__PURE__ */ new Set();
156
- for (const cls of extractClassStrings(code))
157
- for (const token of cls.split(/\s+/).filter(Boolean))
158
- tokens.add(token);
159
- return tokens;
160
- }
161
- function rebuildTokenCSS() {
162
- const live = /* @__PURE__ */ new Set();
163
- for (const tokens of fileTokens.values())
164
- for (const t of tokens) live.add(t);
165
- let changed = false;
166
- for (const token of tokenCSS.keys()) {
167
- if (!live.has(token)) {
168
- tokenCSS.delete(token);
169
- changed = true;
170
- }
146
+ function generateCSS() {
147
+ const tokenCSS = /* @__PURE__ */ new Map();
148
+ for (const dir of ["src", "app", "pages", "components", "views", "layouts"]) {
149
+ scanDir(join(root, dir), (code) => {
150
+ for (const cls of extractClassStrings(code))
151
+ for (const token of cls.split(/\s+/).filter(Boolean))
152
+ if (!tokenCSS.has(token)) {
153
+ const css = generateClassCSS(token, cfg.theme, cfg.darkMode, screens);
154
+ tokenCSS.set(token, css);
155
+ }
156
+ });
171
157
  }
172
- for (const token of live) {
173
- if (!tokenCSS.has(token)) {
174
- tokenCSS.set(token, generateClassCSS(token, cfg.theme, cfg.darkMode, screens));
175
- changed = true;
176
- }
177
- }
178
- return changed;
179
- }
180
- function getFormattedCSS() {
181
158
  return formatKbachCSS(tokenCSS, cfg.theme);
182
159
  }
183
160
  return {
@@ -187,19 +164,12 @@ function kbach(userConfig) {
187
164
  root = resolved.root;
188
165
  },
189
166
  buildStart() {
190
- for (const dir of ["src", "app", "pages", "components", "views", "layouts"])
191
- scanDir(join(root, dir), (code, filePath) => fileTokens.set(filePath, extractTokensFromCode(code)));
192
- rebuildTokenCSS();
193
167
  mainCSSFile = findMainCSSFile(root);
194
- if (mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
168
+ if (mainCSSFile) writeKbachToFile(mainCSSFile, generateCSS());
195
169
  },
196
170
  handleHotUpdate({ file }) {
197
171
  if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
198
- try {
199
- fileTokens.set(normPath(file), extractTokensFromCode(readFileSync(file, "utf-8")));
200
- if (rebuildTokenCSS() && mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
201
- } catch {
202
- }
172
+ if (mainCSSFile) writeKbachToFile(mainCSSFile, generateCSS());
203
173
  }
204
174
  };
205
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.5.32",
3
+ "version": "0.5.33",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",