@vertexvis/doc-viewer 1.0.0-canary.5 → 1.0.0-canary.7

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.
@@ -21,7 +21,7 @@ var patchBrowser = () => {
21
21
 
22
22
  patchBrowser().then(async (options) => {
23
23
  await index.globalScripts();
24
- return index.bootstrapLazy([["vertex-document-viewer.cjs",[[257,"vertex-document-viewer",{"src":[1],"documentId":[513,"document-id"],"provider":[1040],"interactionMode":[1,"interaction-mode"],"documentState":[1040],"layers":[1040],"config":[16],"resizeDebounce":[2,"resize-debounce"],"panByDelta":[64],"zoomTo":[64],"loadPage":[64]},null,{"src":[{"handleSrcChange":0}],"config":[{"handleConfigChange":0}],"interactionMode":[{"handleInteractionModeChange":0}]}]]]], options);
24
+ return index.bootstrapLazy([["vertex-document-viewer.cjs",[[257,"vertex-document-viewer",{"src":[1],"documentId":[513,"document-id"],"provider":[1040],"interactionMode":[1,"interaction-mode"],"documentState":[1040],"layers":[1040],"config":[16],"resizeDebounce":[2,"resize-debounce"],"registerBasicInteractionHandler":[64],"panByDelta":[64],"zoomTo":[64],"loadPage":[64]},null,{"src":[{"handleSrcChange":0}],"config":[{"handleConfigChange":0}],"interactionMode":[{"handleInteractionModeChange":0}]}]]]], options);
25
25
  });
26
26
 
27
27
  exports.setNonce = index.setNonce;
@@ -8,7 +8,7 @@ var index = require('./index-UmtQ5Ckn.js');
8
8
  const defineCustomElements = async (win, options) => {
9
9
  if (typeof window === 'undefined') return undefined;
10
10
  await index.globalScripts();
11
- return index.bootstrapLazy([["vertex-document-viewer.cjs",[[257,"vertex-document-viewer",{"src":[1],"documentId":[513,"document-id"],"provider":[1040],"interactionMode":[1,"interaction-mode"],"documentState":[1040],"layers":[1040],"config":[16],"resizeDebounce":[2,"resize-debounce"],"panByDelta":[64],"zoomTo":[64],"loadPage":[64]},null,{"src":[{"handleSrcChange":0}],"config":[{"handleConfigChange":0}],"interactionMode":[{"handleInteractionModeChange":0}]}]]]], options);
11
+ return index.bootstrapLazy([["vertex-document-viewer.cjs",[[257,"vertex-document-viewer",{"src":[1],"documentId":[513,"document-id"],"provider":[1040],"interactionMode":[1,"interaction-mode"],"documentState":[1040],"layers":[1040],"config":[16],"resizeDebounce":[2,"resize-debounce"],"registerBasicInteractionHandler":[64],"panByDelta":[64],"zoomTo":[64],"loadPage":[64]},null,{"src":[{"handleSrcChange":0}],"config":[{"handleConfigChange":0}],"interactionMode":[{"handleInteractionModeChange":0}]}]]]], options);
12
12
  };
13
13
 
14
14
  exports.setNonce = index.setNonce;
@@ -663,6 +663,14 @@ 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 {
@@ -34636,6 +34644,7 @@ const VertexDocumentViewer = class {
34636
34644
  */
34637
34645
  this.resizeDebounce = 100;
34638
34646
  this.dimensions = dimensions.create(0, 0);
34647
+ this.interactionHandlers = [];
34639
34648
  }
34640
34649
  componentWillLoad() {
34641
34650
  this.handleElementResize = this.handleElementResize.bind(this);
@@ -34643,6 +34652,7 @@ const VertexDocumentViewer = class {
34643
34652
  this.handlePageLoaded = this.handlePageLoaded.bind(this);
34644
34653
  this.handlePageDrawn = this.handlePageDrawn.bind(this);
34645
34654
  this.resizeObserver = new ResizeObserver(this.handleElementResize);
34655
+ this.registerSlotChangeListeners();
34646
34656
  }
34647
34657
  componentShouldUpdate(newValue, oldValue, propName) {
34648
34658
  // Ignore updates to the documentState property, as it is only intended to reflect the current state
@@ -34654,12 +34664,36 @@ const VertexDocumentViewer = class {
34654
34664
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
34655
34665
  this.updateComponentDimensions();
34656
34666
  this.handleSrcChange();
34667
+ this.injectViewerApi();
34657
34668
  }
34658
34669
  disconnectedCallback() {
34659
34670
  var _a;
34660
34671
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
34661
34672
  this.clearCurrentDocument();
34662
34673
  }
34674
+ /**
34675
+ * Registers and initializes an interaction handler with the document viewer. Returns a
34676
+ * `Disposable` that should be used to deregister the interaction handler.
34677
+ *
34678
+ * `InteractionHandler`s are used to build custom mouse and touch interactions.
34679
+ *
34680
+ * @param interactionHandler The interaction handler to register.
34681
+ * @returns {Promise<void>} A promise containing the disposable to use to
34682
+ * deregister the handler.
34683
+ */
34684
+ async registerBasicInteractionHandler(interactionHandler) {
34685
+ this.interactionHandlers.push(interactionHandler);
34686
+ this.initializeInteractionHandler(interactionHandler);
34687
+ return {
34688
+ dispose: () => {
34689
+ const index = this.interactionHandlers.indexOf(interactionHandler);
34690
+ if (index !== -1) {
34691
+ this.interactionHandlers[index].dispose();
34692
+ this.interactionHandlers.splice(index, 1);
34693
+ }
34694
+ },
34695
+ };
34696
+ }
34663
34697
  /**
34664
34698
  * Pans the currently loaded document by the specified delta.
34665
34699
  *
@@ -34718,9 +34752,9 @@ const VertexDocumentViewer = class {
34718
34752
  this.updateInteractionHandler();
34719
34753
  }
34720
34754
  render() {
34721
- return (index.h(index.Host, { key: '9ebb0012f2edde7189b42f35fd2ecefb779b16ef' }, index.h("div", { key: 'ef52dd8c6367213d173f3847ff65deac1da6620e', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, index.h("div", { key: 'db0bede43e0798c1c8097f8079d1bbf4bea3fe15', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
34755
+ 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', {
34722
34756
  'enable-pointer-events ': window.PointerEvent != null,
34723
- }) }, index.h("canvas", { key: '3a705edd1985b11256e565880298a729a5e7260b', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: '9ccb82cc0493342c4e4caf7188c23ad8a55ca93b' }))));
34757
+ }) }, index.h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
34724
34758
  }
34725
34759
  getDocumentApi() {
34726
34760
  if (this.documentApi == null) {
@@ -34786,6 +34820,25 @@ const VertexDocumentViewer = class {
34786
34820
  await ((_a = this.documentApi) === null || _a === void 0 ? void 0 : _a.updateViewport(this.dimensions));
34787
34821
  }, this.resizeDebounce);
34788
34822
  }
34823
+ initializeInteractionHandler(handler) {
34824
+ if (this.canvasEl == null) {
34825
+ throw new Error('Cannot initialize interaction handler');
34826
+ }
34827
+ handler.initialize(this.canvasEl);
34828
+ }
34829
+ registerSlotChangeListeners() {
34830
+ this.mutationObserver = new MutationObserver(_ => this.injectViewerApi());
34831
+ this.mutationObserver.observe(this.hostEl, {
34832
+ childList: true,
34833
+ subtree: true,
34834
+ });
34835
+ }
34836
+ injectViewerApi() {
34837
+ getAllVertexElementChildren(this.hostEl).forEach(node => {
34838
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34839
+ node.viewer = this.hostEl;
34840
+ });
34841
+ }
34789
34842
  get hostEl() { return index.getElement(this); }
34790
34843
  static get watchers() { return {
34791
34844
  "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 {
@@ -27,6 +27,7 @@ export class VertexDocumentViewer {
27
27
  */
28
28
  this.resizeDebounce = 100;
29
29
  this.dimensions = Dimensions.create(0, 0);
30
+ this.interactionHandlers = [];
30
31
  }
31
32
  componentWillLoad() {
32
33
  this.handleElementResize = this.handleElementResize.bind(this);
@@ -34,6 +35,7 @@ export class VertexDocumentViewer {
34
35
  this.handlePageLoaded = this.handlePageLoaded.bind(this);
35
36
  this.handlePageDrawn = this.handlePageDrawn.bind(this);
36
37
  this.resizeObserver = new ResizeObserver(this.handleElementResize);
38
+ this.registerSlotChangeListeners();
37
39
  }
38
40
  componentShouldUpdate(newValue, oldValue, propName) {
39
41
  // Ignore updates to the documentState property, as it is only intended to reflect the current state
@@ -45,12 +47,36 @@ export class VertexDocumentViewer {
45
47
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
46
48
  this.updateComponentDimensions();
47
49
  this.handleSrcChange();
50
+ this.injectViewerApi();
48
51
  }
49
52
  disconnectedCallback() {
50
53
  var _a;
51
54
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
52
55
  this.clearCurrentDocument();
53
56
  }
57
+ /**
58
+ * Registers and initializes an interaction handler with the document viewer. Returns a
59
+ * `Disposable` that should be used to deregister the interaction handler.
60
+ *
61
+ * `InteractionHandler`s are used to build custom mouse and touch interactions.
62
+ *
63
+ * @param interactionHandler The interaction handler to register.
64
+ * @returns {Promise<void>} A promise containing the disposable to use to
65
+ * deregister the handler.
66
+ */
67
+ async registerBasicInteractionHandler(interactionHandler) {
68
+ this.interactionHandlers.push(interactionHandler);
69
+ this.initializeInteractionHandler(interactionHandler);
70
+ return {
71
+ dispose: () => {
72
+ const index = this.interactionHandlers.indexOf(interactionHandler);
73
+ if (index !== -1) {
74
+ this.interactionHandlers[index].dispose();
75
+ this.interactionHandlers.splice(index, 1);
76
+ }
77
+ },
78
+ };
79
+ }
54
80
  /**
55
81
  * Pans the currently loaded document by the specified delta.
56
82
  *
@@ -109,9 +135,9 @@ export class VertexDocumentViewer {
109
135
  this.updateInteractionHandler();
110
136
  }
111
137
  render() {
112
- return (h(Host, { key: '9ebb0012f2edde7189b42f35fd2ecefb779b16ef' }, h("div", { key: 'ef52dd8c6367213d173f3847ff65deac1da6620e', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, h("div", { key: 'db0bede43e0798c1c8097f8079d1bbf4bea3fe15', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
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', {
113
139
  'enable-pointer-events ': window.PointerEvent != null,
114
- }) }, h("canvas", { key: '3a705edd1985b11256e565880298a729a5e7260b', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: '9ccb82cc0493342c4e4caf7188c23ad8a55ca93b' }))));
140
+ }) }, h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
115
141
  }
116
142
  getDocumentApi() {
117
143
  if (this.documentApi == null) {
@@ -177,6 +203,25 @@ export class VertexDocumentViewer {
177
203
  await ((_a = this.documentApi) === null || _a === void 0 ? void 0 : _a.updateViewport(this.dimensions));
178
204
  }, this.resizeDebounce);
179
205
  }
206
+ initializeInteractionHandler(handler) {
207
+ if (this.canvasEl == null) {
208
+ throw new Error('Cannot initialize interaction handler');
209
+ }
210
+ handler.initialize(this.canvasEl);
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
+ }
180
225
  static get is() { return "vertex-document-viewer"; }
181
226
  static get encapsulation() { return "shadow"; }
182
227
  static get originalStyleUrls() {
@@ -460,6 +505,45 @@ export class VertexDocumentViewer {
460
505
  }
461
506
  static get methods() {
462
507
  return {
508
+ "registerBasicInteractionHandler": {
509
+ "complexType": {
510
+ "signature": "(interactionHandler: BasicInteractionHandler) => Promise<Disposable>",
511
+ "parameters": [{
512
+ "name": "interactionHandler",
513
+ "type": "BasicInteractionHandler",
514
+ "docs": "The interaction handler to register."
515
+ }],
516
+ "references": {
517
+ "Promise": {
518
+ "location": "global",
519
+ "id": "global::Promise"
520
+ },
521
+ "Disposable": {
522
+ "location": "import",
523
+ "path": "@vertexvis/utils",
524
+ "id": "../utils/dist/index.d.ts::Disposable",
525
+ "referenceLocation": "Disposable"
526
+ },
527
+ "BasicInteractionHandler": {
528
+ "location": "import",
529
+ "path": "@vertexvis/utils",
530
+ "id": "../utils/dist/index.d.ts::BasicInteractionHandler",
531
+ "referenceLocation": "BasicInteractionHandler"
532
+ }
533
+ },
534
+ "return": "Promise<Disposable>"
535
+ },
536
+ "docs": {
537
+ "text": "Registers and initializes an interaction handler with the document viewer. Returns a\n`Disposable` that should be used to deregister the interaction handler.\n\n`InteractionHandler`s are used to build custom mouse and touch interactions.",
538
+ "tags": [{
539
+ "name": "param",
540
+ "text": "interactionHandler The interaction handler to register."
541
+ }, {
542
+ "name": "returns",
543
+ "text": "A promise containing the disposable to use to\nderegister the handler."
544
+ }]
545
+ }
546
+ },
463
547
  "panByDelta": {
464
548
  "complexType": {
465
549
  "signature": "(delta: Point.Point) => Promise<void>",
@@ -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
+ }