analytica-frontend-lib 1.1.90 → 1.1.91

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
@@ -8557,6 +8557,7 @@ var VideoPlayer = ({
8557
8557
  const [showControls, setShowControls] = useState14(true);
8558
8558
  const [hasCompleted, setHasCompleted] = useState14(false);
8559
8559
  const [showCaptions, setShowCaptions] = useState14(false);
8560
+ const [subtitlesValidation, setSubtitlesValidation] = useState14("idle");
8560
8561
  useEffect15(() => {
8561
8562
  setHasCompleted(false);
8562
8563
  }, [src]);
@@ -8842,11 +8843,12 @@ var VideoPlayer = ({
8842
8843
  setShowSpeedMenu(!showSpeedMenu);
8843
8844
  }, [showSpeedMenu]);
8844
8845
  const toggleCaptions = useCallback3(() => {
8845
- if (!trackRef.current?.track || !subtitles) return;
8846
+ if (!trackRef.current?.track || !subtitles || subtitlesValidation !== "valid")
8847
+ return;
8846
8848
  const newShowCaptions = !showCaptions;
8847
8849
  setShowCaptions(newShowCaptions);
8848
- trackRef.current.track.mode = newShowCaptions && subtitles ? "showing" : "hidden";
8849
- }, [showCaptions, subtitles]);
8850
+ trackRef.current.track.mode = newShowCaptions ? "showing" : "hidden";
8851
+ }, [showCaptions, subtitles, subtitlesValidation]);
8850
8852
  const checkVideoCompletion = useCallback3(
8851
8853
  (progressPercent) => {
8852
8854
  if (progressPercent >= 95 && !hasCompleted) {
@@ -8874,11 +8876,58 @@ var VideoPlayer = ({
8874
8876
  setDuration(videoRef.current.duration);
8875
8877
  }
8876
8878
  }, []);
8879
+ useEffect15(() => {
8880
+ const controller = new AbortController();
8881
+ const validateSubtitles = async () => {
8882
+ if (!subtitles) {
8883
+ setSubtitlesValidation("idle");
8884
+ return;
8885
+ }
8886
+ setSubtitlesValidation("validating");
8887
+ try {
8888
+ if (subtitles.startsWith("data:")) {
8889
+ setSubtitlesValidation("valid");
8890
+ return;
8891
+ }
8892
+ const response = await fetch(subtitles, {
8893
+ method: "HEAD",
8894
+ signal: controller.signal
8895
+ });
8896
+ if (response.ok) {
8897
+ const contentType = response.headers.get("content-type");
8898
+ const isValidType = !contentType || contentType.includes("text/vtt") || contentType.includes("text/plain") || contentType.includes("application/octet-stream");
8899
+ if (isValidType) {
8900
+ setSubtitlesValidation("valid");
8901
+ } else {
8902
+ setSubtitlesValidation("invalid");
8903
+ console.warn(
8904
+ `Subtitles URL has invalid content type: ${contentType}`
8905
+ );
8906
+ }
8907
+ } else {
8908
+ setSubtitlesValidation("invalid");
8909
+ console.warn(
8910
+ `Subtitles URL returned status: ${response.status} ${response.statusText}`
8911
+ );
8912
+ }
8913
+ } catch (error) {
8914
+ if (error instanceof Error && error.name === "AbortError") {
8915
+ return;
8916
+ }
8917
+ console.warn("Subtitles URL validation failed:", error);
8918
+ setSubtitlesValidation("invalid");
8919
+ }
8920
+ };
8921
+ validateSubtitles();
8922
+ return () => {
8923
+ controller.abort();
8924
+ };
8925
+ }, [subtitles]);
8877
8926
  useEffect15(() => {
8878
8927
  if (trackRef.current?.track) {
8879
- trackRef.current.track.mode = showCaptions && subtitles ? "showing" : "hidden";
8928
+ trackRef.current.track.mode = showCaptions && subtitles && subtitlesValidation === "valid" ? "showing" : "hidden";
8880
8929
  }
8881
- }, [subtitles, showCaptions]);
8930
+ }, [subtitles, showCaptions, subtitlesValidation]);
8882
8931
  useEffect15(() => {
8883
8932
  const handleVisibilityChange = () => {
8884
8933
  if (document.hidden && isPlaying && videoRef.current) {
@@ -8932,61 +8981,57 @@ var VideoPlayer = ({
8932
8981
  const getBottomControlsOpacity = useCallback3(() => {
8933
8982
  return showControls ? "opacity-100" : "opacity-0";
8934
8983
  }, [showControls]);
8984
+ const seekBackward = useCallback3(() => {
8985
+ if (videoRef.current) {
8986
+ videoRef.current.currentTime -= 10;
8987
+ }
8988
+ }, []);
8989
+ const seekForward = useCallback3(() => {
8990
+ if (videoRef.current) {
8991
+ videoRef.current.currentTime += 10;
8992
+ }
8993
+ }, []);
8994
+ const increaseVolume = useCallback3(() => {
8995
+ handleVolumeChange(Math.min(100, volume * 100 + 10));
8996
+ }, [handleVolumeChange, volume]);
8997
+ const decreaseVolume = useCallback3(() => {
8998
+ handleVolumeChange(Math.max(0, volume * 100 - 10));
8999
+ }, [handleVolumeChange, volume]);
8935
9000
  const handleVideoKeyDown = useCallback3(
8936
9001
  (e) => {
8937
- if (e.key) {
8938
- e.stopPropagation();
8939
- showControlsWithTimer();
8940
- }
8941
- switch (e.key) {
8942
- case " ":
8943
- case "Enter":
8944
- e.preventDefault();
8945
- togglePlayPause();
8946
- break;
8947
- case "ArrowLeft":
8948
- e.preventDefault();
8949
- if (videoRef.current) {
8950
- videoRef.current.currentTime -= 10;
8951
- }
8952
- break;
8953
- case "ArrowRight":
8954
- e.preventDefault();
8955
- if (videoRef.current) {
8956
- videoRef.current.currentTime += 10;
8957
- }
8958
- break;
8959
- case "ArrowUp":
8960
- e.preventDefault();
8961
- handleVolumeChange(Math.min(100, volume * 100 + 10));
8962
- break;
8963
- case "ArrowDown":
8964
- e.preventDefault();
8965
- handleVolumeChange(Math.max(0, volume * 100 - 10));
8966
- break;
8967
- case "m":
8968
- case "M":
8969
- e.preventDefault();
8970
- toggleMute();
8971
- break;
8972
- case "f":
8973
- case "F":
8974
- e.preventDefault();
8975
- toggleFullscreen();
8976
- break;
8977
- default:
8978
- break;
9002
+ if (!e.key) return;
9003
+ e.stopPropagation();
9004
+ showControlsWithTimer();
9005
+ const keyHandlers = {
9006
+ " ": togglePlayPause,
9007
+ Enter: togglePlayPause,
9008
+ ArrowLeft: seekBackward,
9009
+ ArrowRight: seekForward,
9010
+ ArrowUp: increaseVolume,
9011
+ ArrowDown: decreaseVolume,
9012
+ m: toggleMute,
9013
+ M: toggleMute,
9014
+ f: toggleFullscreen,
9015
+ F: toggleFullscreen
9016
+ };
9017
+ const handler = keyHandlers[e.key];
9018
+ if (handler) {
9019
+ e.preventDefault();
9020
+ handler();
8979
9021
  }
8980
9022
  },
8981
9023
  [
8982
9024
  showControlsWithTimer,
8983
9025
  togglePlayPause,
8984
- handleVolumeChange,
8985
- volume,
9026
+ seekBackward,
9027
+ seekForward,
9028
+ increaseVolume,
9029
+ decreaseVolume,
8986
9030
  toggleMute,
8987
9031
  toggleFullscreen
8988
9032
  ]
8989
9033
  );
9034
+ const groupedSubTitleValid = subtitles && subtitlesValidation === "valid";
8990
9035
  return /* @__PURE__ */ jsxs31("div", { className: cn("flex flex-col", className), children: [
8991
9036
  (title || subtitleText) && /* @__PURE__ */ jsxs31("div", { className: "bg-subject-1 px-8 py-4 flex items-end justify-between min-h-20", children: [
8992
9037
  /* @__PURE__ */ jsxs31("div", { className: "flex flex-col gap-1", children: [
@@ -9060,9 +9105,9 @@ var VideoPlayer = ({
9060
9105
  {
9061
9106
  ref: trackRef,
9062
9107
  kind: "captions",
9063
- src: subtitles || "data:text/vtt;charset=utf-8,WEBVTT",
9108
+ src: groupedSubTitleValid ? subtitles : "data:text/vtt;charset=utf-8,WEBVTT",
9064
9109
  srcLang: "pt-br",
9065
- label: subtitles ? "Legendas em Portugu\xEAs" : "Sem legendas dispon\xEDveis",
9110
+ label: groupedSubTitleValid ? "Legendas em Portugu\xEAs" : "Sem legendas dispon\xEDveis",
9066
9111
  default: false
9067
9112
  }
9068
9113
  )
@@ -9151,7 +9196,7 @@ var VideoPlayer = ({
9151
9196
  showSlider: !isUltraSmallMobile
9152
9197
  }
9153
9198
  ),
9154
- subtitles && /* @__PURE__ */ jsx44(
9199
+ groupedSubTitleValid && /* @__PURE__ */ jsx44(
9155
9200
  IconButton_default,
9156
9201
  {
9157
9202
  icon: /* @__PURE__ */ jsx44(ClosedCaptioning, { size: getIconSize2() }),