@livo-tv/blocks 1.24.0 → 1.25.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
@@ -3903,19 +3903,28 @@ function useHlsPlayback({
3903
3903
  };
3904
3904
  }
3905
3905
 
3906
- // src/components/video/appleMobile.ts
3907
- function isAppleMobileDevice(nav = navigator) {
3908
- if (/iP(hone|ad|od)/.test(nav.userAgent)) return true;
3909
- return nav.platform === "MacIntel" && nav.maxTouchPoints > 1;
3910
- }
3911
-
3912
3906
  // src/components/video/captions.ts
3913
3907
  var CAPTION_LOCALES = ["en", "es", "pt"];
3914
3908
  var LIVE_CUE_EXTRA_LAG_MS = 2e3;
3915
3909
  var LIVE_STACK_MAX_CUES = 150;
3916
- var IOS_CAPTION_WINDOW_LINES = 3;
3917
- var IOS_CAPTION_CHARS_PER_LINE = 40;
3910
+ var CAPTION_CHARS_PER_SECOND = 17;
3911
+ var CAPTION_MIN_DWELL_MS = 1200;
3912
+ var CAPTION_MAX_DWELL_MS = 6e3;
3913
+ var CAPTION_RUSH_DWELL_MS = 2500;
3914
+ var CAPTION_MAX_CHARS_PER_LINE = 42;
3915
+ var CAPTION_COMPACT_CHARS_PER_LINE = 32;
3916
+ var CAPTION_MAX_LINES = 2;
3917
+ var CAPTION_BACKLOG_DROP = 8;
3918
+ var CAPTION_GAP_FILL_MS = 1e3;
3918
3919
  var LIVE_LAG_SPIKE_MS = 2500;
3920
+ var CAPTION_BREAK_PUNCT = /[.,;:?!]$/;
3921
+ var CAPTION_MIN_PUNCT_LINE = 8;
3922
+ var EMPTY_LIVE_CAPTION_PLAYOUT = {
3923
+ screen: null,
3924
+ hideAt: 0,
3925
+ cursor: 0,
3926
+ queue: []
3927
+ };
3919
3928
  function stabilizeLiveLagMs(previous, next) {
3920
3929
  if (previous == null || !Number.isFinite(previous)) return next;
3921
3930
  if (next <= previous) return next;
@@ -3976,26 +3985,148 @@ function parseCaptionVtt(text) {
3976
3985
  }
3977
3986
  return cues;
3978
3987
  }
