2021-08-21 01:29:10 +02:00
|
|
|
<template>
|
2022-06-19 17:04:15 +02:00
|
|
|
<div ref="wrapper" class="relative ml-4 sm:ml-8" v-click-outside="clickOutside">
|
2021-11-27 23:38:29 +01:00
|
|
|
<div class="flex items-center justify-center text-gray-300 cursor-pointer h-full" @mousedown.prevent @mouseup.prevent @click="setShowMenu(true)">
|
2024-09-25 23:49:24 +02:00
|
|
|
<span class="text-gray-200 text-sm sm:text-base">{{ playbackRate.toFixed(1) }}<span class="text-base">x</span></span>
|
2021-08-21 01:29:10 +02:00
|
|
|
</div>
|
2024-09-25 23:49:24 +02:00
|
|
|
<div v-show="showMenu" class="absolute -top-[5.5rem] z-20 bg-bg border-black-200 border shadow-xl rounded-lg" :style="{ left: menuLeft + 'px' }">
|
2022-06-19 17:04:15 +02:00
|
|
|
<div class="absolute -bottom-1.5 right-0 w-full flex justify-center" :style="{ left: arrowLeft + 'px' }">
|
2021-08-21 01:29:10 +02:00
|
|
|
<div class="arrow-down" />
|
|
|
|
</div>
|
2021-11-27 23:38:29 +01:00
|
|
|
<div class="flex items-center h-9 relative overflow-hidden rounded-lg" style="width: 220px">
|
|
|
|
<template v-for="rate in rates">
|
|
|
|
<div :key="rate" class="h-full border-black-300 w-11 cursor-pointer border rounded-sm" :class="value === rate ? 'bg-black-100' : 'hover:bg-black hover:bg-opacity-10'" style="min-width: 44px; max-width: 44px" @click="set(rate)">
|
|
|
|
<div class="w-full h-full flex justify-center items-center">
|
2024-09-25 23:49:24 +02:00
|
|
|
<p class="text-xs text-center">{{ rate }}<span class="text-sm">x</span></p>
|
2021-11-27 23:38:29 +01:00
|
|
|
</div>
|
2021-08-21 01:29:10 +02:00
|
|
|
</div>
|
2021-11-27 23:38:29 +01:00
|
|
|
</template>
|
|
|
|
</div>
|
2024-09-25 23:49:24 +02:00
|
|
|
<div class="w-full py-1 px-1">
|
2021-11-27 23:38:29 +01:00
|
|
|
<div class="flex items-center justify-between">
|
|
|
|
<ui-icon-btn :disabled="!canDecrement" icon="remove" @click="decrement" />
|
2023-02-17 01:01:25 +01:00
|
|
|
<p class="px-2 text-2xl sm:text-3xl">{{ playbackRate }}<span class="text-2xl">x</span></p>
|
2021-11-27 23:38:29 +01:00
|
|
|
<ui-icon-btn :disabled="!canIncrement" icon="add" @click="increment" />
|
2021-08-24 01:31:04 +02:00
|
|
|
</div>
|
2021-08-21 01:29:10 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: [String, Number],
|
|
|
|
default: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-08-24 01:31:04 +02:00
|
|
|
showMenu: false,
|
2021-11-27 23:38:29 +01:00
|
|
|
currentPlaybackRate: 0,
|
|
|
|
MIN_SPEED: 0.5,
|
2023-01-07 23:18:52 +01:00
|
|
|
MAX_SPEED: 10,
|
2024-09-25 23:49:24 +02:00
|
|
|
menuLeft: -96,
|
2022-06-19 17:04:15 +02:00
|
|
|
arrowLeft: 0
|
2021-08-21 01:29:10 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
playbackRate: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rates() {
|
2021-11-27 23:38:29 +01:00
|
|
|
return [0.5, 1, 1.2, 1.5, 2]
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
2021-11-27 23:38:29 +01:00
|
|
|
canIncrement() {
|
|
|
|
return this.playbackRate + 0.1 <= this.MAX_SPEED
|
|
|
|
},
|
|
|
|
canDecrement() {
|
|
|
|
return this.playbackRate - 0.1 >= this.MIN_SPEED
|
2021-08-21 01:29:10 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickOutside() {
|
2021-11-27 23:38:29 +01:00
|
|
|
this.setShowMenu(false)
|
2021-08-21 01:29:10 +02:00
|
|
|
},
|
|
|
|
set(rate) {
|
2021-11-27 23:38:29 +01:00
|
|
|
this.playbackRate = Number(rate)
|
|
|
|
this.$nextTick(() => this.setShowMenu(false))
|
|
|
|
},
|
|
|
|
increment() {
|
|
|
|
if (this.playbackRate + 0.1 > this.MAX_SPEED) return
|
|
|
|
var newPlaybackRate = this.playbackRate + 0.1
|
|
|
|
this.playbackRate = Number(newPlaybackRate.toFixed(1))
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
2021-11-27 23:38:29 +01:00
|
|
|
decrement() {
|
|
|
|
if (this.playbackRate - 0.1 < this.MIN_SPEED) return
|
|
|
|
var newPlaybackRate = this.playbackRate - 0.1
|
|
|
|
this.playbackRate = Number(newPlaybackRate.toFixed(1))
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
2022-06-19 17:04:15 +02:00
|
|
|
updateMenuPositions() {
|
|
|
|
if (!this.$refs.wrapper) return
|
|
|
|
const boundingBox = this.$refs.wrapper.getBoundingClientRect()
|
|
|
|
|
|
|
|
if (boundingBox.left + 110 > window.innerWidth - 10) {
|
|
|
|
this.menuLeft = window.innerWidth - 230 - boundingBox.left
|
|
|
|
|
2024-09-25 23:49:24 +02:00
|
|
|
this.arrowLeft = Math.abs(this.menuLeft) - 96
|
2022-06-19 17:04:15 +02:00
|
|
|
} else {
|
2024-09-25 23:49:24 +02:00
|
|
|
this.menuLeft = -96
|
2022-06-19 17:04:15 +02:00
|
|
|
this.arrowLeft = 0
|
|
|
|
}
|
|
|
|
},
|
2021-11-27 23:38:29 +01:00
|
|
|
setShowMenu(val) {
|
|
|
|
if (val) {
|
2022-06-19 17:04:15 +02:00
|
|
|
this.updateMenuPositions()
|
2021-11-27 23:38:29 +01:00
|
|
|
this.currentPlaybackRate = this.playbackRate
|
|
|
|
} else if (this.currentPlaybackRate !== this.playbackRate) {
|
|
|
|
this.$emit('change', this.playbackRate)
|
|
|
|
}
|
|
|
|
this.showMenu = val
|
2021-08-21 01:29:10 +02:00
|
|
|
}
|
|
|
|
},
|
2022-02-15 21:38:06 +01:00
|
|
|
mounted() {
|
|
|
|
this.currentPlaybackRate = this.playbackRate
|
|
|
|
}
|
2021-08-21 01:29:10 +02:00
|
|
|
}
|
2024-09-25 23:49:24 +02:00
|
|
|
</script>
|