@file-viewer/web 2.1.25 → 2.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.en.md +7 -4
  2. package/README.md +7 -4
  3. package/dist/controller.js +67 -4
  4. package/dist/flyfish-file-viewer-web.iife.js +13 -12
  5. package/package.json +2 -2
  6. package/viewer/flyfish-viewer-assets.json +28 -19
  7. package/viewer/flyfish-viewer-manifest.json +1 -1
  8. package/viewer/vendor/docx/docx.worker.js +1 -1
  9. package/viewer/vendor/pdf/fonts/OFL-1.1.txt +93 -0
  10. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-100-wght-normal.woff2 +0 -0
  11. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-101-wght-normal.woff2 +0 -0
  12. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-102-wght-normal.woff2 +0 -0
  13. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-103-wght-normal.woff2 +0 -0
  14. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-104-wght-normal.woff2 +0 -0
  15. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-105-wght-normal.woff2 +0 -0
  16. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-106-wght-normal.woff2 +0 -0
  17. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-107-wght-normal.woff2 +0 -0
  18. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-108-wght-normal.woff2 +0 -0
  19. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-109-wght-normal.woff2 +0 -0
  20. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-110-wght-normal.woff2 +0 -0
  21. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-111-wght-normal.woff2 +0 -0
  22. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-112-wght-normal.woff2 +0 -0
  23. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-113-wght-normal.woff2 +0 -0
  24. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-114-wght-normal.woff2 +0 -0
  25. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-115-wght-normal.woff2 +0 -0
  26. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-116-wght-normal.woff2 +0 -0
  27. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-117-wght-normal.woff2 +0 -0
  28. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-118-wght-normal.woff2 +0 -0
  29. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-119-wght-normal.woff2 +0 -0
  30. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-21-wght-normal.woff2 +0 -0
  31. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-22-wght-normal.woff2 +0 -0
  32. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-23-wght-normal.woff2 +0 -0
  33. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-24-wght-normal.woff2 +0 -0
  34. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-25-wght-normal.woff2 +0 -0
  35. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-26-wght-normal.woff2 +0 -0
  36. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-27-wght-normal.woff2 +0 -0
  37. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-28-wght-normal.woff2 +0 -0
  38. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-29-wght-normal.woff2 +0 -0
  39. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-30-wght-normal.woff2 +0 -0
  40. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-31-wght-normal.woff2 +0 -0
  41. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-32-wght-normal.woff2 +0 -0
  42. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-33-wght-normal.woff2 +0 -0
  43. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-34-wght-normal.woff2 +0 -0
  44. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-35-wght-normal.woff2 +0 -0
  45. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-36-wght-normal.woff2 +0 -0
  46. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-37-wght-normal.woff2 +0 -0
  47. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-38-wght-normal.woff2 +0 -0
  48. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-39-wght-normal.woff2 +0 -0
  49. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-4-wght-normal.woff2 +0 -0
  50. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-40-wght-normal.woff2 +0 -0
  51. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-41-wght-normal.woff2 +0 -0
  52. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-42-wght-normal.woff2 +0 -0
  53. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-43-wght-normal.woff2 +0 -0
  54. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-44-wght-normal.woff2 +0 -0
  55. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-45-wght-normal.woff2 +0 -0
  56. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-46-wght-normal.woff2 +0 -0
  57. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-47-wght-normal.woff2 +0 -0
  58. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-48-wght-normal.woff2 +0 -0
  59. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-49-wght-normal.woff2 +0 -0
  60. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-5-wght-normal.woff2 +0 -0
  61. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-50-wght-normal.woff2 +0 -0
  62. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-51-wght-normal.woff2 +0 -0
  63. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-52-wght-normal.woff2 +0 -0
  64. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-53-wght-normal.woff2 +0 -0
  65. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-54-wght-normal.woff2 +0 -0
  66. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-55-wght-normal.woff2 +0 -0
  67. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-56-wght-normal.woff2 +0 -0
  68. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-57-wght-normal.woff2 +0 -0
  69. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-58-wght-normal.woff2 +0 -0
  70. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-59-wght-normal.woff2 +0 -0
  71. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-6-wght-normal.woff2 +0 -0
  72. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-60-wght-normal.woff2 +0 -0
  73. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-61-wght-normal.woff2 +0 -0
  74. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-62-wght-normal.woff2 +0 -0
  75. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-63-wght-normal.woff2 +0 -0
  76. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-64-wght-normal.woff2 +0 -0
  77. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-65-wght-normal.woff2 +0 -0
  78. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-66-wght-normal.woff2 +0 -0
  79. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-67-wght-normal.woff2 +0 -0
  80. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-68-wght-normal.woff2 +0 -0
  81. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-69-wght-normal.woff2 +0 -0
  82. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-70-wght-normal.woff2 +0 -0
  83. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-71-wght-normal.woff2 +0 -0
  84. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-72-wght-normal.woff2 +0 -0
  85. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-73-wght-normal.woff2 +0 -0
  86. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-74-wght-normal.woff2 +0 -0
  87. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-75-wght-normal.woff2 +0 -0
  88. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-76-wght-normal.woff2 +0 -0
  89. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-77-wght-normal.woff2 +0 -0
  90. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-78-wght-normal.woff2 +0 -0
  91. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-79-wght-normal.woff2 +0 -0
  92. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-80-wght-normal.woff2 +0 -0
  93. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-81-wght-normal.woff2 +0 -0
  94. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-82-wght-normal.woff2 +0 -0
  95. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-83-wght-normal.woff2 +0 -0
  96. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-84-wght-normal.woff2 +0 -0
  97. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-85-wght-normal.woff2 +0 -0
  98. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-86-wght-normal.woff2 +0 -0
  99. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-87-wght-normal.woff2 +0 -0
  100. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-88-wght-normal.woff2 +0 -0
  101. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-89-wght-normal.woff2 +0 -0
  102. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-90-wght-normal.woff2 +0 -0
  103. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-91-wght-normal.woff2 +0 -0
  104. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-97-wght-normal.woff2 +0 -0
  105. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-98-wght-normal.woff2 +0 -0
  106. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-99-wght-normal.woff2 +0 -0
  107. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-cyrillic-wght-normal.woff2 +0 -0
  108. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-latin-ext-wght-normal.woff2 +0 -0
  109. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-latin-wght-normal.woff2 +0 -0
  110. package/viewer/vendor/pdf/fonts/files/noto-sans-sc-vietnamese-wght-normal.woff2 +0 -0
  111. package/viewer/vendor/pdf/fonts/noto-sans-sc.css +1009 -0
  112. package/viewer/vendor/pdf/pdf.worker.mjs +26882 -21712
  113. package/viewer/vendor/pdf/wasm/LICENSE_JBIG2 +196 -0
  114. package/viewer/vendor/pdf/wasm/LICENSE_OPENJPEG +39 -0
  115. package/viewer/vendor/pdf/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  116. package/viewer/vendor/pdf/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  117. package/viewer/vendor/pdf/wasm/LICENSE_PDFJS_QCMS +22 -0
  118. package/viewer/vendor/pdf/wasm/LICENSE_QCMS +21 -0
  119. package/viewer/vendor/pdf/wasm/jbig2.wasm +0 -0
  120. package/viewer/vendor/pdf/wasm/openjpeg.wasm +0 -0
  121. package/viewer/vendor/pdf/wasm/openjpeg_nowasm_fallback.js +17 -0
  122. package/viewer/vendor/pdf/wasm/qcms_bg.wasm +0 -0
  123. package/viewer/vendor/xlsx/sheet.worker.js +11477 -4327
