@flyfish-group/file-viewer 1.0.3 → 1.0.6

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 (70) hide show
  1. package/LICENSE +160 -0
  2. package/README.md +152 -67
  3. package/dist/components/CadViewer.js +1 -0
  4. package/dist/components/CodeViewer.js +1 -0
  5. package/dist/components/ImageViewer.js +1 -1936
  6. package/dist/components/MarkdownViewer.js +1 -1478
  7. package/dist/components/OfdViewer.js +1 -0
  8. package/dist/components/PdfView.js +1 -22627
  9. package/dist/components/PptxRender.js +1 -21757
  10. package/dist/components/XlsxTable.js +1 -54411
  11. package/dist/components/_commonjsHelpers.js +1 -30
  12. package/dist/components/docx-preview.js +7 -5622
  13. package/dist/components/index.js +1 -1877
  14. package/dist/components/index2.js +1 -0
  15. package/dist/components/jszip.min.js +1 -0
  16. package/dist/components/ofd.js +1 -0
  17. package/dist/components/worker-ref.js +1 -21
  18. package/dist/index.d.ts +45 -0
  19. package/dist/index.mjs +1 -6
  20. package/dist/index.umd.js +7 -260
  21. package/dist/package/index.d.ts +6 -2
  22. package/dist/style.css +15 -46
  23. package/dist/worker/pdf.worker.js +1 -58
  24. package/dist/worker/pptx.worker.js +1 -21
  25. package/dist/worker/sheet.worker.js +1 -38
  26. package/package.json +73 -43
  27. package/dist/components/_commonjs-dynamic-modules.js +0 -6
  28. package/dist/components/utils.d.ts +0 -3
  29. package/dist/main.d.ts +0 -0
  30. package/dist/package/common/type.d.ts +0 -30
  31. package/dist/package/common/util.d.ts +0 -5
  32. package/dist/package/common/worker-ref.d.ts +0 -12
  33. package/dist/package/components/FileViewer/FileViewer.vue.d.ts +0 -18
  34. package/dist/package/components/FileViewer/index.d.ts +0 -2
  35. package/dist/package/components/FileViewer/util.d.ts +0 -2
  36. package/dist/package/use/index.d.ts +0 -1
  37. package/dist/package/use/worker.d.ts +0 -24
  38. package/dist/package/vendors/docx/index.d.ts +0 -4
  39. package/dist/package/vendors/image/ImageViewer.vue.d.ts +0 -15
  40. package/dist/package/vendors/image/index.d.ts +0 -5
  41. package/dist/package/vendors/md/MarkdownViewer.vue.d.ts +0 -15
  42. package/dist/package/vendors/md/index.d.ts +0 -5
  43. package/dist/package/vendors/mp4/index.d.ts +0 -4
  44. package/dist/package/vendors/pdf/PdfView.vue.d.ts +0 -15
  45. package/dist/package/vendors/pdf/index.d.ts +0 -2
  46. package/dist/package/vendors/pdf/worker/index.d.ts +0 -4
  47. package/dist/package/vendors/pptx/PptxRender.vue.d.ts +0 -87
  48. package/dist/package/vendors/pptx/index.d.ts +0 -7
  49. package/dist/package/vendors/pptx/options.d.ts +0 -39
  50. package/dist/package/vendors/pptx/support/chart.d.ts +0 -4
  51. package/dist/package/vendors/pptx/worker/index.d.ts +0 -4
  52. package/dist/package/vendors/renders.d.ts +0 -3
  53. package/dist/package/vendors/text/CodeViewer.vue.d.ts +0 -15
  54. package/dist/package/vendors/text/index.d.ts +0 -7
  55. package/dist/package/vendors/xlsx/XlsxTable.vue.d.ts +0 -17
  56. package/dist/package/vendors/xlsx/index.d.ts +0 -5
  57. package/dist/package/vendors/xlsx/render.d.ts +0 -6
  58. package/dist/package/vendors/xlsx/util.d.ts +0 -8
  59. package/dist/package/vendors/xlsx/worker/index.d.ts +0 -6
  60. package/dist/package/vendors/xlsx/worker/xls/SheetJsModel.d.ts +0 -36
  61. package/dist/package/vendors/xlsx/worker/xls/index.d.ts +0 -4
  62. package/dist/package/vendors/xlsx/worker/xls/sheet.worker.d.ts +0 -1
  63. package/dist/package/vendors/xlsx/worker/xlsx/ExcelJsModel.d.ts +0 -39
  64. package/dist/package/vendors/xlsx/worker/xlsx/color.d.ts +0 -2
  65. package/dist/package/vendors/xlsx/worker/xlsx/context.d.ts +0 -7
  66. package/dist/package/vendors/xlsx/worker/xlsx/index.d.ts +0 -4
  67. package/dist/package/vendors/xlsx/worker/xlsx/util.d.ts +0 -10
  68. package/dist/package/vendors/xlsx/worker/xlsx/xlsx.worker.d.ts +0 -2
  69. package/dist/vite.svg +0 -1
  70. package/dist/worker/xlsx.worker.js +0 -62
