@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.cjs +180 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +180 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
() =>
|
|
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() {
|
|
@@ -4082,6 +4091,27 @@ async function loadLiveCaptions(url) {
|
|
|
4082
4091
|
return { ok: false, cues: [] };
|
|
4083
4092
|
}
|
|
4084
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
|
+
}
|
|
4085
4115
|
var NEAR_BOTTOM_PX = 24;
|
|
4086
4116
|
function LiveCaptionStack({ cues, latestLabel }) {
|
|
4087
4117
|
const scrollerRef = React9__namespace.useRef(null);
|
|
@@ -4143,7 +4173,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
|
|
|
4143
4173
|
ref: scrollerRef,
|
|
4144
4174
|
role: "log",
|
|
4145
4175
|
"aria-relevant": "additions",
|
|
4146
|
-
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-
|
|
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%]",
|
|
4147
4177
|
onScroll: (event) => {
|
|
4148
4178
|
if (ignoreScrollRef.current) return;
|
|
4149
4179
|
const scroller = event.currentTarget;
|
|
@@ -4155,7 +4185,7 @@ function LiveCaptionStack({ cues, latestLabel }) {
|
|
|
4155
4185
|
"p",
|
|
4156
4186
|
{
|
|
4157
4187
|
className: cn(
|
|
4158
|
-
"text-justify [text-align-last:left] leading-
|
|
4188
|
+
"text-justify [text-align-last:left] leading-snug break-words",
|
|
4159
4189
|
!prefersReduced && "transition-opacity"
|
|
4160
4190
|
),
|
|
4161
4191
|
children: cues.map((cue, index) => {
|
|
@@ -4183,6 +4213,46 @@ function LiveCaptionStack({ cues, latestLabel }) {
|
|
|
4183
4213
|
}
|
|
4184
4214
|
);
|
|
4185
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
|
+
}
|
|
4186
4256
|
var DEFAULT_LABELS3 = {
|
|
4187
4257
|
play: "Play",
|
|
4188
4258
|
pause: "Pause",
|
|
@@ -4218,19 +4288,15 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
|
4218
4288
|
var CONTROLS_HIDE_MS = 3e3;
|
|
4219
4289
|
var LIVE_EDGE_THRESHOLD_S = 8;
|
|
4220
4290
|
var SEEK_STEP_S = 5;
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
const webkit = asWebkitVideo(video);
|
|
4226
|
-
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;
|
|
4227
4295
|
}
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
if (document.fullscreenEnabled) return true;
|
|
4231
|
-
const doc = document;
|
|
4232
|
-
return !!doc.webkitFullscreenEnabled;
|
|
4296
|
+
.livo-video-player-media::-webkit-media-controls {
|
|
4297
|
+
display: none !important;
|
|
4233
4298
|
}
|
|
4299
|
+
`;
|
|
4234
4300
|
function captionLocaleLabel(locale, labels) {
|
|
4235
4301
|
switch (locale) {
|
|
4236
4302
|
case "en":
|
|
@@ -4276,6 +4342,9 @@ function VideoPlayer({
|
|
|
4276
4342
|
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
4277
4343
|
const containerRef = React9__namespace.useRef(null);
|
|
4278
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);
|
|
4279
4348
|
const [userStarted, setUserStarted] = React9__namespace.useState(false);
|
|
4280
4349
|
const active = autoPlay || !poster || userStarted;
|
|
4281
4350
|
const autoplayActive = autoPlay || userStarted;
|
|
@@ -4327,9 +4396,12 @@ function VideoPlayer({
|
|
|
4327
4396
|
const [liveLagMs, setLiveLagMs] = React9__namespace.useState(null);
|
|
4328
4397
|
const [behindLive, setBehindLive] = React9__namespace.useState(false);
|
|
4329
4398
|
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9__namespace.useState(false);
|
|
4399
|
+
const [embedded, setEmbedded] = React9__namespace.useState(false);
|
|
4400
|
+
const [cssFullscreen, setCssFullscreen] = React9__namespace.useState(false);
|
|
4330
4401
|
const hideTimerRef = React9__namespace.useRef(null);
|
|
4402
|
+
cssFullscreenRef.current = cssFullscreen;
|
|
4331
4403
|
const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
|
|
4332
|
-
const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
|
|
4404
|
+
const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported || !embedded;
|
|
4333
4405
|
React9__namespace.useEffect(() => {
|
|
4334
4406
|
const video = videoRef.current;
|
|
4335
4407
|
if (!video || !active) return;
|
|
@@ -4382,19 +4454,36 @@ function VideoPlayer({
|
|
|
4382
4454
|
video.pause();
|
|
4383
4455
|
}, [paused, videoRef, isPlaying]);
|
|
4384
4456
|
React9__namespace.useEffect(() => {
|
|
4457
|
+
setEmbedded(isEmbeddedWindow());
|
|
4385
4458
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4386
4459
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4460
|
+
videoRef.current?.setAttribute("webkit-playsinline", "");
|
|
4387
4461
|
}, [videoRef, active]);
|
|
4388
4462
|
React9__namespace.useEffect(() => {
|
|
4389
|
-
const onFsChange = () =>
|
|
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
|
+
};
|
|
4390
4471
|
document.addEventListener("fullscreenchange", onFsChange);
|
|
4391
4472
|
return () => document.removeEventListener("fullscreenchange", onFsChange);
|
|
4392
4473
|
}, []);
|
|
4393
4474
|
React9__namespace.useEffect(() => {
|
|
4394
4475
|
const video = asWebkitVideo(videoRef.current);
|
|
4395
4476
|
if (!video) return;
|
|
4396
|
-
const onBegin = () =>
|
|
4397
|
-
|
|
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
|
+
};
|
|
4398
4487
|
video.addEventListener("webkitbeginfullscreen", onBegin);
|
|
4399
4488
|
video.addEventListener("webkitendfullscreen", onEnd);
|
|
4400
4489
|
return () => {
|
|
@@ -4402,6 +4491,21 @@ function VideoPlayer({
|
|
|
4402
4491
|
video.removeEventListener("webkitendfullscreen", onEnd);
|
|
4403
4492
|
};
|
|
4404
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]);
|
|
4405
4509
|
React9__namespace.useEffect(() => {
|
|
4406
4510
|
const video = videoRef.current;
|
|
4407
4511
|
if (!video) return;
|
|
@@ -4471,6 +4575,39 @@ function VideoPlayer({
|
|
|
4471
4575
|
liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
|
|
4472
4576
|
) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
|
|
4473
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]);
|
|
4474
4611
|
function togglePlay() {
|
|
4475
4612
|
const video = videoRef.current;
|
|
4476
4613
|
if (!video) return;
|
|
@@ -4505,6 +4642,10 @@ function VideoPlayer({
|
|
|
4505
4642
|
video.currentTime = video.seekable.end(video.seekable.length - 1);
|
|
4506
4643
|
if (video.paused) void video.play();
|
|
4507
4644
|
}
|
|
4645
|
+
function exitCssFullscreen() {
|
|
4646
|
+
setCssFullscreen(false);
|
|
4647
|
+
setIsFullscreen(false);
|
|
4648
|
+
}
|
|
4508
4649
|
function toggleFullscreen() {
|
|
4509
4650
|
const el = containerRef.current;
|
|
4510
4651
|
const video = asWebkitVideo(videoRef.current);
|
|
@@ -4516,13 +4657,20 @@ function VideoPlayer({
|
|
|
4516
4657
|
video.webkitExitFullscreen();
|
|
4517
4658
|
return;
|
|
4518
4659
|
}
|
|
4660
|
+
if (cssFullscreen) {
|
|
4661
|
+
exitCssFullscreen();
|
|
4662
|
+
return;
|
|
4663
|
+
}
|
|
4519
4664
|
if (el && hasStandardFullscreen() && typeof el.requestFullscreen === "function") {
|
|
4520
4665
|
void el.requestFullscreen();
|
|
4521
4666
|
return;
|
|
4522
4667
|
}
|
|
4523
|
-
if (video && typeof video.webkitEnterFullscreen === "function") {
|
|
4668
|
+
if (embedded && video && typeof video.webkitEnterFullscreen === "function") {
|
|
4524
4669
|
video.webkitEnterFullscreen();
|
|
4670
|
+
return;
|
|
4525
4671
|
}
|
|
4672
|
+
setCssFullscreen(true);
|
|
4673
|
+
setIsFullscreen(true);
|
|
4526
4674
|
}
|
|
4527
4675
|
function togglePip() {
|
|
4528
4676
|
const video = videoRef.current;
|
|
@@ -4557,6 +4705,12 @@ function VideoPlayer({
|
|
|
4557
4705
|
case "f":
|
|
4558
4706
|
toggleFullscreen();
|
|
4559
4707
|
break;
|
|
4708
|
+
case "Escape":
|
|
4709
|
+
if (cssFullscreen) {
|
|
4710
|
+
e.preventDefault();
|
|
4711
|
+
exitCssFullscreen();
|
|
4712
|
+
}
|
|
4713
|
+
break;
|
|
4560
4714
|
case "ArrowLeft":
|
|
4561
4715
|
if (mode === "vod") {
|
|
4562
4716
|
e.preventDefault();
|
|
@@ -4612,9 +4766,11 @@ function VideoPlayer({
|
|
|
4612
4766
|
"data-slot": "video-player",
|
|
4613
4767
|
"data-mode": mode,
|
|
4614
4768
|
"data-fit": fit,
|
|
4769
|
+
"data-css-fullscreen": cssFullscreen ? "" : void 0,
|
|
4615
4770
|
className: cn(
|
|
4616
|
-
"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",
|
|
4617
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",
|
|
4618
4774
|
className
|
|
4619
4775
|
),
|
|
4620
4776
|
onMouseMove: revealControls,
|
|
@@ -4626,13 +4782,14 @@ function VideoPlayer({
|
|
|
4626
4782
|
role: "region",
|
|
4627
4783
|
"aria-label": "Video player",
|
|
4628
4784
|
children: [
|
|
4785
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: VIDEO_MEDIA_STYLE }),
|
|
4629
4786
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4630
4787
|
"video",
|
|
4631
4788
|
{
|
|
4632
4789
|
ref: videoRef,
|
|
4633
4790
|
playsInline: true,
|
|
4634
4791
|
muted: isMuted,
|
|
4635
|
-
className: "h-full w-full bg-black object-contain",
|
|
4792
|
+
className: "livo-video-player-media h-full w-full bg-black object-contain",
|
|
4636
4793
|
onClick: active ? togglePlay : void 0,
|
|
4637
4794
|
poster
|
|
4638
4795
|
}
|
|
@@ -4671,7 +4828,7 @@ function VideoPlayer({
|
|
|
4671
4828
|
}
|
|
4672
4829
|
)
|
|
4673
4830
|
] }),
|
|
4674
|
-
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(
|
|
4675
4832
|
"button",
|
|
4676
4833
|
{
|
|
4677
4834
|
type: "button",
|
|
@@ -4706,7 +4863,7 @@ function VideoPlayer({
|
|
|
4706
4863
|
{
|
|
4707
4864
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4708
4865
|
"data-slot": "video-captions",
|
|
4709
|
-
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-
|
|
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 })
|
|
4710
4867
|
}
|
|
4711
4868
|
),
|
|
4712
4869
|
active && /* @__PURE__ */ jsxRuntime.jsxs(
|