package/README.en.md CHANGED
@@ -254,7 +254,7 @@ The table below lists the real props, event channel, and customization entry for
254
254
  | Component | Actual props / entry | Event channel | Customization entry |
255
255
  | --- | --- | --- | --- |
256
256
  | 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. |
257
- | 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. |
257
+ | 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`, `theme-change` | Template refs expose `FileViewerExpose`. For `Blob` / `ArrayBuffer`, prefer wrapping it as a named `File` so extension detection stays deterministic. |
258
258
  | 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. |
259
259
  | 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. |
260
260
  | 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. |
@@ -267,7 +267,7 @@ The table below lists the real props, event channel, and customization entry for
267
267
  | `theme` | `light`, `dark`, or `system`. This takes precedence over browser `prefers-color-scheme`. |
268
268
  | `styleIsolation` | `auto`, `shadow`, `scoped`, or `none`. With `auto`, Web Component / full / IIFE entries use Shadow DOM by default; Vue, React, Svelte, and jQuery keep light-DOM compatibility unless renderer content is explicitly isolated with `shadow`. |
269
269
  | `watermark` | Text or image watermark with opacity, rotation, gap, size, font, and color controls. |
270
- | `toolbar` | Controls download, print, HTML export, zoom, toolbar position, and operation-level preflight checks. |
270
+ | `toolbar` | Controls the theme toggle, download, print, HTML export, zoom, item order, toolbar position, and operation-level preflight checks. |
271
271
  | `search` | Document search, highlight class names, case sensitivity, whole-word matching, max matches, and debounce. |
272
272
  | `ai` | Text collection, chunk size, and max text length for provenance, location, vectorization, and external AI workflows. |
273
273
  | `archive` | Archive Worker/WASM URLs, timeout, cache, archive limits, nested entry preview limits, and legacy GBK/GB18030 ZIP filename decoding. |
@@ -322,8 +322,10 @@ const options = {
322
322
  | Config | Description |
323
323
  | --- | --- |
324
324
  | `toolbar: false` | Hides the built-in toolbar without disabling controller APIs such as download, print, export, and zoom. Use this for a fully custom business toolbar. |
325
- | `toolbar: true` | Uses the default built-in toolbar. Download, print, HTML export, and zoom buttons are still shown only when the active renderer supports them. |
325
+ | `toolbar: true` | Uses the default built-in toolbar. The theme toggle is visible by default; download, print, HTML export, and zoom remain capability-aware. |
326
326
  | `download` / `print` / `exportHtml` / `zoom` | Expresses whether the host allows a button. Final availability is still computed from file type, render readiness, export adapter, and zoom provider state. |
327
+ | `theme` | Controls the light/dark toggle and defaults to `true`. A change emits `theme-change`; set it to `false` to hide the button. |
328
+ | `order` | Orders built-in groups with `search`, `zoom`, `download`, `print`, `exportHtml`, and `theme`. Omitted items keep their default relative order. |
327
329
  | `position` | `auto`, `top`, `top-center`, or `bottom-right`. The default `auto` floats PDF actions at bottom right and keeps other formats top-right; use `top-center` for a centered top toolbar. |
328
330
  | `beforeOperation` | Toolbar-level preflight that runs after `options.beforeOperation`. Returning `false` or throwing cancels the operation. |
329
331
  | `beforeDownload` / `beforePrint` / `beforeExportHtml` | Operation-specific preflight for download permission, print audit, export confirmation, and similar business rules. |
@@ -353,6 +355,7 @@ View-state sync is designed for projection systems, remote-control displays, sid
353
355
  | `unload-complete` / `hooks.onUnloadComplete` | Fires after the previous document is released. The reason is `replace`, `reset`, or `component-unmount`. |
354
356
  | `operation-before` / `operation-cancel` | Fires around download, print, HTML export, and zoom actions. Returning `false` from `beforeOperation` cancels the action. |
355
357
  | `operation-availability-change` | Fires when download, print, HTML export, or zoom support changes for the active format. |
358
+ | `theme-change` | Fires when the built-in control selects light or dark mode. The payload is `light` or `dark`. |
356
359
  | `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. |
