@livo-tv/blocks 1.13.0 → 1.14.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 +89 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +89 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3872,6 +3872,22 @@ function stabilizeLiveLagMs(previous, next) {
|
|
|
3872
3872
|
function isCaptionLocale(value) {
|
|
3873
3873
|
return CAPTION_LOCALES.includes(value);
|
|
3874
3874
|
}
|
|
3875
|
+
function isLivePlaylistSrc(src) {
|
|
3876
|
+
return /\/live\//i.test(src);
|
|
3877
|
+
}
|
|
3878
|
+
function zeroAnchorCaptionCues(cues) {
|
|
3879
|
+
if (cues.length === 0) return cues;
|
|
3880
|
+
let origin = Number.POSITIVE_INFINITY;
|
|
3881
|
+
for (const cue of cues) {
|
|
3882
|
+
if (Number.isFinite(cue.start) && cue.start < origin) origin = cue.start;
|
|
3883
|
+
}
|
|
3884
|
+
if (!Number.isFinite(origin) || origin <= 0) return cues;
|
|
3885
|
+
return cues.map((cue) => ({
|
|
3886
|
+
...cue,
|
|
3887
|
+
start: Math.max(0, cue.start - origin),
|
|
3888
|
+
end: Math.max(0, cue.end - origin)
|
|
3889
|
+
}));
|
|
3890
|
+
}
|
|
3875
3891
|
function captionsVttUrlFromPlayback(src, locale) {
|
|
3876
3892
|
const trimmed = src.trim();
|
|
3877
3893
|
if (!trimmed) return null;
|
|
@@ -3919,6 +3935,33 @@ function liveCuesDue(cues, now, lagMs, extraLagMs = LIVE_CUE_EXTRA_LAG_MS) {
|
|
|
3919
3935
|
(cue) => Number.isFinite(cue.receivedAt) && now - cue.receivedAt >= threshold
|
|
3920
3936
|
).sort((left, right) => left.receivedAt - right.receivedAt);
|
|
3921
3937
|
}
|
|
3938
|
+
function normalizeLiveCaptionText(text) {
|
|
3939
|
+
return text.trim().replace(/\s+/g, " ").toLowerCase();
|
|
3940
|
+
}
|
|
3941
|
+
function coalesceLiveCaptionCues(cues) {
|
|
3942
|
+
const out = [];
|
|
3943
|
+
for (const cue of cues) {
|
|
3944
|
+
const text = cue.text.trim();
|
|
3945
|
+
if (!text) continue;
|
|
3946
|
+
const last = out[out.length - 1];
|
|
3947
|
+
if (!last) {
|
|
3948
|
+
out.push({ text, receivedAt: cue.receivedAt });
|
|
3949
|
+
continue;
|
|
3950
|
+
}
|
|
3951
|
+
const lastNorm = normalizeLiveCaptionText(last.text);
|
|
3952
|
+
const nextNorm = normalizeLiveCaptionText(text);
|
|
3953
|
+
if (lastNorm === nextNorm) continue;
|
|
3954
|
+
if (nextNorm.startsWith(lastNorm) || lastNorm.startsWith(nextNorm)) {
|
|
3955
|
+
out[out.length - 1] = {
|
|
3956
|
+
text: nextNorm.length >= lastNorm.length ? text : last.text,
|
|
3957
|
+
receivedAt: cue.receivedAt
|
|
3958
|
+
};
|
|
3959
|
+
continue;
|
|
3960
|
+
}
|
|
3961
|
+
out.push({ text, receivedAt: cue.receivedAt });
|
|
3962
|
+
}
|
|
3963
|
+
return out;
|
|
3964
|
+
}
|
|
3922
3965
|
function mergeLiveCaptionCues(existing, incoming, cap = LIVE_STACK_MAX_CUES) {
|
|
3923
3966
|
const map = /* @__PURE__ */ new Map();
|
|
3924
3967
|
for (const cue of existing) {
|
|
@@ -3970,27 +4013,40 @@ var NEAR_BOTTOM_PX = 24;
|
|
|
3970
4013
|
function LiveCaptionStack({ cues, latestLabel }) {
|
|
3971
4014
|
const scrollerRef = React9.useRef(null);
|
|
3972
4015
|
const followRef = React9.useRef(true);
|
|
4016
|
+
const ignoreScrollRef = React9.useRef(false);
|
|
3973
4017
|
const [following, setFollowing] = React9.useState(true);
|
|
3974
4018
|
const prefersReduced = useMediaQuery2("(prefers-reduced-motion: reduce)");
|
|
3975
4019
|
const lastReceivedAt = cues[cues.length - 1]?.receivedAt;
|
|
3976
4020
|
const scrollToLatest = React9.useCallback(() => {
|
|
3977
4021
|
const scroller = scrollerRef.current;
|
|
3978
4022
|
if (!scroller) return;
|
|
4023
|
+
ignoreScrollRef.current = true;
|
|
3979
4024
|
scroller.scrollTo({
|
|
3980
4025
|
top: scroller.scrollHeight,
|
|
3981
4026
|
behavior: prefersReduced ? "auto" : "smooth"
|
|
3982
4027
|
});
|
|
3983
4028
|
followRef.current = true;
|
|
3984
4029
|
setFollowing(true);
|
|
4030
|
+
window.requestAnimationFrame(() => {
|
|
4031
|
+
window.requestAnimationFrame(() => {
|
|
4032
|
+
ignoreScrollRef.current = false;
|
|
4033
|
+
});
|
|
4034
|
+
});
|
|
3985
4035
|
}, [prefersReduced]);
|
|
3986
4036
|
React9.useLayoutEffect(() => {
|
|
3987
4037
|
if (!followRef.current) return;
|
|
3988
4038
|
const scroller = scrollerRef.current;
|
|
3989
4039
|
if (!scroller) return;
|
|
4040
|
+
ignoreScrollRef.current = true;
|
|
3990
4041
|
scroller.scrollTo({
|
|
3991
4042
|
top: scroller.scrollHeight,
|
|
3992
4043
|
behavior: prefersReduced ? "auto" : "smooth"
|
|
3993
4044
|
});
|
|
4045
|
+
window.requestAnimationFrame(() => {
|
|
4046
|
+
window.requestAnimationFrame(() => {
|
|
4047
|
+
ignoreScrollRef.current = false;
|
|
4048
|
+
});
|
|
4049
|
+
});
|
|
3994
4050
|
}, [lastReceivedAt, prefersReduced, cues.length]);
|
|
3995
4051
|
if (cues.length === 0) return null;
|
|
3996
4052
|
return /* @__PURE__ */ jsx(
|
|
@@ -4014,31 +4070,40 @@ function LiveCaptionStack({ cues, latestLabel }) {
|
|
|
4014
4070
|
ref: scrollerRef,
|
|
4015
4071
|
role: "log",
|
|
4016
4072
|
"aria-relevant": "additions",
|
|
4017
|
-
className: "pointer-events-auto max-h-[4.5rem] overflow-x-hidden overflow-y-auto rounded-sm bg-black/70 px-3 py-1.5 text-
|
|
4073
|
+
className: "pointer-events-auto max-h-[4.5rem] overflow-x-hidden overflow-y-auto rounded-sm bg-black/70 px-3 py-1.5 text-sm font-medium text-white shadow-sm",
|
|
4018
4074
|
onScroll: (event) => {
|
|
4075
|
+
if (ignoreScrollRef.current) return;
|
|
4019
4076
|
const scroller = event.currentTarget;
|
|
4020
4077
|
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < NEAR_BOTTOM_PX;
|
|
4021
4078
|
followRef.current = nearBottom;
|
|
4022
4079
|
setFollowing(nearBottom);
|
|
4023
4080
|
},
|
|
4024
|
-
children:
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4081
|
+
children: /* @__PURE__ */ jsx(
|
|
4082
|
+
"p",
|
|
4083
|
+
{
|
|
4084
|
+
className: cn(
|
|
4085
|
+
"text-justify [text-align-last:left] leading-5 break-words",
|
|
4086
|
+
!prefersReduced && "transition-opacity"
|
|
4087
|
+
),
|
|
4088
|
+
children: cues.map((cue, index) => {
|
|
4089
|
+
const fromEnd = cues.length - 1 - index;
|
|
4090
|
+
const opacity = fromEnd === 0 ? 1 : fromEnd === 1 ? 0.75 : 0.45;
|
|
4091
|
+
const newest = fromEnd === 0;
|
|
4092
|
+
return /* @__PURE__ */ jsxs(
|
|
4093
|
+
"span",
|
|
4094
|
+
{
|
|
4095
|
+
style: { opacity },
|
|
4096
|
+
"aria-live": newest ? "polite" : void 0,
|
|
4097
|
+
children: [
|
|
4098
|
+
index > 0 ? " " : "",
|
|
4099
|
+
cue.text
|
|
4100
|
+
]
|
|
4101
|
+
},
|
|
4102
|
+
cue.receivedAt
|
|
4103
|
+
);
|
|
4104
|
+
})
|
|
4105
|
+
}
|
|
4106
|
+
)
|
|
4042
4107
|
}
|
|
4043
4108
|
)
|
|
4044
4109
|
] })
|
|
@@ -4317,7 +4382,8 @@ function VideoPlayer({
|
|
|
4317
4382
|
return;
|
|
4318
4383
|
}
|
|
4319
4384
|
const cues = await loadCaptionVtt(url);
|
|
4320
|
-
|
|
4385
|
+
const next = isLivePlaylistSrc(src) ? zeroAnchorCaptionCues(cues) : cues;
|
|
4386
|
+
if (!cancelled) setCaptionCues(next);
|
|
4321
4387
|
};
|
|
4322
4388
|
void load();
|
|
4323
4389
|
if (!liveCaptionsBaseUrl) return;
|
|
@@ -4327,7 +4393,9 @@ function VideoPlayer({
|
|
|
4327
4393
|
window.clearInterval(timer);
|
|
4328
4394
|
};
|
|
4329
4395
|
}, [captionLocale, liveCaptionsBaseUrl, src]);
|
|
4330
|
-
const liveDueCues = liveCaptionsBaseUrl ?
|
|
4396
|
+
const liveDueCues = liveCaptionsBaseUrl ? coalesceLiveCaptionCues(
|
|
4397
|
+
liveCuesDue(liveCaptionCues, Date.now(), liveLagMs)
|
|
4398
|
+
) : [];
|
|
4331
4399
|
const activeCaption = liveCaptionsBaseUrl ? null : captionAtTime(captionCues, currentTime);
|
|
4332
4400
|
function togglePlay() {
|
|
4333
4401
|
const video = videoRef.current;
|