@interlacejs/player 0.2.1 → 0.3.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/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/README.md
CHANGED
|
@@ -39,6 +39,30 @@ Behavior notes:
|
|
|
39
39
|
- Blocking hooks pause the video and open content; only completion lets playback continue (the completion surface needs **Continue** click). Blocking content cannot be dismissed.
|
|
40
40
|
- Non-blocking hooks stay anchored inside their time window, can be opened or **skipped** (skip hides it for that window visit; re-approaching the window re-arms it), and completion swaps the anchor for a tag that cannot be re-taken.
|
|
41
41
|
|
|
42
|
+
## Quality menu
|
|
43
|
+
|
|
44
|
+
When the adapter implements the optional quality capability (`supportsQuality(adapter)` from `@interlacejs/core`, e.g. [`@interlacejs/hls-adapter`](https://github.com/farayolaj/interlace/tree/main/packages/hls-adapter)) and reports at least two levels, the player draws a quality button in the top-right corner of the video frame. It opens a menu with **Auto** (showing the level playing, e.g. "Auto · 480p"), each level from high to low, and "Data saver" on the lowest one.
|
|
45
|
+
|
|
46
|
+
- It stays visible while the video is paused, the menu is open, or the button has focus. While playing, it fades out after 2.5 s without pointer movement over the video and comes back on movement, touch or keyboard focus.
|
|
47
|
+
- It is hidden while content (such as a blocking quiz) is open, and only the button and menu take pointer events.
|
|
48
|
+
- It follows the menu-button pattern: arrow keys, Home/End, Enter/Space to select, Escape or an outside click to close.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
<InteractiveVideoPlayer
|
|
52
|
+
adapter={hlsAdapter}
|
|
53
|
+
document={doc}
|
|
54
|
+
registry={registry}
|
|
55
|
+
showQualityControl // default true; pass false to hide it
|
|
56
|
+
strings={{
|
|
57
|
+
qualityLabel: "Qualité",
|
|
58
|
+
qualityAutoLabel: "Auto",
|
|
59
|
+
qualityDataSaverLabel: "Économie de données",
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`QualityControl` is also exported if you want to place it yourself.
|
|
65
|
+
|
|
42
66
|
## Types and authoring
|
|
43
67
|
|
|
44
68
|
Documents are produced by [`@interlacejs/editor`](https://github.com/farayolaj/interlace) but they are plain JSON — see the [root README](https://github.com/farayolaj/interlace) for the full document shape and the `apps/demo` source for a working wiring.
|
package/dist/index.cjs
CHANGED
|
@@ -34,9 +34,11 @@ __export(index_exports, {
|
|
|
34
34
|
BlockingOverlay: () => BlockingOverlay,
|
|
35
35
|
CompletedTag: () => CompletedTag,
|
|
36
36
|
ContentErrorBoundary: () => ContentErrorBoundary,
|
|
37
|
+
DEFAULT_QUALITY_CONTROL_STRINGS: () => DEFAULT_QUALITY_CONTROL_STRINGS,
|
|
37
38
|
InteractiveVideoPlayer: () => InteractiveVideoPlayer,
|
|
38
39
|
OverlayLayer: () => OverlayLayer,
|
|
39
40
|
PreloadScheduler: () => PreloadScheduler,
|
|
41
|
+
QualityControl: () => QualityControl,
|
|
40
42
|
useInteractiveMedia: () => useInteractiveMedia
|
|
41
43
|
});
|
|
42
44
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -441,7 +443,7 @@ var ContentErrorBoundary = class extends import_react3.default.Component {
|
|
|
441
443
|
|
|
442
444
|
// src/components/interactive-video-player.tsx
|
|
443
445
|
var import_core3 = require("@interlacejs/core");
|
|
444
|
-
var
|
|
446
|
+
var import_react7 = require("react");
|
|
445
447
|
|
|
446
448
|
// src/hooks/use-interactive-media.ts
|
|
447
449
|
var import_core2 = require("@interlacejs/core");
|
|
@@ -544,7 +546,8 @@ var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
|
544
546
|
var OverlayLayer = ({
|
|
545
547
|
renderState,
|
|
546
548
|
items,
|
|
547
|
-
onAnchorClick
|
|
549
|
+
onAnchorClick,
|
|
550
|
+
children
|
|
548
551
|
}) => {
|
|
549
552
|
const itemMap = (0, import_react5.useMemo)(() => {
|
|
550
553
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -625,34 +628,447 @@ var OverlayLayer = ({
|
|
|
625
628
|
);
|
|
626
629
|
})
|
|
627
630
|
}
|
|
631
|
+
),
|
|
632
|
+
children
|
|
633
|
+
]
|
|
634
|
+
}
|
|
635
|
+
);
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// src/components/quality-control.tsx
|
|
639
|
+
var import_react6 = require("react");
|
|
640
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
641
|
+
var DEFAULT_QUALITY_CONTROL_STRINGS = {
|
|
642
|
+
qualityLabel: "Quality",
|
|
643
|
+
qualityAutoLabel: "Auto",
|
|
644
|
+
qualityDataSaverLabel: "Data saver"
|
|
645
|
+
};
|
|
646
|
+
var PLAYBACK_POLL_MS = 500;
|
|
647
|
+
var QUALITY_CONTROL_HIDE_DELAY_MS = 2500;
|
|
648
|
+
var AUTO = -1;
|
|
649
|
+
var INSET = import_core.SPACE[2];
|
|
650
|
+
var BUTTON_SIZE = 36;
|
|
651
|
+
function readSnapshot(adapter) {
|
|
652
|
+
return {
|
|
653
|
+
levels: [...adapter.getQualityLevels()].sort((a, b) => b.height - a.height),
|
|
654
|
+
selected: adapter.getQualityLevel(),
|
|
655
|
+
active: adapter.getActiveQualityLevel()
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function prefersReducedMotion() {
|
|
659
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
660
|
+
}
|
|
661
|
+
function pointOf(event) {
|
|
662
|
+
if ("touches" in event) {
|
|
663
|
+
const touch = event.touches[0];
|
|
664
|
+
return touch ? { x: touch.clientX, y: touch.clientY } : null;
|
|
665
|
+
}
|
|
666
|
+
const mouse = event;
|
|
667
|
+
return { x: mouse.clientX, y: mouse.clientY };
|
|
668
|
+
}
|
|
669
|
+
var QualityControl = ({
|
|
670
|
+
adapter,
|
|
671
|
+
strings: stringsOverride
|
|
672
|
+
}) => {
|
|
673
|
+
const strings = { ...DEFAULT_QUALITY_CONTROL_STRINGS, ...stringsOverride };
|
|
674
|
+
const [snapshot, setSnapshot] = (0, import_react6.useState)(() => readSnapshot(adapter));
|
|
675
|
+
const [playing, setPlaying] = (0, import_react6.useState)(false);
|
|
676
|
+
const [recentActivity, setRecentActivity] = (0, import_react6.useState)(false);
|
|
677
|
+
const [focusWithin, setFocusWithin] = (0, import_react6.useState)(false);
|
|
678
|
+
const [open, setOpen] = (0, import_react6.useState)(false);
|
|
679
|
+
const [focusIndex, setFocusIndex] = (0, import_react6.useState)(0);
|
|
680
|
+
const frameRef = (0, import_react6.useRef)(null);
|
|
681
|
+
const buttonRef = (0, import_react6.useRef)(null);
|
|
682
|
+
const menuRef = (0, import_react6.useRef)(null);
|
|
683
|
+
const itemRefs = (0, import_react6.useRef)([]);
|
|
684
|
+
const hideTimerRef = (0, import_react6.useRef)(null);
|
|
685
|
+
const [reducedMotion] = (0, import_react6.useState)(prefersReducedMotion);
|
|
686
|
+
(0, import_react6.useEffect)(() => {
|
|
687
|
+
setSnapshot(readSnapshot(adapter));
|
|
688
|
+
return adapter.on(
|
|
689
|
+
"qualitychange",
|
|
690
|
+
() => setSnapshot(readSnapshot(adapter))
|
|
691
|
+
);
|
|
692
|
+
}, [adapter]);
|
|
693
|
+
const reveal = (0, import_react6.useCallback)(() => {
|
|
694
|
+
setRecentActivity(true);
|
|
695
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
696
|
+
hideTimerRef.current = setTimeout(
|
|
697
|
+
() => setRecentActivity(false),
|
|
698
|
+
QUALITY_CONTROL_HIDE_DELAY_MS
|
|
699
|
+
);
|
|
700
|
+
}, []);
|
|
701
|
+
(0, import_react6.useEffect)(
|
|
702
|
+
() => () => {
|
|
703
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
704
|
+
},
|
|
705
|
+
[]
|
|
706
|
+
);
|
|
707
|
+
(0, import_react6.useEffect)(() => {
|
|
708
|
+
const offPlay = adapter.on("play", () => {
|
|
709
|
+
setPlaying(true);
|
|
710
|
+
reveal();
|
|
711
|
+
});
|
|
712
|
+
const offPause = adapter.on("pause", () => setPlaying(false));
|
|
713
|
+
let lastTime = adapter.getCurrentTime();
|
|
714
|
+
const poll = setInterval(() => {
|
|
715
|
+
const time = adapter.getCurrentTime();
|
|
716
|
+
setPlaying(time !== lastTime);
|
|
717
|
+
lastTime = time;
|
|
718
|
+
}, PLAYBACK_POLL_MS);
|
|
719
|
+
return () => {
|
|
720
|
+
offPlay();
|
|
721
|
+
offPause();
|
|
722
|
+
clearInterval(poll);
|
|
723
|
+
};
|
|
724
|
+
}, [adapter, reveal]);
|
|
725
|
+
(0, import_react6.useEffect)(() => {
|
|
726
|
+
const onActivity = (event) => {
|
|
727
|
+
const frame = frameRef.current;
|
|
728
|
+
const point = pointOf(event);
|
|
729
|
+
if (!frame || !point) return;
|
|
730
|
+
const rect = frame.getBoundingClientRect();
|
|
731
|
+
if (point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom && rect.width > 0 && rect.height > 0) {
|
|
732
|
+
reveal();
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
const events = ["mousemove", "mousedown", "touchstart"];
|
|
736
|
+
events.forEach(
|
|
737
|
+
(type) => document.addEventListener(type, onActivity, { passive: true })
|
|
738
|
+
);
|
|
739
|
+
return () => events.forEach((type) => document.removeEventListener(type, onActivity));
|
|
740
|
+
}, [reveal]);
|
|
741
|
+
(0, import_react6.useEffect)(() => {
|
|
742
|
+
if (!open) return;
|
|
743
|
+
const onPointerDown = (event) => {
|
|
744
|
+
const target = event.target;
|
|
745
|
+
if (buttonRef.current?.contains(target) || menuRef.current?.contains(target)) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
setOpen(false);
|
|
749
|
+
};
|
|
750
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
751
|
+
document.addEventListener("touchstart", onPointerDown);
|
|
752
|
+
return () => {
|
|
753
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
754
|
+
document.removeEventListener("touchstart", onPointerDown);
|
|
755
|
+
};
|
|
756
|
+
}, [open]);
|
|
757
|
+
(0, import_react6.useEffect)(() => {
|
|
758
|
+
if (open) itemRefs.current[focusIndex]?.focus();
|
|
759
|
+
}, [open, focusIndex]);
|
|
760
|
+
const { levels, selected, active } = snapshot;
|
|
761
|
+
if (levels.length < 2) return null;
|
|
762
|
+
const options = [AUTO, ...levels.map((level) => level.id)];
|
|
763
|
+
const activeLevel = levels.find((level) => level.id === active);
|
|
764
|
+
const selectedLevel = levels.find((level) => level.id === selected);
|
|
765
|
+
const lowestId = levels[levels.length - 1].id;
|
|
766
|
+
const optionLabel = (id) => {
|
|
767
|
+
if (id === AUTO) {
|
|
768
|
+
return activeLevel ? `${strings.qualityAutoLabel} \xB7 ${activeLevel.label}` : strings.qualityAutoLabel;
|
|
769
|
+
}
|
|
770
|
+
const level = levels.find((l) => l.id === id);
|
|
771
|
+
return id === lowestId ? `${strings.qualityDataSaverLabel} \xB7 ${level.label}` : level.label;
|
|
772
|
+
};
|
|
773
|
+
const currentLabel = selectedLevel ? selectedLevel.label : activeLevel ? `${strings.qualityAutoLabel} (${activeLevel.label})` : strings.qualityAutoLabel;
|
|
774
|
+
const effectiveHeight = (selectedLevel ?? activeLevel)?.height ?? 0;
|
|
775
|
+
const selectedIndex = Math.max(
|
|
776
|
+
0,
|
|
777
|
+
options.indexOf(selectedLevel ? selected : AUTO)
|
|
778
|
+
);
|
|
779
|
+
const openMenu = (index) => {
|
|
780
|
+
setFocusIndex(index);
|
|
781
|
+
setOpen(true);
|
|
782
|
+
};
|
|
783
|
+
const closeMenu = (returnFocus) => {
|
|
784
|
+
setOpen(false);
|
|
785
|
+
if (returnFocus) buttonRef.current?.focus();
|
|
786
|
+
};
|
|
787
|
+
const select = (id) => {
|
|
788
|
+
adapter.setQualityLevel(id);
|
|
789
|
+
closeMenu(true);
|
|
790
|
+
};
|
|
791
|
+
const onButtonKeyDown = (event) => {
|
|
792
|
+
if (event.key === "ArrowDown") {
|
|
793
|
+
event.preventDefault();
|
|
794
|
+
openMenu(selectedIndex);
|
|
795
|
+
} else if (event.key === "ArrowUp") {
|
|
796
|
+
event.preventDefault();
|
|
797
|
+
openMenu(options.length - 1);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
const onMenuKeyDown = (event) => {
|
|
801
|
+
const last = options.length - 1;
|
|
802
|
+
switch (event.key) {
|
|
803
|
+
case "ArrowDown":
|
|
804
|
+
event.preventDefault();
|
|
805
|
+
setFocusIndex((i) => i >= last ? 0 : i + 1);
|
|
806
|
+
break;
|
|
807
|
+
case "ArrowUp":
|
|
808
|
+
event.preventDefault();
|
|
809
|
+
setFocusIndex((i) => i <= 0 ? last : i - 1);
|
|
810
|
+
break;
|
|
811
|
+
case "Home":
|
|
812
|
+
event.preventDefault();
|
|
813
|
+
setFocusIndex(0);
|
|
814
|
+
break;
|
|
815
|
+
case "End":
|
|
816
|
+
event.preventDefault();
|
|
817
|
+
setFocusIndex(last);
|
|
818
|
+
break;
|
|
819
|
+
case "Enter":
|
|
820
|
+
case " ":
|
|
821
|
+
event.preventDefault();
|
|
822
|
+
select(options[focusIndex]);
|
|
823
|
+
break;
|
|
824
|
+
case "Escape":
|
|
825
|
+
event.preventDefault();
|
|
826
|
+
closeMenu(true);
|
|
827
|
+
break;
|
|
828
|
+
case "Tab":
|
|
829
|
+
setOpen(false);
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
const visible = !playing || open || focusWithin || recentActivity;
|
|
834
|
+
const interactive = visible ? "auto" : "none";
|
|
835
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
836
|
+
"div",
|
|
837
|
+
{
|
|
838
|
+
ref: frameRef,
|
|
839
|
+
"data-testid": "interlace-quality-control",
|
|
840
|
+
"data-visible": visible,
|
|
841
|
+
onFocus: (event) => setFocusWithin(isKeyboardFocus(event.target)),
|
|
842
|
+
onBlur: (event) => {
|
|
843
|
+
if (!frameRef.current?.contains(event.relatedTarget)) {
|
|
844
|
+
setFocusWithin(false);
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
style: {
|
|
848
|
+
position: "absolute",
|
|
849
|
+
inset: 0,
|
|
850
|
+
pointerEvents: "none",
|
|
851
|
+
opacity: visible ? 1 : 0,
|
|
852
|
+
transition: reducedMotion ? "none" : "opacity 200ms ease",
|
|
853
|
+
fontFamily: import_core.FONTS.body,
|
|
854
|
+
zIndex: 20
|
|
855
|
+
},
|
|
856
|
+
children: [
|
|
857
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
858
|
+
"button",
|
|
859
|
+
{
|
|
860
|
+
ref: buttonRef,
|
|
861
|
+
type: "button",
|
|
862
|
+
className: "interlace-focusable",
|
|
863
|
+
"aria-label": `${strings.qualityLabel}: ${currentLabel}`,
|
|
864
|
+
"aria-haspopup": "menu",
|
|
865
|
+
"aria-expanded": open,
|
|
866
|
+
title: strings.qualityLabel,
|
|
867
|
+
onClick: () => open ? closeMenu(false) : openMenu(selectedIndex),
|
|
868
|
+
onKeyDown: onButtonKeyDown,
|
|
869
|
+
style: {
|
|
870
|
+
position: "absolute",
|
|
871
|
+
top: INSET,
|
|
872
|
+
right: INSET,
|
|
873
|
+
width: BUTTON_SIZE,
|
|
874
|
+
height: BUTTON_SIZE,
|
|
875
|
+
padding: 0,
|
|
876
|
+
display: "inline-flex",
|
|
877
|
+
alignItems: "center",
|
|
878
|
+
justifyContent: "center",
|
|
879
|
+
border: "none",
|
|
880
|
+
borderRadius: import_core.RADIUS.md,
|
|
881
|
+
background: "rgba(0, 0, 0, 0.6)",
|
|
882
|
+
color: import_core.COLORS.white,
|
|
883
|
+
cursor: "pointer",
|
|
884
|
+
pointerEvents: interactive
|
|
885
|
+
},
|
|
886
|
+
children: [
|
|
887
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(GearIcon, {}),
|
|
888
|
+
effectiveHeight >= 720 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
889
|
+
"span",
|
|
890
|
+
{
|
|
891
|
+
"aria-hidden": "true",
|
|
892
|
+
style: {
|
|
893
|
+
position: "absolute",
|
|
894
|
+
top: 3,
|
|
895
|
+
right: 2,
|
|
896
|
+
padding: "0 2px",
|
|
897
|
+
borderRadius: 3,
|
|
898
|
+
background: import_core.COLORS.accent,
|
|
899
|
+
color: import_core.COLORS.accentContrast,
|
|
900
|
+
fontSize: 8,
|
|
901
|
+
fontWeight: 700,
|
|
902
|
+
lineHeight: "11px"
|
|
903
|
+
},
|
|
904
|
+
children: "HD"
|
|
905
|
+
}
|
|
906
|
+
)
|
|
907
|
+
]
|
|
908
|
+
}
|
|
909
|
+
),
|
|
910
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
911
|
+
"div",
|
|
912
|
+
{
|
|
913
|
+
ref: menuRef,
|
|
914
|
+
role: "menu",
|
|
915
|
+
"aria-label": strings.qualityLabel,
|
|
916
|
+
onKeyDown: onMenuKeyDown,
|
|
917
|
+
style: {
|
|
918
|
+
position: "absolute",
|
|
919
|
+
top: INSET + BUTTON_SIZE + import_core.SPACE[1],
|
|
920
|
+
right: INSET,
|
|
921
|
+
minWidth: 168,
|
|
922
|
+
maxHeight: `calc(100% - ${INSET * 2 + BUTTON_SIZE + import_core.SPACE[1]}px)`,
|
|
923
|
+
overflowY: "auto",
|
|
924
|
+
boxSizing: "border-box",
|
|
925
|
+
padding: import_core.SPACE[1],
|
|
926
|
+
borderRadius: import_core.RADIUS.md,
|
|
927
|
+
background: "rgba(0, 0, 0, 0.8)",
|
|
928
|
+
color: import_core.COLORS.white,
|
|
929
|
+
fontSize: import_core.TYPE.sm,
|
|
930
|
+
boxShadow: "0 4px 16px rgba(0, 0, 0, 0.35)",
|
|
931
|
+
pointerEvents: "auto"
|
|
932
|
+
},
|
|
933
|
+
children: [
|
|
934
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
935
|
+
"div",
|
|
936
|
+
{
|
|
937
|
+
"aria-hidden": "true",
|
|
938
|
+
style: {
|
|
939
|
+
padding: `${import_core.SPACE[1]}px ${import_core.SPACE[2]}px`,
|
|
940
|
+
fontSize: import_core.TYPE.xs,
|
|
941
|
+
fontWeight: 600,
|
|
942
|
+
opacity: 0.7
|
|
943
|
+
},
|
|
944
|
+
children: strings.qualityLabel
|
|
945
|
+
}
|
|
946
|
+
),
|
|
947
|
+
options.map((id, index) => {
|
|
948
|
+
const checked = selectedLevel ? id === selected : id === AUTO;
|
|
949
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
950
|
+
"button",
|
|
951
|
+
{
|
|
952
|
+
ref: (node) => {
|
|
953
|
+
itemRefs.current[index] = node;
|
|
954
|
+
},
|
|
955
|
+
type: "button",
|
|
956
|
+
role: "menuitemradio",
|
|
957
|
+
"aria-checked": checked,
|
|
958
|
+
tabIndex: -1,
|
|
959
|
+
className: "interlace-focusable",
|
|
960
|
+
onClick: () => select(id),
|
|
961
|
+
onMouseEnter: () => setFocusIndex(index),
|
|
962
|
+
style: {
|
|
963
|
+
display: "flex",
|
|
964
|
+
alignItems: "center",
|
|
965
|
+
gap: import_core.SPACE[2],
|
|
966
|
+
width: "100%",
|
|
967
|
+
minHeight: 36,
|
|
968
|
+
padding: `0 ${import_core.SPACE[3]}px 0 ${import_core.SPACE[2]}px`,
|
|
969
|
+
border: "none",
|
|
970
|
+
borderRadius: import_core.RADIUS.sm,
|
|
971
|
+
background: index === focusIndex ? "rgba(255, 255, 255, 0.16)" : "transparent",
|
|
972
|
+
color: "inherit",
|
|
973
|
+
font: "inherit",
|
|
974
|
+
fontWeight: checked ? 600 : 400,
|
|
975
|
+
textAlign: "left",
|
|
976
|
+
whiteSpace: "nowrap",
|
|
977
|
+
cursor: "pointer"
|
|
978
|
+
},
|
|
979
|
+
children: [
|
|
980
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
981
|
+
"span",
|
|
982
|
+
{
|
|
983
|
+
"aria-hidden": "true",
|
|
984
|
+
style: {
|
|
985
|
+
display: "inline-flex",
|
|
986
|
+
width: 16,
|
|
987
|
+
color: import_core.COLORS.accent
|
|
988
|
+
},
|
|
989
|
+
children: checked && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, {})
|
|
990
|
+
}
|
|
991
|
+
),
|
|
992
|
+
optionLabel(id)
|
|
993
|
+
]
|
|
994
|
+
},
|
|
995
|
+
id
|
|
996
|
+
);
|
|
997
|
+
})
|
|
998
|
+
]
|
|
999
|
+
}
|
|
628
1000
|
)
|
|
629
1001
|
]
|
|
630
1002
|
}
|
|
631
1003
|
);
|
|
632
1004
|
};
|
|
1005
|
+
var GearIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1006
|
+
"svg",
|
|
1007
|
+
{
|
|
1008
|
+
width: "20",
|
|
1009
|
+
height: "20",
|
|
1010
|
+
viewBox: "0 0 24 24",
|
|
1011
|
+
fill: "none",
|
|
1012
|
+
stroke: "currentColor",
|
|
1013
|
+
strokeWidth: "2",
|
|
1014
|
+
strokeLinecap: "round",
|
|
1015
|
+
strokeLinejoin: "round",
|
|
1016
|
+
"aria-hidden": "true",
|
|
1017
|
+
focusable: "false",
|
|
1018
|
+
children: [
|
|
1019
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("circle", { cx: "12", cy: "12", r: "3" }),
|
|
1020
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("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" })
|
|
1021
|
+
]
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1024
|
+
var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1025
|
+
"svg",
|
|
1026
|
+
{
|
|
1027
|
+
width: "16",
|
|
1028
|
+
height: "16",
|
|
1029
|
+
viewBox: "0 0 24 24",
|
|
1030
|
+
fill: "none",
|
|
1031
|
+
stroke: "currentColor",
|
|
1032
|
+
strokeWidth: "3",
|
|
1033
|
+
strokeLinecap: "round",
|
|
1034
|
+
strokeLinejoin: "round",
|
|
1035
|
+
"aria-hidden": "true",
|
|
1036
|
+
focusable: "false",
|
|
1037
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("polyline", { points: "20 6 9 17 4 12" })
|
|
1038
|
+
}
|
|
1039
|
+
);
|
|
1040
|
+
function isKeyboardFocus(element) {
|
|
1041
|
+
try {
|
|
1042
|
+
return element.matches(":focus-visible");
|
|
1043
|
+
} catch {
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
633
1047
|
|
|
634
1048
|
// src/components/interactive-video-player.tsx
|
|
635
|
-
var
|
|
1049
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
636
1050
|
var InteractiveVideoPlayer = ({
|
|
637
1051
|
adapter,
|
|
638
1052
|
document: doc,
|
|
639
1053
|
registry,
|
|
640
1054
|
onError,
|
|
641
1055
|
theme,
|
|
642
|
-
className
|
|
1056
|
+
className,
|
|
1057
|
+
showQualityControl = true,
|
|
1058
|
+
strings
|
|
643
1059
|
}) => {
|
|
644
|
-
const [renderState, setRenderState] = (0,
|
|
1060
|
+
const [renderState, setRenderState] = (0, import_react7.useState)({
|
|
645
1061
|
visibleAnchorIds: [],
|
|
646
1062
|
completedTagIds: [],
|
|
647
1063
|
openedContentIds: []
|
|
648
1064
|
});
|
|
649
|
-
const [activeContentId, setActiveContentId] = (0,
|
|
650
|
-
const [completingId, setCompletingId] = (0,
|
|
651
|
-
const [completingScore, setCompletingScore] = (0,
|
|
1065
|
+
const [activeContentId, setActiveContentId] = (0, import_react7.useState)(null);
|
|
1066
|
+
const [completingId, setCompletingId] = (0, import_react7.useState)(null);
|
|
1067
|
+
const [completingScore, setCompletingScore] = (0, import_react7.useState)(
|
|
652
1068
|
void 0
|
|
653
1069
|
);
|
|
654
|
-
const lastAutoOpenedBlockingIdRef = (0,
|
|
655
|
-
(0,
|
|
1070
|
+
const lastAutoOpenedBlockingIdRef = (0, import_react7.useRef)(null);
|
|
1071
|
+
(0, import_react7.useEffect)(() => {
|
|
656
1072
|
(0, import_core3.ensureInterlaceStyles)();
|
|
657
1073
|
}, []);
|
|
658
1074
|
const { controller, items, initialized, error } = useInteractiveMedia({
|
|
@@ -662,14 +1078,14 @@ var InteractiveVideoPlayer = ({
|
|
|
662
1078
|
onRenderStateChange: setRenderState,
|
|
663
1079
|
onError
|
|
664
1080
|
});
|
|
665
|
-
const handleAnchorClick = (0,
|
|
1081
|
+
const handleAnchorClick = (0, import_react7.useCallback)(
|
|
666
1082
|
(contentId) => {
|
|
667
1083
|
adapter.pause();
|
|
668
1084
|
setActiveContentId(contentId);
|
|
669
1085
|
},
|
|
670
1086
|
[adapter]
|
|
671
1087
|
);
|
|
672
|
-
(0,
|
|
1088
|
+
(0, import_react7.useEffect)(() => {
|
|
673
1089
|
const blockingId = renderState.activeBlockingContentId;
|
|
674
1090
|
if (blockingId && blockingId !== lastAutoOpenedBlockingIdRef.current) {
|
|
675
1091
|
lastAutoOpenedBlockingIdRef.current = blockingId;
|
|
@@ -678,15 +1094,15 @@ var InteractiveVideoPlayer = ({
|
|
|
678
1094
|
lastAutoOpenedBlockingIdRef.current = null;
|
|
679
1095
|
}
|
|
680
1096
|
}, [renderState.activeBlockingContentId]);
|
|
681
|
-
const overlayShowingRef = (0,
|
|
1097
|
+
const overlayShowingRef = (0, import_react7.useRef)(false);
|
|
682
1098
|
overlayShowingRef.current = (activeContentId ?? completingId) !== null;
|
|
683
|
-
(0,
|
|
1099
|
+
(0, import_react7.useEffect)(
|
|
684
1100
|
() => adapter.on("play", () => {
|
|
685
1101
|
if (overlayShowingRef.current) adapter.pause();
|
|
686
1102
|
}),
|
|
687
1103
|
[adapter]
|
|
688
1104
|
);
|
|
689
|
-
const handleContentComplete = (0,
|
|
1105
|
+
const handleContentComplete = (0, import_react7.useCallback)(
|
|
690
1106
|
(score) => {
|
|
691
1107
|
if (!controller || !activeContentId) return;
|
|
692
1108
|
const item = (items ?? []).find((it) => it.getId() === activeContentId);
|
|
@@ -697,14 +1113,14 @@ var InteractiveVideoPlayer = ({
|
|
|
697
1113
|
},
|
|
698
1114
|
[controller, items, activeContentId]
|
|
699
1115
|
);
|
|
700
|
-
const handleContinueAfterCompletion = (0,
|
|
1116
|
+
const handleContinueAfterCompletion = (0, import_react7.useCallback)(() => {
|
|
701
1117
|
setCompletingId(null);
|
|
702
1118
|
setCompletingScore(void 0);
|
|
703
1119
|
overlayShowingRef.current = false;
|
|
704
1120
|
void adapter.play();
|
|
705
1121
|
}, [adapter]);
|
|
706
1122
|
if (error) {
|
|
707
|
-
return /* @__PURE__ */ (0,
|
|
1123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
708
1124
|
"div",
|
|
709
1125
|
{
|
|
710
1126
|
style: {
|
|
@@ -717,7 +1133,7 @@ var InteractiveVideoPlayer = ({
|
|
|
717
1133
|
lineHeight: 1.5
|
|
718
1134
|
},
|
|
719
1135
|
children: [
|
|
720
|
-
/* @__PURE__ */ (0,
|
|
1136
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("strong", { children: "Player Error:" }),
|
|
721
1137
|
" ",
|
|
722
1138
|
error.message
|
|
723
1139
|
]
|
|
@@ -725,7 +1141,7 @@ var InteractiveVideoPlayer = ({
|
|
|
725
1141
|
);
|
|
726
1142
|
}
|
|
727
1143
|
if (!initialized || !controller) {
|
|
728
|
-
return /* @__PURE__ */ (0,
|
|
1144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
729
1145
|
"div",
|
|
730
1146
|
{
|
|
731
1147
|
style: {
|
|
@@ -746,7 +1162,7 @@ var InteractiveVideoPlayer = ({
|
|
|
746
1162
|
(item) => item.content.getId() === overlayContentId
|
|
747
1163
|
);
|
|
748
1164
|
const activeContentType = activeItem ? registry.get(activeItem.content.getContentTypeId()) : void 0;
|
|
749
|
-
return /* @__PURE__ */ (0,
|
|
1165
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ContentErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
750
1166
|
"div",
|
|
751
1167
|
{
|
|
752
1168
|
className: ["interlace-player", className].filter(Boolean).join(" "),
|
|
@@ -757,15 +1173,16 @@ var InteractiveVideoPlayer = ({
|
|
|
757
1173
|
height: "100%"
|
|
758
1174
|
},
|
|
759
1175
|
children: [
|
|
760
|
-
/* @__PURE__ */ (0,
|
|
1176
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
761
1177
|
OverlayLayer,
|
|
762
1178
|
{
|
|
763
1179
|
renderState,
|
|
764
1180
|
items: overlayItems,
|
|
765
|
-
onAnchorClick: handleAnchorClick
|
|
1181
|
+
onAnchorClick: handleAnchorClick,
|
|
1182
|
+
children: showQualityControl && !activeItem && (0, import_core3.supportsQuality)(adapter) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(QualityControl, { adapter, strings })
|
|
766
1183
|
}
|
|
767
1184
|
),
|
|
768
|
-
activeItem && activeContentType && /* @__PURE__ */ (0,
|
|
1185
|
+
activeItem && activeContentType && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
769
1186
|
BlockingOverlay,
|
|
770
1187
|
{
|
|
771
1188
|
content: activeItem.content,
|
|
@@ -838,9 +1255,11 @@ var PreloadScheduler = class {
|
|
|
838
1255
|
BlockingOverlay,
|
|
839
1256
|
CompletedTag,
|
|
840
1257
|
ContentErrorBoundary,
|
|
1258
|
+
DEFAULT_QUALITY_CONTROL_STRINGS,
|
|
841
1259
|
InteractiveVideoPlayer,
|
|
842
1260
|
OverlayLayer,
|
|
843
1261
|
PreloadScheduler,
|
|
1262
|
+
QualityControl,
|
|
844
1263
|
useInteractiveMedia
|
|
845
1264
|
});
|
|
846
1265
|
//# sourceMappingURL=index.cjs.map
|