@m3ui-vue/m3ui-vue 1.2.2 → 1.3.1
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/dist/API.md +3010 -376
- package/dist/MButton-Bl_BSUep.js +172 -0
- package/dist/MButton-Bl_BSUep.js.map +1 -0
- package/dist/MDialog-D_Yik8ou.js +173 -0
- package/dist/MDialog-D_Yik8ou.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-BxifHJdU.js +824 -0
- package/dist/MListItem-BxifHJdU.js.map +1 -0
- package/dist/MLoadingIndicator-BxbFhSX6.js +115 -0
- package/dist/MLoadingIndicator-BxbFhSX6.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-BeN9QcB3.js +435 -0
- package/dist/MSeekBar-BeN9QcB3.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-BVSbJlGS.js +691 -0
- package/dist/MSlider-BVSbJlGS.js.map +1 -0
- package/dist/MSpinner-C2SUnWk4.js +65 -0
- package/dist/MSpinner-C2SUnWk4.js.map +1 -0
- package/dist/MTextField-CEkWSZ2v.js +296 -0
- package/dist/MTextField-CEkWSZ2v.js.map +1 -0
- package/dist/MTooltip-CodJGEO-.js +756 -0
- package/dist/MTooltip-CodJGEO-.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +150 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +248 -0
- package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
- package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
- package/dist/components/MFlow.vue.d.ts +318 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFloorPlan.d.ts +58 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +204 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1702 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3547 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/locales/index.js +1435 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +8248 -7637
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-CaWwi-b6.js} +206 -2
- package/dist/useLocale-CaWwi-b6.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +118 -0
- package/src/__tests__/MFloorPlan.test.ts +299 -0
- package/src/__tests__/MFlow.test.ts +590 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +819 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +1080 -0
- package/src/components/MFloorPlanInspector.vue +169 -0
- package/src/components/MFloorPlanToolbar.vue +128 -0
- package/src/components/MFlow.vue +2060 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1270 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFloorPlan.ts +73 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +410 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +9 -0
- package/src/locales/de.ts +204 -0
- package/src/locales/es.ts +204 -0
- package/src/locales/fr.ts +204 -0
- package/src/locales/ja.ts +204 -0
- package/src/locales/ko.ts +204 -0
- package/src/locales/pt.ts +204 -0
- package/src/locales/zh.ts +204 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,839 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { MediaPlayer } from '../composables/useMediaPlayer'
|
|
3
|
+
|
|
4
|
+
export interface VideoSource {
|
|
5
|
+
src: string
|
|
6
|
+
/** MIME type, e.g. `video/webm` or `application/vnd.apple.mpegurl` (HLS) */
|
|
7
|
+
type?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface VideoTrack {
|
|
11
|
+
/** WebVTT file */
|
|
12
|
+
src: string
|
|
13
|
+
/** Language code, e.g. `es` */
|
|
14
|
+
srclang: string
|
|
15
|
+
/** Shown in the subtitles menu */
|
|
16
|
+
label: string
|
|
17
|
+
/** Shown from the start */
|
|
18
|
+
default?: boolean
|
|
19
|
+
/** Default `subtitles` */
|
|
20
|
+
kind?: 'subtitles' | 'captions'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The bits of hls.js the player uses, so the library doesn't depend on it */
|
|
24
|
+
export interface HlsLike {
|
|
25
|
+
loadSource(src: string): void
|
|
26
|
+
attachMedia(el: HTMLMediaElement): void
|
|
27
|
+
destroy(): void
|
|
28
|
+
on(event: string, fn: (...args: any[]) => void): void
|
|
29
|
+
levels: { height?: number; bitrate?: number }[]
|
|
30
|
+
currentLevel: number
|
|
31
|
+
}
|
|
32
|
+
export interface HlsModule {
|
|
33
|
+
default: { new (config?: Record<string, unknown>): HlsLike; isSupported(): boolean; Events: Record<string, string> }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What the control slots receive */
|
|
37
|
+
export interface VideoPlayerSlotProps {
|
|
38
|
+
player: MediaPlayer
|
|
39
|
+
/** The controls are showing (slots usually fade with them) */
|
|
40
|
+
shown: boolean
|
|
41
|
+
fullscreen: boolean
|
|
42
|
+
/** The player is narrower than 480px (a phone in portrait) */
|
|
43
|
+
compact: boolean
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
/**
|
|
49
|
+
* A video player (not an M3 spec component: a port of Media3's Compose Material3 `Player`, androidx/media
|
|
50
|
+
* `ui_compose_material3`): controls in three slots like Media3's, top (empty, the title in full screen), center
|
|
51
|
+
* (previous, back, a large play/pause, forward, next, centered on the picture) and bottom (an `MSeekBar`, the time
|
|
52
|
+
* and chapter, volume, subtitles, settings, picture in picture and full screen). Unlike Media3's they keep a dark
|
|
53
|
+
* scrim and white content in both themes, as they sit on the picture; the play button is primary-container, a
|
|
54
|
+
* circle while paused that squares off while playing. Controls hide while playing after `hideDelay`.
|
|
55
|
+
* A click plays/pauses and a double click goes full screen; on touch a tap shows or hides the controls, a double
|
|
56
|
+
* tap on either side skips (taps add up), and a long press plays at 2× while held. Keys (with the player
|
|
57
|
+
* focused): Space/K, J/L, arrows, F, M, C, 0–9, Home/End, `<`/`>`.
|
|
58
|
+
*
|
|
59
|
+
* Plays `src`/`sources` in a `<video>`, or anything else through `#media` over a clock of `duration` seconds.
|
|
60
|
+
* HLS (`.m3u8`) plays natively where the browser can; elsewhere pass `:hls="() => import("hls.js")"`.
|
|
61
|
+
*
|
|
62
|
+
* @slot media Replaces the `<video>` (a canvas, a shader, a 3D scene). Props: `{ time, playing, rate, duration }`
|
|
63
|
+
* @slot top Top controls. Props: `VideoPlayerSlotProps`
|
|
64
|
+
* @slot center Replaces the center controls. Props: `VideoPlayerSlotProps`
|
|
65
|
+
* @slot bottom Replaces the bottom controls. Props: `VideoPlayerSlotProps`
|
|
66
|
+
* @slot settings Extra `MMenuItem`s at the end of the settings menu. Props: `{ player }`
|
|
67
|
+
* @slot end Shown over the video when it ends (an "up next", say). Props: `{ player, replay }`
|
|
68
|
+
* @slot error Replaces the error message. Props: `{ error }`
|
|
69
|
+
* @event previous The previous button (or the lock screen's) was pressed
|
|
70
|
+
* @event next The next button (or the lock screen's) was pressed
|
|
71
|
+
* @event ended The video reached its end
|
|
72
|
+
* @event error The video failed to load or play, with the media element's error
|
|
73
|
+
* @event fullscreen Full screen was entered (true) or left (false)
|
|
74
|
+
*/
|
|
75
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, useSlots, watch } from 'vue'
|
|
76
|
+
import { useMediaPlayer } from '../composables/useMediaPlayer'
|
|
77
|
+
import { useLocale } from '../composables/useLocale'
|
|
78
|
+
import MSeekBar, { type SeekBarChapter } from './MSeekBar.vue'
|
|
79
|
+
import MIconButton from './MIconButton.vue'
|
|
80
|
+
import MIcon from './MIcon.vue'
|
|
81
|
+
import MSlider from './MSlider.vue'
|
|
82
|
+
import MMenu from './MMenu.vue'
|
|
83
|
+
import MMenuItem from './MMenuItem.vue'
|
|
84
|
+
import MLoadingIndicator from './MLoadingIndicator.vue'
|
|
85
|
+
|
|
86
|
+
defineOptions({ inheritAttrs: false })
|
|
87
|
+
|
|
88
|
+
const props = withDefaults(defineProps<{
|
|
89
|
+
/** Video URL */
|
|
90
|
+
src?: string
|
|
91
|
+
/** Several formats of the video; the browser plays the first it can */
|
|
92
|
+
sources?: VideoSource[]
|
|
93
|
+
/** Image shown before playing */
|
|
94
|
+
poster?: string
|
|
95
|
+
/** Subtitle tracks (WebVTT) */
|
|
96
|
+
tracks?: VideoTrack[]
|
|
97
|
+
/** Chapters, drawn on the seek bar */
|
|
98
|
+
chapters?: SeekBarChapter[]
|
|
99
|
+
/** Shown at the top in full screen, and on the lock screen while playing */
|
|
100
|
+
title?: string
|
|
101
|
+
/** Length in seconds, for `#media` content (with a `<video>` it comes from the file) */
|
|
102
|
+
duration?: number
|
|
103
|
+
/** Drive this player instead of one of its own (from `useMediaPlayer()`, kept outside to survive page changes). Read once */
|
|
104
|
+
player?: MediaPlayer
|
|
105
|
+
/** Playing (v-model) */
|
|
106
|
+
playing?: boolean
|
|
107
|
+
/** Position in seconds (v-model) */
|
|
108
|
+
currentTime?: number
|
|
109
|
+
/** Playback speed (v-model) */
|
|
110
|
+
rate?: number
|
|
111
|
+
/** Volume, 0 to 1 (v-model) */
|
|
112
|
+
volume?: number
|
|
113
|
+
/** Muted (v-model) */
|
|
114
|
+
muted?: boolean
|
|
115
|
+
/** Starts playing when mounted; muted if the browser blocks sound before a user gesture */
|
|
116
|
+
autoplay?: boolean
|
|
117
|
+
/** Starts over at the end */
|
|
118
|
+
loop?: boolean
|
|
119
|
+
/** Shows the controls. Off: just the video and its gestures */
|
|
120
|
+
controls?: boolean
|
|
121
|
+
/** Adds previous and next buttons (emits `previous`); with only one of the two, the other shows disabled */
|
|
122
|
+
hasPrevious?: boolean
|
|
123
|
+
/** Adds previous and next buttons (emits `next`); with only one of the two, the other shows disabled */
|
|
124
|
+
hasNext?: boolean
|
|
125
|
+
/** Seconds the skip buttons, J/L and double taps move */
|
|
126
|
+
seekStep?: number
|
|
127
|
+
/** Speeds offered in the settings menu */
|
|
128
|
+
speeds?: number[]
|
|
129
|
+
/** Box ratio, as CSS `aspect-ratio`; `auto` follows the video */
|
|
130
|
+
aspectRatio?: string
|
|
131
|
+
/** How the video fills the box */
|
|
132
|
+
fit?: 'contain' | 'cover'
|
|
133
|
+
/** Milliseconds without activity before the controls hide while playing */
|
|
134
|
+
hideDelay?: number
|
|
135
|
+
/** Played part of the seek bar: an M3 role or any CSS color */
|
|
136
|
+
color?: string
|
|
137
|
+
/**
|
|
138
|
+
* The video's CORS mode. Subtitles from another origin need `anonymous` (and a video host that allows it, as
|
|
139
|
+
* the `<track>` is fetched in the video's mode)
|
|
140
|
+
*/
|
|
141
|
+
crossorigin?: 'anonymous' | 'use-credentials'
|
|
142
|
+
/** Loads hls.js for `.m3u8` where the browser can't play HLS: `() => import("hls.js")` */
|
|
143
|
+
hls?: () => Promise<HlsModule>
|
|
144
|
+
}>(), {
|
|
145
|
+
playing: undefined,
|
|
146
|
+
currentTime: undefined,
|
|
147
|
+
rate: undefined,
|
|
148
|
+
volume: undefined,
|
|
149
|
+
muted: undefined,
|
|
150
|
+
autoplay: false,
|
|
151
|
+
loop: false,
|
|
152
|
+
controls: true,
|
|
153
|
+
hasPrevious: false,
|
|
154
|
+
hasNext: false,
|
|
155
|
+
seekStep: 10,
|
|
156
|
+
speeds: () => [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2],
|
|
157
|
+
aspectRatio: '16/9',
|
|
158
|
+
fit: 'contain',
|
|
159
|
+
hideDelay: 3000,
|
|
160
|
+
color: 'primary',
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const emit = defineEmits<{
|
|
164
|
+
'update:playing': [boolean]
|
|
165
|
+
'update:currentTime': [number]
|
|
166
|
+
'update:rate': [number]
|
|
167
|
+
'update:volume': [number]
|
|
168
|
+
'update:muted': [boolean]
|
|
169
|
+
previous: []
|
|
170
|
+
next: []
|
|
171
|
+
ended: []
|
|
172
|
+
error: [MediaError | null]
|
|
173
|
+
fullscreen: [boolean]
|
|
174
|
+
}>()
|
|
175
|
+
|
|
176
|
+
const slots = useSlots()
|
|
177
|
+
const locale = useLocale()
|
|
178
|
+
const root = ref<HTMLElement>()
|
|
179
|
+
const videoEl = ref<HTMLVideoElement>()
|
|
180
|
+
const custom = !!slots.media
|
|
181
|
+
|
|
182
|
+
const player: MediaPlayer = props.player ?? useMediaPlayer({
|
|
183
|
+
media: () => (custom ? null : videoEl.value),
|
|
184
|
+
duration: () => props.duration,
|
|
185
|
+
loop: () => props.loop,
|
|
186
|
+
metadata: () => (props.title ? { title: props.title, artwork: props.poster ? [props.poster] : [] } : null),
|
|
187
|
+
seekStep: props.seekStep,
|
|
188
|
+
onPrevious: () => emit('previous'),
|
|
189
|
+
onNext: () => emit('next'),
|
|
190
|
+
hasPrevious: () => props.hasPrevious,
|
|
191
|
+
hasNext: () => props.hasNext,
|
|
192
|
+
})
|
|
193
|
+
const external = !!props.player
|
|
194
|
+
const hasPrevious = computed(() => (external ? player.hasPrevious.value : props.hasPrevious))
|
|
195
|
+
const hasNext = computed(() => (external ? player.hasNext.value : props.hasNext))
|
|
196
|
+
function previous() {
|
|
197
|
+
if (external) player.previous()
|
|
198
|
+
else emit('previous')
|
|
199
|
+
}
|
|
200
|
+
function next() {
|
|
201
|
+
if (external) player.next()
|
|
202
|
+
else emit('next')
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ── v-model ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
206
|
+
watch(() => props.playing, (v) => { if (v !== undefined) player.playing.value = v })
|
|
207
|
+
watch(() => props.currentTime, (v) => { if (v !== undefined && Math.abs(v - player.currentTime.value) > 0.5) player.seek(v) }, { immediate: true })
|
|
208
|
+
watch(() => props.rate, (v) => { if (v !== undefined) player.rate.value = v }, { immediate: true })
|
|
209
|
+
watch(() => props.volume, (v) => { if (v !== undefined) player.volume.value = v }, { immediate: true })
|
|
210
|
+
watch(() => props.muted, (v) => { if (v !== undefined) player.muted.value = v }, { immediate: true })
|
|
211
|
+
watch(player.playing, (v) => emit('update:playing', v))
|
|
212
|
+
watch(player.currentTime, (v) => emit('update:currentTime', v))
|
|
213
|
+
watch(player.rate, (v) => emit('update:rate', v))
|
|
214
|
+
watch(player.volume, (v) => emit('update:volume', v))
|
|
215
|
+
watch(player.muted, (v) => emit('update:muted', v))
|
|
216
|
+
watch(player.ended, (v) => { if (v) emit('ended') })
|
|
217
|
+
watch(player.error, (e) => { if (e) emit('error', e) })
|
|
218
|
+
|
|
219
|
+
// ── Size ────────────────────────────────────────────────────────────────────────────────────────────────
|
|
220
|
+
const width = ref(640)
|
|
221
|
+
const compact = computed(() => width.value < 480)
|
|
222
|
+
let ro: ResizeObserver | undefined
|
|
223
|
+
|
|
224
|
+
// ── Controls visibility ─────────────────────────────────────────────────────────────────────────────────
|
|
225
|
+
const shown = ref(true)
|
|
226
|
+
const overControls = ref(false)
|
|
227
|
+
const menu = ref<InstanceType<typeof MMenu>>()
|
|
228
|
+
const menuOpen = computed(() => !!(menu.value as { open?: boolean } | undefined)?.open)
|
|
229
|
+
let hideTimer: ReturnType<typeof setTimeout> | undefined
|
|
230
|
+
function poke() {
|
|
231
|
+
shown.value = true
|
|
232
|
+
clearTimeout(hideTimer)
|
|
233
|
+
hideTimer = setTimeout(() => {
|
|
234
|
+
if (player.playing.value && !menuOpen.value && !overControls.value) shown.value = false
|
|
235
|
+
}, props.hideDelay)
|
|
236
|
+
}
|
|
237
|
+
watch(player.playing, (on) => (on ? poke() : (shown.value = true)))
|
|
238
|
+
watch(menuOpen, (open) => { if (!open) poke() })
|
|
239
|
+
const visible = computed(() => props.controls && (shown.value || !player.playing.value || player.ended.value))
|
|
240
|
+
|
|
241
|
+
// ── Flash: a big icon for what you can't see happen (a click on the picture, a double tap, a key) ───────
|
|
242
|
+
const flash = ref<{ icon: string; text?: string; side?: 'left' | 'right'; n: number } | null>(null)
|
|
243
|
+
let flashTimer: ReturnType<typeof setTimeout> | undefined
|
|
244
|
+
function show(icon: string, text?: string, side?: 'left' | 'right') {
|
|
245
|
+
flash.value = { icon, text, side, n: (flash.value?.n ?? 0) + 1 }
|
|
246
|
+
clearTimeout(flashTimer)
|
|
247
|
+
flashTimer = setTimeout(() => (flash.value = null), 650)
|
|
248
|
+
}
|
|
249
|
+
const seconds = (n: number) => locale.mediaSeconds.replace('{seconds}', String(n))
|
|
250
|
+
|
|
251
|
+
function toggle(flashIt = false) {
|
|
252
|
+
const wasPlaying = player.playing.value
|
|
253
|
+
player.toggle()
|
|
254
|
+
if (flashIt) show(wasPlaying ? 'pause' : 'play_arrow')
|
|
255
|
+
}
|
|
256
|
+
// Double taps add up while they keep coming: "30 seconds"
|
|
257
|
+
let skipRun = { side: '' as '' | 'left' | 'right', total: 0, at: 0 }
|
|
258
|
+
function skip(s: number, flashIt = false) {
|
|
259
|
+
player.skip(s)
|
|
260
|
+
if (!flashIt) return
|
|
261
|
+
const side = s > 0 ? 'right' : 'left'
|
|
262
|
+
const t = performance.now()
|
|
263
|
+
skipRun = skipRun.side === side && t - skipRun.at < 1000 ? { side, total: skipRun.total + Math.abs(s), at: t } : { side, total: Math.abs(s), at: t }
|
|
264
|
+
show(s > 0 ? 'fast_forward' : 'fast_rewind', seconds(skipRun.total), side)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ── Pointer on the picture ──────────────────────────────────────────────────────────────────────────────
|
|
268
|
+
let lastTap = -Infinity
|
|
269
|
+
let tapTimer: ReturnType<typeof setTimeout> | undefined
|
|
270
|
+
let pressTimer: ReturnType<typeof setTimeout> | undefined
|
|
271
|
+
let fastFrom: number | null = null
|
|
272
|
+
const fast = ref(false)
|
|
273
|
+
|
|
274
|
+
function onSurfaceDown(e: PointerEvent) {
|
|
275
|
+
if (e.button !== 0) return
|
|
276
|
+
root.value?.focus({ preventScroll: true })
|
|
277
|
+
// Long press: 2× while held (touch and mouse alike, as YouTube)
|
|
278
|
+
clearTimeout(pressTimer)
|
|
279
|
+
pressTimer = setTimeout(() => {
|
|
280
|
+
if (!player.playing.value) return
|
|
281
|
+
fastFrom = player.rate.value
|
|
282
|
+
player.rate.value = 2
|
|
283
|
+
fast.value = true
|
|
284
|
+
}, 500)
|
|
285
|
+
}
|
|
286
|
+
function endFast() {
|
|
287
|
+
clearTimeout(pressTimer)
|
|
288
|
+
if (fastFrom === null) return false
|
|
289
|
+
player.rate.value = fastFrom
|
|
290
|
+
fastFrom = null
|
|
291
|
+
fast.value = false
|
|
292
|
+
return true
|
|
293
|
+
}
|
|
294
|
+
function onSurfaceUp(e: PointerEvent) {
|
|
295
|
+
if (e.button !== 0) return
|
|
296
|
+
if (endFast()) return
|
|
297
|
+
if (e.pointerType === 'mouse') {
|
|
298
|
+
toggle(true)
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
const r = (e.currentTarget as HTMLElement).getBoundingClientRect()
|
|
302
|
+
const x = (e.clientX - r.left) / (r.width || 1)
|
|
303
|
+
const t = performance.now()
|
|
304
|
+
const sideTap = x < 0.35 || x > 0.65
|
|
305
|
+
// A double tap on a side skips; while skips keep coming, single taps on that side do too
|
|
306
|
+
if (sideTap && (t - lastTap < 300 || (skipRun.side && t - skipRun.at < 1000 && skipRun.side === (x < 0.5 ? 'left' : 'right')))) {
|
|
307
|
+
clearTimeout(tapTimer)
|
|
308
|
+
lastTap = t
|
|
309
|
+
skip(x < 0.5 ? -props.seekStep : props.seekStep, true)
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
lastTap = t
|
|
313
|
+
clearTimeout(tapTimer)
|
|
314
|
+
tapTimer = setTimeout(() => (shown.value ? (shown.value = false) : poke()), 260)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ── Full screen: the player covers the page (fixed) and the document goes full screen, so menus teleported
|
|
318
|
+
// to <body> still show over it. iPhones have no Fullscreen API for elements: their video's own player then ──
|
|
319
|
+
const fullscreen = ref(false)
|
|
320
|
+
async function toggleFullscreen() {
|
|
321
|
+
if (fullscreen.value) {
|
|
322
|
+
fullscreen.value = false
|
|
323
|
+
if (document.fullscreenElement) await document.exitFullscreen().catch(() => {})
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
const doc = document.documentElement
|
|
327
|
+
if (!doc.requestFullscreen && videoEl.value && 'webkitEnterFullscreen' in videoEl.value) {
|
|
328
|
+
;(videoEl.value as HTMLVideoElement & { webkitEnterFullscreen(): void }).webkitEnterFullscreen()
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
fullscreen.value = true
|
|
332
|
+
await doc.requestFullscreen?.().catch(() => {})
|
|
333
|
+
// Phones turn to landscape where the browser allows it
|
|
334
|
+
;(screen.orientation as ScreenOrientation & { lock?: (o: string) => Promise<void> } | undefined)?.lock?.('landscape').catch(() => {})
|
|
335
|
+
}
|
|
336
|
+
function onFullscreenChange() {
|
|
337
|
+
if (!document.fullscreenElement && fullscreen.value) fullscreen.value = false
|
|
338
|
+
}
|
|
339
|
+
watch(fullscreen, (v) => emit('fullscreen', v))
|
|
340
|
+
|
|
341
|
+
// ── Picture in picture ──────────────────────────────────────────────────────────────────────────────────
|
|
342
|
+
const pipAvailable = ref(false)
|
|
343
|
+
async function togglePip() {
|
|
344
|
+
const el = videoEl.value
|
|
345
|
+
if (!el) return
|
|
346
|
+
if (document.pictureInPictureElement) await document.exitPictureInPicture().catch(() => {})
|
|
347
|
+
else await el.requestPictureInPicture().catch(() => {})
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ── Volume ──────────────────────────────────────────────────────────────────────────────────────────────
|
|
351
|
+
const volumeIcon = computed(() => {
|
|
352
|
+
const v = player.volume.value
|
|
353
|
+
return player.muted.value || v === 0 ? 'volume_off' : v < 0.5 ? 'volume_down' : 'volume_up'
|
|
354
|
+
})
|
|
355
|
+
const volumePercent = computed({
|
|
356
|
+
get: () => (player.muted.value ? 0 : Math.round(player.volume.value * 100)),
|
|
357
|
+
set: (v: number) => {
|
|
358
|
+
player.volume.value = v / 100
|
|
359
|
+
player.muted.value = v === 0
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
function toggleMute() {
|
|
363
|
+
if (player.muted.value && player.volume.value === 0) player.volume.value = 1
|
|
364
|
+
player.muted.value = !player.muted.value
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ── Subtitles ───────────────────────────────────────────────────────────────────────────────────────────
|
|
368
|
+
const subtitle = ref<number>(props.tracks?.findIndex((t) => t.default) ?? -1)
|
|
369
|
+
let lastSubtitle = Math.max(0, subtitle.value)
|
|
370
|
+
// The browser may turn tracks on by itself (one matching the user's language, say): ours wins whenever they change
|
|
371
|
+
function applySubtitles() {
|
|
372
|
+
const list = videoEl.value?.textTracks
|
|
373
|
+
if (!list) return
|
|
374
|
+
for (let i = 0; i < list.length; i++) {
|
|
375
|
+
const mode = i === subtitle.value ? 'showing' : 'disabled'
|
|
376
|
+
if (list[i]!.mode !== mode) list[i]!.mode = mode
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
watch(subtitle, (i) => {
|
|
380
|
+
if (i >= 0) lastSubtitle = i
|
|
381
|
+
applySubtitles()
|
|
382
|
+
})
|
|
383
|
+
const toggleSubtitles = () => (subtitle.value = subtitle.value >= 0 ? -1 : lastSubtitle)
|
|
384
|
+
|
|
385
|
+
// ── HLS ─────────────────────────────────────────────────────────────────────────────────────────────────
|
|
386
|
+
let hls: HlsLike | null = null
|
|
387
|
+
const levels = ref<{ height?: number; bitrate?: number }[]>([])
|
|
388
|
+
const level = ref(-1)
|
|
389
|
+
watch(level, (l) => { if (hls) hls.currentLevel = l })
|
|
390
|
+
const allSources = computed<VideoSource[]>(() => props.sources ?? (props.src ? [{ src: props.src }] : []))
|
|
391
|
+
const isHls = (s: VideoSource) => /\.m3u8(\?|#|$)/i.test(s.src) || /mpegurl/i.test(s.type ?? '')
|
|
392
|
+
// A source the browser plays itself goes in <source>; an HLS one it can't goes to hls.js
|
|
393
|
+
const hlsSource = ref<string | null>(null)
|
|
394
|
+
|
|
395
|
+
async function setupSource() {
|
|
396
|
+
hls?.destroy()
|
|
397
|
+
hls = null
|
|
398
|
+
levels.value = []
|
|
399
|
+
level.value = -1
|
|
400
|
+
hlsSource.value = null
|
|
401
|
+
const el = videoEl.value
|
|
402
|
+
if (!el || custom) return
|
|
403
|
+
const h = allSources.value.find(isHls)
|
|
404
|
+
if (!h || el.canPlayType('application/vnd.apple.mpegurl') || !props.hls) return
|
|
405
|
+
hlsSource.value = h.src
|
|
406
|
+
const { default: Hls } = await props.hls()
|
|
407
|
+
if (!Hls.isSupported() || hlsSource.value !== h.src) return
|
|
408
|
+
hls = new Hls()
|
|
409
|
+
hls.on(Hls.Events.MANIFEST_PARSED ?? 'hlsManifestParsed', () => { levels.value = hls?.levels ?? [] })
|
|
410
|
+
hls.loadSource(h.src)
|
|
411
|
+
hls.attachMedia(el)
|
|
412
|
+
}
|
|
413
|
+
const nativeSources = computed(() => allSources.value.filter((s) => !hlsSource.value || s.src !== hlsSource.value))
|
|
414
|
+
watch(allSources, async () => {
|
|
415
|
+
// A new video keeps playing if the last one was (or just ended into it)
|
|
416
|
+
const resume = player.playing.value || player.ended.value
|
|
417
|
+
await setupSource()
|
|
418
|
+
await nextTick()
|
|
419
|
+
if (!hls) videoEl.value?.load()
|
|
420
|
+
if (resume) player.play()
|
|
421
|
+
})
|
|
422
|
+
const levelLabel = (l: { height?: number; bitrate?: number }) => (l.height ? `${l.height}p` : `${Math.round((l.bitrate ?? 0) / 1000)} kbps`)
|
|
423
|
+
const qualityLabel = computed(() => (level.value < 0 ? locale.mediaQualityAuto : levelLabel(levels.value[level.value] ?? {})))
|
|
424
|
+
|
|
425
|
+
const speedLabel = (s: number) => (s === 1 ? locale.mediaSpeedNormal : `${s}×`)
|
|
426
|
+
|
|
427
|
+
// ── Keyboard (YouTube's keys) ───────────────────────────────────────────────────────────────────────────
|
|
428
|
+
function onKey(e: KeyboardEvent) {
|
|
429
|
+
const t = e.target as HTMLElement
|
|
430
|
+
if (e.ctrlKey || e.metaKey || e.altKey || t.closest('input, textarea, select, [contenteditable]')) return
|
|
431
|
+
const onControl = t !== root.value && !!t.closest('button, a, [role="slider"], [role="menuitem"]')
|
|
432
|
+
const k = e.key.length === 1 ? e.key.toLowerCase() : e.key
|
|
433
|
+
const d = player.duration.value
|
|
434
|
+
const actions: Record<string, () => void> = {
|
|
435
|
+
k: () => toggle(true),
|
|
436
|
+
j: () => skip(-props.seekStep, true),
|
|
437
|
+
l: () => skip(props.seekStep, true),
|
|
438
|
+
f: toggleFullscreen,
|
|
439
|
+
m: toggleMute,
|
|
440
|
+
'<': () => setSpeed(-1),
|
|
441
|
+
'>': () => setSpeed(1),
|
|
442
|
+
}
|
|
443
|
+
if (props.tracks?.length) actions.c = toggleSubtitles
|
|
444
|
+
if (!onControl) {
|
|
445
|
+
actions[' '] = () => toggle(true)
|
|
446
|
+
actions.ArrowLeft = () => skip(-5, true)
|
|
447
|
+
actions.ArrowRight = () => skip(5, true)
|
|
448
|
+
actions.ArrowUp = () => { volumePercent.value = Math.min(100, volumePercent.value + 5) }
|
|
449
|
+
actions.ArrowDown = () => { volumePercent.value = Math.max(0, volumePercent.value - 5) }
|
|
450
|
+
actions.Home = () => player.seek(0)
|
|
451
|
+
actions.End = () => player.seek(d)
|
|
452
|
+
}
|
|
453
|
+
if (/^[0-9]$/.test(k) && Number.isFinite(d)) actions[k] = () => player.seek((d * Number(k)) / 10)
|
|
454
|
+
if (k === 'Escape' && fullscreen.value) actions.Escape = toggleFullscreen
|
|
455
|
+
const run = actions[k]
|
|
456
|
+
if (!run) return
|
|
457
|
+
e.preventDefault()
|
|
458
|
+
e.stopPropagation()
|
|
459
|
+
run()
|
|
460
|
+
poke()
|
|
461
|
+
}
|
|
462
|
+
function setSpeed(dir: number) {
|
|
463
|
+
const list = props.speeds
|
|
464
|
+
const i = list.indexOf(player.rate.value)
|
|
465
|
+
const nextRate = list[Math.min(list.length - 1, Math.max(0, (i < 0 ? list.indexOf(1) : i) + dir))]
|
|
466
|
+
if (nextRate === undefined) return
|
|
467
|
+
player.rate.value = nextRate
|
|
468
|
+
show('speed', speedLabel(nextRate))
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// ── Lifecycle ───────────────────────────────────────────────────────────────────────────────────────────
|
|
472
|
+
onMounted(async () => {
|
|
473
|
+
ro = new ResizeObserver(([entry]) => { width.value = entry!.contentRect.width })
|
|
474
|
+
ro.observe(root.value!)
|
|
475
|
+
width.value = root.value!.clientWidth || width.value
|
|
476
|
+
document.addEventListener('fullscreenchange', onFullscreenChange)
|
|
477
|
+
pipAvailable.value = !custom && !!document.pictureInPictureEnabled
|
|
478
|
+
if (external && !custom) player.attach(videoEl.value ?? null)
|
|
479
|
+
else if (external) player.attach(null)
|
|
480
|
+
await setupSource()
|
|
481
|
+
applySubtitles()
|
|
482
|
+
videoEl.value?.textTracks?.addEventListener?.('change', applySubtitles)
|
|
483
|
+
videoEl.value?.textTracks?.addEventListener?.('addtrack', applySubtitles)
|
|
484
|
+
poke()
|
|
485
|
+
if (props.autoplay || props.playing) {
|
|
486
|
+
await player.play()
|
|
487
|
+
if (player.blocked.value) {
|
|
488
|
+
player.muted.value = true
|
|
489
|
+
await player.play()
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
})
|
|
493
|
+
onBeforeUnmount(() => {
|
|
494
|
+
ro?.disconnect()
|
|
495
|
+
hls?.destroy()
|
|
496
|
+
videoEl.value?.textTracks?.removeEventListener?.('change', applySubtitles)
|
|
497
|
+
videoEl.value?.textTracks?.removeEventListener?.('addtrack', applySubtitles)
|
|
498
|
+
document.removeEventListener('fullscreenchange', onFullscreenChange)
|
|
499
|
+
if (fullscreen.value && document.fullscreenElement) document.exitFullscreen().catch(() => {})
|
|
500
|
+
;[hideTimer, flashTimer, tapTimer, pressTimer].forEach(clearTimeout)
|
|
501
|
+
if (external) player.attach(undefined)
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
const slotProps = computed<VideoPlayerSlotProps>(() => ({ player, shown: visible.value, fullscreen: fullscreen.value, compact: compact.value }))
|
|
505
|
+
const errorText = computed(() => (player.error.value ? locale.mediaError : ''))
|
|
506
|
+
const playIcon = computed(() => (player.ended.value ? 'replay' : player.playing.value ? 'pause' : 'play_arrow'))
|
|
507
|
+
const playLabel = computed(() => (player.ended.value ? locale.mediaReplay : player.playing.value ? locale.mediaPause : locale.mediaPlay))
|
|
508
|
+
const seekBackLabel = computed(() => locale.mediaSeekBack.replace('{seconds}', String(props.seekStep)))
|
|
509
|
+
const seekForwardLabel = computed(() => locale.mediaSeekForward.replace('{seconds}', String(props.seekStep)))
|
|
510
|
+
const skipIcon = (dir: 'back' | 'forward') => ([5, 10, 30].includes(props.seekStep) ? `${dir === 'back' ? 'replay' : 'forward'}_${props.seekStep}` : dir === 'back' ? 'fast_rewind' : 'fast_forward')
|
|
511
|
+
|
|
512
|
+
// Controls sit on the picture, so they keep a dark scrim and white content in both themes (as Google Photos' and
|
|
513
|
+
// YouTube's do; Media3's gradient to the theme's background washes a light theme's picture out). The play button
|
|
514
|
+
// carries the color: primary-container, a circle while paused that squares off while playing
|
|
515
|
+
const GLASS = 'rgb(0 0 0 / 0.38)'
|
|
516
|
+
const sizes = computed(() => (compact.value ? { play: 64, skip: 48, track: 40, gap: 'gap-5' } : { play: 80, skip: 56, track: 48, gap: 'gap-8' }))
|
|
517
|
+
const playRadius = computed(() => (player.playing.value ? `${Math.round(sizes.value.play * 0.3)}px` : `${sizes.value.play / 2}px`))
|
|
518
|
+
const showTrackButtons = computed(() => hasPrevious.value || hasNext.value)
|
|
519
|
+
|
|
520
|
+
const pad2 = (n: number) => String(n).padStart(2, '0')
|
|
521
|
+
function fmt(t: number) {
|
|
522
|
+
const sec = Math.max(0, Math.floor(t || 0))
|
|
523
|
+
const h = Math.floor(sec / 3600)
|
|
524
|
+
const m = Math.floor((sec % 3600) / 60)
|
|
525
|
+
return (h ? `${h}:${pad2(m)}` : String(m)) + ':' + pad2(sec % 60)
|
|
526
|
+
}
|
|
527
|
+
const timeText = computed(() => `${fmt(player.currentTime.value)} / ${player.duration.value ? fmt(player.duration.value) : '--:--'}`)
|
|
528
|
+
const chapterTitle = computed(() => {
|
|
529
|
+
let found: SeekBarChapter | null = null
|
|
530
|
+
for (const c of props.chapters ?? []) if (c.start <= player.currentTime.value && (!found || c.start >= found.start)) found = c
|
|
531
|
+
return found?.title
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
// A video a hair off the box's ratio (854×481 in 16:9) would leave sub-pixel bars of the black shutter on two
|
|
535
|
+
// edges, which also show through the rounded corners' antialiasing: within 2%, fill the box instead
|
|
536
|
+
const naturalRatio = ref(0)
|
|
537
|
+
function onMetadata() {
|
|
538
|
+
const el = videoEl.value
|
|
539
|
+
naturalRatio.value = el && el.videoHeight ? el.videoWidth / el.videoHeight : 0
|
|
540
|
+
}
|
|
541
|
+
const fitClass = computed(() => {
|
|
542
|
+
if (props.fit === 'cover') return 'object-cover'
|
|
543
|
+
const el = root.value
|
|
544
|
+
const box = el && el.clientHeight ? el.clientWidth / el.clientHeight : 0
|
|
545
|
+
void width.value
|
|
546
|
+
return naturalRatio.value && box && Math.abs(naturalRatio.value / box - 1) < 0.02 ? 'object-cover' : 'object-contain'
|
|
547
|
+
})
|
|
548
|
+
</script>
|
|
549
|
+
|
|
550
|
+
<template>
|
|
551
|
+
<div
|
|
552
|
+
ref="root"
|
|
553
|
+
v-bind="$attrs"
|
|
554
|
+
role="region"
|
|
555
|
+
:aria-label="title || locale.mediaPlayer"
|
|
556
|
+
tabindex="-1"
|
|
557
|
+
class="m3-video-player group/player isolate overflow-hidden bg-black text-white outline-none select-none transform-gpu"
|
|
558
|
+
:class="[fullscreen && 'fixed inset-0 z-400', !visible && player.playing.value && 'cursor-none']"
|
|
559
|
+
:style="fullscreen ? undefined : { aspectRatio: aspectRatio === 'auto' ? undefined : aspectRatio }"
|
|
560
|
+
@pointermove="(e: PointerEvent) => e.pointerType !== 'touch' && poke()"
|
|
561
|
+
@keydown="onKey"
|
|
562
|
+
@focusin="poke"
|
|
563
|
+
>
|
|
564
|
+
<div class="absolute inset-0 flex items-center justify-center">
|
|
565
|
+
<slot
|
|
566
|
+
v-if="custom"
|
|
567
|
+
name="media"
|
|
568
|
+
:time="player.currentTime.value"
|
|
569
|
+
:playing="player.playing.value"
|
|
570
|
+
:rate="player.rate.value"
|
|
571
|
+
:duration="player.duration.value"
|
|
572
|
+
/>
|
|
573
|
+
<video
|
|
574
|
+
v-else
|
|
575
|
+
ref="videoEl"
|
|
576
|
+
class="h-full w-full"
|
|
577
|
+
:class="fitClass"
|
|
578
|
+
:poster="poster"
|
|
579
|
+
:loop="loop"
|
|
580
|
+
playsinline
|
|
581
|
+
preload="metadata"
|
|
582
|
+
:crossorigin="crossorigin"
|
|
583
|
+
@loadedmetadata="onMetadata"
|
|
584
|
+
>
|
|
585
|
+
<source v-for="s in nativeSources" :key="s.src" :src="s.src" :type="s.type" />
|
|
586
|
+
<track
|
|
587
|
+
v-for="(t, i) in tracks"
|
|
588
|
+
:key="t.src"
|
|
589
|
+
:kind="t.kind ?? 'subtitles'"
|
|
590
|
+
:src="t.src"
|
|
591
|
+
:srclang="t.srclang"
|
|
592
|
+
:label="t.label"
|
|
593
|
+
:default="i === subtitle"
|
|
594
|
+
/>
|
|
595
|
+
</video>
|
|
596
|
+
</div>
|
|
597
|
+
|
|
598
|
+
<!-- Scrims behind the top and bottom controls, fading with them -->
|
|
599
|
+
<Transition name="m3-video-fade">
|
|
600
|
+
<div v-if="visible" class="pointer-events-none absolute inset-0" aria-hidden="true">
|
|
601
|
+
<div v-if="fullscreen || slots.top" class="absolute inset-x-0 top-0 h-28 bg-linear-to-b from-black/60 to-transparent" />
|
|
602
|
+
<div class="absolute inset-x-0 bottom-0 h-36 bg-linear-to-t from-black/75 via-black/35 to-transparent" />
|
|
603
|
+
</div>
|
|
604
|
+
</Transition>
|
|
605
|
+
|
|
606
|
+
<!-- Taps and clicks land here, under the controls -->
|
|
607
|
+
<div class="absolute inset-0" @pointerdown="onSurfaceDown" @pointerup="onSurfaceUp" @pointercancel="endFast" @pointerleave="endFast" @dblclick="toggleFullscreen" @contextmenu.prevent />
|
|
608
|
+
|
|
609
|
+
<div v-if="player.waiting.value && !player.error.value" class="pointer-events-none absolute inset-0 flex items-center justify-center">
|
|
610
|
+
<MLoadingIndicator :size="compact ? 56 : 72" contained :label="locale.loading" />
|
|
611
|
+
</div>
|
|
612
|
+
|
|
613
|
+
<!-- 2× while held -->
|
|
614
|
+
<Transition name="m3-video-fade">
|
|
615
|
+
<div v-if="fast" class="pointer-events-none absolute inset-x-0 top-4 flex justify-center">
|
|
616
|
+
<span class="flex items-center gap-1 rounded-full bg-black/45 px-3.5 py-1.5 text-label-large backdrop-blur-md">
|
|
617
|
+
2× <MIcon name="fast_forward" :size="18" filled />
|
|
618
|
+
</span>
|
|
619
|
+
</div>
|
|
620
|
+
</Transition>
|
|
621
|
+
|
|
622
|
+
<Transition name="m3-video-flash">
|
|
623
|
+
<div
|
|
624
|
+
v-if="flash"
|
|
625
|
+
:key="flash.n"
|
|
626
|
+
class="pointer-events-none absolute inset-y-0 flex items-center justify-center"
|
|
627
|
+
:class="flash.side === 'left' ? 'left-0 w-2/5' : flash.side === 'right' ? 'right-0 w-2/5' : 'inset-x-0'"
|
|
628
|
+
aria-hidden="true"
|
|
629
|
+
>
|
|
630
|
+
<div class="flex flex-col items-center gap-2">
|
|
631
|
+
<span class="flex size-16 items-center justify-center rounded-full bg-black/45 backdrop-blur-md"><MIcon :name="flash.icon" :size="34" filled /></span>
|
|
632
|
+
<span v-if="flash.text" class="rounded-full bg-black/45 px-3 py-0.5 text-label-large backdrop-blur-md">{{ flash.text }}</span>
|
|
633
|
+
</div>
|
|
634
|
+
</div>
|
|
635
|
+
</Transition>
|
|
636
|
+
|
|
637
|
+
<div v-if="player.error.value" class="absolute inset-0 flex items-center justify-center bg-black/60 p-4 text-center">
|
|
638
|
+
<slot name="error" :error="player.error.value">
|
|
639
|
+
<p class="flex flex-col items-center gap-2 text-title-medium">
|
|
640
|
+
<MIcon name="error" :size="32" />
|
|
641
|
+
{{ errorText }}
|
|
642
|
+
</p>
|
|
643
|
+
</slot>
|
|
644
|
+
</div>
|
|
645
|
+
|
|
646
|
+
<div v-if="player.ended.value && slots.end" class="absolute inset-0">
|
|
647
|
+
<slot name="end" :player="player" :replay="() => player.play()" />
|
|
648
|
+
</div>
|
|
649
|
+
|
|
650
|
+
<Transition name="m3-video-fade">
|
|
651
|
+
<div v-if="visible && !(player.ended.value && slots.end)" class="pointer-events-none absolute inset-0">
|
|
652
|
+
<!-- Top -->
|
|
653
|
+
<div class="pointer-events-auto absolute inset-x-0 top-0" @pointerenter="overControls = true" @pointerleave="overControls = false">
|
|
654
|
+
<slot name="top" v-bind="slotProps">
|
|
655
|
+
<div v-if="fullscreen" class="flex items-center gap-2 px-2 pt-2">
|
|
656
|
+
<MIconButton icon="arrow_back" :label="locale.mediaExitFullscreen" color="#fff" @click="toggleFullscreen" />
|
|
657
|
+
<p v-if="title" class="min-w-0 flex-1 truncate text-title-medium">{{ title }}</p>
|
|
658
|
+
</div>
|
|
659
|
+
</slot>
|
|
660
|
+
</div>
|
|
661
|
+
|
|
662
|
+
<!-- Center: on the picture's center, whatever the top and bottom hold -->
|
|
663
|
+
<div v-if="!player.waiting.value && !player.error.value" class="absolute inset-0 flex items-center justify-center" :class="sizes.gap">
|
|
664
|
+
<slot name="center" v-bind="slotProps">
|
|
665
|
+
<MIconButton
|
|
666
|
+
v-if="showTrackButtons"
|
|
667
|
+
icon="skip_previous"
|
|
668
|
+
:label="locale.previous"
|
|
669
|
+
:size="sizes.track"
|
|
670
|
+
:icon-size="compact ? 24 : 28"
|
|
671
|
+
:aria-disabled="!hasPrevious || undefined"
|
|
672
|
+
:tabindex="hasPrevious ? undefined : -1"
|
|
673
|
+
variant="filled"
|
|
674
|
+
:color="GLASS"
|
|
675
|
+
icon-filled
|
|
676
|
+
class="backdrop-blur-md" :class="hasPrevious ? 'pointer-events-auto' : 'opacity-40'"
|
|
677
|
+
@click="previous"
|
|
678
|
+
/>
|
|
679
|
+
<MIconButton
|
|
680
|
+
v-if="!player.live.value"
|
|
681
|
+
:icon="skipIcon('back')"
|
|
682
|
+
:label="seekBackLabel"
|
|
683
|
+
:size="sizes.skip"
|
|
684
|
+
:icon-size="compact ? 26 : 30"
|
|
685
|
+
variant="filled"
|
|
686
|
+
:color="GLASS"
|
|
687
|
+
class="pointer-events-auto backdrop-blur-md"
|
|
688
|
+
@click="skip(-seekStep)"
|
|
689
|
+
/>
|
|
690
|
+
<MIconButton
|
|
691
|
+
:icon="playIcon"
|
|
692
|
+
:label="playLabel"
|
|
693
|
+
:size="sizes.play"
|
|
694
|
+
:icon-size="compact ? 32 : 40"
|
|
695
|
+
variant="filled"
|
|
696
|
+
color="var(--color-primary-container)"
|
|
697
|
+
content-color="on-primary-container"
|
|
698
|
+
icon-filled
|
|
699
|
+
class="m3-video-play pointer-events-auto shadow-elevation-2"
|
|
700
|
+
:style="{ borderRadius: playRadius }"
|
|
701
|
+
@click="toggle()"
|
|
702
|
+
/>
|
|
703
|
+
<MIconButton
|
|
704
|
+
v-if="!player.live.value"
|
|
705
|
+
:icon="skipIcon('forward')"
|
|
706
|
+
:label="seekForwardLabel"
|
|
707
|
+
:size="sizes.skip"
|
|
708
|
+
:icon-size="compact ? 26 : 30"
|
|
709
|
+
variant="filled"
|
|
710
|
+
:color="GLASS"
|
|
711
|
+
class="pointer-events-auto backdrop-blur-md"
|
|
712
|
+
@click="skip(seekStep)"
|
|
713
|
+
/>
|
|
714
|
+
<MIconButton
|
|
715
|
+
v-if="showTrackButtons"
|
|
716
|
+
icon="skip_next"
|
|
717
|
+
:label="locale.next"
|
|
718
|
+
:size="sizes.track"
|
|
719
|
+
:icon-size="compact ? 24 : 28"
|
|
720
|
+
:aria-disabled="!hasNext || undefined"
|
|
721
|
+
:tabindex="hasNext ? undefined : -1"
|
|
722
|
+
variant="filled"
|
|
723
|
+
:color="GLASS"
|
|
724
|
+
icon-filled
|
|
725
|
+
class="backdrop-blur-md" :class="hasNext ? 'pointer-events-auto' : 'opacity-40'"
|
|
726
|
+
@click="next"
|
|
727
|
+
/>
|
|
728
|
+
</slot>
|
|
729
|
+
</div>
|
|
730
|
+
|
|
731
|
+
<!-- Bottom -->
|
|
732
|
+
<div class="pointer-events-auto absolute inset-x-0 bottom-0" @pointerenter="overControls = true" @pointerleave="overControls = false">
|
|
733
|
+
<slot name="bottom" v-bind="slotProps">
|
|
734
|
+
<div :class="compact ? 'px-2 pb-1' : 'px-4 pb-2'">
|
|
735
|
+
<MSeekBar
|
|
736
|
+
v-if="!player.live.value"
|
|
737
|
+
v-model="player.currentTime.value"
|
|
738
|
+
:duration="player.duration.value"
|
|
739
|
+
:buffered="player.buffered.value"
|
|
740
|
+
:chapters="chapters"
|
|
741
|
+
:playing="player.playing.value && !player.waiting.value"
|
|
742
|
+
:playback-rate="player.rate.value"
|
|
743
|
+
:color="color"
|
|
744
|
+
track-color="rgb(255 255 255 / 0.28)"
|
|
745
|
+
variant="line"
|
|
746
|
+
:size="compact ? 'xs' : 'sm'"
|
|
747
|
+
time="none"
|
|
748
|
+
class="px-1"
|
|
749
|
+
/>
|
|
750
|
+
<div class="flex items-center gap-1">
|
|
751
|
+
<span v-if="player.live.value" class="ml-2 flex items-center gap-1.5 rounded-full bg-error px-2.5 py-0.5 text-label-medium text-on-error">
|
|
752
|
+
<span class="size-1.5 rounded-full bg-on-error" />{{ locale.mediaLive }}
|
|
753
|
+
</span>
|
|
754
|
+
<p v-else class="ml-1 min-w-0 truncate text-label-large tabular-nums">
|
|
755
|
+
{{ timeText }}<span v-if="chapterTitle && !compact" class="text-white/75"> · {{ chapterTitle }}</span>
|
|
756
|
+
</p>
|
|
757
|
+
<span class="flex-1" />
|
|
758
|
+
<div class="group/vol flex items-center">
|
|
759
|
+
<div v-if="!compact" class="w-0 overflow-hidden transition-[width] duration-300 ease-[cubic-bezier(.2,0,0,1)] group-focus-within/vol:w-24 group-hover/vol:w-24">
|
|
760
|
+
<MSlider v-model="volumePercent" :min="0" :max="100" size="xs" class="w-22 px-1" />
|
|
761
|
+
</div>
|
|
762
|
+
<MIconButton :icon="volumeIcon" :label="player.muted.value ? locale.mediaUnmute : locale.mediaMute" color="#fff" :size="compact ? 'xs' : 'sm'" @click="toggleMute" />
|
|
763
|
+
</div>
|
|
764
|
+
<MIconButton
|
|
765
|
+
v-if="tracks?.length"
|
|
766
|
+
:icon="subtitle >= 0 ? 'subtitles' : 'subtitles_off'"
|
|
767
|
+
:label="locale.mediaSubtitles"
|
|
768
|
+
color="#fff"
|
|
769
|
+
:size="compact ? 'xs' : 'sm'"
|
|
770
|
+
:icon-filled="subtitle >= 0"
|
|
771
|
+
@click="toggleSubtitles"
|
|
772
|
+
/>
|
|
773
|
+
<MMenu ref="menu" submenu-mode="push" align="right">
|
|
774
|
+
<template #trigger>
|
|
775
|
+
<MIconButton icon="settings" :label="locale.mediaSettings" color="#fff" :size="compact ? 'xs' : 'sm'" />
|
|
776
|
+
</template>
|
|
777
|
+
<MMenuItem icon="slow_motion_video">
|
|
778
|
+
{{ locale.mediaSpeed }} · {{ speedLabel(player.rate.value) }}
|
|
779
|
+
<template #children>
|
|
780
|
+
<MMenuItem v-for="s in speeds" :key="s" :selected="player.rate.value === s" @click="player.rate.value = s">{{ speedLabel(s) }}</MMenuItem>
|
|
781
|
+
</template>
|
|
782
|
+
</MMenuItem>
|
|
783
|
+
<MMenuItem v-if="tracks?.length" icon="subtitles">
|
|
784
|
+
{{ locale.mediaSubtitles }} · {{ subtitle >= 0 ? tracks[subtitle]?.label : locale.mediaSubtitlesOff }}
|
|
785
|
+
<template #children>
|
|
786
|
+
<MMenuItem :selected="subtitle < 0" @click="subtitle = -1">{{ locale.mediaSubtitlesOff }}</MMenuItem>
|
|
787
|
+
<MMenuItem v-for="(t, i) in tracks" :key="t.src" :selected="subtitle === i" @click="subtitle = i">{{ t.label }}</MMenuItem>
|
|
788
|
+
</template>
|
|
789
|
+
</MMenuItem>
|
|
790
|
+
<MMenuItem v-if="levels.length > 1" icon="tune">
|
|
791
|
+
{{ locale.mediaQuality }} · {{ qualityLabel }}
|
|
792
|
+
<template #children>
|
|
793
|
+
<MMenuItem :selected="level < 0" @click="level = -1">{{ locale.mediaQualityAuto }}</MMenuItem>
|
|
794
|
+
<MMenuItem v-for="(l, i) in levels" :key="i" :selected="level === i" @click="level = i">{{ levelLabel(l) }}</MMenuItem>
|
|
795
|
+
</template>
|
|
796
|
+
</MMenuItem>
|
|
797
|
+
<slot name="settings" :player="player" />
|
|
798
|
+
</MMenu>
|
|
799
|
+
<MIconButton
|
|
800
|
+
v-if="pipAvailable && !compact"
|
|
801
|
+
icon="picture_in_picture_alt"
|
|
802
|
+
:label="locale.mediaPictureInPicture"
|
|
803
|
+
color="#fff"
|
|
804
|
+
size="sm"
|
|
805
|
+
@click="togglePip"
|
|
806
|
+
/>
|
|
807
|
+
<MIconButton
|
|
808
|
+
:icon="fullscreen ? 'fullscreen_exit' : 'fullscreen'"
|
|
809
|
+
:label="fullscreen ? locale.mediaExitFullscreen : locale.mediaFullscreen"
|
|
810
|
+
color="#fff"
|
|
811
|
+
:size="compact ? 'xs' : 'sm'"
|
|
812
|
+
@click="toggleFullscreen"
|
|
813
|
+
/>
|
|
814
|
+
</div>
|
|
815
|
+
</div>
|
|
816
|
+
</slot>
|
|
817
|
+
</div>
|
|
818
|
+
</div>
|
|
819
|
+
</Transition>
|
|
820
|
+
</div>
|
|
821
|
+
</template>
|
|
822
|
+
|
|
823
|
+
<style>
|
|
824
|
+
/* Root default in the base layer, so a consumer's position class (absolute…) wins */
|
|
825
|
+
@layer base {
|
|
826
|
+
.m3-video-player { position: relative; }
|
|
827
|
+
}
|
|
828
|
+
.m3-video-player video::cue {
|
|
829
|
+
background: color-mix(in srgb, var(--color-scrim) 75%, transparent);
|
|
830
|
+
color: #fff;
|
|
831
|
+
}
|
|
832
|
+
.m3-video-play { transition: border-radius 350ms cubic-bezier(0.2, 0, 0, 1); }
|
|
833
|
+
.m3-video-fade-enter-active,
|
|
834
|
+
.m3-video-fade-leave-active { transition: opacity 250ms cubic-bezier(0.2, 0, 0, 1); }
|
|
835
|
+
.m3-video-fade-enter-from,
|
|
836
|
+
.m3-video-fade-leave-to { opacity: 0; }
|
|
837
|
+
.m3-video-flash-leave-active { transition: opacity 400ms ease, transform 400ms ease; }
|
|
838
|
+
.m3-video-flash-leave-to { opacity: 0; transform: scale(1.3); }
|
|
839
|
+
</style>
|