Skip to content

Commit 02562e7

Browse files
committed
feat: add Ban interaction feature
1 parent 0f54f32 commit 02562e7

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

example/src/components/Demo.vue

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<script setup lang="ts">
2-
import { onMounted, reactive, ref, watchEffect, defineProps } from "vue"
3-
import type { Ref } from "vue"
4-
import { IllestWaveform } from "1llest-waveform-vue"
5-
import type { IllestWaveformProps } from "1llest-waveform-vue"
6-
import "1llest-waveform-vue/dist/style.css"
7-
import PlayIcon from "./icons/Play.vue"
8-
import PauseIcon from "./icons/Pause.vue"
9-
import ReplayIcon from "./icons/Replay.vue"
10-
11-
const { props } = defineProps(["props"])
2+
import { onMounted, reactive, ref, watchEffect, defineProps } from 'vue'
3+
import type { Ref } from 'vue'
4+
// import { IllestWaveform } from '1llest-waveform-vue'
5+
import IllestWaveform from '../../../src/components/IllestWaveform.vue'
6+
import type { IllestWaveformProps } from '1llest-waveform-vue'
7+
import '1llest-waveform-vue/dist/style.css'
8+
import PlayIcon from './icons/Play.vue'
9+
import PauseIcon from './icons/Pause.vue'
10+
import ReplayIcon from './icons/Replay.vue'
11+
12+
const { props } = defineProps(['props'])
1213
1314
const waveOptions = reactive<IllestWaveformProps>({
1415
url: props.url,
@@ -24,8 +25,8 @@ const init = ref(false)
2425
const playing = ref(false)
2526
const finished = ref(false)
2627
const ready = ref(false)
27-
const currentTime = ref("0:00")
28-
const durationTime = ref("0:00")
28+
const currentTime = ref('0:00')
29+
const durationTime = ref('0:00')
2930
3031
const initHandler = (v: boolean) => {
3132
init.value = v
@@ -92,24 +93,24 @@ const getDuration = () => {
9293

9394
<div class="ml-5">
9495
<button
95-
@click="play"
96-
class="btn text-[#3e6bff]"
9796
v-show="!playing && !finished"
97+
class="btn text-[#3e6bff]"
98+
@click="play"
9899
>
99100
<PlayIcon />
100101
<div class="ml-2">PLAY</div>
101102
</button>
102103

103104
<button
104-
@click="pause"
105-
class="btn text-yellow-500"
106105
v-show="playing && !finished"
106+
class="btn text-yellow-500"
107+
@click="pause"
107108
>
108109
<PauseIcon />
109110
<div>PAUSE</div>
110111
</button>
111112

112-
<button @click="replay" class="btn text-green-500" v-show="finished">
113+
<button v-show="finished" class="btn text-green-500" @click="replay">
113114
<ReplayIcon />
114115
<div>REPLAY</div>
115116
</button>

src/components/IllestWaveform.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type IllestWaveformProps = {
2424
lazy?: boolean
2525
skeleton?: boolean
2626
skeletonColor?: string
27+
interact?: boolean
2728
}
2829
2930
const props = withDefaults(defineProps<IllestWaveformProps>(), {
@@ -37,6 +38,7 @@ const props = withDefaults(defineProps<IllestWaveformProps>(), {
3738
lazy: true,
3839
skeleton: true,
3940
skeletonColor: '#232323',
41+
interact: true,
4042
})
4143
4244
// Render trigger can control the render time
@@ -135,12 +137,12 @@ function drawWaveMask(): void | undefined {
135137
}
136138
137139
function mouseMoveHandler(e: any): void {
138-
if (!ready.value) return
140+
if (!ready.value || !props.interact) return
139141
moveX.value = e.layerX
140142
}
141143
142144
function clickHandler(): void {
143-
if (!ready.value) return
145+
if (!ready.value || !props.interact) return
144146
maskWidth.value = moveX.value
145147
const pickedTime: number =
146148
(moveX.value / wave._canvas.width) * webAudioController._audioDuration
@@ -213,7 +215,6 @@ defineExpose({
213215
<section
214216
id="ill-wave-container"
215217
ref="waveformContainer"
216-
:style="`${!ready ? 'cursor: progress;' : 'cursor: pointer'}`"
217218
@mousemove="mouseMoveHandler"
218219
@click="clickHandler"
219220
>
@@ -238,7 +239,7 @@ defineExpose({
238239
</div>
239240

240241
<div
241-
v-show="ready"
242+
v-show="ready && props.interact"
242243
id="ill-cursor"
243244
:style="`width:${props.cursorWidth}px; transform: translateX(${moveX}px);background-color: ${props.cursorColor}; `"
244245
/>
@@ -302,6 +303,7 @@ defineExpose({
302303
top: 0px;
303304
opacity: 0;
304305
transition: opacity 0.2s ease-in-out;
306+
cursor: pointer;
305307
}
306308
307309
#ill-wave-container:hover #ill-cursor {

src/types/waveform.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export type IllestWaveformProps = {
1010
lazy?: boolean
1111
skeleton?: boolean
1212
skeletonColor?: string
13+
interact?: boolean
1314
}

0 commit comments

Comments
 (0)