@kbach/react 0.5.47 → 0.5.48
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-NIBECTRQ.mjs → chunk-BKSXIWL7.mjs} +8 -7
- package/dist/chunk-YZNSWFJT.mjs +544 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +121 -24
- package/dist/index.mjs +30 -16
- package/dist/jsx-dev-runtime.js +116 -29
- package/dist/jsx-dev-runtime.mjs +2 -3
- package/dist/jsx-runtime.d.mts +12 -1
- package/dist/jsx-runtime.d.ts +12 -1
- package/dist/jsx-runtime.js +125 -31
- package/dist/jsx-runtime.mjs +6 -5
- package/dist/vite-plugin.js +29 -18
- package/dist/vite-plugin.mjs +22 -12
- package/package.json +1 -1
- package/dist/chunk-LCK5OGHT.mjs +0 -226
- package/dist/chunk-U3GY5Y6J.mjs +0 -232
package/dist/chunk-U3GY5Y6J.mjs
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flatten,
|
|
3
|
-
getActiveBreakpoints,
|
|
4
|
-
getGlobalWidth,
|
|
5
|
-
getResponsiveModifiers,
|
|
6
|
-
isNative,
|
|
7
|
-
isWeb,
|
|
8
|
-
subscribeGlobalWidth
|
|
9
|
-
} from "./chunk-NIBECTRQ.mjs";
|
|
10
|
-
|
|
11
|
-
// src/core/darkModeStore.ts
|
|
12
|
-
var KEY = "__kbach_dark_store__";
|
|
13
|
-
function getStore() {
|
|
14
|
-
const g = globalThis;
|
|
15
|
-
if (!g[KEY]) {
|
|
16
|
-
g[KEY] = { isDark: false, lastNotified: false, subscribers: /* @__PURE__ */ new Set() };
|
|
17
|
-
}
|
|
18
|
-
return g[KEY];
|
|
19
|
-
}
|
|
20
|
-
function syncGlobalDarkMode(isDark) {
|
|
21
|
-
getStore().isDark = isDark;
|
|
22
|
-
}
|
|
23
|
-
function setGlobalDarkMode(isDark) {
|
|
24
|
-
const store = getStore();
|
|
25
|
-
store.isDark = isDark;
|
|
26
|
-
if (store.lastNotified === isDark) return;
|
|
27
|
-
store.lastNotified = isDark;
|
|
28
|
-
for (const sub of store.subscribers) sub();
|
|
29
|
-
}
|
|
30
|
-
function getGlobalDarkMode() {
|
|
31
|
-
return getStore().isDark;
|
|
32
|
-
}
|
|
33
|
-
function subscribeGlobalDarkMode(callback) {
|
|
34
|
-
const store = getStore();
|
|
35
|
-
store.subscribers.add(callback);
|
|
36
|
-
return () => store.subscribers.delete(callback);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// src/useGlobalDarkMode.ts
|
|
40
|
-
import React from "react";
|
|
41
|
-
var useSyncExternalStore = React.useSyncExternalStore ?? function useSyncExternalStoreFallback(subscribe, getSnapshot, _getServerSnapshot) {
|
|
42
|
-
const [, forceUpdate] = React.useReducer((n) => n + 1, 0);
|
|
43
|
-
React.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
44
|
-
return getSnapshot();
|
|
45
|
-
};
|
|
46
|
-
function useGlobalDarkMode() {
|
|
47
|
-
return useSyncExternalStore(
|
|
48
|
-
subscribeGlobalDarkMode,
|
|
49
|
-
getGlobalDarkMode,
|
|
50
|
-
() => false
|
|
51
|
-
// SSR: default light
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/InteractiveWrapper.tsx
|
|
56
|
-
import React3, { forwardRef, useState, useCallback, useMemo } from "react";
|
|
57
|
-
|
|
58
|
-
// src/useGlobalWidth.ts
|
|
59
|
-
import React2 from "react";
|
|
60
|
-
var useSyncExternalStore2 = React2.useSyncExternalStore ?? function useSyncExternalStoreFallback2(subscribe, getSnapshot, _getServerSnapshot) {
|
|
61
|
-
const [, forceUpdate] = React2.useReducer((n) => n + 1, 0);
|
|
62
|
-
React2.useEffect(() => subscribe(forceUpdate), [subscribe]);
|
|
63
|
-
return getSnapshot();
|
|
64
|
-
};
|
|
65
|
-
var NOOP_SUB = (_) => () => {
|
|
66
|
-
};
|
|
67
|
-
var ZERO_SNAP = () => 0;
|
|
68
|
-
var EMPTY_BREAKPOINTS = /* @__PURE__ */ new Set();
|
|
69
|
-
var _webListeners = null;
|
|
70
|
-
var _webRaf = 0;
|
|
71
|
-
function _webResizeHandler() {
|
|
72
|
-
cancelAnimationFrame(_webRaf);
|
|
73
|
-
_webRaf = requestAnimationFrame(() => {
|
|
74
|
-
if (_webListeners) for (const cb of _webListeners) cb();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function subscribeWebWidth(cb) {
|
|
78
|
-
if (typeof window === "undefined") return () => {
|
|
79
|
-
};
|
|
80
|
-
if (!_webListeners) {
|
|
81
|
-
_webListeners = /* @__PURE__ */ new Set();
|
|
82
|
-
window.addEventListener("resize", _webResizeHandler);
|
|
83
|
-
}
|
|
84
|
-
_webListeners.add(cb);
|
|
85
|
-
return () => {
|
|
86
|
-
_webListeners.delete(cb);
|
|
87
|
-
if (_webListeners.size === 0) {
|
|
88
|
-
window.removeEventListener("resize", _webResizeHandler);
|
|
89
|
-
cancelAnimationFrame(_webRaf);
|
|
90
|
-
_webListeners = null;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function getWebWidth() {
|
|
95
|
-
return typeof window !== "undefined" ? window.innerWidth : 0;
|
|
96
|
-
}
|
|
97
|
-
function useGlobalWidth() {
|
|
98
|
-
return useSyncExternalStore2(
|
|
99
|
-
isWeb ? subscribeWebWidth : subscribeGlobalWidth,
|
|
100
|
-
isWeb ? getWebWidth : getGlobalWidth,
|
|
101
|
-
ZERO_SNAP
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
function useConditionalWidth(active) {
|
|
105
|
-
return useSyncExternalStore2(
|
|
106
|
-
active ? isWeb ? subscribeWebWidth : subscribeGlobalWidth : NOOP_SUB,
|
|
107
|
-
active ? isWeb ? getWebWidth : getGlobalWidth : ZERO_SNAP,
|
|
108
|
-
ZERO_SNAP
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/shared-utils.ts
|
|
113
|
-
function hasResponsiveBuckets(resolved) {
|
|
114
|
-
const responsiveMods = getResponsiveModifiers();
|
|
115
|
-
for (const key of Object.keys(resolved)) {
|
|
116
|
-
if (key === "base") continue;
|
|
117
|
-
for (const mod of key.split(":")) {
|
|
118
|
-
if (responsiveMods.has(mod)) return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
var EMPTY_BREAKPOINTS2 = /* @__PURE__ */ new Set();
|
|
124
|
-
|
|
125
|
-
// src/InteractiveWrapper.tsx
|
|
126
|
-
function chain(original, extra) {
|
|
127
|
-
return (...args) => {
|
|
128
|
-
original?.(...args);
|
|
129
|
-
extra();
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
var InteractiveWrapper = forwardRef(
|
|
133
|
-
function InteractiveWrapper2({
|
|
134
|
-
Component,
|
|
135
|
-
resolvedStyle,
|
|
136
|
-
className,
|
|
137
|
-
style: styleProp,
|
|
138
|
-
onPressIn,
|
|
139
|
-
onPressOut,
|
|
140
|
-
onPointerDown,
|
|
141
|
-
onPointerUp,
|
|
142
|
-
onPointerLeave,
|
|
143
|
-
onMouseEnter,
|
|
144
|
-
onMouseLeave,
|
|
145
|
-
onFocus,
|
|
146
|
-
onBlur,
|
|
147
|
-
...rest
|
|
148
|
-
}, ref) {
|
|
149
|
-
const isDark = useGlobalDarkMode();
|
|
150
|
-
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
151
|
-
const width = useConditionalWidth(needsWidth);
|
|
152
|
-
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
153
|
-
const [pressed, setPressed] = useState(false);
|
|
154
|
-
const [hovered, setHovered] = useState(false);
|
|
155
|
-
const [focused, setFocused] = useState(false);
|
|
156
|
-
const handlePressIn = useCallback(chain(onPressIn, () => setPressed(true)), [onPressIn]);
|
|
157
|
-
const handlePressOut = useCallback(chain(onPressOut, () => setPressed(false)), [onPressOut]);
|
|
158
|
-
const handlePointerDown = useCallback(chain(onPointerDown, () => setPressed(true)), [onPointerDown]);
|
|
159
|
-
const handlePointerUp = useCallback(chain(onPointerUp, () => setPressed(false)), [onPointerUp]);
|
|
160
|
-
const handlePointerLeave = useCallback(chain(onPointerLeave, () => setPressed(false)), [onPointerLeave]);
|
|
161
|
-
const handleMouseEnter = useCallback(chain(onMouseEnter, () => setHovered(true)), [onMouseEnter]);
|
|
162
|
-
const handleMouseLeave = useCallback(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
|
|
163
|
-
const handleFocus = useCallback(chain(onFocus, () => setFocused(true)), [onFocus]);
|
|
164
|
-
const handleBlur = useCallback(chain(onBlur, () => setFocused(false)), [onBlur]);
|
|
165
|
-
const computedStyle = useMemo(
|
|
166
|
-
() => {
|
|
167
|
-
const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused }, breakpoints);
|
|
168
|
-
delete s.__divideX;
|
|
169
|
-
delete s.__divideY;
|
|
170
|
-
delete s.__divideColor;
|
|
171
|
-
delete s.__divideStyle;
|
|
172
|
-
delete s.__keyframe;
|
|
173
|
-
if (typeof Component !== "string") {
|
|
174
|
-
if (s.display === "grid" || s.display === "inline-grid") delete s.display;
|
|
175
|
-
delete s.gridTemplateColumns;
|
|
176
|
-
delete s.gridTemplateRows;
|
|
177
|
-
delete s.gridColumn;
|
|
178
|
-
delete s.gridRow;
|
|
179
|
-
delete s.gridArea;
|
|
180
|
-
delete s.gridColumnStart;
|
|
181
|
-
delete s.gridColumnEnd;
|
|
182
|
-
delete s.gridRowStart;
|
|
183
|
-
delete s.gridRowEnd;
|
|
184
|
-
delete s.gridAutoFlow;
|
|
185
|
-
delete s.gridAutoColumns;
|
|
186
|
-
delete s.gridAutoRows;
|
|
187
|
-
delete s.placeItems;
|
|
188
|
-
delete s.placeContent;
|
|
189
|
-
delete s.justifyItems;
|
|
190
|
-
delete s.placeSelf;
|
|
191
|
-
delete s.justifySelf;
|
|
192
|
-
if (s.position === "sticky" || s.position === "fixed" || s.position === "static") {
|
|
193
|
-
delete s.position;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return s;
|
|
197
|
-
},
|
|
198
|
-
[resolvedStyle, isDark, pressed, hovered, focused, width]
|
|
199
|
-
// eslint-disable-line react-hooks/exhaustive-deps
|
|
200
|
-
);
|
|
201
|
-
const isWebHTMLElement = !isNative && typeof Component === "string";
|
|
202
|
-
const finalStyle = isWebHTMLElement ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
|
|
203
|
-
const { children, ...restWithoutChildren } = rest;
|
|
204
|
-
const componentProps = {
|
|
205
|
-
ref,
|
|
206
|
-
...restWithoutChildren,
|
|
207
|
-
style: finalStyle,
|
|
208
|
-
...!isNative && className ? { className } : {},
|
|
209
|
-
// onPressIn / onPressOut are React Native-only.
|
|
210
|
-
// On web, onPointerDown/Up drive the pressed state instead (covers mouse + touch).
|
|
211
|
-
...!isNative ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave } : { onPressIn: handlePressIn, onPressOut: handlePressOut },
|
|
212
|
-
onMouseEnter: handleMouseEnter,
|
|
213
|
-
onMouseLeave: handleMouseLeave,
|
|
214
|
-
onFocus: handleFocus,
|
|
215
|
-
onBlur: handleBlur
|
|
216
|
-
};
|
|
217
|
-
return Array.isArray(children) ? React3.createElement(Component, componentProps, ...children) : React3.createElement(Component, componentProps, children);
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
|
|
221
|
-
|
|
222
|
-
export {
|
|
223
|
-
syncGlobalDarkMode,
|
|
224
|
-
setGlobalDarkMode,
|
|
225
|
-
EMPTY_BREAKPOINTS,
|
|
226
|
-
useGlobalWidth,
|
|
227
|
-
useConditionalWidth,
|
|
228
|
-
hasResponsiveBuckets,
|
|
229
|
-
EMPTY_BREAKPOINTS2,
|
|
230
|
-
useGlobalDarkMode,
|
|
231
|
-
InteractiveWrapper
|
|
232
|
-
};
|