@kbach/react 0.5.14 → 0.5.16

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.
@@ -0,0 +1,127 @@
1
+ import {
2
+ buildConfig,
3
+ generateClassCSS
4
+ } from "./chunk-SHQPNCQ7.mjs";
5
+
6
+ // src/vite-plugin.ts
7
+ import { readFileSync, readdirSync, statSync } from "fs";
8
+ import { join } from "path";
9
+ var VIRTUAL_ID = "virtual:kbach/styles.css";
10
+ var RESOLVED_ID = "\0" + VIRTUAL_ID;
11
+ function toNumericScreens(screens) {
12
+ const out = {};
13
+ for (const [k, v] of Object.entries(screens)) {
14
+ out[k] = typeof v === "number" ? v : parseInt(String(v), 10);
15
+ }
16
+ return out;
17
+ }
18
+ function scanDir(dir, onFile) {
19
+ try {
20
+ for (const entry of readdirSync(dir)) {
21
+ if (entry.startsWith(".") || entry === "node_modules") continue;
22
+ const full = join(dir, entry);
23
+ try {
24
+ const st = statSync(full);
25
+ if (st.isDirectory()) {
26
+ scanDir(full, onFile);
27
+ } else if (/\.(tsx?|jsx?)$/.test(entry)) {
28
+ onFile(readFileSync(full, "utf-8"));
29
+ }
30
+ } catch {
31
+ }
32
+ }
33
+ } catch {
34
+ }
35
+ }
36
+ function extractClassStrings(code) {
37
+ const found = [];
38
+ const re = /(?:className|kb)=(?:["']([^"']+)["']|\{["']([^"']+)["']\})/g;
39
+ let m;
40
+ while ((m = re.exec(code)) !== null) {
41
+ const val = m[1] ?? m[2];
42
+ if (val) found.push(val);
43
+ }
44
+ return found;
45
+ }
46
+ function buildGlobalCSS(theme) {
47
+ const ff = theme.fontFamily;
48
+ if (!ff?.sans || ff.sans === "System") return "";
49
+ const family = Array.isArray(ff.sans) ? ff.sans.join(", ") : ff.sans;
50
+ return `body { font-family: ${family}; }`;
51
+ }
52
+ function kbach(userConfig) {
53
+ const cfg = buildConfig(userConfig ?? {});
54
+ const screens = toNumericScreens(cfg.theme.screens ?? {});
55
+ const cssMap = /* @__PURE__ */ new Map();
56
+ let root = process.cwd();
57
+ let isDev = false;
58
+ function processClassString(classStr) {
59
+ if (cssMap.has(classStr)) return;
60
+ cssMap.set(classStr, generateClassCSS(classStr, cfg.theme, cfg.darkMode, screens));
61
+ }
62
+ function extractFromCode(code) {
63
+ let added = false;
64
+ for (const cls of extractClassStrings(code)) {
65
+ if (!cssMap.has(cls)) {
66
+ processClassString(cls);
67
+ added = true;
68
+ }
69
+ }
70
+ return added;
71
+ }
72
+ function getAllCSS() {
73
+ const parts = [];
74
+ const global = buildGlobalCSS(cfg.theme);
75
+ if (global) parts.push(global);
76
+ for (const css of cssMap.values()) {
77
+ if (css) parts.push(css);
78
+ }
79
+ return parts.join("\n");
80
+ }
81
+ return {
82
+ name: "kbach",
83
+ enforce: "pre",
84
+ config(_c, env) {
85
+ isDev = env.command === "serve";
86
+ },
87
+ configResolved(resolved) {
88
+ root = resolved.root;
89
+ },
90
+ buildStart() {
91
+ for (const dir of ["src", "app", "pages", "components"]) {
92
+ scanDir(join(root, dir), (code) => extractFromCode(code));
93
+ }
94
+ },
95
+ resolveId(id) {
96
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
97
+ },
98
+ load(id) {
99
+ if (id === RESOLVED_ID) return getAllCSS();
100
+ },
101
+ transform(code, id) {
102
+ if (id.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(id)) return;
103
+ const added = extractFromCode(code);
104
+ if (isDev && added) {
105
+ }
106
+ },
107
+ handleHotUpdate({ file, server }) {
108
+ if (file.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(file)) return;
109
+ try {
110
+ const code = readFileSync(file, "utf-8");
111
+ const added = extractFromCode(code);
112
+ if (added) {
113
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
114
+ if (mod) {
115
+ server.moduleGraph.invalidateModule(mod);
116
+ return [mod];
117
+ }
118
+ }
119
+ } catch {
120
+ }
121
+ }
122
+ };
123
+ }
124
+ export {
125
+ VIRTUAL_ID,
126
+ kbach
127
+ };
package/package.json CHANGED
@@ -1,61 +1,77 @@
1
- {
2
- "name": "@kbach/react",
3
- "version": "0.5.14",
4
- "description": "React / React Native components and hooks for the Kbach framework",
5
- "source": "./src/index.ts",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "source": "./src/index.ts",
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js"
15
- },
16
- "./jsx-runtime": {
17
- "types": "./dist/jsx-runtime.d.ts",
18
- "source": "./src/jsx-runtime.tsx",
19
- "import": "./dist/jsx-runtime.mjs",
20
- "require": "./dist/jsx-runtime.js"
21
- },
22
- "./jsx-dev-runtime": {
23
- "types": "./dist/jsx-dev-runtime.d.ts",
24
- "source": "./src/jsx-dev-runtime.tsx",
25
- "import": "./dist/jsx-dev-runtime.mjs",
26
- "require": "./dist/jsx-dev-runtime.js"
27
- },
28
- "./types": {
29
- "types": "./types.d.ts"
30
- }
31
- },
32
- "scripts": {
33
- "build": "tsup src/index.ts src/jsx-runtime.tsx src/jsx-dev-runtime.tsx --format esm,cjs --dts --clean",
34
- "dev": "tsup src/index.ts src/jsx-runtime.tsx src/jsx-dev-runtime.tsx --format esm,cjs --dts --watch",
35
- "test": "vitest run --passWithNoTests",
36
- "lint": "tsc --noEmit",
37
- "postinstall": "node scripts/postinstall.js"
38
- },
39
- "devDependencies": {
40
- "@types/react": "^19.2.0",
41
- "tsup": "^8.0.0",
42
- "vitest": "^1.0.0"
43
- },
44
- "peerDependencies": {
45
- "react": ">=17.0.0",
46
- "react-native": ">=0.70.0"
47
- },
48
- "peerDependenciesMeta": {
49
- "react-native": {
50
- "optional": true
51
- }
52
- },
53
- "publishConfig": {
54
- "access": "public"
55
- },
56
- "files": [
57
- "dist",
58
- "scripts",
59
- "KBACH.md"
60
- ]
61
- }
1
+ {
2
+ "name": "@kbach/react",
3
+ "version": "0.5.16",
4
+ "description": "React / React Native components and hooks for the Kbach framework",
5
+ "source": "./src/index.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "source": "./src/index.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js"
15
+ },
16
+ "./jsx-runtime": {
17
+ "types": "./dist/jsx-runtime.d.ts",
18
+ "source": "./src/jsx-runtime.tsx",
19
+ "import": "./dist/jsx-runtime.mjs",
20
+ "require": "./dist/jsx-runtime.js"
21
+ },
22
+ "./jsx-dev-runtime": {
23
+ "types": "./dist/jsx-dev-runtime.d.ts",
24
+ "source": "./src/jsx-dev-runtime.tsx",
25
+ "import": "./dist/jsx-dev-runtime.mjs",
26
+ "require": "./dist/jsx-dev-runtime.js"
27
+ },
28
+ "./types": {
29
+ "types": "./types.d.ts"
30
+ },
31
+ "./vite": {
32
+ "types": "./dist/vite-plugin.d.ts",
33
+ "source": "./src/vite-plugin.ts",
34
+ "import": "./dist/vite-plugin.mjs",
35
+ "require": "./dist/vite-plugin.js"
36
+ },
37
+ "./vite/client": {
38
+ "types": "./dist/vite-plugin-client.d.ts"
39
+ }
40
+ },
41
+ "scripts": {
42
+ "build": "tsup src/index.ts src/jsx-runtime.tsx src/jsx-dev-runtime.tsx src/vite-plugin.ts --format esm,cjs --dts --clean --external vite",
43
+ "postbuild": "node -e \"const f=require('fs');f.copyFileSync('src/vite-plugin-client.d.ts','dist/vite-plugin-client.d.ts');f.copyFileSync('src/vite-plugin-client.d.ts','dist/vite-plugin-client.d.mts')\"",
44
+ "dev": "tsup src/index.ts src/jsx-runtime.tsx src/jsx-dev-runtime.tsx src/vite-plugin.ts --format esm,cjs --dts --watch --external vite",
45
+ "test": "vitest run --passWithNoTests",
46
+ "lint": "tsc --noEmit",
47
+ "postinstall": "node scripts/postinstall.js"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^20.19.42",
51
+ "@types/react": "^19.2.0",
52
+ "tsup": "^8.0.0",
53
+ "vite": "^5.4.21",
54
+ "vitest": "^1.0.0"
55
+ },
56
+ "peerDependencies": {
57
+ "react": ">=17.0.0",
58
+ "react-native": ">=0.70.0",
59
+ "vite": ">=4.0.0"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "react-native": {
63
+ "optional": true
64
+ },
65
+ "vite": {
66
+ "optional": true
67
+ }
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ },
72
+ "files": [
73
+ "dist",
74
+ "scripts",
75
+ "KBACH.md"
76
+ ]
77
+ }