@kbach/react 0.3.4 → 0.3.6
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-J322Q3UR.mjs → chunk-ALKTUEAA.mjs} +71 -15
- package/dist/{chunk-ADRZPFQC.mjs → chunk-UFSME6UC.mjs} +124 -17
- package/dist/index.d.mts +35 -6
- package/dist/index.d.ts +35 -6
- package/dist/index.js +190 -38
- package/dist/index.mjs +60 -4
- package/dist/jsx-dev-runtime.js +179 -43
- package/dist/jsx-dev-runtime.mjs +2 -2
- package/dist/jsx-runtime.js +179 -43
- package/dist/jsx-runtime.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
+
EMPTY_BREAKPOINTS,
|
|
2
3
|
InteractiveWrapper,
|
|
3
4
|
flatten,
|
|
5
|
+
getActiveBreakpoints,
|
|
4
6
|
getConfig,
|
|
5
7
|
isWeb,
|
|
6
8
|
resolve,
|
|
9
|
+
useConditionalWidth,
|
|
7
10
|
useGlobalDarkMode
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-UFSME6UC.mjs";
|
|
9
12
|
|
|
10
13
|
// src/jsx-runtime.tsx
|
|
11
14
|
import { jsx as _jsx, jsxs as _jsxs, Fragment } from "react/jsx-runtime";
|
|
12
15
|
|
|
13
16
|
// src/DarkWrapper.tsx
|
|
14
17
|
import React from "react";
|
|
18
|
+
var RESPONSIVE_MODS = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
19
|
+
function hasResponsiveBuckets(resolved) {
|
|
20
|
+
for (const key of Object.keys(resolved)) {
|
|
21
|
+
if (key === "base") continue;
|
|
22
|
+
for (const mod of key.split(":")) {
|
|
23
|
+
if (RESPONSIVE_MODS.has(mod)) return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
15
28
|
var DarkWrapper = React.forwardRef(
|
|
16
29
|
function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
|
|
17
30
|
const isDark = useGlobalDarkMode();
|
|
18
|
-
const
|
|
31
|
+
const needsWidth = !isWeb && hasResponsiveBuckets(resolvedStyle);
|
|
32
|
+
const width = useConditionalWidth(needsWidth);
|
|
33
|
+
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
34
|
+
const computedStyle = flatten(resolvedStyle, isDark, {}, breakpoints);
|
|
19
35
|
const finalStyle = styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
20
36
|
const props = { ref, ...rest, style: finalStyle };
|
|
21
37
|
return Array.isArray(children) ? React.createElement(Component, props, ...children) : React.createElement(Component, props, children);
|
|
@@ -24,14 +40,56 @@ var DarkWrapper = React.forwardRef(
|
|
|
24
40
|
DarkWrapper.displayName = "Kbach.DarkWrapper";
|
|
25
41
|
|
|
26
42
|
// src/jsx-runtime.tsx
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
var INTERACTIVE_MODS = /* @__PURE__ */ new Set([
|
|
44
|
+
"hover",
|
|
45
|
+
"not-hover",
|
|
46
|
+
"focus",
|
|
47
|
+
"not-focus",
|
|
48
|
+
"active",
|
|
49
|
+
"not-active",
|
|
50
|
+
"pressed",
|
|
51
|
+
"not-pressed",
|
|
52
|
+
"disabled",
|
|
53
|
+
"not-disabled",
|
|
54
|
+
"checked",
|
|
55
|
+
"not-checked",
|
|
56
|
+
"visited",
|
|
57
|
+
"not-visited",
|
|
58
|
+
"placeholder",
|
|
59
|
+
"focus-within",
|
|
60
|
+
"focus-visible",
|
|
61
|
+
"group-hover",
|
|
62
|
+
"group-focus",
|
|
63
|
+
"peer-hover",
|
|
64
|
+
"peer-focus",
|
|
65
|
+
"first",
|
|
66
|
+
"last",
|
|
67
|
+
"odd",
|
|
68
|
+
"even",
|
|
69
|
+
"only"
|
|
70
|
+
]);
|
|
71
|
+
var RESPONSIVE_MODS2 = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
72
|
+
var MODE_MODS_JSX = /* @__PURE__ */ new Set(["dark", "light", "not-dark", "not-light"]);
|
|
73
|
+
function bucketMods(resolved) {
|
|
74
|
+
let interactive = false;
|
|
75
|
+
let modeOrResponsive = false;
|
|
76
|
+
for (const key of Object.keys(resolved)) {
|
|
77
|
+
if (key === "base") continue;
|
|
78
|
+
const parts = key.split(":");
|
|
79
|
+
for (const mod of parts) {
|
|
80
|
+
if (INTERACTIVE_MODS.has(mod)) {
|
|
81
|
+
interactive = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const mod of parts) {
|
|
86
|
+
if (MODE_MODS_JSX.has(mod) || RESPONSIVE_MODS2.has(mod)) {
|
|
87
|
+
modeOrResponsive = true;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { interactive, modeOrResponsive };
|
|
35
93
|
}
|
|
36
94
|
var CONSUMED_PROPS = /* @__PURE__ */ new Set(["className", "kb", "__kbachStyles", "__kbachClasses"]);
|
|
37
95
|
function omitConsumed(props) {
|
|
@@ -59,7 +117,8 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
59
117
|
const config = getConfig();
|
|
60
118
|
const resolved = __kbachStyles ?? (classStr ? resolve(classStr, config.theme, config.darkMode) : {});
|
|
61
119
|
const { style: userStyle, ...passProps } = omitConsumed(rawProps);
|
|
62
|
-
|
|
120
|
+
const { interactive, modeOrResponsive } = bucketMods(resolved);
|
|
121
|
+
if (interactive) {
|
|
63
122
|
return _jsx(InteractiveWrapper, {
|
|
64
123
|
Component: type,
|
|
65
124
|
resolvedStyle: resolved,
|
|
@@ -68,10 +127,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
68
127
|
...passProps
|
|
69
128
|
}, key);
|
|
70
129
|
}
|
|
71
|
-
|
|
72
|
-
(k) => k !== "base" && MODE_BUCKET_RE.test(k)
|
|
73
|
-
);
|
|
74
|
-
if (hasModeVariants) {
|
|
130
|
+
if (modeOrResponsive) {
|
|
75
131
|
return _jsx(DarkWrapper, {
|
|
76
132
|
Component: type,
|
|
77
133
|
resolvedStyle: resolved,
|
|
@@ -507,10 +507,14 @@ var defaultTheme = {
|
|
|
507
507
|
}
|
|
508
508
|
},
|
|
509
509
|
screens: {
|
|
510
|
-
sm:
|
|
510
|
+
sm: 390,
|
|
511
|
+
// large phones (iPhone 12+, most Android flagships)
|
|
511
512
|
md: 768,
|
|
513
|
+
// tablets (iPad and up)
|
|
512
514
|
lg: 1024,
|
|
515
|
+
// large tablets (iPad Pro)
|
|
513
516
|
xl: 1280,
|
|
517
|
+
// desktop
|
|
514
518
|
"2xl": 1536
|
|
515
519
|
}
|
|
516
520
|
};
|
|
@@ -1838,6 +1842,48 @@ var LRUCache = class {
|
|
|
1838
1842
|
}
|
|
1839
1843
|
};
|
|
1840
1844
|
|
|
1845
|
+
// src/core/responsiveStore.ts
|
|
1846
|
+
var RESPONSIVE_KEY = "__kbach_responsive__";
|
|
1847
|
+
function getStore() {
|
|
1848
|
+
const g = globalThis;
|
|
1849
|
+
if (!g[RESPONSIVE_KEY]) {
|
|
1850
|
+
g[RESPONSIVE_KEY] = { width: 0, screens: {}, listeners: /* @__PURE__ */ new Set() };
|
|
1851
|
+
}
|
|
1852
|
+
return g[RESPONSIVE_KEY];
|
|
1853
|
+
}
|
|
1854
|
+
function syncGlobalWidth(width) {
|
|
1855
|
+
getStore().width = width;
|
|
1856
|
+
}
|
|
1857
|
+
function syncGlobalScreens(screens) {
|
|
1858
|
+
getStore().screens = screens;
|
|
1859
|
+
}
|
|
1860
|
+
function getGlobalScreens() {
|
|
1861
|
+
return getStore().screens;
|
|
1862
|
+
}
|
|
1863
|
+
function setGlobalWidth(width) {
|
|
1864
|
+
const store = getStore();
|
|
1865
|
+
if (store.width === width) return;
|
|
1866
|
+
store.width = width;
|
|
1867
|
+
for (const l of store.listeners) l(width);
|
|
1868
|
+
}
|
|
1869
|
+
function getGlobalWidth() {
|
|
1870
|
+
return getStore().width;
|
|
1871
|
+
}
|
|
1872
|
+
function subscribeGlobalWidth(listener) {
|
|
1873
|
+
const store = getStore();
|
|
1874
|
+
store.listeners.add(listener);
|
|
1875
|
+
return () => store.listeners.delete(listener);
|
|
1876
|
+
}
|
|
1877
|
+
function getActiveBreakpoints(width) {
|
|
1878
|
+
const store = getStore();
|
|
1879
|
+
const w = width ?? store.width;
|
|
1880
|
+
const active = /* @__PURE__ */ new Set();
|
|
1881
|
+
for (const [name, minW] of Object.entries(store.screens)) {
|
|
1882
|
+
if (typeof minW === "number" && w >= minW) active.add(name);
|
|
1883
|
+
}
|
|
1884
|
+
return active;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1841
1887
|
// src/core/resolver.ts
|
|
1842
1888
|
var styleCache = new LRUCache(1e4);
|
|
1843
1889
|
var _styleEl = null;
|
|
@@ -1888,6 +1934,7 @@ var GROUP_PEER_PREFIX = {
|
|
|
1888
1934
|
"peer-focus": ".peer:focus ~"
|
|
1889
1935
|
};
|
|
1890
1936
|
var MODE_MODS = /* @__PURE__ */ new Set(["dark", "light", "not-dark", "not-light"]);
|
|
1937
|
+
var RESPONSIVE_MODS = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
1891
1938
|
function injectClassRule(cls, bucketKey, styles, darkMode) {
|
|
1892
1939
|
const cssDecls = styleValueToCSS(styles);
|
|
1893
1940
|
if (!cssDecls) return;
|
|
@@ -1897,10 +1944,12 @@ function injectClassRule(cls, bucketKey, styles, darkMode) {
|
|
|
1897
1944
|
return;
|
|
1898
1945
|
}
|
|
1899
1946
|
const mods = bucketKey.split(":");
|
|
1900
|
-
const
|
|
1901
|
-
const
|
|
1902
|
-
const
|
|
1903
|
-
const
|
|
1947
|
+
const responsiveMods = mods.filter((m) => RESPONSIVE_MODS.has(m));
|
|
1948
|
+
const nonResponsiveMods = mods.filter((m) => !RESPONSIVE_MODS.has(m));
|
|
1949
|
+
const hasDark = nonResponsiveMods.includes("dark") || nonResponsiveMods.includes("not-light");
|
|
1950
|
+
const hasLight = nonResponsiveMods.includes("light") || nonResponsiveMods.includes("not-dark");
|
|
1951
|
+
const ancestorMods = nonResponsiveMods.filter((m) => m in GROUP_PEER_PREFIX);
|
|
1952
|
+
const pseudoMods = nonResponsiveMods.filter((m) => !MODE_MODS.has(m) && !(m in GROUP_PEER_PREFIX));
|
|
1904
1953
|
const pseudoSuffix = pseudoMods.map((p) => MODIFIER_TO_PSEUDO[p] ?? `:${p}`).join("");
|
|
1905
1954
|
const elementSelector = `.${escaped}${pseudoSuffix}`;
|
|
1906
1955
|
const ancestorPrefix = ancestorMods.length ? ancestorMods.map((m) => GROUP_PEER_PREFIX[m]).join(" ") + " " : "";
|
|
@@ -1925,6 +1974,13 @@ function injectClassRule(cls, bucketKey, styles, darkMode) {
|
|
|
1925
1974
|
} else {
|
|
1926
1975
|
rule = `${selector} { ${cssDecls} }`;
|
|
1927
1976
|
}
|
|
1977
|
+
if (responsiveMods.length > 0) {
|
|
1978
|
+
const screens = getGlobalScreens();
|
|
1979
|
+
const minWidth = Math.max(...responsiveMods.map((m) => screens[m] ?? 0));
|
|
1980
|
+
if (minWidth > 0) {
|
|
1981
|
+
rule = `@media (min-width: ${minWidth}px) { ${rule} }`;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1928
1984
|
injectRule(rule);
|
|
1929
1985
|
}
|
|
1930
1986
|
var RN_ONLY_PROPS = /* @__PURE__ */ new Set([
|
|
@@ -1993,18 +2049,18 @@ function resolve(classString, theme, darkMode = "attribute") {
|
|
|
1993
2049
|
}
|
|
1994
2050
|
return result;
|
|
1995
2051
|
}
|
|
1996
|
-
function flatten(resolved, isDark, state = {}) {
|
|
2052
|
+
function flatten(resolved, isDark, state = {}, breakpoints = /* @__PURE__ */ new Set()) {
|
|
1997
2053
|
const result = { ...resolved.base ?? {} };
|
|
1998
2054
|
for (const [key, styles] of Object.entries(resolved)) {
|
|
1999
2055
|
if (key === "base" || !styles) continue;
|
|
2000
2056
|
const mods = key.split(":");
|
|
2001
|
-
if (matchesMods(mods, isDark, state)) {
|
|
2057
|
+
if (matchesMods(mods, isDark, state, breakpoints)) {
|
|
2002
2058
|
Object.assign(result, styles);
|
|
2003
2059
|
}
|
|
2004
2060
|
}
|
|
2005
2061
|
return result;
|
|
2006
2062
|
}
|
|
2007
|
-
function matchesMods(mods, isDark, state) {
|
|
2063
|
+
function matchesMods(mods, isDark, state, breakpoints) {
|
|
2008
2064
|
return mods.every((mod) => {
|
|
2009
2065
|
switch (mod) {
|
|
2010
2066
|
case "dark":
|
|
@@ -2042,6 +2098,12 @@ function matchesMods(mods, isDark, state) {
|
|
|
2042
2098
|
return !state.visited;
|
|
2043
2099
|
case "placeholder":
|
|
2044
2100
|
return !!state.placeholder;
|
|
2101
|
+
case "sm":
|
|
2102
|
+
case "md":
|
|
2103
|
+
case "lg":
|
|
2104
|
+
case "xl":
|
|
2105
|
+
case "2xl":
|
|
2106
|
+
return breakpoints.has(mod);
|
|
2045
2107
|
default:
|
|
2046
2108
|
return false;
|
|
2047
2109
|
}
|
|
@@ -2201,7 +2263,7 @@ var customVariants = new Proxy(
|
|
|
2201
2263
|
|
|
2202
2264
|
// src/core/darkModeStore.ts
|
|
2203
2265
|
var KEY = "__kbach_dark_store__";
|
|
2204
|
-
function
|
|
2266
|
+
function getStore2() {
|
|
2205
2267
|
const g = globalThis;
|
|
2206
2268
|
if (!g[KEY]) {
|
|
2207
2269
|
g[KEY] = { isDark: false, lastNotified: false, subscribers: /* @__PURE__ */ new Set() };
|
|
@@ -2209,20 +2271,20 @@ function getStore() {
|
|
|
2209
2271
|
return g[KEY];
|
|
2210
2272
|
}
|
|
2211
2273
|
function syncGlobalDarkMode(isDark) {
|
|
2212
|
-
|
|
2274
|
+
getStore2().isDark = isDark;
|
|
2213
2275
|
}
|
|
2214
2276
|
function setGlobalDarkMode(isDark) {
|
|
2215
|
-
const store =
|
|
2277
|
+
const store = getStore2();
|
|
2216
2278
|
store.isDark = isDark;
|
|
2217
2279
|
if (store.lastNotified === isDark) return;
|
|
2218
2280
|
store.lastNotified = isDark;
|
|
2219
2281
|
for (const sub of store.subscribers) sub();
|
|
2220
2282
|
}
|
|
2221
2283
|
function getGlobalDarkMode() {
|
|
2222
|
-
return
|
|
2284
|
+
return getStore2().isDark;
|
|
2223
2285
|
}
|
|
2224
2286
|
function subscribeGlobalDarkMode(callback) {
|
|
2225
|
-
const store =
|
|
2287
|
+
const store = getStore2();
|
|
2226
2288
|
store.subscribers.add(callback);
|
|
2227
2289
|
return () => store.subscribers.delete(callback);
|
|
2228
2290
|
}
|
|
@@ -2244,13 +2306,47 @@ function useGlobalDarkMode() {
|
|
|
2244
2306
|
}
|
|
2245
2307
|
|
|
2246
2308
|
// src/InteractiveWrapper.tsx
|
|
2247
|
-
import
|
|
2309
|
+
import React3, { forwardRef, useState, useCallback, useMemo } from "react";
|
|
2310
|
+
|
|
2311
|
+
// src/useGlobalWidth.ts
|
|
2312
|
+
import React2 from "react";
|
|
2313
|
+
var useSyncExternalStore2 = React2.useSyncExternalStore ?? function useSyncExternalStoreFallback2(subscribe, getSnapshot, _getServerSnapshot) {
|
|
2314
|
+
const [, forceUpdate] = React2.useReducer((n) => n + 1, 0);
|
|
2315
|
+
React2.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
2316
|
+
return getSnapshot();
|
|
2317
|
+
};
|
|
2318
|
+
var NOOP_SUB = (_) => () => {
|
|
2319
|
+
};
|
|
2320
|
+
var ZERO_SNAP = () => 0;
|
|
2321
|
+
var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
|
|
2322
|
+
function useGlobalWidth() {
|
|
2323
|
+
return useSyncExternalStore2(subscribeGlobalWidth, getGlobalWidth, ZERO_SNAP);
|
|
2324
|
+
}
|
|
2325
|
+
function useConditionalWidth(active) {
|
|
2326
|
+
return useSyncExternalStore2(
|
|
2327
|
+
active ? subscribeGlobalWidth : NOOP_SUB,
|
|
2328
|
+
active ? getGlobalWidth : ZERO_SNAP,
|
|
2329
|
+
ZERO_SNAP
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// src/InteractiveWrapper.tsx
|
|
2248
2334
|
function chain(original, extra) {
|
|
2249
2335
|
return (...args) => {
|
|
2250
2336
|
original?.(...args);
|
|
2251
2337
|
extra();
|
|
2252
2338
|
};
|
|
2253
2339
|
}
|
|
2340
|
+
var RESPONSIVE_MODS2 = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
2341
|
+
function hasResponsiveBuckets(resolved) {
|
|
2342
|
+
for (const key of Object.keys(resolved)) {
|
|
2343
|
+
if (key === "base") continue;
|
|
2344
|
+
for (const mod of key.split(":")) {
|
|
2345
|
+
if (RESPONSIVE_MODS2.has(mod)) return true;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return false;
|
|
2349
|
+
}
|
|
2254
2350
|
var InteractiveWrapper = forwardRef(
|
|
2255
2351
|
function InteractiveWrapper2({
|
|
2256
2352
|
Component,
|
|
@@ -2266,6 +2362,9 @@ var InteractiveWrapper = forwardRef(
|
|
|
2266
2362
|
...rest
|
|
2267
2363
|
}, ref) {
|
|
2268
2364
|
const isDark = useGlobalDarkMode();
|
|
2365
|
+
const needsWidth = !isWeb && hasResponsiveBuckets(resolvedStyle);
|
|
2366
|
+
const width = useConditionalWidth(needsWidth);
|
|
2367
|
+
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
2269
2368
|
const [pressed, setPressed] = useState(false);
|
|
2270
2369
|
const [hovered, setHovered] = useState(false);
|
|
2271
2370
|
const [focused, setFocused] = useState(false);
|
|
@@ -2276,8 +2375,9 @@ var InteractiveWrapper = forwardRef(
|
|
|
2276
2375
|
const handleFocus = useCallback(chain(onFocus, () => setFocused(true)), [onFocus]);
|
|
2277
2376
|
const handleBlur = useCallback(chain(onBlur, () => setFocused(false)), [onBlur]);
|
|
2278
2377
|
const computedStyle = useMemo(
|
|
2279
|
-
() => flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused }),
|
|
2280
|
-
[resolvedStyle, isDark, pressed, hovered, focused]
|
|
2378
|
+
() => flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused }, breakpoints),
|
|
2379
|
+
[resolvedStyle, isDark, pressed, hovered, focused, width]
|
|
2380
|
+
// eslint-disable-line react-hooks/exhaustive-deps
|
|
2281
2381
|
);
|
|
2282
2382
|
const finalStyle = styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
2283
2383
|
const { children, ...restWithoutChildren } = rest;
|
|
@@ -2293,7 +2393,7 @@ var InteractiveWrapper = forwardRef(
|
|
|
2293
2393
|
onFocus: handleFocus,
|
|
2294
2394
|
onBlur: handleBlur
|
|
2295
2395
|
};
|
|
2296
|
-
return Array.isArray(children) ?
|
|
2396
|
+
return Array.isArray(children) ? React3.createElement(Component, componentProps, ...children) : React3.createElement(Component, componentProps, children);
|
|
2297
2397
|
}
|
|
2298
2398
|
);
|
|
2299
2399
|
InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
|
|
@@ -2305,6 +2405,10 @@ export {
|
|
|
2305
2405
|
isWeb,
|
|
2306
2406
|
parseClass,
|
|
2307
2407
|
parseClasses,
|
|
2408
|
+
syncGlobalWidth,
|
|
2409
|
+
syncGlobalScreens,
|
|
2410
|
+
setGlobalWidth,
|
|
2411
|
+
getActiveBreakpoints,
|
|
2308
2412
|
resolve,
|
|
2309
2413
|
flatten,
|
|
2310
2414
|
getConfig,
|
|
@@ -2314,6 +2418,9 @@ export {
|
|
|
2314
2418
|
initConfig,
|
|
2315
2419
|
syncGlobalDarkMode,
|
|
2316
2420
|
setGlobalDarkMode,
|
|
2421
|
+
EMPTY_BREAKPOINTS,
|
|
2422
|
+
useGlobalWidth,
|
|
2423
|
+
useConditionalWidth,
|
|
2317
2424
|
useGlobalDarkMode,
|
|
2318
2425
|
InteractiveWrapper
|
|
2319
2426
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -100,9 +100,11 @@ declare function resolve(classString: string, theme: ThemeConfig, darkMode?: 'at
|
|
|
100
100
|
* Flatten a ResolvedStyle into a single StyleValue for the given runtime state.
|
|
101
101
|
* Used by useStyles() and styled().
|
|
102
102
|
*
|
|
103
|
-
* @param resolved
|
|
104
|
-
* @param isDark
|
|
105
|
-
* @param state
|
|
103
|
+
* @param resolved Output of resolve()
|
|
104
|
+
* @param isDark Whether dark mode is currently active
|
|
105
|
+
* @param state Interaction state flags
|
|
106
|
+
* @param breakpoints Active breakpoint names (sm, md, lg, xl, 2xl). On web,
|
|
107
|
+
* pass an empty Set — CSS @media rules handle responsive.
|
|
106
108
|
*/
|
|
107
109
|
declare function flatten(resolved: ResolvedStyle, isDark: boolean, state?: {
|
|
108
110
|
hover?: boolean;
|
|
@@ -113,7 +115,7 @@ declare function flatten(resolved: ResolvedStyle, isDark: boolean, state?: {
|
|
|
113
115
|
checked?: boolean;
|
|
114
116
|
visited?: boolean;
|
|
115
117
|
placeholder?: boolean;
|
|
116
|
-
}): StyleValue;
|
|
118
|
+
}, breakpoints?: Set<string>): StyleValue;
|
|
117
119
|
|
|
118
120
|
/**
|
|
119
121
|
* Load, merge, and cache the resolved config.
|
|
@@ -185,12 +187,19 @@ interface ThemeProviderProps {
|
|
|
185
187
|
* ```
|
|
186
188
|
*/
|
|
187
189
|
colorScheme?: 'light' | 'dark' | null;
|
|
190
|
+
/**
|
|
191
|
+
* Current window/screen width in pixels for responsive breakpoints.
|
|
192
|
+
* On web this is read from `window.innerWidth` automatically.
|
|
193
|
+
* When importing `ThemeProvider` from `@kbach/native` this is provided
|
|
194
|
+
* automatically from `useWindowDimensions()`.
|
|
195
|
+
*/
|
|
196
|
+
windowWidth?: number;
|
|
188
197
|
/** Override the config (useful for per-tree config). Defaults to global getConfig(). */
|
|
189
198
|
config?: FrameworkConfig;
|
|
190
199
|
/** Disable persistence to localStorage */
|
|
191
200
|
disablePersistence?: boolean;
|
|
192
201
|
}
|
|
193
|
-
declare function ThemeProvider({ children, defaultMode, colorScheme, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
|
|
202
|
+
declare function ThemeProvider({ children, defaultMode, colorScheme, windowWidth: windowWidthProp, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
|
|
194
203
|
|
|
195
204
|
type ToggleVariant = 'button' | 'switch' | 'icon-button';
|
|
196
205
|
interface ThemeToggleProps {
|
|
@@ -281,6 +290,26 @@ declare function useResolvedStyle(classString: string | string[]): ResolvedStyle
|
|
|
281
290
|
*/
|
|
282
291
|
declare function useGlobalDarkMode(): boolean;
|
|
283
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Returns the name of the currently active breakpoint — the largest breakpoint
|
|
295
|
+
* whose min-width the window satisfies, or `'xs'` when below all breakpoints.
|
|
296
|
+
*
|
|
297
|
+
* ```ts
|
|
298
|
+
* const bp = useBreakpoint(); // 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare function useBreakpoint(): string;
|
|
302
|
+
/**
|
|
303
|
+
* Returns a record of boolean flags for each breakpoint — `true` when the
|
|
304
|
+
* window width satisfies that breakpoint's min-width threshold.
|
|
305
|
+
*
|
|
306
|
+
* ```ts
|
|
307
|
+
* const { sm, md, lg } = useResponsive();
|
|
308
|
+
* const padding = lg ? 32 : sm ? 16 : 8;
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
declare function useResponsive(): Record<string, boolean>;
|
|
312
|
+
|
|
284
313
|
interface InteractiveWrapperProps {
|
|
285
314
|
/** The real component to render (View, TouchableOpacity, div, a third-party button…) */
|
|
286
315
|
Component: React__default.ComponentType<any> | string;
|
|
@@ -342,4 +371,4 @@ declare function kb(classString: string, isDark?: boolean): StyleValue | string;
|
|
|
342
371
|
*/
|
|
343
372
|
declare function cx(...classes: Array<string | false | null | undefined>): string;
|
|
344
373
|
|
|
345
|
-
export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, initConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useStyles, useTheme, wrapColors };
|
|
374
|
+
export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, initConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useBreakpoint, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useResponsive, useStyles, useTheme, wrapColors };
|
package/dist/index.d.ts
CHANGED
|
@@ -100,9 +100,11 @@ declare function resolve(classString: string, theme: ThemeConfig, darkMode?: 'at
|
|
|
100
100
|
* Flatten a ResolvedStyle into a single StyleValue for the given runtime state.
|
|
101
101
|
* Used by useStyles() and styled().
|
|
102
102
|
*
|
|
103
|
-
* @param resolved
|
|
104
|
-
* @param isDark
|
|
105
|
-
* @param state
|
|
103
|
+
* @param resolved Output of resolve()
|
|
104
|
+
* @param isDark Whether dark mode is currently active
|
|
105
|
+
* @param state Interaction state flags
|
|
106
|
+
* @param breakpoints Active breakpoint names (sm, md, lg, xl, 2xl). On web,
|
|
107
|
+
* pass an empty Set — CSS @media rules handle responsive.
|
|
106
108
|
*/
|
|
107
109
|
declare function flatten(resolved: ResolvedStyle, isDark: boolean, state?: {
|
|
108
110
|
hover?: boolean;
|
|
@@ -113,7 +115,7 @@ declare function flatten(resolved: ResolvedStyle, isDark: boolean, state?: {
|
|
|
113
115
|
checked?: boolean;
|
|
114
116
|
visited?: boolean;
|
|
115
117
|
placeholder?: boolean;
|
|
116
|
-
}): StyleValue;
|
|
118
|
+
}, breakpoints?: Set<string>): StyleValue;
|
|
117
119
|
|
|
118
120
|
/**
|
|
119
121
|
* Load, merge, and cache the resolved config.
|
|
@@ -185,12 +187,19 @@ interface ThemeProviderProps {
|
|
|
185
187
|
* ```
|
|
186
188
|
*/
|
|
187
189
|
colorScheme?: 'light' | 'dark' | null;
|
|
190
|
+
/**
|
|
191
|
+
* Current window/screen width in pixels for responsive breakpoints.
|
|
192
|
+
* On web this is read from `window.innerWidth` automatically.
|
|
193
|
+
* When importing `ThemeProvider` from `@kbach/native` this is provided
|
|
194
|
+
* automatically from `useWindowDimensions()`.
|
|
195
|
+
*/
|
|
196
|
+
windowWidth?: number;
|
|
188
197
|
/** Override the config (useful for per-tree config). Defaults to global getConfig(). */
|
|
189
198
|
config?: FrameworkConfig;
|
|
190
199
|
/** Disable persistence to localStorage */
|
|
191
200
|
disablePersistence?: boolean;
|
|
192
201
|
}
|
|
193
|
-
declare function ThemeProvider({ children, defaultMode, colorScheme, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
|
|
202
|
+
declare function ThemeProvider({ children, defaultMode, colorScheme, windowWidth: windowWidthProp, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
|
|
194
203
|
|
|
195
204
|
type ToggleVariant = 'button' | 'switch' | 'icon-button';
|
|
196
205
|
interface ThemeToggleProps {
|
|
@@ -281,6 +290,26 @@ declare function useResolvedStyle(classString: string | string[]): ResolvedStyle
|
|
|
281
290
|
*/
|
|
282
291
|
declare function useGlobalDarkMode(): boolean;
|
|
283
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Returns the name of the currently active breakpoint — the largest breakpoint
|
|
295
|
+
* whose min-width the window satisfies, or `'xs'` when below all breakpoints.
|
|
296
|
+
*
|
|
297
|
+
* ```ts
|
|
298
|
+
* const bp = useBreakpoint(); // 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare function useBreakpoint(): string;
|
|
302
|
+
/**
|
|
303
|
+
* Returns a record of boolean flags for each breakpoint — `true` when the
|
|
304
|
+
* window width satisfies that breakpoint's min-width threshold.
|
|
305
|
+
*
|
|
306
|
+
* ```ts
|
|
307
|
+
* const { sm, md, lg } = useResponsive();
|
|
308
|
+
* const padding = lg ? 32 : sm ? 16 : 8;
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
declare function useResponsive(): Record<string, boolean>;
|
|
312
|
+
|
|
284
313
|
interface InteractiveWrapperProps {
|
|
285
314
|
/** The real component to render (View, TouchableOpacity, div, a third-party button…) */
|
|
286
315
|
Component: React__default.ComponentType<any> | string;
|
|
@@ -342,4 +371,4 @@ declare function kb(classString: string, isDark?: boolean): StyleValue | string;
|
|
|
342
371
|
*/
|
|
343
372
|
declare function cx(...classes: Array<string | false | null | undefined>): string;
|
|
344
373
|
|
|
345
|
-
export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, initConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useStyles, useTheme, wrapColors };
|
|
374
|
+
export { type ColorScale, type ColorsAPI, type FrameworkConfig, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type ParsedClass, type PluginAPI, type ResolvedConfig, type ResolvedStyle, type StyleValue, type StyledProps, type ThemeConfig, ThemeContext, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, ThemeToggle, type ThemeToggleProps, type ToggleVariant, buildConfig, cx, defaultColors, defaultTheme, flatten, getConfig, initConfig, kb, parseClass, parseClasses, resolve, styled, updateConfig, useBreakpoint, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useResponsive, useStyles, useTheme, wrapColors };
|