@applicaster/zapp-react-native-utils 15.0.0-alpha.7591121530 → 15.0.0-alpha.8621453569
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/appUtils/accessibilityManager/hooks.ts +23 -0
- package/appUtils/accessibilityManager/index.ts +28 -1
- package/appUtils/accessibilityManager/utils.ts +36 -5
- package/appUtils/platform/platformUtils.ts +104 -21
- package/cellUtils/index.ts +40 -1
- package/manifestUtils/keys.js +0 -21
- package/package.json +2 -2
|
@@ -72,3 +72,26 @@ export const useAnnouncementActive = (
|
|
|
72
72
|
|
|
73
73
|
return isActive;
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Hook to get the current screen reader enabled state
|
|
78
|
+
* Returns a boolean that updates reactively when screen reader is enabled/disabled
|
|
79
|
+
* @returns boolean - true if screen reader is enabled, false otherwise
|
|
80
|
+
*/
|
|
81
|
+
export const useScreenReaderEnabled = (
|
|
82
|
+
accessibilityManager: AccessibilityManager
|
|
83
|
+
) => {
|
|
84
|
+
const [isEnabled, setIsEnabled] = useState(
|
|
85
|
+
accessibilityManager.getState().screenReaderEnabled
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const subscription = accessibilityManager
|
|
90
|
+
.getStateAsObservable()
|
|
91
|
+
.subscribe((state) => setIsEnabled(state.screenReaderEnabled));
|
|
92
|
+
|
|
93
|
+
return () => subscription.unsubscribe();
|
|
94
|
+
}, [accessibilityManager]);
|
|
95
|
+
|
|
96
|
+
return isEnabled;
|
|
97
|
+
};
|
|
@@ -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) {
|
|
@@ -12,13 +12,44 @@ export function calculateReadingTime(
|
|
|
12
12
|
minimumPause: number = 500,
|
|
13
13
|
announcementDelay: number = 700
|
|
14
14
|
): number {
|
|
15
|
-
const
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
}
|
|
@@ -170,7 +170,9 @@ export const getClosedCaptionState = () => {
|
|
|
170
170
|
*/
|
|
171
171
|
export class TTSManager {
|
|
172
172
|
private ttsState$ = new BehaviorSubject<boolean>(false);
|
|
173
|
+
private screenReaderEnabled$ = new BehaviorSubject<boolean>(false);
|
|
173
174
|
private static ttsManagerInstance: TTSManager;
|
|
175
|
+
private samsungListenerId: number | null = null;
|
|
174
176
|
|
|
175
177
|
private constructor() {
|
|
176
178
|
this.initialize();
|
|
@@ -185,23 +187,83 @@ export class TTSManager {
|
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
async initialize() {
|
|
188
|
-
if (
|
|
190
|
+
if (isVizioPlatform()) {
|
|
191
|
+
document.addEventListener(
|
|
192
|
+
"VIZIO_TTS_ENABLED",
|
|
193
|
+
() => {
|
|
194
|
+
log_debug("Vizio screen reader enabled");
|
|
195
|
+
this.screenReaderEnabled$.next(true);
|
|
196
|
+
},
|
|
197
|
+
false
|
|
198
|
+
);
|
|
189
199
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
200
|
+
document.addEventListener(
|
|
201
|
+
"VIZIO_TTS_DISABLED",
|
|
202
|
+
() => {
|
|
203
|
+
log_debug("Vizio screen reader disabled");
|
|
204
|
+
this.screenReaderEnabled$.next(false);
|
|
205
|
+
},
|
|
206
|
+
false
|
|
207
|
+
);
|
|
208
|
+
}
|
|
197
209
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
210
|
+
if (isLgPlatform() && window.webOS?.service) {
|
|
211
|
+
try {
|
|
212
|
+
window.webOS.service.request("luna://com.webos.settingsservice", {
|
|
213
|
+
method: "getSystemSettings",
|
|
214
|
+
parameters: {
|
|
215
|
+
category: "accessibility",
|
|
216
|
+
keys: ["audioGuidance"],
|
|
217
|
+
subscribe: true, // Request a subscription to changes
|
|
218
|
+
},
|
|
219
|
+
onSuccess: (response: any) => {
|
|
220
|
+
const isEnabled = response?.settings?.audioGuidance === "on";
|
|
221
|
+
|
|
222
|
+
log_debug("LG Audio Guidance status changed", {
|
|
223
|
+
isEnabled,
|
|
224
|
+
response,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
this.screenReaderEnabled$.next(isEnabled);
|
|
228
|
+
},
|
|
229
|
+
onFailure: (error: any) => {
|
|
230
|
+
log_debug("webOS settings subscription failed", { error });
|
|
231
|
+
this.screenReaderEnabled$.next(false);
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
} catch (error) {
|
|
235
|
+
log_debug("webOS settings service request error", { error });
|
|
236
|
+
this.screenReaderEnabled$.next(false);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (isSamsungPlatform() && typeof window.tizen !== "undefined") {
|
|
241
|
+
try {
|
|
242
|
+
if (
|
|
243
|
+
window.tizen.accessibility &&
|
|
244
|
+
typeof window.tizen.accessibility
|
|
245
|
+
.addVoiceGuideStatusChangeListener === "function"
|
|
246
|
+
) {
|
|
247
|
+
this.samsungListenerId =
|
|
248
|
+
window.tizen.accessibility.addVoiceGuideStatusChangeListener(
|
|
249
|
+
(enabled: boolean) => {
|
|
250
|
+
log_debug("Samsung Voice Guide status changed", { enabled });
|
|
251
|
+
this.screenReaderEnabled$.next(!!enabled);
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
log_debug("Samsung Voice Guide listener registered", {
|
|
256
|
+
listenerId: this.samsungListenerId,
|
|
257
|
+
});
|
|
258
|
+
} else {
|
|
259
|
+
log_debug("Samsung accessibility API not available");
|
|
260
|
+
this.screenReaderEnabled$.next(false);
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
log_debug("Samsung Voice Guide listener error", { error });
|
|
264
|
+
this.screenReaderEnabled$.next(false);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
205
267
|
}
|
|
206
268
|
|
|
207
269
|
getCurrentState(): boolean {
|
|
@@ -212,17 +274,38 @@ export class TTSManager {
|
|
|
212
274
|
return this.ttsState$.asObservable();
|
|
213
275
|
}
|
|
214
276
|
|
|
277
|
+
getScreenReaderEnabledAsObservable() {
|
|
278
|
+
return this.screenReaderEnabled$.asObservable();
|
|
279
|
+
}
|
|
280
|
+
|
|
215
281
|
readText(text: string) {
|
|
216
282
|
this.ttsState$.next(true);
|
|
217
283
|
|
|
218
|
-
if (
|
|
219
|
-
|
|
284
|
+
if (
|
|
285
|
+
isSamsungPlatform() &&
|
|
286
|
+
typeof window.tizen !== "undefined" &&
|
|
287
|
+
window.tizen.speech
|
|
288
|
+
) {
|
|
289
|
+
try {
|
|
290
|
+
const successCallback = () => {
|
|
291
|
+
log_debug("Samsung TTS play started successfully");
|
|
292
|
+
// Estimate reading time and set inactive when done
|
|
293
|
+
this.scheduleTTSComplete(text);
|
|
294
|
+
};
|
|
220
295
|
|
|
221
|
-
|
|
222
|
-
|
|
296
|
+
const errorCallback = (error: any) => {
|
|
297
|
+
log_debug("Samsung TTS error", { error: error?.message || error });
|
|
298
|
+
this.ttsState$.next(false);
|
|
299
|
+
};
|
|
223
300
|
|
|
224
|
-
|
|
225
|
-
|
|
301
|
+
// Clear any previous speech before speaking new text
|
|
302
|
+
window.tizen.speech.stop();
|
|
303
|
+
|
|
304
|
+
window.tizen.speech.speak(text, successCallback, errorCallback);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
log_debug("Samsung TTS speak() error", { error });
|
|
307
|
+
this.ttsState$.next(false);
|
|
308
|
+
}
|
|
226
309
|
}
|
|
227
310
|
|
|
228
311
|
if (isLgPlatform() && window.webOS?.service) {
|
package/cellUtils/index.ts
CHANGED
|
@@ -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 {
|
|
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/manifestUtils/keys.js
CHANGED
|
@@ -959,27 +959,6 @@ const TV_CELL_LABEL_FIELDS = [
|
|
|
959
959
|
rules: "conditional",
|
|
960
960
|
conditions: [{ key: "switch", section: "styles", value: true }],
|
|
961
961
|
},
|
|
962
|
-
{
|
|
963
|
-
type: ZAPPIFEST_FIELDS.font_selector.roku,
|
|
964
|
-
suffix: "roku font family",
|
|
965
|
-
tooltip: "",
|
|
966
|
-
rules: "conditional",
|
|
967
|
-
conditions: [{ key: "switch", section: "styles", value: true }],
|
|
968
|
-
},
|
|
969
|
-
{
|
|
970
|
-
type: ZAPPIFEST_FIELDS.number_input,
|
|
971
|
-
suffix: "roku font size",
|
|
972
|
-
tooltip: "",
|
|
973
|
-
rules: "conditional",
|
|
974
|
-
conditions: [{ key: "switch", section: "styles", value: true }],
|
|
975
|
-
},
|
|
976
|
-
{
|
|
977
|
-
type: ZAPPIFEST_FIELDS.number_input,
|
|
978
|
-
suffix: "roku line height",
|
|
979
|
-
tooltip: "",
|
|
980
|
-
rules: "conditional",
|
|
981
|
-
conditions: [{ key: "switch", section: "styles", value: true }],
|
|
982
|
-
},
|
|
983
962
|
{
|
|
984
963
|
type: ZAPPIFEST_FIELDS.select,
|
|
985
964
|
suffix: "text alignment",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "15.0.0-alpha.
|
|
3
|
+
"version": "15.0.0-alpha.8621453569",
|
|
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.
|
|
30
|
+
"@applicaster/applicaster-types": "15.0.0-alpha.8621453569",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|