@livo-tv/blocks 1.24.0 → 1.25.1

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;
@@ -3925,22 +3934,6 @@ function stabilizeLiveLagMs(previous, next) {
3925
3934
  function isCaptionLocale(value) {
3926
3935
  return CAPTION_LOCALES.includes(value);
3927
3936
  }
3928
- function isLivePlaylistSrc(src) {
3929
- return /\/live\//i.test(src);
3930
- }
3931
- function zeroAnchorCaptionCues(cues) {
3932
- if (cues.length === 0) return cues;
3933
- let origin = Number.POSITIVE_INFINITY;
3934
- for (const cue of cues) {
3935
- if (Number.isFinite(cue.start) && cue.start < origin) origin = cue.start;
3936
- }
3937
- if (!Number.isFinite(origin) || origin <= 0) return cues;
3938
- return cues.map((cue) => ({
3939
- ...cue,
3940
- start: Math.max(0, cue.start - origin),
3941
- end: Math.max(0, cue.end - origin)
3942
- }));
3943
- }
3944
3937
  function captionsVttUrlFromPlayback(src, locale) {
3945
3938
  const trimmed = src.trim();
3946
3939
  if (!trimmed) return null;
@@ -3976,26 +3969,148 @@ function parseCaptionVtt(text) {
3976
3969
  }
3977
3970
  return cues;
3978
3971
  }
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;
3972
+ function captionScreenRow(text, speaker) {
3973
+ return speaker == null ? { text } : { text, speaker };
3983
3974
  }
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
- }));
3975
+ function chunkLongWord(word, maxCharsPerLine) {
3976
+ if (word.length <= maxCharsPerLine) return [word];
3977
+ const parts = [];
3978
+ for (let index = 0; index < word.length; index += maxCharsPerLine) {
3979
+ parts.push(word.slice(index, index + maxCharsPerLine));
3980
+ }
3981
+ return parts;
3982
+ }
3983
+ function wrapCaptionLines(text, maxCharsPerLine) {
3984
+ const tokens = text.split(" ").filter(Boolean).flatMap((word) => chunkLongWord(word, maxCharsPerLine));
3985
+ const lines = [];
3986
+ let index = 0;
3987
+ while (index < tokens.length) {
3988
+ let end = index;
3989
+ let length = 0;
3990
+ while (end < tokens.length) {
3991
+ const added = tokens[end].length + (end > index ? 1 : 0);
3992
+ if (length + added > maxCharsPerLine && end > index) break;
3993
+ length += added;
3994
+ end += 1;
3995
+ }
3996
+ let breakAt = end;
3997
+ if (end < tokens.length) {
3998
+ for (let cursor = end - 1; cursor > index; cursor -= 1) {
3999
+ if (!CAPTION_BREAK_PUNCT.test(tokens[cursor])) continue;
4000
+ const firstLen = tokens.slice(index, cursor + 1).join(" ").length;
4001
+ if (firstLen >= Math.min(CAPTION_MIN_PUNCT_LINE, maxCharsPerLine)) {
4002
+ breakAt = cursor + 1;
4003
+ }
4004
+ break;
4005
+ }
4006
+ }
4007
+ lines.push(tokens.slice(index, breakAt).join(" "));
4008
+ index = breakAt;
4009
+ }
4010
+ return lines;
4011
+ }
4012
+ function balanceCaptionLines(lines, maxCharsPerLine) {
4013
+ const next = [...lines];
4014
+ for (let index = 0; index + 1 < next.length; index += CAPTION_MAX_LINES) {
4015
+ const left = next[index].split(" ");
4016
+ const right = next[index + 1].split(" ");
4017
+ if (right.length !== 1 || left.length < 3) continue;
4018
+ const moved = left[left.length - 1];
4019
+ const newRight = `${moved} ${right[0]}`;
4020
+ if (newRight.length > maxCharsPerLine) continue;
4021
+ next[index] = left.slice(0, -1).join(" ");
4022
+ next[index + 1] = newRight;
4023
+ }
4024
+ return next;
3992
4025
  }
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);
4026
+ function splitCaptionScreens(text, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
4027
+ const trimmed = text.trim().replace(/\s+/g, " ");
4028
+ if (!trimmed) return [];
4029
+ const lines = balanceCaptionLines(
4030
+ wrapCaptionLines(trimmed, maxCharsPerLine),
4031
+ maxCharsPerLine
4032
+ );
4033
+ const screens = [];
4034
+ for (let index = 0; index < lines.length; index += CAPTION_MAX_LINES) {
4035
+ screens.push(lines.slice(index, index + CAPTION_MAX_LINES).join("\n"));
4036
+ }
4037
+ return screens;
4038
+ }
4039
+ function captionDwellMs(text, backlog = 0) {
4040
+ const chars = text.replace(/\s+/g, " ").trim().length;
4041
+ const raw = chars / CAPTION_CHARS_PER_SECOND * 1e3;
4042
+ const max = backlog > 0 ? CAPTION_RUSH_DWELL_MS : CAPTION_MAX_DWELL_MS;
4043
+ return Math.min(max, Math.max(CAPTION_MIN_DWELL_MS, raw));
4044
+ }
4045
+ function advanceLiveCaptionPlayout(state, cues, now, lagMs, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
4046
+ let screen = state.screen;
4047
+ let hideAt = state.hideAt;
4048
+ let cursor = state.cursor;
4049
+ let queue = state.queue.slice();
4050
+ if (lagMs != null && Number.isFinite(lagMs) && lagMs >= 0) {
4051
+ const threshold = lagMs + LIVE_CUE_EXTRA_LAG_MS;
4052
+ const incoming = cues.filter(
4053
+ (cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.receivedAt) && cue.receivedAt > cursor && now - cue.receivedAt >= threshold
4054
+ ).sort((left, right) => left.receivedAt - right.receivedAt);
4055
+ for (const cue of incoming) {
4056
+ for (const text of splitCaptionScreens(cue.text, maxCharsPerLine)) {
4057
+ queue.push(captionScreenRow(text, cue.speaker));
4058
+ }
4059
+ cursor = cue.receivedAt;
4060
+ }
4061
+ if (queue.length > CAPTION_BACKLOG_DROP) {
4062
+ queue = queue.slice(queue.length - CAPTION_BACKLOG_DROP);
4063
+ }
4064
+ }
4065
+ if (now >= hideAt) {
4066
+ const next = queue.shift();
4067
+ if (next) {
4068
+ screen = next;
4069
+ hideAt = now + captionDwellMs(next.text, queue.length);
4070
+ } else {
4071
+ screen = null;
4072
+ }
4073
+ }
4074
+ return { screen, hideAt, cursor, queue };
4075
+ }
4076
+ function cueEndWithGapFill(cues, index) {
4077
+ const cue = cues[index];
4078
+ if (!cue) return 0;
4079
+ const next = cues[index + 1];
4080
+ if (!next || !Number.isFinite(next.start)) return cue.end;
4081
+ const gapMs = (next.start - cue.end) * 1e3;
4082
+ if (gapMs > 0 && gapMs < CAPTION_GAP_FILL_MS) return next.start;
4083
+ return cue.end;
4084
+ }
4085
+ function captionScreenAtTime(cues, time, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
4086
+ if (!Number.isFinite(time)) return null;
4087
+ const ordered = cues.filter(
4088
+ (cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && Number.isFinite(cue.end)
4089
+ ).sort((left, right) => left.start - right.start);
4090
+ for (let index = 0; index < ordered.length; index += 1) {
4091
+ const cue = ordered[index];
4092
+ const end = cueEndWithGapFill(ordered, index);
4093
+ if (time < cue.start || time >= end) continue;
4094
+ const screens = splitCaptionScreens(cue.text, maxCharsPerLine);
4095
+ if (screens.length === 0) return null;
4096
+ const weights = screens.map(
4097
+ (text) => Math.max(1, text.replace(/\s+/g, "").length)
4098
+ );
4099
+ const total = weights.reduce((sum, weight) => sum + weight, 0);
4100
+ const duration = Math.max(end - cue.start, 0);
4101
+ let cursor = cue.start;
4102
+ for (let screenIndex = 0; screenIndex < screens.length; screenIndex += 1) {
4103
+ const isLast = screenIndex === screens.length - 1;
4104
+ const slice = isLast ? end - cursor : duration * (weights[screenIndex] / total);
4105
+ const sliceEnd = cursor + slice;
4106
+ if (time >= cursor && time < sliceEnd) {
4107
+ return captionScreenRow(screens[screenIndex]);
4108
+ }
4109
+ cursor = sliceEnd;
4110
+ }
4111
+ return captionScreenRow(screens[screens.length - 1]);
4112
+ }
4113
+ return null;
3999
4114
  }
4000
4115
  var LIVE_OVERLAP_MIN_WORDS = 4;
4001
4116
  function normalizeLiveCaptionText(text) {
@@ -4070,17 +4185,6 @@ function coalesceLiveCaptionCues(cues) {
4070
4185
  }
4071
4186
  return out;
4072
4187
  }
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
4188
  function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
4085
4189
  const map = /* @__PURE__ */ new Map();
4086
4190
  for (const cue of existing) {
@@ -4156,121 +4260,29 @@ function isEmbeddedWindow(win = window) {
4156
4260
  return true;
4157
4261
  }
4158
4262
  }
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]);
4263
+ function CaptionOverlay({ screen }) {
4264
+ const lastSpeakerRef = React9__namespace.useRef(void 0);
4265
+ const lastSpeaker = lastSpeakerRef.current;
4187
4266
  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;
4267
+ if (screen?.speaker != null) lastSpeakerRef.current = screen.speaker;
4268
+ }, [screen]);
4269
+ if (!screen) return null;
4270
+ const turnDash = screen.speaker != null && lastSpeaker != null && screen.speaker !== lastSpeaker;
4271
+ const text = turnDash ? `\u2013 ${screen.text}` : screen.text;
4208
4272
  return /* @__PURE__ */ jsxRuntime.jsx(
4209
4273
  "div",
4210
4274
  {
4211
4275
  className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
4212
4276
  "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
- ] })
4277
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4278
+ "p",
4279
+ {
4280
+ role: "status",
4281
+ "aria-live": "polite",
4282
+ 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%]",
4283
+ children: text
4284
+ }
4285
+ )
4274
4286
  }
