@applicaster/zapp-react-native-utils 15.0.0-alpha.6835718972 → 15.0.0-alpha.7413430163

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.
@@ -12,13 +12,44 @@ export function calculateReadingTime(
12
12
  minimumPause: number = 500,
13
13
  announcementDelay: number = 700
14
14
  ): number {
15
- const words = text
16
- .trim()
15
+ const trimmed = text.trim();
16
+
17
+ // Count words (split on whitespace and punctuation, keep alnum boundaries)
18
+ const words = trimmed
17
19
  .split(/(?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)|[^\w\s]+|\s+/)
18
20
  .filter(Boolean).length;
19
21
 
20
- return (
21
- Math.max(minimumPause, (words / wordsPerMinute) * 60 * 1000) +
22
- announcementDelay
22
+ // Count spaces - multiple consecutive spaces add extra pause time
23
+ const spaceMatches: string[] = trimmed.match(/\s+/g) || [];
24
+
25
+ const totalSpaces = spaceMatches.reduce(
26
+ (sum: number, match: string) => sum + match.length,
27
+ 0
23
28
  );
29
+
30
+ const extraSpaces = Math.max(0, totalSpaces - (words - 1)); // words-1 is normal spacing
31
+
32
+ // Heuristic: punctuation increases TTS duration beyond word-based WPM.
33
+ // Commas typically introduce short pauses, sentence terminators longer ones.
34
+ const commaCount = (trimmed.match(/,/g) || []).length;
35
+ const semicolonCount = (trimmed.match(/;/g) || []).length;
36
+ const colonCount = (trimmed.match(/:/g) || []).length;
37
+ const dashCount = (trimmed.match(/\u2013|\u2014|-/g) || []).length; // – — -
38
+ const sentenceEndCount = (trimmed.match(/[.!?](?!\d)/g) || []).length;
39
+
40
+ const commaPauseMs = 220; // short prosody pause for ","
41
+ const midPauseMs = 260; // for ";", ":", dashes
42
+ const sentenceEndPauseMs = 420; // for ".", "!", "?"
43
+ const extraSpacePauseMs = 50; // per extra space beyond normal spacing
44
+
45
+ const punctuationPause =
46
+ commaCount * commaPauseMs +
47
+ (semicolonCount + colonCount + dashCount) * midPauseMs +
48
+ sentenceEndCount * sentenceEndPauseMs +
49
+ extraSpaces * extraSpacePauseMs;
50
+
51
+ const baseByWordsMs = (words / wordsPerMinute) * 60 * 1000;
52
+ const estimatedMs = Math.max(minimumPause, baseByWordsMs + punctuationPause);
53
+
54
+ return estimatedMs + announcementDelay;
24
55
  }
@@ -9,7 +9,10 @@ import {
9
9
  } from "@applicaster/zapp-react-native-utils/stringUtils";
10
10
  import { cellUtilsLogger } from "@applicaster/zapp-react-native-utils/cellUtils/logger";
11
11
  import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
12
- import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
12
+ import {
13
+ isNotNil,
14
+ isNilOrEmpty,
15
+ } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
13
16
 
14
17
  import { toNumberWithDefault, toNumberWithDefaultZero } from "../numberUtils";
15
18
 
@@ -505,3 +508,39 @@ export const getImageContainerMarginStyles = ({ value }: { value: any }) => {
505
508
  marginRight: value("image_margin_right"),
506
509
  };
507
510
  };
511
+
512
+ export const withoutNilOrEmpty = (arr: string[]): string[] =>
513
+ arr.filter((item) => !isNilOrEmpty(item));
514
+
515
+ export const isTextLabel = (key: string): boolean =>
516
+ key.includes("text_label_") && key.endsWith("_switch");
517
+
518
+ export const hasTextLabelsEnabled = (
519
+ configuration: Record<string, any>
520
+ ): boolean => {
521
+ const textLabelsKeys = Object.keys(configuration).filter(isTextLabel);
522
+
523
+ const picked = textLabelsKeys.reduce(
524
+ (acc, key) => {
525
+ acc[key] = configuration[key];
526
+
527
+ return acc;
528
+ },
529
+ {} as Record<string, any>
530
+ );
531
+
532
+ const pickedValues = Object.values(picked);
533
+
534
+ // Check if any switch value is truthy (true, "true", "1", etc.)
535
+ return pickedValues.some((value) => {
536
+ if (typeof value === "boolean") {
537
+ return value === true;
538
+ }
539
+
540
+ if (typeof value === "string") {
541
+ return value !== "" && value.toLowerCase() !== "false";
542
+ }
543
+
544
+ return Boolean(value);
545
+ });
546
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "15.0.0-alpha.6835718972",
3
+ "version": "15.0.0-alpha.7413430163",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "15.0.0-alpha.6835718972",
30
+ "@applicaster/applicaster-types": "15.0.0-alpha.7413430163",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",