3979
- function captionAtTime(cues, time, options) {
3980
- const matched = cues.find((cue) => time >= cue.start && time < cue.end) ?? null;
3981
- if (matched) return matched;
3982
- return null;
3988
+ function captionScreenRow(text, speaker) {
3989
+ return speaker == null ? { text } : { text, speaker };
3983
3990
  }
3984
- function vttCuesDueAt(cues, currentTime, cap = LIVE_STACK_MAX_CUES) {
3985
- if (!Number.isFinite(currentTime)) return [];
3986
- return cues.filter(
3987
- (cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && cue.start <= currentTime
3988
- ).sort((left, right) => left.start - right.start).slice(-Math.max(1, cap)).map((cue) => ({
3989
- text: cue.text.trim(),
3990
- receivedAt: cue.start * 1e3
3991
- }));
3991
+ function chunkLongWord(word, maxCharsPerLine) {
3992
+ if (word.length <= maxCharsPerLine) return [word];
3993
+ const parts = [];
3994
+ for (let index = 0; index < word.length; index += maxCharsPerLine) {
3995
+ parts.push(word.slice(index, index + maxCharsPerLine));
3996
+ }
3997
+ return parts;
3998
+ }
3999
+ function wrapCaptionLines(text, maxCharsPerLine) {
4000
+ const tokens = text.split(" ").filter(Boolean).flatMap((word) => chunkLongWord(word, maxCharsPerLine));
4001
+ const lines = [];
4002
+ let index = 0;
4003
+ while (index < tokens.length) {
4004
+ let end = index;
4005
+ let length = 0;
4006
+ while (end < tokens.length) {
4007
+ const added = tokens[end].length + (end > index ? 1 : 0);
4008
+ if (length + added > maxCharsPerLine && end > index) break;
4009
+ length += added;
4010
+ end += 1;
4011
+ }
4012
+ let breakAt = end;
4013
+ if (end < tokens.length) {
4014
+ for (let cursor = end - 1; cursor > index; cursor -= 1) {
4015
+ if (!CAPTION_BREAK_PUNCT.test(tokens[cursor])) continue;
4016
+ const firstLen = tokens.slice(index, cursor + 1).join(" ").length;
4017
+ if (firstLen >= Math.min(CAPTION_MIN_PUNCT_LINE, maxCharsPerLine)) {
4018
+ breakAt = cursor + 1;
4019
+ }
4020
+ break;
4021
+ }
4022
+ }
4023
+ lines.push(tokens.slice(index, breakAt).join(" "));
4024
+ index = breakAt;
4025
+ }
4026
+ return lines;
4027
+ }
4028
+ function balanceCaptionLines(lines, maxCharsPerLine) {
4029
+ const next = [...lines];
4030
+ for (let index = 0; index + 1 < next.length; index += CAPTION_MAX_LINES) {
4031
+ const left = next[index].split(" ");
4032
+ const right = next[index + 1].split(" ");
4033
+ if (right.length !== 1 || left.length < 3) continue;
4034
+ const moved = left[left.length - 1];
4035
+ const newRight = `${moved} ${right[0]}`;
4036
+ if (newRight.length > maxCharsPerLine) continue;
4037
+ next[index] = left.slice(0, -1).join(" ");
4038
+ next[index + 1] = newRight;
4039
+ }
4040
+ return next;
3992
4041
  }
3993
- function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
3994
- if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return [];
3995
- const threshold = lagMs + extraLagMs;
3996
- return cues.filter(
3997
- (cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
3998
- ).sort((left, right) => left.receivedAt - right.receivedAt);
4042
+ function splitCaptionScreens(text, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
4043
+ const trimmed = text.trim().replace(/\s+/g, " ");
4044
+ if (!trimmed) return [];
4045
+ const lines = balanceCaptionLines(
4046
+ wrapCaptionLines(trimmed, maxCharsPerLine),
4047
+ maxCharsPerLine
4048
+ );
4049
+ const screens = [];
4050
+ for (let index = 0; index < lines.length; index += CAPTION_MAX_LINES) {
4051
+ screens.push(lines.slice(index, index + CAPTION_MAX_LINES).join("\n"));
4052
+ }
4053
+ return screens;
4054
+ }
4055
+ function captionDwellMs(text, backlog = 0) {
4056
+ const chars = text.replace(/\s+/g, " ").trim().length;
4057
+ const raw = chars / CAPTION_CHARS_PER_SECOND * 1e3;
4058
+ const max = backlog > 0 ? CAPTION_RUSH_DWELL_MS : CAPTION_MAX_DWELL_MS;
4059
+ return Math.min(max, Math.max(CAPTION_MIN_DWELL_MS, raw));
4060
+ }
4061
+ function advanceLiveCaptionPlayout(state, cues, now, lagMs, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
4062
+ let screen = state.screen;
4063
+ let hideAt = state.hideAt;
4064
+ let cursor = state.cursor;
4065
+ let queue = state.queue.slice();
4066
+ if (lagMs != null && Number.isFinite(lagMs) && lagMs >= 0) {
4067
+ const threshold = lagMs + LIVE_CUE_EXTRA_LAG_MS;
4068
+ const incoming = cues.filter(
4069
+ (cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.receivedAt) && cue.receivedAt > cursor && now - cue.receivedAt >= threshold
4070
+ ).sort((left, right) => left.receivedAt - right.receivedAt);
4071
+ for (const cue of incoming) {
4072
+ for (const text of splitCaptionScreens(cue.text, maxCharsPerLine)) {
4073
+ queue.push(captionScreenRow(text, cue.speaker));
4074
+ }
4075
+ cursor = cue.receivedAt;
4076
+ }
4077
+ if (queue.length > CAPTION_BACKLOG_DROP) {
4078
+ queue = queue.slice(queue.length - CAPTION_BACKLOG_DROP);
4079
+ }
4080
+ }
4081
+ if (now >= hideAt) {
4082
+ const next = queue.shift();
4083
+ if (next) {
4084
+ screen = next;
4085
+ hideAt = now + captionDwellMs(next.text, queue.length);
4086
+ } else {
4087
+ screen = null;
4088
+ }
4089
+ }
4090
+ return { screen, hideAt, cursor, queue };
4091
+ }
4092
+ function cueEndWithGapFill(cues, index) {
4093
+ const cue = cues[index];
4094
+ if (!cue) return 0;
4095
+ const next = cues[index + 1];
4096
+ if (!next || !Number.isFinite(next.start)) return cue.end;
4097
+ const gapMs = (next.start - cue.end) * 1e3;
4098
+ if (gapMs > 0 && gapMs < CAPTION_GAP_FILL_MS) return next.start;
4099
+ return cue.end;
4100
+ }
4101
+ function captionScreenAtTime(cues, time, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
4102
+ if (!Number.isFinite(time)) return null;
4103
+ const ordered = cues.filter(
4104
+ (cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && Number.isFinite(cue.end)
4105
+ ).sort((left, right) => left.start - right.start);
4106
+ for (let index = 0; index < ordered.length; index += 1) {
4107
+ const cue = ordered[index];
4108
+ const end = cueEndWithGapFill(ordered, index);
4109
+ if (time < cue.start || time >= end) continue;
4110
+ const screens = splitCaptionScreens(cue.text, maxCharsPerLine);
4111
+ if (screens.length === 0) return null;
4112
+ const weights = screens.map(
4113
+ (text) => Math.max(1, text.replace(/\s+/g, "").length)
4114
+ );
4115
+ const total = weights.reduce((sum, weight) => sum + weight, 0);
4116
+ const duration = Math.max(end - cue.start, 0);
4117
+ let cursor = cue.start;
4118
+ for (let screenIndex = 0; screenIndex < screens.length; screenIndex += 1) {
4119
+ const isLast = screenIndex === screens.length - 1;
4120
+ const slice = isLast ? end - cursor : duration * (weights[screenIndex] / total);
4121
+ const sliceEnd = cursor + slice;
4122
+ if (time >= cursor && time < sliceEnd) {
4123
+ return captionScreenRow(screens[screenIndex]);
4124
+ }
4125
+ cursor = sliceEnd;
4126
+ }
4127
+ return captionScreenRow(screens[screens.length - 1]);
4128
+ }
4129
+ return null;
3999
4130
  }
4000
4131
  var LIVE_OVERLAP_MIN_WORDS = 4;
4001
4132
  function normalizeLiveCaptionText(text) {
@@ -4070,17 +4201,6 @@ function coalesceLiveCaptionCues(cues) {
4070
4201
  }
4071
4202
  return out;
4072
4203
  }
4073
- function lastLiveCaptionWindow(cues, maxCues = IOS_CAPTION_WINDOW_LINES) {
4074
- return cues.slice(-Math.max(1, maxCues));
4075
- }
4076
- function lastCaptionLines(text, lines = IOS_CAPTION_WINDOW_LINES, charsPerLine = IOS_CAPTION_CHARS_PER_LINE) {
4077
- const trimmed = text.trim().replace(/\s+/g, " ");
4078
- const maxChars = Math.max(1, lines) * Math.max(1, charsPerLine);
4079
- if (trimmed.length <= maxChars) return trimmed;
4080
- const slice = trimmed.slice(-maxChars);
4081
- const space = slice.indexOf(" ");
4082
- return (space > 0 ? slice.slice(space + 1) : slice).trim();
4083
- }
4084
4204
  function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
4085
4205
  const map = /* @__PURE__ */ new Map();
4086
4206
  for (const cue of existing) {
@@ -4156,121 +4276,29 @@ function isEmbeddedWindow(win = window) {
4156
4276
  return true;
4157
4277
  }
4158
4278
  }
4159
- var NEAR_BOTTOM_PX = 24;
4160
- function LiveCaptionStack({
4161
- cues,
4162
- latestLabel,
4163
- variant = "scroll"
4164
- }) {
4165
- const scrollerRef = React9__namespace.useRef(null);
4166
- const followRef = React9__namespace.useRef(true);
4167
- const ignoreScrollRef = React9__namespace.useRef(false);
4168
- const [following, setFollowing] = React9__namespace.useState(true);
4169
- const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
4170
- const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
4171
- const scrollToLatest = React9__namespace.useCallback(() => {
4172
- const scroller = scrollerRef.current;
4173
- if (!scroller) return;
4174
- ignoreScrollRef.current = true;
4175
- scroller.scrollTo({
4176
- top: scroller.scrollHeight,
4177
- behavior: prefersReduced ? "auto" : "smooth"
4178
- });
4179
- followRef.current = true;
4180
- setFollowing(true);
4181
- window.requestAnimationFrame(() => {
4182
- window.requestAnimationFrame(() => {
4183
- ignoreScrollRef.current = false;
4184
- });
4185
- });
4186
- }, [prefersReduced]);
4279
+ function CaptionOverlay({ screen }) {
4280
+ const lastSpeakerRef = React9__namespace.useRef(void 0);
4281
+ const lastSpeaker = lastSpeakerRef.current;
4187
4282
  React9__namespace.useLayoutEffect(() => {
4188
- if (!followRef.current) return;
4189
- const scroller = scrollerRef.current;
4190
- if (!scroller) return;
4191
- ignoreScrollRef.current = true;
4192
- scroller.scrollTo({
4193
- top: scroller.scrollHeight,
4194
- behavior: prefersReduced ? "auto" : "smooth"
4195
- });
4196
- window.requestAnimationFrame(() => {
4197
- window.requestAnimationFrame(() => {
4198
- ignoreScrollRef.current = false;
4199
- });
4200
- });
4201
- }, [lastReceivedAt, prefersReduced, cues.length]);
4202
- if (cues.length === 0) return null;
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;
4283
+ if (screen?.speaker != null) lastSpeakerRef.current = screen.speaker;
4284
+ }, [screen]);
4285
+ if (!screen) return null;
4286
+ const turnDash = screen.speaker != null && lastSpeaker != null && screen.speaker !== lastSpeaker;
4287
+ const text = turnDash ? `\u2013 ${screen.text}` : screen.text;
4208
4288
  return /* @__PURE__ */ jsxRuntime.jsx(
4209
4289
  "div",
4210
4290
  {
4211
4291
  className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
4212
4292
  "data-slot": "video-captions",
4213
- "data-caption-mode": variant,
4214
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative w-full max-w-[90%]", children: [
4215
- !windowed && !following && /* @__PURE__ */ jsxRuntime.jsx(
4216
- "button",
4217
- {
4218
- type: "button",
4219
- className: "pointer-events-auto absolute -top-8 right-0 rounded-sm bg-black/70 px-2 py-0.5 text-xs font-medium text-white shadow-sm",
4220
- onClick: scrollToLatest,
4221
- children: latestLabel
4222
- }
4223
- ),
4224
- /* @__PURE__ */ jsxRuntime.jsx(
4225
- "div",
4226
- {
4227
- ref: windowed ? void 0 : scrollerRef,
4228
- role: "log",
4229
- "aria-relevant": "additions",
4230
- className: cn(
4231
- "rounded-sm bg-black/70 px-3 py-1.5 text-[length:clamp(10px,2.6cqh,0.875rem)] font-medium text-white shadow-sm [-webkit-text-size-adjust:100%] [text-size-adjust:100%]",
4232
- windowed ? "overflow-hidden" : "pointer-events-auto max-h-[min(4.5rem,18cqh)] overflow-x-hidden overflow-y-auto"
4233
- ),
4234
- onScroll: windowed ? void 0 : (event) => {
4235
- if (ignoreScrollRef.current) return;
4236
- const scroller = event.currentTarget;
4237
- const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
4238
- followRef.current = nearBottom;
4239
- setFollowing(nearBottom);
4240
- },
4241
- children: /* @__PURE__ */ jsxRuntime.jsx(
4242
- "p",
4243
- {
4244
- className: cn(
4245
- "text-justify [text-align-last:left] leading-snug break-words",
4246
- windowed && "line-clamp-3",
4247
- !prefersReduced && "transition-opacity"
4248
- ),
4249
- children: cues.map((cue, index) => {
4250
- const fromEnd = cues.length - 1 - index;
4251
- const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
4252
- const newest = fromEnd === 0;
4253
- const previous = cues[index - 1];
4254
- const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
4255
- return /* @__PURE__ */ jsxRuntime.jsxs(
4256
- "span",
4257
- {
4258
- style: { opacity },
4259
- "aria-live": newest ? "polite" : void 0,
4260
- children: [
4261
- turnStart && index > 0 ? /* @__PURE__ */ jsxRuntime.jsx("br", {}) : index > 0 ? " " : "",
4262
- turnStart ? "\u2013 " : "",
4263
- cue.text
4264
- ]
4265
- },
4266
- cue.receivedAt
4267
- );
4268
- })
4269
- }
4270
- )
4271
- }
4272
- )
4273
- ] })
4293
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4294
+ "p",
4295
+ {
4296
+ role: "status",
4297
+ "aria-live": "polite",
4298
+ className: "line-clamp-2 max-w-[90%] whitespace-pre-line break-words rounded-sm bg-black/70 px-3 py-1.5 text-center text-[length:clamp(10px,2.6cqh,0.875rem)] font-medium text-white shadow-sm [-webkit-text-size-adjust:100%] [text-size-adjust:100%]",
4299
+ children: text
4300
+ }
4301
+ )
4274
4302
  }
4275
4303
  );
4276
4304
  }
