@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.js
CHANGED
|
@@ -3928,6 +3928,15 @@ function captionAtTime(cues, time, options) {
|
|
|
3928
3928
|
if (matched) return matched;
|
|
3929
3929
|
return null;
|
|
3930
3930
|
}
|
|
3931
|
+
function vttCuesDueAt(cues, currentTime, cap = LIVE_STACK_MAX_CUES) {
|
|
3932
|
+
if (!Number.isFinite(currentTime)) return [];
|
|
3933
|
+
return cues.filter(
|
|
3934
|
+
(cue) => Boolean(cue.text.trim()) && Number.isFinite(cue.start) && cue.start <= currentTime
|
|
3935
|
+
).sort((left, right) => left.start - right.start).slice(-Math.max(1, cap)).map((cue) => ({
|
|
3936
|
+
text: cue.text.trim(),
|
|
3937
|
+
receivedAt: cue.start * 1e3
|
|
3938
|
+
}));
|
|
3939
|
+
}
|
|
3931
3940
|
function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
3932
3941
|
if (lagMs == null || !Number.isFinite(lagMs) || lagMs < 0) return [];
|
|
3933
3942
|
const threshold = lagMs + extraLagMs;
|
|
@@ -3935,9 +3944,41 @@ function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
|
3935
3944
|
(cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
|
|
3936
3945
|
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
3937
3946
|
}
|
|
3947
|
+
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
3938
3948
|
function normalizeLiveCaptionText(text) {
|
|
3939
3949
|
return text.trim().replace(/\s+/g, " ").toLowerCase();
|
|
3940
3950
|
}
|
|
3951
|
+
function lastSubseqIndex(haystack, needle) {
|
|
3952
|
+
if (needle.length === 0 || needle.length > haystack.length) return -1;
|
|
3953
|
+
let found = -1;
|
|
3954
|
+
for (let index = 0; index <= haystack.length - needle.length; index += 1) {
|
|
3955
|
+
let match = true;
|
|
3956
|
+
for (let offset = 0; offset < needle.length; offset += 1) {
|
|
3957
|
+
if (haystack[index + offset] !== needle[offset]) {
|
|
3958
|
+
match = false;
|
|
3959
|
+
break;
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
if (match) found = index;
|
|
3963
|
+
}
|
|
3964
|
+
return found;
|
|
3965
|
+
}
|
|
3966
|
+
function remainderAfterOverlap(previous, next) {
|
|
3967
|
+
const prevWords = normalizeLiveCaptionText(previous).split(" ").filter(Boolean);
|
|
3968
|
+
const nextWords = next.trim().replace(/\s+/g, " ").split(" ").filter(Boolean);
|
|
3969
|
+
const nextNorm = nextWords.map((word) => word.toLowerCase());
|
|
3970
|
+
const maxN = Math.min(prevWords.length, nextNorm.length);
|
|
3971
|
+
for (let size = maxN; size >= LIVE_OVERLAP_MIN_WORDS; size -= 1) {
|
|
3972
|
+
for (let start = prevWords.length - size; start >= 0; start -= 1) {
|
|
3973
|
+
const gram = prevWords.slice(start, start + size);
|
|
3974
|
+
const index = lastSubseqIndex(nextNorm, gram);
|
|
3975
|
+
if (index !== -1) {
|
|
3976
|
+
return nextWords.slice(index + size).join(" ");
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
}
|
|
3980
|
+
return null;
|
|
3981
|
+
}
|
|
3941
3982
|
function coalesceLiveCaptionCues(cues) {
|
|
3942
3983
|
const out = [];
|
|
3943
3984
|
for (const cue of cues) {
|
|
@@ -3958,6 +3999,12 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
3958
3999
|
};
|
|
3959
4000
|
continue;
|
|
3960
4001
|
}
|
|
4002
|
+
const remainder = remainderAfterOverlap(last.text, text);
|
|
4003
|
+
if (remainder !== null) {
|
|
4004
|
+
if (!remainder) continue;
|
|
4005
|
+
out.push({ text: remainder, receivedAt: cue.receivedAt });
|
|
4006
|
+
continue;
|
|
4007
|
+
}
|
|
3961
4008
|
out.push({ text, receivedAt: cue.receivedAt });
|
|
3962
4009
|
}
|
|
3963
4010
|
return out;
|
|
@@ -4393,10 +4440,11 @@ function VideoPlayer({
|
|
|
4393
4440
|
window.clearInterval(timer);
|
|
4394
4441
|
};
|
|
4395
4442
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4443
|
+
const endedLiveReplay = !liveCaptionsBaseUrl && isLivePlaylistSrc(src);
|
|
4396
4444
|
const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
|
|
4397
4445
|
liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
|
|
4398
|
-
) : [];
|
|
4399
|
-
const activeCaption = liveCaptionsBaseUrl ? null : captionAtTime(captionCues, currentTime);
|
|
4446
|
+
) : endedLiveReplay ? coalesceLiveCaptionCues(vttCuesDueAt(captionCues, currentTime)) : [];
|
|
4447
|
+
const activeCaption = liveCaptionsBaseUrl || endedLiveReplay ? null : captionAtTime(captionCues, currentTime);
|
|
4400
4448
|
function togglePlay() {
|
|
4401
4449
|
const video = videoRef.current;
|
|
4402
4450
|
if (!video) return;
|
|
@@ -4626,8 +4674,8 @@ function VideoPlayer({
|
|
|
4626
4674
|
] }),
|
|
4627
4675
|
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}` })
|
|
4628
4676
|
] }),
|
|
4629
|
-
liveCaptionsBaseUrl && captionLocale !== "off" && /* @__PURE__ */ jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
|
|
4630
|
-
!liveCaptionsBaseUrl && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsx(
|
|
4677
|
+
(liveCaptionsBaseUrl || endedLiveReplay) && captionLocale !== "off" && /* @__PURE__ */ jsx(LiveCaptionStack, { cues: liveDueCues, latestLabel: t.captionsLatest }),
|
|
4678
|
+
!liveCaptionsBaseUrl && !endedLiveReplay && activeCaption && captionLocale !== "off" && /* @__PURE__ */ jsx(
|
|
4631
4679
|
"div",
|
|
4632
4680
|
{
|
|
4633
4681
|
className: "pointer-events-none absolute inset-x-0 bottom-16 z-[1] flex justify-center px-4",
|