@applicaster/zapp-react-native-utils 15.0.0-rc.11 → 15.0.0-rc.111

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 (158) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +3 -6
  3. package/actionsExecutor/feedDecorator.ts +6 -6
  4. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  5. package/adsUtils/index.ts +2 -2
  6. package/analyticsUtils/README.md +1 -1
  7. package/analyticsUtils/analyticsMapper.ts +10 -2
  8. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  9. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  10. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  11. package/appUtils/HooksManager/index.ts +10 -10
  12. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  13. package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
  14. package/appUtils/accessibilityManager/const.ts +4 -0
  15. package/appUtils/accessibilityManager/hooks.ts +20 -13
  16. package/appUtils/accessibilityManager/index.ts +28 -1
  17. package/appUtils/accessibilityManager/utils.ts +59 -8
  18. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  19. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  20. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  21. package/appUtils/contextKeysManager/index.ts +65 -10
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +4 -0
  23. package/appUtils/focusManager/index.ios.ts +59 -3
  24. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  26. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  27. package/appUtils/focusManagerAux/utils/index.ts +21 -5
  28. package/appUtils/focusManagerAux/utils/utils.ios.ts +234 -0
  29. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  30. package/appUtils/orientationHelper.ts +2 -4
  31. package/appUtils/platform/platformUtils.ts +117 -18
  32. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  33. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  34. package/appUtils/playerManager/player.ts +4 -0
  35. package/appUtils/playerManager/playerNative.ts +31 -17
  36. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  37. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  38. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  39. package/arrayUtils/index.ts +5 -0
  40. package/cellUtils/index.ts +32 -0
  41. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  42. package/cloudEventsUtils/index.ts +65 -1
  43. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  44. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  45. package/configurationUtils/index.ts +17 -11
  46. package/dateUtils/__tests__/dayjs.test.ts +330 -0
  47. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  48. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  49. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  50. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  51. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  52. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  53. package/errorUtils/__tests__/invariant.test.ts +112 -0
  54. package/focusManager/aux/index.ts +1 -1
  55. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  56. package/headersUtils/index.ts +2 -1
  57. package/manifestUtils/defaultManifestConfigurations/player.js +109 -11
  58. package/manifestUtils/keys.js +21 -0
  59. package/manifestUtils/platformIsTV.js +13 -0
  60. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  61. package/manifestUtils/tvAction/container/index.js +1 -1
  62. package/navigationUtils/index.ts +15 -5
  63. package/numberUtils/__tests__/toNumber.test.ts +12 -0
  64. package/numberUtils/__tests__/toPositiveNumber.test.ts +165 -0
  65. package/numberUtils/index.ts +19 -1
  66. package/package.json +4 -4
  67. package/playerUtils/usePlayerTTS.ts +8 -3
  68. package/pluginUtils/index.ts +4 -0
  69. package/reactHooks/advertising/index.ts +2 -2
  70. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  71. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  72. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  73. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  74. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  75. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  76. package/reactHooks/connection/__tests__/index.test.js +1 -1
  77. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  78. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  79. package/reactHooks/device/useIsTablet.tsx +14 -19
  80. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  81. package/reactHooks/events/index.ts +20 -0
  82. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  83. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  84. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  85. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  86. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  87. package/reactHooks/feed/index.ts +0 -2
  88. package/reactHooks/feed/useBatchLoading.ts +7 -1
  89. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  90. package/reactHooks/feed/useInflatedUrl.ts +43 -17
  91. package/reactHooks/feed/usePipesCacheReset.ts +3 -1
  92. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  93. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  94. package/reactHooks/index.ts +2 -0
  95. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  96. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  97. package/reactHooks/layout/index.ts +1 -1
  98. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  99. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  100. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  101. package/reactHooks/navigation/index.ts +27 -11
  102. package/reactHooks/navigation/useRoute.ts +11 -7
  103. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  104. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  105. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  106. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  107. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  108. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  109. package/reactHooks/resolvers/useComponentResolver.ts +8 -2
  110. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  111. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  112. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  113. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  114. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  115. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  116. package/reactHooks/state/index.ts +2 -0
  117. package/reactHooks/state/useComponentScreenState.ts +45 -0
  118. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  119. package/reactHooks/state/useRivers.ts +1 -1
  120. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  121. package/reactHooks/usePluginConfiguration.ts +2 -2
  122. package/reactHooks/utils/__tests__/index.test.js +1 -1
  123. package/rectUtils/__tests__/index.test.ts +549 -0
  124. package/rectUtils/index.ts +2 -2
  125. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +161 -0
  126. package/refreshUtils/RefreshCoordinator/index.ts +216 -0
  127. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  128. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  129. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  130. package/screenPickerUtils/index.ts +5 -0
  131. package/screenState/__tests__/index.test.ts +1 -1
  132. package/screenUtils/index.ts +3 -0
  133. package/searchUtils/const.ts +7 -0
  134. package/searchUtils/index.ts +3 -0
  135. package/services/storageServiceSync.web.ts +1 -1
  136. package/stringUtils/index.ts +1 -1
  137. package/testUtils/index.tsx +30 -21
  138. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  139. package/time/__tests__/Timer.test.ts +236 -0
  140. package/typeGuards/__tests__/isString.test.ts +21 -0
  141. package/typeGuards/index.ts +4 -0
  142. package/utils/__tests__/clone.test.ts +158 -0
  143. package/utils/__tests__/mapAccum.test.ts +73 -0
  144. package/utils/__tests__/mergeRight.test.ts +48 -0
  145. package/utils/__tests__/path.test.ts +7 -0
  146. package/utils/__tests__/selectors.test.ts +124 -0
  147. package/utils/clone.ts +7 -0
  148. package/utils/index.ts +22 -1
  149. package/utils/mapAccum.ts +23 -0
  150. package/utils/mergeRight.ts +5 -0
  151. package/utils/path.ts +6 -3
  152. package/utils/pathOr.ts +5 -1
  153. package/utils/selectors.ts +46 -0
  154. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +49 -12
  155. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  156. package/reactHooks/componentsMap/index.ts +0 -55
  157. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  158. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -0,0 +1,360 @@
