@livo-tv/blocks 1.22.0 → 1.24.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
@@ -1227,6 +1227,7 @@ function LanguageSwitcher({
1227
1227
  const sizes = sizeClasses2[size];
1228
1228
  const shapeClass = shapeClasses2[shape];
1229
1229
  const reduceMotion = framerMotion.useReducedMotion();
1230
+ const layoutId = `${React9.useId()}-activeLanguage`;
1230
1231
  const defaultLabels2 = {
1231
1232
  language: labels.language ?? "Language"
1232
1233
  };
@@ -1302,7 +1303,7 @@ function LanguageSwitcher({
1302
1303
  framerMotion.motion.div,
1303
1304
  {
1304
1305
  className: cn("absolute inset-0 bg-secondary", shapeClass),
1305
- layoutId: "activeLanguage",
1306
+ layoutId,
1306
1307
  initial: { opacity: 0 },
1307
1308
  animate: { opacity: 1 },
1308
1309
  exit: { opacity: 0 },
@@ -4031,6 +4032,9 @@ function remainderAfterOverlap(previous, next) {
4031
4032
  }
4032
4033
  return null;
4033
4034
  }
4035
+ function liveCaptionRow(text, receivedAt, speaker) {
4036
+ return speaker == null ? { text, receivedAt } : { text, receivedAt, speaker };
4037
+ }
4034
4038
  function coalesceLiveCaptionCues(cues) {
4035
4039
  const out = [];
4036
4040
  for (const cue of cues) {
@@ -4038,26 +4042,31 @@ function coalesceLiveCaptionCues(cues) {
4038
4042
  if (!text) continue;
4039
4043
  const last = out[out.length - 1];
4040
4044
  if (!last) {
4041
- out.push({ text, receivedAt: cue.receivedAt });
4045
+ out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
4046
+ continue;
4047
+ }
4048
+ if (last.speaker !== cue.speaker && (last.speaker != null || cue.speaker != null)) {
4049
+ out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
4042
4050
  continue;
4043
4051
  }
4044
4052
  const lastNorm = normalizeLiveCaptionText(last.text);
4045
4053
  const nextNorm = normalizeLiveCaptionText(text);
4046
4054
  if (lastNorm === nextNorm) continue;
4047
4055
  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
- };
4056
+ out[out.length - 1] = liveCaptionRow(
4057
+ nextNorm.length >= lastNorm.length ? text : last.text,
4058
+ cue.receivedAt,
4059
+ cue.speaker ?? last.speaker
4060
+ );
4052
4061
  continue;
4053
4062
  }
4054
4063
  const remainder = remainderAfterOverlap(last.text, text);
4055
4064
  if (remainder !== null) {
4056
4065
  if (!remainder) continue;
4057
- out.push({ text: remainder, receivedAt: cue.receivedAt });
4066
+ out.push(liveCaptionRow(remainder, cue.receivedAt, cue.speaker));
4058
4067
  continue;
4059
4068
  }
4060
- out.push({ text, receivedAt: cue.receivedAt });
4069
+ out.push(liveCaptionRow(text, cue.receivedAt, cue.speaker));
4061
4070
  }
4062
4071
  return out;
4063
4072
  }
@@ -4112,7 +4121,14 @@ async function loadLiveCaptions(url) {
4112
4121
  if (typeof record.receivedAt !== "number" || !Number.isFinite(record.receivedAt)) {
4113
4122
  continue;
4114
4123
  }
4115
- cues.push({ text: record.text.trim(), receivedAt: record.receivedAt });
4124
+ const parsed = {
4125
+ text: record.text.trim(),
4126
+ receivedAt: record.receivedAt
4127
+ };
4128
+ if (typeof record.speaker === "number" && Number.isFinite(record.speaker)) {
4129
+ parsed.speaker = record.speaker;
4130
+ }
4131
+ cues.push(parsed);
4116
4132
  }
4117
4133
  return { ok: true, cues };
4118
4134
  } catch {
@@ -4185,6 +4201,10 @@ function LiveCaptionStack({
4185
4201
  }, [lastReceivedAt, prefersReduced, cues.length]);
4186
4202
  if (cues.length === 0) return null;
4187
4203
  const windowed = variant === "window";
4204
+ const distinctSpeakers = new Set(
4205
+ cues.map((cue) => cue.speaker).filter((speaker) => speaker != null)
4206
+ );
4207
+ const showTurns = distinctSpeakers.size >= 2;
4188
4208
  return /* @__PURE__ */ jsxRuntime.jsx(
4189
4209
  "div",
4190
4210
  {
@@ -4230,13 +4250,16 @@ function LiveCaptionStack({
4230
4250
  const fromEnd = cues.length - 1 - index;
4231
4251
  const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
4232
4252
  const newest = fromEnd === 0;
4253
+ const previous = cues[index - 1];
4254
+ const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
4233
4255
  return /* @__PURE__ */ jsxRuntime.jsxs(
4234
4256
  "span",
4235
4257
  {
4236
4258
  style: { opacity },
4237
4259
  "aria-live": newest ? "polite" : void 0,
4238
4260
  children: [
4239
- index > 0 ? " " : "",
4261
+ turnStart && index > 0 ? /* @__PURE__ */ jsxRuntime.jsx("br", {}) : index > 0 ? " " : "",
4262
+ turnStart ? "\u2013 " : "",
4240
4263
  cue.text
4241
4264
  ]
4242
4265
  },