@kbach/react 0.5.48 → 0.5.51

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.
@@ -2812,9 +2812,11 @@ function flatten(resolved, isDark, state = {}, breakpoints = /* @__PURE__ */ new
2812
2812
  Object.assign(result, styles);
2813
2813
  }
2814
2814
  }
2815
- const defaultFont = getDefaultFontFamily();
2816
- if (defaultFont && !("fontFamily" in result)) {
2817
- result.fontFamily = defaultFont;
2815
+ if (isNative) {
2816
+ const defaultFont = getDefaultFontFamily();
2817
+ if (defaultFont && !("fontFamily" in result)) {
2818
+ result.fontFamily = defaultFont;
2819
+ }
2818
2820
  }
2819
2821
  if (!isNative) {
2820
2822
  const r = result;
@@ -3148,6 +3150,7 @@ var InteractiveWrapper = (0, import_react3.forwardRef)(
3148
3150
  const handleBlur = (0, import_react3.useCallback)(chain(onBlur, () => setFocused(false)), [onBlur]);
3149
3151
  const computedStyle = (0, import_react3.useMemo)(
3150
3152
  () => {
3153
+ if (isWeb) return {};
3151
3154
  const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!rest.disabled, checked: !!rest.checked }, breakpoints);
3152
3155
  delete s.__divideX;
3153
3156
  delete s.__divideY;
@@ -3213,6 +3216,7 @@ var DarkWrapper = import_react4.default.forwardRef(
3213
3216
  const breakpoints = needsWidth ? getActiveBreakpoints(width) : EMPTY_BREAKPOINTS2;
3214
3217
  const isNonStringComponent = typeof Component !== "string";
3215
3218
  const computedStyle = (0, import_react4.useMemo)(() => {
3219
+ if (isWeb) return {};
3216
3220
  const s = flatten(resolvedStyle, isDark, {}, breakpoints);
3217
3221
  stripInternalMarkers(s);
3218
3222
  if (isNonStringComponent) stripWebOnlyProps(s);
@@ -3256,6 +3260,91 @@ function stripWebOnlyProps(s) {
3256
3260
  }
3257
3261
  }
3258
3262
 
3263
+ // src/web-substitute.ts
3264
+ var _rnToHtml = {
3265
+ View: "div",
3266
+ SafeAreaView: "div",
3267
+ KeyboardAvoidingView: "div",
3268
+ ScrollView: "div",
3269
+ VirtualizedList: "div",
3270
+ Text: "span",
3271
+ Pressable: "div",
3272
+ TouchableOpacity: "div",
3273
+ TouchableHighlight: "div",
3274
+ TouchableWithoutFeedback: "div",
3275
+ TouchableNativeFeedback: "div"
3276
+ };
3277
+ var _userMap = /* @__PURE__ */ new Map();
3278
+ var _cache = /* @__PURE__ */ new WeakMap();
3279
+ function registerWebElement(rnComponent, htmlTag) {
3280
+ if (typeof rnComponent !== "object" && typeof rnComponent !== "function") return;
3281
+ _userMap.set(rnComponent, htmlTag);
3282
+ _cache.delete(rnComponent);
3283
+ }
3284
+ function getWebTag(type) {
3285
+ if (typeof type === "string") return null;
3286
+ if (type === null || typeof type !== "function" && typeof type !== "object") return null;
3287
+ const obj = type;
3288
+ if (_userMap.has(obj)) return _userMap.get(obj);
3289
+ if (_cache.has(obj)) return _cache.get(obj);
3290
+ const name = obj.displayName ?? obj.name;
3291
+ const tag = name ? _rnToHtml[name] ?? null : null;
3292
+ _cache.set(obj, tag);
3293
+ return tag;
3294
+ }
3295
+ var _rnOnlyProps = /* @__PURE__ */ new Set([
3296
+ "onLongPress",
3297
+ "delayLongPress",
3298
+ "activeOpacity",
3299
+ "underlayColor",
3300
+ "hitSlop",
3301
+ "pressRetentionOffset",
3302
+ "accessible",
3303
+ "accessibilityState",
3304
+ "accessibilityLiveRegion",
3305
+ "importantForAccessibility",
3306
+ "nativeID",
3307
+ "collapsable",
3308
+ "needsOffscreenAlphaCompositing",
3309
+ "renderToHardwareTextureAndroid",
3310
+ "shouldRasterizeIOS",
3311
+ "pointerEvents"
3312
+ // RN and HTML values differ
3313
+ ]);
3314
+ var _pressableNames = /* @__PURE__ */ new Set([
3315
+ "Pressable",
3316
+ "TouchableOpacity",
3317
+ "TouchableHighlight",
3318
+ "TouchableWithoutFeedback",
3319
+ "TouchableNativeFeedback"
3320
+ ]);
3321
+ function transformToWebProps(originalName, props) {
3322
+ const out = {};
3323
+ const isPressable = _pressableNames.has(originalName);
3324
+ for (const [k, v] of Object.entries(props)) {
3325
+ if (_rnOnlyProps.has(k)) continue;
3326
+ if (k === "onPress") {
3327
+ if (!("onClick" in props)) out.onClick = v;
3328
+ continue;
3329
+ }
3330
+ if (k === "accessibilityLabel") {
3331
+ if (out["aria-label"] == null) out["aria-label"] = v;
3332
+ continue;
3333
+ }
3334
+ if (k === "accessibilityRole") {
3335
+ if (out.role == null) out.role = v;
3336
+ continue;
3337
+ }
3338
+ if (k === "testID") {
3339
+ if (out["data-testid"] == null) out["data-testid"] = v;
3340
+ continue;
3341
+ }
3342
+ out[k] = v;
3343
+ }
3344
+ if (isPressable && !out.role) out.role = "button";
3345
+ return out;
3346
+ }
3347
+
3259
3348
  // src/jsx-runtime.tsx
3260
3349
  var _cachedDefaultFont = void 0;
3261
3350
  var _defaultFontVersion = 0;
@@ -3337,89 +3426,6 @@ function stripWebOnlyInlineProps(s) {
3337
3426
  delete s.position;
3338
3427
  }
3339
3428
  }
3340
- var _rnToHtml = {
3341
- View: "div",
3342
- SafeAreaView: "div",
3343
- KeyboardAvoidingView: "div",
3344
- ScrollView: "div",
3345
- VirtualizedList: "div",
3346
- Text: "span",
3347
- Pressable: "div",
3348
- TouchableOpacity: "div",
3349
- TouchableHighlight: "div",
3350
- TouchableWithoutFeedback: "div",
3351
- TouchableNativeFeedback: "div"
3352
- };
3353
- var _userWebTypeMap = /* @__PURE__ */ new Map();
3354
- var _webTypeCache = /* @__PURE__ */ new WeakMap();
3355
- function registerWebElement(rnComponent, htmlTag) {
3356
- if (typeof rnComponent !== "object" && typeof rnComponent !== "function") return;
3357
- _userWebTypeMap.set(rnComponent, htmlTag);
3358
- _webTypeCache.delete(rnComponent);
3359
- }
3360
- function getWebTag(type) {
3361
- if (typeof type === "string") return null;
3362
- if (type === null || typeof type !== "function" && typeof type !== "object") return null;
3363
- const obj = type;
3364
- if (_userWebTypeMap.has(obj)) return _userWebTypeMap.get(obj);
3365
- if (_webTypeCache.has(obj)) return _webTypeCache.get(obj);
3366
- const name = obj.displayName ?? obj.name;
3367
- const tag = name ? _rnToHtml[name] ?? null : null;
3368
- _webTypeCache.set(obj, tag);
3369
- return tag;
3370
- }
3371
- var _rnOnlyProps = /* @__PURE__ */ new Set([
3372
- "onLongPress",
3373
- "delayLongPress",
3374
- "activeOpacity",
3375
- "underlayColor",
3376
- "hitSlop",
3377
- "pressRetentionOffset",
3378
- "accessible",
3379
- "accessibilityState",
3380
- "accessibilityLiveRegion",
3381
- "importantForAccessibility",
3382
- "nativeID",
3383
- "collapsable",
3384
- "needsOffscreenAlphaCompositing",
3385
- "renderToHardwareTextureAndroid",
3386
- "shouldRasterizeIOS",
3387
- "pointerEvents"
3388
- // RN prop — values differ from HTML pointer-events CSS
3389
- ]);
3390
- var _pressableDisplayNames = /* @__PURE__ */ new Set([
3391
- "Pressable",
3392
- "TouchableOpacity",
3393
- "TouchableHighlight",
3394
- "TouchableWithoutFeedback",
3395
- "TouchableNativeFeedback"
3396
- ]);
3397
- function transformToWebProps(originalName, props) {
3398
- const out = {};
3399
- const isPressable = _pressableDisplayNames.has(originalName);
3400
- for (const [k, v] of Object.entries(props)) {
3401
- if (_rnOnlyProps.has(k)) continue;
3402
- if (k === "onPress") {
3403
- if (!("onClick" in props)) out.onClick = v;
3404
- continue;
3405
- }
3406
- if (k === "accessibilityLabel") {
3407
- if (out["aria-label"] == null) out["aria-label"] = v;
3408
- continue;
3409
- }
3410
- if (k === "accessibilityRole") {
3411
- if (out.role == null) out.role = v;
3412
- continue;
3413
- }
3414
- if (k === "testID") {
3415
- if (out["data-testid"] == null) out["data-testid"] = v;
3416
- continue;
3417
- }
3418
- out[k] = v;
3419
- }
3420
- if (isPressable && !out.role) out.role = "button";
3421
- return out;
3422
- }
3423
3429
  function processElement(type, rawProps, key, isStaticChildren) {
3424
3430
  if (typeof type === "symbol") return makeElement(isStaticChildren, type, rawProps ?? {}, key);
3425
3431
  const webTag = isWeb ? getWebTag(type) : null;
@@ -3438,6 +3444,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
3438
3444
  }, key);
3439
3445
  }
3440
3446
  if (!classStr && !__kbachStyles) {
3447
+ if (isWeb) return makeElement(isStaticChildren, effectiveType, omitConsumed(workingProps), key);
3441
3448
  const defaultFont = getCachedDefaultFont();
3442
3449
  if (!defaultFont) return makeElement(isStaticChildren, effectiveType, workingProps, key);
3443
3450
  const { style: userStyle2, ...passProps2 } = omitConsumed(workingProps);
@@ -3445,7 +3452,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
3445
3452
  return makeElement(isStaticChildren, effectiveType, { ...passProps2, style: finalStyle2 }, key);
3446
3453
  }
3447
3454
  const config = getConfig();
3448
- const resolved = __kbachStyles ?? (classStr ? resolve(classStr, config.theme, config.darkMode) : {});
3455
+ const resolved = !isWeb && __kbachStyles != null ? __kbachStyles : classStr ? resolve(classStr, config.theme, config.darkMode) : {};
3449
3456
  const { style: userStyle, ...passProps } = omitConsumed(workingProps);
3450
3457
  const { interactive, modeOrResponsive } = bucketMods(resolved);
3451
3458
  if (interactive) {
@@ -2,10 +2,12 @@ import {
2
2
  Fragment,
3
3
  _invalidateDefaultFontCache,
4
4
  jsx,
5
- jsxs,
5
+ jsxs
6
+ } from "./chunk-6YN6SRMN.mjs";
7
+ import {
6
8
  registerWebElement
7
- } from "./chunk-YZNSWFJT.mjs";
8
- import "./chunk-BKSXIWL7.mjs";
9
+ } from "./chunk-JVTA5SC3.mjs";
10
+ import "./chunk-JBV2R655.mjs";
9
11
  export {
10
12
  Fragment,
11
13
  _invalidateDefaultFontCache,
@@ -4,7 +4,7 @@ import {
4
4
  generateClassCSS,
5
5
  setCSSGenMode,
6
6
  splitClassTokens
7
- } from "./chunk-BKSXIWL7.mjs";
7
+ } from "./chunk-JBV2R655.mjs";
8
8
 
9
9
  // src/vite-plugin.ts
10
10
  import { readFileSync, writeFileSync, readdirSync, statSync } from "fs";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * React Native → HTML element substitution for web rendering.
3
+ *
4
+ * When isWeb is true, known React Native component types (View, Text, Pressable, …)
5
+ * are replaced with plain HTML element strings ('div', 'span', …) so the DOM shows
6
+ * clean Kbach class names instead of React Native Web's generated css-view-* classes.
7
+ *
8
+ * Used by: jsx-runtime (bare JSX), styled(), DarkWrapper, InteractiveWrapper.
9
+ */
10
+ /**
11
+ * Register a custom React Native component → HTML tag substitution.
12
+ * Call once at app startup before first render.
13
+ *
14
+ * ```ts
15
+ * import { Animated } from 'react-native';
16
+ * import { registerWebElement } from '@kbach/react';
17
+ * registerWebElement(Animated.View, 'div');
18
+ * ```
19
+ */
20
+ declare function registerWebElement(rnComponent: unknown, htmlTag: string): void;
21
+
22
+ export { registerWebElement as r };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * React Native → HTML element substitution for web rendering.
3
+ *
4
+ * When isWeb is true, known React Native component types (View, Text, Pressable, …)
5
+ * are replaced with plain HTML element strings ('div', 'span', …) so the DOM shows
6
+ * clean Kbach class names instead of React Native Web's generated css-view-* classes.
7
+ *
8
+ * Used by: jsx-runtime (bare JSX), styled(), DarkWrapper, InteractiveWrapper.
9
+ */
10
+ /**
11
+ * Register a custom React Native component → HTML tag substitution.
12
+ * Call once at app startup before first render.
13
+ *
14
+ * ```ts
15
+ * import { Animated } from 'react-native';
16
+ * import { registerWebElement } from '@kbach/react';
17
+ * registerWebElement(Animated.View, 'div');
18
+ * ```
19
+ */
20
+ declare function registerWebElement(rnComponent: unknown, htmlTag: string): void;
21
+
22
+ export { registerWebElement as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.5.48",
3
+ "version": "0.5.51",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",