Skip to content

Commit f632cf9

Browse files
committed
style: format with default prettier config
1 parent 2084ff3 commit f632cf9

22 files changed

+292
-302
lines changed

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ module.exports = {
77
],
88
parser: "@typescript-eslint/parser",
99
root: true,
10-
}
10+
};

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
pnpm-lock.yaml

.prettierrc

-1
This file was deleted.

demo/index.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useState } from "react"
2-
import { createRoot } from "react-dom/client"
3-
import "aplayer/dist/APlayer.min.css"
4-
import { APlayer } from "../src"
1+
import { useState } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import "aplayer/dist/APlayer.min.css";
4+
import { APlayer } from "../src";
55

66
const playlist1 = [
77
{
@@ -32,7 +32,7 @@ const playlist1 = [
3232
cover:
3333
"https://p1.music.126.net/RzAd3yEwGX6PW7LEQtK6mA==/109951163707194914.jpg",
3434
},
35-
]
35+
];
3636

3737
const playlist2 = [
3838
{
@@ -42,10 +42,10 @@ const playlist2 = [
4242
cover:
4343
"https://p1.music.126.net/uOvEut2NG6enWVM1s_lJZQ==/109951167656922852.jpg",
4444
},
45-
]
45+
];
4646

4747
function App() {
48-
const [playlist, setPlaylist] = useState(playlist1)
48+
const [playlist, setPlaylist] = useState(playlist1);
4949
return (
5050
<div
5151
style={{
@@ -68,7 +68,7 @@ function App() {
6868
<button onClick={() => setPlaylist(playlist2)}>Playlist 2</button>
6969
</div>
7070
</div>
71-
)
71+
);
7272
}
7373

74-
createRoot(document.getElementById("root") as HTMLElement).render(<App />)
74+
createRoot(document.getElementById("root") as HTMLElement).render(<App />);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"build": "tsup src/index.ts",
2020
"dev": "vite",
2121
"test": "vitest run --passWithNoTests",
22+
"format": "prettier --write .",
2223
"prepublishOnly": "pnpm run build"
2324
},
2425
"license": "MIT",
2526
"devDependencies": {
26-
"@egoist/prettier-config": "1.0.0",
2727
"@testing-library/react": "^13.4.0",
2828
"@types/react": "^18.0.26",
2929
"@types/react-dom": "^18.0.9",

pnpm-lock.yaml

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renovate.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"config:base"
4-
]
2+
"extends": ["config:base"]
53
}

src/components/controller.tsx

+42-45
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { ReactComponent as IconVolumeUp } from "../assets/volume-up.svg"
2-
import { ReactComponent as IconVolumeDown } from "../assets/volume-down.svg"
3-
import { ReactComponent as IconVolumeOff } from "../assets/volume-off.svg"
4-
import { ReactComponent as IconMenu } from "../assets/menu.svg"
5-
import { ReactComponent as IconOrderList } from "../assets/order-list.svg"
6-
import { ReactComponent as IconOrderRandom } from "../assets/order-random.svg"
7-
import { ReactComponent as IconLoopAll } from "../assets/loop-all.svg"
8-
import { ReactComponent as IconLoopOne } from "../assets/loop-one.svg"
9-
import { ReactComponent as IconLoopNone } from "../assets/loop-none.svg"
10-
import { formatAudioDuration } from "../utils/formatAudioDuration"
11-
import { ProgressBar } from "./progress"
12-
import React, { useCallback } from "react"
13-
import { PlaylistLoop, PlaylistOrder } from "../hooks/usePlaylist"
1+
import { ReactComponent as IconVolumeUp } from "../assets/volume-up.svg";
2+
import { ReactComponent as IconVolumeDown } from "../assets/volume-down.svg";
3+
import { ReactComponent as IconVolumeOff } from "../assets/volume-off.svg";
4+
import { ReactComponent as IconMenu } from "../assets/menu.svg";
5+
import { ReactComponent as IconOrderList } from "../assets/order-list.svg";
6+
import { ReactComponent as IconOrderRandom } from "../assets/order-random.svg";
7+
import { ReactComponent as IconLoopAll } from "../assets/loop-all.svg";
8+
import { ReactComponent as IconLoopOne } from "../assets/loop-one.svg";
9+
import { ReactComponent as IconLoopNone } from "../assets/loop-none.svg";
10+
import { formatAudioDuration } from "../utils/formatAudioDuration";
11+
import { ProgressBar } from "./progress";
12+
import React, { useCallback } from "react";
13+
import { PlaylistLoop, PlaylistOrder } from "../hooks/usePlaylist";
1414

