@vertexvis/doc-viewer 1.0.2-canary.7 → 1.0.2-testing.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/dist/cjs/vertex-document-viewer.cjs.entry.js +32 -19
- package/dist/collection/__mocks__/pdfjs-mock.js +1 -2
- package/dist/collection/components/document-viewer/document-viewer.css +0 -11
- 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 +0 -3
- package/dist/collection/lib/pdf/pdfjs-renderer.js +1 -10
- package/dist/components/vertex-document-viewer.js +2 -2
- package/dist/doc-viewer/doc-viewer.esm.js +1 -1
- package/dist/doc-viewer/{p-96109c78.entry.js → p-d397d116.entry.js} +2 -2
- package/dist/esm/vertex-document-viewer.entry.js +32 -19
- package/dist/types/__mocks__/pdfjs-mock.d.ts +2 -2
- package/dist/types/components/document-viewer/document-viewer.d.ts +1 -0
- package/dist/types/lib/document/layers/controller.d.ts +3 -1
- package/dist/types/lib/dom.d.ts +0 -1
- package/package.json +4 -4
|
@@ -625,10 +625,22 @@ function apiSupportsLayers(api) {
|
|
|
625
625
|
class DocumentLayersController {
|
|
626
626
|
constructor(api) {
|
|
627
627
|
this.apiSupportsLayers = false;
|
|
628
|
+
if (api != null) {
|
|
629
|
+
this.setApi(api);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
setApi(api) {
|
|
628
633
|
if (apiSupportsLayers(api)) {
|
|
629
634
|
this.apiSupportsLayers = true;
|
|
630
635
|
this.api = api;
|
|
631
636
|
}
|
|
637
|
+
else {
|
|
638
|
+
this.clear();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
clear() {
|
|
642
|
+
this.apiSupportsLayers = false;
|
|
643
|
+
this.api = undefined;
|
|
632
644
|
}
|
|
633
645
|
/**
|
|
634
646
|
* Returns a boolean indicating whether the document supports layers.
|
|
@@ -663,9 +675,6 @@ class DocumentLayersController {
|
|
|
663
675
|
function getElementBoundingClientRect(element) {
|
|
664
676
|
return element.getBoundingClientRect();
|
|
665
677
|
}
|
|
666
|
-
function createElement(tagName) {
|
|
667
|
-
return document.createElement(tagName);
|
|
668
|
-
}
|
|
669
678
|
function getAllVertexElementChildren(element) {
|
|
670
679
|
return getAllChildren(element)
|
|
671
680
|
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
@@ -34548,7 +34557,7 @@ class PdfJsRenderer extends DocumentRenderer {
|
|
|
34548
34557
|
this.state = { pages: {}, rendering: false };
|
|
34549
34558
|
// Render pages using an offscreen canvas to avoid flickering that can occur for
|
|
34550
34559
|
// PDFs with annotations.
|
|
34551
|
-
this.offscreenCanvas = createElement('canvas');
|
|
34560
|
+
this.offscreenCanvas = document.createElement('canvas');
|
|
34552
34561
|
this.handleStateChanged = this.handleStateChanged.bind(this);
|
|
34553
34562
|
this.stateChangedDisposable = this.api.onStateChanged(this.handleStateChanged);
|
|
34554
34563
|
}
|
|
@@ -34590,18 +34599,10 @@ class PdfJsRenderer extends DocumentRenderer {
|
|
|
34590
34599
|
});
|
|
34591
34600
|
this.offscreenCanvas.width = this.canvas.width;
|
|
34592
34601
|
this.offscreenCanvas.height = this.canvas.height;
|
|
34593
|
-
const offscreenCanvasCtx = this.offscreenCanvas.getContext('2d');
|
|
34594
|
-
// Fill the offscreen canvas with a white background prior to rendering the page to give the content
|
|
34595
|
-
// of the PDF a white background, but maintain the canvas it gets drawn to when copying to the main canvas.
|
|
34596
|
-
if (offscreenCanvasCtx != null) {
|
|
34597
|
-
offscreenCanvasCtx.fillStyle = '#ffffff';
|
|
34598
|
-
offscreenCanvasCtx.fillRect(panOffset.x + centerOffsetX, panOffset.y, scaled.width, scaled.height);
|
|
34599
|
-
}
|
|
34600
34602
|
await page.render({
|
|
34601
34603
|
canvas: this.offscreenCanvas,
|
|
34602
34604
|
viewport: scaled,
|
|
34603
34605
|
intent: 'display',
|
|
34604
|
-
background: 'transparent',
|
|
34605
34606
|
optionalContentConfigPromise: optionalContentConfig != null ? Promise.resolve(optionalContentConfig) : undefined,
|
|
34606
34607
|
}).promise;
|
|
34607
34608
|
// Emit an event before the page is drawn, then draw the page to the canvas on the next
|
|
@@ -34631,7 +34632,7 @@ class PdfJsProvider {
|
|
|
34631
34632
|
}
|
|
34632
34633
|
}
|
|
34633
34634
|
|
|
34634
|
-
const documentViewerCss = () => `:host{display:block;position:relative;width:300px;height:300px;min-width:1px;min-height:1px;user-select:none;-webkit-user-select:none
|
|
34635
|
+
const documentViewerCss = () => `:host{display:block;position:relative;width:300px;height:300px;min-width:1px;min-height:1px;user-select:none;-webkit-user-select:none}.viewer-container{width:100%;height:100%;overflow:hidden}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative}`;
|
|
34635
34636
|
|
|
34636
34637
|
const VertexDocumentViewer = class {
|
|
34637
34638
|
constructor(hostRef) {
|
|
@@ -34663,6 +34664,7 @@ const VertexDocumentViewer = class {
|
|
|
34663
34664
|
this.handleDocumentApiStateChanged = this.handleDocumentApiStateChanged.bind(this);
|
|
34664
34665
|
this.handlePageLoaded = this.handlePageLoaded.bind(this);
|
|
34665
34666
|
this.handlePageDrawn = this.handlePageDrawn.bind(this);
|
|
34667
|
+
this.layers = new DocumentLayersController();
|
|
34666
34668
|
this.resizeObserver = new ResizeObserver(this.handleElementResize);
|
|
34667
34669
|
this.registerSlotChangeListeners();
|
|
34668
34670
|
}
|
|
@@ -34675,7 +34677,7 @@ const VertexDocumentViewer = class {
|
|
|
34675
34677
|
var _a;
|
|
34676
34678
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
|
|
34677
34679
|
this.updateComponentDimensions();
|
|
34678
|
-
this.
|
|
34680
|
+
this.loadInitialSrc();
|
|
34679
34681
|
this.injectViewerApi();
|
|
34680
34682
|
}
|
|
34681
34683
|
disconnectedCallback() {
|
|
@@ -34742,12 +34744,13 @@ const VertexDocumentViewer = class {
|
|
|
34742
34744
|
await documentApi.loadPage(pageNumber);
|
|
34743
34745
|
}
|
|
34744
34746
|
async handleSrcChange() {
|
|
34747
|
+
var _a;
|
|
34745
34748
|
if (this.src != null && this.canvasEl != null) {
|
|
34746
34749
|
this.clearCurrentDocument();
|
|
34747
34750
|
const { api, renderer } = this.provider.create(this.canvasEl, this.config);
|
|
34748
34751
|
this.documentApi = api;
|
|
34749
34752
|
this.documentRenderer = renderer;
|
|
34750
|
-
this.layers
|
|
34753
|
+
(_a = this.layers) === null || _a === void 0 ? void 0 : _a.setApi(api);
|
|
34751
34754
|
this.updateInteractionHandler();
|
|
34752
34755
|
this.updateDocumentApiListeners();
|
|
34753
34756
|
await this.documentApi.updateViewport(this.dimensions);
|
|
@@ -34764,9 +34767,9 @@ const VertexDocumentViewer = class {
|
|
|
34764
34767
|
this.updateInteractionHandler();
|
|
34765
34768
|
}
|
|
34766
34769
|
render() {
|
|
34767
|
-
return (index.h(index.Host, { key: '
|
|
34770
|
+
return (index.h(index.Host, { key: 'a990831d5f2328f2cf21be0b82d4018b05decd51' }, index.h("div", { key: '349abae36254da570e640417fab459680c576465', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, index.h("div", { key: '6fca3f1d5a2c31bdcc0c8dbbd468e306db981740', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
|
|
34768
34771
|
'enable-pointer-events ': window.PointerEvent != null,
|
|
34769
|
-
}) }, index.h("canvas", { key: '
|
|
34772
|
+
}) }, index.h("canvas", { key: 'fe22d0a0cbe37951495420fb8efe6ca1062c38a7', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: '08c7488d0a52bdb369a5a1b70070f3f15da75e3c' }))));
|
|
34770
34773
|
}
|
|
34771
34774
|
getDocumentApi() {
|
|
34772
34775
|
if (this.documentApi == null) {
|
|
@@ -34774,15 +34777,25 @@ const VertexDocumentViewer = class {
|
|
|
34774
34777
|
}
|
|
34775
34778
|
return this.documentApi;
|
|
34776
34779
|
}
|
|
34780
|
+
async loadInitialSrc() {
|
|
34781
|
+
await Promise.resolve();
|
|
34782
|
+
await this.handleSrcChange();
|
|
34783
|
+
}
|
|
34777
34784
|
clearCurrentDocument() {
|
|
34778
|
-
var _a, _b, _c, _d, _e, _f;
|
|
34785
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
34779
34786
|
(_a = this.documentRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
34780
34787
|
(_b = this.documentApi) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
34781
34788
|
(_c = this.panInteractionHandler) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
34782
34789
|
(_d = this.documentApiStateChangedDisposable) === null || _d === void 0 ? void 0 : _d.dispose();
|
|
34783
34790
|
(_e = this.pageLoadedDisposable) === null || _e === void 0 ? void 0 : _e.dispose();
|
|
34784
34791
|
(_f = this.pageDrawnDisposable) === null || _f === void 0 ? void 0 : _f.dispose();
|
|
34785
|
-
this.
|
|
34792
|
+
this.documentRenderer = undefined;
|
|
34793
|
+
this.documentApi = undefined;
|
|
34794
|
+
this.panInteractionHandler = undefined;
|
|
34795
|
+
this.documentApiStateChangedDisposable = undefined;
|
|
34796
|
+
this.pageLoadedDisposable = undefined;
|
|
34797
|
+
this.pageDrawnDisposable = undefined;
|
|
34798
|
+
(_g = this.layers) === null || _g === void 0 ? void 0 : _g.clear();
|
|
34786
34799
|
}
|
|
34787
34800
|
handleDocumentApiStateChanged(state) {
|
|
34788
34801
|
this.documentState = state;
|
|
@@ -8,8 +8,7 @@ export class MockOptionalContentConfig extends Map {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export const mockGetViewport = jest.fn(() => ({ width: 100, height: 100 }));
|
|
11
|
-
|
|
12
|
-
export const mockPageRender = jest.fn((args) => ({ promise: Promise.resolve() }));
|
|
11
|
+
export const mockPageRender = jest.fn(() => ({ promise: Promise.resolve() }));
|
|
13
12
|
export const mockGetPage = jest.fn(() => ({
|
|
14
13
|
getTextContent: jest.fn(() => ({
|
|
15
14
|
items: [],
|
|
@@ -8,13 +8,6 @@
|
|
|
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 #cccccc.
|
|
16
|
-
*/
|
|
17
|
-
--viewer-background: #cccccc;
|
|
18
11
|
}
|
|
19
12
|
|
|
20
13
|
.viewer-container {
|
|
@@ -31,7 +24,3 @@
|
|
|
31
24
|
height: 100%;
|
|
32
25
|
position: relative;
|
|
33
26
|
}
|
|
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: 'fe22d0a0cbe37951495420fb8efe6ca1062c38a7', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: '08c7488d0a52bdb369a5a1b70070f3f15da75e3c' }))));
|
|
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,9 +4,6 @@
|
|
|
4
4
|
export function getElementBoundingClientRect(element) {
|
|
5
5
|
return element.getBoundingClientRect();
|
|
6
6
|
}
|
|
7
|
-
export function createElement(tagName) {
|
|
8
|
-
return document.createElement(tagName);
|
|
9
|
-
}
|
|
10
7
|
export function getAllVertexElementChildren(element) {
|
|
11
8
|
return getAllChildren(element)
|
|
12
9
|
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Dimensions } from "@vertexvis/geometry";
|
|
5
5
|
import { DocumentRenderer } from "../document/renderer";
|
|
6
|
-
import { createElement } from "../dom";
|
|
7
6
|
export class PdfJsRenderer extends DocumentRenderer {
|
|
8
7
|
constructor(api, canvas) {
|
|
9
8
|
super(api, canvas);
|
|
10
9
|
this.state = { pages: {}, rendering: false };
|
|
11
10
|
// Render pages using an offscreen canvas to avoid flickering that can occur for
|
|
12
11
|
// PDFs with annotations.
|
|
13
|
-
this.offscreenCanvas = createElement('canvas');
|
|
12
|
+
this.offscreenCanvas = document.createElement('canvas');
|
|
14
13
|
this.handleStateChanged = this.handleStateChanged.bind(this);
|
|
15
14
|
this.stateChangedDisposable = this.api.onStateChanged(this.handleStateChanged);
|
|
16
15
|
}
|
|
@@ -52,18 +51,10 @@ export class PdfJsRenderer extends DocumentRenderer {
|
|
|
52
51
|
});
|
|
53
52
|
this.offscreenCanvas.width = this.canvas.width;
|
|
54
53
|
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
|
-
}
|
|
62
54
|
await page.render({
|
|
63
55
|
canvas: this.offscreenCanvas,
|
|
64
56
|
viewport: scaled,
|
|
65
57
|
intent: 'display',
|
|
66
|
-
background: 'transparent',
|
|
67
58
|
optionalContentConfigPromise: optionalContentConfig != null ? Promise.resolve(optionalContentConfig) : undefined,
|
|
68
59
|
}).promise;
|
|
69
60
|
// Emit an event before the page is drawn, then draw the page to the canvas on the next
|