@@ -4278,9 +4306,6 @@ function LiveCaptionStack({
4278
4306
  // src/components/video/nativeCaptionTrack.ts
4279
4307
  var NATIVE_CAPTION_HOLD_S = 4;
4280
4308
  var NATIVE_SUBTITLE_KIND = "subtitles";
4281
- function joinCaptionTexts(cues) {
4282
- return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
4283
- }
4284
4309
  function clearNativeCaptionCues(track) {
4285
4310
  const cues = track.cues;
4286
4311
  if (!cues) return;
@@ -4330,12 +4355,13 @@ function ensureLiveSubtitleTracks(video, labels) {
4330
4355
  return track;
4331
4356
  });
4332
4357
  }
4333
- function syncNativeCaptionCue(video, track, text) {
4358
+ function syncNativeCaptionCue(video, track, text, holdSeconds = NATIVE_CAPTION_HOLD_S) {
4334
4359
  clearNativeCaptionCues(track);
4335
4360
  const trimmed = text.trim();
4336
4361
  if (!trimmed) return;
4337
4362
  const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
4338
- track.addCue(new VTTCue(start, start + NATIVE_CAPTION_HOLD_S, trimmed));
4363
+ const hold = Number.isFinite(holdSeconds) ? Math.max(0.2, holdSeconds) : NATIVE_CAPTION_HOLD_S;
4364
+ track.addCue(new VTTCue(start, start + hold, trimmed));
4339
4365
  }
4340
4366
  function zeroAnchorNativeTrackCues(track) {
4341
4367
  const list = track.cues;
@@ -4414,6 +4440,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
4414
4440
  var CONTROLS_HIDE_MS = 3e3;
4415
4441
  var LIVE_EDGE_THRESHOLD_S = 8;
4416
4442
  var SEEK_STEP_S = 5;
4443
+ var LIVE_CAPTION_PLAYOUT_MS = 250;
4417
4444
  var COMPACT_CHROME_PX = 640;
4418
4445
  var VIDEO_MEDIA_STYLE = `
4419
4446
  .livo-video-player-media::-webkit-media-controls-start-playback-button {
@@ -4525,14 +4552,22 @@ function VideoPlayer({
4525
4552
  const [captionLocale, setCaptionLocale] = React9__namespace.useState(defaultCaptionLocale ?? "off");
4526
4553
  const [captionCues, setCaptionCues] = React9__namespace.useState([]);
4527
4554
  const [liveCaptionCues, setLiveCaptionCues] = React9__namespace.useState([]);
4555
+ const [livePlayout, setLivePlayout] = React9__namespace.useState(
4556
+ EMPTY_LIVE_CAPTION_PLAYOUT
4557
+ );
4528
4558
  const [liveLagMs, setLiveLagMs] = React9__namespace.useState(null);
4529
4559
  const [behindLive, setBehindLive] = React9__namespace.useState(false);
4530
4560
  const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9__namespace.useState(false);
4531
4561
  const [embedded, setEmbedded] = React9__namespace.useState(false);
4532
4562
  const [cssFullscreen, setCssFullscreen] = React9__namespace.useState(false);
4533
- const [appleMobile, setAppleMobile] = React9__namespace.useState(false);
4534
4563
  const [webkitNativeFs, setWebkitNativeFs] = React9__namespace.useState(false);
4535
4564
  const hideTimerRef = React9__namespace.useRef(null);
4565
+ const liveCaptionCuesRef = React9__namespace.useRef(liveCaptionCues);
4566
+ const liveLagMsRef = React9__namespace.useRef(liveLagMs);
4567
+ const compactChromeRef = React9__namespace.useRef(compactChrome);
4568
+ liveCaptionCuesRef.current = liveCaptionCues;
4569
+ liveLagMsRef.current = liveLagMs;
4570
+ compactChromeRef.current = compactChrome;
4536
4571
  cssFullscreenRef.current = cssFullscreen;
4537
4572
  captionLocaleRef.current = captionLocale;
4538
4573
  React9__namespace.useEffect(() => {
@@ -4608,7 +4643,6 @@ function VideoPlayer({
4608
4643
  }, [paused, videoRef, isPlaying]);
4609
4644
  React9__namespace.useEffect(() => {
4610
4645
  setEmbedded(isEmbeddedWindow());
4611
- setAppleMobile(isAppleMobileDevice());
4612
4646
  setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
4613
4647
  videoRef.current?.setAttribute("x-webkit-airplay", "allow");
4614
4648
  videoRef.current?.setAttribute("webkit-playsinline", "");
@@ -4749,12 +4783,28 @@ function VideoPlayer({
4749
4783
  window.clearInterval(timer);
4750
4784
  };
4751
4785
  }, [captionLocale, liveCaptionsBaseUrl, src]);
4752
- const endedLiveReplay = !liveCaptionsBaseUrl && isLivePlaylistSrc(src);
4753
- const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
4754
- liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
4755
- ) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
4756
- const captionStackCues = appleMobile ? lastLiveCaptionWindow(liveDueCues) : liveDueCues;
4757
- const activeCaption = liveCaptionsBaseUrl || endedLiveReplay ? null : captionAtTime(captionCues, currentTime);
4786
+ React9__namespace.useEffect(() => {
4787
+ if (!liveCaptionsBaseUrl || captionLocale === "off") {
4788
+ setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
4789
+ return;
4790
+ }
4791
+ const tick = () => {
4792
+ setLivePlayout(
4793
+ (prev) => advanceLiveCaptionPlayout(
4794
+ prev,
4795
+ coalesceLiveCaptionCues(liveCaptionCuesRef.current),
4796
+ Date.now(),
4797
+ liveLagMsRef.current,
4798
+ compactChromeRef.current ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE
4799
+ )
4800
+ );
4801
+ };
4802
+ tick();
4803
+ const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
4804
+ return () => window.clearInterval(timer);
4805
+ }, [liveCaptionsBaseUrl, captionLocale]);
4806
+ const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
4807
+ const captionScreen = liveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
4758
4808
  React9__namespace.useEffect(() => {
4759
4809
  const video = videoRef.current;
4760
4810
  if (!video || !liveCaptionsBaseUrl) return;
@@ -4801,12 +4851,14 @@ function VideoPlayer({
4801
4851
  if (!video || captionLocale === "off" || !liveCaptionsBaseUrl) return;
4802
4852
  const track = findSubtitleTrack(video, captionLocale);
4803
4853
  if (!track) return;
4854
+ const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
4804
4855
  syncNativeCaptionCue(
4805
4856
  video,
4806
4857
  track,
4807
- lastCaptionLines(joinCaptionTexts(captionStackCues))
4858
+ livePlayout.screen?.text ?? "",
4859
+ remaining
4808
4860
  );
4809
- }, [captionStackCues, captionLocale, liveCaptionsBaseUrl]);
4861
+ }, [livePlayout, captionLocale, liveCaptionsBaseUrl]);
4810
4862
  function togglePlay() {
4811
4863
  const video = videoRef.current;
4812
4864
  if (!video) return;
@@ -5072,22 +5124,7 @@ function VideoPlayer({
5072
5124
  ] }),
5073
5125
  typeof stats?.viewers === "number" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rounded bg-black/60 px-2 py-0.5 text-xs", children: t.formatViewers ? t.formatViewers(stats.viewers) : `\u{1F441} ${stats.viewers}` })
5074
5126
  ] }),
5075
- (liveCaptionsBaseUrl || endedLiveReplay) && captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsxRuntime.jsx(
5076
- LiveCaptionStack,
5077
- {
5078
- cues: captionStackCues,
5079
- latestLabel: t.captionsLatest,
5080
- variant: appleMobile ? "window" : "scroll"
5081
- }
5082
- ),
5083
- !liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsxRuntime.jsx(
5084
- "div",
5085
- {
5086
- className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
5087
- "data-slot": "video-captions",
5088
- children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "line-clamp-2 max-w-[90%] break-words rounded-sm bg-black/70 px-3 py-1.5 text-center text-[length:clamp(10px,2.6cqh,0.875rem)] font-medium text-white shadow-sm [-webkit-text-size-adjust:100%] [text-size-adjust:100%]", children: activeCaption.text })
5089
- }
5090
- ),
5127
+ captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsxRuntime.jsx(CaptionOverlay, { screen: captionScreen }),
5091
5128
  active && /* @__PURE__ */ jsxRuntime.jsxs(
5092
5129
  "div",
5093
5130
  {