@kbach/react 0.5.29 → 0.5.31

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.
@@ -1,7 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { F as FrameworkConfig } from './types-CV5vXnSH.mjs';
3
3
 
4
- declare const VIRTUAL_ID = "virtual:kbach/styles.css";
5
4
  declare function kbach(userConfig?: FrameworkConfig): Plugin;
6
5
 
7
- export { VIRTUAL_ID, kbach };
6
+ export { kbach };
@@ -1,7 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { F as FrameworkConfig } from './types-CV5vXnSH.js';
3
3
 
4
- declare const VIRTUAL_ID = "virtual:kbach/styles.css";
5
4
  declare function kbach(userConfig?: FrameworkConfig): Plugin;
6
5
 
7
- export { VIRTUAL_ID, kbach };
6
+ export { kbach };
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/vite-plugin.ts
21
21
  var vite_plugin_exports = {};
22
22
  __export(vite_plugin_exports, {
23
- VIRTUAL_ID: () => VIRTUAL_ID,
24
23
  kbach: () => kbach
25
24
  });
26
25
  module.exports = __toCommonJS(vite_plugin_exports);
@@ -3348,8 +3347,6 @@ var customVariants = new Proxy(
3348
3347
  );
3349
3348
 
3350
3349
  // src/vite-plugin.ts
3351
- var VIRTUAL_ID = "virtual:kbach/styles.css";
3352
- var RESOLVED_ID = "\0virtual:kbach/styles.css";
3353
3350
  var KBACH_START = "/* kbach:start */";
3354
3351
  var KBACH_END = "/* kbach:end */";
