1- <template >
2- <div
3- class =" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
4- :class =" {
5- 'recordingAnimation1' : showAnimation,
6- 'h-2': !isRecording,
7- 'h-1': isRecording,
8- }"
1+ <template >
2+ <div
3+ v-for =" (height, index) in lineHeights"
4+ :key =" index"
5+ class =" bg-white w-[0.2rem] rounded-sm transition-all duration-100 ease-out"
6+ :style =" { height }"
97 />
10- <div
11- class =" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
12- :class =" {
13- 'recordingAnimation2' : showAnimation,
14- 'h-4': !isRecording,
15- 'h-1': isRecording,
16- }"
17- />
18- <div
19- class =" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
20- :class =" {
21- 'recordingAnimation3' : showAnimation,
22- 'h-3': !isRecording,
23- 'h-1': isRecording,
24- }"
25- />
26- <div
27- class =" bg-white w-[0.2rem] rounded-sm transition-all duration-300 ease-in-out"
28- :class =" {
29- 'recordingAnimation4' : showAnimation,
30- 'h-2': !isRecording,
31- 'h-1': isRecording,
32- }"
33- />
34- <template v-if =" isRecording " >
35- <div
36- class =" bg-white w-[0.2rem] rounded-sm h-1 transition-all duration-300 ease-in-out"
37- :class =" {
38- 'recordingAnimation5' : showAnimation,
39- }"
40- />
41- <p class =" text-white ml-2" >End</p >
42- </template >
8+ <p v-if =" isRecording" class =" text-white ml-2" >End</p >
439</template >
4410
45-
46-
4711<script setup lang="ts">
12+ import { computed } from ' vue' ;
13+
14+ const IDLE_LINE_HEIGHTS = [0.5 , 1 , 0.75 , 0.5 ];
15+ const RECORDING_LINE_WEIGHTS = [0.45 , 1 , 0.75 , 0.9 , 0.55 ];
16+ const MIN_RECORDING_HEIGHT = 0.25 ;
17+ const MAX_RECORDING_DELTA = 0.9 ;
4818
4919const props = defineProps <{
5020 showAnimation: boolean ;
5121 isRecording: boolean ;
22+ amplitude: number ;
5223}>();
5324
54- </script >
55-
56- <style scoped lang="scss">
57- .recordingAnimation1 {
58- animation : recordingAnimation 1s infinite ;
59- height : 0.3rem ;
60- }
61-
62- .recordingAnimation2 {
63- animation : recordingAnimation 1s infinite ;
64- animation-delay : 0.2s ;
65- height : 0.5rem ;
25+ const normalizedAmplitude = computed (() => {
26+ if (! props .isRecording || ! props .showAnimation ) {
27+ return 0 ;
6628 }
6729
68- .recordingAnimation3 {
69- animation : recordingAnimation 1s infinite ;
70- animation-delay : 0.4s ;
71- height : 0.4rem ;
72- }
73-
74- .recordingAnimation4 {
75- animation : recordingAnimation 1s infinite ;
76- animation-delay : 0.6s ;
77- height : 0.5rem ;
78- }
30+ return Math .min (Math .max (props .amplitude , 0 ), 1 );
31+ });
7932
80- .recordingAnimation5 {
81- animation : recordingAnimation 1s infinite ;
82- animation-delay : 0.8s ;
83- height : 0.3rem ;
33+ const lineHeights = computed (() => {
34+ if (! props .isRecording ) {
35+ return IDLE_LINE_HEIGHTS .map ((height ) => ` ${height }rem ` );
8436 }
8537
86- @keyframes recordingAnimation {
87- 0% {
88- transform : scaleY (1 );
89- }
90- 50% {
91- transform : scaleY (2 );
92- }
93- 100% {
94- transform : scaleY (1 );
95- }
96- }
97- </style >
38+ return RECORDING_LINE_WEIGHTS .map ((weight ) => {
39+ const height = MIN_RECORDING_HEIGHT + normalizedAmplitude .value * MAX_RECORDING_DELTA * weight ;
40+ return ` ${height }rem ` ;
41+ });
42+ });
43+ </script >
0 commit comments