@dloizides/ui-feedback 1.2.0 → 1.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.0
4
+
5
+ - Add `ToastHost` — the shared, tokenized transient-toast overlay promoted from the
6
+ byte-identical erevna-web / katalogos-web `ToastContainer` twins. Rendering (animated
7
+ fade, positioning, theming) lives here; the emit pipeline stays in the app and is wired
8
+ in via the `subscribe` port (`(push) => unsubscribe`). Colours come from the UiProvider
9
+ theme. New exports: `ToastHost`, `ToastHostProps`, `ToastInput`, `ToastType`, plus the
10
+ `notificationToast` id in `FEEDBACK_TEST_IDS` (default toast testID `notification-toast`,
11
+ preserving existing Playwright selectors).
12
+
3
13
  ## 1.2.0
4
14
 
5
15
  - Broaden the injected theme so the settings-hub kit can consume it: colour scales are now
package/dist/index.d.mts CHANGED
@@ -75,6 +75,8 @@ declare const FEEDBACK_TEST_IDS: {
75
75
  readonly confirmDialog: "confirm-dialog";
76
76
  readonly confirmButton: "confirm-button";
77
77
  readonly cancelConfirmButton: "cancel-confirm-button";
78
+ readonly notificationToast: "notification-toast";
79
+ readonly warmingOverlay: "warming-overlay";
78
80
  };
79
81
 
