@oxyhq/bloom 0.5.1 → 0.6.1

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.
Files changed (73) hide show
  1. package/lib/commonjs/error-boundary/ErrorBoundary.js +27 -7
  2. package/lib/commonjs/error-boundary/ErrorBoundary.js.map +1 -1
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/index.web.js.map +1 -1
  5. package/lib/commonjs/skeleton/index.js +30 -0
  6. package/lib/commonjs/skeleton/index.js.map +1 -1
  7. package/lib/commonjs/theme/BloomThemeProvider.js +6 -0
  8. package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
  9. package/lib/commonjs/theme/index.js +7 -0
  10. package/lib/commonjs/theme/index.js.map +1 -1
  11. package/lib/commonjs/theme/init-css-interop.js +112 -0
  12. package/lib/commonjs/theme/init-css-interop.js.map +1 -0
  13. package/lib/module/error-boundary/ErrorBoundary.js +27 -7
  14. package/lib/module/error-boundary/ErrorBoundary.js.map +1 -1
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/module/index.web.js.map +1 -1
  17. package/lib/module/skeleton/index.js +29 -0
  18. package/lib/module/skeleton/index.js.map +1 -1
  19. package/lib/module/theme/BloomThemeProvider.js +5 -0
  20. package/lib/module/theme/BloomThemeProvider.js.map +1 -1
  21. package/lib/module/theme/index.js +1 -0
  22. package/lib/module/theme/index.js.map +1 -1
  23. package/lib/module/theme/init-css-interop.js +109 -0
  24. package/lib/module/theme/init-css-interop.js.map +1 -0
  25. package/lib/typescript/commonjs/error-boundary/ErrorBoundary.d.ts +3 -1
  26. package/lib/typescript/commonjs/error-boundary/ErrorBoundary.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/error-boundary/index.d.ts +1 -1
  28. package/lib/typescript/commonjs/error-boundary/index.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/error-boundary/types.d.ts +41 -2
  30. package/lib/typescript/commonjs/error-boundary/types.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/index.d.ts +1 -1
  32. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/index.web.d.ts +1 -1
  34. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/skeleton/index.d.ts +24 -1
  36. package/lib/typescript/commonjs/skeleton/index.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts +1 -0
  38. package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/theme/index.d.ts +1 -0
  40. package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/theme/init-css-interop.d.ts +6 -0
  42. package/lib/typescript/commonjs/theme/init-css-interop.d.ts.map +1 -0
  43. package/lib/typescript/module/error-boundary/ErrorBoundary.d.ts +3 -1
  44. package/lib/typescript/module/error-boundary/ErrorBoundary.d.ts.map +1 -1
  45. package/lib/typescript/module/error-boundary/index.d.ts +1 -1
  46. package/lib/typescript/module/error-boundary/index.d.ts.map +1 -1
  47. package/lib/typescript/module/error-boundary/types.d.ts +41 -2
  48. package/lib/typescript/module/error-boundary/types.d.ts.map +1 -1
  49. package/lib/typescript/module/index.d.ts +1 -1
  50. package/lib/typescript/module/index.d.ts.map +1 -1
  51. package/lib/typescript/module/index.web.d.ts +1 -1
  52. package/lib/typescript/module/index.web.d.ts.map +1 -1
  53. package/lib/typescript/module/skeleton/index.d.ts +24 -1
  54. package/lib/typescript/module/skeleton/index.d.ts.map +1 -1
  55. package/lib/typescript/module/theme/BloomThemeProvider.d.ts +1 -0
  56. package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
  57. package/lib/typescript/module/theme/index.d.ts +1 -0
  58. package/lib/typescript/module/theme/index.d.ts.map +1 -1
  59. package/lib/typescript/module/theme/init-css-interop.d.ts +6 -0
  60. package/lib/typescript/module/theme/init-css-interop.d.ts.map +1 -0
  61. package/package.json +1 -1
  62. package/src/__tests__/ErrorBoundary.test.tsx +217 -0
  63. package/src/__tests__/Skeleton.test.tsx +63 -0
  64. package/src/__tests__/init-css-interop.test.ts +130 -0
  65. package/src/error-boundary/ErrorBoundary.tsx +28 -5
  66. package/src/error-boundary/index.ts +5 -1
  67. package/src/error-boundary/types.ts +45 -2
  68. package/src/index.ts +5 -1
  69. package/src/index.web.ts +5 -1
  70. package/src/skeleton/index.tsx +54 -1
  71. package/src/theme/BloomThemeProvider.tsx +5 -0
  72. package/src/theme/index.ts +1 -0
  73. package/src/theme/init-css-interop.ts +126 -0