4275
4287
  );
4276
4288
  }
@@ -4278,9 +4290,6 @@ function LiveCaptionStack({
4278
4290
  // src/components/video/nativeCaptionTrack.ts
4279
4291
  var NATIVE_CAPTION_HOLD_S = 4;
4280
4292
  var NATIVE_SUBTITLE_KIND = "subtitles";
4281
- function joinCaptionTexts(cues) {
4282
- return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
4283
- }
4284
4293
  function clearNativeCaptionCues(track) {
4285
4294
  const cues = track.cues;
4286
4295
  if (!cues) return;
@@ -4330,38 +4339,13 @@ function ensureLiveSubtitleTracks(video, labels) {
4330
4339
  return track;
4331
4340
  });
4332
4341
  }
4333
- function syncNativeCaptionCue(video, track, text) {
4342
+ function syncNativeCaptionCue(video, track, text, holdSeconds = NATIVE_CAPTION_HOLD_S) {
4334
4343
  clearNativeCaptionCues(track);
4335
4344
  const trimmed = text.trim();
4336
4345
  if (!trimmed) return;
4337
4346
  const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
4338
- track.addCue(new VTTCue(start, start + NATIVE_CAPTION_HOLD_S, trimmed));
4339
- }
4340
- function zeroAnchorNativeTrackCues(track) {
4341
- const list = track.cues;
4342
- if (!list || list.length === 0) return;
4343
- let origin = Number.POSITIVE_INFINITY;
4344
- for (let index = 0; index < list.length; index += 1) {
4345
- const cue = list[index];
4346
- if (cue && Number.isFinite(cue.startTime) && cue.startTime < origin) {
4347
- origin = cue.startTime;
4348
- }
4349
- }
4350
- if (!Number.isFinite(origin) || origin <= 0) return;
4351
- const next = [];
4352
- for (let index = 0; index < list.length; index += 1) {
4353
- const cue = list[index];
4354
- if (!(cue instanceof VTTCue)) continue;
4355
- next.push(
4356
- new VTTCue(
4357
- Math.max(0, cue.startTime - origin),
4358
- Math.max(0, cue.endTime - origin),
4359
- cue.text
4360
- )
4361
- );
4362
- }
4363
- clearNativeCaptionCues(track);
4364
- for (const cue of next) track.addCue(cue);
4347
+ const hold = Number.isFinite(holdSeconds) ? Math.max(0.2, holdSeconds) : NATIVE_CAPTION_HOLD_S;
4348
+ track.addCue(new VTTCue(start, start + hold, trimmed));
4365
4349
  }
4366
4350
  function listenTextTracksChange(tracks, onChange) {
4367
4351
  if (typeof tracks.addEventListener === "function") {
@@ -4414,6 +4398,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
4414
4398
  var CONTROLS_HIDE_MS = 3e3;
4415
4399
  var LIVE_EDGE_THRESHOLD_S = 8;
4416
4400
  var SEEK_STEP_S = 5;
4401
+ var LIVE_CAPTION_PLAYOUT_MS = 250;
4417
4402
  var COMPACT_CHROME_PX = 640;
4418
4403
  var VIDEO_MEDIA_STYLE = `
4419
4404
  .livo-video-player-media::-webkit-media-controls-start-playback-button {
@@ -4525,14 +4510,22 @@ function VideoPlayer({
4525
4510
  const [captionLocale, setCaptionLocale] = React9__namespace.useState(defaultCaptionLocale ?? "off");
4526
4511
  const [captionCues, setCaptionCues] = React9__namespace.useState([]);
4527
4512
  const [liveCaptionCues, setLiveCaptionCues] = React9__namespace.useState([]);
4513
+ const [livePlayout, setLivePlayout] = React9__namespace.useState(
4514
+ EMPTY_LIVE_CAPTION_PLAYOUT
4515
+ );
4528
4516
  const [liveLagMs, setLiveLagMs] = React9__namespace.useState(null);
4529
4517
  const [behindLive, setBehindLive] = React9__namespace.useState(false);
4530
4518
  const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9__namespace.useState(false);
4531
4519
  const [embedded, setEmbedded] = React9__namespace.useState(false);
4532
4520
  const [cssFullscreen, setCssFullscreen] = React9__namespace.useState(false);
4533
- const [appleMobile, setAppleMobile] = React9__namespace.useState(false);
4534
4521
  const [webkitNativeFs, setWebkitNativeFs] = React9__namespace.useState(false);
4535
4522
  const hideTimerRef = React9__namespace.useRef(null);
4523
+ const liveCaptionCuesRef = React9__namespace.useRef(liveCaptionCues);
4524
+ const liveLagMsRef = React9__namespace.useRef(liveLagMs);
4525
+ const compactChromeRef = React9__namespace.useRef(compactChrome);
4526
+ liveCaptionCuesRef.current = liveCaptionCues;
4527
+ liveLagMsRef.current = liveLagMs;
4528
+ compactChromeRef.current = compactChrome;
4536
4529
  cssFullscreenRef.current = cssFullscreen;
4537
4530
  captionLocaleRef.current = captionLocale;
4538
4531
  React9__namespace.useEffect(() => {
@@ -4608,7 +4601,6 @@ function VideoPlayer({
4608
4601
  }, [paused, videoRef, isPlaying]);
4609
4602
  React9__namespace.useEffect(() => {
4610
4603
  setEmbedded(isEmbeddedWindow());
4611
- setAppleMobile(isAppleMobileDevice());
4612
4604
  setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
4613
4605
  videoRef.current?.setAttribute("x-webkit-airplay", "allow");
4614
4606
  videoRef.current?.setAttribute("webkit-playsinline", "");
@@ -4636,9 +4628,6 @@ function VideoPlayer({
4636
4628
  function onSidecarTrackLoad(event) {
4637
4629
  const track = event.currentTarget.track;
4638
4630
  if (!track) return;
4639
- if (isLivePlaylistSrc(src)) {
4640
- zeroAnchorNativeTrackCues(track);
4641
- }
4642
4631
  const video = videoRef.current;
4643
4632
  if (video) {
4644
4633
  applyNativeTrackModes(
@@ -4738,8 +4727,7 @@ function VideoPlayer({
4738
4727
  return;
4739
4728
  }
4740
4729
  const cues = await loadCaptionVtt(url);
4741
- const next = isLivePlaylistSrc(src) ? zeroAnchorCaptionCues(cues) : cues;
4742
- if (!cancelled) setCaptionCues(next);
4730
+ if (!cancelled) setCaptionCues(cues);
4743
4731
  };
4744
4732
  void load();
4745
4733
  if (!liveCaptionsBaseUrl) return;
@@ -4749,12 +4737,28 @@ function VideoPlayer({
4749
4737
  window.clearInterval(timer);
4750
4738
  };
4751
4739
  }, [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);
4740
+ React9__namespace.useEffect(() => {
4741
+ if (!liveCaptionsBaseUrl || captionLocale === "off") {
4742
+ setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
4743
+ return;
4744
+ }
4745
+ const tick = () => {
4746
+ setLivePlayout(
4747
+ (prev) => advanceLiveCaptionPlayout(
4748
+ prev,
4749
+ coalesceLiveCaptionCues(liveCaptionCuesRef.current),
4750
+ Date.now(),
4751
+ liveLagMsRef.current,
4752
+ compactChromeRef.current ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE
4753
+ )
4754
+ );
4755
+ };
4756
+ tick();
4757
+ const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
4758
+ return () => window.clearInterval(timer);
4759
+ }, [liveCaptionsBaseUrl, captionLocale]);
4760
+ const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
4761
+ const captionScreen = liveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
4758
4762
  React9__namespace.useEffect(() => {
4759
4763
  const video = videoRef.current;
4760
4764
  if (!video || !liveCaptionsBaseUrl) return;
@@ -4801,12 +4805,14 @@ function VideoPlayer({
4801
4805
  if (!video || captionLocale === "off" || !liveCaptionsBaseUrl) return;
4802
4806
  const track = findSubtitleTrack(video, captionLocale);
4803
4807
  if (!track) return;
4808
+ const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
4804
4809
  syncNativeCaptionCue(
4805
4810
  video,
4806
4811
  track,
4807
- lastCaptionLines(joinCaptionTexts(captionStackCues))
4812
+ livePlayout.screen?.text ?? "",
4813
+ remaining
4808
4814
  );
4809
- }, [captionStackCues, captionLocale, liveCaptionsBaseUrl]);
4815
+ }, [livePlayout, captionLocale, liveCaptionsBaseUrl]);
4810
4816
  function togglePlay() {
4811
4817
  const video = videoRef.current;
4812
4818
  if (!video) return;
@@ -5072,22 +5078,7 @@ function VideoPlayer({
5072
5078
  ] }),
5073
5079
  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
5080
  ] }),
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
- ),
5081
+ captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsxRuntime.jsx(CaptionOverlay, { screen: captionScreen }),
5091
5082
  active && /* @__PURE__ */ jsxRuntime.jsxs(
5092
5083
  "div",
5093
5084
  {