@file-viewer/web 2.1.17 → 2.1.18
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 +63 -1
- package/README.md +63 -1
- package/dist/controller.d.ts +6 -1
- package/dist/controller.js +104 -43
- package/dist/element.d.ts +8 -2
- package/dist/element.js +73 -1
- package/dist/flyfish-file-viewer-web.iife.js +25 -24
- package/package.json +2 -2
- package/viewer/flyfish-viewer-assets.json +6 -6
- package/viewer/flyfish-viewer-manifest.json +1 -1
- package/viewer/vendor/docx/docx.worker.js +1 -1
- package/viewer/vendor/drawio/shapes/mockup/mxMockupContainers.js +1 -1
- package/viewer/vendor/drawio/viewer-static.min.js +37 -37
- package/viewer/vendor/pptx/pptx.worker.js +7 -7
- package/viewer/wasm/cad/dwg-worker.js +1 -1
package/README.en.md
CHANGED
|
@@ -30,6 +30,25 @@ viewer.zoomIn()
|
|
|
30
30
|
|
|
31
31
|
Use `mountViewer(container, options)` when you need a fully imperative controller.
|
|
32
32
|
|
|
33
|
+
## Style Isolation And Customization
|
|
34
|
+
|
|
35
|
+
`<flyfish-file-viewer>` and Web/IIFE mounts use Shadow DOM by default to protect the viewer shell and rendered content from host-page CSS. This is the recommended path for admin systems, low-code shells, micro-frontends, and pages where global CSS is hard to control. For the historical light-DOM behavior, pass `options: { styleIsolation: 'none' }` or `<flyfish-file-viewer style-isolation="none">`.
|
|
36
|
+
|
|
37
|
+
Use CSS variables and Shadow Parts for controlled customization:
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
flyfish-file-viewer {
|
|
41
|
+
--file-viewer-button-color: #123b63;
|
|
42
|
+
--file-viewer-toolbar-bg: rgba(255, 255, 255, 0.96);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
flyfish-file-viewer::part(toolbar) {
|
|
46
|
+
border-radius: 999px;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Stable parts include `host`, `shell`, `toolbar`, `toolbar-group`, `toolbar-status`, `button`, `input`, and `content`. Framework components keep their compatible defaults, and can opt renderer content into an isolated ShadowRoot with `options.styleIsolation: 'shadow'`. See the official documentation for modes, tokens, and hostile CSS verification: https://doc.file-viewer.app/
|
|
51
|
+
|
|
33
52
|
Use the asset copy command when you need to self-host workers, WASM files, and static examples:
|
|
34
53
|
|
|
35
54
|
```bash
|
|
@@ -225,6 +244,7 @@ Every ecosystem package uses the same `ViewerMountOptions` and `FileViewerOption
|
|
|
225
244
|
| `type` | Explicit extension or MIME hint that overrides automatic detection. |
|
|
226
245
|
| `size` | File size hint used in lifecycle context, loading states, and safety limits. |
|
|
227
246
|
| `options` | The shared `FileViewerOptions` surface. Every component package keeps the same semantics. |
|
|
247
|
+
| `options.styleIsolation` | `auto`, `shadow`, `scoped`, or `none`. Pure Web / IIFE / Custom Element entries default to strong isolation; framework packages keep compatibility by default and can opt renderer content into a ShadowRoot. |
|
|
228
248
|
| `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. |
|
|
229
249
|
|
|
230
250
|
## Actual Component Props
|
|
@@ -245,6 +265,7 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
245
265
|
| Options Field | Description |
|
|
246
266
|
| --- | --- |
|
|
247
267
|
| `theme` | `light`, `dark`, or `system`. This takes precedence over browser `prefers-color-scheme`. |
|
|
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`. |
|
|
248
269
|
| `watermark` | Text or image watermark with opacity, rotation, gap, size, font, and color controls. |
|
|
249
270
|
| `toolbar` | Controls download, print, HTML export, zoom, toolbar position, and operation-level preflight checks. |
|
|
250
271
|
| `search` | Document search, highlight class names, case sensitivity, whole-word matching, max matches, and debounce. |
|
|
@@ -255,6 +276,47 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
255
276
|
| `typst` / `data` / `cad` | Typst, SQLite, CAD/DWG/DXF/DWF WASM, worker, encoding, and rendering strategy options. |
|
|
256
277
|
| `hooks` / `beforeOperation` | Shared lifecycle hooks and operation preflight checks for audit, permission, telemetry, and safety controls. |
|
|
257
278
|
|
|
279
|
+
## Style Isolation And Theme Customization
|
|
280
|
+
|
|
281
|
+
For OA systems, low-code shells, micro-frontends, portals, and admin products, prefer the strong Shadow DOM isolation used by Pure Web / Web Component and full packages 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.
|
|
282
|
+
|
|
283
|
+
| Mode | Description |
|
|
284
|
+
| --- | --- |
|
|
285
|
+
| `auto` | Default. `@file-viewer/web`, `@file-viewer/web-full`, IIFE, and `<flyfish-file-viewer>` use Shadow DOM by default. Vue, React, Svelte, and jQuery keep light-DOM compatibility for existing projects while renderer content can still be isolated by core. |
|
|
286
|
+
| `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. |
|
|
287
|
+
| `scoped` | Does not create a ShadowRoot. Uses a stable root selector, `@layer file-viewer`, and local resets to constrain cascade impact while keeping controlled inheritance from the host. |
|
|
288
|
+
| `none` | Historical light-DOM behavior for projects that depend on deep class overrides, old theme CSS, or snapshot tests. |
|
|
289
|
+
|
|
290
|
+
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.
|
|
291
|
+
|
|
292
|
+
```css
|
|
293
|
+
flyfish-file-viewer {
|
|
294
|
+
--file-viewer-bg: #f7f9fc;
|
|
295
|
+
--file-viewer-text: #172033;
|
|
296
|
+
--file-viewer-toolbar-bg: rgba(255, 255, 255, 0.96);
|
|
297
|
+
--file-viewer-button-color: #154b83;
|
|
298
|
+
--file-viewer-button-radius: 6px;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
flyfish-file-viewer::part(toolbar) {
|
|
302
|
+
border: 1px solid rgba(20, 60, 100, 0.14);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
flyfish-file-viewer::part(button) {
|
|
306
|
+
font-weight: 600;
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Framework packages can opt into renderer isolation through the shared options object:
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
const options = {
|
|
314
|
+
styleIsolation: 'shadow',
|
|
315
|
+
theme: 'light',
|
|
316
|
+
toolbar: { position: 'bottom-right' }
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
258
320
|
## Toolbar Customization
|
|
259
321
|
|
|
260
322
|
| Config | Description |
|
|
@@ -262,7 +324,7 @@ The table below lists the real props, event channel, and customization entry for
|
|
|
262
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. |
|
|
263
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. |
|
|
264
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. |
|
|
265
|
-
| `position` | `auto`, `top`, or `bottom-right`. The default `auto` floats PDF actions at bottom right
|
|
327
|
+
| `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. |
|
|
266
328
|
| `beforeOperation` | Toolbar-level preflight that runs after `options.beforeOperation`. Returning `false` or throwing cancels the operation. |
|
|
267
329
|
| `beforeDownload` / `beforePrint` / `beforeExportHtml` | Operation-specific preflight for download permission, print audit, export confirmation, and similar business rules. |
|
|
268
330
|
|
package/README.md
CHANGED
|
@@ -30,6 +30,25 @@ viewer.zoomIn()
|
|
|
30
30
|
|
|
31
31
|
需要完全命令式场景时,仍可使用 `mountViewer(container, options)` 返回完整 controller。
|
|
32
32
|
|
|
33
|
+
## 样式隔离与定制
|
|
34
|
+
|
|
35
|
+
`<flyfish-file-viewer>` 和 Web/IIFE 默认使用 Shadow DOM 隔离组件壳与预览内容,适合 OA、低代码、微前端和后台系统这类宿主 CSS 不可控的页面。需要历史 light DOM 行为时,可传 `options: { styleIsolation: 'none' }` 或 `<flyfish-file-viewer style-isolation="none">`。
|
|
36
|
+
|
|
37
|
+
推荐通过 CSS 变量和 Shadow Parts 做受控定制:
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
flyfish-file-viewer {
|
|
41
|
+
--file-viewer-button-color: #123b63;
|
|
42
|
+
--file-viewer-toolbar-bg: rgba(255, 255, 255, 0.96);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
flyfish-file-viewer::part(toolbar) {
|
|
46
|
+
border-radius: 999px;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
稳定 parts 包括 `host`、`shell`、`toolbar`、`toolbar-group`、`toolbar-status`、`button`、`input` 和 `content`。框架组件默认保持兼容,也可以通过 `options.styleIsolation: 'shadow'` 让 renderer 内容进入独立 ShadowRoot。完整模式、tokens 和 hostile CSS 验证见官方文档: https://doc.file-viewer.app/
|
|
51
|
+
|
|
33
52
|
如需自托管 Worker、WASM 和静态示例资源,可以使用资源复制命令:
|
|
34
53
|
|
|
35
54
|
```bash
|
|
@@ -225,6 +244,7 @@ const options = {
|
|
|
225
244
|
| `type` | 显式指定扩展名或 MIME 线索,覆盖自动识别结果。 |
|
|
226
245
|
| `size` | 文件大小提示,用于生命周期上下文、加载状态和安全限制展示。 |
|
|
227
246
|
| `options` | 完整 `FileViewerOptions`,所有框架包保持同一套参数语义。 |
|
|
247
|
+
| `options.styleIsolation` | `auto`、`shadow`、`scoped` 或 `none`。Pure Web / IIFE / Custom Element 默认强隔离;框架组件默认保持历史兼容,可按需让 renderer 内容进入独立 ShadowRoot。 |
|
|
228
248
|
| `onEvent` / `onStateChange` | Vanilla JS / Pure Web、React、Svelte 等命令式包装层的统一事件和状态订阅;Vue 组件会映射为原生 emit。 |
|
|
229
249
|
|
|
230
250
|
## 实际组件属性
|
|
@@ -245,6 +265,7 @@ const options = {
|
|
|
245
265
|
| Options 字段 | 说明 |
|
|
246
266
|
| --- | --- |
|
|
247
267
|
| `theme` | `light`、`dark` 或 `system`,优先级高于浏览器 `prefers-color-scheme`。 |
|
|
268
|
+
| `styleIsolation` | `auto`、`shadow`、`scoped` 或 `none`。`auto` 下 Web Component / full / IIFE 默认使用 Shadow DOM;Vue、React、Svelte、jQuery 默认保持 light DOM 兼容,但 renderer 内容可通过 `shadow` 获得独立渲染根。 |
|
|
248
269
|
| `watermark` | 开启文字或图片水印,可设置透明度、旋转、间距、尺寸、字体和颜色。 |
|
|
249
270
|
| `toolbar` | 控制下载、打印、HTML 导出、缩放和工具栏位置,并支持操作级前置校验。 |
|
|
250
271
|
| `search` | 配置文档搜索、高亮 class、大小写、整词匹配、最大命中数和 debounce。 |
|
|
@@ -255,6 +276,47 @@ const options = {
|
|
|
255
276
|
| `typst` / `data` / `cad` | 配置 Typst、SQLite、CAD/DWG/DXF/DWF 等 WASM、Worker、编码和渲染策略。 |
|
|
256
277
|
| `hooks` / `beforeOperation` | 统一生命周期 hooks 和操作前置校验,可用于审计、权限、埋点和安全控制。 |
|
|
257
278
|
|
|
279
|
+
## 样式隔离与主题定制
|
|
280
|
+
|
|
281
|
+
推荐在 OA、低代码、微前端、门户和后台系统中优先使用 Pure Web / Web Component 或 full 包默认的 Shadow DOM 强隔离。宿主页面里的 `*`、`button`、`table`、`img`、`svg`、`canvas` 等全局样式不会直接侵入预览器工具栏和正文;预览器也不会把局部 reset 粗暴写到业务页面。
|
|
282
|
+
|
|
283
|
+
| 模式 | 说明 |
|
|
284
|
+
| --- | --- |
|
|
285
|
+
| `auto` | 默认值。`@file-viewer/web`、`@file-viewer/web-full`、IIFE 和 `<flyfish-file-viewer>` 默认走 Shadow DOM;Vue、React、Svelte、jQuery 为兼容旧项目保持 light DOM,但 renderer 内容可由 core 按需隔离。 |
|
|
286
|
+
| `shadow` | 显式创建 ShadowRoot 作为渲染面,适合宿主 CSS 不可控、微前端混挂、低代码平台和设计系统全局 reset 很强的页面。 |
|
|
287
|
+
| `scoped` | 不创建 ShadowRoot,使用稳定根选择器、`@layer file-viewer` 和局部 reset 约束样式权重,适合需要被外层 CSS 轻度继承但又不想污染页面的场景。 |
|
|
288
|
+
| `none` | 历史 light DOM 行为,保留给依赖深度 class 覆盖、旧主题 CSS 或自动化测试快照的项目。 |
|
|
289
|
+
|
|
290
|
+
定制优先级建议是:先使用 `--file-viewer-*` CSS 变量覆盖颜色、字体、间距、圆角、工具栏和按钮;需要命中内部结构时再使用稳定 Shadow Parts。当前 Web shell 暴露 `host`、`shell`、`toolbar`、`toolbar-group`、`toolbar-status`、`button`、`input` 和 `content`,后续 renderer 扩展应继续使用 `state-panel`、`watermark` 这类稳定命名。不要依赖内部 class 名,它们只服务实现细节。
|
|
291
|
+
|
|
292
|
+
```css
|
|
293
|
+
flyfish-file-viewer {
|
|
294
|
+
--file-viewer-bg: #f7f9fc;
|
|
295
|
+
--file-viewer-text: #172033;
|
|
296
|
+
--file-viewer-toolbar-bg: rgba(255, 255, 255, 0.96);
|
|
297
|
+
--file-viewer-button-color: #154b83;
|
|
298
|
+
--file-viewer-button-radius: 6px;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
flyfish-file-viewer::part(toolbar) {
|
|
302
|
+
border: 1px solid rgba(20, 60, 100, 0.14);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
flyfish-file-viewer::part(button) {
|
|
306
|
+
font-weight: 600;
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
框架组件的推荐写法是在 `options` 中显式声明隔离策略:
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
const options = {
|
|
314
|
+
styleIsolation: 'shadow',
|
|
315
|
+
theme: 'light',
|
|
316
|
+
toolbar: { position: 'bottom-right' }
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
258
320
|
## 工具栏定制
|
|
259
321
|
|
|
260
322
|
| 配置 | 说明 |
|
|
@@ -262,7 +324,7 @@ const options = {
|
|
|
262
324
|
| `toolbar: false` | 隐藏内置工具栏,但不关闭下载、打印、导出、缩放等 controller API,适合完全自定义业务工具栏。 |
|
|
263
325
|
| `toolbar: true` | 使用默认内置工具栏,下载、打印、HTML 导出和缩放按钮都会按能力动态显隐。 |
|
|
264
326
|
| `download` / `print` / `exportHtml` / `zoom` | 表达业务是否允许展示对应按钮;最终仍会结合文件类型、渲染完成状态、导出适配器和缩放 provider 计算真实可用性。 |
|
|
265
|
-
| `position` | `auto`、`top`、`bottom-right`。默认 `auto`,PDF
|
|
327
|
+
| `position` | `auto`、`top`、`top-center`、`bottom-right`。默认 `auto`,PDF 自动悬浮右下角,其他格式保持顶部靠右;需要顶部水平居中时传 `top-center`。 |
|
|
266
328
|
| `beforeOperation` | 工具栏层统一前置校验,会在 `options.beforeOperation` 后执行。返回 `false` 或抛错都会取消本次操作。 |
|
|
267
329
|
| `beforeDownload` / `beforePrint` / `beforeExportHtml` | 单按钮前置校验;适合下载权限、打印审计、导出水印确认等细粒度业务规则。 |
|
|
268
330
|
|
package/dist/controller.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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 FileViewerFitMode, type FileViewerFitOptions, type FileViewerFitResult, 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;
|
|
@@ -12,6 +12,9 @@ export type ViewerTypstOptions = FileViewerTypstOptions;
|
|
|
12
12
|
export type ViewerCadOptions = FileViewerCadOptions;
|
|
13
13
|
export type ViewerSearchOptions = FileViewerSearchOptions;
|
|
14
14
|
export type ViewerAiOptions = FileViewerAiOptions;
|
|
15
|
+
export type ViewerFitMode = FileViewerFitMode;
|
|
16
|
+
export type ViewerFitOptions = FileViewerFitOptions;
|
|
17
|
+
export type ViewerFitResult = FileViewerFitResult;
|
|
15
18
|
export type ViewerViewState = FileViewerViewState;
|
|
16
19
|
export type ViewerApplyViewStateOptions = FileViewerApplyViewStateOptions;
|
|
17
20
|
export type ViewerThemeMode = FileViewerThemeMode;
|
|
@@ -79,6 +82,7 @@ export interface ViewerController {
|
|
|
79
82
|
zoomIn(): Promise<FileViewerZoomState | null>;
|
|
80
83
|
zoomOut(): Promise<FileViewerZoomState | null>;
|
|
81
84
|
resetZoom(): Promise<FileViewerZoomState | null>;
|
|
85
|
+
fitToView(fit?: FileViewerFitMode | FileViewerFitOptions): Promise<FileViewerFitResult | null>;
|
|
82
86
|
getViewState(): FileViewerViewState | null;
|
|
83
87
|
applyViewState(state: FileViewerViewState, options?: FileViewerApplyViewStateOptions): Promise<FileViewerViewState | null>;
|
|
84
88
|
searchDocument(query: string): Promise<FileViewerSearchState | null>;
|
|
@@ -109,6 +113,7 @@ export interface ViewerControllerHandle {
|
|
|
109
113
|
zoomIn(): Promise<FileViewerZoomState | null>;
|
|
110
114
|
zoomOut(): Promise<FileViewerZoomState | null>;
|
|
111
115
|
resetZoom(): Promise<FileViewerZoomState | null>;
|
|
116
|
+
fitToView(fit?: FileViewerFitMode | FileViewerFitOptions): Promise<FileViewerFitResult | null>;
|
|
112
117
|
getViewState(): FileViewerViewState | null;
|
|
113
118
|
applyViewState(state: FileViewerViewState, options?: FileViewerApplyViewStateOptions): Promise<FileViewerViewState | null>;
|
|
114
119
|
searchDocument(query: string): Promise<FileViewerSearchState | null>;
|
package/dist/controller.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { applyFileViewerZoomAvailability, createViewer } from '@file-viewer/core';
|
|
2
|
-
import { DEFAULT_FILE_VIEWER_SOURCE_FILENAME, createFileViewerTranslator, getExtension, hasVisibleFileViewerToolbarActions, isFileViewerZoomButtonDisabled, normalizeFileViewerToolbar, normalizeFilename, readFileViewerBuffer, resolveFileViewerSourceFilename, resolveFileViewerToolbarPosition, resolveVisibleFileViewerToolbar, wrapFileViewerFileRef, } from '@file-viewer/core';
|
|
1
|
+
import { appendFileViewerStyle, applyFileViewerZoomAvailability, createViewer, isFileViewerShadowRoot, normalizeFileViewerStyleIsolation, } from '@file-viewer/core';
|
|
2
|
+
import { DEFAULT_FILE_VIEWER_SOURCE_FILENAME, createFileViewerTranslator, getExtension, hasVisibleFileViewerToolbarActions, isFileViewerZoomButtonDisabled, normalizeFileViewerToolbar, normalizeFilename, readFileViewerBuffer, resolveFileViewerSourceFilename, resolveFileViewerToolbarOrder, resolveFileViewerToolbarPosition, resolveVisibleFileViewerToolbar, 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);
|
|
@@ -124,6 +124,10 @@ 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
|
+
fitToView(fit) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.fitToView(fit)) !== null && _b !== void 0 ? _b : Promise.resolve(null);
|
|
130
|
+
},
|
|
127
131
|
getViewState() {
|
|
128
132
|
var _a, _b;
|
|
129
133
|
return (_b = (_a = getController()) === null || _a === void 0 ? void 0 : _a.getViewState()) !== null && _b !== void 0 ? _b : null;
|
|
@@ -211,39 +215,53 @@ const DEFAULT_TOOLBAR_ZOOM_STATE = {
|
|
|
211
215
|
canReset: false,
|
|
212
216
|
};
|
|
213
217
|
const WEB_VIEWER_STYLE = `
|
|
214
|
-
|
|
218
|
+
:host{display:block;width:100%;height:100%;min-width:0;min-height:0;contain:content;--file-viewer-bg:transparent;--file-viewer-text:#172033;--file-viewer-muted:#607282;--file-viewer-font:14px/1.45 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;--file-viewer-border:rgba(20,35,53,.08);--file-viewer-toolbar-bg:rgba(255,255,255,.92);--file-viewer-toolbar-border:rgba(20,35,53,.06);--file-viewer-toolbar-shadow:0 18px 44px rgba(15,23,42,.16);--file-viewer-toolbar-radius:999px;--file-viewer-toolbar-gap:6px;--file-viewer-toolbar-padding:6px 10px;--file-viewer-toolbar-floating-padding:6px;--file-viewer-toolbar-floating-offset:16px;--file-viewer-group-bg:rgba(20,35,53,.035);--file-viewer-group-border:rgba(20,35,53,.08);--file-viewer-button-color:#40546a;--file-viewer-button-hover-bg:rgba(33,163,102,.1);--file-viewer-button-hover-color:#16774c;--file-viewer-button-disabled-color:#aab5c0;--file-viewer-button-radius:8px;--file-viewer-input-bg:#fff;--file-viewer-input-color:#172033;--file-viewer-focus-ring:rgba(31,157,103,.22);--file-viewer-z-toolbar:20;--file-viewer-z-floating-toolbar:30}
|
|
219
|
+
:host([theme='dark']){--file-viewer-toolbar-bg:rgba(15,23,42,.9);--file-viewer-toolbar-border:rgba(148,163,184,.18);--file-viewer-button-color:#d7dee8;--file-viewer-input-bg:rgba(15,23,42,.78);--file-viewer-input-color:#f8fafc;--file-viewer-muted:#cbd5e1}
|
|
220
|
+
*,*::before,*::after{box-sizing:border-box}
|
|
221
|
+
.file-viewer-web-shell{position:relative;width:100%;height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden;background:var(--file-viewer-bg);color:var(--file-viewer-text);font:var(--file-viewer-font);letter-spacing:0;box-sizing:border-box;contain:content}
|
|
215
222
|
.file-viewer-web-content{position:relative;flex:1 1 auto;min-height:0;min-width:0;overflow:auto;overscroll-behavior:contain}
|
|
216
|
-
.file-viewer-web-toolbar{flex:0 0 auto;min-height:45px;display:inline-flex;align-items:center;justify-content:flex-end;gap:
|
|
223
|
+
.file-viewer-web-toolbar{flex:0 0 auto;min-height:45px;display:inline-flex;align-items:center;justify-content:flex-end;gap:var(--file-viewer-toolbar-gap);padding:var(--file-viewer-toolbar-padding);border-bottom:1px solid var(--file-viewer-toolbar-border);background:var(--file-viewer-toolbar-bg);box-sizing:border-box;z-index:var(--file-viewer-z-toolbar)}
|
|
217
224
|
.file-viewer-web-toolbar[hidden]{display:none!important}
|
|
218
|
-
.file-viewer-web-toolbar[data-toolbar-position="
|
|
219
|
-
.file-viewer-web-toolbar-
|
|
220
|
-
.file-viewer-web-toolbar
|
|
221
|
-
.file-viewer-web-toolbar button:
|
|
222
|
-
.file-viewer-web-toolbar button:disabled{color
|
|
225
|
+
.file-viewer-web-toolbar[data-toolbar-position="top-center"]{justify-content:center}
|
|
226
|
+
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"]{position:absolute;right:calc(var(--file-viewer-toolbar-floating-offset) + env(safe-area-inset-right,0px));bottom:calc(var(--file-viewer-toolbar-floating-offset) + env(safe-area-inset-bottom,0px));min-height:42px;padding:var(--file-viewer-toolbar-floating-padding);border:1px solid var(--file-viewer-border);border-radius:var(--file-viewer-toolbar-radius);background:var(--file-viewer-toolbar-bg);box-shadow:var(--file-viewer-toolbar-shadow);backdrop-filter:blur(16px);z-index:var(--file-viewer-z-floating-toolbar)}
|
|
227
|
+
.file-viewer-web-toolbar-group{display:inline-flex;align-items:center;gap:2px;padding:2px;border:1px solid var(--file-viewer-group-border);border-radius:var(--file-viewer-toolbar-radius);background:var(--file-viewer-group-bg)}
|
|
228
|
+
.file-viewer-web-toolbar button{min-width:42px;height:30px;padding:0 10px;border:0;border-radius:var(--file-viewer-button-radius);background:transparent;color:var(--file-viewer-button-color);font:inherit;font-size:12px;font-weight:800;line-height:1;letter-spacing:0;white-space:nowrap;cursor:pointer}
|
|
229
|
+
.file-viewer-web-toolbar button:hover:not(:disabled){background:var(--file-viewer-button-hover-bg);color:var(--file-viewer-button-hover-color)}
|
|
230
|
+
.file-viewer-web-toolbar button:disabled{color:var(--file-viewer-button-disabled-color);cursor:not-allowed}
|
|
223
231
|
.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}
|
|
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
|
|
232
|
+
.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:var(--file-viewer-button-color)}
|
|
225
233
|
.file-viewer-web-toolbar .file-viewer-web-zoom-meter--readonly{font-size:12px;font-weight:800;line-height:1;white-space:nowrap}
|
|
226
234
|
.file-viewer-web-search{gap:4px}
|
|
227
|
-
.file-viewer-web-search input{width:clamp(128px,18vw,220px);height:30px;box-sizing:border-box;border:0;border-radius:
|
|
228
|
-
.file-viewer-web-search input:focus{box-shadow:0 0 0 2px
|
|
235
|
+
.file-viewer-web-search input{width:clamp(128px,18vw,220px);height:30px;box-sizing:border-box;border:0;border-radius:var(--file-viewer-toolbar-radius);padding:0 10px;background:var(--file-viewer-input-bg);color:var(--file-viewer-input-color);font:inherit;font-size:12px;line-height:30px;letter-spacing:0;outline:0}
|
|
236
|
+
.file-viewer-web-search input:focus{box-shadow:0 0 0 2px var(--file-viewer-focus-ring)}
|
|
229
237
|
.file-viewer-web-search button{min-width:32px;height:30px;padding:0 8px;border-radius:999px}
|
|
230
|
-
.file-viewer-web-search-count{min-width:42px;text-align:center;color
|
|
238
|
+
.file-viewer-web-search-count{min-width:42px;text-align:center;color:var(--file-viewer-muted);font-size:12px;font-weight:800;line-height:30px;white-space:nowrap}
|
|
231
239
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] button{min-width:48px;height:32px;border-radius:999px}
|
|
232
240
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-icon-button{width:32px;min-width:32px}
|
|
233
241
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-zoom-meter{min-width:54px;height:32px}
|
|
234
242
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-search button{min-width:32px;height:32px}
|
|
235
243
|
.file-viewer-web-toolbar[data-toolbar-position="bottom-right"] .file-viewer-web-search input{height:32px;line-height:32px;width:clamp(120px,18vw,190px)}
|
|
236
|
-
.file-viewer-web-shell[data-viewer-theme='dark']
|
|
237
|
-
.file-viewer-web-shell[data-viewer-theme='
|
|
238
|
-
.file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-search input{background:rgba(15,23,42,.78);color:#f8fafc}
|
|
239
|
-
.file-viewer-web-shell[data-viewer-theme='dark'] .file-viewer-web-search-count{color:#cbd5e1}
|
|
240
|
-
@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}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-search input{background:rgba(15,23,42,.78);color:#f8fafc}.file-viewer-web-shell[data-viewer-theme='system'] .file-viewer-web-search-count{color:#cbd5e1}}
|
|
244
|
+
.file-viewer-web-shell[data-viewer-theme='dark']{--file-viewer-toolbar-bg:rgba(15,23,42,.9);--file-viewer-toolbar-border:rgba(148,163,184,.18);--file-viewer-button-color:#d7dee8;--file-viewer-input-bg:rgba(15,23,42,.78);--file-viewer-input-color:#f8fafc;--file-viewer-muted:#cbd5e1}
|
|
245
|
+
@media (prefers-color-scheme:dark){.file-viewer-web-shell[data-viewer-theme='system']{--file-viewer-toolbar-bg:rgba(15,23,42,.9);--file-viewer-toolbar-border:rgba(148,163,184,.18);--file-viewer-button-color:#d7dee8;--file-viewer-input-bg:rgba(15,23,42,.78);--file-viewer-input-color:#f8fafc;--file-viewer-muted:#cbd5e1}}
|
|
241
246
|
@media (max-width:640px){.file-viewer-web-toolbar{max-width:100%;overflow-x:auto}.file-viewer-web-toolbar[data-toolbar-position="bottom-right"]{max-width:calc(100% - 32px)}.file-viewer-web-search input{width:120px}}
|
|
242
247
|
`;
|
|
248
|
+
const addPart = (element, ...parts) => {
|
|
249
|
+
const partList = element.part;
|
|
250
|
+
if (partList === null || partList === void 0 ? void 0 : partList.add) {
|
|
251
|
+
partList.add(...parts);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const nextParts = new Set([
|
|
255
|
+
...(element.getAttribute('part') || '').split(/\s+/).filter(Boolean),
|
|
256
|
+
...parts,
|
|
257
|
+
]);
|
|
258
|
+
element.setAttribute('part', [...nextParts].join(' '));
|
|
259
|
+
};
|
|
243
260
|
const createButton = (documentRef, label, className, onClick) => {
|
|
244
261
|
const button = documentRef.createElement('button');
|
|
245
262
|
button.type = 'button';
|
|
246
263
|
button.className = className;
|
|
264
|
+
addPart(button, 'button');
|
|
247
265
|
button.textContent = label;
|
|
248
266
|
button.title = label;
|
|
249
267
|
button.setAttribute('aria-label', label);
|
|
@@ -255,27 +273,47 @@ const createButton = (documentRef, label, className, onClick) => {
|
|
|
255
273
|
const createReadonlyMeter = (documentRef, label, className) => {
|
|
256
274
|
const meter = documentRef.createElement('span');
|
|
257
275
|
meter.className = `${className} file-viewer-web-zoom-meter--readonly`;
|
|
276
|
+
addPart(meter, 'button');
|
|
258
277
|
meter.textContent = label;
|
|
259
278
|
meter.title = label;
|
|
260
279
|
meter.setAttribute('aria-label', label);
|
|
261
280
|
return meter;
|
|
262
281
|
};
|
|
263
282
|
export const mountViewer = (container, initialOptions = {}, coreOptions = {}) => {
|
|
283
|
+
var _a, _b;
|
|
264
284
|
if (!isBrowser()) {
|
|
265
285
|
throw new Error('Flyfish File Viewer can only be mounted in a browser DOM environment.');
|
|
266
286
|
}
|
|
267
287
|
const documentRef = container.ownerDocument;
|
|
268
|
-
const
|
|
269
|
-
|
|
288
|
+
const initialStyleIsolation = normalizeFileViewerStyleIsolation((_a = initialOptions.options) === null || _a === void 0 ? void 0 : _a.styleIsolation);
|
|
289
|
+
const containerRoot = (_b = container.getRootNode) === null || _b === void 0 ? void 0 : _b.call(container);
|
|
290
|
+
const canReuseExistingShadowRoot = isFileViewerShadowRoot(containerRoot);
|
|
291
|
+
const shouldUseShadowRoot = initialStyleIsolation === 'auto' || initialStyleIsolation === 'shadow';
|
|
292
|
+
const existingHostShadowRoot = shouldUseShadowRoot ? container.shadowRoot : null;
|
|
293
|
+
const canAttachShadowRoot = typeof container.attachShadow === 'function' && !container.shadowRoot;
|
|
294
|
+
const shouldAttachShadowRoot = shouldUseShadowRoot &&
|
|
295
|
+
!canReuseExistingShadowRoot &&
|
|
296
|
+
!existingHostShadowRoot &&
|
|
297
|
+
canAttachShadowRoot;
|
|
298
|
+
const renderRoot = shouldAttachShadowRoot
|
|
299
|
+
? container.attachShadow({ mode: 'open', delegatesFocus: true })
|
|
300
|
+
: existingHostShadowRoot || container;
|
|
301
|
+
renderRoot.replaceChildren();
|
|
302
|
+
const styleHandle = appendFileViewerStyle(renderRoot, WEB_VIEWER_STYLE, {
|
|
303
|
+
adoptedStyleSheet: isFileViewerShadowRoot(renderRoot),
|
|
304
|
+
});
|
|
270
305
|
const shell = documentRef.createElement('div');
|
|
271
306
|
shell.className = 'file-viewer-web-shell';
|
|
307
|
+
addPart(shell, 'shell');
|
|
272
308
|
const toolbarEl = documentRef.createElement('div');
|
|
273
309
|
toolbarEl.className = 'file-viewer-web-toolbar';
|
|
310
|
+
addPart(toolbarEl, 'toolbar');
|
|
274
311
|
const contentEl = documentRef.createElement('div');
|
|
275
312
|
contentEl.className = 'file-viewer-web-content';
|
|
313
|
+
addPart(contentEl, 'content');
|
|
276
314
|
contentEl.dataset.viewerScrollContainer = 'true';
|
|
277
315
|
shell.append(toolbarEl, contentEl);
|
|
278
|
-
|
|
316
|
+
renderRoot.appendChild(shell);
|
|
279
317
|
let disposed = false;
|
|
280
318
|
let currentOptions = initialOptions;
|
|
281
319
|
let currentSource = hasSource(currentOptions)
|
|
@@ -341,7 +379,6 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
341
379
|
return !!((_a = renderer === null || renderer === void 0 ? void 0 : renderer.capabilities) === null || _a === void 0 ? void 0 : _a.search);
|
|
342
380
|
};
|
|
343
381
|
const renderToolbar = () => {
|
|
344
|
-
var _a, _b;
|
|
345
382
|
if (disposed) {
|
|
346
383
|
return;
|
|
347
384
|
}
|
|
@@ -362,16 +399,22 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
362
399
|
if (!showToolbar) {
|
|
363
400
|
return;
|
|
364
401
|
}
|
|
365
|
-
|
|
402
|
+
const appendSearchToolbar = () => {
|
|
403
|
+
var _a, _b;
|
|
404
|
+
if (!showSearchToolbar) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
366
407
|
const searchState = state.search;
|
|
367
408
|
const searchTotal = (_a = searchState === null || searchState === void 0 ? void 0 : searchState.total) !== null && _a !== void 0 ? _a : 0;
|
|
368
409
|
const currentIndex = searchTotal > 0 ? ((_b = searchState === null || searchState === void 0 ? void 0 : searchState.currentIndex) !== null && _b !== void 0 ? _b : -1) + 1 : 0;
|
|
369
410
|
const group = documentRef.createElement('form');
|
|
370
411
|
group.className = 'file-viewer-web-toolbar-group file-viewer-web-search';
|
|
412
|
+
addPart(group, 'toolbar-group');
|
|
371
413
|
group.setAttribute('role', 'search');
|
|
372
414
|
group.setAttribute('aria-label', t('toolbar.search'));
|
|
373
415
|
const input = documentRef.createElement('input');
|
|
374
416
|
input.type = 'search';
|
|
417
|
+
addPart(input, 'input');
|
|
375
418
|
input.value = searchDraft;
|
|
376
419
|
input.placeholder = t('toolbar.searchPlaceholder');
|
|
377
420
|
input.title = t('toolbar.searchPlaceholder');
|
|
@@ -382,6 +425,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
382
425
|
});
|
|
383
426
|
const searchButton = documentRef.createElement('button');
|
|
384
427
|
searchButton.type = 'submit';
|
|
428
|
+
addPart(searchButton, 'button');
|
|
385
429
|
searchButton.textContent = t('toolbar.search');
|
|
386
430
|
searchButton.title = t('toolbar.search');
|
|
387
431
|
searchButton.setAttribute('aria-label', t('toolbar.search'));
|
|
@@ -403,6 +447,7 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
403
447
|
clearButton.disabled = toolbarDisabled || (!searchDraft && !(searchState === null || searchState === void 0 ? void 0 : searchState.query));
|
|
404
448
|
const count = documentRef.createElement('span');
|
|
405
449
|
count.className = 'file-viewer-web-search-count';
|
|
450
|
+
addPart(count, 'toolbar-status');
|
|
406
451
|
count.textContent = `${currentIndex}/${searchTotal}`;
|
|
407
452
|
count.setAttribute('aria-live', 'polite');
|
|
408
453
|
group.addEventListener('submit', event => {
|
|
@@ -413,10 +458,14 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
413
458
|
});
|
|
414
459
|
group.append(input, searchButton, previousButton, nextButton, clearButton, count);
|
|
415
460
|
toolbarEl.appendChild(group);
|
|
416
|
-
}
|
|
417
|
-
|
|
461
|
+
};
|
|
462
|
+
const appendZoomToolbar = () => {
|
|
463
|
+
if (!visibleToolbar.zoom) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
418
466
|
const group = documentRef.createElement('div');
|
|
419
467
|
group.className = 'file-viewer-web-toolbar-group';
|
|
468
|
+
addPart(group, 'toolbar-group');
|
|
420
469
|
group.setAttribute('aria-label', t('toolbar.zoomGroup'));
|
|
421
470
|
if (availability.zoomOut) {
|
|
422
471
|
const button = createButton(documentRef, '-', 'file-viewer-web-icon-button', () => controller === null || controller === void 0 ? void 0 : controller.zoomOut());
|
|
@@ -471,25 +520,33 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
471
520
|
if (group.childElementCount) {
|
|
472
521
|
toolbarEl.appendChild(group);
|
|
473
522
|
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if (visibleToolbar.print) {
|
|
482
|
-
const button = createButton(documentRef, t('toolbar.print'), '', () => controller === null || controller === void 0 ? void 0 : controller.printRenderedHtml());
|
|
483
|
-
button.title = t('toolbar.printTitle');
|
|
484
|
-
button.disabled = toolbarDisabled;
|
|
485
|
-
toolbarEl.appendChild(button);
|
|
486
|
-
}
|
|
487
|
-
if (visibleToolbar.exportHtml) {
|
|
488
|
-
const button = createButton(documentRef, t('toolbar.exportHtml'), '', () => controller === null || controller === void 0 ? void 0 : controller.exportRenderedHtml());
|
|
489
|
-
button.title = t('toolbar.exportHtmlTitle');
|
|
523
|
+
};
|
|
524
|
+
const appendToolbarButton = (visible, label, title, onClick) => {
|
|
525
|
+
if (!visible) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const button = createButton(documentRef, label, '', onClick);
|
|
529
|
+
button.title = title;
|
|
490
530
|
button.disabled = toolbarDisabled;
|
|
491
531
|
toolbarEl.appendChild(button);
|
|
492
|
-
}
|
|
532
|
+
};
|
|
533
|
+
resolveFileViewerToolbarOrder(toolbar).forEach(item => {
|
|
534
|
+
if (item === 'search') {
|
|
535
|
+
appendSearchToolbar();
|
|
536
|
+
}
|
|
537
|
+
else if (item === 'zoom') {
|
|
538
|
+
appendZoomToolbar();
|
|
539
|
+
}
|
|
540
|
+
else if (item === 'download') {
|
|
541
|
+
appendToolbarButton(visibleToolbar.download, t('toolbar.download'), t('toolbar.downloadTitle'), () => controller === null || controller === void 0 ? void 0 : controller.downloadOriginalFile());
|
|
542
|
+
}
|
|
543
|
+
else if (item === 'print') {
|
|
544
|
+
appendToolbarButton(visibleToolbar.print, t('toolbar.print'), t('toolbar.printTitle'), () => controller === null || controller === void 0 ? void 0 : controller.printRenderedHtml());
|
|
545
|
+
}
|
|
546
|
+
else if (item === 'exportHtml') {
|
|
547
|
+
appendToolbarButton(visibleToolbar.exportHtml, t('toolbar.exportHtml'), t('toolbar.exportHtmlTitle'), () => controller === null || controller === void 0 ? void 0 : controller.exportRenderedHtml());
|
|
548
|
+
}
|
|
549
|
+
});
|
|
493
550
|
};
|
|
494
551
|
const notifyState = (event) => {
|
|
495
552
|
var _a;
|
|
@@ -636,7 +693,8 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
636
693
|
disposed = true;
|
|
637
694
|
cancel();
|
|
638
695
|
void instance.destroy('component-unmount');
|
|
639
|
-
|
|
696
|
+
styleHandle.remove();
|
|
697
|
+
renderRoot.replaceChildren();
|
|
640
698
|
},
|
|
641
699
|
getApi() {
|
|
642
700
|
return instance;
|
|
@@ -659,6 +717,9 @@ export const mountViewer = (container, initialOptions = {}, coreOptions = {}) =>
|
|
|
659
717
|
resetZoom() {
|
|
660
718
|
return callApi(instance, api => api.resetZoom(), null);
|
|
661
719
|
},
|
|
720
|
+
fitToView(fit) {
|
|
721
|
+
return callApi(instance, api => api.fitToView(fit), null);
|
|
722
|
+
},
|
|
662
723
|
getViewState() {
|
|
663
724
|
return instance.getViewState();
|
|
664
725
|
},
|
package/dist/element.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FileRef, type ViewerController, type ViewerControllerHandle, type ViewerCoreOptions, type ViewerEvent, type ViewerMountOptions, type ViewerOptions, type ViewerState, type ViewerStateListener } from './controller.js';
|
|
1
|
+
import { type FileRef, type ViewerController, type ViewerControllerHandle, type ViewerCoreOptions, type ViewerEvent, type ViewerFitMode, type ViewerFitOptions, type ViewerMountOptions, type ViewerOptions, type ViewerState, type ViewerStateListener } from './controller.js';
|
|
2
2
|
export declare const FILE_VIEWER_ELEMENT_TAG = "flyfish-file-viewer";
|
|
3
3
|
export type FileViewerElementEventName = 'viewer-ready' | 'viewer-event' | 'viewer-state-change' | 'viewer-error';
|
|
4
4
|
export interface FileViewerElementReadyDetail {
|
|
@@ -15,7 +15,7 @@ export interface FileViewerElementSource extends ViewerMountOptions {
|
|
|
15
15
|
coreOptions?: ViewerCoreOptions;
|
|
16
16
|
}
|
|
17
17
|
declare const ElementBase: typeof HTMLElement;
|
|
18
|
-
declare const observedAttributes: readonly ["src", "url", "filename", "name", "type", "size", "locale", "theme", "toolbar", "toolbar-position", "watermark", "search", "options"];
|
|
18
|
+
declare const observedAttributes: readonly ["src", "url", "filename", "name", "type", "size", "locale", "theme", "toolbar", "toolbar-position", "watermark", "search", "fit", "style-isolation", "options"];
|
|
19
19
|
type ObservedAttributeName = typeof observedAttributes[number];
|
|
20
20
|
export declare class FileViewerElement extends ElementBase implements ViewerControllerHandle {
|
|
21
21
|
static get observedAttributes(): ObservedAttributeName[];
|
|
@@ -44,6 +44,10 @@ export declare class FileViewerElement extends ElementBase implements ViewerCont
|
|
|
44
44
|
set options(value: ViewerOptions | undefined);
|
|
45
45
|
get locale(): ViewerOptions['locale'] | undefined;
|
|
46
46
|
set locale(value: ViewerOptions['locale'] | undefined);
|
|
47
|
+
get fit(): ViewerOptions['fit'] | undefined;
|
|
48
|
+
set fit(value: ViewerOptions['fit'] | undefined);
|
|
49
|
+
get styleIsolation(): ViewerOptions['styleIsolation'] | undefined;
|
|
50
|
+
set styleIsolation(value: ViewerOptions['styleIsolation'] | undefined);
|
|
47
51
|
get source(): FileViewerElementSource;
|
|
48
52
|
set source(value: FileViewerElementSource | undefined);
|
|
49
53
|
get coreOptions(): ViewerCoreOptions;
|
|
@@ -63,6 +67,7 @@ export declare class FileViewerElement extends ElementBase implements ViewerCont
|
|
|
63
67
|
zoomIn(): ReturnType<ViewerControllerHandle['zoomIn']>;
|
|
64
68
|
zoomOut(): ReturnType<ViewerControllerHandle['zoomOut']>;
|
|
65
69
|
resetZoom(): ReturnType<ViewerControllerHandle['resetZoom']>;
|
|
70
|
+
fitToView(fit?: ViewerFitMode | ViewerFitOptions): ReturnType<ViewerControllerHandle['fitToView']>;
|
|
66
71
|
getViewState(): ReturnType<ViewerControllerHandle['getViewState']>;
|
|
67
72
|
applyViewState(state: Parameters<ViewerControllerHandle['applyViewState']>[0], options?: Parameters<ViewerControllerHandle['applyViewState']>[1]): ReturnType<ViewerControllerHandle['applyViewState']>;
|
|
68
73
|
searchDocument(query: string): ReturnType<ViewerControllerHandle['searchDocument']>;
|
|
@@ -83,6 +88,7 @@ export declare class FileViewerElement extends ElementBase implements ViewerCont
|
|
|
83
88
|
private remount;
|
|
84
89
|
private remountOrUpdate;
|
|
85
90
|
private ensureMountNode;
|
|
91
|
+
private resolveElementRenderRoot;
|
|
86
92
|
private createEffectiveMountOptions;
|
|
87
93
|
private readAttributeMountOptions;
|
|
88
94
|
private readAttributeViewerOptions;
|