@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 1.0.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.
Files changed (172) hide show
  1. package/README.md +1 -1
  2. package/package.json +42 -26
  3. package/{src/display → pdfjs/dist}/display_utils.js +344 -139
  4. package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
  5. package/pdfjs/dist/l10n_utils.js +140 -0
  6. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  7. package/{src/display → pdfjs/dist}/network.js +149 -87
  8. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  9. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  10. package/pdfjs/dist/pdf.js +12778 -0
  11. package/pdfjs/dist/pdf_link_service.js +638 -0
  12. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  13. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  14. package/pdfjs/dist/pdf_viewer.js +3598 -0
  15. package/pdfjs/dist/ui_utils.js +1033 -0
  16. package/{src/shared → pdfjs/dist}/util.js +301 -287
  17. package/pdfjs/dist/worker.js +62813 -0
  18. package/src/vcf-pdf-viewer.js +98 -46
  19. package/theme/lumo/vcf-pdf-viewer-styles.js +4 -4
  20. package/theme/material/vcf-pdf-viewer-styles.js +4 -4
  21. package/theme/material/vcf-pdf-viewer.js +2 -2
  22. package/src/core/.eslintrc +0 -13
  23. package/src/core/annotation.js +0 -2948
  24. package/src/core/arithmetic_decoder.js +0 -182
  25. package/src/core/ascii_85_stream.js +0 -98
  26. package/src/core/ascii_hex_stream.js +0 -79
  27. package/src/core/base_stream.js +0 -110
  28. package/src/core/bidi.js +0 -438
  29. package/src/core/calibri_factors.js +0 -308
  30. package/src/core/catalog.js +0 -1459
  31. package/src/core/ccitt.js +0 -1062
  32. package/src/core/ccitt_stream.js +0 -60
  33. package/src/core/cff_font.js +0 -116
  34. package/src/core/cff_parser.js +0 -1949
  35. package/src/core/charsets.js +0 -119
  36. package/src/core/chunked_stream.js +0 -557
  37. package/src/core/cmap.js +0 -1039
  38. package/src/core/colorspace.js +0 -1533
  39. package/src/core/core_utils.js +0 -464
  40. package/src/core/crypto.js +0 -1900
  41. package/src/core/decode_stream.js +0 -170
  42. package/src/core/decrypt_stream.js +0 -59
  43. package/src/core/default_appearance.js +0 -99
  44. package/src/core/document.js +0 -1456
  45. package/src/core/encodings.js +0 -301
  46. package/src/core/evaluator.js +0 -4601
  47. package/src/core/file_spec.js +0 -108
  48. package/src/core/flate_stream.js +0 -402
  49. package/src/core/font_renderer.js +0 -882
  50. package/src/core/fonts.js +0 -3260
  51. package/src/core/fonts_utils.js +0 -221
  52. package/src/core/function.js +0 -1257
  53. package/src/core/glyf.js +0 -706
  54. package/src/core/glyphlist.js +0 -4558
  55. package/src/core/helvetica_factors.js +0 -353
  56. package/src/core/image.js +0 -802
  57. package/src/core/image_utils.js +0 -291
  58. package/src/core/jbig2.js +0 -2572
  59. package/src/core/jbig2_stream.js +0 -73
  60. package/src/core/jpeg_stream.js +0 -105
  61. package/src/core/jpg.js +0 -1416
  62. package/src/core/jpx.js +0 -2343
  63. package/src/core/jpx_stream.js +0 -87
  64. package/src/core/liberationsans_widths.js +0 -221
  65. package/src/core/lzw_stream.js +0 -150
  66. package/src/core/metadata_parser.js +0 -146
  67. package/src/core/metrics.js +0 -2970
  68. package/src/core/murmurhash3.js +0 -139
  69. package/src/core/myriadpro_factors.js +0 -290
  70. package/src/core/name_number_tree.js +0 -153
  71. package/src/core/object_loader.js +0 -149
  72. package/src/core/opentype_file_builder.js +0 -154
  73. package/src/core/operator_list.js +0 -734
  74. package/src/core/parser.js +0 -1416
  75. package/src/core/pattern.js +0 -985
  76. package/src/core/pdf_manager.js +0 -217
  77. package/src/core/predictor_stream.js +0 -238
  78. package/src/core/primitives.js +0 -402
  79. package/src/core/ps_parser.js +0 -272
  80. package/src/core/run_length_stream.js +0 -61
  81. package/src/core/segoeui_factors.js +0 -308
  82. package/src/core/standard_fonts.js +0 -817
  83. package/src/core/stream.js +0 -103
  84. package/src/core/struct_tree.js +0 -335
  85. package/src/core/to_unicode_map.js +0 -103
  86. package/src/core/type1_font.js +0 -421
  87. package/src/core/type1_parser.js +0 -776
  88. package/src/core/unicode.js +0 -1649
  89. package/src/core/worker.js +0 -848
  90. package/src/core/worker_stream.js +0 -135
  91. package/src/core/writer.js +0 -278
  92. package/src/core/xfa/bind.js +0 -652
  93. package/src/core/xfa/builder.js +0 -207
  94. package/src/core/xfa/config.js +0 -1926
  95. package/src/core/xfa/connection_set.js +0 -202
  96. package/src/core/xfa/data.js +0 -82
  97. package/src/core/xfa/datasets.js +0 -76
  98. package/src/core/xfa/factory.js +0 -111
  99. package/src/core/xfa/fonts.js +0 -181
  100. package/src/core/xfa/formcalc_lexer.js +0 -385
  101. package/src/core/xfa/formcalc_parser.js +0 -1340
  102. package/src/core/xfa/html_utils.js +0 -639
  103. package/src/core/xfa/layout.js +0 -383
  104. package/src/core/xfa/locale_set.js +0 -345
  105. package/src/core/xfa/namespaces.js +0 -81
  106. package/src/core/xfa/parser.js +0 -184
  107. package/src/core/xfa/setup.js +0 -38
  108. package/src/core/xfa/signature.js +0 -40
  109. package/src/core/xfa/som.js +0 -338
  110. package/src/core/xfa/stylesheet.js +0 -40
  111. package/src/core/xfa/template.js +0 -6260
  112. package/src/core/xfa/text.js +0 -290
  113. package/src/core/xfa/unknown.js +0 -29
  114. package/src/core/xfa/utils.js +0 -217
  115. package/src/core/xfa/xdp.js +0 -59
  116. package/src/core/xfa/xfa_object.js +0 -1130
  117. package/src/core/xfa/xhtml.js +0 -543
  118. package/src/core/xfa_fonts.js +0 -208
  119. package/src/core/xml_parser.js +0 -507
  120. package/src/core/xref.js +0 -899
  121. package/src/display/annotation_layer.js +0 -2107
  122. package/src/display/annotation_storage.js +0 -113
  123. package/src/display/api.js +0 -3292
  124. package/src/display/base_factory.js +0 -180
  125. package/src/display/canvas.js +0 -2828
  126. package/src/display/font_loader.js +0 -484
  127. package/src/display/metadata.js +0 -41
  128. package/src/display/network_utils.js +0 -100
  129. package/src/display/node_utils.js +0 -83
  130. package/src/display/optional_content_config.js +0 -189
  131. package/src/display/pattern_helper.js +0 -659
  132. package/src/display/svg.js +0 -1709
  133. package/src/display/text_layer.js +0 -847
  134. package/src/display/transport_stream.js +0 -303
  135. package/src/display/worker_options.js +0 -40
  136. package/src/display/xfa_layer.js +0 -204
  137. package/src/doc_helper.js +0 -25
  138. package/src/images/logo.svg +0 -41
  139. package/src/interfaces.js +0 -169
  140. package/src/license_header.js +0 -14
  141. package/src/license_header_libre.js +0 -21
  142. package/src/pdf.image_decoders.js +0 -46
  143. package/src/pdf.js +0 -146
  144. package/src/pdf.sandbox.external.js +0 -181
  145. package/src/pdf.sandbox.js +0 -151
  146. package/src/pdf.scripting.js +0 -25
  147. package/src/pdf.worker.entry.js +0 -19
  148. package/src/pdf.worker.js +0 -23
  149. package/src/scripting_api/aform.js +0 -608
  150. package/src/scripting_api/app.js +0 -621
  151. package/src/scripting_api/color.js +0 -129
  152. package/src/scripting_api/common.js +0 -58
  153. package/src/scripting_api/console.js +0 -38
  154. package/src/scripting_api/constants.js +0 -208
  155. package/src/scripting_api/doc.js +0 -1195
  156. package/src/scripting_api/error.js +0 -23
  157. package/src/scripting_api/event.js +0 -232
  158. package/src/scripting_api/field.js +0 -620
  159. package/src/scripting_api/fullscreen.js +0 -145
  160. package/src/scripting_api/initialization.js +0 -223
  161. package/src/scripting_api/pdf_object.js +0 -24
  162. package/src/scripting_api/print_params.js +0 -146
  163. package/src/scripting_api/proxy.js +0 -139
  164. package/src/scripting_api/thermometer.js +0 -69
  165. package/src/scripting_api/util.js +0 -581
  166. package/src/shared/.eslintrc +0 -13
  167. package/src/shared/cffStandardStrings.js +0 -311
  168. package/src/shared/compatibility.js +0 -114
  169. package/src/shared/fonts_utils.js +0 -429
  170. package/src/shared/is_node.js +0 -27
  171. package/src/shared/scripting_utils.js +0 -85
  172. package/src/worker_loader.js +0 -32