80
82
  /**
@@ -154,4 +156,125 @@ interface ConfirmDialogProps {
154
156
  }
155
157
  declare const ConfirmDialog: ({ visible, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, confirmDisabled, loading, destructive, }: ConfirmDialogProps) => React.ReactElement | null;
156
158
 
157
- export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, useFeedbackUi, useFeedbackUi as useUi };
159
+ /**
160
+ * ToastHost — the shared, tokenized transient-toast overlay promoted from the
161
+ * byte-identical erevna-web / katalogos-web `ToastContainer` twins.
162
+ *
163
+ * The RENDERING (animated fade-in/out, positioning, theming) lives here; the
164
+ * EMIT pipeline stays in the app (its event bus / `@dloizides/bff-web-client`
165
+ * toast emitter). The app wires the two together via the `subscribe` port: a
166
+ * function that registers a push callback and returns an unsubscribe. Colours
167
+ * come from the UiProvider theme (`useUi`) — nothing hardcoded.
168
+ */
169
+
170
+ type ToastType = 'success' | 'info' | 'error';
171
+ /** What the app pushes through the `subscribe` port. */
172
+ interface ToastInput {
173
+ text: string;
174
+ type?: ToastType;
175
+ }
176
+ interface ToastHostProps {
177
+ /**
178
+ * Register a push callback; return an unsubscribe. The app adapts its own
179
+ * event bus (e.g. `@dloizides/bff-web-client`'s toast emitter) to this port.
180
+ */
181
+ subscribe: (push: (toast: ToastInput) => void) => () => void;
182
+ /** How long each toast stays before fading (ms). Default 3000. */
183
+ durationMs?: number;
184
+ /** Fade in/out animation duration (ms). Default 200. */
185
+ fadeMs?: number;
186
+ /** Max message length before truncation. Default 500. */
187
+ maxLength?: number;
188
+ /** testID for each toast (defaults to `notification-toast`). */
189
+ toastTestID?: string;
190
+ }
191
+ declare const ToastHost: ({ subscribe, durationMs, fadeMs, maxLength, toastTestID, }: ToastHostProps) => React.ReactElement | null;
192
+
193
+ /**
194
+ * WarmingOverlay — a calm, branded, full-screen "warming up…" overlay for the
195
+ * cold-start UX (Move 3a). It subscribes to the framework-agnostic warmingStore
196
+ * via `useSyncExternalStore` and renders ONLY while `isWarming`, then disappears
197
+ * on auto-settle (so it never permanently traps focus).
198
+ *
199
+ * This is intentionally NOT an error state: a title + subtitle + spinner, with an
200
+ * optional attempt hint. Colours come from the UiProvider theme (`useFeedbackUi`)
201
+ * or an explicit `theme` override — nothing hardcoded. Copy comes from `labels`,
202
+ * a typed bag with English defaults merged with a partial override, so consuming
203
+ * apps can localize but nothing breaks without it.
204
+ */
205
+
206
+ /** Copy for the overlay. All fields have English defaults; apps override any subset. */
207
+ interface WarmingOverlayLabels {
208
+ /** Big line, e.g. "Warming up…". */
209
+ title: string;
210
+ /** Reassuring second line, e.g. "This only takes a moment". */
211
+ subtitle: string;
212
+ /** Screen-reader label for the whole overlay. */
213
+ accessibilityLabel: string;
214
+ /** Optional per-attempt hint, given the current attempt number. */
215
+ attemptHint: (attempt: number) => string;
216
+ }
217
+ interface WarmingOverlayProps {
218
+ /** Partial copy override; unset fields fall back to English defaults. */
219
+ labels?: Partial<WarmingOverlayLabels>;
220
+ /** Theme override; defaults to the mounted UiProvider theme. */
221
+ theme?: FeedbackTheme;
222
+ /** testID for the overlay container (children derive `${prefix}-title`, etc.). */
223
+ testIdPrefix?: string;
224
+ /** Show the "Attempt N" hint under the subtitle (default: false). */
225
+ showAttempt?: boolean;
226
+ }
227
+ declare const WarmingOverlay: ({ labels, theme: themeOverride, testIdPrefix, showAttempt, }: WarmingOverlayProps) => React.ReactElement | null;
228
+
229
+ /**
230
+ * warmingStore — a tiny, framework-agnostic (no React) store for the cold-start
231
+ * "warming up…" UX (Move 3a).
232
+ *
233
+ * On a resource-tight, scale-to-zero prod node the BFF/upstream can be cold on the
234
+ * FIRST request after idle. `@dloizides/bff-web-client`'s `warmupRetryInterceptor`
235
+ * transparently retries the 502/503/504 and fires `onWarmupRetry({ attempt, … })`
236
+ * per retry — but it has NO "recovered" signal (it only fires on retries, never on
237
+ * the eventual success). So an app wires its `onWarmupRetry` to `notifyWarming(...)`
238
+ * here, and this store AUTO-SETTLES `isWarming` back to false after a quiet period
239
+ * with no new notify (i.e. the request finally succeeded and retries stopped).
240
+ *
241
+ * Shaped for React's `useSyncExternalStore`: `subscribeWarming` + `getWarmingSnapshot`
242
+ * (the snapshot object identity only changes when the value changes, so no render loop).
243
+ * SSR/no-DOM safe (timer is guarded, no `window`) and deterministic (no `Date.now()` /
244
+ * `Math.random()`).
245
+ */
246
+ /**
247
+ * How long (ms) the store stays "warming" after the LAST `notifyWarming` before it
248
+ * auto-clears. Sized a touch above the interceptor's largest backoff so a genuine
249
+ * retry storm keeps the overlay up, but a recovered request lets it settle.
250
+ */
251
+ declare const WARMING_QUIET_PERIOD_MS = 2500;
252
+ /** What an app forwards from the interceptor's `onWarmupRetry` callback. */
253
+ interface WarmingInfo {
254
+ attempt: number;
255
+ maxRetries?: number;
256
+ status?: number;
257
+ }
258
+ /** Immutable snapshot read by `useSyncExternalStore`. */
259
+ interface WarmingSnapshot {
260
+ isWarming: boolean;
261
+ attempt: number;
262
+ }
263
+ type WarmingListener = () => void;
264
+ /**
265
+ * Mark the store "warming" and record the latest retry attempt. Resets the
266
+ * auto-settle timer, so as long as retries keep arriving the overlay stays up.
267
+ * Call this from an app's `onWarmupRetry`.
268
+ */
269
+ declare function notifyWarming(info: WarmingInfo): void;
270
+ /**
271
+ * Force-clear the warming state (for tests, or to wire an explicit success signal
272
+ * later). Also cancels any pending auto-settle timer. No-op when already idle.
273
+ */
274
+ declare function settleWarming(): void;
275
+ /** Register a listener; returns an unsubscribe. Shaped for `useSyncExternalStore`. */
276
+ declare function subscribeWarming(listener: WarmingListener): () => void;
277
+ /** Current immutable snapshot. Stable identity until the value changes. */
278
+ declare function getWarmingSnapshot(): WarmingSnapshot;
279
+
280
+ export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ToastHost, type ToastHostProps, type ToastInput, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,8 @@ declare const FEEDBACK_TEST_IDS: {
75
75
  readonly confirmDialog: "confirm-dialog";
76
76
  readonly confirmButton: "confirm-button";
77
77
  readonly cancelConfirmButton: "cancel-confirm-button";
78
+ readonly notificationToast: "notification-toast";
79
+ readonly warmingOverlay: "warming-overlay";
78
80
  };
