@kbach/react 0.5.37 → 0.5.40
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/README.md +173 -98
- package/dist/{chunk-VZHNEDUW.mjs → chunk-6NHHYHNV.mjs} +36 -55
- package/dist/{chunk-36QDTNAQ.mjs → chunk-EYPBYQSB.mjs} +16 -10
- package/dist/{chunk-J2I5YSC5.mjs → chunk-IZ3W6G3V.mjs} +411 -1008
- package/dist/index.d.mts +10 -20
- package/dist/index.d.ts +10 -20
- package/dist/index.js +445 -1038
- package/dist/index.mjs +40 -22
- package/dist/jsx-dev-runtime.d.mts +6 -4
- package/dist/jsx-dev-runtime.d.ts +6 -4
- package/dist/jsx-dev-runtime.js +444 -1062
- package/dist/jsx-dev-runtime.mjs +10 -5
- package/dist/jsx-runtime.d.mts +2 -3
- package/dist/jsx-runtime.d.ts +2 -3
- package/dist/jsx-runtime.js +442 -1060
- package/dist/jsx-runtime.mjs +5 -3
- package/dist/types-D-24rbXu.d.mts +126 -0
- package/dist/types-D-24rbXu.d.ts +126 -0
- package/dist/vite-plugin.d.mts +1 -1
- package/dist/vite-plugin.d.ts +1 -1
- package/dist/vite-plugin.js +301 -841
- package/dist/vite-plugin.mjs +76 -25
- package/package.json +4 -2
- package/types.d.ts +1 -0
- package/dist/types-CV5vXnSH.d.mts +0 -70
- package/dist/types-CV5vXnSH.d.ts +0 -70
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EMPTY_BREAKPOINTS,
|
|
3
3
|
InteractiveWrapper,
|
|
4
|
+
hasResponsiveBuckets,
|
|
4
5
|
setGlobalDarkMode,
|
|
5
6
|
syncGlobalDarkMode,
|
|
6
7
|
useConditionalWidth,
|
|
7
8
|
useGlobalDarkMode,
|
|
8
9
|
useGlobalWidth
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EYPBYQSB.mjs";
|
|
10
11
|
import {
|
|
11
12
|
__require,
|
|
12
13
|
buildConfig,
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
syncGlobalScreens,
|
|
28
29
|
syncGlobalWidth,
|
|
29
30
|
updateConfig
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-IZ3W6G3V.mjs";
|
|
31
32
|
|
|
32
33
|
// src/context.tsx
|
|
33
34
|
import { createContext, useContext } from "react";
|
|
@@ -51,7 +52,20 @@ function applyOpacity(color, opacity) {
|
|
|
51
52
|
const a = Math.max(0, Math.min(1, opacity / 100));
|
|
52
53
|
if (color.startsWith("#")) {
|
|
53
54
|
const h = color.slice(1);
|
|
54
|
-
|
|
55
|
+
let rs, gs, bs;
|
|
56
|
+
if (h.length === 3 || h.length === 4) {
|
|
57
|
+
rs = h[0] + h[0];
|
|
58
|
+
gs = h[1] + h[1];
|
|
59
|
+
bs = h[2] + h[2];
|
|
60
|
+
} else if (h.length === 8) {
|
|
61
|
+
rs = h.slice(0, 2);
|
|
62
|
+
gs = h.slice(2, 4);
|
|
63
|
+
bs = h.slice(4, 6);
|
|
64
|
+
} else {
|
|
65
|
+
rs = h.slice(0, 2);
|
|
66
|
+
gs = h.slice(2, 4);
|
|
67
|
+
bs = h.slice(4, 6);
|
|
68
|
+
}
|
|
55
69
|
return `rgba(${parseInt(rs, 16)},${parseInt(gs, 16)},${parseInt(bs, 16)},${a})`;
|
|
56
70
|
}
|
|
57
71
|
if (color.startsWith("rgb(")) return color.replace("rgb(", "rgba(").replace(")", `,${a})`);
|
|
@@ -151,8 +165,16 @@ function ThemeProvider({
|
|
|
151
165
|
() => isWeb && typeof window !== "undefined" ? window.innerWidth : 0
|
|
152
166
|
);
|
|
153
167
|
const effectiveWidth = windowWidthProp ?? (isWeb ? webWidth : 0);
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
const numericScreens = {};
|
|
169
|
+
for (const [k, v] of Object.entries(resolvedConfig.theme.screens ?? {})) {
|
|
170
|
+
numericScreens[k] = typeof v === "number" ? v : parseInt(String(v), 10);
|
|
171
|
+
}
|
|
172
|
+
const _prevWidthRef = useRef(-1);
|
|
173
|
+
if (_prevWidthRef.current !== effectiveWidth) {
|
|
174
|
+
_prevWidthRef.current = effectiveWidth;
|
|
175
|
+
syncGlobalWidth(effectiveWidth);
|
|
176
|
+
}
|
|
177
|
+
syncGlobalScreens(numericScreens);
|
|
156
178
|
useEffect(() => {
|
|
157
179
|
setGlobalWidth(effectiveWidth);
|
|
158
180
|
}, [effectiveWidth]);
|
|
@@ -376,16 +398,6 @@ import React3, {
|
|
|
376
398
|
useCallback as useCallback3,
|
|
377
399
|
useMemo as useMemo3
|
|
378
400
|
} from "react";
|
|
379
|
-
var RESPONSIVE_MODS = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
380
|
-
function hasResponsiveBuckets(resolved) {
|
|
381
|
-
for (const key of Object.keys(resolved)) {
|
|
382
|
-
if (key === "base") continue;
|
|
383
|
-
for (const mod of key.split(":")) {
|
|
384
|
-
if (RESPONSIVE_MODS.has(mod)) return true;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
401
|
function styled(Component, baseClasses = "") {
|
|
390
402
|
const Styled = forwardRef(
|
|
391
403
|
(props, ref) => {
|
|
@@ -480,10 +492,10 @@ import { useMemo as useMemo4 } from "react";
|
|
|
480
492
|
function useStyles(classString, state = {}) {
|
|
481
493
|
const { isDark, config } = useTheme();
|
|
482
494
|
const width = useGlobalWidth();
|
|
483
|
-
const breakpoints = getActiveBreakpoints(width);
|
|
484
495
|
const normalised = Array.isArray(classString) ? classString.join(" ") : classString;
|
|
485
496
|
return useMemo4(() => {
|
|
486
497
|
const resolved = resolve(normalised, config.theme, config.darkMode);
|
|
498
|
+
const breakpoints = getActiveBreakpoints(width);
|
|
487
499
|
return flatten(resolved, isDark, state, breakpoints);
|
|
488
500
|
}, [normalised, isDark, config, width, state.hover, state.focus, state.pressed, state.active, state.disabled, state.checked, state.visited, state.placeholder]);
|
|
489
501
|
}
|
|
@@ -497,11 +509,15 @@ function useResolvedStyle(classString) {
|
|
|
497
509
|
}
|
|
498
510
|
|
|
499
511
|
// src/useBreakpoint.ts
|
|
512
|
+
import { useMemo as useMemo5 } from "react";
|
|
500
513
|
function useBreakpoint() {
|
|
501
514
|
const { config } = useTheme();
|
|
502
515
|
const width = useGlobalWidth();
|
|
503
516
|
const screens = config.theme.screens;
|
|
504
|
-
const sorted =
|
|
517
|
+
const sorted = useMemo5(
|
|
518
|
+
() => Object.entries(screens).filter(([, v]) => typeof v === "number").sort(([, a], [, b]) => b - a),
|
|
519
|
+
[screens]
|
|
520
|
+
);
|
|
505
521
|
for (const [name, minW] of sorted) {
|
|
506
522
|
if (width >= minW) return name;
|
|
507
523
|
}
|
|
@@ -511,11 +527,13 @@ function useResponsive() {
|
|
|
511
527
|
const { config } = useTheme();
|
|
512
528
|
const width = useGlobalWidth();
|
|
513
529
|
const screens = config.theme.screens;
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
530
|
+
return useMemo5(() => {
|
|
531
|
+
const result = {};
|
|
532
|
+
for (const [name, minW] of Object.entries(screens)) {
|
|
533
|
+
if (typeof minW === "number") result[name] = width >= minW;
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
}, [screens, width]);
|
|
519
537
|
}
|
|
520
538
|
|
|
521
539
|
// src/kb.ts
|
|
@@ -6,14 +6,16 @@ export { Fragment } from 'react';
|
|
|
6
6
|
*
|
|
7
7
|
* Development variant of the custom JSX runtime.
|
|
8
8
|
* Babel uses jsxDEV (instead of jsx/jsxs) in dev builds.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* We intercept `className`/`kb` props exactly like the production runtime, but
|
|
11
|
+
* forward `_source` to React's own jsxDEV so React DevTools can display the
|
|
12
|
+
* correct file + line number for every element.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
|
-
declare function jsxDEV(type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean,
|
|
15
|
+
declare function jsxDEV(type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean, source?: {
|
|
14
16
|
fileName: string;
|
|
15
17
|
lineNumber: number;
|
|
16
18
|
columnNumber: number;
|
|
17
|
-
},
|
|
19
|
+
}, self?: unknown): ReactElement;
|
|
18
20
|
|
|
19
21
|
export { jsxDEV };
|
|
@@ -6,14 +6,16 @@ export { Fragment } from 'react';
|
|
|
6
6
|
*
|
|
7
7
|
* Development variant of the custom JSX runtime.
|
|
8
8
|
* Babel uses jsxDEV (instead of jsx/jsxs) in dev builds.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* We intercept `className`/`kb` props exactly like the production runtime, but
|
|
11
|
+
* forward `_source` to React's own jsxDEV so React DevTools can display the
|
|
12
|
+
* correct file + line number for every element.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
|
-
declare function jsxDEV(type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean,
|
|
15
|
+
declare function jsxDEV(type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean, source?: {
|
|
14
16
|
fileName: string;
|
|
15
17
|
lineNumber: number;
|
|
16
18
|
columnNumber: number;
|
|
17
|
-
},
|
|
19
|
+
}, self?: unknown): ReactElement;
|
|
18
20
|
|
|
19
21
|
export { jsxDEV };
|