document-viewer-vue3 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Document Viewer contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # document-viewer-vue3
2
+
3
+ 面向 Vue 3 的浏览器端文档预览组件。使用一个组件统一展示 Word、Excel、PDF 与 PowerPoint,支持本地 `File` 和远程 URL,并提供加载进度、缩放、下载、打印和主题控制。
4
+
5
+ [在线示例](https://banyan666.github.io/DocumentViewerV3/) · [使用文档](https://banyan666.github.io/DocumentViewerV3/docs/)
6
+
7
+ ## 特性
8
+
9
+ - 常用格式统一入口:DOC / DOCX、XLS / XLSX、PDF、PPTX
10
+ - 本地文件直接在浏览器中读取,不要求服务端转换
11
+ - Word、Excel、PDF、PowerPoint 渲染器按需加载
12
+ - 支持 ESM、UMD、TypeScript 类型声明与独立样式入口
13
+ - 提供深浅主题、工具栏、缩放范围和表格渲染限制
14
+ - 包含完整示例项目与 VitePress 中文文档
15
+
16
+ ## 格式支持
17
+
18
+ | 类型 | 扩展名 | 预览内容 |
19
+ | --- | --- | --- |
20
+ | Word | `.doc` `.dot` `.docx` `.docm` `.dotx` `.dotm` | 文本、分页、表格、图片与常见样式 |
21
+ | Excel | `.xls` `.xlsx` `.xlsm` `.xlsb` `.xlt` `.xltx` `.xltm` | 多工作表、单元格内容与基础格式 |
22
+ | PDF | `.pdf` | 多页 Canvas 渲染 |
23
+ | PowerPoint | `.pptx` `.pptm` `.potx` `.potm` `.ppsx` `.ppsm` | 文本、图片与基础形状 |
24
+
25
+ 远程 URL 由浏览器直接读取,需要目标服务器允许 CORS。旧版二进制 `.ppt` 暂不支持,建议转换为 `.pptx`。
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ pnpm add document-viewer-vue3
31
+ ```
32
+
33
+ ## 快速开始
34
+
35
+ ```vue
36
+ <script setup lang="ts">
37
+ import { ref } from 'vue'
38
+ import { DocumentViewer } from 'document-viewer-vue3'
39
+ import 'document-viewer-vue3/style.css'
40
+
41
+ const file = ref<File>()
42
+
43
+ function chooseFile(event: Event) {
44
+ const input = event.currentTarget as HTMLInputElement
45
+ file.value = input.files?.[0]
46
+ }
47
+ </script>
48
+
49
+ <template>
50
+ <input
51
+ type="file"
52
+ accept=".doc,.docx,.xls,.xlsx,.pdf,.pptx"
53
+ @change="chooseFile"
54
+ >
55
+ <DocumentViewer
56
+ :file="file"
57
+ height="720px"
58
+ :options="{ theme: 'light', toolbar: true }"
59
+ @load-complete="console.log('预览完成')"
60
+ @error="console.error"
61
+ />
62
+ </template>
63
+ ```
64
+
65
+ 预览远程文档:
66
+
67
+ ```vue
68
+ <DocumentViewer
69
+ url="https://api.example.com/files/download?id=100"
70
+ filename="report.pdf"
71
+ height="720px"
72
+ />
73
+ ```
74
+
75
+ URL 本身不含扩展名时,需要使用 `filename` 帮助组件识别格式。
76
+
77
+ ## 全局注册
78
+
79
+ ```ts
80
+ import { createApp } from 'vue'
81
+ import DocumentViewer from 'document-viewer-vue3'
82
+ import 'document-viewer-vue3/style.css'
83
+ import App from './App.vue'
84
+
85
+ createApp(App)
86
+ .use(DocumentViewer)
87
+ .mount('#app')
88
+ ```
89
+
90
+ 也可以自定义全局组件名:
91
+
92
+ ```ts
93
+ app.use(DocumentViewer, { componentName: 'OfficePreview' })
94
+ ```
95
+
96
+ ## Props
97
+
98
+ | 属性 | 类型 | 默认值 | 说明 |
99
+ | --- | --- | --- | --- |
100
+ | `file` | `File` | — | 本地文件,与 URL 同时存在时优先 |
101
+ | `url` | `string` | — | 允许浏览器跨域读取的远程地址 |
102
+ | `filename` | `string` | — | URL 不含扩展名时用于格式识别 |
103
+ | `height` | `string \| number` | `'100%'` | 预览区域高度 |
104
+ | `strict` | `boolean` | `true` | 是否拒绝支持清单以外的扩展名 |
105
+ | `emptyText` | `string` | 内置提示 | 空状态文字 |
106
+ | `options` | `DocumentViewerOptions` | `{}` | 工具栏、主题、缩放和渲染限制 |
107
+
108
+ `DocumentViewerOptions`:
109
+
110
+ | 选项 | 类型 | 默认值 | 说明 |
111
+ | --- | --- | --- | --- |
112
+ | `toolbar` | `boolean` | `true` | 显示内置工具栏 |
113
+ | `theme` | `'light' \| 'dark' \| 'system'` | `'light'` | 组件主题 |
114
+ | `initialZoom` | `number` | `1` | 初始缩放比例 |
115
+ | `minZoom` | `number` | `0.5` | 最小缩放比例 |
116
+ | `maxZoom` | `number` | `2.5` | 最大缩放比例 |
117
+ | `spreadsheetMaxRows` | `number` | — | 每个工作表最多渲染行数 |
118
+ | `spreadsheetMaxColumns` | `number` | — | 每个工作表最多渲染列数 |
119
+ | `fetchOptions` | `RequestInit` | — | 远程文档的请求配置 |
120
+
121
+ ## 事件与实例方法
122
+
123
+ 事件:
124
+
125
+ - `load-start` / `load-complete`
126
+ - `unload-start` / `unload-complete`
127
+ - `progress`
128
+ - `zoom-change`
129
+ - `error`
130
+
131
+ 模板 `ref` 暴露的方法:
132
+
133
+ - `reload()` / `destroy()`
134
+ - `zoomIn()` / `zoomOut()` / `resetZoom()` / `setZoom()`
135
+ - `getZoomState()`
136
+ - `downloadOriginalFile()`
137
+ - `print()`
138
+ - `getScrollContainer()`
139
+
140
+ ## 示例与文档
141
+
142
+ ```bash
143
+ pnpm install
144
+ pnpm dev # 示例站:http://127.0.0.1:5174
145
+ pnpm docs:dev # VitePress:http://127.0.0.1:5175
146
+ ```
147
+
148
+ 项目结构:
149
+
150
+ ```text
151
+ document-viewer/
152
+ ├─ src/ # 组件实现
153
+ ├─ examples/ # Vite + Vue 3 示例站
154
+ ├─ docs/ # VitePress 文档站
155
+ └─ scripts/ # 构建与发布校验
156
+ ```
157
+
158
+ ## 构建与发布
159
+
160
+ ```bash
161
+ pnpm type-check # 类型检查
162
+ pnpm build # 构建 npm 组件包
163
+ pnpm build:examples # 构建示例站
164
+ pnpm build:pages # 构建 GitHub Pages 站点
165
+ pnpm docs:build # 构建文档站
166
+ pnpm verify # 完整验证
167
+ pnpm pack:check # 检查 npm 发布内容
168
+ ```
169
+
170
+ 组件产物输出到 `document-viewer-vue3/`,示例站输出到 `dist-examples/`。确认 `package.json` 的作者、仓库和主页信息后,可执行:
171
+
172
+ ```bash
173
+ npm publish --access public
174
+ ```
175
+
176
+ ## License
177
+
178
+ MIT。第三方软件的版权与许可证信息见 `THIRD_PARTY_NOTICES.md`。
@@ -0,0 +1,43 @@
1
+ # Third-party notices
2
+
3
+ The distributed JavaScript contains code from the following projects:
4
+
5
+ | Project | License | Project URL |
6
+ | --- | --- | --- |
7
+ | docx-preview | Apache License 2.0 | https://github.com/VolodymyrBaydalka/docxjs |
8
+ | msdoc-viewer parser source | MIT License | https://github.com/flyfish-dev/docjs |
9
+ | DOMPurify | Apache License 2.0 or Mozilla Public License 2.0 | https://github.com/cure53/DOMPurify |
10
+ | PDF.js / pdfjs-dist | Apache License 2.0 | https://github.com/mozilla/pdf.js |
11
+ | SheetJS Community Edition / xlsx | Apache License 2.0 | https://sheetjs.com/ |
12
+ | JSZip | MIT License | https://stuk.github.io/jszip/ |
13
+
14
+ Apache License 2.0 text: https://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ MIT-licensed portions retain their copyright notices in the respective upstream
17
+ distributions. This notice does not alter the license of the original projects.
18
+
19
+ The legacy DOC parser source is derived from the public msdoc-viewer 0.2.0 line:
20
+
21
+ ```text
22
+ MIT License
23
+
24
+ Copyright (c) 2026 msdoc-viewer contributors
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining a copy
27
+ of this software and associated documentation files (the "Software"), to deal
28
+ in the Software without restriction, including without limitation the rights
29
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30
+ copies of the Software, and to permit persons to whom the Software is
31
+ furnished to do so, subject to the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be included in all
34
+ copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42
+ SOFTWARE.
43
+ ```
@@ -0,0 +1,178 @@
1
+ # document-viewer-vue3
2
+
3
+ 面向 Vue 3 的浏览器端文档预览组件。使用一个组件统一展示 Word、Excel、PDF 与 PowerPoint,支持本地 `File` 和远程 URL,并提供加载进度、缩放、下载、打印和主题控制。
4
+
5
+ [在线示例](https://banyan666.github.io/DocumentViewerV3/) · [使用文档](https://banyan666.github.io/DocumentViewerV3/docs/)
6
+
7
+ ## 特性
8
+
9
+ - 常用格式统一入口:DOC / DOCX、XLS / XLSX、PDF、PPTX
10
+ - 本地文件直接在浏览器中读取,不要求服务端转换
11
+ - Word、Excel、PDF、PowerPoint 渲染器按需加载
12
+ - 支持 ESM、UMD、TypeScript 类型声明与独立样式入口
13
+ - 提供深浅主题、工具栏、缩放范围和表格渲染限制
14
+ - 包含完整示例项目与 VitePress 中文文档
15
+
16
+ ## 格式支持
17
+
18
+ | 类型 | 扩展名 | 预览内容 |
19
+ | --- | --- | --- |
20
+ | Word | `.doc` `.dot` `.docx` `.docm` `.dotx` `.dotm` | 文本、分页、表格、图片与常见样式 |
21
+ | Excel | `.xls` `.xlsx` `.xlsm` `.xlsb` `.xlt` `.xltx` `.xltm` | 多工作表、单元格内容与基础格式 |
22
+ | PDF | `.pdf` | 多页 Canvas 渲染 |
23
+ | PowerPoint | `.pptx` `.pptm` `.potx` `.potm` `.ppsx` `.ppsm` | 文本、图片与基础形状 |
24
+
25
+ 远程 URL 由浏览器直接读取,需要目标服务器允许 CORS。旧版二进制 `.ppt` 暂不支持,建议转换为 `.pptx`。
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ pnpm add document-viewer-vue3
31
+ ```
32
+
33
+ ## 快速开始
34
+
35
+ ```vue
36
+ <script setup lang="ts">
37
+ import { ref } from 'vue'
38
+ import { DocumentViewer } from 'document-viewer-vue3'
39
+ import 'document-viewer-vue3/style.css'
40
+
41
+ const file = ref<File>()
42
+
43
+ function chooseFile(event: Event) {
44
+ const input = event.currentTarget as HTMLInputElement
45
+ file.value = input.files?.[0]
46
+ }
47
+ </script>
48
+
49
+ <template>
50
+ <input
51
+ type="file"
52
+ accept=".doc,.docx,.xls,.xlsx,.pdf,.pptx"
53
+ @change="chooseFile"
54
+ >
55
+ <DocumentViewer
56
+ :file="file"
57
+ height="720px"
58
+ :options="{ theme: 'light', toolbar: true }"
59
+ @load-complete="console.log('预览完成')"
60
+ @error="console.error"
61
+ />
62
+ </template>
63
+ ```
64
+
65
+ 预览远程文档:
66
+
67
+ ```vue
68
+ <DocumentViewer
69
+ url="https://api.example.com/files/download?id=100"
70
+ filename="report.pdf"
71
+ height="720px"
72
+ />
73
+ ```
74
+
75
+ URL 本身不含扩展名时,需要使用 `filename` 帮助组件识别格式。
76
+
77
+ ## 全局注册
78
+
79
+ ```ts
80
+ import { createApp } from 'vue'
81
+ import DocumentViewer from 'document-viewer-vue3'
82
+ import 'document-viewer-vue3/style.css'
83
+ import App from './App.vue'
84
+
85
+ createApp(App)
86
+ .use(DocumentViewer)
87
+ .mount('#app')
88
+ ```
89
+
90
+ 也可以自定义全局组件名:
91
+
92
+ ```ts
93
+ app.use(DocumentViewer, { componentName: 'OfficePreview' })
94
+ ```
95
+
96
+ ## Props
97
+
98
+ | 属性 | 类型 | 默认值 | 说明 |
99
+ | --- | --- | --- | --- |
100
+ | `file` | `File` | — | 本地文件,与 URL 同时存在时优先 |
101
+ | `url` | `string` | — | 允许浏览器跨域读取的远程地址 |
102
+ | `filename` | `string` | — | URL 不含扩展名时用于格式识别 |
103
+ | `height` | `string \| number` | `'100%'` | 预览区域高度 |
104
+ | `strict` | `boolean` | `true` | 是否拒绝支持清单以外的扩展名 |
105
+ | `emptyText` | `string` | 内置提示 | 空状态文字 |
106
+ | `options` | `DocumentViewerOptions` | `{}` | 工具栏、主题、缩放和渲染限制 |
107
+
108
+ `DocumentViewerOptions`:
109
+
110
+ | 选项 | 类型 | 默认值 | 说明 |
111
+ | --- | --- | --- | --- |
112
+ | `toolbar` | `boolean` | `true` | 显示内置工具栏 |
113
+ | `theme` | `'light' \| 'dark' \| 'system'` | `'light'` | 组件主题 |
114
+ | `initialZoom` | `number` | `1` | 初始缩放比例 |
115
+ | `minZoom` | `number` | `0.5` | 最小缩放比例 |
116
+ | `maxZoom` | `number` | `2.5` | 最大缩放比例 |
117
+ | `spreadsheetMaxRows` | `number` | — | 每个工作表最多渲染行数 |
118
+ | `spreadsheetMaxColumns` | `number` | — | 每个工作表最多渲染列数 |
119
+ | `fetchOptions` | `RequestInit` | — | 远程文档的请求配置 |
120
+
121
+ ## 事件与实例方法
122
+
123
+ 事件:
124
+
125
+ - `load-start` / `load-complete`
126
+ - `unload-start` / `unload-complete`
127
+ - `progress`
128
+ - `zoom-change`
129
+ - `error`
130
+
131
+ 模板 `ref` 暴露的方法:
132
+
133
+ - `reload()` / `destroy()`
134
+ - `zoomIn()` / `zoomOut()` / `resetZoom()` / `setZoom()`
135
+ - `getZoomState()`
136
+ - `downloadOriginalFile()`
137
+ - `print()`
138
+ - `getScrollContainer()`
139
+
140
+ ## 示例与文档
141
+
142
+ ```bash
143
+ pnpm install
144
+ pnpm dev # 示例站:http://127.0.0.1:5174
145
+ pnpm docs:dev # VitePress:http://127.0.0.1:5175
146
+ ```
147
+
148
+ 项目结构:
149
+
150
+ ```text
151
+ document-viewer/
152
+ ├─ src/ # 组件实现
153
+ ├─ examples/ # Vite + Vue 3 示例站
154
+ ├─ docs/ # VitePress 文档站
155
+ └─ scripts/ # 构建与发布校验
156
+ ```
157
+
158
+ ## 构建与发布
159
+
160
+ ```bash
161
+ pnpm type-check # 类型检查
162
+ pnpm build # 构建 npm 组件包
163
+ pnpm build:examples # 构建示例站
164
+ pnpm build:pages # 构建 GitHub Pages 站点
165
+ pnpm docs:build # 构建文档站
166
+ pnpm verify # 完整验证
167
+ pnpm pack:check # 检查 npm 发布内容
168
+ ```
169
+
170
+ 组件产物输出到 `document-viewer-vue3/`,示例站输出到 `dist-examples/`。确认 `package.json` 的作者、仓库和主页信息后,可执行:
171
+
172
+ ```bash
173
+ npm publish --access public
174
+ ```
175
+
176
+ ## License
177
+
178
+ MIT。第三方软件的版权与许可证信息见 `THIRD_PARTY_NOTICES.md`。
@@ -0,0 +1,39 @@
1
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/typeof.js
2
+ function e(t) {
3
+ "@babel/helpers - typeof";
4
+ return e = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
5
+ return typeof e;
6
+ } : function(e) {
7
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
8
+ }, e(t);
9
+ }
10
+ //#endregion
11
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPrimitive.js
12
+ function t(t, n) {
13
+ if (e(t) != "object" || !t) return t;
14
+ var r = t[Symbol.toPrimitive];
15
+ if (r !== void 0) {
16
+ var i = r.call(t, n || "default");
17
+ if (e(i) != "object") return i;
18
+ throw TypeError("@@toPrimitive must return a primitive value.");
19
+ }
20
+ return (n === "string" ? String : Number)(t);
21
+ }
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPropertyKey.js
24
+ function n(n) {
25
+ var r = t(n, "string");
26
+ return e(r) == "symbol" ? r : r + "";
27
+ }
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/defineProperty.js
30
+ function r(e, t, r) {
31
+ return (t = n(t)) in e ? Object.defineProperty(e, t, {
32
+ value: r,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }) : e[t] = r, e;
37
+ }
38
+ //#endregion
39
+ export { r as t };