@livo-tv/blocks 1.14.0 → 1.16.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 +52 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3954,6 +3954,15 @@ function captionAtTime(cues, time, options) {
|
|
|
3954
3954
|
if (matched) return matched;
|
|
3955
3955
|
return null;
|
|
3956
3956
|
}
|
|
3957
|
+
function vttCuesDueAt(cues, currentTime, cap = LIVE_STACK_MAX_CUES) {
|
|
3958
|
+
if (!Number.isFinite(currentTime)) return [];
|
|
3959
|
+
return cues.filter(
|
|
3960
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && cue.start <= currentTime
|
|
3961
|
+
).sort((left, right) => left.start - right.start).slice(-Math.max(1, cap)).map((cue) => ({
|
|
3962
|
+
text: cue.text.trim(),
|
|
3963
|
+
receivedAt: cue.start * 1e3
|
|
3964
|
+
}));
|
|
3965
|
+
}
|
|
3957
3966
|
function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
3958
3967
|
if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return [];
|
|
3959
3968
|
const threshold = lagMs + extraLagMs;
|
|
@@ -3961,9 +3970,41 @@ function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
|
3961
3970
|
(cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
|
|
3962
3971
|
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
3963
3972
|
}
|
|
3973
|
+
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
3964
3974
|
function normalizeLiveCaptionText(text) {
|
|
3965
3975
|
return text.trim().replace(/\s+/g, " ").toLowerCase();
|
|
3966
3976
|
}
|
|
3977
|
+
function lastSubseqIndex(haystack, needle) {
|
|
3978
|
+
if (needle.length === 0 || needle.length > haystack.length) return -1;
|
|
3979
|
+
let found = -1;
|
|
3980
|
+
for (let index = 0; index <= haystack.length - needle.length; index += 1) {
|
|
3981
|
+
let match = true;
|
|
3982
|
+
for (let offset = 0; offset < needle.length; offset += 1) {
|
|
3983
|
+
if (haystack[index + offset] !== needle[offset]) {
|
|
3984
|
+
match = false;
|
|
3985
|
+
break;
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
if (match) found = index;
|
|
3989
|
+
}
|
|
3990
|
+
return found;
|
|
3991
|
+
}
|
|
3992
|
+
function remainderAfterOverlap(previous, next) {
|
|
3993
|
+
const prevWords = normalizeLiveCaptionText(previous).split(" ").filter(Boolean);
|
|
3994
|
+
const nextWords = next.trim().replace(/\s+/g, " ").split(" ").filter(Boolean);
|
|
3995
|
+
const nextNorm = nextWords.map((word) => word.toLowerCase());
|
|
3996
|
+
const maxN = Math.min(prevWords.length, nextNorm.length);
|
|
3997
|
+
for (let size = maxN; size >= LIVE_OVERLAP_MIN_WORDS; size -= 1) {
|
|
3998
|
+
for (let start = prevWords.length - size; start >= 0; start -= 1) {
|
|
3999
|
+
const gram = prevWords.slice(start, start + size);
|
|
4000
|
+
const index = lastSubseqIndex(nextNorm, gram);
|
|
4001
|
+
if (index !== -1) {
|
|
4002
|
+
return nextWords.slice(index + size).join(" ");
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
return null;
|
|
4007
|
+
}
|
|
3967
4008
|
function coalesceLiveCaptionCues(cues) {
|
|
3968
4009
|
const out = [];
|
|
3969
4010
|
for (const cue of cues) {
|
|
@@ -3984,6 +4025,12 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
3984
4025
|
};
|
|
3985
4026
|
continue;
|
|
3986
4027
|
}
|
|
4028
|
+
const remainder = remainderAfterOverlap(last.text, text);
|
|
4029
|
+
if (remainder !== null) {
|
|
4030
|
+
if (!remainder) continue;
|
|
4031
|
+
out.push({ text: remainder, receivedAt: cue.receivedAt });
|
|
4032
|
+
continue;
|
|
4033
|
+
}
|
|
3987
4034
|
out.push({ text, receivedAt: cue.receivedAt });
|
|
3988
4035
|
}
|
|
3989
4036
|
return out;
|
|
@@ -4419,10 +4466,11 @@ function VideoPlayer({
|
|
|
4419
4466
|
window.clearInterval(timer);
|
|
4420
4467
|
};
|
|
4421
4468
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4469
|
+
const endedLiveReplay = !liveCaptionsBaseUrl && isLivePlaylistSrc(src);
|
|
4422
4470
|
const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
|
|
4423
4471
|
liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
|
|
4424
|
-
) : [];
|
|
4425
|
-
const activeCaption = liveCaptionsBaseUrl ? null : captionAtTime(captionCues, currentTime);
|
|
4472
|
+
) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
|
|
4473
|
+
const activeCaption = liveCaptionsBaseUrl || endedLiveReplay ? null : captionAtTime(captionCues, currentTime);
|
|
4426
4474
|
function togglePlay() {
|
|
4427
4475
|
const video = videoRef.current;
|
|
4428
4476
|
if (!video) return;
|
|
@@ -4652,8 +4700,8 @@ function VideoPlayer({
|
|
|
4652
4700
|
] }),
|
|
4653
4701
|
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}` })
|
|
4654
4702
|
] }),
|
|
4655
|
-
liveCaptionsBaseUrl && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
|
|
4656
|
-
!liveCaptionsBaseUrl && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4703
|
+
(liveCaptionsBaseUrl || endedLiveReplay) && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
|
|
4704
|
+
!liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4657
4705
|
"div",
|
|
4658
4706
|
{
|
|
4659
4707
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|