@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.
- package/dist/chunk-FUSJKUE7.mjs +100 -0
- package/dist/chunk-IZK5HMWK.mjs +85 -0
- package/dist/index.d.mts +185 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +516 -0
- package/dist/index.mjs +421 -0
- package/dist/jsx-dev-runtime.d.mts +19 -0
- package/dist/jsx-dev-runtime.d.ts +19 -0
- package/dist/jsx-dev-runtime.js +211 -0
- package/dist/jsx-dev-runtime.mjs +15 -0
- package/dist/jsx-runtime.d.mts +17 -0
- package/dist/jsx-runtime.d.ts +17 -0
- package/dist/jsx-runtime.js +206 -0
- package/dist/jsx-runtime.mjs +11 -0
- package/package.json +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
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/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
InteractiveWrapper: () => InteractiveWrapper,
|
|
34
|
+
ThemeContext: () => ThemeContext,
|
|
35
|
+
ThemeProvider: () => ThemeProvider,
|
|
36
|
+
ThemeToggle: () => ThemeToggle,
|
|
37
|
+
cx: () => cx,
|
|
38
|
+
defaultColors: () => import_core7.defaultColors,
|
|
39
|
+
defaultTheme: () => import_core7.defaultTheme,
|
|
40
|
+
flatten: () => import_core7.flatten,
|
|
41
|
+
getConfig: () => import_core7.getConfig,
|
|
42
|
+
parseClass: () => import_core7.parseClass,
|
|
43
|
+
parseClasses: () => import_core7.parseClasses,
|
|
44
|
+
resolve: () => import_core7.resolve,
|
|
45
|
+
styled: () => styled,
|
|
46
|
+
tw: () => tw,
|
|
47
|
+
updateConfig: () => import_core7.updateConfig,
|
|
48
|
+
useGlobalDarkMode: () => useGlobalDarkMode,
|
|
49
|
+
useResolvedStyle: () => useResolvedStyle,
|
|
50
|
+
useStyles: () => useStyles,
|
|
51
|
+
useTheme: () => useTheme
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(index_exports);
|
|
54
|
+
|
|
55
|
+
// src/context.tsx
|
|
56
|
+
var import_react = require("react");
|
|
57
|
+
var ThemeContext = (0, import_react.createContext)(null);
|
|
58
|
+
function useTheme() {
|
|
59
|
+
const ctx = (0, import_react.useContext)(ThemeContext);
|
|
60
|
+
if (!ctx) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"[Kbach] useTheme() must be called inside a <ThemeProvider>. Wrap your app root with <ThemeProvider>."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return ctx;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/ThemeProvider.tsx
|
|
69
|
+
var import_react2 = require("react");
|
|
70
|
+
var import_core = require("@kbach/core");
|
|
71
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
|
+
var Appearance;
|
|
73
|
+
try {
|
|
74
|
+
({ Appearance } = require("react-native"));
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
var STORAGE_KEY = "kbach-theme";
|
|
78
|
+
function loadPersistedMode() {
|
|
79
|
+
try {
|
|
80
|
+
if (import_core.isWeb) {
|
|
81
|
+
return localStorage.getItem(STORAGE_KEY);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function persistMode(mode) {
|
|
89
|
+
try {
|
|
90
|
+
if (import_core.isWeb) localStorage.setItem(STORAGE_KEY, mode);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function applyWebTheme(resolvedMode, strategy) {
|
|
95
|
+
if (!import_core.isWeb) return;
|
|
96
|
+
const root = document.documentElement;
|
|
97
|
+
if (strategy === "attribute") {
|
|
98
|
+
root.setAttribute("data-theme", resolvedMode);
|
|
99
|
+
} else if (strategy === "class") {
|
|
100
|
+
root.classList.toggle("dark", resolvedMode === "dark");
|
|
101
|
+
root.classList.toggle("light", resolvedMode === "light");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function ThemeProvider({
|
|
105
|
+
children,
|
|
106
|
+
defaultMode = "system",
|
|
107
|
+
config: configOverride,
|
|
108
|
+
disablePersistence = false
|
|
109
|
+
}) {
|
|
110
|
+
const [resolvedConfig, setResolvedConfig] = (0, import_react2.useState)(
|
|
111
|
+
() => configOverride ? (0, import_core.buildConfig)(configOverride) : (0, import_core.getConfig)()
|
|
112
|
+
);
|
|
113
|
+
const getSystemScheme = (0, import_react2.useCallback)(() => {
|
|
114
|
+
if (import_core.isWeb && typeof window !== "undefined") {
|
|
115
|
+
return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
116
|
+
}
|
|
117
|
+
if (Appearance) {
|
|
118
|
+
return Appearance.getColorScheme() === "dark" ? "dark" : "light";
|
|
119
|
+
}
|
|
120
|
+
return "light";
|
|
121
|
+
}, []);
|
|
122
|
+
const [systemScheme, setSystemScheme] = (0, import_react2.useState)(getSystemScheme);
|
|
123
|
+
const [mode, _setMode] = (0, import_react2.useState)(() => {
|
|
124
|
+
if (!disablePersistence) {
|
|
125
|
+
const persisted = loadPersistedMode();
|
|
126
|
+
if (persisted) return persisted;
|
|
127
|
+
}
|
|
128
|
+
return defaultMode;
|
|
129
|
+
});
|
|
130
|
+
const setMode = (0, import_react2.useCallback)((next) => {
|
|
131
|
+
_setMode(next);
|
|
132
|
+
if (!disablePersistence) persistMode(next);
|
|
133
|
+
}, [disablePersistence]);
|
|
134
|
+
const toggle = (0, import_react2.useCallback)(() => {
|
|
135
|
+
setMode(mode === "dark" || mode === "system" && systemScheme === "dark" ? "light" : "dark");
|
|
136
|
+
}, [mode, systemScheme, setMode]);
|
|
137
|
+
const resolvedMode = mode === "system" ? systemScheme : mode;
|
|
138
|
+
const isDark = resolvedMode === "dark";
|
|
139
|
+
(0, import_core.syncGlobalDarkMode)(isDark);
|
|
140
|
+
(0, import_react2.useEffect)(() => {
|
|
141
|
+
applyWebTheme(resolvedMode, resolvedConfig.darkMode);
|
|
142
|
+
(0, import_core.setGlobalDarkMode)(isDark);
|
|
143
|
+
}, [isDark, resolvedMode, resolvedConfig.darkMode]);
|
|
144
|
+
const setSystemSchemeRef = (0, import_react2.useRef)(setSystemScheme);
|
|
145
|
+
setSystemSchemeRef.current = setSystemScheme;
|
|
146
|
+
(0, import_react2.useEffect)(() => {
|
|
147
|
+
if (import_core.isWeb && typeof window !== "undefined") {
|
|
148
|
+
const mq = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
149
|
+
if (!mq) return;
|
|
150
|
+
const handler = (e) => {
|
|
151
|
+
setSystemSchemeRef.current(e.matches ? "dark" : "light");
|
|
152
|
+
};
|
|
153
|
+
mq.addEventListener("change", handler);
|
|
154
|
+
return () => mq.removeEventListener("change", handler);
|
|
155
|
+
}
|
|
156
|
+
if (Appearance) {
|
|
157
|
+
const sub = Appearance.addChangeListener(({ colorScheme }) => {
|
|
158
|
+
setSystemSchemeRef.current(colorScheme === "dark" ? "dark" : "light");
|
|
159
|
+
});
|
|
160
|
+
return () => sub.remove();
|
|
161
|
+
}
|
|
162
|
+
return void 0;
|
|
163
|
+
}, []);
|
|
164
|
+
(0, import_react2.useEffect)(() => {
|
|
165
|
+
if (configOverride) return;
|
|
166
|
+
const unsub = (0, import_core.onConfigChange)(setResolvedConfig);
|
|
167
|
+
return unsub;
|
|
168
|
+
}, [configOverride]);
|
|
169
|
+
const contextValue = (0, import_react2.useMemo)(
|
|
170
|
+
() => ({ mode, resolvedMode, isDark, setMode, toggle, config: resolvedConfig }),
|
|
171
|
+
[mode, resolvedMode, isDark, setMode, toggle, resolvedConfig]
|
|
172
|
+
);
|
|
173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeContext.Provider, { value: contextValue, children });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/ThemeToggle.tsx
|
|
177
|
+
var import_react3 = __toESM(require("react"));
|
|
178
|
+
function getPrimitives() {
|
|
179
|
+
try {
|
|
180
|
+
const RN = require("react-native");
|
|
181
|
+
return {
|
|
182
|
+
View: RN.View,
|
|
183
|
+
Text: RN.Text,
|
|
184
|
+
Touchable: RN.TouchableOpacity,
|
|
185
|
+
Switch: RN.Switch
|
|
186
|
+
};
|
|
187
|
+
} catch {
|
|
188
|
+
const View = ({ style, ...rest }) => import_react3.default.createElement("div", { style, ...rest });
|
|
189
|
+
const Text = ({ style, ...rest }) => import_react3.default.createElement("span", { style, ...rest });
|
|
190
|
+
const Touchable = ({ onPress, style, ...rest }) => import_react3.default.createElement("button", { onClick: onPress, style, ...rest });
|
|
191
|
+
const Switch = ({
|
|
192
|
+
value,
|
|
193
|
+
onValueChange,
|
|
194
|
+
accessibilityLabel
|
|
195
|
+
}) => import_react3.default.createElement("input", {
|
|
196
|
+
type: "checkbox",
|
|
197
|
+
checked: value,
|
|
198
|
+
onChange: (e) => onValueChange?.(e.target.checked),
|
|
199
|
+
"aria-label": accessibilityLabel
|
|
200
|
+
});
|
|
201
|
+
return { View, Text, Touchable, Switch };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
var { View: _View, Text: _Text, Touchable: _Touchable, Switch: _Switch } = getPrimitives();
|
|
205
|
+
function ThemeToggle({
|
|
206
|
+
variant = "button",
|
|
207
|
+
label,
|
|
208
|
+
lightLabel = "Light",
|
|
209
|
+
darkLabel = "Dark",
|
|
210
|
+
includeSystem = false,
|
|
211
|
+
style,
|
|
212
|
+
labelStyle
|
|
213
|
+
}) {
|
|
214
|
+
const { mode, isDark, setMode, toggle } = useTheme();
|
|
215
|
+
const View = _View, Text = _Text, Touchable = _Touchable, Switch = _Switch;
|
|
216
|
+
if (variant === "switch") {
|
|
217
|
+
return import_react3.default.createElement(
|
|
218
|
+
View,
|
|
219
|
+
{ style: { flexDirection: "row", alignItems: "center", gap: 8, ...style } },
|
|
220
|
+
import_react3.default.createElement(Text, { style: { fontSize: 14, ...labelStyle } }, lightLabel),
|
|
221
|
+
import_react3.default.createElement(Switch, {
|
|
222
|
+
value: isDark,
|
|
223
|
+
onValueChange: (v) => setMode(v ? "dark" : "light"),
|
|
224
|
+
trackColor: { false: "#d1d5db", true: "#6366f1" },
|
|
225
|
+
thumbColor: isDark ? "#ffffff" : "#f3f4f6",
|
|
226
|
+
ios_backgroundColor: "#d1d5db",
|
|
227
|
+
accessibilityLabel: "Toggle dark mode"
|
|
228
|
+
}),
|
|
229
|
+
import_react3.default.createElement(Text, { style: { fontSize: 14, ...labelStyle } }, darkLabel)
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (variant === "icon-button") {
|
|
233
|
+
const icon = isDark ? darkLabel : lightLabel;
|
|
234
|
+
return import_react3.default.createElement(
|
|
235
|
+
Touchable,
|
|
236
|
+
{
|
|
237
|
+
onPress: toggle,
|
|
238
|
+
style: {
|
|
239
|
+
padding: 8,
|
|
240
|
+
borderRadius: 8,
|
|
241
|
+
backgroundColor: isDark ? "#374151" : "#f3f4f6",
|
|
242
|
+
...style
|
|
243
|
+
},
|
|
244
|
+
accessibilityRole: "button",
|
|
245
|
+
accessibilityLabel: `Switch to ${isDark ? "light" : "dark"} mode`,
|
|
246
|
+
accessibilityState: {}
|
|
247
|
+
},
|
|
248
|
+
import_react3.default.createElement(Text, { style: { fontSize: 18, ...labelStyle } }, icon)
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
if (includeSystem) {
|
|
252
|
+
const modes = [
|
|
253
|
+
{ key: "light", label: lightLabel },
|
|
254
|
+
{ key: "dark", label: darkLabel },
|
|
255
|
+
{ key: "system", label: "System" }
|
|
256
|
+
];
|
|
257
|
+
return import_react3.default.createElement(
|
|
258
|
+
View,
|
|
259
|
+
{ style: { flexDirection: "row", gap: 4, ...style } },
|
|
260
|
+
...modes.map(
|
|
261
|
+
({ key, label: mLabel }) => import_react3.default.createElement(
|
|
262
|
+
Touchable,
|
|
263
|
+
{
|
|
264
|
+
key,
|
|
265
|
+
onPress: () => setMode(key),
|
|
266
|
+
style: {
|
|
267
|
+
paddingHorizontal: 12,
|
|
268
|
+
paddingVertical: 6,
|
|
269
|
+
borderRadius: 6,
|
|
270
|
+
backgroundColor: mode === key ? isDark ? "#6366f1" : "#3b82f6" : isDark ? "#374151" : "#e5e7eb"
|
|
271
|
+
},
|
|
272
|
+
accessibilityRole: "button",
|
|
273
|
+
accessibilityLabel: `Set ${key} theme`,
|
|
274
|
+
accessibilityState: { selected: mode === key }
|
|
275
|
+
},
|
|
276
|
+
import_react3.default.createElement(Text, {
|
|
277
|
+
style: {
|
|
278
|
+
fontSize: 13,
|
|
279
|
+
fontWeight: "500",
|
|
280
|
+
color: mode === key ? "#ffffff" : isDark ? "#d1d5db" : "#374151",
|
|
281
|
+
...labelStyle
|
|
282
|
+
}
|
|
283
|
+
}, mLabel)
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const currentLabel = label ?? (isDark ? darkLabel : lightLabel);
|
|
289
|
+
return import_react3.default.createElement(
|
|
290
|
+
Touchable,
|
|
291
|
+
{
|
|
292
|
+
onPress: toggle,
|
|
293
|
+
style: {
|
|
294
|
+
paddingHorizontal: 16,
|
|
295
|
+
paddingVertical: 8,
|
|
296
|
+
borderRadius: 8,
|
|
297
|
+
backgroundColor: isDark ? "#374151" : "#e5e7eb",
|
|
298
|
+
...style
|
|
299
|
+
},
|
|
300
|
+
accessibilityRole: "button",
|
|
301
|
+
accessibilityLabel: `Switch to ${isDark ? "light" : "dark"} mode`,
|
|
302
|
+
accessibilityState: {}
|
|
303
|
+
},
|
|
304
|
+
import_react3.default.createElement(Text, {
|
|
305
|
+
style: {
|
|
306
|
+
fontSize: 14,
|
|
307
|
+
fontWeight: "500",
|
|
308
|
+
color: isDark ? "#f9fafb" : "#111827",
|
|
309
|
+
...labelStyle
|
|
310
|
+
}
|
|
311
|
+
}, currentLabel)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/styled.tsx
|
|
316
|
+
var import_react4 = __toESM(require("react"));
|
|
317
|
+
var import_core2 = require("@kbach/core");
|
|
318
|
+
function styled(Component, baseClasses = "") {
|
|
319
|
+
const Styled = (0, import_react4.forwardRef)(
|
|
320
|
+
(props, ref) => {
|
|
321
|
+
const {
|
|
322
|
+
tw: extraClasses,
|
|
323
|
+
style: styleProp,
|
|
324
|
+
onPressIn,
|
|
325
|
+
onPressOut,
|
|
326
|
+
onMouseEnter,
|
|
327
|
+
onMouseLeave,
|
|
328
|
+
onFocus,
|
|
329
|
+
onBlur,
|
|
330
|
+
...rest
|
|
331
|
+
} = props;
|
|
332
|
+
const { isDark, config } = useTheme();
|
|
333
|
+
const [pressed, setPressed] = (0, import_react4.useState)(false);
|
|
334
|
+
const [hovered, setHovered] = (0, import_react4.useState)(false);
|
|
335
|
+
const [focused, setFocused] = (0, import_react4.useState)(false);
|
|
336
|
+
const handlePressIn = (0, import_react4.useCallback)((e) => {
|
|
337
|
+
setPressed(true);
|
|
338
|
+
onPressIn?.(e);
|
|
339
|
+
}, [onPressIn]);
|
|
340
|
+
const handlePressOut = (0, import_react4.useCallback)((e) => {
|
|
341
|
+
setPressed(false);
|
|
342
|
+
onPressOut?.(e);
|
|
343
|
+
}, [onPressOut]);
|
|
344
|
+
const handleMouseEnter = (0, import_react4.useCallback)((e) => {
|
|
345
|
+
setHovered(true);
|
|
346
|
+
onMouseEnter?.(e);
|
|
347
|
+
}, [onMouseEnter]);
|
|
348
|
+
const handleMouseLeave = (0, import_react4.useCallback)((e) => {
|
|
349
|
+
setHovered(false);
|
|
350
|
+
onMouseLeave?.(e);
|
|
351
|
+
}, [onMouseLeave]);
|
|
352
|
+
const handleFocus = (0, import_react4.useCallback)((e) => {
|
|
353
|
+
setFocused(true);
|
|
354
|
+
onFocus?.(e);
|
|
355
|
+
}, [onFocus]);
|
|
356
|
+
const handleBlur = (0, import_react4.useCallback)((e) => {
|
|
357
|
+
setFocused(false);
|
|
358
|
+
onBlur?.(e);
|
|
359
|
+
}, [onBlur]);
|
|
360
|
+
const combined = extraClasses ? `${baseClasses} ${extraClasses}` : baseClasses;
|
|
361
|
+
const resolved = (0, import_react4.useMemo)(() => (0, import_core2.resolve)(combined, config.theme, config.darkMode), [combined, config.theme, config.darkMode]);
|
|
362
|
+
const computedStyle = (0, import_react4.useMemo)(
|
|
363
|
+
() => (0, import_core2.flatten)(resolved, isDark, { pressed, hover: hovered, focus: focused }),
|
|
364
|
+
[resolved, isDark, pressed, hovered, focused]
|
|
365
|
+
);
|
|
366
|
+
const extraStyle = Array.isArray(styleProp) ? Object.assign({}, ...styleProp) : styleProp;
|
|
367
|
+
const finalStyle = extraStyle ? { ...computedStyle, ...extraStyle } : computedStyle;
|
|
368
|
+
return import_react4.default.createElement(Component, {
|
|
369
|
+
ref,
|
|
370
|
+
...rest,
|
|
371
|
+
style: finalStyle,
|
|
372
|
+
onPressIn: handlePressIn,
|
|
373
|
+
onPressOut: handlePressOut,
|
|
374
|
+
onMouseEnter: handleMouseEnter,
|
|
375
|
+
onMouseLeave: handleMouseLeave,
|
|
376
|
+
onFocus: handleFocus,
|
|
377
|
+
onBlur: handleBlur
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
const componentName = Component.displayName ?? Component.name ?? "Component";
|
|
382
|
+
Styled.displayName = `Styled(${componentName})`;
|
|
383
|
+
return Styled;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/useStyles.ts
|
|
387
|
+
var import_react5 = require("react");
|
|
388
|
+
var import_core3 = require("@kbach/core");
|
|
389
|
+
function useStyles(classString, state = {}) {
|
|
390
|
+
const { isDark, config } = useTheme();
|
|
391
|
+
const normalised = Array.isArray(classString) ? classString.join(" ") : classString;
|
|
392
|
+
return (0, import_react5.useMemo)(() => {
|
|
393
|
+
const resolved = (0, import_core3.resolve)(normalised, config.theme, config.darkMode);
|
|
394
|
+
return (0, import_core3.flatten)(resolved, isDark, state);
|
|
395
|
+
}, [normalised, isDark, config, state.hover, state.focus, state.pressed, state.active, state.disabled, state.checked, state.visited, state.placeholder]);
|
|
396
|
+
}
|
|
397
|
+
function useResolvedStyle(classString) {
|
|
398
|
+
const { config } = useTheme();
|
|
399
|
+
const normalised = Array.isArray(classString) ? classString.join(" ") : classString;
|
|
400
|
+
return (0, import_react5.useMemo)(
|
|
401
|
+
() => (0, import_core3.resolve)(normalised, config.theme, config.darkMode),
|
|
402
|
+
[normalised, config]
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/useGlobalDarkMode.ts
|
|
407
|
+
var import_react6 = __toESM(require("react"));
|
|
408
|
+
var import_core4 = require("@kbach/core");
|
|
409
|
+
var useSyncExternalStore = import_react6.default.useSyncExternalStore ?? function useSyncExternalStoreFallback(subscribe, getSnapshot, _getServerSnapshot) {
|
|
410
|
+
const [, forceUpdate] = import_react6.default.useReducer((n) => n + 1, 0);
|
|
411
|
+
import_react6.default.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
412
|
+
return getSnapshot();
|
|
413
|
+
};
|
|
414
|
+
function useGlobalDarkMode() {
|
|
415
|
+
return useSyncExternalStore(
|
|
416
|
+
import_core4.subscribeGlobalDarkMode,
|
|
417
|
+
import_core4.getGlobalDarkMode,
|
|
418
|
+
() => false
|
|
419
|
+
// SSR: default light
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/InteractiveWrapper.tsx
|
|
424
|
+
var import_react7 = __toESM(require("react"));
|
|
425
|
+
var import_core5 = require("@kbach/core");
|
|
426
|
+
function chain(original, extra) {
|
|
427
|
+
return (...args) => {
|
|
428
|
+
original?.(...args);
|
|
429
|
+
extra();
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
var InteractiveWrapper = (0, import_react7.forwardRef)(
|
|
433
|
+
function InteractiveWrapper2({
|
|
434
|
+
Component,
|
|
435
|
+
resolvedStyle,
|
|
436
|
+
className,
|
|
437
|
+
style: styleProp,
|
|
438
|
+
onPressIn,
|
|
439
|
+
onPressOut,
|
|
440
|
+
onMouseEnter,
|
|
441
|
+
onMouseLeave,
|
|
442
|
+
onFocus,
|
|
443
|
+
onBlur,
|
|
444
|
+
...rest
|
|
445
|
+
}, ref) {
|
|
446
|
+
const isDark = useGlobalDarkMode();
|
|
447
|
+
const [pressed, setPressed] = (0, import_react7.useState)(false);
|
|
448
|
+
const [hovered, setHovered] = (0, import_react7.useState)(false);
|
|
449
|
+
const [focused, setFocused] = (0, import_react7.useState)(false);
|
|
450
|
+
const handlePressIn = (0, import_react7.useCallback)(chain(onPressIn, () => setPressed(true)), [onPressIn]);
|
|
451
|
+
const handlePressOut = (0, import_react7.useCallback)(chain(onPressOut, () => setPressed(false)), [onPressOut]);
|
|
452
|
+
const handleMouseEnter = (0, import_react7.useCallback)(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
|
|
453
|
+
const handleMouseLeave = (0, import_react7.useCallback)(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
|
|
454
|
+
const handleFocus = (0, import_react7.useCallback)(chain(onFocus, () => setFocused(true)), [onFocus]);
|
|
455
|
+
const handleBlur = (0, import_react7.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
|
|
456
|
+
const computedStyle = (0, import_react7.useMemo)(
|
|
457
|
+
() => (0, import_core5.flatten)(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused }),
|
|
458
|
+
[resolvedStyle, isDark, pressed, hovered, focused]
|
|
459
|
+
);
|
|
460
|
+
const finalStyle = styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
461
|
+
const { children, ...restWithoutChildren } = rest;
|
|
462
|
+
const componentProps = {
|
|
463
|
+
ref,
|
|
464
|
+
...restWithoutChildren,
|
|
465
|
+
style: finalStyle,
|
|
466
|
+
...import_core5.isWeb && className ? { className } : {},
|
|
467
|
+
onPressIn: handlePressIn,
|
|
468
|
+
onPressOut: handlePressOut,
|
|
469
|
+
onMouseEnter: handleMouseEnter,
|
|
470
|
+
onMouseLeave: handleMouseLeave,
|
|
471
|
+
onFocus: handleFocus,
|
|
472
|
+
onBlur: handleBlur
|
|
473
|
+
};
|
|
474
|
+
return Array.isArray(children) ? import_react7.default.createElement(Component, componentProps, ...children) : import_react7.default.createElement(Component, componentProps, children);
|
|
475
|
+
}
|
|
476
|
+
);
|
|
477
|
+
InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
|
|
478
|
+
|
|
479
|
+
// src/tw.ts
|
|
480
|
+
var import_core6 = require("@kbach/core");
|
|
481
|
+
function tw(classString, isDark = false) {
|
|
482
|
+
const config = (0, import_core6.getConfig)();
|
|
483
|
+
const resolved = (0, import_core6.resolve)(classString, config.theme, config.darkMode);
|
|
484
|
+
if (import_core6.isWeb) {
|
|
485
|
+
return classString;
|
|
486
|
+
}
|
|
487
|
+
return (0, import_core6.flatten)(resolved, isDark);
|
|
488
|
+
}
|
|
489
|
+
function cx(...classes) {
|
|
490
|
+
return classes.filter(Boolean).join(" ");
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/index.ts
|
|
494
|
+
var import_core7 = require("@kbach/core");
|
|
495
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
496
|
+
0 && (module.exports = {
|
|
497
|
+
InteractiveWrapper,
|
|
498
|
+
ThemeContext,
|
|
499
|
+
ThemeProvider,
|
|
500
|
+
ThemeToggle,
|
|
501
|
+
cx,
|
|
502
|
+
defaultColors,
|
|
503
|
+
defaultTheme,
|
|
504
|
+
flatten,
|
|
505
|
+
getConfig,
|
|
506
|
+
parseClass,
|
|
507
|
+
parseClasses,
|
|
508
|
+
resolve,
|
|
509
|
+
styled,
|
|
510
|
+
tw,
|
|
511
|
+
updateConfig,
|
|
512
|
+
useGlobalDarkMode,
|
|
513
|
+
useResolvedStyle,
|
|
514
|
+
useStyles,
|
|
515
|
+
useTheme
|
|
516
|
+
});
|