@vertexvis/doc-viewer 1.0.2-canary.4 → 1.0.2-canary.6

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.
@@ -663,6 +663,9 @@ class DocumentLayersController {
663
663
  function getElementBoundingClientRect(element) {
664
664
  return element.getBoundingClientRect();
665
665
  }
666
+ function createElement(tagName) {
667
+ return document.createElement(tagName);
668
+ }
666
669
  function getAllVertexElementChildren(element) {
667
670
  return getAllChildren(element)
668
671
  .filter(node => node.nodeName.startsWith('VERTEX-'))
@@ -34545,7 +34548,7 @@ class PdfJsRenderer extends DocumentRenderer {
34545
34548
  this.state = { pages: {}, rendering: false };
34546
34549
  // Render pages using an offscreen canvas to avoid flickering that can occur for
34547
34550
  // PDFs with annotations.
34548
- this.offscreenCanvas = document.createElement('canvas');
34551
+ this.offscreenCanvas = createElement('canvas');
34549
34552
  this.handleStateChanged = this.handleStateChanged.bind(this);
34550
34553
  this.stateChangedDisposable = this.api.onStateChanged(this.handleStateChanged);
34551
34554
  }
@@ -34587,10 +34590,18 @@ class PdfJsRenderer extends DocumentRenderer {
34587
34590
  });
34588
34591
  this.offscreenCanvas.width = this.canvas.width;
34589
34592
  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
+ }
34590
34600
  await page.render({
34591
34601
  canvas: this.offscreenCanvas,
34592
34602
  viewport: scaled,
34593
34603
  intent: 'display',
34604
+ background: 'transparent',
34594
34605
  optionalContentConfigPromise: optionalContentConfig != null ? Promise.resolve(optionalContentConfig) : undefined,
34595
34606
  }).promise;
34596
34607
  // Emit an event before the page is drawn, then draw the page to the canvas on the next
@@ -34620,7 +34631,7 @@ class PdfJsProvider {
34620
34631
  }
34621
34632
  }
34622
34633
 
34623
- 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}`;
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;--viewer-background:#cccccc}.viewer-container{width:100%;height:100%;overflow:hidden}.canvas-container{display:flex;justify-content:center;align-items:center;width:100%;height:100%;position:relative}#document-viewer-canvas{background-color:var(--viewer-background)}`;
34624
34635
 
34625
34636
  const VertexDocumentViewer = class {
34626
34637
  constructor(hostRef) {
@@ -34755,7 +34766,7 @@ const VertexDocumentViewer = class {
34755
34766
  render() {
34756
34767
  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', {
34757
34768
  'enable-pointer-events ': window.PointerEvent != null,
34758
- }) }, index.h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
34769
+ }) }, index.h("canvas", { key: 'ae645889dd5cb93084f820f9f3d14a56de0213f7', id: "document-viewer-canvas", role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: '7762c493306bf5d21cd16218f1abd3c6d0300ace' }))));
34759
34770
  }
34760
34771
  getDocumentApi() {
34761
34772
  if (this.documentApi == null) {
@@ -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
- export const mockPageRender = jest.fn(() => ({ promise: Promise.resolve() }));
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 #cccccc.
16
+ */
17
+ --viewer-background: #cccccc;
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
+ }
@@ -137,7 +137,7 @@ export class VertexDocumentViewer {
137
137
  render() {
138
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', {
139
139
  'enable-pointer-events ': window.PointerEvent != null,
140
- }) }, h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
140
+ }) }, h("canvas", { key: 'ae645889dd5cb93084f820f9f3d14a56de0213f7', id: "document-viewer-canvas", role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: '7762c493306bf5d21cd16218f1abd3c6d0300ace' }))));
141
141
  }
142
142
  getDocumentApi() {
143
143
  if (this.documentApi == null) {
@@ -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 = document.createElement('canvas');
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