vitepress-plugin-filelist 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,8 @@
7
7
  - 📁 树形目录,文件夹按需加载
8
8
  - ✅ 勾选文件;选中文件夹会自动加载并选中其下所有层级的文件
9
9
  - 📦 批量打包 ZIP(基于 `fflate`),带进度;保留目录结构,不同目录的同名文件不会互相覆盖
10
- - ⬇️ 单文件下载与预览(`/d/`、`/p/`、`fs/get` 的 `raw_url`)
10
+ - ⬇️ 单文件下载(`fs/get` 的 `raw_url`,回退 `/d/`)
11
+ - 👁️ 弹窗预览(不跳转):图片、音视频、文本、PDF;Office 等其它类型显示文件信息与下载
11
12
  - 🔐 目录密码输入,可选只读 token
12
13
  - 🔎 当前树过滤,按名称 / 大小 / 日期排序
13
14
  - 🎨 紧凑表格:按文件类型着色的扩展名标签、层级引导线,跟随 VitePress 亮 / 暗主题
@@ -132,6 +133,22 @@ interface FileListSource {
132
133
  }
133
134
  ```
134
135
 
136
+ ## 预览
137
+
138
+ 点击预览按钮在当前页面的弹窗(原生 `<dialog>`)中显示,不跳转、不打开新标签页。只有能在页面内显示的类型才有预览按钮;点击文件名仍是下载。
139
+
140
+ | 类型 | 扩展名(节选) | 方式 |
141
+ | --- | --- | --- |
142
+ | 图片 | png、jpg、gif、webp、svg、avif | `<img>`,可旋转、切换原始大小 |
143
+ | 视频 / 音频 | mp4、webm、mov / mp3、m4a、flac、wav | 原生播放器(格式以浏览器支持为准) |
144
+ | 文本 | txt、md、json、csv、yaml、日志与常见代码 | 只读取前 1 MB(Range 请求),纯文本显示 |
145
+ | PDF | pdf | 优先使用 OpenList `iframe_previews` 中配置的 PDF 查看器;未配置时用浏览器自带阅读器(下载后以 Blob 显示,上限 50 MB) |
146
+ | 其它(含 Office、压缩包) | — | 弹窗内显示文件信息和下载按钮 |
147
+
148
+ - 弹窗内 ← / → 切换当前列表中的可预览文件,Esc 或点击遮罩关闭
149
+ - 读取文本和浏览器 PDF 需要文件地址允许跨域:经 OpenList 代理(`/p/`)时由 OpenList 的 CORS 设置决定;网盘直链由网盘决定。失败时显示“无法在页面内预览”和下载按钮
150
+ - `iframe_previews` 来自 `/api/public/settings`,与 OpenList 网页端使用同一配置,占位符 `$url`、`$e_url`、`$b_url`、`$durl`、`$name` 的含义一致
151
+
135
152
  ## 国际化
136
153
 
137
154
  ```md
@@ -167,8 +184,8 @@ import { fileListLocales, formatLabel, resolveLabels } from 'vitepress-plugin-fi
167
184
  | --- | --- |
168
185
  | `POST /api/fs/list` | 目录列表(`per_page: 0`) |
169
186
  | `POST /api/fs/get` | 获取下载 / 预览 / 打包用的 `raw_url`;失败时回退到 `/d/...?sign=` |
170
- | `GET /api/public/settings` | 获取 `site_title` |
171
- | `GET /d/...`、`GET /p/...` | OpenList 生成的下载 / 预览链接 |
187
+ | `GET /api/public/settings` | 获取 `site_title`、`iframe_previews` |
188
+ | `GET /d/...`、`GET /p/...` | 下载与预览读取的文件地址 |
172
189
 
173
190
  ## 导出
174
191
 
@@ -32,6 +32,7 @@ interface FileListLabels {
32
32
  demoPreview: string;
33
33
  demoBatch: string;
34
34
  downloadFailed: string;
35
+ /** @deprecated Preview errors are shown in the dialog (`previewUnavailable`). */
35
36
  previewFailed: string;
36
37
  batchFailed: string;
37
38
  defaultZip: string;
@@ -52,6 +53,23 @@ interface FileListLabels {
52
53
  expand: string;
53
54
  /** Accessible name of the collapse button, `{name}`. */
54
55
  collapse: string;
56
+ /** Preview dialog: close button. */
57
+ close: string;
58
+ /** Preview dialog: previous / next previewable file. */
59
+ previous: string;
60
+ next: string;
61
+ /** Preview dialog: rotate image by 90°. */
62
+ rotate: string;
63
+ /** Preview dialog: toggle the image between fit-to-window and actual size. */
64
+ actualSize: string;
65
+ /** Preview dialog: file type that is not previewed (Office and others). */
66
+ previewUnsupported: string;
67
+ /** Preview dialog: preview failed (network, CORS, unsupported codec). */
68
+ previewUnavailable: string;
69
+ /** Preview dialog: PDF larger than the in-page limit, `{size}`. */
70
+ previewTooLarge: string;
71
+ /** Preview dialog: only the first `{size}` of a text file is shown. */
72
+ textTruncated: string;
55
73
  }
56
74
  interface FileListSource {
57
75
  /** OpenList path, directory or single file. */
@@ -213,6 +231,32 @@ export declare function totalSize(items: Array<{
213
231
  size?: number;
214
232
  }>): number;
215
233
  export declare function compareNodes(a: SortableNode, b: SortableNode, key: SortKey, ascending?: boolean): number;
234
+ export type PreviewKind = 'image' | 'video' | 'audio' | 'text' | 'pdf' | 'none';
235
+ /**
236
+ * How a file is shown in the preview dialog. Office documents and anything
237
+ * else the browser cannot render are `none` (info + download).
238
+ */
239
+ export declare function previewKind(name: string): PreviewKind;
240
+ export interface IframePreview {
241
+ label: string;
242
+ scheme: string;
243
+ }
244
+ /**
245
+ * Viewers from OpenList's public `iframe_previews` setting that match a file,
246
+ * in the order OpenList lists them. Keys are comma-separated extensions or a
247
+ * `/regex/flags` tested against the extension, as in OpenList's frontend.
248
+ */
249
+ export declare function iframePreviewsFor(name: string, setting: string | undefined): IframePreview[];
250
+ /**
251
+ * Fill an OpenList preview scheme: `$name`, `$url` (raw URL) and `$durl`
252
+ * (signed download URL), each optionally prefixed with `e` (URI-encode) or
253
+ * `b` (base64), e.g. `$e_url`, `$b_url`, `$e_durl`.
254
+ */
255
+ export declare function fillPreviewUrl(scheme: string, args: {
256
+ name: string;
257
+ rawUrl: string;
258
+ downloadUrl: string;
259
+ }): string;
216
260
  /**
217
261
  * Register `<FileList>` and `<VPFileList>` globally.
218
262
  *