@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.
@@ -1,29 +1,35 @@
1
- <!-- YsFilePreview —— 文件预览弹窗,全平台统一的文件预览入口。
2
- PDF 用浏览器自带阅读器(iframe 打开 blob 地址,支持翻页、缩放、搜索、打印),
3
- 图片、文本、音视频直接显示,其他类型提示下载。文件内容由调用方的 load 取回(WS 分块、HTTP 都行),
4
- 组件只负责显示、进度、出错重试、下载、新标签打开、全屏和 ← → 切换。关闭后回收 blob 地址。 -->
1
+ <!-- YsFilePreview —— 文件预览弹窗,全平台统一的文件查看/预览/播放入口。
2
+ PDF 用 YsPdfViewer(pdf.js 自绘,跟随明暗),Excel/CSV 用 YsSheetViewer,Word(.docx)用 YsDocViewer,
3
+ 视频/音频用 YsMediaPlayer,图片、文本直接显示,其他类型(含旧版 .doc/.ppt、压缩包)提示下载。
4
+ 文件名和 content_type 认不出类型时(如只有材料编号),读到 Blob 后按 Blob 的 type 和文件头识别(sniffFileType)。
5
+ 文件内容由调用方的 load 取回(WS 分块、HTTP 都行),组件负责显示、进度、出错重试、下载、新标签打开、全屏和 ← → 切换;
6
+ Esc 关闭;焦点在播放器上时 ← → 留给播放器快退快进。窄屏(≤ 640px)自动全屏。关闭后回收 blob 地址。
7
+ 重型依赖(pdf.js、SheetJS、docx-preview)打开对应类型才加载。 -->
5
8
  <script setup lang="ts">
