@livo-tv/blocks 1.17.0 → 1.18.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
@@ -3893,10 +3893,18 @@ function useHlsPlayback({
3893
3893
  };
3894
3894
  }
3895
3895
 
3896
+ // src/components/video/appleMobile.ts
3897
+ function isAppleMobileDevice(nav = navigator) {
3898
+ if (/iP(hone|ad|od)/.test(nav.userAgent)) return true;
3899
+ return nav.platform === "MacIntel" && nav.maxTouchPoints > 1;
3900
+ }
3901
+
3896
3902
  // src/components/video/captions.ts
3897
3903
  var CAPTION_LOCALES = ["en", "es", "pt"];
3898
3904
  var LIVE_CUE_EXTRA_LAG_MS = 2e3;
3899
3905
  var LIVE_STACK_MAX_CUES = 150;
3906
+ var IOS_CAPTION_WINDOW_LINES = 3;
3907
+ var IOS_CAPTION_CHARS_PER_LINE = 40;
3900
3908
  var LIVE_LAG_SPIKE_MS = 2500;
3901
3909
  function stabilizeLiveLagMs(previous, next) {
3902
3910
  if (previous == null || !Number.isFinite(previous)) return next;
@@ -4044,6 +4052,17 @@ function coalesceLiveCaptionCues(cues) {
4044
4052
  }
4045
4053
  return out;
4046
4054
  }
4055
+ function lastLiveCaptionWindow(cues, maxCues = IOS_CAPTION_WINDOW_LINES) {
4056
+ return cues.slice(-Math.max(1, maxCues));
4057
+ }
4058
+ function lastCaptionLines(text, lines = IOS_CAPTION_WINDOW_LINES, charsPerLine = IOS_CAPTION_CHARS_PER_LINE) {
4059
+ const trimmed = text.trim().replace(/\s+/g, " ");
4060
+ const maxChars = Math.max(1, lines) * Math.max(1, charsPerLine);
4061
+ if (trimmed.length <= maxChars) return trimmed;
4062
+ const slice = trimmed.slice(-maxChars);
4063
+ const space = slice.indexOf(" ");
4064
+ return (space > 0 ? slice.slice(space + 1) : slice).trim();
4065
+ }
4047
4066
  function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
4048
4067
  const map = /* @__PURE__ */ new Map();
4049
4068
  for (const cue of existing) {
@@ -4113,7 +4132,11 @@ function isEmbeddedWindow(win = window) {
4113
4132
  }
4114
4133
  }
4115
4134
  var NEAR_BOTTOM_PX = 24;
4116
- function LiveCaptionStack({ cues, latestLabel }) {
4135
+ function LiveCaptionStack({
4136
+ cues,
4137
+ latestLabel,
4138
+ variant = "scroll"
4139
+ }) {
4117
4140
  const scrollerRef = React9__namespace.useRef(null);
4118
4141
  const followRef = React9__namespace.useRef(true);
4119
4142
  const ignoreScrollRef = React9__namespace.useRef(false);
@@ -4152,13 +4175,15 @@ function LiveCaptionStack({ cues, latestLabel }) {
4152
4175
  });
4153
4176
  }, [lastReceivedAt, prefersReduced, cues.length]);
4154
4177
  if (cues.length === 0) return null;
