@interlacejs/player 0.2.1 → 0.3.1
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/README.md +24 -0
- package/dist/index.cjs +442 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.js +441 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -408,9 +408,10 @@ var ContentErrorBoundary = class extends React3.Component {
|
|
|
408
408
|
// src/components/interactive-video-player.tsx
|
|
409
409
|
import {
|
|
410
410
|
ensureInterlaceStyles,
|
|
411
|
+
supportsQuality,
|
|
411
412
|
themeToCssVariables
|
|
412
413
|
} from "@interlacejs/core";
|
|
413
|
-
import { useCallback, useEffect as
|
|
414
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
|
|
414
415
|
|
|
415
416
|
// src/hooks/use-interactive-media.ts
|
|
416
417
|
import {
|
|
@@ -516,7 +517,8 @@ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
|
516
517
|
var OverlayLayer = ({
|
|
517
518
|
renderState,
|
|
518
519
|
items,
|
|
519
|
-
onAnchorClick
|
|
520
|
+
onAnchorClick,
|
|
521
|
+
children
|
|
520
522
|
}) => {
|
|
521
523
|
const itemMap = useMemo(() => {
|
|
522
524
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -597,34 +599,447 @@ var OverlayLayer = ({
|
|
|
597
599
|
);
|
|
598
600
|
})
|
|
599
601
|
}
|
|
602
|
+
),
|
|
603
|
+
children
|
|
604
|
+
]
|
|
605
|
+
}
|
|
606
|
+
);
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/components/quality-control.tsx
|
|
610
|
+
import { useCallback, useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "react";
|
|
611
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
612
|
+
var DEFAULT_QUALITY_CONTROL_STRINGS = {
|
|
613
|
+
qualityLabel: "Quality",
|
|
614
|
+
qualityAutoLabel: "Auto",
|
|
615
|
+
qualityDataSaverLabel: "Data saver"
|
|
616
|
+
};
|
|
617
|
+
var PLAYBACK_POLL_MS = 500;
|
|
618
|
+
var QUALITY_CONTROL_HIDE_DELAY_MS = 2500;
|
|
619
|
+
var AUTO = -1;
|
|
620
|
+
var INSET = SPACE[2];
|
|
621
|
+
var BUTTON_SIZE = 36;
|
|
622
|
+
function readSnapshot(adapter) {
|
|
623
|
+
return {
|
|
624
|
+
levels: [...adapter.getQualityLevels()].sort((a, b) => b.height - a.height),
|
|
625
|
+
selected: adapter.getQualityLevel(),
|
|
626
|
+
active: adapter.getActiveQualityLevel()
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function prefersReducedMotion() {
|
|
630
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
631
|
+
}
|
|
632
|
+
function pointOf(event) {
|
|
633
|
+
if ("touches" in event) {
|
|
634
|
+
const touch = event.touches[0];
|
|
635
|
+
return touch ? { x: touch.clientX, y: touch.clientY } : null;
|
|
636
|
+
}
|
|
637
|
+
const mouse = event;
|
|
638
|
+
return { x: mouse.clientX, y: mouse.clientY };
|
|
639
|
+
}
|
|
640
|
+
var QualityControl = ({
|
|
641
|
+
adapter,
|
|
642
|
+
strings: stringsOverride
|
|
643
|
+
}) => {
|
|
644
|
+
const strings = { ...DEFAULT_QUALITY_CONTROL_STRINGS, ...stringsOverride };
|
|
645
|
+
const [snapshot, setSnapshot] = useState3(() => readSnapshot(adapter));
|
|
646
|
+
const [playing, setPlaying] = useState3(false);
|
|
647
|
+
const [recentActivity, setRecentActivity] = useState3(false);
|
|
648
|
+
const [focusWithin, setFocusWithin] = useState3(false);
|
|
649
|
+
const [open, setOpen] = useState3(false);
|
|
650
|
+
const [focusIndex, setFocusIndex] = useState3(0);
|
|
651
|
+
const frameRef = useRef4(null);
|
|
652
|
+
const buttonRef = useRef4(null);
|
|
653
|
+
const menuRef = useRef4(null);
|
|
654
|
+
const itemRefs = useRef4([]);
|
|
655
|
+
const hideTimerRef = useRef4(null);
|
|
656
|
+
const [reducedMotion] = useState3(prefersReducedMotion);
|
|
657
|
+
useEffect3(() => {
|
|
658
|
+
setSnapshot(readSnapshot(adapter));
|
|
659
|
+
return adapter.on(
|
|
660
|
+
"qualitychange",
|
|
661
|
+
() => setSnapshot(readSnapshot(adapter))
|
|
662
|
+
);
|
|
663
|
+
}, [adapter]);
|
|
664
|
+
const reveal = useCallback(() => {
|
|
665
|
+
setRecentActivity(true);
|
|
666
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
667
|
+
hideTimerRef.current = setTimeout(
|
|
668
|
+
() => setRecentActivity(false),
|
|
669
|
+
QUALITY_CONTROL_HIDE_DELAY_MS
|
|
670
|
+
);
|
|
671
|
+
}, []);
|
|
672
|
+
useEffect3(
|
|
673
|
+
() => () => {
|
|
674
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
675
|
+
},
|
|
676
|
+
[]
|
|
677
|
+
);
|
|
678
|
+
useEffect3(() => {
|
|
679
|
+
const offPlay = adapter.on("play", () => {
|
|
680
|
+
setPlaying(true);
|
|
681
|
+
reveal();
|
|
682
|
+
});
|
|
683
|
+
const offPause = adapter.on("pause", () => setPlaying(false));
|
|
684
|
+
let lastTime = adapter.getCurrentTime();
|
|
685
|
+
const poll = setInterval(() => {
|
|
686
|
+
const time = adapter.getCurrentTime();
|
|
687
|
+
setPlaying(time !== lastTime);
|
|
688
|
+
lastTime = time;
|
|
689
|
+
}, PLAYBACK_POLL_MS);
|
|
690
|
+
return () => {
|
|
691
|
+
offPlay();
|
|
692
|
+
offPause();
|
|
693
|
+
clearInterval(poll);
|
|
694
|
+
};
|
|
695
|
+
}, [adapter, reveal]);
|
|
696
|
+
useEffect3(() => {
|
|
697
|
+
const onActivity = (event) => {
|
|
698
|
+
const frame = frameRef.current;
|
|
699
|
+
const point = pointOf(event);
|
|
700
|
+
if (!frame || !point) return;
|
|
701
|
+
const rect = frame.getBoundingClientRect();
|
|
702
|
+
if (point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom && rect.width > 0 && rect.height > 0) {
|
|
703
|
+
reveal();
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
const events = ["mousemove", "mousedown", "touchstart"];
|
|
707
|
+
events.forEach(
|
|
708
|
+
(type) => document.addEventListener(type, onActivity, { passive: true })
|
|
709
|
+
);
|
|
710
|
+
return () => events.forEach((type) => document.removeEventListener(type, onActivity));
|
|
711
|
+
}, [reveal]);
|
|
712
|
+
useEffect3(() => {
|
|
713
|
+
if (!open) return;
|
|
714
|
+
const onPointerDown = (event) => {
|
|
715
|
+
const target = event.target;
|
|
716
|
+
if (buttonRef.current?.contains(target) || menuRef.current?.contains(target)) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
setOpen(false);
|
|
720
|
+
};
|
|
721
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
722
|
+
document.addEventListener("touchstart", onPointerDown);
|
|
723
|
+
return () => {
|
|
724
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
725
|
+
document.removeEventListener("touchstart", onPointerDown);
|
|
726
|
+
};
|
|
727
|
+
}, [open]);
|
|
728
|
+
useEffect3(() => {
|
|
729
|
+
if (open) itemRefs.current[focusIndex]?.focus();
|
|
730
|
+
}, [open, focusIndex]);
|
|
731
|
+
const { levels, selected, active } = snapshot;
|
|
732
|
+
if (levels.length < 2) return null;
|
|
733
|
+
const options = [AUTO, ...levels.map((level) => level.id)];
|
|
734
|
+
const activeLevel = levels.find((level) => level.id === active);
|
|
735
|
+
const selectedLevel = levels.find((level) => level.id === selected);
|
|
736
|
+
const lowestId = levels[levels.length - 1].id;
|
|
737
|
+
const optionLabel = (id) => {
|
|
738
|
+
if (id === AUTO) {
|
|
739
|
+
return activeLevel ? `${strings.qualityAutoLabel} \xB7 ${activeLevel.label}` : strings.qualityAutoLabel;
|
|
740
|
+
}
|
|
741
|
+
const level = levels.find((l) => l.id === id);
|
|
742
|
+
return id === lowestId ? `${strings.qualityDataSaverLabel} \xB7 ${level.label}` : level.label;
|
|
743
|
+
};
|
|
744
|
+
const currentLabel = selectedLevel ? selectedLevel.label : activeLevel ? `${strings.qualityAutoLabel} (${activeLevel.label})` : strings.qualityAutoLabel;
|
|
745
|
+
const effectiveHeight = (selectedLevel ?? activeLevel)?.height ?? 0;
|
|
746
|
+
const selectedIndex = Math.max(
|
|
747
|
+
0,
|
|
748
|
+
options.indexOf(selectedLevel ? selected : AUTO)
|
|
749
|
+
);
|
|
750
|
+
const openMenu = (index) => {
|
|
751
|
+
setFocusIndex(index);
|
|
752
|
+
setOpen(true);
|
|
753
|
+
};
|
|
754
|
+
const closeMenu = (returnFocus) => {
|
|
755
|
+
setOpen(false);
|
|
756
|
+
if (returnFocus) buttonRef.current?.focus();
|
|
757
|
+
};
|
|
758
|
+
const select = (id) => {
|
|
759
|
+
adapter.setQualityLevel(id);
|
|
760
|
+
closeMenu(true);
|
|
761
|
+
};
|
|
762
|
+
const onButtonKeyDown = (event) => {
|
|
763
|
+
if (event.key === "ArrowDown") {
|
|
764
|
+
event.preventDefault();
|
|
765
|
+
openMenu(selectedIndex);
|
|
766
|
+
} else if (event.key === "ArrowUp") {
|
|
767
|
+
event.preventDefault();
|
|
768
|
+
openMenu(options.length - 1);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
const onMenuKeyDown = (event) => {
|
|
772
|
+
const last = options.length - 1;
|
|
773
|
+
switch (event.key) {
|
|
774
|
+
case "ArrowDown":
|
|
775
|
+
event.preventDefault();
|
|
776
|
+
setFocusIndex((i) => i >= last ? 0 : i + 1);
|
|
777
|
+
break;
|
|
778
|
+
case "ArrowUp":
|
|
779
|
+
event.preventDefault();
|
|
780
|
+
setFocusIndex((i) => i <= 0 ? last : i - 1);
|
|
781
|
+
break;
|
|
782
|
+
case "Home":
|
|
783
|
+
event.preventDefault();
|
|
784
|
+
setFocusIndex(0);
|
|
785
|
+
break;
|
|
786
|
+
case "End":
|
|
787
|
+
event.preventDefault();
|
|
788
|
+
setFocusIndex(last);
|
|
789
|
+
break;
|
|
790
|
+
case "Enter":
|
|
791
|
+
case " ":
|
|
792
|
+
event.preventDefault();
|
|
793
|
+
select(options[focusIndex]);
|
|
794
|
+
break;
|
|
795
|
+
case "Escape":
|
|
796
|
+
event.preventDefault();
|
|
797
|
+
closeMenu(true);
|
|
798
|
+
break;
|
|
799
|
+
case "Tab":
|
|
800
|
+
setOpen(false);
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
const visible = !playing || open || focusWithin || recentActivity;
|
|
805
|
+
const interactive = visible ? "auto" : "none";
|
|
806
|
+
return /* @__PURE__ */ jsxs5(
|
|
807
|
+
"div",
|
|
808
|
+
{
|
|
809
|
+
ref: frameRef,
|
|
810
|
+
"data-testid": "interlace-quality-control",
|
|
811
|
+
"data-visible": visible,
|
|
812
|
+
onFocus: (event) => setFocusWithin(isKeyboardFocus(event.target)),
|
|
813
|
+
onBlur: (event) => {
|
|
814
|
+
if (!frameRef.current?.contains(event.relatedTarget)) {
|
|
815
|
+
setFocusWithin(false);
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
style: {
|
|
819
|
+
position: "absolute",
|
|
820
|
+
inset: 0,
|
|
821
|
+
pointerEvents: "none",
|
|
822
|
+
opacity: visible ? 1 : 0,
|
|
823
|
+
transition: reducedMotion ? "none" : "opacity 200ms ease",
|
|
824
|
+
fontFamily: FONTS.body,
|
|
825
|
+
zIndex: 20
|
|
826
|
+
},
|
|
827
|
+
children: [
|
|
828
|
+
/* @__PURE__ */ jsxs5(
|
|
829
|
+
"button",
|
|
830
|
+
{
|
|
831
|
+
ref: buttonRef,
|
|
832
|
+
type: "button",
|
|
833
|
+
className: "interlace-focusable",
|
|
834
|
+
"aria-label": `${strings.qualityLabel}: ${currentLabel}`,
|
|
835
|
+
"aria-haspopup": "menu",
|
|
836
|
+
"aria-expanded": open,
|
|
837
|
+
title: strings.qualityLabel,
|
|
838
|
+
onClick: () => open ? closeMenu(false) : openMenu(selectedIndex),
|
|
839
|
+
onKeyDown: onButtonKeyDown,
|
|
840
|
+
style: {
|
|
841
|
+
position: "absolute",
|
|
842
|
+
top: INSET,
|
|
843
|
+
right: INSET,
|
|
844
|
+
width: BUTTON_SIZE,
|
|
845
|
+
height: BUTTON_SIZE,
|
|
846
|
+
padding: 0,
|
|
847
|
+
display: "inline-flex",
|
|
848
|
+
alignItems: "center",
|
|
849
|
+
justifyContent: "center",
|
|
850
|
+
border: "none",
|
|
851
|
+
borderRadius: RADIUS.md,
|
|
852
|
+
background: "rgba(0, 0, 0, 0.6)",
|
|
853
|
+
color: COLORS.white,
|
|
854
|
+
cursor: "pointer",
|
|
855
|
+
pointerEvents: interactive
|
|
856
|
+
},
|
|
857
|
+
children: [
|
|
858
|
+
/* @__PURE__ */ jsx5(GearIcon, {}),
|
|
859
|
+
effectiveHeight >= 720 && /* @__PURE__ */ jsx5(
|
|
860
|
+
"span",
|
|
861
|
+
{
|
|
862
|
+
"aria-hidden": "true",
|
|
863
|
+
style: {
|
|
864
|
+
position: "absolute",
|
|
865
|
+
top: 3,
|
|
866
|
+
right: 2,
|
|
867
|
+
padding: "0 2px",
|
|
868
|
+
borderRadius: 3,
|
|
869
|
+
background: COLORS.accent,
|
|
870
|
+
color: COLORS.accentContrast,
|
|
871
|
+
fontSize: 8,
|
|
872
|
+
fontWeight: 700,
|
|
873
|
+
lineHeight: "11px"
|
|
874
|
+
},
|
|
875
|
+
children: "HD"
|
|
876
|
+
}
|
|
877
|
+
)
|
|
878
|
+
]
|
|
879
|
+
}
|
|
880
|
+
),
|
|
881
|
+
open && /* @__PURE__ */ jsxs5(
|
|
882
|
+
"div",
|
|
883
|
+
{
|
|
884
|
+
ref: menuRef,
|
|
885
|
+
role: "menu",
|
|
886
|
+
"aria-label": strings.qualityLabel,
|
|
887
|
+
onKeyDown: onMenuKeyDown,
|
|
888
|
+
style: {
|
|
889
|
+
position: "absolute",
|
|
890
|
+
top: INSET + BUTTON_SIZE + SPACE[1],
|
|
891
|
+
right: INSET,
|
|
892
|
+
minWidth: 168,
|
|
893
|
+
maxHeight: `calc(100% - ${INSET * 2 + BUTTON_SIZE + SPACE[1]}px)`,
|
|
894
|
+
overflowY: "auto",
|
|
895
|
+
boxSizing: "border-box",
|
|
896
|
+
padding: SPACE[1],
|
|
897
|
+
borderRadius: RADIUS.md,
|
|
898
|
+
background: "rgba(0, 0, 0, 0.8)",
|
|
899
|
+
color: COLORS.white,
|
|
900
|
+
fontSize: TYPE.sm,
|
|
901
|
+
boxShadow: "0 4px 16px rgba(0, 0, 0, 0.35)",
|
|
902
|
+
pointerEvents: "auto"
|
|
903
|
+
},
|
|
904
|
+
children: [
|
|
905
|
+
/* @__PURE__ */ jsx5(
|
|
906
|
+
"div",
|
|
907
|
+
{
|
|
908
|
+
"aria-hidden": "true",
|
|
909
|
+
style: {
|
|
910
|
+
padding: `${SPACE[1]}px ${SPACE[2]}px`,
|
|
911
|
+
fontSize: TYPE.xs,
|
|
912
|
+
fontWeight: 600,
|
|
913
|
+
opacity: 0.7
|
|
914
|
+
},
|
|
915
|
+
children: strings.qualityLabel
|
|
916
|
+
}
|
|
917
|
+
),
|
|
918
|
+
options.map((id, index) => {
|
|
919
|
+
const checked = selectedLevel ? id === selected : id === AUTO;
|
|
920
|
+
return /* @__PURE__ */ jsxs5(
|
|
921
|
+
"button",
|
|
922
|
+
{
|
|
923
|
+
ref: (node) => {
|
|
924
|
+
itemRefs.current[index] = node;
|
|
925
|
+
},
|
|
926
|
+
type: "button",
|
|
927
|
+
role: "menuitemradio",
|
|
928
|
+
"aria-checked": checked,
|
|
929
|
+
tabIndex: -1,
|
|
930
|
+
className: "interlace-focusable",
|
|
931
|
+
onClick: () => select(id),
|
|
932
|
+
onMouseEnter: () => setFocusIndex(index),
|
|
933
|
+
style: {
|
|
934
|
+
display: "flex",
|
|
935
|
+
alignItems: "center",
|
|
936
|
+
gap: SPACE[2],
|
|
937
|
+
width: "100%",
|
|
938
|
+
minHeight: 36,
|
|
939
|
+
padding: `0 ${SPACE[3]}px 0 ${SPACE[2]}px`,
|
|
940
|
+
border: "none",
|
|
941
|
+
borderRadius: RADIUS.sm,
|
|
942
|
+
background: index === focusIndex ? "rgba(255, 255, 255, 0.16)" : "transparent",
|
|
943
|
+
color: "inherit",
|
|
944
|
+
font: "inherit",
|
|
945
|
+
fontWeight: checked ? 600 : 400,
|
|
946
|
+
textAlign: "left",
|
|
947
|
+
whiteSpace: "nowrap",
|
|
948
|
+
cursor: "pointer"
|
|
949
|
+
},
|
|
950
|
+
children: [
|
|
951
|
+
/* @__PURE__ */ jsx5(
|
|
952
|
+
"span",
|
|
953
|
+
{
|
|
954
|
+
"aria-hidden": "true",
|
|
955
|
+
style: {
|
|
956
|
+
display: "inline-flex",
|
|
957
|
+
width: 16,
|
|
958
|
+
color: COLORS.accent
|
|
959
|
+
},
|
|
960
|
+
children: checked && /* @__PURE__ */ jsx5(CheckIcon, {})
|
|
961
|
+
}
|
|
962
|
+
),
|
|
963
|
+
optionLabel(id)
|
|
964
|
+
]
|
|
965
|
+
},
|
|
966
|
+
id
|
|
967
|
+
);
|
|
968
|
+
})
|
|
969
|
+
]
|
|
970
|
+
}
|
|
600
971
|
)
|
|
601
972
|
]
|
|
602
973
|
}
|
|
603
974
|
);
|
|
604
975
|
};
|
|
976
|
+
var GearIcon = () => /* @__PURE__ */ jsxs5(
|
|
977
|
+
"svg",
|
|
978
|
+
{
|
|
979
|
+
width: "20",
|
|
980
|
+
height: "20",
|
|
981
|
+
viewBox: "0 0 24 24",
|
|
982
|
+
fill: "none",
|
|
983
|
+
stroke: "currentColor",
|
|
984
|
+
strokeWidth: "2",
|
|
985
|
+
strokeLinecap: "round",
|
|
986
|
+
strokeLinejoin: "round",
|
|
987
|
+
"aria-hidden": "true",
|
|
988
|
+
focusable: "false",
|
|
989
|
+
children: [
|
|
990
|
+
/* @__PURE__ */ jsx5("circle", { cx: "12", cy: "12", r: "3" }),
|
|
991
|
+
/* @__PURE__ */ jsx5("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" })
|
|
992
|
+
]
|
|
993
|
+
}
|
|
994
|
+
);
|
|
995
|
+
var CheckIcon = () => /* @__PURE__ */ jsx5(
|
|
996
|
+
"svg",
|
|
997
|
+
{
|
|
998
|
+
width: "16",
|
|
999
|
+
height: "16",
|
|
1000
|
+
viewBox: "0 0 24 24",
|
|
1001
|
+
fill: "none",
|
|
1002
|
+
stroke: "currentColor",
|
|
1003
|
+
strokeWidth: "3",
|
|
1004
|
+
strokeLinecap: "round",
|
|
1005
|
+
strokeLinejoin: "round",
|
|
1006
|
+
"aria-hidden": "true",
|
|
1007
|
+
focusable: "false",
|
|
1008
|
+
children: /* @__PURE__ */ jsx5("polyline", { points: "20 6 9 17 4 12" })
|
|
1009
|
+
}
|
|
1010
|
+
);
|
|
1011
|
+
function isKeyboardFocus(element) {
|
|
1012
|
+
try {
|
|
1013
|
+
return element.matches(":focus-visible");
|
|
1014
|
+
} catch {
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
605
1018
|
|
|
606
1019
|
// src/components/interactive-video-player.tsx
|
|
607
|
-
import { jsx as
|
|
1020
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
608
1021
|
var InteractiveVideoPlayer = ({
|
|
609
1022
|
adapter,
|
|
610
1023
|
document: doc,
|
|
611
1024
|
registry,
|
|
612
1025
|
onError,
|
|
613
1026
|
theme,
|
|
614
|
-
className
|
|
1027
|
+
className,
|
|
1028
|
+
showQualityControl = true,
|
|
1029
|
+
strings
|
|
615
1030
|
}) => {
|
|
616
|
-
const [renderState, setRenderState] =
|
|
1031
|
+
const [renderState, setRenderState] = useState4({
|
|
617
1032
|
visibleAnchorIds: [],
|
|
618
1033
|
completedTagIds: [],
|
|
619
1034
|
openedContentIds: []
|
|
620
1035
|
});
|
|
621
|
-
const [activeContentId, setActiveContentId] =
|
|
622
|
-
const [completingId, setCompletingId] =
|
|
623
|
-
const [completingScore, setCompletingScore] =
|
|
1036
|
+
const [activeContentId, setActiveContentId] = useState4(null);
|
|
1037
|
+
const [completingId, setCompletingId] = useState4(null);
|
|
1038
|
+
const [completingScore, setCompletingScore] = useState4(
|
|
624
1039
|
void 0
|
|
625
1040
|
);
|
|
626
|
-
const lastAutoOpenedBlockingIdRef =
|
|
627
|
-
|
|
1041
|
+
const lastAutoOpenedBlockingIdRef = useRef5(null);
|
|
1042
|
+
useEffect4(() => {
|
|
628
1043
|
ensureInterlaceStyles();
|
|
629
1044
|
}, []);
|
|
630
1045
|
const { controller, items, initialized, error } = useInteractiveMedia({
|
|
@@ -634,14 +1049,14 @@ var InteractiveVideoPlayer = ({
|
|
|
634
1049
|
onRenderStateChange: setRenderState,
|
|
635
1050
|
onError
|
|
636
1051
|
});
|
|
637
|
-
const handleAnchorClick =
|
|
1052
|
+
const handleAnchorClick = useCallback2(
|
|
638
1053
|
(contentId) => {
|
|
639
1054
|
adapter.pause();
|
|
640
1055
|
setActiveContentId(contentId);
|
|
641
1056
|
},
|
|
642
1057
|
[adapter]
|
|
643
1058
|
);
|
|
644
|
-
|
|
1059
|
+
useEffect4(() => {
|
|
645
1060
|
const blockingId = renderState.activeBlockingContentId;
|
|
646
1061
|
if (blockingId && blockingId !== lastAutoOpenedBlockingIdRef.current) {
|
|
647
1062
|
lastAutoOpenedBlockingIdRef.current = blockingId;
|
|
@@ -650,15 +1065,15 @@ var InteractiveVideoPlayer = ({
|
|
|
650
1065
|
lastAutoOpenedBlockingIdRef.current = null;
|
|
651
1066
|
}
|
|
652
1067
|
}, [renderState.activeBlockingContentId]);
|
|
653
|
-
const overlayShowingRef =
|
|
1068
|
+
const overlayShowingRef = useRef5(false);
|
|
654
1069
|
overlayShowingRef.current = (activeContentId ?? completingId) !== null;
|
|
655
|
-
|
|
1070
|
+
useEffect4(
|
|
656
1071
|
() => adapter.on("play", () => {
|
|
657
1072
|
if (overlayShowingRef.current) adapter.pause();
|
|
658
1073
|
}),
|
|
659
1074
|
[adapter]
|
|
660
1075
|
);
|
|
661
|
-
const handleContentComplete =
|
|
1076
|
+
const handleContentComplete = useCallback2(
|
|
662
1077
|
(score) => {
|
|
663
1078
|
if (!controller || !activeContentId) return;
|
|
664
1079
|
const item = (items ?? []).find((it) => it.getId() === activeContentId);
|
|
@@ -669,14 +1084,14 @@ var InteractiveVideoPlayer = ({
|
|
|
669
1084
|
},
|
|
670
1085
|
[controller, items, activeContentId]
|
|
671
1086
|
);
|
|
672
|
-
const handleContinueAfterCompletion =
|
|
1087
|
+
const handleContinueAfterCompletion = useCallback2(() => {
|
|
673
1088
|
setCompletingId(null);
|
|
674
1089
|
setCompletingScore(void 0);
|
|
675
1090
|
overlayShowingRef.current = false;
|
|
676
1091
|
void adapter.play();
|
|
677
1092
|
}, [adapter]);
|
|
678
1093
|
if (error) {
|
|
679
|
-
return /* @__PURE__ */
|
|
1094
|
+
return /* @__PURE__ */ jsxs6(
|
|
680
1095
|
"div",
|
|
681
1096
|
{
|
|
682
1097
|
style: {
|
|
@@ -689,7 +1104,7 @@ var InteractiveVideoPlayer = ({
|
|
|
689
1104
|
lineHeight: 1.5
|
|
690
1105
|
},
|
|
691
1106
|
children: [
|
|
692
|
-
/* @__PURE__ */
|
|
1107
|
+
/* @__PURE__ */ jsx6("strong", { children: "Player Error:" }),
|
|
693
1108
|
" ",
|
|
694
1109
|
error.message
|
|
695
1110
|
]
|
|
@@ -697,7 +1112,7 @@ var InteractiveVideoPlayer = ({
|
|
|
697
1112
|
);
|
|
698
1113
|
}
|
|
699
1114
|
if (!initialized || !controller) {
|
|
700
|
-
return /* @__PURE__ */
|
|
1115
|
+
return /* @__PURE__ */ jsx6(
|
|
701
1116
|
"div",
|
|
702
1117
|
{
|
|
703
1118
|
style: {
|
|
@@ -718,7 +1133,7 @@ var InteractiveVideoPlayer = ({
|
|
|
718
1133
|
(item) => item.content.getId() === overlayContentId
|
|
719
1134
|
);
|
|
720
1135
|
const activeContentType = activeItem ? registry.get(activeItem.content.getContentTypeId()) : void 0;
|
|
721
|
-
return /* @__PURE__ */
|
|
1136
|
+
return /* @__PURE__ */ jsx6(ContentErrorBoundary, { onError, children: /* @__PURE__ */ jsxs6(
|
|
722
1137
|
"div",
|
|
723
1138
|
{
|
|
724
1139
|
className: ["interlace-player", className].filter(Boolean).join(" "),
|
|
@@ -729,15 +1144,16 @@ var InteractiveVideoPlayer = ({
|
|
|
729
1144
|
height: "100%"
|
|
730
1145
|
},
|
|
731
1146
|
children: [
|
|
732
|
-
/* @__PURE__ */
|
|
1147
|
+
/* @__PURE__ */ jsx6(
|
|
733
1148
|
OverlayLayer,
|
|
734
1149
|
{
|
|
735
1150
|
renderState,
|
|
736
1151
|
items: overlayItems,
|
|
737
|
-
onAnchorClick: handleAnchorClick
|
|
1152
|
+
onAnchorClick: handleAnchorClick,
|
|
1153
|
+
children: showQualityControl && !activeItem && supportsQuality(adapter) && /* @__PURE__ */ jsx6(QualityControl, { adapter, strings })
|
|
738
1154
|
}
|
|
739
1155
|
),
|
|
740
|
-
activeItem && activeContentType && /* @__PURE__ */
|
|
1156
|
+
activeItem && activeContentType && /* @__PURE__ */ jsx6(
|
|
741
1157
|
BlockingOverlay,
|
|
742
1158
|
{
|
|
743
1159
|
content: activeItem.content,
|
|
@@ -809,9 +1225,11 @@ export {
|
|
|
809
1225
|
BlockingOverlay,
|
|
810
1226
|
CompletedTag,
|
|
811
1227
|
ContentErrorBoundary,
|
|
1228
|
+
DEFAULT_QUALITY_CONTROL_STRINGS,
|
|
812
1229
|
InteractiveVideoPlayer,
|
|
813
1230
|
OverlayLayer,
|
|
814
1231
|
PreloadScheduler,
|
|
1232
|
+
QualityControl,
|
|
815
1233
|
useInteractiveMedia
|
|
816
1234
|
};
|
|
817
1235
|
//# sourceMappingURL=index.js.map
|