@intellectif/lk-react 13.0.0 → 14.1.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 +61 -0
- package/README.md +11 -3
- package/dist/{WrittenResponse-B5p_-RnJ.d.ts → WrittenResponse-DrzI89Wg.d.ts} +1 -1
- package/dist/{WrittenResponse-DWtS4tOL.d.cts → WrittenResponse-rRpOr9W1.d.cts} +1 -1
- package/dist/{chunk-UU2NV6SU.cjs → chunk-4Y5TELVU.cjs} +14 -13
- package/dist/chunk-4Y5TELVU.cjs.map +1 -0
- package/dist/{chunk-XAGWBVK3.js → chunk-5CP2Z6IS.js} +6 -5
- package/dist/chunk-5CP2Z6IS.js.map +1 -0
- package/dist/{chunk-NVUFEMPZ.cjs → chunk-5JCTJFQU.cjs} +30 -16
- package/dist/chunk-5JCTJFQU.cjs.map +1 -0
- package/dist/chunk-5JFMXBH7.js +888 -0
- package/dist/chunk-5JFMXBH7.js.map +1 -0
- package/dist/{chunk-NVP6UEQQ.js → chunk-AS2QGND5.js} +4 -4
- package/dist/{chunk-NVP6UEQQ.js.map → chunk-AS2QGND5.js.map} +1 -1
- package/dist/{chunk-3Q4I4KT6.js → chunk-AWQ53DON.js} +78 -2
- package/dist/chunk-AWQ53DON.js.map +1 -0
- package/dist/{chunk-DQERNAWI.js → chunk-B4BCEQNO.js} +26 -31
- package/dist/chunk-B4BCEQNO.js.map +1 -0
- package/dist/chunk-BRPEB43C.cjs +13 -0
- package/dist/chunk-BRPEB43C.cjs.map +1 -0
- package/dist/{chunk-74QXBWCI.cjs → chunk-CTW3G3EH.cjs} +6 -6
- package/dist/{chunk-74QXBWCI.cjs.map → chunk-CTW3G3EH.cjs.map} +1 -1
- package/dist/{chunk-AMGK7DDM.cjs → chunk-D4DQFTA7.cjs} +2 -2
- package/dist/chunk-D4DQFTA7.cjs.map +1 -0
- package/dist/{chunk-R7DI5UMU.js → chunk-DB4DLHN6.js} +22 -4
- package/dist/chunk-DB4DLHN6.js.map +1 -0
- package/dist/{chunk-K3EA547J.cjs → chunk-DPEY7DSE.cjs} +27 -33
- package/dist/chunk-DPEY7DSE.cjs.map +1 -0
- package/dist/{chunk-W4MXRZAB.js → chunk-IDYZ2FA2.js} +6 -5
- package/dist/chunk-IDYZ2FA2.js.map +1 -0
- package/dist/{chunk-K7NMNOPI.cjs → chunk-JG4DWAUJ.cjs} +15 -14
- package/dist/chunk-JG4DWAUJ.cjs.map +1 -0
- package/dist/chunk-KIO6QXGT.cjs +894 -0
- package/dist/chunk-KIO6QXGT.cjs.map +1 -0
- package/dist/chunk-MCO52PV5.js +520 -0
- package/dist/chunk-MCO52PV5.js.map +1 -0
- package/dist/{chunk-HT4FFZZQ.cjs → chunk-MZITNWZ2.cjs} +233 -38
- package/dist/chunk-MZITNWZ2.cjs.map +1 -0
- package/dist/{chunk-Z63JRG4M.cjs → chunk-N536RUCZ.cjs} +15 -14
- package/dist/chunk-N536RUCZ.cjs.map +1 -0
- package/dist/{chunk-PSHNTDKG.js → chunk-NJAF34GN.js} +13 -161
- package/dist/chunk-NJAF34GN.js.map +1 -0
- package/dist/chunk-OD65OZIW.cjs +159 -0
- package/dist/chunk-OD65OZIW.cjs.map +1 -0
- package/dist/{chunk-2GXSA322.cjs → chunk-PSUKWVKU.cjs} +15 -14
- package/dist/chunk-PSUKWVKU.cjs.map +1 -0
- package/dist/chunk-RCMYEWBE.js +11 -0
- package/dist/chunk-RCMYEWBE.js.map +1 -0
- package/dist/{chunk-PY53ABWC.js → chunk-RCPW6HVY.js} +23 -9
- package/dist/chunk-RCPW6HVY.js.map +1 -0
- package/dist/{chunk-DQNVAXG6.js → chunk-RXS455MR.js} +2 -2
- package/dist/chunk-RXS455MR.js.map +1 -0
- package/dist/chunk-TUVEJLOT.js +537 -0
- package/dist/chunk-TUVEJLOT.js.map +1 -0
- package/dist/{chunk-YZWXVZB3.js → chunk-U432HTUW.js} +6 -5
- package/dist/chunk-U432HTUW.js.map +1 -0
- package/dist/chunk-UDCQTOVU.cjs +523 -0
- package/dist/chunk-UDCQTOVU.cjs.map +1 -0
- package/dist/{chunk-5N7OLFHB.js → chunk-UDQS5INQ.js} +6 -5
- package/dist/chunk-UDQS5INQ.js.map +1 -0
- package/dist/{chunk-YILH4ETT.js → chunk-UDZWYHDV.js} +226 -31
- package/dist/chunk-UDZWYHDV.js.map +1 -0
- package/dist/{chunk-SBIJJ374.cjs → chunk-UMDWVMB5.cjs} +24 -6
- package/dist/chunk-UMDWVMB5.cjs.map +1 -0
- package/dist/{chunk-MA7GXUWC.cjs → chunk-VSFHJ7FB.cjs} +78 -2
- package/dist/chunk-VSFHJ7FB.cjs.map +1 -0
- package/dist/{chunk-J73TDY7J.cjs → chunk-WC4OD3EE.cjs} +25 -173
- package/dist/chunk-WC4OD3EE.cjs.map +1 -0
- package/dist/chunk-YM64MS4G.cjs +547 -0
- package/dist/chunk-YM64MS4G.cjs.map +1 -0
- package/dist/chunk-YORQQXGO.js +155 -0
- package/dist/chunk-YORQQXGO.js.map +1 -0
- package/dist/components/ActivityPreview.cjs +15 -10
- package/dist/components/ActivityPreview.d.cts +9 -3
- package/dist/components/ActivityPreview.d.ts +9 -3
- package/dist/components/ActivityPreview.js +14 -9
- package/dist/components/ActivitySequence.cjs +16 -11
- package/dist/components/ActivitySequence.d.cts +115 -4
- package/dist/components/ActivitySequence.d.ts +115 -4
- package/dist/components/ActivitySequence.js +15 -10
- package/dist/components/Dictation.cjs +7 -5
- package/dist/components/Dictation.d.cts +2 -1
- package/dist/components/Dictation.d.ts +2 -1
- package/dist/components/Dictation.js +6 -4
- package/dist/components/FillInTheBlanks.cjs +6 -5
- package/dist/components/FillInTheBlanks.d.cts +2 -1
- package/dist/components/FillInTheBlanks.d.ts +2 -1
- package/dist/components/FillInTheBlanks.js +5 -4
- package/dist/components/GapSelect.cjs +6 -5
- package/dist/components/GapSelect.d.cts +2 -1
- package/dist/components/GapSelect.d.ts +2 -1
- package/dist/components/GapSelect.js +5 -4
- package/dist/components/MultipleChoice.cjs +6 -5
- package/dist/components/MultipleChoice.d.cts +2 -1
- package/dist/components/MultipleChoice.d.ts +2 -1
- package/dist/components/MultipleChoice.js +5 -4
- package/dist/components/PronunciationFeedback.cjs +16 -0
- package/dist/components/PronunciationFeedback.cjs.map +1 -0
- package/dist/components/PronunciationFeedback.d.cts +67 -0
- package/dist/components/PronunciationFeedback.d.ts +67 -0
- package/dist/components/PronunciationFeedback.js +7 -0
- package/dist/components/PronunciationFeedback.js.map +1 -0
- package/dist/components/ReadAloud.cjs +21 -0
- package/dist/components/ReadAloud.cjs.map +1 -0
- package/dist/components/ReadAloud.d.cts +15 -0
- package/dist/components/ReadAloud.d.ts +15 -0
- package/dist/components/ReadAloud.js +12 -0
- package/dist/components/ReadAloud.js.map +1 -0
- package/dist/components/StimulusPanel.cjs +4 -4
- package/dist/components/StimulusPanel.d.cts +2 -1
- package/dist/components/StimulusPanel.d.ts +2 -1
- package/dist/components/StimulusPanel.js +3 -3
- package/dist/components/WrittenResponse.cjs +6 -5
- package/dist/components/WrittenResponse.d.cts +4 -3
- package/dist/components/WrittenResponse.d.ts +4 -3
- package/dist/components/WrittenResponse.js +5 -4
- package/dist/hooks/useSpeechRecorder.cjs +17 -0
- package/dist/hooks/useSpeechRecorder.cjs.map +1 -0
- package/dist/hooks/useSpeechRecorder.d.cts +127 -0
- package/dist/hooks/useSpeechRecorder.d.ts +127 -0
- package/dist/hooks/useSpeechRecorder.js +4 -0
- package/dist/hooks/useSpeechRecorder.js.map +1 -0
- package/dist/i18n/LkIntlProvider.cjs +7 -7
- package/dist/i18n/LkIntlProvider.d.cts +3 -2
- package/dist/i18n/LkIntlProvider.d.ts +3 -2
- package/dist/i18n/LkIntlProvider.js +1 -1
- package/dist/index.cjs +53 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/dist/machine-CuwKqWXC.d.cts +26 -0
- package/dist/machine-CuwKqWXC.d.ts +26 -0
- package/dist/{strings-DPTyLpHt.d.cts → strings-l8Wv1Xax.d.ts} +230 -4
- package/dist/{strings-DPTyLpHt.d.ts → strings-wjAF2ONm.d.cts} +230 -4
- package/dist/theme/ThemeProvider.cjs +6 -6
- package/dist/theme/ThemeProvider.d.cts +4 -4
- package/dist/theme/ThemeProvider.d.ts +4 -4
- package/dist/theme/ThemeProvider.js +1 -1
- package/dist/theme/skin.css +612 -3
- package/package.json +33 -3
- package/dist/chunk-2GXSA322.cjs.map +0 -1
- package/dist/chunk-3Q4I4KT6.js.map +0 -1
- package/dist/chunk-5N7OLFHB.js.map +0 -1
- package/dist/chunk-AMGK7DDM.cjs.map +0 -1
- package/dist/chunk-DQERNAWI.js.map +0 -1
- package/dist/chunk-DQNVAXG6.js.map +0 -1
- package/dist/chunk-HT4FFZZQ.cjs.map +0 -1
- package/dist/chunk-J73TDY7J.cjs.map +0 -1
- package/dist/chunk-K3EA547J.cjs.map +0 -1
- package/dist/chunk-K7NMNOPI.cjs.map +0 -1
- package/dist/chunk-MA7GXUWC.cjs.map +0 -1
- package/dist/chunk-NVUFEMPZ.cjs.map +0 -1
- package/dist/chunk-PSHNTDKG.js.map +0 -1
- package/dist/chunk-PY53ABWC.js.map +0 -1
- package/dist/chunk-R7DI5UMU.js.map +0 -1
- package/dist/chunk-SBIJJ374.cjs.map +0 -1
- package/dist/chunk-UU2NV6SU.cjs.map +0 -1
- package/dist/chunk-W4MXRZAB.js.map +0 -1
- package/dist/chunk-XAGWBVK3.js.map +0 -1
- package/dist/chunk-YILH4ETT.js.map +0 -1
- package/dist/chunk-YZWXVZB3.js.map +0 -1
- package/dist/chunk-Z63JRG4M.cjs.map +0 -1
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { usePlaybackRefusal, readOutcome, readEvidence, percentOfGrade, PronunciationFeedback, markSentence, VISUALLY_HIDDEN, readAssessResult, fractionOfGrade } from './chunk-TUVEJLOT.js';
|
|
3
|
+
import { useSpeechRecorder } from './chunk-MCO52PV5.js';
|
|
4
|
+
import { localeDirectionOf } from './chunk-YORQQXGO.js';
|
|
5
|
+
import { FeedbackRegion } from './chunk-RCMYEWBE.js';
|
|
6
|
+
import { ActivityErrorBoundary, isDevelopment, ANONYMOUS_ACTOR, objectIdFor } from './chunk-B4BCEQNO.js';
|
|
7
|
+
import { ActivityMedia } from './chunk-DB4DLHN6.js';
|
|
8
|
+
import { useActivityState } from './chunk-6N43WDVG.js';
|
|
9
|
+
import { useLkStrings } from './chunk-AWQ53DON.js';
|
|
10
|
+
import { assertRedacted, validateActivity, ActivitySchemaError, READ_ALOUD_MAX_SECONDS, READ_ALOUD_MAX_TAKES, xAPIBuilder, xapiDefinitionFor } from '@intellectif/lk-core';
|
|
11
|
+
import { createContext, useContext, useMemo, useState, useId, useRef, useEffect, useCallback } from 'react';
|
|
12
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
// src/components/shared/capture-registry.ts
|
|
15
|
+
var groups = /* @__PURE__ */ new Map();
|
|
16
|
+
function joinCaptureGroup(group, stop) {
|
|
17
|
+
let members = groups.get(group);
|
|
18
|
+
if (members === void 0) {
|
|
19
|
+
members = /* @__PURE__ */ new Set();
|
|
20
|
+
groups.set(group, members);
|
|
21
|
+
}
|
|
22
|
+
members.add(stop);
|
|
23
|
+
return () => {
|
|
24
|
+
const current = groups.get(group);
|
|
25
|
+
if (current === void 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
current.delete(stop);
|
|
29
|
+
if (current.size === 0) {
|
|
30
|
+
groups.delete(group);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function stopCaptureGroup(group) {
|
|
35
|
+
const members = groups.get(group);
|
|
36
|
+
if (members === void 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const stop of [...members]) {
|
|
40
|
+
stop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var SequenceSlotContext = createContext(null);
|
|
44
|
+
var lastTake = 0;
|
|
45
|
+
function mintTake() {
|
|
46
|
+
lastTake += 1;
|
|
47
|
+
return lastTake;
|
|
48
|
+
}
|
|
49
|
+
var takes = /* @__PURE__ */ new WeakMap();
|
|
50
|
+
function stampTake(value, take) {
|
|
51
|
+
takes.set(value, take);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
function takeOf(value) {
|
|
55
|
+
return typeof value === "object" && value !== null ? takes.get(value) : void 0;
|
|
56
|
+
}
|
|
57
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
58
|
+
function readRecordingBounds(recording) {
|
|
59
|
+
const bounds = typeof recording === "object" && recording !== null ? recording : {};
|
|
60
|
+
const maxSeconds = isNumber(bounds.maxSeconds) && bounds.maxSeconds > 0 ? Math.min(bounds.maxSeconds, READ_ALOUD_MAX_SECONDS) : READ_ALOUD_MAX_SECONDS;
|
|
61
|
+
const minSeconds = isNumber(bounds.minSeconds) && bounds.minSeconds >= 0 && bounds.minSeconds < maxSeconds ? bounds.minSeconds : void 0;
|
|
62
|
+
const takes2 = bounds.maxTakes;
|
|
63
|
+
const maxTakes = takes2 === void 0 || takes2 === null ? void 0 : isNumber(takes2) ? Math.min(Math.max(1, Math.floor(takes2)), READ_ALOUD_MAX_TAKES) : READ_ALOUD_MAX_TAKES;
|
|
64
|
+
return { maxSeconds, minSeconds, maxTakes };
|
|
65
|
+
}
|
|
66
|
+
function secondsWithin(milliseconds, maxSeconds, rounding) {
|
|
67
|
+
const seconds = milliseconds / 1e3;
|
|
68
|
+
const whole = rounding === "nearest" ? Math.round(seconds) : Math.floor(seconds);
|
|
69
|
+
return Math.min(Math.max(0, whole), maxSeconds);
|
|
70
|
+
}
|
|
71
|
+
var modelsGroupCount = 0;
|
|
72
|
+
var VISIBLE_TEXT_RE = /[^\p{White_Space}\p{Cc}\p{Cf}\p{Default_Ignorable_Code_Point}]/u;
|
|
73
|
+
var MARK_ID_RE = /^w\d+$/;
|
|
74
|
+
var STORED_STATES = [
|
|
75
|
+
"correct",
|
|
76
|
+
"mispronounced",
|
|
77
|
+
"omitted"
|
|
78
|
+
];
|
|
79
|
+
var LEVEL_STEPS = 10;
|
|
80
|
+
function offersRetry(phase, uploaded) {
|
|
81
|
+
return phase.kind === "upload-failed" || phase.kind === "assess-failed" && phase.retryable && uploaded !== null;
|
|
82
|
+
}
|
|
83
|
+
function takeStateOf(phase, uploaded) {
|
|
84
|
+
if (phase.kind === "uploading" || phase.kind === "assessing") {
|
|
85
|
+
return "in-flight";
|
|
86
|
+
}
|
|
87
|
+
return offersRetry(phase, uploaded) ? "retryable" : "settled";
|
|
88
|
+
}
|
|
89
|
+
function capturing(status) {
|
|
90
|
+
return status === "recording" || status === "requesting-permission";
|
|
91
|
+
}
|
|
92
|
+
function readingKeyOf(data, bounds) {
|
|
93
|
+
const text = (value) => typeof value === "string" ? value : null;
|
|
94
|
+
return JSON.stringify([
|
|
95
|
+
text(data.id),
|
|
96
|
+
text(data.referenceText),
|
|
97
|
+
text(data.locale),
|
|
98
|
+
String(bounds.maxSeconds),
|
|
99
|
+
String(bounds.minSeconds),
|
|
100
|
+
String(bounds.maxTakes)
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
function slowMediaFor(data, label) {
|
|
104
|
+
const slow = data.slowMedia;
|
|
105
|
+
if (slow === void 0) {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
const policy = data.media?.playback ?? {};
|
|
109
|
+
const { maxPlays: _budget, ...inherited } = policy;
|
|
110
|
+
const hasPolicy = Object.values(inherited).some((value) => value !== void 0);
|
|
111
|
+
return {
|
|
112
|
+
type: "audio",
|
|
113
|
+
url: slow.url,
|
|
114
|
+
alt: slow.alt ?? label,
|
|
115
|
+
...hasPolicy ? { playback: inherited } : {}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function marksFromDetails(details) {
|
|
119
|
+
if (details.length === 0 || !details.every((detail) => MARK_ID_RE.test(detail.itemId))) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return details.map((detail) => {
|
|
123
|
+
const heard = Array.isArray(detail.learnerResponse) ? detail.learnerResponse.join(" ") : detail.learnerResponse;
|
|
124
|
+
const reference = Array.isArray(detail.correctResponse) ? detail.correctResponse.join(" ") : detail.correctResponse;
|
|
125
|
+
const correct = detail.outcome !== void 0 ? detail.outcome === "correct" : detail.correct;
|
|
126
|
+
const state = correct ? "correct" : detail.outcome === "incorrect-omission" ? "omitted" : "mispronounced";
|
|
127
|
+
return {
|
|
128
|
+
itemId: detail.itemId,
|
|
129
|
+
reference,
|
|
130
|
+
heard,
|
|
131
|
+
state,
|
|
132
|
+
// `ScoringDetail.score` is the word's accuracy divided by 100; the marks
|
|
133
|
+
// carry it back in the units the assessment used.
|
|
134
|
+
...typeof detail.score === "number" ? { accuracy: detail.score * 100 } : {}
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function recordingOf(response) {
|
|
139
|
+
return response !== void 0 && response.type === "read-aloud" ? response.recording : null;
|
|
140
|
+
}
|
|
141
|
+
function responseOf(recording, takes2) {
|
|
142
|
+
return { type: "read-aloud", recording, ...takes2 > 0 ? { takes: takes2 } : {} };
|
|
143
|
+
}
|
|
144
|
+
function unscorableMessage(code, s) {
|
|
145
|
+
return code === "no_speech" || code === "insufficient_voiced_time" ? s.readAloudNotHeard : s.readAloudNotAssessed;
|
|
146
|
+
}
|
|
147
|
+
function AnnouncementText({ announcement }) {
|
|
148
|
+
if (announcement === null) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
152
|
+
announcement.text,
|
|
153
|
+
announcement.feedback ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
154
|
+
" ",
|
|
155
|
+
/* @__PURE__ */ jsx("span", { dir: "auto", children: announcement.feedback })
|
|
156
|
+
] }) : null
|
|
157
|
+
] });
|
|
158
|
+
}
|
|
159
|
+
function OutcomeSummary({
|
|
160
|
+
reading,
|
|
161
|
+
s,
|
|
162
|
+
scoreShown
|
|
163
|
+
}) {
|
|
164
|
+
switch (reading.kind) {
|
|
165
|
+
case "graded":
|
|
166
|
+
return /* @__PURE__ */ jsx(
|
|
167
|
+
"div",
|
|
168
|
+
{
|
|
169
|
+
className: "lk-ra-outcome",
|
|
170
|
+
"data-status": reading.status,
|
|
171
|
+
"data-passed": String(reading.grade.passed),
|
|
172
|
+
children: scoreShown ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
173
|
+
/* @__PURE__ */ jsx("p", { className: "lk-ra-grade", children: s.scoreAnnouncement(percentOfGrade(reading.grade), reading.grade.passed) }),
|
|
174
|
+
reading.grade.feedback ? /* @__PURE__ */ jsx("p", { className: "lk-ra-grade-feedback", dir: "auto", children: reading.grade.feedback }) : null
|
|
175
|
+
] })
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
case "deferred":
|
|
179
|
+
return /* @__PURE__ */ jsx("div", { className: "lk-ra-outcome", "data-status": "deferred", children: /* @__PURE__ */ jsx("p", { className: "lk-ra-grade", children: s.awaitingGrade }) });
|
|
180
|
+
case "unscorable":
|
|
181
|
+
return /* @__PURE__ */ jsx(
|
|
182
|
+
"div",
|
|
183
|
+
{
|
|
184
|
+
className: "lk-ra-outcome",
|
|
185
|
+
"data-status": "unscorable",
|
|
186
|
+
...reading.code !== void 0 ? { "data-code": reading.code } : {},
|
|
187
|
+
children: /* @__PURE__ */ jsx("p", { className: "lk-ra-grade", children: s.couldNotBeGraded })
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
default:
|
|
191
|
+
return /* @__PURE__ */ jsx(
|
|
192
|
+
"div",
|
|
193
|
+
{
|
|
194
|
+
className: "lk-ra-outcome",
|
|
195
|
+
...reading.status !== void 0 ? { "data-status": reading.status } : {},
|
|
196
|
+
children: /* @__PURE__ */ jsx("p", { className: "lk-ra-grade", children: s.couldNotBeGraded })
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function ReadAloud({
|
|
202
|
+
data,
|
|
203
|
+
onComplete,
|
|
204
|
+
onSubmit,
|
|
205
|
+
onInteraction,
|
|
206
|
+
value,
|
|
207
|
+
defaultValue,
|
|
208
|
+
defaultSubmitted,
|
|
209
|
+
renderMode = "practice",
|
|
210
|
+
outcome,
|
|
211
|
+
mediaBudget,
|
|
212
|
+
mediaStrings,
|
|
213
|
+
strings,
|
|
214
|
+
theme,
|
|
215
|
+
locale,
|
|
216
|
+
disabled,
|
|
217
|
+
recordingBinding,
|
|
218
|
+
assessment,
|
|
219
|
+
breakThreshold,
|
|
220
|
+
monotoneThreshold,
|
|
221
|
+
workletUrl
|
|
222
|
+
}) {
|
|
223
|
+
const isExam = renderMode === "exam";
|
|
224
|
+
const isReview = renderMode === "review";
|
|
225
|
+
const s = useLkStrings(strings);
|
|
226
|
+
const slot = useContext(SequenceSlotContext);
|
|
227
|
+
const captureGroup = slot?.captureGroup;
|
|
228
|
+
const devError = useMemo(() => {
|
|
229
|
+
if (!isDevelopment()) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
if (data.redacted === true) {
|
|
233
|
+
try {
|
|
234
|
+
assertRedacted(data);
|
|
235
|
+
return null;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const result = validateActivity("read-aloud", data);
|
|
241
|
+
return result.success ? null : new ActivitySchemaError("read-aloud", result.errors);
|
|
242
|
+
}, [data]);
|
|
243
|
+
const { maxSeconds, minSeconds, maxTakes } = readRecordingBounds(data.recording);
|
|
244
|
+
const readingKey = readingKeyOf(data, { maxSeconds, minSeconds, maxTakes });
|
|
245
|
+
const recorder = useSpeechRecorder(
|
|
246
|
+
useMemo(
|
|
247
|
+
() => ({
|
|
248
|
+
maxDurationMs: maxSeconds * 1e3,
|
|
249
|
+
...minSeconds !== void 0 ? { minDurationMs: minSeconds * 1e3 } : {},
|
|
250
|
+
...maxTakes !== void 0 ? { maxTakes } : {},
|
|
251
|
+
// Forwarded, never defaulted: without it the recorder mints its own
|
|
252
|
+
// `blob:` module, which is the one a strict policy refuses.
|
|
253
|
+
...workletUrl !== void 0 ? { workletUrl } : {}
|
|
254
|
+
}),
|
|
255
|
+
[maxSeconds, minSeconds, maxTakes, workletUrl]
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
const { state, start, complete, getTimeSpent, reset } = useActivityState(
|
|
259
|
+
defaultSubmitted === true ? "completed" : "idle"
|
|
260
|
+
);
|
|
261
|
+
const [phase, setPhase] = useState({ kind: "idle" });
|
|
262
|
+
const [uploaded, setUploaded] = useState(null);
|
|
263
|
+
const [takeUrl, setTakeUrl] = useState(null);
|
|
264
|
+
const [playbackUrl, setPlaybackUrl] = useState(null);
|
|
265
|
+
const [errorNonce, setErrorNonce] = useState(0);
|
|
266
|
+
const ids = useId();
|
|
267
|
+
const titleId = `${ids}-title`;
|
|
268
|
+
const [modelsGroup] = useState(() => {
|
|
269
|
+
modelsGroupCount += 1;
|
|
270
|
+
return `lk-ra-models-${modelsGroupCount}`;
|
|
271
|
+
});
|
|
272
|
+
const interactionRef = useRef(onInteraction);
|
|
273
|
+
interactionRef.current = onInteraction;
|
|
274
|
+
const bindingRef = useRef(recordingBinding);
|
|
275
|
+
bindingRef.current = recordingBinding;
|
|
276
|
+
const submittingRef = useRef(false);
|
|
277
|
+
const runRef = useRef(0);
|
|
278
|
+
const slotRef = useRef(slot);
|
|
279
|
+
slotRef.current = slot;
|
|
280
|
+
const reportedTakeRef = useRef(null);
|
|
281
|
+
useEffect(
|
|
282
|
+
() => () => {
|
|
283
|
+
runRef.current += 1;
|
|
284
|
+
const take2 = reportedTakeRef.current;
|
|
285
|
+
if (take2 !== null) {
|
|
286
|
+
slotRef.current?.takeState(take2, "settled");
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
[]
|
|
290
|
+
);
|
|
291
|
+
const fire = useCallback(
|
|
292
|
+
(type, payload) => {
|
|
293
|
+
interactionRef.current?.({ type, activityId: data.id, timestamp: Date.now(), payload });
|
|
294
|
+
},
|
|
295
|
+
[data.id]
|
|
296
|
+
);
|
|
297
|
+
const lastStatusRef = useRef(recorder.status);
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
if (lastStatusRef.current === recorder.status) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
lastStatusRef.current = recorder.status;
|
|
303
|
+
if (recorder.status === "recording") {
|
|
304
|
+
fire("recording-started", { takes: recorder.takesUsed, durationMs: 0 });
|
|
305
|
+
} else if (recorder.status === "recorded" && recorder.take !== null) {
|
|
306
|
+
fire("recording-stopped", {
|
|
307
|
+
takes: recorder.takesUsed,
|
|
308
|
+
durationMs: recorder.take.durationMs
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}, [recorder.status, recorder.take, recorder.takesUsed, fire]);
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
if (recorder.error !== null) {
|
|
314
|
+
setErrorNonce((nonce) => nonce + 1);
|
|
315
|
+
}
|
|
316
|
+
}, [recorder.error]);
|
|
317
|
+
const take = recorder.take;
|
|
318
|
+
useEffect(() => {
|
|
319
|
+
if (take === null || typeof URL.createObjectURL !== "function") {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const url = URL.createObjectURL(take.blob);
|
|
323
|
+
setTakeUrl(url);
|
|
324
|
+
return () => {
|
|
325
|
+
URL.revokeObjectURL(url);
|
|
326
|
+
setTakeUrl(null);
|
|
327
|
+
};
|
|
328
|
+
}, [take]);
|
|
329
|
+
const restored = recordingOf(value ?? defaultValue);
|
|
330
|
+
const restoredKey = restored?.key ?? null;
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
const binding = bindingRef.current;
|
|
333
|
+
if (!isReview || restored === null || binding?.playbackUrl === void 0) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
let live = true;
|
|
337
|
+
void Promise.resolve(binding.playbackUrl(restored)).then(
|
|
338
|
+
(url) => {
|
|
339
|
+
if (live) {
|
|
340
|
+
setPlaybackUrl(url);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
() => {
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
return () => {
|
|
347
|
+
live = false;
|
|
348
|
+
};
|
|
349
|
+
}, [isReview, restoredKey, readingKey]);
|
|
350
|
+
const statusRef = useRef(recorder.status);
|
|
351
|
+
statusRef.current = recorder.status;
|
|
352
|
+
const releaseMicrophone = useCallback(() => {
|
|
353
|
+
if (capturing(statusRef.current)) {
|
|
354
|
+
recorder.discard();
|
|
355
|
+
}
|
|
356
|
+
}, [recorder.discard]);
|
|
357
|
+
useEffect(() => {
|
|
358
|
+
if (captureGroup === void 0) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
return joinCaptureGroup(captureGroup, releaseMicrophone);
|
|
362
|
+
}, [captureGroup, releaseMicrophone]);
|
|
363
|
+
const defaultSubmittedRef = useRef(defaultSubmitted);
|
|
364
|
+
useEffect(() => {
|
|
365
|
+
defaultSubmittedRef.current = defaultSubmitted;
|
|
366
|
+
}, [defaultSubmitted]);
|
|
367
|
+
const lastReadingRef = useRef(readingKey);
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
if (lastReadingRef.current === readingKey) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
lastReadingRef.current = readingKey;
|
|
373
|
+
submittingRef.current = false;
|
|
374
|
+
runRef.current += 1;
|
|
375
|
+
setPhase({ kind: "idle" });
|
|
376
|
+
setUploaded(null);
|
|
377
|
+
setPlaybackUrl(null);
|
|
378
|
+
recorder.reset();
|
|
379
|
+
reset(defaultSubmittedRef.current === true ? "completed" : "idle");
|
|
380
|
+
}, [readingKey, reset, recorder.reset]);
|
|
381
|
+
const phaseTake = phase.kind === "idle" ? null : phase.take;
|
|
382
|
+
const phaseTakeState = takeStateOf(phase, uploaded);
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
const take2 = phaseTake ?? reportedTakeRef.current;
|
|
385
|
+
if (slot === null || take2 === null) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
reportedTakeRef.current = take2;
|
|
389
|
+
slot.takeState(take2, phaseTakeState);
|
|
390
|
+
}, [slot, phaseTake, phaseTakeState]);
|
|
391
|
+
const modelsRef = useRef(null);
|
|
392
|
+
const isCapturing = capturing(recorder.status);
|
|
393
|
+
useEffect(() => {
|
|
394
|
+
if (!isCapturing) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const node = modelsRef.current;
|
|
398
|
+
if (node === null) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const hush = () => {
|
|
402
|
+
for (const media of node.querySelectorAll("audio, video")) {
|
|
403
|
+
const element = media;
|
|
404
|
+
if (!element.paused) {
|
|
405
|
+
element.pause();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
hush();
|
|
410
|
+
node.addEventListener("play", hush, true);
|
|
411
|
+
return () => {
|
|
412
|
+
node.removeEventListener("play", hush, true);
|
|
413
|
+
};
|
|
414
|
+
}, [isCapturing]);
|
|
415
|
+
const slowMedia = useMemo(
|
|
416
|
+
() => slowMediaFor(data, s.readAloudSlowRecording),
|
|
417
|
+
[data, s.readAloudSlowRecording]
|
|
418
|
+
);
|
|
419
|
+
const takeAudio = isReview ? playbackUrl : takeUrl;
|
|
420
|
+
const playback = usePlaybackRefusal(takeAudio);
|
|
421
|
+
const submitRef = useRef(null);
|
|
422
|
+
if (devError) {
|
|
423
|
+
throw devError;
|
|
424
|
+
}
|
|
425
|
+
if (!isReview && recordingBinding?.upload === void 0) {
|
|
426
|
+
throw new Error(
|
|
427
|
+
`ReadAloud "${data.id}" was rendered in renderMode "${renderMode}" without \`recordingBinding.upload\`. The learner could record a take that is stored nowhere and submitted as nothing, which looks like a working activity the whole way through. Pass a \`recordingBinding\` whose \`upload\` puts the take in your storage and returns its key. \`assess\` is optional: without it the take is still recorded, uploaded and submitted, and a notice replaces the feedback.`
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
const submitted = state === "completed";
|
|
431
|
+
const inactive = disabled === true || submitted || isReview;
|
|
432
|
+
const busy = phase.kind === "uploading" || phase.kind === "assessing";
|
|
433
|
+
const takesLeft = maxTakes === void 0 ? void 0 : Math.max(0, maxTakes - recorder.takesUsed);
|
|
434
|
+
const raise = (next) => {
|
|
435
|
+
setErrorNonce((nonce) => nonce + 1);
|
|
436
|
+
setPhase(next);
|
|
437
|
+
};
|
|
438
|
+
const beginTakeReport = (take2) => {
|
|
439
|
+
reportedTakeRef.current = take2;
|
|
440
|
+
slot?.takeState(take2, "in-flight");
|
|
441
|
+
};
|
|
442
|
+
const runAssess = async (ref, current, take2) => {
|
|
443
|
+
const assess = bindingRef.current?.assess;
|
|
444
|
+
const durationMs = current?.durationMs ?? 0;
|
|
445
|
+
const takes2 = recorder.takesUsed;
|
|
446
|
+
const run = runRef.current;
|
|
447
|
+
if (assess === void 0) {
|
|
448
|
+
setPhase({ kind: "unassessed", take: take2 });
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
setPhase({ kind: "assessing", take: take2 });
|
|
452
|
+
fire("assessment-requested", { takes: takes2, durationMs });
|
|
453
|
+
let answer;
|
|
454
|
+
try {
|
|
455
|
+
answer = await assess(ref);
|
|
456
|
+
} catch {
|
|
457
|
+
if (run !== runRef.current) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
raise({ kind: "assess-failed", take: take2, retryable: true });
|
|
461
|
+
fire("assessment-failed", { takes: takes2, durationMs, retryable: true });
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (run !== runRef.current) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const result = readAssessResult(answer);
|
|
468
|
+
if (result.status === "failed") {
|
|
469
|
+
raise({ kind: "assess-failed", take: take2, retryable: result.retryable });
|
|
470
|
+
fire("assessment-failed", { takes: takes2, durationMs, retryable: result.retryable });
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (result.status === "unscorable") {
|
|
474
|
+
setPhase({ kind: "unscorable", take: take2, code: result.code });
|
|
475
|
+
fire("assessment-failed", {
|
|
476
|
+
takes: takes2,
|
|
477
|
+
durationMs,
|
|
478
|
+
retryable: true,
|
|
479
|
+
...result.code !== void 0 ? { code: result.code } : {}
|
|
480
|
+
});
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const timeSpent = getTimeSpent();
|
|
484
|
+
setPhase({ kind: "graded", take: take2, assessment: result.assessment, grade: result.grade });
|
|
485
|
+
const grade = result.grade;
|
|
486
|
+
if (grade === null) {
|
|
487
|
+
fire("assessment-failed", { takes: takes2, durationMs, retryable: true });
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
onComplete?.(
|
|
491
|
+
stampTake(
|
|
492
|
+
{
|
|
493
|
+
score: grade.score,
|
|
494
|
+
maxScore: grade.maxScore,
|
|
495
|
+
passed: grade.passed,
|
|
496
|
+
timeSpent,
|
|
497
|
+
xapiStatement: xAPIBuilder.buildAnsweredStatement({
|
|
498
|
+
actor: ANONYMOUS_ACTOR,
|
|
499
|
+
object: {
|
|
500
|
+
id: objectIdFor(data.id),
|
|
501
|
+
name: { [data.locale ?? "en-US"]: data.title },
|
|
502
|
+
...xapiDefinitionFor(data)
|
|
503
|
+
},
|
|
504
|
+
timeSpentMs: timeSpent,
|
|
505
|
+
response: result.recognizedText ?? "",
|
|
506
|
+
// `ScoringResult.details` is required where `GradeRecord.details` is
|
|
507
|
+
// optional, and an empty list is the honest reading of "no per-word
|
|
508
|
+
// marks were stored" — never a mark of its own.
|
|
509
|
+
scoringResult: {
|
|
510
|
+
score: fractionOfGrade(grade),
|
|
511
|
+
maxScore: 1,
|
|
512
|
+
passed: grade.passed,
|
|
513
|
+
feedback: grade.feedback,
|
|
514
|
+
details: grade.details ?? []
|
|
515
|
+
}
|
|
516
|
+
})
|
|
517
|
+
},
|
|
518
|
+
take2
|
|
519
|
+
)
|
|
520
|
+
);
|
|
521
|
+
};
|
|
522
|
+
const submitTake = async (current) => {
|
|
523
|
+
const binding = bindingRef.current;
|
|
524
|
+
if (inactive || submittingRef.current || binding === void 0) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
submittingRef.current = true;
|
|
528
|
+
const takes2 = recorder.takesUsed;
|
|
529
|
+
const run = runRef.current;
|
|
530
|
+
const take2 = mintTake();
|
|
531
|
+
beginTakeReport(take2);
|
|
532
|
+
try {
|
|
533
|
+
let ref = null;
|
|
534
|
+
if (current !== null) {
|
|
535
|
+
setPhase({ kind: "uploading", take: take2 });
|
|
536
|
+
try {
|
|
537
|
+
ref = await binding.upload(current);
|
|
538
|
+
} catch {
|
|
539
|
+
if (run !== runRef.current) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
raise({ kind: "upload-failed", take: take2 });
|
|
543
|
+
fire("recording-upload-failed", {
|
|
544
|
+
takes: takes2,
|
|
545
|
+
durationMs: current.durationMs,
|
|
546
|
+
retryable: true
|
|
547
|
+
});
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (run !== runRef.current) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
setUploaded(ref);
|
|
554
|
+
fire("recording-uploaded", { takes: takes2, durationMs: current.durationMs });
|
|
555
|
+
}
|
|
556
|
+
onSubmit?.(stampTake(responseOf(ref, takes2), take2));
|
|
557
|
+
fire("submitted", { takes: takes2, durationMs: current?.durationMs ?? 0 });
|
|
558
|
+
if (isExam || ref === null) {
|
|
559
|
+
complete();
|
|
560
|
+
setPhase({ kind: "submitted", take: take2 });
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
await runAssess(ref, current, take2);
|
|
564
|
+
} finally {
|
|
565
|
+
submittingRef.current = false;
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const retryAssess = async (ref, take2) => {
|
|
569
|
+
if (submittingRef.current) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
submittingRef.current = true;
|
|
573
|
+
beginTakeReport(take2);
|
|
574
|
+
try {
|
|
575
|
+
await runAssess(ref, recorder.take, take2);
|
|
576
|
+
} finally {
|
|
577
|
+
submittingRef.current = false;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
const handleSubmit = (event) => {
|
|
581
|
+
event.preventDefault();
|
|
582
|
+
if (inactive || busy || recorder.take === null || phase.kind !== "idle") {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
void submitTake(recorder.take);
|
|
586
|
+
};
|
|
587
|
+
const beginTake = () => {
|
|
588
|
+
if (inactive || busy || !recorder.canRecord) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (recorder.take !== null) {
|
|
592
|
+
fire("recording-discarded", {
|
|
593
|
+
takes: recorder.takesUsed,
|
|
594
|
+
durationMs: recorder.take.durationMs
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
setPhase({ kind: "idle" });
|
|
598
|
+
setUploaded(null);
|
|
599
|
+
start();
|
|
600
|
+
void recorder.start();
|
|
601
|
+
};
|
|
602
|
+
const contentLang = typeof data.locale === "string" ? data.locale : void 0;
|
|
603
|
+
const contentDir = localeDirectionOf(data.locale);
|
|
604
|
+
const outcomeReading = useMemo(() => readOutcome(outcome), [outcome]);
|
|
605
|
+
const keptEvidence = useMemo(() => readEvidence(assessment), [assessment]);
|
|
606
|
+
const storedGrade = outcomeReading?.kind === "graded" && outcomeReading.status === "graded" ? outcomeReading.grade : null;
|
|
607
|
+
const storedMarks = useMemo(
|
|
608
|
+
() => isReview && keptEvidence === null && storedGrade?.details !== void 0 ? marksFromDetails(storedGrade.details) : null,
|
|
609
|
+
[isReview, keptEvidence, storedGrade]
|
|
610
|
+
);
|
|
611
|
+
const feedbackAssessment = isReview ? keptEvidence : phase.kind === "graded" ? phase.assessment : null;
|
|
612
|
+
const feedbackGrade = isReview ? storedGrade : phase.kind === "graded" ? phase.grade : null;
|
|
613
|
+
const feedbackAudio = playback.refused ? null : takeAudio;
|
|
614
|
+
const rootRef = useRef(null);
|
|
615
|
+
const [panelLostTheGrade, setPanelLostTheGrade] = useState(false);
|
|
616
|
+
const panelHasGrade = feedbackAssessment !== null && feedbackGrade !== null;
|
|
617
|
+
const gradeShownInPanel = panelHasGrade && !panelLostTheGrade;
|
|
618
|
+
useEffect(() => {
|
|
619
|
+
const root = rootRef.current;
|
|
620
|
+
const lost = panelHasGrade && (root === null || root.querySelector(".lk-pf-grade") === null);
|
|
621
|
+
setPanelLostTheGrade((was) => was === lost ? was : lost);
|
|
622
|
+
});
|
|
623
|
+
const announcement = useMemo(() => {
|
|
624
|
+
if (isReview) {
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
if (recorder.status === "recording") {
|
|
628
|
+
return { text: s.readAloudRecordingStarted, feedback: null };
|
|
629
|
+
}
|
|
630
|
+
const stopped = recorder.status === "recorded" && take !== null ? {
|
|
631
|
+
text: s.readAloudRecordingStopped(
|
|
632
|
+
secondsWithin(take.durationMs, maxSeconds, "nearest"),
|
|
633
|
+
maxSeconds
|
|
634
|
+
),
|
|
635
|
+
feedback: null
|
|
636
|
+
} : null;
|
|
637
|
+
if (isExam) {
|
|
638
|
+
if (phase.kind === "submitted" || submitted) {
|
|
639
|
+
return { text: s.answerSubmitted, feedback: null };
|
|
640
|
+
}
|
|
641
|
+
return phase.kind === "idle" ? stopped : null;
|
|
642
|
+
}
|
|
643
|
+
switch (phase.kind) {
|
|
644
|
+
case "graded": {
|
|
645
|
+
const grade = phase.grade;
|
|
646
|
+
return grade === null ? { text: `${s.answerSubmitted} ${s.couldNotBeGraded}`, feedback: null } : {
|
|
647
|
+
text: `${s.answerSubmitted} ${s.scoreAnnouncement(percentOfGrade(grade), grade.passed)}`,
|
|
648
|
+
feedback: grade.feedback
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
case "unscorable":
|
|
652
|
+
return { text: unscorableMessage(phase.code, s), feedback: null };
|
|
653
|
+
case "unassessed":
|
|
654
|
+
return { text: s.readAloudAssessmentUnavailable, feedback: null };
|
|
655
|
+
case "idle":
|
|
656
|
+
return stopped;
|
|
657
|
+
default:
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
}, [isReview, isExam, phase, submitted, s, recorder.status, take, maxSeconds]);
|
|
661
|
+
const alertText = recorder.error !== null ? s.readAloudRecorderError(recorder.error) : phase.kind === "upload-failed" ? s.readAloudUploadFailed : phase.kind === "assess-failed" ? s.readAloudAssessmentFailed : null;
|
|
662
|
+
return /* @__PURE__ */ jsxs(
|
|
663
|
+
"form",
|
|
664
|
+
{
|
|
665
|
+
className: "lk-ra",
|
|
666
|
+
ref: rootRef,
|
|
667
|
+
"aria-labelledby": VISIBLE_TEXT_RE.test(data.title) ? titleId : void 0,
|
|
668
|
+
lang: locale,
|
|
669
|
+
"data-render-mode": renderMode,
|
|
670
|
+
style: theme,
|
|
671
|
+
onSubmit: handleSubmit,
|
|
672
|
+
children: [
|
|
673
|
+
/* @__PURE__ */ jsx("p", { id: titleId, className: "lk-ra-title", dir: contentDir ?? "auto", lang: contentLang, children: data.title }),
|
|
674
|
+
typeof data.instructions === "string" && data.instructions !== "" ? /* @__PURE__ */ jsx("p", { className: "lk-ra-instructions", dir: contentDir ?? "auto", lang: contentLang, children: data.instructions }) : null,
|
|
675
|
+
/* @__PURE__ */ jsx("p", { className: "lk-ra-reference", dir: contentDir ?? "auto", lang: contentLang, children: data.referenceText }),
|
|
676
|
+
data.media !== void 0 || slowMedia !== void 0 ? /* @__PURE__ */ jsxs("div", { className: "lk-ra-models", ref: modelsRef, children: [
|
|
677
|
+
data.media !== void 0 ? /* @__PURE__ */ jsxs("fieldset", { className: "lk-ra-model", children: [
|
|
678
|
+
/* @__PURE__ */ jsx("legend", { className: "lk-ra-model-label", children: s.readAloudModelRecording }),
|
|
679
|
+
/* @__PURE__ */ jsx(
|
|
680
|
+
ActivityMedia,
|
|
681
|
+
{
|
|
682
|
+
media: data.media,
|
|
683
|
+
renderMode,
|
|
684
|
+
playbackGroup: modelsGroup,
|
|
685
|
+
...mediaBudget !== void 0 ? { mediaBudget } : {},
|
|
686
|
+
...mediaStrings !== void 0 ? { mediaStrings } : {},
|
|
687
|
+
...strings !== void 0 ? { strings } : {},
|
|
688
|
+
...onInteraction !== void 0 ? { onInteraction } : {},
|
|
689
|
+
...locale !== void 0 ? { locale } : {},
|
|
690
|
+
...disabled === true || isCapturing ? { disabled: true } : {}
|
|
691
|
+
}
|
|
692
|
+
)
|
|
693
|
+
] }) : null,
|
|
694
|
+
slowMedia !== void 0 ? /* @__PURE__ */ jsxs("fieldset", { className: "lk-ra-model", "data-slow": "true", children: [
|
|
695
|
+
/* @__PURE__ */ jsx("legend", { className: "lk-ra-model-label", children: s.readAloudSlowRecording }),
|
|
696
|
+
/* @__PURE__ */ jsx(
|
|
697
|
+
ActivityMedia,
|
|
698
|
+
{
|
|
699
|
+
media: slowMedia,
|
|
700
|
+
renderMode,
|
|
701
|
+
playbackGroup: modelsGroup,
|
|
702
|
+
...mediaStrings !== void 0 ? { mediaStrings } : {},
|
|
703
|
+
...strings !== void 0 ? { strings } : {},
|
|
704
|
+
...locale !== void 0 ? { locale } : {},
|
|
705
|
+
...disabled === true || isCapturing ? { disabled: true } : {}
|
|
706
|
+
}
|
|
707
|
+
)
|
|
708
|
+
] }) : null
|
|
709
|
+
] }) : null,
|
|
710
|
+
isReview || submitted ? null : /* @__PURE__ */ jsxs(
|
|
711
|
+
"div",
|
|
712
|
+
{
|
|
713
|
+
className: "lk-ra-recorder",
|
|
714
|
+
"data-status": recorder.status,
|
|
715
|
+
"data-level": recorder.status === "recording" ? Math.min(LEVEL_STEPS, Math.round(recorder.level * LEVEL_STEPS)) : void 0,
|
|
716
|
+
children: [
|
|
717
|
+
recorder.status === "recording" ? /* @__PURE__ */ jsx(
|
|
718
|
+
"button",
|
|
719
|
+
{
|
|
720
|
+
type: "button",
|
|
721
|
+
className: "lk-ra-stop",
|
|
722
|
+
disabled: inactive,
|
|
723
|
+
onClick: () => recorder.stop(),
|
|
724
|
+
children: s.readAloudStop
|
|
725
|
+
}
|
|
726
|
+
) : (
|
|
727
|
+
// aria-disabled, never disabled, once the takes are spent: a
|
|
728
|
+
// natively disabled button drops keyboard focus to the page body,
|
|
729
|
+
// and this is the control a learner comes back to.
|
|
730
|
+
/* @__PURE__ */ jsx(
|
|
731
|
+
"button",
|
|
732
|
+
{
|
|
733
|
+
type: "button",
|
|
734
|
+
className: "lk-ra-record",
|
|
735
|
+
disabled: inactive,
|
|
736
|
+
"aria-disabled": !recorder.canRecord || busy || void 0,
|
|
737
|
+
onClick: beginTake,
|
|
738
|
+
children: recorder.take === null ? s.readAloudRecord : s.readAloudRerecord
|
|
739
|
+
}
|
|
740
|
+
)
|
|
741
|
+
),
|
|
742
|
+
recorder.status === "recording" ? (
|
|
743
|
+
// Visible, and hidden from assistive technology, beside the level
|
|
744
|
+
// meter the recorder's `data-level` drives. Its text changes every
|
|
745
|
+
// whole second, so as a live region it announced ten times in a
|
|
746
|
+
// ten-second take — into the microphone. What a screen-reader
|
|
747
|
+
// learner needs instead is said once each, below.
|
|
748
|
+
/* @__PURE__ */ jsx("p", { className: "lk-ra-progress", "aria-hidden": "true", children: s.readAloudRecordingProgress(
|
|
749
|
+
secondsWithin(recorder.elapsedMs, maxSeconds, "down"),
|
|
750
|
+
maxSeconds
|
|
751
|
+
) })
|
|
752
|
+
) : null,
|
|
753
|
+
takesLeft !== void 0 && maxTakes !== void 0 ? /* @__PURE__ */ jsx("p", { className: "lk-ra-takes", children: s.readAloudTakesRemaining(takesLeft, maxTakes) }) : null
|
|
754
|
+
]
|
|
755
|
+
}
|
|
756
|
+
),
|
|
757
|
+
takeAudio === null ? null : playback.refused ? (
|
|
758
|
+
// In the player's place, not beside it: a player the page will not
|
|
759
|
+
// load looks exactly like one that works until it is pressed, and then
|
|
760
|
+
// does nothing. A note rather than an alert — the learner can still
|
|
761
|
+
// submit, and nothing here asks them to act.
|
|
762
|
+
/* @__PURE__ */ jsx("p", { className: "lk-ra-take-unavailable", role: "note", children: s.readAloudPlaybackUnavailable })
|
|
763
|
+
) : (
|
|
764
|
+
// biome-ignore lint/a11y/useMediaCaption: the learner's own take has no caption track to offer; its accessible name says whose recording it is
|
|
765
|
+
/* @__PURE__ */ jsx(
|
|
766
|
+
"audio",
|
|
767
|
+
{
|
|
768
|
+
className: "lk-ra-take",
|
|
769
|
+
controls: true,
|
|
770
|
+
src: takeAudio,
|
|
771
|
+
"aria-label": s.readAloudYourRecording,
|
|
772
|
+
onError: (event) => playback.refuse(event.currentTarget),
|
|
773
|
+
...isReview ? {} : { "data-take": recorder.takesUsed }
|
|
774
|
+
}
|
|
775
|
+
)
|
|
776
|
+
),
|
|
777
|
+
isReview || submitted ? null : /* @__PURE__ */ jsxs("div", { className: "lk-ra-actions", children: [
|
|
778
|
+
/* @__PURE__ */ jsx(
|
|
779
|
+
"button",
|
|
780
|
+
{
|
|
781
|
+
ref: submitRef,
|
|
782
|
+
type: "submit",
|
|
783
|
+
className: "lk-ra-submit",
|
|
784
|
+
disabled: disabled === true,
|
|
785
|
+
"aria-disabled": recorder.take === null || phase.kind !== "idle" || void 0,
|
|
786
|
+
"aria-busy": busy || void 0,
|
|
787
|
+
children: s.submit
|
|
788
|
+
}
|
|
789
|
+
),
|
|
790
|
+
isExam ? (
|
|
791
|
+
// Explicit, and only here: an exam answer with no recording is a
|
|
792
|
+
// decision a learner takes, never something a failed upload does
|
|
793
|
+
// for them.
|
|
794
|
+
/* @__PURE__ */ jsx(
|
|
795
|
+
"button",
|
|
796
|
+
{
|
|
797
|
+
type: "button",
|
|
798
|
+
className: "lk-ra-submit-blank",
|
|
799
|
+
disabled: inactive,
|
|
800
|
+
"aria-disabled": busy || void 0,
|
|
801
|
+
onClick: () => {
|
|
802
|
+
if (!busy) {
|
|
803
|
+
void submitTake(null);
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
children: s.readAloudSubmitWithoutRecording
|
|
807
|
+
}
|
|
808
|
+
)
|
|
809
|
+
) : null,
|
|
810
|
+
offersRetry(phase, uploaded) ? /* @__PURE__ */ jsx(
|
|
811
|
+
"button",
|
|
812
|
+
{
|
|
813
|
+
type: "button",
|
|
814
|
+
className: "lk-ra-retry",
|
|
815
|
+
onClick: () => {
|
|
816
|
+
submitRef.current?.focus();
|
|
817
|
+
if (phase.kind === "upload-failed") {
|
|
818
|
+
void submitTake(recorder.take);
|
|
819
|
+
} else if (phase.kind === "assess-failed" && uploaded !== null) {
|
|
820
|
+
void retryAssess(uploaded, phase.take);
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
children: s.readAloudTryAgain
|
|
824
|
+
}
|
|
825
|
+
) : null
|
|
826
|
+
] }),
|
|
827
|
+
busy ? /* @__PURE__ */ jsx("p", { className: "lk-ra-pending", role: "status", "aria-busy": "true", children: phase.kind === "uploading" ? s.readAloudUploading : s.readAloudAssessing }) : null,
|
|
828
|
+
alertText !== null ? /* @__PURE__ */ jsx("p", { className: "lk-ra-alert", role: "alert", children: alertText }, errorNonce) : null,
|
|
829
|
+
feedbackAssessment !== null ? /* @__PURE__ */ jsx(
|
|
830
|
+
PronunciationFeedback,
|
|
831
|
+
{
|
|
832
|
+
data: { referenceText: data.referenceText, locale: data.locale },
|
|
833
|
+
assessment: feedbackAssessment,
|
|
834
|
+
...feedbackGrade !== null ? { grade: feedbackGrade } : {},
|
|
835
|
+
...feedbackAudio !== null ? { audioUrl: feedbackAudio } : {},
|
|
836
|
+
...breakThreshold !== void 0 ? { breakThreshold } : {},
|
|
837
|
+
...monotoneThreshold !== void 0 ? { monotoneThreshold } : {},
|
|
838
|
+
...locale !== void 0 ? { locale } : {},
|
|
839
|
+
...strings !== void 0 ? { strings } : {}
|
|
840
|
+
}
|
|
841
|
+
) : null,
|
|
842
|
+
storedMarks !== null ? /* @__PURE__ */ jsxs("div", { className: "lk-ra-marks", children: [
|
|
843
|
+
/* @__PURE__ */ jsx("ol", { className: "lk-ra-words", "aria-label": s.pronunciationWordsLabel, dir: contentDir, children: storedMarks.map((entry, index) => {
|
|
844
|
+
const sentence = markSentence(entry, s);
|
|
845
|
+
return /* @__PURE__ */ jsxs(
|
|
846
|
+
"li",
|
|
847
|
+
{
|
|
848
|
+
className: "lk-ra-word",
|
|
849
|
+
"data-state": entry.state,
|
|
850
|
+
children: [
|
|
851
|
+
/* @__PURE__ */ jsx("span", { className: "lk-visually-hidden", style: VISUALLY_HIDDEN, children: sentence }),
|
|
852
|
+
/* @__PURE__ */ jsx(
|
|
853
|
+
"span",
|
|
854
|
+
{
|
|
855
|
+
className: "lk-ra-word-text",
|
|
856
|
+
"aria-hidden": "true",
|
|
857
|
+
dir: contentDir ?? "auto",
|
|
858
|
+
lang: contentLang,
|
|
859
|
+
children: entry.reference
|
|
860
|
+
}
|
|
861
|
+
)
|
|
862
|
+
]
|
|
863
|
+
},
|
|
864
|
+
index
|
|
865
|
+
);
|
|
866
|
+
}) }),
|
|
867
|
+
/* @__PURE__ */ jsx("ul", { className: "lk-ra-legend", children: STORED_STATES.map((state2) => /* @__PURE__ */ jsx("li", { "data-state": state2, children: s.pronunciationLegend(state2) }, state2)) })
|
|
868
|
+
] }) : null,
|
|
869
|
+
/* @__PURE__ */ jsx(FeedbackRegion, { id: `${data.id}-feedback`, children: isReview ? outcomeReading !== void 0 ? /* @__PURE__ */ jsx(OutcomeSummary, { reading: outcomeReading, s, scoreShown: gradeShownInPanel }) : null : gradeShownInPanel ? (
|
|
870
|
+
// Announced, not repeated. A grade the feedback panel is already
|
|
871
|
+
// showing would otherwise be read on screen twice, feedback and all —
|
|
872
|
+
// but a live region is the only thing that TELLS a screen-reader
|
|
873
|
+
// learner a grade arrived, since nothing takes focus. Clipped rather
|
|
874
|
+
// than `display: none`, which would stop it being announced at all.
|
|
875
|
+
/* @__PURE__ */ jsx("span", { className: "lk-visually-hidden", style: VISUALLY_HIDDEN, children: /* @__PURE__ */ jsx(AnnouncementText, { announcement }) })
|
|
876
|
+
) : /* @__PURE__ */ jsx(AnnouncementText, { announcement }) })
|
|
877
|
+
]
|
|
878
|
+
}
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
function ReadAloud2(props) {
|
|
882
|
+
const strings = useLkStrings(props.strings);
|
|
883
|
+
return /* @__PURE__ */ jsx(ActivityErrorBoundary, { activityTitle: props.data?.title, strings, children: /* @__PURE__ */ jsx(ReadAloud, { ...props }) });
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
export { ReadAloud2 as ReadAloud, SequenceSlotContext, mintTake, stopCaptureGroup, takeOf };
|
|
887
|
+
//# sourceMappingURL=chunk-5JFMXBH7.js.map
|
|
888
|
+
//# sourceMappingURL=chunk-5JFMXBH7.js.map
|