79
81
 
80
82
  /**
@@ -154,4 +156,125 @@ interface ConfirmDialogProps {
154
156
  }
155
157
  declare const ConfirmDialog: ({ visible, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, confirmDisabled, loading, destructive, }: ConfirmDialogProps) => React.ReactElement | null;
156
158
 
157
- export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, useFeedbackUi, useFeedbackUi as useUi };
159
+ /**
160
+ * ToastHost — the shared, tokenized transient-toast overlay promoted from the
161
+ * byte-identical erevna-web / katalogos-web `ToastContainer` twins.
162
+ *
163
+ * The RENDERING (animated fade-in/out, positioning, theming) lives here; the
164
+ * EMIT pipeline stays in the app (its event bus / `@dloizides/bff-web-client`
165
+ * toast emitter). The app wires the two together via the `subscribe` port: a
166
+ * function that registers a push callback and returns an unsubscribe. Colours
167
+ * come from the UiProvider theme (`useUi`) — nothing hardcoded.
168
+ */
169
+
170
+ type ToastType = 'success' | 'info' | 'error';
171
+ /** What the app pushes through the `subscribe` port. */
172
+ interface ToastInput {
173
+ text: string;
174
+ type?: ToastType;
175
+ }
176
+ interface ToastHostProps {
177
+ /**
178
+ * Register a push callback; return an unsubscribe. The app adapts its own
179
+ * event bus (e.g. `@dloizides/bff-web-client`'s toast emitter) to this port.
180
+ */
181
+ subscribe: (push: (toast: ToastInput) => void) => () => void;
182
+ /** How long each toast stays before fading (ms). Default 3000. */
183
+ durationMs?: number;
184
+ /** Fade in/out animation duration (ms). Default 200. */
185
+ fadeMs?: number;
186
+ /** Max message length before truncation. Default 500. */
187
+ maxLength?: number;
188
+ /** testID for each toast (defaults to `notification-toast`). */
189
+ toastTestID?: string;
190
+ }
191
+ declare const ToastHost: ({ subscribe, durationMs, fadeMs, maxLength, toastTestID, }: ToastHostProps) => React.ReactElement | null;
192
+
193
+ /**
194
+ * WarmingOverlay — a calm, branded, full-screen "warming up…" overlay for the
195
+ * cold-start UX (Move 3a). It subscribes to the framework-agnostic warmingStore
196
+ * via `useSyncExternalStore` and renders ONLY while `isWarming`, then disappears
197
+ * on auto-settle (so it never permanently traps focus).
198
+ *
199
+ * This is intentionally NOT an error state: a title + subtitle + spinner, with an
200
+ * optional attempt hint. Colours come from the UiProvider theme (`useFeedbackUi`)
201
+ * or an explicit `theme` override — nothing hardcoded. Copy comes from `labels`,
202
+ * a typed bag with English defaults merged with a partial override, so consuming
203
+ * apps can localize but nothing breaks without it.
204
+ */
205
+
206
+ /** Copy for the overlay. All fields have English defaults; apps override any subset. */
207
+ interface WarmingOverlayLabels {
208
+ /** Big line, e.g. "Warming up…". */
209
+ title: string;
210
+ /** Reassuring second line, e.g. "This only takes a moment". */
211
+ subtitle: string;
212
+ /** Screen-reader label for the whole overlay. */
213
+ accessibilityLabel: string;
214
+ /** Optional per-attempt hint, given the current attempt number. */
215
+ attemptHint: (attempt: number) => string;
216
+ }
217
+ interface WarmingOverlayProps {
218
+ /** Partial copy override; unset fields fall back to English defaults. */
219
+ labels?: Partial<WarmingOverlayLabels>;
220
+ /** Theme override; defaults to the mounted UiProvider theme. */
221
+ theme?: FeedbackTheme;
222
+ /** testID for the overlay container (children derive `${prefix}-title`, etc.). */
223
+ testIdPrefix?: string;
224
+ /** Show the "Attempt N" hint under the subtitle (default: false). */
225
+ showAttempt?: boolean;
226
+ }
227
+ declare const WarmingOverlay: ({ labels, theme: themeOverride, testIdPrefix, showAttempt, }: WarmingOverlayProps) => React.ReactElement | null;
228
+
229
+ /**
230
+ * warmingStore — a tiny, framework-agnostic (no React) store for the cold-start
231
+ * "warming up…" UX (Move 3a).
232
+ *
233
+ * On a resource-tight, scale-to-zero prod node the BFF/upstream can be cold on the
234
+ * FIRST request after idle. `@dloizides/bff-web-client`'s `warmupRetryInterceptor`
235
+ * transparently retries the 502/503/504 and fires `onWarmupRetry({ attempt, … })`
236
+ * per retry — but it has NO "recovered" signal (it only fires on retries, never on
237
+ * the eventual success). So an app wires its `onWarmupRetry` to `notifyWarming(...)`
238
+ * here, and this store AUTO-SETTLES `isWarming` back to false after a quiet period
239
+ * with no new notify (i.e. the request finally succeeded and retries stopped).
240
+ *
241
+ * Shaped for React's `useSyncExternalStore`: `subscribeWarming` + `getWarmingSnapshot`
242
+ * (the snapshot object identity only changes when the value changes, so no render loop).
243
+ * SSR/no-DOM safe (timer is guarded, no `window`) and deterministic (no `Date.now()` /
244
+ * `Math.random()`).
245
+ */
246
+ /**
247
+ * How long (ms) the store stays "warming" after the LAST `notifyWarming` before it
248
+ * auto-clears. Sized a touch above the interceptor's largest backoff so a genuine
249
+ * retry storm keeps the overlay up, but a recovered request lets it settle.
250
+ */
251
+ declare const WARMING_QUIET_PERIOD_MS = 2500;
252
+ /** What an app forwards from the interceptor's `onWarmupRetry` callback. */
253
+ interface WarmingInfo {
254
+ attempt: number;
255
+ maxRetries?: number;
256
+ status?: number;
257
+ }
258
+ /** Immutable snapshot read by `useSyncExternalStore`. */
259
+ interface WarmingSnapshot {
260
+ isWarming: boolean;
261
+ attempt: number;
262
+ }
263
+ type WarmingListener = () => void;
264
+ /**
265
+ * Mark the store "warming" and record the latest retry attempt. Resets the
266
+ * auto-settle timer, so as long as retries keep arriving the overlay stays up.
267
+ * Call this from an app's `onWarmupRetry`.
268
+ */
269
+ declare function notifyWarming(info: WarmingInfo): void;
270
+ /**
271
+ * Force-clear the warming state (for tests, or to wire an explicit success signal
272
+ * later). Also cancels any pending auto-settle timer. No-op when already idle.
273
+ */
274
+ declare function settleWarming(): void;
275
+ /** Register a listener; returns an unsubscribe. Shaped for `useSyncExternalStore`. */
276
+ declare function subscribeWarming(listener: WarmingListener): () => void;
277
+ /** Current immutable snapshot. Stable identity until the value changes. */
278
+ declare function getWarmingSnapshot(): WarmingSnapshot;
279
+
280
+ export { ConfirmDialog, type ConfirmDialogProps, DISABLED_OPACITY, EmptyListState, type EmptyListStateProps, ErrorState, type ErrorStateProps, FEEDBACK_TEST_IDS, type FeedbackColorScale, type FeedbackNavigate, type FeedbackTheme, type FeedbackThemeColors, type FeedbackThemePalette, type FeedbackThemeSemantic, type FeedbackTranslate, FeedbackUiProvider, type FeedbackUiProviderProps, type FeedbackUiValue, LoadingFallback, type LoadingFallbackProps, MODAL_OVERLAY_COLOR, PageSkeleton, type PageSkeletonProps, ToastHost, type ToastHostProps, type ToastInput, type ToastType, type FeedbackColorScale as UiColorScale, type FeedbackNavigate as UiNavigate, FeedbackUiProvider as UiProvider, type FeedbackUiProviderProps as UiProviderProps, type FeedbackTheme as UiTheme, type FeedbackThemeColors as UiThemeColors, type FeedbackThemePalette as UiThemePalette, type FeedbackThemeSemantic as UiThemeSemantic, type FeedbackTranslate as UiTranslate, type FeedbackUiValue as UiValue, WARMING_QUIET_PERIOD_MS, type WarmingInfo, WarmingOverlay, type WarmingOverlayLabels, type WarmingOverlayProps, type WarmingSnapshot, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
package/dist/index.js CHANGED
@@ -58,7 +58,9 @@ var FEEDBACK_TEST_IDS = {
58
58
  pageSkeleton: "page-skeleton",
59
59
  confirmDialog: "confirm-dialog",
60
60
  confirmButton: "confirm-button",
61
- cancelConfirmButton: "cancel-confirm-button"
61
+ cancelConfirmButton: "cancel-confirm-button",
62
+ notificationToast: "notification-toast",
63
+ warmingOverlay: "warming-overlay"
62
64
  };
63
65
  var MESSAGE_FONT_SIZE = 16;
64
66
  var CONTAINER_PADDING = 20;
@@ -462,6 +464,271 @@ var ConfirmDialog = ({
462
464
  }
463
465
  );
464
466
  };
