@work-zhanguo/light-file-preview 0.0.12 → 0.0.14

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.
Files changed (32) hide show
  1. package/README.md +119 -91
  2. package/dist/DocxRenderer-Cck1uOjU.js +110 -0
  3. package/dist/{PdfRenderer-Due2M5cA.js → PdfRenderer-DweDxjLS.js} +102 -36
  4. package/dist/SheetRenderer-CMDoDBXR.js +940 -0
  5. package/dist/{UnsupportedRenderer-_3Y2XGCI.js → UnsupportedRenderer-pjXuzLhC.js} +1 -1
  6. package/dist/index-AN7FkZtw.js +346 -0
  7. package/dist/light-file-preview.js +1 -1
  8. package/dist/light-file-preview.umd.cjs +68 -68
  9. package/dist/standalone/light-file-preview.iife.js +72 -72
  10. package/dist/standalone/style.css +1 -1
  11. package/dist/style.css +1 -1
  12. package/dist/vue2/DocxRenderer-DR_4KeGA.js +110 -0
  13. package/dist/vue2/{PdfRenderer-pDvWG0pi.js → PdfRenderer-DNDmJ3M6.js} +102 -36
  14. package/dist/vue2/SheetRenderer-XW8dLaab.js +940 -0
  15. package/dist/vue2/{TextRenderer-B0bVXhgh.js → TextRenderer-CQsD7GMD.js} +1 -1
  16. package/dist/vue2/{UnsupportedRenderer-CvvKjt07.js → UnsupportedRenderer-fr1iHYbj.js} +3 -3
  17. package/dist/vue2/light-file-preview-vue2.js +1 -1
  18. package/dist/vue2/light-file-preview-vue2.umd.cjs +115 -115
  19. package/dist/vue2/{vue2-CqSgN38_.js → vue2-C42eMKpL.js} +1495 -1453
  20. package/package.json +4 -1
  21. package/public/screenshots/effect-docx.png +0 -0
  22. package/public/screenshots/effect-pdf.png +0 -0
  23. package/public/screenshots/effect-pptx.png +0 -0
  24. package/public/screenshots/effect-xlsx.png +0 -0
  25. package/public/screenshots/preview-dialog.png +0 -0
  26. package/public/screenshots/preview-docs.png +0 -0
  27. package/public/screenshots/preview-home.png +0 -0
  28. package/dist/DocxRenderer-DogNhBLd.js +0 -42
  29. package/dist/SheetRenderer-D1DAXE1c.js +0 -706
  30. package/dist/index-wdafvObE.js +0 -305
  31. package/dist/vue2/DocxRenderer-BUzCqs85.js +0 -42
  32. package/dist/vue2/SheetRenderer-Z48WXEZj.js +0 -706
package/README.md CHANGED
@@ -1,43 +1,72 @@
1
- # @work-zhanguo/light-file-preview
1
+ <h1 align="center">轻量预览 Light Preview</h1>
2
2
 
3
- # Gitee: [https://gitee.com/hou_zhan_guo/light-file-preview](https://gitee.com/hou_zhan_guo/light-file-preview)
3
+ <p align="center">
4
+ 用于业务系统里的附件预览,支持远程 URL、本地 File、Blob,接入方式尽量保持简单。
5
+ </p>
4
6
 
5
- # npm:[https://www.npmjs.com/package/@work-zhanguo/light-file-preview](https://www.npmjs.com/package/@work-zhanguo/light-file-preview)
7
+ <p align="center">
8
+ <a href="https://gitee.com/hou_zhan_guo/light-file-preview" target="_blank" rel="noreferrer">Gitee</a>
9
+ ·
10
+ <a href="https://www.npmjs.com/package/@work-zhanguo/light-file-preview" target="_blank" rel="noreferrer">npm</a>
11
+ </p>
6
12
 
7
13
  ## 项目简介
8
14
 
9
- 用于业务系统里的附件预览,支持传入文件路径、远程地址和本地文件,接入方式尽量保持简单。
10
-
11
- 当前版本:`0.0.12`
15
+ - 当前版本:`0.0.14`
16
+ - 适用场景:业务系统附件预览、在线查看、弹窗预览、新页面预览
17
+ - 支持 Vue 3、Vue 2 适配入口,以及非 Vue 项目的 standalone 产物
12
18
 
