@nikelroot/video-player 0.1.6 → 0.1.8

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 CHANGED
@@ -37,6 +37,8 @@ export function Example() {
37
37
  }
38
38
  ```
39
39
 
40
+ When `active` is `true`, pressing `F` toggles fullscreen.
41
+
40
42
  Build before publishing:
41
43
 
42
44
  ```bash
package/dist/index.cjs CHANGED
@@ -548,6 +548,19 @@ var VideoPlayerControls = (props) => {
548
548
  } = props;
549
549
  const [, isMobile] = useWindowWidth();
550
550
  if (variant === "none") return null;
551
+ if (variant === "tiny") {
552
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VideoPlayerControlStyles, { $tiny: true, $isMobile: isMobile, onClick: stopControlClick, $showControl: showControl, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "video-player-control-row", children: [
553
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "full" }),
554
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SeekSlider, { playAction, duration, currentTime, seekSetTime })
555
+ ] }) });
556
+ }
557
+ if (variant === "fullscreen-only") {
558
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VideoPlayerControlStyles, { $isMobile: isMobile, onClick: stopControlClick, $showControl: showControl, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "video-player-control-row", children: [
559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "full" }),
560
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlButton, { icon: muted ? "mute" : "sound", label: muted ? "Unmute" : "Mute", onClick: () => onMutedChange(!muted) }),
561
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlButton, { disabled: !fullscreenAllowed, icon: "fullscreen", label: "Fullscreen", onClick: fullScreenAction })
562
+ ] }) });
563
+ }
551
564
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VideoPlayerControlStyles, { $isMobile: isMobile, onClick: stopControlClick, $showControl: showControl, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "video-player-control-row", children: [
552
565
  playing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlButton, { icon: "pause", label: "Pause", onClick: pauseAction }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlButton, { icon: "play", label: "Play", onClick: playAction }),
553
566
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlButton, { icon: "back", label: "Back 15 seconds", onClick: () => seekPrevAction() }),
@@ -772,6 +785,10 @@ var assignRef = (ref, value) => {
772
785
  }
773
786
  ref.current = value;
774
787
  };