package/LICENSE ADDED
@@ -0,0 +1,160 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work by
47
+ the copyright owner or by an individual or Legal Entity authorized to submit on
48
+ behalf of the copyright owner. For the purposes of this definition, "submitted"
49
+ means any form of electronic, verbal, or written communication sent to the
50
+ Licensor or its representatives, including but not limited to communication on
51
+ electronic mailing lists, source code control systems, and issue tracking systems
52
+ that are managed by, or on behalf of, the Licensor for the purpose of discussing
53
+ and improving the Work, but excluding communication that is conspicuously marked
54
+ or otherwise designated in writing by the copyright owner as "Not a
55
+ Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or
66
+ Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
71
+ license to make, have made, use, offer to sell, sell, import, and otherwise
72
+ transfer the Work, where such license applies only to those patent claims
73
+ licensable by such Contributor that are necessarily infringed by their
74
+ Contribution(s) alone or by combination of their Contribution(s) with the Work to
75
+ which such Contribution(s) was submitted. If You institute patent litigation
76
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
77
+ alleging that the Work or a Contribution incorporated within the Work
78
+ constitutes direct or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate as of the date
80
+ such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
83
+ Derivative Works thereof in any medium, with or without modifications, and in
84
+ Source or Object form, provided that You meet the following conditions:
85
+
86
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
87
+ this License; and
88
+
89
+ (b) You must cause any modified files to carry prominent notices stating that
90
+ You changed the files; and
91
+
92
+ (c) You must retain, in the Source form of any Derivative Works that You
93
+ distribute, all copyright, patent, trademark, and attribution notices from the
94
+ Source form of the Work, excluding those notices that do not pertain to any part
95
+ of the Derivative Works; and
96
+
97
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
98
+ any Derivative Works that You distribute must include a readable copy of the
99
+ attribution notices contained within such NOTICE file, excluding those notices
100
+ that do not pertain to any part of the Derivative Works, in at least one of the
101
+ following places: within a NOTICE text file distributed as part of the Derivative
102
+ Works; within the Source form or documentation, if provided along with the
103
+ Derivative Works; or, within a display generated by the Derivative Works, if and
104
+ wherever such third-party notices normally appear. The contents of the NOTICE
105
+ file are for informational purposes only and do not modify the License. You may
106
+ add Your own attribution notices within Derivative Works that You distribute,
107
+ alongside or as an addendum to the NOTICE text from the Work, provided that such
108
+ additional attribution notices cannot be construed as modifying the License.
109
+
110
+ You may add Your own copyright statement to Your modifications and may provide
111
+ additional or different license terms and conditions for use, reproduction, or
112
+ distribution of Your modifications, or for any such Derivative Works as a whole,
113
+ provided Your use, reproduction, and distribution of the Work otherwise complies
114
+ with the conditions stated in this License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
117
+ Contribution intentionally submitted for inclusion in the Work by You to the
118
+ Licensor shall be under the terms and conditions of this License, without any
119
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
120
+ supersede or modify the terms of any separate license agreement you may have
121
+ executed with Licensor regarding such Contributions.
122
+
123
+ 6. Trademarks. This License does not grant permission to use the trade names,
124
+ trademarks, service marks, or product names of the Licensor, except as required
125
+ for reasonable and customary use in describing the origin of the Work and
126
+ reproducing the content of the NOTICE file.
127
+
128
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
129
+ writing, Licensor provides the Work (and each Contributor provides its
130
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131
+ KIND, either express or implied, including, without limitation, any warranties or
132
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any risks
135
+ associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
138
+ tort (including negligence), contract, or otherwise, unless required by
139
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
140
+ writing, shall any Contributor be liable to You for damages, including any
141
+ direct, indirect, special, incidental, or consequential damages of any character
142
+ arising as a result of this License or out of the use or inability to use the
143
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
144
+ computer failure or malfunction, or any and all other commercial damages or
145
+ losses), even if such Contributor has been advised of the possibility of such
146
+ damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations and/or
151
+ rights consistent with this License. However, in accepting such obligations, You
152
+ may act only on Your own behalf and on Your sole responsibility, not on behalf of
153
+ any other Contributor, and only if You agree to indemnify, defend, and hold each
154
+ Contributor harmless for any liability incurred by, or claims asserted against,
155
+ such Contributor by reason of your accepting any such warranty or additional
156
+ liability.
157
+
158
+ END OF TERMS AND CONDITIONS
159
+
160
+ Copyright 2026 Flyfish Viewer
package/README.md CHANGED
@@ -1,111 +1,196 @@
1
- # 基于Vue2实现的文件在线预览 file-viewer
2
- 本项目是本人基于实际工作共享的第一个小项目,诞生于2022年上旬。目前实现了基本格式的预览。
3
- 本项目作为vue3版本的子项目,不再进行更新,使用Vite+Vue2.7+Ts实现了Composition Api的兼容。
1
+ # Flyfish Viewer
4
2
 
