analytica-frontend-lib 1.1.11 → 1.1.13

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.mjs CHANGED
@@ -6789,6 +6789,9 @@ import {
6789
6789
  DotsThreeVertical as DotsThreeVertical2
6790
6790
  } from "phosphor-react";
6791
6791
  import { jsx as jsx36, jsxs as jsxs30 } from "react/jsx-runtime";
6792
+ var CONTROLS_HIDE_TIMEOUT = 3e3;
6793
+ var LEAVE_HIDE_TIMEOUT = 1e3;
6794
+ var INIT_DELAY = 100;
6792
6795
  var formatTime = (seconds) => {
6793
6796
  if (!seconds || isNaN(seconds)) return "0:00";
6794
6797
  const mins = Math.floor(seconds / 60);
@@ -6907,29 +6910,44 @@ var VideoPlayer = ({
6907
6910
  const trackRef = useRef9(null);
6908
6911
  const controlsTimeoutRef = useRef9(null);
6909
6912
  const lastMousePositionRef = useRef9({ x: 0, y: 0 });
6910
- const mouseMoveTimeoutRef = useRef9(null);
6913
+ const isUserInteracting = useCallback(() => {
6914
+ if (showSpeedMenu) {
6915
+ return true;
6916
+ }
6917
+ const activeElement = document.activeElement;
6918
+ const videoContainer = videoRef.current?.parentElement;
6919
+ if (activeElement && videoContainer?.contains(activeElement)) {
6920
+ if (activeElement === videoRef.current) {
6921
+ return false;
6922
+ }
6923
+ const isControl = activeElement.matches("button, input, [tabindex]");
6924
+ if (isControl) {
6925
+ return true;
6926
+ }
6927
+ }
6928
+ return false;
6929
+ }, [showSpeedMenu]);
6911
6930
  const clearControlsTimeout = useCallback(() => {
6912
6931
  if (controlsTimeoutRef.current) {
6913
6932
  clearTimeout(controlsTimeoutRef.current);
6914
6933
  controlsTimeoutRef.current = null;
6915
6934
  }
6916
6935
  }, []);
6917
- const clearMouseMoveTimeout = useCallback(() => {
6918
- if (mouseMoveTimeoutRef.current) {
6919
- clearTimeout(mouseMoveTimeoutRef.current);
6920
- mouseMoveTimeoutRef.current = null;
6921
- }
6922
- }, []);
6923
6936
  const showControlsWithTimer = useCallback(() => {
6924
6937
  setShowControls(true);
6925
6938
  clearControlsTimeout();
6926
- if (isPlaying) {
6927
- const timeout = isFullscreen ? 2e3 : 3e3;
6939
+ if (isFullscreen) {
6940
+ if (isPlaying) {
6941
+ controlsTimeoutRef.current = window.setTimeout(() => {
6942
+ setShowControls(false);
6943
+ }, CONTROLS_HIDE_TIMEOUT);
6944
+ }
6945
+ } else {
6928
6946
  controlsTimeoutRef.current = window.setTimeout(() => {
6929
6947
  setShowControls(false);
6930
- }, timeout);
6948
+ }, CONTROLS_HIDE_TIMEOUT);
6931
6949
  }
6932
- }, [isPlaying, isFullscreen, clearControlsTimeout]);
6950
+ }, [isFullscreen, isPlaying, clearControlsTimeout]);
6933
6951
  const handleMouseMove = useCallback(
6934
6952
  (event) => {
6935
6953
  const currentX = event.clientX;
@@ -6943,6 +6961,18 @@ var VideoPlayer = ({
6943
6961
  },
6944
6962
  [showControlsWithTimer]
6945
6963
  );
6964
+ const handleMouseEnter = useCallback(() => {
6965
+ showControlsWithTimer();
6966
+ }, [showControlsWithTimer]);
6967
+ const handleMouseLeave = useCallback(() => {
6968
+ const userInteracting = isUserInteracting();
6969
+ clearControlsTimeout();
6970
+ if (!isFullscreen && !userInteracting) {
6971
+ controlsTimeoutRef.current = window.setTimeout(() => {
6972
+ setShowControls(false);
6973
+ }, LEAVE_HIDE_TIMEOUT);
6974
+ }
6975
+ }, [isFullscreen, clearControlsTimeout, isUserInteracting]);
6946
6976
  useEffect11(() => {
6947
6977
  if (videoRef.current) {
6948
6978
  videoRef.current.volume = volume;
@@ -6969,9 +6999,13 @@ var VideoPlayer = ({
6969
6999
  showControlsWithTimer();
6970
7000
  } else {
6971
7001
  clearControlsTimeout();
6972
- setShowControls(true);
7002
+ if (isFullscreen) {
7003
+ setShowControls(true);
7004
+ } else {
7005
+ showControlsWithTimer();
7006
+ }
6973
7007
  }
6974
- }, [isPlaying, showControlsWithTimer, clearControlsTimeout]);
7008
+ }, [isPlaying, isFullscreen, showControlsWithTimer, clearControlsTimeout]);
6975
7009
  useEffect11(() => {
6976
7010
  const handleFullscreenChange = () => {
6977
7011
  const isCurrentlyFullscreen = !!document.fullscreenElement;
@@ -6985,6 +7019,28 @@ var VideoPlayer = ({
6985
7019
  document.removeEventListener("fullscreenchange", handleFullscreenChange);
6986
7020
  };
6987
7021
  }, [showControlsWithTimer]);
7022
+ useEffect11(() => {
7023
+ const init = () => {
7024
+ if (!isFullscreen) {
7025
+ showControlsWithTimer();
7026
+ }
7027
+ };
7028
+ let raf1 = 0, raf2 = 0, tid;
7029
+ if (typeof window.requestAnimationFrame === "function") {
7030
+ raf1 = requestAnimationFrame(() => {
7031
+ raf2 = requestAnimationFrame(init);
7032
+ });
7033
+ return () => {
7034
+ cancelAnimationFrame(raf1);
7035
+ cancelAnimationFrame(raf2);
7036
+ };
7037
+ } else {
7038
+ tid = window.setTimeout(init, INIT_DELAY);
7039
+ return () => {
7040
+ if (tid) clearTimeout(tid);
7041
+ };
7042
+ }
7043
+ }, []);
6988
7044
  const getInitialTime = useCallback(() => {
6989
7045
  if (!autoSave || !storageKey) {
6990
7046
  return Number.isFinite(initialTime) && initialTime >= 0 ? initialTime : void 0;
@@ -7141,22 +7197,15 @@ var VideoPlayer = ({
7141
7197
  document.removeEventListener("visibilitychange", handleVisibilityChange);
7142
7198
  window.removeEventListener("blur", handleBlur);
7143
7199
  clearControlsTimeout();
7144
- clearMouseMoveTimeout();
7145
7200
  };
7146
- }, [isPlaying, clearControlsTimeout, clearMouseMoveTimeout]);
7201
+ }, [isPlaying, clearControlsTimeout]);
7147
7202
  const progressPercentage = duration > 0 ? currentTime / duration * 100 : 0;
7148
7203
  const getTopControlsOpacity = useCallback(() => {
7149
- if (isFullscreen) {
7150
- return showControls ? "opacity-100" : "opacity-0";
7151
- }
7152
- return !isPlaying || showControls ? "opacity-100" : "opacity-0 group-hover:opacity-100";
7153
- }, [isFullscreen, showControls, isPlaying]);
7204
+ return showControls ? "opacity-100" : "opacity-0";
7205
+ }, [showControls]);
7154
7206
  const getBottomControlsOpacity = useCallback(() => {
7155
- if (isFullscreen) {
7156
- return showControls ? "opacity-100" : "opacity-0";
7157
- }
7158
- return !isPlaying || showControls ? "opacity-100" : "opacity-0 group-hover:opacity-100";
7159
- }, [isFullscreen, showControls, isPlaying]);
7207
+ return showControls ? "opacity-100" : "opacity-0";
7208
+ }, [showControls]);
7160
7209
  const handleVideoKeyDown = useCallback(
7161
7210
  (e) => {
7162
7211
  if (e.key) {
@@ -7213,7 +7262,7 @@ var VideoPlayer = ({
7213
7262
  ]
7214
7263
  );
7215
7264
  return /* @__PURE__ */ jsxs30("div", { className: cn("flex flex-col", className), children: [
7216
- (title || subtitleText) && /* @__PURE__ */ jsx36("div", { className: "bg-subject-1 rounded-t-xl px-8 py-4 flex items-end justify-between min-h-20", children: /* @__PURE__ */ jsxs30("div", { className: "flex flex-col gap-1", children: [
7265
+ (title || subtitleText) && /* @__PURE__ */ jsx36("div", { className: "bg-subject-1 px-8 py-4 flex items-end justify-between min-h-20", children: /* @__PURE__ */ jsxs30("div", { className: "flex flex-col gap-1", children: [
7217
7266
  title && /* @__PURE__ */ jsx36(
7218
7267
  Text_default,
7219
7268
  {
@@ -7242,13 +7291,15 @@ var VideoPlayer = ({
7242
7291
  {
7243
7292
  className: cn(
7244
7293
  "relative w-full bg-background overflow-hidden group",
7245
- title || subtitleText ? "rounded-b-xl" : "rounded-xl",
7246
- // Hide cursor when controls are hidden and video is playing in fullscreen
7247
- isFullscreen && isPlaying && !showControls ? "cursor-none" : "cursor-default"
7294
+ "rounded-b-xl",
7295
+ // Hide cursor when controls are hidden and video is playing
7296
+ isPlaying && !showControls ? "cursor-none group-hover:cursor-default" : "cursor-default"
7248
7297
  ),
7249
7298
  "aria-label": title ? `Video player: ${title}` : "Video player",
7250
- onMouseMove: isFullscreen ? handleMouseMove : showControlsWithTimer,
7251
- onMouseEnter: showControlsWithTimer,
7299
+ onMouseMove: handleMouseMove,
7300
+ onMouseEnter: handleMouseEnter,
7301
+ onTouchStart: handleMouseEnter,
7302
+ onMouseLeave: handleMouseLeave,
7252
7303
  children: [
7253
7304
  /* @__PURE__ */ jsx36(
7254
7305
  "video",