@livo-tv/blocks 1.24.0 → 1.25.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 +214 -177
- 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 +214 -177
- 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;
|
|
@@ -3950,26 +3959,148 @@ function parseCaptionVtt(text) {
|
|
|
3950
3959
|
}
|
|
3951
3960
|
return cues;
|
|
3952
3961
|
}
|
|
3953
|
-
function
|
|
3954
|
-
|
|
3955
|
-
if (matched) return matched;
|
|
3956
|
-
return null;
|
|
3962
|
+
function captionScreenRow(text, speaker) {
|
|
3963
|
+
return speaker == null ? { text } : { text, speaker };
|
|
3957
3964
|
}
|
|
3958
|
-
function
|
|
3959
|
-
if (
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3965
|
+
function chunkLongWord(word, maxCharsPerLine) {
|
|
3966
|
+
if (word.length <= maxCharsPerLine) return [word];
|
|
3967
|
+
const parts = [];
|
|
3968
|
+
for (let index = 0; index < word.length; index += maxCharsPerLine) {
|
|
3969
|
+
parts.push(word.slice(index, index + maxCharsPerLine));
|
|
3970
|
+
}
|
|
3971
|
+
return parts;
|
|
3972
|
+
}
|
|
3973
|
+
function wrapCaptionLines(text, maxCharsPerLine) {
|
|
3974
|
+
const tokens = text.split(" ").filter(Boolean).flatMap((word) => chunkLongWord(word, maxCharsPerLine));
|
|
3975
|
+
const lines = [];
|
|
3976
|
+
let index = 0;
|
|
3977
|
+
while (index < tokens.length) {
|
|
3978
|
+
let end = index;
|
|
3979
|
+
let length = 0;
|
|
3980
|
+
while (end < tokens.length) {
|
|
3981
|
+
const added = tokens[end].length + (end > index ? 1 : 0);
|
|
3982
|
+
if (length + added > maxCharsPerLine && end > index) break;
|
|
3983
|
+
length += added;
|
|
3984
|
+
end += 1;
|
|
3985
|
+
}
|
|
3986
|
+
let breakAt = end;
|
|
3987
|
+
if (end < tokens.length) {
|
|
3988
|
+
for (let cursor = end - 1; cursor > index; cursor -= 1) {
|
|
3989
|
+
if (!CAPTION_BREAK_PUNCT.test(tokens[cursor])) continue;
|
|
3990
|
+
const firstLen = tokens.slice(index, cursor + 1).join(" ").length;
|
|
3991
|
+
if (firstLen >= Math.min(CAPTION_MIN_PUNCT_LINE, maxCharsPerLine)) {
|
|
3992
|
+
breakAt = cursor + 1;
|
|
3993
|
+
}
|
|
3994
|
+
break;
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
lines.push(tokens.slice(index, breakAt).join(" "));
|
|
3998
|
+
index = breakAt;
|
|
3999
|
+
}
|
|
4000
|
+
return lines;
|
|
4001
|
+
}
|
|
4002
|
+
function balanceCaptionLines(lines, maxCharsPerLine) {
|
|
4003
|
+
const next = [...lines];
|
|
4004
|
+
for (let index = 0; index + 1 < next.length; index += CAPTION_MAX_LINES) {
|
|
4005
|
+
const left = next[index].split(" ");
|
|
4006
|
+
const right = next[index + 1].split(" ");
|
|
4007
|
+
if (right.length !== 1 || left.length < 3) continue;
|
|
4008
|
+
const moved = left[left.length - 1];
|
|
4009
|
+
const newRight = `${moved} ${right[0]}`;
|
|
4010
|
+
if (newRight.length > maxCharsPerLine) continue;
|
|
4011
|
+
next[index] = left.slice(0, -1).join(" ");
|
|
4012
|
+
next[index + 1] = newRight;
|
|
4013
|
+
}
|
|
4014
|
+
return next;
|
|
3966
4015
|
}
|
|
3967
|
-
function
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
(
|
|
3972
|
-
|
|
4016
|
+
function splitCaptionScreens(text, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4017
|
+
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
4018
|
+
if (!trimmed) return [];
|
|
4019
|
+
const lines = balanceCaptionLines(
|
|
4020
|
+
wrapCaptionLines(trimmed, maxCharsPerLine),
|
|
4021
|
+
maxCharsPerLine
|
|
4022
|
+
);
|
|
4023
|
+
const screens = [];
|
|
4024
|
+
for (let index = 0; index < lines.length; index += CAPTION_MAX_LINES) {
|
|
4025
|
+
screens.push(lines.slice(index, index + CAPTION_MAX_LINES).join("\n"));
|
|
4026
|
+
}
|
|
4027
|
+
return screens;
|
|
4028
|
+
}
|
|
4029
|
+
function captionDwellMs(text, backlog = 0) {
|
|
4030
|
+
const chars = text.replace(/\s+/g, " ").trim().length;
|
|
4031
|
+
const raw = chars / CAPTION_CHARS_PER_SECOND * 1e3;
|
|
4032
|
+
const max = backlog > 0 ? CAPTION_RUSH_DWELL_MS : CAPTION_MAX_DWELL_MS;
|
|
4033
|
+
return Math.min(max, Math.max(CAPTION_MIN_DWELL_MS, raw));
|
|
4034
|
+
}
|
|
4035
|
+
function advanceLiveCaptionPlayout(state, cues, now, lagMs, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4036
|
+
let screen = state.screen;
|
|
4037
|
+
let hideAt = state.hideAt;
|
|
4038
|
+
let cursor = state.cursor;
|
|
4039
|
+
let queue = state.queue.slice();
|
|
4040
|
+
if (lagMs != null && Number.isFinite(lagMs) && lagMs >= 0) {
|
|
4041
|
+
const threshold = lagMs + LIVE_CUE_EXTRA_LAG_MS;
|
|
4042
|
+
const incoming = cues.filter(
|
|
4043
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.receivedAt) && cue.receivedAt > cursor && now - cue.receivedAt >= threshold
|
|
4044
|
+
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
4045
|
+
for (const cue of incoming) {
|
|
4046
|
+
for (const text of splitCaptionScreens(cue.text, maxCharsPerLine)) {
|
|
4047
|
+
queue.push(captionScreenRow(text, cue.speaker));
|
|
4048
|
+
}
|
|
4049
|
+
cursor = cue.receivedAt;
|
|
4050
|
+
}
|
|
4051
|
+
if (queue.length > CAPTION_BACKLOG_DROP) {
|
|
4052
|
+
queue = queue.slice(queue.length - CAPTION_BACKLOG_DROP);
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
if (now >= hideAt) {
|
|
4056
|
+
const next = queue.shift();
|
|
4057
|
+
if (next) {
|
|
4058
|
+
screen = next;
|
|
4059
|
+
hideAt = now + captionDwellMs(next.text, queue.length);
|
|
4060
|
+
} else {
|
|
4061
|
+
screen = null;
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
return { screen, hideAt, cursor, queue };
|
|
4065
|
+
}
|
|
4066
|
+
function cueEndWithGapFill(cues, index) {
|
|
4067
|
+
const cue = cues[index];
|
|
4068
|
+
if (!cue) return 0;
|
|
4069
|
+
const next = cues[index + 1];
|
|
4070
|
+
if (!next || !Number.isFinite(next.start)) return cue.end;
|
|
4071
|
+
const gapMs = (next.start - cue.end) * 1e3;
|
|
4072
|
+
if (gapMs > 0 && gapMs < CAPTION_GAP_FILL_MS) return next.start;
|
|
4073
|
+
return cue.end;
|
|
4074
|
+
}
|
|
4075
|
+
function captionScreenAtTime(cues, time, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4076
|
+
if (!Number.isFinite(time)) return null;
|
|
4077
|
+
const ordered = cues.filter(
|
|
4078
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && Number.isFinite(cue.end)
|
|
4079
|
+
).sort((left, right) => left.start - right.start);
|
|
4080
|
+
for (let index = 0; index < ordered.length; index += 1) {
|
|
4081
|
+
const cue = ordered[index];
|
|
4082
|
+
const end = cueEndWithGapFill(ordered, index);
|
|
4083
|
+
if (time < cue.start || time >= end) continue;
|
|
4084
|
+
const screens = splitCaptionScreens(cue.text, maxCharsPerLine);
|
|
4085
|
+
if (screens.length === 0) return null;
|
|
4086
|
+
const weights = screens.map(
|
|
4087
|
+
(text) => Math.max(1, text.replace(/\s+/g, "").length)
|
|
4088
|
+
);
|
|
4089
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
4090
|
+
const duration = Math.max(end - cue.start, 0);
|
|
4091
|
+
let cursor = cue.start;
|
|
4092
|
+
for (let screenIndex = 0; screenIndex < screens.length; screenIndex += 1) {
|
|
4093
|
+
const isLast = screenIndex === screens.length - 1;
|
|
4094
|
+
const slice = isLast ? end - cursor : duration * (weights[screenIndex] / total);
|
|
4095
|
+
const sliceEnd = cursor + slice;
|
|
4096
|
+
if (time >= cursor && time < sliceEnd) {
|
|
4097
|
+
return captionScreenRow(screens[screenIndex]);
|
|
4098
|
+
}
|
|
4099
|
+
cursor = sliceEnd;
|
|
4100
|
+
}
|
|
4101
|
+
return captionScreenRow(screens[screens.length - 1]);
|
|
4102
|
+
}
|
|
4103
|
+
return null;
|
|
3973
4104
|
}
|
|
3974
4105
|
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
3975
4106
|
function normalizeLiveCaptionText(text) {
|
|
@@ -4044,17 +4175,6 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
4044
4175
|
}
|
|
4045
4176
|
return out;
|
|
4046
4177
|
}
|
|
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
4178
|
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
4059
4179
|
const map = /* @__PURE__ */ new Map();
|
|
4060
4180
|
for (const cue of existing) {
|
|
@@ -4130,121 +4250,29 @@ function isEmbeddedWindow(win = window) {
|
|
|
4130
4250
|
return true;
|
|
4131
4251
|
}
|
|
4132
4252
|
}
|
|
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]);
|
|
4253
|
+
function CaptionOverlay({ screen }) {
|
|
4254
|
+
const lastSpeakerRef = React9.useRef(void 0);
|
|
4255
|
+
const lastSpeaker = lastSpeakerRef.current;
|
|
4161
4256
|
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;
|
|
4257
|
+
if (screen?.speaker != null) lastSpeakerRef.current = screen.speaker;
|
|
4258
|
+
}, [screen]);
|
|
4259
|
+
if (!screen) return null;
|
|
4260
|
+
const turnDash = screen.speaker != null && lastSpeaker != null && screen.speaker !== lastSpeaker;
|
|
4261
|
+
const text = turnDash ? `\u2013 ${screen.text}` : screen.text;
|
|
4182
4262
|
return /* @__PURE__ */ jsx(
|
|
4183
4263
|
"div",
|
|
4184
4264
|
{
|
|
4185
4265
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4186
4266
|
"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
|
-
] })
|
|
4267
|
+
children: /* @__PURE__ */ jsx(
|
|
4268
|
+
"p",
|
|
4269
|
+
{
|
|
4270
|
+
role: "status",
|
|
4271
|
+
"aria-live": "polite",
|
|
4272
|
+
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%]",
|
|
4273
|
+
children: text
|
|
4274
|
+
}
|
|
4275
|
+
)
|
|
4248
4276
|
}
|
|
4249
4277
|
);
|
|
4250
4278
|
}
|
|
@@ -4252,9 +4280,6 @@ function LiveCaptionStack({
|
|
|
4252
4280
|
// src/components/video/nativeCaptionTrack.ts
|
|
4253
4281
|
var NATIVE_CAPTION_HOLD_S = 4;
|
|
4254
4282
|
var NATIVE_SUBTITLE_KIND = "subtitles";
|
|
4255
|
-
function joinCaptionTexts(cues) {
|
|
4256
|
-
return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
|
|
4257
|
-
}
|
|
4258
4283
|
function clearNativeCaptionCues(track) {
|
|
4259
4284
|
const cues = track.cues;
|
|
4260
4285
|
if (!cues) return;
|
|
@@ -4304,12 +4329,13 @@ function ensureLiveSubtitleTracks(video, labels) {
|
|
|
4304
4329
|
return track;
|
|
4305
4330
|
});
|
|
4306
4331
|
}
|
|
4307
|
-
function syncNativeCaptionCue(video, track, text) {
|
|
4332
|
+
function syncNativeCaptionCue(video, track, text, holdSeconds = NATIVE_CAPTION_HOLD_S) {
|
|
4308
4333
|
clearNativeCaptionCues(track);
|
|
4309
4334
|
const trimmed = text.trim();
|
|
4310
4335
|
if (!trimmed) return;
|
|
4311
4336
|
const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
|
|
4312
|
-
|
|
4337
|
+
const hold = Number.isFinite(holdSeconds) ? Math.max(0.2, holdSeconds) : NATIVE_CAPTION_HOLD_S;
|
|
4338
|
+
track.addCue(new VTTCue(start, start + hold, trimmed));
|
|
4313
4339
|
}
|
|
4314
4340
|
function zeroAnchorNativeTrackCues(track) {
|
|
4315
4341
|
const list = track.cues;
|
|
@@ -4388,6 +4414,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
|
4388
4414
|
var CONTROLS_HIDE_MS = 3e3;
|
|
4389
4415
|
var LIVE_EDGE_THRESHOLD_S = 8;
|
|
4390
4416
|
var SEEK_STEP_S = 5;
|
|
4417
|
+
var LIVE_CAPTION_PLAYOUT_MS = 250;
|
|
4391
4418
|
var COMPACT_CHROME_PX = 640;
|
|
4392
4419
|
var VIDEO_MEDIA_STYLE = `
|
|
4393
4420
|
.livo-video-player-media::-webkit-media-controls-start-playback-button {
|
|
@@ -4499,14 +4526,22 @@ function VideoPlayer({
|
|
|
4499
4526
|
const [captionLocale, setCaptionLocale] = React9.useState(defaultCaptionLocale ?? "off");
|
|
4500
4527
|
const [captionCues, setCaptionCues] = React9.useState([]);
|
|
4501
4528
|
const [liveCaptionCues, setLiveCaptionCues] = React9.useState([]);
|
|
4529
|
+
const [livePlayout, setLivePlayout] = React9.useState(
|
|
4530
|
+
EMPTY_LIVE_CAPTION_PLAYOUT
|
|
4531
|
+
);
|
|
4502
4532
|
const [liveLagMs, setLiveLagMs] = React9.useState(null);
|
|
4503
4533
|
const [behindLive, setBehindLive] = React9.useState(false);
|
|
4504
4534
|
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9.useState(false);
|
|
4505
4535
|
const [embedded, setEmbedded] = React9.useState(false);
|
|
4506
4536
|
const [cssFullscreen, setCssFullscreen] = React9.useState(false);
|
|
4507
|
-
const [appleMobile, setAppleMobile] = React9.useState(false);
|
|
4508
4537
|
const [webkitNativeFs, setWebkitNativeFs] = React9.useState(false);
|
|
4509
4538
|
const hideTimerRef = React9.useRef(null);
|
|
4539
|
+
const liveCaptionCuesRef = React9.useRef(liveCaptionCues);
|
|
4540
|
+
const liveLagMsRef = React9.useRef(liveLagMs);
|
|
4541
|
+
const compactChromeRef = React9.useRef(compactChrome);
|
|
4542
|
+
liveCaptionCuesRef.current = liveCaptionCues;
|
|
4543
|
+
liveLagMsRef.current = liveLagMs;
|
|
4544
|
+
compactChromeRef.current = compactChrome;
|
|
4510
4545
|
cssFullscreenRef.current = cssFullscreen;
|
|
4511
4546
|
captionLocaleRef.current = captionLocale;
|
|
4512
4547
|
React9.useEffect(() => {
|
|
@@ -4582,7 +4617,6 @@ function VideoPlayer({
|
|
|
4582
4617
|
}, [paused, videoRef, isPlaying]);
|
|
4583
4618
|
React9.useEffect(() => {
|
|
4584
4619
|
setEmbedded(isEmbeddedWindow());
|
|
4585
|
-
setAppleMobile(isAppleMobileDevice());
|
|
4586
4620
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4587
4621
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4588
4622
|
videoRef.current?.setAttribute("webkit-playsinline", "");
|
|
@@ -4723,12 +4757,28 @@ function VideoPlayer({
|
|
|
4723
4757
|
window.clearInterval(timer);
|
|
4724
4758
|
};
|
|
4725
4759
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4760
|
+
React9.useEffect(() => {
|
|
4761
|
+
if (!liveCaptionsBaseUrl || captionLocale === "off") {
|
|
4762
|
+
setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
|
|
4763
|
+
return;
|
|
4764
|
+
}
|
|
4765
|
+
const tick = () => {
|
|
4766
|
+
setLivePlayout(
|
|
4767
|
+
(prev) => advanceLiveCaptionPlayout(
|
|
4768
|
+
prev,
|
|
4769
|
+
coalesceLiveCaptionCues(liveCaptionCuesRef.current),
|
|
4770
|
+
Date.now(),
|
|
4771
|
+
liveLagMsRef.current,
|
|
4772
|
+
compactChromeRef.current ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE
|
|
4773
|
+
)
|
|
4774
|
+
);
|
|
4775
|
+
};
|
|
4776
|
+
tick();
|
|
4777
|
+
const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
|
|
4778
|
+
return () => window.clearInterval(timer);
|
|
4779
|
+
}, [liveCaptionsBaseUrl, captionLocale]);
|
|
4780
|
+
const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
|
|
4781
|
+
const captionScreen = liveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
|
|
4732
4782
|
React9.useEffect(() => {
|
|
4733
4783
|
const video = videoRef.current;
|
|
4734
4784
|
if (!video || !liveCaptionsBaseUrl) return;
|
|
@@ -4775,12 +4825,14 @@ function VideoPlayer({
|
|
|
4775
4825
|
if (!video || captionLocale === "off" || !liveCaptionsBaseUrl) return;
|
|
4776
4826
|
const track = findSubtitleTrack(video, captionLocale);
|
|
4777
4827
|
if (!track) return;
|
|
4828
|
+
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
4778
4829
|
syncNativeCaptionCue(
|
|
4779
4830
|
video,
|
|
4780
4831
|
track,
|
|
4781
|
-
|
|
4832
|
+
livePlayout.screen?.text ?? "",
|
|
4833
|
+
remaining
|
|
4782
4834
|
);
|
|
4783
|
-
}, [
|
|
4835
|
+
}, [livePlayout, captionLocale, liveCaptionsBaseUrl]);
|
|
4784
4836
|
function togglePlay() {
|
|
4785
4837
|
const video = videoRef.current;
|
|
4786
4838
|
if (!video) return;
|
|
@@ -5046,22 +5098,7 @@ function VideoPlayer({
|
|
|
5046
5098
|
] }),
|
|
5047
5099
|
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
5100
|
] }),
|
|
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
|
-
),
|
|
5101
|
+
captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsx(CaptionOverlay, { screen: captionScreen }),
|
|
5065
5102
|
active && /* @__PURE__ */ jsxs(
|
|
5066
5103
|
"div",
|
|
5067
5104
|
{
|