@@ -1,5 +1,12 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
- import { Animated, View, type ViewStyle, type TextStyle, StyleSheet } from 'react-native';
2
+ import {
3
+ Animated,
4
+ View,
5
+ type ViewStyle,
6
+ type TextStyle,
7
+ type DimensionValue,
8
+ StyleSheet,
9
+ } from 'react-native';
3
10
 
4
11
  import { useTheme } from '../theme/use-theme';
5
12
  import { SUPPORTS_NATIVE_DRIVER } from '../styles/native-driver';
@@ -129,6 +136,52 @@ export function Pill({
129
136
  }
130
137
  Pill.displayName = 'Skeleton.Pill';
131
138
 
139
+ /**
140
+ * Generic rectangular shimmering placeholder. Use for image/card/banner
141
+ * placeholders where neither {@link Pill} (forced borderRadius: 999) nor
142
+ * {@link Circle} fit. Defaults to a small borderRadius (8). Pass `0` for
143
+ * sharp corners or any larger number / percentage string for custom shapes.
144
+ */
145
+ export function Box({
146
+ width,
147
+ height,
148
+ borderRadius = 8,
149
+ blend,
150
+ style,
151
+ }: {
152
+ /** Width as a number, percentage string, or any valid RN dimension. */
153
+ width?: DimensionValue;
154
+ /** Height as a number, percentage string, or any valid RN dimension. */
155
+ height?: DimensionValue;
156
+ /**
157
+ * Corner radius — number or percentage string. Defaults to 8. Pass 0 for
158
+ * sharp corners.
159
+ */
160
+ borderRadius?: ViewStyle['borderRadius'];
161
+ /** When true, dampens shimmer opacity (use for nested skeletons). */
162
+ blend?: boolean;
163
+ style?: ViewStyle | ViewStyle[];
164
+ }) {
165
+ const { colors } = useTheme();
166
+ const shimmer = useShimmer();
167
+
168
+ return (
169
+ <Animated.View
170
+ style={[
171
+ {
172
+ backgroundColor: colors.contrast50,
173
+ width,
174
+ height,
175
+ borderRadius,
176
+ opacity: Animated.multiply(shimmer, blend ? 0.6 : 1),
177
+ },
178
+ style,
179
+ ]}
180
+ />
181
+ );
182
+ }
183
+ Box.displayName = 'Skeleton.Box';
184
+
132
185
  export function Col({
133
186
  children,
134
187
  style,
@@ -1,3 +1,8 @@
1
+ // Side-effect import — must come first. Initializes react-native-css-interop's
2
+ // `darkMode` flag to `'class'` at module load so its MutationObserver doesn't
3
+ // throw "Cannot manually set color scheme, as dark mode is type 'media'" the
4
+ // first time Bloom toggles the dark class on <html>. See ./init-css-interop.
5
+ import './init-css-interop';
1
6
  import React, { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react';
2
7
  import { useColorScheme as useRNColorScheme, Platform } from 'react-native';
3
8
  import { APP_COLOR_PRESETS, type AppColorName } from './color-presets';
@@ -6,3 +6,4 @@ export type { AppColorName, AppColorPreset } from './color-presets';
6
6
  export { APP_COLOR_NAMES, APP_COLOR_PRESETS, HEX_TO_APP_COLOR, hexToAppColorName } from './color-presets';
7
7
  export { applyDarkClass } from './apply-dark-class';
8
8
  export { setColorSchemeSafe } from './set-color-scheme-safe';
9
+ export { initCssInteropDarkMode } from './init-css-interop';
@@ -0,0 +1,126 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ /**
4
+ * Initialize react-native-css-interop's `darkMode` flag to `'class'` once at
5
+ * module load time so that downstream calls to its color-scheme machinery do
6
+ * not throw.
7
+ *
8
+ * Why this exists
9
+ * ---------------
10
+ * Bloom toggles a `dark` class on `<html>` (see `applyDarkClass`). When the
11
+ * consuming app ships `react-native-css-interop` (directly or via NativeWind),
12
+ * its web runtime installs a MutationObserver on `<head>` that watches for
13
+ * the NativeWind-generated CSS to be injected. Once that CSS lands, the
14
+ * observer reads the `--css-interop-darkMode` CSS variable and calls
15
+ * `colorScheme.set(...)`. If the active value is `'media'` (the Tailwind
16
+ * default when `darkMode` is unset), `colorScheme.set` throws:
17
+ *
18
+ * "Cannot manually set color scheme, as dark mode is type 'media'.
19
+ * Please use StyleSheet.setFlag('darkMode', 'class')"
20
+ *
21
+ * Bloom is class-driven by design — `applyDarkClass` toggles `<html>.dark` —
22
+ * so we need to force the flag to `'class'` before that observer fires.
23
+ *
24
+ * How it works
25
+ * ------------
26
+ * - On web we set the documented `--css-interop-darkMode` CSS custom property
27
+ * on `documentElement`. This is exactly what NativeWind's Tailwind plugin
28
+ * writes when its config is `darkMode: 'class'`, so we are replicating the
29
+ * public contract — not poking internals.
30
+ * - We additionally try to call `StyleSheet.setFlag('darkMode', 'class')`
31
+ * off of `react-native-css-interop`'s exported `StyleSheet`. The function
32
+ * does not exist in current `react-native-css-interop` (≤0.2.4), but the
33
+ * error message advertises it and future versions are likely to add it.
34
+ * Calling it is forward-compatible; missing-function is a no-op.
35
+ *
36
+ * The whole routine is idempotent and runs exactly once per process via
37
+ * a module-scoped guard.
38
+ */
39
+
40
+ let initialized = false;
41
+ let warned = false;
42
+
43
+ const CSS_VAR_NAME = '--css-interop-darkMode';
44
+ const CSS_VAR_VALUE = 'class dark';
45
+
46
+ interface CssInteropStyleSheet {
47
+ setFlag?: (name: string, value: string) => void;
48
+ }
49
+
50
+ interface CssInteropModule {
51
+ StyleSheet?: CssInteropStyleSheet;
52
+ }
53
+
54
+ function warnOnce(message: string, error?: unknown): void {
55
+ if (warned) return;
56
+ warned = true;
57
+ // Internal Bloom diagnostic. Consumers cannot react to this — it signals
58
+ // a possible compatibility issue between Bloom and the host's css-interop.
59
+ // eslint-disable-next-line no-console
60
+ console.warn(`[Bloom] ${message}`, error ?? '');
61
+ }
62
+
63
+ function setWebCssVariable(): void {
64
+ if (typeof document === 'undefined') return;
65
+ const root = document.documentElement;
66
+ if (!root) return;
67
+ // Only set if not already explicitly configured by the host (e.g. the host's
68
+ // Tailwind config already emitted this variable). Avoid clobbering an
69
+ // explicit `media` choice from the consumer.
70
+ const current = root.style.getPropertyValue(CSS_VAR_NAME);
71
+ if (current) return;
72
+ root.style.setProperty(CSS_VAR_NAME, CSS_VAR_VALUE);
73
+ }
74
+
75
+ function tryCallSetFlag(): void {
76
+ let mod: CssInteropModule | undefined;
77
+ try {
78
+ // Dynamic require: css-interop is not a Bloom dependency. If the host
79
+ // app ships it (via NativeWind or directly), this resolves. Otherwise
80
+ // the require throws and we silently move on — there is nothing to
81
+ // initialize because css-interop is not in the bundle.
82
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
83
+ mod = require('react-native-css-interop') as CssInteropModule;
84
+ } catch {
85
+ return;
86
+ }
87
+
88
+ const setFlag = mod?.StyleSheet?.setFlag;
89
+ if (typeof setFlag !== 'function') {
90
+ // Current react-native-css-interop (≤0.2.4) does not expose `setFlag`.
91
+ // The CSS variable path above is the actual fix on web; on native the
92
+ // flag is baked in by the Tailwind build. Surface a warning so we
93
+ // notice if a future version adds the method but we miss it.
94
+ return;
95
+ }
96
+
97
+ try {
98
+ setFlag.call(mod?.StyleSheet, 'darkMode', 'class');
99
+ } catch (error) {
100
+ warnOnce(
101
+ 'react-native-css-interop StyleSheet.setFlag("darkMode", "class") threw. ' +
102
+ 'Falling back to CSS variable. This is non-fatal.',
103
+ error,
104
+ );
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Idempotent initializer. Safe to call from multiple modules; only the first
110
+ * invocation performs work.
111
+ */
112
+ export function initCssInteropDarkMode(): void {
113
+ if (initialized) return;
114
+ initialized = true;
115
+
116
+ if (Platform.OS === 'web') {
117
+ setWebCssVariable();
118
+ }
119
+
120
+ tryCallSetFlag();
121
+ }
122
+
123
+ // Run on module import so that the flag is in place before any component
124
+ // code (and, critically, before css-interop's MutationObserver fires on web).
125
+ // useEffect would be too late — observers can fire during initial render.
126
+ initCssInteropDarkMode();