467
+ var DEFAULT_DURATION_MS = 3e3;
468
+ var DEFAULT_FADE_MS = 200;
469
+ var DEFAULT_MAX_LENGTH = 500;
470
+ var TOAST_TOP_WEB = 10;
471
+ var TOAST_TOP_MOBILE = 40;
472
+ var TOAST_HORIZONTAL_MARGIN = 10;
473
+ var TOAST_Z_INDEX = 9999;
474
+ var TOAST_INITIAL_TRANSLATE_Y = -6;
475
+ var TOAST_MAX_WIDTH = 600;
476
+ var TOAST_PADDING_HORIZONTAL = 16;
477
+ var TOAST_PADDING_VERTICAL = 10;
478
+ var TOAST_BORDER_RADIUS = 8;
479
+ var TOAST_MARGIN_VERTICAL = 6;
480
+ var C0_CONTROL_END = 31;
481
+ var C1_CONTROL_START = 127;
482
+ var C1_CONTROL_END = 159;
483
+ var ZERO_WIDTH_START = 8203;
484
+ var ZERO_WIDTH_END = 8207;
485
+ var BYTE_ORDER_MARK = 65279;
486
+ var styles6 = reactNative.StyleSheet.create({
487
+ container: {
488
+ position: "absolute",
489
+ top: reactNative.Platform.OS === "web" ? TOAST_TOP_WEB : TOAST_TOP_MOBILE,
490
+ left: TOAST_HORIZONTAL_MARGIN,
491
+ right: TOAST_HORIZONTAL_MARGIN,
492
+ alignItems: "center",
493
+ zIndex: TOAST_Z_INDEX,
494
+ pointerEvents: "box-none"
495
+ },
496
+ toast: {
497
+ paddingHorizontal: TOAST_PADDING_HORIZONTAL,
498
+ paddingVertical: TOAST_PADDING_VERTICAL,
499
+ borderRadius: TOAST_BORDER_RADIUS,
500
+ marginVertical: TOAST_MARGIN_VERTICAL,
501
+ minWidth: "40%",
502
+ maxWidth: TOAST_MAX_WIDTH,
503
+ boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)",
504
+ elevation: 4
505
+ },
506
+ text: {}
507
+ });
508
+ function sanitizeToastText(input, maxLength) {
509
+ let stripped = "";
510
+ for (const ch of input) {
511
+ const code = ch.codePointAt(0) ?? 0;
512
+ const isControl = code <= C0_CONTROL_END || code >= C1_CONTROL_START && code <= C1_CONTROL_END;
513
+ const isHidden = code >= ZERO_WIDTH_START && code <= ZERO_WIDTH_END || code === BYTE_ORDER_MARK;
514
+ if (!isControl && !isHidden) stripped += ch;
515
+ }
516
+ return stripped.length > maxLength ? stripped.slice(0, maxLength) : stripped;
517
+ }
518
+ var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
519
+ const opacityRef = React3.useRef(new reactNative.Animated.Value(0));
520
+ const translateYRef = React3.useRef(new reactNative.Animated.Value(TOAST_INITIAL_TRANSLATE_Y));
521
+ const opacity = opacityRef.current;
522
+ const translateY = translateYRef.current;
523
+ const backgroundColor = React3.useMemo(() => {
524
+ if (message.type === "success") return colors.success;
525
+ if (message.type === "error") return colors.error;
526
+ return colors.primary;
527
+ }, [colors.error, colors.primary, colors.success, message.type]);
528
+ const handleDone = React3.useCallback(() => {
529
+ onDone(message.id);
530
+ }, [message.id, onDone]);
531
+ React3.useEffect(() => {
532
+ const useNative = reactNative.Platform.OS !== "web";
533
+ reactNative.Animated.parallel([
534
+ reactNative.Animated.timing(opacity, { toValue: 1, duration: fadeMs, useNativeDriver: useNative }),
535
+ reactNative.Animated.timing(translateY, { toValue: 0, duration: fadeMs, useNativeDriver: useNative })
536
+ ]).start();
537
+ const hideTimer = setTimeout(() => {
538
+ reactNative.Animated.parallel([
539
+ reactNative.Animated.timing(opacity, { toValue: 0, duration: fadeMs, useNativeDriver: useNative }),
540
+ reactNative.Animated.timing(translateY, { toValue: TOAST_INITIAL_TRANSLATE_Y, duration: fadeMs, useNativeDriver: useNative })
541
+ ]).start(handleDone);
542
+ }, durationMs);
543
+ return () => clearTimeout(hideTimer);
544
+ }, [handleDone, opacity, translateY, durationMs, fadeMs]);
545
+ return /* @__PURE__ */ jsxRuntime.jsx(
546
+ reactNative.Animated.View,
547
+ {
548
+ style: [styles6.toast, { backgroundColor, transform: [{ translateY }], opacity }],
549
+ testID,
550
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles6.text, { color: colors.text }], children: message.text })
551
+ }
552
+ );
553
+ };
554
+ var toastSeq = 0;
555
+ function nextId() {
556
+ toastSeq += 1;
557
+ return `${String(Date.now())}-${String(toastSeq)}`;
558
+ }
559
+ var ToastHost = ({
560
+ subscribe,
561
+ durationMs = DEFAULT_DURATION_MS,
562
+ fadeMs = DEFAULT_FADE_MS,
563
+ maxLength = DEFAULT_MAX_LENGTH,
564
+ toastTestID = FEEDBACK_TEST_IDS.notificationToast
565
+ }) => {
566
+ const [messages, setMessages] = React3.useState([]);
567
+ const { theme } = useFeedbackUi();
568
+ const colors = React3.useMemo(
569
+ () => ({
570
+ primary: theme.palette.primary["500"],
571
+ success: (theme.semantic.success ?? theme.semantic.error)["500"],
572
+ error: theme.semantic.error["500"],
573
+ text: theme.colors.surfaceElevated
574
+ }),
575
+ [theme]
576
+ );
577
+ const push = React3.useCallback(
578
+ (toast) => {
579
+ setMessages((s) => [...s, { id: nextId(), type: toast.type, text: sanitizeToastText(toast.text, maxLength) }]);
580
+ },
581
+ [maxLength]
582
+ );
583
+ const remove = React3.useCallback((id) => {
584
+ setMessages((s) => s.filter((x) => x.id !== id));
585
+ }, []);
586
+ React3.useEffect(() => subscribe(push), [subscribe, push]);
587
+ if (messages.length === 0) return null;
588
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles6.container, children: messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(
589
+ ToastItem,
590
+ {
591
+ colors,
592
+ durationMs,
593
+ fadeMs,
594
+ message: m,
595
+ testID: toastTestID,
596
+ onDone: remove
597
+ },
598
+ m.id
599
+ )) });
600
+ };
601
+
602
+ // src/Warming/warmingStore.ts
603
+ var WARMING_QUIET_PERIOD_MS = 2500;
604
+ var IDLE_ATTEMPT = 0;
605
+ var warming = false;
606
+ var currentAttempt = IDLE_ATTEMPT;
607
+ var snapshot = { isWarming: false, attempt: IDLE_ATTEMPT };
608
+ var listeners = /* @__PURE__ */ new Set();
609
+ var quietTimer;
610
+ function refreshSnapshot() {
611
+ snapshot = { isWarming: warming, attempt: currentAttempt };
612
+ }
613
+ function emit() {
614
+ for (const listener of listeners) listener();
615
+ }
616
+ function clearQuietTimer() {
617
+ if (quietTimer !== void 0) {
618
+ clearTimeout(quietTimer);
619
+ quietTimer = void 0;
620
+ }
621
+ }
622
+ function scheduleSettle() {
623
+ clearQuietTimer();
624
+ if (typeof setTimeout !== "function") return;
625
+ quietTimer = setTimeout(() => {
626
+ quietTimer = void 0;
627
+ settleWarming();
628
+ }, WARMING_QUIET_PERIOD_MS);
629
+ }
630
+ function notifyWarming(info) {
631
+ const changed = !warming || currentAttempt !== info.attempt;
632
+ warming = true;
633
+ currentAttempt = info.attempt;
634
+ scheduleSettle();
635
+ if (changed) {
636
+ refreshSnapshot();
637
+ emit();
638
+ }
639
+ }
640
+ function settleWarming() {
641
+ clearQuietTimer();
642
+ if (!warming) return;
643
+ warming = false;
644
+ currentAttempt = IDLE_ATTEMPT;
645
+ refreshSnapshot();
646
+ emit();
647
+ }
648
+ function subscribeWarming(listener) {
649
+ listeners.add(listener);
650
+ return () => {
651
+ listeners.delete(listener);
652
+ };
653
+ }
654
+ function getWarmingSnapshot() {
655
+ return snapshot;
656
+ }
657
+ var OVERLAY_Z_INDEX = 1e5;
658
+ var CARD_GAP = 12;
659
+ var TITLE_FONT_SIZE = 20;
660
+ var SUBTITLE_FONT_SIZE = 15;
661
+ var ATTEMPT_FONT_SIZE = 13;
662
+ var CARD_PADDING = 24;
663
+ var NO_ATTEMPT = 0;
664
+ var styles7 = reactNative.StyleSheet.create({
665
+ overlay: {
666
+ position: "absolute",
667
+ top: 0,
668
+ left: 0,
669
+ right: 0,
670
+ bottom: 0,
671
+ alignItems: "center",
672
+ justifyContent: "center",
673
+ zIndex: OVERLAY_Z_INDEX,
674
+ elevation: OVERLAY_Z_INDEX,
675
+ padding: CARD_PADDING
676
+ },
677
+ card: {
678
+ alignItems: "center",
679
+ gap: CARD_GAP,
680
+ maxWidth: 320
681
+ },
682
+ title: {
683
+ fontSize: TITLE_FONT_SIZE,
684
+ fontWeight: "700",
685
+ textAlign: "center"
686
+ },
687
+ subtitle: {
688
+ fontSize: SUBTITLE_FONT_SIZE,
689
+ textAlign: "center"
690
+ },
691
+ attempt: {
692
+ fontSize: ATTEMPT_FONT_SIZE,
693
+ textAlign: "center"
694
+ }
695
+ });
696
+ var DEFAULT_WARMING_LABELS = {
697
+ title: "Warming up\u2026",
698
+ subtitle: "This only takes a moment",
699
+ accessibilityLabel: "Warming up, please wait",
700
+ attemptHint: (attempt) => `Attempt ${String(attempt)}`
701
+ };
702
+ var WarmingOverlay = ({
703
+ labels,
704
+ theme: themeOverride,
705
+ testIdPrefix = FEEDBACK_TEST_IDS.warmingOverlay,
706
+ showAttempt = false
707
+ }) => {
708
+ const ctx = useFeedbackUi();
709
+ const snapshot2 = React3.useSyncExternalStore(subscribeWarming, getWarmingSnapshot, getWarmingSnapshot);
710
+ const theme = themeOverride ?? ctx.theme;
711
+ const mergedLabels = { ...DEFAULT_WARMING_LABELS, ...labels };
712
+ if (!snapshot2.isWarming) return null;
713
+ const colors = theme.colors;
714
+ const primary = theme.palette.primary["500"];
715
+ const showHint = showAttempt && snapshot2.attempt > NO_ATTEMPT;
716
+ return /* @__PURE__ */ jsxRuntime.jsx(
717
+ reactNative.View,
718
+ {
719
+ accessibilityLabel: mergedLabels.accessibilityLabel,
720
+ accessibilityRole: "alert",
721
+ style: [styles7.overlay, { backgroundColor: colors.background }],
722
+ testID: testIdPrefix,
723
+ children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.card, children: [
724
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.ActivityIndicator, { color: primary, size: "large" }),
725
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.title, { color: colors.text }], testID: `${testIdPrefix}-title`, children: mergedLabels.title }),
726
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.subtitle, { color: colors.textSecondary }], testID: `${testIdPrefix}-subtitle`, children: mergedLabels.subtitle }),
727
+ showHint ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.attempt, { color: colors.textSecondary }], testID: `${testIdPrefix}-attempt`, children: mergedLabels.attemptHint(snapshot2.attempt) }) : null
728
+ ] })
729
+ }
730
+ );
731
+ };
465
732
 
466
733
  exports.ConfirmDialog = ConfirmDialog;
467
734
  exports.DISABLED_OPACITY = DISABLED_OPACITY;
@@ -472,7 +739,14 @@ exports.FeedbackUiProvider = FeedbackUiProvider;
472
739
  exports.LoadingFallback = LoadingFallback;
473
740
  exports.MODAL_OVERLAY_COLOR = MODAL_OVERLAY_COLOR;
474
741
  exports.PageSkeleton = PageSkeleton;
742
+ exports.ToastHost = ToastHost;
475
743
  exports.UiProvider = FeedbackUiProvider;
744
+ exports.WARMING_QUIET_PERIOD_MS = WARMING_QUIET_PERIOD_MS;
745
+ exports.WarmingOverlay = WarmingOverlay;
746
+ exports.getWarmingSnapshot = getWarmingSnapshot;
747
+ exports.notifyWarming = notifyWarming;
748
+ exports.settleWarming = settleWarming;
749
+ exports.subscribeWarming = subscribeWarming;
476
750
  exports.useFeedbackUi = useFeedbackUi;
477
751
  exports.useUi = useFeedbackUi;
478
752
  //# sourceMappingURL=index.js.map