@meistrari/tela-build 1.84.0 → 1.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,7 @@ Latest updates and announcements.
|
|
|
8
8
|
|
|
9
9
|
## October 7, 2026
|
|
10
10
|
|
|
11
|
+
- New [Video Player](/components/video-player) (`TelaVideoPlayer`): a video with custom controls for play/pause, volume, scrubbing, playback speed, captions, picture-in-picture and fullscreen, plus keyboard shortcuts. Accessible labels are English by default and translatable through `labels`.
|
|
11
12
|
- [Tags Select](/components/tags) back and edit buttons, [Sheet](/components/sheet) content close buttons, and the [Sidebar](/patterns/sidebar) user menu trigger receive shared translated accessible names automatically.
|
|
12
13
|
- [Uploader](/patterns/uploader) disclosure controls use a single named button with the expanded state.
|
|
13
14
|
- [Input](/components/input) clear buttons and tooltips use the shared translated label unless `clearLabel` is provided.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Meta, ArgTypes } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
<Meta title="Media/VideoPlayer" tags={['new']} />
|
|
4
|
+
|
|
5
|
+
# TelaVideoPlayer
|
|
6
|
+
|
|
7
|
+
A video player with custom controls: play/pause, a hover volume slider, a scrubbable progress bar with buffered range and hover time, playback speed, captions, picture-in-picture and fullscreen. Controls fade out after a short idle while playing and come back on pointer movement or focus.
|
|
8
|
+
|
|
9
|
+
The player is a 16:9 black surface in both themes, so its controls are always white.
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
type VideoPlayerProps = {
|
|
15
|
+
src: string
|
|
16
|
+
poster?: string
|
|
17
|
+
tracks?: VideoPlayerTrack[]
|
|
18
|
+
crossorigin?: 'anonymous' | 'use-credentials'
|
|
19
|
+
labels?: Partial<VideoPlayerLabels>
|
|
20
|
+
class?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type VideoPlayerTrack = {
|
|
24
|
+
src: string
|
|
25
|
+
srcLang: string
|
|
26
|
+
label: string
|
|
27
|
+
kind: 'subtitles' | 'captions'
|
|
28
|
+
default?: boolean
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Emits
|
|
33
|
+
|
|
34
|
+
- `play` — playback started
|
|
35
|
+
- `pause` — playback paused
|
|
36
|
+
- `ended` — playback reached the end
|
|
37
|
+
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
### Basic Usage
|
|
41
|
+
|
|
42
|
+
```vue
|
|
43
|
+
<TelaVideoPlayer
|
|
44
|
+
src="https://tela.com/videos/hero-showcase.mp4"
|
|
45
|
+
poster="https://tela.com/videos/hero-showcase-poster.jpg"
|
|
46
|
+
/>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Custom Width and Radius
|
|
50
|
+
|
|
51
|
+
The root accepts `class`, merged with `cn()`, so width and radius can be overridden.
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<TelaVideoPlayer
|
|
55
|
+
src="https://tela.com/videos/hero-showcase.mp4"
|
|
56
|
+
poster="https://tela.com/videos/hero-showcase-poster.jpg"
|
|
57
|
+
class="max-w-480px rounded-12px"
|
|
58
|
+
/>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Captions
|
|
62
|
+
|
|
63
|
+
Pass WebVTT files through `tracks`. A captions toggle appears in the control bar when at least one track is set, and it toggles the first track. Track files on another origin only load when the player sets `crossorigin`: pass `crossorigin="anonymous"` and serve both the track and the video `src` with CORS headers. With `crossorigin` set, a video served without CORS headers fails to load.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const tracks: VideoPlayerTrack[] = [
|
|
67
|
+
{ src: '/captions/intro.en.vtt', srcLang: 'en', label: 'English', kind: 'captions', default: true },
|
|
68
|
+
]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Translation
|
|
72
|
+
|
|
73
|
+
Every accessible label has an English default. Pass `labels` to translate any of them: `region`, `play`, `pause`, `mute`, `unmute`, `volume`, `seek`, `playbackSpeed`, `showCaptions`, `hideCaptions`, `pictureInPicture`, `fullscreen`, `exitFullscreen`.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const labels = { play: t('video.play'), pause: t('video.pause') }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Interaction
|
|
80
|
+
|
|
81
|
+
- Click the video to play or pause; double click toggles fullscreen.
|
|
82
|
+
- Hover the speaker to open the vertical volume slider; drag or use arrow keys on it.
|
|
83
|
+
- Drag the progress bar to scrub. Hovering shows the time under the pointer over the total.
|
|
84
|
+
- The speed button cycles `1×`, `1.25×`, `1.5×`, `2×`.
|
|
85
|
+
- Fullscreen uses the container, so the custom controls stay visible. iPhone Safari has no element fullscreen and falls back to the native video fullscreen.
|
|
86
|
+
- Below the `sm` breakpoint the speed and picture-in-picture buttons are hidden.
|
|
87
|
+
|
|
88
|
+
## Keyboard
|
|
89
|
+
|
|
90
|
+
While the player has focus:
|
|
91
|
+
|
|
92
|
+
| Key | Action |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `Space` / `K` | Play or pause |
|
|
95
|
+
| `M` | Mute or unmute |
|
|
96
|
+
| `F` | Toggle fullscreen |
|
|
97
|
+
| `C` | Toggle captions |
|
|
98
|
+
| `←` / `→` | Seek 5 seconds |
|
|
99
|
+
| `↑` / `↓` | Volume up or down |
|
|
100
|
+
|
|
101
|
+
Space on a focused button activates that button instead of toggling playback. The seek and volume sliders are focusable with Tab and take arrow keys; the seek slider also takes `Home` and `End`. Controls stay visible while a control has keyboard focus.
|
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
|
|
4
|
+
export type VideoPlayerTrack = {
|
|
5
|
+
src: string
|
|
6
|
+
srcLang: string
|
|
7
|
+
label: string
|
|
8
|
+
kind: 'subtitles' | 'captions'
|
|
9
|
+
default?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type VideoPlayerLabels = {
|
|
13
|
+
region: string
|
|
14
|
+
play: string
|
|
15
|
+
pause: string
|
|
16
|
+
mute: string
|
|
17
|
+
unmute: string
|
|
18
|
+
volume: string
|
|
19
|
+
seek: string
|
|
20
|
+
playbackSpeed: string
|
|
21
|
+
showCaptions: string
|
|
22
|
+
hideCaptions: string
|
|
23
|
+
pictureInPicture: string
|
|
24
|
+
fullscreen: string
|
|
25
|
+
exitFullscreen: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const props = withDefaults(defineProps<{
|
|
29
|
+
src: string
|
|
30
|
+
poster?: string
|
|
31
|
+
tracks?: VideoPlayerTrack[]
|
|
32
|
+
crossorigin?: 'anonymous' | 'use-credentials'
|
|
33
|
+
labels?: Partial<VideoPlayerLabels>
|
|
34
|
+
class?: HTMLAttributes['class']
|
|
35
|
+
}>(), {
|
|
36
|
+
tracks: () => [],
|
|
37
|
+
labels: () => ({}),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const emit = defineEmits<{
|
|
41
|
+
play: []
|
|
42
|
+
pause: []
|
|
43
|
+
ended: []
|
|
44
|
+
}>()
|
|
45
|
+
|
|
46
|
+
const DEFAULT_LABELS: VideoPlayerLabels = {
|
|
47
|
+
region: 'Video player',
|
|
48
|
+
play: 'Play',
|
|
49
|
+
pause: 'Pause',
|
|
50
|
+
mute: 'Mute',
|
|
51
|
+
unmute: 'Unmute',
|
|
52
|
+
volume: 'Volume',
|
|
53
|
+
seek: 'Seek',
|
|
54
|
+
playbackSpeed: 'Playback speed',
|
|
55
|
+
showCaptions: 'Show captions',
|
|
56
|
+
hideCaptions: 'Hide captions',
|
|
57
|
+
pictureInPicture: 'Picture in picture',
|
|
58
|
+
fullscreen: 'Fullscreen',
|
|
59
|
+
exitFullscreen: 'Exit fullscreen',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const text = computed(() => ({ ...DEFAULT_LABELS, ...props.labels }))
|
|
63
|
+
|
|
64
|
+
const container = ref<HTMLElement>()
|
|
65
|
+
const video = ref<HTMLVideoElement>()
|
|
66
|
+
|
|
67
|
+
const isMounted = useMounted()
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
playing,
|
|
71
|
+
currentTime,
|
|
72
|
+
duration,
|
|
73
|
+
volume,
|
|
74
|
+
muted,
|
|
75
|
+
rate,
|
|
76
|
+
buffered,
|
|
77
|
+
selectedTrack,
|
|
78
|
+
enableTrack,
|
|
79
|
+
disableTrack,
|
|
80
|
+
supportsPictureInPicture,
|
|
81
|
+
togglePictureInPicture,
|
|
82
|
+
} = useMediaControls(video, {
|
|
83
|
+
src: toRef(props, 'src'),
|
|
84
|
+
tracks: toRef(props, 'tracks'),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const {
|
|
88
|
+
isFullscreen,
|
|
89
|
+
isSupported: isFullscreenSupported,
|
|
90
|
+
toggle: toggleContainerFullscreen,
|
|
91
|
+
} = useFullscreen(container)
|
|
92
|
+
|
|
93
|
+
function togglePlay() {
|
|
94
|
+
playing.value = !playing.value
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* The play toggle waits out the double-click window so a double click only toggles fullscreen. */
|
|
98
|
+
const DOUBLE_CLICK_DELAY = 250
|
|
99
|
+
|
|
100
|
+
let surfaceClickTimer: ReturnType<typeof setTimeout> | undefined
|
|
101
|
+
|
|
102
|
+
function onSurfaceClick() {
|
|
103
|
+
clearTimeout(surfaceClickTimer)
|
|
104
|
+
surfaceClickTimer = setTimeout(togglePlay, DOUBLE_CLICK_DELAY)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function onSurfaceDoubleClick() {
|
|
108
|
+
clearTimeout(surfaceClickTimer)
|
|
109
|
+
toggleFullscreen()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function toggleMute() {
|
|
113
|
+
muted.value = !muted.value
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const IDLE_DELAY = 2200
|
|
117
|
+
|
|
118
|
+
const isUserActive = ref(true)
|
|
119
|
+
|
|
120
|
+
let idleTimer: ReturnType<typeof setTimeout> | undefined
|
|
121
|
+
|
|
122
|
+
function markActive() {
|
|
123
|
+
isUserActive.value = true
|
|
124
|
+
|
|
125
|
+
clearTimeout(idleTimer)
|
|
126
|
+
|
|
127
|
+
idleTimer = setTimeout(() => {
|
|
128
|
+
isUserActive.value = false
|
|
129
|
+
}, IDLE_DELAY)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function onPointerLeave() {
|
|
133
|
+
clearTimeout(idleTimer)
|
|
134
|
+
isUserActive.value = false
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
onBeforeUnmount(() => {
|
|
138
|
+
clearTimeout(surfaceClickTimer)
|
|
139
|
+
clearTimeout(idleTimer)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const isScrubbing = ref(false)
|
|
143
|
+
const isVolumeScrubbing = ref(false)
|
|
144
|
+
|
|
145
|
+
const isControlFocused = ref(false)
|
|
146
|
+
|
|
147
|
+
function onFocusIn(event: FocusEvent) {
|
|
148
|
+
isControlFocused.value = event.target instanceof HTMLElement
|
|
149
|
+
&& event.target !== container.value
|
|
150
|
+
&& event.target.matches(':focus-visible')
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function onFocusOut() {
|
|
154
|
+
isControlFocused.value = false
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const areControlsVisible = computed(() => !playing.value || isUserActive.value || isScrubbing.value || isVolumeScrubbing.value || isControlFocused.value)
|
|
158
|
+
|
|
159
|
+
function formatTime(seconds: number) {
|
|
160
|
+
if (!Number.isFinite(seconds) || seconds < 0)
|
|
161
|
+
seconds = 0
|
|
162
|
+
|
|
163
|
+
const total = Math.floor(seconds)
|
|
164
|
+
const hours = Math.floor(total / 3600)
|
|
165
|
+
const minutes = Math.floor((total % 3600) / 60)
|
|
166
|
+
const secs = total % 60
|
|
167
|
+
const pad = (value: number) => String(value).padStart(2, '0')
|
|
168
|
+
|
|
169
|
+
return hours > 0 ? `${hours}:${pad(minutes)}:${pad(secs)}` : `${pad(minutes)}:${pad(secs)}`
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const elapsedLabel = computed(() => formatTime(currentTime.value))
|
|
173
|
+
const durationLabel = computed(() => formatTime(duration.value))
|
|
174
|
+
const remainingLabel = computed(() => `−${formatTime(Math.max(duration.value - currentTime.value, 0))}`)
|
|
175
|
+
|
|
176
|
+
const SEEK_STEP = 5
|
|
177
|
+
const VOLUME_STEP = 0.1
|
|
178
|
+
|
|
179
|
+
const progressBar = ref<HTMLElement>()
|
|
180
|
+
|
|
181
|
+
const progress = computed(() => (duration.value ? currentTime.value / duration.value : 0))
|
|
182
|
+
|
|
183
|
+
const bufferedProgress = computed(() => {
|
|
184
|
+
const last = buffered.value.at(-1)
|
|
185
|
+
|
|
186
|
+
if (!duration.value || !last)
|
|
187
|
+
return 0
|
|
188
|
+
|
|
189
|
+
return Math.min(last[1] / duration.value, 1)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const hoverRatio = ref<number | null>(null)
|
|
193
|
+
|
|
194
|
+
const hoverLabel = computed(() => (hoverRatio.value === null ? '' : formatTime(hoverRatio.value * duration.value)))
|
|
195
|
+
|
|
196
|
+
function ratioFromEvent(event: PointerEvent) {
|
|
197
|
+
const rect = progressBar.value!.getBoundingClientRect()
|
|
198
|
+
|
|
199
|
+
return Math.min(Math.max((event.clientX - rect.left) / rect.width, 0), 1)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function onBarPointerMove(event: PointerEvent) {
|
|
203
|
+
hoverRatio.value = ratioFromEvent(event)
|
|
204
|
+
|
|
205
|
+
if (isScrubbing.value)
|
|
206
|
+
currentTime.value = hoverRatio.value * duration.value
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function onBarPointerDown(event: PointerEvent) {
|
|
210
|
+
if (!duration.value)
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
isScrubbing.value = true
|
|
214
|
+
progressBar.value!.setPointerCapture(event.pointerId)
|
|
215
|
+
currentTime.value = ratioFromEvent(event) * duration.value
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function onBarPointerUp(event: PointerEvent) {
|
|
219
|
+
if (!isScrubbing.value)
|
|
220
|
+
return
|
|
221
|
+
|
|
222
|
+
isScrubbing.value = false
|
|
223
|
+
progressBar.value!.releasePointerCapture(event.pointerId)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function onBarPointerLeave() {
|
|
227
|
+
if (!isScrubbing.value)
|
|
228
|
+
hoverRatio.value = null
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function seekTo(time: number) {
|
|
232
|
+
currentTime.value = Math.min(Math.max(time, 0), duration.value)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function seekBy(delta: number) {
|
|
236
|
+
seekTo(currentTime.value + delta)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function hasModifier(event: KeyboardEvent) {
|
|
240
|
+
return event.ctrlKey || event.metaKey || event.altKey || event.defaultPrevented
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function onBarKeydown(event: KeyboardEvent) {
|
|
244
|
+
const actions: Record<string, () => void> = {
|
|
245
|
+
ArrowLeft: () => seekBy(-SEEK_STEP),
|
|
246
|
+
ArrowDown: () => seekBy(-SEEK_STEP),
|
|
247
|
+
ArrowRight: () => seekBy(SEEK_STEP),
|
|
248
|
+
ArrowUp: () => seekBy(SEEK_STEP),
|
|
249
|
+
Home: () => seekTo(0),
|
|
250
|
+
End: () => seekTo(duration.value),
|
|
251
|
+
}
|
|
252
|
+
const action = actions[event.key]
|
|
253
|
+
|
|
254
|
+
if (!action || !duration.value || hasModifier(event))
|
|
255
|
+
return
|
|
256
|
+
|
|
257
|
+
event.preventDefault()
|
|
258
|
+
event.stopPropagation()
|
|
259
|
+
|
|
260
|
+
action()
|
|
261
|
+
markActive()
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const RATES = [1, 1.25, 1.5, 2]
|
|
265
|
+
|
|
266
|
+
const rateLabel = computed(() => `${rate.value}×`)
|
|
267
|
+
|
|
268
|
+
function cycleRate() {
|
|
269
|
+
const index = RATES.indexOf(rate.value)
|
|
270
|
+
rate.value = RATES[(index + 1) % RATES.length]!
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const hasCaptions = computed(() => props.tracks.length > 0)
|
|
274
|
+
const areCaptionsOn = computed(() => selectedTrack.value !== -1)
|
|
275
|
+
|
|
276
|
+
function toggleCaptions() {
|
|
277
|
+
if (areCaptionsOn.value)
|
|
278
|
+
disableTrack()
|
|
279
|
+
else
|
|
280
|
+
enableTrack(0)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* Fullscreen: iPhone Safari has no element fullscreen, only the native video one. */
|
|
284
|
+
function toggleFullscreen() {
|
|
285
|
+
const element = video.value
|
|
286
|
+
|
|
287
|
+
if (isFullscreenSupported.value)
|
|
288
|
+
toggleContainerFullscreen()
|
|
289
|
+
else if (element && 'webkitEnterFullscreen' in element && typeof element.webkitEnterFullscreen === 'function')
|
|
290
|
+
element.webkitEnterFullscreen()
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function onKeydown(event: KeyboardEvent) {
|
|
294
|
+
if (hasModifier(event))
|
|
295
|
+
return
|
|
296
|
+
|
|
297
|
+
/* Space on a focused button activates that button, not playback */
|
|
298
|
+
if (event.key === ' ' && event.target instanceof HTMLButtonElement)
|
|
299
|
+
return
|
|
300
|
+
|
|
301
|
+
const actions: Record<string, () => void> = {
|
|
302
|
+
' ': togglePlay,
|
|
303
|
+
'k': togglePlay,
|
|
304
|
+
'm': toggleMute,
|
|
305
|
+
'f': toggleFullscreen,
|
|
306
|
+
'c': () => hasCaptions.value && toggleCaptions(),
|
|
307
|
+
'ArrowLeft': () => seekBy(-SEEK_STEP),
|
|
308
|
+
'ArrowRight': () => seekBy(SEEK_STEP),
|
|
309
|
+
'ArrowUp': () => adjustVolume(VOLUME_STEP),
|
|
310
|
+
'ArrowDown': () => adjustVolume(-VOLUME_STEP),
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const action = actions[event.key]
|
|
314
|
+
|
|
315
|
+
if (!action)
|
|
316
|
+
return
|
|
317
|
+
|
|
318
|
+
event.preventDefault()
|
|
319
|
+
action()
|
|
320
|
+
markActive()
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const volumeBar = ref<HTMLElement>()
|
|
324
|
+
|
|
325
|
+
const effectiveVolume = computed(() => (muted.value ? 0 : volume.value))
|
|
326
|
+
|
|
327
|
+
const VOLUME_TRACK_PADDING = 10
|
|
328
|
+
|
|
329
|
+
function setVolume(value: number) {
|
|
330
|
+
volume.value = Math.min(Math.max(value, 0), 1)
|
|
331
|
+
muted.value = volume.value === 0
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function adjustVolume(delta: number) {
|
|
335
|
+
setVolume(effectiveVolume.value + delta)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function setVolumeFromEvent(event: PointerEvent) {
|
|
339
|
+
const rect = volumeBar.value!.getBoundingClientRect()
|
|
340
|
+
const trackTop = rect.top + VOLUME_TRACK_PADDING
|
|
341
|
+
const trackHeight = rect.height - VOLUME_TRACK_PADDING * 2
|
|
342
|
+
|
|
343
|
+
setVolume(1 - (event.clientY - trackTop) / trackHeight)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function onVolumePointerDown(event: PointerEvent) {
|
|
347
|
+
event.preventDefault()
|
|
348
|
+
|
|
349
|
+
isVolumeScrubbing.value = true
|
|
350
|
+
volumeBar.value!.setPointerCapture(event.pointerId)
|
|
351
|
+
setVolumeFromEvent(event)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function onVolumePointerMove(event: PointerEvent) {
|
|
355
|
+
if (isVolumeScrubbing.value)
|
|
356
|
+
setVolumeFromEvent(event)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function onVolumePointerUp(event: PointerEvent) {
|
|
360
|
+
if (!isVolumeScrubbing.value)
|
|
361
|
+
return
|
|
362
|
+
|
|
363
|
+
isVolumeScrubbing.value = false
|
|
364
|
+
volumeBar.value!.releasePointerCapture(event.pointerId)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function onVolumeKeydown(event: KeyboardEvent) {
|
|
368
|
+
const steps: Record<string, number> = { ArrowLeft: -VOLUME_STEP, ArrowDown: -VOLUME_STEP, ArrowRight: VOLUME_STEP, ArrowUp: VOLUME_STEP }
|
|
369
|
+
const step = steps[event.key]
|
|
370
|
+
|
|
371
|
+
if (step === undefined || hasModifier(event))
|
|
372
|
+
return
|
|
373
|
+
|
|
374
|
+
event.preventDefault()
|
|
375
|
+
event.stopPropagation()
|
|
376
|
+
|
|
377
|
+
adjustVolume(step)
|
|
378
|
+
markActive()
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const volumeIcon = computed(() => {
|
|
382
|
+
if (muted.value || volume.value === 0)
|
|
383
|
+
return 'i-ph-speaker-slash'
|
|
384
|
+
|
|
385
|
+
return volume.value < 0.5 ? 'i-ph-speaker-low' : 'i-ph-speaker-high'
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
const buttonClass = 'flex items-center justify-center shrink-0 size-28px rounded-8px text-white/90 transition-[color,background-color,transform] duration-150 ease-out hover:text-white hover:bg-white/15 active:scale-95 outline-none focus-visible:ring-1 focus-visible:ring-white/60'
|
|
389
|
+
|
|
390
|
+
const timeClass = 'shrink-0 body-12-medium tabular-nums text-white'
|
|
391
|
+
|
|
392
|
+
const iconVariants = {
|
|
393
|
+
initial: { scale: 0.9, opacity: 0 },
|
|
394
|
+
animate: { scale: 1, opacity: 1 },
|
|
395
|
+
exit: { scale: 0.9, opacity: 0 },
|
|
396
|
+
} as const
|
|
397
|
+
|
|
398
|
+
const iconTransition = {
|
|
399
|
+
type: 'spring',
|
|
400
|
+
duration: 0.3,
|
|
401
|
+
bounce: 0,
|
|
402
|
+
} as const
|
|
403
|
+
</script>
|
|
404
|
+
|
|
405
|
+
<template>
|
|
406
|
+
<div
|
|
407
|
+
ref="container"
|
|
408
|
+
tabindex="0"
|
|
409
|
+
role="region"
|
|
410
|
+
:aria-label="text.region"
|
|
411
|
+
:class="cn(
|
|
412
|
+
'group/player relative w-full aspect-video bg-black rounded-16px overflow-hidden outline-none select-none focus-visible:ring-2 focus-visible:ring-white/60',
|
|
413
|
+
isFullscreen && 'rounded-none',
|
|
414
|
+
!areControlsVisible && 'cursor-none',
|
|
415
|
+
props.class,
|
|
416
|
+
)"
|
|
417
|
+
@pointermove="markActive"
|
|
418
|
+
@pointerdown="markActive"
|
|
419
|
+
@pointerleave="onPointerLeave"
|
|
420
|
+
@keydown="onKeydown"
|
|
421
|
+
@focusin="onFocusIn"
|
|
422
|
+
@focusout="onFocusOut"
|
|
423
|
+
>
|
|
424
|
+
<video
|
|
425
|
+
ref="video"
|
|
426
|
+
:poster="poster"
|
|
427
|
+
:crossorigin="crossorigin"
|
|
428
|
+
preload="metadata"
|
|
429
|
+
playsinline
|
|
430
|
+
:class="cn(
|
|
431
|
+
'absolute inset-0 size-full object-contain [&::cue]:bg-black/65 [&::cue]:text-white [&::cue]:text-16px',
|
|
432
|
+
areControlsVisible ? 'cursor-pointer' : 'cursor-none',
|
|
433
|
+
)"
|
|
434
|
+
@click="onSurfaceClick"
|
|
435
|
+
@dblclick="onSurfaceDoubleClick"
|
|
436
|
+
@play="emit('play')"
|
|
437
|
+
@pause="emit('pause')"
|
|
438
|
+
@ended="emit('ended')"
|
|
439
|
+
/>
|
|
440
|
+
|
|
441
|
+
<div
|
|
442
|
+
aria-hidden="true"
|
|
443
|
+
:class="cn(
|
|
444
|
+
'pointer-events-none absolute inset-x-0 bottom-0 h-120px bg-gradient-to-t from-black/60 to-transparent transition-opacity duration-300 ease-out',
|
|
445
|
+
areControlsVisible ? 'opacity-100' : 'opacity-0',
|
|
446
|
+
)"
|
|
447
|
+
/>
|
|
448
|
+
|
|
449
|
+
<div
|
|
450
|
+
:class="cn(
|
|
451
|
+
'absolute inset-x-0 bottom-0 flex items-center gap-12px px-24px pb-20px pt-32px text-white transition-opacity duration-300 ease-out max-sm:px-16px max-sm:pb-14px',
|
|
452
|
+
areControlsVisible ? 'opacity-100' : 'opacity-0 pointer-events-none',
|
|
453
|
+
)"
|
|
454
|
+
>
|
|
455
|
+
<div class="flex items-center gap-8px">
|
|
456
|
+
<button
|
|
457
|
+
type="button"
|
|
458
|
+
:aria-label="playing ? text.pause : text.play"
|
|
459
|
+
:class="buttonClass"
|
|
460
|
+
@click="togglePlay"
|
|
461
|
+
>
|
|
462
|
+
<AnimatePresence mode="popLayout" :initial="false">
|
|
463
|
+
<Motion
|
|
464
|
+
:key="playing ? 'pause' : 'play'"
|
|
465
|
+
as="span"
|
|
466
|
+
class="flex"
|
|
467
|
+
v-bind="iconVariants"
|
|
468
|
+
:transition="iconTransition"
|
|
469
|
+
>
|
|
470
|
+
<TelaIcon
|
|
471
|
+
:name="playing ? 'i-ph-pause-fill' : 'i-ph-play-fill'"
|
|
472
|
+
size="16px"
|
|
473
|
+
:class="!playing && '-ml-2px'"
|
|
474
|
+
/>
|
|
475
|
+
</Motion>
|
|
476
|
+
</AnimatePresence>
|
|
477
|
+
</button>
|
|
478
|
+
|
|
479
|
+
<div class="group/volume relative flex items-center">
|
|
480
|
+
<button
|
|
481
|
+
type="button"
|
|
482
|
+
:aria-label="muted ? text.unmute : text.mute"
|
|
483
|
+
:class="buttonClass"
|
|
484
|
+
@click="toggleMute"
|
|
485
|
+
>
|
|
486
|
+
<TelaIcon :name="volumeIcon" size="18px" />
|
|
487
|
+
</button>
|
|
488
|
+
|
|
489
|
+
<!-- Padded so the pointer can travel from the button to the slider without closing it -->
|
|
490
|
+
<div
|
|
491
|
+
:class="cn(
|
|
492
|
+
'absolute bottom-full left-1/2 -translate-x-1/2 pb-6px transition-opacity duration-150 ease-out',
|
|
493
|
+
isVolumeScrubbing ? 'opacity-100' : 'opacity-0 pointer-events-none group-hover/volume:opacity-100 group-hover/volume:pointer-events-auto group-focus-within/volume:opacity-100 group-focus-within/volume:pointer-events-auto',
|
|
494
|
+
)"
|
|
495
|
+
>
|
|
496
|
+
<div
|
|
497
|
+
ref="volumeBar"
|
|
498
|
+
role="slider"
|
|
499
|
+
:aria-label="text.volume"
|
|
500
|
+
aria-orientation="vertical"
|
|
501
|
+
tabindex="0"
|
|
502
|
+
:aria-valuemin="0"
|
|
503
|
+
:aria-valuemax="100"
|
|
504
|
+
:aria-valuenow="Math.round(effectiveVolume * 100)"
|
|
505
|
+
class="flex items-center justify-center w-28px h-88px py-10px rounded-8px bg-white/15 cursor-crosshair touch-none outline-none focus-visible:ring-1 focus-visible:ring-white/60"
|
|
506
|
+
@pointerdown="onVolumePointerDown"
|
|
507
|
+
@pointermove="onVolumePointerMove"
|
|
508
|
+
@pointerup="onVolumePointerUp"
|
|
509
|
+
@pointercancel="onVolumePointerUp"
|
|
510
|
+
@keydown="onVolumeKeydown"
|
|
511
|
+
>
|
|
512
|
+
<div class="relative w-2px h-full rounded-full bg-white/20 overflow-hidden">
|
|
513
|
+
<div class="absolute inset-x-0 bottom-0 bg-white" :style="{ height: `${effectiveVolume * 100}%` }" />
|
|
514
|
+
</div>
|
|
515
|
+
</div>
|
|
516
|
+
</div>
|
|
517
|
+
</div>
|
|
518
|
+
</div>
|
|
519
|
+
|
|
520
|
+
<div class="flex flex-1 min-w-0 items-center gap-8px">
|
|
521
|
+
<span :class="timeClass">{{ elapsedLabel }}</span>
|
|
522
|
+
|
|
523
|
+
<div
|
|
524
|
+
ref="progressBar"
|
|
525
|
+
role="slider"
|
|
526
|
+
:aria-label="text.seek"
|
|
527
|
+
:aria-valuemin="0"
|
|
528
|
+
:aria-valuemax="Math.round(duration)"
|
|
529
|
+
:aria-valuenow="Math.round(currentTime)"
|
|
530
|
+
:aria-valuetext="elapsedLabel"
|
|
531
|
+
tabindex="0"
|
|
532
|
+
class="relative flex flex-1 items-center h-20px rounded-4px cursor-crosshair touch-none outline-none focus-visible:ring-1 focus-visible:ring-white/60"
|
|
533
|
+
@pointerdown="onBarPointerDown"
|
|
534
|
+
@pointermove="onBarPointerMove"
|
|
535
|
+
@pointerup="onBarPointerUp"
|
|
536
|
+
@pointercancel="onBarPointerUp"
|
|
537
|
+
@pointerleave="onBarPointerLeave"
|
|
538
|
+
@keydown="onBarKeydown"
|
|
539
|
+
>
|
|
540
|
+
<div class="relative w-full h-4px rounded-full bg-white/20 overflow-hidden">
|
|
541
|
+
<div class="absolute inset-y-0 left-0 bg-white/25" :style="{ width: `${bufferedProgress * 100}%` }" />
|
|
542
|
+
<div class="absolute inset-y-0 left-0 bg-white" :style="{ width: `${progress * 100}%` }" />
|
|
543
|
+
</div>
|
|
544
|
+
|
|
545
|
+
<div
|
|
546
|
+
v-if="hoverRatio !== null && duration"
|
|
547
|
+
class="pointer-events-none absolute inset-y-0 -translate-x-1/2 flex flex-col items-center justify-end"
|
|
548
|
+
:style="{ left: `${hoverRatio * 100}%` }"
|
|
549
|
+
>
|
|
550
|
+
<span class="absolute bottom-full mb-6px whitespace-nowrap body-12-medium tabular-nums">
|
|
551
|
+
<span class="text-white">{{ hoverLabel }}</span>
|
|
552
|
+
<span class="text-white/50"> / {{ durationLabel }}</span>
|
|
553
|
+
</span>
|
|
554
|
+
<div class="w-1px h-full bg-white/80" />
|
|
555
|
+
</div>
|
|
556
|
+
</div>
|
|
557
|
+
|
|
558
|
+
<span :class="timeClass">{{ remainingLabel }}</span>
|
|
559
|
+
</div>
|
|
560
|
+
|
|
561
|
+
<div class="flex items-center gap-8px">
|
|
562
|
+
<button
|
|
563
|
+
type="button"
|
|
564
|
+
:aria-label="text.playbackSpeed"
|
|
565
|
+
:class="cn(buttonClass, 'min-w-52px body-12-medium tabular-nums max-sm:hidden')"
|
|
566
|
+
@click="cycleRate"
|
|
567
|
+
>
|
|
568
|
+
{{ rateLabel }}
|
|
569
|
+
</button>
|
|
570
|
+
|
|
571
|
+
<button
|
|
572
|
+
v-if="hasCaptions"
|
|
573
|
+
type="button"
|
|
574
|
+
:aria-label="areCaptionsOn ? text.hideCaptions : text.showCaptions"
|
|
575
|
+
:aria-pressed="areCaptionsOn"
|
|
576
|
+
:class="cn(buttonClass, !areCaptionsOn && 'opacity-60')"
|
|
577
|
+
@click="toggleCaptions"
|
|
578
|
+
>
|
|
579
|
+
<TelaIcon name="i-ph-subtitles" size="18px" />
|
|
580
|
+
</button>
|
|
581
|
+
|
|
582
|
+
<button
|
|
583
|
+
v-if="isMounted && supportsPictureInPicture"
|
|
584
|
+
type="button"
|
|
585
|
+
:aria-label="text.pictureInPicture"
|
|
586
|
+
:class="cn(buttonClass, 'max-sm:hidden')"
|
|
587
|
+
@click="togglePictureInPicture"
|
|
588
|
+
>
|
|
589
|
+
<TelaIcon name="i-ph-picture-in-picture" size="18px" />
|
|
590
|
+
</button>
|
|
591
|
+
|
|
592
|
+
<button
|
|
593
|
+
type="button"
|
|
594
|
+
:aria-label="isFullscreen ? text.exitFullscreen : text.fullscreen"
|
|
595
|
+
:class="buttonClass"
|
|
596
|
+
@click="toggleFullscreen"
|
|
597
|
+
>
|
|
598
|
+
<TelaIcon :name="isFullscreen ? 'i-ph-corners-in' : 'i-ph-corners-out'" size="18px" />
|
|
599
|
+
</button>
|
|
600
|
+
</div>
|
|
601
|
+
</div>
|
|
602
|
+
</div>
|
|
603
|
+
</template>
|