1
+ jest.mock("../../../logger", () => {
2
+ const mockLogError = jest.fn();
3
+
4
+ return {
5
+ createLogger: jest.fn(() => ({
6
+ log_error: mockLogError,
7
+ })),
8
+ __mockLogError: mockLogError, // Export for test access
9
+ };
10
+ });
11
+
12
+ import { calculateReadingTime } from "../utils";
13
+ // @ts-ignore - Access the mock
14
+ import { __mockLogError } from "../../../logger";
15
+
16
+ describe("calculateReadingTime", () => {
17
+ // Default parameters for reference
18
+ const DEFAULT_WPM = 140;
19
+ const DEFAULT_MIN_PAUSE = 500;
20
+ const DEFAULT_DELAY = 700;
21
+
22
+ beforeEach(() => {
23
+ (__mockLogError as jest.Mock).mockClear();
24
+ });
25
+
26
+ describe("Type Safety", () => {
27
+ it("should accept and process string input", () => {
28
+ const result = calculateReadingTime("Hello world");
29
+ expect(result).toBeGreaterThan(0);
30
+ expect(__mockLogError).not.toHaveBeenCalled();
31
+ });
32
+
33
+ it("should accept and process number input", () => {
34
+ const result = calculateReadingTime(12345);
35
+ expect(result).toBeGreaterThan(0);
36
+ expect(__mockLogError).not.toHaveBeenCalled();
37
+ });
38
+
39
+ it("should return 0 and log error for null", () => {
40
+ expect(calculateReadingTime(null as any)).toBe(0);
41
+
42
+ expect(__mockLogError).toHaveBeenCalledWith(
43
+ "Invalid text input for reading time calculation got: null"
44
+ );
45
+ });
46
+
47
+ it("should return 0 and log error for undefined", () => {
48
+ expect(calculateReadingTime(undefined as any)).toBe(0);
49
+
50
+ expect(__mockLogError).toHaveBeenCalledWith(
51
+ "Invalid text input for reading time calculation got: undefined"
52
+ );
53
+ });
54
+
55
+ it("should return 0 and log error for boolean", () => {
56
+ calculateReadingTime(true as any);
57
+
58
+ expect(__mockLogError).toHaveBeenCalledWith(
59
+ "Invalid text input for reading time calculation got: true"
60
+ );
61
+
62
+ (__mockLogError as jest.Mock).mockClear();
63
+
64
+ calculateReadingTime(false as any);
65
+
66
+ expect(__mockLogError).toHaveBeenCalledWith(
67
+ "Invalid text input for reading time calculation got: false"
68
+ );
69
+ });
70
+
71
+ it("should return 0 and log error for object", () => {
72
+ const obj = { text: "hello" };
73
+ calculateReadingTime(obj as any);
74
+
75
+ expect(__mockLogError).toHaveBeenCalledWith(
76
+ `Invalid text input for reading time calculation got: ${obj}`
77
+ );
78
+ });
79
+
80
+ it("should return 0 and log error for array", () => {
81
+ const arr = [1, 2, 3];
82
+ calculateReadingTime(arr as any);
83
+
84
+ expect(__mockLogError).toHaveBeenCalledWith(
85
+ `Invalid text input for reading time calculation got: ${arr}`
86
+ );
87
+ });
88
+
89
+ it("should return 0 and log error for function", () => {
90
+ const fn = () => "text";
91
+ calculateReadingTime(fn as any);
92
+ expect(__mockLogError).toHaveBeenCalled();
93
+
94
+ expect((__mockLogError as jest.Mock).mock.calls[0][0]).toContain(
95
+ "Invalid text input for reading time calculation got:"
96
+ );
97
+ });
98
+
99
+ it("should return 0 and log error for symbol", () => {
100
+ const sym = Symbol("test");
101
+ calculateReadingTime(sym as any);
102
+ expect(__mockLogError).toHaveBeenCalled();
103
+
104
+ expect((__mockLogError as jest.Mock).mock.calls[0][0]).toBe(
105
+ `Invalid text input for reading time calculation got: ${String(sym)}`
106
+ );
107
+ });
108
+ });
109
+
110
+ describe("Empty and Whitespace Handling", () => {
111
+ it("should return 0 for empty string", () => {
112
+ expect(calculateReadingTime("")).toBe(0);
113
+ });
114
+
115
+ it("should return 0 for whitespace-only string", () => {
116
+ expect(calculateReadingTime(" ")).toBe(0);
117
+ expect(calculateReadingTime("\n")).toBe(0);
118
+ expect(calculateReadingTime("\t")).toBe(0);
119
+ expect(calculateReadingTime(" \n\t ")).toBe(0);
120
+ });
121
+
122
+ it("should handle leading and trailing whitespace", () => {
123
+ const withWhitespace = calculateReadingTime(" hello ");
124
+ const withoutWhitespace = calculateReadingTime("hello");
125
+ expect(withWhitespace).toBe(withoutWhitespace);
126
+ });
127
+ });
128
+
129
+ describe("Number Input Handling", () => {
130
+ it("should convert number 0 to string and process", () => {
131
+ const result = calculateReadingTime(0);
132
+ // "0" is one word
133
+ expect(result).toBeGreaterThan(0);
134
+ });
135
+
136
+ it("should convert positive numbers to string", () => {
137
+ const result = calculateReadingTime(123);
138
+ // "123" is one word
139
+ expect(result).toBeGreaterThan(0);
140
+ });
141
+
142
+ it("should convert negative numbers to string", () => {
143
+ const result = calculateReadingTime(-456);
144
+ // "-456" is processed as words
145
+ expect(result).toBeGreaterThan(0);
146
+ });
147
+
148
+ it("should convert decimal numbers to string", () => {
149
+ const result = calculateReadingTime(3.14);
150
+ // "3.14" is processed as words
151
+ expect(result).toBeGreaterThan(0);
152
+ });
153
+
154
+ it("should handle NaN", () => {
155
+ const result = calculateReadingTime(NaN);
156
+ // NaN is typeof "number", so it converts to "NaN" string
157
+ expect(result).toBeGreaterThan(0);
158
+ });
159
+
160
+ it("should handle Infinity", () => {
161
+ const result = calculateReadingTime(Infinity);
162
+ // Infinity is typeof "number", converts to "Infinity" string
163
+ expect(result).toBeGreaterThan(0);
164
+ });
165
+ });
166
+
167
+ describe("Word Counting", () => {
168
+ it("should count single word", () => {
169
+ const result = calculateReadingTime("Hello");
170
+
171
+ const expectedTime = Math.max(
172
+ DEFAULT_MIN_PAUSE,
173
+ (1 / DEFAULT_WPM) * 60 * 1000
174
+ );
175
+
176
+ expect(result).toBe(expectedTime + DEFAULT_DELAY);
177
+ });
178
+
179
+ it("should count multiple words separated by spaces", () => {
180
+ const result = calculateReadingTime("Hello world test");
181
+
182
+ // 3 words
183
+ const expectedTime = Math.max(
184
+ DEFAULT_MIN_PAUSE,
185
+ (3 / DEFAULT_WPM) * 60 * 1000
186
+ );
187
+
188
+ expect(result).toBe(expectedTime + DEFAULT_DELAY);
189
+ });
190
+
191
+ it("should handle words with punctuation", () => {
192
+ const result = calculateReadingTime("Hello, world! How are you?");
193
+ // Should split on punctuation and count words
194
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
195
+ });
196
+
197
+ it("should handle alphanumeric boundaries", () => {
198
+ const result = calculateReadingTime("test123abc");
199
+ // Should split on alphanumeric boundaries
200
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
201
+ });
202
+
203
+ it("should handle long text", () => {
204
+ const longText = "word ".repeat(200); // 200 words
205
+ const result = calculateReadingTime(longText);
206
+ const expectedTime = (200 / DEFAULT_WPM) * 60 * 1000 + DEFAULT_DELAY;
207
+ expect(result).toBeCloseTo(expectedTime, -1); // Within 10ms
208
+ });
209
+ });
210
+
211
+ describe("Minimum Pause", () => {
212
+ it("should return minimum pause + delay for very short text", () => {
213
+ const result = calculateReadingTime("Hi");
214
+ // 1 word, calculation would be less than minimum pause
215
+ expect(result).toBe(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
216
+ });
217
+
218
+ it("should respect custom minimum pause", () => {
219
+ const customMinPause = 1000;
220
+ const result = calculateReadingTime("Hi", DEFAULT_WPM, customMinPause);
221
+ expect(result).toBeGreaterThanOrEqual(customMinPause);
222
+ });
223
+
224
+ it("should exceed minimum pause for longer text", () => {
225
+ const longText = "word ".repeat(50); // 50 words
226
+ const result = calculateReadingTime(longText);
227
+ const calculatedTime = (50 / DEFAULT_WPM) * 60 * 1000;
228
+ expect(result).toBe(calculatedTime + DEFAULT_DELAY);
229
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
230
+ });
231
+ });
232
+
233
+ describe("Custom Parameters", () => {
234
+ it("should respect custom words per minute", () => {
235
+ const text = "word ".repeat(140); // 140 words
236
+ const fastReading = calculateReadingTime(text, 280); // 2x speed
237
+ const normalReading = calculateReadingTime(text, 140); // normal speed
238
+
239
+ // Faster reading should take less time
240
+ expect(fastReading).toBeLessThan(normalReading);
241
+ });
242
+
243
+ it("should respect custom announcement delay", () => {
244
+ const text = "Hello world";
245
+
246
+ const shortDelay = calculateReadingTime(
247
+ text,
248
+ DEFAULT_WPM,
249
+ DEFAULT_MIN_PAUSE,
250
+ 100
251
+ );
252
+
253
+ const longDelay = calculateReadingTime(
254
+ text,
255
+ DEFAULT_WPM,
256
+ DEFAULT_MIN_PAUSE,
257
+ 1000
258
+ );
259
+
260
+ expect(longDelay - shortDelay).toBe(900);
261
+ });
262
+
263
+ it("should work with all custom parameters", () => {
264
+ const result = calculateReadingTime("test", 200, 1000, 500);
265
+ expect(result).toBeGreaterThanOrEqual(1500); // minimum pause + delay
266
+ });
267
+ });
268
+
269
+ describe("Real-world Use Cases", () => {
270
+ it("should handle accessibility announcement text", () => {
271
+ const announcement = "New message from John Doe";
272
+ const result = calculateReadingTime(announcement);
273
+ expect(result).toBeGreaterThan(0);
274
+ expect(result).toBeLessThan(10000); // Less than 10 seconds
275
+ });
276
+
277
+ it("should handle button labels", () => {
278
+ const label = "Submit";
279
+ const result = calculateReadingTime(label);
280
+ expect(result).toBe(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
281
+ });
282
+
283
+ it("should handle form error messages", () => {
284
+ const error = "Please enter a valid email address";
285
+ const result = calculateReadingTime(error);
286
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE);
287
+ });
288
+
289
+ it("should handle article titles", () => {
290
+ const title = "Breaking News: Major Update Released";
291
+ const result = calculateReadingTime(title);
292
+ expect(result).toBeGreaterThan(DEFAULT_MIN_PAUSE + DEFAULT_DELAY);
293
+ });
294
+
295
+ it("should handle notification text", () => {
296
+ const notification = "You have 3 new messages";
297
+ const result = calculateReadingTime(notification);
298
+ expect(result).toBeGreaterThan(0);
299
+ });
300
+ });
301
+
302
+ describe("Edge Cases", () => {
303
+ it("should handle text with special characters", () => {
304
+ const result = calculateReadingTime("@#$%^&*()");
305
+ expect(result).toBeGreaterThanOrEqual(0);
306
+ });
307
+
308
+ it("should handle text with emojis", () => {
309
+ const result = calculateReadingTime("Hello 👋 World 🌍");
310
+ expect(result).toBeGreaterThan(0);
311
+ });
312
+
313
+ it("should handle text with newlines", () => {
314
+ const result = calculateReadingTime("Line 1\nLine 2\nLine 3");
315
+ expect(result).toBeGreaterThan(0);
316
+ });
317
+
318
+ it("should handle mixed alphanumeric text", () => {
319
+ const result = calculateReadingTime(
320
+ "Version 1.2.3 released on 2024-01-01"
321
+ );
322
+
323
+ expect(result).toBeGreaterThan(0);
324
+ });
325
+
326
+ it("should handle very large numbers", () => {
327
+ const result = calculateReadingTime(Number.MAX_SAFE_INTEGER);
328
+ expect(result).toBeGreaterThan(0);
329
+ });
330
+
331
+ it("should return consistent results for same input", () => {
332
+ const text = "Consistent test";
333
+ const result1 = calculateReadingTime(text);
334
+ const result2 = calculateReadingTime(text);
335
+ const result3 = calculateReadingTime(text);
336
+
337
+ expect(result1).toBe(result2);
338
+ expect(result2).toBe(result3);
339
+ });
340
+ });
341
+
342
+ describe("Performance Characteristics", () => {
343
+ it("should handle empty input efficiently", () => {
344
+ const start = Date.now();
345
+ calculateReadingTime("");
346
+ const duration = Date.now() - start;
347
+
348
+ expect(duration).toBeLessThan(10); // Should be nearly instant
349
+ });
350
+
351
+ it("should handle large text efficiently", () => {
352
+ const largeText = "word ".repeat(10000);
353
+ const start = Date.now();
354
+ calculateReadingTime(largeText);
355
+ const duration = Date.now() - start;
356
+
357
+ expect(duration).toBeLessThan(100); // Should complete in less than 100ms
358
+ });
359
+ });
360
+ });
@@ -31,6 +31,10 @@ export const BUTTON_ACCESSIBILITY_KEYS = {
31
31
  hint: "accessibility_close_mini_hint",
32
32
  },
33
33
  },