357
360
 
358
361
  ## Public Operation API
@@ -376,7 +379,7 @@ View-state sync is designed for projection systems, remote-control displays, sid
376
379
  | --- | --- |
377
380
  | Shared viewer assets | The Pure Web package ships `file-viewer-copy-assets` to copy workers, WASM, vendor files, and examples into your static directory. |
378
381
  | CAD / DWG / DXF / DWF | Configure `options.cad.wasmPath`, `workerUrl`, `dwfWasmUrl`, and `dxfEncoding` for self-hosted or intranet deployment. |
379
- | 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. |
382
+ | PDF / DOCX / Excel / 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` / `options.presentation.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`, 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. |
380
383
  | 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. |
381
384
  | 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. |
382
385
  | 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. Vue full packages default to `/file-viewer/` as the asset root; call `setDefaultFullAssetBaseUrl()` first when your static prefix differs. |
package/README.md CHANGED
@@ -254,7 +254,7 @@ const options = {
254
254
  | 组件 | 实际属性 / 入口 | 事件入口 | 定制入口 |
255
255
  | --- | --- | --- | --- |
256
256
  | 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。 |
257
- | 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`。 |
257
+ | 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`、`theme-change` | 模板 `ref` 暴露 `FileViewerExpose`;适合声明式接入。`Blob` / `ArrayBuffer` 建议包装成带扩展名的 `File` 后传给 `file`。 |
258
258
  | 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` 平滑升级。 |