1515
type PlaybackControlsProps = {
16-
themeColor: string
17-
volume: number
18-
onChangeVolume: (volume: number) => void
19-
muted: boolean
20-
currentTime: number | undefined
21-
audioDurationSeconds: number | undefined
22-
bufferedSeconds: number | undefined
23-
onSeek?: (second: number) => void
24-
onToggleMenu?: () => void
25-
onToggleMuted: () => void
26-
order: PlaylistOrder
27-
onOrderChange: (order: PlaylistOrder) => void
28-
loop: PlaylistLoop
29-
onLoopChange: (loop: PlaylistLoop) => void
30-
}
16+
themeColor: string;
17+
volume: number;
18+
onChangeVolume: (volume: number) => void;
19+
muted: boolean;
20+
currentTime: number | undefined;
21+
audioDurationSeconds: number | undefined;
22+
bufferedSeconds: number | undefined;
23+
onSeek?: (second: number) => void;
24+
onToggleMenu?: () => void;
25+
onToggleMuted: () => void;
26+
order: PlaylistOrder;
27+
onOrderChange: (order: PlaylistOrder) => void;
28+
loop: PlaylistLoop;
29+
onLoopChange: (loop: PlaylistLoop) => void;
30+
};
3131

3232
export function PlaybackControls({
3333
themeColor,
@@ -47,21 +47,18 @@ export function PlaybackControls({
4747
}: PlaybackControlsProps) {
4848
const handleVolumeBarMouseDown = useCallback(
4949
(e: React.MouseEvent<HTMLDivElement>) => {
50-
const volumeBarElement = e.currentTarget
51-
const volumeBarRect = volumeBarElement.getBoundingClientRect()
50+
const volumeBarElement = e.currentTarget;
51+
const volumeBarRect = volumeBarElement.getBoundingClientRect();
5252

5353
onChangeVolume(
5454
Math.min(
5555
1,
56-
Math.max(
57-
0,
58-
(volumeBarRect.bottom - e.clientY) / volumeBarRect.height,
59-
),
60-
),
61-
)
56+
Math.max(0, (volumeBarRect.bottom - e.clientY) / volumeBarRect.height)
57+
)
58+
);
6259
},
63-
[onChangeVolume],
64-
)
60+
[onChangeVolume]
61+
);
6562

6663
// Switch order between "list" and "random"
6764
const handleOrderButtonClick = useCallback(() => {
@@ -70,10 +67,10 @@ export function PlaybackControls({
7067
list: "random",
7168
random: "list",
7269
} as const
73-
)[order]
70+
)[order];
7471

75-
onOrderChange(nextOrder)
76-
}, [order, onOrderChange])
72+
onOrderChange(nextOrder);
73+
}, [order, onOrderChange]);
7774

7875
// Transition of loop: all -> one -> none
7976
const handleLoopButtonClick = useCallback(() => {
@@ -83,10 +80,10 @@ export function PlaybackControls({
8380
one: "none",
8481
none: "all",
8582
} as const
86-
)[loop]
83+
)[loop];
8784

88-
onLoopChange(nextLoop)
89-
}, [loop, onLoopChange])
85+
onLoopChange(nextLoop);
86+
}, [loop, onLoopChange]);
9087
return (
9188
<div className="aplayer-controller">
9289
<ProgressBar
@@ -163,5 +160,5 @@ export function PlaybackControls({
163160
<button className="aplayer-icon aplayer-icon-lrc"></button>
164161
</div>
165162
</div>
166-
)
163+
);
167164
}

src/components/list.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import cx from "clsx"
2-
import { defaultThemeColor } from "../constants"
3-
import type { AudioInfo } from "../types"
1+
import cx from "clsx";
2+
import { defaultThemeColor } from "../constants";
3+
import type { AudioInfo } from "../types";
44

55
type PlaylistProps = {
6-
open: boolean
7-
audio: AudioInfo[]
8-
playingAudioUrl?: string
9-
onPlayAudio?: (audio: AudioInfo) => void
10-
}
6+
open: boolean;
7+
audio: AudioInfo[];
8+
playingAudioUrl?: string;
9+
onPlayAudio?: (audio: AudioInfo) => void;
10+
};
1111

