2022-10-30 23:13:57 +00:00
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
|
|
export class VolumeManager {
|
2024-04-23 21:01:27 +00:00
|
|
|
public volume = ref(0)
|
2022-10-30 23:13:57 +00:00
|
|
|
private input!: HTMLInputElement
|
2024-03-18 17:51:51 +00:00
|
|
|
private originalVolume = 0
|
2022-10-30 23:13:57 +00:00
|
|
|
|
2024-03-18 17:51:51 +00:00
|
|
|
public init (input: HTMLInputElement, initialVolume: number) {
|
2022-10-30 23:13:57 +00:00
|
|
|
this.input = input
|
2024-03-18 17:51:51 +00:00
|
|
|
this.originalVolume = initialVolume
|
|
|
|
this.set(initialVolume)
|
2022-10-30 23:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public get () {
|
|
|
|
return this.volume.value
|
|
|
|
}
|
|
|
|
|
2024-01-23 22:50:50 +00:00
|
|
|
public set (volume: number) {
|
2022-10-30 23:13:57 +00:00
|
|
|
this.volume.value = volume
|
|
|
|
this.input.value = String(volume)
|
|
|
|
}
|
|
|
|
|
|
|
|
public mute () {
|
2024-03-18 17:51:51 +00:00
|
|
|
this.originalVolume = this.get()
|
2024-01-23 22:50:50 +00:00
|
|
|
this.set(0)
|
2022-10-30 23:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public unmute () {
|
2024-03-18 17:51:51 +00:00
|
|
|
this.set(this.originalVolume)
|
|
|
|
}
|
|
|
|
|
|
|
|
public toggleMute () {
|
|
|
|
if (this.get() === 0) {
|
|
|
|
this.unmute()
|
|
|
|
} else {
|
|
|
|
this.mute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public increase (amount = 1) {
|
|
|
|
this.set(Math.min(10, this.get() + amount))
|
|
|
|
}
|
|
|
|
|
|
|
|
public decrease (amount = 1) {
|
|
|
|
this.set(Math.max(this.get() - amount, 0))
|
2022-10-30 23:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const volumeManager = new VolumeManager()
|