@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4

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 (174) hide show
  1. package/README.md +1 -1
  2. package/package.json +33 -18
  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/get.js +1857 -0
  6. package/pdfjs/dist/index.js +767 -0
  7. package/pdfjs/dist/l10n_utils.js +140 -0
  8. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  9. package/{src/display → pdfjs/dist}/network.js +149 -87
  10. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  11. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  12. package/pdfjs/dist/pdf.js +12778 -0
  13. package/pdfjs/dist/pdf_link_service.js +638 -0
  14. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  15. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  16. package/pdfjs/dist/pdf_viewer.js +3598 -0
  17. package/pdfjs/dist/typeof.js +100 -0
  18. package/pdfjs/dist/ui_utils.js +1033 -0
  19. package/{src/shared → pdfjs/dist}/util.js +301 -287
  20. package/pdfjs/dist/worker.js +62813 -0
  21. package/src/vcf-pdf-viewer.js +77 -27
  22. package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
  23. package/theme/material/vcf-pdf-viewer.js +2 -2
  24. package/src/core/.eslintrc +0 -13
  25. package/src/core/annotation.js +0 -2948
  26. package/src/core/arithmetic_decoder.js +0 -182
  27. package/src/core/ascii_85_stream.js +0 -98
  28. package/src/core/ascii_hex_stream.js +0 -79
  29. package/src/core/base_stream.js +0 -110
  30. package/src/core/bidi.js +0 -438
  31. package/src/core/calibri_factors.js +0 -308
  32. package/src/core/catalog.js +0 -1459
  33. package/src/core/ccitt.js +0 -1062
  34. package/src/core/ccitt_stream.js +0 -60
  35. package/src/core/cff_font.js +0 -116
  36. package/src/core/cff_parser.js +0 -1949
  37. package/src/core/charsets.js +0 -119
  38. package/src/core/chunked_stream.js +0 -557
  39. package/src/core/cmap.js +0 -1039
  40. package/src/core/colorspace.js +0 -1533
  41. package/src/core/core_utils.js +0 -464
  42. package/src/core/crypto.js +0 -1900
  43. package/src/core/decode_stream.js +0 -170
  44. package/src/core/decrypt_stream.js +0 -59
  45. package/src/core/default_appearance.js +0 -99
  46. package/src/core/document.js +0 -1456
  47. package/src/core/encodings.js +0 -301
  48. package/src/core/evaluator.js +0 -4601
  49. package/src/core/file_spec.js +0 -108
  50. package/src/core/flate_stream.js +0 -402
  51. package/src/core/font_renderer.js +0 -882
  52. package/src/core/fonts.js +0 -3260
  53. package/src/core/fonts_utils.js +0 -221
  54. package/src/core/function.js +0 -1257
  55. package/src/core/glyf.js +0 -706
  56. package/src/core/glyphlist.js +0 -4558
  57. package/src/core/helvetica_factors.js +0 -353
  58. package/src/core/image.js +0 -802
  59. package/src/core/image_utils.js +0 -291
  60. package/src/core/jbig2.js +0 -2572
  61. package/src/core/jbig2_stream.js +0 -73
  62. package/src/core/jpeg_stream.js +0 -105
  63. package/src/core/jpg.js +0 -1416
  64. package/src/core/jpx.js +0 -2343
  65. package/src/core/jpx_stream.js +0 -87
  66. package/src/core/liberationsans_widths.js +0 -221
  67. package/src/core/lzw_stream.js +0 -150
  68. package/src/core/metadata_parser.js +0 -146
  69. package/src/core/metrics.js +0 -2970
  70. package/src/core/murmurhash3.js +0 -139
  71. package/src/core/myriadpro_factors.js +0 -290
  72. package/src/core/name_number_tree.js +0 -153
  73. package/src/core/object_loader.js +0 -149
  74. package/src/core/opentype_file_builder.js +0 -154
  75. package/src/core/operator_list.js +0 -734
  76. package/src/core/parser.js +0 -1416
  77. package/src/core/pattern.js +0 -985
  78. package/src/core/pdf_manager.js +0 -217
  79. package/src/core/predictor_stream.js +0 -238
  80. package/src/core/primitives.js +0 -402
  81. package/src/core/ps_parser.js +0 -272
  82. package/src/core/run_length_stream.js +0 -61
  83. package/src/core/segoeui_factors.js +0 -308
  84. package/src/core/standard_fonts.js +0 -817
  85. package/src/core/stream.js +0 -103
  86. package/src/core/struct_tree.js +0 -335
  87. package/src/core/to_unicode_map.js +0 -103
  88. package/src/core/type1_font.js +0 -421
  89. package/src/core/type1_parser.js +0 -776
  90. package/src/core/unicode.js +0 -1649
  91. package/src/core/worker.js +0 -848
  92. package/src/core/worker_stream.js +0 -135
  93. package/src/core/writer.js +0 -278
  94. package/src/core/xfa/bind.js +0 -652
  95. package/src/core/xfa/builder.js +0 -207
  96. package/src/core/xfa/config.js +0 -1926
  97. package/src/core/xfa/connection_set.js +0 -202
  98. package/src/core/xfa/data.js +0 -82
  99. package/src/core/xfa/datasets.js +0 -76
  100. package/src/core/xfa/factory.js +0 -111
  101. package/src/core/xfa/fonts.js +0 -181
  102. package/src/core/xfa/formcalc_lexer.js +0 -385
  103. package/src/core/xfa/formcalc_parser.js +0 -1340
  104. package/src/core/xfa/html_utils.js +0 -639
  105. package/src/core/xfa/layout.js +0 -383
  106. package/src/core/xfa/locale_set.js +0 -345
  107. package/src/core/xfa/namespaces.js +0 -81
  108. package/src/core/xfa/parser.js +0 -184
  109. package/src/core/xfa/setup.js +0 -38
  110. package/src/core/xfa/signature.js +0 -40
  111. package/src/core/xfa/som.js +0 -338
  112. package/src/core/xfa/stylesheet.js +0 -40
  113. package/src/core/xfa/template.js +0 -6260
  114. package/src/core/xfa/text.js +0 -290
  115. package/src/core/xfa/unknown.js +0 -29
  116. package/src/core/xfa/utils.js +0 -217
  117. package/src/core/xfa/xdp.js +0 -59
  118. package/src/core/xfa/xfa_object.js +0 -1130
  119. package/src/core/xfa/xhtml.js +0 -543
  120. package/src/core/xfa_fonts.js +0 -208
  121. package/src/core/xml_parser.js +0 -507
  122. package/src/core/xref.js +0 -899
  123. package/src/display/annotation_layer.js +0 -2107
  124. package/src/display/annotation_storage.js +0 -113
  125. package/src/display/api.js +0 -3292
  126. package/src/display/base_factory.js +0 -180
  127. package/src/display/canvas.js +0 -2828
  128. package/src/display/font_loader.js +0 -484
  129. package/src/display/metadata.js +0 -41
  130. package/src/display/network_utils.js +0 -100
  131. package/src/display/node_utils.js +0 -83
  132. package/src/display/optional_content_config.js +0 -189
  133. package/src/display/pattern_helper.js +0 -659
  134. package/src/display/svg.js +0 -1709
  135. package/src/display/text_layer.js +0 -847
  136. package/src/display/transport_stream.js +0 -303
  137. package/src/display/worker_options.js +0 -40
  138. package/src/display/xfa_layer.js +0 -204
  139. package/src/doc_helper.js +0 -25
  140. package/src/images/logo.svg +0 -41
  141. package/src/interfaces.js +0 -169
  142. package/src/license_header.js +0 -14
  143. package/src/license_header_libre.js +0 -21
  144. package/src/pdf.image_decoders.js +0 -46
  145. package/src/pdf.js +0 -146
  146. package/src/pdf.sandbox.external.js +0 -181
  147. package/src/pdf.sandbox.js +0 -151
  148. package/src/pdf.scripting.js +0 -25
  149. package/src/pdf.worker.entry.js +0 -19
  150. package/src/pdf.worker.js +0 -23
  151. package/src/scripting_api/aform.js +0 -608
  152. package/src/scripting_api/app.js +0 -621
  153. package/src/scripting_api/color.js +0 -129
  154. package/src/scripting_api/common.js +0 -58
  155. package/src/scripting_api/console.js +0 -38
  156. package/src/scripting_api/constants.js +0 -208
  157. package/src/scripting_api/doc.js +0 -1195
  158. package/src/scripting_api/error.js +0 -23
  159. package/src/scripting_api/event.js +0 -232
  160. package/src/scripting_api/field.js +0 -620
  161. package/src/scripting_api/fullscreen.js +0 -145
  162. package/src/scripting_api/initialization.js +0 -223
  163. package/src/scripting_api/pdf_object.js +0 -24
  164. package/src/scripting_api/print_params.js +0 -146
  165. package/src/scripting_api/proxy.js +0 -139
  166. package/src/scripting_api/thermometer.js +0 -69
  167. package/src/scripting_api/util.js +0 -581
  168. package/src/shared/.eslintrc +0 -13
  169. package/src/shared/cffStandardStrings.js +0 -311
  170. package/src/shared/compatibility.js +0 -114
  171. package/src/shared/fonts_utils.js +0 -429
  172. package/src/shared/is_node.js +0 -27
  173. package/src/shared/scripting_utils.js +0 -85
  174. package/src/worker_loader.js +0 -32
