@kbach/react 0.5.57 → 0.5.58

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.
@@ -7,14 +7,14 @@ import {
7
7
  isNative,
8
8
  isWeb,
9
9
  subscribeGlobalWidth
10
- } from "./chunk-JBV2R655.mjs";
10
+ } from "./chunk-2HWRNTJG.mjs";
11
11
 
12
12
  // src/core/darkModeStore.ts
13
13
  var KEY = "__kbach_dark_store__";
14
14
  function getStore() {
15
15
  const g = globalThis;
16
16
  if (!g[KEY]) {
17
- g[KEY] = { isDark: false, lastNotified: false, subscribers: /* @__PURE__ */ new Set() };
17
+ g[KEY] = { isDark: false, subscribers: /* @__PURE__ */ new Set() };
18
18
  }
19
19
  return g[KEY];
20
20
  }
@@ -23,9 +23,8 @@ function syncGlobalDarkMode(isDark) {
23
23
  }
24
24
  function setGlobalDarkMode(isDark) {
25
25
  const store = getStore();
26
+ if (store.isDark === isDark) return;
26
27
  store.isDark = isDark;
27
- if (store.lastNotified === isDark) return;
28
- store.lastNotified = isDark;
29
28
  for (const sub of store.subscribers) sub();
30
29
  }
