@vertexvis/doc-viewer 1.0.0-canary.6 → 1.0.0-canary.8
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 +30 -6
- package/dist/collection/components/document-viewer/document-viewer.js +19 -4
- package/dist/collection/lib/dom.js +8 -0
- package/dist/collection/lib/interactions/pan-interaction-handler.js +4 -3
- package/dist/components/vertex-document-viewer.js +2 -2
- package/dist/doc-viewer/doc-viewer.esm.js +1 -1
- package/dist/doc-viewer/p-00895e2d.entry.js +25 -0
- package/dist/esm/vertex-document-viewer.entry.js +30 -6
- package/dist/types/components/document-viewer/document-viewer.d.ts +3 -0
- package/dist/types/lib/dom.d.ts +1 -0
- package/dist/types/lib/interactions/pan-interaction-handler.d.ts +2 -1
- package/package.json +4 -4
- package/dist/doc-viewer/p-796f1fa7.entry.js +0 -25
|
@@ -663,11 +663,20 @@ class DocumentLayersController {
|
|
|
663
663
|
function getElementBoundingClientRect(element) {
|
|
664
664
|
return element.getBoundingClientRect();
|
|
665
665
|
}
|
|
666
|
+
function getAllVertexElementChildren(element) {
|
|
667
|
+
return getAllChildren(element)
|
|
668
|
+
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
669
|
+
.reduce((elements, element) => [...elements, element, ...getAllChildren(element)], []);
|
|
670
|
+
}
|
|
671
|
+
function getAllChildren(element) {
|
|
672
|
+
return Array.from(element.querySelectorAll('*'));
|
|
673
|
+
}
|
|
666
674
|
|
|
667
675
|
const DRAG_PIXEL_THRESHOLD = 2;
|
|
668
676
|
class PanInteractionHandler {
|
|
669
|
-
constructor(element, api) {
|
|
677
|
+
constructor(element, hostElement, api) {
|
|
670
678
|
this.element = element;
|
|
679
|
+
this.hostElement = hostElement;
|
|
671
680
|
this.api = api;
|
|
672
681
|
this.isDragging = false;
|
|
673
682
|
this.handlePointerDown = this.handlePointerDown.bind(this);
|
|
@@ -676,11 +685,12 @@ class PanInteractionHandler {
|
|
|
676
685
|
this.handleWheel = this.handleWheel.bind(this);
|
|
677
686
|
this.element.addEventListener('pointerdown', this.handlePointerDown);
|
|
678
687
|
this.element.addEventListener('wheel', this.handleWheel);
|
|
679
|
-
|
|
688
|
+
this.hostElement.addEventListener('wheel', this.handleWheel);
|
|
680
689
|
}
|
|
681
690
|
dispose() {
|
|
682
691
|
this.element.removeEventListener('pointerdown', this.handlePointerDown);
|
|
683
692
|
this.element.removeEventListener('wheel', this.handleWheel);
|
|
693
|
+
this.hostElement.removeEventListener('wheel', this.handleWheel);
|
|
684
694
|
this.removeWindowListeners();
|
|
685
695
|
}
|
|
686
696
|
handleWheel(event) {
|
|
@@ -724,7 +734,6 @@ class PanInteractionHandler {
|
|
|
724
734
|
removeWindowListeners() {
|
|
725
735
|
window.removeEventListener('pointermove', this.handlePointerMove);
|
|
726
736
|
window.removeEventListener('pointerup', this.handlePointerUp);
|
|
727
|
-
window.removeEventListener('wheel', this.handleWheel);
|
|
728
737
|
}
|
|
729
738
|
}
|
|
730
739
|
|
|
@@ -34644,6 +34653,7 @@ const VertexDocumentViewer = class {
|
|
|
34644
34653
|
this.handlePageLoaded = this.handlePageLoaded.bind(this);
|
|
34645
34654
|
this.handlePageDrawn = this.handlePageDrawn.bind(this);
|
|
34646
34655
|
this.resizeObserver = new ResizeObserver(this.handleElementResize);
|
|
34656
|
+
this.registerSlotChangeListeners();
|
|
34647
34657
|
}
|
|
34648
34658
|
componentShouldUpdate(newValue, oldValue, propName) {
|
|
34649
34659
|
// Ignore updates to the documentState property, as it is only intended to reflect the current state
|
|
@@ -34655,6 +34665,7 @@ const VertexDocumentViewer = class {
|
|
|
34655
34665
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
|
|
34656
34666
|
this.updateComponentDimensions();
|
|
34657
34667
|
this.handleSrcChange();
|
|
34668
|
+
this.injectViewerApi();
|
|
34658
34669
|
}
|
|
34659
34670
|
disconnectedCallback() {
|
|
34660
34671
|
var _a;
|
|
@@ -34742,9 +34753,9 @@ const VertexDocumentViewer = class {
|
|
|
34742
34753
|
this.updateInteractionHandler();
|
|
34743
34754
|
}
|
|
34744
34755
|
render() {
|
|
34745
|
-
return (index.h(index.Host, { key: '
|
|
34756
|
+
return (index.h(index.Host, { key: 'f1ddf0b4e321bc244a5d757e48f6d71c23caca3c' }, index.h("div", { key: '174c64c537f4b0f1c45fc6543e5b7f54515e4063', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, index.h("div", { key: '4c47dadba03b32bde017252a9a8ea7f6e6d323f3', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
|
|
34746
34757
|
'enable-pointer-events ': window.PointerEvent != null,
|
|
34747
|
-
}) }, index.h("canvas", { key: '
|
|
34758
|
+
}) }, index.h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
|
|
34748
34759
|
}
|
|
34749
34760
|
getDocumentApi() {
|
|
34750
34761
|
if (this.documentApi == null) {
|
|
@@ -34782,7 +34793,7 @@ const VertexDocumentViewer = class {
|
|
|
34782
34793
|
var _a;
|
|
34783
34794
|
(_a = this.panInteractionHandler) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
34784
34795
|
if (this.interactionMode === 'pan' && this.canvasEl != null && this.documentApi != null) {
|
|
34785
|
-
this.panInteractionHandler = new PanInteractionHandler(this.canvasEl, this.documentApi);
|
|
34796
|
+
this.panInteractionHandler = new PanInteractionHandler(this.canvasEl, this.hostEl, this.documentApi);
|
|
34786
34797
|
}
|
|
34787
34798
|
}
|
|
34788
34799
|
updateComponentDimensions(dimensions) {
|
|
@@ -34816,6 +34827,19 @@ const VertexDocumentViewer = class {
|
|
|
34816
34827
|
}
|
|
34817
34828
|
handler.initialize(this.canvasEl);
|
|
34818
34829
|
}
|
|
34830
|
+
registerSlotChangeListeners() {
|
|
34831
|
+
this.mutationObserver = new MutationObserver(_ => this.injectViewerApi());
|
|
34832
|
+
this.mutationObserver.observe(this.hostEl, {
|
|
34833
|
+
childList: true,
|
|
34834
|
+
subtree: true,
|
|
34835
|
+
});
|
|
34836
|
+
}
|
|
34837
|
+
injectViewerApi() {
|
|
34838
|
+
getAllVertexElementChildren(this.hostEl).forEach(node => {
|
|
34839
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34840
|
+
node.viewer = this.hostEl;
|
|
34841
|
+
});
|
|
34842
|
+
}
|
|
34819
34843
|
get hostEl() { return index.getElement(this); }
|
|
34820
34844
|
static get watchers() { return {
|
|
34821
34845
|
"src": [{
|
|
@@ -6,7 +6,7 @@ import { h, Host } from "@stencil/core";
|
|
|
6
6
|
import { Dimensions } from "@vertexvis/geometry";
|
|
7
7
|
import classNames from "classnames";
|
|
8
8
|
import { DocumentLayersController } from "../../lib/document/layers/controller";
|
|
9
|
-
import { getElementBoundingClientRect } from "../../lib/dom";
|
|
9
|
+
import { getAllVertexElementChildren, getElementBoundingClientRect } from "../../lib/dom";
|
|
10
10
|
import { PanInteractionHandler } from "../../lib/interactions/pan-interaction-handler";
|
|
11
11
|
import { PdfJsProvider } from "../../lib/pdf/pdfjs-provider";
|
|
12
12
|
export class VertexDocumentViewer {
|
|
@@ -35,6 +35,7 @@ export class VertexDocumentViewer {
|
|
|
35
35
|
this.handlePageLoaded = this.handlePageLoaded.bind(this);
|
|
36
36
|
this.handlePageDrawn = this.handlePageDrawn.bind(this);
|
|
37
37
|
this.resizeObserver = new ResizeObserver(this.handleElementResize);
|
|
38
|
+
this.registerSlotChangeListeners();
|
|
38
39
|
}
|
|
39
40
|
componentShouldUpdate(newValue, oldValue, propName) {
|
|
40
41
|
// Ignore updates to the documentState property, as it is only intended to reflect the current state
|
|
@@ -46,6 +47,7 @@ export class VertexDocumentViewer {
|
|
|
46
47
|
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
|
|
47
48
|
this.updateComponentDimensions();
|
|
48
49
|
this.handleSrcChange();
|
|
50
|
+
this.injectViewerApi();
|
|
49
51
|
}
|
|
50
52
|
disconnectedCallback() {
|
|
51
53
|
var _a;
|
|
@@ -133,9 +135,9 @@ export class VertexDocumentViewer {
|
|
|
133
135
|
this.updateInteractionHandler();
|
|
134
136
|
}
|
|
135
137
|
render() {
|
|
136
|
-
return (h(Host, { key: '
|
|
138
|
+
return (h(Host, { key: 'f1ddf0b4e321bc244a5d757e48f6d71c23caca3c' }, h("div", { key: '174c64c537f4b0f1c45fc6543e5b7f54515e4063', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, h("div", { key: '4c47dadba03b32bde017252a9a8ea7f6e6d323f3', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
|
|
137
139
|
'enable-pointer-events ': window.PointerEvent != null,
|
|
138
|
-
}) }, h("canvas", { key: '
|
|
140
|
+
}) }, h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
|
|
139
141
|
}
|
|
140
142
|
getDocumentApi() {
|
|
141
143
|
if (this.documentApi == null) {
|
|
@@ -173,7 +175,7 @@ export class VertexDocumentViewer {
|
|
|
173
175
|
var _a;
|
|
174
176
|
(_a = this.panInteractionHandler) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
175
177
|
if (this.interactionMode === 'pan' && this.canvasEl != null && this.documentApi != null) {
|
|
176
|
-
this.panInteractionHandler = new PanInteractionHandler(this.canvasEl, this.documentApi);
|
|
178
|
+
this.panInteractionHandler = new PanInteractionHandler(this.canvasEl, this.hostEl, this.documentApi);
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
181
|
updateComponentDimensions(dimensions) {
|
|
@@ -207,6 +209,19 @@ export class VertexDocumentViewer {
|
|
|
207
209
|
}
|
|
208
210
|
handler.initialize(this.canvasEl);
|
|
209
211
|
}
|
|
212
|
+
registerSlotChangeListeners() {
|
|
213
|
+
this.mutationObserver = new MutationObserver(_ => this.injectViewerApi());
|
|
214
|
+
this.mutationObserver.observe(this.hostEl, {
|
|
215
|
+
childList: true,
|
|
216
|
+
subtree: true,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
injectViewerApi() {
|
|
220
|
+
getAllVertexElementChildren(this.hostEl).forEach(node => {
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
+
node.viewer = this.hostEl;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
210
225
|
static get is() { return "vertex-document-viewer"; }
|
|
211
226
|
static get encapsulation() { return "shadow"; }
|
|
212
227
|
static get originalStyleUrls() {
|
|
@@ -4,3 +4,11 @@
|
|
|
4
4
|
export function getElementBoundingClientRect(element) {
|
|
5
5
|
return element.getBoundingClientRect();
|
|
6
6
|
}
|
|
7
|
+
export function getAllVertexElementChildren(element) {
|
|
8
|
+
return getAllChildren(element)
|
|
9
|
+
.filter(node => node.nodeName.startsWith('VERTEX-'))
|
|
10
|
+
.reduce((elements, element) => [...elements, element, ...getAllChildren(element)], []);
|
|
11
|
+
}
|
|
12
|
+
function getAllChildren(element) {
|
|
13
|
+
return Array.from(element.querySelectorAll('*'));
|
|
14
|
+
}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
import { Point } from "@vertexvis/geometry";
|
|
5
5
|
const DRAG_PIXEL_THRESHOLD = 2;
|
|
6
6
|
export class PanInteractionHandler {
|
|
7
|
-
constructor(element, api) {
|
|
7
|
+
constructor(element, hostElement, api) {
|
|
8
8
|
this.element = element;
|
|
9
|
+
this.hostElement = hostElement;
|
|
9
10
|
this.api = api;
|
|
10
11
|
this.isDragging = false;
|
|
11
12
|
this.handlePointerDown = this.handlePointerDown.bind(this);
|
|
@@ -14,11 +15,12 @@ export class PanInteractionHandler {
|
|
|
14
15
|
this.handleWheel = this.handleWheel.bind(this);
|
|
15
16
|
this.element.addEventListener('pointerdown', this.handlePointerDown);
|
|
16
17
|
this.element.addEventListener('wheel', this.handleWheel);
|
|
17
|
-
|
|
18
|
+
this.hostElement.addEventListener('wheel', this.handleWheel);
|
|
18
19
|
}
|
|
19
20
|
dispose() {
|
|
20
21
|
this.element.removeEventListener('pointerdown', this.handlePointerDown);
|
|
21
22
|
this.element.removeEventListener('wheel', this.handleWheel);
|
|
23
|
+
this.hostElement.removeEventListener('wheel', this.handleWheel);
|
|
22
24
|
this.removeWindowListeners();
|
|
23
25
|
}
|
|
24
26
|
handleWheel(event) {
|
|
@@ -62,6 +64,5 @@ export class PanInteractionHandler {
|
|
|
62
64
|
removeWindowListeners() {
|
|
63
65
|
window.removeEventListener('pointermove', this.handlePointerMove);
|
|
64
66
|
window.removeEventListener('pointerup', this.handlePointerUp);
|
|
65
|
-
window.removeEventListener('wheel', this.handleWheel);
|
|
66
67
|
}
|
|
67
68
|
}
|