4178
+ const windowed = variant === "window";
4155
4179
  return /* @__PURE__ */ jsxRuntime.jsx(
4156
4180
  "div",
4157
4181
  {
4158
4182
  className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
4159
4183
  "data-slot": "video-captions",
4184
+ "data-caption-mode": variant,
4160
4185
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative w-full max-w-[90%]", children: [
4161
- !following && /* @__PURE__ */ jsxRuntime.jsx(
4186
+ !windowed && !following && /* @__PURE__ */ jsxRuntime.jsx(
4162
4187
  "button",
4163
4188
  {
4164
4189
  type: "button",
@@ -4170,11 +4195,14 @@ function LiveCaptionStack({ cues, latestLabel }) {
4170
4195
  /* @__PURE__ */ jsxRuntime.jsx(
4171
4196
  "div",
4172
4197
  {
4173
- ref: scrollerRef,
4198
+ ref: windowed ? void 0 : scrollerRef,
4174
4199
  role: "log",
4175
4200
  "aria-relevant": "additions",
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%]",
4177
- onScroll: (event) => {
4201
+ className: cn(
4202
+ "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%]",
4203
+ windowed ? "overflow-hidden" : "pointer-events-auto max-h-[min(4.5rem,18cqh)] overflow-x-hidden overflow-y-auto"
4204
+ ),
4205
+ onScroll: windowed ? void 0 : (event) => {
4178
4206
  if (ignoreScrollRef.current) return;
4179
4207
  const scroller = event.currentTarget;
4180
4208
  const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
@@ -4186,6 +4214,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
4186
4214
  {
4187
4215
  className: cn(
4188
4216
  "text-justify [text-align-last:left] leading-snug break-words",
4217
+ windowed && "line-clamp-3",
4189
4218
  !prefersReduced && "transition-opacity"
4190
4219
  ),
4191
4220
  children: cues.map((cue, index) => {
@@ -4263,6 +4292,7 @@ var DEFAULT_LABELS3 = {
4263
4292
  pictureInPicture: "Picture in picture",
4264
4293
  cast: "Cast",
4265
4294
  settings: "Settings",
4295
+ more: "More",
4266
4296
  quality: "Quality",
4267
4297
  auto: "Auto",
4268
4298
  speed: "Speed",
@@ -4288,6 +4318,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
4288
4318
  var CONTROLS_HIDE_MS = 3e3;
4289
4319
  var LIVE_EDGE_THRESHOLD_S = 8;
4290
4320
  var SEEK_STEP_S = 5;
4321
+ var COMPACT_CHROME_PX = 640;
4291
4322
  var VIDEO_MEDIA_STYLE = `
4292
4323
  .livo-video-player-media::-webkit-media-controls-start-playback-button {
4293
4324
  display: none !important;
@@ -4390,6 +4421,7 @@ function VideoPlayer({
4390
4421
  const [controlsVisible, setControlsVisible] = React9__namespace.useState(true);
4391
4422
  const [playbackRate, setPlaybackRate] = React9__namespace.useState(1);
4392
4423
  const [openMenu, setOpenMenu] = React9__namespace.useState(null);
4424
+ const [compactChrome, setCompactChrome] = React9__namespace.useState(false);
4393
4425
  const [captionLocale, setCaptionLocale] = React9__namespace.useState(defaultCaptionLocale ?? "off");
4394
4426
  const [captionCues, setCaptionCues] = React9__namespace.useState([]);
4395
4427
  const [liveCaptionCues, setLiveCaptionCues] = React9__namespace.useState([]);
@@ -4398,8 +4430,24 @@ function VideoPlayer({
4398
4430
  const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9__namespace.useState(false);
4399
4431
  const [embedded, setEmbedded] = React9__namespace.useState(false);
4400
4432
  const [cssFullscreen, setCssFullscreen] = React9__namespace.useState(false);
4433
+ const [appleMobile, setAppleMobile] = React9__namespace.useState(false);
4401
4434
  const hideTimerRef = React9__namespace.useRef(null);
4402
4435
  cssFullscreenRef.current = cssFullscreen;
4436
+ React9__namespace.useEffect(() => {
4437
+ const el = containerRef.current;
4438
+ if (!el || typeof ResizeObserver === "undefined") return;
4439
+ const apply = (width) => {
4440
+ if (width <= 0) return;
4441
+ setCompactChrome(width < COMPACT_CHROME_PX);
4442
+ };
4443
+ apply(el.clientWidth);
4444
+ const observer = new ResizeObserver((entries) => {
4445
+ const width = entries[0]?.contentRect.width;
4446
+ if (typeof width === "number") apply(width);
4447
+ });
4448
+ observer.observe(el);
4449
+ return () => observer.disconnect();
4450
+ }, [active]);
4403
4451
  const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
4404
4452
  const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported || !embedded;
4405
4453
  React9__namespace.useEffect(() => {
@@ -4455,6 +4503,7 @@ function VideoPlayer({
4455
4503
  }, [paused, videoRef, isPlaying]);
4456
4504
  React9__namespace.useEffect(() => {
4457
4505
  setEmbedded(isEmbeddedWindow());
4506
+ setAppleMobile(isAppleMobileDevice());
4458
4507
  setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
4459
4508
  videoRef.current?.setAttribute("x-webkit-airplay", "allow");
4460
4509
  videoRef.current?.setAttribute("webkit-playsinline", "");
@@ -4574,6 +4623,7 @@ function VideoPlayer({
4574
4623
  const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
4575
4624
  liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
4576
4625
  ) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
4626
+ const captionStackCues = appleMobile ? lastLiveCaptionWindow(liveDueCues) : liveDueCues;
4577
4627
  const activeCaption = liveCaptionsBaseUrl || endedLiveReplay ? null : captionAtTime(captionCues, currentTime);
4578
4628
  React9__namespace.useEffect(() => {
4579
4629
  const video = videoRef.current;
@@ -4606,8 +4656,12 @@ function VideoPlayer({
4606
4656
  const track = nativeTrackRef.current;
4607
4657
  if (!video || !track) return;
4608
4658
  if (!(liveCaptionsBaseUrl || endedLiveReplay)) return;
4609
- syncNativeCaptionCue(video, track, joinCaptionTexts(liveDueCues));
4610
- }, [liveDueCues, liveCaptionsBaseUrl, endedLiveReplay]);
4659
+ syncNativeCaptionCue(
4660
+ video,
4661
+ track,
4662
+ lastCaptionLines(joinCaptionTexts(captionStackCues))
4663
+ );
4664
+ }, [captionStackCues, liveCaptionsBaseUrl, endedLiveReplay]);
4611
4665
  function togglePlay() {
4612
4666
  const video = videoRef.current;
4613
4667
  if (!video) return;
@@ -4759,6 +4813,7 @@ function VideoPlayer({
4759
4813
  const showControls = active && state === "ready" && (controlsVisible || !isPlaying);
4760
4814
  const showPoster = !active && !!poster;
4761
4815
  const currentLevelLabel = activeLevel < 0 ? t.auto : `${qualities.find((q) => q.index === activeLevel)?.height ?? ""}p`;
4816
+ const showQuality = showQualitySelector && qualities.length > 1;
4762
4817
  return /* @__PURE__ */ jsxRuntime.jsxs(
4763
4818
  "div",
4764
4819
  {
@@ -4857,7 +4912,14 @@ function VideoPlayer({
4857
4912
  ] }),
4858
4913
  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}` })
4859
4914
  ] }),
4860
- (liveCaptionsBaseUrl || endedLiveReplay) && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
4915
+ (liveCaptionsBaseUrl || endedLiveReplay) && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(
4916
+ LiveCaptionStack,
4917
+ {
4918
+ cues: captionStackCues,
4919
+ latestLabel: t.captionsLatest,
4920
+ variant: appleMobile ? "window" : "scroll"
4921
+ }
4922
+ ),
4861
4923
  !liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(
4862
4924
  "div",
4863
4925
  {
@@ -4886,7 +4948,7 @@ function VideoPlayer({
4886
4948
  formatTime
4887
4949
  }
4888
4950
  ),
4889
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
4951
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-1 sm:gap-2", children: [
4890
4952
  /* @__PURE__ */ jsxRuntime.jsx(
4891
4953
  ControlButton,
4892
4954
  {
@@ -4904,7 +4966,7 @@ function VideoPlayer({
4904
4966
  children: /* @__PURE__ */ jsxRuntime.jsx(VolumeIcon, { className: "size-5" })
4905
4967
  }
4906
4968
  ),
4907
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-20 px-1", children: /* @__PURE__ */ jsxRuntime.jsx(
4969
+ !compactChrome && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-20 px-1", children: /* @__PURE__ */ jsxRuntime.jsx(
4908
4970
  Slider,
4909
4971
  {
4910
4972
  "aria-label": "Volume",
@@ -4916,25 +4978,24 @@ function VideoPlayer({
4916
4978
  }
4917
4979
  ) })
4918
4980
  ] }),
4919
- mode === "vod" && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-1 text-xs tabular-nums", children: [
4981
+ mode === "vod" && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-1 shrink-0 text-xs tabular-nums", children: [
4920
4982
  formatTime(currentTime),
4921
- " / ",
4922
- formatTime(duration)
4983
+ !compactChrome && ` / ${formatTime(duration)}`
4923
4984
  ] }),
4924
4985
  mode === "live" && behindLive && /* @__PURE__ */ jsxRuntime.jsxs(
4925
4986
  "button",
4926
4987
  {
4927
4988
  type: "button",
4928
4989
  onClick: goToLiveEdge,
4929
- className: "ml-1 flex items-center gap-1 rounded bg-white/15 px-2 py-0.5 text-xs hover:bg-white/25",
4990
+ className: "ml-1 flex shrink-0 items-center gap-1 rounded bg-white/15 px-2 py-0.5 text-xs hover:bg-white/25",
4930
4991
  children: [
4931
4992
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "size-1.5 rounded-full bg-red-500" }),
4932
4993
  t.goLive
4933
4994
  ]
4934
4995
  }
4935
4996
  ),
4936
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ml-auto flex items-center gap-1", children: [
4937
- mode === "vod" && typeof stats?.views === "number" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1 text-xs", children: t.formatViews ? t.formatViews(stats.views) : `${stats.views} views` }),
4997
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1", children: [
4998
+ !compactChrome && mode === "vod" && typeof stats?.views === "number" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1 text-xs", children: t.formatViews ? t.formatViews(stats.views) : `${stats.views} views` }),
4938
4999
  /* @__PURE__ */ jsxRuntime.jsxs(
4939
5000
  MenuControl,
4940
5001
  {
@@ -4963,7 +5024,7 @@ function VideoPlayer({
4963
5024
  ]
4964
5025
  }
4965
5026
  ),
4966
- mode === "vod" && /* @__PURE__ */ jsxRuntime.jsx(
5027
+ !compactChrome && mode === "vod" && /* @__PURE__ */ jsxRuntime.jsx(
4967
5028
  MenuControl,
4968
5029
  {
4969
5030
  label: t.speed,
@@ -4987,7 +5048,7 @@ function VideoPlayer({
4987
5048
  ))
4988
5049
  }
4989
5050
  ),
4990
- showQualitySelector && qualities.length > 1 && /* @__PURE__ */ jsxRuntime.jsxs(
5051
+ !compactChrome && showQuality && /* @__PURE__ */ jsxRuntime.jsxs(
4991
5052
  MenuControl,
4992
5053
  {
4993
5054
  label: t.quality,
@@ -5019,7 +5080,7 @@ function VideoPlayer({
5019
5080
  ]
5020
5081
  }
5021
5082
  ),
5022
- /* @__PURE__ */ jsxRuntime.jsx(
5083
+ !compactChrome && /* @__PURE__ */ jsxRuntime.jsx(
5023
5084
  ControlButton,
5024
5085
  {
5025
5086
  label: t.cast,
@@ -5029,12 +5090,81 @@ function VideoPlayer({
5029
5090
  children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Cast, { className: "size-5" })
5030
5091
  }
5031
5092
  ),
5032
- pipSupported && /* @__PURE__ */ jsxRuntime.jsx(ControlButton, { label: t.pictureInPicture, onClick: togglePip, children: /* @__PURE__ */ jsxRuntime.jsx(
5093
+ !compactChrome && pipSupported && /* @__PURE__ */ jsxRuntime.jsx(ControlButton, { label: t.pictureInPicture, onClick: togglePip, children: /* @__PURE__ */ jsxRuntime.jsx(
5033
5094
  lucideReact.PictureInPicture2,
5034
5095
  {
5035
5096
  className: cn("size-5", pipActive && "text-primary")
5036
5097
  }
5037
5098
  ) }),
5099
+ compactChrome && /* @__PURE__ */ jsxRuntime.jsxs(
5100
+ MenuControl,
5101
+ {
5102
+ label: t.more,
5103
+ open: openMenu === "more",
5104
+ onOpenChange: (o) => setOpenMenu(o ? "more" : null),
5105
+ trigger: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EllipsisVertical, { className: "size-5" }),
5106
+ children: [
5107
+ mode === "vod" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5108
+ /* @__PURE__ */ jsxRuntime.jsx(MenuSection, { children: t.speed }),
5109
+ PLAYBACK_RATES.map((rate) => /* @__PURE__ */ jsxRuntime.jsxs(
5110
+ MenuItem,
5111
+ {
5112
+ selected: rate === playbackRate,
5113
+ onSelect: () => changeRate(rate),
5114
+ children: [
5115
+ rate,
5116
+ "\xD7"
5117
+ ]
5118
+ },
5119
+ rate
5120
+ ))
5121
+ ] }),
5122
+ showQuality && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5123
+ /* @__PURE__ */ jsxRuntime.jsx(MenuSection, { children: t.quality }),
5124
+ /* @__PURE__ */ jsxRuntime.jsx(
5125
+ MenuItem,
5126
+ {
5127
+ selected: activeLevel < 0,
5128
+ onSelect: () => chooseLevel(-1),
5129
+ children: t.auto
5130
+ }
5131
+ ),
5132
+ qualities.map((q) => /* @__PURE__ */ jsxRuntime.jsxs(
5133
+ MenuItem,
5134
+ {
5135
+ selected: activeLevel === q.index,
5136
+ onSelect: () => chooseLevel(q.index),
5137
+ children: [
5138
+ q.height,
5139
+ "p"
5140
+ ]
5141
+ },
5142
+ q.index
5143
+ ))
5144
+ ] }),
5145
+ /* @__PURE__ */ jsxRuntime.jsx(
5146
+ MenuAction,
5147
+ {
5148
+ onSelect: () => {
5149
+ setOpenMenu(null);
5150
+ void castHlsUrl(src).catch(() => void 0);
5151
+ },
5152
+ children: t.cast
5153
+ }
5154
+ ),
5155
+ pipSupported && /* @__PURE__ */ jsxRuntime.jsx(
5156
+ MenuAction,
5157
+ {
5158
+ onSelect: () => {
5159
+ setOpenMenu(null);
5160
+ togglePip();
5161
+ },
5162
+ children: t.pictureInPicture
5163
+ }
5164
+ )
5165
+ ]
5166
+ }
5167
+ ),
5038
5168
  fullscreenSupported && /* @__PURE__ */ jsxRuntime.jsx(
5039
5169
  ControlButton,
5040
5170
  {
@@ -5104,6 +5234,9 @@ function MenuControl({
5104
5234
  )
5105
5235
  ] });
5106
5236
  }
5237
+ function MenuSection({ children }) {
5238
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-2 pt-1.5 pb-0.5 text-[10px] font-semibold tracking-wide text-white/50 uppercase", children });
5239
+ }
5107
5240
  function MenuItem({
5108
5241
  selected,
5109
5242
  onSelect,
@@ -5124,6 +5257,21 @@ function MenuItem({
5124
5257
  }
5125
5258
  );
5126
5259
  }
5260
+ function MenuAction({
5261
+ onSelect,
5262
+ children
5263
+ }) {
5264
+ return /* @__PURE__ */ jsxRuntime.jsx(
5265
+ "button",
5266
+ {
5267
+ type: "button",
5268
+ role: "menuitem",
5269
+ onClick: onSelect,
5270
+ className: "flex w-full items-center rounded px-2 py-1.5 text-left text-white/90 hover:bg-white/15",
5271
+ children
5272
+ }
5273
+ );
5274
+ }
5127
5275
 
5128
5276
  // src/components/video/feedPlaybackCoordinator.ts
5129
5277
  var players = /* @__PURE__ */ new Map();