3355
3352
  var GROUPS = [
@@ -3470,7 +3467,7 @@ function scanDir(dir, onFile) {
3470
3467
  try {
3471
3468
  const st = (0, import_fs.statSync)(full);
3472
3469
  if (st.isDirectory()) scanDir(full, onFile);
3473
- else if (/\.(tsx?|jsx?)$/.test(entry)) onFile((0, import_fs.readFileSync)(full, "utf-8"));
3470
+ else if (/\.(tsx?|jsx?)$/.test(entry)) onFile((0, import_fs.readFileSync)(full, "utf-8"), full);
3474
3471
  } catch {
3475
3472
  }
3476
3473
  }
@@ -3490,20 +3487,35 @@ function extractClassStrings(code) {
3490
3487
  function kbach(userConfig) {
3491
3488
  const cfg = buildConfig(userConfig ?? {});
3492
3489
  const screens = toNumericScreens(cfg.theme.screens ?? {});
3490
+ const fileTokens = /* @__PURE__ */ new Map();
3493
3491
  const tokenCSS = /* @__PURE__ */ new Map();
3494
3492
  let root = process.cwd();
3495
3493
  let mainCSSFile = null;
3496
- function processToken(token) {
3497
- if (tokenCSS.has(token)) return false;
3498
- tokenCSS.set(token, generateClassCSS(token, cfg.theme, cfg.darkMode, screens));
3499
- return true;
3500
- }
3501
- function extractFromCode(code) {
3502
- let added = false;
3494
+ function extractTokensFromCode(code) {
3495
+ const tokens = /* @__PURE__ */ new Set();
3503
3496
  for (const cls of extractClassStrings(code))
3504
3497
  for (const token of cls.split(/\s+/).filter(Boolean))
3505
- if (processToken(token)) added = true;
3506
- return added;
3498
+ tokens.add(token);
3499
+ return tokens;
3500
+ }
3501
+ function rebuildTokenCSS() {
3502
+ const live = /* @__PURE__ */ new Set();
3503
+ for (const tokens of fileTokens.values())
3504
+ for (const t of tokens) live.add(t);
3505
+ let changed = false;
3506
+ for (const token of tokenCSS.keys()) {
3507
+ if (!live.has(token)) {
3508
+ tokenCSS.delete(token);
3509
+ changed = true;
3510
+ }
3511
+ }
3512
+ for (const token of live) {
3513
+ if (!tokenCSS.has(token)) {
3514
+ tokenCSS.set(token, generateClassCSS(token, cfg.theme, cfg.darkMode, screens));
3515
+ changed = true;
3516
+ }
3517
+ }
3518
+ return changed;
3507
3519
  }
3508
3520
  function getFormattedCSS() {
3509
3521
  return formatKbachCSS(tokenCSS, cfg.theme);
@@ -3516,26 +3528,16 @@ function kbach(userConfig) {
3516
3528
  },
3517
3529
  buildStart() {
3518
3530
  for (const dir of ["src", "app", "pages", "components", "views", "layouts"])
3519
- scanDir((0, import_path.join)(root, dir), (code) => extractFromCode(code));
3531
+ scanDir((0, import_path.join)(root, dir), (code, filePath) => fileTokens.set(filePath, extractTokensFromCode(code)));
3532
+ rebuildTokenCSS();
3520
3533
  mainCSSFile = findMainCSSFile(root);
3521
3534
  if (mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
3522
3535
  },
3523
- transform(code, id) {
3524
- const cleanId = id.split("?")[0];
3525
- if (/\.(tsx?|jsx?)$/.test(cleanId) && !id.includes("node_modules"))
3526
- extractFromCode(code);
3527
- },
3528
- resolveId(id) {
3529
- if (id === VIRTUAL_ID) return RESOLVED_ID;
3530
- },
3531
- load(id) {
3532
- if (id === RESOLVED_ID) return getFormattedCSS();
3533
- },
3534
3536
  handleHotUpdate({ file }) {
3535
3537
  if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
3536
3538
  try {
3537
- const added = extractFromCode((0, import_fs.readFileSync)(file, "utf-8"));
3538
- if (added && mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
3539
+ fileTokens.set(file, extractTokensFromCode((0, import_fs.readFileSync)(file, "utf-8")));
3540
+ if (rebuildTokenCSS() && mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
3539
3541
  } catch {
3540
3542
  }
3541
3543
  }
@@ -3543,6 +3545,5 @@ function kbach(userConfig) {
3543
3545
  }
3544
3546
  // Annotate the CommonJS export names for ESM import in node:
3545
3547
  0 && (module.exports = {
3546
- VIRTUAL_ID,
3547
3548
  kbach
3548
3549
  });
@@ -6,8 +6,6 @@ import {
6
6
  // src/vite-plugin.ts
7
7
  import { readFileSync, writeFileSync, existsSync, readdirSync, statSync } from "fs";
8
8
  import { join } from "path";
9
- var VIRTUAL_ID = "virtual:kbach/styles.css";
10
- var RESOLVED_ID = "\0virtual:kbach/styles.css";
11
9
  var KBACH_START = "/* kbach:start */";
12
10
  var KBACH_END = "/* kbach:end */";
13
11
  var GROUPS = [
@@ -128,7 +126,7 @@ function scanDir(dir, onFile) {
128
126
  try {
129
127
  const st = statSync(full);
130
128
  if (st.isDirectory()) scanDir(full, onFile);
131
- else if (/\.(tsx?|jsx?)$/.test(entry)) onFile(readFileSync(full, "utf-8"));
129
+ else if (/\.(tsx?|jsx?)$/.test(entry)) onFile(readFileSync(full, "utf-8"), full);
132
130
  } catch {
133
131
  }
134
132
  }
@@ -148,20 +146,35 @@ function extractClassStrings(code) {
148
146
  function kbach(userConfig) {
149
147
  const cfg = buildConfig(userConfig ?? {});
150
148
  const screens = toNumericScreens(cfg.theme.screens ?? {});
149
+ const fileTokens = /* @__PURE__ */ new Map();
151
150
  const tokenCSS = /* @__PURE__ */ new Map();
152
151
  let root = process.cwd();
153
152
  let mainCSSFile = null;
154
- function processToken(token) {
155
- if (tokenCSS.has(token)) return false;
156
- tokenCSS.set(token, generateClassCSS(token, cfg.theme, cfg.darkMode, screens));
157
- return true;
158
- }
159
- function extractFromCode(code) {
160
- let added = false;
153
+ function extractTokensFromCode(code) {
154
+ const tokens = /* @__PURE__ */ new Set();
161
155
  for (const cls of extractClassStrings(code))
162
156
  for (const token of cls.split(/\s+/).filter(Boolean))
163
- if (processToken(token)) added = true;
164
- return added;
157
+ tokens.add(token);
158
+ return tokens;
159
+ }
160
+ function rebuildTokenCSS() {
161
+ const live = /* @__PURE__ */ new Set();
162
+ for (const tokens of fileTokens.values())
163
+ for (const t of tokens) live.add(t);
164
+ let changed = false;
165
+ for (const token of tokenCSS.keys()) {
166
+ if (!live.has(token)) {
167
+ tokenCSS.delete(token);
168
+ changed = true;
169
+ }
170
+ }
171
+ for (const token of live) {
172
+ if (!tokenCSS.has(token)) {
173
+ tokenCSS.set(token, generateClassCSS(token, cfg.theme, cfg.darkMode, screens));
174
+ changed = true;
175
+ }
176
+ }
177
+ return changed;
165
178
  }
166
179
  function getFormattedCSS() {
167
180
  return formatKbachCSS(tokenCSS, cfg.theme);
@@ -174,32 +187,21 @@ function kbach(userConfig) {
174
187
  },
175
188
  buildStart() {
176
189
  for (const dir of ["src", "app", "pages", "components", "views", "layouts"])
177
- scanDir(join(root, dir), (code) => extractFromCode(code));
190
+ scanDir(join(root, dir), (code, filePath) => fileTokens.set(filePath, extractTokensFromCode(code)));
191
+ rebuildTokenCSS();
178
192
  mainCSSFile = findMainCSSFile(root);
179
193
  if (mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
180
194
  },
181
- transform(code, id) {
182
- const cleanId = id.split("?")[0];
183
- if (/\.(tsx?|jsx?)$/.test(cleanId) && !id.includes("node_modules"))
184
- extractFromCode(code);
185
- },
186
- resolveId(id) {
187
- if (id === VIRTUAL_ID) return RESOLVED_ID;
188
- },
189
- load(id) {
190
- if (id === RESOLVED_ID) return getFormattedCSS();
191
- },
192
195
  handleHotUpdate({ file }) {
193
196
  if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
194
197
  try {
195
- const added = extractFromCode(readFileSync(file, "utf-8"));
196
- if (added && mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
198
+ fileTokens.set(file, extractTokensFromCode(readFileSync(file, "utf-8")));
199
+ if (rebuildTokenCSS() && mainCSSFile) writeKbachToFile(mainCSSFile, getFormattedCSS());
197
200
  } catch {
198
201
  }
199
202
  }
200
203
  };
201
204
  }
202
205
  export {
203
- VIRTUAL_ID,
204
206
  kbach
205
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.5.29",
3
+ "version": "0.5.31",
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",