@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 CHANGED
@@ -3961,9 +3961,41 @@ function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
3961
3961
  (cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
3962
3962
  ).sort((left, right) => left.receivedAt - right.receivedAt);
3963
3963
  }
3964
+ var LIVE_OVERLAP_MIN_WORDS = 4;
3964
3965
  function normalizeLiveCaptionText(text) {
3965
3966
  return text.trim().replace(/\s+/g, " ").toLowerCase();
3966
3967
  }
3968
+ function lastSubseqIndex(haystack, needle) {
3969
+ if (needle.length === 0 || needle.length > haystack.length) return -1;
3970
+ let found = -1;
3971
+ for (let index = 0; index <= haystack.length - needle.length; index += 1) {
3972
+ let match = true;
3973
+ for (let offset = 0; offset < needle.length; offset += 1) {
3974
+ if (haystack[index + offset] !== needle[offset]) {
3975
+ match = false;
3976
+ break;
3977
+ }
3978
+ }
3979
+ if (match) found = index;
3980
+ }
3981
+ return found;
3982
+ }
3983
+ function remainderAfterOverlap(previous, next) {
3984
+ const prevWords = normalizeLiveCaptionText(previous).split(" ").filter(Boolean);
3985
+ const nextWords = next.trim().replace(/\s+/g, " ").split(" ").filter(Boolean);
3986
+ const nextNorm = nextWords.map((word) => word.toLowerCase());
3987
+ const maxN = Math.min(prevWords.length, nextNorm.length);
3988
+ for (let size = maxN; size >= LIVE_OVERLAP_MIN_WORDS; size -= 1) {
3989
+ for (let start = prevWords.length - size; start >= 0; start -= 1) {
3990
+ const gram = prevWords.slice(start, start + size);
3991
+ const index = lastSubseqIndex(nextNorm, gram);
3992
+ if (index !== -1) {
3993
+ return nextWords.slice(index + size).join(" ");
3994
+ }
3995
+ }
3996
+ }
3997
+ return null;
3998
+ }
3967
3999
  function coalesceLiveCaptionCues(cues) {
3968
4000
  const out = [];
3969
4001
  for (const cue of cues) {
@@ -3984,6 +4016,12 @@ function coalesceLiveCaptionCues(cues) {
3984
4016
  };
3985
4017
  continue;
3986
4018
  }
4019
+ const remainder = remainderAfterOverlap(last.text, text);
4020
+ if (remainder !== null) {
4021
+ if (!remainder) continue;
4022
+ out.push({ text: remainder, receivedAt: cue.receivedAt });
4023
+ continue;
4024
+ }
3987
4025
  out.push({ text, receivedAt: cue.receivedAt });
3988
4026
  }
3989
4027
  return out;