13
19
  最近更新:
14
20
 
21
+ - `0.0.14`:优化 `xlsx` 空白区域填充,移除未声明的表头/首列固定效果,并为 `PDF`、`DOCX` 增加默认分页与全部展示切换
22
+ - `0.0.13`:修复弹窗失败后同文件无法重试、运行时配置更新不生效的问题,补充 README 示例图与发包说明
15
23
  - `0.0.12`:修复 `xlsx` 部分单元格背景色、文字颜色和边框颜色未正确展示的问题,补充 `theme / tint / indexed` 颜色解析
16
24
  - `0.0.11`:修复 `xlsx` 图片拉伸和底色覆盖问题,优化单元格内容的对齐、换行和数值展示
17
- - `0.0.10`:优化 `xlsx` 预览密度,降低默认列宽和行高,减少横向滚动距离,整体样式更接近 Office
18
- - `0.0.9`:优化 `xlsx` 图片锚点尺寸和裁切边界,补充更接近 Excel 的公式栏名字框与编辑条样式
19
- - `0.0.8`:优化 `xlsx` 预览,补充工作表页签、首行首列编号区、冻结观感、单元格 hover / 选中高亮,并补充组件属性说明
20
- - `0.0.7`:修复 Vue2 `vue-cli / webpack4` 项目引入 PDF 预览时报 `import.meta.url`、`process.getBuiltinModule` 解析错误
21
- - `0.0.6`:修复 Vue2 `vue-cli / webpack4` 项目解析产物时报 `Unexpected token`,降低构建目标到 `es2018`
22
- - `0.0.5`:修复 Vue2 `vue-cli / webpack4` 项目子路径入口解析失败,补充 `vue2.js` 和 `style.css` 兼容入口
23
- - `0.0.4`:修复 Vue2 项目安装时的 `ERESOLVE` 依赖冲突,兼容 `Vue 2.6+` 和 `Vue 3.5+`
24
- - `0.0.3`:发布 `@work-zhanguo/light-file-preview`,补充文档与站点构建说明
25
25
 