@@ -1,3 +1,7 @@
1
+ import { c as assert, l as createPromiseCapability, n as stringToBytes } from './util.js';
2
+ import { v as validateRangeRequestCapabilities, e as extractFilenameFromHeader, c as createResponseStatusError } from './network_utils.js';
3
+ import './display_utils.js';
4
+
1
5
  /* Copyright 2012 Mozilla Foundation
2
6
  *
3
7
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,21 +17,8 @@
13
17
  * limitations under the License.
14
18
  */
15
19
 
16
- import {
17
- assert,
18
- createPromiseCapability,
19
- stringToBytes,
20
- } from "../shared/util.js";
21
- import {
22
- createResponseStatusError,
23
- extractFilenameFromHeader,
24
- validateRangeRequestCapabilities,
25
- } from "./network_utils.js";
26
-
27
20
  if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
28
- throw new Error(
29
- 'Module "./network.js" shall not be used with MOZCENTRAL builds.'
30
- );
21
+ throw new Error('Module "./network.js" shall not be used with MOZCENTRAL builds.');
31
22
  }
32
23
 
33
24
  const OK_RESPONSE = 200;
@@ -35,9 +26,11 @@ const PARTIAL_CONTENT_RESPONSE = 206;
35
26
 
36
27
  function getArrayBuffer(xhr) {
37
28
  const data = xhr.response;
29
+
38
30
  if (typeof data !== "string") {
39
31
  return data;
40
32
  }
33
+
41
34
  const array = stringToBytes(data);
42
35
  return array.buffer;
43
36
  }
