@livo-tv/blocks 1.16.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.js CHANGED
@@ -3616,7 +3616,13 @@ function useHlsPlayback({
3616
3616
  el.muted = true;
3617
3617
  void el.play().then(
3618
3618
  () => setAutoplayState(muted ? "playing" : "muted"),
3619
- () => setAutoplayState("blocked")
3619
+ () => {
3620
+ if (el.paused) {
3621
+ setAutoplayState("blocked");
3622
+ return;
3623
+ }
3624
+ setAutoplayState(el.muted && !muted ? "muted" : "playing");
3625
+ }
3620
3626
  );
3621
3627
  }
3622
3628
  );
@@ -3682,6 +3688,9 @@ function useHlsPlayback({
3682
3688
  mediaErrorRetries = 0;
3683
3689
  clearRetryTimer();
3684
3690
  setState("ready");
3691
+ setAutoplayState(
3692
+ (prev) => prev === "blocked" || prev === "none" ? "playing" : prev
3693
+ );
3685
3694
  onPlayingChangeRef.current?.(true);
3686
3695
  }
3687
3696
  function onPaused() {
@@ -4056,6 +4065,27 @@ async function loadLiveCaptions(url) {
4056
4065
  return { ok: false, cues: [] };
4057
4066
  }
4058
4067
  }
4068
+
4069
+ // src/components/video/fullscreen.ts
4070
+ function asWebkitVideo(video) {
4071
+ return video;
4072
+ }
4073
+ function hasWebkitVideoFullscreen(video) {
4074
+ return typeof asWebkitVideo(video)?.webkitEnterFullscreen === "function";
4075
+ }
4076
+ function hasStandardFullscreen() {
4077
+ if (typeof document === "undefined") return false;
4078
+ if (document.fullscreenEnabled) return true;
4079
+ const doc = document;
4080
+ return !!doc.webkitFullscreenEnabled;
4081
+ }
4082
+ function isEmbeddedWindow(win = window) {
4083
+ try {
4084
+ return win.self !== win.top;
4085
+ } catch {
4086
+ return true;
4087
+ }
4088
+ }
4059
4089
  var NEAR_BOTTOM_PX = 24;
4060
4090
  function LiveCaptionStack({ cues, latestLabel }) {
4061
4091
  const scrollerRef = React9.useRef(null);
@@ -4117,7 +4147,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
4117
4147
  ref: scrollerRef,
4118
4148
  role: "log",
4119
4149
  "aria-relevant": "additions",
4120
- 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",
4150
+ 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%]",
4121
4151
  onScroll: (event) => {
4122
4152
  if (ignoreScrollRef.current) return;
4123
4153
  const scroller = event.currentTarget;
@@ -4129,7 +4159,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
4129
4159
  "p",
4130
4160
  {
4131
4161
  className: cn(
4132
- "text-justify [text-align-last:left] leading-5 break-words",
4162
+ "text-justify [text-align-last:left] leading-snug break-words",
4133
4163
  !prefersReduced && "transition-opacity"
4134
4164
  ),
4135
4165
  children: cues.map((cue, index) => {
@@ -4157,6 +4187,46 @@ function LiveCaptionStack({ cues, latestLabel }) {
4157
4187
  }
4158
4188
  );
4159
4189
  }
4190
+
4191
+ // src/components/video/nativeCaptionTrack.ts
4192
+ var NATIVE_CAPTION_HOLD_S = 4;
4193
+ function joinCaptionTexts(cues) {
4194
+ return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
4195
+ }
4196
+ function clearNativeCaptionCues(track) {
4197
+ const cues = track.cues;
4198
+ if (!cues) return;
4199
+ for (let index = cues.length - 1; index >= 0; index -= 1) {
4200
+ const cue = cues[index];
4201
+ if (cue) track.removeCue(cue);
4202
+ }
4203
+ }
4204
+ function ensureNativeCaptionTrack(video, locale, existing) {
4205
+ if (existing && existing.language === locale) return existing;
4206
+ if (existing) existing.mode = "disabled";
4207
+ const track = video.addTextTrack("captions", "Livo", locale);
4208
+ track.mode = "hidden";
4209
+ return track;
4210
+ }
4211
+ function syncNativeCaptionCue(video, track, text) {
4212
+ clearNativeCaptionCues(track);
4213
+ const trimmed = text.trim();
4214
+ if (!trimmed) return;
4215
+ const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
4216
+ track.addCue(new VTTCue(start, start + NATIVE_CAPTION_HOLD_S, trimmed));
4217
+ }
4218
+ function syncNativeVodCues(track, cues) {
4219
+ clearNativeCaptionCues(track);
4220
+ for (const cue of cues) {
4221
+ const text = cue.text.trim();
4222
+ if (!text) continue;
4223
+ track.addCue(new VTTCue(cue.start, cue.end, text));
4224
+ }
4225
+ }
4226
+ function setNativeCaptionTrackVisible(track, showing) {
4227
+ if (!track) return;
4228
+ track.mode = showing ? "showing" : "hidden";
4229
+ }
4160
4230
  var DEFAULT_LABELS3 = {
4161
4231
  play: "Play",
4162
4232
  pause: "Pause",
@@ -4192,19 +4262,15 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
4192
4262
  var CONTROLS_HIDE_MS = 3e3;
4193
4263
  var LIVE_EDGE_THRESHOLD_S = 8;
4194
4264
  var SEEK_STEP_S = 5;
4195
- function asWebkitVideo(video) {
4196
- return video;
4197
- }
4198
- function hasWebkitVideoFullscreen(video) {
4199
- const webkit = asWebkitVideo(video);
4200
- return typeof webkit?.webkitEnterFullscreen === "function";
4265
+ var VIDEO_MEDIA_STYLE = `
4266
+ .livo-video-player-media::-webkit-media-controls-start-playback-button {
4267
+ display: none !important;
4268
+ -webkit-appearance: none;
4201
4269
  }
4202
- function hasStandardFullscreen() {
4203
- if (typeof document === "undefined") return false;
4204
- if (document.fullscreenEnabled) return true;
4205
- const doc = document;
4206
- return !!doc.webkitFullscreenEnabled;
4270
+ .livo-video-player-media::-webkit-media-controls {
4271
+ display: none !important;
4207
4272
  }
4273
+ `;
4208
4274
  function captionLocaleLabel(locale, labels) {
4209
4275
  switch (locale) {
4210
4276
  case "en":
@@ -4250,6 +4316,9 @@ function VideoPlayer({
4250
4316
  const t = { ...DEFAULT_LABELS3, ...labels };
4251
4317
  const containerRef = React9.useRef(null);
4252
4318
  const firstPlayFiredRef = React9.useRef(false);
4319
+ const nativeTrackRef = React9.useRef(null);
4320
+ const cssFullscreenRef = React9.useRef(false);
4321
+ const webkitFsRef = React9.useRef(false);
4253
4322
  const [userStarted, setUserStarted] = React9.useState(false);
4254
4323
  const active = autoPlay || !poster || userStarted;
4255
4324
  const autoplayActive = autoPlay || userStarted;
@@ -4301,9 +4370,12 @@ function VideoPlayer({
4301
4370
  const [liveLagMs, setLiveLagMs] = React9.useState(null);
4302
4371
  const [behindLive, setBehindLive] = React9.useState(false);
4303
4372
  const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9.useState(false);
4373
+ const [embedded, setEmbedded] = React9.useState(false);
4374
+ const [cssFullscreen, setCssFullscreen] = React9.useState(false);
4304
4375
  const hideTimerRef = React9.useRef(null);
4376
+ cssFullscreenRef.current = cssFullscreen;
4305
4377
  const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
4306
- const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
4378
+ const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported || !embedded;
4307
4379
  React9.useEffect(() => {
4308
4380
  const video = videoRef.current;
4309
4381
  if (!video || !active) return;
@@ -4356,19 +4428,36 @@ function VideoPlayer({
4356
4428
  video.pause();
4357
4429
  }, [paused, videoRef, isPlaying]);
4358
4430
  React9.useEffect(() => {
4431
+ setEmbedded(isEmbeddedWindow());
4359
4432
  setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
4360
4433
  videoRef.current?.setAttribute("x-webkit-airplay", "allow");
4434
+ videoRef.current?.setAttribute("webkit-playsinline", "");
4361
4435
  }, [videoRef, active]);
4362
4436
  React9.useEffect(() => {
4363
- const onFsChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
4437
+ const onFsChange = () => {
4438
+ if (document.fullscreenElement === containerRef.current) {
4439
+ setIsFullscreen(true);
4440
+ return;
4441
+ }
4442
+ if (cssFullscreenRef.current || webkitFsRef.current) return;
4443
+ setIsFullscreen(false);
4444
+ };
4364
4445
  document.addEventListener("fullscreenchange", onFsChange);
4365
4446
  return () => document.removeEventListener("fullscreenchange", onFsChange);
4366
4447
  }, []);
4367
4448
  React9.useEffect(() => {
4368
4449
  const video = asWebkitVideo(videoRef.current);
4369
4450
  if (!video) return;
4370
- const onBegin = () => setIsFullscreen(true);
4371
- const onEnd = () => setIsFullscreen(false);
4451
+ const onBegin = () => {
4452
+ webkitFsRef.current = true;
4453
+ setIsFullscreen(true);
4454
+ setNativeCaptionTrackVisible(nativeTrackRef.current, true);
4455
+ };
4456
+ const onEnd = () => {
4457
+ webkitFsRef.current = false;
4458
+ setNativeCaptionTrackVisible(nativeTrackRef.current, false);
4459
+ if (!cssFullscreenRef.current) setIsFullscreen(false);
4460
+ };
4372
4461
  video.addEventListener("webkitbeginfullscreen", onBegin);
4373
4462
  video.addEventListener("webkitendfullscreen", onEnd);
4374
4463
  return () => {
@@ -4376,6 +4465,21 @@ function VideoPlayer({
4376
4465
  video.removeEventListener("webkitendfullscreen", onEnd);
4377
4466
  };
4378
4467
  }, [videoRef, active]);
4468
+ React9.useEffect(() => {
4469
+ if (!cssFullscreen) return;
4470
+ const previousOverflow = document.body.style.overflow;
4471
+ document.body.style.overflow = "hidden";
4472
+ const onKey = (event) => {
4473
+ if (event.key !== "Escape") return;
4474
+ setCssFullscreen(false);
4475
+ setIsFullscreen(false);
4476
+ };
4477
+ document.addEventListener("keydown", onKey);
4478
+ return () => {
4479
+ document.body.style.overflow = previousOverflow;
4480
+ document.removeEventListener("keydown", onKey);
4481
+ };
4482
+ }, [cssFullscreen]);
4379
4483
  React9.useEffect(() => {
4380
4484
  const video = videoRef.current;
4381
4485
  if (!video) return;
@@ -4445,6 +4549,39 @@ function VideoPlayer({
4445
4549
  liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
4446
4550
  ) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
4447
4551
  const activeCaption = liveCaptionsBaseUrl || endedLiveReplay ? null : captionAtTime(captionCues, currentTime);
4552
+ React9.useEffect(() => {
4553
+ const video = videoRef.current;
4554
+ if (!video || captionLocale === "off") {
4555
+ if (nativeTrackRef.current) {
4556
+ nativeTrackRef.current.mode = "disabled";
4557
+ nativeTrackRef.current = null;
4558
+ }
4559
+ return;
4560
+ }
4561
+ try {
4562
+ nativeTrackRef.current = ensureNativeCaptionTrack(
4563
+ video,
4564
+ captionLocale,
4565
+ nativeTrackRef.current
4566
+ );
4567
+ setNativeCaptionTrackVisible(nativeTrackRef.current, webkitFsRef.current);
4568
+ } catch {
4569
+ nativeTrackRef.current = null;
4570
+ }
4571
+ }, [videoRef, active, captionLocale]);
4572
+ React9.useEffect(() => {
4573
+ const track = nativeTrackRef.current;
4574
+ if (!track || captionLocale === "off") return;
4575
+ if (liveCaptionsBaseUrl || endedLiveReplay) return;
4576
+ syncNativeVodCues(track, captionCues);
4577
+ }, [captionCues, captionLocale, liveCaptionsBaseUrl, endedLiveReplay]);
4578
+ React9.useEffect(() => {
4579
+ const video = videoRef.current;
4580
+ const track = nativeTrackRef.current;
4581
+ if (!video || !track) return;
4582
+ if (!(liveCaptionsBaseUrl || endedLiveReplay)) return;
4583
+ syncNativeCaptionCue(video, track, joinCaptionTexts(liveDueCues));
4584
+ }, [liveDueCues, liveCaptionsBaseUrl, endedLiveReplay]);
4448
4585
  function togglePlay() {
4449
4586
  const video = videoRef.current;
4450
4587
  if (!video) return;
@@ -4479,6 +4616,10 @@ function VideoPlayer({
4479
4616
  video.currentTime = video.seekable.end(video.seekable.length - 1);
4480
4617
  if (video.paused) void video.play();
4481
4618
  }
4619
+ function exitCssFullscreen() {
4620
+ setCssFullscreen(false);
4621
+ setIsFullscreen(false);
4622
+ }
4482
4623
  function toggleFullscreen() {
4483
4624
  const el = containerRef.current;
4484
4625
  const video = asWebkitVideo(videoRef.current);
@@ -4490,13 +4631,20 @@ function VideoPlayer({
4490
4631
  video.webkitExitFullscreen();
4491
4632
  return;
4492
4633
  }
4634
+ if (cssFullscreen) {
4635
+ exitCssFullscreen();
4636
+ return;
4637
+ }
4493
4638
  if (el && hasStandardFullscreen() && typeof el.requestFullscreen === "function") {
4494
4639
  void el.requestFullscreen();
4495
4640
  return;
4496
4641
  }
4497
- if (video && typeof video.webkitEnterFullscreen === "function") {
4642
+ if (embedded && video && typeof video.webkitEnterFullscreen === "function") {
4498
4643
  video.webkitEnterFullscreen();
4644
+ return;
4499
4645
  }
4646
+ setCssFullscreen(true);
4647
+ setIsFullscreen(true);
4500
4648
  }
4501
4649
  function togglePip() {
4502
4650
  const video = videoRef.current;
@@ -4531,6 +4679,12 @@ function VideoPlayer({
4531
4679
  case "f":
4532
4680
  toggleFullscreen();
4533
4681
  break;
4682
+ case "Escape":
4683
+ if (cssFullscreen) {
4684
+ e.preventDefault();
4685
+ exitCssFullscreen();
4686
+ }
4687
+ break;
4534
4688
  case "ArrowLeft":
4535
4689
  if (mode === "vod") {
4536
4690
  e.preventDefault();
@@ -4586,9 +4740,11 @@ function VideoPlayer({
4586
4740
  "data-slot": "video-player",
4587
4741
  "data-mode": mode,
4588
4742
  "data-fit": fit,
4743
+ "data-css-fullscreen": cssFullscreen ? "" : void 0,
4589
4744
  className: cn(
4590
- "group relative w-full overflow-hidden rounded-lg bg-black text-white select-none",
4745
+ "@container group relative w-full overflow-hidden rounded-lg bg-black text-white select-none",
4591
4746
  fit === "contain" ? "h-full min-h-0 aspect-auto" : "aspect-video",
4747
+ cssFullscreen && "fixed inset-0 z-50 h-dvh w-dvw rounded-none",
4592
4748
  className
4593
4749
  ),
4594
4750
  onMouseMove: revealControls,
@@ -4600,13 +4756,14 @@ function VideoPlayer({
4600
4756
  role: "region",
4601
4757
  "aria-label": "Video player",
4602
4758
  children: [
4759
+ /* @__PURE__ */ jsx("style", { children: VIDEO_MEDIA_STYLE }),
4603
4760
  /* @__PURE__ */ jsx(
4604
4761
  "video",
4605
4762
  {
4606
4763
  ref: videoRef,
4607
4764
  playsInline: true,
4608
4765
  muted: isMuted,
4609
- className: "h-full w-full bg-black object-contain",
4766
+ className: "livo-video-player-media h-full w-full bg-black object-contain",
4610
4767
  onClick: active ? togglePlay : void 0,
4611
4768
  poster
4612
4769
  }
@@ -4645,7 +4802,7 @@ function VideoPlayer({
4645
4802
  }
4646
4803
  )
4647
4804
  ] }),
4648
- state === "ready" && autoplayState === "blocked" && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsx(
4805
+ state === "ready" && autoplayState === "blocked" && !isPlaying && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsx(
4649
4806
  "button",
4650
4807
  {
4651
4808
  type: "button",
@@ -4680,7 +4837,7 @@ function VideoPlayer({
4680
4837
  {
4681
4838
  className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
4682
4839
  "data-slot": "video-captions",
4683
- children: /* @__PURE__ */ 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 })
4840
+ children: /* @__PURE__ */ 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 })
4684
4841
  }
4685
4842
  ),
4686
4843
  active && /* @__PURE__ */ jsxs(