1212
export function Playlist({
1313
open,
@@ -30,7 +30,7 @@ export function Playlist({
3030
})}
3131
onClick={() => {
3232
if (audioInfo.url !== playingAudioUrl) {
33-
onPlayAudio?.(audioInfo)
33+
onPlayAudio?.(audioInfo);
3434
}
3535
}}
3636
>
@@ -51,5 +51,5 @@ export function Playlist({
5151
))}
5252
</ol>
5353
</div>
54-
)
54+
);
5555
}

src/components/player.tsx

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
import { useEffect, useState } from "react"
2-
import cx from "clsx"
1+
import { useEffect, useState } from "react";
2+
import cx from "clsx";
33

4-
import { ReactComponent as IconPlay } from "../assets/play.svg"
5-
import { ReactComponent as IconPause } from "../assets/pause.svg"
6-
import type { AudioInfo } from "../types"
7-
import { Playlist } from "./list"
8-
import { PlaybackControls } from "./controller"
9-
import { useAudioControl } from "../hooks/useAudioControl"
10-
import { defaultThemeColor } from "../constants"
11-
import { PlaylistLoop, PlaylistOrder, usePlaylist } from "../hooks/usePlaylist"
4+
import { ReactComponent as IconPlay } from "../assets/play.svg";
5+
import { ReactComponent as IconPause } from "../assets/pause.svg";
6+
import type { AudioInfo } from "../types";
7+
import { Playlist } from "./list";
8+
import { PlaybackControls } from "./controller";
9+
import { useAudioControl } from "../hooks/useAudioControl";
10+
import { defaultThemeColor } from "../constants";
11+
import { PlaylistLoop, PlaylistOrder, usePlaylist } from "../hooks/usePlaylist";
1212

1313
/**
1414
* @see https://aplayer.js.org/#/home?id=options
1515
*/
1616
type APlayerProps = {
17-
audio: AudioInfo | AudioInfo[]
17+
audio: AudioInfo | AudioInfo[];
1818

19-
theme?: string
19+
theme?: string;
2020

2121
/**
2222
* Initial volume
2323
*
2424
* @default 0.7
2525
*/
26-
volume?: number
26+
volume?: number;
2727

2828
/**
2929
* @default "all"
3030
*/
31-
initialLoop?: PlaylistLoop
31+
initialLoop?: PlaylistLoop;
3232

3333
/**
3434
* @default "list"
3535
*/
36-
initialOrder?: PlaylistOrder
36+
initialOrder?: PlaylistOrder;
3737

38-
autoplay?: boolean
39-
}
38+
autoplay?: boolean;
39+
};
4040

4141
export function APlayer({
4242
theme = defaultThemeColor,
@@ -49,31 +49,31 @@ export function APlayer({
4949
initialLoop,
5050
initialOrder,
5151
getSongId: (song) => song.url,
52-
})
52+
});
5353

5454
const audioControl = useAudioControl({
5555
initialVolume: volume,
5656
onError() {
5757
if (playlist.hasNextSong) {
58-
playlist.next()
58+
playlist.next();
5959
}
6060
},
6161
onEnded() {
6262
if (playlist.hasNextSong) {
63-
playlist.next()
63+
playlist.next();
6464
}
6565
},
66-
})
66+
});
6767

6868
useEffect(() => {
6969
if (playlist.currentSong) {
70-
audioControl.playAudio(playlist.currentSong.url)
70+
audioControl.playAudio(playlist.currentSong.url);
7171
}
72-
}, [playlist.currentSong, audioControl])
72+
}, [playlist.currentSong, audioControl]);
7373

74-
const hasPlaylist = Array.isArray(audio)
74+
const hasPlaylist = Array.isArray(audio);
7575

76-
const [isPlaylistOpen, setPlaylistOpen] = useState(() => hasPlaylist)
76+
const [isPlaylistOpen, setPlaylistOpen] = useState(() => hasPlaylist);
7777

7878
return (
7979
<div style={{ width: 600 }}>
@@ -93,7 +93,7 @@ export function APlayer({
9393
<div
9494
className={cx(
9595
"aplayer-button",
96-
audioControl.isPlaying ? "aplayer-pause" : "aplayer-play",
96+
audioControl.isPlaying ? "aplayer-pause" : "aplayer-play"
9797
)}
9898
onClick={() => audioControl.togglePlay()}
9999
>
@@ -143,5 +143,5 @@ export function APlayer({
143143
) : null}
144144
</div>
145145
</div>
146-
)
146+
);
147147
}

0 commit comments

Comments
 (0)