@@ -47,13 +40,12 @@ class NetworkManager {
47
40
  this.url = url;
48
41
  args = args || {};
49
42
  this.isHttp = /^https?:/i.test(url);
50
- this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
43
+ this.httpHeaders = this.isHttp && args.httpHeaders || {};
51
44
  this.withCredentials = args.withCredentials || false;
52
- this.getXhr =
53
- args.getXhr ||
54
- function NetworkManager_getXhr() {
55
- return new XMLHttpRequest();
56
- };
45
+
46
+ this.getXhr = args.getXhr || function NetworkManager_getXhr() {
47
+ return new XMLHttpRequest();
48
+ };
57
49
 
58
50
  this.currXhrId = 0;
59
51
  this.pendingRequests = Object.create(null);
@@ -62,11 +54,13 @@ class NetworkManager {
62
54
  requestRange(begin, end, listeners) {
63
55
  const args = {
64
56
  begin,
65
- end,
57
+ end
66
58
  };
59
+
67
60
  for (const prop in listeners) {
68
61
  args[prop] = listeners[prop];
69
62
  }
63
+
70
64
  return this.request(args);
71
65
  }
72
66
 
@@ -77,25 +71,29 @@ class NetworkManager {
77
71
  request(args) {
78
72
  const xhr = this.getXhr();
79
73
  const xhrId = this.currXhrId++;
80
- const pendingRequest = (this.pendingRequests[xhrId] = {
81
- xhr,
82
- });
83
-
74
+ const pendingRequest = this.pendingRequests[xhrId] = {
75
+ xhr
76
+ };
84
77
  xhr.open("GET", this.url);
85
78
  xhr.withCredentials = this.withCredentials;
79
+
86
80
  for (const property in this.httpHeaders) {
87
81
  const value = this.httpHeaders[property];
82
+
88
83
  if (typeof value === "undefined") {
89
84
  continue;
90
85
  }
86
+
91
87
  xhr.setRequestHeader(property, value);
92
88
  }
89
+
93
90
  if (this.isHttp && "begin" in args && "end" in args) {
94
91
  xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
95
92
  pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
96
93
  } else {
97
94
  pendingRequest.expectedStatus = OK_RESPONSE;
98
95
  }
96
+
99
97
  xhr.responseType = "arraybuffer";
100
98
 
101
99
  if (args.onError) {
@@ -103,21 +101,20 @@ class NetworkManager {
103
101
  args.onError(xhr.status);
104
102
  };
105
103
  }
104
+
106
105
  xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
107
106
  xhr.onprogress = this.onProgress.bind(this, xhrId);
108
-
109
107
  pendingRequest.onHeadersReceived = args.onHeadersReceived;
110
108
  pendingRequest.onDone = args.onDone;
111
109
  pendingRequest.onError = args.onError;
112
110
  pendingRequest.onProgress = args.onProgress;
113
-
114
111
  xhr.send(null);
115
-
116
112
  return xhrId;
117
113
  }
118
114
 
119
115
  onProgress(xhrId, evt) {
120
116
  const pendingRequest = this.pendingRequests[xhrId];
117
+
121
118
  if (!pendingRequest) {
122
119
  // Maybe abortRequest was called...
123
120
  return;
@@ -130,12 +127,14 @@ class NetworkManager {
130
127
 
131
128
  onStateChange(xhrId, evt) {
132
129
  const pendingRequest = this.pendingRequests[xhrId];
130
+
133
131
  if (!pendingRequest) {
134
132
  // Maybe abortRequest was called...
135
133
  return;
136
134
  }
137
135
 
138
136
  const xhr = pendingRequest.xhr;
137
+
139
138
  if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
140
139
  pendingRequest.onHeadersReceived();
141
140
  delete pendingRequest.onHeadersReceived;
@@ -151,46 +150,43 @@ class NetworkManager {
151
150
  return;
152
151
  }
153
152
 
154
- delete this.pendingRequests[xhrId];
153
+ delete this.pendingRequests[xhrId]; // Success status == 0 can be on ftp, file and other protocols.
155
154
 
156
- // Success status == 0 can be on ftp, file and other protocols.
157
155
  if (xhr.status === 0 && this.isHttp) {
158
156
  if (pendingRequest.onError) {
159
157
  pendingRequest.onError(xhr.status);
160
158
  }
159
+
161
160
  return;
162
161
  }
163
- const xhrStatus = xhr.status || OK_RESPONSE;
164
162
 
165
- // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
163
+ const xhrStatus = xhr.status || OK_RESPONSE; // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
166
164
  // "A server MAY ignore the Range header". This means it's possible to
167
165
  // get a 200 rather than a 206 response from a range request.
168
- const ok_response_on_range_request =
169
- xhrStatus === OK_RESPONSE &&
170
- pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
171
-
172
- if (
173
- !ok_response_on_range_request &&
174
- xhrStatus !== pendingRequest.expectedStatus
175
- ) {
166
+
167
+ const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
168
+
169
+ if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
176
170
  if (pendingRequest.onError) {
177
171
  pendingRequest.onError(xhr.status);
178
172
  }
173
+
179
174
  return;
180
175
  }
181
176
 
182
177
  const chunk = getArrayBuffer(xhr);
178
+
183
179
  if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
184
180
  const rangeHeader = xhr.getResponseHeader("Content-Range");
185
181
  const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
186
182
  pendingRequest.onDone({
187
183
  begin: parseInt(matches[1], 10),
188
- chunk,
184
+ chunk
189
185
  });
190
186
  } else if (chunk) {
191
187
  pendingRequest.onDone({
192
188
  begin: 0,
193
- chunk,
189
+ chunk
194
190
  });
195
191
  } else if (pendingRequest.onError) {
196
192
  pendingRequest.onError(xhr.status);
@@ -210,15 +206,17 @@ class NetworkManager {
210
206
  delete this.pendingRequests[xhrId];
211
207
  xhr.abort();
212
208
  }
213
- }
214
209
 
210
+ }
215
211
  /** @implements {IPDFStream} */
212
+
213
+
216
214
  class PDFNetworkStream {
217
215
  constructor(source) {
218
216
  this._source = source;
219
217
  this._manager = new NetworkManager(source.url, {
220
218
  httpHeaders: source.httpHeaders,
221
- withCredentials: source.withCredentials,
219
+ withCredentials: source.withCredentials
222
220
  });
223
221
  this._rangeChunkSize = source.rangeChunkSize;
224
222
  this._fullRequestReader = null;
@@ -227,31 +225,24 @@ class PDFNetworkStream {
227
225
 
228
226
  _onRangeRequestReaderClosed(reader) {
229
227
  const i = this._rangeRequestReaders.indexOf(reader);
228
+
230
229
  if (i >= 0) {
231
230
  this._rangeRequestReaders.splice(i, 1);
232
231
  }
233
232
  }
234
233
 
235
234
  getFullReader() {
236
- assert(
237
- !this._fullRequestReader,
238
- "PDFNetworkStream.getFullReader can only be called once."
239
- );
240
- this._fullRequestReader = new PDFNetworkStreamFullRequestReader(
241
- this._manager,
242
- this._source
243
- );
235
+ assert(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
236
+ this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
244
237
  return this._fullRequestReader;
245
238
  }
246
239
 
247
240
  getRangeReader(begin, end) {
248
- const reader = new PDFNetworkStreamRangeRequestReader(
249
- this._manager,
250
- begin,
251
- end
252
- );
241
+ const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
253
242
  reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
243
+
254
244
  this._rangeRequestReaders.push(reader);
245
+
255
246
  return reader;
256
247
  }
257
248
 
@@ -259,66 +250,72 @@ class PDFNetworkStream {
259
250
  if (this._fullRequestReader) {
260
251
  this._fullRequestReader.cancel(reason);
261
252
  }
253
+
262
254
  for (const reader of this._rangeRequestReaders.slice(0)) {
263
255
  reader.cancel(reason);
264
256
  }
265
257
  }
266
- }
267
258
 
259
+ }
268
260
  /** @implements {IPDFStreamReader} */
261
+
262
+
269
263
  class PDFNetworkStreamFullRequestReader {
270
264
  constructor(manager, source) {
271
265
  this._manager = manager;
272
-
273
266
  const args = {
274
267
  onHeadersReceived: this._onHeadersReceived.bind(this),
275
268
  onDone: this._onDone.bind(this),
276
269
  onError: this._onError.bind(this),
277
- onProgress: this._onProgress.bind(this),
270
+ onProgress: this._onProgress.bind(this)
278
271
  };
279
272
  this._url = source.url;
280
273
  this._fullRequestId = manager.requestFull(args);
281
274
  this._headersReceivedCapability = createPromiseCapability();
282
275
  this._disableRange = source.disableRange || false;
283
276
  this._contentLength = source.length; // Optional
277
+
284
278
  this._rangeChunkSize = source.rangeChunkSize;
279
+
285
280
  if (!this._rangeChunkSize && !this._disableRange) {
286
281
  this._disableRange = true;
287
282
  }
288
283
 
289
284
  this._isStreamingSupported = false;
290
285
  this._isRangeSupported = false;
291
-
292
286
  this._cachedChunks = [];
293
287
  this._requests = [];
294
288
  this._done = false;
295
289
  this._storedError = undefined;
296
290
  this._filename = null;
297
-
298
291
  this.onProgress = null;
299
292
  }
300
293
 
301
294
  _onHeadersReceived() {
302
295
  const fullRequestXhrId = this._fullRequestId;
296
+
303
297
  const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
304
298
 
305
299
  const getResponseHeader = name => {
306
300
  return fullRequestXhr.getResponseHeader(name);
307
301
  };
308
- const { allowRangeRequests, suggestedLength } =
309
- validateRangeRequestCapabilities({
310
- getResponseHeader,
311
- isHttp: this._manager.isHttp,
312
- rangeChunkSize: this._rangeChunkSize,
313
- disableRange: this._disableRange,
314
- });
302
+
303
+ const {
304
+ allowRangeRequests,
305
+ suggestedLength
306
+ } = validateRangeRequestCapabilities({
307
+ getResponseHeader,
308
+ isHttp: this._manager.isHttp,
309
+ rangeChunkSize: this._rangeChunkSize,
310
+ disableRange: this._disableRange
311
+ });
315
312
 
316
313
  if (allowRangeRequests) {
317
314
  this._isRangeSupported = true;
318
- }
319
- // Setting right content length.
320
- this._contentLength = suggestedLength || this._contentLength;
315
+ } // Setting right content length.
316
+
321
317
 
318
+ this._contentLength = suggestedLength || this._contentLength;
322
319
  this._filename = extractFilenameFromHeader(getResponseHeader);
323
320
 
324
321
  if (this._isRangeSupported) {
@@ -336,18 +333,29 @@ class PDFNetworkStreamFullRequestReader {
336
333
  if (args) {
337
334
  if (this._requests.length > 0) {
338
335
  const requestCapability = this._requests.shift();
339
- requestCapability.resolve({ value: args.chunk, done: false });
336
+
337
+ requestCapability.resolve({
338
+ value: args.chunk,
339
+ done: false
340
+ });
340
341
  } else {
341
342
  this._cachedChunks.push(args.chunk);
342
343
  }
343
344
  }
345
+
344
346
  this._done = true;
347
+
345
348
  if (this._cachedChunks.length > 0) {
346
349
  return;
347
350
  }
351
+
348
352
  for (const requestCapability of this._requests) {
349
- requestCapability.resolve({ value: undefined, done: true });
353
+ requestCapability.resolve({
354
+ value: undefined,
355
+ done: true
356
+ });
350
357
  }
358
+
351
359
  this._requests.length = 0;
352
360
  }
353
361
 
@@ -355,10 +363,13 @@ class PDFNetworkStreamFullRequestReader {
355
363
  const url = this._url;
356
364
  const exception = createResponseStatusError(status, url);
357
365
  this._storedError = exception;
366
+
358
367
  this._headersReceivedCapability.reject(exception);
368
+
359
369
  for (const requestCapability of this._requests) {
360
370
  requestCapability.reject(exception);
361
371
  }
372
+
362
373
  this._requests.length = 0;
363
374
  this._cachedChunks.length = 0;
364
375
  }
@@ -367,7 +378,7 @@ class PDFNetworkStreamFullRequestReader {
367
378
  if (this.onProgress) {
368
379
  this.onProgress({
369
380
  loaded: data.loaded,
370
- total: data.lengthComputable ? data.total : this._contentLength,
381
+ total: data.lengthComputable ? data.total : this._contentLength
371
382
  });
372
383
  }
373
384
  }
@@ -396,45 +407,66 @@ class PDFNetworkStreamFullRequestReader {
396
407
  if (this._storedError) {
397
408
  throw this._storedError;
398
409
  }
410
+
399
411
  if (this._cachedChunks.length > 0) {
400
412
  const chunk = this._cachedChunks.shift();
401
- return { value: chunk, done: false };
413
+
414
+ return {
415
+ value: chunk,
416
+ done: false
417
+ };
402
418
  }
419
+
403
420
  if (this._done) {
404
- return { value: undefined, done: true };
421
+ return {
422
+ value: undefined,
423
+ done: true
424
+ };
405
425
  }
426
+
406
427
  const requestCapability = createPromiseCapability();
428
+
407
429
  this._requests.push(requestCapability);
430
+
408
431
  return requestCapability.promise;
409
432
  }
410
433
 
411
434
  cancel(reason) {
412
435
  this._done = true;
436
+
413
437
  this._headersReceivedCapability.reject(reason);
438
+
414
439
  for (const requestCapability of this._requests) {
415
- requestCapability.resolve({ value: undefined, done: true });
440
+ requestCapability.resolve({
441
+ value: undefined,
442
+ done: true
443
+ });
416
444
  }
445
+
417
446
  this._requests.length = 0;
447
+
418
448
  if (this._manager.isPendingRequest(this._fullRequestId)) {
419
449
  this._manager.abortRequest(this._fullRequestId);
420
450
  }
451
+
421
452
  this._fullRequestReader = null;
422
453
  }
423
- }
424
454
 
455
+ }
425
456
  /** @implements {IPDFStreamRangeReader} */
457
+
458
+
426
459
  class PDFNetworkStreamRangeRequestReader {
427
460
  constructor(manager, begin, end) {
428
461
  this._manager = manager;
429
462
  const args = {
430
463
  onDone: this._onDone.bind(this),
431
- onProgress: this._onProgress.bind(this),
464
+ onProgress: this._onProgress.bind(this)
432
465
  };
433
466
  this._requestId = manager.requestRange(begin, end, args);
434
467
  this._requests = [];
435
468
  this._queuedChunk = null;
436
469
  this._done = false;
437
-
438
470
  this.onProgress = null;
439
471
  this.onClosed = null;
440
472
  }
@@ -447,24 +479,36 @@ class PDFNetworkStreamRangeRequestReader {
447
479
 
448
480
  _onDone(data) {
449
481
  const chunk = data.chunk;
482
+
450
483
  if (this._requests.length > 0) {
451
484
  const requestCapability = this._requests.shift();
452
- requestCapability.resolve({ value: chunk, done: false });
485
+
486
+ requestCapability.resolve({
487
+ value: chunk,
488
+ done: false
489
+ });
453
490
  } else {
454
491
  this._queuedChunk = chunk;
455
492
  }
493
+
456
494
  this._done = true;
495
+
457
496
  for (const requestCapability of this._requests) {
458
- requestCapability.resolve({ value: undefined, done: true });
497
+ requestCapability.resolve({
498
+ value: undefined,
499
+ done: true
500
+ });
459
501
  }
502
+
460
503
  this._requests.length = 0;
504
+
461
505
  this._close();
462
506
  }
463
507
 
464
508
  _onProgress(evt) {
465
509
  if (!this.isStreamingSupported && this.onProgress) {
466
510
  this.onProgress({
467
- loaded: evt.loaded,
511
+ loaded: evt.loaded
468
512
  });
469
513
  }
470
514
  }
@@ -477,27 +521,45 @@ class PDFNetworkStreamRangeRequestReader {
477
521
  if (this._queuedChunk !== null) {
478
522
  const chunk = this._queuedChunk;
479
523
  this._queuedChunk = null;
480
- return { value: chunk, done: false };
524
+ return {
525
+ value: chunk,
526
+ done: false
527
+ };
481
528
  }
529
+
482
530
  if (this._done) {
483
- return { value: undefined, done: true };
531
+ return {
532
+ value: undefined,
533
+ done: true
534
+ };
484
535
  }
536
+
485
537
  const requestCapability = createPromiseCapability();
538
+
486
539
  this._requests.push(requestCapability);
540
+
487
541
  return requestCapability.promise;
488
542
  }
489
543
 
490
544
  cancel(reason) {
491
545
  this._done = true;
546
+
492
547
  for (const requestCapability of this._requests) {
493
- requestCapability.resolve({ value: undefined, done: true });
548
+ requestCapability.resolve({
549
+ value: undefined,
550
+ done: true
551
+ });
494
552
  }
553
+
495
554
  this._requests.length = 0;
555
+
496
556
  if (this._manager.isPendingRequest(this._requestId)) {
497
557
  this._manager.abortRequest(this._requestId);
498
558
  }
559
+
499
560
  this._close();
500
561
  }
562
+
501
563
  }
502
564
 
503
565
  export { PDFNetworkStream };