@gentomiyano/optimized-web-audio-player 0.2.0 → 0.2.1
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 +12 -0
- package/dist/react/index.d.ts +10 -2
- package/dist/react/index.js +530 -2
- package/dist/react/index.js.map +1 -1
- package/dist/ui/index.d.ts +14 -6
- package/dist/ui/index.js +31 -109
- package/dist/ui/index.js.map +1 -1
- package/package.json +3 -2
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { C as PlayerViewProps, h as PlayerAppearance,
|
|
3
|
+
import { C as PlayerViewProps, h as PlayerAppearance, B as BoundPlayerCommands, a as BoundPlayerViewState, S as SeekCommitMode, d as PlaybackContextMode, v as PlayerMediaItem, y as PlayerState, j as PlayerCommands, n as PlayerError, R as RepeatMode, f as PlaybackStatus, D as PlayerWaveform } from '../player-BxNFzRq4.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
|
|
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
|
|
13
|
-
readonly
|
|
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;
|
|
15
23
|
}
|
|
16
|
-
declare function
|
|
24
|
+
declare function BoundCompactPlayerView({ appearance, className, commands, contextId, contextMode, options, state, }: BoundCompactPlayerViewProps): react.JSX.Element;
|
|
17
25
|
|
|
18
26
|
interface DetailedPlayerProps extends PlayerViewProps {
|
|
19
27
|
readonly className?: string;
|
|
@@ -148,4 +156,4 @@ interface WidePlayerProps extends PlayerViewProps {
|
|
|
148
156
|
}
|
|
149
157
|
declare function WidePlayer({ appearance, className, commands, state, }: WidePlayerProps): react.JSX.Element;
|
|
150
158
|
|
|
151
|
-
export { Artwork, type ArtworkProps,
|
|
159
|
+
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 {
|
|
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,80 @@ function SeekBar({
|
|
|
948
875
|
}
|
|
949
876
|
);
|
|
950
877
|
}
|
|
951
|
-
function
|
|
878
|
+
function BoundCompactPlayerView({
|
|
952
879
|
appearance,
|
|
953
880
|
className,
|
|
954
|
-
|
|
955
|
-
|
|
881
|
+
commands,
|
|
882
|
+
contextId,
|
|
883
|
+
contextMode,
|
|
884
|
+
options,
|
|
885
|
+
state
|
|
956
886
|
}) {
|
|
957
|
-
const
|
|
958
|
-
const player = usePlayer();
|
|
959
|
-
const progress = bound.state.durationSec === null || bound.state.durationSec <= 0 ? 0 : bound.state.currentTimeSec / bound.state.durationSec;
|
|
887
|
+
const progress = state.durationSec === null || state.durationSec <= 0 ? 0 : state.currentTimeSec / state.durationSec;
|
|
960
888
|
return /* @__PURE__ */ jsx(
|
|
961
889
|
PlayerSurface,
|
|
962
890
|
{
|
|
963
891
|
appearance,
|
|
964
892
|
className: ["player-bound-compact", className].filter(Boolean).join(" "),
|
|
965
|
-
label: `Inline player: ${
|
|
893
|
+
label: `Inline player: ${state.item.title}`,
|
|
966
894
|
children: /* @__PURE__ */ jsxs(
|
|
967
895
|
"div",
|
|
968
896
|
{
|
|
969
897
|
className: "player-bound-compact__main",
|
|
970
|
-
"data-active":
|
|
971
|
-
"data-playback-context-id":
|
|
972
|
-
"data-playback-context-mode":
|
|
973
|
-
"data-queue-item-id":
|
|
898
|
+
"data-active": state.isActive ? "true" : "false",
|
|
899
|
+
"data-playback-context-id": contextId,
|
|
900
|
+
"data-playback-context-mode": contextMode,
|
|
901
|
+
"data-queue-item-id": state.queueItemId,
|
|
974
902
|
children: [
|
|
975
903
|
/* @__PURE__ */ jsx(
|
|
976
904
|
IconButton,
|
|
977
905
|
{
|
|
978
906
|
className: "player-play-button",
|
|
979
|
-
label:
|
|
907
|
+
label: state.isPlaying ? "Pause" : "Play",
|
|
980
908
|
onClick: () => {
|
|
981
|
-
void
|
|
909
|
+
void commands.togglePlayback();
|
|
982
910
|
},
|
|
983
|
-
children:
|
|
911
|
+
children: state.isPlaying ? /* @__PURE__ */ jsx(PauseIcon, { size: 22 }) : /* @__PURE__ */ jsx(PlayIcon, { size: 22 })
|
|
984
912
|
}
|
|
985
913
|
),
|
|
986
914
|
/* @__PURE__ */ jsx(
|
|
987
915
|
Artwork,
|
|
988
916
|
{
|
|
989
917
|
className: "player-bound-compact__artwork",
|
|
990
|
-
item:
|
|
991
|
-
}
|
|
992
|
-
),
|
|
993
|
-
/* @__PURE__ */ jsx(
|
|
994
|
-
TrackMetadata,
|
|
995
|
-
{
|
|
996
|
-
item: bound.state.item,
|
|
997
|
-
scrollTitle: bound.state.isPlaying
|
|
918
|
+
item: state.item
|
|
998
919
|
}
|
|
999
920
|
),
|
|
921
|
+
/* @__PURE__ */ jsx(TrackMetadata, { item: state.item, scrollTitle: state.isPlaying }),
|
|
1000
922
|
/* @__PURE__ */ jsxs("div", { className: "player-bound-compact__signal", children: [
|
|
1001
923
|
/* @__PURE__ */ jsx(
|
|
1002
924
|
Waveform,
|
|
1003
925
|
{
|
|
1004
|
-
opacity:
|
|
1005
|
-
playedStateEnabled:
|
|
926
|
+
opacity: options.waveformOpacity,
|
|
927
|
+
playedStateEnabled: options.waveformPlayedStateEnabled,
|
|
1006
928
|
progress,
|
|
1007
|
-
waveform:
|
|
929
|
+
waveform: state.item.waveform
|
|
1008
930
|
}
|
|
1009
931
|
),
|
|
1010
932
|
/* @__PURE__ */ jsx(
|
|
1011
933
|
TimeReadout,
|
|
1012
934
|
{
|
|
1013
|
-
currentTimeSec:
|
|
1014
|
-
durationSec:
|
|
935
|
+
currentTimeSec: state.currentTimeSec,
|
|
936
|
+
durationSec: state.durationSec
|
|
1015
937
|
}
|
|
1016
938
|
)
|
|
1017
939
|
] }),
|
|
1018
940
|
/* @__PURE__ */ jsx(
|
|
1019
941
|
SeekBar,
|
|
1020
942
|
{
|
|
1021
|
-
canSeek:
|
|
1022
|
-
commitMode:
|
|
1023
|
-
currentTimeSec:
|
|
1024
|
-
durationSec:
|
|
1025
|
-
label: `Seek in ${
|
|
943
|
+
canSeek: state.canSeek,
|
|
944
|
+
commitMode: options.seekCommitMode,
|
|
945
|
+
currentTimeSec: state.currentTimeSec,
|
|
946
|
+
durationSec: state.durationSec,
|
|
947
|
+
label: `Seek in ${state.item.title}`,
|
|
1026
948
|
onSeek: (seconds) => {
|
|
1027
|
-
|
|
949
|
+
commands.seekTo(seconds);
|
|
1028
950
|
},
|
|
1029
|
-
status:
|
|
951
|
+
status: state.status
|
|
1030
952
|
}
|
|
1031
953
|
)
|
|
1032
954
|
]
|
|
@@ -1510,6 +1432,6 @@ function WidePlayer({
|
|
|
1510
1432
|
);
|
|
1511
1433
|
}
|
|
1512
1434
|
|
|
1513
|
-
export { Artwork,
|
|
1435
|
+
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
1436
|
//# sourceMappingURL=index.js.map
|
|
1515
1437
|
//# sourceMappingURL=index.js.map
|