@file-viewer/web 2.0.10 → 2.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/README.en.md +80 -29
- package/README.md +80 -29
- package/dist/element.d.ts +91 -0
- package/dist/element.js +466 -0
- package/dist/flyfish-file-viewer-web.iife.js +9 -7995
- package/dist/global.d.ts +5 -2
- package/dist/global.js +6 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/package.json +12 -3
- package/viewer/flyfish-viewer-assets.json +22 -2
- package/viewer/flyfish-viewer-manifest.json +1 -1
- package/viewer/vendor/docx/docx.worker.js +1 -1
- package/viewer/vendor/xlsx/sheet.worker.js +14 -11
- package/viewer/wasm/typst/fonts/DejaVuSansMono-Bold.ttf +0 -0
- package/viewer/wasm/typst/fonts/DejaVuSansMono-BoldOblique.ttf +0 -0
- package/viewer/wasm/typst/fonts/DejaVuSansMono-Oblique.ttf +0 -0
- package/viewer/wasm/typst/fonts/DejaVuSansMono.ttf +0 -0
- package/viewer/wasm/typst/fonts/LibertinusSerif-Bold.otf +0 -0
- package/viewer/wasm/typst/fonts/LibertinusSerif-BoldItalic.otf +0 -0
- package/viewer/wasm/typst/fonts/LibertinusSerif-Italic.otf +0 -0
- package/viewer/wasm/typst/fonts/LibertinusSerif-Regular.otf +0 -0
- package/viewer/wasm/typst/fonts/LibertinusSerif-Semibold.otf +0 -0
- package/viewer/wasm/typst/fonts/LibertinusSerif-SemiboldItalic.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCM10-Bold.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCM10-BoldItalic.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCM10-Italic.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCM10-Regular.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCMMath-Bold.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCMMath-Book.otf +0 -0
- package/viewer/wasm/typst/fonts/NewCMMath-Regular.otf +0 -0
- package/viewer/wasm/typst/fonts/README.md +7 -0
package/README.en.md
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
# @file-viewer/web
|
|
2
2
|
|
|
3
|
-
The standard pure web native component package for Flyfish File Viewer. It
|
|
3
|
+
The standard pure web native component package for Flyfish File Viewer. It ships the `<flyfish-file-viewer>` Web Component, imperative `mountViewer` controller, IIFE global bundle, and asset-copy CLI for legacy admin pages, script-tag usage, micro-frontends, and framework-free systems.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install @file-viewer/web
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
```html
|
|
10
|
+
<flyfish-file-viewer
|
|
11
|
+
id="viewer"
|
|
12
|
+
src="/example/demo.pdf"
|
|
13
|
+
theme="light"
|
|
14
|
+
toolbar-position="bottom-right"
|
|
15
|
+
style="display:block;height:720px"
|
|
16
|
+
></flyfish-file-viewer>
|
|
17
|
+
```
|
|
18
|
+
|
|
9
19
|
```ts
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
20
|
+
import { defineFileViewerElement } from '@file-viewer/web'
|
|
21
|
+
|
|
22
|
+
defineFileViewerElement()
|
|
23
|
+
|
|
24
|
+
const viewer = document.getElementById('viewer')
|
|
25
|
+
viewer.addEventListener('viewer-event', event => {
|
|
26
|
+
console.log(event.detail.type)
|
|
18
27
|
})
|
|
28
|
+
viewer.zoomIn()
|
|
19
29
|
```
|
|
20
30
|
|
|
31
|
+
Use `mountViewer(container, options)` when you need a fully imperative controller.
|
|
32
|
+
|
|
21
33
|
Use the asset copy command when you need to self-host workers, WASM files, and static examples:
|
|
22
34
|
|
|
23
35
|
```bash
|
|
@@ -28,39 +40,38 @@ No-build or legacy admin pages can copy `dist/flyfish-file-viewer-web.iife.js` a
|
|
|
28
40
|
|
|
29
41
|
```html
|
|
30
42
|
<script src="/vendor/file-viewer-web/flyfish-file-viewer-web.iife.js"></script>
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</script>
|
|
43
|
+
<flyfish-file-viewer
|
|
44
|
+
src="/files/demo.pdf"
|
|
45
|
+
theme="light"
|
|
46
|
+
style="display:block;height:720px"
|
|
47
|
+
></flyfish-file-viewer>
|
|
37
48
|
```
|
|
38
49
|
|
|
39
50
|
The historical package `@flyfish-group/file-viewer-web` remains supported for compatibility. New integrations should prefer the standard package `@file-viewer/web`.
|
|
40
51
|
|
|
41
52
|
## Capabilities
|
|
42
53
|
|
|
43
|
-
`@file-viewer/web` shares the same
|
|
54
|
+
`@file-viewer/web` shares the same core contract and renderer/preset assembly model with the other standard component packages; full capability can be assembled with on-demand renderers or `@file-viewer/preset-all`, including PDF, Word, Excel, PowerPoint, OFD, CAD/DWG/DXF/DWF, EPUB/UMD, archives, email, Markdown, highlighted code, images, audio, video, 3D models, geospatial files, and structured data assets. See the complete format matrix and option reference at https://doc.file-viewer.app/guide/formats
|
|
44
55
|
|
|
45
56
|
<!-- FILE_VIEWER_GENERATED:START -->
|
|
46
57
|
## Ecosystem Matrix
|
|
47
58
|
|
|
48
|
-
Every standard component package shares `@file-viewer/core` as the only common foundation, and no framework component package depends on another framework implementation. Core owns format metadata, source loading,
|
|
59
|
+
Every standard component package shares `@file-viewer/core` as the only common foundation, and no framework component package depends on another framework implementation. Core owns format metadata, source loading, the renderer protocol, events, operation APIs, search, zoom, print, and export. Heavy PDF, Word, PPTX, CAD, Typst, and similar pipelines are assembled explicitly through renderer packages or presets; each framework package owns its local controller, component lifecycle, type exports, and ecosystem-specific interaction layer.
|
|
49
60
|
|
|
50
61
|
| Framework | Standard npm package | Entrypoints | GitHub | Gitee | Historical aliases |
|
|
51
62
|
| --- | --- | --- | --- | --- | --- |
|
|
63
|
+
| Vanilla JS / Pure Web | `@file-viewer/web` | ESM, type declarations, script tag IIFE, worker/WASM viewer assets, asset copy CLI | [file-viewer-web](https://github.com/flyfish-dev/file-viewer-web) | [file-viewer-web](https://gitee.com/flyfish-dev/file-viewer-web) | `@flyfish-group/file-viewer-web` |
|
|
52
64
|
| Vue 3 | `@file-viewer/vue3` | ESM, type declarations | [file-viewer-vue3](https://github.com/flyfish-dev/file-viewer-vue3) | [file-viewer-vue3](https://gitee.com/flyfish-dev/file-viewer-vue3) | `@flyfish-group/file-viewer3`, `file-viewer3` |
|
|
53
65
|
| Vue 2.7 | `@file-viewer/vue2.7` | ESM, type declarations | [file-viewer-vue2.7](https://github.com/flyfish-dev/file-viewer-vue2.7) | [file-viewer-vue2.7](https://gitee.com/flyfish-dev/file-viewer-vue2.7) | `@flyfish-group/file-viewer` |
|
|
54
66
|
| Vue 2.6 | `@file-viewer/vue2.6` | ESM, type declarations | [file-viewer-vue2.6](https://github.com/flyfish-dev/file-viewer-vue2.6) | [file-viewer-vue2.6](https://gitee.com/flyfish-dev/file-viewer-vue2.6) | none |
|
|
55
67
|
| React 18/19 | `@file-viewer/react` | ESM, type declarations | [file-viewer-react](https://github.com/flyfish-dev/file-viewer-react) | [file-viewer-react](https://gitee.com/flyfish-dev/file-viewer-react) | `@flyfish-group/file-viewer-react` |
|
|
56
68
|
| React 16.8/17 | `@file-viewer/react-legacy` | ESM, type declarations | [file-viewer-react-legacy](https://github.com/flyfish-dev/file-viewer-react-legacy) | [file-viewer-react-legacy](https://gitee.com/flyfish-dev/file-viewer-react-legacy) | none |
|
|
57
|
-
| Pure Web | `@file-viewer/web` | ESM, type declarations, script tag IIFE, worker/WASM viewer assets, asset copy CLI | [file-viewer-web](https://github.com/flyfish-dev/file-viewer-web) | [file-viewer-web](https://gitee.com/flyfish-dev/file-viewer-web) | `@flyfish-group/file-viewer-web` |
|
|
58
69
|
| jQuery | `@file-viewer/jquery` | ESM, type declarations | [file-viewer-jquery](https://github.com/flyfish-dev/file-viewer-jquery) | [file-viewer-jquery](https://gitee.com/flyfish-dev/file-viewer-jquery) | none |
|
|
59
70
|
| Svelte | `@file-viewer/svelte` | Svelte component, ESM, type declarations | [file-viewer-svelte](https://github.com/flyfish-dev/file-viewer-svelte) | [file-viewer-svelte](https://gitee.com/flyfish-dev/file-viewer-svelte) | none |
|
|
60
71
|
|
|
61
72
|
## Format Support Matrix
|
|
62
73
|
|
|
63
|
-
The shared
|
|
74
|
+
The shared format matrix currently covers 24 preview pipelines and 206 file extensions. Full capability is assembled through renderer packages or presets, while component packages only adapt their own ecosystem without nesting through another framework implementation.
|
|
64
75
|
|
|
65
76
|
| Preview pipeline | Category | Extensions | Capabilities | Loading |
|
|
66
77
|
| --- | --- | --- | --- | --- |
|
|
@@ -74,20 +85,60 @@ The shared core currently covers 23 preview pipelines and 194 file extensions. R
|
|
|
74
85
|
| Typst | document | `.typ`, `.typst` | download, print(adapter), HTML export(adapter), zoom(provider), search | lazy async |
|
|
75
86
|
| Archive | archive | `.zip`, `.zipx`, `.7z`, `.rar`, `.tar`, `.gz`, `.gzip`, `.tgz`, `.bz2`, `.bzip2`, `.tbz`, `.tbz2`, `.xz`, `.txz`, `.lzma`, `.zst`, `.tzst`, `.cab`, `.ar`, `.cpio`, `.iso`, `.xar`, `.lha`, `.lzh`, `.jar`, `.war`, `.ear`, `.apk`, `.cbz`, `.cbr` | download, search | lazy async |
|
|
76
87
|
| Email | email | `.eml`, `.msg`, `.mbox` | download, HTML export, search | lazy async |
|
|
77
|
-
| EDA | eda | `.olb`, `.dra` | download, print, HTML export, search | lazy async |
|
|
88
|
+
| EDA | eda | `.olb`, `.dra`, `.gds`, `.oas`, `.oasis` | download, print, HTML export, search | lazy async |
|
|
78
89
|
| CAD | cad | `.dxf`, `.dwg`, `.dwf`, `.dwfx`, `.xps` | download, print, HTML export, zoom(provider) | lazy async |
|
|
79
|
-
| 3D Model | model | `.glb`, `.gltf`, `.obj`, `.stl`, `.ply`, `.fbx`, `.dae`, `.3ds`, `.3mf`, `.amf`, `.usd`, `.usda`, `.usdc`, `.usdz`, `.kmz`, `.step`, `.stp`, `.iges`, `.igs`, `.ifc`, `.3dm`, `.pcd`, `.wrl`, `.vrml`, `.xyz`, `.vtk`, `.vtp` | download, zoom(provider) | lazy async |
|
|
90
|
+
| 3D Model | model | `.glb`, `.gltf`, `.obj`, `.stl`, `.ply`, `.fbx`, `.dae`, `.3ds`, `.3mf`, `.amf`, `.usd`, `.usda`, `.usdc`, `.usdz`, `.kmz`, `.step`, `.stp`, `.iges`, `.igs`, `.ifc`, `.3dm`, `.brep`, `.pcd`, `.wrl`, `.vrml`, `.xyz`, `.vtk`, `.vtp` | download, zoom(provider) | lazy async |
|
|
80
91
|
| Geospatial | geo | `.geojson`, `.kml`, `.gpx`, `.shp` | download, print, HTML export, zoom(provider), search | lazy async |
|
|
81
|
-
| Drawing | drawing | `.excalidraw`, `.drawio`, `.dio` | download, print, HTML export, zoom(provider), search | lazy async |
|
|
92
|
+
| Drawing | drawing | `.excalidraw`, `.drawio`, `.dio`, `.mermaid`, `.mmd`, `.plantuml`, `.puml` | download, print, HTML export, zoom(provider), search | lazy async |
|
|
93
|
+
| Mind Map | mindmap | `.xmind` | download, print, HTML export, zoom(provider), search | lazy async |
|
|
82
94
|
| EPUB | ebook | `.epub` | download, HTML export, search(provider) | lazy async |
|
|
83
95
|
| UMD | ebook | `.umd` | download, print, HTML export, zoom(provider), search | lazy async |
|
|
84
96
|
| Image | image | `.gif`, `.jpg`, `.jpeg`, `.bmp`, `.tiff`, `.tif`, `.png`, `.svg`, `.webp`, `.avif`, `.ico`, `.heic`, `.heif`, `.jxl` | download, print, HTML export, zoom(provider) | lazy async |
|
|
85
97
|
| Markdown | markdown | `.md`, `.markdown` | download, print, HTML export, search | lazy async |
|
|
86
|
-
| Code and Text | code | `.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`, `.jsonc`, `.json5`, `.ipynb`, `.toml`, `.proto`, `.hcl`, `.tex`, `.gv`, `.http`, `.react`, `.rb`, `.swift`, `.kt` | download, print, HTML export, search | lazy async |
|
|
98
|
+
| Code and Text | code | `.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`, `.patch`, `.bundle`, `.bdl`, `.jsonc`, `.json5`, `.ipynb`, `.toml`, `.proto`, `.hcl`, `.tex`, `.gv`, `.http`, `.react`, `.rb`, `.swift`, `.kt` | download, print, HTML export, search | lazy async |
|
|
87
99
|
| Video | media | `.mp4`, `.webm`, `.m3u8` | download | lazy async |
|
|
88
100
|
| Audio | media | `.mp3`, `.mpeg`, `.wav`, `.ogg`, `.oga`, `.opus`, `.m4a`, `.aac`, `.flac`, `.weba`, `.midi`, `.mid` | download | lazy async |
|
|
89
101
|
| Data Asset | asset | `.ttf`, `.otf`, `.woff`, `.woff2`, `.psd`, `.ai`, `.eps`, `.sqlite`, `.wasm`, `.parquet`, `.avro`, `.webarchive` | download, HTML export, search | lazy async |
|
|
90
102
|
|
|
103
|
+
## Engineering-Grade On-Demand Renderer Assembly
|
|
104
|
+
|
|
105
|
+
One component, one line of code, fast integration; renderer assembly is what controls install size and first-screen bundle weight. Prefer a product-shaped preset first: `@file-viewer/preset-lite`, `@file-viewer/preset-office`, `@file-viewer/preset-engineering`, or `@file-viewer/preset-all`. Install individual renderer packages only when you need the smallest possible custom cut. The Vite plugin generates `virtual:file-viewer-renderers`, and application code passes the same shared `options` everywhere.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm i @file-viewer/vue3 @file-viewer/core @file-viewer/vite-plugin @file-viewer/preset-office
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { fileViewerRenderers } from '@file-viewer/vite-plugin'
|
|
113
|
+
|
|
114
|
+
export default {
|
|
115
|
+
plugins: [
|
|
116
|
+
fileViewerRenderers({
|
|
117
|
+
preset: 'office',
|
|
118
|
+
scan: true,
|
|
119
|
+
copyAssets: true
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { configuredFileViewerRenderers } from 'virtual:file-viewer-renderers'
|
|
127
|
+
|
|
128
|
+
const options = {
|
|
129
|
+
builtinRenderers: 'none',
|
|
130
|
+
renderers: configuredFileViewerRenderers,
|
|
131
|
+
rendererMode: 'replace'
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- Vue, React, Svelte, jQuery, and Vanilla JavaScript / Pure Web all receive the same `options`; each package maps them to native props, hooks, actions, plugins, or `mountViewer(...)` parameters.
|
|
136
|
+
- `preset-lite` covers text, Markdown, code, images, audio, and video; `preset-office` covers PDF / Word / Excel / PowerPoint / OFD; `preset-engineering` covers CAD / 3D / drawing / XMind / Geo / Typst / EDA / Data.
|
|
137
|
+
- For the smallest custom bundle, skip presets, install individual renderers such as `@file-viewer/renderer-pdf` or `@file-viewer/renderer-word`, and let `formats` generate exact imports.
|
|
138
|
+
- `scan:true` detects `fileViewerFormats`, `data-file-viewer-formats`, and upload `accept` hints so development and production builds select matching renderers automatically.
|
|
139
|
+
- `copyAssets:true` copies PDF/CAD/Typst/Archive/Data workers, WASM, and vendor assets for offline and enterprise intranet deployment.
|
|
140
|
+
- If you want the complete official demo capability matrix, install `@file-viewer/preset-all` and pass `allRenderers` to `renderers`; this is ideal for demos and internal admin tools, but should not be every product default.
|
|
141
|
+
|
|
91
142
|
## Shared Options And Events
|
|
92
143
|
|
|
93
144
|
Every ecosystem package uses the same `ViewerMountOptions` and `FileViewerOptions` semantics, mapped to framework-native props, events, refs, actions, or plugin APIs.
|
|
@@ -101,20 +152,20 @@ Every ecosystem package uses the same `ViewerMountOptions` and `FileViewerOption
|
|
|
101
152
|
| `type` | Explicit extension or MIME hint that overrides automatic detection. |
|
|
102
153
|
| `size` | File size hint used in lifecycle context, loading states, and safety limits. |
|
|
103
154
|
| `options` | The shared `FileViewerOptions` surface. Every component package keeps the same semantics. |
|
|
104
|
-
| `onEvent` / `onStateChange` | Unified event and state subscriptions for imperative wrappers such as Pure Web, React, and Svelte. Vue maps the same events to native emits. |
|
|
155
|
+
| `onEvent` / `onStateChange` | Unified event and state subscriptions for imperative wrappers such as Vanilla JavaScript / Pure Web, React, and Svelte. Vue maps the same events to native emits. |
|
|
105
156
|
|
|
106
157
|
## Actual Component Props
|
|
107
158
|
|
|
108
|
-
The table below lists the real props, event channel, and customization entry for every standard package. If you need imperative mount fields such as `buffer`, `name`, `type`, or `size`, prefer
|
|
159
|
+
The table below lists the real props, event channel, and customization entry for every standard package. If you need imperative mount fields such as `buffer`, `name`, `type`, or `size`, prefer Vanilla JavaScript / Pure Web, React, Svelte, jQuery, or Vue 2. The Vue 3 declarative component intentionally keeps the compact `url` / `file` / `options` entry; wrap raw binary input as a named `File` when extension detection matters.
|
|
109
160
|
|
|
110
161
|
| Component | Actual props / entry | Event channel | Customization entry |
|
|
111
162
|
| --- | --- | --- | --- |
|
|
163
|
+
| Vanilla JS / Pure Web `@file-viewer/web` | `<flyfish-file-viewer>` attributes: `src/url`, `filename/name`, `type`, `size`, `theme`, `toolbar`, `toolbar-position`, `watermark`, `search`, `options`; also supports `mountViewer(...)` | `viewer-ready`, `viewer-event`, `viewer-state-change`, `viewer-error`, `onEvent`, `onStateChange`, `controller.subscribe()` | The Custom Element instance exposes the full controller handle; the IIFE script auto-registers it while keeping imperative `mountViewer` and the asset copy CLI. |
|
|
112
164
|
| Vue 3 `@file-viewer/vue3` | `url`, `file`, `options` | `load-start`, `load-complete`, `unload-start`, `unload-complete`, `operation-before`, `operation-cancel`, `operation-availability-change`, `search-change`, `location-change`, `zoom-change` | Template refs expose `FileViewerExpose`. For `Blob` / `ArrayBuffer`, prefer wrapping it as a named `File` so extension detection stays deterministic. |
|
|
113
165
|
| Vue 2.7 `@file-viewer/vue2.7` | `url`, `file`, `buffer`, `name`, `filename`, `type`, `size`, `options`, `containerClass`, `containerStyle` | `viewer-event` / `viewerEvent` | The component instance exposes the full controller handle. This is the Vue 2.7 line behind the historical `@flyfish-group/file-viewer` package. |
|
|
114
166
|
| Vue 2.6 `@file-viewer/vue2.6` | Same as Vue 2.7 | `viewer-event` / `viewerEvent` | Separate Vue 2.6 build for long-lived applications that cannot move to Vue 2.7. |
|
|
115
167
|
| React `@file-viewer/react` | `ViewerMountOptions` plus native `div` props such as `className`, `style`, `data-*`, and `aria-*` | `onEvent`, `onStateChange` | `ref` exposes `FileViewerHandle`; `useFileViewer()` returns `ref`, `props`, `state`, and `handle` for custom toolbars. |
|
|
116
168
|
| React Legacy `@file-viewer/react-legacy` | Same as the React package | `onEvent`, `onStateChange` | Targets React 16.8 / 17 with a legacy-friendly component export. |
|
|
117
|
-
| Pure Web `@file-viewer/web` | `mountViewer(container, ViewerMountOptions, ViewerCoreOptions?)` | `onEvent`, `onStateChange`, `controller.subscribe()` | Returns `ViewerController`; also ships ESM, script-tag IIFE, and the `file-viewer-copy-assets` CLI. |
|
|
118
169
|
| jQuery `@file-viewer/jquery` | `$(el).fileViewer(ViewerMountOptions & { replace?: boolean })` | `onEvent`, `onStateChange`, or `getFileViewerController(el).subscribe()` | Plugin methods include `zoomIn`, `printRenderedHtml`, and `searchDocument`; `replace:false` updates the same node in place. |
|
|
119
170
|
| Svelte `@file-viewer/svelte` | `ViewerMountOptions` plus `className` and `containerStyle` | `on:viewerEvent`, `onEvent`, `onStateChange` | `bind:this` exposes the controller handle; the `use:fileViewer` action is also available and adds `replace`. |
|
|
120
171
|
|
|
@@ -127,7 +178,7 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
127
178
|
| `ai` | Text collection, chunk size, and max text length for provenance, location, vectorization, and external AI workflows. |
|
|
128
179
|
| `archive` | Archive Worker/WASM URLs, timeout, cache, archive limits, and nested entry preview limits. |
|
|
129
180
|
| `pdf` | PDF.js worker, navigation pane, outline, thumbnails, rotation, streaming, range chunk size, and credentials. |
|
|
130
|
-
| `docx` / `spreadsheet` | DOCX uses the self-maintained @file-viewer/docx engine with Worker parsing, continuous flow reading, and async rendering by default; visual pagination is opt-in. Spreadsheet
|
|
181
|
+
| `docx` / `spreadsheet` | DOCX is provided by @file-viewer/renderer-word and uses the self-maintained @file-viewer/docx engine with Worker parsing, continuous flow reading, and async rendering by default; visual pagination is opt-in. Spreadsheet is provided by @file-viewer/renderer-spreadsheet with fidelity-first main-thread parsing, opt-in Worker loading, and opt-in header drag column resizing. |
|
|
131
182
|
| `typst` / `data` / `cad` | Typst, SQLite, CAD/DWG/DXF/DWF WASM, worker, encoding, and rendering strategy options. |
|
|
132
183
|
| `hooks` / `beforeOperation` | Shared lifecycle hooks and operation preflight checks for audit, permission, telemetry, and safety controls. |
|
|
133
184
|
|
|
@@ -146,10 +197,10 @@ For fully custom toolbars, hide the built-in toolbar and call the standard ref /
|
|
|
146
197
|
|
|
147
198
|
| Ecosystem | Recommended pattern |
|
|
148
199
|
| --- | --- |
|
|
200
|
+
| Vanilla JS / Pure Web | Use `<flyfish-file-viewer toolbar="false">` or `mountViewer(container, { options:{ toolbar:false }, onStateChange })`; custom DOM buttons can call `zoomIn()`, `printRenderedHtml()`, `searchDocument()`, and other element / controller methods directly. Use `viewer-state-change` or `controller.subscribe()` for advanced state sync. |
|
|
149
201
|
| Vue 3 | Pass `:options="{ toolbar: false }"`, call `downloadOriginalFile()`, `printRenderedHtml()`, `exportRenderedHtml()`, `zoomIn()`, `zoomOut()`, and `resetZoom()` through the template ref, and sync buttons with `@operation-availability-change` plus `@zoom-change`. |
|
|
150
202
|
| Vue 2.7 / 2.6 | Use `toolbar:false`, call instance methods through `$refs.viewer`, and listen to `@viewer-event` for `operation-availability-change` or `zoom-change`. |
|
|
151
203
|
| React / React Legacy | Prefer `useFileViewer({ options:{ toolbar:false } })`; pass `viewer.props` to the component, bind custom buttons to `viewer.handle`, and read `viewer.state.availability` / `viewer.state.zoom`. |
|
|
152
|
-
| Pure Web | Use `mountViewer(container, { options:{ toolbar:false }, onStateChange })`; custom DOM buttons call controller methods, and `controller.subscribe()` covers more advanced state sync. |
|
|
153
204
|
| jQuery | Use `$("#viewer").fileViewer({ options:{ toolbar:false } })`; buttons can call `$("#viewer").fileViewer("zoomIn")` or read capability state through `getFileViewerController($("#viewer")).subscribe()`. |
|
|
154
205
|
| Svelte | Use `<FileViewer bind:this={viewer} options={{ toolbar:false }} />`; buttons call `viewer.zoomIn()` / `viewer.printRenderedHtml()`, with `on:viewerEvent` or `onStateChange` for state sync. |
|
|
155
206
|
|
|
@@ -185,7 +236,7 @@ For fully custom toolbars, hide the built-in toolbar and call the standard ref /
|
|
|
185
236
|
| --- | --- |
|
|
186
237
|
| Shared viewer assets | The Pure Web package ships `file-viewer-copy-assets` to copy workers, WASM, vendor files, and examples into your static directory. |
|
|
187
238
|
| CAD / DWG / DXF / DWF | Configure `options.cad.wasmPath`, `workerUrl`, `dwfWasmUrl`, and `dxfEncoding` for self-hosted or intranet deployment. |
|
|
188
|
-
| PDF / DOCX / Excel | Configure `options.pdf.workerUrl`, `options.pdf.cMapUrl`, `options.pdf.wasmUrl`, `options.pdf.standardFontDataUrl`, `options.docx.workerUrl`, `options.docx.workerJsZipUrl`, and `options.spreadsheet.workerUrl`; DOCX Worker parsing is enabled by default
|
|
239
|
+
| PDF / DOCX / Excel | Configure `options.pdf.workerUrl`, `options.pdf.cMapUrl`, `options.pdf.wasmUrl`, `options.pdf.standardFontDataUrl`, `options.docx.workerUrl`, `options.docx.workerJsZipUrl`, and `options.spreadsheet.workerUrl`; DOCX Worker parsing is enabled by default, Excel Worker remains explicit opt-in, and header drag column resizing is controlled by `options.spreadsheet.resizableColumns`. |
|
|
189
240
|
| Typst / SQLite / Archive | Configure Typst compiler/renderer WASM, `data.sqlWasmUrl`, and `archive.workerUrl` / `archive.wasmUrl` as needed; Typst renders through local WASM only and never falls back to a public CDN. |
|
|
190
241
|
| Drawing | Draw.io uses the official diagrams.net offline viewer shipped with viewer assets by default; override `options.drawing.viewerScriptUrl` for custom paths, or set `preferOfficial:false` for the built-in SVG fallback. |
|
|
191
242
|
| Offline deployment | Runtime preview code does not depend on public CDN or third-party online assets; `file-viewer-copy-assets` copies PDF, CAD, Typst, SQLite, archive, Draw.io, DOCX worker/JSZip, and Office worker/vendor assets. |
|
package/README.md
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
# @file-viewer/web
|
|
2
2
|
|
|
3
|
-
标准纯 Web native
|
|
3
|
+
标准纯 Web native 组件包。它提供 `<flyfish-file-viewer>` 原生 Web Component、`mountViewer` 命令式 controller、IIFE 全局脚本和资源复制 CLI,适合传统后台页面、script 标签接入、微前端壳和无框架系统集成。
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install @file-viewer/web
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
```html
|
|
10
|
+
<flyfish-file-viewer
|
|
11
|
+
id="viewer"
|
|
12
|
+
src="/example/demo.pdf"
|
|
13
|
+
theme="light"
|
|
14
|
+
toolbar-position="bottom-right"
|
|
15
|
+
style="display:block;height:720px"
|
|
16
|
+
></flyfish-file-viewer>
|
|
17
|
+
```
|
|
18
|
+
|
|
9
19
|
```ts
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
20
|
+
import { defineFileViewerElement } from '@file-viewer/web'
|
|
21
|
+
|
|
22
|
+
defineFileViewerElement()
|
|
23
|
+
|
|
24
|
+
const viewer = document.getElementById('viewer')
|
|
25
|
+
viewer.addEventListener('viewer-event', event => {
|
|
26
|
+
console.log(event.detail.type)
|
|
18
27
|
})
|
|
28
|
+
viewer.zoomIn()
|
|
19
29
|
```
|
|
20
30
|
|
|
31
|
+
需要完全命令式场景时,仍可使用 `mountViewer(container, options)` 返回完整 controller。
|
|
32
|
+
|
|
21
33
|
如需自托管 Worker、WASM 和静态示例资源,可以使用资源复制命令:
|
|
22
34
|
|
|
23
35
|
```bash
|
|
@@ -28,39 +40,38 @@ npx file-viewer-copy-assets ./public/file-viewer
|
|
|
28
40
|
|
|
29
41
|
```html
|
|
30
42
|
<script src="/vendor/file-viewer-web/flyfish-file-viewer-web.iife.js"></script>
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</script>
|
|
43
|
+
<flyfish-file-viewer
|
|
44
|
+
src="/files/demo.pdf"
|
|
45
|
+
theme="light"
|
|
46
|
+
style="display:block;height:720px"
|
|
47
|
+
></flyfish-file-viewer>
|
|
37
48
|
```
|
|
38
49
|
|
|
39
50
|
历史包名 `@flyfish-group/file-viewer-web` 会继续同步维护;新项目建议优先使用标准包 `@file-viewer/web`。English README: [README.en.md](./README.en.md)。
|
|
40
51
|
|
|
41
52
|
## 能力范围
|
|
42
53
|
|
|
43
|
-
`@file-viewer/web`
|
|
54
|
+
`@file-viewer/web` 与其他标准组件包共享同一套 core 接口和 renderer/preset 装配模型;完整能力可通过按需 renderer 或 `@file-viewer/preset-all` 覆盖 PDF、Word、Excel、PPT、OFD、CAD/DWG/DXF/DWF、EPUB/UMD、压缩包、邮件、Markdown、代码高亮、图片、音频、视频、3D 模型、地理数据和结构化数据资产等预览链路。完整格式矩阵和参数说明见官方文档: https://doc.file-viewer.app/guide/formats
|
|
44
55
|
|
|
45
56
|
<!-- FILE_VIEWER_GENERATED:START -->
|
|
46
57
|
## 生态包矩阵
|
|
47
58
|
|
|
48
|
-
所有标准组件包都只共享 `@file-viewer/core` 这个总底座,不依赖其他框架组件实现。core
|
|
59
|
+
所有标准组件包都只共享 `@file-viewer/core` 这个总底座,不依赖其他框架组件实现。core 负责格式矩阵、资源解析、renderer 协议、事件、操作 API、搜索、缩放、打印和导出;PDF、Word、PPTX、CAD、Typst 等重型链路通过独立 renderer 或 preset 显式装配;各框架组件包自己维护本地 controller、组件生命周期、类型出口和生态交互。
|
|
49
60
|
|
|
50
61
|
| 框架 | 标准 npm 包 | 入口格式 | GitHub | Gitee | 兼容历史包 |
|
|
51
62
|
| --- | --- | --- | --- | --- | --- |
|
|
63
|
+
| Vanilla JS / Pure Web | `@file-viewer/web` | ESM, 类型声明, script 标签 IIFE, Worker/WASM viewer 资源, 复制静态资源 CLI | [file-viewer-web](https://github.com/flyfish-dev/file-viewer-web) | [file-viewer-web](https://gitee.com/flyfish-dev/file-viewer-web) | `@flyfish-group/file-viewer-web` |
|
|
52
64
|
| Vue 3 | `@file-viewer/vue3` | ESM, 类型声明 | [file-viewer-vue3](https://github.com/flyfish-dev/file-viewer-vue3) | [file-viewer-vue3](https://gitee.com/flyfish-dev/file-viewer-vue3) | `@flyfish-group/file-viewer3`, `file-viewer3` |
|
|
53
65
|
| Vue 2.7 | `@file-viewer/vue2.7` | ESM, 类型声明 | [file-viewer-vue2.7](https://github.com/flyfish-dev/file-viewer-vue2.7) | [file-viewer-vue2.7](https://gitee.com/flyfish-dev/file-viewer-vue2.7) | `@flyfish-group/file-viewer` |
|
|
54
66
|
| Vue 2.6 | `@file-viewer/vue2.6` | ESM, 类型声明 | [file-viewer-vue2.6](https://github.com/flyfish-dev/file-viewer-vue2.6) | [file-viewer-vue2.6](https://gitee.com/flyfish-dev/file-viewer-vue2.6) | 无 |
|
|
55
67
|
| React 18/19 | `@file-viewer/react` | ESM, 类型声明 | [file-viewer-react](https://github.com/flyfish-dev/file-viewer-react) | [file-viewer-react](https://gitee.com/flyfish-dev/file-viewer-react) | `@flyfish-group/file-viewer-react` |
|
|
56
68
|
| React 16.8/17 | `@file-viewer/react-legacy` | ESM, 类型声明 | [file-viewer-react-legacy](https://github.com/flyfish-dev/file-viewer-react-legacy) | [file-viewer-react-legacy](https://gitee.com/flyfish-dev/file-viewer-react-legacy) | 无 |
|
|
57
|
-
| Pure Web | `@file-viewer/web` | ESM, 类型声明, script 标签 IIFE, Worker/WASM viewer 资源, 复制静态资源 CLI | [file-viewer-web](https://github.com/flyfish-dev/file-viewer-web) | [file-viewer-web](https://gitee.com/flyfish-dev/file-viewer-web) | `@flyfish-group/file-viewer-web` |
|
|
58
69
|
| jQuery | `@file-viewer/jquery` | ESM, 类型声明 | [file-viewer-jquery](https://github.com/flyfish-dev/file-viewer-jquery) | [file-viewer-jquery](https://gitee.com/flyfish-dev/file-viewer-jquery) | 无 |
|
|
59
70
|
| Svelte | `@file-viewer/svelte` | Svelte 组件, ESM, 类型声明 | [file-viewer-svelte](https://github.com/flyfish-dev/file-viewer-svelte) | [file-viewer-svelte](https://gitee.com/flyfish-dev/file-viewer-svelte) | 无 |
|
|
60
71
|
|
|
61
72
|
## 格式支持矩阵
|
|
62
73
|
|
|
63
|
-
|
|
74
|
+
共享格式矩阵当前覆盖 24 条预览链路、206 个扩展名。完整能力通过 renderer / preset 按需装配,组件层只做生态适配,不互相嵌套。
|
|
64
75
|
|
|
65
76
|
| 预览链路 | 分类 | 扩展名 | 能力 | 加载 |
|
|
66
77
|
| --- | --- | --- | --- | --- |
|
|
@@ -74,20 +85,60 @@ npx file-viewer-copy-assets ./public/file-viewer
|
|
|
74
85
|
| Typst | document | `.typ`, `.typst` | 下载, 打印(适配器), HTML(适配器), 缩放(Provider), 搜索 | 按需异步 |
|
|
75
86
|
| Archive | archive | `.zip`, `.zipx`, `.7z`, `.rar`, `.tar`, `.gz`, `.gzip`, `.tgz`, `.bz2`, `.bzip2`, `.tbz`, `.tbz2`, `.xz`, `.txz`, `.lzma`, `.zst`, `.tzst`, `.cab`, `.ar`, `.cpio`, `.iso`, `.xar`, `.lha`, `.lzh`, `.jar`, `.war`, `.ear`, `.apk`, `.cbz`, `.cbr` | 下载, 搜索 | 按需异步 |
|
|
76
87
|
| Email | email | `.eml`, `.msg`, `.mbox` | 下载, HTML, 搜索 | 按需异步 |
|
|
77
|
-
| EDA | eda | `.olb`, `.dra` | 下载, 打印, HTML, 搜索 | 按需异步 |
|
|
88
|
+
| EDA | eda | `.olb`, `.dra`, `.gds`, `.oas`, `.oasis` | 下载, 打印, HTML, 搜索 | 按需异步 |
|
|
78
89
|
| CAD | cad | `.dxf`, `.dwg`, `.dwf`, `.dwfx`, `.xps` | 下载, 打印, HTML, 缩放(Provider) | 按需异步 |
|
|
79
|
-
| 3D Model | model | `.glb`, `.gltf`, `.obj`, `.stl`, `.ply`, `.fbx`, `.dae`, `.3ds`, `.3mf`, `.amf`, `.usd`, `.usda`, `.usdc`, `.usdz`, `.kmz`, `.step`, `.stp`, `.iges`, `.igs`, `.ifc`, `.3dm`, `.pcd`, `.wrl`, `.vrml`, `.xyz`, `.vtk`, `.vtp` | 下载, 缩放(Provider) | 按需异步 |
|
|
90
|
+
| 3D Model | model | `.glb`, `.gltf`, `.obj`, `.stl`, `.ply`, `.fbx`, `.dae`, `.3ds`, `.3mf`, `.amf`, `.usd`, `.usda`, `.usdc`, `.usdz`, `.kmz`, `.step`, `.stp`, `.iges`, `.igs`, `.ifc`, `.3dm`, `.brep`, `.pcd`, `.wrl`, `.vrml`, `.xyz`, `.vtk`, `.vtp` | 下载, 缩放(Provider) | 按需异步 |
|
|
80
91
|
| Geospatial | geo | `.geojson`, `.kml`, `.gpx`, `.shp` | 下载, 打印, HTML, 缩放(Provider), 搜索 | 按需异步 |
|
|
81
|
-
| Drawing | drawing | `.excalidraw`, `.drawio`, `.dio` | 下载, 打印, HTML, 缩放(Provider), 搜索 | 按需异步 |
|
|
92
|
+
| Drawing | drawing | `.excalidraw`, `.drawio`, `.dio`, `.mermaid`, `.mmd`, `.plantuml`, `.puml` | 下载, 打印, HTML, 缩放(Provider), 搜索 | 按需异步 |
|
|
93
|
+
| Mind Map | mindmap | `.xmind` | 下载, 打印, HTML, 缩放(Provider), 搜索 | 按需异步 |
|
|
82
94
|
| EPUB | ebook | `.epub` | 下载, HTML, 搜索(Provider) | 按需异步 |
|
|
83
95
|
| UMD | ebook | `.umd` | 下载, 打印, HTML, 缩放(Provider), 搜索 | 按需异步 |
|
|
84
96
|
| Image | image | `.gif`, `.jpg`, `.jpeg`, `.bmp`, `.tiff`, `.tif`, `.png`, `.svg`, `.webp`, `.avif`, `.ico`, `.heic`, `.heif`, `.jxl` | 下载, 打印, HTML, 缩放(Provider) | 按需异步 |
|
|
85
97
|
| Markdown | markdown | `.md`, `.markdown` | 下载, 打印, HTML, 搜索 | 按需异步 |
|
|
86
|
-
| Code and Text | code | `.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`, `.jsonc`, `.json5`, `.ipynb`, `.toml`, `.proto`, `.hcl`, `.tex`, `.gv`, `.http`, `.react`, `.rb`, `.swift`, `.kt` | 下载, 打印, HTML, 搜索 | 按需异步 |
|
|
98
|
+
| Code and Text | code | `.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`, `.patch`, `.bundle`, `.bdl`, `.jsonc`, `.json5`, `.ipynb`, `.toml`, `.proto`, `.hcl`, `.tex`, `.gv`, `.http`, `.react`, `.rb`, `.swift`, `.kt` | 下载, 打印, HTML, 搜索 | 按需异步 |
|
|
87
99
|
| Video | media | `.mp4`, `.webm`, `.m3u8` | 下载 | 按需异步 |
|
|
88
100
|
| Audio | media | `.mp3`, `.mpeg`, `.wav`, `.ogg`, `.oga`, `.opus`, `.m4a`, `.aac`, `.flac`, `.weba`, `.midi`, `.mid` | 下载 | 按需异步 |
|
|
89
101
|
| Data Asset | asset | `.ttf`, `.otf`, `.woff`, `.woff2`, `.psd`, `.ai`, `.eps`, `.sqlite`, `.wasm`, `.parquet`, `.avro`, `.webarchive` | 下载, HTML, 搜索 | 按需异步 |
|
|
90
102
|
|
|
103
|
+
## 工程级按需 renderer 装配
|
|
104
|
+
|
|
105
|
+
一个组件,一行代码,快速集成;真正影响安装体积和首屏包体的是 renderer 装配。推荐优先按产品形态选择 `@file-viewer/preset-lite`、`@file-viewer/preset-office`、`@file-viewer/preset-engineering` 或 `@file-viewer/preset-all`,需要极致裁剪时再安装单个 renderer 包。Vite 插件负责生成 `virtual:file-viewer-renderers`,业务代码只传同一套 `options`。
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm i @file-viewer/vue3 @file-viewer/core @file-viewer/vite-plugin @file-viewer/preset-office
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { fileViewerRenderers } from '@file-viewer/vite-plugin'
|
|
113
|
+
|
|
114
|
+
export default {
|
|
115
|
+
plugins: [
|
|
116
|
+
fileViewerRenderers({
|
|
117
|
+
preset: 'office',
|
|
118
|
+
scan: true,
|
|
119
|
+
copyAssets: true
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { configuredFileViewerRenderers } from 'virtual:file-viewer-renderers'
|
|
127
|
+
|
|
128
|
+
const options = {
|
|
129
|
+
builtinRenderers: 'none',
|
|
130
|
+
renderers: configuredFileViewerRenderers,
|
|
131
|
+
rendererMode: 'replace'
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- Vue、React、Svelte、jQuery、Vanilla JS / Pure Web 都传同一份 `options`,只是在各自生态中映射为 props、hook、action、plugin 或 `mountViewer(...)` 参数。
|
|
136
|
+
- `preset-lite` 面向文本、Markdown、代码、图片和音视频;`preset-office` 面向 PDF / Word / Excel / PowerPoint / OFD;`preset-engineering` 面向 CAD / 3D / 绘图 / XMind / Geo / Typst / EDA / Data。
|
|
137
|
+
- 想要最小包体时,可以不用 preset,直接安装 `@file-viewer/renderer-pdf`、`@file-viewer/renderer-word` 等单个 renderer,并用 `formats` 精确生成 import。
|
|
138
|
+
- `scan:true` 会识别 `fileViewerFormats`、`data-file-viewer-formats` 和上传控件 `accept`,调试与打包时自动选择 renderer。
|
|
139
|
+
- `copyAssets:true` 会复制 PDF/CAD/Typst/Archive/Data 等 worker、WASM 和 vendor 资源,满足离线和企业内网部署。
|
|
140
|
+
- 想一次性拥有官方 Demo 的完整能力时,可以安装 `@file-viewer/preset-all` 并把 `allRenderers` 传给 `renderers`;这适合 demo 和后台运维工具,不建议作为所有业务默认入口。
|
|
141
|
+
|
|
91
142
|
## 统一参数与事件
|
|
92
143
|
|
|
93
144
|
所有生态组件都围绕同一套 `ViewerMountOptions` 与 `FileViewerOptions` 工作,只是映射到各自框架的 props、事件、ref、action 或插件 API。
|
|
@@ -101,20 +152,20 @@ npx file-viewer-copy-assets ./public/file-viewer
|
|
|
101
152
|
| `type` | 显式指定扩展名或 MIME 线索,覆盖自动识别结果。 |
|
|
102
153
|
| `size` | 文件大小提示,用于生命周期上下文、加载状态和安全限制展示。 |
|
|
103
154
|
| `options` | 完整 `FileViewerOptions`,所有框架包保持同一套参数语义。 |
|
|
104
|
-
| `onEvent` / `onStateChange` | Pure Web、React、Svelte 等命令式包装层的统一事件和状态订阅;Vue 组件会映射为原生 emit。 |
|
|
155
|
+
| `onEvent` / `onStateChange` | Vanilla JS / Pure Web、React、Svelte 等命令式包装层的统一事件和状态订阅;Vue 组件会映射为原生 emit。 |
|
|
105
156
|
|
|
106
157
|
## 实际组件属性
|
|
107
158
|
|
|
108
|
-
下面列的是每个标准组件包当前真实暴露的属性、事件和控制入口。需要 `buffer`、`name`、`type`、`size` 这类命令式挂载参数时,优先选择
|
|
159
|
+
下面列的是每个标准组件包当前真实暴露的属性、事件和控制入口。需要 `buffer`、`name`、`type`、`size` 这类命令式挂载参数时,优先选择 Vanilla JS / Pure Web、React、Svelte、jQuery 或 Vue2 组件;Vue3 声明式组件保持 `url` / `file` / `options` 的简洁入口,复杂二进制来源请包装成带文件名的 `File`。
|
|
109
160
|
|
|
110
161
|
| 组件 | 实际属性 / 入口 | 事件入口 | 定制入口 |
|
|
111
162
|
| --- | --- | --- | --- |
|
|
163
|
+
| Vanilla JS / Pure Web `@file-viewer/web` | `<flyfish-file-viewer>` 属性 `src/url`、`filename/name`、`type`、`size`、`theme`、`toolbar`、`toolbar-position`、`watermark`、`search`、`options`;也支持 `mountViewer(...)` | `viewer-ready`、`viewer-event`、`viewer-state-change`、`viewer-error`、`onEvent`、`onStateChange`、`controller.subscribe()` | Custom Element 实例暴露完整 controller handle;IIFE script 标签会自动注册元素,同时保留 `mountViewer` 命令式挂载和资源复制 CLI。 |
|
|
112
164
|
| Vue 3 `@file-viewer/vue3` | `url`、`file`、`options` | `load-start`、`load-complete`、`unload-start`、`unload-complete`、`operation-before`、`operation-cancel`、`operation-availability-change`、`search-change`、`location-change`、`zoom-change` | 模板 `ref` 暴露 `FileViewerExpose`;适合声明式接入。`Blob` / `ArrayBuffer` 建议包装成带扩展名的 `File` 后传给 `file`。 |
|
|
113
165
|
| Vue 2.7 `@file-viewer/vue2.7` | `url`、`file`、`buffer`、`name`、`filename`、`type`、`size`、`options`、`containerClass`、`containerStyle` | `viewer-event` / `viewerEvent` | 组件实例暴露 controller handle 全量方法;适合 Vue 2.7 项目和历史 `@flyfish-group/file-viewer` 平滑升级。 |
|
|
114
166
|
| Vue 2.6 `@file-viewer/vue2.6` | 同 Vue 2.7 | `viewer-event` / `viewerEvent` | 独立 Vue 2.6 构建,不要求业务升级到 Vue 2.7。 |
|
|
115
167
|
| React `@file-viewer/react` | `ViewerMountOptions` + `div` 原生属性,如 `className`、`style`、`data-*`、`aria-*` | `onEvent`、`onStateChange` | `ref` 暴露 `FileViewerHandle`;`useFileViewer()` 会返回 `ref`、`props`、`state`、`handle`,便于自定义工具栏。 |
|
|
116
168
|
| React Legacy `@file-viewer/react-legacy` | 同 React 标准包 | `onEvent`、`onStateChange` | 面向 React 16.8 / 17;组件名和默认导出保持 legacy 生态友好。 |
|
|
117
|
-
| Pure Web `@file-viewer/web` | `mountViewer(container, ViewerMountOptions, ViewerCoreOptions?)` | `onEvent`、`onStateChange`、`controller.subscribe()` | 返回 `ViewerController`;同时提供 ESM、IIFE script 标签包和 `file-viewer-copy-assets`。 |
|
|
118
169
|
| jQuery `@file-viewer/jquery` | `$(el).fileViewer(ViewerMountOptions & { replace?: boolean })` | `onEvent`、`onStateChange` 或 `getFileViewerController(el).subscribe()` | 插件方法支持 `zoomIn`、`printRenderedHtml`、`searchDocument` 等;`replace:false` 可在同一节点上原地更新。 |
|
|
119
170
|
| Svelte `@file-viewer/svelte` | `ViewerMountOptions` + `className`、`containerStyle` | `on:viewerEvent`、`onEvent`、`onStateChange` | `bind:this` 暴露 controller handle;也提供 `use:fileViewer` action,action 额外支持 `replace`。 |
|
|
120
171
|
|
|
@@ -127,7 +178,7 @@ npx file-viewer-copy-assets ./public/file-viewer
|
|
|
127
178
|
| `ai` | 控制文本结构采集、分块大小和最大文本长度,为溯源、定位、向量化和外部 AI 流程提供基础。 |
|
|
128
179
|
| `archive` | 配置压缩包 Worker/WASM、超时、缓存、包体限制和压缩包内单文件预览大小。 |
|
|
129
180
|
| `pdf` | 配置 PDF.js Worker、导航栏、目录、缩略图、旋转、流式读取、Range chunk 和凭据。 |
|
|
130
|
-
| `docx` / `spreadsheet` | DOCX
|
|
181
|
+
| `docx` / `spreadsheet` | DOCX 由 @file-viewer/renderer-word 承接并使用自研 @file-viewer/docx,默认 Worker 解析、连续流式阅读和异步分批渲染,可按需显式开启视觉分页;表格由 @file-viewer/renderer-spreadsheet 承接,默认保真主线程渲染,Worker 和表头拖拽调列宽均可按需显式开启。 |
|
|
131
182
|
| `typst` / `data` / `cad` | 配置 Typst、SQLite、CAD/DWG/DXF/DWF 等 WASM、Worker、编码和渲染策略。 |
|
|
132
183
|
| `hooks` / `beforeOperation` | 统一生命周期 hooks 和操作前置校验,可用于审计、权限、埋点和安全控制。 |
|
|
133
184
|
|
|
@@ -146,10 +197,10 @@ npx file-viewer-copy-assets ./public/file-viewer
|
|
|
146
197
|
|
|
147
198
|
| 生态 | 推荐方式 |
|
|
148
199
|
| --- | --- |
|
|
200
|
+
| Vanilla JS / Pure Web | `<flyfish-file-viewer toolbar="false">` 或 `mountViewer(container, { options:{ toolbar:false }, onStateChange })`;外部 DOM 按钮可直接调用元素实例 / controller 的 `zoomIn()`、`printRenderedHtml()`、`searchDocument()` 等方法,复杂场景用 `viewer-state-change` 或 `controller.subscribe()` 同步状态。 |
|
|
149
201
|
| Vue 3 | 传 `:options="{ toolbar: false }"` 隐藏内置工具栏,通过模板 `ref` 调用 `downloadOriginalFile()`、`printRenderedHtml()`、`exportRenderedHtml()`、`zoomIn()`、`zoomOut()`、`resetZoom()`;用 `@operation-availability-change` 和 `@zoom-change` 同步按钮显隐与比例。 |
|
|
150
202
|
| Vue 2.7 / 2.6 | 同样设置 `toolbar:false`,通过 `$refs.viewer` 调用实例方法;监听 `@viewer-event`,在 `event.type === "operation-availability-change"` 或 `event.type === "zoom-change"` 时更新外部工具栏。 |
|
|
151
203
|
| React / React Legacy | 推荐 `useFileViewer({ options:{ toolbar:false } })`,把 `viewer.props` 传给组件,把按钮绑定到 `viewer.handle`,并读取 `viewer.state.availability` / `viewer.state.zoom` 控制禁用状态。 |
|
|
152
|
-
| Pure Web | `const controller = mountViewer(container, { options:{ toolbar:false }, onStateChange })`;外部 DOM 按钮调用 controller 方法,复杂场景可用 `controller.subscribe()` 做状态同步。 |
|
|
153
204
|
| jQuery | `$("#viewer").fileViewer({ options:{ toolbar:false } })`;按钮调用 `$("#viewer").fileViewer("zoomIn")` 或通过 `getFileViewerController($("#viewer")).subscribe()` 获取能力状态。 |
|
|
154
205
|
| Svelte | `<FileViewer bind:this={viewer} options={{ toolbar:false }} />`;按钮直接调用 `viewer.zoomIn()`、`viewer.printRenderedHtml()`,并用 `on:viewerEvent` / `onStateChange` 同步状态。 |
|
|
155
206
|
|
|
@@ -185,7 +236,7 @@ npx file-viewer-copy-assets ./public/file-viewer
|
|
|
185
236
|
| --- | --- |
|
|
186
237
|
| 通用 viewer assets | Pure Web 包提供 `file-viewer-copy-assets`,可把 Worker、WASM、vendor 和示例资源复制到业务静态目录。 |
|
|
187
238
|
| CAD / DWG / DXF / DWF | 按需配置 `options.cad.wasmPath`、`workerUrl`、`dwfWasmUrl`、`dxfEncoding`,支持自托管和内网部署。 |
|
|
188
|
-
| PDF / DOCX / Excel | 按需配置 `options.pdf.workerUrl`、`options.pdf.cMapUrl`、`options.pdf.wasmUrl`、`options.pdf.standardFontDataUrl`、`options.docx.workerUrl`、`options.docx.workerJsZipUrl`、`options.spreadsheet.workerUrl`;DOCX 默认启用自研 Worker 解析,Excel Worker
|
|
239
|
+
| PDF / DOCX / Excel | 按需配置 `options.pdf.workerUrl`、`options.pdf.cMapUrl`、`options.pdf.wasmUrl`、`options.pdf.standardFontDataUrl`、`options.docx.workerUrl`、`options.docx.workerJsZipUrl`、`options.spreadsheet.workerUrl`;DOCX 默认启用自研 Worker 解析,Excel Worker 需显式开启,列宽拖拽可通过 `options.spreadsheet.resizableColumns` 显式开启。 |
|
|
189
240
|
| Typst / SQLite / Archive | 按需配置 Typst compiler/renderer WASM、`data.sqlWasmUrl`、`archive.workerUrl` / `archive.wasmUrl`;Typst 仅使用本地 WASM 真实渲染,不访问公共 CDN。 |
|
|
190
241
|
| Drawing | Draw.io 默认使用随 viewer assets 分发的官方 diagrams.net 离线 viewer;路径特殊时可通过 `options.drawing.viewerScriptUrl` 覆盖,`preferOfficial:false` 才切到内置 SVG 兜底。 |
|
|
191
242
|
| 离线部署 | 运行时不依赖公共 CDN 或第三方在线资源;`file-viewer-copy-assets` 会复制 PDF、CAD、Typst、SQLite、压缩包、Draw.io、DOCX worker/JSZip 和 Office worker/vendor 资产。 |
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type FileRef, type ViewerController, type ViewerControllerHandle, type ViewerCoreOptions, type ViewerEvent, type ViewerMountOptions, type ViewerOptions, type ViewerState, type ViewerStateListener } from './controller.js';
|
|
2
|
+
export declare const FILE_VIEWER_ELEMENT_TAG = "flyfish-file-viewer";
|
|
3
|
+
export type FileViewerElementEventName = 'viewer-ready' | 'viewer-event' | 'viewer-state-change' | 'viewer-error';
|
|
4
|
+
export interface FileViewerElementReadyDetail {
|
|
5
|
+
controller: ViewerController;
|
|
6
|
+
}
|
|
7
|
+
export interface FileViewerElementStateChangeDetail {
|
|
8
|
+
state: ViewerState;
|
|
9
|
+
event?: ViewerEvent;
|
|
10
|
+
}
|
|
11
|
+
export interface FileViewerElementErrorDetail {
|
|
12
|
+
error: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface FileViewerElementSource extends ViewerMountOptions {
|
|
15
|
+
coreOptions?: ViewerCoreOptions;
|
|
16
|
+
}
|
|
17
|
+
declare const ElementBase: typeof HTMLElement;
|
|
18
|
+
declare const observedAttributes: readonly ["src", "url", "filename", "name", "type", "size", "theme", "toolbar", "toolbar-position", "watermark", "search", "options"];
|
|
19
|
+
type ObservedAttributeName = typeof observedAttributes[number];
|
|
20
|
+
export declare class FileViewerElement extends ElementBase implements ViewerControllerHandle {
|
|
21
|
+
static get observedAttributes(): ObservedAttributeName[];
|
|
22
|
+
private mountNode;
|
|
23
|
+
private controller;
|
|
24
|
+
private pendingUpdate;
|
|
25
|
+
private mountOptions;
|
|
26
|
+
private internalCoreOptions;
|
|
27
|
+
get src(): string | undefined;
|
|
28
|
+
set src(value: string | undefined);
|
|
29
|
+
get url(): string | undefined;
|
|
30
|
+
set url(value: string | undefined);
|
|
31
|
+
get file(): FileRef | undefined;
|
|
32
|
+
set file(value: FileRef | undefined);
|
|
33
|
+
get buffer(): ArrayBuffer | undefined;
|
|
34
|
+
set buffer(value: ArrayBuffer | undefined);
|
|
35
|
+
get name(): string | undefined;
|
|
36
|
+
set name(value: string | undefined);
|
|
37
|
+
get filename(): string | undefined;
|
|
38
|
+
set filename(value: string | undefined);
|
|
39
|
+
get type(): string | undefined;
|
|
40
|
+
set type(value: string | undefined);
|
|
41
|
+
get size(): number | undefined;
|
|
42
|
+
set size(value: number | undefined);
|
|
43
|
+
get options(): ViewerOptions | undefined;
|
|
44
|
+
set options(value: ViewerOptions | undefined);
|
|
45
|
+
get source(): FileViewerElementSource;
|
|
46
|
+
set source(value: FileViewerElementSource | undefined);
|
|
47
|
+
get coreOptions(): ViewerCoreOptions;
|
|
48
|
+
set coreOptions(value: ViewerCoreOptions | undefined);
|
|
49
|
+
connectedCallback(): void;
|
|
50
|
+
disconnectedCallback(): void;
|
|
51
|
+
attributeChangedCallback(name: ObservedAttributeName, oldValue: string | null, newValue: string | null): void;
|
|
52
|
+
load(options: ViewerMountOptions): Promise<void>;
|
|
53
|
+
update(options?: ViewerMountOptions): Promise<void>;
|
|
54
|
+
reload(): Promise<void>;
|
|
55
|
+
destroy(): void;
|
|
56
|
+
getController(): ViewerController | null;
|
|
57
|
+
getApi(): ReturnType<ViewerControllerHandle['getApi']>;
|
|
58
|
+
downloadOriginalFile(): Promise<void>;
|
|
59
|
+
printRenderedHtml(): Promise<void>;
|
|
60
|
+
exportRenderedHtml(): Promise<void>;
|
|
61
|
+
zoomIn(): ReturnType<ViewerControllerHandle['zoomIn']>;
|
|
62
|
+
zoomOut(): ReturnType<ViewerControllerHandle['zoomOut']>;
|
|
63
|
+
resetZoom(): ReturnType<ViewerControllerHandle['resetZoom']>;
|
|
64
|
+
searchDocument(query: string): ReturnType<ViewerControllerHandle['searchDocument']>;
|
|
65
|
+
clearDocumentSearch(): ReturnType<ViewerControllerHandle['clearDocumentSearch']>;
|
|
66
|
+
nextSearchResult(): ReturnType<ViewerControllerHandle['nextSearchResult']>;
|
|
67
|
+
previousSearchResult(): ReturnType<ViewerControllerHandle['previousSearchResult']>;
|
|
68
|
+
collectDocumentAnchors(): ReturnType<ViewerControllerHandle['collectDocumentAnchors']>;
|
|
69
|
+
scrollToAnchor(anchor: Parameters<ViewerControllerHandle['scrollToAnchor']>[0]): Promise<boolean>;
|
|
70
|
+
scrollToLine(line: number): Promise<boolean>;
|
|
71
|
+
getDocumentTextChunks(): ReturnType<ViewerControllerHandle['getDocumentTextChunks']>;
|
|
72
|
+
getOperationAvailability(): ReturnType<ViewerControllerHandle['getOperationAvailability']>;
|
|
73
|
+
getZoomState(): ReturnType<ViewerControllerHandle['getZoomState']>;
|
|
74
|
+
getSearchState(): ReturnType<ViewerControllerHandle['getSearchState']>;
|
|
75
|
+
getState(): ReturnType<ViewerControllerHandle['getState']>;
|
|
76
|
+
subscribe(listener: ViewerStateListener): () => void;
|
|
77
|
+
private setMountOptions;
|
|
78
|
+
private mount;
|
|
79
|
+
private remount;
|
|
80
|
+
private remountOrUpdate;
|
|
81
|
+
private ensureMountNode;
|
|
82
|
+
private createEffectiveMountOptions;
|
|
83
|
+
private readAttributeMountOptions;
|
|
84
|
+
private readAttributeViewerOptions;
|
|
85
|
+
private scheduleUpdate;
|
|
86
|
+
private dispatchViewerEvent;
|
|
87
|
+
private dispatchError;
|
|
88
|
+
private dispatchTypedEvent;
|
|
89
|
+
}
|
|
90
|
+
export declare const defineFileViewerElement: (tagName?: string) => CustomElementConstructor | undefined;
|
|
91
|
+
export {};
|