@gentomiyano/optimized-web-audio-player 0.2.0 → 0.2.2

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.
@@ -1,4 +1,4 @@
1
- import { u as PlayerMediaAdapter, v as PlayerMediaItem, Q as QueueItem, n as PlayerError, y as PlayerState, p as PlayerExperienceConfig } from '../player-BxNFzRq4.js';
1
+ import { u as PlayerMediaAdapter, v as PlayerMediaItem, Q as QueueItem, n as PlayerError, z as PlayerState, p as PlayerExperienceConfig } from '../player-CE714iU_.js';
2
2
 
3
3
  type MockPlayerScenario = "success" | "loading" | "duration-unknown" | "missing-waveform" | "recoverable-error" | "fatal-error";
4
4
  interface MockMediaRecord {
@@ -1,19 +1,28 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { C as PlayerViewProps, h as PlayerAppearance, c as PlaybackContextInput, Q as QueueItem, v as PlayerMediaItem, y as PlayerState, j as PlayerCommands, n as PlayerError, R as RepeatMode, f as PlaybackStatus, S as SeekCommitMode, D as PlayerWaveform } from '../player-BxNFzRq4.js';
3
+ import { D as PlayerViewProps, h as PlayerAppearance, B as BoundPlayerCommands, a as BoundPlayerViewState, S as SeekCommitMode, d as PlaybackContextMode, y as PlayerRuntimeStatus, v as PlayerMediaItem, z as PlayerState, j as PlayerCommands, n as PlayerError, R as RepeatMode, f as PlaybackStatus, E as PlayerWaveform } from '../player-CE714iU_.js';
4
4
 
5
5
  interface CompactPlayerProps extends PlayerViewProps {
6
6
  readonly className?: string;
7
7
  }
8
8
  declare function CompactPlayer({ appearance, className, commands, state, }: CompactPlayerProps): react.JSX.Element;
9
9
 
10
- interface BoundCompactPlayerProps {
10
+ interface BoundCompactPlayerViewOptions {
11
+ readonly seekCommitMode: SeekCommitMode;
12
+ readonly waveformOpacity: number;
13
+ readonly waveformPlayedStateEnabled: boolean;
14
+ }
15
+ interface BoundCompactPlayerViewProps {
11
16
  readonly appearance: PlayerAppearance;
12
- readonly context: PlaybackContextInput;
13
- readonly queueItem: QueueItem;
17
+ readonly commands: BoundPlayerCommands;
18
+ readonly state: Readonly<BoundPlayerViewState>;
19
+ readonly options: Readonly<BoundCompactPlayerViewOptions>;
14
20
  readonly className?: string;
21
+ readonly contextId?: string;
22
+ readonly contextMode?: PlaybackContextMode;
23
+ readonly runtimeStatus?: PlayerRuntimeStatus;
15
24
  }
16
- declare function BoundCompactPlayer({ appearance, className, context, queueItem, }: BoundCompactPlayerProps): react.JSX.Element;
25
+ declare function BoundCompactPlayerView({ appearance, className, commands, contextId, contextMode, options, runtimeStatus, state, }: BoundCompactPlayerViewProps): react.JSX.Element;
17
26
 
18
27
  interface DetailedPlayerProps extends PlayerViewProps {
19
28
  readonly className?: string;
@@ -148,4 +157,4 @@ interface WidePlayerProps extends PlayerViewProps {
148
157
  }
149
158
  declare function WidePlayer({ appearance, className, commands, state, }: WidePlayerProps): react.JSX.Element;
150
159
 
151
- export { Artwork, type ArtworkProps, BoundCompactPlayer, type BoundCompactPlayerProps, CompactPlayer, type CompactPlayerProps, DetailedPlayer, type DetailedPlayerProps, IconButton, type IconButtonProps, MiniPlayer, type MiniPlayerProps, PlayerErrorNotice, type PlayerErrorNoticeProps, PlayerStatus, type PlayerStatusProps, PlayerSurface, type PlayerSurfaceProps, PodcastPlayer, type PodcastPlayerProps, PopoverVolumeControl, type PopoverVolumeControlProps, PrimaryPlaybackButton, type PrimaryPlaybackButtonProps, QueuePanel, type QueuePanelProps, QueueToggle, type QueueToggleProps, SeekBar, type SeekBarProps, TimeReadout, type TimeReadoutProps, TrackMetadata, type TrackMetadataProps, TransportControls, type TransportControlsProps, VolumeControl, type VolumeControlProps, Waveform, type WaveformProps, WidePlayer, type WidePlayerProps, clamp, formatTime, formatTimeAria, getErrorMessage, getNextRepeatMode, getRepeatLabel, getStatusLabel };
160
+ export { Artwork, type ArtworkProps, BoundCompactPlayerView, type BoundCompactPlayerViewOptions, type BoundCompactPlayerViewProps, CompactPlayer, type CompactPlayerProps, DetailedPlayer, type DetailedPlayerProps, IconButton, type IconButtonProps, MiniPlayer, type MiniPlayerProps, PlayerErrorNotice, type PlayerErrorNoticeProps, PlayerStatus, type PlayerStatusProps, PlayerSurface, type PlayerSurfaceProps, PodcastPlayer, type PodcastPlayerProps, PopoverVolumeControl, type PopoverVolumeControlProps, PrimaryPlaybackButton, type PrimaryPlaybackButtonProps, QueuePanel, type QueuePanelProps, QueueToggle, type QueueToggleProps, SeekBar, type SeekBarProps, TimeReadout, type TimeReadoutProps, TrackMetadata, type TrackMetadataProps, TransportControls, type TransportControlsProps, VolumeControl, type VolumeControlProps, Waveform, type WaveformProps, WidePlayer, type WidePlayerProps, clamp, formatTime, formatTimeAria, getErrorMessage, getNextRepeatMode, getRepeatLabel, getStatusLabel };
package/dist/ui/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, useState, useRef, useId, useEffect, useMemo, useSyncExternalStore, useContext } from 'react';
1
+ import { useState, useRef, useId, useEffect } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
 
4
4
  // src/ui/player-primitives.tsx
@@ -781,79 +781,6 @@ function CompactPlayer({
781
781
  }
782
782
  );
783
783
  }
784
- var PlayerRuntimeContext = createContext(null);
785
- function usePlayerRuntimeContext() {
786
- const context = useContext(PlayerRuntimeContext);
787
- if (context === null) {
788
- throw new Error("usePlayer must be used inside PlayerProvider.");
789
- }
790
- return context;
791
- }
792
- function usePlayer() {
793
- const context = usePlayerRuntimeContext();
794
- const state = useSyncExternalStore(
795
- (listener) => context.store.subscribe(listener),
796
- () => context.store.getState(),
797
- () => context.store.getState()
798
- );
799
- return {
800
- state,
801
- commands: context.commands,
802
- experience: context.experience,
803
- audioContextState: context.audioContextState,
804
- audioMode: context.audioMode,
805
- mediaSessionSupported: context.mediaSessionSupported,
806
- mediaSessionActionsEnabled: context.mediaSessionActionsEnabled
807
- };
808
- }
809
- function deriveBoundPlayerViewState(playerState, contextId, queueItem) {
810
- const isActive = playerState.activeContext?.id === contextId && playerState.currentQueueItemId === queueItem.queueItemId;
811
- return Object.freeze({
812
- queueItemId: queueItem.queueItemId,
813
- item: isActive ? playerState.currentItem ?? queueItem.item : queueItem.item,
814
- isActive,
815
- status: isActive ? playerState.status : "paused",
816
- currentTimeSec: isActive ? playerState.currentTimeSec : 0,
817
- durationSec: isActive ? playerState.durationSec : queueItem.item.durationHintSec ?? null,
818
- canSeek: isActive && playerState.canSeek,
819
- isPlaying: isActive && playerState.status === "playing"
820
- });
821
- }
822
- function useBoundPlayer({
823
- context,
824
- queueItem
825
- }) {
826
- const player = usePlayer();
827
- const state = useMemo(
828
- () => deriveBoundPlayerViewState(player.state, context.id, queueItem),
829
- [context.id, player.state, queueItem]
830
- );
831
- const commands = useMemo(() => {
832
- const play = () => player.commands.activateContext({
833
- contextId: context.id,
834
- mode: context.mode,
835
- ...context.label === void 0 ? {} : { label: context.label },
836
- queue: context.mode === "manual-history" ? [queueItem] : context.queue,
837
- startQueueItemId: queueItem.queueItemId,
838
- autoplay: true
839
- });
840
- return Object.freeze({
841
- play,
842
- togglePlayback() {
843
- if (player.state.activeContext?.id === context.id && player.state.currentQueueItemId === queueItem.queueItemId) {
844
- return player.commands.togglePlayback();
845
- }
846
- return play();
847
- },
848
- seekTo(seconds) {
849
- if (player.state.activeContext?.id === context.id && player.state.currentQueueItemId === queueItem.queueItemId && player.state.canSeek) {
850
- player.commands.seekTo(seconds);
851
- }
852
- }
853
- });
854
- }, [context, player.commands, player.state, queueItem]);
855
- return { state, commands };
856
- }
857
784
  function SeekBar({
858
785
  canSeek,
859
786
  className,
@@ -948,85 +875,82 @@ function SeekBar({
948
875
  }
949
876
  );
950
877
  }
951
- function BoundCompactPlayer({
878
+ function BoundCompactPlayerView({
952
879
  appearance,
953
880
  className,
954
- context,
955
- queueItem
881
+ commands,
882
+ contextId,
883
+ contextMode,
884
+ options,
885
+ runtimeStatus,
886
+ state
956
887
  }) {
957
- const bound = useBoundPlayer({ context, queueItem });
958
- const player = usePlayer();
959
- const progress = bound.state.durationSec === null || bound.state.durationSec <= 0 ? 0 : bound.state.currentTimeSec / bound.state.durationSec;
888
+ const progress = state.durationSec === null || state.durationSec <= 0 ? 0 : state.currentTimeSec / state.durationSec;
960
889
  return /* @__PURE__ */ jsx(
961
890
  PlayerSurface,
962
891
  {
963
892
  appearance,
964
893
  className: ["player-bound-compact", className].filter(Boolean).join(" "),
965
- label: `Inline player: ${queueItem.item.title}`,
894
+ label: `Inline player: ${state.item.title}`,
966
895
  children: /* @__PURE__ */ jsxs(
967
896
  "div",
968
897
  {
969
898
  className: "player-bound-compact__main",
970
- "data-active": bound.state.isActive ? "true" : "false",
971
- "data-playback-context-id": context.id,
972
- "data-playback-context-mode": context.mode,
973
- "data-queue-item-id": queueItem.queueItemId,
899
+ "data-active": state.isActive ? "true" : "false",
900
+ "data-playback-context-id": contextId,
901
+ "data-playback-context-mode": contextMode,
902
+ "data-player-runtime-status": runtimeStatus,
903
+ "data-queue-item-id": state.queueItemId,
974
904
  children: [
975
905
  /* @__PURE__ */ jsx(
976
906
  IconButton,
977
907
  {
978
908
  className: "player-play-button",
979
- label: bound.state.isPlaying ? "Pause" : "Play",
909
+ label: state.isPlaying ? "Pause" : "Play",
980
910
  onClick: () => {
981
- void bound.commands.togglePlayback();
911
+ void commands.togglePlayback();
982
912
  },
983
- children: bound.state.isPlaying ? /* @__PURE__ */ jsx(PauseIcon, { size: 22 }) : /* @__PURE__ */ jsx(PlayIcon, { size: 22 })
913
+ children: state.isPlaying ? /* @__PURE__ */ jsx(PauseIcon, { size: 22 }) : /* @__PURE__ */ jsx(PlayIcon, { size: 22 })
984
914
  }
985
915
  ),
986
916
  /* @__PURE__ */ jsx(
987
917
  Artwork,
988
918
  {
989
919
  className: "player-bound-compact__artwork",
990
- item: bound.state.item
991
- }
992
- ),
993
- /* @__PURE__ */ jsx(
994
- TrackMetadata,
995
- {
996
- item: bound.state.item,
997
- scrollTitle: bound.state.isPlaying
920
+ item: state.item
998
921
  }
999
922
  ),
923
+ /* @__PURE__ */ jsx(TrackMetadata, { item: state.item, scrollTitle: state.isPlaying }),
1000
924
  /* @__PURE__ */ jsxs("div", { className: "player-bound-compact__signal", children: [
1001
925
  /* @__PURE__ */ jsx(
1002
926
  Waveform,
1003
927
  {
1004
- opacity: player.state.experienceConfig.waveformOpacity,
1005
- playedStateEnabled: player.state.experienceConfig.waveformPlayedStateEnabled,
928
+ opacity: options.waveformOpacity,
929
+ playedStateEnabled: options.waveformPlayedStateEnabled,
1006
930
  progress,
1007
- waveform: bound.state.item.waveform
931
+ waveform: state.item.waveform
1008
932
  }
1009
933
  ),
1010
934
  /* @__PURE__ */ jsx(
1011
935
  TimeReadout,
1012
936
  {
1013
- currentTimeSec: bound.state.currentTimeSec,
1014
- durationSec: bound.state.durationSec
937
+ currentTimeSec: state.currentTimeSec,
938
+ durationSec: state.durationSec
1015
939
  }
1016
940
  )
1017
941
  ] }),
1018
942
  /* @__PURE__ */ jsx(
1019
943
  SeekBar,
1020
944
  {
1021
- canSeek: bound.state.canSeek,
1022
- commitMode: player.state.experienceConfig.seekCommitMode,
1023
- currentTimeSec: bound.state.currentTimeSec,
1024
- durationSec: bound.state.durationSec,
1025
- label: `Seek in ${queueItem.item.title}`,
945
+ canSeek: state.canSeek,
946
+ commitMode: options.seekCommitMode,
947
+ currentTimeSec: state.currentTimeSec,
948
+ durationSec: state.durationSec,
949
+ label: `Seek in ${state.item.title}`,
1026
950
  onSeek: (seconds) => {
1027
- bound.commands.seekTo(seconds);
951
+ commands.seekTo(seconds);
1028
952
  },
1029
- status: bound.state.status
953
+ status: state.status
1030
954
  }
1031
955
  )
1032
956
  ]
@@ -1510,6 +1434,6 @@ function WidePlayer({
1510
1434
  );
1511
1435
  }
1512
1436
 
1513
- export { Artwork, BoundCompactPlayer, CompactPlayer, DetailedPlayer, IconButton, MiniPlayer, PlayerErrorNotice, PlayerStatus, PlayerSurface, PodcastPlayer, PopoverVolumeControl, PrimaryPlaybackButton, QueuePanel, QueueToggle, SeekBar, TimeReadout, TrackMetadata, TransportControls, VolumeControl, Waveform, WidePlayer, clamp, formatTime, formatTimeAria, getErrorMessage, getNextRepeatMode, getRepeatLabel, getStatusLabel };
1437
+ export { Artwork, BoundCompactPlayerView, CompactPlayer, DetailedPlayer, IconButton, MiniPlayer, PlayerErrorNotice, PlayerStatus, PlayerSurface, PodcastPlayer, PopoverVolumeControl, PrimaryPlaybackButton, QueuePanel, QueueToggle, SeekBar, TimeReadout, TrackMetadata, TransportControls, VolumeControl, Waveform, WidePlayer, clamp, formatTime, formatTimeAria, getErrorMessage, getNextRepeatMode, getRepeatLabel, getStatusLabel };
1514
1438
  //# sourceMappingURL=index.js.map
1515
1439
  //# sourceMappingURL=index.js.map