@kbach/react 0.1.0

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,17 @@
1
+ export { Fragment } from 'react/jsx-runtime';
2
+ import { ReactElement } from 'react';
3
+
4
+ /**
5
+ * @kbach/react/jsx-runtime
6
+ *
7
+ * Drop-in replacement for react/jsx-runtime.
8
+ * Intercepts `className` and `tw` props on EVERY JSX element — React Native
9
+ * built-ins, HTML elements on web, and any third-party library component.
10
+ */
11
+
12
+ /** jsx() — elements with 0–1 child or dynamic key. */
13
+ declare function jsx(type: unknown, props: Record<string, unknown> | null, key?: string): ReactElement;
14
+ /** jsxs() — elements with 2+ static children. Children array is compile-time stable. */
15
+ declare function jsxs(type: unknown, props: Record<string, unknown> | null, key?: string): ReactElement;
16
+
17
+ export { jsx, jsxs };
@@ -0,0 +1,17 @@
1
+ export { Fragment } from 'react/jsx-runtime';
2
+ import { ReactElement } from 'react';
3
+
4
+ /**
5
+ * @kbach/react/jsx-runtime
6
+ *
7
+ * Drop-in replacement for react/jsx-runtime.
8
+ * Intercepts `className` and `tw` props on EVERY JSX element — React Native
9
+ * built-ins, HTML elements on web, and any third-party library component.
10
+ */
11
+
12
+ /** jsx() — elements with 0–1 child or dynamic key. */
13
+ declare function jsx(type: unknown, props: Record<string, unknown> | null, key?: string): ReactElement;
14
+ /** jsxs() — elements with 2+ static children. Children array is compile-time stable. */
15
+ declare function jsxs(type: unknown, props: Record<string, unknown> | null, key?: string): ReactElement;
16
+
17
+ export { jsx, jsxs };
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/jsx-runtime.tsx
31
+ var jsx_runtime_exports = {};
32
+ __export(jsx_runtime_exports, {
33
+ Fragment: () => import_jsx_runtime.Fragment,
34
+ jsx: () => jsx,
35
+ jsxs: () => jsxs
36
+ });
37
+ module.exports = __toCommonJS(jsx_runtime_exports);
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ var import_core4 = require("@kbach/core");
40
+
41
+ // src/InteractiveWrapper.tsx
42
+ var import_react2 = __toESM(require("react"));
43
+ var import_core2 = require("@kbach/core");
44
+
45
+ // src/useGlobalDarkMode.ts
46
+ var import_react = __toESM(require("react"));
47
+ var import_core = require("@kbach/core");
48
+ var useSyncExternalStore = import_react.default.useSyncExternalStore ?? function useSyncExternalStoreFallback(subscribe, getSnapshot, _getServerSnapshot) {
49
+ const [, forceUpdate] = import_react.default.useReducer((n) => n + 1, 0);
50
+ import_react.default.useEffect(() => subscribe(forceUpdate), [subscribe]);
51
+ return getSnapshot();
52
+ };
53
+ function useGlobalDarkMode() {
54
+ return useSyncExternalStore(
55
+ import_core.subscribeGlobalDarkMode,
56
+ import_core.getGlobalDarkMode,
57
+ () => false
58
+ // SSR: default light
59
+ );
60
+ }
61
+
62
+ // src/InteractiveWrapper.tsx
63
+ function chain(original, extra) {
64
+ return (...args) => {
65
+ original?.(...args);
66
+ extra();
67
+ };
68
+ }
69
+ var InteractiveWrapper = (0, import_react2.forwardRef)(
70
+ function InteractiveWrapper2({
71
+ Component,
72
+ resolvedStyle,
73
+ className,
74
+ style: styleProp,
75
+ onPressIn,
76
+ onPressOut,
77
+ onMouseEnter,
78
+ onMouseLeave,
79
+ onFocus,
80
+ onBlur,
81
+ ...rest
82
+ }, ref) {
83
+ const isDark = useGlobalDarkMode();
84
+ const [pressed, setPressed] = (0, import_react2.useState)(false);
85
+ const [hovered, setHovered] = (0, import_react2.useState)(false);
86
+ const [focused, setFocused] = (0, import_react2.useState)(false);
87
+ const handlePressIn = (0, import_react2.useCallback)(chain(onPressIn, () => setPressed(true)), [onPressIn]);
88
+ const handlePressOut = (0, import_react2.useCallback)(chain(onPressOut, () => setPressed(false)), [onPressOut]);
89
+ const handleMouseEnter = (0, import_react2.useCallback)(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
90
+ const handleMouseLeave = (0, import_react2.useCallback)(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
91
+ const handleFocus = (0, import_react2.useCallback)(chain(onFocus, () => setFocused(true)), [onFocus]);
92
+ const handleBlur = (0, import_react2.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
93
+ const computedStyle = (0, import_react2.useMemo)(
94
+ () => (0, import_core2.flatten)(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused }),
95
+ [resolvedStyle, isDark, pressed, hovered, focused]
96
+ );
97
+ const finalStyle = styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
98
+ const { children, ...restWithoutChildren } = rest;
99
+ const componentProps = {
100
+ ref,
101
+ ...restWithoutChildren,
102
+ style: finalStyle,
103
+ ...import_core2.isWeb && className ? { className } : {},
104
+ onPressIn: handlePressIn,
105
+ onPressOut: handlePressOut,
106
+ onMouseEnter: handleMouseEnter,
107
+ onMouseLeave: handleMouseLeave,
108
+ onFocus: handleFocus,
109
+ onBlur: handleBlur
110
+ };
111
+ return Array.isArray(children) ? import_react2.default.createElement(Component, componentProps, ...children) : import_react2.default.createElement(Component, componentProps, children);
112
+ }
113
+ );
114
+ InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
115
+
116
+ // src/DarkWrapper.tsx
117
+ var import_react3 = __toESM(require("react"));
118
+ var import_core3 = require("@kbach/core");
119
+ var DarkWrapper = import_react3.default.forwardRef(
120
+ function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
121
+ const isDark = useGlobalDarkMode();
122
+ const computedStyle = (0, import_core3.flatten)(resolvedStyle, isDark);
123
+ const finalStyle = styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
124
+ const props = { ref, ...rest, style: finalStyle };
125
+ return Array.isArray(children) ? import_react3.default.createElement(Component, props, ...children) : import_react3.default.createElement(Component, props, children);
126
+ }
127
+ );
128
+ DarkWrapper.displayName = "Kbach.DarkWrapper";
129
+
130
+ // src/jsx-runtime.tsx
131
+ var MODE_BUCKET_RE = /^(not-)?(dark|light)(:(not-)?(dark|light))*$/;
132
+ function hasInteractiveBuckets(resolved) {
133
+ return Object.keys(resolved).some((key) => {
134
+ if (key === "base") return false;
135
+ if (/^(sm|md|lg|xl|2xl)$/.test(key)) return false;
136
+ if (MODE_BUCKET_RE.test(key)) return false;
137
+ return true;
138
+ });
139
+ }
140
+ var CONSUMED_PROPS = /* @__PURE__ */ new Set(["className", "tw", "__kbachStyles", "__kbachClasses"]);
141
+ function omitConsumed(props) {
142
+ const out = {};
143
+ for (const key of Object.keys(props)) {
144
+ if (!CONSUMED_PROPS.has(key)) out[key] = props[key];
145
+ }
146
+ return out;
147
+ }
148
+ function mergeStyle(computed, userStyle) {
149
+ if (!userStyle) return computed;
150
+ if (Array.isArray(userStyle)) return Object.assign({}, computed, ...userStyle);
151
+ return { ...computed, ...userStyle };
152
+ }
153
+ function makeElement(isStaticChildren, type, props, key) {
154
+ return (isStaticChildren ? import_jsx_runtime.jsxs : import_jsx_runtime.jsx)(type, props, key);
155
+ }
156
+ function processElement(type, rawProps, key, isStaticChildren) {
157
+ if (!rawProps) return (0, import_jsx_runtime.jsx)(type, null, key);
158
+ const { className, tw: twProp, __kbachStyles, __kbachClasses } = rawProps;
159
+ const classStr = className ?? twProp ?? __kbachClasses;
160
+ if (!classStr && !__kbachStyles) {
161
+ return makeElement(isStaticChildren, type, rawProps, key);
162
+ }
163
+ const config = (0, import_core4.getConfig)();
164
+ const resolved = __kbachStyles ?? (classStr ? (0, import_core4.resolve)(classStr, config.theme, config.darkMode) : {});
165
+ const { style: userStyle, ...passProps } = omitConsumed(rawProps);
166
+ if (hasInteractiveBuckets(resolved)) {
167
+ return (0, import_jsx_runtime.jsx)(InteractiveWrapper, {
168
+ Component: type,
169
+ resolvedStyle: resolved,
170
+ ...import_core4.isWeb && classStr ? { className: classStr } : {},
171
+ style: userStyle,
172
+ ...passProps
173
+ }, key);
174
+ }
175
+ const hasModeVariants = Object.keys(resolved).some(
176
+ (k) => k !== "base" && MODE_BUCKET_RE.test(k)
177
+ );
178
+ if (hasModeVariants) {
179
+ return (0, import_jsx_runtime.jsx)(DarkWrapper, {
180
+ Component: type,
181
+ resolvedStyle: resolved,
182
+ ...import_core4.isWeb && classStr ? { className: classStr } : {},
183
+ style: userStyle,
184
+ ...passProps
185
+ }, key);
186
+ }
187
+ const computedStyle = (0, import_core4.flatten)(resolved, false);
188
+ const finalStyle = mergeStyle(computedStyle, userStyle);
189
+ return makeElement(isStaticChildren, type, {
190
+ ...passProps,
191
+ style: finalStyle,
192
+ ...import_core4.isWeb && classStr ? { className: classStr } : {}
193
+ }, key);
194
+ }
195
+ function jsx(type, props, key) {
196
+ return processElement(type, props, key, false);
197
+ }
198
+ function jsxs(type, props, key) {
199
+ return processElement(type, props, key, true);
200
+ }
201
+ // Annotate the CommonJS export names for ESM import in node:
202
+ 0 && (module.exports = {
203
+ Fragment,
204
+ jsx,
205
+ jsxs
206
+ });
@@ -0,0 +1,11 @@
1
+ import {
2
+ Fragment,
3
+ jsx,
4
+ jsxs
5
+ } from "./chunk-FUSJKUE7.mjs";
6
+ import "./chunk-IZK5HMWK.mjs";
7
+ export {
8
+ Fragment,
9
+ jsx,
10
+ jsxs
11
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@kbach/react",
3
+ "version": "0.1.0",
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
+ },
38
+ "dependencies": {
39
+ "@kbach/core": "0.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/react": "^19.2.0",
43
+ "tsup": "^8.0.0",
44
+ "vitest": "^1.0.0"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=17.0.0",
48
+ "react-native": ">=0.70.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "react-native": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "files": ["dist"]
59
+ }