31
30
  function getGlobalDarkMode() {
@@ -37,6 +36,22 @@ function subscribeGlobalDarkMode(callback) {
37
36
  return () => store.subscribers.delete(callback);
38
37
  }
39
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
+
40
55
  // src/web-substitute.ts
41
56
  var _rnToHtml = {
42
57
  View: "div",
@@ -73,8 +88,8 @@ function getWebTag(type, props) {
73
88
  _cache.set(obj, null);
74
89
  return null;
75
90
  }
76
- if (name === "TextInput" && props) {
77
- const multiline = props.multiline === true || Number(props.numberOfLines) > 1;
91
+ if (name === "TextInput") {
92
+ const multiline = !!props && (props.multiline === true || Number(props.numberOfLines) > 1);
78
93
  return multiline ? "textarea" : "input";
79
94
  }
80
95
  if (_cache.has(obj)) return _cache.get(obj);
@@ -111,8 +126,7 @@ var _rnOnlyProps = /* @__PURE__ */ new Set([
111
126
  "shouldRasterizeIOS",
112
127
  "focusable",
113
128
  "hasTVPreferredFocus",
114
- "pointerEvents",
115
- // RN and HTML values differ
129
+ // 'pointerEvents' is handled in transformToWebProps (mapped to CSS style)
116
130
  // Text
117
131
  "selectable",
118
132
  "allowFontScaling",
@@ -223,6 +237,7 @@ function transformToWebProps(originalName, tag, props) {
223
237
  const isTextInput = originalName === "TextInput";
224
238
  const isImage = originalName === "Image" || originalName === "ImageBackground";
225
239
  const isScrollable = originalName === "ScrollView" || originalName === "FlatList" || originalName === "SectionList";
240
+ let pendingStyle = null;
226
241
  for (const [k, v] of Object.entries(props)) {
227
242
  if (_rnOnlyProps.has(k)) continue;
228
243
  if (k === "onPress") {
@@ -267,10 +282,11 @@ function transformToWebProps(originalName, tag, props) {
267
282
  }
268
283
  }
269
284
  if (isScrollable && k === "horizontal") {
270
- if (v) {
271
- const existing = out.style ?? {};
272
- out.style = { display: "flex", flexDirection: "row", overflowX: "auto", ...existing };
273
- }
285
+ if (v) pendingStyle = { display: "flex", flexDirection: "row", overflowX: "auto" };
286
+ continue;
287
+ }
288
+ if (k === "pointerEvents") {
289
+ if (v === "none" || v === "auto") pendingStyle = { ...pendingStyle ?? {}, pointerEvents: v };
274
290
  continue;
275
291
  }
276
292
  if (isImage) {
@@ -293,7 +309,7 @@ function transformToWebProps(originalName, tag, props) {
293
309
  out.style = { ...existing, objectFit: v };
294
310
  continue;
295
311
  }
296
- if (k === "alt" || k === "defaultSource") continue;
312
+ if (k === "defaultSource") continue;
297
313
  }
298
314
  if (k === "style") {
299
315
  if (Array.isArray(v)) {
@@ -305,27 +321,14 @@ function transformToWebProps(originalName, tag, props) {
305
321
  }
306
322
  out[k] = v;
307
323
  }
324
+ if (pendingStyle) {
325
+ out.style = out.style ? { ...pendingStyle, ...out.style } : pendingStyle;
326
+ }
308
327
  if (isPressable && !out.role) out.role = "button";
309
328
  if (isImage && tag === "img" && out.alt == null) out.alt = "";
310
329
  return out;
311
330
  }
312
331
 
313
- // src/useGlobalDarkMode.ts
314
- import React from "react";
315
- var useSyncExternalStore = React.useSyncExternalStore ?? function useSyncExternalStoreFallback(subscribe, getSnapshot, _getServerSnapshot) {
316
- const [, forceUpdate] = React.useReducer((n) => n + 1, 0);
317
- React.useEffect(() => subscribe(forceUpdate), [subscribe]);
318
- return getSnapshot();
319
- };
320
- function useGlobalDarkMode() {
321
- return useSyncExternalStore(
322
- subscribeGlobalDarkMode,
323
- getGlobalDarkMode,
324
- () => false
325
- // SSR: default light
326
- );
327
- }
328
-
329
332
  // src/InteractiveWrapper.tsx
330
333
  import React3, { forwardRef, useState, useCallback, useMemo } from "react";
331
334
 
@@ -446,10 +449,11 @@ var InteractiveWrapper = forwardRef(
446
449
  const handleMouseLeave = useCallback(chain(onMouseLeave, () => setHovered(false)), [onMouseLeave]);
447
450
  const handleFocus = useCallback(chain(onFocus, () => setFocused(true)), [onFocus]);
448
451
  const handleBlur = useCallback(chain(onBlur, () => setFocused(false)), [onBlur]);
452
+ const { children, disabled, checked, ...restForComponent } = rest;
449
453
  const computedStyle = useMemo(
450
454
  () => {
451
455
  if (isWeb) return {};
452
- const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!rest.disabled, checked: !!rest.checked }, breakpoints);
456
+ const s = flatten(resolvedStyle, isDark, { pressed, hover: hovered, focus: focused, disabled: !!disabled, checked: !!checked }, breakpoints);
453
457
  delete s.__divideX;
454
458
  delete s.__divideY;
455
459
  delete s.__divideColor;
@@ -480,20 +484,20 @@ var InteractiveWrapper = forwardRef(
480
484
  }
481
485
  return s;
482
486
  },
483
- [resolvedStyle, isDark, pressed, hovered, focused, width]
484
- // eslint-disable-line react-hooks/exhaustive-deps
487
+ [resolvedStyle, isDark, pressed, hovered, focused, width, disabled, checked]
485
488
  );
486
489
  const skipComputedInline = isWeb || !isNative && typeof Component === "string";
487
490
  const finalStyle = skipComputedInline ? styleProp ?? void 0 : styleProp ? Array.isArray(styleProp) ? Object.assign({}, computedStyle, ...styleProp) : { ...computedStyle, ...styleProp } : computedStyle;
488
- const { children, ...restWithoutChildren } = rest;
489
491
  const componentProps = {
490
492
  ref,
491
- ...restWithoutChildren,
493
+ ...restForComponent,
494
+ ...disabled !== void 0 ? { disabled } : {},
495
+ ...checked !== void 0 ? { checked } : {},
492
496
  style: finalStyle,
493
497
  ...!isNative && className ? { className } : {},
494
498
  // onPressIn / onPressOut are React Native-only.
495
499
  // On web, onPointerDown/Up drive the pressed state instead (covers mouse + touch).
496
- ...!isNative ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave } : { onPressIn: handlePressIn, onPressOut: handlePressOut },
500
+ ...!isNative ? { onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onPointerLeave: handlePointerLeave, onPointerCancel: handlePointerLeave } : { onPressIn: handlePressIn, onPressOut: handlePressOut },
497
501
  onMouseEnter: handleMouseEnter,
498
502
  onMouseLeave: handleMouseLeave,
499
503
  onFocus: handleFocus,
@@ -507,6 +511,7 @@ InteractiveWrapper.displayName = "Kbach.InteractiveWrapper";
507
511
  export {
508
512
  syncGlobalDarkMode,
509
513
  setGlobalDarkMode,
514
+ useGlobalDarkMode,
510
515
  EMPTY_BREAKPOINTS,
511
516
  useGlobalWidth,
512
517
  useConditionalWidth,
@@ -516,6 +521,5 @@ export {
516
521
  registerWebElement,
517
522
  getWebTag,
518
523
  transformToWebProps,
519
- useGlobalDarkMode,
520
524
  InteractiveWrapper
521
525
  };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { ReactNode, ComponentType, ForwardRefExoticComponent } from 'react';
3
- import { T as ThemeColors, a as ThemeConfig, P as ParsedClass, R as ResolvedStyle, S as StyleValue, F as FrameworkConfig, b as ResolvedConfig, c as ThemeMode } from './types-D-24rbXu.mjs';
4
- export { d as PluginAPI } from './types-D-24rbXu.mjs';
3
+ import { T as ThemeColors, a as ThemeConfig, P as ParsedClass, R as ResolvedStyle, S as StyleValue, F as FrameworkConfig, b as ResolvedConfig, c as ThemeMode } from './types-BESBQANS.mjs';
4
+ export { d as PluginAPI } from './types-BESBQANS.mjs';
5
5
  export { r as registerWebElement } from './web-substitute-CfpYFnE7.mjs';
6
6
 
7
7
  declare const defaultColors: ThemeColors;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { ReactNode, ComponentType, ForwardRefExoticComponent } from 'react';
3
- import { T as ThemeColors, a as ThemeConfig, P as ParsedClass, R as ResolvedStyle, S as StyleValue, F as FrameworkConfig, b as ResolvedConfig, c as ThemeMode } from './types-D-24rbXu.js';
4
- export { d as PluginAPI } from './types-D-24rbXu.js';
3
+ import { T as ThemeColors, a as ThemeConfig, P as ParsedClass, R as ResolvedStyle, S as StyleValue, F as FrameworkConfig, b as ResolvedConfig, c as ThemeMode } from './types-BESBQANS.js';
4
+ export { d as PluginAPI } from './types-BESBQANS.js';
5
5
  export { r as registerWebElement } from './web-substitute-CfpYFnE7.js';
6
6
 
7
7
  declare const defaultColors: ThemeColors;