@livo-tv/blocks 1.23.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 +216 -178
- 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 +216 -178
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1227,6 +1227,7 @@ function LanguageSwitcher({
|
|
|
1227
1227
|
const sizes = sizeClasses2[size];
|
|
1228
1228
|
const shapeClass = shapeClasses2[shape];
|
|
1229
1229
|
const reduceMotion = framerMotion.useReducedMotion();
|
|
1230
|
+
const layoutId = `${React9.useId()}-activeLanguage`;
|
|
1230
1231
|
const defaultLabels2 = {
|
|
1231
1232
|
language: labels.language ?? "Language"
|
|
1232
1233
|
};
|
|
@@ -1302,7 +1303,7 @@ function LanguageSwitcher({
|
|
|
1302
1303
|
framerMotion.motion.div,
|
|
1303
1304
|
{
|
|
1304
1305
|
className: cn("absolute inset-0 bg-secondary", shapeClass),
|
|
1305
|
-
layoutId
|
|
1306
|
+
layoutId,
|
|
1306
1307
|
initial: { opacity: 0 },
|
|
1307
1308
|
animate: { opacity: 1 },
|
|
1308
1309
|
exit: { opacity: 0 },
|
|
@@ -3902,19 +3903,28 @@ function useHlsPlayback({
|
|
|
3902
3903
|
};
|
|
3903
3904
|
}
|
|
3904
3905
|
|
|
3905
|
-
// src/components/video/appleMobile.ts
|
|
3906
|
-
function isAppleMobileDevice(nav = navigator) {
|
|
3907
|
-
if (/iP(hone|ad|od)/.test(nav.userAgent)) return true;
|
|
3908
|
-
return nav.platform === "MacIntel" && nav.maxTouchPoints > 1;
|
|
3909
|
-
}
|
|
3910
|
-
|
|
3911
3906
|
// src/components/video/captions.ts
|
|
3912
3907
|
var CAPTION_LOCALES = ["en", "es", "pt"];
|
|
3913
3908
|
var LIVE_CUE_EXTRA_LAG_MS = 2e3;
|
|
3914
3909
|
var LIVE_STACK_MAX_CUES = 150;
|
|
3915
|
-
var
|
|
3916
|
-
var
|
|
3910
|
+
var CAPTION_CHARS_PER_SECOND = 17;
|
|
3911
|
+
var CAPTION_MIN_DWELL_MS = 1200;
|
|
3912
|
+
var CAPTION_MAX_DWELL_MS = 6e3;
|
|
3913
|
+
var CAPTION_RUSH_DWELL_MS = 2500;
|
|
3914
|
+
var CAPTION_MAX_CHARS_PER_LINE = 42;
|
|
3915
|
+
var CAPTION_COMPACT_CHARS_PER_LINE = 32;
|
|
3916
|
+
var CAPTION_MAX_LINES = 2;
|
|
3917
|
+
var CAPTION_BACKLOG_DROP = 8;
|
|
3918
|
+
var CAPTION_GAP_FILL_MS = 1e3;
|
|
3917
3919
|
var LIVE_LAG_SPIKE_MS = 2500;
|
|
3920
|
+
var CAPTION_BREAK_PUNCT = /[.,;:?!]$/;
|
|
3921
|
+
var CAPTION_MIN_PUNCT_LINE = 8;
|
|
3922
|
+
var EMPTY_LIVE_CAPTION_PLAYOUT = {
|
|
3923
|
+
screen: null,
|
|
3924
|
+
hideAt: 0,
|
|
3925
|
+
cursor: 0,
|
|
3926
|
+
queue: []
|
|
3927
|
+
};
|
|
3918
3928
|
function stabilizeLiveLagMs(previous, next) {
|
|
3919
3929
|
if (previous == null || !Number.isFinite(previous)) return next;
|
|
3920
3930
|
if (next <= previous) return next;
|
|
@@ -3975,26 +3985,148 @@ function parseCaptionVtt(text) {
|
|
|
3975
3985
|
}
|
|
3976
3986
|
return cues;
|
|
3977
3987
|
}
|
|
3978
|
-
function
|
|
3979
|
-
|
|
3980
|
-
if (matched) return matched;
|
|
3981
|
-
return null;
|
|
3988
|
+
function captionScreenRow(text, speaker) {
|
|
3989
|
+
return speaker == null ? { text } : { text, speaker };
|
|
3982
3990
|
}
|
|
3983
|
-
function
|
|
3984
|
-
if (
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
+
function chunkLongWord(word, maxCharsPerLine) {
|
|
3992
|
+
if (word.length <= maxCharsPerLine) return [word];
|
|
3993
|
+
const parts = [];
|
|
3994
|
+
for (let index = 0; index < word.length; index += maxCharsPerLine) {
|
|
3995
|
+
parts.push(word.slice(index, index + maxCharsPerLine));
|
|
3996
|
+
}
|
|
3997
|
+
return parts;
|
|
3998
|
+
}
|
|
3999
|
+
function wrapCaptionLines(text, maxCharsPerLine) {
|
|
4000
|
+
const tokens = text.split(" ").filter(Boolean).flatMap((word) => chunkLongWord(word, maxCharsPerLine));
|
|
4001
|
+
const lines = [];
|
|
4002
|
+
let index = 0;
|
|
4003
|
+
while (index < tokens.length) {
|
|
4004
|
+
let end = index;
|
|
4005
|
+
let length = 0;
|
|
4006
|
+
while (end < tokens.length) {
|
|
4007
|
+
const added = tokens[end].length + (end > index ? 1 : 0);
|
|
4008
|
+
if (length + added > maxCharsPerLine && end > index) break;
|
|
4009
|
+
length += added;
|
|
4010
|
+
end += 1;
|
|
4011
|
+
}
|
|
4012
|
+
let breakAt = end;
|
|
4013
|
+
if (end < tokens.length) {
|
|
4014
|
+
for (let cursor = end - 1; cursor > index; cursor -= 1) {
|
|
4015
|
+
if (!CAPTION_BREAK_PUNCT.test(tokens[cursor])) continue;
|
|
4016
|
+
const firstLen = tokens.slice(index, cursor + 1).join(" ").length;
|
|
4017
|
+
if (firstLen >= Math.min(CAPTION_MIN_PUNCT_LINE, maxCharsPerLine)) {
|
|
4018
|
+
breakAt = cursor + 1;
|
|
4019
|
+
}
|
|
4020
|
+
break;
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
lines.push(tokens.slice(index, breakAt).join(" "));
|
|
4024
|
+
index = breakAt;
|
|
4025
|
+
}
|
|
4026
|
+
return lines;
|
|
4027
|
+
}
|
|
4028
|
+
function balanceCaptionLines(lines, maxCharsPerLine) {
|
|
4029
|
+
const next = [...lines];
|
|
4030
|
+
for (let index = 0; index + 1 < next.length; index += CAPTION_MAX_LINES) {
|
|
4031
|
+
const left = next[index].split(" ");
|
|
4032
|
+
const right = next[index + 1].split(" ");
|
|
4033
|
+
if (right.length !== 1 || left.length < 3) continue;
|
|
4034
|
+
const moved = left[left.length - 1];
|
|
4035
|
+
const newRight = `${moved} ${right[0]}`;
|
|
4036
|
+
if (newRight.length > maxCharsPerLine) continue;
|
|
4037
|
+
next[index] = left.slice(0, -1).join(" ");
|
|
4038
|
+
next[index + 1] = newRight;
|
|
4039
|
+
}
|
|
4040
|
+
return next;
|
|
3991
4041
|
}
|
|
3992
|
-
function
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
(
|
|
3997
|
-
|
|
4042
|
+
function splitCaptionScreens(text, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4043
|
+
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
4044
|
+
if (!trimmed) return [];
|
|
4045
|
+
const lines = balanceCaptionLines(
|
|
4046
|
+
wrapCaptionLines(trimmed, maxCharsPerLine),
|
|
4047
|
+
maxCharsPerLine
|
|
4048
|
+
);
|
|
4049
|
+
const screens = [];
|
|
4050
|
+
for (let index = 0; index < lines.length; index += CAPTION_MAX_LINES) {
|
|
4051
|
+
screens.push(lines.slice(index, index + CAPTION_MAX_LINES).join("\n"));
|
|
4052
|
+
}
|
|
4053
|
+
return screens;
|
|
4054
|
+
}
|
|
4055
|
+
function captionDwellMs(text, backlog = 0) {
|
|
4056
|
+
const chars = text.replace(/\s+/g, " ").trim().length;
|
|
4057
|
+
const raw = chars / CAPTION_CHARS_PER_SECOND * 1e3;
|
|
4058
|
+
const max = backlog > 0 ? CAPTION_RUSH_DWELL_MS : CAPTION_MAX_DWELL_MS;
|
|
4059
|
+
return Math.min(max, Math.max(CAPTION_MIN_DWELL_MS, raw));
|
|
4060
|
+
}
|
|
4061
|
+
function advanceLiveCaptionPlayout(state, cues, now, lagMs, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4062
|
+
let screen = state.screen;
|
|
4063
|
+
let hideAt = state.hideAt;
|
|
4064
|
+
let cursor = state.cursor;
|
|
4065
|
+
let queue = state.queue.slice();
|
|
4066
|
+
if (lagMs != null && Number.isFinite(lagMs) && lagMs >= 0) {
|
|
4067
|
+
const threshold = lagMs + LIVE_CUE_EXTRA_LAG_MS;
|
|
4068
|
+
const incoming = cues.filter(
|
|
4069
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.receivedAt) && cue.receivedAt > cursor && now - cue.receivedAt >= threshold
|
|
4070
|
+
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
4071
|
+
for (const cue of incoming) {
|
|
4072
|
+
for (const text of splitCaptionScreens(cue.text, maxCharsPerLine)) {
|
|
4073
|
+
queue.push(captionScreenRow(text, cue.speaker));
|
|
4074
|
+
}
|
|
4075
|
+
cursor = cue.receivedAt;
|
|
4076
|
+
}
|
|
4077
|
+
if (queue.length > CAPTION_BACKLOG_DROP) {
|
|
4078
|
+
queue = queue.slice(queue.length - CAPTION_BACKLOG_DROP);
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
if (now >= hideAt) {
|
|
4082
|
+
const next = queue.shift();
|
|
4083
|
+
if (next) {
|
|
4084
|
+
screen = next;
|
|
4085
|
+
hideAt = now + captionDwellMs(next.text, queue.length);
|
|
4086
|
+
} else {
|
|
4087
|
+
screen = null;
|
|
4088
|
+
}
|
|
4089
|
+
}
|
|
4090
|
+
return { screen, hideAt, cursor, queue };
|
|
4091
|
+
}
|
|
4092
|
+
function cueEndWithGapFill(cues, index) {
|
|
4093
|
+
const cue = cues[index];
|
|
4094
|
+
if (!cue) return 0;
|
|
4095
|
+
const next = cues[index + 1];
|
|
4096
|
+
if (!next || !Number.isFinite(next.start)) return cue.end;
|
|
4097
|
+
const gapMs = (next.start - cue.end) * 1e3;
|
|
4098
|
+
if (gapMs > 0 && gapMs < CAPTION_GAP_FILL_MS) return next.start;
|
|
4099
|
+
return cue.end;
|
|
4100
|
+
}
|
|
4101
|
+
function captionScreenAtTime(cues, time, maxCharsPerLine = CAPTION_MAX_CHARS_PER_LINE) {
|
|
4102
|
+
if (!Number.isFinite(time)) return null;
|
|
4103
|
+
const ordered = cues.filter(
|
|
4104
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && Number.isFinite(cue.end)
|
|
4105
|
+
).sort((left, right) => left.start - right.start);
|
|
4106
|
+
for (let index = 0; index < ordered.length; index += 1) {
|
|
4107
|
+
const cue = ordered[index];
|
|
4108
|
+
const end = cueEndWithGapFill(ordered, index);
|
|
4109
|
+
if (time < cue.start || time >= end) continue;
|
|
4110
|
+
const screens = splitCaptionScreens(cue.text, maxCharsPerLine);
|
|
4111
|
+
if (screens.length === 0) return null;
|
|
4112
|
+
const weights = screens.map(
|
|
4113
|
+
(text) => Math.max(1, text.replace(/\s+/g, "").length)
|
|
4114
|
+
);
|
|
4115
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
4116
|
+
const duration = Math.max(end - cue.start, 0);
|
|
4117
|
+
let cursor = cue.start;
|
|
4118
|
+
for (let screenIndex = 0; screenIndex < screens.length; screenIndex += 1) {
|
|
4119
|
+
const isLast = screenIndex === screens.length - 1;
|
|
4120
|
+
const slice = isLast ? end - cursor : duration * (weights[screenIndex] / total);
|
|
4121
|
+
const sliceEnd = cursor + slice;
|
|
4122
|
+
if (time >= cursor && time < sliceEnd) {
|
|
4123
|
+
return captionScreenRow(screens[screenIndex]);
|
|
4124
|
+
}
|
|
4125
|
+
cursor = sliceEnd;
|
|
4126
|
+
}
|
|
4127
|
+
return captionScreenRow(screens[screens.length - 1]);
|
|
4128
|
+
}
|
|
4129
|
+
return null;
|
|
3998
4130
|
}
|
|
3999
4131
|
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
4000
4132
|
function normalizeLiveCaptionText(text) {
|
|
@@ -4069,17 +4201,6 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
4069
4201
|
}
|
|
4070
4202
|
return out;
|
|
4071
4203
|
}
|
|
4072
|
-
function lastLiveCaptionWindow(cues, maxCues = IOS_CAPTION_WINDOW_LINES) {
|
|
4073
|
-
return cues.slice(-Math.max(1, maxCues));
|
|
4074
|
-
}
|
|
4075
|
-
function lastCaptionLines(text, lines = IOS_CAPTION_WINDOW_LINES, charsPerLine = IOS_CAPTION_CHARS_PER_LINE) {
|
|
4076
|
-
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
4077
|
-
const maxChars = Math.max(1, lines) * Math.max(1, charsPerLine);
|
|
4078
|
-
if (trimmed.length <= maxChars) return trimmed;
|
|
4079
|
-
const slice = trimmed.slice(-maxChars);
|
|
4080
|
-
const space = slice.indexOf(" ");
|
|
4081
|
-
return (space > 0 ? slice.slice(space + 1) : slice).trim();
|
|
4082
|
-
}
|
|
4083
4204
|
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
4084
4205
|
const map = /* @__PURE__ */ new Map();
|
|
4085
4206
|
for (const cue of existing) {
|
|
@@ -4155,121 +4276,29 @@ function isEmbeddedWindow(win = window) {
|
|
|
4155
4276
|
return true;
|
|
4156
4277
|
}
|
|
4157
4278
|
}
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
latestLabel,
|
|
4162
|
-
variant = "scroll"
|
|
4163
|
-
}) {
|
|
4164
|
-
const scrollerRef = React9__namespace.useRef(null);
|
|
4165
|
-
const followRef = React9__namespace.useRef(true);
|
|
4166
|
-
const ignoreScrollRef = React9__namespace.useRef(false);
|
|
4167
|
-
const [following, setFollowing] = React9__namespace.useState(true);
|
|
4168
|
-
const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
|
|
4169
|
-
const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
|
|
4170
|
-
const scrollToLatest = React9__namespace.useCallback(() => {
|
|
4171
|
-
const scroller = scrollerRef.current;
|
|
4172
|
-
if (!scroller) return;
|
|
4173
|
-
ignoreScrollRef.current = true;
|
|
4174
|
-
scroller.scrollTo({
|
|
4175
|
-
top: scroller.scrollHeight,
|
|
4176
|
-
behavior: prefersReduced ? "auto" : "smooth"
|
|
4177
|
-
});
|
|
4178
|
-
followRef.current = true;
|
|
4179
|
-
setFollowing(true);
|
|
4180
|
-
window.requestAnimationFrame(() => {
|
|
4181
|
-
window.requestAnimationFrame(() => {
|
|
4182
|
-
ignoreScrollRef.current = false;
|
|
4183
|
-
});
|
|
4184
|
-
});
|
|
4185
|
-
}, [prefersReduced]);
|
|
4279
|
+
function CaptionOverlay({ screen }) {
|
|
4280
|
+
const lastSpeakerRef = React9__namespace.useRef(void 0);
|
|
4281
|
+
const lastSpeaker = lastSpeakerRef.current;
|
|
4186
4282
|
React9__namespace.useLayoutEffect(() => {
|
|
4187
|
-
if (
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
top: scroller.scrollHeight,
|
|
4193
|
-
behavior: prefersReduced ? "auto" : "smooth"
|
|
4194
|
-
});
|
|
4195
|
-
window.requestAnimationFrame(() => {
|
|
4196
|
-
window.requestAnimationFrame(() => {
|
|
4197
|
-
ignoreScrollRef.current = false;
|
|
4198
|
-
});
|
|
4199
|
-
});
|
|
4200
|
-
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
4201
|
-
if (cues.length === 0) return null;
|
|
4202
|
-
const windowed = variant === "window";
|
|
4203
|
-
const distinctSpeakers = new Set(
|
|
4204
|
-
cues.map((cue) => cue.speaker).filter((speaker) => speaker != null)
|
|
4205
|
-
);
|
|
4206
|
-
const showTurns = distinctSpeakers.size >= 2;
|
|
4283
|
+
if (screen?.speaker != null) lastSpeakerRef.current = screen.speaker;
|
|
4284
|
+
}, [screen]);
|
|
4285
|
+
if (!screen) return null;
|
|
4286
|
+
const turnDash = screen.speaker != null && lastSpeaker != null && screen.speaker !== lastSpeaker;
|
|
4287
|
+
const text = turnDash ? `\u2013 ${screen.text}` : screen.text;
|
|
4207
4288
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4208
4289
|
"div",
|
|
4209
4290
|
{
|
|
4210
4291
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4211
4292
|
"data-slot": "video-captions",
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
"
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
}
|
|
4222
|
-
),
|
|
4223
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4224
|
-
"div",
|
|
4225
|
-
{
|
|
4226
|
-
ref: windowed ? void 0 : scrollerRef,
|
|
4227
|
-
role: "log",
|
|
4228
|
-
"aria-relevant": "additions",
|
|
4229
|
-
className: cn(
|
|
4230
|
-
"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%]",
|
|
4231
|
-
windowed ? "overflow-hidden" : "pointer-events-auto max-h-[min(4.5rem,18cqh)] overflow-x-hidden overflow-y-auto"
|
|
4232
|
-
),
|
|
4233
|
-
onScroll: windowed ? void 0 : (event) => {
|
|
4234
|
-
if (ignoreScrollRef.current) return;
|
|
4235
|
-
const scroller = event.currentTarget;
|
|
4236
|
-
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
|
|
4237
|
-
followRef.current = nearBottom;
|
|
4238
|
-
setFollowing(nearBottom);
|
|
4239
|
-
},
|
|
4240
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4241
|
-
"p",
|
|
4242
|
-
{
|
|
4243
|
-
className: cn(
|
|
4244
|
-
"text-justify [text-align-last:left] leading-snug break-words",
|
|
4245
|
-
windowed && "line-clamp-3",
|
|
4246
|
-
!prefersReduced && "transition-opacity"
|
|
4247
|
-
),
|
|
4248
|
-
children: cues.map((cue, index) => {
|
|
4249
|
-
const fromEnd = cues.length - 1 - index;
|
|
4250
|
-
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4251
|
-
const newest = fromEnd === 0;
|
|
4252
|
-
const previous = cues[index - 1];
|
|
4253
|
-
const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
|
|
4254
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4255
|
-
"span",
|
|
4256
|
-
{
|
|
4257
|
-
style: { opacity },
|
|
4258
|
-
"aria-live": newest ? "polite" : void 0,
|
|
4259
|
-
children: [
|
|
4260
|
-
turnStart && index > 0 ? /* @__PURE__ */ jsxRuntime.jsx("br", {}) : index > 0 ? " " : "",
|
|
4261
|
-
turnStart ? "\u2013 " : "",
|
|
4262
|
-
cue.text
|
|
4263
|
-
]
|
|
4264
|
-
},
|
|
4265
|
-
cue.receivedAt
|
|
4266
|
-
);
|
|
4267
|
-
})
|
|
4268
|
-
}
|
|
4269
|
-
)
|
|
4270
|
-
}
|
|
4271
|
-
)
|
|
4272
|
-
] })
|
|
4293
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4294
|
+
"p",
|
|
4295
|
+
{
|
|
4296
|
+
role: "status",
|
|
4297
|
+
"aria-live": "polite",
|
|
4298
|
+
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%]",
|
|
4299
|
+
children: text
|
|
4300
|
+
}
|
|
4301
|
+
)
|
|
4273
4302
|
}
|
|
4274
4303
|
);
|
|
4275
4304
|
}
|
|
@@ -4277,9 +4306,6 @@ function LiveCaptionStack({
|
|
|
4277
4306
|
// src/components/video/nativeCaptionTrack.ts
|
|
4278
4307
|
var NATIVE_CAPTION_HOLD_S = 4;
|
|
4279
4308
|
var NATIVE_SUBTITLE_KIND = "subtitles";
|
|
4280
|
-
function joinCaptionTexts(cues) {
|
|
4281
|
-
return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
|
|
4282
|
-
}
|
|
4283
4309
|
function clearNativeCaptionCues(track) {
|
|
4284
4310
|
const cues = track.cues;
|
|
4285
4311
|
if (!cues) return;
|
|
@@ -4329,12 +4355,13 @@ function ensureLiveSubtitleTracks(video, labels) {
|
|
|
4329
4355
|
return track;
|
|
4330
4356
|
});
|
|
4331
4357
|
}
|
|
4332
|
-
function syncNativeCaptionCue(video, track, text) {
|
|
4358
|
+
function syncNativeCaptionCue(video, track, text, holdSeconds = NATIVE_CAPTION_HOLD_S) {
|
|
4333
4359
|
clearNativeCaptionCues(track);
|
|
4334
4360
|
const trimmed = text.trim();
|
|
4335
4361
|
if (!trimmed) return;
|
|
4336
4362
|
const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
|
|
4337
|
-
|
|
4363
|
+
const hold = Number.isFinite(holdSeconds) ? Math.max(0.2, holdSeconds) : NATIVE_CAPTION_HOLD_S;
|
|
4364
|
+
track.addCue(new VTTCue(start, start + hold, trimmed));
|
|
4338
4365
|
}
|
|
4339
4366
|
function zeroAnchorNativeTrackCues(track) {
|
|
4340
4367
|
const list = track.cues;
|
|
@@ -4413,6 +4440,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
|
4413
4440
|
var CONTROLS_HIDE_MS = 3e3;
|
|
4414
4441
|
var LIVE_EDGE_THRESHOLD_S = 8;
|
|
4415
4442
|
var SEEK_STEP_S = 5;
|
|
4443
|
+
var LIVE_CAPTION_PLAYOUT_MS = 250;
|
|
4416
4444
|
var COMPACT_CHROME_PX = 640;
|
|
4417
4445
|
var VIDEO_MEDIA_STYLE = `
|
|
4418
4446
|
.livo-video-player-media::-webkit-media-controls-start-playback-button {
|
|
@@ -4524,14 +4552,22 @@ function VideoPlayer({
|
|
|
4524
4552
|
const [captionLocale, setCaptionLocale] = React9__namespace.useState(defaultCaptionLocale ?? "off");
|
|
4525
4553
|
const [captionCues, setCaptionCues] = React9__namespace.useState([]);
|
|
4526
4554
|
const [liveCaptionCues, setLiveCaptionCues] = React9__namespace.useState([]);
|
|
4555
|
+
const [livePlayout, setLivePlayout] = React9__namespace.useState(
|
|
4556
|
+
EMPTY_LIVE_CAPTION_PLAYOUT
|
|
4557
|
+
);
|
|
4527
4558
|
const [liveLagMs, setLiveLagMs] = React9__namespace.useState(null);
|
|
4528
4559
|
const [behindLive, setBehindLive] = React9__namespace.useState(false);
|
|
4529
4560
|
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9__namespace.useState(false);
|
|
4530
4561
|
const [embedded, setEmbedded] = React9__namespace.useState(false);
|
|
4531
4562
|
const [cssFullscreen, setCssFullscreen] = React9__namespace.useState(false);
|
|
4532
|
-
const [appleMobile, setAppleMobile] = React9__namespace.useState(false);
|
|
4533
4563
|
const [webkitNativeFs, setWebkitNativeFs] = React9__namespace.useState(false);
|
|
4534
4564
|
const hideTimerRef = React9__namespace.useRef(null);
|
|
4565
|
+
const liveCaptionCuesRef = React9__namespace.useRef(liveCaptionCues);
|
|
4566
|
+
const liveLagMsRef = React9__namespace.useRef(liveLagMs);
|
|
4567
|
+
const compactChromeRef = React9__namespace.useRef(compactChrome);
|
|
4568
|
+
liveCaptionCuesRef.current = liveCaptionCues;
|
|
4569
|
+
liveLagMsRef.current = liveLagMs;
|
|
4570
|
+
compactChromeRef.current = compactChrome;
|
|
4535
4571
|
cssFullscreenRef.current = cssFullscreen;
|
|
4536
4572
|
captionLocaleRef.current = captionLocale;
|
|
4537
4573
|
React9__namespace.useEffect(() => {
|
|
@@ -4607,7 +4643,6 @@ function VideoPlayer({
|
|
|
4607
4643
|
}, [paused, videoRef, isPlaying]);
|
|
4608
4644
|
React9__namespace.useEffect(() => {
|
|
4609
4645
|
setEmbedded(isEmbeddedWindow());
|
|
4610
|
-
setAppleMobile(isAppleMobileDevice());
|
|
4611
4646
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4612
4647
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4613
4648
|
videoRef.current?.setAttribute("webkit-playsinline", "");
|
|
@@ -4748,12 +4783,28 @@ function VideoPlayer({
|
|
|
4748
4783
|
window.clearInterval(timer);
|
|
4749
4784
|
};
|
|
4750
4785
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4786
|
+
React9__namespace.useEffect(() => {
|
|
4787
|
+
if (!liveCaptionsBaseUrl || captionLocale === "off") {
|
|
4788
|
+
setLivePlayout(EMPTY_LIVE_CAPTION_PLAYOUT);
|
|
4789
|
+
return;
|
|
4790
|
+
}
|
|
4791
|
+
const tick = () => {
|
|
4792
|
+
setLivePlayout(
|
|
4793
|
+
(prev) => advanceLiveCaptionPlayout(
|
|
4794
|
+
prev,
|
|
4795
|
+
coalesceLiveCaptionCues(liveCaptionCuesRef.current),
|
|
4796
|
+
Date.now(),
|
|
4797
|
+
liveLagMsRef.current,
|
|
4798
|
+
compactChromeRef.current ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE
|
|
4799
|
+
)
|
|
4800
|
+
);
|
|
4801
|
+
};
|
|
4802
|
+
tick();
|
|
4803
|
+
const timer = window.setInterval(tick, LIVE_CAPTION_PLAYOUT_MS);
|
|
4804
|
+
return () => window.clearInterval(timer);
|
|
4805
|
+
}, [liveCaptionsBaseUrl, captionLocale]);
|
|
4806
|
+
const captionWrapWidth = compactChrome ? CAPTION_COMPACT_CHARS_PER_LINE : CAPTION_MAX_CHARS_PER_LINE;
|
|
4807
|
+
const captionScreen = liveCaptionsBaseUrl ? livePlayout.screen : captionScreenAtTime(captionCues, currentTime, captionWrapWidth);
|
|
4757
4808
|
React9__namespace.useEffect(() => {
|
|
4758
4809
|
const video = videoRef.current;
|
|
4759
4810
|
if (!video || !liveCaptionsBaseUrl) return;
|
|
@@ -4800,12 +4851,14 @@ function VideoPlayer({
|
|
|
4800
4851
|
if (!video || captionLocale === "off" || !liveCaptionsBaseUrl) return;
|
|
4801
4852
|
const track = findSubtitleTrack(video, captionLocale);
|
|
4802
4853
|
if (!track) return;
|
|
4854
|
+
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
4803
4855
|
syncNativeCaptionCue(
|
|
4804
4856
|
video,
|
|
4805
4857
|
track,
|
|
4806
|
-
|
|
4858
|
+
livePlayout.screen?.text ?? "",
|
|
4859
|
+
remaining
|
|
4807
4860
|
);
|
|
4808
|
-
}, [
|
|
4861
|
+
}, [livePlayout, captionLocale, liveCaptionsBaseUrl]);
|
|
4809
4862
|
function togglePlay() {
|
|
4810
4863
|
const video = videoRef.current;
|
|
4811
4864
|
if (!video) return;
|
|
@@ -5071,22 +5124,7 @@ function VideoPlayer({
|
|
|
5071
5124
|
] }),
|
|
5072
5125
|
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}` })
|
|
5073
5126
|
] }),
|
|
5074
|
-
|
|
5075
|
-
LiveCaptionStack,
|
|
5076
|
-
{
|
|
5077
|
-
cues: captionStackCues,
|
|
5078
|
-
latestLabel: t.captionsLatest,
|
|
5079
|
-
variant: appleMobile ? "window" : "scroll"
|
|
5080
|
-
}
|
|
5081
|
-
),
|
|
5082
|
-
!liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsxRuntime.jsx(
|
|
5083
|
-
"div",
|
|
5084
|
-
{
|
|
5085
|
-
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
5086
|
-
"data-slot": "video-captions",
|
|
5087
|
-
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 })
|
|
5088
|
-
}
|
|
5089
|
-
),
|
|
5127
|
+
captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsxRuntime.jsx(CaptionOverlay, { screen: captionScreen }),
|
|
5090
5128
|
active && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5091
5129
|
"div",
|
|
5092
5130
|
{
|