Skip to content

Commit 82245cf

Browse files
thetarnavgithub-actions[bot]
authored andcommitted
Format
1 parent cda0286 commit 82245cf

File tree

3 files changed

+73
-24
lines changed

3 files changed

+73
-24
lines changed

packages/audio/dev/index.tsx

+52-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,63 @@ import { createAudio, AudioState } from "../src/index.js";
55
// import { play, pause } from "solid-heroicons/solid";
66
// import { speakerWave } from "solid-heroicons/outline";
77

8-
type IconPath = {path: () => JSX.Element; outline?: boolean; mini?: boolean}
9-
type IconProps = JSX.SvgSVGAttributes<SVGSVGElement> & {path: IconPath}
8+
type IconPath = { path: () => JSX.Element; outline?: boolean; mini?: boolean };
9+
type IconProps = JSX.SvgSVGAttributes<SVGSVGElement> & { path: IconPath };
1010

1111
const Icon = (props: IconProps) => {
1212
const [internal, external] = splitProps(props, ["path"]);
13-
return (<svg viewBox={internal.path.mini ? "0 0 20 20" : "0 0 24 24"} fill={internal.path.outline ? "none" : "currentColor"} stroke={internal.path.outline ? "currentColor" : "none"} stroke-width={internal.path.outline ? 1.5 : undefined} {...external}>
14-
{internal.path.path()}
15-
</svg>);
13+
return (
14+
<svg
15+
viewBox={internal.path.mini ? "0 0 20 20" : "0 0 24 24"}
16+
fill={internal.path.outline ? "none" : "currentColor"}
17+
stroke={internal.path.outline ? "currentColor" : "none"}
18+
stroke-width={internal.path.outline ? 1.5 : undefined}
19+
{...external}
20+
>
21+
{internal.path.path()}
22+
</svg>
23+
);
1624
};
1725

18-
const play: IconPath = { path: () => <><path fill-rule="evenodd" d="M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z" clip-rule="evenodd"/></>, outline: false, mini: false };
19-
const pause: IconPath = { path: () => <><path fill-rule="evenodd" d="M6.75 5.25a.75.75 0 01.75-.75H9a.75.75 0 01.75.75v13.5a.75.75 0 01-.75.75H7.5a.75.75 0 01-.75-.75V5.25zm7.5 0A.75.75 0 0115 4.5h1.5a.75.75 0 01.75.75v13.5a.75.75 0 01-.75.75H15a.75.75 0 01-.75-.75V5.25z" clip-rule="evenodd"/></>, outline: false, mini: false };
20-
const speakerWave: IconPath = { path: () => <><path stroke-linecap="round" stroke-linejoin="round" d="M19.114 5.636a9 9 0 010 12.728M16.463 8.288a5.25 5.25 0 010 7.424M6.75 8.25l4.72-4.72a.75.75 0 011.28.53v15.88a.75.75 0 01-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.01 9.01 0 012.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75z"/></>, outline: true, mini: false };
26+
const play: IconPath = {
27+
path: () => (
28+
<>
29+
<path
30+
fill-rule="evenodd"
31+
d="M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z"
32+
clip-rule="evenodd"
33+
/>
34+
</>
35+
),
36+
outline: false,
37+
mini: false,
38+
};
39+
const pause: IconPath = {
40+
path: () => (
41+
<>
42+
<path
43+
fill-rule="evenodd"
44+
d="M6.75 5.25a.75.75 0 01.75-.75H9a.75.75 0 01.75.75v13.5a.75.75 0 01-.75.75H7.5a.75.75 0 01-.75-.75V5.25zm7.5 0A.75.75 0 0115 4.5h1.5a.75.75 0 01.75.75v13.5a.75.75 0 01-.75.75H15a.75.75 0 01-.75-.75V5.25z"
45+
clip-rule="evenodd"
46+
/>
47+
</>
48+
),
49+
outline: false,
50+
mini: false,
51+
};
52+
const speakerWave: IconPath = {
53+
path: () => (
54+
<>
55+
<path
56+
stroke-linecap="round"
57+
stroke-linejoin="round"
58+
d="M19.114 5.636a9 9 0 010 12.728M16.463 8.288a5.25 5.25 0 010 7.424M6.75 8.25l4.72-4.72a.75.75 0 011.28.53v15.88a.75.75 0 01-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.01 9.01 0 012.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75z"
59+
/>
60+
</>
61+
),
62+
outline: true,
63+
mini: false,
64+
};
2165

2266
const formatTime = (time: number) => new Date(time * 1000).toISOString().substr(14, 8);
2367

packages/audio/src/index.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export type AudioEventHandlers = {
2828
// Helper for producing the audio source
2929
const unwrapSource = (src: AudioSource) => {
3030
if (src instanceof HTMLAudioElement) {
31-
return src
31+
return src;
3232
}
3333
const player = new Audio();
34-
setAudioSrc(player, src)
35-
return player
34+
setAudioSrc(player, src);
35+
return player;
3636
};
3737

3838
function setAudioSrc(el: HTMLAudioElement, src: AudioSource) {
@@ -58,15 +58,15 @@ export const makeAudio = (
5858

5959
onMount(() => {
6060
for (const [name, handler] of Object.entries(handlers)) {
61-
player.addEventListener(name, handler as any)
61+
player.addEventListener(name, handler as any);
6262
}
6363
});
6464
onCleanup(() => {
6565
player.pause();
6666
for (const [name, handler] of Object.entries(handlers)) {
67-
player.removeEventListener(name, handler as any)
67+
player.removeEventListener(name, handler as any);
6868
}
69-
})
69+
});
7070

7171
return player;
7272
};
@@ -194,7 +194,12 @@ export const createAudio = (
194194
volume: 0,
195195
});
196196

197-
const { play, pause, setVolume: _setVolume, seek } = makeAudioPlayer(store.player, {
197+
const {
198+
play,
199+
pause,
200+
setVolume: _setVolume,
201+
seek,
202+
} = makeAudioPlayer(store.player, {
198203
loadeddata: () => {
199204
setStore({
200205
state: AudioState.READY,
@@ -217,9 +222,9 @@ export const createAudio = (
217222
});
218223

219224
const setVolume = (volume: number) => {
220-
setStore("volume", volume)
221-
_setVolume(volume)
222-
}
225+
setStore("volume", volume);
226+
_setVolume(volume);
227+
};
223228

224229
// Bind reactive properties as needed
225230
if (src instanceof Function) {
@@ -228,7 +233,7 @@ export const createAudio = (
228233
if (newSrc instanceof HTMLAudioElement) {
229234
setStore("player", newSrc);
230235
} else {
231-
setAudioSrc(store.player, newSrc)
236+
setAudioSrc(store.player, newSrc);
232237
}
233238
seek(0);
234239
});

packages/audio/test/index.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ describe("createAudio", () => {
7474
}));
7575

7676
it("should set the COMPLETE state when audio ends", () => {
77-
const [[audio], dispose] = createRoot(dispose => [createAudio({} as MediaSource), dispose])
78-
expect(audio.state).toBe(AudioState.LOADING)
77+
const [[audio], dispose] = createRoot(dispose => [createAudio({} as MediaSource), dispose]);
78+
expect(audio.state).toBe(AudioState.LOADING);
7979

8080
audio.player.dispatchEvent(new Event("ended"));
81-
expect(audio.state).toBe(AudioState.COMPLETE)
81+
expect(audio.state).toBe(AudioState.COMPLETE);
8282

8383
dispose();
84-
})
85-
});
84+
});
85+
});

0 commit comments

Comments
 (0)