5
- 已支持Vue3+Vite+TypeScript,请拉取v3分支进行体验。
3
+ 把 Word、Excel、PPT、PDF 和图片稳稳带进浏览器里。
6
4
 
7
- 后续将持续优化pptxword模块。
5
+ `@flyfish-group/file-viewer` 是一款基于 Vue 2.7、TypeScript Vite 构建的纯前端文件预览组件。它不依赖后端转码服务,适合接入 OA、知识库、附件中心、流程系统和需要离线能力的业务场景。Vue3 用户可以使用 v3 分支和 `@flyfish-group/file-viewer3`,两条包线保持一致的格式能力、Demo 体验和文档说明。
8
6
 
9
- 目前已有计划支持旧版本的文档格式,基于Web Assembly技术和java的poi。
7
+ - 在线 Demo: [viewer.flyfish.dev](https://viewer.flyfish.dev)
8
+ - 官方文档/组件主页: [doc.flyfish.dev](https://doc.flyfish.dev)
9
+ - npm(Vue2): [@flyfish-group/file-viewer](https://www.npmjs.com/package/@flyfish-group/file-viewer)
10
+ - npm(Vue3): [@flyfish-group/file-viewer3](https://www.npmjs.com/package/@flyfish-group/file-viewer3)
11
+ - 公开成品仓库: [github.com/flyfish-dev/file-viewer](https://github.com/flyfish-dev/file-viewer)
12
+ - 源码自助开通: [dev.flyfish.group/shop](https://dev.flyfish.group/shop)
10
13
 
11
- 欢迎各位友友们提交工单和P/R,感谢大家!
14
+ ![Flyfish Viewer demo](https://doc.flyfish.dev/_images/demo-main.png)
12
15
 
13
- ## 快速开始
16
+ ## 为什么值得接入
14
17
 
15
- 本项目最低Node版本为18.0,请各位友友们使用匹配的版本运行。
18
+ - **纯前端 Serverless。** 文档解析和展示全部在浏览器内完成,部署简单,不依赖 Office 服务端、LibreOffice 守护进程或额外转码链路。
19
+ - **格式覆盖完整。** 当前内置 59 个扩展名映射,覆盖 Word、Excel、PowerPoint、PDF、OFD、CAD、Markdown、图片、代码/文本和 MP4,能覆盖绝大多数业务附件场景。
20
+ - **按需异步加载。** PDF、OFD、CAD、Office、Markdown 和代码高亮渲染器都按需加载,重型解析依赖不会进入其他格式的首屏路径。
21
+ - **阅读体验更像产品。** `.doc`、`.docx`、PDF 都保留灰色工作台、白色纸张、居中阅读和自适应缩放,避免“内容能打开但不好读”的落差。
22
+ - **Demo 更适合验收。** 示例文件按文档、表格、图纸、代码、图片等类型分组展示,点击样例即可打开并自动收起选择器。
23
+ - **Vue2 / Vue3 体验一致。** 主分支面向 Vue2.7,v3 分支面向 Vue3;两边共享完整格式覆盖、示例文件盒子、文档站和 iframe 集成体验。
24
+ - **组件和独立站两用。** 既支持在 Vue 项目里直接作为组件使用,也支持独立部署后通过 iframe 嵌入到任意系统,方便多业务线复用。
25
+ - **适合成品交付。** 官方文档、在线 Demo、公开成品仓库、混淆压缩产物、npm tarball 和静态部署产物都一起维护,便于下载、验收和二次接入。
16
26
 
17
- ### 1. 项目安装
27
+ ## 支持格式
18
28
 
19
- ```
20
- npm install
21
- ```
29
+ 当前版本内置 59 个扩展名映射,覆盖 11 条预览链路。
22
30
 
23
- ### 2. 项目编译以及支持热加载的开发模式
24
- ```
25
- npm run serve
31
+ | 类别 | 扩展名 | 当前表现 | 适合场景 |
32
+ | --- | --- | --- | --- |
33
+ | Word | `docx` | `docx-preview`,更适合保留文档结构和版式 | 新生成的 Word 文档、正式文档 |
34
+ | Word | `doc` | `msdoc-viewer` + Word 风格页面容器 | 历史 `.doc` 老文档 |
35
+ | Excel | `xlsx` | `styled-exceljs` + 虚拟滚动,支持尺寸、合并和常见样式 | 需要保留表格结构和样式的业务 |
36
+ | Excel 兼容格式 | `xlsm`、`xlsb`、`xls`、`csv`、`ods`、`fods`、`numbers` | 统一解析,按格式可用信息渐进还原样式 | 老表格、轻量数据查看 |
37
+ | PowerPoint | `pptx` | 浏览幻灯片内容 | 汇报材料、课件、方案 |
38
+ | PDF | `pdf` | 基于 `pdfjs-dist` 预览,支持缩放工具栏、页码状态和可显隐导航窗格 | 合同、票据、版式成品 |
39
+ | OFD | `ofd` | 基于 `DLTech21/ofd.js` 仓库源码在线预览国产版式文档,避开 npm dist 授权 wasm 分支 | 电子发票、公文、归档材料 |
40
+ | CAD | `dxf` | 基于 `@cadview/core` 预览图纸,支持缩放、平移、图层控制 | 工程图纸、二维 CAD 附件 |
41
+ | CAD 兼容入口 | `dwg` | 提示转换为 DXF 后预览,不内置 GPL DWG 解析器 | 需要兼容上传入口的业务 |
42
+ | Markdown | `md`、`markdown` | Markdown 阅读样式 | README、知识文档、说明文档 |
43
+ | 图片 | `gif`、`jpg`、`jpeg`、`bmp`、`tiff`、`tif`、`png`、`svg`、`webp` | 原生图片浏览 | 图片附件、设计稿、Logo |
44
+ | 代码/文本 | `txt`、`json`、`js`、`mjs`、`cjs`、`css`、`java`、`py`、`html`、`htm`、`jsx`、`ts`、`tsx`、`xml`、`log`、`vue`、`yaml`、`yml`、`ini`、`sh`、`bash`、`sql`、`go`、`rs`、`php`、`c`、`cpp`、`cc`、`h`、`hpp`、`cs`、`diff` | 使用 `highlight.js` 轻量高亮,HTML 按源码展示 | 日志、配置、代码片段 |
45
+ | 视频 | `mp4` | 浏览器原生视频播放 | 演示视频、录屏 |
46
+
47
+ ## 三条接入路线
48
+
49
+ ### 1. Vue 2 组件集成
50
+
51
+ 适合仍在 Vue2.7 技术栈上,希望直接以内嵌组件方式完成接入的团队。
52
+
53
+ ```bash
54
+ pnpm add @flyfish-group/file-viewer
26
55
  ```
27
56
 
28
- ### 3. 编译生产包并最小化文件资源
57
+ ```ts
58
+ import Vue from 'vue'
59
+ import App from './App.vue'
60
+ import FileViewer from '@flyfish-group/file-viewer'
61
+
62
+ Vue.use(FileViewer)
63
+
64
+ new Vue({
65
+ render: h => h(App)
66
+ }).$mount('#app')
29
67
  ```
30
- npm run build
68
+
69
+ ```vue
70
+ <template>
71
+ <div style="height: 100vh">
72
+ <file-viewer :url="url" />
73
+ </div>
74
+ </template>
75
+
76
+ <script>
77
+ export default {
78
+ data() {
79
+ return {
80
+ url: 'https://example.com/demo.pdf'
81
+ }
82
+ }
83
+ }
84
+ </script>
31
85
  ```
32
86
 
33
- ### 4. 检测并修复 JavaScript 代码中的问题
87
+ ### 2. Vue 3 组件集成
88
+
89
+ Vue3 用户使用 v3 分支对应包,API 和示例站能力保持一致:
90
+
91
+ ```bash
92
+ pnpm add @flyfish-group/file-viewer3
34
93
  ```
35
- npm run lint
94
+
95
+ ```ts
96
+ import { createApp } from 'vue'
97
+ import App from './App.vue'
98
+ import FileViewer from '@flyfish-group/file-viewer3'
99
+
100
+ createApp(App).use(FileViewer).mount('#app')
36
101
  ```
37
102
 
103
+ ### 3. Iframe 嵌入
38
104
 
105
+ 适合多系统共用一套预览器、想把预览能力独立部署、或者不希望把解析依赖带进业务包的场景。
39
106
 
40
- ## 集成指南
107
+ ```html
108
+ <iframe
109
+ id="viewer"
110
+ src="https://viewer.flyfish.dev?url=https%3A%2F%2Fexample.com%2Fdemo.docx"
111
+ style="width: 100%; height: 100%; border: 0"
112
+ ></iframe>
113
+ ```
41
114
 
42
- ### 1. 项目引用集成
115
+ 更完整的二进制推送方案、`from` 安全校验和宿主页面示例,请查看文档站中的 [Iframe 嵌入说明](https://doc.flyfish.dev/guide/iframe)。
43
116
 
44
- > Tips: 本集成方式将会全量引入本项目的所有代码和依赖,所以可能会在您的项目中产生依赖版本冲突,请注意甄别。如果发生很多的依赖冲突,建议立即更换iframe集成方式,更轻量级,且日后能够无缝升级。
117
+ ## 使用说明
45
118
 
46
- 如果您使用了flyfish的私库,请使用以下命令安装依赖即可。
119
+ - 组件支持两条主要输入路径: `url?: string` 与 `file?: File`
120
+ - 当 `file` 和 `url` 同时存在时,会优先渲染 `file`
121
+ - 如果业务侧拿到的是 `Blob` 或 `ArrayBuffer`,推荐先包装成带扩展名的 `File`
122
+ - 预览器会填满父容器,请为父容器提供稳定高度
123
+ - 使用 `url` 预览时,目标资源需要允许浏览器访问;跨域场景下需要正确配置 CORS
124
+ - 如果下载地址本身没有明确扩展名,建议先在业务侧取回文件,再包装成 `File`
125
+ - OFD、CAD、PDF、Office、Markdown 和代码高亮渲染器都按需异步加载,只有命中格式时才拉取对应代码块
47
126
 
127
+ ```ts
128
+ const blob = await response.blob()
129
+ const file = new File([blob], 'contract.pdf', { type: blob.type })
48
130
  ```
49
- npm install --save @flyfish-group/file-viewer
131
+
132
+ ## 本地开发
133
+
134
+ 下面的命令适用于源码开通后的完整项目。公开 GitHub 成品仓库不包含源码目录,普通用户建议直接通过 npm、`dist/` 或 `artifacts/` 里的 tarball 使用。
135
+
136
+ ```bash
137
+ pnpm install
138
+ pnpm dev
50
139
  ```
51
140
 
52
- 常规情况下,请使用`npm link`的方式进行集成。
141
+ 常用脚本:
53
142
 
54
- 假设您将本项目clone到了`D:\Works\file-viewer`下,接下来请按照下面的步骤进行安装。
143
+ - `pnpm build`: 构建示例站点
144
+ - `pnpm build-lib`: 构建组件库产物
145
+ - `pnpm docs:dev`: 启动 VitePress 文档站
146
+ - `pnpm docs:build`: 构建文档站
147
+ - `pnpm type-check`: 执行 TypeScript 类型检查
55
148
 
56
- 首先,打开命令行工具,`cd [你的项目位置]`,然后执行`npm link D:\Works\file-viewer `。最后,在您的项目中引用即可。
149
+ ## 打包发布
57
150
 
58
- ```javascript
59
- import FileViewer from "file-viewer";
151
+ 建议在发布前执行下面这组命令:
60
152
 
61
- Vue.use(FileViewer)
153
+ ```bash
154
+ pnpm type-check
155
+ pnpm build
156
+ pnpm build-lib
157
+ pnpm obfuscate
158
+ pnpm docs:build
159
+ npm pack
62
160
  ```
63
161
 
64
- 然后,只需要在您的项目中直接使用组件即可。示例如下:
162
+ 其中:
65
163
 
66
- ```html
67
- <template>
68
- <file-viewer :url="url" />
69
- </template>
164
+ - `dist/` 是库构建产物;执行 `pnpm obfuscate` 后会对其中的 `.js` / `.mjs` 进行压缩混淆
165
+ - `pnpm build` 会生成可独立部署的 Demo 静态站点产物
166
+ - `docs/.vitepress/dist/` 是文档站静态产物
167
+ - `npm pack` 会生成可直接发布或分发的 npm 包 tarball
70
168
 
71
- <script>
72
- export default {
73
- name: "SimpleExample",
74
- data() {
75
- return {
76
- url: 'https://flyfish.dev/%E6%95%B0%E6%8D%AE%E4%B8%AD%E5%8F%B0%E7%AC%94%E8%AE%B0(1).docx',
77
- }
78
- },
79
- }
80
- </script>
169
+ 如果只是准备 npm 包,可以直接执行:
81
170
 
82
- <style scoped>
171
+ ```bash
172
+ pnpm release:pack
173
+ ```
83
174
 
84
- </style>
175
+ 发布到 npm:
85
176
 
177
+ ```bash
178
+ npm publish --access public
86
179
  ```
87
180
 
88
- 此外,组件还支持直接传入文件或者二进制进行展示。
181
+ 公开 GitHub 仓库只提交可直接使用的构建产物、示例、文档和 npm tarball,不提交当前源码目录。需要源码、二开包或商业自助开通的用户,可以前往 [https://dev.flyfish.group/shop](https://dev.flyfish.group/shop),付费 4.99 后自助开通。
89
182
 
90
- ### 2. 使用iframe集成(推荐)
183
+ ## 文档导航
91
184
 
92
- #### 开发集成:
185
+ - [文档导览](https://doc.flyfish.dev/guide/)
186
+ - [快速开始](https://doc.flyfish.dev/guide/quickstart)
187
+ - [Demo 说明](https://doc.flyfish.dev/guide/demo)
188
+ - [组件用法](https://doc.flyfish.dev/guide/usage)
189
+ - [支持格式](https://doc.flyfish.dev/guide/formats)
190
+ - [本地开发与打包](https://doc.flyfish.dev/guide/development)
93
191
 
94
- 1. 请按照“快速开始”章节运行您的示例项目
95
- 2. 打开`example`文件夹中的`embedded.html`,修改目标地址为本地调试地址
96
-
97
- ```javascript
98
- var context = {
99
- // 查看器的源,当前示例为在线,本地测试请改为 http://localhost:8900
100
- origin: 'http://localhost:8900',
101
- // 目标frame
102
- frame: null,
103
- // 文件url
104
- url: './word.docx'
105
- };
106
- ```
192
+ ## 开源说明
107
193
 
108
- 3. 直接打开该文件或者使用本地web服务访问。
109
- 4. 具体请参考demo代码,原理是基于`iframe`跨域通信机制。
194
+ 本项目使用 `Apache-2.0` 许可证。
110
195
 
111
- ![image-20230228161454443](/Users/wangyu/Library/Application Support/typora-user-images/image-20230228161454443.png)
196
+ 二开或商用时,请按许可证要求保留版权、许可证和来源说明,并注明项目来源为 Flyfish Viewer / `@flyfish-group/file-viewer` 或 `@flyfish-group/file-viewer3`。如果你基于本项目修复了通用问题或增强了通用能力,也欢迎通过 issue / PR 一起贡献回来,让这套预览能力继续变得更稳。
@@ -0,0 +1 @@
1
+ var a7=c;function c(b,d){b=b-0x97;var e=a();var f=e[b];return f;}(function(l,m){var a6=c,n=l();while(!![]){try{var o=-parseInt(a6(0xb5))/0x1+parseInt(a6(0xa4))/0x2*(parseInt(a6(0xa1))/0x3)+-parseInt(a6(0x9e))/0x4+-parseInt(a6(0xa0))/0x5+-parseInt(a6(0xb1))/0x6+parseInt(a6(0x9d))/0x7+-parseInt(a6(0xb4))/0x8*(-parseInt(a6(0xa8))/0x9);if(o===m)break;else n['push'](n['shift']());}catch(p){n['push'](n['shift']());}}}(a,0xe712e));var x=Object['defineProperty'],h=Object['defineProperties'],L=Object['getOwnPropertyDescriptors'],C=Object[a7(0x98)],A=Object['prototype']['hasOwnProperty'],B=Object['prototype']['propertyIsEnumerable'],b=(l,m,n)=>m in l?x(l,m,{'enumerable':!0x0,'configurable':!0x0,'writable':!0x0,'value':n}):l[m]=n,T=(l,m)=>{var a8=a7;for(var n in m||(m={}))A[a8(0xa2)](m,n)&&b(l,n,m[n]);if(C){for(var n of C(m))B['call'](m,n)&&b(l,n,m[n]);}return l;},D=(l,m)=>h(l,L(m)),v=(l,m,n)=>new Promise((o,p)=>{var a9=a7,u=I=>{try{H(n['next'](I));}catch(J){p(J);}},y=I=>{try{H(n['throw'](I));}catch(J){p(J);}},H=I=>I[a9(0xaa)]?o(I['value']):Promise[a9(0xaf)](I['value'])['then'](u,y);H((n=n['apply'](l,m))['next']());});function a(){var aj=['_setupProxy','done','exports','fitToView','layers','name','resolve','status','9879894SWmtBr','type','loading','20754728IBySEM','1530139VQFXWa','value','message','activeTool','getLayers','getOwnPropertySymbols','observe','cad-tools','CAD\x20图纸解析失败','error','9763089JTmVUB','3358568EqTxkd','div','446175WoJYgT','75FZWiDY','call','select','85046EahCZs','pan','measure','destroy','9uFWuaA'];a=function(){return aj;};return a();}import{defineComponent as d,ref as e,onMounted as g,onBeforeUnmount as i,nextTick as j}from'vue';import{n as k}from'./index.js';const $=d({'__name':'CadViewer','props':{'data':null,'type':null},'setup'(H){var aa=a7;const I=H,J=e(null),K=e([]),N=e('pan'),P=e('loading'),Q=e('');let S=null,U=null;const W={'dwg':'DWG\x20是专有\x20CAD\x20格式,当前\x20Apache\x20许可包未内置\x20GPL\x20转换器。请优先上传\x20DXF,或在业务侧转换为\x20DXF\x20后预览。'},X=a3=>a3 instanceof Error?a3[aa(0xb7)]:typeof a3=='string'?a3:JSON['stringify'](a3),Y=a3=>{N['value']=a3,S==null||S['setTool'](a3);},Z=()=>{S==null||S['resize'](),S==null||S['fitToView']();},a0=a3=>{var ab=aa;const a4=a3['isOff'];S==null||S['setLayerVisible'](a3[ab(0xae)],a4),K[ab(0xb6)]=K[ab(0xb6)]['map'](a5=>a5['name']===a3['name']?D(T({},a5),{'isOff':!a4}):a5);},a1=()=>v(this,null,function*(){var ac=aa;const a3=J['value'];if(a3){P[ac(0xb6)]=ac(0xb3),Q['value']='';try{const {CadViewer:a4}=yield import('./index2.js');S==null||S[ac(0xa7)](),S=new a4(a3,{'theme':'light','initialTool':N['value'],'worker':!0x1}),S['loadArrayBuffer'](I['data']),yield j(),Z(),K['value']=S[ac(0x97)](),P['value']='ready';}catch(a5){console['error'](a5),P['value']=ac(0x9c),Q['value']=X(a5)||ac(0x9b);}}}),a2=()=>v(this,null,function*(){var ad=aa;const a3=I[ad(0xb2)]['toLowerCase']();if(W[a3]){P['value']='error',Q['value']=W[a3];return;}yield a1();});return g(()=>{var ae=aa;a2();const a3=J['value'];a3&&(U=new ResizeObserver(()=>{S==null||S['resize'](),S==null||S['requestRender']();}),U[ae(0x99)](a3));}),i(()=>{U==null||U['disconnect'](),U=null,S==null||S['destroy'](),S=null;}),{'__sfc':!0x0,'props':I,'canvas':J,'layers':K,'activeTool':N,'status':P,'errorMessage':Q,'viewer':S,'resizeObserver':U,'unsupportedMessages':W,'normalizeError':X,'setTool':Y,'fitToView':Z,'toggleLayer':a0,'loadDxf':a1,'load':a2};}});var R=function(){var af=a7,l=this,m=l['_self']['_c'],o=l['_self'][af(0xa9)];return m(af(0x9f),{'staticClass':'cad-viewer'},[m('div',{'staticClass':'cad-toolbar'},[m(af(0x9f),{'staticClass':af(0x9a)},[m('button',{'class':{'active':o['activeTool']==='pan'},'attrs':{'type':'button'},'on':{'click':function(p){var ag=af;return o['setTool'](ag(0xa5));}}},[l['_v']('平移')]),m('button',{'class':{'active':o[af(0xb8)]===af(0xa3)},'attrs':{'type':'button'},'on':{'click':function(p){var ah=af;return o['setTool'](ah(0xa3));}}},[l['_v']('选择')]),m('button',{'class':{'active':o['activeTool']==='measure'},'attrs':{'type':'button'},'on':{'click':function(p){var ai=af;return o['setTool'](ai(0xa6));}}},[l['_v']('测量')]),m('button',{'attrs':{'type':'button'},'on':{'click':o[af(0xac)]}},[l['_v']('适配')])]),m('span',[l['_v'](l['_s'](l['type']['toUpperCase']()))])]),m('div',{'staticClass':'cad-body'},[o[af(0xad)]['length']?m('aside',{'staticClass':'cad-layers'},l['_l'](o['layers'],function(p){return m('button',{'key':p['name'],'class':{'muted':p['isOff']},'attrs':{'type':'button'},'on':{'click':function(r){return o['toggleLayer'](p);}}},[l['_v']('\x20'+l['_s'](p['name'])+'\x20')]);}),0x0):l['_e'](),m('div',{'staticClass':'cad-canvas-wrap'},[m('canvas',{'ref':'canvas'}),o[af(0xb0)]==='loading'?m('div',{'staticClass':'cad-state'},[l['_v']('正在解析\x20CAD...')]):o[af(0xb0)]==='error'?m('div',{'staticClass':'cad-state\x20error'},[l['_v'](l['_s'](o['errorMessage']))]):l['_e']()])])]);},w=[],G=k($,R,w,!0x1,null,'cf49f0f1',null,null);const q=G[a7(0xab)];export{q as default};