788
+ var isEditableKeyTarget = (target) => {
789
+ if (!(target instanceof HTMLElement)) return false;
790
+ return target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName);
791
+ };
775
792
  var VideoPlayerBase = (props, ref) => {
776
793
  const {
777
794
  controlsVariant = "none",
@@ -1382,6 +1399,21 @@ var VideoPlayerBase = (props, ref) => {
1382
1399
  if (!canAttemptPlayback(videoRef.current)) return;
1383
1400
  void playAction();
1384
1401
  }, [autoPlay, playAction]);
1402
+ (0, import_react3.useEffect)(() => {
1403
+ if (typeof document === "undefined") return;
1404
+ const handleKeyDown = (event) => {
1405
+ if (event.code !== "KeyF") return;
1406
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
1407
+ if (active !== true) return;
1408
+ if (isEditableKeyTarget(event.target)) return;
1409
+ event.preventDefault();
1410
+ fullScreenAction();
1411
+ };
1412
+ document.addEventListener("keydown", handleKeyDown);
1413
+ return () => {
1414
+ document.removeEventListener("keydown", handleKeyDown);
1415
+ };
1416
+ }, [active, fullScreenAction]);
1385
1417
  (0, import_react3.useEffect)(() => {
1386
1418
  if (typeof document === "undefined") return;
1387
1419
  const doc = document;
@@ -1411,7 +1443,7 @@ var VideoPlayerBase = (props, ref) => {
1411
1443
  {
1412
1444
  ref: containerRef,
1413
1445
  onMouseMove: mouseMoveHandler,
1414
- className: "VideoPlayer",
1446
+ className: isFullscreen ? "VideoPlayer VideoPlayer--fullscreen" : "VideoPlayer",
1415
1447
  type,
1416
1448
  $isMobile: isMobile,
1417
1449
  $mobileType: mobileType,
package/dist/index.js CHANGED
@@ -519,6 +519,19 @@ var VideoPlayerControls = (props) => {
519
519
  } = props;
520
520
  const [, isMobile] = useWindowWidth();
521
521
  if (variant === "none") return null;
522
+ if (variant === "tiny") {
523
+ return /* @__PURE__ */ jsx(VideoPlayerControlStyles, { $tiny: true, $isMobile: isMobile, onClick: stopControlClick, $showControl: showControl, children: /* @__PURE__ */ jsxs("div", { className: "video-player-control-row", children: [
524
+ /* @__PURE__ */ jsx("div", { className: "full" }),
525
+ /* @__PURE__ */ jsx(SeekSlider, { playAction, duration, currentTime, seekSetTime })
526
+ ] }) });
527
+ }
528
+ if (variant === "fullscreen-only") {
529
+ return /* @__PURE__ */ jsx(VideoPlayerControlStyles, { $isMobile: isMobile, onClick: stopControlClick, $showControl: showControl, children: /* @__PURE__ */ jsxs("div", { className: "video-player-control-row", children: [
530
+ /* @__PURE__ */ jsx("div", { className: "full" }),
531
+ /* @__PURE__ */ jsx(ControlButton, { icon: muted ? "mute" : "sound", label: muted ? "Unmute" : "Mute", onClick: () => onMutedChange(!muted) }),
532
+ /* @__PURE__ */ jsx(ControlButton, { disabled: !fullscreenAllowed, icon: "fullscreen", label: "Fullscreen", onClick: fullScreenAction })
533
+ ] }) });
534
+ }
522
535
  return /* @__PURE__ */ jsx(VideoPlayerControlStyles, { $isMobile: isMobile, onClick: stopControlClick, $showControl: showControl, children: /* @__PURE__ */ jsxs("div", { className: "video-player-control-row", children: [
523
536
  playing ? /* @__PURE__ */ jsx(ControlButton, { icon: "pause", label: "Pause", onClick: pauseAction }) : /* @__PURE__ */ jsx(ControlButton, { icon: "play", label: "Play", onClick: playAction }),
524
537
  /* @__PURE__ */ jsx(ControlButton, { icon: "back", label: "Back 15 seconds", onClick: () => seekPrevAction() }),
@@ -743,6 +756,10 @@ var assignRef = (ref, value) => {
743
756
  }
744
757
  ref.current = value;
745
758
  };
759
+ var isEditableKeyTarget = (target) => {
760
+ if (!(target instanceof HTMLElement)) return false;
761
+ return target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName);
762
+ };
746
763
  var VideoPlayerBase = (props, ref) => {
747
764
  const {
748
765
  controlsVariant = "none",
@@ -1353,6 +1370,21 @@ var VideoPlayerBase = (props, ref) => {
1353
1370
  if (!canAttemptPlayback(videoRef.current)) return;
1354
1371
  void playAction();
1355
1372
  }, [autoPlay, playAction]);
1373
+ useEffect(() => {
1374
+ if (typeof document === "undefined") return;
1375
+ const handleKeyDown = (event) => {
1376
+ if (event.code !== "KeyF") return;
1377
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
1378
+ if (active !== true) return;
1379
+ if (isEditableKeyTarget(event.target)) return;
1380
+ event.preventDefault();
1381
+ fullScreenAction();
1382
+ };
1383
+ document.addEventListener("keydown", handleKeyDown);
1384
+ return () => {
1385
+ document.removeEventListener("keydown", handleKeyDown);
1386
+ };
1387
+ }, [active, fullScreenAction]);
1356
1388
  useEffect(() => {
1357
1389
  if (typeof document === "undefined") return;
1358
1390
  const doc = document;
@@ -1382,7 +1414,7 @@ var VideoPlayerBase = (props, ref) => {
1382
1414
  {
1383
1415
  ref: containerRef,
1384
1416
  onMouseMove: mouseMoveHandler,
1385
- className: "VideoPlayer",
1417
+ className: isFullscreen ? "VideoPlayer VideoPlayer--fullscreen" : "VideoPlayer",
1386
1418
  type,
1387
1419
  $isMobile: isMobile,
1388
1420
  $mobileType: mobileType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nikelroot/video-player",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Standalone React video player with HLS support.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",