@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.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
|
@@ -1201,6 +1201,7 @@ function LanguageSwitcher({
|
|
|
1201
1201
|
const sizes = sizeClasses2[size];
|
|
1202
1202
|
const shapeClass = shapeClasses2[shape];
|
|
1203
1203
|
const reduceMotion = useReducedMotion();
|
|
1204
|
+
const layoutId = `${useId()}-activeLanguage`;
|
|
1204
1205
|
const defaultLabels2 = {
|
|
1205
1206
|
language: labels.language ?? "Language"
|
|
1206
1207
|
};
|
|
@@ -1276,7 +1277,7 @@ function LanguageSwitcher({
|
|
|
1276
1277
|
motion.div,
|
|
1277
1278
|
{
|
|
1278
1279
|
className: cn("absolute inset-0 bg-secondary", shapeClass),
|
|
1279
|
-
layoutId
|
|
1280
|
+
layoutId,
|
|
1280
1281
|
initial: { opacity: 0 },
|
|
1281
1282
|
animate: { opacity: 1 },
|
|
1282
1283
|
exit: { opacity: 0 },
|
|
@@ -3876,19 +3877,28 @@ function useHlsPlayback({
|
|
|
3876
3877
|
};
|
|
3877
3878
|
}
|
|
3878
3879
|
|
|
3879
|
-
// src/components/video/appleMobile.ts
|
|
3880
|
-
function isAppleMobileDevice(nav = navigator) {
|
|
3881
|
-
if (/iP(hone|ad|od)/.test(nav.userAgent)) return true;
|
|
3882
|
-
return nav.platform === "MacIntel" && nav.maxTouchPoints > 1;
|
|
3883
|
-
}
|
|
3884
|
-
|
|
3885
3880
|
// src/components/video/captions.ts
|
|
3886
3881
|
var CAPTION_LOCALES = ["en", "es", "pt"];
|
|
3887
3882
|
var LIVE_CUE_EXTRA_LAG_MS = 2e3;
|
|
3888
3883
|
var LIVE_STACK_MAX_CUES = 150;
|
|
3889
|
-
var
|
|
3890
|
-
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;
|
|
3891
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
|
+
};
|
|
3892
3902
|
function stabilizeLiveLagMs(previous, next) {
|
|
3893
3903
|
if (previous == null || !Number.isFinite(previous)) return next;
|
|
3894
3904
|
if (next <= previous) return next;
|
|
@@ -3949,26 +3959,148 @@ function parseCaptionVtt(text) {
|
|
|
3949
3959
|
}
|
|
3950
3960
|
return cues;
|
|
3951
3961
|
}
|
|
3952
|
-
function
|
|
3953
|
-
|
|
3954
|
-
if (matched) return matched;
|
|
3955
|
-
return null;
|
|
3962
|
+
function captionScreenRow(text, speaker) {
|
|
3963
|
+
return speaker == null ? { text } : { text, speaker };
|
|
3956
3964
|
}
|
|
3957
|
-
function
|
|
3958
|
-
if (
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
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;
|
|
3965
4015
|
}
|
|
3966
|
-
function
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
(
|
|
3971
|
-
|
|
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;
|
|
3972
4104
|
}
|
|
3973
4105
|
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
3974
4106
|
function normalizeLiveCaptionText(text) {
|
|
@@ -4043,17 +4175,6 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
4043
4175
|
}
|
|
4044
4176
|
return out;
|
|
4045
4177
|
}
|
|
4046
|
-
function lastLiveCaptionWindow(cues, maxCues = IOS_CAPTION_WINDOW_LINES) {
|
|
4047
|
-
return cues.slice(-Math.max(1, maxCues));
|
|
4048
|
-
}
|
|
4049
|
-
function lastCaptionLines(text, lines = IOS_CAPTION_WINDOW_LINES, charsPerLine = IOS_CAPTION_CHARS_PER_LINE) {
|
|
4050
|
-
const trimmed = text.trim().replace(/\s+/g, " ");
|
|
4051
|
-
const maxChars = Math.max(1, lines) * Math.max(1, charsPerLine);
|
|
4052
|
-
if (trimmed.length <= maxChars) return trimmed;
|
|
4053
|
-
const slice = trimmed.slice(-maxChars);
|
|
4054
|
-
const space = slice.indexOf(" ");
|
|
4055
|
-
return (space > 0 ? slice.slice(space + 1) : slice).trim();
|
|
4056
|
-
}
|
|
4057
4178
|
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
4058
4179
|
const map = /* @__PURE__ */ new Map();
|
|
4059
4180
|
for (const cue of existing) {
|
|
@@ -4129,121 +4250,29 @@ function isEmbeddedWindow(win = window) {
|
|
|
4129
4250
|
return true;
|
|
4130
4251
|
}
|
|
4131
4252
|
}
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
latestLabel,
|
|
4136
|
-
variant = "scroll"
|
|
4137
|
-
}) {
|
|
4138
|
-
const scrollerRef = React9.useRef(null);
|
|
4139
|
-
const followRef = React9.useRef(true);
|
|
4140
|
-
const ignoreScrollRef = React9.useRef(false);
|
|
4141
|
-
const [following, setFollowing] = React9.useState(true);
|
|
4142
|
-
const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
|
|
4143
|
-
const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
|
|
4144
|
-
const scrollToLatest = React9.useCallback(() => {
|
|
4145
|
-
const scroller = scrollerRef.current;
|
|
4146
|
-
if (!scroller) return;
|
|
4147
|
-
ignoreScrollRef.current = true;
|
|
4148
|
-
scroller.scrollTo({
|
|
4149
|
-
top: scroller.scrollHeight,
|
|
4150
|
-
behavior: prefersReduced ? "auto" : "smooth"
|
|
4151
|
-
});
|
|
4152
|
-
followRef.current = true;
|
|
4153
|
-
setFollowing(true);
|
|
4154
|
-
window.requestAnimationFrame(() => {
|
|
4155
|
-
window.requestAnimationFrame(() => {
|
|
4156
|
-
ignoreScrollRef.current = false;
|
|
4157
|
-
});
|
|
4158
|
-
});
|
|
4159
|
-
}, [prefersReduced]);
|
|
4253
|
+
function CaptionOverlay({ screen }) {
|
|
4254
|
+
const lastSpeakerRef = React9.useRef(void 0);
|
|
4255
|
+
const lastSpeaker = lastSpeakerRef.current;
|
|
4160
4256
|
React9.useLayoutEffect(() => {
|
|
4161
|
-
if (
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
top: scroller.scrollHeight,
|
|
4167
|
-
behavior: prefersReduced ? "auto" : "smooth"
|
|
4168
|
-
});
|
|
4169
|
-
window.requestAnimationFrame(() => {
|
|
4170
|
-
window.requestAnimationFrame(() => {
|
|
4171
|
-
ignoreScrollRef.current = false;
|
|
4172
|
-
});
|
|
4173
|
-
});
|
|
4174
|
-
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
4175
|
-
if (cues.length === 0) return null;
|
|
4176
|
-
const windowed = variant === "window";
|
|
4177
|
-
const distinctSpeakers = new Set(
|
|
4178
|
-
cues.map((cue) => cue.speaker).filter((speaker) => speaker != null)
|
|
4179
|
-
);
|
|
4180
|
-
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;
|
|
4181
4262
|
return /* @__PURE__ */ jsx(
|
|
4182
4263
|
"div",
|
|
4183
4264
|
{
|
|
4184
4265
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
4185
4266
|
"data-slot": "video-captions",
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
"
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
}
|
|
4196
|
-
),
|
|
4197
|
-
/* @__PURE__ */ jsx(
|
|
4198
|
-
"div",
|
|
4199
|
-
{
|
|
4200
|
-
ref: windowed ? void 0 : scrollerRef,
|
|
4201
|
-
role: "log",
|
|
4202
|
-
"aria-relevant": "additions",
|
|
4203
|
-
className: cn(
|
|
4204
|
-
"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%]",
|
|
4205
|
-
windowed ? "overflow-hidden" : "pointer-events-auto max-h-[min(4.5rem,18cqh)] overflow-x-hidden overflow-y-auto"
|
|
4206
|
-
),
|
|
4207
|
-
onScroll: windowed ? void 0 : (event) => {
|
|
4208
|
-
if (ignoreScrollRef.current) return;
|
|
4209
|
-
const scroller = event.currentTarget;
|
|
4210
|
-
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
|
|
4211
|
-
followRef.current = nearBottom;
|
|
4212
|
-
setFollowing(nearBottom);
|
|
4213
|
-
},
|
|
4214
|
-
children: /* @__PURE__ */ jsx(
|
|
4215
|
-
"p",
|
|
4216
|
-
{
|
|
4217
|
-
className: cn(
|
|
4218
|
-
"text-justify [text-align-last:left] leading-snug break-words",
|
|
4219
|
-
windowed && "line-clamp-3",
|
|
4220
|
-
!prefersReduced && "transition-opacity"
|
|
4221
|
-
),
|
|
4222
|
-
children: cues.map((cue, index) => {
|
|
4223
|
-
const fromEnd = cues.length - 1 - index;
|
|
4224
|
-
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4225
|
-
const newest = fromEnd === 0;
|
|
4226
|
-
const previous = cues[index - 1];
|
|
4227
|
-
const turnStart = showTurns && (index === 0 || previous?.speaker !== cue.speaker);
|
|
4228
|
-
return /* @__PURE__ */ jsxs(
|
|
4229
|
-
"span",
|
|
4230
|
-
{
|
|
4231
|
-
style: { opacity },
|
|
4232
|
-
"aria-live": newest ? "polite" : void 0,
|
|
4233
|
-
children: [
|
|
4234
|
-
turnStart && index > 0 ? /* @__PURE__ */ jsx("br", {}) : index > 0 ? " " : "",
|
|
4235
|
-
turnStart ? "\u2013 " : "",
|
|
4236
|
-
cue.text
|
|
4237
|
-
]
|
|
4238
|
-
},
|
|
4239
|
-
cue.receivedAt
|
|
4240
|
-
);
|
|
4241
|
-
})
|
|
4242
|
-
}
|
|
4243
|
-
)
|
|
4244
|
-
}
|
|
4245
|
-
)
|
|
4246
|
-
] })
|
|
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
|
+
)
|
|
4247
4276
|
}
|
|
4248
4277
|
);
|
|
4249
4278
|
}
|
|
@@ -4251,9 +4280,6 @@ function LiveCaptionStack({
|
|
|
4251
4280
|
// src/components/video/nativeCaptionTrack.ts
|
|
4252
4281
|
var NATIVE_CAPTION_HOLD_S = 4;
|
|
4253
4282
|
var NATIVE_SUBTITLE_KIND = "subtitles";
|
|
4254
|
-
function joinCaptionTexts(cues) {
|
|
4255
|
-
return cues.map((cue) => cue.text.trim()).filter(Boolean).join(" ");
|
|
4256
|
-
}
|
|
4257
4283
|
function clearNativeCaptionCues(track) {
|
|
4258
4284
|
const cues = track.cues;
|
|
4259
4285
|
if (!cues) return;
|
|
@@ -4303,12 +4329,13 @@ function ensureLiveSubtitleTracks(video, labels) {
|
|
|
4303
4329
|
return track;
|
|
4304
4330
|
});
|
|
4305
4331
|
}
|
|
4306
|
-
function syncNativeCaptionCue(video, track, text) {
|
|
4332
|
+
function syncNativeCaptionCue(video, track, text, holdSeconds = NATIVE_CAPTION_HOLD_S) {
|
|
4307
4333
|
clearNativeCaptionCues(track);
|
|
4308
4334
|
const trimmed = text.trim();
|
|
4309
4335
|
if (!trimmed) return;
|
|
4310
4336
|
const start = Number.isFinite(video.currentTime) ? video.currentTime : 0;
|
|
4311
|
-
|
|
4337
|
+
const hold = Number.isFinite(holdSeconds) ? Math.max(0.2, holdSeconds) : NATIVE_CAPTION_HOLD_S;
|
|
4338
|
+
track.addCue(new VTTCue(start, start + hold, trimmed));
|
|
4312
4339
|
}
|
|
4313
4340
|
function zeroAnchorNativeTrackCues(track) {
|
|
4314
4341
|
const list = track.cues;
|
|
@@ -4387,6 +4414,7 @@ var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
|
4387
4414
|
var CONTROLS_HIDE_MS = 3e3;
|
|
4388
4415
|
var LIVE_EDGE_THRESHOLD_S = 8;
|
|
4389
4416
|
var SEEK_STEP_S = 5;
|
|
4417
|
+
var LIVE_CAPTION_PLAYOUT_MS = 250;
|
|
4390
4418
|
var COMPACT_CHROME_PX = 640;
|
|
4391
4419
|
var VIDEO_MEDIA_STYLE = `
|
|
4392
4420
|
.livo-video-player-media::-webkit-media-controls-start-playback-button {
|
|
@@ -4498,14 +4526,22 @@ function VideoPlayer({
|
|
|
4498
4526
|
const [captionLocale, setCaptionLocale] = React9.useState(defaultCaptionLocale ?? "off");
|
|
4499
4527
|
const [captionCues, setCaptionCues] = React9.useState([]);
|
|
4500
4528
|
const [liveCaptionCues, setLiveCaptionCues] = React9.useState([]);
|
|
4529
|
+
const [livePlayout, setLivePlayout] = React9.useState(
|
|
4530
|
+
EMPTY_LIVE_CAPTION_PLAYOUT
|
|
4531
|
+
);
|
|
4501
4532
|
const [liveLagMs, setLiveLagMs] = React9.useState(null);
|
|
4502
4533
|
const [behindLive, setBehindLive] = React9.useState(false);
|
|
4503
4534
|
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React9.useState(false);
|
|
4504
4535
|
const [embedded, setEmbedded] = React9.useState(false);
|
|
4505
4536
|
const [cssFullscreen, setCssFullscreen] = React9.useState(false);
|
|
4506
|
-
const [appleMobile, setAppleMobile] = React9.useState(false);
|
|
4507
4537
|
const [webkitNativeFs, setWebkitNativeFs] = React9.useState(false);
|
|
4508
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;
|
|
4509
4545
|
cssFullscreenRef.current = cssFullscreen;
|
|
4510
4546
|
captionLocaleRef.current = captionLocale;
|
|
4511
4547
|
React9.useEffect(() => {
|
|
@@ -4581,7 +4617,6 @@ function VideoPlayer({
|
|
|
4581
4617
|
}, [paused, videoRef, isPlaying]);
|
|
4582
4618
|
React9.useEffect(() => {
|
|
4583
4619
|
setEmbedded(isEmbeddedWindow());
|
|
4584
|
-
setAppleMobile(isAppleMobileDevice());
|
|
4585
4620
|
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
4586
4621
|
videoRef.current?.setAttribute("x-webkit-airplay", "allow");
|
|
4587
4622
|
videoRef.current?.setAttribute("webkit-playsinline", "");
|
|
@@ -4722,12 +4757,28 @@ function VideoPlayer({
|
|
|
4722
4757
|
window.clearInterval(timer);
|
|
4723
4758
|
};
|
|
4724
4759
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
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);
|
|
4731
4782
|
React9.useEffect(() => {
|
|
4732
4783
|
const video = videoRef.current;
|
|
4733
4784
|
if (!video || !liveCaptionsBaseUrl) return;
|
|
@@ -4774,12 +4825,14 @@ function VideoPlayer({
|
|
|
4774
4825
|
if (!video || captionLocale === "off" || !liveCaptionsBaseUrl) return;
|
|
4775
4826
|
const track = findSubtitleTrack(video, captionLocale);
|
|
4776
4827
|
if (!track) return;
|
|
4828
|
+
const remaining = livePlayout.screen ? Math.max(0.2, (livePlayout.hideAt - Date.now()) / 1e3) : 0;
|
|
4777
4829
|
syncNativeCaptionCue(
|
|
4778
4830
|
video,
|
|
4779
4831
|
track,
|
|
4780
|
-
|
|
4832
|
+
livePlayout.screen?.text ?? "",
|
|
4833
|
+
remaining
|
|
4781
4834
|
);
|
|
4782
|
-
}, [
|
|
4835
|
+
}, [livePlayout, captionLocale, liveCaptionsBaseUrl]);
|
|
4783
4836
|
function togglePlay() {
|
|
4784
4837
|
const video = videoRef.current;
|
|
4785
4838
|
if (!video) return;
|
|
@@ -5045,22 +5098,7 @@ function VideoPlayer({
|
|
|
5045
5098
|
] }),
|
|
5046
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}` })
|
|
5047
5100
|
] }),
|
|
5048
|
-
|
|
5049
|
-
LiveCaptionStack,
|
|
5050
|
-
{
|
|
5051
|
-
cues: captionStackCues,
|
|
5052
|
-
latestLabel: t.captionsLatest,
|
|
5053
|
-
variant: appleMobile ? "window" : "scroll"
|
|
5054
|
-
}
|
|
5055
|
-
),
|
|
5056
|
-
!liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsx(
|
|
5057
|
-
"div",
|
|
5058
|
-
{
|
|
5059
|
-
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|
|
5060
|
-
"data-slot": "video-captions",
|
|
5061
|
-
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 })
|
|
5062
|
-
}
|
|
5063
|
-
),
|
|
5101
|
+
captionLocale !== "off" && !webkitNativeFs && /* @__PURE__ */ jsx(CaptionOverlay, { screen: captionScreen }),
|
|
5064
5102
|
active && /* @__PURE__ */ jsxs(
|
|
5065
5103
|
"div",
|
|
5066
5104
|
{
|