@livo-tv/blocks 1.22.0 → 1.23.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/dist/index.cjs +31 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4005,6 +4005,9 @@ function remainderAfterOverlap(previous, next) {
|
|
|
4005
4005
|
}
|
|
4006
4006
|
return null;
|
|
4007
4007
|
}
|
|
4008
|
+
function liveCaptionRow(text, receivedAt, speaker) {
|
|
4009
|
+
return speaker == null ? { text, receivedAt } : { text, receivedAt, speaker };
|
|
4010
|
+
}
|
|
4008
4011
|
function coalesceLiveCaptionCues(cues) {
|
|
4009
4012
|
const out = [];
|
|
4010
4013
|
for (const cue of cues) {
|
|
@@ -4012,26 +4015,31 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
4012
4015
|
if (!text) continue;
|
|
4013
4016
|
const last = out[out.length - 1];
|
|
4014
4017
|
if (!last) {
|
|
4015
|
-
out.push(
|
|
4018
|
+
out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
|
|
4019
|
+
continue;
|
|
4020
|
+
}
|
|
4021
|
+
if (last.speaker !== cue.speaker && (last.speaker != null || cue.speaker != null)) {
|
|
4022
|
+
out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
|
|
4016
4023
|
continue;
|
|
4017
4024
|
}
|
|
4018
4025
|
const lastNorm = normalizeLiveCaptionText(last.text);
|
|
4019
4026
|
const nextNorm = normalizeLiveCaptionText(text);
|
|
4020
4027
|
if (lastNorm === nextNorm) continue;
|
|
4021
4028
|
if (nextNorm.startsWith(lastNorm) || lastNorm.startsWith(nextNorm)) {
|
|
4022
|
-
out[out.length - 1] =
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4029
|
+
out[out.length - 1] = liveCaptionRow(
|
|
4030
|
+
nextNorm.length >= lastNorm.length ? text : last.text,
|
|
4031
|
+
cue.receivedAt,
|
|
4032
|
+
cue.speaker ?? last.speaker
|
|
4033
|
+
);
|
|
4026
4034
|
continue;
|
|
4027
4035
|
}
|
|
4028
4036
|
const remainder = remainderAfterOverlap(last.text, text);
|
|
4029
4037
|
if (remainder !== null) {
|
|
4030
4038
|
if (!remainder) continue;
|
|
4031
|
-
out.push(
|
|
4039
|
+
out.push(liveCaptionRow(remainder, cue.receivedAt, cue.speaker));
|
|
4032
4040
|
continue;
|
|
4033
4041
|
}
|
|
4034
|
-
out.push(
|
|
4042
|
+
out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
|
|
4035
4043
|
}
|
|
4036
4044
|
return out;
|
|
4037
4045
|
}
|
|
@@ -4086,7 +4094,14 @@ async function loadLiveCaptions(url) {
|
|
|
4086
4094
|
if (typeof record.receivedAt !== "number" || !Number.isFinite(record.receivedAt)) {
|
|
4087
4095
|
continue;
|
|
4088
4096
|
}
|
|
4089
|
-
|
|
4097
|
+
const parsed = {
|
|
4098
|
+
text: record.text.trim(),
|
|
4099
|
+
receivedAt: record.receivedAt
|
|
4100
|
+
};
|
|
4101
|
+
if (typeof record.speaker === "number" && Number.isFinite(record.speaker)) {
|
|
4102
|
+
parsed.speaker = record.speaker;
|
|
4103
|
+
}
|
|
4104
|
+
cues.push(parsed);
|
|
4090
4105
|
}
|
|
4091
4106
|
return { ok: true, cues };
|
|
4092
4107
|
} catch {
|
|
@@ -4159,6 +4174,10 @@ function LiveCaptionStack({
|
|
|
4159
4174
|
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
4160
4175
|
if (cues.length === 0) return null;
|
|
4161
4176
|
const windowed = variant === "window";
|
|
4177
|
+
const distinctSpeakers = new Set(
|
|
4178
|
+
cues.map((cue) => cue.speaker).filter((speaker) => speaker != null)
|
|
4179
|
+
);
|
|
4180
|
+
const showTurns = distinctSpeakers.size >= 2;
|
|
4162
4181
|
return /* @__PURE__ */ jsx(
|
|
4163
4182
|
"div",
|
|
4164
4183
|
{
|
|
@@ -4204,13 +4223,16 @@ function LiveCaptionStack({
|
|
|
4204
4223
|
const fromEnd = cues.length - 1 - index;
|
|
4205
4224
|
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4206
4225
|
const newest = fromEnd === 0;
|
|
4226
|
+
const previous = cues[index - 1];
|
|
4227
|
+
const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
|
|
4207
4228
|
return /* @__PURE__ */ jsxs(
|
|
4208
4229
|
"span",
|
|
4209
4230
|
{
|
|
4210
4231
|
style: { opacity },
|
|
4211
4232
|
"aria-live": newest ? "polite" : void 0,
|
|
4212
4233
|
children: [
|
|
4213
|
-
index > 0 ? " " : "",
|
|
4234
|
+
turnStart && index > 0 ? /* @__PURE__ */ jsx("br", {}) : index > 0 ? " " : "",
|
|
4235
|
+
turnStart ? "\u2013 " : "",
|
|
4214
4236
|
cue.text
|
|
4215
4237
|
]
|
|
4216
4238
|
},
|