@vertexvis/doc-viewer 1.0.2-canary.2 → 1.0.2-canary.21
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/dist/cjs/vertex-document-viewer.cjs.entry.js +125 -277
- package/dist/collection/__mocks__/pdfjs-mock.js +2 -1
- package/dist/collection/components/document-viewer/document-viewer.css +11 -0
- package/dist/collection/components/document-viewer/document-viewer.js +18 -6
- package/dist/collection/lib/document/layers/controller.js +12 -0
- package/dist/collection/lib/dom.js +3 -0
- package/dist/collection/lib/interactions/pan-interaction-handler.js +1 -1
- package/dist/collection/lib/pdf/pdfjs-renderer.js +10 -1
- package/dist/components/vertex-document-viewer.js +2 -2
- package/dist/doc-viewer/doc-viewer.esm.js +1 -1
- package/dist/doc-viewer/p-49c08e34.entry.js +25 -0
- package/dist/esm/vertex-document-viewer.entry.js +125 -277
- package/dist/types/__mocks__/pdfjs-mock.d.ts +3 -2
- package/dist/types/__setup__/polyfills.d.ts +1 -0
- package/dist/types/__setup__/resize-observer.d.ts +1 -0
- package/dist/types/components/document-viewer/document-viewer.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lib/config.d.ts +1 -0
- package/dist/types/lib/document/api.d.ts +1 -0
- package/dist/types/lib/document/layers/controller.d.ts +4 -1
- package/dist/types/lib/document/layers/index.d.ts +1 -0
- package/dist/types/lib/document/layers/types.d.ts +1 -0
- package/dist/types/lib/document/provider.d.ts +1 -0
- package/dist/types/lib/document/renderer.d.ts +1 -0
- package/dist/types/lib/dom.d.ts +2 -0
- package/dist/types/lib/index.d.ts +1 -0
- package/dist/types/lib/interactions/pan-interaction-handler.d.ts +1 -0
- package/dist/types/lib/pdf/pdfjs-api.d.ts +1 -0
- package/dist/types/lib/pdf/pdfjs-provider.d.ts +1 -0
- package/dist/types/lib/pdf/pdfjs-renderer.d.ts +1 -0
- package/dist/types/lib/types/loadableResource.d.ts +1 -0
- package/dist/types/polyfill/index.d.ts +1 -0
- package/dist/types/polyfill/resize-observer.d.ts +1 -0
- package/dist/types/testing/mock-document-api.d.ts +1 -0
- package/package.json +6 -6
- package/dist/doc-viewer/p-f5810a8d.entry.js +0 -25
|
@@ -8,7 +8,8 @@ export class MockOptionalContentConfig extends Map {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export const mockGetViewport = jest.fn(() => ({ width: 100, height: 100 }));
|
|
11
|
-
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
export const mockPageRender = jest.fn((args) => ({ promise: Promise.resolve() }));
|
|
12
13
|
export const mockGetPage = jest.fn(() => ({
|
|
13
14
|
getTextContent: jest.fn(() => ({
|
|
14
15
|
items: [],
|
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
user-select: none;
|
|
10
10
|
-webkit-user-select: none;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @prop --viewer-background:
|
|
14
|
+
* A CSS color value used as the background painted behind the loaded PDF,
|
|
15
|
+
* visible in the negative space around the page. Defaults to #eeeeee.
|
|
16
|
+
*/
|
|
17
|
+
--viewer-background: #eeeeee;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
.viewer-container {
|
|
@@ -24,3 +31,7 @@
|
|
|
24
31
|
height: 100%;
|
|
25
32
|
position: relative;
|
|
26
33
|
}
|
|
34
|
+
|
|
35
|
+
#document-viewer-canvas {
|
|
36
|
+
background-color: var(--viewer-background);
|
|
37
|
+
}
|
|
@@ -34,6 +34,7 @@ export class VertexDocumentViewer {
|
|
|
34
34
|
this.handleDocumentApiStateChanged = this.handleDocumentApiStateChanged.bind(this);
|
|
35
35
|
this.handlePageLoaded = this.handlePageLoaded.bind(this);
|
|
36
36
|
this.handlePageDrawn = this.handlePageDrawn.bind(this);
|
|
37
|
+
this.layers = new DocumentLayersController();
|
|
37
38
|
this.resizeObserver = new ResizeObserver(this.handleElementResize);
|
|
38
39
|
this.registerSlotChangeListeners();
|
|
39
40
|
}
|
|
@@ -46,7 +47,7 @@ export class VertexDocumentViewer {
|
|
|
46
47
|
var _a;
|
|
47
48
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
|
|
48
49
|
this.updateComponentDimensions();
|
|
49
|
-
this.
|
|
50
|
+
this.loadInitialSrc();
|
|
50
51
|
this.injectViewerApi();
|
|
51
52
|
}
|
|
52
53
|
disconnectedCallback() {
|
|
@@ -113,12 +114,13 @@ export class VertexDocumentViewer {
|
|
|
113
114
|
await documentApi.loadPage(pageNumber);
|
|
114
115
|
}
|
|
115
116
|
async handleSrcChange() {
|
|
117
|
+
var _a;
|
|
116
118
|
if (this.src != null && this.canvasEl != null) {
|
|
117
119
|
this.clearCurrentDocument();
|
|
118
120
|
const { api, renderer } = this.provider.create(this.canvasEl, this.config);
|
|
119
121
|
this.documentApi = api;
|
|
120
122
|
this.documentRenderer = renderer;
|
|
121
|
-
this.layers
|
|
123
|
+
(_a = this.layers) === null || _a === void 0 ? void 0 : _a.setApi(api);
|
|
122
124
|
this.updateInteractionHandler();
|
|
123
125
|
this.updateDocumentApiListeners();
|
|
124
126
|
await this.documentApi.updateViewport(this.dimensions);
|
|
@@ -135,9 +137,9 @@ export class VertexDocumentViewer {
|
|
|
135
137
|
this.updateInteractionHandler();
|
|
136
138
|
}
|
|
137
139
|
render() {
|
|
138
|
-
return (h(Host, { key: '
|
|
140
|
+
return (h(Host, { key: 'a990831d5f2328f2cf21be0b82d4018b05decd51' }, h("div", { key: '349abae36254da570e640417fab459680c576465', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, h("div", { key: '6fca3f1d5a2c31bdcc0c8dbbd468e306db981740', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
|
|
139
141
|
'enable-pointer-events ': window.PointerEvent != null,
|
|
140
|
-
}) }, h("canvas", { key: '
|
|
142
|
+
}) }, h("canvas", { key: 'deb1c58d8d20000053cd829401163bf1e68ca88e', id: "document-viewer-canvas", role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: '6b87846ef17b330b0fae5d03103765bad6fdafa6' }))));
|
|
141
143
|
}
|
|
142
144
|
getDocumentApi() {
|
|
143
145
|
if (this.documentApi == null) {
|
|
@@ -145,15 +147,25 @@ export class VertexDocumentViewer {
|
|
|
145
147
|
}
|
|
146
148
|
return this.documentApi;
|
|
147
149
|
}
|
|
150
|
+
async loadInitialSrc() {
|
|
151
|
+
await Promise.resolve();
|
|
152
|
+
await this.handleSrcChange();
|
|
153
|
+
}
|
|
148
154
|
clearCurrentDocument() {
|
|
149
|
-
var _a, _b, _c, _d, _e, _f;
|
|
155
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
150
156
|
(_a = this.documentRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
151
157
|
(_b = this.documentApi) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
152
158
|
(_c = this.panInteractionHandler) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
153
159
|
(_d = this.documentApiStateChangedDisposable) === null || _d === void 0 ? void 0 : _d.dispose();
|
|
154
160
|
(_e = this.pageLoadedDisposable) === null || _e === void 0 ? void 0 : _e.dispose();
|
|
155
161
|
(_f = this.pageDrawnDisposable) === null || _f === void 0 ? void 0 : _f.dispose();
|
|
156
|
-
this.
|
|
162
|
+
this.documentRenderer = undefined;
|
|
163
|
+
this.documentApi = undefined;
|
|
164
|
+
this.panInteractionHandler = undefined;
|
|
165
|
+
this.documentApiStateChangedDisposable = undefined;
|
|
166
|
+
this.pageLoadedDisposable = undefined;
|
|
167
|
+
this.pageDrawnDisposable = undefined;
|
|
168
|
+
(_g = this.layers) === null || _g === void 0 ? void 0 : _g.clear();
|
|
157
169
|
}
|
|
158
170
|
handleDocumentApiStateChanged(state) {
|
|
159
171
|
this.documentState = state;
|
|
@@ -5,10 +5,22 @@ import { apiSupportsLayers } from "./types";
|
|
|
5
5
|
export class DocumentLayersController {
|
|
6
6
|
constructor(api) {
|
|
7
7
|
this.apiSupportsLayers = false;
|
|
8
|
+
if (api != null) {
|
|
9
|
+
this.setApi(api);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
setApi(api) {
|
|
8
13
|
if (apiSupportsLayers(api)) {
|
|
9
14
|
this.apiSupportsLayers = true;
|
|
10
15
|
this.api = api;
|
|
11
16
|
}
|
|
17
|
+
else {
|
|
18
|
+
this.clear();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this.apiSupportsLayers = false;
|
|
23
|
+
this.api = undefined;
|
|
12
24
|
}
|
|
13
25
|
/**
|
|
14
26
|
* Returns a boolean indicating whether the document supports layers.
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
export function getElementBoundingClientRect(element) {
|
|
5
5
|
return element.getBoundingClientRect();
|
|
6
6
|
}
|
|
7
|
+
export function createElement(tagName) {
|
|
8
|
+
return document.createElement(tagName);
|
|
9
|
+
}
|
|
7
10
|
export function getAllVertexElementChildren(element) {
|
|
8
11
|
return getAllChildren(element)
|
|
9
12
|
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Dimensions } from "@vertexvis/geometry";
|
|
5
5
|
import { DocumentRenderer } from "../document/renderer";
|
|
6
|
+
import { createElement } from "../dom";
|
|
6
7
|
export class PdfJsRenderer extends DocumentRenderer {
|
|
7
8
|
constructor(api, canvas) {
|
|
8
9
|
super(api, canvas);
|
|
9
10
|
this.state = { pages: {}, rendering: false };
|
|
10
11
|
// Render pages using an offscreen canvas to avoid flickering that can occur for
|
|
11
12
|
// PDFs with annotations.
|
|
12
|
-
this.offscreenCanvas =
|
|
13
|
+
this.offscreenCanvas = createElement('canvas');
|
|
13
14
|
this.handleStateChanged = this.handleStateChanged.bind(this);
|
|
14
15
|
this.stateChangedDisposable = this.api.onStateChanged(this.handleStateChanged);
|
|
15
16
|
}
|
|
@@ -51,10 +52,18 @@ export class PdfJsRenderer extends DocumentRenderer {
|
|
|
51
52
|
});
|
|
52
53
|
this.offscreenCanvas.width = this.canvas.width;
|
|
53
54
|
this.offscreenCanvas.height = this.canvas.height;
|
|
55
|
+
const offscreenCanvasCtx = this.offscreenCanvas.getContext('2d');
|
|
56
|
+
// Fill the offscreen canvas with a white background prior to rendering the page to give the content
|
|
57
|
+
// of the PDF a white background, but maintain the canvas it gets drawn to when copying to the main canvas.
|
|
58
|
+
if (offscreenCanvasCtx != null) {
|
|
59
|
+
offscreenCanvasCtx.fillStyle = '#ffffff';
|
|
60
|
+
offscreenCanvasCtx.fillRect(panOffset.x + centerOffsetX, panOffset.y, scaled.width, scaled.height);
|
|
61
|
+
}
|
|
54
62
|
await page.render({
|
|
55
63
|
canvas: this.offscreenCanvas,
|
|
56
64
|
viewport: scaled,
|
|
57
65
|
intent: 'display',
|
|
66
|
+
background: 'transparent',
|
|
58
67
|
optionalContentConfigPromise: optionalContentConfig != null ? Promise.resolve(optionalContentConfig) : undefined,
|
|
59
68
|
}).promise;
|
|
60
69
|
// Emit an event before the page is drawn, then draw the page to the canvas on the next
|