@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 CHANGED
@@ -4031,6 +4031,9 @@ function remainderAfterOverlap(previous, next) {
4031
4031
  }
4032
4032
  return null;
4033
4033
  }
4034
+ function liveCaptionRow(text, receivedAt, speaker) {
4035
+ return speaker == null ? { text, receivedAt } : { text, receivedAt, speaker };
4036
+ }
4034
4037
  function coalesceLiveCaptionCues(cues) {
4035
4038
  const out = [];
4036
4039
  for (const cue of cues) {
@@ -4038,26 +4041,31 @@ function coalesceLiveCaptionCues(cues) {
4038
4041
  if (!text) continue;
4039
4042
  const last = out[out.length - 1];
4040
4043
  if (!last) {
4041
- out.push({ text, receivedAt: cue.receivedAt });
4044
+ out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
4045
+ continue;
4046
+ }
4047
+ if (last.speaker !== cue.speaker && (last.speaker != null || cue.speaker != null)) {
4048
+ out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
4042
4049
  continue;
4043
4050
  }
4044
4051
  const lastNorm = normalizeLiveCaptionText(last.text);
4045
4052
  const nextNorm = normalizeLiveCaptionText(text);
4046
4053
  if (lastNorm === nextNorm) continue;
4047
4054
  if (nextNorm.startsWith(lastNorm) || lastNorm.startsWith(nextNorm)) {
4048
- out[out.length - 1] = {
4049
- text: nextNorm.length >= lastNorm.length ? text : last.text,
4050
- receivedAt: cue.receivedAt
4051
- };
4055
+ out[out.length - 1] = liveCaptionRow(
4056
+ nextNorm.length >= lastNorm.length ? text : last.text,
4057
+ cue.receivedAt,
4058
+ cue.speaker ?? last.speaker
4059
+ );
4052
4060
  continue;
4053
4061
  }
4054
4062
  const remainder = remainderAfterOverlap(last.text, text);
4055
4063
  if (remainder !== null) {
4056
4064
  if (!remainder) continue;
4057
- out.push({ text: remainder, receivedAt: cue.receivedAt });
4065
+ out.push(liveCaptionRow(remainder, cue.receivedAt, cue.speaker));
4058
4066
  continue;
4059
4067
  }
4060
- out.push({ text, receivedAt: cue.receivedAt });
4068
+ out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
4061
4069
  }
4062
4070
  return out;
4063
4071
  }
@@ -4112,7 +4120,14 @@ async function loadLiveCaptions(url) {
4112
4120
  if (typeof record.receivedAt !== "number" || !Number.isFinite(record.receivedAt)) {
4113
4121
  continue;
4114
4122
  }
4115
- cues.push({ text: record.text.trim(), receivedAt: record.receivedAt });
4123
+ const parsed = {
4124
+ text: record.text.trim(),
4125
+ receivedAt: record.receivedAt
4126
+ };
4127
+ if (typeof record.speaker === "number" && Number.isFinite(record.speaker)) {
4128
+ parsed.speaker = record.speaker;
4129
+ }
4130
+ cues.push(parsed);
4116
4131
  }
4117
4132
  return { ok: true, cues };
4118
4133
  } catch {
@@ -4185,6 +4200,10 @@ function LiveCaptionStack({
4185
4200
  }, [lastReceivedAt, prefersReduced, cues.length]);
4186
4201
  if (cues.length === 0) return null;
4187
4202
  const windowed = variant === "window";
4203
+ const distinctSpeakers = new Set(
4204
+ cues.map((cue) => cue.speaker).filter((speaker) => speaker != null)
4205
+ );
4206
+ const showTurns = distinctSpeakers.size >= 2;
4188
4207
  return /* @__PURE__ */ jsxRuntime.jsx(
4189
4208
  "div",
4190
4209
  {
@@ -4230,13 +4249,16 @@ function LiveCaptionStack({
4230
4249
  const fromEnd = cues.length - 1 - index;
4231
4250
  const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
4232
4251
  const newest = fromEnd === 0;
4252
+ const previous = cues[index - 1];
4253
+ const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
4233
4254
  return /* @__PURE__ */ jsxRuntime.jsxs(
4234
4255
  "span",
4235
4256
  {
4236
4257
  style: { opacity },
4237
4258
  "aria-live": newest ? "polite" : void 0,
4238
4259
  children: [
4239
- index > 0 ? " " : "",
4260
+ turnStart && index > 0 ? /* @__PURE__ */ jsxRuntime.jsx("br", {}) : index > 0 ? " " : "",
4261
+ turnStart ? "\u2013 " : "",
4240
4262
  cue.text
4241
4263
  ]
4242
4264
  },