@file-viewer/web 2.1.12 → 2.1.14
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 +9 -5
- package/README.md +9 -5
- package/dist/controller.d.ts +9 -1
- package/dist/controller.js +53 -11
- package/dist/element.d.ts +2 -0
- package/dist/element.js +8 -0
- package/dist/flyfish-file-viewer-web.iife.js +14 -13
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
- package/viewer/flyfish-viewer-manifest.json +1 -1
- package/viewer/vendor/docx/docx.worker.js +1 -1
package/README.en.md
CHANGED
|
@@ -234,7 +234,7 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
234
234
|
| Component | Actual props / entry | Event channel | Customization entry |
|
|
235
235
|
| --- | --- | --- | --- |
|
|
236
236
|
| 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. |
|
|
237
|
-
| 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. |
|
|
237
|
+
| 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`, `view-state-change` | Template refs expose `FileViewerExpose`. For `Blob` / `ArrayBuffer`, prefer wrapping it as a named `File` so extension detection stays deterministic. |
|
|
238
238
|
| 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. |
|
|
239
239
|
| 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. |
|
|
240
240
|
| 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. |
|
|
@@ -251,7 +251,7 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
251
251
|
| `ai` | Text collection, chunk size, and max text length for provenance, location, vectorization, and external AI workflows. |
|
|
252
252
|
| `archive` | Archive Worker/WASM URLs, timeout, cache, archive limits, and nested entry preview limits. |
|
|
253
253
|
| `pdf` | PDF.js worker, navigation pane, outline, thumbnails, rotation, streaming, range chunk size, and credentials. |
|
|
254
|
-
| `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
|
|
254
|
+
| `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. |
|
|
255
255
|
| `typst` / `data` / `cad` | Typst, SQLite, CAD/DWG/DXF/DWF WASM, worker, encoding, and rendering strategy options. |
|
|
256
256
|
| `hooks` / `beforeOperation` | Shared lifecycle hooks and operation preflight checks for audit, permission, telemetry, and safety controls. |
|
|
257
257
|
|
|
@@ -268,6 +268,10 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
268
268
|
|
|
269
269
|
For fully custom toolbars, hide the built-in toolbar and call the standard ref / controller APIs from your own UI. Do not implement zoom with an outer CSS `transform: scale()`; PDF, Excel, CAD, canvas-based, and text-layer renderers should use their internal zoom providers to keep coordinates correct.
|
|
270
270
|
|
|
271
|
+
Zoom state is reported by each renderer provider. After first-screen fit, container resize, or asynchronous PDF / Word / image layout, built-in toolbars show the real scale instead of assuming `100%`. Custom toolbars should listen to `zoom-change` / `operation-availability-change`, or read `getZoomState()` / `getOperationAvailability()`.
|
|
272
|
+
|
|
273
|
+
View-state sync is designed for projection systems, remote-control displays, side-by-side review, and reading-position restore. Every standard renderer loader gets a generic view-state provider that records at least `renderer`, zoom, and scroll position; PDF, XMind, Geo, 3D, and CAD add page, navigation, canvas pan, map center, camera, or native view snapshots. Pass `options.initialViewState` for first render, listen to `view-state-change` while running, and use `getViewState()` / `applyViewState(state, { source: "api", action: "restore" })` on Pure Web / Vue3 controllers when an imperative restore API is needed.
|
|
274
|
+
|
|
271
275
|
| Ecosystem | Recommended pattern |
|
|
272
276
|
| --- | --- |
|
|
273
277
|
| 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. |
|
|
@@ -287,7 +291,7 @@ For fully custom toolbars, hide the built-in toolbar and call the standard ref /
|
|
|
287
291
|
| `unload-complete` / `hooks.onUnloadComplete` | Fires after the previous document is released. The reason is `replace`, `reset`, or `component-unmount`. |
|
|
288
292
|
| `operation-before` / `operation-cancel` | Fires around download, print, HTML export, and zoom actions. Returning `false` from `beforeOperation` cancels the action. |
|
|
289
293
|
| `operation-availability-change` | Fires when download, print, HTML export, or zoom support changes for the active format. |
|
|
290
|
-
| `search-change` / `location-change` / `zoom-change` | Fires when search matches, document anchors, or
|
|
294
|
+
| `search-change` / `location-change` / `zoom-change` / `view-state-change` | Fires when search matches, document anchors, zoom state, or full view-state snapshots change so host UIs, display screens, and reading-position restore flows can stay in sync. |
|
|
291
295
|
|
|
292
296
|
## Public Operation API
|
|
293
297
|
|
|
@@ -309,10 +313,10 @@ For fully custom toolbars, hide the built-in toolbar and call the standard ref /
|
|
|
309
313
|
| --- | --- |
|
|
310
314
|
| Shared viewer assets | The Pure Web package ships `file-viewer-copy-assets` to copy workers, WASM, vendor files, and examples into your static directory. |
|
|
311
315
|
| CAD / DWG / DXF / DWF | Configure `options.cad.wasmPath`, `workerUrl`, `dwfWasmUrl`, and `dxfEncoding` for self-hosted or intranet deployment. |
|
|
312
|
-
| PDF / DOCX / Excel | Configure `options.pdf.workerUrl`, `options.pdf.cMapUrl`, `options.pdf.wasmUrl`, `options.pdf.standardFontDataUrl`, `options.docx.workerUrl`, `options.docx.workerJsZipUrl`, and `options.
|
|
316
|
+
| PDF / DOCX / Excel / PPTX | Configure `options.pdf.workerUrl`, `options.pdf.cMapUrl`, `options.pdf.wasmUrl`, `options.pdf.standardFontDataUrl`, `options.docx.workerUrl`, `options.docx.workerJsZipUrl`, `options.spreadsheet.workerUrl`, and `options.presentation.workerUrl` / `options.presentation.workerType`; PDF probes the real static worker first and lazy-loads the packaged handler when unavailable; 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`, and header drag column resizing is controlled by `options.spreadsheet.resizableColumns`; PPTX creates a module Worker on demand and can pin the worker URL/type for strict CSP, legacy WebViews, or self-hosted CDNs. |
|
|
313
317
|
| 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. |
|
|
314
318
|
| 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. |
|
|
315
|
-
| 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. |
|
|
319
|
+
| 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, PPTX worker, and Office worker/vendor assets. |
|
|
316
320
|
| Deployment principle | Heavy workers, WASM files, and parser libraries stay lazy-loaded and are only requested when the active file type needs them. |
|
|
317
321
|
|
|
318
322
|
## Quality Gates
|
package/README.md
CHANGED
|
@@ -234,7 +234,7 @@ const options = {
|
|
|
234
234
|
| 组件 | 实际属性 / 入口 | 事件入口 | 定制入口 |
|
|
235
235
|
| --- | --- | --- | --- |
|
|
236
236
|
| 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。 |
|
|
237
|
-
| 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`。 |
|
|
237
|
+
| 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`、`view-state-change` | 模板 `ref` 暴露 `FileViewerExpose`;适合声明式接入。`Blob` / `ArrayBuffer` 建议包装成带扩展名的 `File` 后传给 `file`。 |
|
|
238
238
|
| 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` 平滑升级。 |
|
|
239
239
|
| Vue 2.6 `@file-viewer/vue2.6` | 同 Vue 2.7 | `viewer-event` / `viewerEvent` | 独立 Vue 2.6 构建,不要求业务升级到 Vue 2.7。 |
|
|
240
240
|
| React `@file-viewer/react` | `ViewerMountOptions` + `div` 原生属性,如 `className`、`style`、`data-*`、`aria-*` | `onEvent`、`onStateChange` | `ref` 暴露 `FileViewerHandle`;`useFileViewer()` 会返回 `ref`、`props`、`state`、`handle`,便于自定义工具栏。 |
|
|
@@ -251,7 +251,7 @@ const options = {
|
|
|
251
251
|
| `ai` | 控制文本结构采集、分块大小和最大文本长度,为溯源、定位、向量化和外部 AI 流程提供基础。 |
|
|
252
252
|
| `archive` | 配置压缩包 Worker/WASM、超时、缓存、包体限制和压缩包内单文件预览大小。 |
|
|
253
253
|
| `pdf` | 配置 PDF.js Worker、导航栏、目录、缩略图、旋转、流式读取、Range chunk 和凭据。 |
|
|
254
|
-
| `docx` / `spreadsheet` | DOCX 由 @file-viewer/renderer-word 承接并使用自研 @file-viewer/docx,默认自动选择 Worker 或主线程解析,连续流式阅读和异步分批渲染,可按需显式开启视觉分页;表格由 @file-viewer/renderer-spreadsheet
|
|
254
|
+
| `docx` / `spreadsheet` | DOCX 由 @file-viewer/renderer-word 承接并使用自研 @file-viewer/docx,默认自动选择 Worker 或主线程解析,连续流式阅读和异步分批渲染,可按需显式开启视觉分页;表格由 @file-viewer/renderer-spreadsheet 承接,默认保真解析,大文件自动启用 Worker,表头拖拽调列宽可按需显式开启。 |
|
|
255
255
|
| `typst` / `data` / `cad` | 配置 Typst、SQLite、CAD/DWG/DXF/DWF 等 WASM、Worker、编码和渲染策略。 |
|
|
256
256
|
| `hooks` / `beforeOperation` | 统一生命周期 hooks 和操作前置校验,可用于审计、权限、埋点和安全控制。 |
|
|
257
257
|
|
|
@@ -268,6 +268,10 @@ const options = {
|
|
|
268
268
|
|
|
269
269
|
完全自定义工具栏时,推荐关闭内置工具栏并使用组件 ref / controller 暴露的标准 API。不要在预览器外层用 CSS `transform: scale()` 做缩放;PDF、Excel、CAD、canvas 和文本层格式都应通过内部缩放 provider 保持坐标正确。
|
|
270
270
|
|
|
271
|
+
缩放状态由各格式 renderer 的内部 provider 上报。首屏自适应、容器尺寸变化或 PDF / Word / 图片等异步布局完成后,内置工具栏会显示真实缩放比例,而不是固定显示 `100%`;自定义工具栏也应监听 `zoom-change` / `operation-availability-change`,或读取 `getZoomState()` / `getOperationAvailability()`。
|
|
272
|
+
|
|
273
|
+
视图状态同步用于投屏、双端协同和恢复阅读进度。所有标准 renderer loader 都会获得通用 view-state provider,至少记录 `renderer`、缩放和滚动位置;PDF、XMind、Geo、3D、CAD 等高交互路径会补充页码、导航、画布 pan、地图中心、相机视角或底层视图快照。初始化可传 `options.initialViewState`,运行中监听 `view-state-change`;Pure Web / Vue3 controller 还可直接调用 `getViewState()` 与 `applyViewState(state, { source: "api", action: "restore" })`。
|
|
274
|
+
|
|
271
275
|
| 生态 | 推荐方式 |
|
|
272
276
|
| --- | --- |
|
|
273
277
|
| 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()` 同步状态。 |
|
|
@@ -287,7 +291,7 @@ const options = {
|
|
|
287
291
|
| `unload-complete` / `hooks.onUnloadComplete` | 旧文档释放完成后触发,reason 会标识 `replace`、`reset` 或 `component-unmount`。 |
|
|
288
292
|
| `operation-before` / `operation-cancel` | 下载、打印、HTML 导出和缩放前后触发;`beforeOperation` 返回 `false` 可取消操作。 |
|
|
289
293
|
| `operation-availability-change` | 当前格式是否可下载、可打印、可导出 HTML、可缩放发生变化时触发。 |
|
|
290
|
-
| `search-change` / `location-change` / `zoom-change` |
|
|
294
|
+
| `search-change` / `location-change` / `zoom-change` / `view-state-change` | 搜索命中、定位锚点、缩放状态和完整视图快照变化时触发,用于外层同步 UI、投屏或恢复阅读进度。 |
|
|
291
295
|
|
|
292
296
|
## 公共操作 API
|
|
293
297
|
|
|
@@ -309,10 +313,10 @@ const options = {
|
|
|
309
313
|
| --- | --- |
|
|
310
314
|
| 通用 viewer assets | Pure Web 包提供 `file-viewer-copy-assets`,可把 Worker、WASM、vendor 和示例资源复制到业务静态目录。 |
|
|
311
315
|
| CAD / DWG / DXF / DWF | 按需配置 `options.cad.wasmPath`、`workerUrl`、`dwfWasmUrl`、`dxfEncoding`,支持自托管和内网部署。 |
|
|
312
|
-
| PDF / DOCX / Excel | 按需配置 `options.pdf.workerUrl`、`options.pdf.cMapUrl`、`options.pdf.wasmUrl`、`options.pdf.standardFontDataUrl`、`options.docx.workerUrl`、`options.docx.workerJsZipUrl`、`options.spreadsheet.workerUrl`;PDF 默认探测真实静态 Worker,不可用时懒加载包内 handler 兜底;DOCX 默认自动选择 Worker 或主线程解析,Electron `file://`
|
|
316
|
+
| PDF / DOCX / Excel / PPTX | 按需配置 `options.pdf.workerUrl`、`options.pdf.cMapUrl`、`options.pdf.wasmUrl`、`options.pdf.standardFontDataUrl`、`options.docx.workerUrl`、`options.docx.workerJsZipUrl`、`options.spreadsheet.workerUrl`、`options.presentation.workerUrl` / `options.presentation.workerType`;PDF 默认探测真实静态 Worker,不可用时懒加载包内 handler 兜底;DOCX 默认自动选择 Worker 或主线程解析,Electron `file://` 等本地不安全协议会自动回退;Excel 默认 `worker: auto`,大文件达到 `workerAutoThreshold` 自动启用 Worker,列宽拖拽可通过 `options.spreadsheet.resizableColumns` 显式开启;PPTX 默认按需创建模块 Worker,严格 CSP、旧 WebView 或自托管 CDN 场景可固定 Worker 地址。 |
|
|
313
317
|
| Typst / SQLite / Archive | 按需配置 Typst compiler/renderer WASM、`data.sqlWasmUrl`、`archive.workerUrl` / `archive.wasmUrl`;Typst 仅使用本地 WASM 真实渲染,不访问公共 CDN。 |
|
|
314
318
|
| Drawing | Draw.io 默认使用随 viewer assets 分发的官方 diagrams.net 离线 viewer;路径特殊时可通过 `options.drawing.viewerScriptUrl` 覆盖,`preferOfficial:false` 才切到内置 SVG 兜底。 |
|
|
315
|
-
| 离线部署 | 运行时不依赖公共 CDN 或第三方在线资源;`file-viewer-copy-assets` 会复制 PDF、CAD、Typst、SQLite、压缩包、Draw.io、DOCX worker/JSZip 和 Office worker/vendor 资产。 |
|
|
319
|
+
| 离线部署 | 运行时不依赖公共 CDN 或第三方在线资源;`file-viewer-copy-assets` 会复制 PDF、CAD、Typst、SQLite、压缩包、Draw.io、DOCX worker/JSZip、PPTX worker 和 Office worker/vendor 资产。 |
|
|
316
320
|
| 部署原则 | 默认只在命中特定格式时异步加载对应依赖;没有命中的格式不会拉取重型 Worker、WASM 或解析库。 |
|
|
317
321
|
|
|
318
322
|
## 质量门禁
|
package/dist/controller.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { type FileViewerAiOptions, type FileViewerArchiveOptions, type FileViewerCadOptions, type FileViewerDocxOptions, type FileViewerDocumentAnchor, type FileViewerDocumentChunk, type FileViewerEvent, type FileViewerEventHandler, type FileViewerEventType, type FileViewerFileRef, type FileViewerInstance, type FileViewerLifecycleContext, type FileViewerOperationAvailability, type FileViewerOperationContext, type FileViewerOptions, type FileViewerPdfOptions, type FileViewerSpreadsheetOptions, type FileViewerPublicApi, type FileViewerSearchOptions, type FileViewerSearchState, type FileViewerThemeMode, type FileViewerToolbarOptions, type FileViewerToolbarPosition, type FileViewerTypstOptions, type FileViewerWatermarkOptions, type FileViewerZoomState, type RendererRegistry } from '@file-viewer/core';
|
|
1
|
+
import { type FileViewerAiOptions, type FileViewerApplyViewStateOptions, type FileViewerArchiveOptions, type FileViewerCadOptions, type FileViewerDocxOptions, type FileViewerDocumentAnchor, type FileViewerDocumentChunk, type FileViewerEvent, type FileViewerEventHandler, type FileViewerEventType, type FileViewerFileRef, type FileViewerInstance, type FileViewerLifecycleContext, type FileViewerOperationAvailability, type FileViewerOperationContext, type FileViewerOptions, type FileViewerPdfOptions, type FileViewerPresentationOptions, type FileViewerSpreadsheetOptions, type FileViewerPublicApi, type FileViewerSearchOptions, type FileViewerSearchState, type FileViewerThemeMode, type FileViewerToolbarOptions, type FileViewerToolbarPosition, type FileViewerTypstOptions, type FileViewerViewState, type FileViewerWatermarkOptions, type FileViewerZoomState, type RendererRegistry } from '@file-viewer/core';
|
|
2
2
|
export type FileRef = FileViewerFileRef;
|
|
3
3
|
export type ViewerWatermarkOptions = FileViewerWatermarkOptions;
|
|
4
4
|
export type ViewerToolbarPosition = FileViewerToolbarPosition;
|
|
5
5
|
export type ViewerToolbarOptions = FileViewerToolbarOptions;
|
|
6
6
|
export type ViewerArchiveOptions = FileViewerArchiveOptions;
|
|
7
7
|
export type ViewerPdfOptions = FileViewerPdfOptions;
|
|
8
|
+
export type ViewerPresentationOptions = FileViewerPresentationOptions;
|
|
8
9
|
export type ViewerSpreadsheetOptions = FileViewerSpreadsheetOptions;
|
|
9
10
|
export type ViewerDocxOptions = FileViewerDocxOptions;
|
|
10
11
|
export type ViewerTypstOptions = FileViewerTypstOptions;
|
|
11
12
|
export type ViewerCadOptions = FileViewerCadOptions;
|
|
12
13
|
export type ViewerSearchOptions = FileViewerSearchOptions;
|
|
13
14
|
export type ViewerAiOptions = FileViewerAiOptions;
|
|
15
|
+
export type ViewerViewState = FileViewerViewState;
|
|
16
|
+
export type ViewerApplyViewStateOptions = FileViewerApplyViewStateOptions;
|
|
14
17
|
export type ViewerThemeMode = FileViewerThemeMode;
|
|
15
18
|
export type ViewerOptions = FileViewerOptions;
|
|
16
19
|
export type ViewerEventType = FileViewerEventType;
|
|
@@ -28,6 +31,7 @@ export interface ViewerState {
|
|
|
28
31
|
search: FileViewerSearchState | null;
|
|
29
32
|
zoom: FileViewerZoomState | null;
|
|
30
33
|
location: FileViewerDocumentAnchor | null;
|
|
34
|
+
viewState: FileViewerViewState | null;
|
|
31
35
|
}
|
|
32
36
|
export type ViewerStateListener = (state: ViewerState, event?: ViewerEvent) => void;
|
|
33
37
|
export interface ViewerMountOptions {
|
|
@@ -75,6 +79,8 @@ export interface ViewerController {
|
|
|
75
79
|
zoomIn(): Promise<FileViewerZoomState | null>;
|
|
76
80
|
zoomOut(): Promise<FileViewerZoomState | null>;
|
|
77
81
|
resetZoom(): Promise<FileViewerZoomState | null>;
|
|
82
|
+
getViewState(): FileViewerViewState | null;
|
|
83
|
+
applyViewState(state: FileViewerViewState, options?: FileViewerApplyViewStateOptions): Promise<FileViewerViewState | null>;
|
|
78
84
|
searchDocument(query: string): Promise<FileViewerSearchState | null>;
|
|
79
85
|
clearDocumentSearch(): Promise<FileViewerSearchState | null>;
|
|
80
86
|
nextSearchResult(): Promise<FileViewerSearchState | null>;
|
|
@@ -103,6 +109,8 @@ export interface ViewerControllerHandle {
|
|
|
103
109
|
zoomIn(): Promise<FileViewerZoomState | null>;
|
|
104
110
|
zoomOut(): Promise<FileViewerZoomState | null>;
|
|
105
111
|
resetZoom(): Promise<FileViewerZoomState | null>;
|
|
112
|
+
getViewState(): FileViewerViewState | null;
|
|
113
|
+
applyViewState(state: FileViewerViewState, options?: FileViewerApplyViewStateOptions): Promise<FileViewerViewState | null>;
|
|
106
114
|
searchDocument(query: string): Promise<FileViewerSearchState | null>;
|
|
107
115
|
clearDocumentSearch(): Promise<FileViewerSearchState | null>;
|
|
108
116
|
nextSearchResult(): Promise<FileViewerSearchState | null>;
|
package/dist/controller.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createViewer } from '@file-viewer/core';
|
|
1
|
+
import { applyFileViewerZoomAvailability, createViewer } from '@file-viewer/core';
|
|
2
2
|
import { DEFAULT_FILE_VIEWER_SOURCE_FILENAME, createFileViewerTranslator, getExtension, hasVisibleFileViewerToolbarActions, isFileViewerZoomButtonDisabled, normalizeFileViewerToolbar, normalizeFilename, readFileViewerBuffer, resolveFileViewerSourceFilename, resolveFileViewerToolbarPosition, resolveVisibleFileViewerToolbar, wrapFileViewerFileRef, } from '@file-viewer/core';
|
|
3
3
|
const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
4
4
|
const hasSource = (options = {}) => {
|
|
@@ -124,6 +124,14 @@ export const createViewerControllerHandle = (getController, dispose) => ({
|
|
|
124
124
|
var _a, _b;
|
|
125
125
|
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.resetZoom()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
126
126
|
},
|
|
127
|
+
getViewState() {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getViewState()) !== null && _b !== void 0 ? _b : null;
|
|
130
|
+
},
|
|
131
|
+
applyViewState(state, options) {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.applyViewState(state, options)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
134
|
+
},
|
|
127
135
|
searchDocument(query) {
|
|
128
136
|
var _a, _b;
|
|
129
137
|
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.searchDocument(query)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
@@ -213,10 +221,11 @@ const WEB_VIEWER_STYLE = `
|
|
|
213
221
|
.file-viewer-web-toolbar button:hover:not(:disabled){background:rgba(33,163,102,.1);color:#16774c}
|
|
214
222
|
.file-viewer-web-toolbar button:disabled{color:#aab5c0;cursor:not-allowed}
|
|
215
223
|
.file-viewer-web-toolbar .file-viewer-web-icon-button{width:30px;min-width:30px;padding:0;display:inline-flex;align-items:center;justify-content:center}
|
|
216
|
-
.file-viewer-web-toolbar .file-viewer-web-zoom-meter{min-width:48px;padding:0 8px;color:#23465e}
|
|
224
|
+
.file-viewer-web-toolbar .file-viewer-web-zoom-meter{min-width:48px;height:30px;padding:0 8px;display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;color:#23465e}
|
|
225
|
+
.file-viewer-web-toolbar .file-viewer-web-zoom-meter--readonly{font-size:12px;font-weight:800;line-height:1;white-space:nowrap}
|
|
217
226
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] button{min-width:48px;height:32px;border-radius:999px}
|
|
218
227
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-icon-button{width:32px;min-width:32px}
|
|
219
|
-
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-zoom-meter{min-width:54px}
|
|
228
|
+
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-zoom-meter{min-width:54px;height:32px}
|
|
220
229
|
.file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}
|
|
221
230
|
.file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-toolbar button{color:#d7dee8}
|
|
222
231
|
@media (prefers-color-scheme:dark){.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar{border-color:rgba(148,163,184,.18);background:rgba(15,23,42,.9)}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-toolbar button{color:#d7dee8}}
|
|
@@ -233,6 +242,14 @@ const createButton = (documentRef, label, className, onClick) => {
|
|
|
233
242
|
});
|
|
234
243
|
return button;
|
|
235
244
|
};
|
|
245
|
+
const createReadonlyMeter = (documentRef, label, className) => {
|
|
246
|
+
const meter = documentRef.createElement('span');
|
|
247
|
+
meter.className = `${className} file-viewer-web-zoom-meter--readonly`;
|
|
248
|
+
meter.textContent = label;
|
|
249
|
+
meter.title = label;
|
|
250
|
+
meter.setAttribute('aria-label', label);
|
|
251
|
+
return meter;
|
|
252
|
+
};
|
|
236
253
|
export const mountViewer = (container, initialOptions = {}, coreOptions = {}) => {
|
|
237
254
|
if (!isBrowser()) {
|
|
238
255
|
throw new Error('Flyfish File Viewer can only be mounted in a browser DOM environment.');
|
|
@@ -265,13 +282,8 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
265
282
|
search: null,
|
|
266
283
|
zoom: null,
|
|
267
284
|
location: null,
|
|
285
|
+
viewState: null,
|
|
268
286
|
};
|
|
269
|
-
const snapshotState = () => ({
|
|
270
|
-
...state,
|
|
271
|
-
search: state.search
|
|
272
|
-
? { ...state.search, matches: [...state.search.matches] }
|
|
273
|
-
: null,
|
|
274
|
-
});
|
|
275
287
|
const getCurrentExtension = () => {
|
|
276
288
|
var _a;
|
|
277
289
|
if ((_a = state.lifecycle) === null || _a === void 0 ? void 0 : _a.type) {
|
|
@@ -281,7 +293,25 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
281
293
|
};
|
|
282
294
|
let instance;
|
|
283
295
|
const getToolbarZoomState = () => state.zoom || instance.getZoomState() || DEFAULT_TOOLBAR_ZOOM_STATE;
|
|
284
|
-
const getToolbarAvailability = () => state.availability || instance.getCapabilities() || DEFAULT_TOOLBAR_AVAILABILITY;
|
|
296
|
+
const getToolbarAvailability = () => applyFileViewerZoomAvailability(state.availability || instance.getCapabilities() || DEFAULT_TOOLBAR_AVAILABILITY, getToolbarZoomState());
|
|
297
|
+
const snapshotState = () => ({
|
|
298
|
+
...state,
|
|
299
|
+
availability: getToolbarAvailability(),
|
|
300
|
+
search: state.search
|
|
301
|
+
? { ...state.search, matches: [...state.search.matches] }
|
|
302
|
+
: null,
|
|
303
|
+
zoom: state.zoom ? { ...state.zoom } : null,
|
|
304
|
+
location: state.location ? { ...state.location } : null,
|
|
305
|
+
viewState: state.viewState
|
|
306
|
+
? {
|
|
307
|
+
...state.viewState,
|
|
308
|
+
zoom: state.viewState.zoom ? { ...state.viewState.zoom } : undefined,
|
|
309
|
+
scroll: state.viewState.scroll ? { ...state.viewState.scroll } : undefined,
|
|
310
|
+
navigation: state.viewState.navigation ? { ...state.viewState.navigation } : undefined,
|
|
311
|
+
extra: state.viewState.extra ? { ...state.viewState.extra } : undefined,
|
|
312
|
+
}
|
|
313
|
+
: null,
|
|
314
|
+
});
|
|
285
315
|
const syncShellTheme = () => {
|
|
286
316
|
var _a;
|
|
287
317
|
shell.dataset.viewerTheme = ((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme) || 'light';
|
|
@@ -334,6 +364,9 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
334
364
|
});
|
|
335
365
|
group.appendChild(meter);
|
|
336
366
|
}
|
|
367
|
+
else {
|
|
368
|
+
group.appendChild(createReadonlyMeter(documentRef, zoomState.label, 'file-viewer-web-zoom-meter'));
|
|
369
|
+
}
|
|
337
370
|
if (availability.zoomIn) {
|
|
338
371
|
const button = createButton(documentRef, '+', 'file-viewer-web-icon-button', () => controller === null || controller === void 0 ? void 0 : controller.zoomIn());
|
|
339
372
|
button.title = t('toolbar.zoomIn');
|
|
@@ -424,6 +457,9 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
424
457
|
else if (event.type === 'zoom-change') {
|
|
425
458
|
state.zoom = event.payload;
|
|
426
459
|
}
|
|
460
|
+
else if (event.type === 'view-state-change') {
|
|
461
|
+
state.viewState = event.payload.state;
|
|
462
|
+
}
|
|
427
463
|
(_a = currentOptions.onEvent) === null || _a === void 0 ? void 0 : _a.call(currentOptions, event);
|
|
428
464
|
notifyState(event);
|
|
429
465
|
};
|
|
@@ -540,6 +576,12 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
540
576
|
resetZoom() {
|
|
541
577
|
return callApi(instance, api => api.resetZoom(), null);
|
|
542
578
|
},
|
|
579
|
+
getViewState() {
|
|
580
|
+
return instance.getViewState();
|
|
581
|
+
},
|
|
582
|
+
applyViewState(state, options) {
|
|
583
|
+
return callApi(instance, api => api.applyViewState(state, options), null);
|
|
584
|
+
},
|
|
543
585
|
searchDocument(query) {
|
|
544
586
|
return callApi(instance, api => api.search(query), null);
|
|
545
587
|
},
|
|
@@ -565,7 +607,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
565
607
|
return instance.getDocumentTextChunks();
|
|
566
608
|
},
|
|
567
609
|
getOperationAvailability() {
|
|
568
|
-
return
|
|
610
|
+
return getToolbarAvailability();
|
|
569
611
|
},
|
|
570
612
|
getZoomState() {
|
|
571
613
|
return instance.getZoomState();
|
package/dist/element.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export declare class FileViewerElement extends ElementBase implements ViewerCont
|
|
|
63
63
|
zoomIn(): ReturnType<ViewerControllerHandle['zoomIn']>;
|
|
64
64
|
zoomOut(): ReturnType<ViewerControllerHandle['zoomOut']>;
|
|
65
65
|
resetZoom(): ReturnType<ViewerControllerHandle['resetZoom']>;
|
|
66
|
+
getViewState(): ReturnType<ViewerControllerHandle['getViewState']>;
|
|
67
|
+
applyViewState(state: Parameters<ViewerControllerHandle['applyViewState']>[0], options?: Parameters<ViewerControllerHandle['applyViewState']>[1]): ReturnType<ViewerControllerHandle['applyViewState']>;
|
|
66
68
|
searchDocument(query: string): ReturnType<ViewerControllerHandle['searchDocument']>;
|
|
67
69
|
clearDocumentSearch(): ReturnType<ViewerControllerHandle['clearDocumentSearch']>;
|
|
68
70
|
nextSearchResult(): ReturnType<ViewerControllerHandle['nextSearchResult']>;
|
package/dist/element.js
CHANGED
|
@@ -246,6 +246,14 @@ export class FileViewerElement extends ElementBase {
|
|
|
246
246
|
var _a, _b;
|
|
247
247
|
return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.resetZoom()) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
248
248
|
}
|
|
249
|
+
getViewState() {
|
|
250
|
+
var _a, _b;
|
|
251
|
+
return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.getViewState()) !== null && _b !== void 0 ? _b : null;
|
|
252
|
+
}
|
|
253
|
+
applyViewState(state, options) {
|
|
254
|
+
var _a, _b;
|
|
255
|
+
return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.applyViewState(state, options)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
256
|
+
}
|
|
249
257
|
searchDocument(query) {
|
|
250
258
|
var _a, _b;
|
|
251
259
|
return (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.searchDocument(query)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|