@kbach/react 0.5.16 → 0.5.17
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/dist/vite-plugin.d.mts +5 -5
- package/dist/vite-plugin.d.ts +5 -5
- package/dist/vite-plugin.js +31 -24
- package/dist/vite-plugin.mjs +31 -24
- package/package.json +2 -2
package/dist/vite-plugin.d.mts
CHANGED
|
@@ -4,15 +4,15 @@ import { F as FrameworkConfig } from './types-CV5vXnSH.mjs';
|
|
|
4
4
|
/**
|
|
5
5
|
* @kbach/react/vite
|
|
6
6
|
*
|
|
7
|
-
* Vite plugin
|
|
8
|
-
*
|
|
7
|
+
* Vite plugin — scans your source files for Kbach className/kb props and
|
|
8
|
+
* appends the generated CSS to any CSS file already imported in your project.
|
|
9
|
+
*
|
|
10
|
+
* Zero setup beyond adding the plugin to vite.config.ts:
|
|
9
11
|
*
|
|
10
|
-
* Usage in vite.config.ts:
|
|
11
12
|
* import { kbach } from '@kbach/react/vite';
|
|
12
13
|
* plugins: [kbach()]
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
* import 'virtual:kbach/styles.css';
|
|
15
|
+
* CSS is only generated for the classes you actually use (like Tailwind).
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
declare const VIRTUAL_ID = "virtual:kbach/styles.css";
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -4,15 +4,15 @@ import { F as FrameworkConfig } from './types-CV5vXnSH.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* @kbach/react/vite
|
|
6
6
|
*
|
|
7
|
-
* Vite plugin
|
|
8
|
-
*
|
|
7
|
+
* Vite plugin — scans your source files for Kbach className/kb props and
|
|
8
|
+
* appends the generated CSS to any CSS file already imported in your project.
|
|
9
|
+
*
|
|
10
|
+
* Zero setup beyond adding the plugin to vite.config.ts:
|
|
9
11
|
*
|
|
10
|
-
* Usage in vite.config.ts:
|
|
11
12
|
* import { kbach } from '@kbach/react/vite';
|
|
12
13
|
* plugins: [kbach()]
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
* import 'virtual:kbach/styles.css';
|
|
15
|
+
* CSS is only generated for the classes you actually use (like Tailwind).
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
declare const VIRTUAL_ID = "virtual:kbach/styles.css";
|
package/dist/vite-plugin.js
CHANGED
|
@@ -3337,7 +3337,7 @@ var customVariants = new Proxy(
|
|
|
3337
3337
|
|
|
3338
3338
|
// src/vite-plugin.ts
|
|
3339
3339
|
var VIRTUAL_ID = "virtual:kbach/styles.css";
|
|
3340
|
-
var RESOLVED_ID = "\
|
|
3340
|
+
var RESOLVED_ID = "\0virtual:kbach/styles.css";
|
|
3341
3341
|
function toNumericScreens(screens) {
|
|
3342
3342
|
const out = {};
|
|
3343
3343
|
for (const [k, v] of Object.entries(screens)) {
|
|
@@ -3383,19 +3383,18 @@ function kbach(userConfig) {
|
|
|
3383
3383
|
const cfg = buildConfig(userConfig ?? {});
|
|
3384
3384
|
const screens = toNumericScreens(cfg.theme.screens ?? {});
|
|
3385
3385
|
const cssMap = /* @__PURE__ */ new Map();
|
|
3386
|
+
const processedCSSFiles = /* @__PURE__ */ new Set();
|
|
3386
3387
|
let root = process.cwd();
|
|
3387
|
-
let
|
|
3388
|
+
let server = null;
|
|
3388
3389
|
function processClassString(classStr) {
|
|
3389
|
-
if (cssMap.has(classStr)) return;
|
|
3390
|
+
if (cssMap.has(classStr)) return false;
|
|
3390
3391
|
cssMap.set(classStr, generateClassCSS(classStr, cfg.theme, cfg.darkMode, screens));
|
|
3392
|
+
return true;
|
|
3391
3393
|
}
|
|
3392
3394
|
function extractFromCode(code) {
|
|
3393
3395
|
let added = false;
|
|
3394
3396
|
for (const cls of extractClassStrings(code)) {
|
|
3395
|
-
if (
|
|
3396
|
-
processClassString(cls);
|
|
3397
|
-
added = true;
|
|
3398
|
-
}
|
|
3397
|
+
if (processClassString(cls)) added = true;
|
|
3399
3398
|
}
|
|
3400
3399
|
return added;
|
|
3401
3400
|
}
|
|
@@ -3408,17 +3407,24 @@ function kbach(userConfig) {
|
|
|
3408
3407
|
}
|
|
3409
3408
|
return parts.join("\n");
|
|
3410
3409
|
}
|
|
3410
|
+
function invalidateCSSModules() {
|
|
3411
|
+
if (!server) return;
|
|
3412
|
+
for (const file of processedCSSFiles) {
|
|
3413
|
+
const mod = server.moduleGraph.getModuleByFile(file);
|
|
3414
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3411
3417
|
return {
|
|
3412
3418
|
name: "kbach",
|
|
3413
3419
|
enforce: "pre",
|
|
3414
|
-
config(_c, env) {
|
|
3415
|
-
isDev = env.command === "serve";
|
|
3416
|
-
},
|
|
3417
3420
|
configResolved(resolved) {
|
|
3418
3421
|
root = resolved.root;
|
|
3419
3422
|
},
|
|
3423
|
+
configureServer(s) {
|
|
3424
|
+
server = s;
|
|
3425
|
+
},
|
|
3420
3426
|
buildStart() {
|
|
3421
|
-
for (const dir of ["src", "app", "pages", "components"]) {
|
|
3427
|
+
for (const dir of ["src", "app", "pages", "components", "views", "layouts"]) {
|
|
3422
3428
|
scanDir((0, import_path.join)(root, dir), (code) => extractFromCode(code));
|
|
3423
3429
|
}
|
|
3424
3430
|
},
|
|
@@ -3429,23 +3435,24 @@ function kbach(userConfig) {
|
|
|
3429
3435
|
if (id === RESOLVED_ID) return getAllCSS();
|
|
3430
3436
|
},
|
|
3431
3437
|
transform(code, id) {
|
|
3432
|
-
if (id.includes("node_modules")
|
|
3433
|
-
|
|
3434
|
-
|
|
3438
|
+
if (id.endsWith(".css") && !id.includes("node_modules") && !id.includes("\0")) {
|
|
3439
|
+
processedCSSFiles.add(id);
|
|
3440
|
+
const kbachCSS = getAllCSS();
|
|
3441
|
+
if (!kbachCSS) return null;
|
|
3442
|
+
return { code: code + "\n/* kbach utilities */\n" + kbachCSS, map: null };
|
|
3443
|
+
}
|
|
3444
|
+
if (/\.(tsx?|jsx?)$/.test(id) && !id.includes("node_modules")) {
|
|
3445
|
+
const added = extractFromCode(code);
|
|
3446
|
+
if (added && server && processedCSSFiles.size > 0) {
|
|
3447
|
+
setTimeout(invalidateCSSModules, 0);
|
|
3448
|
+
}
|
|
3435
3449
|
}
|
|
3436
3450
|
},
|
|
3437
|
-
handleHotUpdate({ file
|
|
3451
|
+
handleHotUpdate({ file }) {
|
|
3438
3452
|
if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
|
|
3439
3453
|
try {
|
|
3440
|
-
const
|
|
3441
|
-
|
|
3442
|
-
if (added) {
|
|
3443
|
-
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
3444
|
-
if (mod) {
|
|
3445
|
-
server.moduleGraph.invalidateModule(mod);
|
|
3446
|
-
return [mod];
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3454
|
+
const added = extractFromCode((0, import_fs.readFileSync)(file, "utf-8"));
|
|
3455
|
+
if (added) invalidateCSSModules();
|
|
3449
3456
|
} catch {
|
|
3450
3457
|
}
|
|
3451
3458
|
}
|
package/dist/vite-plugin.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { readFileSync, readdirSync, statSync } from "fs";
|
|
8
8
|
import { join } from "path";
|
|
9
9
|
var VIRTUAL_ID = "virtual:kbach/styles.css";
|
|
10
|
-
var RESOLVED_ID = "\
|
|
10
|
+
var RESOLVED_ID = "\0virtual:kbach/styles.css";
|
|
11
11
|
function toNumericScreens(screens) {
|
|
12
12
|
const out = {};
|
|
13
13
|
for (const [k, v] of Object.entries(screens)) {
|
|
@@ -53,19 +53,18 @@ function kbach(userConfig) {
|
|
|
53
53
|
const cfg = buildConfig(userConfig ?? {});
|
|
54
54
|
const screens = toNumericScreens(cfg.theme.screens ?? {});
|
|
55
55
|
const cssMap = /* @__PURE__ */ new Map();
|
|
56
|
+
const processedCSSFiles = /* @__PURE__ */ new Set();
|
|
56
57
|
let root = process.cwd();
|
|
57
|
-
let
|
|
58
|
+
let server = null;
|
|
58
59
|
function processClassString(classStr) {
|
|
59
|
-
if (cssMap.has(classStr)) return;
|
|
60
|
+
if (cssMap.has(classStr)) return false;
|
|
60
61
|
cssMap.set(classStr, generateClassCSS(classStr, cfg.theme, cfg.darkMode, screens));
|
|
62
|
+
return true;
|
|
61
63
|
}
|
|
62
64
|
function extractFromCode(code) {
|
|
63
65
|
let added = false;
|
|
64
66
|
for (const cls of extractClassStrings(code)) {
|
|
65
|
-
if (
|
|
66
|
-
processClassString(cls);
|
|
67
|
-
added = true;
|
|
68
|
-
}
|
|
67
|
+
if (processClassString(cls)) added = true;
|
|
69
68
|
}
|
|
70
69
|
return added;
|
|
71
70
|
}
|
|
@@ -78,17 +77,24 @@ function kbach(userConfig) {
|
|
|
78
77
|
}
|
|
79
78
|
return parts.join("\n");
|
|
80
79
|
}
|
|
80
|
+
function invalidateCSSModules() {
|
|
81
|
+
if (!server) return;
|
|
82
|
+
for (const file of processedCSSFiles) {
|
|
83
|
+
const mod = server.moduleGraph.getModuleByFile(file);
|
|
84
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
81
87
|
return {
|
|
82
88
|
name: "kbach",
|
|
83
89
|
enforce: "pre",
|
|
84
|
-
config(_c, env) {
|
|
85
|
-
isDev = env.command === "serve";
|
|
86
|
-
},
|
|
87
90
|
configResolved(resolved) {
|
|
88
91
|
root = resolved.root;
|
|
89
92
|
},
|
|
93
|
+
configureServer(s) {
|
|
94
|
+
server = s;
|
|
95
|
+
},
|
|
90
96
|
buildStart() {
|
|
91
|
-
for (const dir of ["src", "app", "pages", "components"]) {
|
|
97
|
+
for (const dir of ["src", "app", "pages", "components", "views", "layouts"]) {
|
|
92
98
|
scanDir(join(root, dir), (code) => extractFromCode(code));
|
|
93
99
|
}
|
|
94
100
|
},
|
|
@@ -99,23 +105,24 @@ function kbach(userConfig) {
|
|
|
99
105
|
if (id === RESOLVED_ID) return getAllCSS();
|
|
100
106
|
},
|
|
101
107
|
transform(code, id) {
|
|
102
|
-
if (id.includes("node_modules")
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
if (id.endsWith(".css") && !id.includes("node_modules") && !id.includes("\0")) {
|
|
109
|
+
processedCSSFiles.add(id);
|
|
110
|
+
const kbachCSS = getAllCSS();
|
|
111
|
+
if (!kbachCSS) return null;
|
|
112
|
+
return { code: code + "\n/* kbach utilities */\n" + kbachCSS, map: null };
|
|
113
|
+
}
|
|
114
|
+
if (/\.(tsx?|jsx?)$/.test(id) && !id.includes("node_modules")) {
|
|
115
|
+
const added = extractFromCode(code);
|
|
116
|
+
if (added && server && processedCSSFiles.size > 0) {
|
|
117
|
+
setTimeout(invalidateCSSModules, 0);
|
|
118
|
+
}
|
|
105
119
|
}
|
|
106
120
|
},
|
|
107
|
-
handleHotUpdate({ file
|
|
121
|
+
handleHotUpdate({ file }) {
|
|
108
122
|
if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
|
|
109
123
|
try {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
if (added) {
|
|
113
|
-
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
114
|
-
if (mod) {
|
|
115
|
-
server.moduleGraph.invalidateModule(mod);
|
|
116
|
-
return [mod];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
124
|
+
const added = extractFromCode(readFileSync(file, "utf-8"));
|
|
125
|
+
if (added) invalidateCSSModules();
|
|
119
126
|
} catch {
|
|
120
127
|
}
|
|
121
128
|
}
|
package/package.json
CHANGED