@ysgroup/ui 0.1.41 → 0.1.43
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/package.json +7 -4
- package/src/components/YsCountBadge.vue +4 -1
- package/src/components/YsDocViewer.vue +218 -0
- package/src/components/YsFilePreview.vue +227 -158
- package/src/components/YsMediaPlayer.vue +720 -0
- package/src/components/YsPdfViewer.vue +752 -0
- package/src/components/YsRowActionMenu.vue +1 -3
- package/src/components/YsSheetViewer.vue +461 -0
- package/src/components/YsViewerIcon.vue +53 -0
- package/src/components/YsViewerState.vue +66 -0
- package/src/filePreview.ts +244 -10
- package/src/index.ts +16 -0
- package/src/preview/docx.ts +27 -0
- package/src/preview/media.ts +97 -0
- package/src/preview/pdfAssets.ts +381 -0
- package/src/preview/pdfLayout.ts +125 -0
- package/src/preview/pdfjs.ts +38 -0
- package/src/preview/sheetGrid.ts +205 -0
- package/src/preview/viewer.css +255 -0
- package/src/vTip.ts +93 -0
- package/src/vendor/docx-preview.LICENSE.txt +206 -0
- package/src/vendor/docx-preview.d.mts +25 -0
- package/src/vendor/docx-preview.mjs +42 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
<!-- YsMediaPlayer —— 统一外观的视频/音频播放器(不用浏览器原生控件)。
|
|
2
|
+
视频:深色画面区,底部渐隐控制条(播放/暂停、可拖动进度条带缓冲显示和悬停时间、当前/总时长、音量与静音、
|
|
3
|
+
倍速 0.5~2×、画中画(浏览器支持时)、全屏),播放中鼠标静止 2.5 秒自动隐藏;单击画面播放/暂停,双击全屏。
|
|
4
|
+
音频:同风格的精简条(圆形播放键、标题、进度、时长、倍速、音量),底色跟主题。
|
|
5
|
+
快捷键(播放器获得焦点时):空格/K 播放暂停,← → 快退快进 5 秒,↑ ↓ 音量,F 全屏,M 静音。
|
|
6
|
+
处理过的按键会 preventDefault,外层(如 YsFilePreview 的 ← → 切换文件)据此跳过。 -->
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
9
|
+
import YsViewerIcon from "./YsViewerIcon.vue";
|
|
10
|
+
import "../preview/viewer.css";
|
|
11
|
+
import { MEDIA_SPEEDS, bufferedEnd, clampTime, clampVolume, formatMediaTime, formatSpeed, mediaKeyAction, pointerRatio } from "../preview/media";
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(
|
|
14
|
+
defineProps<{
|
|
15
|
+
/** 媒体地址(blob: 或 http 地址)。 */
|
|
16
|
+
src: string;
|
|
17
|
+
type?: "video" | "audio";
|
|
18
|
+
/** 音频条上显示的标题(一般是文件名)。 */
|
|
19
|
+
title?: string;
|
|
20
|
+
poster?: string;
|
|
21
|
+
autoplay?: boolean;
|
|
22
|
+
}>(),
|
|
23
|
+
{ type: "video", title: "", poster: undefined, autoplay: false },
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{ error: [message: string] }>();
|
|
27
|
+
|
|
28
|
+
const root = ref<HTMLElement | null>(null);
|
|
29
|
+
const media = ref<HTMLMediaElement | null>(null);
|
|
30
|
+
const playing = ref(false);
|
|
31
|
+
const waiting = ref(true);
|
|
32
|
+
const duration = ref(0);
|
|
33
|
+
const time = ref(0);
|
|
34
|
+
const buffered = ref(0);
|
|
35
|
+
const volume = ref(1);
|
|
36
|
+
const muted = ref(false);
|
|
37
|
+
const rate = ref(1);
|
|
38
|
+
const errorText = ref("");
|
|
39
|
+
const idle = ref(false);
|
|
40
|
+
const isFullscreen = ref(false);
|
|
41
|
+
const seeking = ref<number | null>(null);
|
|
42
|
+
const hover = ref<number | null>(null);
|
|
43
|
+
const pipSupported = ref(false);
|
|
44
|
+
let idleTimer = 0;
|
|
45
|
+
|
|
46
|
+
const isVideo = computed(() => props.type !== "audio");
|
|
47
|
+
const shownTime = computed(() => (seeking.value !== null ? seeking.value * duration.value : time.value));
|
|
48
|
+
const playedPercent = computed(() => (duration.value ? (shownTime.value / duration.value) * 100 : 0));
|
|
49
|
+
const bufferedPercent = computed(() => (duration.value ? Math.min(100, (buffered.value / duration.value) * 100) : 0));
|
|
50
|
+
const volumeIcon = computed(() => (muted.value || volume.value === 0 ? "mute" : volume.value < 0.5 ? "volume-low" : "volume"));
|
|
51
|
+
const timeText = computed(() => `${formatMediaTime(shownTime.value, duration.value)} / ${formatMediaTime(duration.value)}`);
|
|
52
|
+
|
|
53
|
+
function el(): HTMLMediaElement | null {
|
|
54
|
+
return media.value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ---------- 媒体事件 ----------
|
|
58
|
+
function sync() {
|
|
59
|
+
const m = el();
|
|
60
|
+
if (!m) return;
|
|
61
|
+
playing.value = !m.paused && !m.ended;
|
|
62
|
+
duration.value = Number.isFinite(m.duration) ? m.duration : 0;
|
|
63
|
+
time.value = m.currentTime;
|
|
64
|
+
buffered.value = bufferedEnd(m.buffered, m.currentTime);
|
|
65
|
+
volume.value = m.volume;
|
|
66
|
+
muted.value = m.muted;
|
|
67
|
+
rate.value = m.playbackRate;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function onError() {
|
|
71
|
+
const code = el()?.error?.code;
|
|
72
|
+
errorText.value =
|
|
73
|
+
code === 4 || code === 3
|
|
74
|
+
? `浏览器不支持此${isVideo.value ? "视频" : "音频"}的编码格式(如 H.265/HEVC、AVI、WMV、AMR),请下载后用本地播放器打开。`
|
|
75
|
+
: `${isVideo.value ? "视频" : "音频"}加载失败,请重试或下载后播放。`;
|
|
76
|
+
waiting.value = false;
|
|
77
|
+
emit("error", errorText.value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ---------- 控制 ----------
|
|
81
|
+
async function toggle() {
|
|
82
|
+
const m = el();
|
|
83
|
+
if (!m || errorText.value) return;
|
|
84
|
+
if (m.paused || m.ended) await m.play().catch(() => undefined);
|
|
85
|
+
else m.pause();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function seekBy(delta: number) {
|
|
89
|
+
const m = el();
|
|
90
|
+
if (!m) return;
|
|
91
|
+
m.currentTime = clampTime(m.currentTime + delta, m.duration);
|
|
92
|
+
sync();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function setVolume(value: number) {
|
|
96
|
+
const m = el();
|
|
97
|
+
if (!m) return;
|
|
98
|
+
m.volume = clampVolume(value);
|
|
99
|
+
m.muted = m.volume === 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function toggleMute() {
|
|
103
|
+
const m = el();
|
|
104
|
+
if (!m) return;
|
|
105
|
+
if (m.muted || m.volume === 0) {
|
|
106
|
+
m.muted = false;
|
|
107
|
+
if (m.volume === 0) m.volume = 0.5;
|
|
108
|
+
} else m.muted = true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function setRate(value: number) {
|
|
112
|
+
const m = el();
|
|
113
|
+
if (m) m.playbackRate = value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function toggleFullscreen() {
|
|
117
|
+
if (!isVideo.value) return;
|
|
118
|
+
if (document.fullscreenElement) {
|
|
119
|
+
await document.exitFullscreen().catch(() => undefined);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const target = root.value;
|
|
123
|
+
if (target?.requestFullscreen) await target.requestFullscreen().catch(() => undefined);
|
|
124
|
+
else (el() as HTMLVideoElement & { webkitEnterFullscreen?: () => void })?.webkitEnterFullscreen?.();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function togglePip() {
|
|
128
|
+
const video = el() as HTMLVideoElement | null;
|
|
129
|
+
if (!video) return;
|
|
130
|
+
if (document.pictureInPictureElement) await document.exitPictureInPicture().catch(() => undefined);
|
|
131
|
+
else await video.requestPictureInPicture?.().catch(() => undefined);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function onKeydown(event: KeyboardEvent) {
|
|
135
|
+
const target = event.target as HTMLElement | null;
|
|
136
|
+
if (target?.closest("input, textarea, .el-dropdown-menu")) return;
|
|
137
|
+
const action = mediaKeyAction(event, { video: isVideo.value });
|
|
138
|
+
if (!action) return;
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
wake();
|
|
141
|
+
if (action.type === "toggle") void toggle();
|
|
142
|
+
else if (action.type === "seek") seekBy(action.delta);
|
|
143
|
+
else if (action.type === "volume") {
|
|
144
|
+
const m = el();
|
|
145
|
+
if (m) setVolume((m.muted ? 0 : m.volume) + action.delta);
|
|
146
|
+
}
|
|
147
|
+
else if (action.type === "mute") toggleMute();
|
|
148
|
+
else void toggleFullscreen();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ---------- 进度条拖动 ----------
|
|
152
|
+
function ratioOf(event: PointerEvent): number {
|
|
153
|
+
return pointerRatio(event.clientX, (event.currentTarget as HTMLElement).getBoundingClientRect());
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function onSeekDown(event: PointerEvent) {
|
|
157
|
+
if (!duration.value || event.button !== 0) return;
|
|
158
|
+
(event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId);
|
|
159
|
+
seeking.value = ratioOf(event);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function onSeekMove(event: PointerEvent) {
|
|
163
|
+
const ratio = ratioOf(event);
|
|
164
|
+
hover.value = ratio;
|
|
165
|
+
if (seeking.value !== null) seeking.value = ratio;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function onSeekUp(event: PointerEvent) {
|
|
169
|
+
if (seeking.value === null) return;
|
|
170
|
+
const m = el();
|
|
171
|
+
const ratio = ratioOf(event);
|
|
172
|
+
seeking.value = null;
|
|
173
|
+
if (m && duration.value) {
|
|
174
|
+
m.currentTime = clampTime(ratio * duration.value, duration.value);
|
|
175
|
+
sync();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function onSeekKey(event: KeyboardEvent) {
|
|
180
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
event.stopPropagation();
|
|
183
|
+
seekBy(event.key === "ArrowLeft" ? -5 : 5);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function onVolumePointer(event: PointerEvent) {
|
|
188
|
+
if (event.type === "pointerdown") (event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId);
|
|
189
|
+
else if (!(event.buttons & 1)) return;
|
|
190
|
+
setVolume(ratioOf(event));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ---------- 控制条自动隐藏 ----------
|
|
194
|
+
function wake() {
|
|
195
|
+
idle.value = false;
|
|
196
|
+
window.clearTimeout(idleTimer);
|
|
197
|
+
if (playing.value && isVideo.value) idleTimer = window.setTimeout(() => (idle.value = true), 2500);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
watch(playing, () => wake());
|
|
201
|
+
|
|
202
|
+
function onFullscreenChange() {
|
|
203
|
+
isFullscreen.value = document.fullscreenElement === root.value;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
watch(
|
|
207
|
+
() => props.src,
|
|
208
|
+
() => {
|
|
209
|
+
errorText.value = "";
|
|
210
|
+
waiting.value = true;
|
|
211
|
+
time.value = 0;
|
|
212
|
+
duration.value = 0;
|
|
213
|
+
buffered.value = 0;
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
onMounted(() => {
|
|
218
|
+
pipSupported.value = isVideo.value && "pictureInPictureEnabled" in document && Boolean(document.pictureInPictureEnabled);
|
|
219
|
+
document.addEventListener("fullscreenchange", onFullscreenChange);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
onBeforeUnmount(() => {
|
|
223
|
+
window.clearTimeout(idleTimer);
|
|
224
|
+
document.removeEventListener("fullscreenchange", onFullscreenChange);
|
|
225
|
+
el()?.pause();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
defineExpose({ toggle, seekBy, setVolume, setRate });
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<template>
|
|
232
|
+
<div
|
|
233
|
+
ref="root"
|
|
234
|
+
class="ys-media"
|
|
235
|
+
:class="[isVideo ? 'is-video' : 'is-audio', { 'is-idle': idle && playing && seeking === null, 'is-paused': !playing, 'is-fullscreen': isFullscreen }]"
|
|
236
|
+
tabindex="0"
|
|
237
|
+
role="group"
|
|
238
|
+
:aria-label="isVideo ? '视频播放器' : '音频播放器'"
|
|
239
|
+
@keydown="onKeydown"
|
|
240
|
+
@pointermove="wake"
|
|
241
|
+
>
|
|
242
|
+
<video
|
|
243
|
+
v-if="isVideo"
|
|
244
|
+
ref="media"
|
|
245
|
+
class="ys-media__video"
|
|
246
|
+
:src="src"
|
|
247
|
+
:poster="poster"
|
|
248
|
+
:autoplay="autoplay"
|
|
249
|
+
preload="metadata"
|
|
250
|
+
playsinline
|
|
251
|
+
@click="toggle"
|
|
252
|
+
@dblclick="toggleFullscreen"
|
|
253
|
+
@play="sync"
|
|
254
|
+
@pause="sync"
|
|
255
|
+
@ended="sync"
|
|
256
|
+
@timeupdate="sync"
|
|
257
|
+
@durationchange="sync"
|
|
258
|
+
@progress="sync"
|
|
259
|
+
@volumechange="sync"
|
|
260
|
+
@ratechange="sync"
|
|
261
|
+
@loadedmetadata="sync"
|
|
262
|
+
@waiting="waiting = true"
|
|
263
|
+
@canplay="waiting = false"
|
|
264
|
+
@playing="waiting = false"
|
|
265
|
+
@error="onError"
|
|
266
|
+
/>
|
|
267
|
+
<audio
|
|
268
|
+
v-else
|
|
269
|
+
ref="media"
|
|
270
|
+
:src="src"
|
|
271
|
+
:autoplay="autoplay"
|
|
272
|
+
preload="metadata"
|
|
273
|
+
@play="sync"
|
|
274
|
+
@pause="sync"
|
|
275
|
+
@ended="sync"
|
|
276
|
+
@timeupdate="sync"
|
|
277
|
+
@durationchange="sync"
|
|
278
|
+
@progress="sync"
|
|
279
|
+
@volumechange="sync"
|
|
280
|
+
@ratechange="sync"
|
|
281
|
+
@loadedmetadata="sync"
|
|
282
|
+
@waiting="waiting = true"
|
|
283
|
+
@canplay="waiting = false"
|
|
284
|
+
@playing="waiting = false"
|
|
285
|
+
@error="onError"
|
|
286
|
+
/>
|
|
287
|
+
|
|
288
|
+
<template v-if="isVideo">
|
|
289
|
+
<div v-if="errorText" class="ys-media__error" role="alert">
|
|
290
|
+
<YsViewerIcon name="alert" />
|
|
291
|
+
<span>{{ errorText }}</span>
|
|
292
|
+
</div>
|
|
293
|
+
<div v-else-if="waiting && !playing && !duration" class="ys-media__center"><div class="ys-viewer__spinner ys-media__spinner" /></div>
|
|
294
|
+
<button v-else-if="!playing" type="button" class="ys-media__big-play" aria-label="播放" @click="toggle"><YsViewerIcon name="play" /></button>
|
|
295
|
+
<div v-else-if="waiting" class="ys-media__center"><div class="ys-viewer__spinner ys-media__spinner" /></div>
|
|
296
|
+
</template>
|
|
297
|
+
|
|
298
|
+
<button v-if="!isVideo" type="button" class="ys-media__round" :disabled="!!errorText" :aria-label="playing ? '暂停' : '播放'" @click="toggle">
|
|
299
|
+
<YsViewerIcon :name="playing ? 'pause' : 'play'" />
|
|
300
|
+
</button>
|
|
301
|
+
|
|
302
|
+
<div class="ys-media__controls">
|
|
303
|
+
<div v-if="!isVideo" class="ys-media__headline">
|
|
304
|
+
<span class="ys-media__title" :title="title">{{ errorText || title || "音频" }}</span>
|
|
305
|
+
<span class="ys-media__time">{{ timeText }}</span>
|
|
306
|
+
</div>
|
|
307
|
+
<div
|
|
308
|
+
class="ys-media__progress"
|
|
309
|
+
role="slider"
|
|
310
|
+
tabindex="0"
|
|
311
|
+
aria-label="播放进度"
|
|
312
|
+
:aria-valuemin="0"
|
|
313
|
+
:aria-valuemax="Math.round(duration)"
|
|
314
|
+
:aria-valuenow="Math.round(shownTime)"
|
|
315
|
+
:aria-valuetext="timeText"
|
|
316
|
+
@pointerdown="onSeekDown"
|
|
317
|
+
@pointermove="onSeekMove"
|
|
318
|
+
@pointerup="onSeekUp"
|
|
319
|
+
@pointercancel="seeking = null"
|
|
320
|
+
@pointerleave="hover = null"
|
|
321
|
+
@keydown="onSeekKey"
|
|
322
|
+
>
|
|
323
|
+
<div class="ys-media__track">
|
|
324
|
+
<div class="ys-media__buffered" :style="{ width: `${bufferedPercent}%` }" />
|
|
325
|
+
<div class="ys-media__played" :style="{ width: `${playedPercent}%` }" />
|
|
326
|
+
</div>
|
|
327
|
+
<div class="ys-media__knob" :style="{ left: `${playedPercent}%` }" />
|
|
328
|
+
<div v-if="hover !== null && duration" class="ys-media__hover" :style="{ left: `${hover * 100}%` }">{{ formatMediaTime(hover * duration, duration) }}</div>
|
|
329
|
+
</div>
|
|
330
|
+
<div class="ys-media__row">
|
|
331
|
+
<button v-if="isVideo" type="button" class="ys-media__btn" :aria-label="playing ? '暂停(空格)' : '播放(空格)'" :title="playing ? '暂停(空格)' : '播放(空格)'" @click="toggle">
|
|
332
|
+
<YsViewerIcon :name="playing ? 'pause' : 'play'" />
|
|
333
|
+
</button>
|
|
334
|
+
<div class="ys-media__volume">
|
|
335
|
+
<button type="button" class="ys-media__btn" :aria-label="muted ? '取消静音(M)' : '静音(M)'" :title="muted ? '取消静音(M)' : '静音(M)'" @click="toggleMute">
|
|
336
|
+
<YsViewerIcon :name="volumeIcon" />
|
|
337
|
+
</button>
|
|
338
|
+
<div
|
|
339
|
+
class="ys-media__volume-bar"
|
|
340
|
+
role="slider"
|
|
341
|
+
aria-label="音量"
|
|
342
|
+
:aria-valuemin="0"
|
|
343
|
+
:aria-valuemax="100"
|
|
344
|
+
:aria-valuenow="Math.round((muted ? 0 : volume) * 100)"
|
|
345
|
+
@pointerdown="onVolumePointer"
|
|
346
|
+
@pointermove="onVolumePointer"
|
|
347
|
+
>
|
|
348
|
+
<div class="ys-media__track"><div class="ys-media__played" :style="{ width: `${(muted ? 0 : volume) * 100}%` }" /></div>
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
351
|
+
<span v-if="isVideo" class="ys-media__time">{{ timeText }}</span>
|
|
352
|
+
<span class="ys-media__spacer" />
|
|
353
|
+
<el-dropdown trigger="click" placement="top" popper-class="ys-viewer-menu" :teleported="!isFullscreen" @command="setRate">
|
|
354
|
+
<button type="button" class="ys-media__btn ys-media__speed" aria-label="倍速" title="倍速">{{ rate === 1 ? "倍速" : formatSpeed(rate) }}</button>
|
|
355
|
+
<template #dropdown>
|
|
356
|
+
<el-dropdown-menu>
|
|
357
|
+
<el-dropdown-item v-for="s in [...MEDIA_SPEEDS].reverse()" :key="s" :command="s" :class="{ 'is-current': rate === s }">{{ formatSpeed(s) }}</el-dropdown-item>
|
|
358
|
+
</el-dropdown-menu>
|
|
359
|
+
</template>
|
|
360
|
+
</el-dropdown>
|
|
361
|
+
<button v-if="pipSupported" type="button" class="ys-media__btn" aria-label="画中画" title="画中画" @click="togglePip"><YsViewerIcon name="pip" /></button>
|
|
362
|
+
<button v-if="isVideo" type="button" class="ys-media__btn" :aria-label="isFullscreen ? '退出全屏(F)' : '全屏(F)'" :title="isFullscreen ? '退出全屏(F)' : '全屏(F)'" @click="toggleFullscreen">
|
|
363
|
+
<YsViewerIcon :name="isFullscreen ? 'minimize' : 'maximize'" />
|
|
364
|
+
</button>
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
</div>
|
|
368
|
+
</template>
|
|
369
|
+
|
|
370
|
+
<style scoped>
|
|
371
|
+
.ys-media {
|
|
372
|
+
position: relative;
|
|
373
|
+
box-sizing: border-box;
|
|
374
|
+
font-family: var(--ys-font-family);
|
|
375
|
+
font-variant-numeric: tabular-nums;
|
|
376
|
+
user-select: none;
|
|
377
|
+
-webkit-tap-highlight-color: transparent;
|
|
378
|
+
}
|
|
379
|
+
.ys-media:focus {
|
|
380
|
+
outline: none;
|
|
381
|
+
}
|
|
382
|
+
.ys-media:focus-visible {
|
|
383
|
+
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ys-color-primary) 55%, transparent);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/* ---------- 视频 ---------- */
|
|
387
|
+
.ys-media.is-video {
|
|
388
|
+
display: flex;
|
|
389
|
+
align-items: center;
|
|
390
|
+
justify-content: center;
|
|
391
|
+
width: 100%;
|
|
392
|
+
height: 100%;
|
|
393
|
+
min-height: 200px;
|
|
394
|
+
overflow: hidden;
|
|
395
|
+
background: var(--ys-color-media-bg);
|
|
396
|
+
color: var(--ys-color-media-text);
|
|
397
|
+
}
|
|
398
|
+
.ys-media__video {
|
|
399
|
+
display: block;
|
|
400
|
+
max-width: 100%;
|
|
401
|
+
max-height: 100%;
|
|
402
|
+
object-fit: contain;
|
|
403
|
+
}
|
|
404
|
+
.ys-media.is-video.is-idle {
|
|
405
|
+
cursor: none;
|
|
406
|
+
}
|
|
407
|
+
.ys-media.is-video .ys-media__controls {
|
|
408
|
+
position: absolute;
|
|
409
|
+
right: 0;
|
|
410
|
+
bottom: 0;
|
|
411
|
+
left: 0;
|
|
412
|
+
padding: 28px 14px 8px;
|
|
413
|
+
background: linear-gradient(to top, var(--ys-color-media-control), transparent);
|
|
414
|
+
opacity: 1;
|
|
415
|
+
transition: opacity 0.25s;
|
|
416
|
+
}
|
|
417
|
+
.ys-media.is-video.is-idle .ys-media__controls {
|
|
418
|
+
opacity: 0;
|
|
419
|
+
}
|
|
420
|
+
.ys-media__center,
|
|
421
|
+
.ys-media__big-play,
|
|
422
|
+
.ys-media__error {
|
|
423
|
+
position: absolute;
|
|
424
|
+
top: 50%;
|
|
425
|
+
left: 50%;
|
|
426
|
+
transform: translate(-50%, -50%);
|
|
427
|
+
}
|
|
428
|
+
.ys-media__spinner {
|
|
429
|
+
width: 40px;
|
|
430
|
+
height: 40px;
|
|
431
|
+
border-color: color-mix(in srgb, var(--ys-color-media-text) 20%, transparent);
|
|
432
|
+
border-top-color: var(--ys-color-media-text);
|
|
433
|
+
}
|
|
434
|
+
.ys-media__big-play {
|
|
435
|
+
display: inline-flex;
|
|
436
|
+
align-items: center;
|
|
437
|
+
justify-content: center;
|
|
438
|
+
width: 64px;
|
|
439
|
+
height: 64px;
|
|
440
|
+
padding: 0 0 0 4px;
|
|
441
|
+
border: 1px solid color-mix(in srgb, var(--ys-color-media-text) 25%, transparent);
|
|
442
|
+
border-radius: 50%;
|
|
443
|
+
background: color-mix(in srgb, var(--ys-color-media-bg) 55%, transparent);
|
|
444
|
+
color: var(--ys-color-media-text);
|
|
445
|
+
cursor: pointer;
|
|
446
|
+
backdrop-filter: blur(6px);
|
|
447
|
+
transition:
|
|
448
|
+
transform 0.15s,
|
|
449
|
+
background-color 0.15s;
|
|
450
|
+
}
|
|
451
|
+
.ys-media__big-play:hover {
|
|
452
|
+
background: var(--ys-color-primary);
|
|
453
|
+
transform: translate(-50%, -50%) scale(1.06);
|
|
454
|
+
}
|
|
455
|
+
.ys-media__big-play svg {
|
|
456
|
+
width: 28px;
|
|
457
|
+
height: 28px;
|
|
458
|
+
}
|
|
459
|
+
.ys-media__error {
|
|
460
|
+
display: flex;
|
|
461
|
+
flex-direction: column;
|
|
462
|
+
align-items: center;
|
|
463
|
+
gap: 10px;
|
|
464
|
+
width: min(420px, 86%);
|
|
465
|
+
color: var(--ys-color-media-text);
|
|
466
|
+
font-size: 13px;
|
|
467
|
+
line-height: 1.6;
|
|
468
|
+
text-align: center;
|
|
469
|
+
}
|
|
470
|
+
.ys-media__error svg {
|
|
471
|
+
width: 32px;
|
|
472
|
+
height: 32px;
|
|
473
|
+
color: var(--ys-color-danger);
|
|
474
|
+
}
|
|
475
|
+
.ys-media__row {
|
|
476
|
+
display: flex;
|
|
477
|
+
align-items: center;
|
|
478
|
+
gap: 2px;
|
|
479
|
+
}
|
|
480
|
+
.ys-media__spacer {
|
|
481
|
+
flex: 1;
|
|
482
|
+
}
|
|
483
|
+
.ys-media__btn {
|
|
484
|
+
display: inline-flex;
|
|
485
|
+
flex: none;
|
|
486
|
+
align-items: center;
|
|
487
|
+
justify-content: center;
|
|
488
|
+
min-width: 32px;
|
|
489
|
+
height: 32px;
|
|
490
|
+
padding: 0 6px;
|
|
491
|
+
border: 0;
|
|
492
|
+
border-radius: var(--ys-radius-s);
|
|
493
|
+
background: transparent;
|
|
494
|
+
color: inherit;
|
|
495
|
+
font: inherit;
|
|
496
|
+
font-size: 12px;
|
|
497
|
+
cursor: pointer;
|
|
498
|
+
opacity: 0.88;
|
|
499
|
+
transition:
|
|
500
|
+
opacity 0.15s,
|
|
501
|
+
background-color 0.15s;
|
|
502
|
+
}
|
|
503
|
+
.ys-media__btn:hover {
|
|
504
|
+
opacity: 1;
|
|
505
|
+
}
|
|
506
|
+
.ys-media.is-video .ys-media__btn:hover {
|
|
507
|
+
background: color-mix(in srgb, var(--ys-color-media-text) 14%, transparent);
|
|
508
|
+
}
|
|
509
|
+
.ys-media__btn:focus {
|
|
510
|
+
outline: none;
|
|
511
|
+
}
|
|
512
|
+
.ys-media__btn:focus-visible {
|
|
513
|
+
outline: 2px solid color-mix(in srgb, var(--ys-color-primary) 70%, transparent);
|
|
514
|
+
outline-offset: -2px;
|
|
515
|
+
}
|
|
516
|
+
.ys-media__btn svg {
|
|
517
|
+
width: 18px;
|
|
518
|
+
height: 18px;
|
|
519
|
+
}
|
|
520
|
+
/* el-dropdown 自带文字色,这里让倍速按钮跟随播放器的文字色。 */
|
|
521
|
+
.ys-media :deep(.el-dropdown) {
|
|
522
|
+
color: inherit;
|
|
523
|
+
font: inherit;
|
|
524
|
+
}
|
|
525
|
+
.ys-media__speed {
|
|
526
|
+
min-width: 44px;
|
|
527
|
+
font-weight: 600;
|
|
528
|
+
}
|
|
529
|
+
.ys-media__time {
|
|
530
|
+
margin: 0 8px;
|
|
531
|
+
font-size: 12px;
|
|
532
|
+
white-space: nowrap;
|
|
533
|
+
opacity: 0.9;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/* ---------- 进度条 ---------- */
|
|
537
|
+
.ys-media__progress {
|
|
538
|
+
position: relative;
|
|
539
|
+
display: flex;
|
|
540
|
+
align-items: center;
|
|
541
|
+
height: 16px;
|
|
542
|
+
cursor: pointer;
|
|
543
|
+
touch-action: none;
|
|
544
|
+
}
|
|
545
|
+
.ys-media__progress:focus {
|
|
546
|
+
outline: none;
|
|
547
|
+
}
|
|
548
|
+
.ys-media__track {
|
|
549
|
+
position: relative;
|
|
550
|
+
flex: 1;
|
|
551
|
+
height: 4px;
|
|
552
|
+
overflow: hidden;
|
|
553
|
+
border-radius: 2px;
|
|
554
|
+
background: color-mix(in srgb, currentColor 22%, transparent);
|
|
555
|
+
transition: height 0.12s;
|
|
556
|
+
}
|
|
557
|
+
.ys-media__progress:hover .ys-media__track,
|
|
558
|
+
.ys-media__progress:focus-visible .ys-media__track {
|
|
559
|
+
height: 6px;
|
|
560
|
+
}
|
|
561
|
+
.ys-media__buffered,
|
|
562
|
+
.ys-media__played {
|
|
563
|
+
position: absolute;
|
|
564
|
+
top: 0;
|
|
565
|
+
bottom: 0;
|
|
566
|
+
left: 0;
|
|
567
|
+
border-radius: inherit;
|
|
568
|
+
}
|
|
569
|
+
.ys-media__buffered {
|
|
570
|
+
background: color-mix(in srgb, currentColor 30%, transparent);
|
|
571
|
+
}
|
|
572
|
+
.ys-media__played {
|
|
573
|
+
background: var(--ys-color-primary);
|
|
574
|
+
}
|
|
575
|
+
.ys-media__knob {
|
|
576
|
+
position: absolute;
|
|
577
|
+
top: 50%;
|
|
578
|
+
width: 12px;
|
|
579
|
+
height: 12px;
|
|
580
|
+
border-radius: 50%;
|
|
581
|
+
background: var(--ys-color-primary);
|
|
582
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--ys-color-primary) 28%, transparent);
|
|
583
|
+
transform: translate(-50%, -50%) scale(0);
|
|
584
|
+
transition: transform 0.12s;
|
|
585
|
+
}
|
|
586
|
+
.ys-media__progress:hover .ys-media__knob,
|
|
587
|
+
.ys-media__progress:focus-visible .ys-media__knob {
|
|
588
|
+
transform: translate(-50%, -50%) scale(1);
|
|
589
|
+
}
|
|
590
|
+
.ys-media__hover {
|
|
591
|
+
position: absolute;
|
|
592
|
+
bottom: 18px;
|
|
593
|
+
padding: 2px 6px;
|
|
594
|
+
border-radius: var(--ys-radius-s);
|
|
595
|
+
background: var(--ys-tooltip-bg);
|
|
596
|
+
color: var(--ys-tooltip-text);
|
|
597
|
+
box-shadow: var(--ys-tooltip-shadow);
|
|
598
|
+
font-size: 11px;
|
|
599
|
+
line-height: 16px;
|
|
600
|
+
white-space: nowrap;
|
|
601
|
+
pointer-events: none;
|
|
602
|
+
transform: translateX(-50%);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/* ---------- 音量 ---------- */
|
|
606
|
+
.ys-media__volume {
|
|
607
|
+
display: flex;
|
|
608
|
+
align-items: center;
|
|
609
|
+
}
|
|
610
|
+
.ys-media__volume-bar {
|
|
611
|
+
display: flex;
|
|
612
|
+
align-items: center;
|
|
613
|
+
width: 64px;
|
|
614
|
+
height: 24px;
|
|
615
|
+
margin: 0 6px 0 2px;
|
|
616
|
+
cursor: pointer;
|
|
617
|
+
touch-action: none;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/* ---------- 音频 ---------- */
|
|
621
|
+
.ys-media.is-audio {
|
|
622
|
+
display: flex;
|
|
623
|
+
align-items: center;
|
|
624
|
+
gap: 14px;
|
|
625
|
+
width: min(560px, 100%);
|
|
626
|
+
padding: 14px 16px 10px;
|
|
627
|
+
border: 1px solid var(--ys-color-border);
|
|
628
|
+
border-radius: var(--ys-radius-l);
|
|
629
|
+
background: var(--ys-color-bg-elevated);
|
|
630
|
+
box-shadow: var(--ys-shadow-popper);
|
|
631
|
+
color: var(--ys-color-text-2);
|
|
632
|
+
}
|
|
633
|
+
.ys-media.is-audio .ys-media__controls {
|
|
634
|
+
flex: 1;
|
|
635
|
+
min-width: 0;
|
|
636
|
+
}
|
|
637
|
+
.ys-media__round {
|
|
638
|
+
display: inline-flex;
|
|
639
|
+
flex: none;
|
|
640
|
+
align-items: center;
|
|
641
|
+
justify-content: center;
|
|
642
|
+
width: 44px;
|
|
643
|
+
height: 44px;
|
|
644
|
+
padding: 0;
|
|
645
|
+
border: 0;
|
|
646
|
+
border-radius: 50%;
|
|
647
|
+
background: var(--ys-color-primary);
|
|
648
|
+
color: #fff;
|
|
649
|
+
cursor: pointer;
|
|
650
|
+
box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--ys-color-primary) 45%, transparent);
|
|
651
|
+
transition:
|
|
652
|
+
background-color 0.15s,
|
|
653
|
+
transform 0.15s;
|
|
654
|
+
}
|
|
655
|
+
.ys-media__round:hover:not(:disabled) {
|
|
656
|
+
background: var(--ys-color-primary-hover);
|
|
657
|
+
transform: scale(1.04);
|
|
658
|
+
}
|
|
659
|
+
.ys-media__round:disabled {
|
|
660
|
+
cursor: not-allowed;
|
|
661
|
+
opacity: 0.5;
|
|
662
|
+
}
|
|
663
|
+
.ys-media__round:focus {
|
|
664
|
+
outline: none;
|
|
665
|
+
}
|
|
666
|
+
.ys-media__round:focus-visible {
|
|
667
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--ys-color-primary) 35%, transparent);
|
|
668
|
+
}
|
|
669
|
+
.ys-media__round svg {
|
|
670
|
+
width: 20px;
|
|
671
|
+
height: 20px;
|
|
672
|
+
}
|
|
673
|
+
.ys-media.is-paused .ys-media__round svg {
|
|
674
|
+
margin-left: 2px;
|
|
675
|
+
}
|
|
676
|
+
.ys-media__headline {
|
|
677
|
+
display: flex;
|
|
678
|
+
align-items: baseline;
|
|
679
|
+
gap: 8px;
|
|
680
|
+
margin-bottom: 2px;
|
|
681
|
+
}
|
|
682
|
+
.ys-media__title {
|
|
683
|
+
flex: 1;
|
|
684
|
+
min-width: 0;
|
|
685
|
+
overflow: hidden;
|
|
686
|
+
color: var(--ys-color-text-1);
|
|
687
|
+
font-size: 13px;
|
|
688
|
+
font-weight: 600;
|
|
689
|
+
text-overflow: ellipsis;
|
|
690
|
+
white-space: nowrap;
|
|
691
|
+
}
|
|
692
|
+
.ys-media.is-audio .ys-media__time {
|
|
693
|
+
margin: 0;
|
|
694
|
+
color: var(--ys-color-text-3);
|
|
695
|
+
}
|
|
696
|
+
.ys-media.is-audio .ys-media__track {
|
|
697
|
+
background: color-mix(in srgb, var(--ys-color-text-3) 22%, transparent);
|
|
698
|
+
}
|
|
699
|
+
.ys-media.is-audio .ys-media__buffered {
|
|
700
|
+
background: color-mix(in srgb, var(--ys-color-text-3) 30%, transparent);
|
|
701
|
+
}
|
|
702
|
+
.ys-media.is-audio .ys-media__row {
|
|
703
|
+
margin-top: 2px;
|
|
704
|
+
}
|
|
705
|
+
.ys-media.is-audio .ys-media__btn {
|
|
706
|
+
min-width: 28px;
|
|
707
|
+
height: 28px;
|
|
708
|
+
}
|
|
709
|
+
.ys-media.is-audio .ys-media__btn:hover {
|
|
710
|
+
background: var(--ys-color-bg-hover);
|
|
711
|
+
color: var(--ys-color-text-1);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/* 窄屏:视频隐藏音量条,留静音键。 */
|
|
715
|
+
@media (max-width: 560px) {
|
|
716
|
+
.ys-media.is-video .ys-media__volume-bar {
|
|
717
|
+
display: none;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
</style>
|