@vertexvis/doc-viewer 1.1.3-canary.1 → 1.1.3-canary.2

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.
@@ -34132,11 +34132,10 @@ class EventDispatcher {
34132
34132
  this.listeners = [];
34133
34133
  }
34134
34134
  on(listener, opts = {}) {
34135
- var _a;
34136
34135
  this.listeners.push(listener);
34137
34136
  const controller = new AbortController();
34138
34137
  controller.signal.addEventListener('abort', () => this.off(listener));
34139
- (_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => controller.abort());
34138
+ opts.abort?.addEventListener('abort', () => controller.abort());
34140
34139
  return { dispose: () => controller.abort() };
34141
34140
  }
34142
34141
  once(opts = {}) {
@@ -34148,9 +34147,8 @@ class EventDispatcher {
34148
34147
  });
34149
34148
  }
34150
34149
  async onceWhen(predicate, opts = {}) {
34151
- var _a;
34152
34150
  const controller = new AbortController();
34153
- (_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => controller.abort());
34151
+ opts.abort?.addEventListener('abort', () => controller.abort());
34154
34152
  return new Promise((resolve) => {
34155
34153
  this.when(predicate, (event) => {
34156
34154
  if (predicate(event)) {
@@ -34289,17 +34287,15 @@ function fromUrl(url) {
34289
34287
 
34290
34288
  class PdfJsApi extends DocumentApi {
34291
34289
  constructor(config) {
34292
- var _a;
34293
34290
  super({
34294
34291
  panOffset: point.create(0, 0),
34295
34292
  zoomPercentage: 100,
34296
34293
  });
34297
34294
  this.config = config;
34298
- GlobalWorkerOptions.workerSrc = (_a = config === null || config === void 0 ? void 0 : config.pdfJs.workerSrc) !== null && _a !== void 0 ? _a : './assets/pdf.worker.min.mjs';
34295
+ GlobalWorkerOptions.workerSrc = config?.pdfJs.workerSrc ?? './assets/pdf.worker.min.mjs';
34299
34296
  }
34300
34297
  dispose() {
34301
- var _a;
34302
- (_a = this.state.document) === null || _a === void 0 ? void 0 : _a.destroy();
34298
+ this.state.document?.destroy();
34303
34299
  }
34304
34300
  async load(uri) {
34305
34301
  const resource = fromUri(uri);
@@ -34310,7 +34306,7 @@ class PdfJsApi extends DocumentApi {
34310
34306
  document,
34311
34307
  totalPageCount: document.numPages,
34312
34308
  optionalContentConfig,
34313
- layers: Array.from(optionalContentConfig).map(([id, group]) => { var _a; return ({ id, name: (_a = group.name) !== null && _a !== void 0 ? _a : id, visible: group.visible }); }),
34309
+ layers: Array.from(optionalContentConfig).map(([id, group]) => ({ id, name: group.name ?? id, visible: group.visible })),
34314
34310
  });
34315
34311
  }
34316
34312
  else {
@@ -34318,22 +34314,20 @@ class PdfJsApi extends DocumentApi {
34318
34314
  }
34319
34315
  }
34320
34316
  async loadPage(pageNumber) {
34321
- var _a, _b;
34322
- const totalPageCount = (_a = this.state.totalPageCount) !== null && _a !== void 0 ? _a : 1;
34317
+ const totalPageCount = this.state.totalPageCount ?? 1;
34323
34318
  if (pageNumber <= 0) {
34324
34319
  throw new Error(`Unable to load page ${pageNumber}. The provided page number must be greater than 0.`);
34325
34320
  }
34326
34321
  else if (pageNumber > totalPageCount) {
34327
34322
  throw new Error(`Unable to load page ${pageNumber}. The document only has ${totalPageCount} page(s).`);
34328
34323
  }
34329
- const page = await ((_b = this.state.document) === null || _b === void 0 ? void 0 : _b.getPage(pageNumber));
34330
- const baseViewport = page === null || page === void 0 ? void 0 : page.getViewport({ scale: 1 });
34324
+ const page = await this.state.document?.getPage(pageNumber);
34325
+ const baseViewport = page?.getViewport({ scale: 1 });
34331
34326
  const contentDimensions = baseViewport != null ? dimensions.create(baseViewport.width, baseViewport.height) : undefined;
34332
34327
  this.updateState({ loadedPageNumber: pageNumber, contentDimensions, panOffset: point.create(0, 0) });
34333
34328
  }
34334
34329
  getLayers() {
34335
- var _a;
34336
- return (_a = this.state.layers) !== null && _a !== void 0 ? _a : [];
34330
+ return this.state.layers ?? [];
34337
34331
  }
34338
34332
  setLayerVisibility(id, visible) {
34339
34333
  const { optionalContentConfig } = this.state;
@@ -34343,7 +34337,7 @@ class PdfJsApi extends DocumentApi {
34343
34337
  optionalContentConfig.setVisibility(id, visible);
34344
34338
  this.updateState({
34345
34339
  optionalContentConfig,
34346
- layers: Array.from(optionalContentConfig).map(([id, group]) => { var _a; return ({ id, name: (_a = group.name) !== null && _a !== void 0 ? _a : id, visible: group.visible }); }),
34340
+ layers: Array.from(optionalContentConfig).map(([id, group]) => ({ id, name: group.name ?? id, visible: group.visible })),
34347
34341
  });
34348
34342
  }
34349
34343
  }
@@ -34395,7 +34389,7 @@ class PdfJsRenderer extends DocumentRenderer {
34395
34389
  this.state.pages[loadedPageNumber] = await document.getPage(loadedPageNumber);
34396
34390
  }
34397
34391
  const page = this.state.pages[loadedPageNumber];
34398
- const dimensions$1 = viewport !== null && viewport !== void 0 ? viewport : dimensions.create(0, 0);
34392
+ const dimensions$1 = viewport ?? dimensions.create(0, 0);
34399
34393
  const scaledDimensions = dimensions.scale(window.devicePixelRatio, window.devicePixelRatio, dimensions$1);
34400
34394
  const baseViewport = page.getViewport({ scale: 1 });
34401
34395
  const scaleX = scaledDimensions.width / baseViewport.width;
@@ -34498,15 +34492,13 @@ const VertexDocumentViewer = class {
34498
34492
  return propName !== 'documentState';
34499
34493
  }
34500
34494
  componentDidLoad() {
34501
- var _a;
34502
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
34495
+ this.resizeObserver?.observe(this.hostEl);
34503
34496
  this.updateComponentDimensions();
34504
34497
  this.loadInitialSrc();
34505
34498
  this.injectViewerApi();
34506
34499
  }
34507
34500
  disconnectedCallback() {
34508
- var _a;
34509
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
34501
+ this.resizeObserver?.disconnect();
34510
34502
  this.clearCurrentDocument();
34511
34503
  }
34512
34504
  /**
@@ -34568,13 +34560,12 @@ const VertexDocumentViewer = class {
34568
34560
  await documentApi.loadPage(pageNumber);
34569
34561
  }
34570
34562
  async handleSrcChange() {
34571
- var _a;
34572
34563
  if (this.src != null && this.canvasEl != null) {
34573
34564
  this.clearCurrentDocument();
34574
34565
  const { api, renderer } = this.provider.create(this.canvasEl, this.config);
34575
34566
  this.documentApi = api;
34576
34567
  this.documentRenderer = renderer;
34577
- (_a = this.layers) === null || _a === void 0 ? void 0 : _a.setApi(api);
34568
+ this.layers?.setApi(api);
34578
34569
  this.updateInteractionHandler();
34579
34570
  this.updateDocumentApiListeners();
34580
34571
  await this.documentApi.updateViewport(this.dimensions);
@@ -34606,20 +34597,19 @@ const VertexDocumentViewer = class {
34606
34597
  await this.handleSrcChange();
34607
34598
  }
34608
34599
  clearCurrentDocument() {
34609
- var _a, _b, _c, _d, _e, _f, _g;
34610
- (_a = this.documentRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
34611
- (_b = this.documentApi) === null || _b === void 0 ? void 0 : _b.dispose();
34612
- (_c = this.panInteractionHandler) === null || _c === void 0 ? void 0 : _c.dispose();
34613
- (_d = this.documentApiStateChangedDisposable) === null || _d === void 0 ? void 0 : _d.dispose();
34614
- (_e = this.pageLoadedDisposable) === null || _e === void 0 ? void 0 : _e.dispose();
34615
- (_f = this.pageDrawnDisposable) === null || _f === void 0 ? void 0 : _f.dispose();
34600
+ this.documentRenderer?.dispose();
34601
+ this.documentApi?.dispose();
34602
+ this.panInteractionHandler?.dispose();
34603
+ this.documentApiStateChangedDisposable?.dispose();
34604
+ this.pageLoadedDisposable?.dispose();
34605
+ this.pageDrawnDisposable?.dispose();
34616
34606
  this.documentRenderer = undefined;
34617
34607
  this.documentApi = undefined;
34618
34608
  this.panInteractionHandler = undefined;
34619
34609
  this.documentApiStateChangedDisposable = undefined;
34620
34610
  this.pageLoadedDisposable = undefined;
34621
34611
  this.pageDrawnDisposable = undefined;
34622
- (_g = this.layers) === null || _g === void 0 ? void 0 : _g.clear();
34612
+ this.layers?.clear();
34623
34613
  }
34624
34614
  handleDocumentApiStateChanged(state) {
34625
34615
  this.documentState = state;
@@ -34632,20 +34622,18 @@ const VertexDocumentViewer = class {
34632
34622
  this.pageDrawn.emit(state);
34633
34623
  }
34634
34624
  updateDocumentApiListeners() {
34635
- var _a, _b, _c;
34636
- this.documentApiStateChangedDisposable = (_a = this.documentApi) === null || _a === void 0 ? void 0 : _a.onStateChanged(this.handleDocumentApiStateChanged);
34637
- this.pageLoadedDisposable = (_b = this.documentRenderer) === null || _b === void 0 ? void 0 : _b.onPageLoaded(this.handlePageLoaded);
34638
- this.pageDrawnDisposable = (_c = this.documentRenderer) === null || _c === void 0 ? void 0 : _c.onPageDrawn(this.handlePageDrawn);
34625
+ this.documentApiStateChangedDisposable = this.documentApi?.onStateChanged(this.handleDocumentApiStateChanged);
34626
+ this.pageLoadedDisposable = this.documentRenderer?.onPageLoaded(this.handlePageLoaded);
34627
+ this.pageDrawnDisposable = this.documentRenderer?.onPageDrawn(this.handlePageDrawn);
34639
34628
  }
34640
34629
  updateInteractionHandler() {
34641
- var _a;
34642
- (_a = this.panInteractionHandler) === null || _a === void 0 ? void 0 : _a.dispose();
34630
+ this.panInteractionHandler?.dispose();
34643
34631
  if (this.interactionMode === 'pan' && this.canvasEl != null && this.documentApi != null) {
34644
34632
  this.panInteractionHandler = new PanInteractionHandler(this.canvasEl, this.hostEl, this.documentApi);
34645
34633
  }
34646
34634
  }
34647
34635
  updateComponentDimensions(dimensions) {
34648
- this.dimensions = dimensions !== null && dimensions !== void 0 ? dimensions : getElementBoundingClientRect(this.hostEl);
34636
+ this.dimensions = dimensions ?? getElementBoundingClientRect(this.hostEl);
34649
34637
  if (this.canvasEl != null) {
34650
34638
  this.canvasEl.width = Math.floor(this.dimensions.width * window.devicePixelRatio);
34651
34639
  this.canvasEl.height = Math.floor(this.dimensions.height * window.devicePixelRatio);
@@ -34664,9 +34652,8 @@ const VertexDocumentViewer = class {
34664
34652
  window.clearTimeout(this.resizeTimer);
34665
34653
  }
34666
34654
  this.resizeTimer = window.setTimeout(async () => {
34667
- var _a;
34668
34655
  this.updateComponentDimensions(dimensions);
34669
- await ((_a = this.documentApi) === null || _a === void 0 ? void 0 : _a.updateViewport(this.dimensions));
34656
+ await this.documentApi?.updateViewport(this.dimensions);
34670
34657
  }, this.resizeDebounce);
34671
34658
  }
34672
34659
  initializeInteractionHandler(handler) {
@@ -18,14 +18,14 @@
18
18
  globalThis.MessageEvent = class extends Event {
19
19
  constructor(type, initDict) {
20
20
  super(type);
21
- this.data = initDict === null || initDict === void 0 ? void 0 : initDict.data;
21
+ this.data = initDict?.data;
22
22
  }
23
23
  };
24
24
  globalThis.CloseEvent = class extends Event {
25
25
  constructor(type, initDict) {
26
26
  super(type);
27
- this.code = initDict === null || initDict === void 0 ? void 0 : initDict.code;
28
- this.reason = initDict === null || initDict === void 0 ? void 0 : initDict.reason;
27
+ this.code = initDict?.code;
28
+ this.reason = initDict?.reason;
29
29
  }
30
30
  };
31
31
  globalThis.MutationObserver = class {
@@ -44,15 +44,13 @@ export class VertexDocumentViewer {
44
44
  return propName !== 'documentState';
45
45
  }
46
46
  componentDidLoad() {
47
- var _a;
48
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
47
+ this.resizeObserver?.observe(this.hostEl);
49
48
  this.updateComponentDimensions();
50
49
  this.loadInitialSrc();
51
50
  this.injectViewerApi();
52
51
  }
53
52
  disconnectedCallback() {
54
- var _a;
55
- (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
53
+ this.resizeObserver?.disconnect();
56
54
  this.clearCurrentDocument();
57
55
  }
58
56
  /**
@@ -114,13 +112,12 @@ export class VertexDocumentViewer {
114
112
  await documentApi.loadPage(pageNumber);
115
113
  }
116
114
  async handleSrcChange() {
117
- var _a;
118
115
  if (this.src != null && this.canvasEl != null) {
119
116
  this.clearCurrentDocument();
120
117
  const { api, renderer } = this.provider.create(this.canvasEl, this.config);
121
118
  this.documentApi = api;
122
119
  this.documentRenderer = renderer;
123
- (_a = this.layers) === null || _a === void 0 ? void 0 : _a.setApi(api);
120
+ this.layers?.setApi(api);
124
121
  this.updateInteractionHandler();
125
122
  this.updateDocumentApiListeners();
126
123
  await this.documentApi.updateViewport(this.dimensions);
@@ -152,20 +149,19 @@ export class VertexDocumentViewer {
152
149
  await this.handleSrcChange();
153
150
  }
154
151
  clearCurrentDocument() {
155
- var _a, _b, _c, _d, _e, _f, _g;
156
- (_a = this.documentRenderer) === null || _a === void 0 ? void 0 : _a.dispose();
157
- (_b = this.documentApi) === null || _b === void 0 ? void 0 : _b.dispose();
158
- (_c = this.panInteractionHandler) === null || _c === void 0 ? void 0 : _c.dispose();
159
- (_d = this.documentApiStateChangedDisposable) === null || _d === void 0 ? void 0 : _d.dispose();
160
- (_e = this.pageLoadedDisposable) === null || _e === void 0 ? void 0 : _e.dispose();
161
- (_f = this.pageDrawnDisposable) === null || _f === void 0 ? void 0 : _f.dispose();
152
+ this.documentRenderer?.dispose();
153
+ this.documentApi?.dispose();
154
+ this.panInteractionHandler?.dispose();
155
+ this.documentApiStateChangedDisposable?.dispose();
156
+ this.pageLoadedDisposable?.dispose();
157
+ this.pageDrawnDisposable?.dispose();
162
158
  this.documentRenderer = undefined;
163
159
  this.documentApi = undefined;
164
160
  this.panInteractionHandler = undefined;
165
161
  this.documentApiStateChangedDisposable = undefined;
166
162
  this.pageLoadedDisposable = undefined;
167
163
  this.pageDrawnDisposable = undefined;
168
- (_g = this.layers) === null || _g === void 0 ? void 0 : _g.clear();
164
+ this.layers?.clear();
169
165
  }
170
166
  handleDocumentApiStateChanged(state) {
171
167
  this.documentState = state;
@@ -178,20 +174,18 @@ export class VertexDocumentViewer {
178
174
  this.pageDrawn.emit(state);
179
175
  }
180
176
  updateDocumentApiListeners() {
181
- var _a, _b, _c;
182
- this.documentApiStateChangedDisposable = (_a = this.documentApi) === null || _a === void 0 ? void 0 : _a.onStateChanged(this.handleDocumentApiStateChanged);
183
- this.pageLoadedDisposable = (_b = this.documentRenderer) === null || _b === void 0 ? void 0 : _b.onPageLoaded(this.handlePageLoaded);
184
- this.pageDrawnDisposable = (_c = this.documentRenderer) === null || _c === void 0 ? void 0 : _c.onPageDrawn(this.handlePageDrawn);
177
+ this.documentApiStateChangedDisposable = this.documentApi?.onStateChanged(this.handleDocumentApiStateChanged);
178
+ this.pageLoadedDisposable = this.documentRenderer?.onPageLoaded(this.handlePageLoaded);
179
+ this.pageDrawnDisposable = this.documentRenderer?.onPageDrawn(this.handlePageDrawn);
185
180
  }
186
181
  updateInteractionHandler() {
187
- var _a;
188
- (_a = this.panInteractionHandler) === null || _a === void 0 ? void 0 : _a.dispose();
182
+ this.panInteractionHandler?.dispose();
189
183
  if (this.interactionMode === 'pan' && this.canvasEl != null && this.documentApi != null) {
190
184
  this.panInteractionHandler = new PanInteractionHandler(this.canvasEl, this.hostEl, this.documentApi);
191
185
  }
192
186
  }
193
187
  updateComponentDimensions(dimensions) {
194
- this.dimensions = dimensions !== null && dimensions !== void 0 ? dimensions : getElementBoundingClientRect(this.hostEl);
188
+ this.dimensions = dimensions ?? getElementBoundingClientRect(this.hostEl);
195
189
  if (this.canvasEl != null) {
196
190
  this.canvasEl.width = Math.floor(this.dimensions.width * window.devicePixelRatio);
197
191
  this.canvasEl.height = Math.floor(this.dimensions.height * window.devicePixelRatio);
@@ -210,9 +204,8 @@ export class VertexDocumentViewer {
210
204
  window.clearTimeout(this.resizeTimer);
211
205
  }
212
206
  this.resizeTimer = window.setTimeout(async () => {
213
- var _a;
214
207
  this.updateComponentDimensions(dimensions);
215
- await ((_a = this.documentApi) === null || _a === void 0 ? void 0 : _a.updateViewport(this.dimensions));
208
+ await this.documentApi?.updateViewport(this.dimensions);
216
209
  }, this.resizeDebounce);
217
210
  }
218
211
  initializeInteractionHandler(handler) {
@@ -7,17 +7,15 @@ import { DocumentApi } from "../document/api";
7
7
  import { fromUri } from "../types/loadableResource";
8
8
  export class PdfJsApi extends DocumentApi {
9
9
  constructor(config) {
10
- var _a;
11
10
  super({
12
11
  panOffset: Point.create(0, 0),
13
12
  zoomPercentage: 100,
14
13
  });
15
14
  this.config = config;
16
- pdfjs.GlobalWorkerOptions.workerSrc = (_a = config === null || config === void 0 ? void 0 : config.pdfJs.workerSrc) !== null && _a !== void 0 ? _a : './assets/pdf.worker.min.mjs';
15
+ pdfjs.GlobalWorkerOptions.workerSrc = config?.pdfJs.workerSrc ?? './assets/pdf.worker.min.mjs';
17
16
  }
18
17
  dispose() {
19
- var _a;
20
- (_a = this.state.document) === null || _a === void 0 ? void 0 : _a.destroy();
18
+ this.state.document?.destroy();
21
19
  }
22
20
  async load(uri) {
23
21
  const resource = fromUri(uri);
@@ -28,7 +26,7 @@ export class PdfJsApi extends DocumentApi {
28
26
  document,
29
27
  totalPageCount: document.numPages,
30
28
  optionalContentConfig,
31
- layers: Array.from(optionalContentConfig).map(([id, group]) => { var _a; return ({ id, name: (_a = group.name) !== null && _a !== void 0 ? _a : id, visible: group.visible }); }),
29
+ layers: Array.from(optionalContentConfig).map(([id, group]) => ({ id, name: group.name ?? id, visible: group.visible })),
32
30
  });
33
31
  }
34
32
  else {
@@ -36,22 +34,20 @@ export class PdfJsApi extends DocumentApi {
36
34
  }
37
35
  }
38
36
  async loadPage(pageNumber) {
39
- var _a, _b;
40
- const totalPageCount = (_a = this.state.totalPageCount) !== null && _a !== void 0 ? _a : 1;
37
+ const totalPageCount = this.state.totalPageCount ?? 1;
41
38
  if (pageNumber <= 0) {
42
39
  throw new Error(`Unable to load page ${pageNumber}. The provided page number must be greater than 0.`);
43
40
  }
44
41
  else if (pageNumber > totalPageCount) {
45
42
  throw new Error(`Unable to load page ${pageNumber}. The document only has ${totalPageCount} page(s).`);
46
43
  }
47
- const page = await ((_b = this.state.document) === null || _b === void 0 ? void 0 : _b.getPage(pageNumber));
48
- const baseViewport = page === null || page === void 0 ? void 0 : page.getViewport({ scale: 1 });
44
+ const page = await this.state.document?.getPage(pageNumber);
45
+ const baseViewport = page?.getViewport({ scale: 1 });
49
46
  const contentDimensions = baseViewport != null ? Dimensions.create(baseViewport.width, baseViewport.height) : undefined;
50
47
  this.updateState({ loadedPageNumber: pageNumber, contentDimensions, panOffset: Point.create(0, 0) });
51
48
  }
52
49
  getLayers() {
53
- var _a;
54
- return (_a = this.state.layers) !== null && _a !== void 0 ? _a : [];
50
+ return this.state.layers ?? [];
55
51
  }
56
52
  setLayerVisibility(id, visible) {
57
53
  const { optionalContentConfig } = this.state;
@@ -61,7 +57,7 @@ export class PdfJsApi extends DocumentApi {
61
57
  optionalContentConfig.setVisibility(id, visible);
62
58
  this.updateState({
63
59
  optionalContentConfig,
64
- layers: Array.from(optionalContentConfig).map(([id, group]) => { var _a; return ({ id, name: (_a = group.name) !== null && _a !== void 0 ? _a : id, visible: group.visible }); }),
60
+ layers: Array.from(optionalContentConfig).map(([id, group]) => ({ id, name: group.name ?? id, visible: group.visible })),
65
61
  });
66
62
  }
67
63
  }
@@ -32,7 +32,7 @@ export class PdfJsRenderer extends DocumentRenderer {
32
32
  this.state.pages[loadedPageNumber] = await document.getPage(loadedPageNumber);
33
33
  }
34
34
  const page = this.state.pages[loadedPageNumber];
35
- const dimensions = viewport !== null && viewport !== void 0 ? viewport : Dimensions.create(0, 0);
35
+ const dimensions = viewport ?? Dimensions.create(0, 0);
36
36
  const scaledDimensions = Dimensions.scale(window.devicePixelRatio, window.devicePixelRatio, dimensions);
37
37
  const baseViewport = page.getViewport({ scale: 1 });
38
38
  const scaleX = scaledDimensions.width / baseViewport.width;