@livo-tv/blocks 1.14.0 → 1.15.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 +38 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3935,9 +3935,41 @@ function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
|
3935
3935
|
(cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
|
|
3936
3936
|
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
3937
3937
|
}
|
|
3938
|
+
var LIVE_OVERLAP_MIN_WORDS = 4;
|
|
3938
3939
|
function normalizeLiveCaptionText(text) {
|
|
3939
3940
|
return text.trim().replace(/\s+/g, " ").toLowerCase();
|
|
3940
3941
|
}
|
|
3942
|
+
function lastSubseqIndex(haystack, needle) {
|
|
3943
|
+
if (needle.length === 0 || needle.length > haystack.length) return -1;
|
|
3944
|
+
let found = -1;
|
|
3945
|
+
for (let index = 0; index <= haystack.length - needle.length; index += 1) {
|
|
3946
|
+
let match = true;
|
|
3947
|
+
for (let offset = 0; offset < needle.length; offset += 1) {
|
|
3948
|
+
if (haystack[index + offset] !== needle[offset]) {
|
|
3949
|
+
match = false;
|
|
3950
|
+
break;
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
if (match) found = index;
|
|
3954
|
+
}
|
|
3955
|
+
return found;
|
|
3956
|
+
}
|
|
3957
|
+
function remainderAfterOverlap(previous, next) {
|
|
3958
|
+
const prevWords = normalizeLiveCaptionText(previous).split(" ").filter(Boolean);
|
|
3959
|
+
const nextWords = next.trim().replace(/\s+/g, " ").split(" ").filter(Boolean);
|
|
3960
|
+
const nextNorm = nextWords.map((word) => word.toLowerCase());
|
|
3961
|
+
const maxN = Math.min(prevWords.length, nextNorm.length);
|
|
3962
|
+
for (let size = maxN; size >= LIVE_OVERLAP_MIN_WORDS; size -= 1) {
|
|
3963
|
+
for (let start = prevWords.length - size; start >= 0; start -= 1) {
|
|
3964
|
+
const gram = prevWords.slice(start, start + size);
|
|
3965
|
+
const index = lastSubseqIndex(nextNorm, gram);
|
|
3966
|
+
if (index !== -1) {
|
|
3967
|
+
return nextWords.slice(index + size).join(" ");
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
return null;
|
|
3972
|
+
}
|
|
3941
3973
|
function coalesceLiveCaptionCues(cues) {
|
|
3942
3974
|
const out = [];
|
|
3943
3975
|
for (const cue of cues) {
|
|
@@ -3958,6 +3990,12 @@ function coalesceLiveCaptionCues(cues) {
|
|
|
3958
3990
|
};
|
|
3959
3991
|
continue;
|
|
3960
3992
|
}
|
|
3993
|
+
const remainder = remainderAfterOverlap(last.text, text);
|
|
3994
|
+
if (remainder !== null) {
|
|
3995
|
+
if (!remainder) continue;
|
|
3996
|
+
out.push({ text: remainder, receivedAt: cue.receivedAt });
|
|
3997
|
+
continue;
|
|
3998
|
+
}
|
|
3961
3999
|
out.push({ text, receivedAt: cue.receivedAt });
|
|
3962
4000
|
}
|
|
3963
4001
|
return out;
|