@kbach/ui 0.1.0-beta.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/KBACH.md +1044 -0
- package/README.md +473 -0
- package/dist/chunk-BPCFICND.mjs +4187 -0
- package/dist/chunk-UE54W6ZG.mjs +208 -0
- package/dist/core/index.d.ts +1346 -0
- package/dist/core/index.js +3712 -0
- package/dist/index.d.ts +328 -0
- package/dist/index.js +1191 -0
- package/dist/index.mjs +589 -0
- package/dist/jsx-dev-runtime.d.ts +21 -0
- package/dist/jsx-dev-runtime.js +780 -0
- package/dist/jsx-dev-runtime.mjs +21 -0
- package/dist/jsx-runtime.d.ts +17 -0
- package/dist/jsx-runtime.js +779 -0
- package/dist/jsx-runtime.mjs +17 -0
- package/dist/native.d.ts +314 -0
- package/dist/native.js +99 -0
- package/dist/vite-plugin.d.mts +155 -0
- package/dist/vite-plugin.d.ts +155 -0
- package/dist/vite-plugin.js +3939 -0
- package/dist/vite-plugin.mjs +3903 -0
- package/dist/web-substitute-6xH1WxpZ.d.ts +22 -0
- package/jsx-dev-runtime.js +3 -0
- package/jsx-runtime.js +3 -0
- package/kbach-ui.md +889 -0
- package/package.json +104 -0
- package/scripts/postinstall.js +28 -0
- package/src/native/babel/index.js +30 -0
- package/src/native/babel-plugin/index.js +605 -0
- package/src/native/babel-plugin/index.test.ts +86 -0
- package/types.d.ts +1 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
EMPTY_BREAKPOINTS,
|
|
4
|
+
InteractiveWrapper,
|
|
5
|
+
composeNativeStyle,
|
|
6
|
+
expandModeAwareColorClasses,
|
|
7
|
+
flatten,
|
|
8
|
+
getActiveBreakpoints,
|
|
9
|
+
getConfig,
|
|
10
|
+
getDefaultFontFamily,
|
|
11
|
+
getEffectiveIsWeb,
|
|
12
|
+
getGlobalScreens,
|
|
13
|
+
getImpliedRNClasses,
|
|
14
|
+
getInteractiveModifiers,
|
|
15
|
+
getModeModifiers,
|
|
16
|
+
getResponsiveModifiers,
|
|
17
|
+
getWebTag,
|
|
18
|
+
hasResponsiveBuckets,
|
|
19
|
+
isNative,
|
|
20
|
+
isRuntimeCSSDisabled,
|
|
21
|
+
normalizeClassString,
|
|
22
|
+
onConfigChange,
|
|
23
|
+
resolve,
|
|
24
|
+
stripInternalMarkers,
|
|
25
|
+
stripWebOnlyProps,
|
|
26
|
+
transformToWebProps,
|
|
27
|
+
useConditionalGlobalDarkMode,
|
|
28
|
+
useConditionalWidth
|
|
29
|
+
} from "./chunk-BPCFICND.mjs";
|
|
30
|
+
|
|
31
|
+
// src/jsx-runtime.tsx
|
|
32
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
33
|
+
import { Fragment } from "react";
|
|
34
|
+
|
|
35
|
+
// src/DarkWrapper.tsx
|
|
36
|
+
import React, { useMemo } from "react";
|
|
37
|
+
var DarkWrapper = React.forwardRef(
|
|
38
|
+
function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
|
|
39
|
+
const isWebPlatform = getEffectiveIsWeb();
|
|
40
|
+
const isDark = useConditionalGlobalDarkMode(!isWebPlatform);
|
|
41
|
+
const needsWidth = hasResponsiveBuckets(resolvedStyle);
|
|
42
|
+
const width = useConditionalWidth(needsWidth && !isWebPlatform);
|
|
43
|
+
const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS;
|
|
44
|
+
const screens = getGlobalScreens();
|
|
45
|
+
const isNonStringComponent = typeof Component !== "string";
|
|
46
|
+
const computedStyle = useMemo(() => {
|
|
47
|
+
if (isWebPlatform) return {};
|
|
48
|
+
const s = flatten(resolvedStyle, isDark, {}, breakpoints);
|
|
49
|
+
stripInternalMarkers(s);
|
|
50
|
+
if (isNonStringComponent) stripWebOnlyProps(s);
|
|
51
|
+
return s;
|
|
52
|
+
}, [resolvedStyle, isDark, width, screens, isNonStringComponent]);
|
|
53
|
+
const skipComputedInline = isWebPlatform;
|
|
54
|
+
const finalStyle = skipComputedInline ? styleProp ?? void 0 : composeNativeStyle(computedStyle, styleProp);
|
|
55
|
+
const props = { ref, ...rest, style: finalStyle };
|
|
56
|
+
return Array.isArray(children) ? React.createElement(Component, props, ...children) : React.createElement(Component, props, children);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
DarkWrapper.displayName = "Kbach.DarkWrapper";
|
|
60
|
+
|
|
61
|
+
// src/jsx-runtime.tsx
|
|
62
|
+
var _cachedDefaultFont = void 0;
|
|
63
|
+
var _defaultFontVersion = 0;
|
|
64
|
+
var _lastFontVersion = -1;
|
|
65
|
+
function _invalidateDefaultFontCache() {
|
|
66
|
+
_defaultFontVersion++;
|
|
67
|
+
}
|
|
68
|
+
{
|
|
69
|
+
const _KEY = "__kbach_font_cache_unsub__";
|
|
70
|
+
const g = globalThis;
|
|
71
|
+
if (g[_KEY]) g[_KEY]();
|
|
72
|
+
g[_KEY] = onConfigChange(_invalidateDefaultFontCache);
|
|
73
|
+
}
|
|
74
|
+
function getCachedDefaultFont() {
|
|
75
|
+
if (_lastFontVersion !== _defaultFontVersion) {
|
|
76
|
+
_cachedDefaultFont = getDefaultFontFamily();
|
|
77
|
+
_lastFontVersion = _defaultFontVersion;
|
|
78
|
+
}
|
|
79
|
+
return _cachedDefaultFont;
|
|
80
|
+
}
|
|
81
|
+
var _bucketModsCache = /* @__PURE__ */ new WeakMap();
|
|
82
|
+
function bucketMods(resolved) {
|
|
83
|
+
const cached = _bucketModsCache.get(resolved);
|
|
84
|
+
if (cached) return cached;
|
|
85
|
+
const interactiveMods = getInteractiveModifiers();
|
|
86
|
+
const modeMods = getModeModifiers();
|
|
87
|
+
const responsiveMods = getResponsiveModifiers();
|
|
88
|
+
let interactive = false;
|
|
89
|
+
let modeOrResponsive = false;
|
|
90
|
+
for (const key of Object.keys(resolved)) {
|
|
91
|
+
if (key === "base") continue;
|
|
92
|
+
for (const mod of key.split(":")) {
|
|
93
|
+
if (!interactive && interactiveMods.has(mod)) interactive = true;
|
|
94
|
+
if (!modeOrResponsive && (modeMods.has(mod) || responsiveMods.has(mod))) modeOrResponsive = true;
|
|
95
|
+
}
|
|
96
|
+
if (interactive && modeOrResponsive) break;
|
|
97
|
+
}
|
|
98
|
+
const result = { interactive, modeOrResponsive };
|
|
99
|
+
_bucketModsCache.set(resolved, result);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
var CONSUMED_PROPS = /* @__PURE__ */ new Set(["className", "kb", "__kbachStyles", "__kbachClasses"]);
|
|
103
|
+
function omitConsumed(props) {
|
|
104
|
+
const out = {};
|
|
105
|
+
for (const key of Object.keys(props)) {
|
|
106
|
+
if (!CONSUMED_PROPS.has(key)) out[key] = props[key];
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function makeElement(isStaticChildren, type, props, key) {
|
|
111
|
+
return (isStaticChildren ? _jsxs : _jsx)(type, props, key);
|
|
112
|
+
}
|
|
113
|
+
function processElement(type, rawProps, key, isStaticChildren) {
|
|
114
|
+
if (type === null || typeof type === "symbol") return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
115
|
+
const webTag = getEffectiveIsWeb() ? getWebTag(type, rawProps ?? void 0) : null;
|
|
116
|
+
const effectiveType = webTag ?? type;
|
|
117
|
+
const originalName = webTag ? type?.displayName ?? type?.name : void 0;
|
|
118
|
+
if (!rawProps) return _jsx(effectiveType, null, key);
|
|
119
|
+
const workingProps = webTag && originalName ? transformToWebProps(originalName, webTag, rawProps) : rawProps;
|
|
120
|
+
const { className, kb: kbProp, __kbachStyles, __kbachClasses } = workingProps;
|
|
121
|
+
const classStrRaw = className ?? kbProp ?? __kbachClasses;
|
|
122
|
+
if (classStrRaw !== void 0 && typeof classStrRaw !== "string") {
|
|
123
|
+
return makeElement(isStaticChildren, effectiveType, workingProps, key);
|
|
124
|
+
}
|
|
125
|
+
const classStr = classStrRaw;
|
|
126
|
+
const config = getConfig();
|
|
127
|
+
let expandedClassStr = classStr ? expandModeAwareColorClasses(classStr, config.theme.colors) : classStr;
|
|
128
|
+
if (!isNative && isRuntimeCSSDisabled() && expandedClassStr && !__kbachStyles) {
|
|
129
|
+
const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
|
|
130
|
+
return makeElement(isStaticChildren, effectiveType, {
|
|
131
|
+
...passProps2,
|
|
132
|
+
className: normalizeClassString(expandedClassStr),
|
|
133
|
+
...userStyle2 !== void 0 ? { style: userStyle2 } : {}
|
|
134
|
+
}, key);
|
|
135
|
+
}
|
|
136
|
+
if (classStr && !__kbachStyles && /^(__[A-Za-z0-9_]+\s*)+$/.test(classStr.trim())) {
|
|
137
|
+
const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
|
|
138
|
+
return makeElement(isStaticChildren, effectiveType, {
|
|
139
|
+
...passProps2,
|
|
140
|
+
className: classStr,
|
|
141
|
+
...userStyle2 !== void 0 ? { style: userStyle2 } : {}
|
|
142
|
+
}, key);
|
|
143
|
+
}
|
|
144
|
+
if (!classStr && !__kbachStyles) {
|
|
145
|
+
if (getEffectiveIsWeb()) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
|
|
146
|
+
const defaultFont = getCachedDefaultFont();
|
|
147
|
+
if (!defaultFont || getWebTag(type) !== "span") {
|
|
148
|
+
return makeElement(isStaticChildren, effectiveType, workingProps, key);
|
|
149
|
+
}
|
|
150
|
+
const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
|
|
151
|
+
const finalStyle2 = userStyle2 ? Array.isArray(userStyle2) ? { fontFamily: defaultFont, ...Object.assign({}, ...userStyle2) } : { fontFamily: defaultFont, ...userStyle2 } : { fontFamily: defaultFont };
|
|
152
|
+
return makeElement(isStaticChildren, effectiveType, { ...passProps2, style: finalStyle2 }, key);
|
|
153
|
+
}
|
|
154
|
+
let resolved = isNative && __kbachStyles != null ? __kbachStyles : expandedClassStr ? resolve(expandedClassStr, config.theme, config.darkMode) : {};
|
|
155
|
+
const impliedClasses = getImpliedRNClasses(webTag, resolved.base);
|
|
156
|
+
if (impliedClasses) {
|
|
157
|
+
expandedClassStr = expandedClassStr ? `${expandedClassStr} ${impliedClasses}` : impliedClasses;
|
|
158
|
+
resolved = resolve(expandedClassStr, config.theme, config.darkMode);
|
|
159
|
+
}
|
|
160
|
+
const { style: userStyle, ...passProps } = omitConsumed(workingProps);
|
|
161
|
+
const { interactive, modeOrResponsive } = bucketMods(resolved);
|
|
162
|
+
if (interactive) {
|
|
163
|
+
return _jsx(InteractiveWrapper, {
|
|
164
|
+
Component: effectiveType,
|
|
165
|
+
resolvedStyle: resolved,
|
|
166
|
+
...!isNative && expandedClassStr ? { className: normalizeClassString(expandedClassStr) } : {},
|
|
167
|
+
style: userStyle,
|
|
168
|
+
...passProps
|
|
169
|
+
}, key);
|
|
170
|
+
}
|
|
171
|
+
if (modeOrResponsive) {
|
|
172
|
+
return _jsx(DarkWrapper, {
|
|
173
|
+
Component: effectiveType,
|
|
174
|
+
resolvedStyle: resolved,
|
|
175
|
+
...!isNative && expandedClassStr ? { className: normalizeClassString(expandedClassStr) } : {},
|
|
176
|
+
style: userStyle,
|
|
177
|
+
...passProps
|
|
178
|
+
}, key);
|
|
179
|
+
}
|
|
180
|
+
const skipComputedInline = getEffectiveIsWeb();
|
|
181
|
+
let finalStyle;
|
|
182
|
+
if (!skipComputedInline) {
|
|
183
|
+
const computedStyle = flatten(resolved, false);
|
|
184
|
+
stripInternalMarkers(computedStyle);
|
|
185
|
+
if (typeof effectiveType !== "string") stripWebOnlyProps(computedStyle);
|
|
186
|
+
finalStyle = composeNativeStyle(computedStyle, userStyle);
|
|
187
|
+
} else {
|
|
188
|
+
finalStyle = userStyle ?? void 0;
|
|
189
|
+
}
|
|
190
|
+
return makeElement(isStaticChildren, effectiveType, {
|
|
191
|
+
...passProps,
|
|
192
|
+
...finalStyle !== void 0 ? { style: finalStyle } : {},
|
|
193
|
+
...!isNative && expandedClassStr ? { className: normalizeClassString(expandedClassStr) } : {}
|
|
194
|
+
}, key);
|
|
195
|
+
}
|
|
196
|
+
function jsx(type, props, key) {
|
|
197
|
+
return processElement(type, props, key, false);
|
|
198
|
+
}
|
|
199
|
+
function jsxs(type, props, key) {
|
|
200
|
+
return processElement(type, props, key, true);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export {
|
|
204
|
+
Fragment,
|
|
205
|
+
_invalidateDefaultFontCache,
|
|
206
|
+
jsx,
|
|
207
|
+
jsxs
|
|
208
|
+
};
|