@flyfish-group/file-viewer-web 2.0.10 → 2.0.11
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.en.md +30 -27
- package/README.md +30 -30
- package/dist/flyfish-file-viewer-web.iife.js +268 -268
- package/dist/global.d.ts +5 -2
- package/dist/global.js +6 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/viewer/flyfish-viewer-manifest.json +1 -1
- package/viewer/vendor/docx/docx.worker.js +1 -1
package/README.en.md
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
# @flyfish-group/file-viewer-web
|
|
2
2
|
|
|
3
|
-
Pure web file preview package. This package is the historical alias of `@file-viewer/web` and
|
|
3
|
+
Pure web file preview package. This package is the historical alias of `@file-viewer/web` and ships the same `<flyfish-file-viewer>` Web Component, imperative `mountViewer` controller, IIFE global bundle, and asset-copy CLI.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @flyfish-group/file-viewer-web
|
|
6
|
+
npm install @flyfish-group/file-viewer-web
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<flyfish-file-viewer
|
|
11
|
+
id="viewer"
|
|
12
|
+
src="/files/demo.pdf"
|
|
13
|
+
theme="light"
|
|
14
|
+
toolbar-position="bottom-right"
|
|
15
|
+
style="display:block;height:720px"
|
|
16
|
+
></flyfish-file-viewer>
|
|
7
17
|
```
|
|
8
18
|
|
|
9
19
|
```ts
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
const controller = mountViewer(document.getElementById('viewer')!, {
|
|
13
|
-
url: '/files/demo.pdf',
|
|
14
|
-
options: {
|
|
15
|
-
theme: 'light',
|
|
16
|
-
toolbar: { position: 'bottom-right' },
|
|
17
|
-
search: { maxMatches: 1000 }
|
|
18
|
-
},
|
|
19
|
-
onEvent(event) {
|
|
20
|
-
console.log(event.type, event.event, event.payload)
|
|
21
|
-
}
|
|
22
|
-
})
|
|
20
|
+
import { defineFileViewerElement } from '@flyfish-group/file-viewer-web'
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
defineFileViewerElement()
|
|
23
|
+
|
|
24
|
+
const viewer = document.getElementById('viewer')
|
|
25
|
+
viewer.addEventListener('viewer-event', event => {
|
|
26
|
+
console.log(event.detail.type, event.detail.payload)
|
|
27
|
+
})
|
|
28
|
+
viewer.reload()
|
|
25
29
|
```
|
|
26
30
|
|
|
31
|
+
Use `mountViewer(container, options)` when you need a fully imperative controller.
|
|
32
|
+
|
|
27
33
|
For authenticated files, download the file in your host application first and pass a `Blob` plus a filename:
|
|
28
34
|
|
|
29
35
|
```ts
|
|
30
36
|
const blob = await fetch('/api/files/contract', { credentials: 'include' }).then(res => res.blob())
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
38
|
+
const viewer = document.querySelector('flyfish-file-viewer')
|
|
39
|
+
viewer.file = blob
|
|
40
|
+
viewer.name = 'contract.pdf'
|
|
36
41
|
```
|
|
37
42
|
|
|
38
43
|
## Script Tag Usage
|
|
@@ -40,14 +45,12 @@ mountViewer(document.getElementById('viewer')!, {
|
|
|
40
45
|
No-build projects can self-host the IIFE bundle. It exposes `window.FlyfishFileViewerWeb`:
|
|
41
46
|
|
|
42
47
|
```html
|
|
43
|
-
<div id="viewer" style="height: 720px"></div>
|
|
44
48
|
<script src="/vendor/file-viewer-web/flyfish-file-viewer-web.iife.js"></script>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</script>
|
|
49
|
+
<flyfish-file-viewer
|
|
50
|
+
src="/files/demo.docx"
|
|
51
|
+
theme="light"
|
|
52
|
+
style="display:block;height:720px"
|
|
53
|
+
></flyfish-file-viewer>
|
|
51
54
|
```
|
|
52
55
|
|
|
53
56
|
Browsers cannot resolve a bare package name such as `@flyfish-group/file-viewer-web` without a build tool. Use a static URL, the IIFE global bundle, or an import map. Workers, WASM files, and examples can be self-hosted with:
|
package/README.md
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
# @flyfish-group/file-viewer-web
|
|
2
2
|
|
|
3
|
-
纯 Web 文件预览组件。这个包是 `@file-viewer/web`
|
|
3
|
+
纯 Web 文件预览组件。这个包是 `@file-viewer/web` 的历史包名同步版本,提供同样的 `<flyfish-file-viewer>` 原生 Web Component、`mountViewer` 命令式 controller、IIFE 全局脚本和资源复制 CLI。
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @flyfish-group/file-viewer-web
|
|
6
|
+
npm install @flyfish-group/file-viewer-web
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<flyfish-file-viewer
|
|
11
|
+
id="viewer"
|
|
12
|
+
src="https://example.com/demo.pdf"
|
|
13
|
+
theme="light"
|
|
14
|
+
toolbar-position="bottom-right"
|
|
15
|
+
style="display:block;height:720px"
|
|
16
|
+
></flyfish-file-viewer>
|
|
7
17
|
```
|
|
8
18
|
|
|
9
19
|
```ts
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
const controller = mountViewer(document.getElementById('viewer')!, {
|
|
13
|
-
url: 'https://example.com/demo.pdf',
|
|
14
|
-
options: {
|
|
15
|
-
theme: 'light',
|
|
16
|
-
toolbar: { position: 'bottom-right' },
|
|
17
|
-
search: { maxMatches: 1000 },
|
|
18
|
-
pdf: { toolbar: true },
|
|
19
|
-
watermark: { text: '内部预览', opacity: 0.14 },
|
|
20
|
-
archive: { cache: true }
|
|
21
|
-
},
|
|
22
|
-
onEvent(event) {
|
|
23
|
-
console.log(event.type, event.event, event.payload)
|
|
24
|
-
}
|
|
25
|
-
})
|
|
20
|
+
import { defineFileViewerElement } from '@flyfish-group/file-viewer-web'
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
defineFileViewerElement()
|
|
23
|
+
|
|
24
|
+
const viewer = document.getElementById('viewer')
|
|
25
|
+
viewer.addEventListener('viewer-event', event => {
|
|
26
|
+
console.log(event.detail.type, event.detail.payload)
|
|
27
|
+
})
|
|
28
|
+
viewer.reload()
|
|
28
29
|
```
|
|
29
30
|
|
|
31
|
+
需要完全命令式控制时,仍可使用 `mountViewer(container, options)` 返回完整 controller。
|
|
32
|
+
|
|
30
33
|
鉴权文件可以由宿主系统先下载成 `Blob`,再通过 `file` 和 `name` 交给预览器:
|
|
31
34
|
|
|
32
35
|
```ts
|
|
33
36
|
const blob = await fetch('/api/files/contract', { credentials: 'include' }).then(res => res.blob())
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
38
|
+
const viewer = document.querySelector('flyfish-file-viewer')
|
|
39
|
+
viewer.file = blob
|
|
40
|
+
viewer.name = 'contract.pdf'
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
## Script 标签接入
|
|
@@ -43,14 +45,12 @@ mountViewer(document.getElementById('viewer')!, {
|
|
|
43
45
|
无构建工具项目可以自托管 IIFE 包,它会暴露 `window.FlyfishFileViewerWeb`:
|
|
44
46
|
|
|
45
47
|
```html
|
|
46
|
-
<div id="viewer" style="height: 720px"></div>
|
|
47
48
|
<script src="/vendor/file-viewer-web/flyfish-file-viewer-web.iife.js"></script>
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</script>
|
|
49
|
+
<flyfish-file-viewer
|
|
50
|
+
src="/files/demo.docx"
|
|
51
|
+
theme="light"
|
|
52
|
+
style="display:block;height:720px"
|
|
53
|
+
></flyfish-file-viewer>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
浏览器不能直接解析 `@flyfish-group/file-viewer-web` 这种裸包名;没有构建工具时请使用静态 URL、IIFE 全局包,或配置 import map。Worker、WASM 和示例资源可以通过复制命令自托管:
|