259
259
  | Vue 2.6 `@file-viewer/vue2.6` | 同 Vue 2.7 | `viewer-event` / `viewerEvent` | 独立 Vue 2.6 构建,不要求业务升级到 Vue 2.7。 |
260
260
  | React `@file-viewer/react` | `ViewerMountOptions` + `div` 原生属性,如 `className`、`style`、`data-*`、`aria-*` | `onEvent`、`onStateChange` | `ref` 暴露 `FileViewerHandle`;`useFileViewer()` 会返回 `ref`、`props`、`state`、`handle`,便于自定义工具栏。 |
@@ -267,7 +267,7 @@ const options = {
267
267
  | `theme` | `light`、`dark` 或 `system`,优先级高于浏览器 `prefers-color-scheme`。 |
268
268
  | `styleIsolation` | `auto`、`shadow`、`scoped` 或 `none`。`auto` 下 Web Component / full / IIFE 默认使用 Shadow DOM;Vue、React、Svelte、jQuery 默认保持 light DOM 兼容,但 renderer 内容可通过 `shadow` 获得独立渲染根。 |
269
269
  | `watermark` | 开启文字或图片水印,可设置透明度、旋转、间距、尺寸、字体和颜色。 |
270
- | `toolbar` | 控制下载、打印、HTML 导出、缩放和工具栏位置,并支持操作级前置校验。 |
270
+ | `toolbar` | 控制主题切换、下载、打印、HTML 导出、缩放、按钮顺序和工具栏位置,并支持操作级前置校验。 |
271
271
  | `search` | 配置文档搜索、高亮 class、大小写、整词匹配、最大命中数和 debounce。 |
272
272
  | `ai` | 控制文本结构采集、分块大小和最大文本长度,为溯源、定位、向量化和外部 AI 流程提供基础。 |
273
273
  | `archive` | 配置压缩包 Worker/WASM、超时、缓存、包体限制和压缩包内单文件预览大小;旧 ZIP 中文文件名会自动按 GBK/GB18030 兼容解码。 |
@@ -322,8 +322,10 @@ const options = {
322
322
  | 配置 | 说明 |
323
323
  | --- | --- |
324
324
  | `toolbar: false` | 隐藏内置工具栏,但不关闭下载、打印、导出、缩放等 controller API,适合完全自定义业务工具栏。 |
325
- | `toolbar: true` | 使用默认内置工具栏,下载、打印、HTML 导出和缩放按钮都会按能力动态显隐。 |
325
+ | `toolbar: true` | 使用默认内置工具栏;主题切换默认显示,下载、打印、HTML 导出和缩放按钮按能力动态显隐。 |
326
326
  | `download` / `print` / `exportHtml` / `zoom` | 表达业务是否允许展示对应按钮;最终仍会结合文件类型、渲染完成状态、导出适配器和缩放 provider 计算真实可用性。 |
327
+ | `theme` | 控制浅色/深色切换按钮,默认 `true`;切换后触发 `theme-change`,传 `false` 可隐藏。 |
328
+ | `order` | 设置内置分组顺序,可使用 `search`、`zoom`、`download`、`print`、`exportHtml`、`theme`;遗漏项保持默认相对顺序。 |
327
329
  | `position` | `auto`、`top`、`top-center`、`bottom-right`。默认 `auto`,PDF 自动悬浮右下角,其他格式保持顶部靠右;需要顶部水平居中时传 `top-center`。 |
328
330
  | `beforeOperation` | 工具栏层统一前置校验,会在 `options.beforeOperation` 后执行。返回 `false` 或抛错都会取消本次操作。 |
329
331
  | `beforeDownload` / `beforePrint` / `beforeExportHtml` | 单按钮前置校验;适合下载权限、打印审计、导出水印确认等细粒度业务规则。 |
@@ -353,6 +355,7 @@ const options = {
353
355
  | `unload-complete` / `hooks.onUnloadComplete` | 旧文档释放完成后触发,reason 会标识 `replace`、`reset` 或 `component-unmount`。 |
354
356
  | `operation-before` / `operation-cancel` | 下载、打印、HTML 导出和缩放前后触发;`beforeOperation` 返回 `false` 可取消操作。 |
355
357
  | `operation-availability-change` | 当前格式是否可下载、可打印、可导出 HTML、可缩放发生变化时触发。 |
358
+ | `theme-change` | 用户通过内置按钮切换浅色或深色模式时触发,payload 为 `light` 或 `dark`。 |
356
359
  | `search-change` / `location-change` / `zoom-change` / `view-state-change` | 搜索命中、定位锚点、缩放状态和完整视图快照变化时触发,用于外层同步 UI、投屏或恢复阅读进度。 |
357
360
 
358
361
  ## 公共操作 API
@@ -376,7 +379,7 @@ const options = {
376
379
  | --- | --- |
377
380
  | 通用 viewer assets | Pure Web 包提供 `file-viewer-copy-assets`,可把 Worker、WASM、vendor 和示例资源复制到业务静态目录。 |
378
381
  | CAD / DWG / DXF / DWF | 按需配置 `options.cad.wasmPath`、`workerUrl`、`dwfWasmUrl`、`dxfEncoding`,支持自托管和内网部署。 |
379
- | 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 地址。 |
382
+ | PDF / DOCX / Excel / 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` / `options.presentation.workerType`;PDF 默认探测真实静态 Worker,不可用时懒加载包内 handler 兜底,未嵌入的中文字体默认按页加载本地 Noto Sans SC 分片回退,缺失 ToUnicode 的异常 Identity CJK 字体会在检测到乱码后尝试内存修复;DOCX 默认自动选择 Worker 或主线程解析,Electron `file://` 等本地不安全协议会自动回退;Excel 默认 `worker: auto`,大文件达到 `workerAutoThreshold` 自动启用 Worker,列宽拖拽可通过 `options.spreadsheet.resizableColumns` 显式开启;PPTX 默认按需创建模块 Worker,严格 CSP、旧 WebView 或自托管 CDN 场景可固定 Worker 地址。 |
380
383
  | 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。 |
381
384
  | Drawing | Draw.io 默认使用随 viewer assets 分发的官方 diagrams.net 离线 viewer;路径特殊时可通过 `options.drawing.viewerScriptUrl` 覆盖,`preferOfficial:false` 才切到内置 SVG 兜底。 |
382
385
  | 离线部署 | 运行时不依赖公共 CDN 或第三方在线资源;`file-viewer-copy-assets` 会复制 PDF、CAD、Typst、SQLite、压缩包、Draw.io、DOCX worker/JSZip、PPTX worker 和 Office worker/vendor 资产。Vue full 包默认使用 `/file-viewer/` 作为资源根,路径不同可先调用 `setDefaultFullAssetBaseUrl()`。 |
@@ -1,5 +1,5 @@
1
- import { appendFileViewerStyle, applyFileViewerZoomAvailability, createViewer, isFileViewerShadowRoot, normalizeFileViewerUiDensity, normalizeFileViewerStyleIsolation, } from '@file-viewer/core';
2
- import { DEFAULT_FILE_VIEWER_SOURCE_FILENAME, createFileViewerTranslator, getExtension, normalizeFileViewerSourceUrl, hasVisibleFileViewerToolbarActions, isFileViewerZoomButtonDisabled, normalizeFileViewerToolbar, normalizeFilename, readFileViewerBuffer, resolveFileViewerSourceFilename, resolveFileViewerToolbarOrder, resolveFileViewerToolbarPosition, resolveVisibleFileViewerToolbar, wrapFileViewerFileRef, } from '@file-viewer/core';
1
+ import { appendFileViewerStyle, applyFileViewerZoomAvailability, createViewer, isFileViewerShadowRoot, normalizeFileViewerUiDensity, normalizeFileViewerTheme, normalizeFileViewerStyleIsolation, } from '@file-viewer/core';
2
+ import { DEFAULT_FILE_VIEWER_SOURCE_FILENAME, createFileViewerTranslator, getExtension, normalizeFileViewerSourceUrl, hasVisibleFileViewerToolbarActions, isFileViewerZoomButtonDisabled, normalizeFileViewerToolbar, normalizeFilename, readFileViewerBuffer, resolveFileViewerSourceFilename, resolveFileViewerColorScheme, resolveFileViewerToolbarOrder, resolveFileViewerToolbarPosition, resolveVisibleFileViewerToolbar, toggleFileViewerColorScheme, wrapFileViewerFileRef, } from '@file-viewer/core';
3
3
  const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
4
4
  const hasSource = (options = {}) => {
5
5
  return !!(options.url || options.file || options.buffer);
@@ -235,6 +235,7 @@ const WEB_VIEWER_STYLE = `
235
235
  .file-viewer-web-toolbar button:hover:not(:disabled){background:var(--file-viewer-button-hover-bg);color:var(--file-viewer-button-hover-color)}
236
236
  .file-viewer-web-toolbar button:disabled{color:var(--file-viewer-button-disabled-color);cursor:not-allowed}
237
237
  .file-viewer-web-toolbar .file-viewer-web-icon-button{width:var(--file-viewer-icon-button-size);min-width:var(--file-viewer-icon-button-size);padding:0;display:inline-flex;align-items:center;justify-content:center}
238
+ .file-viewer-web-theme-button svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
238
239
  .file-viewer-web-toolbar .file-viewer-web-zoom-meter{min-width:var(--file-viewer-zoom-meter-min-width);height:var(--file-viewer-button-height);padding:var(--file-viewer-zoom-meter-padding);display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;color:var(--file-viewer-button-color)}
239
240
  .file-viewer-web-toolbar .file-viewer-web-zoom-meter--readonly{font-size:12px;font-weight:800;line-height:1;white-space:nowrap}
240
241
  .file-viewer-web-print-menu{position:relative;display:inline-flex}
@@ -293,8 +294,13 @@ const createReadonlyMeter = (documentRef, label, className) => {
293
294
  meter.setAttribute('aria-label', label);
294
295
  return meter;
295
296
  };
297
+ const setThemeButtonIcon = (button, currentTheme) => {
298
+ button.innerHTML = currentTheme === 'dark'
299
+ ? '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.42 1.42M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.42-1.42M17.66 6.34l1.41-1.41"/></svg>'
300
+ : '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z"/></svg>';
301
+ };
296
302
  export const mountViewer = (container, initialOptions = {}, coreOptions = {}) => {
297
- var _a, _b;
303
+ var _a, _b, _c, _d, _e, _f;
298
304
  if (!isBrowser()) {
299
305
  throw new Error('Flyfish File Viewer can only be mounted in a browser DOM environment.');
300
306
  }
@@ -330,6 +336,12 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
330
336
  renderRoot.appendChild(shell);
331
337
  let disposed = false;
332
338
  let currentOptions = initialOptions;
339
+ const viewerColorSchemeQuery = (_e = (_d = (_c = documentRef.defaultView) === null || _c === void 0 ? void 0 : _c.matchMedia) === null || _d === void 0 ? void 0 : _d.call(_c, '(prefers-color-scheme: dark)')) !== null && _e !== void 0 ? _e : null;
340
+ const resolveCurrentViewerTheme = (theme) => {
341
+ return viewerColorSchemeQuery
342
+ ? resolveFileViewerColorScheme(theme, viewerColorSchemeQuery.matches)
343
+ : resolveFileViewerColorScheme(theme);
344
+ };
333
345
  let currentSource = hasSource(currentOptions)
334
346
  ? toViewerSourceInput(currentOptions)
335
347
  : null;
@@ -377,7 +389,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
377
389
  });
378
390
  const syncShellTheme = () => {
379
391
  var _a, _b, _c;
380
- shell.dataset.viewerTheme = ((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme) || 'light';
392
+ shell.dataset.viewerTheme = normalizeFileViewerTheme((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme);
381
393
  shell.dataset.viewerDensity = normalizeFileViewerUiDensity((_c = (_b = currentOptions.options) === null || _b === void 0 ? void 0 : _b.ui) === null || _c === void 0 ? void 0 : _c.density);
382
394
  };
383
395
  let controller = null;
@@ -551,6 +563,45 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
551
563
  button.disabled = toolbarDisabled;
552
564
  toolbarEl.appendChild(button);
553
565
  };
566
+ const appendThemeToolbar = () => {
567
+ if (!visibleToolbar.theme) {
568
+ return;
569
+ }
570
+ const currentTheme = resolveCurrentViewerTheme(options.theme);
571
+ const title = currentTheme === 'dark'
572
+ ? t('toolbar.themeToLight')
573
+ : t('toolbar.themeToDark');
574
+ const button = createButton(documentRef, '', 'file-viewer-web-icon-button file-viewer-web-theme-button', async () => {
575
+ var _a;
576
+ const previousViewState = instance.getViewState();
577
+ const nextTheme = toggleFileViewerColorScheme((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme, viewerColorSchemeQuery === null || viewerColorSchemeQuery === void 0 ? void 0 : viewerColorSchemeQuery.matches);
578
+ currentOptions = {
579
+ ...currentOptions,
580
+ options: {
581
+ ...(currentOptions.options || {}),
582
+ theme: nextTheme,
583
+ },
584
+ };
585
+ instance.updateOptions({ theme: nextTheme });
586
+ applyViewerEvent({ type: 'theme-change', payload: nextTheme });
587
+ if (currentSource) {
588
+ const session = await loadSource(currentSource).catch(() => null);
589
+ if (session && previousViewState) {
590
+ await instance.applyViewState(previousViewState, {
591
+ action: 'restore',
592
+ source: 'api',
593
+ });
594
+ }
595
+ }
596
+ });
597
+ addPart(button, 'theme-toggle');
598
+ setThemeButtonIcon(button, currentTheme);
599
+ button.title = title;
600
+ button.setAttribute('aria-label', title);
601
+ button.setAttribute('aria-pressed', String(currentTheme === 'dark'));
602
+ button.disabled = toolbarDisabled;
603
+ toolbarEl.appendChild(button);
604
+ };
554
605
  resolveFileViewerToolbarOrder(toolbar).forEach(item => {
555
606
  if (item === 'search') {
556
607
  appendSearchToolbar();
@@ -608,8 +659,17 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
608
659
  else if (item === 'exportHtml') {
609
660
  appendToolbarButton(visibleToolbar.exportHtml, t('toolbar.exportHtml'), t('toolbar.exportHtmlTitle'), () => controller === null || controller === void 0 ? void 0 : controller.exportRenderedHtml());
610
661
  }
662
+ else if (item === 'theme') {
663
+ appendThemeToolbar();
664
+ }
611
665
  });
612
666
  };
667
+ const handleViewerColorSchemeChange = () => {
668
+ var _a;
669
+ if (normalizeFileViewerTheme((_a = currentOptions.options) === null || _a === void 0 ? void 0 : _a.theme) === 'system') {
670
+ renderToolbar();
671
+ }
672
+ };
613
673
  const notifyState = (event) => {
614
674
  var _a;
615
675
  const snapshot = snapshotState();
@@ -667,6 +727,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
667
727
  options: currentOptions.options,
668
728
  onEvent: applyViewerEvent,
669
729
  });
730
+ (_f = viewerColorSchemeQuery === null || viewerColorSchemeQuery === void 0 ? void 0 : viewerColorSchemeQuery.addEventListener) === null || _f === void 0 ? void 0 : _f.call(viewerColorSchemeQuery, 'change', handleViewerColorSchemeChange);
670
731
  renderToolbar();
671
732
  const cancel = () => {
672
733
  abortController === null || abortController === void 0 ? void 0 : abortController.abort();
@@ -750,10 +811,12 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
750
811
  }
751
812
  },
752
813
  destroy() {
814
+ var _a;
753
815
  if (disposed)
754
816
  return;
755
817
  disposed = true;
756
818
  cancel();
819
+ (_a = viewerColorSchemeQuery === null || viewerColorSchemeQuery === void 0 ? void 0 : viewerColorSchemeQuery.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(viewerColorSchemeQuery, 'change', handleViewerColorSchemeChange);
757
820
  void instance.destroy('component-unmount');
758
821
  styleHandle.remove();
759
822
  renderRoot.replaceChildren();