Line data Source code
1 13 : <template>
2 : <div
3 : v-if="animations && animations.length > 0"
4 : class="pointer-events-auto absolute top-0 left-0 z-10 flex w-full flex-col items-center gap-2 pt-2"
5 : >
6 : <div class="flex items-center justify-center gap-2">
7 : <Button
8 : size="icon"
9 : variant="textonly"
10 : class="rounded-full"
11 : :aria-label="$t('g.playPause')"
12 : @click="togglePlay"
13 : >
14 : <i
15 : :class="
16 : cn(
17 : 'size-4.5 text-foreground',
18 : playing ? 'icon-[lucide--pause]' : 'icon-[lucide--play]'
19 : )
20 : "
21 : />
22 : </Button>
23 :
24 : <Select
25 : :model-value="selectedSpeed != null ? String(selectedSpeed) : undefined"
26 : @update:model-value="(val) => (selectedSpeed = Number(val))"
27 : >
28 : <SelectTrigger size="md" class="w-24">
29 : <SelectValue />
30 : </SelectTrigger>
31 : <SelectContent>
32 0 : <SelectItem
33 : v-for="opt in speedOptions"
34 : :key="opt.value"
35 : :value="String(opt.value)"
36 : >
37 : {{ opt.name }}
38 : </SelectItem>
39 : </SelectContent>
40 : </Select>
41 :
42 : <Select
43 : :model-value="
44 : selectedAnimation != null ? String(selectedAnimation) : undefined
45 : "
46 : @update:model-value="(val) => (selectedAnimation = Number(val))"
47 : >
48 : <SelectTrigger size="md" class="w-32">
49 : <SelectValue />
50 : </SelectTrigger>
51 : <SelectContent>
52 0 : <SelectItem
53 : v-for="anim in animations"
54 : :key="anim.index"
55 : :value="String(anim.index)"
56 : >
57 : {{ anim.name }}
58 : </SelectItem>
59 : </SelectContent>
60 : </Select>
61 : </div>
62 :
63 : <div class="flex w-full max-w-xs items-center gap-2 px-4">
64 : <Slider
65 : :model-value="[animationProgress]"
66 : :min="0"
67 : :max="100"
68 : :step="0.1"
69 : class="flex-1"
70 : @update:model-value="handleSliderChange"
71 : />
72 : <span class="min-w-16 text-xs text-foreground">
73 : {{ formatAnimationTime(currentTime) }} /
74 : {{ formatAnimationTime(animationDuration) }}
75 : </span>
76 : </div>
77 : </div>
78 : </template>
79 :
80 : <script setup lang="ts">
81 : import { cn } from '@comfyorg/tailwind-utils'
82 : import { computed } from 'vue'
83 :
84 : import { formatAnimationTime } from '@/extensions/core/load3d/components/formatAnimationTime'
85 : import Button from '@comfyorg/design-system/button/Button'
86 : import Select from '@comfyorg/design-system/select/Select'
87 : import SelectContent from '@comfyorg/design-system/select/SelectContent'
88 : import SelectItem from '@comfyorg/design-system/select/SelectItem'
89 : import SelectTrigger from '@comfyorg/design-system/select/SelectTrigger'
90 : import SelectValue from '@comfyorg/design-system/select/SelectValue'
91 : import Slider from '@comfyorg/design-system/slider/Slider'
92 :
93 : type Animation = { name: string; index: number }
94 :
95 0 : const animations = defineModel<Animation[]>('animations')
96 0 : const playing = defineModel<boolean>('playing')
97 0 : const selectedSpeed = defineModel<number>('selectedSpeed')
98 0 : const selectedAnimation = defineModel<number>('selectedAnimation')
99 0 : const animationProgress = defineModel<number>('animationProgress', {
100 : default: 0
101 : })
102 0 : const animationDuration = defineModel<number>('animationDuration', {
103 : default: 0
104 : })
105 :
106 0 : const emit = defineEmits<{
107 : seek: [progress: number]
108 : }>()
109 :
110 0 : const speedOptions = [
111 : { name: '0.1x', value: 0.1 },
112 : { name: '0.5x', value: 0.5 },
113 : { name: '1x', value: 1 },
114 : { name: '1.5x', value: 1.5 },
115 : { name: '2x', value: 2 }
116 : ]
117 :
118 0 : const currentTime = computed(() => {
119 0 : if (!animationDuration.value) return 0
120 0 : return (animationProgress.value / 100) * animationDuration.value
121 : })
122 :
123 0 : function togglePlay() {
124 0 : playing.value = !playing.value
125 : }
126 :
127 0 : function handleSliderChange(value: number[] | undefined) {
128 0 : if (!value) return
129 0 : const progress = value[0]
130 0 : animationProgress.value = progress
131 0 : emit('seek', progress)
132 : }
133 : </script>
|