6
- import { computed, onBeforeUnmount, ref, watch } from "vue";
7
- import {
8
- ArrowLeft,
9
- ArrowRight,
10
- Close,
11
- Download,
12
- FullScreen,
13
- Document,
14
- TopRight,
15
- } from "@element-plus/icons-vue";
9
+ import { computed, defineAsyncComponent, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
10
+ import YsViewerIcon from "./YsViewerIcon.vue";
11
+ import YsViewerState from "./YsViewerState.vue";
12
+ import "../preview/viewer.css";
16
13
  import {
14
+ OFFICE_MIME,
17
15
  TEXT_PREVIEW_LIMIT,
16
+ fileExtension,
18
17
  fileTypeLabel,
19
18
  formatFileSize,
20
19
  previewKindOf,
21
20
  saveBlob,
22
- sniffPreviewKind,
21
+ sniffFileType,
23
22
  type YsPreviewFile,
24
23
  type YsPreviewKind,
25
24
  } from "../filePreview";
26
25
 
26
+ // 各查看器打开对应类型时才加载(它们的重型依赖本来就是按需加载,这里连组件代码也不进业务页的包)。
27
+ const lazy = <T extends object>(loader: () => Promise<T>) => defineAsyncComponent({ loader, loadingComponent: YsViewerState, delay: 120 });
28
+ const YsPdfViewer = lazy(() => import("./YsPdfViewer.vue"));
29
+ const YsSheetViewer = lazy(() => import("./YsSheetViewer.vue"));
30
+ const YsDocViewer = lazy(() => import("./YsDocViewer.vue"));
31
+ const YsMediaPlayer = lazy(() => import("./YsMediaPlayer.vue"));
32
+
27
33
  const props = withDefaults(
28
34
  defineProps<{
29
35
  modelValue: boolean;
@@ -44,24 +50,46 @@ const emit = defineEmits<{
44
50
 
45
51
  const current = ref(0);
46
52
  const loading = ref(false);
47
- const progress = ref(0);
53
+ const progress = ref<number | null>(null);
48
54
  const error = ref("");
49
- const blob = ref<Blob | null>(null);
55
+ const blob = shallowRef<Blob | null>(null);
50
56
  const url = ref("");
51
57
  const text = ref("");
52
58
  const textCut = ref(false);
53
59
  const kind = ref<YsPreviewKind>("none");
60
+ /** 按内容识别出的 MIME;文件名、content_type 已能确定类型时为空。 */
61
+ const sniffedMime = ref("");
54
62
  const fullscreen = ref(false);
63
+ const narrow = ref(false);
55
64
  let token = 0;
65
+ let media: MediaQueryList | null = null;
56
66
 
57
67
  const file = computed<YsPreviewFile | null>(() => props.files[current.value] ?? null);
58
68
  const total = computed(() => props.files.length);
59
69
  const canPrev = computed(() => current.value > 0);
60
70
  const canNext = computed(() => current.value < total.value - 1);
61
- const meta = computed(() => {
62
- if (!file.value) return "";
63
- const size = formatFileSize(file.value.size);
64
- return [fileTypeLabel(file.value.name, file.value.content_type), size].filter(Boolean).join(" · ");
71
+ const mime = computed(() => sniffedMime.value || file.value?.content_type || "");
72
+ /** 类型标签:按内容识别出类型时用识别结果。 */
73
+ const typeLabel = computed(() => (file.value ? fileTypeLabel(file.value.name, mime.value) : ""));
74
+ const sizeText = computed(() => formatFileSize(file.value?.size));
75
+ const isFull = computed(() => fullscreen.value || narrow.value);
76
+ /** 新标签页打开只对浏览器能直接显示的类型有意义。 */
77
+ const canOpenInTab = computed(() => ["pdf", "image", "video", "audio"].includes(kind.value));
78
+ const isCsv = computed(() => fileExtension(file.value?.name ?? "") === "csv" || /csv/i.test(mime.value));
79
+ /** 标题栏左侧的类型色块:PDF 红、表格绿、文档蓝、图片橙、音视频紫灰,其他中性。 */
80
+ const badge = computed(() => {
81
+ const ext = fileExtension(file.value?.name ?? "").toUpperCase();
82
+ const short = ext && ext.length <= 4 ? ext : typeLabel.value.slice(0, 4).toUpperCase() || "FILE";
83
+ return { text: short, tone: kind.value };
84
+ });
85
+ /** 不支持预览时的说明。 */
86
+ const unsupported = computed(() => {
87
+ const ext = fileExtension(file.value?.name ?? "");
88
+ if (ext === "doc" || ext === "wps" || mime.value === OFFICE_MIME.doc)
89
+ return { title: "旧版 Word(.doc)暂不支持在线预览", detail: "下载后用 Word / WPS 打开;另存为 .docx 后上传即可在线预览。" };
90
+ if (["ppt", "pptx", "dps"].includes(ext) || mime.value.includes("presentation") || mime.value === OFFICE_MIME.ppt)
91
+ return { title: "演示文稿暂不支持在线预览", detail: "下载后用 PowerPoint / WPS 打开。" };
92
+ return { title: `${typeLabel.value || "此类"}文件暂不支持在线预览`, detail: "下载后用本地软件打开。" };
65
93
  });
66
94
 
67
95
  function release() {
@@ -77,7 +105,8 @@ async function open() {
77
105
  const mine = ++token;
78
106
  release();
79
107
  error.value = "";
80
- progress.value = 0;
108
+ progress.value = null;
109
+ sniffedMime.value = "";
81
110
  if (!target) return;
82
111
  kind.value = previewKindOf(target);
83
112
  loading.value = true;
@@ -86,18 +115,21 @@ async function open() {
86
115
  if (mine === token) progress.value = Math.max(0, Math.min(1, ratio));
87
116
  });
88
117
  if (mine !== token) return;
89
- if (kind.value === "none") kind.value = await sniffPreviewKind(data);
90
- if (mine !== token) return;
91
- // PDF 必须带 application/pdf 类型,浏览器才会用自带阅读器打开。
92
- const typed =
93
- kind.value === "pdf" && data.type !== "application/pdf"
94
- ? new Blob([data], { type: "application/pdf" })
95
- : data;
118
+ let type = kind.value === "pdf" ? "application/pdf" : "";
119
+ if (kind.value === "none") {
120
+ const sniffed = await sniffFileType(data);
121
+ if (mine !== token) return;
122
+ kind.value = sniffed.kind;
123
+ type = sniffed.mime;
124
+ sniffedMime.value = sniffed.mime;
125
+ }
126
+ // 补上识别出的类型:新标签页打开、浏览器解码都靠它。
127
+ const typed = type && data.type !== type ? new Blob([data], { type }) : data;
96
128
  blob.value = typed;
97
129
  if (kind.value === "text") {
98
130
  textCut.value = typed.size > TEXT_PREVIEW_LIMIT;
99
131
  text.value = await typed.slice(0, TEXT_PREVIEW_LIMIT).text();
100
- } else if (kind.value !== "none") {
132
+ } else if (kind.value === "image" || kind.value === "video" || kind.value === "audio") {
101
133
  url.value = URL.createObjectURL(typed);
102
134
  }
103
135
  } catch (reason) {
@@ -137,8 +169,19 @@ watch(
137
169
  { immediate: true },
138
170
  );
139
171
 
172
+ function onNarrowChange() {
173
+ narrow.value = Boolean(media?.matches);
174
+ }
175
+
176
+ onMounted(() => {
177
+ media = window.matchMedia?.("(max-width: 640px)") ?? null;
178
+ onNarrowChange();
179
+ media?.addEventListener?.("change", onNarrowChange);
180
+ });
181
+
140
182
  onBeforeUnmount(() => {
141
183
  window.removeEventListener("keydown", onKeydown);
184
+ media?.removeEventListener?.("change", onNarrowChange);
142
185
  token += 1;
143
186
  release();
144
187
  });
@@ -152,8 +195,10 @@ function go(step: number) {
152
195
  }
153
196
 
154
197
  function onKeydown(event: KeyboardEvent) {
198
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
155
199
  const target = event.target as HTMLElement | null;
156
- if (target?.closest("input, textarea, [contenteditable='true']")) return;
200
+ // 输入框、播放器、表格编辑栏里的方向键留给它们自己。
201
+ if (target?.closest("input, textarea, select, [contenteditable='true'], .ys-media, .el-dropdown-menu")) return;
157
202
  if (event.key === "ArrowLeft") go(-1);
158
203
  else if (event.key === "ArrowRight") go(1);
159
204
  }
@@ -174,17 +219,19 @@ async function download() {
174
219
  }
175
220
 
176
221
  function openInTab() {
177
- if (url.value) window.open(url.value, "_blank", "noopener");
222
+ if (!blob.value) return;
223
+ if (!url.value) url.value = URL.createObjectURL(blob.value);
224
+ window.open(url.value, "_blank", "noopener");
178
225
  }
179
226
  </script>
180
227
 
181
228
  <template>
182
229
  <el-dialog
183
230
  :model-value="modelValue"
184
- :fullscreen="fullscreen"
231
+ :fullscreen="isFull"
185
232
  :show-close="false"
186
- width="min(1120px, 92vw)"
187
- top="4vh"
233
+ width="min(1180px, 94vw)"
234
+ top="3vh"
188
235
  append-to-body
189
236
  destroy-on-close
190
237
  class="ys-file-preview"
@@ -192,82 +239,88 @@ function openInTab() {
192
239
  >
193
240
  <template #header>
194
241
  <div class="ys-file-preview__head">
195
- <el-icon class="ys-file-preview__icon" :size="18"><Document /></el-icon>
242
+ <span class="ys-file-preview__badge" :class="`is-${badge.tone}`" aria-hidden="true">{{ badge.text }}</span>
196
243
  <div class="ys-file-preview__title">
197
244
  <strong :title="file?.name">{{ file?.name || "文件预览" }}</strong>
198
- <span>{{ meta }}<template v-if="total > 1"> · 第 {{ current + 1 }} / {{ total }} 个</template></span>
245
+ <span class="ys-file-preview__meta">
246
+ <span v-if="typeLabel" class="ys-file-preview__type">{{ typeLabel }}</span>
247
+ <span v-if="sizeText">{{ sizeText }}</span>
248
+ <span v-if="total > 1" class="ys-file-preview__index">{{ current + 1 }} / {{ total }}</span>
249
+ </span>
199
250
  </div>
200
251
  <div class="ys-file-preview__tools">
201
252
  <template v-if="total > 1">
202
253
  <el-tooltip content="上一个(←)" placement="bottom" :show-after="400">
203
- <button type="button" class="ys-file-preview__tool" :disabled="!canPrev" aria-label="上一个" @click="go(-1)">
204
- <el-icon :size="16"><ArrowLeft /></el-icon>
254
+ <button type="button" class="ys-viewer__btn ys-file-preview__tool" :disabled="!canPrev" aria-label="上一个" @click="go(-1)">
255
+ <YsViewerIcon name="chevron-left" />
205
256
  </button>
206
257
  </el-tooltip>
207
258
  <el-tooltip content="下一个(→)" placement="bottom" :show-after="400">
208
- <button type="button" class="ys-file-preview__tool" :disabled="!canNext" aria-label="下一个" @click="go(1)">
209
- <el-icon :size="16"><ArrowRight /></el-icon>
259
+ <button type="button" class="ys-viewer__btn ys-file-preview__tool" :disabled="!canNext" aria-label="下一个" @click="go(1)">
260
+ <YsViewerIcon name="chevron-right" />
210
261
  </button>
211
262
  </el-tooltip>
212
- <span class="ys-file-preview__divider" aria-hidden="true" />
263
+ <span class="ys-viewer__sep" aria-hidden="true" />
213
264
  </template>
214
- <el-tooltip v-if="kind !== 'none' && kind !== 'text'" content="新标签页打开" placement="bottom" :show-after="400">
215
- <button type="button" class="ys-file-preview__tool" :disabled="!url" aria-label="新标签页打开" @click="openInTab">
216
- <el-icon :size="16"><TopRight /></el-icon>
265
+ <el-tooltip v-if="canOpenInTab" content="新标签页打开" placement="bottom" :show-after="400">
266
+ <button type="button" class="ys-viewer__btn ys-file-preview__tool ys-file-preview__wide" :disabled="!blob" aria-label="新标签页打开" @click="openInTab">
267
+ <YsViewerIcon name="external" />
217
268
  </button>
218
269
  </el-tooltip>
219
- <el-tooltip :content="fullscreen ? '退出全屏' : '全屏'" placement="bottom" :show-after="400">
220
- <button type="button" class="ys-file-preview__tool" :aria-label="fullscreen ? '退出全屏' : '全屏'" @click="fullscreen = !fullscreen">
221
- <el-icon :size="16"><FullScreen /></el-icon>
270
+ <el-tooltip v-if="!narrow" :content="fullscreen ? '退出全屏' : '全屏'" placement="bottom" :show-after="400">
271
+ <button type="button" class="ys-viewer__btn ys-file-preview__tool" :aria-label="fullscreen ? '退出全屏' : '全屏'" @click="fullscreen = !fullscreen">
272
+ <YsViewerIcon :name="fullscreen ? 'minimize' : 'maximize'" />
222
273
  </button>
223
274
  </el-tooltip>
224
275
  <el-tooltip content="下载" placement="bottom" :show-after="400">
225
- <button type="button" class="ys-file-preview__tool" :disabled="loading" aria-label="下载" @click="download">
226
- <el-icon :size="16"><Download /></el-icon>
276
+ <button type="button" class="ys-viewer__btn ys-file-preview__tool" :disabled="loading" aria-label="下载" @click="download">
277
+ <YsViewerIcon name="download" />
278
+ </button>
279
+ </el-tooltip>
280
+ <span class="ys-viewer__sep" aria-hidden="true" />
281
+ <el-tooltip content="关闭(Esc)" placement="bottom" :show-after="400">
282
+ <button type="button" class="ys-viewer__btn ys-file-preview__tool" aria-label="关闭" @click="close">
283
+ <YsViewerIcon name="close" />
227
284
  </button>
228
285
  </el-tooltip>
229
- <span class="ys-file-preview__divider" aria-hidden="true" />
230
- <button type="button" class="ys-file-preview__tool" aria-label="关闭" @click="close">
231
- <el-icon :size="18"><Close /></el-icon>
232
- </button>
233
286
  </div>
234
287
  </div>
235
288
  </template>
236
289
 
237
- <div class="ys-file-preview__stage" :class="{ 'is-fullscreen': fullscreen, 'is-dark': kind === 'image' || kind === 'video' }">
238
- <div v-if="loading" class="ys-file-preview__state">
239
- <el-progress
240
- type="circle"
241
- :width="72"
242
- :stroke-width="5"
243
- :percentage="Math.round(progress * 100)"
244
- />
245
- <span>正在读取文件…</span>
290
+ <div class="ys-file-preview__stage" :class="[`is-${loading || error ? 'state' : kind}`, { 'is-fullscreen': isFull }]">
291
+ <div v-if="loading" class="ys-viewer ys-file-preview__pane">
292
+ <YsViewerState :progress="progress" title="正在读取文件…" :detail="sizeText ? `${file?.name ?? ''} · ${sizeText}` : file?.name" />
246
293
  </div>
247
- <div v-else-if="error" class="ys-file-preview__state">
248
- <span class="ys-file-preview__error">{{ error }}</span>
249
- <el-button type="primary" plain @click="open">重试</el-button>
294
+ <div v-else-if="error" class="ys-viewer ys-file-preview__pane">
295
+ <YsViewerState type="error" title="文件读取失败" :detail="error">
296
+ <template #actions><el-button type="primary" @click="open">重试</el-button></template>
297
+ </YsViewerState>
250
298
  </div>
251
- <template v-else-if="file">
252
- <iframe
253
- v-if="kind === 'pdf' && url"
254
- :key="url"
255
- class="ys-file-preview__frame"
256
- :src="url"
257
- :title="file.name"
258
- />
259
- <img v-else-if="kind === 'image' && url" class="ys-file-preview__image" :src="url" :alt="file.name" />
260
- <video v-else-if="kind === 'video' && url" class="ys-file-preview__media" :src="url" controls />
261
- <audio v-else-if="kind === 'audio' && url" class="ys-file-preview__audio" :src="url" controls />
299
+ <template v-else-if="file && blob">
300
+ <YsPdfViewer v-if="kind === 'pdf'" :source="blob" :fullscreen-button="false">
301
+ <template #error-actions><el-button type="primary" @click="download">下载</el-button></template>
302
+ </YsPdfViewer>
303
+ <YsSheetViewer v-else-if="kind === 'excel'" :source="blob" :file-name="file.name" :csv="isCsv">
304
+ <template #error-actions><el-button type="primary" @click="download">下载</el-button></template>
305
+ </YsSheetViewer>
306
+ <YsDocViewer v-else-if="kind === 'word'" :source="blob" :fullscreen-button="false">
307
+ <template #error-actions><el-button type="primary" @click="download">下载</el-button></template>
308
+ </YsDocViewer>
309
+ <div v-else-if="kind === 'image' && url" class="ys-file-preview__image-wrap">
310
+ <img class="ys-file-preview__image" :src="url" :alt="file.name" />
311
+ </div>
312
+ <YsMediaPlayer v-else-if="kind === 'video' && url" :key="url" :src="url" type="video" />
313
+ <div v-else-if="kind === 'audio' && url" class="ys-file-preview__audio-wrap">
314
+ <YsMediaPlayer :key="url" :src="url" type="audio" :title="file.name" />
315
+ </div>
262
316
  <div v-else-if="kind === 'text'" class="ys-file-preview__text">
263
- <div v-if="textCut" class="ys-file-preview__notice">文件较大,只显示开头 {{ formatFileSize(TEXT_PREVIEW_LIMIT) }},完整内容请下载查看。</div>
317
+ <div v-if="textCut" class="ys-viewer__notice">文件较大,只显示开头 {{ formatFileSize(TEXT_PREVIEW_LIMIT) }},完整内容请下载查看。</div>
264
318
  <pre>{{ text }}</pre>
265
319
  </div>
266
- <div v-else class="ys-file-preview__state">
267
- <el-icon :size="40" class="ys-file-preview__placeholder"><Document /></el-icon>
268
- <strong>{{ fileTypeLabel(file.name, file.content_type) }} 文件暂不支持在线预览</strong>
269
- <span>下载后用本地软件打开</span>
270
- <el-button type="primary" :icon="Download" @click="download">下载</el-button>
320
+ <div v-else class="ys-viewer ys-file-preview__pane">
321
+ <YsViewerState type="empty" :title="unsupported.title" :detail="unsupported.detail">
322
+ <template #actions><el-button type="primary" @click="download">下载</el-button></template>
323
+ </YsViewerState>
271
324
  </div>
272
325
  </template>
273
326
  </div>
@@ -297,19 +350,49 @@ function openInTab() {
297
350
  .ys-file-preview__head {
298
351
  display: flex;
299
352
  align-items: center;
300
- gap: 10px;
301
- min-height: 52px;
353
+ gap: 12px;
354
+ min-height: 56px;
302
355
  padding: 8px 10px 8px 16px;
303
356
  border-bottom: 1px solid var(--ys-color-border);
357
+ background: var(--ys-color-bg-elevated);
304
358
  }
305
- .ys-file-preview__icon {
359
+ .ys-file-preview__badge {
360
+ --tone: var(--ys-color-text-3);
361
+ display: inline-flex;
306
362
  flex: none;
307
- color: var(--ys-color-primary);
363
+ align-items: center;
364
+ justify-content: center;
365
+ width: 36px;
366
+ height: 36px;
367
+ border: 1px solid color-mix(in srgb, var(--tone) 28%, transparent);
368
+ border-radius: var(--ys-radius-m);
369
+ background: color-mix(in srgb, var(--tone) 12%, var(--ys-color-bg-elevated));
370
+ color: var(--tone);
371
+ font-size: 10px;
372
+ font-weight: 700;
373
+ letter-spacing: 0.02em;
374
+ }
375
+ .ys-file-preview__badge.is-pdf {
376
+ --tone: var(--ys-color-danger);
377
+ }
378
+ .ys-file-preview__badge.is-excel {
379
+ --tone: var(--ys-color-success);
380
+ }
381
+ .ys-file-preview__badge.is-word {
382
+ --tone: var(--ys-color-primary);
383
+ }
384
+ .ys-file-preview__badge.is-image {
385
+ --tone: var(--ys-color-warning);
386
+ }
387
+ .ys-file-preview__badge.is-video,
388
+ .ys-file-preview__badge.is-audio {
389
+ --tone: color-mix(in srgb, var(--ys-color-primary) 55%, var(--ys-color-danger));
308
390
  }
309
391
  .ys-file-preview__title {
310
392
  display: flex;
311
393
  flex: 1;
312
394
  flex-direction: column;
395
+ gap: 2px;
313
396
  min-width: 0;
314
397
  line-height: 1.35;
315
398
  }
@@ -321,10 +404,25 @@ function openInTab() {
321
404
  text-overflow: ellipsis;
322
405
  white-space: nowrap;
323
406
  }
324
- .ys-file-preview__title span {
407
+ .ys-file-preview__meta {
408
+ display: flex;
409
+ align-items: center;
410
+ gap: 8px;
411
+ overflow: hidden;
325
412
  color: var(--ys-color-text-3);
326
413
  font-size: 12px;
327
414
  font-variant-numeric: tabular-nums;
415
+ white-space: nowrap;
416
+ }
417
+ .ys-file-preview__type {
418
+ padding: 0 6px;
419
+ border-radius: var(--ys-radius-s);
420
+ background: var(--ys-color-bg-hover);
421
+ color: var(--ys-color-text-2);
422
+ line-height: 18px;
423
+ }
424
+ .ys-file-preview__index {
425
+ color: var(--ys-color-text-2);
328
426
  }
329
427
  .ys-file-preview__tools {
330
428
  display: flex;
@@ -333,69 +431,53 @@ function openInTab() {
333
431
  gap: 2px;
334
432
  }
335
433
  .ys-file-preview__tool {
336
- display: inline-flex;
337
- align-items: center;
338
- justify-content: center;
339
434
  width: 32px;
340
435
  height: 32px;
341
- padding: 0;
342
- border: 0;
343
- border-radius: var(--ys-radius-s);
344
- background: transparent;
345
- color: var(--ys-color-text-2);
346
- cursor: pointer;
347
- }
348
- .ys-file-preview__tool:hover:not(:disabled) {
349
- background: var(--ys-color-bg-hover);
350
- color: var(--ys-color-primary);
351
- }
352
- /* 与顶栏图标按钮一致:不画聚焦框。 */
353
- .ys-file-preview__tool:focus,
354
- .ys-file-preview__tool:focus-visible {
355
- outline: none;
356
- }
357
- .ys-file-preview__tool:disabled {
358
- color: var(--ys-color-text-3);
359
- cursor: not-allowed;
360
- opacity: 0.5;
361
436
  }
362
- .ys-file-preview__divider {
363
- width: 1px;
437
+ .ys-file-preview__tool :deep(svg) {
438
+ width: 18px;
364
439
  height: 18px;
365
- margin: 0 4px;
366
- background: var(--ys-color-border);
367
440
  }
368
441
  .ys-file-preview__stage {
369
442
  display: flex;
370
- align-items: center;
371
- justify-content: center;
372
- height: min(80vh, 900px);
373
- background: var(--ys-color-bg);
443
+ flex-direction: column;
444
+ height: min(82vh, 920px);
445
+ background: var(--ys-color-stage);
374
446
  }
375
447
  .ys-file-preview__stage.is-fullscreen {
376
- height: calc(100vh - 53px);
448
+ height: calc(100vh - 57px);
449
+ height: calc(100dvh - 57px);
450
+ }
451
+ .ys-file-preview__stage.is-video {
452
+ background: var(--ys-color-media-bg);
377
453
  }
378
- .ys-file-preview__stage.is-dark {
379
- background: #1f1f1f;
454
+ .ys-file-preview__stage > :deep(*) {
455
+ flex: 1;
456
+ min-height: 0;
380
457
  }
381
- .ys-file-preview__frame {
382
- width: 100%;
383
- height: 100%;
384
- border: 0;
385
- background: #fff;
458
+ .ys-file-preview__pane {
459
+ justify-content: center;
460
+ }
461
+ .ys-file-preview__image-wrap,
462
+ .ys-file-preview__audio-wrap {
463
+ display: flex;
464
+ align-items: center;
465
+ justify-content: center;
466
+ padding: 16px;
467
+ overflow: auto;
386
468
  }
387
- .ys-file-preview__image,
388
- .ys-file-preview__media {
469
+ .ys-file-preview__image {
389
470
  max-width: 100%;
390
471
  max-height: 100%;
391
472
  object-fit: contain;
392
- }
393
- .ys-file-preview__audio {
394
- width: min(520px, 90%);
473
+ border-radius: 2px;
474
+ box-shadow: var(--ys-shadow-paper);
475
+ /* 透明图片垫一层浅色棋盘格,透明区域看得出来。 */
476
+ background: repeating-conic-gradient(color-mix(in srgb, var(--ys-color-text-3) 14%, transparent) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
395
477
  }
396
478
  .ys-file-preview__text {
397
- align-self: stretch;
398
- width: 100%;
479
+ display: flex;
480
+ flex-direction: column;
399
481
  overflow: auto;
400
482
  background: var(--ys-color-bg-elevated);
401
483
  }
@@ -409,29 +491,16 @@ function openInTab() {
409
491
  white-space: pre-wrap;
410
492
  word-break: break-word;
411
493
  }
412
- .ys-file-preview__notice {
413
- padding: 8px 20px;
414
- border-bottom: 1px solid var(--ys-color-border);
415
- color: var(--ys-color-warning);
416
- font-size: 12px;
417
- }
418
- .ys-file-preview__state {
419
- display: flex;
420
- flex-direction: column;
421
- align-items: center;
422
- gap: 12px;
423
- color: var(--ys-color-text-3);
424
- font-size: 13px;
425
- }
426
- .ys-file-preview__state strong {
427
- color: var(--ys-color-text-1);
428
- font-size: 15px;
429
- font-weight: 600;
430
- }
431
- .ys-file-preview__placeholder {
432
- color: var(--ys-color-text-3);
433
- }
434
- .ys-file-preview__error {
435
- color: var(--ys-color-danger);
494
+ @media (max-width: 640px) {
495
+ .ys-file-preview__head {
496
+ gap: 8px;
497
+ padding-left: 12px;
498
+ }
499
+ .ys-file-preview__badge {
500
+ display: none;
501
+ }
502
+ .ys-file-preview__wide {
503
+ display: none;
504
+ }
436
505
  }
437
506
  </style>