@@ -1,3 +1,5 @@
1
+ import { u as unreachable, D as CMapCompressionType, K as BaseException, c as assert, J as removeNullCharacters, w as warn, L as isString, n as stringToBytes, e as Util } from './util.js';
2
+
1
3
  /* Copyright 2015 Mozilla Foundation
2
4
  *
3
5
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,77 +15,258 @@
13
15
  * limitations under the License.
14
16
  */
15
17
 
16
- import {
17
- assert,
18
- BaseException,
19
- isString,
20
- removeNullCharacters,
21
- stringToBytes,
22
- Util,
23
- warn,
24
- } from "../shared/util.js";
25
- import {
26
- BaseCanvasFactory,
27
- BaseCMapReaderFactory,
28
- BaseStandardFontDataFactory,
29
- BaseSVGFactory,
30
- } from "./base_factory.js";
18
+ class BaseCanvasFactory {
19
+ constructor() {
20
+ if (this.constructor === BaseCanvasFactory) {
21
+ unreachable("Cannot initialize BaseCanvasFactory.");
22
+ }
23
+ }
24
+
25
+ create(width, height) {
26
+ if (width <= 0 || height <= 0) {
27
+ throw new Error("Invalid canvas size");
28
+ }
29
+
30
+ const canvas = this._createCanvas(width, height);
31
+
32
+ return {
33
+ canvas,
34
+ context: canvas.getContext("2d")
35
+ };
36
+ }
37
+
38
+ reset(canvasAndContext, width, height) {
39
+ if (!canvasAndContext.canvas) {
40
+ throw new Error("Canvas is not specified");
41
+ }
42
+
43
+ if (width <= 0 || height <= 0) {
44
+ throw new Error("Invalid canvas size");
45
+ }
46
+
47
+ canvasAndContext.canvas.width = width;
48
+ canvasAndContext.canvas.height = height;
49
+ }
50
+
51
+ destroy(canvasAndContext) {
52
+ if (!canvasAndContext.canvas) {
53
+ throw new Error("Canvas is not specified");
54
+ } // Zeroing the width and height cause Firefox to release graphics
55
+ // resources immediately, which can greatly reduce memory consumption.
56
+
57
+
58
+ canvasAndContext.canvas.width = 0;
59
+ canvasAndContext.canvas.height = 0;
60
+ canvasAndContext.canvas = null;
61
+ canvasAndContext.context = null;
62
+ }
63
+ /**
64
+ * @private
65
+ */
66
+
67
+
68
+ _createCanvas(width, height) {
69
+ unreachable("Abstract method `_createCanvas` called.");
70
+ }
71
+
72
+ }
73
+
74
+ class BaseCMapReaderFactory {
75
+ constructor({
76
+ baseUrl = null,
77
+ isCompressed = false
78
+ }) {
79
+ if (this.constructor === BaseCMapReaderFactory) {
80
+ unreachable("Cannot initialize BaseCMapReaderFactory.");
81
+ }
82
+
83
+ this.baseUrl = baseUrl;
84
+ this.isCompressed = isCompressed;
85
+ }
86
+
87
+ async fetch({
88
+ name
89
+ }) {
90
+ if (!this.baseUrl) {
91
+ throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
92
+ }
93
+
94
+ if (!name) {
95
+ throw new Error("CMap name must be specified.");
96
+ }
97
+
98
+ const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
99
+ const compressionType = this.isCompressed ? CMapCompressionType.BINARY : CMapCompressionType.NONE;
100
+ return this._fetchData(url, compressionType).catch(reason => {
101
+ throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
102
+ });
103
+ }
104
+ /**
105
+ * @private
106
+ */
107
+
108
+
109
+ _fetchData(url, compressionType) {
110
+ unreachable("Abstract method `_fetchData` called.");
111
+ }
112
+
113
+ }
114
+
115
+ class BaseStandardFontDataFactory {
116
+ constructor({
117
+ baseUrl = null
118
+ }) {
119
+ if (this.constructor === BaseStandardFontDataFactory) {
120
+ unreachable("Cannot initialize BaseStandardFontDataFactory.");
121
+ }
31
122
 
123
+ this.baseUrl = baseUrl;
124
+ }
125
+
126
+ async fetch({
127
+ filename
128
+ }) {
129
+ if (!this.baseUrl) {
130
+ throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
131
+ }
132
+
133
+ if (!filename) {
134
+ throw new Error("Font filename must be specified.");
135
+ }
136
+
137
+ const url = `${this.baseUrl}${filename}`;
138
+ return this._fetchData(url).catch(reason => {
139
+ throw new Error(`Unable to load font data at: ${url}`);
140
+ });
141
+ }
142
+ /**
143
+ * @private
144
+ */
145
+
146
+
147
+ _fetchData(url) {
148
+ unreachable("Abstract method `_fetchData` called.");
149
+ }
150
+
151
+ }
152
+
153
+ class BaseSVGFactory {
154
+ constructor() {
155
+ if (this.constructor === BaseSVGFactory) {
156
+ unreachable("Cannot initialize BaseSVGFactory.");
157
+ }
158
+ }
159
+
160
+ create(width, height) {
161
+ if (width <= 0 || height <= 0) {
162
+ throw new Error("Invalid SVG dimensions");
163
+ }
164
+
165
+ const svg = this._createSVG("svg:svg");
166
+
167
+ svg.setAttribute("version", "1.1");
168
+ svg.setAttribute("width", `${width}px`);
169
+ svg.setAttribute("height", `${height}px`);
170
+ svg.setAttribute("preserveAspectRatio", "none");
171
+ svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
172
+ return svg;
173
+ }
174
+
175
+ createElement(type) {
176
+ if (typeof type !== "string") {
177
+ throw new Error("Invalid SVG element type");
178
+ }
179
+
180
+ return this._createSVG(type);
181
+ }
182
+ /**
183
+ * @private
184
+ */
185
+
186
+
187
+ _createSVG(type) {
188
+ unreachable("Abstract method `_createSVG` called.");
189
+ }
190
+
191
+ }
192
+
193
+ /* Copyright 2015 Mozilla Foundation
194
+ *
195
+ * Licensed under the Apache License, Version 2.0 (the "License");
196
+ * you may not use this file except in compliance with the License.
197
+ * You may obtain a copy of the License at
198
+ *
199
+ * http://www.apache.org/licenses/LICENSE-2.0
200
+ *
201
+ * Unless required by applicable law or agreed to in writing, software
202
+ * distributed under the License is distributed on an "AS IS" BASIS,
203
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
204
+ * See the License for the specific language governing permissions and
205
+ * limitations under the License.
206
+ */
32
207
  const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
