@file-viewer/react 2.2.2 → 2.2.4
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 +16 -12
- package/README.md +15 -11
- package/dist/controller.d.ts +1 -128
- package/dist/controller.js +2 -435
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -2
- package/package.json +5 -5
package/README.en.md
CHANGED
|
@@ -33,7 +33,7 @@ The historical package `@flyfish-group/file-viewer-react` remains supported for
|
|
|
33
33
|
<!-- FILE_VIEWER_GENERATED:START -->
|
|
34
34
|
## Ecosystem Matrix
|
|
35
35
|
|
|
36
|
-
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
|
|
36
|
+
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, export, and the framework-neutral browser shell. Heavy PDF, Word, PPT/PPTX, CAD, Typst, and similar pipelines are assembled explicitly through renderer packages or presets; each framework package owns its component lifecycle, type exports, compatibility defaults, and ecosystem-specific interaction layer.
|
|
37
37
|
|
|
38
38
|
| Framework | Standard npm package | Entrypoints | GitHub | Gitee | Historical aliases |
|
|
39
39
|
| --- | --- | --- | --- | --- | --- |
|
|
@@ -203,7 +203,7 @@ Every ecosystem package uses the same `ViewerMountOptions` and `FileViewerOption
|
|
|
203
203
|
| `type` | Explicit extension or MIME hint that overrides automatic detection. |
|
|
204
204
|
| `size` | File size hint used in lifecycle context, loading states, and safety limits. |
|
|
205
205
|
| `options` | The shared `FileViewerOptions` surface. Every component package keeps the same semantics. |
|
|
206
|
-
| `options.styleIsolation` | `auto`, `shadow`, `scoped`, or `none`.
|
|
206
|
+
| `options.styleIsolation` | `auto`, `shadow`, `scoped`, or `none`. `auto` uses Shadow DOM for every standard component so host-page global CSS cannot break the toolbar or document; legacy projects can explicitly use `none`. |
|
|
207
207
|
| `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. |
|
|
208
208
|
|
|
209
209
|
## Actual Component Props
|
|
@@ -224,7 +224,7 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
224
224
|
| Options Field | Description |
|
|
225
225
|
| --- | --- |
|
|
226
226
|
| `theme` | `light`, `dark`, or `system`. This takes precedence over browser `prefers-color-scheme`. |
|
|
227
|
-
| `styleIsolation` | `auto`, `shadow`, `scoped`, or `none`. With `auto`, Web Component
|
|
227
|
+
| `styleIsolation` | `auto`, `shadow`, `scoped`, or `none`. With `auto`, Web Component, IIFE, Vue, React, Svelte, jQuery, and full packages all use Shadow DOM by default. Legacy integrations that depend on deep class overrides can explicitly use `none`. |
|
|
228
228
|
| `watermark` | Text or image watermark with opacity, rotation, gap, size, font, and color controls. |
|
|
229
229
|
| `toolbar` | Controls the theme toggle, download, print, HTML export, zoom, item order, toolbar position, and operation-level preflight checks. |
|
|
230
230
|
| `search` | Document search, highlight class names, case sensitivity, whole-word matching, max matches, and debounce. |
|
|
@@ -232,25 +232,29 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
232
232
|
| `archive` | Archive Worker/WASM URLs, timeout, cache, archive limits, nested entry preview limits, and legacy GBK/GB18030 ZIP filename decoding. |
|
|
233
233
|
| `pdf` | PDF.js worker, navigation pane, outline, thumbnails, rotation, streaming, range chunk size, and credentials. |
|
|
234
234
|
| `docx` / `spreadsheet` | DOCX is provided by @file-viewer/renderer-word and uses the self-maintained @file-viewer/docx engine with automatic worker/main-thread selection, continuous flow reading, and async rendering by default; visual pagination is opt-in. Spreadsheet is provided by @file-viewer/renderer-spreadsheet with fidelity-first parsing, automatic Worker use for large files, and opt-in header drag column resizing. |
|
|
235
|
-
| `presentation` | The presentation renderer keeps two isolated engines: binary PowerPoint 97–2003 `.ppt` uses the packaged `@file-viewer/ppt@0.3.
|
|
235
|
+
| `presentation` | The presentation renderer keeps two isolated engines: binary PowerPoint 97–2003 `.ppt` uses the packaged `@file-viewer/ppt@0.3.2` Worker/OffscreenCanvas/WASM runtime with zero-config standard asset routes; `pptModuleUrl` / `pptWorkerUrl` / `pptWasmUrl` / `pptFontUrl` are custom-path overrides, while `pptWorker` and `pptCache` control its Worker and bounded frame cache. PPTX/OpenXML uses the `@file-viewer/pptx` Worker with optional `workerUrl` / `workerType` overrides. |
|
|
236
236
|
| `typst` / `data` / `cad` | Typst, SQLite, CAD/DWG/DXF/DWF WASM, worker, encoding, and rendering strategy options. |
|
|
237
237
|
| `hooks` / `beforeOperation` | Shared lifecycle hooks and operation preflight checks for audit, permission, telemetry, and safety controls. |
|
|
238
238
|
|
|
239
239
|
## Style Isolation And Theme Customization
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
Every standard component uses strong Shadow DOM isolation by default. Host-page global rules for `*`, `button`, `table`, `img`, `svg`, `canvas`, and similar selectors should not leak into the viewer toolbar or rendered content, and viewer resets should not pollute the host page.
|
|
242
242
|
|
|
243
243
|
| Mode | Description |
|
|
244
244
|
| --- | --- |
|
|
245
|
-
| `auto` | Default.
|
|
245
|
+
| `auto` | Default. Web Component, IIFE, Vue, React, Svelte, jQuery, and full packages all use Shadow DOM so host-page CSS cannot break the toolbar or renderer content. |
|
|
246
246
|
| `shadow` | Creates an explicit ShadowRoot render surface. Use it when host CSS is uncontrolled, micro-frontends are mixed, low-code platforms inject global resets, or design systems have aggressive base styles. |
|
|
247
|
-
| `scoped` | Does not create a ShadowRoot. Uses a stable root selector
|
|
247
|
+
| `scoped` | Does not create a ShadowRoot. Uses a stable root selector and local resets to limit its impact while keeping controlled inheritance from the host. |
|
|
248
248
|
| `none` | Historical light-DOM behavior for projects that depend on deep class overrides, old theme CSS, or snapshot tests. |
|
|
249
249
|
|
|
250
|
+
`styleIsolation` is a mount-time boundary. Remount the component when changing modes. Both `scoped` and `none` use Light DOM, so high-specificity or `!important` host rules can still override them.
|
|
251
|
+
|
|
250
252
|
Customization should start with `--file-viewer-*` CSS variables for color, typography, spacing, radius, toolbar, and button styling. Use stable Shadow Parts only when a specific internal surface needs styling. The current Web shell exposes `host`, `shell`, `toolbar`, `toolbar-group`, `toolbar-status`, `button`, `input`, and `content`; renderer extensions should keep using stable names such as `state-panel` and `watermark`. Do not depend on internal class names; they are implementation details.
|
|
251
253
|
|
|
254
|
+
In this example, `file-viewer-host` is the class on the actual Shadow host. Pass it as `class` in Vue 3, `containerClass` in Vue 2, `className` in React / Svelte, or add it to the element initialized by jQuery.
|
|
255
|
+
|
|
252
256
|
```css
|
|
253
|
-
|
|
257
|
+
.file-viewer-host {
|
|
254
258
|
--file-viewer-bg: #f7f9fc;
|
|
255
259
|
--file-viewer-text: #172033;
|
|
256
260
|
--file-viewer-toolbar-bg: rgba(255, 255, 255, 0.96);
|
|
@@ -258,16 +262,16 @@ flyfish-file-viewer {
|
|
|
258
262
|
--file-viewer-button-radius: 6px;
|
|
259
263
|
}
|
|
260
264
|
|
|
261
|
-
|
|
265
|
+
.file-viewer-host::part(toolbar) {
|
|
262
266
|
border: 1px solid rgba(20, 60, 100, 0.14);
|
|
263
267
|
}
|
|
264
268
|
|
|
265
|
-
|
|
269
|
+
.file-viewer-host::part(button) {
|
|
266
270
|
font-weight: 600;
|
|
267
271
|
}
|
|
268
272
|
```
|
|
269
273
|
|
|
270
|
-
Framework packages
|
|
274
|
+
Framework packages use Shadow DOM without extra configuration; set it explicitly when you want to lock the policy:
|
|
271
275
|
|
|
272
276
|
```ts
|
|
273
277
|
const options = {
|
|
@@ -339,7 +343,7 @@ View-state sync is designed for projection systems, remote-control displays, sid
|
|
|
339
343
|
| --- | --- |
|
|
340
344
|
| Shared viewer assets | Every `*-full` package exposes a `file-viewer-copy-assets` CLI at the package version. It copies workers, WASM, fonts, and vendor files into the application static directory and writes an integrity manifest. The complete `web-full` `dist/` also carries that payload directly. |
|
|
341
345
|
| CAD / DWG / DXF / DWF | Configure `options.cad.wasmPath`, `workerUrl`, `dwfWasmUrl`, and `dxfEncoding` for self-hosted or intranet deployment. |
|
|
342
|
-
| PDF / DOCX / Excel / PPT / PPTX | Configure `options.pdf.workerUrl`, `options.pdf.cMapUrl`, `options.pdf.wasmUrl`, `options.pdf.standardFontDataUrl`, `options.pdf.cjkFontFallbackPath`, `options.pdf.identityFontRepair`, `options.docx.workerUrl`, `options.docx.workerJsZipUrl`, `options.spreadsheet.workerUrl`, and `options.presentation.workerUrl` / `workerType`; PDF probes the real static worker first and lazy-loads the packaged handler when unavailable, unembedded CJK fonts fall back to self-hosted Noto Sans SC shards loaded per page, and malformed Identity CJK fonts without ToUnicode are repaired in memory after corrupted text is detected; DOCX chooses worker or main-thread parsing automatically, Electron `file://` and other unsafe local protocols fall back without user configuration; Excel defaults to `worker: auto`, enabling Worker automatically for files at or above `workerAutoThreshold`; CSV / TSV detects UTF-8, GBK, and GB18030 automatically and accepts `options.spreadsheet.textEncoding` as an explicit override; header drag column resizing is controlled by `options.spreadsheet.resizableColumns`; `.ppt` lazy-loads the packaged `@file-viewer/ppt@0.3.
|
|
346
|
+
| PDF / DOCX / Excel / PPT / PPTX | Configure `options.pdf.workerUrl`, `options.pdf.cMapUrl`, `options.pdf.wasmUrl`, `options.pdf.standardFontDataUrl`, `options.pdf.cjkFontFallbackPath`, `options.pdf.identityFontRepair`, `options.docx.workerUrl`, `options.docx.workerJsZipUrl`, `options.spreadsheet.workerUrl`, and `options.presentation.workerUrl` / `workerType`; PDF probes the real static worker first and lazy-loads the packaged handler when unavailable, unembedded CJK fonts fall back to self-hosted Noto Sans SC shards loaded per page, and malformed Identity CJK fonts without ToUnicode are repaired in memory after corrupted text is detected; DOCX chooses worker or main-thread parsing automatically, Electron `file://` and other unsafe local protocols fall back without user configuration; Excel defaults to `worker: auto`, enabling Worker automatically for files at or above `workerAutoThreshold`; CSV / TSV detects UTF-8, GBK, and GB18030 automatically and accepts `options.spreadsheet.textEncoding` as an explicit override; header drag column resizing is controlled by `options.spreadsheet.resizableColumns`; `.ppt` lazy-loads the packaged `@file-viewer/ppt@0.3.2` Worker/OffscreenCanvas/WASM runtime with bounded frame caching from `vendor/ppt/` without standard-layout configuration; `pptModuleUrl` / `pptWorkerUrl` / `pptWasmUrl` / `pptFontUrl` only override custom routes. PPTX creates its separate module Worker on demand. |
|
|
343
347
|
| 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; Archive decodes legacy GBK/GB18030 ZIP entry names, while RAR, 7z, and encrypted archives still require the libarchive Worker/WASM assets. |
|
|
344
348
|
| 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. |
|
|
345
349
|
| Offline deployment | Runtime preview code does not depend on public CDN or third-party online assets. Every `*-full` package uses `file-viewer/` under the deployment base (`/file-viewer/` at the origin root). Vite publishes assets with `copyAssets:true`; other build tools run `npx --no-install file-viewer-copy-assets ./public/file-viewer`. Call `setDefaultFullAssetBaseUrl()` when assets live elsewhere. |
|
package/README.md
CHANGED
|
@@ -203,7 +203,7 @@ const options = {
|
|
|
203
203
|
| `type` | 显式指定扩展名或 MIME 线索,覆盖自动识别结果。 |
|
|
204
204
|
| `size` | 文件大小提示,用于生命周期上下文、加载状态和安全限制展示。 |
|
|
205
205
|
| `options` | 完整 `FileViewerOptions`,所有框架包保持同一套参数语义。 |
|
|
206
|
-
| `options.styleIsolation` | `auto`、`shadow`、`scoped` 或 `none
|
|
206
|
+
| `options.styleIsolation` | `auto`、`shadow`、`scoped` 或 `none`。所有标准组件的 `auto` 默认使用 Shadow DOM,阻止宿主全局样式破坏工具栏和正文;旧项目可显式使用 `none`。 |
|
|
207
207
|
| `onEvent` / `onStateChange` | Vanilla JS / Pure Web、React、Svelte 等命令式包装层的统一事件和状态订阅;Vue 组件会映射为原生 emit。 |
|
|
208
208
|
|
|
209
209
|
## 实际组件属性
|
|
@@ -224,7 +224,7 @@ const options = {
|
|
|
224
224
|
| Options 字段 | 说明 |
|
|
225
225
|
| --- | --- |
|
|
226
226
|
| `theme` | `light`、`dark` 或 `system`,优先级高于浏览器 `prefers-color-scheme`。 |
|
|
227
|
-
| `styleIsolation` | `auto`、`shadow`、`scoped` 或 `none`。`auto` 下 Web Component
|
|
227
|
+
| `styleIsolation` | `auto`、`shadow`、`scoped` 或 `none`。`auto` 下 Web Component、IIFE、Vue、React、Svelte、jQuery 和 full 包均默认使用 Shadow DOM;依赖深层 class 覆盖的旧项目可显式使用 `none`。 |
|
|
228
228
|
| `watermark` | 开启文字或图片水印,可设置透明度、旋转、间距、尺寸、字体和颜色。 |
|
|
229
229
|
| `toolbar` | 控制主题切换、下载、打印、HTML 导出、缩放、按钮顺序和工具栏位置,并支持操作级前置校验。 |
|
|
230
230
|
| `search` | 配置文档搜索、高亮 class、大小写、整词匹配、最大命中数和 debounce。 |
|
|
@@ -232,25 +232,29 @@ const options = {
|
|
|
232
232
|
| `archive` | 配置压缩包 Worker/WASM、超时、缓存、包体限制和压缩包内单文件预览大小;旧 ZIP 中文文件名会自动按 GBK/GB18030 兼容解码。 |
|
|
233
233
|
| `pdf` | 配置 PDF.js Worker、导航栏、目录、缩略图、旋转、流式读取、Range chunk 和凭据。 |
|
|
234
234
|
| `docx` / `spreadsheet` | DOCX 由 @file-viewer/renderer-word 承接并使用自研 @file-viewer/docx,默认自动选择 Worker 或主线程解析,连续流式阅读和异步分批渲染,可按需显式开启视觉分页;表格由 @file-viewer/renderer-spreadsheet 承接,默认保真解析,大文件自动启用 Worker,表头拖拽调列宽可按需显式开启。 |
|
|
235
|
-
| `presentation` | 演示文稿 renderer 保持两条隔离引擎:PowerPoint 97–2003 `.ppt` 使用包内 `@file-viewer/ppt@0.3.
|
|
235
|
+
| `presentation` | 演示文稿 renderer 保持两条隔离引擎:PowerPoint 97–2003 `.ppt` 使用包内 `@file-viewer/ppt@0.3.2` Worker/OffscreenCanvas/WASM,标准资产布局无需配置 URL;`pptModuleUrl` / `pptWorkerUrl` / `pptWasmUrl` / `pptFontUrl` 仅用于自定义路径;`pptWorker` 与 `pptCache` 控制 Worker 和有界帧缓存。PPTX/OpenXML 使用 `@file-viewer/pptx` Worker,并可通过 `workerUrl` / `workerType` 覆盖。 |
|
|
236
236
|
| `typst` / `data` / `cad` | 配置 Typst、SQLite、CAD/DWG/DXF/DWF 等 WASM、Worker、编码和渲染策略。 |
|
|
237
237
|
| `hooks` / `beforeOperation` | 统一生命周期 hooks 和操作前置校验,可用于审计、权限、埋点和安全控制。 |
|
|
238
238
|
|
|
239
239
|
## 样式隔离与主题定制
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
所有标准组件默认使用 Shadow DOM 强隔离。宿主页面里的 `*`、`button`、`table`、`img`、`svg`、`canvas` 等全局样式不会直接侵入预览器工具栏和正文;预览器也不会把局部 reset 粗暴写到业务页面。
|
|
242
242
|
|
|
243
243
|
| 模式 | 说明 |
|
|
244
244
|
| --- | --- |
|
|
245
|
-
| `auto` |
|
|
245
|
+
| `auto` | 默认值。Web Component、IIFE、Vue、React、Svelte、jQuery 和 full 包均走 Shadow DOM,保护工具栏与 renderer 内容不受宿主全局 CSS 影响。 |
|
|
246
246
|
| `shadow` | 显式创建 ShadowRoot 作为渲染面,适合宿主 CSS 不可控、微前端混挂、低代码平台和设计系统全局 reset 很强的页面。 |
|
|
247
|
-
| `scoped` | 不创建 ShadowRoot
|
|
247
|
+
| `scoped` | 不创建 ShadowRoot,使用稳定根选择器和局部 reset 约束影响范围,适合需要被外层 CSS 轻度继承的场景。 |
|
|
248
248
|
| `none` | 历史 light DOM 行为,保留给依赖深度 class 覆盖、旧主题 CSS 或自动化测试快照的项目。 |
|
|
249
249
|
|
|
250
|
+
`styleIsolation` 是挂载边界配置;运行时切换模式时请重新挂载组件。`scoped` 与 `none` 都属于 Light DOM,仍可能被宿主的高权重或 `!important` 全局规则覆盖。
|
|
251
|
+
|
|
250
252
|
定制优先级建议是:先使用 `--file-viewer-*` CSS 变量覆盖颜色、字体、间距、圆角、工具栏和按钮;需要命中内部结构时再使用稳定 Shadow Parts。当前 Web shell 暴露 `host`、`shell`、`toolbar`、`toolbar-group`、`toolbar-status`、`button`、`input` 和 `content`,后续 renderer 扩展应继续使用 `state-panel`、`watermark` 这类稳定命名。不要依赖内部 class 名,它们只服务实现细节。
|
|
251
253
|
|
|
254
|
+
下面的 `file-viewer-host` 是实际 Shadow host 的 class:Vue 3 通过 `class`,Vue 2 通过 `containerClass`,React / Svelte 通过 `className` 传入,jQuery 则直接加在初始化节点上。
|
|
255
|
+
|
|
252
256
|
```css
|
|
253
|
-
|
|
257
|
+
.file-viewer-host {
|
|
254
258
|
--file-viewer-bg: #f7f9fc;
|
|
255
259
|
--file-viewer-text: #172033;
|
|
256
260
|
--file-viewer-toolbar-bg: rgba(255, 255, 255, 0.96);
|
|
@@ -258,16 +262,16 @@ flyfish-file-viewer {
|
|
|
258
262
|
--file-viewer-button-radius: 6px;
|
|
259
263
|
}
|
|
260
264
|
|
|
261
|
-
|
|
265
|
+
.file-viewer-host::part(toolbar) {
|
|
262
266
|
border: 1px solid rgba(20, 60, 100, 0.14);
|
|
263
267
|
}
|
|
264
268
|
|
|
265
|
-
|
|
269
|
+
.file-viewer-host::part(button) {
|
|
266
270
|
font-weight: 600;
|
|
267
271
|
}
|
|
268
272
|
```
|
|
269
273
|
|
|
270
|
-
|
|
274
|
+
框架组件无需额外配置即可使用 Shadow DOM;也可以在 `options` 中显式声明以固定策略:
|
|
271
275
|
|
|
272
276
|
```ts
|
|
273
277
|
const options = {
|
|
@@ -339,7 +343,7 @@ const options = {
|
|
|
339
343
|
| --- | --- |
|
|
340
344
|
| 通用 viewer assets | 所有 `*-full` 包都提供与自身同版本的 `file-viewer-copy-assets` CLI,用于把 Worker、WASM、字体和 vendor 资源复制到业务静态目录并生成完整性清单;`web-full` 的完整 `dist/` 还会直接携带这些资源。 |
|
|
341
345
|
| CAD / DWG / DXF / DWF | 按需配置 `options.cad.wasmPath`、`workerUrl`、`dwfWasmUrl`、`dxfEncoding`,支持自托管和内网部署。 |
|
|
342
|
-
| PDF / DOCX / Excel / PPT / PPTX | 按需配置 `options.pdf.workerUrl`、`options.pdf.cMapUrl`、`options.pdf.wasmUrl`、`options.pdf.standardFontDataUrl`、`options.pdf.cjkFontFallbackPath`、`options.pdf.identityFontRepair`、`options.docx.workerUrl`、`options.docx.workerJsZipUrl`、`options.spreadsheet.workerUrl`、`options.presentation.workerUrl` / `workerType`;PDF 默认探测真实静态 Worker,不可用时懒加载包内 handler 兜底,未嵌入的中文字体默认按页加载本地 Noto Sans SC 分片回退,缺失 ToUnicode 的异常 Identity CJK 字体会在检测到乱码后尝试内存修复;DOCX 默认自动选择 Worker 或主线程解析,Electron `file://` 等本地不安全协议会自动回退;Excel 默认 `worker: auto`,大文件达到 `workerAutoThreshold` 自动启用 Worker,CSV / TSV 自动识别 UTF-8、GBK 与 GB18030,也可用 `options.spreadsheet.textEncoding` 显式覆盖,列宽拖拽可通过 `options.spreadsheet.resizableColumns` 显式开启;`.ppt` 从 `vendor/ppt/` 按需加载 `@file-viewer/ppt@0.3.
|
|
346
|
+
| PDF / DOCX / Excel / PPT / PPTX | 按需配置 `options.pdf.workerUrl`、`options.pdf.cMapUrl`、`options.pdf.wasmUrl`、`options.pdf.standardFontDataUrl`、`options.pdf.cjkFontFallbackPath`、`options.pdf.identityFontRepair`、`options.docx.workerUrl`、`options.docx.workerJsZipUrl`、`options.spreadsheet.workerUrl`、`options.presentation.workerUrl` / `workerType`;PDF 默认探测真实静态 Worker,不可用时懒加载包内 handler 兜底,未嵌入的中文字体默认按页加载本地 Noto Sans SC 分片回退,缺失 ToUnicode 的异常 Identity CJK 字体会在检测到乱码后尝试内存修复;DOCX 默认自动选择 Worker 或主线程解析,Electron `file://` 等本地不安全协议会自动回退;Excel 默认 `worker: auto`,大文件达到 `workerAutoThreshold` 自动启用 Worker,CSV / TSV 自动识别 UTF-8、GBK 与 GB18030,也可用 `options.spreadsheet.textEncoding` 显式覆盖,列宽拖拽可通过 `options.spreadsheet.resizableColumns` 显式开启;`.ppt` 从 `vendor/ppt/` 按需加载 `@file-viewer/ppt@0.3.2` Worker/OffscreenCanvas/WASM 和有界帧缓存,标准布局无需配置,`pptModuleUrl` / `pptWorkerUrl` / `pptWasmUrl` / `pptFontUrl` 仅覆盖自定义路径;PPTX 按需创建另一条模块 Worker,两条引擎严格隔离。 |
|
|
343
347
|
| Typst / SQLite / Archive | 按需配置 Typst compiler/renderer WASM、`data.sqlWasmUrl`、`archive.workerUrl` / `archive.wasmUrl`;Typst 仅使用本地 WASM 真实渲染,不访问公共 CDN;Archive 兼容 GBK/GB18030 旧 ZIP 中文文件名,RAR、7z 和加密压缩包仍需要 libarchive Worker/WASM。 |
|
|
344
348
|
| Drawing | Draw.io 默认使用随 viewer assets 分发的官方 diagrams.net 离线 viewer;路径特殊时可通过 `options.drawing.viewerScriptUrl` 覆盖,`preferOfficial:false` 才切到内置 SVG 兜底。 |
|
|
345
349
|
| 离线部署 | 运行时不依赖公共 CDN 或第三方在线资源;所有 `*-full` 包默认使用部署基址下的 `file-viewer/`(根部署即 `/file-viewer/`)。Vite 使用 `copyAssets:true` 自动发布,其他构建工具运行 `npx --no-install file-viewer-copy-assets ./public/file-viewer`;资源放在其它位置时调用 `setDefaultFullAssetBaseUrl()`。 |
|
package/dist/controller.d.ts
CHANGED
|
@@ -1,128 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export type FileRef = FileViewerFileRef;
|
|
3
|
-
export type ViewerWatermarkOptions = FileViewerWatermarkOptions;
|
|
4
|
-
export type ViewerToolbarPosition = FileViewerToolbarPosition;
|
|
5
|
-
export type ViewerToolbarOptions = FileViewerToolbarOptions;
|
|
6
|
-
export type ViewerArchiveOptions = FileViewerArchiveOptions;
|
|
7
|
-
export type ViewerPdfOptions = FileViewerPdfOptions;
|
|
8
|
-
export type ViewerSpreadsheetOptions = FileViewerSpreadsheetOptions;
|
|
9
|
-
export type ViewerDocxOptions = FileViewerDocxOptions;
|
|
10
|
-
export type ViewerTypstOptions = FileViewerTypstOptions;
|
|
11
|
-
export type ViewerCadOptions = FileViewerCadOptions;
|
|
12
|
-
export type ViewerSearchOptions = FileViewerSearchOptions;
|
|
13
|
-
export type ViewerAiOptions = FileViewerAiOptions;
|
|
14
|
-
export type ViewerFitMode = FileViewerFitMode;
|
|
15
|
-
export type ViewerFitOptions = FileViewerFitOptions;
|
|
16
|
-
export type ViewerFitResult = FileViewerFitResult;
|
|
17
|
-
export type ViewerThemeMode = FileViewerThemeMode;
|
|
18
|
-
export type ViewerOptions = FileViewerOptions;
|
|
19
|
-
export type ViewerEventType = FileViewerEventType;
|
|
20
|
-
export type ViewerEvent = FileViewerEvent;
|
|
21
|
-
export type ViewerEventHandler = FileViewerEventHandler;
|
|
22
|
-
export type ViewerLifecycleContext = FileViewerLifecycleContext;
|
|
23
|
-
export type ViewerOperationContext = FileViewerOperationContext;
|
|
24
|
-
export interface ViewerState {
|
|
25
|
-
loading: boolean;
|
|
26
|
-
ready: boolean;
|
|
27
|
-
error: unknown | null;
|
|
28
|
-
lastEvent: ViewerEvent | null;
|
|
29
|
-
lifecycle: ViewerLifecycleContext | null;
|
|
30
|
-
availability: FileViewerOperationAvailability | null;
|
|
31
|
-
search: FileViewerSearchState | null;
|
|
32
|
-
zoom: FileViewerZoomState | null;
|
|
33
|
-
location: FileViewerDocumentAnchor | null;
|
|
34
|
-
}
|
|
35
|
-
export type ViewerStateListener = (state: ViewerState, event?: ViewerEvent) => void;
|
|
36
|
-
export interface ViewerMountOptions {
|
|
37
|
-
url?: string;
|
|
38
|
-
file?: FileRef;
|
|
39
|
-
buffer?: ArrayBuffer;
|
|
40
|
-
name?: string;
|
|
41
|
-
filename?: string;
|
|
42
|
-
type?: string;
|
|
43
|
-
size?: number;
|
|
44
|
-
options?: ViewerOptions;
|
|
45
|
-
onEvent?: ViewerEventHandler;
|
|
46
|
-
onStateChange?: ViewerStateListener;
|
|
47
|
-
}
|
|
48
|
-
export interface ViewerSourceInput {
|
|
49
|
-
url?: string;
|
|
50
|
-
file?: FileRef;
|
|
51
|
-
buffer?: ArrayBuffer;
|
|
52
|
-
filename?: string;
|
|
53
|
-
name?: string;
|
|
54
|
-
type?: string;
|
|
55
|
-
size?: number;
|
|
56
|
-
}
|
|
57
|
-
export interface ViewerFetchInput {
|
|
58
|
-
url: string;
|
|
59
|
-
signal?: AbortSignal;
|
|
60
|
-
source: ViewerSourceInput;
|
|
61
|
-
}
|
|
62
|
-
export type ViewerFetchFile = (input: ViewerFetchInput) => Promise<FileRef | null | undefined>;
|
|
63
|
-
export interface ViewerCoreOptions {
|
|
64
|
-
registry?: RendererRegistry;
|
|
65
|
-
fetchFile?: ViewerFetchFile;
|
|
66
|
-
onError?: (error: unknown, source: ViewerSourceInput) => void;
|
|
67
|
-
}
|
|
68
|
-
export interface ViewerController {
|
|
69
|
-
readonly container: HTMLElement;
|
|
70
|
-
load(options: ViewerMountOptions): Promise<void>;
|
|
71
|
-
update(options?: ViewerMountOptions): Promise<void>;
|
|
72
|
-
reload(): Promise<void>;
|
|
73
|
-
destroy(): void;
|
|
74
|
-
getApi(): FileViewerPublicApi | FileViewerInstance | null;
|
|
75
|
-
downloadOriginalFile(): Promise<void>;
|
|
76
|
-
printRenderedHtml(options?: FileViewerPrintOptions): Promise<void>;
|
|
77
|
-
printWithMask(options?: FileViewerPrintOptions): Promise<void>;
|
|
78
|
-
exportRenderedHtml(): Promise<void>;
|
|
79
|
-
zoomIn(): Promise<FileViewerZoomState | null>;
|
|
80
|
-
zoomOut(): Promise<FileViewerZoomState | null>;
|
|
81
|
-
resetZoom(): Promise<FileViewerZoomState | null>;
|
|
82
|
-
fitToView(fit?: FileViewerFitMode | FileViewerFitOptions): Promise<FileViewerFitResult | null>;
|
|
83
|
-
searchDocument(query: string): Promise<FileViewerSearchState | null>;
|
|
84
|
-
clearDocumentSearch(): Promise<FileViewerSearchState | null>;
|
|
85
|
-
nextSearchResult(): Promise<FileViewerSearchState | null>;
|
|
86
|
-
previousSearchResult(): Promise<FileViewerSearchState | null>;
|
|
87
|
-
collectDocumentAnchors(): Promise<FileViewerDocumentAnchor[]>;
|
|
88
|
-
scrollToAnchor(anchor: FileViewerDocumentAnchor | string): Promise<boolean>;
|
|
89
|
-
scrollToLine(line: number): Promise<boolean>;
|
|
90
|
-
getDocumentTextChunks(): FileViewerDocumentChunk[];
|
|
91
|
-
getOperationAvailability(): FileViewerOperationAvailability | null;
|
|
92
|
-
getZoomState(): FileViewerZoomState | null;
|
|
93
|
-
getSearchState(): FileViewerSearchState | null;
|
|
94
|
-
getState(): ViewerState;
|
|
95
|
-
subscribe(listener: ViewerStateListener): () => void;
|
|
96
|
-
}
|
|
97
|
-
export type ViewerControllerAccessor = () => ViewerController | null;
|
|
98
|
-
export interface ViewerControllerHandle {
|
|
99
|
-
load(options: ViewerMountOptions): Promise<void>;
|
|
100
|
-
update(options?: ViewerMountOptions): Promise<void>;
|
|
101
|
-
reload(): Promise<void>;
|
|
102
|
-
destroy(): void;
|
|
103
|
-
getController(): ViewerController | null;
|
|
104
|
-
getApi(): FileViewerPublicApi | FileViewerInstance | null;
|
|
105
|
-
downloadOriginalFile(): Promise<void>;
|
|
106
|
-
printRenderedHtml(options?: FileViewerPrintOptions): Promise<void>;
|
|
107
|
-
printWithMask(options?: FileViewerPrintOptions): Promise<void>;
|
|
108
|
-
exportRenderedHtml(): Promise<void>;
|
|
109
|
-
zoomIn(): Promise<FileViewerZoomState | null>;
|
|
110
|
-
zoomOut(): Promise<FileViewerZoomState | null>;
|
|
111
|
-
resetZoom(): Promise<FileViewerZoomState | null>;
|
|
112
|
-
fitToView(fit?: FileViewerFitMode | FileViewerFitOptions): Promise<FileViewerFitResult | null>;
|
|
113
|
-
searchDocument(query: string): Promise<FileViewerSearchState | null>;
|
|
114
|
-
clearDocumentSearch(): Promise<FileViewerSearchState | null>;
|
|
115
|
-
nextSearchResult(): Promise<FileViewerSearchState | null>;
|
|
116
|
-
previousSearchResult(): Promise<FileViewerSearchState | null>;
|
|
117
|
-
collectDocumentAnchors(): Promise<FileViewerDocumentAnchor[]>;
|
|
118
|
-
scrollToAnchor(anchor: FileViewerDocumentAnchor | string): Promise<boolean>;
|
|
119
|
-
scrollToLine(line: number): Promise<boolean>;
|
|
120
|
-
getDocumentTextChunks(): FileViewerDocumentChunk[];
|
|
121
|
-
getOperationAvailability(): FileViewerOperationAvailability | null;
|
|
122
|
-
getZoomState(): FileViewerZoomState | null;
|
|
123
|
-
getSearchState(): FileViewerSearchState | null;
|
|
124
|
-
getState(): ViewerState | null;
|
|
125
|
-
subscribe(listener: ViewerStateListener): () => void;
|
|
126
|
-
}
|
|
127
|
-
export declare const createViewerControllerHandle: (getController: ViewerControllerAccessor, dispose: () => void) => ViewerControllerHandle;
|
|
128
|
-
export declare const mountViewer: (container: HTMLElement, initialOptions?: ViewerMountOptions, coreOptions?: ViewerCoreOptions) => ViewerController;
|
|
1
|
+
export * from '@file-viewer/core/browser';
|
package/dist/controller.js
CHANGED
|
@@ -1,435 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
4
|
-
const hasSource = (options = {}) => {
|
|
5
|
-
return !!(options.url || options.file || options.buffer);
|
|
6
|
-
};
|
|
7
|
-
const toViewerSourceInput = (options = {}) => ({
|
|
8
|
-
url: options.url,
|
|
9
|
-
file: options.file,
|
|
10
|
-
buffer: options.buffer,
|
|
11
|
-
filename: options.filename || options.name,
|
|
12
|
-
name: options.name,
|
|
13
|
-
type: options.type,
|
|
14
|
-
size: options.size,
|
|
15
|
-
});
|
|
16
|
-
const canUseFetch = () => typeof fetch === 'function';
|
|
17
|
-
const defaultFetchFile = async ({ url, signal }) => {
|
|
18
|
-
if (!canUseFetch()) {
|
|
19
|
-
throw new Error('fetch is not available in the current environment.');
|
|
20
|
-
}
|
|
21
|
-
const requestUrl = normalizeFileViewerSourceUrl(url) || url;
|
|
22
|
-
const response = await fetch(requestUrl, { signal });
|
|
23
|
-
if (!response.ok) {
|
|
24
|
-
throw new Error(`Failed to fetch file: ${response.status} ${response.statusText}`);
|
|
25
|
-
}
|
|
26
|
-
return response.blob();
|
|
27
|
-
};
|
|
28
|
-
const resolveViewerSourceFilename = (source) => {
|
|
29
|
-
return normalizeFilename(source.filename || source.name || resolveFileViewerSourceFilename({
|
|
30
|
-
file: source.file,
|
|
31
|
-
url: source.url,
|
|
32
|
-
fallback: DEFAULT_FILE_VIEWER_SOURCE_FILENAME,
|
|
33
|
-
}), source.type ? `preview.${source.type}` : DEFAULT_FILE_VIEWER_SOURCE_FILENAME);
|
|
34
|
-
};
|
|
35
|
-
const resolveViewerLoadSource = async (source, options = {}) => {
|
|
36
|
-
var _a, _b, _c;
|
|
37
|
-
const filename = resolveViewerSourceFilename(source);
|
|
38
|
-
const type = source.type || getExtension(filename);
|
|
39
|
-
if (source.buffer) {
|
|
40
|
-
return {
|
|
41
|
-
buffer: source.buffer,
|
|
42
|
-
filename,
|
|
43
|
-
type,
|
|
44
|
-
size: (_a = source.size) !== null && _a !== void 0 ? _a : source.buffer.byteLength,
|
|
45
|
-
url: source.url,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (source.file) {
|
|
49
|
-
const file = wrapFileViewerFileRef(source.file, filename);
|
|
50
|
-
return {
|
|
51
|
-
file,
|
|
52
|
-
buffer: await readFileViewerBuffer(file),
|
|
53
|
-
filename: file.name || filename,
|
|
54
|
-
type: type || getExtension(file.name),
|
|
55
|
-
size: (_b = source.size) !== null && _b !== void 0 ? _b : file.size,
|
|
56
|
-
url: source.url,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (source.url) {
|
|
60
|
-
const fileRef = await (options.fetchFile || defaultFetchFile)({
|
|
61
|
-
url: source.url,
|
|
62
|
-
signal: options.signal,
|
|
63
|
-
source,
|
|
64
|
-
});
|
|
65
|
-
if (!fileRef) {
|
|
66
|
-
throw new Error('Downloaded file is empty.');
|
|
67
|
-
}
|
|
68
|
-
const file = wrapFileViewerFileRef(fileRef, filename);
|
|
69
|
-
return {
|
|
70
|
-
file,
|
|
71
|
-
buffer: await readFileViewerBuffer(file),
|
|
72
|
-
filename: file.name || filename,
|
|
73
|
-
type: type || getExtension(file.name),
|
|
74
|
-
size: (_c = source.size) !== null && _c !== void 0 ? _c : file.size,
|
|
75
|
-
url: source.url,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
filename,
|
|
80
|
-
type,
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
export const createViewerControllerHandle = (getController, dispose) => ({
|
|
84
|
-
load(options) {
|
|
85
|
-
var _a, _b;
|
|
86
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.load(options)) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
87
|
-
},
|
|
88
|
-
update(options) {
|
|
89
|
-
var _a, _b;
|
|
90
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.update(options)) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
91
|
-
},
|
|
92
|
-
reload() {
|
|
93
|
-
var _a, _b;
|
|
94
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.reload()) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
95
|
-
},
|
|
96
|
-
destroy() {
|
|
97
|
-
dispose();
|
|
98
|
-
},
|
|
99
|
-
getController,
|
|
100
|
-
getApi() {
|
|
101
|
-
var _a, _b;
|
|
102
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getApi()) !== null && _b !== void 0 ? _b : null;
|
|
103
|
-
},
|
|
104
|
-
downloadOriginalFile() {
|
|
105
|
-
var _a, _b;
|
|
106
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.downloadOriginalFile()) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
107
|
-
},
|
|
108
|
-
printRenderedHtml(options) {
|
|
109
|
-
var _a, _b;
|
|
110
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.printRenderedHtml(options)) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
111
|
-
},
|
|
112
|
-
printWithMask(options) {
|
|
113
|
-
var _a, _b;
|
|
114
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.printWithMask(options)) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
115
|
-
},
|
|
116
|
-
exportRenderedHtml() {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.exportRenderedHtml()) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
119
|
-
},
|
|
120
|
-
zoomIn() {
|
|
121
|
-
var _a, _b;
|
|
122
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.zoomIn()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
123
|
-
},
|
|
124
|
-
zoomOut() {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.zoomOut()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
127
|
-
},
|
|
128
|
-
resetZoom() {
|
|
129
|
-
var _a, _b;
|
|
130
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.resetZoom()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
131
|
-
},
|
|
132
|
-
fitToView(fit) {
|
|
133
|
-
var _a, _b;
|
|
134
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.fitToView(fit)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
135
|
-
},
|
|
136
|
-
searchDocument(query) {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.searchDocument(query)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
139
|
-
},
|
|
140
|
-
clearDocumentSearch() {
|
|
141
|
-
var _a, _b;
|
|
142
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.clearDocumentSearch()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
143
|
-
},
|
|
144
|
-
nextSearchResult() {
|
|
145
|
-
var _a, _b;
|
|
146
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.nextSearchResult()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
147
|
-
},
|
|
148
|
-
previousSearchResult() {
|
|
149
|
-
var _a, _b;
|
|
150
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.previousSearchResult()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
151
|
-
},
|
|
152
|
-
collectDocumentAnchors() {
|
|
153
|
-
var _a, _b;
|
|
154
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.collectDocumentAnchors()) !== null && _b !== void 0 ? _b : Promise.resolve([]);
|
|
155
|
-
},
|
|
156
|
-
scrollToAnchor(anchor) {
|
|
157
|
-
var _a, _b;
|
|
158
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.scrollToAnchor(anchor)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
|
|
159
|
-
},
|
|
160
|
-
scrollToLine(line) {
|
|
161
|
-
var _a, _b;
|
|
162
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.scrollToLine(line)) !== null && _b !== void 0 ? _b : Promise.resolve(false);
|
|
163
|
-
},
|
|
164
|
-
getDocumentTextChunks() {
|
|
165
|
-
var _a, _b;
|
|
166
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getDocumentTextChunks()) !== null && _b !== void 0 ? _b : [];
|
|
167
|
-
},
|
|
168
|
-
getOperationAvailability() {
|
|
169
|
-
var _a, _b;
|
|
170
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getOperationAvailability()) !== null && _b !== void 0 ? _b : null;
|
|
171
|
-
},
|
|
172
|
-
getZoomState() {
|
|
173
|
-
var _a, _b;
|
|
174
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getZoomState()) !== null && _b !== void 0 ? _b : null;
|
|
175
|
-
},
|
|
176
|
-
getSearchState() {
|
|
177
|
-
var _a, _b;
|
|
178
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getSearchState()) !== null && _b !== void 0 ? _b : null;
|
|
179
|
-
},
|
|
180
|
-
getState() {
|
|
181
|
-
var _a, _b;
|
|
182
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getState()) !== null && _b !== void 0 ? _b : null;
|
|
183
|
-
},
|
|
184
|
-
subscribe(listener) {
|
|
185
|
-
var _a, _b;
|
|
186
|
-
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.subscribe(listener)) !== null && _b !== void 0 ? _b : (() => { });
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
const callApi = async (api, action, fallback) => {
|
|
190
|
-
if (!api) {
|
|
191
|
-
return fallback;
|
|
192
|
-
}
|
|
193
|
-
return action(api);
|
|
194
|
-
};
|
|
195
|
-
const isAbortError = (error) => {
|
|
196
|
-
return Boolean(error && typeof error === 'object' && error.name === 'AbortError');
|
|
197
|
-
};
|
|
198
|
-
export const mountViewer = (container, initialOptions = {}, coreOptions = {}) => {
|
|
199
|
-
if (!isBrowser()) {
|
|
200
|
-
throw new Error('Flyfish File Viewer can only be mounted in a browser DOM environment.');
|
|
201
|
-
}
|
|
202
|
-
let disposed = false;
|
|
203
|
-
let currentOptions = initialOptions;
|
|
204
|
-
let currentSource = hasSource(currentOptions)
|
|
205
|
-
? toViewerSourceInput(currentOptions)
|
|
206
|
-
: null;
|
|
207
|
-
let abortController = null;
|
|
208
|
-
const listeners = new Set();
|
|
209
|
-
const state = {
|
|
210
|
-
loading: false,
|
|
211
|
-
ready: false,
|
|
212
|
-
error: null,
|
|
213
|
-
lastEvent: null,
|
|
214
|
-
lifecycle: null,
|
|
215
|
-
availability: null,
|
|
216
|
-
search: null,
|
|
217
|
-
zoom: null,
|
|
218
|
-
location: null,
|
|
219
|
-
};
|
|
220
|
-
const snapshotState = () => ({
|
|
221
|
-
...state,
|
|
222
|
-
search: state.search
|
|
223
|
-
? { ...state.search, matches: [...state.search.matches] }
|
|
224
|
-
: null,
|
|
225
|
-
});
|
|
226
|
-
const notifyState = (event) => {
|
|
227
|
-
var _a;
|
|
228
|
-
const snapshot = snapshotState();
|
|
229
|
-
(_a = currentOptions.onStateChange) === null || _a === void 0 ? void 0 : _a.call(currentOptions, snapshot, event);
|
|
230
|
-
listeners.forEach(listener => listener(snapshot, event));
|
|
231
|
-
};
|
|
232
|
-
const applyViewerEvent = (event) => {
|
|
233
|
-
var _a;
|
|
234
|
-
state.lastEvent = event;
|
|
235
|
-
if (event.type === 'load-start') {
|
|
236
|
-
state.loading = true;
|
|
237
|
-
state.ready = false;
|
|
238
|
-
state.error = null;
|
|
239
|
-
state.lifecycle = event.payload;
|
|
240
|
-
}
|
|
241
|
-
else if (event.type === 'load-complete') {
|
|
242
|
-
state.loading = false;
|
|
243
|
-
state.ready = true;
|
|
244
|
-
state.lifecycle = event.payload;
|
|
245
|
-
}
|
|
246
|
-
else if (event.type === 'unload-start') {
|
|
247
|
-
state.loading = true;
|
|
248
|
-
state.ready = false;
|
|
249
|
-
state.lifecycle = event.payload;
|
|
250
|
-
}
|
|
251
|
-
else if (event.type === 'unload-complete') {
|
|
252
|
-
state.loading = false;
|
|
253
|
-
state.ready = false;
|
|
254
|
-
state.lifecycle = event.payload;
|
|
255
|
-
}
|
|
256
|
-
else if (event.type === 'operation-availability-change') {
|
|
257
|
-
state.availability = event.payload;
|
|
258
|
-
}
|
|
259
|
-
else if (event.type === 'search-change') {
|
|
260
|
-
state.search = event.payload;
|
|
261
|
-
}
|
|
262
|
-
else if (event.type === 'location-change') {
|
|
263
|
-
state.location = event.payload;
|
|
264
|
-
}
|
|
265
|
-
else if (event.type === 'zoom-change') {
|
|
266
|
-
state.zoom = event.payload;
|
|
267
|
-
}
|
|
268
|
-
(_a = currentOptions.onEvent) === null || _a === void 0 ? void 0 : _a.call(currentOptions, event);
|
|
269
|
-
notifyState(event);
|
|
270
|
-
};
|
|
271
|
-
const instance = createViewer(container, {
|
|
272
|
-
registry: coreOptions.registry,
|
|
273
|
-
options: currentOptions.options,
|
|
274
|
-
onEvent: applyViewerEvent,
|
|
275
|
-
});
|
|
276
|
-
const cancel = () => {
|
|
277
|
-
abortController === null || abortController === void 0 ? void 0 : abortController.abort();
|
|
278
|
-
abortController = null;
|
|
279
|
-
};
|
|
280
|
-
const loadSource = async (nextSource) => {
|
|
281
|
-
var _a;
|
|
282
|
-
cancel();
|
|
283
|
-
currentSource = nextSource;
|
|
284
|
-
abortController = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
285
|
-
const controller = abortController;
|
|
286
|
-
try {
|
|
287
|
-
state.loading = true;
|
|
288
|
-
state.error = null;
|
|
289
|
-
notifyState();
|
|
290
|
-
const resolvedSource = await resolveViewerLoadSource(nextSource, {
|
|
291
|
-
fetchFile: coreOptions.fetchFile,
|
|
292
|
-
signal: controller === null || controller === void 0 ? void 0 : controller.signal,
|
|
293
|
-
});
|
|
294
|
-
if (disposed || (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) || abortController !== controller) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
return await instance.load(resolvedSource);
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
if (isAbortError(error) && (controller === null || controller === void 0 ? void 0 : controller.signal.aborted)) {
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
state.loading = false;
|
|
304
|
-
state.ready = false;
|
|
305
|
-
state.error = error;
|
|
306
|
-
notifyState();
|
|
307
|
-
(_a = coreOptions.onError) === null || _a === void 0 ? void 0 : _a.call(coreOptions, error, nextSource);
|
|
308
|
-
throw error;
|
|
309
|
-
}
|
|
310
|
-
finally {
|
|
311
|
-
if (abortController === controller) {
|
|
312
|
-
abortController = null;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
if (currentSource) {
|
|
317
|
-
void loadSource(currentSource);
|
|
318
|
-
}
|
|
319
|
-
const controller = {
|
|
320
|
-
container,
|
|
321
|
-
async load(nextOptions) {
|
|
322
|
-
if (disposed)
|
|
323
|
-
return;
|
|
324
|
-
currentOptions = nextOptions;
|
|
325
|
-
instance.updateOptions(currentOptions.options || {});
|
|
326
|
-
if (hasSource(currentOptions)) {
|
|
327
|
-
await loadSource(toViewerSourceInput(currentOptions));
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
async update(nextOptions = {}) {
|
|
331
|
-
var _a;
|
|
332
|
-
if (disposed)
|
|
333
|
-
return;
|
|
334
|
-
currentOptions = {
|
|
335
|
-
...currentOptions,
|
|
336
|
-
...nextOptions,
|
|
337
|
-
options: (_a = nextOptions.options) !== null && _a !== void 0 ? _a : currentOptions.options,
|
|
338
|
-
};
|
|
339
|
-
instance.updateOptions(currentOptions.options || {});
|
|
340
|
-
if (hasSource(currentOptions)) {
|
|
341
|
-
await loadSource(toViewerSourceInput(currentOptions));
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
currentSource = null;
|
|
345
|
-
await instance.load({ filename: DEFAULT_FILE_VIEWER_SOURCE_FILENAME });
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
async reload() {
|
|
349
|
-
if (disposed)
|
|
350
|
-
return;
|
|
351
|
-
if (currentSource) {
|
|
352
|
-
await loadSource(currentSource);
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
destroy() {
|
|
356
|
-
if (disposed)
|
|
357
|
-
return;
|
|
358
|
-
disposed = true;
|
|
359
|
-
cancel();
|
|
360
|
-
void instance.destroy('component-unmount');
|
|
361
|
-
container.innerHTML = '';
|
|
362
|
-
},
|
|
363
|
-
getApi() {
|
|
364
|
-
return instance;
|
|
365
|
-
},
|
|
366
|
-
downloadOriginalFile() {
|
|
367
|
-
return callApi(instance, api => api.download(), undefined);
|
|
368
|
-
},
|
|
369
|
-
printRenderedHtml(options) {
|
|
370
|
-
return callApi(instance, api => api.print(options), undefined);
|
|
371
|
-
},
|
|
372
|
-
printWithMask(options) {
|
|
373
|
-
return callApi(instance, api => api.printWithMask(options), undefined);
|
|
374
|
-
},
|
|
375
|
-
exportRenderedHtml() {
|
|
376
|
-
return callApi(instance, api => api.exportHtml({ download: true }).then(() => undefined), undefined);
|
|
377
|
-
},
|
|
378
|
-
zoomIn() {
|
|
379
|
-
return callApi(instance, api => api.zoomIn(), null);
|
|
380
|
-
},
|
|
381
|
-
zoomOut() {
|
|
382
|
-
return callApi(instance, api => api.zoomOut(), null);
|
|
383
|
-
},
|
|
384
|
-
resetZoom() {
|
|
385
|
-
return callApi(instance, api => api.resetZoom(), null);
|
|
386
|
-
},
|
|
387
|
-
fitToView(fit) {
|
|
388
|
-
return callApi(instance, api => api.fitToView(fit), null);
|
|
389
|
-
},
|
|
390
|
-
searchDocument(query) {
|
|
391
|
-
return callApi(instance, api => api.search(query), null);
|
|
392
|
-
},
|
|
393
|
-
clearDocumentSearch() {
|
|
394
|
-
return callApi(instance, api => api.clearSearch(), null);
|
|
395
|
-
},
|
|
396
|
-
nextSearchResult() {
|
|
397
|
-
return callApi(instance, api => api.nextSearchResult(), null);
|
|
398
|
-
},
|
|
399
|
-
previousSearchResult() {
|
|
400
|
-
return callApi(instance, api => api.previousSearchResult(), null);
|
|
401
|
-
},
|
|
402
|
-
collectDocumentAnchors() {
|
|
403
|
-
return callApi(instance, api => api.collectDocumentAnchors(), []);
|
|
404
|
-
},
|
|
405
|
-
scrollToAnchor(anchor) {
|
|
406
|
-
return callApi(instance, api => api.scrollToDocumentAnchor(anchor), false);
|
|
407
|
-
},
|
|
408
|
-
scrollToLine(line) {
|
|
409
|
-
return callApi(instance, api => api.scrollToLine(line), false);
|
|
410
|
-
},
|
|
411
|
-
getDocumentTextChunks() {
|
|
412
|
-
return instance.getDocumentTextChunks();
|
|
413
|
-
},
|
|
414
|
-
getOperationAvailability() {
|
|
415
|
-
return instance.getCapabilities();
|
|
416
|
-
},
|
|
417
|
-
getZoomState() {
|
|
418
|
-
return instance.getZoomState();
|
|
419
|
-
},
|
|
420
|
-
getSearchState() {
|
|
421
|
-
return instance.getSearchState();
|
|
422
|
-
},
|
|
423
|
-
getState() {
|
|
424
|
-
return snapshotState();
|
|
425
|
-
},
|
|
426
|
-
subscribe(listener) {
|
|
427
|
-
listeners.add(listener);
|
|
428
|
-
listener(snapshotState());
|
|
429
|
-
return () => {
|
|
430
|
-
listeners.delete(listener);
|
|
431
|
-
};
|
|
432
|
-
},
|
|
433
|
-
};
|
|
434
|
-
return controller;
|
|
435
|
-
};
|
|
1
|
+
// Local public entry; the framework-neutral browser shell lives in core.
|
|
2
|
+
export * from '@file-viewer/core/browser';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HTMLAttributes, type MutableRefObject } from 'react';
|
|
2
2
|
import { type ViewerControllerHandle, type ViewerMountOptions, type ViewerEventHandler, type ViewerState } from './controller.js';
|
|
3
|
-
export type { FileRef, ViewerAiOptions, ViewerArchiveOptions, ViewerCadOptions, ViewerController, ViewerControllerAccessor, ViewerControllerHandle, ViewerDocxOptions, ViewerEvent, ViewerEventHandler, ViewerEventType, ViewerFetchFile, ViewerFetchInput, ViewerMountOptions, ViewerOptions, ViewerPdfOptions, ViewerSpreadsheetOptions, ViewerSearchOptions, ViewerSourceInput, ViewerThemeMode, ViewerToolbarOptions, ViewerToolbarPosition, ViewerTypstOptions, ViewerWatermarkOptions, ViewerLifecycleContext, ViewerOperationContext, ViewerState, ViewerStateListener } from './controller.js';
|
|
3
|
+
export type { FileRef, ViewerAiOptions, ViewerApplyViewStateOptions, ViewerArchiveOptions, ViewerCadOptions, ViewerController, ViewerControllerAccessor, ViewerControllerHandle, ViewerDocxOptions, ViewerEvent, ViewerEventHandler, ViewerEventType, ViewerFetchFile, ViewerFetchInput, ViewerFitMode, ViewerFitOptions, ViewerFitResult, ViewerMountOptions, ViewerOptions, ViewerPdfOptions, ViewerPresentationOptions, ViewerSpreadsheetOptions, ViewerCoreOptions, ViewerSearchOptions, ViewerSourceInput, ViewerThemeMode, ViewerToolbarOptions, ViewerToolbarPosition, ViewerTypstOptions, ViewerUiDensity, ViewerUiOptions, ViewerViewState, ViewerWatermarkOptions, ViewerLifecycleContext, ViewerOperationContext, ViewerState, ViewerStateListener } from './controller.js';
|
|
4
4
|
export interface FileViewerHandle extends ViewerControllerHandle {
|
|
5
5
|
}
|
|
6
6
|
export interface FileViewerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'>, ViewerMountOptions {
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,8 @@ const createInitialViewerState = () => ({
|
|
|
19
19
|
availability: null,
|
|
20
20
|
search: null,
|
|
21
21
|
zoom: null,
|
|
22
|
-
location: null
|
|
22
|
+
location: null,
|
|
23
|
+
viewState: null
|
|
23
24
|
});
|
|
24
25
|
const destroyController = (controllerRef, container) => {
|
|
25
26
|
var _a;
|
|
@@ -33,6 +34,7 @@ export const FileViewer = forwardRef((props, forwardedRef) => {
|
|
|
33
34
|
const { url, file, buffer, name, filename, type, size, options, onEvent, onStateChange, style, ...containerProps } = props;
|
|
34
35
|
const containerRef = useRef(null);
|
|
35
36
|
const controllerRef = useRef(null);
|
|
37
|
+
const appliedViewerOptionsRef = useRef(null);
|
|
36
38
|
const viewerOptions = useMemo(() => ({
|
|
37
39
|
url,
|
|
38
40
|
file,
|
|
@@ -50,11 +52,19 @@ export const FileViewer = forwardRef((props, forwardedRef) => {
|
|
|
50
52
|
if (!container || controllerRef.current) {
|
|
51
53
|
return undefined;
|
|
52
54
|
}
|
|
55
|
+
appliedViewerOptionsRef.current = viewerOptions;
|
|
53
56
|
controllerRef.current = mountViewer(container, viewerOptions, viewerCoreOptions);
|
|
54
|
-
return () =>
|
|
57
|
+
return () => {
|
|
58
|
+
appliedViewerOptionsRef.current = null;
|
|
59
|
+
destroyController(controllerRef, container);
|
|
60
|
+
};
|
|
55
61
|
}, []);
|
|
56
62
|
useEffect(() => {
|
|
57
63
|
var _a;
|
|
64
|
+
if (appliedViewerOptionsRef.current === viewerOptions) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
appliedViewerOptionsRef.current = viewerOptions;
|
|
58
68
|
void ((_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.update(viewerOptions));
|
|
59
69
|
}, [viewerOptions]);
|
|
60
70
|
useImperativeHandle(forwardedRef, () => createViewerControllerHandle(() => controllerRef.current, () => destroyController(controllerRef, containerRef.current)), []);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/react",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "Standard React component package for
|
|
6
|
+
"description": "Standard React component package for File Viewer",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"file-viewer",
|
|
9
9
|
"document-preview",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"registry": "https://registry.npmjs.org/"
|
|
20
20
|
},
|
|
21
21
|
"author": {
|
|
22
|
-
"name": "
|
|
23
|
-
"email": "
|
|
22
|
+
"name": "Yu Wang",
|
|
23
|
+
"email": "admin@flyfish.dev"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"react": ">=17 <20"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "2.2.
|
|
58
|
+
"@file-viewer/core": "2.2.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.2.17",
|