@file-viewer/core 2.4.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +18 -1
- package/README.md +18 -1
- package/dist/config/options.js +9 -3
- package/dist/contracts/types.d.ts +12 -8
- package/dist/export.d.ts +10 -0
- package/dist/export.js +9 -0
- package/dist/exportDocument.d.ts +36 -0
- package/dist/exportDocument.js +848 -0
- package/dist/features/printMask.js +138 -13
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/output/export.d.ts +3 -24
- package/dist/output/export.js +27 -372
- package/dist/registry/capabilities.d.ts +2 -2
- package/dist/registry/formats.d.ts +4 -4
- package/dist/registry/formats.generated.d.ts +57 -19
- package/dist/registry/formats.generated.js +101 -2
- package/dist/renderers/index.d.ts +55 -17
- package/dist/security/svgResources.d.ts +13 -0
- package/dist/security/svgResources.js +177 -0
- package/dist/viewer/createViewer.js +42 -0
- package/dist/viewer/operations.d.ts +1 -0
- package/dist/viewer/operations.js +68 -5
- package/package.json +9 -1
package/README.en.md
CHANGED
|
@@ -66,9 +66,26 @@ const viewer = createViewer(document.querySelector('#viewer')!, {
|
|
|
66
66
|
await viewer.load({ url: '/files/report.pdf' })
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
HTML document builders live in the opt-in export entry so ordinary previews do
|
|
70
|
+
not download the sanitizer. The viewer's `exportHtml()` and `print()` methods
|
|
71
|
+
load this entry only when invoked. For v3, migrate direct builder imports from
|
|
72
|
+
the package root to the explicit subpath:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {
|
|
76
|
+
buildExportHtmlDocument,
|
|
77
|
+
buildFileViewerRenderedHtmlDocument
|
|
78
|
+
} from '@file-viewer/core/export'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The deprecated Vue 3 template re-exports are asynchronous in v3 to preserve
|
|
82
|
+
this lazy boundary, so legacy calls must use `await buildExportHtmlDocument(...)`
|
|
83
|
+
or `await collectDocumentStyles()`. Direct imports from the `export` subpath
|
|
84
|
+
keep their documented return types.
|
|
85
|
+
|
|
69
86
|
`options.styleIsolation` accepts `auto`, `shadow`, `scoped`, or `none`. Use `shadow` when a custom host or framework wrapper needs a ShadowRoot-backed render surface. Core passes the resolved `surface` to renderer `load(context)`, so custom renderers should inject styles into `context.surface.shadowRoot` or the renderer container instead of `document.head`, and should mount overlays inside the same isolated surface when possible.
|
|
70
87
|
|
|
71
|
-
The root `@file-viewer/core` entry remains the
|
|
88
|
+
The root `@file-viewer/core` entry remains the normal browser-compatible entry. New component packages should prefer the narrowest explicit entry point they need: `headless` for contracts and build-time helpers, `browser` for real browser preview, and `export` for sanitized standalone HTML documents.
|
|
72
89
|
|
|
73
90
|
```ts
|
|
74
91
|
import {
|
package/README.md
CHANGED
|
@@ -66,9 +66,26 @@ const viewer = createViewer(document.querySelector('#viewer')!, {
|
|
|
66
66
|
await viewer.load({ url: '/files/report.pdf' })
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
HTML document builders live in the opt-in export entry so ordinary previews do
|
|
70
|
+
not download the sanitizer. The viewer's `exportHtml()` and `print()` methods
|
|
71
|
+
load this entry only when invoked. For v3, migrate direct builder imports from
|
|
72
|
+
the package root to the explicit subpath:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {
|
|
76
|
+
buildExportHtmlDocument,
|
|
77
|
+
buildFileViewerRenderedHtmlDocument
|
|
78
|
+
} from '@file-viewer/core/export'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Vue 3 模板中已弃用的兼容导出在 v3 中改为异步,以保持这条懒加载边界;
|
|
82
|
+
旧调用需要使用 `await buildExportHtmlDocument(...)` 或
|
|
83
|
+
`await collectDocumentStyles()`。直接从 `export` 子路径导入时,返回类型仍
|
|
84
|
+
按该子路径的 API 文档保持不变。
|
|
85
|
+
|
|
69
86
|
`options.styleIsolation` accepts `auto`, `shadow`, `scoped`, or `none`. Use `shadow` when a custom host or framework wrapper needs a ShadowRoot-backed render surface. Core passes the resolved `surface` to renderer `load(context)`, so custom renderers should inject styles into `context.surface.shadowRoot` or the renderer container instead of `document.head`, and should mount overlays inside the same isolated surface when possible.
|
|
70
87
|
|
|
71
|
-
The root `@file-viewer/core` entry remains the
|
|
88
|
+
The root `@file-viewer/core` entry remains the normal browser-compatible entry. New component packages should prefer the narrowest explicit entry point they need: `headless` for contracts and build-time helpers, `browser` for real browser preview, and `export` for sanitized standalone HTML documents.
|
|
72
89
|
|
|
73
90
|
```ts
|
|
74
91
|
import {
|
package/dist/config/options.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const UNSAFE_JSON_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
1
2
|
const isRecord = (value) => {
|
|
2
3
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
3
4
|
};
|
|
@@ -31,14 +32,19 @@ const sanitizeJsonValue = (value) => {
|
|
|
31
32
|
if (!isRecord(value)) {
|
|
32
33
|
return undefined;
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
+
const outputEntries = [];
|
|
35
36
|
Object.entries(value).forEach(([key, nextValue]) => {
|
|
37
|
+
if (UNSAFE_JSON_KEYS.has(key)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
36
40
|
const sanitized = sanitizeJsonValue(nextValue);
|
|
37
41
|
if (sanitized !== undefined) {
|
|
38
|
-
|
|
42
|
+
outputEntries.push([key, sanitized]);
|
|
39
43
|
}
|
|
40
44
|
});
|
|
41
|
-
return
|
|
45
|
+
return outputEntries.length
|
|
46
|
+
? Object.fromEntries(outputEntries)
|
|
47
|
+
: undefined;
|
|
42
48
|
};
|
|
43
49
|
const stripExecutionOnlyOptions = (value) => {
|
|
44
50
|
const { beforeOperation: _beforeOperation, hooks: _hooks, preset: _preset, presets: _presets, renderers: _renderers, rendererMode: _rendererMode, ...rest } = value;
|
|
@@ -28,7 +28,7 @@ export type FileViewerToolbarItem = 'search' | 'zoom' | 'download' | 'print' | '
|
|
|
28
28
|
export type FileViewerResolvedToolbarItem = 'search' | 'zoom' | 'download' | 'print' | 'exportHtml' | 'theme';
|
|
29
29
|
export type FileViewerToolbarActionMap = Partial<Record<FileViewerOperationType, boolean>>;
|
|
30
30
|
export type FileViewerRenderStateKind = 'idle' | 'loading' | 'ready' | 'empty' | 'unsupported' | 'error';
|
|
31
|
-
export type FileViewerRendererCategory = 'office' | 'document' | 'archive' | 'email' | 'eda' | 'cad' | 'model' | 'geo' | 'drawing' | 'mindmap' | 'ebook' | 'image' | 'markdown' | 'code' | 'media' | 'asset' | 'fallback';
|
|
31
|
+
export type FileViewerRendererCategory = 'office' | 'document' | 'archive' | 'email' | 'eda' | 'cad' | 'model' | 'geo' | 'drawing' | 'mindmap' | 'ebook' | 'image' | 'medical-image' | 'cryptographic-container' | 'markdown' | 'code' | 'media' | 'asset' | 'fallback';
|
|
32
32
|
export interface FileViewerWatermarkOptions {
|
|
33
33
|
enabled?: boolean;
|
|
34
34
|
text?: string;
|
|
@@ -197,8 +197,10 @@ export interface FileViewerDocxOptions {
|
|
|
197
197
|
updatePageReferences?: boolean;
|
|
198
198
|
hideWebHiddenContent?: boolean;
|
|
199
199
|
ignoreLastRenderedPageBreak?: boolean;
|
|
200
|
-
/** External DOCX links are blocked by default; internal bookmark links remain active. */
|
|
200
|
+
/** External DOC/DOCX/RTF links are blocked by default; internal bookmark links remain active. */
|
|
201
201
|
externalLinkPolicy?: 'allow' | 'block';
|
|
202
|
+
/** Linked DOC/DOCX/RTF image resources are blocked by default; embedded images remain available. */
|
|
203
|
+
externalResourcePolicy?: 'allow' | 'block';
|
|
202
204
|
/** Overrides automatic DOCX dark rendering derived from the viewer theme. */
|
|
203
205
|
darkMode?: boolean;
|
|
204
206
|
}
|
|
@@ -483,14 +485,16 @@ export interface FileViewerDrawingOptions {
|
|
|
483
485
|
/**
|
|
484
486
|
* Self-hosted diagrams.net viewer script.
|
|
485
487
|
*
|
|
486
|
-
* The default points to the viewer asset copied under
|
|
487
|
-
* `vendor/drawio/viewer-static.min.js
|
|
488
|
-
*
|
|
488
|
+
* The default points to the optional viewer asset copied under
|
|
489
|
+
* `vendor/drawio/viewer-static.min.js`. It is only requested when
|
|
490
|
+
* `preferOfficial` is explicitly enabled and never reaches public
|
|
491
|
+
* diagrams.net hosts.
|
|
489
492
|
*/
|
|
490
493
|
viewerScriptUrl?: string;
|
|
491
494
|
/**
|
|
492
|
-
* Defaults to
|
|
493
|
-
*
|
|
495
|
+
* Defaults to false so untrusted diagrams use the inert built-in SVG path.
|
|
496
|
+
* Set to true only to opt into the separately delivered diagrams.net viewer
|
|
497
|
+
* runtime. It runs in a no-same-origin iframe with a restrictive CSP.
|
|
494
498
|
*/
|
|
495
499
|
preferOfficial?: boolean;
|
|
496
500
|
/**
|
|
@@ -549,7 +553,7 @@ export interface FileViewerCadOptions {
|
|
|
549
553
|
}
|
|
550
554
|
export type FileViewerRendererMode = 'extend' | 'replace';
|
|
551
555
|
export type FileViewerBuiltinRendererPreset = 'all' | 'lite' | 'none';
|
|
552
|
-
export type FileViewerRendererPresetName = 'all' | 'lite' | 'office' | 'engineering';
|
|
556
|
+
export type FileViewerRendererPresetName = 'all' | 'lite' | 'standard' | 'office' | 'engineering';
|
|
553
557
|
export interface FileViewerAutoRendererOptions {
|
|
554
558
|
/**
|
|
555
559
|
* Uses renderer presets registered by build tooling or preset side-effect imports.
|
package/dist/export.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explicit HTML export and print-document entrypoint.
|
|
3
|
+
*
|
|
4
|
+
* This subpath owns the DOM sanitizer and is intentionally excluded from the
|
|
5
|
+
* normal viewer/headless graph. Viewer operations load it only when the user
|
|
6
|
+
* starts an HTML export or print operation.
|
|
7
|
+
*/
|
|
8
|
+
export { buildFileViewerRenderedDomDocument, buildFileViewerRenderedHtmlDocument, buildExportDomDocument, buildExportHtmlDocument, collectDocumentStyles, sanitizeFileViewerExportDocumentDom, sanitizeFileViewerExportDocumentHtml, } from './exportDocument';
|
|
9
|
+
export type { BuildExportHtmlDocumentOptions, BuildFileViewerRenderedHtmlDocumentOptions, } from './exportDocument';
|
|
10
|
+
export { inlineFileViewerBlobUrlsInHtml, prepareFileViewerRenderedContentForSnapshot, replaceFileViewerCanvasWithImages, resolveFileViewerPrintStyle, triggerFileViewerBlobDownload, triggerFileViewerUrlDownload, waitForFileViewerImages, waitForFileViewerNextPaint, waitForFileViewerPrintWindowReady, } from './output/export';
|
package/dist/export.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explicit HTML export and print-document entrypoint.
|
|
3
|
+
*
|
|
4
|
+
* This subpath owns the DOM sanitizer and is intentionally excluded from the
|
|
5
|
+
* normal viewer/headless graph. Viewer operations load it only when the user
|
|
6
|
+
* starts an HTML export or print operation.
|
|
7
|
+
*/
|
|
8
|
+
export { buildFileViewerRenderedDomDocument, buildFileViewerRenderedHtmlDocument, buildExportDomDocument, buildExportHtmlDocument, collectDocumentStyles, sanitizeFileViewerExportDocumentDom, sanitizeFileViewerExportDocumentHtml, } from './exportDocument.js';
|
|
9
|
+
export { inlineFileViewerBlobUrlsInHtml, prepareFileViewerRenderedContentForSnapshot, replaceFileViewerCanvasWithImages, resolveFileViewerPrintStyle, triggerFileViewerBlobDownload, triggerFileViewerUrlDownload, waitForFileViewerImages, waitForFileViewerNextPaint, waitForFileViewerPrintWindowReady, } from './output/export.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FileRenderExportAdapter, FileRenderExportMode, FileViewerPrintMaskOptions } from './contracts/types';
|
|
2
|
+
/**
|
|
3
|
+
* Sanitize the complete standalone export document before it is downloaded or
|
|
4
|
+
* mounted into a print window. This is deliberately enforced in core because
|
|
5
|
+
* third-party render adapters and watermark overrides are library inputs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const sanitizeFileViewerExportDocumentHtml: (html: string, documentRef?: Document) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Produce a sanitized, inert document tree for the print-window mount path.
|
|
10
|
+
* Returning DOM here avoids reinterpreting the sanitized string through a
|
|
11
|
+
* second HTML sink such as document.write or innerHTML.
|
|
12
|
+
*/
|
|
13
|
+
export declare const sanitizeFileViewerExportDocumentDom: (html: string, documentRef?: Document) => HTMLHtmlElement;
|
|
14
|
+
export interface BuildExportHtmlDocumentOptions {
|
|
15
|
+
contentHtml: string;
|
|
16
|
+
includeDocumentStyles?: boolean;
|
|
17
|
+
printStyle?: string;
|
|
18
|
+
title: string;
|
|
19
|
+
watermarkInlineStyle?: string;
|
|
20
|
+
mask?: FileViewerPrintMaskOptions | null;
|
|
21
|
+
/** Document whose Window owns the sanitizer. Defaults to the active document. */
|
|
22
|
+
documentRef?: Document;
|
|
23
|
+
}
|
|
24
|
+
export declare const collectDocumentStyles: (documentRef?: Document) => string;
|
|
25
|
+
export declare const buildExportHtmlDocument: (options: BuildExportHtmlDocumentOptions) => string;
|
|
26
|
+
export declare const buildExportDomDocument: (options: BuildExportHtmlDocumentOptions) => HTMLHtmlElement;
|
|
27
|
+
export interface BuildFileViewerRenderedHtmlDocumentOptions {
|
|
28
|
+
source: HTMLElement;
|
|
29
|
+
mode?: FileRenderExportMode;
|
|
30
|
+
title: string;
|
|
31
|
+
adapter?: FileRenderExportAdapter | null;
|
|
32
|
+
watermarkInlineStyle?: string;
|
|
33
|
+
mask?: FileViewerPrintMaskOptions | null;
|
|
34
|
+
}
|
|
35
|
+
export declare const buildFileViewerRenderedHtmlDocument: (options: BuildFileViewerRenderedHtmlDocumentOptions) => Promise<string>;
|
|
36
|
+
export declare const buildFileViewerRenderedDomDocument: (options: BuildFileViewerRenderedHtmlDocumentOptions) => Promise<HTMLHtmlElement>;
|