@livo-tv/blocks 1.15.0 → 1.17.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
@@ -3642,7 +3642,13 @@ function useHlsPlayback({
3642
3642
  el.muted = true;
3643
3643
  void el.play().then(
3644
3644
  () => setAutoplayState(muted ? "playing" : "muted"),
3645
- () => setAutoplayState("blocked")
3645
+ () => {
3646
+ if (el.paused) {
3647
+ setAutoplayState("blocked");
3648
+ return;
3649
+ }
3650
+ setAutoplayState(el.muted && !muted ? "muted" : "playing");
3651
+ }
3646
3652
  );
3647
3653
  }
3648
3654
  );
@@ -3708,6 +3714,9 @@ function useHlsPlayback({
3708
3714
  mediaErrorRetries = 0;
3709
3715
  clearRetryTimer();
3710
3716
  setState("ready");
3717
+ setAutoplayState(
3718
+ (prev) => prev === "blocked" || prev === "none" ? "playing" : prev
3719
+ );
3711
3720
  onPlayingChangeRef.current?.(true);
3712
3721
  }
3713
3722
  function onPaused() {
@@ -3954,6 +3963,15 @@ function captionAtTime(cues, time, options) {
3954
3963
  if (matched) return matched;
3955
3964
  return null;
3956
3965
  }
3966
+ function vttCuesDueAt(cues, currentTime, cap = LIVE_STACK_MAX_CUES) {
3967
+ if (!Number.isFinite(currentTime)) return [];
3968
+ return cues.filter(
3969
+ (cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && cue.start <= currentTime
3970
+ ).sort((left, right) => left.start - right.start).slice(-Math.max(1, cap)).map((cue) => ({
3971
+ text: cue.text.trim(),
3972
+ receivedAt: cue.start * 1e3
3973
+ }));
3974
+ }
3957
3975
  function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
3958
3976
  if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return [];
3959
3977
  const threshold = lagMs + extraLagMs;
@@ -4073,6 +4091,27 @@ async function loadLiveCaptions(url) {
4073
4091
  return { ok: false, cues: [] };
4074
4092
  }
4075
4093
  }
4094
+
4095
+ // src/components/video/fullscreen.ts
4096
+ function asWebkitVideo(video) {
4097
+ return video;
4098
+ }
4099
+ function hasWebkitVideoFullscreen(video) {
4100
+ return typeof asWebkitVideo(video)?.webkitEnterFullscreen === "function";
4101
+ }
4102
+ function hasStandardFullscreen() {
4103
+ if (typeof document === "undefined") return false;
4104
+ if (document.fullscreenEnabled) return true;
4105
+ const doc = document;
4106
+ return !!doc.webkitFullscreenEnabled;
4107
+ }
4108
+ function isEmbeddedWindow(win = window) {
4109
+ try {
4110
+ return win.self !== win.top;
4111
+ } catch {
4112
+ return true;
4113
+ }
4114
+ }
4076
4115
  var NEAR_BOTTOM_PX = 24;
4077
4116
  function LiveCaptionStack({ cues, latestLabel }) {
4078
4117
  const scrollerRef = React9__namespace.useRef(null);
@@ -4134,7 +4173,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
4134
4173
  ref: scrollerRef,
4135
4174
  role: "log",
4136
4175
  "aria-relevant": "additions",
4137
- className: "pointer-events-auto max-h-[4.5rem] overflow-x-hidden overflow-y-auto rounded-sm bg-black/70 px-3 py-1.5 text-sm font-medium text-white shadow-sm",
4176
+ className: "pointer-events-auto max-h-[min(4.5rem,18cqh)] overflow-x-hidden overflow-y-auto 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%]",
4138
4177
  onScroll: (event) => {
4139
4178
  if (ignoreScrollRef.current) return;
4140
4179
  const scroller = event.currentTarget;
@@ -4146,7 +4185,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
4146
4185
  "p",
4147
4186
  {
4148
4187
  className: cn(
4149
- "text-justify [text-align-last:left] leading-5 break-words",
4188
+ "text-justify [text-align-last:left] leading-snug break-words",
4150
4189
  !prefersReduced && "transition-opacity"
4151
4190
  ),
4152
4191
  children: cues.map((cue, index) => {
@@ -4174,6 +4213,46 @@ function LiveCaptionStack({ cues, latestLabel }) {
4174
4213
  }
4175
4214
  );
4176
4215
  }
4216
+
4217
+ // src/components/video/nativeCaptionTrack.ts
4218
+ var NATIVE_CAPTION_HOLD_S = 4;
4219
+ function joinCaptionTexts(cues) {
4220
+ return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
4221
+ }
4222
+ function clearNativeCaptionCues(track) {
4223
+ const cues = track.cues;
4224
+ if (!cues) return;
4225
+ for (let index = cues.length - 1; index >= 0; index -= 1) {
4226
+ const cue = cues[index];
4227
+ if (cue) track.removeCue(cue);
4228
+ }
4229
+ }
4230
+ function ensureNativeCaptionTrack(video, locale, existing) {
4231
+ if (existing && existing.language === locale) return existing;
4232
+ if (existing) existing.mode = "disabled";
4233
+ const track = video.addTextTrack("captions", "Livo", locale);
4234
+ track.mode = "hidden";
4235
+ return track;
4236
+ }
4237
+ function syncNativeCaptionCue(video, track, text) {
4238
+ clearNativeCaptionCues(track);
4239
+ const trimmed = text.trim();
4240
+ if (!trimmed) return;
4241
+ const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
4242
+ track.addCue(new VTTCue(start, start + NATIVE_CAPTION_HOLD_S, trimmed));
4243
+ }
4244
+ function syncNativeVodCues(track, cues) {
4245
+ clearNativeCaptionCues(track);
4246
+ for (const cue of cues) {
4247
+ const text = cue.text.trim();
4248
+ if (!text) continue;
4249
+ track.addCue(new VTTCue(cue.start, cue.end, text));
4250
+ }
4251
+ }
4252
+ function setNativeCaptionTrackVisible(track, showing) {
4253
+ if (!track) return;
4254
+ track.mode = showing ? "showing" : "hidden";
4255
+ }
4177
4256
  var DEFAULT_LABELS3 = {
4178
4257
  play: "Play",
4179
4258
  pause: "Pause",
@@ -4209,19 +4288,15 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
4209
4288
  var CONTROLS_HIDE_MS = 3e3;
4210
4289
  var LIVE_EDGE_THRESHOLD_S = 8;
4211
4290
  var SEEK_STEP_S = 5;
4212
- function asWebkitVideo(video) {
4213
- return video;
4214
- }
4215
- function hasWebkitVideoFullscreen(video) {
4216
- const webkit = asWebkitVideo(video);
4217
- return typeof webkit?.webkitEnterFullscreen === "function";
4291
+ var VIDEO_MEDIA_STYLE = `
4292
+ .livo-video-player-media::-webkit-media-controls-start-playback-button {
4293
+ display: none !important;
4294
+ -webkit-appearance: none;
4218
4295
  }
4219
- function hasStandardFullscreen() {
4220
- if (typeof document === "undefined") return false;
4221
- if (document.fullscreenEnabled) return true;
4222
- const doc = document;
4223
- return !!doc.webkitFullscreenEnabled;
4296
+ .livo-video-player-media::-webkit-media-controls {
4297
+ display: none !important;
4224
4298
  }
4299
+ `;
4225
4300
  function captionLocaleLabel(locale, labels) {
4226
4301
  switch (locale) {
4227
4302
  case "en":
@@ -4267,6 +4342,9 @@ function VideoPlayer({
4267
4342
  const t = { ...DEFAULT_LABELS3, ...labels };
4268
4343
  const containerRef = React9__namespace.useRef(null);
4269
4344
  const firstPlayFiredRef = React9__namespace.useRef(false);
4345
+ const nativeTrackRef = React9__namespace.useRef(null);
4346
+ const cssFullscreenRef = React9__namespace.useRef(false);
4347
+ const webkitFsRef = React9__namespace.useRef(false);
4270
4348
  const [userStarted, setUserStarted] = React9__namespace.useState(false);
4271
4349
  const active = autoPlay || !poster || userStarted;
4272
4350
  const autoplayActive = autoPlay || userStarted;
@@ -4318,9 +4396,12 @@ function VideoPlayer({
4318
4396
  const [liveLagMs, setLiveLagMs] = React9__namespace.useState(null);
4319
4397
  const [behindLive, setBehindLive] = React9__namespace.useState(false);
4320
4398
  const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9__namespace.useState(false);
4399
+ const [embedded, setEmbedded] = React9__namespace.useState(false);
4400
+ const [cssFullscreen, setCssFullscreen] = React9__namespace.useState(false);
4321
4401
  const hideTimerRef = React9__namespace.useRef(null);
4402
+ cssFullscreenRef.current = cssFullscreen;
4322
4403
  const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
4323
- const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
4404
+ const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported || !embedded;
4324
4405
  React9__namespace.useEffect(() => {
4325
4406
  const video = videoRef.current;
4326
4407
  if (!video || !active) return;
@@ -4373,19 +4454,36 @@ function VideoPlayer({
4373
4454
  video.pause();
4374
4455
  }, [paused, videoRef, isPlaying]);
4375
4456
  React9__namespace.useEffect(() => {
4457
+ setEmbedded(isEmbeddedWindow());
4376
4458
  setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
4377
4459
  videoRef.current?.setAttribute("x-webkit-airplay", "allow");
4460
+ videoRef.current?.setAttribute("webkit-playsinline", "");
4378
4461
  }, [videoRef, active]);
4379
4462
  React9__namespace.useEffect(() => {
4380
- const onFsChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
4463
+ const onFsChange = () => {
4464
+ if (document.fullscreenElement === containerRef.current) {
4465
+ setIsFullscreen(true);
4466
+ return;
4467
+ }
4468
+ if (cssFullscreenRef.current || webkitFsRef.current) return;
4469
+ setIsFullscreen(false);
4470
+ };
4381
4471
  document.addEventListener("fullscreenchange", onFsChange);
4382
4472
  return () => document.removeEventListener("fullscreenchange", onFsChange);
4383
4473
  }, []);
4384
4474
  React9__namespace.useEffect(() => {
4385
4475
  const video = asWebkitVideo(videoRef.current);
4386
4476
  if (!video) return;
4387
- const onBegin = () => setIsFullscreen(true);
4388
- const onEnd = () => setIsFullscreen(false);
4477
+ const onBegin = () => {
4478
+ webkitFsRef.current = true;
4479
+ setIsFullscreen(true);
4480
+ setNativeCaptionTrackVisible(nativeTrackRef.current, true);
4481
+ };
4482
+ const onEnd = () => {
4483
+ webkitFsRef.current = false;
4484
+ setNativeCaptionTrackVisible(nativeTrackRef.current, false);
4485
+ if (!cssFullscreenRef.current) setIsFullscreen(false);
4486
+ };
4389
4487
  video.addEventListener("webkitbeginfullscreen", onBegin);
4390
4488
  video.addEventListener("webkitendfullscreen", onEnd);
4391
4489
  return () => {
@@ -4393,6 +4491,21 @@ function VideoPlayer({
4393
4491
  video.removeEventListener("webkitendfullscreen", onEnd);
4394
4492
  };
4395
4493
  }, [videoRef, active]);
4494
+ React9__namespace.useEffect(() => {
4495
+ if (!cssFullscreen) return;
4496
+ const previousOverflow = document.body.style.overflow;
4497
+ document.body.style.overflow = "hidden";
4498
+ const onKey = (event) => {
4499
+ if (event.key !== "Escape") return;
4500
+ setCssFullscreen(false);
4501
+ setIsFullscreen(false);
4502
+ };
4503
+ document.addEventListener("keydown", onKey);
4504
+ return () => {
4505
+ document.body.style.overflow = previousOverflow;
4506
+ document.removeEventListener("keydown", onKey);
4507
+ };
4508
+ }, [cssFullscreen]);
4396
4509
  React9__namespace.useEffect(() => {
4397
4510
  const video = videoRef.current;
4398
4511
  if (!video) return;
@@ -4457,10 +4570,44 @@ function VideoPlayer({
4457
4570
  window.clearInterval(timer);
4458
4571
  };
4459
4572
  }, [captionLocale, liveCaptionsBaseUrl, src]);
4573
+ const endedLiveReplay = !liveCaptionsBaseUrl && isLivePlaylistSrc(src);
4460
4574
  const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
4461
4575
  liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
4462
- ) : [];
4463
- const activeCaption = liveCaptionsBaseUrl ? null : captionAtTime(captionCues, currentTime);
4576
+ ) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
4577
+ const activeCaption = liveCaptionsBaseUrl || endedLiveReplay ? null : captionAtTime(captionCues, currentTime);
4578
+ React9__namespace.useEffect(() => {
4579
+ const video = videoRef.current;
4580
+ if (!video || captionLocale === "off") {
4581
+ if (nativeTrackRef.current) {
4582
+ nativeTrackRef.current.mode = "disabled";
4583
+ nativeTrackRef.current = null;
4584
+ }
4585
+ return;
4586
+ }
4587
+ try {
4588
+ nativeTrackRef.current = ensureNativeCaptionTrack(
4589
+ video,
4590
+ captionLocale,
4591
+ nativeTrackRef.current
4592
+ );
4593
+ setNativeCaptionTrackVisible(nativeTrackRef.current, webkitFsRef.current);
4594
+ } catch {
4595
+ nativeTrackRef.current = null;
4596
+ }
4597
+ }, [videoRef, active, captionLocale]);
4598
+ React9__namespace.useEffect(() => {
4599
+ const track = nativeTrackRef.current;
4600
+ if (!track || captionLocale === "off") return;
4601
+ if (liveCaptionsBaseUrl || endedLiveReplay) return;
4602
+ syncNativeVodCues(track, captionCues);
4603
+ }, [captionCues, captionLocale, liveCaptionsBaseUrl, endedLiveReplay]);
4604
+ React9__namespace.useEffect(() => {
4605
+ const video = videoRef.current;
4606
+ const track = nativeTrackRef.current;
4607
+ if (!video || !track) return;
4608
+ if (!(liveCaptionsBaseUrl || endedLiveReplay)) return;
4609
+ syncNativeCaptionCue(video, track, joinCaptionTexts(liveDueCues));
4610
+ }, [liveDueCues, liveCaptionsBaseUrl, endedLiveReplay]);
4464
4611
  function togglePlay() {
4465
4612
  const video = videoRef.current;
4466
4613
  if (!video) return;
@@ -4495,6 +4642,10 @@ function VideoPlayer({
4495
4642
  video.currentTime = video.seekable.end(video.seekable.length - 1);
4496
4643
  if (video.paused) void video.play();
4497
4644
  }
4645
+ function exitCssFullscreen() {
4646
+ setCssFullscreen(false);
4647
+ setIsFullscreen(false);
4648
+ }
4498
4649
  function toggleFullscreen() {
4499
4650
  const el = containerRef.current;
4500
4651
  const video = asWebkitVideo(videoRef.current);
@@ -4506,13 +4657,20 @@ function VideoPlayer({
4506
4657
  video.webkitExitFullscreen();
4507
4658
  return;
4508
4659
  }
4660
+ if (cssFullscreen) {
4661
+ exitCssFullscreen();
4662
+ return;
4663
+ }
4509
4664
  if (el && hasStandardFullscreen() && typeof el.requestFullscreen === "function") {
4510
4665
  void el.requestFullscreen();
4511
4666
  return;
4512
4667
  }
4513
- if (video && typeof video.webkitEnterFullscreen === "function") {
4668
+ if (embedded && video && typeof video.webkitEnterFullscreen === "function") {
4514
4669
  video.webkitEnterFullscreen();
4670
+ return;
4515
4671
  }
4672
+ setCssFullscreen(true);
4673
+ setIsFullscreen(true);
4516
4674
  }
4517
4675
  function togglePip() {
4518
4676
  const video = videoRef.current;
@@ -4547,6 +4705,12 @@ function VideoPlayer({
4547
4705
  case "f":
4548
4706
  toggleFullscreen();
4549
4707
  break;
4708
+ case "Escape":
4709
+ if (cssFullscreen) {
4710
+ e.preventDefault();
4711
+ exitCssFullscreen();
4712
+ }
4713
+ break;
4550
4714
  case "ArrowLeft":
4551
4715
  if (mode === "vod") {
4552
4716
  e.preventDefault();
@@ -4602,9 +4766,11 @@ function VideoPlayer({
4602
4766
  "data-slot": "video-player",
4603
4767
  "data-mode": mode,
4604
4768
  "data-fit": fit,
4769
+ "data-css-fullscreen": cssFullscreen ? "" : void 0,
4605
4770
  className: cn(
4606
- "group relative w-full overflow-hidden rounded-lg bg-black text-white select-none",
4771
+ "@container group relative w-full overflow-hidden rounded-lg bg-black text-white select-none",
4607
4772
  fit === "contain" ? "h-full min-h-0 aspect-auto" : "aspect-video",
4773
+ cssFullscreen && "fixed inset-0 z-50 h-dvh w-dvw rounded-none",
4608
4774
  className
4609
4775
  ),
4610
4776
  onMouseMove: revealControls,
@@ -4616,13 +4782,14 @@ function VideoPlayer({
4616
4782
  role: "region",
4617
4783
  "aria-label": "Video player",
4618
4784
  children: [
4785
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: VIDEO_MEDIA_STYLE }),
4619
4786
  /* @__PURE__ */ jsxRuntime.jsx(
4620
4787
  "video",
4621
4788
  {
4622
4789
  ref: videoRef,
4623
4790
  playsInline: true,
4624
4791
  muted: isMuted,
4625
- className: "h-full w-full bg-black object-contain",
4792
+ className: "livo-video-player-media h-full w-full bg-black object-contain",
4626
4793
  onClick: active ? togglePlay : void 0,
4627
4794
  poster
4628
4795
  }
@@ -4661,7 +4828,7 @@ function VideoPlayer({
4661
4828
  }
4662
4829
  )
4663
4830
  ] }),
4664
- state === "ready" && autoplayState === "blocked" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsxRuntime.jsx(
4831
+ state === "ready" && autoplayState === "blocked" && !isPlaying && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsxRuntime.jsx(
4665
4832
  "button",
4666
4833
  {
4667
4834
  type: "button",
@@ -4690,13 +4857,13 @@ function VideoPlayer({
4690
4857
  ] }),
4691
4858
  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}` })
4692
4859
  ] }),
4693
- liveCaptionsBaseUrl && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
4694
- !liveCaptionsBaseUrl && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(
4860
+ (liveCaptionsBaseUrl || endedLiveReplay) && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
4861
+ !liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(
4695
4862
  "div",
4696
4863
  {
4697
4864
  className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
4698
4865
  "data-slot": "video-captions",
4699
- 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-sm font-medium text-white shadow-sm", children: activeCaption.text })
4866
+ 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 })
4700
4867
  }
4701
4868
  ),
4702
4869
  active && /* @__PURE__ */ jsxRuntime.jsxs(