@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 +215 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +215 -224
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -776,7 +776,7 @@ interface VideoPlayerLabels {
|
|
|
776
776
|
captionsEn?: string;
|
|
777
777
|
captionsEs?: string;
|
|
778
778
|
captionsPt?: string;
|
|
779
|
-
/**
|
|
779
|
+
/** @deprecated Unused after movie-style captions; kept for existing callers. */
|
|
780
780
|
captionsLatest?: string;
|
|
781
781
|
}
|
|
782
782
|
interface VideoPlayerProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -776,7 +776,7 @@ interface VideoPlayerLabels {
|
|
|
776
776
|
captionsEn?: string;
|
|
777
777
|
captionsEs?: string;
|
|
778
778
|
captionsPt?: string;
|
|
779
|
-
/**
|
|
779
|
+
/** @deprecated Unused after movie-style captions; kept for existing callers. */
|
|
780
780
|
captionsLatest?: string;
|
|
781
781
|
}
|
|
782
782
|
interface VideoPlayerProps {
|
package/dist/index.js
CHANGED
|
@@ -3877,19 +3877,28 @@ function useHlsPlayback({
|
|
|
3877
3877
|
};
|
|
3878
3878
|
}
|
|
3879
3879
|
|
|
3880
|
-
// src/components/video/appleMobile.ts
|
|
3881
|
-
function isAppleMobileDevice(nav = navigator) {
|
|
3882
|
-
if (/iP(hone|ad|od)/.test(nav.userAgent)) return true;
|
|
3883
|
-
return nav.platform === "MacIntel" && nav.maxTouchPoints > 1;
|
|
3884
|
-
}
|
|
3885
|
-
|
|
3886
3880
|
// src/components/video/captions.ts
|
|
3887
3881
|
var CAPTION_LOCALES = ["en", "es", "pt"];
|
|
3888
3882
|
var LIVE_CUE_EXTRA_LAG_MS = 2e3;
|
|
3889
3883
|
var LIVE_STACK_MAX_CUES = 150;
|
|
3890
|
-
var
|
|
3891
|
-
var
|
|
3884
|
+
var CAPTION_CHARS_PER_SECOND = 17;
|
|
3885
|
+
var CAPTION_MIN_DWELL_MS = 1200;
|
|
3886
|
+
var CAPTION_MAX_DWELL_MS = 6e3;
|
|
3887
|
+
var CAPTION_RUSH_DWELL_MS = 2500;
|
|
3888
|
+
var CAPTION_MAX_CHARS_PER_LINE = 42;
|
|
3889
|
+
var CAPTION_COMPACT_CHARS_PER_LINE = 32;
|
|
3890
|
+
var CAPTION_MAX_LINES = 2;
|
|
3891
|
+
var CAPTION_BACKLOG_DROP = 8;
|
|
3892
|
+
var CAPTION_GAP_FILL_MS = 1e3;
|
|
3892
3893
|
var LIVE_LAG_SPIKE_MS = 2500;
|
|
3894
|
+
var CAPTION_BREAK_PUNCT = /[.,;:?!]$/;
|
|
3895
|
+
var CAPTION_MIN_PUNCT_LINE = 8;
|
|
3896
|
+
var EMPTY_LIVE_CAPTION_PLAYOUT = {
|
|
3897
|
+
screen: null,
|
|
3898
|
+
hideAt: 0,
|
|
3899
|
+
cursor: 0,
|
|
3900
|
+
queue: []
|
|
3901
|
+
};
|
|
3893
3902
|
function stabilizeLiveLagMs(previous, next) {
|
|
3894
3903
|
if (previous == null || !Number.isFinite(previous)) return next;
|
|
3895
3904
|
if (next <= previous) return next;
|
|
@@ -3899,22 +3908,6 @@ function stabilizeLiveLagMs(previous, next) {
|
|
|
3899
3908
|
function isCaptionLocale(value) {
|
|
3900
3909
|
return CAPTION_LOCALES.includes(value);
|
|
3901
3910
|
}
|
|
3902
|
-
function isLivePlaylistSrc(src) {
|
|
3903
|
-
return /\/live\//i.test(src);
|
|
3904
|
-
}
|
|
3905
|
-
function zeroAnchorCaptionCues(cues) {
|
|
3906
|
-
if (cues.length === 0) return cues;
|
|
3907
|
-
let origin = Number.POSITIVE_INFINITY;
|
|
3908
|
-
for (const cue of cues) {
|
|
3909
|
-
if (Number.isFinite(cue.start) && cue.start < origin) origin = cue.start;
|
|
3910
|
-
}
|
|
3911
|
-
if (!Number.isFinite(origin) || origin <= 0) return cues;
|
|
3912
|
-
return cues.map((cue) => ({
|
|
3913
|
-
...cue,
|
|
3914
|
-
start: Math.max(0, cue.start - origin),
|
|
3915
|
-
end: Math.max(0, cue.end - origin)
|
|
3916
|
-
}));
|
|
3917
|
-
}
|
|
3918
3911
|
function captionsVttUrlFromPlayback(src, locale) {
|
|
3919
3912
|
const trimmed = src.trim();
|
|
3920
3913
|
if (!trimmed) return null;
|
|
@@ -3950,26 +3943,148 @@ function parseCaptionVtt(text) {
|
|
|
3950
3943
|
}
|
|
3951
3944
|
return cues;
|
|
3952
3945
|
}
|
|
3953
|
-
function
|
|
3954
|
-
|
|
3955
|
-
if (matched) return matched;
|
|
3956
|
-
return null;
|
|
3946
|
+
function captionScreenRow(text, speaker) {
|
|
3947
|
+
return speaker == null ? { text } : { text, speaker };
|
|
3957
3948
|
}
|
|
3958
|
-
function
|
|
3959
|
-
if (
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3949
|
+
function chunkLongWord(word, maxCharsPerLine) {
|
|
3950
|
+
if (word.length <= maxCharsPerLine) return [word];
|
|
3951
|
+
const parts = [];
|
|
3952
|
+
for (let index = 0; index < word.length; index += maxCharsPerLine) {
|
|
3953
|
+
parts.push(word.slice(index, index + maxCharsPerLine));
|
|
3954
|
+
}
|
|
3955
|
+
return parts;
|
|
3956
|
+
}
|
|
3957
|
+
function wrapCaptionLines(text, maxCharsPerLine) {
|
|
3958
|
+
const tokens = text.split(" ").filter(Boolean).flatMap((word) => chunkLongWord(word, maxCharsPerLine));
|
|
3959
|
+
const lines = [];
|
|
3960
|
+
let index = 0;
|
|
3961
|
+
while (index < tokens.length) {
|
|
3962
|
+
let end = index;
|
|
3963
|
+
let length = 0;
|
|
3964
|
+
while (end < tokens.length) {
|
|
3965
|
+
const added = tokens[end].length + (end > index ? 1 : 0);
|
|
3966
|
+
if (length + added > maxCharsPerLine && end > index) break;
|
|
3967
|
+
length += added;
|
|
3968
|
+
end += 1;
|
|
3969
|
+
}
|
|
3970
|
+
let breakAt = end;
|
|
3971
|
+
if (end < tokens.length) {
|
|
3972
|
+
for (let cursor = end - 1; cursor > index; cursor -= 1) {
|
|
3973
|
+
if (!CAPTION_BREAK_PUNCT.test(tokens[cursor])) continue;
|
|
3974
|
+
const firstLen = tokens.slice(index, cursor + 1).join(" ").length;
|
|
3975
|
+
if (firstLen >= Math.min(CAPTION_MIN_PUNCT_LINE, maxCharsPerLine)) {
|
|
3976
|
+
breakAt = cursor + 1;
|
|
3977
|
+
}
|
|
3978
|
+
break;
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
lines.push(tokens.slice(index, breakAt).join(" "));
|
|
3982
|
+
index = breakAt;
|
|
3983
|
+
}
|
|
3984
|
+
return lines;
|
|
3985
|
+
}
|
|
3986
|
+
function balanceCaptionLines(lines, maxCharsPerLine) {
|
|
3987
|
+
const next = [...lines];
|
|
3988
|
+
for (let index = 0; index + 1 < next.length; index += CAPTION_MAX_LINES) {
|
|
3989
|
+
const left = next[index].split(" ");
|
|
3990
|
+
const right = next[index + 1].split(" ");
|
|
3991
|
+
if (right.length !== 1 || left.length < 3) continue;
|
|
3992
|
+
const moved = left[left.length - 1];
|
|
3993
|
+
const newRight = `${moved} ${right[0]}`;
|
|
3994
|
+
if (newRight.length > maxCharsPerLine) continue;
|
|
3995
|
+
next[index] = left.slice(0, -1).join(" ");
|
|
3996
|
+
next[index + 1] = newRight;
|
|
3997
|
+
}
|
|
3998
|
+
return next;
|
|
3966
3999
|
}
|
|
3967
|
-
function
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
(
|
|
3972
|
-
|
|
4000
|
+
function splitCaptionScreens(text, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4001
|
+
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
4002
|
+
if (!trimmed) return [];
|
|
4003
|
+
const lines = balanceCaptionLines(
|
|
4004
|
+
wrapCaptionLines(trimmed, maxCharsPerLine),
|
|
4005
|
+
maxCharsPerLine
|
|
4006
|
+
);
|
|
4007
|
+
const screens = [];
|
|
4008
|
+
for (let index = 0; index < lines.length; index += CAPTION_MAX_LINES) {
|
|
4009
|
+
screens.push(lines.slice(index, index + CAPTION_MAX_LINES).join("\n"));
|
|
4010
|
+
}
|
|
4011
|
+
return screens;
|
|
4012
|
+
}
|
|
4013
|
+
function captionDwellMs(text, backlog = 0) {
|
|
4014
|
+
const chars = text.replace(/\s+/g, " ").trim().length;
|
|
4015
|
+
const raw = chars / CAPTION_CHARS_PER_SECOND * 1e3;
|
|
4016
|
+
const max = backlog > 0 ? CAPTION_RUSH_DWELL_MS : CAPTION_MAX_DWELL_MS;
|
|
4017
|
+
return Math.min(max, Math.max(CAPTION_MIN_DWELL_MS, raw));
|
|
4018
|
+
}
|
|
4019
|
+
function advanceLiveCaptionPlayout(state, cues, now, lagMs, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4020
|
+
let screen = state.screen;
|
|
4021
|
+
let hideAt = state.hideAt;
|
|
4022
|
+
let cursor = state.cursor;
|
|
4023
|
+
let queue = state.queue.slice();
|
|
4024
|
+
if (lagMs != null && Number.isFinite(lagMs) && lagMs >= 0) {
|
|
4025
|
+
const threshold = lagMs + LIVE_CUE_EXTRA_LAG_MS;
|
|
4026
|
+
const incoming = cues.filter(
|
|
4027
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.receivedAt) && cue.receivedAt > cursor && now - cue.receivedAt >= threshold
|
|
4028
|
+
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
4029
|
+
for (const cue of incoming) {
|
|
4030
|
+
for (const text of splitCaptionScreens(cue.text, maxCharsPerLine)) {
|
|
4031
|
+
queue.push(captionScreenRow(text, cue.speaker));
|
|
4032
|
+
}
|
|
4033
|
+
cursor = cue.receivedAt;
|
|
4034
|
+
}
|
|
4035
|
+
if (queue.length > CAPTION_BACKLOG_DROP) {
|
|
4036
|
+
queue = queue.slice(queue.length - CAPTION_BACKLOG_DROP);
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
if (now >= hideAt) {
|
|
4040
|
+
const next = queue.shift();
|
|
4041
|
+
if (next) {
|
|
4042
|
+
screen = next;
|
|
4043
|
+
hideAt = now + captionDwellMs(next.text, queue.length);
|
|
4044
|
+
} else {
|
|
4045
|
+
screen = null;
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4048
|
+
return { screen, hideAt, cursor, queue };
|
|
4049
|
+
}
|
|
4050
|
+
function cueEndWithGapFill(cues, index) {
|
|
4051
|
+
const cue = cues[index];
|
|
4052
|
+
if (!cue) return 0;
|
|
4053
|
+
const next = cues[index + 1];
|
|
4054
|
+
if (!next || !Number.isFinite(next.start)) return cue.end;
|
|
4055
|
+
const gapMs = (next.start - cue.end) * 1e3;
|
|
4056
|
+
if (gapMs > 0 && gapMs < CAPTION_GAP_FILL_MS) return next.start;
|
|
4057
|
+
return cue.end;
|
|
4058
|
+
}
|
|
4059
|
+
function captionScreenAtTime(cues, time, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4060
|
+
if (!Number.isFinite(time)) return null;
|
|
4061
|
+
const ordered = cues.filter(
|
|
4062
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && Number.isFinite(cue.end)
|
|
4063
|
+
).sort((left, right) => left.start - right.start);
|
|
4064
|
+
for (let index = 0; index < ordered.length; index += 1) {
|
|
4065
|
+
const cue = ordered[index];
|
|
4066
|
+
const end = cueEndWithGapFill(ordered, index);
|
|
4067
|
+
if (time < cue.start || time >= end) continue;
|
|
4068
|
+
const screens = splitCaptionScreens(cue.text, maxCharsPerLine);
|
|
4069
|
+
if (screens.length === 0) return null;
|
|
4070
|
+
const weights = screens.map(
|
|
4071
|
+
(text) => Math.max(1, text.replace(/\s+/g, "").length)
|
|
4072
|
+
);
|
|
4073
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
4074
|
+
const duration = Math.max(end - cue.start, 0);
|
|
4075
|
+
let cursor = cue.start;
|
|
4076
|
+
for (let screenIndex = 0; screenIndex < screens.length; screenIndex += 1) {
|
|
4077
|
+
const isLast = screenIndex === screens.length - 1;
|
|
4078
|
+
const slice = isLast ? end - cursor : duration * (weights[screenIndex] / total);
|
|
4079
|
+
const sliceEnd = cursor + slice;
|
|
4080
|
+
if (time >= cursor && time < sliceEnd) {
|
|
4081
|
+
return captionScreenRow(screens[screenIndex]);
|
|
4082
|
+
}
|
|
4083
|
+
cursor = sliceEnd;
|
|
4084
|
+
}
|
|
4085
|
+
return captionScreenRow(screens[screens.length - 1]);
|
|
4086
|
+
}
|
|
4087
|
+
return null;
|
|
3973
4088
|
}
|
|
3974
4089
|
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
3975
4090
|
function normalizeLiveCaptionText(text) {
|
|
@@ -4044,17 +4159,6 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
4044
4159
|
}
|
|
4045
4160
|
return out;
|
|
4046
4161
|
}
|
|
4047
|
-
function lastLiveCaptionWindow(cues, maxCues = IOS_CAPTION_WINDOW_LINES) {
|
|
4048
|
-
return cues.slice(-Math.max(1, maxCues));
|
|
4049
|
-
}
|
|
4050
|
-
function lastCaptionLines(text, lines = IOS_CAPTION_WINDOW_LINES, charsPerLine = IOS_CAPTION_CHARS_PER_LINE) {
|
|
4051
|
-
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
4052
|
-
const maxChars = Math.max(1, lines) * Math.max(1, charsPerLine);
|
|
4053
|
-
if (trimmed.length <= maxChars) return trimmed;
|
|
4054
|
-
const slice = trimmed.slice(-maxChars);
|
|
4055
|
-
const space = slice.indexOf(" ");
|
|
4056
|
-
return (space > 0 ? slice.slice(space + 1) : slice).trim();
|
|
4057
|
-
}
|
|
4058
4162
|
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
4059
4163
|
const map = /* @__PURE__ */ new Map();
|
|
4060
4164
|
for (const cue of existing) {
|
|
@@ -4130,121 +4234,29 @@ function isEmbeddedWindow(win = window) {
|
|
|
4130
4234
|
return true;
|
|
4131
4235
|
}
|
|
4132
4236
|
}
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
latestLabel,
|
|
4137
|
-
variant = "scroll"
|
|
4138
|
-
}) {
|
|
4139
|
-
const scrollerRef = React9.useRef(null);
|
|
4140
|
-
const followRef = React9.useRef(true);
|
|
4141
|
-
const ignoreScrollRef = React9.useRef(false);
|
|
4142
|
-
const [following, setFollowing] = React9.useState(true);
|
|
4143
|
-
const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
|
|
4144
|
-
const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
|
|
4145
|
-
const scrollToLatest = React9.useCallback(() => {
|
|
4146
|
-
const scroller = scrollerRef.current;
|
|
4147
|
-
if (!scroller) return;
|
|
4148
|
-
ignoreScrollRef.current = true;
|
|
4149
|
-
scroller.scrollTo({
|
|
4150
|
-
top: scroller.scrollHeight,
|
|
4151
|
-
behavior: prefersReduced ? "auto" : "smooth"
|
|
4152
|
-
});
|
|
4153
|
-
followRef.current = true;
|
|
4154
|
-
setFollowing(true);
|
|
4155
|
-
window.requestAnimationFrame(() => {
|
|
4156
|
-
window.requestAnimationFrame(() => {
|
|
4157
|
-
ignoreScrollRef.current = false;
|
|
4158
|
-
});
|
|
4159
|
-
});
|
|
4160
|
-
}, [prefersReduced]);
|
|
4237
|
+
function CaptionOverlay({ screen }) {
|
|
4238
|
+
const lastSpeakerRef = React9.useRef(void 0);
|
|
4239
|
+
const lastSpeaker = lastSpeakerRef.current;
|
|
4161
4240
|
React9.useLayoutEffect(() => {
|
|
4162
|
-
if (
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
top: scroller.scrollHeight,
|
|
4168
|
-
behavior: prefersReduced ? "auto" : "smooth"
|
|
4169
|
-
});
|
|
4170
|
-
window.requestAnimationFrame(() => {
|
|
4171
|
-
window.requestAnimationFrame(() => {
|
|
4172
|
-
ignoreScrollRef.current = false;
|
|
4173
|
-
});
|
|
4174
|
-
});
|
|
4175
|
-
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
4176
|
-
if (cues.length === 0) return null;
|
|
4177
|
-
const windowed = variant === "window";
|
|
4178
|
-
const distinctSpeakers = new Set(
|
|
4179
|
-
cues.map((cue) => cue.speaker).filter((speaker) => speaker != null)
|
|
4180
|
-
);
|
|
4181
|
-
const showTurns = distinctSpeakers.size >= 2;
|
|
4241
|
+
if (screen?.speaker != null) lastSpeakerRef.current = screen.speaker;
|
|
4242
|
+
}, [screen]);
|
|
4243
|
+
if (!screen) return null;
|
|
4244
|
+
const turnDash = screen.speaker != null && lastSpeaker != null && screen.speaker !== lastSpeaker;
|
|
4245
|
+
const text = turnDash ? `\u2013 ${screen.text}` : screen.text;
|
|
4182
4246
|
return /* @__PURE__ */ jsx(
|
|
4183
4247
|
"div",
|
|
4184
4248
|
{
|
|
4185
4249
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4186
4250
|
"data-slot": "video-captions",
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
"
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
}
|
|
4197
|
-
),
|
|
4198
|
-
/* @__PURE__ */ jsx(
|
|
4199
|
-
"div",
|
|
4200
|
-
{
|
|
4201
|
-
ref: windowed ? void 0 : scrollerRef,
|
|
4202
|
-
role: "log",
|
|
4203
|
-
"aria-relevant": "additions",
|
|
4204
|
-
className: cn(
|
|
4205
|
-
"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%]",
|
|
4206
|
-
windowed ? "overflow-hidden" : "pointer-events-auto max-h-[min(4.5rem,18cqh)] overflow-x-hidden overflow-y-auto"
|
|
4207
|
-
),
|
|
4208
|
-
onScroll: windowed ? void 0 : (event) => {
|
|
4209
|
-
if (ignoreScrollRef.current) return;
|
|
4210
|
-
const scroller = event.currentTarget;
|
|
4211
|
-
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
|
|
4212
|
-
followRef.current = nearBottom;
|
|
4213
|
-
setFollowing(nearBottom);
|
|
4214
|
-
},
|
|
4215
|
-
children: /* @__PURE__ */ jsx(
|
|
4216
|
-
"p",
|
|
4217
|
-
{
|
|
4218
|
-
className: cn(
|
|
4219
|
-
"text-justify [text-align-last:left] leading-snug break-words",
|
|
4220
|
-
windowed && "line-clamp-3",
|
|
4221
|
-
!prefersReduced && "transition-opacity"
|
|
4222
|
-
),
|
|
4223
|
-
children: cues.map((cue, index) => {
|
|
4224
|
-
const fromEnd = cues.length - 1 - index;
|
|
4225
|
-
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4226
|
-
const newest = fromEnd === 0;
|
|
4227
|
-
const previous = cues[index - 1];
|
|
4228
|
-
const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
|
|
4229
|
-
return /* @__PURE__ */ jsxs(
|
|
4230
|
-
"span",
|
|
4231
|
-
{
|
|
4232
|
-
style: { opacity },
|
|
4233
|
-
"aria-live": newest ? "polite" : void 0,
|
|
4234
|
-
children: [
|
|
4235
|
-
turnStart && index > 0 ? /* @__PURE__ */ jsx("br", {}) : index > 0 ? " " : "",
|
|
4236
|
-
turnStart ? "\u2013 " : "",
|
|
4237
|
-
cue.text
|
|
4238
|
-
]
|
|
4239
|
-
},
|
|
4240
|
-
cue.receivedAt
|
|
4241
|
-
);
|
|
4242
|
-
})
|
|
4243
|
-
}
|
|
4244
|
-
)
|
|
4245
|
-
}
|
|
4246
|
-
)
|
|
4247
|
-
] })
|
|
4251
|
+
children: /* @__PURE__ */ jsx(
|
|
4252
|
+
"p",
|
|
4253
|
+
{
|
|
4254
|
+
role: "status",
|
|
4255
|
+
"aria-live": "polite",
|
|
4256
|
+
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%]",
|
|
4257
|
+
children: text
|
|
4258
|
+
}
|
|
4259
|
+
)
|
|
4248
4260
|
}
|
|
4249
4261
|
);
|
|
4250
4262
|
}
|
|
@@ -4252,9 +4264,6 @@ function LiveCaptionStack({
|
|
|
4252
4264
|
// src/components/video/nativeCaptionTrack.ts
|
|
4253
4265
|
var NATIVE_CAPTION_HOLD_S = 4;
|
|
4254
4266
|
var NATIVE_SUBTITLE_KIND = "subtitles";
|
|
4255
|
-
function joinCaptionTexts(cues) {
|
|
4256
|
-
return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
|
|
4257
|
-
}
|
|
4258
4267
|
function clearNativeCaptionCues(track) {
|
|
4259
4268
|
const cues = track.cues;
|
|
4260
4269
|
if (!cues) return;
|
|
@@ -4304,38 +4313,13 @@ function ensureLiveSubtitleTracks(video, labels) {
|
|
|
4304
4313
|
return track;
|
|
4305
4314
|
});
|
|
4306
4315
|
}
|
|
4307
|
-
function syncNativeCaptionCue(video, track, text) {
|
|
4316
|
+
function syncNativeCaptionCue(video, track, text, holdSeconds = NATIVE_CAPTION_HOLD_S) {
|
|
4308
4317
|
clearNativeCaptionCues(track);
|
|
4309
4318
|
const trimmed = text.trim();
|
|
4310
4319
|
if (!trimmed) return;
|
|
4311
4320
|
const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
function zeroAnchorNativeTrackCues(track) {
|
|
4315
|
-
const list = track.cues;
|
|
4316
|
-
if (!list || list.length === 0) return;
|
|
4317
|
-
let origin = Number.POSITIVE_INFINITY;
|
|
4318
|
-
for (let index = 0; index < list.length; index += 1) {
|
|
4319
|
-
const cue = list[index];
|
|
4320
|
-
if (cue && Number.isFinite(cue.startTime) && cue.startTime < origin) {
|
|
4321
|
-
origin = cue.startTime;
|
|
4322
|
-
}
|
|
4323
|
-
}
|
|
4324
|
-
if (!Number.isFinite(origin) || origin <= 0) return;
|
|
4325
|
-
const next = [];
|
|
4326
|
-
for (let index = 0; index < list.length; index += 1) {
|
|
4327
|
-
const cue = list[index];
|
|
4328
|
-
if (!(cue instanceof VTTCue)) continue;
|
|
4329
|
-
next.push(
|
|
4330
|
-
new VTTCue(
|
|
4331
|
-
Math.max(0, cue.startTime - origin),
|
|
4332
|
-
Math.max(0, cue.endTime - origin),
|
|
4333
|
-
cue.text
|
|
4334
|
-
)
|
|
4335
|
-
);
|
|
4336
|
-
}
|
|
4337
|
-
clearNativeCaptionCues(track);
|
|
4338
|
-
for (const cue of next) track.addCue(cue);
|
|
4321
|
+
const hold = Number.isFinite(holdSeconds) ? Math.max(0.2, holdSeconds) : NATIVE_CAPTION_HOLD_S;
|
|
4322
|
+
track.addCue(new VTTCue(start, start + hold, trimmed));
|
|
4339
4323
|
}
|
|
4340
4324
|
function listenTextTracksChange(tracks, onChange) {
|
|
4341
4325
|
if (typeof tracks.addEventListener === "function") {
|
|
@@ -4388,6 +4372,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
|
4388
4372
|
var CONTROLS_HIDE_MS = 3e3;
|
|
4389
4373
|
var LIVE_EDGE_THRESHOLD_S = 8;
|
|
4390
4374
|
var SEEK_STEP_S = 5;
|
|
4375
|
+
var LIVE_CAPTION_PLAYOUT_MS = 250;
|
|
4391
4376
|
var COMPACT_CHROME_PX = 640;
|
|
4392
4377
|
var VIDEO_MEDIA_STYLE = `
|
|
4393
4378
|
.livo-video-player-media::-webkit-media-controls-start-playback-button {
|
|
@@ -4499,14 +4484,22 @@ function VideoPlayer({
|
|
|
4499
4484
|
const [captionLocale, setCaptionLocale] = React9.useState(defaultCaptionLocale ?? "off");
|
|
4500
4485
|
const [captionCues, setCaptionCues] = React9.useState([]);
|
|
4501
4486
|
const [liveCaptionCues, setLiveCaptionCues] = React9.useState([]);
|
|
4487
|
+
const [livePlayout, setLivePlayout] = React9.useState(
|
|
4488
|
+
EMPTY_LIVE_CAPTION_PLAYOUT
|
|
4489
|
+
);
|
|
4502
4490
|
const [liveLagMs, setLiveLagMs] = React9.useState(null);
|
|
4503
4491
|
const [behindLive, setBehindLive] = React9.useState(false);
|
|
4504
4492
|
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9.useState(false);
|
|
4505
4493
|
const [embedded, setEmbedded] = React9.useState(false);
|
|
4506
4494
|
const [cssFullscreen, setCssFullscreen] = React9.useState(false);
|
|
4507
|
-
const [appleMobile, setAppleMobile] = React9.useState(false);
|
|
4508
4495
|
const [webkitNativeFs, setWebkitNativeFs] = React9.useState(false);
|
|
4509
4496
|
const hideTimerRef = React9.useRef(null);
|
|
4497
|
+
const liveCaptionCuesRef = React9.useRef(liveCaptionCues);
|
|
4498
|
+
const liveLagMsRef = React9.useRef(liveLagMs);
|
|
4499
|
+
const compactChromeRef = React9.useRef(compactChrome);
|
|
4500
|
+
liveCaptionCuesRef.current = liveCaptionCues;
|
|
4501
|
+
liveLagMsRef.current = liveLagMs;
|
|
4502
|
+
compactChromeRef.current = compactChrome;
|
|
4510
4503
|
cssFullscreenRef.current = cssFullscreen;
|
|
4511
4504
|
captionLocaleRef.current = captionLocale;
|
|
4512
4505
|
React9.useEffect(() => {
|
|
@@ -4582,7 +4575,6 @@ function VideoPlayer({
|
|
|
4582
4575
|
}, [paused, videoRef, isPlaying]);
|
|
4583
4576
|
React9.useEffect(() => {
|
|
4584
4577
|
setEmbedded(isEmbeddedWindow());
|
|
4585
|
-
setAppleMobile(isAppleMobileDevice());
|
|
4586
4578
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4587
4579
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4588
4580
|
videoRef.current?.setAttribute("webkit-playsinline", "");
|
|
@@ -4610,9 +4602,6 @@ function VideoPlayer({
|
|
|
4610
4602
|
function onSidecarTrackLoad(event) {
|
|
4611
4603
|
const track = event.currentTarget.track;
|
|
4612
4604
|
if (!track) return;
|
|
4613
|
-
if (isLivePlaylistSrc(src)) {
|
|
4614
|
-
zeroAnchorNativeTrackCues(track);
|
|
4615
|
-
}
|
|
4616
4605
|
const video = videoRef.current;
|
|
4617
4606
|
if (video) {
|
|
4618
4607
|
applyNativeTrackModes(
|
|
@@ -4712,8 +4701,7 @@ function VideoPlayer({
|
|
|
4712
4701
|
return;
|
|
4713
4702
|
}
|
|
4714
4703
|
const cues = await loadCaptionVtt(url);
|
|
4715
|
-
|
|
4716
|
-
if (!cancelled) setCaptionCues(next);
|
|
4704
|
+
if (!cancelled) setCaptionCues(cues);
|
|
4717
4705
|
};
|
|
4718
4706
|
void load();
|
|
4719
4707
|
if (!liveCaptionsBaseUrl) return;
|
|
@@ -4723,12 +4711,28 @@ function VideoPlayer({
|
|
|
4723
4711
|
window.clearInterval(timer);
|
|
4724
4712
|
};
|
|
4725
4713
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4714
|
+
React9.useEffect(() => {
|
|
4715
|
+
if (!liveCaptionsBaseUrl || captionLocale === "off") {
|
|
4716
|
+
setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
|
|
4717
|
+
return;
|
|
4718
|
+
}
|
|
4719
|
+
const tick = () => {
|
|
4720
|
+
setLivePlayout(
|
|
4721
|
+
(prev) => advanceLiveCaptionPlayout(
|
|
4722
|
+
prev,
|
|
4723
|
+
coalesceLiveCaptionCues(liveCaptionCuesRef.current),
|
|
4724
|
+
Date.now(),
|
|
4725
|
+
liveLagMsRef.current,
|
|
4726
|
+
compactChromeRef.current ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE
|
|
4727
|
+
)
|
|
4728
|
+
);
|
|
4729
|
+
};
|
|
4730
|
+
tick();
|
|
4731
|
+
const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
|
|
4732
|
+
return () => window.clearInterval(timer);
|
|
4733
|
+
}, [liveCaptionsBaseUrl, captionLocale]);
|
|
4734
|
+
const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
|
|
4735
|
+
const captionScreen = liveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
|
|
4732
4736
|
React9.useEffect(() => {
|
|
4733
4737
|
const video = videoRef.current;
|
|
4734
4738
|
if (!video || !liveCaptionsBaseUrl) return;
|
|
@@ -4775,12 +4779,14 @@ function VideoPlayer({
|
|
|
4775
4779
|
if (!video || captionLocale === "off" || !liveCaptionsBaseUrl) return;
|
|
4776
4780
|
const track = findSubtitleTrack(video, captionLocale);
|
|
4777
4781
|
if (!track) return;
|
|
4782
|
+
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
4778
4783
|
syncNativeCaptionCue(
|
|
4779
4784
|
video,
|
|
4780
4785
|
track,
|
|
4781
|
-
|
|
4786
|
+
livePlayout.screen?.text ?? "",
|
|
4787
|
+
remaining
|
|
4782
4788
|
);
|
|
4783
|
-
}, [
|
|
4789
|
+
}, [livePlayout, captionLocale, liveCaptionsBaseUrl]);
|
|
4784
4790
|
function togglePlay() {
|
|
4785
4791
|
const video = videoRef.current;
|
|
4786
4792
|
if (!video) return;
|
|
@@ -5046,22 +5052,7 @@ function VideoPlayer({
|
|
|
5046
5052
|
] }),
|
|
5047
5053
|
typeof stats?.viewers === "number" && /* @__PURE__ */ 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}` })
|
|
5048
5054
|
] }),
|
|
5049
|
-
|
|
5050
|
-
LiveCaptionStack,
|
|
5051
|
-
{
|
|
5052
|
-
cues: captionStackCues,
|
|
5053
|
-
latestLabel: t.captionsLatest,
|
|
5054
|
-
variant: appleMobile ? "window" : "scroll"
|
|
5055
|
-
}
|
|
5056
|
-
),
|
|
5057
|
-
!liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsx(
|
|
5058
|
-
"div",
|
|
5059
|
-
{
|
|
5060
|
-
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
5061
|
-
"data-slot": "video-captions",
|
|
5062
|
-
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 })
|
|
5063
|
-
}
|
|
5064
|
-
),
|
|
5055
|
+
captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsx(CaptionOverlay, { screen: captionScreen }),
|
|
5065
5056
|
active && /* @__PURE__ */ jsxs(
|
|
5066
5057
|
"div",
|
|
5067
5058
|
{
|