33
208
  const SVG_NS = "http://www.w3.org/2000/svg";
34
209
 
35
210
  class DOMCanvasFactory extends BaseCanvasFactory {
36
- constructor({ ownerDocument = globalThis.document } = {}) {
211
+ constructor({
212
+ ownerDocument = globalThis.document
213
+ } = {}) {
37
214
  super();
38
215
  this._document = ownerDocument;
39
216
  }
40
217
 
41
218
  _createCanvas(width, height) {
42
219
  const canvas = this._document.createElement("canvas");
220
+
43
221
  canvas.width = width;
44
222
  canvas.height = height;
45
223
  return canvas;
46
224
  }
225
+
47
226
  }
48
227
 
49
228
  async function fetchData(url, asTypedArray = false) {
50
- if (
51
- (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
52
- isValidFetchUrl(url, document.baseURI)
53
- ) {
229
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") || isValidFetchUrl(url, document.baseURI)) {
54
230
  const response = await fetch(url);
231
+
55
232
  if (!response.ok) {
56
233
  throw new Error(response.statusText);
57
234
  }
58
- return asTypedArray
59
- ? new Uint8Array(await response.arrayBuffer())
60
- : stringToBytes(await response.text());
61
- }
62
235
 
63
- // The Fetch API is not supported.
236
+ return asTypedArray ? new Uint8Array(await response.arrayBuffer()) : stringToBytes(await response.text());
237
+ } // The Fetch API is not supported.
238
+
239
+
64
240
  return new Promise((resolve, reject) => {
65
241
  const request = new XMLHttpRequest();
66
- request.open("GET", url, /* asTypedArray = */ true);
242
+ request.open("GET", url,
243
+ /* asTypedArray = */
244
+ true);
67
245
 
68
246
  if (asTypedArray) {
69
247
  request.responseType = "arraybuffer";
70
248
  }
249
+
71
250
  request.onreadystatechange = () => {
72
251
  if (request.readyState !== XMLHttpRequest.DONE) {
73
252
  return;
74
253
  }
254
+
75
255
  if (request.status === 200 || request.status === 0) {
76
256
  let data;
257
+
77
258
  if (asTypedArray && request.response) {
78
259
  data = new Uint8Array(request.response);
79
260
  } else if (!asTypedArray && request.responseText) {
80
261
  data = stringToBytes(request.responseText);
81
262
  }
263
+
82
264
  if (data) {
83
265
  resolve(data);
84
266
  return;
85
267
  }
86
268
  }
269
+
87
270
  reject(new Error(request.statusText));
88
271
  };
89
272
 
@@ -93,24 +276,33 @@ async function fetchData(url, asTypedArray = false) {
93
276
 
94
277
  class DOMCMapReaderFactory extends BaseCMapReaderFactory {
95
278
  _fetchData(url, compressionType) {
96
- return fetchData(url, /* asTypedArray = */ this.isCompressed).then(data => {
97
- return { cMapData: data, compressionType };
279
+ return fetchData(url,
280
+ /* asTypedArray = */
281
+ this.isCompressed).then(data => {
282
+ return {
283
+ cMapData: data,
284
+ compressionType
285
+ };
98
286
  });
99
287
  }
288
+
100
289
  }
101
290
 
102
291
  class DOMStandardFontDataFactory extends BaseStandardFontDataFactory {
103
292
  _fetchData(url) {
104
- return fetchData(url, /* asTypedArray = */ true);
293
+ return fetchData(url,
294
+ /* asTypedArray = */
295
+ true);
105
296
  }
297
+
106
298
  }
107
299
 
108
300
  class DOMSVGFactory extends BaseSVGFactory {
109
301
  _createSVG(type) {
110
302
  return document.createElementNS(SVG_NS, type);
111
303
  }
112
- }
113
304
 
305
+ }
114
306
  /**
115
307
  * @typedef {Object} PageViewportParameters
116
308
  * @property {Array<number>} viewBox - The xMin, yMin, xMax and
@@ -142,6 +334,8 @@ class DOMSVGFactory extends BaseSVGFactory {
142
334
  /**
143
335
  * PDF page viewport created based on scale, rotation and offset.
144
336
  */
337
+
338
+
145
339
  class PageViewport {
146
340
  /**
147
341
  * @param {PageViewportParameters}
@@ -152,24 +346,25 @@ class PageViewport {
152
346
  rotation,
153
347
  offsetX = 0,
154
348
  offsetY = 0,
155
- dontFlip = false,
349
+ dontFlip = false
156
350
  }) {
157
351
  this.viewBox = viewBox;
158
352
  this.scale = scale;
159
353
  this.rotation = rotation;
160
354
  this.offsetX = offsetX;
161
- this.offsetY = offsetY;
162
-
163
- // creating transform to convert pdf coordinate system to the normal
355
+ this.offsetY = offsetY; // creating transform to convert pdf coordinate system to the normal
164
356
  // canvas like coordinates taking in account scale and rotation
357
+
165
358
  const centerX = (viewBox[2] + viewBox[0]) / 2;
166
359
  const centerY = (viewBox[3] + viewBox[1]) / 2;
167
- let rotateA, rotateB, rotateC, rotateD;
168
- // Normalize the rotation, by clamping it to the [0, 360) range.
360
+ let rotateA, rotateB, rotateC, rotateD; // Normalize the rotation, by clamping it to the [0, 360) range.
361
+
169
362
  rotation %= 360;
363
+
170
364
  if (rotation < 0) {
171
365
  rotation += 360;
172
366
  }
367
+
173
368
  switch (rotation) {
174
369
  case 180:
175
370
  rotateA = -1;
@@ -177,28 +372,30 @@ class PageViewport {
177
372
  rotateC = 0;
178
373
  rotateD = 1;
179
374
  break;
375
+
180
376
  case 90:
181
377
  rotateA = 0;
182
378
  rotateB = 1;
183
379
  rotateC = 1;
184
380
  rotateD = 0;
185
381
  break;
382
+
186
383
  case 270:
187
384
  rotateA = 0;
188
385
  rotateB = -1;
189
386
  rotateC = -1;
190
387
  rotateD = 0;
191
388
  break;
389
+
192
390
  case 0:
193
391
  rotateA = 1;
194
392
  rotateB = 0;
195
393
  rotateC = 0;
196
394
  rotateD = -1;
197
395
  break;
396
+
198
397
  default:
199
- throw new Error(
200
- "PageViewport: Invalid rotation, must be a multiple of 90 degrees."
201
- );
398
+ throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
202
399
  }
203
400
 
204
401
  if (dontFlip) {
@@ -208,6 +405,7 @@ class PageViewport {
208
405
 
209
406
  let offsetCanvasX, offsetCanvasY;
210
407
  let width, height;
408
+
211
409
  if (rotateA === 0) {
212
410
  offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
213
411
  offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
@@ -218,34 +416,28 @@ class PageViewport {
218
416
  offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
219
417
  width = Math.abs(viewBox[2] - viewBox[0]) * scale;
220
418
  height = Math.abs(viewBox[3] - viewBox[1]) * scale;
221
- }
222
- // creating transform for the following operations:
419
+ } // creating transform for the following operations:
223
420
  // translate(-centerX, -centerY), rotate and flip vertically,
224
421
  // scale, and translate(offsetCanvasX, offsetCanvasY)
225
- this.transform = [
226
- rotateA * scale,
227
- rotateB * scale,
228
- rotateC * scale,
229
- rotateD * scale,
230
- offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
231
- offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY,
232
- ];
233
422
 
423
+
424
+ this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
234
425
  this.width = width;
235
426
  this.height = height;
236
427
  }
237
-
238
428
  /**
239
429
  * Clones viewport, with optional additional properties.
240
430
  * @param {PageViewportCloneParameters} [params]
241
431
  * @returns {PageViewport} Cloned viewport.
242
432
  */
433
+
434
+
243
435
  clone({
244
436
  scale = this.scale,
245
437
  rotation = this.rotation,
246
438
  offsetX = this.offsetX,
247
439
  offsetY = this.offsetY,
248
- dontFlip = false,
440
+ dontFlip = false
249
441
  } = {}) {
250
442
  return new PageViewport({
251
443
  viewBox: this.viewBox.slice(),
@@ -253,10 +445,9 @@ class PageViewport {
253
445
  rotation,
254
446
  offsetX,
255
447
  offsetY,
256
- dontFlip,
448
+ dontFlip
257
449
  });
258
450
  }
259
-
260
451
  /**
261
452
  * Converts PDF point to the viewport coordinates. For examples, useful for
262
453
  * converting PDF location into canvas pixel coordinates.
@@ -267,10 +458,11 @@ class PageViewport {
267
458
  * @see {@link convertToPdfPoint}
268
459
  * @see {@link convertToViewportRectangle}
269
460
  */
461
+
462
+
270
463
  convertToViewportPoint(x, y) {
271
464
  return Util.applyTransform([x, y], this.transform);
272
465
  }
273
-
274
466
  /**
275
467
  * Converts PDF rectangle to the viewport coordinates.
276
468
  * @param {Array} rect - The xMin, yMin, xMax and yMax coordinates.
@@ -278,12 +470,13 @@ class PageViewport {
278
470
  * rectangle in the viewport coordinate space.
279
471
  * @see {@link convertToViewportPoint}
280
472
  */
473
+
474
+
281
475
  convertToViewportRectangle(rect) {
282
476
  const topLeft = Util.applyTransform([rect[0], rect[1]], this.transform);
283
477
  const bottomRight = Util.applyTransform([rect[2], rect[3]], this.transform);
284
478
  return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
285
479
  }
286
-
287
480
  /**
288
481
  * Converts viewport coordinates to the PDF location. For examples, useful
289
482
  * for converting canvas pixel location into PDF one.
@@ -293,9 +486,12 @@ class PageViewport {
293
486
  * point in the PDF coordinate space.
294
487
  * @see {@link convertToViewportPoint}
295
488
  */
489
+
490
+
296
491
  convertToPdfPoint(x, y) {
297
492
  return Util.applyInverseTransform([x, y], this.transform);
298
493
  }
494
+
299
495
  }
300
496
 
301
497
  class RenderingCancelledException extends BaseException {
@@ -303,16 +499,17 @@ class RenderingCancelledException extends BaseException {
303
499
  super(msg);
304
500
  this.type = type;
305
501
  }
502
+
306
503
  }
307
504
 
308
505
  const LinkTarget = {
309
- NONE: 0, // Default value.
506
+ NONE: 0,
507
+ // Default value.
310
508
  SELF: 1,
311
509
  BLANK: 2,
312
510
  PARENT: 3,
313
- TOP: 4,
511
+ TOP: 4
314
512
  };
315
-
316
513
  /**
317
514
  * @typedef ExternalLinkParameters
318
515
  * @typedef {Object} ExternalLinkParameters
@@ -330,73 +527,81 @@ const LinkTarget = {
330
527
  * @param {HTMLLinkElement} link - The link element.
331
528
  * @param {ExternalLinkParameters} params
332
529
  */
333
- function addLinkAttributes(link, { url, target, rel, enabled = true } = {}) {
334
- assert(
335
- url && typeof url === "string",
336
- 'addLinkAttributes: A valid "url" parameter must provided.'
337
- );
338
530
 
531
+ function addLinkAttributes(link, {
532
+ url,
533
+ target,
534
+ rel,
535
+ enabled = true
536
+ } = {}) {
537
+ assert(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
339
538
  const urlNullRemoved = removeNullCharacters(url);
539
+
340
540
  if (enabled) {
341
541
  link.href = link.title = urlNullRemoved;
342
542
  } else {
343
543
  link.href = "";
344
544
  link.title = `Disabled: ${urlNullRemoved}`;
545
+
345
546
  link.onclick = () => {
346
547
  return false;
347
548
  };
348
549
  }
349
550
 
350
551
  let targetStr = ""; // LinkTarget.NONE
552
+
351
553
  switch (target) {
352
554
  case LinkTarget.NONE:
353
555
  break;
556
+
354
557
  case LinkTarget.SELF:
355
558
  targetStr = "_self";
356
559
  break;
560
+
357
561
  case LinkTarget.BLANK:
358
562
  targetStr = "_blank";
359
563
  break;
564
+
360
565
  case LinkTarget.PARENT:
361
566
  targetStr = "_parent";
362
567
  break;
568
+
363
569
  case LinkTarget.TOP:
364
570
  targetStr = "_top";
365
571
  break;
366
572
  }
367
- link.target = targetStr;
368
573
 
574
+ link.target = targetStr;
369
575
  link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
370
576
  }
371
577
 
372
578
  function isDataScheme(url) {
373
579
  const ii = url.length;
374
580
  let i = 0;
581
+
375
582
  while (i < ii && url[i].trim() === "") {
376
583
  i++;
377
584
  }
585
+
378
586
  return url.substring(i, i + 5).toLowerCase() === "data:";
379
587
  }
380
588
 
381
589
  function isPdfFile(filename) {
382
590
  return typeof filename === "string" && /\.pdf$/i.test(filename);
383
591
  }
384
-
385
592
  /**
386
593
  * Gets the filename from a given URL.
387
594
  * @param {string} url
388
595
  * @returns {string}
389
596
  */
597
+
598
+
390
599
  function getFilenameFromUrl(url) {
391
600
  const anchor = url.indexOf("#");
392
601
  const query = url.indexOf("?");
393
- const end = Math.min(
394
- anchor > 0 ? anchor : url.length,
395
- query > 0 ? query : url.length
396
- );
602
+ const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
397
603
  return url.substring(url.lastIndexOf("/", end) + 1, end);
398
604
  }
399
-
400
605
  /**
401
606
  * Returns the filename or guessed filename from the url (see issue 3455).
402
607
  * @param {string} url - The original PDF location.
@@ -404,38 +609,39 @@ function getFilenameFromUrl(url) {
404
609
  * unknown, or the protocol is unsupported.
405
610
  * @returns {string} Guessed PDF filename.
406
611
  */
612
+
613
+
407
614
  function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
408
615
  if (typeof url !== "string") {
409
616
  return defaultFilename;
410
617
  }
618
+
411
619
  if (isDataScheme(url)) {
412
620
  warn('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
413
621
  return defaultFilename;
414
622
  }
415
- const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
416
- // SCHEME HOST 1.PATH 2.QUERY 3.REF
623
+
624
+ const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/; // SCHEME HOST 1.PATH 2.QUERY 3.REF
417
625
  // Pattern to get last matching NAME.pdf
626
+
418
627
  const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
419
628
  const splitURI = reURI.exec(url);
420
- let suggestedFilename =
421
- reFilename.exec(splitURI[1]) ||
422
- reFilename.exec(splitURI[2]) ||
423
- reFilename.exec(splitURI[3]);
629
+ let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
630
+
424
631
  if (suggestedFilename) {
425
632
  suggestedFilename = suggestedFilename[0];
633
+
426
634
  if (suggestedFilename.includes("%")) {
427
635
  // URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
428
636
  try {
429
- suggestedFilename = reFilename.exec(
430
- decodeURIComponent(suggestedFilename)
431
- )[0];
432
- } catch (ex) {
433
- // Possible (extremely rare) errors:
637
+ suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
638
+ } catch (ex) {// Possible (extremely rare) errors:
434
639
  // URIError "Malformed URI", e.g. for "%AA.pdf"
435
640
  // TypeError "null has no properties", e.g. for "%2F.pdf"
436
641
  }
437
642
  }
438
643
  }
644
+
439
645
  return suggestedFilename || defaultFilename;
440
646
  }
441
647
 
@@ -449,6 +655,7 @@ class StatTimer {
449
655
  if (name in this.started) {
450
656
  warn(`Timer is already running for ${name}`);
451
657
  }
658
+
452
659
  this.started[name] = Date.now();
453
660
  }
454
661
 
@@ -456,12 +663,13 @@ class StatTimer {
456
663
  if (!(name in this.started)) {
457
664
  warn(`Timer has not been started for ${name}`);
458
665
  }
666
+
459
667
  this.times.push({
460
668
  name,
461
669
  start: this.started[name],
462
- end: Date.now(),
463
- });
464
- // Remove timer from started so it can be called again.
670
+ end: Date.now()
671
+ }); // Remove timer from started so it can be called again.
672
+
465
673
  delete this.started[name];
466
674
  }
467
675
 
@@ -469,35 +677,43 @@ class StatTimer {
469
677
  // Find the longest name for padding purposes.
470
678
  const outBuf = [];
471
679
  let longest = 0;
680
+
472
681
  for (const time of this.times) {
473
682
  const name = time.name;
683
+
474
684
  if (name.length > longest) {
475
685
  longest = name.length;
476
686
  }
477
687
  }
688
+
478
689
  for (const time of this.times) {
479
690
  const duration = time.end - time.start;
480
691
  outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
481
692
  }
693
+
482
694
  return outBuf.join("");
483
695
  }
696
+
484
697
  }
485
698
 
486
699
  function isValidFetchUrl(url, baseUrl) {
487
700
  try {
488
- const { protocol } = baseUrl ? new URL(url, baseUrl) : new URL(url);
489
- // The Fetch API only supports the http/https protocols, and not file/ftp.
701
+ const {
702
+ protocol
703
+ } = baseUrl ? new URL(url, baseUrl) : new URL(url); // The Fetch API only supports the http/https protocols, and not file/ftp.
704
+
490
705
  return protocol === "http:" || protocol === "https:";
491
706
  } catch (ex) {
492
707
  return false; // `new URL()` will throw on incorrect data.
493
708
  }
494
709
  }
495
-
496
710
  /**
497
711
  * @param {string} src
498
712
  * @param {boolean} [removeScriptElement]
499
713
  * @returns {Promise<void>}
500
714
  */
715
+
716
+
501
717
  function loadScript(src, removeScriptElement = false) {
502
718
  return new Promise((resolve, reject) => {
503
719
  const script = document.createElement("script");
@@ -507,16 +723,19 @@ function loadScript(src, removeScriptElement = false) {
507
723
  if (removeScriptElement) {
508
724
  script.remove();
509
725
  }
726
+
510
727
  resolve(evt);
511
728
  };
729
+
512
730
  script.onerror = function () {
513
731
  reject(new Error(`Cannot load script at: ${script.src}`));
514
732
  };
733
+
515
734
  (document.head || document.documentElement).appendChild(script);
516
735
  });
517
- }
736
+ } // Deprecated API function -- display regardless of the `verbosity` setting.
737
+
518
738
 
519
- // Deprecated API function -- display regardless of the `verbosity` setting.
520
739
  function deprecated(details) {
521
740
  console.log("Deprecated API usage: " + details);
522
741
  }
@@ -543,36 +762,36 @@ class PDFDateString {
543
762
  static toDateObject(input) {
544
763
  if (!input || !isString(input)) {
545
764
  return null;
546
- }
765
+ } // Lazily initialize the regular expression.
766
+
547
767
 
548
- // Lazily initialize the regular expression.
549
768
  if (!pdfDateStringRegex) {
550
- pdfDateStringRegex = new RegExp(
551
- "^D:" + // Prefix (required)
552
- "(\\d{4})" + // Year (required)
553
- "(\\d{2})?" + // Month (optional)
554
- "(\\d{2})?" + // Day (optional)
555
- "(\\d{2})?" + // Hour (optional)
556
- "(\\d{2})?" + // Minute (optional)
557
- "(\\d{2})?" + // Second (optional)
558
- "([Z|+|-])?" + // Universal time relation (optional)
559
- "(\\d{2})?" + // Offset hour (optional)
560
- "'?" + // Splitting apostrophe (optional)
561
- "(\\d{2})?" + // Offset minute (optional)
562
- "'?" // Trailing apostrophe (optional)
769
+ pdfDateStringRegex = new RegExp("^D:" + // Prefix (required)
770
+ "(\\d{4})" + // Year (required)
771
+ "(\\d{2})?" + // Month (optional)
772
+ "(\\d{2})?" + // Day (optional)
773
+ "(\\d{2})?" + // Hour (optional)
774
+ "(\\d{2})?" + // Minute (optional)
775
+ "(\\d{2})?" + // Second (optional)
776
+ "([Z|+|-])?" + // Universal time relation (optional)
777
+ "(\\d{2})?" + // Offset hour (optional)
778
+ "'?" + // Splitting apostrophe (optional)
779
+ "(\\d{2})?" + // Offset minute (optional)
780
+ "'?" // Trailing apostrophe (optional)
563
781
  );
564
- }
565
-
566
- // Optional fields that don't satisfy the requirements from the regular
782
+ } // Optional fields that don't satisfy the requirements from the regular
567
783
  // expression (such as incorrect digit counts or numbers that are out of
568
784
  // range) will fall back the defaults from the specification.
785
+
786
+
569
787
  const matches = pdfDateStringRegex.exec(input);
788
+
570
789
  if (!matches) {
571
790
  return null;
572
- }
573
-
574
- // JavaScript's `Date` object expects the month to be between 0 and 11
791
+ } // JavaScript's `Date` object expects the month to be between 0 and 11
575
792
  // instead of 1 and 12, so we have to correct for that.
793
+
794
+
576
795
  const year = parseInt(matches[1], 10);
577
796
  let month = parseInt(matches[2], 10);
578
797
  month = month >= 1 && month <= 12 ? month - 1 : 0;
@@ -588,12 +807,11 @@ class PDFDateString {
588
807
  let offsetHour = parseInt(matches[8], 10);
589
808
  offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
590
809
  let offsetMinute = parseInt(matches[9], 10) || 0;
591
- offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
592
-
593
- // Universal time relation 'Z' means that the local time is equal to the
810
+ offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0; // Universal time relation 'Z' means that the local time is equal to the
594
811
  // universal time, whereas the relations '+'/'-' indicate that the local
595
812
  // time is later respectively earlier than the universal time. Every date
596
813
  // is normalized to universal time.
814
+
597
815
  if (universalTimeRelation === "-") {
598
816
  hour += offsetHour;
599
817
  minute += offsetMinute;
@@ -604,40 +822,27 @@ class PDFDateString {
604
822
 
605
823
  return new Date(Date.UTC(year, month, day, hour, minute, second));
606
824
  }
607
- }
608
825
 
826
+ }
609
827
  /**
610
828
  * NOTE: This is (mostly) intended to support printing of XFA forms.
611
829
  */
612
- function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
613
- const { width, height } = xfaPage.attributes.style;
614
- const viewBox = [0, 0, parseInt(width), parseInt(height)];
615
830
 
831
+
832
+ function getXfaPageViewport(xfaPage, {
833
+ scale = 1,
834
+ rotation = 0
835
+ }) {
836
+ const {
837
+ width,
838
+ height
839
+ } = xfaPage.attributes.style;
840
+ const viewBox = [0, 0, parseInt(width), parseInt(height)];
616
841
  return new PageViewport({
617
842
  viewBox,
618
843
  scale,
619
- rotation,
844
+ rotation
620
845
  });
621
846
  }
622
847
 
623
- export {
624
- addLinkAttributes,
625
- DEFAULT_LINK_REL,
626
- deprecated,
627
- DOMCanvasFactory,
628
- DOMCMapReaderFactory,
629
- DOMStandardFontDataFactory,
630
- DOMSVGFactory,
631
- getFilenameFromUrl,
632
- getPdfFilenameFromUrl,
633
- getXfaPageViewport,
634
- isDataScheme,
635
- isPdfFile,
636
- isValidFetchUrl,
637
- LinkTarget,
638
- loadScript,
639
- PageViewport,
640
- PDFDateString,
641
- RenderingCancelledException,
642
- StatTimer,
643
- };
848
+ export { BaseCanvasFactory as B, DOMCanvasFactory as D, LinkTarget as L, PageViewport as P, RenderingCancelledException as R, StatTimer as S, BaseCMapReaderFactory as a, BaseStandardFontDataFactory as b, DOMCMapReaderFactory as c, DOMStandardFontDataFactory as d, isDataScheme as e, deprecated as f, DOMSVGFactory as g, addLinkAttributes as h, isPdfFile as i, PDFDateString as j, getFilenameFromUrl as k, loadScript as l, isValidFetchUrl as m, getPdfFilenameFromUrl as n, getXfaPageViewport as o };