26
- 详细版本记录见 [CHANGELOG.md](./CHANGELOG.md)
26
+ 详细版本记录见 [CHANGELOG.md](./CHANGELOG.md)
27
+
28
+ ## 效果预览
29
+
30
+ 仓库里的原始截图在 `public/screenshots/` 目录。
31
+
32
+ 下面的示例图使用 npm CDN 地址。当前仓库修改不会立即影响已发布版本;发布包含截图的新版本后,npm 页面会直接显示这些图片。
33
+
34
+ ### DOCX
35
+
36
+ ![DOCX 预览效果](https://unpkg.com/@work-zhanguo/light-file-preview/public/screenshots/effect-docx.png)
37
+
38
+ ### XLSX
39
+
40
+ ![XLSX 预览效果](https://unpkg.com/@work-zhanguo/light-file-preview/public/screenshots/effect-xlsx.png)
41
+
42
+ ### PDF
43
+
44
+ ![PDF 预览效果](https://unpkg.com/@work-zhanguo/light-file-preview/public/screenshots/effect-pdf.png)
45
+
46
+ ### PPTX 降级展示
47
+
48
+ 当前 `PPT` / `PPTX` 不做在线解析,组件会保留下载入口,不会伪装成已支持的在线预览。
49
+
50
+ ![PPTX 降级效果](https://unpkg.com/@work-zhanguo/light-file-preview/public/screenshots/effect-pptx.png)
27
51
 
28
52
  ## 支持文件
29
53
 
30
- 支持类型:
54
+ 在线预览支持:
31
55
 
32
56
  - `PNG`
33
57
  - `JPG`
34
58
  - `JPEG`
35
59
  - `GIF`
36
60
  - `WEBP`
61
+ - `BMP`
62
+ - `SVG`
37
63
  - `PDF`
38
64
  - `TXT`
39
65
  - `JSON`
40
66
  - `JS`
67
+ - `TS`
68
+ - `JSX`
69
+ - `TSX`
41
70
  - `HTML`
42
71
  - `CSS`
43
72
  - `MD`
@@ -50,10 +79,17 @@
50
79
  - `MP3`
51
80
  - `WAV`
52
81
 
82
+ 降级为下载入口:
83
+
84
+ - `DOC`
85
+ - `PPT`
86
+ - `PPTX`
87
+ - 其他未识别格式
88
+
53
89
  补充说明:
54
90
 
55
91
  - 支持远程 `URL`、本地 `File`、`Blob`
56
- - 支持新页面预览和弹窗预览
92
+ - 支持直接嵌入和弹窗预览
57
93
  - 不支持的格式不强行预览,统一保留下载入口
58
94
 
59
95
  ## 项目依赖
@@ -66,26 +102,10 @@
66
102
 
67
103
  ## 安装
68
104
 
69
- 安装组件:
70
-
71
105
  ```bash
72
106
  npm install @work-zhanguo/light-file-preview
73
107
  ```
74
108
 
75
- 如果是 `Vue3` 项目,注册入口:
76
-
77
- ```ts
78
- import LightFilePreview from '@work-zhanguo/light-file-preview';
79
- import '@work-zhanguo/light-file-preview/style.css';
80
- ```
81
-
82
- 如果是 `Vue2` 项目,注册入口:
83
-
84
- ```js
85
- import LightFilePreview from '@work-zhanguo/light-file-preview/vue2';
86
- import '@work-zhanguo/light-file-preview/style.css';
87
- ```
88
-
89
109
  ## 组件属性
90
110
 
91
111
  | 属性 | 类型 | 默认值 | 说明 |
@@ -108,9 +128,62 @@ import '@work-zhanguo/light-file-preview/style.css';
108
128
  - `update:visible`:弹窗关闭时回传状态
109
129
  - `error`:解析失败时返回错误对象
110
130
 
111
- ## 远程地址预览
131
+ ## Vue 3 集成
112
132
 
113
- 通过 `window.open` 传入网络地址,直接打开新页面预览。建议同时传 `name`,这样扩展名识别更稳定。
133
+ ```ts
134
+ import { createApp } from 'vue';
135
+ import App from './App.vue';
136
+ import LightFilePreview from '@work-zhanguo/light-file-preview';
137
+ import '@work-zhanguo/light-file-preview/style.css';
138
+
139
+ createApp(App).use(LightFilePreview).mount('#app');
140
+ ```
141
+
142
+ ```vue
143
+ <template>
144
+ <LightFilePreview source="/files/demo.pdf" />
145
+ </template>
146
+ ```
147
+
148
+ ## Vue 2 集成
149
+
150
+ ```js
151
+ import Vue from 'vue';
152
+ import LightFilePreview from '@work-zhanguo/light-file-preview/vue2';
153
+ import '@work-zhanguo/light-file-preview/style.css';
154
+
155
+ Vue.use(LightFilePreview);
156
+ ```
157
+
158
+ ```vue
159
+ <template>
160
+ <light-file-preview :source="fileUrl" />
161
+ </template>
162
+ ```
163
+
164
+ ## 弹窗预览
165
+
166
+ ```vue
167
+ <template>
168
+ <button @click="show = true">打开弹窗预览</button>
169
+
170
+ <LightFilePreview
171
+ v-model:visible="show"
172
+ source="https://501351981.github.io/vue-office/examples/dist/static/test-files/test.docx"
173
+ mode="dialog"
174
+ />
175
+ </template>
176
+
177
+ <script setup lang="ts">
178
+ import { ref } from 'vue';
179
+
180
+ const show = ref(false);
181
+ </script>
182
+ ```
183
+
184
+ ## 新页面预览
185
+
186
+ 建议同时传 `name`,这样扩展名识别更稳定。
114
187
 
115
188
  ```js
116
189
  const remoteUrl = 'https://example.com/files/test.docx';
@@ -127,6 +200,11 @@ window.open(previewUrl, '_blank');
127
200
 
128
201
  非 Vue 项目可以直接使用 standalone 产物。
129
202
 
203
+ 如果你是从 npm 包里复制静态文件,建议复制下面两个文件:
204
+
205
+ - `dist/standalone/light-file-preview.iife.js`
206
+ - `dist/standalone/style.css`
207
+
130
208
  ```html
131
209
  <link rel="stylesheet" href="/vendor/light-file-preview/style.css" />
132
210
  <div id="preview-root"></div>
@@ -171,55 +249,19 @@ FilePreviewBlock.template = 'your_module.FilePreviewBlock';
171
249
  </templates>
172
250
  ```
173
251
 
174
- ## Vue2 集成
175
-
176
- 通过单独适配入口接入:
177
-
178
- ```js
179
- import Vue from 'vue';
180
- import LightFilePreview from '@work-zhanguo/light-file-preview/vue2';
181
- import '@work-zhanguo/light-file-preview/style.css';
182
-
183
- Vue.use(LightFilePreview);
184
- ```
185
-
186
- ```vue
187
- <template>
188
- <light-file-preview :source="fileUrl" />
189
- </template>
190
- ```
191
-
192
- ## Vue3 集成
193
-
194
- ```ts
195
- import { createApp } from 'vue';
196
- import App from './App.vue';
197
- import LightFilePreview from '@work-zhanguo/light-file-preview';
198
- import '@work-zhanguo/light-file-preview/style.css';
199
-
200
- createApp(App).use(LightFilePreview).mount('#app');
201
- ```
202
-
203
- ```vue
204
- <template>
205
- <LightFilePreview source="/files/demo.pdf" />
206
- </template>
207
- ```
208
-
209
252
  ## 部署说明
210
253
 
211
- 直接复制打包产物:
254
+ 组件库打包:
212
255
 
213
256
  ```bash
214
257
  npm install
215
258
  npm run build
259
+ ```
216
260
 
217
- # 组件库产物
218
- dist/
261
+ 产物目录:
219
262
 
220
- # 可复制到任意项目的独立产物
221
- dist/standalone/
222
- ```
263
+ - `dist/`
264
+ - `dist/standalone/`
223
265
 
224
266
  如果要把首页演示页和文档页一起部署成静态站点,执行:
225
267
 
@@ -229,18 +271,4 @@ npm run build:site
229
271
 
230
272
  站点部署目录:
231
273
 
232
- ```bash
233
- dist-site/
234
- ```
235
-
236
- 其中会包含:
237
-
238
- - `dist-site/index.html`
239
- - `dist-site/docs.html`
240
-
241
- ## 接入说明
242
-
243
- - 本地上传文件只在当前浏览器中预览,不会保存到服务器
244
- - 如果是远程文件预览,需要目标地址允许浏览器访问和跨域读取
245
- - 弹窗预览会挂到 `body`
246
- - 不支持的文件格式会保留下载入口
274
+ - `dist-site/`
@@ -0,0 +1,110 @@
1
+ import { defineComponent as P, ref as i, computed as L, watch as _, onMounted as N, onBeforeUnmount as T, openBlock as p, createElementBlock as d, createElementVNode as n, toDisplayString as v, normalizeClass as b, Fragment as B, createCommentVNode as m } from "vue";
2
+ import { r as D } from "./text-Bqxn_tMI.js";
3
+ const R = { class: "lfp-document" }, $ = {
4
+ key: 0,
5
+ class: "lfp-page-toolbar"
6
+ }, H = { class: "lfp-page-toolbar__meta" }, S = { class: "lfp-page-toolbar__status" }, V = { class: "lfp-page-toolbar__actions" }, A = ["disabled"], O = { class: "lfp-page-toolbar__pager" }, U = ["disabled"], z = /* @__PURE__ */ P({
7
+ __name: "DocxRenderer",
8
+ props: {
9
+ source: {}
10
+ },
11
+ emits: ["loading", "error"],
12
+ setup(h, { emit: y }) {
13
+ const x = h, u = y, l = i(null), o = i(0), a = i(1), s = i("paged"), f = new AbortController(), C = L(() => o.value ? s.value === "paged" ? `第 ${a.value} / ${o.value} 页` : `共 ${o.value} 页` : "");
14
+ function w() {
15
+ if (!l.value)
16
+ return [];
17
+ const t = l.value.querySelector(".docx-wrapper");
18
+ if (!t)
19
+ return [];
20
+ const e = Array.from(t.children).filter(
21
+ (r) => r instanceof HTMLElement && (r.tagName === "SECTION" || r.classList.contains("docx"))
22
+ );
23
+ return e.length ? e : [t];
24
+ }
25
+ function c() {
26
+ const t = w();
27
+ o.value = t.length || 1, a.value = Math.min(Math.max(a.value, 1), o.value), t.forEach((e, r) => {
28
+ e.classList.add("lfp-docx-page"), e.dataset.page = String(r + 1), e.hidden = s.value === "paged" && r !== a.value - 1;
29
+ });
30
+ }
31
+ function g(t) {
32
+ s.value = t;
33
+ }
34
+ function M() {
35
+ a.value = Math.max(a.value - 1, 1);
36
+ }
37
+ function k() {
38
+ a.value = Math.min(a.value + 1, o.value);
39
+ }
40
+ async function E() {
41
+ u("loading", !0);
42
+ try {
43
+ const t = await D(x.source, f.signal), { renderAsync: e } = await import("./docx-preview-BV-bQyiM.js");
44
+ if (!l.value)
45
+ return;
46
+ l.value.innerHTML = "", await e(t, l.value, void 0, {
47
+ className: "lfp-docx-content",
48
+ ignoreWidth: !1,
49
+ ignoreHeight: !1,
50
+ useBase64URL: !0
51
+ }), c();
52
+ } catch (t) {
53
+ u("error", t instanceof Error ? t : new Error("DOCX 预览失败"));
54
+ } finally {
55
+ u("loading", !1);
56
+ }
57
+ }
58
+ return _(s, () => {
59
+ c();
60
+ }), _(a, () => {
61
+ s.value === "paged" && c();
62
+ }), N(() => {
63
+ E();
64
+ }), T(() => {
65
+ f.abort(), l.value && (l.value.innerHTML = "");
66
+ }), (t, e) => (p(), d("div", R, [
67
+ o.value ? (p(), d("div", $, [
68
+ n("div", H, [
69
+ e[2] || (e[2] = n("span", { class: "lfp-page-toolbar__title" }, "Word 视图", -1)),
70
+ n("span", S, v(C.value), 1)
71
+ ]),
72
+ n("div", V, [
73
+ n("button", {
74
+ class: b(["lfp-button is-ghost lfp-page-toolbar__toggle", { "is-active": s.value === "paged" }]),
75
+ type: "button",
76
+ onClick: e[0] || (e[0] = (r) => g("paged"))
77
+ }, " 分页 ", 2),
78
+ n("button", {
79
+ class: b(["lfp-button is-ghost lfp-page-toolbar__toggle", { "is-active": s.value === "all" }]),
80
+ type: "button",
81
+ onClick: e[1] || (e[1] = (r) => g("all"))
82
+ }, " 全部 ", 2),
83
+ s.value === "paged" && o.value > 1 ? (p(), d(B, { key: 0 }, [
84
+ n("button", {
85
+ class: "lfp-button is-ghost lfp-page-toolbar__nav",
86
+ type: "button",
87
+ disabled: a.value <= 1,
88
+ onClick: M
89
+ }, " 上一页 ", 8, A),
90
+ n("span", O, v(a.value) + " / " + v(o.value), 1),
91
+ n("button", {
92
+ class: "lfp-button is-ghost lfp-page-toolbar__nav",
93
+ type: "button",
94
+ disabled: a.value >= o.value,
95
+ onClick: k
96
+ }, " 下一页 ", 8, U)
97
+ ], 64)) : m("", !0)
98
+ ])
99
+ ])) : m("", !0),
100
+ n("div", {
101
+ ref_key: "containerRef",
102
+ ref: l,
103
+ class: "lfp-docx"
104
+ }, null, 512)
105
+ ]));
106
+ }
107
+ });
108
+ export {
109
+ z as default
110
+ };