react-modern-audio-player 1.1.2 → 1.1.3

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.es.js CHANGED
@@ -7920,7 +7920,7 @@ let $bf24a13e98395dd3$export$bca14c5b3b88a9c9 = {
7920
7920
  const useNonNullableContext = (context) => {
7921
7921
  const state = useContext(context);
7922
7922
  if (!state)
7923
- throw new Error(`Cannot find ${context}Provider`);
7923
+ throw new Error(`${context} is not provided or null`);
7924
7924
  return state;
7925
7925
  };
7926
7926
  const defaultInterfacePlacement = {
@@ -12645,6 +12645,12 @@ const useWaveSurfer = () => {
12645
12645
  const curTime = elementRefs.waveformInst.getCurrentTime();
12646
12646
  trackCurTimeEl.innerText = getTimeWithPadStart(curTime);
12647
12647
  }, [elementRefs]);
12648
+ const waveEl = document.getElementsByTagName("wave");
12649
+ useEffect(() => {
12650
+ if (waveEl.length > 1) {
12651
+ waveEl[0].setAttribute("style", "display: none");
12652
+ }
12653
+ }, [waveEl]);
12648
12654
  const [curAudioData, setCurAudioData] = useState();
12649
12655
  useEffect(() => {
12650
12656
  if (!(elementRefs == null ? void 0 : elementRefs.waveformInst) || !playList[curIdx])
@@ -12780,6 +12786,8 @@ const StyledBtn = styled.button`
12780
12786
  height: 100%;
12781
12787
  pointer-events: none;
12782
12788
  }
12789
+
12790
+ /** //TODO : animation on off */
12783
12791
  &:hover {
12784
12792
  transform: scale(1.1);
12785
12793
  }
@@ -12888,7 +12896,7 @@ const PlayBtn = () => {
12888
12896
  customIcons
12889
12897
  } = useNonNullableContext(audioPlayerStateContext);
12890
12898
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12891
- const onClick = () => audioPlayerDispatch({
12899
+ const changePlayState = () => audioPlayerDispatch({
12892
12900
  type: "SET_PlAY_STATE"
12893
12901
  });
12894
12902
  const PlayIcon = useMemo(() => {
@@ -12903,7 +12911,7 @@ const PlayBtn = () => {
12903
12911
  });
12904
12912
  }, [curAudioState.isPlaying, customIcons == null ? void 0 : customIcons.pause, customIcons == null ? void 0 : customIcons.play]);
12905
12913
  return /* @__PURE__ */ jsx(StyledPlayBtn, {
12906
- onClick,
12914
+ onClick: changePlayState,
12907
12915
  className: "play-button",
12908
12916
  children: PlayIcon
12909
12917
  });
@@ -12922,7 +12930,7 @@ const PrevNnextBtn = ({
12922
12930
  customIcons
12923
12931
  } = useNonNullableContext(audioPlayerStateContext);
12924
12932
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12925
- const onClickBtn = () => {
12933
+ const changeAudio = () => {
12926
12934
  if (type === "next") {
12927
12935
  audioPlayerDispatch({
12928
12936
  type: "NEXT_AUDIO"
@@ -12950,7 +12958,7 @@ const PrevNnextBtn = ({
12950
12958
  return null;
12951
12959
  }, [customIcons == null ? void 0 : customIcons.next, customIcons == null ? void 0 : customIcons.prev, type]);
12952
12960
  return visible ? /* @__PURE__ */ jsx(StyledBtn, {
12953
- onClick: onClickBtn,
12961
+ onClick: changeAudio,
12954
12962
  className: "prev-n-next-button",
12955
12963
  children: PrevNnextIcon
12956
12964
  }) : null;
@@ -12982,7 +12990,7 @@ const RepeatTypeBtn = () => {
12982
12990
  customIcons
12983
12991
  } = useNonNullableContext(audioPlayerStateContext);
12984
12992
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12985
- const onClick = useCallback(() => {
12993
+ const changeRepeatType = useCallback(() => {
12986
12994
  switch (curAudioState.repeatType) {
12987
12995
  case "ALL":
12988
12996
  audioPlayerDispatch({
@@ -13035,7 +13043,7 @@ const RepeatTypeBtn = () => {
13035
13043
  }
13036
13044
  }, [curAudioState.repeatType, customIcons == null ? void 0 : customIcons.repeatAll, customIcons == null ? void 0 : customIcons.repeatNone, customIcons == null ? void 0 : customIcons.repeatOne, customIcons == null ? void 0 : customIcons.repeatShuffle]);
13037
13045
  return /* @__PURE__ */ jsx(StyledBtn, {
13038
- onClick,
13046
+ onClick: changeRepeatType,
13039
13047
  className: "repeat-button",
13040
13048
  children: RepeatIcon
13041
13049
  });
@@ -13062,7 +13070,7 @@ const VolumeTriggerBtn = forwardRef((_, ref) => {
13062
13070
  customIcons
13063
13071
  } = useNonNullableContext(audioPlayerStateContext);
13064
13072
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
13065
- const onClickMuted = useCallback(() => audioPlayerDispatch({
13073
+ const changeMuteState = useCallback(() => audioPlayerDispatch({
13066
13074
  type: "SET_MUTED",
13067
13075
  muted: !curAudioState.muted
13068
13076
  }), [audioPlayerDispatch, curAudioState.muted]);
@@ -13112,7 +13120,7 @@ const VolumeTriggerBtn = forwardRef((_, ref) => {
13112
13120
  }
13113
13121
  }, [curAudioState.muted, curAudioState.volume, customIcons == null ? void 0 : customIcons.volumeMuted, customIcons == null ? void 0 : customIcons.volumeFull, customIcons == null ? void 0 : customIcons.volumeHalf]);
13114
13122
  return /* @__PURE__ */ jsx(StyledBtn, {
13115
- onClick: onClickMuted,
13123
+ onClick: changeMuteState,
13116
13124
  className: "volume-trigger-container",
13117
13125
  ref,
13118
13126
  children: VolumeIcon
@@ -14398,29 +14406,39 @@ const DropdownTrigger = ({
14398
14406
  };
14399
14407
  Dropdown.Content = DropdownContent;
14400
14408
  Dropdown.Trigger = DropdownTrigger;
14401
- const Volume = () => {
14402
- const triggerRef = useRef(null);
14403
- const {
14404
- activeUI: {
14405
- volumeSlider
14406
- }
14407
- } = useNonNullableContext(audioPlayerStateContext);
14408
- const [volumeSliderPlacement, setVolumeSliderPlacement] = useState("bottom");
14409
+ const useVolumeSliderPlacement = ({
14410
+ ref,
14411
+ initialState
14412
+ }) => {
14413
+ const [volumeSliderPlacement, setVolumeSliderPlacement] = useState(initialState);
14409
14414
  useEffect(() => {
14410
- if (triggerRef.current) {
14415
+ if (ref.current) {
14411
14416
  const placementValidation = () => {
14412
- if (triggerRef.current.getBoundingClientRect().top < window.innerHeight / 2) {
14417
+ if (ref.current.getBoundingClientRect().top < window.innerHeight / 2) {
14413
14418
  return "bottom";
14414
14419
  }
14415
14420
  return "top";
14416
14421
  };
14417
14422
  setVolumeSliderPlacement(placementValidation());
14418
14423
  }
14419
- }, [triggerRef.current]);
14424
+ }, [ref.current]);
14425
+ return volumeSliderPlacement;
14426
+ };
14427
+ const Volume = () => {
14428
+ const triggerRef = useRef(null);
14429
+ const {
14430
+ activeUI: {
14431
+ volumeSlider: volumeSliderEl
14432
+ }
14433
+ } = useNonNullableContext(audioPlayerStateContext);
14434
+ const volumeSliderPlacement = useVolumeSliderPlacement({
14435
+ ref: triggerRef,
14436
+ initialState: "bottom"
14437
+ });
14420
14438
  return /* @__PURE__ */ jsxs(Dropdown, {
14421
14439
  placement: volumeSliderPlacement,
14422
14440
  triggerType: "hover",
14423
- disabled: !volumeSlider,
14441
+ disabled: !volumeSliderEl,
14424
14442
  children: [/* @__PURE__ */ jsx(Dropdown.Trigger, {
14425
14443
  children: /* @__PURE__ */ jsx(VolumeTriggerBtn, {
14426
14444
  ref: triggerRef
@@ -14541,18 +14559,10 @@ const TrackTimeCurrent = () => {
14541
14559
  const {
14542
14560
  activeUI
14543
14561
  } = useNonNullableContext(audioPlayerStateContext);
14544
- const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14545
- useEffect(() => {
14546
- if (trackCurTimeRef.current) {
14547
- const trackCurTimeEl = trackCurTimeRef.current;
14548
- audioPlayerDispatch({
14549
- type: "SET_ELEMENT_REFS",
14550
- elementRefs: {
14551
- trackCurTimeEl
14552
- }
14553
- });
14554
- }
14555
- }, [trackCurTimeRef.current, audioPlayerDispatch]);
14562
+ useTrackTimeRefDispatchEffect({
14563
+ ref: trackCurTimeRef,
14564
+ refName: "trackCurTimeEl"
14565
+ });
14556
14566
  return /* @__PURE__ */ jsx(TrackTimeCurrentContainer, {
14557
14567
  type: activeUI.trackTime,
14558
14568
  className: "track-time-current-container",
@@ -14568,18 +14578,10 @@ const TrackTimeDuration = () => {
14568
14578
  const {
14569
14579
  activeUI
14570
14580
  } = useNonNullableContext(audioPlayerStateContext);
14571
- const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14572
- useEffect(() => {
14573
- if (trackDurationRef.current) {
14574
- const trackDurationEl = trackDurationRef.current;
14575
- audioPlayerDispatch({
14576
- type: "SET_ELEMENT_REFS",
14577
- elementRefs: {
14578
- trackDurationEl
14579
- }
14580
- });
14581
- }
14582
- }, [trackDurationRef.current, audioPlayerDispatch]);
14581
+ useTrackTimeRefDispatchEffect({
14582
+ ref: trackDurationRef,
14583
+ refName: "trackDurationEl"
14584
+ });
14583
14585
  return /* @__PURE__ */ jsx(TrackTimeDurationContainer, {
14584
14586
  type: activeUI.trackTime,
14585
14587
  className: "track-time-duration-container",
@@ -14590,6 +14592,23 @@ const TrackTimeDuration = () => {
14590
14592
  })
14591
14593
  });
14592
14594
  };
14595
+ const useTrackTimeRefDispatchEffect = ({
14596
+ ref,
14597
+ refName
14598
+ }) => {
14599
+ const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14600
+ useEffect(() => {
14601
+ const trackTimeRef = ref.current;
14602
+ if (trackTimeRef) {
14603
+ audioPlayerDispatch({
14604
+ type: "SET_ELEMENT_REFS",
14605
+ elementRefs: {
14606
+ [refName]: trackTimeRef
14607
+ }
14608
+ });
14609
+ }
14610
+ }, [ref.current, audioPlayerDispatch, refName]);
14611
+ };
14593
14612
  const TrackTimeContainer = styled.div`
14594
14613
  display: flex;
14595
14614
  align-items: center;
@@ -14635,7 +14654,7 @@ const Information = () => {
14635
14654
  curIdx,
14636
14655
  activeUI
14637
14656
  } = useNonNullableContext(audioPlayerStateContext);
14638
- const trackInfoActive = Boolean((_e = (_c = (_a2 = playList[curIdx]) == null ? void 0 : _a2.customTrackInfo) != null ? _c : (_b = playList[curIdx]) == null ? void 0 : _b.writer) != null ? _e : (_d = playList[curIdx]) == null ? void 0 : _d.name) && Boolean((_f = activeUI.trackInfo) != null ? _f : activeUI.all);
14657
+ const isTrackInfoActive = Boolean((_e = (_c = (_a2 = playList[curIdx]) == null ? void 0 : _a2.customTrackInfo) != null ? _c : (_b = playList[curIdx]) == null ? void 0 : _b.writer) != null ? _e : (_d = playList[curIdx]) == null ? void 0 : _d.name) && Boolean((_f = activeUI.trackInfo) != null ? _f : activeUI.all);
14639
14658
  return /* @__PURE__ */ jsxs(Fragment, {
14640
14659
  children: [/* @__PURE__ */ jsx(Grid.Item, {
14641
14660
  gridArea: ((_g = interfacePlacement == null ? void 0 : interfacePlacement.itemCustomArea) == null ? void 0 : _g.artwork) || ((_h = interfacePlacement == null ? void 0 : interfacePlacement.templateArea) == null ? void 0 : _h.artwork) || defaultInterfacePlacement.templateArea.artwork,
@@ -14643,7 +14662,7 @@ const Information = () => {
14643
14662
  children: /* @__PURE__ */ jsx(Artwork, {})
14644
14663
  }), /* @__PURE__ */ jsx(Grid.Item, {
14645
14664
  gridArea: ((_k = interfacePlacement == null ? void 0 : interfacePlacement.itemCustomArea) == null ? void 0 : _k.trackInfo) || ((_l = interfacePlacement == null ? void 0 : interfacePlacement.templateArea) == null ? void 0 : _l.trackInfo) || defaultInterfacePlacement.templateArea.trackInfo,
14646
- visible: trackInfoActive,
14665
+ visible: isTrackInfoActive,
14647
14666
  children: /* @__PURE__ */ jsx(TrackInfo, {})
14648
14667
  }), /* @__PURE__ */ jsx(Grid.Item, {
14649
14668
  gridArea: ((_m = interfacePlacement == null ? void 0 : interfacePlacement.itemCustomArea) == null ? void 0 : _m.trackTimeCurrent) || ((_n = interfacePlacement == null ? void 0 : interfacePlacement.templateArea) == null ? void 0 : _n.trackTimeCurrent) || defaultInterfacePlacement.templateArea.trackTimeCurrent,
@@ -14759,13 +14778,13 @@ const Interface = () => {
14759
14778
  })]
14760
14779
  });
14761
14780
  };
14762
- const AudioPlayer = ({
14763
- playList,
14764
- audioInitialState,
14781
+ const usePropsStateEffect = ({
14765
14782
  placement = {},
14766
14783
  activeUI,
14767
- customIcons,
14768
- coverImgsCss
14784
+ coverImgsCss,
14785
+ audioInitialState,
14786
+ playList,
14787
+ customIcons
14769
14788
  }) => {
14770
14789
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14771
14790
  useLayoutEffect(() => {
@@ -14783,18 +14802,12 @@ const AudioPlayer = ({
14783
14802
  }, [audioPlayerDispatch, placement]);
14784
14803
  useLayoutEffect(() => {
14785
14804
  if (activeUI) {
14786
- audioPlayerDispatch({
14787
- type: "SET_ACTIVE_UI",
14788
- activeUI
14789
- });
14805
+ audioPlayerDispatch({ type: "SET_ACTIVE_UI", activeUI });
14790
14806
  }
14791
14807
  }, [activeUI, audioPlayerDispatch]);
14792
14808
  useLayoutEffect(() => {
14793
14809
  if (coverImgsCss) {
14794
- audioPlayerDispatch({
14795
- type: "SET_COVER_IMGS_CSS",
14796
- coverImgsCss
14797
- });
14810
+ audioPlayerDispatch({ type: "SET_COVER_IMGS_CSS", coverImgsCss });
14798
14811
  }
14799
14812
  }, [audioPlayerDispatch, coverImgsCss]);
14800
14813
  useEffect(() => {
@@ -14806,19 +14819,16 @@ const AudioPlayer = ({
14806
14819
  }
14807
14820
  }, [audioInitialState, audioPlayerDispatch]);
14808
14821
  useEffect(() => {
14809
- audioPlayerDispatch({
14810
- type: "UPDATE_PLAY_LIST",
14811
- playList
14812
- });
14822
+ audioPlayerDispatch({ type: "UPDATE_PLAY_LIST", playList });
14813
14823
  }, [audioPlayerDispatch, playList]);
14814
14824
  useEffect(() => {
14815
14825
  if (customIcons) {
14816
- audioPlayerDispatch({
14817
- type: "SET_CUSTOM_ICONS",
14818
- customIcons
14819
- });
14826
+ audioPlayerDispatch({ type: "SET_CUSTOM_ICONS", customIcons });
14820
14827
  }
14821
14828
  }, [customIcons, audioPlayerDispatch]);
14829
+ };
14830
+ const AudioPlayer = (props) => {
14831
+ usePropsStateEffect(props);
14822
14832
  return /* @__PURE__ */ jsxs($b9606c0c41d55371$export$27a5bd065ad55220, {
14823
14833
  id: "rm-audio-player",
14824
14834
  UNSAFE_className: "rm-audio-player-container",
@@ -0,0 +1,5 @@
1
+ import { VolumeSliderPlacement } from "./Content";
2
+ export declare const useVolumeSliderPlacement: ({ ref, initialState, }: {
3
+ ref: React.RefObject<HTMLElement>;
4
+ initialState: VolumeSliderPlacement;
5
+ }) => VolumeSliderPlacement;
@@ -1,5 +1,5 @@
1
1
  import { FC } from "react";
2
- import { ActiveUI, PlayListPlacement, CustomIcons, PlayerPlacement, PlayList, AudioInitialState, InterfacePlacement, CoverImgsCss } from '../AudioPlayer/Context';
2
+ import { ActiveUI, PlayListPlacement, CustomIcons, PlayerPlacement, PlayList, AudioInitialState, InterfacePlacement, CoverImgsCss } from '../../AudioPlayer/Context';
3
3
  export interface AudioPlayerProps {
4
4
  playList: PlayList;
5
5
  audioInitialState?: AudioInitialState;
@@ -0,0 +1,2 @@
1
+ import { AudioPlayerProps } from ".";
2
+ export declare const usePropsStateEffect: ({ placement, activeUI, coverImgsCss, audioInitialState, playList, customIcons, }: AudioPlayerProps) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-modern-audio-player",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "homepage": "https://github.com/slash9494/react-modern-audio-player/",
5
5
  "module": "dist/index.es.js",
6
6
  "main": "dist/index.cjs",