@ysgroup/ui 0.1.42 → 0.1.44

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,21 +1,19 @@
1
- <!-- YsFilePreview —— 文件预览弹窗,全平台统一的文件预览入口。
2
- PDF 用浏览器自带阅读器(iframe 打开 blob 地址,支持翻页、缩放、搜索、打印),
3
- 图片、文本、音视频直接显示,其他类型提示下载。文件名和 content_type 认不出类型时(如只有材料编号),
4
- 读到 Blob 后按 Blob 的 type 和文件头识别(sniffFileType,只读开头几 KB)。文件内容由调用方的 load 取回(WS 分块、HTTP 都行),
5
- 组件只负责显示、进度、出错重试、下载、新标签打开、全屏和 ← → 切换。关闭后回收 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)打开对应类型才加载。 -->
6
8
  <script setup lang="ts">
7
- import { computed, onBeforeUnmount, ref, watch } from "vue";
8
- import {
9
- ArrowLeft,
10
- ArrowRight,
11
- Close,
12
- Download,
13
- FullScreen,
14
- Document,
15
- TopRight,
16
- } 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";
17
13
  import {
14
+ OFFICE_MIME,
18
15
  TEXT_PREVIEW_LIMIT,
16
+ fileExtension,
19
17
  fileTypeLabel,
20
18
  formatFileSize,
21
19
  previewKindOf,
@@ -25,6 +23,13 @@ import {
25
23
  type YsPreviewKind,
26
24
  } from "../filePreview";
27
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
+
28
33
  const props = withDefaults(
29
34
  defineProps<{
30
35
  modelValue: boolean;
@@ -45,9 +50,9 @@ const emit = defineEmits<{
45
50
 
46
51
  const current = ref(0);
47
52
  const loading = ref(false);
48
- const progress = ref(0);
53
+ const progress = ref<number | null>(null);
49
54
  const error = ref("");
50
- const blob = ref<Blob | null>(null);
55
+ const blob = shallowRef<Blob | null>(null);
51
56
  const url = ref("");
52
57
  const text = ref("");
53
58
  const textCut = ref(false);
@@ -55,21 +60,36 @@ const kind = ref<YsPreviewKind>("none");
55
60
  /** 按内容识别出的 MIME;文件名、content_type 已能确定类型时为空。 */
56
61
  const sniffedMime = ref("");
57
62
  const fullscreen = ref(false);
63
+ const narrow = ref(false);
58
64
  let token = 0;
65
+ let media: MediaQueryList | null = null;
59
66
 
60
67
  const file = computed<YsPreviewFile | null>(() => props.files[current.value] ?? null);
61
68
  const total = computed(() => props.files.length);
62
69
  const canPrev = computed(() => current.value > 0);
63
70
  const canNext = computed(() => current.value < total.value - 1);
71
+ const mime = computed(() => sniffedMime.value || file.value?.content_type || "");
64
72
  /** 类型标签:按内容识别出类型时用识别结果。 */
65
- const typeLabel = computed(() => {
66
- if (!file.value) return "";
67
- return fileTypeLabel(file.value.name, sniffedMime.value || file.value.content_type);
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 };
68
84
  });
69
- const meta = computed(() => {
70
- if (!file.value) return "";
71
- const size = formatFileSize(file.value.size);
72
- return [typeLabel.value, size].filter(Boolean).join(" · ");
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: "下载后用本地软件打开。" };
73
93
  });
74
94
 
75
95
  function release() {
@@ -85,7 +105,7 @@ async function open() {
85
105
  const mine = ++token;
86
106
  release();
87
107
  error.value = "";
88
- progress.value = 0;
108
+ progress.value = null;
89
109
  sniffedMime.value = "";
90
110
  if (!target) return;
91
111
  kind.value = previewKindOf(target);
@@ -95,21 +115,21 @@ async function open() {
95
115
  if (mine === token) progress.value = Math.max(0, Math.min(1, ratio));
96
116
  });
97
117
  if (mine !== token) return;
98
- let mime = kind.value === "pdf" ? "application/pdf" : "";
118
+ let type = kind.value === "pdf" ? "application/pdf" : "";
99
119
  if (kind.value === "none") {
100
120
  const sniffed = await sniffFileType(data);
101
121
  if (mine !== token) return;
102
122
  kind.value = sniffed.kind;
103
- mime = sniffed.mime;
123
+ type = sniffed.mime;
104
124
  sniffedMime.value = sniffed.mime;
105
125
  }
106
- // 补上识别出的类型:PDF 必须带 application/pdf,浏览器才会用自带阅读器;新标签页打开也靠它。
107
- const typed = mime && data.type !== mime ? new Blob([data], { type: mime }) : data;
126
+ // 补上识别出的类型:新标签页打开、浏览器解码都靠它。
127
+ const typed = type && data.type !== type ? new Blob([data], { type }) : data;
108
128
  blob.value = typed;
109
129
  if (kind.value === "text") {
110
130
  textCut.value = typed.size > TEXT_PREVIEW_LIMIT;
111
131
  text.value = await typed.slice(0, TEXT_PREVIEW_LIMIT).text();
112
- } else if (kind.value !== "none") {
132
+ } else if (kind.value === "image" || kind.value === "video" || kind.value === "audio") {
113
133
  url.value = URL.createObjectURL(typed);
114
134
  }
115
135
  } catch (reason) {
@@ -149,8 +169,19 @@ watch(
149
169
  { immediate: true },
150
170
  );
151
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
+
152
182
  onBeforeUnmount(() => {
153
183
  window.removeEventListener("keydown", onKeydown);
184
+ media?.removeEventListener?.("change", onNarrowChange);
154
185
  token += 1;
155
186
  release();
156
187
  });
@@ -164,8 +195,10 @@ function go(step: number) {
164
195
  }
165
196
 
166
197
  function onKeydown(event: KeyboardEvent) {
198
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
167
199
  const target = event.target as HTMLElement | null;
168
- if (target?.closest("input, textarea, [contenteditable='true']")) return;
200
+ // 输入框、播放器、表格编辑栏里的方向键留给它们自己。
201
+ if (target?.closest("input, textarea, select, [contenteditable='true'], .ys-media, .el-dropdown-menu")) return;
169
202
  if (event.key === "ArrowLeft") go(-1);
170
203
  else if (event.key === "ArrowRight") go(1);
171
204
  }
@@ -186,17 +219,19 @@ async function download() {
186
219
  }
187
220
 
188
221
  function openInTab() {
189
- 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");
190
225
  }
191
226
  </script>
192
227
 
193
228
  <template>
194
229
  <el-dialog
195
230
  :model-value="modelValue"
196
- :fullscreen="fullscreen"
231
+ :fullscreen="isFull"
197
232
  :show-close="false"
198
- width="min(1120px, 92vw)"
199
- top="4vh"
233
+ width="min(1180px, 94vw)"
234
+ top="3vh"
200
235
  append-to-body
201
236
  destroy-on-close
202
237
  class="ys-file-preview"
@@ -204,82 +239,88 @@ function openInTab() {
204
239
  >
205
240
  <template #header>
206
241
  <div class="ys-file-preview__head">
207
- <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>
208
243
  <div class="ys-file-preview__title">
209
244
  <strong :title="file?.name">{{ file?.name || "文件预览" }}</strong>
210
- <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>
211
250
  </div>
212
251
  <div class="ys-file-preview__tools">
213
252
  <template v-if="total > 1">
214
253
  <el-tooltip content="上一个(←)" placement="bottom" :show-after="400">
215
- <button type="button" class="ys-file-preview__tool" :disabled="!canPrev" aria-label="上一个" @click="go(-1)">
216
- <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" />
217
256
  </button>
218
257
  </el-tooltip>
219
258
  <el-tooltip content="下一个(→)" placement="bottom" :show-after="400">
220
- <button type="button" class="ys-file-preview__tool" :disabled="!canNext" aria-label="下一个" @click="go(1)">
221
- <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" />
222
261
  </button>
223
262
  </el-tooltip>
224
- <span class="ys-file-preview__divider" aria-hidden="true" />
263
+ <span class="ys-viewer__sep" aria-hidden="true" />
225
264
  </template>
226
- <el-tooltip v-if="kind !== 'none' && kind !== 'text'" content="新标签页打开" placement="bottom" :show-after="400">
227
- <button type="button" class="ys-file-preview__tool" :disabled="!url" aria-label="新标签页打开" @click="openInTab">
228
- <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" />
229
268
  </button>
230
269
  </el-tooltip>
231
- <el-tooltip :content="fullscreen ? '退出全屏' : '全屏'" placement="bottom" :show-after="400">
232
- <button type="button" class="ys-file-preview__tool" :aria-label="fullscreen ? '退出全屏' : '全屏'" @click="fullscreen = !fullscreen">
233
- <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'" />
234
273
  </button>
235
274
  </el-tooltip>
236
275
  <el-tooltip content="下载" placement="bottom" :show-after="400">
237
- <button type="button" class="ys-file-preview__tool" :disabled="loading" aria-label="下载" @click="download">
238
- <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" />
239
284
  </button>
240
285
  </el-tooltip>
241
- <span class="ys-file-preview__divider" aria-hidden="true" />
242
- <button type="button" class="ys-file-preview__tool" aria-label="关闭" @click="close">
243
- <el-icon :size="18"><Close /></el-icon>
244
- </button>
245
286
  </div>
246
287
  </div>
247
288
  </template>
248
289
 
249
- <div class="ys-file-preview__stage" :class="{ 'is-fullscreen': fullscreen, 'is-dark': kind === 'image' || kind === 'video' }">
250
- <div v-if="loading" class="ys-file-preview__state">
251
- <el-progress
252
- type="circle"
253
- :width="72"
254
- :stroke-width="5"
255
- :percentage="Math.round(progress * 100)"
256
- />
257
- <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" />
258
293
  </div>
259
- <div v-else-if="error" class="ys-file-preview__state">
260
- <span class="ys-file-preview__error">{{ error }}</span>
261
- <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>
262
298
  </div>
263
- <template v-else-if="file">
264
- <iframe
265
- v-if="kind === 'pdf' && url"
266
- :key="url"
267
- class="ys-file-preview__frame"
268
- :src="url"
269
- :title="file.name"
270
- />
271
- <img v-else-if="kind === 'image' && url" class="ys-file-preview__image" :src="url" :alt="file.name" />
272
- <video v-else-if="kind === 'video' && url" class="ys-file-preview__media" :src="url" controls />
273
- <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>
274
316
  <div v-else-if="kind === 'text'" class="ys-file-preview__text">
275
- <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>
276
318
  <pre>{{ text }}</pre>
277
319
  </div>
278
- <div v-else class="ys-file-preview__state">
279
- <el-icon :size="40" class="ys-file-preview__placeholder"><Document /></el-icon>
280
- <strong>{{ typeLabel }} 文件暂不支持在线预览</strong>
281
- <span>下载后用本地软件打开</span>
282
- <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>
283
324
  </div>
284
325
  </template>
285
326
  </div>
@@ -309,19 +350,49 @@ function openInTab() {
309
350
  .ys-file-preview__head {
310
351
  display: flex;
311
352
  align-items: center;
312
- gap: 10px;
313
- min-height: 52px;
353
+ gap: 12px;
354
+ min-height: 56px;
314
355
  padding: 8px 10px 8px 16px;
315
356
  border-bottom: 1px solid var(--ys-color-border);
357
+ background: var(--ys-color-bg-elevated);
316
358
  }
317
- .ys-file-preview__icon {
359
+ .ys-file-preview__badge {
360
+ --tone: var(--ys-color-text-3);
361
+ display: inline-flex;
318
362
  flex: none;
319
- 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));
320
390
  }
321
391
  .ys-file-preview__title {
322
392
  display: flex;
323
393
  flex: 1;
324
394
  flex-direction: column;
395
+ gap: 2px;
325
396
  min-width: 0;
326
397
  line-height: 1.35;
327
398
  }
@@ -333,10 +404,25 @@ function openInTab() {
333
404
  text-overflow: ellipsis;
334
405
  white-space: nowrap;
335
406
  }
336
- .ys-file-preview__title span {
407
+ .ys-file-preview__meta {
408
+ display: flex;
409
+ align-items: center;
410
+ gap: 8px;
411
+ overflow: hidden;
337
412
  color: var(--ys-color-text-3);
338
413
  font-size: 12px;
339
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);
340
426
  }
341
427
  .ys-file-preview__tools {
342
428
  display: flex;
@@ -345,69 +431,53 @@ function openInTab() {
345
431
  gap: 2px;
346
432
  }
347
433
  .ys-file-preview__tool {
348
- display: inline-flex;
349
- align-items: center;
350
- justify-content: center;
351
434
  width: 32px;
352
435
  height: 32px;
353
- padding: 0;
354
- border: 0;
355
- border-radius: var(--ys-radius-s);
356
- background: transparent;
357
- color: var(--ys-color-text-2);
358
- cursor: pointer;
359
436
  }
360
- .ys-file-preview__tool:hover:not(:disabled) {
361
- background: var(--ys-color-bg-hover);
362
- color: var(--ys-color-primary);
363
- }
364
- /* 与顶栏图标按钮一致:不画聚焦框。 */
365
- .ys-file-preview__tool:focus,
366
- .ys-file-preview__tool:focus-visible {
367
- outline: none;
368
- }
369
- .ys-file-preview__tool:disabled {
370
- color: var(--ys-color-text-3);
371
- cursor: not-allowed;
372
- opacity: 0.5;
373
- }
374
- .ys-file-preview__divider {
375
- width: 1px;
437
+ .ys-file-preview__tool :deep(svg) {
438
+ width: 18px;
376
439
  height: 18px;
377
- margin: 0 4px;
378
- background: var(--ys-color-border);
379
440
  }
380
441
  .ys-file-preview__stage {
381
442
  display: flex;
382
- align-items: center;
383
- justify-content: center;
384
- height: min(80vh, 900px);
385
- background: var(--ys-color-bg);
443
+ flex-direction: column;
444
+ height: min(82vh, 920px);
445
+ background: var(--ys-color-stage);
386
446
  }
387
447
  .ys-file-preview__stage.is-fullscreen {
388
- height: calc(100vh - 53px);
448
+ height: calc(100vh - 57px);
449
+ height: calc(100dvh - 57px);
389
450
  }
390
- .ys-file-preview__stage.is-dark {
391
- background: #1f1f1f;
451
+ .ys-file-preview__stage.is-video {
452
+ background: var(--ys-color-media-bg);
392
453
  }
393
- .ys-file-preview__frame {
394
- width: 100%;
395
- height: 100%;
396
- border: 0;
397
- background: #fff;
454
+ .ys-file-preview__stage > :deep(*) {
455
+ flex: 1;
456
+ min-height: 0;
398
457
  }
399
- .ys-file-preview__image,
400
- .ys-file-preview__media {
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;
468
+ }
469
+ .ys-file-preview__image {
401
470
  max-width: 100%;
402
471
  max-height: 100%;
403
472
  object-fit: contain;
404
- }
405
- .ys-file-preview__audio {
406
- 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;
407
477
  }
408
478
  .ys-file-preview__text {
409
- align-self: stretch;
410
- width: 100%;
479
+ display: flex;
480
+ flex-direction: column;
411
481
  overflow: auto;
412
482
  background: var(--ys-color-bg-elevated);
413
483
  }
@@ -421,29 +491,16 @@ function openInTab() {
421
491
  white-space: pre-wrap;
422
492
  word-break: break-word;
423
493
  }
424
- .ys-file-preview__notice {
425
- padding: 8px 20px;
426
- border-bottom: 1px solid var(--ys-color-border);
427
- color: var(--ys-color-warning);
428
- font-size: 12px;
429
- }
430
- .ys-file-preview__state {
431
- display: flex;
432
- flex-direction: column;
433
- align-items: center;
434
- gap: 12px;
435
- color: var(--ys-color-text-3);
436
- font-size: 13px;
437
- }
438
- .ys-file-preview__state strong {
439
- color: var(--ys-color-text-1);
440
- font-size: 15px;
441
- font-weight: 600;
442
- }
443
- .ys-file-preview__placeholder {
444
- color: var(--ys-color-text-3);
445
- }
446
- .ys-file-preview__error {
447
- 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
+ }
448
505
  }
449
506
  </style>