34
+ back_to_live: {
35
+ label: "back_to_live_label",
36
+ hint: "",
37
+ },
34
38
  maximize: {
35
39
  label: "accessibility_maximize_label",
36
40
  hint: "accessibility_maximize_hint",
@@ -23,19 +23,6 @@ export const useAccessibilityManager = (
23
23
  }
24
24
  }, [pluginConfiguration, accessibilityManager]);
25
25
 
26
- useEffect(() => {
27
- const subscription = accessibilityManager.getStateAsObservable().subscribe({
28
- next: () => {
29
- // TODO: handle accessibility states
30
- // screenReaderEnabled: false
31
- // reduceMotionEnabled: false
32
- // boldTextEnabled: false
33
- },
34
- });
35
-
36
- return () => subscription.unsubscribe();
37
- }, [accessibilityManager]);
38
-
39
26
  return accessibilityManager;
40
27
  };
41
28
 
@@ -72,3 +59,23 @@ export const useAnnouncementActive = (
72
59
 
73
60
  return isActive;
74
61
  };
62
+
63
+ export const useAccessibilityState = (
64
+ pluginConfiguration: Record<string, any> = {}
65
+ ) => {
66
+ const accessibilityManager = useAccessibilityManager(pluginConfiguration);
67
+
68
+ const [state, setState] = useState<AccessibilityState>(
69
+ accessibilityManager.getState()
70
+ );
71
+
72
+ useEffect(() => {
73
+ const subscription = accessibilityManager
74
+ .getStateAsObservable()
75
+ .subscribe(setState);
76
+
77
+ return () => subscription.unsubscribe();
78
+ }, [accessibilityManager]);
79
+
80
+ return state;
81
+ };
@@ -36,7 +36,20 @@ export class AccessibilityManager {
36
36
  false
37
37
  );
38
38
 
39
- private constructor() {}
39
+ private constructor() {
40
+ this.ttsManager
41
+ .getScreenReaderEnabledAsObservable()
42
+ .subscribe((enabled) => {
43
+ const state = this.state$.getValue();
44
+
45
+ if (state.screenReaderEnabled !== enabled) {
46
+ this.state$.next({
47
+ ...state,
48
+ screenReaderEnabled: enabled,
49
+ });
50
+ }
51
+ });
52
+ }
40
53
 
41
54
  public static getInstance(): AccessibilityManager {
42
55
  if (!AccessibilityManager._instance) {
@@ -92,8 +105,15 @@ export class AccessibilityManager {
92
105
  /**
93
106
  * Adds a heading to the queue, headings will be read before the next text
94
107
  * Each heading will be read once and removed from the queue
108
+ * Does nothing if screen reader is not enabled
95
109
  */
96
110
  public addHeading(heading: string) {
111
+ const state = this.state$.getValue();
112
+
113
+ if (!state.screenReaderEnabled) {
114
+ return;
115
+ }
116
+
97
117
  if (!this.pendingFocusId) {
98
118
  this.pendingFocusId = Date.now().toString();
99
119
  }
@@ -108,6 +128,7 @@ export class AccessibilityManager {
108
128
  *
109
129
  * Implements a delay mechanism to reduce noise during rapid navigation.
110
130
  * Only the most recent announcement will be read after the delay period.
131
+ * Does nothing if screen reader is not enabled
111
132
  */
112
133
  public readText({
113
134
  text,
@@ -116,6 +137,12 @@ export class AccessibilityManager {
116
137
  text: string;
117
138
  keyOfLocalizedText?: string;
118
139
  }) {
140
+ const state = this.state$.getValue();
141
+
142
+ if (!state.screenReaderEnabled) {
143
+ return;
144
+ }
145
+
119
146
  let textToRead = text;
120
147
 
121
148
  if (keyOfLocalizedText) {
@@ -1,24 +1,75 @@
1
+ import { createLogger } from "../../logger";
2
+
3
+ const { log_error } = createLogger({
4
+ category: "AccessibilityManager",
5
+ subsystem: "AppUtils",
6
+ });
7
+
1
8
  /**
2
9
  * Calculates the reading time for a given text based on word count
3
- * @param text - The text to calculate the reading time for
4
- * @param wordsPerMinute - Words per minute reading speed (default: 160)
10
+ * @param text - The text to calculate the reading time for (string or number)
11
+ * @param wordsPerMinute - Words per minute reading speed (default: 140)
5
12
  * @param minimumPause - Minimum pause time in milliseconds (default: 500)
6
13
  * @param announcementDelay - Additional delay for announcement in milliseconds (default: 700)
7
14
  * @returns The reading time in milliseconds
8
15
  */
9
16
  export function calculateReadingTime(
10
- text: string,
17
+ text: string | number,
11
18
  wordsPerMinute: number = 140,
12
19
  minimumPause: number = 500,
13
20
  announcementDelay: number = 700
14
21
  ): number {
15
- const words = text
16
- .trim()
22
+ if (typeof text !== "string" && typeof text !== "number") {
23
+ log_error(
24
+ `Invalid text input for reading time calculation got: ${
25
+ typeof text === "symbol" ? String(text) : text
26
+ }`
27
+ );
28
+
29
+ return 0;
30
+ }
31
+
32
+ const trimmed = typeof text === "number" ? String(text) : text.trim();
33
+
34
+ if (!trimmed) {
35
+ return 0;
36
+ }
37
+
38
+ const words = trimmed
17
39
  .split(/(?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)|[^\w\s]+|\s+/)
18
40
  .filter(Boolean).length;
19
41
 
20
- return (
21
- Math.max(minimumPause, (words / wordsPerMinute) * 60 * 1000) +
22
- announcementDelay
42
+ // Count spaces - multiple consecutive spaces add extra pause time
43
+ const spaceMatches: string[] = trimmed.match(/\s+/g) || [];
44
+
45
+ const totalSpaces = spaceMatches.reduce(
46
+ (sum: number, match: string) => sum + match.length,
47
+ 0
23
48
  );
49
+
50
+ const extraSpaces = Math.max(0, totalSpaces - (words - 1)); // words-1 is normal spacing
51
+
52
+ // Heuristic: punctuation increases TTS duration beyond word-based WPM.
53
+ // Commas typically introduce short pauses, sentence terminators longer ones.
54
+ const commaCount = (trimmed.match(/,/g) || []).length;
55
+ const semicolonCount = (trimmed.match(/;/g) || []).length;
56
+ const colonCount = (trimmed.match(/:/g) || []).length;
57
+ const dashCount = (trimmed.match(/\u2013|\u2014|-/g) || []).length; // – — -
58
+ const sentenceEndCount = (trimmed.match(/[.!?](?!\d)/g) || []).length;
59
+
60
+ const commaPauseMs = 220; // short prosody pause for ","
61
+ const midPauseMs = 260; // for ";", ":", dashes
62
+ const sentenceEndPauseMs = 420; // for ".", "!", "?"
63
+ const extraSpacePauseMs = 50; // per extra space beyond normal spacing
64
+
65
+ const punctuationPause =
66
+ commaCount * commaPauseMs +
67
+ (semicolonCount + colonCount + dashCount) * midPauseMs +
68
+ sentenceEndCount * sentenceEndPauseMs +
69
+ extraSpaces * extraSpacePauseMs;
70
+
71
+ const baseByWordsMs = (words / wordsPerMinute) * 60 * 1000;
72
+ const estimatedMs = Math.max(minimumPause, baseByWordsMs + punctuationPause);
73
+
74
+ return estimatedMs + announcementDelay;
24
75
  }
@@ -1,7 +1,12 @@
1
+ import { NativeModules } from "react-native";
1
2
  import { ContextKeysManager } from "../..";
2
3
 
3
4
  describe("Context Keys Manager - getKeys", () => {
4
- it("returns null if all keys are invalid", async () => {
5
+ beforeEach(() => {
6
+ delete NativeModules.ContextResolverBridge;
7
+ });
8
+
9
+ it("returns null if all keys are invalid 1", async () => {
5
10
  // setup
6
11
  const keys = [null];
7
12
 
@@ -24,7 +29,7 @@ describe("Context Keys Manager - getKeys", () => {
24
29
  expect(getKey.mock.calls).toEqual([[null]]);
25
30
  });
26
31
 
27
- it("returns null if all keys are invalid", async () => {
32
+ it("returns null if all keys are invalid 2", async () => {
28
33
  // setup
29
34
  const keys = [null, undefined];
30
35
 
@@ -1,6 +1,11 @@
1
+ import { NativeModules } from "react-native";
1
2
  import { ContextKeysManager } from "../..";
2
3
 
3
4
  describe("Context Keys Manager - getKeys", () => {
5
+ beforeEach(() => {
6
+ delete NativeModules.ContextResolverBridge;
7
+ });
8
+
4
9
  it("returns value if found by getKey", async () => {
5
10
  // setup
6
11
  const keys = ["namespace.key"];
@@ -165,4 +170,47 @@ describe("Context Keys Manager - getKeys", () => {
165
170
  expect(getKey).toHaveBeenCalledTimes(2);
166
171
  expect(getKey.mock.calls).toEqual([[keys[0]], [keys[1]]]);
167
172
  });
173
+
174
+ it("returns values from native bridge when available", async () => {
175
+ // setup
176
+ const keys = ["namespace.key1", "namespace.key2"];
177
+
178
+ const contextObj = [
179
+ { key: keys[0], required: true },
180
+ { key: keys[1], required: false },
181
+ ];
182
+
183
+ const resolved = {
184
+ [keys[0]]: "value1",
185
+ [keys[1]]: "value2",
186
+ };
187
+
188
+ const reactNative = require("react-native");
189
+
190
+ const bridgeMock = {
191
+ resolveContextKeys: jest.fn().mockResolvedValue(resolved),
192
+ };
193
+
194
+ reactNative.__setContextResolverBridgeMock(bridgeMock);
195
+
196
+ const contextManager = new ContextKeysManager({});
197
+ const getKey = jest.spyOn(contextManager, "getKey");
198
+
199
+ // run
200
+ const result = await contextManager.getKeys(keys, contextObj);
201
+
202
+ // verify
203
+ const map = new Map();
204
+ map.set(keys[0], "value1");
205
+ map.set(keys[1], "value2");
206
+
207
+ expect(result).toEqual(map);
208
+
209
+ expect(bridgeMock.resolveContextKeys).toHaveBeenCalledWith({
210
+ [keys[0]]: true,
211
+ [keys[1]]: false,
212
+ });
213
+
214
+ expect(getKey).not.toHaveBeenCalled();
215
+ });
168
216
  });